Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/mball.c
| Context not available. | |||||
| { | { | ||||
| BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(mb, id)); | BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(mb, id)); | ||||
| mb->is_basis = false; | |||||
| mb->size[0] = mb->size[1] = mb->size[2] = 1.0; | mb->size[0] = mb->size[1] = mb->size[2] = 1.0; | ||||
| mb->texflag = MB_AUTOSPACE; | mb->texflag = MB_AUTOSPACE; | ||||
| Context not available. | |||||
| { | { | ||||
| MetaBall *mb_copy; | MetaBall *mb_copy; | ||||
| BKE_id_copy(bmain, &mb->id, (ID **)&mb_copy); | BKE_id_copy(bmain, &mb->id, (ID **)&mb_copy); | ||||
| mb_copy->is_basis = false; | |||||
| return mb_copy; | return mb_copy; | ||||
| } | } | ||||
| Context not available. | |||||
| return orcodata; | return orcodata; | ||||
| } | } | ||||
| /* Note on mball basis stuff 2.5x (this is a can of worms) | /* Test if Object *ob is a basis MetaBall */ | ||||
| * This really needs a rewrite/refactor its totally broken in anything other then basic cases | bool BKE_mball_is_basis(Object *ob) | ||||
| * Multiple Scenes + Set Scenes & mixing mball basis SHOULD work but fails to update the depsgraph on rename | { | ||||
| * and linking into scenes or removal of basis mball. so take care when changing this code. | BLI_assert(ob->type == OB_MBALL); | ||||
| * | MetaBall *mball = (MetaBall *)ob->data; | ||||
| * Main idiot thing here is that the system returns find_basis_mball() objects which fail a is_basis_mball() test. | |||||
| * | |||||
| * Not only that but the depsgraph and their areas depend on this behavior!, so making small fixes here isn't worth it. | |||||
| * - Campbell | |||||
| */ | |||||
| return (mball->is_basis); | |||||
| } | |||||
| /** \brief Test, if Object *ob is basic MetaBall. | static void mball_set_basis(Object *ob, bool is_basis) | ||||
| * | |||||
| * It test last character of Object ID name. If last character | |||||
| * is digit it return 0, else it return 1. | |||||
| */ | |||||
| bool BKE_mball_is_basis(Object *ob) | |||||
| { | { | ||||
| /* just a quick test */ | MetaBall *mball = (MetaBall *)ob->data; | ||||
| const int len = strlen(ob->id.name); | |||||
| return (!isdigit(ob->id.name[len - 1])); | mball->is_basis = is_basis; | ||||
| } | } | ||||
| /* return nonzero if ob1 is a basis mball for ob */ | /* return nonzero if ob1 is a basis mball for ob */ | ||||
| Context not available. | |||||
| } | } | ||||
| } | } | ||||
| /** \brief This function finds basic MetaBall. | /** \brief This function finds the basis MetaBall. | ||||
| * | * | ||||
| * Basic MetaBall doesn't include any number at the end of | * All MetaBalls with the same base of name can be blended. | ||||
| * its name. All MetaBalls with same base of name can be | * MetaBalls with different basic name can't be blended. | ||||
| * blended. MetaBalls with different basic name can't be | |||||
| * blended. | |||||
| * | * | ||||
| * warning!, is_basis_mball() can fail on returned object, see long note above. | |||||
| */ | */ | ||||
| Object *BKE_mball_basis_find(Scene *scene, Object *basis) | Object *BKE_mball_basis_find(Scene *scene, Object *basis) | ||||
| { | { | ||||
| Object *bob = basis; | if (BKE_mball_is_basis(basis)){ | ||||
| int basisnr, obnr; | return basis; | ||||
| char basisname[MAX_ID_NAME], obname[MAX_ID_NAME]; | } | ||||
| BLI_split_name_num(basisname, &basisnr, basis->id.name + 2, '.'); | |||||
| Object *bob = basis; | |||||
| for (ViewLayer *view_layer = scene->view_layers.first; view_layer; view_layer = view_layer->next) { | for (ViewLayer *view_layer = scene->view_layers.first; view_layer; view_layer = view_layer->next) { | ||||
| for (Base *base = view_layer->object_bases.first; base; base = base->next) { | for (Base *base = view_layer->object_bases.first; base; base = base->next) { | ||||
| Object *ob = base->object; | Object *ob = base->object; | ||||
| if ((ob->type == OB_MBALL) && !(base->flag & BASE_FROM_DUPLI)) { | if ((ob->type == OB_MBALL) && !(base->flag & BASE_FROM_DUPLI)) { | ||||
| if (ob != bob) { | if (ob != bob) { | ||||
| BLI_split_name_num(obname, &obnr, ob->id.name + 2, '.'); | if (BKE_mball_is_basis_for(ob, basis)) { | ||||
| return ob; | |||||
| /* object ob has to be in same "group" ... it means, that it has to have same base of its name */ | |||||
| if (STREQ(obname, basisname)) { | |||||
| if (obnr < basisnr) { | |||||
| basis = ob; | |||||
| basisnr = obnr; | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* No basis object found, so set the input object to basis */ | |||||
| mball_set_basis(basis, true); | |||||
| return basis; | return basis; | ||||
| } | } | ||||
| Context not available. | |||||