Jump to content
  • Advertisement
Sign in to follow this  
CyberSlag5k

How to grab material properties in maxscript

This topic is 4901 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I know how to get the material ID of each face in my mesh, but I don't know how to get the materials that these correspond to. I'm told that what I actually want are the sub-materials of the main material (as apparently there is only one main material per scene)? If this is so, is it something like:
tmesh = snapshotAsMesh obj
file = fopen "C:\\stuff.dat" "wb"
for m = 1 to tmesh.numMats do
(
   sub = tmesh.getMaterial[m]
   amb = sub.getAmbient
   dif = sub.getDiffuse
   spec = sub.getSpecular
   WriteFloat file amb.x
   WriteFloat file amb.y
   WriteFloat file amb.z
   WriteFloat file dif.x
   WriteFloat file dif.y
   WriteFloat file dif.z
   WriteFloat file spec.x
   WriteFloat file spec.y
   WriteFloat file spec.z
)

I'm just pulling these functions out of thin air, so I'm sure the names aren't correct, but is it something similar that I have to do? Thanks! [Edited by - CyberSlag5k on March 15, 2005 12:06:10 PM]

Share this post


Link to post
Share on other sites
Advertisement
This is from my expoter. It will export (if I copied it right [smile]) complete material tree into file in similar way as is in ase files (but with more details about materials). It does not support advanced materials, parametric materials etc, because my engine does not support them so I didn't need export.


--
-- export_map
-- export map definition
-- map : map to export
-- map_ame : identifier of map in file (like Diffuse etc...)
-- amt : map amount
-- lvl : recursion depth (to pretty the file)
-- out_file : output file
--
fn export_map map map_name amt lvl out_file=
(
if (map != undefined) then
(
format "%#% {\n" (spaces lvl) map_name to:out_file

format "%$Amount %\n" (spaces (lvl + 1)) (amt / 100.0) to:out_file
format "%$MapClass %\n" (spaces (lvl + 1)) (classof map) to:out_file

if (classof map == Bitmaptexture) then -- export texture (bitmap image)
(
format "%$Bitmap %\n" (spaces (lvl + 1)) (fix_path map.filename) to:out_file
format "%$Filtering %\n" (spaces (lvl + 1)) map.filtering to:out_file
format "%$UVOffset % %\n" (spaces (lvl + 1)) map.coords.u_offset map.coords.v_offset to:out_file
format "%$UVTiling % %\n" (spaces (lvl + 1)) map.coords.u_tiling map.coords.v_tiling to:out_file
format "%$UVTile % %\n" (spaces (lvl + 1)) map.coords.u_tile map.coords.v_tile to:out_file
format "%$MapChannel %\n" (spaces (lvl + 1)) map.coords.mapchannel to:out_file
)
else -- unsupported texture type (parametric)
(
format "%$$$\n" (spaces (lvl + 2)) to:out_file
)

format "%}\n" (spaces lvl) to:out_file
)
)





--
-- export_material
-- exports material mat into output file
-- mat : material to export
-- lvl : recursion depth (its only cosmetic to write nice columns into file)
-- sub : material index
-- if value is negative, material represents material with index -sub in scene
-- if value > 0, matreial represents sub-material with given index
-- out_file : output file
--
fn export_material mat lvl sub out_file=
(
if (mat == undefined) then return 0

if (sub < 0) then
(
format "%#Material % {\n" (spaces lvl) (-sub) to:out_file
)
else
(
format "%#Submaterial % {\n" (spaces lvl) sub to:out_file
)

format "%$MaterialName %\n" (spaces (lvl + 1)) mat.name to:out_file
format "%$MaterialClass %\n" (spaces (lvl + 1)) (classof mat) to:out_file

if (classof mat == Standardmaterial) then -- export standard materials
(
format "%$ShaderTypeID %\n" (spaces (lvl + 1)) mat.shadertype to:out_file
format "%$ShaderTypeName %\n" (spaces (lvl + 1)) mat.shaderbyname to:out_file
format "%$FaceMap %\n" (spaces (lvl + 1)) mat.facemap to:out_file
format "%$Faceted %\n" (spaces (lvl + 1)) mat.faceted to:out_file
format "%$Opacity %\n" (spaces (lvl + 1)) (mat.opacity / 100.0) to:out_file
format "%$BounceCoef %\n" (spaces (lvl + 1)) mat.bounce to:out_file
format "%$StaticFriction %\n" (spaces (lvl + 1)) mat.staticfriction to:out_file
format "%$SlidingFriction %\n" (spaces (lvl + 1)) mat.slidingfriction to:out_file
format "%$Ambient % % %\n" (spaces (lvl + 1)) (mat.ambient.r as Integer) (mat.ambient.g as Integer) (mat.ambient.b as Integer) to:out_file
format "%$Diffuse % % %\n" (spaces (lvl + 1)) (mat.diffuse.r as Integer) (mat.diffuse.g as Integer) (mat.diffuse.b as Integer) to:out_file
format "%$Specular % % %\n" (spaces (lvl + 1)) (mat.specular.r as Integer) (mat.specular.g as Integer) (mat.specular.b as Integer) to:out_file

export_map mat.maps[2] "Map_Diffuse" mat.mapamounts[2] (lvl + 1) out_file
-- export_map mat.maps[3] "Map_SpecularColor" mat.mapamounts[3] (lvl + 1) out_file
-- export_map mat.maps[4] "Map_SpecularLevel" mat.mapamounts[4] (lvl + 1) out_file
-- export_map mat.maps[7] "Map_Opacity" mat.mapamounts[7] (lvl + 1) out_file
-- export_map mat.maps[9] "Map_Bump" mat.mapamounts[9] (lvl + 1) out_file
-- export_map mat.maps[10] "Map_Reflection" mat.mapamounts[10] (lvl + 1) out_file
-- export_map mat.maps[11] "Map_Refraction" mat.mapamounts[11] (lvl + 1) out_file
)
else if (classof mat == Multimaterial) then -- export multi/sub object materials
(
format "%$NumSubmaterials %\n" (spaces (lvl + 1)) mat.materiallist.count to:out_file

-- go through all sub-materials and write them to file recursively
for i = 1 to mat.materiallist.count do
(
cur_submat = mat.materiallist
export_material cur_submat (lvl + 1) mat.materialidlist out_file
)
)
else -- unsupported material class (like raytrace etc...)
(
format "%$$$\n" (spaces (lvl + 2)) to:out_file
)

format "%}\n" (spaces lvl) to:out_file
)







spaces is just helper function to create string consting of n tabs:

fn spaces n=
(
x = ""

for i = 1 to n do
x += "\t"

x -- return value
)

I don't know whether this is exactly what you wanted, but I hope it helps [smile].

Edit: Typos in comments in source

[Edited by - b2b3 on March 15, 2005 4:30:39 PM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!