Newer
Older
return
blending = world.use_sky_blend, world.use_sky_paper, world.use_sky_real
grd_triple = clamp_color(world.horizon_color)
sky_triple = clamp_color(world.zenith_color)
mix_triple = clamp_color((grd_triple[i] + sky_triple[i]) / 2.0 for i in range(3))
ident_step = ident + (' ' * (-len(ident) + \
fw('%s<Background ' % ident)))
fw('DEF="%s"\n' % secureName(worldname))
# No Skytype - just Hor color
if blending == (False, False, False):
fw(ident_step + 'groundColor="%.3g %.3g %.3g"\n' % grd_triple)
fw(ident_step + 'skyColor="%.3g %.3g %.3g"\n' % grd_triple)
# Blend Gradient
elif blending == (True, False, False):
fw(ident_step + 'groundColor="%.3g %.3g %.3g, %.3g %.3g %.3g"\n' % (grd_triple + mix_triple))
fw(ident_step + 'groundAngle="1.57, 1.57"\n')
fw(ident_step + 'skyColor="%.3g %.3g %.3g, %.3g %.3g %.3g"\n' % (sky_triple + mix_triple))
fw(ident_step + 'skyAngle="1.57, 1.57"\n')
# Blend+Real Gradient Inverse
elif blending == (True, False, True):
fw(ident_step + 'groundColor="%.3g %.3g %.3g, %.3g %.3g %.3g"\n' % (sky_triple + grd_triple))
fw(ident_step + 'groundAngle="1.57"\n')
fw(ident_step + 'skyColor="%.3g %.3g %.3g, %.3g %.3g %.3g, %.3g %.3g %.3g"\n' % (sky_triple + grd_triple + sky_triple))
fw(ident_step + 'skyAngle="1.57, 3.14159"\n')
# Paper - just Zen Color
elif blending == (False, False, True):
fw(ident_step + 'groundColor="%.3g %.3g %.3g"\n' % sky_triple)
fw(ident_step + 'skyColor="%.3g %.3g %.3g"\n' % sky_triple)
# Blend+Real+Paper - komplex gradient
elif blending == (True, True, True):
fw(ident_step + 'groundColor="%.3g %.3g %.3g, %.3g %.3g %.3g"\n' % (sky_triple + grd_triple))
fw(ident_step + 'groundAngle="1.57, 1.57"\n')
fw(ident_step + 'skyColor="%.3g %.3g %.3g, %.3g %.3g %.3g"\n' % (sky_triple + grd_triple))
fw(ident_step + 'skyAngle="1.57, 1.57"\n')
# Any Other two colors
else:
fw(ident_step + 'groundColor="%.3g %.3g %.3g"\n' % grd_triple)
fw(ident_step + 'skyColor="%.3g %.3g %.3g"\n' % sky_triple)
if tex.type == 'IMAGE' and tex.image:
namemat = tex.name
pic = tex.image
basename = os.path.basename(bpy.path.abspath(pic.filepath))
fw(ident_step + 'bottomUrl="%s"\n' % basename)
##########################################################
# 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)
ident = ''
ident = writeHeader(ident)
Campbell Barton
committed
writeNavigationInfo(ident, scene)
writeBackground(ident, world)
writeFog(ident, world)
Campbell Barton
committed
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()
# -------------------------------------------------------------------------
# global cleanup
# -------------------------------------------------------------------------
if use_h3d:
bpy.data.materials.remove(gpu_shader_dummy_mat)
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')
print('failed to import compression modules, exporting uncompressed')
filepath = filepath[:-1] # remove trailing z
if file is None:
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'}