Skip to content

Commit

Permalink
Added "Export Space" for collection exporters
Browse files Browse the repository at this point in the history
This allows the instance offset to be negated.
  • Loading branch information
cmbasnett committed Sep 20, 2024
1 parent 57a4cb5 commit a2a4720
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions io_scene_ase/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def build_ase(context: Context, options: ASEBuildOptions, objects: Iterable[Obje
for object_index, (obj, asset_instance) in enumerate(mesh_objects):

matrix_world = get_object_matrix(obj, asset_instance)
matrix_world = options.transform @ matrix_world

# Save the active color name for vertex color export.
active_color_name = obj.data.color_attributes.active_color_name
Expand Down
17 changes: 13 additions & 4 deletions io_scene_ase/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,8 @@ def execute(self, context):
# Calculate some statistics about the ASE file to display in the console.
object_count = len(ase.geometry_objects)
material_count = len(ase.materials)
vertex_count = sum(len(x.vertices) for x in ase.geometry_objects)
face_count = sum(len(x.faces) for x in ase.geometry_objects)
vertex_count = sum(len(x.vertices) for x in ase.geometry_objects)

ASEWriter().write(self.filepath, ase)
self.report({'INFO'}, f'ASE exported successfully ({object_count} objects, {material_count} materials, {face_count} faces, {vertex_count} vertices)')
Expand Down Expand Up @@ -370,12 +370,15 @@ class ASE_OT_export_collection(Operator, ExportHelper):
collection: StringProperty()
material_order: CollectionProperty(name='Materials', type=ASE_PG_string)
material_order_index: IntProperty(name='Index', default=0)

export_space: EnumProperty(name='Export Space', items=(
('WORLD', 'World Space', 'Export the collection in world-space (i.e., as it appears in the 3D view)'),
('INSTANCE', 'Instance Space', 'Export the collection as an instance (transforms the world-space geometry by the inverse of the instance offset)'),
), default='INSTANCE')

def draw(self, context):
layout = self.layout

materials_header, materials_panel = layout.panel('Materials', default_closed=False)
materials_header, materials_panel = layout.panel('Materials', default_closed=True)
materials_header.label(text='Materials')

if materials_panel:
Expand All @@ -395,13 +398,19 @@ def draw(self, context):
advanced_panel.use_property_split = True
advanced_panel.use_property_decorate = False
advanced_panel.prop(self, 'object_eval_state')
advanced_panel.prop(self, 'export_space')

def execute(self, context):
collection = bpy.data.collections.get(self.collection)

options = ASEBuildOptions()
options.object_eval_state = self.object_eval_state
options.transform = Matrix.Translation(-Vector(collection.instance_offset))

match self.export_space:
case 'WORLD':
options.transform = Matrix.Identity(4)
case 'INSTANCE':
options.transform = Matrix.Translation(-Vector(collection.instance_offset))

# Iterate over all the objects in the collection.
mesh_objects = get_mesh_objects(collection.all_objects)
Expand Down

0 comments on commit a2a4720

Please sign in to comment.