fix edit mode switch crash
This commit is contained in:
parent
bc13386f55
commit
f61c3e1cef
@ -101,7 +101,8 @@ def import_bm(context,filepath,externalTexture,blenderTempFolder):
|
|||||||
texture_filename = read_string(ftexture)
|
texture_filename = read_string(ftexture)
|
||||||
texture_isExternal = read_bool(ftexture)
|
texture_isExternal = read_bool(ftexture)
|
||||||
if texture_isExternal:
|
if texture_isExternal:
|
||||||
item.blenderData = txur = load_image(texture_filename, externalTextureFolder)
|
txur = load_image(texture_filename, externalTextureFolder)
|
||||||
|
item.blenderData = txur
|
||||||
else:
|
else:
|
||||||
# not external. copy temp file into blender temp. then use it.
|
# not external. copy temp file into blender temp. then use it.
|
||||||
# try copy. if fail, don't need to do more
|
# try copy. if fail, don't need to do more
|
||||||
@ -109,7 +110,8 @@ def import_bm(context,filepath,externalTexture,blenderTempFolder):
|
|||||||
shutil.copy(os.path.join(tempTextureFolder, texture_filename), os.path.join(blenderTempTextureFolder, texture_filename))
|
shutil.copy(os.path.join(tempTextureFolder, texture_filename), os.path.join(blenderTempTextureFolder, texture_filename))
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
item.blenderData = txur = load_image(texture_filename, blenderTempTextureFolder)
|
txur = load_image(texture_filename, blenderTempTextureFolder)
|
||||||
|
item.blenderData = txur
|
||||||
txur.name = item.name
|
txur.name = item.name
|
||||||
|
|
||||||
ftexture.close()
|
ftexture.close()
|
||||||
@ -129,7 +131,7 @@ def import_bm(context,filepath,externalTexture,blenderTempFolder):
|
|||||||
material_texture = read_uint32(fmaterial)
|
material_texture = read_uint32(fmaterial)
|
||||||
|
|
||||||
# create basic material
|
# create basic material
|
||||||
item.blenderData = m = bpy.data.materials.new(item.name)
|
m = bpy.data.materials.new(item.name)
|
||||||
m.use_nodes=True
|
m.use_nodes=True
|
||||||
for node in m.node_tree.nodes:
|
for node in m.node_tree.nodes:
|
||||||
m.node_tree.nodes.remove(node)
|
m.node_tree.nodes.remove(node)
|
||||||
@ -155,6 +157,8 @@ def import_bm(context,filepath,externalTexture,blenderTempFolder):
|
|||||||
m['virtools-emissive'] = material_colEmissive
|
m['virtools-emissive'] = material_colEmissive
|
||||||
m['virtools-power'] = material_specularPower
|
m['virtools-power'] = material_specularPower
|
||||||
|
|
||||||
|
item.blenderData = m
|
||||||
|
|
||||||
fmaterial.close()
|
fmaterial.close()
|
||||||
|
|
||||||
# mesh.bm
|
# mesh.bm
|
||||||
@ -225,14 +229,11 @@ def import_bm(context,filepath,externalTexture,blenderTempFolder):
|
|||||||
mesh.loops.add(len(faceList)*3) # triangle face confirm
|
mesh.loops.add(len(faceList)*3) # triangle face confirm
|
||||||
mesh.polygons.add(len(faceList))
|
mesh.polygons.add(len(faceList))
|
||||||
mesh.uv_layers.new(do_init=False)
|
mesh.uv_layers.new(do_init=False)
|
||||||
|
mesh.create_normals_split()
|
||||||
|
|
||||||
# add vertices data
|
# add vertices data
|
||||||
mesh.vertices.foreach_set("co", unpack_list(vList))
|
mesh.vertices.foreach_set("co", unpack_list(vList))
|
||||||
mesh.loops.foreach_set("vertex_index", unpack_list(flat_vertices_index(faceList)))
|
mesh.loops.foreach_set("vertex_index", unpack_list(flat_vertices_index(faceList)))
|
||||||
'''
|
|
||||||
for _index, _item in enumerate(flat_vertices_index(faceList)):
|
|
||||||
mesh.loops[_index].vertex_index = _item
|
|
||||||
'''
|
|
||||||
mesh.loops.foreach_set("normal", unpack_list(flat_vertices_normal(faceList, vnList)))
|
mesh.loops.foreach_set("normal", unpack_list(flat_vertices_normal(faceList, vnList)))
|
||||||
mesh.uv_layers[0].data.foreach_set("uv", unpack_list(flat_vertices_uv(faceList, vtList)))
|
mesh.uv_layers[0].data.foreach_set("uv", unpack_list(flat_vertices_uv(faceList, vtList)))
|
||||||
for i in range(len(faceList)):
|
for i in range(len(faceList)):
|
||||||
@ -241,6 +242,8 @@ def import_bm(context,filepath,externalTexture,blenderTempFolder):
|
|||||||
if faceList[i][9] != -1:
|
if faceList[i][9] != -1:
|
||||||
mesh.polygons[i].material_index = faceList[i][9]
|
mesh.polygons[i].material_index = faceList[i][9]
|
||||||
|
|
||||||
|
mesh.validate(clean_customdata=False)
|
||||||
|
mesh.update(calc_edges=False, calc_edges_loose=False)
|
||||||
|
|
||||||
# add into item using
|
# add into item using
|
||||||
item.blenderData = mesh
|
item.blenderData = mesh
|
||||||
|
Loading…
Reference in New Issue
Block a user