-
-
Notifications
You must be signed in to change notification settings - Fork 252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use meshloader to support multiple file formats loading #744
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b5038c0
use meshloader to support multiple files
Vrixyz fb8a7c7
use scale when loading a mesh from meshloader
Vrixyz 7617ab0
fix docs
Vrixyz 1b7713f
include readme to avoid doc duplication
Vrixyz 8a55b7f
pr feedbacks
Vrixyz 0312820
comment out meshloader publish script
Vrixyz b27377b
uncomment publish script
Vrixyz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
## Unreleased | ||
|
||
Renamed the crate from `rapier3d-stl` to `rapier3d-meshloader`, to better reflect its support for multiple formats. | ||
|
||
### Added | ||
|
||
- Add optional support for Collada and Wavefront files through new feature flags `collada` and `wavefront`. | ||
|
||
### Modified | ||
|
||
- Support for STL is now optional through feature `stl`. | ||
- Features `stl`, `wavefront` and `collada` are enabled by default. | ||
|
||
## 0.3.0 | ||
|
||
This is the initial release of the `rapier3d-stl` crate. | ||
|
||
### Added | ||
|
||
- Add `load_from_path` for creating a shape from a stl file. | ||
- Add `load_from_reader` for creating a shape from an object implementing `Read`. | ||
- Add `load_from_raw_mesh` for creating a shape from an already loaded `IndexedMesh`. |
20 changes: 16 additions & 4 deletions
20
crates/rapier3d-stl/Cargo.toml → crates/rapier3d-meshloader/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,31 @@ | ||
[package] | ||
name = "rapier3d-stl" | ||
name = "rapier3d-meshloader" | ||
version = "0.3.0" | ||
authors = ["Sébastien Crozet <[email protected]>"] | ||
description = "STL file loader for the 3D rapier physics engine." | ||
documentation = "https://docs.rs/rapier3d-stl" | ||
documentation = "https://docs.rs/rapier3d-meshloader" | ||
homepage = "https://rapier.rs" | ||
repository = "https://github.com/dimforge/rapier" | ||
readme = "README.md" | ||
categories = ["science", "game-development", "mathematics", "simulation", "wasm"] | ||
categories = [ | ||
"science", | ||
"game-development", | ||
"mathematics", | ||
"simulation", | ||
"wasm", | ||
] | ||
keywords = ["physics", "joints", "multibody", "robotics", "urdf"] | ||
license = "Apache-2.0" | ||
edition = "2021" | ||
|
||
[features] | ||
default = ["stl", "collada", "wavefront"] | ||
stl = ["mesh-loader/stl"] | ||
collada = ["mesh-loader/collada"] | ||
wavefront = ["mesh-loader/obj"] | ||
|
||
[dependencies] | ||
thiserror = "1.0.61" | ||
stl_io = "0.7" | ||
mesh-loader = { version = "0.1.12", optional = true } | ||
|
||
rapier3d = { version = "0.22", path = "../rapier3d" } |
File renamed without changes.
10 changes: 7 additions & 3 deletions
10
crates/rapier3d-stl/README.md → crates/rapier3d-meshloader/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#![doc = include_str!("../README.md")] | ||
#![deny(missing_docs)] | ||
|
||
use mesh_loader::Mesh; | ||
use rapier3d::geometry::{MeshConverter, SharedShape}; | ||
use rapier3d::math::{Isometry, Point, Real, Vector}; | ||
use rapier3d::prelude::MeshConverterError; | ||
use std::path::Path; | ||
|
||
/// The result of loading a shape. | ||
pub struct LoadedShape { | ||
/// The shape loaded from the file and converted by the [`MeshConverter`]. | ||
pub shape: SharedShape, | ||
/// The shape’s pose. | ||
pub pose: Isometry<Real>, | ||
/// The raw mesh read from the file without any modification. | ||
pub raw_mesh: Mesh, | ||
} | ||
|
||
/// Error while loading an STL file. | ||
#[derive(thiserror::Error, Debug)] | ||
pub enum MeshLoaderError { | ||
/// An error triggered by rapier’s [`MeshConverter`]. | ||
#[error(transparent)] | ||
MeshConverter(#[from] MeshConverterError), | ||
/// A generic IO error. | ||
#[error(transparent)] | ||
Io(#[from] std::io::Error), | ||
} | ||
|
||
/// Loads parry shapes from a file. | ||
/// | ||
/// # Parameters | ||
/// - `path`: the file’s path. | ||
/// - `converter`: controls how the shapes are computed from the content. In particular, it lets | ||
/// you specify if the computed [`SharedShape`] is a triangle mesh, its convex hull, | ||
/// bounding box, etc. | ||
/// - `scale`: the scaling factor applied to the geometry input to the `converter`. This scale will | ||
/// affect at the geometric level the [`LoadedShape::shape`]. Note that raw mesh value stored | ||
/// in [`LoadedShape::raw_mesh`] remains unscaled. | ||
pub fn load_from_path( | ||
path: impl AsRef<Path>, | ||
converter: &MeshConverter, | ||
scale: Vector<Real>, | ||
) -> Result<Vec<Result<LoadedShape, MeshConverterError>>, MeshLoaderError> { | ||
let loader = mesh_loader::Loader::default(); | ||
let mut colliders = vec![]; | ||
let scene = loader.load(path)?; | ||
for (raw_mesh, _) in scene.meshes.into_iter().zip(scene.materials) { | ||
let shape = load_from_raw_mesh(&raw_mesh, converter, scale); | ||
|
||
colliders.push(shape.map(|(shape, pose)| LoadedShape { | ||
shape, | ||
pose, | ||
raw_mesh, | ||
})); | ||
} | ||
Ok(colliders) | ||
} | ||
|
||
/// Loads an file as a shape from a preloaded raw [`mesh_loader::Mesh`]. | ||
/// | ||
/// # Parameters | ||
/// - `raw_mesh`: the raw mesh. | ||
/// - `converter`: controls how the shape is computed from the STL content. In particular, it lets | ||
/// you specify if the computed [`SharedShape`] is a triangle mesh, its convex hull, | ||
/// bounding box, etc. | ||
/// - `scale`: the scaling factor applied to the geometry input to the `converter`. This scale will | ||
/// affect at the geometric level the [`LoadedShape::shape`]. Note that raw mesh value stored | ||
/// in [`LoadedShape::raw_mesh`] remains unscaled. | ||
pub fn load_from_raw_mesh( | ||
raw_mesh: &Mesh, | ||
converter: &MeshConverter, | ||
scale: Vector<Real>, | ||
) -> Result<(SharedShape, Isometry<Real>), MeshConverterError> { | ||
let mut vertices: Vec<_> = raw_mesh | ||
.vertices | ||
.iter() | ||
.map(|xyz| Point::new(xyz[0], xyz[1], xyz[2])) | ||
.collect(); | ||
vertices | ||
.iter_mut() | ||
.for_each(|pt| pt.coords.component_mul_assign(&scale)); | ||
let indices: Vec<_> = raw_mesh.faces.clone(); | ||
converter.convert(vertices, indices) | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your suggestion doesn´t work with the following error:
I can fix it with
cloned()
, or could make an upstream pr to support that conversion?