Exemple #1
0
    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

            body = avango.gua.nodes.RigidBodyNode(
                Name="body",
                Mass=2.0,
                Friction=0.6,
                RollingFriction=0.03,
                Restitution=0.7,
                Transform=avango.gua.make_trans_mat(
                    math.sin(3 * current_time), 7.0, math.cos(3 *
                                                              current_time)))

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

            sphere_geometry.Transform.value = avango.gua.make_scale_mat(
                0.5, 0.5, 0.5)

            if self.red:
                sphere_geometry.Material.value.set_uniform(
                    #"Color", av.Vec4(0.08, 0.08, 0.09, 1.0))
                    "Color",
                    av.Vec4(0.9, 0.266, 0.136, 1.0))
                sphere_geometry.Material.value.set_uniform("Roughness", 0.75)
                sphere_geometry.Material.value.set_uniform("Metalness", 0.0)

            else:
                sphere_geometry.Material.value.set_uniform(
                    "Color", av.Vec4(1.0, 1.0, 1.0, 1.0))
                sphere_geometry.Material.value.set_uniform("Roughness", 0.2)
                sphere_geometry.Material.value.set_uniform("Metalness", 0.0)

            self.red = not self.red

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

            collision_shape_node.Children.value.append(sphere_geometry)
            body.Children.value.append(collision_shape_node)
            self.SceneGraph.value.Root.value.Children.value.append(body)
            self.Physics.value.add_rigid_body(body)

            self.__spawned_balls.append(body)

            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)
Exemple #2
0
    def RESOLVE_PASS(self, p):
        res_pass = av.nodes.ResolvePassDescription()
        res_pass.BackgroundMode.value = eval("avango.gua.BackgroundMode." +
                                             p.resolve_background_mode)
        res_pass.BackgroundColor.value = from_blender_color(
            p.resolve_background_color)
        res_pass.BackgroundTexture.value = p.resolve_background_texture

        res_pass.VignetteCoverage.value = p.resolve_vignette_coverage
        res_pass.VignetteSoftness.value = p.resolve_vignette_softness
        res_pass.VignetteColor.value = av.Vec4(p.resolve_vignette_color[0],
                                               p.resolve_vignette_color[1],
                                               p.resolve_vignette_color[2],
                                               p.resolve_vignette_color[3])

        res_pass.EnvironmentLightingTexture.value = (
            p.resolve_environment_lighting_texture)
        res_pass.EnvironmentLightingMode.value = eval(
            "avango.gua.EnvironmentLightingMode." +
            p.resolve_environment_lighting_mode)
        res_pass.EnvironmentLightingColor.value = from_blender_color(
            p.resolve_environment_lighting_color)
        res_pass.HorizonFade.value = p.resolve_horizon_fade
        res_pass.EnableSSAO.value = p.resolve_ssao_enable
        res_pass.SSAORadius.value = p.resolve_ssao_radius
        res_pass.SSAOIntensity.value = p.resolve_ssao_intensity
        res_pass.SSAOFalloff.value = p.resolve_ssao_falloff
        res_pass.SSAONoiseTexture.value = p.resolve_noise_tex
        # jo
        res_pass.EnableScreenSpaceShadow.value = (
            p.resolve_screen_space_shadows_enable)
        res_pass.ScreenSpaceShadowRadius.value = (
            p.resolve_screen_space_shadows_radius)
        res_pass.ScreenSpaceShadowMaxRadiusPX.value = (
            p.resolve_screen_space_shadows_max_radius_px)
        res_pass.ScreenSpaceShadowIntensity.value = (
            p.resolve_screen_space_shadows_intensity)
        res_pass.EnableFog.value = p.resolve_enable_fog
        res_pass.FogStart.value = p.resolve_fog_start
        res_pass.FogEnd.value = p.resolve_fog_end
        res_pass.Exposure.value = p.resolve_tone_mapping_exposure
        res_pass.ToneMappingMode.value = eval("avango.gua.ToneMappingMode." +
                                              p.resolve_tone_mapping_mode)
        res_pass.DebugTiles.value = p.resolve_enable_debug_tiles
        return res_pass
Exemple #3
0
floor = create_floor()
physics.add_rigid_body(floor)

sphere_body = create_body()
physics.add_rigid_body(sphere_body)

sphere_geometry = loader.create_geometry_from_file("sphere_geometry",
                                                   "data/objects/sphere.obj")

sphere_geometry.Transform.value = avango.gua.make_scale_mat(0.5, 0.5, 0.5)

sphere_geometry.Material.value.set_uniform(
    #"Color", av.Vec4(0.08, 0.08, 0.09, 1.0))
    "Color",
    av.Vec4(0.9, 0.266, 0.136, 1.0))
sphere_geometry.Material.value.set_uniform("Roughness", 0.75)
sphere_geometry.Material.value.set_uniform("Metalness", 0.0)

transform1 = avango.gua.nodes.TransformNode(Children=[sphere_geometry])
transform1.Transform.connect_from(sphere_body.Transform)

graph.Root.value.Children.value = [
    light, screen, floor, sphere_body, transform1
]

timer = avango.nodes.TimeSensor()

#setup viewer
viewer = av.nodes.Viewer()
viewer.Physics.value = physics
Exemple #4
0
def start():
    graph = av.nodes.SceneGraph(Name="scene")
    loader = av.nodes.TriMeshLoader()

    fps_size = av.Vec2(170, 55)

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

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

    fallback_mat = av.create_material(av.MaterialCapabilities.COLOR_VALUE |
                                      av.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,
                    av.LoaderFlags.DEFAULTS)

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

    sun_light = av.nodes.LightNode(Name="sun_light",
                                   Type=av.LightType.SUN,
                                   Color=av.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,
                                             av.LoaderFlags.DEFAULTS)
    floor.Transform.value = av.make_scale_mat(
        200, 1, 200) * av.make_trans_mat(-0.5, -0.2, -0.5)
    floor.ShadowMode.value = 0
    graph.Root.value.Children.value.append(floor)

    width = 1920
    height = int(width * 9.0 / 16.0)
    size = av.Vec2ui(width, height)

    screen = av.nodes.ScreenNode(Name="screen",
                                 Width=4.8,
                                 Height=2.7,
                                 Transform=av.make_trans_mat(0.0, 0.0, -2.5))

    camera = av.nodes.CameraNode(Name="cam",
                                 LeftScreenPath="/cam/screen",
                                 RightScreenPath="/cam/screen",
                                 SceneGraph="scene",
                                 Resolution=size,
                                 OutputWindowName="window",
                                 EyeDistance=0.2,
                                 EnableStereo=False,
                                 Children=[screen],
                                 Transform=av.make_trans_mat(0.0, 0.0, 7.0))

    res_pass = av.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 = av.EnvironmentLightingMode.CUBEMAP
    res_pass.ToneMappingMode.value = av.ToneMappingMode.UNCHARTED
    res_pass.Exposure.value = 1.0
    res_pass.VignetteColor.value = av.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 = av.BackgroundMode.CUBEMAP_TEXTURE
    res_pass.BackgroundTexture.value = "day_skymap"
    res_pass.AlternativeBackgroundTexture.value = "night_skymap"

    sky_pass = av.nodes.SkyMapPassDescription(OutputTextureName="day_skymap")

    av.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 = av.nodes.PipelineDescription(Passes=[
        sky_pass, av.nodes.TriMeshPassDescription(
        ), av.nodes.LightVisibilityPassDescription(
        ), res_pass, av.nodes.TexturedScreenSpaceQuadPassDescription()
    ])

    camera.PipelineDescription.value = pipeline_description

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

    window = av.nodes.Window(Size=size,
                             Title="shadows",
                             LeftResolution=size,
                             RightResolution=size,
                             EnableVsync=False,
                             StereoMode=av.StereoMode.MONO)

    av.register_window("window", window)

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

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

    camera.Transform.connect_from(navigator.OutTransform)

    viewer = av.nodes.Viewer()
    viewer.SceneGraphs.value = [graph]
    viewer.Windows.value = [window]

    timer = avango.nodes.TimeSensor()

    fps_updater = FPSUpdater(FPSResource=fps, Window=window, 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)

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

    viewer.run()
Exemple #5
0
def scene_update(scene):
    objects = bpy.data.objects
    if objects.is_updated:

        for o in objects:
            if o.name in g_cached_objects:
                if o.is_updated or o.is_updated_data:
                    if o.type == 'LAMP':

                        bl_lamp = bpy.data.lamps[o.data.name]
                        lamp = g_cached_objects[o.name]
                        lamp.Type.value = from_blender_lamp_type(o.data.type)
                        lamp.Name.value = o.name
                        lamp.Color.value = from_blender_color(bl_lamp.color)
                        lamp.Brightness.value = bl_lamp.energy
                        lamp.Transform.value = from_blender_matrix4(
                            o.matrix_world)
                    elif o.type == 'MESH':
                        mesh = g_cached_objects[o.name]
                        mesh.Transform.value = from_blender_matrix4(
                            o.matrix_world)
                        for slot in o.material_slots:
                            # material = o.material_slots['Material'].material
                            material = o.material_slots[0].material
                            if material.is_updated:
                                amaterial = material.avango
                                col = slot.material.diffuse_color

                                mesh.Material.value.set_uniform(
                                    "Color", av.Vec4(col.r, col.g, col.b, 1.0))
                                mesh.Material.value.set_uniform(
                                    "Roughness", amaterial.roughness)
                                mesh.Material.value.set_uniform(
                                    "Metalness", float(amaterial.metalness))
                                mesh.Material.value.set_uniform(
                                    "Emissivity", amaterial.emissivity)
                                mesh.Material.value.set_uniform(
                                    "Opacity", amaterial.opacity)
                    elif o.type == 'CAMERA':
                        camera = g_cached_objects[o.name]
                        camera.Transform.value = from_blender_matrix4(
                            o.matrix_world)
                        if o.is_updated_data:
                            pc = PassCreator()
                            ps = pc.create(o.data.avango.pipeline_passes)
                            camera.PipelineDescription.value.Passes.value = ps
                    elif o.type == 'MATERIAL':
                        print("MATERIAL ???", o.type)
                    elif o.type == 'FONT':
                        print("what???", o.type)
                        mesh = g_cached_objects[o.name]
                        mesh.Transform.value = from_blender_matrix4(
                            o.matrix_world)
                        for slot in o.material_slots:
                            # material = o.material_slots['Material'].material
                            material = o.material_slots[0].material
                            if material.is_updated:
                                amaterial = material.avango
                                col = slot.material.diffuse_color

                                mesh.Material.value.set_uniform(
                                    "Color", av.Vec4(col.r, col.g, col.b, 1.0))
                                mesh.Material.value.set_uniform(
                                    "Roughness", amaterial.roughness)
                                mesh.Material.value.set_uniform(
                                    "Metalness", float(amaterial.metalness))
                                mesh.Material.value.set_uniform(
                                    "Emissivity", amaterial.emissivity)
                                mesh.Material.value.set_uniform(
                                    "Opacity", amaterial.opacity)
                    else:
                        print("what???", o.type)
Exemple #6
0
def engine_update(engine, data, scene):
    # if hasattr(engine, "session"):
    #     print("update " + engine.session['uuid'])
    # b_space_view_3d = context.space_data
    # rv3d = b_space_view_3d.region_3d
    # self.camera.NearClip.value = b_space_view_3d.clip_start
    # self.camera.FarClip.value = b_space_view_3d.clip_end
    # xs = matrix_to_list(rv3d.view_matrix)
    # print(xs)
    # #self.camera.Transform.value = av.transpose(
    #     av.from_list(xs))
    # self.camera.Transform.value = av.transpose(
    #     av.inverse(av.from_list(xs)))

    for o in scene.objects:
        if o.name not in g_cached_objects:
            if o.type == 'LAMP':
                bl_lamp = bpy.data.lamps[o.data.name]
                light = av.nodes.LightNode(
                    Type=from_blender_lamp_type(o.data.type),
                    Name=o.name,
                    Color=from_blender_color(bl_lamp.color),
                    Brightness=bl_lamp.energy,
                    Transform=from_blender_matrix4(o.matrix_world))
                g_cached_objects[o.name] = light
                g_graph.Root.value.Children.value.append(light)
            elif o.type == 'MESH':
                # parent = 'null'
                # if o.parent:
                #    parent = o.parent.name
                # matrix = o.matrix_world
                filename = o.name + '.obj'

                path = '/tmp/'

                if not os.path.exists(path):
                    os.makedirs(path)

                bpy.ops.object.select_all(action='DESELECT')
                # scene.objects.active = o
                o.select = True
                world = o.matrix_world.copy()
                Matrix.identity(o.matrix_world)
                bpy.ops.export_scene.obj(filepath=path + filename,
                                         check_existing=False,
                                         use_selection=True,
                                         use_normals=True,
                                         use_triangles=True,
                                         use_uvs=True,
                                         use_materials=True,
                                         axis_forward='Y',
                                         axis_up='Z',
                                         path_mode='AUTO')
                o.matrix_world = world
                o.select = False

                mesh = g_loader.create_geometry_from_file(
                    o.name, path + filename, av.LoaderFlags.NORMALIZE_SCALE)
                for slot in o.material_slots:
                    # material = o.material_slots['Material'].material
                    material = o.material_slots[0].material
                    amaterial = material.avango
                    col = slot.material.diffuse_color

                    mesh.Material.value.set_uniform(
                        "Color", av.Vec4(col.r, col.g, col.b, 1.0))
                    if slot.material.avango.use_color_texture:
                        mesh.Material.value.set_uniform(
                            "ColorMap",
                            texture_filepath(
                                slot.material.avango.color_texture))
                    mesh.Material.value.set_uniform("Roughness",
                                                    amaterial.roughness)
                    if slot.material.avango.use_roughness_texture:
                        mesh.Material.value.set_uniform(
                            "RoughnessMap",
                            texture_filepath(
                                slot.material.avango.roughness_texture))
                    mesh.Material.value.set_uniform("Metalness",
                                                    float(amaterial.metalness))
                    if slot.material.avango.use_metalness_texture:
                        mesh.Material.value.set_uniform(
                            "MetalnessMap",
                            texture_filepath(
                                slot.material.avango.metalness_texture))
                    mesh.Material.value.set_uniform("Emissivity",
                                                    amaterial.emissivity)
                    mesh.Material.value.set_uniform("Opacity",
                                                    amaterial.opacity)

                g_cached_objects[o.name] = mesh
                g_graph.Root.value.Children.value.append(mesh)
            elif o.type == 'CAMERA':
                bl_camera = bpy.data.cameras[o.data.name]
                acamera = bl_camera.avango
                screen = av.nodes.ScreenNode(
                    Name="screen",
                    Width=2,
                    Height=1.5,
                    Transform=av.make_trans_mat(0.0, 0.0, -2.5),
                )

                #res_pass = av.nodes.ResolvePassDescription()
                #res_pass.EnableSSAO.value = True
                #res_pass.SSAOIntensity.value = 4.0
                #res_pass.SSAOFalloff.value = 10.0
                #res_pass.SSAORadius.value = 7.0
                #res_pass.EnvironmentLightingColor.value = (
                #    av.Color(0.1, 0.1, 0.1))
                #res_pass.ToneMappingMode.value = av.ToneMappingMode.UNCHARTED
                #res_pass.Exposure.value = 1.0
                #res_pass.BackgroundColor.value = av.Color(1.0, 0.0, 0.0)

                pc = PassCreator()
                passes = pc.create(o.data.avango.pipeline_passes)

                pipeline_description = av.nodes.PipelineDescription(
                    Passes=passes,
                    EnableABuffer=acamera.enable_abuffer,
                )

                camera = av.nodes.CameraNode(
                    Name=o.name,
                    LeftScreenPath="/" + o.name + "/screen",
                    SceneGraph="scenegraph",
                    Resolution=av.Vec2ui(acamera.resolution[0],
                                         acamera.resolution[1]),
                    OutputWindowName="blender_window",
                    Children=[screen],
                    Transform=from_blender_matrix4(o.matrix_world),
                    NearClip=bl_camera.clip_start,
                    FarClip=bl_camera.clip_end,
                    Mode=0 if o.data.type == 'PERSP' else 1,
                    PipelineDescription=pipeline_description,
                )
                g_cached_objects[o.name] = camera
                g_graph.Root.value.Children.value.append(camera)