building spawning update
Rust / build (push) Failing after 4s

This commit is contained in:
2026-03-18 15:15:11 -04:00
parent 8bf58bb04c
commit ebae1599f1
9 changed files with 160 additions and 120 deletions
+49 -28
View File
@@ -1,12 +1,13 @@
use bevy::{
ecs::system::{EntityCommand, EntityCommands},
ecs::{relationship::RelatedSpawnerCommands, system::EntityCommands},
gltf::{Gltf, GltfMesh},
math::{Quat, Vec3},
prelude::*,
};
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug)]
pub struct PrefabDefination {
pub struct PrefabDefination
{
pub path: String,
pub pos: Vec3,
pub rot: Vec3,
@@ -14,38 +15,54 @@ pub struct PrefabDefination {
pub animations: Option<Vec<AnimationComponent>>,
}
impl PrefabDefination {
pub fn spawn_recursive(&self, gltf: &Gltf, commands: &mut ChildBuilder, meshes: &Assets<GltfMesh>) {
impl PrefabDefination
{
pub fn spawn_recursive(
&self,
gltf: &Gltf,
commands: &mut RelatedSpawnerCommands<ChildOf>,
meshes: &Assets<GltfMesh>,
)
{
let mesh_handle = &gltf.named_meshes[&self.path.clone().into_boxed_str()];
if let Some(gltf_mesh) = meshes.get(mesh_handle.id()) {
let (m, mat) = gltf_mesh.unpack();
let mut entity = commands.spawn((
Mesh3d(m),
MeshMaterial3d(mat),
Transform::from_translation(self.pos).with_rotation(Quat::from_euler(
bevy::math::EulerRot::XYZ,
self.rot.x,
self.rot.y,
self.rot.z,
)),
));
if let Some(children) = &self.children {
entity.with_children(|b| {
for child in children {
child.spawn_recursive(gltf, b, meshes);
}
});
if let Some(primitive) = gltf_mesh.primitives.first() {
let mesh = primitive.mesh.clone();
let mat = primitive
.material
.clone()
.expect(format!("Mesh '{}' does not have a meterial", primitive.name.as_str()).as_str());
let mut entity = commands.spawn((
Mesh3d(mesh),
MeshMaterial3d(mat),
Transform::from_translation(self.pos).with_rotation(Quat::from_euler(
bevy::math::EulerRot::XYZ,
self.rot.x,
self.rot.y,
self.rot.z,
)),
));
if let Some(children) = &self.children {
entity.with_children(|b| {
for child in children {
child.spawn_recursive(gltf, b, meshes);
}
});
}
}
}
}
}
pub trait UnpackGltfMesh {
pub trait UnpackGltfMesh
{
fn unpack(&self) -> (Handle<Mesh>, Handle<StandardMaterial>);
}
impl UnpackGltfMesh for GltfMesh {
fn unpack(&self) -> (Handle<Mesh>, Handle<StandardMaterial>) {
impl UnpackGltfMesh for GltfMesh
{
fn unpack(&self) -> (Handle<Mesh>, Handle<StandardMaterial>)
{
let p = &self.primitives[0];
let mut mat: Handle<StandardMaterial> = default();
if let Some(mesh_material) = &p.material {
@@ -56,19 +73,23 @@ impl UnpackGltfMesh for GltfMesh {
}
#[derive(Serialize, Deserialize, Debug)]
pub enum AnimationComponent {
pub enum AnimationComponent
{
Rotation(RotationAnimation),
Slider,
}
#[derive(Serialize, Deserialize, Debug, Component, Clone, Copy)]
pub struct RotationAnimation {
pub struct RotationAnimation
{
pub axis: Vec3,
pub speed: f32,
}
impl AnimationComponent {
pub fn apply(&self, commands: &mut EntityCommands) {
impl AnimationComponent
{
pub fn apply(&self, commands: &mut EntityCommands)
{
match self {
AnimationComponent::Rotation(comp) => {
commands.insert(comp.clone());