Example #1
0
def draw_circle(scene_simple_graphic, world, r, color):
	step = 50
	prev = gs.Vector3(math.cos(0) * r, 0, math.sin(0) * r) * world
	for i in range(step+1):
		val = gs.Vector3(math.cos(math.pi*2*float(i)/step) * r, 0, math.sin(math.pi*2*float(i)/step) * r) * world

		scene_simple_graphic.Line(prev.x, prev.y, prev.z, val.x, val.y, val.z, color, color)
		prev = val
Example #2
0
def deserialize_matrix(s):
    f = s.split(";")
    m = gs.Matrix4()
    m.SetRow(0, gs.Vector3(float(f[0]), float(f[1]), float(f[2])))
    m.SetRow(1, gs.Vector3(float(f[3]), float(f[4]), float(f[5])))
    m.SetRow(2, gs.Vector3(float(f[6]), float(f[7]), float(f[8])))
    m.SetRow(3, gs.Vector3(float(f[9]), float(f[10]), float(f[11])))
    return m
Example #3
0
 def affiche_geometrie(self, x, y, z, ex, ey, axe_x, axe_y, axe_z, teinte):
     pos = gs.Vector3(x, y, z)
     rot = gs.Matrix3(axe_x, axe_y, axe_z)
     mat = gs.Matrix4.TransformationMatrix(pos, rot)
     mat.SetScale(gs.Vector3(ex, ey, 1))
     materiau = self.geometrie.GetMaterial(0)
     materiau.SetFloat4("teinte", teinte.r, teinte.g, teinte.b, teinte.a)
     Demo.rendu_scene.DrawGeometry(self.geometrie, mat)
def setup_scenario_1():
	# walls
	scene.add_physic_cube(scn, mat=gs.Matrix4.TransformationMatrix(gs.Vector3(tile_quantizer(md_screen_w * -0.1), tile_quantizer(md_screen_h * 0.25), 0),gs.Vector3(0,0, pi * 0.25)),
						  width=sphere_radius * 2.0, height=sphere_radius * 12.0, depth=sphere_radius, mass=0.0)

	scene.add_physic_cube(scn, mat=gs.Matrix4.TransformationMatrix(gs.Vector3(tile_quantizer(md_screen_w * 0.1), tile_quantizer(md_screen_h * -0.15), 0),gs.Vector3(0,0, pi * -0.25)),
						  width=sphere_radius * 2.0, height=sphere_radius * 12.0, depth=sphere_radius, mass=0.0)

	scene.add_physic_cube(scn, mat=gs.Matrix4.TransformationMatrix(gs.Vector3(tile_quantizer(md_screen_w * -0.1), tile_quantizer(md_screen_h * -0.5), 0),gs.Vector3(0,0, pi * 0.25)),
						  width=sphere_radius * 2.0, height=sphere_radius * 12.0, depth=sphere_radius, mass=0.0)
Example #5
0
 def affiche_geometrie(self):
     #SpriteFrame.affiche_geometrie(self,self.x,self.y,self.z,self.ex,self.ey,self.axe_x,self.axe_y,self.axe_z,self.teinte)
     #Version optimisée:
     pos = gs.Vector3(self.x, self.y, self.z)
     mat = gs.Matrix4.TransformationMatrix(pos, self.rotation)
     mat.SetScale(gs.Vector3(self.ex, self.ey, 1))
     materiau = self.geometrie.GetMaterial(0)
     materiau.SetFloat4("teinte", self.teinte.r, self.teinte.g,
                        self.teinte.b, self.teinte.a)
     Demo.rendu_scene.DrawGeometry(self.geometrie, mat)
Example #6
0
 def affiche_geometrie_inverse_X(self, x, y, z, ex, ey, axe_x, axe_y, axe_z,
                                 teinte):
     pos = gs.Vector3(x, y, z)
     #axe_x_inverse=MathsSupp.rotation_vecteur(axe_x,axe_y,pi*2)
     rot = gs.Matrix3(gs.Vector3(-axe_x.x, -axe_x.y, -axe_x.z), axe_y,
                      gs.Vector3(-axe_z.x, -axe_z.y, -axe_z.z))
     mat = gs.Matrix4.TransformationMatrix(pos, rot)
     mat.SetScale(gs.Vector3(ex, ey, 1))
     materiau = self.geometrie.GetMaterial(0)
     materiau.SetFloat4("teinte", teinte.r, teinte.g, teinte.b, teinte.a)
     Demo.rendu_scene.DrawGeometry(self.geometrie, mat)
Example #7
0
	def __init__(self):
		self.tgt = gs.Vector3()
		self.rot = gs.Matrix3()
		self.d = 10

		self.rot_speed = 1.0
		self.k_wheel = 40
Example #8
0
	def update_keyboard(self, cam, dt):
		keyboard_device = gs.GetKeyboard()

		# fps move speed
		speed = dt * 3 * self.speed
		if keyboard_device.IsDown(gs.InputDevice.KeyLShift):
			speed *= 6

		# fps move
		local_dt = gs.Vector3()
		if keyboard_device.IsDown(self.fps_move_forward):
			local_dt += gs.Vector3.Front
		if keyboard_device.IsDown(self.fps_move_back):
			local_dt += gs.Vector3.Back
		if keyboard_device.IsDown(self.fps_move_right):
			local_dt += gs.Vector3.Right
		if keyboard_device.IsDown(self.fps_move_left):
			local_dt += gs.Vector3.Left
		if keyboard_device.IsDown(self.fps_move_up):
			local_dt += gs.Vector3.Up
		if keyboard_device.IsDown(self.fps_move_down):
			local_dt += gs.Vector3.Down

		if local_dt == gs.Vector3.Zero:
			return False

		self.pos += cam.GetTransform().GetWorld().Rotate(local_dt.Normalized() * speed)
		return True
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
Example #10
0
 def calcul_point_plan_projection(cls, cx, cy, cz, spx, spy, axe_x, axe_y):
     """
     Projette un point du plan du sprite dans l'espace
     :param cx: position spatiale de l'origine du plan du sprite
     :param cy:
     :param cz:
     :param spx: Position dans le plan du sprite
     :param spy:
     :param axe_x: Plan du sprite
     :param axe_y:
     :return: gs.Vector3 - la position du point dans l'espace
     """
     projX = gs.Vector3(spx * axe_x.x, spx * axe_x.y, spx * axe_x.z)
     projY = gs.Vector3(spy * axe_y.x, spy * axe_y.y, spy * axe_y.z)
     point = gs.Vector3(projX + projY) + gs.Vector3(cx, cy, cz)
     return point
Example #11
0
    def rotation_vecteur(cls, point, axe, angle):

        prod_scal = point.x * axe.x + point.y * axe.y + point.z * axe.z
        cos_angle = cos(angle)
        sin_angle = sin(angle)

        return gs.Vector3(cos_angle * point.x + sin_angle * (axe.y * point.z - axe.z * point.y) + (1 - cos_angle) * prod_scal * axe.x,\
                        cos_angle * point.y + sin_angle * (axe.z * point.x - axe.x * point.z) + (1 - cos_angle) * prod_scal * axe.y,\
                        cos_angle * point.z + sin_angle * (axe.x * point.y - axe.y * point.x) + (1 - cos_angle) * prod_scal * axe.z)
Example #12
0
def reset_view(scn, cam, cam_handler, use_vr):
	cam_world = None

	# move the camera to see the fbx entirely
	spawnpoint = scn.GetNode("spawnpoint_0")
	if spawnpoint is not None:
		cam_world = spawnpoint.GetTransform().GetWorld()
		print("Find spawnpoint_0")
	else:
		print("can't find sppawnpoint_0")

	if cam_world is None:
		# move the camera to see the fbx entirely
		min_max = gs.MinMax()
		for n in scn.GetNodes():
			if n.GetObject() is not None:
				min_max.Grow(n.GetObject().GetLocalMinMax().Transformed(n.GetTransform().GetWorld()))

		d = min_max.mx.x - min_max.mn.x
		d = max(d, min_max.mx.y - min_max.mn.y)
		d = max(d, min_max.mx.z - min_max.mn.z)
		d = max(0.2, d) * 2
		cam_pos = gs.Vector3(-1, -1, 1).Normalized() * -d

		cam_world = gs.Matrix4.TransformationMatrix(cam_pos, gs.Matrix3.LookAt(cam_pos * -1),
		                                            gs.Vector3.One)

		# in case of vr, no rotation
		if use_vr:
			cam_world = gs.Matrix4.TranslationMatrix(cam_pos * -1)
			d = 1

	else:
		# in case of no vr, up the camera to 1.75
		if not use_vr:
			cam_world = cam_world * gs.Matrix4.TranslationMatrix(gs.Vector3(0, 1.75, 0))
			print("no vr: camera up to 1.75m")

		d = 1

	if not use_vr:
		cam_handler.reset(cam_world, d, cam)
	else:
		cam.GetTransform().SetWorld(cam_world)
def setup_scenario_2():
	# walls
	# scene.add_physic_cube(scn, mat=gs.Matrix4.TransformationMatrix(gs.Vector3(tile_quantizer(md_screen_h * -0.2), -md_screen_h * 0.5,0),gs.Vector3(0,0,0)),
	# 					  width=sphere_radius * 2.0, height=sphere_radius * 12.0, depth=sphere_radius, mass=0.0)
	# scene.add_physic_cube(scn, mat=gs.Matrix4.TransformationMatrix(gs.Vector3(tile_quantizer(md_screen_h * 0.2), -md_screen_h * 0.5,0),gs.Vector3(0,0,0)),
	# 					  width=sphere_radius * 2.0, height=sphere_radius * 12.0, depth=sphere_radius, mass=0.0)

	scene.add_physic_cube(scn, mat=gs.Matrix4.TransformationMatrix(gs.Vector3(tile_quantizer(md_screen_h * -0.4), -md_screen_h * 0.5,0),gs.Vector3(0,0,0)),
						  width=sphere_radius * 2.0, height=sphere_radius * 8, depth=sphere_radius, mass=0.0)
	scene.add_physic_cube(scn, mat=gs.Matrix4.TransformationMatrix(gs.Vector3(tile_quantizer(md_screen_h * 0.4), -md_screen_h * 0.5,0),gs.Vector3(0,0,0)),
						  width=sphere_radius * 2.0, height=sphere_radius * 8, depth=sphere_radius, mass=0.0)

	scene.add_physic_sphere(scn, mat=gs.Matrix4.TransformationMatrix(gs.Vector3(0,-md_screen_h * 0.25,0),gs.Vector3(0,0,0)),
	 					  radius=sphere_radius * 4.0, mass=0.0)

	scene.add_physic_cube(scn, mat=gs.Matrix4.TransformationMatrix(gs.Vector3(tile_quantizer(md_screen_w * -0.48), -md_screen_h * 0.5,0),gs.Vector3(0,0,0)),
						  width=sphere_radius * 2.0, height=sphere_radius * 16.0, depth=sphere_radius, mass=0.0)
	scene.add_physic_cube(scn, mat=gs.Matrix4.TransformationMatrix(gs.Vector3(tile_quantizer(md_screen_w * 0.48), -md_screen_h * 0.5,0),gs.Vector3(0,0,0)),
						  width=sphere_radius * 2.0, height=sphere_radius * 16.0, depth=sphere_radius, mass=0.0)
Example #14
0
 def tri_sprites(cls, liste, camera):
     if len(liste) > 0:
         camPos = camera.GetTransform().GetWorld().GetTranslation()
         for sprite in liste:
             sprPos = camPos - gs.Vector3(sprite.x, sprite.y, sprite.z)
             sprite.distance_camera = sprPos.Len()
         return sorted(liste,
                       key=attrgetter("distance_camera"),
                       reverse=True)
     else:
         return liste
Example #15
0
def draw_spline(scene_simple_graphic, p1, p2, p3, p4, color):
	P = [(p1.x, p1.y, p1.z), (p2.x, p2.y, p2.z), (p3.x, p3.y, p3.z), (p4.x, p4.y, p4.z)]

	C = bspline.C_factory(P, 3, "clamped")
	if C:
		step = 50
		prev_value = [p1.x, p1.y, p1.z]
		val = gs.Vector3()
		for i in range(step):
			val = C(float(i)/step * C.max)
			scene_simple_graphic.Line(prev_value[0], prev_value[1], prev_value[2], val[0], val[1], val[2], color, color)
			prev_value = val
Example #16
0
	def __init__(self):
		self.pos = gs.Vector3()
		self.rot = gs.Matrix3()

		self.fps_move_forward = gs.InputDevice.KeyZ
		self.fps_move_back = gs.InputDevice.KeyS
		self.fps_move_left = gs.InputDevice.KeyQ
		self.fps_move_right = gs.InputDevice.KeyD
		self.fps_move_up = gs.InputDevice.KeyE
		self.fps_move_down = gs.InputDevice.KeyA

		self.speed = 1.0
		self.rot_speed = 1.0
def throw_bullet(size=1.0, mass=1.0, type='sphere', spread_angle=1.0, spread_pos=1.0):
	world = gs.Matrix4.TransformationMatrix(make_solid_pos(uniform(md_screen_w * -0.01 * size * spread_pos, md_screen_w * 0.01 * size * spread_pos), md_screen_h / 2 + (sphere_radius * size)), gs.Vector3())
	if type.find('sphere') > -1:
		new_bullet, rigid_body = scene.add_physic_sphere(scn, world, sphere_radius * size, mass=mass)
	elif type.find('cube') > -1:
		new_bullet, rigid_body = scene.add_physic_cube(scn, world, sphere_radius * size * 1.6, sphere_radius * size * 1.6, sphere_radius * size * 1.6, mass=mass)

	if type.find('elastic') > -1:
		rigid_body.SetRestitution(1.15)

	ejection_vector = world.GetY() + gs.Vector3(uniform(-1.0, 1.0), uniform(0.0, 1.0), 0.0) * spread_angle
	rigid_body.ApplyLinearImpulse(ejection_vector * (-50 / scale_factor))
	new_bullet.SetName('type;' + type + ';size;' + str(int(size)) + ';mass;' + str(int(mass)))
Example #18
0
def draw_fps(scn, gui, scene_simple_graphic, use_vr, dt_sec):
    fps_text = "FPS:{0}".format(int(1 / dt_sec.to_sec()))
    if use_vr:
        head_controller = gs.GetInputSystem().GetDevice("openvr_hmd")
        if head_controller is not None and scn.GetCurrentCamera() is not None:
            text_mat = head_controller.GetMatrix(
                gs.InputDevice.MatrixHead) * gs.Matrix4.TranslationMatrix(
                    gs.Vector3(-0.1, -0.1, 0.5))
            text_pos = text_mat.GetTranslation() + scn.GetCurrentCamera(
            ).GetTransform().GetPosition()
            scene_simple_graphic.SetDepthTest(False)
            scene_simple_graphic.SetBlendMode(gs.BlendAlpha)
            scene_simple_graphic.Text(text_pos.x, text_pos.y, text_pos.z,
                                      fps_text, gs.Color.Green, font, 0.001)

    gui.Text(fps_text)
Example #19
0
def create_new_scene():
    global scn, sky_script, scene_simple_graphic, cam, openvr_frame_renderer

    if scn is None:
        scn = plus.NewScene()

        # check if we use VR
        openvr_frame_renderer = gs.GetFrameRenderer("OpenVR")
        if openvr_frame_renderer is not None and openvr_frame_renderer.Initialize(
                plus.GetRenderSystem()):
            scn.GetSystem("Renderable").SetFrameRenderer(openvr_frame_renderer)
        else:
            openvr_frame_renderer = None
        # openvr_frame_renderer = None
    else:
        scn.Dispose()

        # purge cache
        plus.GetRenderSystemAsync().PurgeCache()
        plus.GetRendererAsync().PurgeCache()

        plus.UpdateScene(scn, gs.time(1.0 / 60))
        plus.UpdateScene(scn, gs.time(1.0 / 60))
        plus.UpdateScene(scn, gs.time(1.0 / 60))

    # scn.GetPhysicSystem().SetDebugVisuals(True)

    vr_controller.clear_controllers(scn)

    # add sky
    if show_sky:
        sky_script = gs.LogicScript("@core/lua/sky_lighting.lua")
        sky_script.Set("time_of_day", 15.0)
        sky_script.Set("attenuation", 0.75)
        sky_script.Set("shadow_range", 1000.0)  # 1km shadow range
        sky_script.Set("shadow_split", gs.Vector4(0.1, 0.2, 0.3, 0.4))
        scn.AddComponent(sky_script)
    else:
        sky_script = None

    # add simple graphic, to draw 3D line
    scene_simple_graphic = gs.SimpleGraphicSceneOverlay(False)
    scn.AddComponent(scene_simple_graphic)

    cam = plus.AddCamera(scn,
                         gs.Matrix4.TranslationMatrix(gs.Vector3(0, 1, -10)))
Example #20
0
	def set_state_from_target(self, tgt, dir, d):
		self.tgt, self.rot, self.d = gs.Vector3(tgt), gs.Matrix3.LookAt(dir), d
Example #21
0
def update_camera_teleporter(scn, scene_simple_graphic, cam, use_vr, authorise_ground_node):
	controller0 = gs.GetInputSystem().GetDevice("openvr_controller_0")
	pos_start = None
	dir_teleporter = None
	teleporter_activate = False

	if use_vr is not None and controller0 is not None:
		if controller0.GetValue(gs.InputDevice.InputButton0) != 0 or controller0.GetValue(gs.InputDevice.InputButton1) != 0:
			pos_cam = cam.GetTransform().GetPosition()
			mat_controller = controller0.GetMatrix(gs.InputDevice.MatrixHead)
			dir_teleporter = mat_controller.GetZ()
			pos_start = mat_controller.GetTranslation() + pos_cam

			teleporter_activate = controller0.WasButtonPressed(gs.InputDevice.Button0)
	else:
		if plus.KeyDown(gs.InputDevice.KeyX) or plus.KeyDown(gs.InputDevice.KeyC):
			pos_start = cam.GetTransform().GetPosition()
			dir_teleporter = cam.GetTransform().GetWorld().GetZ()

	if pos_start is not None:
		if pos_start.y < 0:
			return

		# teleporter
		# project point on the ground
		cos_angle = dir_teleporter.Dot(gs.Vector3(dir_teleporter.x, 0, dir_teleporter.z).Normalized())
		cos_angle = min(1.0, max(cos_angle, -1))
		angle = math.acos(cos_angle)
		if dir_teleporter.y < 0:
			angle = -angle

			velocity = 5
			d = ((velocity * cos_angle) / 9.81) * (velocity * math.sin(angle) + math.sqrt((velocity * math.sin(angle)) ** 2 + 2 * 9.81 * pos_start.y))

		else:
			velocity = 5
			min_d = ((velocity * 1) / 9.81) * (velocity * math.sin(0) + math.sqrt((velocity * math.sin(0)) ** 2 + 2 * 9.81 * pos_start.y))
			max_d = 10
			d = min_d + (1.0 - abs(cos_angle)) * max_d

		ground_pos = gs.Vector3(pos_start.x, 0, pos_start.z) + gs.Vector3(dir_teleporter.x, 0, dir_teleporter.z).Normalized() *d

		authorise_movement = True
		if authorise_ground_node is not None:
			authorise_ground_node.GetObject().GetGeometry().GetMaterial(0).SetFloat3("pos_touched", ground_pos.x, ground_pos.y, ground_pos.z)
			hit, trace = scn.GetPhysicSystem().Raycast(ground_pos + gs.Vector3(0, 0.5, 0), gs.Vector3(0, -1, 0), 4, 3)
			if not hit or trace.GetNode() != authorise_ground_node:
				authorise_movement = False

		strength_force = math.pow((math.sin(angle) + 1) / 2, 2) * 2

		color = gs.Color(0, 1, 198/255) if authorise_movement else gs.Color(1, 18/255, 0)
		helper_2d.draw_spline(scene_simple_graphic, pos_start, pos_start + dir_teleporter * strength_force, ground_pos + gs.Vector3(0, strength_force, 0), ground_pos, color)

		if authorise_ground_node is None:
			helper_2d.draw_circle(scene_simple_graphic, gs.Matrix4.TranslationMatrix(ground_pos), 1, color)

		if authorise_movement and teleporter_activate:
			if use_vr:
				head_controller = gs.GetInputSystem().GetDevice("openvr_hmd")
				head_pos = head_controller.GetMatrix(gs.InputDevice.MatrixHead).GetTranslation()
				head_pos.y = 0
				ground_pos = ground_pos - head_pos
			cam.GetTransform().SetWorld(gs.Matrix4.TranslationMatrix(ground_pos))
	else:
		if authorise_ground_node is not None:
			authorise_ground_node.GetObject().GetGeometry().GetMaterial(0).SetFloat3("pos_touched", 99999, 99999, 99999)
Example #22
0
	def apply_state(self, camera):
		world = gs.Matrix4.TransformationMatrix(self.tgt, self.rot, gs.Vector3.One) * gs.Matrix4.TranslationMatrix(gs.Vector3(0, 0, -self.d))
		camera.GetTransform().SetWorld(world)
		return world
Example #23
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)
Example #24
0
 def convert_to_max(pos):
     return gs.Vector3(pos.x, pos.z, pos.y)
def make_solid_pos(x,y):
	return gs.Vector3(x, y, 0.0)
Example #26
0
def render_mask_screen():
    mask_segment_list = wireframe_json_to_segment_list(
        "@assets/exxos_mask.json")

    scn = scene.new_scene()

    while not scn.IsReady():
        scene.update_scene(scn, 0.0)

    # Add an environment to the scene
    env = gs.Environment()
    env.SetBackgroundColor(gs.Color.Black)
    scn.AddComponent(env)

    # Add a camera
    render_camera = gs.Node()
    render_camera.AddComponent(gs.Transform())
    render_camera.AddComponent(gs.Camera())
    scn.AddNode(render_camera)
    scn.SetCurrentCamera(render_camera)
    render_camera.GetTransform().SetPosition(gs.Vector3(0, 0, -50))

    # Create a (parent) node to rotate the mask
    master_node = gs.Node()
    master_node.AddComponent(gs.Transform())
    scn.AddNode(master_node)

    # Init the starfield
    starfield.init_stars()
    starfield.set_camera_velocity(gs.Vector3(0, 0, -50))

    segment_nodes_list = []
    for seg in mask_segment_list:
        node_a, node_b = gs.Node(), gs.Node()
        tr_a, tr_b = gs.Transform(), gs.Transform()
        tr_a.SetPosition(gs.Vector3(seg[0][0], seg[0][1], seg[0][2]))
        tr_b.SetPosition(gs.Vector3(seg[1][0], seg[1][1], seg[1][2]))
        tr_a.SetParent(master_node)
        tr_b.SetParent(master_node)
        node_a.AddComponent(tr_a)
        node_b.AddComponent(tr_b)
        scn.AddNode(node_a)
        scn.AddNode(node_b)
        segment_nodes_list.append([node_a, node_b])

    seq_duration = 20.0
    fx_timer = 0.0
    while fx_timer < seq_duration:

        render.clear()
        dt_sec = clock.update()

        master_node.GetTransform().SetRotation(
            master_node.GetTransform().GetRotation() +
            gs.Vector3(1, 1, 1) * dt_sec * 0.25)
        scene.update_scene(scn, dt_sec)

        # render.commit_3d()
        # render.set_depth_write3d(False)

        starfield.update_stars(dt_sec)
        starfield.draw_stars(render)

        for seg in segment_nodes_list:
            pos_a = seg[0].GetTransform().GetWorld().GetTranslation()
            pos_b = seg[1].GetTransform().GetWorld().GetTranslation()
            render.line3d(pos_a.x,
                          pos_a.y,
                          pos_a.z,
                          pos_b.x,
                          pos_b.y,
                          pos_b.z,
                          start_color=gs.Color.Blue,
                          end_color=gs.Color.Blue)

        render.flip()

        fx_timer += dt_sec
def make_solid_pos(x, y):
    return gs.Vector3(x * 1.15, y + height * 0.5, cos(x * y + x) * 0.15)
import gs.plus.scene as scene
import gs.plus.clock as clock
from math import pi, cos, sin, asin
import codecs

filename_out = "../src/simulation"
scale_factor = 5.0

gs.plus.create_workers()
gs.LoadPlugins(gs.get_default_plugins_path())

render.init(1280, 720, "../pkg.core")

scn = scene.new_scene()
cam = scene.add_camera(scn,
                       gs.Matrix4.TranslationMatrix(gs.Vector3(0, 3.5, -12.5)))
cam.GetTransform().SetRotation(
    gs.Vector3(pi * 5.0 / 180.0, pi * -5.0 / 180.0, 0))

scene.add_light(scn, gs.Matrix4.RotationMatrix(gs.Vector3(0.65, -0.45, 0)),
                gs.Light.Model_Linear, 150)
scene.add_light(scn,
                gs.Matrix4.RotationMatrix(gs.Vector3(0.55, pi, 0.2)),
                gs.Light.Model_Linear,
                diffuse=gs.Color(0.3, 0.3, 0.4))
scene.add_physic_plane(scn)

# nodes = add_kapla_tower(scn, 0.5, 2, 2, 6, 16)

width, height, length = 1, 1, 1
## Starfield 3D

import gs
import random

max_stars = 0
stars = []
starfield_size = gs.Vector3(50, 50, 500)
camera_velocity = gs.Vector3()
pos_dt = gs.Vector3()


def init_stars(_max_stars=500):
    global stars, max_stars, starfield_size
    max_stars = _max_stars

    def rand_point_within_size():
        global starfield_size
        return gs.Vector3(random.uniform(-starfield_size.x, starfield_size.x),
                          random.uniform(-starfield_size.y, starfield_size.y),
                          random.uniform(-starfield_size.z, starfield_size.z))

    for i in range(max_stars):
        stars.append({'pos': rand_point_within_size(), 'intensity': 1.0})


def set_camera_velocity(vec):
    global camera_velocity, pos_dt
    camera_velocity = vec
    framerate = 60.0
    while framerate > 0 and pos_dt.Len() < 5.0:
 def rand_point_within_size():
     global starfield_size
     return gs.Vector3(random.uniform(-starfield_size.x, starfield_size.x),
                       random.uniform(-starfield_size.y, starfield_size.y),
                       random.uniform(-starfield_size.z, starfield_size.z))