0

我正在开发一个用 python 编写的用于导入多边形几何的 Maya 2013 插件(想想自定义 OBJ 格式的导入器)。我遇到了一个问题,即我无法让 UV 出现在 UV 编辑器中,即使我使用代码生成它们。我检查了 UV 的数量,知道它们已经创建,但似乎看不到在哪里可以找到它们。我知道这可能很棘手(与必须创建一个虚拟 UV 集有关)但我正在寻找有关导致此问题的原因以及如何解决它的洞察力。有任何想法吗?


示例代码:

UVSetNames = ['map1', 'other']

meshFS = maya.OpenMaya.MFnMesh()

newMesh = meshFS.create(numVertices, numFaces, points, faceCounts, faceConnects, uArray, vArray, outputMesh)    # ADDING THE UVs TO THE MESH AT THE SAME TIME
meshFS.updateSurface()
nodeName = meshFS.name()

print 'Mesh node name is: %s' % nodeName

# CREATE THE UV SET
meshFS.createUVSetWithName( UVSetNames[1] )
meshFS.setUVs(uArray, vArray, UVSetNames[1] )

maya.cmds.sets(nodeName, e=True, fe='initialShadingGroup')

print "A) NUM UVs (%s): %d" % (UVSetNames[0], meshFS.numUVs( UVSetNames[0] ) )
print "B) NUM UVs (%s): %d" % (UVSetNames[1], meshFS.numUVs( UVSetNames[1] ) )

结果:

VERT COUNT: 23088

FACE COUNT: 36019

CREATING VERTICIES

Mesh node name is: polySurfaceShape1

A) NUM UVs (map1): 23088

B) NUM UVs (other): 23088

场景文件示例

//Maya ASCII 2013 scene
//Name: example.ma
//Last modified: Mon, Oct 28, 2013 08:49:03 PM
//Codeset: UTF-8
requires maya "2013";
currentUnit -l centimeter -a degree -t film;
fileInfo "application" "maya";
fileInfo "product" "Maya 2013";
fileInfo "version" "2013 x64";
fileInfo "cutIdentifier" "201202220220-825135";
fileInfo "osv" "Mac OS X 10.8.5";
createNode transform -n "polySurface360";
createNode mesh -n "polySurfaceShape360" -p "polySurface360";
    setAttr -k off ".v";
    setAttr ".vir" yes;
    setAttr ".vif" yes;
    setAttr ".uvst[0].uvsn" -type "string" "map1";
    setAttr ".cuvs" -type "string" "map1";
    setAttr ".dcc" -type "string" "Ambient+Diffuse";
    setAttr ".covm[0]"  0 1 1;
    setAttr ".cdvm[0]"  0 1 1;
    setAttr -s 52 ".vt[0:51]"  -0.48699999 0.3705 0.1415 -0.52670002 0.3292 0.1186
         -0.52670002 0.35049999 -0.1302 -0.48699999 0.3964 -0.13240001 0.15009999 0.3705 0.1415
         0.15009999 0.3964 -0.13240001 0.18979999 0.35049999 -0.1302 0.18979999 0.3292 0.1186
         -0.43880001 0.40380001 0.1603 -0.43880001 0.43329999 -0.1302 0.1019 0.40380001 0.1603
         0.1019 0.43329999 -0.1302 -0.48030001 0.40740001 -0.25080001 -0.4303 0.4443 -0.2446
         -0.43450001 0.44060001 -0.2 -0.48370001 0.4034 -0.2022 0.1435 0.40740001 -0.25080001
         0.1468 0.4034 -0.2022 0.0977 0.44060001 -0.2 0.093400002 0.4443 -0.2446 -0.52170002 0.36129999 -0.25850001
         -0.52410001 0.3572 -0.2 0.1848 0.36129999 -0.25850001 0.18719999 0.3572 -0.2 -0.3802 0.4303 0.1762
         -0.3802 0.4632 -0.1302 0.043400001 0.4303 0.1762 0.043400001 0.4632 -0.1302 -0.32170001 0.45120001 0.1895
         -0.32170001 0.48719999 -0.1302 -0.0151 0.45120001 0.1895 -0.0151 0.48719999 -0.1302
         -0.36950001 0.4743 -0.2404 -0.3087 0.4984 -0.23630001 -0.31529999 0.49489999 -0.2
         -0.37490001 0.4707 -0.2 0.032600001 0.4743 -0.2404 0.037999999 0.4707 -0.2 -0.021600001 0.49489999 -0.2
         -0.028200001 0.4984 -0.23630001 -0.1684 0.46470001 0.19859999 -0.24510001 0.4603 0.1956
         -0.24510001 0.49759999 -0.1302 -0.1684 0.50279999 -0.1302 -0.091799997 0.49759999 -0.1302
         -0.091799997 0.4603 0.1956 -0.2419 0.50529999 -0.2 -0.2386 0.50870001 -0.2351 -0.094999999 0.50529999 -0.2
         -0.098300003 0.50870001 -0.2351 -0.1684 0.51050001 -0.2 -0.1684 0.51389998 -0.2339;
    setAttr -s 123 ".ed[0:122]"  0 1 0 1 2 0 2 0 1 2 3 1 3 0 1 4 5 1 5 6 1
         6 4 1 6 7 0 7 4 0 8 0 0 3 8 1 3 9 1 9 8 1 10 11 1 11 5 1 5 10 1 4 10 0 12 13 0 13 14 1
         14 12 1 14 15 1 15 12 1 16 17 1 17 18 1 18 16 1 18 19 1 19 16 0 20 12 0 15 20 1 15 21 1
         21 20 0 22 23 0 23 17 1 17 22 1 16 22 0 14 9 1 9 15 1 3 15 1 17 5 1 11 17 1 11 18 1
         3 21 1 2 21 0 23 6 0 5 23 1 24 8 0 9 24 1 9 25 1 25 24 1 26 27 1 27 11 1 11 26 1
         10 26 0 28 24 0 25 28 1 25 29 1 29 28 1 30 31 1 31 27 1 27 30 1 26 30 0 32 33 0 33 34 1
         34 32 1 34 35 1 35 32 1 36 37 1 37 38 1 38 36 1 38 39 1 39 36 0 13 32 0 35 13 1 35 14 1
         18 37 1 37 19 1 36 19 0 34 29 1 29 35 1 25 35 1 37 27 1 31 37 1 31 38 1 25 14 1 27 18 1
         40 41 0 41 42 1 42 40 1 42 43 1 43 40 1 43 44 1 44 40 1 44 45 1 45 40 0 29 42 1 41 29 1
         41 28 0 30 45 0 45 31 1 44 31 1 46 34 1 33 46 1 33 47 0 47 46 1 48 49 1 49 39 0 39 48 1
         38 48 1 50 46 1 47 50 1 47 51 0 51 50 1 51 49 0 49 50 1 48 50 1 34 42 1 46 42 1 44 48 1
         38 44 1 50 43 1 43 46 1 43 48 1;
    setAttr -s 72 -ch 216 ".fc[0:71]" -type "polyFaces" 
        f 3 0 1 2
        f 3 -3 3 4
        f 3 5 6 7
        f 3 -8 8 9
        f 3 10 -5 11
        f 3 -12 12 13
        f 3 14 15 16
        f 3 -17 -6 17
        f 3 18 19 20
        f 3 -21 21 22
        f 3 23 24 25
        f 3 -26 26 27
        f 3 28 -23 29
        f 3 -30 30 31
        f 3 32 33 34
        f 3 -35 -24 35
        f 3 -22 36 37
        f 3 -38 -13 38
        f 3 39 -16 40
        f 3 -41 41 -25
        f 3 -31 -39 42
        f 3 -43 -4 43
        f 3 44 -7 45
        f 3 -46 -40 -34
        f 3 46 -14 47
        f 3 -48 48 49
        f 3 50 51 52
        f 3 -53 -15 53
        f 3 54 -50 55
        f 3 -56 56 57
        f 3 58 59 60
        f 3 -61 -51 61
        f 3 62 63 64
        f 3 -65 65 66
        f 3 67 68 69
        f 3 -70 70 71
        f 3 72 -67 73
        f 3 -74 74 -20
        f 3 -27 75 76
        f 3 -77 -68 77
        f 3 -66 78 79
        f 3 -80 -57 80
        f 3 81 -60 82
        f 3 -83 83 -69
        f 3 -75 -81 84
        f 3 -85 -49 -37
        f 3 -42 -52 85
        f 3 -86 -82 -76
        f 3 86 87 88
        f 3 -89 89 90
        f 3 -91 91 92
        f 3 -93 93 94
        f 3 95 -88 96
        f 3 -97 97 -58
        f 3 -59 98 99
        f 3 -100 -94 100
        f 3 101 -64 102
        f 3 -103 103 104
        f 3 105 106 107
        f 3 -108 -71 108
        f 3 109 -105 110
        f 3 -111 111 112
        f 3 -113 113 114
        f 3 -115 -106 115
        f 3 -96 -79 116
        f 3 -117 -102 117
        f 3 118 -109 119
        f 3 -120 -84 -101
        f 3 -110 120 121
        f 3 -122 -90 -118
        f 3 -119 -92 122
        f 3 -123 -121 -116;
    setAttr ".cd" -type "dataPolyComponent" Index_Data Edge 0 ;
    setAttr ".cvd" -type "dataPolyComponent" Index_Data Vertex 0 ;
    setAttr ".hfd" -type "dataPolyComponent" Index_Data Face 0 ;
createNode lightLinker -s -n "lightLinker1";
    setAttr -s 2 ".lnk";
    setAttr -s 2 ".slnk";
createNode displayLayerManager -n "layerManager";
createNode displayLayer -n "defaultLayer";
createNode renderLayerManager -n "renderLayerManager";
createNode renderLayer -n "defaultRenderLayer";
    setAttr ".g" yes;
select -ne :time1;
    setAttr ".o" 1;
    setAttr ".unw" 1;
select -ne :renderPartition;
    setAttr -s 2 ".st";
select -ne :initialShadingGroup;
    setAttr ".ro" yes;
select -ne :initialParticleSE;
    setAttr ".ro" yes;
select -ne :defaultShaderList1;
    setAttr -s 2 ".s";
select -ne :postProcessList1;
    setAttr -s 2 ".p";
select -ne :defaultRenderingList1;
select -ne :renderGlobalsList1;
select -ne :hardwareRenderGlobals;
    setAttr ".ctrs" 256;
    setAttr ".btrs" 512;
select -ne :defaultHardwareRenderGlobals;
    setAttr ".fn" -type "string" "im";
    setAttr ".res" -type "string" "ntsc_4d 646 485 1.333";
relationship "link" ":lightLinker1" ":initialShadingGroup.message" ":defaultLightSet.message";
relationship "link" ":lightLinker1" ":initialParticleSE.message" ":defaultLightSet.message";
relationship "shadowLink" ":lightLinker1" ":initialShadingGroup.message" ":defaultLightSet.message";
relationship "shadowLink" ":lightLinker1" ":initialParticleSE.message" ":defaultLightSet.message";
connectAttr "layerManager.dli[0]" "defaultLayer.id";
connectAttr "renderLayerManager.rlmi[0]" "defaultRenderLayer.rlid";
connectAttr "defaultRenderLayer.msg" ":defaultRenderingList1.r" -na;
// End of example.ma
4

1 回答 1

3

从您的示例代码中,我看到您尚未将 UV 分配给几何体。create() 和 setUVs() 方法将使用您提供的 uv 数组创建纹理表,但不会将其分配给网格。您需要在调用 create() 或 setUVs() 后调用 assignUVs() 以完成 API 文档中建议的过程:create()setUVs()assignUVs()。您可以通过调用getAssignedUVs()来验证这一点。希望这有帮助!

于 2014-10-23T18:03:59.983 回答