Skip to content
Snippets Groups Projects
Commit a6189ebc authored by Campbell Barton's avatar Campbell Barton
Browse files

PLY: cleanup style

parent caf0c86b
Branches
Tags
No related merge requests found
......@@ -29,7 +29,8 @@ bl_info = {
"wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/"
"Scripts/Import-Export/Stanford_PLY",
"support": 'OFFICIAL',
"category": "Import-Export"}
"category": "Import-Export",
}
# Copyright (C) 2004, 2005: Bruce Merry, bmerry@cs.uct.ac.za
# Contributors: Bruce Merry, Campbell Barton
......@@ -47,18 +48,18 @@ if "bpy" in locals():
import os
import bpy
from bpy.props import (
CollectionProperty,
StringProperty,
BoolProperty,
EnumProperty,
FloatProperty,
)
CollectionProperty,
StringProperty,
BoolProperty,
EnumProperty,
FloatProperty,
)
from bpy_extras.io_utils import (
ImportHelper,
ExportHelper,
axis_conversion,
orientation_helper
)
ImportHelper,
ExportHelper,
axis_conversion,
orientation_helper
)
class ImportPLY(bpy.types.Operator, ImportHelper):
......@@ -67,10 +68,13 @@ class ImportPLY(bpy.types.Operator, ImportHelper):
bl_label = "Import PLY"
bl_options = {'UNDO'}
files: CollectionProperty(name="File Path",
description="File path used for importing "
"the PLY file",
type=bpy.types.OperatorFileListElement)
files: CollectionProperty(
name="File Path",
description=(
"File path used for importing "
"the PLY file"
),
type=bpy.types.OperatorFileListElement)
directory: StringProperty()
......@@ -102,34 +106,36 @@ class ExportPLY(bpy.types.Operator, ExportHelper):
filter_glob: StringProperty(default="*.ply", options={'HIDDEN'})
use_mesh_modifiers: BoolProperty(
name="Apply Modifiers",
description="Apply Modifiers to the exported mesh",
default=True,
)
name="Apply Modifiers",
description="Apply Modifiers to the exported mesh",
default=True,
)
use_normals: BoolProperty(
name="Normals",
description="Export Normals for smooth and "
"hard shaded faces "
"(hard shaded faces will be exported "
"as individual faces)",
default=True,
)
name="Normals",
description=(
"Export Normals for smooth and "
"hard shaded faces "
"(hard shaded faces will be exported "
"as individual faces)"
),
default=True,
)
use_uv_coords: BoolProperty(
name="UVs",
description="Export the active UV layer",
default=True,
)
name="UVs",
description="Export the active UV layer",
default=True,
)
use_colors: BoolProperty(
name="Vertex Colors",
description="Export the active vertex color layer",
default=True,
)
name="Vertex Colors",
description="Export the active vertex color layer",
default=True,
)
global_scale: FloatProperty(
name="Scale",
min=0.01, max=1000.0,
default=1.0,
)
name="Scale",
min=0.01, max=1000.0,
default=1.0,
)
@classmethod
def poll(cls, context):
......@@ -140,15 +146,19 @@ class ExportPLY(bpy.types.Operator, ExportHelper):
from mathutils import Matrix
keywords = self.as_keywords(ignore=("axis_forward",
"axis_up",
"global_scale",
"check_existing",
"filter_glob",
))
global_matrix = axis_conversion(to_forward=self.axis_forward,
to_up=self.axis_up,
).to_4x4() @ Matrix.Scale(self.global_scale, 4)
keywords = self.as_keywords(
ignore=(
"axis_forward",
"axis_up",
"global_scale",
"check_existing",
"filter_glob",
)
)
global_matrix = axis_conversion(
to_forward=self.axis_forward,
to_up=self.axis_up,
).to_4x4() @ Matrix.Scale(self.global_scale, 4)
keywords["global_matrix"] = global_matrix
filepath = self.filepath
......@@ -182,7 +192,7 @@ def menu_func_export(self, context):
classes = (
ImportPLY,
ExportPLY,
)
)
def register():
......
......@@ -28,12 +28,13 @@ import bpy
import os
def save_mesh(filepath,
mesh,
use_normals=True,
use_uv_coords=True,
use_colors=True,
):
def save_mesh(
filepath,
mesh,
use_normals=True,
use_uv_coords=True,
use_colors=True,
):
def rvec3d(v):
return round(v[0], 6), round(v[1], 6), round(v[2], 6)
......@@ -112,11 +113,12 @@ def save_mesh(filepath,
if has_vcol:
color = col[j]
color = (int(color[0] * 255.0),
int(color[1] * 255.0),
int(color[2] * 255.0),
int(color[3] * 255.0),
)
color = (
int(color[0] * 255.0),
int(color[1] * 255.0),
int(color[2] * 255.0),
int(color[3] * 255.0),
)
key = normal_key, uvcoord_key, color
vdict_local = vdict[vidx]
......@@ -180,16 +182,16 @@ def save_mesh(filepath,
return {'FINISHED'}
def save(operator,
context,
filepath="",
use_mesh_modifiers=True,
use_normals=True,
use_uv_coords=True,
use_colors=True,
global_matrix=None
):
def save(
operator,
context,
filepath="",
use_mesh_modifiers=True,
use_normals=True,
use_uv_coords=True,
use_colors=True,
global_matrix=None
):
obj = context.active_object
if global_matrix is None:
......
......@@ -23,10 +23,11 @@ import struct
class element_spec(object):
__slots__ = ("name",
"count",
"properties",
)
__slots__ = (
"name",
"count",
"properties",
)
def __init__(self, name, count):
self.name = name
......@@ -46,10 +47,11 @@ class element_spec(object):
class property_spec(object):
__slots__ = ("name",
"list_type",
"numeric_type",
)
__slots__ = (
"name",
"list_type",
"numeric_type",
)
def __init__(self, name, list_type, numeric_type):
self.name = name
......@@ -128,26 +130,30 @@ def read(filepath):
format = b''
texture = b''
version = b'1.0'
format_specs = {b'binary_little_endian': '<',
b'binary_big_endian': '>',
b'ascii': b'ascii'}
type_specs = {b'char': 'b',
b'uchar': 'B',
b'int8': 'b',
b'uint8': 'B',
b'int16': 'h',
b'uint16': 'H',
b'short': 'h',
b'ushort': 'H',
b'int': 'i',
b'int32': 'i',
b'uint': 'I',
b'uint32': 'I',
b'float': 'f',
b'float32': 'f',
b'float64': 'd',
b'double': 'd',
b'string': 's'}
format_specs = {
b'binary_little_endian': '<',
b'binary_big_endian': '>',
b'ascii': b'ascii',
}
type_specs = {
b'char': 'b',
b'uchar': 'B',
b'int8': 'b',
b'uint8': 'B',
b'int16': 'h',
b'uint16': 'H',
b'short': 'h',
b'ushort': 'H',
b'int': 'i',
b'int32': 'i',
b'uint': 'I',
b'uint32': 'I',
b'float': 'f',
b'float32': 'f',
b'float64': 'd',
b'double': 'd',
b'string': 's',
}
obj_spec = object_spec()
invalid_ply = (None, None, None)
......@@ -265,11 +271,15 @@ def load_ply_mesh(filepath, ply_name):
if uvindices:
mesh_uvs.extend([(vertices[index][uvindices[0]], vertices[index][uvindices[1]]) for index in indices])
if colindices:
mesh_colors.extend([(vertices[index][colindices[0]] * colmultiply[0],
vertices[index][colindices[1]] * colmultiply[1],
vertices[index][colindices[2]] * colmultiply[2],
vertices[index][colindices[3]] * colmultiply[3],
) for index in indices])
mesh_colors.extend([
(
vertices[index][colindices[0]] * colmultiply[0],
vertices[index][colindices[1]] * colmultiply[1],
vertices[index][colindices[2]] * colmultiply[2],
vertices[index][colindices[3]] * colmultiply[3],
)
for index in indices
])
if uvindices or colindices:
# If we have Cols or UVs then we need to check the face order.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment