Main Page Contents

Working Nebula Matrial with MaxScript

@section NMaxWorkingNebulaMaterialWithMaxScriptOverview Overview

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]
    
meditMaterials contains virtual array of the materials and root level maps corresponding to the slots in the material editor. The array can be indexed by number to specify slot number or name or string to select by material and root level map name. The global varialbe activeMeditSlot contains the index of the currently active Material Editor slot.

@subsection NMaxWorkingNebulaMaterialWithMaxScriptConstructor Constructor

You can create a new Nebula2 material as like you can create materials like standard, blend, shell and composite etc.

@subsection NMaxWorkingNebulaMaterialWithMaxScriptPropertes Properties

The properties of a Nebula2 material vary based on the shader type. The following properties are applicable to all shader types:

The following properties are the parameters of each of the custom attribute for Nebula2 shader type. The parameters can be various depends on its shader type.

See 'MaxScript Reference' provided with 3DS Max for more details about each type of the parameters.

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]
)
    
The frist in-argument currentSlot represents material of the currently selected slot and the second in-argument shaderID represents the shader index of the custom attributes array which will be applied.

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
    
The second shader type of the Nebula2 material is 'Standard'. (It can be changed if you customize all the shaders for your own necessary) So the shader in the first slot will have 'Stadard' for its shader.