2023-05-31 16:19:06 +02:00
|
|
|
/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup bke
|
2011-02-27 20:40:57 +00:00
|
|
|
*/
|
|
|
|
|
|
2022-12-29 12:01:32 -05:00
|
|
|
#include <cmath>
|
|
|
|
|
#include <cstddef>
|
|
|
|
|
#include <cstring>
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
2009-11-01 00:06:53 +00:00
|
|
|
#include "BLI_blenlib.h"
|
2020-09-10 18:00:44 +02:00
|
|
|
#include "BLI_endian_switch.h"
|
Cleanup: reduce amount of math-related includes
Using ClangBuildAnalyzer on the whole Blender build, it was pointing
out that BLI_math.h is the heaviest "header hub" (i.e. non tiny file
that is included a lot).
However, there's very little (actually zero) source files in Blender
that need "all the math" (base, colors, vectors, matrices,
quaternions, intersection, interpolation, statistics, solvers and
time). A common use case is source files needing just vectors, or
just vectors & matrices, or just colors etc. Actually, 181 files
were including the whole math thing without needing it at all.
This change removes BLI_math.h completely, and instead in all the
places that need it, includes BLI_math_vector.h or BLI_math_color.h
and so on.
Change from that:
- BLI_math_color.h was included 1399 times -> now 408 (took 114.0sec
to parse -> now 36.3sec)
- BLI_simd.h 1403 -> 418 (109.7sec -> 34.9sec).
Full rebuild of Blender (Apple M1, Xcode, RelWithDebInfo) is not
affected much (342sec -> 334sec). Most of benefit would be when
someone's changing BLI_simd.h or BLI_math_color.h or similar files,
that now there's 3x fewer files result in a recompile.
Pull Request #110944
2023-08-09 11:39:20 +03:00
|
|
|
#include "BLI_math_matrix.h"
|
2010-06-21 20:10:59 +00:00
|
|
|
#include "BLI_math_vector.h"
|
2023-10-18 17:15:30 +02:00
|
|
|
#include "BLI_string_utils.hh"
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BLI_utildefines.h"
|
2009-11-01 00:06:53 +00:00
|
|
|
|
2015-08-16 17:32:01 +10:00
|
|
|
#include "BLT_translation.h"
|
2013-03-25 08:29:06 +00:00
|
|
|
|
2020-09-10 18:00:44 +02:00
|
|
|
/* Allow using deprecated functionality for .blend file I/O. */
|
|
|
|
|
#define DNA_DEPRECATED_ALLOW
|
|
|
|
|
|
2020-03-06 12:16:56 +01:00
|
|
|
#include "DNA_ID.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "DNA_anim_types.h"
|
2005-09-26 15:34:21 +00:00
|
|
|
#include "DNA_key_types.h"
|
|
|
|
|
#include "DNA_lattice_types.h"
|
2012-02-19 22:17:30 +00:00
|
|
|
#include "DNA_mesh_types.h"
|
2004-03-20 22:55:42 +00:00
|
|
|
#include "DNA_meshdata_types.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "DNA_object_types.h"
|
Giant commit!
A full detailed description of this will be done later... is several days
of work. Here's a summary:
Render:
- Full cleanup of render code, removing *all* globals and bad level calls
all over blender. Render module is now not called abusive anymore
- API-fied calls to rendering
- Full recode of internal render pipeline. Is now rendering tiles by
default, prepared for much smarter 'bucket' render later.
- Each thread now can render a full part
- Renders were tested with 4 threads, goes fine, apart from some lookup
tables in softshadow and AO still
- Rendering is prepared to do multiple layers and passes
- No single 32 bits trick in render code anymore, all 100% floats now.
Writing images/movies
- moved writing images to blender kernel (bye bye 'schrijfplaatje'!)
- made a new Movie handle system, also in kernel. This will enable much
easier use of movies in Blender
PreviewRender:
- Using new render API, previewrender (in buttons) now uses regular render
code to generate images.
- new datafile 'preview.blend.c' has the preview scenes in it
- previews get rendered in exact displayed size (1 pixel = 1 pixel)
3D Preview render
- new; press Pkey in 3d window, for a panel that continuously renders
(pkey is for games, i know... but we dont do that in orange now!)
- this render works nearly identical to buttons-preview render, so it stops
rendering on any event (mouse, keyboard, etc)
- on moving/scaling the panel, the render code doesn't recreate all geometry
- same for shifting/panning view
- all other operations (now) regenerate the full render database still.
- this is WIP... but big fun, especially for simple scenes!
Compositor
- Using same node system as now in use for shaders, you can composit images
- works pretty straightforward... needs much more options/tools and integration
with rendering still
- is not threaded yet, nor is so smart to only recalculate changes... will be
done soon!
- the "Render Result" node will get all layers/passes as output sockets
- The "Output" node renders to a builtin image, which you can view in the Image
window. (yes, output nodes to render-result, and to files, is on the list!)
The Bad News
- "Unified Render" is removed. It might come back in some stage, but this
system should be built from scratch. I can't really understand this code...
I expect it is not much needed, especially with advanced layer/passes
control
- Panorama render, Field render, Motion blur, is not coded yet... (I had to
recode every single feature in render, so...!)
- Lens Flare is also not back... needs total revision, might become composit
effect though (using zbuffer for visibility)
- Part render is gone! (well, thats obvious, its default now).
- The render window is only restored with limited functionality... I am going
to check first the option to render to a Image window, so Blender can become
a true single-window application. :)
For example, the 'Spare render buffer' (jkey) doesnt work.
- Render with border, now default creates a smaller image
- No zbuffers are written yet... on the todo!
- Scons files and MSVC will need work to get compiling again
OK... thats what I can quickly recall. Now go compiling!
2006-01-23 22:05:47 +00:00
|
|
|
#include "DNA_scene_types.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2020-09-10 18:00:44 +02:00
|
|
|
#include "BKE_anim_data.h"
|
2023-11-16 11:41:55 +01:00
|
|
|
#include "BKE_curve.hh"
|
|
|
|
|
#include "BKE_customdata.hh"
|
2010-08-22 14:15:28 +00:00
|
|
|
#include "BKE_deform.h"
|
2023-11-16 11:41:55 +01:00
|
|
|
#include "BKE_editmesh.hh"
|
2020-03-06 12:16:56 +01:00
|
|
|
#include "BKE_idtype.h"
|
2005-09-26 15:34:21 +00:00
|
|
|
#include "BKE_key.h"
|
2023-11-16 11:41:55 +01:00
|
|
|
#include "BKE_lattice.hh"
|
2020-02-10 12:58:59 +01:00
|
|
|
#include "BKE_lib_id.h"
|
2020-05-13 19:08:54 +02:00
|
|
|
#include "BKE_lib_query.h"
|
2023-12-01 19:43:16 +01:00
|
|
|
#include "BKE_main.hh"
|
2023-03-12 22:29:15 +01:00
|
|
|
#include "BKE_mesh.hh"
|
2011-11-06 06:08:18 +00:00
|
|
|
#include "BKE_scene.h"
|
2011-01-07 19:18:31 +00:00
|
|
|
|
2023-08-10 22:40:27 +02:00
|
|
|
#include "RNA_access.hh"
|
|
|
|
|
#include "RNA_path.hh"
|
2022-03-14 16:54:46 +01:00
|
|
|
#include "RNA_prototypes.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2023-08-28 15:01:05 +02:00
|
|
|
#include "BLO_read_write.hh"
|
2020-09-10 18:00:44 +02:00
|
|
|
|
2022-12-20 15:51:47 -03:00
|
|
|
static void shapekey_copy_data(Main * /*bmain*/, ID *id_dst, const ID *id_src, const int /*flag*/)
|
2020-03-06 12:16:56 +01:00
|
|
|
{
|
|
|
|
|
Key *key_dst = (Key *)id_dst;
|
|
|
|
|
const Key *key_src = (const Key *)id_src;
|
|
|
|
|
BLI_duplicatelist(&key_dst->block, &key_src->block);
|
|
|
|
|
|
|
|
|
|
KeyBlock *kb_dst, *kb_src;
|
2022-12-02 12:34:26 +01:00
|
|
|
for (kb_src = static_cast<KeyBlock *>(key_src->block.first),
|
|
|
|
|
kb_dst = static_cast<KeyBlock *>(key_dst->block.first);
|
|
|
|
|
kb_dst;
|
2020-03-06 12:16:56 +01:00
|
|
|
kb_src = kb_src->next, kb_dst = kb_dst->next)
|
|
|
|
|
{
|
|
|
|
|
if (kb_dst->data) {
|
|
|
|
|
kb_dst->data = MEM_dupallocN(kb_dst->data);
|
|
|
|
|
}
|
|
|
|
|
if (kb_src == key_src->refkey) {
|
|
|
|
|
key_dst->refkey = kb_dst;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void shapekey_free_data(ID *id)
|
|
|
|
|
{
|
|
|
|
|
Key *key = (Key *)id;
|
2023-08-03 18:23:49 +10:00
|
|
|
while (KeyBlock *kb = static_cast<KeyBlock *>(BLI_pophead(&key->block))) {
|
2020-03-06 12:16:56 +01:00
|
|
|
if (kb->data) {
|
|
|
|
|
MEM_freeN(kb->data);
|
|
|
|
|
}
|
|
|
|
|
MEM_freeN(kb);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-13 19:08:54 +02:00
|
|
|
static void shapekey_foreach_id(ID *id, LibraryForeachIDData *data)
|
|
|
|
|
{
|
2023-08-22 15:42:19 +02:00
|
|
|
Key *key = reinterpret_cast<Key *>(id);
|
|
|
|
|
const int flag = BKE_lib_query_foreachid_process_flags_get(data);
|
|
|
|
|
|
2020-05-13 19:08:54 +02:00
|
|
|
BKE_LIB_FOREACHID_PROCESS_ID(data, key->from, IDWALK_CB_LOOPBACK);
|
2023-08-22 15:42:19 +02:00
|
|
|
|
|
|
|
|
if (flag & IDWALK_DO_DEPRECATED_POINTERS) {
|
|
|
|
|
BKE_LIB_FOREACHID_PROCESS_ID_NOCHECK(data, key->ipo, IDWALK_CB_USER);
|
|
|
|
|
}
|
2020-05-13 19:08:54 +02:00
|
|
|
}
|
|
|
|
|
|
2022-09-08 16:32:35 +02:00
|
|
|
static ID **shapekey_owner_pointer_get(ID *id)
|
2021-05-26 15:43:12 +02:00
|
|
|
{
|
2022-09-06 09:26:39 +02:00
|
|
|
Key *key = (Key *)id;
|
|
|
|
|
|
2022-12-02 12:34:26 +01:00
|
|
|
BLI_assert(key->from != nullptr);
|
2022-09-06 09:26:39 +02:00
|
|
|
BLI_assert(BKE_key_from_id(key->from) == key);
|
|
|
|
|
|
2022-09-08 16:32:35 +02:00
|
|
|
return &key->from;
|
2021-05-26 15:43:12 +02:00
|
|
|
}
|
|
|
|
|
|
2020-09-10 18:00:44 +02:00
|
|
|
static void shapekey_blend_write(BlendWriter *writer, ID *id, const void *id_address)
|
|
|
|
|
{
|
|
|
|
|
Key *key = (Key *)id;
|
2020-12-14 11:28:08 +01:00
|
|
|
const bool is_undo = BLO_write_is_undo(writer);
|
2020-09-10 18:00:44 +02:00
|
|
|
|
2021-08-19 11:13:55 +02:00
|
|
|
/* write LibData */
|
|
|
|
|
BLO_write_id_struct(writer, Key, id_address, &key->id);
|
|
|
|
|
BKE_id_blend_write(writer, &key->id);
|
|
|
|
|
|
|
|
|
|
/* direct data */
|
|
|
|
|
LISTBASE_FOREACH (KeyBlock *, kb, &key->block) {
|
|
|
|
|
KeyBlock tmp_kb = *kb;
|
|
|
|
|
/* Do not store actual geometry data in case this is a library override ID. */
|
|
|
|
|
if (ID_IS_OVERRIDE_LIBRARY(key) && !is_undo) {
|
|
|
|
|
tmp_kb.totelem = 0;
|
2022-12-02 12:34:26 +01:00
|
|
|
tmp_kb.data = nullptr;
|
2021-08-19 11:13:55 +02:00
|
|
|
}
|
|
|
|
|
BLO_write_struct_at_address(writer, KeyBlock, kb, &tmp_kb);
|
2022-12-02 12:34:26 +01:00
|
|
|
if (tmp_kb.data != nullptr) {
|
2021-08-19 11:13:55 +02:00
|
|
|
BLO_write_raw(writer, tmp_kb.totelem * key->elemsize, tmp_kb.data);
|
2020-09-10 18:00:44 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* old defines from DNA_ipo_types.h for data-type, stored in DNA - don't modify! */
|
|
|
|
|
#define IPO_FLOAT 4
|
|
|
|
|
#define IPO_BEZTRIPLE 100
|
|
|
|
|
#define IPO_BPOINT 101
|
|
|
|
|
|
|
|
|
|
static void switch_endian_keyblock(Key *key, KeyBlock *kb)
|
|
|
|
|
{
|
|
|
|
|
int elemsize = key->elemsize;
|
2022-12-02 12:34:26 +01:00
|
|
|
char *data = static_cast<char *>(kb->data);
|
2020-09-10 18:00:44 +02:00
|
|
|
|
|
|
|
|
for (int a = 0; a < kb->totelem; a++) {
|
|
|
|
|
const char *cp = key->elemstr;
|
|
|
|
|
char *poin = data;
|
|
|
|
|
|
|
|
|
|
while (cp[0]) { /* cp[0] == amount */
|
|
|
|
|
switch (cp[1]) { /* cp[1] = type */
|
|
|
|
|
case IPO_FLOAT:
|
|
|
|
|
case IPO_BPOINT:
|
|
|
|
|
case IPO_BEZTRIPLE: {
|
|
|
|
|
int b = cp[0];
|
|
|
|
|
BLI_endian_switch_float_array((float *)poin, b);
|
|
|
|
|
poin += sizeof(float) * b;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cp += 2;
|
|
|
|
|
}
|
|
|
|
|
data += elemsize;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void shapekey_blend_read_data(BlendDataReader *reader, ID *id)
|
|
|
|
|
{
|
|
|
|
|
Key *key = (Key *)id;
|
|
|
|
|
BLO_read_list(reader, &(key->block));
|
|
|
|
|
|
|
|
|
|
BLO_read_data_address(reader, &key->refkey);
|
|
|
|
|
|
|
|
|
|
LISTBASE_FOREACH (KeyBlock *, kb, &key->block) {
|
|
|
|
|
BLO_read_data_address(reader, &kb->data);
|
|
|
|
|
|
|
|
|
|
if (BLO_read_requires_endian_switch(reader)) {
|
|
|
|
|
switch_endian_keyblock(key, kb);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-11 18:07:59 +01:00
|
|
|
static void shapekey_blend_read_after_liblink(BlendLibReader * /*reader*/, ID *id)
|
2020-09-10 18:00:44 +02:00
|
|
|
{
|
2023-03-11 18:07:59 +01:00
|
|
|
/* ShapeKeys should always only be linked indirectly through their user ID (mesh, Curve etc.), or
|
|
|
|
|
* be fully local data. */
|
|
|
|
|
BLI_assert((id->tag & LIB_TAG_EXTERN) == 0);
|
2023-08-25 12:23:55 +02:00
|
|
|
UNUSED_VARS_NDEBUG(id);
|
2020-09-10 18:00:44 +02:00
|
|
|
}
|
|
|
|
|
|
2020-03-06 12:16:56 +01:00
|
|
|
IDTypeInfo IDType_ID_KE = {
|
2023-01-16 12:41:11 +11:00
|
|
|
/*id_code*/ ID_KE,
|
|
|
|
|
/*id_filter*/ FILTER_ID_KE,
|
|
|
|
|
/*main_listbase_index*/ INDEX_ID_KE,
|
|
|
|
|
/*struct_size*/ sizeof(Key),
|
|
|
|
|
/*name*/ "Key",
|
2023-10-22 08:47:26 +02:00
|
|
|
/*name_plural*/ N_("shape_keys"),
|
2023-01-16 12:41:11 +11:00
|
|
|
/*translation_context*/ BLT_I18NCONTEXT_ID_SHAPEKEY,
|
|
|
|
|
/*flags*/ IDTYPE_FLAGS_NO_LIBLINKING,
|
|
|
|
|
/*asset_type_info*/ nullptr,
|
|
|
|
|
|
|
|
|
|
/*init_data*/ nullptr,
|
|
|
|
|
/*copy_data*/ shapekey_copy_data,
|
|
|
|
|
/*free_data*/ shapekey_free_data,
|
|
|
|
|
/*make_local*/ nullptr,
|
|
|
|
|
/*foreach_id*/ shapekey_foreach_id,
|
|
|
|
|
/*foreach_cache*/ nullptr,
|
|
|
|
|
/*foreach_path*/ nullptr,
|
2022-03-10 11:32:48 +11:00
|
|
|
/* A bit weird, due to shape-keys not being strictly speaking embedded data... But they also
|
2021-05-26 15:43:12 +02:00
|
|
|
* share a lot with those (non linkable, only ever used by one owner ID, etc.). */
|
2023-01-16 12:41:11 +11:00
|
|
|
/*owner_pointer_get*/ shapekey_owner_pointer_get,
|
2020-08-28 13:05:48 +02:00
|
|
|
|
2023-01-16 12:41:11 +11:00
|
|
|
/*blend_write*/ shapekey_blend_write,
|
|
|
|
|
/*blend_read_data*/ shapekey_blend_read_data,
|
2023-03-11 18:07:59 +01:00
|
|
|
/*blend_read_after_liblink*/ shapekey_blend_read_after_liblink,
|
2020-11-03 11:39:36 +01:00
|
|
|
|
2023-01-16 12:41:11 +11:00
|
|
|
/*blend_read_undo_preserve*/ nullptr,
|
2021-01-22 14:52:50 +01:00
|
|
|
|
2023-01-16 12:41:11 +11:00
|
|
|
/*lib_override_apply_post*/ nullptr,
|
2020-03-06 12:16:56 +01:00
|
|
|
};
|
|
|
|
|
|
2012-04-14 02:32:32 +00:00
|
|
|
#define KEY_MODE_DUMMY 0 /* use where mode isn't checked for */
|
|
|
|
|
#define KEY_MODE_BPOINT 1
|
|
|
|
|
#define KEY_MODE_BEZTRIPLE 2
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2018-09-12 17:27:22 +10:00
|
|
|
/* Internal use only. */
|
2022-12-29 12:01:32 -05:00
|
|
|
struct WeightsArrayCache {
|
2018-09-12 17:27:22 +10:00
|
|
|
int num_defgroup_weights;
|
|
|
|
|
float **defgroup_weights;
|
2022-12-29 12:01:32 -05:00
|
|
|
};
|
2018-09-12 17:27:22 +10:00
|
|
|
|
2021-08-20 16:35:35 +10:00
|
|
|
void BKE_key_free_data(Key *key)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2020-03-06 12:16:56 +01:00
|
|
|
shapekey_free_data(&key->id);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
2012-09-19 10:12:07 +00:00
|
|
|
void BKE_key_free_nolib(Key *key)
|
2009-11-02 14:45:12 +00:00
|
|
|
{
|
2023-08-03 18:23:49 +10:00
|
|
|
while (KeyBlock *kb = static_cast<KeyBlock *>(BLI_pophead(&key->block))) {
|
2019-04-22 09:39:35 +10:00
|
|
|
if (kb->data) {
|
2013-08-26 23:37:08 +00:00
|
|
|
MEM_freeN(kb->data);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2009-11-02 14:45:12 +00:00
|
|
|
MEM_freeN(kb);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-12 12:53:27 +02:00
|
|
|
Key *BKE_key_add(Main *bmain, ID *id) /* common function */
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
|
Key *key;
|
|
|
|
|
char *el;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2022-12-02 12:34:26 +01:00
|
|
|
key = static_cast<Key *>(BKE_id_new(bmain, ID_KE, "Key"));
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2012-04-14 02:32:32 +00:00
|
|
|
key->type = KEY_NORMAL;
|
|
|
|
|
key->from = id;
|
2009-11-02 06:31:23 +00:00
|
|
|
|
|
|
|
|
key->uidgen = 1;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2012-09-26 20:05:38 +00:00
|
|
|
/* XXX the code here uses some defines which will soon be deprecated... */
|
2012-04-14 02:32:32 +00:00
|
|
|
switch (GS(id->name)) {
|
|
|
|
|
case ID_ME:
|
|
|
|
|
el = key->elemstr;
|
|
|
|
|
|
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
2018-09-05 16:17:59 +03:00
|
|
|
el[0] = KEYELEM_FLOAT_LEN_COORD;
|
2012-04-14 02:32:32 +00:00
|
|
|
el[1] = IPO_FLOAT;
|
|
|
|
|
el[2] = 0;
|
|
|
|
|
|
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
2018-09-05 16:17:59 +03:00
|
|
|
key->elemsize = sizeof(float[KEYELEM_FLOAT_LEN_COORD]);
|
2012-04-14 02:32:32 +00:00
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case ID_LT:
|
|
|
|
|
el = key->elemstr;
|
|
|
|
|
|
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
2018-09-05 16:17:59 +03:00
|
|
|
el[0] = KEYELEM_FLOAT_LEN_COORD;
|
2012-04-14 02:32:32 +00:00
|
|
|
el[1] = IPO_FLOAT;
|
|
|
|
|
el[2] = 0;
|
|
|
|
|
|
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
2018-09-05 16:17:59 +03:00
|
|
|
key->elemsize = sizeof(float[KEYELEM_FLOAT_LEN_COORD]);
|
2012-04-14 02:32:32 +00:00
|
|
|
|
|
|
|
|
break;
|
2022-02-18 09:50:29 -06:00
|
|
|
case ID_CU_LEGACY:
|
2012-04-14 02:32:32 +00:00
|
|
|
el = key->elemstr;
|
|
|
|
|
|
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
2018-09-05 16:17:59 +03:00
|
|
|
el[0] = KEYELEM_ELEM_SIZE_CURVE;
|
2012-04-14 02:32:32 +00:00
|
|
|
el[1] = IPO_BPOINT;
|
|
|
|
|
el[2] = 0;
|
|
|
|
|
|
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
2018-09-05 16:17:59 +03:00
|
|
|
key->elemsize = sizeof(float[KEYELEM_ELEM_SIZE_CURVE]);
|
2012-04-14 02:32:32 +00:00
|
|
|
|
|
|
|
|
break;
|
2017-08-28 11:19:58 +02:00
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
return key;
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-19 10:12:07 +00:00
|
|
|
void BKE_key_sort(Key *key)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
|
KeyBlock *kb;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-06-17 17:05:51 +02:00
|
|
|
/* locate the key which is out of position */
|
2022-12-02 12:34:26 +01:00
|
|
|
for (kb = static_cast<KeyBlock *>(key->block.first); kb; kb = kb->next) {
|
2019-04-22 09:39:35 +10:00
|
|
|
if ((kb->next) && (kb->pos > kb->next->pos)) {
|
2006-11-19 06:07:24 +00:00
|
|
|
break;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2006-11-19 06:07:24 +00:00
|
|
|
/* if we find a key, move it */
|
2.5: Blender "Animato" - New Animation System
Finally, here is the basic (functional) prototype of the new animation system which will allow for the infamous "everything is animatable", and which also addresses several of the more serious shortcomings of the old system. Unfortunately, this will break old animation files (especially right now, as I haven't written the version patching code yet), however, this is for the future.
Highlights of the new system:
* Scrapped IPO-Curves/IPO/(Action+Constraint-Channels)/Action system, and replaced it with F-Curve/Action.
- F-Curves (animators from other packages will feel at home with this name) replace IPO-Curves.
- The 'new' Actions, act as the containers for F-Curves, so that they can be reused. They are therefore more akin to the old 'IPO' blocks, except they do not have the blocktype restriction, so you can store materials/texture/geometry F-Curves in the same Action as Object transforms, etc.
* F-Curves use RNA-paths for Data Access, hence allowing "every" (where sensible/editable that is) user-accessible setting from RNA to be animated.
* Drivers are no longer mixed with Animation Data, so rigs will not be that easily broken and several dependency problems can be eliminated. (NOTE: drivers haven't been hooked up yet, but the code is in place)
* F-Curve modifier system allows useful 'large-scale' manipulation of F-Curve values, including (I've only included implemented ones here): envelope deform (similar to lattices to allow broad-scale reshaping of curves), curve generator (polynomial or py-expression), cycles (replacing the old cyclic extrapolation modes, giving more control over this). (NOTE: currently this cannot be tested, as there's not access to them, but the code is all in place)
* NLA system with 'tracks' (i.e. layers), and multiple strips per track. (NOTE: NLA system is not yet functional, as it's only partially coded still)
There are more nice things that I will be preparing some nice docs for soon, but for now, check for more details:
http://lists.blender.org/pipermail/bf-taskforce25/2009-January/000260.html
So, what currently works:
* I've implemented two basic operators for the 3D-view only to Insert and Delete Keyframes. These are tempolary ones only that will be replaced in due course with 'proper' code.
* Object Loc/Rot/Scale can be keyframed. Also, the colour of the 'active' material (Note: this should really be for nth material instead, but that doesn't work yet in RNA) can also be keyframed into the same datablock.
* Standard animation refresh (i.e. animation resulting from NLA and Action evaluation) is now done completely separate from drivers before anything else is done after a frame change. Drivers are handled after this in a separate pass, as dictated by depsgraph flags, etc.
Notes:
* Drivers haven't been hooked up yet
* Only objects and data directly linked to objects can be animated.
* Depsgraph will need further tweaks. Currently, I've only made sure that it will update some things in the most basic cases (i.e. frame change).
* Animation Editors are currently broken (in terms of editing stuff). This will be my next target (priority to get Dopesheet working first, then F-Curve editor - i.e. old IPO Editor)
* I've had to put in large chunks of XXX sandboxing for old animation system code all around the place. This will be cleaned up in due course, as some places need special review.
In particular, the particles and sequencer code have far too many manual calls to calculate + flush animation info, which is really bad (this is a 'please explain yourselves' call to Physics coders!).
2009-01-17 03:12:50 +00:00
|
|
|
if (kb) {
|
2006-11-19 06:07:24 +00:00
|
|
|
kb = kb->next; /* next key is the out-of-order one */
|
|
|
|
|
BLI_remlink(&key->block, kb);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2006-11-19 06:07:24 +00:00
|
|
|
/* find the right location and insert before */
|
2023-08-04 08:51:13 +10:00
|
|
|
LISTBASE_FOREACH (KeyBlock *, kb2, &key->block) {
|
2.5: Blender "Animato" - New Animation System
Finally, here is the basic (functional) prototype of the new animation system which will allow for the infamous "everything is animatable", and which also addresses several of the more serious shortcomings of the old system. Unfortunately, this will break old animation files (especially right now, as I haven't written the version patching code yet), however, this is for the future.
Highlights of the new system:
* Scrapped IPO-Curves/IPO/(Action+Constraint-Channels)/Action system, and replaced it with F-Curve/Action.
- F-Curves (animators from other packages will feel at home with this name) replace IPO-Curves.
- The 'new' Actions, act as the containers for F-Curves, so that they can be reused. They are therefore more akin to the old 'IPO' blocks, except they do not have the blocktype restriction, so you can store materials/texture/geometry F-Curves in the same Action as Object transforms, etc.
* F-Curves use RNA-paths for Data Access, hence allowing "every" (where sensible/editable that is) user-accessible setting from RNA to be animated.
* Drivers are no longer mixed with Animation Data, so rigs will not be that easily broken and several dependency problems can be eliminated. (NOTE: drivers haven't been hooked up yet, but the code is in place)
* F-Curve modifier system allows useful 'large-scale' manipulation of F-Curve values, including (I've only included implemented ones here): envelope deform (similar to lattices to allow broad-scale reshaping of curves), curve generator (polynomial or py-expression), cycles (replacing the old cyclic extrapolation modes, giving more control over this). (NOTE: currently this cannot be tested, as there's not access to them, but the code is all in place)
* NLA system with 'tracks' (i.e. layers), and multiple strips per track. (NOTE: NLA system is not yet functional, as it's only partially coded still)
There are more nice things that I will be preparing some nice docs for soon, but for now, check for more details:
http://lists.blender.org/pipermail/bf-taskforce25/2009-January/000260.html
So, what currently works:
* I've implemented two basic operators for the 3D-view only to Insert and Delete Keyframes. These are tempolary ones only that will be replaced in due course with 'proper' code.
* Object Loc/Rot/Scale can be keyframed. Also, the colour of the 'active' material (Note: this should really be for nth material instead, but that doesn't work yet in RNA) can also be keyframed into the same datablock.
* Standard animation refresh (i.e. animation resulting from NLA and Action evaluation) is now done completely separate from drivers before anything else is done after a frame change. Drivers are handled after this in a separate pass, as dictated by depsgraph flags, etc.
Notes:
* Drivers haven't been hooked up yet
* Only objects and data directly linked to objects can be animated.
* Depsgraph will need further tweaks. Currently, I've only made sure that it will update some things in the most basic cases (i.e. frame change).
* Animation Editors are currently broken (in terms of editing stuff). This will be my next target (priority to get Dopesheet working first, then F-Curve editor - i.e. old IPO Editor)
* I've had to put in large chunks of XXX sandboxing for old animation system code all around the place. This will be cleaned up in due course, as some places need special review.
In particular, the particles and sequencer code have far too many manual calls to calculate + flush animation info, which is really bad (this is a 'please explain yourselves' call to Physics coders!).
2009-01-17 03:12:50 +00:00
|
|
|
if (kb2->pos > kb->pos) {
|
2013-02-22 14:12:55 +00:00
|
|
|
BLI_insertlinkafter(&key->block, kb2->prev, kb);
|
2006-11-19 06:07:24 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2006-04-17 17:35:20 +00:00
|
|
|
/* new rule; first key is refkey, this to match drawing channels... */
|
2022-12-02 12:34:26 +01:00
|
|
|
key->refkey = static_cast<KeyBlock *>(key->block.first);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**************** do the key ****************/
|
|
|
|
|
|
2012-05-22 13:59:58 +00:00
|
|
|
void key_curve_position_weights(float t, float data[4], int type)
|
2009-09-16 17:43:09 +00:00
|
|
|
{
|
|
|
|
|
float t2, t3, fc;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-14 02:32:32 +00:00
|
|
|
if (type == KEY_LINEAR) {
|
|
|
|
|
data[0] = 0.0f;
|
|
|
|
|
data[1] = -t + 1.0f;
|
|
|
|
|
data[2] = t;
|
|
|
|
|
data[3] = 0.0f;
|
|
|
|
|
}
|
|
|
|
|
else if (type == KEY_CARDINAL) {
|
|
|
|
|
t2 = t * t;
|
|
|
|
|
t3 = t2 * t;
|
|
|
|
|
fc = 0.71f;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-14 02:32:32 +00:00
|
|
|
data[0] = -fc * t3 + 2.0f * fc * t2 - fc * t;
|
|
|
|
|
data[1] = (2.0f - fc) * t3 + (fc - 3.0f) * t2 + 1.0f;
|
|
|
|
|
data[2] = (fc - 2.0f) * t3 + (3.0f - 2.0f * fc) * t2 + fc * t;
|
|
|
|
|
data[3] = fc * t3 - fc * t2;
|
|
|
|
|
}
|
|
|
|
|
else if (type == KEY_BSPLINE) {
|
|
|
|
|
t2 = t * t;
|
|
|
|
|
t3 = t2 * t;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-14 02:32:32 +00:00
|
|
|
data[0] = -0.16666666f * t3 + 0.5f * t2 - 0.5f * t + 0.16666666f;
|
|
|
|
|
data[1] = 0.5f * t3 - t2 + 0.66666666f;
|
|
|
|
|
data[2] = -0.5f * t3 + 0.5f * t2 + 0.5f * t + 0.16666666f;
|
|
|
|
|
data[3] = 0.16666666f * t3;
|
2009-09-16 17:43:09 +00:00
|
|
|
}
|
2013-06-25 10:49:20 +00:00
|
|
|
else if (type == KEY_CATMULL_ROM) {
|
|
|
|
|
t2 = t * t;
|
|
|
|
|
t3 = t2 * t;
|
|
|
|
|
fc = 0.5f;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-06-25 10:49:20 +00:00
|
|
|
data[0] = -fc * t3 + 2.0f * fc * t2 - fc * t;
|
|
|
|
|
data[1] = (2.0f - fc) * t3 + (fc - 3.0f) * t2 + 1.0f;
|
|
|
|
|
data[2] = (fc - 2.0f) * t3 + (3.0f - 2.0f * fc) * t2 + fc * t;
|
|
|
|
|
data[3] = fc * t3 - fc * t2;
|
|
|
|
|
}
|
2009-09-16 17:43:09 +00:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-22 13:59:58 +00:00
|
|
|
void key_curve_tangent_weights(float t, float data[4], int type)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2009-09-16 17:43:09 +00:00
|
|
|
float t2, fc;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-14 02:32:32 +00:00
|
|
|
if (type == KEY_LINEAR) {
|
|
|
|
|
data[0] = 0.0f;
|
|
|
|
|
data[1] = -1.0f;
|
|
|
|
|
data[2] = 1.0f;
|
|
|
|
|
data[3] = 0.0f;
|
|
|
|
|
}
|
|
|
|
|
else if (type == KEY_CARDINAL) {
|
|
|
|
|
t2 = t * t;
|
|
|
|
|
fc = 0.71f;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-14 02:32:32 +00:00
|
|
|
data[0] = -3.0f * fc * t2 + 4.0f * fc * t - fc;
|
|
|
|
|
data[1] = 3.0f * (2.0f - fc) * t2 + 2.0f * (fc - 3.0f) * t;
|
|
|
|
|
data[2] = 3.0f * (fc - 2.0f) * t2 + 2.0f * (3.0f - 2.0f * fc) * t + fc;
|
|
|
|
|
data[3] = 3.0f * fc * t2 - 2.0f * fc * t;
|
2009-09-16 17:43:09 +00:00
|
|
|
}
|
2012-04-14 02:32:32 +00:00
|
|
|
else if (type == KEY_BSPLINE) {
|
|
|
|
|
t2 = t * t;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-14 02:32:32 +00:00
|
|
|
data[0] = -0.5f * t2 + t - 0.5f;
|
2012-04-14 03:58:08 +00:00
|
|
|
data[1] = 1.5f * t2 - t * 2.0f;
|
2012-04-14 02:32:32 +00:00
|
|
|
data[2] = -1.5f * t2 + t + 0.5f;
|
|
|
|
|
data[3] = 0.5f * t2;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2013-06-25 10:49:20 +00:00
|
|
|
else if (type == KEY_CATMULL_ROM) {
|
|
|
|
|
t2 = t * t;
|
|
|
|
|
fc = 0.5f;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-06-25 10:49:20 +00:00
|
|
|
data[0] = -3.0f * fc * t2 + 4.0f * fc * t - fc;
|
|
|
|
|
data[1] = 3.0f * (2.0f - fc) * t2 + 2.0f * (fc - 3.0f) * t;
|
|
|
|
|
data[2] = 3.0f * (fc - 2.0f) * t2 + 2.0f * (3.0f - 2.0f * fc) * t + fc;
|
|
|
|
|
data[3] = 3.0f * fc * t2 - 2.0f * fc * t;
|
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
2012-05-22 13:59:58 +00:00
|
|
|
void key_curve_normal_weights(float t, float data[4], int type)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2009-09-16 17:43:09 +00:00
|
|
|
float fc;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-14 02:32:32 +00:00
|
|
|
if (type == KEY_LINEAR) {
|
|
|
|
|
data[0] = 0.0f;
|
|
|
|
|
data[1] = 0.0f;
|
|
|
|
|
data[2] = 0.0f;
|
|
|
|
|
data[3] = 0.0f;
|
|
|
|
|
}
|
|
|
|
|
else if (type == KEY_CARDINAL) {
|
|
|
|
|
fc = 0.71f;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-14 03:58:08 +00:00
|
|
|
data[0] = -6.0f * fc * t + 4.0f * fc;
|
2012-04-14 02:32:32 +00:00
|
|
|
data[1] = 6.0f * (2.0f - fc) * t + 2.0f * (fc - 3.0f);
|
|
|
|
|
data[2] = 6.0f * (fc - 2.0f) * t + 2.0f * (3.0f - 2.0f * fc);
|
2012-04-14 03:58:08 +00:00
|
|
|
data[3] = 6.0f * fc * t - 2.0f * fc;
|
2012-04-14 02:32:32 +00:00
|
|
|
}
|
|
|
|
|
else if (type == KEY_BSPLINE) {
|
|
|
|
|
data[0] = -1.0f * t + 1.0f;
|
|
|
|
|
data[1] = 3.0f * t - 2.0f;
|
|
|
|
|
data[2] = -3.0f * t + 1.0f;
|
|
|
|
|
data[3] = 1.0f * t;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2013-06-25 10:49:20 +00:00
|
|
|
else if (type == KEY_CATMULL_ROM) {
|
|
|
|
|
fc = 0.5f;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-06-25 10:49:20 +00:00
|
|
|
data[0] = -6.0f * fc * t + 4.0f * fc;
|
|
|
|
|
data[1] = 6.0f * (2.0f - fc) * t + 2.0f * (fc - 3.0f);
|
|
|
|
|
data[2] = 6.0f * (fc - 2.0f) * t + 2.0f * (3.0f - 2.0f * fc);
|
|
|
|
|
data[3] = 6.0f * fc * t - 2.0f * fc;
|
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
2012-05-22 13:59:58 +00:00
|
|
|
static int setkeys(float fac, ListBase *lb, KeyBlock *k[], float t[4], int cycl)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2003-04-26 11:56:44 +00:00
|
|
|
/* return 1 means k[2] is the position, return 0 means interpolate */
|
2002-10-12 11:37:38 +00:00
|
|
|
KeyBlock *k1, *firstkey;
|
2012-05-22 13:59:58 +00:00
|
|
|
float d, dpos, ofs = 0, lastpos;
|
2002-10-12 11:37:38 +00:00
|
|
|
short bsplinetype;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-12-02 12:34:26 +01:00
|
|
|
firstkey = static_cast<KeyBlock *>(lb->first);
|
|
|
|
|
k1 = static_cast<KeyBlock *>(lb->last);
|
2012-04-14 02:32:32 +00:00
|
|
|
lastpos = k1->pos;
|
|
|
|
|
dpos = lastpos - firstkey->pos;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (fac < firstkey->pos) {
|
2012-04-14 02:32:32 +00:00
|
|
|
fac = firstkey->pos;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
|
else if (fac > k1->pos) {
|
2012-04-14 02:32:32 +00:00
|
|
|
fac = k1->pos;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-14 02:32:32 +00:00
|
|
|
k1 = k[0] = k[1] = k[2] = k[3] = firstkey;
|
|
|
|
|
t[0] = t[1] = t[2] = t[3] = k1->pos;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-09-25 16:56:17 +10:00
|
|
|
#if 0
|
|
|
|
|
if (fac < 0.0 || fac > 1.0) {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-12-02 12:34:26 +01:00
|
|
|
if (k1->next == nullptr) {
|
2012-04-14 02:32:32 +00:00
|
|
|
return 1;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-14 02:32:32 +00:00
|
|
|
if (cycl) { /* pre-sort */
|
|
|
|
|
k[2] = k1->next;
|
|
|
|
|
k[3] = k[2]->next;
|
2022-12-02 12:34:26 +01:00
|
|
|
if (k[3] == nullptr) {
|
2012-04-14 02:32:32 +00:00
|
|
|
k[3] = k1;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
while (k1) {
|
2022-12-02 12:34:26 +01:00
|
|
|
if (k1->next == nullptr) {
|
2012-04-14 02:32:32 +00:00
|
|
|
k[0] = k1;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2012-04-14 02:32:32 +00:00
|
|
|
k1 = k1->next;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2023-09-25 16:56:17 +10:00
|
|
|
// k1 = k[1]; /* UNUSED */
|
2012-04-14 02:32:32 +00:00
|
|
|
t[0] = k[0]->pos;
|
|
|
|
|
t[1] += dpos;
|
|
|
|
|
t[2] = k[2]->pos + dpos;
|
|
|
|
|
t[3] = k[3]->pos + dpos;
|
|
|
|
|
fac += dpos;
|
|
|
|
|
ofs = dpos;
|
|
|
|
|
if (k[3] == k[1]) {
|
|
|
|
|
t[3] += dpos;
|
|
|
|
|
ofs = 2.0f * dpos;
|
|
|
|
|
}
|
2019-04-22 09:39:35 +10:00
|
|
|
if (fac < t[1]) {
|
2012-04-14 02:32:32 +00:00
|
|
|
fac += dpos;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2012-04-14 02:32:32 +00:00
|
|
|
k1 = k[3];
|
|
|
|
|
}
|
|
|
|
|
else { /* pre-sort */
|
|
|
|
|
k[2] = k1->next;
|
|
|
|
|
t[2] = k[2]->pos;
|
|
|
|
|
k[3] = k[2]->next;
|
2022-12-02 12:34:26 +01:00
|
|
|
if (k[3] == nullptr) {
|
2012-04-14 02:32:32 +00:00
|
|
|
k[3] = k[2];
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2012-04-14 02:32:32 +00:00
|
|
|
t[3] = k[3]->pos;
|
|
|
|
|
k1 = k[3];
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-14 02:32:32 +00:00
|
|
|
while (t[2] < fac) { /* find correct location */
|
2022-12-02 12:34:26 +01:00
|
|
|
if (k1->next == nullptr) {
|
2012-03-24 06:18:31 +00:00
|
|
|
if (cycl) {
|
2012-04-14 02:32:32 +00:00
|
|
|
k1 = firstkey;
|
|
|
|
|
ofs += dpos;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2013-03-09 03:46:30 +00:00
|
|
|
else if (t[2] == t[3]) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2013-03-09 03:46:30 +00:00
|
|
|
else {
|
|
|
|
|
k1 = k1->next;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-14 02:32:32 +00:00
|
|
|
t[0] = t[1];
|
|
|
|
|
k[0] = k[1];
|
|
|
|
|
t[1] = t[2];
|
|
|
|
|
k[1] = k[2];
|
|
|
|
|
t[2] = t[3];
|
|
|
|
|
k[2] = k[3];
|
|
|
|
|
t[3] = k1->pos + ofs;
|
|
|
|
|
k[3] = k1;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (ofs > 2.1f + lastpos) {
|
2012-03-24 06:18:31 +00:00
|
|
|
break;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-14 02:32:32 +00:00
|
|
|
bsplinetype = 0;
|
2019-04-22 09:39:35 +10:00
|
|
|
if (k[1]->type == KEY_BSPLINE || k[2]->type == KEY_BSPLINE) {
|
2012-04-14 02:32:32 +00:00
|
|
|
bsplinetype = 1;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-14 02:32:32 +00:00
|
|
|
if (cycl == 0) {
|
|
|
|
|
if (bsplinetype == 0) { /* B spline doesn't go through the control points */
|
|
|
|
|
if (fac <= t[1]) { /* fac for 1st key */
|
|
|
|
|
t[2] = t[1];
|
|
|
|
|
k[2] = k[1];
|
2002-10-12 11:37:38 +00:00
|
|
|
return 1;
|
|
|
|
|
}
|
2012-04-14 02:32:32 +00:00
|
|
|
if (fac >= t[2]) { /* fac after 2nd key */
|
2002-10-12 11:37:38 +00:00
|
|
|
return 1;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2012-04-14 02:32:32 +00:00
|
|
|
else if (fac > t[2]) { /* last key */
|
|
|
|
|
fac = t[2];
|
|
|
|
|
k[3] = k[2];
|
|
|
|
|
t[3] = t[2];
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
2012-04-14 02:32:32 +00:00
|
|
|
d = t[2] - t[1];
|
2012-03-24 06:18:31 +00:00
|
|
|
if (d == 0.0f) {
|
2012-04-14 02:32:32 +00:00
|
|
|
if (bsplinetype == 0) {
|
|
|
|
|
return 1; /* both keys equal */
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2012-04-14 02:32:32 +00:00
|
|
|
else {
|
|
|
|
|
d = (fac - t[1]) / d;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2003-04-26 11:56:44 +00:00
|
|
|
/* interpolation */
|
2009-09-16 17:43:09 +00:00
|
|
|
key_curve_position_weights(d, t, k[1]->type);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (k[1]->type != k[2]->type) {
|
2012-05-22 13:59:58 +00:00
|
|
|
float t_other[4];
|
|
|
|
|
key_curve_position_weights(d, t_other, k[2]->type);
|
|
|
|
|
interp_v4_v4v4(t, t, t_other, d);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-13 11:27:09 +02:00
|
|
|
static void flerp(int tot,
|
|
|
|
|
float *in,
|
|
|
|
|
const float *f0,
|
|
|
|
|
const float *f1,
|
|
|
|
|
const float *f2,
|
|
|
|
|
const float *f3,
|
|
|
|
|
const float *t)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
|
int a;
|
|
|
|
|
|
2012-04-14 02:32:32 +00:00
|
|
|
for (a = 0; a < tot; a++) {
|
|
|
|
|
in[a] = t[0] * f0[a] + t[1] * f1[a] + t[2] * f2[a] + t[3] * f3[a];
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-13 11:27:09 +02:00
|
|
|
static void rel_flerp(int tot, float *in, const float *ref, const float *out, float fac)
|
2005-10-04 15:00:28 +00:00
|
|
|
{
|
|
|
|
|
int a;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2012-04-14 02:32:32 +00:00
|
|
|
for (a = 0; a < tot; a++) {
|
|
|
|
|
in[a] -= fac * (ref[a] - out[a]);
|
2005-10-04 15:00:28 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-01 00:06:53 +00:00
|
|
|
static char *key_block_get_data(Key *key, KeyBlock *actkb, KeyBlock *kb, char **freedata)
|
|
|
|
|
{
|
2012-03-24 06:18:31 +00:00
|
|
|
if (kb == actkb) {
|
2009-11-01 00:06:53 +00:00
|
|
|
/* this hack makes it possible to edit shape keys in
|
2012-03-03 20:19:11 +00:00
|
|
|
* edit mode with shape keys blending applied */
|
2012-03-24 06:18:31 +00:00
|
|
|
if (GS(key->from->name) == ID_ME) {
|
2009-11-01 00:06:53 +00:00
|
|
|
Mesh *me;
|
|
|
|
|
BMVert *eve;
|
|
|
|
|
BMIter iter;
|
|
|
|
|
float(*co)[3];
|
|
|
|
|
int a;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-14 02:32:32 +00:00
|
|
|
me = (Mesh *)key->from;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-02-17 18:05:18 +11:00
|
|
|
if (me->edit_mesh && me->edit_mesh->bm->totvert == kb->totelem) {
|
2012-04-14 02:32:32 +00:00
|
|
|
a = 0;
|
2022-12-02 12:34:26 +01:00
|
|
|
co = static_cast<float(*)[3]>(
|
|
|
|
|
MEM_mallocN(sizeof(float[3]) * me->edit_mesh->bm->totvert, "key_block_get_data"));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-02-17 18:05:18 +11:00
|
|
|
BM_ITER_MESH (eve, &iter, me->edit_mesh->bm, BM_VERTS_OF_MESH) {
|
2011-10-28 12:40:15 +00:00
|
|
|
copy_v3_v3(co[a], eve->co);
|
2009-11-01 00:06:53 +00:00
|
|
|
a++;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-14 02:32:32 +00:00
|
|
|
*freedata = (char *)co;
|
|
|
|
|
return (char *)co;
|
2009-11-01 00:06:53 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-12-02 12:34:26 +01:00
|
|
|
*freedata = nullptr;
|
|
|
|
|
return static_cast<char *>(kb->data);
|
2009-11-01 00:06:53 +00:00
|
|
|
}
|
|
|
|
|
|
2023-11-30 10:42:18 +11:00
|
|
|
/* currently only the first value of 'r_ofs' may be set. */
|
|
|
|
|
static bool key_pointer_size(
|
|
|
|
|
const Key *key, const int mode, int *r_poinsize, int *r_ofs, int *r_step)
|
2011-01-03 04:59:57 +00:00
|
|
|
{
|
2022-12-02 12:34:26 +01:00
|
|
|
if (key->from == nullptr) {
|
2014-04-01 11:34:00 +11:00
|
|
|
return false;
|
2011-01-03 04:59:57 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-11-30 10:42:18 +11:00
|
|
|
*r_step = 1;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-14 02:32:32 +00:00
|
|
|
switch (GS(key->from->name)) {
|
|
|
|
|
case ID_ME:
|
2023-11-30 10:42:18 +11:00
|
|
|
*r_ofs = sizeof(float[KEYELEM_FLOAT_LEN_COORD]);
|
|
|
|
|
*r_poinsize = *r_ofs;
|
2012-04-14 02:32:32 +00:00
|
|
|
break;
|
|
|
|
|
case ID_LT:
|
2023-11-30 10:42:18 +11:00
|
|
|
*r_ofs = sizeof(float[KEYELEM_FLOAT_LEN_COORD]);
|
|
|
|
|
*r_poinsize = *r_ofs;
|
2012-04-14 02:32:32 +00:00
|
|
|
break;
|
2022-02-18 09:50:29 -06:00
|
|
|
case ID_CU_LEGACY:
|
2012-04-14 02:32:32 +00:00
|
|
|
if (mode == KEY_MODE_BPOINT) {
|
2023-11-30 10:42:18 +11:00
|
|
|
*r_ofs = sizeof(float[KEYELEM_FLOAT_LEN_BPOINT]);
|
|
|
|
|
*r_step = KEYELEM_ELEM_LEN_BPOINT;
|
2012-04-14 02:32:32 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2023-11-30 10:42:18 +11:00
|
|
|
*r_ofs = sizeof(float[KEYELEM_FLOAT_LEN_BEZTRIPLE]);
|
|
|
|
|
*r_step = KEYELEM_ELEM_LEN_BEZTRIPLE;
|
2012-04-14 02:32:32 +00:00
|
|
|
}
|
2023-11-30 10:42:18 +11:00
|
|
|
*r_poinsize = sizeof(float[KEYELEM_ELEM_SIZE_CURVE]);
|
2012-04-14 02:32:32 +00:00
|
|
|
break;
|
|
|
|
|
default:
|
2021-07-15 18:23:28 +10:00
|
|
|
BLI_assert_msg(0, "invalid 'key->from' ID type");
|
2014-04-01 11:34:00 +11:00
|
|
|
return false;
|
2011-01-03 04:59:57 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-04-01 11:34:00 +11:00
|
|
|
return true;
|
2011-01-03 04:59:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void cp_key(const int start,
|
|
|
|
|
int end,
|
|
|
|
|
const int tot,
|
|
|
|
|
char *poin,
|
|
|
|
|
Key *key,
|
|
|
|
|
KeyBlock *actkb,
|
|
|
|
|
KeyBlock *kb,
|
|
|
|
|
float *weights,
|
|
|
|
|
const int mode)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
|
float ktot = 0.0, kd = 0.0;
|
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
2018-09-05 16:17:59 +03:00
|
|
|
int elemsize, poinsize = 0, a, step, *ofsp, ofs[32], flagflo = 0;
|
2009-11-01 00:06:53 +00:00
|
|
|
char *k1, *kref, *freek1, *freekref;
|
2002-10-12 11:37:38 +00:00
|
|
|
char *cp, elemstr[8];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-01-03 04:59:57 +00:00
|
|
|
/* currently always 0, in future key_pointer_size may assign */
|
2012-04-14 02:32:32 +00:00
|
|
|
ofs[1] = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (!key_pointer_size(key, mode, &poinsize, &ofs[0], &step)) {
|
2011-01-03 04:59:57 +00:00
|
|
|
return;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (end > tot) {
|
2012-04-14 02:32:32 +00:00
|
|
|
end = tot;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (tot != kb->totelem) {
|
2012-04-14 02:32:32 +00:00
|
|
|
ktot = 0.0;
|
|
|
|
|
flagflo = 1;
|
2012-03-24 06:18:31 +00:00
|
|
|
if (kb->totelem) {
|
2022-12-08 13:04:50 +11:00
|
|
|
kd = kb->totelem / float(tot);
|
2012-04-14 02:32:32 +00:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
return;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-14 02:32:32 +00:00
|
|
|
k1 = key_block_get_data(key, actkb, kb, &freek1);
|
|
|
|
|
kref = key_block_get_data(key, actkb, key->refkey, &freekref);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-01-07 02:02:55 +11:00
|
|
|
/* this exception is needed curves with multiple splines */
|
2012-04-14 02:32:32 +00:00
|
|
|
if (start != 0) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-14 02:32:32 +00:00
|
|
|
poin += poinsize * start;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (flagflo) {
|
2012-04-14 02:32:32 +00:00
|
|
|
ktot += start * kd;
|
2023-01-03 11:04:16 +11:00
|
|
|
a = int(floor(ktot));
|
2012-03-24 06:18:31 +00:00
|
|
|
if (a) {
|
2012-04-14 02:32:32 +00:00
|
|
|
ktot -= a;
|
|
|
|
|
k1 += a * key->elemsize;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2013-03-09 03:46:30 +00:00
|
|
|
else {
|
|
|
|
|
k1 += start * key->elemsize;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2013-03-09 03:46:30 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (mode == KEY_MODE_BEZTRIPLE) {
|
2012-04-14 02:32:32 +00:00
|
|
|
elemstr[0] = 1;
|
|
|
|
|
elemstr[1] = IPO_BEZTRIPLE;
|
|
|
|
|
elemstr[2] = 0;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2003-04-26 11:56:44 +00:00
|
|
|
/* just do it here, not above! */
|
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
2018-09-05 16:17:59 +03:00
|
|
|
elemsize = key->elemsize * step;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
2018-09-05 16:17:59 +03:00
|
|
|
for (a = start; a < end; a += step) {
|
2012-04-14 02:32:32 +00:00
|
|
|
cp = key->elemstr;
|
2019-04-22 09:39:35 +10:00
|
|
|
if (mode == KEY_MODE_BEZTRIPLE) {
|
2012-04-14 02:32:32 +00:00
|
|
|
cp = elemstr;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-14 02:32:32 +00:00
|
|
|
ofsp = ofs;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-14 02:32:32 +00:00
|
|
|
while (cp[0]) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-14 02:32:32 +00:00
|
|
|
switch (cp[1]) {
|
|
|
|
|
case IPO_FLOAT:
|
|
|
|
|
if (weights) {
|
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
2018-09-05 16:17:59 +03:00
|
|
|
memcpy(poin, kref, sizeof(float[KEYELEM_FLOAT_LEN_COORD]));
|
2019-04-22 09:39:35 +10:00
|
|
|
if (*weights != 0.0f) {
|
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
2018-09-05 16:17:59 +03:00
|
|
|
rel_flerp(
|
|
|
|
|
KEYELEM_FLOAT_LEN_COORD, (float *)poin, (float *)kref, (float *)k1, *weights);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2012-04-14 02:32:32 +00:00
|
|
|
weights++;
|
|
|
|
|
}
|
|
|
|
|
else {
|
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
2018-09-05 16:17:59 +03:00
|
|
|
memcpy(poin, k1, sizeof(float[KEYELEM_FLOAT_LEN_COORD]));
|
2012-04-14 02:32:32 +00:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case IPO_BPOINT:
|
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
2018-09-05 16:17:59 +03:00
|
|
|
memcpy(poin, k1, sizeof(float[KEYELEM_FLOAT_LEN_BPOINT]));
|
2012-04-14 02:32:32 +00:00
|
|
|
break;
|
|
|
|
|
case IPO_BEZTRIPLE:
|
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
2018-09-05 16:17:59 +03:00
|
|
|
memcpy(poin, k1, sizeof(float[KEYELEM_FLOAT_LEN_BEZTRIPLE]));
|
2012-04-14 02:32:32 +00:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
/* should never happen */
|
2019-04-22 09:39:35 +10:00
|
|
|
if (freek1) {
|
2012-04-14 02:32:32 +00:00
|
|
|
MEM_freeN(freek1);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
|
if (freekref) {
|
2012-04-14 02:32:32 +00:00
|
|
|
MEM_freeN(freekref);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2021-07-15 18:23:28 +10:00
|
|
|
BLI_assert_msg(0, "invalid 'cp[1]'");
|
2012-04-14 02:32:32 +00:00
|
|
|
return;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-14 02:48:56 +00:00
|
|
|
poin += *ofsp;
|
2012-04-14 02:32:32 +00:00
|
|
|
cp += 2;
|
|
|
|
|
ofsp++;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2003-04-26 11:56:44 +00:00
|
|
|
/* are we going to be nasty? */
|
2012-03-24 06:18:31 +00:00
|
|
|
if (flagflo) {
|
2012-04-14 02:32:32 +00:00
|
|
|
ktot += kd;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (ktot >= 1.0f) {
|
2011-03-28 04:22:50 +00:00
|
|
|
ktot -= 1.0f;
|
2012-04-14 02:32:32 +00:00
|
|
|
k1 += elemsize;
|
|
|
|
|
kref += elemsize;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2005-10-04 15:00:28 +00:00
|
|
|
else {
|
2012-04-14 02:32:32 +00:00
|
|
|
k1 += elemsize;
|
|
|
|
|
kref += elemsize;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2005-10-04 15:00:28 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (freek1) {
|
2012-03-24 06:18:31 +00:00
|
|
|
MEM_freeN(freek1);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
|
if (freekref) {
|
2012-03-24 06:18:31 +00:00
|
|
|
MEM_freeN(freekref);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
2011-01-03 04:59:57 +00:00
|
|
|
static void cp_cu_key(Curve *cu,
|
|
|
|
|
Key *key,
|
|
|
|
|
KeyBlock *actkb,
|
|
|
|
|
KeyBlock *kb,
|
|
|
|
|
const int start,
|
|
|
|
|
int end,
|
|
|
|
|
char *out,
|
|
|
|
|
const int tot)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
|
Nurb *nu;
|
2009-11-01 00:06:53 +00:00
|
|
|
int a, step, a1, a2;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-12-02 12:34:26 +01:00
|
|
|
for (a = 0, nu = static_cast<Nurb *>(cu->nurb.first); nu; nu = nu->next, a += step) {
|
2012-03-24 06:18:31 +00:00
|
|
|
if (nu->bp) {
|
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
2018-09-05 16:17:59 +03:00
|
|
|
step = KEYELEM_ELEM_LEN_BPOINT * nu->pntsu * nu->pntsv;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-10-23 13:28:22 +00:00
|
|
|
a1 = max_ii(a, start);
|
|
|
|
|
a2 = min_ii(a + step, end);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (a1 < a2) {
|
2022-12-02 12:34:26 +01:00
|
|
|
cp_key(a1, a2, tot, out, key, actkb, kb, nullptr, KEY_MODE_BPOINT);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
else if (nu->bezt) {
|
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
2018-09-05 16:17:59 +03:00
|
|
|
step = KEYELEM_ELEM_LEN_BEZTRIPLE * nu->pntsu;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-07-25 11:57:36 +00:00
|
|
|
/* exception because keys prefer to work with complete blocks */
|
2012-10-23 13:28:22 +00:00
|
|
|
a1 = max_ii(a, start);
|
|
|
|
|
a2 = min_ii(a + step, end);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (a1 < a2) {
|
2022-12-02 12:34:26 +01:00
|
|
|
cp_key(a1, a2, tot, out, key, actkb, kb, nullptr, KEY_MODE_BEZTRIPLE);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2012-04-14 02:32:32 +00:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
step = 0;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-12 17:27:22 +10:00
|
|
|
static void key_evaluate_relative(const int start,
|
|
|
|
|
int end,
|
|
|
|
|
const int tot,
|
|
|
|
|
char *basispoin,
|
|
|
|
|
Key *key,
|
|
|
|
|
KeyBlock *actkb,
|
|
|
|
|
float **per_keyblock_weights,
|
|
|
|
|
const int mode)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
|
KeyBlock *kb;
|
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
2018-09-05 16:17:59 +03:00
|
|
|
int *ofsp, ofs[3], elemsize, b, step;
|
2002-10-12 11:37:38 +00:00
|
|
|
char *cp, *poin, *reffrom, *from, elemstr[8];
|
2013-08-19 10:36:39 +00:00
|
|
|
int poinsize, keyblock_index;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-01-03 04:59:57 +00:00
|
|
|
/* currently always 0, in future key_pointer_size may assign */
|
2012-04-14 02:32:32 +00:00
|
|
|
ofs[1] = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (!key_pointer_size(key, mode, &poinsize, &ofs[0], &step)) {
|
2011-01-03 04:59:57 +00:00
|
|
|
return;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (end > tot) {
|
2012-04-14 02:32:32 +00:00
|
|
|
end = tot;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-12-17 13:14:01 +11:00
|
|
|
/* In case of Bezier-triple. */
|
|
|
|
|
elemstr[0] = 1; /* Number of IPO-floats. */
|
2012-04-14 02:32:32 +00:00
|
|
|
elemstr[1] = IPO_BEZTRIPLE;
|
|
|
|
|
elemstr[2] = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2003-04-26 11:56:44 +00:00
|
|
|
/* just here, not above! */
|
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
2018-09-05 16:17:59 +03:00
|
|
|
elemsize = key->elemsize * step;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2005-09-26 15:34:21 +00:00
|
|
|
/* step 1 init */
|
2022-12-02 12:34:26 +01:00
|
|
|
cp_key(start, end, tot, basispoin, key, actkb, key->refkey, nullptr, mode);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2005-09-26 15:34:21 +00:00
|
|
|
/* step 2: do it */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-12-02 12:34:26 +01:00
|
|
|
for (kb = static_cast<KeyBlock *>(key->block.first), keyblock_index = 0; kb;
|
|
|
|
|
kb = kb->next, keyblock_index++)
|
|
|
|
|
{
|
2012-04-14 02:32:32 +00:00
|
|
|
if (kb != key->refkey) {
|
|
|
|
|
float icuval = kb->curval;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2005-10-28 08:11:15 +00:00
|
|
|
/* only with value, and no difference allowed */
|
2012-04-14 02:32:32 +00:00
|
|
|
if (!(kb->flag & KEYBLOCK_MUTE) && icuval != 0.0f && kb->totelem == tot) {
|
2007-11-20 16:58:25 +00:00
|
|
|
KeyBlock *refb;
|
2013-08-19 10:36:39 +00:00
|
|
|
float weight,
|
2022-12-02 12:34:26 +01:00
|
|
|
*weights = per_keyblock_weights ? per_keyblock_weights[keyblock_index] : nullptr;
|
|
|
|
|
char *freefrom = nullptr;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2007-11-20 16:58:25 +00:00
|
|
|
/* reference now can be any block */
|
2022-12-02 12:34:26 +01:00
|
|
|
refb = static_cast<KeyBlock *>(BLI_findlink(&key->block, kb->relative));
|
|
|
|
|
if (refb == nullptr) {
|
2012-04-14 02:32:32 +00:00
|
|
|
continue;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-14 02:32:32 +00:00
|
|
|
poin = basispoin;
|
|
|
|
|
from = key_block_get_data(key, actkb, kb, &freefrom);
|
2020-02-19 08:54:34 -03:00
|
|
|
|
|
|
|
|
/* For meshes, use the original values instead of the bmesh values to
|
|
|
|
|
* maintain a constant offset. */
|
2022-12-02 12:34:26 +01:00
|
|
|
reffrom = static_cast<char *>(refb->data);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-14 02:32:32 +00:00
|
|
|
poin += start * poinsize;
|
|
|
|
|
reffrom += key->elemsize * start; /* key elemsize yes! */
|
|
|
|
|
from += key->elemsize * start;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
2018-09-05 16:17:59 +03:00
|
|
|
for (b = start; b < end; b += step) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-14 02:32:32 +00:00
|
|
|
weight = weights ? (*weights * icuval) : icuval;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-14 02:32:32 +00:00
|
|
|
cp = key->elemstr;
|
2019-04-22 09:39:35 +10:00
|
|
|
if (mode == KEY_MODE_BEZTRIPLE) {
|
2012-04-14 02:32:32 +00:00
|
|
|
cp = elemstr;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-14 02:32:32 +00:00
|
|
|
ofsp = ofs;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-07-01 09:54:44 +00:00
|
|
|
while (cp[0]) { /* (cp[0] == amount) */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-14 02:32:32 +00:00
|
|
|
switch (cp[1]) {
|
|
|
|
|
case IPO_FLOAT:
|
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
2018-09-05 16:17:59 +03:00
|
|
|
rel_flerp(KEYELEM_FLOAT_LEN_COORD,
|
|
|
|
|
(float *)poin,
|
|
|
|
|
(float *)reffrom,
|
|
|
|
|
(float *)from,
|
|
|
|
|
weight);
|
2012-04-14 02:32:32 +00:00
|
|
|
break;
|
|
|
|
|
case IPO_BPOINT:
|
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
2018-09-05 16:17:59 +03:00
|
|
|
rel_flerp(KEYELEM_FLOAT_LEN_BPOINT,
|
|
|
|
|
(float *)poin,
|
|
|
|
|
(float *)reffrom,
|
|
|
|
|
(float *)from,
|
|
|
|
|
weight);
|
2012-04-14 02:32:32 +00:00
|
|
|
break;
|
|
|
|
|
case IPO_BEZTRIPLE:
|
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
2018-09-05 16:17:59 +03:00
|
|
|
rel_flerp(KEYELEM_FLOAT_LEN_BEZTRIPLE,
|
|
|
|
|
(float *)poin,
|
|
|
|
|
(float *)reffrom,
|
|
|
|
|
(float *)from,
|
|
|
|
|
weight);
|
2012-04-14 02:32:32 +00:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
/* should never happen */
|
2019-04-22 09:39:35 +10:00
|
|
|
if (freefrom) {
|
2012-04-14 02:32:32 +00:00
|
|
|
MEM_freeN(freefrom);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2021-07-15 18:23:28 +10:00
|
|
|
BLI_assert_msg(0, "invalid 'cp[1]'");
|
2012-04-14 02:32:32 +00:00
|
|
|
return;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-14 02:48:56 +00:00
|
|
|
poin += *ofsp;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-14 02:32:32 +00:00
|
|
|
cp += 2;
|
2002-10-12 11:37:38 +00:00
|
|
|
ofsp++;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-14 02:32:32 +00:00
|
|
|
reffrom += elemsize;
|
|
|
|
|
from += elemsize;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (weights) {
|
2012-03-24 06:18:31 +00:00
|
|
|
weights++;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (freefrom) {
|
2012-03-24 06:18:31 +00:00
|
|
|
MEM_freeN(freefrom);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-03 04:59:57 +00:00
|
|
|
static void do_key(const int start,
|
|
|
|
|
int end,
|
|
|
|
|
const int tot,
|
|
|
|
|
char *poin,
|
|
|
|
|
Key *key,
|
|
|
|
|
KeyBlock *actkb,
|
|
|
|
|
KeyBlock **k,
|
|
|
|
|
float *t,
|
|
|
|
|
const int mode)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
|
float k1tot = 0.0, k2tot = 0.0, k3tot = 0.0, k4tot = 0.0;
|
|
|
|
|
float k1d = 0.0, k2d = 0.0, k3d = 0.0, k4d = 0.0;
|
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
2018-09-05 16:17:59 +03:00
|
|
|
int a, step, ofs[32], *ofsp;
|
2012-04-14 02:32:32 +00:00
|
|
|
int flagdo = 15, flagflo = 0, elemsize, poinsize = 0;
|
2009-11-01 00:06:53 +00:00
|
|
|
char *k1, *k2, *k3, *k4, *freek1, *freek2, *freek3, *freek4;
|
2011-09-22 14:42:29 +00:00
|
|
|
char *cp, elemstr[8];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-01-03 04:59:57 +00:00
|
|
|
/* currently always 0, in future key_pointer_size may assign */
|
2012-04-14 02:32:32 +00:00
|
|
|
ofs[1] = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (!key_pointer_size(key, mode, &poinsize, &ofs[0], &step)) {
|
2011-01-03 04:59:57 +00:00
|
|
|
return;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (end > tot) {
|
2012-04-14 02:32:32 +00:00
|
|
|
end = tot;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-14 02:32:32 +00:00
|
|
|
k1 = key_block_get_data(key, actkb, k[0], &freek1);
|
|
|
|
|
k2 = key_block_get_data(key, actkb, k[1], &freek2);
|
|
|
|
|
k3 = key_block_get_data(key, actkb, k[2], &freek3);
|
|
|
|
|
k4 = key_block_get_data(key, actkb, k[3], &freek4);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-03-29 16:33:51 +11:00
|
|
|
/* Test for more or less points (per key!) */
|
2012-03-24 06:18:31 +00:00
|
|
|
if (tot != k[0]->totelem) {
|
2012-04-14 02:32:32 +00:00
|
|
|
k1tot = 0.0;
|
2002-10-12 11:37:38 +00:00
|
|
|
flagflo |= 1;
|
2012-03-24 06:18:31 +00:00
|
|
|
if (k[0]->totelem) {
|
2022-12-08 13:04:50 +11:00
|
|
|
k1d = k[0]->totelem / float(tot);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2013-03-09 03:46:30 +00:00
|
|
|
else {
|
|
|
|
|
flagdo -= 1;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2013-03-09 03:46:30 +00:00
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
if (tot != k[1]->totelem) {
|
2012-04-14 02:32:32 +00:00
|
|
|
k2tot = 0.0;
|
2002-10-12 11:37:38 +00:00
|
|
|
flagflo |= 2;
|
2012-03-24 06:18:31 +00:00
|
|
|
if (k[0]->totelem) {
|
2022-12-08 13:04:50 +11:00
|
|
|
k2d = k[1]->totelem / float(tot);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2013-03-09 03:46:30 +00:00
|
|
|
else {
|
|
|
|
|
flagdo -= 2;
|
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
if (tot != k[2]->totelem) {
|
2012-04-14 02:32:32 +00:00
|
|
|
k3tot = 0.0;
|
2002-10-12 11:37:38 +00:00
|
|
|
flagflo |= 4;
|
2012-03-24 06:18:31 +00:00
|
|
|
if (k[0]->totelem) {
|
2022-12-08 13:04:50 +11:00
|
|
|
k3d = k[2]->totelem / float(tot);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2013-03-09 03:46:30 +00:00
|
|
|
else {
|
|
|
|
|
flagdo -= 4;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2013-03-09 03:46:30 +00:00
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
if (tot != k[3]->totelem) {
|
2012-04-14 02:32:32 +00:00
|
|
|
k4tot = 0.0;
|
2002-10-12 11:37:38 +00:00
|
|
|
flagflo |= 8;
|
2012-03-24 06:18:31 +00:00
|
|
|
if (k[0]->totelem) {
|
2022-12-08 13:04:50 +11:00
|
|
|
k4d = k[3]->totelem / float(tot);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2013-03-09 03:46:30 +00:00
|
|
|
else {
|
|
|
|
|
flagdo -= 8;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2013-03-09 03:46:30 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-01-07 02:02:55 +11:00
|
|
|
/* this exception is needed for curves with multiple splines */
|
2012-04-14 02:32:32 +00:00
|
|
|
if (start != 0) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-14 02:32:32 +00:00
|
|
|
poin += poinsize * start;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (flagdo & 1) {
|
|
|
|
|
if (flagflo & 1) {
|
2012-04-14 02:32:32 +00:00
|
|
|
k1tot += start * k1d;
|
2023-01-03 11:04:16 +11:00
|
|
|
a = int(floor(k1tot));
|
2012-03-24 06:18:31 +00:00
|
|
|
if (a) {
|
2012-04-14 02:32:32 +00:00
|
|
|
k1tot -= a;
|
|
|
|
|
k1 += a * key->elemsize;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2013-03-09 03:46:30 +00:00
|
|
|
else {
|
|
|
|
|
k1 += start * key->elemsize;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2013-03-09 03:46:30 +00:00
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
if (flagdo & 2) {
|
|
|
|
|
if (flagflo & 2) {
|
2012-04-14 02:32:32 +00:00
|
|
|
k2tot += start * k2d;
|
2023-01-03 11:04:16 +11:00
|
|
|
a = int(floor(k2tot));
|
2012-03-24 06:18:31 +00:00
|
|
|
if (a) {
|
2012-04-14 02:32:32 +00:00
|
|
|
k2tot -= a;
|
|
|
|
|
k2 += a * key->elemsize;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2013-03-09 03:46:30 +00:00
|
|
|
else {
|
|
|
|
|
k2 += start * key->elemsize;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2013-03-09 03:46:30 +00:00
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
if (flagdo & 4) {
|
|
|
|
|
if (flagflo & 4) {
|
2012-04-14 02:32:32 +00:00
|
|
|
k3tot += start * k3d;
|
2023-01-03 11:04:16 +11:00
|
|
|
a = int(floor(k3tot));
|
2012-03-24 06:18:31 +00:00
|
|
|
if (a) {
|
2012-04-14 02:32:32 +00:00
|
|
|
k3tot -= a;
|
|
|
|
|
k3 += a * key->elemsize;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
}
|
2013-03-09 03:46:30 +00:00
|
|
|
else {
|
2014-11-16 18:50:23 +01:00
|
|
|
k3 += start * key->elemsize;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
if (flagdo & 8) {
|
|
|
|
|
if (flagflo & 8) {
|
2013-03-09 03:46:30 +00:00
|
|
|
k4tot += start * k4d;
|
2023-01-03 11:04:16 +11:00
|
|
|
a = int(floor(k4tot));
|
2019-04-17 06:17:24 +02:00
|
|
|
if (a) {
|
2012-04-14 02:32:32 +00:00
|
|
|
k4tot -= a;
|
2013-03-09 03:46:30 +00:00
|
|
|
k4 += a * key->elemsize;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2013-03-09 03:46:30 +00:00
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
else {
|
2012-04-14 02:32:32 +00:00
|
|
|
k4 += start * key->elemsize;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-12-17 13:14:01 +11:00
|
|
|
/* In case of bezier-triples. */
|
|
|
|
|
elemstr[0] = 1; /* Number of IPO-floats. */
|
2012-04-14 02:32:32 +00:00
|
|
|
elemstr[1] = IPO_BEZTRIPLE;
|
2013-03-09 03:46:30 +00:00
|
|
|
elemstr[2] = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-09 03:46:30 +00:00
|
|
|
/* only here, not above! */
|
|
|
|
|
elemsize = key->elemsize * step;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-09 03:46:30 +00:00
|
|
|
for (a = start; a < end; a += step) {
|
|
|
|
|
cp = key->elemstr;
|
2019-04-22 09:39:35 +10:00
|
|
|
if (mode == KEY_MODE_BEZTRIPLE) {
|
2012-04-14 02:32:32 +00:00
|
|
|
cp = elemstr;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-14 02:32:32 +00:00
|
|
|
ofsp = ofs;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-14 02:32:32 +00:00
|
|
|
while (cp[0]) { /* (cp[0] == amount) */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-14 02:32:32 +00:00
|
|
|
switch (cp[1]) {
|
|
|
|
|
case IPO_FLOAT:
|
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
2018-09-05 16:17:59 +03:00
|
|
|
flerp(KEYELEM_FLOAT_LEN_COORD,
|
|
|
|
|
(float *)poin,
|
|
|
|
|
(float *)k1,
|
2012-07-01 09:54:44 +00:00
|
|
|
(float *)k2,
|
2012-04-14 02:32:32 +00:00
|
|
|
(float *)k3,
|
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
2018-09-05 16:17:59 +03:00
|
|
|
(float *)k4,
|
|
|
|
|
t);
|
2012-04-14 02:32:32 +00:00
|
|
|
break;
|
|
|
|
|
case IPO_BPOINT:
|
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
2018-09-05 16:17:59 +03:00
|
|
|
flerp(KEYELEM_FLOAT_LEN_BPOINT,
|
|
|
|
|
(float *)poin,
|
|
|
|
|
(float *)k1,
|
|
|
|
|
(float *)k2,
|
|
|
|
|
(float *)k3,
|
|
|
|
|
(float *)k4,
|
|
|
|
|
t);
|
2012-04-14 02:32:32 +00:00
|
|
|
break;
|
|
|
|
|
case IPO_BEZTRIPLE:
|
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
2018-09-05 16:17:59 +03:00
|
|
|
flerp(KEYELEM_FLOAT_LEN_BEZTRIPLE,
|
2022-12-02 12:34:26 +01:00
|
|
|
(float *)poin,
|
|
|
|
|
(float *)k1,
|
|
|
|
|
(float *)k2,
|
|
|
|
|
(float *)k3,
|
|
|
|
|
(float *)k4,
|
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
2018-09-05 16:17:59 +03:00
|
|
|
t);
|
2012-04-14 02:32:32 +00:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
/* should never happen */
|
2019-04-22 09:39:35 +10:00
|
|
|
if (freek1) {
|
2012-04-14 02:32:32 +00:00
|
|
|
MEM_freeN(freek1);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
|
if (freek2) {
|
2012-04-14 02:32:32 +00:00
|
|
|
MEM_freeN(freek2);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
|
if (freek3) {
|
2012-04-14 02:32:32 +00:00
|
|
|
MEM_freeN(freek3);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
|
if (freek4) {
|
2012-04-14 02:32:32 +00:00
|
|
|
MEM_freeN(freek4);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2021-07-15 18:23:28 +10:00
|
|
|
BLI_assert_msg(0, "invalid 'cp[1]'");
|
2012-04-14 02:32:32 +00:00
|
|
|
return;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-14 02:48:56 +00:00
|
|
|
poin += *ofsp;
|
2012-04-14 02:32:32 +00:00
|
|
|
cp += 2;
|
2002-10-12 11:37:38 +00:00
|
|
|
ofsp++;
|
|
|
|
|
}
|
2003-04-26 11:56:44 +00:00
|
|
|
/* lets do it the difficult way: when keys have a different size */
|
2012-03-24 06:18:31 +00:00
|
|
|
if (flagdo & 1) {
|
|
|
|
|
if (flagflo & 1) {
|
2012-04-14 02:32:32 +00:00
|
|
|
k1tot += k1d;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (k1tot >= 1.0f) {
|
2011-03-28 04:22:50 +00:00
|
|
|
k1tot -= 1.0f;
|
2012-04-14 02:32:32 +00:00
|
|
|
k1 += elemsize;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2015-05-24 22:18:16 +10:00
|
|
|
else {
|
|
|
|
|
k1 += elemsize;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
if (flagdo & 2) {
|
|
|
|
|
if (flagflo & 2) {
|
2012-04-14 02:32:32 +00:00
|
|
|
k2tot += k2d;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (k2tot >= 1.0f) {
|
2011-03-28 04:22:50 +00:00
|
|
|
k2tot -= 1.0f;
|
2012-04-14 02:32:32 +00:00
|
|
|
k2 += elemsize;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
}
|
2013-03-09 03:46:30 +00:00
|
|
|
else {
|
|
|
|
|
k2 += elemsize;
|
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
if (flagdo & 4) {
|
|
|
|
|
if (flagflo & 4) {
|
2012-04-14 02:32:32 +00:00
|
|
|
k3tot += k3d;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (k3tot >= 1.0f) {
|
2011-03-28 04:22:50 +00:00
|
|
|
k3tot -= 1.0f;
|
2012-04-14 02:32:32 +00:00
|
|
|
k3 += elemsize;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2013-03-09 03:46:30 +00:00
|
|
|
else {
|
|
|
|
|
k3 += elemsize;
|
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
if (flagdo & 8) {
|
|
|
|
|
if (flagflo & 8) {
|
2012-04-14 02:32:32 +00:00
|
|
|
k4tot += k4d;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (k4tot >= 1.0f) {
|
2011-03-28 04:22:50 +00:00
|
|
|
k4tot -= 1.0f;
|
2012-04-14 02:32:32 +00:00
|
|
|
k4 += elemsize;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2013-03-09 03:46:30 +00:00
|
|
|
else {
|
|
|
|
|
k4 += elemsize;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
2013-03-09 03:46:30 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (freek1) {
|
2012-03-24 06:18:31 +00:00
|
|
|
MEM_freeN(freek1);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
|
if (freek2) {
|
2012-03-24 06:18:31 +00:00
|
|
|
MEM_freeN(freek2);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
|
if (freek3) {
|
2012-03-24 06:18:31 +00:00
|
|
|
MEM_freeN(freek3);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
|
if (freek4) {
|
2012-03-24 06:18:31 +00:00
|
|
|
MEM_freeN(freek4);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
2013-08-19 10:36:39 +00:00
|
|
|
static float *get_weights_array(Object *ob, char *vgroup, WeightsArrayCache *cache)
|
2005-10-04 15:00:28 +00:00
|
|
|
{
|
2022-12-02 12:34:26 +01:00
|
|
|
const MDeformVert *dvert = nullptr;
|
|
|
|
|
BMEditMesh *em = nullptr;
|
2010-03-09 04:32:40 +00:00
|
|
|
BMIter iter;
|
|
|
|
|
BMVert *eve;
|
2012-04-14 02:32:32 +00:00
|
|
|
int totvert = 0, defgrp_index = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2006-09-14 08:13:09 +00:00
|
|
|
/* no vgroup string set? */
|
2019-04-22 09:39:35 +10:00
|
|
|
if (vgroup[0] == 0) {
|
2022-12-02 12:34:26 +01:00
|
|
|
return nullptr;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2006-09-14 08:13:09 +00:00
|
|
|
/* gather dvert and totvert */
|
2012-04-14 02:32:32 +00:00
|
|
|
if (ob->type == OB_MESH) {
|
2022-12-02 12:34:26 +01:00
|
|
|
Mesh *me = static_cast<Mesh *>(ob->data);
|
Mesh: Remove redundant custom data pointers
For copy-on-write, we want to share attribute arrays between meshes
where possible. Mutable pointers like `Mesh.mvert` make that difficult
by making ownership vague. They also make code more complex by adding
redundancy.
The simplest solution is just removing them and retrieving layers from
`CustomData` as needed. Similar changes have already been applied to
curves and point clouds (e9f82d3dc7ee, 410a6efb747f). Removing use of
the pointers generally makes code more obvious and more reusable.
Mesh data is now accessed with a C++ API (`Mesh::edges()` or
`Mesh::edges_for_write()`), and a C API (`BKE_mesh_edges(mesh)`).
The CoW changes this commit makes possible are described in T95845
and T95842, and started in D14139 and D14140. The change also simplifies
the ongoing mesh struct-of-array refactors from T95965.
**RNA/Python Access Performance**
Theoretically, accessing mesh elements with the RNA API may become
slower, since the layer needs to be found on every random access.
However, overhead is already high enough that this doesn't make a
noticible differenc, and performance is actually improved in some
cases. Random access can be up to 10% faster, but other situations
might be a bit slower. Generally using `foreach_get/set` are the best
way to improve performance. See the differential revision for more
discussion about Python performance.
Cycles has been updated to use raw pointers and the internal Blender
mesh types, mostly because there is no sense in having this overhead
when it's already compiled with Blender. In my tests this roughly
halves the Cycles mesh creation time (0.19s to 0.10s for a 1 million
face grid).
Differential Revision: https://developer.blender.org/D15488
2022-09-05 11:56:34 -05:00
|
|
|
dvert = BKE_mesh_deform_verts(me);
|
2012-04-14 02:32:32 +00:00
|
|
|
totvert = me->totvert;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (me->edit_mesh && me->edit_mesh->bm->totvert == totvert) {
|
2019-02-17 18:05:18 +11:00
|
|
|
em = me->edit_mesh;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2006-09-14 08:13:09 +00:00
|
|
|
}
|
2012-04-14 02:32:32 +00:00
|
|
|
else if (ob->type == OB_LATTICE) {
|
2022-12-02 12:34:26 +01:00
|
|
|
Lattice *lt = static_cast<Lattice *>(ob->data);
|
2012-04-14 02:32:32 +00:00
|
|
|
dvert = lt->dvert;
|
|
|
|
|
totvert = lt->pntsu * lt->pntsv * lt->pntsw;
|
2006-09-14 08:13:09 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-12-02 12:34:26 +01:00
|
|
|
if (dvert == nullptr) {
|
|
|
|
|
return nullptr;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2005-10-04 15:00:28 +00:00
|
|
|
/* find the group (weak loop-in-loop) */
|
2020-03-06 12:50:56 +11:00
|
|
|
defgrp_index = BKE_object_defgroup_name_index(ob, vgroup);
|
2012-10-22 17:19:05 +00:00
|
|
|
if (defgrp_index != -1) {
|
2005-10-04 15:00:28 +00:00
|
|
|
float *weights;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-08-19 10:36:39 +00:00
|
|
|
if (cache) {
|
2022-12-02 12:34:26 +01:00
|
|
|
if (cache->defgroup_weights == nullptr) {
|
2021-07-13 12:10:34 -04:00
|
|
|
int num_defgroup = BKE_object_defgroup_count(ob);
|
2022-12-02 12:34:26 +01:00
|
|
|
cache->defgroup_weights = static_cast<float **>(MEM_callocN(
|
|
|
|
|
sizeof(*cache->defgroup_weights) * num_defgroup, "cached defgroup weights"));
|
2013-08-19 10:36:39 +00:00
|
|
|
cache->num_defgroup_weights = num_defgroup;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-08-19 10:36:39 +00:00
|
|
|
if (cache->defgroup_weights[defgrp_index]) {
|
|
|
|
|
return cache->defgroup_weights[defgrp_index];
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-12-02 12:34:26 +01:00
|
|
|
weights = static_cast<float *>(MEM_mallocN(totvert * sizeof(float), "weights"));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (em) {
|
2020-09-09 16:35:20 +02:00
|
|
|
int i;
|
2013-05-27 12:42:48 +00:00
|
|
|
const int cd_dvert_offset = CustomData_get_offset(&em->bm->vdata, CD_MDEFORMVERT);
|
2012-05-13 14:47:53 +00:00
|
|
|
BM_ITER_MESH_INDEX (eve, &iter, em->bm, BM_VERTS_OF_MESH, i) {
|
2022-12-02 12:34:26 +01:00
|
|
|
dvert = static_cast<const MDeformVert *>(BM_ELEM_CD_GET_VOID_P(eve, cd_dvert_offset));
|
2020-03-06 12:50:56 +11:00
|
|
|
weights[i] = BKE_defvert_find_weight(dvert, defgrp_index);
|
2005-10-04 15:00:28 +00:00
|
|
|
}
|
|
|
|
|
}
|
2010-01-31 11:15:51 +00:00
|
|
|
else {
|
2020-09-09 16:35:20 +02:00
|
|
|
for (int i = 0; i < totvert; i++, dvert++) {
|
2020-03-06 12:50:56 +11:00
|
|
|
weights[i] = BKE_defvert_find_weight(dvert, defgrp_index);
|
2010-01-31 11:15:51 +00:00
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-08-19 10:36:39 +00:00
|
|
|
if (cache) {
|
|
|
|
|
cache->defgroup_weights[defgrp_index] = weights;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2005-10-04 15:00:28 +00:00
|
|
|
return weights;
|
|
|
|
|
}
|
2022-12-02 12:34:26 +01:00
|
|
|
return nullptr;
|
2005-10-04 15:00:28 +00:00
|
|
|
}
|
|
|
|
|
|
2018-09-12 17:27:22 +10:00
|
|
|
static float **keyblock_get_per_block_weights(Object *ob, Key *key, WeightsArrayCache *cache)
|
2013-08-19 10:36:39 +00:00
|
|
|
{
|
|
|
|
|
KeyBlock *keyblock;
|
|
|
|
|
float **per_keyblock_weights;
|
|
|
|
|
int keyblock_index;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-12-02 12:34:26 +01:00
|
|
|
per_keyblock_weights = static_cast<float **>(
|
|
|
|
|
MEM_mallocN(sizeof(*per_keyblock_weights) * key->totkey, "per keyblock weights"));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-12-02 12:34:26 +01:00
|
|
|
for (keyblock = static_cast<KeyBlock *>(key->block.first), keyblock_index = 0; keyblock;
|
2013-08-19 10:36:39 +00:00
|
|
|
keyblock = keyblock->next, keyblock_index++)
|
|
|
|
|
{
|
|
|
|
|
per_keyblock_weights[keyblock_index] = get_weights_array(ob, keyblock->vgroup, cache);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-08-19 10:36:39 +00:00
|
|
|
return per_keyblock_weights;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-12 17:27:22 +10:00
|
|
|
static void keyblock_free_per_block_weights(Key *key,
|
|
|
|
|
float **per_keyblock_weights,
|
|
|
|
|
WeightsArrayCache *cache)
|
2013-08-19 10:36:39 +00:00
|
|
|
{
|
|
|
|
|
int a;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-08-19 10:36:39 +00:00
|
|
|
if (cache) {
|
|
|
|
|
if (cache->num_defgroup_weights) {
|
|
|
|
|
for (a = 0; a < cache->num_defgroup_weights; a++) {
|
|
|
|
|
if (cache->defgroup_weights[a]) {
|
|
|
|
|
MEM_freeN(cache->defgroup_weights[a]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
MEM_freeN(cache->defgroup_weights);
|
|
|
|
|
}
|
2022-12-02 12:34:26 +01:00
|
|
|
cache->defgroup_weights = nullptr;
|
2013-08-19 10:36:39 +00:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
for (a = 0; a < key->totkey; a++) {
|
|
|
|
|
if (per_keyblock_weights[a]) {
|
|
|
|
|
MEM_freeN(per_keyblock_weights[a]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-08-19 10:36:39 +00:00
|
|
|
MEM_freeN(per_keyblock_weights);
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-07 02:02:55 +11:00
|
|
|
static void do_mesh_key(Object *ob, Key *key, char *out, const int tot)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2012-09-19 10:12:07 +00:00
|
|
|
KeyBlock *k[4], *actkb = BKE_keyblock_from_object(ob);
|
2012-04-05 05:25:20 +00:00
|
|
|
float t[4];
|
|
|
|
|
int flag = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-01-07 02:02:55 +11:00
|
|
|
if (key->type == KEY_RELATIVE) {
|
2022-12-02 12:34:26 +01:00
|
|
|
WeightsArrayCache cache = {0, nullptr};
|
2015-01-07 02:02:55 +11:00
|
|
|
float **per_keyblock_weights;
|
2018-09-12 17:27:22 +10:00
|
|
|
per_keyblock_weights = keyblock_get_per_block_weights(ob, key, &cache);
|
|
|
|
|
key_evaluate_relative(
|
|
|
|
|
0, tot, tot, (char *)out, key, actkb, per_keyblock_weights, KEY_MODE_DUMMY);
|
|
|
|
|
keyblock_free_per_block_weights(key, per_keyblock_weights, &cache);
|
2015-01-07 02:02:55 +11:00
|
|
|
}
|
|
|
|
|
else {
|
2012-04-05 05:05:18 +00:00
|
|
|
const float ctime_scaled = key->ctime / 100.0f;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-01-07 02:02:55 +11:00
|
|
|
flag = setkeys(ctime_scaled, &key->block, k, t, 0);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-01-07 02:02:55 +11:00
|
|
|
if (flag == 0) {
|
|
|
|
|
do_key(0, tot, tot, (char *)out, key, actkb, k, t, KEY_MODE_DUMMY);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2022-12-02 12:34:26 +01:00
|
|
|
cp_key(0, tot, tot, (char *)out, key, actkb, k[2], nullptr, KEY_MODE_DUMMY);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-03 04:59:57 +00:00
|
|
|
static void do_cu_key(
|
|
|
|
|
Curve *cu, Key *key, KeyBlock *actkb, KeyBlock **k, float *t, char *out, const int tot)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
|
Nurb *nu;
|
2009-11-01 00:06:53 +00:00
|
|
|
int a, step;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-12-02 12:34:26 +01:00
|
|
|
for (a = 0, nu = static_cast<Nurb *>(cu->nurb.first); nu; nu = nu->next, a += step) {
|
2012-03-24 06:18:31 +00:00
|
|
|
if (nu->bp) {
|
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
2018-09-05 16:17:59 +03:00
|
|
|
step = KEYELEM_ELEM_LEN_BPOINT * nu->pntsu * nu->pntsv;
|
2012-04-14 02:32:32 +00:00
|
|
|
do_key(a, a + step, tot, out, key, actkb, k, t, KEY_MODE_BPOINT);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
else if (nu->bezt) {
|
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
2018-09-05 16:17:59 +03:00
|
|
|
step = KEYELEM_ELEM_LEN_BEZTRIPLE * nu->pntsu;
|
2012-04-14 02:32:32 +00:00
|
|
|
do_key(a, a + step, tot, out, key, actkb, k, t, KEY_MODE_BEZTRIPLE);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
step = 0;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-05 05:05:18 +00:00
|
|
|
static void do_rel_cu_key(Curve *cu, Key *key, KeyBlock *actkb, char *out, const int tot)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
|
Nurb *nu;
|
2009-11-01 00:06:53 +00:00
|
|
|
int a, step;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-12-02 12:34:26 +01:00
|
|
|
for (a = 0, nu = static_cast<Nurb *>(cu->nurb.first); nu; nu = nu->next, a += step) {
|
2012-03-24 06:18:31 +00:00
|
|
|
if (nu->bp) {
|
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
2018-09-05 16:17:59 +03:00
|
|
|
step = KEYELEM_ELEM_LEN_BPOINT * nu->pntsu * nu->pntsv;
|
2022-12-02 12:34:26 +01:00
|
|
|
key_evaluate_relative(a, a + step, tot, out, key, actkb, nullptr, KEY_MODE_BPOINT);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
else if (nu->bezt) {
|
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
2018-09-05 16:17:59 +03:00
|
|
|
step = KEYELEM_ELEM_LEN_BEZTRIPLE * nu->pntsu;
|
2022-12-02 12:34:26 +01:00
|
|
|
key_evaluate_relative(a, a + step, tot, out, key, actkb, nullptr, KEY_MODE_BEZTRIPLE);
|
2012-04-14 02:32:32 +00:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
step = 0;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-07 02:02:55 +11:00
|
|
|
static void do_curve_key(Object *ob, Key *key, char *out, const int tot)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2022-12-02 12:34:26 +01:00
|
|
|
Curve *cu = static_cast<Curve *>(ob->data);
|
2012-09-19 10:12:07 +00:00
|
|
|
KeyBlock *k[4], *actkb = BKE_keyblock_from_object(ob);
|
2012-04-05 05:25:20 +00:00
|
|
|
float t[4];
|
|
|
|
|
int flag = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-01-07 02:02:55 +11:00
|
|
|
if (key->type == KEY_RELATIVE) {
|
|
|
|
|
do_rel_cu_key(cu, cu->key, actkb, out, tot);
|
|
|
|
|
}
|
|
|
|
|
else {
|
2012-04-05 05:05:18 +00:00
|
|
|
const float ctime_scaled = key->ctime / 100.0f;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-01-07 02:02:55 +11:00
|
|
|
flag = setkeys(ctime_scaled, &key->block, k, t, 0);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-01-07 02:02:55 +11:00
|
|
|
if (flag == 0) {
|
|
|
|
|
do_cu_key(cu, key, actkb, k, t, out, tot);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2015-01-07 02:02:55 +11:00
|
|
|
cp_cu_key(cu, key, actkb, k[2], 0, tot, out, tot);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-07 02:02:55 +11:00
|
|
|
static void do_latt_key(Object *ob, Key *key, char *out, const int tot)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2022-12-02 12:34:26 +01:00
|
|
|
Lattice *lt = static_cast<Lattice *>(ob->data);
|
2012-09-19 10:12:07 +00:00
|
|
|
KeyBlock *k[4], *actkb = BKE_keyblock_from_object(ob);
|
2012-04-05 05:25:20 +00:00
|
|
|
float t[4];
|
|
|
|
|
int flag;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-01-07 02:02:55 +11:00
|
|
|
if (key->type == KEY_RELATIVE) {
|
|
|
|
|
float **per_keyblock_weights;
|
2022-12-02 12:34:26 +01:00
|
|
|
per_keyblock_weights = keyblock_get_per_block_weights(ob, key, nullptr);
|
2018-09-12 17:27:22 +10:00
|
|
|
key_evaluate_relative(
|
|
|
|
|
0, tot, tot, (char *)out, key, actkb, per_keyblock_weights, KEY_MODE_DUMMY);
|
2022-12-02 12:34:26 +01:00
|
|
|
keyblock_free_per_block_weights(key, per_keyblock_weights, nullptr);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2015-01-07 02:02:55 +11:00
|
|
|
const float ctime_scaled = key->ctime / 100.0f;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-01-07 02:02:55 +11:00
|
|
|
flag = setkeys(ctime_scaled, &key->block, k, t, 0);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-01-07 02:02:55 +11:00
|
|
|
if (flag == 0) {
|
|
|
|
|
do_key(0, tot, tot, (char *)out, key, actkb, k, t, KEY_MODE_DUMMY);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2022-12-02 12:34:26 +01:00
|
|
|
cp_key(0, tot, tot, (char *)out, key, actkb, k[2], nullptr, KEY_MODE_DUMMY);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (lt->flag & LT_OUTSIDE) {
|
2012-03-24 06:18:31 +00:00
|
|
|
outside_lattice(lt);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
2022-07-20 10:45:23 +02:00
|
|
|
static void keyblock_data_convert_to_lattice(const float (*fp)[3],
|
|
|
|
|
BPoint *bpoint,
|
|
|
|
|
const int totpoint);
|
|
|
|
|
static void keyblock_data_convert_to_curve(const float *fp, ListBase *nurb, const int totpoint);
|
|
|
|
|
|
|
|
|
|
float *BKE_key_evaluate_object_ex(
|
|
|
|
|
Object *ob, int *r_totelem, float *arr, size_t arr_size, ID *obdata)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2012-09-19 10:12:07 +00:00
|
|
|
Key *key = BKE_key_from_object(ob);
|
|
|
|
|
KeyBlock *actkb = BKE_keyblock_from_object(ob);
|
2009-11-01 00:06:53 +00:00
|
|
|
char *out;
|
2012-04-14 02:32:32 +00:00
|
|
|
int tot = 0, size = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-12-02 12:34:26 +01:00
|
|
|
if (key == nullptr || BLI_listbase_is_empty(&key->block)) {
|
|
|
|
|
return nullptr;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-11-01 00:06:53 +00:00
|
|
|
/* compute size of output array */
|
2012-03-24 06:18:31 +00:00
|
|
|
if (ob->type == OB_MESH) {
|
2022-12-02 12:34:26 +01:00
|
|
|
Mesh *me = static_cast<Mesh *>(ob->data);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-14 02:32:32 +00:00
|
|
|
tot = me->totvert;
|
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
2018-09-05 16:17:59 +03:00
|
|
|
size = tot * sizeof(float[KEYELEM_FLOAT_LEN_COORD]);
|
2009-11-01 00:06:53 +00:00
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
else if (ob->type == OB_LATTICE) {
|
2022-12-02 12:34:26 +01:00
|
|
|
Lattice *lt = static_cast<Lattice *>(ob->data);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-14 02:32:32 +00:00
|
|
|
tot = lt->pntsu * lt->pntsv * lt->pntsw;
|
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
2018-09-05 16:17:59 +03:00
|
|
|
size = tot * sizeof(float[KEYELEM_FLOAT_LEN_COORD]);
|
2009-11-01 00:06:53 +00:00
|
|
|
}
|
2022-02-18 09:50:29 -06:00
|
|
|
else if (ELEM(ob->type, OB_CURVES_LEGACY, OB_SURF)) {
|
2022-12-02 12:34:26 +01:00
|
|
|
Curve *cu = static_cast<Curve *>(ob->data);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
2018-09-05 16:17:59 +03:00
|
|
|
tot = BKE_keyblock_curve_element_count(&cu->nurb);
|
|
|
|
|
size = tot * sizeof(float[KEYELEM_ELEM_SIZE_CURVE]);
|
2009-11-01 00:06:53 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-11-01 00:06:53 +00:00
|
|
|
/* if nothing to interpolate, cancel */
|
2019-04-22 09:39:35 +10:00
|
|
|
if (tot == 0 || size == 0) {
|
2022-12-02 12:34:26 +01:00
|
|
|
return nullptr;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-11-01 00:06:53 +00:00
|
|
|
/* allocate array */
|
2022-12-02 12:34:26 +01:00
|
|
|
if (arr == nullptr) {
|
|
|
|
|
out = static_cast<char *>(MEM_callocN(size, "BKE_key_evaluate_object out"));
|
2013-07-19 10:40:20 +00:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (arr_size != size) {
|
2022-12-02 12:34:26 +01:00
|
|
|
return nullptr;
|
2013-07-19 10:40:20 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-07-19 10:40:20 +00:00
|
|
|
out = (char *)arr;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (ob->shapeflag & OB_SHAPE_LOCK) {
|
2009-11-01 00:06:53 +00:00
|
|
|
/* shape locked, copy the locked shape instead of blending */
|
2022-12-02 12:34:26 +01:00
|
|
|
KeyBlock *kb = static_cast<KeyBlock *>(BLI_findlink(&key->block, ob->shapenr - 1));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (kb && (kb->flag & KEYBLOCK_MUTE)) {
|
2012-04-14 02:32:32 +00:00
|
|
|
kb = key->refkey;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-12-02 12:34:26 +01:00
|
|
|
if (kb == nullptr) {
|
|
|
|
|
kb = static_cast<KeyBlock *>(key->block.first);
|
2012-04-14 02:32:32 +00:00
|
|
|
ob->shapenr = 1;
|
2005-10-30 18:29:40 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-11-01 06:45:36 +00:00
|
|
|
if (OB_TYPE_SUPPORT_VGROUP(ob->type)) {
|
2022-12-02 12:34:26 +01:00
|
|
|
float *weights = get_weights_array(ob, kb->vgroup, nullptr);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-10-21 08:16:15 +00:00
|
|
|
cp_key(0, tot, tot, out, key, actkb, kb, weights, 0);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (weights) {
|
2012-03-24 06:18:31 +00:00
|
|
|
MEM_freeN(weights);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2005-09-26 15:34:21 +00:00
|
|
|
}
|
2022-02-18 09:50:29 -06:00
|
|
|
else if (ELEM(ob->type, OB_CURVES_LEGACY, OB_SURF)) {
|
2022-12-02 12:34:26 +01:00
|
|
|
cp_cu_key(static_cast<Curve *>(ob->data), key, actkb, kb, 0, tot, out, tot);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2005-09-26 15:34:21 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2019-04-22 09:39:35 +10:00
|
|
|
if (ob->type == OB_MESH) {
|
2015-01-07 02:02:55 +11:00
|
|
|
do_mesh_key(ob, key, out, tot);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
|
else if (ob->type == OB_LATTICE) {
|
2015-01-07 02:02:55 +11:00
|
|
|
do_latt_key(ob, key, out, tot);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2022-02-18 09:50:29 -06:00
|
|
|
else if (ob->type == OB_CURVES_LEGACY) {
|
2015-01-07 02:02:55 +11:00
|
|
|
do_curve_key(ob, key, out, tot);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
|
else if (ob->type == OB_SURF) {
|
2015-01-07 02:02:55 +11:00
|
|
|
do_curve_key(ob, key, out, tot);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2005-09-26 15:34:21 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-12-02 12:34:26 +01:00
|
|
|
if (obdata != nullptr) {
|
2022-07-20 10:45:23 +02:00
|
|
|
switch (GS(obdata->name)) {
|
|
|
|
|
case ID_ME: {
|
|
|
|
|
Mesh *mesh = (Mesh *)obdata;
|
|
|
|
|
const int totvert = min_ii(tot, mesh->totvert);
|
2023-02-21 10:38:21 -05:00
|
|
|
mesh->vert_positions_for_write().take_front(totvert).copy_from(
|
|
|
|
|
{reinterpret_cast<const blender::float3 *>(out), totvert});
|
2023-11-29 18:17:30 +01:00
|
|
|
BKE_mesh_tag_positions_changed(mesh);
|
2022-07-20 10:45:23 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case ID_LT: {
|
|
|
|
|
Lattice *lattice = (Lattice *)obdata;
|
|
|
|
|
const int totpoint = min_ii(tot, lattice->pntsu * lattice->pntsv * lattice->pntsw);
|
|
|
|
|
keyblock_data_convert_to_lattice((const float(*)[3])out, lattice->def, totpoint);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case ID_CU_LEGACY: {
|
|
|
|
|
Curve *curve = (Curve *)obdata;
|
|
|
|
|
const int totpoint = min_ii(tot, BKE_keyblock_curve_element_count(&curve->nurb));
|
|
|
|
|
keyblock_data_convert_to_curve((const float *)out, &curve->nurb, totpoint);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
BLI_assert_unreachable();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-03 06:47:44 +00:00
|
|
|
if (r_totelem) {
|
|
|
|
|
*r_totelem = tot;
|
|
|
|
|
}
|
2012-04-14 02:32:32 +00:00
|
|
|
return (float *)out;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
2015-01-07 02:02:55 +11:00
|
|
|
float *BKE_key_evaluate_object(Object *ob, int *r_totelem)
|
2013-07-19 10:40:20 +00:00
|
|
|
{
|
2022-12-02 12:34:26 +01:00
|
|
|
return BKE_key_evaluate_object_ex(ob, r_totelem, nullptr, 0, nullptr);
|
2013-07-19 10:40:20 +00:00
|
|
|
}
|
|
|
|
|
|
2020-07-25 16:35:52 +10:00
|
|
|
int BKE_keyblock_element_count_from_shape(const Key *key, const int shape_index)
|
|
|
|
|
{
|
|
|
|
|
int result = 0;
|
|
|
|
|
int index = 0;
|
2022-12-02 12:34:26 +01:00
|
|
|
for (const KeyBlock *kb = static_cast<const KeyBlock *>(key->block.first); kb;
|
|
|
|
|
kb = kb->next, index++)
|
|
|
|
|
{
|
2020-11-06 12:30:59 +11:00
|
|
|
if (ELEM(shape_index, -1, index)) {
|
2020-07-25 16:35:52 +10:00
|
|
|
result += kb->totelem;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int BKE_keyblock_element_count(const Key *key)
|
|
|
|
|
{
|
|
|
|
|
return BKE_keyblock_element_count_from_shape(key, -1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t BKE_keyblock_element_calc_size_from_shape(const Key *key, const int shape_index)
|
|
|
|
|
{
|
2023-01-03 11:04:16 +11:00
|
|
|
return size_t(BKE_keyblock_element_count_from_shape(key, shape_index)) * key->elemsize;
|
2020-07-25 16:35:52 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t BKE_keyblock_element_calc_size(const Key *key)
|
|
|
|
|
{
|
|
|
|
|
return BKE_keyblock_element_calc_size_from_shape(key, -1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Key-Block Data Access
|
|
|
|
|
*
|
|
|
|
|
* Utilities for getting/setting key data as a single array,
|
|
|
|
|
* use #BKE_keyblock_element_calc_size to allocate the size of the data needed.
|
|
|
|
|
* \{ */
|
|
|
|
|
|
|
|
|
|
void BKE_keyblock_data_get_from_shape(const Key *key, float (*arr)[3], const int shape_index)
|
|
|
|
|
{
|
|
|
|
|
uint8_t *elements = (uint8_t *)arr;
|
|
|
|
|
int index = 0;
|
2022-12-02 12:34:26 +01:00
|
|
|
for (const KeyBlock *kb = static_cast<const KeyBlock *>(key->block.first); kb;
|
|
|
|
|
kb = kb->next, index++)
|
|
|
|
|
{
|
2020-11-06 12:30:59 +11:00
|
|
|
if (ELEM(shape_index, -1, index)) {
|
2020-07-25 16:35:52 +10:00
|
|
|
const int block_elem_len = kb->totelem * key->elemsize;
|
|
|
|
|
memcpy(elements, kb->data, block_elem_len);
|
|
|
|
|
elements += block_elem_len;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BKE_keyblock_data_get(const Key *key, float (*arr)[3])
|
|
|
|
|
{
|
|
|
|
|
BKE_keyblock_data_get_from_shape(key, arr, -1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BKE_keyblock_data_set_with_mat4(Key *key,
|
|
|
|
|
const int shape_index,
|
|
|
|
|
const float (*coords)[3],
|
|
|
|
|
const float mat[4][4])
|
|
|
|
|
{
|
|
|
|
|
if (key->elemsize != sizeof(float[3])) {
|
2021-07-15 18:23:28 +10:00
|
|
|
BLI_assert_msg(0, "Invalid elemsize");
|
2020-07-25 16:35:52 +10:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const float(*elements)[3] = coords;
|
|
|
|
|
|
|
|
|
|
int index = 0;
|
2022-12-02 12:34:26 +01:00
|
|
|
for (KeyBlock *kb = static_cast<KeyBlock *>(key->block.first); kb; kb = kb->next, index++) {
|
2020-11-06 12:30:59 +11:00
|
|
|
if (ELEM(shape_index, -1, index)) {
|
2020-07-25 16:35:52 +10:00
|
|
|
const int block_elem_len = kb->totelem;
|
|
|
|
|
float(*block_data)[3] = (float(*)[3])kb->data;
|
|
|
|
|
for (int data_offset = 0; data_offset < block_elem_len; ++data_offset) {
|
|
|
|
|
const float *src_data = (const float *)(elements + data_offset);
|
|
|
|
|
float *dst_data = (float *)(block_data + data_offset);
|
|
|
|
|
mul_v3_m4v3(dst_data, mat, src_data);
|
|
|
|
|
}
|
|
|
|
|
elements += block_elem_len;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BKE_keyblock_curve_data_set_with_mat4(
|
|
|
|
|
Key *key, const ListBase *nurb, const int shape_index, const void *data, const float mat[4][4])
|
|
|
|
|
{
|
2022-12-02 12:34:26 +01:00
|
|
|
const uint8_t *elements = static_cast<const uint8_t *>(data);
|
2020-07-25 16:35:52 +10:00
|
|
|
|
|
|
|
|
int index = 0;
|
2022-12-02 12:34:26 +01:00
|
|
|
for (KeyBlock *kb = static_cast<KeyBlock *>(key->block.first); kb; kb = kb->next, index++) {
|
2020-11-06 12:30:59 +11:00
|
|
|
if (ELEM(shape_index, -1, index)) {
|
2020-07-25 16:35:52 +10:00
|
|
|
const int block_elem_size = kb->totelem * key->elemsize;
|
|
|
|
|
BKE_keyblock_curve_data_transform(nurb, mat, elements, kb->data);
|
|
|
|
|
elements += block_elem_size;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BKE_keyblock_data_set(Key *key, const int shape_index, const void *data)
|
|
|
|
|
{
|
2022-12-02 12:34:26 +01:00
|
|
|
const uint8_t *elements = static_cast<const uint8_t *>(data);
|
2020-07-25 16:35:52 +10:00
|
|
|
int index = 0;
|
2022-12-02 12:34:26 +01:00
|
|
|
for (KeyBlock *kb = static_cast<KeyBlock *>(key->block.first); kb; kb = kb->next, index++) {
|
2020-11-06 12:30:59 +11:00
|
|
|
if (ELEM(shape_index, -1, index)) {
|
2020-07-25 16:35:52 +10:00
|
|
|
const int block_elem_size = kb->totelem * key->elemsize;
|
|
|
|
|
memcpy(kb->data, elements, block_elem_size);
|
|
|
|
|
elements += block_elem_size;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** \} */
|
|
|
|
|
|
2019-01-25 17:37:19 +01:00
|
|
|
bool BKE_key_idtype_support(const short id_type)
|
|
|
|
|
{
|
|
|
|
|
switch (id_type) {
|
|
|
|
|
case ID_ME:
|
2022-02-18 09:50:29 -06:00
|
|
|
case ID_CU_LEGACY:
|
2019-01-25 17:37:19 +01:00
|
|
|
case ID_LT:
|
|
|
|
|
return true;
|
|
|
|
|
default:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-08 18:19:28 +11:00
|
|
|
Key **BKE_key_from_id_p(ID *id)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2015-10-08 18:19:28 +11:00
|
|
|
switch (GS(id->name)) {
|
|
|
|
|
case ID_ME: {
|
|
|
|
|
Mesh *me = (Mesh *)id;
|
|
|
|
|
return &me->key;
|
|
|
|
|
}
|
2022-02-18 09:50:29 -06:00
|
|
|
case ID_CU_LEGACY: {
|
2015-10-08 18:19:28 +11:00
|
|
|
Curve *cu = (Curve *)id;
|
2022-12-02 12:34:26 +01:00
|
|
|
if (cu->vfont == nullptr) {
|
2015-10-08 18:19:28 +11:00
|
|
|
return &cu->key;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case ID_LT: {
|
|
|
|
|
Lattice *lt = (Lattice *)id;
|
|
|
|
|
return <->key;
|
|
|
|
|
}
|
2017-08-28 11:19:58 +02:00
|
|
|
default:
|
|
|
|
|
break;
|
2005-09-26 15:34:21 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-12-02 12:34:26 +01:00
|
|
|
return nullptr;
|
2015-10-08 18:19:28 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Key *BKE_key_from_id(ID *id)
|
|
|
|
|
{
|
|
|
|
|
Key **key_p;
|
|
|
|
|
key_p = BKE_key_from_id_p(id);
|
|
|
|
|
if (key_p) {
|
|
|
|
|
return *key_p;
|
2005-09-26 15:34:21 +00:00
|
|
|
}
|
2015-10-08 18:19:28 +11:00
|
|
|
|
2022-12-02 12:34:26 +01:00
|
|
|
return nullptr;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2005-07-15 17:55:19 +00:00
|
|
|
|
2022-04-28 10:53:50 -05:00
|
|
|
Key **BKE_key_from_object_p(Object *ob)
|
2015-10-08 18:19:28 +11:00
|
|
|
{
|
2022-12-02 12:34:26 +01:00
|
|
|
if (ob == nullptr || ob->data == nullptr) {
|
|
|
|
|
return nullptr;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2015-10-08 18:19:28 +11:00
|
|
|
|
2022-12-02 12:34:26 +01:00
|
|
|
return BKE_key_from_id_p(static_cast<ID *>(ob->data));
|
2015-10-08 18:19:28 +11:00
|
|
|
}
|
|
|
|
|
|
2022-04-28 10:53:50 -05:00
|
|
|
Key *BKE_key_from_object(Object *ob)
|
2015-06-08 19:49:01 +10:00
|
|
|
{
|
|
|
|
|
Key **key_p;
|
|
|
|
|
key_p = BKE_key_from_object_p(ob);
|
|
|
|
|
if (key_p) {
|
|
|
|
|
return *key_p;
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-02 12:34:26 +01:00
|
|
|
return nullptr;
|
2015-06-08 19:49:01 +10:00
|
|
|
}
|
|
|
|
|
|
2012-09-19 10:12:07 +00:00
|
|
|
KeyBlock *BKE_keyblock_add(Key *key, const char *name)
|
2009-11-22 13:44:09 +00:00
|
|
|
{
|
|
|
|
|
KeyBlock *kb;
|
2012-04-14 02:32:32 +00:00
|
|
|
float curpos = -0.1;
|
2009-11-22 13:44:09 +00:00
|
|
|
int tot;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-12-02 12:34:26 +01:00
|
|
|
kb = static_cast<KeyBlock *>(key->block.last);
|
2019-04-22 09:39:35 +10:00
|
|
|
if (kb) {
|
2012-04-14 02:32:32 +00:00
|
|
|
curpos = kb->pos;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-12-02 12:34:26 +01:00
|
|
|
kb = MEM_cnew<KeyBlock>("Keyblock");
|
2009-11-22 13:44:09 +00:00
|
|
|
BLI_addtail(&key->block, kb);
|
2018-07-30 12:22:18 +02:00
|
|
|
kb->type = KEY_LINEAR;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-11-16 13:57:58 +01:00
|
|
|
tot = BLI_listbase_count(&key->block);
|
2012-03-24 06:18:31 +00:00
|
|
|
if (name) {
|
2023-05-09 12:50:37 +10:00
|
|
|
STRNCPY(kb->name, name);
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2019-04-22 09:39:35 +10:00
|
|
|
if (tot == 1) {
|
2023-05-13 17:38:48 +10:00
|
|
|
STRNCPY_UTF8(kb->name, DATA_("Basis"));
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2023-05-09 12:50:37 +10:00
|
|
|
SNPRINTF(kb->name, DATA_("Key %d"), tot - 1);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2009-12-28 18:03:04 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-25 08:29:06 +00:00
|
|
|
BLI_uniquename(&key->block, kb, DATA_("Key"), '.', offsetof(KeyBlock, name), sizeof(kb->name));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-11-29 00:53:23 +00:00
|
|
|
kb->uid = key->uidgen++;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-11-22 13:44:09 +00:00
|
|
|
key->totkey++;
|
2019-04-22 09:39:35 +10:00
|
|
|
if (key->totkey == 1) {
|
2012-04-14 02:32:32 +00:00
|
|
|
key->refkey = kb;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-14 02:32:32 +00:00
|
|
|
kb->slidermin = 0.0f;
|
|
|
|
|
kb->slidermax = 1.0f;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-05-27 15:10:58 +10:00
|
|
|
/* \note caller may want to set this to current time, but don't do it here since we need to sort
|
|
|
|
|
* which could cause problems in some cases, see #BKE_keyblock_add_ctime. */
|
2012-04-12 11:05:16 +00:00
|
|
|
kb->pos = curpos + 0.1f; /* only used for absolute shape keys */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-12 11:05:16 +00:00
|
|
|
return kb;
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-03 18:55:59 +11:00
|
|
|
KeyBlock *BKE_keyblock_add_ctime(Key *key, const char *name, const bool do_force)
|
2012-04-12 11:05:16 +00:00
|
|
|
{
|
2012-09-19 10:12:07 +00:00
|
|
|
KeyBlock *kb = BKE_keyblock_add(key, name);
|
Fix T39897: shape keys created while the Relative checkbox is unchecked start out with frame=0
So! First, frame for absolute shape keys: never allow a new key to have the same pos as an
existing one (this does not make sense). This way, the two workflows are possible (create
all keys and then animate ctime, or animate ctime and then create keys where you need them).
Also, fixed UIList for shapekeys, the "absolute" test was wrong, and better to show frame
value, even though not editable, than nothing in case of absolute keys.
And finally, add getter to RNA 'frame' readonly value, so that we output real frame values,
and not dummy internal ones (which are /100) in our API.
2014-05-18 22:05:21 +02:00
|
|
|
const float cpos = key->ctime / 100.0f;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Fix T39897: shape keys created while the Relative checkbox is unchecked start out with frame=0
So! First, frame for absolute shape keys: never allow a new key to have the same pos as an
existing one (this does not make sense). This way, the two workflows are possible (create
all keys and then animate ctime, or animate ctime and then create keys where you need them).
Also, fixed UIList for shapekeys, the "absolute" test was wrong, and better to show frame
value, even though not editable, than nothing in case of absolute keys.
And finally, add getter to RNA 'frame' readonly value, so that we output real frame values,
and not dummy internal ones (which are /100) in our API.
2014-05-18 22:05:21 +02:00
|
|
|
/* In case of absolute keys, there is no point in adding more than one key with the same pos.
|
2022-12-13 12:34:32 +11:00
|
|
|
* Hence only set new key-block pos to current time if none previous one already use it.
|
Fix T39897: shape keys created while the Relative checkbox is unchecked start out with frame=0
So! First, frame for absolute shape keys: never allow a new key to have the same pos as an
existing one (this does not make sense). This way, the two workflows are possible (create
all keys and then animate ctime, or animate ctime and then create keys where you need them).
Also, fixed UIList for shapekeys, the "absolute" test was wrong, and better to show frame
value, even though not editable, than nothing in case of absolute keys.
And finally, add getter to RNA 'frame' readonly value, so that we output real frame values,
and not dummy internal ones (which are /100) in our API.
2014-05-18 22:05:21 +02:00
|
|
|
* Now at least people just adding absolute keys without touching to ctime
|
2023-02-12 14:37:16 +11:00
|
|
|
* won't have to systematically use retiming func (and have ordering issues, too). See #39897.
|
Fix T39897: shape keys created while the Relative checkbox is unchecked start out with frame=0
So! First, frame for absolute shape keys: never allow a new key to have the same pos as an
existing one (this does not make sense). This way, the two workflows are possible (create
all keys and then animate ctime, or animate ctime and then create keys where you need them).
Also, fixed UIList for shapekeys, the "absolute" test was wrong, and better to show frame
value, even though not editable, than nothing in case of absolute keys.
And finally, add getter to RNA 'frame' readonly value, so that we output real frame values,
and not dummy internal ones (which are /100) in our API.
2014-05-18 22:05:21 +02:00
|
|
|
*/
|
|
|
|
|
if (!do_force && (key->type != KEY_RELATIVE)) {
|
2023-08-04 08:51:13 +10:00
|
|
|
LISTBASE_FOREACH (KeyBlock *, it_kb, &key->block) {
|
2019-04-08 23:54:37 +02:00
|
|
|
/* Use epsilon to avoid floating point precision issues.
|
|
|
|
|
* 1e-3 because the position is stored as frame * 1e-2. */
|
|
|
|
|
if (compare_ff(it_kb->pos, cpos, 1e-3f)) {
|
Fix T39897: shape keys created while the Relative checkbox is unchecked start out with frame=0
So! First, frame for absolute shape keys: never allow a new key to have the same pos as an
existing one (this does not make sense). This way, the two workflows are possible (create
all keys and then animate ctime, or animate ctime and then create keys where you need them).
Also, fixed UIList for shapekeys, the "absolute" test was wrong, and better to show frame
value, even though not editable, than nothing in case of absolute keys.
And finally, add getter to RNA 'frame' readonly value, so that we output real frame values,
and not dummy internal ones (which are /100) in our API.
2014-05-18 22:05:21 +02:00
|
|
|
return kb;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-04-12 11:05:16 +00:00
|
|
|
if (do_force || (key->type != KEY_RELATIVE)) {
|
Fix T39897: shape keys created while the Relative checkbox is unchecked start out with frame=0
So! First, frame for absolute shape keys: never allow a new key to have the same pos as an
existing one (this does not make sense). This way, the two workflows are possible (create
all keys and then animate ctime, or animate ctime and then create keys where you need them).
Also, fixed UIList for shapekeys, the "absolute" test was wrong, and better to show frame
value, even though not editable, than nothing in case of absolute keys.
And finally, add getter to RNA 'frame' readonly value, so that we output real frame values,
and not dummy internal ones (which are /100) in our API.
2014-05-18 22:05:21 +02:00
|
|
|
kb->pos = cpos;
|
2012-09-19 10:12:07 +00:00
|
|
|
BKE_key_sort(key);
|
2009-11-22 13:44:09 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-11-22 13:44:09 +00:00
|
|
|
return kb;
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-17 17:05:51 +02:00
|
|
|
KeyBlock *BKE_keyblock_from_object(Object *ob)
|
2005-07-15 17:55:19 +00:00
|
|
|
{
|
2012-09-19 10:12:07 +00:00
|
|
|
Key *key = BKE_key_from_object(ob);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2005-09-26 15:34:21 +00:00
|
|
|
if (key) {
|
2022-12-02 12:34:26 +01:00
|
|
|
KeyBlock *kb = static_cast<KeyBlock *>(BLI_findlink(&key->block, ob->shapenr - 1));
|
2005-09-26 15:34:21 +00:00
|
|
|
return kb;
|
2005-07-15 17:55:19 +00:00
|
|
|
}
|
|
|
|
|
|
2022-12-02 12:34:26 +01:00
|
|
|
return nullptr;
|
2005-07-15 17:55:19 +00:00
|
|
|
}
|
2007-08-22 10:07:42 +00:00
|
|
|
|
2012-09-19 10:12:07 +00:00
|
|
|
KeyBlock *BKE_keyblock_from_object_reference(Object *ob)
|
2009-11-11 18:31:19 +00:00
|
|
|
{
|
2012-09-19 10:12:07 +00:00
|
|
|
Key *key = BKE_key_from_object(ob);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (key) {
|
2009-11-11 18:31:19 +00:00
|
|
|
return key->refkey;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2009-11-11 18:31:19 +00:00
|
|
|
|
2022-12-02 12:34:26 +01:00
|
|
|
return nullptr;
|
2009-11-11 18:31:19 +00:00
|
|
|
}
|
|
|
|
|
|
2012-09-19 10:12:07 +00:00
|
|
|
KeyBlock *BKE_keyblock_from_key(Key *key, int index)
|
2007-08-22 10:07:42 +00:00
|
|
|
{
|
|
|
|
|
if (key) {
|
2022-12-02 12:34:26 +01:00
|
|
|
KeyBlock *kb = static_cast<KeyBlock *>(key->block.first);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2020-09-09 16:35:20 +02:00
|
|
|
for (int i = 1; i < key->totkey; i++) {
|
2012-04-14 02:32:32 +00:00
|
|
|
kb = kb->next;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (index == i) {
|
2007-08-22 10:07:42 +00:00
|
|
|
return kb;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2007-08-22 10:07:42 +00:00
|
|
|
}
|
|
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2022-12-02 12:34:26 +01:00
|
|
|
return nullptr;
|
2007-08-22 10:07:42 +00:00
|
|
|
}
|
2008-12-19 11:45:46 +00:00
|
|
|
|
2012-09-19 10:12:07 +00:00
|
|
|
KeyBlock *BKE_keyblock_find_name(Key *key, const char name[])
|
2008-12-19 11:45:46 +00:00
|
|
|
{
|
2022-12-02 12:34:26 +01:00
|
|
|
return static_cast<KeyBlock *>(BLI_findstring(&key->block, name, offsetof(KeyBlock, name)));
|
2012-09-19 12:11:28 +00:00
|
|
|
}
|
|
|
|
|
|
2022-09-09 08:24:31 -05:00
|
|
|
KeyBlock *BKE_keyblock_find_uid(Key *key, const int uid)
|
|
|
|
|
{
|
|
|
|
|
LISTBASE_FOREACH (KeyBlock *, kb, &key->block) {
|
|
|
|
|
if (kb->uid == uid) {
|
|
|
|
|
return kb;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-12-02 12:34:26 +01:00
|
|
|
return nullptr;
|
2022-09-09 08:24:31 -05:00
|
|
|
}
|
|
|
|
|
|
2012-09-19 12:11:28 +00:00
|
|
|
void BKE_keyblock_copy_settings(KeyBlock *kb_dst, const KeyBlock *kb_src)
|
|
|
|
|
{
|
|
|
|
|
kb_dst->pos = kb_src->pos;
|
|
|
|
|
kb_dst->curval = kb_src->curval;
|
|
|
|
|
kb_dst->type = kb_src->type;
|
|
|
|
|
kb_dst->relative = kb_src->relative;
|
2023-05-09 12:50:37 +10:00
|
|
|
STRNCPY(kb_dst->vgroup, kb_src->vgroup);
|
2012-09-19 12:11:28 +00:00
|
|
|
kb_dst->slidermin = kb_src->slidermin;
|
|
|
|
|
kb_dst->slidermax = kb_src->slidermax;
|
2008-12-19 11:45:46 +00:00
|
|
|
}
|
2009-11-01 00:06:53 +00:00
|
|
|
|
2022-04-28 09:10:37 -05:00
|
|
|
char *BKE_keyblock_curval_rnapath_get(const Key *key, const KeyBlock *kb)
|
2009-11-01 00:06:53 +00:00
|
|
|
{
|
|
|
|
|
PropertyRNA *prop;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2009-11-01 00:06:53 +00:00
|
|
|
/* sanity checks */
|
2022-12-02 12:34:26 +01:00
|
|
|
if (ELEM(nullptr, key, kb)) {
|
|
|
|
|
return nullptr;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2009-11-01 00:06:53 +00:00
|
|
|
/* create the RNA pointer */
|
2023-09-06 00:48:50 +02:00
|
|
|
PointerRNA ptr = RNA_pointer_create((ID *)&key->id, &RNA_ShapeKey, (KeyBlock *)kb);
|
2009-11-01 00:06:53 +00:00
|
|
|
/* get pointer to the property too */
|
2012-04-14 02:32:32 +00:00
|
|
|
prop = RNA_struct_find_property(&ptr, "value");
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2009-11-01 00:06:53 +00:00
|
|
|
/* return the path */
|
|
|
|
|
return RNA_path_from_ID_to_property(&ptr, prop);
|
|
|
|
|
}
|
2009-12-28 15:26:36 +00:00
|
|
|
|
|
|
|
|
/* conversion functions */
|
|
|
|
|
|
|
|
|
|
/************************* Lattice ************************/
|
2021-12-07 17:19:15 +11:00
|
|
|
|
2022-04-28 09:10:37 -05:00
|
|
|
void BKE_keyblock_update_from_lattice(const Lattice *lt, KeyBlock *kb)
|
2009-12-28 15:26:36 +00:00
|
|
|
{
|
|
|
|
|
BPoint *bp;
|
2014-11-17 10:46:31 +01:00
|
|
|
float(*fp)[3];
|
2009-12-28 15:26:36 +00:00
|
|
|
int a, tot;
|
|
|
|
|
|
2014-11-16 18:50:23 +01:00
|
|
|
BLI_assert(kb->totelem == lt->pntsu * lt->pntsv * lt->pntsw);
|
2009-12-28 15:26:36 +00:00
|
|
|
|
2014-11-16 18:50:23 +01:00
|
|
|
tot = kb->totelem;
|
2019-04-22 09:39:35 +10:00
|
|
|
if (tot == 0) {
|
2014-11-16 18:50:23 +01:00
|
|
|
return;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2009-12-28 15:26:36 +00:00
|
|
|
|
2012-04-14 02:32:32 +00:00
|
|
|
bp = lt->def;
|
2022-12-02 12:34:26 +01:00
|
|
|
fp = static_cast<float(*)[3]>(kb->data);
|
2014-11-17 10:46:31 +01:00
|
|
|
for (a = 0; a < kb->totelem; a++, fp++, bp++) {
|
|
|
|
|
copy_v3_v3(*fp, bp->vec);
|
2009-12-28 15:26:36 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-28 09:10:37 -05:00
|
|
|
void BKE_keyblock_convert_from_lattice(const Lattice *lt, KeyBlock *kb)
|
2014-11-16 18:50:23 +01:00
|
|
|
{
|
|
|
|
|
int tot;
|
|
|
|
|
|
|
|
|
|
tot = lt->pntsu * lt->pntsv * lt->pntsw;
|
2019-04-22 09:39:35 +10:00
|
|
|
if (tot == 0) {
|
2014-11-16 18:50:23 +01:00
|
|
|
return;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2014-11-16 18:50:23 +01:00
|
|
|
|
|
|
|
|
MEM_SAFE_FREE(kb->data);
|
|
|
|
|
|
|
|
|
|
kb->data = MEM_mallocN(lt->key->elemsize * tot, __func__);
|
|
|
|
|
kb->totelem = tot;
|
|
|
|
|
|
2014-11-16 19:15:23 +01:00
|
|
|
BKE_keyblock_update_from_lattice(lt, kb);
|
2014-11-16 18:50:23 +01:00
|
|
|
}
|
|
|
|
|
|
2022-07-20 10:45:23 +02:00
|
|
|
static void keyblock_data_convert_to_lattice(const float (*fp)[3],
|
|
|
|
|
BPoint *bpoint,
|
|
|
|
|
const int totpoint)
|
2009-12-28 15:26:36 +00:00
|
|
|
{
|
2022-07-20 10:45:23 +02:00
|
|
|
for (int i = 0; i < totpoint; i++, fp++, bpoint++) {
|
|
|
|
|
copy_v3_v3(bpoint->vec, *fp);
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-12-28 15:26:36 +00:00
|
|
|
|
2022-07-20 10:45:23 +02:00
|
|
|
void BKE_keyblock_convert_to_lattice(const KeyBlock *kb, Lattice *lt)
|
|
|
|
|
{
|
|
|
|
|
BPoint *bp = lt->def;
|
2022-12-02 12:34:26 +01:00
|
|
|
const float(*fp)[3] = static_cast<const float(*)[3]>(kb->data);
|
2022-07-20 10:45:23 +02:00
|
|
|
const int tot = min_ii(kb->totelem, lt->pntsu * lt->pntsv * lt->pntsw);
|
2009-12-28 15:26:36 +00:00
|
|
|
|
2022-07-20 10:45:23 +02:00
|
|
|
keyblock_data_convert_to_lattice(fp, bp, tot);
|
2009-12-28 15:26:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/************************* Curve ************************/
|
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
2018-09-05 16:17:59 +03:00
|
|
|
|
2021-06-30 16:37:14 +10:00
|
|
|
int BKE_keyblock_curve_element_count(const ListBase *nurb)
|
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
2018-09-05 16:17:59 +03:00
|
|
|
{
|
2021-06-30 16:37:14 +10:00
|
|
|
const Nurb *nu;
|
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
2018-09-05 16:17:59 +03:00
|
|
|
int tot = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-12-02 12:34:26 +01:00
|
|
|
nu = static_cast<const Nurb *>(nurb->first);
|
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
2018-09-05 16:17:59 +03:00
|
|
|
while (nu) {
|
2019-04-22 09:39:35 +10:00
|
|
|
if (nu->bezt) {
|
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
2018-09-05 16:17:59 +03:00
|
|
|
tot += KEYELEM_ELEM_LEN_BEZTRIPLE * nu->pntsu;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
|
else if (nu->bp) {
|
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
2018-09-05 16:17:59 +03:00
|
|
|
tot += KEYELEM_ELEM_LEN_BPOINT * nu->pntsu * nu->pntsv;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
2018-09-05 16:17:59 +03:00
|
|
|
nu = nu->next;
|
|
|
|
|
}
|
|
|
|
|
return tot;
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-20 15:51:47 -03:00
|
|
|
void BKE_keyblock_update_from_curve(const Curve * /*cu*/, KeyBlock *kb, const ListBase *nurb)
|
2009-12-28 15:26:36 +00:00
|
|
|
{
|
|
|
|
|
BezTriple *bezt;
|
|
|
|
|
BPoint *bp;
|
|
|
|
|
float *fp;
|
|
|
|
|
int a, tot;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2009-12-28 15:26:36 +00:00
|
|
|
/* count */
|
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
2018-09-05 16:17:59 +03:00
|
|
|
BLI_assert(BKE_keyblock_curve_element_count(nurb) == kb->totelem);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-11-16 18:50:23 +01:00
|
|
|
tot = kb->totelem;
|
2019-04-22 09:39:35 +10:00
|
|
|
if (tot == 0) {
|
2014-11-16 18:50:23 +01:00
|
|
|
return;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-12-02 12:34:26 +01:00
|
|
|
fp = static_cast<float *>(kb->data);
|
2023-08-04 08:51:13 +10:00
|
|
|
LISTBASE_FOREACH (Nurb *, nu, nurb) {
|
2012-03-24 06:18:31 +00:00
|
|
|
if (nu->bezt) {
|
2014-11-17 10:46:31 +01:00
|
|
|
for (a = nu->pntsu, bezt = nu->bezt; a; a--, bezt++) {
|
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
2018-09-05 16:17:59 +03:00
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
|
copy_v3_v3(&fp[i * 3], bezt->vec[i]);
|
2014-11-17 10:46:31 +01:00
|
|
|
}
|
2019-03-04 01:14:27 +11:00
|
|
|
fp[9] = bezt->tilt;
|
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
2018-09-05 16:17:59 +03:00
|
|
|
fp[10] = bezt->radius;
|
|
|
|
|
fp += KEYELEM_FLOAT_LEN_BEZTRIPLE;
|
2009-12-28 15:26:36 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
2018-09-05 16:17:59 +03:00
|
|
|
for (a = nu->pntsu * nu->pntsv, bp = nu->bp; a; a--, bp++) {
|
2011-10-28 12:40:15 +00:00
|
|
|
copy_v3_v3(fp, bp->vec);
|
2019-03-04 01:14:27 +11:00
|
|
|
fp[3] = bp->tilt;
|
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
2018-09-05 16:17:59 +03:00
|
|
|
fp[4] = bp->radius;
|
|
|
|
|
fp += KEYELEM_FLOAT_LEN_BPOINT;
|
2009-12-28 15:26:36 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-25 16:35:52 +10:00
|
|
|
void BKE_keyblock_curve_data_transform(const ListBase *nurb,
|
|
|
|
|
const float mat[4][4],
|
|
|
|
|
const void *src_data,
|
|
|
|
|
void *dst_data)
|
|
|
|
|
{
|
2022-12-02 12:34:26 +01:00
|
|
|
const float *src = static_cast<const float *>(src_data);
|
|
|
|
|
float *dst = static_cast<float *>(dst_data);
|
2023-08-04 08:51:13 +10:00
|
|
|
LISTBASE_FOREACH (Nurb *, nu, nurb) {
|
2020-07-25 16:35:52 +10:00
|
|
|
if (nu->bezt) {
|
|
|
|
|
for (int a = nu->pntsu; a; a--) {
|
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
|
mul_v3_m4v3(&dst[i * 3], mat, &src[i * 3]);
|
|
|
|
|
}
|
|
|
|
|
dst[9] = src[9];
|
|
|
|
|
dst[10] = src[10];
|
|
|
|
|
src += KEYELEM_FLOAT_LEN_BEZTRIPLE;
|
|
|
|
|
dst += KEYELEM_FLOAT_LEN_BEZTRIPLE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
for (int a = nu->pntsu * nu->pntsv; a; a--) {
|
|
|
|
|
mul_v3_m4v3(dst, mat, src);
|
|
|
|
|
dst[3] = src[3];
|
|
|
|
|
dst[4] = src[4];
|
|
|
|
|
src += KEYELEM_FLOAT_LEN_BPOINT;
|
|
|
|
|
dst += KEYELEM_FLOAT_LEN_BPOINT;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-28 09:10:37 -05:00
|
|
|
void BKE_keyblock_convert_from_curve(const Curve *cu, KeyBlock *kb, const ListBase *nurb)
|
2014-11-16 18:50:23 +01:00
|
|
|
{
|
|
|
|
|
int tot;
|
|
|
|
|
|
|
|
|
|
/* count */
|
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
2018-09-05 16:17:59 +03:00
|
|
|
tot = BKE_keyblock_curve_element_count(nurb);
|
2019-04-22 09:39:35 +10:00
|
|
|
if (tot == 0) {
|
2014-11-16 18:50:23 +01:00
|
|
|
return;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2014-11-16 18:50:23 +01:00
|
|
|
|
|
|
|
|
MEM_SAFE_FREE(kb->data);
|
|
|
|
|
|
|
|
|
|
kb->data = MEM_mallocN(cu->key->elemsize * tot, __func__);
|
|
|
|
|
kb->totelem = tot;
|
|
|
|
|
|
2014-11-16 19:15:23 +01:00
|
|
|
BKE_keyblock_update_from_curve(cu, kb, nurb);
|
2014-11-16 18:50:23 +01:00
|
|
|
}
|
|
|
|
|
|
2022-07-20 10:45:23 +02:00
|
|
|
static void keyblock_data_convert_to_curve(const float *fp, ListBase *nurb, int totpoint)
|
2009-12-28 15:26:36 +00:00
|
|
|
{
|
2022-12-02 12:34:26 +01:00
|
|
|
for (Nurb *nu = static_cast<Nurb *>(nurb->first); nu && totpoint > 0; nu = nu->next) {
|
|
|
|
|
if (nu->bezt != nullptr) {
|
2022-07-20 10:45:23 +02:00
|
|
|
BezTriple *bezt = nu->bezt;
|
|
|
|
|
for (int i = nu->pntsu; i && (totpoint -= KEYELEM_ELEM_LEN_BEZTRIPLE) >= 0;
|
|
|
|
|
i--, bezt++, fp += KEYELEM_FLOAT_LEN_BEZTRIPLE)
|
|
|
|
|
{
|
|
|
|
|
for (int j = 0; j < 3; j++) {
|
|
|
|
|
copy_v3_v3(bezt->vec[j], &fp[j * 3]);
|
2014-11-17 10:46:31 +01:00
|
|
|
}
|
2019-03-04 01:14:27 +11:00
|
|
|
bezt->tilt = fp[9];
|
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
2018-09-05 16:17:59 +03:00
|
|
|
bezt->radius = fp[10];
|
2009-12-28 15:26:36 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
2022-07-20 10:45:23 +02:00
|
|
|
BPoint *bp = nu->bp;
|
|
|
|
|
for (int i = nu->pntsu * nu->pntsv; i && (totpoint -= KEYELEM_ELEM_LEN_BPOINT) >= 0;
|
|
|
|
|
i--, bp++, fp += KEYELEM_FLOAT_LEN_BPOINT)
|
|
|
|
|
{
|
2011-10-28 12:40:15 +00:00
|
|
|
copy_v3_v3(bp->vec, fp);
|
2019-03-04 01:14:27 +11:00
|
|
|
bp->tilt = fp[3];
|
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
2018-09-05 16:17:59 +03:00
|
|
|
bp->radius = fp[4];
|
2009-12-28 15:26:36 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-20 15:51:47 -03:00
|
|
|
void BKE_keyblock_convert_to_curve(KeyBlock *kb, Curve * /*cu*/, ListBase *nurb)
|
2022-07-20 10:45:23 +02:00
|
|
|
{
|
2022-12-02 12:34:26 +01:00
|
|
|
const float *fp = static_cast<const float *>(kb->data);
|
2022-07-20 10:45:23 +02:00
|
|
|
const int tot = min_ii(kb->totelem, BKE_keyblock_curve_element_count(nurb));
|
|
|
|
|
|
|
|
|
|
keyblock_data_convert_to_curve(fp, nurb, tot);
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-28 15:26:36 +00:00
|
|
|
/************************* Mesh ************************/
|
2021-12-07 17:19:15 +11:00
|
|
|
|
2022-04-28 09:10:37 -05:00
|
|
|
void BKE_keyblock_update_from_mesh(const Mesh *me, KeyBlock *kb)
|
2009-12-28 15:26:36 +00:00
|
|
|
{
|
2014-11-16 18:50:23 +01:00
|
|
|
BLI_assert(me->totvert == kb->totelem);
|
2009-12-28 15:26:36 +00:00
|
|
|
|
Mesh: Move positions to a generic attribute
**Changes**
As described in T93602, this patch removes all use of the `MVert`
struct, replacing it with a generic named attribute with the name
`"position"`, consistent with other geometry types.
Variable names have been changed from `verts` to `positions`, to align
with the attribute name and the more generic design (positions are not
vertices, they are just an attribute stored on the point domain).
This change is made possible by previous commits that moved all other
data out of `MVert` to runtime data or other generic attributes. What
remains is mostly a simple type change. Though, the type still shows up
859 times, so the patch is quite large.
One compromise is that now `CD_MASK_BAREMESH` now contains
`CD_PROP_FLOAT3`. With the general move towards generic attributes
over custom data types, we are removing use of these type masks anyway.
**Benefits**
The most obvious benefit is reduced memory usage and the benefits
that brings in memory-bound situations. `float3` is only 3 bytes, in
comparison to `MVert` which was 4. When there are millions of vertices
this starts to matter more.
The other benefits come from using a more generic type. Instead of
writing algorithms specifically for `MVert`, code can just use arrays
of vectors. This will allow eliminating many temporary arrays or
wrappers used to extract positions.
Many possible improvements aren't implemented in this patch, though
I did switch simplify or remove the process of creating temporary
position arrays in a few places.
The design clarity that "positions are just another attribute" brings
allows removing explicit copying of vertices in some procedural
operations-- they are just processed like most other attributes.
**Performance**
This touches so many areas that it's hard to benchmark exhaustively,
but I observed some areas as examples.
* The mesh line node with 4 million count was 1.5x (8ms to 12ms) faster.
* The Spring splash screen went from ~4.3 to ~4.5 fps.
* The subdivision surface modifier/node was slightly faster
RNA access through Python may be slightly slower, since now we need
a name lookup instead of just a custom data type lookup for each index.
**Future Improvements**
* Remove uses of "vert_coords" functions:
* `BKE_mesh_vert_coords_alloc`
* `BKE_mesh_vert_coords_get`
* `BKE_mesh_vert_coords_apply{_with_mat4}`
* Remove more hidden copying of positions
* General simplification now possible in many areas
* Convert more code to C++ to use `float3` instead of `float[3]`
* Currently `reinterpret_cast` is used for those C-API functions
Differential Revision: https://developer.blender.org/D15982
2023-01-10 00:10:43 -05:00
|
|
|
const int tot = me->totvert;
|
2019-04-22 09:39:35 +10:00
|
|
|
if (tot == 0) {
|
2014-11-16 18:50:23 +01:00
|
|
|
return;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2009-12-28 15:26:36 +00:00
|
|
|
|
2023-06-14 11:59:32 -04:00
|
|
|
const blender::Span<blender::float3> positions = me->vert_positions();
|
|
|
|
|
memcpy(kb->data, positions.data(), sizeof(float[3]) * tot);
|
2009-12-28 15:26:36 +00:00
|
|
|
}
|
|
|
|
|
|
2022-04-28 09:10:37 -05:00
|
|
|
void BKE_keyblock_convert_from_mesh(const Mesh *me, const Key *key, KeyBlock *kb)
|
2014-11-16 18:50:23 +01:00
|
|
|
{
|
2018-06-21 18:24:32 +02:00
|
|
|
const int len = me->totvert;
|
2014-11-16 18:50:23 +01:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (me->totvert == 0) {
|
2014-11-16 18:50:23 +01:00
|
|
|
return;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2014-11-16 18:50:23 +01:00
|
|
|
|
|
|
|
|
MEM_SAFE_FREE(kb->data);
|
|
|
|
|
|
2022-12-08 13:04:50 +11:00
|
|
|
kb->data = MEM_malloc_arrayN(size_t(len), size_t(key->elemsize), __func__);
|
2018-06-21 18:24:32 +02:00
|
|
|
kb->totelem = len;
|
2014-11-16 18:50:23 +01:00
|
|
|
|
2014-11-16 19:15:23 +01:00
|
|
|
BKE_keyblock_update_from_mesh(me, kb);
|
2014-11-16 18:50:23 +01:00
|
|
|
}
|
|
|
|
|
|
Mesh: Move positions to a generic attribute
**Changes**
As described in T93602, this patch removes all use of the `MVert`
struct, replacing it with a generic named attribute with the name
`"position"`, consistent with other geometry types.
Variable names have been changed from `verts` to `positions`, to align
with the attribute name and the more generic design (positions are not
vertices, they are just an attribute stored on the point domain).
This change is made possible by previous commits that moved all other
data out of `MVert` to runtime data or other generic attributes. What
remains is mostly a simple type change. Though, the type still shows up
859 times, so the patch is quite large.
One compromise is that now `CD_MASK_BAREMESH` now contains
`CD_PROP_FLOAT3`. With the general move towards generic attributes
over custom data types, we are removing use of these type masks anyway.
**Benefits**
The most obvious benefit is reduced memory usage and the benefits
that brings in memory-bound situations. `float3` is only 3 bytes, in
comparison to `MVert` which was 4. When there are millions of vertices
this starts to matter more.
The other benefits come from using a more generic type. Instead of
writing algorithms specifically for `MVert`, code can just use arrays
of vectors. This will allow eliminating many temporary arrays or
wrappers used to extract positions.
Many possible improvements aren't implemented in this patch, though
I did switch simplify or remove the process of creating temporary
position arrays in a few places.
The design clarity that "positions are just another attribute" brings
allows removing explicit copying of vertices in some procedural
operations-- they are just processed like most other attributes.
**Performance**
This touches so many areas that it's hard to benchmark exhaustively,
but I observed some areas as examples.
* The mesh line node with 4 million count was 1.5x (8ms to 12ms) faster.
* The Spring splash screen went from ~4.3 to ~4.5 fps.
* The subdivision surface modifier/node was slightly faster
RNA access through Python may be slightly slower, since now we need
a name lookup instead of just a custom data type lookup for each index.
**Future Improvements**
* Remove uses of "vert_coords" functions:
* `BKE_mesh_vert_coords_alloc`
* `BKE_mesh_vert_coords_get`
* `BKE_mesh_vert_coords_apply{_with_mat4}`
* Remove more hidden copying of positions
* General simplification now possible in many areas
* Convert more code to C++ to use `float3` instead of `float[3]`
* Currently `reinterpret_cast` is used for those C-API functions
Differential Revision: https://developer.blender.org/D15982
2023-01-10 00:10:43 -05:00
|
|
|
void BKE_keyblock_convert_to_mesh(const KeyBlock *kb,
|
|
|
|
|
float (*vert_positions)[3],
|
|
|
|
|
const int totvert)
|
2009-12-28 15:26:36 +00:00
|
|
|
{
|
2022-07-20 10:45:23 +02:00
|
|
|
const int tot = min_ii(kb->totelem, totvert);
|
2023-01-17 10:20:16 -06:00
|
|
|
memcpy(vert_positions, kb->data, sizeof(float[3]) * tot);
|
2022-07-20 10:45:23 +02:00
|
|
|
}
|
|
|
|
|
|
2022-04-28 09:10:37 -05:00
|
|
|
void BKE_keyblock_mesh_calc_normals(const KeyBlock *kb,
|
2023-01-13 17:21:20 -06:00
|
|
|
Mesh *mesh,
|
2022-12-17 12:47:43 +11:00
|
|
|
float (*r_vert_normals)[3],
|
2023-07-24 22:06:55 +02:00
|
|
|
float (*r_face_normals)[3],
|
2022-12-17 12:47:43 +11:00
|
|
|
float (*r_loop_normals)[3])
|
2015-10-12 20:12:55 +02:00
|
|
|
{
|
2023-07-24 22:06:55 +02:00
|
|
|
if (r_vert_normals == nullptr && r_face_normals == nullptr && r_loop_normals == nullptr) {
|
2015-10-12 20:12:55 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-06-14 11:59:32 -04:00
|
|
|
blender::Array<blender::float3> positions(mesh->vert_positions());
|
|
|
|
|
BKE_keyblock_convert_to_mesh(kb, reinterpret_cast<float(*)[3]>(positions.data()), mesh->totvert);
|
Mesh: Move edges to a generic attribute
Implements #95966, as the final step of #95965.
This commit changes the storage of mesh edge vertex indices from the
`MEdge` type to the generic `int2` attribute type. This follows the
general design for geometry and the attribute system, where the data
storage type and the usage semantics are separated.
The main benefit of the change is reduced memory usage-- the
requirements of storing mesh edges is reduced by 1/3. For example,
this saves 8MB on a 1 million vertex grid. This also gives performance
benefits to any memory-bound mesh processing algorithm that uses edges.
Another benefit is that all of the edge's vertex indices are
contiguous. In a few cases, it's helpful to process all of them as
`Span<int>` rather than `Span<int2>`. Similarly, the type is more
likely to match a generic format used by a library, or code that
shouldn't know about specific Blender `Mesh` types.
Various Notes:
- The `.edge_verts` name is used to reflect a mapping between domains,
similar to `.corner_verts`, etc. The period means that it the data
shouldn't change arbitrarily by the user or procedural operations.
- `edge[0]` is now used instead of `edge.v1`
- Signed integers are used instead of unsigned to reduce the mixing
of signed-ness, which can be error prone.
- All of the previously used core mesh data types (`MVert`, `MEdge`,
`MLoop`, `MPoly` are now deprecated. Only generic types are used).
- The `vec2i` DNA type is used in the few C files where necessary.
Pull Request: https://projects.blender.org/blender/blender/pulls/106638
2023-04-17 13:47:41 +02:00
|
|
|
const blender::Span<blender::int2> edges = mesh->edges();
|
2023-07-24 22:06:55 +02:00
|
|
|
const blender::OffsetIndices faces = mesh->faces();
|
Mesh: Replace MLoop struct with generic attributes
Implements #102359.
Split the `MLoop` struct into two separate integer arrays called
`corner_verts` and `corner_edges`, referring to the vertex each corner
is attached to and the next edge around the face at each corner. These
arrays can be sliced to give access to the edges or vertices in a face.
Then they are often referred to as "poly_verts" or "poly_edges".
The main benefits are halving the necessary memory bandwidth when only
one array is used and simplifications from using regular integer indices
instead of a special-purpose struct.
The commit also starts a renaming from "loop" to "corner" in mesh code.
Like the other mesh struct of array refactors, forward compatibility is
kept by writing files with the older format. This will be done until 4.0
to ease the transition process.
Looking at a small portion of the patch should give a good impression
for the rest of the changes. I tried to make the changes as small as
possible so it's easy to tell the correctness from the diff. Though I
found Blender developers have been very inventive over the last decade
when finding different ways to loop over the corners in a face.
For performance, nearly every piece of code that deals with `Mesh` is
slightly impacted. Any algorithm that is memory bottle-necked should
see an improvement. For example, here is a comparison of interpolating
a vertex float attribute to face corners (Ryzen 3700x):
**Before** (Average: 3.7 ms, Min: 3.4 ms)
```
threading::parallel_for(loops.index_range(), 4096, [&](IndexRange range) {
for (const int64_t i : range) {
dst[i] = src[loops[i].v];
}
});
```
**After** (Average: 2.9 ms, Min: 2.6 ms)
```
array_utils::gather(src, corner_verts, dst);
```
That's an improvement of 28% to the average timings, and it's also a
simplification, since an index-based routine can be used instead.
For more examples using the new arrays, see the design task.
Pull Request: https://projects.blender.org/blender/blender/pulls/104424
2023-03-20 15:55:13 +01:00
|
|
|
const blender::Span<int> corner_verts = mesh->corner_verts();
|
|
|
|
|
const blender::Span<int> corner_edges = mesh->corner_edges();
|
2022-03-22 09:43:02 -05:00
|
|
|
|
2022-12-17 12:47:43 +11:00
|
|
|
const bool loop_normals_needed = r_loop_normals != nullptr;
|
|
|
|
|
const bool vert_normals_needed = r_vert_normals != nullptr || loop_normals_needed;
|
2023-07-24 22:06:55 +02:00
|
|
|
const bool face_normals_needed = r_face_normals != nullptr || vert_normals_needed ||
|
2022-03-22 09:43:02 -05:00
|
|
|
loop_normals_needed;
|
|
|
|
|
|
2022-12-17 12:47:43 +11:00
|
|
|
float(*vert_normals)[3] = r_vert_normals;
|
2023-07-24 22:06:55 +02:00
|
|
|
float(*face_normals)[3] = r_face_normals;
|
2022-03-22 09:43:02 -05:00
|
|
|
bool free_vert_normals = false;
|
2023-07-24 22:06:55 +02:00
|
|
|
bool free_face_normals = false;
|
2022-12-17 12:47:43 +11:00
|
|
|
if (vert_normals_needed && r_vert_normals == nullptr) {
|
2022-12-02 12:34:26 +01:00
|
|
|
vert_normals = static_cast<float(*)[3]>(
|
|
|
|
|
MEM_malloc_arrayN(mesh->totvert, sizeof(float[3]), __func__));
|
2022-03-22 09:43:02 -05:00
|
|
|
free_vert_normals = true;
|
|
|
|
|
}
|
2023-07-24 22:06:55 +02:00
|
|
|
if (face_normals_needed && r_face_normals == nullptr) {
|
|
|
|
|
face_normals = static_cast<float(*)[3]>(
|
|
|
|
|
MEM_malloc_arrayN(mesh->faces_num, sizeof(float[3]), __func__));
|
|
|
|
|
free_face_normals = true;
|
2022-03-22 09:43:02 -05:00
|
|
|
}
|
|
|
|
|
|
2023-07-24 22:06:55 +02:00
|
|
|
if (face_normals_needed) {
|
|
|
|
|
blender::bke::mesh::normals_calc_faces(
|
2023-06-14 11:59:32 -04:00
|
|
|
positions,
|
2023-07-24 22:06:55 +02:00
|
|
|
faces,
|
Mesh: Replace MLoop struct with generic attributes
Implements #102359.
Split the `MLoop` struct into two separate integer arrays called
`corner_verts` and `corner_edges`, referring to the vertex each corner
is attached to and the next edge around the face at each corner. These
arrays can be sliced to give access to the edges or vertices in a face.
Then they are often referred to as "poly_verts" or "poly_edges".
The main benefits are halving the necessary memory bandwidth when only
one array is used and simplifications from using regular integer indices
instead of a special-purpose struct.
The commit also starts a renaming from "loop" to "corner" in mesh code.
Like the other mesh struct of array refactors, forward compatibility is
kept by writing files with the older format. This will be done until 4.0
to ease the transition process.
Looking at a small portion of the patch should give a good impression
for the rest of the changes. I tried to make the changes as small as
possible so it's easy to tell the correctness from the diff. Though I
found Blender developers have been very inventive over the last decade
when finding different ways to loop over the corners in a face.
For performance, nearly every piece of code that deals with `Mesh` is
slightly impacted. Any algorithm that is memory bottle-necked should
see an improvement. For example, here is a comparison of interpolating
a vertex float attribute to face corners (Ryzen 3700x):
**Before** (Average: 3.7 ms, Min: 3.4 ms)
```
threading::parallel_for(loops.index_range(), 4096, [&](IndexRange range) {
for (const int64_t i : range) {
dst[i] = src[loops[i].v];
}
});
```
**After** (Average: 2.9 ms, Min: 2.6 ms)
```
array_utils::gather(src, corner_verts, dst);
```
That's an improvement of 28% to the average timings, and it's also a
simplification, since an index-based routine can be used instead.
For more examples using the new arrays, see the design task.
Pull Request: https://projects.blender.org/blender/blender/pulls/104424
2023-03-20 15:55:13 +01:00
|
|
|
corner_verts,
|
2023-07-24 22:06:55 +02:00
|
|
|
{reinterpret_cast<blender::float3 *>(face_normals), faces.size()});
|
2022-03-22 09:43:02 -05:00
|
|
|
}
|
|
|
|
|
if (vert_normals_needed) {
|
2023-08-25 23:06:06 +02:00
|
|
|
blender::bke::mesh::normals_calc_verts(
|
2023-06-14 11:59:32 -04:00
|
|
|
positions,
|
2023-07-24 22:06:55 +02:00
|
|
|
faces,
|
Mesh: Replace MLoop struct with generic attributes
Implements #102359.
Split the `MLoop` struct into two separate integer arrays called
`corner_verts` and `corner_edges`, referring to the vertex each corner
is attached to and the next edge around the face at each corner. These
arrays can be sliced to give access to the edges or vertices in a face.
Then they are often referred to as "poly_verts" or "poly_edges".
The main benefits are halving the necessary memory bandwidth when only
one array is used and simplifications from using regular integer indices
instead of a special-purpose struct.
The commit also starts a renaming from "loop" to "corner" in mesh code.
Like the other mesh struct of array refactors, forward compatibility is
kept by writing files with the older format. This will be done until 4.0
to ease the transition process.
Looking at a small portion of the patch should give a good impression
for the rest of the changes. I tried to make the changes as small as
possible so it's easy to tell the correctness from the diff. Though I
found Blender developers have been very inventive over the last decade
when finding different ways to loop over the corners in a face.
For performance, nearly every piece of code that deals with `Mesh` is
slightly impacted. Any algorithm that is memory bottle-necked should
see an improvement. For example, here is a comparison of interpolating
a vertex float attribute to face corners (Ryzen 3700x):
**Before** (Average: 3.7 ms, Min: 3.4 ms)
```
threading::parallel_for(loops.index_range(), 4096, [&](IndexRange range) {
for (const int64_t i : range) {
dst[i] = src[loops[i].v];
}
});
```
**After** (Average: 2.9 ms, Min: 2.6 ms)
```
array_utils::gather(src, corner_verts, dst);
```
That's an improvement of 28% to the average timings, and it's also a
simplification, since an index-based routine can be used instead.
For more examples using the new arrays, see the design task.
Pull Request: https://projects.blender.org/blender/blender/pulls/104424
2023-03-20 15:55:13 +01:00
|
|
|
corner_verts,
|
2023-11-10 15:19:01 +01:00
|
|
|
mesh->vert_to_face_map(),
|
2023-08-25 23:06:06 +02:00
|
|
|
{reinterpret_cast<const blender::float3 *>(face_normals), faces.size()},
|
2023-03-12 22:29:15 +01:00
|
|
|
{reinterpret_cast<blender::float3 *>(vert_normals), mesh->totvert});
|
2022-03-22 09:43:02 -05:00
|
|
|
}
|
|
|
|
|
if (loop_normals_needed) {
|
2023-07-26 17:04:13 +02:00
|
|
|
const blender::short2 *clnors = static_cast<const blender::short2 *>(
|
|
|
|
|
CustomData_get_layer(&mesh->loop_data, CD_CUSTOMLOOPNORMAL));
|
2023-01-10 16:12:14 -05:00
|
|
|
const bool *sharp_edges = static_cast<const bool *>(
|
2023-07-25 21:15:52 +02:00
|
|
|
CustomData_get_layer_named(&mesh->edge_data, CD_PROP_BOOL, "sharp_edge"));
|
Mesh: Move face shade smooth flag to a generic attribute
Currently the shade smooth status for mesh faces is stored as part of
`MPoly::flag`. As described in #95967, this moves that information
to a separate boolean attribute. It also flips its status, so the
attribute is now called `sharp_face`, which mirrors the existing
`sharp_edge` attribute. The attribute doesn't need to be allocated
when all faces are smooth. Forward compatibility is kept until
4.0 like the other mesh refactors.
This will reduce memory bandwidth requirements for some operations,
since the array of booleans uses 12 times less memory than `MPoly`.
It also allows faces to be stored more efficiently in the future, since
the flag is now unused. It's also possible to use generic functions to
process the values. For example, finding whether there is a sharp face
is just `sharp_faces.contains(true)`.
The `shade_smooth` attribute is no longer accessible with geometry nodes.
Since there were dedicated accessor nodes for that data, that shouldn't
be a problem. That's difficult to version automatically since the named
attribute nodes could be used in arbitrary combinations.
**Implementation notes:**
- The attribute and array variables in the code use the `sharp_faces`
term, to be consistent with the user-facing "sharp faces" wording,
and to avoid requiring many renames when #101689 is implemented.
- Cycles now accesses smooth face status with the generic attribute,
to avoid overhead.
- Changing the zero-value from "smooth" to "flat" takes some care to
make sure defaults are the same.
- Versioning for the edge mode extrude node is particularly complex.
New nodes are added by versioning to propagate the attribute in its
old inverted state.
- A lot of access is still done through the `CustomData` API rather
than the attribute API because of a few functions. That can be
cleaned up easily in the future.
- In the future we would benefit from a way to store attributes as a
single value for when all faces are sharp.
Pull Request: https://projects.blender.org/blender/blender/pulls/104422
2023-03-08 15:36:18 +01:00
|
|
|
const bool *sharp_faces = static_cast<const bool *>(
|
2023-07-25 21:15:52 +02:00
|
|
|
CustomData_get_layer_named(&mesh->face_data, CD_PROP_BOOL, "sharp_face"));
|
2023-03-12 22:29:15 +01:00
|
|
|
blender::bke::mesh::normals_calc_loop(
|
2023-06-14 11:59:32 -04:00
|
|
|
positions,
|
2023-03-12 22:29:15 +01:00
|
|
|
edges,
|
2023-07-24 22:06:55 +02:00
|
|
|
faces,
|
Mesh: Replace MLoop struct with generic attributes
Implements #102359.
Split the `MLoop` struct into two separate integer arrays called
`corner_verts` and `corner_edges`, referring to the vertex each corner
is attached to and the next edge around the face at each corner. These
arrays can be sliced to give access to the edges or vertices in a face.
Then they are often referred to as "poly_verts" or "poly_edges".
The main benefits are halving the necessary memory bandwidth when only
one array is used and simplifications from using regular integer indices
instead of a special-purpose struct.
The commit also starts a renaming from "loop" to "corner" in mesh code.
Like the other mesh struct of array refactors, forward compatibility is
kept by writing files with the older format. This will be done until 4.0
to ease the transition process.
Looking at a small portion of the patch should give a good impression
for the rest of the changes. I tried to make the changes as small as
possible so it's easy to tell the correctness from the diff. Though I
found Blender developers have been very inventive over the last decade
when finding different ways to loop over the corners in a face.
For performance, nearly every piece of code that deals with `Mesh` is
slightly impacted. Any algorithm that is memory bottle-necked should
see an improvement. For example, here is a comparison of interpolating
a vertex float attribute to face corners (Ryzen 3700x):
**Before** (Average: 3.7 ms, Min: 3.4 ms)
```
threading::parallel_for(loops.index_range(), 4096, [&](IndexRange range) {
for (const int64_t i : range) {
dst[i] = src[loops[i].v];
}
});
```
**After** (Average: 2.9 ms, Min: 2.6 ms)
```
array_utils::gather(src, corner_verts, dst);
```
That's an improvement of 28% to the average timings, and it's also a
simplification, since an index-based routine can be used instead.
For more examples using the new arrays, see the design task.
Pull Request: https://projects.blender.org/blender/blender/pulls/104424
2023-03-20 15:55:13 +01:00
|
|
|
corner_verts,
|
|
|
|
|
corner_edges,
|
2023-08-30 23:41:59 +02:00
|
|
|
mesh->corner_to_face_map(),
|
2023-03-12 22:29:15 +01:00
|
|
|
{reinterpret_cast<blender::float3 *>(vert_normals), mesh->totvert},
|
2023-07-24 22:06:55 +02:00
|
|
|
{reinterpret_cast<blender::float3 *>(face_normals), faces.size()},
|
2023-03-12 22:29:15 +01:00
|
|
|
sharp_edges,
|
|
|
|
|
sharp_faces,
|
2023-07-26 17:04:13 +02:00
|
|
|
clnors,
|
2023-03-12 22:29:15 +01:00
|
|
|
nullptr,
|
Mesh: Replace MLoop struct with generic attributes
Implements #102359.
Split the `MLoop` struct into two separate integer arrays called
`corner_verts` and `corner_edges`, referring to the vertex each corner
is attached to and the next edge around the face at each corner. These
arrays can be sliced to give access to the edges or vertices in a face.
Then they are often referred to as "poly_verts" or "poly_edges".
The main benefits are halving the necessary memory bandwidth when only
one array is used and simplifications from using regular integer indices
instead of a special-purpose struct.
The commit also starts a renaming from "loop" to "corner" in mesh code.
Like the other mesh struct of array refactors, forward compatibility is
kept by writing files with the older format. This will be done until 4.0
to ease the transition process.
Looking at a small portion of the patch should give a good impression
for the rest of the changes. I tried to make the changes as small as
possible so it's easy to tell the correctness from the diff. Though I
found Blender developers have been very inventive over the last decade
when finding different ways to loop over the corners in a face.
For performance, nearly every piece of code that deals with `Mesh` is
slightly impacted. Any algorithm that is memory bottle-necked should
see an improvement. For example, here is a comparison of interpolating
a vertex float attribute to face corners (Ryzen 3700x):
**Before** (Average: 3.7 ms, Min: 3.4 ms)
```
threading::parallel_for(loops.index_range(), 4096, [&](IndexRange range) {
for (const int64_t i : range) {
dst[i] = src[loops[i].v];
}
});
```
**After** (Average: 2.9 ms, Min: 2.6 ms)
```
array_utils::gather(src, corner_verts, dst);
```
That's an improvement of 28% to the average timings, and it's also a
simplification, since an index-based routine can be used instead.
For more examples using the new arrays, see the design task.
Pull Request: https://projects.blender.org/blender/blender/pulls/104424
2023-03-20 15:55:13 +01:00
|
|
|
{reinterpret_cast<blender::float3 *>(r_loop_normals), corner_verts.size()});
|
2015-10-12 20:12:55 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-03-22 09:43:02 -05:00
|
|
|
if (free_vert_normals) {
|
|
|
|
|
MEM_freeN(vert_normals);
|
|
|
|
|
}
|
2023-07-24 22:06:55 +02:00
|
|
|
if (free_face_normals) {
|
|
|
|
|
MEM_freeN(face_normals);
|
2015-10-12 20:12:55 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-16 18:50:23 +01:00
|
|
|
/************************* raw coords ************************/
|
2021-12-07 17:19:15 +11:00
|
|
|
|
2022-04-28 09:10:37 -05:00
|
|
|
void BKE_keyblock_update_from_vertcos(const Object *ob, KeyBlock *kb, const float (*vertCos)[3])
|
2010-06-21 20:10:59 +00:00
|
|
|
{
|
2019-08-21 11:46:04 +10:00
|
|
|
const float(*co)[3] = vertCos;
|
2022-12-02 12:34:26 +01:00
|
|
|
float *fp = static_cast<float *>(kb->data);
|
2014-11-16 18:50:23 +01:00
|
|
|
int tot, a;
|
2010-06-21 20:10:59 +00:00
|
|
|
|
2014-11-16 21:45:40 +01:00
|
|
|
#ifndef NDEBUG
|
|
|
|
|
if (ob->type == OB_LATTICE) {
|
2022-12-02 12:34:26 +01:00
|
|
|
Lattice *lt = static_cast<Lattice *>(ob->data);
|
2014-11-16 21:45:40 +01:00
|
|
|
BLI_assert((lt->pntsu * lt->pntsv * lt->pntsw) == kb->totelem);
|
|
|
|
|
}
|
2022-02-18 09:50:29 -06:00
|
|
|
else if (ELEM(ob->type, OB_CURVES_LEGACY, OB_SURF)) {
|
2022-12-02 12:34:26 +01:00
|
|
|
Curve *cu = static_cast<Curve *>(ob->data);
|
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
2018-09-05 16:17:59 +03:00
|
|
|
BLI_assert(BKE_keyblock_curve_element_count(&cu->nurb) == kb->totelem);
|
2014-11-16 21:45:40 +01:00
|
|
|
}
|
|
|
|
|
else if (ob->type == OB_MESH) {
|
2022-12-02 12:34:26 +01:00
|
|
|
Mesh *me = static_cast<Mesh *>(ob->data);
|
2014-11-16 21:45:40 +01:00
|
|
|
BLI_assert(me->totvert == kb->totelem);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
BLI_assert(0 == kb->totelem);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2010-06-21 20:10:59 +00:00
|
|
|
|
2014-11-16 18:50:23 +01:00
|
|
|
tot = kb->totelem;
|
2019-04-22 09:39:35 +10:00
|
|
|
if (tot == 0) {
|
2014-11-16 18:50:23 +01:00
|
|
|
return;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-10-03 12:06:06 +11:00
|
|
|
/* Copy coords to key-block. */
|
2012-03-24 06:18:31 +00:00
|
|
|
if (ELEM(ob->type, OB_MESH, OB_LATTICE)) {
|
2014-11-17 10:46:31 +01:00
|
|
|
for (a = 0; a < tot; a++, fp += 3, co++) {
|
|
|
|
|
copy_v3_v3(fp, *co);
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2022-02-18 09:50:29 -06:00
|
|
|
else if (ELEM(ob->type, OB_CURVES_LEGACY, OB_SURF)) {
|
2022-04-28 09:10:37 -05:00
|
|
|
const Curve *cu = (const Curve *)ob->data;
|
|
|
|
|
const BezTriple *bezt;
|
|
|
|
|
const BPoint *bp;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-08-04 08:51:13 +10:00
|
|
|
LISTBASE_FOREACH (const Nurb *, nu, &cu->nurb) {
|
2012-03-24 06:18:31 +00:00
|
|
|
if (nu->bezt) {
|
2014-11-17 10:46:31 +01:00
|
|
|
for (a = nu->pntsu, bezt = nu->bezt; a; a--, bezt++) {
|
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
2018-09-05 16:17:59 +03:00
|
|
|
for (int i = 0; i < 3; i++, co++) {
|
|
|
|
|
copy_v3_v3(&fp[i * 3], *co);
|
2010-06-21 20:10:59 +00:00
|
|
|
}
|
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
2018-09-05 16:17:59 +03:00
|
|
|
fp += KEYELEM_FLOAT_LEN_BEZTRIPLE;
|
2010-06-21 20:10:59 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
2018-09-05 16:17:59 +03:00
|
|
|
for (a = nu->pntsu * nu->pntsv, bp = nu->bp; a; a--, bp++, co++) {
|
2014-11-17 10:46:31 +01:00
|
|
|
copy_v3_v3(fp, *co);
|
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
2018-09-05 16:17:59 +03:00
|
|
|
fp += KEYELEM_FLOAT_LEN_BPOINT;
|
2010-06-21 20:10:59 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-28 09:10:37 -05:00
|
|
|
void BKE_keyblock_convert_from_vertcos(const Object *ob, KeyBlock *kb, const float (*vertCos)[3])
|
2010-06-21 20:10:59 +00:00
|
|
|
{
|
2014-11-16 18:50:23 +01:00
|
|
|
int tot = 0, elemsize;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-11-16 18:50:23 +01:00
|
|
|
MEM_SAFE_FREE(kb->data);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-06-21 20:10:59 +00:00
|
|
|
/* Count of vertex coords in array */
|
2012-03-24 06:18:31 +00:00
|
|
|
if (ob->type == OB_MESH) {
|
2022-04-28 09:10:37 -05:00
|
|
|
const Mesh *me = (const Mesh *)ob->data;
|
2012-04-14 02:32:32 +00:00
|
|
|
tot = me->totvert;
|
|
|
|
|
elemsize = me->key->elemsize;
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
|
|
|
|
else if (ob->type == OB_LATTICE) {
|
2022-04-28 09:10:37 -05:00
|
|
|
const Lattice *lt = (const Lattice *)ob->data;
|
2012-04-14 02:32:32 +00:00
|
|
|
tot = lt->pntsu * lt->pntsv * lt->pntsw;
|
|
|
|
|
elemsize = lt->key->elemsize;
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
2022-02-18 09:50:29 -06:00
|
|
|
else if (ELEM(ob->type, OB_CURVES_LEGACY, OB_SURF)) {
|
2022-04-28 09:10:37 -05:00
|
|
|
const Curve *cu = (const Curve *)ob->data;
|
2012-04-14 02:32:32 +00:00
|
|
|
elemsize = cu->key->elemsize;
|
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
2018-09-05 16:17:59 +03:00
|
|
|
tot = BKE_keyblock_curve_element_count(&cu->nurb);
|
2010-06-21 20:10:59 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (tot == 0) {
|
2014-11-16 18:50:23 +01:00
|
|
|
return;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-11-16 18:50:23 +01:00
|
|
|
kb->data = MEM_mallocN(tot * elemsize, __func__);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-10-03 12:06:06 +11:00
|
|
|
/* Copy coords to key-block. */
|
2014-11-16 19:15:23 +01:00
|
|
|
BKE_keyblock_update_from_vertcos(ob, kb, vertCos);
|
2014-11-16 18:50:23 +01:00
|
|
|
}
|
|
|
|
|
|
2022-04-28 09:10:37 -05:00
|
|
|
float (*BKE_keyblock_convert_to_vertcos(const Object *ob, const KeyBlock *kb))[3]
|
2014-11-16 18:50:23 +01:00
|
|
|
{
|
2014-11-17 10:46:31 +01:00
|
|
|
float(*vertCos)[3], (*co)[3];
|
2022-12-02 12:34:26 +01:00
|
|
|
const float *fp = static_cast<const float *>(kb->data);
|
2014-11-16 18:50:23 +01:00
|
|
|
int tot = 0, a;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-11-16 18:50:23 +01:00
|
|
|
/* Count of vertex coords in array */
|
|
|
|
|
if (ob->type == OB_MESH) {
|
2022-04-28 09:10:37 -05:00
|
|
|
const Mesh *me = (const Mesh *)ob->data;
|
2014-11-16 18:50:23 +01:00
|
|
|
tot = me->totvert;
|
|
|
|
|
}
|
|
|
|
|
else if (ob->type == OB_LATTICE) {
|
2022-04-28 09:10:37 -05:00
|
|
|
const Lattice *lt = (const Lattice *)ob->data;
|
2014-11-16 18:50:23 +01:00
|
|
|
tot = lt->pntsu * lt->pntsv * lt->pntsw;
|
|
|
|
|
}
|
2022-02-18 09:50:29 -06:00
|
|
|
else if (ELEM(ob->type, OB_CURVES_LEGACY, OB_SURF)) {
|
2022-04-28 09:10:37 -05:00
|
|
|
const Curve *cu = (const Curve *)ob->data;
|
2014-11-16 18:50:23 +01:00
|
|
|
tot = BKE_nurbList_verts_count(&cu->nurb);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-22 09:39:35 +10:00
|
|
|
if (tot == 0) {
|
2022-12-02 12:34:26 +01:00
|
|
|
return nullptr;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-12-02 12:34:26 +01:00
|
|
|
co = vertCos = static_cast<float(*)[3]>(MEM_mallocN(tot * sizeof(*vertCos), __func__));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-11-16 18:50:23 +01:00
|
|
|
/* Copy coords to array */
|
2012-03-24 06:18:31 +00:00
|
|
|
if (ELEM(ob->type, OB_MESH, OB_LATTICE)) {
|
2014-11-17 10:46:31 +01:00
|
|
|
for (a = 0; a < tot; a++, fp += 3, co++) {
|
|
|
|
|
copy_v3_v3(*co, fp);
|
2010-06-21 20:10:59 +00:00
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
2022-02-18 09:50:29 -06:00
|
|
|
else if (ELEM(ob->type, OB_CURVES_LEGACY, OB_SURF)) {
|
2022-04-28 09:10:37 -05:00
|
|
|
const Curve *cu = (const Curve *)ob->data;
|
|
|
|
|
const BezTriple *bezt;
|
|
|
|
|
const BPoint *bp;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-08-04 08:51:13 +10:00
|
|
|
LISTBASE_FOREACH (Nurb *, nu, &cu->nurb) {
|
2012-03-24 06:18:31 +00:00
|
|
|
if (nu->bezt) {
|
2014-11-17 10:46:31 +01:00
|
|
|
for (a = nu->pntsu, bezt = nu->bezt; a; a--, bezt++) {
|
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
2018-09-05 16:17:59 +03:00
|
|
|
for (int i = 0; i < 3; i++, co++) {
|
|
|
|
|
copy_v3_v3(*co, &fp[i * 3]);
|
2010-06-21 20:10:59 +00:00
|
|
|
}
|
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
2018-09-05 16:17:59 +03:00
|
|
|
fp += KEYELEM_FLOAT_LEN_BEZTRIPLE;
|
2010-06-21 20:10:59 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
2018-09-05 16:17:59 +03:00
|
|
|
for (a = nu->pntsu * nu->pntsv, bp = nu->bp; a; a--, bp++, co++) {
|
2014-11-17 10:46:31 +01:00
|
|
|
copy_v3_v3(*co, fp);
|
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
2018-09-05 16:17:59 +03:00
|
|
|
fp += KEYELEM_FLOAT_LEN_BPOINT;
|
2010-06-21 20:10:59 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-11-16 18:50:23 +01:00
|
|
|
return vertCos;
|
2010-06-21 20:10:59 +00:00
|
|
|
}
|
2010-06-23 12:27:13 +00:00
|
|
|
|
2022-04-28 09:10:37 -05:00
|
|
|
void BKE_keyblock_update_from_offset(const Object *ob, KeyBlock *kb, const float (*ofs)[3])
|
2010-06-23 12:27:13 +00:00
|
|
|
{
|
|
|
|
|
int a;
|
2022-12-02 12:34:26 +01:00
|
|
|
float *fp = static_cast<float *>(kb->data);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (ELEM(ob->type, OB_MESH, OB_LATTICE)) {
|
2014-11-17 10:46:31 +01:00
|
|
|
for (a = 0; a < kb->totelem; a++, fp += 3, ofs++) {
|
|
|
|
|
add_v3_v3(fp, *ofs);
|
2010-06-23 12:27:13 +00:00
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
2022-02-18 09:50:29 -06:00
|
|
|
else if (ELEM(ob->type, OB_CURVES_LEGACY, OB_SURF)) {
|
2022-04-28 09:10:37 -05:00
|
|
|
const Curve *cu = (const Curve *)ob->data;
|
|
|
|
|
const BezTriple *bezt;
|
|
|
|
|
const BPoint *bp;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-08-04 08:51:13 +10:00
|
|
|
LISTBASE_FOREACH (const Nurb *, nu, &cu->nurb) {
|
2012-03-24 06:18:31 +00:00
|
|
|
if (nu->bezt) {
|
2014-11-17 10:46:31 +01:00
|
|
|
for (a = nu->pntsu, bezt = nu->bezt; a; a--, bezt++) {
|
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
2018-09-05 16:17:59 +03:00
|
|
|
for (int i = 0; i < 3; i++, ofs++) {
|
|
|
|
|
add_v3_v3(&fp[i * 3], *ofs);
|
2010-06-23 12:27:13 +00:00
|
|
|
}
|
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
2018-09-05 16:17:59 +03:00
|
|
|
fp += KEYELEM_FLOAT_LEN_BEZTRIPLE;
|
2010-06-23 12:27:13 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
2018-09-05 16:17:59 +03:00
|
|
|
for (a = nu->pntsu * nu->pntsv, bp = nu->bp; a; a--, bp++, ofs++) {
|
2014-11-17 10:46:31 +01:00
|
|
|
add_v3_v3(fp, *ofs);
|
Put the Radius property of Curve points under shape key control.
Since shape keys are stored as raw floating point data, this
unfortunately requires changes to all code that works with it.
An additional complication is that bezier and nurbs control
points have different entry size, and can be mixed in the same
object (and hence shape key buffer).
Shape key entries are changed from:
bezier: float v1[3], v2[3], v3[3], tilt, pad, pad;
nurbs: float vec[3], tilt;
To:
bezier: float v1[3], v2[3], v3[3], tilt, radius, pad;
nurbs: float vec[3], tilt, radius, pad;
The official shape key element size is changed to 3 floats,
with 4 elements for bezier nodes, and 2 for nurbs. This also
means that the element count is not equal to the vertex count
anymore.
While searching for all curve Shape Key code, I also found that
BKE_curve_transform_ex and BKE_curve_translate were broken. This
can be seen by trying to change the Origin of a Curve with keys.
Reviewers: campbellbarton, sergey
Differential Revision: https://developer.blender.org/D3676
2018-09-05 16:17:59 +03:00
|
|
|
fp += KEYELEM_FLOAT_LEN_BPOINT;
|
2010-06-23 12:27:13 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-10-21 11:59:14 +02:00
|
|
|
|
|
|
|
|
bool BKE_keyblock_move(Object *ob, int org_index, int new_index)
|
|
|
|
|
{
|
|
|
|
|
Key *key = BKE_key_from_object(ob);
|
|
|
|
|
KeyBlock *kb;
|
|
|
|
|
const int act_index = ob->shapenr - 1;
|
|
|
|
|
const int totkey = key->totkey;
|
|
|
|
|
int i;
|
|
|
|
|
bool rev, in_range = false;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-10-21 11:59:14 +02:00
|
|
|
if (org_index < 0) {
|
|
|
|
|
org_index = act_index;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-10-21 11:59:14 +02:00
|
|
|
CLAMP(new_index, 0, key->totkey - 1);
|
|
|
|
|
CLAMP(org_index, 0, key->totkey - 1);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-10-21 11:59:14 +02:00
|
|
|
if (new_index == org_index) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-10-21 11:59:14 +02:00
|
|
|
rev = ((new_index - org_index) < 0) ? true : false;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-27 12:07:07 +10:00
|
|
|
/* We swap 'org' element with its previous/next neighbor (depending on direction of the move)
|
|
|
|
|
* repeatedly, until we reach final position.
|
2014-10-21 11:59:14 +02:00
|
|
|
* This allows us to only loop on the list once! */
|
2022-12-02 12:34:26 +01:00
|
|
|
for (kb = static_cast<KeyBlock *>(rev ? key->block.last : key->block.first),
|
|
|
|
|
i = (rev ? totkey - 1 : 0);
|
|
|
|
|
kb;
|
2014-10-21 11:59:14 +02:00
|
|
|
kb = (rev ? kb->prev : kb->next), rev ? i-- : i++)
|
|
|
|
|
{
|
|
|
|
|
if (i == org_index) {
|
|
|
|
|
in_range = true; /* Start list items swapping... */
|
|
|
|
|
}
|
|
|
|
|
else if (i == new_index) {
|
|
|
|
|
in_range = false; /* End list items swapping. */
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-10-21 11:59:14 +02:00
|
|
|
if (in_range) {
|
|
|
|
|
KeyBlock *other_kb = rev ? kb->prev : kb->next;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-10-21 11:59:14 +02:00
|
|
|
/* Swap with previous/next list item. */
|
2014-10-21 14:06:16 +02:00
|
|
|
BLI_listbase_swaplinks(&key->block, kb, other_kb);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-10-21 11:59:14 +02:00
|
|
|
/* Swap absolute positions. */
|
2023-01-09 11:12:03 -05:00
|
|
|
std::swap(kb->pos, other_kb->pos);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-10-21 11:59:14 +02:00
|
|
|
kb = other_kb;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-10-21 11:59:14 +02:00
|
|
|
/* Adjust relative indices, this has to be done on the whole list! */
|
|
|
|
|
if (kb->relative == org_index) {
|
|
|
|
|
kb->relative = new_index;
|
|
|
|
|
}
|
|
|
|
|
else if (kb->relative < org_index && kb->relative >= new_index) {
|
|
|
|
|
/* remove after, insert before this index */
|
|
|
|
|
kb->relative++;
|
|
|
|
|
}
|
|
|
|
|
else if (kb->relative > org_index && kb->relative <= new_index) {
|
|
|
|
|
/* remove before, insert after this index */
|
|
|
|
|
kb->relative--;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-27 12:07:07 +10:00
|
|
|
/* Need to update active shape number if it's affected,
|
|
|
|
|
* same principle as for relative indices above. */
|
2014-10-21 11:59:14 +02:00
|
|
|
if (org_index == act_index) {
|
|
|
|
|
ob->shapenr = new_index + 1;
|
|
|
|
|
}
|
|
|
|
|
else if (act_index < org_index && act_index >= new_index) {
|
|
|
|
|
ob->shapenr++;
|
|
|
|
|
}
|
|
|
|
|
else if (act_index > org_index && act_index <= new_index) {
|
|
|
|
|
ob->shapenr--;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-10-21 11:59:14 +02:00
|
|
|
/* First key is always refkey, matches interface and BKE_key_sort */
|
2022-12-02 12:34:26 +01:00
|
|
|
key->refkey = static_cast<KeyBlock *>(key->block.first);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-10-21 11:59:14 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
2014-11-16 21:45:40 +01:00
|
|
|
|
2022-04-28 09:10:37 -05:00
|
|
|
bool BKE_keyblock_is_basis(const Key *key, const int index)
|
2014-11-16 21:45:40 +01:00
|
|
|
{
|
2022-04-28 09:10:37 -05:00
|
|
|
const KeyBlock *kb;
|
2014-11-16 21:45:40 +01:00
|
|
|
int i;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-11-16 21:45:40 +01:00
|
|
|
if (key->type == KEY_RELATIVE) {
|
2022-12-02 12:34:26 +01:00
|
|
|
for (i = 0, kb = static_cast<const KeyBlock *>(key->block.first); kb; i++, kb = kb->next) {
|
2014-11-16 21:45:40 +01:00
|
|
|
if ((i != index) && (kb->relative == index)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-11-16 21:45:40 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
2023-07-14 20:11:24 +03:00
|
|
|
|
|
|
|
|
bool *BKE_keyblock_get_dependent_keys(const Key *key, const int index)
|
|
|
|
|
{
|
|
|
|
|
if (key->type != KEY_RELATIVE) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const int count = BLI_listbase_count(&key->block);
|
|
|
|
|
|
|
|
|
|
if (index < 0 || index >= count) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Seed the table with the specified key. */
|
|
|
|
|
bool *marked = static_cast<bool *>(MEM_callocN(sizeof(bool) * count, __func__));
|
|
|
|
|
|
|
|
|
|
marked[index] = true;
|
|
|
|
|
|
|
|
|
|
/* Iterative breadth-first search through the key list. This method minimizes
|
2023-07-20 09:40:32 +10:00
|
|
|
* the number of scans through the list and is fail-safe vs reference cycles. */
|
2023-07-14 20:11:24 +03:00
|
|
|
bool updated, found = false;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
updated = false;
|
|
|
|
|
|
|
|
|
|
LISTBASE_FOREACH_INDEX (const KeyBlock *, kb, &key->block, i) {
|
|
|
|
|
if (!marked[i] && kb->relative >= 0 && kb->relative < count && marked[kb->relative]) {
|
|
|
|
|
marked[i] = true;
|
|
|
|
|
updated = found = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} while (updated);
|
|
|
|
|
|
|
|
|
|
if (!found) {
|
|
|
|
|
MEM_freeN(marked);
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* After the search is complete, exclude the original key. */
|
|
|
|
|
marked[index] = false;
|
|
|
|
|
return marked;
|
|
|
|
|
}
|