[Closed] 'Attaching' trimeshes ?
Hi all.
I’m working on a primitive whose final mesh is made of a number of identical copies of a base mesh.
Basically, I have a base_mesh variable local to the plugin, holding a trimesh value defined in a on rollout open handler.
In the buildmesh block, I first define an array of positions (through the mouse tool), then create an empty final_mesh trimesh, and finally loop through all the positions and for each:
- make a copy of base_mesh,
- move it to the current position,
- ‘add’ it to final_mesh.
Then: setMesh mesh final_mesh
I have three problems with this:
1- I have to drag VERY slowly in the viewport to get a chance to see anything,
2- depending on the size of the drag, the various elements might intersect, in which case the result is a boolean union of the elements,
3- every so often I get a system exception, eventually followed by a crash.
So, do you guys know of a way to quickly attach several trimeshes together other than using the ‘+’ boolean operator?
Thanks in advance.
(attached is the script with a simple base mesh: 4 verts and 4 faces)
I’ve found a workaround by attaching editable meshes together and grabbing the resulting trimesh (and then deleting the emesh).
It works fine but feels more like a hack than a good solution.
So, no way to ‘attach’ trimeshes together?
edit: I’ve replaced the attachment in the previous post by the last – working – version.
you can ‘attach’ 2 trimesh’s together using meshop.attach <target_trimesh> <source_trimesh>, otherwise to get the boolean as far as I know, the “+” operator is what you have to use
Thanks for the quick answer, Gravey. But the meshop.attach() method doesn’t seem to work (though it does return OK, unllike the attach() method).
I tried:
a = pyramid()
b = box()
ma = a.mesh
mb = b.mesh
delete a
delete b
meshop.attach ma mb
em = editable_mesh()
em.mesh = ma
update em
As a result I get only the pyramy mesh, no trace of the box.
Am I missing something?
(the boolean union was my first try, not what I wanted)
You code has to work with this small change:
a = pyramid()
b = box()
ma = copy a.mesh
mb = b.mesh
delete a
delete b
meshop.attach ma mb
em = editable_mesh()
em.mesh = ma
update em
Thanks a lot, Denis! Now it works like a charm.
Though I’ve no idea why it didn’t work before (?).
Because the mesh of object A is trimesh of Pyramid Base object. You can’t change the trimesh of generic object.
you can convert object A to editable mesh and after that everything will be OK:
a = converttomesh (pyramid())
b = box()
ma = a.mesh
mb = b.mesh
delete a
delete b
meshop.attach ma mb
em = editable_mesh()
em.mesh = ma
update em
but better way is to use instances of a geometry class and not create actual nodes:
a = createinstance pyramid
b = createinstance box
ma = copy a.mesh
meshop.attach ma b.mesh
em = editable_mesh()
em.mesh = ma
update em
I think I’m starting to get it.
What confused me is the reference saying:
<node>.mesh
Extracts a copy of a node's world state if it is convertible to a mesh.
<editable_mesh_baseobject>.mesh
Extracts a copy of base object's mesh.
<trimesh>.mesh
Extracts a copy of another TriMesh's mesh.
So in fact, <node>.mesh doesn’t extract a copy, but is the actual node’s mesh, if I understand you correctly.
Correct, you can use snapShotAsMesh to get a node’s world state mesh (the resulting mesh is a copy). If, after using this method, you no longer need to have the copy in memory, use delete to dispose it.
tmp = snapShotAsMesh $
---
delete tmp
Martijn
Thanks for the enlightment, Martijn. The script is working fine now.
About deleting the trimesh, I forgot to do it at first. And since the script was doing many copies inside a buildmesh block, I had a huge memory leak. It’s fixed now.
Here is a link to the final version: http://www.scriptspot.com/3ds-max/scripts/beeramid
It’s rather useless. I was just curious about how to instance trimeshes inside a simpleObject plugin.
Thanks for your help, guys.