[Bf-extensions-cvs] [a9b6ac93] blender2.8: PLY Import: add back some code from recent 2.8 update
Campbell Barton
noreply at git.blender.org
Wed Oct 3 01:02:07 CEST 2018
Commit: a9b6ac9390bbbc46fda2590e14c698d326e1cc10
Author: Campbell Barton
Date: Wed Oct 3 08:59:10 2018 +1000
Branches: blender2.8
https://developer.blender.org/rBAa9b6ac9390bbbc46fda2590e14c698d326e1cc10
PLY Import: add back some code from recent 2.8 update
'TextureFile' while not officially part of the spec is often used,
so it's nice to add it back later.
===================================================================
M io_mesh_ply/import_ply.py
===================================================================
diff --git a/io_mesh_ply/import_ply.py b/io_mesh_ply/import_ply.py
index b2db42ef..a106f6e4 100644
--- a/io_mesh_ply/import_ply.py
+++ b/io_mesh_ply/import_ply.py
@@ -126,6 +126,7 @@ class object_spec(object):
def read(filepath):
format = b''
+ texture = b''
version = b'1.0'
format_specs = {b'binary_little_endian': '<',
b'binary_big_endian': '>',
@@ -167,7 +168,15 @@ def read(filepath):
valid_header = True
break
elif tokens[0] == b'comment':
+ if len(tokens) < 2:
+ continue
+ elif tokens[1] == b'TextureFile':
+ if len(tokens) < 4:
+ print('Invalid texture line')
+ else:
+ texture = tokens[2]
continue
+
elif tokens[0] == b'obj_info':
continue
elif tokens[0] == b'format':
@@ -206,7 +215,7 @@ def read(filepath):
obj = obj_spec.load(format_specs[format], plyf)
- return obj_spec, obj
+ return obj_spec, obj, texture
import bpy
@@ -215,7 +224,8 @@ import bpy
def load_ply_mesh(filepath, ply_name):
from bpy_extras.io_utils import unpack_face_list
- obj_spec, obj = read(filepath)
+ obj_spec, obj, texture = read(filepath)
+ # XXX28: use texture
if obj is None:
print('Invalid file')
return
@@ -340,6 +350,36 @@ def load_ply_mesh(filepath, ply_name):
mesh.update()
mesh.validate()
+ if texture and uvindices:
+ pass
+ # XXX28: add support for using texture.
+ '''
+ import os
+ import sys
+ from bpy_extras.image_utils import load_image
+
+ encoding = sys.getfilesystemencoding()
+ encoded_texture = texture.decode(encoding=encoding)
+ name = bpy.path.display_name_from_filepath(texture)
+ image = load_image(encoded_texture, os.path.dirname(filepath), recursive=True, place_holder=True)
+
+ if image:
+ texture = bpy.data.textures.new(name=name, type='IMAGE')
+ texture.image = image
+
+ material = bpy.data.materials.new(name=name)
+ material.use_shadeless = True
+
+ mtex = material.texture_slots.add()
+ mtex.texture = texture
+ mtex.texture_coords = 'UV'
+ mtex.use_map_color_diffuse = True
+
+ mesh.materials.append(material)
+ for face in mesh.uv_textures[0].data:
+ face.image = image
+ '''
+
return mesh
More information about the Bf-extensions-cvs
mailing list