|
| 1 | +pub mod models; |
1 | 2 | pub mod radix;
|
2 | 3 | pub mod texture_gen;
|
3 | 4 |
|
4 |
| -use js_sys::{Float32Array, Object, Uint32Array, Uint8Array}; |
| 5 | +use js_sys::{Float32Array, Uint32Array, Uint8Array}; |
5 | 6 | use wasm_bindgen::prelude::*;
|
| 7 | +use crate::models::TextureData; |
6 | 8 |
|
7 | 9 | /// Generate a splat texture from the given attributes.
|
8 | 10 | ///
|
9 | 11 | /// Wraps the [`texture_gen::generate_texture_from_attrs`] function for access from JavaScript.
|
10 | 12 | #[wasm_bindgen]
|
11 |
| -pub fn generate_splat_texture_from_attrs( |
| 13 | +pub fn generate_splat_texture( |
12 | 14 | positions: &Float32Array,
|
13 | 15 | scales: &Float32Array,
|
14 | 16 | rotations: &Float32Array,
|
15 | 17 | colors: &Uint8Array,
|
16 | 18 | count: usize,
|
17 |
| -) -> Result<Object, JsValue> { |
18 |
| - let texture_data = |
19 |
| - texture_gen::generate_texture_from_attrs(positions, scales, rotations, colors, count)?; |
20 |
| - |
21 |
| - let js_data = Uint32Array::new_with_length(texture_data.width() * texture_data.height() * 4); |
22 |
| - js_data.copy_from(&texture_data.data()); |
23 |
| - |
24 |
| - let result = Object::new(); |
25 |
| - js_sys::Reflect::set(&result, &"data".into(), &js_data)?; |
26 |
| - js_sys::Reflect::set( |
27 |
| - &result, |
28 |
| - &"width".into(), |
29 |
| - &(texture_data.width() as f64).into(), |
30 |
| - )?; |
31 |
| - js_sys::Reflect::set( |
32 |
| - &result, |
33 |
| - &"height".into(), |
34 |
| - &(texture_data.height() as f64).into(), |
35 |
| - )?; |
| 19 | +) -> Result<TextureData, JsValue> { |
| 20 | + texture_gen::generate_texture_from_attrs(positions, scales, rotations, colors, count) |
| 21 | +} |
36 | 22 |
|
37 |
| - Ok(result) |
| 23 | +/// Sorts the Gaussian Splats by depth using a radix sort. |
| 24 | +/// |
| 25 | +/// Wraps the [`radix::radix_sort_gaussians_indexes`] function for access from JavaScript. |
| 26 | +#[wasm_bindgen] |
| 27 | +pub fn radix_sort_gaussians_indexes( |
| 28 | + positions: &Float32Array, |
| 29 | + model_view: &Float32Array, |
| 30 | + count: usize, |
| 31 | +) -> Result<Uint32Array, JsValue> { |
| 32 | + radix::radix_sort_gaussians_indexes(positions, model_view, count) |
38 | 33 | }
|
0 commit comments