-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backwards compatibility fix for Gazebo 9.6 -> Gazebo 9.0.
- Loading branch information
1 parent
0a38e70
commit 3ca69f3
Showing
9 changed files
with
258 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
asv_wave_sim_gazebo_plugins/include/asv_wave_sim_gazebo_plugins/Gazebo.hh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
/////////////////////////////////////////////////////////////////////////////// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters