forked from bartvdbraak/blender
Collada: Import now always rotates input to match blender's Z_UP axis
This commit is contained in:
parent
c8958eea29
commit
1a3a252e06
@ -185,6 +185,7 @@ void DocumentImporter::finish()
|
|||||||
Main *bmain = CTX_data_main(mContext);
|
Main *bmain = CTX_data_main(mContext);
|
||||||
// TODO: create a new scene except the selected <visual_scene> - use current blender scene for it
|
// TODO: create a new scene except the selected <visual_scene> - use current blender scene for it
|
||||||
Scene *sce = CTX_data_scene(mContext);
|
Scene *sce = CTX_data_scene(mContext);
|
||||||
|
unit_converter.calculate_scale(*sce);
|
||||||
|
|
||||||
/** TODO Break up and put into 2-pass parsing of DAE */
|
/** TODO Break up and put into 2-pass parsing of DAE */
|
||||||
std::vector<const COLLADAFW::VisualScene *>::iterator it;
|
std::vector<const COLLADAFW::VisualScene *>::iterator it;
|
||||||
@ -224,10 +225,8 @@ void DocumentImporter::finish()
|
|||||||
std::vector<Object *> *objects_done;
|
std::vector<Object *> *objects_done;
|
||||||
objects_done = write_node(roots[i], NULL, sce, NULL, false);
|
objects_done = write_node(roots[i], NULL, sce, NULL, false);
|
||||||
|
|
||||||
if (!this->import_settings->import_units) {
|
// Match incoming scene with current unit settings
|
||||||
// Match incoming scene with current unit settings
|
bc_match_scale(objects_done, unit_converter, !this->import_settings->import_units);
|
||||||
bc_match_scale(objects_done, *sce, unit_converter);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// update scene
|
// update scene
|
||||||
|
@ -324,65 +324,30 @@ std::string bc_replace_string(std::string data, const std::string& pattern,
|
|||||||
* Calculate a rescale factor such that the imported scene's scale
|
* Calculate a rescale factor such that the imported scene's scale
|
||||||
* is preserved. I.e. 1 meter in the import will also be
|
* is preserved. I.e. 1 meter in the import will also be
|
||||||
* 1 meter in the current scene.
|
* 1 meter in the current scene.
|
||||||
* XXX : I am not sure if it is correct to map 1 Blender Unit
|
|
||||||
* to 1 Meter for unit type NONE. But it looks reasonable to me.
|
|
||||||
*/
|
*/
|
||||||
void bc_match_scale(std::vector<Object *> *objects_done,
|
|
||||||
Scene &sce,
|
void bc_match_scale(Object *ob, UnitConverter &bc_unit, bool scale_to_scene)
|
||||||
UnitConverter &bc_unit)
|
|
||||||
{
|
{
|
||||||
Object *ob = NULL;
|
if (scale_to_scene) {
|
||||||
|
mul_m4_m4m4(ob->obmat, bc_unit.get_scale(), ob->obmat);
|
||||||
PointerRNA scene_ptr, unit_settings;
|
|
||||||
PropertyRNA *system_ptr, *scale_ptr;
|
|
||||||
RNA_id_pointer_create(&sce.id, &scene_ptr);
|
|
||||||
|
|
||||||
unit_settings = RNA_pointer_get(&scene_ptr, "unit_settings");
|
|
||||||
system_ptr = RNA_struct_find_property(&unit_settings, "system");
|
|
||||||
scale_ptr = RNA_struct_find_property(&unit_settings, "scale_length");
|
|
||||||
|
|
||||||
int type = RNA_property_enum_get(&unit_settings, system_ptr);
|
|
||||||
|
|
||||||
float bl_scale;
|
|
||||||
|
|
||||||
switch (type) {
|
|
||||||
case USER_UNIT_NONE:
|
|
||||||
bl_scale = 1.0; // map 1 Blender unit to 1 Meter
|
|
||||||
break;
|
|
||||||
|
|
||||||
case USER_UNIT_METRIC:
|
|
||||||
bl_scale = RNA_property_float_get(&unit_settings, scale_ptr);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default :
|
|
||||||
bl_scale = RNA_property_float_get(&unit_settings, scale_ptr);
|
|
||||||
// it looks like the conversion to Imperial is done implicitly.
|
|
||||||
// So nothing to do here.
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
mul_m4_m4m4(ob->obmat, bc_unit.get_rotation(), ob->obmat);
|
||||||
float scale_conv = bc_unit.getLinearMeter() / bl_scale;
|
BKE_object_apply_mat4(ob, ob->obmat, 0, 0);
|
||||||
|
}
|
||||||
float rescale[3];
|
|
||||||
rescale[0] = rescale[1] = rescale[2] = scale_conv;
|
|
||||||
|
|
||||||
float size_mat4[4][4];
|
|
||||||
|
|
||||||
float axis_mat4[4][4];
|
|
||||||
unit_m4(axis_mat4);
|
|
||||||
|
|
||||||
size_to_mat4(size_mat4, rescale);
|
|
||||||
|
|
||||||
|
void bc_match_scale(std::vector<Object *> *objects_done,
|
||||||
|
UnitConverter &bc_unit,
|
||||||
|
bool scale_to_scene)
|
||||||
|
{
|
||||||
for (std::vector<Object *>::iterator it = objects_done->begin();
|
for (std::vector<Object *>::iterator it = objects_done->begin();
|
||||||
it != objects_done->end();
|
it != objects_done->end();
|
||||||
++it)
|
++it)
|
||||||
{
|
{
|
||||||
ob = *it;
|
Object *ob = *it;
|
||||||
mul_m4_m4m4(ob->obmat, size_mat4, ob->obmat);
|
if (ob -> parent == NULL) {
|
||||||
mul_m4_m4m4(ob->obmat, bc_unit.get_rotation(), ob->obmat);
|
bc_match_scale(*it, bc_unit, scale_to_scene);
|
||||||
BKE_object_apply_mat4(ob, ob->obmat, 0, 0);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void bc_triangulate_mesh(Mesh *me)
|
void bc_triangulate_mesh(Mesh *me)
|
||||||
|
@ -83,7 +83,8 @@ extern int bc_get_active_UVLayer(Object *ob);
|
|||||||
|
|
||||||
extern std::string bc_replace_string(std::string data, const std::string& pattern, const std::string& replacement);
|
extern std::string bc_replace_string(std::string data, const std::string& pattern, const std::string& replacement);
|
||||||
extern std::string bc_url_encode(std::string data);
|
extern std::string bc_url_encode(std::string data);
|
||||||
extern void bc_match_scale(std::vector<Object *> *objects_done, Scene &sce, UnitConverter &unit_converter);
|
extern void bc_match_scale(Object *ob, UnitConverter &bc_unit, bool scale_to_scene);
|
||||||
|
extern void bc_match_scale(std::vector<Object *> *objects_done, UnitConverter &unit_converter, bool scale_to_scene);
|
||||||
|
|
||||||
extern void bc_triangulate_mesh(Mesh *me);
|
extern void bc_triangulate_mesh(Mesh *me);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user