示例#1
0
文件: device.py 项目: vrsys/avango
class MouseDevice(avango.script.Script):

    RelX = avango.SFFloat()
    RelY = avango.SFFloat()

    ButtonLeft = avango.SFBool()
    ButtonRight = avango.SFBool()

    def __init__(self):
        self.super(MouseDevice).__init__()

        self.device_sensor = avango.daemon.nodes.DeviceSensor(
            DeviceService=avango.daemon.DeviceService())
        self.device_sensor.Station.value = "gua-device-mouse"

        self.always_evaluate(True)

    def evaluate(self):

        self.RelX.value = 0.0
        self.RelY.value = 0.0

        rel_x = self.device_sensor.Value0.value
        if rel_x >= 2 or rel_x <= -2:
            self.RelX.value = rel_x

        rel_y = self.device_sensor.Value1.value
        if rel_y >= 2 or rel_y <= -2:
            self.RelY.value = rel_y

        self.ButtonLeft.value = self.device_sensor.Button0.value
        self.ButtonRight.value = self.device_sensor.Button1.value
示例#2
0
class SwingMatrix(avango.script.Script):
    TimeIn = avango.SFFloat()
    Scale = avango.SFFloat()
    MatrixOut = avango.osg.SFMatrix()

    def evaluate(self):
        self.MatrixOut.value = avango.osg.make_trans_mat(
            0., self.Scale.value * math.sin(self.TimeIn.value), 0.)
示例#3
0
class BallSpawner(avango.script.Script):

  TimeIn = avango.SFFloat()
  SceneGraph = avango.gua.SFSceneGraph()
  Physics = avango.gua.SFPhysics()
  MaxBallCount = avango.SFFloat()

  def __init__(self):

    self.super(BallSpawner).__init__()

    self.MaxBallCount.value = 50

    self.__last_spawn_time = -1
    self.__loader = avango.gua.nodes.TriMeshLoader()

    self.__spawned_balls = []

  def evaluate(self):
    global SPAWN_TIME
    current_time = self.TimeIn.value

    if self.__last_spawn_time == -1 or current_time - self.__last_spawn_time >= SPAWN_TIME:
      self.__last_spawn_time = current_time

      light_rb = avango.gua.nodes.RigidBodyNode(
        Name = "light_rb",
        Mass = 1.0,
        Friction = 0.6,
        RollingFriction = 0.03,
        Restitution = 1.0,
        Transform = avango.gua.make_trans_mat(math.sin(current_time) * 0.3, 1.5, 0.0)
      )

      light_geometry = self.__loader.create_geometry_from_file(
        "light_geometry", "data/objects/sphere.obj"
      )

      light_geometry.Transform.value = avango.gua.make_scale_mat(0.1, 0.1, 0.1)

      light_csn = avango.gua.nodes.CollisionShapeNode(
        Name = "light_csn",
        ShapeName = "sphere"
      )

      light_csn.Children.value.append(light_geometry)
      light_rb.Children.value.append(light_csn)
      self.SceneGraph.value.Root.value.Children.value.append(light_rb)
      self.Physics.value.add_rigid_body(light_rb)

      self.__spawned_balls.append(light_rb)

      if len(self.__spawned_balls) > self.MaxBallCount.value:
        to_remove = self.__spawned_balls.pop(0)
        self.Physics.value.remove_rigid_body(to_remove)
        self.SceneGraph.value.Root.value.Children.value.remove(to_remove)
示例#4
0
文件: main.py 项目: wobakj/avango
class TimedRotate(avango.script.Script):
    TimeIn = avango.SFFloat()
    MatrixOut = avango.gua.SFMatrix4()
    RotationSpeed = avango.SFFloat()

    def __init__(self):
        self.super(TimedRotate).__init__()
        self.RotationSpeed.value = 2.0

    @field_has_changed(TimeIn)
    def update(self):
        self.MatrixOut.value = avango.gua.make_rot_mat(
            self.TimeIn.value * self.RotationSpeed.value, 0.0, 1.0, 0.0)
示例#5
0
class Float2Vec2Converter(avango.script.Script):
    "Converts two Floats into on Vec2"

    Value0 = avango.SFFloat()
    Value1 = avango.SFFloat()
    Output = avango.gua.SFVec2()
    
    def __init__(self):
        self.super(Float2Vec2Converter).__init__()
        
        self.Name.value = "Float2Vec2Converter"
        

    def evaluate(self):
        self.Output.value = avango.gua.Vec2(self.Value0.value, self.Value1.value)
示例#6
0
class DeviceRotate(avango.script.Script):

    # input fields from device
    RotX = avango.SFFloat()
    RotY = avango.SFFloat()
    RotZ = avango.SFFloat()

    # output field: rotation matrix
    MatrixOut = avango.gua.SFMatrix4()

    def evaluate(self):
        self.MatrixOut.value = \
            avango.gua.make_rot_mat(self.RotX.value * 90.0, 1.0, 0.0, 0.0) * \
            avango.gua.make_rot_mat(self.RotY.value * 90.0, 0.0, 1.0, 0.0) * \
            avango.gua.make_rot_mat(self.RotZ.value * 90.0, 0.0, 0.0, 1.0)
示例#7
0
class Float2Add(avango.script.Script):
    "Adds two float values"

    Value0 = avango.SFFloat()
    Value1 = avango.SFFloat()

    Output = avango.SFFloat()
    
    def __init__(self):
        self.super(Float2Add).__init__()
        
        self.Name.value = "Float2Add"

    def evaluate(self):
        self.Output.value = self.Value0.value + self.Value1.value
示例#8
0
class Vec3(avango.script.Script):

    # Input
    X = avango.SFFloat()
    Y = avango.SFFloat()
    Z = avango.SFFloat()

    # Output
    Vector = avango.gua.SFVec3()

    def __init__(self):
        self.super(Vec3).__init__()

        self.Name.value = "Vec3"

        self.X.value = 0.0
        self.Y.value = 0.0
        self.Z.value = 0.0
        self.Vector.value = avango.gua.Vec3(0.0, 0.0, 0.0)

    def constructor(self, json, app):
        self.Name.value = json["name"]

        values = json["values"]
        self.X.value = values["X"]
        self.Y.value = values["Y"]
        self.Z.value = values["Z"]

        app.add_field_container(self)

        for connection in json["field_connections"]:
            app.plan_field_connection(
                self.Name.value,
                connection["from_field"],
                connection["to_node"],
                connection["to_field"],
            )

    def set_field_value(self, field_name, value):
        field = self.get_field(field_name)
        field.value = value

    def evaluate(self):
        self.Vector.value = avango.gua.Vec3(
            self.X.value,
            self.Y.value,
            self.Z.value,
        )
示例#9
0
class FloatMath(avango.script.Script):

    # Input
    First = avango.SFFloat()
    Second = avango.SFFloat()
    # Output
    Result = avango.SFFloat()

    operator_dict = {
        'ADD': function_add,
        'SUBTRACT': function_sub,
        'MULTIPLY': function_mult,
        'DIVIDE': function_div,
        'POWER': function_pow,
        'MODULO': function_mod,
        'ROOT': function_root,
        'SINUS': function_sin
    }

    def __init__(self):
        self.super(FloatMath).__init__()
        self.Name.value = "FloatMath"
        self.First.value = 0.0
        self.Second.value = 0.0

    def constructor(self, json, app):
        self.Name.value = json["name"].replace('.', '_')

        values = json["values"]
        self.First.value = values["First"]
        self.Second.value = values["Second"]

        app.add_field_container(self)

        for connection in json["field_connections"]:
            app.plan_field_connection(self.Name.value,
                                      connection["from_field"],
                                      connection["to_node"],
                                      connection["to_field"])

        self.operator = FloatMath.operator_dict[json["operator"]]

    def set_field_value(self, field_name, value):
        field = self.get_field(field_name)
        field.value = value

    def evaluate(self):
        self.Result.value = self.operator(self.First.value, self.Second.value)
class TUIOCursor(avango.script.Script):
    PosX = avango.SFFloat()
    PosY = avango.SFFloat()
    SpeedX = avango.SFFloat()
    SpeedY = avango.SFFloat()
    MotionSpeed = avango.SFFloat()
    MotionAcceleration = avango.SFFloat()
    IsMoving = avango.SFBool()
    State = avango.SFFloat()
    SessionID = avango.SFFloat()
    CursorID = avango.SFInt()
    IsTouched = avango.SFBool()
    MovementVector = avango.gua.SFVec2()

    def __init__(self):
        self.super(TUIOCursor).__init__()

        # initialize fields
        self.PosX.value = -1.0
        self.PosY.value = -1.0
        self.State.value = 4.0
        self.SessionID.value = -1.0
        self.MovementVector.value = avango.gua.Vec2(0, 0)

        self.device_sensor = avango.daemon.nodes.DeviceSensor(
            DeviceService=avango.daemon.DeviceService())
        self.PosX.connect_from(self.device_sensor.Value0)
        self.PosY.connect_from(self.device_sensor.Value1)
        self.SpeedX.connect_from(self.device_sensor.Value2)
        self.SpeedY.connect_from(self.device_sensor.Value3)
        self.MotionSpeed.connect_from(self.device_sensor.Value4)
        self.MotionAcceleration.connect_from(self.device_sensor.Value5)
        self.IsMoving.connect_from(self.device_sensor.Value6)
        self.State.connect_from(self.device_sensor.Value7)
        self.SessionID.connect_from(self.device_sensor.Value8)

    def updateTouched(self):
        """
        Call whenever some touch input data has changed. This method will update self.IsTouched accordingly.
        """
        self.IsTouched.value = (self.PosX.value != -1.0
                                and self.PosY.value != -1.0)

    @field_has_changed(CursorID)
    def set_station(self):
        """
        Set station name.
        """
        self.device_sensor.Station.value = "gua-finger{}#cursor".format(
            self.CursorID.value)

    @field_has_changed(PosX)
    def updatePosX(self):
        self.updateTouched()

    @field_has_changed(PosY)
    def updatePosY(self):
        self.updateTouched()
示例#11
0
class Hinge(avango.script.Script):

    ## input fields
    sf_rot_value = avango.SFFloat()

    # Number of Hinge instances that have already been created.
    number_of_instances = 0
    angle = 40
    hook = None

    ## constructor
    def __init__(self):
        self.super(Hinge).__init__()

        ## get unique id for this instance
        self.id = Hinge.number_of_instances
        Hinge.number_of_instances += 1

    def my_constructor(
        self,
        PARENT_NODE=None,
        DIAMETER=0.1,  # in meter
        HEIGHT=0.1,  # in meter
        ROT_OFFSET_MAT=avango.gua.make_identity_mat(
        ),  # the rotation offset relative to the parent coordinate system
        ROT_AXIS=avango.gua.Vec3(
            0, 1, 0
        ),  # the axis to rotate arround with the rotation input (default is head axis)        
        SF_ROT_INPUT_MAT=None):
        self.ROT_OFFSET_MAT = ROT_OFFSET_MAT
        self.ROT_AXIS = ROT_AXIS
        self.SF_ROT_INPUT_MAT = SF_ROT_INPUT_MAT
        _loader = avango.gua.nodes.TriMeshLoader(
        )  # get trimesh loader to load external tri-meshes
        self.matrix = avango.gua.nodes.TransformNode(Name="Hinge")
        self.matrix.Transform.value = self.ROT_OFFSET_MAT
        PARENT_NODE.Children.value.append(self.matrix)

        angle = 90 if self.ROT_AXIS[2] == 1 else 0

        self.obj = _loader.create_geometry_from_file(
            "obj", "data/objects/cylinder.obj",
            avango.gua.LoaderFlags.DEFAULTS)
        self.obj.Transform.value = \
         avango.gua.make_rot_mat(angle, 1, 0, 0) * \
         avango.gua.make_scale_mat(DIAMETER, HEIGHT, DIAMETER)
        self.obj.Material.value.set_uniform("Color",
                                            avango.gua.Vec4(1.0, .0, .0, 1))
        self.matrix.Children.value.append(self.obj)

    @field_has_changed(sf_rot_value)
    def sf_rot_value_changed(self):
        pass
        self.angle += self.sf_rot_value.value * 50
        self.angle = min(max(self.angle, self.SF_ROT_INPUT_MAT[0]),
                         self.SF_ROT_INPUT_MAT[1])
        self.matrix.Transform.value = self.ROT_OFFSET_MAT * \
         avango.gua.make_rot_mat(self.angle, self.ROT_AXIS)
        if self.hook != None:
            self.hook.sf_mat.value = self.hook.obj.WorldTransform.value
示例#12
0
class RotationAnimator(avango.script.Script):

    # input field
    sf_rotation_speed = avango.SFFloat()
    sf_rotation_speed.value = 40.0  # deg/s

    # output field
    sf_rot_mat = avango.gua.SFMatrix4()
    sf_rot_mat.value = avango.gua.make_identity_mat()

    def __init__(self):
        self.super(RotationAnimator).__init__()
        # YOUR CODE - BEGIN (Exercise 2.8 - Frame-Rate Independent Mapping of Bird)
        self.start_time = time.time()
        # YOUR CODE - END (Exercise 2.8 - Frame-Rate Independent Mapping of Bird)
        self.always_evaluate(True)

    # called every frame because of self.always_evaluate(True)
    def evaluate(self):
        # YOUR CODE - BEGIN (Exercise 2.8 - Frame-Rate Independent Mapping of Bird)
        new_time = time.time()
        elapsed_time = new_time - self.start_time
        self.start_time = new_time
        new_angle = self.sf_rotation_speed.value * elapsed_time
        self.sf_rot_mat.value = avango.gua.make_rot_mat(new_angle, 0, 1, 0) * \
            self.sf_rot_mat.value
示例#13
0
class RotateMatrix(avango.script.Script):
    TimeIn = avango.SFFloat()
    MatrixOut = avango.osg.SFMatrix()

    def evaluate(self):
        self.MatrixOut.value = avango.osg.make_rot_mat(self.TimeIn.value, 0.,
                                                       1., 0.)
示例#14
0
class Accumulator(avango.script.Script):
    ## declaration of fields
    sf_rot_input = avango.SFFloat()

    sf_mat = avango.gua.SFMatrix4()
    sf_mat.value = avango.gua.make_identity_mat(
    )  # initialize field with identity matrix
    hinge_id = 0

    ## constructor
    def __init__(self):
        self.super(Accumulator).__init__()  # call base-class constructor

    ## callback functions
    def evaluate(self):
        # perform update when fields change (with dependency evaluation)
        print("accum eval")

        # ToDo: accumulate rotation input here
        # 3.2
        rot_mat = None

        # rotate around y axis for base, other wise x
        if self.hinge_id == 0:
            rot_mat = avango.gua.make_rot_mat(self.sf_rot_input.value, 0, 1, 0)
            print("dmm")
        else:
            rot_mat = avango.gua.make_rot_mat(self.sf_rot_input.value, 0, 1, 0)

        self.sf_mat.value = self.sf_mat.value * avango.gua.make_rot_mat(
            self.sf_rot_input.value, 0, 1, 0)
示例#15
0
class TransformSmoother(avango.script.Script):
  InTransform = avango.gua.SFMatrix4()
  OutTransform = avango.gua.SFMatrix4()
  Smoothness = avango.SFFloat()

  def __init__(self):
    self.super(TransformSmoother).__init__()
    self.always_evaluate(True)
    self.InTransform.value = avango.gua.make_identity_mat()
    self.OutTransform.value = avango.gua.make_identity_mat()

  def evaluate(self):
    if math.isnan(self.OutTransform.value.get_element(0,0)):
      self.OutTransform.value = avango.gua.make_identity_mat()
    in_translate = self.InTransform.value.get_translate()
    in_rotation = self.InTransform.value.get_rotate_scale_corrected()
    in_scale = self.InTransform.value.get_scale()

    out_translate = self.OutTransform.value.get_translate()
    out_rotation = self.OutTransform.value.get_rotate_scale_corrected()
    out_scale = self.OutTransform.value.get_scale()

    out_translate = out_translate * (1.0 - self.Smoothness.value) + in_translate * self.Smoothness.value
    out_rotation = out_rotation.slerp_to(in_rotation, self.Smoothness.value)
    out_scale = out_scale * (1.0 - self.Smoothness.value) + in_scale * self.Smoothness.value

    self.OutTransform.value = avango.gua.make_trans_mat(out_translate) *\
                              avango.gua.make_rot_mat(out_rotation) *\
                              avango.gua.make_scale_mat(out_scale)
示例#16
0
 def testWriteSFFloat(self):
     field = avango.SFFloat()
     field.value = float(1.2)
     hout = StringIO.StringIO()
     connect.write("A", field, hout)
     self.assertFloatListEqual("A\x00SFFloat\x00", "1.2", "\n",
                               hout.getvalue())
示例#17
0
class TimedKeyToggling(avango.script.Script):
    TimeIn = avango.SFFloat()
    MatrixOut = avango.gua.SFMatrix4()

    keyboard_events = 0
    logging_node = 0

    frame_time_dict = dict()

    num_entries = 0

    def set_logging_node(self, ln):
        self.logging_node = ln

    def set_keyboard_events(self, keyboard):
        self.keyboard_events = keyboard

    @field_has_changed(TimeIn)
    def update(self):
        if (0 != self.logging_node) and (0 != self.keyboard_events):
            if self.keyboard_events.logging_enabled:
                #print("XXXXXX")
                self.logging_node.Tags.value = ["X"]

                if self.num_entries == 0:
                    self.frame_time_dict[4.13123123] = 0.0
                else:
                    self.frame_time_dict[4.13123123] += 1.1

                self.num_entries = self.num_entries + 1
            else:
                self.logging_node.Tags.value = []

                if self.num_entries != 0:
                    pass
class TimedSwayingUpdate(avango.script.Script):

  ## @var TimeIn
  # Field containing the current time in seconds.
  TimeIn = avango.SFFloat()

  ## @var SFRotMat
  # Field containing the rotation being calculated by this class.
  SFRotMat = avango.gua.SFMatrix4()

  # parameters
  ## @var max_rot_offset
  # Maximum rotation in degrees
  max_rot_offset = 1.0 

  ## @var frequency
  # Frequency to be applied.
  frequency      = 0.1

  ## Called whenever TimeIn changes.
  @field_has_changed(TimeIn)
  def update(self):
    #calculate rotation of the ship
    self.SFRotMat.value = avango.gua.make_rot_mat( self.max_rot_offset * math.sin( (20 * self.frequency * self.TimeIn.value) / math.pi ),
                          0, 0, 1)
示例#19
0
class FloatToAlphaConverter(avango.script.Script):
    ColorIn = avango.gua.SFVec4()
    Alpha = avango.SFFloat()
    Color = avango.gua.SFVec4()
    
    def __init__(self):
        self.super(FloatToAlphaConverter).__init__()
        self.__alpha_changed = False
        self.__color_in = avango.gua.Vec4(1,1,1,1)
        self.Name.value = "FloatToAlphaConverter"
        
    @field_has_changed(ColorIn)
    def color_in_changed(self):
        self.__color_in = self.ColorIn.value
    
    @field_has_changed(Alpha)
    def alpha_changed(self):
        self.__alpha_changed = True
        
    def evaluate(self):
        print "eval: " + str(self.Alpha.value)
        if self.__alpha_changed:
            
            self.Color.value = avango.gua.Vec4(self.__color_in.x, self.__color_in.y, self.__color_in.z, self.Alpha.value)
            self.__alpha_changed = False
class Shot(avango.script.Script):

    ## @var sf_abs_mat
    # Field representing the translation and rotation matrix of this shot.
    sf_abs_mat = avango.gua.SFMatrix4()

    ## @var sf_scale
    # Field representing the scaling of this shot.
    sf_scale = avango.SFFloat()

    ## @var sf_viewing_mode
    # Field representing the viewing mode of this shot.
    sf_viewing_mode = avango.SFString()

    ## @var sf_camera_mode
    # Field representing the camera mode of this shot.
    sf_camera_mode = avango.SFString()

    ## @var sf_negative_parallax
    # Field representing the negative parallax state of this shot.
    sf_negative_parallax = avango.SFString()

    ## Default constructor.
    def __init__(self):
        self.super(Shot).__init__()

    ## Custom constructor.
    def my_constructor(self, ABS_MAT, SCALE, VIEWING_MODE, CAMERA_MODE,
                       NEGATIVE_PARALLAX):

        self.sf_abs_mat.value = ABS_MAT
        self.sf_scale.value = SCALE
        self.sf_viewing_mode.value = VIEWING_MODE
        self.sf_camera_mode.value = CAMERA_MODE
        self.sf_negative_parallax.value = NEGATIVE_PARALLAX
示例#21
0
class TimedUpdateTrackingInfo(avango.script.Script):
    TimeIn = avango.SFFloat()
    CentralUserMatrixOut = avango.gua.SFMatrix4()

    #CentralUser = avango.gua.SFMatrix4()

    DeviceSensorGlassesA = avango.daemon.nodes.DeviceSensor(
        DeviceService=avango.daemon.DeviceService())
    DeviceSensorGlassesA.Station.value = "tracking-dbl-glasses-A"
    DeviceSensorGlassesA.TransmitterOffset.value = avango.gua.make_trans_mat(
        0.0, 0.045, 0.0)
    """
    keyboard_events = 0
    logging_node = 0

    frame_time_dict = dict()

    num_entries = 0

    def set_logging_node(self, ln):
        self.logging_node = ln

    def set_keyboard_events(self, keyboard):
        self.keyboard_events = keyboard
    """
    @field_has_changed(TimeIn)
    def update(self):
        self.CentralUserMatrixOut.value = self.DeviceSensorGlassesA.Matrix.value
示例#22
0
class RotationAnimator(avango.script.Script):

    # input field
    sf_rotation_speed = avango.SFFloat()
    sf_rotation_speed.value = 40.0  # deg/s

    # output field
    sf_rot_mat = avango.gua.SFMatrix4()
    sf_rot_mat.value = avango.gua.make_identity_mat()

    def __init__(self):
        self.super(RotationAnimator).__init__()
        # YOUR CODE - BEGIN (Exercise 2.8 - Frame-Rate Independent Mapping of Bird)
        self.time_before_frame = 0
        self.current_time = time.time()
        # YOUR CODE - END (Exercise 2.8 - Frame-Rate Independent Mapping of Bird)
        self.always_evaluate(True)

    # called every frame because of self.always_evaluate(True)
    def evaluate(self):

        self.rot = 0.1 if self.current_time - self.time_before_frame < 0.005 else 1.25

        self.sf_rot_mat.value =  avango.gua.make_rot_mat(self.rot, 0, 1, 0) * avango.gua.make_rot_mat(0.1, 0, 1, 0) * \
                self.sf_rot_mat.value
        self.time_before_frame = self.current_time
        self.current_time = time.time()
示例#23
0
文件: led_wall.py 项目: wobakj/avango
class RadiusRumbler(avango.script.Script):

    Trigger = avango.SFBool()
    Radius = avango.SFFloat()

    def __init__(self):
        self.super(RadiusRumbler).__init__()
        self._rad_delta = 0.02
        self._enlarge = True

    @field_has_changed(Trigger)
    def trigger_changed(self):
        if self.Trigger.value:
            self.always_evaluate(True)
        else:
            self.always_evaluate(False)

    def evaluate(self):
        if self.Trigger.value:
            delta = self._rad_delta
            if not self._enlarge:
                delta = -delta

            self.Radius.value += delta
            self._enlarge = not self._enlarge
示例#24
0
class TimedRotate(avango.script.Script):
    TimeIn = avango.SFFloat()
    MatrixOut = avango.gua.SFMatrix4()

    def evaluate(self):
        self.MatrixOut.value = avango.gua.make_rot_mat(
            self.TimeIn.value * 10.0, 0.0, 1.0, 0.0)
示例#25
0
文件: main.py 项目: vrsys/avango
class SunUpdater(avango.script.Script):

    TimeIn = avango.SFFloat()
    TimeScale = avango.SFFloat()

    MatrixOut = avango.gua.SFMatrix4()
    DirectionOut = avango.gua.SFVec3()
    SunColorOut = avango.gua.SFColor()
    GroundColorOut = avango.gua.SFColor()
    BlendFactorOut = avango.SFFloat()

    def __init__(self):
        self.super(SunUpdater).__init__()
        self.city = a["Berlin"]

    @field_has_changed(TimeIn)
    def update(self):
        date = datetime.utcnow() + timedelta(
            0, self.TimeIn.value * self.TimeScale.value)
        azimuth = get_azimuth(self.city, date)
        elevation = get_elevation(self.city, date)

        r = g = b = 0.0

        if (elevation > 0):
            r = g = b = elevation / 90
            r = pow(r, 0.3) * 1.3
            g = pow(g, 0.4) * 1.2
            b = pow(b, 0.5) * 1.6

        self.SunColorOut.value = avango.gua.Color(r, g, b)
        self.MatrixOut.value = avango.gua.make_rot_mat(
            azimuth, 0, 1, 0) * avango.gua.make_rot_mat(-elevation, 1, 0, 0)
        direcion = self.MatrixOut.value * avango.gua.Vec3(0, 0, -1)
        self.DirectionOut.value = avango.gua.Vec3(direcion.x, direcion.y,
                                                  direcion.z)

        self.BlendFactorOut.value = 0.0

        if elevation / 90 < 0:
            self.BlendFactorOut.value = abs(elevation / 90) * 5

        if direcion.y > 0:
            val = max(0.2 - direcion.y, 0)
            self.GroundColorOut.value = avango.gua.Color(val, val, val)
        else:
            self.GroundColorOut.value = avango.gua.Color(0.5, 0.5, 0.5)
示例#26
0
class TimedRotate(avango.script.Script):
    TimeIn = avango.SFFloat()
    MatrixOut = avango.gua.SFMatrix4()

    @field_has_changed(TimeIn)
    def update(self):
        self.MatrixOut.value = avango.gua.make_rot_mat(self.TimeIn.value * 2.0,
                                                       0.0, 1.0, 0.0)
示例#27
0
class TimedRotate(avango.script.Script):
    TimeIn = avango.SFFloat()
    MatrixOut = avango.gua.SFMatrix4()

    def evaluate(self):
        #move the abstract geometry in a pseudo-random manner
        self.MatrixOut.value = avango.gua.make_rot_mat(math.sin(0.5*self.TimeIn.value) * 50.0,
                                                       1.0, 1.0, 0.0) * avango.gua.make_rot_mat(math.cos(1.5*self.TimeIn.value) * 150.0, 0.0, 0.0, 1.0) * avango.gua.make_rot_mat(math.sin(10*self.TimeIn.value) * 15.0, 1.0, 0.0, 1.0)
class DayAnimationUpdate(avango.script.Script):

  ## @var TimeIn
  # Field containting the current time in seconds.
  TimeIn = avango.SFFloat()

  ## @var sf_sun_mat
  # Field containing the calculated rotation matrix for the sun.
  sf_sun_mat = avango.gua.SFMatrix4()

  ## @var day_time
  # The length of one day in seconds.
  day_time = 5 * 30.0

  ## @var morning_sun_color
  # The color of the sun at sunrise.
  morning_sun_color = avango.gua.Color(0.9, 0.65, 0.65)

  ## @var noon_sun_color
  # The color of the sun at noon.
  noon_sun_color = avango.gua.Color(1.0, 0.8, 0.8)

  ## @var evening_sun_color
  # The color of the sun at sunset.
  evening_sun_color = morning_sun_color

  ## @var sf_sun_color
  # The color of the sun.
  sf_sun_color = avango.gua.SFColor()
  sf_sun_color.value = morning_sun_color

  ## Linearly interpolates between two colors according to a given ratio.
  # @param START_COLOR The starting value for a ratio of 0.
  # @param TARGET_COLOR The final value for a ratio of 1.
  # @param RATIO A value between 0 and 1 that determines the interpolated result.
  def lerp_color(self, START_COLOR, TARGET_COLOR, RATIO):
    _start_vec  = avango.gua.Vec3(START_COLOR.r, START_COLOR.g, START_COLOR.b)
    _end_vec    = avango.gua.Vec3(TARGET_COLOR.r, TARGET_COLOR.g, TARGET_COLOR.b)
    _lerp_vec   = _start_vec.lerp_to(_end_vec, RATIO)
    return avango.gua.Color(_lerp_vec.x, _lerp_vec.y, _lerp_vec.z)

  ## Called whenever TimeIn changes.
  @field_has_changed(TimeIn)
  def update(self):

    # set position of the sun
    _sun_angle = ((self.TimeIn.value % self.day_time) / self.day_time) * 360.0

    self.sf_sun_mat.value =  avango.gua.make_rot_mat(-_sun_angle, 1, 0, 0) * \
                             avango.gua.make_rot_mat(-30.0, 0, 1, 0)

    # update the sun color
    # between morning and noon
    if _sun_angle < 45:  
      self.sf_sun_color.value = self.lerp_color(self.morning_sun_color, self.noon_sun_color, _sun_angle / 45.0)
    # between noon and evening
    elif (_sun_angle > 135) and (_sun_angle < 180): 
      self.sf_sun_color.value = self.lerp_color(self.noon_sun_color, self.evening_sun_color, (_sun_angle - 135.0) / 45.0)
示例#29
0
class PropertyModifierInt(avango.script.Script):

    Enable = avango.SFBool()
    TimeIn = avango.SFDouble()

    Property = avango.SFInt()
    PropertyMin = avango.SFInt()
    PropertyMax = avango.SFInt()

    PropertyStepSize = avango.SFInt()
    PropertyInc = avango.SFBool()
    PropertyDec = avango.SFBool()
    TriggerTimeDelta = avango.SFFloat()

    Triggered = avango.SFBool()

    def __init__(self):
        self.super(PropertyModifierInt).__init__()

        self.last_trigger_time = self.TimeIn.value
        self.Enable.value = False

        self.Property.value = 0
        self.PropertyMin.value = 0
        self.PropertyMax.value = 100000

        self.PropertyStepSize.value = 1
        self.PropertyInc.value = False
        self.PropertyDec.value = False
        self.TriggerTimeDelta.value = 0.05

        self.always_evaluate(True)

        self.Name.value = "PropertyModifierInt"

    def evaluate(self):

        if (not self.PropertyInc.value
                and not self.PropertyDec.value) or not self.Enable.value:
            return

        time = self.TimeIn.value
        time_delta = time - self.last_trigger_time
        if time_delta > self.TriggerTimeDelta.value:

            if self.PropertyInc.value:
                new_val = self.Property.value + self.PropertyStepSize.value
                if new_val <= self.PropertyMax.value:
                    self.Property.value = new_val
                    self.Triggered.value = True
                self.last_trigger_time = time

            elif self.PropertyDec.value:
                new_val = self.Property.value - self.PropertyStepSize.value
                if new_val >= self.PropertyMin.value:
                    self.Property.value = new_val
                    self.Triggered.value = True
                self.last_trigger_time = time
示例#30
0
class DoubleTapDetector(avango.script.Script):
    DoubleTapPositions = avango.gua.MFVec2()
    DoubleTapTimeThreshold = avango.SFFloat()  # in seconds
    DoubleTapDistanceThreshold = avango.SFFloat()  # in NDC

    def __init__(self):
        self.super(DoubleTapDetector).__init__()
        self.always_evaluate(True)

        self.DoubleTapTimeThreshold.value = 0.5
        self.DoubleTapDistanceThreshold.value = 0.01

        self.__timer = avango.nodes.TimeSensor()
        self.__cursors = []
        self.__tap_detectors = []
        self.reset()

    def reset(self):
        self.DoubleTapPositions.value = []

        self.__first_taps = []

    def add_cursor(self, touch_cursor):
        self.__cursors.append(touch_cursor)
        tap_detector = TapDetector()
        tap_detector.Cursor = touch_cursor
        self.__tap_detectors.append(tap_detector)

    def evaluate(self):

        for tap in self.__first_taps:
            for detector in self.__tap_detectors:
                if detector.TapDetected.value == True:
                    if self.__timer.Time.value - tap[0] <= self.DoubleTapTimeThreshold.value and \
                       (detector.TapPosition.value - tap[1]).length() <= self.DoubleTapDistanceThreshold.value:

                        self.DoubleTapPositions.value.append(
                            (detector.TapPosition.value + tap[1]) / 2.0)
                        detector.reset()

        for detector in self.__tap_detectors:
            if detector.TapDetected.value == True:
                self.__first_taps.append(
                    (self.__timer.Time.value, detector.TapPosition.value))
                detector.reset()