簡體   English   中英

Python for USD——在立方體上映射一個紋理,這樣每個面都有相同的圖像

[英]Python for USD – Map a texture on a cube so every face have the same image

貼圖紋理錯誤的立方體背面

我有一個簡單的網格立方體,我希望在立方體的每個面上應用相同的圖像:這是我目前所擁有的(正面可以,但其他面不行)

# create mesh with texture coordinates
stage.DefinePrim('/' + assetName + '/Geom', 'Scope')
mesh = UsdGeom.Mesh.Define(stage, '/' + assetName + '/Geom/cube')
mesh.CreateSubdivisionSchemeAttr().Set(UsdGeom.Tokens.none)
mesh.CreatePointsAttr([(-x/2, -y/2, z/2), (x/2, -y/2, z/2), (-x/2, y/2, z/2), (x/2, y/2, z/2), (-x/2, y/2, -z/2), (x/2, y/2, -z/2), (-x/2, -y/2, -z/2), (x/2, -y/2, -z/2)])
mesh.CreateExtentAttr(UsdGeom.PointBased(mesh).ComputeExtent(mesh.GetPointsAttr().Get()))
mesh.CreateNormalsAttr([(0,0,1), (0,1,0), (0,0,-1), (0,-1,0), (1,0,0), (-1,0,0)])
mesh.SetNormalsInterpolation(UsdGeom.Tokens.uniform)

mesh.CreateFaceVertexCountsAttr([4, 4, 4, 4, 4, 4])
mesh.CreateFaceVertexIndicesAttr([0,1,3,2, 2,3,5,4, 4,5,7,6, 6,7,1,0, 1,7,5,3, 6,0,2,4]) # per-face vertex indices
    
texCoords = mesh.CreatePrimvar('st', Sdf.ValueTypeNames.TexCoord2fArray, UsdGeom.Tokens.faceVarying) # a 'faceVarying' mesh attribute is stored per-face per-vertex
texCoords.Set([(0, 0),(1, 0), (1,1), (0, 1), (0, 0), (1, 0), (1, 1), (0, 1), (0, 0), (1, 0), (1, 1), (0, 1), (0, 0), (1, 0)])

texCoords.SetIndices(Vt.IntArray([0,1,2,3, 3,2,4,5, 5,4,6,7, 7,6,8,9, 1,10,11,2, 12,0,3,13]))

正面有預期的紋理,但其他人很奇怪。 我不明白紋理坐標是如何定義的。

感謝您的幫助。

美國農業部 Python 腳本

我有以下解決方案,但它的映射不正確(您應該從頭開始重建這個立方體原語)。 但是,此示例清楚地向您展示了如何將紋理映射到 USDA 模型的每個單獨面上。

在此處輸入圖像描述

#usda 1.0
(
    defaultPrim = "Cube"
    upAxis = "Y"
)

def Xform "Cube" (kind = "component")
{
    def Mesh "polyCube"
    {    
        float3[] extent = [(-0.5, -0.5, -0.5), (0.5, 0.5, 0.5)]    
        int[] faceVertexCounts = [4, 4, 4, 4, 4, 4]    
        int[] faceVertexIndices = [ 0, 1, 3, 2,  2, 3, 5, 4,  4, 5, 7, 6, 
                                    6, 7, 1, 0,  1, 7, 5, 3,  6, 0, 2, 4 ]

        point3f[] points = [ (-0.5,-0.5, 0.5), (0.5,-0.5, 0.5), 
                             (-0.5, 0.5, 0.5), (0.5, 0.5, 0.5), 
                             (-0.5, 0.5,-0.5), (0.5, 0.5,-0.5), 
                             (-0.5,-0.5,-0.5), (0.5,-0.5,-0.5) ]

        texCoord2f[] primvars:st = [ (0, 0), (0, 1), (1, 0), (1, 1), (0, 0), 
                                     (0, 1), (1, 0), (1, 1), (0, 0), (0, 1), 
                                     (1, 0), (1, 1), (0, 0), (0, 1) ] (    
            interpolation = "faceVarying"
        )

        int[] primvars:st:indices = [ 0, 1, 2, 3,   3, 2, 4, 5,    5, 4, 6, 7, 
                                      7, 6, 8, 9,   1, 10, 11, 2,  12, 0, 3, 13 ]

        color3f[] primvars:displayColor = [(0.75, 0.75, 0.75)]
        rel material:binding = </Texturing/Material>
    } 
}

這是一個着色器:

def Xform "Texturing" 
{
    def Material "Material"
    {
        token outputs:surface.connect = </Texturing/Material/Surface.outputs:surface>

        def Shader "Surface"
        {
            uniform token info:id = "UsdUVTexture"
            asset inputs:file = @image.jpg@

            token inputs:wrapS = "repeat"
            token inputs:wrapT = "repeat"
            token outputs:rgb

            color3f inputs:diffuseColor.connect = </Texturing/Material/Surface.outputs:rgb>    
            token outputs:surface
        }
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM