-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add support for parsing rOBJ and rCAM chunks #30
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ target | |
Cargo.lock | ||
.vscode | ||
.idea/ | ||
*.iml | ||
*.iml | ||
.DS_Store |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,8 @@ pub enum Chunk { | |
Pack(Model), | ||
Palette(Vec<u32>), | ||
Material(Material), | ||
RenderObjects(Dict), | ||
RenderCamera(RenderCamera), | ||
TransformNode(SceneTransform), | ||
GroupNode(SceneGroup), | ||
ShapeNode(SceneShape), | ||
|
@@ -41,6 +43,15 @@ pub struct Material { | |
pub properties: Dict, | ||
} | ||
|
||
/// A material used to render this model. | ||
#[derive(Clone, Debug, PartialEq, Eq)] | ||
pub struct RenderCamera { | ||
/// The Cameras's ID. | ||
pub id: u32, | ||
/// Properties of the camera, mapped by property name. | ||
pub properties: Dict, | ||
} | ||
|
||
// TODO: maybe material schemas? | ||
impl Material { | ||
/// The '_type' field, if present | ||
|
@@ -56,9 +67,10 @@ impl Material { | |
pub fn weight(&self) -> Option<f32> { | ||
let w = self.get_f32("_weight"); | ||
|
||
if let Some(w) = w && (w < 0.0 || w > 1.0) | ||
{ | ||
debug!("_weight observed outside of range of [0..1]: {}", w); | ||
if let Some(w) = w { | ||
if w < 0.0 || w > 1.0 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you're going to change unrelated code, please do it in a separate PR There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, not sure if this is still a problem in the latest main branch, will check and see. It was preventing me from compiling at all, but yeah I probably shouldn't have included in the PR :) |
||
debug!("_weight observed outside of range of [0..1]: {}", w); | ||
} | ||
} | ||
|
||
w | ||
|
@@ -183,6 +195,8 @@ fn map_chunk_to_data(version: u32, main: Chunk) -> DotVoxData { | |
let mut models: Vec<Model> = vec![]; | ||
let mut palette_holder: Vec<u32> = DEFAULT_PALETTE.to_vec(); | ||
let mut materials: Vec<Material> = vec![]; | ||
let mut render_objects: Vec<Dict> = vec![]; | ||
let mut render_cameras: Vec<RenderCamera> = vec![]; | ||
let mut scene: Vec<SceneNode> = vec![]; | ||
let mut layers: Vec<Layer> = Vec::new(); | ||
|
||
|
@@ -197,6 +211,8 @@ fn map_chunk_to_data(version: u32, main: Chunk) -> DotVoxData { | |
Chunk::Pack(model) => models.push(model), | ||
Chunk::Palette(palette) => palette_holder = palette, | ||
Chunk::Material(material) => materials.push(material), | ||
Chunk::RenderObjects(dict) => render_objects.push(dict), | ||
Chunk::RenderCamera(camera) => render_cameras.push(camera), | ||
Chunk::TransformNode(scene_transform) => { | ||
scene.push(SceneNode::Transform { | ||
attributes: scene_transform.header.attributes, | ||
|
@@ -238,6 +254,8 @@ fn map_chunk_to_data(version: u32, main: Chunk) -> DotVoxData { | |
models, | ||
palette: palette_holder, | ||
materials, | ||
render_objects, | ||
render_cameras, | ||
scenes: scene, | ||
layers, | ||
} | ||
|
@@ -247,6 +265,8 @@ fn map_chunk_to_data(version: u32, main: Chunk) -> DotVoxData { | |
models: vec![], | ||
palette: vec![], | ||
materials: vec![], | ||
render_objects: vec![], | ||
render_cameras: vec![], | ||
scenes: vec![], | ||
layers: vec![], | ||
}, | ||
|
@@ -270,6 +290,8 @@ fn build_chunk(id: &str, chunk_content: &[u8], children_size: u32, child_content | |
"PACK" => build_pack_chunk(chunk_content), | ||
"RGBA" => build_palette_chunk(chunk_content), | ||
"MATL" => build_material_chunk(chunk_content), | ||
"rOBJ" => build_render_objects_chunk(chunk_content), | ||
"rCAM" => build_render_camera_chunk(chunk_content), | ||
"nTRN" => build_scene_transform_chunk(chunk_content), | ||
"nGRP" => build_scene_group_chunk(chunk_content), | ||
"nSHP" => build_scene_shape_chunk(chunk_content), | ||
|
@@ -305,6 +327,19 @@ fn build_material_chunk(chunk_content: &[u8]) -> Chunk { | |
} | ||
Chunk::Invalid(chunk_content.to_vec()) | ||
} | ||
fn build_render_camera_chunk(chunk_content: &[u8]) -> Chunk { | ||
if let Ok((_, camera)) = parse_render_camera(chunk_content) { | ||
return Chunk::RenderCamera(camera); | ||
} | ||
Chunk::Invalid(chunk_content.to_vec()) | ||
} | ||
|
||
fn build_render_objects_chunk(chunk_content: &[u8]) -> Chunk { | ||
if let Ok((_, dict)) = parse_dict(chunk_content) { | ||
return Chunk::RenderObjects(dict); | ||
} | ||
Chunk::Invalid(chunk_content.to_vec()) | ||
} | ||
|
||
fn build_palette_chunk(chunk_content: &[u8]) -> Chunk { | ||
if let Ok((_, palette)) = palette::extract_palette(chunk_content) { | ||
|
@@ -374,6 +409,11 @@ pub fn parse_material(i: &[u8]) -> IResult<&[u8], Material> { | |
Ok((i, Material { id, properties })) | ||
} | ||
|
||
pub fn parse_render_camera(i: &[u8]) -> IResult<&[u8], RenderCamera> { | ||
let (i, (id, properties)) = pair(le_u32, parse_dict)(i)?; | ||
Ok((i, RenderCamera { id, properties })) | ||
} | ||
|
||
pub(crate) fn parse_dict(i: &[u8]) -> IResult<&[u8], Dict> { | ||
let (i, n) = le_u32(i)?; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
[ | ||
[ | ||
0, | ||
{ | ||
"_angle": "0 0 0", | ||
"_focus": "0 0 0", | ||
"_fov": "45", | ||
"_frustum": "0.414214", | ||
"_mode": "pers", | ||
"_radius": "0" | ||
} | ||
], | ||
[ | ||
1, | ||
{ | ||
"_angle": "0 0 0", | ||
"_focus": "0 0 0", | ||
"_fov": "45", | ||
"_frustum": "0.414214", | ||
"_mode": "pers", | ||
"_radius": "0" | ||
} | ||
], | ||
[ | ||
2, | ||
{ | ||
"_angle": "0 0 0", | ||
"_focus": "0 0 0", | ||
"_fov": "45", | ||
"_frustum": "0.414214", | ||
"_mode": "pers", | ||
"_radius": "0" | ||
} | ||
], | ||
[ | ||
3, | ||
{ | ||
"_angle": "0 0 0", | ||
"_focus": "0 0 0", | ||
"_fov": "45", | ||
"_frustum": "0.414214", | ||
"_mode": "pers", | ||
"_radius": "0" | ||
} | ||
], | ||
[ | ||
4, | ||
{ | ||
"_angle": "0 0 0", | ||
"_focus": "0 0 0", | ||
"_fov": "45", | ||
"_frustum": "0.414214", | ||
"_mode": "pers", | ||
"_radius": "0" | ||
} | ||
], | ||
[ | ||
5, | ||
{ | ||
"_angle": "0 0 0", | ||
"_focus": "0 0 0", | ||
"_fov": "45", | ||
"_frustum": "0.414214", | ||
"_mode": "pers", | ||
"_radius": "0" | ||
} | ||
], | ||
[ | ||
6, | ||
{ | ||
"_angle": "0 0 0", | ||
"_focus": "0 0 0", | ||
"_fov": "45", | ||
"_frustum": "0.414214", | ||
"_mode": "pers", | ||
"_radius": "0" | ||
} | ||
], | ||
[ | ||
7, | ||
{ | ||
"_angle": "0 0 0", | ||
"_focus": "0 0 0", | ||
"_fov": "45", | ||
"_frustum": "0.414214", | ||
"_mode": "pers", | ||
"_radius": "0" | ||
} | ||
], | ||
[ | ||
8, | ||
{ | ||
"_angle": "0 0 0", | ||
"_focus": "0 0 0", | ||
"_fov": "45", | ||
"_frustum": "0.414214", | ||
"_mode": "pers", | ||
"_radius": "0" | ||
} | ||
], | ||
[ | ||
9, | ||
{ | ||
"_angle": "0 0 0", | ||
"_focus": "0 0 0", | ||
"_fov": "45", | ||
"_frustum": "0.414214", | ||
"_mode": "pers", | ||
"_radius": "0" | ||
} | ||
] | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you re-export RenderCamera in the crate root and use it directly?