Converting an object's display color to a Vray Material

Converting an object's display color to a Vray Material

Anonymous
Not applicable
1,824 Views
3 Replies
Message 1 of 4

Converting an object's display color to a Vray Material

Anonymous
Not applicable
Hi guys...

I'm a complete newbie when it comes to MaxScripting, but I have done some basic VB.NET and Rhinoscripting, so I'm hoping I can catch on quickly enough or copy and paste some code into the right configuration. Here's my challenge:

I have a large set of geometry that was created by a parametric design plug-in for Rhino called Grasshopper. I was able to bake the geometry with a "per object" color, which is fine but I want to be able to convert these colors into Vray materials in Max. When I import the scene in Max, I separate the objects by color, so I have a huge amount of object sets (equal to the number of distinct colors in the scene). I could go in and try to replicate the color of each set one by one, but I'm hoping to script an alternative, since there can be hundreds of colors and I may need to do this many times.

I'd like to be able to take the color from the Max Display color field and create a VRay Material with the corresponding diffuse layer and a predetermined set of reflection and refraction parameters that will apply to all of the materials. These materials must also be applied back to the corresponding geometry so they can be rendered in Vray. I'm working in Max 9 and Vray 1.5.

Does this sound simple enough? Any pointers?

Thanks,
Marc
0 Likes
1,825 Views
3 Replies
Replies (3)
Message 2 of 4

Steve_Curley
Mentor
Mentor
Should be fairly straightforward if - and it's a mighty big if - Vray exposes it's material properties to Maxscript. Unfortunately I don't have Vray so I can't answer that.

In principle:-

Iterate over all the objects in the scene
for each one determine if you already created a material with the correct colour
if so, apply it
if not, create one and note the fact (so you can test for it)

Rather than creating each new material property by property, you could create a template one in the Material Editor, copy it to a new one (in the script) and change only its colour (and name). Still need access to a Vray material's diffuse colour property in order to do it though.

Max 2016 (SP1/EXT1)
Win7Pro x64 (SP1). i5-3570K @ 4.4GHz, 8Gb Ram, DX11.
nVidia GTX760 (2GB) (Driver 430.86).

0 Likes
Message 3 of 4

Anonymous
Not applicable
You have probably already found a solution for this, but I would write something like this:



objs = selectByName title:"Select the objects you want to create a VRay material for"
for obj in objs do (
newMat = VRayMtl()
newMat.diffuse = obj.wirecolor
obj.material = newMat
)


You can modify any feature of a VRayMtl. Here's the editable properties that are exposed to MaxScript:


newMat = vraymtl()
VRayMtl:VRayMtl
show newMat
.diffuse : RGB color
.diffuse_roughness : float
.reflection : RGB color
.reflection_glossiness : float
.hilight_glossiness (reflection_glossiness) : float
.reflection_subdivs : integer
.reflection_fresnel : boolean
.reflection_maxDepth : integer
.reflection_exitColor (reflect_exitColor) : RGB color
.reflection_useInterpolation (useInterpolation) : boolean
.reflection_ior : float
.reflection_lockGlossiness : boolean
.reflection_lockIOR : boolean
.refraction : RGB color
.refraction_glossiness : float
.refraction_subdivs : integer
.refraction_ior : float
.refraction_fogColor : RGB color
.refraction_fogMult (refraction_fogMultiplier) : float
.refraction_fogBias : float
.refraction_affectShadows : boolean
.refraction_affectAlpha : boolean
.refraction_maxDepth : integer
.refraction_exitColor (refract_exitColor) : RGB color
.refraction_useExitColor (refract_useExitColor) : boolean
.refraction_useInterpolation : boolean
.translucency_on (translucency_type) : integer
.translucency_thickness : worldUnits
.translucency_scatterCoeff : float
.translucency_fbCoeff : float
.translucency_multiplier : float
.translucency_color (translucent_color) : RGB color
.brdf_type : integer
.anisotropy (brdf_anisotropy) : float
.anisotropy_rotation (brdf_anisotropy_rotation) : float
.anisotropy_derivation (brdf_anisotropy_derivation) : integer
.anisotropy_axis (brdf_anisotropy_axis) : integer
.anisotropy_channel (brdf_anisotropy_channel) : integer
.soften (brdf_soften) : float
.option_traceDiffuse : boolean
.option_traceReflection : boolean
.option_traceRefraction : boolean
.option_doubleSided : boolean
.option_reflectOnBack : boolean
.option_useIrradMap : boolean
.option_traceDiffuseAndGlossy : integer
.option_cutOff : float
.preservationMode : integer
.option_environment_priority : integer
.option_clampTextures : boolean
.texmap_diffuse : texturemap
.texmap_diffuse_on : boolean
.texmap_diffuse_multiplier : float
.texmap_reflection : texturemap
.texmap_reflection_on : boolean
.texmap_reflection_multiplier : float
.texmap_refraction : texturemap
.texmap_refraction_on : boolean
.texmap_refraction_multiplier : float
.texmap_bump : texturemap
.texmap_bump_on : boolean
.texmap_bump_multiplier : float
.texmap_reflectionGlossiness : texturemap
.texmap_reflectionGlossiness_on : boolean
.texmap_reflectionGlossiness_multiplier : float
.texmap_refractionGlossiness : texturemap
.texmap_refractionGlossiness_on : boolean
.texmap_refractionGlossiness_multiplier : float
.texmap_refractionIOR (texmap_ior) : texturemap
.texmap_refractionIOR_on (texmap_ior_on) : boolean
.texmap_refractionIOR_multiplier (texmap_ior_multiplier) : float
.texmap_displacement : texturemap
.texmap_displacement_on : boolean
.texmap_displacement_multiplier : float
.texmap_translucent : texturemap
.texmap_translucent_on : boolean
.texmap_translucent_multiplier : float
.texmap_environment : texturemap
.texmap_environment_on : boolean
.texmap_hilightGlossiness : texturemap
.texmap_hilightGlossiness_on : boolean
.texmap_hilightGlossiness_multiplier : float
.texmap_reflectionIOR : texturemap
.texmap_reflectionIOR_on : boolean
.texmap_reflectionIOR_multiplier : float
.texmap_opacity : texturemap
.texmap_opacity_on : boolean
.texmap_opacity_multiplier : float
.texmap_roughness : texturemap
.texmap_roughness_on : boolean
.texmap_roughness_multiplier : float
.texmap_anisotropy : texturemap
.texmap_anisotropy_on : boolean
.texmap_anisotropy_multiplier : float
.texmap_anisotropy_rotation : texturemap
.texmap_anisotropy_rotation_on : boolean
.texmap_anisotropy_rotation_multiplier : float
.reflect_minRate : integer
.reflect_maxRate : integer
.reflect_interpSamples : integer
.reflect_colorThreshold (reflect_clrThresh) : float
.reflect_normalThreshold (reflect_nrmThresh) : float
.refract_minRate : integer
.refract_maxRate : integer
.refract_interpSamples : integer
.refract_colorThreshold (refract_clrThresh) : float
.refract_normalThreshold (refract_nrmThresh) : float
0 Likes
Message 4 of 4

Anonymous
Not applicable
 
0 Likes