-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDisplayMesh.py
More file actions
371 lines (296 loc) · 16 KB
/
Copy pathDisplayMesh.py
File metadata and controls
371 lines (296 loc) · 16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
"""
Copyright (C) 2001 - 2016 Autodesk, Inc. and/or its licensors.
All Rights Reserved.
The coded instructions, statements, computer programs, and/or related material
(collectively the "Data") in these files contain unpublished information
proprietary to Autodesk, Inc. and/or its licensors, which is protected by
Canada and United States of America federal copyright law and by international
treaties.
The Data may not be disclosed or distributed to third parties, in whole or in
part, without the prior written consent of Autodesk, Inc. ("Autodesk").
THE DATA IS PROVIDED "AS IS" AND WITHOUT WARRANTY.
ALL WARRANTIES ARE EXPRESSLY EXCLUDED AND DISCLAIMED. AUTODESK MAKES NO
WARRANTY OF ANY KIND WITH RESPECT TO THE DATA, EXPRESS, IMPLIED OR ARISING
BY CUSTOM OR TRADE USAGE, AND DISCLAIMS ANY IMPLIED WARRANTIES OF TITLE,
NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE OR USE.
WITHOUT LIMITING THE FOREGOING, AUTODESK DOES NOT WARRANT THAT THE OPERATION
OF THE DATA WILL BE UNINTERRUPTED OR ERROR FREE.
IN NO EVENT SHALL AUTODESK, ITS AFFILIATES, PARENT COMPANIES, LICENSORS
OR SUPPLIERS ("AUTODESK GROUP") BE LIABLE FOR ANY LOSSES, DAMAGES OR EXPENSES
OF ANY KIND (INCLUDING WITHOUT LIMITATION PUNITIVE OR MULTIPLE DAMAGES OR OTHER
SPECIAL, DIRECT, INDIRECT, EXEMPLARY, INCIDENTAL, LOSS OF PROFITS, REVENUE
OR DATA, COST OF COVER OR CONSEQUENTIAL LOSSES OR DAMAGES OF ANY KIND),
HOWEVER CAUSED, AND REGARDLESS OF THE THEORY OF LIABILITY, WHETHER DERIVED
FROM CONTRACT, TORT (INCLUDING, BUT NOT LIMITED TO, NEGLIGENCE), OR OTHERWISE,
ARISING OUT OF OR RELATING TO THE DATA OR ITS USE OR ANY OTHER PERFORMANCE,
WHETHER OR NOT AUTODESK HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH LOSS
OR DAMAGE.
"""
from DisplayCommon import *
from fbx import FbxLayerElement
from fbx import FbxSurfaceMaterial
from fbx import FbxLayeredTexture
from fbx import FbxTexture
from fbx import FbxCriteria
from DisplayMaterial import DisplayMaterial
from DisplayTexture import DisplayTexture
from DisplayLink import DisplayLink
from DisplayShape import DisplayShape
def DisplayMesh(pNode):
lMesh = pNode.GetNodeAttribute ()
DisplayString("Mesh Name: ", pNode.GetName())
DisplayControlsPoints(lMesh)
DisplayPolygons(lMesh)
DisplayMaterialMapping(lMesh)
DisplayMaterial(lMesh)
DisplayTexture(lMesh)
DisplayMaterialConnections(lMesh)
DisplayLink(lMesh)
DisplayShape(lMesh)
def DisplayControlsPoints(pMesh):
lControlPointsCount = pMesh.GetControlPointsCount()
lControlPoints = pMesh.GetControlPoints()
DisplayString(" Control Points")
for i in range(lControlPointsCount):
DisplayInt(" Control Point ", i)
Display3DVector(" Coordinates: ", lControlPoints[i])
for j in range(pMesh.GetLayerCount()):
leNormals = pMesh.GetLayer(j).GetNormals()
if leNormals:
if leNormals.GetMappingMode() == FbxLayerElement.EMappingMode.eByControlPoint:
header = " Normal Vector (on layer %d): " % j
if leNormals.GetReferenceMode() == FbxLayerElement.EReferenceMode.eDirect:
Display3DVector(header, leNormals.GetDirectArray().GetAt(i))
DisplayString("")
def DisplayPolygons(pMesh):
lPolygonCount = pMesh.GetPolygonCount()
lControlPoints = pMesh.GetControlPoints()
DisplayString(" Polygons")
vertexId = 0
for i in range(lPolygonCount):
DisplayInt(" Polygon ", i)
for l in range(pMesh.GetLayerCount()):
lePolgrp = pMesh.GetLayer(l).GetPolygonGroups()
if lePolgrp:
if lePolgrp.GetMappingMode() == FbxLayerElement.EMappingMode.eByPolygon:
if lePolgrp.GetReferenceMode() == FbxLayerElement.EReferenceMode.eIndex:
header = " Assigned to group (on layer %d): " % l
polyGroupId = lePolgrp.GetIndexArray().GetAt(i)
DisplayInt(header, polyGroupId)
else:
# any other mapping modes don't make sense
DisplayString(" \"unsupported group assignment\"")
lPolygonSize = pMesh.GetPolygonSize(i)
for j in range(lPolygonSize):
lControlPointIndex = pMesh.GetPolygonVertex(i, j)
Display3DVector(" Coordinates: ", lControlPoints[lControlPointIndex])
for l in range(pMesh.GetLayerCount()):
leVtxc = pMesh.GetLayer(l).GetVertexColors()
if leVtxc:
header = " Color vertex (on layer %d): " % l
if leVtxc.GetMappingMode() == FbxLayerElement.EMappingMode.eByControlPoint:
if leVtxc.GetReferenceMode() == FbxLayerElement.EReferenceMode.eDirect:
DisplayColor(header, leVtxc.GetDirectArray().GetAt(lControlPointIndex))
elif leVtxc.GetReferenceMode() == FbxLayerElement.EReferenceMode.eIndexToDirect:
id = leVtxc.GetIndexArray().GetAt(lControlPointIndex)
DisplayColor(header, leVtxc.GetDirectArray().GetAt(id))
elif leVtxc.GetMappingMode() == FbxLayerElement.EMappingMode.eByPolygonVertex:
if leVtxc.GetReferenceMode() == FbxLayerElement.EReferenceMode.eDirect:
DisplayColor(header, leVtxc.GetDirectArray().GetAt(vertexId))
elif leVtxc.GetReferenceMode() == FbxLayerElement.EReferenceMode.eIndexToDirect:
id = leVtxc.GetIndexArray().GetAt(vertexId)
DisplayColor(header, leVtxc.GetDirectArray().GetAt(id))
elif leVtxc.GetMappingMode() == FbxLayerElement.EMappingMode.eByPolygon or \
leVtxc.GetMappingMode() == FbxLayerElement.EMappingMode.eAllSame or \
leVtxc.GetMappingMode() == FbxLayerElement.EMappingMode.eNone:
# doesn't make much sense for UVs
pass
leUV = pMesh.GetLayer(l).GetUVs()
if leUV:
header = " Texture UV (on layer %d): " % l
if leUV.GetMappingMode() == FbxLayerElement.EMappingMode.eByControlPoint:
if leUV.GetReferenceMode() == FbxLayerElement.EReferenceMode.eDirect:
Display2DVector(header, leUV.GetDirectArray().GetAt(lControlPointIndex))
elif leUV.GetReferenceMode() == FbxLayerElement.EReferenceMode.eIndexToDirect:
id = leUV.GetIndexArray().GetAt(lControlPointIndex)
Display2DVector(header, leUV.GetDirectArray().GetAt(id))
elif leUV.GetMappingMode() == FbxLayerElement.EMappingMode.eByPolygonVertex:
lTextureUVIndex = pMesh.GetTextureUVIndex(i, j)
if leUV.GetReferenceMode() == FbxLayerElement.EReferenceMode.eDirect or \
leUV.GetReferenceMode() == FbxLayerElement.EReferenceMode.eIndexToDirect:
Display2DVector(header, leUV.GetDirectArray().GetAt(lTextureUVIndex))
elif leUV.GetMappingMode() == FbxLayerElement.EMappingMode.eByPolygon or \
leUV.GetMappingMode() == FbxLayerElement.eAllSame or \
leUV.GetMappingMode() == FbxLayerElement.eNone:
# doesn't make much sense for UVs
pass
# # end for layer
vertexId += 1
# # end for polygonSize
# # end for polygonCount
# check visibility for the edges of the mesh
for l in range(pMesh.GetLayerCount()):
leVisibility=pMesh.GetLayer(0).GetVisibility()
if leVisibility:
header = " Edge Visibilty (on layer %d): " % l
DisplayString(header)
# should be eByEdge
if leVisibility.GetMappingMode() == FbxLayerElement.eByEdge:
# should be eDirect
for j in range(pMesh.GetMeshEdgeCount()):
DisplayInt(" Edge ", j)
DisplayBool(" Edge visibilty: ", leVisibility.GetDirectArray().GetAt(j))
DisplayString("")
def DisplayTextureNames(pProperty):
lTextureName = ""
lLayeredTextureCount = pProperty.GetSrcObjectCount(FbxCriteria.ObjectType(FbxLayeredTexture.ClassId))
if lLayeredTextureCount > 0:
for j in range(lLayeredTextureCount):
lLayeredTexture = pProperty.GetSrcObject(FbxCriteria.ObjectType(FbxLayeredTexture.ClassId), j)
lNbTextures = lLayeredTexture.GetSrcObjectCount(FbxCriteria.ObjectType(FbxTexture.ClassId))
lTextureName = " Texture "
for k in range(lNbTextures):
lTextureName += "\""
lTextureName += lLayeredTexture.GetName()
lTextureName += "\""
lTextureName += " "
lTextureName += "of "
lTextureName += pProperty.GetName().Buffer()
lTextureName += " on layer "
lTextureName += j
lTextureName += " |"
else:
#no layered texture simply get on the property
lNbTextures = pProperty.GetSrcObjectCount(FbxCriteria.ObjectType(FbxTexture.ClassId))
if lNbTextures > 0:
lTextureName = " Texture "
lTextureName += " "
for j in range(lNbTextures):
lTexture = pProperty.GetSrcObject(FbxCriteria.ObjectType(FbxTexture.ClassId),j)
if lTexture:
lTextureName += "\""
lTextureName += lTexture.GetName()
lTextureName += "\""
lTextureName += " "
lTextureName += "of "
lTextureName += pProperty.GetName().Buffer()
lTextureName += " |"
return lTextureName
def DisplayMaterialTextureConnections(pMaterial, pMatId, l ):
lConnectionString = " Material " + str(pMatId) + " (on layer " + str(l) +") -- "
#Show all the textures
#Diffuse Textures
lProperty = pMaterial.FindProperty(FbxSurfaceMaterial.sDiffuse)
lConnectionString += DisplayTextureNames(lProperty)
#DiffuseFactor Textures
lProperty = pMaterial.FindProperty(FbxSurfaceMaterial.sDiffuseFactor)
lConnectionString += DisplayTextureNames(lProperty)
#Emissive Textures
lProperty = pMaterial.FindProperty(FbxSurfaceMaterial.sEmissive)
lConnectionString += DisplayTextureNames(lProperty)
#EmissiveFactor Textures
lProperty = pMaterial.FindProperty(FbxSurfaceMaterial.sEmissiveFactor)
lConnectionString += DisplayTextureNames(lProperty)
#Ambient Textures
lProperty = pMaterial.FindProperty(FbxSurfaceMaterial.sAmbient)
lConnectionString += DisplayTextureNames(lProperty)
#AmbientFactor Textures
lProperty = pMaterial.FindProperty(FbxSurfaceMaterial.sAmbientFactor)
lConnectionString += DisplayTextureNames(lProperty)
#Specular Textures
lProperty = pMaterial.FindProperty(FbxSurfaceMaterial.sSpecular)
lConnectionString += DisplayTextureNames(lProperty)
#SpecularFactor Textures
lProperty = pMaterial.FindProperty(FbxSurfaceMaterial.sSpecularFactor)
lConnectionString += DisplayTextureNames(lProperty)
#Shininess Textures
lProperty = pMaterial.FindProperty(FbxSurfaceMaterial.sShininess)
lConnectionString += DisplayTextureNames(lProperty)
#Bump Textures
lProperty = pMaterial.FindProperty(FbxSurfaceMaterial.sBump)
lConnectionString += DisplayTextureNames(lProperty)
#Normal Map Textures
lProperty = pMaterial.FindProperty(FbxSurfaceMaterial.sNormalMap)
lConnectionString += DisplayTextureNames(lProperty)
#Transparent Textures
lProperty = pMaterial.FindProperty(FbxSurfaceMaterial.sTransparentColor)
lConnectionString += DisplayTextureNames(lProperty)
#TransparencyFactor Textures
lProperty = pMaterial.FindProperty(FbxSurfaceMaterial.sTransparencyFactor)
lConnectionString += DisplayTextureNames(lProperty)
#Reflection Textures
lProperty = pMaterial.FindProperty(FbxSurfaceMaterial.sReflection)
lConnectionString += DisplayTextureNames(lProperty)
#ReflectionFactor Textures
lProperty = pMaterial.FindProperty(FbxSurfaceMaterial.sReflectionFactor)
lConnectionString += DisplayTextureNames(lProperty)
#if(lMaterial != NULL)
DisplayString(lConnectionString)
def DisplayMaterialConnections(pMesh):
lPolygonCount = pMesh.GetPolygonCount()
DisplayString(" Polygons Material Connections")
#check whether the material maps with only one mesh
lIsAllSame = True
for l in range(pMesh.GetLayerCount()):
lLayerMaterial = pMesh.GetLayer(l).GetMaterials()
if lLayerMaterial:
if lLayerMaterial.GetMappingMode() == FbxLayerElement.EMappingMode.eByPolygon:
lIsAllSame = False
break
#For eAllSame mapping type, just out the material and texture mapping info once
if lIsAllSame:
for l in range(pMesh.GetLayerCount()):
lLayerMaterial = pMesh.GetLayer(l).GetMaterials()
if lLayerMaterial:
if lLayerMaterial.GetMappingMode() == FbxLayerElement.EMappingMode.eAllSame:
lMaterial = pMesh.GetNode().GetMaterial(lLayerMaterial.GetIndexArray().GetAt(0))
lMatId = lLayerMaterial.GetIndexArray().GetAt(0)
if lMatId >=0:
DisplayInt(" All polygons share the same material on layer ", l)
DisplayMaterialTextureConnections(lMaterial, lMatId, l)
else:
#layer 0 has no material
if l == 0:
DisplayString(" no material applied")
#For eByPolygon mapping type, just out the material and texture mapping info once
else:
for i in range(lPolygonCount):
DisplayInt(" Polygon ", i)
for l in range(pMesh.GetLayerCount()):
lLayerMaterial = pMesh.GetLayer(l).GetMaterials()
if lLayerMaterial:
lMatId = -1
lMaterial = pMesh.GetNode().GetMaterial(lLayerMaterial.GetIndexArray().GetAt(i))
lMatId = lLayerMaterial.GetIndexArray().GetAt(i)
if lMatId >= 0:
DisplayMaterialTextureConnections(lMaterial, lMatId, l)
def DisplayMaterialMapping(pMesh):
lMappingTypes = [ "None", "By Control Point", "By Polygon Vertex", "By Polygon", "By Edge", "All Same" ]
lReferenceMode = [ "Direct", "Index", "Index to Direct"]
lMtrlCount = 0
lNode = None
if pMesh:
lNode = pMesh.GetNode()
if lNode:
lMtrlCount = lNode.GetMaterialCount()
for l in range(pMesh.GetLayerCount()):
leMat = pMesh.GetLayer(l).GetMaterials()
if leMat:
header = " Material layer %d: " % l
DisplayString(header)
DisplayString(" Mapping: ", lMappingTypes[leMat.GetMappingMode().value])
DisplayString(" ReferenceMode: ", lReferenceMode[leMat.GetReferenceMode().value])
lMaterialCount = 0
if leMat.GetReferenceMode() == FbxLayerElement.EReferenceMode.eDirect or \
leMat.GetReferenceMode() == FbxLayerElement.EReferenceMode.eIndexToDirect:
lMaterialCount = lMtrlCount
if leMat.GetReferenceMode() == FbxLayerElement.EReferenceMode.eIndex or \
leMat.GetReferenceMode() == FbxLayerElement.EReferenceMode.eIndexToDirect:
lString = " Indices: "
lIndexArrayCount = leMat.GetIndexArray().GetCount()
for i in range(lIndexArrayCount):
lString += str(leMat.GetIndexArray().GetAt(i))
if i < lIndexArrayCount - 1:
lString += ", "
DisplayString(lString)
DisplayString("")