Skip to content
Snippets Groups Projects
Commit bf9647e7 authored by Campbell Barton's avatar Campbell Barton
Browse files

minor name & syntax cleanup

parent 519b1a9f
No related branches found
No related tags found
No related merge requests found
...@@ -120,7 +120,6 @@ def export(file, ...@@ -120,7 +120,6 @@ def export(file,
gpu_shader_dummy_mat = bpy.data.materials.new('X3D_DYMMY_MAT') gpu_shader_dummy_mat = bpy.data.materials.new('X3D_DYMMY_MAT')
gpu_shader_cache[None] = gpu.export_shader(scene, gpu_shader_dummy_mat) gpu_shader_cache[None] = gpu.export_shader(scene, gpu_shader_dummy_mat)
########################################################## ##########################################################
# Writing nodes routines # Writing nodes routines
########################################################## ##########################################################
...@@ -155,17 +154,17 @@ def export(file, ...@@ -155,17 +154,17 @@ def export(file,
fw('%s</X3D>' % ident) fw('%s</X3D>' % ident)
return ident return ident
def writeViewpoint(ident, ob, mat, scene): def writeViewpoint(ident, obj, mat, scene):
loc, quat, scale = mat.decompose() loc, quat, scale = mat.decompose()
ident_step = ident + (' ' * (-len(ident) + \ ident_step = ident + (' ' * (-len(ident) + \
fw('%s<Viewpoint ' % ident))) fw('%s<Viewpoint ' % ident)))
fw('DEF="%s"\n' % clean_str(ob.name)) fw('DEF="%s"\n' % clean_str(obj.name))
fw(ident_step + 'description="%s"\n' % ob.name) fw(ident_step + 'description="%s"\n' % obj.name)
fw(ident_step + 'centerOfRotation="0 0 0"\n') fw(ident_step + 'centerOfRotation="0 0 0"\n')
fw(ident_step + 'position="%3.2f %3.2f %3.2f"\n' % loc[:]) fw(ident_step + 'position="%3.2f %3.2f %3.2f"\n' % loc[:])
fw(ident_step + 'orientation="%3.2f %3.2f %3.2f %3.2f"\n' % (quat.axis[:] + (quat.angle, ))) fw(ident_step + 'orientation="%3.2f %3.2f %3.2f %3.2f"\n' % (quat.axis[:] + (quat.angle, )))
fw(ident_step + 'fieldOfView="%.3g"\n' % ob.data.angle) fw(ident_step + 'fieldOfView="%.3g"\n' % obj.data.angle)
fw(ident_step + '/>\n') fw(ident_step + '/>\n')
def writeFog(ident, world): def writeFog(ident, world):
...@@ -194,8 +193,8 @@ def export(file, ...@@ -194,8 +193,8 @@ def export(file,
fw(ident_step + 'avatarSize="0.25, 1.75, 0.75"\n') fw(ident_step + 'avatarSize="0.25, 1.75, 0.75"\n')
fw(ident_step + '/>\n') fw(ident_step + '/>\n')
def writeSpotLight(ident, ob, mtx, lamp, world): def writeSpotLight(ident, obj, mtx, lamp, world):
safeName = clean_str(ob.name) safeName = clean_str(obj.name)
if world: if world:
ambi = world.ambient_color ambi = world.ambient_color
amb_intensity = ((ambi[0] + ambi[1] + ambi[2]) / 3.0) / 2.5 amb_intensity = ((ambi[0] + ambi[1] + ambi[2]) / 3.0) / 2.5
...@@ -228,8 +227,8 @@ def export(file, ...@@ -228,8 +227,8 @@ def export(file,
fw(ident_step + 'location="%.4g %.4g %.4g"\n' % location) fw(ident_step + 'location="%.4g %.4g %.4g"\n' % location)
fw(ident_step + '/>\n') fw(ident_step + '/>\n')
def writeDirectionalLight(ident, ob, mtx, lamp, world): def writeDirectionalLight(ident, obj, mtx, lamp, world):
safeName = clean_str(ob.name) safeName = clean_str(obj.name)
if world: if world:
ambi = world.ambient_color ambi = world.ambient_color
# ambi = world.amb # ambi = world.amb
...@@ -251,9 +250,9 @@ def export(file, ...@@ -251,9 +250,9 @@ def export(file,
fw(ident_step + 'direction="%.4g %.4g %.4g"\n' % orientation) fw(ident_step + 'direction="%.4g %.4g %.4g"\n' % orientation)
fw(ident_step + '/>\n') fw(ident_step + '/>\n')
def writePointLight(ident, ob, mtx, lamp, world): def writePointLight(ident, obj, mtx, lamp, world):
safeName = clean_str(ob.name) safeName = clean_str(obj.name)
if world: if world:
ambi = world.ambient_color ambi = world.ambient_color
# ambi = world.amb # ambi = world.amb
...@@ -296,9 +295,9 @@ def export(file, ...@@ -296,9 +295,9 @@ def export(file,
return "%s" % (newname) return "%s" % (newname)
secureName.nodeID = 0 secureName.nodeID = 0
def writeIndexedFaceSet(ident, ob, mesh, mtx, world): def writeIndexedFaceSet(ident, obj, mesh, mtx, world):
shape_name_x3d = clean_str(ob.name) shape_name_x3d = clean_str(obj.name)
mesh_name_x3d = clean_str(mesh.name) mesh_name_x3d = clean_str(mesh.name)
if not mesh.faces: if not mesh.faces:
...@@ -434,7 +433,7 @@ def export(file, ...@@ -434,7 +433,7 @@ def export(file,
gpu_shader = gpu_shader_cache.get(material) # material can be 'None', uses dummy cache gpu_shader = gpu_shader_cache.get(material) # material can be 'None', uses dummy cache
if gpu_shader is None: if gpu_shader is None:
gpu_shader = gpu_shader_cache[material] = gpu.export_shader(scene, material) gpu_shader = gpu_shader_cache[material] = gpu.export_shader(scene, material)
if 1: # XXX DEBUG if 1: # XXX DEBUG
gpu_shader_tmp = gpu.export_shader(scene, material) gpu_shader_tmp = gpu.export_shader(scene, material)
import pprint import pprint
...@@ -444,7 +443,6 @@ def export(file, ...@@ -444,7 +443,6 @@ def export(file,
pprint.pprint(gpu_shader_tmp, width=120) pprint.pprint(gpu_shader_tmp, width=120)
#pprint.pprint(val['vertex']) #pprint.pprint(val['vertex'])
del gpu_shader_tmp del gpu_shader_tmp
fw('%s<Appearance>\n' % ident) fw('%s<Appearance>\n' % ident)
ident += '\t' ident += '\t'
...@@ -483,7 +481,7 @@ def export(file, ...@@ -483,7 +481,7 @@ def export(file,
if use_h3d: if use_h3d:
mat_tmp = material if material else gpu_shader_dummy_mat mat_tmp = material if material else gpu_shader_dummy_mat
writeMaterialH3D(ident, mat_tmp, clean_str(mat_tmp.name, ''), world, writeMaterialH3D(ident, mat_tmp, clean_str(mat_tmp.name, ''), world,
ob, gpu_shader) obj, gpu_shader)
del mat_tmp del mat_tmp
else: else:
writeMaterial(ident, material, clean_str(material.name, ''), world) writeMaterial(ident, material, clean_str(material.name, ''), world)
...@@ -611,11 +609,10 @@ def export(file, ...@@ -611,11 +609,10 @@ def export(file,
fw('%.3g %.3g %.3g ' % x3d_v[0][slot_col]) fw('%.3g %.3g %.3g ' % x3d_v[0][slot_col])
fw('" />\n') fw('" />\n')
if use_h3d: if use_h3d:
# write attributes # write attributes
for gpu_attr in gpu_shader['attributes']: for gpu_attr in gpu_shader['attributes']:
# UVs # UVs
if gpu_attr['type'] == gpu.CD_MTFACE: if gpu_attr['type'] == gpu.CD_MTFACE:
if gpu_attr['datatype'] == gpu.GPU_DATA_2F: if gpu_attr['datatype'] == gpu.GPU_DATA_2F:
...@@ -702,7 +699,7 @@ def export(file, ...@@ -702,7 +699,7 @@ def export(file,
fw('%.6g %.6g %.6g ' % v.co[:]) fw('%.6g %.6g %.6g ' % v.co[:])
fw('"\n') fw('"\n')
fw(ident_step + '/>\n') fw(ident_step + '/>\n')
is_coords_written = True is_coords_written = True
if use_normals: if use_normals:
...@@ -793,7 +790,7 @@ def export(file, ...@@ -793,7 +790,7 @@ def export(file,
fw(ident_step + '/>\n') fw(ident_step + '/>\n')
def writeMaterialH3D(ident, mat, material_id, world, def writeMaterialH3D(ident, mat, material_id, world,
ob, gpu_shader): obj, gpu_shader):
fw('%s<Material />\n' % ident) fw('%s<Material />\n' % ident)
if mat.tag: if mat.tag:
...@@ -828,7 +825,6 @@ def export(file, ...@@ -828,7 +825,6 @@ def export(file,
#~ GPU_DYNAMIC_SAMPLER_2DIMAGE 13 #~ GPU_DYNAMIC_SAMPLER_2DIMAGE 13
#~ GPU_DYNAMIC_SAMPLER_2DSHADOW 14 #~ GPU_DYNAMIC_SAMPLER_2DSHADOW 14
''' '''
inline const char* typeToString( X3DType t ) { inline const char* typeToString( X3DType t ) {
switch( t ) { switch( t ) {
...@@ -874,7 +870,7 @@ def export(file, ...@@ -874,7 +870,7 @@ def export(file,
case MFMATRIX3D: return "MFMatrix3d"; case MFMATRIX3D: return "MFMatrix3d";
case SFMATRIX4D: return "SFMatrix4d"; case SFMATRIX4D: return "SFMatrix4d";
case MFMATRIX4D: return "MFMatrix4d"; case MFMATRIX4D: return "MFMatrix4d";
case UNKNOWN_X3D_TYPE: case UNKNOWN_X3D_TYPE:
default:return "UNKNOWN_X3D_TYPE"; default:return "UNKNOWN_X3D_TYPE";
''' '''
import gpu import gpu
...@@ -932,14 +928,14 @@ def export(file, ...@@ -932,14 +928,14 @@ def export(file,
elif uniform['type'] == gpu.GPU_DYNAMIC_OBJECT_IMAT: elif uniform['type'] == gpu.GPU_DYNAMIC_OBJECT_IMAT:
if uniform['datatype'] == gpu.GPU_DATA_16F: if uniform['datatype'] == gpu.GPU_DATA_16F:
value = ' '.join(['%.6f' % f for v in (global_matrix * ob.matrix_world).inverted() for f in v]) value = ' '.join(['%.6f' % f for v in (global_matrix * obj.matrix_world).inverted() for f in v])
fw('%s<field name="%s" type="SFMatrix4f" accessType="inputOutput" value="%s" />\n' % (ident, uniform['varname'], value)) fw('%s<field name="%s" type="SFMatrix4f" accessType="inputOutput" value="%s" />\n' % (ident, uniform['varname'], value))
else: else:
assert(0) assert(0)
elif uniform['type'] == gpu.GPU_DYNAMIC_SAMPLER_2DSHADOW: elif uniform['type'] == gpu.GPU_DYNAMIC_SAMPLER_2DSHADOW:
pass # XXX, shadow buffers not supported. pass # XXX, shadow buffers not supported.
elif uniform['type'] == gpu.GPU_DYNAMIC_SAMPLER_2DBUFFER: elif uniform['type'] == gpu.GPU_DYNAMIC_SAMPLER_2DBUFFER:
if uniform['datatype'] == gpu.GPU_DATA_1I: if uniform['datatype'] == gpu.GPU_DATA_1I:
if 1: if 1:
...@@ -1082,57 +1078,56 @@ def export(file, ...@@ -1082,57 +1078,56 @@ def export(file,
ident = '\t\t' ident = '\t\t'
if use_selection: if use_selection:
objects = (o for o in scene.objects if o.is_visible(scene) and o.select) objects = (obj for obj in scene.objects if obj.is_visible(scene) and o.select)
else: else:
objects = (o for o in scene.objects if o.is_visible(scene)) objects = (obj for obj in scene.objects if obj.is_visible(scene))
for ob_main in objects: for obj_main in objects:
free, derived = create_derived_objects(scene, ob_main) free, derived = create_derived_objects(scene, obj_main)
if derived is None: if derived is None:
continue continue
for ob, ob_mat in derived: for obj, obj_matrix in derived:
objType = ob.type obj_type = obj.type
objName = ob.name obj_matrix = global_matrix * obj_matrix
ob_mat = global_matrix * ob_mat
if objType == 'CAMERA': if obj_type == 'CAMERA':
writeViewpoint(ident, ob, ob_mat, scene) writeViewpoint(ident, obj, obj_matrix, scene)
elif objType in ('MESH', 'CURVE', 'SURF', 'FONT'): elif obj_type in ('MESH', 'CURVE', 'SURF', 'FONT'):
if (objType != 'MESH') or (use_apply_modifiers and ob.is_modified(scene, 'PREVIEW')): if (obj_type != 'MESH') or (use_apply_modifiers and obj.is_modified(scene, 'PREVIEW')):
try: try:
me = ob.to_mesh(scene, use_apply_modifiers, 'PREVIEW') me = obj.to_mesh(scene, use_apply_modifiers, 'PREVIEW')
except: except:
me = None me = None
else: else:
me = ob.data me = obj.data
if me is not None: if me is not None:
writeIndexedFaceSet(ident, ob, me, ob_mat, world) writeIndexedFaceSet(ident, obj, me, obj_matrix, world)
# free mesh created with create_mesh() # free mesh created with create_mesh()
if me != ob.data: if me != obj.data:
bpy.data.meshes.remove(me) bpy.data.meshes.remove(me)
elif objType == 'LAMP': elif obj_type == 'LAMP':
data = ob.data data = obj.data
datatype = data.type datatype = data.type
if datatype == 'POINT': if datatype == 'POINT':
writePointLight(ident, ob, ob_mat, data, world) writePointLight(ident, obj, obj_matrix, data, world)
elif datatype == 'SPOT': elif datatype == 'SPOT':
writeSpotLight(ident, ob, ob_mat, data, world) writeSpotLight(ident, obj, obj_matrix, data, world)
elif datatype == 'SUN': elif datatype == 'SUN':
writeDirectionalLight(ident, ob, ob_mat, data, world) writeDirectionalLight(ident, obj, obj_matrix, data, world)
else: else:
writeDirectionalLight(ident, ob, ob_mat, data, world) writeDirectionalLight(ident, obj, obj_matrix, data, world)
else: else:
#print "Info: Ignoring [%s], object type [%s] not handle yet" % (object.name,object.getType) #print "Info: Ignoring [%s], object type [%s] not handle yet" % (object.name,object.getType)
pass pass
if free: if free:
free_derived_objects(ob_main) free_derived_objects(obj_main)
ident = writeFooter(ident) ident = writeFooter(ident)
...@@ -1145,7 +1140,7 @@ def export(file, ...@@ -1145,7 +1140,7 @@ def export(file,
if use_h3d: if use_h3d:
bpy.data.materials.remove(gpu_shader_dummy_mat) bpy.data.materials.remove(gpu_shader_dummy_mat)
print('Info: finished X3D export to %r' % file.name) print('Info: finished X3D export to %r' % file.name)
########################################################## ##########################################################
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment