Skip to content
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

Introduces GZ_MESH_FORCE_ASSIMP flag #403

Merged
6 changes: 5 additions & 1 deletion graphics/include/gz/common/MeshManager.hh
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,12 @@ namespace gz
const gz::math::Vector2d &_segments,
const gz::math::Vector2d &_uvTile);

/// \brief Sets the forceAssimp flag by reading the GZ_MESH_FORCE_ASSIMP
/// environment variable. If forceAssimp true, MeshManager uses Assimp
/// for loading all mesh formats, otherwise only for GLTF and FBX.
public: void SetAssimpEnvs();

/// \brief Tesselate a 2D mesh
///
/// Makes a zigzag pattern compatible with strips
/// \param[in] _sm the mesh to tesselate
/// \param[in] _meshWith mesh width
Expand Down
46 changes: 34 additions & 12 deletions graphics/src/MeshManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ class gz::common::MeshManager::Implementation

/// \brief Mutex to protect the mesh map
public: std::mutex mutex;

/// \brief True if assimp is used for loading all supported mesh formats
public: bool forceAssimp;
#ifdef _WIN32
#pragma warning(pop)
#endif
Expand Down Expand Up @@ -145,21 +148,27 @@ const Mesh *MeshManager::Load(const std::string &_filename)
std::transform(extension.begin(), extension.end(),
extension.begin(), ::tolower);
MeshLoader *loader = nullptr;

loader = &this->dataPtr->assimpLoader;
/*
if (extension == "stl" || extension == "stlb" || extension == "stla")
loader = &this->dataPtr->stlLoader;
else if (extension == "dae")
loader = &this->dataPtr->colladaLoader;
else if (extension == "obj")
loader = &this->dataPtr->objLoader;
this->SetAssimpEnvs();
if (this->dataPtr->forceAssimp)
{
loader = &this->dataPtr->assimpLoader;
}
else
{
gzerr << "Unsupported mesh format for file[" << _filename << "]\n";
return nullptr;
if (extension == "stl" || extension == "stlb" || extension == "stla")
loader = &this->dataPtr->stlLoader;
else if (extension == "dae")
loader = &this->dataPtr->colladaLoader;
else if (extension == "obj")
loader = &this->dataPtr->objLoader;
else if (extension == "gltf" || extension == "glb" || extension == "fbx")
loader = &this->dataPtr->assimpLoader;
else
{
gzerr << "Unsupported mesh format for file[" << _filename << "]\n";
return nullptr;
}
}
*/
// This mutex prevents two threads from loading the same mesh at the
// same time.
std::lock_guard<std::mutex> lock(this->dataPtr->mutex);
Expand Down Expand Up @@ -1623,3 +1632,16 @@ void MeshManager::ConvertPolylinesToVerticesAndEdges(
}
}
}

//////////////////////////////////////////////////
void MeshManager::SetAssimpEnvs()
{
std::string forceAssimpEnv;
common::env("GZ_MESH_FORCE_ASSIMP", forceAssimpEnv);
this->dataPtr->forceAssimp = false;
if (forceAssimpEnv == "true")
{
gzmsg << "Using assimp to load all mesh formats" << std::endl;
this->dataPtr->forceAssimp = true;
}
}