Merge -c 29009,29081,29189 from COLLADA branch into trunk.

This commit is contained in:
Arystanbek Dyussenov 2010-06-03 17:41:33 +00:00
parent 6ac2ee5929
commit a545998c84
8 changed files with 375 additions and 59 deletions

@ -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 @@ public:
source.setAccessorCount(totuv);
source.setAccessorStride(2);
COLLADASW::SourceBase::ParameterNameList &param = source.getParameterNameList();
param.push_back("X");
param.push_back("Y");
param.push_back("S");
param.push_back("T");
source.prepareToAppendValues();
@ -908,7 +931,7 @@ public:
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 @@ private:
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 @@ private:
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)));

@ -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

@ -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 @@ private:
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 @@ private:
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,7 +543,21 @@ private:
// 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;
}
@ -552,10 +585,12 @@ private:
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 @@ private:
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 @@ private:
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 @@ private:
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,7 +976,70 @@ private:
// - 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;
for (ri = skin_root_joints.begin(); ri != skin_root_joints.end(); ri++) {
if (a->uses_joint_or_descendant(*ri)) {
shared = b->get_armature();
break;
}
}
if (shared != NULL)
break;
}
if (shared)
ob_arm = skin.set_armature(shared);
else
ob_arm = skin.create_armature(scene);
// enter armature edit mode
ED_armature_to_edit(ob_arm);
@ -921,15 +1051,23 @@ private:
// min_angle = 360.0f; // minimum angle between bone head-tail and a row of bone matrix
// create bones
/*
TODO:
check if bones have already been created for a given joint
*/
std::vector<COLLADAFW::Node*>::iterator ri;
for (ri = root_joints.begin(); ri != root_joints.end(); ri++) {
// for shared armature check if bone tree is already created
if (shared && std::find(skin_root_joints.begin(), skin_root_joints.end(), *ri) != skin_root_joints.end())
continue;
std::vector<COLLADAFW::Node*>::iterator it;
for (it = root_joints.begin(); it != root_joints.end(); it++) {
// since root_joints may contain joints for multiple controllers, we need to filter
if (skin.uses_joint(*it)) {
create_bone(skin, *it, NULL, (*it)->getChildNodes().getCount(), NULL, (bArmature*)ob_arm->data);
if (skin.uses_joint_or_descendant(*ri)) {
create_bone(skin, *ri, NULL, (*ri)->getChildNodes().getCount(), NULL, (bArmature*)ob_arm->data);
if (joint_parent_map.find((*it)->getUniqueId()) != joint_parent_map.end() && !skin.get_parent())
skin.set_parent(joint_parent_map[(*it)->getUniqueId()]);
if (joint_parent_map.find((*ri)->getUniqueId()) != joint_parent_map.end() && !skin.get_parent())
skin.set_parent(joint_parent_map[(*ri)->getUniqueId()]);
}
}
@ -1071,10 +1209,8 @@ public:
const COLLADAFW::UniqueId& skin_id = controller->getUniqueId();
if (controller->getControllerType() == COLLADAFW::Controller::CONTROLLER_TYPE_SKIN) {
COLLADAFW::SkinController *co = (COLLADAFW::SkinController*)controller;
// to find geom id by controller id
// to be able to find geom id by controller id
geom_uid_by_controller_uid[skin_id] = co->getSource();
const COLLADAFW::UniqueId& data_uid = co->getSkinControllerData();
@ -1083,9 +1219,7 @@ public:
return true;
}
Object *ob_arm = skin_by_data_uid[data_uid].create_armature(co, scene);
armature_objects.push_back(ob_arm);
skin_by_data_uid[data_uid].set_controller(co);
}
// morph controller
else {
@ -1110,7 +1244,7 @@ public:
for (it = skin_by_data_uid.begin(); it != skin_by_data_uid.end(); it++) {
SkinInfo& skin = it->second;
if (skin.uses_joint(node))
if (skin.uses_joint_or_descendant(node))
return skin.get_armature();
}
@ -1122,19 +1256,6 @@ public:
BLI_snprintf(joint_path, count, "pose.bones[\"%s\"]", get_joint_name(node));
}
#if 0
void fix_animation()
{
/* Change Euler rotation to Quaternion for bone animation */
std::vector<Object*>::iterator it;
for (it = armature_objects.begin(); it != armature_objects.end(); it++) {
Object *ob = *it;
if (!ob || !ob->adt || !ob->adt->action) continue;
anim_importer->change_eul_to_quat(ob, ob->adt->action);
}
}
#endif
// gives a world-space mat
bool get_joint_bind_mat(float m[][4], COLLADAFW::Node *joint)
{
@ -1207,7 +1328,7 @@ private:
}
#endif
void getUV(int uv_set_index, int uv_index[2], float *uv)
void getUV(int uv_index[2], float *uv)
{
switch(mVData->getType()) {
case COLLADAFW::MeshVertexData::DATA_TYPE_FLOAT:
@ -1258,7 +1379,7 @@ private:
}
#endif
void set_face_uv(MTFace *mtface, UVDataWrapper &uvs, int uv_set_index,
void set_face_uv(MTFace *mtface, UVDataWrapper &uvs,
COLLADAFW::IndexList& index_list, unsigned int *tris_indices)
{
int uv_indices[4][2];
@ -1273,12 +1394,12 @@ private:
uv_indices[i][1] = uv_index * 2 + 1;
}
uvs.getUV(uv_set_index, uv_indices[0], mtface->uv[0]);
uvs.getUV(uv_set_index, uv_indices[1], mtface->uv[1]);
uvs.getUV(uv_set_index, uv_indices[2], mtface->uv[2]);
uvs.getUV(uv_indices[0], mtface->uv[0]);
uvs.getUV(uv_indices[1], mtface->uv[1]);
uvs.getUV(uv_indices[2], mtface->uv[2]);
}
void set_face_uv(MTFace *mtface, UVDataWrapper &uvs, int uv_set_index,
void set_face_uv(MTFace *mtface, UVDataWrapper &uvs,
COLLADAFW::IndexList& index_list, int index, bool quad)
{
int uv_indices[4][2];
@ -1293,11 +1414,11 @@ private:
uv_indices[i][1] = uv_index * 2 + 1;
}
uvs.getUV(uv_set_index, uv_indices[0], mtface->uv[0]);
uvs.getUV(uv_set_index, uv_indices[1], mtface->uv[1]);
uvs.getUV(uv_set_index, uv_indices[2], mtface->uv[2]);
uvs.getUV(uv_indices[0], mtface->uv[0]);
uvs.getUV(uv_indices[1], mtface->uv[1]);
uvs.getUV(uv_indices[2], mtface->uv[2]);
if (quad) uvs.getUV(uv_set_index, uv_indices[3], mtface->uv[3]);
if (quad) uvs.getUV(uv_indices[3], mtface->uv[3]);
#ifdef COLLADA_DEBUG
/*if (quad) {
@ -1497,13 +1618,13 @@ private:
// allocate UV layers
unsigned int totuvset = mesh->getUVCoords().getInputInfosArray().getCount();
for (i = 0; i < totuvset; i++) {
if (mesh->getUVCoords().getLength(i) == 0) {
totuvset = 0;
break;
}
}
// for (i = 0; i < totuvset; i++) {
// if (mesh->getUVCoords().getLength(i) == 0) {
// totuvset = 0;
// break;
// }
// }
for (i = 0; i < totuvset; i++) {
CustomData_add_layer(&me->fdata, CD_MTFACE, CD_CALLOC, NULL, me->totface);
//this->set_layername_map[i] = CustomData_get_layer_name(&me->fdata, CD_MTFACE, i);
@ -1560,6 +1681,7 @@ private:
set_face_indices(mface, indices, false);
indices += 3;
#if 0
for (k = 0; k < totuvset; k++) {
if (!index_list_array.empty() && index_list_array[k]) {
// get mtface by face index and uv set index
@ -1567,6 +1689,15 @@ private:
set_face_uv(&mtface[face_index], uvs, k, *index_list_array[k], index, false);
}
}
#else
for (k = 0; k < index_list_array.getCount(); k++) {
int uvset_index = index_list_array[k]->getSetIndex();
// get mtface by face index and uv set index
MTFace *mtface = (MTFace*)CustomData_get_layer_n(&me->fdata, CD_MTFACE, uvset_index);
set_face_uv(&mtface[face_index], uvs, *index_list_array[k], index, false);
}
#endif
test_index_face(mface, &me->fdata, face_index, 3);
@ -1598,6 +1729,7 @@ private:
// set mtface for each uv set
// it is assumed that all primitives have equal number of UV sets
#if 0
for (k = 0; k < totuvset; k++) {
if (!index_list_array.empty() && index_list_array[k]) {
// get mtface by face index and uv set index
@ -1605,6 +1737,15 @@ private:
set_face_uv(&mtface[face_index], uvs, k, *index_list_array[k], index, mface->v4 != 0);
}
}
#else
for (k = 0; k < index_list_array.getCount(); k++) {
int uvset_index = index_list_array[k]->getSetIndex();
// get mtface by face index and uv set index
MTFace *mtface = (MTFace*)CustomData_get_layer_n(&me->fdata, CD_MTFACE, uvset_index);
set_face_uv(&mtface[face_index], uvs, *index_list_array[k], index, mface->v4 != 0);
}
#endif
test_index_face(mface, &me->fdata, face_index, vcount);
@ -1640,6 +1781,7 @@ private:
set_face_indices(mface, tri_indices, false);
#if 0
for (unsigned int l = 0; l < totuvset; l++) {
if (!index_list_array.empty() && index_list_array[l]) {
// get mtface by face index and uv set index
@ -1647,6 +1789,16 @@ private:
set_face_uv(&mtface[face_index], uvs, l, *index_list_array[l], uv_indices);
}
}
#else
for (unsigned int l = 0; l < index_list_array.getCount(); l++) {
int uvset_index = index_list_array[l]->getSetIndex();
// get mtface by face index and uv set index
MTFace *mtface = (MTFace*)CustomData_get_layer_n(&me->fdata, CD_MTFACE, uvset_index);
set_face_uv(&mtface[face_index], uvs, *index_list_array[l], uv_indices);
}
#endif
test_index_face(mface, &me->fdata, face_index, 3);

@ -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 Main;
struct bContext;

@ -1,4 +1,30 @@
#!/usr/bin/python
# $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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# The Original Code is Copyright (C) 2006, Blender Foundation
# All rights reserved.
#
# The Original Code is: all of this file.
#
# Contributor(s): Arystanbek Dyussenov, Nathan Letwory.
#
# ***** END GPL LICENSE BLOCK *****
Import ('env')
sources = env.Glob('*.cpp')

@ -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 *****
*/
#include "BKE_main.h"
#include "BKE_scene.h"
#include "BKE_context.h"

@ -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 *****
*/
#ifndef BLENDER_COLLADA_H
#define BLENDER_COLLADA_H

@ -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 *****
*/
#ifndef BLENDER_COLLADA_H
#define BLENDER_COLLADA_H