[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [15684] branches/soc-2008-nicholasbishop/ source/blender: Started removing the old multires code.
Nicholas Bishop
nicholasbishop at gmail.com
Tue Jul 22 01:41:01 CEST 2008
Revision: 15684
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15684
Author: nicholasbishop
Date: 2008-07-22 01:41:01 +0200 (Tue, 22 Jul 2008)
Log Message:
-----------
Started removing the old multires code. Also removed a few pointers in the DNA data that won't be needed for backwards-compat. Put a warning in the Python code as a reminder that it'll need to be updated to work with the new multires code.
Modified Paths:
--------------
branches/soc-2008-nicholasbishop/source/blender/blenkernel/BKE_multires.h
branches/soc-2008-nicholasbishop/source/blender/blenkernel/intern/multires.c
branches/soc-2008-nicholasbishop/source/blender/blenloader/intern/readfile.c
branches/soc-2008-nicholasbishop/source/blender/makesdna/DNA_meshdata_types.h
branches/soc-2008-nicholasbishop/source/blender/python/api2_2x/Mesh.c
branches/soc-2008-nicholasbishop/source/blender/src/buttons_editing.c
branches/soc-2008-nicholasbishop/source/blender/src/multires.c
Modified: branches/soc-2008-nicholasbishop/source/blender/blenkernel/BKE_multires.h
===================================================================
--- branches/soc-2008-nicholasbishop/source/blender/blenkernel/BKE_multires.h 2008-07-21 22:36:05 UTC (rev 15683)
+++ branches/soc-2008-nicholasbishop/source/blender/blenkernel/BKE_multires.h 2008-07-21 23:41:01 UTC (rev 15684)
@@ -41,7 +41,6 @@
struct MultiresLevel *multires_level_n(struct Multires *mr, int n);
/* Level control */
-void multires_add_level(struct Object *ob, struct Mesh *me, const char subdiv_type);
void multires_set_level(struct Object *ob, struct Mesh *me, const int render);
void multires_free_level(struct MultiresLevel *lvl);
Modified: branches/soc-2008-nicholasbishop/source/blender/blenkernel/intern/multires.c
===================================================================
--- branches/soc-2008-nicholasbishop/source/blender/blenkernel/intern/multires.c 2008-07-21 22:36:05 UTC (rev 15683)
+++ branches/soc-2008-nicholasbishop/source/blender/blenkernel/intern/multires.c 2008-07-21 23:41:01 UTC (rev 15684)
@@ -71,21 +71,6 @@
return NULL;
}
-/* Free and clear the temporary connectivity data */
-static void multires_free_temp_data(MultiresLevel *lvl)
-{
- if(lvl) {
- if(lvl->edge_boundary_states) MEM_freeN(lvl->edge_boundary_states);
- if(lvl->vert_edge_map) MEM_freeN(lvl->vert_edge_map);
- if(lvl->vert_face_map) MEM_freeN(lvl->vert_face_map);
- if(lvl->map_mem) MEM_freeN(lvl->map_mem);
-
- lvl->edge_boundary_states = NULL;
- lvl->vert_edge_map = lvl->vert_face_map = NULL;
- lvl->map_mem = NULL;
- }
-}
-
/* Does not actually free lvl itself */
void multires_free_level(MultiresLevel *lvl)
{
@@ -93,8 +78,6 @@
if(lvl->faces) MEM_freeN(lvl->faces);
if(lvl->edges) MEM_freeN(lvl->edges);
if(lvl->colfaces) MEM_freeN(lvl->colfaces);
-
- multires_free_temp_data(lvl);
}
}
@@ -133,9 +116,6 @@
lvl->faces= MEM_dupallocN(orig->faces);
lvl->colfaces= MEM_dupallocN(orig->colfaces);
lvl->edges= MEM_dupallocN(orig->edges);
- lvl->edge_boundary_states = NULL;
- lvl->vert_edge_map= lvl->vert_face_map= NULL;
- lvl->map_mem= NULL;
return lvl;
}
@@ -416,60 +396,6 @@
unsigned Index;
} MultiresMapNode;
-/* Produces temporary connectivity data for the multires lvl */
-static void multires_calc_temp_data(MultiresLevel *lvl)
-{
- unsigned i, j, emax;
- MultiresMapNode *indexnode= NULL;
-
- lvl->map_mem= MEM_mallocN(sizeof(MultiresMapNode)*(lvl->totedge*2 + lvl->totface*4), "map_mem");
- indexnode= lvl->map_mem;
-
- /* edge map */
- lvl->vert_edge_map= MEM_callocN(sizeof(ListBase)*lvl->totvert,"vert_edge_map");
- for(i=0; i<lvl->totedge; ++i) {
- for(j=0; j<2; ++j, ++indexnode) {
- indexnode->Index= i;
- BLI_addtail(&lvl->vert_edge_map[lvl->edges[i].v[j]], indexnode);
- }
- }
-
- /* face map */
- lvl->vert_face_map= MEM_callocN(sizeof(ListBase)*lvl->totvert,"vert_face_map");
- for(i=0; i<lvl->totface; ++i){
- for(j=0; j<(lvl->faces[i].v[3]?4:3); ++j, ++indexnode) {
- indexnode->Index= i;
- BLI_addtail(&lvl->vert_face_map[lvl->faces[i].v[j]], indexnode);
- }
- }
-
- /* edge boundaries */
- emax = (lvl->prev ? (lvl->prev->totedge * 2) : lvl->totedge);
- lvl->edge_boundary_states= MEM_callocN(sizeof(char)*lvl->totedge, "edge_boundary_states");
- for(i=0; i<emax; ++i) {
- MultiresMapNode *n1= lvl->vert_face_map[lvl->edges[i].v[0]].first;
- unsigned total= 0;
-
- lvl->edge_boundary_states[i] = 1;
- while(n1 && lvl->edge_boundary_states[i] == 1) {
- MultiresMapNode *n2= lvl->vert_face_map[lvl->edges[i].v[1]].first;
- while(n2) {
- if(n1->Index == n2->Index) {
- ++total;
-
- if(total > 1) {
- lvl->edge_boundary_states[i] = 0;
- break;
- }
- }
-
- n2= n2->next;
- }
- n1= n1->next;
- }
- }
-}
-
/* CATMULL-CLARK
============= */
@@ -493,266 +419,9 @@
float boundary_edges_average[3];
} MultiApplyData;
-/* Simply averages the four corners of a polygon. */
-static float catmullclark_smooth_face(MultiApplyData *data, const unsigned i)
-{
- const float total= data->corner1[i]+data->corner2[i]+data->corner3[i];
- return data->quad ? (total+data->corner4[i])/4 : total/3;
-}
-
-static float catmullclark_smooth_edge(MultiApplyData *data, const unsigned i)
-{
- float accum= 0;
- unsigned count= 2;
-
- accum+= data->endpoint1[i] + data->endpoint2[i];
-
- if(!data->boundary) {
- accum+= data->edge_face_neighbor_midpoints_accum[i];
- count+= data->edge_face_neighbor_midpoints_total;
- }
-
- return accum / count;
-}
-
-static float catmullclark_smooth_vert(MultiApplyData *data, const unsigned i)
-{
- if(data->boundary) {
- return data->original[i]*0.75 + data->boundary_edges_average[i]*0.25;
- } else {
- return (data->vert_face_neighbor_midpoints_average[i] +
- 2*data->vert_edge_neighbor_midpoints_average[i] +
- data->original[i]*(data->edge_count-3))/data->edge_count;
- }
-}
-
-
-
-/* Call func count times, passing in[i] as the input and storing the output in out[i] */
-static void multi_apply(float *out, MultiApplyData *data,
- const unsigned count, float (*func)(MultiApplyData *, const unsigned))
-{
- unsigned i;
- for(i=0; i<count; ++i)
- out[i]= func(data,i);
-}
-
-static short multires_vert_is_boundary(MultiresLevel *lvl, unsigned v)
-{
- MultiresMapNode *node= lvl->vert_edge_map[v].first;
- while(node) {
- if(lvl->edge_boundary_states[node->Index])
- return 1;
- node= node->next;
- }
- return 0;
-}
-
-#define GET_FLOAT(array, i, j, stride) (((float*)((char*)(array)+((i)*(stride))))[(j)])
-
-static void edge_face_neighbor_midpoints_accum(MultiApplyData *data, MultiresLevel *lvl,
- void *array, const char stride, const MultiresEdge *e)
-{
- ListBase *neighbors1= &lvl->vert_face_map[e->v[0]];
- ListBase *neighbors2= &lvl->vert_face_map[e->v[1]];
- MultiresMapNode *n1, *n2;
- unsigned j,count= 0;
- float *out= data->edge_face_neighbor_midpoints_accum;
-
- out[0]=out[1]=out[2]= 0;
-
- for(n1= neighbors1->first; n1; n1= n1->next) {
- for(n2= neighbors2->first; n2; n2= n2->next) {
- if(n1->Index == n2->Index) {
- for(j=0; j<3; ++j)
- out[j]+= GET_FLOAT(array,lvl->faces[n1->Index].mid,j,stride);
- ++count;
- }
- }
- }
-
- data->edge_face_neighbor_midpoints_total= count;
-}
-
-static void vert_face_neighbor_midpoints_average(MultiApplyData *data, MultiresLevel *lvl,
- void *array, const char stride, const unsigned i)
-{
- ListBase *neighbors= &lvl->vert_face_map[i];
- MultiresMapNode *n1;
- unsigned j,count= 0;
- float *out= data->vert_face_neighbor_midpoints_average;
-
- out[0]=out[1]=out[2]= 0;
-
- for(n1= neighbors->first; n1; n1= n1->next) {
- for(j=0; j<3; ++j)
- out[j]+= GET_FLOAT(array,lvl->faces[n1->Index].mid,j,stride);
- ++count;
- }
- for(j=0; j<3; ++j) out[j]/= count;
-}
-
-static void vert_edge_neighbor_midpoints_average(MultiApplyData *data, MultiresLevel *lvl,
- void *array, const char stride, const unsigned i)
-{
- ListBase *neighbors= &lvl->vert_edge_map[i];
- MultiresMapNode *n1;
- unsigned j,count= 0;
- float *out= data->vert_edge_neighbor_midpoints_average;
-
- out[0]=out[1]=out[2]= 0;
-
- for(n1= neighbors->first; n1; n1= n1->next) {
- for(j=0; j<3; ++j)
- out[j]+= (GET_FLOAT(array,lvl->edges[n1->Index].v[0],j,stride) +
- GET_FLOAT(array,lvl->edges[n1->Index].v[1],j,stride)) / 2;
- ++count;
- }
- for(j=0; j<3; ++j) out[j]/= count;
-}
-
-static void boundary_edges_average(MultiApplyData *data, MultiresLevel *lvl,
- void *array, const char stride, const unsigned i)
-{
- ListBase *neighbors= &lvl->vert_edge_map[i];
- MultiresMapNode *n1;
- unsigned j,count= 0;
- float *out= data->boundary_edges_average;
-
- out[0]=out[1]=out[2]= 0;
-
- for(n1= neighbors->first; n1; n1= n1->next) {
- const MultiresEdge *e= &lvl->edges[n1->Index];
- const unsigned end= e->v[0]==i ? e->v[1] : e->v[0];
-
- if(lvl->edge_boundary_states[n1->Index]) {
- for(j=0; j<3; ++j)
- out[j]+= GET_FLOAT(array,end,j,stride);
- ++count;
- }
- }
- for(j=0; j<3; ++j) out[j]/= count;
-}
-
/* END CATMULL-CLARK
================= */
-/* Update vertex locations and vertex flags */
-static void multires_update_vertices(Mesh *me, EditMesh *em)
-{
- MultiresLevel *cr_lvl= current_level(me->mr), *pr_lvl= NULL,
- *last_lvl= me->mr->levels.last;
- vec3f *pr_deltas= NULL, *cr_deltas= NULL, *swap_deltas= NULL;
- EditVert *eve= NULL;
- MultiApplyData data;
- int i, j;
-
- /* Prepare deltas */
- pr_deltas= MEM_callocN(sizeof(vec3f)*last_lvl->totvert, "multires deltas 1");
- cr_deltas= MEM_callocN(sizeof(vec3f)*last_lvl->totvert, "multires deltas 2");
-
- /* Calculate initial deltas -- current mesh subtracted from current level*/
- if(em) eve= em->verts.first;
- for(i=0; i<cr_lvl->totvert; ++i) {
- if(em) {
- VecSubf(&cr_deltas[i].x, eve->co, me->mr->verts[i].co);
- eve= eve->next;
- } else
- VecSubf(&cr_deltas[i].x, me->mvert[i].co, me->mr->verts[i].co);
- }
-
-
- /* Copy current level's vertex flags and clear the rest */
- if(em) eve= em->verts.first;
- for(i=0; i < last_lvl->totvert; ++i) {
- if(i < cr_lvl->totvert) {
- MVert mvflag;
- multires_get_vert(&mvflag, eve, &me->mvert[i], i);
- if(em) eve= eve->next;
- me->mr->verts[i].flag= mvflag.flag;
- }
- else
- me->mr->verts[i].flag= 0;
- }
-
- /* If already on the highest level, copy current verts (including flags) into current level */
- if(cr_lvl == last_lvl) {
- if(em)
- eve= em->verts.first;
- for(i=0; i<cr_lvl->totvert; ++i) {
- multires_get_vert(&me->mr->verts[i], eve, &me->mvert[i], i);
- if(em) eve= eve->next;
- }
- }
-
- /* Update higher levels */
- pr_lvl= BLI_findlink(&me->mr->levels,me->mr->current-1);
- cr_lvl= pr_lvl->next;
- while(cr_lvl) {
- multires_calc_temp_data(pr_lvl);
-
- /* Swap the old/new deltas */
- swap_deltas= pr_deltas;
- pr_deltas= cr_deltas;
- cr_deltas= swap_deltas;
-
- /* Calculate and add new deltas
- ============================ */
- for(i=0; i<pr_lvl->totface; ++i) {
- const MultiresFace *f= &pr_lvl->faces[i];
- data.corner1= &pr_deltas[f->v[0]].x;
- data.corner2= &pr_deltas[f->v[1]].x;
- data.corner3= &pr_deltas[f->v[2]].x;
- data.corner4= &pr_deltas[f->v[3]].x;
- data.quad= f->v[3] ? 1 : 0;
- multi_apply(&cr_deltas[f->mid].x, &data, 3, catmullclark_smooth_face);
-
- for(j=0; j<(data.quad?4:3); ++j)
- me->mr->verts[f->mid].flag |= me->mr->verts[f->v[j]].flag;
- }
-
- for(i=0; i<pr_lvl->totedge; ++i) {
- const MultiresEdge *e= &pr_lvl->edges[i];
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list