Initial Commit

This commit is contained in:
SoraKatadzuma committed 2026-11-12 19:27:17 -06:00
commit ed1188f440
36 files changed
+8436

No files matched your search

+107
View File
@@ -0,0 +1,107 @@
#! Contains reading an object's properties as `Properties70` holds them: each a
#! `P` node of its name, its type, its label, and its flags, then its values.
#! Where an object leaves one out, the template of its kind, of the document's
#! `Definitions`, gives it, as FBX's SDK reads them. And reading the children
#! a node holds a value in, as a texture's `FileName`.
import malunal::linear;
module malunal::fbx;
#! The text of a node's first child of a name, its first property's, or empty
#! where it has none.
pub def document::text_of(&this, of: u32, name: strview): strview {
val found := this.child(of, name) else { return ""; };
val held := &this.nodes[found as u64];
return "" if held.properties.length == 0;
return held.properties[0].text();
}
#! The number of a node's first child of a name, its first property's, or a
#! given one where it has none.
pub def document::number_of(&this, of: u32, name: strview, given: f64): f64 {
val found := this.child(of, name) else { return given; };
val held := &this.nodes[found as u64];
return given if held.properties.length == 0;
return held.properties[0].number();
}
# Notes the templates of the document's definitions.
def scene::read_templates(&mut this): void {
val definitions := this.document.child(absent, "Definitions") else { return; };
val kinds := this.document.children_named(definitions, "ObjectType");
for k in 0..kinds.length {
var kind := string::new(nothing{});
if this.document.property(kinds[k], 0) is some(&named) {
kind.append(named.text());
}
val templates := this.document.children_named(kinds[k], "PropertyTemplate");
for t in 0..templates.length {
if this.document.child(templates[t], "Properties70") is some(properties) {
this.templates.append(template{ kind = string::from(kind.span, nothing{}), properties = properties });
}
}
}
}
# The `P` node of a name among a `Properties70` node's.
def entry_in(made: &document, properties: u32, name: strview): maybe<u32> {
val list := made.nodes[properties as u64].children.span;
for i in 0..list.length {
val each := &made.nodes[list[i] as u64];
continue if each.properties.length == 0 || each.name.span != "P";
return list[i] if each.properties[0].text() == name;
}
return nothing{};
}
#! An object's property of a name: the `P` node of it, of its own
#! `Properties70`, or of its kind's template, where neither has it, nothing.
#! A `P` node's properties are its name, type, label, and flags, then its
#! values.
#! @param object The object's node, or any node holding `Properties70`, as
#! `GlobalSettings`.
pub def scene::entry(&this, object: u32, name: strview): maybe<u32> {
if this.document.child(object, "Properties70") is some(own) {
if entry_in(&this.document, own, name) is some(found) {
return found;
}
}
val kind := this.document.nodes[object as u64].name.span;
for i in 0..this.templates.length {
continue if this.templates[i].kind.span != kind;
if entry_in(&this.document, this.templates[i].properties, name) is some(found) {
return found;
}
}
return nothing{};
}
#! An object's property of a number, or a given one where it has none.
pub def scene::number_of(&this, object: u32, name: strview, given: f64): f64 {
val found := this.entry(object, name) else { return given; };
val held := &this.document.nodes[found as u64];
return given if held.properties.length < 5;
return held.properties[4].number();
}
#! An object's property of three numbers, as a color or a translation, or a
#! given one where it has none.
pub def scene::vector_of(&this, object: u32, name: strview, given: vec3): vec3 {
val found := this.entry(object, name) else { return given; };
val held := &this.document.nodes[found as u64];
return given if held.properties.length < 7;
return vec3{ held.properties[4].number() as f32, held.properties[5].number() as f32, held.properties[6].number() as f32 };
}
#! An object's property of text, or empty where it has none.
pub def scene::text_of(&this, object: u32, name: strview): strview {
val found := this.entry(object, name) else { return ""; };
val held := &this.document.nodes[found as u64];
return "" if held.properties.length < 5;
return held.properties[4].text();
}
#! An object's property of a boolean, or a given one where it has none.
pub def scene::flag_of(&this, object: u32, name: strview, given: bool): bool {
return this.number_of(object, name, given ? 1 : 0) != 0;
}