Exemplo n.º 1
0
    def testFlushStreamInInput(self):
        stream = SimpleStream()
        node = AInputNode()
        node.set_stream(stream)
        avango.evaluate()

        self.assert_(stream.flushed)
Exemplo n.º 2
0
    def testDynamicFieldRemoval(self):
        node1 = DynamicFieldScript()
        #Every script node has a Name field by default
        self.assertEqual(1, node1._get_num_fields())
        node1.add_dynamic_int_fields("field_", 1)
        self.assertEqual(2, node1._get_num_fields())

        node2 = DynamicFieldScript()
        self.assertEqual(1, node2._get_num_fields())
        node2.add_dynamic_int_fields("field_", 1)
        self.assertEqual(2, node2._get_num_fields())

        self.assertEqual(0, node1._get_field("field_0").get_number_of_connected_fields())
        node1._get_field("field_0").connect_from(node2._get_field("field_0"))
        self.assertEqual(1, node1._get_field("field_0").get_number_of_connected_fields())

        node2._get_field("field_0").value = 42
        avango.evaluate()
        self.assertEqual(42, node1._get_field("field_0").value)

        node2.remove_field("field_0")
        self.assertEqual(0, node1._get_field("field_0").get_number_of_connected_fields())
        self.assertEqual(1, node2._get_num_fields())

        node2.add_dynamic_int_fields("field_", 1)
        self.assertEqual(2, node2._get_num_fields())

        node1._get_field("field_0").connect_from(node2._get_field("field_0"))
        self.assertEqual(1, node1._get_field("field_0").get_number_of_connected_fields())
        node2._get_field("field_0").value = 23
        avango.evaluate()
        self.assertEqual(23, node1._get_field("field_0").value)
Exemplo n.º 3
0
    def testFlushStreamInInput(self):
        stream = SimpleStream()
        node = AInputNode()
        node.set_stream(stream)
        avango.evaluate()

        self.assert_(stream.flushed)
Exemplo n.º 4
0
    def testSilentOutputOfNode(self):
        stream = SimpleStream()
        node = AOutputNode()
        node.set_stream(stream)
        avango.evaluate()
        offset = len(stream.output.getvalue())
        avango.evaluate()

        self.assertEqual("", stream.output.getvalue()[offset:])
Exemplo n.º 5
0
 def testEvaluateWithValues(self):
     node = nodes.IncValueWithValues()
     self.assert_(node)
     node.field.value = 0
     avango.evaluate()
     self.assertEqual(node.field.value, 1)
     node.field.value = 2
     avango.evaluate()
     self.assertEqual(node.field.value, 3)
Exemplo n.º 6
0
    def testSilentOutputOfNode(self):
        stream = SimpleStream()
        node = AOutputNode()
        node.set_stream(stream)
        avango.evaluate()
        offset = len(stream.output.getvalue())
        avango.evaluate()

        self.assertEqual("", stream.output.getvalue()[offset:])
Exemplo n.º 7
0
 def testEvaluateWithValues(self):
     node = nodes.IncValueWithValues()
     self.assert_(node)
     node.field.value = 0
     avango.evaluate()
     self.assertEqual(node.field.value, 1)
     node.field.value = 2
     avango.evaluate()
     self.assertEqual(node.field.value, 3)
Exemplo n.º 8
0
 def testMatrixTranslationCalculator(self):
     calculator = avango.utils.nodes.TranslationMatrixCalculator()
     
     m0 = avango.osg.make_trans_mat(1,1,1)
     m1 = avango.osg.make_trans_mat(11,21,31)
     
     calculator.MatrixFrom.value = m0
     calculator.MatrixTo.value = m1
     avango.evaluate()
Exemplo n.º 9
0
    def testMatrixTranslationCalculator(self):
        calculator = avango.utils.nodes.TranslationMatrixCalculator()

        m0 = avango.osg.make_trans_mat(1, 1, 1)
        m1 = avango.osg.make_trans_mat(11, 21, 31)

        calculator.MatrixFrom.value = m0
        calculator.MatrixTo.value = m1
        avango.evaluate()
Exemplo n.º 10
0
    def testInitalOutputOfNode(self):
        stream = SimpleStream()
        node = AOutputNode()
        node.set_stream(stream)
        avango.evaluate()

        result = stream.output.getvalue().split()
        self.assert_("anint\x00SFInt\x000" in result)
        self.assert_("astring\x00SFString\x00" in result)
        self.assert_("morestrings\x00MFString" in result)
Exemplo n.º 11
0
    def testInitalOutputOfNode(self):
        stream = SimpleStream()
        node = AOutputNode()
        node.set_stream(stream)
        avango.evaluate()

        result = stream.output.getvalue().split()
        self.assert_("anint\x00SFInt\x000"  in result)
        self.assert_("astring\x00SFString\x00" in result)
        self.assert_("morestrings\x00MFString" in result)
Exemplo n.º 12
0
    def testDeltaOutputOfNode(self):
        stream = SimpleStream()
        node = AOutputNode()
        node.set_stream(stream)
        avango.evaluate()
        offset = len(stream.output.getvalue())

        node.anint.value = 42
        avango.evaluate()

        self.assertEqual("anint\x00SFInt\x0042\n", stream.output.getvalue()[offset:])
Exemplo n.º 13
0
    def testDeltaOutputOfNode(self):
        stream = SimpleStream()
        node = AOutputNode()
        node.set_stream(stream)
        avango.evaluate()
        offset = len(stream.output.getvalue())

        node.anint.value = 42
        avango.evaluate()

        self.assertEqual("anint\x00SFInt\x0042\n",
                         stream.output.getvalue()[offset:])
Exemplo n.º 14
0
    def testCreatorFunction(self):
        w1 = Widget()
        w2 = Widget()
        w1.Value.value = 0.5

        w2.Value.connect_from( avango.utils.make_float_normalization(-1,1,0,1,w1.Value) )
        avango.evaluate()
        self.assertEqual(w2.Value.value, 0.75)

        w1.Value.value = 1.0
        avango.evaluate()
        self.assertEqual(w2.Value.value, 1.0)
Exemplo n.º 15
0
    def testSilentInputOfNode(self):
        stream = SimpleStream()
        node = AInputNode()
        node.set_stream(stream)

        node.anint.value = 42
        node.astring.value = "Bingo"
        node.morestrings.value = ["A", "B"]

        avango.evaluate()

        self.assertEqual(42, node.anint.value)
        self.assertEqual("Bingo", node.astring.value)
        self.assertEqual("A", node.morestrings.value[0])
        self.assertEqual("B", node.morestrings.value[1])
Exemplo n.º 16
0
    def testEdgeTrigger(self):
        field_container = AddSubtractDeltaTrigger()
        self.assertEqual(field_container.Value.value, 0)
        field_container.Trigger.value = True
        self.assertEqual(field_container.Value.value, 0)
        avango.evaluate()
        self.assertEqual(field_container.Value.value, 1)


        field_container.Trigger.value = False
        self.assertEqual(field_container.Value.value, 1)
        avango.evaluate()
        self.assertEqual(field_container.Value.value, 0)
        field_container.Trigger.value = False
        self.assertEqual(field_container.Value.value, 0)
Exemplo n.º 17
0
    def testFloatXMin(self):

        min = avango.utils.nodes.FloatXMin()
        min.BaseFieldName.value = "InputField"

        w1 = Widget(Value=1)
        min.add_and_connect_float_field(w1.Value)
        w2 = Widget(Value=223)
        min.add_and_connect_float_field(w2.Value)
        avango.evaluate()
        self.assertEqual(min.Output.value, 1)

        w2.Value.value = -42
        avango.evaluate()
        self.assertEqual(min.Output.value, -42)
Exemplo n.º 18
0
    def testSilentInputOfNode(self):
        stream = SimpleStream()
        node = AInputNode()
        node.set_stream(stream)

        node.anint.value = 42
        node.astring.value = "Bingo"
        node.morestrings.value = ["A", "B"]

        avango.evaluate()

        self.assertEqual(42, node.anint.value)
        self.assertEqual("Bingo", node.astring.value)
        self.assertEqual("A", node.morestrings.value[0])
        self.assertEqual("B", node.morestrings.value[1])
Exemplo n.º 19
0
    def testFloatXMin(self):

        min = avango.utils.nodes.FloatXMin()
        min.BaseFieldName.value = "InputField"

        w1 = Widget(Value=1)
        min.add_and_connect_float_field(w1.Value)
        w2 = Widget(Value=223)
        min.add_and_connect_float_field(w2.Value)
        avango.evaluate()
        self.assertEqual(min.Output.value, 1)

        w2.Value.value = -42
        avango.evaluate()
        self.assertEqual(min.Output.value, -42)
Exemplo n.º 20
0
    def testBoolXOr(self):
        keep_alive = []
        trigger_fields = []
        num_fields = 10
        for i in range(0,num_fields):
            w = Widget(Trigger = False)
            keep_alive.append(w)
            trigger_fields.append(w.Trigger)

        output = avango.utils.make_boolX_or(trigger_fields)
        self.assertEqual(output.value, False)
        avango.evaluate()
        self.assertEqual(output.value, False)
        trigger_fields[1].value = True
        avango.evaluate()
        self.assertEqual(output.value, True)
Exemplo n.º 21
0
    def testZeroCrossNormalization(self):
        normalization = avango.utils.nodes.FloatNormalization()
        normalization.MinIn.value = -10.0
        normalization.MaxIn.value = 10.0
        normalization.MinOut.value = 0.0
        normalization.MaxOut.value = 1.0
        normalization.ValueIn.value = 0.0
        avango.evaluate()
        self.assertEqual(normalization.ValueOut.value, 0.5)

        normalization.MinIn.value = -10.0
        normalization.MaxIn.value = 90.0
        normalization.MinOut.value = -1.0
        normalization.MaxOut.value = 0.0
        normalization.ValueIn.value = 40.0
        avango.evaluate()
        self.assertEqual(normalization.ValueOut.value, -0.5)
Exemplo n.º 22
0
    def testNegativeNormalization(self):
        normalization = avango.utils.nodes.FloatNormalization()
        normalization.MinIn.value = -10.0
        normalization.MaxIn.value = -5.0
        normalization.MinOut.value = 0.0
        normalization.MaxOut.value = 1.0
        normalization.ValueIn.value = -7.5
        avango.evaluate()
        self.assertEqual(normalization.ValueOut.value, 0.5)

        normalization.MinIn.value = -20.0
        normalization.MaxIn.value = -10.0
        normalization.MinOut.value = -1.0
        normalization.MaxOut.value = 0.0
        normalization.ValueIn.value = -15.0
        avango.evaluate()
        self.assertEqual(normalization.ValueOut.value, -0.5)
Exemplo n.º 23
0
    def testModifiedInputOfNode(self):
        stream = SimpleStream()
        node = AInputNode()
        stream.input = StringIO.StringIO("anint\x00SFInt\x000\n"
                                         "astring\x00SFString\x00\n"
                                         "morestrings\x00MFString\n")
        node.set_stream(stream)

        node.anint.value = 42
        node.astring.value = "Bingo"
        node.morestrings.value = ["A", "B"]

        avango.evaluate()

        self.assertEqual(0, node.anint.value)
        self.assertEqual("", node.astring.value)
        self.assertEqual(0, len(node.morestrings.value))
Exemplo n.º 24
0
    def testModifiedInputOfNode(self):
        stream = SimpleStream()
        node = AInputNode()
        stream.input = StringIO.StringIO(
            "anint\x00SFInt\x000\n"
            "astring\x00SFString\x00\n"
            "morestrings\x00MFString\n")
        node.set_stream(stream)

        node.anint.value = 42
        node.astring.value = "Bingo"
        node.morestrings.value = ["A", "B"]

        avango.evaluate()

        self.assertEqual(0, node.anint.value)
        self.assertEqual("", node.astring.value)
        self.assertEqual(0, len(node.morestrings.value))
Exemplo n.º 25
0
    def testDynamicFieldRemoval(self):
        node1 = DynamicFieldScript()
        #Every script node has a Name field by default
        self.assertEqual(1, node1._get_num_fields())
        node1.add_dynamic_int_fields("field_", 1)
        self.assertEqual(2, node1._get_num_fields())

        node2 = DynamicFieldScript()
        self.assertEqual(1, node2._get_num_fields())
        node2.add_dynamic_int_fields("field_", 1)
        self.assertEqual(2, node2._get_num_fields())

        self.assertEqual(
            0,
            node1._get_field("field_0").get_number_of_connected_fields())
        node1._get_field("field_0").connect_from(node2._get_field("field_0"))
        self.assertEqual(
            1,
            node1._get_field("field_0").get_number_of_connected_fields())

        node2._get_field("field_0").value = 42
        avango.evaluate()
        self.assertEqual(42, node1._get_field("field_0").value)

        node2.remove_field("field_0")
        self.assertEqual(
            0,
            node1._get_field("field_0").get_number_of_connected_fields())
        self.assertEqual(1, node2._get_num_fields())

        node2.add_dynamic_int_fields("field_", 1)
        self.assertEqual(2, node2._get_num_fields())

        node1._get_field("field_0").connect_from(node2._get_field("field_0"))
        self.assertEqual(
            1,
            node1._get_field("field_0").get_number_of_connected_fields())
        node2._get_field("field_0").value = 23
        avango.evaluate()
        self.assertEqual(23, node1._get_field("field_0").value)
Exemplo n.º 26
0
 def testConnectedFields(self):
     node0 = MVFNodeOut()
     node1 = MVFNodeIn()
     node2 = MVFNodeIn()
     
     node1.FloatVecIn.connect_from(node0.FloatVecOut)
     node2.FloatVecIn.connect_from(node0.FloatVecOut)
     node0.FloatVecOut.all_values = [-1.0, 1.0, 2.0, 4.0]
     
     self.assertEqual(list(node0.FloatVecOut.all_values), list(node1.FloatVecIn.all_values))
     self.assertEqual(list(node0.FloatVecOut.all_values), list(node2.FloatVecIn.all_values))        
     
     avango.evaluate()
     
     self.assertEqual(node1.saved_changed_inds, [0, 1, 2, 3])
     self.assertEqual(node1.saved_changed_inds, node2.saved_changed_inds)
     
     node0.compute_results()
     avango.evaluate()
     
     self.assertEqual(node1.saved_changed_inds, [0, 3, 4, 5])
     self.assertEqual(node1.saved_changed_inds, node2.saved_changed_inds)
     self.assertEqual(list(node0.FloatVecOut.all_values), list(node1.FloatVecIn.all_values))
     self.assertEqual(list(node0.FloatVecOut.all_values), list(node2.FloatVecIn.all_values))
Exemplo n.º 27
0
    def testTaskInvokation(self):
        time_sensor = avango.nodes.TimeSensor()
        task_scheduler = avango.utils.nodes.TaskScheduler()
        task_scheduler.TimeIn.connect_from(time_sensor.Time)

        task1 = TimeDeltaIncrement()
        task1.TimeDelta.value = 0.1

        task2 = TimeDeltaIncrement()
        task2.TimeDelta.value = 0.2

        task_scheduler.add_delayed_task(task1)
        task_scheduler.add_delayed_task(task2)

        avango.evaluate()

        self.assertEqual(task1.Value.value, 0)
        self.assertEqual(task2.Value.value, 0)
        self.assertEqual(task_scheduler.get_num_tasks(), 2)
        time.sleep(0.05)
        avango.evaluate()

        self.assertEqual(task1.Value.value, 0)
        self.assertEqual(task2.Value.value, 0)
        self.assertEqual(task_scheduler.get_num_tasks(), 2)
        time.sleep(0.06)
        avango.evaluate()

        self.assertEqual(task1.Value.value, 1)
        self.assertEqual(task2.Value.value, 0)
        self.assertEqual(task_scheduler.get_num_tasks(), 1)
        time.sleep(0.1)
        avango.evaluate()

        self.assertEqual(task1.Value.value, 1)
        self.assertEqual(task2.Value.value, 1)
        self.assertEqual(task_scheduler.get_num_tasks(), 0)
Exemplo n.º 28
0
    def testTaskInvokation(self):
        time_sensor = avango.nodes.TimeSensor()
        task_scheduler = avango.utils.nodes.TaskScheduler()
        task_scheduler.TimeIn.connect_from(time_sensor.Time)

        task1 = TimeDeltaIncrement()
        task1.TimeDelta.value = 0.1

        task2 = TimeDeltaIncrement()
        task2.TimeDelta.value = 0.2

        task_scheduler.add_delayed_task(task1)
        task_scheduler.add_delayed_task(task2)

        avango.evaluate()

        self.assertEqual(task1.Value.value, 0)
        self.assertEqual(task2.Value.value, 0)
        self.assertEqual(task_scheduler.get_num_tasks(),2)
        time.sleep(0.05)
        avango.evaluate()

        self.assertEqual(task1.Value.value, 0)
        self.assertEqual(task2.Value.value, 0)
        self.assertEqual(task_scheduler.get_num_tasks(),2)
        time.sleep(0.06)
        avango.evaluate()

        self.assertEqual(task1.Value.value, 1)
        self.assertEqual(task2.Value.value, 0)
        self.assertEqual(task_scheduler.get_num_tasks(),1)
        time.sleep(0.1)
        avango.evaluate()

        self.assertEqual(task1.Value.value, 1)
        self.assertEqual(task2.Value.value, 1)
        self.assertEqual(task_scheduler.get_num_tasks(),0)
Exemplo n.º 29
0
    def testFloatXSum(self):

        sum = avango.utils.nodes.FloatXSum()
        sum.BaseFieldName.value = "InputField"

        w1 = Widget(Value=1)
        sum.add_and_connect_float_field(w1.Value)
        w2 = Widget(Value=2)
        sum.add_and_connect_float_field(w2.Value)
        avango.evaluate()
        self.assertEqual(sum.Output.value, 3)

        w3 = Widget(Value=-3)
        sum.add_and_connect_float_field(w3.Value)
        self.assertEqual(sum.InputField2.value, -3)
        avango.evaluate()
        self.assertEqual(sum.Output.value, 0)

        w3.Value.value = 39
        avango.evaluate()
        self.assertEqual(sum.Output.value, 42)
Exemplo n.º 30
0
    def testFloatXSum(self):

        sum = avango.utils.nodes.FloatXSum()
        sum.BaseFieldName.value = "InputField"

        w1 = Widget(Value=1)
        sum.add_and_connect_float_field(w1.Value)
        w2 = Widget(Value=2)
        sum.add_and_connect_float_field(w2.Value)
        avango.evaluate()
        self.assertEqual(sum.Output.value, 3)

        w3 = Widget(Value=-3)
        sum.add_and_connect_float_field(w3.Value)
        self.assertEqual(sum.InputField2.value, -3)
        avango.evaluate()
        self.assertEqual(sum.Output.value, 0)

        w3.Value.value = 39
        avango.evaluate()
        self.assertEqual(sum.Output.value, 42)
Exemplo n.º 31
0
    def testPositiveNormalization(self):
        normalization = avango.utils.nodes.FloatNormalization()
        normalization.MinIn.value = 5.0
        normalization.MaxIn.value = 10.0
        normalization.MinOut.value = 0.0
        normalization.MaxOut.value = 1.0
        normalization.ValueIn.value = 7.5
        avango.evaluate()
        self.assertEqual(normalization.ValueOut.value, 0.5)

        normalization.MinOut.value = 11.0
        normalization.MaxOut.value = 12.0
        avango.evaluate()
        self.assertEqual(normalization.ValueOut.value, 11.5)

        normalization.MinIn.value = 0.0
        normalization.MaxIn.value = 360.0
        normalization.MinOut.value = 0.0
        normalization.MaxOut.value = 1.0
        normalization.ValueIn.value = 90.0
        avango.evaluate()
        self.assertEqual(normalization.ValueOut.value, 0.25)
Exemplo n.º 32
0
    def testBoolMerge(self):

        w1 = Widget()
        w1.Trigger.value = False
        w2 = Widget()
        w2.Trigger.value = False

        combined_widget = avango.utils.merge_and_connect_bool_scripts(w1,w2)
        self.assertEqual(combined_widget.Trigger.value, False)

        w1.Trigger.value = True
        avango.evaluate()
        self.assertEqual(combined_widget.Trigger.value, True)

        w1.Trigger.value = False
        w2.Trigger.value = True
        avango.evaluate()
        self.assertEqual(combined_widget.Trigger.value, True)

        w1.Trigger.value = False
        w2.Trigger.value = False
        avango.evaluate()
        self.assertEqual(combined_widget.Trigger.value, False)
Exemplo n.º 33
0
 def testTouchMyself(self):
     node = TouchMyself()
     avango.evaluate()
     self.assertEqual(2, node.value)
Exemplo n.º 34
0
 def testTouchMyself(self):
     node = TouchMyself()
     avango.evaluate()
     self.assertEqual(2, node.value)
Exemplo n.º 35
0
Arquivo: video.py Projeto: 4og/avango
viewer.MasterCamera.value = camera
viewer.Scene.value = root_group

# set up event handling

events = avango.osg.viewer.nodes.EventFields(View = viewer)
window.ToggleFullScreen.connect_from(events.KeyAltReturn)
window.DragEvent.connect_from(events.DragEvent)
window.MoveEvent.connect_from(events.MoveEvent)
"""

# load a video
loadimagestream = avango.osg.nodes.LoadImageStream(
                    Filename = sys.argv[1])
#viewer.frame()
avango.evaluate()

video = loadimagestream.ImageStream.get_value()
video.Loop.value = True
video.Status.value=avango.osg.streamstatus.playing

videoTexture = avango.osg.nodes.Texture2D(Image = video, ResizeNonPowerOfTwoHint = False)
#s = avango.osg.nodes.StateSet(Texture0 = videoTexture)


print videoTexture.Image.value.Width.value
print videoTexture.TextureHeight.value


quad = avango.osg.nodes.TexturedQuad()
quad.Texture2D.value = videoTexture
Exemplo n.º 36
0
 def testDerivedExposedTouch(self):
     node = DerivedExposedTouch()
     node.derived_touch()
     avango.evaluate()
     self.assertEqual(2, node.value)
Exemplo n.º 37
0
 def testDoubleDerivedUpcalling(self):
     node = DoubleDerivedUpcallingIncValue()
     node.field.value = 0
     avango.evaluate()
     self.assertEqual(node.field.value, 1)
     self.assertEqual(1, node.value)
Exemplo n.º 38
0
Arquivo: main.py Projeto: vrsys/avango
def start():
    graph = avango.gua.nodes.SceneGraph(Name="scene")
    loader = avango.gua.nodes.TriMeshLoader()

    fallback_mat = avango.gua.create_material(
        avango.gua.MaterialCapabilities.COLOR_VALUE
        | avango.gua.MaterialCapabilities.ROUGHNESS_VALUE)
    fallback_mat.set_uniform("Roughness", 0.6)

    for x in range(0, CUBE_COUNT_X):
        for y in range(0, CUBE_COUNT_Y):
            for z in range(0, CUBE_COUNT_Z):

                new_cube = loader.create_geometry_from_file(
                    "cube" + str(x) + str(y) + str(z),
                    "data/objects/monkey.obj",
                    fallback_mat,
                    #avango.gua.LoaderFlags.DEFAULTS
                )

                new_cube.Transform.value = avango.gua.make_trans_mat(x*2, y*2, z*2) * \
                                           avango.gua.make_scale_mat(0.3, 0.3, 0.3)
                graph.Root.value.Children.value.append(new_cube)
                new_cube.ShadowMode.value = 1

    sun_light = avango.gua.nodes.LightNode(
        Name="sun_light",
        Type=avango.gua.LightType.SUN,
        Color=avango.gua.Color(1.0, 1.0, 0.7),
        EnableShadows=True,
        ShadowMapSize=1024,
        ShadowOffset=0.0005,
        ShadowCascadedSplits=[0.1, 4, 7, 20],
        ShadowMaxDistance=30,
        ShadowNearClippingInSunDirection=100,
        ShadowFarClippingInSunDirection=100,
        Brightness=4)
    graph.Root.value.Children.value.append(sun_light)

    floor = loader.create_geometry_from_file("floor", "data/objects/plane.obj",
                                             fallback_mat,
                                             avango.gua.LoaderFlags.DEFAULTS)
    floor.Transform.value = avango.gua.make_scale_mat(
        200, 1, 200) * avango.gua.make_trans_mat(-0.5, -0.2, -0.5)
    floor.ShadowMode.value = 0
    graph.Root.value.Children.value.append(floor)

    width = 700
    height = int(width * 9.0 / 16.0)
    size4k = avango.gua.Vec2ui(3840, 2160)
    size = size4k  # avango.gua.Vec2ui(width, height)
    vsync = True

    screen_tl = avango.gua.nodes.ScreenNode(
        Name="screen_tl",
        Width=1.6,
        Height=0.9,
        Transform=avango.gua.make_trans_mat(-0.8, 0.45, -2.5))

    camera_tl = avango.gua.nodes.CameraNode(
        Name="cam_tl",
        BlackList=[],
        LeftScreenPath="/head/cam_tl/screen_tl",
        RightScreenPath="/head/cam_tl/screen_tl",
        SceneGraph="scene",
        Resolution=size,
        OutputWindowName="window_tl",
        EyeDistance=0.2,
        EnableStereo=False,
        Children=[screen_tl])

    screen_tr = avango.gua.nodes.ScreenNode(
        Name="screen_tr",
        Width=1.6,
        Height=0.9,
        Transform=avango.gua.make_trans_mat(0.8, 0.45, -2.5))

    camera_tr = avango.gua.nodes.CameraNode(
        Name="cam_tr",
        LeftScreenPath="/head/cam_tr/screen_tr",
        RightScreenPath="/head/cam_tr/screen_tr",
        SceneGraph="scene",
        Resolution=size,
        OutputWindowName="window_tr",
        EyeDistance=0.2,
        EnableStereo=False,
        Children=[screen_tr])

    screen_bl = avango.gua.nodes.ScreenNode(
        Name="screen_bl",
        Width=1.6,
        Height=0.9,
        Transform=avango.gua.make_trans_mat(-0.8, -0.45, -2.5))

    camera_bl = avango.gua.nodes.CameraNode(
        Name="cam_bl",
        BlackList=[],
        LeftScreenPath="/head/cam_bl/screen_bl",
        RightScreenPath="/head/cam_bl/screen_bl",
        SceneGraph="scene",
        Resolution=size,
        OutputWindowName="window_bl",
        EyeDistance=0.2,
        EnableStereo=False,
        Children=[screen_bl])

    screen_br = avango.gua.nodes.ScreenNode(
        Name="screen_br",
        Width=1.6,
        Height=0.9,
        Transform=avango.gua.make_trans_mat(0.8, -0.45, -2.5))

    camera_br = avango.gua.nodes.CameraNode(
        Name="cam_br",
        BlackList=[],
        LeftScreenPath="/head/cam_br/screen_br",
        RightScreenPath="/head/cam_br/screen_br",
        SceneGraph="scene",
        Resolution=size,
        OutputWindowName="window_br",
        EyeDistance=0.2,
        EnableStereo=False,
        Children=[screen_br])

    res_pass = avango.gua.nodes.ResolvePassDescription()
    res_pass.EnableSSAO.value = True
    res_pass.SSAOIntensity.value = 3.0
    res_pass.SSAOFalloff.value = 20.0
    res_pass.SSAORadius.value = 10.0
    #res_pass.EnvironmentLightingTexture.value = "day_skymap"
    #res_pass.AlternativeEnvironmentLightingTexture.value = "night_skymap"
    #res_pass.EnvironmentLightingMode.value = avango.gua.EnvironmentLightingMode.CUBEMAP
    res_pass.ToneMappingMode.value = avango.gua.ToneMappingMode.UNCHARTED
    res_pass.Exposure.value = 1.0
    res_pass.VignetteColor.value = avango.gua.Vec4(0, 0, 0, 0.7)
    res_pass.VignetteCoverage.value = 0.0
    res_pass.EnableFog.value = True
    res_pass.FogStart.value = 30
    res_pass.FogEnd.value = 100
    #res_pass.BackgroundMode.value = avango.gua.BackgroundMode.CUBEMAP_TEXTURE
    #res_pass.BackgroundTexture.value = "day_skymap"
    #res_pass.AlternativeBackgroundTexture.value = "night_skymap"

    sky_pass = avango.gua.nodes.SkyMapPassDescription(
        OutputTextureName="day_skymap")

    avango.gua.create_texture_cube(
        "night_skymap",
        "data/textures/stars/purple-nebula/purple-nebula_right1.jpg",
        "data/textures/stars/purple-nebula/purple-nebula_left2.jpg",
        "data/textures/stars/purple-nebula/purple-nebula_bottom4.jpg",
        "data/textures/stars/purple-nebula/purple-nebula_top3.jpg",
        "data/textures/stars/purple-nebula/purple-nebula_front5.jpg",
        "data/textures/stars/purple-nebula/purple-nebula_back6.jpg")

    pipeline_description = avango.gua.nodes.PipelineDescription(Passes=[
        sky_pass,
        avango.gua.nodes.TriMeshPassDescription(),
        avango.gua.nodes.LightVisibilityPassDescription(), res_pass,
        avango.gua.nodes.TexturedScreenSpaceQuadPassDescription()
    ])

    camera_tl.PipelineDescription.value = pipeline_description
    camera_tr.PipelineDescription.value = pipeline_description
    camera_bl.PipelineDescription.value = pipeline_description
    camera_br.PipelineDescription.value = pipeline_description

    head = avango.gua.nodes.TransformNode(
        Name="head", Children=[camera_tl, camera_tr, camera_bl, camera_br])

    graph.Root.value.Children.value.append(head)

    window_tl = avango.gua.nodes.Window(Size=size,
                                        Display=":0.0",
                                        SwapGroup=1,
                                        SwapBarrier=1,
                                        Title="day cycle top left",
                                        LeftResolution=size,
                                        RightResolution=size,
                                        EnableVsync=vsync,
                                        StereoMode=avango.gua.StereoMode.MONO)

    window_tr = avango.gua.nodes.Window(Size=size,
                                        Display=":0.1",
                                        SwapGroup=1,
                                        SwapBarrier=1,
                                        Title="day cycle top right",
                                        LeftResolution=size,
                                        RightResolution=size,
                                        EnableVsync=vsync,
                                        StereoMode=avango.gua.StereoMode.MONO)

    window_bl = avango.gua.nodes.Window(Size=size,
                                        Display=":0.2",
                                        SwapGroup=1,
                                        SwapBarrier=1,
                                        Title="day cycle bottom left",
                                        LeftResolution=size,
                                        RightResolution=size,
                                        EnableVsync=vsync,
                                        StereoMode=avango.gua.StereoMode.MONO)

    window_br = avango.gua.nodes.Window(Size=size,
                                        Display=":0.3",
                                        SwapGroup=1,
                                        SwapBarrier=1,
                                        Title="day cycle bottom right",
                                        LeftResolution=size,
                                        RightResolution=size,
                                        EnableVsync=vsync,
                                        StereoMode=avango.gua.StereoMode.MONO)

    avango.gua.register_window("window_tl", window_tl)
    avango.gua.register_window("window_tr", window_tr)
    avango.gua.register_window("window_bl", window_bl)
    avango.gua.register_window("window_br", window_br)

    navigator = examples_common.navigator.Navigator()
    navigator.StartLocation.value = head.Transform.value.get_translate()
    navigator.OutTransform.connect_from(head.Transform)

    navigator.RotationSpeed.value = 0.2
    navigator.MotionSpeed.value = 0.04

    head.Transform.connect_from(navigator.OutTransform)

    viewer = avango.gua.nodes.Viewer()
    viewer.SceneGraphs.value = [graph]
    viewer.Windows.value = [window_tl, window_tr, window_bl, window_br]

    timer = avango.nodes.TimeSensor()

    sun_updater = SunUpdater(TimeScale=3500)
    sun_updater.TimeIn.connect_from(timer.Time)
    sun_light.Transform.connect_from(sun_updater.MatrixOut)
    sun_light.Color.connect_from(sun_updater.SunColorOut)
    sky_pass.LightDirection.connect_from(sun_updater.DirectionOut)
    sky_pass.GroundColor.connect_from(sun_updater.GroundColorOut)
    res_pass.BackgroundTextureBlendFactor.connect_from(
        sun_updater.BlendFactorOut)
    res_pass.EnvironmentLightingTextureBlendFactor.connect_from(
        sun_updater.BlendFactorOut)

    def toggle_swap_barrier():
        window_tl.SwapGroup.value = (window_tl.SwapGroup.value + 1) % 2
        window_tr.SwapGroup.value = (window_tr.SwapGroup.value + 1) % 2
        window_bl.SwapGroup.value = (window_bl.SwapGroup.value + 1) % 2
        window_br.SwapGroup.value = (window_br.SwapGroup.value + 1) % 2
        window_tl.SwapBarrier.value = (window_tl.SwapBarrier.value + 1) % 2
        window_tr.SwapBarrier.value = (window_tr.SwapBarrier.value + 1) % 2
        window_bl.SwapBarrier.value = (window_bl.SwapBarrier.value + 1) % 2
        window_br.SwapBarrier.value = (window_br.SwapBarrier.value + 1) % 2

        print("window_tl.SwapGroup.value = ", window_tl.SwapGroup.value)
        print("window_tr.SwapGroup.value = ", window_tr.SwapGroup.value)
        print("window_bl.SwapGroup.value = ", window_bl.SwapGroup.value)
        print("window_br.SwapGroup.value = ", window_br.SwapGroup.value)
        print("window_tl.SwapBarrier.value = ", window_tl.SwapBarrier.value)
        print("window_tr.SwapBarrier.value = ", window_tr.SwapBarrier.value)
        print("window_bl.SwapBarrier.value = ", window_bl.SwapBarrier.value)
        print("window_br.SwapBarrier.value = ", window_br.SwapBarrier.value)

    guaVE = GuaVE()
    guaVE.start(locals(), globals())

    avango.evaluate()
    print("sleep 5 seconds")
    time.sleep(5)
    viewer.run()
Exemplo n.º 39
0
viewer = avango.osg.viewer.nodes.Viewer()
viewer.MasterCamera.value = camera
viewer.Scene.value = root_group

# set up event handling

events = avango.osg.viewer.nodes.EventFields(View = viewer)
window.ToggleFullScreen.connect_from(events.KeyAltReturn)
window.DragEvent.connect_from(events.DragEvent)
window.MoveEvent.connect_from(events.MoveEvent)
"""

# load a video
loadimagestream = avango.osg.nodes.LoadImageStream(Filename=sys.argv[1])
#viewer.frame()
avango.evaluate()

video = loadimagestream.ImageStream.get_value()
video.Loop.value = True
video.Status.value = avango.osg.streamstatus.playing

videoTexture = avango.osg.nodes.Texture2D(Image=video,
                                          ResizeNonPowerOfTwoHint=False)
#s = avango.osg.nodes.StateSet(Texture0 = videoTexture)

print videoTexture.Image.value.Width.value
print videoTexture.TextureHeight.value

quad = avango.osg.nodes.TexturedQuad()
quad.Texture2D.value = videoTexture
quad.UseFilename.value = False
Exemplo n.º 40
0
 def testOptimize(self):
     node = avango.osg.nodes.Sphere()
     optimizer = avango.utils.nodes.NodeOptimizer(Node=node)
     optimizer.Trigger.value = True
     avango.evaluate()
Exemplo n.º 41
0
 def testDoubleDerivedUpcalling(self):
     node = DoubleDerivedUpcallingIncValue()
     node.field.value = 0
     avango.evaluate()
     self.assertEqual(node.field.value, 1)
     self.assertEqual(1, node.value)
Exemplo n.º 42
0
 def testDerivedExposedTouch(self):
     node = DerivedExposedTouch()
     node.derived_touch()
     avango.evaluate()
     self.assertEqual(2, node.value)
Exemplo n.º 43
0
def start():
  graph  = avango.gua.nodes.SceneGraph(Name = "scene")
  loader = avango.gua.nodes.TriMeshLoader()

  fps_size = avango.gua.Vec2(170, 55)

  fps = avango.gua.gui.nodes.GuiResourceNode()
  fps.TextureName.value = "fps"
  fps.URL.value = "asset://gua/data/html/fps.html"
  fps.Size.value = fps_size

  fps_quad = avango.gua.nodes.TexturedScreenSpaceQuadNode(
    Name = "fps_quad",
    Texture = "fps",
    Width = int(fps_size.x),
    Height = int(fps_size.y),
    Anchor = avango.gua.Vec2(1.0, 1.0),
    Tags = ["fps"]
  )
  graph.Root.value.Children.value.append(fps_quad)

  fallback_mat = avango.gua.create_material(avango.gua.MaterialCapabilities.COLOR_VALUE | avango.gua.MaterialCapabilities.ROUGHNESS_VALUE)
  fallback_mat.set_uniform("Roughness", 0.6)

  for x in range(0, CUBE_COUNT_X):
    for y in range(0, CUBE_COUNT_Y):
      for z in range(0, CUBE_COUNT_Z):

        new_cube = loader.create_geometry_from_file(
          "cube" + str(x) + str(y) + str(z),
          "data/objects/monkey.obj",
          fallback_mat,
          #avango.gua.LoaderFlags.DEFAULTS
        )

        new_cube.Transform.value = avango.gua.make_trans_mat(x*2, y*2, z*2) * \
                                   avango.gua.make_scale_mat(0.3, 0.3, 0.3)
        graph.Root.value.Children.value.append(new_cube)
        new_cube.ShadowMode.value = 1

  sun_light = avango.gua.nodes.LightNode(
    Name = "sun_light",
    Type = avango.gua.LightType.SUN,
    Color = avango.gua.Color(1.0, 1.0, 0.7),
    EnableShadows = True,
    ShadowMapSize = 1024,
    ShadowOffset = 0.0005,
    ShadowCascadedSplits = [0.1, 4, 7, 20],
    ShadowMaxDistance = 30,
    ShadowNearClippingInSunDirection = 100,
    ShadowFarClippingInSunDirection = 100,
    Brightness = 4
  )
  graph.Root.value.Children.value.append(sun_light)

  floor = loader.create_geometry_from_file(
    "floor",
    "data/objects/plane.obj",
    fallback_mat,
    avango.gua.LoaderFlags.DEFAULTS
  )
  floor.Transform.value = avango.gua.make_scale_mat(200, 1, 200) * avango.gua.make_trans_mat(-0.5, -0.2, -0.5)
  floor.ShadowMode.value = 0
  graph.Root.value.Children.value.append(floor)

  width = 700;
  height = int(width * 9.0 / 16.0)
  size4k = avango.gua.Vec2ui(3840, 2160)
  size = size4k # avango.gua.Vec2ui(width, height)
  vsync = True

  screen_tl = avango.gua.nodes.ScreenNode(
    Name = "screen_tl",
    Width = 1.6,
    Height = 0.9,
    Transform = avango.gua.make_trans_mat(-0.8, 0.45, -2.5)
  )

  camera_tl = avango.gua.nodes.CameraNode(
    Name = "cam_tl",
    BlackList = ["fps"],
    LeftScreenPath = "/head/cam_tl/screen_tl",
    RightScreenPath = "/head/cam_tl/screen_tl",
    SceneGraph = "scene",
    Resolution = size,
    OutputWindowName = "window_tl",
    EyeDistance = 0.2,
    EnableStereo = False,
    Children = [screen_tl]
  )

  screen_tr = avango.gua.nodes.ScreenNode(
    Name = "screen_tr",
    Width = 1.6,
    Height = 0.9,
    Transform = avango.gua.make_trans_mat(0.8, 0.45, -2.5)
  )

  camera_tr = avango.gua.nodes.CameraNode(
    Name = "cam_tr",
    LeftScreenPath = "/head/cam_tr/screen_tr",
    RightScreenPath = "/head/cam_tr/screen_tr",
    SceneGraph = "scene",
    Resolution = size,
    OutputWindowName = "window_tr",
    EyeDistance = 0.2,
    EnableStereo = False,
    Children = [screen_tr]
  )

  screen_bl = avango.gua.nodes.ScreenNode(
    Name = "screen_bl",
    Width = 1.6,
    Height = 0.9,
    Transform = avango.gua.make_trans_mat(-0.8, -0.45, -2.5)
  )

  camera_bl = avango.gua.nodes.CameraNode(
    Name = "cam_bl",
    BlackList = ["fps"],
    LeftScreenPath = "/head/cam_bl/screen_bl",
    RightScreenPath = "/head/cam_bl/screen_bl",
    SceneGraph = "scene",
    Resolution = size,
    OutputWindowName = "window_bl",
    EyeDistance = 0.2,
    EnableStereo = False,
    Children = [screen_bl]
  )

  screen_br = avango.gua.nodes.ScreenNode(
    Name = "screen_br",
    Width = 1.6,
    Height = 0.9,
    Transform = avango.gua.make_trans_mat(0.8, -0.45, -2.5)
  )

  camera_br = avango.gua.nodes.CameraNode(
    Name = "cam_br",
    BlackList = ["fps"],
    LeftScreenPath = "/head/cam_br/screen_br",
    RightScreenPath = "/head/cam_br/screen_br",
    SceneGraph = "scene",
    Resolution = size,
    OutputWindowName = "window_br",
    EyeDistance = 0.2,
    EnableStereo = False,
    Children = [screen_br]
  )


  res_pass = avango.gua.nodes.ResolvePassDescription()
  res_pass.EnableSSAO.value = True
  res_pass.SSAOIntensity.value = 3.0
  res_pass.SSAOFalloff.value = 20.0
  res_pass.SSAORadius.value = 10.0
  #res_pass.EnvironmentLightingTexture.value = "day_skymap"
  #res_pass.AlternativeEnvironmentLightingTexture.value = "night_skymap"
  #res_pass.EnvironmentLightingMode.value = avango.gua.EnvironmentLightingMode.CUBEMAP
  res_pass.ToneMappingMode.value = avango.gua.ToneMappingMode.UNCHARTED
  res_pass.Exposure.value = 1.0
  res_pass.VignetteColor.value = avango.gua.Vec4(0, 0, 0, 0.7)
  res_pass.VignetteCoverage.value = 0.0
  res_pass.EnableFog.value = True
  res_pass.FogStart.value = 30
  res_pass.FogEnd.value = 100
  #res_pass.BackgroundMode.value = avango.gua.BackgroundMode.CUBEMAP_TEXTURE
  #res_pass.BackgroundTexture.value = "day_skymap"
  #res_pass.AlternativeBackgroundTexture.value = "night_skymap"

  sky_pass = avango.gua.nodes.SkyMapPassDescription(
    OutputTextureName="day_skymap"
  )

  avango.gua.create_texture_cube(
    "night_skymap",
    "data/textures/stars/purple-nebula/purple-nebula_right1.jpg",
    "data/textures/stars/purple-nebula/purple-nebula_left2.jpg",
    "data/textures/stars/purple-nebula/purple-nebula_bottom4.jpg",
    "data/textures/stars/purple-nebula/purple-nebula_top3.jpg",
    "data/textures/stars/purple-nebula/purple-nebula_front5.jpg",
    "data/textures/stars/purple-nebula/purple-nebula_back6.jpg"
  )

  pipeline_description = avango.gua.nodes.PipelineDescription(
    Passes = [
      sky_pass,
      avango.gua.nodes.TriMeshPassDescription(),
      avango.gua.nodes.LightVisibilityPassDescription(),
      res_pass,
      avango.gua.nodes.TexturedScreenSpaceQuadPassDescription()
    ]
  )

  camera_tl.PipelineDescription.value = pipeline_description
  camera_tr.PipelineDescription.value = pipeline_description
  camera_bl.PipelineDescription.value = pipeline_description
  camera_br.PipelineDescription.value = pipeline_description

  head = avango.gua.nodes.TransformNode(
    Name = "head",
    Children = [camera_tl, camera_tr, camera_bl, camera_br]
  )

  graph.Root.value.Children.value.append(head)

  window_tl = avango.gua.nodes.Window(
    Size = size,
    Display = ":0.0",
    SwapGroup = 1,
    SwapBarrier = 1,
    Title = "day cycle top left",
    LeftResolution = size,
    RightResolution = size,
    EnableVsync = vsync,
    StereoMode = avango.gua.StereoMode.MONO
  )

  window_tr = avango.gua.nodes.Window(
    Size = size,
    Display = ":0.1",
    SwapGroup = 1,
    SwapBarrier = 1,
    Title = "day cycle top right",
    LeftResolution = size,
    RightResolution = size,
    EnableVsync = vsync,
    StereoMode = avango.gua.StereoMode.MONO
  )

  window_bl = avango.gua.nodes.Window(
    Size = size,
    Display = ":0.2",
    SwapGroup = 1,
    SwapBarrier = 1,
    Title = "day cycle bottom left",
    LeftResolution = size,
    RightResolution = size,
    EnableVsync = vsync,
    StereoMode = avango.gua.StereoMode.MONO
  )

  window_br = avango.gua.nodes.Window(
    Size = size,
    Display = ":0.3",
    SwapGroup = 1,
    SwapBarrier = 1,
    Title = "day cycle bottom right",
    LeftResolution = size,
    RightResolution = size,
    EnableVsync = vsync,
    StereoMode = avango.gua.StereoMode.MONO
  )

  avango.gua.register_window("window_tl", window_tl)
  avango.gua.register_window("window_tr", window_tr)
  avango.gua.register_window("window_bl", window_bl)
  avango.gua.register_window("window_br", window_br)

  navigator = examples_common.navigator.Navigator()
  navigator.StartLocation.value = head.Transform.value.get_translate()
  navigator.OutTransform.connect_from(head.Transform)

  navigator.RotationSpeed.value = 0.2
  navigator.MotionSpeed.value = 0.04

  head.Transform.connect_from(navigator.OutTransform)

  viewer = avango.gua.nodes.Viewer()
  viewer.SceneGraphs.value = [graph]
  viewer.Windows.value = [window_tl, window_tr, window_bl, window_br]

  timer = avango.nodes.TimeSensor()

  fps_updater = FPSUpdater(
    FPSResource = fps,
    Window = window_tr,
    Viewer = viewer
  )
  fps_updater.TimeIn.connect_from(timer.Time)

  sun_updater = SunUpdater(
    TimeScale = 3500
  )
  sun_updater.TimeIn.connect_from(timer.Time)
  sun_light.Transform.connect_from(sun_updater.MatrixOut)
  sun_light.Color.connect_from(sun_updater.SunColorOut)
  sky_pass.LightDirection.connect_from(sun_updater.DirectionOut)
  sky_pass.GroundColor.connect_from(sun_updater.GroundColorOut)
  res_pass.BackgroundTextureBlendFactor.connect_from(sun_updater.BlendFactorOut)
  res_pass.EnvironmentLightingTextureBlendFactor.connect_from(sun_updater.BlendFactorOut)

  def toggle_swap_barrier():
      window_tl.SwapGroup.value = (window_tl.SwapGroup.value + 1) % 2
      window_tr.SwapGroup.value = (window_tr.SwapGroup.value + 1) % 2
      window_bl.SwapGroup.value = (window_bl.SwapGroup.value + 1) % 2
      window_br.SwapGroup.value = (window_br.SwapGroup.value + 1) % 2
      window_tl.SwapBarrier.value = (window_tl.SwapBarrier.value + 1) % 2
      window_tr.SwapBarrier.value = (window_tr.SwapBarrier.value + 1) % 2
      window_bl.SwapBarrier.value = (window_bl.SwapBarrier.value + 1) % 2
      window_br.SwapBarrier.value = (window_br.SwapBarrier.value + 1) % 2

      print("window_tl.SwapGroup.value = ", window_tl.SwapGroup.value)
      print("window_tr.SwapGroup.value = ", window_tr.SwapGroup.value)
      print("window_bl.SwapGroup.value = ", window_bl.SwapGroup.value)
      print("window_br.SwapGroup.value = ", window_br.SwapGroup.value)
      print("window_tl.SwapBarrier.value = ", window_tl.SwapBarrier.value)
      print("window_tr.SwapBarrier.value = ", window_tr.SwapBarrier.value)
      print("window_bl.SwapBarrier.value = ", window_bl.SwapBarrier.value)
      print("window_br.SwapBarrier.value = ", window_br.SwapBarrier.value)

  guaVE = GuaVE()
  guaVE.start(locals(), globals())

  avango.evaluate()
  print("sleep 5 seconds")
  time.sleep(5)
  viewer.run()
Exemplo n.º 44
0
 def testOptimize(self):
     node = avango.osg.nodes.Sphere()
     optimizer = avango.utils.nodes.NodeOptimizer(Node=node)
     optimizer.Trigger.value = True
     avango.evaluate()