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

Associate library materials effect with meshes #151

Merged
merged 10 commits into from
Feb 5, 2021

Conversation

ahcorde
Copy link
Contributor

@ahcorde ahcorde commented Jan 15, 2021

This PR is related with this issue #91 (comment)

The material could be defined in Collada like this:

  <library_materials>
    <material id="material-cube">
      <instance_effect url="#effect-cube"/>
    </material>
  </library_materials>

This kind of material definition were never associated with the mesh. This PR try to fix this issue.

Signed-off-by: ahcorde [email protected]

@ahcorde ahcorde added the bug Something isn't working label Jan 15, 2021
@ahcorde ahcorde requested a review from iche033 January 15, 2021 13:07
@ahcorde ahcorde requested a review from mjcarroll as a code owner January 15, 2021 13:07
@ahcorde ahcorde self-assigned this Jan 15, 2021
@github-actions github-actions bot added 🏢 edifice Ignition Edifice 🏰 citadel Ignition Citadel 📜 blueprint Ignition Blueprint 🔮 dome Ignition Dome labels Jan 15, 2021
Signed-off-by: ahcorde <[email protected]>
@codecov
Copy link

codecov bot commented Jan 15, 2021

Codecov Report

Merging #151 (2dfff6e) into ign-common3 (c98d0d2) will increase coverage by 0.04%.
The diff coverage is 94.73%.

Impacted file tree graph

@@               Coverage Diff               @@
##           ign-common3     #151      +/-   ##
===============================================
+ Coverage        75.01%   75.06%   +0.04%     
===============================================
  Files               72       72              
  Lines            10215    10234      +19     
===============================================
+ Hits              7663     7682      +19     
  Misses            2552     2552              
Impacted Files Coverage Δ
graphics/src/ColladaLoader.cc 85.38% <94.73%> (+0.20%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c98d0d2...2dfff6e. Read the comment docs.

@chapulina
Copy link
Contributor

Would it be possible to add a test? Maybe using the mesh provided in #91 ?

Signed-off-by: ahcorde <[email protected]>
@ahcorde
Copy link
Contributor Author

ahcorde commented Feb 4, 2021

+1 for the test. Added here 188d06d

@ahcorde ahcorde requested a review from mjcarroll February 4, 2021 10:27
graphics/src/ColladaLoader_TEST.cc Outdated Show resolved Hide resolved
graphics/src/ColladaLoader_TEST.cc Outdated Show resolved Hide resolved
graphics/src/ColladaLoader_TEST.cc Outdated Show resolved Hide resolved
graphics/src/ColladaLoader.cc Show resolved Hide resolved
Signed-off-by: ahcorde <[email protected]>
@ahcorde ahcorde requested a review from chapulina February 4, 2021 17:09
@ahcorde ahcorde merged commit 89b1157 into ign-common3 Feb 5, 2021
@ahcorde ahcorde deleted the ahcorde/fix/library_materials branch February 5, 2021 07:48
@peci1
Copy link
Contributor

peci1 commented Feb 23, 2021

I'm sorry, @ahcorde , but this PR seems to break some other mesh parsing. X1 SubT robots are no longer blue, EXPLORER_DS1 has a weird red-ish color instead of carbon black...

image

Check the behavior of ColladaLoader with ~/.ignition/fuel/fuel.ignitionrobotics.org/openrobotics/models/x1 config 1/18/meshes/chassis.dae.

This file has one <vertices> and two <triangles>. Each triangle list defines a different symbol for material. However, after loading the mesh with ColladaLoader, both submeshes have material index 1 assigned. Without this PR, submesh 0 correctly has material index 0. Here's a simple (wrongly) failing test for me:

TEST_F(ColladaLoader, LoadX1)
{
  common::ColladaLoader loader;
  common::Mesh *mesh = loader.Load("/home/peci1/.ignition/fuel/fuel.ignitionrobotics.org/openrobotics/models/x1 config 1/18/meshes/chassis.dae");

  ASSERT_EQ(2u, mesh->SubMeshCount());
  ASSERT_EQ(2u, mesh->MaterialCount());

  EXPECT_EQ(0u, mesh->SubMeshByIndex(0).lock()->MaterialIndex());
  EXPECT_EQ(1u, mesh->SubMeshByIndex(1).lock()->MaterialIndex());
}

Reading through #91 and Collada spec, I think the mesh submitted by @jaelrod is not what he expected it to be. The "triangles" section (p. 188) says:

material xs:NCName Declares a symbol for a material. This symbol is bound to a material at the time of instantiation; see <instance_geometry> and <bind_material>. Optional. If not specified then the lighting and shading results are application defined.

@jaelrod was concerned about reusability of the library geometries. But I think there was a misunderstanding on what does the <triangles material=""> attribute actually mean. It does NOT specify the material to use. It specifies the symbol to which a material has to be bound in the <instance_geometry>. So it's not a "value", but a "variable name". I think there's nothing against naming the "variable" (material), as long as you can bind different materials to it (referencing the name in the <instance_material symbol=""> attribute and specifying the selected material in <instance_material target=""> attribute).

The mesh from #91 could work if the default value for the <triangles material=""> were "material". But the spec says that if this attribute is missing, shading is application-dependent. This is probably where application behavior starts to differ (and that's correct, as the spec says). To be compatible with Blender (which is generally a nice thing, I would say), this PR should be reverted and the change should be somewhere near

https://github.com/ignitionrobotics/ign-common/blob/abfecc8a262b32e3df7495f11b04fd38f5594f68/graphics/src/ColladaLoader.cc#L2009-L2029

I think this if could assume that there is a default value for the material attribute - "material". It should just silence the warnings in case it tried to find a material and did not succeed.

@peci1 peci1 mentioned this pull request Mar 8, 2021
7 tasks
chapulina added a commit that referenced this pull request Mar 9, 2021
chapulina added a commit that referenced this pull request Mar 9, 2021
chapulina added a commit that referenced this pull request Mar 19, 2021
* 🎈 3.11.0 (#178)

Signed-off-by: Louise Poubel <[email protected]>

* Relax expectation so encoder test passes on ARM (#183)

Signed-off-by: Louise Poubel <[email protected]>

* Revert "Associate library materials effect with meshes (#151)" (#182)

This reverts commit 89b1157.

Signed-off-by: Louise Poubel <[email protected]>

* 🎈 3.11.1 (#184)

Signed-off-by: Louise Poubel <[email protected]>

* Master branch updates (#179)

Part of gazebo-tooling/release-tools#416

Signed-off-by: Louise Poubel <[email protected]>

* Remove use of _SOURCE and _BINARY dirs in tests (#158)

Test cleanup:

Merges test/util.hh and test_config.h into a single file (fixes include path issues)
Adds fixtures for retrieving test data from test/data folder
Moves testing utilities into ignition::common::testing

Signed-off-by: Michael Carroll <[email protected]>
Co-authored-by: Jose Luis Rivero <[email protected]>

Co-authored-by: Michael Carroll <[email protected]>
Co-authored-by: Jose Luis Rivero <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📜 blueprint Ignition Blueprint bug Something isn't working 🏰 citadel Ignition Citadel 🔮 dome Ignition Dome 🏢 edifice Ignition Edifice
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants