PDA

View Full Version : How to get all the parameters of a material?


iandreev
03-15-2012, 11:05 PM
Hello,

I am trying to output materials from 3dsmax and noticed that it is not easy.

First of all, if I execute maxscript command
showProperties $Box001.material
and Standard material is assigned to Box001 object, I will receive a list of ALL parameters of Standard material. How can I get the same list using 3dsmax SDK?

OK, there is Animatable, IParamBlock and IParamBlock2 classes but list of parameters received with these classes is not full. To output parameters I used following code:


void LogParamBlockProp(IParamBlock *pblock, int shift)
{
LogOutput("This is a ParamBlock with parameters:", shift);
LogOutput("{", shift);

int numParam = pblock->NumParams();
for(int i=0;i<numParam;i++)
{
const char* type;
switch(pblock->GetParameterType(i))
{
case TYPE_FLOAT:
type = "type_float";
break;
case TYPE_INT:
type = "type_int";
break;
case TYPE_BOOL:
type = "type_bool";
break;
case TYPE_POINT3:
type = "type_point3";
break;
case TYPE_RGBA:
type = "type_rgba";
break;
default:
type = "Unknown";
break;
}

{
char buffer[STRING_BUFFER_SIZE];
sprintf_s(
buffer,
"Parameter %d: %s",
i,
type);
LogOutput(buffer, shift+1);
}

}
LogOutput("}", shift);
}

void LogParamBlockProp(IParamBlock2 *pblock, int shift)
{
ParamBlockDesc2 *desc = pblock->GetDesc();

LogOutput("This is a IParamBlock2 with parameters:", shift);
LogOutput("{", shift);

int numParam = desc->Count();
for(int i=0;i<numParam;i++)
{
const char* type;
switch(desc->paramdefs[i].type)
{
case TYPE_FLOAT:
type = "type_float";
break;
case TYPE_WORLD:
type = "type_world";
break;
case TYPE_INT:
type = "type_int";
break;
case TYPE_BOOL:
type = "type_bool";
break;
case TYPE_POINT3:
type = "type_point3";
break;
case TYPE_COLOR:
type = "type_color";
break;
case TYPE_RGBA:
type = "type_rgba";
break;
case TYPE_PCNT_FRAC:
type = "type_pcnt_frac";
break;
case TYPE_BITMAP:
type = "type_bitmap";
break;
case TYPE_FRGBA:
type = "type_frgba";
break;
case TYPE_TEXMAP:
type = "type_texmap";
break;
default:
type = "Unknown";
break;
}

{
char buffer[STRING_BUFFER_SIZE];
sprintf_s(
buffer,
"Parameter %d: %s %s",
desc->paramdefs[i].ID,
desc->paramdefs[i].int_name,
type);
LogOutput(buffer, shift+1);
}


}
LogOutput("}", shift);
}

void LogObjectProp(Animatable *sub, int shift)
{
if( sub->IsSubClassOf(PARAMBLOCK2CLASSID) )
{
LogParamBlockProp((IParamBlock2 *)sub, shift);
}

if( sub->IsSubClassOf(PARAMBLOCKCLASSID) )
{
LogParamBlockProp((IParamBlock *)sub, shift);
}

int numSubs = sub->NumSubs();

if(numSubs == 0)
{
return;
}

{
char buffer[STRING_BUFFER_SIZE];
sprintf_s(
buffer,
"This Animatable contains %d subanimatabless:",
numSubs );
LogOutput(buffer, shift);
}

LogOutput("{", shift);

Animatable *subsub;

for(int i=0;i<numSubs;i++)
{
{
char buffer[STRING_BUFFER_SIZE];
sprintf_s(
buffer,
"%d) Name: %s",
i,
sub->SubAnimName(i) );
LogOutput(buffer, shift+1);
}

subsub = sub->SubAnim(i);
if(subsub)
{
showObjectProp(subsub, shift+1);
}
}

LogOutput("}", shift);
}


This code produces following output:

Standard material "Material #25" handleID:5042
This Animatable contains 5 subanimatabless:
{
0) Name: Maps
This Animatable contains 48 subanimatabless:
{
0) Name: Ambient Color Amount
1) Name: Ambient Color: None
2) Name: Diffuse Color Amount
3) Name: Diffuse Color: None
4) Name: Specular Color Amount
5) Name: Specular Color: None
6) Name: Specular Level Amount
7) Name: Specular Level: None
8) Name: Glossiness Amount
9) Name: Glossiness: None
10) Name: Self-Illumination Amount
11) Name: Self-Illumination: None
12) Name: Opacity Amount
13) Name: Opacity: None
14) Name: Filter Color Amount
15) Name: Filter Color: None
16) Name: Bump Amount
17) Name: Bump: None
18) Name: Reflection Amount
19) Name: Reflection: None
20) Name: Refraction Amount
21) Name: Refraction: None
22) Name: Displacement Amount
23) Name: Displacement: None
24) Name: Amount
25) Name: : None
26) Name: RGB Level Amount
27) Name: : None
28) Name: RGB Offset Amount
29) Name: : None
30) Name: RGB Level Amount
31) Name: : None
32) Name: RGB Level Amount
33) Name: : None
34) Name: RGB Level Amount
35) Name: : None
36) Name: RGB Offset Amount
37) Name: : None
38) Name: RGB Level Amount
39) Name: : None
40) Name: RGB Offset Amount
41) Name: : None
42) Name: Amount
43) Name: : None
44) Name: Amount
45) Name: : None
46) Name: Amount
47) Name: : None
}
1) Name: Shader Basic Parameters
This Animatable contains 1 subanimatabless:
{
0) Name: Parameters
This is a IParamBlock2 with parameters:
{
Parameter 0: ambient type_rgba
Parameter 1: diffuse type_rgba
Parameter 2: specular type_rgba
Parameter 3: adTextureLock type_bool
Parameter 4: adLock type_bool
Parameter 5: dsLock type_bool
Parameter 6: useSelfIllumColor type_bool
Parameter 7: selfIllumAmount type_pcnt_frac
Parameter 8: selfIllumColor type_rgba
Parameter 9: specularLevel type_pcnt_frac
Parameter 10: glossiness type_pcnt_frac
Parameter 11: soften type_float
}
This Animatable contains 8 subanimatabless:
{
0) Name: Ambient Color
1) Name: Diffuse Color
2) Name: Specular Color
3) Name: Self-Illumination
4) Name: Self-Illum Color
5) Name: Specular Level
6) Name: Glossiness
7) Name: Soften
}
}
2) Name: Extended Parameters
This is a IParamBlock2 with parameters:
{
Parameter 0: opacityType type_int
Parameter 1: opacity type_pcnt_frac
Parameter 2: filterColor type_rgba
Parameter 3: filterMap type_texmap
Parameter 4: opacityFallOffType type_int
Parameter 5: opacityFallOff type_pcnt_frac
Parameter 6: ior type_float
Parameter 7: wireSize type_float
Parameter 8: wireUnits type_int
Parameter 9: applyReflectionDimming type_bool
Parameter 10: dimLevel type_float
Parameter 11: reflectionLevel type_float
}
This Animatable contains 7 subanimatabless:
{
0) Name: Opacity
1) Name: Filter Color
2) Name: Falloff
3) Name: Index of Refraction
4) Name: Wire Size
5) Name: Dim Level
6) Name: Reflection Level
}
3) Name: SuperSampling
This is a IParamBlock2 with parameters:
{
Parameter 0: sampler type_int
Parameter 1: samplerQuality type_float
Parameter 2: samplerEnable type_bool
Parameter 4: samplerAdaptThreshold type_float
Parameter 3: samplerAdaptOn type_bool
Parameter 6: subSampleTextureOn type_bool
Parameter 5: samplerAdvancedOptions type_bool
Parameter 7: samplerByName Unknown
Parameter 8: UserParam0 type_float
Parameter 9: UserParam1 type_float
Parameter 10: samplerUseGlobal type_bool
}
This Animatable contains 2 subanimatabless:
{
0) Name: Sampler Quality
1) Name: Sampler Enable
}
4) Name: Dynamics Properties
This is a IParamBlock2 with parameters:
{
Parameter 0: bounce type_float
Parameter 1: staticFriction type_float
Parameter 2: slidingFriction type_float
}
This Animatable contains 3 subanimatabless:
{
0) Name: Bounce Coefficient
1) Name: Static Friction
2) Name: Sliding Friction
}
}


but showProperties produced output with other parameters and number of parameters in this case much biggest than with Animatable, IParamBlock and IParamBlock2 way:

.shaderType (Shader_Type) : integer
.wire : boolean
.twoSided (Two_sided) : boolean
.faceMap (Face_Map) : boolean
.faceted : boolean
.shaderByName (Shader_Name) : string
.opacityType (Opacity_Type) : integer
.opacity : percent
.filterColor (Filter_Color) : RGB color
.filterMap (Filter_Map) : texturemap
.opacityFallOffType (Falloff_Type) : integer
.opacityFallOff (Falloff) : percent
.ior (Index_of_Refraction) : float
.wireSize (Wire_Size) : float
.wireUnits (Wire_Units) : integer
.applyReflectionDimming (Apply_Reflection_Dimming) : boolean
.dimLevel (Dim_Level) : float
.reflectionLevel (Reflection_Level) : float
.sampler (Pixel_Sampler) : integer
.samplerQuality (Sampler_Quality) : float
.samplerEnable (Sampler_Enable) : boolean
.samplerAdaptThreshold (Adaptive_Threshold) : float
.samplerAdaptOn (Adaptive_On) : boolean
.subSampleTextureOn (SubSample_Textures) : boolean
.samplerAdvancedOptions (Advanced_Options) : boolean
.samplerByName (Sampler_Name) : string
.UserParam0 (Optional_Param0) : float
.UserParam1 (Optional_Param1) : float
.samplerUseGlobal (Use_Global_Settings) : boolean
.mapEnables (Map_Enables) : boolean array
.maps : texturemap array
.mapAmounts (Map_Amounts) : percent array
.adTextureLock (Ambient_Diffuse_Texture_Lock) : boolean
.ambientMap (alias for maps[0])
.ambientMapAmount (alias for mapAmounts[0])
.ambientMapEnable (alias for mapEnables[0])
.bumpMap (alias for maps[8])
.bumpMapAmount (alias for mapAmounts[8])
.bumpMapEnable (alias for mapEnables[8])
.diffuseMap (alias for maps[1])
.diffuseMapAmount (alias for mapAmounts[1])
.diffuseMapEnable (alias for mapEnables[1])
.displacementMap (alias for maps[11])
.displacementMapAmount (alias for mapAmounts[11])
.displacementMapEnable (alias for mapEnables[11])
.filterMap (alias for maps[7])
.filterMapAmount (alias for mapAmounts[7])
.filterMapEnable (alias for mapEnables[7])
.glossinessMap (alias for maps[4])
.glossinessMapAmount (alias for mapAmounts[4])
.glossinessMapEnable (alias for mapEnables[4])
.opacityMap (alias for maps[6])
.opacityMapAmount (alias for mapAmounts[6])
.opacityMapEnable (alias for mapEnables[6])
.reflectionMap (alias for maps[9])
.reflectionMapAmount (alias for mapAmounts[9])
.reflectionMapEnable (alias for mapEnables[9])
.refractionMap (alias for maps[10])
.refractionMapAmount (alias for mapAmounts[10])
.refractionMapEnable (alias for mapEnables[10])
.selfIllumMap (alias for maps[5])
.selfIllumMapAmount (alias for mapAmounts[5])
.selfIllumMapEnable (alias for mapEnables[5])
.specularLevelMap (alias for maps[3])
.specularLevelMapAmount (alias for mapAmounts[3])
.specularLevelMapEnable (alias for mapEnables[3])
.specularMap (alias for maps[2])
.specularMapAmount (alias for mapAmounts[2])
.specularMapEnable (alias for mapEnables[2])
.noExposureControl : boolean
.exposureControlInvertSelfIllum : boolean
.exposureControlInvertReflection : boolean
.exposureControlInvertRefraction : boolean
.ambient (Ambient_Color) : RGB color
.diffuse (Diffuse_Color) : RGB color
.specular (Specular_Color) : RGB color
.adTextureLock (Ambient_Diffuse_Texture_Lock) : boolean
.adLock (Ambient_Diffuse_Lock) : boolean
.dsLock (Diffuse_Specular_Lock) : boolean
.useSelfIllumColor (Use_Self_Illum_Color) : boolean
.selfIllumAmount (Self_Illumination) : percent
.selfIllumColor (Self_Illum_Color) : RGB color
.specularLevel (Specular_Level) : percent
.glossiness : percent
.soften : float
false


How can I get all the parameters of a material?

DaveWortley
03-15-2012, 11:22 PM
for o in (GetPropNames $.material) do
(
Getproperty o $.material
)

iandreev
03-15-2012, 11:24 PM
for o in (GetPropNames $.material) do
(
Getproperty o $.material
)

But this is maxscript. I need to get the same list as showProperties but using 3dsmax SDK on C++

Klunk
03-15-2012, 11:29 PM
can't you get this info directly from from StdMat2, StdMat, Mtl class hierarchy ?

from an INode something like this will get you access

Mtl* nodeMtl = node->GetMtl ();
StdMat2* stdMat = dynamic_cast<StdMat2*>(nodeMtl );
if(stdMat)
{
.....

iandreev
03-15-2012, 11:38 PM
can't you get this info directly from from StdMat2, StdMat, Mtl class hierarchy ?
I am sorry but no I can't. Because I need to output not only standard material, I need to output all parameters of any material.

Klunk
03-16-2012, 09:51 AM
there a property enumeration system , IGameProperty, in the IGame export wrapper you could look at.

iandreev
03-16-2012, 12:11 PM
there a property enumeration system , IGameProperty, in the IGame export wrapper you could look at.

IGameProperty is a wrapper around the standard 3ds Max ParamBlock and ParamBlock2. I'm already working with ParamBlock and ParamBlock2. You can see the code I listed in the first massage.

The problem that the numbers of parameters I received with ParamBlock/ParamBlock2 system is much less than I received with showProperties. Where can I find ALL the parameters?

Klunk
03-16-2012, 04:15 PM
looks to me as if you are not sending the right/complete paramblock to your enumerator`or the enumerator is getting all the params.

one of the ParamBlockDesc2 for stdmtl2

static ParamBlockDesc2 std2_shader_blk (
std2_shader, _T("shaderParameters"), 0, &stdmtl2CD, P_AUTO_CONSTRUCT + P_AUTO_UI, SHADER_PB_REF,

//rollout
IDD_DMTL_SHADER4, IDS_KE_SHADER, 0, 0, &shaderDlgProc,

// params
std2_shader_type, _T("shaderType"), TYPE_INT, 0, IDS_JW_SHADERTYPE,
p_default, 3,
p_ui, TYPE_INTLISTBOX, IDC_SHADER, 0,
p_accessor, &shaderPBAccessor,
end,
std2_wire, _T("wire"), TYPE_BOOL, 0, IDS_DS_WIREFRAME,
p_default, FALSE,
p_ui, TYPE_SINGLECHEKBOX, IDC_WIRE,
p_accessor, &shaderPBAccessor,
end,
std2_two_sided, _T("twoSided"), TYPE_BOOL, 0, IDS_JW_TWOSIDED,
p_default, FALSE,
p_ui, TYPE_SINGLECHEKBOX, IDC_2SIDE,
p_accessor, &shaderPBAccessor,
end,
std2_face_map, _T("faceMap"), TYPE_BOOL, 0, IDS_JW_FACEMAP,
p_default, FALSE,
p_ui, TYPE_SINGLECHEKBOX, IDC_FACE_MAP,
p_accessor, &shaderPBAccessor,
end,
std2_faceted, _T("faceted"), TYPE_BOOL, 0, IDS_KE_FACETED,
p_default, FALSE,
p_ui, TYPE_SINGLECHEKBOX, IDC_FACETED,
p_accessor, &shaderPBAccessor,
end,
std2_shader_by_name, _T("shaderByName"), TYPE_STRING, 0, IDS_JW_SHADERBYNAME,
p_accessor, &shaderPBAccessor,
end,
end
);

seems to contain params not in your sdk output (from stdmtl2.cpp in maxsdk\samples\materials

iandreev
03-16-2012, 04:45 PM
looks to me as if you are not sending the right/complete paramblock to your enumerator`or the enumerator is getting all the params.

one of the ParamBlockDesc2 for stdmtl2

seems to contain params not in your sdk output (from stdmtl2.cpp in maxsdk\samples\materials

Yes, I has seen stdmtl2.cpp. And I've got all the parameters that are in stdmtl.cpp. But there are the last 16 parameters of showProperties output of Standard material:

.noExposureControl : boolean
.exposureControlInvertSelfIllum : boolean
.exposureControlInvertReflection : boolean
.exposureControlInvertRefraction : boolean
.ambient (Ambient_Color) : RGB color
.diffuse (Diffuse_Color) : RGB color
.specular (Specular_Color) : RGB color
.adTextureLock (Ambient_Diffuse_Texture_Lock) : boolean
.adLock (Ambient_Diffuse_Lock) : boolean
.dsLock (Diffuse_Specular_Lock) : boolean
.useSelfIllumColor (Use_Self_Illum_Color) : boolean
.selfIllumAmount (Self_Illumination) : percent
.selfIllumColor (Self_Illum_Color) : RGB color
.specularLevel (Specular_Level) : percent
.glossiness : percent
.soften : float


What is it? I tried to search any of these parameters in stdmtl2.cpp and there is no text coincidence. It seems to me these parameters are parameters of Shader *pShader; (string 191 of stdmtl2.h) But pShader belongs only to class StdMtl2. How to get pShader using max SDK from a Mtl object? Or how to get ALL of these parameters?

gandhics
03-16-2012, 07:22 PM
In Standard material, each "Shader" such as Blinn/Phong/Anisotropic is a seperate plugin.

iandreev
03-16-2012, 08:28 PM
OK, I found it.
It is possible to get all the parameters with ReferenceMaker::GetReference() method.

denisT
03-17-2012, 04:47 AM
OK, I found it.
It is possible to get all the parameters with ReferenceMaker::GetReference() method.
however, if you asked a question on this forum but got an answer yourself, please show your solution. thanx

iandreev
03-17-2012, 12:57 PM
however, if you asked a question on this forum but got an answer yourself, please show your solution. thanx

Actually ReferenceMaker::GetReference() is the solution. The following code will output all the parameters of the material.


void LogParamBlockProp(IParamBlock *pblock, int shift)
{
LogOutput("This is a ParamBlock with parameters:", shift);
LogOutput("{", shift);

int numParam = pblock->NumParams();
for(int i=0;i<numParam;i++)
{
const char* type;
switch(pblock->GetParameterType(i))
{
case TYPE_FLOAT:
type = "type_float";
break;
case TYPE_INT:
type = "type_int";
break;
case TYPE_BOOL:
type = "type_bool";
break;
case TYPE_POINT3:
type = "type_point3";
break;
case TYPE_RGBA:
type = "type_rgba";
break;
default:
type = "Unknown";
break;
}

{
char buffer[STRING_BUFFER_SIZE];
sprintf_s(
buffer,
"Parameter %d: %s",
i,
type);
LogOutput(buffer, shift+1);
}

}
LogOutput("}", shift);
}

void LogParamBlockProp(IParamBlock2 *pblock, int shift)
{
ParamBlockDesc2 *desc = pblock->GetDesc();

LogOutput("This is a IParamBlock2 with parameters:", shift);
LogOutput("{", shift);

int numParam = desc->Count();
for(int i=0;i<numParam;i++)
{
const char* type;
switch(desc->paramdefs[i].type)
{
case TYPE_FLOAT:
type = "type_float";
break;
case TYPE_WORLD:
type = "type_world";
break;
case TYPE_INT:
type = "type_int";
break;
case TYPE_BOOL:
type = "type_bool";
break;
case TYPE_POINT3:
type = "type_point3";
break;
case TYPE_COLOR:
type = "type_color";
break;
case TYPE_RGBA:
type = "type_rgba";
break;
case TYPE_PCNT_FRAC:
type = "type_pcnt_frac";
break;
case TYPE_BITMAP:
type = "type_bitmap";
break;
case TYPE_FRGBA:
type = "type_frgba";
break;
case TYPE_TEXMAP:
type = "type_texmap";
break;
default:
type = "Unknown";
break;
}

{
char buffer[STRING_BUFFER_SIZE];
sprintf_s(
buffer,
"Parameter %d: %s %s",
desc->paramdefs[i].ID,
desc->paramdefs[i].int_name,
type);
LogOutput(buffer, shift+1);
}


}
LogOutput("}", shift);
}

void LogMaterialRefs(ReferenceMaker* mtl, int shift)
{
int nref = mtl->NumRefs();

{
char buffer[STRING_BUFFER_SIZE];
sprintf_s(
buffer,
"This Mtl contains %d ReferenceTargets:",
nref );
LogOutput(buffer, shift);
}

if(nref == 0)
{
return;
}

LogOutput("{", shift);

for(int i=0; i<nref; i++)
{
ReferenceTarget* ref = mtl->GetReference(i);

if(!ref)
{
LogOutput("NULL", shift+1);
continue;
}

Class_ID classid = ref->ClassID();

if(classid == PARAMBLOCKCLASSID)
{
LogOutput("PARAMBLOCKCLASSID", shift+1);
LogParamBlockProp((IParamBlock *)ref, shift+1);
}
else if ( classid == PARAMBLOCK2CLASSID)
{
LogOutput("PARAMBLOCK2CLASSID", shift+1);
LogParamBlockProp((IParamBlock2 *)ref, shift+1);
}
else if ( classid == TEXTUREMAPSCLASSID)
{
LogOutput("TEXTUREMAPSCLASSID", shift+1);
LogMaterialRefs(ref, shift+1);
}
else if ( classid == SHADERCLASSID)
{
LogOutput("SHADERCLASSID", shift+1);
LogMaterialRefs(ref, shift+1);
}
else if ( classid == SAMPLERCLASSID)
{
LogOutput("SAMPLERCLASSID", shift+1);
}
else
{
char buffer[STRING_BUFFER_SIZE];
sprintf_s(
buffer,
"UNKNOWN Class ID: 0x%x 0x%x",
classid.PartA(),
classid.PartB() );
LogOutput(buffer, shift+1);
}
}

LogOutput("}", shift);

}

denisT
03-17-2012, 09:04 PM
thanks a lot!

CGTalk Moderation
03-17-2012, 09:04 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.