Skip to content

Commit

Permalink
Correct al instances of config.get() to use singleton-comparison in…
Browse files Browse the repository at this point in the history
…stead of truthiness
  • Loading branch information
sercero committed Mar 10, 2024
1 parent e57c36d commit cb5928f
Show file tree
Hide file tree
Showing 11 changed files with 113 additions and 96 deletions.
20 changes: 13 additions & 7 deletions io_ogre/mesh_preview.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,28 @@ def execute(self, context):
elif context.active_object.type == 'EMPTY': # assume group
obs = []
for e in context.selected_objects:
if e.type != 'EMPTY' and e.instance_collection: continue
if e.type != 'EMPTY' and e.instance_collection:
continue
grp = e.instance_collection
subs = []
for o in grp.objects:
if o.type=='MESH': subs.append( o )
if o.type=='MESH':
subs.append( o )
if subs:
m = merge_objects( subs, transform=e.matrix_world )
obs.append( m )
if obs:
merged = merge_objects( obs )
umaterials = dot_mesh( merged, path=path, force_name='preview' )
for o in obs: context.scene.objects.unlink(o)
for o in obs:
context.scene.objects.unlink(o)

if not self.mesh:
for ob in context.selected_objects:
if ob.type == 'MESH':
for mat in ob.data.materials:
if mat and mat not in umaterials: umaterials.append( mat )
if mat and mat not in umaterials:
umaterials.append( mat )

if not merged:
mgroup = False # TODO relevant? MeshMagick.get_merge_group( context.active_object )
Expand All @@ -82,23 +86,25 @@ def execute(self, context):
for ob in mgroup.objects:
nmats = dot_mesh( ob, path=path )
for m in nmats:
if m not in umaterials: umaterials.append( m )
if m not in umaterials:
umaterials.append( m )
MeshMagick.merge( mgroup, path=path, force_name='preview' )
else:
dot_mesh( merged or context.active_object, path=path, force_name='preview', overwrite=True )

mats = objects_merge_materials([merged or context.active_object])
dot_materials(mats, path, False, "preview")

if merged: context.scene.objects.unlink( merged )
if merged:
context.scene.objects.unlink( merged )

try:
os.environ["OGRE_MIN_LOGLEVEL"] = "3" # only warnings and up
if sys.platform.startswith('linux') or sys.platform.startswith('darwin') or sys.platform.startswith('freebsd'):
subprocess.Popen([config.get('MESH_PREVIEWER'), path + '/preview.mesh'])
else:
subprocess.Popen([config.get('MESH_PREVIEWER'), 'C:\\tmp\\preview.mesh'] )
except:
except e:
Report.errors.append('Viewer not found at "%s"' % config.get('MESH_PREVIEWER'))

Report.show()
Expand Down
2 changes: 1 addition & 1 deletion io_ogre/ogre/material.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def generate_pass( self, mat, pass_name="" ):
self.w.iword('cull_hardware none').nl()
self.w.iword('depth_write off').nl()

if config.get('USE_FFP_PARAMETERS'):
if config.get('USE_FFP_PARAMETERS') is True:
# arbitrary bad translation from PBR to Blinn Phong
# derive proportions from metallic
bf = 1.0 - mat_wrapper.metallic
Expand Down
22 changes: 11 additions & 11 deletions io_ogre/ogre/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ def dot_mesh(ob, path, force_name=None, ignore_shape_animation=False, normals=Tr
# Don't export hidden or unselected objects unless told to
if not isLOD and (
(config.get('LOD_GENERATION') == '2' and "_LOD_" in ob.name) or
(not config.get("EXPORT_HIDDEN") and ob not in bpy.context.visible_objects) or
(config.get("SELECTED_ONLY") and not ob.select_get())
((config.get("EXPORT_HIDDEN") is False) and ob not in bpy.context.visible_objects) or
((config.get("SELECTED_ONLY") is True) and not ob.select_get())
):
logger.debug("Skip exporting hidden/non-selected object: %s" % ob.data.name)
return []
Expand All @@ -108,13 +108,13 @@ def dot_mesh(ob, path, force_name=None, ignore_shape_animation=False, normals=Tr
# If we try to remove the unwanted modifiers from the copy object, then none of the modifiers will be applied when doing `to_mesh()`

# If we want to optimise array modifiers as instances, then the Array Modifier should be disabled
if config.get("ARRAY") == True:
if config.get("ARRAY") is True:
disable_mods = ['ARMATURE', 'ARRAY']
else:
disable_mods = ['ARMATURE']

for mod in ob.modifiers:
if mod.type in disable_mods and mod.show_viewport == True:
if mod.type in disable_mods and mod.show_viewport is True:
logger.debug("Disabling Modifier: %s" % mod.name)
mod.show_viewport = False

Expand Down Expand Up @@ -622,7 +622,7 @@ def duplicate_object(scene, name, copyobj):
arm = ob.find_armature()
if arm:
skeleton_name = obj_name
if config.get('SHARED_ARMATURE') == True:
if config.get('SHARED_ARMATURE') is True:
skeleton_name = arm.data.name
skeleton_name = util.clean_object_name(skeleton_name)

Expand All @@ -634,7 +634,7 @@ def duplicate_object(scene, name, copyobj):
boneIndexFromName = {}
for bone in arm.pose.bones:
boneOutputEnableFromName[ bone.name ] = True
if config.get('ONLY_DEFORMABLE_BONES'):
if config.get('ONLY_DEFORMABLE_BONES') is True:
# if we found a deformable bone,
if bone.bone.use_deform:
# visit all ancestor bones and mark them "output enabled"
Expand Down Expand Up @@ -676,7 +676,7 @@ def duplicate_object(scene, name, copyobj):
doc.end_tag('boneassignments')

# Updated June3 2011 - shape animation works
if config.get('SHAPE_ANIMATIONS') and mesh.shape_keys and len(mesh.shape_keys.key_blocks) > 0:
if (config.get('SHAPE_ANIMATIONS') is True) and mesh.shape_keys and len(mesh.shape_keys.key_blocks) > 0:
logger.info('* Writing shape keys')

doc.start_tag('poses', {})
Expand Down Expand Up @@ -719,7 +719,7 @@ def duplicate_object(scene, name, copyobj):
pv = skey.data[ v.index ]
x,y,z = swap( pv.co - v.co )

if config.get('SHAPE_NORMALS'):
if config.get('SHAPE_NORMALS') is True:
vertex_idx = v.index

# Try to get original polygon loop index (before tesselation)
Expand All @@ -735,7 +735,7 @@ def duplicate_object(scene, name, copyobj):
pn = mathutils.Vector( snormals[normal_idx] )
nx,ny,nz = swap( pn )

if config.get('SHAPE_NORMALS'):
if config.get('SHAPE_NORMALS') is True:
doc.leaf_tag('poseoffset', {
'x' : '%6f' % x,
'y' : '%6f' % y,
Expand Down Expand Up @@ -844,10 +844,10 @@ def replaceInplace(f,searchExp,replaceExp):

# If requested by the user, generate LOD levels / Edge Lists / Vertex buffer optimization through OgreMeshUpgrader
if ((config.get('LOD_LEVELS') > 0 and config.get('LOD_GENERATION') == '0') or
(config.get('GENERATE_EDGE_LISTS') == True)):
(config.get('GENERATE_EDGE_LISTS') is True)):
target_mesh_file = os.path.join(path, '%s.mesh' % obj_name )
util.mesh_upgrade_tool(target_mesh_file)

# Note that exporting the skeleton does not happen here anymore
# It was moved to the function dot_skeleton in its own module (skeleton.py)

Expand Down
11 changes: 6 additions & 5 deletions io_ogre/ogre/node_anim.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,11 @@ def write_animation(ob, action, frame_start, frame_end, doc, xmlnode):

_fps = float( bpy.context.scene.render.fps )

# Actually in Blender this does not make sense because there is only one possible animation per object, but lets maintain compatibility with Easy Ogre Exporter
# Actually in Blender this does not make sense because there is only one possible animation per object,
# but lets maintain compatibility with Easy Ogre Exporter
aa = doc.createElement('animations')
xmlnode.appendChild(aa)

a = doc.createElement('animation')
a.setAttribute("name", "%s" % action.name)
a.setAttribute("enable", "false")
Expand All @@ -111,17 +112,17 @@ def write_animation(ob, action, frame_start, frame_end, doc, xmlnode):
aa.appendChild(a)

frame_current = bpy.context.scene.frame_current

initial_location = mathutils.Vector((0, 0, 0))
initial_rotation = mathutils.Quaternion((1, 0, 0, 0))
initial_scale = mathutils.Vector((1, 1, 1))

frames = range(int(frame_start), int(frame_end) + 1)

# If NODE_KEYFRAMES is True, then use only the keyframes to export the animation
#if config.get('NODE_KEYFRAMES'):
#if config.get('NODE_KEYFRAMES') is True:
# frames = get_keyframes(action)

for frame in frames:

kf = doc.createElement('keyframe')
Expand Down
16 changes: 8 additions & 8 deletions io_ogre/ogre/ogre_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def xCollectVertexData(data):

sys.stdout.write("\n")

if vb.hasAttribute('normals') and config.get('IMPORT_NORMALS'):
if vb.hasAttribute('normals') and config.get('IMPORT_NORMALS') is True:
for vertex in vb.getElementsByTagName('vertex'):
for vn in vertex.childNodes:
if vn.localName == 'normal':
Expand Down Expand Up @@ -684,7 +684,7 @@ def xReadAnimation(action, tracks):
continue
time = float(keyframe.getAttribute('time'))
frame = time * fps
if config.get('ROUND_FRAMES'):
if config.get('ROUND_FRAMES') is True:
frame = round(frame)
for key in keyframe.childNodes:
if key.nodeType != 1:
Expand Down Expand Up @@ -809,7 +809,7 @@ def bCreateMesh(meshData, folder, name, filepath):
subOb.select_set(True)

# TODO: Try to merge everything into the armature object
if config.get('MERGE_SUBMESHES') == True:
if config.get('MERGE_SUBMESHES') is True:
bpy.ops.object.join()
ob = bpy.context.view_layer.objects.active
ob.name = name
Expand Down Expand Up @@ -1297,7 +1297,7 @@ def load(filepath):

# Use selected skeleton
selectedSkeleton = bpy.context.active_object \
if (config.get('USE_SELECTED_SKELETON')
if (config.get('USE_SELECTED_SKELETON') is True
and bpy.context.active_object
and bpy.context.active_object.type == 'ARMATURE') else None
if selectedSkeleton:
Expand All @@ -1320,9 +1320,9 @@ def load(filepath):
meshData['skeletonName'] = os.path.basename(skeletonFile[:-9])

# Parse animations
if config.get('IMPORT_ANIMATIONS'):
if config.get('IMPORT_ANIMATIONS') is True:
fps = xAnalyseFPS(xDocSkeletonData)
if(fps and config.get('ROUND_FRAMES')):
if(fps and (config.get('ROUND_FRAMES') is True)):
logger.info(" * Setting FPS to %s" % fps)
bpy.context.scene.render.fps = int(fps)
xCollectAnimations(meshData, xDocSkeletonData)
Expand All @@ -1335,15 +1335,15 @@ def load(filepath):
xCollectMeshData(meshData, xDocMeshData, onlyName, folder)
MaterialParser.xCollectMaterialData(meshData, onlyName, folder)

if config.get('IMPORT_SHAPEKEYS'):
if config.get('IMPORT_SHAPEKEYS') is True:
xCollectPoseData(meshData, xDocMeshData)

# After collecting is done, start creating stuff#
# Create skeleton (if any) and mesh from parsed data
bCreateMesh(meshData, folder, onlyName, pathMeshXml)
bCreateAnimations(meshData)

if config.get('IMPORT_XML_DELETE') == True:
if config.get('IMPORT_XML_DELETE') is True:
# Cleanup by deleting the XML file we created
os.unlink("%s" % pathMeshXml)
if 'skeleton' in meshData:
Expand Down
22 changes: 11 additions & 11 deletions io_ogre/ogre/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ def dot_scene(path, scene_name=None):
for ob in bpy.context.scene.objects:
if ob.subcollision:
continue
if not (config.get("EXPORT_HIDDEN") or ob in bpy.context.visible_objects):
if ((config.get("EXPORT_HIDDEN") is False) and (ob not in bpy.context.visible_objects)):
continue
if config.get("SELECTED_ONLY") and not ob.select_get():
if ob.type == 'CAMERA' and config.get("FORCE_CAMERA"):
if ob.type == 'CAMERA' and (config.get("FORCE_CAMERA") is True):
pass
elif ob.type == 'LAMP' and config.get("FORCE_LAMPS"):
elif ob.type == 'LAMP' and (config.get("FORCE_LAMPS") is True):
pass
else:
continue
Expand Down Expand Up @@ -190,7 +190,7 @@ def _flatten( _c, _f ):
meshes.append(ob)

materials = []
if config.get("MATERIALS"):
if config.get("MATERIALS") is True:
logger.info("* Processing Materials")
materials = util.objects_merge_materials(meshes)

Expand Down Expand Up @@ -223,7 +223,7 @@ def _flatten( _c, _f ):
)

# Create the .scene file
if config.get('SCENE'):
if config.get('SCENE') is True:
data = doc.toprettyxml()
try:
with open(target_scene_file, 'wb') as fd:
Expand Down Expand Up @@ -484,7 +484,7 @@ def dot_scene_node_export( ob, path, doc=None, rex=None,
o = _ogre_node_helper( doc, ob )
xmlparent.appendChild(o)

# if config.get('EXPORT_USER'):
# if config.get('EXPORT_USER') is True:
# Custom user props
if len(ob.items()) > 0:
user = doc.createElement('userData')
Expand Down Expand Up @@ -534,13 +534,13 @@ def dot_scene_node_export( ob, path, doc=None, rex=None,
elif collisionFile:
e.setAttribute('collisionFile', collisionFile )

#if config.get('EXPORT_USER'):
#if config.get('EXPORT_USER') is True:
_mesh_entity_helper( doc, ob, e )

# export mesh.xml file of this object
if config.get('MESH') and ob.data.name not in exported_meshes:
if (config.get('MESH') is True) and ob.data.name not in exported_meshes:
exists = os.path.isfile( join( path, '%s.mesh' % ob.data.name ) )
overwrite = not exists or (exists and config.get("MESH_OVERWRITE"))
overwrite = not exists or (exists and (config.get("MESH_OVERWRITE") is True))
tangents = int(config.get("GENERATE_TANGENTS"))
mesh.dot_mesh(ob, path, overwrite=overwrite, tangents=tangents)
exported_meshes.append( ob.data.name )
Expand All @@ -549,7 +549,7 @@ def dot_scene_node_export( ob, path, doc=None, rex=None,
# Deal with Array modifier
vecs = [ ob.matrix_world.to_translation() ]
for mod in ob.modifiers:
if config.get("ARRAY") == True and mod.type == 'ARRAY':
if (config.get("ARRAY") is True) and (mod.type == 'ARRAY'):
if mod.fit_type != 'FIXED_COUNT':
logger.warning("<%s> Unsupported array-modifier type: %s, only 'Fixed Count' is supported" % (ob.name, mod.fit_type))
Report.warnings.append("Object \"%s\" has unsupported array-modifier type: %s, only 'Fixed Count' is supported" % (ob.name, mod.fit_type))
Expand Down Expand Up @@ -682,7 +682,7 @@ def dot_scene_node_export( ob, path, doc=None, rex=None,
a.setAttribute('quadratic', '0.0')

# Node Animation
if config.get('NODE_ANIMATION'):
if config.get('NODE_ANIMATION') is True:
node_anim.dot_nodeanim(ob, doc, o)

for child in ob.children:
Expand Down
Loading

0 comments on commit cb5928f

Please sign in to comment.