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:
Cinema 4D Version: 10.102
Platform: Windows ;
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:
BaseDocument* bakeDoc = NULL;;
sprintf_s(info, 512, "TextureBaker started with %d jobs to do...", this->m_vWorkList.size());
for(std::vector<BakerInstruction>::iterator i = this->m_vWorkList.begin(); i != this->m_vWorkList.end(); i++)
TextureTag* tTagToBake = TextureTag::Alloc();
Material* matToBake = Material::Alloc();
i->TexTag->CopyTo(tTagToBake, COPY_NO_INTERNALS, 0);
BaseChannel* source = i->TexTag->GetMaterial()->GetChannel(i->ChannelToBake);
lumData = source->GetData();
bakeDoc = InitBakeTexture(g_pDocument, tTagToBake, i->SourceUVs, i->ResultUVs, bakeSettings, &i-;>ResultError, this->Get());
if(i->ResultError || !bakeDoc)
BaseBitmap* resultBitmap = BaseBitmap::Alloc();
i->ResultError = BakeTexture(bakeDoc, bakeSettings, resultBitmap, this->Get(), NULL, NULL);
i->ResultFile = Filename(i->ExpMat->GetName()+String("_")+i->TexTag->GetObject()->GetName()+String("_")+TexChannelToString(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;
if(!resultBitmap->Save(Filename(i->TargetFolder.GetString()+String("\")+i->ResultFile.GetFileString()), FILTER_TIF, 0, 0))
GeConsoleOut("ERROR: Failed writing texture to disc!");