fix: Collada: The limit precision option does nothing

This commit is contained in:
Gaia Clary 2018-11-26 23:05:55 +01:00
parent f753fd1779
commit 65874d3f33
7 changed files with 57 additions and 16 deletions

View File

@ -304,7 +304,7 @@ void ArmatureExporter::add_bone_transform(Object *ob_arm, Bone *bone, COLLADASW:
}
if (this->export_settings->limit_precision)
bc_sanitize_mat(mat, 6);
bc_sanitize_mat(mat, LIMITTED_PRECISION);
TransformWriter::add_node_transform(node, mat, NULL);

View File

@ -533,7 +533,7 @@ std::string ControllerExporter::add_inv_bind_mats_source(Object *ob_arm, ListBas
invert_m4_m4(mat, world);
UnitConverter::mat4_to_dae(inv_bind_mat, mat);
if (this->export_settings->limit_precision)
bc_sanitize_mat(inv_bind_mat, 6);
bc_sanitize_mat(inv_bind_mat, LIMITTED_PRECISION);
source.appendValues(inv_bind_mat);
}
}

View File

@ -36,10 +36,10 @@ extern "C" {
void SceneExporter::exportScene()
{
ViewLayer *view_layer = blender_context.get_view_layer();
Scene *scene = blender_context.get_scene();
// <library_visual_scenes> <visual_scene>
std::string name = id_name(view_layer);
std::string name = id_name(scene);
openVisualScene(translate_id(name), encode_xml(name));
exportHierarchy();
closeVisualScene();
@ -136,7 +136,12 @@ void SceneExporter::writeNodes(Object *ob)
TransformWriter::add_node_transform_identity(colladaNode);
}
else {
TransformWriter::add_node_transform_ob(colladaNode, ob, this->export_settings->export_transformation_type);
TransformWriter::add_node_transform_ob(
colladaNode,
ob,
this->export_settings->export_transformation_type,
this->export_settings->limit_precision
);
}
// <instance_geometry>

View File

@ -33,7 +33,7 @@
#include "TransformWriter.h"
void TransformWriter::add_node_transform(COLLADASW::Node& node, float mat[4][4], float parent_mat[4][4])
void TransformWriter::add_node_transform(COLLADASW::Node& node, float mat[4][4], float parent_mat[4][4], bool limit_precision)
{
float loc[3], rot[3], scale[3];
float local[4][4];
@ -63,8 +63,11 @@ void TransformWriter::add_node_transform(COLLADASW::Node& node, float mat[4][4],
}
}
void TransformWriter::add_node_transform_ob(COLLADASW::Node& node, Object *ob,
BC_export_transformation_type transformation_type)
void TransformWriter::add_node_transform_ob(
COLLADASW::Node& node,
Object *ob,
BC_export_transformation_type transformation_type,
bool limit_precision)
{
#if 0
float rot[3], loc[3], scale[3];
@ -101,17 +104,18 @@ void TransformWriter::add_node_transform_ob(COLLADASW::Node& node, Object *ob,
add_transform(node, loc, rot, scale);
#endif
UnitConverter converter;
double d_obmat[4][4];
float f_obmat[4][4];
/* Export the local Matrix (relative to the object parent, be it an object, bone or vertex(-tices)) */
float f_obmat[4][4];
BKE_object_matrix_local_get(ob, f_obmat);
converter.mat4_to_dae_double(d_obmat, f_obmat);
switch (transformation_type) {
case BC_TRANSFORMATION_TYPE_MATRIX:
{
UnitConverter converter;
double d_obmat[4][4];
converter.mat4_to_dae_double(d_obmat, f_obmat);
if (limit_precision)
bc_sanitize_mat(d_obmat, LIMITTED_PRECISION);
node.addMatrix("transform",d_obmat);
break;
}
@ -119,6 +123,11 @@ void TransformWriter::add_node_transform_ob(COLLADASW::Node& node, Object *ob,
{
float loc[3], rot[3], scale[3];
bc_decompose(f_obmat, loc, rot, NULL, scale);
if (limit_precision) {
bc_sanitize_v3(loc, LIMITTED_PRECISION);
bc_sanitize_v3(rot, LIMITTED_PRECISION);
bc_sanitize_v3(scale, LIMITTED_PRECISION);
}
add_transform(node, loc, rot, scale);
break;
}

View File

@ -39,10 +39,17 @@
class TransformWriter
{
protected:
void add_node_transform(COLLADASW::Node& node, float mat[4][4], float parent_mat[4][4]);
void add_node_transform(
COLLADASW::Node& node,
float mat[4][4],
float parent_mat[4][4],
bool limit_precision=false);
void add_node_transform_ob(COLLADASW::Node& node, Object *ob,
BC_export_transformation_type transformation_type);
void add_node_transform_ob(
COLLADASW::Node& node,
Object *ob,
BC_export_transformation_type transformation_type,
bool limit_precision = false);
void add_node_transform_identity(COLLADASW::Node& node);

View File

@ -1135,6 +1135,15 @@ void bc_sanitize_mat(float mat[4][4], int precision)
}
}
void bc_sanitize_v3(float v[3], int precision)
{
for (int i = 0; i < 3; i++) {
double val = (double)v[i];
val = double_round(val, precision);
v[i] = (float)val;
}
}
void bc_sanitize_mat(double mat[4][4], int precision)
{
for (int i = 0; i < 4; i++)
@ -1142,6 +1151,13 @@ void bc_sanitize_mat(double mat[4][4], int precision)
mat[i][j] = double_round(mat[i][j], precision);
}
void bc_sanitize_v3(double v[3], int precision)
{
for (int i = 0; i < 3; i++) {
v[i] = double_round(v[i], precision);
}
}
void bc_copy_m4_farray(float r[4][4], float *a)
{
for (int i = 0; i < 4; i++)

View File

@ -74,6 +74,8 @@ extern "C" {
#include "BCSampleData.h"
#include "BlenderContext.h"
static int LIMITTED_PRECISION = 6;
struct Depsgraph;
typedef std::map<COLLADAFW::UniqueId, Image*> UidImageMap;
@ -209,6 +211,8 @@ void bc_copy_v44_m4d(std::vector<std::vector<double>> &a, double(&r)[4][4]);
void bc_sanitize_mat(float mat[4][4], int precision);
void bc_sanitize_mat(double mat[4][4], int precision);
void bc_sanitize_v3(double v[3], int precision);
void bc_sanitize_v3(float v[3], int precision);
extern IDProperty *bc_get_IDProperty(Bone *bone, std::string key);
extern void bc_set_IDProperty(EditBone *ebone, const char *key, float value);