mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 16:54:45 +00:00
Merge branch 'codex/fbx-ordered-placements' into codex/fbx-integration
This commit is contained in:
+17
-10
@@ -814,8 +814,8 @@ impl Document {
|
||||
self.scene_with_placements(limits, resolve, options).map(|(scene, _)| scene)
|
||||
}
|
||||
|
||||
/// Build a scene and list its mesh-node indices in FBX placement order.
|
||||
pub fn scene_with_placements(&self, limits: &Limits, resolve: Resolver, options: &SceneOptions) -> Result<(Scene, Vec<usize>)> {
|
||||
/// Build a scene and list its mesh nodes in FBX placement order.
|
||||
pub fn scene_with_placements(&self, limits: &Limits, resolve: Resolver, options: &SceneOptions) -> Result<(Scene, Vec<Placement>)> {
|
||||
if self.version != 0 && self.version < 6000 {
|
||||
return Err(crate::Error::Unsupported(format!(
|
||||
"FBX {}.{} (only FBX 6.x and 7.x files are read)",
|
||||
@@ -982,7 +982,7 @@ impl Document {
|
||||
}
|
||||
ni
|
||||
};
|
||||
placement_nodes.insert((gid, Some(*id)), placement_node);
|
||||
placement_nodes.insert((gid, Some(*id)), Placement { node: placement_node, model: Some(ni) });
|
||||
}
|
||||
}
|
||||
// Geometry with no Model connection still contributes a mesh at the origin.
|
||||
@@ -1004,7 +1004,7 @@ impl Document {
|
||||
let node_index = b.scene.nodes.len();
|
||||
b.scene.roots.push(node_index);
|
||||
b.scene.nodes.push(Node { mesh: Some(mesh_index), ..Node::default() });
|
||||
unplaced.push((key_text(gid), node_index));
|
||||
unplaced.push((key_text(gid), Placement { node: node_index, model: None }));
|
||||
}
|
||||
let placements = ordered_placements(&models, &links, &placement_nodes, unplaced);
|
||||
let mut scene = b.scene;
|
||||
@@ -1016,16 +1016,16 @@ impl Document {
|
||||
fn ordered_placements<'a>(
|
||||
models: &[(Key<'a>, &Record)],
|
||||
links: &[(Key<'a>, Key<'a>)],
|
||||
placement_nodes: &HashMap<(Key<'a>, Option<Key<'a>>), usize>,
|
||||
mut unplaced: Vec<(String, usize)>,
|
||||
) -> Vec<usize> {
|
||||
placement_nodes: &HashMap<(Key<'a>, Option<Key<'a>>), Placement>,
|
||||
mut unplaced: Vec<(String, Placement)>,
|
||||
) -> Vec<Placement> {
|
||||
let mut placements = Vec::new();
|
||||
let mut seen = HashSet::new();
|
||||
let mut add = |key| {
|
||||
if let Some(index) = placement_nodes.get(&key).copied()
|
||||
&& seen.insert(index)
|
||||
if let Some(placement) = placement_nodes.get(&key).copied()
|
||||
&& seen.insert(placement.node)
|
||||
{
|
||||
placements.push(index);
|
||||
placements.push(placement);
|
||||
}
|
||||
};
|
||||
// FBX 6 stores geometry in its model; connected FBX 7 geometry follows connection order.
|
||||
@@ -1042,6 +1042,13 @@ fn ordered_placements<'a>(
|
||||
placements
|
||||
}
|
||||
|
||||
/// One placed FBX mesh, with its scene node and source model node (if any).
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub struct Placement {
|
||||
pub node: usize,
|
||||
pub model: Option<usize>,
|
||||
}
|
||||
|
||||
/// Diffuse material values as stored in FBX, before color-space conversion.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct DiffuseMaterial {
|
||||
|
||||
@@ -852,7 +852,7 @@ fn placement_and_polygon_order_follow_the_fbx() {
|
||||
let options = crate::fbx::SceneOptions { strict_geometry: true, ..Default::default() };
|
||||
let (scene, placements) = doc.scene_with_placements(&Limits::default(), &mut no_external, &options).unwrap();
|
||||
assert_eq!(placements.len(), 1);
|
||||
let mesh = scene.nodes[placements[0]].mesh.unwrap();
|
||||
let mesh = scene.nodes[placements[0].node].mesh.unwrap();
|
||||
let parts = &scene.meshes[mesh].parts;
|
||||
assert_eq!(parts.len(), 3);
|
||||
assert_eq!(parts[0].material, parts[2].material);
|
||||
@@ -864,6 +864,7 @@ fn placement_order_follows_connections_not_model_declarations() {
|
||||
let text = with("Model: 201, \"Model::Later\", \"Mesh\" {}\n", "").replace("C: \"OO\",100,300", "C: \"OO\",100,201\n C: \"OO\",100,300");
|
||||
let doc = document(text.as_bytes());
|
||||
let (scene, placements) = doc.scene_with_placements(&Limits::default(), &mut no_external, &Default::default()).unwrap();
|
||||
let names: Vec<_> = placements.iter().map(|i| scene.nodes[*i].name.as_str()).collect();
|
||||
let names: Vec<_> = placements.iter().map(|i| scene.nodes[i.node].name.as_str()).collect();
|
||||
assert_eq!(names, ["Later", "Shape geometry"]);
|
||||
assert_eq!(scene.nodes[placements[1].model.unwrap()].name, "Shape");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user