23 std::string filepath(obj_path);
31 *num_meshes = loaded_objs.size();
32 for (
auto& mesh : loaded_objs)
33 mesh.PerformRotation(xrot, yrot, zrot);
37 for (
int i = 0; i < *num_meshes; i++) {
41 *out_data_array = data_array;
46 return HF_STATUS::INVALID_OBJ;
49 return HF_STATUS::NOT_FOUND;
52 std::cerr <<
"Generic Error" << std::endl;
53 return HF_STATUS::GENERIC_ERROR;
63 const float* vertices,
69 vector<float> vertex_array(vertices, vertices + num_vertices);
70 vector<int> index_array(indices, indices + num_indices);
71 std::string mesh_name(name);
75 *out_info =
new MeshInfo<float>(vertex_array, index_array,
id, mesh_name);
86 if (mesh_to_rotate->
meshid < 0)
87 return HF_STATUS::INVALID_OBJ;
99 *vertex_out = mesh_vertices.data;
100 *num_vertices = mesh_vertices.size / 3;
102 *index_out = mesh_indices.data;
103 *num_triangles = mesh_indices.size / 3;
105 return HF_STATUS::OK;
110 auto name = MI->
name;
112 int num_characters = name.size()+1;
113 *out_name =
new char[num_characters];
114 std::copy(name.c_str(), name.c_str() + num_characters, *out_name);
116 return HF_STATUS::OK;
121 return HF_STATUS::OK;
Contains definitions for the Exceptions namespace.
Contains definitions for the MeshInfo class.
Contains definitions for the Geometry namespace.
void DeleteRawPtr(T *ptr)
Delete some object pointed to by ptr
Header file for functions related to loading/storing an OBJ file (a mesh)
C_INTERFACE LoadOBJ(const char *obj_path, HF::Geometry::GROUP_METHOD gm, float xrot, float yrot, float zrot, MeshInfo< float > ***out_data_array, int *num_meshes)
Load an obj from the given path then rotate it by x,y, and z.
C_INTERFACE DestroyMeshInfo(MeshInfo< float > *mesh_to_destroy)
Free the memory addressed by mesh_to_destroy, which was allocated by either LoadOBJ or StoreMesh.
C_INTERFACE GetMeshName(const HF::Geometry::MeshInfo< float > *MI, char **out_name)
Get the name of a mesh.
C_INTERFACE StoreMesh(MeshInfo< float > **out_info, const int *indices, int num_indices, const float *vertices, int num_vertices, const char *name, int id)
Store a mesh in a format usable with DHARTAPI.
C_INTERFACE GetVertsAndTris(const MeshInfo< float > *MI, int **index_out, int *num_triangles, float **vertex_out, int *num_vertices)
Get a pointer to and the size of a mesh's triangle and vertex arrays.
C_INTERFACE RotateMesh(MeshInfo< float > *mesh_to_rotate, float xrot, float yrot, float zrot)
Rotate an existing mesh (HF::Geometry::MeshInfo)
C_INTERFACE DestroyMeshInfoPtrArray(MeshInfo< float > **data_array)
C_INTERFACE GetMeshID(const HF::Geometry::MeshInfo< float > *MI, int *out_id)
Get the ID of a mesh.
Custom exceptions and error codes used interally by DHARTAPI.
@ INVALID_OBJ
The given path did not point to a valid obj file.
@ OK
Operation was successful.
Manipulate and load geometry from disk.
vector< MeshInfo< float > > LoadMeshObjects(std::string path, GROUP_METHOD gm, bool change_coords, int scale)
Create MeshInfo instances from the OBJ at path.
GROUP_METHOD
Method of grouping submeshes in OBJ files.
Thrown when desired file is not found.
The OBJ file was not valid.
A collection of vertices and indices representing geometry.
void PerformRotation(numeric_type rx, numeric_type ry, numeric_type rz)
Rotate this mesh by x, y, z rotations in degrees (pitch, yaw, roll).
int meshid
Identifier for this mesh.
std::string name
A human-readable title.
const array_and_size< int > GetIndexPointer() const
Get a pointer to the index array of this mesh.
const array_and_size< numeric_type > GetVertexPointer() const
Get a pointer to the vertex array of this mesh.