-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDisplayMaterial.py
More file actions
219 lines (186 loc) · 12.4 KB
/
Copy pathDisplayMaterial.py
File metadata and controls
219 lines (186 loc) · 12.4 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
"""
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 fbx import *
from DisplayCommon import *
def DisplayMaterial(pGeometry):
lMaterialCount = 0
lNode = None
if pGeometry:
lNode = pGeometry.GetNode()
if lNode:
lMaterialCount = lNode.GetMaterialCount()
for l in range(pGeometry.GetLayerCount()):
leMat = pGeometry.GetLayer(l).GetMaterials()
if leMat:
if leMat.GetReferenceMode() == FbxLayerElement.EReferenceMode.eIndex:
#Materials are in an undefined external table
continue
if lMaterialCount > 0:
theColor = FbxColor()
header = " Materials on layer %d: " % l
DisplayString(header)
for lCount in range(lMaterialCount):
DisplayInt(" Material ", lCount)
lMaterial = lNode.GetMaterial(lCount)
DisplayString(" Name: \"", lMaterial.GetName(), "\"")
#Get the implementation to see if it's a hardware shader.
lImplementation = GetImplementation(lMaterial, "ImplementationHLSL")
lImplemenationType = "HLSL"
if not lImplementation:
lImplementation = GetImplementation(lMaterial, "ImplementationCGFX")
lImplemenationType = "CGFX"
if lImplementation:
#Now we have a hardware shader, let's read it
print(" Hardware Shader Type: %s\n" % lImplemenationType.Buffer())
lRootTable = lImplementation.GetRootTable()
lFileName = lRootTable.DescAbsoluteURL.Get()
lTechniqueName = lRootTable.DescTAG.Get()
lTable = lImplementation.GetRootTable()
lEntryNum = lTable.GetEntryCount()
for i in range(lEntryNum):
lEntry = lTable.GetEntry(i)
lEntry.GetEntryType(True)
lTest = lEntry.GetSource()
print(" Entry: %s\n" % lTest.Buffer())
if cmp( FbxPropertyEntryView.sEntryType, lEntrySrcType ) == 0:
lFbxProp = lMaterial.FindPropertyHierarchical(lEntry.GetSource())
if not lFbxProp.IsValid():
lFbxProp = lMaterial.RootProperty.FindHierarchical(lEntry.GetSource())
elif cmp( FbxConstantEntryView.sEntryType, lEntrySrcType ) == 0:
lFbxProp = lImplementation.GetConstants().FindHierarchical(lEntry.GetSource())
if lFbxProp.IsValid():
if lFbxProp.GetSrcObjectCount( FbxCriteria.ObjectType(FbxTexture.ClassId) ) > 0:
#do what you want with the texture
for j in range(lFbxProp.GetSrcObjectCount(FbxCriteria.ObjectType(FbxTexture.ClassId))):
lTex = lFbxProp.GetSrcObject(FbxCriteria.ObjectType(FbxTexture.ClassId),j)
print(" Texture: %s\n" % lTex.GetFileName())
else:
lFbxType = lFbxProp.GetPropertyDataType()
if (lFbxType == EFbxType.eFbxBool):
lFbxProp = FbxPropertyBool1(lFbxProp)
DisplayBool(" Bool: ", lFbxProp.Get())
elif (lFbxType == EFbxType.eFbxInt):
lFbxProp = FbxPropertyInteger1(lFbxProp)
DisplayInt(" Int: ", lFbxProp.Get())
elif (lFbxType == EFbxType.eFbxEnum):
lFbxProp = FbxPropertyEnum(lFbxProp)
DisplayInt(" Enum: ", lFbxProp.Get())
elif (lFbxType == EFbxType.eFbxFloat):
lFbxProp = FbxPropertyFloat1(lFbxProp)
DisplayDouble(" Float: ", lFbxProp.Get())
elif ( lFbxType == EFbxType.eFbxDouble):
lFbxProp = FbxPropertyDouble1(lFbxProp)
DisplayDouble(" Double: ", lFbxProp.Get())
elif ( lFbxType == EFbxType.eFbxString ):
lFbxProp = FbxPropertyString(lFbxProp)
DisplayString(" String: ", lFbxProp.Get())
elif ( lFbxType == EFbxType.eFbxDouble2):
lFbxProp = FbxPropertyDouble2(lFbxProp)
res, lDouble2= lFbxProp.Get()
lVect = []
lVect[0] = lDouble2[0]
lVect[1] = lDouble2[1]
Display2DVector(" 2D vector: ", lVect)
elif ( lFbxType == EFbxType.eFbxDouble3):
lFbxProp = FbxPropertyDouble3(lFbxProp)
res, lDouble3 = lFbxProp.Get()
lVect = []
lVect[0] = lDouble3[0]
lVect[1] = lDouble3[1]
lVect[2] = lDouble3[2]
Display3DVector(" 3D vector: ", lVect)
elif ( lFbxType == EFbxType.eFbxDouble4):
lFbxProp = FbxPropertyDouble4(lFbxProp)
res, lDouble4 = lFbxProp.Get()
lVect = []
lVect[0] = lDouble4[0]
lVect[1] = lDouble4[1]
lVect[2] = lDouble4[2]
lVect[3] = lDouble4[3]
Display4DVector(" 4D vector: ", lVect)
elif ( lFbxType == EFbxType.eFbxDouble4x4):
lFbxProp = FbxPropertyXMatrix(lFbxProp)
res, lDouble44 = lFbxProp.Get(EFbxType.eFbxDouble44)
for j in range(4):
lVect = []
lVect[0] = lDouble44[j][0]
lVect[1] = lDouble44[j][1]
lVect[2] = lDouble44[j][2]
lVect[3] = lDouble44[j][3]
Display4DVector(" 4x4D vector: ", lVect)
elif (lMaterial.GetClassId().Is(FbxSurfacePhong.ClassId)):
# We found a Phong material. Display its properties.
# Display the Ambient Color
lFbxDouble3 = lMaterial.Ambient
theColor.Set(lFbxDouble3.Get()[0], lFbxDouble3.Get()[1], lFbxDouble3.Get()[2])
DisplayColor(" Ambient: ", theColor)
# Display the Diffuse Color
lFbxDouble3 = lMaterial.Diffuse
theColor.Set(lFbxDouble3.Get()[0], lFbxDouble3.Get()[1], lFbxDouble3.Get()[2])
DisplayColor(" Diffuse: ", theColor)
# Display the Specular Color (unique to Phong materials)
lFbxDouble3 = lMaterial.Specular
theColor.Set(lFbxDouble3.Get()[0], lFbxDouble3.Get()[1], lFbxDouble3.Get()[2])
DisplayColor(" Specular: ", theColor)
# Display the Emissive Color
lFbxDouble3 = lMaterial.Emissive
theColor.Set(lFbxDouble3.Get()[0], lFbxDouble3.Get()[1], lFbxDouble3.Get()[2])
DisplayColor(" Emissive: ", theColor)
# Opacity is Transparency factor now
lFbxDouble1 = lMaterial.TransparencyFactor
DisplayDouble(" Opacity: ", 1.0-lFbxDouble1.Get())
# Display the Shininess
lFbxDouble1 = lMaterial.Shininess
DisplayDouble(" Shininess: ", lFbxDouble1.Get())
# Display the Reflectivity
lFbxDouble3 = lMaterial.Reflection
theColor.Set(lFbxDouble3.Get()[0], lFbxDouble3.Get()[1], lFbxDouble3.Get()[2])
DisplayColor(" Reflectivity: ", theColor)
elif lMaterial.GetClassId().Is(FbxSurfaceLambert.ClassId):
# We found a Lambert material. Display its properties.
# Display the Ambient Color
lFbxDouble3 = lMaterial.Ambient
theColor.Set(lFbxDouble3.Get()[0], lFbxDouble3.Get()[1], lFbxDouble3.Get()[2])
DisplayColor(" Ambient: ", theColor)
# Display the Diffuse Color
lFbxDouble3 = lMaterial.Diffuse
theColor.Set(lFbxDouble3.Get()[0], lFbxDouble3.Get()[1], lFbxDouble3.Get()[2])
DisplayColor(" Diffuse: ", theColor)
# Display the Emissive
lFbxDouble3 = lMaterial.Emissive
theColor.Set(lFbxDouble3.Get()[0], lFbxDouble3.Get()[1], lFbxDouble3.Get()[2])
DisplayColor(" Emissive: ", theColor)
# Display the Opacity
lFbxDouble1 = lMaterial.TransparencyFactor
DisplayDouble(" Opacity: ", 1.0-lFbxDouble1.Get())
else:
DisplayString("Unknown type of Material")
lString = lMaterial.ShadingModel
DisplayString(" Shading Model: ", lString.Get().Buffer())
DisplayString("")