Created
August 16, 2021 16:53
-
-
Save arpit15/743423c178f7d8af45362505b687a5b7 to your computer and use it in GitHub Desktop.
git patch for ply loader blender
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/io_mesh_ply/__init__.py b/io_mesh_ply/__init__.py | |
index a3f08ebd..10cdd3ba 100644 | |
--- a/io_mesh_ply/__init__.py | |
+++ b/io_mesh_ply/__init__.py | |
@@ -55,7 +55,7 @@ from bpy_extras.io_utils import ( | |
orientation_helper, | |
) | |
- | |
+@orientation_helper(axis_forward='Y', axis_up='Z') | |
class ImportPLY(bpy.types.Operator, ImportHelper): | |
"""Load a PLY geometry file""" | |
bl_idname = "import_mesh.ply" | |
@@ -68,17 +68,16 @@ class ImportPLY(bpy.types.Operator, ImportHelper): | |
type=bpy.types.OperatorFileListElement, | |
) | |
- # Hide opertator properties, rest of this is managed in C. See WM_operator_properties_filesel(). | |
- hide_props_region: BoolProperty( | |
- name="Hide Operator Properties", | |
- description="Collapse the region displaying the operator settings", | |
- default=True, | |
- ) | |
- | |
directory: StringProperty() | |
filename_ext = ".ply" | |
filter_glob: StringProperty(default="*.ply", options={'HIDDEN'}) | |
+ global_scale: FloatProperty( | |
+ name="Scale", | |
+ min=0.01, | |
+ max=1000.0, | |
+ default=1.0, | |
+ ) | |
def execute(self, context): | |
import os | |
@@ -91,11 +90,16 @@ class ImportPLY(bpy.types.Operator, ImportHelper): | |
for name in self.files | |
] | |
+ global_matrix = axis_conversion( | |
+ from_forward=self.axis_forward, | |
+ from_up=self.axis_up, | |
+ ).to_4x4() @ Matrix.Scale(self.global_scale, 4) | |
+ | |
if not paths: | |
paths.append(self.filepath) | |
for path in paths: | |
- import_ply.load(self, context, path) | |
+ import_ply.load(self, context, path, global_matrix) | |
context.window.cursor_set('DEFAULT') | |
@@ -213,6 +217,31 @@ class PLY_PT_export_include(bpy.types.Panel): | |
layout.prop(operator, "use_selection") | |
+class PLY_PT_import_transform(bpy.types.Panel): | |
+ bl_space_type = 'FILE_BROWSER' | |
+ bl_region_type = 'TOOL_PROPS' | |
+ bl_label = "Transform" | |
+ bl_parent_id = "FILE_PT_operator" | |
+ | |
+ @classmethod | |
+ def poll(cls, context): | |
+ sfile = context.space_data | |
+ operator = sfile.active_operator | |
+ | |
+ return operator.bl_idname == "IMPORT_MESH_OT_ply" | |
+ | |
+ def draw(self, context): | |
+ layout = self.layout | |
+ layout.use_property_split = True | |
+ layout.use_property_decorate = False | |
+ | |
+ sfile = context.space_data | |
+ operator = sfile.active_operator | |
+ | |
+ layout.prop(operator, "axis_forward") | |
+ layout.prop(operator, "axis_up") | |
+ layout.prop(operator, "global_scale") | |
+ | |
class PLY_PT_export_transform(bpy.types.Panel): | |
bl_space_type = 'FILE_BROWSER' | |
bl_region_type = 'TOOL_PROPS' | |
@@ -276,6 +305,7 @@ def menu_func_export(self, context): | |
classes = ( | |
ImportPLY, | |
+ PLY_PT_import_transform, | |
ExportPLY, | |
PLY_PT_export_include, | |
PLY_PT_export_transform, | |
diff --git a/io_mesh_ply/import_ply.py b/io_mesh_ply/import_ply.py | |
index d9d12d67..bd5abade 100644 | |
--- a/io_mesh_ply/import_ply.py | |
+++ b/io_mesh_ply/import_ply.py | |
@@ -428,7 +428,7 @@ def load_ply_mesh(filepath, ply_name): | |
return mesh | |
-def load_ply(filepath): | |
+def load_ply(filepath, global_matrix=None): | |
import time | |
import bpy | |
@@ -436,6 +436,8 @@ def load_ply(filepath): | |
ply_name = bpy.path.display_name_from_filepath(filepath) | |
mesh = load_ply_mesh(filepath, ply_name) | |
+ if global_matrix is not None: | |
+ mesh.transform(global_matrix) | |
if not mesh: | |
return {'CANCELLED'} | |
@@ -452,5 +454,5 @@ def load_ply(filepath): | |
return {'FINISHED'} | |
-def load(operator, context, filepath=""): | |
- return load_ply(filepath) | |
+def load(operator, context, filepath="", global_matrix=None): | |
+ return load_ply(filepath, global_matrix) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment