Newer
Older
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
colf= vcol.data[fi]
if len(face) > 2:
colf.color1= face[0]
colf.color2= face[1]
colf.color3= face[2]
if len(face) == 4:
colf.color4= face[3]
# Create the UV Maps.
if len(layer_data.uvmaps) > 0:
print("Adding "+str(len(layer_data.uvmaps))+" UV Textures")
for uvmap_key in layer_data.uvmaps:
map_pack= create_mappack(layer_data, uvmap_key, "UV")
uvm= me.uv_textures.new(uvmap_key)
if not uvm:
break
for fi in map_pack:
if fi > len(uvm.data):
continue
face= map_pack[fi]
uvf= uvm.data[fi]
if len(face) > 2:
uvf.uv1= face[0]
uvf.uv2= face[1]
uvf.uv3= face[2]
if len(face) == 4:
uvf.uv4= face[3]
# Now add the NGons.
if len(ngons) > 0:
for ng_key in ngons:
face_offset= len(me.faces)
ng= ngons[ng_key]
v_locs= []
for vi in range(len(ng)):
v_locs.append(mathutils.Vector(layer_data.pnts[ngons[ng_key][vi]]))
tris= PolyFill([v_locs])
me.faces.add(len(tris))
for tri in tris:
face= me.faces[face_offset]
face.vertices_raw[0]= ng[tri[0]]
face.vertices_raw[1]= ng[tri[1]]
face.vertices_raw[2]= ng[tri[2]]
face.material_index= me.faces[ng_key].material_index
face.use_smooth= me.faces[ng_key].use_smooth
face_offset+= 1
me.update()
# Non-face edges won't show up until Edit Mode cycling
if has_edges:
bpy.ops.object.select_all(action='DESELECT')
ob.users_scene[0].objects.active= ob
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.object.mode_set(mode='OBJECT')
# Unfortunately we can't exlude certain faces from the subdivision.
if layer_data.has_subds and add_subd_mod:
ob.modifiers.new(name="Subsurf", type='SUBSURF')
# Should we build an armature from the embedded rig?
if len(layer_data.bones) > 0 and skel_to_arm:
bpy.ops.object.armature_add()
arm_object= bpy.context.active_object
arm_object.name= "ARM_" + layer_data.name
arm_object.data.name= arm_object.name
arm_object.location= layer_data.pivot
bpy.ops.object.mode_set(mode='EDIT')
build_armature(layer_data, arm_object.data.edit_bones)
bpy.ops.object.mode_set(mode='OBJECT')
# Clear out the dictionaries for this layer.
layer_data.bone_names.clear()
layer_data.bone_rolls.clear()
layer_data.wmaps.clear()
layer_data.colmaps.clear()
layer_data.uvmaps.clear()
layer_data.morphs.clear()
layer_data.surf_tags.clear()
# With the objects made, setup the parents and re-adjust the locations.
for ob_key in ob_dict:
if ob_dict[ob_key][1] != -1 and ob_dict[ob_key][1] in ob_dict:
parent_ob = ob_dict[ob_dict[ob_key][1]]
ob_dict[ob_key][0].parent= parent_ob[0]
ob_dict[ob_key][0].location-= parent_ob[0].location
bpy.context.scene.update()
print("Done Importing LWO File")
from bpy.props import *
class IMPORT_OT_lwo(bpy.types.Operator):
'''Import LWO Operator.'''
bl_idname= "import_scene.lwo"
bl_label= "Import LWO"
bl_description= "Import a LightWave Object file."
bl_options= {'REGISTER', 'UNDO'}
filepath= StringProperty(name="File Path", description="Filepath used for importing the LWO file", maxlen=1024, default="")
ADD_SUBD_MOD= BoolProperty(name="Apply SubD Modifier", description="Apply the Subdivision Surface modifier to layers with Subpatches", default= True)
LOAD_HIDDEN= BoolProperty(name="Load Hidden Layers", description="Load object layers that have been marked as hidden", default= False)
SKEL_TO_ARM= BoolProperty(name="Create Armature", description="Create an armature from an embedded Skelegon rig", default= True)
def execute(self, context):
load_lwo(self.properties.filepath,
context,
self.properties.ADD_SUBD_MOD,
self.properties.LOAD_HIDDEN,
self.properties.SKEL_TO_ARM)
return {'FINISHED'}
def invoke(self, context, event):
wm= context.window_manager
wm.add_fileselect(self)
return {'RUNNING_MODAL'}
def menu_func(self, context):
self.layout.operator(IMPORT_OT_lwo.bl_idname, text="LightWave Object (.lwo)")
def register():
bpy.types.INFO_MT_file_import.append(menu_func)
def unregister():
bpy.types.INFO_MT_file_import.remove(menu_func)
if __name__ == "__main__":