Notifications
Clear all

[Closed] How to move Box to vertice with good orientation

Hi I just started learning maxscript.

I figured out how to move boxes to vertices like this (PIC1) I want them to be more like this (PIC2)(did it with scatter) and it would be great if all boxes were rotated like boxes in the bottom row. . Thanks for any help

3 Replies

Here you go

(
	-- the object you want to distribute on
	local distObj = $
	-- the object you want to duplicate for evey vertex of distObj
	local dupObj = box height:15 length:5 width:5
	
	-- loop through distObj\s vertexes
	for i = 1 to distObj.mesh.numVerts do (
		-- get vertex pos
		local p = getVert distObj.mesh i
		-- get vertex normal
		local z = normalize (getNormal distObj.mesh i)
		-- point the x axis upwards
		local x = [0,0,1]
		-- calculate y axis
		local y = normalize (cross z x)
		-- orthogonize x axis
		x = normalize (cross y z)
		
		-- duplicate dupObj
		local dup = instance dupObj
		-- copy wirecolor
		dup.wirecolor = distObj.wirecolor
		-- create transformation matrix
		dup.transform = (matrix3 x y z p) * distObj.transform
	)
	
	-- delete the original dupObj
	delete dupObj
)

It depends on way you “move boxes to vertices”. Also, the question is do you want to animate these vertices. If not, probably the simple solution is to use Scatter ( Compound Object ). By default, if you distribute source to “All Vertices” it gives orientation based on normal of each vertex. In animation case you can use PFlow or set up rotation script controller with maxscript. I think these effect could be reached by many ways, so… please write a little bit closer what you want.

Works great!!

THANKS!