Create a mesh from raw float data passed from TS. vertex_data layout: [x,y,z, nx,ny,nz, r,g,b,a, u,v] per vertex (12 floats each)
(&mut self, vertex_data: &[f32], index_data: &[u32])
| 271 | /// Create a mesh from raw float data passed from TS. |
| 272 | /// vertex_data layout: [x,y,z, nx,ny,nz, r,g,b,a, u,v] per vertex (12 floats each) |
| 273 | pub fn create_mesh(&mut self, vertex_data: &[f32], index_data: &[u32]) -> f64 { |
| 274 | let floats_per_vert = 12; |
| 275 | let vert_count = vertex_data.len() / floats_per_vert; |
| 276 | if vert_count == 0 { return 0.0; } |
| 277 | |
| 278 | let mut vertices = Vec::with_capacity(vert_count); |
| 279 | let mut bbox_min = [f32::MAX; 3]; |
| 280 | let mut bbox_max = [f32::MIN; 3]; |
| 281 | |
| 282 | for i in 0..vert_count { |
| 283 | let o = i * floats_per_vert; |
| 284 | let pos = [vertex_data[o], vertex_data[o+1], vertex_data[o+2]]; |
| 285 | for k in 0..3 { |
| 286 | if pos[k] < bbox_min[k] { bbox_min[k] = pos[k]; } |
| 287 | if pos[k] > bbox_max[k] { bbox_max[k] = pos[k]; } |
| 288 | } |
| 289 | vertices.push(Vertex3D { |
| 290 | position: pos, |
| 291 | normal: [vertex_data[o+3], vertex_data[o+4], vertex_data[o+5]], |
| 292 | color: [vertex_data[o+6], vertex_data[o+7], vertex_data[o+8], vertex_data[o+9]], |
| 293 | uv: [vertex_data[o+10], vertex_data[o+11]], |
| 294 | joints: [0.0; 4], |
| 295 | weights: [0.0; 4], |
| 296 | tangent: [0.0; 4], |
| 297 | }); |
| 298 | } |
| 299 | |
| 300 | let indices = index_data.to_vec(); |
| 301 | let model = ModelData { |
| 302 | meshes: vec![MeshData { vertices, indices, texture_idx: None, normal_texture_idx: None, metallic_roughness_texture_idx: None, emissive_texture_idx: None, occlusion_texture_idx: None, metallic_factor: 0.0, roughness_factor: 1.0, emissive_factor: [0.0; 3], alpha_cutoff: 0.0 }], |
| 303 | bbox_min, |
| 304 | bbox_max, |
| 305 | }; |
| 306 | self.models.alloc(model) |
| 307 | } |
| 308 | |
| 309 | /// Q9: Generate a ribbon mesh along a Catmull-Rom spline. Used by the |
| 310 | /// editor's river tool. `points` is flat [x0,y0,z0, x1,y1,z1, ...], |
no test coverage detected