Files
test2/source/blender/blenkernel/intern/mball.cc

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

662 lines
17 KiB
C++
Raw Normal View History

/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup bke
*
* MetaBalls are created from a single Object (with a name without number in it).
2011-10-10 09:38:02 +00:00
* All objects with the same name (but with a number in it) are added to this.
2002-10-12 11:37:38 +00:00
*/
#include <cctype>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
2002-10-12 11:37:38 +00:00
#include "MEM_guardedalloc.h"
/* Allow using deprecated functionality for .blend file I/O. */
#define DNA_DEPRECATED_ALLOW
#include "DNA_defaults.h"
2002-10-12 11:37:38 +00:00
#include "DNA_material_types.h"
#include "DNA_mesh_types.h"
2002-10-12 11:37:38 +00:00
#include "DNA_meta_types.h"
#include "DNA_object_types.h"
2002-10-12 11:37:38 +00:00
#include "DNA_scene_types.h"
#include "BLI_blenlib.h"
#include "BLI_math_matrix.h"
#include "BLI_math_rotation.h"
#include "BLI_math_vector.h"
#include "BLI_string_utils.hh"
#include "BLI_utildefines.h"
2002-10-12 11:37:38 +00:00
#include "BLT_translation.h"
#include "BKE_main.hh"
2002-10-12 11:37:38 +00:00
#include "BKE_anim_data.h"
#include "BKE_curve.hh"
#include "BKE_displist.h"
#include "BKE_geometry_set.hh"
#include "BKE_idtype.hh"
#include "BKE_lattice.hh"
2024-01-23 15:18:09 -05:00
#include "BKE_layer.hh"
2024-01-15 12:44:04 -05:00
#include "BKE_lib_id.hh"
#include "BKE_lib_query.hh"
#include "BKE_material.h"
#include "BKE_mball.hh"
#include "BKE_mball_tessellate.hh"
#include "BKE_mesh.hh"
#include "BKE_object.hh"
#include "BKE_object_types.hh"
#include "BKE_scene.h"
2002-10-12 11:37:38 +00:00
#include "DEG_depsgraph.hh"
#include "BLO_read_write.hh"
using blender::Span;
static void metaball_init_data(ID *id)
{
MetaBall *metaball = (MetaBall *)id;
BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(metaball, id));
2002-10-12 11:37:38 +00:00
MEMCPY_STRUCT_AFTER(metaball, DNA_struct_default_get(MetaBall), id);
}
static void metaball_copy_data(Main * /*bmain*/, ID *id_dst, const ID *id_src, const int /*flag*/)
2002-10-12 11:37:38 +00:00
{
MetaBall *metaball_dst = (MetaBall *)id_dst;
const MetaBall *metaball_src = (const MetaBall *)id_src;
2002-10-12 11:37:38 +00:00
BLI_duplicatelist(&metaball_dst->elems, &metaball_src->elems);
metaball_dst->mat = static_cast<Material **>(MEM_dupallocN(metaball_src->mat));
2002-10-12 11:37:38 +00:00
metaball_dst->editelems = nullptr;
metaball_dst->lastelem = nullptr;
2002-10-12 11:37:38 +00:00
}
static void metaball_free_data(ID *id)
2002-10-12 11:37:38 +00:00
{
MetaBall *metaball = (MetaBall *)id;
MEM_SAFE_FREE(metaball->mat);
BLI_freelistN(&metaball->elems);
}
static void metaball_foreach_id(ID *id, LibraryForeachIDData *data)
{
MetaBall *metaball = reinterpret_cast<MetaBall *>(id);
const int flag = BKE_lib_query_foreachid_process_flags_get(data);
for (int i = 0; i < metaball->totcol; i++) {
BKE_LIB_FOREACHID_PROCESS_IDSUPER(data, metaball->mat[i], IDWALK_CB_USER);
}
if (flag & IDWALK_DO_DEPRECATED_POINTERS) {
BKE_LIB_FOREACHID_PROCESS_ID_NOCHECK(data, metaball->ipo, IDWALK_CB_USER);
}
}
static void metaball_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{
MetaBall *mb = (MetaBall *)id;
/* Clean up, important in undo case to reduce false detection of changed datablocks. */
mb->editelems = nullptr;
/* Must always be cleared (meta's don't have their own edit-data). */
mb->needs_flush_to_id = 0;
mb->lastelem = nullptr;
/* write LibData */
BLO_write_id_struct(writer, MetaBall, id_address, &mb->id);
BKE_id_blend_write(writer, &mb->id);
/* direct data */
BLO_write_pointer_array(writer, mb->totcol, mb->mat);
LISTBASE_FOREACH (MetaElem *, ml, &mb->elems) {
BLO_write_struct(writer, MetaElem, ml);
}
}
static void metaball_blend_read_data(BlendDataReader *reader, ID *id)
{
MetaBall *mb = (MetaBall *)id;
BLO_read_pointer_array(reader, (void **)&mb->mat);
BLO_read_list(reader, &(mb->elems));
mb->editelems = nullptr;
/* Must always be cleared (meta's don't have their own edit-data). */
mb->needs_flush_to_id = 0;
// mb->edit_elems.first = mb->edit_elems.last = nullptr;
mb->lastelem = nullptr;
}
IDTypeInfo IDType_ID_MB = {
/*id_code*/ ID_MB,
/*id_filter*/ FILTER_ID_MB,
/*main_listbase_index*/ INDEX_ID_MB,
/*struct_size*/ sizeof(MetaBall),
/*name*/ "Metaball",
/*name_plural*/ N_("metaballs"),
/*translation_context*/ BLT_I18NCONTEXT_ID_METABALL,
/*flags*/ IDTYPE_FLAGS_APPEND_IS_REUSABLE,
/*asset_type_info*/ nullptr,
/*init_data*/ metaball_init_data,
/*copy_data*/ metaball_copy_data,
/*free_data*/ metaball_free_data,
/*make_local*/ nullptr,
/*foreach_id*/ metaball_foreach_id,
/*foreach_cache*/ nullptr,
/*foreach_path*/ nullptr,
/*owner_pointer_get*/ nullptr,
/*blend_write*/ metaball_blend_write,
/*blend_read_data*/ metaball_blend_read_data,
/*blend_read_after_liblink*/ nullptr,
/*blend_read_undo_preserve*/ nullptr,
/*lib_override_apply_post*/ nullptr,
};
/* Functions */
MetaBall *BKE_mball_add(Main *bmain, const char *name)
{
MetaBall *mb = static_cast<MetaBall *>(BKE_id_new(bmain, ID_MB, name));
2002-10-12 11:37:38 +00:00
return mb;
}
MetaElem *BKE_mball_element_add(MetaBall *mb, const int type)
{
MetaElem *ml = MEM_cnew<MetaElem>(__func__);
unit_qt(ml->quat);
ml->rad = 2.0;
ml->s = 2.0;
ml->flag = MB_SCALE_RAD;
switch (type) {
case MB_BALL:
ml->type = MB_BALL;
ml->expx = ml->expy = ml->expz = 1.0;
break;
case MB_TUBE:
ml->type = MB_TUBE;
ml->expx = ml->expy = ml->expz = 1.0;
break;
case MB_PLANE:
ml->type = MB_PLANE;
ml->expx = ml->expy = ml->expz = 1.0;
break;
case MB_ELIPSOID:
ml->type = MB_ELIPSOID;
ml->expx = 1.2f;
ml->expy = 0.8f;
ml->expz = 1.0;
break;
case MB_CUBE:
ml->type = MB_CUBE;
ml->expx = ml->expy = ml->expz = 1.0;
break;
default:
break;
}
BLI_addtail(&mb->elems, ml);
return ml;
}
2002-10-12 11:37:38 +00:00
bool BKE_mball_is_basis(const Object *ob)
{
/* Meta-Ball Basis Notes from Blender-2.5x
* =======================================
*
* NOTE(@ideasman42): This is a can of worms.
*
* This really needs a rewrite/refactor its totally broken in anything other than basic cases
* Multiple Scenes + Set Scenes & mixing meta-ball basis _should_ work but fails to update the
* depsgraph on rename and linking into scenes or removal of basis meta-ball.
* So take care when changing this code.
*
* Main idiot thing here is that the system returns #BKE_mball_basis_find()
* objects which fail a #BKE_mball_is_basis() test.
*
* Not only that but the depsgraph and their areas depend on this behavior,
* so making small fixes here isn't worth it. */
/* Just a quick test. */
2013-03-09 05:35:49 +00:00
const int len = strlen(ob->id.name);
2022-10-07 22:52:53 +11:00
return !isdigit(ob->id.name[len - 1]);
}
2002-10-12 11:37:38 +00:00
bool BKE_mball_is_same_group(const Object *ob1, const Object *ob2)
{
int basis1nr, basis2nr;
char basis1name[MAX_ID_NAME], basis2name[MAX_ID_NAME];
if (ob1->id.name[2] != ob2->id.name[2]) {
/* Quick return in case first char of both ID's names is not the same... */
return false;
}
BLI_string_split_name_number(ob1->id.name + 2, '.', basis1name, &basis1nr);
BLI_string_split_name_number(ob2->id.name + 2, '.', basis2name, &basis2nr);
return STREQ(basis1name, basis2name);
}
bool BKE_mball_is_basis_for(const Object *ob1, const Object *ob2)
{
return BKE_mball_is_same_group(ob1, ob2) && BKE_mball_is_basis(ob1);
}
bool BKE_mball_is_any_selected(const MetaBall *mb)
{
LISTBASE_FOREACH (const MetaElem *, ml, mb->editelems) {
if (ml->flag & SELECT) {
return true;
}
}
return false;
}
bool BKE_mball_is_any_selected_multi(const Span<Base *> bases)
{
for (Base *base : bases) {
Object *obedit = base->object;
MetaBall *mb = (MetaBall *)obedit->data;
if (BKE_mball_is_any_selected(mb)) {
return true;
}
}
return false;
}
bool BKE_mball_is_any_unselected(const MetaBall *mb)
{
LISTBASE_FOREACH (const MetaElem *, ml, mb->editelems) {
if ((ml->flag & SELECT) == 0) {
return true;
}
}
return false;
}
static void mball_data_properties_copy(MetaBall *mb_dst, MetaBall *mb_src)
{
mb_dst->wiresize = mb_src->wiresize;
mb_dst->rendersize = mb_src->rendersize;
mb_dst->thresh = mb_src->thresh;
mb_dst->flag = mb_src->flag;
DEG_id_tag_update(&mb_dst->id, 0);
}
void BKE_mball_properties_copy(Main *bmain, MetaBall *metaball_src)
{
/**
* WARNING: This code does not cover all potential corner-cases. E.g. if:
* <pre>
* | Object | ObData |
* | ---------- | ---------- |
* | Meta_A | Meta_A |
* | Meta_A.001 | Meta_A.001 |
* | Meta_B | Meta_A |
* | Meta_B.001 | Meta_B.001 |
* </pre>
*
* Calling this function with `metaball_src` being `Meta_A.001` will update `Meta_A`, but NOT
* `Meta_B.001`. So in the 'Meta_B' family, the two metaballs will have unmatching settings now.
*
* Solving this case would drastically increase the complexity of this code though, so don't
* think it would be worth it.
*/
for (Object *ob_src = static_cast<Object *>(bmain->objects.first);
ob_src != nullptr && !ID_IS_LINKED(ob_src);)
{
if (ob_src->data != metaball_src) {
ob_src = static_cast<Object *>(ob_src->id.next);
continue;
}
/* In this code we take advantage of two facts:
* - MetaBalls of the same family have the same basis name,
* - IDs are sorted by name in their Main listbase.
* So, all MetaBall objects of the same family are contiguous in bmain list (potentially mixed
* with non-meta-ball objects with same basis names).
*
* Using this, it is possible to process the whole set of meta-balls with a single loop on the
* whole list of Objects, though additionally going backward on part of the list in some cases.
*/
Object *ob_iter = nullptr;
int obactive_nr, ob_nr;
char obactive_name[MAX_ID_NAME], ob_name[MAX_ID_NAME];
BLI_string_split_name_number(ob_src->id.name + 2, '.', obactive_name, &obactive_nr);
for (ob_iter = static_cast<Object *>(ob_src->id.prev); ob_iter != nullptr;
ob_iter = static_cast<Object *>(ob_iter->id.prev))
{
if (ob_iter->id.name[2] != obactive_name[0]) {
break;
}
if (ob_iter->type != OB_MBALL || ob_iter->data == metaball_src) {
continue;
}
BLI_string_split_name_number(ob_iter->id.name + 2, '.', ob_name, &ob_nr);
if (!STREQ(obactive_name, ob_name)) {
break;
}
mball_data_properties_copy(static_cast<MetaBall *>(ob_iter->data), metaball_src);
}
for (ob_iter = static_cast<Object *>(ob_src->id.next); ob_iter != nullptr;
ob_iter = static_cast<Object *>(ob_iter->id.next))
{
if (ob_iter->id.name[2] != obactive_name[0] || ID_IS_LINKED(ob_iter)) {
break;
}
if (ob_iter->type != OB_MBALL || ob_iter->data == metaball_src) {
continue;
}
BLI_string_split_name_number(ob_iter->id.name + 2, '.', ob_name, &ob_nr);
if (!STREQ(obactive_name, ob_name)) {
break;
}
mball_data_properties_copy(static_cast<MetaBall *>(ob_iter->data), metaball_src);
}
ob_src = ob_iter;
}
}
Object *BKE_mball_basis_find(Scene *scene, Object *object)
2002-10-12 11:37:38 +00:00
{
Object *bob = object;
int basisnr, obnr;
char basisname[MAX_ID_NAME], obname[MAX_ID_NAME];
BLI_string_split_name_number(object->id.name + 2, '.', basisname, &basisnr);
LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) {
ViewLayer: Lazy sync of scene data. When a change happens which invalidates view layers the syncing will be postponed until the first usage. This will improve importing or adding many objects in a single operation/script. `BKE_view_layer_need_resync_tag` is used to tag the view layer to be out of sync. Before accessing `BKE_view_layer_active_base_get`, `BKE_view_layer_active_object_get`, `BKE_view_layer_active_collection` or `BKE_view_layer_object_bases` the caller should call `BKE_view_layer_synced_ensure`. Having two functions ensures that partial syncing could be added as smaller patches in the future. Tagging a view layer out of sync could be replaced with a partial sync. Eventually the number of full resyncs could be reduced. After all tagging has been replaced with partial syncs the ensure_sync could be phased out. This patch has been added to discuss the details and consequences of the current approach. For clarity the call to BKE_view_layer_ensure_sync is placed close to the getters. In the future this could be placed in more strategical places to reduce the number of calls or improve performance. Finding those strategical places isn't that clear. When multiple operations are grouped in a single script you might want to always check for resync. Some areas found that can be improved. This list isn't complete. These areas aren't addressed by this patch as these changes would be hard to detect to the reviewer. The idea is to add changes to these areas as a separate patch. It might be that the initial commit would reduce performance compared to master, but will be fixed by the additional patches. **Object duplication** During object duplication the syncing is temporarily disabled. With this patch this isn't useful as when disabled the view_layer is accessed to locate bases. This can be improved by first locating the source bases, then duplicate and sync and locate the new bases. Will be solved in a separate patch for clarity reasons ({D15886}). **Object add** `BKE_object_add` not only adds a new object, but also selects and activates the new base. This requires the view_layer to be resynced. Some callers reverse the selection and activation (See `get_new_constraint_target`). We should make the selection and activation optional. This would make it possible to add multiple objects without having to resync per object. **Postpone Activate Base** Setting the basact is done in many locations. They follow a rule as after an action find the base and set the basact. Finding the base could require a resync. The idea is to store in the view_layer the object which base will be set in the basact during the next sync, reducing the times resyncing needs to happen. Reviewed By: mont29 Maniphest Tasks: T73411 Differential Revision: https://developer.blender.org/D15885
2022-09-14 21:33:51 +02:00
BKE_view_layer_synced_ensure(scene, view_layer);
LISTBASE_FOREACH (Base *, base, BKE_view_layer_object_bases_get(view_layer)) {
Render Layers and Collections (merge from render-layers) Design Documents ---------------- * https://wiki.blender.org/index.php/Dev:2.8/Source/Layers * https://wiki.blender.org/index.php/Dev:2.8/Source/DataDesignRevised User Commit Log --------------- * New Layer and Collection system to replace render layers and viewport layers. * A layer is a set of collections of objects (and their drawing options) required for specific tasks. * A collection is a set of objects, equivalent of the old layers in Blender. A collection can be shared across multiple layers. * All Scenes have a master collection that all other collections are children of. * New collection "context" tab (in Properties Editor) * New temporary viewport "collections" panel to control per-collection visibility Missing User Features --------------------- * Collection "Filter" Option to add objects based on their names * Collection Manager operators The existing buttons are placeholders * Collection Manager drawing The editor main region is empty * Collection Override * Per-Collection engine settings This will come as a separate commit, as part of the clay-engine branch Dev Commit Log -------------- * New DNA file (DNA_layer_types.h) with the new structs We are replacing Base by a new extended Base while keeping it backward compatible with some legacy settings (i.e., lay, flag_legacy). Renamed all Base to BaseLegacy to make it clear the areas of code that still need to be converted Note: manual changes were required on - deg_builder_nodes.h, rna_object.c, KX_Light.cpp * Unittesting for main syncronization requirements - read, write, add/copy/remove objects, copy scene, collection link/unlinking, context) * New Editor: Collection Manager Based on patch by Julian Eisel This is extracted from the layer-manager branch. With the following changes: - Renamed references of layer manager to collections manager - I doesn't include the editors/space_collections/ draw and util files - The drawing code itself will be implemented separately by Julian * Base / Object: A little note about them. Original Blender code would try to keep them in sync through the code, juggling flags back and forth. This will now be handled by Depsgraph, keeping Object and Bases more separated throughout the non-rendering code. Scene.base is being cleared in doversion, and the old viewport drawing code was poorly converted to use the new bases while the new viewport code doesn't get merged and replace the old one. Python API Changes ------------------ ``` - scene.layers + # no longer exists - scene.objects + scene.scene_layers.active.objects - scene.objects.active + scene.render_layers.active.objects.active - bpy.context.scene.objects.link() + bpy.context.scene_collection.objects.link() - bpy_extras.object_utils.object_data_add(context, obdata, operator=None, use_active_layer=True, name=None) + bpy_extras.object_utils.object_data_add(context, obdata, operator=None, name=None) - bpy.context.object.select + bpy.context.object.select = True + bpy.context.object.select = False + bpy.context.object.select_get() + bpy.context.object.select_set(action='SELECT') + bpy.context.object.select_set(action='DESELECT') -AddObjectHelper.layers + # no longer exists ```
2017-02-07 10:18:38 +01:00
Object *ob = base->object;
if ((ob->type == OB_MBALL) && !(base->flag & BASE_FROM_DUPLI)) {
Render Layers and Collections (merge from render-layers) Design Documents ---------------- * https://wiki.blender.org/index.php/Dev:2.8/Source/Layers * https://wiki.blender.org/index.php/Dev:2.8/Source/DataDesignRevised User Commit Log --------------- * New Layer and Collection system to replace render layers and viewport layers. * A layer is a set of collections of objects (and their drawing options) required for specific tasks. * A collection is a set of objects, equivalent of the old layers in Blender. A collection can be shared across multiple layers. * All Scenes have a master collection that all other collections are children of. * New collection "context" tab (in Properties Editor) * New temporary viewport "collections" panel to control per-collection visibility Missing User Features --------------------- * Collection "Filter" Option to add objects based on their names * Collection Manager operators The existing buttons are placeholders * Collection Manager drawing The editor main region is empty * Collection Override * Per-Collection engine settings This will come as a separate commit, as part of the clay-engine branch Dev Commit Log -------------- * New DNA file (DNA_layer_types.h) with the new structs We are replacing Base by a new extended Base while keeping it backward compatible with some legacy settings (i.e., lay, flag_legacy). Renamed all Base to BaseLegacy to make it clear the areas of code that still need to be converted Note: manual changes were required on - deg_builder_nodes.h, rna_object.c, KX_Light.cpp * Unittesting for main syncronization requirements - read, write, add/copy/remove objects, copy scene, collection link/unlinking, context) * New Editor: Collection Manager Based on patch by Julian Eisel This is extracted from the layer-manager branch. With the following changes: - Renamed references of layer manager to collections manager - I doesn't include the editors/space_collections/ draw and util files - The drawing code itself will be implemented separately by Julian * Base / Object: A little note about them. Original Blender code would try to keep them in sync through the code, juggling flags back and forth. This will now be handled by Depsgraph, keeping Object and Bases more separated throughout the non-rendering code. Scene.base is being cleared in doversion, and the old viewport drawing code was poorly converted to use the new bases while the new viewport code doesn't get merged and replace the old one. Python API Changes ------------------ ``` - scene.layers + # no longer exists - scene.objects + scene.scene_layers.active.objects - scene.objects.active + scene.render_layers.active.objects.active - bpy.context.scene.objects.link() + bpy.context.scene_collection.objects.link() - bpy_extras.object_utils.object_data_add(context, obdata, operator=None, use_active_layer=True, name=None) + bpy_extras.object_utils.object_data_add(context, obdata, operator=None, name=None) - bpy.context.object.select + bpy.context.object.select = True + bpy.context.object.select = False + bpy.context.object.select_get() + bpy.context.object.select_set(action='SELECT') + bpy.context.object.select_set(action='DESELECT') -AddObjectHelper.layers + # no longer exists ```
2017-02-07 10:18:38 +01:00
if (ob != bob) {
BLI_string_split_name_number(ob->id.name + 2, '.', obname, &obnr);
Render Layers and Collections (merge from render-layers) Design Documents ---------------- * https://wiki.blender.org/index.php/Dev:2.8/Source/Layers * https://wiki.blender.org/index.php/Dev:2.8/Source/DataDesignRevised User Commit Log --------------- * New Layer and Collection system to replace render layers and viewport layers. * A layer is a set of collections of objects (and their drawing options) required for specific tasks. * A collection is a set of objects, equivalent of the old layers in Blender. A collection can be shared across multiple layers. * All Scenes have a master collection that all other collections are children of. * New collection "context" tab (in Properties Editor) * New temporary viewport "collections" panel to control per-collection visibility Missing User Features --------------------- * Collection "Filter" Option to add objects based on their names * Collection Manager operators The existing buttons are placeholders * Collection Manager drawing The editor main region is empty * Collection Override * Per-Collection engine settings This will come as a separate commit, as part of the clay-engine branch Dev Commit Log -------------- * New DNA file (DNA_layer_types.h) with the new structs We are replacing Base by a new extended Base while keeping it backward compatible with some legacy settings (i.e., lay, flag_legacy). Renamed all Base to BaseLegacy to make it clear the areas of code that still need to be converted Note: manual changes were required on - deg_builder_nodes.h, rna_object.c, KX_Light.cpp * Unittesting for main syncronization requirements - read, write, add/copy/remove objects, copy scene, collection link/unlinking, context) * New Editor: Collection Manager Based on patch by Julian Eisel This is extracted from the layer-manager branch. With the following changes: - Renamed references of layer manager to collections manager - I doesn't include the editors/space_collections/ draw and util files - The drawing code itself will be implemented separately by Julian * Base / Object: A little note about them. Original Blender code would try to keep them in sync through the code, juggling flags back and forth. This will now be handled by Depsgraph, keeping Object and Bases more separated throughout the non-rendering code. Scene.base is being cleared in doversion, and the old viewport drawing code was poorly converted to use the new bases while the new viewport code doesn't get merged and replace the old one. Python API Changes ------------------ ``` - scene.layers + # no longer exists - scene.objects + scene.scene_layers.active.objects - scene.objects.active + scene.render_layers.active.objects.active - bpy.context.scene.objects.link() + bpy.context.scene_collection.objects.link() - bpy_extras.object_utils.object_data_add(context, obdata, operator=None, use_active_layer=True, name=None) + bpy_extras.object_utils.object_data_add(context, obdata, operator=None, name=None) - bpy.context.object.select + bpy.context.object.select = True + bpy.context.object.select = False + bpy.context.object.select_get() + bpy.context.object.select_set(action='SELECT') + bpy.context.object.select_set(action='DESELECT') -AddObjectHelper.layers + # no longer exists ```
2017-02-07 10:18:38 +01:00
/* Object ob has to be in same "group" ... it means,
* that it has to have same base of its name. */
Render Layers and Collections (merge from render-layers) Design Documents ---------------- * https://wiki.blender.org/index.php/Dev:2.8/Source/Layers * https://wiki.blender.org/index.php/Dev:2.8/Source/DataDesignRevised User Commit Log --------------- * New Layer and Collection system to replace render layers and viewport layers. * A layer is a set of collections of objects (and their drawing options) required for specific tasks. * A collection is a set of objects, equivalent of the old layers in Blender. A collection can be shared across multiple layers. * All Scenes have a master collection that all other collections are children of. * New collection "context" tab (in Properties Editor) * New temporary viewport "collections" panel to control per-collection visibility Missing User Features --------------------- * Collection "Filter" Option to add objects based on their names * Collection Manager operators The existing buttons are placeholders * Collection Manager drawing The editor main region is empty * Collection Override * Per-Collection engine settings This will come as a separate commit, as part of the clay-engine branch Dev Commit Log -------------- * New DNA file (DNA_layer_types.h) with the new structs We are replacing Base by a new extended Base while keeping it backward compatible with some legacy settings (i.e., lay, flag_legacy). Renamed all Base to BaseLegacy to make it clear the areas of code that still need to be converted Note: manual changes were required on - deg_builder_nodes.h, rna_object.c, KX_Light.cpp * Unittesting for main syncronization requirements - read, write, add/copy/remove objects, copy scene, collection link/unlinking, context) * New Editor: Collection Manager Based on patch by Julian Eisel This is extracted from the layer-manager branch. With the following changes: - Renamed references of layer manager to collections manager - I doesn't include the editors/space_collections/ draw and util files - The drawing code itself will be implemented separately by Julian * Base / Object: A little note about them. Original Blender code would try to keep them in sync through the code, juggling flags back and forth. This will now be handled by Depsgraph, keeping Object and Bases more separated throughout the non-rendering code. Scene.base is being cleared in doversion, and the old viewport drawing code was poorly converted to use the new bases while the new viewport code doesn't get merged and replace the old one. Python API Changes ------------------ ``` - scene.layers + # no longer exists - scene.objects + scene.scene_layers.active.objects - scene.objects.active + scene.render_layers.active.objects.active - bpy.context.scene.objects.link() + bpy.context.scene_collection.objects.link() - bpy_extras.object_utils.object_data_add(context, obdata, operator=None, use_active_layer=True, name=None) + bpy_extras.object_utils.object_data_add(context, obdata, operator=None, name=None) - bpy.context.object.select + bpy.context.object.select = True + bpy.context.object.select = False + bpy.context.object.select_get() + bpy.context.object.select_set(action='SELECT') + bpy.context.object.select_set(action='DESELECT') -AddObjectHelper.layers + # no longer exists ```
2017-02-07 10:18:38 +01:00
if (STREQ(obname, basisname)) {
if (obnr < basisnr) {
object = ob;
Render Layers and Collections (merge from render-layers) Design Documents ---------------- * https://wiki.blender.org/index.php/Dev:2.8/Source/Layers * https://wiki.blender.org/index.php/Dev:2.8/Source/DataDesignRevised User Commit Log --------------- * New Layer and Collection system to replace render layers and viewport layers. * A layer is a set of collections of objects (and their drawing options) required for specific tasks. * A collection is a set of objects, equivalent of the old layers in Blender. A collection can be shared across multiple layers. * All Scenes have a master collection that all other collections are children of. * New collection "context" tab (in Properties Editor) * New temporary viewport "collections" panel to control per-collection visibility Missing User Features --------------------- * Collection "Filter" Option to add objects based on their names * Collection Manager operators The existing buttons are placeholders * Collection Manager drawing The editor main region is empty * Collection Override * Per-Collection engine settings This will come as a separate commit, as part of the clay-engine branch Dev Commit Log -------------- * New DNA file (DNA_layer_types.h) with the new structs We are replacing Base by a new extended Base while keeping it backward compatible with some legacy settings (i.e., lay, flag_legacy). Renamed all Base to BaseLegacy to make it clear the areas of code that still need to be converted Note: manual changes were required on - deg_builder_nodes.h, rna_object.c, KX_Light.cpp * Unittesting for main syncronization requirements - read, write, add/copy/remove objects, copy scene, collection link/unlinking, context) * New Editor: Collection Manager Based on patch by Julian Eisel This is extracted from the layer-manager branch. With the following changes: - Renamed references of layer manager to collections manager - I doesn't include the editors/space_collections/ draw and util files - The drawing code itself will be implemented separately by Julian * Base / Object: A little note about them. Original Blender code would try to keep them in sync through the code, juggling flags back and forth. This will now be handled by Depsgraph, keeping Object and Bases more separated throughout the non-rendering code. Scene.base is being cleared in doversion, and the old viewport drawing code was poorly converted to use the new bases while the new viewport code doesn't get merged and replace the old one. Python API Changes ------------------ ``` - scene.layers + # no longer exists - scene.objects + scene.scene_layers.active.objects - scene.objects.active + scene.render_layers.active.objects.active - bpy.context.scene.objects.link() + bpy.context.scene_collection.objects.link() - bpy_extras.object_utils.object_data_add(context, obdata, operator=None, use_active_layer=True, name=None) + bpy_extras.object_utils.object_data_add(context, obdata, operator=None, name=None) - bpy.context.object.select + bpy.context.object.select = True + bpy.context.object.select = False + bpy.context.object.select_get() + bpy.context.object.select_set(action='SELECT') + bpy.context.object.select_set(action='DESELECT') -AddObjectHelper.layers + # no longer exists ```
2017-02-07 10:18:38 +01:00
basisnr = obnr;
}
2012-09-16 04:58:18 +00:00
}
}
}
2002-10-12 11:37:38 +00:00
}
}
return object;
2002-10-12 11:37:38 +00:00
}
2018-11-08 08:02:02 +11:00
bool BKE_mball_minmax_ex(
const MetaBall *mb, float min[3], float max[3], const float obmat[4][4], const short flag)
{
const float scale = obmat ? mat4_to_scale(obmat) : 1.0f;
bool changed = false;
float centroid[3], vec[3];
INIT_MINMAX(min, max);
LISTBASE_FOREACH (const MetaElem *, ml, &mb->elems) {
if ((ml->flag & flag) == flag) {
const float scale_mb = (ml->rad * 0.5f) * scale;
if (obmat) {
mul_v3_m4v3(centroid, obmat, &ml->x);
}
else {
copy_v3_v3(centroid, &ml->x);
}
/* TODO(@ideasman42): non circle shapes cubes etc, probably nobody notices. */
2020-09-09 16:35:20 +02:00
for (int i = -1; i != 3; i += 2) {
copy_v3_v3(vec, centroid);
add_v3_fl(vec, scale_mb * i);
minmax_v3v3_v3(min, max, vec);
}
changed = true;
}
}
return changed;
}
2018-11-08 08:02:02 +11:00
bool BKE_mball_minmax(const MetaBall *mb, float min[3], float max[3])
{
INIT_MINMAX(min, max);
LISTBASE_FOREACH (const MetaElem *, ml, &mb->elems) {
minmax_v3v3_v3(min, max, &ml->x);
}
return (BLI_listbase_is_empty(&mb->elems) == false);
}
2018-11-08 08:02:02 +11:00
bool BKE_mball_center_median(const MetaBall *mb, float r_cent[3])
{
int total = 0;
zero_v3(r_cent);
LISTBASE_FOREACH (const MetaElem *, ml, &mb->elems) {
add_v3_v3(r_cent, &ml->x);
total++;
}
if (total) {
mul_v3_fl(r_cent, 1.0f / float(total));
}
return (total != 0);
}
2018-11-08 08:02:02 +11:00
bool BKE_mball_center_bounds(const MetaBall *mb, float r_cent[3])
{
float min[3], max[3];
if (BKE_mball_minmax(mb, min, max)) {
mid_v3_v3v3(r_cent, min, max);
2014-12-01 17:11:18 +01:00
return true;
}
2014-12-01 17:11:18 +01:00
return false;
}
void BKE_mball_transform(MetaBall *mb, const float mat[4][4], const bool do_props)
{
float quat[4];
const float scale = mat4_to_scale(mat);
const float scale_sqrt = sqrtf(scale);
mat4_to_quat(quat, mat);
LISTBASE_FOREACH (MetaElem *, ml, &mb->elems) {
2018-11-08 08:02:02 +11:00
mul_m4_v3(mat, &ml->x);
mul_qt_qtqt(ml->quat, quat, ml->quat);
if (do_props) {
2018-11-08 08:02:02 +11:00
ml->rad *= scale;
/* hrmf, probably elems shouldn't be
* treating scale differently - campbell */
2018-11-08 08:02:02 +11:00
if (!MB_TYPE_SIZE_SQUARED(ml->type)) {
mul_v3_fl(&ml->expx, scale);
}
else {
2018-11-08 08:02:02 +11:00
mul_v3_fl(&ml->expx, scale_sqrt);
}
}
}
}
void BKE_mball_translate(MetaBall *mb, const float offset[3])
{
LISTBASE_FOREACH (MetaElem *, ml, &mb->elems) {
add_v3_v3(&ml->x, offset);
}
}
2018-11-08 08:02:02 +11:00
int BKE_mball_select_count(const MetaBall *mb)
{
int sel = 0;
LISTBASE_FOREACH (const MetaElem *, ml, mb->editelems) {
if (ml->flag & SELECT) {
sel++;
}
}
return sel;
}
int BKE_mball_select_count_multi(const Span<Base *> bases)
2018-11-08 08:02:02 +11:00
{
int sel = 0;
for (Base *base : bases) {
Object *obedit = base->object;
2018-11-08 08:02:02 +11:00
const MetaBall *mb = (MetaBall *)obedit->data;
sel += BKE_mball_select_count(mb);
}
return sel;
}
bool BKE_mball_select_all(MetaBall *mb)
{
bool changed = false;
LISTBASE_FOREACH (MetaElem *, ml, mb->editelems) {
if ((ml->flag & SELECT) == 0) {
ml->flag |= SELECT;
changed = true;
}
}
return changed;
}
bool BKE_mball_select_all_multi_ex(const Span<Base *> bases)
{
bool changed_multi = false;
for (Base *base : bases) {
Object *obedit = base->object;
MetaBall *mb = static_cast<MetaBall *>(obedit->data);
changed_multi |= BKE_mball_select_all(mb);
}
return changed_multi;
}
bool BKE_mball_deselect_all(MetaBall *mb)
{
bool changed = false;
LISTBASE_FOREACH (MetaElem *, ml, mb->editelems) {
if ((ml->flag & SELECT) != 0) {
ml->flag &= ~SELECT;
changed = true;
}
}
return changed;
}
bool BKE_mball_deselect_all_multi_ex(const Span<Base *> bases)
{
bool changed_multi = false;
for (Base *base : bases) {
Object *obedit = base->object;
MetaBall *mb = static_cast<MetaBall *>(obedit->data);
changed_multi |= BKE_mball_deselect_all(mb);
DEG_id_tag_update(&mb->id, ID_RECALC_SELECT);
}
return changed_multi;
}
bool BKE_mball_select_swap(MetaBall *mb)
{
bool changed = false;
LISTBASE_FOREACH (MetaElem *, ml, mb->editelems) {
ml->flag ^= SELECT;
changed = true;
}
return changed;
}
bool BKE_mball_select_swap_multi_ex(const Span<Base *> bases)
{
bool changed_multi = false;
for (Base *base : bases) {
Object *obedit = base->object;
MetaBall *mb = (MetaBall *)obedit->data;
changed_multi |= BKE_mball_select_swap(mb);
}
return changed_multi;
}
/* **** Depsgraph evaluation **** */
void BKE_mball_data_update(Depsgraph *depsgraph, Scene *scene, Object *ob)
{
using namespace blender;
using namespace blender::bke;
BLI_assert(ob->type == OB_MBALL);
BKE_object_free_derived_caches(ob);
const Object *basis_object = BKE_mball_basis_find(scene, ob);
if (ob != basis_object) {
return;
}
Mesh *mesh = BKE_mball_polygonize(depsgraph, scene, ob);
if (mesh == nullptr) {
return;
}
const MetaBall *mball = static_cast<MetaBall *>(ob->data);
mesh->mat = static_cast<Material **>(MEM_dupallocN(mball->mat));
mesh->totcol = mball->totcol;
if (ob->parent && ob->parent->type == OB_LATTICE && ob->partype == PARSKEL) {
BKE_lattice_deform_coords(
ob->parent,
ob,
reinterpret_cast<float(*)[3]>(mesh->vert_positions_for_write().data()),
mesh->verts_num,
0,
nullptr,
1.0f);
mesh->tag_positions_changed();
}
ob->runtime->geometry_set_eval = new GeometrySet(GeometrySet::from_mesh(mesh));
};