== Sculpt ==

Fixed bad level calls in sculptmode.
This commit is contained in:
2007-12-26 22:40:56 +00:00
parent ae976e087a
commit 015007beaf
18 changed files with 318 additions and 289 deletions

View File

@@ -207,12 +207,6 @@ void post_layer_create(struct VLayer *vlayer);
void post_layer_destroy(struct VLayer *vlayer);
void post_server_add(void);
/* sculptmode.c */
struct SculptData;
void sculpt_reset_curve(struct SculptData *sd);
void sculptmode_free_all(struct Scene *sce);
void sculptmode_init(struct Scene *sce);
/* zbuf.c */
void antialias_tagbuf(int xsize, int ysize, char *rectmove);

View File

@@ -111,6 +111,11 @@ UvVertMap *make_uv_vert_map(struct MFace *mface, struct MTFace *tface, unsigned
UvMapVert *get_uv_map_vert(UvVertMap *vmap, unsigned int v);
void free_uv_vert_map(UvVertMap *vmap);
/* Partial Mesh Visibility */
struct PartialVisibility *mesh_pmv_copy(struct PartialVisibility *);
void mesh_pmv_free(struct PartialVisibility *);
void mesh_pmv_revert(struct Object *ob, struct Mesh *me);
void mesh_pmv_off(struct Object *ob, struct Mesh *me);
/* functions for making menu's from customdata layers */
int mesh_layers_menu_charlen(struct CustomData *data, int type); /* use this to work out how many chars to allocate */

View File

@@ -47,7 +47,7 @@ void multires_edge_level_update(struct Object *ob, struct Mesh *me);
void multires_free(struct Multires *mr);
struct Multires *multires_copy(struct Multires *orig);
void multires_create(struct Mesh *me);
void multires_create(struct Object *ob, struct Mesh *me);
/* CustomData */
void multires_delete_layer(struct Mesh *me, struct CustomData *cd, const int type, int n);

View File

@@ -34,11 +34,13 @@
#ifndef BKE_SCENE_H
#define BKE_SCENE_H
struct bglMats;
struct Scene;
struct Object;
struct Base;
struct AviCodecData;
struct QuicktimeCodecData;
struct SculptData;
/* sequence related defines */
#define WHILE_SEQ(base) { \

View File

@@ -0,0 +1,64 @@
/*
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* 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
* of the License, or (at your option) any later version.
*
* 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,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2007 by Nicholas Bishop
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL LICENSE BLOCK *****
*/
typedef struct SculptSession {
struct ProjVert *projverts;
struct bglMats *mats;
/* An array of lists; array is sized as
large as the number of verts in the mesh,
the list for each vert contains the index
for all the faces that use that vertex */
struct ListBase *vertex_users;
struct IndexNode *vertex_users_mem;
int vertex_users_size;
/* Used temporarily per-stroke */
float *vertexcosnos;
ListBase damaged_rects;
ListBase damaged_verts;
/* Used to cache the render of the active texture */
unsigned int texcache_w, texcache_h, *texcache;
struct PropsetData *propset;
/* For rotating around a pivot point */
vec3f pivot;
struct SculptStroke *stroke;
} SculptSession;
void sculptdata_init(struct Scene *sce);
void sculptdata_free(struct Scene *sce);
void sculptsession_free(struct Scene *sce);
void sculpt_vertexusers_free(struct SculptSession *ss);
void sculpt_reset_curve(struct SculptData *sd);

View File

@@ -310,10 +310,6 @@ void post_geometry_free_constraint(struct VNode *vnode) {}
void post_layer_create(struct VLayer *vlayer) {}
void post_layer_destroy(struct VLayer *vlayer) {}
void post_server_add(void) {}
/* sculpt stubs */
void sculpt_reset_curve(struct SculptData *sd) {}
void sculptmode_init(struct Scene *sce) {}
void sculptmode_free_all(struct Scene *sce) {}
/* zbuf.c stub */
void antialias_tagbuf(int xsize, int ysize, char *rectmove) {}

View File

@@ -55,8 +55,6 @@
#include "DNA_meshdata_types.h"
#include "DNA_ipo_types.h"
#include "BDR_sculptmode.h"
#include "BKE_customdata.h"
#include "BKE_depsgraph.h"
#include "BKE_main.h"
@@ -1230,3 +1228,70 @@ void free_uv_vert_map(UvVertMap *vmap)
}
}
/* Partial Mesh Visibility */
PartialVisibility *mesh_pmv_copy(PartialVisibility *pmv)
{
PartialVisibility *n= MEM_dupallocN(pmv);
n->vert_map= MEM_dupallocN(pmv->vert_map);
n->edge_map= MEM_dupallocN(pmv->edge_map);
n->old_edges= MEM_dupallocN(pmv->old_edges);
n->old_faces= MEM_dupallocN(pmv->old_faces);
return n;
}
void mesh_pmv_free(PartialVisibility *pv)
{
MEM_freeN(pv->vert_map);
MEM_freeN(pv->edge_map);
MEM_freeN(pv->old_faces);
MEM_freeN(pv->old_edges);
MEM_freeN(pv);
}
void mesh_pmv_revert(Object *ob, Mesh *me)
{
if(me->pv) {
unsigned i;
MVert *nve, *old_verts;
/* Reorder vertices */
nve= me->mvert;
old_verts = MEM_mallocN(sizeof(MVert)*me->pv->totvert,"PMV revert verts");
for(i=0; i<me->pv->totvert; ++i)
old_verts[i]= nve[me->pv->vert_map[i]];
/* Restore verts, edges and faces */
CustomData_free_layer_active(&me->vdata, CD_MVERT, me->totvert);
CustomData_free_layer_active(&me->edata, CD_MEDGE, me->totedge);
CustomData_free_layer_active(&me->fdata, CD_MFACE, me->totface);
CustomData_add_layer(&me->vdata, CD_MVERT, CD_ASSIGN, old_verts, me->pv->totvert);
CustomData_add_layer(&me->edata, CD_MEDGE, CD_ASSIGN, me->pv->old_edges, me->pv->totedge);
CustomData_add_layer(&me->fdata, CD_MFACE, CD_ASSIGN, me->pv->old_faces, me->pv->totface);
mesh_update_customdata_pointers(me);
me->totvert= me->pv->totvert;
me->totedge= me->pv->totedge;
me->totface= me->pv->totface;
me->pv->old_edges= NULL;
me->pv->old_faces= NULL;
/* Free maps */
MEM_freeN(me->pv->edge_map);
me->pv->edge_map= NULL;
MEM_freeN(me->pv->vert_map);
me->pv->vert_map= NULL;
DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
}
}
void mesh_pmv_off(Object *ob, Mesh *me)
{
if(ob && me->pv) {
mesh_pmv_revert(ob, me);
MEM_freeN(me->pv);
me->pv= NULL;
}
}

View File

@@ -35,8 +35,6 @@
#include "DNA_object_types.h"
#include "DNA_vec_types.h"
#include "BDR_sculptmode.h"
#include "BIF_editmesh.h"
#include "BLI_arithb.h"
@@ -348,7 +346,7 @@ void multires_load_cols(Mesh *me)
}
}
void multires_create(Mesh *me)
void multires_create(Object *ob, Mesh *me)
{
MultiresLevel *lvl;
EditMesh *em= G.obedit ? G.editMesh : NULL;
@@ -359,7 +357,7 @@ void multires_create(Mesh *me)
lvl= MEM_callocN(sizeof(MultiresLevel), "multires level");
if(me->pv) sculptmode_pmv_off(me);
if(me->pv) mesh_pmv_off(ob, me);
me->mr= MEM_callocN(sizeof(Multires), "multires data");
@@ -1105,7 +1103,7 @@ void multires_add_level(Object *ob, Mesh *me, const char subdiv_type)
MVert *oldverts= NULL;
lvl= MEM_callocN(sizeof(MultiresLevel), "multireslevel");
if(me->pv) sculptmode_pmv_off(me);
if(me->pv) mesh_pmv_off(ob, me);
check_colors(me);
multires_update_levels(me, 0);
@@ -1271,7 +1269,7 @@ void multires_add_level(Object *ob, Mesh *me, const char subdiv_type)
void multires_set_level(Object *ob, Mesh *me, const int render)
{
if(me->pv) sculptmode_pmv_off(me);
if(me->pv) mesh_pmv_off(ob, me);
check_colors(me);
multires_update_levels(me, render);

View File

@@ -47,6 +47,7 @@
#include "MEM_guardedalloc.h"
#include "DNA_armature_types.h"
#include "DNA_color_types.h"
#include "DNA_constraint_types.h"
#include "DNA_curve_types.h"
#include "DNA_group_types.h"
@@ -63,6 +64,7 @@
#include "BKE_anim.h"
#include "BKE_armature.h"
#include "BKE_bad_level_calls.h"
#include "BKE_colortools.h"
#include "BKE_constraint.h"
#include "BKE_depsgraph.h"
#include "BKE_global.h"
@@ -75,11 +77,11 @@
#include "BKE_node.h"
#include "BKE_object.h"
#include "BKE_scene.h"
#include "BKE_sculpt.h"
#include "BKE_world.h"
#include "BKE_utildefines.h"
#include "BIF_previewrender.h"
#include "BDR_sculptmode.h"
#include "BPY_extern.h"
#include "BLI_arithb.h"
@@ -168,7 +170,7 @@ void free_scene(Scene *sce)
MEM_freeN(sce->nodetree);
}
sculptmode_free_all(sce);
sculptdata_free(sce);
}
Scene *add_scene(char *name)
@@ -259,7 +261,7 @@ Scene *add_scene(char *name)
BLI_init_rctf(&sce->r.safety, 0.1f, 0.9f, 0.1f, 0.9f);
sce->r.osa= 8;
sculptmode_init(sce);
sculptdata_init(sce);
/* note; in header_info.c the scene copy happens..., if you add more to renderdata it has to be checked there */
scene_add_render_layer(sce);
@@ -578,3 +580,118 @@ void scene_add_render_layer(Scene *sce)
srl->passflag= SCE_PASS_COMBINED|SCE_PASS_Z;
}
/* Initialize 'permanent' sculpt data that is saved with file kept after
switching out of sculptmode. */
void sculptdata_init(Scene *sce)
{
SculptData *sd;
if(!sce)
return;
sd= &sce->sculptdata;
if(sd->cumap)
curvemapping_free(sd->cumap);
memset(sd, 0, sizeof(SculptData));
sd->drawbrush.size = sd->smoothbrush.size = sd->pinchbrush.size =
sd->inflatebrush.size = sd->grabbrush.size =
sd->layerbrush.size = sd->flattenbrush.size = 50;
sd->drawbrush.strength = sd->smoothbrush.strength =
sd->pinchbrush.strength = sd->inflatebrush.strength =
sd->grabbrush.strength = sd->layerbrush.strength =
sd->flattenbrush.strength = 25;
sd->drawbrush.dir = sd->pinchbrush.dir = sd->inflatebrush.dir = sd->layerbrush.dir= 1;
sd->drawbrush.airbrush = sd->smoothbrush.airbrush =
sd->pinchbrush.airbrush = sd->inflatebrush.airbrush =
sd->layerbrush.airbrush = sd->flattenbrush.airbrush = 0;
sd->drawbrush.view= 0;
sd->brush_type= DRAW_BRUSH;
sd->texact= -1;
sd->texfade= 1;
sd->averaging= 1;
sd->texsep= 0;
sd->texrept= SCULPTREPT_DRAG;
sd->flags= SCULPT_DRAW_BRUSH;
sd->tablet_size=3;
sd->tablet_strength=10;
sd->rake=0;
sculpt_reset_curve(sd);
}
void sculptdata_free(Scene *sce)
{
SculptData *sd= &sce->sculptdata;
int a;
sculptsession_free(sce);
for(a=0; a<MAX_MTEX; a++) {
MTex *mtex= sd->mtex[a];
if(mtex) {
if(mtex->tex) mtex->tex->id.us--;
MEM_freeN(mtex);
}
}
curvemapping_free(sd->cumap);
sd->cumap = NULL;
}
void sculpt_vertexusers_free(SculptSession *ss)
{
if(ss && ss->vertex_users){
MEM_freeN(ss->vertex_users);
MEM_freeN(ss->vertex_users_mem);
ss->vertex_users= NULL;
ss->vertex_users_mem= NULL;
ss->vertex_users_size= 0;
}
}
void sculptsession_free(Scene *sce)
{
SculptSession *ss= sce->sculptdata.session;
if(ss) {
if(ss->projverts)
MEM_freeN(ss->projverts);
if(ss->mats)
MEM_freeN(ss->mats);
sculpt_vertexusers_free(ss);
if(ss->texcache)
MEM_freeN(ss->texcache);
MEM_freeN(ss);
sce->sculptdata.session= NULL;
}
}
/* Default curve approximates 0.5 * (cos(pi * x) + 1), with 0 <= x <= 1 */
void sculpt_reset_curve(SculptData *sd)
{
CurveMap *cm = NULL;
if(!sd->cumap)
sd->cumap = curvemapping_add(1, 0, 0, 1, 1);
cm = sd->cumap->cm;
if(cm->curve)
MEM_freeN(cm->curve);
cm->curve= MEM_callocN(6*sizeof(CurveMapPoint), "curve points");
cm->flag &= ~CUMA_EXTEND_EXTRAPOLATE;
cm->totpoint= 6;
cm->curve[0].x= 0;
cm->curve[0].y= 1;
cm->curve[1].x= 0.1;
cm->curve[1].y= 0.97553;
cm->curve[2].x= 0.3;
cm->curve[2].y= 0.79389;
cm->curve[3].x= 0.9;
cm->curve[3].y= 0.02447;
cm->curve[4].x= 0.7;
cm->curve[4].y= 0.20611;
cm->curve[5].x= 1;
cm->curve[5].y= 0;
}

View File

@@ -32,8 +32,6 @@
#include "DNA_listBase.h"
#include "DNA_vec_types.h"
/* For bglMats */
#include "BIF_glutil.h"
#include "transform.h"
struct uiBlock;
@@ -55,6 +53,7 @@ typedef enum PropsetMode {
PropsetStrength,
PropsetTexRot
} PropsetMode;
typedef struct PropsetData {
PropsetMode mode;
unsigned int tex;
@@ -68,40 +67,10 @@ typedef struct PropsetData {
NumInput num;
} PropsetData;
typedef struct SculptSession {
bglMats mats;
/* An array of lists; array is sized as
large as the number of verts in the mesh,
the list for each vert contains the index
for all the faces that use that vertex */
struct ListBase *vertex_users;
struct IndexNode *vertex_users_mem;
int vertex_users_size;
/* Used temporarily per-stroke */
float *vertexcosnos;
ListBase damaged_rects;
ListBase damaged_verts;
/* Used to cache the render of the active texture */
unsigned int texcache_w, texcache_h, *texcache;
PropsetData *propset;
/* For rotating around a pivot point */
vec3f pivot;
struct SculptStroke *stroke;
} SculptSession;
SculptSession *sculpt_session(void);
struct SculptSession *sculpt_session(void);
struct SculptData *sculpt_data(void);
/* Memory */
void sculpt_reset_curve(struct SculptData *sd);
void sculptmode_init(struct Scene *);
void sculptmode_free_all(struct Scene *);
void sculptmode_correct_state(void);
/* Interface */
@@ -135,10 +104,6 @@ void sculpt_stroke_draw();
/* Partial Mesh Visibility */
struct PartialVisibility *sculptmode_copy_pmv(struct PartialVisibility *);
void sculptmode_pmv_free(struct PartialVisibility *);
void sculptmode_revert_pmv(struct Mesh *me);
void sculptmode_pmv_off(struct Mesh *me);
void sculptmode_pmv(int mode);
#endif

View File

@@ -1356,7 +1356,7 @@ static void modifiers_applyModifier(void *obv, void *mdv)
return;
}
sculptmode_pmv_off(me);
mesh_pmv_off(ob, me);
dm = mesh_create_derived_for_modifier(ob, md);
if (!dm) {

View File

@@ -108,6 +108,7 @@
#include "BKE_particle.h"
#include "BKE_pointcache.h"
#include "BKE_scene.h"
#include "BKE_sculpt.h"
#include "BKE_texture.h"
#include "BKE_utildefines.h"

View File

@@ -1621,7 +1621,7 @@ void enter_editmode(int wc)
if(ob->type==OB_MESH) {
me= get_mesh(ob);
if( me==0 ) return;
if(me->pv) sculptmode_pmv_off(me);
if(me->pv) mesh_pmv_off(ob, me);
ok= 1;
G.obedit= ob;
make_editMesh();

View File

@@ -233,7 +233,7 @@ void multires_make(void *ob, void *me_v)
multires_check_state();
multires_create(me);
multires_create(ob, me);
allqueue(REDRAWBUTSEDIT, 0);
BIF_undo_push("Make multires");

View File

@@ -31,11 +31,16 @@
*/
#include "MEM_guardedalloc.h"
#include "DNA_listBase.h"
#include "DNA_scene_types.h"
#include "BKE_sculpt.h"
#include "BLI_blenlib.h"
#include "BIF_gl.h"
#include "BDR_sculptmode.h"
#include <math.h>
/* Temporary storage of input stroke control points */

View File

@@ -65,6 +65,7 @@
#include "BKE_main.h"
#include "BKE_mesh.h"
#include "BKE_modifier.h"
#include "BKE_sculpt.h"
#include "BKE_texture.h"
#include "BKE_utildefines.h"
#include "BKE_colortools.h"
@@ -168,7 +169,6 @@ typedef struct ProjVert {
char inside;
} ProjVert;
static ProjVert *projverts= NULL;
static Object *active_ob= NULL;
SculptData *sculpt_data(void)
@@ -192,135 +192,13 @@ SculptSession *sculpt_session(void)
* Allocate/initialize/free data
*/
// Default curve approximates 0.5 * (cos(pi * x) + 1), with 0 <= x <= 1;
void sculpt_reset_curve(SculptData *sd)
{
CurveMap *cm = NULL;
if(!sd->cumap)
sd->cumap = curvemapping_add(1, 0, 0, 1, 1);
cm = sd->cumap->cm;
if(cm->curve)
MEM_freeN(cm->curve);
cm->curve= MEM_callocN(6*sizeof(CurveMapPoint), "curve points");
cm->flag &= ~CUMA_EXTEND_EXTRAPOLATE;
cm->totpoint= 6;
cm->curve[0].x= 0;
cm->curve[0].y= 1;
cm->curve[1].x= 0.1;
cm->curve[1].y= 0.97553;
cm->curve[2].x= 0.3;
cm->curve[2].y= 0.79389;
cm->curve[3].x= 0.9;
cm->curve[3].y= 0.02447;
cm->curve[4].x= 0.7;
cm->curve[4].y= 0.20611;
cm->curve[5].x= 1;
cm->curve[5].y= 0;
}
/* Initialize 'permanent' sculpt data that is saved with file kept after
switching out of sculptmode. */
void sculptmode_init(Scene *sce)
{
SculptData *sd;
if(!sce) {
error("Unable to initialize sculptmode: bad scene");
return;
}
sd= &sce->sculptdata;
if(sd->cumap)
curvemapping_free(sd->cumap);
memset(sd, 0, sizeof(SculptData));
sd->drawbrush.size = sd->smoothbrush.size = sd->pinchbrush.size =
sd->inflatebrush.size = sd->grabbrush.size =
sd->layerbrush.size = sd->flattenbrush.size = 50;
sd->drawbrush.strength = sd->smoothbrush.strength =
sd->pinchbrush.strength = sd->inflatebrush.strength =
sd->grabbrush.strength = sd->layerbrush.strength =
sd->flattenbrush.strength = 25;
sd->drawbrush.dir = sd->pinchbrush.dir = sd->inflatebrush.dir = sd->layerbrush.dir= 1;
sd->drawbrush.airbrush = sd->smoothbrush.airbrush =
sd->pinchbrush.airbrush = sd->inflatebrush.airbrush =
sd->layerbrush.airbrush = sd->flattenbrush.airbrush = 0;
sd->drawbrush.view= 0;
sd->brush_type= DRAW_BRUSH;
sd->texact= -1;
sd->texfade= 1;
sd->averaging= 1;
sd->texsep= 0;
sd->texrept= SCULPTREPT_DRAG;
sd->flags= SCULPT_DRAW_BRUSH;
sd->tablet_size=3;
sd->tablet_strength=10;
sd->rake=0;
sculpt_reset_curve(sd);
}
void sculptmode_free_session(Scene *);
void sculpt_init_session(void)
{
if(sculpt_data()->session)
sculptmode_free_session(G.scene);
sculptsession_free(G.scene);
sculpt_data()->session= MEM_callocN(sizeof(SculptSession), "SculptSession");
}
void sculptmode_free_vertexusers(SculptSession *ss)
{
if(ss && ss->vertex_users){
MEM_freeN(ss->vertex_users);
MEM_freeN(ss->vertex_users_mem);
ss->vertex_users= NULL;
ss->vertex_users_mem= NULL;
ss->vertex_users_size= 0;
}
}
void sculptmode_propset_end(SculptSession *ss, int);
void sculptmode_free_session(Scene *sce)
{
SculptSession *ss= sce->sculptdata.session;
if(ss) {
sculptmode_free_vertexusers(ss);
if(ss->texcache)
MEM_freeN(ss->texcache);
sculptmode_propset_end(ss, 1);
MEM_freeN(ss);
sce->sculptdata.session= NULL;
}
}
void sculptmode_free_all(Scene *sce)
{
SculptData *sd= &sce->sculptdata;
int a;
sculptmode_free_session(sce);
if(projverts) {
MEM_freeN(projverts);
projverts = NULL;
}
for(a=0; a<MAX_MTEX; a++) {
MTex *mtex= sd->mtex[a];
if(mtex) {
if(mtex->tex) mtex->tex->id.us--;
MEM_freeN(mtex);
}
}
curvemapping_free(sd->cumap);
sd->cumap = NULL;
}
/* vertex_users is an array of Lists that store all the faces that use a
particular vertex. vertex_users is in the same order as mesh.mvert */
void calc_vertex_users()
@@ -330,7 +208,7 @@ void calc_vertex_users()
IndexNode *node= NULL;
Mesh *me= get_mesh(OBACT);
sculptmode_free_vertexusers(ss);
sculpt_vertexusers_free(ss);
/* For efficiency, use vertex_users_mem as a memory pool (may be larger
than necessary if mesh has triangles, but only one alloc is needed.) */
@@ -384,7 +262,9 @@ void init_sculptmatrices()
glPushMatrix();
glMultMatrixf(OBACT->obmat);
bgl_get_mats(&ss->mats);
if(!ss->mats)
ss->mats = MEM_callocN(sizeof(bglMats), "sculpt bglmats");
bgl_get_mats(ss->mats);
glPopMatrix();
@@ -419,8 +299,8 @@ vec3f unproject(const short x, const short y, const float z)
double ux, uy, uz;
vec3f p;
gluUnProject(x,y,z, ss->mats.modelview, ss->mats.projection,
(GLint *)ss->mats.viewport, &ux, &uy, &uz );
gluUnProject(x,y,z, ss->mats->modelview, ss->mats->projection,
(GLint *)ss->mats->viewport, &ux, &uy, &uz );
p.x= ux;
p.y= uy;
p.z= uz;
@@ -433,8 +313,8 @@ void project(const float v[3], short p[2])
SculptSession *ss= sculpt_session();
double ux, uy, uz;
gluProject(v[0],v[1],v[2], ss->mats.modelview, ss->mats.projection,
(GLint *)ss->mats.viewport, &ux, &uy, &uz);
gluProject(v[0],v[1],v[2], ss->mats->modelview, ss->mats->projection,
(GLint *)ss->mats->viewport, &ux, &uy, &uz);
p[0]= ux;
p[1]= uy;
}
@@ -867,7 +747,7 @@ float tex_strength(EditData *e, float *point, const float len,const unsigned vin
across the symmetry axis in order to project it. This insures
that the brush texture will be oriented correctly. */
if(!e->symm)
pv= projverts[vindex];
pv= ss->projverts[vindex];
else {
float co[3];
VecCopyf(co, point);
@@ -934,6 +814,7 @@ void sculpt_add_damaged_rect(EditData *e)
const float radius= brush_size();
RectNode *rn= MEM_mallocN(sizeof(RectNode),"RectNode");
Mesh *me= get_mesh(OBACT);
SculptSession *ss = sculpt_session();
unsigned i;
/* Find center */
@@ -947,10 +828,10 @@ void sculpt_add_damaged_rect(EditData *e)
/* Update insides */
for(i=0; i<me->totvert; ++i) {
if(!projverts[i].inside) {
if(projverts[i].co[0] > rn->r.xmin && projverts[i].co[1] > rn->r.ymin &&
projverts[i].co[0] < rn->r.xmax && projverts[i].co[1] < rn->r.ymax) {
projverts[i].inside= 1;
if(!ss->projverts[i].inside) {
if(ss->projverts[i].co[0] > rn->r.xmin && ss->projverts[i].co[1] > rn->r.ymin &&
ss->projverts[i].co[0] < rn->r.xmax && ss->projverts[i].co[1] < rn->r.ymax) {
ss->projverts[i].inside= 1;
}
}
}
@@ -1005,7 +886,7 @@ void do_brush_action(EditData e)
if(!e.grabdata || (e.grabdata && e.grabdata->firsttime)) {
for(i=0; i<me->totvert; ++i) {
/* Projverts.inside provides a rough bounding box */
if(projverts[i].inside) {
if(ss->projverts[i].inside) {
vert= ss->vertexcosnos ? &ss->vertexcosnos[i*6] : me->mvert[i].co;
av_dist= VecLenf(&e.center.x,vert);
if(av_dist < e.size) {
@@ -1172,13 +1053,13 @@ void calc_damaged_verts(ListBase *damaged_verts, GrabData *grabdata)
}
}
void projverts_clear_inside()
void projverts_clear_inside(SculptSession *ss)
{
Mesh *me = get_mesh(OBACT);
if(me) {
int i;
for(i = 0; i < me->totvert; ++i)
projverts[i].inside = 0;
ss->projverts[i].inside = 0;
}
}
@@ -1196,7 +1077,7 @@ BrushData *sculptmode_brush(void)
sd->brush_type==FLATTEN_BRUSH ? &sd->flattenbrush : NULL);
if(!bd) {
sculptmode_init(G.scene);
sculptdata_init(G.scene);
bd = &sd->drawbrush;
}
@@ -1604,19 +1485,20 @@ void sculptmode_selectbrush_menu(void)
void sculptmode_update_all_projverts(float *vertcosnos)
{
SculptSession *ss = sculpt_session();
Mesh *me= get_mesh(OBACT);
unsigned i;
if(!projverts)
projverts = MEM_mallocN(sizeof(ProjVert)*me->totvert,"ProjVerts");
if(!ss->projverts)
ss->projverts = MEM_mallocN(sizeof(ProjVert)*me->totvert,"ProjVerts");
for(i=0; i<me->totvert; ++i) {
project(vertcosnos ? &vertcosnos[i * 6] : me->mvert[i].co, projverts[i].co);
projverts[i].inside= 0;
project(vertcosnos ? &vertcosnos[i * 6] : me->mvert[i].co, ss->projverts[i].co);
ss->projverts[i].inside= 0;
}
}
void sculptmode_draw_wires(int only_damaged, Mesh *me)
void sculptmode_draw_wires(SculptSession *ss, int only_damaged, Mesh *me)
{
int i;
@@ -1627,7 +1509,7 @@ void sculptmode_draw_wires(int only_damaged, Mesh *me)
for(i=0; i<me->totedge; i++) {
MEdge *med= &me->medge[i];
if((!only_damaged || (projverts[med->v1].inside || projverts[med->v2].inside)) &&
if((!only_damaged || (ss->projverts[med->v1].inside || ss->projverts[med->v2].inside)) &&
(med->flag & ME_EDGEDRAW)) {
glDrawElements(GL_LINES, 2, GL_UNSIGNED_INT, &med->v1);
}
@@ -1641,6 +1523,7 @@ void sculptmode_draw_mesh(int only_damaged)
{
Mesh *me= get_mesh(OBACT);
int i, j, dt, drawCurrentMat = 1, matnr= -1;
SculptSession *ss = sculpt_session();
persp(PERSP_VIEW);
mymultmatrix(OBACT->obmat);
@@ -1670,7 +1553,7 @@ void sculptmode_draw_mesh(int only_damaged)
inside the area(s) modified by the brush */
if(only_damaged) {
for(j=0; j<(f->v4?4:3); ++j) {
if(projverts[*((&f->v1)+j)].inside) {
if(ss->projverts[*((&f->v1)+j)].inside) {
inside= 1;
break;
}
@@ -1688,7 +1571,7 @@ void sculptmode_draw_mesh(int only_damaged)
glColorMask(1,1,1,1);
if(dt==OB_WIRE || (OBACT->dtx & OB_DRAWWIRE))
sculptmode_draw_wires(only_damaged, me);
sculptmode_draw_wires(ss, only_damaged, me);
glDisable(GL_DEPTH_TEST);
}
@@ -1754,11 +1637,11 @@ void sculpt(void)
/* Check that vertex users are up-to-date */
if(ob != active_ob || !ss->vertex_users || ss->vertex_users_size != get_mesh(ob)->totvert) {
sculptmode_free_vertexusers(ss);
sculpt_vertexusers_free(ss);
calc_vertex_users();
if(projverts)
MEM_freeN(projverts);
projverts = NULL;
if(ss->projverts)
MEM_freeN(ss->projverts);
ss->projverts = NULL;
active_ob= ob;
}
@@ -1866,7 +1749,7 @@ void sculpt(void)
sculptmode_draw_mesh(1);
glAccum(GL_LOAD, 1);
projverts_clear_inside();
projverts_clear_inside(ss);
persp(PERSP_WIN);
glDisable(GL_DEPTH_TEST);
@@ -1951,9 +1834,9 @@ void set_sculptmode(void)
G.f &= ~G_SCULPTMODE;
sculptmode_free_session(G.scene);
sculptsession_free(G.scene);
if(me && me->pv)
sculptmode_pmv_off(me);
mesh_pmv_off(OBACT, me);
}
else {
G.f |= G_SCULPTMODE;
@@ -1974,77 +1857,9 @@ void set_sculptmode(void)
}
/* Partial Mesh Visibility */
PartialVisibility *sculptmode_copy_pmv(PartialVisibility *pmv)
{
PartialVisibility *n= MEM_dupallocN(pmv);
n->vert_map= MEM_dupallocN(pmv->vert_map);
n->edge_map= MEM_dupallocN(pmv->edge_map);
n->old_edges= MEM_dupallocN(pmv->old_edges);
n->old_faces= MEM_dupallocN(pmv->old_faces);
return n;
}
void sculptmode_pmv_free(PartialVisibility *pv)
{
MEM_freeN(pv->vert_map);
MEM_freeN(pv->edge_map);
MEM_freeN(pv->old_faces);
MEM_freeN(pv->old_edges);
MEM_freeN(pv);
}
void sculptmode_revert_pmv(Mesh *me)
{
if(me->pv) {
unsigned i;
MVert *nve, *old_verts;
active_ob= NULL;
/* Reorder vertices */
nve= me->mvert;
old_verts = MEM_mallocN(sizeof(MVert)*me->pv->totvert,"PMV revert verts");
for(i=0; i<me->pv->totvert; ++i)
old_verts[i]= nve[me->pv->vert_map[i]];
/* Restore verts, edges and faces */
CustomData_free_layer_active(&me->vdata, CD_MVERT, me->totvert);
CustomData_free_layer_active(&me->edata, CD_MEDGE, me->totedge);
CustomData_free_layer_active(&me->fdata, CD_MFACE, me->totface);
CustomData_add_layer(&me->vdata, CD_MVERT, CD_ASSIGN, old_verts, me->pv->totvert);
CustomData_add_layer(&me->edata, CD_MEDGE, CD_ASSIGN, me->pv->old_edges, me->pv->totedge);
CustomData_add_layer(&me->fdata, CD_MFACE, CD_ASSIGN, me->pv->old_faces, me->pv->totface);
mesh_update_customdata_pointers(me);
me->totvert= me->pv->totvert;
me->totedge= me->pv->totedge;
me->totface= me->pv->totface;
me->pv->old_edges= NULL;
me->pv->old_faces= NULL;
/* Free maps */
MEM_freeN(me->pv->edge_map);
me->pv->edge_map= NULL;
MEM_freeN(me->pv->vert_map);
me->pv->vert_map= NULL;
DAG_object_flush_update(G.scene, OBACT, OB_RECALC_DATA);
}
}
void sculptmode_pmv_off(Mesh *me)
{
if(me->pv) {
sculptmode_revert_pmv(me);
MEM_freeN(me->pv);
me->pv= NULL;
}
}
/* mode: 0=hide outside selection, 1=hide inside selection */
void sculptmode_do_pmv(Object *ob, rcti *hb_2d, int mode)
static void sculptmode_do_pmv(Object *ob, rcti *hb_2d, int mode)
{
Mesh *me= get_mesh(ob);
vec3f hidebox[6];
@@ -2085,7 +1900,7 @@ void sculptmode_do_pmv(Object *ob, rcti *hb_2d, int mode)
for(i=0; i<me->pv->totvert; ++i) {
old_map[i]= me->pv->vert_map[i]<me->totvert?0:1;
}
sculptmode_revert_pmv(me);
mesh_pmv_revert(ob, me);
}
/* Kill sculpt data */
@@ -2202,7 +2017,7 @@ void sculptmode_do_pmv(Object *ob, rcti *hb_2d, int mode)
DAG_object_flush_update(G.scene, OBACT, OB_RECALC_DATA);
}
rcti sculptmode_pmv_box()
static rcti sculptmode_pmv_box()
{
short down[2], mouse[2];
rcti ret;
@@ -2257,7 +2072,7 @@ void sculptmode_pmv(int mode)
sculptmode_do_pmv(ob,&hb_2d,mode);
}
else sculptmode_pmv_off(get_mesh(ob));
else mesh_pmv_off(ob, get_mesh(ob));
scrarea_do_windraw(curarea);

View File

@@ -89,6 +89,7 @@
#include "BKE_multires.h"
#include "BKE_node.h"
#include "BKE_scene.h"
#include "BKE_sculpt.h"
#include "BKE_texture.h"
#include "BKE_utildefines.h"
#include "BKE_image.h" /* for IMA_TYPE_COMPOSITE and IMA_TYPE_R_RESULT */
@@ -1509,7 +1510,7 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
case HKEY:
if(G.qual==LR_ALTKEY) {
waitcursor(1);
sculptmode_pmv_off(get_mesh(ob));
mesh_pmv_off(ob, get_mesh(ob));
BIF_undo_push("Partial mesh hide");
allqueue(REDRAWVIEW3D,0);
waitcursor(0);

View File

@@ -66,6 +66,7 @@
#include "BKE_global.h"
#include "BKE_main.h"
#include "BKE_object.h"
#include "BKE_sculpt.h"
#include "BKE_utildefines.h"
#include "BIF_editparticle.h"