Skip to content

Commit 4748187

Browse files
committed
animated_mesh.py works!
1 parent 3d70536 commit 4748187

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

crates/processing_pyo3/examples/animated_mesh.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
from processing import *
2+
from math import sin, cos
23

34
mesh = None
45
grid_size = 20
56
spacing = 10.0
67
offset = (grid_size * spacing) / 2.0;
8+
time = 0.0
79

810
def setup():
911
global mesh
@@ -39,13 +41,23 @@ def draw():
3941
global grid_size
4042
global offset
4143
global spacing
44+
global time
4245

4346
camera_position(150.0, 150.0, 150.0)
4447
camera_look_at( 0.0, 0.0, 0.0)
4548
background(220, 200, 140)
4649

50+
for z in range(grid_size):
51+
for x in range(grid_size):
52+
idx = int(z * grid_size + x)
53+
px = x * spacing - offset
54+
pz = z * spacing - offset
55+
wave = sin(px * 0.1 + time) * cos(pz * 0.1 + time) * 20.0
56+
mesh.set_vertex(idx, px, wave, pz)
57+
4758
draw_mesh(mesh)
4859

60+
time += 0.05
4961

5062

5163
# TODO: this should happen implicitly on module load somehow

crates/processing_pyo3/src/graphics.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ impl Mesh {
6565
pub fn index(&self, i: u32) -> PyResult<()> {
6666
geometry_index(self.entity, i).map_err(|e| PyRuntimeError::new_err(format!("{e}")))
6767
}
68+
69+
pub fn set_vertex(&self, i: u32, x: f32, y: f32, z: f32) -> PyResult<()> {
70+
geometry_set_vertex(self.entity, i, x, y, z)
71+
.map_err(|e| PyRuntimeError::new_err(format!("{e}")))
72+
}
6873
}
6974

7075
#[pyclass(unsendable)]

0 commit comments

Comments
 (0)