[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [1993] trunk/py/scripts/addons/ io_scene_x3d/export_x3d.py: nicer field formatting
Campbell Barton
ideasman42 at gmail.com
Thu Jun 2 07:13:50 CEST 2011
Revision: 1993
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=1993
Author: campbellbarton
Date: 2011-06-02 05:13:50 +0000 (Thu, 02 Jun 2011)
Log Message:
-----------
nicer field formatting
Modified Paths:
--------------
trunk/py/scripts/addons/io_scene_x3d/export_x3d.py
Modified: trunk/py/scripts/addons/io_scene_x3d/export_x3d.py
===================================================================
--- trunk/py/scripts/addons/io_scene_x3d/export_x3d.py 2011-06-02 01:59:46 UTC (rev 1992)
+++ trunk/py/scripts/addons/io_scene_x3d/export_x3d.py 2011-06-02 05:13:50 UTC (rev 1993)
@@ -108,7 +108,9 @@
use_h3d=False,
):
- # globals
+ # -------------------------------------------------------------------------
+ # global setup
+ # -------------------------------------------------------------------------
fw = file.write
dirname = os.path.dirname(file.name)
gpu_shader_cache = {}
@@ -139,7 +141,8 @@
ident += '\t'
fw('%s<meta name="filename" content="%s" />\n' % (ident, bfile))
fw('%s<meta name="generator" content="Blender %s" />\n' % (ident, bpy.app.version_string))
- fw('%s<meta name="translator" content="X3D exporter v1.55 (2006/01/17)" />\n' % ident)
+ # this info was never updated, so blender version should be enough
+ # fw('%s<meta name="translator" content="X3D exporter v1.55 (2006/01/17)" />\n' % ident)
ident = ident[:-1]
fw('%s</head>\n' % ident)
fw('%s<Scene>\n' % ident)
@@ -155,14 +158,17 @@
def writeViewpoint(ident, ob, mat, scene):
loc, quat, scale = mat.decompose()
- fw('%s<Viewpoint DEF="%s" ' % (ident, clean_str(ob.name)))
- fw('description="%s" ' % ob.name)
- fw('centerOfRotation="0 0 0" ')
- fw('position="%3.2f %3.2f %3.2f" ' % loc[:])
- fw('orientation="%3.2f %3.2f %3.2f %3.2f" ' % (quat.axis[:] + (quat.angle, )))
- fw('fieldOfView="%.3g" ' % ob.data.angle)
- fw('/>\n')
+ ident_step = ident + (' ' * (-len(ident) + \
+ fw('%s<Viewpoint ' % ident)))
+ fw('DEF="%s"\n' % clean_str(ob.name))
+ fw(ident_step + 'description="%s"\n' % ob.name)
+ fw(ident_step + 'centerOfRotation="0 0 0"\n')
+ 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 + 'fieldOfView="%.3g"\n' % ob.data.angle)
+ fw(ident_step + '/>\n')
+
def writeFog(ident, world):
if world:
mtype = world.mist_settings.falloff
@@ -171,14 +177,23 @@
return
if mparam.use_mist:
- fw('%s<Fog fogType="%s" ' % (ident, 'LINEAR' if (mtype == 'LINEAR') else 'EXPONENTIAL'))
- fw('color="%.3g %.3g %.3g" ' % clamp_color(world.horizon_color))
- fw('visibilityRange="%.3g" />\n' % mparam.depth)
+ ident_step = ident + (' ' * (-len(ident) + \
+ fw('%s<Fog ' % ident)))
+ fw('fogType="%s"\n' % ('LINEAR' if (mtype == 'LINEAR') else 'EXPONENTIAL'))
+ fw(ident_step + 'color="%.3g %.3g %.3g"\n' % clamp_color(world.horizon_color))
+ fw(ident_step + 'visibilityRange="%.3g"\n' % mparam.depth)
+ fw(ident_step + '/>\n')
else:
return
def writeNavigationInfo(ident, scene):
- fw('%s<NavigationInfo headlight="false" visibilityLimit="0.0" type=\'"EXAMINE","ANY"\' avatarSize="0.25, 1.75, 0.75" />\n' % ident)
+ ident_step = ident + (' ' * (-len(ident) + \
+ fw('%s<NavigationInfo ' % ident)))
+ fw('headlight="false"\n')
+ fw(ident_step + 'visibilityLimit="0.0"\n')
+ fw(ident_step + 'type=\'"EXAMINE", "ANY"\'\n')
+ fw(ident_step + 'avatarSize="0.25, 1.75, 0.75"\n')
+ fw(ident_step + '/>\n')
def writeSpotLight(ident, ob, mtx, lamp, world):
safeName = clean_str(ob.name)
@@ -201,15 +216,18 @@
radius = lamp.distance * math.cos(beamWidth)
# radius = lamp.dist*math.cos(beamWidth)
- fw('%s<SpotLight DEF="%s" ' % (ident, safeName))
- fw('radius="%.4g" ' % radius)
- fw('ambientIntensity="%.4g" ' % amb_intensity)
- fw('intensity="%.4g" ' % intensity)
- fw('color="%.4g %.4g %.4g" ' % clamp_color(lamp.color))
- fw('beamWidth="%.4g" ' % beamWidth)
- fw('cutOffAngle="%.4g" ' % cutOffAngle)
- fw('direction="%.4g %.4g %.4g" ' % orientation)
- fw('location="%.4g %.4g %.4g" />\n' % location)
+ ident_step = ident + (' ' * (-len(ident) + \
+ fw('%s<SpotLight ' % ident)))
+ fw('DEF="%s"\n' % safeName)
+ fw(ident_step + 'radius="%.4g"\n' % radius)
+ fw(ident_step + 'ambientIntensity="%.4g"\n' % amb_intensity)
+ fw(ident_step + 'intensity="%.4g"\n' % intensity)
+ fw(ident_step + 'color="%.4g %.4g %.4g"\n' % clamp_color(lamp.color))
+ fw(ident_step + 'beamWidth="%.4g"\n' % beamWidth)
+ fw(ident_step + 'cutOffAngle="%.4g"\n' % cutOffAngle)
+ fw(ident_step + 'direction="%.4g %.4g %.4g"\n' % orientation)
+ fw(ident_step + 'location="%.4g %.4g %.4g"\n' % location)
+ fw(ident_step + '/>\n')
def writeDirectionalLight(ident, ob, mtx, lamp, world):
safeName = clean_str(ob.name)
@@ -225,11 +243,14 @@
orientation = matrix_direction_neg_z(mtx)
- fw('%s<DirectionalLight DEF="%s" ' % (ident, safeName))
- fw('ambientIntensity="%.4g" ' % amb_intensity)
- fw('color="%.4g %.4g %.4g" ' % clamp_color(lamp.color))
- fw('intensity="%.4g" ' % intensity)
- fw('direction="%.4g %.4g %.4g" />\n' % orientation)
+ ident_step = ident + (' ' * (-len(ident) + \
+ fw('%s<DirectionalLight ' % ident)))
+ fw('DEF="%s"\n' % safeName)
+ fw(ident_step + 'ambientIntensity="%.4g"\n' % amb_intensity)
+ fw(ident_step + 'color="%.4g %.4g %.4g"\n' % clamp_color(lamp.color))
+ fw(ident_step + 'intensity="%.4g"\n' % intensity)
+ fw(ident_step + 'direction="%.4g %.4g %.4g"\n' % orientation)
+ fw(ident_step + '/>\n')
def writePointLight(ident, ob, mtx, lamp, world):
@@ -245,13 +266,16 @@
intensity = min(lamp.energy / 1.75, 1.0)
location = mtx.to_translation()[:]
- fw('%s<PointLight DEF="%s" ' % (ident, safeName))
- fw('ambientIntensity="%.4g" ' % amb_intensity)
- fw('color="%.4g %.4g %.4g" ' % clamp_color(lamp.color))
+ ident_step = ident + (' ' * (-len(ident) + \
+ fw('%s<PointLight ' % ident)))
+ fw('DEF="%s"\n' % safeName)
+ fw(ident_step + 'ambientIntensity="%.4g"\n' % amb_intensity)
+ fw(ident_step + 'color="%.4g %.4g %.4g"\n' % clamp_color(lamp.color))
- fw('intensity="%.4g" ' % intensity)
- fw('radius="%.4g" ' % lamp.distance)
- fw('location="%.4g %.4g %.4g" />\n' % location)
+ fw(ident_step + 'intensity="%.4g"\n' % intensity)
+ fw(ident_step + 'radius="%.4g" \n' % lamp.distance)
+ fw(ident_step + 'location="%.4g %.4g %.4g"\n' % location)
+ fw(ident_step + '/>\n')
def secureName(name):
name = name + str(secureName.nodeID)
@@ -316,11 +340,13 @@
loc, quat, sca = mtx.decompose()
- fw('%s<Transform DEF="%s" ' % (ident, shape_name_x3d))
- fw('translation="%.6g %.6g %.6g" ' % loc[:])
- fw('scale="%.6g %.6g %.6g" ' % sca[:])
- fw('rotation="%.6g %.6g %.6g %.6g" ' % (quat.axis[:] + (quat.angle, )))
- fw('>\n')
+ ident_step = ident + (' ' * (-len(ident) + \
+ fw('%s<Transform ' % ident)))
+ fw('DEF="%s"\n' % shape_name_x3d)
+ fw(ident_step + 'translation="%.6g %.6g %.6g"\n' % loc[:])
+ fw(ident_step + 'scale="%.6g %.6g %.6g"\n' % sca[:])
+ fw(ident_step + 'rotation="%.6g %.6g %.6g %.6g"\n' % (quat.axis[:] + (quat.angle, )))
+ fw(ident_step + '>\n')
ident += '\t'
if mesh.tag:
@@ -447,12 +473,13 @@
else:
rot = 0.0
- fw('%s<TextureTransform ' % ident)
+ ident_step = ident + (' ' * (-len(ident) + \
+ fw('%s<TextureTransform ' % ident)))
# fw('center="%.6g %.6g" ' % (0.0, 0.0))
- fw('translation="%.6g %.6g" ' % loc)
- fw('scale="%.6g %.6g" ' % (sca_x, sca_y))
- fw('rotation="%.6g" ' % rot)
- fw('/>\n')
+ fw(ident_step + 'translation="%.6g %.6g"\n' % loc)
+ fw(ident_step + 'scale="%.6g %.6g"\n' % (sca_x, sca_y))
+ fw(ident_step + 'rotation="%.6g"\n' % rot)
+ fw(ident_step + '/>\n')
if use_h3d:
mat_tmp = material if material else gpu_shader_dummy_mat
@@ -470,17 +497,17 @@
#-- IndexedFaceSet or IndexedLineSet
if use_triangulate:
- fw('%s<IndexedTriangleSet ' % ident)
- ident += '\t'
+ ident_step = ident + (' ' * (-len(ident) + \
+ fw('%s<IndexedTriangleSet ' % ident)))
# --- Write IndexedTriangleSet Attributes (same as IndexedFaceSet)
- fw('solid="%s" ' % ('true' if mesh.show_double_sided else 'false'))
+ fw('solid="%s"\n' % ('true' if mesh.show_double_sided else 'false'))
if is_smooth:
- fw('creaseAngle="%.4g" ' % mesh.auto_smooth_angle)
+ fw(ident_step + 'creaseAngle="%.4g"\n' % mesh.auto_smooth_angle)
if use_normals:
# currently not optional, could be made so:
- fw('normalPerVertex="true" ')
+ fw(ident_step + 'normalPerVertex="true"\n')
slot_uv = None
slot_col = None
@@ -551,13 +578,14 @@
# clear unused faces
face_tri_list[totface:] = []
- fw('index="')
+ fw(ident_step + 'index="')
for x3d_f in face_tri_list:
fw('%i %i %i ' % (x3d_f[0][2], x3d_f[1][2], x3d_f[2][2]))
- fw('" ')
+ fw('"\n')
# close IndexedTriangleSet
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list