Ejemplo n.º 1
0
def producer():
    print "producer:", gs.time(), "start"
    counter = 0
    while True:
        print "producer:", gs.time(), "counter", counter
        counter += 1
        gs.wait(1)
Ejemplo n.º 2
0
def fork_example_args():
    gs.wait(100)
    print "fork_example_args:", gs.time(), "     start"
    gs.fork([counter]*4,
      args=[("a",9),("bb",5),(),()],
      keyargs=[{},{},dict(name="ccc",last=7),dict(name="dddd",last=15)])
    print "fork_example_args:", gs.time(), "     finish"
Ejemplo n.º 3
0
def producer():
    print "producer:", gs.time(), "start"
    counter = 0
    while True:
        print "producer:", gs.time(), "counter", counter
        counter += 1
        gs.wait(1)
Ejemplo n.º 4
0
def fork_example_args():
    gs.wait(100)
    print "fork_example_args:", gs.time(), "     start"
    gs.fork([counter] * 4,
            args=[("a", 9), ("bb", 5), (), ()],
            keyargs=[{}, {},
                     dict(name="ccc", last=7),
                     dict(name="dddd", last=15)])
    print "fork_example_args:", gs.time(), "     finish"
Ejemplo n.º 5
0
def controler(thread):
    print "controler:", gs.time(), "start"
    print "controler:", gs.time(), "waiting 5 ns to reset thread", thread.name
    gs.wait(5, gs.NS)
    print "controler:", gs.time(), "reseting thread", thread.name, "NOW!"
    thread.reset()
    print "controler:", gs.time(), "waiting 3 ns to kill thread", thread.name
    gs.wait(3)
    print "controler:", gs.time(), "killing thread", thread.name, "NOW!"
    thread.kill()
Ejemplo n.º 6
0
def load_new_scene(filename):
    global current_filename_scn, authorise_ground_node, authorise_ground_geo

    if getattr(sys, 'frozen', False):
        os.chdir(os.path.dirname(sys.executable))
    else:
        os.chdir(os.path.dirname(os.path.realpath(__file__)))

    # create new scene
    create_new_scene()

    if not os.path.exists(filename):
        print("{0} doesn't exist".format(filename))
        return

    # load new scene
    gs.MountFileDriver(gs.StdFileDriver(os.path.dirname(filename)))
    gs.MountFileDriver(gs.StdFileDriver(os.path.dirname(filename)), "export")
    scn.Load(filename, gs.SceneLoadContext(plus.GetRenderSystem()))

    # call twice to be sure it's loaded
    plus.UpdateScene(scn, gs.time(1.0 / 60))
    plus.UpdateScene(scn, gs.time(1.0 / 60))
    plus.UpdateScene(scn, gs.time(1.0 / 60))
    plus.UpdateScene(scn, gs.time(1.0 / 60))

    # find the authorise ground
    authorise_ground_node = scn.GetNode("chaperone_area")
    if authorise_ground_node is not None:
        p = authorise_ground_node.GetTransform().GetPosition()
        p.y += 0.01
        authorise_ground_node.GetTransform().SetPosition(p)
        rb = gs.MakeRigidBody()
        rb.SetCollisionLayer(2)
        authorise_ground_node.AddComponent(rb)
        mesh_col = gs.MakeMeshCollision()
        mesh_col.SetGeometry(
            gs.LoadCoreGeometry(
                authorise_ground_node.GetObject().GetGeometry().GetName()))
        mesh_col.SetMass(0)
        authorise_ground_node.AddComponent(mesh_col)
        authorise_ground_node.GetObject().GetGeometry().SetMaterial(
            0, authorise_ground_mat)
        authorise_ground_node.SetIsStatic(True)

    # move the camera to see the fbx entirely
    camera.reset_view(scn, cam, camera_handler, openvr_frame_renderer)
    current_filename_scn = filename

    scn.SetCurrentCamera(cam)

    # create the list of object to switch
    switch_object.load_switch_object(scn)

    vr_controller.update_controller(scn)
Ejemplo n.º 7
0
def fork_example():
    print "fork_example:", gs.time(), "     start"
    gs.fork( [lambda: counter("a",9),
              lambda: counter("bb",5),
              lambda: counter("ccc",7),
              lambda: counter("dddd",15),
              ],
             wait_for = 2,
             kill = True,
             debug = False)
    print "fork_example:", gs.time(), "     finish"
Ejemplo n.º 8
0
def fork_example():
    print "fork_example:", gs.time(), "     start"
    gs.fork([
        lambda: counter("a", 9),
        lambda: counter("bb", 5),
        lambda: counter("ccc", 7),
        lambda: counter("dddd", 15),
    ],
            wait_for=2,
            kill=True,
            debug=False)
    print "fork_example:", gs.time(), "     finish"
Ejemplo n.º 9
0
def update(scn, openvr_frame_renderer):
    if calibration_matrix is None:
        load_calibration()

    if recording:
        update_recording(scn)
    elif playing or playing_record_frame or do_calibration:
        update_play(scn, openvr_frame_renderer)

    if show_live_cam:
        plus = gs.GetPlus()
        size = plus.GetRendererAsync().GetCurrentOutputWindow().GetSize()

        if openvr_frame_renderer is not None:
            scn.GetSystem("Renderable").SetFrameRenderer(None)

        plus.GetRendererAsync().SetViewport(
            gs.fRect(0, 0, size.x * 0.5, size.y * 0.5))
        plus.GetRendererAsync().SetClippingRect(
            gs.fRect(0, 0, size.x * 0.5, size.y * 0.5))
        plus.GetRendererAsync().Clear(gs.Color.Black)

        scn.GetCurrentCamera().GetTransform().SetWorld(saved_cam_matrix)

        scn.Update(gs.time(0))
        scn.WaitUpdate()
        scn.Commit()
        scn.WaitCommit()

        plus.GetRendererAsync().SetViewport(gs.fRect(0, 0, size.x, size.y))
        plus.GetRendererAsync().SetClippingRect(gs.fRect(0, 0, size.x, size.y))

        if openvr_frame_renderer is not None:
            scn.GetSystem("Renderable").SetFrameRenderer(openvr_frame_renderer)
Ejemplo n.º 10
0
def consumer():

    tests = [ \
"(e1 & e2)",
"((e1 | e2) & e3)",
"(e1 & (e2 | e3))",
"(e0 | e1 & e2 & e3 | e4)",
"((e1 | e2) | (e3 & e4))",
]

    try:  test = tests[int(sys.argv[1])]
    except:  test = tests[1]

    print "consumer", gs.time(), "waiting for", test
    exec "gs.wait" + test
    print "consumer", gs.time(), "end"
Ejemplo n.º 11
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)))
Ejemplo n.º 12
0
def consumer():

    tests = [ \
"(e1 & e2)",
    "((e1 | e2) & e3)",
    "(e1 & (e2 | e3))",
    "(e0 | e1 & e2 & e3 | e4)",
    "((e1 | e2) | (e3 & e4))",
             ]

    try:
        test = tests[int(sys.argv[1])]
    except:
        test = tests[1]

    print "consumer", gs.time(), "waiting for", test
    exec "gs.wait" + test
    print "consumer", gs.time(), "end"
Ejemplo n.º 13
0
def test2():
    print "test2:", gs.time(), "          start"

    print "test2:", gs.time(), "          waiting for e1"
    gs.wait(e1)
    print "test2:", gs.time(), "          e1 fired"

    print "test2:", gs.time(), "          waiting for e2"
    gs.wait(e2)
    print "test2:", gs.time(), "          e2 fired"

    print "test2:", gs.time(), "          waiting for e3"
    gs.wait(e3)
    print "test2:", gs.time(), "          e3 fired"

    print "test2:", gs.time(), "          end"
Ejemplo n.º 14
0
def test2():
    print "test2:", gs.time(), "          start"

    print "test2:", gs.time(), "          waiting for e1"
    gs.wait(e1)
    print "test2:", gs.time(), "          e1 fired"

    print "test2:", gs.time(), "          waiting for e2"
    gs.wait(e2)
    print "test2:", gs.time(), "          e2 fired"

    print "test2:", gs.time(), "          waiting for e3"
    gs.wait(e3)
    print "test2:", gs.time(), "          e3 fired"

    print "test2:", gs.time(), "          end"
def create_particle(scn, nb):
	global particles, particle_count
	particle_count = nb
	particles = []
	# particles don't collide to each other
	scn.GetPhysicSystem().SetCollisionLayerPairState(1, 1, False)
	scn.GetPhysicSystem().SetCollisionLayerPairState(0, 1, True)

	for i in range(particle_count):
		node, rigid_body = gs.GetPlus().AddPhysicSphere(scn, gs.Matrix4.TranslationMatrix(gs.Vector3(0, -100, 0)), 0.025)
		# avoid the particle to collide to each other
		rigid_body.SetCollisionLayer(1)
		particles.append([0, rigid_body])
		plus.UpdateScene(scn, gs.time(1.0/60))
Ejemplo n.º 16
0
 def doit(self):
     print "producer:", gs.time(), "start"
     print "producer:", gs.time(), "write 3 to output"
     self.output.write(3)
     print "producer:", gs.time(), "read input signal:", self.input.read()
     print "producer:", gs.time(), "wait for reply (write_event)"
     gs.wait(self.input.write_event())
     print "producer:", gs.time(), "read input signal again:", self.input.read()
     print "producer:", gs.time(), "end"
Ejemplo n.º 17
0
def producer():
    print "producer:", gs.time(), "start"
    print "producer:", gs.time(), "write 3 to prod"
    prod.write(3)
    print "producer:", gs.time(), "read signal cons default:", cons.read()
    print "producer:", gs.time(), "wait for reply (write_event on cons)"
    gs.wait(cons.write_event())
    print "producer:", gs.time(), "read signal cons again:", cons.read()
    print "producer:", gs.time(), "end"
Ejemplo n.º 18
0
def consumer():
    print "consumer:", gs.time(), "start"
    print "consumer:", gs.time(), "read signal prod default:", prod.read()
    print "consumer:", gs.time(), "wait for input (write_event on prod)"
    gs.wait(prod.write_event())
    print "consumer:", gs.time(), "read signal prod again:", prod.read()
    print "consumer:", gs.time(), "double the input value and write back"
    cons.write(prod.read() * 2)
    print "consumer:", gs.time(), "end"
Ejemplo n.º 19
0
def consumer():
    print "consumer:", gs.time(), "start"
    print "consumer:", gs.time(), "read signal prod default:", prod.read()
    print "consumer:", gs.time(), "wait for input (write_event on prod)"
    gs.wait(prod.write_event())
    print "consumer:", gs.time(), "read signal prod again:", prod.read()
    print "consumer:", gs.time(), "double the input value and write back"
    cons.write(prod.read()*2)
    print "consumer:", gs.time(), "end"
Ejemplo n.º 20
0
def producer():
    print "producer:", gs.time(), "start"
    print "producer:", gs.time(), "write 3 to prod"
    prod.write(3)
    print "producer:", gs.time(), "read signal cons default:", cons.read()
    print "producer:", gs.time(), "wait for reply (write_event on cons)"
    gs.wait(cons.write_event())
    print "producer:", gs.time(), "read signal cons again:", cons.read()
    print "producer:", gs.time(), "end"
Ejemplo n.º 21
0
 def doit(self):
     print "consumer:", gs.time(), "start"
     print "consumer:", gs.time(), "read input signal:", self.input.read()
     print "consumer:", gs.time(), "wait for input (write_event)"
     gs.wait(self.input.write_event())
     print "consumer:", gs.time(), "read input signal again:", self.input.read()
     print "consumer:", gs.time(), "double the input value and write to output"
     self.output.write(self.input.read()*2)
     print "consumer:", gs.time(), "end"
Ejemplo n.º 22
0
def producer():
    print "producer:", gs.time(), "start"
    print "producer:", gs.time(), "notify e0 after 1ns"
    e0.notify(1)
    print "producer:", gs.time(), "notify e1 after 8ns"
    e1.notify(8)
    print "producer:", gs.time(), "notify e2 after 5ns"
    e2.notify(5)
    print "producer:", gs.time(), "notify e3 after 3ns"
    e3.notify(3)
    print "producer:", gs.time(), "notify e4 after 10ns"
    e4.notify(10)
    print "producer:", gs.time(), "end"
Ejemplo n.º 23
0
def producer():
    print "producer:", gs.time(), "start"
    print "producer:", gs.time(), "notify e0 after 1ns"
    e0.notify(1)
    print "producer:", gs.time(), "notify e1 after 8ns"
    e1.notify(8)
    print "producer:", gs.time(), "notify e2 after 5ns"
    e2.notify(5)
    print "producer:", gs.time(), "notify e3 after 3ns"
    e3.notify(3)
    print "producer:", gs.time(), "notify e4 after 10ns"
    e4.notify(10)
    print "producer:", gs.time(), "end"
Ejemplo n.º 24
0
 def doit(self):
     print "producer:", gs.time(), "start"
     print "producer:", gs.time(), "write 3 to output"
     self.output.write(3)
     print "producer:", gs.time(), "read input signal:", self.input.read()
     print "producer:", gs.time(), "wait for reply (write_event)"
     gs.wait(self.input.write_event())
     print "producer:", gs.time(
     ), "read input signal again:", self.input.read()
     print "producer:", gs.time(), "end"
def initialize_environment(scn):
	global score_plane
	scn.GetPhysicSystem().SetTimestep(1.0/120)

	plus.AddPhysicPlane(scn)

	# create the plane to evaluate score
	score_plane, rb_plane = plus.AddPhysicPlane(scn, gs.Matrix4.TransformationMatrix(gs.Vector3(2, 1, -1), gs.Vector3(0.75, 0, 0)), 1, 1)

	while score_plane.GetComponent("BoxCollision") is None:
		plus.UpdateScene(scn, gs.time(1.0/60))
	score_plane.GetComponent("BoxCollision").SetDimensions(gs.Vector3(1, 0.1, 1))
	score_plane.GetComponent("BoxCollision").SetMatrix(gs.Matrix4.TranslationMatrix(gs.Vector3(0, -0.05, 0)))

	# initialize particles
	particle_emitter.create_particle(scn, 200)
Ejemplo n.º 26
0
def producer():
    print "producer:", gs.time(), "start"
    f.write(1)
    print "producer:", gs.time(), "wrote 1"
    f.write(2)
    print "producer:", gs.time(), "wrote 2"
    f.write(3)
    print "producer:", gs.time(), "wrote 3"
    f.write(4)
    print "producer:", gs.time(), "wrote 4"
    print "producer:", gs.time(), "end"
Ejemplo n.º 27
0
 def doit(self):
     print "consumer:", gs.time(), "start"
     print "consumer:", gs.time(), "read input signal:", self.input.read()
     print "consumer:", gs.time(), "wait for input (write_event)"
     gs.wait(self.input.write_event())
     print "consumer:", gs.time(
     ), "read input signal again:", self.input.read()
     print "consumer:", gs.time(
     ), "double the input value and write to output"
     self.output.write(self.input.read() * 2)
     print "consumer:", gs.time(), "end"
Ejemplo n.º 28
0
def consumer():
    print "consumer:", gs.time(), "start"
    data = f.read()
    print "consumer:", gs.time(), "read ", data
    data = f.read()
    print "consumer:", gs.time(), "read ", data
    data = f.read()
    print "consumer:", gs.time(), "read ", data
    data = f.read()
    print "consumer:", gs.time(), "read ", data
    print "consumer:", gs.time(), "end"
Ejemplo n.º 29
0
def test1():

    print "test1:", gs.time(), "start"
    print "test1:", gs.time(), "wait for 10 default units (ns)"
    gs.wait(10)

    print "test1:", gs.time(), "notify e1 in the same delta"
    e1.notify()
    print "test1:", gs.time(), "wait for one delta"
    gs.wait(0)
    print "test1:", gs.time(), "at this delta e1 was already notified"
    print "test1:", gs.time(), "wait for 10 default units (ns)"
    gs.wait(10)

    print "test1:", gs.time(), "notify e2 in the next delta"
    e2.notify(0)
    print "test1:", gs.time(), "wait for one delta"
    gs.wait(0)
    print "test1:", gs.time(), "at this same delta e2 gets notified"
    print "test1:", gs.time(), "wait for 10 default units (ns)"
    gs.wait(10)

    print "test1:", gs.time(), "notify e3 delayed by 5 us"
    e3.notify(5, gs.US)
    print "test1:", gs.time(), "wait for 4 us"
    gs.wait(4, gs.US)
    print "test1:", gs.time(), "at this time e3 wasn't notifyed yet"
    print "test1:", gs.time(), "wait for 10 default units (ns)"
    gs.wait(10)

    print "test1:", gs.time(), "end"
Ejemplo n.º 30
0
def controler(thread):
    print "controler:", gs.time(), "start"

    print "controler:", gs.time(), "waiting 5 ns to pause thread", thread.name
    gs.wait(5, gs.NS)
    print "controler:", gs.time(), "pausing thread", thread.name, "NOW!"
    thread.pause()
    print "controler:", gs.time(), "waiting 3 ns to resume thread", thread.name
    gs.wait(3)
    print "controler:", gs.time(), "resuming thread", thread.name, "NOW!"
    thread.resume()

    print "controler:", gs.time(), "waiting 5 ns to pause thread", thread.name
    gs.wait(5, gs.NS)
    print "controler:", gs.time(), "pausing thread", thread.name, "NOW!"
    thread.pause()
    print "controler:", gs.time(), "waiting 3 ns to resume thread", thread.name
    gs.wait(3)
    print "controler:", gs.time(), "resuming thread", thread.name, "NOW!"
    thread.resume()

    print "controler:", gs.time(), "waiting 10 ns to kill thread", thread.name
    gs.wait(10)
    print "controler:", gs.time(), "killing thread", thread.name, "NOW!"
    thread.kill()
Ejemplo n.º 31
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()
Ejemplo n.º 32
0
def counter(name, last):
    for num in range(1, last + 1):
        print gs.time(), name + "\t", num
        if num <> last: gs.wait(1)
    print gs.time(), name + "\t", "finished"
Ejemplo n.º 33
0
def counter(name,last):
    for num in range(1,last+1):
        print gs.time(), name+"\t", num
        if num <> last: gs.wait(1)
    print gs.time(), name+"\t", "finished"
Ejemplo n.º 34
0
def update(scn, gui, openvr_frame_renderer):
    global render_tgt_a, render_tgt_b, render_tgt_scene, gpu_texture_a, gpu_texture_b, gpu_texture_scene, scn_glow, single_texture_shader, vtxs, uvs

    if not scn.IsReady():
        return

    screen_size = plus.GetRendererAsync().GetCurrentOutputWindow().GetSize()
    if render_tgt_a is None:
        render_tgt_a, gpu_texture_a = create_scene_render_target(
            screen_size.x, screen_size.y)
        render_tgt_b, gpu_texture_b = create_scene_render_target(
            screen_size.x, screen_size.y)

        render_tgt_scene, gpu_texture_scene = create_scene_render_target(
            screen_size.x, screen_size.y)

        scn_glow = plus.NewScene(False, False)
        plus.AddEnvironment(scn_glow,
                            gs.Color.Transparent)  # clear color to transparent

        scn_glow.SetCurrentCamera(
            plus.AddCamera(scn_glow,
                           scn.GetCurrentCamera().GetTransform().GetWorld()))

        # find all node with name group, insert in the scn_glow and remove from the other
        for node in scn.GetNodes():
            if "group" in node.GetName():
                new_node = plus.AddGeometry(
                    scn_glow,
                    node.GetObject().GetGeometry().GetName(),
                    node.GetTransform().GetWorld())
                new_node.SetName(node.GetName())
                # remove from the old
                scn.RemoveNode(node)

        plus.UpdateScene(scn_glow, gs.time(0))
        plus.UpdateScene(scn_glow, gs.time(0))

        single_texture_shader = plus.GetRendererAsync().LoadShader(
            "assets/blur_texture.isl")

        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)
        ]

    # check if change groupe
    change_groupe(scn, gui, openvr_frame_renderer)

    # render the geo in the first render target
    plus.GetRendererAsync().SetRenderTarget(render_tgt_a)
    plus.GetRendererAsync().Clear(gs.Color(0, 0, 0, 0))
    plus.GetRendererAsync().SetViewport(
        gs.fRect(0, 0, screen_size.x, screen_size.y))

    if scn_glow.GetCurrentCamera() is not None:
        scn_glow.GetCurrentCamera().GetTransform().SetWorld(
            scn.GetCurrentCamera().GetTransform().GetWorld())
    plus.UpdateScene(scn_glow, gs.time(0))

    # render the first picture into the main scene second picture
    def blur(tgt_1, pict_1, tgt_2, pict_2):
        plus.GetRendererAsync().SetRenderTarget(tgt_2)
        plus.GetRendererAsync().SetViewport(
            gs.fRect(0, 0, screen_size.x, screen_size.y))
        plus.GetRendererAsync().Set2DMatrices()
        plus.GetRendererAsync().EnableBlending(True)
        plus.GetRendererAsync().SetShader(single_texture_shader)
        plus.GetRenderSystemAsync().SetShaderEngineValues()
        horizontal = 0
        for i in range(5):
            plus.GetRendererAsync().SetRenderTarget(tgt_2)
            plus.GetRendererAsync().Clear(gs.Color(0, 0, 0, 0))
            plus.GetRendererAsync().SetShaderTexture("u_tex", pict_1)
            plus.GetRendererAsync().SetShaderValue("horizontal", horizontal)
            plus.GetRenderSystemAsync().DrawTriangleUV(2, vtxs, uvs)

            plus.GetRendererAsync().DrawFrame()
            plus.GetRendererAsync().Sync()
            tgt_1, tgt_2 = tgt_2, tgt_1
            pict_1, pict_2 = pict_2, pict_1
            horizontal = (horizontal + 1) % 2

        return pict_1

    if single_texture_shader is not None and single_texture_shader.IsReady():
        gpu_texture_blur = gpu_texture_a  #blur(render_tgt_a, gpu_texture_a, render_tgt_b, gpu_texture_b)

        # render the final picture
        plus.GetRendererAsync().SetRenderTarget(None)
        plus.GetRendererAsync().SetViewport(
            gs.fRect(0, 0, screen_size.x, screen_size.y))

        # render the slow scene output
        plus.Texture2D(0, 0, 1, gpu_texture_scene, gs.Color.White, False, True)
        plus.SetBlend2D(gs.BlendAlpha)
        plus.Texture2D(0, 0, 1, gpu_texture_blur, gs.Color.White, False, True)
        plus.SetBlend2D(gs.BlendOpaque)
Ejemplo n.º 35
0
def test1():

    print "test1:", gs.time(), "start"
    print "test1:", gs.time(), "wait for 10 default units (ns)"
    gs.wait(10)

    print "test1:", gs.time(), "notify e1 in the same delta"
    e1.notify()
    print "test1:", gs.time(), "wait for one delta"
    gs.wait(0)
    print "test1:", gs.time(), "at this delta e1 was already notified"
    print "test1:", gs.time(), "wait for 10 default units (ns)"
    gs.wait(10)

    print "test1:", gs.time(), "notify e2 in the next delta"
    e2.notify(0)
    print "test1:", gs.time(), "wait for one delta"
    gs.wait(0)
    print "test1:", gs.time(), "at this same delta e2 gets notified"
    print "test1:", gs.time(), "wait for 10 default units (ns)"
    gs.wait(10)

    print "test1:", gs.time(), "notify e3 delayed by 5 us"
    e3.notify(5, gs.US)
    print "test1:", gs.time(), "wait for 4 us"
    gs.wait(4, gs.US)
    print "test1:", gs.time(), "at this time e3 wasn't notifyed yet"
    print "test1:", gs.time(), "wait for 10 default units (ns)"
    gs.wait(10)

    print "test1:", gs.time(), "end"
Ejemplo n.º 36
0
def controler(thread):
    print "controler:", gs.time(), "start"

    print "controler:", gs.time(), "waiting 5 ns to pause thread", thread.name
    gs.wait(5, gs.NS)
    print "controler:", gs.time(), "pausing thread", thread.name, "NOW!"
    thread.pause()
    print "controler:", gs.time(), "waiting 3 ns to resume thread", thread.name
    gs.wait(3)
    print "controler:", gs.time(), "resuming thread", thread.name, "NOW!"
    thread.resume()

    print "controler:", gs.time(), "waiting 5 ns to pause thread", thread.name
    gs.wait(5, gs.NS)
    print "controler:", gs.time(), "pausing thread", thread.name, "NOW!"
    thread.pause()
    print "controler:", gs.time(), "waiting 3 ns to resume thread", thread.name
    gs.wait(3)
    print "controler:", gs.time(), "resuming thread", thread.name, "NOW!"
    thread.resume()

    print "controler:", gs.time(), "waiting 10 ns to kill thread", thread.name
    gs.wait(10)
    print "controler:", gs.time(), "killing thread", thread.name, "NOW!"
    thread.kill()
Ejemplo n.º 37
0
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
#   02110-1301  USA
#
# ENDLICENSETEXT

import gs
import random

print "Start the simulation before defining the system"
gs.start(1,gs.US)
print "Simulation started:", gs.time()


f = gs.fifo(2)

def producer():
    print "producer:", gs.time(), "start"
    f.write(1)
    print "producer:", gs.time(), "wrote 1"
    f.write(2)
    print "producer:", gs.time(), "wrote 2"
    f.write(3)
    print "producer:", gs.time(), "wrote 3"
    f.write(4)
    print "producer:", gs.time(), "wrote 4"
    print "producer:", gs.time(), "end"