Skip to content

Commit d0378d2

Browse files
authored
Merge pull request #17 from sdfgeoff/bevy-0.6
Bevy 0.6
2 parents 823b25f + 59624ba commit d0378d2

File tree

10 files changed

+953
-1167
lines changed

10 files changed

+953
-1167
lines changed

Cargo.lock

Lines changed: 847 additions & 1066 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[package]
22
name = "blender_bevy_toolkit"
3-
version = "0.1.0"
3+
version = "0.2.0"
44
authors = ["Geoffrey Irons <[email protected]>"]
5-
edition = "2018"
5+
edition = "2021"
66
license = "MIT"
77

88
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@@ -13,7 +13,7 @@ serde = {version = "1", features = ["derive"]}
1313
smallvec = { version = "1.4", features = ["serde"] }
1414

1515
[dependencies.bevy]
16-
version="0.5.0"
16+
version="0.6.0"
1717

1818
[dependencies.bevy_rapier3d]
19-
version="0.9.0"
19+
version="0.12.0"

blender_bevy_toolkit/core_definitions/mesh.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ def serialize_mesh(obj):
7676
if mesh.uv_layers:
7777

7878
uv_raw = mesh.uv_layers[0].data[loop_index].uv
79-
uv = (uv_raw[0], uv_raw[1], 0.0)
79+
uv = (uv_raw[0], uv_raw[1])
8080
else:
81-
uv = (0.0, 0.0, 0.0)
81+
uv = (0.0, 0.0)
8282

8383
dedup = (position, normal, uv)
8484
if dedup not in dedup_data_lookup:
@@ -112,7 +112,7 @@ def serialize_mesh(obj):
112112
for normal in normals:
113113
out_data += struct.pack("fff", *normal)
114114
for uv in uv0:
115-
out_data += struct.pack("fff", *uv)
115+
out_data += struct.pack("ff", *uv)
116116
for index in indices:
117117
out_data += struct.pack("III", *index)
118118

blender_bevy_toolkit/rapier_definitions/rigid_body_description.json

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
{
88
"field": "body_status",
99
"type": "u8enum",
10-
"default": ["dynamic", "static", "kinematic"],
10+
"default": ["dynamic", "static", "kinematic (position)", "kinematic (velocity)"],
1111
"description": "Dynamic bodies respond to forces. Static bodies do not move. Kinematic bodies must be moved manually but internally track velocity so they push other dynamic bodies properly"
1212
},
1313
{
@@ -33,18 +33,6 @@
3333
"type": "bool",
3434
"default": false,
3535
"description": "allow this body to sleep when velocity is low - this increases performance"
36-
},
37-
{
38-
"field": "mass_extra",
39-
"type": "f32",
40-
"default": 0.0,
41-
"description": "mass of the body additional to the mass of the collision shapes"
42-
},
43-
{
44-
"field": "inertia_extra",
45-
"type": "vec3",
46-
"default": [0.0, 0.0, 0.0],
47-
"description": "inertia of the body additional to the mass of the collision shapes"
4836
}
4937
]
5038
}

examples/scenes/main.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
//! This example loads the various test scenes
22
use bevy::prelude::*;
3-
use bevy_rapier3d::physics::RapierPhysicsPlugin;
3+
use bevy_rapier3d::physics::{NoUserData, RapierPhysicsPlugin};
4+
use bevy_rapier3d::prelude::*;
45
use blender_bevy_toolkit::BlendLoadPlugin;
56

7+
68
fn spawn_scene(
79
mut commands: Commands,
810
asset_server: Res<AssetServer>,
@@ -18,7 +20,7 @@ fn spawn_scene(
1820
});
1921

2022
// Create a Light
21-
commands.spawn().insert_bundle(LightBundle {
23+
commands.spawn().insert_bundle(PointLightBundle {
2224
transform: Transform::from_translation(Vec3::new(0.0, 8.0, 0.0)),
2325
..Default::default()
2426
});
@@ -27,13 +29,21 @@ fn spawn_scene(
2729
scene_spawner.spawn_dynamic(scene_handle);
2830
}
2931

32+
33+
fn setup_physics(mut physics_config: ResMut<RapierConfiguration>) {
34+
physics_config.gravity.y = 0.0;
35+
physics_config.gravity.z = -9.8;
36+
}
37+
38+
3039
fn main() {
3140
println!("Running example scenes");
32-
33-
App::build()
41+
42+
App::new()
3443
.add_plugins(DefaultPlugins)
35-
.add_plugin(RapierPhysicsPlugin)
44+
.add_plugin(RapierPhysicsPlugin::<NoUserData>::default())
3645
.add_plugin(BlendLoadPlugin::default())
3746
.add_startup_system(spawn_scene.system())
47+
.add_system(setup_physics.system())
3848
.run();
3949
}

src/blend_collection.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use bevy::prelude::*;
22

33
/// This component loads another collection and spawns it as a child
44
/// of the entity with this component
5-
#[derive(Reflect, Default)]
5+
#[derive(Reflect, Default, Component)]
66
#[reflect(Component)]
77
pub struct BlendCollectionLoader {
88
path: String,

src/blend_label.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use bevy::prelude::*;
22

33
/// Component that contains the name of the object
4-
#[derive(Reflect, Default)]
4+
#[derive(Reflect, Default, Component, Debug)]
55
#[reflect(Component)]
66
pub struct BlendLabel {
77
pub name: String,

src/blend_mesh.rs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
use bevy::{
22
asset::{AssetLoader, LoadContext},
33
prelude::*,
4-
render::{mesh::Indices, pipeline::PrimitiveTopology},
4+
render::{mesh::Indices, render_resource::PrimitiveTopology},
55
utils::BoxedFuture,
66
};
77
use std::convert::TryInto;
88

9-
#[derive(Reflect, Default)]
9+
#[derive(Reflect, Default, Component)]
1010
#[reflect(Component)] // this tells the reflect derive to also reflect component behaviors
1111
pub struct BlendMeshLoader {
1212
path: String,
1313
}
1414

1515
type FVec3Arr = Vec<[f32; 3]>;
16+
type FVec2Arr = Vec<[f32; 2]>;
1617

1718
pub fn blend_mesh_loader(
1819
mut commands: Commands,
@@ -40,10 +41,8 @@ pub fn blend_mesh_loader(
4041
commands.entity(entity).insert_bundle((
4142
bundle.mesh,
4243
bundle.material,
43-
bundle.main_pass,
44-
bundle.draw,
45-
bundle.visible,
46-
bundle.render_pipelines,
44+
bundle.visibility,
45+
bundle.computed_visibility,
4746
));
4847
}
4948
}
@@ -80,7 +79,6 @@ pub fn load_mesh(data: &[u8]) -> Mesh {
8079
mesh.set_attribute(Mesh::ATTRIBUTE_POSITION, positions);
8180
mesh.set_attribute(Mesh::ATTRIBUTE_NORMAL, normals);
8281
mesh.set_attribute(Mesh::ATTRIBUTE_UV_0, uv0s);
83-
8482
mesh
8583
}
8684

@@ -105,6 +103,17 @@ fn parse_vec3_array(data: &[u8], num_elements: usize) -> Vec<[f32; 3]> {
105103
}
106104
out_array
107105
}
106+
/// Converts a slice of u8's into a vec of f32;s
107+
fn parse_vec2_array(data: &[u8], num_elements: usize) -> Vec<[f32; 2]> {
108+
let mut out_array = Vec::with_capacity(num_elements);
109+
for i in 0..num_elements {
110+
out_array.push([
111+
get_f32(&data[i * 12..]),
112+
get_f32(&data[(i * 8 + 4)..]),
113+
]);
114+
}
115+
out_array
116+
}
108117
/// Converts a slice of u8's into a vec of u16's
109118
fn parse_u32_array(data: &[u8], num_elements: usize) -> Vec<u32> {
110119
let mut out_array = Vec::with_capacity(num_elements);
@@ -117,18 +126,18 @@ fn parse_u32_array(data: &[u8], num_elements: usize) -> Vec<u32> {
117126
/// Converts the bytes of a binary stl file into a vector of face indices,
118127
/// vertices and vertex normals.
119128
/// Expects correctly formatted STL files
120-
fn extact_buffers_from_mesh(mesh: &[u8]) -> (Vec<u32>, FVec3Arr, FVec3Arr, FVec3Arr) {
129+
fn extact_buffers_from_mesh(mesh: &[u8]) -> (Vec<u32>, FVec3Arr, FVec3Arr, FVec2Arr) {
121130
let num_verts = u16::from_le_bytes(mesh[0..2].try_into().unwrap()) as usize;
122131
let num_faces = u16::from_le_bytes(mesh[2..4].try_into().unwrap()) as usize;
123132

124133
let verts_start = 4;
125134
let normals_start = verts_start + num_verts * 4 * 3;
126135
let uv0_start = normals_start + num_verts * 4 * 3;
127-
let indices_start = uv0_start + num_verts * 4 * 3;
136+
let indices_start = uv0_start + num_verts * 4 * 2;
128137

129138
let positions = parse_vec3_array(&mesh[verts_start..], num_verts);
130139
let normals = parse_vec3_array(&mesh[normals_start..], num_verts);
131-
let uv0 = parse_vec3_array(&mesh[uv0_start..], num_verts);
140+
let uv0 = parse_vec2_array(&mesh[uv0_start..], num_verts);
132141
let indices = parse_u32_array(&mesh[indices_start..], num_faces * 3);
133142

134143
(indices, positions, normals, uv0)

src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@ impl BlendLoadPlugin {
1515
}
1616

1717
impl Plugin for BlendLoadPlugin {
18-
fn build(&self, app: &mut AppBuilder) {
18+
fn build(&self, app: &mut App) {
1919
app.register_type::<blend_label::BlendLabel>();
2020
app.register_type::<blend_collection::BlendCollectionLoader>();
2121
app.register_type::<blend_mesh::BlendMeshLoader>();
2222
app.register_type::<rapier_physics::RigidBodyDescription>();
2323
app.register_type::<rapier_physics::ColliderDescription>();
24-
2524
app.init_asset_loader::<blend_mesh::BlendMeshAssetLoader>();
2625

2726
app.add_system(blend_collection::blend_collection_loader.system());

0 commit comments

Comments
 (0)