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

fix Material names #100

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

RemiArnaud
Copy link
Contributor

A Material is an effect instance, and can change values on the instaced effect.
This PR introduces effect instances, and apply the material name to the instance, since this instance is directly the GLTF Material.
This fixes Material names in the exported gltf.

Other Material attributes marked as TODO in this PR.

Example material from the spec:

  <material id="Blue"> 
    <instance_effect  url="#phongEffect"> 
      <setparam ref="AMBIENT"> 
        <float3>0.0 0.0 0.1</float3> 
      </setparam> 
      <setparam ref="DIFFUSE"> 
        <float3>0.15 0.15 0.1</float3> 
      </setparam> 
      <setparam ref="SPECULAR"> 
        <float3>0.5 0.5 0.5</float3> 
      </setparam> 
      <setparam ref="SHININESS"> 
        <float>16.0</float> 
      </setparam> 
      </instance_effect> 
  </material>  

@pjcozzi
Copy link
Member

pjcozzi commented Nov 8, 2017

Thanks @RemiArnaud! @lasalvavida do you have any time to look at this?

@lasalvavida
Copy link
Contributor

lasalvavida commented Nov 8, 2017

This functionality (minus copying other material properties) should already be available via GLTF::Material::Clone inherited from GLTF::Object::Clone which does copy the name.

However, I'm pretty sure this isn't necessary at all since glTF materials are mapped 1:1 with COLLADA instanced effects (not COLLADA materials) already, so it isn't clear to me what this pull request is actually supposed to do.

@RemiArnaud, in the future to expedite review, please include a model that does not convert correctly currently with your pull request so that it is clear what your change does and is easy for me to test.

@RemiArnaud
Copy link
Contributor Author

Just take any collada model and observe that the material name in collada does not end up as the material name in gltf, but instead the effect name is used.

@lasalvavida
Copy link
Contributor

Ah, okay. The writing of the effect name was an intentional decision on my part. This is because glTF materials map to COLLADA instanced effects, not COLLADA materials, despite their name.

I'm fine with a change to keep the material name and store it if the instanced effect does not already have a name and/or a command like flag like --materialNames that overwrites effect names with material names.

@RemiArnaud
Copy link
Contributor Author

To be correct, the current implementation maps the collada effect to the gltf material.
The instanced effect - by definition the material in collada - should be mapped to the gltf material, which is the object of this PR, although still leaving some TODOs to implement the case where materials apply changes to the instances effect.

@RemiArnaud
Copy link
Contributor Author

@lasalvavida. Thinking about uploading a sample model. I think it could be a good idea to collect unit tests collada files and corresponding unit tests - checking the json has the expected value. What do you think?

@lasalvavida
Copy link
Contributor

lasalvavida commented Nov 8, 2017

I think it could be a good idea to collect unit tests collada files and corresponding unit tests - checking the json has the expected value. What do you think?

It is a good idea. There is already a unit test framework, feel free to add tests.

Thank you for the clarification. I see the issue now. Please see how instanced geometry gets resolved using the clone function when instance meshes have different materials. The solution for this should use the same approach.

@lasalvavida
Copy link
Contributor

lasalvavida commented Nov 8, 2017

collect unit tests collada files

Though I think it's worth saying that this should be done with small tailored inline COLLADA strings and not file I/O on full COLLADA files.

@lasalvavida lasalvavida closed this Mar 2, 2018
@lasalvavida lasalvavida changed the base branch from 2.0 to master March 4, 2018 23:21
@lasalvavida lasalvavida reopened this Mar 4, 2018
@loadpixels loadpixels mentioned this pull request Jun 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants