[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [42689] branches/soc-2011-onion-uv-tools/ source/blender/editors/uvedit: move smart stitch to its own file
Antony Riakiotakis
kalast at gmail.com
Sat Dec 17 14:58:33 CET 2011
Revision: 42689
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=42689
Author: psy-fi
Date: 2011-12-17 13:58:16 +0000 (Sat, 17 Dec 2011)
Log Message:
-----------
move smart stitch to its own file
Modified Paths:
--------------
branches/soc-2011-onion-uv-tools/source/blender/editors/uvedit/CMakeLists.txt
branches/soc-2011-onion-uv-tools/source/blender/editors/uvedit/uvedit_intern.h
branches/soc-2011-onion-uv-tools/source/blender/editors/uvedit/uvedit_ops.c
Added Paths:
-----------
branches/soc-2011-onion-uv-tools/source/blender/editors/uvedit/uvedit_smart_stitch.c
Modified: branches/soc-2011-onion-uv-tools/source/blender/editors/uvedit/CMakeLists.txt
===================================================================
--- branches/soc-2011-onion-uv-tools/source/blender/editors/uvedit/CMakeLists.txt 2011-12-17 13:23:04 UTC (rev 42688)
+++ branches/soc-2011-onion-uv-tools/source/blender/editors/uvedit/CMakeLists.txt 2011-12-17 13:58:16 UTC (rev 42689)
@@ -42,6 +42,7 @@
uvedit_unwrap_ops.c
uvedit_intern.h
uvedit_parametrizer.h
+ uvedit_smart_stitch.c
)
blender_add_lib(bf_editor_uvedit "${SRC}" "${INC}" "${INC_SYS}")
Modified: branches/soc-2011-onion-uv-tools/source/blender/editors/uvedit/uvedit_intern.h
===================================================================
--- branches/soc-2011-onion-uv-tools/source/blender/editors/uvedit/uvedit_intern.h 2011-12-17 13:23:04 UTC (rev 42688)
+++ branches/soc-2011-onion-uv-tools/source/blender/editors/uvedit/uvedit_intern.h 2011-12-17 13:58:16 UTC (rev 42689)
@@ -90,8 +90,10 @@
/* utility tool functions */
void find_nearest_uv_vert(struct Scene *scene, struct Image *ima, struct EditMesh *em, float co[2], float penalty[2], struct NearestHit *hit);
+void find_nearest_uv_edge(struct Scene *scene, struct Image *ima, struct EditMesh *em, float co[2], struct NearestHit *hit);
struct UvElement *get_uv_element(struct UvElementMap *map, struct EditFace *efa, int index);
StitchPreviewer *uv_get_stitch_previewer(void);
+void uvedit_live_unwrap_update(struct SpaceImage *sima, struct Scene *scene, struct Object *obedit);
/* operators */
void UV_OT_average_islands_scale(struct wmOperatorType *ot);
@@ -103,6 +105,7 @@
void UV_OT_reset(struct wmOperatorType *ot);
void UV_OT_sphere_project(struct wmOperatorType *ot);
void UV_OT_unwrap(struct wmOperatorType *ot);
+void UV_OT_stitch(struct wmOperatorType *ot);
#endif /* ED_UVEDIT_INTERN_H */
Modified: branches/soc-2011-onion-uv-tools/source/blender/editors/uvedit/uvedit_ops.c
===================================================================
--- branches/soc-2011-onion-uv-tools/source/blender/editors/uvedit/uvedit_ops.c 2011-12-17 13:23:04 UTC (rev 42688)
+++ branches/soc-2011-onion-uv-tools/source/blender/editors/uvedit/uvedit_ops.c 2011-12-17 13:58:16 UTC (rev 42689)
@@ -402,7 +402,7 @@
/*********************** live unwrap utilities ***********************/
-static void uvedit_live_unwrap_update(SpaceImage *sima, Scene *scene, Object *obedit)
+void uvedit_live_unwrap_update(SpaceImage *sima, Scene *scene, Object *obedit)
{
if(sima && (sima->flag & SI_LIVE_UNWRAP)) {
ED_uvedit_live_unwrap_begin(scene, obedit);
@@ -529,7 +529,7 @@
/************************** find nearest ****************************/
-static void find_nearest_uv_edge(Scene *scene, Image *ima, EditMesh *em, float co[2], NearestHit *hit)
+void find_nearest_uv_edge(Scene *scene, Image *ima, EditMesh *em, float co[2], NearestHit *hit)
{
MTFace *tf;
EditFace *efa;
@@ -1300,1805 +1300,6 @@
ot->poll= ED_operator_uvedit;
}
-/* ********************** smart stitch operator *********************** */
-
-
-struct IslandStitchData;
-
-/* This is a straightforward implementation, count the uv's in the island that will move and take the mean displacement/rotation and apply it to all
- * elements of the island except from the stitchable */
-typedef struct IslandStitchData{
- /* rotation can be used only for edges, for vertices there is no such notion */
- float rotation;
- float translation[2];
- /* Used for rotation, the island will rotate around this point */
- float medianPoint[2];
- int numOfElements;
- int numOfEdges;
- /* Flag to remember if island has been added for preview */
- char addedForPreview;
- /* Flag an island to be considered for determining static island */
- char stitchableCandidate;
-}IslandStitchData;
-
-/* just for averaging UVs */
-typedef struct UVVertAverage {
- float uv[2];
- unsigned short count;
-} UVVertAverage;
-
-typedef struct UvEdge {
- /* index to uv buffer */
- unsigned int uv1;
- unsigned int uv2;
- /* general use flag (Used to check if edge is boundary here, and propagates to adjacency elements) */
- char flag;
- /* element that guarantees element->face has the face on element->tfindex and element->tfindex+1 is the second uv */
- UvElement *element;
-}UvEdge;
-
-#define STITCHNEW
-
-/* stitch state object */
-typedef struct StitchState {
- /* edge or vertex stitch mode */
- char mode;
- /* use limit flag */
- char use_limit;
- /* limit to operator, same as original operator */
- float limitDist;
- /* snap uv islands together during stitching */
- char snapIslands;
- /* stich at midpoints or at islands */
- char midpoints;
- /* editmesh, cached for use in modal handler */
- EditMesh *em;
- /* element map for getting info about uv connectivity */
- UvElementMap *elementMap;
- /* Edge container */
- UvEdge *uvedges;
- /* container of first of a group of coincident uvs, these will be operated upon */
- UvElement **uvs;
- int total_separate_uvs;
- /* maps uvelements to their first coincident uv */
- int *map;
- /* hold selection related information */
- void **selection_stack;
- int selection_size;
- /* island that stays in place */
- int static_island;
- /* For fast edge lookup... */
- GHash *edgeHash;
- /* ...And actual edge storage */
- UvEdge *edges;
- int total_edges;
-} StitchState;
-
-
-/*
- * defines for UvElement flags
- */
-#define STITCH_SELECTED 1
-#define STITCH_STITCHABLE 2
-#define STITCH_PROCESSED 4
-#define STITCH_BOUNDARY 8
-#define STITCH_STITCHABLE_CANDIDATE 16
-
-#define STITCH_NO_PREVIEW -1
-/* Previewer stuff (see uvedit_intern.h for more info) */
-static StitchPreviewer *_stitch_preview;
-
-/* constructor */
-static StitchPreviewer * stitch_preview_init(void)
-{
- _stitch_preview = MEM_mallocN(sizeof(StitchPreviewer), "stitch_previewer");
- _stitch_preview->previewQuads = NULL;
- _stitch_preview->previewTris = NULL;
- _stitch_preview->previewStitchable = NULL;
- _stitch_preview->previewUnstitchable = NULL;
-
- _stitch_preview->numOfQuads = 0;
- _stitch_preview->numOfTris = 0;
- _stitch_preview->numOfStitchable = 0;
- _stitch_preview->numOfUnstitchable = 0;
- _stitch_preview->mode = 0;
-
- _stitch_preview->enabled = 1;
- return _stitch_preview;
-}
-
-/* destructor...yeah this should be C++ :) */
-static void stitch_preview_delete(void)
-{
- if(_stitch_preview)
- {
- if(_stitch_preview->previewQuads)
- {
- MEM_freeN(_stitch_preview->previewQuads);
- _stitch_preview->previewQuads = NULL;
- }
- if(_stitch_preview->previewTris)
- {
- MEM_freeN(_stitch_preview->previewTris);
- _stitch_preview->previewTris = NULL;
- }
- if(_stitch_preview->previewStitchable)
- {
- MEM_freeN(_stitch_preview->previewStitchable);
- _stitch_preview->previewStitchable = NULL;
- }
- if(_stitch_preview->previewUnstitchable)
- {
- MEM_freeN(_stitch_preview->previewUnstitchable);
- _stitch_preview->previewUnstitchable = NULL;
- }
- MEM_freeN(_stitch_preview);
- _stitch_preview = NULL;
- }
-}
-
-
-/* "getter method" */
-StitchPreviewer *uv_get_stitch_previewer(void)
-{
- return _stitch_preview;
-}
-
-
-/* This function updates the header of the UV editor when the stitch tool updates its settings */
-static void stitch_update_header(StitchState *stitch_state, bContext *C)
-{
- static char str[] = "Select(V {+Ctrl deselect}) Toggle(T) %c Vertex %c Edge, %c Preview(P), %c Limit(L), %c Snap(S), %c Midpoints(M), (Ctrl+Wheel/-+)Limit Adjust: %.2f, Switch Static Island(I) ";
- char msg[256];
- ScrArea *sa= CTX_wm_area(C);
- char mode = (stitch_state->mode == VERT_STITCH);
-
- if(sa) {
- sprintf(msg, str, (mode)? '*':' ',
- (!mode)? '*':' ',
- uv_get_stitch_previewer()->enabled?'*':' ',
- stitch_state->use_limit?'*':' ',
- stitch_state->snapIslands?'*' :' ',
- stitch_state->midpoints?'*' :' ' ,
- stitch_state->limitDist);
- ED_area_headerprint(sa, msg);
- }
-}
-
-static int getNumOfIslandUvs(UvElementMap *elementMap, int island){
- if(island == elementMap->totalIslands-1){
- return elementMap->totalUVs - elementMap->islandIndices[island];
- }else{
- return elementMap->islandIndices[island+1] - elementMap->islandIndices[island];
- }
-}
-
-static void stitch_uv_rotate(float rotation, float medianPoint[2], float uv[2]){
- float uv_rotation_result[2];
-
- uv[0] -= medianPoint[0];
- uv[1] -= medianPoint[1];
-
- uv_rotation_result[0] = cos(rotation)*uv[0] - sin(rotation)*uv[1];
- uv_rotation_result[1] = sin(rotation)*uv[0] + cos(rotation)*uv[1];
-
- uv[0] = uv_rotation_result[0] + medianPoint[0];
- uv[1] = uv_rotation_result[1] + medianPoint[1];
-}
-
-
-/* Calculate snapping for islands */
-static void stitch_calculate_island_snapping(StitchState *state, StitchPreviewer *preview, IslandStitchData *island_stitch_data, int final){
- int i;
- EditFace *efa;
- MTFace *mt;
- UvElement *element;
-
- for(i = 0; i < state->elementMap->totalIslands; i++){
- if(island_stitch_data[i].addedForPreview){
- int numOfIslandUVs = 0, j;
- /* check to avoid divide by 0 */
- if(state->mode == EDGE_STITCH){
- island_stitch_data[i].rotation /= island_stitch_data[i].numOfEdges;
- island_stitch_data[i].medianPoint[0] /= island_stitch_data[i].numOfEdges;
- island_stitch_data[i].medianPoint[1] /= island_stitch_data[i].numOfEdges;
- }
- island_stitch_data[i].translation[0] /= island_stitch_data[i].numOfElements;
- island_stitch_data[i].translation[1] /= island_stitch_data[i].numOfElements;
- numOfIslandUVs = getNumOfIslandUvs(state->elementMap, i);
- element = &state->elementMap->buf[state->elementMap->islandIndices[i]];
- for(j = 0; j < numOfIslandUVs; j++, element++){
- /* stitchable uvs have already been processed, don't process */
- if(!(element->flag & STITCH_PROCESSED)){
- efa = element->face;
- mt = CustomData_em_get(&state->em->fdata, efa->data, CD_MTFACE);
- if(final){
- if(state->mode == EDGE_STITCH){
- stitch_uv_rotate(island_stitch_data[i].rotation, island_stitch_data[i].medianPoint, mt->uv[element->tfindex]);
- }
- mt->uv[element->tfindex][0] += island_stitch_data[i].translation[0];
- mt->uv[element->tfindex][1] += island_stitch_data[i].translation[1];
- }
- else if(efa->tmp.l != STITCH_NO_PREVIEW){
- if(efa->v4){
- if(state->mode == EDGE_STITCH){
- stitch_uv_rotate(island_stitch_data[i].rotation, island_stitch_data[i].medianPoint, &preview->previewQuads[efa->tmp.l + 2*element->tfindex]);
- }
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list