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)
|
return (x, 1-y)
|
||||||
|
|
||||||
class A3DBlenderImporter:
|
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.modelData = modelData
|
||||||
self.directory = directory
|
self.directory = directory
|
||||||
self.materials = []
|
self.materials = []
|
||||||
self.meshes = []
|
self.meshes = []
|
||||||
|
|
||||||
# User settings
|
# User settings
|
||||||
self.create_collection = create_collection
|
|
||||||
self.reset_empty_transform = reset_empty_transform
|
self.reset_empty_transform = reset_empty_transform
|
||||||
self.try_import_textures = try_import_textures
|
self.try_import_textures = try_import_textures
|
||||||
|
|
||||||
@@ -78,18 +77,12 @@ class A3DBlenderImporter:
|
|||||||
self.meshes.append(me)
|
self.meshes.append(me)
|
||||||
|
|
||||||
# Create objects
|
# 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 = []
|
objects = []
|
||||||
for objectData in self.modelData.objects:
|
for objectData in self.modelData.objects:
|
||||||
ob = self.buildBlenderObject(objectData)
|
ob = self.buildBlenderObject(objectData)
|
||||||
objects.append(ob)
|
objects.append(ob)
|
||||||
# Assign object parents and link to collection
|
# Assign object parents and link to collection
|
||||||
for obI, ob in enumerate(objects):
|
for obI, ob in enumerate(objects):
|
||||||
collection.objects.link(ob)
|
|
||||||
|
|
||||||
# Assign parents
|
# Assign parents
|
||||||
parentID = self.modelData.transformParentIDs[obI]
|
parentID = self.modelData.transformParentIDs[obI]
|
||||||
if parentID == 0 and self.modelData.version < 3:
|
if parentID == 0 and self.modelData.version < 3:
|
||||||
@@ -101,6 +94,8 @@ class A3DBlenderImporter:
|
|||||||
parentOB = objects[parentID]
|
parentOB = objects[parentID]
|
||||||
ob.parent = parentOB
|
ob.parent = parentOB
|
||||||
|
|
||||||
|
return objects
|
||||||
|
|
||||||
'''
|
'''
|
||||||
Blender data builders
|
Blender data builders
|
||||||
'''
|
'''
|
||||||
|
|||||||
@@ -21,13 +21,15 @@ SOFTWARE.
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
import bpy
|
import bpy
|
||||||
from bpy.types import Operator
|
from bpy.types import Operator, OperatorFileListElement
|
||||||
from bpy.props import StringProperty, BoolProperty
|
from bpy.props import StringProperty, BoolProperty, CollectionProperty
|
||||||
from bpy_extras.io_utils import ImportHelper
|
from bpy_extras.io_utils import ImportHelper
|
||||||
|
|
||||||
from .A3D import A3D
|
from .A3D import A3D
|
||||||
from .A3DBlenderImporter import A3DBlenderImporter
|
from .A3DBlenderImporter import A3DBlenderImporter
|
||||||
|
|
||||||
|
from glob import glob
|
||||||
|
|
||||||
'''
|
'''
|
||||||
Operators
|
Operators
|
||||||
'''
|
'''
|
||||||
@@ -39,6 +41,7 @@ class ImportA3D(Operator, ImportHelper):
|
|||||||
|
|
||||||
filter_glob: StringProperty(default="*.a3d", options={'HIDDEN'})
|
filter_glob: StringProperty(default="*.a3d", options={'HIDDEN'})
|
||||||
directory: StringProperty(subtype='DIR_PATH', options={'HIDDEN'})
|
directory: StringProperty(subtype='DIR_PATH', options={'HIDDEN'})
|
||||||
|
files: CollectionProperty(type=OperatorFileListElement, options={"HIDDEN", "SKIP_SAVE"})
|
||||||
|
|
||||||
# User options
|
# User options
|
||||||
create_collection: BoolProperty(name="Create collection", description="Create a collection to hold all the model objects", default=False)
|
create_collection: BoolProperty(name="Create collection", description="Create a collection to hold all the model objects", default=False)
|
||||||
@@ -52,8 +55,9 @@ class ImportA3D(Operator, ImportHelper):
|
|||||||
return ImportHelper.invoke(self, context, event)
|
return ImportHelper.invoke(self, context, event)
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
filepath = self.filepath
|
objects = []
|
||||||
|
for file in self.files:
|
||||||
|
filepath = self.directory + file.name
|
||||||
# Read the file
|
# Read the file
|
||||||
print(f"Reading A3D data from {filepath}")
|
print(f"Reading A3D data from {filepath}")
|
||||||
modelData = A3D()
|
modelData = A3D()
|
||||||
@@ -61,8 +65,16 @@ class ImportA3D(Operator, ImportHelper):
|
|||||||
modelData.read(file)
|
modelData.read(file)
|
||||||
|
|
||||||
# Import data into blender
|
# Import data into blender
|
||||||
modelImporter = A3DBlenderImporter(modelData, self.directory, self.create_collection, self.reset_empty_transform, self.try_import_textures)
|
modelImporter = A3DBlenderImporter(modelData, self.directory, self.reset_empty_transform, self.try_import_textures)
|
||||||
modelImporter.importData()
|
objects += 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"}
|
return {"FINISHED"}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user