Compare commits
No commits in common. "a17c035c05238c696c127d1d0976150721309891" and "e5018c8258ca2cc94c4c914a25f76a5b50adcf52" have entirely different histories.
a17c035c05
...
e5018c8258
|
@ -330,12 +330,6 @@ version = "1.1.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0"
|
checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "atomic_refcell"
|
|
||||||
version = "0.1.13"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "41e67cd8309bbd06cd603a9e693a784ac2e5d1e955f11286e355089fcab3047c"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "autocfg"
|
name = "autocfg"
|
||||||
version = "1.1.0"
|
version = "1.1.0"
|
||||||
|
@ -714,9 +708,12 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "crossbeam-utils"
|
name = "crossbeam-utils"
|
||||||
version = "0.8.19"
|
version = "0.8.18"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345"
|
checksum = "c3a430a770ebd84726f584a90ee7f020d28db52c6d02138900f22341f866d39c"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "crunchy"
|
name = "crunchy"
|
||||||
|
@ -1752,7 +1749,6 @@ name = "lyra-ecs"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"atomic_refcell",
|
|
||||||
"lyra-ecs-derive",
|
"lyra-ecs-derive",
|
||||||
"lyra-math",
|
"lyra-math",
|
||||||
"paste",
|
"paste",
|
||||||
|
@ -1848,7 +1844,6 @@ dependencies = [
|
||||||
"lyra-ecs",
|
"lyra-ecs",
|
||||||
"lyra-math",
|
"lyra-math",
|
||||||
"lyra-reflect",
|
"lyra-reflect",
|
||||||
"lyra-scene",
|
|
||||||
"mime",
|
"mime",
|
||||||
"notify",
|
"notify",
|
||||||
"notify-debouncer-full",
|
"notify-debouncer-full",
|
||||||
|
|
|
@ -17,24 +17,6 @@ pub trait Bundle {
|
||||||
fn is_dynamic(&self) -> bool;
|
fn is_dynamic(&self) -> bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Bundle for () {
|
|
||||||
fn type_ids(&self) -> Vec<DynTypeId> {
|
|
||||||
vec![DynTypeId::of::<()>()]
|
|
||||||
}
|
|
||||||
|
|
||||||
fn info(&self) -> Vec<ComponentInfo> {
|
|
||||||
vec![ComponentInfo::new::<()>()]
|
|
||||||
}
|
|
||||||
|
|
||||||
fn take(self, mut f: impl FnMut(NonNull<u8>, DynTypeId, usize)) {
|
|
||||||
f(NonNull::from(&self).cast(), DynTypeId::of::<()>(), size_of::<()>());
|
|
||||||
}
|
|
||||||
|
|
||||||
fn is_dynamic(&self) -> bool {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<C: Component> Bundle for C {
|
impl<C: Component> Bundle for C {
|
||||||
fn type_ids(&self) -> Vec<DynTypeId> {
|
fn type_ids(&self) -> Vec<DynTypeId> {
|
||||||
vec![DynTypeId::of::<C>()]
|
vec![DynTypeId::of::<C>()]
|
||||||
|
|
|
@ -367,8 +367,8 @@ impl World {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Ensure that all non-send resources are only accessible on the main thread.
|
// TODO: Ensure that all non-send resources are only accessible on the main thread.
|
||||||
unsafe impl Send for World {}
|
/* unsafe impl Send for World {}
|
||||||
unsafe impl Sync for World {}
|
unsafe impl Sync for World {} */
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
|
@ -32,7 +32,7 @@ impl From<&Variant> for VariantType {
|
||||||
|
|
||||||
/// Generates the following different outputs:
|
/// Generates the following different outputs:
|
||||||
///
|
///
|
||||||
/// ```nobuild
|
/// ```compile_fail
|
||||||
/// // for struct variants
|
/// // for struct variants
|
||||||
/// TestEnum::Error { msg, code }
|
/// TestEnum::Error { msg, code }
|
||||||
///
|
///
|
||||||
|
@ -98,7 +98,7 @@ fn gen_variant_if(enum_id: &proc_macro2::Ident, variant: &Variant, if_body: proc
|
||||||
|
|
||||||
/// Generates the following:
|
/// Generates the following:
|
||||||
///
|
///
|
||||||
/// ```nobuild
|
/// ```compile_fail
|
||||||
/// /// generated one field here
|
/// /// generated one field here
|
||||||
/// if name == "msg" {
|
/// if name == "msg" {
|
||||||
/// return Some(msg);
|
/// return Some(msg);
|
||||||
|
@ -129,7 +129,7 @@ fn gen_if_field_names(variant: &Variant) -> proc_macro2::TokenStream {
|
||||||
|
|
||||||
/// Generates the following rust code:
|
/// Generates the following rust code:
|
||||||
///
|
///
|
||||||
/// ```nobuild
|
/// ```compile_fail
|
||||||
/// match name {
|
/// match name {
|
||||||
/// "msg" | "code" => true,
|
/// "msg" | "code" => true,
|
||||||
/// _ => false,
|
/// _ => false,
|
||||||
|
@ -153,7 +153,7 @@ fn gen_match_names(variant: &Variant) -> proc_macro2::TokenStream {
|
||||||
|
|
||||||
/// Generates the following:
|
/// Generates the following:
|
||||||
///
|
///
|
||||||
/// ```nobuild
|
/// ```compile_fail
|
||||||
/// /// generated one field here
|
/// /// generated one field here
|
||||||
/// if idx == 0 {
|
/// if idx == 0 {
|
||||||
/// return Some(a);
|
/// return Some(a);
|
||||||
|
@ -190,7 +190,7 @@ fn gen_if_field_indices(variant: &Variant) -> proc_macro2::TokenStream {
|
||||||
|
|
||||||
/// Generates the following:
|
/// Generates the following:
|
||||||
///
|
///
|
||||||
/// ```nobuild
|
/// ```compile_fail
|
||||||
/// /// generated one field here
|
/// /// generated one field here
|
||||||
/// if idx == 0 {
|
/// if idx == 0 {
|
||||||
/// return Some("a");
|
/// return Some("a");
|
||||||
|
@ -226,7 +226,7 @@ fn gen_if_field_indices_names(variant: &Variant) -> proc_macro2::TokenStream {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Generates the following:
|
/// Generates the following:
|
||||||
/// ```nobuild
|
/// ```compile_fail
|
||||||
/// /// when `by_index` is false:
|
/// /// when `by_index` is false:
|
||||||
///
|
///
|
||||||
/// if let TestEnum::Error{ msg, code} = self {
|
/// if let TestEnum::Error{ msg, code} = self {
|
||||||
|
@ -300,7 +300,7 @@ fn gen_enum_if_stmts(enum_id: &proc_macro2::Ident, data: &DataEnum, by_index: bo
|
||||||
|
|
||||||
/// Generates the following rust code:
|
/// Generates the following rust code:
|
||||||
///
|
///
|
||||||
/// ```nobuild
|
/// ```compile_fail
|
||||||
/// if let TestEnum::Error { msg, code } = self {
|
/// if let TestEnum::Error { msg, code } = self {
|
||||||
/// return match name {
|
/// return match name {
|
||||||
/// // expands for continuing struct fields
|
/// // expands for continuing struct fields
|
||||||
|
@ -331,7 +331,7 @@ fn gen_enum_has_field(enum_id: &proc_macro2::Ident, data: &DataEnum) -> proc_mac
|
||||||
|
|
||||||
/// Generates the following code:
|
/// Generates the following code:
|
||||||
///
|
///
|
||||||
/// ```nobuild
|
/// ```compile_fail
|
||||||
/// match self {
|
/// match self {
|
||||||
/// TestEnum::Start => 0,
|
/// TestEnum::Start => 0,
|
||||||
/// TestEnum::Middle(a, b) => 2,
|
/// TestEnum::Middle(a, b) => 2,
|
||||||
|
@ -358,7 +358,7 @@ fn gen_enum_fields_len(enum_id: &proc_macro2::Ident, data: &DataEnum) -> proc_ma
|
||||||
|
|
||||||
/// Generates the following code:
|
/// Generates the following code:
|
||||||
///
|
///
|
||||||
/// ```nobuild
|
/// ```compile_fail
|
||||||
/// if let TestEnum::Error { msg, code } = self {
|
/// if let TestEnum::Error { msg, code } = self {
|
||||||
/// if idx == 0 {
|
/// if idx == 0 {
|
||||||
/// return Some("msg");
|
/// return Some("msg");
|
||||||
|
@ -389,7 +389,7 @@ fn gen_enum_field_name_at(enum_id: &proc_macro2::Ident, data: &DataEnum) -> proc
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Generates the following code:
|
/// Generates the following code:
|
||||||
/// ```nobuild
|
/// ```compile_fail
|
||||||
/// match self {
|
/// match self {
|
||||||
/// TestEnum::Start => 0,
|
/// TestEnum::Start => 0,
|
||||||
/// TestEnum::Middle(a, b) => 1,
|
/// TestEnum::Middle(a, b) => 1,
|
||||||
|
@ -427,7 +427,7 @@ fn gen_enum_variant_name(enum_id: &proc_macro2::Ident, data: &DataEnum, gen_inde
|
||||||
/// Generates a match statement that returns the types of the variants of the enum.
|
/// Generates a match statement that returns the types of the variants of the enum.
|
||||||
///
|
///
|
||||||
/// Example:
|
/// Example:
|
||||||
/// ```nobuild
|
/// ```compile_fail
|
||||||
/// match self {
|
/// match self {
|
||||||
/// TestEnum::Start => EnumType::Unit,
|
/// TestEnum::Start => EnumType::Unit,
|
||||||
/// TestEnum::Middle(a, b) => EnumType::Tuple,
|
/// TestEnum::Middle(a, b) => EnumType::Tuple,
|
||||||
|
|
|
@ -28,7 +28,7 @@ impl StructType {
|
||||||
/// contains a borrow (mutable borrow if `is_mut` is true) to the matching struct field.
|
/// contains a borrow (mutable borrow if `is_mut` is true) to the matching struct field.
|
||||||
///
|
///
|
||||||
/// Example:
|
/// Example:
|
||||||
/// ```nobuild
|
/// ```compile_fail
|
||||||
/// // when `is_mut` = false
|
/// // when `is_mut` = false
|
||||||
/// match name {
|
/// match name {
|
||||||
/// "x" => Some(&self.x),
|
/// "x" => Some(&self.x),
|
||||||
|
@ -85,7 +85,7 @@ fn gen_struct_field_match(data: &DataStruct, is_mut: bool) -> proc_macro2::Token
|
||||||
/// with the provided `val`.
|
/// with the provided `val`.
|
||||||
///
|
///
|
||||||
/// Example:
|
/// Example:
|
||||||
/// ```nobuild
|
/// ```compile_fail
|
||||||
/// match name {
|
/// match name {
|
||||||
/// "x" => self.x = any_val.downcast_ref::<f32>()
|
/// "x" => self.x = any_val.downcast_ref::<f32>()
|
||||||
/// .expect(&format!("Cannot set struct's field of {} type to the provided type of {}", "f32", val.name()))
|
/// .expect(&format!("Cannot set struct's field of {} type to the provided type of {}", "f32", val.name()))
|
||||||
|
@ -140,7 +140,7 @@ fn gen_struct_set_field_match(data: &DataStruct) -> proc_macro2::TokenStream {
|
||||||
/// the type of the field.
|
/// the type of the field.
|
||||||
///
|
///
|
||||||
/// Example:
|
/// Example:
|
||||||
/// ```nobuild
|
/// ```compile_fail
|
||||||
/// match name {
|
/// match name {
|
||||||
/// "x" => Some("f32"),
|
/// "x" => Some("f32"),
|
||||||
/// "y" => Some("f32"),
|
/// "y" => Some("f32"),
|
||||||
|
@ -177,7 +177,7 @@ fn gen_struct_field_name_match(data: &DataStruct) -> proc_macro2::TokenStream {
|
||||||
/// with the provided `val`.
|
/// with the provided `val`.
|
||||||
///
|
///
|
||||||
/// Example:
|
/// Example:
|
||||||
/// ```nobuild
|
/// ```compile_fail
|
||||||
/// match name {
|
/// match name {
|
||||||
/// 0 => self.x = any_val.downcast_ref::<f32>()
|
/// 0 => self.x = any_val.downcast_ref::<f32>()
|
||||||
/// .expect(&format!("Cannot set struct's field of {} type to the provided type of {}", "f32", val.name()))
|
/// .expect(&format!("Cannot set struct's field of {} type to the provided type of {}", "f32", val.name()))
|
||||||
|
@ -243,7 +243,7 @@ fn gen_struct_set_field_match_idx(data: &DataStruct) -> proc_macro2::TokenStream
|
||||||
/// type of the field.
|
/// type of the field.
|
||||||
///
|
///
|
||||||
/// Example:
|
/// Example:
|
||||||
/// ```nobuild
|
/// ```compile_fail
|
||||||
/// match name {
|
/// match name {
|
||||||
/// 0 => Some("f32"),
|
/// 0 => Some("f32"),
|
||||||
/// 1 => Some("f32"),
|
/// 1 => Some("f32"),
|
||||||
|
@ -274,7 +274,7 @@ fn gen_struct_field_name_match_idx(data: &DataStruct) -> proc_macro2::TokenStrea
|
||||||
/// to the matching struct field.
|
/// to the matching struct field.
|
||||||
///
|
///
|
||||||
/// Example:
|
/// Example:
|
||||||
/// ```nobuild
|
/// ```compile_fail
|
||||||
/// // when `is_mut` = false
|
/// // when `is_mut` = false
|
||||||
/// match idx {
|
/// match idx {
|
||||||
/// 0 => Some(&self.x),
|
/// 0 => Some(&self.x),
|
||||||
|
@ -335,7 +335,7 @@ fn gen_struct_field_match_idx(data: &DataStruct, is_mut: bool) -> proc_macro2::T
|
||||||
/// and returns an Option that contains the name of the field.
|
/// and returns an Option that contains the name of the field.
|
||||||
///
|
///
|
||||||
/// Example:
|
/// Example:
|
||||||
/// ```nobuild
|
/// ```compile_fail
|
||||||
/// match idx {
|
/// match idx {
|
||||||
/// 0 => Some("x"),
|
/// 0 => Some("x"),
|
||||||
/// 1 => Some("y"),
|
/// 1 => Some("y"),
|
||||||
|
|
|
@ -9,7 +9,6 @@ edition = "2021"
|
||||||
lyra-ecs = { path = "../lyra-ecs", features = [ "math" ] }
|
lyra-ecs = { path = "../lyra-ecs", features = [ "math" ] }
|
||||||
lyra-reflect = { path = "../lyra-reflect" }
|
lyra-reflect = { path = "../lyra-reflect" }
|
||||||
lyra-math = { path = "../lyra-math" }
|
lyra-math = { path = "../lyra-math" }
|
||||||
lyra-scene = { path = "../lyra-scene" }
|
|
||||||
anyhow = "1.0.75"
|
anyhow = "1.0.75"
|
||||||
base64 = "0.21.4"
|
base64 = "0.21.4"
|
||||||
crossbeam = { version = "0.8.4", features = [ "crossbeam-channel" ] }
|
crossbeam = { version = "0.8.4", features = [ "crossbeam-channel" ] }
|
||||||
|
|
|
@ -3,10 +3,9 @@ use std::{ffi::OsStr, path::{Path, PathBuf}, sync::Arc};
|
||||||
use glam::{Quat, Vec3};
|
use glam::{Quat, Vec3};
|
||||||
use instant::Instant;
|
use instant::Instant;
|
||||||
use lyra_math::Transform;
|
use lyra_math::Transform;
|
||||||
use lyra_scene::{SceneGraph, SceneNode};
|
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
use crate::{loader::{LoaderError, PinedBoxLoaderFuture, ResourceLoader}, util, ResHandle, ResourceData, ResourceManager, ResourceStorage};
|
use crate::{gltf::GltfScene, loader::{LoaderError, PinedBoxLoaderFuture, ResourceLoader}, util, ResHandle, ResourceData, ResourceManager, ResourceStorage};
|
||||||
use super::{Gltf, GltfNode, Material, Mesh, MeshIndices, MeshVertexAttribute, VertexAttributeData};
|
use super::{Gltf, GltfNode, Material, Mesh, MeshIndices, MeshVertexAttribute, VertexAttributeData};
|
||||||
|
|
||||||
use tracing::debug;
|
use tracing::debug;
|
||||||
|
@ -65,7 +64,7 @@ impl ModelLoader {
|
||||||
}
|
}
|
||||||
} */
|
} */
|
||||||
|
|
||||||
fn process_node(ctx: &mut GltfLoadContext, materials: &Vec<ResHandle<Material>>, scene: &mut SceneGraph, scene_parent: &SceneNode, gnode: gltf::Node<'_>) -> GltfNode {
|
fn process_node(ctx: &mut GltfLoadContext, materials: &Vec<ResHandle<Material>>, gnode: gltf::Node<'_>) -> GltfNode {
|
||||||
let mut node = GltfNode::default();
|
let mut node = GltfNode::default();
|
||||||
|
|
||||||
node.transform = {
|
node.transform = {
|
||||||
|
@ -76,8 +75,6 @@ impl ModelLoader {
|
||||||
};
|
};
|
||||||
node.name = gnode.name().map(str::to_string);
|
node.name = gnode.name().map(str::to_string);
|
||||||
|
|
||||||
let scene_node = scene.add_node_under(scene_parent, node.transform, ());
|
|
||||||
|
|
||||||
if let Some(mesh) = gnode.mesh() {
|
if let Some(mesh) = gnode.mesh() {
|
||||||
let mut new_mesh = Mesh::default();
|
let mut new_mesh = Mesh::default();
|
||||||
|
|
||||||
|
@ -130,12 +127,11 @@ impl ModelLoader {
|
||||||
|
|
||||||
let handle = ResHandle::new_ready(None, new_mesh);
|
let handle = ResHandle::new_ready(None, new_mesh);
|
||||||
ctx.resource_manager.store_uuid(handle.clone());
|
ctx.resource_manager.store_uuid(handle.clone());
|
||||||
node.mesh = Some(handle.clone());
|
node.mesh = Some(handle);
|
||||||
scene.insert(&scene_node, handle);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for child in gnode.children() {
|
for child in gnode.children() {
|
||||||
let cmesh = ModelLoader::process_node(ctx, materials, scene, &scene_node, child);
|
let cmesh = ModelLoader::process_node(ctx, materials, child);
|
||||||
node.children.push(cmesh);
|
node.children.push(cmesh);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -214,21 +210,7 @@ impl ResourceLoader for ModelLoader {
|
||||||
debug!("Loaded {} materials in {}s", materials.len(), mat_time.as_secs_f32());
|
debug!("Loaded {} materials in {}s", materials.len(), mat_time.as_secs_f32());
|
||||||
|
|
||||||
for (_idx, scene) in gltf.scenes().enumerate() {
|
for (_idx, scene) in gltf.scenes().enumerate() {
|
||||||
let mut graph = SceneGraph::new();
|
let start_inst = Instant::now();
|
||||||
let root_node = graph.root_node();
|
|
||||||
|
|
||||||
for node in scene.nodes() {
|
|
||||||
let n = ModelLoader::process_node(&mut context, &materials, &mut graph, &root_node, node);
|
|
||||||
|
|
||||||
if let Some(mesh) = n.mesh {
|
|
||||||
gltf_out.meshes.push(mesh.clone());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let graph = ResHandle::new_ready(Some(path.as_str()), graph);
|
|
||||||
gltf_out.scenes.push(graph);
|
|
||||||
|
|
||||||
/* let start_inst = Instant::now();
|
|
||||||
let nodes: Vec<GltfNode> = scene.nodes()
|
let nodes: Vec<GltfNode> = scene.nodes()
|
||||||
.map(|node| ModelLoader::process_node(&mut context, &materials, node))
|
.map(|node| ModelLoader::process_node(&mut context, &materials, node))
|
||||||
.collect();
|
.collect();
|
||||||
|
@ -246,7 +228,7 @@ impl ResourceLoader for ModelLoader {
|
||||||
nodes,
|
nodes,
|
||||||
};
|
};
|
||||||
let scene = ResHandle::new_ready(Some(path.as_str()), scene);
|
let scene = ResHandle::new_ready(Some(path.as_str()), scene);
|
||||||
gltf_out.scenes.push(scene); */
|
gltf_out.scenes.push(scene);
|
||||||
}
|
}
|
||||||
|
|
||||||
gltf_out.materials = materials;
|
gltf_out.materials = materials;
|
||||||
|
@ -267,8 +249,6 @@ impl ResourceLoader for ModelLoader {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use lyra_ecs::{query::Entities, relation::ChildOf};
|
|
||||||
|
|
||||||
use crate::tests::busy_wait_resource;
|
use crate::tests::busy_wait_resource;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@ -292,30 +272,14 @@ mod tests {
|
||||||
let scene = &gltf.scenes[0]
|
let scene = &gltf.scenes[0]
|
||||||
.data_ref().unwrap();
|
.data_ref().unwrap();
|
||||||
|
|
||||||
let mut node = None;
|
assert_eq!(scene.nodes.len(), 1);
|
||||||
scene.traverse_down(|no, _tran| {
|
let mnode = &scene.nodes[0];
|
||||||
node = Some(no.clone());
|
|
||||||
});
|
|
||||||
|
|
||||||
let world = scene.world();
|
assert!(mnode.mesh.is_some());
|
||||||
let node = node.unwrap();
|
assert_eq!(mnode.transform, Transform::from_xyz(0.0, 0.0, 0.0));
|
||||||
|
assert_eq!(mnode.children.len(), 0);
|
||||||
|
|
||||||
let data = world.view_one::<(&ResHandle<Mesh>, &Transform)>(node.entity()).get();
|
let mesh = mnode.mesh.as_ref().unwrap();
|
||||||
debug_assert!(data.is_some(), "The mesh was not loaded"); // transform will always be there
|
|
||||||
let data = data.unwrap();
|
|
||||||
|
|
||||||
// ensure there are no children of the node
|
|
||||||
assert_eq!(
|
|
||||||
world.view::<Entities>()
|
|
||||||
.relates_to::<ChildOf>(node.entity())
|
|
||||||
.into_iter()
|
|
||||||
.count(),
|
|
||||||
0
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(*data.1, Transform::from_xyz(0.0, 0.0, 0.0));
|
|
||||||
|
|
||||||
let mesh = data.0;
|
|
||||||
let mesh = mesh.data_ref().unwrap();
|
let mesh = mesh.data_ref().unwrap();
|
||||||
assert!(mesh.position().unwrap().len() > 0);
|
assert!(mesh.position().unwrap().len() > 0);
|
||||||
assert!(mesh.normals().unwrap().len() > 0);
|
assert!(mesh.normals().unwrap().len() > 0);
|
||||||
|
|
|
@ -3,7 +3,6 @@ pub use loader::*;
|
||||||
|
|
||||||
pub mod material;
|
pub mod material;
|
||||||
use lyra_math::Transform;
|
use lyra_math::Transform;
|
||||||
use lyra_scene::SceneGraph;
|
|
||||||
use crate::ResourceData;
|
use crate::ResourceData;
|
||||||
pub use material::*;
|
pub use material::*;
|
||||||
|
|
||||||
|
@ -18,7 +17,7 @@ use crate::ResHandle;
|
||||||
/// A loaded Gltf file
|
/// A loaded Gltf file
|
||||||
#[derive(Clone, Default)]
|
#[derive(Clone, Default)]
|
||||||
pub struct Gltf {
|
pub struct Gltf {
|
||||||
pub scenes: Vec<ResHandle<SceneGraph>>,
|
pub scenes: Vec<ResHandle<GltfScene>>,
|
||||||
pub materials: Vec<ResHandle<Material>>,
|
pub materials: Vec<ResHandle<Material>>,
|
||||||
pub meshes: Vec<ResHandle<Mesh>>,
|
pub meshes: Vec<ResHandle<Mesh>>,
|
||||||
}
|
}
|
||||||
|
@ -56,6 +55,14 @@ impl ResourceData for Gltf {
|
||||||
impl Gltf {
|
impl Gltf {
|
||||||
/// Collects all Gltf meshes and gets their world Transform.
|
/// Collects all Gltf meshes and gets their world Transform.
|
||||||
pub fn collect_world_meshes(&self) -> Vec<(ResHandle<Mesh>, Transform)> {
|
pub fn collect_world_meshes(&self) -> Vec<(ResHandle<Mesh>, Transform)> {
|
||||||
todo!()
|
let mut v = vec![];
|
||||||
|
|
||||||
|
for scene in self.scenes.iter() {
|
||||||
|
let mut tmp = scene.data_ref()
|
||||||
|
.unwrap().collect_world_meshes();
|
||||||
|
v.append(&mut tmp);
|
||||||
|
}
|
||||||
|
|
||||||
|
v
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,5 +1,4 @@
|
||||||
use lyra_math::Transform;
|
use lyra_math::Transform;
|
||||||
use lyra_scene::SceneGraph;
|
|
||||||
use crate::{optionally_add_to_dep, ResourceData, UntypedResHandle};
|
use crate::{optionally_add_to_dep, ResourceData, UntypedResHandle};
|
||||||
|
|
||||||
use super::Mesh;
|
use super::Mesh;
|
||||||
|
@ -34,8 +33,8 @@ impl ResourceData for GltfNode {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// A Scene in a Gltf file
|
/// A Scene in a Gltf file
|
||||||
/* #[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct GltfScene {
|
pub struct GltfScene {
|
||||||
pub nodes: Vec<GltfNode>,
|
pub nodes: Vec<GltfNode>,
|
||||||
}
|
}
|
||||||
|
@ -93,18 +92,4 @@ impl GltfScene {
|
||||||
|
|
||||||
v
|
v
|
||||||
}
|
}
|
||||||
} */
|
|
||||||
|
|
||||||
impl ResourceData for SceneGraph {
|
|
||||||
fn dependencies(&self) -> Vec<crate::UntypedResHandle> {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn as_any(&self) -> &dyn std::any::Any {
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
fn as_any_mut(&mut self) -> &mut dyn std::any::Any {
|
|
||||||
self
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -214,12 +214,12 @@ impl UntypedResHandle {
|
||||||
/// However, the only times it will be blocking is if another thread is reloading the resource
|
/// However, the only times it will be blocking is if another thread is reloading the resource
|
||||||
/// and has a write lock on the data. This means that most of the time, it is not blocking.
|
/// and has a write lock on the data. This means that most of the time, it is not blocking.
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
pub struct ResHandle<T: ResourceData> {
|
pub struct ResHandle<T: 'static> {
|
||||||
pub(crate) handle: UntypedResHandle,
|
pub(crate) handle: UntypedResHandle,
|
||||||
_marker: PhantomData<T>,
|
_marker: PhantomData<T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: ResourceData> Clone for ResHandle<T> {
|
impl<T> Clone for ResHandle<T> {
|
||||||
fn clone(&self) -> Self {
|
fn clone(&self) -> Self {
|
||||||
Self {
|
Self {
|
||||||
handle: self.handle.clone(),
|
handle: self.handle.clone(),
|
||||||
|
@ -228,7 +228,7 @@ impl<T: ResourceData> Clone for ResHandle<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: ResourceData> Deref for ResHandle<T> {
|
impl<T> Deref for ResHandle<T> {
|
||||||
type Target = UntypedResHandle;
|
type Target = UntypedResHandle;
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target {
|
||||||
|
@ -236,7 +236,7 @@ impl<T: ResourceData> Deref for ResHandle<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: ResourceData> DerefMut for ResHandle<T> {
|
impl<T> DerefMut for ResHandle<T> {
|
||||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||||
&mut self.handle
|
&mut self.handle
|
||||||
}
|
}
|
||||||
|
@ -285,7 +285,7 @@ impl<T: ResourceData> ResHandle<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: ResourceData> ResourceStorage for ResHandle<T> {
|
impl<T: Send + Sync + 'static> ResourceStorage for ResHandle<T> {
|
||||||
fn as_any(&self) -> &dyn Any {
|
fn as_any(&self) -> &dyn Any {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
|
@ -173,7 +173,7 @@ impl ResourceManager {
|
||||||
|
|
||||||
/// Request a resource without downcasting to a `ResHandle<T>`.
|
/// Request a resource without downcasting to a `ResHandle<T>`.
|
||||||
/// Whenever you're ready to downcast, you can do so like this:
|
/// Whenever you're ready to downcast, you can do so like this:
|
||||||
/// ```nobuild
|
/// ```compile_fail
|
||||||
/// let arc_any = res_arc.as_arc_any();
|
/// let arc_any = res_arc.as_arc_any();
|
||||||
/// let res: Arc<ResHandle<T>> = res.downcast::<ResHandle<T>>().expect("Failure to downcast resource");
|
/// let res: Arc<ResHandle<T>> = res.downcast::<ResHandle<T>>().expect("Failure to downcast resource");
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -221,7 +221,7 @@ impl ResourceManager {
|
||||||
///
|
///
|
||||||
/// The resource cannot be requested with [`ResourceManager::request`], it can only be
|
/// The resource cannot be requested with [`ResourceManager::request`], it can only be
|
||||||
/// retrieved with [`ResourceManager::request_uuid`].
|
/// retrieved with [`ResourceManager::request_uuid`].
|
||||||
pub fn store_uuid<T: ResourceData>(&self, res: ResHandle<T>) {
|
pub fn store_uuid<T: Send + Sync + 'static>(&self, res: ResHandle<T>) {
|
||||||
let mut state = self.state_mut();
|
let mut state = self.state_mut();
|
||||||
state.resources.insert(res.uuid().to_string(), Arc::new(res));
|
state.resources.insert(res.uuid().to_string(), Arc::new(res));
|
||||||
}
|
}
|
||||||
|
@ -230,7 +230,7 @@ impl ResourceManager {
|
||||||
///
|
///
|
||||||
/// Returns `None` if the resource was not found. The resource must of had been
|
/// Returns `None` if the resource was not found. The resource must of had been
|
||||||
/// stored with [`ResourceManager::request`] to return `Some`.
|
/// stored with [`ResourceManager::request`] to return `Some`.
|
||||||
pub fn request_uuid<T: ResourceData>(&self, uuid: &Uuid) -> Option<ResHandle<T>> {
|
pub fn request_uuid<T: Send + Sync + 'static>(&self, uuid: &Uuid) -> Option<ResHandle<T>> {
|
||||||
let state = self.state();
|
let state = self.state();
|
||||||
match state.resources.get(&uuid.to_string())
|
match state.resources.get(&uuid.to_string())
|
||||||
.or_else(|| state.uuid_resources.get(&uuid))
|
.or_else(|| state.uuid_resources.get(&uuid))
|
||||||
|
@ -291,7 +291,7 @@ impl ResourceManager {
|
||||||
/// Requests bytes from the manager.
|
/// Requests bytes from the manager.
|
||||||
pub fn request_loaded_bytes<T>(&self, ident: &str) -> Result<Arc<ResHandle<T>>, RequestError>
|
pub fn request_loaded_bytes<T>(&self, ident: &str) -> Result<Arc<ResHandle<T>>, RequestError>
|
||||||
where
|
where
|
||||||
T: ResourceData
|
T: Send + Sync + Any + 'static
|
||||||
{
|
{
|
||||||
let state = self.state();
|
let state = self.state();
|
||||||
match state.resources.get(&ident.to_string()) {
|
match state.resources.get(&ident.to_string()) {
|
||||||
|
@ -366,7 +366,7 @@ impl ResourceManager {
|
||||||
/// the handle.
|
/// the handle.
|
||||||
pub fn reload<T>(&self, resource: ResHandle<T>) -> Result<(), RequestError>
|
pub fn reload<T>(&self, resource: ResHandle<T>) -> Result<(), RequestError>
|
||||||
where
|
where
|
||||||
T: ResourceData
|
T: Send + Sync + Any + 'static
|
||||||
{
|
{
|
||||||
let state = self.state();
|
let state = self.state();
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ pub trait WorldAssetExt {
|
||||||
/// automatically triggered if the resource is being watched.
|
/// automatically triggered if the resource is being watched.
|
||||||
fn reload_res<T>(&mut self, resource: ResHandle<T>) -> Result<(), RequestError>
|
fn reload_res<T>(&mut self, resource: ResHandle<T>) -> Result<(), RequestError>
|
||||||
where
|
where
|
||||||
T: ResourceData;
|
T: Send + Sync + Any + 'static;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WorldAssetExt for World {
|
impl WorldAssetExt for World {
|
||||||
|
@ -67,7 +67,7 @@ impl WorldAssetExt for World {
|
||||||
|
|
||||||
fn reload_res<T>(&mut self, resource: ResHandle<T>) -> Result<(), RequestError>
|
fn reload_res<T>(&mut self, resource: ResHandle<T>) -> Result<(), RequestError>
|
||||||
where
|
where
|
||||||
T: ResourceData
|
T: Send + Sync + Any + 'static
|
||||||
{
|
{
|
||||||
let man = self.get_resource_or_default::<ResourceManager>();
|
let man = self.get_resource_or_default::<ResourceManager>();
|
||||||
man.reload(resource)
|
man.reload(resource)
|
||||||
|
|
|
@ -116,13 +116,6 @@ impl SceneGraph {
|
||||||
world_add_child_node(&mut self.world, parent, local_transform, bundle)
|
world_add_child_node(&mut self.world, parent, local_transform, bundle)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Insert a component bundle to a SceneNode.
|
|
||||||
///
|
|
||||||
/// See [`lyra_ecs::World::insert`].
|
|
||||||
pub fn insert<B: Bundle>(&mut self, node: &SceneNode, bundle: B) {
|
|
||||||
self.world.insert(node.entity(), bundle);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn add_empty_node_under(&mut self, parent: &SceneNode, local_transform: Transform) -> SceneNode {
|
pub fn add_empty_node_under(&mut self, parent: &SceneNode, local_transform: Transform) -> SceneNode {
|
||||||
let e = self.world.spawn((SceneNodeFlag, local_transform));
|
let e = self.world.spawn((SceneNodeFlag, local_transform));
|
||||||
self.world.add_relation(e, ChildOf, parent.entity());
|
self.world.add_relation(e, ChildOf, parent.entity());
|
||||||
|
@ -162,11 +155,6 @@ impl SceneGraph {
|
||||||
pub fn root_node(&self) -> SceneNode {
|
pub fn root_node(&self) -> SceneNode {
|
||||||
self.root_node.clone()
|
self.root_node.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Retrieve a borrow of the world that backs the Scene
|
|
||||||
pub fn world(&self) -> &World {
|
|
||||||
&self.world
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add a node under a parent node.
|
/// Add a node under a parent node.
|
||||||
|
|
Loading…
Reference in New Issue