drwave / usd-sketchup

Source & macOS binary of USD exporter for SketchUp
Other
63 stars 5 forks source link

materials and display color don't play nice #7

Closed drwave closed 5 years ago

drwave commented 6 years ago

Given a mesh that is broken up into multiple faces.

If you put solid colors as materials on all the faces, it gets exported correctly as display color.

If you have a textured material on any of the faces, the faces that have solid colors on them have undefined behavior - sometimes they have a colored variant of the texture materials, sometimes, they have no color at all.

I think the correct answer is to just stop using displayColor/Opacity and make materials for colored faces instead, but need to do some more research...

MaterialColorBug.zip

drwave commented 6 years ago
image
drwave commented 6 years ago
image
wave-electron commented 6 years ago

this was the SketchUp test model i did, just a simple cube, with jpg materials on each face.

[image: sketchup.png]

This is how it looked in xcode beta 6 (opening usd.c file).

[image: xcodeBeta6.png]

the resulting usdz file.

[image: IMG_1592.JPG]

On Sat, 1 Sep 2018 at 09:40, Michael B. Johnson notifications@github.com wrote:

Given a mesh that is broken up into multiple faces.

If you put solid colors as materials on all the faces, it gets exported correctly as display color.

If you have a textured material on any of the faces, the faces that have solid colors on them have undefined behavior - sometimes they have a colored variant of the texture materials, sometimes, they have no color at all.

I think the correct answer is to just stop using displayColor/Opacity and make materials for colored faces instead, but need to do some more research...

MaterialColorBug.zip https://github.com/drwave/usd-sketchup/files/2341890/MaterialColorBug.zip

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/drwave/usd-sketchup/issues/7, or mute the thread https://github.com/notifications/unsubscribe-auth/APhRdNUtc0w_XRSYjT-yX3NJfU08qPpiks5uWclVgaJpZM4WV-dW .

-- Kind Regards,

Mr Ashley Joyce

Company Director

Bowin Service Pty Ltd

T: 0404481375 F: 02 8080 4393 E: admin@bowin.com.au

drwave commented 6 years ago

I'm not seeing the images in your post. I do see mine in the initial comment, so I'm not sure if this is me or you...

wave-electron commented 6 years ago

strange..... I'll attached them next time to the email (I was dragging the images into the email) using gmail image upload... maybe that features buggy.

Anyway, I've dropped the images into a folder at https://www.fusionar.app/sketchup/

Looks like the material images are not getting assigned correctly.

On Sat, 1 Sep 2018 at 09:55, Michael B. Johnson notifications@github.com wrote:

I'm not seeing the images in your post. I do see mine in the initial comment, so I'm not sure if this is me or you...

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/drwave/usd-sketchup/issues/7#issuecomment-417816266, or mute the thread https://github.com/notifications/unsubscribe-auth/APhRdATChHm1aLoeCQvEXSvuMuxL8cLEks5uWczsgaJpZM4WV-dW .

drwave commented 6 years ago

So… Since I can only see 3 sides of each cube… Is it wrong?

On Aug 31, 2018, at 5:07 PM, Ashley Joyce notifications@github.com wrote:

strange..... I'll attached them next time to the email (I was dragging the images into the email) using gmail image upload... maybe that features buggy.

Anyway, I've dropped the images into a folder at https://www.fusionar.app/sketchup/

Looks like the material images are not getting assigned correctly.

On Sat, 1 Sep 2018 at 09:55, Michael B. Johnson notifications@github.com wrote:

I'm not seeing the images in your post. I do see mine in the initial comment, so I'm not sure if this is me or you...

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/drwave/usd-sketchup/issues/7#issuecomment-417816266, or mute the thread https://github.com/notifications/unsubscribe-auth/APhRdATChHm1aLoeCQvEXSvuMuxL8cLEks5uWczsgaJpZM4WV-dW .

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/drwave/usd-sketchup/issues/7#issuecomment-417817586, or mute the thread https://github.com/notifications/unsubscribe-auth/ABmgOgk0HJz5AFhSs1-IFTj0ImyeCYLkks5uWc-ygaJpZM4WV-dW.

wave-electron commented 6 years ago

Yep, its wrong. The jpg materials for each side - 6 sides of the cube.... only one jpg was copied to the usdzip archive. However, if you open up the usda file in xcode, your getting the base color applied to each face, but its assigning only the one material jpg to all faces of the cube. Does that make sense?

On Sat, 1 Sep 2018 at 10:11, Michael B. Johnson notifications@github.com wrote:

So… Since I can only see 3 sides of each cube… Is it wrong?

On Aug 31, 2018, at 5:07 PM, Ashley Joyce notifications@github.com wrote:

strange..... I'll attached them next time to the email (I was dragging the images into the email) using gmail image upload... maybe that features buggy.

Anyway, I've dropped the images into a folder at https://www.fusionar.app/sketchup/

Looks like the material images are not getting assigned correctly.

On Sat, 1 Sep 2018 at 09:55, Michael B. Johnson < notifications@github.com> wrote:

I'm not seeing the images in your post. I do see mine in the initial comment, so I'm not sure if this is me or you...

— You are receiving this because you commented. Reply to this email directly, view it on GitHub < https://github.com/drwave/usd-sketchup/issues/7#issuecomment-417816266>, or mute the thread < https://github.com/notifications/unsubscribe-auth/APhRdATChHm1aLoeCQvEXSvuMuxL8cLEks5uWczsgaJpZM4WV-dW

.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub < https://github.com/drwave/usd-sketchup/issues/7#issuecomment-417817586>, or mute the thread < https://github.com/notifications/unsubscribe-auth/ABmgOgk0HJz5AFhSs1-IFTj0ImyeCYLkks5uWc-ygaJpZM4WV-dW .

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/drwave/usd-sketchup/issues/7#issuecomment-417817985, or mute the thread https://github.com/notifications/unsubscribe-auth/APhRdIj-d_v3CZtZRBb92floj2vQxvXUks5uWdC6gaJpZM4WV-dW .

drwave commented 6 years ago

Can you please upload the .skp file and .usdz in a .zip so I can try and reproduce?

Sent from my iPhone

On Aug 31, 2018, at 5:25 PM, Ashley Joyce notifications@github.com wrote:

Yep, its wrong. The jpg materials for each side - 6 sides of the cube.... only one jpg was copied to the usdzip archive. However, if you open up the usda file in xcode, your getting the base color applied to each face, but its assigning only the one material jpg to all faces of the cube. Does that make sense?

On Sat, 1 Sep 2018 at 10:11, Michael B. Johnson notifications@github.com wrote:

So… Since I can only see 3 sides of each cube… Is it wrong?

On Aug 31, 2018, at 5:07 PM, Ashley Joyce notifications@github.com wrote:

strange..... I'll attached them next time to the email (I was dragging the images into the email) using gmail image upload... maybe that features buggy.

Anyway, I've dropped the images into a folder at https://www.fusionar.app/sketchup/

Looks like the material images are not getting assigned correctly.

On Sat, 1 Sep 2018 at 09:55, Michael B. Johnson < notifications@github.com> wrote:

I'm not seeing the images in your post. I do see mine in the initial comment, so I'm not sure if this is me or you...

— You are receiving this because you commented. Reply to this email directly, view it on GitHub < https://github.com/drwave/usd-sketchup/issues/7#issuecomment-417816266>, or mute the thread < https://github.com/notifications/unsubscribe-auth/APhRdATChHm1aLoeCQvEXSvuMuxL8cLEks5uWczsgaJpZM4WV-dW

.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub < https://github.com/drwave/usd-sketchup/issues/7#issuecomment-417817586>, or mute the thread < https://github.com/notifications/unsubscribe-auth/ABmgOgk0HJz5AFhSs1-IFTj0ImyeCYLkks5uWc-ygaJpZM4WV-dW .

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/drwave/usd-sketchup/issues/7#issuecomment-417817985, or mute the thread https://github.com/notifications/unsubscribe-auth/APhRdIj-d_v3CZtZRBb92floj2vQxvXUks5uWdC6gaJpZM4WV-dW .

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

wave-electron commented 6 years ago

boxTest2.zip

wave-electron commented 6 years ago

I just tested colors only on the cube now.

cubecolorsonly

usda file result -> rgb colors

xcode

usdz file results -> greyscale?

cubecolorsonlyusdz

I've attached skp file and resulting usdz archives

cubeColorsOnly.zip

drwave commented 5 years ago

Hmm. Opening up that sketchup file, exporting it as usda and looking at in in my ModelIO/SceneKit app, they look identical.

I will take a look at in in iOS next week.

The greyscale is very odd, though.

I would suggest looking at the USDA file and see if the colors are somehow greyscale.

Also, I have uploaded a new prebuilt version of the plug-in - try that. Note: I have made no changes I know of that should affect color...

drwave commented 5 years ago

Also - export a usda, then use usdcat (you'll need to install the Apple provided USDZ Python tools) to generate a usdcat file from the usdz and compare the color values.

drwave commented 5 years ago

Also just checked the .usd and .usdz export in my ModelIO/SceneKit app - still correctly colored, not greyscale.

wave-electron commented 5 years ago

This is the cubeColorsOnly.usda Using the SketchUp exporter. This still produces a cube with greyscale in ios12 beta12 Safari.

(
    defaultPrim = "cubeColorsOnly_SketchUp_usda"
    subLayers = [
        @./cubeColorsOnly_SketchUp_usda.geom.usda@
    ]
    upAxis = "Z"
)

def Xform "cubeColorsOnly_SketchUp_usda" (
    kind = "assembly"
)
{
}

This is the cubeColorsOnly_SketchUp_usda.geom.usda


over "cubeColorsOnly_SketchUp_usda"
{
    def Xform "Geom"
    {
        def Mesh "BothSides"
        {
            uniform bool doubleSided = 1
            float3[] extent = [(-94, -122, 0), (0, 0, 92)]
            int[] faceVertexCounts = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]
            int[] faceVertexIndices = [0, 1, 2, 1, 0, 3, 4, 5, 6, 5, 4, 7, 8, 9, 10, 9, 8, 11, 12, 13, 14, 13, 12, 15, 16, 17, 18, 17, 16, 19, 20, 21, 22, 21, 20, 23]
            uniform token orientation = "rightHanded"
            point3f[] points = [(0, 0, 0), (-94, -122, 0), (-94, 0, 0), (0, -122, 0), (0, -122, 92), (-94, 0, 92), (-94, -122, 92), (0, 0, 92), (-94, 0, 92), (0, 0, 0), (-94, 0, 0), (0, 0, 92), (0, 0, 0), (0, -122, 92), (0, -122, 0), (0, 0, 92), (0, -122, 92), (-94, -122, 0), (0, -122, 0), (-94, -122, 92), (-94, 0, 92), (-94, -122, 0), (-94, -122, 92), (-94, 0, 0)]
            color3f[] primvars:displayColor = [(0.4, 1, 0.99607843), (0.4, 1, 0.99607843), (0.4, 1, 0.4), (0.4, 1, 0.4), (0, 0, 0.99607843), (0, 0, 0.99607843), (0.9843137, 0.003921569, 0.023529412), (0.9843137, 0.003921569, 0.023529412), (1, 1, 0.4), (1, 1, 0.4), (0.9843137, 0.003921569, 0.023529412), (0.9843137, 0.003921569, 0.023529412)] (
                interpolation = "uniform"
            )
            float[] primvars:displayOpacity = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] (
                interpolation = "uniform"
            )
            float2[] primvars:st = [(0, 0), (37.007874, -48.031498), (37.007874, 0), (0, -48.031498), (0, -48.031498), (-37.007874, 0), (-37.007874, -48.031498), (0, 0), (37.007874, 36.220474), (0, 0), (37.007874, 0), (0, 36.220474), (0, 0), (-48.031498, 36.220474), (-48.031498, 0), (0, 36.220474), (0, 36.220474), (-37.007874, 0), (0, 0), (-37.007874, 36.220474), (0, 36.220474), (48.031498, 0), (48.031498, 36.220474), (0, 0)] (
                interpolation = "vertex"
            )
            uniform token subdivisionScheme = "none"
        }
    }
}

Taking the same cubeColorsOnly created in SketchUp and exporting as a collada DAE file then using the COLLADA2GLTF exporter followed by the gltf2usd exporter. I can create the following usda file to compare against the SketchUp usda version above. This displays the solid colors correctly in IOS12 Beta12 Safari.

#usda 1.0

def Scope "Materials"
{
    def Material "pbrmaterial_0"
    {
        token outputs:displacement.connect = </Materials/pbrmaterial_0/pbrMat1.outputs:displacement>
        token outputs:surface.connect = </Materials/pbrmaterial_0/pbrMat1.outputs:surface>

        def Shader "pbrMat1"
        {
            uniform token info:id = "UsdPreviewSurface"
            color3f inputs:diffuseColor = (0.4, 1, 0.9960784)
            float inputs:metallic = 0
            float inputs:opacity = 1
            bool inputs:useSpecularWorkflow = 0
            token outputs:displacement
            token outputs:surface
        }

        def Shader "primvar_st0"
        {
            uniform token info:id = "UsdPrimvarReader_float2"
            float2 inputs:fallback = (0, 0)
            token inputs:varname = "st0"
            float2 outputs:result
        }

        def Shader "primvar_st1"
        {
            uniform token info:id = "UsdPrimvarReader_float2"
            float2 inputs:fallback = (0, 0)
            token inputs:varname = "st1"
            float2 outputs:result
        }
    }

    def Material "pbrmaterial_1"
    {
        token outputs:displacement.connect = </Materials/pbrmaterial_1/pbrMat1.outputs:displacement>
        token outputs:surface.connect = </Materials/pbrmaterial_1/pbrMat1.outputs:surface>

        def Shader "pbrMat1"
        {
            uniform token info:id = "UsdPreviewSurface"
            color3f inputs:diffuseColor = (0.9843137, 0.0039216, 0.0235294)
            float inputs:metallic = 0
            float inputs:opacity = 1
            bool inputs:useSpecularWorkflow = 0
            token outputs:displacement
            token outputs:surface
        }

        def Shader "primvar_st0"
        {
            uniform token info:id = "UsdPrimvarReader_float2"
            float2 inputs:fallback = (0, 0)
            token inputs:varname = "st0"
            float2 outputs:result
        }

        def Shader "primvar_st1"
        {
            uniform token info:id = "UsdPrimvarReader_float2"
            float2 inputs:fallback = (0, 0)
            token inputs:varname = "st1"
            float2 outputs:result
        }
    }

    def Material "pbrmaterial_2"
    {
        token outputs:displacement.connect = </Materials/pbrmaterial_2/pbrMat1.outputs:displacement>
        token outputs:surface.connect = </Materials/pbrmaterial_2/pbrMat1.outputs:surface>

        def Shader "pbrMat1"
        {
            uniform token info:id = "UsdPreviewSurface"
            color3f inputs:diffuseColor = (1, 1, 0.4)
            float inputs:metallic = 0
            float inputs:opacity = 1
            bool inputs:useSpecularWorkflow = 0
            token outputs:displacement
            token outputs:surface
        }

        def Shader "primvar_st0"
        {
            uniform token info:id = "UsdPrimvarReader_float2"
            float2 inputs:fallback = (0, 0)
            token inputs:varname = "st0"
            float2 outputs:result
        }

        def Shader "primvar_st1"
        {
            uniform token info:id = "UsdPrimvarReader_float2"
            float2 inputs:fallback = (0, 0)
            token inputs:varname = "st1"
            float2 outputs:result
        }
    }

    def Material "pbrmaterial_3"
    {
        token outputs:displacement.connect = </Materials/pbrmaterial_3/pbrMat1.outputs:displacement>
        token outputs:surface.connect = </Materials/pbrmaterial_3/pbrMat1.outputs:surface>

        def Shader "pbrMat1"
        {
            uniform token info:id = "UsdPreviewSurface"
            color3f inputs:diffuseColor = (0.9843137, 0.0039216, 0.0235294)
            float inputs:metallic = 0
            float inputs:opacity = 1
            bool inputs:useSpecularWorkflow = 0
            token outputs:displacement
            token outputs:surface
        }

        def Shader "primvar_st0"
        {
            uniform token info:id = "UsdPrimvarReader_float2"
            float2 inputs:fallback = (0, 0)
            token inputs:varname = "st0"
            float2 outputs:result
        }

        def Shader "primvar_st1"
        {
            uniform token info:id = "UsdPrimvarReader_float2"
            float2 inputs:fallback = (0, 0)
            token inputs:varname = "st1"
            float2 outputs:result
        }
    }

    def Material "pbrmaterial_4"
    {
        token outputs:displacement.connect = </Materials/pbrmaterial_4/pbrMat1.outputs:displacement>
        token outputs:surface.connect = </Materials/pbrmaterial_4/pbrMat1.outputs:surface>

        def Shader "pbrMat1"
        {
            uniform token info:id = "UsdPreviewSurface"
            color3f inputs:diffuseColor = (0, 0, 0.9960784)
            float inputs:metallic = 0
            float inputs:opacity = 1
            bool inputs:useSpecularWorkflow = 0
            token outputs:displacement
            token outputs:surface
        }

        def Shader "primvar_st0"
        {
            uniform token info:id = "UsdPrimvarReader_float2"
            float2 inputs:fallback = (0, 0)
            token inputs:varname = "st0"
            float2 outputs:result
        }

        def Shader "primvar_st1"
        {
            uniform token info:id = "UsdPrimvarReader_float2"
            float2 inputs:fallback = (0, 0)
            token inputs:varname = "st1"
            float2 outputs:result
        }
    }

    def Material "pbrmaterial_5"
    {
        token outputs:displacement.connect = </Materials/pbrmaterial_5/pbrMat1.outputs:displacement>
        token outputs:surface.connect = </Materials/pbrmaterial_5/pbrMat1.outputs:surface>

        def Shader "pbrMat1"
        {
            uniform token info:id = "UsdPreviewSurface"
            color3f inputs:diffuseColor = (0.4, 1, 0.4)
            float inputs:metallic = 0
            float inputs:opacity = 1
            bool inputs:useSpecularWorkflow = 0
            token outputs:displacement
            token outputs:surface
        }

        def Shader "primvar_st0"
        {
            uniform token info:id = "UsdPrimvarReader_float2"
            float2 inputs:fallback = (0, 0)
            token inputs:varname = "st0"
            float2 outputs:result
        }

        def Shader "primvar_st1"
        {
            uniform token info:id = "UsdPrimvarReader_float2"
            float2 inputs:fallback = (0, 0)
            token inputs:varname = "st1"
            float2 outputs:result
        }
    }
}

def Xform "root"
{
    float3 xformOp:scale = (100, 100, 100)
    uniform token[] xformOpOrder = ["xformOp:scale"]

    def Xform "node0"
    {
        matrix4d xformOp:transform = ( (1, 0, 0, 0), (0, 0, -1, 0), (0, 1, 0, 0), (0, 0, 0, 1) )
        uniform token[] xformOpOrder = ["xformOp:transform"]

        def Xform "node1"
        {
            matrix4d xformOp:transform = ( (1, 0, 0, 0), (0, 1, 0, 0), (0, 0, 1, 0), (0, 0, 0, 1) )
            uniform token[] xformOpOrder = ["xformOp:transform"]

            def Mesh "mesh_primitive0"
            {
                float3[] extent = [(-0.94, -1.22, 0), (0, 0, 0)]
                int[] faceVertexCounts = [3, 3]
                int[] faceVertexIndices = [0, 1, 2, 1, 0, 3]
                rel material:binding = </Materials/pbrmaterial_0>
                normal3f[] normals = [(0, 0, -1), (0, 0, -1), (0, 0, -1), (0, 0, -1)]
                point3f[] points = [(0, 0, 0), (-0.94, -1.22, 0), (-0.94, 0, 0), (0, -1.22, 0)]
                uniform token subdivisionScheme = "none"
            }

            def Xform "node7"
            {
                matrix4d xformOp:transform = ( (1, 0, 0, 0), (0, 1, 0, 0), (0, 0, 1, 0), (0, 0, 0, 1) )
                uniform token[] xformOpOrder = ["xformOp:transform"]

                def Mesh "mesh_primitive0"
                {
                    float3[] extent = [(-0.94, -1.22, 0.92), (0, 0, 0.92)]
                    int[] faceVertexCounts = [3, 3]
                    int[] faceVertexIndices = [0, 1, 2, 1, 0, 3]
                    rel material:binding = </Materials/pbrmaterial_5>
                    normal3f[] normals = [(0, 0, 1), (0, 0, 1), (0, 0, 1), (0, 0, 1)]
                    point3f[] points = [(0, -1.22, 0.92), (-0.94, 0, 0.92), (-0.94, -1.22, 0.92), (0, 0, 0.92)]
                    uniform token subdivisionScheme = "none"
                }
            }

            def Xform "node6"
            {
                matrix4d xformOp:transform = ( (1, 0, 0, 0), (0, 1, 0, 0), (0, 0, 1, 0), (0, 0, 0, 1) )
                uniform token[] xformOpOrder = ["xformOp:transform"]

                def Mesh "mesh_primitive0"
                {
                    float3[] extent = [(-0.94, 0, 0), (0, 0, 0.92)]
                    int[] faceVertexCounts = [3, 3]
                    int[] faceVertexIndices = [0, 1, 2, 1, 0, 3]
                    rel material:binding = </Materials/pbrmaterial_4>
                    normal3f[] normals = [(-0, 1, 0), (-0, 1, 0), (-0, 1, 0), (-0, 1, 0)]
                    point3f[] points = [(-0.94, 0, 0.92), (0, 0, 0), (-0.94, 0, 0), (0, 0, 0.92)]
                    uniform token subdivisionScheme = "none"
                }
            }

            def Xform "node5"
            {
                matrix4d xformOp:transform = ( (1, 0, 0, 0), (0, 1, 0, 0), (0, 0, 1, 0), (0, 0, 0, 1) )
                uniform token[] xformOpOrder = ["xformOp:transform"]

                def Mesh "mesh_primitive0"
                {
                    float3[] extent = [(0, -1.22, 0), (0, 0, 0.92)]
                    int[] faceVertexCounts = [3, 3]
                    int[] faceVertexIndices = [0, 1, 2, 1, 0, 3]
                    rel material:binding = </Materials/pbrmaterial_3>
                    normal3f[] normals = [(1, 0, 0), (1, 0, 0), (1, 0, 0), (1, 0, 0)]
                    point3f[] points = [(0, 0, 0), (0, -1.22, 0.92), (0, -1.22, 0), (0, 0, 0.92)]
                    uniform token subdivisionScheme = "none"
                }
            }

            def Xform "node4"
            {
                matrix4d xformOp:transform = ( (1, 0, 0, 0), (0, 1, 0, 0), (0, 0, 1, 0), (0, 0, 0, 1) )
                uniform token[] xformOpOrder = ["xformOp:transform"]

                def Mesh "mesh_primitive0"
                {
                    float3[] extent = [(-0.94, -1.22, 0), (0, -1.22, 0.92)]
                    int[] faceVertexCounts = [3, 3]
                    int[] faceVertexIndices = [0, 1, 2, 1, 0, 3]
                    rel material:binding = </Materials/pbrmaterial_2>
                    normal3f[] normals = [(-0, -1, -0), (-0, -1, -0), (-0, -1, -0), (-0, -1, -0)]
                    point3f[] points = [(0, -1.22, 0.92), (-0.94, -1.22, 0), (0, -1.22, 0), (-0.94, -1.22, 0.92)]
                    uniform token subdivisionScheme = "none"
                }
            }

            def Xform "node3"
            {
                matrix4d xformOp:transform = ( (1, 0, 0, 0), (0, 1, 0, 0), (0, 0, 1, 0), (0, 0, 0, 1) )
                uniform token[] xformOpOrder = ["xformOp:transform"]

                def Mesh "mesh_primitive0"
                {
                    float3[] extent = [(-0.94, -1.22, 0), (-0.94, 0, 0.92)]
                    int[] faceVertexCounts = [3, 3]
                    int[] faceVertexIndices = [0, 1, 2, 1, 0, 3]
                    rel material:binding = </Materials/pbrmaterial_1>
                    normal3f[] normals = [(-1, 0, 0), (-1, 0, 0), (-1, 0, 0), (-1, 0, 0)]
                    point3f[] points = [(-0.94, 0, 0.92), (-0.94, -1.22, 0), (-0.94, -1.22, 0.92), (-0.94, 0, 0)]
                    uniform token subdivisionScheme = "none"
                }
            }

            def Xform "node2"
            {
                matrix4d xformOp:transform = ( (0.9121643900871276, -0.4098244905471802, 0, 0), (0.11210639774799348, 0.24952009320259097, 0.9618585109710692, 0), (-0.3941932022571564, -0.8773730993270874, 0.2735474109649658, 0), (-3.4964497089385986, -6.886987209320068, 2.5246870517730717, 1) )
                uniform token[] xformOpOrder = ["xformOp:transform"]
            }
        }
    }
}

Maybe the def Scope Materials needs to be in the primary usda file for them to display correctly in IOS12?

wave-electron commented 5 years ago

I edited cubeColorsOnly_SketchUp_usda.geom.usda so that its the primary usda file. Solid colors display in xcode10 beta6, but as greyscale in IOS12 Safari


#usda 1.0

    def Xform "Geom"
    {
        def Mesh "BothSides"
        {
            uniform bool doubleSided = 1
            float3[] extent = [(-94, -122, 0), (0, 0, 92)]
            int[] faceVertexCounts = [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3]
            int[] faceVertexIndices = [0, 1, 2, 1, 0, 3, 4, 5, 6, 5, 4, 7, 8, 9, 10, 9, 8, 11, 12, 13, 14, 13, 12, 15, 16, 17, 18, 17, 16, 19, 20, 21, 22, 21, 20, 23]
            uniform token orientation = "rightHanded"
            point3f[] points = [(0, 0, 0), (-94, -122, 0), (-94, 0, 0), (0, -122, 0), (0, -122, 92), (-94, 0, 92), (-94, -122, 92), (0, 0, 92), (-94, 0, 92), (0, 0, 0), (-94, 0, 0), (0, 0, 92), (0, 0, 0), (0, -122, 92), (0, -122, 0), (0, 0, 92), (0, -122, 92), (-94, -122, 0), (0, -122, 0), (-94, -122, 92), (-94, 0, 92), (-94, -122, 0), (-94, -122, 92), (-94, 0, 0)]
            color3f[] primvars:displayColor = [(0.4, 1, 0.99607843), (0.4, 1, 0.99607843), (0.4, 1, 0.4), (0.4, 1, 0.4), (0, 0, 0.99607843), (0, 0, 0.99607843), (0.9843137, 0.003921569, 0.023529412), (0.9843137, 0.003921569, 0.023529412), (1, 1, 0.4), (1, 1, 0.4), (0.9843137, 0.003921569, 0.023529412), (0.9843137, 0.003921569, 0.023529412)] (
                interpolation = "uniform"
            )
            float[] primvars:displayOpacity = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] (
                interpolation = "uniform"
            )
            float2[] primvars:st = [(0, 0), (37.007874, -48.031498), (37.007874, 0), (0, -48.031498), (0, -48.031498), (-37.007874, 0), (-37.007874, -48.031498), (0, 0), (37.007874, 36.220474), (0, 0), (37.007874, 0), (0, 36.220474), (0, 0), (-48.031498, 36.220474), (-48.031498, 0), (0, 36.220474), (0, 36.220474), (-37.007874, 0), (0, 0), (-37.007874, 36.220474), (0, 36.220474), (48.031498, 0), (48.031498, 36.220474), (0, 0)] (
                interpolation = "vertex"
            )
            uniform token subdivisionScheme = "none"
        }
    }

``
wave-electron commented 5 years ago

I've just tested boxTest2.zip again with the materials on each cube face & it is now displaying correctly in IOS12 now with the latest plugin.

boxtest2

drwave commented 5 years ago

So currently there's a difference between a solid color material (which I save to USD as a displayColor/Opacity) and a textured one (for which I emit Materials that use the PreviewSurface).

I think the right answer is (eventually) to emit Materials for even solid color materials, and set that color via the diffuseColor (as your other example above does) as that's more deterministic.

displayColor/Opacity are really just hints, and what's probably happening is that the usdz import in ARKit 2 is being more strict, and only coloring things based on Materials, which is totally defensible.

Thanks for all the debugging - this was very helpful, and is even more incentive to generate Materials and not just (or maybe even) use displayColor.

When I first wrote this converter in 2015 we had Hydra preview shading, but it was temporary, so I moved over to displayColor/Opacity, but now that PreviewSurface is implemented in both SceneKit/ARKit 2 and Hydra, I should probably go back to using Materials for all color.

drwave commented 5 years ago

Okay, the current build now puts out a new Material that will map displayColor to diffuseColor and displayOpacity to opacity in the PreviewSurface. This works on Hydra, but does not currently work on the iOS 12 or macOS Mojave betas. Hoping to hear back from Apple if there's a way around this.

drwave commented 5 years ago

So the current workaround would be to emit a material with a UsdPreviewSurface shader that set the diffuseColor and opacity directly there. This should work on ARKit 2, but assuming you used GeomSubsets to apply it to the various parts of the mesh, it would NOT currently work on Hydra, as GeomSubsets aren't yet supported there. But in the exporter, we could pay attention to if we want to do "ARKit compatible" export, and emit those sorts of materials INSTEAD of using the fallback material (which currently will not work on ).

A lot of workarounds; hopefully this is temporary and will be fixed in the next few months...

drwave commented 5 years ago

So once we don't have to write out all the values of a shader, I think we should end up with something like this, for a given RGBA of (1, 0, 0, 0.7):

def Shader "SingleRGBA" { uniform token info:id = "UsdPreviewSurface" color3f inputs:diffuseColor = (1, 0, 0) float inputs:opacity = .7 token outputs:surface }

drwave commented 5 years ago

Okay, I've checked in a fix for this. Note that if you want to use the resulting USD file with ARKit, you'll need to make sure that the checkbox "Export as ARKit compatible" must be checked. If it is, we emit materials for the various RGBA face colors, each as a separate material. This works around the bug that ARKit currently can't handle connections between primvar shaders other than float2.

wave-electron commented 5 years ago

Just downloaded the latest commit USDExporter.plugin. Worked perfectly! I will do some more extensive testing on models using components & groupings and let you know if I find any further issues.

drwave commented 5 years ago

That’s a great relief!

On Sep 12, 2018, at 2:32 PM, Ashley Joyce notifications@github.com wrote:

Just downloaded the latest commit USDExporter.plugin <x-msg://21/USDExporter.plugin.zip>. Worked perfectly! I will do some more extensive testing on models using components & groupings and let you know if I find any further issues.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/drwave/usd-sketchup/issues/7#issuecomment-420805315, or mute the thread https://github.com/notifications/unsubscribe-auth/ABmgOmQPQQ5uTyXrGtMcGL_ELCJ5NsAFks5uaX2LgaJpZM4WV-dW.

wave-electron commented 5 years ago

@drwave At then moment it doesn't seem to play nice with assets from 3d warehouse . In this case the asset is a bmx bike, the usdz does at least displays in xcode, however, colors don't seem right. The frame should be bright yellow. Unfortunately, the usdz

does not preview in IOS 12 at all! I've noticed a number of 3D warehouse assets I've tried just don't preview in IOS 12.

xcode screen shot

example5

I haven't had a chance to drill into the usda for possible reasons yet. In one case I ungrouped the meshes and removed meshes until one of the 3d warehouse assets finally previewed in usdz. But I needed to delete most of the asset before it finally worked?

here is the asset BMX.usdz.txt

drwave commented 5 years ago

Hmm, that BMX file got turned into a .txt file? Not sure how to read it... I think GitHub is getting confused about .usdz files. Maybe change the extension to .zip before uploading?

Also, a few 3DWarehouse links would be great...

wave-electron commented 5 years ago

@drwave No I do it that way so I can upload it. Just rename the file after downloading to BMX.usdz and it should open.

wave-electron commented 5 years ago

@drwave These 3D warehouse assets seem extremely complicated! The exporter dialogue is saying that 14,008 Materials were exported! Looks like about 10 core materials, so its counting a material for maybe every face?

example6
drwave commented 5 years ago

Well, the workaround is to make a material for every unique RGBA on the mesh vs. using displayColor/Opacity shader (which isn't working). Looking...

drwave commented 5 years ago

Also, that number is deceiving. Look at the code starting at line 1264 in USDExporter.cpp:

// note: We may define the same material many times on a given mesh if
// the same color is on different faces. Eventually we may want to note that
// we've already done this for a given path, but for now, this is clearer...
drwave commented 5 years ago

That means the count keeps going up, even when the material will only be defined once in the file. But it's confusing enough I'll fix it.

wave-electron commented 5 years ago

@drwave Ok. The gltf2usd tool converts the BMX file - which previews in IOS 12 with correct colors.

I've upload usda files for you to compare. For starters the sketchUp version is more than twice the file size & struggles to open in xcode... so definitely some performance issues going to happen.

BMX-archive.zip

drwave commented 5 years ago

Cool, thanks - will take a look. Yea, I've got it narrowed down to a much simpler example, and it seems to be related to grouping.

wave-electron commented 5 years ago

@drwave Ok. Will leave it with you... I'll explore more tomorrow when I've got more time.

drwave commented 5 years ago

Oh - I just remembered. There's a bug in iOS 12 that can't handle USD instancing, and I'm still putting that out.

I'm checking my stuff on Mojave (which handles instancing fine), I bet that's why some of the files won't even image on iOS 12. It's a one line fix (line 886):

change: primSchema.GetPrim().SetInstanceable(true);

to false.

I will fix this color bug first...

drwave commented 5 years ago

I totally see the bug... Will take a bit to fix this, though.

Thanks for finding it - it's obvious now that you've pointed it out.

drwave commented 5 years ago

Notes for fixer:

drwave commented 5 years ago

I have a nice simple SketchUp file that demonstrates the problem. Once I upload unit tests, this should go in there.

This is a zip'ed SKP file

BMXYellowRing.zip

Note that the resulting USD file that I'm currently generating is wrong - this is not just a materials issue, the displayColor of the mesh is white, but it should be yellow.

More investigation needed. In some ways, this is a relief - the bug is more glaring - it's not just the Material issue. When I fix displayColor, I expect it will fix the material.

drwave commented 5 years ago

Hi Ashely.

I have a very simple example that I don't understand how to parse, given its structure. This is a zip'ed .skp file. I'd love for you to try and export it with your skp - > glTF -> USD exporter and see what you get.

BMXRedRing.zip

The issue for me is that in using the SketchUp C++ API, I get to the group "HEAD TUBE", and it has neither a front or back material (even though the mesh is clearly red - I dropped a pure red value on it) and so I don't have any color information to work with.

if the glTF exporter you're using can get to the color, I'd love a pointer to it so I can understand where it's finding that color info, because it's a mystery to me.

I'm a little concerned that this might be a Ruby vs. C++ API thing, where SketchUp has a richer API on the Ruby side than the C++ side...

wave-electron commented 5 years ago

@drwave My process for creating the usda file.

  1. Export the file from SketchUp as dae file. (check triangulate all faces)
  2. Use the Collada2GlTF command tool to convert glTF 2.0
  3. Use the glTF2USD command tool

I've included the intermediary files dae & glTF files in the conversion process. Note:

When I export the dae files from SketchUp I triangulate the faces, I checked "Export double Sided faces" as a test. The resultant usda file displays different and not what you expect. I've included that usda file... it may give you a clue to whats going on... but it may be something to do with this!

BMXRedRing.zip

drwave commented 5 years ago

So it turns out Groups in SketchUp can have a material associated with them - who knew?

Anyway, I have a proof of concept that now exports the BMX model (mostly) correctly, including colors and textures, now I need to do a bit of performance tuning before I push it out. There does seem to be some materials that are the wrong color, and one texture is missing. I will dig into those issues after I deal with the performance issue (mainly need to coalesce the materials).

Here's what it looks like in SketchUp:

bmxsu

Here's a picture of what the exported USD file looks like:

bmxusdimport
drwave commented 5 years ago

Related to this - we're not wiring up the alpha from the texture to the opacity on the PreviewSurface. I will file a separate bug on this.

drwave commented 5 years ago

Just uploaded new code and pre-built binary with my fixes in it. This version is performant, and emits pretty clean USD.

wave-electron commented 5 years ago

I was trying a few more 3d warehouse models tonight, I'm finding cases where materials are not displaying in ios12. In one case I looked into, the uv map was a tga file format. How do you handle those types of image files.. as I opened the usdz and there was no image file in the usdz archive? This is one of the models with tga file format

The gltf2usd handled it, because Blenders glTF exporter converted the tga file to jpg automatically, so the gtlf2usd didn't have to handle a tga file. archive-with-tga-file-gltf2usd-converted-usd-files.zip

drwave commented 5 years ago

Yea, it’s an issue.

I’m hoping the SketchUp folks can tell me a better way of getting at the texture data. Right now I ask the SketchUp API to write all the textures out, and in some cases (like .BMP) it seems to turn them into .PNG files, but when you ask the SUMaterial for it’s filename, it gives you the original one named with .BMP. Very frustrating.

On Sep 18, 2018, at 5:36 AM, Ashley Joyce notifications@github.com wrote:

I was trying a few more 3d warehouse models tonight, I'm finding cases where materials are not displaying in ios12. In one case I looked into, the uv map was a tga file format. How do you handle those types of image files.. as I opened the usdz and there was no image file in the usdz archive? This is one of the models with tga file format https://3dwarehouse.sketchup.com/model/u87cefd27-ee53-4bbc-beb2-2e94fb7824e4/Giraffe The gltf2usd handled it, because Blenders glTF exporter converted the tga file to jpg automatically, so the gtlf2usd didn't have to handle a tga file. archive-with-tga-file-gltf2usd-converted-usd-files.zip https://github.com/drwave/usd-sketchup/files/2392654/model-with-tga-file.zip — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/drwave/usd-sketchup/issues/7#issuecomment-422374575, or mute the thread https://github.com/notifications/unsubscribe-auth/ABmgOkNENzv65w0RKaQ2hGnHCUOBRppkks5ucOjpgaJpZM4WV-dW.

drwave commented 5 years ago

Okay, just checked in (and updated prebuilt binary) with a fix for this.

It’s a hack, really, but does fix that specific “tga” issue. Still hoping the SketchUp devs will give me a better solution.

On Sep 18, 2018, at 7:16 AM, Michael B. Johnson drwave@me.com wrote:

Yea, it’s an issue.

I’m hoping the SketchUp folks can tell me a better way of getting at the texture data. Right now I ask the SketchUp API to write all the textures out, and in some cases (like .BMP) it seems to turn them into .PNG files, but when you ask the SUMaterial for it’s filename, it gives you the original one named with .BMP. Very frustrating.

On Sep 18, 2018, at 5:36 AM, Ashley Joyce <notifications@github.com mailto:notifications@github.com> wrote:

I was trying a few more 3d warehouse models tonight, I'm finding cases where materials are not displaying in ios12. In one case I looked into, the uv map was a tga file format. How do you handle those types of image files.. as I opened the usdz and there was no image file in the usdz archive? This is one of the modelswith tga file format https://3dwarehouse.sketchup.com/model/u87cefd27-ee53-4bbc-beb2-2e94fb7824e4/Giraffe The gltf2usd handled it, because Blenders glTF exporter converted the tga file to jpg automatically, so the gtlf2usd didn't have to handle a tga file. archive-with-tga-file-gltf2usd-converted-usd-files.zip https://github.com/drwave/usd-sketchup/files/2392654/model-with-tga-file.zip — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/drwave/usd-sketchup/issues/7#issuecomment-422374575, or mute the thread https://github.com/notifications/unsubscribe-auth/ABmgOkNENzv65w0RKaQ2hGnHCUOBRppkks5ucOjpgaJpZM4WV-dW.

drwave commented 5 years ago

As far as I can tell, this issue is fixed, at least as far as I've been able to repro it. If it comes up again, let's file a new issue.