Skip to content

Instantly share code, notes, and snippets.

@aobond2
Last active February 21, 2024 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aobond2/31a9bdd4f2bbd49da9a1fcfc3965e74e to your computer and use it in GitHub Desktop.
Save aobond2/31a9bdd4f2bbd49da9a1fcfc3965e74e to your computer and use it in GitHub Desktop.
Get all available GLBs, then make a csv to categorized them
import csv
import os
import glob
# Define the CSV file path
characterGLBFolder = "C:/Users/BondhanKimbalazani/Documents/ModularCharacter/GLB_Test"
targetFile = "C:/Users/BondhanKimbalazani/Documents/ModularCharacter/ClothingTest-Sheet3.csv"
BodyArray = []
HairArray = []
LegBaseArray = []
LegsUpperArray = []
ShoesArray = []
TorsoBaseArray = []
TorsoUpperArray = []
partsDictionary = {
"partName" : ["MainBody","Hair","LegBase","LegsUpper","Shoes","TorsoBase","TorsoUpper"],
"partArray" : [BodyArray, HairArray, LegBaseArray, LegsUpperArray, ShoesArray, TorsoBaseArray, TorsoUpperArray]
}
def getGLBBasedOnPart():
glbFiles = glob.glob(os.path.join(characterGLBFolder, "*.glb"))
for glb in glbFiles:
partName = getPartNameOfCurrentGLB(glb)
if partName in partsDictionary["partName"]:
partNameIndex = partsDictionary["partName"].index(partName)
relatedPartArray = partsDictionary["partArray"][partNameIndex]
relatedPartArray.append(glb)
def writePartsArrayToCSV(partArrays, partNames, targetFile):
maxLength = max(len(arr) for arr in partArrays)
# Pad the arrays with None if they are shorter than maxLength
paddedArrays = [[item or None for item in arr] + [None] * (maxLength - len(arr)) for arr in partArrays]
with open(targetFile, 'w', newline='') as file:
writer = csv.writer(file)
writer.writerow(partNames)
writer.writerows(zip(*paddedArrays))
def getPartNameOfCurrentGLB(glb):
fileName = os.path.basename(glb)
partName = fileName.split("_")[1]
return partName
getGLBBasedOnPart()
writePartsArrayToCSV(partsDictionary["partArray"], partsDictionary["partName"], targetFile)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment