Skip to content

Commit

Permalink
feat(referenceId): Add referenceId export
Browse files Browse the repository at this point in the history
Makes it possible to export referenced i3d files directly from Blender.

Close #190
  • Loading branch information
NMC-TBone authored Nov 24, 2023
1 parent 78105ee commit 8b260c3
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
3 changes: 3 additions & 0 deletions addon/i3dio/i3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ def add_file_image(self, path_to_file: str) -> int:
def add_file_shader(self, path_to_file: str) -> int:
return self.add_file(Shader, path_to_file)

def add_file_reference(self, path_to_file: str) -> int:
return self.add_file(Reference, path_to_file)

def get_setting(self, setting: str):
return self.settings[setting]

Expand Down
6 changes: 5 additions & 1 deletion addon/i3dio/node_classes/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,8 @@ class Image(File):


class Shader(File):
MODHUB_FOLDER = 'shaders'
MODHUB_FOLDER = 'shaders'


class Reference(File):
MODHUB_FOLDER = 'assets'
8 changes: 8 additions & 0 deletions addon/i3dio/node_classes/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,13 @@ def _write_user_attributes(self):
except AttributeError:
pass

def _add_reference_file(self):
if self.blender_object.i3d_reference_path == "" or not self.blender_object.i3d_reference_path.endswith('.i3d'):
return
self.logger.debug(f"Adding reference file")
file_id = self.i3d.add_file_reference(self.blender_object.i3d_reference_path)
self._write_attribute('referenceId', file_id)

@property
@abstractmethod
def _transform_for_conversion(self) -> Union[mathutils.Matrix, None]:
Expand Down Expand Up @@ -206,6 +213,7 @@ def populate_xml_element(self):
self._write_properties()
self._write_user_attributes()
self._add_transform_to_xml_element(self._transform_for_conversion)
self._add_reference_file()

def add_child(self, node: SceneGraphNode):
self.children.append(node)
Expand Down
26 changes: 26 additions & 0 deletions addon/i3dio/ui/object.py
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,25 @@ def draw(self, context):
obj.i3d_attributes.property_unset(prop[0])


@register
class I3D_IO_PT_reference_file(Panel):
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_label = 'Reference File'
bl_context = 'object'
bl_parent_id = 'I3D_IO_PT_object_attributes'

@classmethod
def poll(cls, context):
return context.object is not None and context.object.type == 'EMPTY'

def draw(self, context):
layout = self.layout
layout.use_property_split = True
layout.use_property_decorate = False
layout.prop(context.object, 'i3d_reference_path')


@register
class I3DMappingData(bpy.types.PropertyGroup):
is_mapped: BoolProperty(
Expand Down Expand Up @@ -852,18 +871,25 @@ def draw(self, context):
row = layout.row()
row.prop(obj.i3d_mapping, 'mapping_name')


def register():
for cls in classes:
bpy.utils.register_class(cls)
bpy.types.Object.i3d_attributes = PointerProperty(type=I3DNodeObjectAttributes)
bpy.types.Object.i3d_merge_group_index = IntProperty(default = -1)
bpy.types.Object.i3d_mapping = PointerProperty(type=I3DMappingData)
bpy.types.Object.i3d_reference_path = StringProperty(
name="Reference Path",
description="Put the path to the .i3d file you want to reference here",
default='',
subtype='FILE_PATH')
bpy.types.Scene.i3dio_merge_groups = CollectionProperty(type=I3DMergeGroup)
load_post.append(handle_old_merge_groups)

def unregister():
load_post.remove(handle_old_merge_groups)
del bpy.types.Scene.i3dio_merge_groups
del bpy.types.Object.i3d_reference_path
del bpy.types.Object.i3d_mapping
del bpy.types.Object.i3d_merge_group_index
del bpy.types.Object.i3d_attributes
Expand Down

0 comments on commit 8b260c3

Please sign in to comment.