Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ license = "MIT OR Apache-2.0"
readme = "README.md"

[dependencies]
bevy = { version = "0.15", features = [
bevy = { path = "../bevy", features = [
"file_watcher",
"bevy_picking",
"serialize",
Expand All @@ -19,9 +19,6 @@ serde = "1"
serde_json = "1"
anyhow = "1"

[dev-dependencies]
bevy-inspector-egui = "0.30.0"

[lints.clippy]
type_complexity = "allow"
doc_markdown = "warn"
Expand Down
Binary file added assets/models/AliciaSolid.vrm
Binary file not shown.
18 changes: 14 additions & 4 deletions examples/simple.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
use bevy::prelude::*;
use bevy_inspector_egui::quick::WorldInspectorPlugin;
/*use bevy_inspector_egui::quick::WorldInspectorPlugin;*/
use bevy_vrma::vrm::loader::VrmHandle;
use bevy_vrma::vrm::VrmPlugin;
use bevy_vrma::vrm::{VrmBone, VrmPlugin};

fn main() {
App::new()
.add_plugins((DefaultPlugins, WorldInspectorPlugin::default(), VrmPlugin))
.add_plugins((
DefaultPlugins,
/* WorldInspectorPlugin::default(), */ VrmPlugin,
))
.add_systems(Startup, (spawn_camera, spawn_vrm))
.add_systems(Update, bone_names)
.run();
}

Expand All @@ -18,5 +22,11 @@ fn spawn_vrm(
mut commands: Commands,
asset_server: Res<AssetServer>,
) {
commands.spawn(VrmHandle(asset_server.load("models/sample.vrm")));
commands.spawn(VrmHandle(asset_server.load("models/AliciaSolid2.vrm")));
}

fn bone_names(query: Query<&VrmBone>) {
for bone in query.iter() {
//println!("{}", bone.0);
}
}
2 changes: 1 addition & 1 deletion examples/vrma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ fn spawn_vrm(
};

commands
.spawn(VrmHandle(asset_server.load("models/sample.vrm")))
.spawn(VrmHandle(asset_server.load("models/AliciaSolid.vrm")))
.with_children(|cmd| {
vrma(1, cmd);
vrma(2, cmd);
Expand Down
11 changes: 9 additions & 2 deletions src/system_param/child_searcher.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::vrm::VrmBone;
use bevy::core::Name;
use bevy::ecs::system::SystemParam;
use bevy::prelude::{Children, Entity, Query};
use bevy::prelude::{Children, Entity, Name, Query};

#[derive(SystemParam)]
pub struct ChildSearcher<'w, 's> {
Expand All @@ -17,6 +16,14 @@ pub struct ChildSearcher<'w, 's> {
}

impl ChildSearcher<'_, '_> {
#[inline]
pub fn has_not_root_bone(
&self,
root: Entity,
) -> bool {
self.find_from_name(root, "Root").is_none()
}

pub fn find_from_name(
&self,
root: Entity,
Expand Down
5 changes: 2 additions & 3 deletions src/vrm/expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ use crate::vrm::extensions::VrmExtensions;
use crate::vrm::VrmExpression;
use bevy::app::Plugin;
use bevy::asset::{Assets, Handle};
use bevy::core::Name;
use bevy::gltf::GltfNode;
use bevy::prelude::{Component, Deref, Reflect};
use bevy::utils::HashMap;
use bevy::platform_support::collections::HashMap;
use bevy::prelude::{Component, Deref, Name, Reflect};

#[derive(Reflect, Debug, Clone)]
pub struct ExpressionNode {
Expand Down
10 changes: 8 additions & 2 deletions src/vrm/extensions/vrmc_spring_bone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ pub enum ColliderShape {
Capsule(Capsule),
}

impl Default for ColliderShape {
fn default() -> Self {
Self::Sphere(Sphere::default())
}
}

impl ColliderShape {
/// Returns the collision vector from the collider to the target position.
pub fn calc_collision(
Expand Down Expand Up @@ -129,7 +135,7 @@ impl ColliderShape {
}
}

#[derive(Serialize, Deserialize, Debug, Copy, Clone, PartialEq, Component, Reflect)]
#[derive(Serialize, Deserialize, Debug, Copy, Clone, PartialEq, Component, Reflect, Default)]
#[reflect(Component, Serialize, Deserialize)]
pub struct Sphere {
/// Local coordinate of the sphere center
Expand All @@ -139,7 +145,7 @@ pub struct Sphere {
}

/// 楕円形の
#[derive(Serialize, Deserialize, Debug, Copy, Clone, PartialEq, Component, Reflect)]
#[derive(Serialize, Deserialize, Debug, Copy, Clone, PartialEq, Component, Reflect, Default)]
#[reflect(Component, Serialize, Deserialize)]
pub struct Capsule {
/// Local coordinate of the center of the half sphere at the start point of the capsule
Expand Down
2 changes: 1 addition & 1 deletion src/vrm/extensions/vrmc_vrm.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::vrm::extensions::VrmNode;
use bevy::utils::HashMap;
use bevy::platform_support::collections::HashMap;
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize)]
Expand Down
12 changes: 7 additions & 5 deletions src/vrm/humanoid_bone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ use crate::vrm::extensions::VrmNode;
use crate::vrm::{BoneRestGlobalTransform, BoneRestTransform, VrmBone, VrmHipsBoneTo};
use bevy::app::{App, Plugin, Update};
use bevy::asset::{Assets, Handle};
use bevy::core::Name;
use bevy::gltf::GltfNode;
use bevy::hierarchy::Children;
use bevy::platform_support::collections::HashMap;
use bevy::prelude::*;
use bevy::utils::HashMap;
use serde::{Deserialize, Serialize};

#[derive(Component, Reflect, Debug, Clone, Eq, PartialEq, Hash, Serialize, Deserialize)]
Expand Down Expand Up @@ -60,9 +58,13 @@ fn attach_bones(
transforms: Query<(&Transform, &GlobalTransform)>,
) {
for (vrm_entity, humanoid_bones) in vrm.iter() {
if searcher.find_from_name(vrm_entity, "Root").is_none() {
/*if searcher.find_from_name(vrm_entity, "Root").is_none() &&
// for blender export names it Root_ instead of Root
searcher.find_from_name(vrm_entity, "Root_").is_none() &&
searcher.find_from_name(vrm_entity, "Armature_rootJoint").is_none() {
println!("NO BONES");
continue;
}
}*/

for (bone, name) in humanoid_bones.iter() {
let Some(bone_entity) = searcher.find_from_name(vrm_entity, name.as_str()) else {
Expand Down
9 changes: 6 additions & 3 deletions src/vrm/spawn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ use crate::vrm::spring_bone::registry::*;
use crate::vrm::{Vrm, VrmPath};
use bevy::app::{App, Update};
use bevy::asset::Assets;
use bevy::core::Name;
use bevy::gltf::GltfNode;
use bevy::log::error;
use bevy::prelude::{Commands, Entity, Plugin, Query, Res};
use bevy::prelude::{Commands, Entity, Name, Plugin, Query, Res};
use bevy::scene::SceneRoot;

pub struct VrmSpawnPlugin;
Expand Down Expand Up @@ -61,7 +60,11 @@ fn spawn_vrm(

if let Some(spring_bone) = extensions.vrmc_spring_bone.as_ref() {
cmd.insert((
SpringJointRegistry::new(&spring_bone.all_joints(), &node_assets, &vrm.gltf.nodes),
SpringJointPropsRegistry::new(
&spring_bone.all_joints(),
&node_assets,
&vrm.gltf.nodes,
),
SpringColliderRegistry::new(&spring_bone.colliders, &node_assets, &vrm.gltf.nodes),
SpringNodeRegistry::new(spring_bone, &node_assets, &vrm.gltf.nodes),
));
Expand Down
4 changes: 3 additions & 1 deletion src/vrm/spring_bone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ pub struct SpringRoot {

pub colliders: Vec<Entity>,

/// If the spring chain has a center node,
/// the inertia of the spring bone is evaluated in the [`Center Space`](https://github.com/vrm-c/vrm-specification/tree/master/specification/VRMC_springBone-1.0#center-space).
pub center_node: Option<Entity>,
}

#[derive(Component, Reflect, Debug, Serialize, Deserialize, Copy, Clone)]
#[derive(Component, Reflect, Debug, Serialize, Deserialize, Copy, Clone, Default)]
#[reflect(Component, Serialize, Deserialize)]
pub struct SpringJointProps {
pub drag_force: f32,
Expand Down
Loading