Ensure all objects are deleted after export + use env var for user directory

This commit is contained in:
CakeLancelot 2024-01-19 14:30:17 -06:00
parent c7b4182a4b
commit 249af1d2d3

View File

@ -4,9 +4,9 @@ import bpy
import bmesh import bmesh
import os import os
dongpath = r'C:\Users\gents\AppData\LocalLow\Unity\Web Player\Cache\Fusionfall' dongpath = (os.path.expandvars('%userprofile%') + "/AppData/LocalLow/Unity/Web Player/Cache/FusionFall")
env = UnityEnvironment(base_path=dongpath) env = UnityEnvironment(base_path=dongpath)
outpath = r'C:\Users\gents\3D Objects\FFTerrainMeshes' outpath = (os.path.expandvars('%userprofile%') + "/3D Objects/FFTerrainMeshes")
def uvs_from_vert(uv_layer, v): def uvs_from_vert(uv_layer, v):
uvs = [] uvs = []
@ -15,6 +15,12 @@ def uvs_from_vert(uv_layer, v):
uvs.append(uv_data.uv) uvs.append(uv_data.uv)
return uvs return uvs
def delete_all_objects():
for i in bpy.context.scene.objects:
i.select_set(True)
bpy.ops.object.delete()
def rip_terrain_mesh(f, outpath, clear=False): def rip_terrain_mesh(f, outpath, clear=False):
dong = Asset.from_file(f, environment=env) dong = Asset.from_file(f, environment=env)
@ -132,9 +138,7 @@ def rip_terrain_mesh(f, outpath, clear=False):
bpy.ops.export_scene.fbx(filepath=os.path.join(outpath, outfile)) bpy.ops.export_scene.fbx(filepath=os.path.join(outpath, outfile))
if(clear): if(clear):
bpy.ops.object.mode_set(mode="OBJECT") delete_all_objects()
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete()
dongs = os.listdir(dongpath) dongs = os.listdir(dongpath)
for dongname in dongs: for dongname in dongs:
@ -147,4 +151,4 @@ for dongname in dongs:
with open(os.path.join(dongpath, dongname, assetname), "rb") as f: with open(os.path.join(dongpath, dongname, assetname), "rb") as f:
outdir = os.path.join(outpath, dongname, assetname) outdir = os.path.join(outpath, dongname, assetname)
os.makedirs(outdir, exist_ok=True) os.makedirs(outdir, exist_ok=True)
rip_terrain_mesh(f, outdir) rip_terrain_mesh(f, outdir, True)