Your browser does not seem to support JavaScript. As a result, your viewing experience will be diminished, and you have been placed in read-only mode.
Please download a browser that supports JavaScript, or enable it if it's disabled (i.e. NoScript).
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 20/10/2010 at 07:52, xxxxxxxx wrote:
User Information: Cinema 4D Version: Platform: Language(s) : C++ ;
--------- Hello,
Am writing a C4D importer using melange , the problem is I can read materials using baseDoc->GetFirstMaterial(); and then loop to read all materials , the problem is that I can't find which material is assigned to what object ( by object I mean PolygonObject) ?
I appreciate any help , Regards. Mohammad
On 21/10/2010 at 02:40, xxxxxxxx wrote:
now I figured out how to find which material is assigned to what object , but can't read material properties using melange, is that even possible ?
On 08/11/2010 at 06:36, xxxxxxxx wrote:
hi,
here's an example (without error checking) :
// get object BaseObject *myImportedObject = myImportedDocument->GetFirstObject();
// get texture tag TextureTag *tTag = myImportedObject->GetTag(Ttexture);
// get material BaseMaterial *mat = tTag->GetMaterial();
// get color parameter of color channel GeData data; mat->GetParameter(MATERIAL_COLOR_COLOR, data)) Vector col = data.GetVector();
// shader BaseShader* sh = mat->GetShader(MATERIAL_COLOR_SHADER); ...
btw. if you need the internal name of a paramter the console window can show it, just drag the parameter into the edit field of the console windwow (menu Window->Console...)
cheers jens
ps: the included commandline project shows shows a lot of examples like this, please have a look into "C4DImportExport.cpp"
On 08/11/2010 at 10:02, xxxxxxxx wrote:
BTW, I'm not sure if this is still the case with R12 and/or Melange, but tTag->GetMaterial() doesn't always mean that you'll be looking at a standard material (it could be a shader). I always do a: if(mat->GetType() == Mmaterial) check on it.
As mentioned, this may no longer be necessary (?).
On 08/11/2010 at 10:09, xxxxxxxx wrote:
Originally posted by xxxxxxxx BTW, I'm not sure if this is still the case with R12 and/or Melange, but tTag->GetMaterial() doesn't always mean that you'll be looking at a standard material (it could be a shader)
Originally posted by xxxxxxxx
BTW, I'm not sure if this is still the case with R12 and/or Melange, but tTag->GetMaterial() doesn't always mean that you'll be looking at a standard material (it could be a shader)
Could you elaborate what you mean by this? how could it be a shader? A material tag does only take a material.
On 08/11/2010 at 10:13, xxxxxxxx wrote:
May be an issue of Symantics... what I mean is things like plugin materials (VRay), or Banzi, Danel, Cheen, etc. Create one of those in a document, then drop it on a model... you get a Texture Tag. When you call that tag's GetMaterial() method, you get a result, but the type is not Mmaterial... meaning that it's also _not_ a BaseMaterial*, so calling BaseMaterial::() methods on it will crash the app.
Again.. this is from my early experience (and much to my chagrin) starting back with R7. I don't know if it's still an issue or not.
On 08/11/2010 at 10:21, xxxxxxxx wrote:
...actually, I may be mis-remembering this situation. I _think_ what happens is that tTag->GetMaterial() returns NULL if it's not a Mmaterial - and I was accessing the NULL pointer (no error-checking) causing the crash. But I'm also doing that type-check, so I may have run into some other (or similar) issue as described above.
On 08/11/2010 at 10:24, xxxxxxxx wrote:
Originally posted by xxxxxxxx May be an issue of Symantics... what I mean is things like plugin materials (VRay), or Banzi, Danel, Cheen, etc. Create one of those in a document, then drop it on a model... you get a Texture Tag. When you call that tag's GetMaterial() method, you get a result, but the type is not Mmaterial... meaning that it's also _not_ a BaseMaterial*, so calling BaseMaterial::() methods on it will crash the app. Again.. this is from my early experience (and much to my chagrin) starting back with R7. I don't know if it's still an issue or not.
Hmm, it should still be a BaseMaterial. Every material, may it be from a plugin or the standard material, is a basematerial, it was just an inherited type namely PluginMaterial (in preR12) and then probably of type Mplugin (or the according plugin id). Or do you mean something else? At least that´s my understanding.
On 08/11/2010 at 10:28, xxxxxxxx wrote:
Frankly, it's been several years since I worked through this issue, so my memory on the subject is a little iffy ... but what I am basically doing is some of:
if( pBaseMat->GetChannelState(CHANNEL_COLOR) ) { pChannel = pBaseMat->GetChannel(CHANNEL_COLOR); bc = pChannel->GetData(); preset = Vector(1.0, 1.0, 1.0); vVal = bc.GetVector(BASECHANNEL_COLOR_EX, preset); rBright = bc.GetReal(BASECHANNEL_BRIGHTNESS_EX, 1.0); pMat->diffuse[0] = vVal.x * rBright; pMat->diffuse[1] = vVal.y * rBright; pMat->diffuse[2] = vVal.z * rBright; txName = bc.GetString(BASECHANNEL_TEXTURE); cmpGetCString7(txName, pMat->szMap_Kd, MAX_MAPNAME_LEN); pMat->kd = true; }
...and similar code for other channels (transparency, luminance, etc). Somewhere in the mix of all that is an issue - if it's a Plugin material, or a Banzi/Banji type shader (they don't have those channels).
EDIT: Hmm... actually, I was casting it to a Material* (not BaseMaterial), so that's probably where the issue was. It's only a " Material " if the type is Mmaterial (GetChannelState() is a member of the Material class).