Notifications
Clear all

[Closed] material ID script. how to?

hey guys,
I have no idea whatsoever about maxscript, and I wanted to try something but I don’t even know where to start:

The idea is to uv an object, and assign different material ID’s to the faces of that object according to the position of the poligons in the UV space, just taking into account the V position, so if a poligon is within the 0-1 range in the V, assign the ID 1, if its in the 1-2 range, assign the 2, and so on…

any idea how to do that? is that even possible to do?

cheers!

27 Replies
4 Replies
 3ak
(@3ak)
Joined: 11 months ago

Posts: 0

I think you could find corresponding tex face for every geo face. Check UVs in that tex face and according to UVs set mat ID of the geo face with setFaceMatID

(@denist)
Joined: 11 months ago

Posts: 0

because you are not a tech guy there is the rule for you… before asking how to do anything please tell why you need it.
the answer to the main question might differ.

(@metamesh)
Joined: 11 months ago

Posts: 0

I just said it before, I have a lot of objects and each object has their uv’s separated in the uv space so the region that goes from 0-1 in V needs to be material 1, the poligons within the region from 1-2 go need to be material 2, and so on… there’s lots ob objects and lots of materials to be assigned to each object so i don’t want to do it by hand

cheers!

(@denist)
Joined: 11 months ago

Posts: 0

your question is technically incorrect.
are you asking about the center of a polygon?
are we talking about the mesh or the poly?
do you have the world space mapping?

so… if you want to get an answer you have to clearly explain the problem…
the mxs solution might be (will be) only one line of code, but I (I’m sorry) don’t see a clear picture.

You can try using my simple tool from this post. There you must select maually faces in UnwrapUVW window and assingn them proper material ID via tool. This way should by enough for couple ID.
Of course it not what you exactly need, but can by helpfull partially.

but I don’t want to select manually all the uvs etc etc, I just want to select the object, run the script, done. I have a big ammount of objects that need to tweak in this way, with lots of uv’s and I don’t want to go 1 by 1 doing it by hand…

thanks for the suggestion tho!

any other ideas on how to script that ?

cheers!

 3ak

)
you don’t need to do it manually. i mean find faces in a loop)
i’ll give it a try.
But how compute UVs for the face? cause some of 3 certices of a face could be in differen coords (i mean one in 0-1 range, another in 1-2 for example)
maybe face center?

I have another rule, that many times I’ve break:
First try, show your code, then ask for orientation… not for answer…

But Anyway, next test averages the uvs of faceverts and calculates the matID ‘V only’
change: gradients | chn

(
o = selection[1]
chn = 1
gradients = 10

for f = 1 to polyop.getNumMapFaces o chn collect
(
	sum = 0.0
	face = polyop.getMapFace $ chn f
	count = face.count
	for v = 1 to count do sum += (polyop.getMapVert $ chn face[v]).y
	sum /= count
	sum = (sum*gradients+.5) as integer + 1
	polyop.setFaceMatID o f sum
)
/* test */
mat = multiSubMaterial numsubs:0
col = red
for n = 1 to gradients do
(
	mat.materialList[n] = standard diffuseColor:(col.hue = (255./gradients)*n;col)
	mat.materialIDlist[n] = n
)
o.material = mat
)
 3ak
for g in selection do
(
	numfaces = getnumfaces g.mesh
	for i = 1 to numfaces do
	(
		vi = getTVface g.mesh i
		v1 = getTvert g.mesh vi.x
		v2 = getTvert g.mesh vi.y
		v3 = getTvert g.mesh vi.z
		averageUV = (v1+v2+v3)/3
		matid = (floor (averageUV.y+1)) as integer
		m1 = getfacematid g.mesh i
		polyop.setfacematid g i matid
		m2 = getfacematid g.mesh i
	)
	update g
)

…oops. i’m late. btw, does anybody know why SetFaceMatID doesn’t work? only one of polyop struct really set ID.

3 Replies
(@denist)
Joined: 11 months ago

Posts: 0

stop… slow down. your idea is right, but the code solution is … hmm…
every time when you call node’s trimesh using <node>.mesh calling the mxs creates the instance of trimesh…
we discussed this issue on this forum.
so… make a copy of trimesh and use it for the getting uv data

 3ak
(@3ak)
Joined: 11 months ago

Posts: 0

thanks) i’m not a programmer so my code needs your attention)

so i need snapshotasmesh and at the end just make obj.mesh = mySnapshotMesh?

(@denist)
Joined: 11 months ago

Posts: 0

you are a mxs scripter. your code needs a little tweaking only.
i benchmarked copy mesh vs snapshotasmesh … the snapshotasmesh wins.

let’s understand that the OP is not a tech guy, he’s an artist,
Explaining things in a technical way its not usual or easy for those who are starting to learn mxs.

there are 3 options:

  1. ignore the thread (something I tend to do alot)
  2. explain your point of view, and give an example somehow like in post #10
  3. play for fun, with the most logical meaning:

he says polygons = must be the center
99% of modelers use editable_poly
it’s rare to use world space

and indeed a good clear explanation is the ideal.
but forums like this tend to be very far from the ‘ideal’

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

wait a sec. the guy is not learning the mxs. he is looking for solution. to get an answer you have to ask the proper question.

Not even with a proper question, people on this forum should get the answer.

The answer should always come from them.
Otherwise there are professionals waiting for paid work…

But as i said, I break that rule… because I don’t really take the answer seriously in the sense of what is best for the person who ask. So I can easily criticize myself and everybody who is giving direct solutions for others to copy/paste.

all right here is an screenshot,
there’s a teapot and the uv’s of the teapot, all the poligons within the range from 0 to 1 in V should get ID material 1, all the polygons within the range from 1 to 2 in V should get ID mat =2 and so on when running the script, does that make any sense now?
thanks for the help, appreciated!

1 Reply
 3ak
(@3ak)
Joined: 11 months ago

Posts: 0

one question is how sort faces – by their centers, by all their vertices?

my little script may be not very memory friendly as denisT said but it works (slightly updated). Just select your objects (they must be poly and have UVs). And assign multimat to see result. It sorts faces by their center. If center point has V in 1 to 2 then matID of the face will be 2:


see post #20.
Ruramuq has the same in post#8. even brighter)


i like how you do it. almost everything is right. but there are some details…
all your calcs made in mesh space, but the face ID your apply is in poly space. you have to understand that mesh face index and poly face index are different.
another thing…
floor … blah … to integer works, but there is the mod function to do the same.

Page 1 / 2