[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [29191] trunk/blender/source/blender/ collada: Merge -c 29009, 29081, 29189 from COLLADA branch into trunk.
Arystanbek Dyussenov
arystan.d at gmail.com
Thu Jun 3 19:41:33 CEST 2010
Revision: 29191
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=29191
Author: kazanbas
Date: 2010-06-03 19:41:33 +0200 (Thu, 03 Jun 2010)
Log Message:
-----------
Merge -c 29009,29081,29189 from COLLADA branch into trunk.
Modified Paths:
--------------
trunk/blender/source/blender/collada/DocumentExporter.cpp
trunk/blender/source/blender/collada/DocumentExporter.h
trunk/blender/source/blender/collada/DocumentImporter.cpp
trunk/blender/source/blender/collada/DocumentImporter.h
trunk/blender/source/blender/collada/SConscript
trunk/blender/source/blender/collada/collada.cpp
trunk/blender/source/blender/collada/collada.h
trunk/blender/source/blender/collada/collada_internal.h
Modified: trunk/blender/source/blender/collada/DocumentExporter.cpp
===================================================================
--- trunk/blender/source/blender/collada/DocumentExporter.cpp 2010-06-03 17:29:06 UTC (rev 29190)
+++ trunk/blender/source/blender/collada/DocumentExporter.cpp 2010-06-03 17:41:33 UTC (rev 29191)
@@ -1,3 +1,26 @@
+/**
+ * $Id$
+ *
+ * ***** 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.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
@@ -638,8 +661,8 @@
source.setAccessorCount(totuv);
source.setAccessorStride(2);
COLLADASW::SourceBase::ParameterNameList ¶m = source.getParameterNameList();
- param.push_back("X");
- param.push_back("Y");
+ param.push_back("S");
+ param.push_back("T");
source.prepareToAppendValues();
@@ -908,7 +931,7 @@
Object *ob_arm = get_assigned_armature(ob);
bArmature *arm = (bArmature*)ob_arm->data;
- const std::string& controller_id = get_controller_id(ob_arm);
+ const std::string& controller_id = get_controller_id(ob_arm, ob);
COLLADASW::InstanceController ins(mSW);
ins.setUrl(COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, controller_id));
@@ -1051,9 +1074,9 @@
TransformWriter::add_node_transform(node, mat, NULL);
}
- std::string get_controller_id(Object *ob_arm)
+ std::string get_controller_id(Object *ob_arm, Object *ob)
{
- return translate_id(id_name(ob_arm)) + SKIN_CONTROLLER_ID_SUFFIX;
+ return translate_id(id_name(ob_arm)) + "_" + translate_id(id_name(ob)) + SKIN_CONTROLLER_ID_SUFFIX;
}
// ob should be of type OB_MESH
@@ -1087,7 +1110,7 @@
if (!me->dvert) return;
std::string controller_name = id_name(ob_arm);
- std::string controller_id = get_controller_id(ob_arm);
+ std::string controller_id = get_controller_id(ob_arm, ob);
openSkin(controller_id, controller_name,
COLLADABU::URI(COLLADABU::Utils::EMPTY_STRING, get_geometry_id(ob)));
Modified: trunk/blender/source/blender/collada/DocumentExporter.h
===================================================================
--- trunk/blender/source/blender/collada/DocumentExporter.h 2010-06-03 17:29:06 UTC (rev 29190)
+++ trunk/blender/source/blender/collada/DocumentExporter.h 2010-06-03 17:41:33 UTC (rev 29191)
@@ -1,3 +1,26 @@
+/**
+ * $Id$
+ *
+ * ***** 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 *****
+ */
struct Scene;
class DocumentExporter
Modified: trunk/blender/source/blender/collada/DocumentImporter.cpp
===================================================================
--- trunk/blender/source/blender/collada/DocumentImporter.cpp 2010-06-03 17:29:06 UTC (rev 29190)
+++ trunk/blender/source/blender/collada/DocumentImporter.cpp 2010-06-03 17:41:33 UTC (rev 29191)
@@ -1,3 +1,26 @@
+/**
+ * $Id$
+ *
+ * ***** 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, Nathan Letwory.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
// TODO:
// * name imported objects
// * import object rotation as euler
@@ -396,8 +419,6 @@
std::vector<COLLADAFW::Node*> root_joints;
std::map<COLLADAFW::UniqueId, Object*> joint_parent_map;
- std::vector<Object*> armature_objects;
-
MeshImporterBase *mesh_importer;
AnimationImporterBase *anim_importer;
@@ -506,13 +527,11 @@
joint_data.push_back(jd);
}
- // called from write_controller
- Object *create_armature(const COLLADAFW::SkinController* co, Scene *scene)
+ void set_controller(const COLLADAFW::SkinController* co)
{
- ob_arm = add_object(scene, OB_ARMATURE);
-
controller_uid = co->getUniqueId();
+ // fill in joint UIDs
const COLLADAFW::UniqueIdArray& joint_uids = co->getJoints();
for (unsigned int i = 0; i < joint_uids.getCount(); i++) {
joint_data[i].joint_uid = joint_uids[i];
@@ -524,10 +543,24 @@
// now we'll be able to get inv bind matrix from joint id
// joint_id_to_joint_index_map[joint_ids[i]] = i;
}
+ }
+ // called from write_controller
+ Object *create_armature(Scene *scene)
+ {
+ ob_arm = add_object(scene, OB_ARMATURE);
return ob_arm;
}
+ Object* set_armature(Object *ob_arm)
+ {
+ if (this->ob_arm)
+ return this->ob_arm;
+
+ this->ob_arm = ob_arm;
+ return ob_arm;
+ }
+
bool get_joint_inv_bind_matrix(float inv_bind_mat[][4], COLLADAFW::Node *node)
{
const COLLADAFW::UniqueId& uid = node->getUniqueId();
@@ -552,10 +585,12 @@
return controller_uid;
}
+ // check if this skin controller references a joint or any descendant of it
+ //
// some nodes may not be referenced by SkinController,
// in this case to determine if the node belongs to this armature,
// we need to search down the tree
- bool uses_joint(COLLADAFW::Node *node)
+ bool uses_joint_or_descendant(COLLADAFW::Node *node)
{
const COLLADAFW::UniqueId& uid = node->getUniqueId();
std::vector<JointData>::iterator it;
@@ -566,7 +601,7 @@
COLLADAFW::NodePointerArray& children = node->getChildNodes();
for (unsigned int i = 0; i < children.getCount(); i++) {
- if (this->uses_joint(children[i]))
+ if (uses_joint_or_descendant(children[i]))
return true;
}
@@ -658,6 +693,38 @@
return parent;
}
+ void find_root_joints(const std::vector<COLLADAFW::Node*> &root_joints,
+ std::map<COLLADAFW::UniqueId, COLLADAFW::Node*>& joint_by_uid,
+ std::vector<COLLADAFW::Node*>& result)
+ {
+ std::vector<COLLADAFW::Node*>::const_iterator it;
+ for (it = root_joints.begin(); it != root_joints.end(); it++) {
+ COLLADAFW::Node *root = *it;
+ std::vector<JointData>::iterator ji;
+ for (ji = joint_data.begin(); ji != joint_data.end(); ji++) {
+ COLLADAFW::Node *joint = joint_by_uid[(*ji).joint_uid];
+ if (find_node_in_tree(joint, root)) {
+ if (std::find(result.begin(), result.end(), root) == result.end())
+ result.push_back(root);
+ }
+ }
+ }
+ }
+
+ bool find_node_in_tree(COLLADAFW::Node *node, COLLADAFW::Node *tree_root)
+ {
+ if (node == tree_root)
+ return true;
+
+ COLLADAFW::NodePointerArray& children = tree_root->getChildNodes();
+ for (unsigned int i = 0; i < children.getCount(); i++) {
+ if (find_node_in_tree(node, children[i]))
+ return true;
+ }
+
+ return false;
+ }
+
};
std::map<COLLADAFW::UniqueId, SkinInfo> skin_by_data_uid; // data UID = skin controller data UID
@@ -841,7 +908,7 @@
for (sit = skin_by_data_uid.begin(); sit != skin_by_data_uid.end(); sit++) {
SkinInfo& skin = sit->second;
- if (skin.uses_joint(joint)) {
+ if (skin.uses_joint_or_descendant(joint)) {
bPoseChannel *pchan = skin.get_pose_channel_from_node(joint);
if (pchan) {
@@ -909,8 +976,71 @@
// - exit edit mode
// - set a sphere shape to leaf bones
- Object *ob_arm = skin.get_armature();
+ Object *ob_arm = NULL;
+ /*
+ * find if there's another skin sharing at least one bone with this skin
+ * if so, use that skin's armature
+ */
+
+ /*
+ Pseudocode:
+
+ find_node_in_tree(node, root_joint)
+
+ skin::find_root_joints(root_joints):
+ std::vector root_joints;
+ for each root in root_joints:
+ for each joint in joints:
+ if find_node_in_tree(joint, root):
+ if (std::find(root_joints.begin(), root_joints.end(), root) == root_joints.end())
+ root_joints.push_back(root);
+
+ for (each skin B with armature) {
+ find all root joints for skin B
+
+ for each joint X in skin A:
+ for each root joint R in skin B:
+ if (find_node_in_tree(X, R)) {
+ shared = 1;
+ goto endloop;
+ }
+ }
+
+ endloop:
+ */
+
+ SkinInfo *a = &skin;
+ Object *shared = NULL;
+ std::vector<COLLADAFW::Node*> skin_root_joints;
+
+ std::map<COLLADAFW::UniqueId, SkinInfo>::iterator it;
+ for (it = skin_by_data_uid.begin(); it != skin_by_data_uid.end(); it++) {
+ SkinInfo *b = &it->second;
+ if (b == a || b->get_armature() == NULL)
+ continue;
+
+ skin_root_joints.clear();
+
+ b->find_root_joints(root_joints, joint_by_uid, skin_root_joints);
+
+ std::vector<COLLADAFW::Node*>::iterator ri;
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list