pep8 cleanup.
This commit is contained in:
@@ -41,9 +41,10 @@ import mathutils
|
||||
|
||||
from io_utils import create_derived_objects, free_derived_objects
|
||||
|
||||
DEG2RAD=0.017453292519943295
|
||||
DEG2RAD = 0.017453292519943295
|
||||
RAD_90D = -(math.pi / 2.0)
|
||||
MATWORLD= mathutils.Matrix.Rotation(RAD_90D, 4, 'X')
|
||||
MATWORLD = mathutils.Matrix.Rotation(RAD_90D, 4, 'X')
|
||||
|
||||
|
||||
def round_color(col, cp):
|
||||
return tuple([round(max(min(c, 1.0), 0.0), cp) for c in col])
|
||||
@@ -61,6 +62,7 @@ extension = ''
|
||||
# Functions for writing output file
|
||||
##########################################################
|
||||
|
||||
|
||||
class x3d_class:
|
||||
|
||||
def __init__(self, filepath):
|
||||
@@ -73,18 +75,18 @@ class x3d_class:
|
||||
self.halonode = 0
|
||||
self.collnode = 0
|
||||
self.tilenode = 0
|
||||
self.verbose=2 # level of verbosity in console 0-none, 1-some, 2-most
|
||||
self.cp=3 # decimals for material color values 0.000 - 1.000
|
||||
self.vp=3 # decimals for vertex coordinate values 0.000 - n.000
|
||||
self.tp=3 # decimals for texture coordinate values 0.000 - 1.000
|
||||
self.it=3
|
||||
self.verbose = 2 # level of verbosity in console 0-none, 1-some, 2-most
|
||||
self.cp = 3 # decimals for material color values 0.000 - 1.000
|
||||
self.vp = 3 # decimals for vertex coordinate values 0.000 - n.000
|
||||
self.tp = 3 # decimals for texture coordinate values 0.000 - 1.000
|
||||
self.it = 3
|
||||
|
||||
#--- class private don't touch ---
|
||||
self.texNames={} # dictionary of textureNames
|
||||
self.matNames={} # dictionary of materiaNames
|
||||
self.meshNames={} # dictionary of meshNames
|
||||
self.indentLevel=0 # keeps track of current indenting
|
||||
self.filepath=filepath
|
||||
self.texNames = {} # dictionary of textureNames
|
||||
self.matNames = {} # dictionary of materiaNames
|
||||
self.meshNames = {} # dictionary of meshNames
|
||||
self.indentLevel = 0 # keeps track of current indenting
|
||||
self.filepath = filepath
|
||||
self.file = None
|
||||
if filepath.lower().endswith('.x3dz'):
|
||||
try:
|
||||
@@ -92,45 +94,45 @@ class x3d_class:
|
||||
self.file = gzip.open(filepath, "w")
|
||||
except:
|
||||
print("failed to import compression modules, exporting uncompressed")
|
||||
self.filepath = filepath[:-1] # remove trailing z
|
||||
self.filepath = filepath[:-1] # remove trailing z
|
||||
|
||||
if self.file is None:
|
||||
self.file = open(self.filepath, "w", encoding='utf8')
|
||||
|
||||
self.bNav=0
|
||||
self.nodeID=0
|
||||
self.namesReserved=[ "Anchor","Appearance","Arc2D","ArcClose2D","AudioClip","Background","Billboard",
|
||||
"BooleanFilter","BooleanSequencer","BooleanToggle","BooleanTrigger","Box","Circle2D",
|
||||
"Collision","Color","ColorInterpolator","ColorRGBA","component","Cone","connect",
|
||||
"Contour2D","ContourPolyline2D","Coordinate","CoordinateDouble","CoordinateInterpolator",
|
||||
"CoordinateInterpolator2D","Cylinder","CylinderSensor","DirectionalLight","Disk2D",
|
||||
"ElevationGrid","EspduTransform","EXPORT","ExternProtoDeclare","Extrusion","field",
|
||||
"fieldValue","FillProperties","Fog","FontStyle","GeoCoordinate","GeoElevationGrid",
|
||||
"GeoLocationLocation","GeoLOD","GeoMetadata","GeoOrigin","GeoPositionInterpolator",
|
||||
"GeoTouchSensor","GeoViewpoint","Group","HAnimDisplacer","HAnimHumanoid","HAnimJoint",
|
||||
"HAnimSegment","HAnimSite","head","ImageTexture","IMPORT","IndexedFaceSet",
|
||||
"IndexedLineSet","IndexedTriangleFanSet","IndexedTriangleSet","IndexedTriangleStripSet",
|
||||
"Inline","IntegerSequencer","IntegerTrigger","IS","KeySensor","LineProperties","LineSet",
|
||||
"LoadSensor","LOD","Material","meta","MetadataDouble","MetadataFloat","MetadataInteger",
|
||||
"MetadataSet","MetadataString","MovieTexture","MultiTexture","MultiTextureCoordinate",
|
||||
"MultiTextureTransform","NavigationInfo","Normal","NormalInterpolator","NurbsCurve",
|
||||
"NurbsCurve2D","NurbsOrientationInterpolator","NurbsPatchSurface",
|
||||
"NurbsPositionInterpolator","NurbsSet","NurbsSurfaceInterpolator","NurbsSweptSurface",
|
||||
"NurbsSwungSurface","NurbsTextureCoordinate","NurbsTrimmedSurface","OrientationInterpolator",
|
||||
"PixelTexture","PlaneSensor","PointLight","PointSet","Polyline2D","Polypoint2D",
|
||||
"PositionInterpolator","PositionInterpolator2D","ProtoBody","ProtoDeclare","ProtoInstance",
|
||||
"ProtoInterface","ProximitySensor","ReceiverPdu","Rectangle2D","ROUTE","ScalarInterpolator",
|
||||
"Scene","Script","Shape","SignalPdu","Sound","Sphere","SphereSensor","SpotLight","StaticGroup",
|
||||
"StringSensor","Switch","Text","TextureBackground","TextureCoordinate","TextureCoordinateGenerator",
|
||||
"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","" ]
|
||||
self.bNav = 0
|
||||
self.nodeID = 0
|
||||
self.namesReserved = ("Anchor", "Appearance", "Arc2D", "ArcClose2D", "AudioClip", "Background", "Billboard",
|
||||
"BooleanFilter", "BooleanSequencer", "BooleanToggle", "BooleanTrigger", "Box", "Circle2D",
|
||||
"Collision", "Color", "ColorInterpolator", "ColorRGBA", "component", "Cone", "connect",
|
||||
"Contour2D", "ContourPolyline2D", "Coordinate", "CoordinateDouble", "CoordinateInterpolator",
|
||||
"CoordinateInterpolator2D", "Cylinder", "CylinderSensor", "DirectionalLight", "Disk2D",
|
||||
"ElevationGrid", "EspduTransform", "EXPORT", "ExternProtoDeclare", "Extrusion", "field",
|
||||
"fieldValue", "FillProperties", "Fog", "FontStyle", "GeoCoordinate", "GeoElevationGrid",
|
||||
"GeoLocationLocation", "GeoLOD", "GeoMetadata", "GeoOrigin", "GeoPositionInterpolator",
|
||||
"GeoTouchSensor", "GeoViewpoint", "Group", "HAnimDisplacer", "HAnimHumanoid", "HAnimJoint",
|
||||
"HAnimSegment", "HAnimSite", "head", "ImageTexture", "IMPORT", "IndexedFaceSet",
|
||||
"IndexedLineSet", "IndexedTriangleFanSet", "IndexedTriangleSet", "IndexedTriangleStripSet",
|
||||
"Inline", "IntegerSequencer", "IntegerTrigger", "IS", "KeySensor", "LineProperties", "LineSet",
|
||||
"LoadSensor", "LOD", "Material", "meta", "MetadataDouble", "MetadataFloat", "MetadataInteger",
|
||||
"MetadataSet", "MetadataString", "MovieTexture", "MultiTexture", "MultiTextureCoordinate",
|
||||
"MultiTextureTransform", "NavigationInfo", "Normal", "NormalInterpolator", "NurbsCurve",
|
||||
"NurbsCurve2D", "NurbsOrientationInterpolator", "NurbsPatchSurface",
|
||||
"NurbsPositionInterpolator", "NurbsSet", "NurbsSurfaceInterpolator", "NurbsSweptSurface",
|
||||
"NurbsSwungSurface", "NurbsTextureCoordinate", "NurbsTrimmedSurface", "OrientationInterpolator",
|
||||
"PixelTexture", "PlaneSensor", "PointLight", "PointSet", "Polyline2D", "Polypoint2D",
|
||||
"PositionInterpolator", "PositionInterpolator2D", "ProtoBody", "ProtoDeclare", "ProtoInstance",
|
||||
"ProtoInterface", "ProximitySensor", "ReceiverPdu", "Rectangle2D", "ROUTE", "ScalarInterpolator",
|
||||
"Scene", "Script", "Shape", "SignalPdu", "Sound", "Sphere", "SphereSensor", "SpotLight", "StaticGroup",
|
||||
"StringSensor", "Switch", "Text", "TextureBackground", "TextureCoordinate", "TextureCoordinateGenerator",
|
||||
"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", "")
|
||||
|
||||
##########################################################
|
||||
# Writing nodes routines
|
||||
@@ -138,7 +140,7 @@ class x3d_class:
|
||||
|
||||
def writeHeader(self):
|
||||
#bfile = sys.expandpath( Blender.Get('filepath') ).replace('<', '<').replace('>', '>')
|
||||
bfile = repr(os.path.basename(self.filepath).replace('<', '<').replace('>', '>'))[1:-1] # use outfile name
|
||||
bfile = repr(os.path.basename(self.filepath).replace('<', '<').replace('>', '>'))[1:-1] # use outfile name
|
||||
self.file.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
|
||||
self.file.write("<!DOCTYPE X3D PUBLIC \"ISO//Web3D//DTD X3D 3.0//EN\" \"http://www.web3d.org/specifications/x3d-3.0.dtd\">\n")
|
||||
self.file.write("<X3D version=\"3.0\" profile=\"Immersive\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema-instance\" xsd:noNamespaceSchemaLocation=\"http://www.web3d.org/specifications/x3d-3.0.xsd\">\n")
|
||||
@@ -212,7 +214,7 @@ class x3d_class:
|
||||
# if (mtype == 1 or mtype == 2):
|
||||
self.file.write("<Fog fogType=\"%s\" " % self.namesFog[mtype])
|
||||
self.file.write("color=\"%s %s %s\" " % round_color(world.horizon_color, self.cp))
|
||||
self.file.write("visibilityRange=\"%s\" />\n\n" % round(mparam[2],self.cp))
|
||||
self.file.write("visibilityRange=\"%s\" />\n\n" % round(mparam[2], self.cp))
|
||||
else:
|
||||
return
|
||||
|
||||
@@ -229,68 +231,66 @@ class x3d_class:
|
||||
ambientIntensity = 0.0
|
||||
|
||||
# compute cutoff and beamwidth
|
||||
intensity=min(lamp.energy/1.75,1.0)
|
||||
beamWidth=lamp.spot_size * 0.37;
|
||||
# beamWidth=((lamp.spotSize*math.pi)/180.0)*.37;
|
||||
cutOffAngle=beamWidth*1.3
|
||||
intensity = min(lamp.energy / 1.75, 1.0)
|
||||
beamWidth = lamp.spot_size * 0.37
|
||||
# beamWidth=((lamp.spotSize*math.pi)/180.0)*.37
|
||||
cutOffAngle = beamWidth * 1.3
|
||||
|
||||
dx, dy, dz = self.computeDirection(mtx)
|
||||
|
||||
#location=(ob.matrix_world*MATWORLD).translation_part() # now passed
|
||||
location=(MATWORLD * mtx).translation_part()
|
||||
location = (MATWORLD * mtx).translation_part()
|
||||
|
||||
radius = lamp.distance*math.cos(beamWidth)
|
||||
radius = lamp.distance * math.cos(beamWidth)
|
||||
# radius = lamp.dist*math.cos(beamWidth)
|
||||
self.file.write("<SpotLight DEF=\"%s\" " % safeName)
|
||||
self.file.write("radius=\"%s\" " % (round(radius,self.cp)))
|
||||
self.file.write("ambientIntensity=\"%s\" " % (round(ambientIntensity,self.cp)))
|
||||
self.file.write("intensity=\"%s\" " % (round(intensity,self.cp)))
|
||||
self.file.write("radius=\"%s\" " % (round(radius, self.cp)))
|
||||
self.file.write("ambientIntensity=\"%s\" " % (round(ambientIntensity, self.cp)))
|
||||
self.file.write("intensity=\"%s\" " % (round(intensity, self.cp)))
|
||||
self.file.write("color=\"%s %s %s\" " % round_color(lamp.color, self.cp))
|
||||
self.file.write("beamWidth=\"%s\" " % (round(beamWidth,self.cp)))
|
||||
self.file.write("cutOffAngle=\"%s\" " % (round(cutOffAngle,self.cp)))
|
||||
self.file.write("direction=\"%s %s %s\" " % (round(dx,3),round(dy,3),round(dz,3)))
|
||||
self.file.write("location=\"%s %s %s\" />\n\n" % (round(location[0],3), round(location[1],3), round(location[2],3)))
|
||||
|
||||
self.file.write("beamWidth=\"%s\" " % (round(beamWidth, self.cp)))
|
||||
self.file.write("cutOffAngle=\"%s\" " % (round(cutOffAngle, self.cp)))
|
||||
self.file.write("direction=\"%s %s %s\" " % (round(dx, 3), round(dy, 3), round(dz, 3)))
|
||||
self.file.write("location=\"%s %s %s\" />\n\n" % (round(location[0], 3), round(location[1], 3), round(location[2], 3)))
|
||||
|
||||
def writeDirectionalLight(self, ob, mtx, lamp, world):
|
||||
safeName = self.cleanStr(ob.name)
|
||||
if world:
|
||||
ambi = world.ambient_color
|
||||
# ambi = world.amb
|
||||
ambientIntensity = ((float(ambi[0] + ambi[1] + ambi[2]))/3)/2.5
|
||||
ambientIntensity = ((float(ambi[0] + ambi[1] + ambi[2])) / 3.0) / 2.5
|
||||
else:
|
||||
ambi = 0
|
||||
ambientIntensity = 0
|
||||
|
||||
intensity=min(lamp.energy/1.75,1.0)
|
||||
intensity = min(lamp.energy / 1.75, 1.0)
|
||||
dx, dy, dz = self.computeDirection(mtx)
|
||||
self.file.write("<DirectionalLight DEF=\"%s\" " % safeName)
|
||||
self.file.write("ambientIntensity=\"%s\" " % (round(ambientIntensity,self.cp)))
|
||||
self.file.write("color=\"%s %s %s\" " % (round(lamp.color[0],self.cp), round(lamp.color[1],self.cp), round(lamp.color[2],self.cp)))
|
||||
self.file.write("ambientIntensity=\"%s\" " % (round(ambientIntensity, self.cp)))
|
||||
self.file.write("color=\"%s %s %s\" " % (round(lamp.color[0], self.cp), round(lamp.color[1], self.cp), round(lamp.color[2], self.cp)))
|
||||
# self.file.write("color=\"%s %s %s\" " % (round(lamp.col[0],self.cp), round(lamp.col[1],self.cp), round(lamp.col[2],self.cp)))
|
||||
self.file.write("intensity=\"%s\" " % (round(intensity,self.cp)))
|
||||
self.file.write("direction=\"%s %s %s\" />\n\n" % (round(dx,4),round(dy,4),round(dz,4)))
|
||||
self.file.write("intensity=\"%s\" " % (round(intensity, self.cp)))
|
||||
self.file.write("direction=\"%s %s %s\" />\n\n" % (round(dx, 4), round(dy, 4), round(dz, 4)))
|
||||
|
||||
def writePointLight(self, ob, mtx, lamp, world):
|
||||
safeName = self.cleanStr(ob.name)
|
||||
if world:
|
||||
ambi = world.ambient_color
|
||||
# ambi = world.amb
|
||||
ambientIntensity = ((float(ambi[0] + ambi[1] + ambi[2]))/3)/2.5
|
||||
ambientIntensity = ((float(ambi[0] + ambi[1] + ambi[2])) / 3) / 2.5
|
||||
else:
|
||||
ambi = 0
|
||||
ambientIntensity = 0
|
||||
|
||||
location= (MATWORLD * mtx).translation_part()
|
||||
location = (MATWORLD * mtx).translation_part()
|
||||
|
||||
self.file.write("<PointLight DEF=\"%s\" " % safeName)
|
||||
self.file.write("ambientIntensity=\"%s\" " % (round(ambientIntensity,self.cp)))
|
||||
self.file.write("color=\"%s %s %s\" " % (round(lamp.color[0],self.cp), round(lamp.color[1],self.cp), round(lamp.color[2],self.cp)))
|
||||
self.file.write("ambientIntensity=\"%s\" " % (round(ambientIntensity, self.cp)))
|
||||
self.file.write("color=\"%s %s %s\" " % (round(lamp.color[0], self.cp), round(lamp.color[1], self.cp), round(lamp.color[2], self.cp)))
|
||||
# self.file.write("color=\"%s %s %s\" " % (round(lamp.col[0],self.cp), round(lamp.col[1],self.cp), round(lamp.col[2],self.cp)))
|
||||
self.file.write("intensity=\"%s\" " % (round( min(lamp.energy/1.75,1.0) ,self.cp)))
|
||||
self.file.write("radius=\"%s\" " % lamp.distance )
|
||||
self.file.write("intensity=\"%s\" " % (round(min(lamp.energy / 1.75, 1.0), self.cp)))
|
||||
self.file.write("radius=\"%s\" " % lamp.distance)
|
||||
# self.file.write("radius=\"%s\" " % lamp.dist )
|
||||
self.file.write("location=\"%s %s %s\" />\n\n" % (round(location[0],3), round(location[1],3), round(location[2],3)))
|
||||
self.file.write("location=\"%s %s %s\" />\n\n" % (round(location[0], 3), round(location[1], 3), round(location[2], 3)))
|
||||
'''
|
||||
def writeNode(self, ob, mtx):
|
||||
obname=str(ob.name)
|
||||
@@ -308,13 +308,13 @@ class x3d_class:
|
||||
'''
|
||||
def secureName(self, name):
|
||||
name = name + str(self.nodeID)
|
||||
self.nodeID=self.nodeID+1
|
||||
self.nodeID = self.nodeID + 1
|
||||
if len(name) <= 3:
|
||||
newname = "_" + str(self.nodeID)
|
||||
return "%s" % (newname)
|
||||
else:
|
||||
for bad in ['"','#',"'",',','.','[','\\',']','{','}']:
|
||||
name=name.replace(bad,'_')
|
||||
for bad in ('"', '#', "'", ', ', '.', '[', '\\', ']', '{', '}'):
|
||||
name = name.replace(bad, "_")
|
||||
if name in self.namesReserved:
|
||||
newname = name[0:3] + "_" + str(self.nodeID)
|
||||
return "%s" % (newname)
|
||||
@@ -325,14 +325,15 @@ class x3d_class:
|
||||
newname = name
|
||||
return "%s" % (newname)
|
||||
|
||||
def writeIndexedFaceSet(self, ob, mesh, mtx, world, EXPORT_TRI = False):
|
||||
imageMap={} # set of used images
|
||||
sided={} # 'one':cnt , 'two':cnt
|
||||
def writeIndexedFaceSet(self, ob, mesh, mtx, world, EXPORT_TRI=False):
|
||||
imageMap = {} # set of used images
|
||||
sided = {} # 'one':cnt , 'two':cnt
|
||||
meshName = self.cleanStr(ob.name)
|
||||
|
||||
meshME = self.cleanStr(ob.data.name) # We dont care if its the mesh name or not
|
||||
# meshME = self.cleanStr(ob.getData(mesh=1).name) # We dont care if its the mesh name or not
|
||||
if len(mesh.faces) == 0: return
|
||||
meshME = self.cleanStr(ob.data.name) # We dont care if its the mesh name or not
|
||||
if not mesh.faces:
|
||||
return
|
||||
|
||||
mode = []
|
||||
# mode = 0
|
||||
if mesh.uv_textures.active:
|
||||
@@ -351,43 +352,43 @@ class x3d_class:
|
||||
|
||||
if 'HALO' in mode and self.halonode == 0:
|
||||
# if mode & Mesh.FaceModes.HALO and self.halonode == 0:
|
||||
self.writeIndented("<Billboard axisOfRotation=\"0 0 0\">\n",1)
|
||||
self.writeIndented("<Billboard axisOfRotation=\"0 0 0\">\n", 1)
|
||||
self.halonode = 1
|
||||
elif 'BILLBOARD' in mode and self.billnode == 0:
|
||||
# elif mode & Mesh.FaceModes.BILLBOARD and self.billnode == 0:
|
||||
self.writeIndented("<Billboard axisOfRotation=\"0 1 0\">\n",1)
|
||||
self.writeIndented("<Billboard axisOfRotation=\"0 1 0\">\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("<Collision enabled=\"false\">\n",1)
|
||||
self.writeIndented("<Collision enabled=\"false\">\n", 1)
|
||||
self.collnode = 1
|
||||
|
||||
nIFSCnt=self.countIFSSetsNeeded(mesh, imageMap, sided)
|
||||
nIFSCnt = self.countIFSSetsNeeded(mesh, imageMap, sided)
|
||||
|
||||
if nIFSCnt > 1:
|
||||
self.writeIndented("<Group DEF=\"%s%s\">\n" % ("G_", meshName),1)
|
||||
self.writeIndented("<Group DEF=\"%s%s\">\n" % ("G_", meshName), 1)
|
||||
|
||||
if 'two' in sided and sided['two'] > 0:
|
||||
bTwoSided=1
|
||||
bTwoSided = 1
|
||||
else:
|
||||
bTwoSided=0
|
||||
bTwoSided = 0
|
||||
|
||||
mtx = MATWORLD * mtx
|
||||
|
||||
loc= mtx.translation_part()
|
||||
sca= mtx.scale_part()
|
||||
loc = mtx.translation_part()
|
||||
sca = mtx.scale_part()
|
||||
quat = mtx.to_quat()
|
||||
rot= quat.axis
|
||||
rot = quat.axis
|
||||
|
||||
self.writeIndented('<Transform DEF="%s" translation="%.6f %.6f %.6f" scale="%.6f %.6f %.6f" rotation="%.6f %.6f %.6f %.6f">\n' % \
|
||||
(meshName, loc[0], loc[1], loc[2], sca[0], sca[1], sca[2], rot[0], rot[1], rot[2], quat.angle) )
|
||||
(meshName, loc[0], loc[1], loc[2], sca[0], sca[1], sca[2], rot[0], rot[1], rot[2], quat.angle))
|
||||
# self.writeIndented('<Transform DEF="%s" translation="%.6f %.6f %.6f" scale="%.6f %.6f %.6f" rotation="%.6f %.6f %.6f %.6f">\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("<Shape>\n",1)
|
||||
self.writeIndented("<Shape>\n", 1)
|
||||
is_smooth = False
|
||||
|
||||
# XXX, lame, only exports first material.
|
||||
@@ -437,15 +438,15 @@ class x3d_class:
|
||||
#-- IndexedFaceSet or IndexedLineSet
|
||||
|
||||
# user selected BOUNDS=1, SOLID=3, SHARED=4, or TEXTURE=5
|
||||
ifStyle="IndexedFaceSet"
|
||||
ifStyle = "IndexedFaceSet"
|
||||
# look up mesh name, use it if available
|
||||
if meshME in self.meshNames:
|
||||
self.writeIndented("<%s USE=\"ME_%s\">" % (ifStyle, meshME), 1)
|
||||
self.meshNames[meshME]+=1
|
||||
self.meshNames[meshME] += 1
|
||||
else:
|
||||
if int(mesh.users) > 1:
|
||||
self.writeIndented("<%s DEF=\"ME_%s\" " % (ifStyle, meshME), 1)
|
||||
self.meshNames[meshME]=1
|
||||
self.meshNames[meshME] = 1
|
||||
else:
|
||||
self.writeIndented("<%s " % ifStyle, 1)
|
||||
|
||||
@@ -459,9 +460,9 @@ class x3d_class:
|
||||
is_smooth = True
|
||||
break
|
||||
if is_smooth == True:
|
||||
creaseAngle=(mesh.auto_smooth_angle)*(math.pi/180.0)
|
||||
creaseAngle = (mesh.auto_smooth_angle) * (math.pi / 180.0)
|
||||
# creaseAngle=(mesh.degr)*(math.pi/180.0)
|
||||
self.file.write("creaseAngle=\"%s\" " % (round(creaseAngle,self.cp)))
|
||||
self.file.write("creaseAngle=\"%s\" " % (round(creaseAngle, self.cp)))
|
||||
|
||||
#--- output textureCoordinates if UV texture used
|
||||
if mesh.uv_textures.active:
|
||||
@@ -508,7 +509,7 @@ class x3d_class:
|
||||
|
||||
self.file.write("\n")
|
||||
|
||||
def writeCoordinates(self, ob, mesh, meshName, EXPORT_TRI = False):
|
||||
def writeCoordinates(self, ob, mesh, meshName, EXPORT_TRI=False):
|
||||
# create vertex list and pre rotate -90 degrees X for VRML
|
||||
|
||||
if self.writingcoords == 0:
|
||||
@@ -516,7 +517,7 @@ class x3d_class:
|
||||
for face in mesh.faces:
|
||||
fv = face.vertices[:]
|
||||
|
||||
if len(fv)==3:
|
||||
if len(fv) == 3:
|
||||
self.file.write("%i %i %i -1, " % (fv[0], fv[1], fv[2]))
|
||||
else:
|
||||
if EXPORT_TRI:
|
||||
@@ -529,7 +530,7 @@ class x3d_class:
|
||||
else:
|
||||
#-- vertices
|
||||
# mesh.transform(ob.matrix_world)
|
||||
self.writeIndented("<Coordinate DEF=\"%s%s\" \n" % ("coord_",meshName), 1)
|
||||
self.writeIndented("<Coordinate DEF=\"%s%s\" \n" % ("coord_", meshName), 1)
|
||||
self.file.write("\t\t\t\tpoint=\"")
|
||||
for v in mesh.vertices:
|
||||
self.file.write("%.6f %.6f %.6f, " % v.co[:])
|
||||
@@ -570,14 +571,14 @@ class x3d_class:
|
||||
# XXX, 1 color per face, only
|
||||
self.file.write("%.3f %.3f %.3f, " % face.color1[:])
|
||||
self.file.write("\" />")
|
||||
self.writeIndented("\n",-1)
|
||||
self.writeIndented("\n", -1)
|
||||
|
||||
def writeMaterial(self, mat, matName, world):
|
||||
# look up material name, use it if available
|
||||
if matName in self.matNames:
|
||||
self.writeIndented("<Material USE=\"MA_%s\" />\n" % matName)
|
||||
self.matNames[matName]+=1
|
||||
return;
|
||||
self.matNames[matName] += 1
|
||||
return
|
||||
|
||||
self.matNames[matName] = 1
|
||||
|
||||
@@ -606,7 +607,7 @@ class x3d_class:
|
||||
self.writeIndented("ambientIntensity=\"%s\" " % (round(ambient, self.cp)))
|
||||
self.file.write("shininess=\"%s\" " % (round(shininess, self.cp)))
|
||||
self.file.write("transparency=\"%s\" />" % (round(transp, self.cp)))
|
||||
self.writeIndented("\n",-1)
|
||||
self.writeIndented("\n", -1)
|
||||
|
||||
def writeImageTexture(self, image):
|
||||
name = image.name
|
||||
@@ -617,12 +618,15 @@ class x3d_class:
|
||||
else:
|
||||
self.writeIndented("<ImageTexture DEF=\"%s\" " % self.cleanStr(name), 1)
|
||||
self.file.write("url=\"%s\" />" % filepath)
|
||||
self.writeIndented("\n",-1)
|
||||
self.writeIndented("\n", -1)
|
||||
self.texNames[name] = 1
|
||||
|
||||
def writeBackground(self, world, alltextures):
|
||||
if world: worldname = world.name
|
||||
else: return
|
||||
if world:
|
||||
worldname = world.name
|
||||
else:
|
||||
return
|
||||
|
||||
blending = world.use_sky_blend, world.use_sky_paper, world.use_sky_real
|
||||
|
||||
grd_triple = round_color(world.horizon_color, self.cp)
|
||||
@@ -698,10 +702,10 @@ class x3d_class:
|
||||
# export routine
|
||||
##########################################################
|
||||
|
||||
def export(self, scene, world, alltextures,\
|
||||
EXPORT_APPLY_MODIFIERS = False,\
|
||||
EXPORT_TRI= False,\
|
||||
):
|
||||
def export(self, scene, world, alltextures,
|
||||
EXPORT_APPLY_MODIFIERS=False,
|
||||
EXPORT_TRI=False,
|
||||
):
|
||||
|
||||
print("Info: starting X3D export to %r..." % self.filepath)
|
||||
self.writeHeader()
|
||||
@@ -710,8 +714,6 @@ class x3d_class:
|
||||
self.writeBackground(world, alltextures)
|
||||
self.writeFog(world)
|
||||
self.proto = 0
|
||||
|
||||
|
||||
# # COPIED FROM OBJ EXPORTER
|
||||
# if EXPORT_APPLY_MODIFIERS:
|
||||
# temp_mesh_name = '~tmp-mesh'
|
||||
@@ -726,36 +728,35 @@ class x3d_class:
|
||||
# if not containerMesh:
|
||||
# containerMesh = Mesh.New(temp_mesh_name)
|
||||
# --------------------------
|
||||
|
||||
|
||||
for ob_main in [o for o in scene.objects if o.is_visible(scene)]:
|
||||
# for ob_main in scene.objects.context:
|
||||
|
||||
free, derived = create_derived_objects(scene, ob_main)
|
||||
|
||||
if derived is None: continue
|
||||
if derived is None:
|
||||
continue
|
||||
|
||||
for ob, ob_mat in derived:
|
||||
# for ob, ob_mat in BPyObject.getDerivedObjects(ob_main):
|
||||
objType=ob.type
|
||||
objName=ob.name
|
||||
objType = ob.type
|
||||
objName = ob.name
|
||||
if objType == 'CAMERA':
|
||||
self.writeViewpoint(ob, ob_mat, scene)
|
||||
elif objType in ('MESH', 'CURVE', 'SURF', 'FONT') :
|
||||
elif objType in ('MESH', 'CURVE', 'SURF', 'FONT'):
|
||||
if EXPORT_APPLY_MODIFIERS or objType != 'MESH':
|
||||
me = ob.create_mesh(scene, EXPORT_APPLY_MODIFIERS, 'PREVIEW')
|
||||
else:
|
||||
me = ob.data
|
||||
|
||||
self.writeIndexedFaceSet(ob, me, ob_mat, world, EXPORT_TRI = EXPORT_TRI)
|
||||
self.writeIndexedFaceSet(ob, me, ob_mat, world, EXPORT_TRI=EXPORT_TRI)
|
||||
|
||||
# free mesh created with create_mesh()
|
||||
if me != ob.data:
|
||||
bpy.data.meshes.remove(me)
|
||||
|
||||
elif objType == 'LAMP':
|
||||
data= ob.data
|
||||
datatype=data.type
|
||||
data = ob.data
|
||||
datatype = data.type
|
||||
if datatype == 'POINT':
|
||||
self.writePointLight(ob, ob_mat, data, world)
|
||||
elif datatype == 'SPOT':
|
||||
@@ -785,27 +786,27 @@ class x3d_class:
|
||||
|
||||
def cleanup(self):
|
||||
self.file.close()
|
||||
self.texNames={}
|
||||
self.matNames={}
|
||||
self.indentLevel=0
|
||||
self.texNames = {}
|
||||
self.matNames = {}
|
||||
self.indentLevel = 0
|
||||
print("Info: finished X3D export to %r" % self.filepath)
|
||||
|
||||
def cleanStr(self, name, prefix='rsvd_'):
|
||||
"""cleanStr(name,prefix) - try to create a valid VRML DEF name from object name"""
|
||||
|
||||
newName=name[:]
|
||||
newName = name
|
||||
if len(newName) == 0:
|
||||
self.nNodeID+=1
|
||||
self.nNodeID += 1
|
||||
return "%s%d" % (prefix, self.nNodeID)
|
||||
|
||||
if newName in self.namesReserved:
|
||||
newName='%s%s' % (prefix,newName)
|
||||
newName = '%s%s' % (prefix, newName)
|
||||
|
||||
if newName[0].isdigit():
|
||||
newName='%s%s' % ('_',newName)
|
||||
newName = "%s%s" % ('_', newName)
|
||||
|
||||
for bad in [' ','"','#',"'",',','.','[','\\',']','{','}']:
|
||||
newName=newName.replace(bad,'_')
|
||||
for bad in [' ', '"', '#', "'", ', ', '.', '[', '\\', ']', '{', '}']:
|
||||
newName = newName.replace(bad, '_')
|
||||
return newName
|
||||
|
||||
def countIFSSetsNeeded(self, mesh, imageMap, sided):
|
||||
@@ -820,9 +821,9 @@ class x3d_class:
|
||||
o - split when faces only have 2 vertices * needs to be an IndexLineSet
|
||||
"""
|
||||
|
||||
imageNameMap={}
|
||||
faceMap={}
|
||||
nFaceIndx=0
|
||||
imageNameMap = {}
|
||||
faceMap = {}
|
||||
nFaceIndx = 0
|
||||
|
||||
if mesh.uv_textures.active:
|
||||
# if mesh.faceUV:
|
||||
@@ -831,27 +832,27 @@ class x3d_class:
|
||||
sidename = "two" if face.use_twoside else "one"
|
||||
|
||||
if sidename in sided:
|
||||
sided[sidename]+=1
|
||||
sided[sidename] += 1
|
||||
else:
|
||||
sided[sidename]=1
|
||||
sided[sidename] = 1
|
||||
|
||||
image = face.image
|
||||
if image:
|
||||
faceName="%s_%s" % (face.image.name, sidename);
|
||||
faceName = "%s_%s" % (face.image.name, sidename)
|
||||
try:
|
||||
imageMap[faceName].append(face)
|
||||
except:
|
||||
imageMap[faceName]=[face.image.name,sidename,face]
|
||||
imageMap[faceName] = [face.image.name, sidename, face]
|
||||
|
||||
if self.verbose > 2:
|
||||
for faceName in imageMap.keys():
|
||||
ifs=imageMap[faceName]
|
||||
ifs = imageMap[faceName]
|
||||
print("Debug: faceName=%s image=%s, solid=%s facecnt=%d" % \
|
||||
(faceName, ifs[0], ifs[1], len(ifs)-2))
|
||||
(faceName, ifs[0], ifs[1], len(ifs) - 2))
|
||||
|
||||
return len(imageMap)
|
||||
|
||||
def faceToString(self,face):
|
||||
def faceToString(self, face):
|
||||
|
||||
print("Debug: face.flag=0x%x (bitflags)" % face.flag)
|
||||
if face.sel:
|
||||
@@ -882,7 +883,7 @@ class x3d_class:
|
||||
# if c: break
|
||||
# return c
|
||||
|
||||
def meshToString(self,mesh):
|
||||
def meshToString(self, mesh):
|
||||
# print("Debug: mesh.hasVertexUV=%d" % mesh.vertexColors)
|
||||
print("Debug: mesh.faceUV=%d" % (len(mesh.uv_textures) > 0))
|
||||
# print("Debug: mesh.faceUV=%d" % mesh.faceUV)
|
||||
@@ -912,7 +913,7 @@ class x3d_class:
|
||||
if inc < 1:
|
||||
self.indentLevel = self.indentLevel + inc
|
||||
|
||||
spaces=""
|
||||
spaces = ""
|
||||
for x in range(self.indentLevel):
|
||||
spaces = spaces + "\t"
|
||||
self.file.write(spaces + s)
|
||||
@@ -924,6 +925,7 @@ class x3d_class:
|
||||
# Callbacks, needed before Main
|
||||
##########################################################
|
||||
|
||||
|
||||
def save(operator, context, filepath="",
|
||||
use_apply_modifiers=False,
|
||||
use_triangulate=False,
|
||||
@@ -955,4 +957,3 @@ def save(operator, context, filepath="",
|
||||
)
|
||||
|
||||
return {'FINISHED'}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user