def render_strings_array(strings=None, fade=1.0, fonts_dict={}):
    sys = render.get_render_system()
    render.get_renderer().EnableBlending(True)
    render.get_renderer().EnableDepthTest(False)

    for line in strings:
        font_key = line[4] + "_" + str(line[5])
        if not font_key in fonts_dict:
            fonts_dict[font_key] = gs.RasterFont(
                "@assets/" + line[4] + ".ttf", int(line[5] * zoom_size() / 3),
                512)

        rect = fonts_dict[font_key].GetTextRect(sys, line[0])
        x = (demo_screen_size[0] - rect.GetWidth()) * 0.5
        y = (amiga_screen_size[1] - line[1]) * zoom_size()
        fonts_dict[font_key].Write(sys, line[0], gs.Vector3(x, y, 0.5),
                                   gs.Color.White * fade)

    sys.DrawRasterFontBatch()

    render.get_renderer().EnableBlending(False)

    # underline ?
    for line in strings:
        if line[3] == 1:
            font_key = line[4] + "_" + str(line[5])
            rect = fonts_dict[font_key].GetTextRect(sys, line[0])
            x = (demo_screen_size[0] - rect.GetWidth()) * 0.5
            y = (amiga_screen_size[1] - line[1]) * zoom_size() - (
                line[5] * 0.2 * zoom_size() / 3)
            render.line2d(x, y, x + rect.GetWidth(), y,
                          gs.Color.White * fade * fade,
                          gs.Color.White * fade * fade)

    return fonts_dict
def render_strings_array(strings = None, fade = 1.0, fonts_dict = {}):
	sys = render.get_render_system()
	render.get_renderer().EnableBlending(True)
	render.get_renderer().EnableDepthTest(False)

	for line in strings:
		font_key = line[4] + "_" + str(line[5])
		if not font_key in fonts_dict:
			fonts_dict[font_key] = gs.RasterFont("@assets/" + line[4] + ".ttf", int(line[5] * zoom_size() / 3), 512)

		rect = fonts_dict[font_key].GetTextRect(sys, line[0])
		x = (demo_screen_size[0] - rect.GetWidth()) * 0.5
		y = (amiga_screen_size[1] - line[1]) * zoom_size()
		fonts_dict[font_key].Write(sys, line[0], gs.Vector3(x, y, 0.5), gs.Color.White * fade)

	sys.DrawRasterFontBatch()

	render.get_renderer().EnableBlending(False)

	# underline ?
	for line in strings:
		if line[3] == 1:
			font_key = line[4] + "_" + str(line[5])
			rect = fonts_dict[font_key].GetTextRect(sys, line[0])
			x = (demo_screen_size[0] - rect.GetWidth()) * 0.5
			y = (amiga_screen_size[1] - line[1]) * zoom_size() - (line[5] * 0.2 * zoom_size() / 3)
			render.line2d(x, y, x + rect.GetWidth(), y, gs.Color.White * fade * fade, gs.Color.White * fade * fade)

	return fonts_dict
Esempio n. 3
0
    def init(cls):
        cls.rendu = render.get_renderer()
        cls.clavier = input.get_keyboard()

        cls.systeme = render.get_render_system()

        cls.rendu2d = gs.SimpleGraphicEngine()
        cls.rendu2d.SetDepthWrite(False)
        cls.rendu2d.SetDepthTest(True)
        cls.rendu2d.SetBlendMode(gs.BlendAlpha)
        cls.rendu_scene=None    #Initialisé à chaque activation de scène

        cls.texture_ombre_sol=Demo.rendu.LoadTexture("textures/ombre_sol.png")
        cls.texture_bruit_01=Demo.rendu.LoadTexture("textures/bruit_01.png")

        if cls.texture_ombre_sol is None or cls.texture_bruit_01 is None:
            cls.message_erreur="Impossible de charger les textures de base"
            cls.drapeau_erreur=True

        #Shaders par défaut:
        cls.shader_billboards=cls.systeme.LoadSurfaceShader("shaders/sprite_alpha.isl",False)
        cls.shader_constant_map=cls.systeme.LoadSurfaceShader("shaders/constant_map.isl",False)
        cls.shader_constant=cls.systeme.LoadSurfaceShader("shaders/diffuse_constante.isl",False)
        cls.shader_ocean_01=cls.systeme.LoadSurfaceShader("shaders/ocean.isl",False)
        cls.shader_ocean_02=cls.systeme.LoadSurfaceShader("shaders/ocean_proche.isl",False)
        cls.shader_transparent=cls.systeme.LoadSurfaceShader("shaders/diffuse_alpha.isl",False)

        #Init le post-rendu:
        cls.init_post_rendu()

        #Init le gestionnaire sonore:
        cls.audio = gs.ALMixer()
        cls.audio.Open()
	def __init__(self, size_world):
		self.sphere_array = []
		self.tile_array = []

		with open("map.txt") as f:
			data = f.readlines()
			y = -5
			for d in data:
				x = -5
				for v in d:
					if v == 'X':
						self.sphere_array.extend([sphere(x, y, 0.5)])
					x += 1
				y += 1

		self.tile_ground = render.get_render_system().LoadGeometry("@core/res/tile_0.geo")
		self.wall_1m = render.get_render_system().LoadGeometry("@core/res/wall_1m_high.geo")
		self.wall_2m = render.get_render_system().LoadGeometry("@core/res/wall_2m_high.geo")
Esempio n. 5
0
    def init(cls):

        #-------- Environnement:
        cls.couleur_horizon = gs.Color(1., .699, .586)
        cls.couleur_zenith = gs.Color(1., 0.978, 0.407)
        cls.couleur_ambiante = gs.Color(0.19, 0.42, 0.34)
        #cls.couleur_ambiante=gs.Color(0.5,0.5,0.5)

        #-------- Création de la scène:
        cls.scene3d = scene.new_scene()

        cls.contexte = gs.SceneLoadContext(render.get_render_system())
        cls.scene3d.Load("scene_01/Gare_test.scn", cls.contexte)
        #----------- Attend que la scène soit accessible:
        scene.update_scene(cls.scene3d, 1 / 60)

        #----------- Prise en main de la scène:
        cls.noeuds = cls.contexte.GetNodes()
        cls.components = cls.scene3d.GetComponents()

        for comp in cls.components:
            if comp.GetAspect() == "Environment":
                cls.environnement = comp
                break

        #----------- Init billboards et shaders:

        cls.init_billboards(cls.noeuds, cls.liste_sprites_scene)
        cls.init_shaders(cls.noeuds)

        #----------- Init environnement:

        cls.environnement.SetBackgroundColor(cls.couleur_horizon)
        cls.environnement.SetFogColor(cls.couleur_horizon)
        cls.environnement.SetFogNear(1)
        cls.environnement.SetFogFar(100)
        cls.environnement.SetAmbientIntensity(2)
        cls.environnement.SetAmbientColor(cls.couleur_ambiante)

        cls.camera = cls.scene3d.GetNode("Camera")
        cls.camera.GetCamera().SetZNear(.1)
        cls.camera.GetCamera().SetZFar(1000.)
        cls.camera_start_pos_mem = cls.camera.GetTransform().GetPosition()
        #cls.camera.AddComponent(gs.Target())   #Si la caméra suit une cible

        cls.lumiere_clair_obscur = cls.scene3d.GetNode("clair obscur")
        cls.lumiere_soleil = cls.scene3d.GetNode("soleil")

        cls.lumiere_soleil.GetLight().SetShadow(
            gs.Light.Shadow_Map)  #Active les ombres portées
        cls.lumiere_soleil.GetLight().SetShadowRange(100)

        cls.lumiere_soleil.GetLight().SetDiffuseIntensity(1.)
        cls.lumiere_soleil.GetLight().SetSpecularIntensity(1.)

        orientation = gs.Vector3(54 / 180 * pi, 135 / 180 * pi, 0)
        cls.lumiere_clair_obscur.GetTransform().SetRotation(orientation)

        orientation = gs.Vector3(54 / 180 * pi, -45 / 180 * pi, 0)
        cls.lumiere_soleil.GetTransform().SetRotation(orientation)

        #cls.lumiere_clair_obscur.GetLight().SetDiffuseIntensity(2.)
        #cls.lumiere_clair_obscur.GetLight().SetSpecularIntensity(2.)

        #-------- Mémorise les intensités lumineuses pour le switch des éclairages:
        noeuds = cls.scene3d.GetNodes()
        for noeud in noeuds:
            if not noeud.GetLight() == None:
                cls.lumieres_intens_mem.append(
                    noeud.GetLight().GetDiffuseIntensity())
                cls.lumieres_intens_mem.append(
                    noeud.GetLight().GetSpecularIntensity())

        #--------Init les variables de shaders:

        #Couleur d'ambiance:
        """
        for noeud in cls.noeuds:
            if not noeud.GetObject()==None:
                obj=noeud.GetObject()
                geo=obj.GetGeometry()
                n=geo.GetMaterialCount()
                i=0
                while i<n:
                    materiau=geo.GetMaterial(i)
                    materiau.SetFloat3("ambient_color",cls.couleur_ambiante.r*0.,cls.couleur_ambiante.g*0.,cls.couleur_ambiante.b*0.)
                    i+=1
        """
        #--------- Init listes des sprites:
        #cls.liste_sprites_scene.append(...)

        #--------- Inits de l'éditeur embarqué
        cls.cube_l_soleil = scene.add_cube(cls.scene3d, gs.Matrix4.Identity,
                                           0.5, 0.5, 2.)
        cls.cube_l_clair_obscur = scene.add_cube(cls.scene3d,
                                                 gs.Matrix4.Identity, 0.5, 0.5,
                                                 2.)

        cls.scene3d.SetCurrentCamera(cls.camera)

        scene.update_scene(cls.scene3d, 1 / 60)
def convert_folder(folder_path):
    scn = None

    nml_reader = NmlReader()

    for in_file in os.listdir(folder_path):

        if os.path.isdir(os.path.join(folder_path, in_file)):
            convert_folder(os.path.join(folder_path, in_file))
        else:
            if in_file.find(".nms") > -1:
                # Found a NMS file, creates a new scene
                scn = scene.new_scene()
                links = []
                uid_dict = {}

                print("Reading file ", os.path.join(folder_path, in_file))
                nml_reader.LoadingXmlFile(os.path.join(folder_path, in_file))

                in_root = nml_reader.main_node.GetChild("Scene")
                in_items = in_root.GetChilds("Items")

                # ----------- LINKAGE ----------------------
                in_links_root = in_root.GetChild("Links")

                if in_links_root is not None:
                    in_links = in_links_root.GetChilds("Link")

                    for in_link in in_links:
                        child_item = int(get_nml_node_data(in_link.GetChild("Item"), -1))
                        parent_item = int(get_nml_node_data(in_link.GetChild("Link"), -1))

                        if child_item != -1 and parent_item != -1:
                            links.append({"child": child_item, "parent": parent_item})

                            # ----------- INSTANCES ----------------------
                for in_item in in_items:
                    #   Load instances
                    instances = in_item.GetChilds("Instance")

                    for instance in instances:
                        mitem = instance.GetChild("MItem")
                        item = instance.GetChild("Item")
                        template = instance.GetChild("Template")

                        if (
                            mitem is not None
                            and mitem.GetChild("Active") is not None
                            and mitem.GetChild("Helper") is None
                        ):
                            instance_path = get_nml_node_data(instance.GetChild("Template"))

                            if instance_path is not None:
                                # get item name
                                item_name = get_nml_node_data(mitem.GetChild("Id"), "default_name")
                                uid = int(get_nml_node_data(mitem.GetChild("UId"), -1))

                                # transformation
                                position, rotation, scale, rotation_order = parse_transformation(item)

                                new_node = gs.Node(item_name)
                                scn.AddNode(new_node)

                                node_transform = gs.Transform()
                                node_transform.SetPosition(position)
                                node_transform.SetRotation(rotation)
                                node_transform.SetScale(scale)
                                new_node.AddComponent(node_transform)

                                instance_path = instance_path.replace(".nms", ".scn")
                                instance_path = instance_path.replace("scenes/", folder_assets)

                                node_instance = gs.Instance()
                                node_instance.SetPath(instance_path)
                                new_node.AddComponent(node_instance)

                                # ----------- CAMERAS ----------------------
                for in_item in in_items:
                    #   Load cameras
                    mcameras = in_item.GetChilds("MCamera")

                    for mcamera in mcameras:
                        mitem = mcamera.GetChild("MItem")
                        if (
                            mitem is not None
                            and mitem.GetChild("Active") is not None
                            and mitem.GetChild("Helper") is None
                        ):
                            camera = mcamera.GetChild("Camera")
                            item = camera.GetChild("Item")

                            # get item name
                            item_name = get_nml_node_data(mitem.GetChild("Id"), "default_name")
                            uid = int(get_nml_node_data(mitem.GetChild("UId"), -1))

                            # transformation
                            position, rotation, scale, rotation_order = parse_transformation(item)

                            znear = float(get_nml_node_data(item.GetChild("ZNear"), 0.2))
                            zfar = float(get_nml_node_data(item.GetChild("ZFar"), 50000.0))
                            zoom = float(get_nml_node_data(item.GetChild("ZoomFactor"), 5.0)) / 2.0

                            new_node = scene.add_camera(scn)
                            new_node.SetName(item_name)
                            new_node.GetComponentsWithAspect("Transform")[0].SetPosition(position)
                            new_node.GetComponentsWithAspect("Transform")[0].SetRotation(rotation)

                            new_node.GetComponentsWithAspect("Camera")[0].SetZNear(znear)
                            new_node.GetComponentsWithAspect("Camera")[0].SetZFar(zfar)
                            new_node.GetComponentsWithAspect("Camera")[0].SetZoomFactor(zoom)

                            uid_dict[str(uid)] = new_node

                            # ----------- LIGHT ----------------------
                for in_item in in_items:
                    #   Load lights
                    mlights = in_item.GetChilds("MLight")

                    for mlight in mlights:
                        mitem = mlight.GetChild("MItem")
                        if (
                            mitem is not None
                            and mitem.GetChild("Active") is not None
                            and mitem.GetChild("Helper") is None
                        ):
                            light = mlight.GetChild("Light")
                            item = light.GetChild("Item")

                            # get item name
                            item_name = get_nml_node_data(mitem.GetChild("Id"), "default_name")
                            uid = int(get_nml_node_data(mitem.GetChild("UId"), -1))

                            # transformation
                            position, rotation, scale, rotation_order = parse_transformation(item)
                            diffuse_color, specular_color, shadow_color = parse_light_color(light)

                            new_node = scene.add_light(scn)
                            new_node.SetName(item_name)
                            new_node.GetComponentsWithAspect("Transform")[0].SetPosition(position)
                            new_node.GetComponentsWithAspect("Transform")[0].SetRotation(rotation)
                            new_node.GetComponentsWithAspect("Transform")[0].SetScale(scale)

                            # light type
                            light_type = light.GetChild("Type")
                            light_type = get_nml_node_data(light_type, "Point")

                            light_range = float(get_nml_node_data(light.GetChild("Range"), 0.0))

                            if light_type == "Point":
                                new_node.GetComponentsWithAspect("Light")[0].SetModel(gs.Light.Model_Point)
                                new_node.GetComponentsWithAspect("Light")[0].SetRange(light_range)

                            if light_type == "Parallel":
                                new_node.GetComponentsWithAspect("Light")[0].SetModel(gs.Light.Model_Linear)

                            if light_type == "Spot":
                                new_node.GetComponentsWithAspect("Light")[0].SetModel(gs.Light.Model_Spot)
                                new_node.GetComponentsWithAspect("Light")[0].SetRange(light_range)
                                new_node.GetComponentsWithAspect("Light")[0].SetConeAngle(
                                    float(get_nml_node_data(light.GetChild("ConeAngle"), 30.0))
                                )
                                new_node.GetComponentsWithAspect("Light")[0].SetEdgeAngle(
                                    float(get_nml_node_data(light.GetChild("EdgeAngle"), 15.0))
                                )

                            new_node.GetComponentsWithAspect("Light")[0].SetShadowRange(
                                float(get_nml_node_data(light.GetChild("ShadowRange"), 0.0))
                            )
                            new_node.GetComponentsWithAspect("Light")[0].SetClipDistance(
                                float(get_nml_node_data(light.GetChild("ClipDistance"), 300.0))
                            )

                            new_node.GetComponentsWithAspect("Light")[0].SetDiffuseColor(diffuse_color)
                            new_node.GetComponentsWithAspect("Light")[0].SetSpecularColor(specular_color)
                            new_node.GetComponentsWithAspect("Light")[0].SetShadowColor(shadow_color)

                            new_node.GetComponentsWithAspect("Light")[0].SetDiffuseIntensity(
                                float(get_nml_node_data(light.GetChild("DiffuseIntensity"), 1.0))
                            )
                            new_node.GetComponentsWithAspect("Light")[0].SetSpecularIntensity(
                                float(get_nml_node_data(light.GetChild("SpecularIntensity"), 0.0))
                            )

                            new_node.GetComponentsWithAspect("Light")[0].SetZNear(
                                float(get_nml_node_data(light.GetChild("ZNear"), 0.01))
                            )
                            new_node.GetComponentsWithAspect("Light")[0].SetShadowBias(
                                float(get_nml_node_data(light.GetChild("ShadowBias"), 0.01))
                            )

                            uid_dict[str(uid)] = new_node

                            # ----------- GEOMETRIES & NULL OBJECTS ----------------------
                for in_item in in_items:
                    #   Load items with geometry
                    mobjects = in_item.GetChilds("MObject")
                    for mobject in mobjects:
                        mitem = mobject.GetChild("MItem")
                        if (
                            mitem is not None
                            and mitem.GetChild("Active") is not None
                            and mitem.GetChild("Helper") is None
                        ):
                            object = mobject.GetChild("Object")
                            item = object.GetChild("Item")

                            # get item name
                            item_name = get_nml_node_data(mitem.GetChild("Id"), "default_name")
                            uid = int(get_nml_node_data(mitem.GetChild("UId"), -1))

                            # get item geometry
                            geometry_filename = None
                            if object is not None:
                                geometry = object.GetChild("Geometry")
                                if geometry is not None:
                                    geometry_filename = geometry.m_Data
                                    geometry_filename = clean_nml_string(geometry_filename)
                                    if geometry_filename.find("/") > -1:
                                        geometry_filename = geometry_filename.split("/")[-1]
                                    geometry_filename = geometry_filename.replace(".nmg", ".geo")

                                    # transformation
                            position, rotation, scale, rotation_order = parse_transformation(item)

                            new_node = None

                            if geometry_filename is not None and geometry_filename != "":
                                new_node = scene.add_geometry(scn, os.path.join(folder_assets, geometry_filename))
                            else:
                                new_node = scene.add_geometry(scn, "")

                            if new_node is not None:
                                new_node.SetName(item_name)
                                new_node.GetComponentsWithAspect("Transform")[0].SetPosition(position)
                                new_node.GetComponentsWithAspect("Transform")[0].SetRotation(rotation)
                                new_node.GetComponentsWithAspect("Transform")[0].SetScale(scale)

                                # physics
                                physic_item = mitem.GetChild("PhysicItem")
                                if physic_item is not None:
                                    physic_mode = get_nml_node_data(physic_item.GetChild("Mode"), "None")
                                    if physic_mode != "None":
                                        rigid_body = gs.MakeRigidBody()

                                        linear_damping = 1.0 - float(
                                            get_nml_node_data(physic_item.GetChild("LinearDamping_v2"), 1.0)
                                        )
                                        angular_damping = 1.0 - float(
                                            get_nml_node_data(physic_item.GetChild("AngularDamping_v2"), 1.0)
                                        )
                                        rigid_body.SetLinearDamping(linear_damping)
                                        rigid_body.SetAngularDamping(angular_damping)

                                        physic_self_mask = int(get_nml_node_data(physic_item.GetChild("SelfMask"), 1))
                                        physic_collision_mask = int(get_nml_node_data(physic_item.GetChild("Mask"), 1))

                                        new_node.AddComponent(rigid_body)

                                        # iterate on shapes
                                        physic_root_shapes = physic_item.GetChild("Shapes")
                                        if physic_root_shapes is not None:
                                            physic_shapes = physic_root_shapes.GetChilds("GColShape")
                                            if physic_shapes is not None:
                                                for physic_shape in physic_shapes:
                                                    physic_shape_type = get_nml_node_data(
                                                        physic_shape.GetChild("Type"), "Box"
                                                    )

                                                    col_type_dict = {
                                                        "Box": gs.MakeBoxCollision(),
                                                        "Sphere": gs.MakeSphereCollision(),
                                                        "Capsule": gs.MakeCapsuleCollision(),
                                                        "Cylinder": gs.MakeCapsuleCollision(),
                                                        "Mesh": gs.MakeMeshCollision(),
                                                        "Convex": gs.MakeConvexCollision(),
                                                    }

                                                    if physic_shape_type in col_type_dict:
                                                        new_collision_shape = col_type_dict[physic_shape_type]
                                                    else:
                                                        new_collision_shape = gs.MakeBoxCollision()

                                                    new_collision_shape.SetMass(
                                                        float(get_nml_node_data(physic_shape.GetChild("Mass"), 1.0))
                                                    )
                                                    new_collision_shape.SetSelfMask(physic_self_mask)
                                                    new_collision_shape.SetCollisionMask(physic_collision_mask)

                                                    position, rotation, scale, dimensions = parse_collision_shape_transformation(
                                                        physic_shape
                                                    )

                                                    # new_collision_shape.SetMatrix()

                                                    if physic_shape_type == "Box":
                                                        new_collision_shape.SetDimensions(dimensions)
                                                    elif physic_shape_type == "Sphere":
                                                        new_collision_shape.SetRadius(dimensions.x)
                                                    elif (
                                                        physic_shape_type == "Capsule"
                                                        or physic_shape_type == "Cylinder"
                                                    ):
                                                        new_collision_shape.SetRadius(dimensions.x)
                                                        new_collision_shape.SetLength(dimensions.y)

                                                    new_node.AddComponent(new_collision_shape)

                                uid_dict[str(uid)] = new_node

                                # ----------- RE-LINKAGE ----------------------
                for linkage in links:
                    if linkage["parent"] is not None and linkage["child"] is not None:

                        if str(linkage["child"]) in uid_dict and str(linkage["parent"]) in uid_dict:
                            uid_dict[str(linkage["child"])].GetComponentsWithAspect("Transform")[0].SetParent(
                                uid_dict[str(linkage["parent"])]
                            )

                            # ----------- ENVIRONMENT ----------------------
                in_globals = in_root.GetChild("Globals")

                env_global = gs.Environment()
                scn.AddComponent(env_global)

                bg_color, ambient_color, fog_color = parse_globals_color(in_globals)

                ambient_intensity = float(get_nml_node_data(in_globals.GetChild("AmbientIntensity"), 0.5))
                fog_near = float(get_nml_node_data(in_globals.GetChild("FogNear"), 0.5))
                fog_far = float(get_nml_node_data(in_globals.GetChild("FogFar"), 0.5))

                env_global.SetBackgroundColor(bg_color)

                env_global.SetAmbientIntensity(ambient_intensity)
                env_global.SetAmbientColor(ambient_color)

                env_global.SetFogNear(fog_near)
                env_global.SetFogFar(fog_far)
                env_global.SetFogColor(fog_color)

                scn.Commit()
                scn.WaitCommit()

                # Creates the output folder
                folder_out = folder_path.replace(root_in + "\\", "")
                folder_out = folder_out.replace(root_in + "/", "")
                folder_out = folder_out.replace(root_in, "")

                if folder_out != "" and not os.path.exists(os.path.join(root_out, folder_out)):
                    os.makedirs(os.path.join(root_out, folder_out), exist_ok=True)

                    # Saves the scene
                out_file = os.path.join("@out", folder_out, in_file.replace(".nms", ".scn"))
                print("saving to ", out_file)
                scn.Save(out_file, gs.SceneSaveContext(render.get_render_system()))

                # Clears the scene
                scn.Clear()
                scn.Dispose()
                scn = None
Esempio n. 7
0
def final():
	render.clear()

	# initialize graphic and audio systems

	movie = gs.WebMMovie()
	movie.Open("@data/sylvain_durif.webm")

	video_format = movie.GetVideoData().GetFormat()

	# create the frame textures and frame object
	gpu = render.get_renderer()
	y_tex = gpu.NewTexture()
	gpu.CreateTexture(y_tex, video_format.width, video_format.height, gs.GpuTexture.R8, gs.GpuTexture.NoAA,
					  gs.GpuTexture.UsageDefault, False)
	u_tex = gpu.NewTexture()
	gpu.CreateTexture(u_tex, video_format.width // 2, video_format.height // 2, gs.GpuTexture.R8,
						  gs.GpuTexture.NoAA, gs.GpuTexture.UsageDefault, False)
	v_tex = gpu.NewTexture()
	gpu.CreateTexture(v_tex, video_format.width // 2, video_format.height // 2, gs.GpuTexture.R8,
						  gs.GpuTexture.NoAA, gs.GpuTexture.UsageDefault, False)

	frame = gs.VideoFrame()
	video_format.ClearFrame(frame)
	video_timestamp = gs.time(0)  # assume first frame time stamp is 0

	# load the YV12 to RGB shader and setup drawing states
	shader = gpu.LoadShader("@data/yv12.isl")

	gpu.EnableDepthTest(False)  # disable depth testing so that we don't even need to clear the z-buffer

	# start streaming the movie audio data
	channel = audio.get_mixer().StreamData(movie.GetAudioData())

	# play until movie ends
	while not movie.IsEOF():
		render.clear()
		# fit the while output window
		screen_size = gpu.GetCurrentOutputWindow().GetSize()
		gpu.SetViewport(gs.fRect(0, 0, screen_size.x, screen_size.y))
		gpu.Set2DMatrices()  # update the 2d matrix

		# fetch the next video frame once audio gets past video
		audio_timestamp = audio.get_mixer().GetChannelPosition(channel)  # audio timestamp as reported by the mixer

		if audio_timestamp >= video_timestamp:
			movie.GetVideoData().GetFrame(frame)
			video_timestamp = frame.GetTimestamp()
			gpu.BlitTexture(y_tex, frame.GetPlaneData(gs.VideoFrame.Y), video_format.width, video_format.height)
			gpu.BlitTexture(u_tex, frame.GetPlaneData(gs.VideoFrame.U), video_format.width // 2,
							video_format.height // 2)
			gpu.BlitTexture(v_tex, frame.GetPlaneData(gs.VideoFrame.V), video_format.width // 2,
							video_format.height // 2)

			# draw the current video frame to screen
			vtxs = [gs.Vector3(0, 0, 0.5), gs.Vector3(0, screen_size.y, 0.5),
					gs.Vector3(screen_size.x, screen_size.y, 0.5), gs.Vector3(0, 0, 0.5),
					gs.Vector3(screen_size.x, screen_size.y, 0.5), gs.Vector3(screen_size.x, 0, 0.5)]
			uvs = [gs.Vector2(0, 1), gs.Vector2(0, 0), gs.Vector2(1, 0), gs.Vector2(0, 1), gs.Vector2(1, 0),
				   gs.Vector2(1, 1)]
		render_system = render.get_render_system()
		gpu.SetShader(shader)
		gs.SetShaderEngineValues(render_system)
		gpu.SetShaderTexture("y_tex", y_tex)
		gpu.SetShaderTexture("u_tex", u_tex)
		gpu.SetShaderTexture("v_tex", v_tex)
		render_system.DrawTriangleUV(2, vtxs, uvs)
		render.flip()
    def init(cls):

        #-------- Environnement:
        cls.couleur_horizon=gs.Color(10./255.,1./255.,5./255.,1.)
        cls.couleur_zenith=gs.Color(70./255.,150./255.,255./255.,1.)
        cls.couleur_ambiante=gs.Color(70./255.,150./255.,255./255.,1.)
        #cls.couleur_ambiante=gs.Color(1,0,0,1)

        #-------- Création de la scène:
        cls.scene3d=scene.new_scene()

        cls.contexte=gs.SceneLoadContext(render.get_render_system())
        #cls.scene3d.Load("scene_terrain_marching/Terrain_Marching.scn",cls.contexte)
        cls.scene3d.Load("scene_01/Gare_test.scn",cls.contexte)
        #----------- Attend que la scène soit accessible:
        scene.update_scene(cls.scene3d,1/60)

        #----------- Prise en main de la scène:
        cls.noeuds=cls.contexte.GetNodes()
        cls.components=cls.scene3d.GetComponents()

        for comp in cls.components:
            if comp.GetAspect()=="Environment":
                cls.environnement=comp
                break

        #----------- Init billboards et shaders:

        cls.init_billboards(cls.noeuds,cls.liste_sprites_scene)
        cls.init_shaders(cls.noeuds)

        #----------- Init environnement:

        cls.environnement.SetBackgroundColor(gs.Color(0.,0.,0.,0))
        cls.environnement.SetFogColor(cls.couleur_zenith)
        cls.environnement.SetFogNear(10)
        cls.environnement.SetFogFar(6000)
        cls.environnement.SetAmbientIntensity(.1)
        cls.environnement.SetAmbientColor(cls.couleur_ambiante)

        cls.camera=cls.scene3d.GetNode("Camera")
        cls.camera.GetCamera().SetZNear(.1)
        cls.camera.GetCamera().SetZFar(10000.)
        cls.camera_start_pos_mem=cls.camera.GetTransform().GetPosition()
        #cls.camera.AddComponent(gs.Target())   #Si la caméra suit une cible

        cls.lumiere_ciel=cls.scene3d.GetNode("clair obscur")
        cls.lumiere_soleil=cls.scene3d.GetNode("soleil")
        cls.lumiere_ciel.GetLight().SetDiffuseColor(gs.Color(77./255.,158./255.,255./255.,1.))
        cls.lumiere_ciel.GetLight().SetDiffuseIntensity(0.2)
        cls.lumiere_soleil.GetLight().SetDiffuseColor(gs.Color(255./255.,250./255.,223./255.,1.))

        cls.lumiere_soleil.GetLight().SetShadow(gs.Light.Shadow_Map)    #Active les ombres portées
        cls.lumiere_soleil.GetLight().SetShadowRange(100)

        cls.lumiere_soleil.GetLight().SetDiffuseIntensity(1.)
        cls.lumiere_soleil.GetLight().SetSpecularIntensity(1.)

        orientation=gs.Vector3(54/180*pi,135/180*pi,0)
        cls.lumiere_ciel.GetTransform().SetRotation(orientation)

        orientation=gs.Vector3(54/180*pi,-45/180*pi,0)
        cls.lumiere_soleil.GetTransform().SetRotation(orientation)

        #cls.lumiere_ciel.GetLight().SetDiffuseIntensity(2.)
        #cls.lumiere_ciel.GetLight().SetSpecularIntensity(2.)



        #-------- Mémorise les intensités lumineuses pour le switch des éclairages:
        noeuds=cls.scene3d.GetNodes()
        for noeud in noeuds:
            if not noeud.GetLight()==None:
                cls.lumieres_intens_mem.append(noeud.GetLight().GetDiffuseIntensity())
                cls.lumieres_intens_mem.append(noeud.GetLight().GetSpecularIntensity())

        #--------Init les variables de shaders:

        #Couleur d'ambiance:
        """
        for noeud in cls.noeuds:
            if not noeud.GetObject()==None:
                obj=noeud.GetObject()
                geo=obj.GetGeometry()
                n=geo.GetMaterialCount()
                i=0
                while i<n:
                    materiau=geo.GetMaterial(i)
                    materiau.SetFloat3("ambient_color",cls.couleur_ambiante.r*0.,cls.couleur_ambiante.g*0.,cls.couleur_ambiante.b*0.)
                    i+=1
        """
        #--------- Init listes des sprites:
        #cls.liste_sprites_scene.append(...)


        #--------- Inits de l'éditeur embarqué
        cls.cube_l_soleil=scene.add_cube(cls.scene3d,gs.Matrix4.Identity,0.5,0.5,2.)
        cls.cube_l_ciel=scene.add_cube(cls.scene3d,gs.Matrix4.Identity,0.5,0.5,2.)

        cls.scene3d.SetCurrentCamera(cls.camera)

        scene.update_scene(cls.scene3d,1/60)

        #------------- Filtres:
        Demo.pr_alpha_rendu=1.
        Demo.pr_alpha_aura=0.
        Demo.pr_taille_aura=50
        Demo.pr_aura_contraste=2
        Demo.pr_aura_seuil_contraste=0.6

        #-------------- Init le shader de rendu de terrain:
        cls.shader_terrain=Demo.rendu.LoadShader("shaders_marching/terrain_marching_montagnes.isl")
        cls.texture_terrain1=Demo.rendu.LoadTexture("textures/bruit_1024.png")
        cls.texture_terrain2=Demo.rendu.LoadTexture("textures/bruit_512.png")
        cls.texture_terrain3=Demo.rendu.LoadTexture("textures/bruit_512.png")

        cls.facteur_echelle_terrain_l1 = gs.Vector2(20000,20000)
        cls.facteur_echelle_terrain_l2 = gs.Vector2(1000,1000)
        cls.facteur_echelle_terrain_l3 = gs.Vector2(90,90)

        cls.amplitude_l1=1000
        cls.amplitude_l2=37
        cls.amplitude_l3=4
        cls.terrain_intensite_ambiante=0.2

        cls.facteur_precision_distance=1.01
        cls.couleur_neige=gs.Color(0.91,0.91,1)
        cls.couleur_eau=gs.Color(117./255.,219./255.,211./255.)
        cls.altitude_eau=15
    def init(cls):

        #-------- Environnement:
        cls.couleur_horizon = gs.Color(10. / 255., 1. / 255., 5. / 255., 1.)
        cls.couleur_zenith = gs.Color(70. / 255., 150. / 255., 255. / 255., 1.)
        cls.couleur_ambiante = gs.Color(70. / 255., 150. / 255., 255. / 255.,
                                        1.)
        #cls.couleur_ambiante=gs.Color(1,0,0,1)

        #-------- Création de la scène:
        cls.scene3d = scene.new_scene()

        cls.contexte = gs.SceneLoadContext(render.get_render_system())
        #cls.scene3d.Load("scene_terrain_marching/Terrain_Marching.scn",cls.contexte)
        cls.scene3d.Load("scene_01/Gare_test.scn", cls.contexte)
        #----------- Attend que la scène soit accessible:
        scene.update_scene(cls.scene3d, 1 / 60)

        #----------- Prise en main de la scène:
        cls.noeuds = cls.contexte.GetNodes()
        cls.components = cls.scene3d.GetComponents()

        for comp in cls.components:
            if comp.GetAspect() == "Environment":
                cls.environnement = comp
                break

        #----------- Init billboards et shaders:

        cls.init_billboards(cls.noeuds, cls.liste_sprites_scene)
        cls.init_shaders(cls.noeuds)

        #----------- Init environnement:

        cls.environnement.SetBackgroundColor(gs.Color(0., 0., 0., 0))
        cls.environnement.SetFogColor(cls.couleur_zenith)
        cls.environnement.SetFogNear(10)
        cls.environnement.SetFogFar(6000)
        cls.environnement.SetAmbientIntensity(.1)
        cls.environnement.SetAmbientColor(cls.couleur_ambiante)

        cls.camera = cls.scene3d.GetNode("Camera")
        cls.camera.GetCamera().SetZNear(.1)
        cls.camera.GetCamera().SetZFar(10000.)
        cls.camera_start_pos_mem = cls.camera.GetTransform().GetPosition()
        #cls.camera.AddComponent(gs.Target())   #Si la caméra suit une cible

        cls.lumiere_ciel = cls.scene3d.GetNode("clair obscur")
        cls.lumiere_soleil = cls.scene3d.GetNode("soleil")
        cls.lumiere_ciel.GetLight().SetDiffuseColor(
            gs.Color(77. / 255., 158. / 255., 255. / 255., 1.))
        cls.lumiere_ciel.GetLight().SetDiffuseIntensity(0.2)
        cls.lumiere_soleil.GetLight().SetDiffuseColor(
            gs.Color(255. / 255., 250. / 255., 223. / 255., 1.))

        cls.lumiere_soleil.GetLight().SetShadow(
            gs.Light.Shadow_Map)  #Active les ombres portées
        cls.lumiere_soleil.GetLight().SetShadowRange(100)

        cls.lumiere_soleil.GetLight().SetDiffuseIntensity(1.)
        cls.lumiere_soleil.GetLight().SetSpecularIntensity(1.)

        orientation = gs.Vector3(54 / 180 * pi, 135 / 180 * pi, 0)
        cls.lumiere_ciel.GetTransform().SetRotation(orientation)

        orientation = gs.Vector3(54 / 180 * pi, -45 / 180 * pi, 0)
        cls.lumiere_soleil.GetTransform().SetRotation(orientation)

        #cls.lumiere_ciel.GetLight().SetDiffuseIntensity(2.)
        #cls.lumiere_ciel.GetLight().SetSpecularIntensity(2.)

        #-------- Mémorise les intensités lumineuses pour le switch des éclairages:
        noeuds = cls.scene3d.GetNodes()
        for noeud in noeuds:
            if not noeud.GetLight() == None:
                cls.lumieres_intens_mem.append(
                    noeud.GetLight().GetDiffuseIntensity())
                cls.lumieres_intens_mem.append(
                    noeud.GetLight().GetSpecularIntensity())

        #--------Init les variables de shaders:

        #Couleur d'ambiance:
        """
        for noeud in cls.noeuds:
            if not noeud.GetObject()==None:
                obj=noeud.GetObject()
                geo=obj.GetGeometry()
                n=geo.GetMaterialCount()
                i=0
                while i<n:
                    materiau=geo.GetMaterial(i)
                    materiau.SetFloat3("ambient_color",cls.couleur_ambiante.r*0.,cls.couleur_ambiante.g*0.,cls.couleur_ambiante.b*0.)
                    i+=1
        """
        #--------- Init listes des sprites:
        #cls.liste_sprites_scene.append(...)

        #--------- Inits de l'éditeur embarqué
        cls.cube_l_soleil = scene.add_cube(cls.scene3d, gs.Matrix4.Identity,
                                           0.5, 0.5, 2.)
        cls.cube_l_ciel = scene.add_cube(cls.scene3d, gs.Matrix4.Identity, 0.5,
                                         0.5, 2.)

        cls.scene3d.SetCurrentCamera(cls.camera)

        scene.update_scene(cls.scene3d, 1 / 60)

        #------------- Filtres:
        Demo.pr_alpha_rendu = 1.
        Demo.pr_alpha_aura = 0.
        Demo.pr_taille_aura = 50
        Demo.pr_aura_contraste = 2
        Demo.pr_aura_seuil_contraste = 0.6

        #-------------- Init le shader de rendu de terrain:
        cls.shader_terrain = Demo.rendu.LoadShader(
            "shaders_marching/terrain_marching_montagnes.isl")
        cls.texture_terrain1 = Demo.rendu.LoadTexture(
            "textures/bruit_1024.png")
        cls.texture_terrain2 = Demo.rendu.LoadTexture("textures/bruit_512.png")
        cls.texture_terrain3 = Demo.rendu.LoadTexture("textures/bruit_512.png")

        cls.facteur_echelle_terrain_l1 = gs.Vector2(20000, 20000)
        cls.facteur_echelle_terrain_l2 = gs.Vector2(1000, 1000)
        cls.facteur_echelle_terrain_l3 = gs.Vector2(90, 90)

        cls.amplitude_l1 = 1000
        cls.amplitude_l2 = 37
        cls.amplitude_l3 = 4
        cls.terrain_intensite_ambiante = 0.2

        cls.facteur_precision_distance = 1.01
        cls.couleur_neige = gs.Color(0.91, 0.91, 1)
        cls.couleur_eau = gs.Color(117. / 255., 219. / 255., 211. / 255.)
        cls.altitude_eau = 15
def setup():
	global scn, title_music
	scn = scene.new_scene()
	scn.Load('@assets/3d/level_title.scn', gs.SceneLoadContext(render.get_render_system()))
	title_music = audio.get_mixer().Stream("@assets/sfx/sfx_cellos_loop.ogg")