THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 08/09/2007 at 03:19, xxxxxxxx wrote:
User Information:
Cinema 4D Version: 10.102
Platform: Windows ;
Language(s) :
---------
Hi there!
Currently I'm trying to add automatic texture baking to my scene exporter (from C4D to Ogre) in order to get the materials in Ogre as close as possible to their C4D counterparts.
However I've run into some problems with the baking. First of all it seems the only channel I can be sure not to be affected by lighting would be the luminance channel of the material. I've tried baking textures manually and no matter what options I set in the BakeTexture tag in C4D, the color channel for example always depends on the lighting in the scene.
So, in order to export an approximation of the actual channel texture / shader used, I thought I'd do the following:
1. Take the channel I want to bake from Material M and copy it to the luminance channel of a temporary Material N.
2. Clone the TextureTag into a temporary one, change the material used there to Material N from (1.), add that tag to the object's tags.
3. Bake that stuff with BAKE_TEX_LUMINANCE set to true.
4. Save resulting BaseBitmap to file.
There are two problems with this:
a) When I copy the original channel to the luminance channel of N, only the top-most level of info is copied. My simple test case is a material with a Noise shader in the color channel. After copying the color channel to N's luminance channel, the Noise shader is there, but its parameters are back to standard, i.e. not copied. I assume the same thing would happen with Fusion or any other shader. (I checked this by adding the material N to the document.)
How can I copy a complete channel of a material, including its shaders and their hierarchy? (like the Copy / Paste Channel functions in C4D do)
b) It seems my code still bakes the old, unchanged material and still bakes only the color channel while taking illumination into account. Can somebody tell me where I'm going wrong?
This is the source for the main of my texture baking thread:
<CODE>
BaseDocument* bakeDoc = NULL;;
BaseContainer bakeSettings;
char info[512];
sprintf_s(info, 512, "TextureBaker started with %d jobs to do...", this->m_vWorkList.size());
GeConsoleOut(String(info));
BaseContainer lumData;
for(std::vector<BakerInstruction>::iterator i = this->m_vWorkList.begin(); i != this->m_vWorkList.end(); i++)
{
TextureTag* tTagToBake = TextureTag::Alloc();
Material* matToBake = Material::Alloc();
matToBake->SetChannelState(CHANNEL_LUMINANCE, TRUE);
matToBake->SetChannelState(CHANNEL_COLOR, FALSE);
matToBake->SetChannelState(CHANNEL_SPECULAR, FALSE);
i->TexTag->CopyTo(tTagToBake, COPY_NO_INTERNALS, 0);
tTagToBake->SetMaterial(matToBake);
tTagToBake->InsertBefore(i->TexTag->GetObject()->GetFirstTag());
BaseChannel* source = i->TexTag->GetMaterial()->GetChannel(i->ChannelToBake);
lumData = source->GetData();
matToBake->GetChannel(CHANNEL_LUMINANCE)->SetData(lumData);
g_pDocument->InsertMaterial(matToBake);
bakeSettings.FlushAll();
bakeSettings.InsData(BAKE_TEX_LUMINANCE, GeData(TRUE));
bakeSettings.InsData(BAKE_TEX_WIDTH, GeData(i->TargetResX));
bakeSettings.InsData(BAKE_TEX_HEIGHT, GeData(i->TargetResY));
bakeSettings.InsData(BAKE_TEX_UV_LEFT, GeData(i->MinU));
bakeSettings.InsData(BAKE_TEX_UV_RIGHT, GeData(i->MaxU));
bakeSettings.InsData(BAKE_TEX_UV_TOP, GeData(i->MinV));
bakeSettings.InsData(BAKE_TEX_UV_BOTTOM, GeData(i->MaxV));
bakeDoc = InitBakeTexture(g_pDocument, tTagToBake, i->SourceUVs, i->ResultUVs, bakeSettings, &i-;>ResultError, this->Get());
if(i->ResultError || !bakeDoc)
{
GeConsoleOut(i->ToString());
continue;
}
BaseBitmap* resultBitmap = BaseBitmap::Alloc();
i->ResultError = BakeTexture(bakeDoc, bakeSettings, resultBitmap, this->Get(), NULL, NULL);
if(i->ResultError)
{
GeConsoleOut(i->ToString());
continue;
}
i->ResultFile = Filename(i->ExpMat->GetName()+String("_")+i->TexTag->GetObject()->GetName()+String("_")+TexChannelToString(i->ChannelToBake));
i->ResultFile.SetSuffix("tif");
switch(i->ChannelToBake)
{
case CHANNEL_COLOR: i->ExpMat->SetDiffuseTex(i->ResultFile); break;
case CHANNEL_TRANSPARENCY: i->ExpMat->SetTransparencyTex(i->ResultFile); break;
case CHANNEL_SPECULARCOLOR: i->ExpMat->SetSpecTex(i->ResultFile); break;
default: GeConsoleOut("Can't set new filename for exportmaterial"); break;
}
GeConsoleOut(i->ToString());
if(!resultBitmap->Save(Filename(i->TargetFolder.GetString()+String("\")+i->ResultFile.GetFileString()), FILTER_TIF, 0, 0))
{
GeConsoleOut("ERROR: Failed writing texture to disc!");
}
//tTagToBake->Remove();
BaseBitmap::Free(resultBitmap);
}
//TextureTag::Free(tTagToBake);
bakeSettings.FlushAll();
GeConsoleOut("TextureBaker done!");
</CODE>