|
@@ -228,6 +228,7 @@ postMessage( model );
|
|
|
"""
|
|
|
|
|
|
TEMPLATE_VERTEX = "%f,%f,%f"
|
|
|
+TEMPLATE_VERTEX_TRUNCATE = "%d,%d,%d"
|
|
|
|
|
|
TEMPLATE_N = "%f,%f,%f"
|
|
|
TEMPLATE_UV = "%f,%f"
|
|
@@ -391,8 +392,11 @@ def bottom(vertices):
|
|
|
def hexcolor(c):
|
|
|
return ( int(c[0] * 255) << 16 ) + ( int(c[1] * 255) << 8 ) + int(c[2] * 255)
|
|
|
|
|
|
-def generate_vertex(v):
|
|
|
- return TEMPLATE_VERTEX % (v.co.x, v.co.y, v.co.z)
|
|
|
+def generate_vertex(v, truncate):
|
|
|
+ if truncate:
|
|
|
+ return TEMPLATE_VERTEX_TRUNCATE % (v.co.x, v.co.y, v.co.z)
|
|
|
+ else:
|
|
|
+ return TEMPLATE_VERTEX % (v.co.x, v.co.y, v.co.z)
|
|
|
|
|
|
def generate_normal(n):
|
|
|
return TEMPLATE_N % (n[0], n[1], n[2])
|
|
@@ -737,7 +741,7 @@ def generate_materials_string(mesh, scene, use_colors, draw_type):
|
|
|
# ASCII model generator
|
|
|
# #####################################################
|
|
|
|
|
|
-def generate_ascii_model(mesh, scene, use_normals, use_colors, use_uv_coords, use_materials, align_model, flipyz, draw_type):
|
|
|
+def generate_ascii_model(mesh, scene, use_normals, use_colors, use_uv_coords, use_materials, align_model, flipyz, option_truncate, draw_type):
|
|
|
|
|
|
vertices = mesh.vertices[:]
|
|
|
|
|
@@ -772,7 +776,7 @@ def generate_ascii_model(mesh, scene, use_normals, use_colors, use_uv_coords, us
|
|
|
|
|
|
"materials" : mstring,
|
|
|
|
|
|
- "vertices" : ",".join(generate_vertex(v) for v in vertices),
|
|
|
+ "vertices" : ",".join(generate_vertex(v, option_truncate) for v in vertices),
|
|
|
|
|
|
"faces" : ",".join(generate_face(f, i, normals, uvs, colors, mesh, use_normals, use_colors, use_uv_coords, use_materials, flipyz) for i, f in enumerate(mesh.faces))
|
|
|
|
|
@@ -785,13 +789,13 @@ def generate_ascii_model(mesh, scene, use_normals, use_colors, use_uv_coords, us
|
|
|
# Model exporter - export single mesh
|
|
|
# #####################################################
|
|
|
|
|
|
-def export_mesh(obj, scene, filepath, use_normals, use_colors, use_uv_coords, use_materials, align_model, flipyz, export_single_model):
|
|
|
+def export_mesh(obj, scene, filepath, use_normals, use_colors, use_uv_coords, use_materials, align_model, flipyz, option_truncate, option_scale, export_single_model):
|
|
|
"""Export single mesh"""
|
|
|
|
|
|
|
|
|
# collapse modifiers into mesh
|
|
|
|
|
|
- mesh = obj.create_mesh(scene, True, 'RENDER')
|
|
|
+ mesh = obj.create_mesh(scene, True, 'RENDER')
|
|
|
|
|
|
if not mesh:
|
|
|
raise Exception("Error, could not get mesh data from object [%s]" % obj.name)
|
|
@@ -806,6 +810,8 @@ def export_mesh(obj, scene, filepath, use_normals, use_colors, use_uv_coords, us
|
|
|
else:
|
|
|
mesh.transform(X_ROT)
|
|
|
|
|
|
+ mesh.transform(mathutils.Matrix.Scale(option_scale, 4))
|
|
|
+
|
|
|
mesh.calc_normals()
|
|
|
|
|
|
faceUV = (len(mesh.uv_textures) > 0)
|
|
@@ -828,7 +834,7 @@ def export_mesh(obj, scene, filepath, use_normals, use_colors, use_uv_coords, us
|
|
|
if not active_col_layer:
|
|
|
use_colors = False
|
|
|
|
|
|
- text = generate_ascii_model(mesh, scene, use_normals, use_colors, use_uv_coords, use_materials, align_model, flipyz, obj.draw_type)
|
|
|
+ text = generate_ascii_model(mesh, scene, use_normals, use_colors, use_uv_coords, use_materials, align_model, flipyz, option_truncate, obj.draw_type)
|
|
|
write_file(filepath, text)
|
|
|
|
|
|
# remove temp mesh
|
|
@@ -929,7 +935,7 @@ def generate_objects(data):
|
|
|
group_string = generate_string_list(group_ids)
|
|
|
|
|
|
castsShadow = generate_bool_property(obj.THREE_castsShadow)
|
|
|
- meshCollider = generate_bool_property(obj.THREE_meshCollider)
|
|
|
+ meshCollider = generate_bool_property(obj.THREE_meshCollider)
|
|
|
|
|
|
object_string = TEMPLATE_OBJECT % {
|
|
|
"object_id" : generate_string(object_id),
|
|
@@ -1255,7 +1261,7 @@ def export_scene(scene, filepath, flipyz):
|
|
|
# Main
|
|
|
# #####################################################
|
|
|
|
|
|
-def save(operator, context, filepath = "", option_flip_yz = True, use_normals = True, use_colors = True, use_uv_coords = True, use_materials = True, align_model = 0, option_export_scene = True):
|
|
|
+def save(operator, context, filepath = "", option_flip_yz = True, use_normals = True, use_colors = True, use_uv_coords = True, use_materials = True, align_model = 0, option_export_scene = False, option_truncate = False, option_scale = 1.0):
|
|
|
|
|
|
filepath = ensure_extension(filepath, '.js')
|
|
|
|
|
@@ -1286,7 +1292,7 @@ def save(operator, context, filepath = "", option_flip_yz = True, use_normals =
|
|
|
|
|
|
if name not in geo_set:
|
|
|
fname = generate_mesh_filename(name, filepath)
|
|
|
- export_mesh(obj, scene, fname, use_normals, use_colors, use_uv_coords, use_materials, 0, option_flip_yz, False)
|
|
|
+ export_mesh(obj, scene, fname, use_normals, use_colors, use_uv_coords, use_materials, 0, option_flip_yz, option_truncate, option_scale, False)
|
|
|
|
|
|
geo_set.add(name)
|
|
|
|
|
@@ -1296,7 +1302,7 @@ def save(operator, context, filepath = "", option_flip_yz = True, use_normals =
|
|
|
if not obj:
|
|
|
raise Exception("Error, Select 1 active object or select 'export scene'")
|
|
|
|
|
|
- export_mesh(obj, scene, filepath, use_normals, use_colors, use_uv_coords, use_materials, align_model, option_flip_yz, True)
|
|
|
+ export_mesh(obj, scene, filepath, use_normals, use_colors, use_uv_coords, use_materials, align_model, option_flip_yz, option_truncate, option_scale, True)
|
|
|
|
|
|
|
|
|
return {'FINISHED'}
|