Skip to content
This repository has been archived by the owner on Jun 6, 2018. It is now read-only.

Commit

Permalink
feature(parse-collada): add implementation for primitive elements
Browse files Browse the repository at this point in the history
Add implementation for <lines>, <linestrips>, <ph>, <polygons>,
<polylist>, <trifans>, <tristrip>, and <vcount>, and add helper methods to
PrimitiveElements to retieve data in a way that's uniform for all variants
if all variants have that data.
  • Loading branch information
randomPoison committed Dec 4, 2015
1 parent 6edf916 commit 953ac4b
Showing 1 changed file with 100 additions and 6 deletions.
106 changes: 100 additions & 6 deletions lib/parse_collada/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1084,8 +1084,25 @@ collada_element!("library_visual_scenes", LibraryVisualScenes => {
rep child extra: Extra
});

collada_element!("lines", Lines => {});
collada_element!("linestrips", Linestrips => {});
collada_element!("lines", Lines => {
req attrib count: usize
opt attrib name: String,
opt attrib material: String

opt child p: Primitive
rep child input: InputShared,
rep child extra: Extra
});

collada_element!("linestrips", Linestrips => {
req attrib count: usize
opt attrib name: String,
opt attrib material: String

rep child input: InputShared,
rep child p: Primitive,
rep child extra: Extra
});

collada_element!("longitude", Longitude => {
contents: f32
Expand Down Expand Up @@ -1356,9 +1373,35 @@ impl ColladaElement for Param {
}

collada_element!("param", ParamReference => {});

collada_element!("ph", PrimitiveHoles => {
req child p: Primitive
rep child h: Primitive
});

collada_element!("phong", Phong => {});
collada_element!("polygons", Polygons => {});
collada_element!("polylist", Polylist => {});

collada_element!("polygons", Polygons => {
req attrib count: usize
opt attrib material: String,
opt attrib name: String

rep child input: InputShared,
rep child p: Primitive,
rep child ph: PrimitiveHoles,
rep child extra: Extra
});

collada_element!("polylist", Polylist => {
req attrib count: usize
opt attrib name: String,
opt attrib material: String

opt child vcount: VCount,
opt child p: Primitive
rep child input: InputShared,
rep child extra: Extra
});

collada_element!("p", Primitive => {
contents: Vec<usize>
Expand All @@ -1375,6 +1418,36 @@ pub enum PrimitiveElements {
Tristrips(Tristrips)
}

impl PrimitiveElements {
/// Retrieve the element's list of inputs regardless of the specific variant.
///
/// All primitive elements have a list of <input> (shared) elements, so this utility method
/// retrieves the `&[InputShared]` from the primitive element regardless of the variant.
pub fn input(&self) -> &[InputShared] {
match *self {
PrimitiveElements::Lines(ref element) => &*element.input,
PrimitiveElements::Linestrips(ref element) => &*element.input,
PrimitiveElements::Polygons(ref element) => &*element.input,
PrimitiveElements::Polylist(ref element) => &*element.input,
PrimitiveElements::Triangles(ref element) => &*element.input,
PrimitiveElements::Trifans(ref element) => &*element.input,
PrimitiveElements::Tristrips(ref element) => &*element.input,
}
}

pub fn count(&self) -> usize {
match *self {
PrimitiveElements::Lines(ref element) => element.count,
PrimitiveElements::Linestrips(ref element) => element.count,
PrimitiveElements::Polygons(ref element) => element.count,
PrimitiveElements::Polylist(ref element) => element.count,
PrimitiveElements::Triangles(ref element) => element.count,
PrimitiveElements::Trifans(ref element) => element.count,
PrimitiveElements::Tristrips(ref element) => element.count,
}
}
}

#[derive(Debug, Clone)]
pub enum Profile {
Bridge(ProfileBridge),
Expand Down Expand Up @@ -1635,8 +1708,25 @@ collada_element!("triangles", Triangles => {
rep child extra: Extra
});

collada_element!("trifans", Trifans => {});
collada_element!("tristrips", Tristrips => {});
collada_element!("trifans", Trifans => {
req attrib count: usize
opt attrib name: String,
opt attrib material: String

rep child input: InputShared,
rep child p: Primitive,
rep child extra: Extra
});

collada_element!("tristrips", Tristrips => {
req attrib count: usize
opt attrib name: String,
opt attrib material: String

rep child input: InputShared,
rep child p: Primitive,
rep child extra: Extra
});

collada_element!("unit", Unit => {
opt attrib name: String,
Expand Down Expand Up @@ -1699,6 +1789,10 @@ impl ColladaAttribute for UriFragment {
}
}

collada_element!("vcount", VCount => {
contents: Vec<usize>
});

collada_element!("vertices", Vertices => {
req attrib id: String
opt attrib name: String
Expand Down

0 comments on commit 953ac4b

Please sign in to comment.