Ejemplo n.º 1
0
Mesh *BKE_mesh_copy_ex(Main *bmain, Mesh *me)
{
	Mesh *men;
	MTFace *tface;
	MTexPoly *txface;
	int a, i;
	const int do_tessface = ((me->totface != 0) && (me->totpoly == 0)); /* only do tessface if we have no polys */
	
	men = BKE_libblock_copy_ex(bmain, &me->id);
	
	men->mat = MEM_dupallocN(me->mat);
	for (a = 0; a < men->totcol; a++) {
		id_us_plus((ID *)men->mat[a]);
	}
	id_us_plus((ID *)men->texcomesh);

	CustomData_copy(&me->vdata, &men->vdata, CD_MASK_MESH, CD_DUPLICATE, men->totvert);
	CustomData_copy(&me->edata, &men->edata, CD_MASK_MESH, CD_DUPLICATE, men->totedge);
	CustomData_copy(&me->ldata, &men->ldata, CD_MASK_MESH, CD_DUPLICATE, men->totloop);
	CustomData_copy(&me->pdata, &men->pdata, CD_MASK_MESH, CD_DUPLICATE, men->totpoly);
	if (do_tessface) {
		CustomData_copy(&me->fdata, &men->fdata, CD_MASK_MESH, CD_DUPLICATE, men->totface);
	}
	else {
		mesh_tessface_clear_intern(men, FALSE);
	}

	BKE_mesh_update_customdata_pointers(men, do_tessface);

	/* ensure indirect linked data becomes lib-extern */
	for (i = 0; i < me->fdata.totlayer; i++) {
		if (me->fdata.layers[i].type == CD_MTFACE) {
			tface = (MTFace *)me->fdata.layers[i].data;

			for (a = 0; a < me->totface; a++, tface++)
				if (tface->tpage)
					id_lib_extern((ID *)tface->tpage);
		}
	}
	
	for (i = 0; i < me->pdata.totlayer; i++) {
		if (me->pdata.layers[i].type == CD_MTEXPOLY) {
			txface = (MTexPoly *)me->pdata.layers[i].data;

			for (a = 0; a < me->totpoly; a++, txface++)
				if (txface->tpage)
					id_lib_extern((ID *)txface->tpage);
		}
	}

	men->edit_btmesh = NULL;

	men->mselect = MEM_dupallocN(men->mselect);
	men->bb = MEM_dupallocN(men->bb);
	
	men->key = BKE_key_copy(me->key);
	if (men->key) men->key->from = (ID *)men;

	return men;
}
Ejemplo n.º 2
0
Lattice *BKE_lattice_copy(Lattice *lt)
{
	Lattice *ltn;

	ltn = BKE_libblock_copy(&lt->id);
	ltn->def = MEM_dupallocN(lt->def);

	ltn->key = BKE_key_copy(ltn->key);
	if (ltn->key) ltn->key->from = (ID *)ltn;
	
	if (lt->dvert) {
		int tot = lt->pntsu * lt->pntsv * lt->pntsw;
		ltn->dvert = MEM_mallocN(sizeof(MDeformVert) * tot, "Lattice MDeformVert");
		copy_dverts(ltn->dvert, lt->dvert, tot);
	}

	ltn->editlatt = NULL;

	return ltn;
}
Ejemplo n.º 3
0
Lattice *BKE_lattice_copy(Lattice *lt)
{
	Lattice *ltn;

	ltn = BKE_libblock_copy(&lt->id);
	ltn->def = MEM_dupallocN(lt->def);

	ltn->key = BKE_key_copy(ltn->key);
	if (ltn->key) ltn->key->from = (ID *)ltn;
	
	if (lt->dvert) {
		int tot = lt->pntsu * lt->pntsv * lt->pntsw;
		ltn->dvert = MEM_mallocN(sizeof(MDeformVert) * tot, "Lattice MDeformVert");
		BKE_defvert_array_copy(ltn->dvert, lt->dvert, tot);
	}

	ltn->editlatt = NULL;

	if (lt->id.lib) {
		BKE_id_lib_local_paths(G.main, lt->id.lib, &ltn->id);
	}

	return ltn;
}
Ejemplo n.º 4
0
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;
}