Notifications
Clear all

[Closed] Rig System

 MZ1

What is the best way to create a Rig System like Daylight? (By using scripted plugin)
This is my first try by using helper plugin:

plugin Helper RigSystem
name:"Rig System"
classID:#(0x7d8d1d94, 0x823edb3b)
category:"Tests"
extends:point
replaceUI:true
(
	local ThisNode
	
	parameters Nodes_Param
	(	
		BoxNM type:#maxobject
		SphereNM type:#maxobject
	)
	
	parameters Body_Param rollout:Body_Rol
	(
		Width type:#worldUnits ui:Width default:10
		Length type:#worldUnits ui:Length default:20
		Height type:#worldUnits ui:Height default:30
		
		on Width set Val do this.UpdateRig()
		on Length set Val do this.UpdateRig()
		on Height set Val do this.UpdateRig()
	)
	
	rollout Body_Rol "Body"
	(
		spinner Width "Width" type:#worldunits range:[0,1e9,0]
		spinner Length "Length" type:#worldunits range:[0,1e9,0]
		spinner Height "Height" type:#worldunits range:[0,1e9,0]
	)
	
	fn UpdateRig = 
	(
		if ThisNode != undefined do
		(
			if not isvalidnode BoxNM.node do in ThisNode BoxNM.node = box()
			if BoxNM.node.parent != ThisNode do BoxNM.node.parent = ThisNode
			BoxNM.node.Width = Width
			BoxNM.node.Length = Length
			BoxNM.node.Height = Height
			BoxNM.node.pos.controller.value = [0,0,10]
			
			if not isvalidnode SphereNM.node do in ThisNode SphereNM.node = Sphere()
			if SphereNM.node.parent != ThisNode do SphereNM.node.parent = ThisNode
			SphereNM.node.Radius = Width
			SphereNM.node.pos.controller.value = [0,0,30]
		)
	)
	
	on Create do
	(
		BoxNM = NodeMonitor()
		SphereNM = NodeMonitor()
	)
	
	on AttachedToNode Nd do
	(
		ThisNode = Nd
		this.UpdateRig()
	)
	
	on DetachedFromNode Nd do
	(
		Objs = for o in #(BoxNM.node,SphereNM.node) where isvalidnode o collect o
		delete Objs
	)
	
	on Clone Old do
	(
		BoxNM.node = copy Old.BoxNM.node
		SphereNM.node = copy Old.SphereNM.node
	)
	
	on GetDisplayMesh do
	(
		Msh = trimesh()
		setMesh Msh verts:#([-20,-20,0],[20,-20,0],[20,20,0],[-20,20,0]) faces:#([3,2,1], [1,4,3])
		extrudeFace Msh #(1,2) 1 100 dir:#common
		for j = 1 to Msh.numfaces do
  		(
  			setEdgeVis Msh j 3 false
  		)
		Msh
	)
	
	tool Create
	(
		on mousePoint click do
		case click of
		(
			1: 
			(
				nodeTM.translation = gridPoint
				#stop
			)
		)
		
	)
	
)

I think this is the bug, when I extend plugin from dummy, Nitrus driver does not show up my helper.

5 Replies
 MZ1

Why I got the error says that object is deleted:“Attempt to access deleted MAX object”, when I add a modifier to the object?

plugin Helper RigSystem
name:"Rig System"
classID:#(0x7d8d1d94, 0x823edb3b)
category:"Tests"
extends:point
replaceUI:true
(
	local ThisNode
	
	parameters Nodes_Param
	(	
		BoxNM type:#maxobject
		SphereNM type:#maxobject
	)
	
	parameters Body_Param rollout:Body_Rol
	(
		Width type:#worldUnits ui:Width default:10
		Length type:#worldUnits ui:Length default:20
		Height type:#worldUnits ui:Height default:30
		
		on Width set Val do this.UpdateRig()
		on Length set Val do this.UpdateRig()
		on Height set Val do this.UpdateRig()
	)
	
	rollout Body_Rol "Body"
	(
		spinner Width "Width" type:#worldunits range:[0,1e9,0]
		spinner Length "Length" type:#worldunits range:[0,1e9,0]
		spinner Height "Height" type:#worldunits range:[0,1e9,0]
	)
	
	fn UpdateRig = 
	(
		if ThisNode != undefined do
		(
			if not isvalidnode BoxNM.node do
			(
				in ThisNode BoxNM.node = box()
				addmodifier BoxNM.node (bend())
			)
			if BoxNM.node.parent != ThisNode do BoxNM.node.parent = ThisNode
			BoxNM.node.Width = Width
			BoxNM.node.Length = Length
			BoxNM.node.Height = Height
			BoxNM.node.pos.controller.value = [0,0,10]
			
			if not isvalidnode SphereNM.node do in ThisNode SphereNM.node = Sphere()
			if SphereNM.node.parent != ThisNode do SphereNM.node.parent = ThisNode
			SphereNM.node.Radius = Width
			SphereNM.node.pos.controller.value = [0,0,30]
		)
	)
	
	on Create do
	(
		BoxNM = NodeMonitor()
		SphereNM = NodeMonitor()
	)
	
	on AttachedToNode Nd do
	(
		ThisNode = Nd
		this.UpdateRig()
	)
	
	on DetachedFromNode Nd do
	(
		Objs = for o in #(BoxNM.node,SphereNM.node) where isvalidnode o collect o
		delete Objs
	)
	
	on Clone Old do
	(
		BoxNM.node = copy Old.BoxNM.node
		SphereNM.node = copy Old.SphereNM.node
	)
	
	on GetDisplayMesh do
	(
		Msh = trimesh()
		setMesh Msh verts:#([-20,-20,0],[20,-20,0],[20,20,0],[-20,20,0]) faces:#([3,2,1], [1,4,3])
		extrudeFace Msh #(1,2) 1 100 dir:#common
		for j = 1 to Msh.numfaces do
  		(
  			setEdgeVis Msh j 3 false
  		)
		Msh
	)
	
	tool Create
	(
		on mousePoint click do
		case click of
		(
			1: 
			(
				nodeTM.translation = gridPoint
				#stop
			)
		)
		
	)
	
)

it looks like the BoxNM parameter can be invalid or undefined. as well as BoxNM.node can be undefined, invalid, or a deleted node

1 Reply
 MZ1
(@mz1)
Joined: 1 year ago

Posts: 0

Script works very well without “AddModifier” function, I don’t delete any node. what will happen when I add modifier?

 MZ1

I think this problem happen at C++ level and I don’t know how to solve it.

 MZ1

Finally I figure it out why this error happen. when I add modifier at “AttachedToNode” state, node is not created completely and this error will happen.