diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-10-03 01:59:10 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-10-03 01:59:10 +0300 |
commit | a9b6ac9390bbbc46fda2590e14c698d326e1cc10 (patch) | |
tree | d1d4be1659ede15fc300fd6348dd7c2b22d11754 /io_mesh_ply/import_ply.py | |
parent | 7bc4655e7b000bfe49336257edcb3a934d01650a (diff) |
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.
Diffstat (limited to 'io_mesh_ply/import_ply.py')
-rw-r--r-- | io_mesh_ply/import_ply.py | 44 |
1 files changed, 42 insertions, 2 deletions
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 |