Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Letwory <nathan@letworyinteractive.com>2010-10-06 11:13:42 +0400
committerNathan Letwory <nathan@letworyinteractive.com>2010-10-06 11:13:42 +0400
commitfdadab10062cd9fbef6a6585fd19f344280a9d5b (patch)
tree52f819576cff389159b13255e28d50972583d249 /source/blender/collada
parent02d97e4da297b8fa112811470846c0ae4598412a (diff)
COLLADA exporter: split camera and light export into own files.
Diffstat (limited to 'source/blender/collada')
-rw-r--r--source/blender/collada/CameraExporter.cpp86
-rw-r--r--source/blender/collada/CameraExporter.h43
-rw-r--r--source/blender/collada/DocumentExporter.cpp296
-rw-r--r--source/blender/collada/LightExporter.cpp106
-rw-r--r--source/blender/collada/LightExporter.h43
-rw-r--r--source/blender/collada/collada_internal.cpp240
-rw-r--r--source/blender/collada/collada_internal.h74
7 files changed, 554 insertions, 334 deletions
diff --git a/source/blender/collada/CameraExporter.cpp b/source/blender/collada/CameraExporter.cpp
new file mode 100644
index 00000000000..b4ccfd5d6d1
--- /dev/null
+++ b/source/blender/collada/CameraExporter.cpp
@@ -0,0 +1,86 @@
+/**
+ * $Id: DocumentExporter.cpp 32309 2010-10-05 00:05:14Z jesterking $
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Chingiz Dyussenov, Arystanbek Dyussenov, Jan Diederich, Tod Liverseed,
+ * Nathan Letwory
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#include <string>
+
+#include "COLLADASWCamera.h"
+#include "COLLADASWCameraOptic.h"
+
+#include "DNA_camera_types.h"
+
+#include "CameraExporter.h"
+
+#include "collada_internal.h"
+
+CamerasExporter::CamerasExporter(COLLADASW::StreamWriter *sw): COLLADASW::LibraryCameras(sw){}
+
+template<class Functor>
+void forEachCameraObjectInScene(Scene *sce, Functor &f)
+{
+ Base *base= (Base*) sce->base.first;
+ while(base) {
+ Object *ob = base->object;
+
+ if (ob->type == OB_CAMERA && ob->data) {
+ f(ob, sce);
+ }
+ base= base->next;
+ }
+}
+
+void CamerasExporter::exportCameras(Scene *sce)
+{
+ openLibrary();
+
+ forEachCameraObjectInScene(sce, *this);
+
+ closeLibrary();
+}
+void CamerasExporter::operator()(Object *ob, Scene *sce)
+{
+ // TODO: shiftx, shifty, YF_dofdist
+ Camera *cam = (Camera*)ob->data;
+ std::string cam_id(get_camera_id(ob));
+ std::string cam_name(id_name(cam));
+
+ if (cam->type == CAM_PERSP) {
+ COLLADASW::PerspectiveOptic persp(mSW);
+ persp.setXFov(lens_to_angle(cam->lens)*(180.0f/M_PI));
+ persp.setAspectRatio(1.0);
+ persp.setZFar(cam->clipend);
+ persp.setZNear(cam->clipsta);
+ COLLADASW::Camera ccam(mSW, &persp, cam_id, cam_name);
+ addCamera(ccam);
+ }
+ else {
+ COLLADASW::OrthographicOptic ortho(mSW);
+ ortho.setXMag(cam->ortho_scale);
+ ortho.setAspectRatio(1.0);
+ ortho.setZFar(cam->clipend);
+ ortho.setZNear(cam->clipsta);
+ COLLADASW::Camera ccam(mSW, &ortho, cam_id, cam_name);
+ addCamera(ccam);
+ }
+}
diff --git a/source/blender/collada/CameraExporter.h b/source/blender/collada/CameraExporter.h
new file mode 100644
index 00000000000..a4605b99f52
--- /dev/null
+++ b/source/blender/collada/CameraExporter.h
@@ -0,0 +1,43 @@
+/**
+ * $Id: DocumentExporter.cpp 32309 2010-10-05 00:05:14Z jesterking $
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Chingiz Dyussenov, Arystanbek Dyussenov, Jan Diederich, Tod Liverseed,
+ * Nathan Letwory
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#ifndef __CAMERAEXPORTER_H__
+#define __CAMERAEXPORTER_H__
+
+#include "COLLADASWStreamWriter.h"
+#include "COLLADASWLibraryCameras.h"
+
+#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
+
+class CamerasExporter: COLLADASW::LibraryCameras
+{
+public:
+ CamerasExporter(COLLADASW::StreamWriter *sw);
+ void exportCameras(Scene *sce);
+ void operator()(Object *ob, Scene *sce);
+};
+
+#endif
diff --git a/source/blender/collada/DocumentExporter.cpp b/source/blender/collada/DocumentExporter.cpp
index c13e089fa4a..661f31f5210 100644
--- a/source/blender/collada/DocumentExporter.cpp
+++ b/source/blender/collada/DocumentExporter.cpp
@@ -95,11 +95,11 @@ extern char build_rev[];
#include "COLLADASWTexture.h"
#include "COLLADASWLibraryMaterials.h"
#include "COLLADASWBindMaterial.h"
-#include "COLLADASWLibraryCameras.h"
+//#include "COLLADASWLibraryCameras.h"
#include "COLLADASWLibraryLights.h"
#include "COLLADASWInstanceCamera.h"
#include "COLLADASWInstanceLight.h"
-#include "COLLADASWCameraOptic.h"
+//#include "COLLADASWCameraOptic.h"
#include "COLLADASWConstants.h"
#include "COLLADASWLibraryControllers.h"
#include "COLLADASWInstanceController.h"
@@ -108,6 +108,9 @@ extern char build_rev[];
#include "collada_internal.h"
#include "DocumentExporter.h"
+#include "CameraExporter.h"
+#include "LightExporter.h"
+
#include <vector>
#include <algorithm> // std::find
@@ -128,161 +131,6 @@ char *CustomData_get_active_layer_name(const CustomData *data, int type)
return data->layers[layer_index].name;
}
-/**
-Translation map.
-Used to translate every COLLADA id to a valid id, no matter what "wrong" letters may be
-included. Look at the IDREF XSD declaration for more.
-Follows strictly the COLLADA XSD declaration which explicitly allows non-english chars,
-like special chars (e.g. micro sign), umlauts and so on.
-The COLLADA spec also allows additional chars for member access ('.'), these
-must obviously be removed too, otherwise they would be heavily misinterpreted.
-*/
-const unsigned char translate_start_name_map[256] = {
-95, 95, 95, 95, 95, 95, 95, 95, 95,
-95, 95, 95, 95, 95, 95, 95, 95,
-95, 95, 95, 95, 95, 95, 95, 95,
-95, 95, 95, 95, 95, 95, 95, 95,
-95, 95, 95, 95, 95, 95, 95, 95,
-95, 95, 95, 95, 95, 95, 95, 95,
-95, 95, 95, 95, 95, 95, 95, 95,
-95, 95, 95, 95, 95, 95, 95, 95,
-65, 66, 67, 68, 69, 70, 71, 72,
-73, 74, 75, 76, 77, 78, 79, 80,
-81, 82, 83, 84, 85, 86, 87, 88,
-89, 90, 95, 95, 95, 95, 95, 95,
-97, 98, 99, 100, 101, 102, 103, 104,
-105, 106, 107, 108, 109, 110, 111, 112,
-113, 114, 115, 116, 117, 118, 119, 120,
-121, 122, 95, 95, 95, 95, 95, 95,
-95, 95, 95, 95, 95, 95, 95, 95,
-95, 95, 95, 95, 95, 95, 95, 95,
-95, 95, 95, 95, 95, 95, 95, 95,
-95, 95, 95, 95, 95, 95, 95, 95,
-95, 95, 95, 95, 95, 95, 95, 95,
-95, 95, 95, 95, 95, 95, 95, 95,
-95, 95, 95, 95, 95, 95, 95, 95,
-95, 95, 95, 95, 95, 95, 95, 192,
-193, 194, 195, 196, 197, 198, 199, 200,
-201, 202, 203, 204, 205, 206, 207, 208,
-209, 210, 211, 212, 213, 214, 95, 216,
-217, 218, 219, 220, 221, 222, 223, 224,
-225, 226, 227, 228, 229, 230, 231, 232,
-233, 234, 235, 236, 237, 238, 239, 240,
-241, 242, 243, 244, 245, 246, 95, 248,
-249, 250, 251, 252, 253, 254, 255};
-
-const unsigned char translate_name_map[256] = {
-95, 95, 95, 95, 95, 95, 95, 95, 95,
-95, 95, 95, 95, 95, 95, 95, 95,
-95, 95, 95, 95, 95, 95, 95, 95,
-95, 95, 95, 95, 95, 95, 95, 95,
-95, 95, 95, 95, 95, 95, 95, 95,
-95, 95, 95, 95, 45, 95, 95, 48,
-49, 50, 51, 52, 53, 54, 55, 56,
-57, 95, 95, 95, 95, 95, 95, 95,
-65, 66, 67, 68, 69, 70, 71, 72,
-73, 74, 75, 76, 77, 78, 79, 80,
-81, 82, 83, 84, 85, 86, 87, 88,
-89, 90, 95, 95, 95, 95, 95, 95,
-97, 98, 99, 100, 101, 102, 103, 104,
-105, 106, 107, 108, 109, 110, 111, 112,
-113, 114, 115, 116, 117, 118, 119, 120,
-121, 122, 95, 95, 95, 95, 95, 95,
-95, 95, 95, 95, 95, 95, 95, 95,
-95, 95, 95, 95, 95, 95, 95, 95,
-95, 95, 95, 95, 95, 95, 95, 95,
-95, 95, 95, 95, 95, 95, 95, 95,
-95, 95, 95, 95, 95, 95, 95, 95,
-95, 95, 95, 95, 95, 95, 95, 95,
-95, 95, 95, 95, 95, 95, 183, 95,
-95, 95, 95, 95, 95, 95, 95, 192,
-193, 194, 195, 196, 197, 198, 199, 200,
-201, 202, 203, 204, 205, 206, 207, 208,
-209, 210, 211, 212, 213, 214, 95, 216,
-217, 218, 219, 220, 221, 222, 223, 224,
-225, 226, 227, 228, 229, 230, 231, 232,
-233, 234, 235, 236, 237, 238, 239, 240,
-241, 242, 243, 244, 245, 246, 95, 248,
-249, 250, 251, 252, 253, 254, 255};
-
-typedef std::map< std::string, std::vector<std::string> > map_string_list;
-map_string_list global_id_map;
-
-/** Look at documentation of translate_map */
-static std::string translate_id(const std::string &id)
-{
- if (id.size() == 0)
- { return id; }
- std::string id_translated = id;
- id_translated[0] = translate_start_name_map[(unsigned int)id_translated[0]];
- for (unsigned int i=1; i < id_translated.size(); i++)
- {
- id_translated[i] = translate_name_map[(unsigned int)id_translated[i]];
- }
- // It's so much workload now, the if() should speed up things.
- if (id_translated != id)
- {
- // Search duplicates
- map_string_list::iterator iter = global_id_map.find(id_translated);
- if (iter != global_id_map.end())
- {
- unsigned int i = 0;
- bool found = false;
- for (i=0; i < iter->second.size(); i++)
- {
- if (id == iter->second[i])
- {
- found = true;
- break;
- }
- }
- bool convert = false;
- if (found)
- {
- if (i > 0)
- { convert = true; }
- }
- else
- {
- convert = true;
- global_id_map[id_translated].push_back(id);
- }
- if (convert)
- {
- std::stringstream out;
- out << ++i;
- id_translated += out.str();
- }
- }
- else { global_id_map[id_translated].push_back(id); }
- }
- return id_translated;
-}
-
-static std::string id_name(void *id)
-{
- return ((ID*)id)->name + 2;
-}
-
-static std::string get_geometry_id(Object *ob)
-{
- return translate_id(id_name(ob)) + "-mesh";
-}
-
-static std::string get_light_id(Object *ob)
-{
- return translate_id(id_name(ob)) + "-light";
-}
-
-static std::string get_camera_id(Object *ob)
-{
- return translate_id(id_name(ob)) + "-camera";
-}
-
-std::string get_joint_id(Bone *bone, Object *ob_arm)
-{
- return translate_id(id_name(ob_arm) + "_" + bone->name);
-}
/*
@@ -321,34 +169,6 @@ void forEachObjectInScene(Scene *sce, Functor &f)
}
}
-template<class Functor>
-void forEachCameraObjectInScene(Scene *sce, Functor &f)
-{
- Base *base= (Base*) sce->base.first;
- while(base) {
- Object *ob = base->object;
-
- if (ob->type == OB_CAMERA && ob->data) {
- f(ob, sce);
- }
- base= base->next;
- }
-}
-
-template<class Functor>
-void forEachLampObjectInScene(Scene *sce, Functor &f)
-{
- Base *base= (Base*) sce->base.first;
- while(base) {
- Object *ob = base->object;
-
- if (ob->type == OB_LAMP && ob->data) {
- f(ob);
- }
- base= base->next;
- }
-}
-
// used in forEachMaterialInScene
template <class MaterialFunctor>
class ForEachMaterialFunctor
@@ -1869,108 +1689,6 @@ public:
}
};
-class CamerasExporter: COLLADASW::LibraryCameras
-{
-public:
- CamerasExporter(COLLADASW::StreamWriter *sw): COLLADASW::LibraryCameras(sw){}
- void exportCameras(Scene *sce)
- {
- openLibrary();
-
- forEachCameraObjectInScene(sce, *this);
-
- closeLibrary();
- }
- void operator()(Object *ob, Scene *sce)
- {
- // TODO: shiftx, shifty, YF_dofdist
- Camera *cam = (Camera*)ob->data;
- std::string cam_id(get_camera_id(ob));
- std::string cam_name(id_name(cam));
-
- if (cam->type == CAM_PERSP) {
- COLLADASW::PerspectiveOptic persp(mSW);
- persp.setXFov(lens_to_angle(cam->lens)*(180.0f/M_PI));
- persp.setAspectRatio(1.0);
- persp.setZFar(cam->clipend);
- persp.setZNear(cam->clipsta);
- COLLADASW::Camera ccam(mSW, &persp, cam_id, cam_name);
- addCamera(ccam);
- }
- else {
- COLLADASW::OrthographicOptic ortho(mSW);
- ortho.setXMag(cam->ortho_scale);
- ortho.setAspectRatio(1.0);
- ortho.setZFar(cam->clipend);
- ortho.setZNear(cam->clipsta);
- COLLADASW::Camera ccam(mSW, &ortho, cam_id, cam_name);
- addCamera(ccam);
- }
- }
-};
-
-class LightsExporter: COLLADASW::LibraryLights
-{
-public:
- LightsExporter(COLLADASW::StreamWriter *sw): COLLADASW::LibraryLights(sw){}
- void exportLights(Scene *sce)
- {
- openLibrary();
-
- forEachLampObjectInScene(sce, *this);
-
- closeLibrary();
- }
- void operator()(Object *ob)
- {
- Lamp *la = (Lamp*)ob->data;
- std::string la_id(get_light_id(ob));
- std::string la_name(id_name(la));
- COLLADASW::Color col(la->r, la->g, la->b);
- float e = la->energy;
-
- // sun
- if (la->type == LA_SUN) {
- COLLADASW::DirectionalLight cla(mSW, la_id, la_name, e);
- cla.setColor(col);
- addLight(cla);
- }
- // hemi
- else if (la->type == LA_HEMI) {
- COLLADASW::AmbientLight cla(mSW, la_id, la_name, e);
- cla.setColor(col);
- addLight(cla);
- }
- // spot
- else if (la->type == LA_SPOT) {
- COLLADASW::SpotLight cla(mSW, la_id, la_name, e);
- cla.setColor(col);
- cla.setFallOffAngle(la->spotsize);
- cla.setFallOffExponent(la->spotblend);
- cla.setLinearAttenuation(la->att1);
- cla.setQuadraticAttenuation(la->att2);
- addLight(cla);
- }
- // lamp
- else if (la->type == LA_LOCAL) {
- COLLADASW::PointLight cla(mSW, la_id, la_name, e);
- cla.setColor(col);
- cla.setLinearAttenuation(la->att1);
- cla.setQuadraticAttenuation(la->att2);
- addLight(cla);
- }
- // area lamp is not supported
- // it will be exported as a local lamp
- else {
- COLLADASW::PointLight cla(mSW, la_id, la_name, e);
- cla.setColor(col);
- cla.setLinearAttenuation(la->att1);
- cla.setQuadraticAttenuation(la->att2);
- addLight(cla);
- }
- }
-};
-
// TODO: it would be better to instantiate animations rather than create a new one per object
// COLLADA allows this through multiple <channel>s in <animation>.
// For this to work, we need to know objects that use a certain action.
@@ -2584,8 +2302,8 @@ protected:
void DocumentExporter::exportCurrentScene(Scene *sce, const char* filename)
{
- global_id_map.clear();
-
+ clear_global_id_map();
+
COLLADABU::NativeString native_filename =
COLLADABU::NativeString(std::string(filename));
COLLADASW::StreamWriter sw(native_filename);
diff --git a/source/blender/collada/LightExporter.cpp b/source/blender/collada/LightExporter.cpp
new file mode 100644
index 00000000000..0bedce41bc0
--- /dev/null
+++ b/source/blender/collada/LightExporter.cpp
@@ -0,0 +1,106 @@
+/**
+ * $Id: DocumentExporter.cpp 32309 2010-10-05 00:05:14Z jesterking $
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Chingiz Dyussenov, Arystanbek Dyussenov, Jan Diederich, Tod Liverseed,
+ * Nathan Letwory
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#include <string>
+
+#include "COLLADASWColor.h"
+#include "COLLADASWLight.h"
+
+#include "DNA_lamp_types.h"
+
+#include "LightExporter.h"
+#include "collada_internal.h"
+
+template<class Functor>
+void forEachLampObjectInScene(Scene *sce, Functor &f)
+{
+ Base *base= (Base*) sce->base.first;
+ while(base) {
+ Object *ob = base->object;
+
+ if (ob->type == OB_LAMP && ob->data) {
+ f(ob);
+ }
+ base= base->next;
+ }
+}
+
+LightsExporter::LightsExporter(COLLADASW::StreamWriter *sw): COLLADASW::LibraryLights(sw){}
+void LightsExporter::exportLights(Scene *sce)
+{
+ openLibrary();
+
+ forEachLampObjectInScene(sce, *this);
+
+ closeLibrary();
+}
+void LightsExporter::operator()(Object *ob)
+{
+ Lamp *la = (Lamp*)ob->data;
+ std::string la_id(get_light_id(ob));
+ std::string la_name(id_name(la));
+ COLLADASW::Color col(la->r, la->g, la->b);
+ float e = la->energy;
+
+ // sun
+ if (la->type == LA_SUN) {
+ COLLADASW::DirectionalLight cla(mSW, la_id, la_name, e);
+ cla.setColor(col);
+ addLight(cla);
+ }
+ // hemi
+ else if (la->type == LA_HEMI) {
+ COLLADASW::AmbientLight cla(mSW, la_id, la_name, e);
+ cla.setColor(col);
+ addLight(cla);
+ }
+ // spot
+ else if (la->type == LA_SPOT) {
+ COLLADASW::SpotLight cla(mSW, la_id, la_name, e);
+ cla.setColor(col);
+ cla.setFallOffAngle(la->spotsize);
+ cla.setFallOffExponent(la->spotblend);
+ cla.setLinearAttenuation(la->att1);
+ cla.setQuadraticAttenuation(la->att2);
+ addLight(cla);
+ }
+ // lamp
+ else if (la->type == LA_LOCAL) {
+ COLLADASW::PointLight cla(mSW, la_id, la_name, e);
+ cla.setColor(col);
+ cla.setLinearAttenuation(la->att1);
+ cla.setQuadraticAttenuation(la->att2);
+ addLight(cla);
+ }
+ // area lamp is not supported
+ // it will be exported as a local lamp
+ else {
+ COLLADASW::PointLight cla(mSW, la_id, la_name, e);
+ cla.setColor(col);
+ cla.setLinearAttenuation(la->att1);
+ cla.setQuadraticAttenuation(la->att2);
+ addLight(cla);
+ }
+}
diff --git a/source/blender/collada/LightExporter.h b/source/blender/collada/LightExporter.h
new file mode 100644
index 00000000000..70fa88d6193
--- /dev/null
+++ b/source/blender/collada/LightExporter.h
@@ -0,0 +1,43 @@
+/**
+ * $Id: DocumentExporter.cpp 32309 2010-10-05 00:05:14Z jesterking $
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Chingiz Dyussenov, Arystanbek Dyussenov, Jan Diederich, Tod Liverseed,
+ * Nathan Letwory
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#ifndef __LIGHTEXPORTER_H__
+#define __LIGHTEXPORTER_H__
+
+#include "COLLADASWStreamWriter.h"
+#include "COLLADASWLibraryLights.h"
+
+#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
+
+class LightsExporter: COLLADASW::LibraryLights
+{
+public:
+ LightsExporter(COLLADASW::StreamWriter *sw);
+ void exportLights(Scene *sce);
+ void operator()(Object *ob);
+};
+
+#endif
diff --git a/source/blender/collada/collada_internal.cpp b/source/blender/collada/collada_internal.cpp
new file mode 100644
index 00000000000..cfa94e60199
--- /dev/null
+++ b/source/blender/collada/collada_internal.cpp
@@ -0,0 +1,240 @@
+/**
+ * $Id: collada_internal.h 32309 2010-10-05 00:05:14Z jesterking $
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Chingiz Dyussenov, Arystanbek Dyussenov.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#include "collada_internal.h"
+
+UnitConverter::UnitConverter() : unit(), up_axis(COLLADAFW::FileInfo::Z_UP) {}
+
+void UnitConverter::read_asset(const COLLADAFW::FileInfo* asset)
+{
+}
+
+// TODO
+// convert vector vec from COLLADA format to Blender
+void UnitConverter::convertVec3(float *vec)
+{
+}
+
+// TODO need also for angle conversion, time conversion...
+
+void UnitConverter::dae_matrix_to_mat4_(float out[][4], const COLLADABU::Math::Matrix4& in)
+{
+ // in DAE, matrices use columns vectors, (see comments in COLLADABUMathMatrix4.h)
+ // so here, to make a blender matrix, we swap columns and rows
+ for (int i = 0; i < 4; i++) {
+ for (int j = 0; j < 4; j++) {
+ out[i][j] = in[j][i];
+ }
+ }
+}
+
+void UnitConverter::mat4_to_dae(float out[][4], float in[][4])
+{
+ copy_m4_m4(out, in);
+ transpose_m4(out);
+}
+
+void UnitConverter::mat4_to_dae_double(double out[][4], float in[][4])
+{
+ float mat[4][4];
+
+ mat4_to_dae(mat, in);
+
+ for (int i = 0; i < 4; i++)
+ for (int j = 0; j < 4; j++)
+ out[i][j] = mat[i][j];
+}
+
+void TransformBase::decompose(float mat[][4], float *loc, float eul[3], float quat[4], float *size)
+{
+ mat4_to_size(size, mat);
+ if (eul) {
+ mat4_to_eul(eul, mat);
+ }
+ if (quat) {
+ mat4_to_quat(quat, mat);
+ }
+ copy_v3_v3(loc, mat[3]);
+}
+
+/**
+Translation map.
+Used to translate every COLLADA id to a valid id, no matter what "wrong" letters may be
+included. Look at the IDREF XSD declaration for more.
+Follows strictly the COLLADA XSD declaration which explicitly allows non-english chars,
+like special chars (e.g. micro sign), umlauts and so on.
+The COLLADA spec also allows additional chars for member access ('.'), these
+must obviously be removed too, otherwise they would be heavily misinterpreted.
+*/
+const unsigned char translate_start_name_map[256] = {
+95, 95, 95, 95, 95, 95, 95, 95, 95,
+95, 95, 95, 95, 95, 95, 95, 95,
+95, 95, 95, 95, 95, 95, 95, 95,
+95, 95, 95, 95, 95, 95, 95, 95,
+95, 95, 95, 95, 95, 95, 95, 95,
+95, 95, 95, 95, 95, 95, 95, 95,
+95, 95, 95, 95, 95, 95, 95, 95,
+95, 95, 95, 95, 95, 95, 95, 95,
+65, 66, 67, 68, 69, 70, 71, 72,
+73, 74, 75, 76, 77, 78, 79, 80,
+81, 82, 83, 84, 85, 86, 87, 88,
+89, 90, 95, 95, 95, 95, 95, 95,
+97, 98, 99, 100, 101, 102, 103, 104,
+105, 106, 107, 108, 109, 110, 111, 112,
+113, 114, 115, 116, 117, 118, 119, 120,
+121, 122, 95, 95, 95, 95, 95, 95,
+95, 95, 95, 95, 95, 95, 95, 95,
+95, 95, 95, 95, 95, 95, 95, 95,
+95, 95, 95, 95, 95, 95, 95, 95,
+95, 95, 95, 95, 95, 95, 95, 95,
+95, 95, 95, 95, 95, 95, 95, 95,
+95, 95, 95, 95, 95, 95, 95, 95,
+95, 95, 95, 95, 95, 95, 95, 95,
+95, 95, 95, 95, 95, 95, 95, 192,
+193, 194, 195, 196, 197, 198, 199, 200,
+201, 202, 203, 204, 205, 206, 207, 208,
+209, 210, 211, 212, 213, 214, 95, 216,
+217, 218, 219, 220, 221, 222, 223, 224,
+225, 226, 227, 228, 229, 230, 231, 232,
+233, 234, 235, 236, 237, 238, 239, 240,
+241, 242, 243, 244, 245, 246, 95, 248,
+249, 250, 251, 252, 253, 254, 255};
+
+const unsigned char translate_name_map[256] = {
+95, 95, 95, 95, 95, 95, 95, 95, 95,
+95, 95, 95, 95, 95, 95, 95, 95,
+95, 95, 95, 95, 95, 95, 95, 95,
+95, 95, 95, 95, 95, 95, 95, 95,
+95, 95, 95, 95, 95, 95, 95, 95,
+95, 95, 95, 95, 45, 95, 95, 48,
+49, 50, 51, 52, 53, 54, 55, 56,
+57, 95, 95, 95, 95, 95, 95, 95,
+65, 66, 67, 68, 69, 70, 71, 72,
+73, 74, 75, 76, 77, 78, 79, 80,
+81, 82, 83, 84, 85, 86, 87, 88,
+89, 90, 95, 95, 95, 95, 95, 95,
+97, 98, 99, 100, 101, 102, 103, 104,
+105, 106, 107, 108, 109, 110, 111, 112,
+113, 114, 115, 116, 117, 118, 119, 120,
+121, 122, 95, 95, 95, 95, 95, 95,
+95, 95, 95, 95, 95, 95, 95, 95,
+95, 95, 95, 95, 95, 95, 95, 95,
+95, 95, 95, 95, 95, 95, 95, 95,
+95, 95, 95, 95, 95, 95, 95, 95,
+95, 95, 95, 95, 95, 95, 95, 95,
+95, 95, 95, 95, 95, 95, 95, 95,
+95, 95, 95, 95, 95, 95, 183, 95,
+95, 95, 95, 95, 95, 95, 95, 192,
+193, 194, 195, 196, 197, 198, 199, 200,
+201, 202, 203, 204, 205, 206, 207, 208,
+209, 210, 211, 212, 213, 214, 95, 216,
+217, 218, 219, 220, 221, 222, 223, 224,
+225, 226, 227, 228, 229, 230, 231, 232,
+233, 234, 235, 236, 237, 238, 239, 240,
+241, 242, 243, 244, 245, 246, 95, 248,
+249, 250, 251, 252, 253, 254, 255};
+
+typedef std::map< std::string, std::vector<std::string> > map_string_list;
+map_string_list global_id_map;
+
+void clear_global_id_map()
+{
+ global_id_map.clear();
+}
+
+/** Look at documentation of translate_map */
+std::string translate_id(const std::string &id)
+{
+ if (id.size() == 0)
+ { return id; }
+ std::string id_translated = id;
+ id_translated[0] = translate_start_name_map[(unsigned int)id_translated[0]];
+ for (unsigned int i=1; i < id_translated.size(); i++)
+ {
+ id_translated[i] = translate_name_map[(unsigned int)id_translated[i]];
+ }
+ // It's so much workload now, the if() should speed up things.
+ if (id_translated != id)
+ {
+ // Search duplicates
+ map_string_list::iterator iter = global_id_map.find(id_translated);
+ if (iter != global_id_map.end())
+ {
+ unsigned int i = 0;
+ bool found = false;
+ for (i=0; i < iter->second.size(); i++)
+ {
+ if (id == iter->second[i])
+ {
+ found = true;
+ break;
+ }
+ }
+ bool convert = false;
+ if (found)
+ {
+ if (i > 0)
+ { convert = true; }
+ }
+ else
+ {
+ convert = true;
+ global_id_map[id_translated].push_back(id);
+ }
+ if (convert)
+ {
+ std::stringstream out;
+ out << ++i;
+ id_translated += out.str();
+ }
+ }
+ else { global_id_map[id_translated].push_back(id); }
+ }
+ return id_translated;
+}
+
+std::string id_name(void *id)
+{
+ return ((ID*)id)->name + 2;
+}
+
+std::string get_geometry_id(Object *ob)
+{
+ return translate_id(id_name(ob)) + "-mesh";
+}
+
+std::string get_light_id(Object *ob)
+{
+ return translate_id(id_name(ob)) + "-light";
+}
+
+std::string get_joint_id(Bone *bone, Object *ob_arm)
+{
+ return translate_id(id_name(ob_arm) + "_" + bone->name);
+}
+
+std::string get_camera_id(Object *ob)
+{
+ return translate_id(id_name(ob)) + "-camera";
+}
diff --git a/source/blender/collada/collada_internal.h b/source/blender/collada/collada_internal.h
index f8fbe71e6d9..1e3546263da 100644
--- a/source/blender/collada/collada_internal.h
+++ b/source/blender/collada/collada_internal.h
@@ -24,9 +24,15 @@
#ifndef BLENDER_COLLADA_H
#define BLENDER_COLLADA_H
+#include <string>
+#include <vector>
+#include <map>
+
#include "COLLADAFWFileInfo.h"
#include "Math/COLLADABUMathMatrix4.h"
+#include "DNA_armature_types.h"
+#include "DNA_object_types.h"
#include "BLI_math.h"
class UnitConverter
@@ -38,63 +44,41 @@ private:
public:
// Initialize with Z_UP, since Blender uses right-handed, z-up
- UnitConverter() : unit(), up_axis(COLLADAFW::FileInfo::Z_UP) {}
+ UnitConverter();
- void read_asset(const COLLADAFW::FileInfo* asset)
- {
- }
+ void read_asset(const COLLADAFW::FileInfo* asset);
// TODO
// convert vector vec from COLLADA format to Blender
- void convertVec3(float *vec)
- {
- }
+ void convertVec3(float *vec);
// TODO need also for angle conversion, time conversion...
- void dae_matrix_to_mat4_(float out[][4], const COLLADABU::Math::Matrix4& in)
- {
- // in DAE, matrices use columns vectors, (see comments in COLLADABUMathMatrix4.h)
- // so here, to make a blender matrix, we swap columns and rows
- for (int i = 0; i < 4; i++) {
- for (int j = 0; j < 4; j++) {
- out[i][j] = in[j][i];
- }
- }
- }
-
- void mat4_to_dae(float out[][4], float in[][4])
- {
- copy_m4_m4(out, in);
- transpose_m4(out);
- }
-
- void mat4_to_dae_double(double out[][4], float in[][4])
- {
- float mat[4][4];
-
- mat4_to_dae(mat, in);
-
- for (int i = 0; i < 4; i++)
- for (int j = 0; j < 4; j++)
- out[i][j] = mat[i][j];
- }
+ void dae_matrix_to_mat4_(float out[][4], const COLLADABU::Math::Matrix4& in);
+
+ void mat4_to_dae(float out[][4], float in[][4]);
+
+ void mat4_to_dae_double(double out[][4], float in[][4]);
};
class TransformBase
{
public:
- void decompose(float mat[][4], float *loc, float eul[3], float quat[4], float *size)
- {
- mat4_to_size(size, mat);
- if (eul) {
- mat4_to_eul(eul, mat);
- }
- if (quat) {
- mat4_to_quat(quat, mat);
- }
- copy_v3_v3(loc, mat[3]);
- }
+ void decompose(float mat[][4], float *loc, float eul[3], float quat[4], float *size);
};
+extern void clear_global_id_map();
+/** Look at documentation of translate_map */
+extern std::string translate_id(const std::string &id);
+
+extern std::string id_name(void *id);
+
+extern std::string get_geometry_id(Object *ob);
+
+extern std::string get_light_id(Object *ob);
+
+extern std::string get_joint_id(Bone *bone, Object *ob_arm);
+
+extern std::string get_camera_id(Object *ob);
+
#endif