提交 e6fd2d05 编写于 作者: M Mr.doob

Blender Exporter: Added option for truncating vertex values. Added scale parameter.

上级 09e976f2
......@@ -129,6 +129,8 @@ class ExportTHREEJS(bpy.types.Operator, ExportHelper):
use_colors = BoolProperty(name="Colors", description="Export vertex colors", default=True)
use_uv_coords = BoolProperty(name="UVs", description="Export texture coordinates", default=True)
option_export_scene = BoolProperty(name="Scene", description="Export scene", default=False)
option_truncate = BoolProperty(name="Truncate", description="Truncate decimals", default=False)
option_scale = FloatProperty(name="Scale", description="Scale data", min=0.01, max=1000.0, soft_min=0.01, soft_max=1000.0, default=1.0)
align_types = [("None","None","None"), ("Center","Center","Center"), ("Bottom","Bottom","Bottom"), ("Top","Top","Top")]
align_model = EnumProperty(name="Align model", description="Align model", items=align_types, default="None")
......@@ -164,12 +166,15 @@ class ExportTHREEJS(bpy.types.Operator, ExportHelper):
row = layout.row()
row.prop(self.properties, "use_normals")
row = layout.row()
row.prop(self.properties, "use_colors")
row = layout.row()
row.prop(self.properties, "use_uv_coords")
row = layout.row()
row.prop(self.properties, "use_materials")
layout.separator()
row = layout.row()
row.prop(self.properties, "option_truncate")
row.prop(self.properties, "option_scale")
# ################################################################
......
......@@ -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'}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册