Notifications
Clear all

[Closed] material ID script. how to?

 3ak

yes. updated ver)


for g in selection do
(
	--g = snapshotasmesh obj
	numfaces = polyop.getnummapfaces g 1
	for i = 1 to numfaces do
	(
		
		vi = polyop.getmapface g 1 i
		averageUV = 0.0
		for j = 1 to vi.count do averageUV +=(polyop.getmapvert g 1 vi[j]).y
		averageUV/=vi.count	
		matid = (floor (averageUV+1)) as integer
		format "face: %  id: %  center: % 
" i matid averageuv
		polyop.setfacematid g i matid

	)
	
)

and i don’t know how to do it in mesh space cause setmapdaceid does nothing (only polyop’s func works) – mat id stays the same. don’t know why.

as for mod and floor – mod returns fraction so let’s say our V = 2.53 – mod() returns 0.53 and floor() – 2. i need last one.

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

forget about original question. as i said – not clear question can’t get the complete answer.
so let’s play yourself.

i don’t have the max open but the idea has to be:

do everything in mesh space

get a uv face center averaging tverts coordinates. it’s the same as you do (getTVFace, getTVert…)

apply face ID (setFaceMatID) using just float of center’s v … (or v+1)

hey! my bad. just apply the float and mxs will cast the number to integer …

well… one line solution… blind test:


 for f=1 to mesh.numfaces do [b]setFaceMatID f mesh (vv = gettvface mesh f; [/b][b](((gettvert mesh vv[1]) + [/b][b](gettvert mesh vv[2]) + ([/b][b]gettvert mesh vv[3])[/b][b])[/b]/3).y +1)
 

does it work?

sorry for any possible mistake… it was sent from my phone.

 3ak

no. it will not work. change “setfacematID mesh f” and what is more important setfacematID doesn’t work. matIDs of the faces don’t change.

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

yes. of course it works.


 (
 	delete objects
 	mesh = plane name:"ID_Mesh" length:100 width:100 lengthsegs:10 widthsegs:10 realWorldMapSize:on realWorldMapSize:on mapcoords:on
 	converttomesh mesh
 	for f=1 to mesh.numfaces do setFaceMatID mesh f (vv = gettvface mesh f; (((gettvert mesh vv[1]) + (gettvert mesh vv[2]) + (gettvert mesh vv[3]))/3).y +1)
 	for f=1 to mesh.numfaces do format "face:% id:%
" f (getFaceMatID mesh f)
 )
 

the question is what to do with negative numbers…
probably the best way if to collect all tverts to get the bounds first and shift IDs to avoid the negative values:


 (
 	delete objects
 	mesh = plane name:"ID_Mesh" length:100 width:100 lengthsegs:10 widthsegs:10 realWorldMapSize:on realWorldMapSize:on mapcoords:on 
 	converttomesh mesh
 	
 	min = 1e9
 	tverts = for v=1 to mesh.numtverts collect
 	(
 		p = gettvert mesh v
 		if p.y < min do min = p.y
 		p.y/3
 	)
	min = if min >= 1 the 0 else (1 - min)
	for f=1 to mesh.numfaces do 
 	(
 		vv = gettvface mesh f
 		setFaceMatID mesh f (tverts[vv[1]] + tverts[vv[2]] + tverts[vv[3]] + min)
 	)
 	for f=1 to mesh.numfaces do format "face:% id:%
" f (getFaceMatID mesh f)
 )
 

thanks everyone for the replies, I just tried the script and it does work, it does exactly what i was hoping, so thanks a lot for the time spent, 3ak.

I’ll see if i manage to understand what you did in there, is a fairly short script but as i said I don’t have scripting or programming experience whatsoever and i go really slow whit these scripting thing… :banghead:

thanks again

use somebody else’s script but pick the right one…

Page 2 / 2