Blender V2.61 - r43446
|
00001 /* 00002 * $Id: GroupExporter.cpp 40019 2011-09-07 18:23:30Z jesterking $ 00003 * 00004 * ***** BEGIN GPL LICENSE BLOCK ***** 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * as published by the Free Software Foundation; either version 2 00009 * of the License, or (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software Foundation, 00018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 * 00020 * Contributor(s): Chingiz Dyussenov, Arystanbek Dyussenov, Jan Diederich, Tod Liverseed. 00021 * 00022 * ***** END GPL LICENSE BLOCK ***** 00023 */ 00024 00029 #include "GroupExporter.h" 00030 00031 GroupExporter::GroupExporter(COLLADASW::StreamWriter *sw, ArmatureExporter *arm, const ExportSettings *export_settings) 00032 : LibraryNodes(sw), arm_exporter(arm), export_settings(export_settings) 00033 {} 00034 00035 void GroupExporter::exportScene(Scene *sce) 00036 { 00037 this->scene = sce; 00038 // <library_visual_scenes> <visual_scene> 00039 std::string id_naming = id_name(this->scene); 00040 openNode(translate_id(id_naming), id_naming); 00041 exportGroups(); 00042 closeNode(); 00043 closeLibrary(); 00044 } 00045 00046 void GroupExporter::exportGroups() 00047 { 00048 Base *base= (Base*) this->scene->base.first; 00049 while(base) { 00050 Object *ob = base->object; 00051 00052 if (!ob->parent) { 00053 if(this->scene->lay & ob->lay) { 00054 switch(ob->type) { 00055 case OB_EMPTY: 00056 if (this->export_settings->selected && !(ob->flag & SELECT) && (ob->transflag & OB_DUPLIGROUP) == OB_DUPLIGROUP && ob->dup_group) { 00057 // write groups .... 00058 writeGroups(ob); 00059 } 00060 break; 00061 } 00062 } 00063 } 00064 00065 base= base->next; 00066 } 00067 } 00068 00069 void GroupExporter::createGroupsList() 00070 { 00071 Base *base; //= (Base*) this->scene->base.first; 00072 for(base = (Base *)this->scene->base.first; base; base=base->next) { 00073 Object *ob = base->object; 00074 00075 if (!ob->parent) { 00076 if(this->scene->lay & ob->lay) { 00077 switch(ob->type) { 00078 case OB_EMPTY: 00079 if (this->export_settings->selected && !(ob->flag & SELECT) && (ob->transflag & OB_DUPLIGROUP) == OB_DUPLIGROUP && ob->dup_group) { 00080 addGroupToList(ob); 00081 } 00082 } 00083 } 00084 } 00085 } 00086 } 00087 00088 void GroupExporter::addGroupToList(Object *ob) 00089 { 00090 //if(this->groups 00091 this->groups.push_back(ob->dup_group); 00092 // write nodes for child objects 00093 Base *b; 00094 for(b = (Base *)this->scene->base.first; b; b=b->next) { 00095 // cob - child object 00096 Object *cob = b->object; 00097 if(cob->parent==ob) { 00098 } 00099 } 00100 } 00101 00102 void GroupExporter::writeGroups(Object *ob) 00103 { 00104 COLLADASW::Node node(mSW); 00105 node.setNodeId(translate_id(id_name(ob))); 00106 node.setType(COLLADASW::Node::NODE); 00107 00108 node.start(); 00109 00110 bool is_skinned_mesh = arm_exporter->is_skinned_mesh(ob); 00111 00112 if (ob->type == OB_MESH && is_skinned_mesh) 00113 // for skinned mesh we write obmat in <bind_shape_matrix> 00114 TransformWriter::add_node_transform_identity(node); 00115 else 00116 TransformWriter::add_node_transform_ob(node, ob); 00117 00118 // <instance_geometry> 00119 if (ob->type == OB_MESH) { 00120 if (is_skinned_mesh) { 00121 arm_exporter->add_instance_controller(ob); 00122 } 00123 else { 00124 COLLADASW::InstanceGeometry instGeom(mSW); 00125 instGeom.setUrl(COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, get_geometry_id(ob))); 00126 00127 InstanceWriter::add_material_bindings(instGeom.getBindMaterial(), ob); 00128 00129 instGeom.add(); 00130 } 00131 } 00132 00133 // <instance_controller> 00134 else if (ob->type == OB_ARMATURE) { 00135 arm_exporter->add_armature_bones(ob, this->scene); 00136 00137 // XXX this looks unstable... 00138 node.end(); 00139 } 00140 00141 // <instance_camera> 00142 else if (ob->type == OB_CAMERA) { 00143 COLLADASW::InstanceCamera instCam(mSW, COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, get_camera_id(ob))); 00144 instCam.add(); 00145 } 00146 00147 // <instance_light> 00148 else if (ob->type == OB_LAMP) { 00149 COLLADASW::InstanceLight instLa(mSW, COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, get_light_id(ob))); 00150 instLa.add(); 00151 } 00152 00153 // empty object 00154 else if (ob->type == OB_EMPTY) { // TODO: handle groups (OB_DUPLIGROUP 00155 if((ob->transflag & OB_DUPLIGROUP) == OB_DUPLIGROUP && ob->dup_group) { 00156 GroupObject *go = NULL; 00157 Group *gr = ob->dup_group; 00158 /*printf("group detected %u\n", gr); 00159 for(go = (GroupObject*)(gr->gobject.first); go; go=go->next) { 00160 printf("\t%s\n", go->ob->id.name); 00161 }*/ 00162 } 00163 } 00164 00165 // write nodes for child objects 00166 Base *b = (Base*) this->scene->base.first; 00167 while(b) { 00168 // cob - child object 00169 Object *cob = b->object; 00170 00171 if (cob->parent == ob) { 00172 switch(cob->type) { 00173 case OB_MESH: 00174 case OB_CAMERA: 00175 case OB_LAMP: 00176 case OB_EMPTY: 00177 case OB_ARMATURE: 00178 // write node... 00179 writeGroups(cob); 00180 break; 00181 } 00182 } 00183 00184 b = b->next; 00185 } 00186 00187 if (ob->type != OB_ARMATURE) 00188 node.end(); 00189 } 00190