Notifications
Clear all

[Closed] accessing mesh class on an edit mesh modifier

 rdg

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

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

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

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

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.

…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

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

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.

very nice, i’ll give this a try prettyPixel

thanks for the help

 rdg

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

Page 2 / 2