PDA

View Full Version : accessing mesh class on an edit mesh modifier


Aearon
09-21-2005, 11:43 AM
Hi Guys,

I'm looking for a way to work on the mesh/trimesh of an edit mesh modifier

i know how to use the meshOp struct on baseObjects, but haven't found a way to work on edit mesh modifiers...

i want to write a script that adds an edit mesh modifier to an editable mesh, deletes all vertices in there and attaches a box that matches the bounding box of the original mesh

i want this so i can switch between the mesh and a box representation of the object by just enabling/disabling the edit mesh modifier

rdg
09-21-2005, 02:22 PM
Hi Aearon,

this is a different approach:

plugin modifier toggleDisplayAsBox
name:"Display as Box"
classID:#(0x165fd123, 0x5b06b16)
extends:EmptyModifier replaceUI:true version:1
(
parameters main rollout:params (
)

rollout params "Display As Box" (
button toggleDisplay "Togggle"
on toggleDisplay pressed do (
max box mode
)
)
)

switching the representation of the object by just enabling/disabling the modifier is not possible, though :(

Georg

Aearon
09-21-2005, 02:39 PM
thanks for the help rdg, but this still uses the standard max box mode, what i want is a 'solid' box, that why i was trying to use geometry

any ideas?

Light
09-21-2005, 02:51 PM
Aearon,

Although you can use the bounding box for this, I have written this fn that creates a box in place of an object and then removes it.

fn toggleBox =
(
local sel = selection[1]
local theName = sel.name
local last3 = ""; for i = (theName.count - 2) to theName.count do last3 += theName[i]
if last3 == "64X" then
(
delete sel
local theObj = ""; for i = 1 to (theName.count - 3) do theObj += theName[i]
local yourObj = getNodeByName theObj
unhide yourObj
select yourObj
)
else
(
local theMin = sel.min
local theMax = sel.max
local theBox = box width:(theMax.x - theMin.x) length:(theMax.y - theMin.y) height:(theMax.z - theMin.z)
theBox.center = sel.center
theBox.name = sel.name + "64X"
hide sel
select theBox
)
)




Light

Light
09-21-2005, 02:55 PM
The above code ignores the rotations so this one doesn't:

fn toggleBox =
(
local sel = selection[1]
local theName = sel.name
local last3 = ""; for i = (theName.count - 2) to theName.count do last3 += theName[i]
if last3 == "64X" then
(
delete sel
local theObj = ""; for i = 1 to (theName.count - 3) do theObj += theName[i]
local yourObj = getNodeByName theObj
unhide yourObj
select yourObj
)
else
(
local rot = sel.rotation
sel.rotation = quat 0 0 0 1
local theMin = sel.min
local theMax = sel.max
local theBox = box width:(theMax.x - theMin.x) length:(theMax.y - theMin.y) height:(theMax.z - theMin.z)
theBox.center = sel.center
theBox.name = sel.name + "64X"
hide sel
select theBox
theBox.rotation = rot
sel.rotation = rot
)
)




Light

rdg
09-21-2005, 02:59 PM
well, I missed the solid part of the box.

Light.'s function needs some linking between the original object and the box representation.

I tried something with the a scripted edit_mesh modifier, but I don't get it how it works ...

Georg

Aearon
09-21-2005, 03:10 PM
Thanks for the help light. the problem is that i don't know how to attach this box to the edit_mesh modifier though.

i've come this far now (already have a solution to create the box):

fn getSize obj =
(
objNumVerts=obj.numVerts
if objNumVerts>0 then
(
coord=coordsys local meshOp.getVert obj 1
minU=coord.x; minV=coord.y; minW=coord.z; maxU=coord.x; maxV=coord.y; maxW=coord.z
for v=2 to objNumVerts do
(
coord=coordsys local meshOp.getVert obj v
if coord.x<minU then minU=coord.x
if coord.y<minV then minV=coord.y
if coord.z<minW then minW=coord.z
if coord.x>maxU then maxU=coord.x
if coord.y>maxV then maxV=coord.y
if coord.z>maxW then maxW=coord.z
)--for
-- min,max,size,center
#([minU,minV,minW],[maxU,maxV,maxW],[maxU-minU,maxV-minV,maxW-minW],[(minU+((maxU-minU)/2.0)),(minV+((maxV-minV)/2.0)),(minW+((maxW-minW)/2.0))])
)
else false
)

with redraw off (
for o in selection do (
objSize = (getsize o)[3]

myBox = box width:objSize.x length:objSize.y height:objSize.z transform:o.transform
myBox.center = o.center

-- the following is the part that doesn't work yet:
-- this is supposed to add an edit mesh modifier, delete the original mesh in there
-- and replace it with a box. goal: when the modifier is on, there is only the box, when it's off
-- i can see the original mesh in the baseObject underneath.
-- this does work when i create it using the UI
editMeshMod = Edit_Mesh()
addModifier o editMeshMod

meshop.attach editMeshMod.mesh $Box01 targetNode:o -- here is the problem, there is no mesh property on an edit mesh modifier
)
)

check the comments for additional info on the problem

the getSize function is be prettyPixel by the way (check this thread) (http://forums.cgsociety.org/showthread.php?t=222028&highlight=getSize)

Light
09-21-2005, 03:24 PM
Aearon,

Like this: attach $ $targetMesh ?




Light

Aearon
09-21-2005, 03:51 PM
Yeah but that will attach it to the baseobject, not the edit mesh modifier :(

Aearon
09-21-2005, 03:55 PM
here's an example of what i want (switch edit mesh modifier on and off to see the different versions of the object)

rdg
09-21-2005, 04:07 PM
I understand what you want,
but my approach using a scripted modifier is somewhat lost ...

something I discovered and maybe of interest:

the "on create" handler of the scripted modifier is executed on the opening of the modifier pulldown menu. Code inside this handler will execute anytime, if there is no apropiate error checking ...

In a extendeed Edit_Mesh modifier the numSubObjectLevels returns 0.

As you noticed, all meshoperations inside the modifier seem to operate on the baseobject not on the modifier ...

After seeing your example, I guess yo want this for character animation?
So anything using wiredparameters would be a unwanted performance slowdown ...



Georg

Aearon
09-21-2005, 04:16 PM
thanks for looking further into this rdg

the problem with the scripted modifier solution is that there needs to be an additional script on all machines, i'd rather have the solution as simple as possible and contained within the scene

you are right... wiring shouldn't be necessary for this. the irony is that i already have the solution i want working, but i can't create it using a script :shrug:

i already have an external script that will switch these modifiers on all objects starting with a certain character name (eg Jessy_ like in the suplied file) and ending with "_Slice"

this means that nothing has to be executed while playing the animation or animating, the function is just invoked when i use the script, so there would be no additional weight to the scene except for the vertex data inside the edit mesh modifier

i need this to get the fastest possible playback within max with at least some volume reference. i could of course also model the bones to fit the volume of the character, but i'd rather have everything on the sliced meshes

rdg
09-21-2005, 05:22 PM
here is another idea:

it is based on a customAttribute sample from PEN.
If you can't get the edit_Mesh-Modifier working you can make it the other way around:

create the proxy mesh
create an empty Editable-Mesh
attach both the proxy and the original object to the empty mesh

theBox=box()
-- execute the function to match it your original object
-- -
theMesh=Editable_Mesh()
-- position it to your original mesh
-- -
attach theMesh theBox

-- define the custom attribute
ca=attributes testCA (
local theElements=#("box","original")
local theToggled=1
parameters testP rollout:testR (
)

fn toggleSomeThing = (
print theElements[theToggled]
if theToggled == 1 then (
theToggled=2
)else(
theToggled=1
)
)
rollout testR "test" (
button toggleIt "toggle"
on toggleIt pressed do (
toggleSomething()
)
)
)

custAttributes.add theMesh ca

you can toggle via the button or $.toggleSomeThing()
The toggle should control the visibility of the elements box and original mesh.

drawback:
a. you cannot toggle by enabling a modifier
b. everytime I try to get tsomthing with meshes working I feel like a complete idot. so no face hiding/revealing is implemented ...
but if you attach the box first face 1 to 12 will always belong to the box ...

Georg

prettyPixel
09-21-2005, 06:17 PM
Aearon, It doesn't seem to have an access to the mesh in modifier Edit_Mesh.
But It works if you use an Edit_Poly ;)

for o in selection do (
objSize = (getsize o)[3]

myBox = box width:objSize.x length:objSize.y height:objSize.z transform:o.transform
myBox.center = o.center

editPolyMod = Edit_Poly()
addModifier o editPolyMod
convertToPoly myBox
editPolyMod.setSelection #Vertex #{1..editPolyMod.GetNumVertices()}
editPolyMod.ButtonOp #DeleteVertex
editPolyMod.Attach myBox
)

Of course you replace meshOp by polyOp in function getsize...

About this function, are you sure that you need a full scan of your object ?
In fact this function is only usefull If your axis isn't correctly placed.
Moreover it does not give the oriented bounding box of the object.

Hope this helps

Aearon
09-21-2005, 08:50 PM
thanks prettyPixel, and rdg for looking into it as well!

i'm glad there's such a simple solution, it works perfect so far :)

as for the getSize function, if you have a simpler solution i'm all ears ;) it basically takes no time to calculate anyway though, and i only have to run the script once when i create the slices.

Aearon
09-21-2005, 09:02 PM
...and another little problem, the editpoly must be open in the modify panel for the attach to work :(

a workaround is to switch to the modify panel and select every object one by one and do the attach.. not too pretty though :/

Aearon
09-21-2005, 09:06 PM
this is the fastest i could come up with:

(switching back to the create panel is way faster than just leaving the modify panel open, because then it's also updated while the edit poly is added , i tried it on about 25 objects)

with redraw off (
mySel = selection as array
for o in mySel do (
select o

convertTo o Editable_Poly

objSize = (getsize o)[3]

myBox = box width:objSize.x length:objSize.y height:objSize.z transform:o.transform
myBox.center = o.center

editPolyMod = Edit_Poly()
addModifier o editPolyMod
editPolyMod.setSelection #Vertex #{1..editPolyMod.GetNumVertices()}
editPolyMod.ButtonOp #DeleteVertex
max modify mode
editPolyMod.attach myBox
max create mode
)
)

unless of course there's a way to attach without the modify panel open

prettyPixel
09-23-2005, 12:11 AM
I do not know if that can be useful for you but here is an another version of the script which avoids converting the objects into poly. It is better to activate the modify mode when modifiers are added or when you make operations on the object.

fn getSize obj =
(
rotObj=obj.rotation
obj.rotation=quat 0 0 1 0
size=obj.max-obj.min
obj.rotation=rotObj
return size
)

with redraw off
(
for o in selection do
(
objSize = getsize o
myBox = box width:objSize.x length:objSize.y height:objSize.z transform:o.transform
myBox.center = o.center

max modify mode
editPolyMod = Edit_Poly()
addModifier o editPolyMod
convertToPoly myBox
editPolyMod.setSelection #Vertex #{1..editPolyMod.GetNumVertices()}
editPolyMod.ButtonOp #DeleteVertex
editPolyMod.Attach myBox
max create mode
)
)

The size of the bounding box is not as much reliable in this version but I believe that does not have importance.

Aearon
09-23-2005, 07:59 AM
very nice, i'll give this a try prettyPixel

thanks for the help

rdg
09-23-2005, 08:58 AM
Here is a version that checks if exposeTM is supported and uses the .worldBoundingBoxSize property.

fn getSizeRot obj =
(
rotObj=obj.rotation
obj.rotation=quat 0 0 1 0
size=obj.max-obj.min
obj.rotation=rotObj
return size
)

fn getExposedSize obj = (
theExpTM.exposeNode=obj
return theExpTM.worldBoundingBoxSize
)

with redraw off
(
-- check if exposeTM is supported
if exposeTM != undefined then (
getsize=getExposedSize
global theExpTM
theExpTM=exposeTM()
)else(
getsize=getSizeRot
)
-- -
for o in selection do
(
objSize = getsize o
myBox = box width:objSize.x length:objSize.y height:objSize.z transform:o.transform
myBox.center = o.center

max modify mode
editPolyMod = Edit_Poly()
addModifier o editPolyMod
convertToPoly myBox
editPolyMod.setSelection #Vertex #{1..editPolyMod.GetNumVertices()}
editPolyMod.ButtonOp #DeleteVertex
editPolyMod.Attach myBox
max create mode
)
try (if theExpTM != undefined then delete theExpTM)catch()
)


Georg

CGTalk Moderation
09-23-2005, 08:58 AM
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.