diff options
author | Tom Musgrove <LetterRip@gmail.com> | 2006-03-11 13:51:06 +0300 |
---|---|---|
committer | Tom Musgrove <LetterRip@gmail.com> | 2006-03-11 13:51:06 +0300 |
commit | 7e857617bb9014e2892e34d257e8db4803d3fd68 (patch) | |
tree | 98ca3f5c63b5a9bfa0c69259d57ac5083b6c45bd /release | |
parent | 9af72012c841f45754fe1f459dbedc88efe154fa (diff) |
==scripts==
removing obsolete and redundant scripts from the repository
Diffstat (limited to 'release')
-rw-r--r-- | release/scripts/DirectXExporter.py | 456 | ||||
-rw-r--r-- | release/scripts/wrl2export.py | 1014 |
2 files changed, 0 insertions, 1470 deletions
diff --git a/release/scripts/DirectXExporter.py b/release/scripts/DirectXExporter.py deleted file mode 100644 index 9303683e269..00000000000 --- a/release/scripts/DirectXExporter.py +++ /dev/null @@ -1,456 +0,0 @@ -#!BPY - -""" Registration info for Blender menus: -Name: 'DirectX (.x)...' -Blender: 234 -Group: 'Export' -Submenu: 'Only mesh data...' mesh -Submenu: 'Animation(not armature yet)...' anim -Tip: 'Export to DirectX text file format' -""" - -__author__ = "Arben (Ben) Omari" -__url__ = ("blender", "elysiun", "Author's site, http://www.omariben.too.it") -__version__ = "1.0" - -__bpydoc__ = """\ -This script exports Blender uv-textured meshes with animation frame keys to -DirectX 7's text file format. - -Usage: - -Run the script and check console for possible warning messages. - -Supported:<br> - UV-textured meshes with animation frame (location, rotation) keys. - -Known issues:<br> - Some DX format viewers don't support Material names with dots -('.') in them. - -Notes:<br> - Check author's site or the elYsiun forum for a new beta version of the -DX exporter. -""" - - -# $Id$ -# -# DirectX.py version 1.0 -# Copyright (C) 2003 Arben OMARI -- omariarben@everyday.com -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# This script export meshes created with Blender in DirectX file format -# it exports meshes,materials,normals,texturecoords and and animations - -# Grab the latest version here :www.omariben.too.it - -import Blender -from Blender import Types, Object, NMesh, Material -#import string -from math import * - - - - -#*********************************************** -#*********************************************** -# EXPORTER -#*********************************************** -#*********************************************** - -class xExport: - def __init__(self, filename): - self.file = open(filename, "w") - - #*********************************************** - # Export animations - #*********************************************** - def exportAnim(self): - tex = [] - print "exporting ..." - self.writeHeader() - for name in Object.Get(): - obj = name.getData() - if type(obj) == Types.NMeshType : - - self.writeFrames(name, obj) - self.writeMeshcoord(name, obj ) - self.writeMeshMaterialList(name, obj, tex) - self.writeMeshNormals(name, obj) - self.writeMeshTextureCoords(name, obj) - self.file.write("}\n") - self.file.write("}\n") - self.writeAnimation(name, obj) - - self.writeEnd() - - #*********************************************** - # Export geometry - #*********************************************** - def exportTex(self): - tex = [] - print "exporting ..." - self.writeHeader() - for name in Object.Get(): - obj = name.getData() - if type(obj) == Types.NMeshType : - self.writeMeshcoord(name, obj ) - self.writeMeshMaterialList(name, obj, tex) - self.writeMeshNormals(name, obj) - self.writeMeshTextureCoords(name, obj) - self.file.write("}\n") - - self.writeEnd() - - #*********************************************** - #HEADER - #*********************************************** - def writeHeader(self): - self.file.write("xof 0302txt 0064\n") - self.file.write("\n") - self.file.write("Header{\n") - self.file.write("1;0;1;\n") - self.file.write("}\n") - - #*********************************************** - #CLOSE FILE - #*********************************************** - def writeEnd(self): - self.file.close() - print "... finished" - - - - #*********************************************** - #EXPORT TEXTURES - #*********************************************** - def writeTextures(self,name, tex): - mesh = name.data - for face in mesh.faces: - if face.image and face.image.name not in tex: - tex.append(face.image.name) - - - #*********************************************** - #EXPORT MESH DATA - #*********************************************** - def writeMeshcoord(self, name, obj ): - - self.file.write("Mesh Mesh_%s {\n" % (name.name)) - numfaces=len(obj.faces) - #POSITION - loc = name.getMatrix() - x = loc[3][0] - y = loc[3][1] - z = loc[3][2] - #VERTICES NUMBER - mesh = name.data - numvert = 0 - for face in mesh.faces: - numvert = numvert + len(face.v) - self.file.write("%s;\n" % (numvert)) - #VERTICES COORDINATES - counter = 0 - for face in mesh.faces: - counter += 1 - if counter == numfaces: - if len(face.v) == 4: - self.file.write("%s; %s; %s;,\n" % ((face.v[0].co[0] + x), face.v[0].co[1] + y, face.v[0].co[2] + z)) - self.file.write("%s; %s; %s;,\n" % ((face.v[1].co[0] + x), face.v[1].co[1] + y, face.v[1].co[2] + z)) - self.file.write("%s; %s; %s;,\n" % ((face.v[2].co[0] + x), face.v[2].co[1] + y, face.v[2].co[2] + z)) - self.file.write("%s; %s; %s;;\n" % ((face.v[3].co[0] + x), face.v[3].co[1] + y, face.v[3].co[2] + z)) - elif len(face.v) == 3 : - self.file.write("%s; %s; %s;,\n" % ((face.v[0].co[0] + x), face.v[0].co[1] + y, face.v[0].co[2] + z)) - self.file.write("%s; %s; %s;,\n" % ((face.v[1].co[0] + x), face.v[1].co[1] + y, face.v[1].co[2] + z)) - self.file.write("%s; %s; %s;;\n" % ((face.v[2].co[0] + x), face.v[2].co[1] + y, face.v[2].co[2] + z)) - - else : - if len(face.v) == 4: - self.file.write("%s; %s; %s;,\n" % ((face.v[0].co[0] + x), face.v[0].co[1] + y, face.v[0].co[2] + z)) - self.file.write("%s; %s; %s;,\n" % ((face.v[1].co[0] + x), face.v[1].co[1] + y, face.v[1].co[2] + z)) - self.file.write("%s; %s; %s;,\n" % ((face.v[2].co[0] + x), face.v[2].co[1] + y, face.v[2].co[2] + z)) - self.file.write("%s; %s; %s;,\n" % ((face.v[3].co[0] + x), face.v[3].co[1] + y, face.v[3].co[2] + z)) - elif len(face.v) == 3: - self.file.write("%s; %s; %s;,\n" % ((face.v[0].co[0] + x), face.v[0].co[1] + y, face.v[0].co[2] + z)) - self.file.write("%s; %s; %s;,\n" % ((face.v[1].co[0] + x), face.v[1].co[1] + y, face.v[1].co[2] + z)) - self.file.write("%s; %s; %s;,\n" % ((face.v[2].co[0] + x), face.v[2].co[1] + y, face.v[2].co[2] + z)) - - - - #FACES NUMBER - - self.file.write("%s;\n" % (numfaces)) - #FACES INDEX - numface=len(obj.faces) - coun,counter = 0, 0 - for face in mesh.faces : - coun += 1 - if coun == numface: - if len(face.v) == 3: - self.file.write("3; %s; %s; %s;;\n" % (counter, counter + 1, counter + 2)) - counter += 3 - elif len(face.v) == 4: - self.file.write("4; %s; %s; %s; %s;;\n" % (counter, counter + 1, counter + 2, counter + 3)) - counter += 4 - elif len(face.v) == 2: - print "WARNING:the mesh has faces with less then 3 vertices" - else: - - if len(face.v) == 3: - self.file.write("3; %s; %s; %s;,\n" % (counter, counter + 1, counter + 2)) - counter += 3 - elif len(face.v) == 4: - self.file.write("4; %s; %s; %s; %s;,\n" % (counter, counter + 1, counter + 2, counter + 3)) - counter += 4 - elif len(face.v) == 2: - print "WARNING:the mesh has faces with less then 3 vertices" - - - - - - #*********************************************** - #MESH MATERIAL LIST - #*********************************************** - def writeMeshMaterialList(self, name, obj, tex): - self.file.write(" MeshMaterialList {\n") - #HOW MANY MATERIALS ARE USED - count = 0 - for mat in Material.Get(): - count+=1 - self.file.write(" %s;\n" % (len(tex) + count)) - #HOW MANY FACES IT HAS - numfaces=len(obj.faces) - self.file.write(" %s;\n" % (numfaces)) - ##MATERIALS INDEX FOR EVERY FACE - counter = 0 - for face in obj.faces : - counter += 1 - mater = face.materialIndex - if counter == numfaces: - if face.image and face.image.name in tex : - self.file.write(" %s;;\n" % (tex.index(face.image.name) + count)) - else : - self.file.write(" %s;;\n" % (mater)) - else : - if face.image and face.image.name in tex : - self.file.write(" %s,\n" % (tex.index(face.image.name) + count)) - else : - self.file.write(" %s,\n" % (mater)) - - ##MATERIAL NAME - for mat in Material.Get(): - self.file.write(" Material") - for a in range(0,len(mat.name)): - if mat.name[a] == ".": - print "WARNING:the material " + mat.name + " contains '.' within.Many viewers may refuse to read the exported file" - self.file.write(" %s "% (mat.name)) - self.file.write("{\n") - self.file.write(" %s; %s; %s;" % (mat.R, mat.G, mat.B)) - self.file.write("%s;;\n" % (mat.alpha)) - self.file.write(" %s;\n" % (mat.spec)) - self.file.write(" %s; %s; %s;;\n" % (mat.specR, mat.specG, mat.specB)) - self.file.write(" 0.0; 0.0; 0.0;;\n") - self.file.write(" }\n") - - for mat in tex: - self.file.write(" Material Mat") - self.file.write("%s "% (len(tex))) - self.file.write("{\n") - self.file.write(" 1.0; 1.0; 1.0; 1.0;;\n") - self.file.write(" 1.0;\n") - self.file.write(" 1.0; 1.0; 1.0;;\n") - self.file.write(" 0.0; 0.0; 0.0;;\n") - self.file.write(" TextureFilename {\n") - self.file.write(' "%s" ;'% (face.image.name)) - self.file.write(" }\n") - self.file.write(" }\n") - self.file.write(" }\n") - #*********************************************** - #MESH NORMALS - #*********************************************** - def writeMeshNormals(self,name,obj): - self.file.write(" MeshNormals {\n") - #VERTICES NUMBER - numvert=len(obj.verts) - self.file.write("%s;\n" % (numvert)) - #VERTICES NORMAL - counter = 0 - for vert in obj.verts: - counter += 1 - if counter == numvert: - self.file.write("%s; %s; %s;;\n" % (vert.no[0], vert.no[1], vert.no[2])) - else : - self.file.write("%s; %s; %s;,\n" % (vert.no[0], vert.no[1], vert.no[2])) - #FACES NUMBER - numfaces=len(obj.faces) - self.file.write("%s;\n" % (numfaces)) - #FACES INDEX - counter = 0 - for face in obj.faces : - counter += 1 - if counter == numfaces: - if len(face.v) == 3: - self.file.write("3; %s; %s; %s;;\n" % (face[0].index, face[1].index, face[2].index)) - elif len(face.v) == 4: - self.file.write("4; %s; %s; %s; %s;;\n" % (face[0].index, face[1].index, face[2].index, face[3].index)) - else: - if len(face.v) == 3: - self.file.write("3; %s; %s; %s;,\n" % (face[0].index, face[1].index, face[2].index)) - elif len(face.v) == 4 : - self.file.write("4; %s; %s; %s; %s;,\n" % (face[0].index, face[1].index, face[2].index, face[3].index)) - self.file.write("}\n") - #*********************************************** - #MESH TEXTURE COORDS - #*********************************************** - def writeMeshTextureCoords(self, name, obj): - if obj.hasFaceUV(): - self.file.write("MeshTextureCoords {\n") - #VERTICES NUMBER - mesh = name.data - numvert = 0 - for face in mesh.faces: - numvert = numvert + len(face.v) - self.file.write("%s;\n" % (numvert)) - #UV COORDS - counter = -1 - for face in mesh.faces: - counter += 1 - if len(face.v) == 4: - self.file.write("%s;%s;,\n" % (mesh.faces[counter].uv[0][0], -mesh.faces[counter].uv[0][1])) - self.file.write("%s;%s;,\n" % (mesh.faces[counter].uv[1][0], -mesh.faces[counter].uv[1][1])) - self.file.write("%s;%s;,\n" % (mesh.faces[counter].uv[2][0], -mesh.faces[counter].uv[2][1])) - self.file.write("%s;%s;,\n" % (mesh.faces[counter].uv[3][0], -mesh.faces[counter].uv[3][1])) - elif len(face.v) == 3: - self.file.write("%s;%s;,\n" % (mesh.faces[counter].uv[0][0], -mesh.faces[counter].uv[0][1])) - self.file.write("%s;%s;,\n" % (mesh.faces[counter].uv[1][0], -mesh.faces[counter].uv[1][1])) - self.file.write("%s;%s;,\n" % (mesh.faces[counter].uv[2][0], -mesh.faces[counter].uv[2][1])) - - self.file.write("}\n") - - #*********************************************** - #FRAMES - #*********************************************** - def writeFrames(self, name, obj): - matx = name.getMatrix() - self.file.write("Frame Fr_") - self.file.write("%s {\n" % (obj.name)) - self.file.write(" FrameTransformMatrix {\n") - self.file.write(" %s,%s,%s,%s,\n" % - (round(matx[0][0],6),round(matx[0][1],6),round(matx[0][2],6),round(matx[0][3],6))) - self.file.write(" %s,%s,%s,%s,\n" % - (round(matx[1][0],6),round(matx[1][1],6),round(matx[1][2],6),round(matx[1][3],6))) - self.file.write(" %s,%s,%s,%s,\n" % - (round(matx[2][0],6),round(matx[2][1],6),round(matx[2][2],6),round(matx[2][3],6))) - self.file.write(" %s,%s,%s,%s;;\n" % - (round(matx[3][0],6),round(matx[3][1],6),round(matx[3][2],6),round(matx[3][3],6))) - self.file.write(" }\n") - #*********************************************** - #WRITE ANIMATION KEYS - #*********************************************** - def writeAnimation(self, name, obj): - startFr = Blender.Get('staframe') - endFr = Blender.Get('endframe') - self.file.write("AnimationSet animset_") - self.file.write("%s {\n" % (obj.name)) - self.file.write(" Animation anim_") - self.file.write("%s { \n" % (obj.name)) - self.file.write(" {Fr_") - self.file.write("%s }\n" % (obj.name)) - self.file.write(" AnimationKey { \n") - self.file.write(" 0;\n") - self.file.write(" %s; \n" % (endFr)) - for fr in range(startFr,endFr + 1) : - self.file.write(" %s; " % (fr)) - self.file.write("4; ") - Blender.Set('curframe',fr) - rot = name.rot - rot_x = rot[0] - rot_y = rot[1] - rot_z = rot[2] - quat = self.euler2quat(rot_x,rot_y,rot_z) - self.file.write("%s, %s, %s,%s;;" % - (quat[0],quat[1],quat[2],quat[3])) - if fr == endFr: - self.file.write(";\n") - else: - self.file.write(",\n") - self.file.write(" }\n") - self.file.write(" AnimationKey { \n") - self.file.write(" 2;\n") - self.file.write(" %s; \n" % (endFr)) - for fr in range(startFr,endFr + 1) : - self.file.write(" %s; " % (fr)) - self.file.write("3; ") - Blender.Set('curframe',fr) - loc = name.loc - self.file.write("%s, %s, %s;;" % - (loc[0],loc[1],loc[2])) - if fr == endFr: - self.file.write(";\n") - else: - self.file.write(",\n") - self.file.write(" }\n") - self.file.write(" AnimationKey { \n") - self.file.write(" 1;\n") - self.file.write(" %s; \n" % (endFr)) - for fr in range(startFr,endFr + 1) : - self.file.write(" %s; " % (fr)) - self.file.write("3; ") - Blender.Set('curframe',fr) - size = name.size - self.file.write("%s, %s, %s;;" % - (size[0],size[1],size[2])) - if fr == endFr: - self.file.write(";\n") - else: - self.file.write(",\n") - self.file.write(" }\n") - self.file.write(" }\n") - self.file.write(" }\n") - - def euler2quat(self,rot_x,rot_y,rot_z): - c_x = cos(rot_x / 2) - c_y = cos(rot_y / 2) - c_z = cos(rot_z / 2) - - s_x = sin(rot_x / 2) - s_y = sin(rot_y / 2) - s_z = sin(rot_z / 2) - - cy_cz = c_y * c_z - sy_sz = s_y * s_z - - quat_w = c_x * cy_cz - s_x * sy_sz - quat_x = s_x * cy_cz + c_x * sy_sz - quat_y = c_x * s_y * c_z - s_x * c_y * s_z - quat_z = c_x * c_y * s_z + s_x * s_y * c_z - - return(quat_w,quat_x,quat_y,quat_z) - -#*********************************************** -# MAIN -#*********************************************** - - -def my_callback(filename): - if filename.find('.x', -2) <= 0: filename += '.x' # add '.x' if the user didn't - xexport = xExport(filename) - arg = __script__['arg'] - if arg == 'anim': - xexport.exportAnim() - else: - xexport.exportTex() - -fname = Blender.sys.makename(ext = ".x") -Blender.Window.FileSelector(my_callback, "Export DirectX",fname) diff --git a/release/scripts/wrl2export.py b/release/scripts/wrl2export.py deleted file mode 100644 index 6b0ef55b81b..00000000000 --- a/release/scripts/wrl2export.py +++ /dev/null @@ -1,1014 +0,0 @@ -#!BPY -""" Registration info for Blender menus: -Name: 'VRML 97 (old version)...' -Blender: 232 -Group: 'Export' -Submenu: 'All Objects...' all -Submenu: 'Selected Objects...' selected -Tooltip: 'Old version of VRML2 exporter, please try the newer one' -""" - -__author__ = ("Rick Kimball", "Ken Miller", "Steve Matthews") -__url__ = ["blender", "elysiun", -"Author's (Rick) homepage, http://kimballsoftware.com/blender", -"Show your VRML world at vrmlworld.net, http://vrmlworld.net"] -__version__ = "2004/01/19" - -__bpydoc__ = """\ -This script exports to VRML 2.0 format. - -Usage: - -Run this script from "File->Export" menu. A pop-up will ask whether you -want to export only selected or all relevant objects. - -Known issues:<br> - Doesn't handle multiple materials (don't use material indices);<br> - Doesn't handle multiple UV textures on a single mesh (create a mesh -for each texture);<br> - Material colors need work;<br> - Spotlight softness needs work;<br> - Can't get the texture array associated with material * not the UV ones;<br> - Can't set smoothing, crease angle and mesh smoothing * setting not - accessible. -""" - - -# $Id$ -# -#------------------------------------------------------------------------ -# VRML2 exporter for blender 2.28a or above -# -# Source: http://blender.kimballsoftware.com/ -# -# Authors: Rick Kimball with much inspiration -# from the forum at www.elysiun.com -# and irc://irc.freenode.net/blenderchat -# Ken Miller and Steve Matthews (Added Camera Support) -# -# ***** BEGIN GPL LICENSE BLOCK ***** -# -# Copyright (C) 2003,2004: Rick Kimball rick@vrmlworld.net -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software Foundation, -# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -# -# ***** END GPL LICENCE BLOCK ***** -# -# To use script: -# 1.) load this file in the text window. -# (press SHIFT+F11, Open New via Datablock button) -# 2.) make sure your mouse is over the text edit window and -# run this script. (press ALT+P) -# Or: -# copy to the scripts directory and it will appear in the -# export list. (Needs 2.32 or higher) -# -# Notes: -# a.) output filename is same as current blender file with .wrl extension -# b.) error messages go to the Blender DOS console window -# -# The latest version of this python export script: -# http://blender.kimballsoftware.com/ -# -# If you like this script, try using http://vrmlworld.net/ -# to show off your VRML world. -# -# 2004-01-19 by Rick Kimball <rick@vrmlworld.net> -# o added sub menus and file selector dialog -# -# 2004-01-17 by Rick Kimball <rick@vrmlworld.net> -# o add meta comments so script will appear in export menu list -# -# 2003-11-01 by Rick Kimball <rick@vrmlworld.net> -# o fixed issues related to Lamp object and 2.28a API. -# -# 2003-07-19 by Rick Kimball <rick@vrmlworld.net> -# o made compatible with new Python API in 2.28 -# -# 2003-01-16 by Ken Miller - with math help from Steve Matthews :) -# o Added support for exporting cameras out of Blender -# o Sets the name of the camera as the object name -# o sets the description of the camera as the object name, -# which should be modified to something meaningful -# o sets the position and orientation -# -# 2003-01-19 Rick Kimball <rick@vrmlworld.net> -# o Added Support For PointLight, SpotLight and DirectionalLight using Lamps -# o Creates multi singlesided or doublesided IFS -# o Creates IndexedLineSets if DrawTypes is WIRE instead of Shaded -# -# 2003-02-03 Rick Kimball <rick@vrmlworld.net> -# o attempts to catch exceptions for empty objects -# -# 2003-02-04 Rick Kimball <rick@vrmlworld.net> -# o fixed file overwrite problem when blender filename is all uppercase -# -# 2003-02-08 Rick Kimball <rick@vrmlworld.net> -# o cleanStr() creates valid VRML DEF names even if object.name -# is zero length or uses VRML reserved names or characters -# -#------------------------------------------------------------------------ -# Known Issue: -# o doesn't handle multiple materials (don't use material indices) -# o doesn't handle multiple UV textures on a single mesh. (create a mesh for each texture) -# o material colors need work -# o spotlight softness needs work -# o can't get the texture array associated with material * not the UV ones -# o can't set smoothing, crease angle and mesh smoothing * setting not accesible -# -# Still Todo: -# -# - Support for material indexes -# - Automatically Split IFS when multiple UV textures found * warning only now -# - Automatically Split IFS when combination of single vs double sided -# - Automatically Split IFS when face with only 2 vertices is found should be an ILS -# - Export common coordinate map for split IFS -# - Intelligent color array vs color index -# - Support more blender objects: World -# - Figure out how to output Animation -# - Add GUI to control the following: -# o All/Layer/Object output radio button -# o Color per vertex toggle yes/no -# o Complex/Simple VRML output radio button -# o Compressed/Uncompressed output radio button -# o Decimal precision dropdown 1,2,3,4,5,6 -# o IFS/Elevation Grid output radio button -# o Normals output toggle yes/no -# o Proto output toggle yes/no -# o Verbose console progress - -import Blender -from Blender import NMesh, Lamp -import math - - -#-- module constants -radD=math.pi/180.0 -rad90=90.0*radD # for rotation -rad30=30.0*radD # default crease angle -ARG='' - -#------------------------------------------------------------------------ -#-- utility functions and classes -- -#------------------------------------------------------------------------ -def rad2deg(v): - return round(v*180.0/math.pi,4) - -def deg2rad(v): - return (v*math.pi)/180.0; - -class DrawTypes: - """Object DrawTypes enum values - BOUNDS - draw only the bounding box of the object - WIRE - draw object as a wire frame - SOLID - draw object with flat shading - SHADED - draw object with OpenGL shading -""" - BOUNDBOX = 1 - WIRE = 2 - SOLID = 3 - SHADED = 4 - TEXTURE = 5 - -#------------------------------------------------------ -# the Blender.Object class seems to be missing this... -#------------------------------------------------------ -if not hasattr(Blender.Object,'DrawTypes'): - Blender.Object.DrawTypes = DrawTypes() - -#------------------------------------------------------------------------ -#-- VRML2Export -- -#------------------------------------------------------------------------ -class VRML2Export: - #------------------------------------------------------------------------ - def __init__(self, filename): - #--- public you can change these --- - self.verbose=1 # 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.ambientIntensity=.2 - self.defCreaseAngle=rad30 - self.smooth=0 - - #--- class private don't touch --- - self.texNames={} # dictionary of textureNames - self.matNames={} # dictionary of materiaNames - self.indentLevel=0 # keeps track of current indenting - self.filename=filename - self.file = open(filename, "w") - self.bNav=0 - self.nNodeID=0 - self.VRMLReserved=[ "Anchor","Appearance","Anchor","AudioClip","Background", - "Billboard", "Box", "Collision", "Color", "ColorInterpolator", - "Cone", "Coordinate", "CoordinateInterpolator", "Cylinder", - "CylinderSensor", "DirectionalLight", "ElevationGrid", - "Extrustion", "Fog", "FontStyle", "Group", "ImageTexture", - "IndexedFaceSet", "IndexedLineSet", "Inline", "LOD", - "Material", "MovieTexture", "NavigationInfo", "Normal", - "NormalInterpolator","OrientationInterpolator", "PixelTexture", - "PlaneSensor", "PointLight", "PointSet", "PositionInterpolator", - "ProxmimitySensor", "ScalarInterpolator", "Script", "Shape", - "Sound", "Sphere", "SphereSensor", "SpotLight", "Switch", - "Text", "TextureCoordinate", "TextureTransform", "TimeSensor", - "TouchSensor", "Transform", "Viewpoint", "VisibilitySensor", - "WorldInfo" - ] - - #------------------------------------------------------------------------ - # writeHeader, export file, cleanup - #------------------------------------------------------------------------ - def writeHeader(self): - self.file.write("#VRML V2.0 utf8\n") - self.file.write("# modeled using blender3d http://blender.org/$\n") - self.file.write("# exported using wrl2export.py version $Revision$\n") - self.file.write("# get latest exporter at http://kimballsoftware.com/blender/\n\n") - - def export(self, scene): - print "Info: starting VRML2 export to " + self.filename + "..." - - self.writeHeader() - theObjects = [] - if ARG == 'selected': - theObjects = Blender.Object.GetSelected() - else: - theObjects = scene.getChildren() - - for object in theObjects: - try: - objType=object.getType() - - if objType == "Mesh": - self.writeIndexedFaceSet(object, normals = 0) - elif objType == "Camera": - self.writeCameraInfo(object) - elif objType == "Lamp": - # if there is a lamp then we probably want to turn off the headlight - if self.bNav == 0: - self.writeNavigationInfo() - self.bNav=1 - #endif - - lamp=Lamp.Get(object.data.getName()) - try: - lampType=lamp.getType() - - if lampType == Lamp.Types.Lamp: - self.writePointLight(object, lamp) - elif lampType == Lamp.Types.Spot: - self.writeSpotLight(object, lamp) - elif lampType == Lamp.Types.Sun: - self.writeDirectionalLight(object, lamp) - else: - self.writeDirectionalLight(object, lamp) - #endif - except AttributeError: - print "Error: Unable to get type info for %s" % object.name - else: - print "Info: Ignoring [%s], object type [%s] not handle yet" % \ - (object.name,object.getType()) - #endif - except ValueError: - print "Error: object named %s has problem with accessing an attribute" % object.name - #end try - #endfor - self.cleanup() - - def cleanup(self): - self.file.close() - self.texNames={} - self.matNames={} - self.indentLevel=0 - print "Info: finished VRML2 export to %s\n" % self.filename - - #------------------------------------------------------------------------ - # Writes out camera info as a viewpoint - # Handles orientation, position - # Use camera object name to set description - #------------------------------------------------------------------------ - def writeCameraInfo(self, object): - if self.verbose > 0: - print "Info: exporting camera named="+object.name - #endif - - self.writeIndented("DEF %s Viewpoint {\n" % (self.cleanStr(object.name)), 1) - - self.writeIndented("description \"%s\" \n" % (object.name)) - - # get the camera location, subtract 90 degress from X to orient like VRML does - loc = self.rotatePointForVRML(object.loc) - rot = [object.RotX - 1.57, object.RotY, object.RotZ] - nRot = self.rotatePointForVRML(rot) - - # convert to Quaternion and to Angle Axis - Q = self.eulerToQuaternions(nRot[0], nRot[1], nRot[2]) - Q1 = self.multiplyQuaternions(Q[0], Q[1]) - Qf = self.multiplyQuaternions(Q1, Q[2]) - angleAxis = self.quaternionToAngleAxis(Qf) - - # write orientation statement - self.writeIndented("orientation %3.2f %3.2f %3.2f %3.2f\n" % - (angleAxis[0], angleAxis[1], -angleAxis[2], angleAxis[3])) - - # write position statement - self.writeIndented("position %3.2f %3.2f %3.2f\n" % - (loc[0], loc[1], loc[2])) - - self.writeIndented("} # Viewpoint\n", -1) - - self.writeIndented("\n") - - #------------------------------------------------------------------------ - def writeIndexedFaceSet(self, object, normals = 0): - if self.verbose > 0: - print "Info: exporting mesh named=["+object.name+"]" - #endif - - imageMap={} # set of used images - sided={} # 'one':cnt , 'two':cnt - vColors={} # 'multi':1 - - mesh=object.getData() - - nIFSCnt=self.countIFSSetsNeeded(mesh, imageMap, sided, vColors) - - meshName = self.cleanStr(object.name) - - if nIFSCnt > 1: - self.writeIndented("DEF %s%s Group {\n" % ("G_", meshName),1) - self.writeIndented("children [\n",1) - #endif - - if self.verbose > 0: - print "Debug: [%s] has %d UV Textures" % (object.name, nIFSCnt) - #endif - - if sided.has_key('two') and sided['two'] > 0: - bTwoSided=1 - else: - bTwoSided=0 - - self.writeIndented("DEF %s Shape {\n" % meshName,1) - - # show script debugging info - if self.verbose > 1: - self.meshToString(mesh) - print "Debug: mesh.faces[" - for face in mesh.faces: - self.faceToString(face) - #endfor - print "Debug: ]" - #endif - - maters=mesh.materials - hasImageTexture=0 - - if len(maters) > 0 or mesh.hasFaceUV(): - self.writeIndented("appearance Appearance {\n", 1) - - # right now this script can only handle a single material per mesh. - if len(maters) >= 1: - mat=Blender.Material.Get(maters[0].name) - self.writeMaterial(mat, self.cleanStr(maters[0].name,'mat_')) - if len(maters) > 1: - print "Warning: mesh named %s has multiple materials" % meshName - print "Warning: only one material per object handled" - #endif - else: - self.writeIndented("material NULL\n") - #endif - - #-- textures - if mesh.hasFaceUV(): - for face in mesh.faces: - if (hasImageTexture == 0) and (face.image): - self.writeImageTexture(face.image.name) - hasImageTexture=1 # keep track of face texture - #endif - #endfor - #endif - - self.writeIndented("} # Appearance\n", -1) - #endif - - #------------------------------------------------------------------- - #-- - #-- IndexedFaceSet or IndexedLineSet - # - - # check if object is wireframe only - if object.drawType == Blender.Object.DrawTypes.WIRE: - # user selected WIRE=2 on the Drawtype=Wire on (F9) Edit page - ifStyle="IndexedLineSet" - else: - # user selected BOUNDS=1, SOLID=3, SHARED=4, or TEXTURE=5 - ifStyle="IndexedFaceSet" - #endif - - self.writeIndented("geometry %s {\n" % ifStyle, 1) - if object.drawType != Blender.Object.DrawTypes.WIRE: - if bTwoSided == 1: - self.writeIndented("solid FALSE # two sided\n") - else: - self.writeIndented("solid TRUE # one sided\n") - #endif - #endif - - #--- - #--- output coordinates - self.writeCoordinates(object, mesh, meshName) - - if object.drawType != Blender.Object.DrawTypes.WIRE: - #--- - #--- output textureCoordinates if UV texture used - if mesh.hasFaceUV(): - if hasImageTexture == 1: - self.writeTextureCoordinates(mesh) - if vColors.has_key('multi'): - self.writeVertexColors(mesh) # experiment - #endif - else: - self.writeFaceColors(mesh) - #endif hasImageTexture - #endif hasFaceUV - - # TBD: figure out how to get this properly - if self.smooth: - creaseAngle=self.defCreaseAngle; - self.writeIndented("creaseAngle %s\n" % creaseAngle) - else: - self.writeIndented("creaseAngle 0.0 # in radians\n") - #endif mesh.smooth - #endif WIRE - - #--- output vertexColors - if mesh.hasVertexColours() and vColors.has_key('multi'): - self.writeVertexColors(mesh) - #endif - - #--- output closing braces - self.writeIndented("} # %s\n" % ifStyle, -1) - self.writeIndented("} # Shape\n", -1) - - if nIFSCnt > 1: - self.writeIndented("] # children\n", -1) - self.writeIndented("} # Group\n", -1) - #endif - - self.writeIndented("\n") - - #------------------------------------------------------------------------ - def writeCoordinates(self, object, mesh, meshName): - #-- vertices - self.writeIndented("coord DEF %s%s Coordinate {\n" % ("coord_",meshName), 1) - self.writeIndented("point [\n", 1) - meshVertexList = mesh.verts - - # create vertex list and pre rotate -90 degrees X for VRML - mm=object.getMatrix() - for vertex in meshVertexList: - v=self.rotVertex(mm, vertex); - self.writeIndented("%s %s %s,\n" % - (round(v[0],self.vp), - round(v[1],self.vp), - round(v[2],self.vp) )) - #endfor - self.writeIndented("] # point\n", -1) - self.writeIndented("} # Coordinate\n", -1) - - self.writeIndented("coordIndex [\n", 1) - coordIndexList=[] - for face in mesh.faces: - cordStr="" - for i in range(len(face)): - indx=meshVertexList.index(face[i]) - cordStr = cordStr + "%s, " % indx - #endfor - self.writeIndented(cordStr + "-1,\n") - #endfor - self.writeIndented("] # coordIndex\n", -1) - - #------------------------------------------------------------------------ - def writeTextureCoordinates(self, mesh): - texCoordList=[] - texIndexList=[] - j=0 - - for face in mesh.faces: - for i in range(len(face)): - texIndexList.append(j) - texCoordList.append(face.uv[i]) - j=j+1 - #endfor - texIndexList.append(-1) - #endfor - - self.writeIndented("texCoord TextureCoordinate {\n", 1) - self.writeIndented("point [\n", 1) - for i in range(len(texCoordList)): - self.writeIndented("%s %s," % - (round(texCoordList[i][0],self.tp), - round(texCoordList[i][1],self.tp))+"\n") - #endfor - self.writeIndented("] # point\n", -1) - self.writeIndented("} # texCoord\n", -1) - - self.writeIndented("texCoordIndex [\n", 1) - texIndxStr="" - for i in range(len(texIndexList)): - texIndxStr = texIndxStr + "%d, " % texIndexList[i] - if texIndexList[i]==-1: - self.writeIndented(texIndxStr + "\n") - texIndxStr="" - #endif - #endfor - self.writeIndented("] # texCoordIndex\n", -1) - - #------------------------------------------------------------------------ - def writeFaceColors(self, mesh): - self.writeIndented("colorPerVertex FALSE\n") - self.writeIndented("color Color {\n",1) - self.writeIndented("color [\n",1) - - for face in mesh.faces: - if face.col: - c=face.col[0] - if self.verbose > 1: - print "Debug: face.col r=%d g=%d b=%d" % (c.r, c.g, c.b) - #endif - - aColor = self.rgbToFS(c) - self.writeIndented("%s,\n" % aColor) - #endfor - - self.writeIndented("] # color\n",-1) - self.writeIndented("} # Color\n",-1) - - #------------------------------------------------------------------------ - def writeVertexColors(self, mesh): - self.writeIndented("colorPerVertex TRUE\n") - self.writeIndented("color Color {\n",1) - self.writeIndented("color [\n",1) - - for i in range(len(mesh.verts)): - c=self.getVertexColorByIndx(mesh,i) - if self.verbose > 1: - print "Debug: vertex[%d].col r=%d g=%d b=%d" % (i, c.r, c.g, c.b) - #endif - - aColor = self.rgbToFS(c) - self.writeIndented("%s,\n" % aColor) - #endfor - - self.writeIndented("] # color\n",-1) - self.writeIndented("} # Color\n",-1) - - #------------------------------------------------------------------------ - def writeMaterial(self, mat, matName): - # look up material name, use it if available - if self.matNames.has_key(matName): - self.writeIndented("material USE %s\n" % matName) - self.matNames[matName]+=1 - return; - #endif - - self.matNames[matName]=1 - - ambient = mat.amb - diffuseR, diffuseG, diffuseB = mat.rgbCol[0], mat.rgbCol[1],mat.rgbCol[2] - emisR, emisG, emisB = diffuseR*mat.emit, diffuseG*mat.emit, diffuseB*mat.emit - shininess = mat.hard/255.0 - specR = mat.specCol[0] - specG = mat.specCol[1] - specB = mat.specCol[2] - transp = 1-mat.alpha - - self.writeIndented("material DEF %s Material {\n" % matName, 1) - self.writeIndented("diffuseColor %s %s %s" % - (round(diffuseR,self.cp), round(diffuseG,self.cp), round(diffuseB,self.cp)) + - "\n") - self.writeIndented("ambientIntensity %s" % - (round(ambient,self.cp))+ - "\n") - self.writeIndented("specularColor %s %s %s" % - (round(specR,self.cp), round(specG,self.cp), round(specB,self.cp)) + - "\n" ) - self.writeIndented("emissiveColor %s %s %s" % - (round(emisR,self.cp), round(emisG,self.cp), round(emisB,self.cp)) + - "\n" ) - self.writeIndented("shininess %s" % - (round(shininess,self.cp)) + - "\n" ) - self.writeIndented("transparency %s" % - (round(transp,self.cp)) + - "\n") - self.writeIndented("} # Material\n",-1) - - #------------------------------------------------------------------------ - def writeImageTexture(self, name): - if self.texNames.has_key(name): - self.writeIndented("texture USE %s\n" % self.cleanStr(name)) - self.texNames[name] += 1 - return - else: - self.writeIndented("texture DEF %s ImageTexture {\n" % self.cleanStr(name), 1) - self.writeIndented("url \"%s\"\n" % name) - self.writeIndented("} # ImageTexture \n",-1) - self.texNames[name] = 1 - #endif - - #------------------------------------------------------------------------ - def writeSpotLight(self, object, lamp): - safeName = self.cleanStr(object.name) - - # compute cutoff and beamwidth - intensity=min(lamp.energy/1.5,1.0) # TBD: figure out the right value - - beamWidth=deg2rad(lamp.spotSize)*.5; - cutOffAngle=beamWidth*.99 - - (dx,dy,dz)=self.computeDirection(object) - # note -dx seems to equal om[3][0] - # note -dz seems to equal om[3][1] - # note dy seems to equal om[3][2] - om = object.getMatrix() - - location=self.rotVertex(om, (0,0,0)); - radius = lamp.dist*math.cos(beamWidth) - self.writeIndented("DEF %s SpotLight {\n" % safeName,1) - self.writeIndented("radius %s\n" % radius ) - self.writeIndented("intensity %s\n" % intensity ) - self.writeIndented("beamWidth %s # lamp.spotSize %s\n" % (beamWidth, lamp.spotSize) ) - self.writeIndented("cutOffAngle %s # lamp.spotBlend %s\n" % (cutOffAngle, lamp.spotBlend)) - self.writeIndented("direction %s %s %s # lamp.RotX=%s RotY=%s RotZ=%s\n" % \ - (round(dx,3),round(dy,3),round(dz,3), - round(rad2deg(object.RotX),3), - round(rad2deg(object.RotY),3), - round(rad2deg(object.RotZ),3))) - self.writeIndented("location %s %s %s\n" % (round(location[0],3), - round(location[1],3), - round(location[2],3))) - self.writeIndented("} # SpotLight\n",-1) - - # export a cone that matches the spotlight in verbose mode - if self.verbose > 1: - self.writeIndented("#generated visible spotlight cone\n") - self.writeIndented("Transform { # Spotlight Cone\n",1) - self.writeIndented("translation %s %s %s\n" % (round(location[0],3), - round(location[1],3), - round(location[2],3))) - rot = [object.RotX, object.RotY, object.RotZ] - nRot = self.rotatePointForVRML(rot) - - # convert to Quaternion and to Angle Axis - Q = self.eulerToQuaternions(nRot[0], nRot[1], nRot[2]) - Q1 = self.multiplyQuaternions(Q[0], Q[1]) - Qf = self.multiplyQuaternions(Q1, Q[2]) - angleAxis = self.quaternionToAngleAxis(Qf) - - # write orientation statement - self.writeIndented("rotation %3.2f %3.2f %3.2f %3.2f\n" % - (angleAxis[0], angleAxis[1], -angleAxis[2], angleAxis[3])) - - self.writeIndented("children [\n",1) - - ch=radius - br=ch*math.sin(beamWidth) - self.writeIndented("Transform {\n",1) - self.writeIndented("translation 0 -%s 0\n" % (ch/2)) - self.writeIndented("children ") - self.writeIndented("Collision {\n",1) - self.writeIndented("collide FALSE children Shape {\n",1) - self.writeIndented("geometry Cone { height %s bottomRadius %s }\n" % (ch, br)) - self.writeIndented("appearance Appearance{\n",1) - self.writeIndented("material Material { diffuseColor 1 1 1 transparency .8 }\n") - self.writeIndented("} # Appearance\n",-1) - self.writeIndented("} # Shape\n",-1) - self.writeIndented("} # Collision\n",-1) - self.writeIndented("} # Transform visible cone \n",-1) - self.writeIndented("] # Spot children\n",-1) - self.writeIndented("} # SpotLight Cone Transform\n",-1) - #endif debug cone - self.writeIndented("\n") - - #------------------------------------------------------------------------ - def writeDirectionalLight(self, object, lamp): - safeName = self.cleanStr(object.name) - - intensity=min(lamp.energy/1.5, 1.0) # TBD: figure out the right value - (dx,dy,dz)=self.computeDirection(object) - - self.writeIndented("DEF %s DirectionalLight {\n" % safeName,1) - self.writeIndented("ambientIntensity %s\n" % self.ambientIntensity ) - self.writeIndented("intensity %s\n" % intensity ) - self.writeIndented("direction %s %s %s\n" % (round(dx,4),round(dy,4),round(dz,4))) - self.writeIndented("} # DirectionalLight\n",-1) - self.writeIndented("\n") - - #------------------------------------------------------------------------ - def writePointLight(self, object, lamp): - safeName = self.cleanStr(object.name) - - om = object.getMatrix() - location=self.rotVertex(om, (0,0,0)); - intensity=min(lamp.energy/1.5,1.0) # TBD: figure out the right value - - radius = lamp.dist - self.writeIndented("DEF %s PointLight {\n" % safeName,1) - self.writeIndented("ambientIntensity %s\n" % self.ambientIntensity ) - self.writeIndented("intensity %s\n" % intensity ) - self.writeIndented("location %s %s %s\n" % (round(location[0],3), - round(location[1],3), - round(location[2],3))) - self.writeIndented("radius %s\n" % radius ) - self.writeIndented("} # PointLight\n",-1) - self.writeIndented("\n") - - #------------------------------------------------------------------------ - def writeNavigationInfo(self): - self.writeIndented("NavigationInfo {\n",1) - self.writeIndented("headlight FALSE\n") - self.writeIndented("avatarSize [0.25, 1.75, 0.75]\n") - self.writeIndented("} # NavigationInfo\n",-1) - self.writeIndented("\n") - - #------------------------------------------------------------------------ - #--- Utility methods - #------------------------------------------------------------------------ - - def cleanStr(self, name, prefix='rsvd_'): - """cleanStr(name,prefix) - try to create a valid VRML DEF name from object name""" - - newName=name[:] - if len(newName) == 0: - self.nNodeID+=1 - return "%s%d" % (prefix, self.nNodeID) - - if newName in self.VRMLReserved: - newName='%s%s' % (prefix,newName) - #endif - - if newName[0] in ['0','1','2','3','4','5','6','7','8','9']: - newName='%s%s' % ('_',newName) - #endif - - for bad in [' ','"','#',"'",',','.','[','\\',']','{','}']: - newName=newName.replace(bad,'_') - return newName - - def countIFSSetsNeeded(self, mesh, imageMap, sided, vColors): - """ - countIFFSetsNeeded() - should look at a blender mesh to determine - how many VRML IndexFaceSets or IndexLineSets are needed. A - new mesh created under the following conditions: - - o - split by UV Textures / one per mesh - o - split by face, one sided and two sided - o - split by smooth and flat faces - o - split when faces only have 2 vertices * needs to be an IndexLineSet - """ - - imageNameMap={} - faceMap={} - nFaceIndx=0 - - for face in mesh.faces: - sidename=''; - if (face.mode & NMesh.FaceModes.TWOSIDE) == NMesh.FaceModes.TWOSIDE: - sidename='two' - else: - sidename='one' - #endif - - if not vColors.has_key('multi'): - for face in mesh.faces: - if face.col: - c=face.col[0] - if c.r != 255 and c.g != 255 and c.b !=255: - vColors['multi']=1 - #endif - #endif - #endfor - #endif - - if sided.has_key(sidename): - sided[sidename]+=1 - else: - sided[sidename]=1 - #endif - - if face.image: - faceName="%s_%s" % (face.image.name, sidename); - - if imageMap.has_key(faceName): - imageMap[faceName].append(face) - else: - imageMap[faceName]=[face.image.name,sidename,face] - #endif - #endif - #endfor - - if self.verbose > 0: - for faceName in imageMap.keys(): - ifs=imageMap[faceName] - print "Debug: faceName=%s image=%s, solid=%s facecnt=%d" % \ - (faceName, ifs[0], ifs[1], len(ifs)-2) - #endif - #endif - - return len(imageMap.keys()) - - def faceToString(self,face): - print "Debug: face.flag=0x%x (bitflags)" % face.flag - if face.flag & NMesh.FaceFlags.SELECT == NMesh.FaceFlags.SELECT: - print "Debug: face.flag.SELECT=true" - #endif - - print "Debug: face.mode=0x%x (bitflags)" % face.mode - if (face.mode & NMesh.FaceModes.TWOSIDE) == NMesh.FaceModes.TWOSIDE: - print "Debug: face.mode twosided" - #endif - - print "Debug: face.transp=0x%x (enum)" % face.transp - if face.transp == NMesh.FaceTranspModes.SOLID: - print "Debug: face.transp.SOLID" - # - - if face.image: - print "Debug: face.image=%s" % face.image.name - #endif - print "Debug: face.materialIndex=%d" % face.materialIndex - - def getVertexColorByIndx(self, mesh, indx): - for face in mesh.faces: - j=0 - for vertex in face.v: - if vertex.index == indx: - c=face.col[j] - #endif - j=j+1 - #endfor - #endfor - return c - - def meshToString(self,mesh): - print "Debug: mesh.hasVertexUV=%d" % mesh.hasVertexUV() - print "Debug: mesh.hasFaceUV=%d" % mesh.hasFaceUV() - print "Debug: mesh.hasVertexColours=%d" % mesh.hasVertexColours() - print "Debug: mesh.verts=%d" % len(mesh.verts) - print "Debug: mesh.faces=%d" % len(mesh.faces) - print "Debug: mesh.materials=%d" % len(mesh.materials) - - def rgbToFS(self, c): - s="%s %s %s" % ( - round(c.r/255.0,self.cp), - round(c.g/255.0,self.cp), - round(c.b/255.0,self.cp)) - return s - - def computeDirection(self, object): - x,y,z=(0,-1.0,0) # point down - ax,ay,az = (object.RotX,object.RotZ,object.RotY) - - # rot X - x1=x - y1=y*math.cos(ax)-z*math.sin(ax) - z1=y*math.sin(ax)+z*math.cos(ax) - - # rot Y - x2=x1*math.cos(ay)+z1*math.sin(ay) - y2=y1 - z2=z1*math.cos(ay)-x1*math.sin(ay) - - # rot Z - x3=x2*math.cos(az)-y2*math.sin(az) - y3=x2*math.sin(az)+y2*math.cos(az) - z3=z2 - - return [x3,y3,z3] - - - # swap Y and Z to handle axis difference between Blender and VRML - #------------------------------------------------------------------------ - def rotatePointForVRML(self, v): - x = v[0] - y = v[2] - z = -v[1] - - vrmlPoint=[x, y, z] - return vrmlPoint - - def rotVertex(self, mm, v): - lx,ly,lz=v[0],v[1],v[2] - gx=(mm[0][0]*lx + mm[1][0]*ly + mm[2][0]*lz) + mm[3][0] - gy=((mm[0][2]*lx + mm[1][2]*ly+ mm[2][2]*lz) + mm[3][2]) - gz=-((mm[0][1]*lx + mm[1][1]*ly + mm[2][1]*lz) + mm[3][1]) - rotatedv=[gx,gy,gz] - return rotatedv - - def writeIndented(self, s, inc=0): - if inc < 1: - self.indentLevel = self.indentLevel + inc - #endif - - spaces="" - for x in xrange(self.indentLevel): - spaces = spaces + " " - #endfor - self.file.write(spaces + s) - - if inc > 0: - self.indentLevel = self.indentLevel + inc - #endif - - # Converts a Euler to three new Quaternions - # Angles of Euler are passed in as radians - #------------------------------------------------------------------------ - def eulerToQuaternions(self, x, y, z): - Qx = [math.cos(x/2), math.sin(x/2), 0, 0] - Qy = [math.cos(y/2), 0, math.sin(y/2), 0] - Qz = [math.cos(z/2), 0, 0, math.sin(z/2)] - - quaternionVec=[Qx,Qy,Qz] - return quaternionVec - - # Multiply two Quaternions together to get a new Quaternion - #------------------------------------------------------------------------ - def multiplyQuaternions(self, Q1, Q2): - result = [((Q1[0] * Q2[0]) - (Q1[1] * Q2[1]) - (Q1[2] * Q2[2]) - (Q1[3] * Q2[3])), - ((Q1[0] * Q2[1]) + (Q1[1] * Q2[0]) + (Q1[2] * Q2[3]) - (Q1[3] * Q2[2])), - ((Q1[0] * Q2[2]) + (Q1[2] * Q2[0]) + (Q1[3] * Q2[1]) - (Q1[1] * Q2[3])), - ((Q1[0] * Q2[3]) + (Q1[3] * Q2[0]) + (Q1[1] * Q2[2]) - (Q1[2] * Q2[1]))] - - return result - - # Convert a Quaternion to an Angle Axis (ax, ay, az, angle) - # angle is in radians - #------------------------------------------------------------------------ - def quaternionToAngleAxis(self, Qf): - scale = math.pow(Qf[1],2) + math.pow(Qf[2],2) + math.pow(Qf[3],2) - ax = Qf[1] - ay = Qf[2] - az = Qf[3] - - if scale > .0001: - ax/=scale - ay/=scale - az/=scale - #endif - - angle = 2 * math.acos(Qf[0]) - - result = [ax, ay, az, angle] - return result - -def file_callback(filename): - if filename.find('.wrl', -4) < 0: filename += '.wrl' - wrlexport=VRML2Export(filename) - scene = Blender.Scene.getCurrent() - wrlexport.export(scene) -#enddef - -#------------------------------------------------------------------------ -# main routine -#------------------------------------------------------------------------ -print "\nThis is the old version of the vrml 2 (or 97) exporter." -print "It should be removed soon, please try the updated 'VRML 97' version.\n" - -try: - ARG = __script__['arg'] # user selected argument -except: - print "older version" - -if Blender.Get('version') < 225: - print "Warning: VRML2 export failed, wrong blender version!" - print " You aren't running blender version 2.25 or greater" - print " download a newer version from http://blender.org/" -else: - if ARG == 'all' or ARG == 'selected': - Blender.Window.FileSelector(file_callback,"Export VRML 2.0") - else: - baseFileName=Blender.Get('filename') - if baseFileName.find('.') != -1: - dots=Blender.Get('filename').split('.')[0:-1] - else: - dots=[baseFileName] - #endif - dots+=["wrl"] - vrmlFile=".".join(dots) - - file_callback(vrmlFile) - #endif -#endif |