void DocumentImporter::translate_anim_recursive(COLLADAFW::Node *node, COLLADAFW::Node *par = NULL, Object *parob = NULL) { if (par && par->getType() == COLLADAFW::Node::JOINT) { // par is root if there's no corresp. key in root_map if (root_map.find(par->getUniqueId()) == root_map.end()) root_map[node->getUniqueId()] = par; else root_map[node->getUniqueId()] = root_map[par->getUniqueId()]; } /*COLLADAFW::Transformation::TransformationType types[] = { COLLADAFW::Transformation::ROTATE, COLLADAFW::Transformation::SCALE, COLLADAFW::Transformation::TRANSLATE, COLLADAFW::Transformation::MATRIX }; Object *ob;*/ unsigned int i; //for (i = 0; i < 4; i++) //ob = anim_importer.translate_Animations(node, root_map, object_map, FW_object_map); COLLADAFW::NodePointerArray &children = node->getChildNodes(); for (i = 0; i < children.getCount(); i++) { translate_anim_recursive(children[i], node, NULL); } }
void DocumentImporter::translate_anim_recursive(COLLADAFW::Node *node, COLLADAFW::Node *par = NULL, Object *parob = NULL) { // The split in #29246, rootmap must point at actual root when // calculating bones in apply_curves_as_matrix. - actual root is the root node. // This has to do with inverse bind poses being world space // (the sources for skinned bones' restposes) and the way // non-skinning nodes have their "restpose" recursively calculated. // XXX TODO: design issue, how to support unrelated joints taking // part in skinning. if (par) { // && par->getType() == COLLADAFW::Node::JOINT) { // par is root if there's no corresp. key in root_map if (root_map.find(par->getUniqueId()) == root_map.end()) root_map[node->getUniqueId()] = node; else root_map[node->getUniqueId()] = root_map[par->getUniqueId()]; } #if 0 COLLADAFW::Transformation::TransformationType types[] = { COLLADAFW::Transformation::ROTATE, COLLADAFW::Transformation::SCALE, COLLADAFW::Transformation::TRANSLATE, COLLADAFW::Transformation::MATRIX }; Object *ob; #endif unsigned int i; if (node->getType() == COLLADAFW::Node::JOINT && par == NULL) { // For Skeletons without root node we have to simulate the // root node here and recursively enter the same function // XXX: maybe this can be made more elegant. translate_anim_recursive(node, node, parob); } else { anim_importer.translate_Animations(node, root_map, object_map, FW_object_map); COLLADAFW::NodePointerArray &children = node->getChildNodes(); for (i = 0; i < children.getCount(); i++) { translate_anim_recursive(children[i], node, NULL); } } }
void DocumentImporter::finish() { if (mImportStage != General) return; Main *bmain = CTX_data_main(mContext); // TODO: create a new scene except the selected <visual_scene> - use current blender scene for it Scene *sce = CTX_data_scene(mContext); unit_converter.calculate_scale(*sce); std::vector<Object *> *objects_to_scale = new std::vector<Object *>(); /** TODO Break up and put into 2-pass parsing of DAE */ std::vector<const COLLADAFW::VisualScene *>::iterator it; for (it = vscenes.begin(); it != vscenes.end(); it++) { PointerRNA sceneptr, unit_settings; PropertyRNA *system, *scale; // 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"); if (this->import_settings->import_units) { 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; } float unit_factor = unit_converter.getLinearMeter(); RNA_property_float_set(&unit_settings, scale, unit_factor); fprintf(stdout, "Collada: Adjusting Blender units to Importset units: %f.\n", unit_factor); } // Write nodes to scene const COLLADAFW::NodePointerArray& roots = (*it)->getRootNodes(); for (unsigned int i = 0; i < roots.getCount(); i++) { std::vector<Object *> *objects_done = write_node(roots[i], NULL, sce, NULL, false); objects_to_scale->insert(objects_to_scale->end(), objects_done->begin(), objects_done->end()); delete objects_done; } // update scene DAG_relations_tag_update(bmain); WM_event_add_notifier(mContext, NC_OBJECT | ND_TRANSFORM, NULL); } mesh_importer.optimize_material_assignements(); armature_importer.set_tags_map(this->uid_tags_map); armature_importer.make_armatures(mContext); armature_importer.make_shape_keys(); DAG_relations_tag_update(bmain); #if 0 armature_importer.fix_animation(); #endif for (std::vector<const COLLADAFW::VisualScene *>::iterator it = vscenes.begin(); it != vscenes.end(); it++) { const COLLADAFW::NodePointerArray& roots = (*it)->getRootNodes(); for (unsigned int i = 0; i < roots.getCount(); i++) { translate_anim_recursive(roots[i], NULL, NULL); } } if (libnode_ob.size()) { Scene *sce = CTX_data_scene(mContext); fprintf(stderr, "got %d library nodes to free\n", (int)libnode_ob.size()); // free all library_nodes std::vector<Object *>::iterator it; for (it = libnode_ob.begin(); it != libnode_ob.end(); it++) { Object *ob = *it; Base *base = BKE_scene_base_find(sce, ob); if (base) { BLI_remlink(&sce->base, base); BKE_libblock_free_us(G.main, base->object); if (sce->basact == base) sce->basact = NULL; MEM_freeN(base); } } libnode_ob.clear(); DAG_relations_tag_update(bmain); } bc_match_scale(objects_to_scale, unit_converter, !this->import_settings->import_units); delete objects_to_scale; }
void DocumentImporter::finish() { if(mImportStage!=General) return; /** TODO Break up and put into 2-pass parsing of DAE */ 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++) { write_node(roots[i], NULL, sce, NULL, false); } } armature_importer.set_tags_map(this->uid_tags_map); armature_importer.make_armatures(mContext); #if 0 armature_importer.fix_animation(); #endif for (std::vector<const COLLADAFW::VisualScene*>::iterator it = vscenes.begin(); it != vscenes.end(); it++) { const COLLADAFW::NodePointerArray& roots = (*it)->getRootNodes(); for (unsigned int i = 0; i < roots.getCount(); i++) translate_anim_recursive(roots[i],NULL,NULL); } if (libnode_ob.size()) { Scene *sce = CTX_data_scene(mContext); fprintf(stderr, "got %d library nodes to free\n", (int)libnode_ob.size()); // free all library_nodes std::vector<Object*>::iterator it; for (it = libnode_ob.begin(); it != libnode_ob.end(); it++) { Object *ob = *it; Base *base = object_in_scene(ob, sce); if (base) { BLI_remlink(&sce->base, base); free_libblock_us(&G.main->object, base->object); if (sce->basact==base) sce->basact= NULL; MEM_freeN(base); } } libnode_ob.clear(); DAG_scene_sort(CTX_data_main(mContext), sce); DAG_ids_flush_update(CTX_data_main(mContext), 0); } }