[Closed] Problem with splitting a mesh into separate objects
Hello!
I’m stuck with a maxscript that should split a mesh into separate objects (by detaching faces) with a given number of faces per object. The problem is that I now have a mesh that has vertex lightning applied to it, and when running the script, I get new objects, but I’m missing the vertex lightning. What kind of operations should I add to my script so it would preserve the vertex lightning?
(Note that vertex lightning is preserved when I detach faces manually by selecting them in the viewport and selecting “Detach” form the popup menu)
My script:
Undo off ()
obj = $
n = obj.numfaces
facesPerObject = 210
for v = 1 to n/facesPerObject do
(
k = obj.numfaces
emesh = copy obj
if k < facesPerObject then
newMesh = meshop.detachFaces obj #{1..k} delete:true asMesh:true
else
newMesh = meshop.detachFaces obj #{1..facesPerObject} delete:true asMesh:true
update obj
emesh.mesh = newMesh
delete newMesh
update emesh
)
im just thinking whether you need to embed the vextex lighting value of the verts detached somewhere like in one of there free slots, then recall it later?
I would probably store the vertex colors in an array just before you’re about to detach them and apply them to the new object after creation.
Yeah, the same idea popped through my mind once, but I have no idea how to do this.
Can you give me an example or point which chapters/topics I should see in the maxscript reference?
i havnet got much time to go into detail but:
vertex_color_array = #()
vertex_array = (meshop.getVertsUsingFace obj k as array)
for n = 1 to k do (vertex_color_array[n] = getVertColor obj vertex_array[n])
this will (hopefully) extract the vertex colours and stick them in an array. you then have
to use setVertColor to apply them to you new mesh.
or… could you perhaps take a copy of your object, invert the face selection and delete the rest?
i was thinking of using vertex channels as it stays with the scene- ala appdata.