Compare commits

..

2 Commits

Author SHA1 Message Date
CakeLancelot
249af1d2d3 Ensure all objects are deleted after export + use env var for user directory 2024-01-19 14:30:17 -06:00
gsemaj
c7b4182a4b
Export terrain meshes as FBX instead of OBJ 2024-01-19 10:42:49 -08:00

View File

@ -4,9 +4,9 @@ import bpy
import bmesh
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)
outpath = r'C:\Users\gents\3D Objects\FFTerrainMeshes'
outpath = (os.path.expandvars('%userprofile%') + "/3D Objects/FFTerrainMeshes")
def uvs_from_vert(uv_layer, v):
uvs = []
@ -15,6 +15,12 @@ def uvs_from_vert(uv_layer, v):
uvs.append(uv_data.uv)
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):
dong = Asset.from_file(f, environment=env)
@ -128,13 +134,11 @@ def rip_terrain_mesh(f, outpath, clear=False):
# export
bpy.ops.object.select_all(action='SELECT')
name = terrainData['m_Name']
outfile = f"{name}.obj"
bpy.ops.export_scene.obj(filepath=os.path.join(outpath, outfile))
outfile = f"{name}.fbx"
bpy.ops.export_scene.fbx(filepath=os.path.join(outpath, outfile))
if(clear):
bpy.ops.object.mode_set(mode="OBJECT")
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete()
delete_all_objects()
dongs = os.listdir(dongpath)
for dongname in dongs:
@ -147,4 +151,4 @@ for dongname in dongs:
with open(os.path.join(dongpath, dongname, assetname), "rb") as f:
outdir = os.path.join(outpath, dongname, assetname)
os.makedirs(outdir, exist_ok=True)
rip_terrain_mesh(f, outdir)
rip_terrain_mesh(f, outdir, True)