enzyme69 / blendersushi

Blender Sushi related scripts. Mostly about Sverchok, Geometry Nodes, Animation Nodes, and related Python scripts.
244 stars 33 forks source link

BSLIVE 0009 / Spinning Turntable 3D Logo USDZ for AR Quick Look #428

Open enzyme69 opened 6 years ago

enzyme69 commented 6 years ago
#usda 1.0
(
    endTimeCode = 480
    startTimeCode = 0
    upAxis = "Z"
)

def Xform "Top" (
)
{

    def "BaseGeom" (
        add references = @/Users/jimmygunawan/Desktop/snailspindemo/snailspin.obj@</Base_BaseGeom>
    )
    {
        rel material:binding = </usd_converter_materials/StingrayPBS_0>
    }

    def "SnailGeom" (
        add references = @/Users/jimmygunawan/Desktop/snailspindemo/snailspin.obj@</Snail_SnailGeom>
    )
    {
        rel material:binding = </usd_converter_materials/StingrayPBS_1>
    }

    float xformOp:rotateY:spin.timeSamples = {
        0: 0,
        480: 1440,
    }
    uniform token[] xformOpOrder = ["xformOp:rotateY:spin"]
}

def Scope "usd_converter_materials"
{
    def Material "StingrayPBS_0"
    {
        token inputs:frame:stPrimvarName = "Texture_uv"
        token outputs:displacement.connect = </usd_converter_materials/StingrayPBS_0/pbr.outputs:displacement>
        token outputs:surface.connect = </usd_converter_materials/StingrayPBS_0/pbr.outputs:surface>

        def Shader "pbr"
        {
            uniform token info:id = "UsdPreviewSurface"
            float inputs:clearcoat = 0
            float inputs:clearcoatRoughness = 0
            color3f inputs:diffuseColor.connect = </usd_converter_materials/StingrayPBS_0/color_map.outputs:rgb>
            float inputs:displacement = 0
            color3f inputs:emissiveColor.connect = </usd_converter_materials/StingrayPBS_0/emissive_map.outputs:rgb>
            float inputs:ior = 1.5
            float inputs:metallic.connect = </usd_converter_materials/StingrayPBS_0/metallic_map.outputs:r>
            normal3f inputs:normal.connect = </usd_converter_materials/StingrayPBS_0/normal_map.outputs:rgb>
            float inputs:occlusion.connect = </usd_converter_materials/StingrayPBS_0/ao_map.outputs:r>
            float inputs:opacity = 1
            float inputs:roughness.connect = </usd_converter_materials/StingrayPBS_0/roughness_map.outputs:r>
            color3f inputs:specularColor = (1, 1, 1)
            int inputs:useSpecularWorkflow = 0
            token outputs:displacement
            token outputs:surface
        }

        def Shader "Primvar"
        {
            uniform token info:id = "UsdPrimvarReader_float2"
            float2 inputs:default = (0, 0)
            token inputs:varname.connect = </usd_converter_materials/StingrayPBS_0.inputs:frame:stPrimvarName>
            float2 outputs:result
        }

        def Shader "color_map"
        {
            uniform token info:id = "UsdUVTexture"
            float4 inputs:default = (0, 0, 0, 1)
            asset inputs:file = @/Users/jimmygunawan/Desktop/snailspindemo/old-textured-fabric-albedo.png@
            float2 inputs:st.connect = </usd_converter_materials/StingrayPBS_0/Primvar.outputs:result>
            token inputs:wrapS = "repeat"
            token inputs:wrapT = "repeat"
            float3 outputs:rgb
        }

        def Shader "normal_map"
        {
            uniform token info:id = "UsdUVTexture"
            float4 inputs:default = (0, 0, 0, 1)
            asset inputs:file = @/Users/jimmygunawan/Desktop/snailspindemo/old-textured-fabric-normal.png@
            float2 inputs:st.connect = </usd_converter_materials/StingrayPBS_0/Primvar.outputs:result>
            token inputs:wrapS = "repeat"
            token inputs:wrapT = "repeat"
            float3 outputs:rgb
        }

        def Shader "ao_map"
        {
            uniform token info:id = "UsdUVTexture"
            float4 inputs:default = (0, 0, 0, 1)
            asset inputs:file = @/Users/jimmygunawan/Desktop/snailspindemo/old-textured-fabric-ao.png@
            float2 inputs:st.connect = </usd_converter_materials/StingrayPBS_0/Primvar.outputs:result>
            token inputs:wrapS = "repeat"
            token inputs:wrapT = "repeat"
            float outputs:r
        }

        def Shader "emissive_map"
        {
            uniform token info:id = "UsdUVTexture"
            float4 inputs:default = (0, 0, 0, 1)
            float2 inputs:st.connect = </usd_converter_materials/StingrayPBS_0/Primvar.outputs:result>
            token inputs:wrapS = "repeat"
            token inputs:wrapT = "repeat"
            float3 outputs:rgb
        }

        def Shader "metallic_map"
        {
            uniform token info:id = "UsdUVTexture"
            float4 inputs:default = (0, 0, 0, 1)
            asset inputs:file = @/Users/jimmygunawan/Desktop/snailspindemo/old-textured-fabric-metal.png@
            float2 inputs:st.connect = </usd_converter_materials/StingrayPBS_0/Primvar.outputs:result>
            token inputs:wrapS = "repeat"
            token inputs:wrapT = "repeat"
            float outputs:r
        }

        def Shader "roughness_map"
        {
            uniform token info:id = "UsdUVTexture"
            float4 inputs:default = (0, 0, 0, 1)
            asset inputs:file = @/Users/jimmygunawan/Desktop/snailspindemo/old-textured-fabric-roughness.png@
            float2 inputs:st.connect = </usd_converter_materials/StingrayPBS_0/Primvar.outputs:result>
            token inputs:wrapS = "repeat"
            token inputs:wrapT = "repeat"
            float outputs:r
        }
    }

    def Material "StingrayPBS_1"
    {
        token inputs:frame:stPrimvarName = "Texture_uv"
        token outputs:displacement.connect = </usd_converter_materials/StingrayPBS_1/pbr.outputs:displacement>
        token outputs:surface.connect = </usd_converter_materials/StingrayPBS_1/pbr.outputs:surface>

        def Shader "pbr"
        {
            uniform token info:id = "UsdPreviewSurface"
            float inputs:clearcoat = 0
            float inputs:clearcoatRoughness = 0
            color3f inputs:diffuseColor.connect = </usd_converter_materials/StingrayPBS_1/color_map.outputs:rgb>
            float inputs:displacement = 0
            color3f inputs:emissiveColor.connect = </usd_converter_materials/StingrayPBS_1/emissive_map.outputs:rgb>
            float inputs:ior = 1.5
            float inputs:metallic.connect = </usd_converter_materials/StingrayPBS_1/metallic_map.outputs:r>
            normal3f inputs:normal.connect = </usd_converter_materials/StingrayPBS_1/normal_map.outputs:rgb>
            float inputs:occlusion.connect = </usd_converter_materials/StingrayPBS_1/ao_map.outputs:r>
            float inputs:opacity = 1
            float inputs:roughness.connect = </usd_converter_materials/StingrayPBS_1/roughness_map.outputs:r>
            color3f inputs:specularColor = (1, 1, 1)
            int inputs:useSpecularWorkflow = 0
            token outputs:displacement
            token outputs:surface
        }

        def Shader "Primvar"
        {
            uniform token info:id = "UsdPrimvarReader_float2"
            float2 inputs:default = (0, 0)
            token inputs:varname.connect = </usd_converter_materials/StingrayPBS_1.inputs:frame:stPrimvarName>
            float2 outputs:result
        }

        def Shader "color_map"
        {
            uniform token info:id = "UsdUVTexture"
            float4 inputs:default = (0, 0, 0, 1)
            asset inputs:file = @/Users/jimmygunawan/Desktop/snail_usdz/bamboo-wood-semigloss-albedo.png@
            float2 inputs:st.connect = </usd_converter_materials/StingrayPBS_1/Primvar.outputs:result>
            token inputs:wrapS = "repeat"
            token inputs:wrapT = "repeat"
            float3 outputs:rgb
        }

        def Shader "normal_map"
        {
            uniform token info:id = "UsdUVTexture"
            float4 inputs:default = (0, 0, 0, 1)
            asset inputs:file = @/Users/jimmygunawan/Desktop/snail_usdz/bamboo-wood-semigloss-normal.png@
            float2 inputs:st.connect = </usd_converter_materials/StingrayPBS_1/Primvar.outputs:result>
            token inputs:wrapS = "repeat"
            token inputs:wrapT = "repeat"
            float3 outputs:rgb
        }

        def Shader "ao_map"
        {
            uniform token info:id = "UsdUVTexture"
            float4 inputs:default = (0, 0, 0, 1)
            float2 inputs:st.connect = </usd_converter_materials/StingrayPBS_1/Primvar.outputs:result>
            token inputs:wrapS = "repeat"
            token inputs:wrapT = "repeat"
            float outputs:r
        }

        def Shader "emissive_map"
        {
            uniform token info:id = "UsdUVTexture"
            float4 inputs:default = (0, 0, 0, 1)
            float2 inputs:st.connect = </usd_converter_materials/StingrayPBS_1/Primvar.outputs:result>
            token inputs:wrapS = "repeat"
            token inputs:wrapT = "repeat"
            float3 outputs:rgb
        }

        def Shader "metallic_map"
        {
            uniform token info:id = "UsdUVTexture"
            float4 inputs:default = (0, 0, 0, 1)
            asset inputs:file = @/Users/jimmygunawan/Desktop/snail_usdz/bamboo-wood-semigloss-metal.png@
            float2 inputs:st.connect = </usd_converter_materials/StingrayPBS_1/Primvar.outputs:result>
            token inputs:wrapS = "repeat"
            token inputs:wrapT = "repeat"
            float outputs:r
        }

        def Shader "roughness_map"
        {
            uniform token info:id = "UsdUVTexture"
            float4 inputs:default = (0, 0, 0, 1)
            asset inputs:file = @/Users/jimmygunawan/Desktop/snail_usdz/bamboo-wood-semigloss-roughness.png@
            float2 inputs:st.connect = </usd_converter_materials/StingrayPBS_1/Primvar.outputs:result>
            token inputs:wrapS = "repeat"
            token inputs:wrapT = "repeat"
            float outputs:r
        }
    }
}
enzyme69 commented 6 years ago

Above USDA example is referencing:

And using hierarchy and rotation operator, it will procedurally spin the 3D AR in realtime. When converted into USDZ it will work as AR Quick Look.

enzyme69 commented 6 years ago

FUNNY GOTCHA: Last time I check, USDZ with this type of procedural animation does not actually spin, but it works on iOS as AR Quick Look too. This is interesting!

enzyme69 commented 6 years ago

Spin Axis and Actual Up Axis can be confusing, but here is spinning suzanne head:

#usda 1.0
(
    endTimeCode = 480
    startTimeCode = 0
    upAxis = "Y"
    defaultPrim = "Top"
)

def Xform "Top" (
)
{

    def Mesh "Suzanne"
    {xxx}

    float xformOp:rotateY:spin.timeSamples = {
        0: 0,
        480: 1440,
    }
    uniform token[] xformOpOrder = ["xformOp:rotateY:spin"]
}
enzyme69 commented 6 years ago

NOTE: seems like referencing OBJ is crashing usdz_converter now... weird