diff options
Diffstat (limited to 'source/blender/collada')
-rw-r--r-- | source/blender/collada/DocumentImporter.cpp | 29 | ||||
-rw-r--r-- | source/blender/collada/MeshImporter.cpp | 7 | ||||
-rw-r--r-- | source/blender/collada/MeshImporter.h | 4 | ||||
-rw-r--r-- | source/blender/collada/collada_internal.cpp | 32 | ||||
-rw-r--r-- | source/blender/collada/collada_internal.h | 14 |
5 files changed, 72 insertions, 14 deletions
diff --git a/source/blender/collada/DocumentImporter.cpp b/source/blender/collada/DocumentImporter.cpp index 40e4d389b88..a406845c8a2 100644 --- a/source/blender/collada/DocumentImporter.cpp +++ b/source/blender/collada/DocumentImporter.cpp @@ -72,6 +72,8 @@ #include "DNA_camera_types.h" #include "DNA_lamp_types.h" +#include "RNA_access.h" + #include "MEM_guardedalloc.h" #include "DocumentImporter.h" @@ -130,7 +132,7 @@ public: /** Constructor. */ Writer(bContext *C, const char *filename) : mFilename(filename), mContext(C), armature_importer(&unit_converter, &mesh_importer, &anim_importer, CTX_data_scene(C)), - mesh_importer(&armature_importer, CTX_data_scene(C)), + mesh_importer(&unit_converter, &armature_importer, CTX_data_scene(C)), anim_importer(&unit_converter, &armature_importer, CTX_data_scene(C)) {} /** Destructor. */ @@ -172,8 +174,30 @@ public: { std::vector<const COLLADAFW::VisualScene*>::iterator it; for (it = vscenes.begin(); it != vscenes.end(); it++) { + PointerRNA sceneptr, unit_settings; + PropertyRNA *system, *scale; // TODO: create a new scene except the selected <visual_scene> - use current blender scene for it Scene *sce = CTX_data_scene(mContext); + + // for scene unit settings: system, scale_length + RNA_id_pointer_create(&sce->id, &sceneptr); + unit_settings = RNA_pointer_get(&sceneptr, "unit_settings"); + system = RNA_struct_find_property(&unit_settings, "system"); + scale = RNA_struct_find_property(&unit_settings, "scale_length"); + + switch(unit_converter.isMetricSystem()) { + case UnitConverter::Metric: + RNA_property_enum_set(&unit_settings, system, USER_UNIT_METRIC); + break; + case UnitConverter::Imperial: + RNA_property_enum_set(&unit_settings, system, USER_UNIT_IMPERIAL); + break; + default: + RNA_property_enum_set(&unit_settings, system, USER_UNIT_NONE); + break; + } + RNA_property_float_set(&unit_settings, scale, unit_converter.getLinearMeter()); + const COLLADAFW::NodePointerArray& roots = (*it)->getRootNodes(); for (unsigned int i = 0; i < roots.getCount(); i++) { @@ -253,9 +277,6 @@ public: @return The writer should return true, if writing succeeded, false otherwise.*/ virtual bool writeGlobalAsset ( const COLLADAFW::FileInfo* asset ) { - // XXX take up_axis, unit into account - // COLLADAFW::FileInfo::Unit unit = asset->getUnit(); - // COLLADAFW::FileInfo::UpAxisType upAxis = asset->getUpAxisType(); unit_converter.read_asset(asset); return true; diff --git a/source/blender/collada/MeshImporter.cpp b/source/blender/collada/MeshImporter.cpp index df5136f1cb4..44ac310e353 100644 --- a/source/blender/collada/MeshImporter.cpp +++ b/source/blender/collada/MeshImporter.cpp @@ -323,8 +323,9 @@ void MeshImporter::read_vertices(COLLADAFW::Mesh *mesh, Mesh *me) MVert *mvert; int i; - for (i = 0, mvert = me->mvert; i < me->totvert; i++, mvert++) + for (i = 0, mvert = me->mvert; i < me->totvert; i++, mvert++) { get_vector(mvert->co, pos, i); + } } int MeshImporter::triangulate_poly(unsigned int *indices, int totvert, MVert *verts, std::vector<unsigned int>& tri) @@ -631,7 +632,7 @@ void MeshImporter::read_faces(COLLADAFW::Mesh *mesh, Mesh *me, int new_tris) } } - mat_prim_map[mp->getMaterialId()].push_back(prim); + mat_prim_map[mp->getMaterialId()].push_back(prim); } geom_uid_mat_mapping_map[mesh->getUniqueId()] = mat_prim_map; @@ -689,7 +690,7 @@ bool MeshImporter::flat_face(unsigned int *nind, COLLADAFW::MeshVertexData& nor, return true; } -MeshImporter::MeshImporter(ArmatureImporter *arm, Scene *sce) : scene(sce), armature_importer(arm) {} +MeshImporter::MeshImporter(UnitConverter *unitconv, ArmatureImporter *arm, Scene *sce) : unitconverter(unitconv), scene(sce), armature_importer(arm) {} Object *MeshImporter::get_object_by_geom_uid(const COLLADAFW::UniqueId& geom_uid) { diff --git a/source/blender/collada/MeshImporter.h b/source/blender/collada/MeshImporter.h index 1fa9ebfbabc..055c4798855 100644 --- a/source/blender/collada/MeshImporter.h +++ b/source/blender/collada/MeshImporter.h @@ -119,10 +119,12 @@ private: void get_vector(float v[3], COLLADAFW::MeshVertexData& arr, int i); bool flat_face(unsigned int *nind, COLLADAFW::MeshVertexData& nor, int count); + + UnitConverter *unitconverter; public: - MeshImporter(ArmatureImporter *arm, Scene *sce); + MeshImporter(UnitConverter *unitconv, ArmatureImporter *arm, Scene *sce); virtual Object *get_object_by_geom_uid(const COLLADAFW::UniqueId& geom_uid); diff --git a/source/blender/collada/collada_internal.cpp b/source/blender/collada/collada_internal.cpp index 67ee4818f7e..6f401c1856f 100644 --- a/source/blender/collada/collada_internal.cpp +++ b/source/blender/collada/collada_internal.cpp @@ -28,12 +28,38 @@ UnitConverter::UnitConverter() : unit(), up_axis(COLLADAFW::FileInfo::Z_UP) {} void UnitConverter::read_asset(const COLLADAFW::FileInfo* asset) { + unit = asset->getUnit(); + up_axis = asset->getUpAxisType(); } -// TODO -// convert vector vec from COLLADA format to Blender -void UnitConverter::convertVec3(float *vec) +UnitConverter::UnitSystem UnitConverter::isMetricSystem() { + switch(unit.getLinearUnitUnit()) { + case COLLADAFW::FileInfo::Unit::MILLIMETER: + case COLLADAFW::FileInfo::Unit::CENTIMETER: + case COLLADAFW::FileInfo::Unit::DECIMETER: + case COLLADAFW::FileInfo::Unit::METER: + case COLLADAFW::FileInfo::Unit::KILOMETER: + return UnitConverter::Metric; + case COLLADAFW::FileInfo::Unit::INCH: + case COLLADAFW::FileInfo::Unit::FOOT: + case COLLADAFW::FileInfo::Unit::YARD: + return UnitConverter::Imperial; + default: + return UnitConverter::None; + } +} + +float UnitConverter::getLinearMeter() +{ + return (float)unit.getLinearUnitMeter(); +} + +void UnitConverter::convertVector3(COLLADABU::Math::Vector3 &vec, float *v) +{ + v[0] = vec.x; + v[1] = vec.y; + v[2] = vec.z; } // TODO need also for angle conversion, time conversion... diff --git a/source/blender/collada/collada_internal.h b/source/blender/collada/collada_internal.h index 1e3546263da..72b03a3d090 100644 --- a/source/blender/collada/collada_internal.h +++ b/source/blender/collada/collada_internal.h @@ -43,14 +43,22 @@ private: public: + enum UnitSystem { + None, + Metric, + Imperial + }; + // Initialize with Z_UP, since Blender uses right-handed, z-up UnitConverter(); void read_asset(const COLLADAFW::FileInfo* asset); - // TODO - // convert vector vec from COLLADA format to Blender - void convertVec3(float *vec); + void convertVector3(COLLADABU::Math::Vector3 &vec, float *v); + + UnitConverter::UnitSystem isMetricSystem(void); + + float getLinearMeter(void); // TODO need also for angle conversion, time conversion... |