Ported over the bad-level cleanup from Chris for Sculpt.

This commit is contained in:
Ton Roosendaal 2007-12-29 17:07:55 +00:00
parent c27b65a255
commit da7208eab5
9 changed files with 2091 additions and 76 deletions

@ -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 */

@ -0,0 +1,68 @@
/*
* $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 *****
*/
struct CustomData;
struct EditMesh;
struct Multires;
struct MultiresLevel;
struct Mesh;
struct Object;
/* Level access */
struct MultiresLevel *current_level(struct Multires *mr);
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);
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 Object *ob, struct Mesh *me);
/* CustomData */
void multires_delete_layer(struct Mesh *me, struct CustomData *cd, const int type, int n);
void multires_add_layer(struct Mesh *me, struct CustomData *cd, const int type, const int n);
void multires_del_lower_customdata(struct Multires *mr, struct MultiresLevel *cr_lvl);
void multires_to_mcol(struct MultiresColFace *f, MCol mcol[4]);
/* After adding or removing vcolor layers, run this */
void multires_load_cols(struct Mesh *me);
/* Private (used in multires-firstlevel.c) */
void multires_level_to_mesh(struct Object *ob, struct Mesh *me, const int render);
void multires_update_levels(struct Mesh *me, const int render);
void multires_update_first_level(struct Mesh *me, struct EditMesh *em);
void multires_update_customdata(struct MultiresLevel *lvl1, struct CustomData *src,
struct CustomData *dst, const int type);
void multires_customdata_to_mesh(struct Mesh *me, struct EditMesh *em,
struct MultiresLevel *lvl, struct CustomData *src,
struct CustomData *dst, const int type);

@ -0,0 +1,93 @@
/*
* $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 *****
*/
#ifndef BKE_SCULPT_H
#define BKE_SCULPT_H
struct NumInput;
struct Scene;
struct SculptData;
struct SculptSession;
typedef enum PropsetMode {
PropsetNone = 0,
PropsetSize,
PropsetStrength,
PropsetTexRot
} PropsetMode;
typedef struct PropsetData {
PropsetMode mode;
unsigned int tex;
short origloc[2];
float *texdata;
short origsize;
char origstrength;
float origtexrot;
struct NumInput *num;
} PropsetData;
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);
#endif

@ -55,14 +55,13 @@
#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"
#include "BKE_DerivedMesh.h"
#include "BKE_global.h"
#include "BKE_mesh.h"
#include "BKE_multires.h"
#include "BKE_subsurf.h"
#include "BKE_displist.h"
#include "BKE_library.h"
@ -83,8 +82,6 @@
#include "BLI_editVert.h"
#include "BLI_arithb.h"
#include "multires.h"
int update_realtime_texture(MTFace *tface, double time)
{
Image *ima;
@ -1231,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;
}
}

@ -0,0 +1,409 @@
/*
* $Id: multires-firstlevel.c 13001 2007-12-26 09:39:15Z nicholasbishop $
*
* ***** 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) 2006 by Nicholas Bishop
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL LICENSE BLOCK *****
*
* Deals with the first-level data in multires (edge flags, weights, and UVs)
*
* multires.h
*
*/
#include "DNA_customdata_types.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
#include "BIF_editmesh.h"
#include "BKE_customdata.h"
#include "BKE_global.h"
#include "BKE_mesh.h"
#include "BKE_multires.h"
#include "BLI_editVert.h"
#include "MEM_guardedalloc.h"
#include "blendef.h"
#include <string.h>
MDeformVert *subdivide_dverts(MDeformVert *src, MultiresLevel *lvl);
MTFace *subdivide_mtfaces(MTFace *src, MultiresLevel *lvl);
void multires_update_edge_flags(Mesh *me, EditMesh *em);
void eed_to_medge_flag(EditEdge *eed, short *flag, char *crease);
/*********** Generic ***********/
CustomDataMask cdmask(const int type)
{
if(type == CD_MDEFORMVERT)
return CD_MASK_MDEFORMVERT;
else if(type == CD_MTFACE)
return CD_MASK_MTFACE;
return -1;
}
char type_ok(const int type)
{
return (type == CD_MDEFORMVERT) || (type == CD_MTFACE);
}
/* Copy vdata or fdata from Mesh or EditMesh to Multires. */
void multires_update_customdata(MultiresLevel *lvl1, CustomData *src, CustomData *dst, const int type)
{
if(src && dst && type_ok(type)) {
const int tot= (type == CD_MDEFORMVERT ? lvl1->totvert : lvl1->totface);
int i;
CustomData_free(dst, tot);
if(CustomData_has_layer(src, type)) {
if(G.obedit) {
EditVert *eve= G.editMesh->verts.first;
EditFace *efa= G.editMesh->faces.first;
CustomData_copy(src, dst, cdmask(type), CD_CALLOC, tot);
for(i=0; i<tot; ++i) {
if(type == CD_MDEFORMVERT) {
CustomData_from_em_block(&G.editMesh->vdata, dst, eve->data, i);
eve= eve->next;
}
else if(type == CD_MTFACE) {
CustomData_from_em_block(&G.editMesh->fdata, dst, efa->data, i);
efa= efa->next;
}
}
}
else
CustomData_copy(src, dst, cdmask(type), CD_DUPLICATE, tot);
}
}
}
/* Uses subdivide_dverts or subdivide_mtfaces to subdivide src to match lvl_end. Does not free src. */
void *subdivide_customdata_to_level(void *src, MultiresLevel *lvl_start,
MultiresLevel *lvl_end, const int type)
{
if(src && lvl_start && lvl_end && type_ok(type)) {
MultiresLevel *lvl;
void *cr_data= NULL, *pr_data= NULL;
pr_data= src;
for(lvl= lvl_start; lvl && lvl != lvl_end; lvl= lvl->next) {
if(type == CD_MDEFORMVERT)
cr_data= subdivide_dverts(pr_data, lvl);
else if(type == CD_MTFACE)
cr_data= subdivide_mtfaces(pr_data, lvl);
/* Free previous subdivision level's data */
if(lvl != lvl_start) {
if(type == CD_MDEFORMVERT)
free_dverts(pr_data, lvl->totvert);
else if(type == CD_MTFACE)
MEM_freeN(pr_data);
}
pr_data= cr_data;
cr_data= NULL;
}
return pr_data;
}
return NULL;
}
/* Directly copy src into dst (handles both Mesh and EditMesh) */
void customdata_to_mesh(Mesh *me, EditMesh *em, CustomData *src, CustomData *dst, const int tot, const int type)
{
if(me && me->mr && src && dst && type_ok(type)) {
if(em) {
int i;
EditVert *eve= em->verts.first;
EditFace *efa= em->faces.first;
CustomData_copy(src, dst, cdmask(type), CD_CALLOC, 0);
for(i=0; i<tot; ++i) {
if(type == CD_MDEFORMVERT) {
CustomData_to_em_block(src, dst, i, &eve->data);
eve= eve->next;
}
else if(type == CD_MTFACE) {
CustomData_to_em_block(src, dst, i, &efa->data);
efa= efa->next;
}
}
} else {
CustomData_merge(src, dst, cdmask(type), CD_DUPLICATE, tot);
}
}
}
/* Subdivide vdata or fdata from Multires into either Mesh or EditMesh. */
void multires_customdata_to_mesh(Mesh *me, EditMesh *em, MultiresLevel *lvl, CustomData *src,
CustomData *dst, const int type)
{
if(me && me->mr && lvl && src && dst && type_ok(type) &&
CustomData_has_layer(src, type)) {
const int tot= (type == CD_MDEFORMVERT ? lvl->totvert : lvl->totface);
if(lvl == me->mr->levels.first) {
customdata_to_mesh(me, em, src, dst, tot, type);
}
else {
CustomData cdf;
const int count = CustomData_number_of_layers(src, type);
int i;
/* Construct a new CustomData containing the subdivided data */
CustomData_copy(src, &cdf, cdmask(type), CD_ASSIGN, tot);
for(i=0; i<count; ++i) {
void *layer= CustomData_get_layer_n(&cdf, type, i);
CustomData_set_layer_n(&cdf, type, i,
subdivide_customdata_to_level(layer, me->mr->levels.first, lvl, type));
}
customdata_to_mesh(me, em, &cdf, dst, tot, type);
CustomData_free(&cdf, tot);
}
}
}
/* Subdivide the first-level customdata up to cr_lvl, then delete the original data */
void multires_del_lower_customdata(Multires *mr, MultiresLevel *cr_lvl)
{
MultiresLevel *lvl1= mr->levels.first;
MDeformVert *dverts= NULL;
CustomData cdf;
int i;
/* dverts */
dverts= subdivide_customdata_to_level(CustomData_get(&mr->vdata, 0, CD_MDEFORMVERT),
lvl1, cr_lvl, CD_MDEFORMVERT);
if(dverts) {
CustomData_free_layers(&mr->vdata, CD_MDEFORMVERT, lvl1->totvert);
CustomData_add_layer(&mr->vdata, CD_MDEFORMVERT, CD_ASSIGN, dverts, cr_lvl->totvert);
}
/* mtfaces */
CustomData_copy(&mr->fdata, &cdf, CD_MASK_MTFACE, CD_ASSIGN, cr_lvl->totface);
for(i=0; i<CustomData_number_of_layers(&mr->fdata, CD_MTFACE); ++i) {
MTFace *mtfaces=
subdivide_customdata_to_level(CustomData_get_layer_n(&mr->fdata, CD_MTFACE, i),
lvl1, cr_lvl, CD_MTFACE);
if(mtfaces)
CustomData_set_layer_n(&cdf, CD_MTFACE, i, mtfaces);
}
CustomData_free(&mr->fdata, lvl1->totface);
mr->fdata= cdf;
}
/* Update all special first-level data, if the first-level is active */
void multires_update_first_level(Mesh *me, EditMesh *em)
{
if(me && me->mr && me->mr->current == 1) {
multires_update_customdata(me->mr->levels.first, em ? &em->vdata : &me->vdata,
&me->mr->vdata, CD_MDEFORMVERT);
multires_update_customdata(me->mr->levels.first, em ? &em->fdata : &me->fdata,
&me->mr->fdata, CD_MTFACE);
multires_update_edge_flags(me, em);
}
}
/*********** Multires.edge_flags ***********/
void multires_update_edge_flags(Mesh *me, EditMesh *em)
{
MultiresLevel *lvl= me->mr->levels.first;
EditEdge *eed= NULL;
int i;
if(em) eed= em->edges.first;
for(i=0; i<lvl->totedge; ++i) {
if(em) {
me->mr->edge_flags[i]= 0;
eed_to_medge_flag(eed, &me->mr->edge_flags[i], &me->mr->edge_creases[i]);
eed= eed->next;
}
else {
me->mr->edge_flags[i]= me->medge[i].flag;
me->mr->edge_creases[i]= me->medge[i].crease;
}
}
}
/*********** Multires.vdata ***********/
/* MDeformVert */
/* Add each weight from in to out. Scale each weight by w. */
void multires_add_dvert(MDeformVert *out, const MDeformVert *in, const float w)
{
if(out && in) {
int i, j;
char found;
for(i=0; i<in->totweight; ++i) {
found= 0;
for(j=0; j<out->totweight; ++j) {
if(out->dw[j].def_nr==in->dw[i].def_nr) {
out->dw[j].weight += in->dw[i].weight * w;
found= 1;
}
}
if(!found) {
MDeformWeight *newdw= MEM_callocN(sizeof(MDeformWeight)*(out->totweight+1),
"multires dvert");
if(out->dw) {
memcpy(newdw, out->dw, sizeof(MDeformWeight)*out->totweight);
MEM_freeN(out->dw);
}
out->dw= newdw;
out->dw[out->totweight].weight= in->dw[i].weight * w;
out->dw[out->totweight].def_nr= in->dw[i].def_nr;
++out->totweight;
}
}
}
}
/* Takes an input array of dverts and subdivides them (linear) using the topology of lvl */
MDeformVert *subdivide_dverts(MDeformVert *src, MultiresLevel *lvl)
{
if(lvl && lvl->next) {
MDeformVert *out = MEM_callocN(sizeof(MDeformVert)*lvl->next->totvert, "dvert prop array");
int i, j;
/* Copy lower level */
for(i=0; i<lvl->totvert; ++i)
multires_add_dvert(&out[i], &src[i], 1);
/* Edge verts */
for(i=0; i<lvl->totedge; ++i) {
for(j=0; j<2; ++j)
multires_add_dvert(&out[lvl->totvert+i], &src[lvl->edges[i].v[j]],0.5);
}
/* Face verts */
for(i=0; i<lvl->totface; ++i) {
for(j=0; j<(lvl->faces[i].v[3]?4:3); ++j)
multires_add_dvert(&out[lvl->totvert + lvl->totedge + i],
&src[lvl->faces[i].v[j]],
lvl->faces[i].v[3]?0.25:(1.0f/3.0f));
}
return out;
}
return NULL;
}
/*********** Multires.fdata ***********/
/* MTFace */
void multires_uv_avg2(float out[2], const float a[2], const float b[2])
{
int i;
for(i=0; i<2; ++i)
out[i] = (a[i] + b[i]) / 2.0f;
}
/* Takes an input array of mtfaces and subdivides them (linear) using the topology of lvl */
MTFace *subdivide_mtfaces(MTFace *src, MultiresLevel *lvl)
{
if(lvl && lvl->next) {
MTFace *out= MEM_callocN(sizeof(MultiresColFace)*lvl->next->totface,"Multirescolfaces");
int i, j, curf;
for(i=0, curf=0; i<lvl->totface; ++i) {
const char sides= lvl->faces[i].v[3]?4:3;
float cntr[2]= {0, 0};
/* Find average uv coord of the current face */
for(j=0; j<sides; ++j) {
cntr[0]+= src[i].uv[j][0];
cntr[1]+= src[i].uv[j][1];
}
cntr[0]/= sides;
cntr[1]/= sides;
for(j=0; j<sides; ++j, ++curf) {
out[curf]= src[i];
multires_uv_avg2(out[curf].uv[0], src[i].uv[j], src[i].uv[j==0?sides-1:j-1]);
out[curf].uv[1][0]= src[i].uv[j][0];
out[curf].uv[1][1]= src[i].uv[j][1];
multires_uv_avg2(out[curf].uv[2], src[i].uv[j], src[i].uv[j==sides-1?0:j+1]);
out[curf].uv[3][0]= cntr[0];
out[curf].uv[3][1]= cntr[1];
}
}
return out;
}
return NULL;
}
void multires_delete_layer(Mesh *me, CustomData *cd, const int type, int n)
{
if(me && me->mr && cd) {
MultiresLevel *lvl1= me->mr->levels.first;
multires_update_levels(me, 0);
CustomData_set_layer_active(cd, type, n);
CustomData_free_layer_active(cd, type, lvl1->totface);
multires_level_to_mesh(OBACT, me, 0);
}
}
void multires_add_layer(Mesh *me, CustomData *cd, const int type, const int n)
{
if(me && me->mr && cd) {
multires_update_levels(me, 0);
if(CustomData_has_layer(cd, type))
CustomData_add_layer(cd, type, CD_DUPLICATE, CustomData_get_layer(cd, type),
current_level(me->mr)->totface);
else
CustomData_add_layer(cd, type, CD_DEFAULT, NULL, current_level(me->mr)->totface);
CustomData_set_layer_active(cd, type, n);
multires_level_to_mesh(OBACT, me, 0);
}
}

File diff suppressed because it is too large Load Diff

@ -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,127 @@ 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);
if(ss->propset) {
if(ss->propset->texdata)
MEM_freeN(ss->propset->texdata);
if(ss->propset->num)
MEM_freeN(ss->propset->num);
MEM_freeN(ss->propset);
}
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;
}

@ -1,5 +1,5 @@
/*
* $Id: BDR_sculptmode.h 11036 2007-06-24 22:28:28Z nicholasbishop $
* $Id: BDR_sculptmode.h 13014 2007-12-26 23:08:00Z nicholasbishop $
*
* ***** BEGIN GPL LICENSE BLOCK *****
*
@ -32,8 +32,7 @@
#include "DNA_listBase.h"
#include "DNA_vec_types.h"
/* For bglMats */
#include "BIF_glutil.h"
#include "BKE_sculpt.h"
#include "transform.h"
struct uiBlock;
@ -49,62 +48,15 @@ struct ScrArea;
struct SculptData;
struct SculptStroke;
typedef enum PropsetMode {
PropsetNone = 0,
PropsetSize,
PropsetStrength,
PropsetTexRot
} PropsetMode;
typedef struct PropsetData {
PropsetMode mode;
unsigned int tex;
short origloc[2];
float *texdata;
short origsize;
char origstrength;
float origtexrot;
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 sculptmode_init(struct Scene *);
void sculptmode_free_all(struct Scene *);
void sculptmode_correct_state(void);
/* Interface */
void sculptmode_draw_interface_tools(struct uiBlock *block,unsigned short cx, unsigned short cy);
void sculptmode_draw_interface_brush(struct uiBlock *block,unsigned short cx, unsigned short cy);
void sculptmode_draw_interface_textures(struct uiBlock *block,unsigned short cx, unsigned short cy);
void sculptmode_rem_tex(void*,void*);
void sculptmode_propset_init(PropsetMode mode);
@ -133,10 +85,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

@ -41,15 +41,11 @@ void saveover() {}
void texstr() {}
void pupmenu() {}
/* global vars */
void *curarea;
void *editNurb;
void *editelems;
/* blenkernel errors */
void PE_recalc_world_cos() {}
void PE_free_particle_edit() {}
void PE_get_colors() {}
/* python, will come back */
void BPY_post_start_python() {}
void BPY_run_python_script() {}
@ -87,20 +83,21 @@ void deselectall() {}
/* sculpt */
void sculptmode_free_all() {}
void sculptmode_init() {}
void multires_level_n() {}
void multires_set_level() {}
void multires_update_levels() {}
void multires_copy() {}
void multires_free() {}
void sculpt_reset_curve() {}
/* mesh */
void free_realtime_image() {}
void NewBooleanDerivedMesh() {}
void harmonic_coordinates_bind() {}
/* particle */
void PE_recalc_world_cos() {}
void PE_free_particle_edit() {}
void PE_get_colors() {}
/* fluid */
void fluidsimSettingsCopy() {}
void fluidsimSettingsFree() {}
void NewBooleanDerivedMesh() {}
void harmonic_coordinates_bind() {}
void BIF_filelist_freelib() {}