Comments (3)
Performance has been improved, will do some timings in the near future and see what's remaining.
from meshopt-rs.
The remaining work is around improving the DecodePosition -> collect pattern. I'm thinking that implementing a nice referencing data reader that can step by a configurable stride, and is zero-copy would do the trick (needs to work like the C++ API which works similar to glVertexPointer)
An example:
pub struct VertexDataReader<'a> {
reader: Cursor<&'a [u8]>
}
impl<'a> VertexDataReader<'a> {
pub fn new (data: &'a [u8]) -> VertexDataReader<'a> {
VertexDataReader{ reader: Cursor::new(data) }
}
}
impl<'a> Read for VertexDataReader<'a> {
fn read(&mut self, buf: &mut [u8]) -> Result<usize, io::Error> {
self.reader.read(buf)
}
}
from meshopt-rs.
I'm using nalgebra_glm
types for my vertex streams as well as some custom types and ran into some issues with that related to DecodePosition
and with requiring that vertex data implement Default
(which none of my types did).
My first workaround was to implement some new function wrappers locally for this use case, one that allowed me to remap without having the structure implement the Default
trait by providing a fn that could do that instead:
fn remap_vertex_buffer<T>(
vertex_remap: &[u32],
source_vertices: &[T],
default_fn: fn() -> T,
) -> Vec<T>
where
T: Clone,
{
let mut dest_vertices: Vec<T> = vec![default_fn(); vertex_remap.len()];
unsafe {
meshopt::ffi::meshopt_remapVertexBuffer(
dest_vertices.as_mut_ptr() as *mut ::std::os::raw::c_void,
source_vertices.as_ptr() as *const ::std::os::raw::c_void,
vertex_remap.len(),
std::mem::size_of::<T>(),
vertex_remap.as_ptr() as *const ::std::os::raw::c_uint,
);
}
dest_vertices
}
Which I called like this, which felt like an ok workaround:
mesh.positions = remap_vertex_buffer(&vertex_remap, &mesh.positions, || glm::vec3(0.0, 0.0, 0.0));
To avoid DecodePosition
I simply did a local explicit version with the glm::Vec3
type which is definitely not as nice but works:
fn optimize_overdraw_in_place(indices: &mut [u32], vertices: &[glm::Vec3], threshold: f32) {
let positions = vertices
.iter()
.map(|vertex| [vertex.x, vertex.y, vertex.z])
.collect::<Vec<[f32; 3]>>();
unsafe {
meshopt::ffi::meshopt_optimizeOverdraw(
indices.as_mut_ptr() as *mut ::std::os::raw::c_uint,
indices.as_ptr() as *const ::std::os::raw::c_uint,
indices.len(),
positions.as_ptr() as *const f32,
positions.len(),
std::mem::size_of::<f32>() * 3,
threshold,
);
}
}
So having your proposed VertexDataReader
and being able to pass that in to read and convert any data stream would be a much better approach I think.
from meshopt-rs.
Related Issues (17)
- Write unit tests
- derive(Debug) on generated structs
- Add wrappers for new methods
- Evaluate pure rust compression crates HOT 2
- Demo build failure HOT 1
- Supporting additional vertex attributes HOT 1
- Any plans for updating to newer versions of meshoptimizer library ? HOT 2
- optimize_vertex_cache_in_place takes immutable indices
- Replace deprecated `failure` crate
- Incorrect buffer size HOT 3
- Evaluate using half-rs for half quantization routines HOT 1
- Documentation coverage of the API HOT 2
- Create a minimalistic 100% optimal tool example HOT 8
- Simplifier should read the entire vertex, not just positions HOT 2
- More exhaustive validation in some sanity check modes
- Upgrade to latest mesh optimizer HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from meshopt-rs.