Asset export script updated
This commit is contained in:
@@ -3,6 +3,9 @@ import os
|
||||
import sys
|
||||
import traceback
|
||||
import json
|
||||
from mathutils import Vector
|
||||
import numpy as np
|
||||
|
||||
|
||||
TEST_SCENE_DIR = os.path.join(os.getcwd(), "assets/blender-2.80")
|
||||
EXPORTED_DIR = os.path.join(os.getcwd(), ".")
|
||||
@@ -12,6 +15,63 @@ def export_escn(out_file, config):
|
||||
import io_scene_godot
|
||||
io_scene_godot.export(out_file, config)
|
||||
|
||||
def split_export(out_dir, config):
|
||||
SOURCE_SCENE = os.path.join(os.getcwd(), "assets", "blender-2.80", "common-all.blend")
|
||||
EXPORT_DIR = os.path.join(os.getcwd(), "assets", "blender-2.80", "exports")
|
||||
SCENE_DIR = os.path.join(os.getcwd(), "assets", "blender-2.80")
|
||||
CHARACTER_DIR = out_dir
|
||||
SHAPES_PER_PART = 12
|
||||
def make_part_list(shapes):
|
||||
part_no = 0
|
||||
ret = {}
|
||||
part_shapes = []
|
||||
for k in shapes:
|
||||
if len(part_shapes) < SHAPES_PER_PART:
|
||||
part_shapes.append(k)
|
||||
else:
|
||||
fn = "common_part%d.blend" % (part_no)
|
||||
ret[fn] = part_shapes
|
||||
part_shapes = [k]
|
||||
part_no += 1
|
||||
ret["common_part%d.blend" % (part_no)] = part_shapes
|
||||
return ret
|
||||
|
||||
base_config = config
|
||||
shape_list = []
|
||||
result_data = {}
|
||||
if os.path.exists(os.path.join(CHARACTER_DIR, "data.json")):
|
||||
result_data = json.load(open(os.path.join(CHARACTER_DIR, "data.json")))
|
||||
result_data["files"] = []
|
||||
# bpy.ops.wm.open_mainfile(filepath=config["source"])
|
||||
if not os.path.exists(EXPORT_DIR):
|
||||
os.makedirs(EXPORT_DIR)
|
||||
|
||||
for shape_key_iter in bpy.data.objects["base"].data.shape_keys.key_blocks:
|
||||
if shape_key_iter.name != "Basis":
|
||||
shape_list.append(shape_key_iter.name)
|
||||
split_list = make_part_list(shape_list)
|
||||
for fn in split_list.keys():
|
||||
bpy.ops.wm.save_mainfile(filepath=os.path.join(EXPORT_DIR, fn), check_existing=False)
|
||||
for fn in split_list.keys():
|
||||
bpy.ops.wm.open_mainfile(filepath=os.path.join(EXPORT_DIR, fn))
|
||||
for ob in bpy.data.objects:
|
||||
if ob.name == "base" or ob.name.endswith("_helper"):
|
||||
for shape_key_iter in ob.data.shape_keys.key_blocks:
|
||||
if not shape_key_iter.name in split_list[fn] + ["Basis"]:
|
||||
ob.shape_key_remove(shape_key_iter)
|
||||
bpy.ops.wm.save_mainfile(filepath=os.path.join(EXPORT_DIR, fn), check_existing=False)
|
||||
out_path = os.path.join(
|
||||
CHARACTER_DIR,
|
||||
fn.replace('.blend', '.escn')
|
||||
)
|
||||
export_escn(out_path, base_config)
|
||||
result_data["files"].append(os.path.join("characters", "common", fn.replace('.blend', '.escn')))
|
||||
print("Exported to {}".format(os.path.abspath(out_path)))
|
||||
fd = open(os.path.join(CHARACTER_DIR, "data.json"), "w")
|
||||
fd.write(json.dumps(result_data, indent=4, sort_keys=True))
|
||||
fd.close()
|
||||
print("Exported to {}".format(os.path.abspath(out_path)))
|
||||
|
||||
def main():
|
||||
dir_queue = list()
|
||||
dir_queue.append('.')
|
||||
@@ -27,6 +87,7 @@ def main():
|
||||
base_config = {
|
||||
"outpath": "exports",
|
||||
"collections": [],
|
||||
"split": False,
|
||||
"use_visible_objects": True,
|
||||
"use_export_selected": False,
|
||||
"use_mesh_modifiers": True,
|
||||
@@ -83,7 +144,15 @@ def main():
|
||||
config["outpath"],
|
||||
item.replace('.blend', '.escn')
|
||||
)
|
||||
if len(config["collections"]) > 0:
|
||||
if config["split"]:
|
||||
config["source"] = item_abspath
|
||||
out_path = os.path.join(
|
||||
EXPORTED_DIR,
|
||||
dir_relpath,
|
||||
config["outpath"]
|
||||
)
|
||||
split_export(out_path, config)
|
||||
elif len(config["collections"]) > 0:
|
||||
for cur_col in config["collections"]:
|
||||
col_keep = {}
|
||||
for c in bpy.data.collections:
|
||||
|
||||
Reference in New Issue
Block a user