Announcement

Collapse
No announcement yet.

Little script tweak, needs and expert!

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

  • Little script tweak, needs and expert!

    Hi, the second script problem I have had in as many days!!

    I have the following script below that basically affects all objects with "Balls" in their title. It looks to see if the balls objects have moved from their last frame to the current frame and sets their morpher modifier value to 100 or 0 based on the outcome.

    My issue is its taking all movenets, ie x,y,z and rotation. I would like it to only be affected by x,y and z. Does anyone know how I can edit this code to only use the position not rotation?

    MyArray = $Balls* as array
    for i = 1 to MyArray.count do
    (
    t0 = f-1
    t1 = f
    p0 = at time t0 myarray[i].pos
    p1 = at time t1 myarray[i].pos
    if p0==p1 then WM3_MC_SetValue myarray[i].morpher 1 0.0
    else WM3_MC_SetValue myarray[i].morpher 1 100.0
    )

    I think its the .pos section that needs something else added, but I have no idea!

    Many thanks
    Mark

  • #2
    Something like:
    Code:
    MyArray = $Balls* as array
    for i = 1 to MyArray.count do
    (
    	t0 = f-1 
    	t1 = f
    	px0 = at time t0 myarray[i].pos.x
    	px1 = at time t1 myarray[i].pos.x
    	py0 = at time t0 myarray[i].pos.y
    	py1 = at time t1 myarray[i].pos.y
    	pz0 = at time t0 myarray[i].pos.z
    	pz1 = at time t1 myarray[i].pos.z
    	
    	if (px0==px1 and py0==py1 and pz0==pz1) then WM3_MC_SetValue myarray[i].morpher 1 0.0
    	else WM3_MC_SetValue myarray[i].morpher 1 100.0
    )
    Should work.
    Dan Brew

    Comment


    • #3
      Are you running this with animation on as it won't record key values otherwise?

      I've also found that the .pos property can sometimes stop working for no reason - the maxscript macrorecorder can also stop responding mid max session too so might be worth trying .position or .transform.position or .transform.[4] as alternatives. I'd use a lot of print commands with what p0 and p1 are set to to see what maxscript is actually calculating each time.

      Comment


      • #4
        Thanks Dan, speedy!! I have tried but with no luck, it looks logical to me. Any other throughts?

        Comment


        • #5
          Hi John, yes the "balls" objects are animated about the place (remember the script you sorted me out with yesterday, same objects now with lovely rotations, but now the morpher is adding point cached movements depending on static or moving)

          I could try one of the script changes you mention, but ultimately the new script is not working. Ill try anyway, never no.

          Thanks guys.

          Comment


          • #6
            Originally posted by m_hinks View Post
            Thanks Dan, speedy!! I have tried but with no luck, it looks logical to me. Any other throughts?
            Only to do as John says and print out px0, px1 etc. to see why Max thinks the object is moving. You might find that that you need to add a tolerance so instead of checking whether px0 == px1, you could test whether:
            Code:
            abs (px0 - px1) > 0.001
            Dan Brew

            Comment


            • #7
              I've tried the below using one of Johns options, but not fixed. As soon as I remove the rotation, it works perfectly.

              Code:
              for i = 1 to Myarray.count do
              (
              	t0 = f-1 
              	t1 = f
              	px0 = at time t0 Myarray[i].transform.position.x
              	px1 = at time t1 Myarray[i].transform.position.x
              	py0 = at time t0 Myarray[i].transform.position.y
              	py1 = at time t1 Myarray[i].transform.position.y
              	pz0 = at time t0 Myarray[i].transform.position.z
              	pz1 = at time t1 Myarray[i].transform.position.z
              	
              	if (px0==px1 and py0==py1 and pz0==pz1) then WM3_MC_SetValue Myarray[i].morpher 1 0.0
              	else WM3_MC_SetValue Myarray[i].morpher 1 100.0
              )

              I've not sure how to use your tolerence code! I'm new to the scripting game, but like it.

              Comment


              • #8
                I meant check whether the values and almost the same like this:
                Code:
                MyArray = $Balls* as array
                for i = 1 to MyArray.count do
                (
                	local torerance = 0.001
                	t0 = f-1 
                	t1 = f
                	
                	dx = abs((at time t0 myarray[i].pos.x) - (at time t1 myarray[i].pos.x))
                	dy = abs((at time t0 myarray[i].pos.y) - (at time t1 myarray[i].pos.y))
                	dz = abs((at time t0 myarray[i].pos.z) - (at time t1 myarray[i].pos.z))
                	
                	if (dx < torerance and dy < torerance and dz < torerance) then WM3_MC_SetValue myarray[i].morpher 1 0.0
                	else WM3_MC_SetValue myarray[i].morpher 1 100.0
                )
                Dan Brew

                Comment


                • #9
                  oh yes, sweet, works like a dream, just had to increase the tolerence to 0.01.

                  Thanks for your help, very clever, I can go now!!

                  Mark

                  Comment


                  • #10
                    Ok great.

                    Taking what john said in to account this should be better:
                    Code:
                    MyArray = $Balls* as array
                    for i = 1 to MyArray.count do
                    (
                    	t0 = f-1 
                    	t1 = f
                    	
                    	dist = distance (at time t0 myarray[i].transform.position) (at time t1 myarray[i].transform.position)
                    	
                    	if (dist < 0.01) then WM3_MC_SetValue myarray[i].morpher 1 0.0
                    	else WM3_MC_SetValue myarray[i].morpher 1 100.0
                    )
                    Dan Brew

                    Comment


                    • #11
                      nice, even shorter. But the tolerence has gone, can this still be adjusted, or does this do away with the need for that?

                      Edit: scrap that, found the 0.01 value!!!

                      Thanks, amazing.
                      Last edited by m_hinks; 17-01-2013, 10:25 AM. Reason: im stupid!

                      Comment


                      • #12
                        Ok.

                        I only used the variable 'tolerance' so you could change several values quickly. Since we're only testing once there's no need for it.
                        Dan Brew

                        Comment

                        Working...
                        X