Newer
Older
Campbell Barton
committed
fw("rightUrl=\"%s\" " % basename)
Campbell Barton
committed
fw("topUrl=\"%s\" " % basename)
Campbell Barton
committed
fw("/>\n")
##########################################################
# export routine
##########################################################
# tag un-exported IDs
bpy.data.meshes.tag(False)
bpy.data.materials.tag(False)
bpy.data.images.tag(False)
print("Info: starting X3D export to %r..." % file.name)
Campbell Barton
committed
ident = ""
ident = writeHeader(ident)
Campbell Barton
committed
writeNavigationInfo(ident, scene)
writeBackground(ident, world)
writeFog(ident, world)
Campbell Barton
committed
ident = "\t\t"
Campbell Barton
committed
if use_selection:
objects = (o for o in scene.objects if o.is_visible(scene) and o.select)
else:
objects = (o for o in scene.objects if o.is_visible(scene))
for ob_main in objects:
free, derived = create_derived_objects(scene, ob_main)
if derived is None:
continue
for ob, ob_mat in derived:
objType = ob.type
objName = ob.name
ob_mat = global_matrix * ob_mat
if objType == 'CAMERA':
writeViewpoint(ident, ob, ob_mat, scene)
elif objType in ('MESH', 'CURVE', 'SURF', 'FONT'):
Campbell Barton
committed
if (objType != 'MESH') or (use_apply_modifiers and ob.is_modified(scene, 'PREVIEW')):
Campbell Barton
committed
try:
me = ob.to_mesh(scene, use_apply_modifiers, 'PREVIEW')
Campbell Barton
committed
except:
me = None
else:
me = ob.data
Campbell Barton
committed
if me is not None:
writeIndexedFaceSet(ident, ob, me, ob_mat, world)
Campbell Barton
committed
# free mesh created with create_mesh()
if me != ob.data:
bpy.data.meshes.remove(me)
elif objType == 'LAMP':
data = ob.data
datatype = data.type
if datatype == 'POINT':
writePointLight(ident, ob, ob_mat, data, world)
elif datatype == 'SPOT':
writeSpotLight(ident, ob, ob_mat, data, world)
elif datatype == 'SUN':
writeDirectionalLight(ident, ob, ob_mat, data, world)
else:
writeDirectionalLight(ident, ob, ob_mat, data, world)
else:
#print "Info: Ignoring [%s], object type [%s] not handle yet" % (object.name,object.getType)
pass
if free:
free_derived_objects(ob_main)
ident = writeFooter(ident)
export_main()
file.close()
print("Info: finished X3D export to %r" % file.name)
##########################################################
# Callbacks, needed before Main
##########################################################
def save(operator, context, filepath="",
use_selection=True,
use_apply_modifiers=False,
use_triangulate=False,
global_matrix=None,
):
if use_compress:
if not filepath.lower().endswith('.x3dz'):
filepath = '.'.join(filepath.split('.')[:-1]) + '.x3dz'
else:
if not filepath.lower().endswith('.x3d'):
filepath = '.'.join(filepath.split('.')[:-1]) + '.x3d'
if bpy.ops.object.mode_set.poll():
bpy.ops.object.mode_set(mode='OBJECT')
file = None
if filepath.lower().endswith('.x3dz'):
try:
import gzip
file = gzip.open(filepath, "w")
except:
print("failed to import compression modules, exporting uncompressed")
filepath = filepath[:-1] # remove trailing z
if file is None:
file = open(filepath, "w")
if global_matrix is None:
global_matrix = mathutils.Matrix()
export(file,
global_matrix,
context.scene,
use_apply_modifiers=use_apply_modifiers,
use_selection=use_selection,
use_triangulate=use_triangulate,
use_normals=use_normals,
return {'FINISHED'}