Skip to content

Commit 3327147

Browse files
committed
update WASM bindings
1 parent 0c420ff commit 3327147

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

src/wasm/mesh_js.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ impl MeshJs {
3434
#[wasm_bindgen(js_name = positions)]
3535
pub fn positions(&self) -> Float64Array {
3636
let obj = self.to_arrays();
37-
let pos = Reflect::get(&obj, &"positions".into()).unwrap();
38-
pos.dyn_into::<Float64Array>().unwrap()
37+
let position = Reflect::get(&obj, &"positions".into()).unwrap();
38+
position.dyn_into::<Float64Array>().unwrap()
3939
}
4040

4141
/// Return an interleaved array of vertex normals (nx,ny,nz)*.
@@ -66,11 +66,11 @@ impl MeshJs {
6666
for poly in &self.inner.polygons {
6767
for vertex in &poly.vertices {
6868
if !vertices.iter().any(|v: &Point3<f64>| {
69-
(v.x - vertex.pos.x).abs() < 1e-8
70-
&& (v.y - vertex.pos.y).abs() < 1e-8
71-
&& (v.z - vertex.pos.z).abs() < 1e-8
69+
(v.x - vertex.position.x).abs() < 1e-8
70+
&& (v.y - vertex.position.y).abs() < 1e-8
71+
&& (v.z - vertex.position.z).abs() < 1e-8
7272
}) {
73-
vertices.push(vertex.pos);
73+
vertices.push(vertex.position);
7474
}
7575
}
7676
}
@@ -90,7 +90,7 @@ impl MeshJs {
9090
let mut idx: u32 = 0;
9191
for p in &tri.polygons {
9292
for v in &p.vertices {
93-
positions.extend_from_slice(&[v.pos.x as f64, v.pos.y as f64, v.pos.z as f64]);
93+
positions.extend_from_slice(&[v.position.x as f64, v.position.y as f64, v.position.z as f64]);
9494
normals.extend_from_slice(&[
9595
v.normal.x as f64,
9696
v.normal.y as f64,
@@ -133,7 +133,7 @@ impl MeshJs {
133133
let js_vert = Object::new();
134134

135135
// Wrap position and normal in Point3Js / Vector3Js
136-
let pos_js = Point3Js::from(v.pos);
136+
let pos_js = Point3Js::from(v.position);
137137
let norm_js = Vector3Js::from(v.normal);
138138

139139
Reflect::set(&js_vert, &"position".into(), &JsValue::from(pos_js)).unwrap();
@@ -469,6 +469,11 @@ impl MeshJs {
469469
self.inner
470470
.to_amf_with_color(object_name, units, (r as Real, g as Real, b as Real))
471471
}
472+
473+
#[wasm_bindgen(js_name = toGLTF)]
474+
pub fn to_gltf(&self, object_name: &str) -> String {
475+
self.inner.to_gltf(object_name)
476+
}
472477

473478
#[wasm_bindgen(js_name=fromSketch)]
474479
pub fn from_sketch(sketch_js: &SketchJs) -> MeshJs {

src/wasm/plane_js.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::float_types::Real;
2-
use crate::mesh::{plane::Plane, vertex::Vertex};
2+
use crate::mesh::plane::Plane;
3+
use crate::vertex::Vertex;
34
use crate::wasm::{
45
matrix_js::Matrix4Js, point_js::Point3Js, polygon_js::PolygonJs, vector_js::Vector3Js,
56
vertex_js::VertexJs,

src/wasm/polygon_js.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use crate::mesh::{polygon::Polygon, vertex::Vertex};
1+
use crate::mesh::polygon::Polygon;
2+
use crate::vertex::Vertex;
23
use crate::wasm::{
34
js_metadata_to_string, plane_js::PlaneJs, point_js::Point3Js, vector_js::Vector3Js,
45
vertex_js::VertexJs,
@@ -112,9 +113,9 @@ impl PolygonJs {
112113
let mut data = Vec::with_capacity(self.inner.vertices.len() * 6);
113114

114115
for v in &self.inner.vertices {
115-
data.push(v.pos.x as f64);
116-
data.push(v.pos.y as f64);
117-
data.push(v.pos.z as f64);
116+
data.push(v.position.x as f64);
117+
data.push(v.position.y as f64);
118+
data.push(v.position.z as f64);
118119
data.push(v.normal.x as f64);
119120
data.push(v.normal.y as f64);
120121
data.push(v.normal.z as f64);

0 commit comments

Comments
 (0)