Example #1
0
* The yellow axis (y) stick up from the plane.
* The red box fits snugly around the grid.
"""

from wgpu.gui.auto import WgpuCanvas, run
import pygfx as gfx

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

background = gfx.Background(
    None, gfx.BackgroundMaterial((0, 0.1, 0, 1), (0, 0.1, 0.1, 1)))
scene.add(background)

axes = gfx.AxesHelper(length=40)
scene.add(axes)

grid = gfx.GridHelper(size=100)
scene.add(grid)

box = gfx.BoxHelper(size=100)
scene.add(box)

camera = gfx.PerspectiveCamera(70, 16 / 9)
camera.position.set(75, 75, 75)
camera.look_at(gfx.linalg.Vector3())

controls = gfx.OrbitControls(camera.position.clone())
controls.add_default_event_handlers(canvas, camera)
Example #2
0
"""
Example showing orbit camera controls.
"""

import imageio
from wgpu.gui.auto import WgpuCanvas, run
import pygfx as gfx

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

scene.add(gfx.AxesHelper(length=250))

im = imageio.imread("imageio:chelsea.png")
tex = gfx.Texture(im, dim=2).get_view(filter="linear")

material = gfx.MeshBasicMaterial(map=tex, side="front")
geometry = gfx.box_geometry(100, 100, 100)
cubes = [gfx.Mesh(geometry, material) for i in range(8)]
for i, cube in enumerate(cubes):
    cube.position.set(350 - i * 100, 150, 0)
    scene.add(cube)

background = gfx.Background(None,
                            gfx.BackgroundMaterial((0, 1, 0, 1), (0, 1, 1, 1)))
scene.add(background)

camera = gfx.PerspectiveCamera(70, 16 / 9)
camera.position.set(0, 0, 500)
controls = gfx.OrbitControls(camera.position.clone())
Example #3
0
"""
Example showing orbit camera controls.
"""

import imageio
from wgpu.gui.auto import WgpuCanvas, run
import pygfx as gfx

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

axes = gfx.AxesHelper(length=250)
scene.add(axes)

background = gfx.Background(None,
                            gfx.BackgroundMaterial((0, 1, 0, 1), (0, 1, 1, 1)))
scene.add(background)

im = imageio.imread("imageio:astronaut.png")
tex = gfx.Texture(im, dim=2)
geometry = gfx.plane_geometry(512, 512)
material = gfx.MeshBasicMaterial(map=tex.get_view(filter="linear"))
plane = gfx.Mesh(geometry, material)
scene.add(plane)

camera = gfx.OrthographicCamera(512, 512)
camera.position.set(0, 0, 500)
controls = gfx.PanZoomControls(camera.position.clone())
controls.add_default_event_handlers(canvas, camera)