Setup for physics path behavior

Forum Forums Visual Components 4.0 Component Modeling Setup for physics path behavior

Visual Components Essentials has been officially released, download link

Be sure to read the Forum Rules and Guidelines before start using the Forum.

Tagged: , ,

This topic contains 21 replies, has 3 voices, and was last updated by line_out line_out 1 year, 7 months ago.

Viewing 7 posts - 16 through 22 (of 22 total)
  • Author
    Posts
  • #514
    line_out
    line_out
    Participant

    Basically, you can run to different scripts (remember to connect the signals to both scripts), one that handles outputs and one that handles inputs. Add the item and the port to a list in the signal handler, then process them in order in the onRun logic, however this won’t work if the order of the parts changes, e.g. if you have a physical stoppper inbetween, that only stops the physical parts, in that case, you will need some sensor before the output, to actually check what part is about to leave (like a volume sensor) .

    In newer versions the transition from logical path to physical path and the change of the kinematic type to be in physics from kinematics will (hopefully) be handled automatically. Things are still changing in the phys. implementation, so things might worker better in the near future.
    Input Script

    from vcScript import *
    
    def OnSignal( signal ):
      global queue
      if signal == partSignal and partSignal.Value:
        part = partSignal.Value
        isPartPhysics = False
        for b in part.Behaviours:
          if b.Type == "rPhysicsEntity":
            isPartPhysics = True
            break
        ##check if part can be transferred to physics path
        port = 0
        if isPartPhysics:
          connector = physicsPath.Connectors[0]
        else:
          connector = simPath.Connectors[0]
        queue.append( (part, port, connector) )
    
    def OnRun():
      global queue
      queue = []
      ##wait for part and then add to queue
      while True:
        condition(lambda: queue)
        part, port, connector = queue.pop(0)
        proxy.connectInternally(port,connector)
        triggerCondition(lambda: getTrigger() == pathSignal and pathSignal.Value)
        physEntity = part.findBehaviour('PhysicsEntity')
        if physEntity:
          type_ = physEntity.getProperty('Physics Type')
          type_ .Value = 0
        proxy.connectInternally(port, None)
          
    comp = getComponent()
    simPath = comp.findBehaviour("OneWayPath")
    physicsPath = comp.findBehaviour("PhysicsPath")
    proxy = comp.findBehaviour("ComponentFlowProxy")
    portSignal = proxy.PortSignal
    partSignal = proxy.ComponentSignal
    pathSignal = comp.findBehaviour("TransitionSignal")

    Output Script

    from vcScript import *
    
    def OnSignal( signal ):
      global queue
      if signal == partSignal and partSignal.Value:
        part = partSignal.Value
        isPartPhysics = False
        for b in part.Behaviours:
          if b.Type == "rPhysicsEntity":
            isPartPhysics = True
            break
        ##check if part can be transferred to physics path
        port = 1
        if isPartPhysics:
          connector = physicsPath.Connectors[1]
        else:
          connector = simPath.Connectors[1]
        queue.append( (part, port, connector) )
    
    def OnRun():
      global queue
      queue = []
      ##wait for part and then add to queue
      while True:
        condition(lambda: queue)
        part, port, connector = queue.pop(0)
        proxy.connectInternally(port,connector)
        try:
          physEntity = part.findBehaviour('PhysicsEntity')
        except: pass
        triggerCondition(lambda: getTrigger() == pathSignal and not pathSignal.Value)
        try:
          if physEntity and outIface.ConnectedComponent:
            type_ = physEntity.getProperty('Physics Type')
            type_ .Value = 1
        except: pass
        proxy.connectInternally(port,None)
          
    comp = getComponent()
    simPath = comp.findBehaviour("OneWayPath")
    physicsPath = comp.findBehaviour("PhysicsPath")
    proxy = comp.findBehaviour("ComponentFlowProxy")
    portSignal = proxy.PortSignal
    partSignal = proxy.ComponentSignal
    pathSignal = comp.findBehaviour("TransitionSignal")
    outIface = comp.findBehaviour("OneToOneInterface_1")
    #537
    zesty
    zesty
    Participant

    This is good work. Do you have the layout where that code works or 3D PDF?

    How should it work when a part exits a physics path and enters a sim path: should the part fall to the floor or set the Physics Type property to 0/None like you did in your code?

    #540
    line_out
    line_out
    Participant

    Well, in the normal case I would say that the part automatically would have its property changed to kinematics and driven on the simpath. Then again, if there is nothing connected to the end of the phys conveyor or the gap between the physics collider and the sim path is to large the part should fall to the floor. I can’t run that code any more since I have a newer version now, where some things allready have changed 🙂

    #544
    zesty
    zesty
    Participant

    Yes, does not work for me either. The parts just sit at the gate and never enter paths. May I ask why you set the PhysicsType to 0 when part enters Physics path?

    #547
    line_out
    line_out
    Participant

    Hi, that is the enumerator for InPhysics, when the part were traveling on the normal path the mode was set to Kinematics, which means that the phys path can’t interact witht the part.

    #549
    zesty
    zesty
    Participant

    So for physics path:

    • PhysicsPath behavior
    • PhysicsEntity behavior with Physics Type property set to #Kinematic
    • Node root feature Collider property set to #Boxes

    And for physics part used in material flow:

    • PhysicsEntity behavior with Physics Type property set to #In Physics for physics paths and #Out of Physics for sim paths

    This feels like progress. So in a way I could define a new flow type behavior for handling sim and physics path routes and Physics Type settings like a Behavior add-on?

    #550
    line_out
    line_out
    Participant

    For now maybe an add-on is the right way to go if you want to resolve this particular problem. There might however be better ways of doing this in the future. But hopefully it will work out of the box later on, sicne the physics implementation is still under devlopment.

    Anyway for the part, #Kinematics should work fine as well, depending on what you are doing.

Viewing 7 posts - 16 through 22 (of 22 total)

You must be logged in to reply to this topic.