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
| import fbx from fbx import FbxVector2 import os import csv
def Run(): node = hou.pwd() fileName=node.parm("file").eval() csv_path = node.parm('csv_path').eval() directory = node.parm('directory').eval() num =1 birth_data = DuplicateArray(ReadCsvByPath(csv_path,num)) for path in birth_data: fileName = os.path.basename(path) if "@" not in fileName: print path iter=0 fbxManager = fbx.FbxManager.Create() fbxScene = fbx.FbxScene.Create(fbxManager, "") fbxImporter = fbx.FbxImporter.Create(fbxManager, "") fbxImporter.Initialize(path) fbxImporter.Import(fbxScene) fbxRoot = fbxScene.GetRootNode() if IsCollider(fileName) == True: for i in GetFbxNodeList(fbxRoot,list = []): if i.GetMesh()!= None: i.GetMesh().ClearLayers() iter+=1 for i in GetFbxNodeList(fbxRoot,list = []): if i.GetMesh()!= None: mesh = i.GetMesh() LayerCount = mesh.GetLayerCount() for j in range(LayerCount): Layer = mesh.GetLayer(j) if(Layer.GetVertexColors()!=None): Layer.SetVertexColors(None) iter+=1
if LayerCount>=4: for j in range(LayerCount): if j==1 or j==2: Layer = mesh.GetLayer(j) uv = Layer.GetUVs() DirectArray = uv.GetDirectArray() DirectArray.SetCount(1) DirectArray.SetAt(0,FbxVector2(0,0)) iter+=1 elif j>3: Layer = mesh.GetLayer(j) Layer.SetUVs(None) iter+=1 if LayerCount<4: for j in range(LayerCount): if j>0: Layer = mesh.GetLayer(j) Layer.SetUVs(None) iter+=1 if iter!=0: ExportFbx(fbxManager,path,fbxScene) fbxScene.Destroy() fbxImporter.Destroy() fbxManager.Destroy() def GetFbxNodeList(fbxRoot,list = []): num = fbxRoot.GetChildCount() for i in range(fbxRoot.GetChildCount()): fbxChildRoot = fbxRoot.GetChild(i) list.append(fbxChildRoot) if fbxChildRoot.GetChildCount()>0 : GetFbxNodeList(fbxChildRoot,list) return list def ExportFbx(fbxManager,fileName,fbxScene): fbxExporter = fbx.FbxExporter.Create(fbxManager, "Exporter") fileFormat = -1 fbxExporter.Initialize(fileName,fileFormat,fbxManager.GetIOSettings()) fbxExporter.Export(fbxScene) fbxExporter.Destroy()
def GetFbxListInDirectory(filepath,file_type,list=[]): path_list = os.listdir(filepath) for f1 in path_list: f1_path = os.path.join(filepath,f1) if os.path.isfile(f1_path): suffix = os.path.splitext(f1_path)[0][1:] if suffix.lower() == file_type: f1_path.replace("\\","/") list.append(f1_path) if os.path.isdir(f1_path): GetFbxListInDirectory(f1_path,file_type,list) return list def IsCollider(fileName): if "Collider" in fileName or "collider" in fileName: return True else: return False def DuplicateArray(Imported_Array): List = [] for i in Imported_Array: if i not in List: List.append(i) return List
def ReadCsvByPath(csv_path,num): birth_data = [] with open(csv_path) as csvfile: csv_reader = csv.reader(csvfile) for row in csv_reader: birth_data.append(str(row[num])) return birth_data
|