mirror of
https://github.com/MapMakersAndProgrammers/io_scene_a3d.git
synced 2025-10-26 01:49:13 -07:00
Import orphaned transforms
This commit is contained in:
@@ -46,6 +46,17 @@ class A3DBlenderExporter:
|
|||||||
objects = []
|
objects = []
|
||||||
for ob in self.objects:
|
for ob in self.objects:
|
||||||
me = ob.data
|
me = ob.data
|
||||||
|
if me == None:
|
||||||
|
# Create a transform for this object without the object itself
|
||||||
|
transform = A3DObjects.A3DTransform()
|
||||||
|
transform.position = ob.location
|
||||||
|
rotationW, rotationX, rotationY, rotationZ = ob.rotation_quaternion
|
||||||
|
transform.rotation = (rotationX, rotationY, rotationZ, rotationW)
|
||||||
|
transform.scale = ob.scale
|
||||||
|
transform.name = ob.name
|
||||||
|
transforms[ob.name] = transform
|
||||||
|
|
||||||
|
continue
|
||||||
|
|
||||||
# Process materials
|
# Process materials
|
||||||
for ma in me.materials:
|
for ma in me.materials:
|
||||||
@@ -128,8 +139,12 @@ class A3DBlenderExporter:
|
|||||||
uv1Vertices[i2] = uv1Data.uv[polygon.loop_start+2].vector
|
uv1Vertices[i2] = uv1Data.uv[polygon.loop_start+2].vector
|
||||||
uv1Buffer.data = uv1Vertices
|
uv1Buffer.data = uv1Vertices
|
||||||
|
|
||||||
mesh.vertexBufferCount = 3 #XXX: We only do coordinate, normal1 and uv1
|
normal2Buffer = A3DObjects.A3DVertexBuffer()
|
||||||
mesh.vertexBuffers = [coordinateBuffer, uv1Buffer, normal1Buffer]
|
normal2Buffer.bufferType = A3D_VERTEXTYPE_NORMAL2
|
||||||
|
normal2Buffer.data = normal1Buffer.data
|
||||||
|
|
||||||
|
mesh.vertexBufferCount = 4 #XXX: We only do coordinate, normal1 and uv1
|
||||||
|
mesh.vertexBuffers = [coordinateBuffer, uv1Buffer, normal1Buffer, normal2Buffer]
|
||||||
|
|
||||||
# Create submeshes
|
# Create submeshes
|
||||||
indexArrays = {} # material_index: index array
|
indexArrays = {} # material_index: index array
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ def mirrorUVY(uv):
|
|||||||
return (x, 1-y)
|
return (x, 1-y)
|
||||||
|
|
||||||
class A3DBlenderImporter:
|
class A3DBlenderImporter:
|
||||||
def __init__(self, modelData, directory, reset_empty_transform=True, try_import_textures=True):
|
def __init__(self, modelData, directory, reset_empty_transform=True, try_import_textures=True, import_unused_transforms=True):
|
||||||
self.modelData = modelData
|
self.modelData = modelData
|
||||||
self.directory = directory
|
self.directory = directory
|
||||||
self.materials = []
|
self.materials = []
|
||||||
@@ -48,6 +48,7 @@ class A3DBlenderImporter:
|
|||||||
# User settings
|
# User settings
|
||||||
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
|
||||||
|
self.import_unused_transforms = import_unused_transforms
|
||||||
|
|
||||||
def importData(self):
|
def importData(self):
|
||||||
print("Importing A3D model data into blender")
|
print("Importing A3D model data into blender")
|
||||||
@@ -79,6 +80,37 @@ class A3DBlenderImporter:
|
|||||||
continue
|
continue
|
||||||
parentOB = objects[parentID]
|
parentOB = objects[parentID]
|
||||||
ob.parent = parentOB
|
ob.parent = parentOB
|
||||||
|
if self.import_unused_transforms:
|
||||||
|
# First identify which transforms have not been used
|
||||||
|
unusedTransformIndices = list(
|
||||||
|
range(len(self.modelData.transforms))
|
||||||
|
)
|
||||||
|
print(unusedTransformIndices)
|
||||||
|
for objectData in self.modelData.objects:
|
||||||
|
unusedTransformIndices.remove(objectData.transformID)
|
||||||
|
|
||||||
|
# Create empty objects for each transform
|
||||||
|
for transformID in unusedTransformIndices:
|
||||||
|
transformData = self.modelData.transforms[transformID]
|
||||||
|
ob = bpy.data.objects.new(transformData.name, None)
|
||||||
|
ob.empty_display_size = 10
|
||||||
|
ob.location = transformData.position
|
||||||
|
ob.rotation_mode = "QUATERNION"
|
||||||
|
x, y, z, w = transformData.rotation
|
||||||
|
ob.rotation_quaternion = (w, x, y, z)
|
||||||
|
ob.scale = transformData.scale
|
||||||
|
objects.append(ob)
|
||||||
|
|
||||||
|
# Assign parent
|
||||||
|
parentID = self.modelData.transformParentIDs[transformID]
|
||||||
|
if self.modelData.version < 3:
|
||||||
|
# version 2 models use 0 to signify empty parent
|
||||||
|
parentID -= 1
|
||||||
|
if parentID == -1:
|
||||||
|
# empty parent
|
||||||
|
continue
|
||||||
|
parentOB = objects[parentID]
|
||||||
|
ob.parent = parentOB
|
||||||
|
|
||||||
return objects
|
return objects
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user