diff --git a/io_scene_x3d/export_x3d.py b/io_scene_x3d/export_x3d.py index 7f5972c0ed9076423319754c8e79c0cc8ce82802..79afa5d856b80261745d4116602acaabf7e3da09 100644 --- a/io_scene_x3d/export_x3d.py +++ b/io_scene_x3d/export_x3d.py @@ -327,15 +327,17 @@ def export(file, def writeViewpoint(ident, obj, matrix, scene): view_id = quoteattr(unique_name(obj, 'CA_' + obj.name, uuid_cache_view, clean_func=clean_def, sep="_")) - loc, quat, scale = matrix.decompose() + loc, rot, scale = matrix.decompose() + rot = rot.to_axis_angle() + rot = rot[0][:] + (rot[1], ) ident_step = ident + (' ' * (-len(ident) + \ fw('%s<Viewpoint ' % ident))) fw('DEF=%s\n' % view_id) fw(ident_step + 'centerOfRotation="0 0 0"\n') fw(ident_step + 'position="%3.2f %3.2f %3.2f"\n' % loc[:]) - fw(ident_step + 'orientation="%3.2f %3.2f %3.2f %3.2f"\n' % (quat.axis.normalized()[:] + (quat.angle, ))) - fw(ident_step + 'fieldOfView="%.3g"\n' % obj.data.angle) + fw(ident_step + 'orientation="%3.2f %3.2f %3.2f %3.2f"\n' % rot) + fw(ident_step + 'fieldOfView="%.3f"\n' % obj.data.angle) fw(ident_step + '/>\n') def writeFog(ident, world): @@ -349,8 +351,8 @@ def export(file, ident_step = ident + (' ' * (-len(ident) + \ fw('%s<Fog ' % ident))) fw('fogType="%s"\n' % ('LINEAR' if (mtype == 'LINEAR') else 'EXPONENTIAL')) - fw(ident_step + 'color="%.3g %.3g %.3g"\n' % clamp_color(world.horizon_color)) - fw(ident_step + 'visibilityRange="%.3g"\n' % mparam.depth) + fw(ident_step + 'color="%.3f %.3f %.3f"\n' % clamp_color(world.horizon_color)) + fw(ident_step + 'visibilityRange="%.3f"\n' % mparam.depth) fw(ident_step + '/>\n') else: return @@ -372,12 +374,14 @@ def export(file, else: fw('\n') - loc, quat, sca = matrix.decompose() + loc, rot, sca = matrix.decompose() + rot = rot.to_axis_angle() + rot = rot[0][:] + (rot[1], ) - fw(ident_step + 'translation="%.6g %.6g %.6g"\n' % loc[:]) - # fw(ident_step + 'center="%.6g %.6g %.6g"\n' % (0, 0, 0)) - fw(ident_step + 'scale="%.6g %.6g %.6g"\n' % sca[:]) - fw(ident_step + 'rotation="%.6g %.6g %.6g %.6g"\n' % (quat.axis.normalized()[:] + (quat.angle, ))) + fw(ident_step + 'translation="%.6f %.6f %.6f"\n' % loc[:]) + # fw(ident_step + 'center="%.6f %.6f %.6f"\n' % (0, 0, 0)) + fw(ident_step + 'scale="%.6f %.6f %.6f"\n' % sca[:]) + fw(ident_step + 'rotation="%.6f %.6f %.6f %.6f"\n' % rot) fw(ident_step + '>\n') ident += '\t' return ident @@ -413,14 +417,14 @@ def export(file, ident_step = ident + (' ' * (-len(ident) + \ fw('%s<SpotLight ' % ident))) fw('DEF=%s\n' % lamp_id) - fw(ident_step + 'radius="%.4g"\n' % radius) - fw(ident_step + 'ambientIntensity="%.4g"\n' % amb_intensity) - fw(ident_step + 'intensity="%.4g"\n' % intensity) - fw(ident_step + 'color="%.4g %.4g %.4g"\n' % clamp_color(lamp.color)) - fw(ident_step + 'beamWidth="%.4g"\n' % beamWidth) - fw(ident_step + 'cutOffAngle="%.4g"\n' % cutOffAngle) - fw(ident_step + 'direction="%.4g %.4g %.4g"\n' % orientation) - fw(ident_step + 'location="%.4g %.4g %.4g"\n' % location) + fw(ident_step + 'radius="%.4f"\n' % radius) + fw(ident_step + 'ambientIntensity="%.4f"\n' % amb_intensity) + fw(ident_step + 'intensity="%.4f"\n' % intensity) + fw(ident_step + 'color="%.4f %.4f %.4f"\n' % clamp_color(lamp.color)) + fw(ident_step + 'beamWidth="%.4f"\n' % beamWidth) + fw(ident_step + 'cutOffAngle="%.4f"\n' % cutOffAngle) + fw(ident_step + 'direction="%.4f %.4f %.4f"\n' % orientation) + fw(ident_step + 'location="%.4f %.4f %.4f"\n' % location) fw(ident_step + '/>\n') def writeDirectionalLight(ident, obj, matrix, lamp, world): @@ -442,10 +446,10 @@ def export(file, ident_step = ident + (' ' * (-len(ident) + \ fw('%s<DirectionalLight ' % ident))) fw('DEF=%s\n' % lamp_id) - fw(ident_step + 'ambientIntensity="%.4g"\n' % amb_intensity) - fw(ident_step + 'color="%.4g %.4g %.4g"\n' % clamp_color(lamp.color)) - fw(ident_step + 'intensity="%.4g"\n' % intensity) - fw(ident_step + 'direction="%.4g %.4g %.4g"\n' % orientation) + fw(ident_step + 'ambientIntensity="%.4f"\n' % amb_intensity) + fw(ident_step + 'color="%.4f %.4f %.4f"\n' % clamp_color(lamp.color)) + fw(ident_step + 'intensity="%.4f"\n' % intensity) + fw(ident_step + 'direction="%.4f %.4f %.4f"\n' % orientation) fw(ident_step + '/>\n') def writePointLight(ident, obj, matrix, lamp, world): @@ -466,12 +470,12 @@ def export(file, ident_step = ident + (' ' * (-len(ident) + \ fw('%s<PointLight ' % ident))) fw('DEF=%s\n' % lamp_id) - fw(ident_step + 'ambientIntensity="%.4g"\n' % amb_intensity) - fw(ident_step + 'color="%.4g %.4g %.4g"\n' % clamp_color(lamp.color)) + fw(ident_step + 'ambientIntensity="%.4f"\n' % amb_intensity) + fw(ident_step + 'color="%.4f %.4f %.4f"\n' % clamp_color(lamp.color)) - fw(ident_step + 'intensity="%.4g"\n' % intensity) - fw(ident_step + 'radius="%.4g" \n' % lamp.distance) - fw(ident_step + 'location="%.4g %.4g %.4g"\n' % location) + fw(ident_step + 'intensity="%.4f"\n' % intensity) + fw(ident_step + 'radius="%.4f" \n' % lamp.distance) + fw(ident_step + 'location="%.4f %.4f %.4f"\n' % location) fw(ident_step + '/>\n') def writeIndexedFaceSet(ident, obj, mesh, matrix, world): @@ -627,10 +631,10 @@ def export(file, ident_step = ident + (' ' * (-len(ident) + \ fw('%s<TextureTransform ' % ident))) fw('\n') - # fw('center="%.6g %.6g" ' % (0.0, 0.0)) - fw(ident_step + 'translation="%.6g %.6g"\n' % loc) - fw(ident_step + 'scale="%.6g %.6g"\n' % (sca_x, sca_y)) - fw(ident_step + 'rotation="%.6g"\n' % rot) + # fw('center="%.6f %.6f" ' % (0.0, 0.0)) + fw(ident_step + 'translation="%.6f %.6f"\n' % loc) + fw(ident_step + 'scale="%.6f %.6f"\n' % (sca_x, sca_y)) + fw(ident_step + 'rotation="%.6f"\n' % rot) fw(ident_step + '/>\n') if use_h3d: @@ -743,26 +747,26 @@ def export(file, fw('%s<Coordinate ' % ident) fw('point="') for x3d_v in vert_tri_list: - fw('%.6g %.6g %.6g ' % mesh_vertices[x3d_v[1]].co[:]) + fw('%.6f %.6f %.6f ' % mesh_vertices[x3d_v[1]].co[:]) fw('" />\n') if use_normals or is_force_normals: fw('%s<Normal ' % ident) fw('vector="') for x3d_v in vert_tri_list: - fw('%.6g %.6g %.6g ' % mesh_vertices[x3d_v[1]].normal[:]) + fw('%.6f %.6f %.6f ' % mesh_vertices[x3d_v[1]].normal[:]) fw('" />\n') if is_uv: fw('%s<TextureCoordinate point="' % ident) for x3d_v in vert_tri_list: - fw('%.4g %.4g ' % x3d_v[0][slot_uv]) + fw('%.4f %.4f ' % x3d_v[0][slot_uv]) fw('" />\n') if is_col: fw('%s<Color color="' % ident) for x3d_v in vert_tri_list: - fw('%.3g %.3g %.3g ' % x3d_v[0][slot_col]) + fw('%.3f %.3f %.3f ' % x3d_v[0][slot_col]) fw('" />\n') if use_h3d: @@ -777,7 +781,7 @@ def export(file, fw('numComponents="2" ') fw('value="') for x3d_v in vert_tri_list: - fw('%.4g %.4g ' % x3d_v[0][slot_uv]) + fw('%.4f %.4f ' % x3d_v[0][slot_uv]) fw('" />\n') else: assert(0) @@ -799,7 +803,7 @@ def export(file, # --- Write IndexedFaceSet Attributes (same as IndexedTriangleSet) fw('solid="%s"\n' % ('true' if mesh.show_double_sided else 'false')) if is_smooth: - fw(ident_step + 'creaseAngle="%.4g"\n' % mesh.auto_smooth_angle) + fw(ident_step + 'creaseAngle="%.4f"\n' % mesh.auto_smooth_angle) if use_normals: # currently not optional, could be made so: @@ -852,7 +856,7 @@ def export(file, fw('DEF=%s\n' % mesh_id_coords) fw(ident_step + 'point="') for v in mesh.vertices: - fw('%.6g %.6g %.6g ' % v.co[:]) + fw('%.6f %.6f %.6f ' % v.co[:]) fw('"\n') fw(ident_step + '/>\n') @@ -864,7 +868,7 @@ def export(file, fw('DEF=%s\n' % mesh_id_normals) fw(ident_step + 'vector="') for v in mesh.vertices: - fw('%.6g %.6g %.6g ' % v.normal[:]) + fw('%.6f %.6f %.6f ' % v.normal[:]) fw('"\n') fw(ident_step + '/>\n') @@ -872,7 +876,7 @@ def export(file, fw('%s<TextureCoordinate point="' % ident) for i in face_group: for uv in mesh_faces_uv[i].uv: - fw('%.4g %.4g ' % uv[:]) + fw('%.4f %.4f ' % uv[:]) del mesh_faces_uv fw('" />\n') @@ -880,7 +884,7 @@ def export(file, fw('%s<Color color="' % ident) # XXX, 1 color per face, only for i in face_group: - fw('%.3g %.3g %.3g ' % mesh_faces_col[i].color1[:]) + fw('%.3f %.3f %.3f ' % mesh_faces_col[i].color1[:]) fw('" />\n') #--- output vertexColors @@ -938,11 +942,11 @@ def export(file, ident_step = ident + (' ' * (-len(ident) + \ fw('%s<Material ' % ident))) fw('DEF=%s\n' % material_id) - fw(ident_step + 'diffuseColor="%.3g %.3g %.3g"\n' % clamp_color(diffuseColor)) - fw(ident_step + 'specularColor="%.3g %.3g %.3g"\n' % clamp_color(specColor)) - fw(ident_step + 'emissiveColor="%.3g %.3g %.3g"\n' % clamp_color(emitColor)) - fw(ident_step + 'ambientIntensity="%.3g"\n' % ambient) - fw(ident_step + 'shininess="%.3g"\n' % shininess) + fw(ident_step + 'diffuseColor="%.3f %.3f %.3f"\n' % clamp_color(diffuseColor)) + fw(ident_step + 'specularColor="%.3f %.3f %.3f"\n' % clamp_color(specColor)) + fw(ident_step + 'emissiveColor="%.3f %.3f %.3f"\n' % clamp_color(emitColor)) + fw(ident_step + 'ambientIntensity="%.3f"\n' % ambient) + fw(ident_step + 'shininess="%.3f"\n' % shininess) fw(ident_step + 'transparency="%s"\n' % transp) fw(ident_step + '/>\n') @@ -1078,7 +1082,7 @@ def export(file, 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 = '%.6g %.6g %.6g' % (global_matrix * lamp_obj.matrix_world).to_translation()[:] + value = '%.6f %.6f %.6f' % (global_matrix * lamp_obj.matrix_world).to_translation()[:] field_descr = " <!--- Lamp DynCo '%s' -->" % lamp_obj.name fw('%s<field name="%s" type="SFVec3f" accessType="inputOutput" value="%s" />%s\n' % (ident, uniform['varname'], value, field_descr)) @@ -1107,7 +1111,7 @@ def export(file, frag_uniform_var_map[uniform['varname']] = lamp_obj lamp = lamp_obj.data - value = '%.6g %.6g %.6g' % (lamp.color * lamp.energy)[:] + value = '%.6f %.6f %.6f' % (lamp.color * lamp.energy)[:] field_descr = " <!--- Lamp DynColor '%s' -->" % lamp_obj.name if uniform['datatype'] == gpu.GPU_DATA_3F: fw('%s<field name="%s" type="SFVec3f" accessType="inputOutput" value="%s" />%s\n' % (ident, uniform['varname'], value, field_descr)) @@ -1126,7 +1130,7 @@ def export(file, if uniform['datatype'] == gpu.GPU_DATA_3F: lamp_obj = uniform['lamp'] - value = '%.6g %.6g %.6g' % ((global_matrix * lamp_obj.matrix_world).to_quaternion() * mathutils.Vector((0.0, 0.0, 1.0))).normalized()[:] + value = '%.6f %.6f %.6f' % ((global_matrix * lamp_obj.matrix_world).to_quaternion() * mathutils.Vector((0.0, 0.0, 1.0))).normalized()[:] field_descr = " <!--- Lamp DynDirection '%s' -->" % lamp_obj.name fw('%s<field name="%s" type="SFVec3f" accessType="inputOutput" value="%s" />%s\n' % (ident, uniform['varname'], value, field_descr)) @@ -1194,7 +1198,7 @@ def export(file, #for i in range(0, 10, 4) #value = ' '.join(['%d' % f for f in uniform['texpixels']]) - # value = ' '.join(['%.6g' % (f / 256) for f in uniform['texpixels']]) + # value = ' '.join(['%.6f' % (f / 256) for f in uniform['texpixels']]) #fw('%s<field name="%s" type="SFInt32" accessType="inputOutput" value="%s" />%s\n' % (ident, uniform['varname'], value, field_descr)) #print('test', len(uniform['texpixels'])) @@ -1273,34 +1277,34 @@ def export(file, fw('DEF=%s\n' % world_id) # No Skytype - just Hor color if blending == (False, False, False): - fw(ident_step + 'groundColor="%.3g %.3g %.3g"\n' % grd_triple) - fw(ident_step + 'skyColor="%.3g %.3g %.3g"\n' % grd_triple) + fw(ident_step + 'groundColor="%.3f %.3f %.3f"\n' % grd_triple) + fw(ident_step + 'skyColor="%.3f %.3f %.3f"\n' % grd_triple) # Blend Gradient elif blending == (True, False, False): - fw(ident_step + 'groundColor="%.3g %.3g %.3g, %.3g %.3g %.3g"\n' % (grd_triple + mix_triple)) + fw(ident_step + 'groundColor="%.3f %.3f %.3f, %.3f %.3f %.3f"\n' % (grd_triple + mix_triple)) fw(ident_step + 'groundAngle="1.57, 1.57"\n') - fw(ident_step + 'skyColor="%.3g %.3g %.3g, %.3g %.3g %.3g"\n' % (sky_triple + mix_triple)) + fw(ident_step + 'skyColor="%.3f %.3f %.3f, %.3f %.3f %.3f"\n' % (sky_triple + mix_triple)) fw(ident_step + 'skyAngle="1.57, 1.57"\n') # Blend+Real Gradient Inverse elif blending == (True, False, True): - fw(ident_step + 'groundColor="%.3g %.3g %.3g, %.3g %.3g %.3g"\n' % (sky_triple + grd_triple)) + fw(ident_step + 'groundColor="%.3f %.3f %.3f, %.3f %.3f %.3f"\n' % (sky_triple + grd_triple)) fw(ident_step + 'groundAngle="1.57"\n') - fw(ident_step + 'skyColor="%.3g %.3g %.3g, %.3g %.3g %.3g, %.3g %.3g %.3g"\n' % (sky_triple + grd_triple + sky_triple)) + fw(ident_step + 'skyColor="%.3f %.3f %.3f, %.3f %.3f %.3f, %.3f %.3f %.3f"\n' % (sky_triple + grd_triple + sky_triple)) fw(ident_step + 'skyAngle="1.57, 3.14159"\n') # Paper - just Zen Color elif blending == (False, False, True): - fw(ident_step + 'groundColor="%.3g %.3g %.3g"\n' % sky_triple) - fw(ident_step + 'skyColor="%.3g %.3g %.3g"\n' % sky_triple) + fw(ident_step + 'groundColor="%.3f %.3f %.3f"\n' % sky_triple) + fw(ident_step + 'skyColor="%.3f %.3f %.3f"\n' % sky_triple) # Blend+Real+Paper - komplex gradient elif blending == (True, True, True): - fw(ident_step + 'groundColor="%.3g %.3g %.3g, %.3g %.3g %.3g"\n' % (sky_triple + grd_triple)) + fw(ident_step + 'groundColor="%.3f %.3f %.3f, %.3f %.3f %.3f"\n' % (sky_triple + grd_triple)) fw(ident_step + 'groundAngle="1.57, 1.57"\n') - fw(ident_step + 'skyColor="%.3g %.3g %.3g, %.3g %.3g %.3g"\n' % (sky_triple + grd_triple)) + fw(ident_step + 'skyColor="%.3f %.3f %.3f, %.3f %.3f %.3f"\n' % (sky_triple + grd_triple)) fw(ident_step + 'skyAngle="1.57, 1.57"\n') # Any Other two colors else: - fw(ident_step + 'groundColor="%.3g %.3g %.3g"\n' % grd_triple) - fw(ident_step + 'skyColor="%.3g %.3g %.3g"\n' % sky_triple) + fw(ident_step + 'groundColor="%.3f %.3f %.3f"\n' % grd_triple) + fw(ident_step + 'skyColor="%.3f %.3f %.3f"\n' % sky_triple) for tex in bpy.data.textures: if tex.type == 'IMAGE' and tex.image: