Notifications
Clear all

[Closed] Use simpleManipulator as a Helper Object

In several different threadы people asked how to write simpleManipulator plugin and use it ‘a la’ Helper Object.

here is an example how to make Wire drawn object:

plugin simpleManipulator ArrowManip
name:"Arrow"
classID:#(0x1967, 0x2227058a)
category:"Manipulators"
(
	local updated = off
	
    local g_col = colorMan.getColor #manipulatorsSelected
    local x_col = [1,0,0] -- colorMan.getColor #manipulatorsSelected
    local y_col = [0,1,0] -- colorMan.getColor #manipulatorsActive
    local z_col = [0,0,1] 
	
	local c_col = #(x_col, y_col, z_col) 
	
	fn getNode = (refs.dependentnodes this)[1]

    parameters arrowParams rollout:arrowParams
    ( 
		axis type:#integer animatable: on default:1 ui:ui_axis
		dir type:#integer animatable: on default:1 ui:ui_dir
		ways type:#integer animatable: on default:1 ui:ui_ways
		length type:#float animatable:on default:1.0 ui:ui_length
		width type:#float animatable:on default:0.5 ui:ui_width
		spacing type:#float animatable:on default:0.0 ui:ui_spacing
		base_length type:#float animatable:on default:0.75 ui:ui_base_length
		base_width type:#float animatable:on default:0.5 ui:ui_base_width
		positionX type:#float animatable:on default:0.0 ui:ui_positionX
		positionY type:#float animatable:on default:0.0 ui:ui_positionY
		positionZ type:#float animatable:on default:0.0 ui:ui_positionZ
		spin type:#float animatable:on default:0.0 ui:ui_spin
		bend type:#float animatable:on default:0.0 ui:ui_bend
	)
	rollout arrowParams "Wire Arrow"
	(
		group "Geometry: "
		(
			label lb_axis "Axis: " align:#left offset:[16,4] across:2
			radiobuttons ui_axis "" labels:#("X", "Y", "Z") columns:3 align:#left offset:[-22,3]
			label lb_dir "Dir: " align:#left offset:[23,4] across:2
			radiobuttons ui_dir "" labels:#("Horizontal", "Vertical") columns:1 align:#left offset:[-22,3]
			spinner ui_ways "Ways: " type:#integer fieldwidth:56 range:[1, 4, 1] align:#right offset:[0,6]
			spinner ui_length "Length: " type:#float fieldwidth:56 range:[-1e9, 1e9, 0.0] align:#right offset:[0,6]
			spinner ui_width "Width: " type:#float fieldwidth:56 range:[-1e9, 1e9, 0.0] scale:0.01 align:#right offset:[0,-2]
			spinner ui_spacing "Spacing: " type:#float fieldwidth:56 range:[-1e9, 1e9, 0.0] scale:0.01 align:#right offset:[0,4]
			spinner ui_base_length "Base Length: " type:#float fieldwidth:56 range:[0, 1, 0.0] scale:0.01 align:#right offset:[0,4]
			spinner ui_base_width "Base Width: " type:#float fieldwidth:56 range:[0, 1, 0.0] scale:0.01 align:#right offset:[0,-2]
			spinner ui_positionX "Position X: " type:#float fieldwidth:56 range:[-1e9, 1e9, 0.0] align:#right offset:[0,4]
			spinner ui_positionY "Y: " type:#float fieldwidth:56 range:[-1e9, 1e9, 0.0] align:#right offset:[0,-2]
			spinner ui_positionZ "Z: " type:#float fieldwidth:56 range:[-1e9, 1e9, 0.0] align:#right offset:[0,-2]
			spinner ui_spin "Spin: " type:#float fieldwidth:56 range:[-1e9, 1e9, 0.0] align:#right offset:[0,4]
			spinner ui_bend "Bend: " type:#float fieldwidth:56 range:[-1e9, 1e9, 0.0] align:#right offset:[0,-2]
		)
	)

	on canManipulate target return 
	(
		off
	)

	tool create
	(
		on mousePoint click do case click of
		(
			1: nodeTM.translation = gridPoint
			2: #stop
		)

		on mouseMove click do case click of
		(
			2: 
			(
				length = abs gridDist.x
				width = (abs gridDist.y) * 2
			)
		)
	)

	mapped fn addPoint p giz = 
	(
		if p == #new then giz.startNewLine() else giz.addPoint p
	)
	fn makeArrowGizmo =
	(
		local bw = base_width
		local bl = base_length
		
		local giz = manip.makeGizmoShape()
		
		local pp = 
		#(
			[-bw,0,0], [bw,0,0], [bw,bl,0], [1,bl,0], [0,1,0], [-1,bl,0], [-bw,bl,0],[-bw,0,0]
		)
		local tm = translate (scalematrix [width/2,length,1]) [0,spacing,0]
		
		case dir of
		(
			1: ()
			2: rotateY tm 90
		)
		for k in #{1..pp.count} do pp[k] *= tm
		
		insertitem #new pp 1
		addPoint pp giz
				
		case ways of
		(
			2: 
			(
				rtm = rotateZmatrix 90
				for k in #{2..pp.count} do pp[k] *= rtm
				addPoint pp giz
			)
			3: 
			(
				rtm = rotateZmatrix 90
				for k in #{2..pp.count} do pp[k] *= rtm
				addPoint pp giz
				rtm = prerotateZ rtm 90
				for k in #{2..pp.count} do pp[k] *= rtm
				addPoint pp giz
			)
			4: 
			(
				rtm = rotateZmatrix 90
				for k in #{2..pp.count} do pp[k] *= rtm
				addPoint pp giz
				for k in #{2..pp.count} do pp[k] *= rtm
				addPoint pp giz
				for k in #{2..pp.count} do pp[k] *= rtm
				addPoint pp giz
			)
		)
		
		giz
	)	
	fn makeGizmos light:off force:off = if not isAnimPlaying() do animate off undo off
	(
		local flags = 0 --gizmoDontHitTest
		local node = getNode() --firstonly:on
			
		this.clearGizmos()
		
		local giz = makeArrowGizmo()

		local tm = matrix3 1
		
		local _axis = amax 1 (amin 3 axis)
		local rot = case _axis of
		(
			1: (eulerangles 0 0 -90) as matrix3
			2: (eulerangles 0 0 0) as matrix3
			3: (eulerangles 90 0 90) as matrix3
		)
		
		tm = prerotatez tm spin
		tm = prerotatey tm bend
		tm *= rot
		
		local pos = [positionX,positionY,positionZ]
		tm = translate tm pos
		
		giz.transform tm
		this.addGizmoShape giz flags c_col[axis] g_col
	)
	on updateGizmos do makeGizmos()
)

Anyone who is interested in this example, sooner or later will face certain problems. These problems are part of the method, but they have solutions.

In the meantime, I will not get ahead of myself …

8 Replies

I gues this thread was adressed in first place to me, so thanks.
Just a question, can´t I use directly base_width and base_length instead of that local variables bw and bl?

Had some problems with that code:

After deliting:

if not isAnimPlaying() do animate off undo off

this problem was solved, but got the next one:

After deleting:

fn getNode = (refs.dependentnodes this)[1]
and
local node = getNode() --firstonly:on
It worcks, but I personaly don´t see any advantages aver that other code with arrow mesh helper, I mean it´s still a wire arrow and not a solid one and there still no way to see where the front and back side of the arrow is.

there are several ways how to get a tool that you need for your job:

  1. to find a built-in solution in the main tool (3DS MAX in our case)
  2. to find a third-party solution on free or commercial resources
  3. to learn how to make tools, study the subject and develop the tool yourself
  4. to find someone who interesting in tools development practicing, interest him in your task and wait for the solution
  5. to order a solution to a professional, and pay for the entire development cycle

the two first solution don’t exist, as i understand.
the third solution is not suitable for you for some reason.
the fourth doesn’t work for your because it’s not complete.
the fifth solution, if you bear in mind me, you obviously can’t afford.

what do we have to do in this case?

the fourth solution still leaves me some sense, but only in combination with the third.
make two wire arrows yourself using my snippet, then we can continue.

if, in order to start the car, i will do pulling out some wires and hoses from under the hood, will this help?

1 Reply
(@gtafan)
Joined: 1 year ago

Posts: 0

I see your point, but saw no other way to make it worck and that lines of code were of no use for me since I didn´t even understand what they were doing. Now I got a really simple example of solid mesh helper:

plugin simpleManipulator HelperTest_DisplayMesh
name:"HelperTest"
classID:#(0x47db14fe, 0x4e9b5f90)
category:"Manipulators"
(
parameters pblock rollout:params
(
size type:#float animatable:true ui:amount default:40.0
)
rollout params "HelperTest Parameters"
(
Spinner amount "Size:" range:[0, 1e9, 40]
)
on canManipulate target return 
	(
		off
	)
on updateGizmos do(
		this.clearGizmos()
		this.addGizmoMesh (createInstance box width:size height:size length:size).mesh 0 (colorMan.getColor #manipulatorsSelected) (colorMan.getColor #manipulatorsActive)
)
tool create
(
on mousePoint click do
(
nodeTM.translation = gridPoint;#stop
)
)
)

The only problem, I am not able to manipulate the material of that mesh. Not shure if it´s posible at all.

you can’t use material, but you can set a color for added mesh using addGizmoMesh
and of course you can add as many meshes as you need with different colors

OK, thanks. How to set a color for mesh then?

Is there a posibility to moove the box from my example by [0, 0, -size/2]? I mean moove the box gizmo, not the node itself.