Skip to content

Commit 0dbf413

Browse files
Update pygfx and fix examples (#97)
* Update pygfx and fix examples
1 parent 1fd1023 commit 0dbf413

8 files changed

Lines changed: 119 additions & 138 deletions

examples/combined-example.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ def mounted(self):
2929
{
3030
"name": "Landmarks",
3131
},
32+
h("AmbientLight"),
33+
h("PointLight"),
3234
h(
3335
PointCloud,
3436
# When increasing this number, it will take longer

examples/component-example.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,13 @@ def render(self):
9090
renderer=cg.PygfxRenderer(), event_loop_type=cg.EventLoopType.QT
9191
)
9292

93-
element = h(NumberPad, {})
93+
element = h(
94+
"Group",
95+
{},
96+
h(NumberPad),
97+
h("AmbientLight"),
98+
h("PointLight", {"position": [10, 30, 40]}),
99+
)
94100
container = gfx.Scene()
95101

96102
def animate():

examples/pygfx-example.py

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,3 @@
1-
"""
2-
Followed the following guide:
3-
https://pomb.us/build-your-own-react/
4-
and implemented it in Python.
5-
6-
Example 'React' code:
7-
8-
<Group name="Landmarks">
9-
<Point name="Hip" position="[1, 1, 1]" />
10-
</Group>
11-
12-
This can be transpiled to a tree of 'VNodes'.
13-
Instead of JSX/Vue template, this could also be just creating
14-
the tree of VNodes 'manually'.
15-
VNodes are essentially a description of the to-be-displayed item.
16-
17-
1. Create tree of VNodes
18-
2. Render the tree (see __init__.py)
19-
- Split up the work in smaller chunks (node-by-node)
20-
- Build up a 'work-in-progress' tree of 'fibers'
21-
- Once it is ready, compare this tree with the 'current' tree (reconciliation)
22-
- The renderer that is called during reconciliation creates the actual 'dom' nodes,
23-
so a PygfxRenderer for instance would know how to reconcile a tree of pygfx
24-
objects.
25-
26-
"""
271
from point_cloud import materials, PointCloud, sphere_geom
282
import pygfx as gfx
293
from wgpu.gui.auto import run, WgpuCanvas
@@ -36,7 +10,7 @@
3610
canvas = WgpuCanvas(size=(600, 400))
3711
renderer = gfx.renderers.WgpuRenderer(canvas)
3812

39-
camera = gfx.PerspectiveCamera(60, 16 / 9)
13+
camera = gfx.PerspectiveCamera(70, 16 / 9)
4014
camera.position.z = 15
4115

4216
controls = gfx.OrbitController(camera.position.clone())
@@ -52,6 +26,8 @@
5226
{
5327
"name": "Landmarks",
5428
},
29+
h("AmbientLight"),
30+
h("PointLight", {"position": [0, 70, 70], "cast_shadow": True}),
5531
h(
5632
PointCloud,
5733
# When increasing this number, it will take longer

examples/pygfx-slider-example.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def __init__(self, *args, **kwargs):
4343
def mouse_down(self, event):
4444
if not self._sphere:
4545
self._sphere = event.current_target
46-
self._sphere.set_pointer_capture(event.pointer_id)
46+
self._sphere.set_pointer_capture(event.pointer_id, event.root)
4747
self._captured = True
4848
self._mouse_pos = event.x, event.y
4949

@@ -81,7 +81,18 @@ def render(self):
8181
class Slider(cg.Component):
8282
def render(self):
8383
return h(
84-
"Group", self.state, h(Track, {"scale": [0.5, 0.5, 10]}), h(Scrubber, {})
84+
"Group",
85+
self.state,
86+
h(Track, {"scale": [0.5, 0.5, 10]}),
87+
h(Scrubber, {}),
88+
h("AmbientLight"),
89+
h(
90+
"PointLight",
91+
{
92+
"position": [20, 40, 50],
93+
"cast_shadow": True,
94+
},
95+
),
8596
)
8697

8798

examples/pyside-example.py

Lines changed: 0 additions & 82 deletions
This file was deleted.

examples/todo-example.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""
22
Example of how to render to PySide6 UI.
33
"""
4-
from observ import reactive
54
from PySide6 import QtWidgets
65

76
import collagraph as cg
@@ -40,15 +39,11 @@ def TodoList(props):
4039
class TodoApp(cg.Component):
4140
def __init__(self, *args, **kwargs):
4241
super().__init__(*args, **kwargs)
43-
self.state = reactive(
44-
{
45-
"items": [
46-
"Groceries",
47-
"Laundry",
48-
],
49-
"text": "",
50-
}
51-
)
42+
self.state["items"] = [
43+
"Groceries",
44+
"Laundry",
45+
]
46+
self.state["text"] = ""
5247

5348
def handle_change(self, event):
5449
self.state["text"] = event

poetry.lock

Lines changed: 88 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pyside = ["pyside6_essentials"]
1414
[tool.poetry.dependencies]
1515
python = ">=3.9"
1616
observ = ">=0.9.5"
17-
pygfx = { version = ">=0.1.9", optional = true }
17+
pygfx = { version = ">=0.1.12", optional = true }
1818
pyside6_essentials = { version = "~6.4", python = "<3.12", optional = true }
1919

2020
[tool.poetry.group.dev.dependencies]

0 commit comments

Comments
 (0)