Basic mesh parsing.

The test scene isn't rendering properly, presumably because
something isn't correct in the parsing (although it's not clear
it's in the mesh parsing).  Need to investigate.
This commit is contained in:
Nathan Vegdahl 2016-05-28 01:03:56 -07:00
parent 99dc371a75
commit e3db7cd6ca
3 changed files with 59 additions and 4 deletions

View File

@ -197,6 +197,33 @@ mod test {
assert_eq!(ws_i64(b" -42 53"), Done(&b"53"[..], -42));
}
#[test]
fn ws_usize_1() {
assert_eq!(ws_usize(b"42"), Done(&b""[..], 42));
assert_eq!(ws_usize(b" 42"), Done(&b""[..], 42));
assert_eq!(ws_usize(b"42 "), Done(&b""[..], 42));
assert_eq!(ws_usize(b" 42"), Done(&b""[..], 42));
assert_eq!(ws_usize(b" 42 53"), Done(&b"53"[..], 42));
}
#[test]
fn ws_isize_1() {
assert_eq!(ws_isize(b"42"), Done(&b""[..], 42));
assert_eq!(ws_isize(b" 42"), Done(&b""[..], 42));
assert_eq!(ws_isize(b"42 "), Done(&b""[..], 42));
assert_eq!(ws_isize(b" 42"), Done(&b""[..], 42));
assert_eq!(ws_isize(b" 42 53"), Done(&b"53"[..], 42));
}
#[test]
fn ws_isize_2() {
assert_eq!(ws_isize(b"-42"), Done(&b""[..], -42));
assert_eq!(ws_isize(b" -42"), Done(&b""[..], -42));
assert_eq!(ws_isize(b"-42 "), Done(&b""[..], -42));
assert_eq!(ws_isize(b" -42 "), Done(&b""[..], -42));
assert_eq!(ws_isize(b" -42 53"), Done(&b"53"[..], -42));
}
#[test]
fn ws_f32_1() {
assert_eq!(ws_f32(b"42"), Done(&b""[..], 42.0));

View File

@ -4,8 +4,9 @@ use std::result::Result;
use super::DataTree;
use super::psy::{parse_matrix, PsyParseError};
use super::psy_mesh_surface::parse_mesh_surface;
use assembly::{Assembly, AssemblyBuilder};
use assembly::{Assembly, AssemblyBuilder, Object};
pub fn parse_assembly(tree: &DataTree) -> Result<Assembly, PsyParseError> {
let mut builder = AssemblyBuilder::new();
@ -58,7 +59,12 @@ pub fn parse_assembly(tree: &DataTree) -> Result<Assembly, PsyParseError> {
// MeshSurface
"MeshSurface" => {
// TODO: call mesh surface parsing function once it's written
if let &DataTree::Internal {ident: Some(ident), ..} = child {
builder.add_object(ident, Object::Surface(Box::new(try!(parse_mesh_surface(&child)))));
} else {
// TODO: error condition of some kind, because no ident
panic!();
}
}
_ => {

View File

@ -30,6 +30,7 @@ pub fn parse_mesh_surface(tree: &DataTree) -> Result<TriangleMesh, PsyParseError
// Get verts
// TODO: store vert count for a single round and make sure all rounds
// have the same count.
let mut time_samples = 0;
for (_, text) in tree.iter_leaf_children_with_type("Vertices") {
let mut raw_text = text.trim().as_bytes();
@ -40,6 +41,8 @@ pub fn parse_mesh_surface(tree: &DataTree) -> Result<TriangleMesh, PsyParseError
verts.push(Point::new(vert.0, vert.1, vert.2));
}
time_samples += 1;
}
// Get face vert counts
@ -64,6 +67,25 @@ pub fn parse_mesh_surface(tree: &DataTree) -> Result<TriangleMesh, PsyParseError
}
}
// TODO: build triangle mesh
unimplemented!();
// Build triangle mesh
// TODO: time samples
let mut triangles = Vec::new();
let mut ii = 0;
for fvc in face_vert_counts.iter() {
if *fvc >= 3 {
let v1 = ii;
for vi in 0..(fvc - 2) {
triangles.push((verts[face_vert_indices[v1]],
verts[face_vert_indices[v1 + vi + 1]],
verts[face_vert_indices[v1 + vi + 2]]));
}
} else {
// TODO: proper error
panic!();
}
ii += *fvc;
}
Ok(TriangleMesh::from_triangles(time_samples, triangles))
}