Beispiel #1
0
 def _on_button_click(self):
     positions = [[random.uniform(-50, 50),
                   random.uniform(-50, 50), 0] for i in range(8)]
     line = gfx.Line(gfx.Geometry(positions=positions),
                     gfx.LineMaterial(thickness=3))
     self._scene.add(line)
     self._canvas.update()
Beispiel #2
0
scene2 = gfx.Scene()

positions = np.array(
    [
        [-1, -1, 0.5],
        [-1, +1, 0.5],
        [+1, +1, 0.5],
        [+1, -1, 0.5],
        [-1, -1, 0.5],
        [+1, +1, 0.5],
    ],
    np.float32,
)
geometry2 = gfx.Geometry(positions=positions * 0.9)
material2 = gfx.LineMaterial(thickness=5.0, color=(0.8, 0.0, 0.2, 1.0))
line2 = gfx.Line(geometry2, material2)
scene2.add(line2)

camera2 = gfx.NDCCamera()


def animate():
    rot = gfx.linalg.Quaternion().set_from_euler(gfx.linalg.Euler(0.005, 0.01))
    cube1.rotation.multiply(rot)

    renderer.render(scene1, camera1, flush=False)
    renderer.render(scene2, camera2)

    canvas.request_draw()

Beispiel #3
0
import numpy as np
from wgpu.gui.auto import WgpuCanvas, run
import pygfx as gfx


canvas = WgpuCanvas()
renderer = gfx.renderers.WgpuRenderer(canvas)
scene = gfx.Scene()

xx = np.linspace(-50, 50, 10)
yy = np.random.uniform(20, 50, 10)
geometry = gfx.Geometry(positions=[(x, y, 0) for x, y in zip(xx, yy)])
if True:  # Set to False to try this for a line
    ob = gfx.Points(geometry, gfx.PointsMaterial(color=(0, 1, 1, 1), size=20))
else:
    ob = gfx.Line(geometry, gfx.LineMaterial(color=(0, 1, 1, 1), thickness=12))
scene.add(ob)

camera = gfx.OrthographicCamera(120, 120)


@canvas.add_event_handler("pointer_down")
def handle_event(event):
    info = renderer.get_pick_info((event["x"], event["y"]))
    wobject = info["world_object"]
    # If a point was clicked ..
    if wobject and "vertex_index" in info:
        i = int(round(info["vertex_index"]))
        geometry.positions.data[i, 1] *= -1
        geometry.positions.update_range(i)
        canvas.request_draw()
Beispiel #4
0
renderer = gfx.WgpuRenderer(canvas)

# A straight line
line1 = [[100, 100], [100, 200], [100, 200], [100, 400]]

# A line with a 180 degree turn (a bit of a special case for the implementation)
line2 = [[200, 100], [200, 400], [200, 100]]

# A swiggly line
line3 = [[300 + random.randint(-10, 10), 100 + i * 3] for i in range(100)]

# A line with other turns
line4 = [[400, 100], [500, 200], [400, 300], [450, 400]]

scene = gfx.Scene()

material = gfx.LineMaterial(thickness=80.0, color=(0.8, 0.7, 0.0, 1.0))

for line in [line1, line2, line3, line4]:
    line = [pos + [0] for pos in line]  # Make the positions vec3
    geometry = gfx.Geometry(positions=line)
    line = gfx.Line(geometry, material)
    scene.add(line)

camera = gfx.ScreenCoordsCamera()


if __name__ == "__main__":
    canvas.request_draw(lambda: renderer.render(scene, camera))
    run()
Beispiel #5
0
scene = gfx.Scene()
positions = [[200 + np.sin(i) * i * 6, 200 + np.cos(i) * i * 6, 0] for i in range(20)]
positions += [[400 - np.sin(i) * i * 6, 200 + np.cos(i) * i * 6, 0] for i in range(20)]
positions += [
    [450, 400, 0],
    [375, 400, 0],
    [300, 400, 0],
    [400, 370, 0],
    [300, 340, 0],
]

# Spiral away in z (to make the depth buffer less boring)
for i in range(len(positions)):
    positions[i][2] = i

line = gfx.Line(
    gfx.Geometry(positions=positions),
    gfx.LineMaterial(thickness=12.0, color=(0.8, 0.7, 0.0)),
)
scene.add(line)

camera = gfx.OrthographicCamera(600, 500)
camera.position.set(300, 250, 0)


if __name__ == "__main__":
    renderer_svg.render(scene, camera)
    canvas.request_draw(lambda: renderer.render(scene, camera))
    run()
Beispiel #6
0
def test_render_registry_of_svg():
    r = gfx.renderers.svg._svgrenderer.registry

    assert None is r.get_render_function(Object1(Material1()))

    assert r.get_render_function(gfx.Line(None, gfx.LineMaterial()))