Announcement

Collapse
No announcement yet.

face trajectory script

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • face trajectory script

    Hi,

    I have a simple problem, that appears to be very hard to figure out! I can not find a solution anywhere!

    I have a load of boxes moving all over the scene, with just X and Y keys. All I need to do is get the boxes to face the direction they are moving.

    Someone out there must beable to help, as I'm fast running out of hair to pull out!

    I think the solution needs to be a once run thing, so it can look at the motion of the selected objects and key its rotation accordingly.

    Thanks,

    Mark

  • #2
    I've done something slightly similar - Do the boxes always have their z axis pointing directly upwards?

    Comment


    • #3
      Hi Jo

      Yes the z is always up, and usually they all have the same 0 rotation as they are the same geometry instances about.

      Hope you can help! Really stuck.

      Mark

      Comment


      • #4
        There is probably a script out there that can convert the motions of the boxes into splines. Then you can assign a Path Constraint to the boxes and they will point along their trajectories accordingly. Or you can just go to the Scriptspot forum or the Maxscript section of The Area and there's a fair chance somebody there could whip something up for you.
        - Geoff

        Comment


        • #5
          Hi Geoff

          Yes an option, but not in this case because the boxes move about and also have stop points, then but would require a lot of work animating the path constraints movement along the spline.

          Got over 5000 boxes, or in this case they are now dummies, moving about with no rotation.

          Mark

          Comment


          • #6
            Yowza - my current method wouldn't be the quickest for that, will keep checking things.

            Comment


            • #7
              Do you have anything I could try, time is not the most important thing at the moment, just trying not to have to do them by hand!!! It might get reduced to under 1K in the end, hard to tell.

              Thanks

              Comment


              • #8
                Not perfectly - I've got a setup to calculate the steering on a car but that's only for six wheels as opposed to five thousand objects., it also doesn't have any brilliant stuff built in there to take into account stopping so a bit more work to do yet.

                Comment


                • #9
                  Okay - got something now.

                  What I'd suggest is for starters doing a hold or save before running this - there's no undo, and it might lock up / fuck up. I've only tested it on 5 objects so far so I've no idea if maxscript will die trying to operate on that many objects, so I'd also suggest perhaps running it on batches of objects rather than the whole lot at first.

                  Copy and paste this code into a new script, select your objects and run it:

                  Code:
                  heapSize += 50000000
                  
                  TheSel = selection as array
                  		
                  undo off (	
                  		
                  	escapeEnable = false
                  	disableSceneRedraw()
                  			
                  	For i = 1 to selection.count do
                  	(
                  			
                  			TheObj = selection[i]
                  
                  			p = point()
                  
                  			animate on
                  
                  			for t = animationrange.start to animationrange.end do
                  			(
                  				slidertime = t
                  				p.transform = theObj.transform
                  			)
                  
                  			p2 = copy p
                  
                  			inserttime p 0f -1
                  
                  			animate on
                  
                  			for t = animationrange.start to animationrange.end do
                  			(
                  				slidertime = t
                  				TheCurrentPos = p2.pos
                  				TheNewPos = p.pos
                  				
                  				FrontX = normalize(TheNewPos - TheCurrentPos)
                  				FrontZ = normalize([0,0,1])
                  				Fronty = normalize(cross FrontZ Frontx)
                  				
                  				if theCurrentPos != theNewPos then
                  				(
                  					TheObj.transform = matrix3 FrontX FrontY FrontZ TheCurrentPos
                  				) else (
                  					TheObj.pos = TheCurrentPos
                  				)
                  				
                  			)
                  
                  			Delete P
                  			Delete P2
                  			
                  	)
                  
                  	gc()
                  	
                  	enableSceneRedraw()			
                  	completeRedraw()
                  )

                  Comment


                  • #10
                    Amazing!! Ran it on 30+ and works like a charm. I'll test over lunch with 500!!

                    My initial thoughts are can the script not add a key frame for every frame on the x,y and Z, but just on the Z rotation? Dont worry if not, not the files might get heavy with 100's of objects with keys on every frame.

                    Many thanks, I owe you hours of my life!!

                    Mark

                    Comment


                    • #11
                      At the minute it's just mapping the transforms - what I'd do is use the filters in the track view to only show your x and y rotation and delete all the keyframes, you're right that it'll make your scenes huge!

                      Comment


                      • #12
                        I did a test, and it does also add a key for position to every frame. The position is already keyed and would be good to keep those tracks intact. I have as you say just filtered the x and y rotation and cleared them out. Also using the reduce keys function on the z can help smooth the result a little.

                        Also, can the script be amended if needed so it only keys every other frame etc, every frame might be overkill for some things?

                        Overall very happy!!
                        Last edited by m_hinks; 15-01-2013, 05:01 AM.

                        Comment


                        • #13
                          Use the frame accuracy to decide how often it saves a frame!

                          Code:
                          try(destroydialog CalcRotation)catch()
                          
                          	rollout CalcRotation "Calculate Orientation by movement"
                          	(
                          
                          		
                          		group "Calculate Suspension"
                          		(
                          			Spinner FrameAccuracy "Frame Accuracy" type:#integer width:200 align:#right range:[1,100,1]
                          			button ProcessOrientation "Calculate Orientation" width:200 align:#right
                          		)
                          
                          		on ProcessOrientation pressed do
                          		(
                          		
                          		TheSel = selection as array
                          				
                          		undo off (	
                          				
                          				escapeEnable = false
                          				disableSceneRedraw()
                          						
                          				For i = 1 to selection.count do
                          				(
                          						
                          						TheObj = selection[i]
                          
                          						p = point()
                          
                          						animate on
                          
                          						for t = animationrange.start to animationrange.end by FrameAccuracy.value do
                          						(
                          							slidertime = t
                          							p.transform = theObj.transform
                          						)
                          
                          						p2 = copy p
                          
                          						inserttime p 0f -1
                          
                          						animate on
                          
                          						for t = animationrange.start to animationrange.end by FrameAccuracy.value do
                          						(
                          							slidertime = t
                          							TheCurrentPos = p2.pos
                          							TheNewPos = p.pos
                          							
                          							FrontX = normalize(TheNewPos - TheCurrentPos)
                          							FrontZ = normalize([0,0,1])
                          							Fronty = normalize(cross FrontZ Frontx)
                          							
                          							if theCurrentPos != theNewPos then
                          							(
                          								TheObj.transform = matrix3 FrontX FrontY FrontZ TheCurrentPos
                          							) else (
                          								TheObj.pos = TheCurrentPos
                          							)
                          							
                          						)
                          
                          						Delete P
                          						Delete P2
                          						
                          				)
                          
                          				gc()
                          				
                          				enableSceneRedraw()			
                          				completeRedraw()
                          			)
                          		
                          		)
                          	)
                          	
                          CreateDialog CalcRotation width:300

                          Comment


                          • #14
                            God, I wish I had a scripter at our studio!!! You single handedly save me a ton of time. In fact running it at every 10th is as smooth as every frame.

                            Thanks again.

                            Comment


                            • #15
                              There's two maxscript dvd's from cg academy uploaded here - https://www.youtube.com/playlist?lis...23503E8054145C - It'd nearly be worth buying them just to get a high res copy in the correct order but I'm not sure if the company is still running or not.

                              There's another intro frm the writer of maxscript here - http://vimeo.com/19276145

                              Comment

                              Working...