Object *DocumentImporter::create_instance_node(Object *source_ob, COLLADAFW::Node *source_node, COLLADAFW::Node *instance_node, Scene *sce, bool is_library_node) { fprintf(stderr, "create <instance_node> under node id=%s from node id=%s\n", instance_node ? instance_node->getOriginalId().c_str() : NULL, source_node ? source_node->getOriginalId().c_str() : NULL); Object *obn = BKE_object_copy(source_ob); DAG_id_tag_update(&obn->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME); BKE_scene_base_add(sce, obn); if (instance_node) { anim_importer.read_node_transform(instance_node, obn); // if we also have a source_node (always ;), take its // transformation matrix and apply it to the newly instantiated // object to account for node hierarchy transforms in // .dae if (source_node) { COLLADABU::Math::Matrix4 mat4 = source_node->getTransformationMatrix(); COLLADABU::Math::Matrix4 bmat4 = mat4.transpose(); // transpose to get blender row-major order float mat[4][4]; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { mat[i][j] = bmat4[i][j]; } } // calc new matrix and apply mul_m4_m4m4(obn->obmat, obn->obmat, mat); BKE_object_apply_mat4(obn, obn->obmat, 0, 0); } } else { anim_importer.read_node_transform(source_node, obn); } /*DAG_relations_tag_update(CTX_data_main(mContext));*/ COLLADAFW::NodePointerArray &children = source_node->getChildNodes(); if (children.getCount()) { for (unsigned int i = 0; i < children.getCount(); i++) { COLLADAFW::Node *child_node = children[i]; const COLLADAFW::UniqueId& child_id = child_node->getUniqueId(); if (object_map.find(child_id) == object_map.end()) continue; COLLADAFW::InstanceNodePointerArray &inodes = child_node->getInstanceNodes(); Object *new_child = NULL; if (inodes.getCount()) { // \todo loop through instance nodes const COLLADAFW::UniqueId& id = inodes[0]->getInstanciatedObjectId(); fprintf(stderr, "Doing %d child nodes\n", (int)node_map.count(id)); new_child = create_instance_node(object_map.find(id)->second, node_map[id], child_node, sce, is_library_node); } else { new_child = create_instance_node(object_map.find(child_id)->second, child_node, NULL, sce, is_library_node); } bc_set_parent(new_child, obn, mContext, true); if (is_library_node) libnode_ob.push_back(new_child); } } return obn; }
BL_ArmatureObject::BL_ArmatureObject( void* sgReplicationInfo, SG_Callbacks callbacks, Object *armature, Scene *scene, int vert_deform_type) : KX_GameObject(sgReplicationInfo,callbacks), m_controlledConstraints(), m_poseChannels(), m_scene(scene), // maybe remove later. needed for BKE_pose_where_is m_lastframe(0.0), m_timestep(0.040), m_vert_deform_type(vert_deform_type), m_constraintNumber(0), m_channelNumber(0), m_lastapplyframe(0.0) { m_origObjArma = armature; // Keep a copy of the original armature so we can fix drivers later m_objArma = BKE_object_copy(armature); m_objArma->data = BKE_armature_copy((bArmature *)armature->data); m_pose = m_objArma->pose; // need this to get iTaSC working ok in the BGE m_pose->flag |= POSE_GAME_ENGINE; memcpy(m_obmat, m_objArma->obmat, sizeof(m_obmat)); // The side-effect of this method registers this object as "animatable" with the KX_Scene. GetActionManager(); }
void BL_ArmatureObject::ProcessReplica() { KX_GameObject::ProcessReplica(); bArmature* tmp = (bArmature*)m_objArma->data; m_objArma = BKE_object_copy(m_objArma); m_objArma->data = BKE_armature_copy(tmp); m_pose = m_objArma->pose; }
int id_copy(ID *id, ID **newid, int test) { if (!test) *newid = NULL; /* conventions: * - make shallow copy, only this ID block * - id.us of the new ID is set to 1 */ switch (GS(id->name)) { case ID_SCE: return 0; /* can't be copied from here */ case ID_LI: return 0; /* can't be copied from here */ case ID_OB: if (!test) *newid = (ID *)BKE_object_copy((Object *)id); return 1; case ID_ME: if (!test) *newid = (ID *)BKE_mesh_copy((Mesh *)id); return 1; case ID_CU: if (!test) *newid = (ID *)BKE_curve_copy((Curve *)id); return 1; case ID_MB: if (!test) *newid = (ID *)BKE_mball_copy((MetaBall *)id); return 1; case ID_MA: if (!test) *newid = (ID *)BKE_material_copy((Material *)id); return 1; case ID_TE: if (!test) *newid = (ID *)BKE_texture_copy((Tex *)id); return 1; case ID_IM: if (!test) *newid = (ID *)BKE_image_copy((Image *)id); return 1; case ID_LT: if (!test) *newid = (ID *)BKE_lattice_copy((Lattice *)id); return 1; case ID_LA: if (!test) *newid = (ID *)BKE_lamp_copy((Lamp *)id); return 1; case ID_SPK: if (!test) *newid = (ID *)BKE_speaker_copy((Speaker *)id); return 1; case ID_CA: if (!test) *newid = (ID *)BKE_camera_copy((Camera *)id); return 1; case ID_IP: return 0; /* deprecated */ case ID_KE: if (!test) *newid = (ID *)BKE_key_copy((Key *)id); return 1; case ID_WO: if (!test) *newid = (ID *)BKE_world_copy((World *)id); return 1; case ID_SCR: return 0; /* can't be copied from here */ case ID_VF: return 0; /* not implemented */ case ID_TXT: if (!test) *newid = (ID *)BKE_text_copy((Text *)id); return 1; case ID_SCRIPT: return 0; /* deprecated */ case ID_SO: return 0; /* not implemented */ case ID_GR: if (!test) *newid = (ID *)BKE_group_copy((Group *)id); return 1; case ID_AR: if (!test) *newid = (ID *)BKE_armature_copy((bArmature *)id); return 1; case ID_AC: if (!test) *newid = (ID *)BKE_action_copy((bAction *)id); return 1; case ID_NT: if (!test) *newid = (ID *)ntreeCopyTree((bNodeTree *)id); return 1; case ID_BR: if (!test) *newid = (ID *)BKE_brush_copy((Brush *)id); return 1; case ID_PA: if (!test) *newid = (ID *)BKE_particlesettings_copy((ParticleSettings *)id); return 1; case ID_WM: return 0; /* can't be copied from here */ case ID_GD: return 0; /* not implemented */ } return 0; }