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
|
|
|
*/
|
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
Cleanup of MotionPaths+Ghosts (AnimViz) - Part 1
This commit sets up some of the groundwork necessary to extend the animation visualisation capabilities, previously only available for bones in PoseMode, to Objects as well. Also, some of the other goals of this refactor is to make future visualisation goodies (i.e. editable paths) more feasible...
(There's really nothing to see here yet. The following log notes are really just for my own reference to keep track of things.)
Currently, the following things have been done:
* New datastructures + settings have been tidied up, ready for usage
* Added these new types into the Object and PoseBone code as necessary, with freeing/adding/copying accounted for
* File IO code for the new data, including version patching to convert the old system to the new one.
* Set up the drawing system for motionpaths based on the old armature path drawing code. Armatures still draw using the old system, since the two systems use different storage systems.
* Started setting up the motionpath 'baking' code, but the core of this still needs to be coded...
Next Steps (after some semi-urgent Durian Driver changes):
* Port the ghosting/onionskinning code over too
* Finish motionpath baking code
* RNA wrapping for the new types
* Hooking up all the new code into the operators, etc.
2010-01-01 12:24:16 +00:00
|
|
|
|
2023-07-22 11:27:25 +10:00
|
|
|
#include <cfloat>
|
2014-01-21 12:11:34 +01:00
|
|
|
|
2020-04-03 11:35:04 +02:00
|
|
|
#include "DNA_curve_types.h"
|
Orange branch: Revived hidden treasure, the Groups!
Previous experiment (in 2000) didn't satisfy, it had even some primitive
NLA option in groups... so, cleaned up the old code (removed most) and
integrated it back in a more useful way.
Usage:
- CTRL+G gives menu to add group, add to existing group, or remove from
groups.
- In Object buttons, a new (should become first) Panel was added, showing
not only Object "ID button" and Parent, but also the Groups the Object
Belongs to. These buttons also allow rename, assigning or removing.
- To indicate Objects are grouped, they're drawn in a (not theme yet, so
temporal?) green wire color.
- Use ALT+SHIFT mouse-select to (de)select an entire group
But, the real power of groups is in the following features:
-> Particle Force field and Guide control
In the "Particle Motion" Panel, you can indicate a Group name, this then
limits force fields or guides to members of that Group. (Note that layers
still work on top of that... not sure about that).
-> Light Groups
In the Material "Shaders" Panel, you can indicate a Group name to limit
lighting for the Material to lamps in this group. The Lights in a Group do
need to be 'visible' for the Scene to be rendered (as usual).
-> Group Duplicator
In the Object "Anim" Panel, you can set any Object (use Empty!) to
duplicate an entire Group. It will make copies of all Objects in that Group.
Also works for animated Objects, but it will copy the current positions or
deforms. Control over 'local timing' (so we can do Massive anims!) will be
added later.
(Note; this commit won't render Group duplicators yet, a fix in bf-blender
will enable that, next commit will sync)
-> Library Appending
In the SHIFT-F1 or SHIFT+F4 browsers, you can also find the Groups listed.
By appending or linking the Group itself, and use the Group Duplicator, you
now can animate and position linked Objects. The nice thing is that the
local saved file itself will only store the Group name that was linked, so
on a next file read, the Group Objects will be re-read as stored (changed)
in the Library file.
(Note; current implementation also "gives a base" to linked Group Objects,
to show them as Objects in the current Scene. Need that now for testing
purposes, but probably will be removed later).
-> Outliner
Outliner now shows Groups as optio too, nice to organize your data a bit too!
In General, Groups have a very good potential... for example, it could
become default for MetaBall Objects too (jiri, I can help you later on how
this works). All current 'layer relationships' in Blender should be dropped
in time, I guess...
2005-12-06 10:55:30 +00:00
|
|
|
#include "DNA_key_types.h"
|
2020-04-03 11:35:04 +02:00
|
|
|
#include "DNA_object_types.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_rotation.h"
|
2020-04-03 11:35:04 +02:00
|
|
|
#include "BLI_math_vector.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2020-04-03 11:35:04 +02:00
|
|
|
#include "BKE_anim_path.h"
|
2023-11-16 11:41:55 +01:00
|
|
|
#include "BKE_curve.hh"
|
2024-01-30 14:42:07 -05:00
|
|
|
#include "BKE_key.hh"
|
2023-11-15 18:46:07 +01:00
|
|
|
#include "BKE_object_types.hh"
|
2018-06-01 16:38:21 +02:00
|
|
|
|
2019-02-01 12:44:19 +11:00
|
|
|
#include "CLG_log.h"
|
|
|
|
|
|
|
|
|
|
static CLG_LogRef LOG = {"bke.anim"};
|
|
|
|
|
|
Cleanup of MotionPaths+Ghosts (AnimViz) - Part 1
This commit sets up some of the groundwork necessary to extend the animation visualisation capabilities, previously only available for bones in PoseMode, to Objects as well. Also, some of the other goals of this refactor is to make future visualisation goodies (i.e. editable paths) more feasible...
(There's really nothing to see here yet. The following log notes are really just for my own reference to keep track of things.)
Currently, the following things have been done:
* New datastructures + settings have been tidied up, ready for usage
* Added these new types into the Object and PoseBone code as necessary, with freeing/adding/copying accounted for
* File IO code for the new data, including version patching to convert the old system to the new one.
* Set up the drawing system for motionpaths based on the old armature path drawing code. Armatures still draw using the old system, since the two systems use different storage systems.
* Started setting up the motionpath 'baking' code, but the core of this still needs to be coded...
Next Steps (after some semi-urgent Durian Driver changes):
* Port the ghosting/onionskinning code over too
* Finish motionpath baking code
* RNA wrapping for the new types
* Hooking up all the new code into the operators, etc.
2010-01-01 12:24:16 +00:00
|
|
|
/* ******************************************************************** */
|
|
|
|
|
/* Curve Paths - for curve deforms and/or curve following */
|
|
|
|
|
|
2021-04-08 15:51:08 +02:00
|
|
|
static int get_bevlist_seg_array_size(const BevList *bl)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2021-04-08 15:51:08 +02:00
|
|
|
if (bl->poly >= 0) {
|
|
|
|
|
/* Cyclic curve. */
|
|
|
|
|
return bl->nr;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2021-04-08 15:51:08 +02:00
|
|
|
|
|
|
|
|
return bl->nr - 1;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
2021-04-08 15:51:08 +02:00
|
|
|
int BKE_anim_path_get_array_size(const CurveCache *curve_cache)
|
|
|
|
|
{
|
2023-07-17 10:46:26 +02:00
|
|
|
BLI_assert(curve_cache != nullptr);
|
2021-04-08 15:51:08 +02:00
|
|
|
|
2023-07-17 10:46:26 +02:00
|
|
|
BevList *bl = static_cast<BevList *>(curve_cache->bev.first);
|
2021-04-08 15:51:08 +02:00
|
|
|
|
2023-07-17 10:46:26 +02:00
|
|
|
BLI_assert(bl != nullptr && bl->nr > 1);
|
2021-04-08 15:51:08 +02:00
|
|
|
|
|
|
|
|
return get_bevlist_seg_array_size(bl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float BKE_anim_path_get_length(const CurveCache *curve_cache)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2021-04-09 14:55:31 +10:00
|
|
|
const int seg_size = BKE_anim_path_get_array_size(curve_cache);
|
2021-04-08 15:51:08 +02:00
|
|
|
return curve_cache->anim_path_accum_length[seg_size - 1];
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-04-09 14:55:31 +10:00
|
|
|
void BKE_anim_path_calc_data(Object *ob)
|
2021-04-08 15:51:08 +02:00
|
|
|
{
|
2023-07-17 10:46:26 +02:00
|
|
|
if (ob == nullptr || ob->type != OB_CURVES_LEGACY) {
|
2012-09-03 22:53:34 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2023-11-15 18:46:07 +01:00
|
|
|
if (ob->runtime->curve_cache == nullptr) {
|
2021-04-08 15:51:08 +02:00
|
|
|
CLOG_WARN(&LOG, "No curve cache!");
|
|
|
|
|
return;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2021-04-08 15:51:08 +02:00
|
|
|
/* We only use the first curve. */
|
2023-11-15 18:46:07 +01:00
|
|
|
BevList *bl = static_cast<BevList *>(ob->runtime->curve_cache->bev.first);
|
2023-07-17 10:46:26 +02:00
|
|
|
if (bl == nullptr || !bl->nr) {
|
2021-04-08 15:51:08 +02:00
|
|
|
CLOG_WARN(&LOG, "No bev list data!");
|
2012-09-03 22:53:34 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-04-08 15:51:08 +02:00
|
|
|
/* Free old data. */
|
2023-11-15 18:46:07 +01:00
|
|
|
if (ob->runtime->curve_cache->anim_path_accum_length) {
|
|
|
|
|
MEM_freeN((void *)ob->runtime->curve_cache->anim_path_accum_length);
|
2021-04-08 15:51:08 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-04-08 15:51:08 +02:00
|
|
|
/* We assume that we have at least two points.
|
|
|
|
|
* If there is less than two points in the curve,
|
|
|
|
|
* no BevList should have been generated.
|
|
|
|
|
*/
|
|
|
|
|
BLI_assert(bl->nr > 1);
|
|
|
|
|
|
2021-04-09 14:55:31 +10:00
|
|
|
const int seg_size = get_bevlist_seg_array_size(bl);
|
|
|
|
|
float *len_data = (float *)MEM_mallocN(sizeof(float) * seg_size, "calcpathdist");
|
2023-11-15 18:46:07 +01:00
|
|
|
ob->runtime->curve_cache->anim_path_accum_length = len_data;
|
2021-04-08 15:51:08 +02:00
|
|
|
|
|
|
|
|
BevPoint *bp_arr = bl->bevpoints;
|
|
|
|
|
float prev_len = 0.0f;
|
|
|
|
|
for (int i = 0; i < bl->nr - 1; i++) {
|
|
|
|
|
prev_len += len_v3v3(bp_arr[i].vec, bp_arr[i + 1].vec);
|
|
|
|
|
len_data[i] = prev_len;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-04-08 15:51:08 +02:00
|
|
|
if (bl->poly >= 0) {
|
|
|
|
|
/* Cyclic curve. */
|
|
|
|
|
len_data[seg_size - 1] = prev_len + len_v3v3(bp_arr[0].vec, bp_arr[bl->nr - 1].vec);
|
2012-09-03 22:53:34 +00:00
|
|
|
}
|
2021-04-08 15:51:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void get_curve_points_from_idx(const int idx,
|
2021-04-09 14:55:31 +10:00
|
|
|
const BevList *bl,
|
|
|
|
|
const bool is_cyclic,
|
|
|
|
|
BevPoint const **r_p0,
|
|
|
|
|
BevPoint const **r_p1,
|
|
|
|
|
BevPoint const **r_p2,
|
|
|
|
|
BevPoint const **r_p3)
|
2021-04-08 15:51:08 +02:00
|
|
|
{
|
|
|
|
|
BLI_assert(idx >= 0);
|
|
|
|
|
BLI_assert(idx < bl->nr - 1 || (is_cyclic && idx < bl->nr));
|
|
|
|
|
BLI_assert(bl->nr > 1);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-04-09 14:55:31 +10:00
|
|
|
const BevPoint *bp_arr = bl->bevpoints;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-04-09 14:55:31 +10:00
|
|
|
/* First segment. */
|
2021-04-08 15:51:08 +02:00
|
|
|
if (idx == 0) {
|
|
|
|
|
*r_p1 = &bp_arr[0];
|
|
|
|
|
if (is_cyclic) {
|
|
|
|
|
*r_p0 = &bp_arr[bl->nr - 1];
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2021-04-08 15:51:08 +02:00
|
|
|
*r_p0 = *r_p1;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-04-08 15:51:08 +02:00
|
|
|
*r_p2 = &bp_arr[1];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-04-08 15:51:08 +02:00
|
|
|
if (bl->nr > 2) {
|
|
|
|
|
*r_p3 = &bp_arr[2];
|
2014-04-11 17:40:07 +06:00
|
|
|
}
|
|
|
|
|
else {
|
2021-04-08 15:51:08 +02:00
|
|
|
*r_p3 = *r_p2;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2021-04-08 15:51:08 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-04-08 15:51:08 +02:00
|
|
|
/* Last segment (or next to last in a cyclic curve). */
|
|
|
|
|
if (idx == bl->nr - 2) {
|
2021-04-11 13:09:27 +10:00
|
|
|
/* The case when the bl->nr == 2 falls in to the "first segment" check above.
|
2021-04-08 15:51:08 +02:00
|
|
|
* So here we can assume that bl->nr > 2.
|
|
|
|
|
*/
|
|
|
|
|
*r_p0 = &bp_arr[idx - 1];
|
|
|
|
|
*r_p1 = &bp_arr[idx];
|
|
|
|
|
*r_p2 = &bp_arr[idx + 1];
|
|
|
|
|
|
|
|
|
|
if (is_cyclic) {
|
|
|
|
|
*r_p3 = &bp_arr[0];
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
*r_p3 = *r_p2;
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-04-08 15:51:08 +02:00
|
|
|
if (idx == bl->nr - 1) {
|
|
|
|
|
/* Last segment in a cyclic curve. This should only trigger if the curve is cyclic
|
|
|
|
|
* as it gets an extra segment between the end and the start point. */
|
|
|
|
|
*r_p0 = &bp_arr[idx - 1];
|
|
|
|
|
*r_p1 = &bp_arr[idx];
|
|
|
|
|
*r_p2 = &bp_arr[0];
|
|
|
|
|
*r_p3 = &bp_arr[1];
|
|
|
|
|
return;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-04-08 15:51:08 +02:00
|
|
|
/* To get here the curve has to have four curve points or more and idx can't
|
|
|
|
|
* be the first or the last segment.
|
|
|
|
|
* So we can assume that we can get four points without any special checks.
|
|
|
|
|
*/
|
|
|
|
|
*r_p0 = &bp_arr[idx - 1];
|
|
|
|
|
*r_p1 = &bp_arr[idx];
|
|
|
|
|
*r_p2 = &bp_arr[idx + 1];
|
|
|
|
|
*r_p3 = &bp_arr[idx + 2];
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
2021-04-08 15:51:08 +02:00
|
|
|
static bool binary_search_anim_path(const float *accum_len_arr,
|
|
|
|
|
const int seg_size,
|
|
|
|
|
const float goal_len,
|
|
|
|
|
int *r_idx,
|
|
|
|
|
float *r_frac)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2021-04-08 15:51:08 +02:00
|
|
|
float left_len, right_len;
|
|
|
|
|
int cur_idx = 0, cur_base = 0;
|
|
|
|
|
int cur_step = seg_size - 1;
|
|
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
|
cur_idx = cur_base + cur_step / 2;
|
|
|
|
|
left_len = accum_len_arr[cur_idx];
|
|
|
|
|
right_len = accum_len_arr[cur_idx + 1];
|
|
|
|
|
|
|
|
|
|
if (left_len <= goal_len && right_len > goal_len) {
|
|
|
|
|
*r_idx = cur_idx + 1;
|
|
|
|
|
*r_frac = (goal_len - left_len) / (right_len - left_len);
|
|
|
|
|
return true;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2021-04-08 15:51:08 +02:00
|
|
|
if (cur_idx == 0) {
|
2021-04-11 13:09:27 +10:00
|
|
|
/* We ended up at the first segment. The point must be in here. */
|
2021-04-08 15:51:08 +02:00
|
|
|
*r_idx = 0;
|
|
|
|
|
*r_frac = goal_len / accum_len_arr[0];
|
|
|
|
|
return true;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2021-04-08 15:51:08 +02:00
|
|
|
|
|
|
|
|
if (UNLIKELY(cur_step == 0)) {
|
|
|
|
|
/* This should never happen unless there is something horribly wrong. */
|
|
|
|
|
CLOG_ERROR(&LOG, "Couldn't find any valid point on the animation path!");
|
2021-07-15 18:23:28 +10:00
|
|
|
BLI_assert_msg(0, "Couldn't find any valid point on the animation path!");
|
2021-04-08 15:51:08 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (left_len < goal_len) {
|
|
|
|
|
/* Go to the right. */
|
|
|
|
|
cur_base = cur_idx + 1;
|
|
|
|
|
cur_step--;
|
|
|
|
|
} /* Else, go to the left. */
|
|
|
|
|
|
|
|
|
|
cur_step /= 2;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-08 15:51:08 +02:00
|
|
|
bool BKE_where_on_path(const Object *ob,
|
|
|
|
|
float ctime,
|
|
|
|
|
float r_vec[4],
|
|
|
|
|
float r_dir[3],
|
|
|
|
|
float r_quat[4],
|
|
|
|
|
float *r_radius,
|
|
|
|
|
float *r_weight)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2023-07-17 10:46:26 +02:00
|
|
|
if (ob == nullptr || ob->type != OB_CURVES_LEGACY) {
|
2020-06-13 15:16:18 +10:00
|
|
|
return false;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2023-07-17 10:46:26 +02:00
|
|
|
Curve *cu = static_cast<Curve *>(ob->data);
|
2023-11-15 18:46:07 +01:00
|
|
|
if (ob->runtime->curve_cache == nullptr) {
|
2021-04-08 15:51:08 +02:00
|
|
|
CLOG_WARN(&LOG, "No curve cache!");
|
2020-06-13 15:16:18 +10:00
|
|
|
return false;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2023-11-15 18:46:07 +01:00
|
|
|
if (ob->runtime->curve_cache->anim_path_accum_length == nullptr) {
|
2021-11-25 13:45:32 +01:00
|
|
|
CLOG_WARN(&LOG, "No anim path!");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2021-04-08 15:51:08 +02:00
|
|
|
/* We only use the first curve. */
|
2023-11-15 18:46:07 +01:00
|
|
|
BevList *bl = static_cast<BevList *>(ob->runtime->curve_cache->bev.first);
|
2023-07-17 10:46:26 +02:00
|
|
|
if (bl == nullptr || !bl->nr) {
|
2021-04-08 15:51:08 +02:00
|
|
|
CLOG_WARN(&LOG, "No bev list data!");
|
2020-06-13 15:16:18 +10:00
|
|
|
return false;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2021-04-08 15:51:08 +02:00
|
|
|
|
|
|
|
|
/* Test for cyclic curve. */
|
|
|
|
|
const bool is_cyclic = bl->poly >= 0;
|
|
|
|
|
|
|
|
|
|
if (is_cyclic) {
|
|
|
|
|
/* Wrap the time into a 0.0 - 1.0 range. */
|
|
|
|
|
if (ctime < 0.0f || ctime > 1.0f) {
|
|
|
|
|
ctime -= floorf(ctime);
|
|
|
|
|
}
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-04-08 15:51:08 +02:00
|
|
|
/* The curve points for this ctime value. */
|
2021-04-09 14:55:31 +10:00
|
|
|
const BevPoint *p0, *p1, *p2, *p3;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-04-08 15:51:08 +02:00
|
|
|
float frac;
|
|
|
|
|
const int seg_size = get_bevlist_seg_array_size(bl);
|
2023-11-15 18:46:07 +01:00
|
|
|
const float *accum_len_arr = ob->runtime->curve_cache->anim_path_accum_length;
|
2021-04-08 15:51:08 +02:00
|
|
|
const float goal_len = ctime * accum_len_arr[seg_size - 1];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-04-08 15:51:08 +02:00
|
|
|
/* Are we simply trying to get the start/end point? */
|
|
|
|
|
if (ctime <= 0.0f || ctime >= 1.0f) {
|
|
|
|
|
const float clamp_time = clamp_f(ctime, 0.0f, 1.0f);
|
|
|
|
|
const int idx = clamp_time * (seg_size - 1);
|
|
|
|
|
get_curve_points_from_idx(idx, bl, is_cyclic, &p0, &p1, &p2, &p3);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-04-08 15:51:08 +02:00
|
|
|
if (idx == 0) {
|
|
|
|
|
frac = goal_len / accum_len_arr[0];
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
frac = (goal_len - accum_len_arr[idx - 1]) / (accum_len_arr[idx] - accum_len_arr[idx - 1]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* Do binary search to get the correct segment. */
|
|
|
|
|
int idx;
|
2021-04-09 14:55:31 +10:00
|
|
|
const bool found_idx = binary_search_anim_path(accum_len_arr, seg_size, goal_len, &idx, &frac);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-04-08 15:51:08 +02:00
|
|
|
if (UNLIKELY(!found_idx)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
get_curve_points_from_idx(idx, bl, is_cyclic, &p0, &p1, &p2, &p3);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-01-10 01:45:53 +06:00
|
|
|
/* NOTE: commented out for follow constraint
|
|
|
|
|
*
|
2020-06-12 12:51:57 +10:00
|
|
|
* If it's ever be uncommented watch out for BKE_curve_deform_coords()
|
2014-01-10 01:45:53 +06:00
|
|
|
* which used to temporary set CU_FOLLOW flag for the curve and no
|
|
|
|
|
* longer does it (because of threading issues of such a thing.
|
|
|
|
|
*/
|
2019-05-01 11:09:22 +10:00
|
|
|
// if (cu->flag & CU_FOLLOW) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-04-08 15:51:08 +02:00
|
|
|
float w[4];
|
|
|
|
|
|
|
|
|
|
key_curve_tangent_weights(frac, w, KEY_BSPLINE);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-04-13 19:22:10 -05:00
|
|
|
if (r_dir) {
|
|
|
|
|
interp_v3_v3v3v3v3(r_dir, p0->vec, p1->vec, p2->vec, p3->vec, w);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-04-13 19:22:10 -05:00
|
|
|
/* Make compatible with #vec_to_quat. */
|
|
|
|
|
negate_v3(r_dir);
|
|
|
|
|
}
|
Result of 2 weeks of quiet coding work in Greece :)
Aim was to get a total refresh of the animation system. This
is needed because;
- we need to upgrade it with 21st century features
- current code is spaghetti/hack combo, and hides good design
- it should become lag-free with using dependency graphs
A full log, with complete code API/structure/design explanation
will follow, that's a load of work... so here below the list with
hot changes;
- The entire object update system (matrices, geometry) is now
centralized. Calls to where_is_object and makeDispList are
forbidden, instead we tag objects 'changed' and let the
depgraph code sort it out
- Removed all old "Ika" code
- Depgraph is aware of all relationships, including meta balls,
constraints, bevelcurve, and so on.
- Made depgraph aware of relation types and layers, to do smart
flushing of 'changed' events. Nothing gets calculated too often!
- Transform uses depgraph to detect changes
- On frame-advance, depgraph flushes animated changes
Armatures;
Almost all armature related code has been fully built from scratch.
It now reveils the original design much better, with a very clean
implementation, lag free without even calculating each Bone more than
once. Result is quite a speedup yes!
Important to note is;
1) Armature is data containing the 'rest position'
2) Pose is the changes of rest position, and always on object level.
That way more Objects can use same Pose. Also constraints are in Pose
3) Actions only contain the Ipos to change values in Poses.
- Bones draw unrotated now
- Drawing bones speedup enormously (10-20 times)
- Bone selecting in EditMode, selection state is saved for PoseMode,
and vice-versa
- Undo in editmode
- Bone renaming does vertexgroups, constraints, posechannels, actions,
for all users of Armature in entire file
- Added Bone renaming in NKey panel
- Nkey PoseMode shows eulers now
- EditMode and PoseMode now have 'active' bone too (last clicked)
- Parenting in EditMode' CTRL+P, ALT+P, with nice options!
- Pose is added in Outliner now, with showing that constraints are in
the Pose, not Armature
- Disconnected IK solving from constraints. It's a separate phase now,
on top of the full Pose calculations
- Pose itself has a dependency graph too, so evaluation order is lag free.
TODO NOW;
- Rotating in Posemode has incorrect inverse transform (Martin will fix)
- Python Bone/Armature/Pose API disabled... needs full recode too
(wait for my doc!)
- Game engine will need upgrade too
- Depgraph code needs revision, cleanup, can be much faster!
(But, compliments for Jean-Luc, it works like a charm!)
- IK changed, it now doesnt use previous position to advance to next
position anymore. That system looks nice (no flips) but is not well
suited for NLA and background render.
TODO LATER;
We now can do loadsa new nifty features as well; like:
- Kill PoseMode (can be option for armatures itself)
- Make B-Bones (Bezier, Bspline, like for spines)
- Move all silly button level edit to 3d window (like CTRL+I = add
IK)
- Much better & informative drawing
- Fix action/nla editors
- Put all ipos in Actions (object, mesh key, lamp color)
- Add hooks
- Null bones
- Much more advanced constraints...
Bugfixes;
- OGL render (view3d header) had wrong first frame on anim render
- Ipo 'recording' mode had wrong playback speed
- Vertex-key mode now sticks to show 'active key', until frame change
-Ton-
2005-07-03 17:35:38 +00:00
|
|
|
//}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-04-08 15:51:08 +02:00
|
|
|
const ListBase *nurbs = BKE_curve_editNurbs_get(cu);
|
2019-04-22 09:39:35 +10:00
|
|
|
if (!nurbs) {
|
2013-04-15 12:04:55 +00:00
|
|
|
nurbs = &cu->nurb;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2023-07-17 10:46:26 +02:00
|
|
|
const Nurb *nu = static_cast<const Nurb *>(nurbs->first);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-06-24 15:56:58 +10:00
|
|
|
/* Make sure that first and last frame are included in the vectors here. */
|
2021-04-08 15:51:08 +02:00
|
|
|
if (ELEM(nu->type, CU_POLY, CU_BEZIER, CU_NURBS)) {
|
|
|
|
|
key_curve_position_weights(frac, w, KEY_LINEAR);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2021-04-08 15:51:08 +02:00
|
|
|
else if (p2 == p3) {
|
|
|
|
|
key_curve_position_weights(frac, w, KEY_CARDINAL);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2021-04-08 15:51:08 +02:00
|
|
|
key_curve_position_weights(frac, w, KEY_BSPLINE);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-05-03 09:25:19 +02:00
|
|
|
if (r_vec) {
|
2023-09-22 12:02:32 +10:00
|
|
|
/* X, Y, Z axis. */
|
|
|
|
|
r_vec[0] = w[0] * p0->vec[0] + w[1] * p1->vec[0] + w[2] * p2->vec[0] + w[3] * p3->vec[0];
|
|
|
|
|
r_vec[1] = w[0] * p0->vec[1] + w[1] * p1->vec[1] + w[2] * p2->vec[1] + w[3] * p3->vec[1];
|
|
|
|
|
r_vec[2] = w[0] * p0->vec[2] + w[1] * p1->vec[2] + w[2] * p2->vec[2] + w[3] * p3->vec[2];
|
2022-05-03 09:25:19 +02:00
|
|
|
}
|
2021-04-08 15:51:08 +02:00
|
|
|
|
|
|
|
|
/* Clamp weights to 0-1 as we don't want to extrapolate other values than position. */
|
|
|
|
|
clamp_v4(w, 0.0f, 1.0f);
|
|
|
|
|
|
2022-05-03 09:25:19 +02:00
|
|
|
if (r_vec) {
|
|
|
|
|
/* Tilt, should not be needed since we have quat still used. */
|
|
|
|
|
r_vec[3] = w[0] * p0->tilt + w[1] * p1->tilt + w[2] * p2->tilt + w[3] * p3->tilt;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-06-13 15:25:43 +10:00
|
|
|
if (r_quat) {
|
2010-09-20 09:09:00 +00:00
|
|
|
float totfac, q1[4], q2[4];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-04-08 15:51:08 +02:00
|
|
|
totfac = w[0] + w[3];
|
2019-04-22 09:39:35 +10:00
|
|
|
if (totfac > FLT_EPSILON) {
|
2021-04-08 15:51:08 +02:00
|
|
|
interp_qt_qtqt(q1, p0->quat, p3->quat, w[3] / totfac);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2012-05-06 17:22:54 +00:00
|
|
|
copy_qt_qt(q1, p1->quat);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-04-08 15:51:08 +02:00
|
|
|
totfac = w[1] + w[2];
|
2019-04-22 09:39:35 +10:00
|
|
|
if (totfac > FLT_EPSILON) {
|
2021-04-08 15:51:08 +02:00
|
|
|
interp_qt_qtqt(q2, p1->quat, p2->quat, w[2] / totfac);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2012-05-06 17:22:54 +00:00
|
|
|
copy_qt_qt(q2, p3->quat);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-04-08 15:51:08 +02:00
|
|
|
totfac = w[0] + w[1] + w[2] + w[3];
|
2019-04-22 09:39:35 +10:00
|
|
|
if (totfac > FLT_EPSILON) {
|
2021-04-08 15:51:08 +02:00
|
|
|
interp_qt_qtqt(r_quat, q1, q2, (w[1] + w[2]) / totfac);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2020-06-13 15:25:43 +10:00
|
|
|
copy_qt_qt(r_quat, q2);
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2009-09-16 17:43:09 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-06-13 15:25:43 +10:00
|
|
|
if (r_radius) {
|
2021-04-08 15:51:08 +02:00
|
|
|
*r_radius = w[0] * p0->radius + w[1] * p1->radius + w[2] * p2->radius + w[3] * p3->radius;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-06-13 15:25:43 +10:00
|
|
|
if (r_weight) {
|
2021-04-08 15:51:08 +02:00
|
|
|
*r_weight = w[0] * p0->weight + w[1] * p1->weight + w[2] * p2->weight + w[3] * p3->weight;
|
2019-04-22 09:39:35 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-06-13 15:16:18 +10:00
|
|
|
return true;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|