- moved mesh_getVertexCos to mesh.c and prototyped

- make mesh_modifier build vertex locations on demand
This commit is contained in:
2005-07-22 17:03:50 +00:00
parent f6024cfdac
commit cb3d0afd87
4 changed files with 28 additions and 44 deletions

View File

@@ -93,6 +93,10 @@ void mesh_calculate_vertex_normals (struct Mesh *me);
*/
void mesh_calc_normals(struct MVert *mverts, int numVerts, struct MFace *mfaces, int numFaces, float **faceNors_r);
/* Return a newly MEM_malloc'd array of all the mesh vertex locations
* (_numVerts_r_ may be NULL) */
float (*mesh_getVertexCos(struct Mesh *me, int *numVerts_r))[3];
#ifdef __cplusplus
}
#endif

View File

@@ -1123,18 +1123,6 @@ DerivedMesh *derivedmesh_from_displistmesh(DispListMesh *dlm)
typedef float vec3f[3];
static vec3f *mesh_getVertexCos(Mesh *me, int *numVerts_r)
{
int i, numVerts = *numVerts_r = me->totvert;
float (*cos)[3] = MEM_mallocN(sizeof(*cos)*numVerts, "vertexcos1");
for (i=0; i<numVerts; i++) {
VECCOPY(cos[i], me->mvert[i].co);
}
return cos;
}
static void mesh_calc_modifiers(Object *ob, float (*inputVertexCos)[3], DerivedMesh **deform_r, DerivedMesh **final_r, int useRenderParams, int useDeform)
{
Mesh *me = ob->data;

View File

@@ -59,6 +59,7 @@
#include "BKE_object.h"
#include "BKE_softbody.h"
#include "BKE_utildefines.h"
#include "BKE_mesh.h"
#include "BLI_blenlib.h"
#include "BLI_arithb.h"
@@ -231,31 +232,14 @@ void mesh_modifier(Object *ob, float (**vertexCos_r)[3])
{
MVert *origMVert=NULL;
Mesh *me= ob->data;
int a, done=0;
float (*vertexCos)[3];
*vertexCos_r = NULL;
float (*vertexCos)[3] = NULL;
int a;
do_mesh_key(me);
/* conditions if it's needed */
if(ob->hooks.first);
else if(ob->effect.first); // weak... particles too
else if(ob->parent && ob->parent->type==OB_LATTICE);
else if(ob->parent && ob->partype==PARSKEL);
else if(ob->softflag & OB_SB_ENABLE);
else return;
if(me->totvert==0) return;
vertexCos = MEM_mallocN(sizeof(*vertexCos)*me->totvert, "mm_vertexcos");
for (a=0; a<me->totvert; a++) {
VECCOPY(vertexCos[a], me->mvert[a].co);
}
/* hooks */
if(ob->hooks.first) {
done= 1;
if (!vertexCos) vertexCos = mesh_getVertexCos(me, NULL);
/* NULL signals initialize */
hook_object_deform(ob, 0, NULL);
@@ -272,50 +256,45 @@ void mesh_modifier(Object *ob, float (**vertexCos_r)[3])
for (wav= ob->effect.first; wav; wav= wav->next) {
if(wav->type==EFF_WAVE) {
if (!vertexCos) vertexCos = mesh_getVertexCos(me, NULL);
init_wave_deform(wav);
for(a=0; a<me->totvert; a++) {
calc_wave_deform(wav, ctime, vertexCos[a]);
}
done = 1;
}
}
}
if((ob->softflag & OB_SB_ENABLE) && !(ob->softflag & OB_SB_POSTDEF)) {
done= 1;
if (!vertexCos) vertexCos = mesh_getVertexCos(me, NULL);
sbObjectStep(ob, (float)G.scene->r.cfra, vertexCos);
}
if (ob->parent && me->totvert) {
if(ob->parent->type==OB_CURVE && ob->partype==PARSKEL) {
if (!vertexCos) vertexCos = mesh_getVertexCos(me, NULL);
curve_deform_verts(ob->parent, ob, vertexCos, me->totvert);
done= 1;
}
else if(ob->parent->type==OB_LATTICE) {
if (!vertexCos) vertexCos = mesh_getVertexCos(me, NULL);
lattice_deform_verts(ob->parent, ob, vertexCos, me->totvert);
done= 1;
}
else if(ob->parent->type==OB_ARMATURE && ob->partype==PARSKEL) {
// misleading making displists... very bad
if (ob->parent!=G.obedit) {
if (!vertexCos) vertexCos = mesh_getVertexCos(me, NULL);
armature_deform_verts(ob->parent, ob, vertexCos, me->totvert);
}
done= 1;
}
}
if((ob->softflag & OB_SB_ENABLE) && (ob->softflag & OB_SB_POSTDEF)) {
done= 1;
if (!vertexCos) vertexCos = mesh_getVertexCos(me, NULL);
sbObjectStep(ob, (float)G.scene->r.cfra, vertexCos);
}
if (done) {
*vertexCos_r = vertexCos;
} else {
MEM_freeN(vertexCos_r);
}
}
int curve_modifier(Object *ob, char mode)

View File

@@ -1283,3 +1283,16 @@ void mesh_calc_normals(MVert *mverts, int numVerts, MFace *mfaces, int numFaces,
MEM_freeN(fnors);
}
}
float (*mesh_getVertexCos(Mesh *me, int *numVerts_r))[3]
{
int i, numVerts = me->totvert;
float (*cos)[3] = MEM_mallocN(sizeof(*cos)*numVerts, "vertexcos1");
if (numVerts_r) *numVerts_r = numVerts;
for (i=0; i<numVerts; i++) {
VECCOPY(cos[i], me->mvert[i].co);
}
return cos;
}