Skip to content

Commit

Permalink
Merge pull request #610 from gazebosim/scpeters/merge_5_main
Browse files Browse the repository at this point in the history
Merge gz-common5 ➡️  main
  • Loading branch information
scpeters authored May 14, 2024
2 parents 6dae728 + 316ea33 commit 3930407
Show file tree
Hide file tree
Showing 10 changed files with 136 additions and 42 deletions.
26 changes: 17 additions & 9 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,37 @@
name: macOS latest

on: [push, pull_request]
on:
pull_request:
push:
branches:
- 'ign-common[0-9]'
- 'gz-common[0-9]'
- 'main'

jobs:
build:
env:
PACKAGE: gz-common6
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Homebrew
id: set-up-homebrew
uses: Homebrew/actions/setup-homebrew@master
- run: brew config
- run: brew list

# Workaround for https://github.com/actions/setup-python/issues/577
- name: Clean up python binaries
run: |
rm -f /usr/local/bin/2to3*;
rm -f /usr/local/bin/idle3*;
rm -f /usr/local/bin/pydoc3*;
rm -f /usr/local/bin/python3*;
rm -f /usr/local/bin/python3*-config;
rm -f $(brew --prefix)/bin/2to3*;
rm -f $(brew --prefix)/bin/idle3*;
rm -f $(brew --prefix)/bin/pydoc3*;
rm -f $(brew --prefix)/bin/python3*;
rm -f $(brew --prefix)/bin/python3*-config;
- name: Install base dependencies
env:
HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK: 1
run: |
brew tap osrf/simulation;
# check for ci_matching_branch
Expand All @@ -45,7 +53,7 @@ jobs:
- run: mkdir build
- name: cmake
working-directory: build
run: cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local/Cellar/${PACKAGE}/HEAD
run: cmake .. -DCMAKE_INSTALL_PREFIX=$(brew --prefix)/Cellar/${PACKAGE}/HEAD
- run: make
working-directory: build
# Run make install before make test so that the package will be available to
Expand Down
11 changes: 11 additions & 0 deletions .github/workflows/package_xml.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: Validate package.xml

on:
pull_request:

jobs:
package-xml:
runs-on: ubuntu-latest
name: Validate package.xml
steps:
- uses: gazebo-tooling/action-gz-ci/validate_package_xml@jammy
17 changes: 17 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@

## Gazebo Common 5.x

## Gazebo Common 5.6.0 (2024-04-23)

1. Clarify units for the DEM classes
* [Pull request #595](https://github.com/gazebosim/gz-common/pull/595)

1. Remove pessimizing move
* [Pull request #593](https://github.com/gazebosim/gz-common/pull/593)

1. Fix bazel build
* [Pull request #592](https://github.com/gazebosim/gz-common/pull/592)

1. Add new function in MeshManager to merge all submeshes of a mesh into one
* [Pull request #588](https://github.com/gazebosim/gz-common/pull/588)

1. Adds new function in MeshManager for performing convex decomposition
* [Pull request #585](https://github.com/gazebosim/gz-common/pull/585)

## Gazebo Common 5.5.1 (2024-03-14)

1. Various Bazel adjustments for linting
Expand Down
6 changes: 6 additions & 0 deletions av/src/AudioDecoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@ common::AudioDecoder::Implementation::~Implementation()
{
// Close the codec
if (this->codecCtx)
{
#if LIBAVFORMAT_VERSION_MAJOR < 59
avcodec_close(this->codecCtx);
#else
avcodec_free_context(&this->codecCtx);
#endif
}

// Close the audio file
if (this->formatCtx)
Expand Down
4 changes: 4 additions & 0 deletions av/src/Video.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,11 @@ void Video::Cleanup()
avformat_close_input(&this->dataPtr->formatCtx);

// Close the codec
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 48, 101)
avcodec_free_context(&this->dataPtr->codecCtx);
#else
avcodec_close(this->dataPtr->codecCtx);
#endif

av_free(this->dataPtr->avFrameDst);
}
Expand Down
4 changes: 2 additions & 2 deletions geospatial/include/gz/common/geospatial/Dem.hh
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ namespace gz
public: int Load(const std::string &_filename = "");

/// \brief Get the elevation of a terrain's point in meters.
/// \param[in] _x X coordinate of the terrain.
/// \param[in] _y Y coordinate of the terrain.
/// \param[in] _x X coordinate of the terrain in raster coordinates.
/// \param[in] _y Y coordinate of the terrain in raster coordinates.
/// \return Terrain's elevation at (x,y) in meters or infinity if illegal
/// coordinates were provided.
public: double Elevation(double _x, double _y);
Expand Down
6 changes: 3 additions & 3 deletions geospatial/include/gz/common/geospatial/HeightmapData.hh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace gz
/// Ex: A subsampling of 2 in a terrain of 129x129 means that the height
/// vector will be 257 * 257.
/// \param[in] _vertSize Number of points per row.
/// \param[in] _size Real dimmensions of the terrain.
/// \param[in] _size Real dimensions of the terrain.
/// \param[in] _scale Vector3 used to scale the height.
/// \param[in] _flipY If true, it inverts the order in which the vector
/// is filled.
Expand All @@ -48,11 +48,11 @@ namespace gz
std::vector<float> &_heights) const = 0;

/// \brief Get the terrain's height.
/// \return The terrain's height.
/// \return The terrain's height [pixels].
public: virtual unsigned int Height() const = 0;

/// \brief Get the terrain's width.
/// \return The terrain's width.
/// \return The terrain's width [pixels].
public: virtual unsigned int Width() const = 0;

/// \brief Get the maximum terrain's elevation.
Expand Down
72 changes: 46 additions & 26 deletions graphics/src/AssimpLoader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
*
*/

#include <cstddef>
#include <queue>
#include <string>
#include <unordered_set>

#include "gz/common/graphics/Types.hh"
Expand Down Expand Up @@ -69,10 +71,12 @@ class AssimpLoader::Implementation
/// \param[in] _scene the assimp scene
/// \param[in] _matIdx index of the material in the scene
/// \param[in] _path path where the mesh is located
/// \param[in] _fileBaseName Base name of the mesh file.
/// \return pointer to the converted common::Material
public: MaterialPtr CreateMaterial(const aiScene* _scene,
public: MaterialPtr CreateMaterial(const aiScene *_scene,
unsigned _matIdx,
const std::string& _path) const;
const std::string &_path,
const std::string &_fileBaseName) const;

/// \brief Load a texture embedded in a mesh (i.e. for GLB format)
/// into a gz::common::Image
Expand All @@ -82,13 +86,15 @@ class AssimpLoader::Implementation

/// \brief Utility function to generate a texture name for both embedded
/// and external textures
/// \param[in] _prefix Prefix to add to the texture name
/// \param[in] _scene the assimp scene
/// \param[in] _mat the assimp material
/// \param[in] _type the type of texture (i.e. Diffuse, Metal)
/// \return the generated texture name
public: std::string GenerateTextureName(const aiScene* _scene,
aiMaterial* _mat,
const std::string& _type) const;
public: std::string GenerateTextureName(const std::string &_prefix,
const aiScene* _scene,
aiMaterial *_mat,
const std::string &_type) const;

/// \brief Function to parse texture information and load it if embedded
/// \param[in] _scene the assimp scene
Expand Down Expand Up @@ -320,7 +326,8 @@ void AssimpLoader::Implementation::RecursiveSkeletonCreate(const aiNode* _node,

//////////////////////////////////////////////////
MaterialPtr AssimpLoader::Implementation::CreateMaterial(
const aiScene* _scene, unsigned _matIdx, const std::string& _path) const
const aiScene *_scene, unsigned _matIdx, const std::string &_path,
const std::string &_fileBaseName) const
{
MaterialPtr mat = std::make_shared<Material>();
aiColor4D color;
Expand Down Expand Up @@ -386,8 +393,8 @@ MaterialPtr AssimpLoader::Implementation::CreateMaterial(
if (ret == AI_SUCCESS)
{
// Check if the texture is embedded or not
auto [texName, texData] = this->LoadTexture(_scene,
texturePath, this->GenerateTextureName(_scene, assimpMat, "Diffuse"));
auto [texName, texData] = this->LoadTexture(_scene, texturePath,
this->GenerateTextureName(_fileBaseName, _scene, assimpMat, "Diffuse"));
if (texData != nullptr)
mat->SetTextureImage(texName, texData);
else
Expand Down Expand Up @@ -421,18 +428,19 @@ MaterialPtr AssimpLoader::Implementation::CreateMaterial(
if (ret == AI_SUCCESS)
{
auto [texName, texData] = this->LoadTexture(_scene, texturePath,
this->GenerateTextureName(_scene, assimpMat, "MetallicRoughness"));
this->GenerateTextureName(_fileBaseName, _scene, assimpMat,
"MetallicRoughness"));
// Load it into a common::Image then split it
auto texImg = texData != nullptr ? texData :
std::make_shared<Image>(joinPaths(_path, texName));
auto [metalTexture, roughTexture] =
this->SplitMetallicRoughnessMap(*texImg);
pbr.SetMetalnessMap(
this->GenerateTextureName(_scene, assimpMat, "Metalness"),
metalTexture);
this->GenerateTextureName(_fileBaseName, _scene, assimpMat,
"Metalness"), metalTexture);
pbr.SetRoughnessMap(
this->GenerateTextureName(_scene, assimpMat, "Roughness"),
roughTexture);
this->GenerateTextureName(_fileBaseName, _scene, assimpMat,
"Roughness"), roughTexture);
}
else
{
Expand All @@ -441,15 +449,17 @@ MaterialPtr AssimpLoader::Implementation::CreateMaterial(
if (ret == AI_SUCCESS)
{
auto [texName, texData] = this->LoadTexture(_scene, texturePath,
this->GenerateTextureName(_scene, assimpMat, "Metalness"));
this->GenerateTextureName(_fileBaseName, _scene, assimpMat,
"Metalness"));
pbr.SetMetalnessMap(texName, texData);
}
ret = assimpMat->GetTexture(
aiTextureType_DIFFUSE_ROUGHNESS, 0, &texturePath);
if (ret == AI_SUCCESS)
{
auto [texName, texData] = this->LoadTexture(_scene, texturePath,
this->GenerateTextureName(_scene, assimpMat, "Roughness"));
this->GenerateTextureName(_fileBaseName, _scene, assimpMat,
"Roughness"));
pbr.SetRoughnessMap(texName, texData);
}
// Load lightmap only if it is not a glb/glTF mesh that contains a
Expand All @@ -464,7 +474,8 @@ MaterialPtr AssimpLoader::Implementation::CreateMaterial(
if (ret == AI_SUCCESS)
{
auto [texName, texData] = this->LoadTexture(_scene, texturePath,
this->GenerateTextureName(_scene, assimpMat, "Lightmap"));
this->GenerateTextureName(_fileBaseName, _scene, assimpMat,
"Lightmap"));
pbr.SetLightMap(texName, uvIdx, texData);
}
}
Expand All @@ -473,15 +484,16 @@ MaterialPtr AssimpLoader::Implementation::CreateMaterial(
if (ret == AI_SUCCESS)
{
auto [texName, texData] = this->LoadTexture(_scene, texturePath,
this->GenerateTextureName(_scene, assimpMat, "Normal"));
this->GenerateTextureName(_fileBaseName, _scene, assimpMat, "Normal"));
// TODO(luca) different normal map spaces
pbr.SetNormalMap(texName, NormalMapSpace::TANGENT, texData);
}
ret = assimpMat->GetTexture(aiTextureType_EMISSIVE, 0, &texturePath);
if (ret == AI_SUCCESS)
{
auto [texName, texData] = this->LoadTexture(_scene, texturePath,
this->GenerateTextureName(_scene, assimpMat, "Emissive"));
this->GenerateTextureName(_fileBaseName, _scene, assimpMat,
"Emissive"));
pbr.SetEmissiveMap(texName, texData);
}
#ifndef GZ_ASSIMP_PRE_5_2_0
Expand Down Expand Up @@ -600,15 +612,16 @@ ImagePtr AssimpLoader::Implementation::LoadEmbeddedTexture(

//////////////////////////////////////////////////
std::string AssimpLoader::Implementation::GenerateTextureName(
const aiScene* _scene, aiMaterial* _mat, const std::string& _type) const
const std::string &_prefix, const aiScene *_scene, aiMaterial *_mat,
const std::string &_type) const
{
#ifdef GZ_ASSIMP_PRE_5_2_0
auto rootName = _scene->mRootNode->mName;
#else
auto rootName = _scene->mName;
#endif
return ToString(rootName) + "_" + ToString(_mat->GetName()) +
"_" + _type;
return _prefix + "_" + ToString(rootName) + "_" +
ToString(_mat->GetName()) + "_" + _type;
}

//////////////////////////////////////////////////
Expand Down Expand Up @@ -695,12 +708,18 @@ Mesh *AssimpLoader::Load(const std::string &_filename)
}
auto& rootNode = scene->mRootNode;
auto rootName = ToString(rootNode->mName);

// compute assimp root node transform
std::string extension = _filename.substr(_filename.rfind(".") + 1,
_filename.size());
auto fileBaseName = common::basename(_filename);
std::string extension;
std::size_t extIdx = _filename.rfind(".");
if (extIdx != std::string::npos)
{
extension = _filename.substr(extIdx + 1, _filename.size());
fileBaseName = fileBaseName.substr(0, fileBaseName.rfind(extension) - 1);
}
std::transform(extension.begin(), extension.end(),
extension.begin(), ::tolower);

// compute assimp root node transform
bool useIdentityRotation = (extension != "glb" && extension != "glTF");
auto transform = this->dataPtr->UpdatedRootNodeTransform(scene,
useIdentityRotation);
Expand All @@ -709,7 +728,8 @@ Mesh *AssimpLoader::Load(const std::string &_filename)
// Add the materials first
for (unsigned _matIdx = 0; _matIdx < scene->mNumMaterials; ++_matIdx)
{
auto mat = this->dataPtr->CreateMaterial(scene, _matIdx, path);
auto mat = this->dataPtr->CreateMaterial(scene, _matIdx, path,
fileBaseName);
mesh->AddMaterial(mat);
}
// Create the skeleton
Expand Down
4 changes: 2 additions & 2 deletions graphics/src/AssimpLoader_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -721,9 +721,9 @@ TEST_F(AssimpLoader, LoadGlTF2BoxWithJPEGTexture)
// Assimp 5.2.0 and above uses the scene name for its texture names,
// older version use the root node instead.
#ifdef GZ_ASSIMP_PRE_5_2_0
EXPECT_EQ("Cube_Material_Diffuse", mat->TextureImage());
EXPECT_EQ("box_texture_jpg_Cube_Material_Diffuse", mat->TextureImage());
#else
EXPECT_EQ("Scene_Material_Diffuse", mat->TextureImage());
EXPECT_EQ("box_texture_jpg_Scene_Material_Diffuse", mat->TextureImage());
#endif
EXPECT_NE(nullptr, mat->TextureData());
delete mesh;
Expand Down
28 changes: 28 additions & 0 deletions package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0"?>
<package format="2">
<name>gz-common6</name>
<version>6.0.0</version>
<description>Gazebo Common : AV, Graphics, Events, and much more.</description>
<maintainer email="[email protected]">Nate Koenig</maintainer>
<license>Apache License 2.0</license>
<url type="website">https://github.com/gazebosim/gz-common</url>

<buildtool_depend>cmake</buildtool_depend>
<buildtool_depend>pkg-config</buildtool_depend>

<build_depend>gz-cmake4</build_depend>

<depend>assimp-dev</depend>
<depend>ffmpeg-dev</depend>
<depend>gz-math8</depend>
<depend>gz-utils3</depend>
<depend>libfreeimage-dev</depend>
<depend>libgdal-dev</depend>
<depend>libgts</depend>
<depend>tinyxml2</depend>
<depend>uuid</depend>

<export>
<build_type>cmake</build_type>
</export>
</package>

0 comments on commit 3930407

Please sign in to comment.