forked from bartvdbraak/blender
fix for [#6692] vrml (.wrl) export bug in V2.44 release
patch from Michalis Kamburelis with some minor edits
This commit is contained in:
parent
3331bfae48
commit
71fbf87304
@ -3,9 +3,6 @@
|
|||||||
Name: 'VRML97 (.wrl)...'
|
Name: 'VRML97 (.wrl)...'
|
||||||
Blender: 241
|
Blender: 241
|
||||||
Group: 'Export'
|
Group: 'Export'
|
||||||
Submenu: 'All Objects...' all
|
|
||||||
Submenu: 'All Objects compressed...' comp
|
|
||||||
Submenu: 'Selected Objects...' selected
|
|
||||||
Tooltip: 'Export to VRML97 file (.wrl)'
|
Tooltip: 'Export to VRML97 file (.wrl)'
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@ -55,7 +52,7 @@ want to export only selected or all relevant objects.
|
|||||||
|
|
||||||
import Blender
|
import Blender
|
||||||
from Blender import Object, Mesh, Lamp, Draw, BGL, \
|
from Blender import Object, Mesh, Lamp, Draw, BGL, \
|
||||||
Image, Text, sys, Mathutils
|
Image, Text, sys, Mathutils, Registry
|
||||||
from Blender.Scene import Render
|
from Blender.Scene import Render
|
||||||
|
|
||||||
import math
|
import math
|
||||||
@ -70,8 +67,9 @@ worldmat = Blender.Texture.Get()
|
|||||||
filename = Blender.Get('filename')
|
filename = Blender.Get('filename')
|
||||||
_safeOverwrite = True
|
_safeOverwrite = True
|
||||||
extension = ''
|
extension = ''
|
||||||
ARG=''
|
|
||||||
|
|
||||||
|
# Matrices below are used only when export_rotate_z_to_y.val:
|
||||||
|
#
|
||||||
# Blender is Z up, VRML is Y up, both are right hand coordinate
|
# Blender is Z up, VRML is Y up, both are right hand coordinate
|
||||||
# systems, so to go from Blender coords to VRML coords we rotate
|
# systems, so to go from Blender coords to VRML coords we rotate
|
||||||
# by 90 degrees around the X axis. In matrix notation, we have a
|
# by 90 degrees around the X axis. In matrix notation, we have a
|
||||||
@ -633,12 +631,10 @@ class VRML2Export:
|
|||||||
meshVertexList = me.verts
|
meshVertexList = me.verts
|
||||||
|
|
||||||
for vertex in meshVertexList:
|
for vertex in meshVertexList:
|
||||||
blenvert = Mathutils.Vector(vertex.co)
|
vrmlvert = vertex.co
|
||||||
vrmlvert = M_blen2vrml * blenvert
|
if export_rotate_z_to_y.val:
|
||||||
self.writeUnindented("%s %s %s\n " % \
|
vrmlvert = M_blen2vrml * vrmlvert
|
||||||
(vrmlvert[0], \
|
self.writeUnindented("%.6f %.6f %.6f\n " % (vrmlvert[0], vrmlvert[1], vrmlvert[2]))
|
||||||
vrmlvert[1], \
|
|
||||||
vrmlvert[2]))
|
|
||||||
self.writeIndented("]\n", -1)
|
self.writeIndented("]\n", -1)
|
||||||
self.writeIndented("}\n", -1)
|
self.writeIndented("}\n", -1)
|
||||||
self.writeIndented("\n")
|
self.writeIndented("\n")
|
||||||
@ -1016,7 +1012,10 @@ class VRML2Export:
|
|||||||
return
|
return
|
||||||
|
|
||||||
ob_matrix = Mathutils.Matrix(ob.getMatrix('worldspace'))
|
ob_matrix = Mathutils.Matrix(ob.getMatrix('worldspace'))
|
||||||
matrix = M_blen2vrml * ob_matrix * M_vrml2blen
|
if export_rotate_z_to_y.val:
|
||||||
|
matrix = M_blen2vrml * ob_matrix * M_vrml2blen
|
||||||
|
else:
|
||||||
|
matrix = ob_matrix
|
||||||
e = matrix.rotationPart().toEuler()
|
e = matrix.rotationPart().toEuler()
|
||||||
|
|
||||||
v = matrix.translationPart()
|
v = matrix.translationPart()
|
||||||
@ -1089,7 +1088,7 @@ class VRML2Export:
|
|||||||
self.writeFog()
|
self.writeFog()
|
||||||
self.proto = 0
|
self.proto = 0
|
||||||
allObj = []
|
allObj = []
|
||||||
if ARG == 'selected':
|
if export_selection_only.val:
|
||||||
allObj = list(scene.objects.context)
|
allObj = list(scene.objects.context)
|
||||||
else:
|
else:
|
||||||
allObj = list(scene.objects)
|
allObj = list(scene.objects)
|
||||||
@ -1098,7 +1097,7 @@ class VRML2Export:
|
|||||||
for thisObj in allObj:
|
for thisObj in allObj:
|
||||||
self.writeObject(thisObj)
|
self.writeObject(thisObj)
|
||||||
|
|
||||||
if ARG != 'selected':
|
if not export_selection_only.val:
|
||||||
self.writeScript()
|
self.writeScript()
|
||||||
self.cleanup()
|
self.cleanup()
|
||||||
|
|
||||||
@ -1213,26 +1212,58 @@ def select_file(filename):
|
|||||||
wrlexport=VRML2Export(filename)
|
wrlexport=VRML2Export(filename)
|
||||||
wrlexport.export(scene, world, worldmat)
|
wrlexport.export(scene, world, worldmat)
|
||||||
|
|
||||||
|
#########################################################
|
||||||
|
# UI and Registry utilities
|
||||||
|
#########################################################
|
||||||
|
|
||||||
|
export_selection_only = Draw.Create(0)
|
||||||
|
export_rotate_z_to_y = Draw.Create(1)
|
||||||
|
export_compressed = Draw.Create(0)
|
||||||
|
|
||||||
|
def save_to_registry():
|
||||||
|
d = {}
|
||||||
|
d['selection_only'] = export_selection_only.val
|
||||||
|
d['rotate_z_to_y'] = export_rotate_z_to_y.val
|
||||||
|
d['compressed'] = export_compressed.val
|
||||||
|
Registry.SetKey('vrml97_export', d, True)
|
||||||
|
|
||||||
|
def load_from_registry():
|
||||||
|
d = Registry.GetKey('vrml97_export', True)
|
||||||
|
if d:
|
||||||
|
try:
|
||||||
|
export_selection_only.val = d['selection_only']
|
||||||
|
export_rotate_z_to_y.val = d['rotate_z_to_y']
|
||||||
|
export_compressed.val = d['compressed']
|
||||||
|
except: save_to_registry() # If data is not valid, rewrite it.
|
||||||
|
|
||||||
|
def show_popup():
|
||||||
|
pup_block = [
|
||||||
|
('Selection Only', export_selection_only, 'Only export objects in visible selection. Else export whole scene.'),
|
||||||
|
('Rotate +Z to +Y', export_rotate_z_to_y, 'Rotate such that +Z axis (Blender up) becomes +Y (VRML up).'),
|
||||||
|
('Compress', export_compressed, 'Generate a .wrz file (normal VRML compressed by gzip).')
|
||||||
|
]
|
||||||
|
return Draw.PupBlock('Export VRML 97...', pup_block)
|
||||||
|
|
||||||
#########################################################
|
#########################################################
|
||||||
# main routine
|
# main routine
|
||||||
#########################################################
|
#########################################################
|
||||||
|
|
||||||
try:
|
load_from_registry()
|
||||||
ARG = __script__['arg'] # user selected argument
|
|
||||||
except:
|
|
||||||
print "older version"
|
|
||||||
|
|
||||||
if Blender.Get('version') < 235:
|
# Note that show_popup must be done before Blender.Window.FileSelector,
|
||||||
print "Warning: VRML97 export failed, wrong blender version!"
|
# because export_compressed affects the suggested extension of resulting
|
||||||
print " You aren't running blender version 2.35 or greater"
|
# file.
|
||||||
print " download a newer version from http://blender3d.org/"
|
|
||||||
else:
|
if show_popup():
|
||||||
if ARG == 'comp':
|
save_to_registry()
|
||||||
extension=".wrz"
|
if export_compressed.val:
|
||||||
from gzip import *
|
try:
|
||||||
|
extension=".wrz"
|
||||||
|
from gzip import *
|
||||||
|
except:
|
||||||
|
print "could not import gzip"
|
||||||
|
pass
|
||||||
else:
|
else:
|
||||||
extension=".wrl"
|
extension=".wrl"
|
||||||
Blender.Window.FileSelector(select_file, "Export VRML97", \
|
Blender.Window.FileSelector(select_file, "Export VRML97", \
|
||||||
sys.makename(ext=extension))
|
sys.makename(ext=extension))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user