Notifications
Clear all

[Closed] Is it possible to get face & vert count in materialclass?

Im wondering if its possible to get the amount of faces and verts a material would use on a single editable mesh?

For example say I have this script “multimaterials in specific”

for obj in geometry do(
	if classof obj.material == multimaterial then(
		for z = 1 to obj.material.count do(
		)
	)
)

would it be possible to in the z loop to count how many faces and verts the first material uses and then the same again for the next material on the same mesh?

3 Replies

can you not just do that by counting the faces by material id?

1 Reply
(@troopermanaic)
Joined: 11 months ago

Posts: 0

I thought so but it seems that with 2 different materials applied to the same mesh all the material ID’s are 1 for some reason. getfacematid is what I should be using right?

EDIT OK IDK what it was maybe some sort of bug but I restarted max and its getting the ids correct now. It was really messing with my head.

Anyway now im trying to get the vert count in multimaterials on single meshes and im having a bit more trouble with it then I thought I would. Unless there is an easier way to do it this is currently how im doing it

clearlistener()

for obj in geometry do(
	ids = obj.material.materialIDList
	if classof obj.material == multimaterial then(
		for id=1 to ids.count do(
			for f = 1 to obj.numfaces do(
				if getfacematid obj f == ids[id] do(
					zz=meshop.getVertsUsingFace obj f
					print zz
				)
			)
			format "Current mat: % 
" obj.material[id].name --above in listener is the verts
		)
	)
)

Basically zz is the verts in the material, I figured when there is a “,” in the array then it represents 1 vert and then its just #…# then its 3. I was trying to figure out math functions for this where I could get the total verts per material in one mesh but nothing seems to be working for me.

This will works on Editable_Mesh only

(
 	clearlistener()
 	getFaceVerts = meshop.getVertsUsingFace
 	for obj in geometry where isKindOf obj Editable_Mesh and isKindOf obj.mat multimaterial do
 	(
 		array = for mat in obj.mat.materiallist collect #(mat.name, #{}) 
 		for f = 1 to obj.numfaces where (number = findItem obj.mat.materialIDList (getfacematid obj f)) != 0 do
 		(
 			join array[number][2] (getFaceVerts obj f)
 		)
 		print array
 	)
 )