Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
blender-addons
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
blender
blender-addons
Commits
a6189ebc
Commit
a6189ebc
authored
6 years ago
by
Campbell Barton
Browse files
Options
Downloads
Patches
Plain Diff
PLY: cleanup style
parent
caf0c86b
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
io_mesh_ply/__init__.py
+59
-49
59 additions, 49 deletions
io_mesh_ply/__init__.py
io_mesh_ply/export_ply.py
+23
-21
23 additions, 21 deletions
io_mesh_ply/export_ply.py
io_mesh_ply/import_ply.py
+43
-33
43 additions, 33 deletions
io_mesh_ply/import_ply.py
with
125 additions
and
103 deletions
io_mesh_ply/__init__.py
+
59
−
49
View file @
a6189ebc
...
...
@@ -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
():
...
...
This diff is collapsed.
Click to expand it.
io_mesh_ply/export_ply.py
+
23
−
21
View file @
a6189ebc
...
...
@@ -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_
normal
s
=
True
,
use_
uv_coord
s
=
True
,
use_co
l
ors
=
True
,
global_matrix
=
None
):
def
save
(
operator
,
context
,
filepath
=
""
,
use_
mesh_modifier
s
=
True
,
use_
normal
s
=
True
,
use_
uv_
coor
d
s
=
True
,
use_colors
=
True
,
global_matrix
=
None
):
obj
=
context
.
active_object
if
global_matrix
is
None
:
...
...
This diff is collapsed.
Click to expand it.
io_mesh_ply/import_ply.py
+
43
−
33
View file @
a6189ebc
...
...
@@ -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.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment