~ubuntu-branches/ubuntu/trusty/blender/trusty

« back to all changes in this revision

Viewing changes to release/scripts/addons/io_import_scene_lwo.py

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
    "name": "Import LightWave Objects",
21
21
    "author": "Ken Nign (Ken9)",
22
22
    "version": (1, 2),
23
 
    "blender": (2, 5, 7),
 
23
    "blender": (2, 57, 0),
24
24
    "location": "File > Import > LightWave Object (.lwo)",
25
25
    "description": "Imports a LWO file including any UV, Morph and Color maps. "\
26
26
        "Can convert Skelegons to an Armature.",
27
27
    "warning": "",
28
 
    "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.5/Py/"\
 
28
    "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/"\
29
29
        "Scripts/Import-Export/LightWave_Object",
30
30
    "tracker_url": "https://projects.blender.org/tracker/index.php?"\
31
31
        "func=detail&aid=23623",
153
153
             ADD_SUBD_MOD=True,
154
154
             LOAD_HIDDEN=False,
155
155
             SKEL_TO_ARM=True):
156
 
    '''Read the LWO file, hand off to version specific function.'''
 
156
    """Read the LWO file, hand off to version specific function."""
157
157
    name, ext= os.path.splitext(os.path.basename(filename))
158
158
    file= open(filename, 'rb')
159
159
 
189
189
 
190
190
 
191
191
def read_lwo2(file, filename, layers, surfs, tags, add_subd_mod, load_hidden, skel_to_arm):
192
 
    '''Read version 2 file, LW 6+.'''
 
192
    """Read version 2 file, LW 6+."""
193
193
    handle_layer= True
194
194
    last_pols_count= 0
195
195
    just_read_bones= False
275
275
 
276
276
 
277
277
def read_lwob(file, filename, layers, surfs, tags, add_subd_mod):
278
 
    '''Read version 1 file, LW < 6.'''
 
278
    """Read version 1 file, LW < 6."""
279
279
    last_pols_count= 0
280
280
    print("Importing LWO: " + filename + "\nLWO v1 Format")
281
281
 
317
317
 
318
318
 
319
319
def read_lwostring(raw_name):
320
 
    '''Parse a zero-padded string.'''
 
320
    """Parse a zero-padded string."""
321
321
 
322
322
    i = raw_name.find(b'\0')
323
323
    name_len = i + 1
334
334
 
335
335
 
336
336
def read_vx(pointdata):
337
 
    '''Read a variable-length index.'''
 
337
    """Read a variable-length index."""
338
338
    if pointdata[0] != 255:
339
339
        index= pointdata[0]*256 + pointdata[1]
340
340
        size= 2
346
346
 
347
347
 
348
348
def read_tags(tag_bytes, object_tags):
349
 
    '''Read the object's Tags chunk.'''
 
349
    """Read the object's Tags chunk."""
350
350
    offset= 0
351
351
    chunk_len= len(tag_bytes)
352
352
 
357
357
 
358
358
 
359
359
def read_layr(layr_bytes, object_layers, load_hidden):
360
 
    '''Read the object's layer data.'''
 
360
    """Read the object's layer data."""
361
361
    new_layr= _obj_layer()
362
362
    new_layr.index, flags= struct.unpack(">HH", layr_bytes[0:4])
363
363
 
386
386
 
387
387
 
388
388
def read_layr_5(layr_bytes, object_layers):
389
 
    '''Read the object's layer data.'''
 
389
    """Read the object's layer data."""
390
390
    # XXX: Need to check what these two exactly mean for a LWOB/LWLO file.
391
391
    new_layr= _obj_layer()
392
392
    new_layr.index, flags= struct.unpack(">HH", layr_bytes[0:4])
405
405
 
406
406
 
407
407
def read_pnts(pnt_bytes, object_layers):
408
 
    '''Read the layer's points.'''
 
408
    """Read the layer's points."""
409
409
    print("\tReading Layer ("+object_layers[-1].name+") Points")
410
410
    offset= 0
411
411
    chunk_len= len(pnt_bytes)
422
422
 
423
423
 
424
424
def read_weightmap(weight_bytes, object_layers):
425
 
    '''Read a weight map's values.'''
 
425
    """Read a weight map's values."""
426
426
    chunk_len= len(weight_bytes)
427
427
    offset= 2
428
428
    name, name_len= read_lwostring(weight_bytes[offset:])
440
440
 
441
441
 
442
442
def read_morph(morph_bytes, object_layers, is_abs):
443
 
    '''Read an endomorph's relative or absolute displacement values.'''
 
443
    """Read an endomorph's relative or absolute displacement values."""
444
444
    chunk_len= len(morph_bytes)
445
445
    offset= 2
446
446
    name, name_len= read_lwostring(morph_bytes[offset:])
464
464
 
465
465
 
466
466
def read_colmap(col_bytes, object_layers):
467
 
    '''Read the RGB or RGBA color map.'''
 
467
    """Read the RGB or RGBA color map."""
468
468
    chunk_len= len(col_bytes)
469
469
    dia,= struct.unpack(">H", col_bytes[0:2])
470
470
    offset= 2
497
497
 
498
498
 
499
499
def read_color_vmad(col_bytes, object_layers, last_pols_count):
500
 
    '''Read the Discontinous (per-polygon) RGB values.'''
 
500
    """Read the Discontinous (per-polygon) RGB values."""
501
501
    chunk_len= len(col_bytes)
502
502
    dia,= struct.unpack(">H", col_bytes[0:2])
503
503
    offset= 2
546
546
 
547
547
 
548
548
def read_uvmap(uv_bytes, object_layers):
549
 
    '''Read the simple UV coord values.'''
 
549
    """Read the simple UV coord values."""
550
550
    chunk_len= len(uv_bytes)
551
551
    offset= 2
552
552
    name, name_len= read_lwostring(uv_bytes[offset:])
570
570
 
571
571
 
572
572
def read_uv_vmad(uv_bytes, object_layers, last_pols_count):
573
 
    '''Read the Discontinous (per-polygon) uv values.'''
 
573
    """Read the Discontinous (per-polygon) uv values."""
574
574
    chunk_len= len(uv_bytes)
575
575
    offset= 2
576
576
    name, name_len= read_lwostring(uv_bytes[offset:])
602
602
 
603
603
 
604
604
def read_weight_vmad(ew_bytes, object_layers):
605
 
    '''Read the VMAD Weight values.'''
 
605
    """Read the VMAD Weight values."""
606
606
    chunk_len= len(ew_bytes)
607
607
    offset= 2
608
608
    name, name_len= read_lwostring(ew_bytes[offset:])
613
613
    # Some info: LW stores a face's points in a clock-wize order (with the
614
614
    # normal pointing at you). This gives edges a 'direction' which is used
615
615
    # when it comes to storing CC edge weight values. The weight is given
616
 
    # to the point preceeding the edge that the weight belongs to.
 
616
    # to the point preceding the edge that the weight belongs to.
617
617
    while offset < chunk_len:
618
618
        pnt_id, pnt_id_len = read_vx(ew_bytes[offset:offset+4])
619
619
        offset+= pnt_id_len
639
639
        
640
640
 
641
641
def read_pols(pol_bytes, object_layers):
642
 
    '''Read the layer's polygons, each one is just a list of point indexes.'''
 
642
    """Read the layer's polygons, each one is just a list of point indexes."""
643
643
    print("\tReading Layer ("+object_layers[-1].name+") Polygons")
644
644
    offset= 0
645
645
    pols_count = len(pol_bytes)
660
660
 
661
661
 
662
662
def read_pols_5(pol_bytes, object_layers):
663
 
    '''
 
663
    """
664
664
    Read the polygons, each one is just a list of point indexes.
665
665
    But it also includes the surface index.
666
 
    '''
 
666
    """
667
667
    print("\tReading Layer ("+object_layers[-1].name+") Polygons")
668
668
    offset= 0
669
669
    chunk_len= len(pol_bytes)
692
692
 
693
693
 
694
694
def read_bones(bone_bytes, object_layers):
695
 
    '''Read the layer's skelegons.'''
 
695
    """Read the layer's skelegons."""
696
696
    print("\tReading Layer ("+object_layers[-1].name+") Bones")
697
697
    offset= 0
698
698
    bones_count = len(bone_bytes)
710
710
 
711
711
 
712
712
def read_bone_tags(tag_bytes, object_layers, object_tags, type):
713
 
    '''Read the bone name or roll tags.'''
 
713
    """Read the bone name or roll tags."""
714
714
    offset= 0
715
715
    chunk_len= len(tag_bytes)
716
716
 
730
730
 
731
731
 
732
732
def read_surf_tags(tag_bytes, object_layers, last_pols_count):
733
 
    '''Read the list of PolyIDs and tag indexes.'''
 
733
    """Read the list of PolyIDs and tag indexes."""
734
734
    print("\tReading Layer ("+object_layers[-1].name+") Surface Assignments")
735
735
    offset= 0
736
736
    chunk_len= len(tag_bytes)
748
748
 
749
749
 
750
750
def read_surf(surf_bytes, object_surfs):
751
 
    '''Read the object's surface data.'''
 
751
    """Read the object's surface data."""
752
752
    if len(object_surfs) == 0:
753
753
        print("Reading Object Surfaces")
754
754
 
816
816
 
817
817
 
818
818
def read_surf_5(surf_bytes, object_surfs):
819
 
    '''Read the object's surface data.'''
 
819
    """Read the object's surface data."""
820
820
    if len(object_surfs) == 0:
821
821
        print("Reading Object Surfaces")
822
822
 
875
875
 
876
876
 
877
877
def create_mappack(data, map_name, map_type):
878
 
    '''Match the map data to faces.'''
 
878
    """Match the map data to faces."""
879
879
    pack= {}
880
880
 
881
881
    def color_pointmap(map):
943
943
 
944
944
 
945
945
def build_armature(layer_data, bones):
946
 
    '''Build an armature from the skelegon data in the mesh.'''
 
946
    """Build an armature from the skelegon data in the mesh."""
947
947
    print("Building Armature")
948
948
 
949
949
    # New Armatures include a default bone, remove it.
980
980
 
981
981
 
982
982
def build_objects(object_layers, object_surfs, object_tags, object_name, add_subd_mod, skel_to_arm):
983
 
    '''Using the gathered data, create the objects.'''
 
983
    """Using the gathered data, create the objects."""
984
984
    ob_dict= {}  # Used for the parenting setup.
985
985
    print("Adding %d Materials" % len(object_surfs))
986
986
 
1088
1088
            print("Adding %d Vertex Color Maps" % len(layer_data.colmaps))
1089
1089
            for cmap_key in layer_data.colmaps:
1090
1090
                map_pack= create_mappack(layer_data, cmap_key, "COLOR")
1091
 
                vcol= me.vertex_colors.new(cmap_key)
1092
 
                if not vcol:
 
1091
                me.vertex_colors.new(cmap_key)
 
1092
                vcol= me.tessface_vertex_colors[-1]
 
1093
                if not vcol or not vcol.data:
1093
1094
                    break
1094
1095
                for fi in map_pack:
1095
1096
                    if fi > len(vcol.data):
1109
1110
            print("Adding %d UV Textures" % len(layer_data.uvmaps))
1110
1111
            for uvmap_key in layer_data.uvmaps:
1111
1112
                map_pack= create_mappack(layer_data, uvmap_key, "UV")
1112
 
                uvm= me.uv_textures.new(name=uvmap_key)
1113
 
                uvloop = me.uv_layers[-1]
1114
 
                uvm = uvloop.data
1115
 
                if not uvm:
 
1113
                me.uv_textures.new(name=uvmap_key)
 
1114
                uvm= me.tessface_uv_textures[-1]
 
1115
                if not uvm or not uvm.data:
1116
1116
                    break
1117
1117
                for fi in map_pack:
1118
1118
                    if fi > len(uvm.data):
1142
1142
                    face.vertices_raw[0]= ng[tri[0]]
1143
1143
                    face.vertices_raw[1]= ng[tri[1]]
1144
1144
                    face.vertices_raw[2]= ng[tri[2]]
1145
 
                    face.material_index= me.faces[ng_key].material_index
1146
 
                    face.use_smooth= me.faces[ng_key].use_smooth
 
1145
                    face.material_index= me.tessfaces[ng_key].material_index
 
1146
                    face.use_smooth= me.tessfaces[ng_key].use_smooth
1147
1147
                    face_offset+= 1
1148
1148
 
1149
1149
        # FaceIDs are no longer a concern, so now update the mesh.
1214
1214
 
1215
1215
 
1216
1216
class IMPORT_OT_lwo(bpy.types.Operator):
1217
 
    '''Import LWO Operator.'''
 
1217
    """Import LWO Operator"""
1218
1218
    bl_idname= "import_scene.lwo"
1219
1219
    bl_label= "Import LWO"
1220
1220
    bl_description= "Import a LightWave Object file"