Inside Sabertooth
Learn how Sabertooth uses 3ds Max to create 3D interactive projects, including HBO Go’s Game of Thrones interactive experience
  • 1/3
You are here: Forum Home / Autodesk 3ds® Max® / SDK / Access material properties by string in C++ (w/o type casting), as in MaxScript?
  RSS 2.0 ATOM  

Access material properties by string in C++ (w/o type casting), as in MaxScript?
Rate this thread
 
63755
 
Permlink of this thread  
avatar
  • Total Posts: 3
  • Joined: 22 January 2012 03:55 AM

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!



Replies: 1
/img/forum/dark/default_avatar.png

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  
avatar
  • Location: Kristiansand - Norway
  • Total Posts: 193
  • Joined: 20 December 2006 03:43 AM
  • Permlink of this post

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 0count objmat->NumParamBlocks(); count; ++i{
 IParamBlock2 
*pBlock objmat->GetParamBlock(i);

 for (
int j 0count pBlock->NumParams(); 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

Replies: 0
avatar

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?



Replies: 0