mirror of
https://github.com/MapMakersAndProgrammers/io_scene_a3d.git
synced 2025-10-26 01:49:13 -07:00
Allow for importing multiple files simultaneously
This commit is contained in:
@@ -53,14 +53,13 @@ def mirrorUVY(uv):
|
||||
return (x, 1-y)
|
||||
|
||||
class A3DBlenderImporter:
|
||||
def __init__(self, modelData, directory, create_collection=True, reset_empty_transform=True, try_import_textures=True):
|
||||
def __init__(self, modelData, directory, reset_empty_transform=True, try_import_textures=True):
|
||||
self.modelData = modelData
|
||||
self.directory = directory
|
||||
self.materials = []
|
||||
self.meshes = []
|
||||
|
||||
# User settings
|
||||
self.create_collection = create_collection
|
||||
self.reset_empty_transform = reset_empty_transform
|
||||
self.try_import_textures = try_import_textures
|
||||
|
||||
@@ -78,18 +77,12 @@ class A3DBlenderImporter:
|
||||
self.meshes.append(me)
|
||||
|
||||
# Create objects
|
||||
collection = bpy.context.collection # By default use the current active collection
|
||||
if self.create_collection:
|
||||
collection = bpy.data.collections.new("Object")
|
||||
bpy.context.collection.children.link(collection)
|
||||
objects = []
|
||||
for objectData in self.modelData.objects:
|
||||
ob = self.buildBlenderObject(objectData)
|
||||
objects.append(ob)
|
||||
# Assign object parents and link to collection
|
||||
for obI, ob in enumerate(objects):
|
||||
collection.objects.link(ob)
|
||||
|
||||
# Assign parents
|
||||
parentID = self.modelData.transformParentIDs[obI]
|
||||
if parentID == 0 and self.modelData.version < 3:
|
||||
@@ -101,6 +94,8 @@ class A3DBlenderImporter:
|
||||
parentOB = objects[parentID]
|
||||
ob.parent = parentOB
|
||||
|
||||
return objects
|
||||
|
||||
'''
|
||||
Blender data builders
|
||||
'''
|
||||
|
||||
@@ -21,13 +21,15 @@ SOFTWARE.
|
||||
'''
|
||||
|
||||
import bpy
|
||||
from bpy.types import Operator
|
||||
from bpy.props import StringProperty, BoolProperty
|
||||
from bpy.types import Operator, OperatorFileListElement
|
||||
from bpy.props import StringProperty, BoolProperty, CollectionProperty
|
||||
from bpy_extras.io_utils import ImportHelper
|
||||
|
||||
from .A3D import A3D
|
||||
from .A3DBlenderImporter import A3DBlenderImporter
|
||||
|
||||
from glob import glob
|
||||
|
||||
'''
|
||||
Operators
|
||||
'''
|
||||
@@ -39,6 +41,7 @@ class ImportA3D(Operator, ImportHelper):
|
||||
|
||||
filter_glob: StringProperty(default="*.a3d", options={'HIDDEN'})
|
||||
directory: StringProperty(subtype='DIR_PATH', options={'HIDDEN'})
|
||||
files: CollectionProperty(type=OperatorFileListElement, options={"HIDDEN", "SKIP_SAVE"})
|
||||
|
||||
# User options
|
||||
create_collection: BoolProperty(name="Create collection", description="Create a collection to hold all the model objects", default=False)
|
||||
@@ -52,17 +55,26 @@ class ImportA3D(Operator, ImportHelper):
|
||||
return ImportHelper.invoke(self, context, event)
|
||||
|
||||
def execute(self, context):
|
||||
filepath = self.filepath
|
||||
objects = []
|
||||
for file in self.files:
|
||||
filepath = self.directory + file.name
|
||||
# Read the file
|
||||
print(f"Reading A3D data from {filepath}")
|
||||
modelData = A3D()
|
||||
with open(filepath, "rb") as file:
|
||||
modelData.read(file)
|
||||
|
||||
# Read the file
|
||||
print(f"Reading A3D data from {filepath}")
|
||||
modelData = A3D()
|
||||
with open(filepath, "rb") as file:
|
||||
modelData.read(file)
|
||||
# Import data into blender
|
||||
modelImporter = A3DBlenderImporter(modelData, self.directory, self.reset_empty_transform, self.try_import_textures)
|
||||
objects += modelImporter.importData()
|
||||
|
||||
# Import data into blender
|
||||
modelImporter = A3DBlenderImporter(modelData, self.directory, self.create_collection, self.reset_empty_transform, self.try_import_textures)
|
||||
modelImporter.importData()
|
||||
# Link objects to collection
|
||||
collection = bpy.context.collection
|
||||
if self.create_collection:
|
||||
collection = bpy.data.collections.new("Collection")
|
||||
bpy.context.collection.children.link(collection)
|
||||
for obI, ob in enumerate(objects):
|
||||
collection.objects.link(ob)
|
||||
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user