Note
Go to the end to download the full example code
Sphere GeometryΒΆ
Example showing different types of geometric cylinders.
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()
spheres = [
(
(0, 0, -7.5),
(0, 0.65, 0, 1),
gfx.sphere_geometry(4.5, phi_length=np.pi * 1.5),
),
((0, 0, 7.5), (1, 1, 1, 1), gfx.sphere_geometry(4)),
(
(15, 0, -7.5),
(1, 0.3, 0.3, 1),
gfx.sphere_geometry(4, theta_start=np.pi * 0.25, theta_length=np.pi * 0.50),
),
(
(15, 0, 7.5),
(0.35, 0, 0, 1),
gfx.sphere_geometry(5, width_segments=6),
),
((-15, 0, -7.5), (1, 1, 0.75, 1), gfx.sphere_geometry(7)),
((-15, 0, 7.5), (1, 1, 0.75, 1), gfx.sphere_geometry(5, height_segments=8)),
]
for pos, color, geometry in spheres:
material = gfx.MeshPhongMaterial(color=color, flat_shading=True)
wobject = gfx.Mesh(geometry, material)
wobject.local.position = pos
scene.add(wobject)
camera = gfx.PerspectiveCamera(70, 16 / 9)
camera.show_object(scene, (-1, -1, -1), up=(0, 1, 0))
scene.add(camera.add(gfx.DirectionalLight()))
scene.add(gfx.AmbientLight())
controller = gfx.OrbitController(camera, register_events=renderer)
if __name__ == "__main__":
canvas.request_draw(lambda: renderer.render(scene, camera))
run()
Total running time of the script: (0 minutes 0.439 seconds)