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

KHR extensions #894

Merged
merged 3 commits into from
Nov 23, 2020
Merged

KHR extensions #894

merged 3 commits into from
Nov 23, 2020

Conversation

pandaGaume
Copy link
Contributor

Fix #872 default test behavior and prepare #892 support for clearcoat, sheen and transmission

Fix default test behavior and prepare support for clearcoat, sheen and transmission
@@ -63,7 +67,7 @@ public bool ShouldSerializeemissiveTexture()

public bool ShouldSerializeemissiveFactor()
{
return (this.emissiveFactor != null && !this.emissiveFactor.SequenceEqual(new float[] { 0f, 0f, 0f }));
return (this.emissiveFactor != null && !this.emissiveFactor.SequenceEqual(zeros3));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reccomend using tools.isAlmostEqualTo() instead of doing floating point equivalency.

Copy link
Contributor Author

@pandaGaume pandaGaume Nov 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, Then we use the MathUtilities wich is already used in GLTFLight and the ArrayExtension. Both on Utilities shared project
ok ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, thanks

@@ -8,6 +8,10 @@ namespace GLTFExport.Entities
[DataContract]
public class GLTFMaterial : GLTFIndexedChildRootProperty
{
internal static float[] one2 = { 1.0f, 1.0f };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we instead add a definition to our Tools.Math file with definitions of vector2, vector3 and the zero and one constants, similar to babylon.js?

Copy link
Contributor Author

@pandaGaume pandaGaume Nov 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we may have this , but if we create vector, i recommend to introduce this vector class directly into the GltfExport.Entities to avoid new dependencies. The gltf project is supposed to be standalone and self sufficient (wich its not the case today). So, similar to babylon.js, introduce one Maths.cs file with Vector2 and Vector3, and some logic to replace the MathUtilities used in only one place so far.

in the mean time, as you pointed out a poor code design option, i propose to clear this static and introduce

        public static bool IsAllAlmostEqualTo(this float[] current, float value, float epsilon)
        {
            if( current == null)
            {
                return false;
            }

            for (var i = 0; i < current.Length; ++i)
            {
                if (!MathUtilities.IsAlmostEqualTo(current[i], value, epsilon))
                {
                    return false;
                }
            }
            return true;
        }

into ArrayExtensions.cs

then we may discard the static and use the extension as

        public bool ShouldSerializescale()
        {
            return this.scale != null && !this.scale.IsAllAlmostEqualTo(1,float.Epsilon);
        }

then make the code more resilient without the need to introduce new classes.

Copy link
Contributor

@Drigax Drigax Nov 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems like an alright decision, I just like code reuse, and not making architectural decisions for convenience sake, Currently we take dependencies on some shared utilities, helper functions and structures in SharedProjects, as long as we don't take any additional dependencies directly from Max or/Maya2Babylon.

Some standalone math utility, as opposed to an appendix to the gltf entities, but I don't think it matters that much to hold up the PR if you decide otherwise. Where we're using them, we also reused some entities defined in our babylon utilities as part of the glTF exporter, as they are used by the babylon entities.

Ultimately, it would be a good goal to architect such that we can easily make Babylon2GLTF its own standalone executable.

Contributing to our utilities should still allow the project to be relatively standalone, right? That would be akin to using a shared math library or scientific computing library in my opinion.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I definitely agree with adding a helper function to compare arrays via IsAllAlmostEqualTo,

Alternatively you can override IsAlmostEqualTo to use float[] as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok this is what i done. I guess PR is ready now.

@Drigax
Copy link
Contributor

Drigax commented Nov 23, 2020

Thanks, checking in.

@sebavan sebavan merged commit eed9173 into BabylonJS:master Nov 23, 2020
@pandaGaume pandaGaume deleted the KHR branch November 24, 2020 06:51
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.

glTF with KHR_texture_transform contains default values that shouldn't be written
3 participants