Skip to content

Instantly share code, notes, and snippets.

@arpit15
Created February 16, 2022 00:41
Show Gist options
  • Save arpit15/a15e4585dcfe40b7db3f67500b88a878 to your computer and use it in GitHub Desktop.
Save arpit15/a15e4585dcfe40b7db3f67500b88a878 to your computer and use it in GitHub Desktop.
Add ply plugin import option for transformation
diff --git a/io_mesh_ply/__init__.py b/io_mesh_ply/__init__.py
index a3f08ebd..a456bac6 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"
@@ -79,10 +79,17 @@ class ImportPLY(bpy.types.Operator, ImportHelper):
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
from . import import_ply
+ from mathutils import Matrix
context.window.cursor_set('WAIT')
@@ -91,11 +98,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')
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