Page Menu
Home
Search
Configure Global Search
Log In
Files
F21269
io_scene_x3d_optional_name_decorations.patch
Public
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Authored By
Peter Amstutz (tetron)
Nov 13 2013, 4:31 PM
Size
13 KB
Subscribers
None
io_scene_x3d_optional_name_decorations.patch
View Options
Index: io_scene_x3d/__init__.py
===================================================================
--- io_scene_x3d/__init__.py (revision 2909)
+++ io_scene_x3d/__init__.py (working copy)
@@ -134,13 +134,19 @@
description="Export parent child relationships",
default=True,
)
+ name_decorations = BoolProperty(
+ name="Name decorations",
+ description="Add prefixes to the names of exported nodes to indicate their type.",
+ default=True,
+ )
use_h3d = BoolProperty(
name="H3D Extensions",
description="Export shaders for H3D",
default=False,
)
- axis_forward = EnumProperty(
- name="Forward",
+
+ blender_axis_forward = EnumProperty(
+ name="Blender Forward",
items=(('X', "X Forward", ""),
('Y', "Y Forward", ""),
('Z', "Z Forward", ""),
@@ -148,11 +154,35 @@
('-Y', "-Y Forward", ""),
('-Z', "-Z Forward", ""),
),
+ default='-Y',
+ )
+
+ blender_axis_up = EnumProperty(
+ name="Blender Up",
+ items=(('X', "X Up", ""),
+ ('Y', "Y Up", ""),
+ ('Z', "Z Up", ""),
+ ('-X', "-X Up", ""),
+ ('-Y', "-Y Up", ""),
+ ('-Z', "-Z Up", ""),
+ ),
+ default='Z',
+ )
+
+ x3d_axis_forward = EnumProperty(
+ name="X3D Forward",
+ items=(('X', "X Forward", ""),
+ ('Y', "Y Forward", ""),
+ ('Z', "Z Forward", ""),
+ ('-X', "-X Forward", ""),
+ ('-Y', "-Y Forward", ""),
+ ('-Z', "-Z Forward", ""),
+ ),
default='Z',
)
- axis_up = EnumProperty(
- name="Up",
+ x3d_axis_up = EnumProperty(
+ name="X3D Up",
items=(('X', "X Up", ""),
('Y', "Y Up", ""),
('Z', "Z Up", ""),
@@ -168,13 +198,17 @@
def execute(self, context):
from . import export_x3d
- keywords = self.as_keywords(ignore=("axis_forward",
- "axis_up",
+ keywords = self.as_keywords(ignore=("blender_axis_forward",
+ "blender_axis_up",
+ "x3d_axis_forward",
+ "x3d_axis_up",
"check_existing",
"filter_glob",
))
- global_matrix = axis_conversion(to_forward=self.axis_forward,
- to_up=self.axis_up,
+ global_matrix = axis_conversion(from_forward=self.blender_axis_forward,
+ from_up=self.blender_axis_up,
+ to_forward=self.x3d_axis_forward,
+ to_up=self.x3d_axis_up,
).to_4x4()
keywords["global_matrix"] = global_matrix
Index: io_scene_x3d/export_x3d.py
===================================================================
--- io_scene_x3d/export_x3d.py (revision 2909)
+++ io_scene_x3d/export_x3d.py (working copy)
@@ -187,7 +187,7 @@
lines.append("\n")
elif l.lstrip().startswith("lamp_visibility_other("):
w = l.split(', ')
- last_transform = w[1] + "_transform" # XXX - HACK!!!
+ last_transform = w[1] + _TRANSFORM # XXX - HACK!!!
w[1] = '(view_matrix * %s_transform * vec4(%s.x, %s.y, %s.z, 1.0)).xyz' % (w[1], w[1], w[1], w[1])
l = ", ".join(w)
elif l.lstrip().startswith("lamp_visibility_sun_hemi("):
@@ -246,6 +246,7 @@
use_hierarchy=True,
use_h3d=False,
path_mode='AUTO',
+ name_decorations=True,
):
# -------------------------------------------------------------------------
@@ -255,13 +256,49 @@
from bpy_extras.io_utils import unique_name
from xml.sax.saxutils import quoteattr, escape
- uuid_cache_object = {} # object
- uuid_cache_lamp = {} # 'LA_' + object.name
- uuid_cache_view = {} # object, different namespace
- uuid_cache_mesh = {} # mesh
- uuid_cache_material = {} # material
- uuid_cache_image = {} # image
- uuid_cache_world = {} # world
+
+
+ if name_decorations:
+ # If names are decorated, the uuid map can be split up
+ # by type for efficiency of collision testing
+ # since objects of different types will always have
+ # different decorated names.
+ uuid_cache_object = {} # object
+ uuid_cache_lamp = {} # 'LA_' + object.name
+ uuid_cache_view = {} # object, different namespace
+ uuid_cache_mesh = {} # mesh
+ uuid_cache_material = {} # material
+ uuid_cache_image = {} # image
+ uuid_cache_world = {} # world
+ CA_ = 'CA_'
+ OB_ = 'OB_'
+ ME_ = 'ME_'
+ IM_ = 'IM_'
+ WO_ = 'WO_'
+ MA_ = 'MA_'
+ LA_ = 'LA_'
+ group_ = 'group_'
+ else:
+ # If names are not decorated, it may be possible for two objects to
+ # have the same name, so there has to be a unified dictionary to
+ # prevent uuid collisions.
+ uuid_cache_object = {} # object
+ uuid_cache_lamp = uuid_cache_object # 'LA_' + object.name
+ uuid_cache_view = uuid_cache_object # object, different namespace
+ uuid_cache_mesh = uuid_cache_object # mesh
+ uuid_cache_material = uuid_cache_object # material
+ uuid_cache_image = uuid_cache_object # image
+ uuid_cache_world = uuid_cache_object # world
+ CA_ = ''
+ OB_ = ''
+ ME_ = ''
+ IM_ = ''
+ WO_ = ''
+ MA_ = ''
+ LA_ = ''
+ group_ = ''
+
+ _TRANSFORM = '_TRANSFORM'
# store files to copy
copy_set = set()
@@ -328,7 +365,7 @@
return ident
def writeViewpoint(ident, obj, matrix, scene):
- view_id = quoteattr(unique_name(obj, 'CA_' + obj.name, uuid_cache_view, clean_func=clean_def, sep="_"))
+ view_id = quoteattr(unique_name(obj, CA_ + obj.name, uuid_cache_view, clean_func=clean_def, sep="_"))
loc, rot, scale = matrix.decompose()
rot = rot.to_axis_angle()
@@ -396,7 +433,7 @@
def writeSpotLight(ident, obj, matrix, lamp, world):
# note, lamp_id is not re-used
- lamp_id = quoteattr(unique_name(obj, 'LA_' + obj.name, uuid_cache_lamp, clean_func=clean_def, sep="_"))
+ lamp_id = quoteattr(unique_name(obj, LA_ + obj.name, uuid_cache_lamp, clean_func=clean_def, sep="_"))
if world:
ambi = world.ambient_color
@@ -432,7 +469,7 @@
def writeDirectionalLight(ident, obj, matrix, lamp, world):
# note, lamp_id is not re-used
- lamp_id = quoteattr(unique_name(obj, 'LA_' + obj.name, uuid_cache_lamp, clean_func=clean_def, sep="_"))
+ lamp_id = quoteattr(unique_name(obj, LA_ + obj.name, uuid_cache_lamp, clean_func=clean_def, sep="_"))
if world:
ambi = world.ambient_color
@@ -457,7 +494,7 @@
def writePointLight(ident, obj, matrix, lamp, world):
# note, lamp_id is not re-used
- lamp_id = quoteattr(unique_name(obj, 'LA_' + obj.name, uuid_cache_lamp, clean_func=clean_def, sep="_"))
+ lamp_id = quoteattr(unique_name(obj, LA_ + obj.name, uuid_cache_lamp, clean_func=clean_def, sep="_"))
if world:
ambi = world.ambient_color
@@ -482,9 +519,9 @@
fw(ident_step + '/>\n')
def writeIndexedFaceSet(ident, obj, mesh, matrix, world):
- obj_id = quoteattr(unique_name(obj, 'OB_' + obj.name, uuid_cache_object, clean_func=clean_def, sep="_"))
- mesh_id = quoteattr(unique_name(mesh, 'ME_' + mesh.name, uuid_cache_mesh, clean_func=clean_def, sep="_"))
- mesh_id_group = prefix_quoted_str(mesh_id, 'group_')
+ obj_id = quoteattr(unique_name(obj, OB_ + obj.name, uuid_cache_object, clean_func=clean_def, sep="_"))
+ mesh_id = quoteattr(unique_name(mesh, ME_ + mesh.name, uuid_cache_mesh, clean_func=clean_def, sep="_"))
+ mesh_id_group = prefix_quoted_str(mesh_id, group_)
mesh_id_coords = prefix_quoted_str(mesh_id, 'coords_')
mesh_id_normals = prefix_quoted_str(mesh_id, 'normals_')
@@ -501,7 +538,7 @@
# use _ifs_TRANSFORM suffix so we dont collide with transform node when
# hierarchys are used.
- ident = writeTransform_begin(ident, matrix, suffix_quoted_str(obj_id, "_ifs_TRANSFORM"))
+ ident = writeTransform_begin(ident, matrix, suffix_quoted_str(obj_id, "_ifs" + _TRANSFORM))
if mesh.tag:
fw('%s<Group USE=%s />\n' % (ident, mesh_id_group))
@@ -918,7 +955,7 @@
fw('%s</Collision>\n' % ident)
def writeMaterial(ident, material, world):
- material_id = quoteattr(unique_name(material, 'MA_' + material.name, uuid_cache_material, clean_func=clean_def, sep="_"))
+ material_id = quoteattr(unique_name(material, MA_ + material.name, uuid_cache_material, clean_func=clean_def, sep="_"))
# look up material name, use it if available
if material.tag:
@@ -1084,7 +1121,7 @@
frag_uniform_var_map[uniform['varname']] = lamp_obj
if uniform['datatype'] == gpu.GPU_DATA_3F: # should always be true!
- lamp_obj_id = quoteattr(unique_name(lamp_obj, 'LA_' + lamp_obj.name, uuid_cache_lamp, clean_func=clean_def, sep="_"))
+ lamp_obj_id = quoteattr(unique_name(lamp_obj, LA_ + lamp_obj.name, uuid_cache_lamp, clean_func=clean_def, sep="_"))
lamp_obj_transform_id = quoteattr(unique_name(lamp_obj, lamp_obj.name, uuid_cache_object, clean_func=clean_def, sep="_"))
value = '%.6f %.6f %.6f' % (global_matrix * lamp_obj.matrix_world).to_translation()[:]
@@ -1100,7 +1137,7 @@
frag_vars.append("uniform mat4 %s_transform;" % uniform['varname'])
h3d_material_route.append(
'<ROUTE fromNode=%s fromField="accumulatedForward" toNode=%s toField="%s_transform" />%s' %
- (suffix_quoted_str(lamp_obj_transform_id, "_TRANSFORM"), material_id, uniform['varname'], field_descr))
+ (suffix_quoted_str(lamp_obj_transform_id, _TRANSFORM), material_id, uniform['varname'], field_descr))
h3d_material_route.append(
'<ROUTE fromNode=%s fromField="location" toNode=%s toField="%s" /> %s' %
@@ -1141,7 +1178,7 @@
# route so we can have the lamp update the view
if h3d_is_object_view(scene, lamp_obj):
- lamp_id = quoteattr(unique_name(lamp_obj, 'LA_' + lamp_obj.name, uuid_cache_lamp, clean_func=clean_def, sep="_"))
+ lamp_id = quoteattr(unique_name(lamp_obj, LA_ + lamp_obj.name, uuid_cache_lamp, clean_func=clean_def, sep="_"))
h3d_material_route.append(
'<ROUTE fromNode=%s fromField="direction" toNode=%s toField="%s" />%s' %
(lamp_id, material_id, uniform['varname'], field_descr))
@@ -1234,7 +1271,7 @@
fw('%s</ComposedShader>\n' % ident)
def writeImageTexture(ident, image):
- image_id = quoteattr(unique_name(image, 'IM_' + image.name, uuid_cache_image, clean_func=clean_def, sep="_"))
+ image_id = quoteattr(unique_name(image, IM_ + image.name, uuid_cache_image, clean_func=clean_def, sep="_"))
if image.tag:
fw('%s<ImageTexture USE=%s />\n' % (ident, image_id))
@@ -1270,7 +1307,7 @@
return
# note, not re-used
- world_id = quoteattr(unique_name(world, 'WO_' + world.name, uuid_cache_world, clean_func=clean_def, sep="_"))
+ world_id = quoteattr(unique_name(world, WO_ + world.name, uuid_cache_world, clean_func=clean_def, sep="_"))
blending = world.use_sky_blend, world.use_sky_paper, world.use_sky_real
@@ -1350,7 +1387,7 @@
obj_main_id = quoteattr(unique_name(obj_main, obj_main.name, uuid_cache_object, clean_func=clean_def, sep="_"))
- ident = writeTransform_begin(ident, obj_main_matrix if obj_main_parent else global_matrix * obj_main_matrix, suffix_quoted_str(obj_main_id, "_TRANSFORM"))
+ ident = writeTransform_begin(ident, obj_main_matrix if obj_main_parent else global_matrix * obj_main_matrix, suffix_quoted_str(obj_main_id, _TRANSFORM))
for obj, obj_matrix in (() if derived is None else derived):
obj_type = obj.type
@@ -1507,6 +1544,7 @@
use_h3d=False,
global_matrix=None,
path_mode='AUTO',
+ name_decorations=True,
):
bpy.path.ensure_ext(filepath, '.x3dz' if use_compress else '.x3d')
@@ -1534,6 +1572,7 @@
use_hierarchy=use_hierarchy,
use_h3d=use_h3d,
path_mode=path_mode,
+ name_decorations=name_decorations,
)
return {'FINISHED'}
File Metadata
Details
Mime Type
text/x-diff
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
5d/37/7acc24bceb57ecf4166c349bd27c
Event Timeline
Log In to Comment