Crate dae_parser[−][src]
Expand description
A parser for the COLLADA format (.dae
extension).
The main entry point is the Document
type, which has a FromStr
implementation to convert
literal strings / slices, or Document::from_file
to read from a .dae
file on disk.
Collada documents are parsed eagerly, validating everything according to the COLLADA schema. Once parsed, the data structures (structs and enums) can be navigated directly, as all the data structures are public, and reflect the XML schema closely.
This library implements only version 1.4.1 of the Collada spec, although it may be expanded in the future (PRs welcome).
use std::str::FromStr;
use dae_parser::*;
let dae_file = r##"\
<?xml version="1.0" encoding="utf-8"?>
<COLLADA xmlns="http://www.collada.org/2005/11/COLLADASchema" version="1.4.1">
<asset>
<created>1970-01-01T00:00:00</created>
<modified>1970-01-01T00:00:00</modified>
</asset>
<library_geometries>
<geometry id="Cube-mesh" name="Cube">
<mesh>
<source id="Cube-mesh-positions">
<float_array id="Cube-mesh-positions-array" count="18">
1 1 1 1 -1 1 1 -1 -1 -1 1 1 -1 -1 1 -1 -1 -1
</float_array>
<technique_common>
<accessor source="#Cube-mesh-positions-array" count="6" stride="3">
<param name="X" type="float"/>
<param name="Y" type="float"/>
<param name="Z" type="float"/>
</accessor>
</technique_common>
</source>
<vertices id="Cube-mesh-vertices">
<input semantic="POSITION" source="#Cube-mesh-positions"/>
</vertices>
<triangles material="Material-material" count="4">
<input semantic="VERTEX" source="#Cube-mesh-vertices" offset="0"/>
<p>3 1 0 1 5 2 3 4 1 1 4 5</p>
</triangles>
</mesh>
</geometry>
</library_geometries>
</COLLADA>"##;
let document = Document::from_str(dae_file).unwrap();
if let LibraryElement::Geometries(lib) = &document.library[0] {
let geom = &lib.items[0];
assert_eq!(geom.id.as_ref().unwrap(), "Cube-mesh");
if let GeometryElement::Mesh(mesh) = &geom.element {
assert_eq!(mesh.source[0].id.as_ref().unwrap(), "Cube-mesh-positions");
if let Primitive::Triangles(tris) = &mesh.elements[0] {
assert_eq!(
tris.data.0.as_deref().unwrap(),
&[3, 1, 0, 1, 5, 2, 3, 4, 1, 1, 4, 5]
);
return;
}
}
}
panic!()
Structs
A struct representing a DOM Element.
<input>
(unshared)
<source>
(core)
<technique>
(core)