|
1 | 1 | //! Action to convert an LDraw file to another format.
|
2 | 2 |
|
3 | 3 | use crate::{
|
4 |
| - as_u8_slice, |
5 | 4 | error::{Error, Utf8Error},
|
6 | 5 | gltf, Action, App, DiskResolver, GeometryCache,
|
7 | 6 | };
|
@@ -252,8 +251,9 @@ impl ConvertCommand {
|
252 | 251 | gltf: &mut gltf::Gltf,
|
253 | 252 | buffer: &mut Vec<u8>,
|
254 | 253 | ) {
|
| 254 | + // TODO: glTF is LE only; should convert on BE platforms |
255 | 255 | let vertices = &geometry_cache.vertices;
|
256 |
| - let vertices_bytes: &[u8] = unsafe { as_u8_slice(vertices) }; |
| 256 | + let vertices_bytes: &[u8] = bytemuck::cast_slice(&vertices[..]); |
257 | 257 |
|
258 | 258 | // TODO: Line indices?
|
259 | 259 | let vertex_buffer_view_index = gltf.buffer_views.len() as u32;
|
@@ -293,16 +293,19 @@ impl ConvertCommand {
|
293 | 293 | let attributes = HashMap::from([("POSITION".to_string(), gltf.accessors.len() as u32)]);
|
294 | 294 | gltf.accessors.push(vertex_accessor);
|
295 | 295 |
|
296 |
| - // TODO: Use bytemuck instead. |
297 |
| - let triangle_indices = &geometry_cache.triangle_indices; |
298 |
| - let triangle_indices_bytes: &[u8] = unsafe { as_u8_slice(triangle_indices) }; |
| 296 | + // TODO: glTF is LE only; should convert on BE platforms |
| 297 | + let triangle_indices_bytes: &[u8] = |
| 298 | + bytemuck::cast_slice(&geometry_cache.triangle_indices[..]); |
299 | 299 |
|
| 300 | + let byte_offset = buffer.len() as u32; |
| 301 | + let byte_length = triangle_indices_bytes.len() as u32; |
300 | 302 | let index_buffer_view_index = gltf.buffer_views.len() as u32;
|
| 303 | + |
301 | 304 | gltf.buffer_views.push(gltf::BufferView {
|
302 | 305 | name: Some("index_buffer".to_string()),
|
303 | 306 | buffer_index: 0,
|
304 |
| - byte_length: triangle_indices_bytes.len() as u32, |
305 |
| - byte_offset: buffer.len() as u32, |
| 307 | + byte_length, |
| 308 | + byte_offset, |
306 | 309 | byte_stride: None,
|
307 | 310 | target: Some(gltf::BufferTarget::ElementArrayBuffer as u32),
|
308 | 311 | });
|
|
0 commit comments