Skip to content

Commit

Permalink
Release v0.1.2
Browse files Browse the repository at this point in the history
Backwards compatibility fix for Gazebo 9.6 -> Gazebo 9.0.
  • Loading branch information
srmainwaring authored Feb 14, 2019
1 parent 0a38e70 commit 3ca69f3
Show file tree
Hide file tree
Showing 9 changed files with 258 additions and 7 deletions.
24 changes: 22 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,31 @@ This package contains plugins that support the simulation of waves and surface v
## Dependencies

You will need a working installation of ROS and Gazebo in order to use this package.
It has been tested with:

- Gazebo version 9.4.1

## Ubuntu

- Ubuntu 18.04
- ROS Melodic Morenia
- Gazebo version 9.0.0

Install CGAL 4.13 libraries:

```bash
sudo apt-get install libcgal-dev
```

### macOS

- OSX 10.11.6
- ROS Melodic Morenia
- Gazebo version 9.6.0

Install CGAL 4.13 libraries:

```bash
brew install cgal
```

## Installation

Expand Down
2 changes: 1 addition & 1 deletion asv_wave_sim/package.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<package format="2">
<name>asv_wave_sim</name>
<version>0.1.1</version>
<version>0.1.2</version>
<description>
This package contains Gazebo plugins and models for simulating
water waves for surface vessels.
Expand Down
2 changes: 1 addition & 1 deletion asv_wave_sim_gazebo/package.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<package format="2">
<name>asv_wave_sim_gazebo</name>
<version>0.1.1</version>
<version>0.1.2</version>
<description>
This package contains Gazebo media, models and worlds for simulating
water waves and dynamics for surface vessels. There are ROS
Expand Down
1 change: 1 addition & 0 deletions asv_wave_sim_gazebo_plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ add_library(Hydrodynamics
SHARED
src/Algorithm.cc
src/Convert.cc
src/Gazebo.cc
src/Geometry.cc
src/Grid.cc
src/MeshTools.cc
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (C) 2012 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.
*
*/

/// \file Gazebo.hh
/// \brief Support for methods not available in legacy versions of Gazebo.

#ifndef _ASV_WAVE_SIM_GAZEBO_PLUGINS_GAZEBO_HH_
#define _ASV_WAVE_SIM_GAZEBO_PLUGINS_GAZEBO_HH_

#include <string>

namespace gazebo
{
namespace rendering
{
class Visual;

/// \brief Set a shader program parameter associated to this visual's
/// material
/// \param[in] _visual Reference to a Visual
/// \param[in] _paramName Name of shader parameter
/// \param[in] _shaderType Type of shader. Supported types:
/// vertex, fragment
/// \param[in] _value Value to set the parameter to. The value string can
/// be a number (int, float) or a space delimited array of numbers
/// (floats). The value type must match the type defined in the shaders.
/// Note: Setting vec2/float2 params is only supported in ogre1.9+
void SetMaterialShaderParam(
Visual& _visual,
const std::string &_paramName,
const std::string &_shaderType,
const std::string &_value);

}; // namespace rendering

} // namespace gazebo

#endif // _ASV_WAVE_SIM_GAZEBO_PLUGINS_GAZEBO_HH_
2 changes: 1 addition & 1 deletion asv_wave_sim_gazebo_plugins/package.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<package format="2">
<name>asv_wave_sim_gazebo_plugins</name>
<version>0.1.1</version>
<version>0.1.2</version>
<description>
This package contains Gazebo plugins for the simulation of
water surface waves and hydrostatic and hydrodynamics forces.
Expand Down
1 change: 0 additions & 1 deletion asv_wave_sim_gazebo_plugins/src/CGAL_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include <CGAL/AABB_face_graph_triangle_primitive.h>
#include <CGAL/AABB_tree.h>
#include <CGAL/AABB_traits.h>
#include <CGAL/draw_surface_mesh.h>
#include <CGAL/number_utils.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/Simple_cartesian.h>
Expand Down
152 changes: 152 additions & 0 deletions asv_wave_sim_gazebo_plugins/src/Gazebo.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
/*
* Copyright (C) 2012 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.
*
*/

#include "asv_wave_sim_gazebo_plugins/Gazebo.hh"

#include <gazebo/gazebo.hh>
#include <gazebo/common/common.hh>
#include <gazebo/rendering/rendering.hh>

#include <array>
#include <iostream>
#include <iterator>
#include <string>

namespace gazebo
{
namespace rendering
{

void SetMaterialShaderParam(
Visual& _visual,
const std::string &_paramName,
const std::string &_shaderType,
const std::string &_value)
{
// currently only vertex and fragment shaders are supported
if (_shaderType != "vertex" && _shaderType != "fragment")
{
gzerr << "Shader type: '" << _shaderType << "' is not supported"
<< std::endl;
return;
}

// set the parameter based name and type defined in material script
// and shaders
auto setNamedParam = [](Ogre::GpuProgramParametersSharedPtr _params,
const std::string &_name, const std::string &_v)
{
auto paramDef = _params->_findNamedConstantDefinition(_name);
if (!paramDef)
return;

switch (paramDef->constType)
{
case Ogre::GCT_INT1:
{
int value = Ogre::StringConverter::parseInt(_v);
_params->setNamedConstant(_name, value);
break;
}
case Ogre::GCT_FLOAT1:
{
Ogre::Real value = Ogre::StringConverter::parseReal(_v);
_params->setNamedConstant(_name, value);
break;
}
#if (OGRE_VERSION >= ((1 << 16) | (9 << 8) | 0))
case Ogre::GCT_INT2:
case Ogre::GCT_FLOAT2:
{
Ogre::Vector2 value = Ogre::StringConverter::parseVector2(_v);
_params->setNamedConstant(_name, value);
break;
}
#endif
case Ogre::GCT_INT3:
case Ogre::GCT_FLOAT3:
{
Ogre::Vector3 value = Ogre::StringConverter::parseVector3(_v);
_params->setNamedConstant(_name, value);
break;
}
case Ogre::GCT_INT4:
case Ogre::GCT_FLOAT4:
{
Ogre::Vector4 value = Ogre::StringConverter::parseVector4(_v);
_params->setNamedConstant(_name, value);
break;
}
case Ogre::GCT_MATRIX_4X4:
{
Ogre::Matrix4 value = Ogre::StringConverter::parseMatrix4(_v);
_params->setNamedConstant(_name, value);
break;
}
default:
break;
}
};

// loop through material techniques and passes to find the param
Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().getByName(
_visual.GetMaterialName());
if (mat.isNull())
{
gzerr << "Failed to find material: '" << _visual.GetMaterialName()
<< std::endl;
return;
}
for (unsigned int i = 0; i < mat->getNumTechniques(); ++i)
{
Ogre::Technique *technique = mat->getTechnique(i);
if (!technique)
continue;
for (unsigned int j = 0; j < technique->getNumPasses(); ++j)
{
Ogre::Pass *pass = technique->getPass(j);
if (!pass)
continue;

// check if pass is programmable, ie if they are using shaders
if (!pass->isProgrammable())
continue;

if (_shaderType == "vertex" && pass->hasVertexProgram())
{
setNamedParam(pass->getVertexProgramParameters(), _paramName, _value);
}
else if (_shaderType == "fragment" && pass->hasFragmentProgram())
{
setNamedParam(pass->getFragmentProgramParameters(), _paramName, _value);
}
else
{
gzerr << "Failed to retrieve shaders for material: '"
<< _visual.GetMaterialName() << "', technique: '"
<< technique->getName() << "', pass: '" << pass->getName() << "'"
<< std::endl;
continue;
}
}
}
}

} // namespace rendering
} // namespace gazebo

///////////////////////////////////////////////////////////////////////////////
29 changes: 28 additions & 1 deletion asv_wave_sim_gazebo_plugins/src/WavefieldVisualPlugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "asv_wave_sim_gazebo_plugins/WavefieldVisualPlugin.hh"

#include "asv_wave_sim_gazebo_plugins/Convert.hh"
#include "asv_wave_sim_gazebo_plugins/Gazebo.hh"
#include "asv_wave_sim_gazebo_plugins/Grid.hh"
#include "asv_wave_sim_gazebo_plugins/Wavefield.hh"
#include "asv_wave_sim_gazebo_plugins/Utilities.hh"
Expand Down Expand Up @@ -285,9 +286,13 @@ namespace asv

// Initialise vertex shader
std::string shaderType = "vertex";
#if 0
this->data->visual->SetMaterialShaderParam(
"time", shaderType, std::to_string(0.0));

#else
rendering::SetMaterialShaderParam(*this->data->visual,
"time", shaderType, std::to_string(0.0));
#endif
this->SetShaderParams();
this->data->isInitialised = true;
}
Expand All @@ -309,8 +314,13 @@ namespace asv
{
std::string shaderType = "vertex";
float simTime = this->data->simTime;
#if 0
this->data->visual->SetMaterialShaderParam(
"time", shaderType, std::to_string(simTime));
#else
rendering::SetMaterialShaderParam(*this->data->visual,
"time", shaderType, std::to_string(simTime));
#endif
}
}

Expand Down Expand Up @@ -386,6 +396,7 @@ namespace asv

// These parameters are updated on initialisation
auto& visual = *this->data->visual;
#if 0
visual.SetMaterialShaderParam(
"amplitude", shaderType, Ogre::StringConverter::toString(amplitude));
visual.SetMaterialShaderParam(
Expand All @@ -400,6 +411,22 @@ namespace asv
"dir1", shaderType, Ogre::StringConverter::toString(dir1));
visual.SetMaterialShaderParam(
"dir2", shaderType, Ogre::StringConverter::toString(dir2));
#else
rendering::SetMaterialShaderParam(visual,
"amplitude", shaderType, Ogre::StringConverter::toString(amplitude));
rendering::SetMaterialShaderParam(visual,
"wavenumber", shaderType, Ogre::StringConverter::toString(wavenumber));
rendering::SetMaterialShaderParam(visual,
"omega", shaderType, Ogre::StringConverter::toString(omega));
rendering::SetMaterialShaderParam(visual,
"steepness", shaderType, Ogre::StringConverter::toString(steepness));
rendering::SetMaterialShaderParam(visual,
"dir0", shaderType, Ogre::StringConverter::toString(dir0));
rendering::SetMaterialShaderParam(visual,
"dir1", shaderType, Ogre::StringConverter::toString(dir1));
rendering::SetMaterialShaderParam(visual,
"dir2", shaderType, Ogre::StringConverter::toString(dir2));
#endif
}

} // namespace asv

0 comments on commit 3ca69f3

Please sign in to comment.