Created
October 29, 2022 20:24
-
-
Save loonaticx/cd5bff2dfa3530f2e33ea8856dd0d580 to your computer and use it in GitHub Desktop.
Removes defined UV names in eggfiles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Use this to check for models with non-empty UVMap names (known to cause issues) | |
Usage: | |
python FixUVName.py problem.egg problem2.egg ... | |
""" | |
import os | |
import sys | |
from panda3d.core import loadPrcFileData | |
loadPrcFileData("", "notify-level-linmath error") | |
from panda3d.egg import * | |
global uvNames | |
uvNames = set() | |
global problematicUV | |
problematicUV = False | |
allFiles = [] | |
modelFiles = {} | |
sys.argv.pop(0) | |
for entry in sys.argv: | |
allFiles.append(entry) | |
resourceDir = os.getcwd() | |
def traverseEgg(egg): | |
global uvNames | |
global problematicUV | |
for child in egg.getChildren(): | |
if isinstance(child, EggGroup): | |
# print(f"found an EggGroup: {child.getName()}") | |
traverseEgg(child) | |
if isinstance(child, EggTexture): | |
# print(f"found an EggTexture: {child.getName()}") | |
uvName = child.getUvName() | |
if uvName: | |
print(f"found a uvName: {uvName} from model {egg.egg_filename} with EggTexture {child.getName()}") | |
problematicUV = True | |
uvNames.add(uvName) | |
# Clear foo from <Scalar> uv-name { foo } | |
child.clearUvName() | |
if isinstance(child, EggVertexPool): | |
# print(f"found an EggVertexPool: {child.getName()}") | |
for vpoolchild in child: # should only contain EggVertexes | |
for uvName in uvNames: | |
uv = vpoolchild.modifyUvObj(uvName) | |
if uv: | |
# print(f"found uv {uvName}") | |
# Clear foo from <UV> foo { ... } | |
uv.setName('') | |
for file in allFiles: | |
if os.path.isfile(os.path.join(resourceDir, file)): | |
if not file.endswith(".egg"): | |
continue # We only want egg files | |
modelFiles[str(file)] = str(os.path.splitext(file)[0]) | |
for model in modelFiles.items(): | |
problematicUV = False | |
egg = EggData() | |
egg.read(model[0]) | |
traverseEgg(egg) | |
print(f"Loaded model: {model[0]}") | |
if problematicUV: | |
egg.writeEgg(model[0]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment