Radial Sort In Line

I'd like to do a radial sort that apply an change on the first object and then increaingly all the way around till i reach the last object.

Check out the attached image to make more sense.

For example: I have an array of sphere and I'd like to change there diffuse color from white to black based on the radial array. Check out the image to make more sense. For the sake of the image i just did it by hand.

Thanks

JokerMartini

AttachmentSize
radialsort.png24.87 KB

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
JokerMartini's picture

This errors as well for some reason?

this is the error i get
-- Unknown property: "pos" in undefined
-- Error occurred in getCircleObjArrayInOrder(); position: 500; line: 12

objs =$Sphere* as array
 
-- function limitation:
-- the objects must be at zero plane on Z axis
fn getCircleObjArrayInOrder objs dir:1 = (
	sortedArray = #()
	oldSel = getCurrentSelection(); select objs
	c = Point2 $.center[1] $.center[2] -- get center XY coords
	select oldSel -- restore previus selection
	-- add 1st object ("at 12 o'clock") to the array
	for o in objs where o.pos[1] == c[1] and o.pos[2] > c[2] do append sortedArray o
	obj1Pos = Point2 sortedArray[1].pos[1] sortedArray[1].pos[2]
	r = distance c obj1Pos -- get the radius
	a = (360.0 / objs.count) * dir -- get the angle
	for i = 1 to objs.count-1 do ( -- find the rest...
		ps = formattedPrint [r*sin(a*i),r*cos(a*i),0] format:".2f"
		for o in objs where formattedPrint o.pos format:".2f" == ps do append sortedArray o
	)
	sortedArray -- return result
)
 
-- if dir:1 (default) the order is CW, if is -1 then CCW
a1 = getCircleObjArrayInOrder objs -- sorted CW
a2 = getCircleObjArrayInOrder objs dir:-1 -- sorted CCW

John Martini
Digital Artist
http://www.JokerMartini.com (new site)

Anubis's picture

try this

-- function limitation:
-- the objects must be at zero plane on Z axis
fn getCircleObjArrayInOrder objs dir:1 = (
	sortedArray = #()
	oldSel = getCurrentSelection(); select objs
	c = Point2 $.center[1] $.center[2] -- get center XY coords
	select oldSel -- restore previus selection
	-- add 1st object ("at 12 o'clock") to the array
	for o in objs where o.pos[1] == c[1] and o.pos[2] > c[2] do append sortedArray o
	obj1Pos = Point2 sortedArray[1].pos[1] sortedArray[1].pos[2]
	r = distance c obj1Pos -- get the radius
	a = (360.0 / objs.count) * dir -- get the angle
	for i = 1 to objs.count-1 do ( -- find the rest...
		ps = formattedPrint [r*sin(a*i),r*cos(a*i),0] format:".2f"
		for o in objs where formattedPrint o.pos format:".2f" == ps do append sortedArray o
	)
	sortedArray -- return result
)
 
-- if dir:1 (default) the order is CW, if is -1 then CCW
a1 = getCircleObjArrayInOrder boxes -- sorted CW
a2 = getCircleObjArrayInOrder boxes dir:-1 -- sorted CCW

my recent MAXScripts RSS (archive here)

JokerMartini's picture

Its Erroring out

It errors out and says this in the listener:

In the max scene i just have 12 spheres in circular array like in the image attached.

getCircleObjArrayInOrder()
-- Error occurred in getCircleObjArrayInOrder(); filename: ; position: 187; line: 6
--  Frame:
--   sortedArray: #()
--   r: undefined
--   objs: undefined
--   dir: 1
--   a: undefined
--   c: undefined
--   obj1Pos: undefined
--   oldSel: #($Sphere001, $Sphere006, $Sphere009, $Sphere012, $Sphere015, $Sphere018, $Sphere021, $Sphere024, $Sphere027, $Sphere030, $Sphere033, $Sphere036)
-- No ""select"" function for undefined
-- Error occurred in getCircleObjArrayInOrder(); filename: ; position: 187; line: 6
--  Frame:
--   sortedArray: #()
--   r: undefined
--   objs: undefined
--   dir: -1
--   a: undefined
--   c: undefined
--   obj1Pos: undefined
--   oldSel: #($Sphere001, $Sphere006, $Sphere009, $Sphere012, $Sphere015, $Sphere018, $Sphere021, $Sphere024, $Sphere027, $Sphere030, $Sphere033, $Sphere036)
-- No ""select"" function for undefined

John Martini
Digital Artist
http://www.JokerMartini.com (new site)

Anubis's picture

You execute the function

You execute the function without argument!
The 2nd (dir) is optinal but the 1st required.

Put your objects to array (for eg):
objs = $Sphere* as array

and use this array as argument:
a1 = getCircleObjArrayInOrder objs

my recent MAXScripts RSS (archive here)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.