Skip to content

Commit

Permalink
Merge pull request #62 from cmilatinov/feature/property-store
Browse files Browse the repository at this point in the history
Add ability to load scenes with custom properties
  • Loading branch information
Jhonny Knaak de Vargas authored Feb 4, 2024
2 parents 67accd0 + b164ab8 commit 8fc62d1
Show file tree
Hide file tree
Showing 10 changed files with 652 additions and 33 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## Changelog

### 3.2.0
- Added ability to load scenes with property stores (see `load_scene_with_props` example)

### 3.1.1
- Fixing windows compilation. Thanks @Snowiiii for this.

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "russimp"
version = "3.1.1"
version = "3.2.0"
authors = ["Jhonny Knaak de Vargas"]
edition = "2021"
license-file = "LICENSE"
Expand Down
46 changes: 46 additions & 0 deletions examples/load_scene_with_props.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
use russimp::node::Node;
use russimp::property::Property;
use russimp::scene::PostProcess;
use russimp::sys::AI_CONFIG_IMPORT_FBX_PRESERVE_PIVOTS;
use russimp::{property::PropertyStore, scene::Scene};

fn traverse_nodes(node: &Node, indent: String) {
println!("{}{}", indent, node.name);
for child in node.children.borrow().iter() {
traverse_nodes(&*child, format!(" {}", indent));
}
}

fn main() {
// NOTE: You can construct this from a HashMap
// or any iterator if you want.
//
// The cast here is only necessary because
// the array only contains one entry and rust
// tries to make an iterator returning a reference
// to a sized array instead of a slice.
let props: PropertyStore = [(
AI_CONFIG_IMPORT_FBX_PRESERVE_PIVOTS as &[u8],
Property::Integer(0),
)]
.into_iter()
.into();

let scene = Scene::from_file_with_props(
"models/FBX/y_bot_run.fbx",
vec![
PostProcess::Triangulate,
PostProcess::GenerateSmoothNormals,
PostProcess::FlipUVs,
PostProcess::FlipWindingOrder,
PostProcess::JoinIdenticalVertices,
PostProcess::OptimizeGraph,
],
&props,
)
.unwrap();

if let Some(root) = &scene.root {
traverse_nodes(&*root, String::from(""));
}
}
69 changes: 69 additions & 0 deletions models/COLLADA/blender_cube.dae
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="utf-8"?>
<COLLADA xmlns="http://www.collada.org/2005/11/COLLADASchema" version="1.4.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<asset>
<contributor>
<author>Blender User</author>
<authoring_tool>Blender 4.0.2 commit date:2023-12-05, commit time:07:41, hash:9be62e85b727</authoring_tool>
</contributor>
<created>2024-02-02T16:02:18</created>
<modified>2024-02-02T16:02:18</modified>
<unit name="meter" meter="1"/>
<up_axis>Z_UP</up_axis>
</asset>
<library_images/>
<library_geometries>
<geometry id="Cube_001-mesh" name="Cube.001">
<mesh>
<source id="Cube_001-mesh-positions">
<float_array id="Cube_001-mesh-positions-array" count="24">-1 -1 -1 -1 -1 1 -1 1 -1 -1 1 1 1 -1 -1 1 -1 1 1 1 -1 1 1 1</float_array>
<technique_common>
<accessor source="#Cube_001-mesh-positions-array" count="8" stride="3">
<param name="X" type="float"/>
<param name="Y" type="float"/>
<param name="Z" type="float"/>
</accessor>
</technique_common>
</source>
<source id="Cube_001-mesh-normals">
<float_array id="Cube_001-mesh-normals-array" count="18">-1 0 0 0 1 0 1 0 0 0 -1 0 0 0 -1 0 0 1</float_array>
<technique_common>
<accessor source="#Cube_001-mesh-normals-array" count="6" stride="3">
<param name="X" type="float"/>
<param name="Y" type="float"/>
<param name="Z" type="float"/>
</accessor>
</technique_common>
</source>
<source id="Cube_001-mesh-map-0">
<float_array id="Cube_001-mesh-map-0-array" count="72">0.625 0 0.375 0.25 0.375 0 0.625 0.25 0.375 0.5 0.375 0.25 0.625 0.5 0.375 0.75 0.375 0.5 0.625 0.75 0.375 1 0.375 0.75 0.375 0.5 0.125 0.75 0.125 0.5 0.875 0.5 0.625 0.75 0.625 0.5 0.625 0 0.625 0.25 0.375 0.25 0.625 0.25 0.625 0.5 0.375 0.5 0.625 0.5 0.625 0.75 0.375 0.75 0.625 0.75 0.625 1 0.375 1 0.375 0.5 0.375 0.75 0.125 0.75 0.875 0.5 0.875 0.75 0.625 0.75</float_array>
<technique_common>
<accessor source="#Cube_001-mesh-map-0-array" count="36" stride="2">
<param name="S" type="float"/>
<param name="T" type="float"/>
</accessor>
</technique_common>
</source>
<vertices id="Cube_001-mesh-vertices">
<input semantic="POSITION" source="#Cube_001-mesh-positions"/>
</vertices>
<triangles count="12">
<input semantic="VERTEX" source="#Cube_001-mesh-vertices" offset="0"/>
<input semantic="NORMAL" source="#Cube_001-mesh-normals" offset="1"/>
<input semantic="TEXCOORD" source="#Cube_001-mesh-map-0" offset="2" set="0"/>
<p>1 0 0 2 0 1 0 0 2 3 1 3 6 1 4 2 1 5 7 2 6 4 2 7 6 2 8 5 3 9 0 3 10 4 3 11 6 4 12 0 4 13 2 4 14 3 5 15 5 5 16 7 5 17 1 0 18 3 0 19 2 0 20 3 1 21 7 1 22 6 1 23 7 2 24 5 2 25 4 2 26 5 3 27 1 3 28 0 3 29 6 4 30 4 4 31 0 4 32 3 5 33 1 5 34 5 5 35</p>
</triangles>
</mesh>
</geometry>
</library_geometries>
<library_visual_scenes>
<visual_scene id="Scene" name="Scene">
<node id="Cube" name="Cube" type="NODE">
<matrix sid="transform">1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1</matrix>
<instance_geometry url="#Cube_001-mesh" name="Cube"/>
</node>
</visual_scene>
</library_visual_scenes>
<scene>
<instance_visual_scene url="#Scene"/>
</scene>
</COLLADA>
69 changes: 69 additions & 0 deletions models/COLLADA/blender_plane.dae
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="utf-8"?>
<COLLADA xmlns="http://www.collada.org/2005/11/COLLADASchema" version="1.4.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<asset>
<contributor>
<author>Blender User</author>
<authoring_tool>Blender 4.0.2 commit date:2023-12-05, commit time:07:41, hash:9be62e85b727</authoring_tool>
</contributor>
<created>2024-02-02T16:28:47</created>
<modified>2024-02-02T16:28:47</modified>
<unit name="meter" meter="1"/>
<up_axis>Z_UP</up_axis>
</asset>
<library_images/>
<library_geometries>
<geometry id="Plane-mesh" name="Plane">
<mesh>
<source id="Plane-mesh-positions">
<float_array id="Plane-mesh-positions-array" count="12">-1 -1 0 1 -1 0 -1 1 0 1 1 0</float_array>
<technique_common>
<accessor source="#Plane-mesh-positions-array" count="4" stride="3">
<param name="X" type="float"/>
<param name="Y" type="float"/>
<param name="Z" type="float"/>
</accessor>
</technique_common>
</source>
<source id="Plane-mesh-normals">
<float_array id="Plane-mesh-normals-array" count="3">0 0 1</float_array>
<technique_common>
<accessor source="#Plane-mesh-normals-array" count="1" stride="3">
<param name="X" type="float"/>
<param name="Y" type="float"/>
<param name="Z" type="float"/>
</accessor>
</technique_common>
</source>
<source id="Plane-mesh-map-0">
<float_array id="Plane-mesh-map-0-array" count="12">1 0 0 1 0 0 1 0 1 1 0 1</float_array>
<technique_common>
<accessor source="#Plane-mesh-map-0-array" count="6" stride="2">
<param name="S" type="float"/>
<param name="T" type="float"/>
</accessor>
</technique_common>
</source>
<vertices id="Plane-mesh-vertices">
<input semantic="POSITION" source="#Plane-mesh-positions"/>
</vertices>
<triangles count="2">
<input semantic="VERTEX" source="#Plane-mesh-vertices" offset="0"/>
<input semantic="NORMAL" source="#Plane-mesh-normals" offset="1"/>
<input semantic="TEXCOORD" source="#Plane-mesh-map-0" offset="2" set="0"/>
<p>1 0 0 2 0 1 0 0 2 1 0 3 3 0 4 2 0 5</p>
</triangles>
</mesh>
</geometry>
</library_geometries>
<library_visual_scenes>
<visual_scene id="Scene" name="Scene">
<node id="Plane" name="Plane" type="NODE">
<matrix sid="transform">1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1</matrix>
<instance_geometry url="#Plane-mesh" name="Plane"/>
</node>
</visual_scene>
</library_visual_scenes>
<scene>
<instance_visual_scene url="#Scene"/>
</scene>
</COLLADA>
Binary file added models/FBX/cube_armature.fbx
Binary file not shown.
Binary file added models/FBX/y_bot_run.fbx
Binary file not shown.
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub mod material;
pub mod mesh;
pub mod metadata;
pub mod node;
pub mod property;
pub mod scene;

#[derive(Derivative)]
Expand Down
Loading

0 comments on commit 8fc62d1

Please sign in to comment.