use crate::{Edge, EdgeKind, HashSet, Node, OwnedArgument, OwnedData, Scene};
use core::{cmp::Ordering, fmt};
mod attributes;
mod chain;
mod instances;
mod mesh;
mod motion;
mod outputs;
mod primvar;
pub use chain::WorldTransforms;
pub use instances::Instances;
pub use mesh::{Face, Faces};
pub use motion::Sampled;
pub use primvar::{Interpolation, PrimitiveVariable};
#[rustfmt::skip]
pub const IDENTITY: [f64; 16] = [
1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0,
];
const TRANSFORMATION_MATRIX: &str = "transformationmatrix";
const MATRICES: &str = "transformationmatrices";
const MODEL_INDICES: &str = "modelindices";
const FACE_VERTEX_COUNTS: &str = "nvertices";
const HOLE_COUNTS: &str = "nholes";
const POSITIONS: &str = "P";
const INDICES: &str = ".indices";
const VARIABLE_NAME: &str = "variablename";
const VARIABLE_SOURCE: &str = "variablesource";
const LAYER_NAME: &str = "layername";
const LAYER_TYPE: &str = "layertype";
const SCALAR_FORMAT: &str = "scalarformat";
const WITH_ALPHA: &str = "withalpha";
const DITHERING: &str = "dithering";
const FILTER: &str = "filter";
const FILTER_WIDTH: &str = "filterwidth";
const COLOR_PROFILE: &str = "colorprofile";
const SORT_KEY: &str = "sortkey";
const DISABLED: &str = "disabledinstances";
#[derive(Debug, Clone, PartialEq)]
#[non_exhaustive]
pub enum ResolveError {
MultipleParents {
handle: String,
parents: Vec<String>,
},
MotionSampledTransform {
handle: String,
},
Cycle {
handle: String,
},
Detached {
handle: String,
},
UnknownHandle {
handle: String,
},
Instanced {
instancer: String,
},
MalformedInstanceMatrices {
instances: String,
values: usize,
},
DuplicateModelIndex {
instances: String,
index: i32,
},
UnknownModelIndex {
instances: String,
model: i32,
},
NotAnAncestor {
handle: String,
ancestor: String,
},
MissingSampleAtTime {
handle: String,
time: f64,
available: Vec<f64>,
},
MissingFaceCounts {
handle: String,
},
MalformedIndices {
handle: String,
attribute: String,
indices: usize,
face_vertices: usize,
values: usize,
},
AmbiguousInterpolation {
handle: String,
attribute: String,
values: usize,
faces: usize,
vertices: usize,
face_vertices: usize,
},
MalformedFaceCounts {
handle: String,
expected: usize,
found: usize,
},
}
impl fmt::Display for ResolveError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::MultipleParents { handle, parents } => write!(
f,
"ɴsɪ node {handle:?} has {} parents ({}); that is \
instancing, which has one world transform per path, not \
one overall",
parents.len(),
parents.join(", ")
),
Self::MotionSampledTransform { handle } => write!(
f,
"ɴsɪ node {handle:?} carries motion-sampled placement \
data; the static value would be the wrong answer, so \
ask at a time instead"
),
Self::Cycle { handle } => write!(
f,
"ɴsɪ transform chain revisits node {handle:?}; a cyclic \
scene has no world transform"
),
Self::UnknownHandle { handle } => {
write!(f, "no ɴsɪ node is named {handle:?}")
}
Self::Detached { handle } => write!(
f,
"ɴsɪ node {handle:?} is not connected to {root:?}, so it \
is not in the scene and has no world transform",
root = crate::ROOT
),
Self::Instanced { instancer } => write!(
f,
"ɴsɪ node is an instancing prototype of {instancer:?}, \
which carries one transform per instance; there is no \
single world transform for it"
),
Self::MalformedInstanceMatrices { instances, values } => {
write!(
f,
"ɴsɪ node {instances:?} has {values} values in \
transformationmatrices, which is not a whole number \
of 4x4 matrices"
)
}
Self::DuplicateModelIndex { instances, index } => write!(
f,
"ɴsɪ node {instances:?} has two sourcemodels connections \
at index {index}, so its models are not an ordered list"
),
Self::UnknownModelIndex { instances, model } => write!(
f,
"ɴsɪ node {instances:?} selects model index {model}, which \
matches no sourcemodels connection"
),
Self::NotAnAncestor { handle, ancestor } => write!(
f,
"ɴsɪ node {ancestor:?} is not on {handle:?}'s chain, so \
there is no transform of one relative to the other"
),
Self::MissingSampleAtTime {
handle,
time,
available,
} => write!(
f,
"ɴsɪ node {handle:?} has no transform sample at time \
{time}; it has {available:?}, and this crate does not \
interpolate between them"
),
Self::MalformedIndices {
handle,
attribute,
indices,
face_vertices,
values,
} => write!(
f,
"ɴsɪ primitive {handle:?} has {indices} {attribute:?} \
indices for {face_vertices} face-vertices into {values} \
values; indices are read per face-vertex"
),
Self::AmbiguousInterpolation {
handle,
attribute,
values,
faces,
vertices,
face_vertices,
} => write!(
f,
"ɴsɪ primitive {handle:?} has {values} {attribute:?} values, \
which is neither constant (1), per face ({faces}), per \
vertex ({vertices}) nor per face-vertex ({face_vertices})"
),
Self::MissingFaceCounts { handle } => write!(
f,
"ɴsɪ mesh {handle:?} sets no \"nvertices\", which ɴsɪ \
requires; its faces are undefined"
),
Self::MalformedFaceCounts {
handle,
expected,
found,
} => write!(
f,
"ɴsɪ mesh {handle:?} has \"nholes\" asking for {expected} \
\"nvertices\" values and carries {found}; with holes, each \
face takes its outer perimeter plus one count per hole"
),
}
}
}
impl core::error::Error for ResolveError {}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub struct Binding {
pub attributes: Vec<String>,
pub surface_shader: Option<String>,
pub displacement_shader: Option<String>,
pub volume_shader: Option<String>,
}
pub const RAY_TYPES: [&str; 8] = [
"camera",
"diffuse",
"hair",
"reflection",
"refraction",
"shadow",
"specular",
"volume",
];
#[derive(Debug, Clone, PartialEq)]
#[non_exhaustive]
pub struct Placement {
pub path: Vec<String>,
pub transform: [f64; 16],
pub binding: Option<Binding>,
}
#[derive(Debug, Clone, Copy, PartialEq)]
#[non_exhaustive]
pub struct AttributeValue<'a> {
pub node: &'a str,
pub name: &'a str,
pub arg: Option<&'a OwnedArgument>,
pub priority: i32,
}
#[derive(Debug, Clone, PartialEq)]
#[non_exhaustive]
pub struct RenderOutput {
pub camera: String,
pub screen: String,
pub layers: Vec<OutputLayer>,
}
#[derive(Debug, Clone, Copy, PartialEq)]
#[non_exhaustive]
pub struct InstanceRef<'a> {
pub source: usize,
pub transform: &'a [f64; 16],
}
#[derive(Debug, Clone, PartialEq)]
#[non_exhaustive]
pub struct Instance {
pub source: usize,
pub transform: [f64; 16],
}
#[derive(Debug, Clone, PartialEq)]
#[non_exhaustive]
pub struct OutputLayer {
pub handle: String,
pub variable_name: Option<String>,
pub variable_source: String,
pub layer_name: Option<String>,
pub layer_type: String,
pub scalar_format: String,
pub with_alpha: bool,
pub dithering: bool,
pub filter: String,
pub filter_width: f64,
pub color_profile: Option<String>,
pub sort_key: Option<i32>,
pub drivers: Vec<String>,
}
fn mul(a: [f64; 16], b: [f64; 16]) -> [f64; 16] {
let mut out = [0.0; 16];
for row in 0..4 {
for col in 0..4 {
let mut sum = 0.0;
for k in 0..4 {
sum += a[row * 4 + k] * b[k * 4 + col];
}
out[row * 4 + col] = sum;
}
}
out
}
#[cfg(test)]
mod tests;