Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct al instances of config.get() to use singleton-comparison #208

Merged
merged 1 commit into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 == 'LIGHT' and config.get("FORCE_LIGHTS"):
elif ob.type == 'LIGHT' and (config.get("FORCE_LIGHTS") 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
24 changes: 12 additions & 12 deletions io_ogre/ogre/skeleton.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ def dot_skeleton(obj, path, **kwargs):
"""

arm = obj.find_armature()
if arm and config.get('ARMATURE_ANIMATION'):
if arm and (config.get('ARMATURE_ANIMATION') is True):
exported_armatures = kwargs.get('exported_armatures')

name = kwargs.get('force_name') or obj.data.name
if config.get('SHARED_ARMATURE') == True:
if config.get('SHARED_ARMATURE') is True:
name = kwargs.get('force_name') or arm.data.name
name = util.clean_object_name(name)

Expand Down Expand Up @@ -101,7 +101,7 @@ def __init__(self, rbone, pbone, skeleton):

self.bone = pbone # safe to hold pointer to pose bone, not edit bone!
self.shouldOutput = True
if config.get('ONLY_DEFORMABLE_BONES') and not pbone.bone.use_deform:
if (config.get('ONLY_DEFORMABLE_BONES') is True) and not pbone.bone.use_deform:
self.shouldOutput = False

# todo: Test -> #if pbone.bone.use_inherit_scale: logger.warn('Bone <%s> is using inherit scaling, Ogre has no support for this' % self.name)
Expand Down Expand Up @@ -131,7 +131,7 @@ def update(self): # called on frame update
#else:
# self.pose_rotation = pbone.rotation_euler.to_quaternion()

if config.get('OGRE_INHERIT_SCALE'):
if config.get('OGRE_INHERIT_SCALE') is True:
# special case workaround for broken Ogre nonuniform scaling:
# Ogre can't deal with arbitrary nonuniform scaling, but it can handle certain special cases
# The special case we are trying to handle here is when a bone has a nonuniform scale and it's
Expand Down Expand Up @@ -399,11 +399,11 @@ def write_animation( self, arm, actionName, frameBegin, frameEnd, doc, parentEle
if bone.shouldOutput:
bone_tracks.append( Bone_Track(bone) )
bone.clear_pose_transform() # clear out any leftover pose transforms in case this bone isn't keyframed

# Decide keyframes to export:
# ONLY keyframes (Exported animation won't be affected by Inverse Kinematics, Drivers and modified F-Curves)
# OR export keyframe each frame over animation range (Exported animation will be affected by Inverse Kinematics, Drivers and modified F-Curves)
if config.get('ONLY_KEYFRAMES'): # Only keyframes
if config.get('ONLY_KEYFRAMES') is True: # Only keyframes
frame_range = [] # Holds a list of keyframes for export
action = bpy.data.actions[actionName] # actionName is the animation name (NLAtrack child)
# loops through all channels on the f-curve --> Code taken from: https://blender.stackexchange.com/questions/8387/how-to-get-keyframe-data-from-python
Expand Down Expand Up @@ -443,14 +443,14 @@ def write_animation( self, arm, actionName, frameBegin, frameEnd, doc, parentEle
parentElement.appendChild( anim )
tracks = doc.createElement('tracks')
anim.appendChild( tracks )

# Report and log
suffix_text = ''
if config.get('ONLY_KEYFRAMES'):
if config.get('ONLY_KEYFRAMES') is True:
suffix_text = ' - Key frames: ' + str(frame_range)
logger.info('+ %s Key frames: %s' %(actionName,str(frame_range)))
Report.armature_animations.append( '%s : %s [start frame=%s end frame=%s]%s' %(arm.name, actionName, frameBegin, frameEnd, suffix_text) )

# Write stuff to skeleton.xml file
anim.setAttribute('name', actionName) # USE the action name
anim.setAttribute('length', '%6f' %( (frameEnd - frameBegin)/ _fps ) )
Expand Down Expand Up @@ -519,9 +519,9 @@ def to_xml( self ):
Report.warnings.append('You must assign an NLA strip to armature (%s) that defines the start and end frames' % arm.name)

# Log to console
if config.get('ONLY_KEYFRAMES'):
if config.get('ONLY_KEYFRAMES') is True:
logger.info('+ Only exporting keyframes')

actions = {} # actions by name
# the only thing NLA is used for is to gather the names of the actions
# it doesn't matter if the actions are all in the same NLA track or in different tracks
Expand All @@ -543,7 +543,7 @@ def to_xml( self ):
action = actionData[0]
arm.animation_data.action = action # set as the current action
suppressedBones = []
if config.get('ONLY_KEYFRAMED_BONES'):
if config.get('ONLY_KEYFRAMED_BONES') is True:
keyframedBones = {}
for group in action.groups:
keyframedBones[ group.name ] = True
Expand Down
6 changes: 3 additions & 3 deletions io_ogre/ui/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def execute(self, context):
file_handler = None

# Add a file handler to all Logger instances
if config.get('ENABLE_LOGGING') == True:
if config.get('ENABLE_LOGGING') is True:
log_file = ("%s/blender2ogre.log" % target_path)
logger.info("* Writing log file to: %s" % log_file)

Expand All @@ -191,7 +191,7 @@ def execute(self, context):

file_handler.setFormatter(file_formatter)

if config.get('DEBUG_LOGGING') == True:
if config.get('DEBUG_LOGGING') is True:
level = logging.DEBUG
else:
level = logging.INFO
Expand Down Expand Up @@ -220,7 +220,7 @@ def execute(self, context):
Report.show()

# Flush and close all logging file handlers
if config.get('ENABLE_LOGGING') == True and file_handler != None:
if config.get('ENABLE_LOGGING') is True and file_handler is not None:
for logger_name in logging.Logger.manager.loggerDict.keys():
logging.getLogger(logger_name).handlers.clear()

Expand Down
Loading
Loading