Skip to content

Commit

Permalink
Use assimp for loading meshes (#393)
Browse files Browse the repository at this point in the history
Signed-off-by: Luca Della Vedova <[email protected]>
Signed-off by: Onur Berk Tore [email protected]
Signed-off-by: Louise Poubel <[email protected]>
Signed-off-by: Michael Carroll <[email protected]>

Co-authored-by: Onur Berk Töre <[email protected]>
Co-authored-by: Michael Carroll <[email protected]>
Co-authored-by: Louise Poubel <[email protected]>
  • Loading branch information
4 people authored Jul 30, 2022
1 parent 3224324 commit a27c7a1
Show file tree
Hide file tree
Showing 18 changed files with 1,749 additions and 44 deletions.
1 change: 1 addition & 0 deletions .github/ci/packages.apt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
libassimp-dev
libavcodec-dev
libavdevice-dev
libavformat-dev
Expand Down
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ gz_find_package(AVCODEC REQUIRED_BY av PRETTY libavcodec)
# Find avutil
gz_find_package(AVUTIL REQUIRED_BY av PRETTY libavutil)

#------------------------------------
# Find assimp
gz_find_package(GzAssimp REQUIRED_BY graphics PRETTY assimp)


message(STATUS "-------------------------------------------\n")

Expand Down
51 changes: 51 additions & 0 deletions graphics/include/gz/common/AssimpLoader.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright (C) 2022 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef GZ_COMMON_ASSIMPLOADER_HH_
#define GZ_COMMON_ASSIMPLOADER_HH_

#include <string>
#include <gz/common/graphics/Export.hh>
#include <gz/common/MeshLoader.hh>

#include <gz/utils/ImplPtr.hh>

namespace gz
{
namespace common
{
/// \class AssimpLoader AssimpLoader.hh gz/common/AssimpLoader.hh
/// \brief Class used to load mesh files using the assimp lodaer
class GZ_COMMON_GRAPHICS_VISIBLE AssimpLoader : public MeshLoader
{
/// \brief Constructor
public: AssimpLoader();

/// \brief Destructor
public: virtual ~AssimpLoader();

/// \brief Load a mesh
/// \param[in] _filename Mesh file to load
/// \return Pointer to a new Mesh
public: virtual Mesh *Load(const std::string &_filename) override;

/// \internal
/// \brief Pointer to private data.
GZ_UTILS_UNIQUE_IMPL_PTR(dataPtr)
};
}
}
#endif
12 changes: 10 additions & 2 deletions graphics/include/gz/common/Material.hh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <gz/math/Color.hh>
#include <gz/common/graphics/Export.hh>
#include <gz/common/EnumIface.hh>
#include <gz/common/Image.hh>
#include <gz/common/Pbr.hh>

#include <gz/utils/ImplPtr.hh>
Expand Down Expand Up @@ -102,15 +103,22 @@ namespace gz

/// \brief Set a texture image
/// \param[in] _tex The name of the texture, which must be in the
/// resource path
public: void SetTextureImage(const std::string &_tex);
/// resource path or its name if _img is provided
/// \param[in] _img The image containing the texture if image has been
/// loaded in memory
public: void SetTextureImage(const std::string &_tex,
const std::shared_ptr<const Image> &_img = nullptr);

/// \brief Set a texture image
/// \param[in] _tex The name of the texture
/// \param[in] _resourcePath Path which contains _tex
public: void SetTextureImage(const std::string &_tex,
const std::string &_resourcePath);

/// \brief Gets the texture image, if the texture was loaded from memory
/// \return A pointer to the image that was loaded from memory
public: std::shared_ptr<const Image> TextureData() const;

/// \brief Get a texture image
/// \return The name of the texture image (if one exists) or an empty
/// string
Expand Down
12 changes: 10 additions & 2 deletions graphics/include/gz/common/MeshManager.hh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ namespace gz
class SubMesh;

/// \class MeshManager MeshManager.hh gz/common/MeshManager.hh
/// \brief Maintains and manages all meshes
/// \brief Maintains and manages all meshes. Supported mesh formats are
/// STL (STLA, STLB), COLLADA, OBJ, GLTF (GLB) and FBX. By default only GLTF
/// and FBX are loaded using assimp loader, however if GZ_MESH_FORCE_ASSIMP
/// environment variable is set, then MeshManager will use assimp loader for
/// all supported mesh formats.
class GZ_COMMON_GRAPHICS_VISIBLE MeshManager
: public SingletonT<MeshManager>
{
Expand Down Expand Up @@ -240,8 +244,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
52 changes: 47 additions & 5 deletions graphics/include/gz/common/Pbr.hh
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
#ifndef GZ_COMMON_PBR_HH_
#define GZ_COMMON_PBR_HH_

#include <memory>
#include <string>

#include <gz/utils/ImplPtr.hh>

#include <gz/common/graphics/Export.hh>
#include <gz/common/Image.hh>

namespace gz
{
Expand Down Expand Up @@ -84,12 +86,20 @@ namespace common
/// has not been specified.
public: std::string NormalMap() const;

/// \brief Gets the normal map data,
/// if the texture was loaded from memory, otherwise a nullptr
/// \return A pointer to the image that was loaded from memory
public: std::shared_ptr<const Image> NormalMapData() const;

/// \brief Set the normal map filename.
/// \param[in] _map Filename of the normal map.
/// \param[in] _space Space that the normal map is defined in.
/// Defaults to tangent space.
/// \param[in] _img The image containing the texture if image has been
/// loaded in memory
public: void SetNormalMap(const std::string &_map,
NormalMapSpace _space = NormalMapSpace::TANGENT);
NormalMapSpace _space = NormalMapSpace::TANGENT,
const std::shared_ptr<const Image> &_img = nullptr);

/// \brief Get the normal map type, either tangent or object space
/// \return Space that the normal map is defined in
Expand Down Expand Up @@ -123,7 +133,15 @@ namespace common

/// \brief Set the roughness map filename for metal workflow.
/// \param[in] _map Filename of the roughness map.
public: void SetRoughnessMap(const std::string &_map);
/// \param[in] _img The image containing the texture if image has been
/// loaded in memory
public: void SetRoughnessMap(const std::string &_map,
const std::shared_ptr<const Image> &_img = nullptr);

/// \brief Gets the roughness map data,
/// if the texture was loaded from memory, otherwise a nullptr
/// \return A pointer to the image that was loaded from memory
public: std::shared_ptr<const Image> RoughnessMapData() const;

/// \brief Get the metalness map filename for metal workflow. This will be
/// an empty string if a metalness map has not been set.
Expand All @@ -133,7 +151,15 @@ namespace common

/// \brief Set the metalness map filename for metal workflow.
/// \param[in] _map Filename of the metalness map.
public: void SetMetalnessMap(const std::string &_map);
/// \param[in] _img The image containing the texture if image has been
/// loaded in memory
public: void SetMetalnessMap(const std::string &_map,
const std::shared_ptr<const Image> &_img = nullptr);

/// \brief Gets the metalness map data,
/// if the texture was loaded from memory, otherwise a nullptr
/// \return A pointer to the image that was loaded from memory
public: std::shared_ptr<const Image> MetalnessMapData() const;

/// \brief Get the emissive map filename. This will be an empty string
/// if an emissive map has not been set.
Expand All @@ -143,18 +169,34 @@ namespace common

/// \brief Set the emissive map filename.
/// \param[in] _map Filename of the emissive map.
public: void SetEmissiveMap(const std::string &_map);
/// \param[in] _img The image containing the texture if image has been
/// loaded in memory
public: void SetEmissiveMap(const std::string &_map,
const std::shared_ptr<const Image> &_img = nullptr);

/// \brief Gets the emissive map data,
/// if the texture was loaded from memory, otherwise a nullptr
/// \return A pointer to the image that was loaded from memory
public: std::shared_ptr<const Image> EmissiveMapData() const;

/// \brief Get the light map filename. This will be an empty string
/// if an light map has not been set.
/// \return Filename of the light map, or empty string if a light
/// map has not been specified.
public: std::string LightMap() const;

/// \brief Gets the light map data,
/// if the texture was loaded from memory, otherwise a nullptr
/// \return A pointer to the image that was loaded from memory
public: std::shared_ptr<const Image> LightMapData() const;

/// \brief Set the light map filename.
/// \param[in] _map Filename of the light map.
/// \param[in] _uvSet Index of the texture coordinate set
public: void SetLightMap(const std::string &_map, unsigned int _uvSet = 0u);
/// \param[in] _img The image containing the texture if image has been
/// loaded in memory
public: void SetLightMap(const std::string &_map, unsigned int _uvSet = 0u,
const std::shared_ptr<const Image> &_img = nullptr);

/// \brief Get the light map texture coordinate set.
/// \return Index of the light map texture coordinate set
Expand Down
Loading

0 comments on commit a27c7a1

Please sign in to comment.