Encapsulate mjCMesh data, apply Google C++ naming convention to class members (See https://google.github.io/styleguide/cppguide.html#Variable_Names), and fix a couple of typos.
PiperOrigin-RevId: 553129088 Change-Id: Ic515154220af472f4fc90ca9ade92d86b205cc94
This commit is contained in:
+522
-397
File diff suppressed because it is too large
Load Diff
+35
-35
@@ -828,7 +828,7 @@ void mjCModel::SetDefaultNames(void) {
|
||||
// meshes
|
||||
for (int i=0; i<meshes.size(); i++) {
|
||||
if (meshes[i]->name.empty()) {
|
||||
stripped = mjuu_strippath(meshes[i]->file);
|
||||
stripped = mjuu_strippath(meshes[i]->file());
|
||||
meshes[i]->name = mjuu_stripext(stripped);
|
||||
|
||||
// name cannot be empty
|
||||
@@ -934,12 +934,12 @@ void mjCModel::SetSizes(void) {
|
||||
|
||||
// nmeshvert, nmeshface, nmeshtexcoord, nmeshgraph
|
||||
for (int i=0; i<nmesh; i++) {
|
||||
nmeshvert += meshes[i]->nvert;
|
||||
nmeshnormal += meshes[i]->nnormal;
|
||||
nmeshface += meshes[i]->nface;
|
||||
nmeshtexcoord += (meshes[i]->texcoord ? meshes[i]->ntexcoord : 0);
|
||||
nmeshgraph += meshes[i]->szgraph;
|
||||
nbvh += meshes[i]->tree.nbvh;
|
||||
nmeshvert += meshes[i]->nvert();
|
||||
nmeshnormal += meshes[i]->nnormal();
|
||||
nmeshface += meshes[i]->nface();
|
||||
nmeshtexcoord += (meshes[i]->HasTexcoord() ? meshes[i]->ntexcoord() : 0);
|
||||
nmeshgraph += meshes[i]->szgraph();
|
||||
nbvh += meshes[i]->tree().nbvh;
|
||||
}
|
||||
|
||||
// nskinvert, nskintexvert, nskinface, nskinbone, nskinbonevert
|
||||
@@ -1712,43 +1712,43 @@ void mjCModel::CopyObjects(mjModel* m) {
|
||||
|
||||
// set fields
|
||||
m->mesh_vertadr[i] = vert_adr;
|
||||
m->mesh_vertnum[i] = pme->nvert;
|
||||
m->mesh_vertnum[i] = pme->nvert();
|
||||
m->mesh_normaladr[i] = normal_adr;
|
||||
m->mesh_normalnum[i] = pme->nnormal;
|
||||
m->mesh_texcoordadr[i] = (pme->texcoord ? texcoord_adr : -1);
|
||||
m->mesh_texcoordnum[i] = pme->ntexcoord;
|
||||
m->mesh_normalnum[i] = pme->nnormal();
|
||||
m->mesh_texcoordadr[i] = (pme->HasTexcoord() ? texcoord_adr : -1);
|
||||
m->mesh_texcoordnum[i] = pme->ntexcoord();
|
||||
m->mesh_faceadr[i] = face_adr;
|
||||
m->mesh_facenum[i] = pme->nface;
|
||||
m->mesh_graphadr[i] = (pme->szgraph ? graph_adr : -1);
|
||||
m->mesh_facenum[i] = pme->nface();
|
||||
m->mesh_graphadr[i] = (pme->szgraph() ? graph_adr : -1);
|
||||
m->mesh_bvhadr[i] = bvh_adr;
|
||||
m->mesh_bvhnum[i] = pme->tree.nbvh;
|
||||
m->mesh_bvhnum[i] = pme->tree().nbvh;
|
||||
|
||||
// copy vertices, normals, faces, texcoords, aux data
|
||||
memcpy(m->mesh_vert + 3*vert_adr, pme->vert, 3*pme->nvert*sizeof(float));
|
||||
memcpy(m->mesh_normal + 3*normal_adr, pme->normal, 3*pme->nnormal*sizeof(float));
|
||||
memcpy(m->mesh_face + 3*face_adr, pme->face, 3*pme->nface*sizeof(float));
|
||||
memcpy(m->mesh_facenormal + 3*face_adr, pme->facenormal, 3*pme->nface*sizeof(int));
|
||||
if (pme->texcoord) {
|
||||
memcpy(m->mesh_texcoord + 2*texcoord_adr, pme->texcoord, 2*pme->ntexcoord*sizeof(float));
|
||||
memcpy(m->mesh_facetexcoord + 3*face_adr, pme->facetexcoord, 3*pme->nface*sizeof(int));
|
||||
pme->CopyVert(m->mesh_vert + 3*vert_adr);
|
||||
pme->CopyNormal(m->mesh_normal + 3*normal_adr);
|
||||
pme->CopyFace(m->mesh_face + 3*face_adr);
|
||||
pme->CopyFaceNormal(m->mesh_facenormal + 3*face_adr);
|
||||
if (pme->HasTexcoord()) {
|
||||
pme->CopyTexcoord(m->mesh_texcoord + 2*texcoord_adr);
|
||||
pme->CopyFaceTexcoord(m->mesh_facetexcoord + 3*face_adr);
|
||||
} else {
|
||||
memset(m->mesh_facetexcoord + 3*face_adr, 0, 3*pme->nface*sizeof(int));
|
||||
memset(m->mesh_facetexcoord + 3*face_adr, 0, 3*pme->nface()*sizeof(int));
|
||||
}
|
||||
if (pme->szgraph) {
|
||||
memcpy(m->mesh_graph + graph_adr, pme->graph, pme->szgraph*sizeof(int));
|
||||
if (pme->szgraph()) {
|
||||
pme->CopyGraph(m->mesh_graph + graph_adr);
|
||||
}
|
||||
memcpy(m->bvh_aabb + 6*bvh_adr, pme->tree.bvh.data(), 6*pme->tree.nbvh*sizeof(mjtNum));
|
||||
memcpy(m->bvh_child + 2*bvh_adr, pme->tree.child.data(), 2*pme->tree.nbvh*sizeof(int));
|
||||
memcpy(m->bvh_depth + bvh_adr, pme->tree.level.data(), pme->tree.nbvh*sizeof(int));
|
||||
memcpy(m->bvh_geomid + bvh_adr, pme->tree.nodeid.data(), pme->tree.nbvh*sizeof(int));
|
||||
memcpy(m->bvh_aabb + 6*bvh_adr, pme->tree().bvh.data(), 6*pme->tree().nbvh*sizeof(mjtNum));
|
||||
memcpy(m->bvh_child + 2*bvh_adr, pme->tree().child.data(), 2*pme->tree().nbvh*sizeof(int));
|
||||
memcpy(m->bvh_depth + bvh_adr, pme->tree().level.data(), pme->tree().nbvh*sizeof(int));
|
||||
memcpy(m->bvh_geomid + bvh_adr, pme->tree().nodeid.data(), pme->tree().nbvh*sizeof(int));
|
||||
|
||||
// advance counters
|
||||
vert_adr += pme->nvert;
|
||||
normal_adr += pme->nnormal;
|
||||
texcoord_adr += (pme->texcoord ? pme->ntexcoord : 0);
|
||||
face_adr += pme->nface;
|
||||
graph_adr += pme->szgraph;
|
||||
bvh_adr += pme->tree.nbvh;
|
||||
vert_adr += pme->nvert();
|
||||
normal_adr += pme->nnormal();
|
||||
texcoord_adr += (pme->HasTexcoord() ? pme->ntexcoord() : 0);
|
||||
face_adr += pme->nface();
|
||||
graph_adr += pme->szgraph();
|
||||
bvh_adr += pme->tree().nbvh;
|
||||
}
|
||||
|
||||
// skins
|
||||
@@ -2535,7 +2535,7 @@ void mjCModel::TryCompile(mjModel*& m, mjData*& d, int vfs_provider) {
|
||||
for (int i=0; i<geoms.size(); i++) {
|
||||
if (geoms[i]->meshid>=0 && geoms[i]->type==mjGEOM_MESH &&
|
||||
(geoms[i]->contype || geoms[i]->conaffinity)) {
|
||||
meshes[geoms[i]->meshid]->needhull = true;
|
||||
meshes[geoms[i]->meshid]->set_needhull(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1302,7 +1302,8 @@ double mjCGeom::GetVolume(void) {
|
||||
if (model->exactmeshinertia || typeinertia==mjSHELL_MESH) {
|
||||
return pmesh->GetVolumeRef(typeinertia);
|
||||
} else {
|
||||
return pmesh->boxsz_volume[0]*pmesh->boxsz_volume[1]*pmesh->boxsz_volume[2]*8;
|
||||
const double* boxsz_volume = pmesh->boxsz_volume();
|
||||
return boxsz_volume[0]*boxsz_volume[1]*boxsz_volume[2]*8;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1419,7 +1420,7 @@ void mjCGeom::SetInertia(void) {
|
||||
|
||||
// compute radius of bounding sphere
|
||||
double mjCGeom::GetRBound(void) {
|
||||
double* aabb;
|
||||
const double* aabb;
|
||||
double haabb[3] = {0};
|
||||
|
||||
switch (type) {
|
||||
@@ -1439,7 +1440,7 @@ double mjCGeom::GetRBound(void) {
|
||||
return sqrt(size[0]*size[0]+size[1]*size[1]+size[2]*size[2]);
|
||||
|
||||
case mjGEOM_MESH:
|
||||
aabb = model->meshes[meshid]->aabb;
|
||||
aabb = model->meshes[meshid]->aabb();
|
||||
haabb[0] = mjMAX(fabs(aabb[0]), fabs(aabb[3]));
|
||||
haabb[1] = mjMAX(fabs(aabb[1]), fabs(aabb[4]));
|
||||
haabb[2] = mjMAX(fabs(aabb[2]), fabs(aabb[5]));
|
||||
@@ -1585,7 +1586,7 @@ void mjCGeom::ComputeAABB() {
|
||||
break;
|
||||
|
||||
case mjGEOM_MESH:
|
||||
mjuu_copyvec(aabb, model->meshes[meshid]->aabb, 6);
|
||||
mjuu_copyvec(aabb, model->meshes[meshid]->aabb(), 6);
|
||||
break;
|
||||
|
||||
case mjGEOM_PLANE:
|
||||
@@ -1752,7 +1753,7 @@ void mjCGeom::Compile(void) {
|
||||
size[1] = model->hfields[hfieldid]->size[1];
|
||||
size[2] = 0.5*(model->hfields[hfieldid]->size[2]+model->hfields[hfieldid]->size[3]);
|
||||
} else if (type==mjGEOM_MESH) {
|
||||
double* aabb = model->meshes[meshid]->aabb;
|
||||
const double* aabb = model->meshes[meshid]->aabb();
|
||||
size[0] = mjMAX(fabs(aabb[0]), fabs(aabb[3]));
|
||||
size[1] = mjMAX(fabs(aabb[1]), fabs(aabb[4]));
|
||||
size[2] = mjMAX(fabs(aabb[2]), fabs(aabb[5]));
|
||||
|
||||
+109
-56
@@ -15,7 +15,9 @@
|
||||
#ifndef MUJOCO_SRC_USER_USER_OBJECTS_H_
|
||||
#define MUJOCO_SRC_USER_USER_OBJECTS_H_
|
||||
|
||||
#include <array>
|
||||
#include <map>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -518,42 +520,93 @@ class mjCLight : public mjCBase {
|
||||
// Describes a mesh
|
||||
|
||||
class mjCMesh: public mjCBase {
|
||||
friend class mjCDef;
|
||||
friend class mjCGeom;
|
||||
friend class mjCBody;
|
||||
friend class mjCSkin;
|
||||
friend class mjCModel;
|
||||
friend class mjXWriter;
|
||||
|
||||
public:
|
||||
mjCMesh(mjCModel* = 0, mjCDef* = 0);
|
||||
~mjCMesh();
|
||||
|
||||
// public getters
|
||||
const std::string& content_type() const { return content_type_; }
|
||||
const std::string& file() const { return file_; }
|
||||
const double* refpos() const { return refpos_; }
|
||||
const double* refquat() const { return refquat_; }
|
||||
const double* scale() const { return scale_; }
|
||||
bool smoothnormal() const { return smoothnormal_; }
|
||||
|
||||
// public getters for user data
|
||||
const std::vector<float>& uservert() const { return uservert_; }
|
||||
const std::vector<float>& usernormal() const { return usernormal_; }
|
||||
const std::vector<float>& usertexcoord() const { return usertexcoord_; }
|
||||
const std::vector<int>& userface() const { return userface_; }
|
||||
|
||||
// mesh properites computed by Compile
|
||||
const double* boxsz_volume() const { return boxsz_volume_; }
|
||||
const double* aabb() const { return aabb_; }
|
||||
|
||||
// number of vertices, normals, texture coordinates, and faces
|
||||
int nvert() const { return nvert_; }
|
||||
int nnormal() const { return nnormal_; }
|
||||
int ntexcoord() const { return ntexcoord_; }
|
||||
int nface() const { return nface_; }
|
||||
|
||||
// return size of graph data in ints
|
||||
int szgraph() const { return szgraph_; }
|
||||
|
||||
// bounding volume hierarchy tree
|
||||
const mjCBoundingVolumeHierarchy& tree() { return tree_; }
|
||||
|
||||
// general setters
|
||||
void set_file(const std::string& file);
|
||||
void set_scale(std::array<double, 3> scale);
|
||||
void set_smoothnormal(bool smoothnormal);
|
||||
void set_needhull(bool needhull);
|
||||
|
||||
// setters used in reading XML attributes (no-op if empty optional)
|
||||
void set_content_type(std::optional<std::string>&& content_type);
|
||||
void set_file(std::optional<std::string>&& file);
|
||||
void set_refpos(std::optional<std::array<double, 3>> refpos);
|
||||
void set_refquat(std::optional<std::array<double, 4>> refquat);
|
||||
void set_scale(std::optional<std::array<double, 3>> scale);
|
||||
|
||||
void set_uservert(std::optional<std::vector<float>>&& uservert);
|
||||
void set_usernormal(std::optional<std::vector<float>>&& usernormal);
|
||||
void set_usertexcoord(std::optional<std::vector<float>>&& usertexcoord);
|
||||
void set_userface(std::optional<std::vector<int>>&& userface);
|
||||
|
||||
void Compile(int vfs_provider); // compiler
|
||||
double* GetPosPtr(mjtMeshType type); // get position
|
||||
double* GetQuatPtr(mjtMeshType type); // get orientation
|
||||
double* GetInertiaBoxPtr(mjtMeshType type); // get inertia box
|
||||
double& GetVolumeRef(mjtMeshType type); // get volume
|
||||
void FitGeom(mjCGeom* geom, double* meshpos); // approximate mesh with simple geom
|
||||
bool HasTexcoord() const; // texcoord not null
|
||||
|
||||
void CopyVert(float* arr) const; // copy vert data into array
|
||||
void CopyNormal(float* arr) const; // copy normal data into array
|
||||
void CopyFace(int* arr) const; // copy face data into array
|
||||
void CopyFaceNormal(int* arr) const; // copy face normal data into array
|
||||
void CopyFaceTexcoord(int* arr) const; // copy face texcoord data into array
|
||||
void CopyTexcoord(float* arr) const; // copy texcoord data into array
|
||||
void CopyGraph(int* arr) const; // copy graph data into array
|
||||
|
||||
// returns a bounding volume given a face
|
||||
mjCBoundingVolume GetBoundingVolume(int faceid);
|
||||
|
||||
std::string content_type; // content type of file
|
||||
std::string file; // mesh file
|
||||
double refpos[3]; // reference position (translate)
|
||||
double refquat[4]; // reference orientation (rotate)
|
||||
double scale[3]; // rescale mesh
|
||||
bool smoothnormal; // do not exclude large-angle faces from normals
|
||||
|
||||
std::vector<float> uservert; // user vertex data
|
||||
std::vector<float> usernormal; // user normal data
|
||||
std::vector<float> usertexcoord; // user texcoord data
|
||||
std::vector<int> userface; // user vertex indices
|
||||
std::vector<int> userfacenormal; // user normal indices
|
||||
std::vector<int> userfacetexcoord; // user texcoord indices
|
||||
std::vector< std::pair<int, int> > useredge; // user half-edge data
|
||||
|
||||
private:
|
||||
mjCMesh(mjCModel* = 0, mjCDef* = 0); // constructor
|
||||
~mjCMesh(); // destructor
|
||||
void Compile(int vfs_provider); // compiler
|
||||
std::string content_type_; // content type of file
|
||||
std::string file_; // mesh file
|
||||
double refpos_[3]; // reference position (translate)
|
||||
double refquat_[4]; // reference orientation (rotate)
|
||||
double scale_[3]; // rescale mesh
|
||||
bool smoothnormal_; // do not exclude large-angle faces from normals
|
||||
|
||||
std::vector<float> uservert_; // user vertex data
|
||||
std::vector<float> usernormal_; // user normal data
|
||||
std::vector<float> usertexcoord_; // user texcoord data
|
||||
std::vector<int> userface_; // user vertex indices
|
||||
std::vector<int> userfacenormal_; // user normal indices
|
||||
std::vector<int> userfacetexcoord_; // user texcoord indices
|
||||
std::vector< std::pair<int, int> > useredge_; // user half-edge data
|
||||
|
||||
void LoadOBJ(mjResource* resource); // load mesh in wavefront OBJ format
|
||||
void LoadSTL(mjResource* resource); // load mesh in STL BIN format
|
||||
void LoadMSH(mjResource* resource); // load mesh in MSH BIN format
|
||||
@@ -572,43 +625,43 @@ class mjCMesh: public mjCBase {
|
||||
bool exactmeshinertia);
|
||||
|
||||
// mesh properties that indicate a well-formed mesh
|
||||
std::pair<int, int> invalidorientation; // indices of invalid edge; -1 if none
|
||||
bool validarea; // false if the area is too small
|
||||
int validvolume; // 0: volume is too small, -1: volume is negative
|
||||
bool valideigenvalue; // false if inertia eigenvalue is too small
|
||||
bool validinequality; // false if inertia inequality is not satisfied
|
||||
bool processed; // false if the mesh has not been processed yet
|
||||
std::pair<int, int> invalidorientation_; // indices of invalid edge; -1 if none
|
||||
bool validarea_; // false if the area is too small
|
||||
int validvolume_; // 0: volume is too small, -1: volume is negative
|
||||
bool valideigenvalue_; // false if inertia eigenvalue is too small
|
||||
bool validinequality_; // false if inertia inequality is not satisfied
|
||||
bool processed_; // false if the mesh has not been processed yet
|
||||
|
||||
// mesh properties computed by Compile
|
||||
double pos_volume[3]; // CoM position
|
||||
double pos_surface[3]; // CoM position
|
||||
double quat_volume[4]; // inertia orientation
|
||||
double quat_surface[4]; // inertia orientation
|
||||
double boxsz_volume[3]; // half-sizes of equivalent inertia box (volume)
|
||||
double boxsz_surface[3]; // half-sizes of equivalent inertia box (surface)
|
||||
double aabb[6]; // axis-aligned bounding box
|
||||
double volume; // volume of the mesh
|
||||
double surface; // surface of the mesh
|
||||
double pos_volume_[3]; // CoM position
|
||||
double pos_surface_[3]; // CoM position
|
||||
double quat_volume_[4]; // inertia orientation
|
||||
double quat_surface_[4]; // inertia orientation
|
||||
double boxsz_volume_[3]; // half-sizes of equivalent inertia box (volume)
|
||||
double boxsz_surface_[3]; // half-sizes of equivalent inertia box (surface)
|
||||
double aabb_[6]; // axis-aligned bounding box
|
||||
double volume_; // volume of the mesh
|
||||
double surface_; // surface of the mesh
|
||||
|
||||
// mesh data to be copied into mjModel
|
||||
int nvert; // number of vertices
|
||||
int nnormal; // number of normals
|
||||
int ntexcoord; // number of texcoords
|
||||
int nface; // number of faces
|
||||
int szgraph; // size of graph data in ints
|
||||
float* vert; // vertex data (3*nvert), relative to (pos, quat)
|
||||
float* normal; // vertex normal data (3*nnormal)
|
||||
double* center; // face circumcenter data (3*nface)
|
||||
float* texcoord; // vertex texcoord data (2*ntexcoord or NULL)
|
||||
int* face; // face vertex indices (3*nface)
|
||||
int* facenormal; // face normal indices (3*nface)
|
||||
int* facetexcoord; // face texcoord indices (3*nface)
|
||||
int* graph; // convex graph data
|
||||
int nvert_; // number of vertices
|
||||
int nnormal_; // number of normals
|
||||
int ntexcoord_; // number of texcoords
|
||||
int nface_; // number of faces
|
||||
int szgraph_; // size of graph data in ints
|
||||
float* vert_; // vertex data (3*nvert), relative to (pos, quat)
|
||||
float* normal_; // vertex normal data (3*nnormal)
|
||||
double* center_; // face circumcenter data (3*nface)
|
||||
float* texcoord_; // vertex texcoord data (2*ntexcoord or NULL)
|
||||
int* face_; // face vertex indices (3*nface)
|
||||
int* facenormal_; // face normal indices (3*nface)
|
||||
int* facetexcoord_; // face texcoord indices (3*nface)
|
||||
int* graph_; // convex graph data
|
||||
|
||||
bool needhull; // needs convex hull for collisions
|
||||
bool needhull_; // needs convex hull for collisions
|
||||
|
||||
mjCBoundingVolumeHierarchy tree; // bounding volume hierarchy
|
||||
std::vector<double> face_aabb; // bounding boxes of all faces
|
||||
mjCBoundingVolumeHierarchy tree_; // bounding volume hierarchy
|
||||
std::vector<double> face_aabb_; // bounding boxes of all faces
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user