Sign in to follow this  
CyberSlag5k

MAX Multimaterial storage question

Recommended Posts

CyberSlag5k    514
As many of you know, I'm writing a maxscript exporter and I have a question as to the way multimaterials and submaterials are stored. I know that in the latest versions of MAX there is essentially only one material and it is composed of multi/sub materials. It appears my artist is using 4 multi-materials. The first is of type ink 'n paint (I'm not entirely sure what this even is), the second a standard, and the third and fourth a multi/sub object. I can traverse a list of submaterials, but I am unsure how to move from one multi-material to the next (or if I even have to). My present exporting code makes no accomodations for these multiple type, it just gets a number of submaterials (though which one it gets it for or if it's for the whole thing I don't know) and exports each one:
fn exportMaterial tempMat file =
(
if(classof tempMat == StandardMaterial) then
(
		amb = tempMat.ambient
		dif = tempMat.diffuse
		spe = tempMat.specular
		WriteFloat file (amb.r / 255.0)
		WriteFloat file (amb.g / 255.0)
		WriteFloat file (amb.b / 255.0)
		WriteFloat file 0
		
		WriteFloat file (dif.r / 255.0)
		WriteFloat file (dif.g / 255.0)
		WriteFloat file (dif.b / 255.0)
		WriteFloat file 1
		
		WriteFloat file (spe.r / 255.0)
		WriteFloat file (spe.g / 255.0)
		WriteFloat file (spe.b / 255.0)
		WriteFloat file 1
		
		WriteFloat file tempMat.Glossiness
	)
)

//other stuff

	tempMat = theObj.material
	if classof tempMat == multimaterial then
	(
		WriteLong file tempMat.numsubs
		for m = 1 to tempMat.numsubs do
			exportMaterial tempMat[m] file
	)
	else
	(
		WriteLong file 1
		exportMaterial tempMat file
	)




That exports 10 materials that come out like this:
Number of Materials: 10
Material 0: 
	Ambient:  	0.588000, 	0.588000, 	0.588000 	0.000000
	Diffuse:  	0.588000, 	0.588000, 	0.588000 	1.000000
	Specular:  	0.900000, 	0.900000, 	0.900000 	1.000000
	Glossiness:  	10.000000

Material 1: 
	Ambient:  	0.588000, 	0.588000, 	0.588000 	0.000000
	Diffuse:  	0.588000, 	0.588000, 	0.588000 	1.000000
	Specular:  	0.900000, 	0.900000, 	0.900000 	1.000000
	Glossiness:  	10.000000

Material 2: 
	Ambient:  	0.588000, 	0.588000, 	0.588000 	0.000000
	Diffuse:  	0.588000, 	0.588000, 	0.588000 	1.000000
	Specular:  	0.900000, 	0.900000, 	0.900000 	1.000000
	Glossiness:  	10.000000

Material 3: 
	Ambient:  	0.588000, 	0.588000, 	0.588000 	0.000000
	Diffuse:  	0.588000, 	0.588000, 	0.588000 	1.000000
	Specular:  	0.900000, 	0.900000, 	0.900000 	1.000000
	Glossiness:  	10.000000

Material 4: 
	Ambient:  	0.588000, 	0.588000, 	0.588000 	0.000000
	Diffuse:  	0.588000, 	0.588000, 	0.588000 	1.000000
	Specular:  	0.900000, 	0.900000, 	0.900000 	1.000000
	Glossiness:  	10.000000

Material 5: 
	Ambient:  	0.588000, 	0.588000, 	0.588000 	0.000000
	Diffuse:  	0.588000, 	0.588000, 	0.588000 	1.000000
	Specular:  	0.900000, 	0.900000, 	0.900000 	1.000000
	Glossiness:  	10.000000

Material 6: 
	Ambient:  	0.588000, 	0.588000, 	0.588000 	0.000000
	Diffuse:  	0.588000, 	0.588000, 	0.588000 	1.000000
	Specular:  	0.900000, 	0.900000, 	0.900000 	1.000000
	Glossiness:  	10.000000

Material 7: 
	Ambient:  	-431602080.000000, 	-431602080.000000, 	-431602080.000000 	-431602080.000000
	Diffuse:  	-431602080.000000, 	-431602080.000000, 	-431602080.000000 	-431602080.000000
	Specular:  	-431602080.000000, 	-431602080.000000, 	-431602080.000000 	-431602080.000000
	Glossiness:  	-431602080.000000

Material 8: 
	Ambient:  	-431602080.000000, 	-431602080.000000, 	-431602080.000000 	-431602080.000000
	Diffuse:  	-431602080.000000, 	-431602080.000000, 	-431602080.000000 	-431602080.000000
	Specular:  	-431602080.000000, 	-431602080.000000, 	-431602080.000000 	-431602080.000000
	Glossiness:  	-431602080.000000

Material 9: 
	Ambient:  	-431602080.000000, 	-431602080.000000, 	-431602080.000000 	-431602080.000000
	Diffuse:  	-431602080.000000, 	-431602080.000000, 	-431602080.000000 	-431602080.000000
	Specular:  	-431602080.000000, 	-431602080.000000, 	-431602080.000000 	-431602080.000000



I assume the last three are not used or defined by the artist (which is fine, if a material isn't defined then a face certainly won't have its). It is clear that the first seven are just the default material, so I'm fairly certain that I'm grabbing the materials from the wrong place. So what I'm thinking I need to do is, for each multi-material I need to go down and grab the sub-materials for that multi-material (it appears as though the artist has used 4). So then my material IDs would be a little funny, I'm thinking, unless they'll just be sequential across the whole material object? I'm really attempting to understand how MAX stores things so that I'm not just guessing while I'm programming. I've read a bit out of the user's reference manual, which is helping. Still, I wish there were a resource more tuned toward programmers available to me (I'm working off of the free demo). Perhaps I'll take a trip up to the university's labs and browse the SDK a bit. Anyway, thanks in advance! EDIT: I'm also still having a bit of trouble with my material IDs. I made a simple block and gave it a single material and exported it. My output file looks like this:
Number of Faces: 12
Face List:
	0, 	2, 	3 	: 	2
	3, 	1, 	0 	: 	2
	4, 	5, 	7 	: 	1
	7, 	6, 	4 	: 	1
	0, 	1, 	5 	: 	5
	5, 	4, 	0 	: 	5
	1, 	3, 	7 	: 	4
	7, 	5, 	1 	: 	4
	3, 	2, 	6 	: 	6
	6, 	7, 	3 	: 	6
	2, 	0, 	4 	: 	3
	4, 	6, 	2 	: 	3

Number of Materials: 1
Material 0: 
	Ambient:  	1.000000, 	0.811765, 	0.709804 	0.000000
	Diffuse:  	1.000000, 	0.811765, 	0.709804 	1.000000
	Specular:  	0.900000, 	0.900000, 	0.900000 	1.000000
	Glossiness:  	9.999999


That number after the colon in the face list is the material ID. As you can see, there is a single material, why would the face IDs then go up to 6? My face exporting code is as follows:
	num_faces = tmesh.numfaces
	WriteLong file num_faces
	for f = 1 to num_faces do
	(
		tempFace = getFace tmesh f
		WriteLong file (tempFace.x - 1) #unsigned
		WriteLong file (tempFace.y - 1) #unsigned
		WriteLong file (tempFace.z - 1) #unsigned

		matID = getFaceMatId tmesh f
		WriteLong file matID
	)


Does that look right? [Edited by - CyberSlag5k on March 28, 2005 2:45:15 PM]

Share this post


Link to post
Share on other sites
Alex Baker    172

Hi,

i'm short on time just right now, but:
in general, dont get confused by 3DSMAX behaviour when summing up all materials
into one multimaterial.
In 3DSMAX, the material is assigned by face - this means, creating a cube,
having two different materials on it, will result in one multimaterial
consisting of the two different materials.
This is because: if you select a distinct face, you get this material from this
face in the material editor - if you click on a mesh, you get all the materials
used by this mesh.
Best way would be: loop through all the (multi)materials in your scene and
create a "flat" array, storing all these single materials; then do a check,
which materials is actually used in your final output.

Share this post


Link to post
Share on other sites
CyberSlag5k    514
Thank you for your response, Alex.

Quote:

Best way would be: loop through all the (multi)materials in your scene and
create a "flat" array, storing all these single materials; then do a check,
which materials is actually used in your final output.


It's how I loop through all the multi-materials that's throwing me. I presently check for the material's numSubs, but I don't think that's right. I think I need to go through each multi-material and pull the number of subs off of that, which I'm not sure how to do.

Once that is done, will material IDs match up? So like if multi-material number 1 uses 3 sub-materials and number 2 has 5 subs, will material ID 5 be multi-material number 2's second sub?

Share this post


Link to post
Share on other sites
Alex Baker    172

Cyberslag5k,


Quote:
]Original post by CyberSlag5k
It's how I loop through all the multi-materials that's throwing me. I presently check for the material's numSubs, but I don't think that's right. I think I need to go through each multi-material and pull the number of subs off of that, which I'm not sure how to do.

Yes, this is the correct way - use the "GetNumSubMats()" function of the Mtl-
class - this will return how many sub materials are currently used by this
material.

Quote:
]Original post by CyberSlag5k
Once that is done, will material IDs match up? So like if multi-material number 1 uses 3 sub-materials and number 2 has 5 subs, will material ID 5 be multi-
material number 2's second sub?

This is a good question i can't answer just right now from the top of my head,
because everything i can remember is, that i extended the plugin a few month
ago, to work around this problem:
instead of the material ID of each face, take the name(!) to do comparison on
material usage in your models. MaterialID's *may* be matching up, but this is
not guaranteed - but by taking the name of the material you are on the save
side !

I can do a test to figure this out for you, but not within the next days,
because i have to prepare for a business trip to mumbai, where i will stay for
one week. When i'm back, i can tell you more - but: using the name will surely
throw out the result you are expecting, try this at first !

Share this post


Link to post
Share on other sites
CyberSlag5k    514
Thank you for all of your help, Alex. It is most appreciated.

This project has been a bit of a nightmare for me. Every time I think I'm forward with it, I take 3 steps back. I have no experience with 3DS MAX, and as such I'm playing the guessing game with how stuff is stored and whatnot.

That being the case, I think I'm going to go back to the .3ds format I started on. I've since found some better documentation and I really need to get some positive progress to report to my team. They're counting on me, so I think it's time to swallow my pride and use an exisiting file format.

Thanks again!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this