void ControllerExporter::export_morph_controller(Object *ob, Key *key) { bool use_instantiation = this->export_settings->use_object_instantiation; Mesh *me; me = bc_get_mesh_copy(scene, ob, this->export_settings->export_mesh_type, this->export_settings->apply_modifiers, this->export_settings->triangulate); std::string controller_name = id_name(ob) + "-morph"; std::string controller_id = get_controller_id(key, ob); openMorph(controller_id, controller_name, COLLADABU::URI(COLLADABU::Utils::EMPTY_STRING, get_geometry_id(ob, use_instantiation))); std::string targets_id = add_morph_targets(key, ob); std::string morph_weights_id = add_morph_weights(key, ob); COLLADASW::TargetsElement targets(mSW); COLLADASW::InputList &input = targets.getInputList(); input.push_back(COLLADASW::Input(COLLADASW::InputSemantic::MORPH_TARGET, // constant declared in COLLADASWInputList.h COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, targets_id))); input.push_back(COLLADASW::Input(COLLADASW::InputSemantic::MORPH_WEIGHT, COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, morph_weights_id))); targets.add(); BKE_libblock_free_us(G.main, me); //support for animations //can also try the base element and param alternative add_weight_extras(key); closeMorph(); closeController(); }
static bool ED_object_shape_key_remove_all(Main *bmain, Object *ob) { Key *key; key = BKE_key_from_object(ob); if (key == NULL) return false; switch (GS(key->from->name)) { case ID_ME: ((Mesh *)key->from)->key = NULL; break; case ID_CU: ((Curve *)key->from)->key = NULL; break; case ID_LT: ((Lattice *)key->from)->key = NULL; break; } BKE_libblock_free_us(bmain, key); return true; }
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; }
static bool ED_object_shape_key_remove(Main *bmain, Object *ob) { KeyBlock *kb, *rkb; Key *key; key = BKE_key_from_object(ob); if (key == NULL) return false; kb = BLI_findlink(&key->block, ob->shapenr - 1); if (kb) { for (rkb = key->block.first; rkb; rkb = rkb->next) if (rkb->relative == ob->shapenr - 1) rkb->relative = 0; BLI_remlink(&key->block, kb); key->totkey--; if (key->refkey == kb) { key->refkey = key->block.first; if (key->refkey) { /* apply new basis key on original data */ switch (ob->type) { case OB_MESH: BKE_key_convert_to_mesh(key->refkey, ob->data); break; case OB_CURVE: case OB_SURF: BKE_key_convert_to_curve(key->refkey, ob->data, BKE_curve_nurbs_get(ob->data)); break; case OB_LATTICE: BKE_key_convert_to_lattice(key->refkey, ob->data); break; } } } if (kb->data) MEM_freeN(kb->data); MEM_freeN(kb); if (ob->shapenr > 1) { ob->shapenr--; } } if (key->totkey == 0) { switch (GS(key->from->name)) { case ID_ME: ((Mesh *)key->from)->key = NULL; break; case ID_CU: ((Curve *)key->from)->key = NULL; break; case ID_LT: ((Lattice *)key->from)->key = NULL; break; } BKE_libblock_free_us(bmain, key); } return true; }
void GeometryExporter::operator()(Object *ob) { // XXX don't use DerivedMesh, Mesh instead? #if 0 DerivedMesh *dm = mesh_get_derived_final(mScene, ob, CD_MASK_BAREMESH); #endif bool use_instantiation = this->export_settings->use_object_instantiation; Mesh *me = bc_get_mesh_copy( mScene, ob, this->export_settings->export_mesh_type, this->export_settings->apply_modifiers, this->export_settings->triangulate); Mesh *mesh = (Mesh *) ob->data; me->flag = mesh->flag; std::string geom_id = get_geometry_id(ob, use_instantiation); std::vector<Normal> nor; std::vector<BCPolygonNormalsIndices> norind; // Skip if linked geometry was already exported from another reference if (use_instantiation && exportedGeometry.find(geom_id) != exportedGeometry.end()) { return; } std::string geom_name = (use_instantiation) ? id_name(ob->data) : id_name(ob); exportedGeometry.insert(geom_id); bool has_color = (bool)CustomData_has_layer(&me->fdata, CD_MCOL); create_normals(nor, norind, me); // openMesh(geoId, geoName, meshId) openMesh(geom_id, geom_name); // writes <source> for vertex coords createVertsSource(geom_id, me); // writes <source> for normal coords createNormalsSource(geom_id, me, nor); bool has_uvs = (bool)CustomData_has_layer(&me->fdata, CD_MTFACE); // writes <source> for uv coords if mesh has uv coords if (has_uvs) { createTexcoordsSource(geom_id, me); } if (has_color) { createVertexColorSource(geom_id, me); } // <vertices> COLLADASW::Vertices verts(mSW); verts.setId(getIdBySemantics(geom_id, COLLADASW::InputSemantic::VERTEX)); COLLADASW::InputList &input_list = verts.getInputList(); COLLADASW::Input input(COLLADASW::InputSemantic::POSITION, getUrlBySemantics(geom_id, COLLADASW::InputSemantic::POSITION)); input_list.push_back(input); verts.add(); createLooseEdgeList(ob, me, geom_id); // Only create Polylists if number of faces > 0 if (me->totface > 0) { // XXX slow if (ob->totcol) { for (int a = 0; a < ob->totcol; a++) { createPolylist(a, has_uvs, has_color, ob, me, geom_id, norind); } } else { createPolylist(0, has_uvs, has_color, ob, me, geom_id, norind); } } closeMesh(); if (me->flag & ME_TWOSIDED) { mSW->appendTextBlock("<extra><technique profile=\"MAYA\"><double_sided>1</double_sided></technique></extra>"); } closeGeometry(); if (this->export_settings->include_shapekeys) { Key * key = BKE_key_from_object(ob); if (key) { KeyBlock * kb = (KeyBlock *)key->block.first; //skip the basis kb = kb->next; for (; kb; kb = kb->next) { BKE_keyblock_convert_to_mesh(kb, me); export_key_mesh(ob, me, kb); } } } BKE_libblock_free_us(G.main, me); }