Working Nebula Matrial with MaxScript
- NMaxWorkingNebulaMaterialWithMaxScriptOverview
- NMaxWorkingNebulaMaterialWithMaxScriptMaxScript
- NMaxWorkingNebulaMaterialWithMaxScriptExamples
In the most cases, it is enough to assign material in the material editor with the way which described in the section Using Material Editor. But sometimes you might need to do that with max script.
For an example, you have a mesh which aleady has 50 different materials for its material. And you want to change all those materials to the other one material but keep its texture maps unchanged. You can do that by changing all each of the mateirals manually. But it is tedious job. It will be better to do that with max script which let it to be done automatically. The rest of the sections following this will describe that.
Nebula2 custom material is a 'scripted plug-ins', exactly saying, 'Level5 Scripted- plug-ins'. It means that you can access Nebula2 material and specify new values with the same way as like you do with max script for other standard material types of 3DS Max. If you are not familiar with the 'scripted plug-ins' of MaxScript, refer 'MaxScript Reference' provided with 3DS Max.
@section NMaxWorkingNebulaMaterialWithMaxScriptMaxScript MaxScript
This section of the document covers max script of the Nebula2 custom material.
Nebula material is one of the materials which contained in slot of the 3DS Max material editor. It will helpful to know the way to access a currently selected (or activated) slot in the material editor to understand the rest of the sections. 3DS Max provides max script functions to access and specify the material editor and the following code shows that:
currentSlot = meditMaterials[activeMeditSlot]
@subsection NMaxWorkingNebulaMaterialWithMaxScriptConstructor Constructor
You can create a new Nebula2 material as like you can create materials like standard, blend, shell and composite etc.
- Nebula2Material
Constructor of Nebula2 custom material
The following example shows that how to assign the newly created Nebula2 custom material to the third slot of the 3DS Max material editor:meditMaterials[3] = Nebula2Material()
The properties of a Nebula2 material vary based on the shader type. The following properties are applicable to all shader types:
- customAttributes
Array which contains scripted custom attribtes of Nebula2 shader. Each of the custom attibute is dynamically created when the startup of 3DS Max and added to the Nebula2 custom material editor when the user select one of the item of the combobox control.
The following code shows the custom attribute array items:The result of the above wll be the something like the following:currentSlot.customAttributes
#(undefined, <AttributeDef:Standard>, <AttributeDef:Standard_Skinned>, ...
- effectFileNames
Array which contains .fx effect file name corespondes to the each of the cusotm attibutes.
The result of the above wll be the something like the following:currentSlot.effectFileNames
#("'None'", "'shaders:default.fx'", "'shaders:default_skinned.fx'", ...
- paramCurShader
Array index which indicates currently selected shader.
The following code shows the interger of the array index which indicates currently selected shader:The result of the above wll be the something like the following:currentSlot.paramCurShader
1
- paramEffectFile Effect file name which of currently selected shader.
Effect file name which of currently selected shader.
The following code shows .fx effect file name of currently selected shader:The result of the above wll be the something like the following:currentSlot.paramEffectFile
"Standard"
- Shader : string Type. Effect file name. e.g) 'default.fx'
- LockViewer : boolean Type.
- MatAmbient : frgba Type. Ambient color of the material.
- MatDiffuse : frgba Type. Diffuse color of the material.
- MatSpecular : frgba Type. Specular color of the material.
- MatSpecularPower : float Type. Specular power of the material.
- AlphaRef : integer Type.
- AlphaSrcBlend : integer Type.
- AlphaDstBlend : integer Type.
- CullMode : integer Type. Culling mode.
- DiffMap0 : texturemap Type. The index of the map can be one of the [0, 3]
- BumpMap0 : texturemap Type. The index of the map can be one of the [0, 3]
- NoiseMap0 :texturemap Type. The index of the map can be one of the [0, 3]
- AmbientMap0 : texturemap Type. The index of the map can be one of the [0, 3]
- CubMap0 : texturemap Type. The index of the map can be one of the [0, 3]
- SwingAngle : float Type.
- SwingTime : float Type.
- SpriteSwingAngle : float Type.
- SpriteSwingTime : float Type.
- InnerLightIntensity : float Type.
- OuterLightIntensity : float Type.
- MatTranslucency : float Type.
You can access each of the parameter with the same way like other parameters of custom attribute. The following code shows the wat to access the 'Shader' parameter of the material in the currently activated slot:
currentSlot.Shader
The result of the above wll be the something like the following:
"shaders:default.fx"
You can also access all other paramters of the material with the same way.
See '$3dsmax/scripts/n2materialplugin.ms'
max script file to see all the custom attributes and the material script plug-in produced by the nmaxtoolbox plugin.
@section NMaxWorkingNebulaMaterialWithMaxScriptExamples Examples
The following max script function describes that how to change a shader of the currently selected slot of the material:
fn nChangeMaterial currentSlot shaderID = ( custAttributes.add currentSlot currentSlot.customAttributes[shaderID] currentSlot.Shader.selection = shaderID currentSlot.paramCurShader = shaderID currentSlot.effectFileName.caption = "Effect Fils: " + effectFileNames[shaderID] currentSlot.paramEffectFile = currentSlot.effectFileNames[shaderID] )
Note that when you change the shader of the Nebula material, .selection, .paramCurShader and .paramEffectFile should be assigned with proper values.
The following code creates Nebula2 material and set it to the first slot then changes the shader type with second type in the custom attribute array:
meditMaterials[1] = Nebula2Material() nChangeMaterial meditMaterials[1] 2