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>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
2011-01-07 18:36:47 +00:00
|
|
|
|
2011-10-27 05:34:39 +00:00
|
|
|
#include "BLI_bpath.h"
|
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
|
|
|
|
|
|
|
#include "DNA_curve_types.h"
|
|
|
|
#include "DNA_material_types.h"
|
|
|
|
|
|
|
|
/* for dereferencing pointers */
|
|
|
|
#include "DNA_key_types.h"
|
2009-01-04 14:14:06 +00:00
|
|
|
#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"
|
2009-01-04 14:14:06 +00:00
|
|
|
#include "BKE_anim.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "BKE_curve.h"
|
|
|
|
#include "BKE_displist.h"
|
2009-01-23 14:43:25 +00:00
|
|
|
#include "BKE_font.h"
|
2009-01-04 14:14:06 +00:00
|
|
|
#include "BKE_global.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "BKE_key.h"
|
2009-01-04 14:14:06 +00:00
|
|
|
#include "BKE_library.h"
|
|
|
|
#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
|
|
|
|
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-02-28 14:05:00 +00:00
|
|
|
float *labda, float *mu, float vec[3]);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-04-28 16:49:00 +00:00
|
|
|
void BKE_curve_unlink(Curve *cu)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
int a;
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
for (a=0; a<cu->totcol; a++) {
|
|
|
|
if (cu->mat[a]) cu->mat[a]->id.us--;
|
2010-09-29 06:24:05 +00:00
|
|
|
cu->mat[a]= NULL;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
if (cu->vfont) cu->vfont->id.us--;
|
2010-09-29 06:24:05 +00:00
|
|
|
cu->vfont= NULL;
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (cu->vfontb) cu->vfontb->id.us--;
|
2010-09-29 06:24:05 +00:00
|
|
|
cu->vfontb= NULL;
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (cu->vfonti) cu->vfonti->id.us--;
|
2010-09-29 06:24:05 +00:00
|
|
|
cu->vfonti= NULL;
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (cu->vfontbi) cu->vfontbi->id.us--;
|
2010-09-29 06:24:05 +00:00
|
|
|
cu->vfontbi= NULL;
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (cu->key) cu->key->id.us--;
|
2010-09-29 06:24:05 +00:00
|
|
|
cu->key= NULL;
|
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) {
|
2009-01-23 14:43:25 +00:00
|
|
|
EditFont *ef= cu->editfont;
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (ef->oldstr) MEM_freeN(ef->oldstr);
|
|
|
|
if (ef->oldstrinfo) MEM_freeN(ef->oldstrinfo);
|
|
|
|
if (ef->textbuf) MEM_freeN(ef->textbuf);
|
|
|
|
if (ef->textbufinfo) MEM_freeN(ef->textbufinfo);
|
|
|
|
if (ef->copybuf) MEM_freeN(ef->copybuf);
|
|
|
|
if (ef->copybufinfo) MEM_freeN(ef->copybufinfo);
|
2009-01-23 14:43:25 +00:00
|
|
|
|
|
|
|
MEM_freeN(ef);
|
|
|
|
cu->editfont= NULL;
|
|
|
|
}
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-04-28 16:49:00 +00:00
|
|
|
void BKE_curve_editNurb_keyIndex_free(EditNurb *editnurb)
|
2011-09-14 00:37:27 +00:00
|
|
|
{
|
|
|
|
if (!editnurb->keyindex) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
BLI_ghash_free(editnurb->keyindex, NULL, (GHashValFreeFP)MEM_freeN);
|
|
|
|
editnurb->keyindex= NULL;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
BKE_curve_editNurb_keyIndex_free(cu->editnurb);
|
2011-09-14 00:37:27 +00:00
|
|
|
MEM_freeN(cu->editnurb);
|
|
|
|
cu->editnurb= NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-23 14:43:25 +00:00
|
|
|
/* don't free curve itself */
|
2012-04-28 16:49:00 +00:00
|
|
|
void BKE_curve_free(Curve *cu)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2012-04-28 16:49:00 +00:00
|
|
|
BKE_nurbList_free(&cu->nurb);
|
2002-10-12 11:37:38 +00:00
|
|
|
BLI_freelistN(&cu->bev);
|
|
|
|
freedisplist(&cu->disp);
|
2012-04-28 16:49:00 +00:00
|
|
|
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);
|
|
|
|
BKE_curve_unlink(cu);
|
2009-01-18 10:41:45 +00:00
|
|
|
BKE_free_animdata((ID *)cu);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (cu->mat) MEM_freeN(cu->mat);
|
|
|
|
if (cu->str) MEM_freeN(cu->str);
|
|
|
|
if (cu->strinfo) MEM_freeN(cu->strinfo);
|
|
|
|
if (cu->bb) MEM_freeN(cu->bb);
|
|
|
|
if (cu->path) free_path(cu->path);
|
|
|
|
if (cu->tb) MEM_freeN(cu->tb);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2012-04-28 16:49:00 +00:00
|
|
|
Curve *BKE_curve_add(const char *name, int type)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
Curve *cu;
|
|
|
|
|
2012-05-05 14:03:12 +00:00
|
|
|
cu = BKE_libblock_alloc(&G.main->curve, ID_CU, name);
|
2012-03-23 20:18:09 +00:00
|
|
|
copy_v3_fl(cu->size, 1.0f);
|
2010-08-06 08:27:07 +00:00
|
|
|
cu->flag= CU_FRONT|CU_BACK|CU_DEFORM_BOUNDS_OFF|CU_PATH_RADIUS;
|
2002-10-12 11:37:38 +00:00
|
|
|
cu->pathlen= 100;
|
2010-12-20 07:45:24 +00:00
|
|
|
cu->resolu= cu->resolv= (type == OB_SURF) ? 4 : 12;
|
2002-10-12 11:37:38 +00:00
|
|
|
cu->width= 1.0;
|
2005-06-17 21:04:27 +00:00
|
|
|
cu->wordspace = 1.0;
|
2002-10-12 11:37:38 +00:00
|
|
|
cu->spacing= cu->linedist= 1.0;
|
|
|
|
cu->fsize= 1.0;
|
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
|
|
|
cu->ulheight = 0.05;
|
2004-03-14 16:59:48 +00:00
|
|
|
cu->texflag= CU_AUTOSPACE;
|
2010-07-13 22:21:59 +00:00
|
|
|
cu->smallcaps_scale= 0.75f;
|
2009-11-05 10:09:45 +00:00
|
|
|
cu->twist_mode= CU_TWIST_MINIMUM; // XXX: this one seems to be the best one in most cases, at least for curve deform...
|
2011-11-24 14:30:37 +00:00
|
|
|
cu->type= type;
|
2012-05-04 17:04:20 +00:00
|
|
|
cu->bevfac1= 0.0f;
|
|
|
|
cu->bevfac2= 1.0f;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-05-05 14:03:12 +00:00
|
|
|
cu->bb= BKE_boundbox_alloc_unit();
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (type==OB_FONT) {
|
2012-05-05 14:52:04 +00:00
|
|
|
cu->vfont= cu->vfontb= cu->vfonti= cu->vfontbi= BKE_vfont_builtin_get();
|
2009-01-23 14:43:25 +00:00
|
|
|
cu->vfont->id.us+=4;
|
|
|
|
cu->str= MEM_mallocN(12, "str");
|
2010-11-05 07:35:21 +00:00
|
|
|
BLI_strncpy(cu->str, "Text", 12);
|
2010-07-17 17:50:20 +00:00
|
|
|
cu->len= cu->pos= 4;
|
2009-06-15 09:54:37 +00:00
|
|
|
cu->strinfo= MEM_callocN(12*sizeof(CharInfo), "strinfo new");
|
2009-01-23 14:43:25 +00:00
|
|
|
cu->totbox= cu->actbox= 1;
|
|
|
|
cu->tb= MEM_callocN(MAXTEXTBOX*sizeof(TextBox), "textbox");
|
|
|
|
cu->tb[0].w = cu->tb[0].h = 0.0;
|
|
|
|
}
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
return cu;
|
|
|
|
}
|
|
|
|
|
2012-04-28 16:49:00 +00:00
|
|
|
Curve *BKE_curve_copy(Curve *cu)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
Curve *cun;
|
|
|
|
int a;
|
|
|
|
|
2012-05-05 14:03:12 +00:00
|
|
|
cun= BKE_libblock_copy(&cu->id);
|
2011-02-13 10:52:18 +00:00
|
|
|
cun->nurb.first= cun->nurb.last= NULL;
|
2012-04-29 17:11:40 +00:00
|
|
|
BKE_nurbList_duplicate(&(cun->nurb), &(cu->nurb));
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
cun->mat= MEM_dupallocN(cu->mat);
|
2012-03-24 06:18:31 +00:00
|
|
|
for (a=0; a<cun->totcol; a++) {
|
2002-10-12 11:37:38 +00:00
|
|
|
id_us_plus((ID *)cun->mat[a]);
|
|
|
|
}
|
|
|
|
|
|
|
|
cun->str= MEM_dupallocN(cu->str);
|
2005-06-17 21:04:27 +00:00
|
|
|
cun->strinfo= MEM_dupallocN(cu->strinfo);
|
|
|
|
cun->tb= MEM_dupallocN(cu->tb);
|
2002-10-12 11:37:38 +00:00
|
|
|
cun->bb= MEM_dupallocN(cu->bb);
|
|
|
|
|
2012-05-05 14:03:12 +00:00
|
|
|
cun->key= BKE_key_copy(cu->key);
|
2012-03-24 06:18:31 +00:00
|
|
|
if (cun->key) cun->key->from= (ID *)cun;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2011-02-13 10:52:18 +00:00
|
|
|
cun->disp.first= cun->disp.last= NULL;
|
|
|
|
cun->bev.first= cun->bev.last= NULL;
|
|
|
|
cun->path= NULL;
|
2002-10-12 11:37:38 +00: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
|
|
|
cun->editnurb= NULL;
|
2010-02-27 16:06:33 +00:00
|
|
|
cun->editfont= NULL;
|
2011-04-21 09:38:09 +00:00
|
|
|
cun->selboxes= NULL;
|
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
|
|
|
|
2.5: Blender "Animato" - New Animation System
Finally, here is the basic (functional) prototype of the new animation system which will allow for the infamous "everything is animatable", and which also addresses several of the more serious shortcomings of the old system. Unfortunately, this will break old animation files (especially right now, as I haven't written the version patching code yet), however, this is for the future.
Highlights of the new system:
* Scrapped IPO-Curves/IPO/(Action+Constraint-Channels)/Action system, and replaced it with F-Curve/Action.
- F-Curves (animators from other packages will feel at home with this name) replace IPO-Curves.
- The 'new' Actions, act as the containers for F-Curves, so that they can be reused. They are therefore more akin to the old 'IPO' blocks, except they do not have the blocktype restriction, so you can store materials/texture/geometry F-Curves in the same Action as Object transforms, etc.
* F-Curves use RNA-paths for Data Access, hence allowing "every" (where sensible/editable that is) user-accessible setting from RNA to be animated.
* Drivers are no longer mixed with Animation Data, so rigs will not be that easily broken and several dependency problems can be eliminated. (NOTE: drivers haven't been hooked up yet, but the code is in place)
* F-Curve modifier system allows useful 'large-scale' manipulation of F-Curve values, including (I've only included implemented ones here): envelope deform (similar to lattices to allow broad-scale reshaping of curves), curve generator (polynomial or py-expression), cycles (replacing the old cyclic extrapolation modes, giving more control over this). (NOTE: currently this cannot be tested, as there's not access to them, but the code is all in place)
* NLA system with 'tracks' (i.e. layers), and multiple strips per track. (NOTE: NLA system is not yet functional, as it's only partially coded still)
There are more nice things that I will be preparing some nice docs for soon, but for now, check for more details:
http://lists.blender.org/pipermail/bf-taskforce25/2009-January/000260.html
So, what currently works:
* I've implemented two basic operators for the 3D-view only to Insert and Delete Keyframes. These are tempolary ones only that will be replaced in due course with 'proper' code.
* Object Loc/Rot/Scale can be keyframed. Also, the colour of the 'active' material (Note: this should really be for nth material instead, but that doesn't work yet in RNA) can also be keyframed into the same datablock.
* Standard animation refresh (i.e. animation resulting from NLA and Action evaluation) is now done completely separate from drivers before anything else is done after a frame change. Drivers are handled after this in a separate pass, as dictated by depsgraph flags, etc.
Notes:
* Drivers haven't been hooked up yet
* Only objects and data directly linked to objects can be animated.
* Depsgraph will need further tweaks. Currently, I've only made sure that it will update some things in the most basic cases (i.e. frame change).
* Animation Editors are currently broken (in terms of editing stuff). This will be my next target (priority to get Dopesheet working first, then F-Curve editor - i.e. old IPO Editor)
* I've had to put in large chunks of XXX sandboxing for old animation system code all around the place. This will be cleaned up in due course, as some places need special review.
In particular, the particles and sequencer code have far too many manual calls to calculate + flush animation info, which is really bad (this is a 'please explain yourselves' call to Physics coders!).
2009-01-17 03:12:50 +00:00
|
|
|
#if 0 // XXX old animation system
|
2003-04-25 15:48:11 +00:00
|
|
|
/* single user ipo too */
|
2012-03-24 06:18:31 +00:00
|
|
|
if (cun->ipo) cun->ipo= copy_ipo(cun->ipo);
|
2.5: Blender "Animato" - New Animation System
Finally, here is the basic (functional) prototype of the new animation system which will allow for the infamous "everything is animatable", and which also addresses several of the more serious shortcomings of the old system. Unfortunately, this will break old animation files (especially right now, as I haven't written the version patching code yet), however, this is for the future.
Highlights of the new system:
* Scrapped IPO-Curves/IPO/(Action+Constraint-Channels)/Action system, and replaced it with F-Curve/Action.
- F-Curves (animators from other packages will feel at home with this name) replace IPO-Curves.
- The 'new' Actions, act as the containers for F-Curves, so that they can be reused. They are therefore more akin to the old 'IPO' blocks, except they do not have the blocktype restriction, so you can store materials/texture/geometry F-Curves in the same Action as Object transforms, etc.
* F-Curves use RNA-paths for Data Access, hence allowing "every" (where sensible/editable that is) user-accessible setting from RNA to be animated.
* Drivers are no longer mixed with Animation Data, so rigs will not be that easily broken and several dependency problems can be eliminated. (NOTE: drivers haven't been hooked up yet, but the code is in place)
* F-Curve modifier system allows useful 'large-scale' manipulation of F-Curve values, including (I've only included implemented ones here): envelope deform (similar to lattices to allow broad-scale reshaping of curves), curve generator (polynomial or py-expression), cycles (replacing the old cyclic extrapolation modes, giving more control over this). (NOTE: currently this cannot be tested, as there's not access to them, but the code is all in place)
* NLA system with 'tracks' (i.e. layers), and multiple strips per track. (NOTE: NLA system is not yet functional, as it's only partially coded still)
There are more nice things that I will be preparing some nice docs for soon, but for now, check for more details:
http://lists.blender.org/pipermail/bf-taskforce25/2009-January/000260.html
So, what currently works:
* I've implemented two basic operators for the 3D-view only to Insert and Delete Keyframes. These are tempolary ones only that will be replaced in due course with 'proper' code.
* Object Loc/Rot/Scale can be keyframed. Also, the colour of the 'active' material (Note: this should really be for nth material instead, but that doesn't work yet in RNA) can also be keyframed into the same datablock.
* Standard animation refresh (i.e. animation resulting from NLA and Action evaluation) is now done completely separate from drivers before anything else is done after a frame change. Drivers are handled after this in a separate pass, as dictated by depsgraph flags, etc.
Notes:
* Drivers haven't been hooked up yet
* Only objects and data directly linked to objects can be animated.
* Depsgraph will need further tweaks. Currently, I've only made sure that it will update some things in the most basic cases (i.e. frame change).
* Animation Editors are currently broken (in terms of editing stuff). This will be my next target (priority to get Dopesheet working first, then F-Curve editor - i.e. old IPO Editor)
* I've had to put in large chunks of XXX sandboxing for old animation system code all around the place. This will be cleaned up in due course, as some places need special review.
In particular, the particles and sequencer code have far too many manual calls to calculate + flush animation info, which is really bad (this is a 'please explain yourselves' call to Physics coders!).
2009-01-17 03:12:50 +00:00
|
|
|
#endif // XXX old animation system
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
id_us_plus((ID *)cun->vfont);
|
2005-06-17 21:04:27 +00:00
|
|
|
id_us_plus((ID *)cun->vfontb);
|
|
|
|
id_us_plus((ID *)cun->vfonti);
|
|
|
|
id_us_plus((ID *)cun->vfontbi);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
return cun;
|
|
|
|
}
|
|
|
|
|
2011-04-26 07:17:21 +00:00
|
|
|
static void extern_local_curve(Curve *cu)
|
|
|
|
{
|
|
|
|
id_lib_extern((ID *)cu->vfont);
|
|
|
|
id_lib_extern((ID *)cu->vfontb);
|
|
|
|
id_lib_extern((ID *)cu->vfonti);
|
|
|
|
id_lib_extern((ID *)cu->vfontbi);
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (cu->mat) {
|
2011-04-26 07:17:21 +00:00
|
|
|
extern_local_matarar(cu->mat, cu->totcol);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-28 16:49:00 +00:00
|
|
|
void BKE_curve_make_local(Curve *cu)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2011-04-26 07:17:21 +00:00
|
|
|
Main *bmain= G.main;
|
|
|
|
Object *ob;
|
2011-10-27 05:34:39 +00:00
|
|
|
int is_local= FALSE, is_lib= FALSE;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2003-04-25 15:48:11 +00:00
|
|
|
/* - when there are only lib users: don't do
|
|
|
|
* - when there are only local users: set flag
|
|
|
|
* - mixed: do a copy
|
2002-10-12 11:37:38 +00:00
|
|
|
*/
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (cu->id.lib==NULL) return;
|
2010-09-29 06:24:05 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (cu->id.us==1) {
|
2011-10-27 05:34:39 +00:00
|
|
|
id_clear_lib_data(bmain, &cu->id);
|
2011-04-26 07:17:21 +00:00
|
|
|
extern_local_curve(cu);
|
2002-10-12 11:37:38 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-04-26 07:17:21 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
for (ob= bmain->object.first; ob && ELEM(0, is_lib, is_local); ob= ob->id.next) {
|
|
|
|
if (ob->data == cu) {
|
|
|
|
if (ob->id.lib) is_lib= TRUE;
|
2011-10-27 05:34:39 +00:00
|
|
|
else is_local= TRUE;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
2011-04-26 07:17:21 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (is_local && is_lib == FALSE) {
|
2011-10-27 05:34:39 +00:00
|
|
|
id_clear_lib_data(bmain, &cu->id);
|
2011-04-26 07:17:21 +00:00
|
|
|
extern_local_curve(cu);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
else if (is_local && is_lib) {
|
2012-04-28 16:49:00 +00:00
|
|
|
Curve *cu_new= BKE_curve_copy(cu);
|
2011-11-30 00:32:13 +00:00
|
|
|
cu_new->id.us= 0;
|
2011-04-26 07:17:21 +00:00
|
|
|
|
2011-11-30 00:32:13 +00:00
|
|
|
BKE_id_lib_local_paths(bmain, cu->id.lib, &cu_new->id);
|
2011-10-27 05:34:39 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
for (ob= bmain->object.first; ob; ob= ob->id.next) {
|
|
|
|
if (ob->data==cu) {
|
|
|
|
if (ob->id.lib==NULL) {
|
2011-11-30 00:32:13 +00:00
|
|
|
ob->data= cu_new;
|
|
|
|
cu_new->id.us++;
|
2002-10-12 11:37:38 +00:00
|
|
|
cu->id.us--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
2011-11-24 14:30:37 +00:00
|
|
|
int type= cu->type;
|
|
|
|
|
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) {
|
2011-11-24 14:30:37 +00:00
|
|
|
type= OB_CURVE;
|
|
|
|
|
|
|
|
for (nu= cu->nurb.first; nu; nu= nu->next) {
|
2012-03-24 06:18:31 +00:00
|
|
|
if (nu->pntsv>1) {
|
2011-11-24 14:30:37 +00:00
|
|
|
type= OB_SURF;
|
|
|
|
}
|
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-04-28 16:49:00 +00:00
|
|
|
ListBase *nurbs= BKE_curve_nurbs_get(cu);
|
2011-11-03 16:16:19 +00:00
|
|
|
Nurb *nu= nurbs->first;
|
|
|
|
|
2012-03-24 06:18:31 +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-03-24 06:18:31 +00:00
|
|
|
for ( ; nu; nu= nu->next) {
|
2011-11-03 16:16:19 +00:00
|
|
|
nu->flag |= CU_2D;
|
2012-04-28 16:49:00 +00:00
|
|
|
BKE_nurb_test2D(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-04-28 16:49:00 +00:00
|
|
|
ob->type= BKE_curve_type_get(ob->data);
|
2011-11-03 16:16:19 +00:00
|
|
|
|
2012-03-24 06:18:31 +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
|
|
|
}
|
|
|
|
|
2012-05-05 21:28:12 +00:00
|
|
|
void BKE_curve_texspace_calc(Curve *cu)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
DispList *dl;
|
|
|
|
BoundBox *bb;
|
2010-08-01 11:00:36 +00:00
|
|
|
float *fp, min[3], max[3];
|
2002-10-12 11:37:38 +00:00
|
|
|
int tot, doit= 0;
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (cu->bb==NULL) cu->bb= MEM_callocN(sizeof(BoundBox), "boundbox");
|
2002-10-12 11:37:38 +00:00
|
|
|
bb= cu->bb;
|
|
|
|
|
|
|
|
INIT_MINMAX(min, max);
|
|
|
|
|
|
|
|
dl= cu->disp.first;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (dl) {
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-01-20 22:09:30 +00:00
|
|
|
tot = ELEM(dl->type, DL_INDEX3, DL_INDEX4) ? dl->nr : dl->nr * dl->parts;
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (tot) doit= 1;
|
2008-09-23 13:35:32 +00:00
|
|
|
fp= dl->verts;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (tot--) {
|
2008-09-23 13:35:32 +00:00
|
|
|
DO_MINMAX(fp, min, max);
|
|
|
|
fp += 3;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
dl= dl->next;
|
|
|
|
}
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (!doit) {
|
2005-07-18 17:33:51 +00:00
|
|
|
min[0] = min[1] = min[2] = -1.0f;
|
|
|
|
max[0] = max[1] = max[2] = 1.0f;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2012-05-05 14:03:12 +00:00
|
|
|
BKE_boundbox_init_from_minmax(bb, min, max);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (cu->texflag & CU_AUTOSPACE) {
|
2010-08-01 11:00:36 +00:00
|
|
|
mid_v3_v3v3(cu->loc, min, max);
|
|
|
|
cu->size[0]= (max[0]-min[0])/2.0f;
|
|
|
|
cu->size[1]= (max[1]-min[1])/2.0f;
|
|
|
|
cu->size[2]= (max[2]-min[2])/2.0f;
|
|
|
|
|
2012-03-23 20:18:09 +00:00
|
|
|
zero_v3(cu->rot);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (cu->size[0]==0.0f) cu->size[0]= 1.0f;
|
|
|
|
else if (cu->size[0]>0.0f && cu->size[0]<0.00001f) cu->size[0]= 0.00001f;
|
|
|
|
else if (cu->size[0]<0.0f && cu->size[0]> -0.00001f) cu->size[0]= -0.00001f;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (cu->size[1]==0.0f) cu->size[1]= 1.0f;
|
|
|
|
else if (cu->size[1]>0.0f && cu->size[1]<0.00001f) cu->size[1]= 0.00001f;
|
|
|
|
else if (cu->size[1]<0.0f && cu->size[1]> -0.00001f) cu->size[1]= -0.00001f;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (cu->size[2]==0.0f) cu->size[2]= 1.0f;
|
|
|
|
else if (cu->size[2]>0.0f && cu->size[2]<0.00001f) cu->size[2]= 0.00001f;
|
|
|
|
else if (cu->size[2]<0.0f && cu->size[2]> -0.00001f) cu->size[2]= -0.00001f;
|
2002-10-12 11:37:38 +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;
|
|
|
|
int tot=0;
|
|
|
|
|
|
|
|
nu= nurb->first;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (nu) {
|
|
|
|
if (nu->bezt) tot+= 3*nu->pntsu;
|
|
|
|
else if (nu->bp) tot+= nu->pntsu*nu->pntsv;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
nu= nu->next;
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
int tot=0;
|
|
|
|
|
|
|
|
nu= nurb->first;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (nu) {
|
|
|
|
if (nu->bezt) tot+= nu->pntsu;
|
|
|
|
else if (nu->bp) tot+= nu->pntsu*nu->pntsv;
|
2007-06-14 14:36:27 +00:00
|
|
|
|
|
|
|
nu= nu->next;
|
|
|
|
}
|
|
|
|
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-03-24 06:18:31 +00:00
|
|
|
if (nu==NULL) return;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (nu->bezt) MEM_freeN(nu->bezt);
|
2011-02-13 10:52:18 +00:00
|
|
|
nu->bezt= NULL;
|
2012-03-24 06:18:31 +00:00
|
|
|
if (nu->bp) MEM_freeN(nu->bp);
|
2011-02-13 10:52:18 +00:00
|
|
|
nu->bp= NULL;
|
2012-03-24 06:18:31 +00:00
|
|
|
if (nu->knotsu) MEM_freeN(nu->knotsu);
|
2008-05-26 09:50:46 +00:00
|
|
|
nu->knotsu= NULL;
|
2012-03-24 06:18:31 +00:00
|
|
|
if (nu->knotsv) MEM_freeN(nu->knotsv);
|
2008-05-26 09:50:46 +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-03-24 06:18:31 +00:00
|
|
|
if (lb==NULL) return;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
nu= lb->first;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (nu) {
|
2002-10-12 11:37:38 +00:00
|
|
|
next= nu->next;
|
2012-04-28 16:49:00 +00:00
|
|
|
BKE_nurb_free(nu);
|
2002-10-12 11:37:38 +00:00
|
|
|
nu= next;
|
|
|
|
}
|
2011-02-13 10:52:18 +00:00
|
|
|
lb->first= lb->last= NULL;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2012-04-28 16:49:00 +00:00
|
|
|
Nurb *BKE_nurb_duplicate(Nurb *nu)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
Nurb *newnu;
|
|
|
|
int len;
|
|
|
|
|
2012-04-29 15:47:02 +00:00
|
|
|
newnu= (Nurb*)MEM_mallocN(sizeof(Nurb), "duplicateNurb");
|
2012-03-24 06:18:31 +00:00
|
|
|
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) {
|
2002-10-12 11:37:38 +00:00
|
|
|
newnu->bezt=
|
2012-04-29 15:47:02 +00:00
|
|
|
(BezTriple*)MEM_mallocN((nu->pntsu)* sizeof(BezTriple), "duplicateNurb2");
|
2002-10-12 11:37:38 +00:00
|
|
|
memcpy(newnu->bezt, nu->bezt, nu->pntsu*sizeof(BezTriple));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
len= nu->pntsu*nu->pntsv;
|
|
|
|
newnu->bp=
|
2012-04-29 15:47:02 +00:00
|
|
|
(BPoint*)MEM_mallocN((len)* sizeof(BPoint), "duplicateNurb3");
|
2002-10-12 11:37:38 +00:00
|
|
|
memcpy(newnu->bp, nu->bp, len*sizeof(BPoint));
|
|
|
|
|
2008-05-26 09:50:46 +00:00
|
|
|
newnu->knotsu= newnu->knotsv= NULL;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (nu->knotsu) {
|
2002-10-12 11:37:38 +00:00
|
|
|
len= KNOTSU(nu);
|
2012-03-24 06:18:31 +00:00
|
|
|
if (len) {
|
2002-10-12 11:37:38 +00:00
|
|
|
newnu->knotsu= MEM_mallocN(len*sizeof(float), "duplicateNurb4");
|
|
|
|
memcpy(newnu->knotsu, nu->knotsu, sizeof(float)*len);
|
|
|
|
}
|
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
if (nu->pntsv>1 && nu->knotsv) {
|
2002-10-12 11:37:38 +00:00
|
|
|
len= KNOTSV(nu);
|
2012-03-24 06:18:31 +00:00
|
|
|
if (len) {
|
2002-10-12 11:37:38 +00:00
|
|
|
newnu->knotsv= MEM_mallocN(len*sizeof(float), "duplicateNurb5");
|
|
|
|
memcpy(newnu->knotsv, nu->knotsv, sizeof(float)*len);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return newnu;
|
|
|
|
}
|
|
|
|
|
2012-04-28 16:49:00 +00:00
|
|
|
void BKE_nurbList_duplicate(ListBase *lb1, ListBase *lb2)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
Nurb *nu, *nun;
|
|
|
|
|
2012-04-28 16:49:00 +00:00
|
|
|
BKE_nurbList_free(lb1);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
nu= lb2->first;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (nu) {
|
2012-04-28 16:49:00 +00:00
|
|
|
nun= BKE_nurb_duplicate(nu);
|
2002-10-12 11:37:38 +00:00
|
|
|
BLI_addtail(lb1, nun);
|
|
|
|
|
|
|
|
nu= nu->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-28 16:49:00 +00:00
|
|
|
void BKE_nurb_test2D(Nurb *nu)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
BezTriple *bezt;
|
|
|
|
BPoint *bp;
|
|
|
|
int a;
|
2009-09-08 00:23:33 +00:00
|
|
|
|
2012-03-24 06:18:31 +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) {
|
2002-10-12 11:37:38 +00:00
|
|
|
a= nu->pntsu;
|
|
|
|
bezt= nu->bezt;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (a--) {
|
2002-10-12 11:37:38 +00:00
|
|
|
bezt->vec[0][2]= 0.0;
|
|
|
|
bezt->vec[1][2]= 0.0;
|
|
|
|
bezt->vec[2][2]= 0.0;
|
|
|
|
bezt++;
|
|
|
|
}
|
|
|
|
}
|
2009-09-08 00:23:33 +00:00
|
|
|
else {
|
2002-10-12 11:37:38 +00:00
|
|
|
a= nu->pntsu*nu->pntsv;
|
|
|
|
bp= nu->bp;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (a--) {
|
2002-10-12 11:37:38 +00:00
|
|
|
bp->vec[2]= 0.0;
|
|
|
|
bp++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-28 16:49:00 +00:00
|
|
|
void BKE_nurb_minmax(Nurb *nu, float *min, float *max)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
BezTriple *bezt;
|
|
|
|
BPoint *bp;
|
|
|
|
int a;
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (nu->type == CU_BEZIER) {
|
2002-10-12 11:37:38 +00:00
|
|
|
a= nu->pntsu;
|
|
|
|
bezt= nu->bezt;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (a--) {
|
2002-10-12 11:37:38 +00:00
|
|
|
DO_MINMAX(bezt->vec[0], min, max);
|
|
|
|
DO_MINMAX(bezt->vec[1], min, max);
|
|
|
|
DO_MINMAX(bezt->vec[2], min, max);
|
|
|
|
bezt++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
a= nu->pntsu*nu->pntsv;
|
|
|
|
bp= nu->bp;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (a--) {
|
2002-10-12 11:37:38 +00:00
|
|
|
DO_MINMAX(bp->vec, min, max);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/* 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
|
|
|
{
|
|
|
|
BPoint *tmp= nu->bp;
|
|
|
|
int i;
|
|
|
|
nu->bp= (BPoint *)MEM_mallocN((nu->pntsu + number) * sizeof(BPoint), "rna_Curve_spline_points_add");
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (tmp) {
|
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
|
|
|
memmove(nu->bp, tmp, nu->pntsu * sizeof(BPoint));
|
|
|
|
MEM_freeN(tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(nu->bp + nu->pntsu, 0, number * sizeof(BPoint));
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
for (i=0, tmp= nu->bp + nu->pntsu; i < number; i++, tmp++) {
|
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
|
|
|
tmp->radius= 1.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
BezTriple *tmp= nu->bezt;
|
|
|
|
int i;
|
|
|
|
nu->bezt= (BezTriple *)MEM_mallocN((nu->pntsu + number) * sizeof(BezTriple), "rna_Curve_spline_points_add");
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (tmp) {
|
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
|
|
|
memmove(nu->bezt, tmp, nu->pntsu * sizeof(BezTriple));
|
|
|
|
MEM_freeN(tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(nu->bezt + nu->pntsu, 0, number * sizeof(BezTriple));
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
for (i=0, tmp= nu->bezt + nu->pntsu; i < number; i++, tmp++) {
|
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
|
|
|
tmp->radius= 1.0f;
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2003-04-25 15:48:11 +00:00
|
|
|
/* ~~~~~~~~~~~~~~~~~~~~Non Uniform Rational B Spline calculations ~~~~~~~~~~~ */
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
|
2011-08-01 05:25:30 +00:00
|
|
|
static void calcknots(float *knots, const short 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 */
|
2011-08-01 05:25:30 +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-04-28 06:31:57 +00:00
|
|
|
switch (flag & (CU_NURB_ENDPOINT|CU_NURB_BEZIER)) {
|
2011-08-01 02:52:08 +00:00
|
|
|
case CU_NURB_ENDPOINT:
|
2002-10-12 11:37:38 +00:00
|
|
|
k= 0.0;
|
2012-03-24 06:18:31 +00:00
|
|
|
for (a=1; a <= pnts_order; a++) {
|
2002-10-12 11:37:38 +00:00
|
|
|
knots[a-1]= k;
|
2012-03-24 06:18:31 +00:00
|
|
|
if (a >= order && a <= pnts) k+= 1.0f;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2011-08-01 02:52:08 +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 */
|
2012-03-24 06:18:31 +00:00
|
|
|
if (order==4) {
|
2002-10-12 11:37:38 +00:00
|
|
|
k= 0.34;
|
2012-03-24 06:18:31 +00:00
|
|
|
for (a=0; a < pnts_order; a++) {
|
2011-03-28 04:22:50 +00:00
|
|
|
knots[a]= floorf(k);
|
|
|
|
k+= (1.0f/3.0f);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
else if (order==3) {
|
2011-03-28 04:22:50 +00:00
|
|
|
k= 0.6f;
|
2012-03-24 06:18:31 +00:00
|
|
|
for (a=0; a < pnts_order; a++) {
|
|
|
|
if (a >= order && a <= pnts) k+= 0.5f;
|
2011-03-28 04:22:50 +00:00
|
|
|
knots[a]= floorf(k);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
2008-05-26 09:50:46 +00:00
|
|
|
else {
|
|
|
|
printf("bez nurb curve order is not 3 or 4, should never happen\n");
|
|
|
|
}
|
2011-08-01 02:52:08 +00:00
|
|
|
break;
|
|
|
|
default:
|
2012-03-24 06:18:31 +00:00
|
|
|
for (a=0; a < pnts_order; a++) {
|
2011-08-01 02:52:08 +00:00
|
|
|
knots[a]= (float)a;
|
|
|
|
}
|
|
|
|
break;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-07 19:59:02 +00:00
|
|
|
static void makecyclicknots(float *knots, short 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-03-24 06:18:31 +00:00
|
|
|
if (knots==NULL) return;
|
2008-05-26 12:50:00 +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-03-24 06:18:31 +00:00
|
|
|
if (order>2) {
|
2002-10-30 00:37:19 +00:00
|
|
|
b= pnts+order2;
|
2012-03-24 06:18:31 +00:00
|
|
|
for (a=1; a<order2; a++) {
|
|
|
|
if (knots[b]!= knots[b-a]) break;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
if (a==order2) knots[pnts+order-2]+= 1.0f;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
b= order;
|
2010-03-22 09:30:00 +00:00
|
|
|
c=pnts + order + order2;
|
2012-03-24 06:18:31 +00:00
|
|
|
for (a=pnts+order2; a<c; a++) {
|
2002-10-12 11:37:38 +00:00
|
|
|
knots[a]= knots[a-1]+ (knots[b]-knots[b-1]);
|
|
|
|
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) {
|
|
|
|
if (nu->knotsu) MEM_freeN(nu->knotsu);
|
2012-04-28 16:49:00 +00:00
|
|
|
if (BKE_nurb_check_valid_u(nu)) {
|
2002-10-12 11:37:38 +00:00
|
|
|
nu->knotsu= MEM_callocN(4+sizeof(float)*KNOTSU(nu), "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
|
|
|
}
|
2008-05-26 12:50:00 +00:00
|
|
|
else nu->knotsu= NULL;
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
|
|
|
else if (uv == 2) {
|
|
|
|
if (nu->knotsv) MEM_freeN(nu->knotsv);
|
2012-04-28 16:49:00 +00:00
|
|
|
if (BKE_nurb_check_valid_v(nu)) {
|
2002-10-12 11:37:38 +00:00
|
|
|
nu->knotsv= MEM_callocN(4+sizeof(float)*KNOTSV(nu), "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
|
|
|
}
|
2008-05-26 12:50:00 +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);
|
|
|
|
}
|
|
|
|
|
2006-02-07 19:59:02 +00:00
|
|
|
static void basisNurb(float t, short order, short 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
|
|
|
|
|
|
|
orderpluspnts= order+pnts;
|
2010-03-22 09:30:00 +00:00
|
|
|
opp2 = orderpluspnts-1;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
/* this is for float inaccuracy */
|
2012-03-24 06:18:31 +00:00
|
|
|
if (t < knots[0]) t= knots[0];
|
|
|
|
else if (t > knots[opp2]) t= knots[opp2];
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2003-04-25 15:48:11 +00:00
|
|
|
/* this part is order '1' */
|
2010-03-22 09:30:00 +00:00
|
|
|
o2 = order + 1;
|
2012-03-24 06:18:31 +00:00
|
|
|
for (i=0;i<opp2;i++) {
|
|
|
|
if (knots[i]!=knots[i+1] && t>= knots[i] && t<=knots[i+1]) {
|
2002-10-12 11:37:38 +00:00
|
|
|
basis[i]= 1.0;
|
2002-10-30 00:37:19 +00:00
|
|
|
i1= i-o2;
|
2012-03-24 06:18:31 +00:00
|
|
|
if (i1<0) i1= 0;
|
2002-10-12 11:37:38 +00:00
|
|
|
i2= i;
|
|
|
|
i++;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (i<opp2) {
|
2002-10-12 11:37:38 +00:00
|
|
|
basis[i]= 0.0;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else basis[i]= 0.0;
|
|
|
|
}
|
|
|
|
basis[i]= 0.0;
|
|
|
|
|
2012-04-29 15:47:02 +00:00
|
|
|
/* this is order 2, 3, ... */
|
2012-03-24 06:18:31 +00:00
|
|
|
for (j=2; j<=order; j++) {
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (i2+j>= orderpluspnts) i2= opp2-j;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
for (i= i1; i<=i2; i++) {
|
|
|
|
if (basis[i]!=0.0f)
|
2002-10-12 11:37:38 +00:00
|
|
|
d= ((t-knots[i])*basis[i]) / (knots[i+j-1]-knots[i]);
|
|
|
|
else
|
2011-03-28 04:22:50 +00:00
|
|
|
d= 0.0f;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (basis[i+1] != 0.0f)
|
2002-10-12 11:37:38 +00:00
|
|
|
e= ((knots[i+j]-t)*basis[i+1]) / (knots[i+j]-knots[i+1]);
|
|
|
|
else
|
|
|
|
e= 0.0;
|
|
|
|
|
|
|
|
basis[i]= d+e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*start= 1000;
|
|
|
|
*end= 0;
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
for (i=i1; i<=i2; i++) {
|
|
|
|
if (basis[i] > 0.0f) {
|
2002-10-12 11:37:38 +00:00
|
|
|
*end= i;
|
2012-03-24 06:18:31 +00:00
|
|
|
if (*start==1000) *start= i;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-28 16:49:00 +00:00
|
|
|
void BKE_nurb_makeFaces(Nurb *nu, float *coord_array, int rowstride, int resolu, int resolv)
|
2008-09-23 13:35:32 +00:00
|
|
|
/* coord_array has to be 3*4*resolu*resolv in size, and zero-ed */
|
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;
|
2008-09-26 19:00:49 +00:00
|
|
|
|
2010-11-11 09:56:39 +00:00
|
|
|
int totu = nu->pntsu*resolu, totv = nu->pntsv*resolv;
|
2008-09-26 19:00:49 +00:00
|
|
|
|
2012-03-24 06:18:31 +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;
|
2008-09-26 19:00:49 +00:00
|
|
|
|
2003-04-25 15:48:11 +00:00
|
|
|
/* allocate and initialize */
|
2008-09-26 19:00:49 +00:00
|
|
|
len = totu * totv;
|
2012-03-24 06:18:31 +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
|
|
|
|
|
|
|
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
sum= (float *)MEM_callocN(sizeof(float)*len, "makeNurbfaces1");
|
2008-09-26 19:00:49 +00:00
|
|
|
|
|
|
|
len= totu*totv;
|
2012-03-24 06:18:31 +00:00
|
|
|
if (len==0) {
|
2002-10-12 11:37:38 +00:00
|
|
|
MEM_freeN(sum);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2002-10-12 11:37:38 +00:00
|
|
|
ratcomp= 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
bp++;
|
|
|
|
}
|
2008-09-26 19:00:49 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
fp= nu->knotsu;
|
|
|
|
ustart= fp[nu->orderu-1];
|
2012-03-24 06:18:31 +00:00
|
|
|
if (nu->flagu & CU_NURB_CYCLIC) uend= fp[nu->pntsu+nu->orderu-1];
|
2002-10-12 11:37:38 +00:00
|
|
|
else uend= fp[nu->pntsu];
|
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
|
|
|
ustep= (uend-ustart)/((nu->flagu & CU_NURB_CYCLIC) ? totu : totu - 1);
|
2008-09-26 19:00:49 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
basisu= (float *)MEM_mallocN(sizeof(float)*KNOTSU(nu), "makeNurbfaces3");
|
|
|
|
|
|
|
|
fp= nu->knotsv;
|
|
|
|
vstart= fp[nu->orderv-1];
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (nu->flagv & CU_NURB_CYCLIC) vend= fp[nu->pntsv+nu->orderv-1];
|
2002-10-12 11:37:38 +00:00
|
|
|
else vend= fp[nu->pntsv];
|
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
|
|
|
vstep= (vend-vstart)/((nu->flagv & CU_NURB_CYCLIC) ? totv : totv - 1);
|
2008-09-26 19:00:49 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
len= KNOTSV(nu);
|
2008-09-26 19:00:49 +00:00
|
|
|
basisv= (float *)MEM_mallocN(sizeof(float)*len*totv, "makeNurbfaces3");
|
|
|
|
jstart= (int *)MEM_mallocN(sizeof(float)*totv, "makeNurbfaces4");
|
|
|
|
jend= (int *)MEM_mallocN(sizeof(float)*totv, "makeNurbfaces5");
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-04-29 15:47:02 +00:00
|
|
|
/* precalculation of basisv and jstart, jend */
|
2012-03-24 06:18:31 +00:00
|
|
|
if (nu->flagv & CU_NURB_CYCLIC) cycl= nu->orderv-1;
|
2002-10-12 11:37:38 +00:00
|
|
|
else cycl= 0;
|
|
|
|
v= vstart;
|
|
|
|
basis= basisv;
|
2010-11-11 09:56:39 +00:00
|
|
|
curv= totv;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (curv--) {
|
2010-11-11 09:56:39 +00:00
|
|
|
basisNurb(v, nu->orderv, (short)(nu->pntsv+cycl), nu->knotsv, basis, jstart+curv, jend+curv);
|
2002-10-12 11:37:38 +00:00
|
|
|
basis+= KNOTSV(nu);
|
|
|
|
v+= vstep;
|
|
|
|
}
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (nu->flagu & CU_NURB_CYCLIC) cycl= nu->orderu-1;
|
2002-10-12 11:37:38 +00:00
|
|
|
else cycl= 0;
|
2008-09-23 13:35:32 +00:00
|
|
|
in= coord_array;
|
2002-10-12 11:37:38 +00:00
|
|
|
u= ustart;
|
2010-11-11 09:56:39 +00:00
|
|
|
curu= totu;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (curu--) {
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
basisNurb(u, nu->orderu, (short)(nu->pntsu+cycl), nu->knotsu, basisu, &istart, &iend);
|
|
|
|
|
|
|
|
basis= basisv;
|
2010-11-11 09:56:39 +00:00
|
|
|
curv= totv;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (curv--) {
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2010-11-11 09:56:39 +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 */
|
2002-10-12 11:37:38 +00:00
|
|
|
sumdiv= 0.0;
|
|
|
|
fp= sum;
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
for (j= jsta; j<=jen; j++) {
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (j>=nu->pntsv) jofs= (j - nu->pntsv);
|
2002-10-12 11:37:38 +00:00
|
|
|
else jofs= j;
|
|
|
|
bp= nu->bp+ nu->pntsu*jofs+istart-1;
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
for (i= istart; i<=iend; i++, fp++) {
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (i>= nu->pntsu) {
|
2002-10-12 11:37:38 +00:00
|
|
|
iofs= i- nu->pntsu;
|
|
|
|
bp= nu->bp+ nu->pntsu*jofs+iofs;
|
|
|
|
}
|
|
|
|
else bp++;
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (ratcomp) {
|
2002-10-12 11:37:38 +00:00
|
|
|
*fp= basisu[i]*basis[j]*bp->vec[3];
|
|
|
|
sumdiv+= *fp;
|
|
|
|
}
|
|
|
|
else *fp= basisu[i]*basis[j];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (ratcomp) {
|
2002-10-12 11:37:38 +00:00
|
|
|
fp= sum;
|
2012-03-24 06:18:31 +00:00
|
|
|
for (j= jsta; j<=jen; j++) {
|
|
|
|
for (i= istart; i<=iend; i++, fp++) {
|
2002-10-12 11:37:38 +00:00
|
|
|
*fp/= sumdiv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-04-25 15:48:11 +00:00
|
|
|
/* one! (1.0) real point now */
|
2002-10-12 11:37:38 +00:00
|
|
|
fp= sum;
|
2012-03-24 06:18:31 +00:00
|
|
|
for (j= jsta; j<=jen; j++) {
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (j>=nu->pntsv) jofs= (j - nu->pntsv);
|
2002-10-12 11:37:38 +00:00
|
|
|
else jofs= j;
|
|
|
|
bp= nu->bp+ nu->pntsu*jofs+istart-1;
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
for (i= istart; i<=iend; i++, fp++) {
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (i>= nu->pntsu) {
|
2002-10-12 11:37:38 +00:00
|
|
|
iofs= i- nu->pntsu;
|
|
|
|
bp= nu->bp+ nu->pntsu*jofs+iofs;
|
|
|
|
}
|
|
|
|
else bp++;
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (*fp != 0.0f) {
|
2002-10-12 11:37:38 +00:00
|
|
|
in[0]+= (*fp) * bp->vec[0];
|
|
|
|
in[1]+= (*fp) * bp->vec[1];
|
|
|
|
in[2]+= (*fp) * bp->vec[2];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
in+=3;
|
|
|
|
basis+= KNOTSV(nu);
|
|
|
|
}
|
|
|
|
u+= ustep;
|
2008-09-26 19:00:49 +00: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-04-28 16:49:00 +00:00
|
|
|
void BKE_nurb_makeCurve(Nurb *nu, float *coord_array, float *tilt_array, float *radius_array, float *weight_array, int resolu, int stride)
|
2008-09-23 13:35:32 +00:00
|
|
|
/* coord_array has to be 3*4*pntsu*resolu in size and zero-ed
|
|
|
|
* tilt_array and radius_array will be written to if valid */
|
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;
|
2010-04-21 11:59:47 +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-03-24 06:18:31 +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 */
|
2002-10-12 11:37:38 +00:00
|
|
|
len= nu->pntsu;
|
2012-03-24 06:18:31 +00:00
|
|
|
if (len==0) return;
|
2002-10-12 11:37:38 +00:00
|
|
|
sum= (float *)MEM_callocN(sizeof(float)*len, "makeNurbcurve1");
|
2008-09-23 06:26:48 +00:00
|
|
|
|
2008-10-06 06:10:14 +00:00
|
|
|
resolu= (resolu*SEGMENTSU(nu));
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (resolu==0) {
|
2002-10-12 11:37:38 +00:00
|
|
|
MEM_freeN(sum);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
fp= nu->knotsu;
|
|
|
|
ustart= fp[nu->orderu-1];
|
2012-03-24 06:18:31 +00:00
|
|
|
if (nu->flagu & CU_NURB_CYCLIC) uend= fp[nu->pntsu+nu->orderu-1];
|
2002-10-12 11:37:38 +00:00
|
|
|
else uend= fp[nu->pntsu];
|
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
|
|
|
ustep= (uend-ustart)/(resolu - ((nu->flagu & CU_NURB_CYCLIC) ? 0 : 1));
|
2008-10-06 06:10:14 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
basisu= (float *)MEM_mallocN(sizeof(float)*KNOTSU(nu), "makeNurbcurve3");
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (nu->flagu & CU_NURB_CYCLIC) cycl= nu->orderu-1;
|
2002-10-12 11:37:38 +00:00
|
|
|
else cycl= 0;
|
|
|
|
|
|
|
|
u= ustart;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (resolu--) {
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
basisNurb(u, nu->orderu, (short)(nu->pntsu+cycl), nu->knotsu, basisu, &istart, &iend);
|
2003-04-25 15:48:11 +00:00
|
|
|
/* calc sum */
|
2002-10-12 11:37:38 +00:00
|
|
|
sumdiv= 0.0;
|
|
|
|
fp= sum;
|
|
|
|
bp= nu->bp+ istart-1;
|
2012-03-24 06:18:31 +00:00
|
|
|
for (i= istart; i<=iend; i++, fp++) {
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (i>=nu->pntsu) bp= nu->bp+(i - nu->pntsu);
|
2002-10-12 11:37:38 +00:00
|
|
|
else bp++;
|
|
|
|
|
|
|
|
*fp= basisu[i]*bp->vec[3];
|
|
|
|
sumdiv+= *fp;
|
|
|
|
}
|
2012-03-24 07:52:14 +00:00
|
|
|
if (sumdiv != 0.0f) if (sumdiv < 0.999f || sumdiv > 1.001f) {
|
2003-04-25 15:48:11 +00:00
|
|
|
/* is normalizing needed? */
|
2002-10-12 11:37:38 +00:00
|
|
|
fp= sum;
|
2012-03-24 06:18:31 +00:00
|
|
|
for (i= istart; i<=iend; i++, fp++) {
|
2002-10-12 11:37:38 +00:00
|
|
|
*fp/= sumdiv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-04-25 15:48:11 +00:00
|
|
|
/* one! (1.0) real point */
|
2002-10-12 11:37:38 +00:00
|
|
|
fp= sum;
|
|
|
|
bp= nu->bp+ istart-1;
|
2012-03-24 06:18:31 +00:00
|
|
|
for (i= istart; i<=iend; i++, fp++) {
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (i>=nu->pntsu) bp= nu->bp+(i - nu->pntsu);
|
2002-10-12 11:37:38 +00:00
|
|
|
else bp++;
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (*fp != 0.0f) {
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2008-09-23 13:35:32 +00:00
|
|
|
coord_fp[0]+= (*fp) * bp->vec[0];
|
|
|
|
coord_fp[1]+= (*fp) * bp->vec[1];
|
|
|
|
coord_fp[2]+= (*fp) * bp->vec[2];
|
|
|
|
|
|
|
|
if (tilt_fp)
|
|
|
|
(*tilt_fp) += (*fp) * bp->alfa;
|
|
|
|
|
|
|
|
if (radius_fp)
|
|
|
|
(*radius_fp) += (*fp) * bp->radius;
|
2010-04-21 11:59:47 +00:00
|
|
|
|
|
|
|
if (weight_fp)
|
|
|
|
(*weight_fp) += (*fp) * bp->weight;
|
2008-09-23 13:35:32 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-10 02:57:25 +00:00
|
|
|
coord_fp = (float *)(((char *)coord_fp) + stride);
|
2008-09-23 13:35:32 +00:00
|
|
|
|
2009-09-10 02:57:25 +00:00
|
|
|
if (tilt_fp) tilt_fp = (float *)(((char *)tilt_fp) + stride);
|
|
|
|
if (radius_fp) radius_fp = (float *)(((char *)radius_fp) + stride);
|
2010-04-21 11:59:47 +00:00
|
|
|
if (weight_fp) weight_fp = (float *)(((char *)weight_fp) + stride);
|
2008-09-23 13:35:32 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
u+= ustep;
|
|
|
|
}
|
|
|
|
|
2003-04-25 15:48:11 +00:00
|
|
|
/* free */
|
2002-10-12 11:37:38 +00:00
|
|
|
MEM_freeN(sum);
|
|
|
|
MEM_freeN(basisu);
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
q0= rt0;
|
2002-10-12 11:37:38 +00:00
|
|
|
q1= rt1+rt2+rt3;
|
|
|
|
q2= 2*rt2+6*rt3;
|
|
|
|
q3= 6*rt3;
|
2011-04-21 15:53:30 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
for (a=0; a<=it; a++) {
|
2002-10-12 11:37:38 +00:00
|
|
|
*p= q0;
|
2009-09-10 02:57:25 +00:00
|
|
|
p = (float *)(((char *)p)+stride);
|
2002-10-12 11:37:38 +00:00
|
|
|
q0+= q1;
|
2011-04-21 15:53:30 +00:00
|
|
|
q1+= q2;
|
|
|
|
q2+= q3;
|
|
|
|
}
|
2009-09-11 15:35:30 +00:00
|
|
|
}
|
|
|
|
|
2009-09-14 16:52:06 +00:00
|
|
|
static void forward_diff_bezier_cotangent(float *p0, float *p1, float *p2, float *p3, float *p, int it, int stride)
|
2009-09-11 15:35:30 +00:00
|
|
|
{
|
|
|
|
/* note that these are not purpendicular to the curve
|
|
|
|
* they need to be rotated for this,
|
|
|
|
*
|
|
|
|
* This could also be optimized like forward_diff_bezier */
|
|
|
|
int a;
|
2012-03-24 06:18:31 +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-03-24 06:18:31 +00:00
|
|
|
for (i=0; i<3; i++) {
|
2009-09-11 15:35:30 +00:00
|
|
|
p[i]= (-6*t + 6)*p0[i] + (18*t - 12)*p1[i] + (-18*t + 6)*p2[i] + (6*t)*p3[i];
|
|
|
|
}
|
2009-11-10 20:43:45 +00:00
|
|
|
normalize_v3(p);
|
2009-09-11 15:35:30 +00:00
|
|
|
p = (float *)(((char *)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 */
|
2006-03-11 12:34:50 +00:00
|
|
|
Curve *cu= ob->data;
|
2002-10-12 11:37:38 +00:00
|
|
|
Nurb *nu;
|
|
|
|
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;
|
2006-03-11 12:34:50 +00:00
|
|
|
|
|
|
|
/* first calculate the size of the datablock */
|
|
|
|
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
|
|
|
|
|
|
|
resolu= cu->resolu_ren ? cu->resolu_ren : nu->resolu;
|
|
|
|
resolv= cu->resolv_ren ? cu->resolv_ren : nu->resolv;
|
2006-03-11 12:34:50 +00:00
|
|
|
|
2010-11-11 09:56:39 +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-03-24 06:18:31 +00:00
|
|
|
if (nu->pntsv>1) tot+= sizeu * sizev;
|
2006-03-11 12:34:50 +00:00
|
|
|
|
|
|
|
nu= nu->next;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2006-03-11 12:34:50 +00:00
|
|
|
/* makeNurbfaces wants zeros */
|
2008-09-23 13:35:32 +00:00
|
|
|
fp= coord_array= MEM_callocN(3*sizeof(float)*tot, "make_orco");
|
2006-03-11 12:34:50 +00:00
|
|
|
|
|
|
|
nu= cu->nurb.first;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (nu) {
|
2010-11-11 09:56:39 +00:00
|
|
|
resolu= cu->resolu_ren ? cu->resolu_ren : nu->resolu;
|
|
|
|
resolv= cu->resolv_ren ? cu->resolv_ren : nu->resolv;
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (nu->pntsv>1) {
|
2010-11-11 09:56:39 +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++;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (cu->flag & CU_UV_ORCO) {
|
|
|
|
for (b=0; b< sizeu; b++) {
|
|
|
|
for (a=0; a< sizev; a++) {
|
2006-03-11 12:34:50 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (sizev <2) fp[0]= 0.0f;
|
2008-09-23 13:35:32 +00:00
|
|
|
else fp[0]= -1.0f + 2.0f*((float)a)/(sizev - 1);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (sizeu <2) fp[1]= 0.0f;
|
2008-09-23 13:35:32 +00:00
|
|
|
else fp[1]= -1.0f + 2.0f*((float)b)/(sizeu - 1);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2008-09-23 13:35:32 +00:00
|
|
|
fp[2]= 0.0;
|
2006-03-11 12:34:50 +00:00
|
|
|
|
2008-09-23 13:35:32 +00:00
|
|
|
fp+= 3;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2010-11-11 09:56:39 +00:00
|
|
|
float *_tdata= MEM_callocN((nu->pntsu*resolu) * (nu->pntsv*resolv) *3*sizeof(float), "temp data");
|
2006-07-06 14:20:44 +00:00
|
|
|
float *tdata= _tdata;
|
|
|
|
|
2012-04-28 16:49:00 +00:00
|
|
|
BKE_nurb_makeFaces(nu, tdata, 0, resolu, resolv);
|
2006-03-11 12:34:50 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
for (b=0; b<sizeu; b++) {
|
2006-07-06 14:20:44 +00:00
|
|
|
int use_b= b;
|
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 (b==sizeu-1 && (nu->flagu & CU_NURB_CYCLIC))
|
2006-07-06 14:20:44 +00:00
|
|
|
use_b= 0;
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
for (a=0; a<sizev; a++) {
|
2006-07-06 14:20:44 +00:00
|
|
|
int use_a= a;
|
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 (a==sizev-1 && (nu->flagv & CU_NURB_CYCLIC))
|
2006-07-06 14:20:44 +00:00
|
|
|
use_a= 0;
|
|
|
|
|
2010-11-11 09:56:39 +00:00
|
|
|
tdata = _tdata + 3 * (use_b * (nu->pntsv*resolv) + use_a);
|
2006-07-06 14:20:44 +00:00
|
|
|
|
2008-09-23 13:35:32 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2006-07-06 14:20:44 +00:00
|
|
|
|
|
|
|
MEM_freeN(_tdata);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
2006-03-11 12:34:50 +00:00
|
|
|
nu= nu->next;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2006-03-11 12:34:50 +00:00
|
|
|
|
2008-09-23 13:35:32 +00:00
|
|
|
return coord_array;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-08-14 06:08:41 +00:00
|
|
|
/* NOTE: This routine is tied to the order of vertex
|
|
|
|
* built by displist and as passed to the renderer.
|
|
|
|
*/
|
2012-04-28 16:49:00 +00:00
|
|
|
float *BKE_curve_make_orco(Scene *scene, Object *ob)
|
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
|
|
|
|
2010-03-08 13:49:13 +00:00
|
|
|
makeDispListCurveTypes_forOrco(scene, ob, &disp);
|
2005-08-14 06:08:41 +00:00
|
|
|
|
|
|
|
numVerts = 0;
|
2010-03-08 13:49:13 +00:00
|
|
|
for (dl=disp.first; dl; dl=dl->next) {
|
2005-08-14 06:08:41 +00:00
|
|
|
if (dl->type==DL_INDEX3) {
|
|
|
|
numVerts += dl->nr;
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
|
|
|
else if (dl->type==DL_SURF) {
|
2006-06-21 10:02:47 +00:00
|
|
|
/* convertblender.c uses the Surface code for creating renderfaces when cyclic U only (closed circle beveling) */
|
|
|
|
if (dl->flag & DL_CYCL_U) {
|
|
|
|
if (dl->flag & DL_CYCL_V)
|
|
|
|
numVerts += (dl->parts+1)*(dl->nr+1);
|
|
|
|
else
|
|
|
|
numVerts += dl->parts*(dl->nr+1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
numVerts += dl->parts*dl->nr;
|
2005-08-14 06:08:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-23 13:35:32 +00:00
|
|
|
fp= coord_array= MEM_mallocN(3*sizeof(float)*numVerts, "cu_orco");
|
2010-03-08 13:49:13 +00:00
|
|
|
for (dl=disp.first; dl; dl=dl->next) {
|
2005-08-14 06:08:41 +00:00
|
|
|
if (dl->type==DL_INDEX3) {
|
2006-03-11 12:34:50 +00:00
|
|
|
for (u=0; u<dl->nr; u++, fp+=3) {
|
|
|
|
if (cu->flag & CU_UV_ORCO) {
|
2005-08-14 06:08:41 +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 {
|
2011-10-28 12:40:15 +00:00
|
|
|
copy_v3_v3(fp, &dl->verts[u*3]);
|
2005-08-14 06:08:41 +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];
|
|
|
|
}
|
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
|
|
|
else if (dl->type==DL_SURF) {
|
2006-06-21 10:02:47 +00:00
|
|
|
int sizeu= dl->nr, sizev= dl->parts;
|
2006-03-11 12:34:50 +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++;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (u=0; u<sizev; u++) {
|
2012-04-29 15:47:02 +00:00
|
|
|
for (v=0; v<sizeu; v++, fp+=3) {
|
2006-03-11 12:34:50 +00:00
|
|
|
if (cu->flag & CU_UV_ORCO) {
|
2010-11-14 19:06:39 +00:00
|
|
|
fp[0]= 2.0f*u/(sizev - 1) - 1.0f;
|
|
|
|
fp[1]= 2.0f*v/(sizeu - 1) - 1.0f;
|
2005-08-14 06:08:41 +00:00
|
|
|
fp[2]= 0.0;
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
|
|
|
else {
|
2008-11-02 14:03:47 +00:00
|
|
|
float *vert;
|
2006-03-11 12:34:50 +00:00
|
|
|
int realv= v % dl->nr;
|
2008-11-02 14:03:47 +00:00
|
|
|
int realu= u % dl->parts;
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-08 13:49:13 +00:00
|
|
|
freedisplist(&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 ****************** */
|
|
|
|
|
2012-04-28 16:49:00 +00:00
|
|
|
void BKE_curve_bevel_make(Scene *scene, Object *ob, ListBase *disp, int forRender)
|
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;
|
|
|
|
|
|
|
|
cu= ob->data;
|
2005-08-14 06:08:41 +00:00
|
|
|
disp->first = disp->last = NULL;
|
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) {
|
2010-08-05 08:39:25 +00:00
|
|
|
if (cu->bevobj->type!=OB_CURVE) return;
|
|
|
|
|
2010-03-30 14:33:05 +00:00
|
|
|
bevcu= cu->bevobj->data;
|
2012-03-24 06:18:31 +00:00
|
|
|
if (bevcu->ext1==0.0f && bevcu->ext2==0.0f) {
|
2010-03-30 14:33:05 +00:00
|
|
|
ListBase bevdisp= {NULL, NULL};
|
|
|
|
facx= cu->bevobj->size[0];
|
|
|
|
facy= cu->bevobj->size[1];
|
|
|
|
|
|
|
|
if (forRender) {
|
|
|
|
makeDispListCurveTypes_forRender(scene, cu->bevobj, &bevdisp, NULL, 0);
|
|
|
|
dl= bevdisp.first;
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
|
|
|
else {
|
2011-01-05 10:40:38 +00:00
|
|
|
dl= cu->bevobj->disp.first;
|
2012-03-24 06:18:31 +00:00
|
|
|
if (dl==NULL) {
|
2010-03-30 14:33:05 +00:00
|
|
|
makeDispListCurveTypes(scene, cu->bevobj, 0);
|
2011-01-05 10:40:38 +00:00
|
|
|
dl= cu->bevobj->disp.first;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
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)) {
|
2010-03-30 14:33:05 +00:00
|
|
|
dlnew= MEM_mallocN(sizeof(DispList), "makebevelcurve1");
|
|
|
|
*dlnew= *dl;
|
|
|
|
dlnew->verts= MEM_mallocN(3*sizeof(float)*dl->parts*dl->nr, "makebevelcurve1");
|
|
|
|
memcpy(dlnew->verts, dl->verts, 3*sizeof(float)*dl->parts*dl->nr);
|
|
|
|
|
2012-03-24 06:18:31 +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);
|
|
|
|
fp= dlnew->verts;
|
|
|
|
nr= dlnew->parts*dlnew->nr;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (nr--) {
|
2010-03-30 14:33:05 +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
|
|
|
}
|
|
|
|
}
|
2010-03-30 14:33:05 +00:00
|
|
|
dl= dl->next;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2010-03-30 14:33:05 +00:00
|
|
|
|
|
|
|
freedisplist(&bevdisp);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
else if (cu->ext1==0.0f && cu->ext2==0.0f) {
|
2005-08-14 06:08:41 +00:00
|
|
|
;
|
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
else if (cu->ext2==0.0f) {
|
2002-10-12 11:37:38 +00:00
|
|
|
dl= MEM_callocN(sizeof(DispList), "makebevelcurve2");
|
|
|
|
dl->verts= MEM_mallocN(2*3*sizeof(float), "makebevelcurve2");
|
|
|
|
BLI_addtail(disp, dl);
|
|
|
|
dl->type= DL_SEGM;
|
|
|
|
dl->parts= 1;
|
2004-10-31 13:51:36 +00:00
|
|
|
dl->flag= DL_FRONT_CURVE|DL_BACK_CURVE;
|
2002-10-12 11:37:38 +00:00
|
|
|
dl->nr= 2;
|
2004-10-31 13:51:36 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
fp= dl->verts;
|
|
|
|
fp[0]= fp[1]= 0.0;
|
|
|
|
fp[2]= -cu->ext1;
|
|
|
|
fp[3]= fp[4]= 0.0;
|
|
|
|
fp[5]= cu->ext1;
|
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
else if ( (cu->flag & (CU_FRONT|CU_BACK))==0 && cu->ext1==0.0f) { // we make a full round bevel in that case
|
2006-03-06 21:44:08 +00:00
|
|
|
|
|
|
|
nr= 4+ 2*cu->bevresol;
|
|
|
|
|
|
|
|
dl= MEM_callocN(sizeof(DispList), "makebevelcurve p1");
|
|
|
|
dl->verts= MEM_mallocN(nr*3*sizeof(float), "makebevelcurve p1");
|
|
|
|
BLI_addtail(disp, dl);
|
|
|
|
dl->type= DL_POLY;
|
|
|
|
dl->parts= 1;
|
|
|
|
dl->flag= DL_BACK_CURVE;
|
|
|
|
dl->nr= nr;
|
|
|
|
|
|
|
|
/* a circle */
|
|
|
|
fp= dl->verts;
|
2011-03-28 04:22:50 +00:00
|
|
|
dangle= (2.0f*(float)M_PI/(nr));
|
2006-10-14 23:27:18 +00:00
|
|
|
angle= -(nr-1)*dangle;
|
2006-03-06 21:44:08 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
for (a=0; a<nr; a++) {
|
2006-03-06 21:44:08 +00:00
|
|
|
fp[0]= 0.0;
|
2011-03-28 04:22:50 +00:00
|
|
|
fp[1]= (cosf(angle)*(cu->ext2));
|
|
|
|
fp[2]= (sinf(angle)*(cu->ext2)) - cu->ext1;
|
2006-10-14 23:27:18 +00:00
|
|
|
angle+= dangle;
|
2006-03-06 21:44:08 +00:00
|
|
|
fp+= 3;
|
|
|
|
}
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
else {
|
2005-04-16 15:51:44 +00:00
|
|
|
short dnr;
|
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)) {
|
2010-07-14 17:47:58 +00:00
|
|
|
dnr= nr= 2+ cu->bevresol;
|
2012-03-24 06:18:31 +00:00
|
|
|
if ( (cu->flag & (CU_FRONT|CU_BACK))==0)
|
2010-07-14 17:47:58 +00:00
|
|
|
nr= 3+ 2*cu->bevresol;
|
|
|
|
|
|
|
|
dl= MEM_callocN(sizeof(DispList), "makebevelcurve p1");
|
|
|
|
dl->verts= MEM_mallocN(nr*3*sizeof(float), "makebevelcurve p1");
|
|
|
|
BLI_addtail(disp, dl);
|
|
|
|
dl->type= DL_SEGM;
|
|
|
|
dl->parts= 1;
|
|
|
|
dl->flag= DL_BACK_CURVE;
|
|
|
|
dl->nr= nr;
|
|
|
|
|
|
|
|
/* half a circle */
|
|
|
|
fp= dl->verts;
|
|
|
|
dangle= (0.5*M_PI/(dnr-1));
|
|
|
|
angle= -(nr-1)*dangle;
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
for (a=0; a<nr; a++) {
|
2010-07-14 17:47:58 +00:00
|
|
|
fp[0]= 0.0;
|
2011-03-28 04:22:50 +00:00
|
|
|
fp[1]= (float)(cosf(angle)*(cu->ext2));
|
|
|
|
fp[2]= (float)(sinf(angle)*(cu->ext2)) - cu->ext1;
|
2010-07-14 17:47:58 +00:00
|
|
|
angle+= dangle;
|
|
|
|
fp+= 3;
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2004-10-31 13:51:36 +00:00
|
|
|
|
|
|
|
/* part 2, sidefaces */
|
2012-03-24 06:18:31 +00:00
|
|
|
if (cu->ext1!=0.0f) {
|
2004-10-31 13:51:36 +00:00
|
|
|
nr= 2;
|
|
|
|
|
|
|
|
dl= MEM_callocN(sizeof(DispList), "makebevelcurve p2");
|
|
|
|
dl->verts= MEM_callocN(nr*3*sizeof(float), "makebevelcurve p2");
|
|
|
|
BLI_addtail(disp, dl);
|
|
|
|
dl->type= DL_SEGM;
|
|
|
|
dl->parts= 1;
|
|
|
|
dl->nr= nr;
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
fp= dl->verts;
|
2004-10-31 13:51:36 +00:00
|
|
|
fp[1]= cu->ext2;
|
|
|
|
fp[2]= -cu->ext1;
|
|
|
|
fp[4]= cu->ext2;
|
|
|
|
fp[5]= cu->ext1;
|
2005-04-16 15:51:44 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if ( (cu->flag & (CU_FRONT|CU_BACK))==0) {
|
2005-04-16 15:51:44 +00:00
|
|
|
dl= MEM_dupallocN(dl);
|
|
|
|
dl->verts= MEM_dupallocN(dl->verts);
|
|
|
|
BLI_addtail(disp, dl);
|
|
|
|
|
|
|
|
fp= dl->verts;
|
|
|
|
fp[1]= -fp[1];
|
|
|
|
fp[2]= -fp[2];
|
|
|
|
fp[4]= -fp[4];
|
|
|
|
fp[5]= -fp[5];
|
|
|
|
}
|
2004-10-31 13:51:36 +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)) {
|
2010-07-14 17:47:58 +00:00
|
|
|
dnr= nr= 2+ cu->bevresol;
|
2012-03-24 06:18:31 +00:00
|
|
|
if ( (cu->flag & (CU_FRONT|CU_BACK))==0)
|
2010-07-14 17:47:58 +00:00
|
|
|
nr= 3+ 2*cu->bevresol;
|
|
|
|
|
|
|
|
dl= MEM_callocN(sizeof(DispList), "makebevelcurve p3");
|
|
|
|
dl->verts= MEM_mallocN(nr*3*sizeof(float), "makebevelcurve p3");
|
|
|
|
BLI_addtail(disp, dl);
|
|
|
|
dl->type= DL_SEGM;
|
|
|
|
dl->flag= DL_FRONT_CURVE;
|
|
|
|
dl->parts= 1;
|
|
|
|
dl->nr= nr;
|
|
|
|
|
|
|
|
/* half a circle */
|
|
|
|
fp= dl->verts;
|
|
|
|
angle= 0.0;
|
|
|
|
dangle= (0.5*M_PI/(dnr-1));
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
for (a=0; a<nr; a++) {
|
2010-07-14 17:47:58 +00:00
|
|
|
fp[0]= 0.0;
|
2011-03-28 04:22:50 +00:00
|
|
|
fp[1]= (float)(cosf(angle)*(cu->ext2));
|
|
|
|
fp[2]= (float)(sinf(angle)*(cu->ext2)) + cu->ext1;
|
2010-07-14 17:47:58 +00:00
|
|
|
angle+= dangle;
|
|
|
|
fp+= 3;
|
|
|
|
}
|
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,
|
|
|
|
float *labda, float *mu, float vec[3])
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
/* return:
|
2012-03-03 20:19:11 +00:00
|
|
|
* -1: colliniar
|
|
|
|
* 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;
|
|
|
|
|
|
|
|
deler= (v1[cox]-v2[cox])*(v3[coy]-v4[coy])-(v3[cox]-v4[cox])*(v1[coy]-v2[coy]);
|
2012-03-24 06:18:31 +00:00
|
|
|
if (deler==0.0f) return -1;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
*labda= (v1[coy]-v3[coy])*(v3[cox]-v4[cox])-(v1[cox]-v3[cox])*(v3[coy]-v4[coy]);
|
|
|
|
*labda= -(*labda/deler);
|
|
|
|
|
|
|
|
deler= v3[coy]-v4[coy];
|
2012-03-24 06:18:31 +00:00
|
|
|
if (deler==0) {
|
2002-10-12 11:37:38 +00:00
|
|
|
deler=v3[cox]-v4[cox];
|
|
|
|
*mu= -(*labda*(v2[cox]-v1[cox])+v1[cox]-v3[cox])/deler;
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
|
|
|
else {
|
2002-10-12 11:37:38 +00:00
|
|
|
*mu= -(*labda*(v2[coy]-v1[coy])+v1[coy]-v3[coy])/deler;
|
|
|
|
}
|
|
|
|
vec[cox]= *labda*(v2[cox]-v1[cox])+v1[cox];
|
|
|
|
vec[coy]= *labda*(v2[coy]-v1[coy])+v1[coy];
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (*labda>=0.0f && *labda<=1.0f && *mu>=0.0f && *mu<=1.0f) {
|
|
|
|
if (*labda==0.0f || *labda==1.0f || *mu==0.0f || *mu==1.0f) return 1;
|
2002-10-12 11:37:38 +00:00
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-29 15:47:02 +00:00
|
|
|
static short bevelinside(BevList *bl1, BevList *bl2)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2003-04-25 15:48:11 +00:00
|
|
|
/* is bl2 INSIDE bl1 ? with left-right method and "labda's" */
|
|
|
|
/* 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;
|
|
|
|
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
|
|
|
|
|
|
|
bevp= (BevPoint *)(bl2+1);
|
2009-09-10 02:57:25 +00:00
|
|
|
hvec1[0]= bevp->vec[0];
|
|
|
|
hvec1[1]= bevp->vec[1];
|
2002-10-12 11:37:38 +00:00
|
|
|
hvec1[2]= 0.0;
|
2012-04-29 15:47:02 +00:00
|
|
|
copy_v3_v3(hvec2, hvec1);
|
2002-10-12 11:37:38 +00:00
|
|
|
hvec2[0]+=1000;
|
|
|
|
|
2003-04-25 15:48:11 +00:00
|
|
|
/* test it with all edges of potential surounding poly */
|
|
|
|
/* count number of transitions left-right */
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
bevp= (BevPoint *)(bl1+1);
|
|
|
|
nr= bl1->nr;
|
|
|
|
prevbevp= bevp+(nr-1);
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
while (nr--) {
|
2010-02-03 21:33:22 +00:00
|
|
|
min= prevbevp->vec[1];
|
2009-09-10 02:57:25 +00:00
|
|
|
max= bevp->vec[1];
|
2012-03-24 06:18:31 +00:00
|
|
|
if (max<min) {
|
2002-10-12 11:37:38 +00:00
|
|
|
min= max;
|
2009-09-10 02:57:25 +00:00
|
|
|
max= prevbevp->vec[1];
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
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 */
|
2009-09-10 02:57:25 +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) {
|
|
|
|
if (vec[0]<hvec1[0]) links++;
|
2002-10-12 11:37:38 +00:00
|
|
|
else rechts++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
prevbevp= bevp;
|
|
|
|
bevp++;
|
|
|
|
}
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if ( (links & 1) && (rechts & 1) ) return 1;
|
2002-10-12 11:37:38 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct bevelsort {
|
|
|
|
float left;
|
|
|
|
BevList *bl;
|
|
|
|
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
|
|
|
{
|
2012-04-29 15:47:02 +00:00
|
|
|
const struct bevelsort *x1=a1, *x2=a2;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-03-24 06:18:31 +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
|
|
|
|
2006-02-07 19:59:02 +00:00
|
|
|
static void calc_bevel_sin_cos(float x1, float y1, float x2, float y2, float *sina, float *cosa)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
float t01, t02, x3, y3;
|
|
|
|
|
|
|
|
t01= (float)sqrt(x1*x1+y1*y1);
|
|
|
|
t02= (float)sqrt(x2*x2+y2*y2);
|
2012-03-24 06:18:31 +00:00
|
|
|
if (t01==0.0f) t01= 1.0f;
|
|
|
|
if (t02==0.0f) t02= 1.0f;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
x1/=t01;
|
|
|
|
y1/=t01;
|
|
|
|
x2/=t02;
|
|
|
|
y2/=t02;
|
|
|
|
|
|
|
|
t02= x1*x2+y1*y2;
|
2012-03-24 06:18:31 +00:00
|
|
|
if (fabs(t02)>=1.0) t02= .5*M_PI;
|
2002-10-12 11:37:38 +00:00
|
|
|
else t02= (saacos(t02))/2.0f;
|
|
|
|
|
|
|
|
t02= (float)sin(t02);
|
2012-03-24 06:18:31 +00:00
|
|
|
if (t02==0.0f) t02= 1.0f;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
x3= x1-x2;
|
|
|
|
y3= y1-y2;
|
2012-03-24 06:18:31 +00:00
|
|
|
if (x3==0 && y3==0) {
|
2002-10-12 11:37:38 +00:00
|
|
|
x3= y1;
|
|
|
|
y3= -x1;
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
|
|
|
else {
|
2002-10-12 11:37:38 +00:00
|
|
|
t01= (float)sqrt(x3*x3+y3*y3);
|
|
|
|
x3/=t01;
|
|
|
|
y3/=t01;
|
|
|
|
}
|
|
|
|
|
|
|
|
*sina= -y3/t02;
|
|
|
|
*cosa= x3/t02;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-04-21 11:59:47 +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-03-24 06:18:31 +00:00
|
|
|
if (tilt_array==NULL && radius_array==NULL)
|
2009-09-10 02:57:25 +00:00
|
|
|
return;
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
last= nu->bezt+(nu->pntsu-1);
|
|
|
|
|
2003-04-25 15:48:11 +00:00
|
|
|
/* returns a point */
|
2012-03-24 06:18:31 +00:00
|
|
|
if (prevbezt==nu->bezt) {
|
|
|
|
if (nu->flagu & CU_NURB_CYCLIC) pprev= last;
|
2002-10-12 11:37:38 +00:00
|
|
|
else pprev= prevbezt;
|
|
|
|
}
|
|
|
|
else pprev= prevbezt-1;
|
|
|
|
|
2003-04-25 15:48:11 +00:00
|
|
|
/* next point */
|
2012-03-24 06:18:31 +00:00
|
|
|
if (bezt==last) {
|
|
|
|
if (nu->flagu & CU_NURB_CYCLIC) next= nu->bezt;
|
2002-10-12 11:37:38 +00:00
|
|
|
else next= bezt;
|
|
|
|
}
|
|
|
|
else next= bezt+1;
|
|
|
|
|
|
|
|
fac= 0.0;
|
2006-02-07 19:59:02 +00:00
|
|
|
dfac= 1.0f/(float)resolu;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
for (a=0; a<resolu; a++, fac+= dfac) {
|
2008-09-23 13:35:32 +00:00
|
|
|
if (tilt_array) {
|
2010-08-12 06:28:46 +00:00
|
|
|
if (nu->tilt_interp==KEY_CU_EASE) { /* May as well support for tilt also 2.47 ease interp */
|
2009-09-10 02:57:25 +00:00
|
|
|
*tilt_array = prevbezt->alfa + (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);
|
2009-09-10 02:57:25 +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
|
|
|
}
|
2009-09-10 02:57:25 +00:00
|
|
|
|
|
|
|
tilt_array = (float *)(((char *)tilt_array) + stride);
|
2008-09-23 13:35:32 +00:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2008-09-23 13:35:32 +00:00
|
|
|
if (radius_array) {
|
2010-08-12 06:28:46 +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 */
|
2009-09-10 02:57:25 +00:00
|
|
|
*radius_array = prevbezt->radius + (bezt->radius - prevbezt->radius)*(3.0f*fac*fac - 2.0f*fac*fac*fac);
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
|
|
|
else {
|
2008-09-23 13:35:32 +00:00
|
|
|
|
|
|
|
/* reuse interpolation from tilt if we can */
|
|
|
|
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
|
|
|
}
|
2009-09-10 02:57:25 +00:00
|
|
|
*radius_array= t[0]*pprev->radius + t[1]*prevbezt->radius + t[2]*bezt->radius + t[3]*next->radius;
|
2008-09-23 13:35:32 +00:00
|
|
|
}
|
2009-09-10 02:57:25 +00:00
|
|
|
|
|
|
|
radius_array = (float *)(((char *)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 */
|
|
|
|
*weight_array = prevbezt->weight + (bezt->weight - prevbezt->weight)*(3.0f*fac*fac - 2.0f*fac*fac*fac);
|
|
|
|
|
|
|
|
weight_array = (float *)(((char *)weight_array) + stride);
|
|
|
|
}
|
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 */
|
|
|
|
|
|
|
|
/* correct non-cyclic cases by copying direction and rotation
|
|
|
|
* values onto the first & last end-points */
|
2009-11-21 14:35:28 +00:00
|
|
|
static void bevel_list_cyclic_fix_3D(BevList *bl)
|
2009-09-11 15:35:30 +00:00
|
|
|
{
|
|
|
|
BevPoint *bevp, *bevp1;
|
|
|
|
|
|
|
|
bevp= (BevPoint *)(bl+1);
|
|
|
|
bevp1= bevp+1;
|
2011-10-28 12:40:15 +00:00
|
|
|
copy_qt_qt(bevp->quat, bevp1->quat);
|
|
|
|
copy_v3_v3(bevp->dir, bevp1->dir);
|
|
|
|
copy_v3_v3(bevp->tan, bevp1->tan);
|
2009-09-11 15:35:30 +00:00
|
|
|
bevp= (BevPoint *)(bl+1);
|
|
|
|
bevp+= (bl->nr-1);
|
|
|
|
bevp1= bevp-1;
|
2011-10-28 12:40:15 +00:00
|
|
|
copy_qt_qt(bevp->quat, bevp1->quat);
|
|
|
|
copy_v3_v3(bevp->dir, bevp1->dir);
|
|
|
|
copy_v3_v3(bevp->tan, bevp1->tan);
|
2009-09-11 15:35:30 +00:00
|
|
|
}
|
|
|
|
/* utility for make_bevel_list_3D_* funcs */
|
|
|
|
static void bevel_list_calc_bisect(BevList *bl)
|
|
|
|
{
|
|
|
|
BevPoint *bevp2, *bevp1, *bevp0;
|
|
|
|
int nr;
|
|
|
|
|
|
|
|
bevp2= (BevPoint *)(bl+1);
|
|
|
|
bevp1= bevp2+(bl->nr-1);
|
|
|
|
bevp0= bevp1-1;
|
|
|
|
|
|
|
|
nr= bl->nr;
|
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
|
|
|
|
|
|
|
bevp0= bevp1;
|
|
|
|
bevp1= bevp2;
|
|
|
|
bevp2++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
static void bevel_list_flip_tangents(BevList *bl)
|
|
|
|
{
|
|
|
|
BevPoint *bevp2, *bevp1, *bevp0;
|
|
|
|
int nr;
|
|
|
|
|
|
|
|
bevp2= (BevPoint *)(bl+1);
|
|
|
|
bevp1= bevp2+(bl->nr-1);
|
|
|
|
bevp0= bevp1-1;
|
|
|
|
|
|
|
|
nr= bl->nr;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (nr--) {
|
|
|
|
if (RAD2DEGF(angle_v2v2(bevp0->tan, bevp1->tan)) > 90.0f)
|
2009-11-10 20:43:45 +00:00
|
|
|
negate_v3(bevp1->tan);
|
2009-09-11 15:35:30 +00:00
|
|
|
|
|
|
|
bevp0= bevp1;
|
|
|
|
bevp1= bevp2;
|
|
|
|
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];
|
|
|
|
|
|
|
|
bevp2= (BevPoint *)(bl+1);
|
|
|
|
bevp1= bevp2+(bl->nr-1);
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
bevp1= bevp2;
|
|
|
|
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-03-24 06:18:31 +00:00
|
|
|
for (a=0; a < smooth_iter; a++) {
|
2009-09-11 15:35:30 +00:00
|
|
|
|
|
|
|
bevp2= (BevPoint *)(bl+1);
|
|
|
|
bevp1= bevp2+(bl->nr-1);
|
|
|
|
bevp0= bevp1-1;
|
|
|
|
|
|
|
|
nr= bl->nr;
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (bl->poly== -1) { /* check its not cyclic */
|
2009-09-11 15:35:30 +00:00
|
|
|
/* skip the first point */
|
2011-01-10 03:58:07 +00:00
|
|
|
/* bevp0= bevp1; */
|
2009-09-11 15:35:30 +00:00
|
|
|
bevp1= bevp2;
|
|
|
|
bevp2++;
|
|
|
|
nr--;
|
|
|
|
|
|
|
|
bevp0= bevp1;
|
|
|
|
bevp1= bevp2;
|
|
|
|
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
|
|
|
|
|
|
|
|
2011-01-10 03:58:07 +00:00
|
|
|
/* bevp0= bevp1; */ /* UNUSED */
|
2009-09-11 15:35:30 +00:00
|
|
|
bevp1= bevp2;
|
|
|
|
bevp2++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void make_bevel_list_3D_zup(BevList *bl)
|
|
|
|
{
|
|
|
|
BevPoint *bevp2, *bevp1, *bevp0; /* standard for all make_bevel_list_3D_* funcs */
|
|
|
|
int nr;
|
|
|
|
|
|
|
|
bevp2= (BevPoint *)(bl+1);
|
|
|
|
bevp1= bevp2+(bl->nr-1);
|
|
|
|
bevp0= bevp1-1;
|
|
|
|
|
|
|
|
nr= bl->nr;
|
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);
|
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
|
|
|
|
|
|
|
bevp0= bevp1;
|
|
|
|
bevp1= bevp2;
|
|
|
|
bevp2++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
bevp2= (BevPoint *)(bl+1);
|
|
|
|
bevp1= bevp2+(bl->nr-1);
|
|
|
|
bevp0= bevp1-1;
|
|
|
|
|
|
|
|
nr= bl->nr;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (nr--) {
|
2009-09-11 15:35:30 +00:00
|
|
|
|
2012-03-24 06:18:31 +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 {
|
2009-11-10 20:43:45 +00:00
|
|
|
float angle= angle_normalized_v3v3(bevp0->dir, bevp1->dir);
|
2009-09-11 15:35:30 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (angle > 0.0f) { /* otherwise we can keep as is */
|
2011-02-13 10:52:18 +00:00
|
|
|
float cross_tmp[3];
|
2009-11-10 20:43:45 +00:00
|
|
|
cross_v3_v3v3(cross_tmp, bevp0->dir, bevp1->dir);
|
|
|
|
axis_angle_to_quat(q, cross_tmp, angle);
|
|
|
|
mul_qt_qtqt(bevp1->quat, q, bevp0->quat);
|
2009-09-11 15:35:30 +00:00
|
|
|
}
|
|
|
|
else {
|
2011-10-28 12:40:15 +00:00
|
|
|
copy_qt_qt(bevp1->quat, bevp0->quat);
|
2009-09-11 15:35:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bevp0= bevp1;
|
|
|
|
bevp1= bevp2;
|
|
|
|
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-04-29 15:47:02 +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;
|
|
|
|
|
|
|
|
|
|
|
|
bevp_first= (BevPoint *)(bl+1);
|
|
|
|
bevp_first+= bl->nr-1;
|
|
|
|
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
|
|
|
|
* better to align the angle quat roll's before comparing */
|
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2009-11-10 20:43:45 +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;
|
|
|
|
|
|
|
|
bevp2= (BevPoint *)(bl+1);
|
|
|
|
bevp1= bevp2+(bl->nr-1);
|
|
|
|
bevp0= bevp1-1;
|
|
|
|
|
|
|
|
nr= bl->nr;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (nr--) {
|
2009-09-11 15:35:30 +00:00
|
|
|
ang_fac= angle * (1.0f-((float)nr/bl->nr)); /* also works */
|
|
|
|
|
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
|
|
|
|
|
|
|
bevp0= bevp1;
|
|
|
|
bevp1= bevp2;
|
|
|
|
bevp2++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void make_bevel_list_3D_tangent(BevList *bl)
|
|
|
|
{
|
|
|
|
BevPoint *bevp2, *bevp1, *bevp0; /* standard for all make_bevel_list_3D_* funcs */
|
|
|
|
int nr;
|
|
|
|
|
|
|
|
float bevp0_tan[3], cross_tmp[3];
|
|
|
|
|
|
|
|
bevel_list_calc_bisect(bl);
|
2012-03-24 06:18:31 +00:00
|
|
|
if (bl->poly== -1) /* check its not cyclic */
|
2009-11-21 14:35:28 +00:00
|
|
|
bevel_list_cyclic_fix_3D(bl); // XXX - run this now so tangents will be right before doing the flipping
|
2009-09-11 15:35:30 +00:00
|
|
|
bevel_list_flip_tangents(bl);
|
|
|
|
|
|
|
|
/* correct the tangents */
|
|
|
|
bevp2= (BevPoint *)(bl+1);
|
|
|
|
bevp1= bevp2+(bl->nr-1);
|
|
|
|
bevp0= bevp1-1;
|
|
|
|
|
|
|
|
nr= bl->nr;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (nr--) {
|
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);
|
|
|
|
cross_v3_v3v3(bevp1->tan, cross_tmp, bevp1->dir);
|
|
|
|
normalize_v3(bevp1->tan);
|
2009-09-11 15:35:30 +00:00
|
|
|
|
|
|
|
bevp0= bevp1;
|
|
|
|
bevp1= bevp2;
|
|
|
|
bevp2++;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* now for the real twist calc */
|
|
|
|
bevp2= (BevPoint *)(bl+1);
|
|
|
|
bevp1= bevp2+(bl->nr-1);
|
|
|
|
bevp0= bevp1-1;
|
|
|
|
|
2011-10-28 12:40:15 +00:00
|
|
|
copy_v3_v3(bevp0_tan, bevp0->tan);
|
2009-09-11 15:35:30 +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
|
|
|
|
2011-01-10 03:58:07 +00:00
|
|
|
/* bevp0= bevp1; */ /* UNUSED */
|
2009-09-11 15:35:30 +00:00
|
|
|
bevp1= bevp2;
|
|
|
|
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) {
|
2009-09-11 15:35:30 +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);
|
|
|
|
}
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (bl->poly== -1) /* check its not cyclic */
|
2009-11-21 14:35:28 +00:00
|
|
|
bevel_list_cyclic_fix_3D(bl);
|
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];
|
|
|
|
|
|
|
|
BevPoint *bevp2= (BevPoint *)(bl+1);
|
|
|
|
BevPoint *bevp1= bevp2+1;
|
|
|
|
|
|
|
|
/* 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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-04-28 16:49:00 +00:00
|
|
|
void BKE_curve_bevelList_make(Object *ob)
|
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)
|
|
|
|
* - separate in individual blicks with BoundBox
|
|
|
|
* - AutoHole detection
|
|
|
|
*/
|
2002-10-12 11:37:38 +00:00
|
|
|
Curve *cu;
|
|
|
|
Nurb *nu;
|
|
|
|
BezTriple *bezt, *prevbezt;
|
|
|
|
BPoint *bp;
|
|
|
|
BevList *bl, *blnew, *blnext;
|
|
|
|
BevPoint *bevp, *bevp2, *bevp1 = NULL, *bevp0;
|
2009-09-11 15:35:30 +00:00
|
|
|
float min, inp, x1, x2, y1, y2;
|
2002-10-12 11:37:38 +00:00
|
|
|
struct bevelsort *sortdata, *sd, *sd1;
|
2009-10-21 17:56:26 +00:00
|
|
|
int a, b, nr, poly, resolu = 0, len = 0;
|
2010-04-21 11:59:47 +00:00
|
|
|
int do_tilt, do_radius, do_weight;
|
2008-09-23 13:35:32 +00:00
|
|
|
|
2003-04-25 15:48:11 +00:00
|
|
|
/* this function needs an object, because of tflag and upflag */
|
2002-10-12 11:37:38 +00:00
|
|
|
cu= ob->data;
|
|
|
|
|
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; */
|
2008-09-23 13:35:32 +00:00
|
|
|
|
2003-04-25 15:48:11 +00:00
|
|
|
/* STEP 1: MAKE POLYS */
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
BLI_freelistN(&(cu->bev));
|
2012-03-24 06:18:31 +00:00
|
|
|
if (cu->editnurb && ob->type!=OB_FONT) {
|
2012-04-28 16:49:00 +00:00
|
|
|
ListBase *nurbs= BKE_curve_editNurbs_get(cu);
|
2012-03-24 06:18:31 +00:00
|
|
|
nu = nurbs->first;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nu = cu->nurb.first;
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
while (nu) {
|
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 */
|
2010-04-21 11:59:47 +00:00
|
|
|
do_weight = 1;
|
2008-09-23 13:35:32 +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)) {
|
2008-09-23 13:35:32 +00:00
|
|
|
bl= MEM_callocN(sizeof(BevList)+1*sizeof(BevPoint), "makeBevelList1");
|
2007-12-03 22:42:48 +00:00
|
|
|
BLI_addtail(&(cu->bev), bl);
|
|
|
|
bl->nr= 0;
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (G.rendering && cu->resolu_ren!=0)
|
2006-02-07 19:59:02 +00:00
|
|
|
resolu= cu->resolu_ren;
|
|
|
|
else
|
|
|
|
resolu= nu->resolu;
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (nu->type == CU_POLY) {
|
2008-01-11 22:54:02 +00:00
|
|
|
len= nu->pntsu;
|
2008-09-23 13:35:32 +00:00
|
|
|
bl= MEM_callocN(sizeof(BevList)+len*sizeof(BevPoint), "makeBevelList2");
|
2002-10-12 11:37:38 +00:00
|
|
|
BLI_addtail(&(cu->bev), bl);
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (nu->flagu & CU_NURB_CYCLIC) bl->poly= 0;
|
2002-10-12 11:37:38 +00:00
|
|
|
else bl->poly= -1;
|
|
|
|
bl->nr= len;
|
2009-09-10 02:57:25 +00:00
|
|
|
bl->dupe_nr= 0;
|
2002-10-12 11:37:38 +00:00
|
|
|
bevp= (BevPoint *)(bl+1);
|
|
|
|
bp= nu->bp;
|
|
|
|
|
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);
|
2002-10-12 11:37:38 +00:00
|
|
|
bevp->alfa= bp->alfa;
|
2008-09-23 13:35:32 +00:00
|
|
|
bevp->radius= bp->radius;
|
2010-04-21 11:59:47 +00:00
|
|
|
bevp->weight= bp->weight;
|
2009-09-10 02:57:25 +00:00
|
|
|
bevp->split_tag= TRUE;
|
2002-10-12 11:37:38 +00:00
|
|
|
bevp++;
|
|
|
|
bp++;
|
|
|
|
}
|
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
else if (nu->type == CU_BEZIER) {
|
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
|
|
|
len= resolu*(nu->pntsu+ (nu->flagu & CU_NURB_CYCLIC) -1)+1; /* in case last point is not cyclic */
|
2008-09-23 13:35:32 +00:00
|
|
|
bl= MEM_callocN(sizeof(BevList)+len*sizeof(BevPoint), "makeBevelBPoints");
|
2002-10-12 11:37:38 +00:00
|
|
|
BLI_addtail(&(cu->bev), bl);
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (nu->flagu & CU_NURB_CYCLIC) bl->poly= 0;
|
2002-10-12 11:37:38 +00:00
|
|
|
else bl->poly= -1;
|
|
|
|
bevp= (BevPoint *)(bl+1);
|
|
|
|
|
|
|
|
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++;
|
|
|
|
prevbezt= nu->bezt+(nu->pntsu-1);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
prevbezt= bezt;
|
|
|
|
bezt++;
|
|
|
|
}
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
while (a--) {
|
|
|
|
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]);
|
2002-10-12 11:37:38 +00:00
|
|
|
bevp->alfa= prevbezt->alfa;
|
2008-09-23 13:35:32 +00:00
|
|
|
bevp->radius= prevbezt->radius;
|
2010-04-21 11:59:47 +00:00
|
|
|
bevp->weight= prevbezt->weight;
|
2009-09-10 02:57:25 +00:00
|
|
|
bevp->split_tag= TRUE;
|
|
|
|
bevp->dupe_tag= FALSE;
|
2002-10-12 11:37:38 +00:00
|
|
|
bevp++;
|
|
|
|
bl->nr++;
|
2009-09-10 02:57:25 +00:00
|
|
|
bl->dupe_nr= 1;
|
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;
|
|
|
|
|
|
|
|
/* BevPoint must stay aligned to 4 so sizeof(BevPoint)/sizeof(float) works */
|
2012-03-24 06:18:31 +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
|
|
|
}
|
2002-10-12 11:37:38 +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,
|
|
|
|
do_tilt ? &bevp->alfa : NULL,
|
|
|
|
do_radius ? &bevp->radius : NULL,
|
|
|
|
do_weight ? &bevp->weight : NULL,
|
|
|
|
resolu, sizeof(BevPoint));
|
2009-09-11 15:35:30 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-03-24 06:18:31 +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-03-24 06:18:31 +00:00
|
|
|
if (prevbezt->h1==prevbezt->h2) {
|
|
|
|
if (prevbezt->h1==0 || prevbezt->h1==HD_VECT) bevp->split_tag= TRUE;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-03-24 06:18:31 +00:00
|
|
|
if (prevbezt->h1==0 || prevbezt->h1==HD_VECT) bevp->split_tag= TRUE;
|
|
|
|
else if (prevbezt->h2==0 || prevbezt->h2==HD_VECT) bevp->split_tag= TRUE;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2006-02-07 19:59:02 +00:00
|
|
|
bl->nr+= resolu;
|
2009-09-10 02:57:25 +00:00
|
|
|
bevp+= resolu;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
prevbezt= bezt;
|
|
|
|
bezt++;
|
|
|
|
}
|
|
|
|
|
2012-03-24 06:18:31 +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]);
|
2006-11-16 11:49:14 +00:00
|
|
|
bevp->alfa= prevbezt->alfa;
|
2008-09-23 13:35:32 +00:00
|
|
|
bevp->radius= prevbezt->radius;
|
2010-04-21 11:59:47 +00:00
|
|
|
bevp->weight= prevbezt->weight;
|
2002-10-12 11:37:38 +00:00
|
|
|
bl->nr++;
|
|
|
|
}
|
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
else if (nu->type == CU_NURBS) {
|
|
|
|
if (nu->pntsv==1) {
|
2008-10-06 06:10:14 +00:00
|
|
|
len= (resolu*SEGMENTSU(nu));
|
|
|
|
|
2008-09-23 15:57:05 +00:00
|
|
|
bl= MEM_callocN(sizeof(BevList)+len*sizeof(BevPoint), "makeBevelList3");
|
2002-10-12 11:37:38 +00:00
|
|
|
BLI_addtail(&(cu->bev), bl);
|
|
|
|
bl->nr= len;
|
2009-09-10 02:57:25 +00:00
|
|
|
bl->dupe_nr= 0;
|
2012-03-24 06:18:31 +00:00
|
|
|
if (nu->flagu & CU_NURB_CYCLIC) bl->poly= 0;
|
2002-10-12 11:37:38 +00:00
|
|
|
else bl->poly= -1;
|
|
|
|
bevp= (BevPoint *)(bl+1);
|
|
|
|
|
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));
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
nu= nu->next;
|
|
|
|
}
|
|
|
|
|
2003-04-25 15:48:11 +00:00
|
|
|
/* STEP 2: DOUBLE POINTS AND AUTOMATIC RESOLUTION, REDUCE DATABLOCKS */
|
2002-10-12 11:37:38 +00:00
|
|
|
bl= cu->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 */
|
|
|
|
nr= bl->nr;
|
|
|
|
bevp1= (BevPoint *)(bl+1);
|
|
|
|
bevp0= bevp1+(nr-1);
|
|
|
|
nr--;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (nr--) {
|
|
|
|
if ( fabs(bevp0->vec[0]-bevp1->vec[0])<0.00001 ) {
|
|
|
|
if ( fabs(bevp0->vec[1]-bevp1->vec[1])<0.00001 ) {
|
|
|
|
if ( fabs(bevp0->vec[2]-bevp1->vec[2])<0.00001 ) {
|
2009-09-10 02:57:25 +00:00
|
|
|
bevp0->dupe_tag= TRUE;
|
|
|
|
bl->dupe_nr++;
|
2007-12-03 22:42:48 +00:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
2007-12-03 22:42:48 +00:00
|
|
|
bevp0= bevp1;
|
|
|
|
bevp1++;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
bl= bl->next;
|
|
|
|
}
|
|
|
|
bl= cu->bev.first;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (bl) {
|
2002-10-12 11:37:38 +00:00
|
|
|
blnext= bl->next;
|
2012-03-24 06:18:31 +00:00
|
|
|
if (bl->nr && bl->dupe_nr) {
|
2009-09-10 02:57:25 +00:00
|
|
|
nr= bl->nr- bl->dupe_nr+1; /* +1 because vectorbezier sets flag too */
|
2008-09-23 13:35:32 +00:00
|
|
|
blnew= MEM_mallocN(sizeof(BevList)+nr*sizeof(BevPoint), "makeBevelList4");
|
2002-10-12 11:37:38 +00:00
|
|
|
memcpy(blnew, bl, sizeof(BevList));
|
|
|
|
blnew->nr= 0;
|
|
|
|
BLI_remlink(&(cu->bev), bl);
|
2012-04-29 15:47:02 +00:00
|
|
|
BLI_insertlinkbefore(&(cu->bev), blnext, blnew); /* to make sure bevlijst is tuned with nurblist */
|
2002-10-12 11:37:38 +00:00
|
|
|
bevp0= (BevPoint *)(bl+1);
|
|
|
|
bevp1= (BevPoint *)(blnew+1);
|
|
|
|
nr= bl->nr;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (nr--) {
|
|
|
|
if (bevp0->dupe_tag==0) {
|
2002-10-12 11:37:38 +00:00
|
|
|
memcpy(bevp1, bevp0, sizeof(BevPoint));
|
|
|
|
bevp1++;
|
|
|
|
blnew->nr++;
|
|
|
|
}
|
|
|
|
bevp0++;
|
|
|
|
}
|
|
|
|
MEM_freeN(bl);
|
2009-09-10 02:57:25 +00:00
|
|
|
blnew->dupe_nr= 0;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
bl= blnext;
|
|
|
|
}
|
|
|
|
|
2009-09-07 08:37:28 +00:00
|
|
|
/* STEP 3: POLYS COUNT AND AUTOHOLE */
|
2002-10-12 11:37:38 +00:00
|
|
|
bl= cu->bev.first;
|
|
|
|
poly= 0;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (bl) {
|
|
|
|
if (bl->nr && bl->poly>=0) {
|
2002-10-12 11:37:38 +00:00
|
|
|
poly++;
|
|
|
|
bl->poly= poly;
|
2009-09-07 08:37:28 +00:00
|
|
|
bl->hole= 0;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
bl= bl->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-04-25 15:48:11 +00:00
|
|
|
/* find extreme left points, also test (turning) direction */
|
2012-03-24 06:18:31 +00:00
|
|
|
if (poly>0) {
|
2002-10-12 11:37:38 +00:00
|
|
|
sd= sortdata= MEM_mallocN(sizeof(struct bevelsort)*poly, "makeBevelList5");
|
|
|
|
bl= cu->bev.first;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (bl) {
|
|
|
|
if (bl->poly>0) {
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
min= 300000.0;
|
|
|
|
bevp= (BevPoint *)(bl+1);
|
|
|
|
nr= bl->nr;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (nr--) {
|
|
|
|
if (min>bevp->vec[0]) {
|
2009-09-10 02:57:25 +00:00
|
|
|
min= bevp->vec[0];
|
2002-10-12 11:37:38 +00:00
|
|
|
bevp1= bevp;
|
|
|
|
}
|
|
|
|
bevp++;
|
|
|
|
}
|
|
|
|
sd->bl= bl;
|
|
|
|
sd->left= min;
|
|
|
|
|
|
|
|
bevp= (BevPoint *)(bl+1);
|
2012-03-24 06:18:31 +00:00
|
|
|
if (bevp1== bevp) bevp0= bevp+ (bl->nr-1);
|
2002-10-12 11:37:38 +00:00
|
|
|
else bevp0= bevp1-1;
|
|
|
|
bevp= bevp+ (bl->nr-1);
|
2012-03-24 06:18:31 +00:00
|
|
|
if (bevp1== bevp) bevp2= (BevPoint *)(bl+1);
|
2002-10-12 11:37:38 +00:00
|
|
|
else bevp2= bevp1+1;
|
|
|
|
|
2009-09-10 02:57:25 +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-03-24 06:18:31 +00:00
|
|
|
if (inp > 0.0f) sd->dir= 1;
|
2002-10-12 11:37:38 +00:00
|
|
|
else sd->dir= 0;
|
|
|
|
|
|
|
|
sd++;
|
|
|
|
}
|
|
|
|
|
|
|
|
bl= bl->next;
|
|
|
|
}
|
2012-04-29 15:47:02 +00:00
|
|
|
qsort(sortdata, poly, sizeof(struct bevelsort), vergxcobev);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
sd= sortdata+1;
|
2012-03-24 06:18:31 +00:00
|
|
|
for (a=1; a<poly; a++, sd++) {
|
2003-04-25 15:48:11 +00:00
|
|
|
bl= sd->bl; /* is bl a hole? */
|
2002-10-12 11:37:38 +00:00
|
|
|
sd1= sortdata+ (a-1);
|
2012-03-24 06:18:31 +00:00
|
|
|
for (b=a-1; b>=0; b--, sd1--) { /* all polys to the left */
|
|
|
|
if (bevelinside(sd1->bl, bl)) {
|
2009-09-07 08:37:28 +00:00
|
|
|
bl->hole= 1- sd1->bl->hole;
|
2002-10-12 11:37:38 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-04-25 15:48:11 +00:00
|
|
|
/* turning direction */
|
2012-03-24 06:18:31 +00:00
|
|
|
if ((cu->flag & CU_3D)==0) {
|
2002-10-12 11:37:38 +00:00
|
|
|
sd= sortdata;
|
2012-03-24 06:18:31 +00:00
|
|
|
for (a=0; a<poly; a++, sd++) {
|
|
|
|
if (sd->bl->hole==sd->dir) {
|
2002-10-12 11:37:38 +00:00
|
|
|
bl= sd->bl;
|
|
|
|
bevp1= (BevPoint *)(bl+1);
|
|
|
|
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-03-24 06:18:31 +00:00
|
|
|
if ((cu->flag & CU_3D)==0) {
|
2009-11-21 14:35:28 +00:00
|
|
|
/* note: bevp->dir and bevp->quat are not needed for beveling but are
|
|
|
|
* used when making a path from a 2D curve, therefor they need to be set - Campbell */
|
2009-09-11 15:35:30 +00:00
|
|
|
bl= cu->bev.first;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (bl) {
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (bl->nr < 2) {
|
2009-09-11 15:35:30 +00:00
|
|
|
/* do nothing */
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
else if (bl->nr==2) { /* 2 pnt, treat separate */
|
2009-09-11 15:35:30 +00:00
|
|
|
bevp2= (BevPoint *)(bl+1);
|
|
|
|
bevp1= bevp2+1;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2009-09-11 15:35:30 +00:00
|
|
|
x1= bevp1->vec[0]- bevp2->vec[0];
|
|
|
|
y1= bevp1->vec[1]- bevp2->vec[1];
|
2009-09-05 09:54:01 +00:00
|
|
|
|
2009-09-11 15:35:30 +00:00
|
|
|
calc_bevel_sin_cos(x1, y1, -x1, -y1, &(bevp1->sina), &(bevp1->cosa));
|
|
|
|
bevp2->sina= bevp1->sina;
|
|
|
|
bevp2->cosa= bevp1->cosa;
|
2009-11-21 14:35:28 +00:00
|
|
|
|
|
|
|
/* fill in dir & quat */
|
|
|
|
make_bevel_list_segment_3D(bl);
|
2009-09-11 15:35:30 +00:00
|
|
|
}
|
|
|
|
else {
|
2009-09-05 09:54:01 +00:00
|
|
|
bevp2= (BevPoint *)(bl+1);
|
|
|
|
bevp1= bevp2+(bl->nr-1);
|
|
|
|
bevp0= bevp1-1;
|
|
|
|
|
|
|
|
nr= bl->nr;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (nr--) {
|
2009-09-11 15:35:30 +00:00
|
|
|
x1= bevp1->vec[0]- bevp0->vec[0];
|
|
|
|
x2= bevp1->vec[0]- bevp2->vec[0];
|
|
|
|
y1= bevp1->vec[1]- bevp0->vec[1];
|
|
|
|
y2= bevp1->vec[1]- bevp2->vec[1];
|
2009-09-05 09:54:01 +00:00
|
|
|
|
2009-09-11 15:35:30 +00:00
|
|
|
calc_bevel_sin_cos(x1, y1, x2, y2, &(bevp1->sina), &(bevp1->cosa));
|
2009-09-05 09:54:01 +00:00
|
|
|
|
2009-11-21 14:35:28 +00:00
|
|
|
/* 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);
|
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
|
|
|
/* done with inline make_bevel_list_3D_zup */
|
|
|
|
|
2009-09-11 15:35:30 +00:00
|
|
|
bevp0= bevp1;
|
|
|
|
bevp1= bevp2;
|
|
|
|
bevp2++;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2009-09-05 09:54:01 +00:00
|
|
|
|
2009-09-11 15:35:30 +00:00
|
|
|
/* correct non-cyclic cases */
|
2012-03-24 06:18:31 +00:00
|
|
|
if (bl->poly== -1) {
|
2002-10-12 11:37:38 +00:00
|
|
|
bevp= (BevPoint *)(bl+1);
|
|
|
|
bevp1= bevp+1;
|
|
|
|
bevp->sina= bevp1->sina;
|
|
|
|
bevp->cosa= bevp1->cosa;
|
|
|
|
bevp= (BevPoint *)(bl+1);
|
|
|
|
bevp+= (bl->nr-1);
|
|
|
|
bevp1= bevp-1;
|
|
|
|
bevp->sina= bevp1->sina;
|
|
|
|
bevp->cosa= bevp1->cosa;
|
2009-11-21 14:35:28 +00:00
|
|
|
|
|
|
|
/* correct for the dir/quat, see above why its needed */
|
|
|
|
bevel_list_cyclic_fix_3D(bl);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
2009-09-11 15:35:30 +00:00
|
|
|
bl= bl->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else { /* 3D Curves */
|
|
|
|
bl= cu->bev.first;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (bl) {
|
2009-09-11 15:35:30 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (bl->nr < 2) {
|
2009-09-11 15:35:30 +00:00
|
|
|
/* do nothing */
|
|
|
|
}
|
2012-03-24 06:18:31 +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 {
|
|
|
|
make_bevel_list_3D(bl, (int)(resolu*cu->twist_smooth), cu->twist_mode);
|
|
|
|
}
|
|
|
|
bl= bl->next;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ****************** HANDLES ************** */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* handlecodes:
|
2010-01-22 23:51:31 +00:00
|
|
|
* 0: nothing, 1:auto, 2:vector, 3:aligned
|
2002-10-12 11:37:38 +00:00
|
|
|
*/
|
|
|
|
|
2.5: Blender "Animato" - New Animation System
Finally, here is the basic (functional) prototype of the new animation system which will allow for the infamous "everything is animatable", and which also addresses several of the more serious shortcomings of the old system. Unfortunately, this will break old animation files (especially right now, as I haven't written the version patching code yet), however, this is for the future.
Highlights of the new system:
* Scrapped IPO-Curves/IPO/(Action+Constraint-Channels)/Action system, and replaced it with F-Curve/Action.
- F-Curves (animators from other packages will feel at home with this name) replace IPO-Curves.
- The 'new' Actions, act as the containers for F-Curves, so that they can be reused. They are therefore more akin to the old 'IPO' blocks, except they do not have the blocktype restriction, so you can store materials/texture/geometry F-Curves in the same Action as Object transforms, etc.
* F-Curves use RNA-paths for Data Access, hence allowing "every" (where sensible/editable that is) user-accessible setting from RNA to be animated.
* Drivers are no longer mixed with Animation Data, so rigs will not be that easily broken and several dependency problems can be eliminated. (NOTE: drivers haven't been hooked up yet, but the code is in place)
* F-Curve modifier system allows useful 'large-scale' manipulation of F-Curve values, including (I've only included implemented ones here): envelope deform (similar to lattices to allow broad-scale reshaping of curves), curve generator (polynomial or py-expression), cycles (replacing the old cyclic extrapolation modes, giving more control over this). (NOTE: currently this cannot be tested, as there's not access to them, but the code is all in place)
* NLA system with 'tracks' (i.e. layers), and multiple strips per track. (NOTE: NLA system is not yet functional, as it's only partially coded still)
There are more nice things that I will be preparing some nice docs for soon, but for now, check for more details:
http://lists.blender.org/pipermail/bf-taskforce25/2009-January/000260.html
So, what currently works:
* I've implemented two basic operators for the 3D-view only to Insert and Delete Keyframes. These are tempolary ones only that will be replaced in due course with 'proper' code.
* Object Loc/Rot/Scale can be keyframed. Also, the colour of the 'active' material (Note: this should really be for nth material instead, but that doesn't work yet in RNA) can also be keyframed into the same datablock.
* Standard animation refresh (i.e. animation resulting from NLA and Action evaluation) is now done completely separate from drivers before anything else is done after a frame change. Drivers are handled after this in a separate pass, as dictated by depsgraph flags, etc.
Notes:
* Drivers haven't been hooked up yet
* Only objects and data directly linked to objects can be animated.
* Depsgraph will need further tweaks. Currently, I've only made sure that it will update some things in the most basic cases (i.e. frame change).
* Animation Editors are currently broken (in terms of editing stuff). This will be my next target (priority to get Dopesheet working first, then F-Curve editor - i.e. old IPO Editor)
* I've had to put in large chunks of XXX sandboxing for old animation system code all around the place. This will be cleaned up in due course, as some places need special review.
In particular, the particles and sequencer code have far too many manual calls to calculate + flush animation info, which is really bad (this is a 'please explain yourselves' call to Physics coders!).
2009-01-17 03:12:50 +00:00
|
|
|
/* mode: is not zero when FCurve, is 2 when forced horizontal for autohandles */
|
2012-03-12 14:55:56 +00:00
|
|
|
static void calchandleNurb_intern(BezTriple *bezt, BezTriple *prev, BezTriple *next, int mode, int skip_align)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2012-04-29 15:47:02 +00:00
|
|
|
float *p1, *p2, *p3, pt[3];
|
2011-09-29 06:15:33 +00:00
|
|
|
float dvec_a[3], dvec_b[3];
|
|
|
|
float len, len_a, len_b;
|
2011-07-09 14:22:52 +00:00
|
|
|
const float eps= 1e-5;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-03-24 06:18:31 +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
|
|
|
|
|
|
|
p2= bezt->vec[1];
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (prev==NULL) {
|
2002-10-12 11:37:38 +00:00
|
|
|
p3= next->vec[1];
|
2011-09-29 06:15:33 +00:00
|
|
|
pt[0]= 2.0f*p2[0] - p3[0];
|
|
|
|
pt[1]= 2.0f*p2[1] - p3[1];
|
|
|
|
pt[2]= 2.0f*p2[2] - p3[2];
|
2002-10-12 11:37:38 +00:00
|
|
|
p1= pt;
|
|
|
|
}
|
2011-09-29 06:15:33 +00:00
|
|
|
else {
|
|
|
|
p1= prev->vec[1];
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (next==NULL) {
|
2011-09-29 06:15:33 +00:00
|
|
|
pt[0]= 2.0f*p2[0] - p1[0];
|
|
|
|
pt[1]= 2.0f*p2[1] - p1[1];
|
|
|
|
pt[2]= 2.0f*p2[2] - p1[2];
|
2002-10-12 11:37:38 +00:00
|
|
|
p3= pt;
|
|
|
|
}
|
2011-09-29 06:15:33 +00:00
|
|
|
else {
|
|
|
|
p3= next->vec[1];
|
|
|
|
}
|
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);
|
|
|
|
|
|
|
|
if (mode != 0) {
|
|
|
|
len_a= dvec_a[0];
|
|
|
|
len_b= dvec_b[0];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
len_a= len_v3(dvec_a);
|
|
|
|
len_b= len_v3(dvec_b);
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-03-24 06:18:31 +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
|
|
|
|
|
|
|
|
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];
|
|
|
|
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;
|
|
|
|
len= len_v3(tvec) * 2.5614f;
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (len!=0.0f) {
|
2005-10-23 21:36:24 +00:00
|
|
|
int leftviolate=0, rightviolate=0; /* for mode==2 */
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
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;
|
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)) {
|
2011-09-29 06:15:33 +00:00
|
|
|
len_a/=len;
|
|
|
|
madd_v3_v3v3fl(p2-3, p2, tvec, -len_a);
|
2005-07-10 12:50:14 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if ((bezt->h1==HD_AUTO_ANIM) && next && prev) { /* keep horizontal if extrema */
|
2005-07-10 12:50:14 +00:00
|
|
|
float ydiff1= prev->vec[1][1] - bezt->vec[1][1];
|
|
|
|
float ydiff2= next->vec[1][1] - bezt->vec[1][1];
|
2012-03-24 06:18:31 +00:00
|
|
|
if ( (ydiff1 <= 0.0f && ydiff2 <= 0.0f) || (ydiff1 >= 0.0f && ydiff2 >= 0.0f) ) {
|
2005-07-10 12:50:14 +00:00
|
|
|
bezt->vec[0][1]= bezt->vec[1][1];
|
|
|
|
}
|
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]) {
|
2005-10-23 21:36:24 +00:00
|
|
|
bezt->vec[0][1]= prev->vec[1][1];
|
|
|
|
leftviolate= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2012-03-24 06:18:31 +00:00
|
|
|
if (prev->vec[1][1] < bezt->vec[0][1]) {
|
2005-10-23 21:36:24 +00:00
|
|
|
bezt->vec[0][1]= prev->vec[1][1];
|
|
|
|
leftviolate= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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)) {
|
2011-09-29 06:15:33 +00:00
|
|
|
len_b/=len;
|
|
|
|
madd_v3_v3v3fl(p2+3, p2, tvec, len_b);
|
2005-07-10 12:50:14 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if ((bezt->h2==HD_AUTO_ANIM) && next && prev) { /* keep horizontal if extrema */
|
2005-07-10 12:50:14 +00:00
|
|
|
float ydiff1= prev->vec[1][1] - bezt->vec[1][1];
|
|
|
|
float ydiff2= next->vec[1][1] - bezt->vec[1][1];
|
2012-03-24 06:18:31 +00:00
|
|
|
if ( (ydiff1 <= 0.0f && ydiff2 <= 0.0f) || (ydiff1 >= 0.0f && ydiff2 >= 0.0f) ) {
|
2005-07-10 12:50:14 +00:00
|
|
|
bezt->vec[2][1]= bezt->vec[1][1];
|
|
|
|
}
|
2011-09-29 06:15:33 +00:00
|
|
|
else { /* andles 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]) {
|
2005-10-23 21:36:24 +00:00
|
|
|
bezt->vec[2][1]= next->vec[1][1];
|
|
|
|
rightviolate= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2012-03-24 06:18:31 +00:00
|
|
|
if (next->vec[1][1] > bezt->vec[2][1]) {
|
2005-10-23 21:36:24 +00:00
|
|
|
bezt->vec[2][1]= next->vec[1][1];
|
|
|
|
rightviolate= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
if (leftviolate || rightviolate) { /* align left handle */
|
2005-10-23 21:36:24 +00:00
|
|
|
float h1[3], h2[3];
|
2011-09-29 06:15:33 +00:00
|
|
|
float dot;
|
2005-10-23 21:36:24 +00:00
|
|
|
|
2009-11-10 20:43:45 +00:00
|
|
|
sub_v3_v3v3(h1, p2-3, p2);
|
|
|
|
sub_v3_v3v3(h2, p2, p2+3);
|
2011-09-11 02:50:01 +00:00
|
|
|
|
2011-09-29 06:15:33 +00:00
|
|
|
len_a= normalize_v3(h1);
|
|
|
|
len_b= normalize_v3(h2);
|
|
|
|
|
|
|
|
dot= dot_v3v3(h1, h2);
|
2011-09-11 02:50:01 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (leftviolate) {
|
2011-09-29 06:15:33 +00:00
|
|
|
mul_v3_fl(h1, dot * len_b);
|
|
|
|
sub_v3_v3v3(p2+3, p2, h1);
|
2005-10-23 21:36:24 +00:00
|
|
|
}
|
|
|
|
else {
|
2011-09-29 06:15:33 +00:00
|
|
|
mul_v3_fl(h2, dot * len_a);
|
|
|
|
add_v3_v3v3(p2-3, p2, h2);
|
2005-07-10 12:50:14 +00:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2005-07-10 12:50:14 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (bezt->h1==HD_VECT) { /* vector */
|
2011-10-07 00:26:04 +00:00
|
|
|
madd_v3_v3v3fl(p2-3, p2, dvec_a, -1.0f/3.0f);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
if (bezt->h2==HD_VECT) {
|
2011-10-07 00:26:04 +00:00
|
|
|
madd_v3_v3v3fl(p2+3, p2, dvec_b, 1.0f/3.0f);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (skip_align) {
|
2012-03-12 14:55:56 +00:00
|
|
|
/* handles need to be updated during animation and applying stuff like hooks,
|
|
|
|
* but in such situatios it's quite difficult to distinguish in which order
|
|
|
|
* align handles should be aligned so skip them for now */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:15:33 +00:00
|
|
|
len_b= len_v3v3(p2, p2+3);
|
|
|
|
len_a= len_v3v3(p2, p2-3);
|
2012-03-24 06:18:31 +00:00
|
|
|
if (len_a==0.0f) len_a= 1.0f;
|
|
|
|
if (len_b==0.0f) len_b= 1.0f;
|
2005-07-10 12:50:14 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (bezt->f1 & SELECT) { /* order of calculation */
|
|
|
|
if (bezt->h2==HD_ALIGN) { /* aligned */
|
|
|
|
if (len_a>eps) {
|
2011-09-29 06:15:33 +00:00
|
|
|
len= len_b/len_a;
|
|
|
|
p2[3]= p2[0]+len*(p2[0] - p2[-3]);
|
|
|
|
p2[4]= p2[1]+len*(p2[1] - p2[-2]);
|
|
|
|
p2[5]= p2[2]+len*(p2[2] - p2[-1]);
|
2011-07-09 14:22:52 +00:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
if (bezt->h1==HD_ALIGN) {
|
|
|
|
if (len_b>eps) {
|
2011-09-29 06:15:33 +00:00
|
|
|
len= len_a/len_b;
|
|
|
|
p2[-3]= p2[0]+len*(p2[0] - p2[3]);
|
|
|
|
p2[-2]= p2[1]+len*(p2[1] - p2[4]);
|
|
|
|
p2[-1]= p2[2]+len*(p2[2] - p2[5]);
|
2011-07-09 14:22:52 +00:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2012-03-24 06:18:31 +00:00
|
|
|
if (bezt->h1==HD_ALIGN) {
|
|
|
|
if (len_b>eps) {
|
2011-09-29 06:15:33 +00:00
|
|
|
len= len_a/len_b;
|
|
|
|
p2[-3]= p2[0]+len*(p2[0] - p2[3]);
|
|
|
|
p2[-2]= p2[1]+len*(p2[1] - p2[4]);
|
|
|
|
p2[-1]= p2[2]+len*(p2[2] - p2[5]);
|
2011-07-09 14:22:52 +00:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
if (bezt->h2==HD_ALIGN) { /* aligned */
|
|
|
|
if (len_a>eps) {
|
2011-09-29 06:15:33 +00:00
|
|
|
len= len_b/len_a;
|
|
|
|
p2[3]= p2[0]+len*(p2[0] - p2[-3]);
|
|
|
|
p2[4]= p2[1]+len*(p2[1] - p2[-2]);
|
|
|
|
p2[5]= p2[2]+len*(p2[2] - p2[-1]);
|
2011-07-09 14:22:52 +00:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-12 14:55:56 +00:00
|
|
|
static void calchandlesNurb_intern(Nurb *nu, int skip_align)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
BezTriple *bezt, *prev, *next;
|
|
|
|
short a;
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (nu->type != CU_BEZIER) return;
|
|
|
|
if (nu->pntsu<2) return;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
a= nu->pntsu;
|
|
|
|
bezt= nu->bezt;
|
2012-03-24 06:18:31 +00:00
|
|
|
if (nu->flagu & CU_NURB_CYCLIC) prev= bezt+(a-1);
|
2011-02-13 10:52:18 +00:00
|
|
|
else prev= NULL;
|
2002-10-12 11:37:38 +00:00
|
|
|
next= bezt+1;
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
while (a--) {
|
2012-03-12 14:55:56 +00:00
|
|
|
calchandleNurb_intern(bezt, prev, next, 0, skip_align);
|
2002-10-12 11:37:38 +00:00
|
|
|
prev= bezt;
|
2012-03-24 06:18:31 +00:00
|
|
|
if (a==1) {
|
|
|
|
if (nu->flagu & CU_NURB_CYCLIC) next= nu->bezt;
|
2011-02-13 10:52:18 +00:00
|
|
|
else next= NULL;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
else next++;
|
|
|
|
|
|
|
|
bezt++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-28 16:49:00 +00:00
|
|
|
void BKE_nurb_handle_calc(BezTriple *bezt, BezTriple *prev, BezTriple *next, int mode)
|
2012-03-12 14:55:56 +00:00
|
|
|
{
|
|
|
|
calchandleNurb_intern(bezt, prev, next, mode, FALSE);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
calchandlesNurb_intern(nu, FALSE);
|
|
|
|
}
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-04-28 16:49:00 +00:00
|
|
|
void BKE_nurb_handles_test(Nurb *nu)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2010-03-22 09:30:00 +00:00
|
|
|
/* use when something has changed with handles.
|
2012-03-03 20:19:11 +00:00
|
|
|
* it treats all BezTriples with the following rules:
|
|
|
|
* PHASE 1: do types have to be altered?
|
|
|
|
* Auto handles: become aligned when selection status is NOT(000 || 111)
|
|
|
|
* Vector handles: become 'nothing' when (one half selected AND other not)
|
|
|
|
* PHASE 2: recalculate handles
|
|
|
|
*/
|
2002-10-12 11:37:38 +00:00
|
|
|
BezTriple *bezt;
|
|
|
|
short flag, a;
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (nu->type != CU_BEZIER) return;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
bezt= nu->bezt;
|
|
|
|
a= nu->pntsu;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (a--) {
|
2002-10-12 11:37:38 +00:00
|
|
|
flag= 0;
|
2012-03-24 06:18:31 +00:00
|
|
|
if (bezt->f1 & SELECT) flag++;
|
|
|
|
if (bezt->f2 & SELECT) flag += 2;
|
|
|
|
if (bezt->f3 & SELECT) flag += 4;
|
2011-08-05 11:23:28 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if ( !(flag==0 || flag==7) ) {
|
|
|
|
if (ELEM(bezt->h1, HD_AUTO, HD_AUTO_ANIM)) { /* auto */
|
2002-10-12 11:37:38 +00:00
|
|
|
bezt->h1= HD_ALIGN;
|
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
if (ELEM(bezt->h2, HD_AUTO, HD_AUTO_ANIM)) { /* auto */
|
2002-10-12 11:37:38 +00:00
|
|
|
bezt->h2= HD_ALIGN;
|
|
|
|
}
|
2011-08-05 11:23:28 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (bezt->h1==HD_VECT) { /* vector */
|
|
|
|
if (flag < 4) bezt->h1= 0;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
if (bezt->h2==HD_VECT) { /* vector */
|
|
|
|
if ( flag > 3) bezt->h2= 0;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
bezt++;
|
|
|
|
}
|
2011-08-05 11:23:28 +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 */
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
BezTriple *bezt2, *bezt1, *bezt0;
|
|
|
|
int i, align, leftsmall, rightsmall;
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (nu==NULL || nu->bezt==NULL) return;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
bezt2 = nu->bezt;
|
|
|
|
bezt1 = bezt2 + (nu->pntsu-1);
|
|
|
|
bezt0 = bezt1 - 1;
|
|
|
|
i = nu->pntsu;
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
while (i--) {
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
align= leftsmall= rightsmall= 0;
|
|
|
|
|
2003-04-25 15:48:11 +00:00
|
|
|
/* left handle: */
|
2012-03-24 06:18:31 +00:00
|
|
|
if (flag==0 || (bezt1->f1 & flag) ) {
|
2002-10-12 11:37:38 +00:00
|
|
|
bezt1->h1= 0;
|
2003-04-25 15:48:11 +00:00
|
|
|
/* distance too short: vectorhandle */
|
2012-04-29 17:11:40 +00:00
|
|
|
if (len_v3v3(bezt1->vec[1], bezt0->vec[1]) < 0.0001f) {
|
2002-10-12 11:37:38 +00:00
|
|
|
bezt1->h1= HD_VECT;
|
|
|
|
leftsmall= 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* aligned handle? */
|
2012-03-24 06:18:31 +00:00
|
|
|
if (dist_to_line_v2(bezt1->vec[1], bezt1->vec[0], bezt1->vec[2]) < 0.0001f) {
|
2002-10-12 11:37:38 +00:00
|
|
|
align= 1;
|
|
|
|
bezt1->h1= HD_ALIGN;
|
|
|
|
}
|
2003-04-25 15:48:11 +00:00
|
|
|
/* or vector handle? */
|
2012-03-24 06:18:31 +00:00
|
|
|
if (dist_to_line_v2(bezt1->vec[0], bezt1->vec[1], bezt0->vec[1]) < 0.0001f)
|
2002-10-12 11:37:38 +00:00
|
|
|
bezt1->h1= HD_VECT;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2003-04-25 15:48:11 +00:00
|
|
|
/* right handle: */
|
2012-03-24 06:18:31 +00:00
|
|
|
if (flag==0 || (bezt1->f3 & flag) ) {
|
2002-10-12 11:37:38 +00:00
|
|
|
bezt1->h2= 0;
|
2003-04-25 15:48:11 +00:00
|
|
|
/* distance too short: vectorhandle */
|
2012-04-29 17:11:40 +00:00
|
|
|
if (len_v3v3(bezt1->vec[1], bezt2->vec[1]) < 0.0001f) {
|
2002-10-12 11:37:38 +00:00
|
|
|
bezt1->h2= HD_VECT;
|
|
|
|
rightsmall= 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* aligned handle? */
|
2012-03-24 06:18:31 +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? */
|
2012-03-24 06:18:31 +00:00
|
|
|
if (dist_to_line_v2(bezt1->vec[2], bezt1->vec[1], bezt2->vec[1]) < 0.0001f)
|
2002-10-12 11:37:38 +00:00
|
|
|
bezt1->h2= HD_VECT;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
if (leftsmall && bezt1->h2==HD_ALIGN) bezt1->h2= 0;
|
|
|
|
if (rightsmall && bezt1->h1==HD_ALIGN) bezt1->h1= 0;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2003-04-25 15:48:11 +00:00
|
|
|
/* undesired combination: */
|
2012-03-24 06:18:31 +00:00
|
|
|
if (bezt1->h1==HD_ALIGN && bezt1->h2==HD_VECT) bezt1->h1= 0;
|
|
|
|
if (bezt1->h2==HD_ALIGN && bezt1->h1==HD_VECT) bezt1->h2= 0;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
bezt0= bezt1;
|
|
|
|
bezt1= bezt2;
|
|
|
|
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;
|
|
|
|
|
2009-01-14 13:04:48 +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);
|
2002-10-12 11:37:38 +00:00
|
|
|
nu= nu->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-28 16:49:00 +00:00
|
|
|
void BKE_nurbList_handles_set(ListBase *editnurb, short 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;
|
|
|
|
short a, ok=0;
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (code==1 || code==2) {
|
2009-01-14 13:04:48 +00:00
|
|
|
nu= editnurb->first;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (nu) {
|
|
|
|
if (nu->type == CU_BEZIER) {
|
2002-10-12 11:37:38 +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)) {
|
|
|
|
if (bezt->f1 & SELECT) bezt->h1= code;
|
|
|
|
if (bezt->f3 & SELECT) bezt->h2= code;
|
|
|
|
if (bezt->h1!=bezt->h2) {
|
2012-03-25 22:35:18 +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++;
|
|
|
|
}
|
2012-04-28 16:49:00 +00:00
|
|
|
BKE_nurb_handles_calc(nu);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
nu= nu->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2003-04-25 15:48:11 +00:00
|
|
|
/* there is 1 handle not FREE: FREE it all, else make ALIGNED */
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2009-01-14 13:04:48 +00:00
|
|
|
nu= editnurb->first;
|
2007-11-10 15:31:41 +00:00
|
|
|
if (code == 5) {
|
|
|
|
ok = HD_ALIGN;
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
|
|
|
else if (code == 6) {
|
2007-11-10 15:31:41 +00:00
|
|
|
ok = HD_FREE;
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
|
|
|
else {
|
2007-11-10 15:31:41 +00:00
|
|
|
/* Toggle */
|
2012-03-24 06:18:31 +00:00
|
|
|
while (nu) {
|
|
|
|
if (nu->type == CU_BEZIER) {
|
2007-11-10 15:31:41 +00:00
|
|
|
bezt= nu->bezt;
|
|
|
|
a= nu->pntsu;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (a--) {
|
|
|
|
if ((bezt->f1 & SELECT) && bezt->h1) ok= 1;
|
|
|
|
if ((bezt->f3 & SELECT) && bezt->h2) ok= 1;
|
|
|
|
if (ok) break;
|
2007-11-10 15:31:41 +00:00
|
|
|
bezt++;
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2007-11-10 15:31:41 +00:00
|
|
|
nu= nu->next;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
if (ok) ok= HD_FREE;
|
2007-11-10 15:31:41 +00:00
|
|
|
else ok= HD_ALIGN;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2009-01-14 13:04:48 +00:00
|
|
|
nu= editnurb->first;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (nu) {
|
|
|
|
if (nu->type == CU_BEZIER) {
|
2002-10-12 11:37:38 +00:00
|
|
|
bezt= nu->bezt;
|
|
|
|
a= nu->pntsu;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (a--) {
|
|
|
|
if (bezt->f1 & SELECT) bezt->h1= ok;
|
|
|
|
if (bezt->f3 & SELECT) bezt->h2= ok;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
bezt++;
|
|
|
|
}
|
2012-04-28 16:49:00 +00:00
|
|
|
BKE_nurb_handles_calc(nu);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
nu= nu->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-07 19:59:02 +00:00
|
|
|
static void swapdata(void *adr1, void *adr2, int len)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (len<=0) return;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (len<65) {
|
2002-10-12 11:37:38 +00:00
|
|
|
char adr[64];
|
|
|
|
|
|
|
|
memcpy(adr, adr1, len);
|
|
|
|
memcpy(adr1, adr2, len);
|
|
|
|
memcpy(adr2, adr, len);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
char *adr;
|
|
|
|
|
2005-04-17 18:00:33 +00:00
|
|
|
adr= (char *)MEM_mallocN(len, "curve swap");
|
2002-10-12 11:37:38 +00:00
|
|
|
memcpy(adr, adr1, len);
|
|
|
|
memcpy(adr1, adr2, len);
|
|
|
|
memcpy(adr2, adr, len);
|
2005-04-17 18:00:33 +00:00
|
|
|
MEM_freeN(adr);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-03-24 06:18:31 +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) {
|
2002-10-12 11:37:38 +00:00
|
|
|
a= nu->pntsu;
|
|
|
|
bezt1= nu->bezt;
|
|
|
|
bezt2= bezt1+(a-1);
|
2012-03-24 06:18:31 +00:00
|
|
|
if (a & 1) a+= 1; /* if odd, also swap middle content */
|
2002-10-12 11:37:38 +00:00
|
|
|
a/= 2;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (a>0) {
|
|
|
|
if (bezt1!=bezt2) SWAP(BezTriple, *bezt1, *bezt2);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
swapdata(bezt1->vec[0], bezt1->vec[2], 12);
|
2012-03-24 06:18:31 +00:00
|
|
|
if (bezt1!=bezt2) swapdata(bezt2->vec[0], bezt2->vec[2], 12);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
SWAP(char, bezt1->h1, bezt1->h2);
|
|
|
|
SWAP(short, bezt1->f1, bezt1->f3);
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
if (bezt1!=bezt2) {
|
2002-10-12 11:37:38 +00:00
|
|
|
SWAP(char, bezt2->h1, bezt2->h2);
|
|
|
|
SWAP(short, bezt2->f1, bezt2->f3);
|
|
|
|
bezt1->alfa= -bezt1->alfa;
|
|
|
|
bezt2->alfa= -bezt2->alfa;
|
|
|
|
}
|
|
|
|
a--;
|
|
|
|
bezt1++;
|
|
|
|
bezt2--;
|
|
|
|
}
|
|
|
|
}
|
2012-03-24 06:18:31 +00:00
|
|
|
else if (nu->pntsv==1) {
|
2002-10-12 11:37:38 +00:00
|
|
|
a= nu->pntsu;
|
|
|
|
bp1= nu->bp;
|
|
|
|
bp2= bp1+(a-1);
|
|
|
|
a/= 2;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (bp1!=bp2 && a>0) {
|
2002-10-12 11:37:38 +00:00
|
|
|
SWAP(BPoint, *bp1, *bp2);
|
|
|
|
a--;
|
|
|
|
bp1->alfa= -bp1->alfa;
|
|
|
|
bp2->alfa= -bp2->alfa;
|
|
|
|
bp1++;
|
|
|
|
bp2--;
|
|
|
|
}
|
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 */
|
|
|
|
a= KNOTSU(nu);
|
|
|
|
fp1= nu->knotsu;
|
|
|
|
fp2= fp1+(a-1);
|
|
|
|
a/= 2;
|
2012-03-24 06:18:31 +00:00
|
|
|
while (fp1!=fp2 && a>0) {
|
2010-12-03 17:31:34 +00:00
|
|
|
SWAP(float, *fp1, *fp2);
|
|
|
|
a--;
|
|
|
|
fp1++;
|
|
|
|
fp2--;
|
|
|
|
}
|
|
|
|
/* and make in increasing order again */
|
|
|
|
a= KNOTSU(nu);
|
|
|
|
fp1= nu->knotsu;
|
|
|
|
fp2=tempf= MEM_mallocN(sizeof(float)*a, "switchdirect");
|
2012-03-24 06:18:31 +00:00
|
|
|
while (a--) {
|
2010-12-03 17:31:34 +00:00
|
|
|
fp2[0]= fabs(fp1[1]-fp1[0]);
|
|
|
|
fp1++;
|
|
|
|
fp2++;
|
|
|
|
}
|
|
|
|
|
|
|
|
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--) {
|
2010-12-03 17:31:34 +00:00
|
|
|
fp1[0]= fp1[-1]+fp2[0];
|
|
|
|
fp1++;
|
|
|
|
fp2++;
|
|
|
|
}
|
|
|
|
MEM_freeN(tempf);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
for (b=0; b<nu->pntsv; b++) {
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
bp1= nu->bp+b*nu->pntsu;
|
|
|
|
a= nu->pntsu;
|
|
|
|
bp2= bp1+(a-1);
|
|
|
|
a/= 2;
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
while (bp1!=bp2 && a>0) {
|
2002-10-12 11:37:38 +00:00
|
|
|
SWAP(BPoint, *bp1, *bp2);
|
|
|
|
a--;
|
|
|
|
bp1++;
|
|
|
|
bp2--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-08-15 10:30:53 +00:00
|
|
|
|
|
|
|
|
2012-04-28 16:49:00 +00:00
|
|
|
float (*BKE_curve_vertexCos_get(Curve *UNUSED(cu), ListBase *lb, int *numVerts_r))[3]
|
2005-08-15 10:30:53 +00:00
|
|
|
{
|
2012-04-28 16:49:00 +00:00
|
|
|
int i, numVerts = *numVerts_r = BKE_nurbList_verts_count(lb);
|
2005-08-15 10:30:53 +00:00
|
|
|
float *co, (*cos)[3] = MEM_mallocN(sizeof(*cos)*numVerts, "cu_vcos");
|
|
|
|
Nurb *nu;
|
|
|
|
|
|
|
|
co = cos[0];
|
|
|
|
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-04-29 15:47:02 +00:00
|
|
|
for (i=0; i<nu->pntsu; i++, bezt++) {
|
2011-10-28 12:40:15 +00:00
|
|
|
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-04-29 15:47:02 +00:00
|
|
|
for (i=0; i<nu->pntsu*nu->pntsv; i++, bp++) {
|
2011-10-28 12:40:15 +00:00
|
|
|
copy_v3_v3(co, bp->vec); co+=3;
|
2005-08-15 10:30:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return cos;
|
|
|
|
}
|
|
|
|
|
2012-04-28 16:49:00 +00:00
|
|
|
void BK_curve_vertexCos_apply(Curve *UNUSED(cu), ListBase *lb, float (*vertexCos)[3])
|
2005-08-15 10:30:53 +00:00
|
|
|
{
|
|
|
|
float *co = vertexCos[0];
|
|
|
|
Nurb *nu;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
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-04-29 15:47:02 +00:00
|
|
|
for (i=0; i<nu->pntsu; i++, bezt++) {
|
2011-10-28 12:40:15 +00:00
|
|
|
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-04-29 15:47:02 +00:00
|
|
|
for (i=0; i<nu->pntsu*nu->pntsv; i++, bp++) {
|
2011-10-28 12:40:15 +00:00
|
|
|
copy_v3_v3(bp->vec, co); co+=3;
|
2005-08-15 10:30:53 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-12 14:55:56 +00:00
|
|
|
|
|
|
|
calchandlesNurb_intern(nu, TRUE);
|
2005-08-15 10:30:53 +00:00
|
|
|
}
|
|
|
|
}
|
2008-05-26 09:50:46 +00:00
|
|
|
|
2012-04-28 16:49:00 +00:00
|
|
|
float (*BKE_curve_keyVertexCos_get(Curve *UNUSED(cu), 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);
|
2009-10-22 09:31:07 +00:00
|
|
|
float *co, (*cos)[3] = MEM_mallocN(sizeof(*cos)*numVerts, "cu_vcos");
|
|
|
|
Nurb *nu;
|
|
|
|
|
|
|
|
co = cos[0];
|
|
|
|
for (nu=lb->first; nu; nu=nu->next) {
|
|
|
|
if (nu->type == CU_BEZIER) {
|
|
|
|
BezTriple *bezt = nu->bezt;
|
|
|
|
|
2012-04-29 15:47:02 +00:00
|
|
|
for (i=0; i<nu->pntsu; i++, bezt++) {
|
2011-10-28 12:40:15 +00:00
|
|
|
copy_v3_v3(co, key); co+=3; key+=3;
|
|
|
|
copy_v3_v3(co, key); co+=3; key+=3;
|
|
|
|
copy_v3_v3(co, key); co+=3; key+=3;
|
2010-07-25 11:57:36 +00:00
|
|
|
key+=3; /* skip tilt */
|
2009-10-22 09:31:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
BPoint *bp = nu->bp;
|
|
|
|
|
2012-04-29 15:47:02 +00:00
|
|
|
for (i=0; i<nu->pntsu*nu->pntsv; i++, bp++) {
|
2011-10-28 12:40:15 +00:00
|
|
|
copy_v3_v3(co, key); co+=3; key+=3;
|
2009-10-22 09:31:07 +00:00
|
|
|
key++; /* skip tilt */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return cos;
|
|
|
|
}
|
|
|
|
|
2012-04-28 16:49:00 +00:00
|
|
|
void BKE_curve_keyVertexTilts_apply(Curve *UNUSED(cu), ListBase *lb, float *key)
|
2009-10-22 09:31:07 +00:00
|
|
|
{
|
|
|
|
Nurb *nu;
|
|
|
|
int i;
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
for (nu=lb->first; nu; nu=nu->next) {
|
|
|
|
if (nu->type == CU_BEZIER) {
|
2009-10-22 09:31:07 +00:00
|
|
|
BezTriple *bezt = nu->bezt;
|
|
|
|
|
2012-04-29 15:47:02 +00:00
|
|
|
for (i=0; i<nu->pntsu; i++, bezt++) {
|
2009-10-22 09:31:07 +00:00
|
|
|
key+=3*3;
|
|
|
|
bezt->alfa= *key;
|
2010-12-03 14:35:03 +00:00
|
|
|
key+=3;
|
2009-10-22 09:31:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
BPoint *bp = nu->bp;
|
|
|
|
|
2012-04-29 15:47:02 +00:00
|
|
|
for (i=0; i<nu->pntsu*nu->pntsv; i++, bp++) {
|
2009-10-22 09:31:07 +00:00
|
|
|
key+=3;
|
|
|
|
bp->alfa= *key;
|
|
|
|
key++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-29 15:47:02 +00:00
|
|
|
int BKE_nurb_check_valid_u(struct Nurb *nu)
|
2008-05-26 09:50:46 +00:00
|
|
|
{
|
|
|
|
if (nu==NULL) return 0;
|
|
|
|
if (nu->pntsu <= 1) return 0;
|
2009-09-08 00:23:33 +00:00
|
|
|
if (nu->type != CU_NURBS) return 1; /* not a nurb, lets assume its valid */
|
2008-05-26 09:50:46 +00:00
|
|
|
|
|
|
|
if (nu->pntsu < nu->orderu) return 0;
|
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->flag & CU_NURB_CYCLIC)==0) && (nu->flagu & CU_NURB_BEZIER)) { /* Bezier U Endpoints */
|
2008-05-26 09:50:46 +00:00
|
|
|
if (nu->orderu==4) {
|
|
|
|
if (nu->pntsu < 5) return 0; /* bezier with 4 orderu needs 5 points */
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
|
|
|
else if (nu->orderu != 3) return 0; /* order must be 3 or 4 */
|
2008-05-26 09:50:46 +00:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
2012-04-29 15:47:02 +00:00
|
|
|
int BKE_nurb_check_valid_v(struct Nurb *nu)
|
2008-05-26 09:50:46 +00:00
|
|
|
{
|
|
|
|
if (nu==NULL) return 0;
|
|
|
|
if (nu->pntsv <= 1) return 0;
|
2009-09-08 00:23:33 +00:00
|
|
|
if (nu->type != CU_NURBS) return 1; /* not a nurb, lets assume its valid */
|
2008-05-26 09:50:46 +00:00
|
|
|
|
|
|
|
if (nu->pntsv < nu->orderv) return 0;
|
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->flag & CU_NURB_CYCLIC)==0) && (nu->flagv & CU_NURB_BEZIER)) { /* Bezier V Endpoints */
|
2008-05-26 09:50:46 +00:00
|
|
|
if (nu->orderv==4) {
|
|
|
|
if (nu->pntsv < 5) return 0; /* bezier with 4 orderu needs 5 points */
|
2012-03-24 06:18:31 +00:00
|
|
|
}
|
|
|
|
else if (nu->orderv != 3) return 0; /* order must be 3 or 4 */
|
2008-05-26 09:50:46 +00:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2012-04-29 15:47:02 +00:00
|
|
|
int BKE_nurb_order_clamp_u(struct Nurb *nu)
|
2008-05-26 09:50:46 +00:00
|
|
|
{
|
|
|
|
int change = 0;
|
2012-03-24 06:18:31 +00:00
|
|
|
if (nu->pntsu<nu->orderu) {
|
2008-05-26 09:50:46 +00:00
|
|
|
nu->orderu= nu->pntsu;
|
|
|
|
change= 1;
|
|
|
|
}
|
2012-03-24 06:18:31 +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);
|
2008-05-26 09:50:46 +00:00
|
|
|
change= 1;
|
|
|
|
}
|
|
|
|
return change;
|
|
|
|
}
|
|
|
|
|
2012-04-29 15:47:02 +00:00
|
|
|
int BKE_nurb_order_clamp_v(struct Nurb *nu)
|
2008-05-26 09:50:46 +00:00
|
|
|
{
|
|
|
|
int change = 0;
|
2012-03-24 06:18:31 +00:00
|
|
|
if (nu->pntsv<nu->orderv) {
|
2008-05-26 09:50:46 +00:00
|
|
|
nu->orderv= nu->pntsv;
|
|
|
|
change= 1;
|
|
|
|
}
|
2012-03-24 06:18:31 +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);
|
2008-05-26 09:50:46 +00:00
|
|
|
change= 1;
|
|
|
|
}
|
|
|
|
return change;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
/* basic vertex data functions */
|
2012-04-28 16:49:00 +00:00
|
|
|
int BKE_curve_minmax(Curve *cu, float min[3], float max[3])
|
2010-08-01 11:00:36 +00:00
|
|
|
{
|
2012-04-28 16:49:00 +00:00
|
|
|
ListBase *nurb_lb= BKE_curve_nurbs_get(cu);
|
2010-08-01 11:00:36 +00:00
|
|
|
Nurb *nu;
|
|
|
|
|
2012-03-24 06:18:31 +00:00
|
|
|
for (nu= nurb_lb->first; nu; nu= nu->next)
|
2012-04-28 16:49:00 +00:00
|
|
|
BKE_nurb_minmax(nu, min, max);
|
2010-08-01 11:00:36 +00:00
|
|
|
|
|
|
|
return (nurb_lb->first != NULL);
|
|
|
|
}
|
|
|
|
|
2012-04-28 16:49:00 +00:00
|
|
|
int BKE_curve_center_median(Curve *cu, float cent[3])
|
2010-08-01 11:00:36 +00:00
|
|
|
{
|
2012-04-28 16:49:00 +00:00
|
|
|
ListBase *nurb_lb= BKE_curve_nurbs_get(cu);
|
2010-08-01 11:00:36 +00:00
|
|
|
Nurb *nu;
|
|
|
|
int total= 0;
|
|
|
|
|
|
|
|
zero_v3(cent);
|
|
|
|
|
2012-03-24 06:18:31 +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;
|
|
|
|
i= nu->pntsu;
|
|
|
|
total += i * 3;
|
2012-03-24 06:18:31 +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;
|
|
|
|
i= nu->pntsu*nu->pntsv;
|
|
|
|
total += i;
|
2012-03-24 06:18:31 +00:00
|
|
|
for (bp= nu->bp; i--; bp++) {
|
2010-08-01 11:00:36 +00:00
|
|
|
add_v3_v3(cent, bp->vec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mul_v3_fl(cent, 1.0f/(float)total);
|
|
|
|
|
|
|
|
return (total != 0);
|
|
|
|
}
|
|
|
|
|
2012-04-28 16:49:00 +00:00
|
|
|
int 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);
|
2012-04-28 16:49:00 +00:00
|
|
|
if (BKE_curve_minmax(cu, min, max)) {
|
2010-08-01 11:00:36 +00:00
|
|
|
mid_v3_v3v3(cent, min, max);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-04-28 16:49:00 +00:00
|
|
|
void BKE_curve_translate(Curve *cu, float offset[3], int do_keys)
|
2010-08-01 11:00:36 +00:00
|
|
|
{
|
2012-04-28 16:49:00 +00:00
|
|
|
ListBase *nurb_lb= BKE_curve_nurbs_get(cu);
|
2010-08-01 11:00:36 +00:00
|
|
|
Nurb *nu;
|
|
|
|
int i;
|
|
|
|
|
2012-03-24 06:18:31 +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) {
|
2010-08-01 11:00:36 +00:00
|
|
|
i= nu->pntsu;
|
2012-03-24 06:18:31 +00:00
|
|
|
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 {
|
|
|
|
i= nu->pntsu*nu->pntsv;
|
2012-03-24 06:18:31 +00:00
|
|
|
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;
|
|
|
|
for (kb=cu->key->block.first; kb; kb=kb->next) {
|
|
|
|
float *fp= kb->data;
|
|
|
|
for (i= kb->totelem; i--; fp+=3) {
|
|
|
|
add_v3_v3(fp, offset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-07-31 12:43:41 +00:00
|
|
|
|
2012-04-28 16:49:00 +00:00
|
|
|
void BKE_curve_delete_material_index(Curve *cu, int index)
|
2011-07-31 12:43:41 +00:00
|
|
|
{
|
2012-04-28 16:49:00 +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) {
|
2011-07-31 12:43:41 +00:00
|
|
|
struct CharInfo *info= cu->strinfo;
|
|
|
|
int i;
|
2012-03-24 06:18:31 +00:00
|
|
|
for (i= cu->len-1; i >= 0; i--, info++) {
|
2011-07-31 12:43:41 +00:00
|
|
|
if (info->mat_nr && info->mat_nr>=index) {
|
|
|
|
info->mat_nr--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Nurb *nu;
|
|
|
|
|
|
|
|
for (nu= cu->nurb.first; nu; nu= nu->next) {
|
2012-03-24 06:18:31 +00:00
|
|
|
if (nu->mat_nr && nu->mat_nr>=index) {
|
2011-07-31 12:43:41 +00:00
|
|
|
nu->mat_nr--;
|
|
|
|
if (curvetype == OB_CURVE) nu->charidx--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|