-
Notifications
You must be signed in to change notification settings - Fork 276
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
Support for Gazebo materials #2269
Conversation
Signed-off-by: Dharini Dutia <[email protected]>
Signed-off-by: Dharini Dutia <[email protected]>
Signed-off-by: Dharini Dutia <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works well, but there are a few changes we need to make before merging:
Signed-off-by: Dharini Dutia <[email protected]>
Co-authored-by: Alejandro Hernández Cordero <[email protected]> Signed-off-by: Dharini Dutia <[email protected]> Signed-off-by: Dharini Dutia <[email protected]>
Signed-off-by: Dharini Dutia <[email protected]>
8db08c1
to
7e333f5
Compare
Signed-off-by: Dharini Dutia <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a style nit, but there is a good chunk of code here that uses ::iterator
types rather than range-based for loops. I know that this is copied code so it's probably not a huge deal, but it looks inconsistent with the rest of the codebase.
Signed-off-by: Dharini Dutia <[email protected]>
Signed-off-by: Dharini Dutia <[email protected]>
Signed-off-by: Dharini Dutia <[email protected]>
Signed-off-by: Dharini Dutia <[email protected]>
121e539
to
f151561
Compare
Signed-off-by: Dharini Dutia <[email protected]>
f151561
to
07415de
Compare
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## gz-sim8 #2269 +/- ##
===========================================
+ Coverage 65.61% 65.80% +0.19%
===========================================
Files 324 327 +3
Lines 30925 31212 +287
===========================================
+ Hits 20292 20540 +248
- Misses 10633 10672 +39 ☔ View full report in Codecov by Sentry. |
Signed-off-by: Dharini Dutia <[email protected]>
0bb3523
to
f2e2f5f
Compare
ad1de96
to
7b08ebf
Compare
if (!_visual->Material()->ScriptUri().empty()) | ||
{ | ||
gzwarn << "Gazebo does not support Ogre material scripts. See " << | ||
"https://gazebosim.org/api/sim/8/migrationsdf.html#:~:text=Materials " << |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does the #:~:text=Materials
part work? It takes me to the migration page but not the Materials section.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its using text fragments, and mostly browser dependent. For me, it highlights and scrolls to the Material section but scrolls back up the page. Do you think it would be useful?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah ok I thought it would jump to that section. Yes I see it highlighted. We can leave the text fragment here.
Signed-off-by: Dharini Dutia <[email protected]>
26565b2
to
7621715
Compare
Signed-off-by: Dharini Dutia <[email protected]>
60f05db
to
eacd18f
Compare
Signed-off-by: Dharini Dutia <[email protected]>
eacd18f
to
404ffef
Compare
ConfigNode * ambientNode = passNode->findChild("ambient"); | ||
if (ambientNode) { | ||
std::vector<float> ambientValues; | ||
ambientNode->getValuesInFloat(ambientValues); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't guarantee that getValuesInFloat
will return a vector of 3 (at least). For example, if the user modifies the gazebo.material
file and forgets to put the third value for a color, we'd end up with a vector of size 2, but then we'd try to access ambientValues[2]
which would be undefined behavior. So I think we should add a check here and other places getValuesInFloat
is used in this file. Alternatively, we can have a fuction in ConfigNode
that returns a color instead of a vector.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of gz/math
dependency in ConfigLoader
and placing extra checks in MaterialParser
, I'm thinking of updating getValuesInFloat
to check if the vector has 3 or more values, which is common for all colors in the material file. If not then throwing an error saying "Bad material file", what do you think about that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we do that, my preference would be to create another getColorValues
function or something similar so getValuesInFloat
can remain a generic function that gets a list of floats for non-colors. Either way, by "throwing an error", you mean printing an error message, I definitely agree. But if you mean throw an exception, I would say we should avoid throwing exceptions since that's our general practice in the Gazebo codebase.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added another function with the size check. Yeah that's right just printing an error message, not throwing an exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I see the size check has been added, but it would still allow out of bounds access on the vector since the code continues to assign the colors after getColorValues
whether that fails or not. I would suggest something like the following:
std::vector<float> ambientValues;
ambientNode->getColorValues(ambientValues);
values->ambient.emplace();
for (std::size_t i=0; i < ambientValues.size(); ++i)
{
values->ambient[i] = ambientValues[i];
}
However, it looks like there's a bug in Color::operator[]
since it doesn't return a reference. So another way would be to modify the getColorValues
function to resize the vector.
inline void getColorValues(std::vector<float> & colorValues)
{
getValuesInFloat(colorValues);
if (colorValues.size() < 3)
{
gzerr << "Bad material file." << std::endl;
colorValues.resize(3);
}
}
5a4c1aa
to
d5ad0cf
Compare
ConfigNode * ambientNode = passNode->findChild("ambient"); | ||
if (ambientNode) { | ||
std::vector<float> ambientValues; | ||
ambientNode->getValuesInFloat(ambientValues); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I see the size check has been added, but it would still allow out of bounds access on the vector since the code continues to assign the colors after getColorValues
whether that fails or not. I would suggest something like the following:
std::vector<float> ambientValues;
ambientNode->getColorValues(ambientValues);
values->ambient.emplace();
for (std::size_t i=0; i < ambientValues.size(); ++i)
{
values->ambient[i] = ambientValues[i];
}
However, it looks like there's a bug in Color::operator[]
since it doesn't return a reference. So another way would be to modify the getColorValues
function to resize the vector.
inline void getColorValues(std::vector<float> & colorValues)
{
getValuesInFloat(colorValues);
if (colorValues.size() < 3)
{
gzerr << "Bad material file." << std::endl;
colorValues.resize(3);
}
}
Signed-off-by: Dharini Dutia <[email protected]>
d5ad0cf
to
d768c85
Compare
Signed-off-by: Dharini Dutia <[email protected]>
de4a442
to
ccad6bd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a couple more minor comments. Thanks for iterating!
There are also a few style issues, but for the sake of expediency, we'll address them later.
Signed-off-by: Dharini Dutia <[email protected]>
* test script tag Signed-off-by: Dharini Dutia <[email protected]> * add dark grey before creating component Signed-off-by: Dharini Dutia <[email protected]> * material parser Signed-off-by: Dharini Dutia <[email protected]> * linters Signed-off-by: Dharini Dutia <[email protected]> * Update src/rendering/MaterialParser/MaterialParser.cc Co-authored-by: Alejandro Hernández Cordero <[email protected]> Signed-off-by: Dharini Dutia <[email protected]> Signed-off-by: Dharini Dutia <[email protected]> * fix configLoader, material struct and feedback Signed-off-by: Dharini Dutia <[email protected]> * default color and todos Signed-off-by: Dharini Dutia <[email protected]> * install/load one file, range based loop, hardcode dependent solid colors Signed-off-by: Dharini Dutia <[email protected]> * fix install_dir property Signed-off-by: Dharini Dutia <[email protected]> * credits, initializing cleanup Signed-off-by: Dharini Dutia <[email protected]> * eof Signed-off-by: Dharini Dutia <[email protected]> * reformat Signed-off-by: Dharini Dutia <[email protected]> * add integration test Signed-off-by: Dharini Dutia <[email protected]> * migration note Signed-off-by: Dharini Dutia <[email protected]> * intends, default case, invalid color Signed-off-by: Dharini Dutia <[email protected]> * optional materialValues, typo Signed-off-by: Dharini Dutia <[email protected]> * feedback Signed-off-by: Dharini Dutia <[email protected]> * size check Signed-off-by: Dharini Dutia <[email protected]> * get color values Signed-off-by: Dharini Dutia <[email protected]> * migration doc update Signed-off-by: Dharini Dutia <[email protected]> --------- Signed-off-by: Dharini Dutia <[email protected]> Signed-off-by: Dharini Dutia <[email protected]> Co-authored-by: Alejandro Hernández Cordero <[email protected]>
* test script tag Signed-off-by: Dharini Dutia <[email protected]> * add dark grey before creating component Signed-off-by: Dharini Dutia <[email protected]> * material parser Signed-off-by: Dharini Dutia <[email protected]> * linters Signed-off-by: Dharini Dutia <[email protected]> * Update src/rendering/MaterialParser/MaterialParser.cc Co-authored-by: Alejandro Hernández Cordero <[email protected]> Signed-off-by: Dharini Dutia <[email protected]> Signed-off-by: Dharini Dutia <[email protected]> * fix configLoader, material struct and feedback Signed-off-by: Dharini Dutia <[email protected]> * default color and todos Signed-off-by: Dharini Dutia <[email protected]> * install/load one file, range based loop, hardcode dependent solid colors Signed-off-by: Dharini Dutia <[email protected]> * fix install_dir property Signed-off-by: Dharini Dutia <[email protected]> * credits, initializing cleanup Signed-off-by: Dharini Dutia <[email protected]> * eof Signed-off-by: Dharini Dutia <[email protected]> * reformat Signed-off-by: Dharini Dutia <[email protected]> * add integration test Signed-off-by: Dharini Dutia <[email protected]> * migration note Signed-off-by: Dharini Dutia <[email protected]> * intends, default case, invalid color Signed-off-by: Dharini Dutia <[email protected]> * optional materialValues, typo Signed-off-by: Dharini Dutia <[email protected]> * feedback Signed-off-by: Dharini Dutia <[email protected]> * size check Signed-off-by: Dharini Dutia <[email protected]> * get color values Signed-off-by: Dharini Dutia <[email protected]> * migration doc update Signed-off-by: Dharini Dutia <[email protected]> --------- Signed-off-by: Dharini Dutia <[email protected]> Signed-off-by: Dharini Dutia <[email protected]> Co-authored-by: Alejandro Hernández Cordero <[email protected]>
🎉 New feature
Closes #10
Summary
Ported the OgreMaterialParser from the Ogre community, also used in
gzweb
to add minimal parsing capabilities of Gazebo materials. This would make migration from Gazebo Classic to Gazebo Sim a little bit easier.Limitations:
Task list:
Test it
Run Gazebo from the source directory
gz sim src/sdformat/test/integration/model/double_pendulum.sdf -v 3
Checklist
codecheck
passed (See contributing)Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining
Signed-off-by
messages.