|
|
|
Tell us what you think of the site.
|
Autodesk Media & Entertainment User Community
|
Autodesk® 3ds Max®
|
|
Autodesk® Maya®
|
|
Autodesk® Softimage®
|
|
Autodesk® MotionBuilder®
|
|
Autodesk® Mudbox™
|
|
Autodesk® ImageModeler™
|
|
Autodesk® Sketchbook® Pro
|
|
Autodesk® Smoke on Mac®
|
| Access material properties by string in C++ (w/o type casting), as in MaxScript?
|
|
|
I’m writing my custom exporter using the max C++ SDK. Everything runs fine so far, but I have one issue with materials. The main reason for writing my own exporter is to be able to translate different materials to my own renderer’s materials. In particular, I want to support standard max/mray materials, as well as VRay materials. My problem is that I cannot see how I can access VRay material properties without casting each material to the VRay type. For this, I of course need the VRay SDK, and I want to avoid this dependency. In MaxScript you can just write
if (classof material == VrayMtl) then
(
myGlossiness = material.reflection_glossiness
)
I want to be able to write such thing in C++ without explicitly casting the material pointer to a type, for which I’d need a header file with its definition. Please tell me it’s possible to access material properties by string in the C++ SDK. Thanks!
|
|
|
|
|
I just discovered the Mtl::NumParamBlocks() Mtl::GetParamBlock(int) methods which reveal interesting things, i.e. parameters, when explored. Am I on the right track? :)
Author: ingenious
|
| Replied: 22 January 2012 08:59 AM
|
|
|
|
|
I do it like this:
in my custom material I have a parameter named “opacity_value”.
I then loop through every submaterial and paramblock to check if it exists.
I then assign the opacity to the int variable, and write it out to my file.
for (int i = 0, count = objmat->NumParamBlocks(); i < count; ++i) {
IParamBlock2 *pBlock = objmat->GetParamBlock(i);
for (int j = 0, count = pBlock->NumParams(); j < count; ++j) {
if (::_stricmp(pBlock->GetLocalName(j), "opacity_value") == 0)
{
int opacity_value;
pBlock->GetValue(j,GetCOREInterface()->GetTime(),opacity_value,FOREVER,NULL);
fprintf(file, "\t<opacity value=\"%\" />\n", opacity_value);
}
}
http://www.stigatle.net
|
|
|
|
Thanks for the reply! I found my way and can now access properties and export the needed data. However, I have a problem with dynamically created parameter blocks / UI rollouts.
Take the Standard material for example - I want to export its parameters. I loop over the parameter blocks of the Mtl object, each corresponding to a rollout in the material editor, and process its parameters. However, I’m missing the most vital parameter block - the one with the basic BRDF parameters, which in the UI is created dynamically, depending on the type of BRDF chosen (in the topmost dropdown) - Anisotropic, Blinn, Metal, etc. Looping over the parameter blocks of the Mtl object just skips this block, which should come right after the “Shader Basic Parameters” block.
Also, I have troubles accessing VRayMtl’s properties - I can list and access them, however the values I get from the properties are not the values I have in the material editor UI. This leads me to thinking that I should somehow update the parameters before processing them. But how?
|
|
|
|
|
|