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

Use assimp for loading meshes #393

Merged
merged 86 commits into from
Jul 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
33c8d2f
First draft of assimp loader, can load obj and dae meshes
luca-della-vedova May 13, 2022
bce766d
WIP correct material assignments
luca-della-vedova May 13, 2022
3b08c5b
Refactor mesh creation into separate function
luca-della-vedova May 13, 2022
0ed8f69
WIP adding actor support
luca-della-vedova May 18, 2022
531b2a8
[FEATURE] Drag and drop support for gltf and fbx (#354)
May 18, 2022
8f63b21
WIP actors with single skeletons working
luca-della-vedova May 20, 2022
db823ca
Migrate to assimp 5.2.0
luca-della-vedova May 23, 2022
1795314
Fix: Works even the root node doesnt have child (#358)
May 30, 2022
ce4cfc8
Only load bones if model has animations
luca-della-vedova May 30, 2022
47e42a3
Naming style to follow Gazebo convention
luca-della-vedova May 30, 2022
2a94bfc
Merge branch 'main' of github.com:gazebosim/gz-common into luca/assim…
luca-della-vedova May 30, 2022
c106035
Fix after namespace migration
luca-della-vedova May 30, 2022
d5f9935
Parse alpha from texture from GLTF materials
luca-della-vedova Jun 1, 2022
1f28b89
Minor cleanups, parse metalness and roughness
luca-della-vedova Jun 1, 2022
b7f160a
Fix: Assimp generates normals for all the meshes. (#359)
Jun 3, 2022
1c9771d
WIP create API for having in memory textures
luca-della-vedova Jun 6, 2022
fd3a0f5
Diffuse textures working
luca-della-vedova Jun 6, 2022
08f1102
Add API to load compressed images and read RGBA data
luca-della-vedova Jun 9, 2022
661823c
Add test
luca-della-vedova Jun 9, 2022
b5ab18f
Deallocate memory in tests
luca-della-vedova Jun 9, 2022
97b459e
Merge branch 'feature/compressed_images' into luca/inmemory_textures
luca-della-vedova Jun 9, 2022
d08554f
Migrate to image API, minor cleanups
luca-della-vedova Jun 10, 2022
304cd93
Merge branch 'luca/inmemory_textures' into luca/assimp_sandbox
luca-della-vedova Jun 10, 2022
d6c59b1
Add PBR materials to inmemory textures
luca-della-vedova Jun 10, 2022
6879e1c
Merge branch 'luca/inmemory_textures' into luca/assimp_sandbox
luca-della-vedova Jun 13, 2022
435fe13
Use correct mesh index to load bones
luca-della-vedova Jun 15, 2022
91e32ea
Add metallic roughness map support
luca-della-vedova Jun 17, 2022
d09f892
Merge branch 'main' into luca/assimp_sandbox
luca-della-vedova Jun 21, 2022
ee7fb08
Add API to return image data as vector of bytes
luca-della-vedova Jun 21, 2022
7ee1c45
Update migration guide
luca-della-vedova Jun 21, 2022
c822fc0
Move to new API
luca-della-vedova Jun 22, 2022
032611b
Move to GZ impl ptr, don't remove empty bones
luca-della-vedova Jun 23, 2022
05f4604
Merge branch 'main' into luca/vector_image_data
mjcarroll Jun 24, 2022
2f78228
Merge branch 'main' into luca/assimp_sandbox
luca-della-vedova Jun 27, 2022
9d9d692
Merge branch 'main' into luca/vector_image_data
mjcarroll Jun 27, 2022
41541c1
Add path to find external texture for collada files
luca-della-vedova Jun 28, 2022
da0d078
WIP port all tests from other loaders
luca-della-vedova Jun 28, 2022
98c5c06
Minor cleanup and name migration
luca-della-vedova Jun 28, 2022
2f580e7
WIP Fixing and reenabling tests
luca-della-vedova Jun 28, 2022
efec93f
Fix more tests
luca-della-vedova Jun 28, 2022
683a6c1
Fix a few more unit tests
luca-della-vedova Jun 29, 2022
b5bc4db
Fix: Reversed models when skeletons exist (#375)
Jun 30, 2022
b630640
Merge branch 'main' into luca/vector_image_data
mjcarroll Jun 30, 2022
a970a52
Revert to only parse skeletons for scenes with animations
luca-della-vedova Jul 8, 2022
4e7c022
Clean debug statements
luca-della-vedova Jul 12, 2022
2b2e220
Minor performance improvements in mesh manager
luca-della-vedova Jul 12, 2022
d030bc5
Add assimp dependency to github packages
luca-della-vedova Jul 12, 2022
af99a3e
Merge branch 'main' into luca/assimp_sandbox
luca-della-vedova Jul 12, 2022
57f8a73
Don't force assimp version anymore
luca-della-vedova Jul 12, 2022
8bb789e
Code style
luca-della-vedova Jul 12, 2022
5a5cbea
Documentation, remove workaround and clean state
luca-della-vedova Jul 12, 2022
d647967
Minor cleanup and review feedback
luca-della-vedova Jul 14, 2022
28f9b68
Merge branch 'main' into luca/vector_image_data
mjcarroll Jul 18, 2022
589bc8a
Merge branch 'main' of https://github.com/ignitionrobotics/ign-common…
luca-della-vedova Jul 19, 2022
51a8953
WIP compile in Ubuntu 20.04
luca-della-vedova Jul 19, 2022
d798f74
WIP Make CI green in focal
luca-della-vedova Jul 20, 2022
a62eb6f
Fix CI in Jammy
luca-della-vedova Jul 20, 2022
8ce8b79
Update for bone node assignment in assimp 5.2.0
luca-della-vedova Jul 20, 2022
6a0839a
Fix bone node name logic
luca-della-vedova Jul 20, 2022
cdfb6da
Revert to normal loaders for old asset formats
luca-della-vedova Jul 20, 2022
61e22e6
Remove commented tests
luca-della-vedova Jul 20, 2022
8fe6b91
Feature: Inits units tests for fbx and glTF2 (#385)
Jul 20, 2022
36aca25
Revert bone node name change
luca-della-vedova Jul 20, 2022
54aea7c
Merge branch 'main' into luca/assimp_sandbox
luca-della-vedova Jul 20, 2022
590ee15
Merge remote-tracking branch 'origin/luca/vector_image_data' into luc…
luca-della-vedova Jul 22, 2022
e0b3cd6
Add PBR Emissive map
luca-della-vedova Jul 22, 2022
a0c668d
Fix style
luca-della-vedova Jul 22, 2022
d78e2dd
Minor cleanups
luca-della-vedova Jul 22, 2022
ff4c1eb
Add test for material
luca-della-vedova Jul 22, 2022
cdc14c8
Merge branch 'main' of https://github.com/ignitionrobotics/ign-common…
luca-della-vedova Jul 26, 2022
85bfe1b
Address review feedback, fix const correctness
luca-della-vedova Jul 27, 2022
9165ee9
Add test for fully featured GLB and embedded lightmap
luca-della-vedova Jul 27, 2022
25616cd
Skip test on older assimp version
luca-della-vedova Jul 27, 2022
e801652
Add test to texture values and alpha from texture
luca-della-vedova Jul 27, 2022
2f969d4
Fix color test, add mesh manager integration test
luca-della-vedova Jul 27, 2022
8224142
Fix texture splitting index calculation
luca-della-vedova Jul 27, 2022
1138935
Fix color parsing and unit test
luca-della-vedova Jul 27, 2022
44e19b1
Temporary - use gz-cmake custom branch for CI
luca-della-vedova Jul 29, 2022
5d43e70
Change to ci matching branch
luca-della-vedova Jul 29, 2022
420bc48
Remove github dependencies file
luca-della-vedova Jul 29, 2022
a7b0967
Disable narrowing conversion warning
luca-della-vedova Jul 29, 2022
acdf06d
Silence warning on Ubuntu / Mac
luca-della-vedova Jul 29, 2022
4484e5e
Merge branch 'main' into luca/assimp_sandbox
luca-della-vedova Jul 29, 2022
afc47c8
Introduces GZ_MESH_FORCE_ASSIMP flag (#403)
Jul 29, 2022
2c07731
Add integration test for environment variable
luca-della-vedova Jul 29, 2022
a1c0b9f
Increase test coverage
chapulina Jul 30, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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