Skip to content

Commit 74d8000

Browse files
authored
Merge pull request #7 from Lamoot/limit-precision
Option to limit precision of exported data
2 parents b3481da + 0f0ee8a commit 74d8000

File tree

2 files changed

+72
-19
lines changed

2 files changed

+72
-19
lines changed

io_scene_dae/__init__.py

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# ##### END GPL LICENSE BLOCK #####
1717

1818
import bpy
19-
from bpy.props import StringProperty, BoolProperty, FloatProperty, EnumProperty
19+
from bpy.props import StringProperty, BoolProperty, FloatProperty, EnumProperty, IntProperty
2020

2121
from bpy_extras.io_utils import ExportHelper
2222
bl_info = {
@@ -177,6 +177,14 @@ class CE_OT_export_dae(bpy.types.Operator, ExportHelper):
177177
default=False,
178178
)
179179

180+
use_limit_precision : IntProperty(
181+
name="Data Precision",
182+
description=("To how many decimals are the exported values limited. \n"
183+
"The lower the number, the smaller the exported file"),
184+
min=4, max=16,
185+
default=6,
186+
)
187+
180188
@property
181189
def check_extension(self):
182190
return True
@@ -347,15 +355,41 @@ def draw(self, context):
347355
col.prop(operator, 'use_anim_skip_noexp')
348356
col.prop(operator, 'use_anim_optimize')
349357
col.prop(operator, 'anim_optimize_precision')
358+
359+
class DAE_PT_export_extras(bpy.types.Panel):
360+
bl_space_type = 'FILE_BROWSER'
361+
bl_region_type = 'TOOL_PROPS'
362+
bl_label = "Extra"
363+
bl_parent_id = "FILE_PT_operator"
364+
bl_options = {'DEFAULT_CLOSED'}
350365

366+
@classmethod
367+
def poll(cls, context):
368+
sfile = context.space_data
369+
operator = sfile.active_operator
370+
371+
return operator.bl_idname == "EXPORT_SCENE_OT_dae"
372+
373+
def draw(self, context):
374+
layout = self.layout
375+
layout.use_property_split = True
376+
layout.use_property_decorate = False
377+
378+
sfile = context.space_data
379+
operator = sfile.active_operator
380+
381+
col = layout.column(align = True)
382+
col.prop(operator, 'use_limit_precision')
351383

352384
classes = (
353385
CE_OT_export_dae,
354386
DAE_PT_export_include,
355387
DAE_PT_export_transform,
356388
DAE_PT_export_geometry,
357389
DAE_PT_export_armature,
358-
DAE_PT_export_animation
390+
DAE_PT_export_animation,
391+
DAE_PT_export_extras
392+
359393
)
360394

361395
def register():

io_scene_dae/export_dae.py

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,16 @@ def snap_tup(tup):
5757
return tup
5858

5959

60-
def strmtx(mtx, scale=1.0):
60+
def strmtx(mtx, scale=1.0, limit=16):
6161
# When scaling the exported data, we only want to affect distances,
6262
# so we only multiply location values in the transform matrix.
6363
mtx_util = Matrix([[0,0,0,0], [0,0,0,0],[0,0,0,0],[0,0,0,scale-1]])
6464
mtx = (mtx * scale).normalized() - mtx_util
65-
65+
6666
s = ""
6767
for x in range(4):
6868
for y in range(4):
69-
s += "{} ".format(mtx[x][y])
69+
s += "{} ".format(round((mtx[x][y]), limit))
7070
s = " {} ".format(s)
7171
return s
7272

@@ -776,9 +776,12 @@ def export_mesh(self, node, armature=None, skeyindex=-1, skel_source=None,
776776
self.writel(S_GEOM, 3, "<source id=\"{}-positions\">".format(meshid))
777777
float_values = ""
778778
sf = self.config["scale_factor"]
779+
lim = self.config["use_limit_precision"]
779780
for v in vertices:
780781
float_values += " {} {} {}".format(
781-
v.vertex.x * sf, v.vertex.y * sf, v.vertex.z * sf)
782+
round(v.vertex.x * sf, lim),
783+
round(v.vertex.y * sf, lim),
784+
round(v.vertex.z * sf, lim))
782785
self.writel(
783786
S_GEOM, 4, "<float_array id=\"{}-positions-array\" "
784787
"count=\"{}\">{}</float_array>".format(
@@ -799,7 +802,9 @@ def export_mesh(self, node, armature=None, skeyindex=-1, skel_source=None,
799802
float_values = ""
800803
for v in vertices:
801804
float_values += " {} {} {}".format(
802-
v.normal.x, v.normal.y, v.normal.z)
805+
round(v.normal.x, lim),
806+
round(v.normal.y, lim),
807+
round(v.normal.z, lim))
803808
self.writel(
804809
S_GEOM, 4, "<float_array id=\"{}-normals-array\" "
805810
"count=\"{}\">{}</float_array>".format(
@@ -821,7 +826,9 @@ def export_mesh(self, node, armature=None, skeyindex=-1, skel_source=None,
821826
float_values = ""
822827
for v in vertices:
823828
float_values += " {} {} {}".format(
824-
v.tangent.x, v.tangent.y, v.tangent.z)
829+
round(v.tangent.x, lim),
830+
round(v.tangent.y, lim),
831+
round(v.tangent.z, lim))
825832
self.writel(
826833
S_GEOM, 4, "<float_array id=\"{}-tangents-array\" "
827834
"count=\"{}\">{}</float_array>".format(
@@ -842,7 +849,9 @@ def export_mesh(self, node, armature=None, skeyindex=-1, skel_source=None,
842849
float_values = ""
843850
for v in vertices:
844851
float_values += " {} {} {}".format(
845-
v.bitangent.x, v.bitangent.y, v.bitangent.z)
852+
round(v.bitangent.x, lim),
853+
round(v.bitangent.y, lim),
854+
round(v.bitangent.z, lim))
846855
self.writel(
847856
S_GEOM, 4, "<float_array id=\"{}-bitangents-array\" "
848857
"count=\"{}\">{}</float_array>".format(
@@ -865,7 +874,9 @@ def export_mesh(self, node, armature=None, skeyindex=-1, skel_source=None,
865874
float_values = ""
866875
for v in vertices:
867876
try:
868-
float_values += " {} {}".format(v.uv[uvi].x, v.uv[uvi].y)
877+
float_values += " {} {}".format(
878+
round(v.uv[uvi].x, lim),
879+
round(v.uv[uvi].y, lim))
869880
except:
870881
# TODO: Review, understand better the multi-uv-layer API
871882
float_values += " 0 0 "
@@ -891,7 +902,9 @@ def export_mesh(self, node, armature=None, skeyindex=-1, skel_source=None,
891902
float_values = ""
892903
for v in vertices:
893904
float_values += " {} {} {}".format(
894-
v.color.x, v.color.y, v.color.z)
905+
round(v.color.x, lim),
906+
round(v.color.y, lim),
907+
round(v.color.z, lim))
895908
self.writel(
896909
S_GEOM, 4, "<float_array id=\"{}-colors-array\" "
897910
"count=\"{}\">{}</float_array>".format(
@@ -998,10 +1011,11 @@ def export_mesh(self, node, armature=None, skeyindex=-1, skel_source=None,
9981011
skel_source))
9991012
else:
10001013
self.writel(S_SKIN, 2, "<skin source=\"#{}\">".format(meshid))
1001-
1014+
1015+
lim = self.config["use_limit_precision"]
10021016
self.writel(
10031017
S_SKIN, 3, "<bind_shape_matrix>{}</bind_shape_matrix>".format(
1004-
strmtx(node.matrix_world)))
1018+
strmtx(node.matrix_world, 1, lim)))
10051019
# Joint Names
10061020
self.writel(S_SKIN, 3, "<source id=\"{}-joints\">".format(contid))
10071021
name_values = ""
@@ -1026,8 +1040,9 @@ def export_mesh(self, node, armature=None, skeyindex=-1, skel_source=None,
10261040
contid))
10271041
pose_values = ""
10281042
sf = self.config["scale_factor"]
1043+
lim = self.config["use_limit_precision"]
10291044
for v in si["bone_bind_poses"]:
1030-
pose_values += " {}".format(strmtx(v, sf))
1045+
pose_values += " {}".format(strmtx(v, sf, lim))
10311046

10321047
self.writel(
10331048
S_SKIN, 4, "<float_array id=\"{}-bind_poses-array\" "
@@ -1051,7 +1066,7 @@ def export_mesh(self, node, armature=None, skeyindex=-1, skel_source=None,
10511066
for v in vertices:
10521067
skin_weights_total += len(v.weights)
10531068
for w in v.weights:
1054-
skin_weights += " {}".format(w)
1069+
skin_weights += " {}".format(round(w, lim))
10551070

10561071
self.writel(
10571072
S_SKIN, 4, "<float_array id=\"{}-skin_weights-array\" "
@@ -1239,10 +1254,11 @@ def export_armature_bone(self, bone, il, si):
12391254
si["skeleton_nodes"].append(boneid)
12401255

12411256
sf = self.config["scale_factor"]
1257+
lim = self.config["use_limit_precision"]
12421258
if (is_ctrl_bone is False):
12431259
self.writel(
12441260
S_NODES, il, "<matrix sid=\"transform\">{}</matrix>".format(
1245-
strmtx(xform, sf)))
1261+
strmtx(xform, sf, lim)))
12461262

12471263
for c in bone.children:
12481264
self.export_armature_bone(c, il, si)
@@ -1584,9 +1600,10 @@ def export_node(self, node, il):
15841600
il += 1
15851601

15861602
sf = self.config["scale_factor"]
1603+
lim = self.config["use_limit_precision"]
15871604
self.writel(
15881605
S_NODES, il, "<matrix sid=\"transform\">{}</matrix>".format(
1589-
strmtx(node.matrix_local, sf)))
1606+
strmtx(node.matrix_local, sf, lim)))
15901607
if (node.type == "MESH"):
15911608
self.export_mesh_node(node, il)
15921609
elif (node.type == "CURVE"):
@@ -1682,10 +1699,11 @@ def export_animation_transform_channel(self, target, keys, matrices=True):
16821699
source_interps = ""
16831700

16841701
sf = self.config["scale_factor"]
1702+
lim = self.config["use_limit_precision"]
16851703
for k in keys:
16861704
source_frames += " {}".format(k[0])
16871705
if (matrices):
1688-
source_transforms += " {}".format(strmtx(k[1], sf))
1706+
source_transforms += " {}".format(strmtx(k[1], sf, lim))
16891707
else:
16901708
source_transforms += " {}".format(k[1])
16911709

@@ -2019,8 +2037,9 @@ def sort_by_frame(item):
20192037
markers.append(m)
20202038
markers.sort(key=sort_by_frame)
20212039

2040+
lim = self.config["use_limit_precision"]
20222041
for m in markers:
2023-
tkf = round(m.frame * 1/scene.render.fps, 6)
2042+
tkf = round(m.frame * 1/scene.render.fps, lim)
20242043
textkeys_output.write(m.name + " " + str(tkf) + '\n' )
20252044
textkeys_output.close()
20262045

0 commit comments

Comments
 (0)