diff --git a/release/scripts/op/io_scene_x3d/export_x3d.py b/release/scripts/op/io_scene_x3d/export_x3d.py
index 7c676f98f31..ea474a72b20 100644
--- a/release/scripts/op/io_scene_x3d/export_x3d.py
+++ b/release/scripts/op/io_scene_x3d/export_x3d.py
@@ -40,23 +40,15 @@ import bpy
import mathutils
from io_utils import create_derived_objects, free_derived_objects
-
-DEG2RAD = 0.017453292519943295
-RAD_90D = -(math.pi / 2.0)
-MATWORLD = mathutils.Matrix.Rotation(RAD_90D, 4, 'X')
+MATWORLD = mathutils.Matrix.Rotation(-(math.pi / 2.0), 4, 'X')
def round_color(col, cp):
return tuple([round(max(min(c, 1.0), 0.0), cp) for c in col])
-####################################
-# Global Variables
-####################################
+def matrix_direction(mtx):
+ return (mathutils.Vector((0.0, 0.0, -1.0)) * (MATWORLD * mtx).rotation_part()).normalize()[:]
-filepath = ""
-_safeOverwrite = True
-
-extension = ''
##########################################################
# Functions for writing output file
@@ -124,11 +116,7 @@ class x3d_class:
"TextureTransform", "TimeSensor", "TimeTrigger", "TouchSensor", "Transform", "TransmitterPdu",
"TriangleFanSet", "TriangleSet", "TriangleSet2D", "TriangleStripSet", "Viewpoint", "VisibilitySensor",
"WorldInfo", "X3D", "XvlShell", "VertexShader", "FragmentShader", "MultiShaderAppearance", "ShaderAppearance")
- self.namesStandard = ("Empty", "Empty.000", "Empty.001", "Empty.002", "Empty.003", "Empty.004", "Empty.005",
- "Empty.006", "Empty.007", "Empty.008", "Empty.009", "Empty.010", "Empty.011", "Empty.012",
- "Scene.001", "Scene.002", "Scene.003", "Scene.004", "Scene.005", "Scene.06", "Scene.013",
- "Scene.006", "Scene.007", "Scene.008", "Scene.009", "Scene.010", "Scene.011", "Scene.012",
- "World", "World.000", "World.001", "World.002", "World.003", "World.004", "World.005")
+
self.namesFog = ("", "LINEAR", "EXPONENTIAL", "")
##########################################################
@@ -152,21 +140,6 @@ class x3d_class:
# This functionality is poorly defined, disabling for now - campbell
'''
- def writeInline(self):
- inlines = Blender.Scene.Get()
- allinlines = len(inlines)
- if scene != inlines[0]:
- return
- else:
- for i in xrange(allinlines):
- nameinline=inlines[i].name
- if (nameinline not in self.namesStandard) and (i > 0):
- self.file.write("" % nameinline)
- self.file.write("\n\n")
-
-
def writeScript(self):
textEditor = Blender.Text.Get()
alltext = len(textEditor)
@@ -178,14 +151,14 @@ class x3d_class:
nalllines = len(textEditor[i].asLines())
alllines = textEditor[i].asLines()
for j in xrange(nalllines):
- self.writeIndented(alllines[j] + "\n")
+ self.write_indented(alllines[j] + "\n")
elif (self.proto == 0):
if (nametext == "route" or nametext == "route.js" or nametext == "route.txt") and (nlines != None):
nalllines = len(textEditor[i].asLines())
alllines = textEditor[i].asLines()
for j in xrange(nalllines):
- self.writeIndented(alllines[j] + "\n")
- self.writeIndented("\n")
+ self.write_indented(alllines[j] + "\n")
+ self.write_indented("\n")
'''
def writeViewpoint(self, ob, mat, scene):
@@ -233,7 +206,7 @@ class x3d_class:
# beamWidth=((lamp.spotSize*math.pi)/180.0)*.37
cutOffAngle = beamWidth * 1.3
- dx, dy, dz = self.computeDirection(mtx)
+ dx, dy, dz = matrix_direction(mtx)
location = (MATWORLD * mtx).translation_part()
@@ -260,11 +233,10 @@ class x3d_class:
ambientIntensity = 0
intensity = min(lamp.energy / 1.75, 1.0)
- dx, dy, dz = self.computeDirection(mtx)
+ dx, dy, dz = matrix_direction(mtx)
self.file.write("\n\n" % (round(dx, 4), round(dy, 4), round(dz, 4)))
@@ -283,26 +255,11 @@ class x3d_class:
self.file.write("\n\n" % (round(location[0], 3), round(location[1], 3), round(location[2], 3)))
- '''
- def writeNode(self, ob, mtx):
- obname=str(ob.name)
- if obname in self.namesStandard:
- return
- else:
- dx,dy,dz = self.computeDirection(mtx)
- # location=(MATWORLD * ob.matrix_world).translation_part()
- location=(MATWORLD * mtx).translation_part()
- self.writeIndented("<%s\n" % obname,1)
- self.writeIndented("direction=\"%s %s %s\"\n" % (round(dx,3),round(dy,3),round(dz,3)))
- self.writeIndented("location=\"%s %s %s\"\n" % (round(location[0],3), round(location[1],3), round(location[2],3)))
- self.writeIndented("/>\n",-1)
- self.writeIndented("\n")
- '''
+
def secureName(self, name):
name = name + str(self.nodeID)
self.nodeID = self.nodeID + 1
@@ -349,24 +306,24 @@ class x3d_class:
if 'HALO' in mode and self.halonode == 0:
# if mode & Mesh.FaceModes.HALO and self.halonode == 0:
- self.writeIndented("\n", 1)
+ self.write_indented("\n", 1)
self.halonode = 1
elif 'BILLBOARD' in mode and self.billnode == 0:
# elif mode & Mesh.FaceModes.BILLBOARD and self.billnode == 0:
- self.writeIndented("\n", 1)
+ self.write_indented("\n", 1)
self.billnode = 1
# TF_TILES is marked as deprecated in DNA_meshdata_types.h
# elif mode & Mesh.FaceModes.TILES and self.tilenode == 0:
# self.tilenode = 1
elif 'COLLISION' not in mode and self.collnode == 0:
# elif not mode & Mesh.FaceModes.DYNAMIC and self.collnode == 0:
- self.writeIndented("\n", 1)
+ self.write_indented("\n", 1)
self.collnode = 1
nIFSCnt = self.countIFSSetsNeeded(mesh, imageMap, sided)
if nIFSCnt > 1:
- self.writeIndented("\n" % ("G_", meshName), 1)
+ self.write_indented("\n" % ("G_", meshName), 1)
if 'two' in sided and sided['two'] > 0:
bTwoSided = 1
@@ -380,12 +337,10 @@ class x3d_class:
quat = mtx.to_quat()
rot = quat.axis
- self.writeIndented('\n' % \
+ self.write_indented('\n' % \
(meshName, loc[0], loc[1], loc[2], sca[0], sca[1], sca[2], rot[0], rot[1], rot[2], quat.angle))
- # self.writeIndented('\n' % \
- # (meshName, loc[0], loc[1], loc[2], sca[0], sca[1], sca[2], rot[0], rot[1], rot[2], quat.angle*DEG2RAD) )
- self.writeIndented("\n", 1)
+ self.write_indented("\n", 1)
is_smooth = False
# XXX, lame, only exports first material.
@@ -395,7 +350,7 @@ class x3d_class:
break
if mat_first or mesh.uv_textures.active:
- self.writeIndented("\n", 1)
+ self.write_indented("\n", 1)
# right now this script can only handle a single material per mesh.
if mat_first and mat_first.use_face_texture == False:
self.writeMaterial(mat_first, self.cleanStr(mat_first.name, ""), world)
@@ -427,21 +382,21 @@ class x3d_class:
self.writeImageTexture(image)
if self.tilenode == 1:
- self.writeIndented("\n" % (image.xrep, image.yrep))
+ self.write_indented("\n" % (image.xrep, image.yrep))
self.tilenode = 0
- self.writeIndented("\n", -1)
+ self.write_indented("\n", -1)
#-- IndexedFaceSet or IndexedLineSet
# user selected BOUNDS=1, SOLID=3, SHARED=4, or TEXTURE=5
# look up mesh name, use it if available
if mesh.tag:
- self.writeIndented("" % meshME, 1)
+ self.write_indented("" % meshME, 1)
else:
mesh.tag = True
- self.writeIndented("\n", -1)
- self.writeIndented("\n", -1)
- self.writeIndented("\n", -1)
+ self.write_indented("\n", -1)
+ self.write_indented("\n", -1)
+ self.write_indented("\n", -1)
if self.halonode == 1:
- self.writeIndented("\n", -1)
+ self.write_indented("\n", -1)
self.halonode = 0
if self.billnode == 1:
- self.writeIndented("\n", -1)
+ self.write_indented("\n", -1)
self.billnode = 0
if self.collnode == 1:
- self.writeIndented("\n", -1)
+ self.write_indented("\n", -1)
self.collnode = 0
if nIFSCnt > 1:
- self.writeIndented("\n", -1)
+ self.write_indented("\n", -1)
self.file.write("\n")
@@ -523,12 +477,12 @@ class x3d_class:
else:
#-- vertices
# mesh.transform(ob.matrix_world)
- self.writeIndented("")
- self.writeIndented("\n", -1)
+ self.write_indented("\n", -1)
def writeTextureCoordinates(self, mesh):
if self.writingtexture == 0:
@@ -548,28 +502,28 @@ class x3d_class:
else:
texCoordList = (uv for fuv in mesh.uv_textures.active.data for uv in fuv.uv)
- self.writeIndented("")
- self.writeIndented("\n", -1)
+ self.write_indented("\n", -1)
def writeFaceColors(self, mesh):
if self.writingcolor == 0:
self.file.write("colorPerVertex=\"false\" ")
elif mesh.vertex_colors.active:
- self.writeIndented("")
- self.writeIndented("\n", -1)
+ self.write_indented("\n", -1)
def writeMaterial(self, mat, matName, world):
# look up material name, use it if available
if mat.tag:
- self.writeIndented("\n" % matName)
+ self.write_indented("\n" % matName)
else:
mat.tag = True
@@ -591,26 +545,26 @@ class x3d_class:
shininess = 0.0
specColor = emitColor = diffuseColor
- self.writeIndented("" % (round(transp, self.cp)))
- self.writeIndented("\n", -1)
+ self.write_indented("\n", -1)
def writeImageTexture(self, image):
name = image.name
filepath = os.path.basename(image.filepath)
if image.tag:
- self.writeIndented("\n" % self.cleanStr(name))
+ self.write_indented("\n" % self.cleanStr(name))
else:
image.tag = True
- self.writeIndented("" % filepath)
- self.writeIndented("\n", -1)
+ self.write_indented("\n", -1)
def writeBackground(self, world, alltextures):
if world:
@@ -624,9 +578,7 @@ class x3d_class:
sky_triple = round_color(world.zenith_color, self.cp)
mix_triple = round_color(((grd_triple[i] + sky_triple[i]) / 2.0 for i in range(3)), self.cp)
- self.file.write("\n\n")
+ self.write_indented("topUrl=\"%s\" " % basename)
+ self.write_indented("/>\n\n")
##########################################################
# export routine
@@ -893,24 +845,13 @@ class x3d_class:
# round(c.b/255.0,self.cp))
return s
- def computeDirection(self, mtx):
- return (mathutils.Vector((0.0, 0.0, -1.0)) * (MATWORLD * mtx).rotation_part()).normalize()[:]
-
- # swap Y and Z to handle axis difference between Blender and VRML
- #------------------------------------------------------------------------
- def rotatePointForVRML(self, v):
- return v[0], v[2], -v[1]
-
# For writing well formed VRML code
#------------------------------------------------------------------------
- def writeIndented(self, s, inc=0):
+ def write_indented(self, s, inc=0):
if inc < 1:
self.indentLevel = self.indentLevel + inc
- spaces = ""
- for x in range(self.indentLevel):
- spaces = spaces + "\t"
- self.file.write(spaces + s)
+ self.file.write((self.indentLevel * "\t") + s)
if inc > 0:
self.indentLevel = self.indentLevel + inc