Skip to content
Merged
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
39 changes: 9 additions & 30 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,11 @@ winit = {version = "0.30.5", features = ["serde", "rwh_06"]}
bitflags = "2.4.1"
ash = "0.38.0"
ash-window = "0.13.0"
gltf = "1.4.0"
gltf = "1.4.1"
base64 = "0.22.0"
glam = { version = "0.27.0", features = ["bytemuck"] }
genmesh = "0.6.2"

[dev-dependencies]
#noise = { version = "0.8" }
#bytemuck = { version = "1.4", features = ["derive"] }

6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ cargo run --release
We are using GLSL shaders. There is no auto-compilation to SPV right now, so please use `glslc`:

```
glslc -fshader-stage=vertex src/models/shaders/non-rigged.vert.glsl -o src/models/shaders/non-rigged.vert.spv
glslc -fshader-stage=fragment src/models/shaders/non-rigged.frag.glsl -o src/models/shaders/non-rigged.frag.spv
glslc -fshader-stage=vertex src/models/shaders/only_mesh.vert.glsl -o src/models/shaders/only_mesh.vert.spv
glslc -fshader-stage=fragment src/models/shaders/only_mesh.frag.glsl -o src/models/shaders/only_mesh.frag.spv
glslc -fshader-stage=vertex src/models/shaders/skin_mesh.vert.glsl -o src/models/shaders/skin_mesh.vert.spv
glslc -fshader-stage=fragment src/models/shaders/skin_mesh.frag.glsl -o src/models/shaders/skin_mesh.frag.spv
```

## Sponsors
Expand Down
4 changes: 3 additions & 1 deletion src/graphics/vulkan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1920,7 +1920,9 @@ impl Buffer {
data: &[T],
) -> u64 {
let align = std::mem::align_of::<T>() as u64;
let size = (data.len() * std::mem::size_of_val(data)) as u64;
let size = (data.len() * std::mem::size_of::<T>()) as u64;

log::debug!("map buffer: align({:?}), size({})", align, size);

let memory_ptr = gpu
.map_memory(
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ pub mod math;
/// Models abstractions
pub mod models;
pub use models::{
Animation, Armature, Color, Image, Joint, Material, Mesh, Model, RenderModels, Transform,
VertexAttribute, VertexBitangent, VertexJoints, VertexNormal, VertexPosition, VertexTangent,
VertexTexture, VertexWeights,
Animation, AnimationPlayer, AnimationState, Armature, Color, Image, Joint, Material, Mesh,
Model, RenderModels, Transform, VertexAttribute, VertexBitangent, VertexJoints, VertexNormal,
VertexPosition, VertexTangent, VertexTexture, VertexWeights,
};

/// Rendering tools and routines
Expand Down
57 changes: 30 additions & 27 deletions src/loaders/gltf_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::log;
use crate::math::{Mat4, Quat, Vec3};
use crate::models::{
Animation, Armature, Color, Image, ImageFormat, Interpolation, Joint, Material, Mesh,
Transform, VertexJoints, VertexNormal, VertexPosition, VertexTexture, VertexWeights,
Transform3D, VertexJoints, VertexNormal, VertexPosition, VertexTexture, VertexWeights,
};
use crate::utils::Id;

Expand Down Expand Up @@ -236,7 +236,7 @@ impl GltfLoader {
let id = Id::new();

let (translation, rotation, scale) = node.transform().decomposed();
let local_bind_transform = Transform::new(
let local_bind_transform = Transform3D::new(
Vec3::from(translation),
// Quat::new(rotation[3], rotation[0], rotation[1], rotation[2]),
Quat::from_xyzw(rotation[0], rotation[1], rotation[2], rotation[3]),
Expand Down Expand Up @@ -450,36 +450,39 @@ impl GltfLoader {
let reader = channel.reader(|buffer| Some(&buffers[buffer.index()]));
let outputs = reader.read_outputs();
let timestamps = reader.read_inputs().unwrap().collect::<Vec<f32>>();
let joint_id = output
.loaded_joints
.get(&index)
.cloned()
.expect("Animation target joint does not exist");

match outputs.unwrap() {
gltf::animation::util::ReadOutputs::Translations(out) => asset
.add_translation_channel(
if let Some(joint_id) = output.loaded_joints.get(&index).cloned() {
match outputs.unwrap() {
gltf::animation::util::ReadOutputs::Translations(out) => asset
.add_translation_channel(
joint_id,
interpolation,
timestamps,
out.map(Vec3::from).collect(),
),
gltf::animation::util::ReadOutputs::Rotations(out) => asset
.add_rotation_channel(
joint_id,
interpolation,
timestamps,
out.into_f32()
.map(|q| Quat::from_xyzw(q[0], q[1], q[2], q[3]))
.collect(),
),
gltf::animation::util::ReadOutputs::Scales(out) => asset.add_scale_channel(
joint_id,
interpolation,
timestamps,
out.map(Vec3::from).collect(),
),
gltf::animation::util::ReadOutputs::Rotations(out) => asset.add_rotation_channel(
joint_id,
interpolation,
timestamps,
out.into_f32()
.map(|q| Quat::from_xyzw(q[0], q[1], q[2], q[3]))
.collect(),
),
gltf::animation::util::ReadOutputs::Scales(out) => asset.add_scale_channel(
joint_id,
interpolation,
timestamps,
out.map(Vec3::from).collect(),
),
gltf::animation::util::ReadOutputs::MorphTargetWeights(ref _weights) => (),
};
gltf::animation::util::ReadOutputs::MorphTargetWeights(ref _weights) => (),
};
} else {
log::warn!(
"Animation {} refers target joint ({}), that does not exist",
asset.name(),
index
);
}
}

output.result.push(Box::new(asset));
Expand Down
26 changes: 20 additions & 6 deletions src/models.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mod animations;
pub use animations::{Animation, Interpolation};
pub use animations::{Animation, AnimationPlayer, AnimationState, Interpolation};

mod armatures;
pub use armatures::{Armature, Joint};
Expand All @@ -22,15 +22,15 @@ mod renderer;
pub use renderer::{RenderModels, RenderModelsSetup};

mod transforms;
pub use transforms::{Transform, TransformBuilder};
pub use transforms::{Transform, Transform3D, TransformBuilder};

mod vertices;
pub use vertices::{
VertexAttribute, VertexBitangent, VertexJoints, VertexNormal, VertexPosition, VertexTangent,
VertexTexture, VertexWeights,
};

use crate::math::{Quat, Vec3};
use crate::math::{Mat4, Quat, Vec3};
use crate::utils::Id;
use crate::world::Entity;

Expand All @@ -41,16 +41,28 @@ pub struct Model {
pub translate: Vec3,
pub scale: Vec3,
pub rotate: Quat,
pub pose: Vec<Mat4>,
pub animation: Option<AnimationPlayer>,
}

impl From<Model> for Entity {
fn from(model: Model) -> Self {
Entity::new((
let animation = model.animation;
let mut entity = Entity::new((
model.mesh,
model.material,
model.armature,
Transform::new(model.translate, model.rotate, model.scale),
))
Transform::new(
Transform3D::new(model.translate, model.rotate, model.scale),
model.pose,
),
));

if let Some(player) = animation {
entity = entity.with(player);
}

entity
}
}

Expand All @@ -63,6 +75,8 @@ impl Default for Model {
translate: Vec3::new(0.0, 0.0, 0.0),
scale: Vec3::new(1.0, 1.0, 1.0),
rotate: Quat::IDENTITY,
pose: Vec::new(),
animation: None,
}
}
}
Loading
Loading