Use default camera when none present
This commit is contained in:
parent
c03cc0a745
commit
6eff988be8
|
@ -2136,12 +2136,8 @@ class ArmoryExporter:
|
|||
self.output['lamp_datas'].append(o)
|
||||
|
||||
def export_camera(self, objectRef):
|
||||
# This function exports a single camera object
|
||||
o = {}
|
||||
o['name'] = objectRef[1]["structName"]
|
||||
|
||||
#self.WriteNodeTable(objectRef)
|
||||
|
||||
objref = objectRef[0]
|
||||
|
||||
o['near_plane'] = objref.clip_start
|
||||
|
@ -2177,6 +2173,10 @@ class ArmoryExporter:
|
|||
col = background_node.inputs[0].default_value
|
||||
strength = background_node.inputs[1].default_value
|
||||
o['clear_color'] = [col[0] * strength, col[1] * strength, col[2] * strength, col[3]]
|
||||
o['clear_color'][0] = max(min(o['clear_color'][0], 1.0), 0.0)
|
||||
o['clear_color'][1] = max(min(o['clear_color'][1], 1.0), 0.0)
|
||||
o['clear_color'][2] = max(min(o['clear_color'][2], 1.0), 0.0)
|
||||
o['clear_color'][3] = max(min(o['clear_color'][3], 1.0), 0.0)
|
||||
else:
|
||||
o['clear_color'] = [0.0, 0.0, 0.0, 1.0]
|
||||
|
||||
|
@ -2555,6 +2555,53 @@ class ArmoryExporter:
|
|||
if not self.camera_spawned:
|
||||
log.warn('No camera found in active scene layers')
|
||||
|
||||
if len(self.output['camera_datas']) == 0:
|
||||
log.warn('Creating default camera')
|
||||
o = {}
|
||||
o['name'] = 'DefaultCamera'
|
||||
o['near_plane'] = 0.1
|
||||
o['far_plane'] = 200.0
|
||||
o['fov'] = 0.85
|
||||
if ArmoryExporter.in_viewport:
|
||||
pw = self.get_viewport_panels_w()
|
||||
proj, is_persp = self.get_viewport_projection_matrix()
|
||||
if pw == 0 and is_persp:
|
||||
o['projection'] = self.write_matrix(proj)
|
||||
o['projection'][5] = 2.027726888656616 # Wrong val returned when no camera present?
|
||||
o['type'] = 'perspective'
|
||||
o['frustum_culling'] = True
|
||||
o['render_path'] = 'armory_default/armory_default'
|
||||
o['clear_color'] = [0.0, 0.0, 0.0, 1.0]
|
||||
self.output['camera_datas'].append(o)
|
||||
o = {}
|
||||
o['name'] = 'DefaultCamera'
|
||||
o['type'] = 'camera_object'
|
||||
o['data_ref'] = 'DefaultCamera'
|
||||
o['material_refs'] = []
|
||||
o['transform'] = {}
|
||||
viewport_matrix = self.get_viewport_view_matrix()
|
||||
if viewport_matrix != None:
|
||||
o['transform']['values'] = self.write_matrix(viewport_matrix.inverted())
|
||||
o['local_transform_only'] = True
|
||||
else:
|
||||
o['transform']['values'] = [1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0]
|
||||
o['traits'] = []
|
||||
# Debug console enabled, attach console overlay to each camera
|
||||
if bpy.data.worlds['Arm'].arm_play_console:
|
||||
ArmoryExporter.export_ui = True
|
||||
console_trait = {}
|
||||
console_trait['type'] = 'Script'
|
||||
console_trait['class_name'] = 'armory.trait.internal.DebugConsole'
|
||||
console_trait['parameters'] = []
|
||||
o['traits'].append(console_trait)
|
||||
navigation_trait = {}
|
||||
navigation_trait['type'] = 'Script'
|
||||
navigation_trait['class_name'] = 'armory.trait.WalkNavigation'
|
||||
navigation_trait['parameters'] = [str(arm.utils.get_ease_viewport_camera()).lower()]
|
||||
o['traits'].append(navigation_trait)
|
||||
self.output['objects'].append(o)
|
||||
self.output['camera_ref'] = 'DefaultCamera'
|
||||
|
||||
if self.restoreFrame:
|
||||
self.scene.frame_set(originalFrame, originalSubframe)
|
||||
|
||||
|
|
|
@ -248,7 +248,7 @@ def make_draw_compositor(stage, node_group, node, with_fxaa=False):
|
|||
if wrd.arm_fog:
|
||||
compositor_defs += '_CFog'
|
||||
# compo_pos = True
|
||||
if bpy.data.cameras[0].dof_distance > 0.0:
|
||||
if len(bpy.data.cameras) > 0 and bpy.data.cameras[0].dof_distance > 0.0:
|
||||
compositor_defs += '_CDOF'
|
||||
compo_depth = True
|
||||
# if compo_pos:
|
||||
|
|
|
@ -130,6 +130,8 @@ class ArmTraitListDeleteItem(bpy.types.Operator):
|
|||
@classmethod
|
||||
def poll(self, context):
|
||||
""" Enable if there's something in the list """
|
||||
if bpy.context.object == None:
|
||||
return False
|
||||
return len(bpy.context.object.arm_traitlist) > 0
|
||||
|
||||
def execute(self, context):
|
||||
|
@ -156,6 +158,8 @@ class ArmTraitListMoveItem(bpy.types.Operator):
|
|||
|
||||
@classmethod
|
||||
def poll(self, context):
|
||||
if bpy.context.object == None:
|
||||
return False
|
||||
""" Enable if there's something in the list. """
|
||||
return len(bpy.context.object.arm_traitlist) > 0
|
||||
|
||||
|
|
|
@ -46,6 +46,8 @@ class ArmTraitParamListDeleteItem(bpy.types.Operator):
|
|||
@classmethod
|
||||
def poll(self, context):
|
||||
""" Enable if there's something in the list """
|
||||
if bpy.context.object == None:
|
||||
return False
|
||||
if len(context.object.arm_traitlist) == 0:
|
||||
return False
|
||||
trait = context.object.arm_traitlist[context.object.arm_traitlist_index]
|
||||
|
@ -79,6 +81,8 @@ class ArmTraitParamListMoveItem(bpy.types.Operator):
|
|||
@classmethod
|
||||
def poll(self, context):
|
||||
""" Enable if there's something in the list. """
|
||||
if bpy.context.object == None:
|
||||
return False
|
||||
if len(context.object.arm_traitlist) == 0:
|
||||
return False
|
||||
trait = context.object.arm_traitlist[context.object.arm_traitlist_index]
|
||||
|
|
|
@ -512,9 +512,6 @@ class ArmoryPlayButton(bpy.types.Operator):
|
|||
if not arm.utils.check_saved(self):
|
||||
return {"CANCELLED"}
|
||||
|
||||
if not arm.utils.check_camera(self):
|
||||
return {"CANCELLED"}
|
||||
|
||||
if not arm.utils.check_sdkpath(self):
|
||||
return {"CANCELLED"}
|
||||
|
||||
|
@ -545,9 +542,6 @@ class ArmoryPlayInViewportButton(bpy.types.Operator):
|
|||
if not arm.utils.check_saved(self):
|
||||
return {"CANCELLED"}
|
||||
|
||||
if not arm.utils.check_camera(self):
|
||||
return {"CANCELLED"}
|
||||
|
||||
if not arm.utils.check_sdkpath(self):
|
||||
return {"CANCELLED"}
|
||||
|
||||
|
@ -598,9 +592,6 @@ class ArmoryBuildButton(bpy.types.Operator):
|
|||
if not arm.utils.check_saved(self):
|
||||
return {"CANCELLED"}
|
||||
|
||||
if not arm.utils.check_camera(self):
|
||||
return {"CANCELLED"}
|
||||
|
||||
if not arm.utils.check_sdkpath(self):
|
||||
return {"CANCELLED"}
|
||||
|
||||
|
@ -626,9 +617,6 @@ class ArmoryBuildProjectButton(bpy.types.Operator):
|
|||
if not arm.utils.check_saved(self):
|
||||
return {"CANCELLED"}
|
||||
|
||||
if not arm.utils.check_camera(self):
|
||||
return {"CANCELLED"}
|
||||
|
||||
if not arm.utils.check_sdkpath(self):
|
||||
return {"CANCELLED"}
|
||||
|
||||
|
@ -745,9 +733,6 @@ class ArmoryPublishButton(bpy.types.Operator):
|
|||
if not arm.utils.check_saved(self):
|
||||
return {"CANCELLED"}
|
||||
|
||||
if not arm.utils.check_camera(self):
|
||||
return {"CANCELLED"}
|
||||
|
||||
if not arm.utils.check_sdkpath(self):
|
||||
return {"CANCELLED"}
|
||||
|
||||
|
@ -783,9 +768,6 @@ class ArmoryRenderButton(bpy.types.Operator):
|
|||
if not arm.utils.check_saved(self):
|
||||
return {"CANCELLED"}
|
||||
|
||||
if not arm.utils.check_camera(self):
|
||||
return {"CANCELLED"}
|
||||
|
||||
if not arm.utils.check_sdkpath(self):
|
||||
return {"CANCELLED"}
|
||||
|
||||
|
|
|
@ -307,12 +307,6 @@ def check_saved(self):
|
|||
return False
|
||||
return True
|
||||
|
||||
def check_camera(self):
|
||||
if len(bpy.data.cameras) == 0:
|
||||
self.report({"ERROR"}, "No camera found in scene")
|
||||
return False
|
||||
return True
|
||||
|
||||
def check_sdkpath(self):
|
||||
s = get_sdk_path()
|
||||
for c in r'[];><&*%=+@!#^()|?^':
|
||||
|
|
|
@ -281,8 +281,8 @@ def write_indexhtml(w, h):
|
|||
""")
|
||||
|
||||
def write_compiledglsl():
|
||||
clip_start = bpy.data.cameras[0].clip_start # Same clip values for all cameras for now
|
||||
clip_end = bpy.data.cameras[0].clip_end
|
||||
clip_start = bpy.data.cameras[0].clip_start if len(bpy.data.cameras) > 0 else 0.1 # Same clip values for all cameras for now
|
||||
clip_end = bpy.data.cameras[0].clip_end if len(bpy.data.cameras) > 0 else 200.0
|
||||
wrd = bpy.data.worlds['Arm']
|
||||
shadowmap_size = wrd.arm_shadowmap_size_cache
|
||||
rpdat = arm.utils.get_rp()
|
||||
|
@ -379,7 +379,7 @@ const float compoFogAmountB = """ + str(round(wrd.arm_fog_amountb * 100) / 100)
|
|||
const vec3 compoFogColor = vec3(""" + str(round(wrd.arm_fog_color[0] * 100) / 100) + """, """ + str(round(wrd.arm_fog_color[1] * 100) / 100) + """, """ + str(round(wrd.arm_fog_color[2] * 100) / 100) + """);
|
||||
""")
|
||||
|
||||
if bpy.data.cameras[0].dof_distance > 0.0:
|
||||
if len(bpy.data.cameras) > 0 and bpy.data.cameras[0].dof_distance > 0.0:
|
||||
f.write(
|
||||
"""const float compoDOFDistance = """ + str(round(bpy.data.cameras[0].dof_distance * 100) / 100) + """;
|
||||
const float compoDOFFstop = """ + str(round(bpy.data.cameras[0].gpu_dof.fstop * 100) / 100) + """;
|
||||
|
|
Loading…
Reference in a new issue