2024-05-15 11:25:30 +00:00
|
|
|
|
|
|
|
import os
|
|
|
|
import json
|
|
|
|
import bpy
|
|
|
|
from ..core.scene_helpers import add_scene_property
|
|
|
|
|
|
|
|
def find_blueprints_not_on_disk(blueprints, folder_path, extension):
|
|
|
|
not_found_blueprints = []
|
|
|
|
for blueprint in blueprints:
|
|
|
|
gltf_output_path = os.path.join(folder_path, blueprint.name + extension)
|
|
|
|
# print("gltf_output_path", gltf_output_path)
|
|
|
|
found = os.path.exists(gltf_output_path) and os.path.isfile(gltf_output_path)
|
|
|
|
if not found:
|
|
|
|
not_found_blueprints.append(blueprint)
|
|
|
|
return not_found_blueprints
|
|
|
|
|
|
|
|
def check_if_blueprint_on_disk(scene_name, folder_path, extension):
|
|
|
|
gltf_output_path = os.path.join(folder_path, scene_name + extension)
|
|
|
|
found = os.path.exists(gltf_output_path) and os.path.isfile(gltf_output_path)
|
|
|
|
return found
|
|
|
|
|
2024-05-17 12:30:15 +00:00
|
|
|
def inject_export_path_into_internal_blueprints(internal_blueprints, blueprints_path, gltf_extension):
|
2024-05-15 11:25:30 +00:00
|
|
|
for blueprint in internal_blueprints:
|
2024-05-17 12:30:15 +00:00
|
|
|
blueprint_exported_path = os.path.join(blueprints_path, f"{blueprint.name}{gltf_extension}")
|
2024-06-25 16:27:52 +00:00
|
|
|
# print("injecting blueprint path", blueprint_exported_path, "for", blueprint.name)
|
2024-06-09 08:54:10 +00:00
|
|
|
|
2024-05-15 11:25:30 +00:00
|
|
|
blueprint.collection["export_path"] = blueprint_exported_path
|
|
|
|
|
2024-05-25 08:46:14 +00:00
|
|
|
def inject_blueprints_list_into_main_scene(scene, blueprints_data, settings):
|
|
|
|
project_root_path = getattr(settings, "project_root_path")
|
|
|
|
assets_path = getattr(settings,"assets_path")
|
|
|
|
levels_path = getattr(settings,"levels_path")
|
|
|
|
blueprints_path = getattr(settings, "blueprints_path")
|
|
|
|
export_gltf_extension = getattr(settings, "export_gltf_extension")
|
2024-05-15 11:25:30 +00:00
|
|
|
|
|
|
|
# print("injecting assets/blueprints data into scene")
|
|
|
|
assets_list_name = f"assets_list_{scene.name}_components"
|
|
|
|
assets_list_data = {}
|
|
|
|
|
|
|
|
blueprint_instance_names_for_scene = blueprints_data.blueprint_instances_per_main_scene.get(scene.name, None)
|
|
|
|
blueprint_assets_list = []
|
|
|
|
if blueprint_instance_names_for_scene:
|
|
|
|
for blueprint_name in blueprint_instance_names_for_scene:
|
|
|
|
blueprint = blueprints_data.blueprints_per_name.get(blueprint_name, None)
|
|
|
|
if blueprint is not None:
|
2024-06-25 16:27:52 +00:00
|
|
|
#print("BLUEPRINT", blueprint)
|
2024-05-15 11:25:30 +00:00
|
|
|
blueprint_exported_path = None
|
|
|
|
if blueprint.local:
|
2024-05-17 12:30:15 +00:00
|
|
|
blueprint_exported_path = os.path.join(blueprints_path, f"{blueprint.name}{export_gltf_extension}")
|
2024-05-15 11:25:30 +00:00
|
|
|
else:
|
|
|
|
# get the injected path of the external blueprints
|
|
|
|
blueprint_exported_path = blueprint.collection['Export_path'] if 'Export_path' in blueprint.collection else None
|
2024-06-25 16:27:52 +00:00
|
|
|
#print("foo", dict(blueprint.collection))
|
2024-05-15 11:25:30 +00:00
|
|
|
if blueprint_exported_path is not None:
|
|
|
|
blueprint_assets_list.append({"name": blueprint.name, "path": blueprint_exported_path, "type": "MODEL", "internal": True})
|
|
|
|
|
|
|
|
|
2024-05-16 12:09:40 +00:00
|
|
|
|
2024-05-15 11:25:30 +00:00
|
|
|
|
|
|
|
assets_list_name = f"assets_{scene.name}"
|
|
|
|
scene["assets"] = json.dumps(blueprint_assets_list)
|
|
|
|
|
2024-06-25 16:27:52 +00:00
|
|
|
#print("blueprint assets", blueprint_assets_list)
|
2024-05-15 11:25:30 +00:00
|
|
|
|
|
|
|
def remove_blueprints_list_from_main_scene(scene):
|
|
|
|
assets_list = None
|
|
|
|
assets_list_name = f"assets_list_{scene.name}_components"
|
|
|
|
|
|
|
|
for object in scene.objects:
|
|
|
|
if object.name == assets_list_name:
|
|
|
|
assets_list = object
|
|
|
|
if assets_list is not None:
|
|
|
|
bpy.data.objects.remove(assets_list, do_unlink=True)
|