Multiple objects using a line as animation guide

Multiple objects using a line as animation guide

Anonymous
Not applicable
4,039 Views
15 Replies
Message 1 of 16

Multiple objects using a line as animation guide

Anonymous
Not applicable

Hi everyone. I need to do a animation using the image attached as reference. To distribute the balls in each line is easy. I am just using the spacing tool to do that. The problem is to animate the balls trough the line. Using the path constraints make the balls go to the same initial ponit in each line. Than I have to relocate each ball manualy using % along path. It works but make the job a pain in the ass. Somebody knows how to animate each ball in the respective line but preserving the original location? Thanks!

0 Likes
Accepted solutions (1)
4,040 Views
15 Replies
Replies (15)
Message 2 of 16

leeminardi
Mentor
Mentor

I'm not sure what you meant by "... but preserving the original location".

 

Would using a wire parameter do what you want?  If there were ten balls total and each  10% apart then the second ball would be  Percent + 0.1

 

image.png

 

A script could probably be written to create the balls and the wire parameters.

lee.minardi
Message 3 of 16

domo.spaji
Advisor
Advisor

Path Deform modifier with "Stretch" across the shapes option. Animate "percent" value.

Balls for one spline lined/attached in single object.

That would work for 2nd version of Path Deform (like in Max 2021)

 

Message 4 of 16

Anonymous
Not applicable

Great! I tought about the possibility of doing some script to automate the process. But I am not a programer. Would you know how to do that? 

Thanks

0 Likes
Message 5 of 16

Anonymous
Not applicable
I gave for the path deform a try but the result was bizarre. At least in Max 2020
0 Likes
Message 6 of 16

leeminardi
Mentor
Mentor

@domo.spaji would you post a sample file of how Path Deform could be used?  It might be more efficient than using wire parameters.

lee.minardi
0 Likes
Message 7 of 16

leeminardi
Mentor
Mentor
Accepted solution

@Anonymous   my experience writing scripts is very limited and am still learning function syntax and correct program structure.  The following code will generate multiple geosphere (I think they are better to use than spheres).  The program does not terminate as it should.  I am still trying to determine how to do that.  In this version the program will display the Wire Parameter menu when it is done running.  At this point the user should just click anywhere on the screen.  Multiple geospheres will then be created at a separation of  1/n percent apart. 

 

You can change the values of r (radius of geosphere) and n (total number) to suit your needs.  If this program generally meets your needs I can improve the user interface.

image.png

-- Creates n geospheres of radius r that are evenly spaced along the selected spline
-- bug, program does not terminate gracefully but works! When the program is done running
-- you will see the WireParameter menu.  Just click anywhere on the screen to finish the program.
-- L. Minard 9/18/2021  version 1
--
-- IMPORTANT -  select the path spline before execution
--
r = 0.08  -- radius of geosphere
n = 10    -- total numbers of spheres
nsegs = 2  -- number of segments per geosphere
--
ThePath = selection[1]
clearSelection()
GeoSphere pos:[-47.7738,35.8673,0] isSelected:on radius:r segments:nsegs
s01 = selection[1]
s01.pos.controller = Path_Constraint ()
s01.pos.controller.path = ThePath
clearSelection()

for k = 1 to (n - 1) do
(
	GeoSphere pos:[-40.0,35.8673,0] isSelected:on radius:r  segments:nsegs
	s02 = selection[1]
	s02.pos.controller = Path_Constraint ()
	s02.pos.controller.path = ThePath
	delta = "Percent + " +  (k * n  / 100.) as string
	select $GeoSphere001
	macros.run "Parameter Wire" "paramWire"
	paramWire.connect $.pos.controller[#Percent] s02.pos.controller[#Percent] delta
	
	clearSelection()
)
print "DONE"

 

 

lee.minardi
Message 8 of 16

domo.spaji
Advisor
Advisor

It's pretty simple...

 

PDformStretch.PNG

 

Yellow tpots lined  and attached in single mesh obj.

Rose tpots added Path Deform - setup on pic.

0 Likes
Message 9 of 16

leeminardi
Mentor
Mentor

@domo.spaji Thank you but I couldn't get it to work.

 

I created a Teapot added an Edit Mesh modifier then used array to make 10 total instances in the x direction.  I then selected the 10 Teapots and click Attach. I  added a Path Deform modifier with stretch and got the following.

 

image.png

 

I tried several other approaches but no luck.   Any suggestions?

lee.minardi
0 Likes
Message 10 of 16

domo.spaji
Advisor
Advisor

You didn't attach them to single obj.

Don't understand how you tried it, we are talking about Attach option in Edit/able Poly/Mesh Geometry rollout.

You can not attach instanced objects or modifiers, make at least one of them unique and attach others.

 

0 Likes
Message 11 of 16

domo.spaji
Advisor
Advisor
Also, line should be closed (or "almost" closed) so there will no be stretching from 1st to last knot in it...
0 Likes
Message 12 of 16

Anonymous
Not applicable

I am using 3ds Max 2022 but I cant see in across shapes option the stretch option, I just see the Loopback option.

What I have to do to enable this option?

0 Likes
Message 13 of 16

domo.spaji
Advisor
Advisor

You can't enable it, that is 3rd gen. of Path Def. XD

 

Try without that, stretch is/was just "necessary evil" to make it loop on same shape path.

 

If doesn't working use Path Deform WSM.

Pick path and press "Move to path". Again, animate "percent" value.

 

Make sure you divide spline  enough so that objects dont change shape on different parts of path.

Add "Normalize spline" modifier to it...

 

 

 

0 Likes
Message 14 of 16

Anonymous
Not applicable
Hey my friend. You are my hero! A tried the path deform but it didnt worked as I expected. Than I used your script and the jobe is done! I just had to change some values to suit my needs. This could be improved if you want as I had to trie lots of numbers in the sciprt parts that I figured out. Those numbers could be part of variables and funtions to be automated. The script with the changes are bellow. Thanks a billion!
r = 1 -- radius of geosphere
n = 200 -- total numbers of spheres
nsegs = 2 -- number of segments per geosphere
--
ThePath = selection[1]
clearSelection()
GeoSphere pos:[-47.7738,35.8673,0] isSelected:on radius:r segments:nsegs
s01 = selection[1]
s01.pos.controller = Path_Constraint ()
s01.pos.controller.path = ThePath
clearSelection()

for k = 1 to (n - 1) do
(
GeoSphere pos:[-40.0,35.8673,0] isSelected:on radius:r segments:nsegs
s02 = selection[1]
s02.pos.controller = Path_Constraint ()
s02.pos.controller.path = ThePath
delta = "Percent + " + (k * n / 40000.) as string
select $GeoSphere001
macros.run "Parameter Wire" "paramWire"
paramWire.connect $.pos.controller[#Percent] s02.pos.controller[#Percent] delta
clearSelection()
)
print "DONE"
0 Likes
Message 15 of 16

leeminardi
Mentor
Mentor

Here's a much friendlier version of the Maxscript.  In addition it fixes some major calculation errors.

 

-- Creates user specifed number of geospheres of a given radius r 
-- that are evenly spaced along the selected spline.
--
-- L. Minardi 9/21/2021  version 4
--
if ballsRollout != undefined do 
 (
 	try(DestroyDialog ballsRollout)catch()
 )

rollout BallsRollout "Balls Along Spline" width:200 height:120
(
	spinner 'BallRad' "Ball radius:" range:[0,10000,0.1] fieldWidth:40 type:#float 
	spinner 'numBalls' "Total number of balls:" range:[0,100000,10] fieldWidth:40 type:#integer
	spinner 'numSegs' "Number of ball segments:" range:[0,50,2] fieldWidth:40 type:#integer
	button 'btnGo' "Go" pos:[50,75] width:96 height:36 align:#left
	on btnGo pressed do
	(
		if 
--		 (selection[1] != undefined) and (superClassOf selection[1] != shape) then 	
		(selection[1] != undefined) then 	
		(				
			thePath = selection[1] 
			clearSelection()
			GeoSphere pos:[0.0,0.0,0.0] isSelected:on radius:BallRad.value segments:numSegs.value
			s01 = selection[1]
			s01.pos.controller = Path_Constraint ()
			s01.pos.controller.path = ThePath
			clearSelection()
			for k = 1 to (numBalls.value - 1) do
				(
					GeoSphere pos:[0.0,0.0,0.0] isSelected:on radius:BallRad.value  segments:numSegs.value
					s02 = selection[1]
					s02.pos.controller = Path_Constraint ()
					s02.pos.controller.path = ThePath
					delta = "Percent + " +  (k as float / numBalls.value  ) as string
					select $GeoSphere001
					paramWire.connect $.pos.controller[#Percent] s02.pos.controller[#Percent] delta
					clearSelection()
				)
			print "DONE"	
		)	
		else
		(
			messageBox "Select a shape object!"	
		)
	)
)
createdialog BallsRollout 

 

lee.minardi
Message 16 of 16

leeminardi
Mentor
Mentor

@Anonymous  version 4 had a bug that if the file already contained Geosphere001 and it was not linked to a path the program would crash.  

 

Version 5 below changes this so that a geosphere named Geosphere__Master  is used as the base object.  It is very unlikely that your Max file would include such a named object and therefore should execute fine.

Please let me know if you have any problems with the program.

 

 

-- Creates user specifed number of geospheres of a given radius r 
-- that are evenly spaced along the selected spline
--
-- L. Minardi 9/22/2021  version 5
--
-- IMPORTANT -  select the path spline before execution
--

if ballsRollout != undefined do 
 (
 	try(DestroyDialog ballsRollout)catch()
 )

rollout BallsRollout "Balls Along Spline" width:200 height:120
(
	spinner 'BallRad' "Ball radius:" range:[0,10000,0.1] fieldWidth:40 type:#float 
	spinner 'numBalls' "Total number of balls:" range:[0,100000,10] fieldWidth:40 type:#integer
	spinner 'numSegs' "Number of ball segments:" range:[0,50,2] fieldWidth:40 type:#integer
	button 'btnGo' "Go" pos:[50,75] width:96 height:36 align:#left
	on btnGo pressed do
	(
		if 
			-- ((selection[1] != undefined) and (superClassOf selection[1] != shape)) then 	
		(selection[1] != undefined) then 	
		(				
			thePath = selection[1] 
			clearSelection()
			GeoSphere pos:[0.0,0.0,0.0] isSelected:on radius:BallRad.value name:"GeoSphere001__Master" segments:numSegs.value
			s01 = selection[1]
			s01.pos.controller = Path_Constraint ()
			s01.pos.controller.path = ThePath
			clearSelection()
			for k = 1 to (numBalls.value - 1) do
				(
					GeoSphere pos:[0.0,0.0,0.0] isSelected:on radius:BallRad.value  segments:numSegs.value
					s02 = selection[1]
					s02.pos.controller = Path_Constraint ()
					s02.pos.controller.path = ThePath
					delta = "Percent + " +  (k as float / numBalls.value  ) as string
					select $GeoSphere001__Master
					paramWire.connect $.pos.controller[#Percent] s02.pos.controller[#Percent] delta
					clearSelection()
				)
			print "DONE"	
		)	
		else
		(
			messageBox "Select a shape object!"	
		)
	)
)
createdialog BallsRollout 

 

 

 

lee.minardi