PDA

View Full Version : polyOp.attach with keeping material ids


arnecls
02-28-2006, 12:58 PM
I've got a problem with polyOp.attach.
I want to attach polys and detach them by materialid after doing some operations on the merged poly.
The problem is, that attach() does NOT keep the materialIds as it should do.

The script works like this:


[...]
-- this happens in a loop, so there are different CurrentMatId per mesh
polyOp.setFaceMatID Mesh #all CurrentMatId

[...]
-- this happens in the same loop
MasterObject.EditablePoly.attach Mesh MasterObject

[...]
-- doing some stuff

[...]
-- another loop ...
-- Is there a function that does this part here?
Faces = #()
for Index=1 to (polyOp.getNumFaces MasterObject) do
(
if polyOp.getFaceMatID MasterObject Index == MatId then
Faces[Faces.count + 1] = Index
)

[...]
-- the same loop as above
polyOp.detachFaces MasterObject Faces asNode:true name:NewMeshName
NewMesh = getNodeByName NewMeshName ignoreCase:false

-- NewMesh can be undefined as MaterialIDs will be merged almost always


I stopped the workeflow after attaching the polys together and the materialids are definitly merged wrong there (had 1-3, got 1 and 2), so no problem with my "getByMaterialID" function.
Is there any hidden option to tell attach "keep that materialIds"? Didn't find anything in the Maxscript help.
What I found out is, that when I use the normal "attach" button, it asks me to keep MaterialIDs. If I check this, my script works like a charm, but it would be nice to automate this behavior.

Thanks
Arne

arnecls
03-01-2006, 03:45 PM
Finally made it work, but the problem stays. Anyway - In my special case I could use a workaround:
What I need are faces with an "id", so that I can detach them back out after merge. Here is how it works:

I'm "abusing" the FaceFlags property for this task. The last 8 Bit of the flags are "free for personal use", so I can fit max. 255 ids in there.
Please note, that I converted every editable mesh to an editable poly here, but I guess it works with meshes straight away, too.


Mesh.EditablePoly.setFaceFlags #{1..Mesh.GetNumFaces()} (16777216 + CurrentObjId * 16777216)


The math I'm doing at the end is shifting by 25 (am I right, that there is no shifting operator in maxscript?) to get my number to the last 8 bit of the 32 Bit flag number.
To get those objects back you need to "hack" them back out:


Flag = (16777216 + Pair.Id * 16777216)
FacesTemp = polyOp.getFacesByFlag _MasterObject Flag

FacesForID = #()
for Face in FacesTemp do
(
if (polyOp.getFaceFlags _MasterObject Face) == Flag then
append FacesForID Face
)


The loop is necessary, bacause I get all flags matching the "Flag" bitmask.
What I want is the exact "Flag", so I need to compare the faces one-by-one afterwards. The result is stored in FacesForID.
This is rather time consuming for large models but works fine (although I did NOT test if my shifting math is right here).

CGTalk Moderation
03-01-2006, 03:45 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.