Fix wrong context error after deleting object, lgt_mat export
This commit is contained in:
parent
f734f01c21
commit
e906e9e089
@ -588,9 +588,11 @@ class ExportMyFormat(bpy.types.Operator, ExportHelper):
|
|||||||
TIMshift = 2
|
TIMshift = 2
|
||||||
# Set context area to 3d view
|
# Set context area to 3d view
|
||||||
previousAreaType = 0
|
previousAreaType = 0
|
||||||
if bpy.context.object.mode != 'OBJECT' :
|
if bpy.context.mode != 'OBJECT' :
|
||||||
previousAreaType = bpy.context.area.type
|
previousAreaType = bpy.context.area.type
|
||||||
bpy.context.area.type="VIEW_3D"
|
bpy.context.area.type="VIEW_3D"
|
||||||
|
if bpy.context.object is None:
|
||||||
|
bpy.context.scene.objects.active = bpy.context.scene.objects[first_mesh]
|
||||||
# Leave edit mode to avoid errors
|
# Leave edit mode to avoid errors
|
||||||
bpy.ops.object.mode_set(mode='OBJECT')
|
bpy.ops.object.mode_set(mode='OBJECT')
|
||||||
# restore previous area type
|
# restore previous area type
|
||||||
@ -1058,7 +1060,7 @@ class ExportMyFormat(bpy.types.Operator, ExportHelper):
|
|||||||
# LLM : Local Light Matrix
|
# LLM : Local Light Matrix
|
||||||
if len( lmpObjects ) is not None:
|
if len( lmpObjects ) is not None:
|
||||||
cnt = 0
|
cnt = 0
|
||||||
pad = 3 - len( lmpObjects ) if ( len( lmpObjects ) < 3 ) else 0
|
# ~ pad = 3 - len( lmpObjects ) if ( len( lmpObjects ) < 3 ) else 0
|
||||||
f.write( "MATRIX " + fileName + "_lgtmat = {\n")
|
f.write( "MATRIX " + fileName + "_lgtmat = {\n")
|
||||||
for light in sorted(lmpObjects):
|
for light in sorted(lmpObjects):
|
||||||
# Get rid of orphans
|
# Get rid of orphans
|
||||||
@ -1072,23 +1074,23 @@ class ExportMyFormat(bpy.types.Operator, ExportHelper):
|
|||||||
# Get lightsource's world orientation
|
# Get lightsource's world orientation
|
||||||
lightdir = bpy.data.objects[lmpObjects[light]].matrix_world * Vector( ( 0, 0, -1, 0 ) )
|
lightdir = bpy.data.objects[lmpObjects[light]].matrix_world * Vector( ( 0, 0, -1, 0 ) )
|
||||||
f.write(
|
f.write(
|
||||||
"\t" + str( int( lightdir.x * energy ) ) + "," +
|
"\t" + str( int( lightdir.x * energy ) ) + ", " +
|
||||||
"\t" + str( int( -lightdir.z * energy ) ) + "," +
|
str( int( -lightdir.z * energy ) ) + ", " +
|
||||||
"\t" + str( int( lightdir.y * energy ) )
|
str( int( lightdir.y * energy ) )
|
||||||
)
|
)
|
||||||
if cnt < 2:
|
if cnt < 2:
|
||||||
f.write(",\n")
|
f.write(",\n")
|
||||||
# If less than 3 light sources exist in blender, fill the matrix with 0s.
|
cnt += 1
|
||||||
if pad:
|
# If less than 3 light sources exist in blender, fill the matrix with 0s.
|
||||||
f.write(",\n")
|
# ~ if pad:
|
||||||
while cnt < pad:
|
while cnt < 3:
|
||||||
f.write("\t0,0,0")
|
f.write("\t0, 0, 0")
|
||||||
if cnt != pad:
|
if cnt < 2:
|
||||||
f.write(",\n")
|
f.write(",")
|
||||||
cnt += 1
|
f.write("\n")
|
||||||
else:
|
cnt += 1
|
||||||
cnt += 1
|
# ~ else:
|
||||||
f.write("\n\t};\n\n")
|
f.write("\t};\n\n")
|
||||||
level_symbols.append( "MATRIX " + fileName + "_lgtmat" )
|
level_symbols.append( "MATRIX " + fileName + "_lgtmat" )
|
||||||
# LCM : Local Color Matrix
|
# LCM : Local Color Matrix
|
||||||
f.write( "MATRIX " + fileName + "_cmat = {\n")
|
f.write( "MATRIX " + fileName + "_cmat = {\n")
|
||||||
|
Loading…
Reference in New Issue
Block a user