Notifications
Clear all

[Closed] accessing mesh class on an edit mesh modifier

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

19 Replies
 rdg

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

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?

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

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

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

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)

Aearon,

Like this: attach $ $targetMesh ?

Light

Yeah but that will attach it to the baseobject, not the edit mesh modifier

here’s an example of what i want (switch edit mesh modifier on and off to see the different versions of the object)

Page 1 / 2