• Login
sketchucation logo sketchucation
  • Login
ℹ️ GoFundMe | Our friend Gus Robatto needs some help in a challenging time Learn More

Working on new scripting system.

Scheduled Pinned Locked Moved SketchyPhysics
68 Posts 14 Posters 10.1k Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    CPhillips
    last edited by 19 May 2009, 04:32

    This code does not work with the current version and it may change before release. No ETA but its coming along well.
    I have been revamping the scripting system to make it much more flexible and powerful and I finally got the basics in place. Its pretty cool.

    There is a new scripted field like OnTick and OnTouch except the code that runs in that window is totally different.

    What you do is specify what happens when an event like touch or tick occurs. This script is the same as setting OnTick to "@count=0".

    setEvent("OnTick"){@count=0}
    

    Meaning every Tick set the variable @count=0

    Here is an more complex example that will keep track of how many times an object is touched.

    
    setEvent("onstart"){@count=0}
    setEvent("ontouch"){@count+=1}
    setEvent("onend"){puts "#{name} was touched #{@count} times."}
    
    

    First line says that at the start of the simulation set @count to 0. Unlike the current scrips @count is private to this object. So each object has its own version of @count. @@count would be public and shared among all objects.

    
    setEvent("OnTouch"){@count+=1}
    
    

    The first time an object touches me increase the count. Note. This event only fires the first time two objects start touching and not every frame like the current OnTouch. There is a new OnTouching event that does that.

    setEvent("OnEnd"){puts "#{name} was touched #{@count} times."}
    
    

    OnEnd is called at when the user ends the simulation. This prints the count in the ruby console. Not a very exciting example but it shows off some of the basics.

    Events so far are:
    OnStart=Start of simulation
    OnEnd=End of sim
    OnTick=Same as current OnTick
    OnTouch=Two objects start touching
    OnUntouch=Two object stop touching
    OnTouching=Same as current OnTouch
    OnKeyDown=Called once when the user presses a key
    OnKeyUp=Called once when the user releases a key

    I am planning on adding events for joystick buttons, timers and mouse click and drag.

    In the events you can now set most of the objects flags like hidden, nocollision, static, magnetic etc.

    
     #At sim start hide the object
    setEvent("onstart"){hidden=true}
    
       #When an object touches me...
    setEvent("ontouch"){|toucher|
       #if the object that touched me is named "box
      if toucher.name=="box"
         #unhide and become solid 
        hidden=false 
        nocollision=false
      end
    }
    
      #unhide group at end of sim
    setEvent("onend"){hidden=false}
    

    You can copy and push objects and soon and create and connect joints. This code in a "wheel" object it will automatically connect it to the object named "car" with a hinge.

    setEvent("onstart"){
      car=findBody("car")
      connectTo(car,"hinge")
    }
    
    

    Objects with this code act like they are covered in very sticky fly paper.😄

    setEvent("ontouch"){|toucher|
        #connect anything that touches me with a
        #fixed joint 
      connectTo(toucher,"fixed")
    }
    
    

    Some other things planned are teleporting and a fancy version of lookat.

    Chris

    1 Reply Last reply Reply Quote 0
    • P Offline
      pilou
      last edited by 19 May 2009, 07:52

      SDK maker 😮 😎

      Frenchy Pilou
      Is beautiful that please without concept!
      My Little site :)

      1 Reply Last reply Reply Quote 0
      • W Offline
        Wacov
        last edited by 19 May 2009, 09:11

        AWESOME

        Can we disconnect joints yet...?

        http://sketchup.google.com/3dwarehouse/cldetails?mid=3096a836877fb9af6cd8ad826e9017b8&prevstart=0

        1 Reply Last reply Reply Quote 0
        • S Offline
          Sgal
          last edited by 19 May 2009, 20:53

          It's possible to set the joints' variables with connectTo?
          Ad also, this innovations will need a lot of documentations.

          1 Reply Last reply Reply Quote 0
          • C Offline
            CPhillips
            last edited by 19 May 2009, 21:04

            Yes you can disconnect joints. Yes you can edit the joint parameters and yes it will need a lot of documents.

            1 Reply Last reply Reply Quote 0
            • P Offline
              Physicsguy1
              last edited by 19 May 2009, 22:45

              Teleporting?!?! I can't wait!

              1 Reply Last reply Reply Quote 0
              • B Offline
                BTM
                last edited by 19 May 2009, 23:18

                Teleporting. I was thinking about that. I was thinking that If I could find the identity %(#808080)[( 0x14758974, i think that kind of a thing. I used
                model = Sketchup.active_model
                selection = model.selection
                UI.messagebox selection

                to find it.)] of a group, I might be able to set it's position with a key, with the current version. I don't know though.

                1 Reply Last reply Reply Quote 0
                • C Offline
                  CPhillips
                  last edited by 20 May 2009, 01:05

                  Teleporting isnt possible in the current version. Even if you set the position of an object the physics engine would just move it back the next frame.

                  1 Reply Last reply Reply Quote 0
                  • W Offline
                    Wacov
                    last edited by 20 May 2009, 21:32

                    Could I make one small request? Could you set SP to run every script in a model once, when it is loaded? This would stop the error messages popping up when I try and edit a script that uses a method or variable, that's set in another script, which itself hasn't been run yet.

                    http://sketchup.google.com/3dwarehouse/cldetails?mid=3096a836877fb9af6cd8ad826e9017b8&prevstart=0

                    1 Reply Last reply Reply Quote 0
                    • C Offline
                      CPhillips
                      last edited by 20 May 2009, 22:39

                      Due to how they work I cant make it do that with the OnTouch and OnTick fields. But the new scripted field does it. Its a lot better.

                      1 Reply Last reply Reply Quote 0
                      • C Offline
                        CPhillips
                        last edited by 21 May 2009, 05:57

                        I got teleport working tonight. Its a lot of fun. I made a car that teleports back to the start if it flips over.

                        But disconnecting joints is proving to be difficult. If I want to maintain backward compatibility it might be that only certain joints can be disconnected.

                        1 Reply Last reply Reply Quote 0
                        • W Offline
                          Wacov
                          last edited by 21 May 2009, 10:34

                          With the teleportation, will the camera be moved if it's following a teleported object? And could you have a breakable object, which, when broken, teleports back to the starting position with all its joints intact?

                          I think as long as we can break fixed joints on command it should be alright. Oh, and I just thought of a possible solution to the deletion problem; maybe, while the simulation is running, you create a new, invisible layer. When the script 'deletes' an object, just move it into that layer and set its state to ignore... then just change it back and remove the new layer at the end of each simulation!

                          http://sketchup.google.com/3dwarehouse/cldetails?mid=3096a836877fb9af6cd8ad826e9017b8&prevstart=0

                          1 Reply Last reply Reply Quote 0
                          • C Offline
                            CPhillips
                            last edited by 21 May 2009, 20:37

                            Yes to the camera. I dont know about the breakable objects.

                            Next version you should be able to destroy objects.

                            1 Reply Last reply Reply Quote 0
                            • P Offline
                              phy
                              last edited by 21 May 2009, 21:08

                              This stuff is great. UM,can I ask when the next version is going to out. 😒 😄

                              Tableau de comparaison de Staxyn s'agit d'un mГ©dicament uniquement sur ordonnance.

                              1 Reply Last reply Reply Quote 0
                              • C Offline
                                CPhillips
                                last edited by 22 May 2009, 01:15

                                Not sure. Everytime I mention a date or a timeframe for a release I wind up missing it.

                                And speaking of breakable... I worked on something a little different today. 😄

                                shatter1.JPG
                                shatter2.JPG
                                shatter3.JPG

                                1 Reply Last reply Reply Quote 0
                                • B Offline
                                  BTM
                                  last edited by 22 May 2009, 01:33

                                  Awesome! THAT must have been hard to do 😕

                                  1 Reply Last reply Reply Quote 0
                                  • P Offline
                                    Physicsguy1
                                    last edited by 22 May 2009, 05:18

                                    Did you split that manually, or was it randomly split at the initiation of the simulation? And if you did figure out the script that splits an object, can you control the breaking force, if possible?

                                    1 Reply Last reply Reply Quote 0
                                    • C Offline
                                      CPhillips
                                      last edited by 22 May 2009, 06:08

                                      I wrote a script that splits an object N times and I call it from the new OnTouch event. So it is "broken" at collide time. Right now it is a totally random shatter rather than splits at the point of contact. But I might be able to make it to a more realistic now that OnTouch now has info about how fast and exactly where bodies collide.

                                      The other problem is the pieces don't inherit the movement of the original object. So that big box drops to the floor, stops on a dime and shatters, and then slowly falls to pieces. I need to figure out how to give the pieces velocity and rotation.

                                      1 Reply Last reply Reply Quote 0
                                      • W Offline
                                        Wacov
                                        last edited by 22 May 2009, 08:39

                                        Ok, that's REALLY awesome... first, does it split the actual geometry, or the collision mesh? And one important thing would be efficiency; would we be able to set the generated pieces to noCollision, and delete them after a timer? Or better yet, create the biggest pieces normally, but on a deletion timer, and make the smaller pieces noCollision.

                                        And I'm pretty sure it won't, but will it break in response to tension and/or internal stress? For example, putting a heavy weight in direct contact, without dropping it, or hitting it with an extremely powerful magnet.

                                        http://sketchup.google.com/3dwarehouse/cldetails?mid=3096a836877fb9af6cd8ad826e9017b8&prevstart=0

                                        1 Reply Last reply Reply Quote 0
                                        • P Offline
                                          phy
                                          last edited by 22 May 2009, 11:47

                                          That looks so cool, can't wait. But I have a question is this version going to still be sp3 or is it going to be spIV? Are we going to be able to control how many places the breakable script breaks? Also in the next version will we be able to group joints multiple times?

                                          Tableau de comparaison de Staxyn s'agit d'un mГ©dicament uniquement sur ordonnance.

                                          1 Reply Last reply Reply Quote 0
                                          • 1
                                          • 2
                                          • 3
                                          • 4
                                          • 1 / 4
                                          1 / 4
                                          • First post
                                            1/68
                                            Last post
                                          Buy SketchPlus
                                          Buy SUbD
                                          Buy WrapR
                                          Buy eBook
                                          Buy Modelur
                                          Buy Vertex Tools
                                          Buy SketchCuisine
                                          Buy FormFonts

                                          Advertisement