Skip to content

Commit

Permalink
Remove ply reader. Contains security flaw due depending on vulnerable…
Browse files Browse the repository at this point in the history
… linked-hash-map, not in use anyway.
  • Loading branch information
bourumir-wyngs committed Dec 5, 2024
1 parent 5072d61 commit c369dba
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 62 deletions.
2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ parry3d = { version = "0.17", optional = true }
# Palellization of collision
rayon = { version = "1.10", optional = true }

# For loading meshes, needed for collision and visualization
ply-rs = { version = "0.1", optional = true }
stl_io = { version = "0.8", optional = true }

# Needed for visualization. We must disable audio by not including
Expand Down
60 changes: 0 additions & 60 deletions src/read_trimesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,67 +8,7 @@ use std::fs::File;
use std::io::BufReader;
use nalgebra::Point3;

/// Function to load a TriMesh from a PLY file
#[allow(dead_code)]
pub fn load_trimesh_from_ply(ply_file_path: &str) -> TriMesh {
// Open the file
let file = File::open(ply_file_path)
.expect(&format!("Could not open PLY file: {}", ply_file_path));
let mut reader = BufReader::new(file);

// Create a PLY parser and parse the header
let parser = Parser::<DefaultElement>::new();
let ply = parser.read_ply(&mut reader)
.expect(&format!("Could not parse PLY file: {}", ply_file_path));

// Extract vertices and faces from the PLY file
let mut vertices = Vec::new();
let mut indices = Vec::new();

// Extract vertices
if let Some(vertices_elem) = ply.payload.get("vertex") {
for vertex in vertices_elem {
let x = match vertex.get("x").unwrap() {
Property::Float(val) => *val,
Property::Double(val) => *val as f32,
_ => panic!("Unexpected type for vertex x"),
};
let y = match vertex.get("y").unwrap() {
Property::Float(val) => *val,
Property::Double(val) => *val as f32,
_ => panic!("Unexpected type for vertex y"),
};
let z = match vertex.get("z").unwrap() {
Property::Float(val) => *val,
Property::Double(val) => *val as f32,
_ => panic!("Unexpected type for vertex z"),
};

vertices.push([x, y, z].into()); // Push vertex to the vertices list
}
}

// Extract faces (indices)
if let Some(faces_elem) = ply.payload.get("face") {
for face in faces_elem {
if let Property::ListUInt(indices_list) = face.get("vertex_indices").unwrap() {
let i1 = indices_list[0];
let i2 = indices_list[1];
let i3 = indices_list[2];
indices.push([i1, i2, i3].into()); // Push triangle indices
} else {
panic!("Unexpected type for face indices");
}
}
}

// Create a TriMesh from vertices and indices
TriMesh::with_flags(vertices, indices,
TriMeshFlags::FIX_INTERNAL_EDGES | TriMeshFlags::MERGE_DUPLICATE_VERTICES)
}

/// Function to load a TriMesh from an STL file
#[allow(dead_code)]
pub fn load_trimesh_from_stl(stl_file_path: &str) -> TriMesh {
// Open the STL file
let file = File::open(stl_file_path)
Expand Down

0 comments on commit c369dba

Please sign in to comment.