Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2011-05-25 02:20:54 +0400
committerCampbell Barton <ideasman42@gmail.com>2011-05-25 02:20:54 +0400
commit86bd3cc31b636070da779f21b1fdc128faf1fc5d (patch)
tree485b42f72598708db283bd56c6ccb6ecdb5b742d /io_scene_x3d
parentb50a40ef9dbeb1554f66bedd21d0905875ba1172 (diff)
axis conversion for X3D and OBJ operators
Diffstat (limited to 'io_scene_x3d')
-rw-r--r--io_scene_x3d/__init__.py67
-rw-r--r--io_scene_x3d/export_x3d.py13
-rw-r--r--io_scene_x3d/import_x3d.py58
3 files changed, 103 insertions, 35 deletions
diff --git a/io_scene_x3d/__init__.py b/io_scene_x3d/__init__.py
index 9da01735..dd0e1e03 100644
--- a/io_scene_x3d/__init__.py
+++ b/io_scene_x3d/__init__.py
@@ -40,8 +40,8 @@ if "bpy" in locals():
import bpy
-from bpy.props import StringProperty, BoolProperty
-from bpy_extras.io_utils import ImportHelper, ExportHelper
+from bpy.props import StringProperty, BoolProperty, EnumProperty
+from bpy_extras.io_utils import ImportHelper, ExportHelper, axis_conversion
class ImportX3D(bpy.types.Operator, ImportHelper):
@@ -52,9 +52,38 @@ class ImportX3D(bpy.types.Operator, ImportHelper):
filename_ext = ".x3d"
filter_glob = StringProperty(default="*.x3d;*.wrl", options={'HIDDEN'})
+ global_axis_forward = EnumProperty(
+ name="Forward",
+ items=(('X', "X Forward", ""),
+ ('Y', "Y Forward", ""),
+ ('Z', "Z Forward", ""),
+ ('-X', "-X Forward", ""),
+ ('-Y', "-Y Forward", ""),
+ ('-Z', "-Z Forward", ""),
+ ),
+ default='Z',
+ )
+
+ global_axis_up = EnumProperty(
+ name="Up",
+ items=(('X', "X Up", ""),
+ ('Y', "Y Up", ""),
+ ('Z', "Z Up", ""),
+ ('-X', "-X Up", ""),
+ ('-Y', "-Y Up", ""),
+ ('-Z', "-Z Up", ""),
+ ),
+ default='-Y',
+ )
+
def execute(self, context):
from . import import_x3d
- return import_x3d.load(self, context, **self.as_keywords(ignore=("filter_glob",)))
+
+ keywords = self.as_keywords(ignore=("global_axis_forward", "global_axis_up", "filter_glob"))
+ global_matrix = axis_conversion(from_forward=self.global_axis_forward, from_up=self.global_axis_up).to_4x4()
+ keywords["global_matrix"] = global_matrix
+
+ return import_x3d.load(self, context, **keywords)
class ExportX3D(bpy.types.Operator, ExportHelper):
@@ -70,9 +99,39 @@ class ExportX3D(bpy.types.Operator, ExportHelper):
use_triangulate = BoolProperty(name="Triangulate", description="Triangulate quads.", default=False)
use_compress = BoolProperty(name="Compress", description="GZip the resulting file, requires a full python install", default=False)
+ global_axis_forward = EnumProperty(
+ name="Forward",
+ items=(('X', "X Forward", ""),
+ ('Y', "Y Forward", ""),
+ ('Z', "Z Forward", ""),
+ ('-X', "-X Forward", ""),
+ ('-Y', "-Y Forward", ""),
+ ('-Z', "-Z Forward", ""),
+ ),
+ default='Z',
+ )
+
+ global_axis_up = EnumProperty(
+ name="Up",
+ items=(('X', "X Up", ""),
+ ('Y', "Y Up", ""),
+ ('Z', "Z Up", ""),
+ ('-X', "-X Up", ""),
+ ('-Y', "-Y Up", ""),
+ ('-Z', "-Z Up", ""),
+ ),
+ default='-Y',
+ )
+
def execute(self, context):
from . import export_x3d
- return export_x3d.save(self, context, **self.as_keywords(ignore=("check_existing", "filter_glob")))
+ from mathutils import Matrix
+
+ keywords = self.as_keywords(ignore=("global_axis_forward", "global_axis_up", "check_existing", "filter_glob"))
+ global_matrix = axis_conversion(to_forward=self.global_axis_forward, to_up=self.global_axis_up).to_4x4()
+ keywords["global_matrix"] = global_matrix
+
+ return export_x3d.save(self, context, **keywords)
def menu_func_import(self, context):
diff --git a/io_scene_x3d/export_x3d.py b/io_scene_x3d/export_x3d.py
index 43033a0c..86d2209b 100644
--- a/io_scene_x3d/export_x3d.py
+++ b/io_scene_x3d/export_x3d.py
@@ -745,10 +745,12 @@ def export(file,
def save(operator, context, filepath="",
- use_selection=True,
- use_apply_modifiers=False,
- use_triangulate=False,
- use_compress=False):
+ use_selection=True,
+ use_apply_modifiers=False,
+ use_triangulate=False,
+ use_compress=False,
+ global_matrix=None,
+ ):
if use_compress:
if not filepath.lower().endswith('.x3dz'):
@@ -772,7 +774,8 @@ def save(operator, context, filepath="",
if file is None:
file = open(filepath, "w")
- global_matrix = mathutils.Matrix.Rotation(-(math.pi / 2.0), 4, 'X')
+ if global_matrix is None:
+ global_matrix = mathutils.Matrix()
export(file,
global_matrix,
diff --git a/io_scene_x3d/import_x3d.py b/io_scene_x3d/import_x3d.py
index 2ad2b172..9fb40288 100644
--- a/io_scene_x3d/import_x3d.py
+++ b/io_scene_x3d/import_x3d.py
@@ -25,10 +25,7 @@ import os
def imageConvertCompat(path):
- try:
- import os
- except:
- return path
+
if os.sep == '\\':
return path # assime win32 has quicktime, dont convert
@@ -258,10 +255,10 @@ def is_nodeline(i, words):
# Ok, we have a { after some values
# Check the values are not fields
for i, val in enumerate(words):
- if i != 0 and words[i - 1] in ('DEF', 'USE'):
+ if i != 0 and words[i - 1] in {'DEF', 'USE'}:
# ignore anything after DEF, it is a ID and can contain any chars.
pass
- elif val[0].isalpha() and val not in ('TRUE', 'FALSE'):
+ elif val[0].isalpha() and val not in {'TRUE', 'FALSE'}:
pass
else:
# There is a number in one of the values, therefor we are not a node.
@@ -1180,7 +1177,7 @@ class vrmlNode(object):
value_all = value.split()
def iskey(k):
- if k[0] != '"' and k[0].isalpha() and k.upper() not in ('TRUE', 'FALSE'):
+ if k[0] != '"' and k[0].isalpha() and k.upper() not in {'TRUE', 'FALSE'}:
return True
return False
@@ -1328,7 +1325,7 @@ class x3dNode(vrmlNode):
return
for x3dChildNode in self.x3dNode.childNodes:
- if x3dChildNode.nodeType in (x3dChildNode.TEXT_NODE, x3dChildNode.COMMENT_NODE, x3dChildNode.CDATA_SECTION_NODE):
+ if x3dChildNode.nodeType in {x3dChildNode.TEXT_NODE, x3dChildNode.COMMENT_NODE, x3dChildNode.CDATA_SECTION_NODE}:
continue
node_type = NODE_NORMAL
@@ -1539,7 +1536,7 @@ import math
MATRIX_Z_TO_Y = Matrix.Rotation(math.pi / 2.0, 4, 'X')
-def getFinalMatrix(node, mtx, ancestry):
+def getFinalMatrix(node, mtx, ancestry, global_matrix):
transform_nodes = [node_tx for node_tx in ancestry if node_tx.getSpec() == 'Transform']
if node.getSpec() == 'Transform':
@@ -1554,7 +1551,7 @@ def getFinalMatrix(node, mtx, ancestry):
mtx = mat * mtx
# worldspace matrix
- mtx = MATRIX_Z_TO_Y * mtx
+ mtx = mtx * global_matrix
return mtx
@@ -2040,7 +2037,7 @@ def importMesh_Box(geom, ancestry):
return bpymesh
-def importShape(node, ancestry):
+def importShape(node, ancestry, global_matrix):
vrmlname = node.getDefName()
if not vrmlname:
vrmlname = 'Shape'
@@ -2217,7 +2214,7 @@ def importShape(node, ancestry):
# Can transform data or object, better the object so we can instance the data
#bpymesh.transform(getFinalMatrix(node))
- bpyob.matrix_world = getFinalMatrix(node, None, ancestry)
+ bpyob.matrix_world = getFinalMatrix(node, None, ancestry, global_matrix)
def importLamp_PointLight(node, ancestry):
@@ -2303,7 +2300,7 @@ def importLamp_SpotLight(node, ancestry):
return bpylamp, mtx
-def importLamp(node, spec, ancestry):
+def importLamp(node, spec, ancestry, global_matrix):
if spec == 'PointLight':
bpylamp, mtx = importLamp_PointLight(node, ancestry)
elif spec == 'DirectionalLight':
@@ -2317,10 +2314,10 @@ def importLamp(node, spec, ancestry):
bpyob = node.blendObject = bpy.data.objects.new("TODO", bpylamp)
bpy.context.scene.objects.link(bpyob)
- bpyob.matrix_world = getFinalMatrix(node, mtx, ancestry)
+ bpyob.matrix_world = getFinalMatrix(node, mtx, ancestry. global_matrix)
-def importViewpoint(node, ancestry):
+def importViewpoint(node, ancestry, global_matrix):
name = node.getDefName()
if not name:
name = 'Viewpoint'
@@ -2339,10 +2336,10 @@ def importViewpoint(node, ancestry):
bpyob = node.blendObject = bpy.data.objects.new("TODO", bpycam)
bpy.context.scene.objects.link(bpyob)
- bpyob.matrix_world = getFinalMatrix(node, mtx, ancestry)
+ bpyob.matrix_world = getFinalMatrix(node, mtx, ancestry, global_matrix)
-def importTransform(node, ancestry):
+def importTransform(node, ancestry, global_matrix):
name = node.getDefName()
if not name:
name = 'Transform'
@@ -2350,7 +2347,7 @@ def importTransform(node, ancestry):
bpyob = node.blendObject = bpy.data.objects.new(name, None)
bpy.context.scene.objects.link(bpyob)
- bpyob.matrix_world = getFinalMatrix(node, None, ancestry)
+ bpyob.matrix_world = getFinalMatrix(node, None, ancestry, global_matrix)
# so they are not too annoying
bpyob.empty_draw_type = 'PLAIN_AXES'
@@ -2516,7 +2513,7 @@ ROUTE champFly001.bindTime TO vpTs.set_startTime
set_data_from_node = defDict[from_id]
translatePositionInterpolator(set_data_from_node, action, ancestry)
- if to_type in ('set_orientation', 'rotation'):
+ if to_type in {'set_orientation', 'rotation'}:
action = getIpo(to_id)
set_data_from_node = defDict[from_id]
translateOrientationInterpolator(set_data_from_node, action, ancestry)
@@ -2532,7 +2529,12 @@ ROUTE champFly001.bindTime TO vpTs.set_startTime
translateTimeSensor(time_node, action, ancestry)
-def load_web3d(path, PREF_FLAT=False, PREF_CIRCLE_DIV=16, HELPER_FUNC=None):
+def load_web3d(path,
+ PREF_FLAT=False,
+ PREF_CIRCLE_DIV=16,
+ global_matrix=None,
+ HELPER_FUNC=None,
+ ):
# Used when adding blender primitives
GLOBALS['CIRCLE_DETAIL'] = PREF_CIRCLE_DIV
@@ -2547,6 +2549,9 @@ def load_web3d(path, PREF_FLAT=False, PREF_CIRCLE_DIV=16, HELPER_FUNC=None):
print(msg)
return
+ if global_matrix is None:
+ global_matrix = Matrix()
+
# fill with tuples - (node, [parents-parent, parent])
all_nodes = root_node.getSerialized([], [])
@@ -2566,15 +2571,15 @@ def load_web3d(path, PREF_FLAT=False, PREF_CIRCLE_DIV=16, HELPER_FUNC=None):
# by an external script. - gets first pick
pass
if spec == 'Shape':
- importShape(node, ancestry)
- elif spec in ('PointLight', 'DirectionalLight', 'SpotLight'):
- importLamp(node, spec, ancestry)
+ importShape(node, ancestry, global_matrix)
+ elif spec in {'PointLight', 'DirectionalLight', 'SpotLight'}:
+ importLamp(node, spec, ancestry, global_matrix)
elif spec == 'Viewpoint':
- importViewpoint(node, ancestry)
+ importViewpoint(node, ancestry, global_matrix)
elif spec == 'Transform':
# Only use transform nodes when we are not importing a flat object hierarchy
if PREF_FLAT == False:
- importTransform(node, ancestry)
+ importTransform(node, ancestry, global_matrix)
'''
# These are delt with later within importRoute
elif spec=='PositionInterpolator':
@@ -2641,11 +2646,12 @@ def load_web3d(path, PREF_FLAT=False, PREF_CIRCLE_DIV=16, HELPER_FUNC=None):
del child_dict
-def load(operator, context, filepath=""):
+def load(operator, context, filepath="", global_matrix=None):
load_web3d(filepath,
PREF_FLAT=True,
PREF_CIRCLE_DIV=16,
+ global_matrix=global_matrix,
)
return {'FINISHED'}