Beispiel #1
0
def create_scene(clipping_planes, clipping_mode):

    maxsize = 221
    scene = gfx.Scene()
    for n in range(20, maxsize, 50):
        material = gfx.MeshPhongMaterial(
            color=(n / maxsize, 1, 0, 1),
            clipping_planes=clipping_planes,
            clipping_mode=clipping_mode,
        )
        geometry = gfx.box_geometry(n, n, n)
        cube = gfx.Mesh(geometry, material)
        scene.add(cube)

    return scene
Beispiel #2
0
    def __init__(self):
        super().__init__(None)
        self.resize(640, 480)

        # Creat button and hook it up
        self._button = QtWidgets.QPushButton("Add a line", self)
        self._button.clicked.connect(self._on_button_click)

        # Create canvas, renderer and a scene object
        self._canvas = WgpuCanvas(parent=self)
        self._renderer = gfx.WgpuRenderer(self._canvas)
        self._scene = gfx.Scene()
        self._camera = gfx.OrthographicCamera(110, 110)

        # Hook up the animate callback
        self._canvas.request_draw(self.animate)

        layout = QtWidgets.QHBoxLayout()
        self.setLayout(layout)
        layout.addWidget(self._button)
        layout.addWidget(self._canvas)
Beispiel #3
0
"""
Example showing off the mesh slice material.
"""

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

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

geometry = gfx.torus_knot_geometry(1, 0.3, 128, 16)
material1 = gfx.MeshPhongMaterial(color=(0.5, 0.5, 0.5, 1.0))
material2 = gfx.MeshSliceMaterial(thickness=8,
                                  color=(1, 1, 0, 1),
                                  plane=(0, 0, 1, 0))
obj1 = gfx.Mesh(geometry, material1)
obj2 = gfx.Mesh(geometry, material2)
scene.add(obj1)
scene.add(obj2)

camera = gfx.PerspectiveCamera(70, 2)
camera.position.z = 4


def animate():

    dist = material2.plane[3]
    dist += 0.02
    if dist > 1:
        dist = -1.5
Beispiel #4
0
The idea is to render both scenes, but clear the depth before rendering
the overlay, so that it's always on top.
"""

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

# Create a canvas and renderer

canvas = WgpuCanvas(size=(500, 300))
renderer = gfx.renderers.WgpuRenderer(canvas)

# Compose a 3D scene

scene1 = gfx.Scene()

geometry1 = gfx.box_geometry(200, 200, 200)
material1 = gfx.MeshPhongMaterial(color=(1, 1, 0, 1.0))
cube1 = gfx.Mesh(geometry1, material1)
scene1.add(cube1)

camera1 = gfx.OrthographicCamera(300, 300)

# Compose another scene, a 2D overlay

scene2 = gfx.Scene()

positions = np.array(
    [
        [-1, -1, 0.5],