merging harmonic-skeleton branch into trunk. All changes are hidden behind a disabled define, nothing to see here
This commit is contained in:
commit
481831bd27
@ -259,6 +259,21 @@ Scene *add_scene(char *name)
|
||||
sce->toolsettings->select_thresh= 0.01f;
|
||||
sce->toolsettings->jointrilimit = 0.8f;
|
||||
|
||||
sce->toolsettings->skgen_resolution = 100;
|
||||
sce->toolsettings->skgen_threshold_internal = 0.01f;
|
||||
sce->toolsettings->skgen_threshold_external = 0.01f;
|
||||
sce->toolsettings->skgen_angle_limit = 45.0f;
|
||||
sce->toolsettings->skgen_length_ratio = 1.3f;
|
||||
sce->toolsettings->skgen_length_limit = 1.5f;
|
||||
sce->toolsettings->skgen_correlation_limit = 0.98f;
|
||||
sce->toolsettings->skgen_symmetry_limit = 0.1f;
|
||||
sce->toolsettings->skgen_postpro = SKGEN_SMOOTH;
|
||||
sce->toolsettings->skgen_postpro_passes = 1;
|
||||
sce->toolsettings->skgen_options = SKGEN_FILTER_INTERNAL|SKGEN_FILTER_EXTERNAL|SKGEN_FILTER_SMART|SKGEN_HARMONIC|SKGEN_SUB_CORRELATION|SKGEN_STICK_TO_EMBEDDING;
|
||||
sce->toolsettings->skgen_subdivisions[0] = SKGEN_SUB_CORRELATION;
|
||||
sce->toolsettings->skgen_subdivisions[1] = SKGEN_SUB_LENGTH;
|
||||
sce->toolsettings->skgen_subdivisions[2] = SKGEN_SUB_ANGLE;
|
||||
|
||||
pset= &sce->toolsettings->particle;
|
||||
pset->flag= PE_KEEP_LENGTHS|PE_LOCK_FIRST|PE_DEFLECT_EMITTER;
|
||||
pset->emitterdist= 0.25f;
|
||||
|
@ -245,6 +245,7 @@ void VecMulf(float *v1, float f);
|
||||
int VecLenCompare(float *v1, float *v2, float limit);
|
||||
int VecCompare(float *v1, float *v2, float limit);
|
||||
int VecEqual(float *v1, float *v2);
|
||||
int VecIsNull(float *v);
|
||||
|
||||
void printvecf(char *str,float v[3]);
|
||||
void printvec4f(char *str, float v[4]);
|
||||
@ -265,6 +266,7 @@ void Vec2Copyf(float *v1, float *v2);
|
||||
void Vec2Lerpf(float *target, float *a, float *b, float t);
|
||||
|
||||
void AxisAngleToQuat(float *q, float *axis, float angle);
|
||||
void RotationBetweenVectorsToQuat(float *q, float v1[3], float v2[3]);
|
||||
void vectoquat(float *vec, short axis, short upflag, float *q);
|
||||
|
||||
float VecAngle2(float *v1, float *v2);
|
||||
|
@ -34,7 +34,12 @@
|
||||
|
||||
struct GHash;
|
||||
typedef struct GHash GHash;
|
||||
typedef struct GHashIterator GHashIterator;
|
||||
|
||||
typedef struct GHashIterator {
|
||||
GHash *gh;
|
||||
int curBucket;
|
||||
struct Entry *curEntry;
|
||||
} GHashIterator;
|
||||
|
||||
typedef unsigned int (*GHashHashFP) (void *key);
|
||||
typedef int (*GHashCmpFP) (void *a, void *b);
|
||||
@ -62,6 +67,15 @@ int BLI_ghash_size (GHash *gh);
|
||||
* @return Pointer to a new DynStr.
|
||||
*/
|
||||
GHashIterator* BLI_ghashIterator_new (GHash *gh);
|
||||
/**
|
||||
* Init an already allocated GHashIterator. The hash table must not
|
||||
* be mutated while the iterator is in use, and the iterator will
|
||||
* step exactly BLI_ghash_size(gh) times before becoming done.
|
||||
*
|
||||
* @param ghi The GHashIterator to initialize.
|
||||
* @param gh The GHash to iterate over.
|
||||
*/
|
||||
void BLI_ghashIterator_init(GHashIterator *ghi, GHash *gh);
|
||||
/**
|
||||
* Free a GHashIterator.
|
||||
*
|
||||
|
125
source/blender/blenlib/BLI_graph.h
Normal file
125
source/blender/blenlib/BLI_graph.h
Normal file
@ -0,0 +1,125 @@
|
||||
#ifndef BLI_GRAPH_H_
|
||||
#define BLI_GRAPH_H_
|
||||
|
||||
#include "DNA_listBase.h"
|
||||
|
||||
struct BGraph;
|
||||
struct BNode;
|
||||
struct BArc;
|
||||
|
||||
struct RadialArc;
|
||||
|
||||
typedef void (*FreeArc)(struct BArc*);
|
||||
typedef void (*FreeNode)(struct BNode*);
|
||||
typedef void (*RadialSymmetry)(struct BNode* root_node, struct RadialArc* ring, int total);
|
||||
typedef void (*AxialSymmetry)(struct BNode* root_node, struct BNode* node1, struct BNode* node2, struct BArc* arc1, struct BArc* arc2);
|
||||
|
||||
/* IF YOU MODIFY THOSE TYPES, YOU NEED TO UPDATE ALL THOSE THAT "INHERIT" FROM THEM
|
||||
*
|
||||
* RigGraph, ReebGraph
|
||||
*
|
||||
* */
|
||||
|
||||
typedef struct BGraph {
|
||||
ListBase arcs;
|
||||
ListBase nodes;
|
||||
|
||||
float length;
|
||||
|
||||
/* function pointer to deal with custom fonctionnality */
|
||||
FreeArc free_arc;
|
||||
FreeNode free_node;
|
||||
RadialSymmetry radial_symmetry;
|
||||
AxialSymmetry axial_symmetry;
|
||||
} BGraph;
|
||||
|
||||
typedef struct BNode {
|
||||
void *next, *prev;
|
||||
float p[3];
|
||||
int flag;
|
||||
|
||||
int degree;
|
||||
struct BArc **arcs;
|
||||
|
||||
int subgraph_index;
|
||||
|
||||
int symmetry_level;
|
||||
int symmetry_flag;
|
||||
float symmetry_axis[3];
|
||||
} BNode;
|
||||
|
||||
typedef struct BArc {
|
||||
void *next, *prev;
|
||||
struct BNode *head, *tail;
|
||||
int flag;
|
||||
|
||||
float length;
|
||||
|
||||
int symmetry_level;
|
||||
int symmetry_group;
|
||||
int symmetry_flag;
|
||||
} BArc;
|
||||
|
||||
/* Helper structure for radial symmetry */
|
||||
typedef struct RadialArc
|
||||
{
|
||||
struct BArc *arc;
|
||||
float n[3]; /* normalized vector joining the nodes of the arc */
|
||||
} RadialArc;
|
||||
|
||||
BNode *BLI_otherNode(BArc *arc, BNode *node);
|
||||
|
||||
void BLI_freeNode(BGraph *graph, BNode *node);
|
||||
void BLI_removeNode(BGraph *graph, BNode *node);
|
||||
|
||||
void BLI_removeArc(BGraph *graph, BArc *arc);
|
||||
|
||||
void BLI_flagNodes(BGraph *graph, int flag);
|
||||
void BLI_flagArcs(BGraph *graph, int flag);
|
||||
|
||||
int BLI_hasAdjacencyList(BGraph *rg);
|
||||
void BLI_buildAdjacencyList(BGraph *rg);
|
||||
void BLI_rebuildAdjacencyList(BGraph* rg);
|
||||
void BLI_rebuildAdjacencyListForNode(BGraph* rg, BNode *node);
|
||||
void BLI_freeAdjacencyList(BGraph *rg);
|
||||
|
||||
int BLI_FlagSubgraphs(BGraph *graph);
|
||||
void BLI_ReflagSubgraph(BGraph *graph, int old_subgraph, int new_subgraph);
|
||||
|
||||
#define SHAPE_RADIX 10 /* each shape level is encoded this base */
|
||||
|
||||
int BLI_subtreeShape(BGraph *graph, BNode *node, BArc *rootArc, int include_root);
|
||||
float BLI_subtreeLength(BNode *node);
|
||||
void BLI_calcGraphLength(BGraph *graph);
|
||||
|
||||
void BLI_replaceNode(BGraph *graph, BNode *node_src, BNode *node_replaced);
|
||||
void BLI_replaceNodeInArc(BGraph *graph, BArc *arc, BNode *node_src, BNode *node_replaced);
|
||||
void BLI_removeDoubleNodes(BGraph *graph, float limit);
|
||||
BNode * BLI_FindNodeByPosition(BGraph *graph, float *p, float limit);
|
||||
|
||||
BArc * BLI_findConnectedArc(BGraph *graph, BArc *arc, BNode *v);
|
||||
|
||||
int BLI_isGraphCyclic(BGraph *graph);
|
||||
|
||||
/*------------ Symmetry handling ------------*/
|
||||
void BLI_markdownSymmetry(BGraph *graph, BNode *root_node, float limit);
|
||||
|
||||
void BLI_mirrorAlongAxis(float v[3], float center[3], float axis[3]);
|
||||
|
||||
/* BNode symmetry flags */
|
||||
#define SYM_TOPOLOGICAL 1
|
||||
#define SYM_PHYSICAL 2
|
||||
|
||||
/* the following two are exclusive */
|
||||
#define SYM_AXIAL 4
|
||||
#define SYM_RADIAL 8
|
||||
|
||||
/* BArc symmetry flags
|
||||
*
|
||||
* axial symetry sides */
|
||||
#define SYM_SIDE_POSITIVE 1
|
||||
#define SYM_SIDE_NEGATIVE 2
|
||||
/* Anything higher is the order in radial symmetry */
|
||||
#define SYM_SIDE_RADIAL 3
|
||||
|
||||
#endif /*BLI_GRAPH_H_*/
|
@ -39,17 +39,41 @@
|
||||
#define BLENDER_MAX_THREADS 8
|
||||
|
||||
struct ListBase;
|
||||
|
||||
void BLI_init_threads (struct ListBase *threadbase, void *(*do_thread)(void *), int tot);
|
||||
int BLI_available_threads(struct ListBase *threadbase);
|
||||
int BLI_available_thread_index(struct ListBase *threadbase);
|
||||
void BLI_insert_thread (struct ListBase *threadbase, void *callerdata);
|
||||
void BLI_remove_thread (struct ListBase *threadbase, void *callerdata);
|
||||
void BLI_remove_thread_index(struct ListBase *threadbase, int index);
|
||||
void BLI_remove_threads(struct ListBase *threadbase);
|
||||
void BLI_end_threads (struct ListBase *threadbase);
|
||||
|
||||
void BLI_lock_thread (int type);
|
||||
void BLI_unlock_thread (int type);
|
||||
|
||||
int BLI_system_thread_count( void ); /* gets the number of threads the system can make use of */
|
||||
|
||||
/* ThreadedWorker is a simple tool for dispatching work to a limited number of threads in a transparent
|
||||
* fashion from the caller's perspective
|
||||
* */
|
||||
|
||||
struct ThreadedWorker;
|
||||
|
||||
/* Create a new worker supporting tot parallel threads.
|
||||
* When new work in inserted and all threads are busy, sleep(sleep_time) before checking again
|
||||
*/
|
||||
struct ThreadedWorker *BLI_create_worker(void *(*do_thread)(void *), int tot, int sleep_time);
|
||||
|
||||
/* join all working threads */
|
||||
void BLI_end_worker(struct ThreadedWorker *worker);
|
||||
|
||||
/* also ends all working threads */
|
||||
void BLI_destroy_worker(struct ThreadedWorker *worker);
|
||||
|
||||
/* Spawns a new work thread if possible, sleeps until one is available otherwise
|
||||
* NOTE: inserting work is NOT thread safe, so make sure it is only done from one thread */
|
||||
void BLI_insert_work(struct ThreadedWorker *worker, void *param);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -200,12 +200,6 @@ void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreef
|
||||
|
||||
/***/
|
||||
|
||||
struct GHashIterator {
|
||||
GHash *gh;
|
||||
int curBucket;
|
||||
Entry *curEntry;
|
||||
};
|
||||
|
||||
GHashIterator *BLI_ghashIterator_new(GHash *gh) {
|
||||
GHashIterator *ghi= malloc(sizeof(*ghi));
|
||||
ghi->gh= gh;
|
||||
@ -219,6 +213,17 @@ GHashIterator *BLI_ghashIterator_new(GHash *gh) {
|
||||
}
|
||||
return ghi;
|
||||
}
|
||||
void BLI_ghashIterator_init(GHashIterator *ghi, GHash *gh) {
|
||||
ghi->gh= gh;
|
||||
ghi->curEntry= NULL;
|
||||
ghi->curBucket= -1;
|
||||
while (!ghi->curEntry) {
|
||||
ghi->curBucket++;
|
||||
if (ghi->curBucket==ghi->gh->nbuckets)
|
||||
break;
|
||||
ghi->curEntry= ghi->gh->buckets[ghi->curBucket];
|
||||
}
|
||||
}
|
||||
void BLI_ghashIterator_free(GHashIterator *ghi) {
|
||||
free(ghi);
|
||||
}
|
||||
|
@ -1371,6 +1371,18 @@ void NormalQuat(float *q)
|
||||
}
|
||||
}
|
||||
|
||||
void RotationBetweenVectorsToQuat(float *q, float v1[3], float v2[3])
|
||||
{
|
||||
float axis[3];
|
||||
float angle;
|
||||
|
||||
Crossf(axis, v1, v2);
|
||||
|
||||
angle = NormalizedVecAngle2(v1, v2);
|
||||
|
||||
AxisAngleToQuat(q, axis, angle);
|
||||
}
|
||||
|
||||
void AxisAngleToQuat(float *q, float *axis, float angle)
|
||||
{
|
||||
float nor[3];
|
||||
@ -2219,6 +2231,11 @@ int VecEqual(float *v1, float *v2)
|
||||
return ((v1[0]==v2[0]) && (v1[1]==v2[1]) && (v1[2]==v2[2]));
|
||||
}
|
||||
|
||||
int VecIsNull(float *v)
|
||||
{
|
||||
return (v[0] == 0 && v[1] == 0 && v[2] == 0);
|
||||
}
|
||||
|
||||
void CalcNormShort( short *v1, short *v2, short *v3, float *n) /* is also cross product */
|
||||
{
|
||||
float n1[3],n2[3];
|
||||
|
1087
source/blender/blenlib/intern/graph.c
Normal file
1087
source/blender/blenlib/intern/graph.c
Normal file
File diff suppressed because it is too large
Load Diff
@ -38,6 +38,8 @@
|
||||
#include "BLI_blenlib.h"
|
||||
#include "BLI_threads.h"
|
||||
|
||||
#include "PIL_time.h"
|
||||
|
||||
/* for checking system threads - BLI_system_thread_count */
|
||||
#ifdef WIN32
|
||||
#include "Windows.h"
|
||||
@ -199,6 +201,34 @@ void BLI_remove_thread(ListBase *threadbase, void *callerdata)
|
||||
}
|
||||
}
|
||||
|
||||
void BLI_remove_thread_index(ListBase *threadbase, int index)
|
||||
{
|
||||
ThreadSlot *tslot;
|
||||
int counter=0;
|
||||
|
||||
for(tslot = threadbase->first; tslot; tslot = tslot->next, counter++) {
|
||||
if (counter == index && tslot->avail == 0) {
|
||||
tslot->callerdata = NULL;
|
||||
pthread_join(tslot->pthread, NULL);
|
||||
tslot->avail = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BLI_remove_threads(ListBase *threadbase)
|
||||
{
|
||||
ThreadSlot *tslot;
|
||||
|
||||
for(tslot = threadbase->first; tslot; tslot = tslot->next) {
|
||||
if (tslot->avail == 0) {
|
||||
tslot->callerdata = NULL;
|
||||
pthread_join(tslot->pthread, NULL);
|
||||
tslot->avail = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BLI_end_threads(ListBase *threadbase)
|
||||
{
|
||||
ThreadSlot *tslot;
|
||||
@ -265,4 +295,104 @@ int BLI_system_thread_count( void )
|
||||
return t;
|
||||
}
|
||||
|
||||
/* ************************************************ */
|
||||
|
||||
typedef struct ThreadedWorker {
|
||||
ListBase threadbase;
|
||||
void *(*work_fnct)(void *);
|
||||
char busy[RE_MAX_THREAD];
|
||||
int total;
|
||||
int sleep_time;
|
||||
} ThreadedWorker;
|
||||
|
||||
typedef struct WorkParam {
|
||||
ThreadedWorker *worker;
|
||||
void *param;
|
||||
int index;
|
||||
} WorkParam;
|
||||
|
||||
void *exec_work_fnct(void *v_param)
|
||||
{
|
||||
WorkParam *p = (WorkParam*)v_param;
|
||||
void *value;
|
||||
|
||||
value = p->worker->work_fnct(p->param);
|
||||
|
||||
p->worker->busy[p->index] = 0;
|
||||
MEM_freeN(p);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
ThreadedWorker *BLI_create_worker(void *(*do_thread)(void *), int tot, int sleep_time)
|
||||
{
|
||||
ThreadedWorker *worker;
|
||||
|
||||
worker = MEM_callocN(sizeof(ThreadedWorker), "threadedworker");
|
||||
|
||||
if (tot > RE_MAX_THREAD)
|
||||
{
|
||||
tot = RE_MAX_THREAD;
|
||||
}
|
||||
else if (tot < 1)
|
||||
{
|
||||
tot= 1;
|
||||
}
|
||||
|
||||
worker->total = tot;
|
||||
worker->work_fnct = do_thread;
|
||||
|
||||
BLI_init_threads(&worker->threadbase, exec_work_fnct, tot);
|
||||
|
||||
return worker;
|
||||
}
|
||||
|
||||
void BLI_end_worker(ThreadedWorker *worker)
|
||||
{
|
||||
BLI_remove_threads(&worker->threadbase);
|
||||
}
|
||||
|
||||
void BLI_destroy_worker(ThreadedWorker *worker)
|
||||
{
|
||||
BLI_end_worker(worker);
|
||||
BLI_freelistN(&worker->threadbase);
|
||||
MEM_freeN(worker);
|
||||
}
|
||||
|
||||
void BLI_insert_work(ThreadedWorker *worker, void *param)
|
||||
{
|
||||
WorkParam *p = MEM_callocN(sizeof(WorkParam), "workparam");
|
||||
int index;
|
||||
|
||||
if (BLI_available_threads(&worker->threadbase) == 0)
|
||||
{
|
||||
index = worker->total;
|
||||
while(index == worker->total)
|
||||
{
|
||||
PIL_sleep_ms(worker->sleep_time);
|
||||
|
||||
for (index = 0; index < worker->total; index++)
|
||||
{
|
||||
if (worker->busy[index] == 0)
|
||||
{
|
||||
BLI_remove_thread_index(&worker->threadbase, index);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
index = BLI_available_thread_index(&worker->threadbase);
|
||||
}
|
||||
|
||||
worker->busy[index] = 1;
|
||||
|
||||
p->param = param;
|
||||
p->index = index;
|
||||
p->worker = worker;
|
||||
|
||||
BLI_insert_thread(&worker->threadbase, p);
|
||||
}
|
||||
|
||||
/* eof */
|
||||
|
@ -7379,6 +7379,24 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* sanity check for skgen
|
||||
* */
|
||||
{
|
||||
Scene *sce;
|
||||
for(sce=main->scene.first; sce; sce = sce->id.next)
|
||||
{
|
||||
if (sce->toolsettings->skgen_subdivisions[0] == sce->toolsettings->skgen_subdivisions[1] ||
|
||||
sce->toolsettings->skgen_subdivisions[0] == sce->toolsettings->skgen_subdivisions[2] ||
|
||||
sce->toolsettings->skgen_subdivisions[1] == sce->toolsettings->skgen_subdivisions[2])
|
||||
{
|
||||
sce->toolsettings->skgen_subdivisions[0] = SKGEN_SUB_CORRELATION;
|
||||
sce->toolsettings->skgen_subdivisions[1] = SKGEN_SUB_LENGTH;
|
||||
sce->toolsettings->skgen_subdivisions[2] = SKGEN_SUB_ANGLE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ((main->versionfile < 245) || (main->versionfile == 245 && main->subversionfile < 2)) {
|
||||
Image *ima;
|
||||
|
@ -68,6 +68,8 @@ typedef struct EditBone
|
||||
|
||||
} EditBone;
|
||||
|
||||
void make_boneList(struct ListBase *list, struct ListBase *bones, EditBone *parent);
|
||||
void editbones_to_armature (struct ListBase *list, struct Object *ob);
|
||||
|
||||
void adduplicate_armature(void);
|
||||
void addvert_armature(void);
|
||||
@ -148,6 +150,15 @@ void align_selected_bones(void);
|
||||
|
||||
#define BONESEL_NOSEL 0x80000000 /* Indicates a negative number */
|
||||
|
||||
/* from autoarmature */
|
||||
void BIF_retargetArmature();
|
||||
void BIF_adjustRetarget();
|
||||
void BIF_freeRetarget();
|
||||
|
||||
struct ReebArc;
|
||||
float calcVariance(struct ReebArc *arc, int start, int end, float v0[3], float n[3]);
|
||||
float calcDistance(struct ReebArc *arc, int start, int end, float head[3], float tail[3]);
|
||||
|
||||
/* useful macros */
|
||||
#define EBONE_VISIBLE(arm, ebone) ((arm->layer & ebone->layer) && !(ebone->flag & BONE_HIDDEN_A))
|
||||
#define EBONE_EDITABLE(ebone) ((ebone->flag & BONE_SELECTED) && !(ebone->flag & BONE_EDITMODE_LOCKED))
|
||||
|
@ -443,7 +443,8 @@ void curvemap_buttons(struct uiBlock *block, struct CurveMapping *cumap, char la
|
||||
#define B_SETMCOL_RND 2083
|
||||
#define B_DRAWBWEIGHTS 2084
|
||||
|
||||
#define B_GEN_SKELETON 2090
|
||||
#define B_GEN_SKELETON 2085
|
||||
#define B_RETARGET_SKELETON 2086
|
||||
|
||||
/* *********************** */
|
||||
#define B_VGROUPBUTS 2100
|
||||
|
@ -28,18 +28,35 @@
|
||||
#ifndef REEB_H_
|
||||
#define REEB_H_
|
||||
|
||||
//#define WITH_BF_REEB
|
||||
|
||||
#include "DNA_listBase.h"
|
||||
|
||||
#include "BLI_graph.h"
|
||||
|
||||
struct GHash;
|
||||
struct EdgeHash;
|
||||
struct ReebArc;
|
||||
struct ReebEdge;
|
||||
struct ReebNode;
|
||||
|
||||
typedef struct ReebGraph {
|
||||
ListBase arcs;
|
||||
ListBase nodes;
|
||||
ListBase arcs;
|
||||
ListBase nodes;
|
||||
|
||||
float length;
|
||||
|
||||
FreeArc free_arc;
|
||||
FreeNode free_node;
|
||||
RadialSymmetry radial_symmetry;
|
||||
AxialSymmetry axial_symmetry;
|
||||
/*********************************/
|
||||
|
||||
int resolution;
|
||||
int totnodes;
|
||||
struct EdgeHash *emap;
|
||||
int multi_level;
|
||||
struct ReebGraph *link_up; /* for multi resolution filtering, points to higher levels */
|
||||
} ReebGraph;
|
||||
|
||||
typedef struct EmbedBucket {
|
||||
@ -49,13 +66,25 @@ typedef struct EmbedBucket {
|
||||
} EmbedBucket;
|
||||
|
||||
typedef struct ReebNode {
|
||||
struct ReebNode *next, *prev;
|
||||
struct ReebArc **arcs;
|
||||
int index;
|
||||
int degree;
|
||||
float weight;
|
||||
void *next, *prev;
|
||||
float p[3];
|
||||
int flags;
|
||||
int flag;
|
||||
|
||||
int degree;
|
||||
struct ReebArc **arcs;
|
||||
|
||||
int subgraph_index;
|
||||
|
||||
int symmetry_level;
|
||||
int symmetry_flag;
|
||||
float symmetry_axis[3];
|
||||
/*********************************/
|
||||
|
||||
int index;
|
||||
float weight;
|
||||
int multi_level;
|
||||
struct ReebNode *link_down; /* for multi resolution filtering, points to lower levels, if present */
|
||||
struct ReebNode *link_up;
|
||||
} ReebNode;
|
||||
|
||||
typedef struct ReebEdge {
|
||||
@ -63,15 +92,28 @@ typedef struct ReebEdge {
|
||||
struct ReebArc *arc;
|
||||
struct ReebNode *v1, *v2;
|
||||
struct ReebEdge *nextEdge;
|
||||
int flag;
|
||||
} ReebEdge;
|
||||
|
||||
typedef struct ReebArc {
|
||||
struct ReebArc *next, *prev;
|
||||
void *next, *prev;
|
||||
struct ReebNode *head, *tail;
|
||||
int flag;
|
||||
|
||||
float length;
|
||||
|
||||
int symmetry_level;
|
||||
int symmetry_group;
|
||||
int symmetry_flag;
|
||||
/*********************************/
|
||||
|
||||
ListBase edges;
|
||||
struct ReebNode *v1, *v2;
|
||||
int bcount;
|
||||
struct EmbedBucket *buckets;
|
||||
int bcount;
|
||||
int flags;
|
||||
|
||||
struct GHash *faces;
|
||||
float angle;
|
||||
struct ReebArc *link_up; /* for multi resolution filtering, points to higher levels */
|
||||
} ReebArc;
|
||||
|
||||
typedef struct ReebArcIterator {
|
||||
@ -79,29 +121,37 @@ typedef struct ReebArcIterator {
|
||||
int index;
|
||||
int start;
|
||||
int end;
|
||||
int stride;
|
||||
int stride;
|
||||
int length;
|
||||
} ReebArcIterator;
|
||||
|
||||
struct EditMesh;
|
||||
struct EdgeIndex;
|
||||
|
||||
int weightToHarmonic(struct EditMesh *em);
|
||||
int weightFromDistance(struct EditMesh *em);
|
||||
int weightToHarmonic(struct EditMesh *em, struct EdgeIndex *indexed_edges);
|
||||
int weightFromDistance(struct EditMesh *em, struct EdgeIndex *indexed_edges);
|
||||
int weightFromLoc(struct EditMesh *me, int axis);
|
||||
void weightToVCol(struct EditMesh *em);
|
||||
void weightToVCol(struct EditMesh *em, int index);
|
||||
void arcToVCol(struct ReebGraph *rg, struct EditMesh *em, int index);
|
||||
void angleToVCol(struct EditMesh *em, int index);
|
||||
void renormalizeWeight(struct EditMesh *em, float newmax);
|
||||
|
||||
ReebGraph * generateReebGraph(struct EditMesh *me, int subdivisions);
|
||||
void freeGraph(ReebGraph *rg);
|
||||
void exportGraph(ReebGraph *rg, int count);
|
||||
|
||||
#define OTHER_NODE(arc, node) ((arc->v1 == node) ? arc->v2 : arc->v1)
|
||||
ReebGraph * newReebGraph();
|
||||
|
||||
void initArcIterator(struct ReebArcIterator *iter, struct ReebArc *arc, struct ReebNode *head);
|
||||
void initArcIterator2(struct ReebArcIterator *iter, struct ReebArc *arc, int start, int end);
|
||||
void initArcIteratorStart(struct ReebArcIterator *iter, struct ReebArc *arc, struct ReebNode *head, int start);
|
||||
struct EmbedBucket * nextBucket(struct ReebArcIterator *iter);
|
||||
struct EmbedBucket * nextNBucket(ReebArcIterator *iter, int n);
|
||||
struct EmbedBucket * peekBucket(ReebArcIterator *iter, int n);
|
||||
struct EmbedBucket * currentBucket(struct ReebArcIterator *iter);
|
||||
struct EmbedBucket * previousBucket(struct ReebArcIterator *iter);
|
||||
int iteratorStopped(struct ReebArcIterator *iter);
|
||||
|
||||
/* Filtering */
|
||||
void filterNullReebGraph(ReebGraph *rg);
|
||||
int filterSmartReebGraph(ReebGraph *rg, float threshold);
|
||||
int filterExternalReebGraph(ReebGraph *rg, float threshold);
|
||||
int filterInternalReebGraph(ReebGraph *rg, float threshold);
|
||||
|
||||
@ -110,18 +160,33 @@ void repositionNodes(ReebGraph *rg);
|
||||
void postprocessGraph(ReebGraph *rg, char mode);
|
||||
void removeNormalNodes(ReebGraph *rg);
|
||||
|
||||
/* Graph processing */
|
||||
void buildAdjacencyList(ReebGraph *rg);
|
||||
|
||||
void sortNodes(ReebGraph *rg);
|
||||
void sortArcs(ReebGraph *rg);
|
||||
|
||||
int subtreeDepth(ReebNode *node, ReebArc *rootArc);
|
||||
int countConnectedArcs(ReebGraph *rg, ReebNode *node);
|
||||
int hasAdjacencyList(ReebGraph *rg);
|
||||
int isGraphCyclic(ReebGraph *rg);
|
||||
|
||||
/* Sanity check */
|
||||
/*------------ Sanity check ------------*/
|
||||
void verifyBuckets(ReebGraph *rg);
|
||||
void verifyFaces(ReebGraph *rg);
|
||||
|
||||
/*********************** PUBLIC *********************************/
|
||||
|
||||
#define REEB_MAX_MULTI_LEVEL 10
|
||||
|
||||
ReebGraph *BIF_ReebGraphFromEditMesh(void);
|
||||
ReebGraph *BIF_ReebGraphMultiFromEditMesh(void);
|
||||
void BIF_flagMultiArcs(ReebGraph *rg, int flag);
|
||||
|
||||
void BIF_GlobalReebGraphFromEditMesh(void);
|
||||
void BIF_GlobalReebFree(void);
|
||||
|
||||
ReebNode *BIF_otherNodeFromIndex(ReebArc *arc, ReebNode *node);
|
||||
ReebNode *BIF_NodeFromIndex(ReebArc *arc, ReebNode *node);
|
||||
ReebNode *BIF_lowestLevelNode(ReebNode *node);
|
||||
|
||||
ReebGraph *BIF_graphForMultiNode(ReebGraph *rg, ReebNode *node);
|
||||
|
||||
void REEB_freeGraph(ReebGraph *rg);
|
||||
void REEB_exportGraph(ReebGraph *rg, int count);
|
||||
void REEB_draw();
|
||||
|
||||
|
||||
#endif /*REEB_H_*/
|
||||
|
@ -433,14 +433,20 @@ typedef struct ToolSettings {
|
||||
float skgen_angle_limit;
|
||||
float skgen_correlation_limit;
|
||||
float skgen_symmetry_limit;
|
||||
float skgen_retarget_angle_weight;
|
||||
float skgen_retarget_length_weight;
|
||||
float skgen_retarget_distance_weight;
|
||||
short skgen_options;
|
||||
char skgen_postpro;
|
||||
char skgen_postpro_passes;
|
||||
char skgen_subdivisions[3];
|
||||
char skgen_multi_level;
|
||||
char skgen_optimisation_method;
|
||||
|
||||
char tpad[6];
|
||||
|
||||
/* Alt+RMB option */
|
||||
char edge_mode;
|
||||
char pad3[4];
|
||||
} ToolSettings;
|
||||
|
||||
/* Used by all brushes to store their properties, which can be directly set
|
||||
@ -837,12 +843,21 @@ typedef struct Scene {
|
||||
#define RETOPO_ELLIPSE 4
|
||||
|
||||
/* toolsettings->skgen_options */
|
||||
#define SKGEN_FILTER_INTERNAL 1
|
||||
#define SKGEN_FILTER_EXTERNAL 2
|
||||
#define SKGEN_SYMMETRY 4
|
||||
#define SKGEN_CUT_LENGTH 8
|
||||
#define SKGEN_CUT_ANGLE 16
|
||||
#define SKGEN_CUT_CORRELATION 32
|
||||
#define SKGEN_FILTER_INTERNAL (1 << 0)
|
||||
#define SKGEN_FILTER_EXTERNAL (1 << 1)
|
||||
#define SKGEN_SYMMETRY (1 << 2)
|
||||
#define SKGEN_CUT_LENGTH (1 << 3)
|
||||
#define SKGEN_CUT_ANGLE (1 << 4)
|
||||
#define SKGEN_CUT_CORRELATION (1 << 5)
|
||||
#define SKGEN_HARMONIC (1 << 6)
|
||||
#define SKGEN_STICK_TO_EMBEDDING (1 << 7)
|
||||
#define SKGEN_ADAPTIVE_DISTANCE (1 << 8)
|
||||
#define SKGEN_FILTER_SMART (1 << 9)
|
||||
#define SKGEN_DISP_LENGTH (1 << 10)
|
||||
#define SKGEN_DISP_WEIGHT (1 << 11)
|
||||
#define SKGEN_DISP_ORIG (1 << 12)
|
||||
#define SKGEN_DISP_EMBED (1 << 13)
|
||||
#define SKGEN_DISP_INDEX (1 << 14)
|
||||
|
||||
#define SKGEN_SUB_LENGTH 0
|
||||
#define SKGEN_SUB_ANGLE 1
|
||||
|
2968
source/blender/src/autoarmature.c
Normal file
2968
source/blender/src/autoarmature.c
Normal file
File diff suppressed because it is too large
Load Diff
@ -180,6 +180,8 @@
|
||||
#include "butspace.h" // own module
|
||||
#include "multires.h"
|
||||
|
||||
#include "reeb.h"
|
||||
|
||||
static float editbutweight= 1.0;
|
||||
float editbutvweight= 1;
|
||||
static int actmcol= 0, acttface= 0, acttface_rnd = 0, actmcol_rnd = 0;
|
||||
@ -5052,6 +5054,9 @@ void do_meshbuts(unsigned short event)
|
||||
case B_GEN_SKELETON:
|
||||
generateSkeleton();
|
||||
break;
|
||||
case B_RETARGET_SKELETON:
|
||||
BIF_retargetArmature();
|
||||
break;
|
||||
}
|
||||
|
||||
/* WATCH IT: previous events only in editmode! */
|
||||
@ -5150,6 +5155,100 @@ static void skgen_reorder(void *option, void *arg2)
|
||||
}
|
||||
}
|
||||
|
||||
static void skgen_graphgen(void *arg1, void *arg2)
|
||||
{
|
||||
BIF_GlobalReebGraphFromEditMesh();
|
||||
allqueue(REDRAWVIEW3D, 0);
|
||||
}
|
||||
|
||||
static void skgen_graphfree(void *arg1, void *arg2)
|
||||
{
|
||||
BIF_GlobalReebFree();
|
||||
allqueue(REDRAWVIEW3D, 0);
|
||||
}
|
||||
|
||||
static void skgen_rigadjust(void *arg1, void *arg2)
|
||||
{
|
||||
BIF_adjustRetarget();
|
||||
}
|
||||
|
||||
static void skgen_rigfree(void *arg1, void *arg2)
|
||||
{
|
||||
BIF_freeRetarget();
|
||||
}
|
||||
|
||||
static void skgen_graph_block(uiBlock *block)
|
||||
{
|
||||
uiBlockBeginAlign(block);
|
||||
uiDefButS(block, NUM, B_DIFF, "Resolution:", 1025,150,225,19, &G.scene->toolsettings->skgen_resolution,10.0,1000.0, 0, 0, "Specifies the resolution of the graph's embedding");
|
||||
uiDefButBitS(block, TOG, SKGEN_HARMONIC, B_DIFF, "H", 1250,150, 25,19, &G.scene->toolsettings->skgen_options, 0, 0, 0, 0, "Apply harmonic smoothing to the weighting");
|
||||
uiDefButBitS(block, TOG, SKGEN_FILTER_INTERNAL, B_DIFF, "Filter In", 1025,130, 83,19, &G.scene->toolsettings->skgen_options, 0, 0, 0, 0, "Filter internal small arcs from graph");
|
||||
uiDefButF(block, NUM, B_DIFF, "", 1111,130,164,19, &G.scene->toolsettings->skgen_threshold_internal,0.0, 10.0, 10, 0, "Specify the threshold ratio for filtering internal arcs");
|
||||
uiDefButBitS(block, TOG, SKGEN_FILTER_EXTERNAL, B_DIFF, "Filter Ex", 1025,110, 53,19, &G.scene->toolsettings->skgen_options, 0, 0, 0, 0, "Filter external small arcs from graph");
|
||||
uiDefButBitS(block, TOG, SKGEN_FILTER_SMART, B_DIFF, "Sm", 1078,110, 30,19, &G.scene->toolsettings->skgen_options, 0, 0, 0, 0, "Smart Filtering");
|
||||
uiDefButF(block, NUM, B_DIFF, "", 1111,110,164,19, &G.scene->toolsettings->skgen_threshold_external,0.0, 10.0, 10, 0, "Specify the threshold ratio for filtering external arcs");
|
||||
|
||||
uiDefButBitS(block, TOG, SKGEN_SYMMETRY, B_DIFF, "Symmetry", 1025, 90,125,19, &G.scene->toolsettings->skgen_options, 0, 0, 0, 0, "Restore symmetries based on topology");
|
||||
uiDefButF(block, NUM, B_DIFF, "T:", 1150, 90,125,19, &G.scene->toolsettings->skgen_symmetry_limit,0.0, 1.0, 10, 0, "Specify the threshold distance for considering potential symmetric arcs");
|
||||
uiDefButC(block, NUM, B_DIFF, "P:", 1025, 70, 62,19, &G.scene->toolsettings->skgen_postpro_passes, 0, 10, 10, 0, "Specify the number of processing passes on the embeddings");
|
||||
uiDefButC(block, ROW, B_DIFF, "Smooth", 1087, 70, 63,19, &G.scene->toolsettings->skgen_postpro, 5.0, (float)SKGEN_SMOOTH, 0, 0, "Smooth embeddings");
|
||||
uiDefButC(block, ROW, B_DIFF, "Average", 1150, 70, 62,19, &G.scene->toolsettings->skgen_postpro, 5.0, (float)SKGEN_AVERAGE, 0, 0, "Average embeddings");
|
||||
uiDefButC(block, ROW, B_DIFF, "Sharpen", 1212, 70, 63,19, &G.scene->toolsettings->skgen_postpro, 5.0, (float)SKGEN_SHARPEN, 0, 0, "Sharpen embeddings");
|
||||
|
||||
uiBlockEndAlign(block);
|
||||
}
|
||||
|
||||
static void editing_panel_mesh_skgen_display(Object *ob, Mesh *me)
|
||||
{
|
||||
uiBlock *block;
|
||||
uiBut *but;
|
||||
|
||||
block= uiNewBlock(&curarea->uiblocks, "editing_panel_mesh_skgen_display", UI_EMBOSS, UI_HELV, curarea->win);
|
||||
uiNewPanelTabbed("Mesh Tools More", "Skgen");
|
||||
if(uiNewPanel(curarea, block, "Graph", "Editing", 960, 0, 318, 204)==0) return;
|
||||
|
||||
but = uiDefBut(block, BUT, B_DIFF, "Generate", 1025,170,125,19, 0, 0, 0, 0, 0, "Generate Graph from Mesh");
|
||||
uiButSetFunc(but, skgen_graphgen, NULL, NULL);
|
||||
but = uiDefBut(block, BUT, B_DIFF, "Free", 1150,170,125,19, 0, 0, 0, 0, 0, "Free Graph from Mesh");
|
||||
uiButSetFunc(but, skgen_graphfree, NULL, NULL);
|
||||
|
||||
skgen_graph_block(block);
|
||||
|
||||
uiBlockBeginAlign(block);
|
||||
uiDefButBitS(block, TOG, SKGEN_DISP_LENGTH, REDRAWVIEW3D, "Length", 1025, 40, 50,19, &G.scene->toolsettings->skgen_options, 0, 0, 0, 0, "Show Length");
|
||||
uiDefButBitS(block, TOG, SKGEN_DISP_WEIGHT, REDRAWVIEW3D, "Weight", 1075, 40, 50,19, &G.scene->toolsettings->skgen_options, 0, 0, 0, 0, "Show Weight");
|
||||
uiDefButBitS(block, TOG, SKGEN_DISP_EMBED, REDRAWVIEW3D, "Embed", 1125, 40, 50,19, &G.scene->toolsettings->skgen_options, 0, 0, 0, 0, "Show Arc Embedings");
|
||||
uiDefButBitS(block, TOG, SKGEN_DISP_INDEX, REDRAWVIEW3D, "Index", 1175, 40, 50,19, &G.scene->toolsettings->skgen_options, 0, 0, 0, 0, "Show Arc and Node indexes");
|
||||
uiDefButBitS(block, TOG, SKGEN_DISP_ORIG, REDRAWVIEW3D, "Original", 1225, 40, 50,19, &G.scene->toolsettings->skgen_options, 0, 0, 0, 0, "Show Original Graph");
|
||||
|
||||
uiBlockEndAlign(block);
|
||||
|
||||
uiDefButC(block, NUM, REDRAWVIEW3D, "Level:", 1025, 20, 125,19, &G.scene->toolsettings->skgen_multi_level, 0, REEB_MAX_MULTI_LEVEL, 1, 0,"Specify the level to draw");
|
||||
}
|
||||
|
||||
static void editing_panel_mesh_skgen_retarget(Object *ob, Mesh *me)
|
||||
{
|
||||
uiBlock *block;
|
||||
uiBut *but;
|
||||
|
||||
block= uiNewBlock(&curarea->uiblocks, "editing_panel_mesh_skgen_retarget", UI_EMBOSS, UI_HELV, curarea->win);
|
||||
uiNewPanelTabbed("Mesh Tools More", "Skgen");
|
||||
if(uiNewPanel(curarea, block, "Retarget", "Editing", 960, 0, 318, 204)==0) return;
|
||||
|
||||
uiDefBut(block, BUT, B_RETARGET_SKELETON, "Retarget Skeleton", 1025,170,100,19, 0, 0, 0, 0, 0, "Retarget Selected Armature to this Mesh");
|
||||
but = uiDefBut(block, BUT, B_DIFF, "Adjust", 1125,170,100,19, 0, 0, 0, 0, 0, "Adjust Retarget using new weights");
|
||||
uiButSetFunc(but, skgen_rigadjust, NULL, NULL);
|
||||
but = uiDefBut(block, BUT, B_DIFF, "Free", 1225,170,50,19, 0, 0, 0, 0, 0, "Free Retarget structure");
|
||||
uiButSetFunc(but, skgen_rigfree, NULL, NULL);
|
||||
|
||||
skgen_graph_block(block);
|
||||
|
||||
uiDefButF(block, NUM, B_DIFF, "Ang:", 1025, 40, 83,19, &G.scene->toolsettings->skgen_retarget_angle_weight, 0, 10, 1, 0, "Angle Weight");
|
||||
uiDefButF(block, NUM, B_DIFF, "Len:", 1108, 40, 83,19, &G.scene->toolsettings->skgen_retarget_length_weight, 0, 10, 1, 0, "Length Weight");
|
||||
uiDefButF(block, NUM, B_DIFF, "Dist:", 1191, 40, 84,19, &G.scene->toolsettings->skgen_retarget_distance_weight, 0, 10, 1, 0, "Distance Weight");
|
||||
uiDefButC(block, NUM, B_DIFF, "Method:", 1025, 20, 125,19, &G.scene->toolsettings->skgen_optimisation_method, 0, 2, 1, 0,"Optimisation Method (0: brute, 1: memoize, 2: annealing max fixed");
|
||||
}
|
||||
|
||||
static void editing_panel_mesh_skgen(Object *ob, Mesh *me)
|
||||
{
|
||||
uiBlock *block;
|
||||
@ -5157,20 +5256,17 @@ static void editing_panel_mesh_skgen(Object *ob, Mesh *me)
|
||||
int i;
|
||||
|
||||
block= uiNewBlock(&curarea->uiblocks, "editing_panel_mesh_skgen", UI_EMBOSS, UI_HELV, curarea->win);
|
||||
if(uiNewPanel(curarea, block, "Skeleton Generator", "Editing", 960, 0, 318, 204)==0) return;
|
||||
uiNewPanelTabbed("Mesh Tools More", "Skgen");
|
||||
if(uiNewPanel(curarea, block, "Generator", "Editing", 960, 0, 318, 204)==0) return;
|
||||
|
||||
uiDefBut(block, BUT, B_GEN_SKELETON, "Generate Skeleton", 1025,170,250,19, 0, 0, 0, 0, 0, "Generate Skeleton from Mesh");
|
||||
uiDefBut(block, BUT, B_GEN_SKELETON, "Generate", 1025,170,250,19, 0, 0, 0, 0, 0, "Generate Skeleton from Mesh");
|
||||
|
||||
skgen_graph_block(block);
|
||||
|
||||
uiBlockBeginAlign(block);
|
||||
uiDefButS(block, NUM, B_DIFF, "Resolution:", 1025,150,250,19, &G.scene->toolsettings->skgen_resolution,10.0,1000.0, 0, 0, "Specifies the resolution of the graph's embedding");
|
||||
uiDefButBitS(block, TOG, SKGEN_FILTER_INTERNAL, B_DIFF, "Filter In", 1025,130, 83,19, &G.scene->toolsettings->skgen_options, 0, 0, 0, 0, "Filter internal small arcs from graph");
|
||||
uiDefButF(block, NUM, B_DIFF, "T:", 1111,130,164,19, &G.scene->toolsettings->skgen_threshold_internal,0.0, 1.0, 10, 0, "Specify the threshold ratio for filtering internal arcs");
|
||||
uiDefButBitS(block, TOG, SKGEN_FILTER_EXTERNAL, B_DIFF, "Filter Ex", 1025,110, 83,19, &G.scene->toolsettings->skgen_options, 0, 0, 0, 0, "Filter external small arcs from graph");
|
||||
uiDefButF(block, NUM, B_DIFF, "T:", 1111,110,164,19, &G.scene->toolsettings->skgen_threshold_external,0.0, 1.0, 10, 0, "Specify the threshold ratio for filtering external arcs");
|
||||
|
||||
for(i = 0; i < SKGEN_SUB_TOTAL; i++)
|
||||
{
|
||||
int y = 90 - 20 * i;
|
||||
int y = 50 - 20 * i;
|
||||
|
||||
but = uiDefIconBut(block, BUT, B_MODIFIER_RECALC, VICON_MOVE_DOWN, 1025, y, 16, 19, NULL, 0.0, 0.0, 0.0, 0.0, "Change the order the subdivisions algorithm are applied");
|
||||
uiButSetFunc(but, skgen_reorder, SET_INT_IN_POINTER(i), NULL);
|
||||
@ -5187,18 +5283,14 @@ static void editing_panel_mesh_skgen(Object *ob, Mesh *me)
|
||||
uiDefButF(block, NUM, B_DIFF, "T:", 1111, y,164,19, &G.scene->toolsettings->skgen_angle_limit,0.0, 90.0, 10, 0, "Specify the threshold angle in degrees for subdivision");
|
||||
break;
|
||||
case SKGEN_SUB_CORRELATION:
|
||||
uiDefButBitS(block, TOG, SKGEN_CUT_CORRELATION, B_DIFF, "Correlation", 1041, y, 67,19, &G.scene->toolsettings->skgen_options, 0, 0, 0, 0, "Subdivide arcs based on correlation");
|
||||
uiDefButF(block, NUM, B_DIFF, "T:", 1111, y,164,19, &G.scene->toolsettings->skgen_correlation_limit,0.0, 1.0, 0.01, 0, "Specify the threshold correlation for subdivision");
|
||||
uiDefButBitS(block, TOG, SKGEN_CUT_CORRELATION, B_DIFF, "Adaptative", 1041, y, 67,19, &G.scene->toolsettings->skgen_options, 0, 0, 0, 0, "Subdivide arcs adaptatively");
|
||||
uiDefButF(block, NUM, B_DIFF, "T:", 1111, y,114,19, &G.scene->toolsettings->skgen_correlation_limit,0.0, 1.0, 0.01, 0, "Specify the adaptive threshold for subdivision");
|
||||
uiDefButBitS(block, TOG, SKGEN_STICK_TO_EMBEDDING, B_DIFF, "E", 1225, y, 25,19, &G.scene->toolsettings->skgen_options, 0, 0, 0, 0, "Stick endpoint to embedding");
|
||||
uiDefButBitS(block, TOG, SKGEN_ADAPTIVE_DISTANCE, B_DIFF, "D", 1250, y, 25,19, &G.scene->toolsettings->skgen_options, 0, 0, 0, 0, "Adaptive distance (on) or variance(off)");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uiDefButBitS(block, TOG, SKGEN_SYMMETRY, B_DIFF, "Symmetry", 1025, 30,125,19, &G.scene->toolsettings->skgen_options, 0, 0, 0, 0, "Restore symmetries based on topology");
|
||||
uiDefButF(block, NUM, B_DIFF, "T:", 1150, 30,125,19, &G.scene->toolsettings->skgen_symmetry_limit,0.0, 1.0, 10, 0, "Specify the threshold distance for considering potential symmetric arcs");
|
||||
uiDefButC(block, NUM, B_DIFF, "P:", 1025, 10, 62,19, &G.scene->toolsettings->skgen_postpro_passes, 0, 10, 10, 0, "Specify the number of processing passes on the embeddings");
|
||||
uiDefButC(block, ROW, B_DIFF, "Smooth", 1087, 10, 63,19, &G.scene->toolsettings->skgen_postpro, 5.0, (float)SKGEN_SMOOTH, 0, 0, "Smooth embeddings");
|
||||
uiDefButC(block, ROW, B_DIFF, "Average", 1150, 10, 62,19, &G.scene->toolsettings->skgen_postpro, 5.0, (float)SKGEN_AVERAGE, 0, 0, "Average embeddings");
|
||||
uiDefButC(block, ROW, B_DIFF, "Sharpen", 1212, 10, 63,19, &G.scene->toolsettings->skgen_postpro, 5.0, (float)SKGEN_SHARPEN, 0, 0, "Sharpen embeddings");
|
||||
uiBlockEndAlign(block);
|
||||
}
|
||||
|
||||
@ -6623,8 +6715,11 @@ void editing_panels()
|
||||
editing_panel_mesh_tools1(ob, ob->data);
|
||||
uiNewPanelTabbed("Mesh Tools 1", "Editing");
|
||||
|
||||
if (G.rt == 42) /* hidden for now, no time for docs */
|
||||
editing_panel_mesh_skgen(ob, ob->data);
|
||||
#ifdef WITH_BF_REEB
|
||||
editing_panel_mesh_skgen(ob, ob->data);
|
||||
editing_panel_mesh_skgen_retarget(ob, ob->data);
|
||||
editing_panel_mesh_skgen_display(ob, ob->data);
|
||||
#endif
|
||||
|
||||
editing_panel_mesh_uvautocalculation();
|
||||
if (EM_texFaceCheck())
|
||||
|
@ -167,6 +167,8 @@
|
||||
|
||||
#include "RE_pipeline.h" // make_stars
|
||||
|
||||
#include "reeb.h"
|
||||
|
||||
#include "GPU_draw.h"
|
||||
#include "GPU_material.h"
|
||||
|
||||
@ -3240,6 +3242,8 @@ void drawview3dspace(ScrArea *sa, void *spacedata)
|
||||
BIF_drawPropCircle(); // only editmode and particles have proportional edit
|
||||
BIF_drawSnap();
|
||||
}
|
||||
|
||||
REEB_draw();
|
||||
|
||||
if(G.scene->radio) RAD_drawall(v3d->drawtype>=OB_SOLID);
|
||||
|
||||
|
@ -4514,542 +4514,7 @@ void transform_armature_mirror_update(void)
|
||||
/*************************************** SKELETON GENERATOR ******************************************/
|
||||
/*****************************************************************************************************/
|
||||
|
||||
/**************************************** SYMMETRY HANDLING ******************************************/
|
||||
|
||||
void markdownSymmetryArc(ReebArc *arc, ReebNode *node, int level);
|
||||
|
||||
void mirrorAlongAxis(float v[3], float center[3], float axis[3])
|
||||
{
|
||||
float dv[3], pv[3];
|
||||
|
||||
VecSubf(dv, v, center);
|
||||
Projf(pv, dv, axis);
|
||||
VecMulf(pv, -2);
|
||||
VecAddf(v, v, pv);
|
||||
}
|
||||
|
||||
/* Helper structure for radial symmetry */
|
||||
typedef struct RadialArc
|
||||
{
|
||||
ReebArc *arc;
|
||||
float n[3]; /* normalized vector joining the nodes of the arc */
|
||||
} RadialArc;
|
||||
|
||||
void reestablishRadialSymmetry(ReebNode *node, int depth, float axis[3])
|
||||
{
|
||||
RadialArc *ring = NULL;
|
||||
RadialArc *unit;
|
||||
float limit = G.scene->toolsettings->skgen_symmetry_limit;
|
||||
int symmetric = 1;
|
||||
int count = 0;
|
||||
int i;
|
||||
|
||||
/* count the number of arcs in the symmetry ring */
|
||||
for (i = 0; node->arcs[i] != NULL; i++)
|
||||
{
|
||||
ReebArc *connectedArc = node->arcs[i];
|
||||
|
||||
/* depth is store as a negative in flag. symmetry level is positive */
|
||||
if (connectedArc->flags == -depth)
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
ring = MEM_callocN(sizeof(RadialArc) * count, "radial symmetry ring");
|
||||
unit = ring;
|
||||
|
||||
/* fill in the ring */
|
||||
for (unit = ring, i = 0; node->arcs[i] != NULL; i++)
|
||||
{
|
||||
ReebArc *connectedArc = node->arcs[i];
|
||||
|
||||
/* depth is store as a negative in flag. symmetry level is positive */
|
||||
if (connectedArc->flags == -depth)
|
||||
{
|
||||
ReebNode *otherNode = OTHER_NODE(connectedArc, node);
|
||||
float vec[3];
|
||||
|
||||
unit->arc = connectedArc;
|
||||
|
||||
/* project the node to node vector on the symmetry plane */
|
||||
VecSubf(unit->n, otherNode->p, node->p);
|
||||
Projf(vec, unit->n, axis);
|
||||
VecSubf(unit->n, unit->n, vec);
|
||||
|
||||
Normalize(unit->n);
|
||||
|
||||
unit++;
|
||||
}
|
||||
}
|
||||
|
||||
/* sort ring */
|
||||
for (i = 0; i < count - 1; i++)
|
||||
{
|
||||
float minAngle = 3; /* arbitrary high value, higher than 2, at least */
|
||||
int minIndex = -1;
|
||||
int j;
|
||||
|
||||
for (j = i + 1; j < count; j++)
|
||||
{
|
||||
float angle = Inpf(ring[i].n, ring[j].n);
|
||||
|
||||
/* map negative values to 1..2 */
|
||||
if (angle < 0)
|
||||
{
|
||||
angle = 1 - angle;
|
||||
}
|
||||
|
||||
if (angle < minAngle)
|
||||
{
|
||||
minIndex = j;
|
||||
minAngle = angle;
|
||||
}
|
||||
}
|
||||
|
||||
/* swap if needed */
|
||||
if (minIndex != i + 1)
|
||||
{
|
||||
RadialArc tmp;
|
||||
tmp = ring[i + 1];
|
||||
ring[i + 1] = ring[minIndex];
|
||||
ring[minIndex] = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < count && symmetric; i++)
|
||||
{
|
||||
ReebNode *node1, *node2;
|
||||
float tangent[3];
|
||||
float normal[3];
|
||||
float p[3];
|
||||
int j = (i + 1) % count; /* next arc in the circular list */
|
||||
|
||||
VecAddf(tangent, ring[i].n, ring[j].n);
|
||||
Crossf(normal, tangent, axis);
|
||||
|
||||
node1 = OTHER_NODE(ring[i].arc, node);
|
||||
node2 = OTHER_NODE(ring[j].arc, node);
|
||||
|
||||
VECCOPY(p, node2->p);
|
||||
mirrorAlongAxis(p, node->p, normal);
|
||||
|
||||
/* check if it's within limit before continuing */
|
||||
if (VecLenf(node1->p, p) > limit)
|
||||
{
|
||||
symmetric = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (symmetric)
|
||||
{
|
||||
/* first pass, merge incrementally */
|
||||
for (i = 0; i < count - 1; i++)
|
||||
{
|
||||
ReebNode *node1, *node2;
|
||||
float tangent[3];
|
||||
float normal[3];
|
||||
int j = i + 1;
|
||||
|
||||
VecAddf(tangent, ring[i].n, ring[j].n);
|
||||
Crossf(normal, tangent, axis);
|
||||
|
||||
node1 = OTHER_NODE(ring[i].arc, node);
|
||||
node2 = OTHER_NODE(ring[j].arc, node);
|
||||
|
||||
/* mirror first node and mix with the second */
|
||||
mirrorAlongAxis(node1->p, node->p, normal);
|
||||
VecLerpf(node2->p, node2->p, node1->p, 1.0f / (j + 1));
|
||||
|
||||
/* Merge buckets
|
||||
* there shouldn't be any null arcs here, but just to be safe
|
||||
* */
|
||||
if (ring[i].arc->bcount > 0 && ring[j].arc->bcount > 0)
|
||||
{
|
||||
ReebArcIterator iter1, iter2;
|
||||
EmbedBucket *bucket1 = NULL, *bucket2 = NULL;
|
||||
|
||||
initArcIterator(&iter1, ring[i].arc, node);
|
||||
initArcIterator(&iter2, ring[j].arc, node);
|
||||
|
||||
bucket1 = nextBucket(&iter1);
|
||||
bucket2 = nextBucket(&iter2);
|
||||
|
||||
/* Make sure they both start at the same value */
|
||||
while(bucket1 && bucket1->val < bucket2->val)
|
||||
{
|
||||
bucket1 = nextBucket(&iter1);
|
||||
}
|
||||
|
||||
while(bucket2 && bucket2->val < bucket1->val)
|
||||
{
|
||||
bucket2 = nextBucket(&iter2);
|
||||
}
|
||||
|
||||
|
||||
for ( ;bucket1 && bucket2; bucket1 = nextBucket(&iter1), bucket2 = nextBucket(&iter2))
|
||||
{
|
||||
bucket2->nv += bucket1->nv; /* add counts */
|
||||
|
||||
/* mirror on axis */
|
||||
mirrorAlongAxis(bucket1->p, node->p, normal);
|
||||
/* add bucket2 in bucket1 */
|
||||
VecLerpf(bucket2->p, bucket2->p, bucket1->p, (float)bucket1->nv / (float)(bucket2->nv));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* second pass, mirror back on previous arcs */
|
||||
for (i = count - 1; i > 0; i--)
|
||||
{
|
||||
ReebNode *node1, *node2;
|
||||
float tangent[3];
|
||||
float normal[3];
|
||||
int j = i - 1;
|
||||
|
||||
VecAddf(tangent, ring[i].n, ring[j].n);
|
||||
Crossf(normal, tangent, axis);
|
||||
|
||||
node1 = OTHER_NODE(ring[i].arc, node);
|
||||
node2 = OTHER_NODE(ring[j].arc, node);
|
||||
|
||||
/* copy first node than mirror */
|
||||
VECCOPY(node2->p, node1->p);
|
||||
mirrorAlongAxis(node2->p, node->p, normal);
|
||||
|
||||
/* Copy buckets
|
||||
* there shouldn't be any null arcs here, but just to be safe
|
||||
* */
|
||||
if (ring[i].arc->bcount > 0 && ring[j].arc->bcount > 0)
|
||||
{
|
||||
ReebArcIterator iter1, iter2;
|
||||
EmbedBucket *bucket1 = NULL, *bucket2 = NULL;
|
||||
|
||||
initArcIterator(&iter1, ring[i].arc, node);
|
||||
initArcIterator(&iter2, ring[j].arc, node);
|
||||
|
||||
bucket1 = nextBucket(&iter1);
|
||||
bucket2 = nextBucket(&iter2);
|
||||
|
||||
/* Make sure they both start at the same value */
|
||||
while(bucket1 && bucket1->val < bucket2->val)
|
||||
{
|
||||
bucket1 = nextBucket(&iter1);
|
||||
}
|
||||
|
||||
while(bucket2 && bucket2->val < bucket1->val)
|
||||
{
|
||||
bucket2 = nextBucket(&iter2);
|
||||
}
|
||||
|
||||
|
||||
for ( ;bucket1 && bucket2; bucket1 = nextBucket(&iter1), bucket2 = nextBucket(&iter2))
|
||||
{
|
||||
/* copy and mirror back to bucket2 */
|
||||
bucket2->nv = bucket1->nv;
|
||||
VECCOPY(bucket2->p, bucket1->p);
|
||||
mirrorAlongAxis(bucket2->p, node->p, normal);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MEM_freeN(ring);
|
||||
}
|
||||
|
||||
void reestablishAxialSymmetry(ReebNode *node, int depth, float axis[3])
|
||||
{
|
||||
ReebArc *arc1 = NULL;
|
||||
ReebArc *arc2 = NULL;
|
||||
ReebNode *node1 = NULL, *node2 = NULL;
|
||||
float limit = G.scene->toolsettings->skgen_symmetry_limit;
|
||||
float nor[3], vec[3], p[3];
|
||||
int i;
|
||||
|
||||
for (i = 0; node->arcs[i] != NULL; i++)
|
||||
{
|
||||
ReebArc *connectedArc = node->arcs[i];
|
||||
|
||||
/* depth is store as a negative in flag. symmetry level is positive */
|
||||
if (connectedArc->flags == -depth)
|
||||
{
|
||||
if (arc1 == NULL)
|
||||
{
|
||||
arc1 = connectedArc;
|
||||
node1 = OTHER_NODE(arc1, node);
|
||||
}
|
||||
else
|
||||
{
|
||||
arc2 = connectedArc;
|
||||
node2 = OTHER_NODE(arc2, node);
|
||||
break; /* Can stop now, the two arcs have been found */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* shouldn't happen, but just to be sure */
|
||||
if (node1 == NULL || node2 == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
VecSubf(p, node1->p, node->p);
|
||||
Crossf(vec, p, axis);
|
||||
Crossf(nor, vec, axis);
|
||||
|
||||
/* mirror node2 along axis */
|
||||
VECCOPY(p, node2->p);
|
||||
mirrorAlongAxis(p, node->p, nor);
|
||||
|
||||
/* check if it's within limit before continuing */
|
||||
if (VecLenf(node1->p, p) <= limit)
|
||||
{
|
||||
|
||||
/* average with node1 */
|
||||
VecAddf(node1->p, node1->p, p);
|
||||
VecMulf(node1->p, 0.5f);
|
||||
|
||||
/* mirror back on node2 */
|
||||
VECCOPY(node2->p, node1->p);
|
||||
mirrorAlongAxis(node2->p, node->p, nor);
|
||||
|
||||
/* Merge buckets
|
||||
* there shouldn't be any null arcs here, but just to be safe
|
||||
* */
|
||||
if (arc1->bcount > 0 && arc2->bcount > 0)
|
||||
{
|
||||
ReebArcIterator iter1, iter2;
|
||||
EmbedBucket *bucket1 = NULL, *bucket2 = NULL;
|
||||
|
||||
initArcIterator(&iter1, arc1, node);
|
||||
initArcIterator(&iter2, arc2, node);
|
||||
|
||||
bucket1 = nextBucket(&iter1);
|
||||
bucket2 = nextBucket(&iter2);
|
||||
|
||||
/* Make sure they both start at the same value */
|
||||
while(bucket1 && bucket1->val < bucket2->val)
|
||||
{
|
||||
bucket1 = nextBucket(&iter1);
|
||||
}
|
||||
|
||||
while(bucket2 && bucket2->val < bucket1->val)
|
||||
{
|
||||
bucket2 = nextBucket(&iter2);
|
||||
}
|
||||
|
||||
|
||||
for ( ;bucket1 && bucket2; bucket1 = nextBucket(&iter1), bucket2 = nextBucket(&iter2))
|
||||
{
|
||||
bucket1->nv += bucket2->nv; /* add counts */
|
||||
|
||||
/* mirror on axis */
|
||||
mirrorAlongAxis(bucket2->p, node->p, nor);
|
||||
/* add bucket2 in bucket1 */
|
||||
VecLerpf(bucket1->p, bucket1->p, bucket2->p, (float)bucket2->nv / (float)(bucket1->nv));
|
||||
|
||||
/* copy and mirror back to bucket2 */
|
||||
bucket2->nv = bucket1->nv;
|
||||
VECCOPY(bucket2->p, bucket1->p);
|
||||
mirrorAlongAxis(bucket2->p, node->p, nor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void markdownSecondarySymmetry(ReebNode *node, int depth, int level)
|
||||
{
|
||||
float axis[3] = {0, 0, 0};
|
||||
int count = 0;
|
||||
int i;
|
||||
|
||||
/* Only reestablish spatial symmetry if needed */
|
||||
if (G.scene->toolsettings->skgen_options & SKGEN_SYMMETRY)
|
||||
{
|
||||
/* count the number of branches in this symmetry group
|
||||
* and determinte the axis of symmetry
|
||||
* */
|
||||
for (i = 0; node->arcs[i] != NULL; i++)
|
||||
{
|
||||
ReebArc *connectedArc = node->arcs[i];
|
||||
|
||||
/* depth is store as a negative in flag. symmetry level is positive */
|
||||
if (connectedArc->flags == -depth)
|
||||
{
|
||||
count++;
|
||||
}
|
||||
/* If arc is on the axis */
|
||||
else if (connectedArc->flags == level)
|
||||
{
|
||||
VecAddf(axis, axis, connectedArc->v1->p);
|
||||
VecSubf(axis, axis, connectedArc->v2->p);
|
||||
}
|
||||
}
|
||||
|
||||
Normalize(axis);
|
||||
|
||||
/* Split between axial and radial symmetry */
|
||||
if (count == 2)
|
||||
{
|
||||
reestablishAxialSymmetry(node, depth, axis);
|
||||
}
|
||||
else
|
||||
{
|
||||
reestablishRadialSymmetry(node, depth, axis);
|
||||
}
|
||||
}
|
||||
|
||||
/* markdown secondary symetries */
|
||||
for (i = 0; node->arcs[i] != NULL; i++)
|
||||
{
|
||||
ReebArc *connectedArc = node->arcs[i];
|
||||
|
||||
if (connectedArc->flags == -depth)
|
||||
{
|
||||
/* markdown symmetry for branches corresponding to the depth */
|
||||
markdownSymmetryArc(connectedArc, node, level + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void markdownSymmetryArc(ReebArc *arc, ReebNode *node, int level)
|
||||
{
|
||||
int i;
|
||||
arc->flags = level;
|
||||
|
||||
node = OTHER_NODE(arc, node);
|
||||
|
||||
for (i = 0; node->arcs[i] != NULL; i++)
|
||||
{
|
||||
ReebArc *connectedArc = node->arcs[i];
|
||||
|
||||
if (connectedArc != arc)
|
||||
{
|
||||
ReebNode *connectedNode = OTHER_NODE(connectedArc, node);
|
||||
|
||||
/* symmetry level is positive value, negative values is subtree depth */
|
||||
connectedArc->flags = -subtreeDepth(connectedNode, connectedArc);
|
||||
}
|
||||
}
|
||||
|
||||
arc = NULL;
|
||||
|
||||
for (i = 0; node->arcs[i] != NULL; i++)
|
||||
{
|
||||
int issymmetryAxis = 0;
|
||||
ReebArc *connectedArc = node->arcs[i];
|
||||
|
||||
/* only arcs not already marked as symetric */
|
||||
if (connectedArc->flags < 0)
|
||||
{
|
||||
int j;
|
||||
|
||||
/* true by default */
|
||||
issymmetryAxis = 1;
|
||||
|
||||
for (j = 0; node->arcs[j] != NULL && issymmetryAxis == 1; j++)
|
||||
{
|
||||
ReebArc *otherArc = node->arcs[j];
|
||||
|
||||
/* different arc, same depth */
|
||||
if (otherArc != connectedArc && otherArc->flags == connectedArc->flags)
|
||||
{
|
||||
/* not on the symmetry axis */
|
||||
issymmetryAxis = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* arc could be on the symmetry axis */
|
||||
if (issymmetryAxis == 1)
|
||||
{
|
||||
/* no arc as been marked previously, keep this one */
|
||||
if (arc == NULL)
|
||||
{
|
||||
arc = connectedArc;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* there can't be more than one symmetry arc */
|
||||
arc = NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* go down the arc continuing the symmetry axis */
|
||||
if (arc)
|
||||
{
|
||||
markdownSymmetryArc(arc, node, level);
|
||||
}
|
||||
|
||||
|
||||
/* secondary symmetry */
|
||||
for (i = 0; node->arcs[i] != NULL; i++)
|
||||
{
|
||||
ReebArc *connectedArc = node->arcs[i];
|
||||
|
||||
/* only arcs not already marked as symetric and is not the next arc on the symmetry axis */
|
||||
if (connectedArc->flags < 0)
|
||||
{
|
||||
/* subtree depth is store as a negative value in the flag */
|
||||
markdownSecondarySymmetry(node, -connectedArc->flags, level);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void markdownSymmetry(ReebGraph *rg)
|
||||
{
|
||||
ReebNode *node;
|
||||
ReebArc *arc;
|
||||
/* only for Acyclic graphs */
|
||||
int cyclic = isGraphCyclic(rg);
|
||||
|
||||
/* mark down all arcs as non-symetric */
|
||||
for (arc = rg->arcs.first; arc; arc = arc->next)
|
||||
{
|
||||
arc->flags = 0;
|
||||
}
|
||||
|
||||
/* mark down all nodes as not on the symmetry axis */
|
||||
for (node = rg->nodes.first; node; node = node->next)
|
||||
{
|
||||
node->flags = 0;
|
||||
}
|
||||
|
||||
/* node list is sorted, so lowest node is always the head (by design) */
|
||||
node = rg->nodes.first;
|
||||
|
||||
/* only work on acyclic graphs and if only one arc is incident on the first node */
|
||||
if (cyclic == 0 && countConnectedArcs(rg, node) == 1)
|
||||
{
|
||||
arc = node->arcs[0];
|
||||
|
||||
markdownSymmetryArc(arc, node, 1);
|
||||
|
||||
/* mark down non-symetric arcs */
|
||||
for (arc = rg->arcs.first; arc; arc = arc->next)
|
||||
{
|
||||
if (arc->flags < 0)
|
||||
{
|
||||
arc->flags = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* mark down nodes with the lowest level symmetry axis */
|
||||
if (arc->v1->flags == 0 || arc->v1->flags > arc->flags)
|
||||
{
|
||||
arc->v1->flags = arc->flags;
|
||||
}
|
||||
if (arc->v2->flags == 0 || arc->v2->flags > arc->flags)
|
||||
{
|
||||
arc->v2->flags = arc->flags;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**************************************** SUBDIVISION ALGOS ******************************************/
|
||||
|
||||
@ -5114,7 +4579,7 @@ EditBone * subdivideByAngle(ReebArc *arc, ReebNode *head, ReebNode *tail)
|
||||
return lastBone;
|
||||
}
|
||||
|
||||
float calcCorrelation(ReebArc *arc, int start, int end, float v0[3], float n[3])
|
||||
float calcVariance(ReebArc *arc, int start, int end, float v0[3], float n[3])
|
||||
{
|
||||
int len = 2 + abs(end - start);
|
||||
|
||||
@ -5162,19 +4627,47 @@ float calcCorrelation(ReebArc *arc, int start, int end, float v0[3], float n[3])
|
||||
/* adding start(0) and end(1) values to s_t */
|
||||
s_t += (avg_t * avg_t) + (1 - avg_t) * (1 - avg_t);
|
||||
|
||||
return 1.0f - s_xyz / s_t;
|
||||
return s_xyz / s_t;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 1.0f;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
float calcDistance(ReebArc *arc, int start, int end, float head[3], float tail[3])
|
||||
{
|
||||
ReebArcIterator iter;
|
||||
EmbedBucket *bucket = NULL;
|
||||
float max_dist = 0;
|
||||
|
||||
/* calculate maximum distance */
|
||||
for (initArcIterator2(&iter, arc, start, end), bucket = nextBucket(&iter);
|
||||
bucket;
|
||||
bucket = nextBucket(&iter))
|
||||
{
|
||||
float v1[3], v2[3], c[3];
|
||||
float dist;
|
||||
|
||||
VecSubf(v1, head, tail);
|
||||
VecSubf(v2, bucket->p, tail);
|
||||
|
||||
Crossf(c, v1, v2);
|
||||
|
||||
dist = Inpf(c, c) / Inpf(v1, v1);
|
||||
|
||||
max_dist = dist > max_dist ? dist : max_dist;
|
||||
}
|
||||
|
||||
|
||||
return max_dist;
|
||||
}
|
||||
|
||||
EditBone * subdivideByCorrelation(ReebArc *arc, ReebNode *head, ReebNode *tail)
|
||||
{
|
||||
ReebArcIterator iter;
|
||||
float n[3];
|
||||
float CORRELATION_THRESHOLD = G.scene->toolsettings->skgen_correlation_limit;
|
||||
float ADAPTIVE_THRESHOLD = G.scene->toolsettings->skgen_correlation_limit;
|
||||
EditBone *lastBone = NULL;
|
||||
|
||||
/* init iterator to get start and end from head */
|
||||
@ -5183,15 +4676,17 @@ EditBone * subdivideByCorrelation(ReebArc *arc, ReebNode *head, ReebNode *tail)
|
||||
/* Calculate overall */
|
||||
VecSubf(n, arc->buckets[iter.end].p, head->p);
|
||||
|
||||
if (G.scene->toolsettings->skgen_options & SKGEN_CUT_CORRELATION &&
|
||||
calcCorrelation(arc, iter.start, iter.end, head->p, n) < CORRELATION_THRESHOLD)
|
||||
if (G.scene->toolsettings->skgen_options & SKGEN_CUT_CORRELATION)
|
||||
{
|
||||
EmbedBucket *bucket = NULL;
|
||||
EmbedBucket *previous = NULL;
|
||||
EditBone *child = NULL;
|
||||
EditBone *parent = NULL;
|
||||
float normal[3] = {0, 0, 0};
|
||||
float avg_normal[3];
|
||||
int total = 0;
|
||||
int boneStart = iter.start;
|
||||
|
||||
|
||||
parent = add_editbone("Bone");
|
||||
parent->flag = BONE_SELECTED|BONE_TIPSEL|BONE_ROOTSEL;
|
||||
VECCOPY(parent->head, head->p);
|
||||
@ -5200,12 +4695,46 @@ EditBone * subdivideByCorrelation(ReebArc *arc, ReebNode *head, ReebNode *tail)
|
||||
bucket;
|
||||
previous = bucket, bucket = nextBucket(&iter))
|
||||
{
|
||||
/* Calculate normal */
|
||||
VecSubf(n, bucket->p, parent->head);
|
||||
float btail[3];
|
||||
float value = 0;
|
||||
|
||||
if (calcCorrelation(arc, boneStart, iter.index, parent->head, n) < CORRELATION_THRESHOLD)
|
||||
if (G.scene->toolsettings->skgen_options & SKGEN_STICK_TO_EMBEDDING)
|
||||
{
|
||||
VECCOPY(parent->tail, previous->p);
|
||||
VECCOPY(btail, bucket->p);
|
||||
}
|
||||
else
|
||||
{
|
||||
float length;
|
||||
|
||||
/* Calculate normal */
|
||||
VecSubf(n, bucket->p, parent->head);
|
||||
length = Normalize(n);
|
||||
|
||||
total += 1;
|
||||
VecAddf(normal, normal, n);
|
||||
VECCOPY(avg_normal, normal);
|
||||
VecMulf(avg_normal, 1.0f / total);
|
||||
|
||||
VECCOPY(btail, avg_normal);
|
||||
VecMulf(btail, length);
|
||||
VecAddf(btail, btail, parent->head);
|
||||
}
|
||||
|
||||
if (G.scene->toolsettings->skgen_options & SKGEN_ADAPTIVE_DISTANCE)
|
||||
{
|
||||
value = calcDistance(arc, boneStart, iter.index, parent->head, btail);
|
||||
}
|
||||
else
|
||||
{
|
||||
float n[3];
|
||||
|
||||
VecSubf(n, btail, parent->head);
|
||||
value = calcVariance(arc, boneStart, iter.index, parent->head, n);
|
||||
}
|
||||
|
||||
if (value > ADAPTIVE_THRESHOLD)
|
||||
{
|
||||
VECCOPY(parent->tail, btail);
|
||||
|
||||
child = add_editbone("Bone");
|
||||
VECCOPY(child->head, parent->tail);
|
||||
@ -5214,6 +4743,9 @@ EditBone * subdivideByCorrelation(ReebArc *arc, ReebNode *head, ReebNode *tail)
|
||||
|
||||
parent = child; // new child is next parent
|
||||
boneStart = iter.index; // start from end
|
||||
|
||||
normal[0] = normal[1] = normal[2] = 0;
|
||||
total = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -5231,7 +4763,7 @@ float arcLengthRatio(ReebArc *arc)
|
||||
float embedLength = 0.0f;
|
||||
int i;
|
||||
|
||||
arcLength = VecLenf(arc->v1->p, arc->v2->p);
|
||||
arcLength = VecLenf(arc->head->p, arc->tail->p);
|
||||
|
||||
if (arc->bcount > 0)
|
||||
{
|
||||
@ -5241,8 +4773,8 @@ float arcLengthRatio(ReebArc *arc)
|
||||
embedLength += VecLenf(arc->buckets[i - 1].p, arc->buckets[i].p);
|
||||
}
|
||||
/* Add head and tail -> embedding vectors */
|
||||
embedLength += VecLenf(arc->v1->p, arc->buckets[0].p);
|
||||
embedLength += VecLenf(arc->v2->p, arc->buckets[arc->bcount - 1].p);
|
||||
embedLength += VecLenf(arc->head->p, arc->buckets[0].p);
|
||||
embedLength += VecLenf(arc->tail->p, arc->buckets[arc->bcount - 1].p);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -5374,8 +4906,6 @@ void generateSkeletonFromReebGraph(ReebGraph *rg)
|
||||
{
|
||||
exit_editmode(EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR); // freedata, and undo
|
||||
}
|
||||
|
||||
setcursor_space(SPACE_VIEW3D, CURSOR_WAIT);
|
||||
|
||||
dst = add_object(OB_ARMATURE);
|
||||
base_init_from_view3d(BASACT, G.vd);
|
||||
@ -5392,7 +4922,7 @@ void generateSkeletonFromReebGraph(ReebGraph *rg)
|
||||
|
||||
arcBoneMap = BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp);
|
||||
|
||||
markdownSymmetry(rg);
|
||||
BLI_markdownSymmetry((BGraph*)rg, rg->nodes.first, G.scene->toolsettings->skgen_symmetry_limit);
|
||||
|
||||
for (arc = rg->arcs.first; arc; arc = arc->next)
|
||||
{
|
||||
@ -5402,43 +4932,43 @@ void generateSkeletonFromReebGraph(ReebGraph *rg)
|
||||
|
||||
/* Find out the direction of the arc through simple heuristics (in order of priority) :
|
||||
*
|
||||
* 1- Arcs on primary symmetry axis (flags == 1) point up (head: high weight -> tail: low weight)
|
||||
* 1- Arcs on primary symmetry axis (symmetry == 1) point up (head: high weight -> tail: low weight)
|
||||
* 2- Arcs starting on a primary axis point away from it (head: node on primary axis)
|
||||
* 3- Arcs point down (head: low weight -> tail: high weight)
|
||||
*
|
||||
* Finally, the arc direction is stored in its flags: 1 (low -> high), -1 (high -> low)
|
||||
* Finally, the arc direction is stored in its flag: 1 (low -> high), -1 (high -> low)
|
||||
*/
|
||||
|
||||
/* if arc is a symmetry axis, internal bones go up the tree */
|
||||
if (arc->flags == 1 && arc->v2->degree != 1)
|
||||
if (arc->symmetry_level == 1 && arc->tail->degree != 1)
|
||||
{
|
||||
head = arc->v2;
|
||||
tail = arc->v1;
|
||||
head = arc->tail;
|
||||
tail = arc->head;
|
||||
|
||||
arc->flags = -1; /* mark arc direction */
|
||||
arc->flag = -1; /* mark arc direction */
|
||||
}
|
||||
/* Bones point AWAY from the symmetry axis */
|
||||
else if (arc->v1->flags == 1)
|
||||
else if (arc->head->symmetry_level == 1)
|
||||
{
|
||||
head = arc->v1;
|
||||
tail = arc->v2;
|
||||
head = arc->head;
|
||||
tail = arc->tail;
|
||||
|
||||
arc->flags = 1; /* mark arc direction */
|
||||
arc->flag = 1; /* mark arc direction */
|
||||
}
|
||||
else if (arc->v2->flags == 1)
|
||||
else if (arc->tail->symmetry_level == 1)
|
||||
{
|
||||
head = arc->v2;
|
||||
tail = arc->v1;
|
||||
head = arc->tail;
|
||||
tail = arc->head;
|
||||
|
||||
arc->flags = -1; /* mark arc direction */
|
||||
arc->flag = -1; /* mark arc direction */
|
||||
}
|
||||
/* otherwise, always go from low weight to high weight */
|
||||
else
|
||||
{
|
||||
head = arc->v1;
|
||||
tail = arc->v2;
|
||||
head = arc->head;
|
||||
tail = arc->tail;
|
||||
|
||||
arc->flags = 1; /* mark arc direction */
|
||||
arc->flag = 1; /* mark arc direction */
|
||||
}
|
||||
|
||||
/* Loop over subdivision methods */
|
||||
@ -5480,12 +5010,12 @@ void generateSkeletonFromReebGraph(ReebGraph *rg)
|
||||
ReebArc *incomingArc = NULL;
|
||||
int i;
|
||||
|
||||
for (i = 0; node->arcs[i] != NULL; i++)
|
||||
for (i = 0; i < node->degree; i++)
|
||||
{
|
||||
arc = node->arcs[i];
|
||||
arc = (ReebArc*)node->arcs[i];
|
||||
|
||||
/* if arc is incoming into the node */
|
||||
if ((arc->v1 == node && arc->flags == -1) || (arc->v2 == node && arc->flags == 1))
|
||||
if ((arc->head == node && arc->flag == -1) || (arc->tail == node && arc->flag == 1))
|
||||
{
|
||||
if (incomingArc == NULL)
|
||||
{
|
||||
@ -5506,12 +5036,12 @@ void generateSkeletonFromReebGraph(ReebGraph *rg)
|
||||
EditBone *parentBone = BLI_ghash_lookup(arcBoneMap, incomingArc);
|
||||
|
||||
/* Look for outgoing arcs and parent their bones */
|
||||
for (i = 0; node->arcs[i] != NULL; i++)
|
||||
for (i = 0; i < node->degree; i++)
|
||||
{
|
||||
arc = node->arcs[i];
|
||||
|
||||
/* if arc is outgoing from the node */
|
||||
if ((arc->v1 == node && arc->flags == 1) || (arc->v2 == node && arc->flags == -1))
|
||||
if ((arc->head == node && arc->flag == 1) || (arc->tail == node && arc->flag == -1))
|
||||
{
|
||||
EditBone *childBone = BLI_ghash_lookup(arcBoneMap, arc);
|
||||
|
||||
@ -5529,89 +5059,21 @@ void generateSkeletonFromReebGraph(ReebGraph *rg)
|
||||
}
|
||||
|
||||
BLI_ghash_free(arcBoneMap, NULL, NULL);
|
||||
|
||||
setcursor_space(SPACE_VIEW3D, CURSOR_EDIT);
|
||||
|
||||
BIF_undo_push("Generate Skeleton");
|
||||
}
|
||||
|
||||
void generateSkeleton(void)
|
||||
{
|
||||
EditMesh *em = G.editMesh;
|
||||
ReebGraph *rg = NULL;
|
||||
int i;
|
||||
ReebGraph *reebg;
|
||||
|
||||
if (em == NULL)
|
||||
return;
|
||||
|
||||
setcursor_space(SPACE_VIEW3D, CURSOR_WAIT);
|
||||
|
||||
if (weightFromDistance(em) == 0)
|
||||
{
|
||||
error("No selected vertex\n");
|
||||
return;
|
||||
}
|
||||
|
||||
renormalizeWeight(em, 1.0f);
|
||||
|
||||
weightToHarmonic(em);
|
||||
|
||||
#ifdef DEBUG_REEB
|
||||
weightToVCol(em);
|
||||
#endif
|
||||
|
||||
rg = generateReebGraph(em, G.scene->toolsettings->skgen_resolution);
|
||||
reebg = BIF_ReebGraphFromEditMesh();
|
||||
|
||||
verifyBuckets(rg);
|
||||
|
||||
/* Remove arcs without embedding */
|
||||
filterNullReebGraph(rg);
|
||||
generateSkeletonFromReebGraph(reebg);
|
||||
|
||||
verifyBuckets(rg);
|
||||
REEB_freeGraph(reebg);
|
||||
|
||||
|
||||
i = 1;
|
||||
/* filter until there's nothing more to do */
|
||||
while (i == 1)
|
||||
{
|
||||
i = 0; /* no work done yet */
|
||||
|
||||
if (G.scene->toolsettings->skgen_options & SKGEN_FILTER_EXTERNAL)
|
||||
{
|
||||
i |= filterExternalReebGraph(rg, G.scene->toolsettings->skgen_threshold_external * G.scene->toolsettings->skgen_resolution);
|
||||
}
|
||||
|
||||
verifyBuckets(rg);
|
||||
|
||||
if (G.scene->toolsettings->skgen_options & SKGEN_FILTER_INTERNAL)
|
||||
{
|
||||
i |= filterInternalReebGraph(rg, G.scene->toolsettings->skgen_threshold_internal * G.scene->toolsettings->skgen_resolution);
|
||||
}
|
||||
}
|
||||
|
||||
verifyBuckets(rg);
|
||||
|
||||
repositionNodes(rg);
|
||||
|
||||
verifyBuckets(rg);
|
||||
|
||||
/* Filtering might have created degree 2 nodes, so remove them */
|
||||
removeNormalNodes(rg);
|
||||
|
||||
verifyBuckets(rg);
|
||||
|
||||
for(i = 0; i < G.scene->toolsettings->skgen_postpro_passes; i++)
|
||||
{
|
||||
postprocessGraph(rg, G.scene->toolsettings->skgen_postpro);
|
||||
}
|
||||
|
||||
buildAdjacencyList(rg);
|
||||
|
||||
sortNodes(rg);
|
||||
|
||||
sortArcs(rg);
|
||||
|
||||
generateSkeletonFromReebGraph(rg);
|
||||
|
||||
freeGraph(rg);
|
||||
setcursor_space(SPACE_VIEW3D, CURSOR_EDIT);
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -149,6 +149,8 @@
|
||||
|
||||
#include "PIL_time.h"
|
||||
|
||||
#include "reeb.h"
|
||||
|
||||
#include "GPU_extensions.h"
|
||||
#include "GPU_draw.h"
|
||||
|
||||
@ -1099,6 +1101,9 @@ void exit_usiblender(void)
|
||||
|
||||
BIF_clear_tempfiles();
|
||||
|
||||
BIF_GlobalReebFree();
|
||||
BIF_freeRetarget();
|
||||
|
||||
tf= G.ttfdata.first;
|
||||
while(tf)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user