diff --git a/tools/blenvy/gltf_auto_export/helpers/helpers_collections.py b/tools/blenvy/core/helpers_collections.py similarity index 100% rename from tools/blenvy/gltf_auto_export/helpers/helpers_collections.py rename to tools/blenvy/core/helpers_collections.py diff --git a/tools/blenvy/gltf_auto_export/helpers/generate_and_export.py b/tools/blenvy/gltf_auto_export/helpers/generate_and_export.py index d99c610..9e0c6e4 100644 --- a/tools/blenvy/gltf_auto_export/helpers/generate_and_export.py +++ b/tools/blenvy/gltf_auto_export/helpers/generate_and_export.py @@ -1,6 +1,6 @@ import bpy from ..auto_export.export_gltf import export_gltf -from .helpers_collections import (set_active_collection) +from ...core.helpers_collections import (set_active_collection) """ generates a temporary scene, fills it with data, cleans up after itself diff --git a/tools/blenvy/gltf_auto_export/modules/export_materials.py b/tools/blenvy/gltf_auto_export/modules/export_materials.py index 429b9d5..de5d5f0 100644 --- a/tools/blenvy/gltf_auto_export/modules/export_materials.py +++ b/tools/blenvy/gltf_auto_export/modules/export_materials.py @@ -2,26 +2,11 @@ import os import bpy from pathlib import Path -from ..helpers.generate_and_export import generate_and_export -from ..helpers.helpers_collections import (traverse_tree) -from ..auto_export.export_gltf import (export_gltf, generate_gltf_export_preferences) +from ...core.helpers_collections import (traverse_tree) from ...core.object_makers import make_cube - -# get materials per object, and injects the materialInfo component -def get_materials(object): - material_slots = object.material_slots - used_materials_names = [] - #materials_per_object = {} - current_project_name = Path(bpy.context.blend_data.filepath).stem - - for m in material_slots: - material = m.material - # print(" slot", m, "material", material) - used_materials_names.append(material.name) - # TODO:, also respect slots & export multiple materials if applicable ! - object['MaterialInfo'] = '(name: "'+material.name+'", source: "'+current_project_name + '")' - - return used_materials_names +from ...materials.materials_helpers import get_all_materials +from ..helpers.generate_and_export import generate_and_export +from ..auto_export.export_gltf import (generate_gltf_export_preferences) def clear_material_info(collection_names, library_scenes): for scene in library_scenes: @@ -32,21 +17,6 @@ def clear_material_info(collection_names, library_scenes): if 'MaterialInfo' in dict(object): # FIXME: hasattr does not work ???? del object["MaterialInfo"] - -def get_all_materials(collection_names, library_scenes): - #print("collecton", layerColl, "otot", layerColl.all_objects) #all_objects - used_material_names = [] - for scene in library_scenes: - root_collection = scene.collection - for cur_collection in traverse_tree(root_collection): - if cur_collection.name in collection_names: - for object in cur_collection.all_objects: - used_material_names = used_material_names + get_materials(object) - # we only want unique names - used_material_names = list(set(used_material_names)) - return used_material_names - - # creates a new object with the applied material, for the material library def make_material_object(name, location=[0,0,0], rotation=[0,0,0], scale=[1,1,1], material=None, collection=None): #original_active_object = bpy.context.active_object diff --git a/tools/blenvy/materials/__init__.py b/tools/blenvy/materials/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tools/blenvy/materials/materials_helpers.py b/tools/blenvy/materials/materials_helpers.py new file mode 100644 index 0000000..78adbb4 --- /dev/null +++ b/tools/blenvy/materials/materials_helpers.py @@ -0,0 +1,35 @@ +import os +import bpy +from pathlib import Path +from ..core.helpers_collections import (traverse_tree) + +# get materials per object, and injects the materialInfo component +def get_materials(object): + material_slots = object.material_slots + used_materials_names = [] + #materials_per_object = {} + current_project_name = Path(bpy.context.blend_data.filepath).stem + + for m in material_slots: + material = m.material + # print(" slot", m, "material", material) + used_materials_names.append(material.name) + # TODO:, also respect slots & export multiple materials if applicable ! + # TODO: do NOT modify objects like this !! do it in a different function + object['MaterialInfo'] = '(name: "'+material.name+'", source: "'+current_project_name + '")' + + return used_materials_names + + +def get_all_materials(collection_names, library_scenes): + used_material_names = [] + for scene in library_scenes: + root_collection = scene.collection + for cur_collection in traverse_tree(root_collection): + if cur_collection.name in collection_names: + for object in cur_collection.all_objects: + used_material_names = used_material_names + get_materials(object) + + # we only want unique names + used_material_names = list(set(used_material_names)) + return used_material_names \ No newline at end of file