Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'release/scripts/io/import_scene_obj.py')
-rw-r--r--release/scripts/io/import_scene_obj.py57
1 files changed, 20 insertions, 37 deletions
diff --git a/release/scripts/io/import_scene_obj.py b/release/scripts/io/import_scene_obj.py
index c5bd8339a15..afe82410557 100644
--- a/release/scripts/io/import_scene_obj.py
+++ b/release/scripts/io/import_scene_obj.py
@@ -54,8 +54,8 @@ Note, This loads mesh objects and materials only, nurbs and curves are not suppo
import os
import time
import bpy
-import Mathutils
-import Geometry
+import mathutils
+from geometry import PolyFill
# from Blender import Mesh, Draw, Window, Texture, Material, sys
# # import BPyMesh
@@ -65,19 +65,6 @@ import Geometry
# try: import os
# except: os= False
-# Generic path functions
-def stripFile(path):
- '''Return directory, where the file is'''
- lastSlash= max(path.rfind('\\'), path.rfind('/'))
- if lastSlash != -1:
- path= path[:lastSlash]
- return '%s%s' % (path, os.sep)
-# return '%s%s' % (path, sys.sep)
-
-def stripPath(path):
- '''Strips the slashes from the back of a string'''
- return path.split('/')[-1].split('\\')[-1]
-
def stripExt(name): # name is a string
'''Strips the prefix off the name before writing'''
index= name.rfind('.')
@@ -127,7 +114,7 @@ def BPyMesh_ngon(from_data, indices, PREF_FIX_LOOPS= True):
if not set: # Need sets for this, otherwise do a normal fill.
PREF_FIX_LOOPS= False
- Vector= Mathutils.Vector
+ Vector= mathutils.Vector
if not indices:
return []
@@ -158,7 +145,7 @@ def BPyMesh_ngon(from_data, indices, PREF_FIX_LOOPS= True):
if verts[i][1]==verts[i-1][0]:
verts.pop(i-1)
- fill= Geometry.PolyFill([verts])
+ fill= PolyFill([verts])
else:
'''
@@ -266,7 +253,7 @@ def BPyMesh_ngon(from_data, indices, PREF_FIX_LOOPS= True):
vert_map[i+ii]= vert[2]
ii+=len(verts)
- fill= Geometry.PolyFill([ [v[0] for v in loop] for loop in loop_list ])
+ fill= PolyFill([ [v[0] for v in loop] for loop in loop_list ])
#draw_loops(loop_list)
#raise 'done loop'
# map to original indicies
@@ -316,13 +303,13 @@ def line_value(line_split):
def load_image(imagepath, dirname):
if os.path.exists(imagepath):
- return bpy.data.add_image(imagepath)
+ return bpy.data.images.load(imagepath)
variants = [os.path.join(dirname, imagepath), os.path.join(dirname, os.path.basename(imagepath))]
for path in variants:
if os.path.exists(path):
- return bpy.data.add_image(path)
+ return bpy.data.images.load(path)
else:
print(path, "doesn't exist")
@@ -360,7 +347,7 @@ def create_materials(filepath, material_libs, unique_materials, unique_material_
Create all the used materials in this obj,
assign colors and images to the materials from all referenced material libs
'''
- DIR= stripFile(filepath)
+ DIR= os.path.dirname(filepath)
#==================================================================================#
# This function sets textures defined in .mtl file #
@@ -431,7 +418,7 @@ def create_materials(filepath, material_libs, unique_materials, unique_material_
# Add an MTL with the same name as the obj if no MTLs are spesified.
- temp_mtl= stripExt(stripPath(filepath))+ '.mtl'
+ temp_mtl = os.path.splitext((os.path.basename(filepath)))[0] + '.mtl'
if os.path.exists(DIR + temp_mtl) and temp_mtl not in material_libs:
# if sys.exists(DIR + temp_mtl) and temp_mtl not in material_libs:
@@ -521,10 +508,9 @@ def split_mesh(verts_loc, faces, unique_materials, filepath, SPLIT_OB_OR_GROUP,
'''
Takes vert_loc and faces, and seperates into multiple sets of
(verts_loc, faces, unique_materials, dataname)
- This is done so objects do not overload the 16 material limit.
'''
- filename = stripExt(stripPath(filepath))
+ filename = os.path.splitext((os.path.basename(filepath)))[0]
if not SPLIT_OB_OR_GROUP and not SPLIT_MATERIALS:
# use the filename for the object name since we arnt chopping up the mesh.
@@ -610,7 +596,7 @@ def create_mesh(scn, new_objects, has_ngons, CREATE_FGONS, CREATE_EDGES, verts_l
if unique_smooth_groups:
sharp_edges= {}
- smooth_group_users= dict([ (context_smooth_group, {}) for context_smooth_group in list(unique_smooth_groups.keys()) ])
+ smooth_group_users = {context_smooth_group: {} for context_smooth_group in list(unique_smooth_groups.keys())}
context_smooth_group_old= -1
# Split fgons into tri's
@@ -705,7 +691,7 @@ def create_mesh(scn, new_objects, has_ngons, CREATE_FGONS, CREATE_EDGES, verts_l
# map the material names to an index
- material_mapping= dict([(name, i) for i, name in enumerate(unique_materials)]) # enumerate over unique_materials keys()
+ material_mapping = {name: i for i, name in enumerate(unique_materials)} # enumerate over unique_materials keys()
materials= [None] * len(unique_materials)
@@ -715,9 +701,8 @@ def create_mesh(scn, new_objects, has_ngons, CREATE_FGONS, CREATE_EDGES, verts_l
me= bpy.data.meshes.new(dataname)
# make sure the list isnt too big
- for material in materials[0:16]:
+ for material in materials:
me.add_material(material)
-# me.materials= materials[0:16] # make sure the list isnt too big.
#me.verts.extend([(0,0,0)]) # dummy vert
me.add_geometry(len(verts_loc), 0, len(faces))
@@ -772,8 +757,6 @@ def create_mesh(scn, new_objects, has_ngons, CREATE_FGONS, CREATE_EDGES, verts_l
if context_material:
if context_material_old is not context_material:
mat= material_mapping[context_material]
- if mat>15:
- mat= 15
context_material_old= context_material
blender_face.material_index= mat
@@ -1363,7 +1346,7 @@ def load_obj_ui(filepath, BATCH_LOAD= False):
'Separate objects from obj...',\
('Object', SPLIT_OBJECTS, 'Import OBJ Objects into Blender Objects'),\
('Group', SPLIT_GROUPS, 'Import OBJ Groups into Blender Objects'),\
- ('Material', SPLIT_MATERIALS, 'Import each material into a seperate mesh (Avoids > 16 per mesh error)'),\
+ ('Split Materials', SPLIT_MATERIALS, 'Import each material into a seperate mesh'),\
'Options...',\
('Keep Vert Order', KEEP_VERT_ORDER, 'Keep vert and face order, disables some other options.'),\
('Clamp Scale:', CLAMP_SIZE, 0.0, 1000.0, 'Clamp the size to this maximum (Zero to Disable)'),\
@@ -1449,7 +1432,7 @@ def load_obj_ui(filepath, BATCH_LOAD= False):
Draw.BeginAlign()
SPLIT_OBJECTS = Draw.Toggle('Object', EVENT_REDRAW, ui_x+9, ui_y+89, 55, 21, SPLIT_OBJECTS.val, 'Import OBJ Objects into Blender Objects', do_split)
SPLIT_GROUPS = Draw.Toggle('Group', EVENT_REDRAW, ui_x+64, ui_y+89, 55, 21, SPLIT_GROUPS.val, 'Import OBJ Groups into Blender Objects', do_split)
- SPLIT_MATERIALS = Draw.Toggle('Material', EVENT_REDRAW, ui_x+119, ui_y+89, 60, 21, SPLIT_MATERIALS.val, 'Import each material into a seperate mesh (Avoids > 16 per mesh error)', do_split)
+ SPLIT_MATERIALS = Draw.Toggle('Split Materials', EVENT_REDRAW, ui_x+119, ui_y+89, 60, 21, SPLIT_MATERIALS.val, 'Import each material into a seperate mesh', do_split)
Draw.EndAlign()
# Only used for user feedback
@@ -1580,14 +1563,14 @@ class IMPORT_OT_obj(bpy.types.Operator):
# to the class instance from the operator settings before calling.
- path = StringProperty(name="File Path", description="File path used for importing the OBJ file", maxlen= 1024, default= "")
+ filepath = StringProperty(name="File Path", description="Filepath used for importing the OBJ file", maxlen= 1024, default= "")
CREATE_SMOOTH_GROUPS = BoolProperty(name="Smooth Groups", description="Surround smooth groups by sharp edges", default= True)
CREATE_FGONS = BoolProperty(name="NGons as FGons", description="Import faces with more then 4 verts as fgons", default= True)
CREATE_EDGES = BoolProperty(name="Lines as Edges", description="Import lines and faces with 2 verts as edge", default= True)
SPLIT_OBJECTS = BoolProperty(name="Object", description="Import OBJ Objects into Blender Objects", default= True)
SPLIT_GROUPS = BoolProperty(name="Group", description="Import OBJ Groups into Blender Objects", default= True)
- SPLIT_MATERIALS = BoolProperty(name="Material", description="Import each material into a seperate mesh (Avoids > 16 per mesh error)", default= True)
+ SPLIT_MATERIALS = BoolProperty(name="Split Materials", description="Import each material into a seperate mesh", default= False)
# old comment: only used for user feedback
# disabled this option because in old code a handler for it disabled SPLIT* params, it's not passed to load_obj
# KEEP_VERT_ORDER = BoolProperty(name="Keep Vert Order", description="Keep vert and face order, disables split options, enable for morph targets", default= True)
@@ -1600,7 +1583,7 @@ class IMPORT_OT_obj(bpy.types.Operator):
def execute(self, context):
# print("Selected: " + context.active_object.name)
- load_obj(self.properties.path,
+ load_obj(self.properties.filepath,
context,
self.properties.CLAMP_SIZE,
self.properties.CREATE_FGONS,
@@ -1621,7 +1604,8 @@ class IMPORT_OT_obj(bpy.types.Operator):
return {'RUNNING_MODAL'}
-menu_func = lambda self, context: self.layout.operator(IMPORT_OT_obj.bl_idname, text="Wavefront (.obj)")
+def menu_func(self, context):
+ self.layout.operator(IMPORT_OT_obj.bl_idname, text="Wavefront (.obj)")
def register():
@@ -1648,4 +1632,3 @@ def unregister():
if __name__ == "__main__":
register()
-