2011-10-10 09:38:02 +00:00
|
|
|
/*
|
2008-04-16 22:40:48 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
2008-04-16 22:40:48 +00:00
|
|
|
* of the License, or (at your option) any later version.
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* The Original Code is: all of this file.
|
|
|
|
*
|
|
|
|
* Contributor(s): none yet.
|
|
|
|
*
|
2008-04-16 22:40:48 +00:00
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
2002-10-12 11:37:38 +00:00
|
|
|
*/
|
|
|
|
|
2011-02-27 20:40:57 +00:00
|
|
|
/** \file blender/blenkernel/intern/curve.c
|
|
|
|
* \ingroup bke
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
#include <math.h> // floor
|
|
|
|
#include <string.h>
|
2012-05-07 08:53:59 +00:00
|
|
|
#include <stdlib.h>
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
2011-01-07 18:36:47 +00:00
|
|
|
|
2011-09-14 00:37:27 +00:00
|
|
|
#include "BLI_blenlib.h"
|
|
|
|
#include "BLI_math.h"
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BLI_utildefines.h"
|
2011-09-14 00:37:27 +00:00
|
|
|
#include "BLI_ghash.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2017-11-01 21:34:30 +03:00
|
|
|
#include "DNA_anim_types.h"
|
2012-05-07 08:53:59 +00:00
|
|
|
#include "DNA_curve_types.h"
|
|
|
|
#include "DNA_material_types.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
/* for dereferencing pointers */
|
2012-05-07 08:53:59 +00:00
|
|
|
#include "DNA_key_types.h"
|
|
|
|
#include "DNA_scene_types.h"
|
|
|
|
#include "DNA_vfont_types.h"
|
2010-08-04 04:01:27 +00:00
|
|
|
#include "DNA_object_types.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2009-01-18 10:41:45 +00:00
|
|
|
#include "BKE_animsys.h"
|
2012-05-07 08:53:59 +00:00
|
|
|
#include "BKE_curve.h"
|
|
|
|
#include "BKE_displist.h"
|
|
|
|
#include "BKE_font.h"
|
|
|
|
#include "BKE_global.h"
|
|
|
|
#include "BKE_key.h"
|
|
|
|
#include "BKE_library.h"
|
2016-07-09 15:08:24 +02:00
|
|
|
#include "BKE_library_query.h"
|
|
|
|
#include "BKE_library_remap.h"
|
2012-05-07 08:53:59 +00:00
|
|
|
#include "BKE_main.h"
|
2011-04-26 07:17:21 +00:00
|
|
|
#include "BKE_object.h"
|
|
|
|
#include "BKE_material.h"
|
2011-01-07 19:18:31 +00:00
|
|
|
|
2017-04-06 15:37:46 +02:00
|
|
|
#include "DEG_depsgraph.h"
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
/* globals */
|
|
|
|
|
|
|
|
/* local */
|
2012-02-28 14:05:00 +00:00
|
|
|
static int cu_isectLL(const float v1[3], const float v2[3], const float v3[3], const float v4[3],
|
2011-11-11 13:09:14 +00:00
|
|
|
short cox, short coy,
|
2012-12-11 14:18:37 +00:00
|
|
|
float *lambda, float *mu, float vec[3]);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2009-01-23 14:43:25 +00:00
|
|
|
/* frees editcurve entirely */
|
2012-04-28 16:49:00 +00:00
|
|
|
void BKE_curve_editfont_free(Curve *cu)
|
2009-01-23 14:43:25 +00:00
|
|
|
{
|
2012-03-24 06:18:31 +00:00
|
|
|
if (cu->editfont) {
|
2012-05-06 15:15:33 +00:00
|
|
|
EditFont *ef = cu->editfont;
|
2012-05-07 08:53:59 +00:00
|
|
|
|
|
|
|
if (ef->textbuf)
|
|
|
|
MEM_freeN(ef->textbuf);
|
|
|
|
if (ef->textbufinfo)
|
|
|
|
MEM_freeN(ef->textbufinfo);
|
2014-01-07 17:04:19 +11:00
|
|
|
if (ef->selboxes)
|
|
|
|
MEM_freeN(ef->selboxes);
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2009-01-23 14:43:25 +00:00
|
|
|
MEM_freeN(ef);
|
2012-05-06 15:15:33 +00:00
|
|
|
cu->editfont = NULL;
|
2009-01-23 14:43:25 +00:00
|
|
|
}
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
Fix T50745: Shape key editing on bezier objects broken with Rendered Viewport Shading
So... Curve+shapekey was even more broken than it looked, this report was
actually a nice crasher (immediate crash in an ASAN build when trying to
edit a curve shapekey with some viewport rendering enabled).
There were actually two different issues here.
I) The less critical: rB6f1493f68fe was not fully fixing issues from
T50614. More specifically, if you updated obdata from editnurb
*without* freeing editnurb afterwards, you had a 'restored' (to
original curve) editnurb, without the edited shapekey modifications
anymore. This was fixed by tweaking again `calc_shapeKeys()` behavior in
`ED_curve_editnurb_load()`.
II) The crasher: in `ED_curve_editnurb_make()`, the call to
`init_editNurb_keyIndex()` was directly storing pointers of obdata
nurbs. Since those get freed every time `ED_curve_editnurb_load()` is
executed, it easily ended up being pointers to freed memory. This was
fixed by copying those data, which implied more complex handling code
for editnurbs->keyindex, and some reshuffling of a few functions to
avoid duplicating things between editor's editcurve.c and BKE's curve.c
Note that the separation of functions between editors and BKE area for
curve could use a serious update, it's currently messy to say the least.
Then again, that area is due to rework since a long time now... :/
Finally, aligned 'for_render' curve evaluation to mesh one - now
editing a shapekey will show in rendered viewports, if it does have some
weight (exactly as with shapekeys of meshes).
2017-02-22 21:20:50 +01:00
|
|
|
static void curve_editNurb_keyIndex_cv_free_cb(void *val)
|
2011-09-14 00:37:27 +00:00
|
|
|
{
|
Fix T50745: Shape key editing on bezier objects broken with Rendered Viewport Shading
So... Curve+shapekey was even more broken than it looked, this report was
actually a nice crasher (immediate crash in an ASAN build when trying to
edit a curve shapekey with some viewport rendering enabled).
There were actually two different issues here.
I) The less critical: rB6f1493f68fe was not fully fixing issues from
T50614. More specifically, if you updated obdata from editnurb
*without* freeing editnurb afterwards, you had a 'restored' (to
original curve) editnurb, without the edited shapekey modifications
anymore. This was fixed by tweaking again `calc_shapeKeys()` behavior in
`ED_curve_editnurb_load()`.
II) The crasher: in `ED_curve_editnurb_make()`, the call to
`init_editNurb_keyIndex()` was directly storing pointers of obdata
nurbs. Since those get freed every time `ED_curve_editnurb_load()` is
executed, it easily ended up being pointers to freed memory. This was
fixed by copying those data, which implied more complex handling code
for editnurbs->keyindex, and some reshuffling of a few functions to
avoid duplicating things between editor's editcurve.c and BKE's curve.c
Note that the separation of functions between editors and BKE area for
curve could use a serious update, it's currently messy to say the least.
Then again, that area is due to rework since a long time now... :/
Finally, aligned 'for_render' curve evaluation to mesh one - now
editing a shapekey will show in rendered viewports, if it does have some
weight (exactly as with shapekeys of meshes).
2017-02-22 21:20:50 +01:00
|
|
|
CVKeyIndex *index = val;
|
|
|
|
MEM_freeN(index->orig_cv);
|
|
|
|
MEM_freeN(val);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BKE_curve_editNurb_keyIndex_delCV(GHash *keyindex, const void *cv)
|
|
|
|
{
|
|
|
|
BLI_assert(keyindex != NULL);
|
|
|
|
BLI_ghash_remove(keyindex, cv, NULL, curve_editNurb_keyIndex_cv_free_cb);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BKE_curve_editNurb_keyIndex_free(GHash **keyindex)
|
|
|
|
{
|
|
|
|
if (!(*keyindex)) {
|
2011-09-14 00:37:27 +00:00
|
|
|
return;
|
|
|
|
}
|
Fix T50745: Shape key editing on bezier objects broken with Rendered Viewport Shading
So... Curve+shapekey was even more broken than it looked, this report was
actually a nice crasher (immediate crash in an ASAN build when trying to
edit a curve shapekey with some viewport rendering enabled).
There were actually two different issues here.
I) The less critical: rB6f1493f68fe was not fully fixing issues from
T50614. More specifically, if you updated obdata from editnurb
*without* freeing editnurb afterwards, you had a 'restored' (to
original curve) editnurb, without the edited shapekey modifications
anymore. This was fixed by tweaking again `calc_shapeKeys()` behavior in
`ED_curve_editnurb_load()`.
II) The crasher: in `ED_curve_editnurb_make()`, the call to
`init_editNurb_keyIndex()` was directly storing pointers of obdata
nurbs. Since those get freed every time `ED_curve_editnurb_load()` is
executed, it easily ended up being pointers to freed memory. This was
fixed by copying those data, which implied more complex handling code
for editnurbs->keyindex, and some reshuffling of a few functions to
avoid duplicating things between editor's editcurve.c and BKE's curve.c
Note that the separation of functions between editors and BKE area for
curve could use a serious update, it's currently messy to say the least.
Then again, that area is due to rework since a long time now... :/
Finally, aligned 'for_render' curve evaluation to mesh one - now
editing a shapekey will show in rendered viewports, if it does have some
weight (exactly as with shapekeys of meshes).
2017-02-22 21:20:50 +01:00
|
|
|
BLI_ghash_free(*keyindex, NULL, curve_editNurb_keyIndex_cv_free_cb);
|
|
|
|
*keyindex = NULL;
|
2011-09-14 00:37:27 +00:00
|
|
|
}
|
|
|
|
|
2012-04-29 17:11:40 +00:00
|
|
|
void BKE_curve_editNurb_free(Curve *cu)
|
2011-09-14 00:37:27 +00:00
|
|
|
{
|
2012-03-24 06:18:31 +00:00
|
|
|
if (cu->editnurb) {
|
2012-04-28 16:49:00 +00:00
|
|
|
BKE_nurbList_free(&cu->editnurb->nurbs);
|
Fix T50745: Shape key editing on bezier objects broken with Rendered Viewport Shading
So... Curve+shapekey was even more broken than it looked, this report was
actually a nice crasher (immediate crash in an ASAN build when trying to
edit a curve shapekey with some viewport rendering enabled).
There were actually two different issues here.
I) The less critical: rB6f1493f68fe was not fully fixing issues from
T50614. More specifically, if you updated obdata from editnurb
*without* freeing editnurb afterwards, you had a 'restored' (to
original curve) editnurb, without the edited shapekey modifications
anymore. This was fixed by tweaking again `calc_shapeKeys()` behavior in
`ED_curve_editnurb_load()`.
II) The crasher: in `ED_curve_editnurb_make()`, the call to
`init_editNurb_keyIndex()` was directly storing pointers of obdata
nurbs. Since those get freed every time `ED_curve_editnurb_load()` is
executed, it easily ended up being pointers to freed memory. This was
fixed by copying those data, which implied more complex handling code
for editnurbs->keyindex, and some reshuffling of a few functions to
avoid duplicating things between editor's editcurve.c and BKE's curve.c
Note that the separation of functions between editors and BKE area for
curve could use a serious update, it's currently messy to say the least.
Then again, that area is due to rework since a long time now... :/
Finally, aligned 'for_render' curve evaluation to mesh one - now
editing a shapekey will show in rendered viewports, if it does have some
weight (exactly as with shapekeys of meshes).
2017-02-22 21:20:50 +01:00
|
|
|
BKE_curve_editNurb_keyIndex_free(&cu->editnurb->keyindex);
|
2011-09-14 00:37:27 +00:00
|
|
|
MEM_freeN(cu->editnurb);
|
2012-05-06 15:15:33 +00:00
|
|
|
cu->editnurb = NULL;
|
2011-09-14 00:37:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
ID-Remap - Step one: core work (cleanup and rework of generic ID datablock handling).
This commit changes a lot of how IDs are handled internally, especially the unlinking/freeing
processes. So far, this was very fuzy, to summarize cleanly deleting or replacing a datablock
was pretty much impossible, except for a few special cases.
Also, unlinking was handled by each datatype, in a rather messy and prone-to-errors way (quite
a few ID usages were missed or wrongly handled that way).
One of the main goal of id-remap branch was to cleanup this, and fatorize ID links handling
by using library_query utils to allow generic handling of those, which is now the case
(now, generic ID links handling is only "knwon" from readfile.c and library_query.c).
This commit also adds backends to allow live replacement and deletion of datablocks in Blender
(so-called 'remapping' process, where we replace all usages of a given ID pointer by a new one,
or NULL one in case of unlinking).
This will allow nice new features, like ability to easily reload or relocate libraries, real immediate
deletion of datablocks in blender, replacement of one datablock by another, etc.
Some of those are for next commits.
A word of warning: this commit is highly risky, because it affects potentially a lot in Blender core.
Though it was tested rather deeply, being totally impossible to check all possible ID usage cases,
it's likely there are some remaining issues and bugs in new code... Please report them! ;)
Review task: D2027 (https://developer.blender.org/D2027).
Reviewed by campbellbarton, thanks a bunch.
2016-06-22 17:29:38 +02:00
|
|
|
/** Free (or release) any data used by this curve (does not free the curve itself). */
|
2012-04-28 16:49:00 +00:00
|
|
|
void BKE_curve_free(Curve *cu)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
ID-Remap - Step one: core work (cleanup and rework of generic ID datablock handling).
This commit changes a lot of how IDs are handled internally, especially the unlinking/freeing
processes. So far, this was very fuzy, to summarize cleanly deleting or replacing a datablock
was pretty much impossible, except for a few special cases.
Also, unlinking was handled by each datatype, in a rather messy and prone-to-errors way (quite
a few ID usages were missed or wrongly handled that way).
One of the main goal of id-remap branch was to cleanup this, and fatorize ID links handling
by using library_query utils to allow generic handling of those, which is now the case
(now, generic ID links handling is only "knwon" from readfile.c and library_query.c).
This commit also adds backends to allow live replacement and deletion of datablocks in Blender
(so-called 'remapping' process, where we replace all usages of a given ID pointer by a new one,
or NULL one in case of unlinking).
This will allow nice new features, like ability to easily reload or relocate libraries, real immediate
deletion of datablocks in blender, replacement of one datablock by another, etc.
Some of those are for next commits.
A word of warning: this commit is highly risky, because it affects potentially a lot in Blender core.
Though it was tested rather deeply, being totally impossible to check all possible ID usage cases,
it's likely there are some remaining issues and bugs in new code... Please report them! ;)
Review task: D2027 (https://developer.blender.org/D2027).
Reviewed by campbellbarton, thanks a bunch.
2016-06-22 17:29:38 +02:00
|
|
|
BKE_animdata_free((ID *)cu, false);
|
|
|
|
|
2017-04-15 16:46:17 +10:00
|
|
|
BKE_curve_batch_cache_free(cu);
|
|
|
|
|
2012-04-28 16:49:00 +00:00
|
|
|
BKE_nurbList_free(&cu->nurb);
|
|
|
|
BKE_curve_editfont_free(cu);
|
2009-01-14 12:26:45 +00:00
|
|
|
|
2012-04-28 16:49:00 +00:00
|
|
|
BKE_curve_editNurb_free(cu);
|
ID-Remap - Step one: core work (cleanup and rework of generic ID datablock handling).
This commit changes a lot of how IDs are handled internally, especially the unlinking/freeing
processes. So far, this was very fuzy, to summarize cleanly deleting or replacing a datablock
was pretty much impossible, except for a few special cases.
Also, unlinking was handled by each datatype, in a rather messy and prone-to-errors way (quite
a few ID usages were missed or wrongly handled that way).
One of the main goal of id-remap branch was to cleanup this, and fatorize ID links handling
by using library_query utils to allow generic handling of those, which is now the case
(now, generic ID links handling is only "knwon" from readfile.c and library_query.c).
This commit also adds backends to allow live replacement and deletion of datablocks in Blender
(so-called 'remapping' process, where we replace all usages of a given ID pointer by a new one,
or NULL one in case of unlinking).
This will allow nice new features, like ability to easily reload or relocate libraries, real immediate
deletion of datablocks in blender, replacement of one datablock by another, etc.
Some of those are for next commits.
A word of warning: this commit is highly risky, because it affects potentially a lot in Blender core.
Though it was tested rather deeply, being totally impossible to check all possible ID usage cases,
it's likely there are some remaining issues and bugs in new code... Please report them! ;)
Review task: D2027 (https://developer.blender.org/D2027).
Reviewed by campbellbarton, thanks a bunch.
2016-06-22 17:29:38 +02:00
|
|
|
|
|
|
|
MEM_SAFE_FREE(cu->mat);
|
|
|
|
MEM_SAFE_FREE(cu->str);
|
|
|
|
MEM_SAFE_FREE(cu->strinfo);
|
|
|
|
MEM_SAFE_FREE(cu->bb);
|
|
|
|
MEM_SAFE_FREE(cu->tb);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
First step to handle missing libs/datablocks when reading a file.
Idea is, instead of ignoring completely missing linked datablocks, to
create void placeholders for them.
That way, you can work on your file, save it, and find again your missing data once
lib becomes available again. Or you can edit missing lib's path (in Outliner),
save and reload the file, and you are done.
Also, Outliner now shows broken libraries (and placeholders) with a 'broken lib' icon.
Future plans are also to be able to relocate missing libs and reload them at runtime.
Code notes:
- Placeholder ID is just a regular datablock of same type as expected linked one,
with 'default' data, and a LIB_MISSING bitflag set.
- To allow creation of such datablocks, creation of datablocks in BKE was split in two step:
+ Allocation of memory itself.
+ Setting of all internal data to default values.
See also the design task (T43351).
Reviewed by @campbellbarton, thanks a bunch!
Differential Revision: https://developer.blender.org/D1394
2015-10-20 14:44:57 +02:00
|
|
|
void BKE_curve_init(Curve *cu)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
First step to handle missing libs/datablocks when reading a file.
Idea is, instead of ignoring completely missing linked datablocks, to
create void placeholders for them.
That way, you can work on your file, save it, and find again your missing data once
lib becomes available again. Or you can edit missing lib's path (in Outliner),
save and reload the file, and you are done.
Also, Outliner now shows broken libraries (and placeholders) with a 'broken lib' icon.
Future plans are also to be able to relocate missing libs and reload them at runtime.
Code notes:
- Placeholder ID is just a regular datablock of same type as expected linked one,
with 'default' data, and a LIB_MISSING bitflag set.
- To allow creation of such datablocks, creation of datablocks in BKE was split in two step:
+ Allocation of memory itself.
+ Setting of all internal data to default values.
See also the design task (T43351).
Reviewed by @campbellbarton, thanks a bunch!
Differential Revision: https://developer.blender.org/D1394
2015-10-20 14:44:57 +02:00
|
|
|
/* BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(cu, id)); */ /* cu->type is already initialized... */
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-03-23 20:18:09 +00:00
|
|
|
copy_v3_fl(cu->size, 1.0f);
|
2012-05-06 15:15:33 +00:00
|
|
|
cu->flag = CU_FRONT | CU_BACK | CU_DEFORM_BOUNDS_OFF | CU_PATH_RADIUS;
|
|
|
|
cu->pathlen = 100;
|
First step to handle missing libs/datablocks when reading a file.
Idea is, instead of ignoring completely missing linked datablocks, to
create void placeholders for them.
That way, you can work on your file, save it, and find again your missing data once
lib becomes available again. Or you can edit missing lib's path (in Outliner),
save and reload the file, and you are done.
Also, Outliner now shows broken libraries (and placeholders) with a 'broken lib' icon.
Future plans are also to be able to relocate missing libs and reload them at runtime.
Code notes:
- Placeholder ID is just a regular datablock of same type as expected linked one,
with 'default' data, and a LIB_MISSING bitflag set.
- To allow creation of such datablocks, creation of datablocks in BKE was split in two step:
+ Allocation of memory itself.
+ Setting of all internal data to default values.
See also the design task (T43351).
Reviewed by @campbellbarton, thanks a bunch!
Differential Revision: https://developer.blender.org/D1394
2015-10-20 14:44:57 +02:00
|
|
|
cu->resolu = cu->resolv = (cu->type == OB_SURF) ? 4 : 12;
|
2012-05-06 15:15:33 +00:00
|
|
|
cu->width = 1.0;
|
2005-06-17 21:04:27 +00:00
|
|
|
cu->wordspace = 1.0;
|
2012-05-06 15:15:33 +00:00
|
|
|
cu->spacing = cu->linedist = 1.0;
|
|
|
|
cu->fsize = 1.0;
|
2012-05-07 08:53:59 +00:00
|
|
|
cu->ulheight = 0.05;
|
2012-05-06 15:15:33 +00:00
|
|
|
cu->texflag = CU_AUTOSPACE;
|
|
|
|
cu->smallcaps_scale = 0.75f;
|
2012-05-07 08:53:59 +00:00
|
|
|
/* XXX: this one seems to be the best one in most cases, at least for curve deform... */
|
|
|
|
cu->twist_mode = CU_TWIST_MINIMUM;
|
2012-05-06 15:15:33 +00:00
|
|
|
cu->bevfac1 = 0.0f;
|
|
|
|
cu->bevfac2 = 1.0f;
|
2014-03-28 16:41:56 +06:00
|
|
|
cu->bevfac1_mapping = CU_BEVFAC_MAP_RESOLU;
|
|
|
|
cu->bevfac2_mapping = CU_BEVFAC_MAP_RESOLU;
|
2012-05-06 15:15:33 +00:00
|
|
|
|
|
|
|
cu->bb = BKE_boundbox_alloc_unit();
|
|
|
|
|
First step to handle missing libs/datablocks when reading a file.
Idea is, instead of ignoring completely missing linked datablocks, to
create void placeholders for them.
That way, you can work on your file, save it, and find again your missing data once
lib becomes available again. Or you can edit missing lib's path (in Outliner),
save and reload the file, and you are done.
Also, Outliner now shows broken libraries (and placeholders) with a 'broken lib' icon.
Future plans are also to be able to relocate missing libs and reload them at runtime.
Code notes:
- Placeholder ID is just a regular datablock of same type as expected linked one,
with 'default' data, and a LIB_MISSING bitflag set.
- To allow creation of such datablocks, creation of datablocks in BKE was split in two step:
+ Allocation of memory itself.
+ Setting of all internal data to default values.
See also the design task (T43351).
Reviewed by @campbellbarton, thanks a bunch!
Differential Revision: https://developer.blender.org/D1394
2015-10-20 14:44:57 +02:00
|
|
|
if (cu->type == OB_FONT) {
|
2012-05-06 15:15:33 +00:00
|
|
|
cu->vfont = cu->vfontb = cu->vfonti = cu->vfontbi = BKE_vfont_builtin_get();
|
|
|
|
cu->vfont->id.us += 4;
|
2018-01-14 22:14:20 +01:00
|
|
|
cu->str = MEM_malloc_arrayN(12, sizeof(unsigned char), "str");
|
2010-11-05 07:35:21 +00:00
|
|
|
BLI_strncpy(cu->str, "Text", 12);
|
2014-01-03 17:04:42 +11:00
|
|
|
cu->len = cu->len_wchar = cu->pos = 4;
|
2018-01-14 22:14:20 +01:00
|
|
|
cu->strinfo = MEM_calloc_arrayN(12, sizeof(CharInfo), "strinfo new");
|
2012-05-06 15:15:33 +00:00
|
|
|
cu->totbox = cu->actbox = 1;
|
2018-01-14 22:14:20 +01:00
|
|
|
cu->tb = MEM_calloc_arrayN(MAXTEXTBOX, sizeof(TextBox), "textbox");
|
2009-01-23 14:43:25 +00:00
|
|
|
cu->tb[0].w = cu->tb[0].h = 0.0;
|
|
|
|
}
|
First step to handle missing libs/datablocks when reading a file.
Idea is, instead of ignoring completely missing linked datablocks, to
create void placeholders for them.
That way, you can work on your file, save it, and find again your missing data once
lib becomes available again. Or you can edit missing lib's path (in Outliner),
save and reload the file, and you are done.
Also, Outliner now shows broken libraries (and placeholders) with a 'broken lib' icon.
Future plans are also to be able to relocate missing libs and reload them at runtime.
Code notes:
- Placeholder ID is just a regular datablock of same type as expected linked one,
with 'default' data, and a LIB_MISSING bitflag set.
- To allow creation of such datablocks, creation of datablocks in BKE was split in two step:
+ Allocation of memory itself.
+ Setting of all internal data to default values.
See also the design task (T43351).
Reviewed by @campbellbarton, thanks a bunch!
Differential Revision: https://developer.blender.org/D1394
2015-10-20 14:44:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Curve *BKE_curve_add(Main *bmain, const char *name, int type)
|
|
|
|
{
|
|
|
|
Curve *cu;
|
|
|
|
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
cu = BKE_libblock_alloc(bmain, ID_CU, name, 0);
|
First step to handle missing libs/datablocks when reading a file.
Idea is, instead of ignoring completely missing linked datablocks, to
create void placeholders for them.
That way, you can work on your file, save it, and find again your missing data once
lib becomes available again. Or you can edit missing lib's path (in Outliner),
save and reload the file, and you are done.
Also, Outliner now shows broken libraries (and placeholders) with a 'broken lib' icon.
Future plans are also to be able to relocate missing libs and reload them at runtime.
Code notes:
- Placeholder ID is just a regular datablock of same type as expected linked one,
with 'default' data, and a LIB_MISSING bitflag set.
- To allow creation of such datablocks, creation of datablocks in BKE was split in two step:
+ Allocation of memory itself.
+ Setting of all internal data to default values.
See also the design task (T43351).
Reviewed by @campbellbarton, thanks a bunch!
Differential Revision: https://developer.blender.org/D1394
2015-10-20 14:44:57 +02:00
|
|
|
cu->type = type;
|
|
|
|
|
|
|
|
BKE_curve_init(cu);
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
return cu;
|
|
|
|
}
|
|
|
|
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
/**
|
|
|
|
* Only copy internal data of Curve ID from source to already allocated/initialized destination.
|
|
|
|
* You probably nerver want to use that directly, use id_copy or BKE_id_copy_ex for typical needs.
|
|
|
|
*
|
|
|
|
* WARNING! This function will not handle ID user count!
|
|
|
|
*
|
|
|
|
* \param flag Copying options (see BKE_library.h's LIB_ID_COPY_... flags for more).
|
|
|
|
*/
|
|
|
|
void BKE_curve_copy_data(Main *bmain, Curve *cu_dst, const Curve *cu_src, const int flag)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
BLI_listbase_clear(&cu_dst->nurb);
|
|
|
|
BKE_nurbList_duplicate(&(cu_dst->nurb), &(cu_src->nurb));
|
2002-10-12 11:37:38 +00:00
|
|
|
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
cu_dst->mat = MEM_dupallocN(cu_src->mat);
|
2012-05-07 08:53:59 +00:00
|
|
|
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
cu_dst->str = MEM_dupallocN(cu_src->str);
|
|
|
|
cu_dst->strinfo = MEM_dupallocN(cu_src->strinfo);
|
|
|
|
cu_dst->tb = MEM_dupallocN(cu_src->tb);
|
|
|
|
cu_dst->bb = MEM_dupallocN(cu_src->bb);
|
|
|
|
cu_dst->batch_cache = NULL;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2018-05-14 14:23:11 +02:00
|
|
|
if (cu_src->key && (flag & LIB_ID_COPY_SHAPEKEY)) {
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
BKE_id_copy_ex(bmain, &cu_src->key->id, (ID **)&cu_dst->key, flag, false);
|
2016-07-09 14:44:48 +02:00
|
|
|
}
|
2.5: Most curve/surface editmode operators back:
* Hide, Reveal
* Separate, Duplicate, Delete
* Set Weight, Set Radius, Set Spline Type, Set Handle Type, Set Smooth
* Tilt, Clear Tilt
* Smooth, Smooth Radius
* De(select) First, De(select) Last, De(select) All, Select Inverse,
Select Linked, Select Control Point Row, Select Next, Select Previous,
Select More, Select Less, Select Random, Select Every Nth
* Switch Direction, Subdivide, Make Segment, Spin, Extrude, Toggle Cyclic
* Specials Menu
Not working correct yet:
* Add Vertex (ctrl click)
* Add Menu
2009-02-12 22:12:21 +00:00
|
|
|
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
cu_dst->editnurb = NULL;
|
|
|
|
cu_dst->editfont = NULL;
|
|
|
|
}
|
2015-01-09 09:52:51 +01:00
|
|
|
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
Curve *BKE_curve_copy(Main *bmain, const Curve *cu)
|
|
|
|
{
|
|
|
|
Curve *cu_copy;
|
2018-05-14 14:23:11 +02:00
|
|
|
BKE_id_copy_ex(bmain, &cu->id, (ID **)&cu_copy, LIB_ID_COPY_SHAPEKEY, false);
|
Refactor ID copying (and to some extent, ID freeing).
This will allow much finer controll over how we copy data-blocks, from
full copy in Main database, to "lighter" ones (out of Main, inside an
already allocated datablock, etc.).
This commit also transfers a llot of what was previously handled by
per-ID-type custom code to generic ID handling code in BKE_library.
Hopefully will avoid in future inconsistencies and missing bits we had
all over the codebase in the past.
It also adds missing copying handling for a few types, most notably
Scene (which where using a fully customized handling previously).
Note that the type of allocation used during copying (regular in Main,
allocated but outside of Main, or not allocated by ID handling code at
all) is stored in ID's, which allows to handle them correctly when
freeing. This needs to be taken care of with caution when doing 'weird'
unusual things with ID copying and/or allocation!
As a final note, while rather noisy, this commit will hopefully not
break too much existing branches, old 'API' has been kept for the main
part, as a wrapper around new code. Cleaning it up will happen later.
Design task : T51804
Phab Diff: D2714
2017-08-07 16:39:55 +02:00
|
|
|
return cu_copy;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2016-07-20 19:49:45 +02:00
|
|
|
void BKE_curve_make_local(Main *bmain, Curve *cu, const bool lib_local)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2016-07-20 19:49:45 +02:00
|
|
|
BKE_id_make_local_generic(bmain, &cu->id, true, lib_local);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2011-09-14 00:37:27 +00:00
|
|
|
/* Get list of nurbs from editnurbs structure */
|
2012-04-28 16:49:00 +00:00
|
|
|
ListBase *BKE_curve_editNurbs_get(Curve *cu)
|
2011-09-14 00:37:27 +00:00
|
|
|
{
|
|
|
|
if (cu->editnurb) {
|
|
|
|
return &cu->editnurb->nurbs;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-04-28 16:49:00 +00:00
|
|
|
short BKE_curve_type_get(Curve *cu)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
Nurb *nu;
|
2012-05-06 15:15:33 +00:00
|
|
|
int type = cu->type;
|
2011-11-24 14:30:37 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (cu->vfont) {
|
2007-03-27 11:37:54 +00:00
|
|
|
return OB_FONT;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2011-11-24 14:30:37 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (!cu->type) {
|
2012-05-06 15:15:33 +00:00
|
|
|
type = OB_CURVE;
|
2011-11-24 14:30:37 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
for (nu = cu->nurb.first; nu; nu = nu->next) {
|
|
|
|
if (nu->pntsv > 1) {
|
|
|
|
type = OB_SURF;
|
2011-11-24 14:30:37 +00:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
2011-11-24 14:30:37 +00:00
|
|
|
|
|
|
|
return type;
|
2007-03-27 11:37:54 +00:00
|
|
|
}
|
|
|
|
|
2012-04-28 16:49:00 +00:00
|
|
|
void BKE_curve_curve_dimension_update(Curve *cu)
|
2011-11-03 16:16:19 +00:00
|
|
|
{
|
2012-05-06 15:15:33 +00:00
|
|
|
ListBase *nurbs = BKE_curve_nurbs_get(cu);
|
|
|
|
Nurb *nu = nurbs->first;
|
2011-11-03 16:16:19 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
if (cu->flag & CU_3D) {
|
|
|
|
for (; nu; nu = nu->next) {
|
2011-11-03 16:16:19 +00:00
|
|
|
nu->flag &= ~CU_2D;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2012-05-06 15:15:33 +00:00
|
|
|
for (; nu; nu = nu->next) {
|
2011-11-03 16:16:19 +00:00
|
|
|
nu->flag |= CU_2D;
|
2018-11-13 14:21:42 +11:00
|
|
|
BKE_nurb_test_2d(nu);
|
2011-11-03 16:16:19 +00:00
|
|
|
|
|
|
|
/* since the handles are moved they need to be auto-located again */
|
2012-03-24 06:18:31 +00:00
|
|
|
if (nu->type == CU_BEZIER)
|
2012-04-28 16:49:00 +00:00
|
|
|
BKE_nurb_handles_calc(nu);
|
2011-11-03 16:16:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-28 16:49:00 +00:00
|
|
|
void BKE_curve_type_test(Object *ob)
|
2011-11-03 16:16:19 +00:00
|
|
|
{
|
2012-05-06 15:15:33 +00:00
|
|
|
ob->type = BKE_curve_type_get(ob->data);
|
2011-11-03 16:16:19 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
if (ob->type == OB_CURVE)
|
2012-04-28 16:49:00 +00:00
|
|
|
BKE_curve_curve_dimension_update((Curve *)ob->data);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2013-08-21 07:40:19 +00:00
|
|
|
void BKE_curve_boundbox_calc(Curve *cu, float r_loc[3], float r_size[3])
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2013-08-21 07:40:19 +00:00
|
|
|
BoundBox *bb;
|
2013-08-19 09:13:15 +00:00
|
|
|
float min[3], max[3];
|
2013-08-21 07:40:19 +00:00
|
|
|
float mloc[3], msize[3];
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2013-08-21 07:40:19 +00:00
|
|
|
if (cu->bb == NULL) cu->bb = MEM_callocN(sizeof(BoundBox), "boundbox");
|
|
|
|
bb = cu->bb;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2013-08-21 07:40:19 +00:00
|
|
|
if (!r_loc) r_loc = mloc;
|
|
|
|
if (!r_size) r_size = msize;
|
2010-08-01 11:00:36 +00:00
|
|
|
|
2013-08-21 07:40:19 +00:00
|
|
|
INIT_MINMAX(min, max);
|
Move curve's boundbox and texspace calculation out of modifier stack
There were several issues with how bounding box and texture space
are calculated:
- This was done at the same time as applying modifiers, meaning if
several objects are sharing the same curve datablock, bounding
box and texture space will be calculated multiple times.
Further, allocating bounding box wasn't safe for threading.
- Bounding box and texture space were evaluated after pre-tessellation
modifiers are applied. This means Curve-level data is actually
depends on object data, and it's really bad because different
objects could have different modifiers and this leads to
conflicts (curve's data depends on object evaluation order)
and doesn't behave in a predictable way.
This commit moves bounding box and texture space evaluation from
modifier stack to own utility functions, just like it's was done
for meshes.
This makes curve objects update thread-safe, but gives some
limitations as well. Namely, with such approach it's not so
clear how to preserve the same behavior of texture space:
before this change texture space and bounding box would match
beveled curve as accurate as possible.
Old behavior was nice for quick texturing -- in most cases you
didn't need to modify texture space at all. But texture space
was depending on render/preview settings which could easily lead
to situations, when final result would be far different from
preview one.
Now we're using CV points coordinates and their radius to approximate
the bounding box. This doesn't give the same exact texture space,
but it helps a lot keeping texture space in a nice predictable way.
We could make approximation smarter in the future, but fir now
added operator to match texture space to fully tessellated curve
called "Match Texture Space".
Review link:
https://codereview.appspot.com/15410043/
Brief description:
http://wiki.blender.org/index.php/User:Nazg-gul/GSoC-2013/Results#Curve_Texture_Space
2013-10-20 14:41:33 +02:00
|
|
|
if (!BKE_curve_minmax(cu, true, min, max)) {
|
|
|
|
min[0] = min[1] = min[2] = -1.0f;
|
|
|
|
max[0] = max[1] = max[2] = 1.0f;
|
|
|
|
}
|
|
|
|
|
2013-08-21 07:40:19 +00:00
|
|
|
mid_v3_v3v3(r_loc, min, max);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2013-08-21 07:40:19 +00:00
|
|
|
r_size[0] = (max[0] - min[0]) / 2.0f;
|
|
|
|
r_size[1] = (max[1] - min[1]) / 2.0f;
|
|
|
|
r_size[2] = (max[2] - min[2]) / 2.0f;
|
2012-05-06 15:15:33 +00:00
|
|
|
|
2013-08-21 07:40:19 +00:00
|
|
|
BKE_boundbox_init_from_minmax(bb, min, max);
|
2012-05-06 15:15:33 +00:00
|
|
|
|
2013-08-21 07:40:19 +00:00
|
|
|
bb->flag &= ~BOUNDBOX_DIRTY;
|
2013-08-19 09:58:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BoundBox *BKE_curve_boundbox_get(Object *ob)
|
|
|
|
{
|
2018-11-25 17:16:11 +01:00
|
|
|
/* This is Object-level data access, DO NOT touch to Mesh's bb, would be totally thread-unsafe. */
|
|
|
|
if (ob->bb == NULL || ob->bb->flag & BOUNDBOX_DIRTY) {
|
|
|
|
Curve *cu = ob->data;
|
|
|
|
float min[3], max[3];
|
2013-08-19 09:58:28 +00:00
|
|
|
|
2018-11-25 17:16:11 +01:00
|
|
|
INIT_MINMAX(min, max);
|
|
|
|
BKE_curve_minmax(cu, true, min, max);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2018-11-25 17:16:11 +01:00
|
|
|
if (ob->bb == NULL) {
|
|
|
|
ob->bb = MEM_mallocN(sizeof(*ob->bb), __func__);
|
|
|
|
}
|
|
|
|
BKE_boundbox_init_from_minmax(ob->bb, min, max);
|
|
|
|
ob->bb->flag &= ~BOUNDBOX_DIRTY;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2013-08-19 09:58:28 +00:00
|
|
|
|
2018-11-25 17:16:11 +01:00
|
|
|
return ob->bb;
|
2013-08-19 09:58:28 +00:00
|
|
|
}
|
|
|
|
|
2013-08-21 07:40:19 +00:00
|
|
|
void BKE_curve_texspace_calc(Curve *cu)
|
|
|
|
{
|
|
|
|
float loc[3], size[3];
|
|
|
|
int a;
|
|
|
|
|
|
|
|
BKE_curve_boundbox_calc(cu, loc, size);
|
|
|
|
|
|
|
|
if (cu->texflag & CU_AUTOSPACE) {
|
|
|
|
for (a = 0; a < 3; a++) {
|
|
|
|
if (size[a] == 0.0f) size[a] = 1.0f;
|
|
|
|
else if (size[a] > 0.0f && size[a] < 0.00001f) size[a] = 0.00001f;
|
|
|
|
else if (size[a] < 0.0f && size[a] > -0.00001f) size[a] = -0.00001f;
|
|
|
|
}
|
|
|
|
|
|
|
|
copy_v3_v3(cu->loc, loc);
|
|
|
|
copy_v3_v3(cu->size, size);
|
|
|
|
zero_v3(cu->rot);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-21 13:06:29 -02:00
|
|
|
BoundBox *BKE_curve_texspace_get(Curve *cu, float r_loc[3], float r_rot[3], float r_size[3])
|
2013-08-19 09:58:28 +00:00
|
|
|
{
|
|
|
|
if (cu->bb == NULL || (cu->bb->flag & BOUNDBOX_DIRTY)) {
|
|
|
|
BKE_curve_texspace_calc(cu);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (r_loc) copy_v3_v3(r_loc, cu->loc);
|
|
|
|
if (r_rot) copy_v3_v3(r_rot, cu->rot);
|
|
|
|
if (r_size) copy_v3_v3(r_size, cu->size);
|
2018-11-21 13:06:29 -02:00
|
|
|
|
|
|
|
return cu->bb;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2014-04-01 11:34:00 +11:00
|
|
|
bool BKE_nurbList_index_get_co(ListBase *nurb, const int index, float r_co[3])
|
2012-09-16 08:25:31 +00:00
|
|
|
{
|
|
|
|
Nurb *nu;
|
|
|
|
int tot = 0;
|
|
|
|
|
|
|
|
for (nu = nurb->first; nu; nu = nu->next) {
|
|
|
|
int tot_nu;
|
|
|
|
if (nu->type == CU_BEZIER) {
|
|
|
|
tot_nu = nu->pntsu;
|
|
|
|
if (index - tot < tot_nu) {
|
|
|
|
copy_v3_v3(r_co, nu->bezt[index - tot].vec[1]);
|
2014-04-01 11:34:00 +11:00
|
|
|
return true;
|
2012-09-16 08:25:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
tot_nu = nu->pntsu * nu->pntsv;
|
|
|
|
if (index - tot < tot_nu) {
|
|
|
|
copy_v3_v3(r_co, nu->bp[index - tot].vec);
|
2014-04-01 11:34:00 +11:00
|
|
|
return true;
|
2012-09-16 08:25:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
tot += tot_nu;
|
|
|
|
}
|
|
|
|
|
2014-04-01 11:34:00 +11:00
|
|
|
return false;
|
2012-09-16 08:25:31 +00:00
|
|
|
}
|
|
|
|
|
2012-04-28 16:49:00 +00:00
|
|
|
int BKE_nurbList_verts_count(ListBase *nurb)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
Nurb *nu;
|
2012-05-06 15:15:33 +00:00
|
|
|
int tot = 0;
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
nu = nurb->first;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (nu) {
|
2012-05-07 08:53:59 +00:00
|
|
|
if (nu->bezt)
|
|
|
|
tot += 3 * nu->pntsu;
|
|
|
|
else if (nu->bp)
|
|
|
|
tot += nu->pntsu * nu->pntsv;
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
nu = nu->next;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
return tot;
|
|
|
|
}
|
|
|
|
|
2012-04-28 16:49:00 +00:00
|
|
|
int BKE_nurbList_verts_count_without_handles(ListBase *nurb)
|
2007-06-14 14:36:27 +00:00
|
|
|
{
|
|
|
|
Nurb *nu;
|
2012-05-06 15:15:33 +00:00
|
|
|
int tot = 0;
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
nu = nurb->first;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (nu) {
|
2012-05-07 08:53:59 +00:00
|
|
|
if (nu->bezt)
|
|
|
|
tot += nu->pntsu;
|
|
|
|
else if (nu->bp)
|
|
|
|
tot += nu->pntsu * nu->pntsv;
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
nu = nu->next;
|
2007-06-14 14:36:27 +00:00
|
|
|
}
|
|
|
|
return tot;
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
/* **************** NURBS ROUTINES ******************** */
|
|
|
|
|
2012-04-28 16:49:00 +00:00
|
|
|
void BKE_nurb_free(Nurb *nu)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
if (nu == NULL) return;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-07 08:53:59 +00:00
|
|
|
if (nu->bezt)
|
|
|
|
MEM_freeN(nu->bezt);
|
2012-05-06 15:15:33 +00:00
|
|
|
nu->bezt = NULL;
|
2012-05-07 08:53:59 +00:00
|
|
|
if (nu->bp)
|
|
|
|
MEM_freeN(nu->bp);
|
2012-05-06 15:15:33 +00:00
|
|
|
nu->bp = NULL;
|
2012-05-07 08:53:59 +00:00
|
|
|
if (nu->knotsu)
|
|
|
|
MEM_freeN(nu->knotsu);
|
2012-05-06 15:15:33 +00:00
|
|
|
nu->knotsu = NULL;
|
2012-05-07 08:53:59 +00:00
|
|
|
if (nu->knotsv)
|
|
|
|
MEM_freeN(nu->knotsv);
|
2012-05-06 15:15:33 +00:00
|
|
|
nu->knotsv = NULL;
|
2012-03-24 07:52:14 +00:00
|
|
|
/* if (nu->trim.first) freeNurblist(&(nu->trim)); */
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
MEM_freeN(nu);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-28 16:49:00 +00:00
|
|
|
void BKE_nurbList_free(ListBase *lb)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
Nurb *nu, *next;
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
if (lb == NULL) return;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
nu = lb->first;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (nu) {
|
2012-05-06 15:15:33 +00:00
|
|
|
next = nu->next;
|
2012-04-28 16:49:00 +00:00
|
|
|
BKE_nurb_free(nu);
|
2012-05-06 15:15:33 +00:00
|
|
|
nu = next;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2014-02-08 06:07:10 +11:00
|
|
|
BLI_listbase_clear(lb);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2017-06-14 22:36:30 +02:00
|
|
|
Nurb *BKE_nurb_duplicate(const Nurb *nu)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
Nurb *newnu;
|
|
|
|
int len;
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
newnu = (Nurb *)MEM_mallocN(sizeof(Nurb), "duplicateNurb");
|
|
|
|
if (newnu == NULL) return NULL;
|
2002-10-12 11:37:38 +00:00
|
|
|
memcpy(newnu, nu, sizeof(Nurb));
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (nu->bezt) {
|
2012-05-06 15:15:33 +00:00
|
|
|
newnu->bezt =
|
2018-01-14 22:14:20 +01:00
|
|
|
(BezTriple *)MEM_malloc_arrayN(nu->pntsu, sizeof(BezTriple), "duplicateNurb2");
|
2012-05-06 15:15:33 +00:00
|
|
|
memcpy(newnu->bezt, nu->bezt, nu->pntsu * sizeof(BezTriple));
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-05-06 15:15:33 +00:00
|
|
|
len = nu->pntsu * nu->pntsv;
|
|
|
|
newnu->bp =
|
2018-01-14 22:14:20 +01:00
|
|
|
(BPoint *)MEM_malloc_arrayN(len, sizeof(BPoint), "duplicateNurb3");
|
2012-05-06 15:15:33 +00:00
|
|
|
memcpy(newnu->bp, nu->bp, len * sizeof(BPoint));
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
newnu->knotsu = newnu->knotsv = NULL;
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (nu->knotsu) {
|
2012-05-06 15:15:33 +00:00
|
|
|
len = KNOTSU(nu);
|
2012-03-24 06:18:31 +00:00
|
|
|
if (len) {
|
2018-01-14 22:14:20 +01:00
|
|
|
newnu->knotsu = MEM_malloc_arrayN(len, sizeof(float), "duplicateNurb4");
|
2012-05-06 15:15:33 +00:00
|
|
|
memcpy(newnu->knotsu, nu->knotsu, sizeof(float) * len);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
2012-05-06 15:15:33 +00:00
|
|
|
if (nu->pntsv > 1 && nu->knotsv) {
|
|
|
|
len = KNOTSV(nu);
|
2012-03-24 06:18:31 +00:00
|
|
|
if (len) {
|
2018-01-14 22:14:20 +01:00
|
|
|
newnu->knotsv = MEM_malloc_arrayN(len, sizeof(float), "duplicateNurb5");
|
2012-05-06 15:15:33 +00:00
|
|
|
memcpy(newnu->knotsv, nu->knotsv, sizeof(float) * len);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return newnu;
|
|
|
|
}
|
|
|
|
|
2013-10-17 19:57:14 +00:00
|
|
|
/* copy the nurb but allow for different number of points (to be copied after this) */
|
|
|
|
Nurb *BKE_nurb_copy(Nurb *src, int pntsu, int pntsv)
|
|
|
|
{
|
|
|
|
Nurb *newnu = (Nurb *)MEM_mallocN(sizeof(Nurb), "copyNurb");
|
|
|
|
memcpy(newnu, src, sizeof(Nurb));
|
|
|
|
|
|
|
|
if (pntsu == 1) SWAP(int, pntsu, pntsv);
|
|
|
|
newnu->pntsu = pntsu;
|
|
|
|
newnu->pntsv = pntsv;
|
|
|
|
|
2015-01-26 18:21:44 +11:00
|
|
|
/* caller can manually handle these arrays */
|
|
|
|
newnu->knotsu = NULL;
|
|
|
|
newnu->knotsv = NULL;
|
|
|
|
|
2013-10-17 19:57:14 +00:00
|
|
|
if (src->bezt) {
|
2018-01-14 22:14:20 +01:00
|
|
|
newnu->bezt = (BezTriple *)MEM_malloc_arrayN(pntsu * pntsv, sizeof(BezTriple), "copyNurb2");
|
2013-10-17 19:57:14 +00:00
|
|
|
}
|
|
|
|
else {
|
2018-01-14 22:14:20 +01:00
|
|
|
newnu->bp = (BPoint *)MEM_malloc_arrayN(pntsu * pntsv, sizeof(BPoint), "copyNurb3");
|
2013-10-17 19:57:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return newnu;
|
|
|
|
}
|
|
|
|
|
2017-06-14 22:36:30 +02:00
|
|
|
void BKE_nurbList_duplicate(ListBase *lb1, const ListBase *lb2)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
Nurb *nu, *nun;
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2012-04-28 16:49:00 +00:00
|
|
|
BKE_nurbList_free(lb1);
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
nu = lb2->first;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (nu) {
|
2012-05-06 15:15:33 +00:00
|
|
|
nun = BKE_nurb_duplicate(nu);
|
2002-10-12 11:37:38 +00:00
|
|
|
BLI_addtail(lb1, nun);
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
nu = nu->next;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-13 14:21:42 +11:00
|
|
|
void BKE_nurb_test_2d(Nurb *nu)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
BezTriple *bezt;
|
|
|
|
BPoint *bp;
|
|
|
|
int a;
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
if ((nu->flag & CU_2D) == 0)
|
2009-09-08 00:23:33 +00:00
|
|
|
return;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (nu->type == CU_BEZIER) {
|
2012-05-06 15:15:33 +00:00
|
|
|
a = nu->pntsu;
|
|
|
|
bezt = nu->bezt;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (a--) {
|
2012-05-06 15:15:33 +00:00
|
|
|
bezt->vec[0][2] = 0.0;
|
|
|
|
bezt->vec[1][2] = 0.0;
|
|
|
|
bezt->vec[2][2] = 0.0;
|
2002-10-12 11:37:38 +00:00
|
|
|
bezt++;
|
|
|
|
}
|
|
|
|
}
|
2009-09-08 00:23:33 +00:00
|
|
|
else {
|
2012-05-06 15:15:33 +00:00
|
|
|
a = nu->pntsu * nu->pntsv;
|
|
|
|
bp = nu->bp;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (a--) {
|
2012-05-06 15:15:33 +00:00
|
|
|
bp->vec[2] = 0.0;
|
2002-10-12 11:37:38 +00:00
|
|
|
bp++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-13 09:33:46 +10:00
|
|
|
/**
|
|
|
|
* if use_radius is truth, minmax will take points' radius into account,
|
|
|
|
* which will make boundbox closer to beveled curve.
|
Move curve's boundbox and texspace calculation out of modifier stack
There were several issues with how bounding box and texture space
are calculated:
- This was done at the same time as applying modifiers, meaning if
several objects are sharing the same curve datablock, bounding
box and texture space will be calculated multiple times.
Further, allocating bounding box wasn't safe for threading.
- Bounding box and texture space were evaluated after pre-tessellation
modifiers are applied. This means Curve-level data is actually
depends on object data, and it's really bad because different
objects could have different modifiers and this leads to
conflicts (curve's data depends on object evaluation order)
and doesn't behave in a predictable way.
This commit moves bounding box and texture space evaluation from
modifier stack to own utility functions, just like it's was done
for meshes.
This makes curve objects update thread-safe, but gives some
limitations as well. Namely, with such approach it's not so
clear how to preserve the same behavior of texture space:
before this change texture space and bounding box would match
beveled curve as accurate as possible.
Old behavior was nice for quick texturing -- in most cases you
didn't need to modify texture space at all. But texture space
was depending on render/preview settings which could easily lead
to situations, when final result would be far different from
preview one.
Now we're using CV points coordinates and their radius to approximate
the bounding box. This doesn't give the same exact texture space,
but it helps a lot keeping texture space in a nice predictable way.
We could make approximation smarter in the future, but fir now
added operator to match texture space to fully tessellated curve
called "Match Texture Space".
Review link:
https://codereview.appspot.com/15410043/
Brief description:
http://wiki.blender.org/index.php/User:Nazg-gul/GSoC-2013/Results#Curve_Texture_Space
2013-10-20 14:41:33 +02:00
|
|
|
*/
|
|
|
|
void BKE_nurb_minmax(Nurb *nu, bool use_radius, float min[3], float max[3])
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
BezTriple *bezt;
|
|
|
|
BPoint *bp;
|
|
|
|
int a;
|
Move curve's boundbox and texspace calculation out of modifier stack
There were several issues with how bounding box and texture space
are calculated:
- This was done at the same time as applying modifiers, meaning if
several objects are sharing the same curve datablock, bounding
box and texture space will be calculated multiple times.
Further, allocating bounding box wasn't safe for threading.
- Bounding box and texture space were evaluated after pre-tessellation
modifiers are applied. This means Curve-level data is actually
depends on object data, and it's really bad because different
objects could have different modifiers and this leads to
conflicts (curve's data depends on object evaluation order)
and doesn't behave in a predictable way.
This commit moves bounding box and texture space evaluation from
modifier stack to own utility functions, just like it's was done
for meshes.
This makes curve objects update thread-safe, but gives some
limitations as well. Namely, with such approach it's not so
clear how to preserve the same behavior of texture space:
before this change texture space and bounding box would match
beveled curve as accurate as possible.
Old behavior was nice for quick texturing -- in most cases you
didn't need to modify texture space at all. But texture space
was depending on render/preview settings which could easily lead
to situations, when final result would be far different from
preview one.
Now we're using CV points coordinates and their radius to approximate
the bounding box. This doesn't give the same exact texture space,
but it helps a lot keeping texture space in a nice predictable way.
We could make approximation smarter in the future, but fir now
added operator to match texture space to fully tessellated curve
called "Match Texture Space".
Review link:
https://codereview.appspot.com/15410043/
Brief description:
http://wiki.blender.org/index.php/User:Nazg-gul/GSoC-2013/Results#Curve_Texture_Space
2013-10-20 14:41:33 +02:00
|
|
|
float point[3];
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (nu->type == CU_BEZIER) {
|
2012-05-06 15:15:33 +00:00
|
|
|
a = nu->pntsu;
|
|
|
|
bezt = nu->bezt;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (a--) {
|
Move curve's boundbox and texspace calculation out of modifier stack
There were several issues with how bounding box and texture space
are calculated:
- This was done at the same time as applying modifiers, meaning if
several objects are sharing the same curve datablock, bounding
box and texture space will be calculated multiple times.
Further, allocating bounding box wasn't safe for threading.
- Bounding box and texture space were evaluated after pre-tessellation
modifiers are applied. This means Curve-level data is actually
depends on object data, and it's really bad because different
objects could have different modifiers and this leads to
conflicts (curve's data depends on object evaluation order)
and doesn't behave in a predictable way.
This commit moves bounding box and texture space evaluation from
modifier stack to own utility functions, just like it's was done
for meshes.
This makes curve objects update thread-safe, but gives some
limitations as well. Namely, with such approach it's not so
clear how to preserve the same behavior of texture space:
before this change texture space and bounding box would match
beveled curve as accurate as possible.
Old behavior was nice for quick texturing -- in most cases you
didn't need to modify texture space at all. But texture space
was depending on render/preview settings which could easily lead
to situations, when final result would be far different from
preview one.
Now we're using CV points coordinates and their radius to approximate
the bounding box. This doesn't give the same exact texture space,
but it helps a lot keeping texture space in a nice predictable way.
We could make approximation smarter in the future, but fir now
added operator to match texture space to fully tessellated curve
called "Match Texture Space".
Review link:
https://codereview.appspot.com/15410043/
Brief description:
http://wiki.blender.org/index.php/User:Nazg-gul/GSoC-2013/Results#Curve_Texture_Space
2013-10-20 14:41:33 +02:00
|
|
|
if (use_radius) {
|
|
|
|
float radius_vector[3];
|
|
|
|
radius_vector[0] = radius_vector[1] = radius_vector[2] = bezt->radius;
|
|
|
|
|
|
|
|
add_v3_v3v3(point, bezt->vec[1], radius_vector);
|
|
|
|
minmax_v3v3_v3(min, max, point);
|
|
|
|
|
|
|
|
sub_v3_v3v3(point, bezt->vec[1], radius_vector);
|
|
|
|
minmax_v3v3_v3(min, max, point);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
minmax_v3v3_v3(min, max, bezt->vec[1]);
|
|
|
|
}
|
2012-05-13 11:05:52 +00:00
|
|
|
minmax_v3v3_v3(min, max, bezt->vec[0]);
|
|
|
|
minmax_v3v3_v3(min, max, bezt->vec[2]);
|
2002-10-12 11:37:38 +00:00
|
|
|
bezt++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2012-05-06 15:15:33 +00:00
|
|
|
a = nu->pntsu * nu->pntsv;
|
|
|
|
bp = nu->bp;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (a--) {
|
Move curve's boundbox and texspace calculation out of modifier stack
There were several issues with how bounding box and texture space
are calculated:
- This was done at the same time as applying modifiers, meaning if
several objects are sharing the same curve datablock, bounding
box and texture space will be calculated multiple times.
Further, allocating bounding box wasn't safe for threading.
- Bounding box and texture space were evaluated after pre-tessellation
modifiers are applied. This means Curve-level data is actually
depends on object data, and it's really bad because different
objects could have different modifiers and this leads to
conflicts (curve's data depends on object evaluation order)
and doesn't behave in a predictable way.
This commit moves bounding box and texture space evaluation from
modifier stack to own utility functions, just like it's was done
for meshes.
This makes curve objects update thread-safe, but gives some
limitations as well. Namely, with such approach it's not so
clear how to preserve the same behavior of texture space:
before this change texture space and bounding box would match
beveled curve as accurate as possible.
Old behavior was nice for quick texturing -- in most cases you
didn't need to modify texture space at all. But texture space
was depending on render/preview settings which could easily lead
to situations, when final result would be far different from
preview one.
Now we're using CV points coordinates and their radius to approximate
the bounding box. This doesn't give the same exact texture space,
but it helps a lot keeping texture space in a nice predictable way.
We could make approximation smarter in the future, but fir now
added operator to match texture space to fully tessellated curve
called "Match Texture Space".
Review link:
https://codereview.appspot.com/15410043/
Brief description:
http://wiki.blender.org/index.php/User:Nazg-gul/GSoC-2013/Results#Curve_Texture_Space
2013-10-20 14:41:33 +02:00
|
|
|
if (nu->pntsv == 1 && use_radius) {
|
|
|
|
float radius_vector[3];
|
|
|
|
radius_vector[0] = radius_vector[1] = radius_vector[2] = bp->radius;
|
|
|
|
|
|
|
|
add_v3_v3v3(point, bp->vec, radius_vector);
|
|
|
|
minmax_v3v3_v3(min, max, point);
|
|
|
|
|
|
|
|
sub_v3_v3v3(point, bp->vec, radius_vector);
|
|
|
|
minmax_v3v3_v3(min, max, point);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Surfaces doesn't use bevel, so no need to take radius into account. */
|
|
|
|
minmax_v3v3_v3(min, max, bp->vec);
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
bp++;
|
|
|
|
}
|
|
|
|
}
|
merge own commits into render branch into trunk since 27560
27562, 27570, 27571, 27574, 27576, 27577, 27579, 27590, 27591, 27594, 27595, 27596, 27599, 27605, 27611, 27612, 27613, 27614, 27623
2010-03-20 16:41:01 +00:00
|
|
|
}
|
|
|
|
|
2018-08-20 11:10:09 +10:00
|
|
|
float BKE_nurb_calc_length(const Nurb *nu, int resolution)
|
|
|
|
{
|
|
|
|
BezTriple *bezt, *prevbezt;
|
|
|
|
BPoint *bp, *prevbp;
|
|
|
|
int a, b;
|
|
|
|
float length = 0.0f;
|
|
|
|
int resolu = resolution ? resolution : nu->resolu;
|
|
|
|
int pntsu = nu->pntsu;
|
|
|
|
float *points, *pntsit, *prevpntsit;
|
|
|
|
|
|
|
|
if (nu->type == CU_POLY) {
|
|
|
|
a = nu->pntsu - 1;
|
|
|
|
bp = nu->bp;
|
|
|
|
if (nu->flagu & CU_NURB_CYCLIC) {
|
|
|
|
++a;
|
|
|
|
prevbp = nu->bp + (nu->pntsu - 1);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
prevbp = bp;
|
|
|
|
bp++;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (a--) {
|
|
|
|
length += len_v3v3(prevbp->vec, bp->vec);
|
|
|
|
prevbp = bp;
|
|
|
|
++bp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (nu->type == CU_BEZIER) {
|
|
|
|
points = MEM_mallocN(sizeof(float[3]) * (resolu + 1), "getLength_bezier");
|
|
|
|
a = nu->pntsu - 1;
|
|
|
|
bezt = nu->bezt;
|
|
|
|
if (nu->flagu & CU_NURB_CYCLIC) {
|
|
|
|
++a;
|
|
|
|
prevbezt = nu->bezt + (nu->pntsu - 1);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
prevbezt = bezt;
|
|
|
|
++bezt;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (a--) {
|
|
|
|
if (prevbezt->h2 == HD_VECT && bezt->h1 == HD_VECT) {
|
|
|
|
length += len_v3v3(prevbezt->vec[1], bezt->vec[1]);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
for (int j = 0; j < 3; j++) {
|
|
|
|
BKE_curve_forward_diff_bezier(
|
|
|
|
prevbezt->vec[1][j], prevbezt->vec[2][j],
|
|
|
|
bezt->vec[0][j], bezt->vec[1][j],
|
|
|
|
points + j, resolu, 3 * sizeof(float));
|
|
|
|
}
|
|
|
|
|
|
|
|
prevpntsit = pntsit = points;
|
|
|
|
b = resolu;
|
|
|
|
while (b--) {
|
|
|
|
pntsit += 3;
|
|
|
|
length += len_v3v3(prevpntsit, pntsit);
|
|
|
|
prevpntsit = pntsit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
prevbezt = bezt;
|
|
|
|
++bezt;
|
|
|
|
}
|
|
|
|
|
|
|
|
MEM_freeN(points);
|
|
|
|
}
|
|
|
|
else if (nu->type == CU_NURBS) {
|
|
|
|
if (nu->pntsv == 1) {
|
|
|
|
/* important to zero for BKE_nurb_makeCurve. */
|
|
|
|
points = MEM_callocN(sizeof(float[3]) * pntsu * resolu, "getLength_nurbs");
|
|
|
|
|
|
|
|
BKE_nurb_makeCurve(
|
|
|
|
nu, points,
|
|
|
|
NULL, NULL, NULL,
|
|
|
|
resolu, sizeof(float[3]));
|
|
|
|
|
|
|
|
if (nu->flagu & CU_NURB_CYCLIC) {
|
|
|
|
b = pntsu * resolu + 1;
|
|
|
|
prevpntsit = points + 3 * (pntsu * resolu - 1);
|
|
|
|
pntsit = points;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
b = (pntsu - 1) * resolu;
|
|
|
|
prevpntsit = points;
|
|
|
|
pntsit = points + 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (--b) {
|
|
|
|
length += len_v3v3(prevpntsit, pntsit);
|
|
|
|
prevpntsit = pntsit;
|
|
|
|
pntsit += 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
MEM_freeN(points);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return length;
|
|
|
|
}
|
|
|
|
|
merge own commits into render branch into trunk since 27560
27562, 27570, 27571, 27574, 27576, 27577, 27579, 27590, 27591, 27594, 27595, 27596, 27599, 27605, 27611, 27612, 27613, 27614, 27623
2010-03-20 16:41:01 +00:00
|
|
|
/* be sure to call makeknots after this */
|
2012-04-28 16:49:00 +00:00
|
|
|
void BKE_nurb_points_add(Nurb *nu, int number)
|
merge own commits into render branch into trunk since 27560
27562, 27570, 27571, 27574, 27576, 27577, 27579, 27590, 27591, 27594, 27595, 27596, 27599, 27605, 27611, 27612, 27613, 27614, 27623
2010-03-20 16:41:01 +00:00
|
|
|
{
|
2014-04-29 07:50:25 +10:00
|
|
|
BPoint *bp;
|
merge own commits into render branch into trunk since 27560
27562, 27570, 27571, 27574, 27576, 27577, 27579, 27590, 27591, 27594, 27595, 27596, 27599, 27605, 27611, 27612, 27613, 27614, 27623
2010-03-20 16:41:01 +00:00
|
|
|
int i;
|
|
|
|
|
2014-04-29 07:50:25 +10:00
|
|
|
nu->bp = MEM_recallocN(nu->bp, (nu->pntsu + number) * sizeof(BPoint));
|
merge own commits into render branch into trunk since 27560
27562, 27570, 27571, 27574, 27576, 27577, 27579, 27590, 27591, 27594, 27595, 27596, 27599, 27605, 27611, 27612, 27613, 27614, 27623
2010-03-20 16:41:01 +00:00
|
|
|
|
2014-04-29 07:50:25 +10:00
|
|
|
for (i = 0, bp = &nu->bp[nu->pntsu]; i < number; i++, bp++) {
|
|
|
|
bp->radius = 1.0f;
|
merge own commits into render branch into trunk since 27560
27562, 27570, 27571, 27574, 27576, 27577, 27579, 27590, 27591, 27594, 27595, 27596, 27599, 27605, 27611, 27612, 27613, 27614, 27623
2010-03-20 16:41:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nu->pntsu += number;
|
|
|
|
}
|
|
|
|
|
2012-04-28 16:49:00 +00:00
|
|
|
void BKE_nurb_bezierPoints_add(Nurb *nu, int number)
|
merge own commits into render branch into trunk since 27560
27562, 27570, 27571, 27574, 27576, 27577, 27579, 27590, 27591, 27594, 27595, 27596, 27599, 27605, 27611, 27612, 27613, 27614, 27623
2010-03-20 16:41:01 +00:00
|
|
|
{
|
2014-04-29 07:50:25 +10:00
|
|
|
BezTriple *bezt;
|
merge own commits into render branch into trunk since 27560
27562, 27570, 27571, 27574, 27576, 27577, 27579, 27590, 27591, 27594, 27595, 27596, 27599, 27605, 27611, 27612, 27613, 27614, 27623
2010-03-20 16:41:01 +00:00
|
|
|
int i;
|
|
|
|
|
2014-05-13 16:39:51 +02:00
|
|
|
nu->bezt = MEM_recallocN(nu->bezt, (nu->pntsu + number) * sizeof(BezTriple));
|
merge own commits into render branch into trunk since 27560
27562, 27570, 27571, 27574, 27576, 27577, 27579, 27590, 27591, 27594, 27595, 27596, 27599, 27605, 27611, 27612, 27613, 27614, 27623
2010-03-20 16:41:01 +00:00
|
|
|
|
2014-04-29 07:50:25 +10:00
|
|
|
for (i = 0, bezt = &nu->bezt[nu->pntsu]; i < number; i++, bezt++) {
|
|
|
|
bezt->radius = 1.0f;
|
merge own commits into render branch into trunk since 27560
27562, 27570, 27571, 27574, 27576, 27577, 27579, 27590, 27591, 27594, 27595, 27596, 27599, 27605, 27611, 27612, 27613, 27614, 27623
2010-03-20 16:41:01 +00:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
merge own commits into render branch into trunk since 27560
27562, 27570, 27571, 27574, 27576, 27577, 27579, 27590, 27591, 27594, 27595, 27596, 27599, 27605, 27611, 27612, 27613, 27614, 27623
2010-03-20 16:41:01 +00:00
|
|
|
nu->pntsu += number;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2013-07-24 13:56:36 +00:00
|
|
|
|
2015-07-09 13:14:09 +10:00
|
|
|
int BKE_nurb_index_from_uv(
|
|
|
|
Nurb *nu,
|
|
|
|
int u, int v)
|
|
|
|
{
|
|
|
|
const int totu = nu->pntsu;
|
|
|
|
const int totv = nu->pntsv;
|
|
|
|
|
|
|
|
if (nu->flagu & CU_NURB_CYCLIC) {
|
|
|
|
u = mod_i(u, totu);
|
|
|
|
}
|
|
|
|
else if (u < 0 || u >= totu) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nu->flagv & CU_NURB_CYCLIC) {
|
|
|
|
v = mod_i(v, totv);
|
|
|
|
}
|
|
|
|
else if (v < 0 || v >= totv) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (v * totu) + u;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BKE_nurb_index_to_uv(
|
|
|
|
Nurb *nu, int index,
|
|
|
|
int *r_u, int *r_v)
|
|
|
|
{
|
|
|
|
const int totu = nu->pntsu;
|
|
|
|
const int totv = nu->pntsv;
|
|
|
|
BLI_assert(index >= 0 && index < (nu->pntsu * nu->pntsv));
|
|
|
|
*r_u = (index % totu);
|
|
|
|
*r_v = (index / totu) % totv;
|
|
|
|
}
|
|
|
|
|
2013-07-24 13:56:36 +00:00
|
|
|
BezTriple *BKE_nurb_bezt_get_next(Nurb *nu, BezTriple *bezt)
|
|
|
|
{
|
|
|
|
BezTriple *bezt_next;
|
|
|
|
|
|
|
|
BLI_assert(ARRAY_HAS_ITEM(bezt, nu->bezt, nu->pntsu));
|
|
|
|
|
|
|
|
if (bezt == &nu->bezt[nu->pntsu - 1]) {
|
|
|
|
if (nu->flagu & CU_NURB_CYCLIC) {
|
|
|
|
bezt_next = nu->bezt;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
bezt_next = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
bezt_next = bezt + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return bezt_next;
|
|
|
|
}
|
|
|
|
|
|
|
|
BPoint *BKE_nurb_bpoint_get_next(Nurb *nu, BPoint *bp)
|
|
|
|
{
|
|
|
|
BPoint *bp_next;
|
|
|
|
|
|
|
|
BLI_assert(ARRAY_HAS_ITEM(bp, nu->bp, nu->pntsu));
|
|
|
|
|
|
|
|
if (bp == &nu->bp[nu->pntsu - 1]) {
|
|
|
|
if (nu->flagu & CU_NURB_CYCLIC) {
|
|
|
|
bp_next = nu->bp;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
bp_next = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
bp_next = bp + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return bp_next;
|
|
|
|
}
|
|
|
|
|
|
|
|
BezTriple *BKE_nurb_bezt_get_prev(Nurb *nu, BezTriple *bezt)
|
|
|
|
{
|
|
|
|
BezTriple *bezt_prev;
|
|
|
|
|
|
|
|
BLI_assert(ARRAY_HAS_ITEM(bezt, nu->bezt, nu->pntsu));
|
2017-10-14 17:54:43 +11:00
|
|
|
BLI_assert(nu->pntsv <= 1);
|
2013-07-24 13:56:36 +00:00
|
|
|
|
|
|
|
if (bezt == nu->bezt) {
|
|
|
|
if (nu->flagu & CU_NURB_CYCLIC) {
|
|
|
|
bezt_prev = &nu->bezt[nu->pntsu - 1];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
bezt_prev = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
bezt_prev = bezt - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return bezt_prev;
|
|
|
|
}
|
|
|
|
|
|
|
|
BPoint *BKE_nurb_bpoint_get_prev(Nurb *nu, BPoint *bp)
|
|
|
|
{
|
|
|
|
BPoint *bp_prev;
|
|
|
|
|
|
|
|
BLI_assert(ARRAY_HAS_ITEM(bp, nu->bp, nu->pntsu));
|
2017-07-10 16:27:15 +10:00
|
|
|
BLI_assert(nu->pntsv == 1);
|
2013-07-24 13:56:36 +00:00
|
|
|
|
|
|
|
if (bp == nu->bp) {
|
|
|
|
if (nu->flagu & CU_NURB_CYCLIC) {
|
|
|
|
bp_prev = &nu->bp[nu->pntsu - 1];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
bp_prev = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
bp_prev = bp - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return bp_prev;
|
|
|
|
}
|
|
|
|
|
2017-07-10 16:27:15 +10:00
|
|
|
void BKE_nurb_bezt_calc_normal(struct Nurb *UNUSED(nu), BezTriple *bezt, float r_normal[3])
|
2013-07-24 13:56:36 +00:00
|
|
|
{
|
|
|
|
/* calculate the axis matrix from the spline */
|
|
|
|
float dir_prev[3], dir_next[3];
|
|
|
|
|
|
|
|
sub_v3_v3v3(dir_prev, bezt->vec[0], bezt->vec[1]);
|
|
|
|
sub_v3_v3v3(dir_next, bezt->vec[1], bezt->vec[2]);
|
|
|
|
|
|
|
|
normalize_v3(dir_prev);
|
|
|
|
normalize_v3(dir_next);
|
|
|
|
|
|
|
|
add_v3_v3v3(r_normal, dir_prev, dir_next);
|
|
|
|
normalize_v3(r_normal);
|
|
|
|
}
|
|
|
|
|
2017-07-10 16:27:15 +10:00
|
|
|
void BKE_nurb_bezt_calc_plane(struct Nurb *nu, BezTriple *bezt, float r_plane[3])
|
2013-07-24 13:56:36 +00:00
|
|
|
{
|
|
|
|
float dir_prev[3], dir_next[3];
|
|
|
|
|
|
|
|
sub_v3_v3v3(dir_prev, bezt->vec[0], bezt->vec[1]);
|
|
|
|
sub_v3_v3v3(dir_next, bezt->vec[1], bezt->vec[2]);
|
|
|
|
|
|
|
|
normalize_v3(dir_prev);
|
|
|
|
normalize_v3(dir_next);
|
|
|
|
|
|
|
|
cross_v3_v3v3(r_plane, dir_prev, dir_next);
|
|
|
|
if (normalize_v3(r_plane) < FLT_EPSILON) {
|
|
|
|
BezTriple *bezt_prev = BKE_nurb_bezt_get_prev(nu, bezt);
|
|
|
|
BezTriple *bezt_next = BKE_nurb_bezt_get_next(nu, bezt);
|
|
|
|
|
|
|
|
if (bezt_prev) {
|
|
|
|
sub_v3_v3v3(dir_prev, bezt_prev->vec[1], bezt->vec[1]);
|
|
|
|
normalize_v3(dir_prev);
|
|
|
|
}
|
|
|
|
if (bezt_next) {
|
|
|
|
sub_v3_v3v3(dir_next, bezt->vec[1], bezt_next->vec[1]);
|
|
|
|
normalize_v3(dir_next);
|
|
|
|
}
|
|
|
|
cross_v3_v3v3(r_plane, dir_prev, dir_next);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* matches with bones more closely */
|
|
|
|
{
|
|
|
|
float dir_mid[3], tvec[3];
|
|
|
|
add_v3_v3v3(dir_mid, dir_prev, dir_next);
|
|
|
|
cross_v3_v3v3(tvec, r_plane, dir_mid);
|
|
|
|
copy_v3_v3(r_plane, tvec);
|
|
|
|
}
|
|
|
|
|
|
|
|
normalize_v3(r_plane);
|
|
|
|
}
|
|
|
|
|
2017-07-10 16:27:15 +10:00
|
|
|
void BKE_nurb_bpoint_calc_normal(struct Nurb *nu, BPoint *bp, float r_normal[3])
|
2015-07-09 02:56:04 +10:00
|
|
|
{
|
|
|
|
BPoint *bp_prev = BKE_nurb_bpoint_get_prev(nu, bp);
|
|
|
|
BPoint *bp_next = BKE_nurb_bpoint_get_next(nu, bp);
|
|
|
|
|
|
|
|
zero_v3(r_normal);
|
|
|
|
|
|
|
|
if (bp_prev) {
|
|
|
|
float dir_prev[3];
|
|
|
|
sub_v3_v3v3(dir_prev, bp_prev->vec, bp->vec);
|
|
|
|
normalize_v3(dir_prev);
|
|
|
|
add_v3_v3(r_normal, dir_prev);
|
|
|
|
}
|
|
|
|
if (bp_next) {
|
|
|
|
float dir_next[3];
|
|
|
|
sub_v3_v3v3(dir_next, bp->vec, bp_next->vec);
|
|
|
|
normalize_v3(dir_next);
|
|
|
|
add_v3_v3(r_normal, dir_next);
|
|
|
|
}
|
|
|
|
|
|
|
|
normalize_v3(r_normal);
|
|
|
|
}
|
|
|
|
|
2017-07-10 14:37:20 +10:00
|
|
|
void BKE_nurb_bpoint_calc_plane(struct Nurb *nu, BPoint *bp, float r_plane[3])
|
|
|
|
{
|
|
|
|
BPoint *bp_prev = BKE_nurb_bpoint_get_prev(nu, bp);
|
|
|
|
BPoint *bp_next = BKE_nurb_bpoint_get_next(nu, bp);
|
|
|
|
|
|
|
|
float dir_prev[3] = {0.0f}, dir_next[3] = {0.0f};
|
|
|
|
|
|
|
|
if (bp_prev) {
|
|
|
|
sub_v3_v3v3(dir_prev, bp_prev->vec, bp->vec);
|
|
|
|
normalize_v3(dir_prev);
|
|
|
|
}
|
|
|
|
if (bp_next) {
|
|
|
|
sub_v3_v3v3(dir_next, bp->vec, bp_next->vec);
|
|
|
|
normalize_v3(dir_next);
|
|
|
|
}
|
|
|
|
cross_v3_v3v3(r_plane, dir_prev, dir_next);
|
|
|
|
|
|
|
|
/* matches with bones more closely */
|
|
|
|
{
|
|
|
|
float dir_mid[3], tvec[3];
|
|
|
|
add_v3_v3v3(dir_mid, dir_prev, dir_next);
|
|
|
|
cross_v3_v3v3(tvec, r_plane, dir_mid);
|
|
|
|
copy_v3_v3(r_plane, tvec);
|
|
|
|
}
|
|
|
|
|
|
|
|
normalize_v3(r_plane);
|
|
|
|
}
|
|
|
|
|
2003-04-25 15:48:11 +00:00
|
|
|
/* ~~~~~~~~~~~~~~~~~~~~Non Uniform Rational B Spline calculations ~~~~~~~~~~~ */
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
|
2014-01-19 00:18:53 +06:00
|
|
|
static void calcknots(float *knots, const int pnts, const short order, const short flag)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2011-08-01 02:52:08 +00:00
|
|
|
/* knots: number of pnts NOT corrected for cyclic */
|
2012-05-06 15:15:33 +00:00
|
|
|
const int pnts_order = pnts + order;
|
2002-10-12 11:37:38 +00:00
|
|
|
float k;
|
2011-08-01 02:52:08 +00:00
|
|
|
int a;
|
2002-10-30 00:37:19 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
switch (flag & (CU_NURB_ENDPOINT | CU_NURB_BEZIER)) {
|
|
|
|
case CU_NURB_ENDPOINT:
|
|
|
|
k = 0.0;
|
|
|
|
for (a = 1; a <= pnts_order; a++) {
|
|
|
|
knots[a - 1] = k;
|
2012-05-07 08:53:59 +00:00
|
|
|
if (a >= order && a <= pnts)
|
|
|
|
k += 1.0f;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2012-05-06 15:15:33 +00:00
|
|
|
break;
|
|
|
|
case CU_NURB_BEZIER:
|
|
|
|
/* Warning, the order MUST be 2 or 4,
|
|
|
|
* if this is not enforced, the displist will be corrupt */
|
|
|
|
if (order == 4) {
|
|
|
|
k = 0.34;
|
|
|
|
for (a = 0; a < pnts_order; a++) {
|
|
|
|
knots[a] = floorf(k);
|
|
|
|
k += (1.0f / 3.0f);
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2012-05-06 15:15:33 +00:00
|
|
|
else if (order == 3) {
|
|
|
|
k = 0.6f;
|
|
|
|
for (a = 0; a < pnts_order; a++) {
|
2012-05-07 08:53:59 +00:00
|
|
|
if (a >= order && a <= pnts)
|
|
|
|
k += 0.5f;
|
2012-05-06 15:15:33 +00:00
|
|
|
knots[a] = floorf(k);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
printf("bez nurb curve order is not 3 or 4, should never happen\n");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
for (a = 0; a < pnts_order; a++) {
|
|
|
|
knots[a] = (float)a;
|
|
|
|
}
|
|
|
|
break;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-19 00:18:53 +06:00
|
|
|
static void makecyclicknots(float *knots, int pnts, short order)
|
2003-04-25 15:48:11 +00:00
|
|
|
/* pnts, order: number of pnts NOT corrected for cyclic */
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2002-10-30 00:37:19 +00:00
|
|
|
int a, b, order2, c;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-07 08:53:59 +00:00
|
|
|
if (knots == NULL)
|
|
|
|
return;
|
2008-05-26 12:50:00 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
order2 = order - 1;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2003-04-25 15:48:11 +00:00
|
|
|
/* do first long rows (order -1), remove identical knots at endpoints */
|
2012-05-06 15:15:33 +00:00
|
|
|
if (order > 2) {
|
|
|
|
b = pnts + order2;
|
|
|
|
for (a = 1; a < order2; a++) {
|
2012-05-07 08:53:59 +00:00
|
|
|
if (knots[b] != knots[b - a])
|
|
|
|
break;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2012-05-07 08:53:59 +00:00
|
|
|
if (a == order2)
|
|
|
|
knots[pnts + order - 2] += 1.0f;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
b = order;
|
|
|
|
c = pnts + order + order2;
|
|
|
|
for (a = pnts + order2; a < c; a++) {
|
|
|
|
knots[a] = knots[a - 1] + (knots[b] - knots[b - 1]);
|
2002-10-12 11:37:38 +00:00
|
|
|
b--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
|
2010-09-30 06:51:32 +00:00
|
|
|
static void makeknots(Nurb *nu, short uv)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2012-03-24 06:18:31 +00:00
|
|
|
if (nu->type == CU_NURBS) {
|
|
|
|
if (uv == 1) {
|
2012-05-07 08:53:59 +00:00
|
|
|
if (nu->knotsu)
|
|
|
|
MEM_freeN(nu->knotsu);
|
2012-04-28 16:49:00 +00:00
|
|
|
if (BKE_nurb_check_valid_u(nu)) {
|
2018-01-14 22:14:20 +01:00
|
|
|
nu->knotsu = MEM_calloc_arrayN(KNOTSU(nu) + 1, sizeof(float), "makeknots");
|
2012-03-24 06:18:31 +00:00
|
|
|
if (nu->flagu & CU_NURB_CYCLIC) {
|
2008-05-26 12:50:00 +00:00
|
|
|
calcknots(nu->knotsu, nu->pntsu, nu->orderu, 0); /* cyclic should be uniform */
|
|
|
|
makecyclicknots(nu->knotsu, nu->pntsu, nu->orderu);
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
|
|
|
else {
|
2011-08-01 02:52:08 +00:00
|
|
|
calcknots(nu->knotsu, nu->pntsu, nu->orderu, nu->flagu);
|
2008-05-26 12:50:00 +00:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2012-05-07 08:53:59 +00:00
|
|
|
else
|
|
|
|
nu->knotsu = NULL;
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
|
|
|
else if (uv == 2) {
|
2012-05-07 08:53:59 +00:00
|
|
|
if (nu->knotsv)
|
|
|
|
MEM_freeN(nu->knotsv);
|
2012-04-28 16:49:00 +00:00
|
|
|
if (BKE_nurb_check_valid_v(nu)) {
|
2018-01-14 22:14:20 +01:00
|
|
|
nu->knotsv = MEM_calloc_arrayN(KNOTSV(nu) + 1, sizeof(float), "makeknots");
|
2012-03-24 06:18:31 +00:00
|
|
|
if (nu->flagv & CU_NURB_CYCLIC) {
|
2008-05-26 12:50:00 +00:00
|
|
|
calcknots(nu->knotsv, nu->pntsv, nu->orderv, 0); /* cyclic should be uniform */
|
|
|
|
makecyclicknots(nu->knotsv, nu->pntsv, nu->orderv);
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
|
|
|
else {
|
2011-08-01 02:52:08 +00:00
|
|
|
calcknots(nu->knotsv, nu->pntsv, nu->orderv, nu->flagv);
|
2008-05-26 12:50:00 +00:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2013-03-09 03:46:30 +00:00
|
|
|
else {
|
|
|
|
nu->knotsv = NULL;
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-28 16:49:00 +00:00
|
|
|
void BKE_nurb_knot_calc_u(Nurb *nu)
|
2010-09-30 06:51:32 +00:00
|
|
|
{
|
|
|
|
makeknots(nu, 1);
|
|
|
|
}
|
|
|
|
|
2012-04-28 16:49:00 +00:00
|
|
|
void BKE_nurb_knot_calc_v(Nurb *nu)
|
2010-09-30 06:51:32 +00:00
|
|
|
{
|
|
|
|
makeknots(nu, 2);
|
|
|
|
}
|
|
|
|
|
2014-01-19 00:18:53 +06:00
|
|
|
static void basisNurb(float t, short order, int pnts, float *knots, float *basis, int *start, int *end)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
float d, e;
|
2012-04-29 15:47:02 +00:00
|
|
|
int i, i1 = 0, i2 = 0, j, orderpluspnts, opp2, o2;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
orderpluspnts = order + pnts;
|
|
|
|
opp2 = orderpluspnts - 1;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
/* this is for float inaccuracy */
|
2012-11-01 13:00:24 +00:00
|
|
|
if (t < knots[0])
|
|
|
|
t = knots[0];
|
2018-06-17 17:05:51 +02:00
|
|
|
else if (t > knots[opp2])
|
2012-11-01 13:00:24 +00:00
|
|
|
t = knots[opp2];
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2003-04-25 15:48:11 +00:00
|
|
|
/* this part is order '1' */
|
2012-05-06 15:15:33 +00:00
|
|
|
o2 = order + 1;
|
|
|
|
for (i = 0; i < opp2; i++) {
|
|
|
|
if (knots[i] != knots[i + 1] && t >= knots[i] && t <= knots[i + 1]) {
|
|
|
|
basis[i] = 1.0;
|
|
|
|
i1 = i - o2;
|
|
|
|
if (i1 < 0) i1 = 0;
|
|
|
|
i2 = i;
|
2002-10-12 11:37:38 +00:00
|
|
|
i++;
|
2012-05-06 15:15:33 +00:00
|
|
|
while (i < opp2) {
|
|
|
|
basis[i] = 0.0;
|
2002-10-12 11:37:38 +00:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2012-05-07 08:53:59 +00:00
|
|
|
else
|
|
|
|
basis[i] = 0.0;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2012-05-06 15:15:33 +00:00
|
|
|
basis[i] = 0.0;
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2012-04-29 15:47:02 +00:00
|
|
|
/* this is order 2, 3, ... */
|
2012-05-06 15:15:33 +00:00
|
|
|
for (j = 2; j <= order; j++) {
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
if (i2 + j >= orderpluspnts) i2 = opp2 - j;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
for (i = i1; i <= i2; i++) {
|
|
|
|
if (basis[i] != 0.0f)
|
|
|
|
d = ((t - knots[i]) * basis[i]) / (knots[i + j - 1] - knots[i]);
|
2002-10-12 11:37:38 +00:00
|
|
|
else
|
2012-05-06 15:15:33 +00:00
|
|
|
d = 0.0f;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
if (basis[i + 1] != 0.0f)
|
|
|
|
e = ((knots[i + j] - t) * basis[i + 1]) / (knots[i + j] - knots[i + 1]);
|
2002-10-12 11:37:38 +00:00
|
|
|
else
|
2012-05-06 15:15:33 +00:00
|
|
|
e = 0.0;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
basis[i] = d + e;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
*start = 1000;
|
|
|
|
*end = 0;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
for (i = i1; i <= i2; i++) {
|
2012-03-24 06:18:31 +00:00
|
|
|
if (basis[i] > 0.0f) {
|
2012-05-06 15:15:33 +00:00
|
|
|
*end = i;
|
|
|
|
if (*start == 1000) *start = i;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-20 11:10:09 +10:00
|
|
|
/**
|
|
|
|
* \param coord_array: has to be (3 * 4 * resolu * resolv) in size, and zero-ed.
|
|
|
|
*/
|
|
|
|
void BKE_nurb_makeFaces(const Nurb *nu, float *coord_array, int rowstride, int resolu, int resolv)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
BPoint *bp;
|
|
|
|
float *basisu, *basis, *basisv, *sum, *fp, *in;
|
|
|
|
float u, v, ustart, uend, ustep, vstart, vend, vstep, sumdiv;
|
2010-11-11 09:56:39 +00:00
|
|
|
int i, j, iofs, jofs, cycl, len, curu, curv;
|
2002-10-12 11:37:38 +00:00
|
|
|
int istart, iend, jsta, jen, *jstart, *jend, ratcomp;
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
int totu = nu->pntsu * resolu, totv = nu->pntsv * resolv;
|
2012-05-07 08:53:59 +00:00
|
|
|
|
|
|
|
if (nu->knotsu == NULL || nu->knotsv == NULL)
|
|
|
|
return;
|
|
|
|
if (nu->orderu > nu->pntsu)
|
|
|
|
return;
|
|
|
|
if (nu->orderv > nu->pntsv)
|
|
|
|
return;
|
|
|
|
if (coord_array == NULL)
|
|
|
|
return;
|
|
|
|
|
2003-04-25 15:48:11 +00:00
|
|
|
/* allocate and initialize */
|
2008-09-26 19:00:49 +00:00
|
|
|
len = totu * totv;
|
2012-05-07 08:53:59 +00:00
|
|
|
if (len == 0)
|
|
|
|
return;
|
More text object fancyness, and fixes:
- "Flush" is now split into two seperate Alignment modes "Flush" and
"Justify":
- Justify does exactly the same as a normal word processor's justify
function does, and in addition, it uses *whitespace* instead of
*character spacing* (kerning) to fill lines. Much more readable.
- Flush is pretty much the old Blender "Flush" mode - and as such it
uses character spacing to fill lines. Just as Justify, this only
works with at least one textframe.
- Underlining for text objects. Not a lot to explain. New button "U" in
the editbuttons, and CTRL-U as hotkey toggle underlining for newly
entered characters or for the selection, just like CTRL-B/CTRL-I do for
bold/italic.
Underline height (thickness) and Underline position (vertical) can be
set in the editbuttons.
Implemented as CU_POLY polygon curves.
- The B, U and i buttons (and the corresponding CTRL-B/U/I keystrokes)
have been fixed to only affect *one* attribute at a time. Formerly,
hitting CTRL-B when no other style was active, on a text portion with
italics text, for example, would kill the italics and just apply bold.
Now, these attributes always add or substract only, but do not
replace the style.
- In the past, there were bugs with material indices uninitialized, and
thus crashes in the renderer with illegal material indices.
Even though I assume they have been fixed, I've put in a check that
checks (hah) if the material index of a character is illegal (bigger
than ob->totcol), and then sets it to zero, and spits out a warning
on stderr.
If you see such warnings, please report and link to the .blend.
- Bugfix: All alignment modes only worked if there were at least *two*
lines of text in the text object. Fixed
There's now a regression test file for text objects, please add to the
corresponding repository:
http://blender.instinctive.de/downloads/release/demo/text-regression.blend.gz
2005-08-29 12:46:07 +00:00
|
|
|
|
2018-01-14 22:14:20 +01:00
|
|
|
sum = (float *)MEM_calloc_arrayN(len, sizeof(float), "makeNurbfaces1");
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
bp = nu->bp;
|
|
|
|
i = nu->pntsu * nu->pntsv;
|
|
|
|
ratcomp = 0;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (i--) {
|
|
|
|
if (bp->vec[3] != 1.0f) {
|
2012-05-06 15:15:33 +00:00
|
|
|
ratcomp = 1;
|
2002-10-12 11:37:38 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
bp++;
|
|
|
|
}
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
fp = nu->knotsu;
|
|
|
|
ustart = fp[nu->orderu - 1];
|
2012-05-07 08:53:59 +00:00
|
|
|
if (nu->flagu & CU_NURB_CYCLIC)
|
|
|
|
uend = fp[nu->pntsu + nu->orderu - 1];
|
|
|
|
else
|
|
|
|
uend = fp[nu->pntsu];
|
2012-05-06 15:15:33 +00:00
|
|
|
ustep = (uend - ustart) / ((nu->flagu & CU_NURB_CYCLIC) ? totu : totu - 1);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2018-01-14 22:14:20 +01:00
|
|
|
basisu = (float *)MEM_malloc_arrayN(KNOTSU(nu), sizeof(float), "makeNurbfaces3");
|
2012-05-06 15:15:33 +00:00
|
|
|
|
|
|
|
fp = nu->knotsv;
|
|
|
|
vstart = fp[nu->orderv - 1];
|
|
|
|
|
2012-05-07 08:53:59 +00:00
|
|
|
if (nu->flagv & CU_NURB_CYCLIC)
|
|
|
|
vend = fp[nu->pntsv + nu->orderv - 1];
|
|
|
|
else
|
|
|
|
vend = fp[nu->pntsv];
|
2012-05-06 15:15:33 +00:00
|
|
|
vstep = (vend - vstart) / ((nu->flagv & CU_NURB_CYCLIC) ? totv : totv - 1);
|
|
|
|
|
|
|
|
len = KNOTSV(nu);
|
2018-01-14 22:14:20 +01:00
|
|
|
basisv = (float *)MEM_malloc_arrayN(len * totv, sizeof(float), "makeNurbfaces3");
|
|
|
|
jstart = (int *)MEM_malloc_arrayN(totv, sizeof(float), "makeNurbfaces4");
|
|
|
|
jend = (int *)MEM_malloc_arrayN(totv, sizeof(float), "makeNurbfaces5");
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-04-29 15:47:02 +00:00
|
|
|
/* precalculation of basisv and jstart, jend */
|
2012-05-07 08:53:59 +00:00
|
|
|
if (nu->flagv & CU_NURB_CYCLIC)
|
|
|
|
cycl = nu->orderv - 1;
|
2012-05-06 15:15:33 +00:00
|
|
|
else cycl = 0;
|
|
|
|
v = vstart;
|
|
|
|
basis = basisv;
|
|
|
|
curv = totv;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (curv--) {
|
2014-01-19 00:18:53 +06:00
|
|
|
basisNurb(v, nu->orderv, nu->pntsv + cycl, nu->knotsv, basis, jstart + curv, jend + curv);
|
2012-05-06 15:15:33 +00:00
|
|
|
basis += KNOTSV(nu);
|
|
|
|
v += vstep;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2012-05-07 08:53:59 +00:00
|
|
|
if (nu->flagu & CU_NURB_CYCLIC)
|
|
|
|
cycl = nu->orderu - 1;
|
|
|
|
else
|
|
|
|
cycl = 0;
|
2012-05-06 15:15:33 +00:00
|
|
|
in = coord_array;
|
|
|
|
u = ustart;
|
|
|
|
curu = totu;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (curu--) {
|
2014-01-19 00:18:53 +06:00
|
|
|
basisNurb(u, nu->orderu, nu->pntsu + cycl, nu->knotsu, basisu, &istart, &iend);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
basis = basisv;
|
|
|
|
curv = totv;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (curv--) {
|
2012-05-06 15:15:33 +00:00
|
|
|
jsta = jstart[curv];
|
|
|
|
jen = jend[curv];
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2003-04-25 15:48:11 +00:00
|
|
|
/* calculate sum */
|
2012-05-06 15:15:33 +00:00
|
|
|
sumdiv = 0.0;
|
|
|
|
fp = sum;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
for (j = jsta; j <= jen; j++) {
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-07 08:53:59 +00:00
|
|
|
if (j >= nu->pntsv)
|
|
|
|
jofs = (j - nu->pntsv);
|
|
|
|
else
|
|
|
|
jofs = j;
|
2012-05-06 15:15:33 +00:00
|
|
|
bp = nu->bp + nu->pntsu * jofs + istart - 1;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
for (i = istart; i <= iend; i++, fp++) {
|
|
|
|
if (i >= nu->pntsu) {
|
|
|
|
iofs = i - nu->pntsu;
|
|
|
|
bp = nu->bp + nu->pntsu * jofs + iofs;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2012-05-07 08:53:59 +00:00
|
|
|
else
|
|
|
|
bp++;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (ratcomp) {
|
2012-05-06 15:15:33 +00:00
|
|
|
*fp = basisu[i] * basis[j] * bp->vec[3];
|
|
|
|
sumdiv += *fp;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2012-05-07 08:53:59 +00:00
|
|
|
else
|
|
|
|
*fp = basisu[i] * basis[j];
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (ratcomp) {
|
2012-05-06 15:15:33 +00:00
|
|
|
fp = sum;
|
|
|
|
for (j = jsta; j <= jen; j++) {
|
|
|
|
for (i = istart; i <= iend; i++, fp++) {
|
|
|
|
*fp /= sumdiv;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-19 15:13:15 +10:00
|
|
|
zero_v3(in);
|
|
|
|
|
2003-04-25 15:48:11 +00:00
|
|
|
/* one! (1.0) real point now */
|
2012-05-06 15:15:33 +00:00
|
|
|
fp = sum;
|
|
|
|
for (j = jsta; j <= jen; j++) {
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-07 08:53:59 +00:00
|
|
|
if (j >= nu->pntsv)
|
|
|
|
jofs = (j - nu->pntsv);
|
|
|
|
else
|
|
|
|
jofs = j;
|
2012-05-06 15:15:33 +00:00
|
|
|
bp = nu->bp + nu->pntsu * jofs + istart - 1;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
for (i = istart; i <= iend; i++, fp++) {
|
|
|
|
if (i >= nu->pntsu) {
|
|
|
|
iofs = i - nu->pntsu;
|
|
|
|
bp = nu->bp + nu->pntsu * jofs + iofs;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2012-05-07 08:53:59 +00:00
|
|
|
else
|
|
|
|
bp++;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (*fp != 0.0f) {
|
2012-06-12 20:04:55 +00:00
|
|
|
madd_v3_v3fl(in, bp->vec, *fp);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
in += 3;
|
|
|
|
basis += KNOTSV(nu);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2012-05-06 15:15:33 +00:00
|
|
|
u += ustep;
|
2017-11-02 15:09:11 +11:00
|
|
|
if (rowstride != 0) {
|
|
|
|
in = (float *)(((unsigned char *)in) + (rowstride - 3 * totv * sizeof(*in)));
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2003-04-25 15:48:11 +00:00
|
|
|
/* free */
|
2002-10-12 11:37:38 +00:00
|
|
|
MEM_freeN(sum);
|
|
|
|
MEM_freeN(basisu);
|
|
|
|
MEM_freeN(basisv);
|
|
|
|
MEM_freeN(jstart);
|
|
|
|
MEM_freeN(jend);
|
|
|
|
}
|
|
|
|
|
2012-10-27 10:42:28 +00:00
|
|
|
/**
|
|
|
|
* \param coord_array Has to be 3 * 4 * pntsu * resolu in size and zero-ed
|
|
|
|
* \param tilt_array set when non-NULL
|
|
|
|
* \param radius_array set when non-NULL
|
|
|
|
*/
|
2018-08-20 11:10:09 +10:00
|
|
|
void BKE_nurb_makeCurve(
|
|
|
|
const Nurb *nu, float *coord_array, float *tilt_array, float *radius_array, float *weight_array,
|
|
|
|
int resolu, int stride)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2015-02-27 20:14:15 +11:00
|
|
|
const float eps = 1e-6f;
|
2002-10-12 11:37:38 +00:00
|
|
|
BPoint *bp;
|
|
|
|
float u, ustart, uend, ustep, sumdiv;
|
2008-09-23 13:35:32 +00:00
|
|
|
float *basisu, *sum, *fp;
|
2012-05-06 15:15:33 +00:00
|
|
|
float *coord_fp = coord_array, *tilt_fp = tilt_array, *radius_fp = radius_array, *weight_fp = weight_array;
|
2006-02-07 19:59:02 +00:00
|
|
|
int i, len, istart, iend, cycl;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-07 08:53:59 +00:00
|
|
|
if (nu->knotsu == NULL)
|
|
|
|
return;
|
|
|
|
if (nu->orderu > nu->pntsu)
|
|
|
|
return;
|
|
|
|
if (coord_array == NULL)
|
|
|
|
return;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2003-04-25 15:48:11 +00:00
|
|
|
/* allocate and initialize */
|
2012-05-06 15:15:33 +00:00
|
|
|
len = nu->pntsu;
|
2012-05-07 08:53:59 +00:00
|
|
|
if (len == 0)
|
|
|
|
return;
|
2018-01-14 22:14:20 +01:00
|
|
|
sum = (float *)MEM_calloc_arrayN(len, sizeof(float), "makeNurbcurve1");
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
resolu = (resolu * SEGMENTSU(nu));
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
if (resolu == 0) {
|
2002-10-12 11:37:38 +00:00
|
|
|
MEM_freeN(sum);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
fp = nu->knotsu;
|
|
|
|
ustart = fp[nu->orderu - 1];
|
2012-05-07 08:53:59 +00:00
|
|
|
if (nu->flagu & CU_NURB_CYCLIC)
|
|
|
|
uend = fp[nu->pntsu + nu->orderu - 1];
|
|
|
|
else
|
|
|
|
uend = fp[nu->pntsu];
|
2012-05-06 15:15:33 +00:00
|
|
|
ustep = (uend - ustart) / (resolu - ((nu->flagu & CU_NURB_CYCLIC) ? 0 : 1));
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2018-01-14 22:14:20 +01:00
|
|
|
basisu = (float *)MEM_malloc_arrayN(KNOTSU(nu), sizeof(float), "makeNurbcurve3");
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-07 08:53:59 +00:00
|
|
|
if (nu->flagu & CU_NURB_CYCLIC)
|
|
|
|
cycl = nu->orderu - 1;
|
|
|
|
else
|
|
|
|
cycl = 0;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
u = ustart;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (resolu--) {
|
2014-01-19 00:18:53 +06:00
|
|
|
basisNurb(u, nu->orderu, nu->pntsu + cycl, nu->knotsu, basisu, &istart, &iend);
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2003-04-25 15:48:11 +00:00
|
|
|
/* calc sum */
|
2012-05-06 15:15:33 +00:00
|
|
|
sumdiv = 0.0;
|
|
|
|
fp = sum;
|
|
|
|
bp = nu->bp + istart - 1;
|
|
|
|
for (i = istart; i <= iend; i++, fp++) {
|
2012-05-07 08:53:59 +00:00
|
|
|
if (i >= nu->pntsu)
|
|
|
|
bp = nu->bp + (i - nu->pntsu);
|
|
|
|
else
|
|
|
|
bp++;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
*fp = basisu[i] * bp->vec[3];
|
|
|
|
sumdiv += *fp;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2015-02-27 20:14:15 +11:00
|
|
|
if ((sumdiv != 0.0f) && (sumdiv < 1.0f - eps || sumdiv > 1.0f + eps)) {
|
2012-11-09 09:33:28 +00:00
|
|
|
/* is normalizing needed? */
|
|
|
|
fp = sum;
|
|
|
|
for (i = istart; i <= iend; i++, fp++) {
|
|
|
|
*fp /= sumdiv;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2012-11-09 09:33:28 +00:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2014-06-19 15:13:15 +10:00
|
|
|
zero_v3(coord_fp);
|
|
|
|
|
2003-04-25 15:48:11 +00:00
|
|
|
/* one! (1.0) real point */
|
2012-05-06 15:15:33 +00:00
|
|
|
fp = sum;
|
|
|
|
bp = nu->bp + istart - 1;
|
|
|
|
for (i = istart; i <= iend; i++, fp++) {
|
2012-05-07 08:53:59 +00:00
|
|
|
if (i >= nu->pntsu)
|
|
|
|
bp = nu->bp + (i - nu->pntsu);
|
|
|
|
else
|
|
|
|
bp++;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (*fp != 0.0f) {
|
2012-06-12 20:04:55 +00:00
|
|
|
madd_v3_v3fl(coord_fp, bp->vec, *fp);
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2008-09-23 13:35:32 +00:00
|
|
|
if (tilt_fp)
|
|
|
|
(*tilt_fp) += (*fp) * bp->alfa;
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2008-09-23 13:35:32 +00:00
|
|
|
if (radius_fp)
|
|
|
|
(*radius_fp) += (*fp) * bp->radius;
|
2010-04-21 11:59:47 +00:00
|
|
|
|
|
|
|
if (weight_fp)
|
|
|
|
(*weight_fp) += (*fp) * bp->weight;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-03 16:40:14 +10:00
|
|
|
coord_fp = POINTER_OFFSET(coord_fp, stride);
|
2012-05-07 08:53:59 +00:00
|
|
|
|
|
|
|
if (tilt_fp)
|
2016-05-03 16:40:14 +10:00
|
|
|
tilt_fp = POINTER_OFFSET(tilt_fp, stride);
|
2012-05-07 08:53:59 +00:00
|
|
|
if (radius_fp)
|
2016-05-03 16:40:14 +10:00
|
|
|
radius_fp = POINTER_OFFSET(radius_fp, stride);
|
2012-05-07 08:53:59 +00:00
|
|
|
if (weight_fp)
|
2016-05-03 16:40:14 +10:00
|
|
|
weight_fp = POINTER_OFFSET(weight_fp, stride);
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
u += ustep;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2003-04-25 15:48:11 +00:00
|
|
|
/* free */
|
2002-10-12 11:37:38 +00:00
|
|
|
MEM_freeN(sum);
|
|
|
|
MEM_freeN(basisu);
|
|
|
|
}
|
|
|
|
|
2016-07-03 23:20:53 +10:00
|
|
|
/**
|
|
|
|
* Calculate the length for arrays filled in by #BKE_curve_calc_coords_axis.
|
|
|
|
*/
|
|
|
|
unsigned int BKE_curve_calc_coords_axis_len(
|
|
|
|
const unsigned int bezt_array_len, const unsigned int resolu,
|
|
|
|
const bool is_cyclic, const bool use_cyclic_duplicate_endpoint)
|
|
|
|
{
|
|
|
|
const unsigned int segments = bezt_array_len - (is_cyclic ? 0 : 1);
|
|
|
|
const unsigned int points_len = (segments * resolu) + (is_cyclic ? (use_cyclic_duplicate_endpoint) : 1);
|
|
|
|
return points_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-07-08 00:48:03 +10:00
|
|
|
* Calculate an array for the entire curve (cyclic or non-cyclic).
|
2016-07-03 23:20:53 +10:00
|
|
|
* \note Call for each axis.
|
|
|
|
*
|
|
|
|
* \param use_cyclic_duplicate_endpoint: Duplicate values at the beginning & end of the array.
|
|
|
|
*/
|
|
|
|
void BKE_curve_calc_coords_axis(
|
|
|
|
const BezTriple *bezt_array, const unsigned int bezt_array_len, const unsigned int resolu,
|
|
|
|
const bool is_cyclic, const bool use_cyclic_duplicate_endpoint,
|
|
|
|
/* array params */
|
|
|
|
const unsigned int axis, const unsigned int stride,
|
|
|
|
float *r_points)
|
|
|
|
{
|
|
|
|
const unsigned int points_len = BKE_curve_calc_coords_axis_len(
|
|
|
|
bezt_array_len, resolu, is_cyclic, use_cyclic_duplicate_endpoint);
|
|
|
|
float *r_points_offset = r_points;
|
|
|
|
|
|
|
|
const unsigned int resolu_stride = resolu * stride;
|
|
|
|
const unsigned int bezt_array_last = bezt_array_len - 1;
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < bezt_array_last; i++) {
|
|
|
|
const BezTriple *bezt_curr = &bezt_array[i];
|
|
|
|
const BezTriple *bezt_next = &bezt_array[i + 1];
|
|
|
|
BKE_curve_forward_diff_bezier(
|
|
|
|
bezt_curr->vec[1][axis], bezt_curr->vec[2][axis],
|
|
|
|
bezt_next->vec[0][axis], bezt_next->vec[1][axis],
|
|
|
|
r_points_offset, (int)resolu, stride);
|
|
|
|
r_points_offset = POINTER_OFFSET(r_points_offset, resolu_stride);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_cyclic) {
|
|
|
|
const BezTriple *bezt_curr = &bezt_array[bezt_array_last];
|
|
|
|
const BezTriple *bezt_next = &bezt_array[0];
|
|
|
|
BKE_curve_forward_diff_bezier(
|
|
|
|
bezt_curr->vec[1][axis], bezt_curr->vec[2][axis],
|
|
|
|
bezt_next->vec[0][axis], bezt_next->vec[1][axis],
|
|
|
|
r_points_offset, (int)resolu, stride);
|
|
|
|
r_points_offset = POINTER_OFFSET(r_points_offset, resolu_stride);
|
|
|
|
if (use_cyclic_duplicate_endpoint) {
|
|
|
|
*r_points_offset = *r_points;
|
|
|
|
r_points_offset = POINTER_OFFSET(r_points_offset, stride);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
float *r_points_last = POINTER_OFFSET(r_points, bezt_array_last * resolu_stride);
|
|
|
|
*r_points_last = bezt_array[bezt_array_last].vec[1][axis];
|
|
|
|
r_points_offset = POINTER_OFFSET(r_points_offset, stride);
|
|
|
|
}
|
|
|
|
|
|
|
|
BLI_assert(POINTER_OFFSET(r_points, points_len * stride) == r_points_offset);
|
|
|
|
UNUSED_VARS_NDEBUG(points_len);
|
|
|
|
}
|
|
|
|
|
2005-07-16 19:07:02 +00:00
|
|
|
/* forward differencing method for bezier curve */
|
2012-04-28 16:49:00 +00:00
|
|
|
void BKE_curve_forward_diff_bezier(float q0, float q1, float q2, float q3, float *p, int it, int stride)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2012-04-29 15:47:02 +00:00
|
|
|
float rt0, rt1, rt2, rt3, f;
|
2002-10-12 11:37:38 +00:00
|
|
|
int a;
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
f = (float)it;
|
|
|
|
rt0 = q0;
|
|
|
|
rt1 = 3.0f * (q1 - q0) / f;
|
|
|
|
f *= f;
|
|
|
|
rt2 = 3.0f * (q0 - 2.0f * q1 + q2) / f;
|
|
|
|
f *= it;
|
|
|
|
rt3 = (q3 - q0 + 3.0f * (q1 - q2)) / f;
|
2011-04-21 15:53:30 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
q0 = rt0;
|
|
|
|
q1 = rt1 + rt2 + rt3;
|
|
|
|
q2 = 2 * rt2 + 6 * rt3;
|
|
|
|
q3 = 6 * rt3;
|
2011-04-21 15:53:30 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
for (a = 0; a <= it; a++) {
|
|
|
|
*p = q0;
|
2016-05-03 16:40:14 +10:00
|
|
|
p = POINTER_OFFSET(p, stride);
|
2012-05-06 15:15:33 +00:00
|
|
|
q0 += q1;
|
|
|
|
q1 += q2;
|
|
|
|
q2 += q3;
|
2011-04-21 15:53:30 +00:00
|
|
|
}
|
2009-09-11 15:35:30 +00:00
|
|
|
}
|
|
|
|
|
2015-05-07 18:10:34 +02:00
|
|
|
/* forward differencing method for first derivative of cubic bezier curve */
|
|
|
|
void BKE_curve_forward_diff_tangent_bezier(float q0, float q1, float q2, float q3, float *p, int it, int stride)
|
|
|
|
{
|
|
|
|
float rt0, rt1, rt2, f;
|
|
|
|
int a;
|
|
|
|
|
|
|
|
f = 1.0f / (float)it;
|
|
|
|
|
|
|
|
rt0 = 3.0f * (q1 - q0);
|
|
|
|
rt1 = f * (3.0f * (q3 - q0) + 9.0f * (q1 - q2));
|
2015-05-13 06:10:49 +10:00
|
|
|
rt2 = 6.0f * (q0 + q2) - 12.0f * q1;
|
2015-05-07 18:10:34 +02:00
|
|
|
|
|
|
|
q0 = rt0;
|
|
|
|
q1 = f * (rt1 + rt2);
|
|
|
|
q2 = 2.0f * f * rt1;
|
|
|
|
|
|
|
|
for (a = 0; a <= it; a++) {
|
|
|
|
*p = q0;
|
2016-05-03 16:40:14 +10:00
|
|
|
p = POINTER_OFFSET(p, stride);
|
2015-05-07 18:10:34 +02:00
|
|
|
q0 += q1;
|
|
|
|
q1 += q2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-12 22:13:38 +00:00
|
|
|
static void forward_diff_bezier_cotangent(const float p0[3], const float p1[3], const float p2[3], const float p3[3],
|
|
|
|
float p[3], int it, int stride)
|
2009-09-11 15:35:30 +00:00
|
|
|
{
|
2012-08-24 23:22:34 +00:00
|
|
|
/* note that these are not perpendicular to the curve
|
2009-09-11 15:35:30 +00:00
|
|
|
* they need to be rotated for this,
|
|
|
|
*
|
2012-05-12 22:13:38 +00:00
|
|
|
* This could also be optimized like BKE_curve_forward_diff_bezier */
|
2009-09-11 15:35:30 +00:00
|
|
|
int a;
|
2012-05-06 15:15:33 +00:00
|
|
|
for (a = 0; a <= it; a++) {
|
2009-09-11 15:35:30 +00:00
|
|
|
float t = (float)a / (float)it;
|
|
|
|
|
|
|
|
int i;
|
2012-05-06 15:15:33 +00:00
|
|
|
for (i = 0; i < 3; i++) {
|
2012-05-12 22:13:38 +00:00
|
|
|
p[i] = (-6.0f * t + 6.0f) * p0[i] +
|
|
|
|
( 18.0f * t - 12.0f) * p1[i] +
|
|
|
|
(-18.0f * t + 6.0f) * p2[i] +
|
|
|
|
( 6.0f * t) * p3[i];
|
2009-09-11 15:35:30 +00:00
|
|
|
}
|
2009-11-10 20:43:45 +00:00
|
|
|
normalize_v3(p);
|
2016-05-03 16:40:14 +10:00
|
|
|
p = POINTER_OFFSET(p, stride);
|
2011-04-21 15:53:30 +00:00
|
|
|
}
|
2009-09-11 15:35:30 +00:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
|
|
|
|
|
2012-04-28 16:49:00 +00:00
|
|
|
float *BKE_curve_surf_make_orco(Object *ob)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2010-11-11 09:56:39 +00:00
|
|
|
/* Note: this function is used in convertblender only atm, so
|
|
|
|
* suppose nonzero curve's render resolution should always be used */
|
2012-05-06 15:15:33 +00:00
|
|
|
Curve *cu = ob->data;
|
2002-10-12 11:37:38 +00:00
|
|
|
Nurb *nu;
|
2012-05-06 15:15:33 +00:00
|
|
|
int a, b, tot = 0;
|
2006-03-11 12:34:50 +00:00
|
|
|
int sizeu, sizev;
|
2010-11-11 09:56:39 +00:00
|
|
|
int resolu, resolv;
|
2008-09-23 13:35:32 +00:00
|
|
|
float *fp, *coord_array;
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2006-03-11 12:34:50 +00:00
|
|
|
/* first calculate the size of the datablock */
|
2012-05-06 15:15:33 +00:00
|
|
|
nu = cu->nurb.first;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (nu) {
|
2006-03-11 12:34:50 +00:00
|
|
|
/* as we want to avoid the seam in a cyclic nurbs
|
2012-03-03 20:19:11 +00:00
|
|
|
* texture wrapping, reserve extra orco data space to save these extra needed
|
|
|
|
* vertex based UV coordinates for the meridian vertices.
|
|
|
|
* Vertices on the 0/2pi boundary are not duplicated inside the displist but later in
|
|
|
|
* the renderface/vert construction.
|
|
|
|
*
|
|
|
|
* See also convertblender.c: init_render_surf()
|
|
|
|
*/
|
2010-11-11 09:56:39 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
resolu = cu->resolu_ren ? cu->resolu_ren : nu->resolu;
|
|
|
|
resolv = cu->resolv_ren ? cu->resolv_ren : nu->resolv;
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
sizeu = nu->pntsu * resolu;
|
|
|
|
sizev = nu->pntsv * resolv;
|
merge own commits into render branch into trunk since 27560
27562, 27570, 27571, 27574, 27576, 27577, 27579, 27590, 27591, 27594, 27595, 27596, 27599, 27605, 27611, 27612, 27613, 27614, 27623
2010-03-20 16:41:01 +00:00
|
|
|
if (nu->flagu & CU_NURB_CYCLIC) sizeu++;
|
|
|
|
if (nu->flagv & CU_NURB_CYCLIC) sizev++;
|
2012-05-06 15:15:33 +00:00
|
|
|
if (nu->pntsv > 1) tot += sizeu * sizev;
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
nu = nu->next;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2006-03-11 12:34:50 +00:00
|
|
|
/* makeNurbfaces wants zeros */
|
2018-01-14 22:14:20 +01:00
|
|
|
fp = coord_array = MEM_calloc_arrayN(tot, 3 * sizeof(float), "make_orco");
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
nu = cu->nurb.first;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (nu) {
|
2012-05-06 15:15:33 +00:00
|
|
|
resolu = cu->resolu_ren ? cu->resolu_ren : nu->resolu;
|
|
|
|
resolv = cu->resolv_ren ? cu->resolv_ren : nu->resolv;
|
2010-11-11 09:56:39 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
if (nu->pntsv > 1) {
|
|
|
|
sizeu = nu->pntsu * resolu;
|
|
|
|
sizev = nu->pntsv * resolv;
|
2012-05-07 08:53:59 +00:00
|
|
|
|
|
|
|
if (nu->flagu & CU_NURB_CYCLIC)
|
|
|
|
sizeu++;
|
|
|
|
if (nu->flagv & CU_NURB_CYCLIC)
|
|
|
|
sizev++;
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (cu->flag & CU_UV_ORCO) {
|
2012-05-06 15:15:33 +00:00
|
|
|
for (b = 0; b < sizeu; b++) {
|
|
|
|
for (a = 0; a < sizev; a++) {
|
2012-05-07 08:53:59 +00:00
|
|
|
|
|
|
|
if (sizev < 2)
|
|
|
|
fp[0] = 0.0f;
|
|
|
|
else
|
|
|
|
fp[0] = -1.0f + 2.0f * ((float)a) / (sizev - 1);
|
|
|
|
|
|
|
|
if (sizeu < 2)
|
|
|
|
fp[1] = 0.0f;
|
|
|
|
else
|
|
|
|
fp[1] = -1.0f + 2.0f * ((float)b) / (sizeu - 1);
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
fp[2] = 0.0;
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
fp += 3;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2012-05-07 08:53:59 +00:00
|
|
|
int size = (nu->pntsu * resolu) * (nu->pntsv * resolv) * 3 * sizeof(float);
|
2014-06-19 15:13:15 +10:00
|
|
|
float *_tdata = MEM_mallocN(size, "temp data");
|
2012-05-06 15:15:33 +00:00
|
|
|
float *tdata = _tdata;
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2012-04-28 16:49:00 +00:00
|
|
|
BKE_nurb_makeFaces(nu, tdata, 0, resolu, resolv);
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
for (b = 0; b < sizeu; b++) {
|
|
|
|
int use_b = b;
|
|
|
|
if (b == sizeu - 1 && (nu->flagu & CU_NURB_CYCLIC))
|
2014-04-01 11:34:00 +11:00
|
|
|
use_b = false;
|
2012-05-06 15:15:33 +00:00
|
|
|
|
|
|
|
for (a = 0; a < sizev; a++) {
|
|
|
|
int use_a = a;
|
|
|
|
if (a == sizev - 1 && (nu->flagv & CU_NURB_CYCLIC))
|
2014-04-01 11:34:00 +11:00
|
|
|
use_a = false;
|
2012-05-06 15:15:33 +00:00
|
|
|
|
|
|
|
tdata = _tdata + 3 * (use_b * (nu->pntsv * resolv) + use_a);
|
|
|
|
|
|
|
|
fp[0] = (tdata[0] - cu->loc[0]) / cu->size[0];
|
|
|
|
fp[1] = (tdata[1] - cu->loc[1]) / cu->size[1];
|
|
|
|
fp[2] = (tdata[2] - cu->loc[2]) / cu->size[2];
|
|
|
|
fp += 3;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2006-07-06 14:20:44 +00:00
|
|
|
MEM_freeN(_tdata);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
2012-05-06 15:15:33 +00:00
|
|
|
nu = nu->next;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2008-09-23 13:35:32 +00:00
|
|
|
return coord_array;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
/* NOTE: This routine is tied to the order of vertex
|
|
|
|
* built by displist and as passed to the renderer.
|
|
|
|
*/
|
2018-04-06 12:07:27 +02:00
|
|
|
float *BKE_curve_make_orco(Depsgraph *depsgraph, Scene *scene, Object *ob, int *r_numVerts)
|
2005-08-14 06:08:41 +00:00
|
|
|
{
|
|
|
|
Curve *cu = ob->data;
|
|
|
|
DispList *dl;
|
|
|
|
int u, v, numVerts;
|
2008-09-23 13:35:32 +00:00
|
|
|
float *fp, *coord_array;
|
2010-03-08 13:49:13 +00:00
|
|
|
ListBase disp = {NULL, NULL};
|
2005-08-14 06:08:41 +00:00
|
|
|
|
2018-04-06 12:07:27 +02:00
|
|
|
BKE_displist_make_curveTypes_forOrco(depsgraph, scene, ob, &disp);
|
2005-08-14 06:08:41 +00:00
|
|
|
|
|
|
|
numVerts = 0;
|
2012-05-06 15:15:33 +00:00
|
|
|
for (dl = disp.first; dl; dl = dl->next) {
|
|
|
|
if (dl->type == DL_INDEX3) {
|
2005-08-14 06:08:41 +00:00
|
|
|
numVerts += dl->nr;
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
2012-05-06 15:15:33 +00:00
|
|
|
else if (dl->type == DL_SURF) {
|
2012-05-07 08:53:59 +00:00
|
|
|
/* convertblender.c uses the Surface code for creating renderfaces when cyclic U only
|
|
|
|
* (closed circle beveling)
|
|
|
|
*/
|
2006-06-21 10:02:47 +00:00
|
|
|
if (dl->flag & DL_CYCL_U) {
|
|
|
|
if (dl->flag & DL_CYCL_V)
|
2012-05-06 15:15:33 +00:00
|
|
|
numVerts += (dl->parts + 1) * (dl->nr + 1);
|
2006-06-21 10:02:47 +00:00
|
|
|
else
|
2012-05-06 15:15:33 +00:00
|
|
|
numVerts += dl->parts * (dl->nr + 1);
|
2006-06-21 10:02:47 +00:00
|
|
|
}
|
2013-11-26 01:17:24 +06:00
|
|
|
else if (dl->flag & DL_CYCL_V) {
|
|
|
|
numVerts += (dl->parts + 1) * dl->nr;
|
|
|
|
}
|
2006-06-21 10:02:47 +00:00
|
|
|
else
|
2012-05-06 15:15:33 +00:00
|
|
|
numVerts += dl->parts * dl->nr;
|
2005-08-14 06:08:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-13 07:13:28 +00:00
|
|
|
if (r_numVerts)
|
|
|
|
*r_numVerts = numVerts;
|
|
|
|
|
2018-01-14 22:14:20 +01:00
|
|
|
fp = coord_array = MEM_malloc_arrayN(numVerts, 3 * sizeof(float), "cu_orco");
|
2012-05-06 15:15:33 +00:00
|
|
|
for (dl = disp.first; dl; dl = dl->next) {
|
|
|
|
if (dl->type == DL_INDEX3) {
|
|
|
|
for (u = 0; u < dl->nr; u++, fp += 3) {
|
2006-03-11 12:34:50 +00:00
|
|
|
if (cu->flag & CU_UV_ORCO) {
|
2012-05-06 15:15:33 +00:00
|
|
|
fp[0] = 2.0f * u / (dl->nr - 1) - 1.0f;
|
|
|
|
fp[1] = 0.0;
|
|
|
|
fp[2] = 0.0;
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-05-06 15:15:33 +00:00
|
|
|
copy_v3_v3(fp, &dl->verts[u * 3]);
|
2005-08-14 06:08:41 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
fp[0] = (fp[0] - cu->loc[0]) / cu->size[0];
|
|
|
|
fp[1] = (fp[1] - cu->loc[1]) / cu->size[1];
|
|
|
|
fp[2] = (fp[2] - cu->loc[2]) / cu->size[2];
|
2005-08-14 06:08:41 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
2012-05-06 15:15:33 +00:00
|
|
|
else if (dl->type == DL_SURF) {
|
|
|
|
int sizeu = dl->nr, sizev = dl->parts;
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2006-06-21 10:02:47 +00:00
|
|
|
/* exception as handled in convertblender.c too */
|
|
|
|
if (dl->flag & DL_CYCL_U) {
|
2006-03-11 12:34:50 +00:00
|
|
|
sizeu++;
|
2006-06-21 10:02:47 +00:00
|
|
|
if (dl->flag & DL_CYCL_V)
|
|
|
|
sizev++;
|
|
|
|
}
|
2017-11-02 15:09:11 +11:00
|
|
|
else if (dl->flag & DL_CYCL_V) {
|
2013-11-26 01:17:24 +06:00
|
|
|
sizev++;
|
|
|
|
}
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
for (u = 0; u < sizev; u++) {
|
|
|
|
for (v = 0; v < sizeu; v++, fp += 3) {
|
2006-03-11 12:34:50 +00:00
|
|
|
if (cu->flag & CU_UV_ORCO) {
|
2012-05-06 15:15:33 +00:00
|
|
|
fp[0] = 2.0f * u / (sizev - 1) - 1.0f;
|
|
|
|
fp[1] = 2.0f * v / (sizeu - 1) - 1.0f;
|
|
|
|
fp[2] = 0.0;
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
|
|
|
else {
|
2014-04-27 00:20:13 +10:00
|
|
|
const float *vert;
|
2012-05-06 15:15:33 +00:00
|
|
|
int realv = v % dl->nr;
|
|
|
|
int realu = u % dl->parts;
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
vert = dl->verts + 3 * (dl->nr * realu + realv);
|
2011-10-28 12:40:15 +00:00
|
|
|
copy_v3_v3(fp, vert);
|
2005-08-14 06:08:41 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
fp[0] = (fp[0] - cu->loc[0]) / cu->size[0];
|
|
|
|
fp[1] = (fp[1] - cu->loc[1]) / cu->size[1];
|
|
|
|
fp[2] = (fp[2] - cu->loc[2]) / cu->size[2];
|
2005-08-14 06:08:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-07 06:58:03 +00:00
|
|
|
BKE_displist_free(&disp);
|
2005-08-14 06:08:41 +00:00
|
|
|
|
2008-09-23 13:35:32 +00:00
|
|
|
return coord_array;
|
2005-08-14 06:08:41 +00:00
|
|
|
}
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
/* ***************** BEVEL ****************** */
|
|
|
|
|
2017-08-16 12:45:11 +10:00
|
|
|
void BKE_curve_bevel_make(
|
2018-04-06 12:07:27 +02:00
|
|
|
Depsgraph *depsgraph, Scene *scene, Object *ob, ListBase *disp,
|
2017-08-16 12:45:11 +10:00
|
|
|
const bool for_render, const bool use_render_resolution)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
DispList *dl, *dlnew;
|
|
|
|
Curve *bevcu, *cu;
|
2006-10-14 23:27:18 +00:00
|
|
|
float *fp, facx, facy, angle, dangle;
|
2002-10-12 11:37:38 +00:00
|
|
|
int nr, a;
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
cu = ob->data;
|
2014-02-08 06:07:10 +11:00
|
|
|
BLI_listbase_clear(disp);
|
2005-12-09 14:30:51 +00:00
|
|
|
|
|
|
|
/* if a font object is being edited, then do nothing */
|
2012-03-24 06:18:31 +00:00
|
|
|
// XXX if ( ob == obedit && ob->type == OB_FONT ) return;
|
2005-12-09 14:30:51 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (cu->bevobj) {
|
2012-05-07 08:53:59 +00:00
|
|
|
if (cu->bevobj->type != OB_CURVE)
|
|
|
|
return;
|
2010-08-05 08:39:25 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
bevcu = cu->bevobj->data;
|
|
|
|
if (bevcu->ext1 == 0.0f && bevcu->ext2 == 0.0f) {
|
|
|
|
ListBase bevdisp = {NULL, NULL};
|
|
|
|
facx = cu->bevobj->size[0];
|
|
|
|
facy = cu->bevobj->size[1];
|
2010-03-30 14:33:05 +00:00
|
|
|
|
2014-03-20 22:56:28 +11:00
|
|
|
if (for_render) {
|
2018-04-06 12:07:27 +02:00
|
|
|
BKE_displist_make_curveTypes_forRender(depsgraph, scene, cu->bevobj, &bevdisp, NULL, false, use_render_resolution);
|
2012-05-06 15:15:33 +00:00
|
|
|
dl = bevdisp.first;
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
2018-07-30 16:54:40 +02:00
|
|
|
else if (cu->bevobj->runtime.curve_cache) {
|
|
|
|
dl = cu->bevobj->runtime.curve_cache->disp.first;
|
2014-02-17 22:01:38 +01:00
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
else {
|
2018-07-30 16:54:40 +02:00
|
|
|
BLI_assert(cu->bevobj->runtime.curve_cache != NULL);
|
2014-02-17 22:01:38 +01:00
|
|
|
dl = NULL;
|
2010-03-30 14:33:05 +00:00
|
|
|
}
|
2010-03-26 15:06:30 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
while (dl) {
|
2012-03-25 22:35:18 +00:00
|
|
|
if (ELEM(dl->type, DL_POLY, DL_SEGM)) {
|
2012-05-06 15:15:33 +00:00
|
|
|
dlnew = MEM_mallocN(sizeof(DispList), "makebevelcurve1");
|
|
|
|
*dlnew = *dl;
|
2018-01-14 22:14:20 +01:00
|
|
|
dlnew->verts = MEM_malloc_arrayN(dl->parts * dl->nr, 3 * sizeof(float), "makebevelcurve1");
|
2012-05-06 15:15:33 +00:00
|
|
|
memcpy(dlnew->verts, dl->verts, 3 * sizeof(float) * dl->parts * dl->nr);
|
2010-03-30 14:33:05 +00:00
|
|
|
|
2012-05-07 08:53:59 +00:00
|
|
|
if (dlnew->type == DL_SEGM)
|
|
|
|
dlnew->flag |= (DL_FRONT_CURVE | DL_BACK_CURVE);
|
2010-03-30 14:33:05 +00:00
|
|
|
|
|
|
|
BLI_addtail(disp, dlnew);
|
2012-05-06 15:15:33 +00:00
|
|
|
fp = dlnew->verts;
|
|
|
|
nr = dlnew->parts * dlnew->nr;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (nr--) {
|
2012-05-06 15:15:33 +00:00
|
|
|
fp[2] = fp[1] * facy;
|
|
|
|
fp[1] = -fp[0] * facx;
|
|
|
|
fp[0] = 0.0;
|
|
|
|
fp += 3;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
2012-05-06 15:15:33 +00:00
|
|
|
dl = dl->next;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2010-03-30 14:33:05 +00:00
|
|
|
|
2012-05-07 06:58:03 +00:00
|
|
|
BKE_displist_free(&bevdisp);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
2012-05-06 15:15:33 +00:00
|
|
|
else if (cu->ext1 == 0.0f && cu->ext2 == 0.0f) {
|
2012-10-21 07:58:38 +00:00
|
|
|
/* pass */
|
2005-08-14 06:08:41 +00:00
|
|
|
}
|
2012-05-06 15:15:33 +00:00
|
|
|
else if (cu->ext2 == 0.0f) {
|
|
|
|
dl = MEM_callocN(sizeof(DispList), "makebevelcurve2");
|
2018-01-14 22:14:20 +01:00
|
|
|
dl->verts = MEM_malloc_arrayN(2, sizeof(float[3]), "makebevelcurve2");
|
2002-10-12 11:37:38 +00:00
|
|
|
BLI_addtail(disp, dl);
|
2012-05-06 15:15:33 +00:00
|
|
|
dl->type = DL_SEGM;
|
|
|
|
dl->parts = 1;
|
|
|
|
dl->flag = DL_FRONT_CURVE | DL_BACK_CURVE;
|
|
|
|
dl->nr = 2;
|
|
|
|
|
|
|
|
fp = dl->verts;
|
|
|
|
fp[0] = fp[1] = 0.0;
|
|
|
|
fp[2] = -cu->ext1;
|
|
|
|
fp[3] = fp[4] = 0.0;
|
|
|
|
fp[5] = cu->ext1;
|
|
|
|
}
|
2017-11-02 15:09:11 +11:00
|
|
|
else if ((cu->flag & (CU_FRONT | CU_BACK)) == 0 && cu->ext1 == 0.0f) { /* we make a full round bevel in that case */
|
2012-05-06 15:15:33 +00:00
|
|
|
nr = 4 + 2 * cu->bevresol;
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
dl = MEM_callocN(sizeof(DispList), "makebevelcurve p1");
|
2018-01-14 22:14:20 +01:00
|
|
|
dl->verts = MEM_malloc_arrayN(nr, sizeof(float[3]), "makebevelcurve p1");
|
2006-03-06 21:44:08 +00:00
|
|
|
BLI_addtail(disp, dl);
|
2012-05-06 15:15:33 +00:00
|
|
|
dl->type = DL_POLY;
|
|
|
|
dl->parts = 1;
|
|
|
|
dl->flag = DL_BACK_CURVE;
|
|
|
|
dl->nr = nr;
|
2006-03-06 21:44:08 +00:00
|
|
|
|
|
|
|
/* a circle */
|
2012-05-06 15:15:33 +00:00
|
|
|
fp = dl->verts;
|
|
|
|
dangle = (2.0f * (float)M_PI / (nr));
|
|
|
|
angle = -(nr - 1) * dangle;
|
|
|
|
|
|
|
|
for (a = 0; a < nr; a++) {
|
|
|
|
fp[0] = 0.0;
|
|
|
|
fp[1] = (cosf(angle) * (cu->ext2));
|
|
|
|
fp[2] = (sinf(angle) * (cu->ext2)) - cu->ext1;
|
|
|
|
angle += dangle;
|
|
|
|
fp += 3;
|
2006-03-06 21:44:08 +00:00
|
|
|
}
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
else {
|
2005-04-16 15:51:44 +00:00
|
|
|
short dnr;
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2004-10-31 13:51:36 +00:00
|
|
|
/* bevel now in three parts, for proper vertex normals */
|
2010-07-14 17:47:58 +00:00
|
|
|
/* part 1, back */
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if ((cu->flag & CU_BACK) || !(cu->flag & CU_FRONT)) {
|
2012-05-06 15:15:33 +00:00
|
|
|
dnr = nr = 2 + cu->bevresol;
|
2017-11-02 15:09:11 +11:00
|
|
|
if ((cu->flag & (CU_FRONT | CU_BACK)) == 0) {
|
2012-05-06 15:15:33 +00:00
|
|
|
nr = 3 + 2 * cu->bevresol;
|
2017-11-02 15:09:11 +11:00
|
|
|
}
|
2012-05-06 15:15:33 +00:00
|
|
|
dl = MEM_callocN(sizeof(DispList), "makebevelcurve p1");
|
2018-01-14 22:14:20 +01:00
|
|
|
dl->verts = MEM_malloc_arrayN(nr, sizeof(float[3]), "makebevelcurve p1");
|
2010-07-14 17:47:58 +00:00
|
|
|
BLI_addtail(disp, dl);
|
2012-05-06 15:15:33 +00:00
|
|
|
dl->type = DL_SEGM;
|
|
|
|
dl->parts = 1;
|
|
|
|
dl->flag = DL_BACK_CURVE;
|
|
|
|
dl->nr = nr;
|
2010-07-14 17:47:58 +00:00
|
|
|
|
|
|
|
/* half a circle */
|
2012-05-06 15:15:33 +00:00
|
|
|
fp = dl->verts;
|
2015-01-31 17:23:30 +11:00
|
|
|
dangle = ((float)M_PI_2 / (dnr - 1));
|
2012-05-06 15:15:33 +00:00
|
|
|
angle = -(nr - 1) * dangle;
|
2010-07-14 17:47:58 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
for (a = 0; a < nr; a++) {
|
|
|
|
fp[0] = 0.0;
|
|
|
|
fp[1] = (float)(cosf(angle) * (cu->ext2));
|
|
|
|
fp[2] = (float)(sinf(angle) * (cu->ext2)) - cu->ext1;
|
|
|
|
angle += dangle;
|
|
|
|
fp += 3;
|
2010-07-14 17:47:58 +00:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2004-10-31 13:51:36 +00:00
|
|
|
/* part 2, sidefaces */
|
2012-05-06 15:15:33 +00:00
|
|
|
if (cu->ext1 != 0.0f) {
|
|
|
|
nr = 2;
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
dl = MEM_callocN(sizeof(DispList), "makebevelcurve p2");
|
2018-01-14 22:14:20 +01:00
|
|
|
dl->verts = MEM_malloc_arrayN(nr, sizeof(float[3]), "makebevelcurve p2");
|
2004-10-31 13:51:36 +00:00
|
|
|
BLI_addtail(disp, dl);
|
2012-05-06 15:15:33 +00:00
|
|
|
dl->type = DL_SEGM;
|
|
|
|
dl->parts = 1;
|
|
|
|
dl->nr = nr;
|
|
|
|
|
|
|
|
fp = dl->verts;
|
|
|
|
fp[1] = cu->ext2;
|
|
|
|
fp[2] = -cu->ext1;
|
|
|
|
fp[4] = cu->ext2;
|
|
|
|
fp[5] = cu->ext1;
|
|
|
|
|
2017-11-02 15:09:11 +11:00
|
|
|
if ((cu->flag & (CU_FRONT | CU_BACK)) == 0) {
|
2012-05-06 15:15:33 +00:00
|
|
|
dl = MEM_dupallocN(dl);
|
|
|
|
dl->verts = MEM_dupallocN(dl->verts);
|
2005-04-16 15:51:44 +00:00
|
|
|
BLI_addtail(disp, dl);
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
fp = dl->verts;
|
|
|
|
fp[1] = -fp[1];
|
|
|
|
fp[2] = -fp[2];
|
|
|
|
fp[4] = -fp[4];
|
|
|
|
fp[5] = -fp[5];
|
2005-04-16 15:51:44 +00:00
|
|
|
}
|
2004-10-31 13:51:36 +00:00
|
|
|
}
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2010-07-14 17:47:58 +00:00
|
|
|
/* part 3, front */
|
2012-03-24 06:18:31 +00:00
|
|
|
if ((cu->flag & CU_FRONT) || !(cu->flag & CU_BACK)) {
|
2012-05-06 15:15:33 +00:00
|
|
|
dnr = nr = 2 + cu->bevresol;
|
2017-11-02 15:09:11 +11:00
|
|
|
if ((cu->flag & (CU_FRONT | CU_BACK)) == 0) {
|
2012-05-06 15:15:33 +00:00
|
|
|
nr = 3 + 2 * cu->bevresol;
|
2017-11-02 15:09:11 +11:00
|
|
|
}
|
2012-05-06 15:15:33 +00:00
|
|
|
dl = MEM_callocN(sizeof(DispList), "makebevelcurve p3");
|
2018-01-14 22:14:20 +01:00
|
|
|
dl->verts = MEM_malloc_arrayN(nr, sizeof(float[3]), "makebevelcurve p3");
|
2010-07-14 17:47:58 +00:00
|
|
|
BLI_addtail(disp, dl);
|
2012-05-06 15:15:33 +00:00
|
|
|
dl->type = DL_SEGM;
|
|
|
|
dl->flag = DL_FRONT_CURVE;
|
|
|
|
dl->parts = 1;
|
|
|
|
dl->nr = nr;
|
2010-07-14 17:47:58 +00:00
|
|
|
|
|
|
|
/* half a circle */
|
2012-05-06 15:15:33 +00:00
|
|
|
fp = dl->verts;
|
|
|
|
angle = 0.0;
|
2015-01-31 17:23:30 +11:00
|
|
|
dangle = ((float)M_PI_2 / (dnr - 1));
|
2010-07-14 17:47:58 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
for (a = 0; a < nr; a++) {
|
|
|
|
fp[0] = 0.0;
|
|
|
|
fp[1] = (float)(cosf(angle) * (cu->ext2));
|
|
|
|
fp[2] = (float)(sinf(angle) * (cu->ext2)) + cu->ext1;
|
|
|
|
angle += dangle;
|
|
|
|
fp += 3;
|
2010-07-14 17:47:58 +00:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-28 14:05:00 +00:00
|
|
|
static int cu_isectLL(const float v1[3], const float v2[3], const float v3[3], const float v4[3],
|
|
|
|
short cox, short coy,
|
2012-12-11 14:18:37 +00:00
|
|
|
float *lambda, float *mu, float vec[3])
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
/* return:
|
2012-07-16 23:23:33 +00:00
|
|
|
* -1: collinear
|
2012-03-03 20:19:11 +00:00
|
|
|
* 0: no intersection of segments
|
|
|
|
* 1: exact intersection of segments
|
|
|
|
* 2: cross-intersection of segments
|
|
|
|
*/
|
2002-10-12 11:37:38 +00:00
|
|
|
float deler;
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
deler = (v1[cox] - v2[cox]) * (v3[coy] - v4[coy]) - (v3[cox] - v4[cox]) * (v1[coy] - v2[coy]);
|
2012-05-07 08:53:59 +00:00
|
|
|
if (deler == 0.0f)
|
|
|
|
return -1;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-12-11 14:18:37 +00:00
|
|
|
*lambda = (v1[coy] - v3[coy]) * (v3[cox] - v4[cox]) - (v1[cox] - v3[cox]) * (v3[coy] - v4[coy]);
|
|
|
|
*lambda = -(*lambda / deler);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
deler = v3[coy] - v4[coy];
|
|
|
|
if (deler == 0) {
|
|
|
|
deler = v3[cox] - v4[cox];
|
2012-12-11 14:18:37 +00:00
|
|
|
*mu = -(*lambda * (v2[cox] - v1[cox]) + v1[cox] - v3[cox]) / deler;
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-12-11 14:18:37 +00:00
|
|
|
*mu = -(*lambda * (v2[coy] - v1[coy]) + v1[coy] - v3[coy]) / deler;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2012-12-11 14:18:37 +00:00
|
|
|
vec[cox] = *lambda * (v2[cox] - v1[cox]) + v1[cox];
|
|
|
|
vec[coy] = *lambda * (v2[coy] - v1[coy]) + v1[coy];
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-12-11 14:18:37 +00:00
|
|
|
if (*lambda >= 0.0f && *lambda <= 1.0f && *mu >= 0.0f && *mu <= 1.0f) {
|
|
|
|
if (*lambda == 0.0f || *lambda == 1.0f || *mu == 0.0f || *mu == 1.0f)
|
2012-05-07 08:53:59 +00:00
|
|
|
return 1;
|
2002-10-12 11:37:38 +00:00
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-26 22:45:06 +00:00
|
|
|
static bool bevelinside(BevList *bl1, BevList *bl2)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2012-12-11 14:18:37 +00:00
|
|
|
/* is bl2 INSIDE bl1 ? with left-right method and "lambda's" */
|
2003-04-25 15:48:11 +00:00
|
|
|
/* returns '1' if correct hole */
|
2002-10-12 11:37:38 +00:00
|
|
|
BevPoint *bevp, *prevbevp;
|
2012-04-29 15:47:02 +00:00
|
|
|
float min, max, vec[3], hvec1[3], hvec2[3], lab, mu;
|
2012-05-06 15:15:33 +00:00
|
|
|
int nr, links = 0, rechts = 0, mode;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2003-04-25 15:48:11 +00:00
|
|
|
/* take first vertex of possible hole */
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2014-06-15 14:23:23 +10:00
|
|
|
bevp = bl2->bevpoints;
|
2012-05-06 15:15:33 +00:00
|
|
|
hvec1[0] = bevp->vec[0];
|
|
|
|
hvec1[1] = bevp->vec[1];
|
|
|
|
hvec1[2] = 0.0;
|
2012-04-29 15:47:02 +00:00
|
|
|
copy_v3_v3(hvec2, hvec1);
|
2012-05-06 15:15:33 +00:00
|
|
|
hvec2[0] += 1000;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2018-09-24 17:27:41 +02:00
|
|
|
/* test it with all edges of potential surrounding poly */
|
2003-04-25 15:48:11 +00:00
|
|
|
/* count number of transitions left-right */
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2014-06-15 14:23:23 +10:00
|
|
|
bevp = bl1->bevpoints;
|
2012-05-06 15:15:33 +00:00
|
|
|
nr = bl1->nr;
|
|
|
|
prevbevp = bevp + (nr - 1);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
while (nr--) {
|
2012-05-06 15:15:33 +00:00
|
|
|
min = prevbevp->vec[1];
|
|
|
|
max = bevp->vec[1];
|
|
|
|
if (max < min) {
|
|
|
|
min = max;
|
|
|
|
max = prevbevp->vec[1];
|
|
|
|
}
|
|
|
|
if (min != max) {
|
|
|
|
if (min <= hvec1[1] && max >= hvec1[1]) {
|
2003-04-25 15:48:11 +00:00
|
|
|
/* there's a transition, calc intersection point */
|
2012-05-06 15:15:33 +00:00
|
|
|
mode = cu_isectLL(prevbevp->vec, bevp->vec, hvec1, hvec2, 0, 1, &lab, &mu, vec);
|
2003-04-25 15:48:11 +00:00
|
|
|
/* if lab==0.0 or lab==1.0 then the edge intersects exactly a transition
|
2012-03-03 20:19:11 +00:00
|
|
|
* only allow for one situation: we choose lab= 1.0
|
2002-10-12 11:37:38 +00:00
|
|
|
*/
|
2012-03-24 06:18:31 +00:00
|
|
|
if (mode >= 0 && lab != 0.0f) {
|
2012-05-06 15:15:33 +00:00
|
|
|
if (vec[0] < hvec1[0]) links++;
|
2002-10-12 11:37:38 +00:00
|
|
|
else rechts++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-05-06 15:15:33 +00:00
|
|
|
prevbevp = bevp;
|
2002-10-12 11:37:38 +00:00
|
|
|
bevp++;
|
|
|
|
}
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2013-03-26 22:45:06 +00:00
|
|
|
return (links & 1) && (rechts & 1);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-05 21:45:05 +00:00
|
|
|
struct BevelSort {
|
2002-10-12 11:37:38 +00:00
|
|
|
BevList *bl;
|
2013-09-05 21:45:05 +00:00
|
|
|
float left;
|
2002-10-12 11:37:38 +00:00
|
|
|
int dir;
|
|
|
|
};
|
|
|
|
|
2006-02-07 19:59:02 +00:00
|
|
|
static int vergxcobev(const void *a1, const void *a2)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2013-09-05 21:45:05 +00:00
|
|
|
const struct BevelSort *x1 = a1, *x2 = a2;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-07 08:53:59 +00:00
|
|
|
if (x1->left > x2->left)
|
|
|
|
return 1;
|
|
|
|
else if (x1->left < x2->left)
|
|
|
|
return -1;
|
2002-10-12 11:37:38 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-04-25 15:48:11 +00:00
|
|
|
/* this function cannot be replaced with atan2, but why? */
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2014-03-30 11:08:33 +11:00
|
|
|
static void calc_bevel_sin_cos(float x1, float y1, float x2, float y2,
|
|
|
|
float *r_sina, float *r_cosa)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
float t01, t02, x3, y3;
|
|
|
|
|
2014-03-28 14:53:37 +11:00
|
|
|
t01 = sqrtf(x1 * x1 + y1 * y1);
|
|
|
|
t02 = sqrtf(x2 * x2 + y2 * y2);
|
2012-05-07 08:53:59 +00:00
|
|
|
if (t01 == 0.0f)
|
|
|
|
t01 = 1.0f;
|
|
|
|
if (t02 == 0.0f)
|
|
|
|
t02 = 1.0f;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
x1 /= t01;
|
|
|
|
y1 /= t01;
|
|
|
|
x2 /= t02;
|
|
|
|
y2 /= t02;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
t02 = x1 * x2 + y1 * y2;
|
2012-07-21 15:27:40 +00:00
|
|
|
if (fabsf(t02) >= 1.0f)
|
2015-01-31 17:23:30 +11:00
|
|
|
t02 = M_PI_2;
|
2012-05-07 08:53:59 +00:00
|
|
|
else
|
|
|
|
t02 = (saacos(t02)) / 2.0f;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2013-01-12 14:28:23 +00:00
|
|
|
t02 = sinf(t02);
|
2012-05-07 08:53:59 +00:00
|
|
|
if (t02 == 0.0f)
|
|
|
|
t02 = 1.0f;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
x3 = x1 - x2;
|
|
|
|
y3 = y1 - y2;
|
|
|
|
if (x3 == 0 && y3 == 0) {
|
|
|
|
x3 = y1;
|
|
|
|
y3 = -x1;
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
|
|
|
else {
|
2014-03-28 14:53:37 +11:00
|
|
|
t01 = sqrtf(x3 * x3 + y3 * y3);
|
2012-05-06 15:15:33 +00:00
|
|
|
x3 /= t01;
|
|
|
|
y3 /= t01;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2014-03-30 11:08:33 +11:00
|
|
|
*r_sina = -y3 / t02;
|
|
|
|
*r_cosa = x3 / t02;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-05-07 08:53:59 +00:00
|
|
|
static void alfa_bezpart(BezTriple *prevbezt, BezTriple *bezt, Nurb *nu, float *tilt_array, float *radius_array,
|
|
|
|
float *weight_array, int resolu, int stride)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
BezTriple *pprev, *next, *last;
|
|
|
|
float fac, dfac, t[4];
|
|
|
|
int a;
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
if (tilt_array == NULL && radius_array == NULL)
|
2009-09-10 02:57:25 +00:00
|
|
|
return;
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
last = nu->bezt + (nu->pntsu - 1);
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2003-04-25 15:48:11 +00:00
|
|
|
/* returns a point */
|
2012-05-06 15:15:33 +00:00
|
|
|
if (prevbezt == nu->bezt) {
|
2012-05-07 08:53:59 +00:00
|
|
|
if (nu->flagu & CU_NURB_CYCLIC)
|
|
|
|
pprev = last;
|
|
|
|
else
|
|
|
|
pprev = prevbezt;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2012-05-07 08:53:59 +00:00
|
|
|
else
|
|
|
|
pprev = prevbezt - 1;
|
|
|
|
|
2003-04-25 15:48:11 +00:00
|
|
|
/* next point */
|
2012-05-06 15:15:33 +00:00
|
|
|
if (bezt == last) {
|
2012-05-07 08:53:59 +00:00
|
|
|
if (nu->flagu & CU_NURB_CYCLIC)
|
|
|
|
next = nu->bezt;
|
|
|
|
else
|
|
|
|
next = bezt;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2012-05-07 08:53:59 +00:00
|
|
|
else
|
|
|
|
next = bezt + 1;
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
fac = 0.0;
|
|
|
|
dfac = 1.0f / (float)resolu;
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
for (a = 0; a < resolu; a++, fac += dfac) {
|
2008-09-23 13:35:32 +00:00
|
|
|
if (tilt_array) {
|
2012-05-06 15:15:33 +00:00
|
|
|
if (nu->tilt_interp == KEY_CU_EASE) { /* May as well support for tilt also 2.47 ease interp */
|
2012-05-07 08:53:59 +00:00
|
|
|
*tilt_array = prevbezt->alfa +
|
2017-11-02 15:09:11 +11:00
|
|
|
(bezt->alfa - prevbezt->alfa) * (3.0f * fac * fac - 2.0f * fac * fac * fac);
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
|
|
|
else {
|
2009-09-09 18:09:03 +00:00
|
|
|
key_curve_position_weights(fac, t, nu->tilt_interp);
|
2012-05-06 15:15:33 +00:00
|
|
|
*tilt_array = t[0] * pprev->alfa + t[1] * prevbezt->alfa + t[2] * bezt->alfa + t[3] * next->alfa;
|
2008-09-23 13:35:32 +00:00
|
|
|
}
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2016-05-03 16:40:14 +10:00
|
|
|
tilt_array = POINTER_OFFSET(tilt_array, stride);
|
2008-09-23 13:35:32 +00:00
|
|
|
}
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2008-09-23 13:35:32 +00:00
|
|
|
if (radius_array) {
|
2012-05-06 15:15:33 +00:00
|
|
|
if (nu->radius_interp == KEY_CU_EASE) {
|
2008-09-23 13:35:32 +00:00
|
|
|
/* Support 2.47 ease interp
|
|
|
|
* Note! - this only takes the 2 points into account,
|
|
|
|
* giving much more localized results to changes in radius, sometimes you want that */
|
2012-05-07 08:53:59 +00:00
|
|
|
*radius_array = prevbezt->radius +
|
2017-11-02 15:09:11 +11:00
|
|
|
(bezt->radius - prevbezt->radius) * (3.0f * fac * fac - 2.0f * fac * fac * fac);
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2008-09-23 13:35:32 +00:00
|
|
|
/* reuse interpolation from tilt if we can */
|
2012-05-06 15:15:33 +00:00
|
|
|
if (tilt_array == NULL || nu->tilt_interp != nu->radius_interp) {
|
2009-09-09 18:09:03 +00:00
|
|
|
key_curve_position_weights(fac, t, nu->radius_interp);
|
2008-09-23 13:35:32 +00:00
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
*radius_array =
|
2017-11-02 15:09:11 +11:00
|
|
|
t[0] * pprev->radius + t[1] * prevbezt->radius +
|
|
|
|
t[2] * bezt->radius + t[3] * next->radius;
|
2008-09-23 13:35:32 +00:00
|
|
|
}
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2016-05-03 16:40:14 +10:00
|
|
|
radius_array = POINTER_OFFSET(radius_array, stride);
|
2008-09-23 13:35:32 +00:00
|
|
|
}
|
2010-04-21 11:59:47 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (weight_array) {
|
2010-04-21 11:59:47 +00:00
|
|
|
/* basic interpolation for now, could copy tilt interp too */
|
2018-06-17 17:05:51 +02:00
|
|
|
*weight_array =
|
2017-11-02 15:09:11 +11:00
|
|
|
prevbezt->weight +
|
|
|
|
(bezt->weight - prevbezt->weight) * (3.0f * fac * fac - 2.0f * fac * fac * fac);
|
2010-04-21 11:59:47 +00:00
|
|
|
|
2016-05-03 16:40:14 +10:00
|
|
|
weight_array = POINTER_OFFSET(weight_array, stride);
|
2010-04-21 11:59:47 +00:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-11 15:35:30 +00:00
|
|
|
/* make_bevel_list_3D_* funcs, at a minimum these must
|
|
|
|
* fill in the bezp->quat and bezp->dir values */
|
|
|
|
|
|
|
|
/* utility for make_bevel_list_3D_* funcs */
|
|
|
|
static void bevel_list_calc_bisect(BevList *bl)
|
|
|
|
{
|
|
|
|
BevPoint *bevp2, *bevp1, *bevp0;
|
|
|
|
int nr;
|
2013-08-07 18:22:15 +00:00
|
|
|
bool is_cyclic = bl->poly != -1;
|
2009-09-11 15:35:30 +00:00
|
|
|
|
2013-08-07 18:22:15 +00:00
|
|
|
if (is_cyclic) {
|
2014-06-15 14:23:23 +10:00
|
|
|
bevp2 = bl->bevpoints;
|
2013-08-07 18:22:15 +00:00
|
|
|
bevp1 = bevp2 + (bl->nr - 1);
|
|
|
|
bevp0 = bevp1 - 1;
|
|
|
|
nr = bl->nr;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* If spline is not cyclic, direction of first and
|
|
|
|
* last bevel points matches direction of CV handle.
|
|
|
|
*
|
|
|
|
* This is getting calculated earlier when we know
|
|
|
|
* CV's handles and here we might simply skip evaluation
|
|
|
|
* of direction for this guys.
|
|
|
|
*/
|
|
|
|
|
2014-06-15 14:23:23 +10:00
|
|
|
bevp0 = bl->bevpoints;
|
2013-08-07 18:22:15 +00:00
|
|
|
bevp1 = bevp0 + 1;
|
|
|
|
bevp2 = bevp1 + 1;
|
|
|
|
|
|
|
|
nr = bl->nr - 2;
|
|
|
|
}
|
2009-09-11 15:35:30 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
while (nr--) {
|
2009-09-11 15:35:30 +00:00
|
|
|
/* totally simple */
|
2009-11-10 20:43:45 +00:00
|
|
|
bisect_v3_v3v3v3(bevp1->dir, bevp0->vec, bevp1->vec, bevp2->vec);
|
2009-09-11 15:35:30 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
bevp0 = bevp1;
|
|
|
|
bevp1 = bevp2;
|
2009-09-11 15:35:30 +00:00
|
|
|
bevp2++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
static void bevel_list_flip_tangents(BevList *bl)
|
|
|
|
{
|
|
|
|
BevPoint *bevp2, *bevp1, *bevp0;
|
|
|
|
int nr;
|
|
|
|
|
2014-06-15 14:23:23 +10:00
|
|
|
bevp2 = bl->bevpoints;
|
2012-05-06 15:15:33 +00:00
|
|
|
bevp1 = bevp2 + (bl->nr - 1);
|
|
|
|
bevp0 = bevp1 - 1;
|
2009-09-11 15:35:30 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
nr = bl->nr;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (nr--) {
|
2013-04-14 11:56:11 +00:00
|
|
|
if (angle_normalized_v3v3(bevp0->tan, bevp1->tan) > DEG2RADF(90.0f))
|
2009-11-10 20:43:45 +00:00
|
|
|
negate_v3(bevp1->tan);
|
2009-09-11 15:35:30 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
bevp0 = bevp1;
|
|
|
|
bevp1 = bevp2;
|
2009-09-11 15:35:30 +00:00
|
|
|
bevp2++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* apply user tilt */
|
|
|
|
static void bevel_list_apply_tilt(BevList *bl)
|
|
|
|
{
|
2011-03-19 05:06:06 +00:00
|
|
|
BevPoint *bevp2, *bevp1;
|
2009-09-11 15:35:30 +00:00
|
|
|
int nr;
|
|
|
|
float q[4];
|
|
|
|
|
2014-06-15 14:23:23 +10:00
|
|
|
bevp2 = bl->bevpoints;
|
2012-05-06 15:15:33 +00:00
|
|
|
bevp1 = bevp2 + (bl->nr - 1);
|
2009-09-11 15:35:30 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
nr = bl->nr;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (nr--) {
|
2009-11-10 20:43:45 +00:00
|
|
|
axis_angle_to_quat(q, bevp1->dir, bevp1->alfa);
|
|
|
|
mul_qt_qtqt(bevp1->quat, q, bevp1->quat);
|
|
|
|
normalize_qt(bevp1->quat);
|
2009-09-11 15:35:30 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
bevp1 = bevp2;
|
2009-09-11 15:35:30 +00:00
|
|
|
bevp2++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* smooth quats, this function should be optimized, it can get slow with many iterations. */
|
|
|
|
static void bevel_list_smooth(BevList *bl, int smooth_iter)
|
|
|
|
{
|
|
|
|
BevPoint *bevp2, *bevp1, *bevp0;
|
|
|
|
int nr;
|
|
|
|
|
|
|
|
float q[4];
|
|
|
|
float bevp0_quat[4];
|
|
|
|
int a;
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
for (a = 0; a < smooth_iter; a++) {
|
2014-06-15 14:23:23 +10:00
|
|
|
bevp2 = bl->bevpoints;
|
2012-05-06 15:15:33 +00:00
|
|
|
bevp1 = bevp2 + (bl->nr - 1);
|
|
|
|
bevp0 = bevp1 - 1;
|
2009-09-11 15:35:30 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
nr = bl->nr;
|
2009-09-11 15:35:30 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
if (bl->poly == -1) { /* check its not cyclic */
|
2009-09-11 15:35:30 +00:00
|
|
|
/* skip the first point */
|
2012-10-26 04:14:10 +00:00
|
|
|
/* bevp0 = bevp1; */
|
2012-05-06 15:15:33 +00:00
|
|
|
bevp1 = bevp2;
|
2009-09-11 15:35:30 +00:00
|
|
|
bevp2++;
|
|
|
|
nr--;
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
bevp0 = bevp1;
|
|
|
|
bevp1 = bevp2;
|
2009-09-11 15:35:30 +00:00
|
|
|
bevp2++;
|
|
|
|
nr--;
|
|
|
|
}
|
|
|
|
|
2011-10-28 12:40:15 +00:00
|
|
|
copy_qt_qt(bevp0_quat, bevp0->quat);
|
2009-09-11 15:35:30 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
while (nr--) {
|
2009-09-11 15:35:30 +00:00
|
|
|
/* interpolate quats */
|
2012-04-29 15:47:02 +00:00
|
|
|
float zaxis[3] = {0, 0, 1}, cross[3], q2[4];
|
2009-11-10 20:43:45 +00:00
|
|
|
interp_qt_qtqt(q, bevp0_quat, bevp2->quat, 0.5);
|
|
|
|
normalize_qt(q);
|
2009-09-11 15:35:30 +00:00
|
|
|
|
2009-11-10 20:43:45 +00:00
|
|
|
mul_qt_v3(q, zaxis);
|
|
|
|
cross_v3_v3v3(cross, zaxis, bevp1->dir);
|
|
|
|
axis_angle_to_quat(q2, cross, angle_normalized_v3v3(zaxis, bevp1->dir));
|
|
|
|
normalize_qt(q2);
|
2009-09-11 15:35:30 +00:00
|
|
|
|
2011-10-28 12:40:15 +00:00
|
|
|
copy_qt_qt(bevp0_quat, bevp1->quat);
|
2009-11-10 20:43:45 +00:00
|
|
|
mul_qt_qtqt(q, q2, q);
|
|
|
|
interp_qt_qtqt(bevp1->quat, bevp1->quat, q, 0.5);
|
|
|
|
normalize_qt(bevp1->quat);
|
2009-09-11 15:35:30 +00:00
|
|
|
|
2012-10-26 04:14:10 +00:00
|
|
|
/* bevp0 = bevp1; */ /* UNUSED */
|
2012-05-06 15:15:33 +00:00
|
|
|
bevp1 = bevp2;
|
2009-09-11 15:35:30 +00:00
|
|
|
bevp2++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void make_bevel_list_3D_zup(BevList *bl)
|
|
|
|
{
|
2014-06-15 14:23:23 +10:00
|
|
|
BevPoint *bevp = bl->bevpoints;
|
2013-08-07 18:22:15 +00:00
|
|
|
int nr = bl->nr;
|
2009-09-11 15:35:30 +00:00
|
|
|
|
2013-08-07 18:22:15 +00:00
|
|
|
bevel_list_calc_bisect(bl);
|
2009-09-11 15:35:30 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
while (nr--) {
|
2013-08-07 18:22:15 +00:00
|
|
|
vec_to_quat(bevp->quat, bevp->dir, 5, 1);
|
|
|
|
bevp++;
|
|
|
|
}
|
|
|
|
}
|
2009-09-11 15:35:30 +00:00
|
|
|
|
2013-08-07 18:22:15 +00:00
|
|
|
static void minimum_twist_between_two_points(BevPoint *current_point, BevPoint *previous_point)
|
|
|
|
{
|
|
|
|
float angle = angle_normalized_v3v3(previous_point->dir, current_point->dir);
|
|
|
|
float q[4];
|
|
|
|
|
|
|
|
if (angle > 0.0f) { /* otherwise we can keep as is */
|
|
|
|
float cross_tmp[3];
|
|
|
|
cross_v3_v3v3(cross_tmp, previous_point->dir, current_point->dir);
|
|
|
|
axis_angle_to_quat(q, cross_tmp, angle);
|
|
|
|
mul_qt_qtqt(current_point->quat, q, previous_point->quat);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
copy_qt_qt(current_point->quat, previous_point->quat);
|
2009-09-11 15:35:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void make_bevel_list_3D_minimum_twist(BevList *bl)
|
|
|
|
{
|
|
|
|
BevPoint *bevp2, *bevp1, *bevp0; /* standard for all make_bevel_list_3D_* funcs */
|
|
|
|
int nr;
|
|
|
|
float q[4];
|
|
|
|
|
|
|
|
bevel_list_calc_bisect(bl);
|
|
|
|
|
2014-06-15 14:23:23 +10:00
|
|
|
bevp2 = bl->bevpoints;
|
2012-05-06 15:15:33 +00:00
|
|
|
bevp1 = bevp2 + (bl->nr - 1);
|
|
|
|
bevp0 = bevp1 - 1;
|
2009-09-11 15:35:30 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
nr = bl->nr;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (nr--) {
|
2009-09-11 15:35:30 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
if (nr + 4 > bl->nr) { /* first time and second time, otherwise first point adjusts last */
|
2012-04-29 15:47:02 +00:00
|
|
|
vec_to_quat(bevp1->quat, bevp1->dir, 5, 1);
|
2009-09-11 15:35:30 +00:00
|
|
|
}
|
|
|
|
else {
|
2013-08-07 18:22:15 +00:00
|
|
|
minimum_twist_between_two_points(bevp1, bevp0);
|
2009-09-11 15:35:30 +00:00
|
|
|
}
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
bevp0 = bevp1;
|
|
|
|
bevp1 = bevp2;
|
2009-09-11 15:35:30 +00:00
|
|
|
bevp2++;
|
|
|
|
}
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (bl->poly != -1) { /* check for cyclic */
|
2009-09-11 15:35:30 +00:00
|
|
|
|
|
|
|
/* Need to correct for the start/end points not matching
|
|
|
|
* do this by calculating the tilt angle difference, then apply
|
|
|
|
* the rotation gradually over the entire curve
|
|
|
|
*
|
2011-05-28 13:11:24 +00:00
|
|
|
* note that the split is between last and second last, rather than first/last as youd expect.
|
2009-09-11 15:35:30 +00:00
|
|
|
*
|
|
|
|
* real order is like this
|
|
|
|
* 0,1,2,3,4 --> 1,2,3,4,0
|
|
|
|
*
|
|
|
|
* this is why we compare last with second last
|
|
|
|
* */
|
2012-05-06 15:15:33 +00:00
|
|
|
float vec_1[3] = {0, 1, 0}, vec_2[3] = {0, 1, 0}, angle, ang_fac, cross_tmp[3];
|
2009-09-11 15:35:30 +00:00
|
|
|
|
|
|
|
BevPoint *bevp_first;
|
|
|
|
BevPoint *bevp_last;
|
|
|
|
|
|
|
|
|
2014-06-15 14:23:23 +10:00
|
|
|
bevp_first = bl->bevpoints;
|
2012-05-06 15:15:33 +00:00
|
|
|
bevp_first += bl->nr - 1;
|
2009-09-11 15:35:30 +00:00
|
|
|
bevp_last = bevp_first;
|
|
|
|
bevp_last--;
|
|
|
|
|
|
|
|
/* quats and vec's are normalized, should not need to re-normalize */
|
2009-11-10 20:43:45 +00:00
|
|
|
mul_qt_v3(bevp_first->quat, vec_1);
|
|
|
|
mul_qt_v3(bevp_last->quat, vec_2);
|
|
|
|
normalize_v3(vec_1);
|
|
|
|
normalize_v3(vec_2);
|
2009-09-11 15:35:30 +00:00
|
|
|
|
|
|
|
/* align the vector, can avoid this and it looks 98% OK but
|
2012-05-16 23:37:23 +00:00
|
|
|
* better to align the angle quat roll's before comparing */
|
2009-09-11 15:35:30 +00:00
|
|
|
{
|
2009-11-10 20:43:45 +00:00
|
|
|
cross_v3_v3v3(cross_tmp, bevp_last->dir, bevp_first->dir);
|
|
|
|
angle = angle_normalized_v3v3(bevp_first->dir, bevp_last->dir);
|
|
|
|
axis_angle_to_quat(q, cross_tmp, angle);
|
|
|
|
mul_qt_v3(q, vec_2);
|
2009-09-11 15:35:30 +00:00
|
|
|
}
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
angle = angle_normalized_v3v3(vec_1, vec_2);
|
2009-09-11 15:35:30 +00:00
|
|
|
|
|
|
|
/* flip rotation if needs be */
|
2009-11-10 20:43:45 +00:00
|
|
|
cross_v3_v3v3(cross_tmp, vec_1, vec_2);
|
|
|
|
normalize_v3(cross_tmp);
|
2012-03-24 06:18:31 +00:00
|
|
|
if (angle_normalized_v3v3(bevp_first->dir, cross_tmp) < DEG2RADF(90.0f))
|
2009-09-11 15:35:30 +00:00
|
|
|
angle = -angle;
|
|
|
|
|
2014-06-15 14:23:23 +10:00
|
|
|
bevp2 = bl->bevpoints;
|
2012-05-06 15:15:33 +00:00
|
|
|
bevp1 = bevp2 + (bl->nr - 1);
|
|
|
|
bevp0 = bevp1 - 1;
|
2009-09-11 15:35:30 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
nr = bl->nr;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (nr--) {
|
2012-05-06 15:15:33 +00:00
|
|
|
ang_fac = angle * (1.0f - ((float)nr / bl->nr)); /* also works */
|
2009-09-11 15:35:30 +00:00
|
|
|
|
2009-11-10 20:43:45 +00:00
|
|
|
axis_angle_to_quat(q, bevp1->dir, ang_fac);
|
|
|
|
mul_qt_qtqt(bevp1->quat, q, bevp1->quat);
|
2009-09-11 15:35:30 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
bevp0 = bevp1;
|
|
|
|
bevp1 = bevp2;
|
2009-09-11 15:35:30 +00:00
|
|
|
bevp2++;
|
|
|
|
}
|
|
|
|
}
|
2013-08-07 18:22:15 +00:00
|
|
|
else {
|
2013-08-13 15:27:49 +00:00
|
|
|
/* Need to correct quat for the first/last point,
|
2013-08-07 18:22:15 +00:00
|
|
|
* this is so because previously it was only calculated
|
|
|
|
* using it's own direction, which might not correspond
|
2013-08-13 15:27:49 +00:00
|
|
|
* the twist of neighbor point.
|
2013-08-07 18:22:15 +00:00
|
|
|
*/
|
2014-06-15 14:23:23 +10:00
|
|
|
bevp1 = bl->bevpoints;
|
2013-08-13 15:27:49 +00:00
|
|
|
bevp0 = bevp1 + 1;
|
|
|
|
minimum_twist_between_two_points(bevp1, bevp0);
|
|
|
|
|
2014-06-15 14:23:23 +10:00
|
|
|
bevp2 = bl->bevpoints;
|
2013-08-07 18:22:15 +00:00
|
|
|
bevp1 = bevp2 + (bl->nr - 1);
|
|
|
|
bevp0 = bevp1 - 1;
|
|
|
|
minimum_twist_between_two_points(bevp1, bevp0);
|
|
|
|
}
|
2009-09-11 15:35:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void make_bevel_list_3D_tangent(BevList *bl)
|
|
|
|
{
|
|
|
|
BevPoint *bevp2, *bevp1, *bevp0; /* standard for all make_bevel_list_3D_* funcs */
|
|
|
|
int nr;
|
|
|
|
|
2012-10-12 14:35:10 +00:00
|
|
|
float bevp0_tan[3];
|
2009-09-11 15:35:30 +00:00
|
|
|
|
|
|
|
bevel_list_calc_bisect(bl);
|
|
|
|
bevel_list_flip_tangents(bl);
|
|
|
|
|
|
|
|
/* correct the tangents */
|
2014-06-15 14:23:23 +10:00
|
|
|
bevp2 = bl->bevpoints;
|
2012-05-06 15:15:33 +00:00
|
|
|
bevp1 = bevp2 + (bl->nr - 1);
|
|
|
|
bevp0 = bevp1 - 1;
|
2009-09-11 15:35:30 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
nr = bl->nr;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (nr--) {
|
2012-10-12 14:35:10 +00:00
|
|
|
float cross_tmp[3];
|
2009-11-10 20:43:45 +00:00
|
|
|
cross_v3_v3v3(cross_tmp, bevp1->tan, bevp1->dir);
|
|
|
|
cross_v3_v3v3(bevp1->tan, cross_tmp, bevp1->dir);
|
|
|
|
normalize_v3(bevp1->tan);
|
2009-09-11 15:35:30 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
bevp0 = bevp1;
|
|
|
|
bevp1 = bevp2;
|
2009-09-11 15:35:30 +00:00
|
|
|
bevp2++;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* now for the real twist calc */
|
2014-06-15 14:23:23 +10:00
|
|
|
bevp2 = bl->bevpoints;
|
2012-05-06 15:15:33 +00:00
|
|
|
bevp1 = bevp2 + (bl->nr - 1);
|
|
|
|
bevp0 = bevp1 - 1;
|
2009-09-11 15:35:30 +00:00
|
|
|
|
2011-10-28 12:40:15 +00:00
|
|
|
copy_v3_v3(bevp0_tan, bevp0->tan);
|
2009-09-11 15:35:30 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
nr = bl->nr;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (nr--) {
|
2009-09-11 15:35:30 +00:00
|
|
|
/* make perpendicular, modify tan in place, is ok */
|
|
|
|
float cross_tmp[3];
|
2012-04-29 15:47:02 +00:00
|
|
|
float zero[3] = {0, 0, 0};
|
2009-09-11 15:35:30 +00:00
|
|
|
|
2009-11-10 20:43:45 +00:00
|
|
|
cross_v3_v3v3(cross_tmp, bevp1->tan, bevp1->dir);
|
|
|
|
normalize_v3(cross_tmp);
|
2012-04-29 15:47:02 +00:00
|
|
|
tri_to_quat(bevp1->quat, zero, cross_tmp, bevp1->tan); /* XXX - could be faster */
|
2009-09-11 15:35:30 +00:00
|
|
|
|
2012-10-26 04:14:10 +00:00
|
|
|
/* bevp0 = bevp1; */ /* UNUSED */
|
2012-05-06 15:15:33 +00:00
|
|
|
bevp1 = bevp2;
|
2009-09-11 15:35:30 +00:00
|
|
|
bevp2++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-14 16:52:06 +00:00
|
|
|
static void make_bevel_list_3D(BevList *bl, int smooth_iter, int twist_mode)
|
2009-09-11 15:35:30 +00:00
|
|
|
{
|
2012-04-28 06:31:57 +00:00
|
|
|
switch (twist_mode) {
|
2012-05-06 15:15:33 +00:00
|
|
|
case CU_TWIST_TANGENT:
|
|
|
|
make_bevel_list_3D_tangent(bl);
|
|
|
|
break;
|
|
|
|
case CU_TWIST_MINIMUM:
|
|
|
|
make_bevel_list_3D_minimum_twist(bl);
|
|
|
|
break;
|
|
|
|
default: /* CU_TWIST_Z_UP default, pre 2.49c */
|
|
|
|
make_bevel_list_3D_zup(bl);
|
2013-07-21 08:16:37 +00:00
|
|
|
break;
|
2009-09-11 15:35:30 +00:00
|
|
|
}
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (smooth_iter)
|
2009-09-11 15:35:30 +00:00
|
|
|
bevel_list_smooth(bl, smooth_iter);
|
|
|
|
|
|
|
|
bevel_list_apply_tilt(bl);
|
|
|
|
}
|
|
|
|
|
2009-11-21 14:35:28 +00:00
|
|
|
/* only for 2 points */
|
|
|
|
static void make_bevel_list_segment_3D(BevList *bl)
|
|
|
|
{
|
|
|
|
float q[4];
|
|
|
|
|
2014-06-15 14:23:23 +10:00
|
|
|
BevPoint *bevp2 = bl->bevpoints;
|
2012-05-06 15:15:33 +00:00
|
|
|
BevPoint *bevp1 = bevp2 + 1;
|
2009-11-21 14:35:28 +00:00
|
|
|
|
|
|
|
/* simple quat/dir */
|
|
|
|
sub_v3_v3v3(bevp1->dir, bevp1->vec, bevp2->vec);
|
|
|
|
normalize_v3(bevp1->dir);
|
|
|
|
|
2012-04-29 15:47:02 +00:00
|
|
|
vec_to_quat(bevp1->quat, bevp1->dir, 5, 1);
|
2009-11-21 14:35:28 +00:00
|
|
|
|
|
|
|
axis_angle_to_quat(q, bevp1->dir, bevp1->alfa);
|
|
|
|
mul_qt_qtqt(bevp1->quat, q, bevp1->quat);
|
|
|
|
normalize_qt(bevp1->quat);
|
2011-10-28 12:40:15 +00:00
|
|
|
copy_v3_v3(bevp2->dir, bevp1->dir);
|
|
|
|
copy_qt_qt(bevp2->quat, bevp1->quat);
|
2009-11-21 14:35:28 +00:00
|
|
|
}
|
|
|
|
|
2013-02-21 17:16:51 +00:00
|
|
|
/* only for 2 points */
|
|
|
|
static void make_bevel_list_segment_2D(BevList *bl)
|
|
|
|
{
|
2014-06-15 14:23:23 +10:00
|
|
|
BevPoint *bevp2 = bl->bevpoints;
|
2013-02-21 17:16:51 +00:00
|
|
|
BevPoint *bevp1 = bevp2 + 1;
|
|
|
|
|
|
|
|
const float x1 = bevp1->vec[0] - bevp2->vec[0];
|
|
|
|
const float y1 = bevp1->vec[1] - bevp2->vec[1];
|
|
|
|
|
|
|
|
calc_bevel_sin_cos(x1, y1, -x1, -y1, &(bevp1->sina), &(bevp1->cosa));
|
|
|
|
bevp2->sina = bevp1->sina;
|
|
|
|
bevp2->cosa = bevp1->cosa;
|
|
|
|
|
|
|
|
/* fill in dir & quat */
|
|
|
|
make_bevel_list_segment_3D(bl);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void make_bevel_list_2D(BevList *bl)
|
|
|
|
{
|
|
|
|
/* note: bevp->dir and bevp->quat are not needed for beveling but are
|
2018-09-24 17:27:41 +02:00
|
|
|
* used when making a path from a 2D curve, therefore they need to be set - Campbell */
|
2013-02-21 17:16:51 +00:00
|
|
|
|
2013-08-14 19:45:35 +00:00
|
|
|
BevPoint *bevp0, *bevp1, *bevp2;
|
2013-02-21 17:16:51 +00:00
|
|
|
int nr;
|
|
|
|
|
2013-08-14 19:45:35 +00:00
|
|
|
if (bl->poly != -1) {
|
2014-06-15 14:23:23 +10:00
|
|
|
bevp2 = bl->bevpoints;
|
2013-08-14 19:45:35 +00:00
|
|
|
bevp1 = bevp2 + (bl->nr - 1);
|
|
|
|
bevp0 = bevp1 - 1;
|
|
|
|
nr = bl->nr;
|
|
|
|
}
|
|
|
|
else {
|
2014-06-15 14:23:23 +10:00
|
|
|
bevp0 = bl->bevpoints;
|
2013-08-14 19:45:35 +00:00
|
|
|
bevp1 = bevp0 + 1;
|
|
|
|
bevp2 = bevp1 + 1;
|
|
|
|
|
|
|
|
nr = bl->nr - 2;
|
|
|
|
}
|
|
|
|
|
2013-02-21 17:16:51 +00:00
|
|
|
while (nr--) {
|
|
|
|
const float x1 = bevp1->vec[0] - bevp0->vec[0];
|
|
|
|
const float x2 = bevp1->vec[0] - bevp2->vec[0];
|
|
|
|
const float y1 = bevp1->vec[1] - bevp0->vec[1];
|
|
|
|
const float y2 = bevp1->vec[1] - bevp2->vec[1];
|
|
|
|
|
|
|
|
calc_bevel_sin_cos(x1, y1, x2, y2, &(bevp1->sina), &(bevp1->cosa));
|
|
|
|
|
|
|
|
/* from: make_bevel_list_3D_zup, could call but avoid a second loop.
|
|
|
|
* no need for tricky tilt calculation as with 3D curves */
|
|
|
|
bisect_v3_v3v3v3(bevp1->dir, bevp0->vec, bevp1->vec, bevp2->vec);
|
|
|
|
vec_to_quat(bevp1->quat, bevp1->dir, 5, 1);
|
|
|
|
/* done with inline make_bevel_list_3D_zup */
|
|
|
|
|
|
|
|
bevp0 = bevp1;
|
|
|
|
bevp1 = bevp2;
|
|
|
|
bevp2++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* correct non-cyclic cases */
|
|
|
|
if (bl->poly == -1) {
|
2013-08-14 19:45:35 +00:00
|
|
|
BevPoint *bevp;
|
|
|
|
float angle;
|
|
|
|
|
|
|
|
/* first */
|
2014-06-15 14:23:23 +10:00
|
|
|
bevp = bl->bevpoints;
|
2015-01-31 17:23:30 +11:00
|
|
|
angle = atan2f(bevp->dir[0], bevp->dir[1]) - (float)M_PI_2;
|
2013-08-14 19:45:35 +00:00
|
|
|
bevp->sina = sinf(angle);
|
|
|
|
bevp->cosa = cosf(angle);
|
|
|
|
vec_to_quat(bevp->quat, bevp->dir, 5, 1);
|
|
|
|
|
|
|
|
/* last */
|
2014-06-15 14:23:23 +10:00
|
|
|
bevp = bl->bevpoints;
|
2013-02-21 17:16:51 +00:00
|
|
|
bevp += (bl->nr - 1);
|
2015-01-31 17:23:30 +11:00
|
|
|
angle = atan2f(bevp->dir[0], bevp->dir[1]) - (float)M_PI_2;
|
2013-08-14 19:45:35 +00:00
|
|
|
bevp->sina = sinf(angle);
|
|
|
|
bevp->cosa = cosf(angle);
|
|
|
|
vec_to_quat(bevp->quat, bevp->dir, 5, 1);
|
2013-02-21 17:16:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-12 09:00:48 +00:00
|
|
|
static void bevlist_firstlast_direction_calc_from_bpoint(Nurb *nu, BevList *bl)
|
|
|
|
{
|
|
|
|
if (nu->pntsu > 1) {
|
|
|
|
BPoint *first_bp = nu->bp, *last_bp = nu->bp + (nu->pntsu - 1);
|
|
|
|
BevPoint *first_bevp, *last_bevp;
|
|
|
|
|
2014-06-15 14:23:23 +10:00
|
|
|
first_bevp = bl->bevpoints;
|
2013-08-12 09:00:48 +00:00
|
|
|
last_bevp = first_bevp + (bl->nr - 1);
|
|
|
|
|
|
|
|
sub_v3_v3v3(first_bevp->dir, (first_bp + 1)->vec, first_bp->vec);
|
|
|
|
normalize_v3(first_bevp->dir);
|
|
|
|
|
|
|
|
sub_v3_v3v3(last_bevp->dir, last_bp->vec, (last_bp - 1)->vec);
|
|
|
|
normalize_v3(last_bevp->dir);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-18 17:35:51 +06:00
|
|
|
void BKE_curve_bevelList_free(ListBase *bev)
|
|
|
|
{
|
|
|
|
BevList *bl, *blnext;
|
|
|
|
for (bl = bev->first; bl != NULL; bl = blnext) {
|
|
|
|
blnext = bl->next;
|
|
|
|
if (bl->seglen != NULL) {
|
|
|
|
MEM_freeN(bl->seglen);
|
|
|
|
}
|
|
|
|
if (bl->segbevcount != NULL) {
|
|
|
|
MEM_freeN(bl->segbevcount);
|
|
|
|
}
|
2018-01-18 20:54:49 +11:00
|
|
|
if (bl->bevpoints != NULL) {
|
|
|
|
MEM_freeN(bl->bevpoints);
|
|
|
|
}
|
2014-08-18 17:35:51 +06:00
|
|
|
MEM_freeN(bl);
|
|
|
|
}
|
2015-06-20 17:09:05 +10:00
|
|
|
|
|
|
|
BLI_listbase_clear(bev);
|
2014-08-18 17:35:51 +06:00
|
|
|
}
|
|
|
|
|
2013-08-19 09:36:40 +00:00
|
|
|
void BKE_curve_bevelList_make(Object *ob, ListBase *nurbs, bool for_render)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2003-04-25 15:48:11 +00:00
|
|
|
/*
|
2012-03-03 20:19:11 +00:00
|
|
|
* - convert all curves to polys, with indication of resol and flags for double-vertices
|
|
|
|
* - possibly; do a smart vertice removal (in case Nurb)
|
2014-06-09 11:01:51 +10:00
|
|
|
* - separate in individual blocks with BoundBox
|
2012-03-03 20:19:11 +00:00
|
|
|
* - AutoHole detection
|
|
|
|
*/
|
2014-08-18 17:35:51 +06:00
|
|
|
|
|
|
|
/* this function needs an object, because of tflag and upflag */
|
|
|
|
Curve *cu = ob->data;
|
2002-10-12 11:37:38 +00:00
|
|
|
Nurb *nu;
|
|
|
|
BezTriple *bezt, *prevbezt;
|
|
|
|
BPoint *bp;
|
|
|
|
BevList *bl, *blnew, *blnext;
|
2015-11-23 11:27:02 +11:00
|
|
|
BevPoint *bevp2, *bevp1 = NULL, *bevp0;
|
2014-08-18 17:35:51 +06:00
|
|
|
const float treshold = 0.00001f;
|
2013-02-21 17:16:51 +00:00
|
|
|
float min, inp;
|
2015-09-04 01:04:37 +02:00
|
|
|
float *seglen = NULL;
|
2013-09-05 21:45:05 +00:00
|
|
|
struct BevelSort *sortdata, *sd, *sd1;
|
2014-08-18 17:35:51 +06:00
|
|
|
int a, b, nr, poly, resolu = 0, len = 0, segcount;
|
|
|
|
int *segbevcount;
|
2014-04-01 11:34:00 +11:00
|
|
|
bool do_tilt, do_radius, do_weight;
|
2014-02-03 18:55:59 +11:00
|
|
|
bool is_editmode = false;
|
2013-08-19 09:25:24 +00:00
|
|
|
ListBase *bev;
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2014-08-18 17:35:51 +06:00
|
|
|
/* segbevcount alsp requires seglen. */
|
|
|
|
const bool need_seglen =
|
2014-08-21 00:10:57 +10:00
|
|
|
ELEM(cu->bevfac1_mapping, CU_BEVFAC_MAP_SEGMENT, CU_BEVFAC_MAP_SPLINE) ||
|
|
|
|
ELEM(cu->bevfac2_mapping, CU_BEVFAC_MAP_SEGMENT, CU_BEVFAC_MAP_SPLINE);
|
2014-08-18 17:35:51 +06:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2018-07-30 16:54:40 +02:00
|
|
|
bev = &ob->runtime.curve_cache->bev;
|
2013-08-19 09:25:24 +00:00
|
|
|
|
2008-09-23 13:35:32 +00:00
|
|
|
/* do we need to calculate the radius for each point? */
|
2008-09-23 15:57:05 +00:00
|
|
|
/* do_radius = (cu->bevobj || cu->taperobj || (cu->flag & CU_FRONT) || (cu->flag & CU_BACK)) ? 0 : 1; */
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2003-04-25 15:48:11 +00:00
|
|
|
/* STEP 1: MAKE POLYS */
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2018-07-30 16:54:40 +02:00
|
|
|
BKE_curve_bevelList_free(&ob->runtime.curve_cache->bev);
|
2013-08-19 09:36:40 +00:00
|
|
|
nu = nurbs->first;
|
2012-05-06 15:15:33 +00:00
|
|
|
if (cu->editnurb && ob->type != OB_FONT) {
|
2013-01-15 15:42:12 +00:00
|
|
|
is_editmode = 1;
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2013-01-15 15:42:12 +00:00
|
|
|
for (; nu; nu = nu->next) {
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2013-01-15 15:42:12 +00:00
|
|
|
if (nu->hide && is_editmode)
|
|
|
|
continue;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2008-09-23 13:35:32 +00:00
|
|
|
/* check if we will calculate tilt data */
|
2009-04-20 15:06:46 +00:00
|
|
|
do_tilt = CU_DO_TILT(cu, nu);
|
|
|
|
do_radius = CU_DO_RADIUS(cu, nu); /* normal display uses the radius, better just to calculate them */
|
2014-04-01 11:34:00 +11:00
|
|
|
do_weight = true;
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2008-05-17 22:37:34 +00:00
|
|
|
/* check we are a single point? also check we are not a surface and that the orderu is sane,
|
|
|
|
* enforced in the UI but can go wrong possibly */
|
2012-04-28 16:49:00 +00:00
|
|
|
if (!BKE_nurb_check_valid_u(nu)) {
|
2018-01-15 06:57:26 +01:00
|
|
|
bl = MEM_callocN(sizeof(BevList), "makeBevelList1");
|
|
|
|
bl->bevpoints = MEM_calloc_arrayN(1, sizeof(BevPoint), "makeBevelPoints1");
|
2013-08-19 09:25:24 +00:00
|
|
|
BLI_addtail(bev, bl);
|
2012-05-06 15:15:33 +00:00
|
|
|
bl->nr = 0;
|
2013-07-17 14:05:50 +00:00
|
|
|
bl->charidx = nu->charidx;
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
|
|
|
else {
|
2015-11-23 11:27:02 +11:00
|
|
|
BevPoint *bevp;
|
|
|
|
|
2013-08-19 09:36:40 +00:00
|
|
|
if (for_render && cu->resolu_ren != 0)
|
2012-05-06 15:15:33 +00:00
|
|
|
resolu = cu->resolu_ren;
|
2006-02-07 19:59:02 +00:00
|
|
|
else
|
2012-05-06 15:15:33 +00:00
|
|
|
resolu = nu->resolu;
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2014-08-18 17:35:51 +06:00
|
|
|
segcount = SEGMENTSU(nu);
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (nu->type == CU_POLY) {
|
2012-05-06 15:15:33 +00:00
|
|
|
len = nu->pntsu;
|
2018-01-15 06:57:26 +01:00
|
|
|
bl = MEM_callocN(sizeof(BevList), "makeBevelList2");
|
|
|
|
bl->bevpoints = MEM_calloc_arrayN(len, sizeof(BevPoint), "makeBevelPoints2");
|
2014-09-30 15:57:06 +06:00
|
|
|
if (need_seglen && (nu->flagu & CU_NURB_CYCLIC) == 0) {
|
2018-01-14 22:14:20 +01:00
|
|
|
bl->seglen = MEM_malloc_arrayN(segcount, sizeof(float), "makeBevelList2_seglen");
|
|
|
|
bl->segbevcount = MEM_malloc_arrayN(segcount, sizeof(int), "makeBevelList2_segbevcount");
|
2014-08-18 17:35:51 +06:00
|
|
|
}
|
2013-08-19 09:25:24 +00:00
|
|
|
BLI_addtail(bev, bl);
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2013-07-17 14:05:50 +00:00
|
|
|
bl->poly = (nu->flagu & CU_NURB_CYCLIC) ? 0 : -1;
|
2012-05-06 15:15:33 +00:00
|
|
|
bl->nr = len;
|
|
|
|
bl->dupe_nr = 0;
|
2013-07-17 14:05:50 +00:00
|
|
|
bl->charidx = nu->charidx;
|
2014-06-15 14:23:23 +10:00
|
|
|
bevp = bl->bevpoints;
|
2014-08-18 17:35:51 +06:00
|
|
|
bevp->offset = 0;
|
2012-05-06 15:15:33 +00:00
|
|
|
bp = nu->bp;
|
2014-08-18 17:35:51 +06:00
|
|
|
seglen = bl->seglen;
|
|
|
|
segbevcount = bl->segbevcount;
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
while (len--) {
|
2011-10-28 12:40:15 +00:00
|
|
|
copy_v3_v3(bevp->vec, bp->vec);
|
2012-05-06 15:15:33 +00:00
|
|
|
bevp->alfa = bp->alfa;
|
|
|
|
bevp->radius = bp->radius;
|
|
|
|
bevp->weight = bp->weight;
|
2014-04-01 11:34:00 +11:00
|
|
|
bevp->split_tag = true;
|
2002-10-12 11:37:38 +00:00
|
|
|
bp++;
|
2014-09-30 15:57:06 +06:00
|
|
|
if (seglen != NULL && len != 0) {
|
2014-08-18 17:35:51 +06:00
|
|
|
*seglen = len_v3v3(bevp->vec, bp->vec);
|
|
|
|
bevp++;
|
|
|
|
bevp->offset = *seglen;
|
|
|
|
if (*seglen > treshold) *segbevcount = 1;
|
|
|
|
else *segbevcount = 0;
|
|
|
|
seglen++;
|
|
|
|
segbevcount++;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
bevp++;
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2013-08-12 09:00:48 +00:00
|
|
|
|
|
|
|
if ((nu->flagu & CU_NURB_CYCLIC) == 0) {
|
|
|
|
bevlist_firstlast_direction_calc_from_bpoint(nu, bl);
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
else if (nu->type == CU_BEZIER) {
|
2012-05-07 08:53:59 +00:00
|
|
|
/* in case last point is not cyclic */
|
2014-08-18 17:35:51 +06:00
|
|
|
len = segcount * resolu + 1;
|
|
|
|
|
2018-01-15 06:57:26 +01:00
|
|
|
bl = MEM_callocN(sizeof(BevList), "makeBevelBPoints");
|
|
|
|
bl->bevpoints = MEM_calloc_arrayN(len, sizeof(BevPoint), "makeBevelBPointsPoints");
|
2014-09-30 15:57:06 +06:00
|
|
|
if (need_seglen && (nu->flagu & CU_NURB_CYCLIC) == 0) {
|
2018-01-14 22:14:20 +01:00
|
|
|
bl->seglen = MEM_malloc_arrayN(segcount, sizeof(float), "makeBevelBPoints_seglen");
|
|
|
|
bl->segbevcount = MEM_malloc_arrayN(segcount, sizeof(int), "makeBevelBPoints_segbevcount");
|
2014-08-18 17:35:51 +06:00
|
|
|
}
|
2013-08-19 09:25:24 +00:00
|
|
|
BLI_addtail(bev, bl);
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2013-07-17 14:05:50 +00:00
|
|
|
bl->poly = (nu->flagu & CU_NURB_CYCLIC) ? 0 : -1;
|
|
|
|
bl->charidx = nu->charidx;
|
2014-08-18 17:35:51 +06:00
|
|
|
|
2014-06-15 14:23:23 +10:00
|
|
|
bevp = bl->bevpoints;
|
2014-08-18 17:35:51 +06:00
|
|
|
seglen = bl->seglen;
|
|
|
|
segbevcount = bl->segbevcount;
|
|
|
|
|
|
|
|
bevp->offset = 0;
|
|
|
|
if (seglen != NULL) {
|
|
|
|
*seglen = 0;
|
|
|
|
*segbevcount = 0;
|
|
|
|
}
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
a = nu->pntsu - 1;
|
|
|
|
bezt = nu->bezt;
|
2012-03-24 06:18:31 +00:00
|
|
|
if (nu->flagu & CU_NURB_CYCLIC) {
|
2002-10-12 11:37:38 +00:00
|
|
|
a++;
|
2012-05-06 15:15:33 +00:00
|
|
|
prevbezt = nu->bezt + (nu->pntsu - 1);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-05-06 15:15:33 +00:00
|
|
|
prevbezt = bezt;
|
2002-10-12 11:37:38 +00:00
|
|
|
bezt++;
|
|
|
|
}
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2013-08-07 18:22:15 +00:00
|
|
|
sub_v3_v3v3(bevp->dir, prevbezt->vec[2], prevbezt->vec[1]);
|
|
|
|
normalize_v3(bevp->dir);
|
|
|
|
|
2014-08-18 17:35:51 +06:00
|
|
|
BLI_assert(segcount >= a);
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
while (a--) {
|
2012-05-06 15:15:33 +00:00
|
|
|
if (prevbezt->h2 == HD_VECT && bezt->h1 == HD_VECT) {
|
2009-09-10 02:57:25 +00:00
|
|
|
|
2011-10-28 12:40:15 +00:00
|
|
|
copy_v3_v3(bevp->vec, prevbezt->vec[1]);
|
2012-05-06 15:15:33 +00:00
|
|
|
bevp->alfa = prevbezt->alfa;
|
|
|
|
bevp->radius = prevbezt->radius;
|
|
|
|
bevp->weight = prevbezt->weight;
|
2014-04-01 11:34:00 +11:00
|
|
|
bevp->split_tag = true;
|
|
|
|
bevp->dupe_tag = false;
|
2002-10-12 11:37:38 +00:00
|
|
|
bevp++;
|
|
|
|
bl->nr++;
|
2012-05-06 15:15:33 +00:00
|
|
|
bl->dupe_nr = 1;
|
2014-08-18 17:35:51 +06:00
|
|
|
if (seglen != NULL) {
|
|
|
|
*seglen = len_v3v3(prevbezt->vec[1], bezt->vec[1]);
|
|
|
|
bevp->offset = *seglen;
|
|
|
|
seglen++;
|
|
|
|
/* match segbevcount to the cleaned up bevel lists (see STEP 2) */
|
|
|
|
if (bevp->offset > treshold) *segbevcount = 1;
|
|
|
|
segbevcount++;
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
else {
|
2003-04-25 15:48:11 +00:00
|
|
|
/* always do all three, to prevent data hanging around */
|
2009-09-10 02:57:25 +00:00
|
|
|
int j;
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2009-09-10 02:57:25 +00:00
|
|
|
/* BevPoint must stay aligned to 4 so sizeof(BevPoint)/sizeof(float) works */
|
2012-05-06 15:15:33 +00:00
|
|
|
for (j = 0; j < 3; j++) {
|
2012-04-29 17:11:40 +00:00
|
|
|
BKE_curve_forward_diff_bezier(prevbezt->vec[1][j], prevbezt->vec[2][j],
|
|
|
|
bezt->vec[0][j], bezt->vec[1][j],
|
|
|
|
&(bevp->vec[j]), resolu, sizeof(BevPoint));
|
2009-09-10 02:57:25 +00:00
|
|
|
}
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2009-09-10 02:57:25 +00:00
|
|
|
/* if both arrays are NULL do nothiong */
|
2012-04-29 17:11:40 +00:00
|
|
|
alfa_bezpart(prevbezt, bezt, nu,
|
2012-05-06 15:15:33 +00:00
|
|
|
do_tilt ? &bevp->alfa : NULL,
|
|
|
|
do_radius ? &bevp->radius : NULL,
|
|
|
|
do_weight ? &bevp->weight : NULL,
|
2012-04-29 17:11:40 +00:00
|
|
|
resolu, sizeof(BevPoint));
|
2009-09-11 15:35:30 +00:00
|
|
|
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
if (cu->twist_mode == CU_TWIST_TANGENT) {
|
2012-04-29 17:11:40 +00:00
|
|
|
forward_diff_bezier_cotangent(prevbezt->vec[1], prevbezt->vec[2],
|
|
|
|
bezt->vec[0], bezt->vec[1],
|
|
|
|
bevp->tan, resolu, sizeof(BevPoint));
|
2009-09-11 15:35:30 +00:00
|
|
|
}
|
|
|
|
|
2003-04-25 15:48:11 +00:00
|
|
|
/* indicate with handlecodes double points */
|
2012-05-06 15:15:33 +00:00
|
|
|
if (prevbezt->h1 == prevbezt->h2) {
|
2012-05-07 08:53:59 +00:00
|
|
|
if (prevbezt->h1 == 0 || prevbezt->h1 == HD_VECT)
|
2014-04-01 11:34:00 +11:00
|
|
|
bevp->split_tag = true;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-05-07 08:53:59 +00:00
|
|
|
if (prevbezt->h1 == 0 || prevbezt->h1 == HD_VECT)
|
2014-04-01 11:34:00 +11:00
|
|
|
bevp->split_tag = true;
|
2012-05-07 08:53:59 +00:00
|
|
|
else if (prevbezt->h2 == 0 || prevbezt->h2 == HD_VECT)
|
2014-04-01 11:34:00 +11:00
|
|
|
bevp->split_tag = true;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2014-08-18 17:35:51 +06:00
|
|
|
|
|
|
|
/* seglen */
|
|
|
|
if (seglen != NULL) {
|
|
|
|
*seglen = 0;
|
|
|
|
*segbevcount = 0;
|
|
|
|
for (j = 0; j < resolu; j++) {
|
|
|
|
bevp0 = bevp;
|
|
|
|
bevp++;
|
|
|
|
bevp->offset = len_v3v3(bevp0->vec, bevp->vec);
|
|
|
|
/* match seglen and segbevcount to the cleaned up bevel lists (see STEP 2) */
|
|
|
|
if (bevp->offset > treshold) {
|
|
|
|
*seglen += bevp->offset;
|
|
|
|
*segbevcount += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
seglen++;
|
|
|
|
segbevcount++;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
bevp += resolu;
|
|
|
|
}
|
2012-05-06 15:15:33 +00:00
|
|
|
bl->nr += resolu;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2012-05-06 15:15:33 +00:00
|
|
|
prevbezt = bezt;
|
2002-10-12 11:37:38 +00:00
|
|
|
bezt++;
|
|
|
|
}
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
if ((nu->flagu & CU_NURB_CYCLIC) == 0) { /* not cyclic: endpoint */
|
2011-10-28 12:40:15 +00:00
|
|
|
copy_v3_v3(bevp->vec, prevbezt->vec[1]);
|
2012-05-06 15:15:33 +00:00
|
|
|
bevp->alfa = prevbezt->alfa;
|
|
|
|
bevp->radius = prevbezt->radius;
|
|
|
|
bevp->weight = prevbezt->weight;
|
2013-08-07 18:22:15 +00:00
|
|
|
|
|
|
|
sub_v3_v3v3(bevp->dir, prevbezt->vec[1], prevbezt->vec[0]);
|
|
|
|
normalize_v3(bevp->dir);
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
bl->nr++;
|
|
|
|
}
|
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
else if (nu->type == CU_NURBS) {
|
2012-05-06 15:15:33 +00:00
|
|
|
if (nu->pntsv == 1) {
|
2014-08-18 17:35:51 +06:00
|
|
|
len = (resolu * segcount);
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2018-01-15 06:57:26 +01:00
|
|
|
bl = MEM_callocN(sizeof(BevList), "makeBevelList3");
|
|
|
|
bl->bevpoints = MEM_calloc_arrayN(len, sizeof(BevPoint), "makeBevelPoints3");
|
2014-09-30 15:57:06 +06:00
|
|
|
if (need_seglen && (nu->flagu & CU_NURB_CYCLIC) == 0) {
|
2018-01-14 22:14:20 +01:00
|
|
|
bl->seglen = MEM_malloc_arrayN(segcount, sizeof(float), "makeBevelList3_seglen");
|
|
|
|
bl->segbevcount = MEM_malloc_arrayN(segcount, sizeof(int), "makeBevelList3_segbevcount");
|
2014-08-18 17:35:51 +06:00
|
|
|
}
|
2013-08-19 09:25:24 +00:00
|
|
|
BLI_addtail(bev, bl);
|
2012-05-06 15:15:33 +00:00
|
|
|
bl->nr = len;
|
|
|
|
bl->dupe_nr = 0;
|
2013-07-17 14:05:50 +00:00
|
|
|
bl->poly = (nu->flagu & CU_NURB_CYCLIC) ? 0 : -1;
|
|
|
|
bl->charidx = nu->charidx;
|
2014-08-18 17:35:51 +06:00
|
|
|
|
2014-06-15 14:23:23 +10:00
|
|
|
bevp = bl->bevpoints;
|
2014-08-18 17:35:51 +06:00
|
|
|
seglen = bl->seglen;
|
|
|
|
segbevcount = bl->segbevcount;
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2012-04-29 17:11:40 +00:00
|
|
|
BKE_nurb_makeCurve(nu, &bevp->vec[0],
|
|
|
|
do_tilt ? &bevp->alfa : NULL,
|
|
|
|
do_radius ? &bevp->radius : NULL,
|
|
|
|
do_weight ? &bevp->weight : NULL,
|
|
|
|
resolu, sizeof(BevPoint));
|
2013-08-12 09:00:48 +00:00
|
|
|
|
2014-08-18 17:35:51 +06:00
|
|
|
/* match seglen and segbevcount to the cleaned up bevel lists (see STEP 2) */
|
|
|
|
if (seglen != NULL) {
|
|
|
|
nr = segcount;
|
|
|
|
bevp0 = bevp;
|
|
|
|
bevp++;
|
|
|
|
while (nr) {
|
|
|
|
int j;
|
|
|
|
*seglen = 0;
|
|
|
|
*segbevcount = 0;
|
|
|
|
/* We keep last bevel segment zero-length. */
|
|
|
|
for (j = 0; j < ((nr == 1) ? (resolu - 1) : resolu); j++) {
|
|
|
|
bevp->offset = len_v3v3(bevp0->vec, bevp->vec);
|
|
|
|
if (bevp->offset > treshold) {
|
|
|
|
*seglen += bevp->offset;
|
|
|
|
*segbevcount += 1;
|
|
|
|
}
|
|
|
|
bevp0 = bevp;
|
|
|
|
bevp++;
|
|
|
|
}
|
|
|
|
seglen++;
|
|
|
|
segbevcount++;
|
|
|
|
nr--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-12 09:00:48 +00:00
|
|
|
if ((nu->flagu & CU_NURB_CYCLIC) == 0) {
|
|
|
|
bevlist_firstlast_direction_calc_from_bpoint(nu, bl);
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-04-25 15:48:11 +00:00
|
|
|
/* STEP 2: DOUBLE POINTS AND AUTOMATIC RESOLUTION, REDUCE DATABLOCKS */
|
2013-08-19 09:25:24 +00:00
|
|
|
bl = bev->first;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (bl) {
|
2007-12-03 22:42:48 +00:00
|
|
|
if (bl->nr) { /* null bevel items come from single points */
|
2013-09-17 11:00:09 +00:00
|
|
|
bool is_cyclic = bl->poly != -1;
|
2012-05-06 15:15:33 +00:00
|
|
|
nr = bl->nr;
|
2013-09-17 11:00:09 +00:00
|
|
|
if (is_cyclic) {
|
2014-06-15 14:23:23 +10:00
|
|
|
bevp1 = bl->bevpoints;
|
2013-09-17 11:00:09 +00:00
|
|
|
bevp0 = bevp1 + (nr - 1);
|
|
|
|
}
|
|
|
|
else {
|
2014-06-15 14:23:23 +10:00
|
|
|
bevp0 = bl->bevpoints;
|
2014-08-18 17:35:51 +06:00
|
|
|
bevp0->offset = 0;
|
2013-09-17 11:00:09 +00:00
|
|
|
bevp1 = bevp0 + 1;
|
|
|
|
}
|
2007-12-03 22:42:48 +00:00
|
|
|
nr--;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (nr--) {
|
2014-08-18 17:35:51 +06:00
|
|
|
if (seglen != NULL) {
|
|
|
|
if (fabsf(bevp1->offset) < treshold) {
|
|
|
|
bevp0->dupe_tag = true;
|
|
|
|
bl->dupe_nr++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (fabsf(bevp0->vec[0] - bevp1->vec[0]) < 0.00001f) {
|
|
|
|
if (fabsf(bevp0->vec[1] - bevp1->vec[1]) < 0.00001f) {
|
|
|
|
if (fabsf(bevp0->vec[2] - bevp1->vec[2]) < 0.00001f) {
|
|
|
|
bevp0->dupe_tag = true;
|
|
|
|
bl->dupe_nr++;
|
|
|
|
}
|
2007-12-03 22:42:48 +00:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
2012-05-06 15:15:33 +00:00
|
|
|
bevp0 = bevp1;
|
2007-12-03 22:42:48 +00:00
|
|
|
bevp1++;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
2012-05-06 15:15:33 +00:00
|
|
|
bl = bl->next;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2013-08-19 09:25:24 +00:00
|
|
|
bl = bev->first;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (bl) {
|
2012-05-06 15:15:33 +00:00
|
|
|
blnext = bl->next;
|
2012-03-24 06:18:31 +00:00
|
|
|
if (bl->nr && bl->dupe_nr) {
|
2012-05-06 15:15:33 +00:00
|
|
|
nr = bl->nr - bl->dupe_nr + 1; /* +1 because vectorbezier sets flag too */
|
2018-01-15 06:57:26 +01:00
|
|
|
blnew = MEM_callocN(sizeof(BevList), "makeBevelList4");
|
2002-10-12 11:37:38 +00:00
|
|
|
memcpy(blnew, bl, sizeof(BevList));
|
2018-01-15 06:57:26 +01:00
|
|
|
blnew->bevpoints = MEM_calloc_arrayN(nr, sizeof(BevPoint), "makeBevelPoints4");
|
|
|
|
if (!blnew->bevpoints) {
|
|
|
|
MEM_freeN(blnew);
|
|
|
|
break;
|
|
|
|
}
|
2014-08-18 17:35:51 +06:00
|
|
|
blnew->segbevcount = bl->segbevcount;
|
|
|
|
blnew->seglen = bl->seglen;
|
2012-05-06 15:15:33 +00:00
|
|
|
blnew->nr = 0;
|
2013-08-19 09:25:24 +00:00
|
|
|
BLI_remlink(bev, bl);
|
|
|
|
BLI_insertlinkbefore(bev, blnext, blnew); /* to make sure bevlijst is tuned with nurblist */
|
2014-06-15 14:23:23 +10:00
|
|
|
bevp0 = bl->bevpoints;
|
|
|
|
bevp1 = blnew->bevpoints;
|
2012-05-06 15:15:33 +00:00
|
|
|
nr = bl->nr;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (nr--) {
|
2012-05-06 15:15:33 +00:00
|
|
|
if (bevp0->dupe_tag == 0) {
|
2002-10-12 11:37:38 +00:00
|
|
|
memcpy(bevp1, bevp0, sizeof(BevPoint));
|
|
|
|
bevp1++;
|
|
|
|
blnew->nr++;
|
|
|
|
}
|
|
|
|
bevp0++;
|
|
|
|
}
|
2018-01-15 06:57:26 +01:00
|
|
|
if (bl->bevpoints != NULL) {
|
|
|
|
MEM_freeN(bl->bevpoints);
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
MEM_freeN(bl);
|
2012-05-06 15:15:33 +00:00
|
|
|
blnew->dupe_nr = 0;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2012-05-06 15:15:33 +00:00
|
|
|
bl = blnext;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2009-09-07 08:37:28 +00:00
|
|
|
/* STEP 3: POLYS COUNT AND AUTOHOLE */
|
2013-08-19 09:25:24 +00:00
|
|
|
bl = bev->first;
|
2012-05-06 15:15:33 +00:00
|
|
|
poly = 0;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (bl) {
|
2012-05-06 15:15:33 +00:00
|
|
|
if (bl->nr && bl->poly >= 0) {
|
2002-10-12 11:37:38 +00:00
|
|
|
poly++;
|
2012-05-06 15:15:33 +00:00
|
|
|
bl->poly = poly;
|
|
|
|
bl->hole = 0;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2012-05-06 15:15:33 +00:00
|
|
|
bl = bl->next;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2003-04-25 15:48:11 +00:00
|
|
|
/* find extreme left points, also test (turning) direction */
|
2012-05-06 15:15:33 +00:00
|
|
|
if (poly > 0) {
|
2018-01-14 22:14:20 +01:00
|
|
|
sd = sortdata = MEM_malloc_arrayN(poly, sizeof(struct BevelSort), "makeBevelList5");
|
2013-08-19 09:25:24 +00:00
|
|
|
bl = bev->first;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (bl) {
|
2012-05-06 15:15:33 +00:00
|
|
|
if (bl->poly > 0) {
|
2015-11-23 11:27:02 +11:00
|
|
|
BevPoint *bevp;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
min = 300000.0;
|
2014-06-15 14:23:23 +10:00
|
|
|
bevp = bl->bevpoints;
|
2012-05-06 15:15:33 +00:00
|
|
|
nr = bl->nr;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (nr--) {
|
2012-05-06 15:15:33 +00:00
|
|
|
if (min > bevp->vec[0]) {
|
|
|
|
min = bevp->vec[0];
|
|
|
|
bevp1 = bevp;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
bevp++;
|
|
|
|
}
|
2012-05-06 15:15:33 +00:00
|
|
|
sd->bl = bl;
|
|
|
|
sd->left = min;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2014-06-15 14:23:23 +10:00
|
|
|
bevp = bl->bevpoints;
|
2012-05-07 08:53:59 +00:00
|
|
|
if (bevp1 == bevp)
|
|
|
|
bevp0 = bevp + (bl->nr - 1);
|
|
|
|
else
|
|
|
|
bevp0 = bevp1 - 1;
|
2012-05-06 15:15:33 +00:00
|
|
|
bevp = bevp + (bl->nr - 1);
|
2012-05-07 08:53:59 +00:00
|
|
|
if (bevp1 == bevp)
|
2014-06-15 14:23:23 +10:00
|
|
|
bevp2 = bl->bevpoints;
|
2012-05-07 08:53:59 +00:00
|
|
|
else
|
|
|
|
bevp2 = bevp1 + 1;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-11-09 09:33:28 +00:00
|
|
|
inp = ((bevp1->vec[0] - bevp0->vec[0]) * (bevp0->vec[1] - bevp2->vec[1]) +
|
|
|
|
(bevp0->vec[1] - bevp1->vec[1]) * (bevp0->vec[0] - bevp2->vec[0]));
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-07 08:53:59 +00:00
|
|
|
if (inp > 0.0f)
|
|
|
|
sd->dir = 1;
|
|
|
|
else
|
|
|
|
sd->dir = 0;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
sd++;
|
|
|
|
}
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
bl = bl->next;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2013-09-05 21:45:05 +00:00
|
|
|
qsort(sortdata, poly, sizeof(struct BevelSort), vergxcobev);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
sd = sortdata + 1;
|
|
|
|
for (a = 1; a < poly; a++, sd++) {
|
|
|
|
bl = sd->bl; /* is bl a hole? */
|
|
|
|
sd1 = sortdata + (a - 1);
|
|
|
|
for (b = a - 1; b >= 0; b--, sd1--) { /* all polys to the left */
|
2013-07-17 14:05:50 +00:00
|
|
|
if (sd1->bl->charidx == bl->charidx) { /* for text, only check matching char */
|
|
|
|
if (bevelinside(sd1->bl, bl)) {
|
|
|
|
bl->hole = 1 - sd1->bl->hole;
|
|
|
|
break;
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-04-25 15:48:11 +00:00
|
|
|
/* turning direction */
|
2012-05-06 15:15:33 +00:00
|
|
|
if ((cu->flag & CU_3D) == 0) {
|
|
|
|
sd = sortdata;
|
|
|
|
for (a = 0; a < poly; a++, sd++) {
|
|
|
|
if (sd->bl->hole == sd->dir) {
|
|
|
|
bl = sd->bl;
|
2014-06-15 14:23:23 +10:00
|
|
|
bevp1 = bl->bevpoints;
|
2012-05-06 15:15:33 +00:00
|
|
|
bevp2 = bevp1 + (bl->nr - 1);
|
|
|
|
nr = bl->nr / 2;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (nr--) {
|
2002-10-12 11:37:38 +00:00
|
|
|
SWAP(BevPoint, *bevp1, *bevp2);
|
|
|
|
bevp1++;
|
|
|
|
bevp2--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
MEM_freeN(sortdata);
|
|
|
|
}
|
|
|
|
|
2009-09-11 15:35:30 +00:00
|
|
|
/* STEP 4: 2D-COSINES or 3D ORIENTATION */
|
2012-05-06 15:15:33 +00:00
|
|
|
if ((cu->flag & CU_3D) == 0) {
|
2013-02-21 17:16:51 +00:00
|
|
|
/* 2D Curves */
|
2013-08-19 09:25:24 +00:00
|
|
|
for (bl = bev->first; bl; bl = bl->next) {
|
2012-03-24 06:18:31 +00:00
|
|
|
if (bl->nr < 2) {
|
2014-06-15 14:23:23 +10:00
|
|
|
BevPoint *bevp = bl->bevpoints;
|
2014-04-11 17:40:07 +06:00
|
|
|
unit_qt(bevp->quat);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2012-05-06 15:15:33 +00:00
|
|
|
else if (bl->nr == 2) { /* 2 pnt, treat separate */
|
2013-02-21 17:16:51 +00:00
|
|
|
make_bevel_list_segment_2D(bl);
|
2009-09-11 15:35:30 +00:00
|
|
|
}
|
|
|
|
else {
|
2013-02-21 17:16:51 +00:00
|
|
|
make_bevel_list_2D(bl);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2009-09-11 15:35:30 +00:00
|
|
|
}
|
|
|
|
}
|
2013-02-21 17:16:51 +00:00
|
|
|
else {
|
|
|
|
/* 3D Curves */
|
2013-08-19 09:25:24 +00:00
|
|
|
for (bl = bev->first; bl; bl = bl->next) {
|
2012-03-24 06:18:31 +00:00
|
|
|
if (bl->nr < 2) {
|
2014-06-15 14:23:23 +10:00
|
|
|
BevPoint *bevp = bl->bevpoints;
|
2014-04-11 17:40:07 +06:00
|
|
|
unit_qt(bevp->quat);
|
2009-09-11 15:35:30 +00:00
|
|
|
}
|
2012-05-06 15:15:33 +00:00
|
|
|
else if (bl->nr == 2) { /* 2 pnt, treat separate */
|
2009-11-21 14:35:28 +00:00
|
|
|
make_bevel_list_segment_3D(bl);
|
2009-09-11 15:35:30 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-05-06 15:15:33 +00:00
|
|
|
make_bevel_list_3D(bl, (int)(resolu * cu->twist_smooth), cu->twist_mode);
|
2009-09-11 15:35:30 +00:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ****************** HANDLES ************** */
|
|
|
|
|
2016-02-25 11:02:46 +11:00
|
|
|
static void calchandleNurb_intern(
|
|
|
|
BezTriple *bezt, const BezTriple *prev, const BezTriple *next,
|
2017-11-01 21:34:30 +03:00
|
|
|
bool is_fcurve, bool skip_align, char fcurve_smoothing)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2014-02-27 17:03:35 +11:00
|
|
|
/* defines to avoid confusion */
|
2015-08-02 13:54:06 +10:00
|
|
|
#define p2_h1 ((p2) - 3)
|
|
|
|
#define p2_h2 ((p2) + 3)
|
2014-02-27 17:03:35 +11:00
|
|
|
|
2016-02-25 11:02:46 +11:00
|
|
|
const float *p1, *p3;
|
|
|
|
float *p2;
|
|
|
|
float pt[3];
|
2011-09-29 06:15:33 +00:00
|
|
|
float dvec_a[3], dvec_b[3];
|
|
|
|
float len, len_a, len_b;
|
2014-05-03 21:58:02 +02:00
|
|
|
float len_ratio;
|
2012-05-06 15:15:33 +00:00
|
|
|
const float eps = 1e-5;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2017-11-01 21:34:30 +03:00
|
|
|
/* assume normal handle until we check */
|
|
|
|
bezt->f5 = HD_AUTOTYPE_NORMAL;
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
if (bezt->h1 == 0 && bezt->h2 == 0) {
|
2011-09-29 06:15:33 +00:00
|
|
|
return;
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
p2 = bezt->vec[1];
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
if (prev == NULL) {
|
|
|
|
p3 = next->vec[1];
|
|
|
|
pt[0] = 2.0f * p2[0] - p3[0];
|
|
|
|
pt[1] = 2.0f * p2[1] - p3[1];
|
|
|
|
pt[2] = 2.0f * p2[2] - p3[2];
|
|
|
|
p1 = pt;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2011-09-29 06:15:33 +00:00
|
|
|
else {
|
2012-05-06 15:15:33 +00:00
|
|
|
p1 = prev->vec[1];
|
2011-09-29 06:15:33 +00:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
if (next == NULL) {
|
|
|
|
pt[0] = 2.0f * p2[0] - p1[0];
|
|
|
|
pt[1] = 2.0f * p2[1] - p1[1];
|
|
|
|
pt[2] = 2.0f * p2[2] - p1[2];
|
|
|
|
p3 = pt;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2011-09-29 06:15:33 +00:00
|
|
|
else {
|
2012-05-06 15:15:33 +00:00
|
|
|
p3 = next->vec[1];
|
2011-09-29 06:15:33 +00:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2011-09-29 06:15:33 +00:00
|
|
|
sub_v3_v3v3(dvec_a, p2, p1);
|
|
|
|
sub_v3_v3v3(dvec_b, p3, p2);
|
|
|
|
|
2014-03-01 12:57:15 +11:00
|
|
|
if (is_fcurve) {
|
2012-05-06 15:15:33 +00:00
|
|
|
len_a = dvec_a[0];
|
|
|
|
len_b = dvec_b[0];
|
2011-09-29 06:15:33 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-05-06 15:15:33 +00:00
|
|
|
len_a = len_v3(dvec_a);
|
|
|
|
len_b = len_v3(dvec_b);
|
2011-09-29 06:15:33 +00:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
if (len_a == 0.0f) len_a = 1.0f;
|
|
|
|
if (len_b == 0.0f) len_b = 1.0f;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2014-05-03 21:58:02 +02:00
|
|
|
len_ratio = len_a / len_b;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-04-29 15:47:02 +00:00
|
|
|
if (ELEM(bezt->h1, HD_AUTO, HD_AUTO_ANIM) || ELEM(bezt->h2, HD_AUTO, HD_AUTO_ANIM)) { /* auto */
|
2011-09-29 06:15:33 +00:00
|
|
|
float tvec[3];
|
2012-05-06 15:15:33 +00:00
|
|
|
tvec[0] = dvec_b[0] / len_b + dvec_a[0] / len_a;
|
|
|
|
tvec[1] = dvec_b[1] / len_b + dvec_a[1] / len_a;
|
|
|
|
tvec[2] = dvec_b[2] / len_b + dvec_a[2] / len_a;
|
2014-03-01 12:57:15 +11:00
|
|
|
|
|
|
|
if (is_fcurve) {
|
2017-11-01 21:34:30 +03:00
|
|
|
if (fcurve_smoothing != FCURVE_SMOOTH_NONE) {
|
|
|
|
/* force the horizontal handle size to be 1/3 of the key interval so that
|
|
|
|
* the X component of the parametric bezier curve is a linear spline */
|
2017-11-02 15:09:11 +11:00
|
|
|
len = 6.0f / 2.5614f;
|
2017-11-01 21:34:30 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
len = tvec[0];
|
|
|
|
}
|
2014-02-28 12:09:17 +11:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
len = len_v3(tvec);
|
|
|
|
}
|
|
|
|
len *= 2.5614f;
|
2011-09-29 06:15:33 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
if (len != 0.0f) {
|
2014-03-01 12:57:15 +11:00
|
|
|
/* only for fcurves */
|
|
|
|
bool leftviolate = false, rightviolate = false;
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2017-11-01 21:34:30 +03:00
|
|
|
if (!is_fcurve || fcurve_smoothing == FCURVE_SMOOTH_NONE) {
|
|
|
|
if (len_a > 5.0f * len_b)
|
|
|
|
len_a = 5.0f * len_b;
|
|
|
|
if (len_b > 5.0f * len_a)
|
|
|
|
len_b = 5.0f * len_a;
|
|
|
|
}
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2012-04-29 15:47:02 +00:00
|
|
|
if (ELEM(bezt->h1, HD_AUTO, HD_AUTO_ANIM)) {
|
2012-05-06 15:15:33 +00:00
|
|
|
len_a /= len;
|
2014-02-27 17:03:35 +11:00
|
|
|
madd_v3_v3v3fl(p2_h1, p2, tvec, -len_a);
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
if ((bezt->h1 == HD_AUTO_ANIM) && next && prev) { /* keep horizontal if extrema */
|
|
|
|
float ydiff1 = prev->vec[1][1] - bezt->vec[1][1];
|
|
|
|
float ydiff2 = next->vec[1][1] - bezt->vec[1][1];
|
2012-05-07 08:53:59 +00:00
|
|
|
if ((ydiff1 <= 0.0f && ydiff2 <= 0.0f) || (ydiff1 >= 0.0f && ydiff2 >= 0.0f)) {
|
2012-05-06 15:15:33 +00:00
|
|
|
bezt->vec[0][1] = bezt->vec[1][1];
|
2017-11-01 21:34:30 +03:00
|
|
|
bezt->f5 = HD_AUTOTYPE_SPECIAL;
|
2005-07-10 12:50:14 +00:00
|
|
|
}
|
2011-09-29 06:15:33 +00:00
|
|
|
else { /* handles should not be beyond y coord of two others */
|
2012-03-24 06:18:31 +00:00
|
|
|
if (ydiff1 <= 0.0f) {
|
|
|
|
if (prev->vec[1][1] > bezt->vec[0][1]) {
|
2012-05-06 15:15:33 +00:00
|
|
|
bezt->vec[0][1] = prev->vec[1][1];
|
|
|
|
leftviolate = 1;
|
2005-10-23 21:36:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2012-03-24 06:18:31 +00:00
|
|
|
if (prev->vec[1][1] < bezt->vec[0][1]) {
|
2012-05-06 15:15:33 +00:00
|
|
|
bezt->vec[0][1] = prev->vec[1][1];
|
|
|
|
leftviolate = 1;
|
2005-10-23 21:36:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-07-10 12:50:14 +00:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2012-04-29 15:47:02 +00:00
|
|
|
if (ELEM(bezt->h2, HD_AUTO, HD_AUTO_ANIM)) {
|
2012-05-06 15:15:33 +00:00
|
|
|
len_b /= len;
|
2014-02-27 17:03:35 +11:00
|
|
|
madd_v3_v3v3fl(p2_h2, p2, tvec, len_b);
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
if ((bezt->h2 == HD_AUTO_ANIM) && next && prev) { /* keep horizontal if extrema */
|
|
|
|
float ydiff1 = prev->vec[1][1] - bezt->vec[1][1];
|
|
|
|
float ydiff2 = next->vec[1][1] - bezt->vec[1][1];
|
2017-11-02 15:09:11 +11:00
|
|
|
if ((ydiff1 <= 0.0f && ydiff2 <= 0.0f) || (ydiff1 >= 0.0f && ydiff2 >= 0.0f)) {
|
2012-05-06 15:15:33 +00:00
|
|
|
bezt->vec[2][1] = bezt->vec[1][1];
|
2017-11-01 21:34:30 +03:00
|
|
|
bezt->f5 = HD_AUTOTYPE_SPECIAL;
|
2005-07-10 12:50:14 +00:00
|
|
|
}
|
2014-04-28 16:44:06 +12:00
|
|
|
else { /* handles should not be beyond y coord of two others */
|
2012-03-24 06:18:31 +00:00
|
|
|
if (ydiff1 <= 0.0f) {
|
|
|
|
if (next->vec[1][1] < bezt->vec[2][1]) {
|
2012-05-06 15:15:33 +00:00
|
|
|
bezt->vec[2][1] = next->vec[1][1];
|
|
|
|
rightviolate = 1;
|
2005-10-23 21:36:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2012-03-24 06:18:31 +00:00
|
|
|
if (next->vec[1][1] > bezt->vec[2][1]) {
|
2012-05-06 15:15:33 +00:00
|
|
|
bezt->vec[2][1] = next->vec[1][1];
|
|
|
|
rightviolate = 1;
|
2005-10-23 21:36:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
if (leftviolate || rightviolate) { /* align left handle */
|
2014-03-01 12:57:15 +11:00
|
|
|
BLI_assert(is_fcurve);
|
2018-10-17 12:43:41 +02:00
|
|
|
/* simple 2d calculation */
|
|
|
|
float h1_x = p2_h1[0] - p2[0];
|
|
|
|
float h2_x = p2[0] - p2_h2[0];
|
|
|
|
|
|
|
|
if (leftviolate) {
|
|
|
|
p2_h2[1] = p2[1] + ((p2[1] - p2_h1[1]) / h1_x) * h2_x;
|
2014-02-27 17:15:49 +11:00
|
|
|
}
|
|
|
|
else {
|
2018-10-17 12:43:41 +02:00
|
|
|
p2_h1[1] = p2[1] + ((p2[1] - p2_h2[1]) / h2_x) * h1_x;
|
2005-07-10 12:50:14 +00:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
if (bezt->h1 == HD_VECT) { /* vector */
|
2014-02-27 17:03:35 +11:00
|
|
|
madd_v3_v3v3fl(p2_h1, p2, dvec_a, -1.0f / 3.0f);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2012-05-06 15:15:33 +00:00
|
|
|
if (bezt->h2 == HD_VECT) {
|
2014-02-27 17:03:35 +11:00
|
|
|
madd_v3_v3v3fl(p2_h2, p2, dvec_b, 1.0f / 3.0f);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2014-09-04 15:40:29 +10:00
|
|
|
if (skip_align ||
|
|
|
|
/* when one handle is free, alignming makes no sense, see: T35952 */
|
|
|
|
(ELEM(HD_FREE, bezt->h1, bezt->h2)) ||
|
|
|
|
/* also when no handles are aligned, skip this step */
|
|
|
|
(!ELEM(HD_ALIGN, bezt->h1, bezt->h2) &&
|
|
|
|
!ELEM(HD_ALIGN_DOUBLESIDE, bezt->h1, bezt->h2)))
|
|
|
|
{
|
2012-03-12 14:55:56 +00:00
|
|
|
/* handles need to be updated during animation and applying stuff like hooks,
|
2012-09-28 06:45:20 +00:00
|
|
|
* but in such situations it's quite difficult to distinguish in which order
|
2012-03-12 14:55:56 +00:00
|
|
|
* align handles should be aligned so skip them for now */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-05-27 21:28:42 +10:00
|
|
|
len_a = len_v3v3(p2, p2_h1);
|
|
|
|
len_b = len_v3v3(p2, p2_h2);
|
2014-05-14 13:10:45 +10:00
|
|
|
|
2014-05-27 21:28:42 +10:00
|
|
|
if (len_a == 0.0f) len_a = 1.0f;
|
|
|
|
if (len_b == 0.0f) len_b = 1.0f;
|
|
|
|
|
|
|
|
len_ratio = len_a / len_b;
|
2005-07-10 12:50:14 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (bezt->f1 & SELECT) { /* order of calculation */
|
2013-10-30 10:38:45 +01:00
|
|
|
if (ELEM(bezt->h2, HD_ALIGN, HD_ALIGN_DOUBLESIDE)) { /* aligned */
|
2012-05-06 15:15:33 +00:00
|
|
|
if (len_a > eps) {
|
2014-05-03 21:58:02 +02:00
|
|
|
len = 1.0f / len_ratio;
|
2014-02-27 17:03:35 +11:00
|
|
|
p2_h2[0] = p2[0] + len * (p2[0] - p2_h1[0]);
|
|
|
|
p2_h2[1] = p2[1] + len * (p2[1] - p2_h1[1]);
|
|
|
|
p2_h2[2] = p2[2] + len * (p2[2] - p2_h1[2]);
|
2011-07-09 14:22:52 +00:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2013-10-30 10:38:45 +01:00
|
|
|
if (ELEM(bezt->h1, HD_ALIGN, HD_ALIGN_DOUBLESIDE)) {
|
2012-05-06 15:15:33 +00:00
|
|
|
if (len_b > eps) {
|
2014-05-03 21:58:02 +02:00
|
|
|
len = len_ratio;
|
2014-02-27 17:03:35 +11:00
|
|
|
p2_h1[0] = p2[0] + len * (p2[0] - p2_h2[0]);
|
|
|
|
p2_h1[1] = p2[1] + len * (p2[1] - p2_h2[1]);
|
|
|
|
p2_h1[2] = p2[2] + len * (p2[2] - p2_h2[2]);
|
2011-07-09 14:22:52 +00:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2013-10-30 10:38:45 +01:00
|
|
|
if (ELEM(bezt->h1, HD_ALIGN, HD_ALIGN_DOUBLESIDE)) {
|
2012-05-06 15:15:33 +00:00
|
|
|
if (len_b > eps) {
|
2014-05-03 21:58:02 +02:00
|
|
|
len = len_ratio;
|
2014-02-27 17:03:35 +11:00
|
|
|
p2_h1[0] = p2[0] + len * (p2[0] - p2_h2[0]);
|
|
|
|
p2_h1[1] = p2[1] + len * (p2[1] - p2_h2[1]);
|
|
|
|
p2_h1[2] = p2[2] + len * (p2[2] - p2_h2[2]);
|
2011-07-09 14:22:52 +00:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2013-10-30 10:38:45 +01:00
|
|
|
if (ELEM(bezt->h2, HD_ALIGN, HD_ALIGN_DOUBLESIDE)) { /* aligned */
|
2012-05-06 15:15:33 +00:00
|
|
|
if (len_a > eps) {
|
2014-05-03 21:58:02 +02:00
|
|
|
len = 1.0f / len_ratio;
|
2014-02-27 17:03:35 +11:00
|
|
|
p2_h2[0] = p2[0] + len * (p2[0] - p2_h1[0]);
|
|
|
|
p2_h2[1] = p2[1] + len * (p2[1] - p2_h1[1]);
|
|
|
|
p2_h2[2] = p2[2] + len * (p2[2] - p2_h1[2]);
|
2011-07-09 14:22:52 +00:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
2014-02-27 17:03:35 +11:00
|
|
|
|
|
|
|
#undef p2_h1
|
|
|
|
#undef p2_h2
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2014-02-27 17:03:35 +11:00
|
|
|
static void calchandlesNurb_intern(Nurb *nu, bool skip_align)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
BezTriple *bezt, *prev, *next;
|
2014-01-19 00:18:53 +06:00
|
|
|
int a;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-07 08:53:59 +00:00
|
|
|
if (nu->type != CU_BEZIER)
|
|
|
|
return;
|
|
|
|
if (nu->pntsu < 2)
|
|
|
|
return;
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
a = nu->pntsu;
|
|
|
|
bezt = nu->bezt;
|
|
|
|
if (nu->flagu & CU_NURB_CYCLIC) prev = bezt + (a - 1);
|
|
|
|
else prev = NULL;
|
|
|
|
next = bezt + 1;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
while (a--) {
|
2017-11-01 21:34:30 +03:00
|
|
|
calchandleNurb_intern(bezt, prev, next, 0, skip_align, 0);
|
2012-05-06 15:15:33 +00:00
|
|
|
prev = bezt;
|
|
|
|
if (a == 1) {
|
2012-05-07 08:53:59 +00:00
|
|
|
if (nu->flagu & CU_NURB_CYCLIC)
|
|
|
|
next = nu->bezt;
|
|
|
|
else
|
|
|
|
next = NULL;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2012-05-07 08:53:59 +00:00
|
|
|
else
|
|
|
|
next++;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
bezt++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-01 21:34:30 +03:00
|
|
|
/* A utility function for allocating a number of arrays of the same length
|
|
|
|
* with easy error checking and deallocation, and an easy way to add or remove
|
|
|
|
* arrays that are processed in this way when changing code.
|
|
|
|
*
|
|
|
|
* floats, chars: NULL-terminated arrays of pointers to array pointers that need to be allocated.
|
|
|
|
*
|
|
|
|
* Returns: pointer to the buffer that contains all of the arrays.
|
|
|
|
*/
|
|
|
|
static void *allocate_arrays(int count, float ***floats, char ***chars, const char *name)
|
|
|
|
{
|
2018-01-15 06:57:26 +01:00
|
|
|
size_t num_floats = 0, num_chars = 0;
|
2017-11-01 21:34:30 +03:00
|
|
|
|
|
|
|
while (floats && floats[num_floats]) {
|
|
|
|
num_floats++;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (chars && chars[num_chars]) {
|
|
|
|
num_chars++;
|
|
|
|
}
|
|
|
|
|
2018-01-15 06:57:26 +01:00
|
|
|
void *buffer = (float *)MEM_malloc_arrayN(count, (sizeof(float) * num_floats + num_chars), name);
|
2017-11-01 21:34:30 +03:00
|
|
|
|
|
|
|
if (!buffer)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
float *fptr = buffer;
|
|
|
|
|
|
|
|
for (int i = 0; i < num_floats; i++, fptr += count) {
|
|
|
|
*floats[i] = fptr;
|
|
|
|
}
|
|
|
|
|
2017-11-02 15:09:11 +11:00
|
|
|
char *cptr = (char *)fptr;
|
2017-11-01 21:34:30 +03:00
|
|
|
|
|
|
|
for (int i = 0; i < num_chars; i++, cptr += count) {
|
|
|
|
*chars[i] = cptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void free_arrays(void *buffer)
|
|
|
|
{
|
|
|
|
MEM_freeN(buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* computes in which direction to change h[i] to satisfy conditions better */
|
|
|
|
static float bezier_relax_direction(float *a, float *b, float *c, float *d, float *h, int i, int count)
|
|
|
|
{
|
|
|
|
/* current deviation between sides of the equation */
|
2017-11-02 15:09:11 +11:00
|
|
|
float state = a[i] * h[(i + count - 1) % count] +
|
|
|
|
b[i] * h[i] +
|
|
|
|
c[i] * h[(i + 1) % count] -
|
|
|
|
d[i];
|
2017-11-01 21:34:30 +03:00
|
|
|
|
|
|
|
/* only the sign is meaningful */
|
|
|
|
return -state * b[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
static void bezier_lock_unknown(float *a, float *b, float *c, float *d, int i, float value)
|
|
|
|
{
|
|
|
|
a[i] = c[i] = 0.0f;
|
|
|
|
b[i] = 1.0f;
|
|
|
|
d[i] = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void bezier_restore_equation(float *a, float *b, float *c, float *d, float *a0, float *b0, float *c0, float *d0, int i)
|
|
|
|
{
|
|
|
|
a[i] = a0[i];
|
|
|
|
b[i] = b0[i];
|
|
|
|
c[i] = c0[i];
|
|
|
|
d[i] = d0[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool tridiagonal_solve_with_limits(float *a, float *b, float *c, float *d, float *h, float *hmin, float *hmax, int solve_count)
|
|
|
|
{
|
|
|
|
float *a0, *b0, *c0, *d0;
|
|
|
|
float **arrays[] = { &a0, &b0, &c0, &d0, NULL };
|
|
|
|
char *is_locked, *num_unlocks;
|
|
|
|
char **flagarrays[] = { &is_locked, &num_unlocks, NULL };
|
|
|
|
|
|
|
|
void *tmps = allocate_arrays(solve_count, arrays, flagarrays, "tridiagonal_solve_with_limits");
|
|
|
|
if (!tmps)
|
|
|
|
return false;
|
|
|
|
|
2017-11-02 15:09:11 +11:00
|
|
|
memcpy(a0, a, sizeof(float) * solve_count);
|
|
|
|
memcpy(b0, b, sizeof(float) * solve_count);
|
|
|
|
memcpy(c0, c, sizeof(float) * solve_count);
|
|
|
|
memcpy(d0, d, sizeof(float) * solve_count);
|
2017-11-01 21:34:30 +03:00
|
|
|
|
|
|
|
memset(is_locked, 0, solve_count);
|
|
|
|
memset(num_unlocks, 0, solve_count);
|
|
|
|
|
|
|
|
bool overshoot, unlocked;
|
|
|
|
|
2017-11-02 15:09:11 +11:00
|
|
|
do {
|
2017-11-01 21:34:30 +03:00
|
|
|
if (!BLI_tridiagonal_solve_cyclic(a, b, c, d, h, solve_count)) {
|
|
|
|
free_arrays(tmps);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* first check if any handles overshoot the limits, and lock them */
|
|
|
|
bool all = false, locked = false;
|
|
|
|
|
|
|
|
overshoot = unlocked = false;
|
|
|
|
|
2017-11-02 15:09:11 +11:00
|
|
|
do {
|
2017-11-01 21:34:30 +03:00
|
|
|
for (int i = 0; i < solve_count; i++) {
|
|
|
|
if (h[i] >= hmin[i] && h[i] <= hmax[i])
|
|
|
|
continue;
|
|
|
|
|
|
|
|
overshoot = true;
|
|
|
|
|
|
|
|
float target = h[i] > hmax[i] ? hmax[i] : hmin[i];
|
|
|
|
|
|
|
|
/* heuristically only lock handles that go in the right direction if there are such ones */
|
|
|
|
if (target != 0.0f || all) {
|
|
|
|
/* mark item locked */
|
|
|
|
is_locked[i] = 1;
|
|
|
|
|
|
|
|
bezier_lock_unknown(a, b, c, d, i, target);
|
|
|
|
locked = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
all = true;
|
2017-11-02 15:09:11 +11:00
|
|
|
} while (overshoot && !locked);
|
2017-11-01 21:34:30 +03:00
|
|
|
|
|
|
|
/* if no handles overshot and were locked, see if it may be a good idea to unlock some handles */
|
|
|
|
if (!locked) {
|
|
|
|
for (int i = 0; i < solve_count; i++) {
|
|
|
|
// to definitely avoid infinite loops limit this to 2 times
|
|
|
|
if (!is_locked[i] || num_unlocks[i] >= 2)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* if the handle wants to move in allowable direction, release it */
|
|
|
|
float relax = bezier_relax_direction(a0, b0, c0, d0, h, i, solve_count);
|
|
|
|
|
|
|
|
if ((relax > 0 && h[i] < hmax[i]) || (relax < 0 && h[i] > hmin[i])) {
|
|
|
|
bezier_restore_equation(a, b, c, d, a0, b0, c0, d0, i);
|
|
|
|
|
|
|
|
is_locked[i] = 0;
|
|
|
|
num_unlocks[i]++;
|
|
|
|
unlocked = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-11-02 15:09:11 +11:00
|
|
|
} while (overshoot || unlocked);
|
2017-11-01 21:34:30 +03:00
|
|
|
|
|
|
|
free_arrays(tmps);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This function computes the handles of a series of auto bezier points
|
|
|
|
* on the basis of 'no acceleration discontinuities' at the points.
|
|
|
|
* The first and last bezier points are considered 'fixed' (their handles are not touched)
|
2017-11-05 14:33:18 +11:00
|
|
|
* The result is the smoothest possible trajectory going through intermediate points.
|
|
|
|
* The difficulty is that the handles depends on their neighbors.
|
2017-11-01 21:34:30 +03:00
|
|
|
*
|
|
|
|
* The exact solution is found by solving a tridiagonal matrix equation formed
|
|
|
|
* by the continuity and boundary conditions. Although theoretically handle position
|
|
|
|
* is affected by all other points of the curve segment, in practice the influence
|
|
|
|
* decreases exponentially with distance.
|
|
|
|
*
|
|
|
|
* Note: this algorithm assumes that the handle horizontal size if always 1/3 of the
|
|
|
|
* of the interval to the next point. This rule ensures linear interpolation of time.
|
|
|
|
*
|
|
|
|
* ^ height (co 1)
|
|
|
|
* | yN
|
|
|
|
* | yN-1 |
|
|
|
|
* | y2 | |
|
|
|
|
* | y1 | | |
|
|
|
|
* | y0 | | | |
|
|
|
|
* | | | | | |
|
|
|
|
* | | | | | |
|
|
|
|
* | | | | | |
|
|
|
|
* |-------t1---------t2--------- ~ --------tN-------------------> time (co 0)
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Mathematical basis:
|
|
|
|
*
|
|
|
|
* 1. Handle lengths on either side of each point are connected by a factor
|
|
|
|
* ensuring continuity of the first derivative:
|
|
|
|
*
|
|
|
|
* l[i] = t[i+1]/t[i]
|
|
|
|
*
|
|
|
|
* 2. The tridiagonal system is formed by the following equation, which is derived
|
|
|
|
* by differentiating the bezier curve and specifies second derivative continuity
|
|
|
|
* at every point:
|
|
|
|
*
|
|
|
|
* l[i]^2 * h[i-1] + (2*l[i]+2) * h[i] + 1/l[i+1] * h[i+1] = (y[i]-y[i-1])*l[i]^2 + y[i+1]-y[i]
|
|
|
|
*
|
|
|
|
* 3. If this point is adjacent to a manually set handle with X size not equal to 1/3
|
|
|
|
* of the horizontal interval, this equation becomes slightly more complex:
|
|
|
|
*
|
|
|
|
* l[i]^2 * h[i-1] + (3*(1-R[i-1])*l[i] + 3*(1-L[i+1])) * h[i] + 1/l[i+1] * h[i+1] = (y[i]-y[i-1])*l[i]^2 + y[i+1]-y[i]
|
|
|
|
*
|
|
|
|
* The difference between equations amounts to this, and it's obvious that when R[i-1]
|
|
|
|
* and L[i+1] are both 1/3, it becomes zero:
|
|
|
|
*
|
|
|
|
* ( (1-3*R[i-1])*l[i] + (1-3*L[i+1]) ) * h[i]
|
|
|
|
*
|
|
|
|
* 4. The equations for zero acceleration border conditions are basically the above
|
|
|
|
* equation with parts omitted, so the handle size correction also applies.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
static void bezier_eq_continuous(float *a, float *b, float *c, float *d, float *dy, float *l, int i)
|
|
|
|
{
|
|
|
|
a[i] = l[i] * l[i];
|
|
|
|
b[i] = 2.0f * (l[i] + 1);
|
2017-11-02 15:09:11 +11:00
|
|
|
c[i] = 1.0f / l[i + 1];
|
|
|
|
d[i] = dy[i] * l[i] * l[i] + dy[i + 1];
|
2017-11-01 21:34:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void bezier_eq_noaccel_right(float *a, float *b, float *c, float *d, float *dy, float *l, int i)
|
|
|
|
{
|
|
|
|
a[i] = 0.0f;
|
|
|
|
b[i] = 2.0f;
|
2017-11-02 15:09:11 +11:00
|
|
|
c[i] = 1.0f / l[i + 1];
|
|
|
|
d[i] = dy[i + 1];
|
2017-11-01 21:34:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void bezier_eq_noaccel_left(float *a, float *b, float *c, float *d, float *dy, float *l, int i)
|
|
|
|
{
|
|
|
|
a[i] = l[i] * l[i];
|
|
|
|
b[i] = 2.0f * l[i];
|
|
|
|
c[i] = 0.0f;
|
|
|
|
d[i] = dy[i] * l[i] * l[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* auto clamp prevents its own point going the wrong way, and adjacent handles overshooting */
|
|
|
|
static void bezier_clamp(float *hmax, float *hmin, int i, float dy, bool no_reverse, bool no_overshoot)
|
|
|
|
{
|
|
|
|
if (dy > 0) {
|
|
|
|
if (no_overshoot)
|
|
|
|
hmax[i] = min_ff(hmax[i], dy);
|
|
|
|
if (no_reverse)
|
|
|
|
hmin[i] = 0.0f;
|
|
|
|
}
|
|
|
|
else if (dy < 0) {
|
|
|
|
if (no_reverse)
|
|
|
|
hmax[i] = 0.0f;
|
|
|
|
if (no_overshoot)
|
|
|
|
hmin[i] = max_ff(hmin[i], dy);
|
|
|
|
}
|
|
|
|
else if (no_reverse || no_overshoot) {
|
|
|
|
hmax[i] = hmin[i] = 0.0f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* write changes to a bezier handle */
|
|
|
|
static void bezier_output_handle_inner(BezTriple *bezt, bool right, float newval[3], bool endpoint)
|
|
|
|
{
|
|
|
|
float tmp[3];
|
|
|
|
|
|
|
|
int idx = right ? 2 : 0;
|
|
|
|
char hr = right ? bezt->h2 : bezt->h1;
|
|
|
|
char hm = right ? bezt->h1 : bezt->h2;
|
|
|
|
|
|
|
|
/* only assign Auto/Vector handles */
|
|
|
|
if (!ELEM(hr, HD_AUTO, HD_AUTO_ANIM, HD_VECT))
|
|
|
|
return;
|
|
|
|
|
|
|
|
copy_v3_v3(bezt->vec[idx], newval);
|
|
|
|
|
|
|
|
/* fix up the Align handle if any */
|
|
|
|
if (ELEM(hm, HD_ALIGN, HD_ALIGN_DOUBLESIDE)) {
|
2017-11-02 15:09:11 +11:00
|
|
|
float hlen = len_v3v3(bezt->vec[1], bezt->vec[2 - idx]);
|
2017-11-01 21:34:30 +03:00
|
|
|
float h2len = len_v3v3(bezt->vec[1], bezt->vec[idx]);
|
|
|
|
|
|
|
|
sub_v3_v3v3(tmp, bezt->vec[1], bezt->vec[idx]);
|
2017-11-02 15:09:11 +11:00
|
|
|
madd_v3_v3v3fl(bezt->vec[2 - idx], bezt->vec[1], tmp, hlen / h2len);
|
2017-11-01 21:34:30 +03:00
|
|
|
}
|
|
|
|
/* at end points of the curve, mirror handle to the other side */
|
|
|
|
else if (endpoint && ELEM(hm, HD_AUTO, HD_AUTO_ANIM, HD_VECT)) {
|
|
|
|
sub_v3_v3v3(tmp, bezt->vec[1], bezt->vec[idx]);
|
2017-11-02 15:09:11 +11:00
|
|
|
add_v3_v3v3(bezt->vec[2 - idx], bezt->vec[1], tmp);
|
2017-11-01 21:34:30 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void bezier_output_handle(BezTriple *bezt, bool right, float dy, bool endpoint)
|
|
|
|
{
|
|
|
|
float tmp[3];
|
|
|
|
|
|
|
|
copy_v3_v3(tmp, bezt->vec[right ? 2 : 0]);
|
|
|
|
|
|
|
|
tmp[1] = bezt->vec[1][1] + dy;
|
|
|
|
|
|
|
|
bezier_output_handle_inner(bezt, right, tmp, endpoint);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool bezier_check_solve_end_handle(BezTriple *bezt, char htype, bool end)
|
|
|
|
{
|
|
|
|
return (htype == HD_VECT) || (end && ELEM(htype, HD_AUTO, HD_AUTO_ANIM) && bezt->f5 == HD_AUTOTYPE_NORMAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static float bezier_calc_handle_adj(float hsize[2], float dx)
|
|
|
|
{
|
|
|
|
/* if handles intersect in x direction, they are scaled to fit */
|
2017-11-02 15:09:11 +11:00
|
|
|
float fac = dx / (hsize[0] + dx / 3.0f);
|
|
|
|
if (fac < 1.0f) {
|
2017-11-01 21:34:30 +03:00
|
|
|
mul_v2_fl(hsize, fac);
|
2017-11-02 15:09:11 +11:00
|
|
|
}
|
|
|
|
return 1.0f - 3.0f * hsize[0] / dx;
|
2017-11-01 21:34:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void bezier_handle_calc_smooth_fcurve(BezTriple *bezt, int total, int start, int count, bool cycle)
|
|
|
|
{
|
|
|
|
float *dx, *dy, *l, *a, *b, *c, *d, *h, *hmax, *hmin;
|
|
|
|
float **arrays[] = { &dx, &dy, &l, &a, &b, &c, &d, &h, &hmax, &hmin, NULL };
|
|
|
|
|
|
|
|
int solve_count = count;
|
|
|
|
|
|
|
|
/* verify index ranges */
|
|
|
|
|
|
|
|
if (count < 2)
|
|
|
|
return;
|
|
|
|
|
2017-11-02 15:09:11 +11:00
|
|
|
BLI_assert(start < total - 1 && count <= total);
|
2017-11-01 21:34:30 +03:00
|
|
|
BLI_assert(start + count <= total || cycle);
|
|
|
|
|
|
|
|
bool full_cycle = (start == 0 && count == total && cycle);
|
|
|
|
|
|
|
|
BezTriple *bezt_first = &bezt[start];
|
2017-11-02 15:09:11 +11:00
|
|
|
BezTriple *bezt_last = &bezt[(start + count > total) ? start + count - total : start + count - 1];
|
2017-11-01 21:34:30 +03:00
|
|
|
|
2017-11-02 15:09:11 +11:00
|
|
|
bool solve_first = bezier_check_solve_end_handle(bezt_first, bezt_first->h2, start == 0);
|
|
|
|
bool solve_last = bezier_check_solve_end_handle(bezt_last, bezt_last->h1, start + count == total);
|
2017-11-01 21:34:30 +03:00
|
|
|
|
2017-11-02 15:09:11 +11:00
|
|
|
if (count == 2 && !full_cycle && solve_first == solve_last) {
|
|
|
|
return;
|
|
|
|
}
|
2017-11-01 21:34:30 +03:00
|
|
|
|
|
|
|
/* allocate all */
|
|
|
|
|
|
|
|
void *tmp_buffer = allocate_arrays(count, arrays, NULL, "bezier_calc_smooth_tmp");
|
|
|
|
if (!tmp_buffer)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* point locations */
|
|
|
|
|
|
|
|
dx[0] = dy[0] = NAN_FLT;
|
|
|
|
|
2017-11-02 15:09:11 +11:00
|
|
|
for (int i = 1, j = start + 1; i < count; i++, j++) {
|
|
|
|
dx[i] = bezt[j].vec[1][0] - bezt[j - 1].vec[1][0];
|
|
|
|
dy[i] = bezt[j].vec[1][1] - bezt[j - 1].vec[1][1];
|
2017-11-01 21:34:30 +03:00
|
|
|
|
|
|
|
/* when cyclic, jump from last point to first */
|
2017-11-02 15:09:11 +11:00
|
|
|
if (cycle && j == total - 1)
|
2017-11-01 21:34:30 +03:00
|
|
|
j = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ratio of x intervals */
|
|
|
|
|
2017-11-02 15:09:11 +11:00
|
|
|
l[0] = l[count - 1] = 1.0f;
|
2017-11-01 21:34:30 +03:00
|
|
|
|
2017-11-02 15:09:11 +11:00
|
|
|
for (int i = 1; i < count - 1; i++) {
|
|
|
|
l[i] = dx[i + 1] / dx[i];
|
2017-11-01 21:34:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* compute handle clamp ranges */
|
|
|
|
|
|
|
|
bool clamped_prev = false, clamped_cur = ELEM(HD_AUTO_ANIM, bezt_first->h1, bezt_first->h2);
|
|
|
|
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
hmax[i] = FLT_MAX;
|
|
|
|
hmin[i] = -FLT_MAX;
|
|
|
|
}
|
|
|
|
|
2017-11-02 15:09:11 +11:00
|
|
|
for (int i = 1, j = start + 1; i < count; i++, j++) {
|
2017-11-01 21:34:30 +03:00
|
|
|
clamped_prev = clamped_cur;
|
|
|
|
clamped_cur = ELEM(HD_AUTO_ANIM, bezt[j].h1, bezt[j].h2);
|
|
|
|
|
2017-11-02 15:09:11 +11:00
|
|
|
if (cycle && j == total - 1) {
|
2017-11-01 21:34:30 +03:00
|
|
|
j = 0;
|
|
|
|
clamped_cur = clamped_cur || ELEM(HD_AUTO_ANIM, bezt[j].h1, bezt[j].h2);
|
|
|
|
}
|
|
|
|
|
2017-11-02 15:09:11 +11:00
|
|
|
bezier_clamp(hmax, hmin, i - 1, dy[i], clamped_prev, clamped_prev);
|
2017-11-01 21:34:30 +03:00
|
|
|
bezier_clamp(hmax, hmin, i, dy[i] * l[i], clamped_cur, clamped_cur);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* full cycle merges first and last points into continuous loop */
|
|
|
|
|
|
|
|
float first_handle_adj = 0.0f, last_handle_adj = 0.0f;
|
|
|
|
|
2017-11-02 15:09:11 +11:00
|
|
|
if (full_cycle) {
|
2018-09-24 17:27:41 +02:00
|
|
|
/* reduce the number of unknowns by one */
|
2017-11-02 15:09:11 +11:00
|
|
|
int i = solve_count = count - 1;
|
2017-11-01 21:34:30 +03:00
|
|
|
|
|
|
|
dx[0] = dx[i];
|
|
|
|
dy[0] = dy[i];
|
|
|
|
|
|
|
|
l[0] = l[i] = dx[1] / dx[0];
|
|
|
|
|
|
|
|
hmin[0] = max_ff(hmin[0], hmin[i]);
|
|
|
|
hmax[0] = min_ff(hmax[0], hmax[i]);
|
|
|
|
|
|
|
|
solve_first = solve_last = true;
|
|
|
|
|
|
|
|
bezier_eq_continuous(a, b, c, d, dy, l, 0);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
float tmp[2];
|
|
|
|
|
|
|
|
/* boundary condition: fixed handles or zero curvature */
|
|
|
|
if (!solve_first) {
|
|
|
|
sub_v2_v2v2(tmp, bezt_first->vec[2], bezt_first->vec[1]);
|
|
|
|
first_handle_adj = bezier_calc_handle_adj(tmp, dx[1]);
|
|
|
|
|
|
|
|
bezier_lock_unknown(a, b, c, d, 0, tmp[1]);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
bezier_eq_noaccel_right(a, b, c, d, dy, l, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!solve_last) {
|
|
|
|
sub_v2_v2v2(tmp, bezt_last->vec[1], bezt_last->vec[0]);
|
2017-11-02 15:09:11 +11:00
|
|
|
last_handle_adj = bezier_calc_handle_adj(tmp, dx[count - 1]);
|
2017-11-01 21:34:30 +03:00
|
|
|
|
2017-11-02 15:09:11 +11:00
|
|
|
bezier_lock_unknown(a, b, c, d, count - 1, tmp[1]);
|
2017-11-01 21:34:30 +03:00
|
|
|
}
|
|
|
|
else {
|
2017-11-02 15:09:11 +11:00
|
|
|
bezier_eq_noaccel_left(a, b, c, d, dy, l, count - 1);
|
2017-11-01 21:34:30 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* main tridiagonal system of equations */
|
|
|
|
|
2017-11-02 15:09:11 +11:00
|
|
|
for (int i = 1; i < count - 1; i++) {
|
2017-11-01 21:34:30 +03:00
|
|
|
bezier_eq_continuous(a, b, c, d, dy, l, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* apply correction for user-defined handles with nonstandard x positions */
|
|
|
|
|
|
|
|
if (!full_cycle) {
|
|
|
|
if (count > 2 || solve_last) {
|
2017-11-02 15:09:11 +11:00
|
|
|
b[1] += l[1] * first_handle_adj;
|
2017-11-01 21:34:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (count > 2 || solve_first) {
|
2017-11-02 15:09:11 +11:00
|
|
|
b[count - 2] += last_handle_adj;
|
2017-11-01 21:34:30 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* solve and output results */
|
|
|
|
|
|
|
|
if (tridiagonal_solve_with_limits(a, b, c, d, h, hmin, hmax, solve_count)) {
|
|
|
|
if (full_cycle) {
|
2017-11-02 15:09:11 +11:00
|
|
|
h[count - 1] = h[0];
|
2017-11-01 21:34:30 +03:00
|
|
|
}
|
|
|
|
|
2017-11-02 15:09:11 +11:00
|
|
|
for (int i = 1, j = start + 1; i < count - 1; i++, j++) {
|
|
|
|
bool end = (j == total - 1);
|
2017-11-01 21:34:30 +03:00
|
|
|
|
2017-11-02 15:09:11 +11:00
|
|
|
bezier_output_handle(&bezt[j], false, -h[i] / l[i], end);
|
2017-11-01 21:34:30 +03:00
|
|
|
|
|
|
|
if (end)
|
|
|
|
j = 0;
|
|
|
|
|
|
|
|
bezier_output_handle(&bezt[j], true, h[i], end);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (solve_first) {
|
|
|
|
bezier_output_handle(bezt_first, true, h[0], start == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (solve_last) {
|
2017-11-02 15:09:11 +11:00
|
|
|
bezier_output_handle(bezt_last, false, -h[count - 1] / l[count - 1], start + count == total);
|
2017-11-01 21:34:30 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* free all */
|
|
|
|
|
|
|
|
free_arrays(tmp_buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool is_free_auto_point(BezTriple *bezt)
|
|
|
|
{
|
|
|
|
return BEZT_IS_AUTOH(bezt) && bezt->f5 == HD_AUTOTYPE_NORMAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BKE_nurb_handle_smooth_fcurve(BezTriple *bezt, int total, bool cycle)
|
|
|
|
{
|
|
|
|
/* ignore cyclic extrapolation if end points are locked */
|
2017-11-02 15:09:11 +11:00
|
|
|
cycle = cycle && is_free_auto_point(&bezt[0]) && is_free_auto_point(&bezt[total - 1]);
|
2017-11-01 21:34:30 +03:00
|
|
|
|
|
|
|
/* if cyclic, try to find a sequence break point */
|
|
|
|
int search_base = 0;
|
|
|
|
|
|
|
|
if (cycle) {
|
2017-11-02 15:09:11 +11:00
|
|
|
for (int i = 1; i < total - 1; i++) {
|
2017-11-01 21:34:30 +03:00
|
|
|
if (!is_free_auto_point(&bezt[i])) {
|
|
|
|
search_base = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* all points of the curve are freely changeable auto handles - solve as full cycle */
|
|
|
|
if (search_base == 0) {
|
|
|
|
bezier_handle_calc_smooth_fcurve(bezt, total, 0, total, cycle);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find continuous subsequences of free auto handles and smooth them, starting at
|
|
|
|
* search_base. In cyclic mode these subsequences can span the cycle boundary. */
|
|
|
|
int start = search_base, count = 1;
|
|
|
|
|
2017-11-02 15:09:11 +11:00
|
|
|
for (int i = 1, j = start + 1; i < total; i++, j++) {
|
2017-11-01 21:34:30 +03:00
|
|
|
/* in cyclic mode: jump from last to first point when necessary */
|
2017-11-02 15:09:11 +11:00
|
|
|
if (j == total - 1 && cycle)
|
2017-11-01 21:34:30 +03:00
|
|
|
j = 0;
|
|
|
|
|
|
|
|
/* non auto handle closes the list (we come here at least for the last handle, see above) */
|
|
|
|
if (!is_free_auto_point(&bezt[j])) {
|
2017-11-02 15:09:11 +11:00
|
|
|
bezier_handle_calc_smooth_fcurve(bezt, total, start, count + 1, cycle);
|
2017-11-01 21:34:30 +03:00
|
|
|
start = j;
|
|
|
|
count = 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count > 1) {
|
|
|
|
bezier_handle_calc_smooth_fcurve(bezt, total, start, count, cycle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BKE_nurb_handle_calc(BezTriple *bezt, BezTriple *prev, BezTriple *next, const bool is_fcurve, const char smoothing)
|
2012-03-12 14:55:56 +00:00
|
|
|
{
|
2017-11-01 21:34:30 +03:00
|
|
|
calchandleNurb_intern(bezt, prev, next, is_fcurve, false, smoothing);
|
2012-03-12 14:55:56 +00:00
|
|
|
}
|
|
|
|
|
2012-04-28 16:49:00 +00:00
|
|
|
void BKE_nurb_handles_calc(Nurb *nu) /* first, if needed, set handle flags */
|
2012-03-12 14:55:56 +00:00
|
|
|
{
|
2014-04-01 11:34:00 +11:00
|
|
|
calchandlesNurb_intern(nu, false);
|
2012-03-12 14:55:56 +00:00
|
|
|
}
|
|
|
|
|
2014-09-04 16:14:02 +10:00
|
|
|
/**
|
|
|
|
* Workaround #BKE_nurb_handles_calc logic
|
|
|
|
* that makes unselected align to the selected handle.
|
|
|
|
*/
|
|
|
|
static void nurbList_handles_swap_select(Nurb *nu)
|
|
|
|
{
|
|
|
|
BezTriple *bezt;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = nu->pntsu, bezt = nu->bezt; i--; bezt++) {
|
|
|
|
if ((bezt->f1 & SELECT) != (bezt->f3 & SELECT)) {
|
|
|
|
bezt->f1 ^= SELECT;
|
|
|
|
bezt->f3 ^= SELECT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* internal use only (weak) */
|
|
|
|
static void nurb_handles_calc__align_selected(Nurb *nu)
|
|
|
|
{
|
|
|
|
nurbList_handles_swap_select(nu);
|
|
|
|
BKE_nurb_handles_calc(nu);
|
|
|
|
nurbList_handles_swap_select(nu);
|
|
|
|
}
|
|
|
|
|
2013-08-29 02:32:51 +00:00
|
|
|
/* similar to BKE_nurb_handle_calc but for curves and
|
|
|
|
* figures out the previous and next for us */
|
|
|
|
void BKE_nurb_handle_calc_simple(Nurb *nu, BezTriple *bezt)
|
|
|
|
{
|
2013-09-10 01:06:45 +00:00
|
|
|
if (nu->pntsu > 1) {
|
|
|
|
BezTriple *prev = BKE_nurb_bezt_get_prev(nu, bezt);
|
|
|
|
BezTriple *next = BKE_nurb_bezt_get_next(nu, bezt);
|
2017-11-01 21:34:30 +03:00
|
|
|
BKE_nurb_handle_calc(bezt, prev, next, 0, 0);
|
2013-09-10 01:06:45 +00:00
|
|
|
}
|
2013-08-29 02:32:51 +00:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2015-01-26 20:55:41 +11:00
|
|
|
void BKE_nurb_handle_calc_simple_auto(Nurb *nu, BezTriple *bezt)
|
|
|
|
{
|
|
|
|
if (nu->pntsu > 1) {
|
|
|
|
const char h1_back = bezt->h1, h2_back = bezt->h2;
|
|
|
|
|
|
|
|
bezt->h1 = bezt->h2 = HD_AUTO;
|
|
|
|
|
|
|
|
/* Override handle types to HD_AUTO and recalculate */
|
|
|
|
BKE_nurb_handle_calc_simple(nu, bezt);
|
|
|
|
|
|
|
|
bezt->h1 = h1_back;
|
|
|
|
bezt->h2 = h2_back;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-01 08:18:43 +00:00
|
|
|
/**
|
|
|
|
* Use when something has changed handle positions.
|
|
|
|
*
|
|
|
|
* The caller needs to recalculate handles.
|
|
|
|
*/
|
|
|
|
void BKE_nurb_bezt_handle_test(BezTriple *bezt, const bool use_handle)
|
|
|
|
{
|
|
|
|
short flag = 0;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2013-10-01 08:18:43 +00:00
|
|
|
#define SEL_F1 (1 << 0)
|
|
|
|
#define SEL_F2 (1 << 1)
|
|
|
|
#define SEL_F3 (1 << 2)
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2013-10-01 08:18:43 +00:00
|
|
|
if (use_handle) {
|
|
|
|
if (bezt->f1 & SELECT) flag |= SEL_F1;
|
|
|
|
if (bezt->f2 & SELECT) flag |= SEL_F2;
|
|
|
|
if (bezt->f3 & SELECT) flag |= SEL_F3;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
flag = (bezt->f2 & SELECT) ? (SEL_F1 | SEL_F2 | SEL_F3) : 0;
|
|
|
|
}
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2013-10-01 08:18:43 +00:00
|
|
|
/* check for partial selection */
|
|
|
|
if (!ELEM(flag, 0, SEL_F1 | SEL_F2 | SEL_F3)) {
|
|
|
|
if (ELEM(bezt->h1, HD_AUTO, HD_AUTO_ANIM)) {
|
|
|
|
bezt->h1 = HD_ALIGN;
|
|
|
|
}
|
|
|
|
if (ELEM(bezt->h2, HD_AUTO, HD_AUTO_ANIM)) {
|
|
|
|
bezt->h2 = HD_ALIGN;
|
|
|
|
}
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2013-10-01 08:18:43 +00:00
|
|
|
if (bezt->h1 == HD_VECT) {
|
|
|
|
if ((!(flag & SEL_F1)) != (!(flag & SEL_F2))) {
|
|
|
|
bezt->h1 = HD_FREE;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2013-10-01 08:18:43 +00:00
|
|
|
}
|
|
|
|
if (bezt->h2 == HD_VECT) {
|
|
|
|
if ((!(flag & SEL_F3)) != (!(flag & SEL_F2))) {
|
|
|
|
bezt->h2 = HD_FREE;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
2013-10-01 08:18:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#undef SEL_F1
|
|
|
|
#undef SEL_F2
|
|
|
|
#undef SEL_F3
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void BKE_nurb_handles_test(Nurb *nu, const bool use_handle)
|
|
|
|
{
|
|
|
|
BezTriple *bezt;
|
2014-01-19 00:18:53 +06:00
|
|
|
int a;
|
2013-10-01 08:18:43 +00:00
|
|
|
|
|
|
|
if (nu->type != CU_BEZIER)
|
|
|
|
return;
|
|
|
|
|
|
|
|
bezt = nu->bezt;
|
|
|
|
a = nu->pntsu;
|
|
|
|
while (a--) {
|
|
|
|
BKE_nurb_bezt_handle_test(bezt, use_handle);
|
2002-10-12 11:37:38 +00:00
|
|
|
bezt++;
|
|
|
|
}
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2012-04-28 16:49:00 +00:00
|
|
|
BKE_nurb_handles_calc(nu);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2012-04-28 16:49:00 +00:00
|
|
|
void BKE_nurb_handles_autocalc(Nurb *nu, int flag)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2003-04-25 15:48:11 +00:00
|
|
|
/* checks handle coordinates and calculates type */
|
2013-10-08 12:03:49 +00:00
|
|
|
const float eps = 0.0001f;
|
|
|
|
const float eps_sq = eps * eps;
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
BezTriple *bezt2, *bezt1, *bezt0;
|
2013-10-08 12:35:58 +00:00
|
|
|
int i;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-07 08:53:59 +00:00
|
|
|
if (nu == NULL || nu->bezt == NULL)
|
|
|
|
return;
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
bezt2 = nu->bezt;
|
2012-05-06 15:15:33 +00:00
|
|
|
bezt1 = bezt2 + (nu->pntsu - 1);
|
2002-10-12 11:37:38 +00:00
|
|
|
bezt0 = bezt1 - 1;
|
|
|
|
i = nu->pntsu;
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
while (i--) {
|
2013-10-08 12:35:58 +00:00
|
|
|
bool align = false, leftsmall = false, rightsmall = false;
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2003-04-25 15:48:11 +00:00
|
|
|
/* left handle: */
|
2017-11-02 15:09:11 +11:00
|
|
|
if (flag == 0 || (bezt1->f1 & flag)) {
|
2013-10-01 08:18:43 +00:00
|
|
|
bezt1->h1 = HD_FREE;
|
2003-04-25 15:48:11 +00:00
|
|
|
/* distance too short: vectorhandle */
|
2013-10-08 12:03:49 +00:00
|
|
|
if (len_squared_v3v3(bezt1->vec[1], bezt0->vec[1]) < eps_sq) {
|
2012-05-06 15:15:33 +00:00
|
|
|
bezt1->h1 = HD_VECT;
|
2013-10-08 12:35:58 +00:00
|
|
|
leftsmall = true;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* aligned handle? */
|
2013-12-28 17:29:58 +11:00
|
|
|
if (dist_squared_to_line_v3(bezt1->vec[1], bezt1->vec[0], bezt1->vec[2]) < eps_sq) {
|
2013-10-08 12:35:58 +00:00
|
|
|
align = true;
|
2012-05-06 15:15:33 +00:00
|
|
|
bezt1->h1 = HD_ALIGN;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2003-04-25 15:48:11 +00:00
|
|
|
/* or vector handle? */
|
2013-12-28 17:29:58 +11:00
|
|
|
if (dist_squared_to_line_v3(bezt1->vec[0], bezt1->vec[1], bezt0->vec[1]) < eps_sq)
|
2012-05-06 15:15:33 +00:00
|
|
|
bezt1->h1 = HD_VECT;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
2003-04-25 15:48:11 +00:00
|
|
|
/* right handle: */
|
2017-11-02 15:09:11 +11:00
|
|
|
if (flag == 0 || (bezt1->f3 & flag)) {
|
2013-10-01 08:18:43 +00:00
|
|
|
bezt1->h2 = HD_FREE;
|
2003-04-25 15:48:11 +00:00
|
|
|
/* distance too short: vectorhandle */
|
2013-10-08 12:03:49 +00:00
|
|
|
if (len_squared_v3v3(bezt1->vec[1], bezt2->vec[1]) < eps_sq) {
|
2012-05-06 15:15:33 +00:00
|
|
|
bezt1->h2 = HD_VECT;
|
2013-10-08 12:35:58 +00:00
|
|
|
rightsmall = true;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* aligned handle? */
|
2012-05-06 15:15:33 +00:00
|
|
|
if (align) bezt1->h2 = HD_ALIGN;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2003-04-25 15:48:11 +00:00
|
|
|
/* or vector handle? */
|
2013-12-28 17:29:58 +11:00
|
|
|
if (dist_squared_to_line_v3(bezt1->vec[2], bezt1->vec[1], bezt2->vec[1]) < eps_sq)
|
2012-05-06 15:15:33 +00:00
|
|
|
bezt1->h2 = HD_VECT;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
2012-05-07 08:53:59 +00:00
|
|
|
if (leftsmall && bezt1->h2 == HD_ALIGN)
|
2013-10-01 08:18:43 +00:00
|
|
|
bezt1->h2 = HD_FREE;
|
2012-05-07 08:53:59 +00:00
|
|
|
if (rightsmall && bezt1->h1 == HD_ALIGN)
|
2013-10-01 08:18:43 +00:00
|
|
|
bezt1->h1 = HD_FREE;
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2003-04-25 15:48:11 +00:00
|
|
|
/* undesired combination: */
|
2012-05-07 08:53:59 +00:00
|
|
|
if (bezt1->h1 == HD_ALIGN && bezt1->h2 == HD_VECT)
|
2013-10-01 08:18:43 +00:00
|
|
|
bezt1->h1 = HD_FREE;
|
2012-05-07 08:53:59 +00:00
|
|
|
if (bezt1->h2 == HD_ALIGN && bezt1->h1 == HD_VECT)
|
2013-10-01 08:18:43 +00:00
|
|
|
bezt1->h2 = HD_FREE;
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
bezt0 = bezt1;
|
|
|
|
bezt1 = bezt2;
|
2002-10-12 11:37:38 +00:00
|
|
|
bezt2++;
|
|
|
|
}
|
|
|
|
|
2012-04-28 16:49:00 +00:00
|
|
|
BKE_nurb_handles_calc(nu);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2012-04-28 16:49:00 +00:00
|
|
|
void BKE_nurbList_handles_autocalc(ListBase *editnurb, int flag)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
Nurb *nu;
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
nu = editnurb->first;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (nu) {
|
2012-04-28 16:49:00 +00:00
|
|
|
BKE_nurb_handles_autocalc(nu, flag);
|
2012-05-06 15:15:33 +00:00
|
|
|
nu = nu->next;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-30 14:04:24 +11:00
|
|
|
void BKE_nurbList_handles_set(ListBase *editnurb, const char code)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
/* code==1: set autohandle */
|
|
|
|
/* code==2: set vectorhandle */
|
2005-07-10 12:50:14 +00:00
|
|
|
/* code==3 (HD_ALIGN) it toggle, vectorhandles become HD_FREE */
|
|
|
|
/* code==4: sets icu flag to become IPO_AUTO_HORIZ, horizontal extremes on auto-handles */
|
2007-11-10 15:31:41 +00:00
|
|
|
/* code==5: Set align, like 3 but no toggle */
|
|
|
|
/* code==6: Clear align, like 3 but no toggle */
|
2002-10-12 11:37:38 +00:00
|
|
|
Nurb *nu;
|
|
|
|
BezTriple *bezt;
|
2014-01-19 00:18:53 +06:00
|
|
|
int a;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2014-03-30 14:04:24 +11:00
|
|
|
if (ELEM(code, HD_AUTO, HD_VECT)) {
|
2012-05-06 15:15:33 +00:00
|
|
|
nu = editnurb->first;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (nu) {
|
|
|
|
if (nu->type == CU_BEZIER) {
|
2012-05-06 15:15:33 +00:00
|
|
|
bezt = nu->bezt;
|
|
|
|
a = nu->pntsu;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (a--) {
|
|
|
|
if ((bezt->f1 & SELECT) || (bezt->f3 & SELECT)) {
|
2012-05-07 08:53:59 +00:00
|
|
|
if (bezt->f1 & SELECT)
|
|
|
|
bezt->h1 = code;
|
|
|
|
if (bezt->f3 & SELECT)
|
|
|
|
bezt->h2 = code;
|
2012-05-06 15:15:33 +00:00
|
|
|
if (bezt->h1 != bezt->h2) {
|
2012-05-07 08:53:59 +00:00
|
|
|
if (ELEM(bezt->h1, HD_ALIGN, HD_AUTO))
|
|
|
|
bezt->h1 = HD_FREE;
|
|
|
|
if (ELEM(bezt->h2, HD_ALIGN, HD_AUTO))
|
|
|
|
bezt->h2 = HD_FREE;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
bezt++;
|
|
|
|
}
|
2014-09-04 16:14:02 +10:00
|
|
|
|
|
|
|
/* like BKE_nurb_handles_calc but moves selected */
|
|
|
|
nurb_handles_calc__align_selected(nu);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2012-05-06 15:15:33 +00:00
|
|
|
nu = nu->next;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2014-03-30 14:04:24 +11:00
|
|
|
char h_new = HD_FREE;
|
|
|
|
|
2003-04-25 15:48:11 +00:00
|
|
|
/* there is 1 handle not FREE: FREE it all, else make ALIGNED */
|
2007-11-10 15:31:41 +00:00
|
|
|
if (code == 5) {
|
2014-03-30 14:04:24 +11:00
|
|
|
h_new = HD_ALIGN;
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
|
|
|
else if (code == 6) {
|
2014-03-30 14:04:24 +11:00
|
|
|
h_new = HD_FREE;
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
|
|
|
else {
|
2007-11-10 15:31:41 +00:00
|
|
|
/* Toggle */
|
2014-03-30 14:04:24 +11:00
|
|
|
for (nu = editnurb->first; nu; nu = nu->next) {
|
2012-03-24 06:18:31 +00:00
|
|
|
if (nu->type == CU_BEZIER) {
|
2012-05-06 15:15:33 +00:00
|
|
|
bezt = nu->bezt;
|
|
|
|
a = nu->pntsu;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (a--) {
|
2014-03-30 14:04:24 +11:00
|
|
|
if (((bezt->f1 & SELECT) && bezt->h1 != HD_FREE) ||
|
|
|
|
((bezt->f3 & SELECT) && bezt->h2 != HD_FREE))
|
|
|
|
{
|
|
|
|
h_new = HD_AUTO;
|
|
|
|
break;
|
|
|
|
}
|
2007-11-10 15:31:41 +00:00
|
|
|
bezt++;
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
2014-03-30 14:04:24 +11:00
|
|
|
h_new = (h_new == HD_FREE) ? HD_ALIGN : HD_FREE;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2014-03-30 14:04:24 +11:00
|
|
|
for (nu = editnurb->first; nu; nu = nu->next) {
|
2012-03-24 06:18:31 +00:00
|
|
|
if (nu->type == CU_BEZIER) {
|
2012-05-06 15:15:33 +00:00
|
|
|
bezt = nu->bezt;
|
|
|
|
a = nu->pntsu;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (a--) {
|
2014-03-30 14:04:24 +11:00
|
|
|
if (bezt->f1 & SELECT) bezt->h1 = h_new;
|
|
|
|
if (bezt->f3 & SELECT) bezt->h2 = h_new;
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
bezt++;
|
|
|
|
}
|
2014-09-04 16:14:02 +10:00
|
|
|
|
|
|
|
/* like BKE_nurb_handles_calc but moves selected */
|
|
|
|
nurb_handles_calc__align_selected(nu);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-14 02:32:48 +11:00
|
|
|
void BKE_nurbList_handles_recalculate(ListBase *editnurb, const bool calc_length, const char flag)
|
|
|
|
{
|
|
|
|
Nurb *nu;
|
|
|
|
BezTriple *bezt;
|
|
|
|
int a;
|
|
|
|
|
|
|
|
for (nu = editnurb->first; nu; nu = nu->next) {
|
|
|
|
if (nu->type == CU_BEZIER) {
|
|
|
|
bool changed = false;
|
|
|
|
|
|
|
|
for (a = nu->pntsu, bezt = nu->bezt; a--; bezt++) {
|
|
|
|
|
|
|
|
const bool h1_select = (bezt->f1 & flag) == flag;
|
|
|
|
const bool h2_select = (bezt->f3 & flag) == flag;
|
|
|
|
|
|
|
|
if (h1_select || h2_select) {
|
|
|
|
|
|
|
|
float co1_back[3], co2_back[3];
|
|
|
|
|
|
|
|
copy_v3_v3(co1_back, bezt->vec[0]);
|
|
|
|
copy_v3_v3(co2_back, bezt->vec[2]);
|
|
|
|
|
2015-01-26 20:55:41 +11:00
|
|
|
BKE_nurb_handle_calc_simple_auto(nu, bezt);
|
2013-12-14 02:32:48 +11:00
|
|
|
|
|
|
|
if (h1_select) {
|
|
|
|
if (!calc_length) {
|
|
|
|
dist_ensure_v3_v3fl(bezt->vec[0], bezt->vec[1], len_v3v3(co1_back, bezt->vec[1]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
copy_v3_v3(bezt->vec[0], co1_back);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (h2_select) {
|
|
|
|
if (!calc_length) {
|
|
|
|
dist_ensure_v3_v3fl(bezt->vec[2], bezt->vec[1], len_v3v3(co2_back, bezt->vec[1]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
copy_v3_v3(bezt->vec[2], co2_back);
|
|
|
|
}
|
|
|
|
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (changed) {
|
|
|
|
/* Recalculate the whole curve */
|
|
|
|
BKE_nurb_handles_calc(nu);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-16 00:03:33 +00:00
|
|
|
void BKE_nurbList_flag_set(ListBase *editnurb, short flag)
|
|
|
|
{
|
|
|
|
Nurb *nu;
|
|
|
|
BezTriple *bezt;
|
|
|
|
BPoint *bp;
|
|
|
|
int a;
|
|
|
|
|
|
|
|
for (nu = editnurb->first; nu; nu = nu->next) {
|
|
|
|
if (nu->type == CU_BEZIER) {
|
|
|
|
a = nu->pntsu;
|
|
|
|
bezt = nu->bezt;
|
|
|
|
while (a--) {
|
|
|
|
bezt->f1 = bezt->f2 = bezt->f3 = flag;
|
|
|
|
bezt++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
a = nu->pntsu * nu->pntsv;
|
|
|
|
bp = nu->bp;
|
|
|
|
while (a--) {
|
|
|
|
bp->f1 = flag;
|
|
|
|
bp++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-28 16:49:00 +00:00
|
|
|
void BKE_nurb_direction_switch(Nurb *nu)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
BezTriple *bezt1, *bezt2;
|
|
|
|
BPoint *bp1, *bp2;
|
|
|
|
float *fp1, *fp2, *tempf;
|
|
|
|
int a, b;
|
|
|
|
|
2012-08-25 20:16:08 +00:00
|
|
|
if (nu->pntsu == 1 && nu->pntsv == 1) {
|
|
|
|
return;
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (nu->type == CU_BEZIER) {
|
2012-05-06 15:15:33 +00:00
|
|
|
a = nu->pntsu;
|
|
|
|
bezt1 = nu->bezt;
|
|
|
|
bezt2 = bezt1 + (a - 1);
|
|
|
|
if (a & 1) a += 1; /* if odd, also swap middle content */
|
|
|
|
a /= 2;
|
|
|
|
while (a > 0) {
|
2012-08-25 20:16:08 +00:00
|
|
|
if (bezt1 != bezt2) {
|
2012-05-07 08:53:59 +00:00
|
|
|
SWAP(BezTriple, *bezt1, *bezt2);
|
2012-08-25 20:16:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
swap_v3_v3(bezt1->vec[0], bezt1->vec[2]);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-08-25 20:16:08 +00:00
|
|
|
if (bezt1 != bezt2) {
|
|
|
|
swap_v3_v3(bezt2->vec[0], bezt2->vec[2]);
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
SWAP(char, bezt1->h1, bezt1->h2);
|
2012-08-25 19:43:15 +00:00
|
|
|
SWAP(char, bezt1->f1, bezt1->f3);
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
if (bezt1 != bezt2) {
|
2002-10-12 11:37:38 +00:00
|
|
|
SWAP(char, bezt2->h1, bezt2->h2);
|
2012-08-25 19:43:15 +00:00
|
|
|
SWAP(char, bezt2->f1, bezt2->f3);
|
2012-05-06 15:15:33 +00:00
|
|
|
bezt1->alfa = -bezt1->alfa;
|
|
|
|
bezt2->alfa = -bezt2->alfa;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2014-02-14 14:58:52 +06:00
|
|
|
else {
|
|
|
|
bezt1->alfa = -bezt1->alfa;
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
a--;
|
2012-05-07 08:53:59 +00:00
|
|
|
bezt1++;
|
2002-10-12 11:37:38 +00:00
|
|
|
bezt2--;
|
|
|
|
}
|
|
|
|
}
|
2012-05-06 15:15:33 +00:00
|
|
|
else if (nu->pntsv == 1) {
|
|
|
|
a = nu->pntsu;
|
|
|
|
bp1 = nu->bp;
|
|
|
|
bp2 = bp1 + (a - 1);
|
|
|
|
a /= 2;
|
|
|
|
while (bp1 != bp2 && a > 0) {
|
2002-10-12 11:37:38 +00:00
|
|
|
SWAP(BPoint, *bp1, *bp2);
|
|
|
|
a--;
|
2012-05-06 15:15:33 +00:00
|
|
|
bp1->alfa = -bp1->alfa;
|
|
|
|
bp2->alfa = -bp2->alfa;
|
2012-05-07 08:53:59 +00:00
|
|
|
bp1++;
|
2002-10-12 11:37:38 +00:00
|
|
|
bp2--;
|
|
|
|
}
|
2014-02-14 14:58:52 +06:00
|
|
|
/* If there're odd number of points no need to touch coord of middle one,
|
|
|
|
* but still need to change it's tilt.
|
|
|
|
*/
|
|
|
|
if (nu->pntsu & 1) {
|
|
|
|
bp1->alfa = -bp1->alfa;
|
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
if (nu->type == CU_NURBS) {
|
2010-12-03 17:31:34 +00:00
|
|
|
/* no knots for too short paths */
|
2012-03-24 06:18:31 +00:00
|
|
|
if (nu->knotsu) {
|
2010-12-03 17:31:34 +00:00
|
|
|
/* inverse knots */
|
2012-05-06 15:15:33 +00:00
|
|
|
a = KNOTSU(nu);
|
|
|
|
fp1 = nu->knotsu;
|
|
|
|
fp2 = fp1 + (a - 1);
|
|
|
|
a /= 2;
|
|
|
|
while (fp1 != fp2 && a > 0) {
|
2010-12-03 17:31:34 +00:00
|
|
|
SWAP(float, *fp1, *fp2);
|
|
|
|
a--;
|
2012-05-07 08:53:59 +00:00
|
|
|
fp1++;
|
2010-12-03 17:31:34 +00:00
|
|
|
fp2--;
|
|
|
|
}
|
|
|
|
/* and make in increasing order again */
|
2012-05-06 15:15:33 +00:00
|
|
|
a = KNOTSU(nu);
|
|
|
|
fp1 = nu->knotsu;
|
2018-01-14 22:14:20 +01:00
|
|
|
fp2 = tempf = MEM_malloc_arrayN(a, sizeof(float), "switchdirect");
|
2014-02-20 20:09:06 +11:00
|
|
|
a--;
|
|
|
|
fp2[a] = fp1[a];
|
2012-03-24 06:18:31 +00:00
|
|
|
while (a--) {
|
2014-03-01 14:20:54 +11:00
|
|
|
fp2[0] = fabsf(fp1[1] - fp1[0]);
|
2010-12-03 17:31:34 +00:00
|
|
|
fp1++;
|
|
|
|
fp2++;
|
|
|
|
}
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
a = KNOTSU(nu) - 1;
|
|
|
|
fp1 = nu->knotsu;
|
|
|
|
fp2 = tempf;
|
|
|
|
fp1[0] = 0.0;
|
2002-10-12 11:37:38 +00:00
|
|
|
fp1++;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (a--) {
|
2012-05-06 15:15:33 +00:00
|
|
|
fp1[0] = fp1[-1] + fp2[0];
|
2010-12-03 17:31:34 +00:00
|
|
|
fp1++;
|
|
|
|
fp2++;
|
|
|
|
}
|
|
|
|
MEM_freeN(tempf);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2012-05-06 15:15:33 +00:00
|
|
|
for (b = 0; b < nu->pntsv; b++) {
|
|
|
|
bp1 = nu->bp + b * nu->pntsu;
|
|
|
|
a = nu->pntsu;
|
|
|
|
bp2 = bp1 + (a - 1);
|
|
|
|
a /= 2;
|
2012-05-07 08:53:59 +00:00
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
while (bp1 != bp2 && a > 0) {
|
2002-10-12 11:37:38 +00:00
|
|
|
SWAP(BPoint, *bp1, *bp2);
|
|
|
|
a--;
|
2012-05-07 08:53:59 +00:00
|
|
|
bp1++;
|
2002-10-12 11:37:38 +00:00
|
|
|
bp2--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-08-15 10:30:53 +00:00
|
|
|
|
|
|
|
|
2014-03-16 03:24:05 +11:00
|
|
|
float (*BKE_curve_nurbs_vertexCos_get(ListBase *lb, int *r_numVerts))[3]
|
2005-08-15 10:30:53 +00:00
|
|
|
{
|
2014-03-16 03:24:05 +11:00
|
|
|
int i, numVerts = *r_numVerts = BKE_nurbList_verts_count(lb);
|
2018-01-14 22:14:20 +01:00
|
|
|
float *co, (*cos)[3] = MEM_malloc_arrayN(numVerts, sizeof(*cos), "cu_vcos");
|
2005-08-15 10:30:53 +00:00
|
|
|
Nurb *nu;
|
|
|
|
|
|
|
|
co = cos[0];
|
2012-05-06 15:15:33 +00:00
|
|
|
for (nu = lb->first; nu; nu = nu->next) {
|
2009-09-08 00:23:33 +00:00
|
|
|
if (nu->type == CU_BEZIER) {
|
2005-08-15 10:30:53 +00:00
|
|
|
BezTriple *bezt = nu->bezt;
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
for (i = 0; i < nu->pntsu; i++, bezt++) {
|
|
|
|
copy_v3_v3(co, bezt->vec[0]); co += 3;
|
|
|
|
copy_v3_v3(co, bezt->vec[1]); co += 3;
|
|
|
|
copy_v3_v3(co, bezt->vec[2]); co += 3;
|
2005-08-15 10:30:53 +00:00
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
|
|
|
else {
|
2005-08-15 10:30:53 +00:00
|
|
|
BPoint *bp = nu->bp;
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
for (i = 0; i < nu->pntsu * nu->pntsv; i++, bp++) {
|
|
|
|
copy_v3_v3(co, bp->vec); co += 3;
|
2005-08-15 10:30:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return cos;
|
|
|
|
}
|
|
|
|
|
2013-08-19 09:29:51 +00:00
|
|
|
void BK_curve_nurbs_vertexCos_apply(ListBase *lb, float (*vertexCos)[3])
|
2005-08-15 10:30:53 +00:00
|
|
|
{
|
2014-04-27 00:20:13 +10:00
|
|
|
const float *co = vertexCos[0];
|
2005-08-15 10:30:53 +00:00
|
|
|
Nurb *nu;
|
|
|
|
int i;
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
for (nu = lb->first; nu; nu = nu->next) {
|
2009-09-08 00:23:33 +00:00
|
|
|
if (nu->type == CU_BEZIER) {
|
2005-08-15 10:30:53 +00:00
|
|
|
BezTriple *bezt = nu->bezt;
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
for (i = 0; i < nu->pntsu; i++, bezt++) {
|
|
|
|
copy_v3_v3(bezt->vec[0], co); co += 3;
|
|
|
|
copy_v3_v3(bezt->vec[1], co); co += 3;
|
|
|
|
copy_v3_v3(bezt->vec[2], co); co += 3;
|
2005-08-15 10:30:53 +00:00
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
|
|
|
else {
|
2005-08-15 10:30:53 +00:00
|
|
|
BPoint *bp = nu->bp;
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
for (i = 0; i < nu->pntsu * nu->pntsv; i++, bp++) {
|
|
|
|
copy_v3_v3(bp->vec, co); co += 3;
|
2005-08-15 10:30:53 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-12 14:55:56 +00:00
|
|
|
|
2014-04-01 11:34:00 +11:00
|
|
|
calchandlesNurb_intern(nu, true);
|
2005-08-15 10:30:53 +00:00
|
|
|
}
|
|
|
|
}
|
2008-05-26 09:50:46 +00:00
|
|
|
|
2013-08-19 09:29:51 +00:00
|
|
|
float (*BKE_curve_nurbs_keyVertexCos_get(ListBase *lb, float *key))[3]
|
2009-10-22 09:31:07 +00:00
|
|
|
{
|
2012-04-28 16:49:00 +00:00
|
|
|
int i, numVerts = BKE_nurbList_verts_count(lb);
|
2018-01-14 22:14:20 +01:00
|
|
|
float *co, (*cos)[3] = MEM_malloc_arrayN(numVerts, sizeof(*cos), "cu_vcos");
|
2009-10-22 09:31:07 +00:00
|
|
|
Nurb *nu;
|
|
|
|
|
|
|
|
co = cos[0];
|
2012-05-06 15:15:33 +00:00
|
|
|
for (nu = lb->first; nu; nu = nu->next) {
|
2009-10-22 09:31:07 +00:00
|
|
|
if (nu->type == CU_BEZIER) {
|
|
|
|
BezTriple *bezt = nu->bezt;
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
for (i = 0; i < nu->pntsu; i++, 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
|
|
|
copy_v3_v3(co, &key[0]); co += 3;
|
|
|
|
copy_v3_v3(co, &key[3]); co += 3;
|
|
|
|
copy_v3_v3(co, &key[6]); co += 3;
|
|
|
|
key += KEYELEM_FLOAT_LEN_BEZTRIPLE;
|
2009-10-22 09:31:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
BPoint *bp = nu->bp;
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
for (i = 0; i < nu->pntsu * nu->pntsv; i++, 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
|
|
|
copy_v3_v3(co, key); co += 3;
|
|
|
|
key += KEYELEM_FLOAT_LEN_BPOINT;
|
2009-10-22 09:31:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return cos;
|
|
|
|
}
|
|
|
|
|
2013-08-19 09:29:51 +00:00
|
|
|
void BKE_curve_nurbs_keyVertexTilts_apply(ListBase *lb, float *key)
|
2009-10-22 09:31:07 +00:00
|
|
|
{
|
|
|
|
Nurb *nu;
|
|
|
|
int i;
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
for (nu = lb->first; nu; nu = nu->next) {
|
2012-03-24 06:18:31 +00:00
|
|
|
if (nu->type == CU_BEZIER) {
|
2009-10-22 09:31:07 +00:00
|
|
|
BezTriple *bezt = nu->bezt;
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
for (i = 0; i < nu->pntsu; i++, 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
|
|
|
bezt->alfa = key[9];
|
|
|
|
bezt->radius = key[10];
|
|
|
|
key += KEYELEM_FLOAT_LEN_BEZTRIPLE;
|
2009-10-22 09:31:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
BPoint *bp = nu->bp;
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
for (i = 0; i < nu->pntsu * nu->pntsv; i++, 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
|
|
|
bp->alfa = key[3];
|
|
|
|
bp->radius = key[4];
|
|
|
|
key += KEYELEM_FLOAT_LEN_BPOINT;
|
2009-10-22 09:31:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-09 05:35:49 +00:00
|
|
|
bool BKE_nurb_check_valid_u(struct Nurb *nu)
|
2008-05-26 09:50:46 +00:00
|
|
|
{
|
2012-05-07 08:53:59 +00:00
|
|
|
if (nu->pntsu <= 1)
|
2013-03-09 05:35:49 +00:00
|
|
|
return false;
|
2012-05-07 08:53:59 +00:00
|
|
|
if (nu->type != CU_NURBS)
|
2013-03-09 05:35:49 +00:00
|
|
|
return true; /* not a nurb, lets assume its valid */
|
2012-05-06 15:15:33 +00:00
|
|
|
|
2013-03-09 05:35:49 +00:00
|
|
|
if (nu->pntsu < nu->orderu) return false;
|
2017-09-28 14:33:59 +05:00
|
|
|
if (((nu->flagu & CU_NURB_CYCLIC) == 0) && (nu->flagu & CU_NURB_BEZIER)) { /* Bezier U Endpoints */
|
2012-05-06 15:15:33 +00:00
|
|
|
if (nu->orderu == 4) {
|
2012-05-07 08:53:59 +00:00
|
|
|
if (nu->pntsu < 5)
|
2013-03-09 05:35:49 +00:00
|
|
|
return false; /* bezier with 4 orderu needs 5 points */
|
2012-05-07 08:53:59 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (nu->orderu != 3)
|
2013-03-09 05:35:49 +00:00
|
|
|
return false; /* order must be 3 or 4 */
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
2008-05-26 09:50:46 +00:00
|
|
|
}
|
2013-03-09 05:35:49 +00:00
|
|
|
return true;
|
2008-05-26 09:50:46 +00:00
|
|
|
}
|
2013-03-09 05:35:49 +00:00
|
|
|
bool BKE_nurb_check_valid_v(struct Nurb *nu)
|
2008-05-26 09:50:46 +00:00
|
|
|
{
|
2012-05-07 08:53:59 +00:00
|
|
|
if (nu->pntsv <= 1)
|
2013-03-09 05:35:49 +00:00
|
|
|
return false;
|
2012-05-07 08:53:59 +00:00
|
|
|
if (nu->type != CU_NURBS)
|
2013-03-09 05:35:49 +00:00
|
|
|
return true; /* not a nurb, lets assume its valid */
|
2012-05-06 15:15:33 +00:00
|
|
|
|
2012-05-07 08:53:59 +00:00
|
|
|
if (nu->pntsv < nu->orderv)
|
2013-03-09 05:35:49 +00:00
|
|
|
return false;
|
2017-09-28 14:33:59 +05:00
|
|
|
if (((nu->flagv & CU_NURB_CYCLIC) == 0) && (nu->flagv & CU_NURB_BEZIER)) { /* Bezier V Endpoints */
|
2012-05-06 15:15:33 +00:00
|
|
|
if (nu->orderv == 4) {
|
2012-05-07 08:53:59 +00:00
|
|
|
if (nu->pntsv < 5)
|
2013-03-09 05:35:49 +00:00
|
|
|
return false; /* bezier with 4 orderu needs 5 points */
|
2012-05-07 08:53:59 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (nu->orderv != 3)
|
2013-03-09 05:35:49 +00:00
|
|
|
return false; /* order must be 3 or 4 */
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
2008-05-26 09:50:46 +00:00
|
|
|
}
|
2013-03-09 05:35:49 +00:00
|
|
|
return true;
|
2008-05-26 09:50:46 +00:00
|
|
|
}
|
|
|
|
|
2014-04-08 07:28:14 +10:00
|
|
|
bool BKE_nurb_check_valid_uv(struct Nurb *nu)
|
|
|
|
{
|
|
|
|
if (!BKE_nurb_check_valid_u(nu))
|
|
|
|
return false;
|
|
|
|
if ((nu->pntsv > 1) && !BKE_nurb_check_valid_v(nu))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-03-09 05:35:49 +00:00
|
|
|
bool BKE_nurb_order_clamp_u(struct Nurb *nu)
|
2008-05-26 09:50:46 +00:00
|
|
|
{
|
2013-11-26 06:39:14 +11:00
|
|
|
bool changed = false;
|
2012-05-06 15:15:33 +00:00
|
|
|
if (nu->pntsu < nu->orderu) {
|
2014-03-07 14:05:10 +06:00
|
|
|
nu->orderu = max_ii(2, nu->pntsu);
|
2013-11-26 06:39:14 +11:00
|
|
|
changed = true;
|
2008-05-26 09:50:46 +00:00
|
|
|
}
|
2012-05-06 15:15:33 +00:00
|
|
|
if (((nu->flagu & CU_NURB_CYCLIC) == 0) && (nu->flagu & CU_NURB_BEZIER)) {
|
2012-04-29 15:47:02 +00:00
|
|
|
CLAMP(nu->orderu, 3, 4);
|
2013-11-26 06:39:14 +11:00
|
|
|
changed = true;
|
2008-05-26 09:50:46 +00:00
|
|
|
}
|
2013-11-26 06:39:14 +11:00
|
|
|
return changed;
|
2008-05-26 09:50:46 +00:00
|
|
|
}
|
|
|
|
|
2013-03-09 05:35:49 +00:00
|
|
|
bool BKE_nurb_order_clamp_v(struct Nurb *nu)
|
2008-05-26 09:50:46 +00:00
|
|
|
{
|
2013-11-26 06:39:14 +11:00
|
|
|
bool changed = false;
|
2012-05-06 15:15:33 +00:00
|
|
|
if (nu->pntsv < nu->orderv) {
|
2014-03-07 14:05:10 +06:00
|
|
|
nu->orderv = max_ii(2, nu->pntsv);
|
2013-11-26 06:39:14 +11:00
|
|
|
changed = true;
|
2008-05-26 09:50:46 +00:00
|
|
|
}
|
2012-05-06 15:15:33 +00:00
|
|
|
if (((nu->flagv & CU_NURB_CYCLIC) == 0) && (nu->flagv & CU_NURB_BEZIER)) {
|
2012-04-29 15:47:02 +00:00
|
|
|
CLAMP(nu->orderv, 3, 4);
|
2013-11-26 06:39:14 +11:00
|
|
|
changed = true;
|
2008-05-26 09:50:46 +00:00
|
|
|
}
|
2013-11-26 06:39:14 +11:00
|
|
|
return changed;
|
2008-05-26 09:50:46 +00:00
|
|
|
}
|
|
|
|
|
2014-05-26 09:11:42 +10:00
|
|
|
/**
|
|
|
|
* \note caller must ensure active vertex remains valid.
|
|
|
|
*/
|
2013-03-20 15:01:15 +00:00
|
|
|
bool BKE_nurb_type_convert(Nurb *nu, const short type, const bool use_handles)
|
|
|
|
{
|
|
|
|
BezTriple *bezt;
|
|
|
|
BPoint *bp;
|
|
|
|
int a, c, nr;
|
|
|
|
|
|
|
|
if (nu->type == CU_POLY) {
|
|
|
|
if (type == CU_BEZIER) { /* to Bezier with vecthandles */
|
|
|
|
nr = nu->pntsu;
|
2018-01-14 22:14:20 +01:00
|
|
|
bezt = (BezTriple *)MEM_calloc_arrayN(nr, sizeof(BezTriple), "setsplinetype2");
|
2013-03-20 15:01:15 +00:00
|
|
|
nu->bezt = bezt;
|
|
|
|
a = nr;
|
|
|
|
bp = nu->bp;
|
|
|
|
while (a--) {
|
|
|
|
copy_v3_v3(bezt->vec[1], bp->vec);
|
|
|
|
bezt->f1 = bezt->f2 = bezt->f3 = bp->f1;
|
|
|
|
bezt->h1 = bezt->h2 = HD_VECT;
|
|
|
|
bezt->weight = bp->weight;
|
|
|
|
bezt->radius = bp->radius;
|
|
|
|
bp++;
|
|
|
|
bezt++;
|
|
|
|
}
|
|
|
|
MEM_freeN(nu->bp);
|
|
|
|
nu->bp = NULL;
|
|
|
|
nu->pntsu = nr;
|
2017-10-14 17:54:43 +11:00
|
|
|
nu->pntsv = 0;
|
2013-03-20 15:01:15 +00:00
|
|
|
nu->type = CU_BEZIER;
|
|
|
|
BKE_nurb_handles_calc(nu);
|
|
|
|
}
|
|
|
|
else if (type == CU_NURBS) {
|
|
|
|
nu->type = CU_NURBS;
|
|
|
|
nu->orderu = 4;
|
|
|
|
nu->flagu &= CU_NURB_CYCLIC; /* disable all flags except for cyclic */
|
|
|
|
BKE_nurb_knot_calc_u(nu);
|
|
|
|
a = nu->pntsu * nu->pntsv;
|
|
|
|
bp = nu->bp;
|
|
|
|
while (a--) {
|
|
|
|
bp->vec[3] = 1.0;
|
|
|
|
bp++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (nu->type == CU_BEZIER) { /* Bezier */
|
|
|
|
if (type == CU_POLY || type == CU_NURBS) {
|
|
|
|
nr = use_handles ? (3 * nu->pntsu) : nu->pntsu;
|
2018-01-14 22:14:20 +01:00
|
|
|
nu->bp = MEM_calloc_arrayN(nr, sizeof(BPoint), "setsplinetype");
|
2013-03-20 15:01:15 +00:00
|
|
|
a = nu->pntsu;
|
|
|
|
bezt = nu->bezt;
|
|
|
|
bp = nu->bp;
|
|
|
|
while (a--) {
|
|
|
|
if ((type == CU_POLY && bezt->h1 == HD_VECT && bezt->h2 == HD_VECT) || (use_handles == false)) {
|
|
|
|
/* vector handle becomes 1 poly vertice */
|
|
|
|
copy_v3_v3(bp->vec, bezt->vec[1]);
|
|
|
|
bp->vec[3] = 1.0;
|
|
|
|
bp->f1 = bezt->f2;
|
|
|
|
if (use_handles) nr -= 2;
|
|
|
|
bp->radius = bezt->radius;
|
|
|
|
bp->weight = bezt->weight;
|
|
|
|
bp++;
|
|
|
|
}
|
|
|
|
else {
|
2014-04-27 00:20:13 +10:00
|
|
|
const char *f = &bezt->f1;
|
2013-03-20 15:01:15 +00:00
|
|
|
for (c = 0; c < 3; c++, f++) {
|
|
|
|
copy_v3_v3(bp->vec, bezt->vec[c]);
|
|
|
|
bp->vec[3] = 1.0;
|
|
|
|
bp->f1 = *f;
|
|
|
|
bp->radius = bezt->radius;
|
|
|
|
bp->weight = bezt->weight;
|
|
|
|
bp++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bezt++;
|
|
|
|
}
|
|
|
|
MEM_freeN(nu->bezt);
|
|
|
|
nu->bezt = NULL;
|
|
|
|
nu->pntsu = nr;
|
|
|
|
nu->pntsv = 1;
|
|
|
|
nu->orderu = 4;
|
|
|
|
nu->orderv = 1;
|
|
|
|
nu->type = type;
|
|
|
|
|
|
|
|
if (type == CU_NURBS) {
|
|
|
|
nu->flagu &= CU_NURB_CYCLIC; /* disable all flags except for cyclic */
|
|
|
|
nu->flagu |= CU_NURB_BEZIER;
|
|
|
|
BKE_nurb_knot_calc_u(nu);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (nu->type == CU_NURBS) {
|
|
|
|
if (type == CU_POLY) {
|
|
|
|
nu->type = CU_POLY;
|
|
|
|
if (nu->knotsu) MEM_freeN(nu->knotsu); /* python created nurbs have a knotsu of zero */
|
|
|
|
nu->knotsu = NULL;
|
|
|
|
if (nu->knotsv) MEM_freeN(nu->knotsv);
|
|
|
|
nu->knotsv = NULL;
|
|
|
|
}
|
|
|
|
else if (type == CU_BEZIER) { /* to Bezier */
|
|
|
|
nr = nu->pntsu / 3;
|
|
|
|
|
|
|
|
if (nr < 2) {
|
|
|
|
return false; /* conversion impossible */
|
|
|
|
}
|
|
|
|
else {
|
2018-01-14 22:14:20 +01:00
|
|
|
bezt = MEM_calloc_arrayN(nr, sizeof(BezTriple), "setsplinetype2");
|
2013-03-20 15:01:15 +00:00
|
|
|
nu->bezt = bezt;
|
|
|
|
a = nr;
|
|
|
|
bp = nu->bp;
|
|
|
|
while (a--) {
|
|
|
|
copy_v3_v3(bezt->vec[0], bp->vec);
|
|
|
|
bezt->f1 = bp->f1;
|
|
|
|
bp++;
|
|
|
|
copy_v3_v3(bezt->vec[1], bp->vec);
|
|
|
|
bezt->f2 = bp->f1;
|
|
|
|
bp++;
|
|
|
|
copy_v3_v3(bezt->vec[2], bp->vec);
|
|
|
|
bezt->f3 = bp->f1;
|
|
|
|
bezt->radius = bp->radius;
|
|
|
|
bezt->weight = bp->weight;
|
|
|
|
bp++;
|
|
|
|
bezt++;
|
|
|
|
}
|
|
|
|
MEM_freeN(nu->bp);
|
|
|
|
nu->bp = NULL;
|
|
|
|
MEM_freeN(nu->knotsu);
|
|
|
|
nu->knotsu = NULL;
|
|
|
|
nu->pntsu = nr;
|
|
|
|
nu->type = CU_BEZIER;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-07-25 11:57:36 +00:00
|
|
|
/* Get edit nurbs or normal nurbs list */
|
2012-04-28 16:49:00 +00:00
|
|
|
ListBase *BKE_curve_nurbs_get(Curve *cu)
|
2010-07-25 11:57:36 +00:00
|
|
|
{
|
|
|
|
if (cu->editnurb) {
|
2012-04-28 16:49:00 +00:00
|
|
|
return BKE_curve_editNurbs_get(cu);
|
2010-07-25 11:57:36 +00:00
|
|
|
}
|
2008-05-26 09:50:46 +00:00
|
|
|
|
2010-07-25 11:57:36 +00:00
|
|
|
return &cu->nurb;
|
|
|
|
}
|
2010-08-01 11:00:36 +00:00
|
|
|
|
2015-07-09 13:14:09 +10:00
|
|
|
void BKE_curve_nurb_active_set(Curve *cu, const Nurb *nu)
|
2014-01-27 15:18:40 +11:00
|
|
|
{
|
|
|
|
if (nu == NULL) {
|
2014-05-26 09:17:00 +10:00
|
|
|
cu->actnu = CU_ACT_NONE;
|
2014-01-27 15:18:40 +11:00
|
|
|
}
|
|
|
|
else {
|
2016-04-04 17:55:28 +10:00
|
|
|
BLI_assert(!nu->hide);
|
2014-01-27 15:18:40 +11:00
|
|
|
ListBase *nurbs = BKE_curve_editNurbs_get(cu);
|
|
|
|
cu->actnu = BLI_findindex(nurbs, nu);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Nurb *BKE_curve_nurb_active_get(Curve *cu)
|
|
|
|
{
|
|
|
|
ListBase *nurbs = BKE_curve_editNurbs_get(cu);
|
|
|
|
return BLI_findlink(nurbs, cu->actnu);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get active vert for curve */
|
|
|
|
void *BKE_curve_vert_active_get(Curve *cu)
|
|
|
|
{
|
|
|
|
Nurb *nu = NULL;
|
|
|
|
void *vert = NULL;
|
|
|
|
|
|
|
|
BKE_curve_nurb_vert_active_get(cu, &nu, &vert);
|
|
|
|
return vert;
|
|
|
|
}
|
|
|
|
|
2015-07-09 13:14:09 +10:00
|
|
|
int BKE_curve_nurb_vert_index_get(const Nurb *nu, const void *vert)
|
|
|
|
{
|
|
|
|
if (nu->type == CU_BEZIER) {
|
|
|
|
BLI_assert(ARRAY_HAS_ITEM((BezTriple *)vert, nu->bezt, nu->pntsu));
|
|
|
|
return (BezTriple *)vert - nu->bezt;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
BLI_assert(ARRAY_HAS_ITEM((BPoint *)vert, nu->bp, nu->pntsu * nu->pntsv));
|
|
|
|
return (BPoint *)vert - nu->bp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-27 15:18:40 +11:00
|
|
|
/* Set active nurb and active vert for curve */
|
2015-07-09 13:14:09 +10:00
|
|
|
void BKE_curve_nurb_vert_active_set(Curve *cu, const Nurb *nu, const void *vert)
|
2014-01-27 15:18:40 +11:00
|
|
|
{
|
|
|
|
if (nu) {
|
|
|
|
BKE_curve_nurb_active_set(cu, nu);
|
|
|
|
|
2014-05-26 09:11:42 +10:00
|
|
|
if (vert) {
|
2015-07-09 13:14:09 +10:00
|
|
|
cu->actvert = BKE_curve_nurb_vert_index_get(nu, vert);
|
2014-01-27 15:18:40 +11:00
|
|
|
}
|
|
|
|
else {
|
2014-05-26 09:11:42 +10:00
|
|
|
cu->actvert = CU_ACT_NONE;
|
2014-01-27 15:18:40 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
cu->actnu = cu->actvert = CU_ACT_NONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get points to active active nurb and active vert for curve */
|
|
|
|
bool BKE_curve_nurb_vert_active_get(Curve *cu, Nurb **r_nu, void **r_vert)
|
|
|
|
{
|
|
|
|
Nurb *nu = NULL;
|
|
|
|
void *vert = NULL;
|
|
|
|
|
|
|
|
if (cu->actvert != CU_ACT_NONE) {
|
|
|
|
ListBase *nurbs = BKE_curve_editNurbs_get(cu);
|
|
|
|
nu = BLI_findlink(nurbs, cu->actnu);
|
|
|
|
|
|
|
|
if (nu) {
|
|
|
|
if (nu->type == CU_BEZIER) {
|
|
|
|
BLI_assert(nu->pntsu > cu->actvert);
|
|
|
|
vert = &nu->bezt[cu->actvert];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
BLI_assert((nu->pntsu * nu->pntsv) > cu->actvert);
|
|
|
|
vert = &nu->bp[cu->actvert];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*r_nu = nu;
|
|
|
|
*r_vert = vert;
|
|
|
|
|
|
|
|
return (*r_vert != NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BKE_curve_nurb_vert_active_validate(Curve *cu)
|
|
|
|
{
|
|
|
|
Nurb *nu;
|
|
|
|
void *vert;
|
|
|
|
|
|
|
|
if (BKE_curve_nurb_vert_active_get(cu, &nu, &vert)) {
|
|
|
|
if (nu->type == CU_BEZIER) {
|
2015-07-09 14:52:01 +10:00
|
|
|
BezTriple *bezt = vert;
|
|
|
|
if (BEZT_ISSEL_ANY(bezt) == 0) {
|
2014-01-27 15:18:40 +11:00
|
|
|
cu->actvert = CU_ACT_NONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2015-07-09 14:52:01 +10:00
|
|
|
BPoint *bp = vert;
|
|
|
|
if ((bp->f1 & SELECT) == 0) {
|
2014-01-27 15:18:40 +11:00
|
|
|
cu->actvert = CU_ACT_NONE;
|
|
|
|
}
|
|
|
|
}
|
2016-04-04 17:55:28 +10:00
|
|
|
|
|
|
|
if (nu->hide) {
|
|
|
|
cu->actnu = CU_ACT_NONE;
|
|
|
|
}
|
2014-01-27 15:18:40 +11:00
|
|
|
}
|
|
|
|
}
|
2010-08-01 11:00:36 +00:00
|
|
|
|
|
|
|
/* basic vertex data functions */
|
Move curve's boundbox and texspace calculation out of modifier stack
There were several issues with how bounding box and texture space
are calculated:
- This was done at the same time as applying modifiers, meaning if
several objects are sharing the same curve datablock, bounding
box and texture space will be calculated multiple times.
Further, allocating bounding box wasn't safe for threading.
- Bounding box and texture space were evaluated after pre-tessellation
modifiers are applied. This means Curve-level data is actually
depends on object data, and it's really bad because different
objects could have different modifiers and this leads to
conflicts (curve's data depends on object evaluation order)
and doesn't behave in a predictable way.
This commit moves bounding box and texture space evaluation from
modifier stack to own utility functions, just like it's was done
for meshes.
This makes curve objects update thread-safe, but gives some
limitations as well. Namely, with such approach it's not so
clear how to preserve the same behavior of texture space:
before this change texture space and bounding box would match
beveled curve as accurate as possible.
Old behavior was nice for quick texturing -- in most cases you
didn't need to modify texture space at all. But texture space
was depending on render/preview settings which could easily lead
to situations, when final result would be far different from
preview one.
Now we're using CV points coordinates and their radius to approximate
the bounding box. This doesn't give the same exact texture space,
but it helps a lot keeping texture space in a nice predictable way.
We could make approximation smarter in the future, but fir now
added operator to match texture space to fully tessellated curve
called "Match Texture Space".
Review link:
https://codereview.appspot.com/15410043/
Brief description:
http://wiki.blender.org/index.php/User:Nazg-gul/GSoC-2013/Results#Curve_Texture_Space
2013-10-20 14:41:33 +02:00
|
|
|
bool BKE_curve_minmax(Curve *cu, bool use_radius, float min[3], float max[3])
|
2010-08-01 11:00:36 +00:00
|
|
|
{
|
2012-05-06 15:15:33 +00:00
|
|
|
ListBase *nurb_lb = BKE_curve_nurbs_get(cu);
|
2017-12-19 15:08:29 +01:00
|
|
|
ListBase temp_nurb_lb = {NULL, NULL};
|
|
|
|
const bool is_font = (BLI_listbase_is_empty(nurb_lb)) && (cu->len != 0);
|
|
|
|
/* For font curves we generate temp list of splines.
|
|
|
|
*
|
|
|
|
* This is likely to be fine, this function is not supposed to be called
|
|
|
|
* often, and it's the only way to get meaningful bounds for fonts.
|
|
|
|
*/
|
|
|
|
if (is_font) {
|
|
|
|
nurb_lb = &temp_nurb_lb;
|
2018-06-12 15:03:51 +02:00
|
|
|
BKE_vfont_to_curve_ex(NULL, cu, FO_EDIT, nurb_lb,
|
2017-12-19 15:08:29 +01:00
|
|
|
NULL, NULL, NULL, NULL);
|
|
|
|
use_radius = false;
|
|
|
|
}
|
|
|
|
/* Do bounding box based on splines. */
|
|
|
|
for (Nurb *nu = nurb_lb->first; nu; nu = nu->next) {
|
Move curve's boundbox and texspace calculation out of modifier stack
There were several issues with how bounding box and texture space
are calculated:
- This was done at the same time as applying modifiers, meaning if
several objects are sharing the same curve datablock, bounding
box and texture space will be calculated multiple times.
Further, allocating bounding box wasn't safe for threading.
- Bounding box and texture space were evaluated after pre-tessellation
modifiers are applied. This means Curve-level data is actually
depends on object data, and it's really bad because different
objects could have different modifiers and this leads to
conflicts (curve's data depends on object evaluation order)
and doesn't behave in a predictable way.
This commit moves bounding box and texture space evaluation from
modifier stack to own utility functions, just like it's was done
for meshes.
This makes curve objects update thread-safe, but gives some
limitations as well. Namely, with such approach it's not so
clear how to preserve the same behavior of texture space:
before this change texture space and bounding box would match
beveled curve as accurate as possible.
Old behavior was nice for quick texturing -- in most cases you
didn't need to modify texture space at all. But texture space
was depending on render/preview settings which could easily lead
to situations, when final result would be far different from
preview one.
Now we're using CV points coordinates and their radius to approximate
the bounding box. This doesn't give the same exact texture space,
but it helps a lot keeping texture space in a nice predictable way.
We could make approximation smarter in the future, but fir now
added operator to match texture space to fully tessellated curve
called "Match Texture Space".
Review link:
https://codereview.appspot.com/15410043/
Brief description:
http://wiki.blender.org/index.php/User:Nazg-gul/GSoC-2013/Results#Curve_Texture_Space
2013-10-20 14:41:33 +02:00
|
|
|
BKE_nurb_minmax(nu, use_radius, min, max);
|
2017-12-19 15:08:29 +01:00
|
|
|
}
|
|
|
|
const bool result = (BLI_listbase_is_empty(nurb_lb) == false);
|
|
|
|
/* Cleanup if needed. */
|
|
|
|
BKE_nurbList_free(&temp_nurb_lb);
|
|
|
|
return result;
|
2010-08-01 11:00:36 +00:00
|
|
|
}
|
|
|
|
|
2013-03-09 05:35:49 +00:00
|
|
|
bool BKE_curve_center_median(Curve *cu, float cent[3])
|
2010-08-01 11:00:36 +00:00
|
|
|
{
|
2012-05-06 15:15:33 +00:00
|
|
|
ListBase *nurb_lb = BKE_curve_nurbs_get(cu);
|
2010-08-01 11:00:36 +00:00
|
|
|
Nurb *nu;
|
2012-05-06 15:15:33 +00:00
|
|
|
int total = 0;
|
2010-08-01 11:00:36 +00:00
|
|
|
|
|
|
|
zero_v3(cent);
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
for (nu = nurb_lb->first; nu; nu = nu->next) {
|
2010-08-01 11:00:36 +00:00
|
|
|
int i;
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (nu->type == CU_BEZIER) {
|
2010-08-01 11:00:36 +00:00
|
|
|
BezTriple *bezt;
|
2012-05-06 15:15:33 +00:00
|
|
|
i = nu->pntsu;
|
2010-08-01 11:00:36 +00:00
|
|
|
total += i * 3;
|
2012-05-06 15:15:33 +00:00
|
|
|
for (bezt = nu->bezt; i--; bezt++) {
|
2010-08-01 11:00:36 +00:00
|
|
|
add_v3_v3(cent, bezt->vec[0]);
|
|
|
|
add_v3_v3(cent, bezt->vec[1]);
|
|
|
|
add_v3_v3(cent, bezt->vec[2]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
BPoint *bp;
|
2012-05-06 15:15:33 +00:00
|
|
|
i = nu->pntsu * nu->pntsv;
|
2010-08-01 11:00:36 +00:00
|
|
|
total += i;
|
2012-05-06 15:15:33 +00:00
|
|
|
for (bp = nu->bp; i--; bp++) {
|
2010-08-01 11:00:36 +00:00
|
|
|
add_v3_v3(cent, bp->vec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-06 02:48:03 +00:00
|
|
|
if (total) {
|
|
|
|
mul_v3_fl(cent, 1.0f / (float)total);
|
|
|
|
}
|
2010-08-01 11:00:36 +00:00
|
|
|
|
|
|
|
return (total != 0);
|
|
|
|
}
|
|
|
|
|
2013-03-09 05:35:49 +00:00
|
|
|
bool BKE_curve_center_bounds(Curve *cu, float cent[3])
|
2010-08-01 11:00:36 +00:00
|
|
|
{
|
|
|
|
float min[3], max[3];
|
2010-08-03 00:56:43 +00:00
|
|
|
INIT_MINMAX(min, max);
|
Move curve's boundbox and texspace calculation out of modifier stack
There were several issues with how bounding box and texture space
are calculated:
- This was done at the same time as applying modifiers, meaning if
several objects are sharing the same curve datablock, bounding
box and texture space will be calculated multiple times.
Further, allocating bounding box wasn't safe for threading.
- Bounding box and texture space were evaluated after pre-tessellation
modifiers are applied. This means Curve-level data is actually
depends on object data, and it's really bad because different
objects could have different modifiers and this leads to
conflicts (curve's data depends on object evaluation order)
and doesn't behave in a predictable way.
This commit moves bounding box and texture space evaluation from
modifier stack to own utility functions, just like it's was done
for meshes.
This makes curve objects update thread-safe, but gives some
limitations as well. Namely, with such approach it's not so
clear how to preserve the same behavior of texture space:
before this change texture space and bounding box would match
beveled curve as accurate as possible.
Old behavior was nice for quick texturing -- in most cases you
didn't need to modify texture space at all. But texture space
was depending on render/preview settings which could easily lead
to situations, when final result would be far different from
preview one.
Now we're using CV points coordinates and their radius to approximate
the bounding box. This doesn't give the same exact texture space,
but it helps a lot keeping texture space in a nice predictable way.
We could make approximation smarter in the future, but fir now
added operator to match texture space to fully tessellated curve
called "Match Texture Space".
Review link:
https://codereview.appspot.com/15410043/
Brief description:
http://wiki.blender.org/index.php/User:Nazg-gul/GSoC-2013/Results#Curve_Texture_Space
2013-10-20 14:41:33 +02:00
|
|
|
if (BKE_curve_minmax(cu, false, min, max)) {
|
2010-08-01 11:00:36 +00:00
|
|
|
mid_v3_v3v3(cent, min, max);
|
2013-03-09 05:35:49 +00:00
|
|
|
return true;
|
2010-08-01 11:00:36 +00:00
|
|
|
}
|
|
|
|
|
2013-03-09 05:35:49 +00:00
|
|
|
return false;
|
2010-08-01 11:00:36 +00:00
|
|
|
}
|
|
|
|
|
2014-09-01 20:09:31 +10:00
|
|
|
|
2017-08-11 22:16:44 +10:00
|
|
|
void BKE_curve_transform_ex(
|
|
|
|
Curve *cu, float mat[4][4],
|
|
|
|
const bool do_keys, const bool do_props, const float unit_scale)
|
2014-09-01 20:09:31 +10:00
|
|
|
{
|
|
|
|
Nurb *nu;
|
|
|
|
BPoint *bp;
|
|
|
|
BezTriple *bezt;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (nu = cu->nurb.first; nu; nu = nu->next) {
|
|
|
|
if (nu->type == CU_BEZIER) {
|
|
|
|
i = nu->pntsu;
|
|
|
|
for (bezt = nu->bezt; i--; bezt++) {
|
|
|
|
mul_m4_v3(mat, bezt->vec[0]);
|
|
|
|
mul_m4_v3(mat, bezt->vec[1]);
|
|
|
|
mul_m4_v3(mat, bezt->vec[2]);
|
2017-08-11 22:16:44 +10:00
|
|
|
if (do_props) {
|
|
|
|
bezt->radius *= unit_scale;
|
|
|
|
}
|
2014-09-01 20:09:31 +10:00
|
|
|
}
|
|
|
|
BKE_nurb_handles_calc(nu);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
i = nu->pntsu * nu->pntsv;
|
2015-06-08 12:58:50 +10:00
|
|
|
for (bp = nu->bp; i--; bp++) {
|
2014-09-01 20:09:31 +10:00
|
|
|
mul_m4_v3(mat, bp->vec);
|
2017-08-11 22:16:44 +10:00
|
|
|
if (do_props) {
|
|
|
|
bp->radius *= unit_scale;
|
|
|
|
}
|
2015-06-08 12:58:50 +10:00
|
|
|
}
|
2014-09-01 20:09:31 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (do_keys && cu->key) {
|
|
|
|
KeyBlock *kb;
|
|
|
|
for (kb = cu->key->block.first; kb; kb = kb->next) {
|
|
|
|
float *fp = kb->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
|
|
|
int n = kb->totelem;
|
|
|
|
|
|
|
|
for (nu = cu->nurb.first; nu; nu = nu->next) {
|
|
|
|
if (nu->type == CU_BEZIER) {
|
|
|
|
for (i = nu->pntsu; i && (n -= KEYELEM_ELEM_LEN_BEZTRIPLE) >= 0; i--) {
|
|
|
|
mul_m4_v3(mat, &fp[0]);
|
|
|
|
mul_m4_v3(mat, &fp[3]);
|
|
|
|
mul_m4_v3(mat, &fp[6]);
|
|
|
|
if (do_props) {
|
|
|
|
fp[10] *= unit_scale; /* radius */
|
|
|
|
}
|
|
|
|
fp += KEYELEM_FLOAT_LEN_BEZTRIPLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
for (i = nu->pntsu * nu->pntsv; i && (n -= KEYELEM_ELEM_LEN_BPOINT) >= 0; i--) {
|
|
|
|
mul_m4_v3(mat, fp);
|
|
|
|
if (do_props) {
|
|
|
|
fp[4] *= unit_scale; /* radius */
|
|
|
|
}
|
|
|
|
fp += KEYELEM_FLOAT_LEN_BPOINT;
|
|
|
|
}
|
|
|
|
}
|
2014-09-01 20:09:31 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-11 22:16:44 +10:00
|
|
|
void BKE_curve_transform(
|
|
|
|
Curve *cu, float mat[4][4],
|
|
|
|
const bool do_keys, const bool do_props)
|
2014-09-01 20:09:31 +10:00
|
|
|
{
|
|
|
|
float unit_scale = mat4_to_scale(mat);
|
2017-08-11 22:16:44 +10:00
|
|
|
BKE_curve_transform_ex(cu, mat, do_keys, do_props, unit_scale);
|
2014-09-01 20:09:31 +10:00
|
|
|
}
|
|
|
|
|
2014-10-31 16:17:02 +01:00
|
|
|
void BKE_curve_translate(Curve *cu, float offset[3], const bool do_keys)
|
2010-08-01 11:00:36 +00:00
|
|
|
{
|
2012-05-06 15:15:33 +00:00
|
|
|
ListBase *nurb_lb = BKE_curve_nurbs_get(cu);
|
2010-08-01 11:00:36 +00:00
|
|
|
Nurb *nu;
|
|
|
|
int i;
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
for (nu = nurb_lb->first; nu; nu = nu->next) {
|
2010-08-01 11:00:36 +00:00
|
|
|
BezTriple *bezt;
|
|
|
|
BPoint *bp;
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (nu->type == CU_BEZIER) {
|
2012-05-06 15:15:33 +00:00
|
|
|
i = nu->pntsu;
|
|
|
|
for (bezt = nu->bezt; i--; bezt++) {
|
2010-08-01 11:00:36 +00:00
|
|
|
add_v3_v3(bezt->vec[0], offset);
|
|
|
|
add_v3_v3(bezt->vec[1], offset);
|
|
|
|
add_v3_v3(bezt->vec[2], offset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2012-05-06 15:15:33 +00:00
|
|
|
i = nu->pntsu * nu->pntsv;
|
|
|
|
for (bp = nu->bp; i--; bp++) {
|
2010-08-01 11:00:36 +00:00
|
|
|
add_v3_v3(bp->vec, offset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (do_keys && cu->key) {
|
|
|
|
KeyBlock *kb;
|
2012-05-06 15:15:33 +00:00
|
|
|
for (kb = cu->key->block.first; kb; kb = kb->next) {
|
|
|
|
float *fp = kb->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
|
|
|
int n = kb->totelem;
|
|
|
|
|
|
|
|
for (nu = cu->nurb.first; nu; nu = nu->next) {
|
|
|
|
if (nu->type == CU_BEZIER) {
|
|
|
|
for (i = nu->pntsu; i && (n -= KEYELEM_ELEM_LEN_BEZTRIPLE) >= 0; i--) {
|
|
|
|
add_v3_v3(&fp[0], offset);
|
|
|
|
add_v3_v3(&fp[3], offset);
|
|
|
|
add_v3_v3(&fp[6], offset);
|
|
|
|
fp += KEYELEM_FLOAT_LEN_BEZTRIPLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
for (i = nu->pntsu * nu->pntsv; i && (n -= KEYELEM_ELEM_LEN_BPOINT) >= 0; i--) {
|
|
|
|
add_v3_v3(fp, offset);
|
|
|
|
fp += KEYELEM_FLOAT_LEN_BPOINT;
|
|
|
|
}
|
|
|
|
}
|
2010-08-01 11:00:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-07-31 12:43:41 +00:00
|
|
|
|
2013-08-14 11:29:58 +00:00
|
|
|
void BKE_curve_material_index_remove(Curve *cu, int index)
|
2011-07-31 12:43:41 +00:00
|
|
|
{
|
2012-05-06 15:15:33 +00:00
|
|
|
const int curvetype = BKE_curve_type_get(cu);
|
2011-07-31 12:43:41 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (curvetype == OB_FONT) {
|
2012-05-06 15:15:33 +00:00
|
|
|
struct CharInfo *info = cu->strinfo;
|
2011-07-31 12:43:41 +00:00
|
|
|
int i;
|
2014-01-03 17:04:42 +11:00
|
|
|
for (i = cu->len_wchar - 1; i >= 0; i--, info++) {
|
2012-05-06 15:15:33 +00:00
|
|
|
if (info->mat_nr && info->mat_nr >= index) {
|
2011-07-31 12:43:41 +00:00
|
|
|
info->mat_nr--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Nurb *nu;
|
|
|
|
|
2012-05-06 15:15:33 +00:00
|
|
|
for (nu = cu->nurb.first; nu; nu = nu->next) {
|
|
|
|
if (nu->mat_nr && nu->mat_nr >= index) {
|
2011-07-31 12:43:41 +00:00
|
|
|
nu->mat_nr--;
|
2013-08-14 11:29:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BKE_curve_material_index_clear(Curve *cu)
|
|
|
|
{
|
|
|
|
const int curvetype = BKE_curve_type_get(cu);
|
|
|
|
|
|
|
|
if (curvetype == OB_FONT) {
|
|
|
|
struct CharInfo *info = cu->strinfo;
|
|
|
|
int i;
|
2014-01-03 17:04:42 +11:00
|
|
|
for (i = cu->len_wchar - 1; i >= 0; i--, info++) {
|
2013-08-14 11:29:58 +00:00
|
|
|
info->mat_nr = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Nurb *nu;
|
|
|
|
|
|
|
|
for (nu = cu->nurb.first; nu; nu = nu->next) {
|
|
|
|
nu->mat_nr = 0;
|
2011-07-31 12:43:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-03-11 17:12:18 +11:00
|
|
|
|
2018-07-01 15:47:09 +02:00
|
|
|
bool BKE_curve_material_index_validate(Curve *cu)
|
2014-07-17 17:12:12 +02:00
|
|
|
{
|
|
|
|
const int curvetype = BKE_curve_type_get(cu);
|
|
|
|
bool is_valid = true;
|
|
|
|
|
|
|
|
if (curvetype == OB_FONT) {
|
|
|
|
CharInfo *info = cu->strinfo;
|
|
|
|
const int max_idx = max_ii(0, cu->totcol); /* OB_FONT use 1 as first mat index, not 0!!! */
|
|
|
|
int i;
|
|
|
|
for (i = cu->len_wchar - 1; i >= 0; i--, info++) {
|
|
|
|
if (info->mat_nr > max_idx) {
|
|
|
|
info->mat_nr = 0;
|
|
|
|
is_valid = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Nurb *nu;
|
|
|
|
const int max_idx = max_ii(0, cu->totcol - 1);
|
|
|
|
for (nu = cu->nurb.first; nu; nu = nu->next) {
|
|
|
|
if (nu->mat_nr > max_idx) {
|
|
|
|
nu->mat_nr = 0;
|
|
|
|
is_valid = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!is_valid) {
|
2017-04-06 16:11:50 +02:00
|
|
|
DEG_id_tag_update(&cu->id, OB_RECALC_DATA);
|
2014-07-17 17:12:12 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-28 07:24:56 +10:00
|
|
|
void BKE_curve_material_remap(Curve *cu, const unsigned int *remap, unsigned int remap_len)
|
|
|
|
{
|
|
|
|
const int curvetype = BKE_curve_type_get(cu);
|
|
|
|
const short remap_len_short = (short)remap_len;
|
|
|
|
|
|
|
|
#define MAT_NR_REMAP(n) \
|
|
|
|
if (n < remap_len_short) { \
|
|
|
|
BLI_assert(n >= 0 && remap[n] < remap_len_short); \
|
|
|
|
n = remap[n]; \
|
|
|
|
} ((void)0)
|
|
|
|
|
|
|
|
if (curvetype == OB_FONT) {
|
|
|
|
struct CharInfo *strinfo;
|
|
|
|
int charinfo_len, i;
|
|
|
|
|
|
|
|
if (cu->editfont) {
|
|
|
|
EditFont *ef = cu->editfont;
|
|
|
|
strinfo = ef->textbufinfo;
|
|
|
|
charinfo_len = ef->len;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
strinfo = cu->strinfo;
|
|
|
|
charinfo_len = cu->len_wchar;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i <= charinfo_len; i++) {
|
|
|
|
if (strinfo[i].mat_nr > 0) {
|
|
|
|
strinfo[i].mat_nr -= 1;
|
|
|
|
MAT_NR_REMAP(strinfo[i].mat_nr);
|
|
|
|
strinfo[i].mat_nr += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Nurb *nu;
|
|
|
|
ListBase *nurbs = BKE_curve_editNurbs_get(cu);
|
|
|
|
|
|
|
|
if (nurbs) {
|
|
|
|
for (nu = nurbs->first; nu; nu = nu->next) {
|
|
|
|
MAT_NR_REMAP(nu->mat_nr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef MAT_NR_REMAP
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-03-11 17:12:18 +11:00
|
|
|
void BKE_curve_rect_from_textbox(const struct Curve *cu, const struct TextBox *tb, struct rctf *r_rect)
|
|
|
|
{
|
2014-05-16 10:27:52 +10:00
|
|
|
r_rect->xmin = cu->xof + tb->x;
|
|
|
|
r_rect->ymax = cu->yof + tb->y + cu->fsize;
|
2014-03-11 17:12:18 +11:00
|
|
|
|
|
|
|
r_rect->xmax = r_rect->xmin + tb->w;
|
|
|
|
r_rect->ymin = r_rect->ymax - tb->h;
|
|
|
|
}
|
2015-05-12 13:57:11 +05:00
|
|
|
|
|
|
|
/* **** Depsgraph evaluation **** */
|
|
|
|
|
2018-05-02 11:46:56 +02:00
|
|
|
void BKE_curve_eval_geometry(Depsgraph *depsgraph,
|
2015-05-12 13:57:11 +05:00
|
|
|
Curve *curve)
|
|
|
|
{
|
2018-05-02 11:46:56 +02:00
|
|
|
DEG_debug_print_eval(depsgraph, __func__, curve->id.name, curve);
|
2015-05-12 13:57:11 +05:00
|
|
|
if (curve->bb == NULL || (curve->bb->flag & BOUNDBOX_DIRTY)) {
|
|
|
|
BKE_curve_texspace_calc(curve);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-21 21:14:11 +10:00
|
|
|
/* Draw Engine */
|
2018-08-23 10:14:29 -03:00
|
|
|
void (*BKE_curve_batch_cache_dirty_tag_cb)(Curve *cu, int mode) = NULL;
|
2017-04-21 21:14:11 +10:00
|
|
|
void (*BKE_curve_batch_cache_free_cb)(Curve *cu) = NULL;
|
|
|
|
|
2018-08-23 10:14:29 -03:00
|
|
|
void BKE_curve_batch_cache_dirty_tag(Curve *cu, int mode)
|
2017-04-21 21:14:11 +10:00
|
|
|
{
|
|
|
|
if (cu->batch_cache) {
|
2018-08-23 10:14:29 -03:00
|
|
|
BKE_curve_batch_cache_dirty_tag_cb(cu, mode);
|
2017-04-21 21:14:11 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
void BKE_curve_batch_cache_free(Curve *cu)
|
|
|
|
{
|
|
|
|
if (cu->batch_cache) {
|
|
|
|
BKE_curve_batch_cache_free_cb(cu);
|
|
|
|
}
|
2017-07-21 11:53:13 +02:00
|
|
|
}
|