Initial Commit

This commit is contained in:
SoraKatadzuma committed 2026-11-14 15:40:07 -06:00
commit 05afb4a443
36 files changed
+8436

No files matched your search

+400
View File
@@ -0,0 +1,400 @@
#! Contains `scene`, what a document's objects mean, as FBX's SDK reads them:
#! its settings; models, the tree of nodes, each placed by FBX's chain of
#! translations, pivots, rotations, and scales; meshes, of polygons of any
#! number of corners, their normals, places on textures, colors, and
#! materials given for each corner; materials, textures, and the files they
#! embed; cameras and lights; skins, of clusters binding a mesh's points to
#! bones; blend shapes; bind poses; and animations, of stacks, layers, curve
#! nodes, and curves. Each part keeps its id, its name, and its node in the
#! document, whose other properties `scene::entry` and those after it read.
#! Indices between parts are `u32`s, into the scene's lists, `absent` where
#! they name nothing.
import malunal::linear;
module malunal::fbx;
#! The order a model's rotation turns about its axes, the first named turning
#! first.
pub enum rotation_order: u8 { xyz, xzy, yzx, yxz, zxy, zyx, spheric_xyz }
#! What a scene's settings say of the whole of it.
pub struct settings {
#! The axis up, the axis to the front, and the axis across, each 0, 1, or 2
#! for x, y, or z, and its sign, 1 or -1.
pub var up_axis: u32 = 1;
pub var up_sign: i32 = 1;
pub var front_axis: u32 = 2;
pub var front_sign: i32 = 1;
pub var coord_axis: u32;
pub var coord_sign: i32 = 1;
#! How many centimeters a unit is, as 100 of a file in meters; and what it
#! was before the tool that wrote it scaled it.
pub var unit_scale: f64 = 1;
pub var original_unit_scale: f64 = 1;
#! Frames a second, and the time it spans, in seconds.
pub var frame_rate: f64 = 30;
pub var start: f64;
pub var stop: f64;
pub var ambient := vec3::zero;
}
#! A model: a node of the tree, and what's there, a mesh, a camera, a light,
#! or a bone, as `kind` says, as `Mesh`, `LimbNode`, or `Null`.
pub struct model {
pub var id: i64;
pub var name: string;
pub var kind: string;
pub var node: u32;
pub var parent: u32 = absent;
pub var children: vector<u32>;
pub var mesh: u32 = absent;
#! Its materials, in the order they're connected, which a mesh's polygons'
#! materials index.
pub var materials: vector<u32>;
pub var camera: u32 = absent;
pub var light: u32 = absent;
#! Where it is within its parent: `Lcl Translation`, `Lcl Rotation` in
#! degrees, and `Lcl Scaling`.
pub var translation := vec3::zero;
pub var rotation := vec3::zero;
pub var scale := vec3::one;
#! Rotations before and after its own, in degrees, and the order its own
#! turns in, which hold only where `rotation_active` is.
pub var pre_rotation := vec3::zero;
pub var post_rotation := vec3::zero;
pub var order := rotation_order::xyz;
pub var rotation_active: bool;
#! The pivots it's turned and scaled about, and their offsets.
pub var rotation_offset := vec3::zero;
pub var rotation_pivot := vec3::zero;
pub var scaling_offset := vec3::zero;
pub var scaling_pivot := vec3::zero;
#! Where its mesh is within it, its children not: `GeometricTranslation`,
#! `GeometricRotation` in degrees, and `GeometricScaling`.
pub var geometric_translation := vec3::zero;
pub var geometric_rotation := vec3::zero;
pub var geometric_scale := vec3::one;
#! `InheritType`: how its parent's scale passes to it; 1, the default, as
#! matrices multiply.
pub var inherit: u32 = 1;
pub var visible := true;
}
#! A run of a mesh's corners.
pub struct polygon {
pub var first: u64;
pub var count: u32;
}
#! A set of places on a texture, one for each corner, of a name.
pub struct uv_set {
pub var name: string;
pub var uvs: vector<vec2>;
}
#! A mesh: points, and polygons of them; what's given of each corner, its
#! normal, its places on textures, and its color, each list as long as the
#! corners, where it's given; and each polygon's material.
pub struct mesh {
pub var id: i64;
pub var name: string;
pub var node: u32;
pub var positions: vector<vec3>;
pub var polygons: vector<polygon>;
#! The points of each polygon's corners, in turn.
pub var corners: vector<u32>;
pub var normals: vector<vec3>;
pub var uv_sets: vector<uv_set>;
pub var colors: vector<vec4>;
#! Each polygon's material, an index into its model's; empty where none's
#! given, as all of the first.
pub var materials: vector<u32>;
pub var skin: u32 = absent;
pub var blend_shapes: vector<u32>;
}
#! A shape a blend shape channel blends a mesh toward: how far each of the
#! points it names moves, and its normal turns.
pub struct shape {
pub var id: i64;
pub var name: string;
pub var node: u32;
pub var points: vector<u32>;
pub var offsets: vector<vec3>;
pub var normals: vector<vec3>;
}
#! A blend shape: the channels blending a mesh.
pub struct blend_shape {
pub var id: i64;
pub var name: string;
pub var node: u32;
pub var mesh: u32 = absent;
pub var channels: vector<u32>;
}
#! A channel of a blend shape: how far, from 0 to 100, it blends toward its
#! shapes, and the weight at which each is whole, where it has more than one.
pub struct blend_channel {
pub var id: i64;
pub var name: string;
pub var node: u32;
pub var weight: f32;
pub var full_weights: vector<f32>;
pub var shapes: vector<u32>;
}
#! A skin: the clusters binding a mesh's points to bones.
pub struct skin {
pub var id: i64;
pub var name: string;
pub var node: u32;
pub var mesh: u32 = absent;
pub var clusters: vector<u32>;
}
#! A cluster: the points a bone moves, and how much; the mesh's place when it
#! was bound, `transform`, and the bone's, `transform_link`.
pub struct cluster {
pub var id: i64;
pub var name: string;
pub var node: u32;
pub var skin: u32 = absent;
#! The model that's its bone.
pub var bone: u32 = absent;
pub var points: vector<u32>;
pub var weights: vector<f32>;
pub var transform := mat4::identity;
pub var transform_link := mat4::identity;
}
#! A texture a material maps, and the property it's mapped to, as
#! `DiffuseColor` or `NormalMap`.
pub struct material_map {
pub var property: string;
pub var texture: u32;
}
#! A material: its shading model, `phong` or `lambert`, its colors and
#! factors, of the defaults FBX's SDK gives where it leaves them out, and the
#! textures it maps.
pub struct material {
pub var id: i64;
pub var name: string;
pub var node: u32;
pub var shading: string;
pub var diffuse := vec3{ 0.8, 0.8, 0.8 };
pub var diffuse_factor: f32 = 1;
pub var ambient := vec3{ 0.2, 0.2, 0.2 };
pub var ambient_factor: f32 = 1;
pub var specular := vec3{ 0.2, 0.2, 0.2 };
pub var specular_factor: f32 = 1;
pub var shininess: f32 = 20;
pub var emissive := vec3::zero;
pub var emissive_factor: f32 = 1;
#! `TransparencyFactor`, and `Opacity`, where it's given, which some tools
#! write and others don't.
pub var transparency: f32;
pub var opacity: f32 = 1;
pub var reflection_factor: f32 = 1;
pub var bump_factor: f32 = 1;
pub var maps: vector<material_map>;
}
#! The texture it maps to a property, where it maps one.
pub def material::map(&this, property: strview): maybe<u32> {
for i in 0..this.maps.length {
return this.maps[i].texture if this.maps[i].property.span == property;
}
return nothing{};
}
#! A texture: the file it names, as written, and relative to the FBX file; the
#! set of places it's drawn by, where it names one; how it's placed; and the
#! video embedding its file, where one does.
pub struct texture {
pub var id: i64;
pub var name: string;
pub var node: u32;
pub var file: string;
pub var relative: string;
pub var uv_set: string;
pub var translation := vec3::zero;
pub var rotation := vec3::zero;
pub var scale := vec3::one;
#! 0 where it repeats, 1 where it's clamped.
pub var wrap_u: u32;
pub var wrap_v: u32;
pub var video: u32 = absent;
}
#! A video, as FBX calls an image: the file it names, and its bytes, where the
#! FBX file embeds them.
pub struct video {
pub var id: i64;
pub var name: string;
pub var node: u32;
pub var file: string;
pub var relative: string;
pub var content: vector<u8>;
}
#! A camera, as its node attribute gives it: distances and angles in the
#! file's units and degrees.
pub struct camera {
pub var id: i64;
pub var name: string;
pub var node: u32;
pub var orthographic: bool;
pub var field_of_view: f32 = 40;
pub var field_of_view_x: f32 = 40;
pub var field_of_view_y: f32 = 40;
pub var focal_length: f32 = 34.89;
pub var near: f32 = 10;
pub var far: f32 = 4000;
pub var aspect_width: f32 = 320;
pub var aspect_height: f32 = 200;
pub var ortho_zoom: f32 = 1;
}
#! What kind of light it is.
pub enum light_kind: u8 { point, directional, spot, area, volume }
#! A light, as its node attribute gives it: its intensity as a percent, 100
#! the whole of its color, and a spot's cone's angles in degrees.
pub struct light {
pub var id: i64;
pub var name: string;
pub var node: u32;
pub var kind: light_kind;
pub var color := vec3::one;
pub var intensity: f32 = 100;
pub var inner_angle: f32;
pub var outer_angle: f32 = 45;
#! 0 where it doesn't decay, 1 linearly, 2 quadratically, 3 cubically.
pub var decay: u32;
pub var decay_start: f32;
pub var casts_shadows: bool;
}
#! A model's place in a pose: its matrix, of its place in the world, where
#! the pose is a bind pose.
pub struct pose_entry {
pub var model: u32 = absent;
pub var id: i64;
pub var matrix := mat4::identity;
}
#! A pose: each model's matrix, as when a skin was bound, where it's a bind
#! pose.
pub struct pose {
pub var id: i64;
pub var name: string;
pub var node: u32;
pub var bind: bool;
pub var entries: vector<pose_entry>;
}
#! An animation: its layers, and the time it spans, in seconds.
pub struct animation_stack {
pub var id: i64;
pub var name: string;
pub var node: u32;
pub var start: f64;
pub var stop: f64;
pub var layers: vector<u32>;
}
#! A layer of an animation: its curve nodes, and how much it weighs, from 0 to
#! 100.
pub struct animation_layer {
pub var id: i64;
pub var name: string;
pub var node: u32;
pub var stack: u32 = absent;
pub var weight: f32 = 100;
pub var curve_nodes: vector<u32>;
}
#! What kind of part a curve node animates.
pub enum part_kind: u8 { none, model, channel, material, camera, light, other }
#! A channel of a curve node: its name, as `X` of `d|X`, its value where no
#! curve's given, and its curve, where one is.
pub struct curve_channel {
pub var name: string;
pub var value: f32;
pub var curve: u32 = absent;
}
#! A curve node: the property of a part it animates, as a model's
#! `Lcl Translation` or a blend channel's `DeformPercent`, and its channels.
pub struct curve_node {
pub var id: i64;
pub var name: string;
pub var node: u32;
pub var layer: u32 = absent;
pub var target_kind: part_kind;
pub var target: u32 = absent;
pub var property: string;
pub var channels: vector<curve_channel>;
}
#! The channel of a name, as `X`, where it has one.
pub def curve_node::channel(&this, name: strview): maybe<&curve_channel> {
for i in 0..this.channels.length {
return &this.channels[i] if this.channels[i].name.span == name;
}
return nothing{};
}
#! How a curve goes from a key to the next.
pub enum key_interpolation: u8 { constant, linear, cubic }
#! A curve: its keys, each a time in seconds and a value, how it goes on to the
#! next, and a cubic's slopes, to its right and to the next key's left.
pub struct curve {
pub var id: i64;
pub var name: string;
pub var node: u32;
pub var value: f32;
pub var times: vector<f64>;
pub var values: vector<f32>;
pub var interpolations: vector<key_interpolation>;
pub var right_slopes: vector<f32>;
pub var next_left_slopes: vector<f32>;
}
#! A property template of the document's definitions, which gives the values
#! its objects of a kind leave out.
struct template {
var kind: string;
var properties: u32;
}
#! A scene: the document it's of, and what its objects mean, each kind in a
#! list of its own.
pub struct scene {
pub var document: document;
pub var settings: settings;
pub var models: vector<model>;
pub var meshes: vector<mesh>;
pub var shapes: vector<shape>;
pub var blend_shapes: vector<blend_shape>;
pub var channels: vector<blend_channel>;
pub var skins: vector<skin>;
pub var clusters: vector<cluster>;
pub var materials: vector<material>;
pub var textures: vector<texture>;
pub var videos: vector<video>;
pub var cameras: vector<camera>;
pub var lights: vector<light>;
pub var poses: vector<pose>;
pub var stacks: vector<animation_stack>;
pub var layers: vector<animation_layer>;
pub var curve_nodes: vector<curve_node>;
pub var curves: vector<curve>;
#! The models at the root.
pub var roots: vector<u32>;
var templates: vector<template>;
}