Announcement

Collapse
No announcement yet.

script for point cache

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

  • #16
    Thanks Colin, though for the last hour I've tried to use your script with no luck!!

    I'm a complete beginner I'm afraid! If you have any spare time, would you beable to show me how to incorperate your code with mine?

    On a side note, I'm also trying to achieve the same effect through Pflow. Its ok, but I cant get each particle to stay locked to the moving object. I think Ill stick to the method thats working for now!

    I did have a thought, at the moment I have to copy this script and amend for every character, as the name of the object is being used in it. I have tried just using $ but this errors on all 4 lines where the $objectname is used.

    Comment


    • #17
      Then you want to look into the for loop.

      It's pretty simple but gives you the ability to do fairly complex things on lots of objects. In your case the $ sign represents the single current object you have selected. Maxscript can sometimes use multiple objects with this syntax but not always. Instead using something like this:

      For i in selection do
      (
      i.radius = 20
      )

      So the first line just means for every object I have selected, do whatever commands are between the brackets to that object. The letter "i" is kind of the same as $ in your scripts, i starts off as meaning object 1 of the collection you have selected, then once it's looped through all of the commands between the brackets, "i" becomes object 2 and so on. There's also no particular reason for using the letter "i", you can use anything in there you want, once it's consistent in the script. When you start using a for loop inside another for loop, you need to use a unique letter or name for each for loop.
      Last edited by joconnell; 24-02-2011, 04:03 AM.

      Comment


      • #18
        Thanks Jo, that has now worked, but only when I have the object selected. Is there a way to get it working on any object its appied to, but without needing to select it?

        Or might there be a way to make this into a pre-render script, and have it effect all objects on a specific layer? No idea how to do that tho!!

        Thanks,
        Last edited by m_hinks; 24-02-2011, 04:45 AM.

        Comment


        • #19
          Yeah you've got to tell maxscript what to work on in the first place. One way to do this is to make a specific name for all your dummy objects and then use maxscript to collect those objects. For this you'll have to use an array. An array is just a collection of objects, this can be a collection of numbers, a collection of objects or any type of data really. For example if you wanted to select all the spheres in your scene and save them as a collection you can play with later, use Myarray = $sphere* as array which will make a selection of everything that has a name starting with sphere - be careful with this since you might get objects you don't want to affect. Make sure you use a really specific name for all your dummy objects just in case. Once you've got an array of your objects, you loop through them using the following syntax:

          Myarray = $sphere* as array

          for I = 1 to myarray.count do
          (
          myarray[i].radius = I * 10
          )

          So it's similar to the usual for loop with a few tweaks:

          Myarray = $sphere* as array - You're creating a new array called MyArray and loading all the objects in the scene with names that start with sphere. This is pretty much just a way of saving the objects for later access.

          For i = 1 to myarray.count do - this means that I is the letter being used as the count of the loop, and when looping through, start off with 1 and go all the way up to the total number of objects in the array called myarray. Similar to you using sphere_m.pos where .pos accesses the position property of an object, ".count" is a property of an array. So in this case the loop will start at 1 and keep going until it reaches the total number of objects in your array.

          myarray[i].radius = I * 10 - Okay so here you see how you pick an object in an array. You type the name of the array, then in square brackets following it, type in the number of the object you want to access. If you were to manually type myArray[1] it'll tell you the first object that got put into the array. In this particular case, myarray[1] represents the first sphere object, and that has a .radius property. So this line of code is a bit like typing sphere01.radius. Here to make sure it's working I've made the script assign a radius of 10 multiplied by the count number of our for loop so each sphere gets bigger.

          And that's it! There's a few different ways to use a for loop, some shorter than others, and they all offer different features. For example you've got really global ones like "for i in lights do" which will try and run on every object in the light category of objects in max. You've got "for i in shapes do" and other such loops for specific types of objects in max, "for i in selection do" for running through selections of objects, and the normal "for i = 1 to whatever do" for looping through data, or objects or things that don't fit into another category.

          Comment


          • #20
            wow! Perfect, Ill spend this afternoon going through this and see if I can get it working, many thanks.

            Ill be back asking about my morpher, and blending the morph I'm sure!

            Hope your late night was successful.

            M

            Comment


            • #21
              Thats really great, it works perfectly. I put the script on a ball, and removed it from all the peds. That script is now controlling the walk/idle of 10 peds perfectly.

              Thanks you very much. I cant seem to get a 300k zip file uploaded on here for you to see, dont know why?

              Here is the code;

              MyArray = $Ped* 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
              )

              So all that is left know is getting the transition in the morpher to be over 5/6 frames, not "on/Off"

              Thanks again.

              Comment


              • #22
                Probably something added on to the else WM3_MC_SetValue myarray[i].morpher 1 100.0 line.

                Look into controllers and keyframes so that you can set a key at frame t (with t being the current frame) with a value of 0.0 and then at frame [t + 6] add a keyframe with a value of 100.

                Comment


                • #23
                  Code:
                  MyArray = $Ped* as array
                  
                  for i = 1 to MyArray.count do
                  (
                       animate on (
                            for t in 0 to 100 by 5 do (
                                 at time t 
                                      WM3_MC_SetValue MyArray[i].morpher 1 t   -- the t variable is the frame time (0,5,10,15...100)
                            )
                       )
                       
                  )
                  I have no idea what the variable f is or anything so your code doesn't make any sense to me.

                  but try something like the above. I just can't decipher this without some of the variable information.
                  Colin Senner

                  Comment


                  • #24
                    Sorry Colin, the variables are just the pre-set ones in the script controller dialog.

                    f = frames
                    t = ticks
                    s = seconds
                    nt = norm time

                    I shall give your new script a go right now, thanks for your input.

                    Stupid question, but where would you put this script, or how would you have it running in a scene. I'm sure my way is not the best/right!!

                    M

                    Comment

                    Working...
                    X