2002-10-12 11:37:38 +00:00
|
|
|
|
2003-04-26 13:07:59 +00:00
|
|
|
/* mesh.c
|
|
|
|
*
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* ***** BEGIN GPL/BL DUAL 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. The Blender
|
|
|
|
* Foundation also sells licenses for use in proprietary software under
|
|
|
|
* the Blender License. See http://www.blender.org/BL/ for information
|
|
|
|
* about this.
|
|
|
|
*
|
|
|
|
* 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) 2001-2002 by NaN Holding BV.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* The Original Code is: all of this file.
|
|
|
|
*
|
|
|
|
* Contributor(s): none yet.
|
|
|
|
*
|
|
|
|
* ***** END GPL/BL DUAL LICENSE BLOCK *****
|
|
|
|
*/
|
|
|
|
|
2002-11-25 12:02:15 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
#include "DNA_ID.h"
|
|
|
|
#include "DNA_curve_types.h"
|
|
|
|
#include "DNA_material_types.h"
|
|
|
|
#include "DNA_object_types.h"
|
|
|
|
#include "DNA_image_types.h"
|
|
|
|
#include "DNA_key_types.h"
|
|
|
|
#include "DNA_mesh_types.h"
|
2004-03-20 22:55:42 +00:00
|
|
|
#include "DNA_meshdata_types.h"
|
2006-09-12 14:05:26 +00:00
|
|
|
#include "DNA_ipo_types.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2006-11-06 01:08:26 +00:00
|
|
|
#include "BDR_sculptmode.h"
|
|
|
|
|
Added custom vertex/edge/face data for meshes:
All data layers, including MVert/MEdge/MFace, are now managed as custom
data layers. The pointers like Mesh.mvert, Mesh.dvert or Mesh.mcol are
still used of course, but allocating, copying or freeing these arrays
should be done through the CustomData API.
Work in progress documentation on this is here:
http://mediawiki.blender.org/index.php/BlenderDev/BlenderArchitecture/CustomData
Replaced TFace by MTFace:
This is the same struct, except that it does not contain color, that now
always stays separated in MCol. This was not a good design decision to
begin with, and it is needed for adding multiple color layers later. Note
that this does mean older Blender versions will not be able to read UV
coordinates from the next release, due to an SDNA limitation.
Removed DispListMesh:
This now fully replaced by DerivedMesh. To provide access to arrays of
vertices, edges and faces, like DispListMesh does. The semantics of the
DerivedMesh.getVertArray() and similar functions were changed to return
a pointer to an array if one exists, or otherwise allocate a temporary
one. On releasing the DerivedMesh, this temporary array will be removed
automatically.
Removed ssDM and meshDM DerivedMesh backends:
The ssDM backend was for DispListMesh, so that became obsolete automatically.
The meshDM backend was replaced by the custom data backend, that now figures
out which layers need to be modified, and only duplicates those.
This changes code in many places, and overall removes 2514 lines of code.
So, there's a good chance this might break some stuff, although I've been
testing it for a few days now. The good news is, adding multiple color and
uv layers should now become easy.
2006-11-20 04:28:02 +00:00
|
|
|
#include "BKE_customdata.h"
|
2005-07-14 17:10:44 +00:00
|
|
|
#include "BKE_depsgraph.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "BKE_main.h"
|
2005-03-29 16:43:39 +00:00
|
|
|
#include "BKE_DerivedMesh.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "BKE_global.h"
|
|
|
|
#include "BKE_mesh.h"
|
|
|
|
#include "BKE_subsurf.h"
|
|
|
|
#include "BKE_displist.h"
|
|
|
|
#include "BKE_library.h"
|
|
|
|
#include "BKE_material.h"
|
|
|
|
#include "BKE_key.h"
|
|
|
|
/* these 2 are only used by conversion functions */
|
|
|
|
#include "BKE_curve.h"
|
|
|
|
/* -- */
|
|
|
|
#include "BKE_object.h"
|
|
|
|
#include "BKE_utildefines.h"
|
|
|
|
#include "BKE_bad_level_calls.h"
|
|
|
|
|
2006-08-20 15:22:56 +00:00
|
|
|
#ifdef WITH_VERSE
|
|
|
|
#include "BKE_verse.h"
|
|
|
|
#endif
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "BLI_blenlib.h"
|
|
|
|
#include "BLI_editVert.h"
|
|
|
|
#include "BLI_arithb.h"
|
|
|
|
|
2006-11-06 01:08:26 +00:00
|
|
|
#include "multires.h"
|
|
|
|
|
Added custom vertex/edge/face data for meshes:
All data layers, including MVert/MEdge/MFace, are now managed as custom
data layers. The pointers like Mesh.mvert, Mesh.dvert or Mesh.mcol are
still used of course, but allocating, copying or freeing these arrays
should be done through the CustomData API.
Work in progress documentation on this is here:
http://mediawiki.blender.org/index.php/BlenderDev/BlenderArchitecture/CustomData
Replaced TFace by MTFace:
This is the same struct, except that it does not contain color, that now
always stays separated in MCol. This was not a good design decision to
begin with, and it is needed for adding multiple color layers later. Note
that this does mean older Blender versions will not be able to read UV
coordinates from the next release, due to an SDNA limitation.
Removed DispListMesh:
This now fully replaced by DerivedMesh. To provide access to arrays of
vertices, edges and faces, like DispListMesh does. The semantics of the
DerivedMesh.getVertArray() and similar functions were changed to return
a pointer to an array if one exists, or otherwise allocate a temporary
one. On releasing the DerivedMesh, this temporary array will be removed
automatically.
Removed ssDM and meshDM DerivedMesh backends:
The ssDM backend was for DispListMesh, so that became obsolete automatically.
The meshDM backend was replaced by the custom data backend, that now figures
out which layers need to be modified, and only duplicates those.
This changes code in many places, and overall removes 2514 lines of code.
So, there's a good chance this might break some stuff, although I've been
testing it for a few days now. The good news is, adding multiple color and
uv layers should now become easy.
2006-11-20 04:28:02 +00:00
|
|
|
int update_realtime_texture(MTFace *tface, double time)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
Image *ima;
|
|
|
|
int inc = 0;
|
|
|
|
float diff;
|
|
|
|
int newframe;
|
|
|
|
|
|
|
|
ima = tface->tpage;
|
|
|
|
|
|
|
|
if (!ima)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (ima->lastupdate<0)
|
|
|
|
ima->lastupdate = 0;
|
|
|
|
|
|
|
|
if (ima->lastupdate>time)
|
|
|
|
ima->lastupdate=(float)time;
|
|
|
|
|
|
|
|
if(ima->tpageflag & IMA_TWINANIM) {
|
|
|
|
if(ima->twend >= ima->xrep*ima->yrep) ima->twend= ima->xrep*ima->yrep-1;
|
|
|
|
|
2003-04-26 13:07:59 +00:00
|
|
|
/* check: is the bindcode not in the array? Then free. (still to do) */
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
diff = (float)(time-ima->lastupdate);
|
|
|
|
|
|
|
|
inc = (int)(diff*(float)ima->animspeed);
|
|
|
|
|
|
|
|
ima->lastupdate+=((float)inc/(float)ima->animspeed);
|
|
|
|
|
|
|
|
newframe = ima->lastframe+inc;
|
|
|
|
|
|
|
|
if (newframe > (int)ima->twend)
|
|
|
|
newframe = (int)ima->twsta-1 + (newframe-ima->twend)%(ima->twend-ima->twsta);
|
|
|
|
|
|
|
|
ima->lastframe = newframe;
|
|
|
|
}
|
|
|
|
return inc;
|
|
|
|
}
|
|
|
|
|
Added custom vertex/edge/face data for meshes:
All data layers, including MVert/MEdge/MFace, are now managed as custom
data layers. The pointers like Mesh.mvert, Mesh.dvert or Mesh.mcol are
still used of course, but allocating, copying or freeing these arrays
should be done through the CustomData API.
Work in progress documentation on this is here:
http://mediawiki.blender.org/index.php/BlenderDev/BlenderArchitecture/CustomData
Replaced TFace by MTFace:
This is the same struct, except that it does not contain color, that now
always stays separated in MCol. This was not a good design decision to
begin with, and it is needed for adding multiple color layers later. Note
that this does mean older Blender versions will not be able to read UV
coordinates from the next release, due to an SDNA limitation.
Removed DispListMesh:
This now fully replaced by DerivedMesh. To provide access to arrays of
vertices, edges and faces, like DispListMesh does. The semantics of the
DerivedMesh.getVertArray() and similar functions were changed to return
a pointer to an array if one exists, or otherwise allocate a temporary
one. On releasing the DerivedMesh, this temporary array will be removed
automatically.
Removed ssDM and meshDM DerivedMesh backends:
The ssDM backend was for DispListMesh, so that became obsolete automatically.
The meshDM backend was replaced by the custom data backend, that now figures
out which layers need to be modified, and only duplicates those.
This changes code in many places, and overall removes 2514 lines of code.
So, there's a good chance this might break some stuff, although I've been
testing it for a few days now. The good news is, adding multiple color and
uv layers should now become easy.
2006-11-20 04:28:02 +00:00
|
|
|
void mesh_update_customdata_pointers(Mesh *me)
|
|
|
|
{
|
|
|
|
me->mvert = CustomData_get_layer(&me->vdata, CD_MVERT);
|
|
|
|
me->dvert = CustomData_get_layer(&me->vdata, CD_MDEFORMVERT);
|
|
|
|
me->msticky = CustomData_get_layer(&me->vdata, CD_MSTICKY);
|
|
|
|
|
|
|
|
me->medge = CustomData_get_layer(&me->edata, CD_MEDGE);
|
|
|
|
|
|
|
|
me->mface = CustomData_get_layer(&me->fdata, CD_MFACE);
|
|
|
|
me->mcol = CustomData_get_layer(&me->fdata, CD_MCOL);
|
|
|
|
me->mtface = CustomData_get_layer(&me->fdata, CD_MTFACE);
|
|
|
|
}
|
|
|
|
|
2006-09-12 14:05:26 +00:00
|
|
|
/* Note: unlinking is called when me->id.us is 0, question remains how
|
|
|
|
* much unlinking of Library data in Mesh should be done... probably
|
|
|
|
* we need a more generic method, like the expand() functions in
|
|
|
|
* readfile.c */
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
void unlink_mesh(Mesh *me)
|
|
|
|
{
|
|
|
|
int a;
|
|
|
|
|
|
|
|
if(me==0) return;
|
|
|
|
|
|
|
|
for(a=0; a<me->totcol; a++) {
|
|
|
|
if(me->mat[a]) me->mat[a]->id.us--;
|
|
|
|
me->mat[a]= 0;
|
|
|
|
}
|
2006-09-12 14:05:26 +00:00
|
|
|
|
|
|
|
if(me->key) {
|
|
|
|
me->key->id.us--;
|
|
|
|
if (me->key->id.us == 0 && me->key->ipo )
|
|
|
|
me->key->ipo->id.us--;
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
me->key= 0;
|
|
|
|
|
|
|
|
if(me->texcomesh) me->texcomesh= 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-04-26 13:07:59 +00:00
|
|
|
/* do not free mesh itself */
|
2002-10-12 11:37:38 +00:00
|
|
|
void free_mesh(Mesh *me)
|
|
|
|
{
|
|
|
|
unlink_mesh(me);
|
|
|
|
|
2006-11-06 01:08:26 +00:00
|
|
|
if(me->pv) {
|
|
|
|
if(me->pv->vert_map) MEM_freeN(me->pv->vert_map);
|
|
|
|
if(me->pv->edge_map) MEM_freeN(me->pv->edge_map);
|
|
|
|
if(me->pv->old_faces) MEM_freeN(me->pv->old_faces);
|
|
|
|
if(me->pv->old_edges) MEM_freeN(me->pv->old_edges);
|
2007-01-16 06:56:03 +00:00
|
|
|
me->totvert= me->pv->totvert;
|
|
|
|
me->totedge= me->pv->totedge;
|
|
|
|
me->totface= me->pv->totface;
|
2006-11-06 01:08:26 +00:00
|
|
|
MEM_freeN(me->pv);
|
|
|
|
}
|
|
|
|
|
Added custom vertex/edge/face data for meshes:
All data layers, including MVert/MEdge/MFace, are now managed as custom
data layers. The pointers like Mesh.mvert, Mesh.dvert or Mesh.mcol are
still used of course, but allocating, copying or freeing these arrays
should be done through the CustomData API.
Work in progress documentation on this is here:
http://mediawiki.blender.org/index.php/BlenderDev/BlenderArchitecture/CustomData
Replaced TFace by MTFace:
This is the same struct, except that it does not contain color, that now
always stays separated in MCol. This was not a good design decision to
begin with, and it is needed for adding multiple color layers later. Note
that this does mean older Blender versions will not be able to read UV
coordinates from the next release, due to an SDNA limitation.
Removed DispListMesh:
This now fully replaced by DerivedMesh. To provide access to arrays of
vertices, edges and faces, like DispListMesh does. The semantics of the
DerivedMesh.getVertArray() and similar functions were changed to return
a pointer to an array if one exists, or otherwise allocate a temporary
one. On releasing the DerivedMesh, this temporary array will be removed
automatically.
Removed ssDM and meshDM DerivedMesh backends:
The ssDM backend was for DispListMesh, so that became obsolete automatically.
The meshDM backend was replaced by the custom data backend, that now figures
out which layers need to be modified, and only duplicates those.
This changes code in many places, and overall removes 2514 lines of code.
So, there's a good chance this might break some stuff, although I've been
testing it for a few days now. The good news is, adding multiple color and
uv layers should now become easy.
2006-11-20 04:28:02 +00:00
|
|
|
CustomData_free(&me->vdata, me->totvert);
|
|
|
|
CustomData_free(&me->edata, me->totedge);
|
|
|
|
CustomData_free(&me->fdata, me->totface);
|
2004-07-08 20:38:27 +00:00
|
|
|
|
|
|
|
if(me->mat) MEM_freeN(me->mat);
|
2005-07-18 18:28:16 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
if(me->bb) MEM_freeN(me->bb);
|
2006-05-10 21:08:38 +00:00
|
|
|
if(me->mselect) MEM_freeN(me->mselect);
|
2006-11-06 01:08:26 +00:00
|
|
|
|
2006-12-02 23:37:52 +00:00
|
|
|
if(me->mr) multires_free(me->mr);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void copy_dverts(MDeformVert *dst, MDeformVert *src, int copycount)
|
|
|
|
{
|
|
|
|
/* Assumes dst is already set up */
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!src || !dst)
|
|
|
|
return;
|
|
|
|
|
|
|
|
memcpy (dst, src, copycount * sizeof(MDeformVert));
|
|
|
|
|
|
|
|
for (i=0; i<copycount; i++){
|
|
|
|
if (src[i].dw){
|
|
|
|
dst[i].dw = MEM_callocN (sizeof(MDeformWeight)*src[i].totweight, "copy_deformWeight");
|
|
|
|
memcpy (dst[i].dw, src[i].dw, sizeof (MDeformWeight)*src[i].totweight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
Added custom vertex/edge/face data for meshes:
All data layers, including MVert/MEdge/MFace, are now managed as custom
data layers. The pointers like Mesh.mvert, Mesh.dvert or Mesh.mcol are
still used of course, but allocating, copying or freeing these arrays
should be done through the CustomData API.
Work in progress documentation on this is here:
http://mediawiki.blender.org/index.php/BlenderDev/BlenderArchitecture/CustomData
Replaced TFace by MTFace:
This is the same struct, except that it does not contain color, that now
always stays separated in MCol. This was not a good design decision to
begin with, and it is needed for adding multiple color layers later. Note
that this does mean older Blender versions will not be able to read UV
coordinates from the next release, due to an SDNA limitation.
Removed DispListMesh:
This now fully replaced by DerivedMesh. To provide access to arrays of
vertices, edges and faces, like DispListMesh does. The semantics of the
DerivedMesh.getVertArray() and similar functions were changed to return
a pointer to an array if one exists, or otherwise allocate a temporary
one. On releasing the DerivedMesh, this temporary array will be removed
automatically.
Removed ssDM and meshDM DerivedMesh backends:
The ssDM backend was for DispListMesh, so that became obsolete automatically.
The meshDM backend was replaced by the custom data backend, that now figures
out which layers need to be modified, and only duplicates those.
This changes code in many places, and overall removes 2514 lines of code.
So, there's a good chance this might break some stuff, although I've been
testing it for a few days now. The good news is, adding multiple color and
uv layers should now become easy.
2006-11-20 04:28:02 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
void free_dverts(MDeformVert *dvert, int totvert)
|
|
|
|
{
|
|
|
|
/* Instead of freeing the verts directly,
|
|
|
|
call this function to delete any special
|
|
|
|
vert data */
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!dvert)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Free any special data from the verts */
|
|
|
|
for (i=0; i<totvert; i++){
|
|
|
|
if (dvert[i].dw) MEM_freeN (dvert[i].dw);
|
|
|
|
}
|
|
|
|
MEM_freeN (dvert);
|
|
|
|
}
|
|
|
|
|
2007-03-11 16:25:17 +00:00
|
|
|
Mesh *add_mesh(char *name)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
Mesh *me;
|
|
|
|
|
2007-03-11 16:25:17 +00:00
|
|
|
me= alloc_libblock(&G.main->mesh, ID_ME, name);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
me->size[0]= me->size[1]= me->size[2]= 1.0;
|
|
|
|
me->smoothresh= 30;
|
2004-03-22 22:02:18 +00:00
|
|
|
me->texflag= AUTOSPACE;
|
2002-10-12 11:37:38 +00:00
|
|
|
me->flag= ME_TWOSIDED;
|
|
|
|
me->bb= unit_boundbox();
|
2006-08-20 15:22:56 +00:00
|
|
|
|
|
|
|
#ifdef WITH_VERSE
|
|
|
|
me->vnode = NULL;
|
|
|
|
#endif
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
return me;
|
|
|
|
}
|
|
|
|
|
|
|
|
Mesh *copy_mesh(Mesh *me)
|
|
|
|
{
|
|
|
|
Mesh *men;
|
2006-12-12 21:29:09 +00:00
|
|
|
MTFace *tface;
|
|
|
|
int a, i;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
men= copy_libblock(me);
|
|
|
|
|
|
|
|
men->mat= MEM_dupallocN(me->mat);
|
|
|
|
for(a=0; a<men->totcol; a++) {
|
|
|
|
id_us_plus((ID *)men->mat[a]);
|
|
|
|
}
|
|
|
|
id_us_plus((ID *)men->texcomesh);
|
|
|
|
|
Added custom vertex/edge/face data for meshes:
All data layers, including MVert/MEdge/MFace, are now managed as custom
data layers. The pointers like Mesh.mvert, Mesh.dvert or Mesh.mcol are
still used of course, but allocating, copying or freeing these arrays
should be done through the CustomData API.
Work in progress documentation on this is here:
http://mediawiki.blender.org/index.php/BlenderDev/BlenderArchitecture/CustomData
Replaced TFace by MTFace:
This is the same struct, except that it does not contain color, that now
always stays separated in MCol. This was not a good design decision to
begin with, and it is needed for adding multiple color layers later. Note
that this does mean older Blender versions will not be able to read UV
coordinates from the next release, due to an SDNA limitation.
Removed DispListMesh:
This now fully replaced by DerivedMesh. To provide access to arrays of
vertices, edges and faces, like DispListMesh does. The semantics of the
DerivedMesh.getVertArray() and similar functions were changed to return
a pointer to an array if one exists, or otherwise allocate a temporary
one. On releasing the DerivedMesh, this temporary array will be removed
automatically.
Removed ssDM and meshDM DerivedMesh backends:
The ssDM backend was for DispListMesh, so that became obsolete automatically.
The meshDM backend was replaced by the custom data backend, that now figures
out which layers need to be modified, and only duplicates those.
This changes code in many places, and overall removes 2514 lines of code.
So, there's a good chance this might break some stuff, although I've been
testing it for a few days now. The good news is, adding multiple color and
uv layers should now become easy.
2006-11-20 04:28:02 +00:00
|
|
|
CustomData_copy(&me->vdata, &men->vdata, CD_MASK_MESH, CD_DUPLICATE, men->totvert);
|
|
|
|
CustomData_copy(&me->edata, &men->edata, CD_MASK_MESH, CD_DUPLICATE, men->totedge);
|
|
|
|
CustomData_copy(&me->fdata, &men->fdata, CD_MASK_MESH, CD_DUPLICATE, men->totface);
|
|
|
|
mesh_update_customdata_pointers(men);
|
|
|
|
|
2006-12-12 21:29:09 +00:00
|
|
|
/* ensure indirect linked data becomes lib-extern */
|
|
|
|
for(i=0; i<me->fdata.totlayer; i++) {
|
|
|
|
if(me->fdata.layers[i].type == CD_MTFACE) {
|
|
|
|
tface= (MTFace*)me->fdata.layers[i].data;
|
|
|
|
|
|
|
|
for(a=0; a<me->totface; a++, tface++)
|
|
|
|
if(tface->tpage)
|
|
|
|
id_lib_extern((ID*)tface->tpage);
|
|
|
|
}
|
2006-10-16 11:31:09 +00:00
|
|
|
}
|
2006-12-01 18:41:25 +00:00
|
|
|
|
|
|
|
if(me->mr)
|
|
|
|
men->mr= multires_copy(me->mr);
|
Added custom vertex/edge/face data for meshes:
All data layers, including MVert/MEdge/MFace, are now managed as custom
data layers. The pointers like Mesh.mvert, Mesh.dvert or Mesh.mcol are
still used of course, but allocating, copying or freeing these arrays
should be done through the CustomData API.
Work in progress documentation on this is here:
http://mediawiki.blender.org/index.php/BlenderDev/BlenderArchitecture/CustomData
Replaced TFace by MTFace:
This is the same struct, except that it does not contain color, that now
always stays separated in MCol. This was not a good design decision to
begin with, and it is needed for adding multiple color layers later. Note
that this does mean older Blender versions will not be able to read UV
coordinates from the next release, due to an SDNA limitation.
Removed DispListMesh:
This now fully replaced by DerivedMesh. To provide access to arrays of
vertices, edges and faces, like DispListMesh does. The semantics of the
DerivedMesh.getVertArray() and similar functions were changed to return
a pointer to an array if one exists, or otherwise allocate a temporary
one. On releasing the DerivedMesh, this temporary array will be removed
automatically.
Removed ssDM and meshDM DerivedMesh backends:
The ssDM backend was for DispListMesh, so that became obsolete automatically.
The meshDM backend was replaced by the custom data backend, that now figures
out which layers need to be modified, and only duplicates those.
This changes code in many places, and overall removes 2514 lines of code.
So, there's a good chance this might break some stuff, although I've been
testing it for a few days now. The good news is, adding multiple color and
uv layers should now become easy.
2006-11-20 04:28:02 +00:00
|
|
|
|
|
|
|
men->mselect= NULL;
|
2006-05-10 17:22:49 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
men->bb= MEM_dupallocN(men->bb);
|
|
|
|
|
|
|
|
men->key= copy_key(me->key);
|
|
|
|
if(men->key) men->key->from= (ID *)men;
|
2006-08-20 15:22:56 +00:00
|
|
|
|
|
|
|
#ifdef WITH_VERSE
|
|
|
|
men->vnode = NULL;
|
|
|
|
#endif
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
return men;
|
|
|
|
}
|
|
|
|
|
|
|
|
void make_local_tface(Mesh *me)
|
|
|
|
{
|
Added custom vertex/edge/face data for meshes:
All data layers, including MVert/MEdge/MFace, are now managed as custom
data layers. The pointers like Mesh.mvert, Mesh.dvert or Mesh.mcol are
still used of course, but allocating, copying or freeing these arrays
should be done through the CustomData API.
Work in progress documentation on this is here:
http://mediawiki.blender.org/index.php/BlenderDev/BlenderArchitecture/CustomData
Replaced TFace by MTFace:
This is the same struct, except that it does not contain color, that now
always stays separated in MCol. This was not a good design decision to
begin with, and it is needed for adding multiple color layers later. Note
that this does mean older Blender versions will not be able to read UV
coordinates from the next release, due to an SDNA limitation.
Removed DispListMesh:
This now fully replaced by DerivedMesh. To provide access to arrays of
vertices, edges and faces, like DispListMesh does. The semantics of the
DerivedMesh.getVertArray() and similar functions were changed to return
a pointer to an array if one exists, or otherwise allocate a temporary
one. On releasing the DerivedMesh, this temporary array will be removed
automatically.
Removed ssDM and meshDM DerivedMesh backends:
The ssDM backend was for DispListMesh, so that became obsolete automatically.
The meshDM backend was replaced by the custom data backend, that now figures
out which layers need to be modified, and only duplicates those.
This changes code in many places, and overall removes 2514 lines of code.
So, there's a good chance this might break some stuff, although I've been
testing it for a few days now. The good news is, adding multiple color and
uv layers should now become easy.
2006-11-20 04:28:02 +00:00
|
|
|
MTFace *tface;
|
2002-10-12 11:37:38 +00:00
|
|
|
Image *ima;
|
2006-12-12 21:29:09 +00:00
|
|
|
int a, i;
|
|
|
|
|
|
|
|
for(i=0; i<me->fdata.totlayer; i++) {
|
|
|
|
if(me->fdata.layers[i].type == CD_MTFACE) {
|
|
|
|
tface= (MTFace*)me->fdata.layers[i].data;
|
|
|
|
|
|
|
|
for(a=0; a<me->totface; a++, tface++) {
|
|
|
|
/* special case: ima always local immediately */
|
|
|
|
if(tface->tpage) {
|
|
|
|
ima= tface->tpage;
|
|
|
|
if(ima->id.lib) {
|
|
|
|
ima->id.lib= 0;
|
|
|
|
ima->id.flag= LIB_LOCAL;
|
|
|
|
new_id(0, (ID *)ima, 0);
|
|
|
|
}
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void make_local_mesh(Mesh *me)
|
|
|
|
{
|
|
|
|
Object *ob;
|
|
|
|
Mesh *men;
|
|
|
|
int local=0, lib=0;
|
2003-04-26 13:07:59 +00:00
|
|
|
|
|
|
|
/* - only lib users: do nothing
|
|
|
|
* - only local users: set flag
|
|
|
|
* - mixed: make copy
|
|
|
|
*/
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
if(me->id.lib==0) return;
|
|
|
|
if(me->id.us==1) {
|
|
|
|
me->id.lib= 0;
|
|
|
|
me->id.flag= LIB_LOCAL;
|
|
|
|
new_id(0, (ID *)me, 0);
|
|
|
|
|
Added custom vertex/edge/face data for meshes:
All data layers, including MVert/MEdge/MFace, are now managed as custom
data layers. The pointers like Mesh.mvert, Mesh.dvert or Mesh.mcol are
still used of course, but allocating, copying or freeing these arrays
should be done through the CustomData API.
Work in progress documentation on this is here:
http://mediawiki.blender.org/index.php/BlenderDev/BlenderArchitecture/CustomData
Replaced TFace by MTFace:
This is the same struct, except that it does not contain color, that now
always stays separated in MCol. This was not a good design decision to
begin with, and it is needed for adding multiple color layers later. Note
that this does mean older Blender versions will not be able to read UV
coordinates from the next release, due to an SDNA limitation.
Removed DispListMesh:
This now fully replaced by DerivedMesh. To provide access to arrays of
vertices, edges and faces, like DispListMesh does. The semantics of the
DerivedMesh.getVertArray() and similar functions were changed to return
a pointer to an array if one exists, or otherwise allocate a temporary
one. On releasing the DerivedMesh, this temporary array will be removed
automatically.
Removed ssDM and meshDM DerivedMesh backends:
The ssDM backend was for DispListMesh, so that became obsolete automatically.
The meshDM backend was replaced by the custom data backend, that now figures
out which layers need to be modified, and only duplicates those.
This changes code in many places, and overall removes 2514 lines of code.
So, there's a good chance this might break some stuff, although I've been
testing it for a few days now. The good news is, adding multiple color and
uv layers should now become easy.
2006-11-20 04:28:02 +00:00
|
|
|
if(me->mtface) make_local_tface(me);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ob= G.main->object.first;
|
|
|
|
while(ob) {
|
|
|
|
if( me==get_mesh(ob) ) {
|
|
|
|
if(ob->id.lib) lib= 1;
|
|
|
|
else local= 1;
|
|
|
|
}
|
|
|
|
ob= ob->id.next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(local && lib==0) {
|
|
|
|
me->id.lib= 0;
|
|
|
|
me->id.flag= LIB_LOCAL;
|
|
|
|
new_id(0, (ID *)me, 0);
|
|
|
|
|
Added custom vertex/edge/face data for meshes:
All data layers, including MVert/MEdge/MFace, are now managed as custom
data layers. The pointers like Mesh.mvert, Mesh.dvert or Mesh.mcol are
still used of course, but allocating, copying or freeing these arrays
should be done through the CustomData API.
Work in progress documentation on this is here:
http://mediawiki.blender.org/index.php/BlenderDev/BlenderArchitecture/CustomData
Replaced TFace by MTFace:
This is the same struct, except that it does not contain color, that now
always stays separated in MCol. This was not a good design decision to
begin with, and it is needed for adding multiple color layers later. Note
that this does mean older Blender versions will not be able to read UV
coordinates from the next release, due to an SDNA limitation.
Removed DispListMesh:
This now fully replaced by DerivedMesh. To provide access to arrays of
vertices, edges and faces, like DispListMesh does. The semantics of the
DerivedMesh.getVertArray() and similar functions were changed to return
a pointer to an array if one exists, or otherwise allocate a temporary
one. On releasing the DerivedMesh, this temporary array will be removed
automatically.
Removed ssDM and meshDM DerivedMesh backends:
The ssDM backend was for DispListMesh, so that became obsolete automatically.
The meshDM backend was replaced by the custom data backend, that now figures
out which layers need to be modified, and only duplicates those.
This changes code in many places, and overall removes 2514 lines of code.
So, there's a good chance this might break some stuff, although I've been
testing it for a few days now. The good news is, adding multiple color and
uv layers should now become easy.
2006-11-20 04:28:02 +00:00
|
|
|
if(me->mtface) make_local_tface(me);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
else if(local && lib) {
|
|
|
|
men= copy_mesh(me);
|
|
|
|
men->id.us= 0;
|
|
|
|
|
|
|
|
ob= G.main->object.first;
|
|
|
|
while(ob) {
|
|
|
|
if( me==get_mesh(ob) ) {
|
|
|
|
if(ob->id.lib==0) {
|
|
|
|
set_mesh(ob, men);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ob= ob->id.next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void boundbox_mesh(Mesh *me, float *loc, float *size)
|
|
|
|
{
|
|
|
|
MVert *mvert;
|
|
|
|
BoundBox *bb;
|
|
|
|
float min[3], max[3];
|
|
|
|
float mloc[3], msize[3];
|
|
|
|
int a;
|
|
|
|
|
|
|
|
if(me->bb==0) me->bb= MEM_callocN(sizeof(BoundBox), "boundbox");
|
|
|
|
bb= me->bb;
|
|
|
|
|
|
|
|
INIT_MINMAX(min, max);
|
|
|
|
|
|
|
|
if (!loc) loc= mloc;
|
|
|
|
if (!size) size= msize;
|
|
|
|
|
|
|
|
mvert= me->mvert;
|
|
|
|
for(a=0; a<me->totvert; a++, mvert++) {
|
|
|
|
DO_MINMAX(mvert->co, min, max);
|
|
|
|
}
|
|
|
|
|
2005-07-18 17:33:51 +00:00
|
|
|
if(!me->totvert) {
|
|
|
|
min[0] = min[1] = min[2] = -1.0f;
|
|
|
|
max[0] = max[1] = max[2] = 1.0f;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2005-07-18 17:33:51 +00:00
|
|
|
loc[0]= (min[0]+max[0])/2.0f;
|
|
|
|
loc[1]= (min[1]+max[1])/2.0f;
|
|
|
|
loc[2]= (min[2]+max[2])/2.0f;
|
|
|
|
|
|
|
|
size[0]= (max[0]-min[0])/2.0f;
|
|
|
|
size[1]= (max[1]-min[1])/2.0f;
|
|
|
|
size[2]= (max[2]-min[2])/2.0f;
|
|
|
|
|
|
|
|
boundbox_set_from_min_max(bb, min, max);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void tex_space_mesh(Mesh *me)
|
|
|
|
{
|
|
|
|
KeyBlock *kb;
|
|
|
|
float *fp, loc[3], size[3], min[3], max[3];
|
|
|
|
int a;
|
|
|
|
|
|
|
|
boundbox_mesh(me, loc, size);
|
|
|
|
|
2004-03-22 22:02:18 +00:00
|
|
|
if(me->texflag & AUTOSPACE) {
|
2002-10-12 11:37:38 +00:00
|
|
|
if(me->key) {
|
|
|
|
kb= me->key->refkey;
|
|
|
|
if (kb) {
|
|
|
|
|
|
|
|
INIT_MINMAX(min, max);
|
|
|
|
|
|
|
|
fp= kb->data;
|
|
|
|
for(a=0; a<kb->totelem; a++, fp+=3) {
|
|
|
|
DO_MINMAX(fp, min, max);
|
|
|
|
}
|
|
|
|
if(kb->totelem) {
|
|
|
|
loc[0]= (min[0]+max[0])/2.0f; loc[1]= (min[1]+max[1])/2.0f; loc[2]= (min[2]+max[2])/2.0f;
|
|
|
|
size[0]= (max[0]-min[0])/2.0f; size[1]= (max[1]-min[1])/2.0f; size[2]= (max[2]-min[2])/2.0f;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
loc[0]= loc[1]= loc[2]= 0.0;
|
|
|
|
size[0]= size[1]= size[2]= 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-07-14 21:57:18 +00:00
|
|
|
for (a=0; a<3; a++) {
|
|
|
|
if(size[a]==0.0) size[a]= 1.0;
|
|
|
|
else if(size[a]>0.0 && size[a]<0.00001) size[a]= 0.00001;
|
|
|
|
else if(size[a]<0.0 && size[a]> -0.00001) size[a]= -0.00001;
|
|
|
|
}
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
VECCOPY(me->loc, loc);
|
|
|
|
VECCOPY(me->size, size);
|
|
|
|
me->rot[0]= me->rot[1]= me->rot[2]= 0.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-05 21:50:23 +00:00
|
|
|
BoundBox *mesh_get_bb(Object *ob)
|
2005-07-14 18:04:27 +00:00
|
|
|
{
|
2007-12-05 21:50:23 +00:00
|
|
|
Mesh *me= ob->data;
|
|
|
|
|
|
|
|
if(ob->bb)
|
|
|
|
return ob->bb;
|
|
|
|
|
|
|
|
if (!me->bb)
|
2005-07-14 18:04:27 +00:00
|
|
|
tex_space_mesh(me);
|
|
|
|
|
|
|
|
return me->bb;
|
|
|
|
}
|
|
|
|
|
2005-07-14 21:57:18 +00:00
|
|
|
void mesh_get_texspace(Mesh *me, float *loc_r, float *rot_r, float *size_r)
|
|
|
|
{
|
|
|
|
if (!me->bb) {
|
|
|
|
tex_space_mesh(me);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (loc_r) VECCOPY(loc_r, me->loc);
|
|
|
|
if (rot_r) VECCOPY(rot_r, me->rot);
|
|
|
|
if (size_r) VECCOPY(size_r, me->size);
|
|
|
|
}
|
|
|
|
|
2007-12-05 12:40:54 +00:00
|
|
|
float *get_mesh_orco_verts(Object *ob)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2005-07-20 04:44:02 +00:00
|
|
|
Mesh *me = ob->data;
|
2005-07-18 19:58:23 +00:00
|
|
|
int a, totvert;
|
2007-01-21 23:46:00 +00:00
|
|
|
float (*vcos)[3] = NULL;
|
2005-07-18 18:28:16 +00:00
|
|
|
|
2007-12-05 12:40:54 +00:00
|
|
|
/* Get appropriate vertex coordinates */
|
2005-07-18 19:58:23 +00:00
|
|
|
if(me->key && me->texcomesh==0 && me->key->refkey) {
|
2007-11-04 22:00:24 +00:00
|
|
|
vcos= mesh_getRefKeyCos(me, &totvert);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
else {
|
2007-01-21 23:46:00 +00:00
|
|
|
MultiresLevel *lvl = NULL;
|
|
|
|
MVert *mvert = NULL;
|
|
|
|
|
|
|
|
if(me->mr) {
|
2007-04-14 19:54:26 +00:00
|
|
|
lvl = multires_level_n(me->mr, me->mr->pinlvl);
|
2007-01-21 23:46:00 +00:00
|
|
|
vcos = MEM_callocN(sizeof(*vcos)*lvl->totvert, "orco mr mesh");
|
2007-06-01 02:21:11 +00:00
|
|
|
mvert = me->mr->verts;
|
2007-01-21 23:46:00 +00:00
|
|
|
totvert = lvl->totvert;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Mesh *tme = me->texcomesh?me->texcomesh:me;
|
2007-01-22 09:24:52 +00:00
|
|
|
vcos = MEM_callocN(sizeof(*vcos)*me->totvert, "orco mesh");
|
2007-01-21 23:46:00 +00:00
|
|
|
mvert = tme->mvert;
|
|
|
|
totvert = MIN2(tme->totvert, me->totvert);
|
|
|
|
}
|
2005-07-18 19:58:23 +00:00
|
|
|
|
|
|
|
for(a=0; a<totvert; a++, mvert++) {
|
|
|
|
vcos[a][0]= mvert->co[0];
|
|
|
|
vcos[a][1]= mvert->co[1];
|
|
|
|
vcos[a][2]= mvert->co[2];
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
2005-07-18 18:28:16 +00:00
|
|
|
|
2007-12-05 12:40:54 +00:00
|
|
|
return (float*)vcos;
|
|
|
|
}
|
2005-07-18 19:58:23 +00:00
|
|
|
|
2007-12-11 20:02:21 +00:00
|
|
|
void transform_mesh_orco_verts(Mesh *me, float (*orco)[3], int totvert, int invert)
|
2007-12-05 12:40:54 +00:00
|
|
|
{
|
|
|
|
float loc[3], size[3];
|
|
|
|
int a;
|
2005-07-18 19:58:23 +00:00
|
|
|
|
2005-08-13 16:39:22 +00:00
|
|
|
mesh_get_texspace(me->texcomesh?me->texcomesh:me, loc, NULL, size);
|
2005-07-18 19:58:23 +00:00
|
|
|
|
2007-12-11 20:02:21 +00:00
|
|
|
if(invert) {
|
|
|
|
for(a=0; a<totvert; a++) {
|
|
|
|
float *co = orco[a];
|
|
|
|
co[0] = co[0]*size[0] + loc[0];
|
|
|
|
co[1] = co[1]*size[1] + loc[1];
|
|
|
|
co[2] = co[2]*size[2] + loc[2];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
for(a=0; a<totvert; a++) {
|
|
|
|
float *co = orco[a];
|
|
|
|
co[0] = (co[0]-loc[0])/size[0];
|
|
|
|
co[1] = (co[1]-loc[1])/size[1];
|
|
|
|
co[2] = (co[2]-loc[2])/size[2];
|
|
|
|
}
|
2005-07-18 19:58:23 +00:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2006-11-08 20:14:04 +00:00
|
|
|
/* rotates the vertices of a face in case v[2] or v[3] (vertex index) is = 0.
|
|
|
|
this is necessary to make the if(mface->v4) check for quads work */
|
Added custom vertex/edge/face data for meshes:
All data layers, including MVert/MEdge/MFace, are now managed as custom
data layers. The pointers like Mesh.mvert, Mesh.dvert or Mesh.mcol are
still used of course, but allocating, copying or freeing these arrays
should be done through the CustomData API.
Work in progress documentation on this is here:
http://mediawiki.blender.org/index.php/BlenderDev/BlenderArchitecture/CustomData
Replaced TFace by MTFace:
This is the same struct, except that it does not contain color, that now
always stays separated in MCol. This was not a good design decision to
begin with, and it is needed for adding multiple color layers later. Note
that this does mean older Blender versions will not be able to read UV
coordinates from the next release, due to an SDNA limitation.
Removed DispListMesh:
This now fully replaced by DerivedMesh. To provide access to arrays of
vertices, edges and faces, like DispListMesh does. The semantics of the
DerivedMesh.getVertArray() and similar functions were changed to return
a pointer to an array if one exists, or otherwise allocate a temporary
one. On releasing the DerivedMesh, this temporary array will be removed
automatically.
Removed ssDM and meshDM DerivedMesh backends:
The ssDM backend was for DispListMesh, so that became obsolete automatically.
The meshDM backend was replaced by the custom data backend, that now figures
out which layers need to be modified, and only duplicates those.
This changes code in many places, and overall removes 2514 lines of code.
So, there's a good chance this might break some stuff, although I've been
testing it for a few days now. The good news is, adding multiple color and
uv layers should now become easy.
2006-11-20 04:28:02 +00:00
|
|
|
void test_index_face(MFace *mface, CustomData *fdata, int mfindex, int nr)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
/* first test if the face is legal */
|
|
|
|
if(mface->v3 && mface->v3==mface->v4) {
|
|
|
|
mface->v4= 0;
|
|
|
|
nr--;
|
|
|
|
}
|
|
|
|
if(mface->v2 && mface->v2==mface->v3) {
|
|
|
|
mface->v3= mface->v4;
|
|
|
|
mface->v4= 0;
|
|
|
|
nr--;
|
|
|
|
}
|
|
|
|
if(mface->v1==mface->v2) {
|
|
|
|
mface->v2= mface->v3;
|
|
|
|
mface->v3= mface->v4;
|
|
|
|
mface->v4= 0;
|
|
|
|
nr--;
|
|
|
|
}
|
|
|
|
|
2003-04-26 13:07:59 +00:00
|
|
|
/* prevent a zero at wrong index location */
|
- added mesh_strip_loose_faces, works in conjunction with make_edges
to get rid of faces with MFace.v3==0
- change all Mesh's to have ->medge now. This is forced by make_edges
on readfile, and in the various exotic important routines, and on
conversion back in python.
- make python NMesh structure always have medges now (needs testing)
- with above two changes it is guarenteed that mf->v3 is never ==0
in main blender code (i.e., all MFace's are actually triangles
or quads) and so I went through and removed all the historic tests
to deal with MFace.v3==0. Equals lots of deleting, I am in heaven!
- removed MEdge edcode flag, no longer needed
- added experimental replacement for edge flag system
Still are some inconsistencies in FACESELECT mode edge drawing to
be ironed out.
NOTE: This commit adds an experimental edge flag calc system, based
on 10-seconds-of-thought algorithm by yours truly. Would appreciate
feedback on how this system works, esp compared to old one and esp
on complex or interesting models.
To Use: New system is enabled by setting G.rt to a value between
1 and 1000 (Value of 0 uses old system). Value 1000 is reserved for
"auto" edge, which is more or less identical to old system but also
makes sure that at least 10% of edges are drawn (solves errors for
super subdivided meshes). Values between 1 and 999 act as percent
(out of 1000) of edges that should be drawn, starting with "most
interesting" edges first. Please try it and comment!
2005-08-21 07:19:20 +00:00
|
|
|
if(nr==3) {
|
2002-10-12 11:37:38 +00:00
|
|
|
if(mface->v3==0) {
|
Added custom vertex/edge/face data for meshes:
All data layers, including MVert/MEdge/MFace, are now managed as custom
data layers. The pointers like Mesh.mvert, Mesh.dvert or Mesh.mcol are
still used of course, but allocating, copying or freeing these arrays
should be done through the CustomData API.
Work in progress documentation on this is here:
http://mediawiki.blender.org/index.php/BlenderDev/BlenderArchitecture/CustomData
Replaced TFace by MTFace:
This is the same struct, except that it does not contain color, that now
always stays separated in MCol. This was not a good design decision to
begin with, and it is needed for adding multiple color layers later. Note
that this does mean older Blender versions will not be able to read UV
coordinates from the next release, due to an SDNA limitation.
Removed DispListMesh:
This now fully replaced by DerivedMesh. To provide access to arrays of
vertices, edges and faces, like DispListMesh does. The semantics of the
DerivedMesh.getVertArray() and similar functions were changed to return
a pointer to an array if one exists, or otherwise allocate a temporary
one. On releasing the DerivedMesh, this temporary array will be removed
automatically.
Removed ssDM and meshDM DerivedMesh backends:
The ssDM backend was for DispListMesh, so that became obsolete automatically.
The meshDM backend was replaced by the custom data backend, that now figures
out which layers need to be modified, and only duplicates those.
This changes code in many places, and overall removes 2514 lines of code.
So, there's a good chance this might break some stuff, although I've been
testing it for a few days now. The good news is, adding multiple color and
uv layers should now become easy.
2006-11-20 04:28:02 +00:00
|
|
|
static int corner_indices[4] = {1, 2, 0, 3};
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
SWAP(int, mface->v1, mface->v2);
|
|
|
|
SWAP(int, mface->v2, mface->v3);
|
|
|
|
|
2006-11-20 19:03:37 +00:00
|
|
|
if(fdata)
|
|
|
|
CustomData_swap(fdata, mfindex, corner_indices);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(nr==4) {
|
|
|
|
if(mface->v3==0 || mface->v4==0) {
|
Added custom vertex/edge/face data for meshes:
All data layers, including MVert/MEdge/MFace, are now managed as custom
data layers. The pointers like Mesh.mvert, Mesh.dvert or Mesh.mcol are
still used of course, but allocating, copying or freeing these arrays
should be done through the CustomData API.
Work in progress documentation on this is here:
http://mediawiki.blender.org/index.php/BlenderDev/BlenderArchitecture/CustomData
Replaced TFace by MTFace:
This is the same struct, except that it does not contain color, that now
always stays separated in MCol. This was not a good design decision to
begin with, and it is needed for adding multiple color layers later. Note
that this does mean older Blender versions will not be able to read UV
coordinates from the next release, due to an SDNA limitation.
Removed DispListMesh:
This now fully replaced by DerivedMesh. To provide access to arrays of
vertices, edges and faces, like DispListMesh does. The semantics of the
DerivedMesh.getVertArray() and similar functions were changed to return
a pointer to an array if one exists, or otherwise allocate a temporary
one. On releasing the DerivedMesh, this temporary array will be removed
automatically.
Removed ssDM and meshDM DerivedMesh backends:
The ssDM backend was for DispListMesh, so that became obsolete automatically.
The meshDM backend was replaced by the custom data backend, that now figures
out which layers need to be modified, and only duplicates those.
This changes code in many places, and overall removes 2514 lines of code.
So, there's a good chance this might break some stuff, although I've been
testing it for a few days now. The good news is, adding multiple color and
uv layers should now become easy.
2006-11-20 04:28:02 +00:00
|
|
|
static int corner_indices[4] = {2, 3, 0, 1};
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
SWAP(int, mface->v1, mface->v3);
|
|
|
|
SWAP(int, mface->v2, mface->v4);
|
- convert all DerivedMesh map functions to use index based
mapping (instead of Edit{Vert,Edge,Face} pointers)
- dropped convertToDispListMeshMapped (whew, glad of it too)
- added DerivedMesh drawMappedFaces function
- dropped EM suffix for DerivedMesh functions, it was neither
particularly correct nor descriptive
- converted test_index_mface to test_index_face that also corrects
MCol and TFace. Good thing we had three versions of this routine,
you never know when one might burn down.
- removed flipnorm_mesh, not used anymore (and was incorrect to
boot)
- Getting face select to work with modifiers turned out to be much
more complicated than expected. Reworked mapping architecture for
modifiers - basically elements in a DispListMesh are now required
to be stored in an order that corresponds exactly to original
ordering. MVert/MEdge/MFace all have a new flag ME_XXX_STEPINDEX
that is set on each element that is set on the first derived element
of each original element. I can't say the code to follow these
requirements for subsurf is particularly transparent, but on the
upside it is a reasonably consistent and simple system that is memory
efficient and allows keeping the DispListMesh structure.
- rewrote mirror modifier to be simpler/conform to new requirements
for mapped DispListMesh structure. This also means that mirror interacts
much better with incremental subsurf calculation (it used to recalc
one entire side on any topology change, now it generally avoids that).
- added EM_{init,free}_index_arrays and EM_get_{vert,edge,face}_for_index
functions to handle mapping indices back into appropriate EditMesh
structures.
- bug fix, make edges didn't recalc object data
- bug fix, initial image assignment to TFace's didn't recalc object data
- new feature, added circle select support for FACESELECT
- bug fix, creating new faces in editmode duplicated the TFACE active
flag - but there should only be one active tface
- bug fix, possible crash when deleting all faces in faceselect mode
on mesh with tfaces...
Still todo: TFace edge drawing is still not always correct in face
mode, in particular with a mirror modifier when mesh has edges (and
no preceeding subsurf). Have not yet decided how to deal with this.
Best solution is probably to do switch to meshes all having MEdge's,
in which case I can get rid of TFace edge flags (and need to recalc
modifiers on tface selection change).
2005-08-20 03:08:23 +00:00
|
|
|
|
2006-11-20 19:03:37 +00:00
|
|
|
if(fdata)
|
|
|
|
CustomData_swap(fdata, mfindex, corner_indices);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Mesh *get_mesh(Object *ob)
|
|
|
|
{
|
|
|
|
|
|
|
|
if(ob==0) return 0;
|
|
|
|
if(ob->type==OB_MESH) return ob->data;
|
|
|
|
else return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_mesh(Object *ob, Mesh *me)
|
|
|
|
{
|
|
|
|
Mesh *old=0;
|
|
|
|
|
|
|
|
if(ob==0) return;
|
|
|
|
|
|
|
|
if(ob->type==OB_MESH) {
|
|
|
|
old= ob->data;
|
|
|
|
old->id.us--;
|
|
|
|
ob->data= me;
|
|
|
|
id_us_plus((ID *)me);
|
|
|
|
}
|
|
|
|
|
|
|
|
test_object_materials((ID *)me);
|
|
|
|
}
|
|
|
|
|
2004-07-08 20:38:27 +00:00
|
|
|
/* ************** make edges in a Mesh, for outside of editmode */
|
|
|
|
|
|
|
|
struct edgesort {
|
|
|
|
int v1, v2;
|
2005-09-22 17:00:58 +00:00
|
|
|
short is_loose, is_draw;
|
2004-07-08 20:38:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* edges have to be added with lowest index first for sorting */
|
2005-09-22 17:00:58 +00:00
|
|
|
static void to_edgesort(struct edgesort *ed, int v1, int v2, short is_loose, short is_draw)
|
2004-07-08 20:38:27 +00:00
|
|
|
{
|
|
|
|
if(v1<v2) {
|
|
|
|
ed->v1= v1; ed->v2= v2;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ed->v1= v2; ed->v2= v1;
|
|
|
|
}
|
2005-08-20 09:16:09 +00:00
|
|
|
ed->is_loose= is_loose;
|
2005-09-22 17:00:58 +00:00
|
|
|
ed->is_draw= is_draw;
|
2004-07-08 20:38:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int vergedgesort(const void *v1, const void *v2)
|
|
|
|
{
|
|
|
|
const struct edgesort *x1=v1, *x2=v2;
|
|
|
|
|
|
|
|
if( x1->v1 > x2->v1) return 1;
|
|
|
|
else if( x1->v1 < x2->v1) return -1;
|
|
|
|
else if( x1->v2 > x2->v2) return 1;
|
|
|
|
else if( x1->v2 < x2->v2) return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-09-22 17:52:41 +00:00
|
|
|
void make_edges(Mesh *me, int old)
|
2004-07-08 20:38:27 +00:00
|
|
|
{
|
|
|
|
MFace *mface;
|
|
|
|
MEdge *medge;
|
|
|
|
struct edgesort *edsort, *ed;
|
|
|
|
int a, totedge=0, final=0;
|
|
|
|
|
|
|
|
/* we put all edges in array, sort them, and detect doubles that way */
|
|
|
|
|
|
|
|
for(a= me->totface, mface= me->mface; a>0; a--, mface++) {
|
|
|
|
if(mface->v4) totedge+=4;
|
|
|
|
else if(mface->v3) totedge+=3;
|
|
|
|
else totedge+=1;
|
|
|
|
}
|
|
|
|
|
- added data arguments to deformer modifiers, in case someone wants
to write one that is based on geometry (and not just vertex position)
- added editmode versions of modifier deform/apply calls and flag
to tag modifiers that support editmode
- added isFinalCalc param to applyModifier, basically a switch to let
subsurf know if it is calc'ng orco or not (so it can deal with cache
appropriately). This is kinda hacky and perhaps I can come up with
a better solution (its also a waste to do a complete subdivide just
to get vertex locations).
- changed ccgsubsurf to not preallocate hash's to be approximately correct
size... this was probably not a big performance savings but means that
the order of faces returned by the iterator can vary after the first
call, this messes up orco calculation so dropped for time being.
- minor bug fix, meshes with only key didn't get vertex normals correctly
calc'd
- updated editmesh derivedmesh to support auxiliary locations
- changed mesh_calc_modifiers to alloc deformVerts on demand
- added editmesh_calc_modifiers for calculating editmesh cage and final
derivedmesh's
- bug fix, update shadedisplist to always calc colors (even if totvert==0)
- changed load_editMesh and make_edge to build me->medge even if totedge==0
(incremental subsurf checks this)
todo: add drawFacesTex for ccgderivedmesh
So, modifiers in editmode are back (which means auto-mirror
in edit mode works now) although still not finished. Currently
no cage is computed, the cage is always the base mesh (in
other words, Optimal edge style editing is off), and the final
mesh currently includes all modifiers that work in edit mode
(including lattice and curve). At some point there will be toggles
for which modifiers affect the final/cage editmode derivedmesh's.
Also, very nice new feature is that incremental subsurf in object
mode returns a ccgderivedmesh object instead of copying to a new
displistmesh. This can make a *huge* speed difference, and is very
nice for working with deformed armatures (esp. with only small
per frame changes).
2005-07-22 07:37:15 +00:00
|
|
|
if(totedge==0) {
|
Added custom vertex/edge/face data for meshes:
All data layers, including MVert/MEdge/MFace, are now managed as custom
data layers. The pointers like Mesh.mvert, Mesh.dvert or Mesh.mcol are
still used of course, but allocating, copying or freeing these arrays
should be done through the CustomData API.
Work in progress documentation on this is here:
http://mediawiki.blender.org/index.php/BlenderDev/BlenderArchitecture/CustomData
Replaced TFace by MTFace:
This is the same struct, except that it does not contain color, that now
always stays separated in MCol. This was not a good design decision to
begin with, and it is needed for adding multiple color layers later. Note
that this does mean older Blender versions will not be able to read UV
coordinates from the next release, due to an SDNA limitation.
Removed DispListMesh:
This now fully replaced by DerivedMesh. To provide access to arrays of
vertices, edges and faces, like DispListMesh does. The semantics of the
DerivedMesh.getVertArray() and similar functions were changed to return
a pointer to an array if one exists, or otherwise allocate a temporary
one. On releasing the DerivedMesh, this temporary array will be removed
automatically.
Removed ssDM and meshDM DerivedMesh backends:
The ssDM backend was for DispListMesh, so that became obsolete automatically.
The meshDM backend was replaced by the custom data backend, that now figures
out which layers need to be modified, and only duplicates those.
This changes code in many places, and overall removes 2514 lines of code.
So, there's a good chance this might break some stuff, although I've been
testing it for a few days now. The good news is, adding multiple color and
uv layers should now become easy.
2006-11-20 04:28:02 +00:00
|
|
|
/* flag that mesh has edges */
|
- added data arguments to deformer modifiers, in case someone wants
to write one that is based on geometry (and not just vertex position)
- added editmode versions of modifier deform/apply calls and flag
to tag modifiers that support editmode
- added isFinalCalc param to applyModifier, basically a switch to let
subsurf know if it is calc'ng orco or not (so it can deal with cache
appropriately). This is kinda hacky and perhaps I can come up with
a better solution (its also a waste to do a complete subdivide just
to get vertex locations).
- changed ccgsubsurf to not preallocate hash's to be approximately correct
size... this was probably not a big performance savings but means that
the order of faces returned by the iterator can vary after the first
call, this messes up orco calculation so dropped for time being.
- minor bug fix, meshes with only key didn't get vertex normals correctly
calc'd
- updated editmesh derivedmesh to support auxiliary locations
- changed mesh_calc_modifiers to alloc deformVerts on demand
- added editmesh_calc_modifiers for calculating editmesh cage and final
derivedmesh's
- bug fix, update shadedisplist to always calc colors (even if totvert==0)
- changed load_editMesh and make_edge to build me->medge even if totedge==0
(incremental subsurf checks this)
todo: add drawFacesTex for ccgderivedmesh
So, modifiers in editmode are back (which means auto-mirror
in edit mode works now) although still not finished. Currently
no cage is computed, the cage is always the base mesh (in
other words, Optimal edge style editing is off), and the final
mesh currently includes all modifiers that work in edit mode
(including lattice and curve). At some point there will be toggles
for which modifiers affect the final/cage editmode derivedmesh's.
Also, very nice new feature is that incremental subsurf in object
mode returns a ccgderivedmesh object instead of copying to a new
displistmesh. This can make a *huge* speed difference, and is very
nice for working with deformed armatures (esp. with only small
per frame changes).
2005-07-22 07:37:15 +00:00
|
|
|
me->medge = MEM_callocN(0, "make mesh edges");
|
|
|
|
me->totedge = 0;
|
|
|
|
return;
|
|
|
|
}
|
2004-07-08 20:38:27 +00:00
|
|
|
|
|
|
|
ed= edsort= MEM_mallocN(totedge*sizeof(struct edgesort), "edgesort");
|
|
|
|
|
|
|
|
for(a= me->totface, mface= me->mface; a>0; a--, mface++) {
|
2005-09-22 17:00:58 +00:00
|
|
|
to_edgesort(ed++, mface->v1, mface->v2, !mface->v3, mface->edcode & ME_V1V2);
|
2004-07-08 20:38:27 +00:00
|
|
|
if(mface->v4) {
|
2005-09-22 17:00:58 +00:00
|
|
|
to_edgesort(ed++, mface->v2, mface->v3, 0, mface->edcode & ME_V2V3);
|
|
|
|
to_edgesort(ed++, mface->v3, mface->v4, 0, mface->edcode & ME_V3V4);
|
|
|
|
to_edgesort(ed++, mface->v4, mface->v1, 0, mface->edcode & ME_V4V1);
|
2004-07-08 20:38:27 +00:00
|
|
|
}
|
|
|
|
else if(mface->v3) {
|
2005-09-22 17:00:58 +00:00
|
|
|
to_edgesort(ed++, mface->v2, mface->v3, 0, mface->edcode & ME_V2V3);
|
|
|
|
to_edgesort(ed++, mface->v3, mface->v1, 0, mface->edcode & ME_V3V1);
|
2004-07-08 20:38:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
qsort(edsort, totedge, sizeof(struct edgesort), vergedgesort);
|
|
|
|
|
|
|
|
/* count final amount */
|
|
|
|
for(a=totedge, ed=edsort; a>1; a--, ed++) {
|
|
|
|
/* edge is unique when it differs from next edge, or is last */
|
|
|
|
if(ed->v1 != (ed+1)->v1 || ed->v2 != (ed+1)->v2) final++;
|
|
|
|
}
|
|
|
|
final++;
|
|
|
|
|
Added custom vertex/edge/face data for meshes:
All data layers, including MVert/MEdge/MFace, are now managed as custom
data layers. The pointers like Mesh.mvert, Mesh.dvert or Mesh.mcol are
still used of course, but allocating, copying or freeing these arrays
should be done through the CustomData API.
Work in progress documentation on this is here:
http://mediawiki.blender.org/index.php/BlenderDev/BlenderArchitecture/CustomData
Replaced TFace by MTFace:
This is the same struct, except that it does not contain color, that now
always stays separated in MCol. This was not a good design decision to
begin with, and it is needed for adding multiple color layers later. Note
that this does mean older Blender versions will not be able to read UV
coordinates from the next release, due to an SDNA limitation.
Removed DispListMesh:
This now fully replaced by DerivedMesh. To provide access to arrays of
vertices, edges and faces, like DispListMesh does. The semantics of the
DerivedMesh.getVertArray() and similar functions were changed to return
a pointer to an array if one exists, or otherwise allocate a temporary
one. On releasing the DerivedMesh, this temporary array will be removed
automatically.
Removed ssDM and meshDM DerivedMesh backends:
The ssDM backend was for DispListMesh, so that became obsolete automatically.
The meshDM backend was replaced by the custom data backend, that now figures
out which layers need to be modified, and only duplicates those.
This changes code in many places, and overall removes 2514 lines of code.
So, there's a good chance this might break some stuff, although I've been
testing it for a few days now. The good news is, adding multiple color and
uv layers should now become easy.
2006-11-20 04:28:02 +00:00
|
|
|
|
2006-12-12 21:29:09 +00:00
|
|
|
medge= CustomData_add_layer(&me->edata, CD_MEDGE, CD_CALLOC, NULL, final);
|
|
|
|
me->medge= medge;
|
2004-07-08 20:38:27 +00:00
|
|
|
me->totedge= final;
|
|
|
|
|
|
|
|
for(a=totedge, ed=edsort; a>1; a--, ed++) {
|
|
|
|
/* edge is unique when it differs from next edge, or is last */
|
|
|
|
if(ed->v1 != (ed+1)->v1 || ed->v2 != (ed+1)->v2) {
|
|
|
|
medge->v1= ed->v1;
|
|
|
|
medge->v2= ed->v2;
|
2005-09-22 17:52:41 +00:00
|
|
|
if(old==0 || ed->is_draw) medge->flag= ME_EDGEDRAW|ME_EDGERENDER;
|
2005-08-20 09:16:09 +00:00
|
|
|
if(ed->is_loose) medge->flag|= ME_LOOSEEDGE;
|
2004-07-08 20:38:27 +00:00
|
|
|
medge++;
|
|
|
|
}
|
2005-09-22 17:00:58 +00:00
|
|
|
else {
|
|
|
|
/* equal edge, we merge the drawflag */
|
|
|
|
(ed+1)->is_draw |= ed->is_draw;
|
|
|
|
}
|
2004-07-08 20:38:27 +00:00
|
|
|
}
|
|
|
|
/* last edge */
|
|
|
|
medge->v1= ed->v1;
|
|
|
|
medge->v2= ed->v2;
|
2005-08-21 19:01:30 +00:00
|
|
|
medge->flag= ME_EDGEDRAW;
|
2005-08-20 09:16:09 +00:00
|
|
|
if(ed->is_loose) medge->flag|= ME_LOOSEEDGE;
|
2005-08-12 21:55:50 +00:00
|
|
|
medge->flag |= ME_EDGERENDER;
|
2004-07-08 20:38:27 +00:00
|
|
|
|
|
|
|
MEM_freeN(edsort);
|
- added mesh_strip_loose_faces, works in conjunction with make_edges
to get rid of faces with MFace.v3==0
- change all Mesh's to have ->medge now. This is forced by make_edges
on readfile, and in the various exotic important routines, and on
conversion back in python.
- make python NMesh structure always have medges now (needs testing)
- with above two changes it is guarenteed that mf->v3 is never ==0
in main blender code (i.e., all MFace's are actually triangles
or quads) and so I went through and removed all the historic tests
to deal with MFace.v3==0. Equals lots of deleting, I am in heaven!
- removed MEdge edcode flag, no longer needed
- added experimental replacement for edge flag system
Still are some inconsistencies in FACESELECT mode edge drawing to
be ironed out.
NOTE: This commit adds an experimental edge flag calc system, based
on 10-seconds-of-thought algorithm by yours truly. Would appreciate
feedback on how this system works, esp compared to old one and esp
on complex or interesting models.
To Use: New system is enabled by setting G.rt to a value between
1 and 1000 (Value of 0 uses old system). Value 1000 is reserved for
"auto" edge, which is more or less identical to old system but also
makes sure that at least 10% of edges are drawn (solves errors for
super subdivided meshes). Values between 1 and 999 act as percent
(out of 1000) of edges that should be drawn, starting with "most
interesting" edges first. Please try it and comment!
2005-08-21 07:19:20 +00:00
|
|
|
|
|
|
|
mesh_strip_loose_faces(me);
|
2004-07-08 20:38:27 +00:00
|
|
|
}
|
|
|
|
|
- added mesh_strip_loose_faces, works in conjunction with make_edges
to get rid of faces with MFace.v3==0
- change all Mesh's to have ->medge now. This is forced by make_edges
on readfile, and in the various exotic important routines, and on
conversion back in python.
- make python NMesh structure always have medges now (needs testing)
- with above two changes it is guarenteed that mf->v3 is never ==0
in main blender code (i.e., all MFace's are actually triangles
or quads) and so I went through and removed all the historic tests
to deal with MFace.v3==0. Equals lots of deleting, I am in heaven!
- removed MEdge edcode flag, no longer needed
- added experimental replacement for edge flag system
Still are some inconsistencies in FACESELECT mode edge drawing to
be ironed out.
NOTE: This commit adds an experimental edge flag calc system, based
on 10-seconds-of-thought algorithm by yours truly. Would appreciate
feedback on how this system works, esp compared to old one and esp
on complex or interesting models.
To Use: New system is enabled by setting G.rt to a value between
1 and 1000 (Value of 0 uses old system). Value 1000 is reserved for
"auto" edge, which is more or less identical to old system but also
makes sure that at least 10% of edges are drawn (solves errors for
super subdivided meshes). Values between 1 and 999 act as percent
(out of 1000) of edges that should be drawn, starting with "most
interesting" edges first. Please try it and comment!
2005-08-21 07:19:20 +00:00
|
|
|
void mesh_strip_loose_faces(Mesh *me)
|
|
|
|
{
|
|
|
|
int a,b;
|
|
|
|
|
|
|
|
for (a=b=0; a<me->totface; a++) {
|
2005-08-31 04:04:28 +00:00
|
|
|
if (me->mface[a].v3) {
|
- added mesh_strip_loose_faces, works in conjunction with make_edges
to get rid of faces with MFace.v3==0
- change all Mesh's to have ->medge now. This is forced by make_edges
on readfile, and in the various exotic important routines, and on
conversion back in python.
- make python NMesh structure always have medges now (needs testing)
- with above two changes it is guarenteed that mf->v3 is never ==0
in main blender code (i.e., all MFace's are actually triangles
or quads) and so I went through and removed all the historic tests
to deal with MFace.v3==0. Equals lots of deleting, I am in heaven!
- removed MEdge edcode flag, no longer needed
- added experimental replacement for edge flag system
Still are some inconsistencies in FACESELECT mode edge drawing to
be ironed out.
NOTE: This commit adds an experimental edge flag calc system, based
on 10-seconds-of-thought algorithm by yours truly. Would appreciate
feedback on how this system works, esp compared to old one and esp
on complex or interesting models.
To Use: New system is enabled by setting G.rt to a value between
1 and 1000 (Value of 0 uses old system). Value 1000 is reserved for
"auto" edge, which is more or less identical to old system but also
makes sure that at least 10% of edges are drawn (solves errors for
super subdivided meshes). Values between 1 and 999 act as percent
(out of 1000) of edges that should be drawn, starting with "most
interesting" edges first. Please try it and comment!
2005-08-21 07:19:20 +00:00
|
|
|
if (a!=b) {
|
|
|
|
memcpy(&me->mface[b],&me->mface[a],sizeof(me->mface[b]));
|
Added custom vertex/edge/face data for meshes:
All data layers, including MVert/MEdge/MFace, are now managed as custom
data layers. The pointers like Mesh.mvert, Mesh.dvert or Mesh.mcol are
still used of course, but allocating, copying or freeing these arrays
should be done through the CustomData API.
Work in progress documentation on this is here:
http://mediawiki.blender.org/index.php/BlenderDev/BlenderArchitecture/CustomData
Replaced TFace by MTFace:
This is the same struct, except that it does not contain color, that now
always stays separated in MCol. This was not a good design decision to
begin with, and it is needed for adding multiple color layers later. Note
that this does mean older Blender versions will not be able to read UV
coordinates from the next release, due to an SDNA limitation.
Removed DispListMesh:
This now fully replaced by DerivedMesh. To provide access to arrays of
vertices, edges and faces, like DispListMesh does. The semantics of the
DerivedMesh.getVertArray() and similar functions were changed to return
a pointer to an array if one exists, or otherwise allocate a temporary
one. On releasing the DerivedMesh, this temporary array will be removed
automatically.
Removed ssDM and meshDM DerivedMesh backends:
The ssDM backend was for DispListMesh, so that became obsolete automatically.
The meshDM backend was replaced by the custom data backend, that now figures
out which layers need to be modified, and only duplicates those.
This changes code in many places, and overall removes 2514 lines of code.
So, there's a good chance this might break some stuff, although I've been
testing it for a few days now. The good news is, adding multiple color and
uv layers should now become easy.
2006-11-20 04:28:02 +00:00
|
|
|
CustomData_copy_data(&me->fdata, &me->fdata, a, b, 1);
|
|
|
|
CustomData_free_elem(&me->fdata, a, 1);
|
- added mesh_strip_loose_faces, works in conjunction with make_edges
to get rid of faces with MFace.v3==0
- change all Mesh's to have ->medge now. This is forced by make_edges
on readfile, and in the various exotic important routines, and on
conversion back in python.
- make python NMesh structure always have medges now (needs testing)
- with above two changes it is guarenteed that mf->v3 is never ==0
in main blender code (i.e., all MFace's are actually triangles
or quads) and so I went through and removed all the historic tests
to deal with MFace.v3==0. Equals lots of deleting, I am in heaven!
- removed MEdge edcode flag, no longer needed
- added experimental replacement for edge flag system
Still are some inconsistencies in FACESELECT mode edge drawing to
be ironed out.
NOTE: This commit adds an experimental edge flag calc system, based
on 10-seconds-of-thought algorithm by yours truly. Would appreciate
feedback on how this system works, esp compared to old one and esp
on complex or interesting models.
To Use: New system is enabled by setting G.rt to a value between
1 and 1000 (Value of 0 uses old system). Value 1000 is reserved for
"auto" edge, which is more or less identical to old system but also
makes sure that at least 10% of edges are drawn (solves errors for
super subdivided meshes). Values between 1 and 999 act as percent
(out of 1000) of edges that should be drawn, starting with "most
interesting" edges first. Please try it and comment!
2005-08-21 07:19:20 +00:00
|
|
|
}
|
|
|
|
b++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
me->totface = b;
|
|
|
|
}
|
2004-07-08 20:38:27 +00:00
|
|
|
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
void mball_to_mesh(ListBase *lb, Mesh *me)
|
|
|
|
{
|
|
|
|
DispList *dl;
|
|
|
|
MVert *mvert;
|
|
|
|
MFace *mface;
|
|
|
|
float *nors, *verts;
|
|
|
|
int a, *index;
|
|
|
|
|
|
|
|
dl= lb->first;
|
|
|
|
if(dl==0) return;
|
|
|
|
|
|
|
|
if(dl->type==DL_INDEX4) {
|
|
|
|
me->flag= ME_NOPUNOFLIP;
|
|
|
|
me->totvert= dl->nr;
|
|
|
|
me->totface= dl->parts;
|
|
|
|
|
2006-12-12 21:29:09 +00:00
|
|
|
mvert= CustomData_add_layer(&me->vdata, CD_MVERT, CD_CALLOC, NULL, dl->nr);
|
|
|
|
mface= CustomData_add_layer(&me->fdata, CD_MFACE, CD_CALLOC, NULL, dl->parts);
|
Added custom vertex/edge/face data for meshes:
All data layers, including MVert/MEdge/MFace, are now managed as custom
data layers. The pointers like Mesh.mvert, Mesh.dvert or Mesh.mcol are
still used of course, but allocating, copying or freeing these arrays
should be done through the CustomData API.
Work in progress documentation on this is here:
http://mediawiki.blender.org/index.php/BlenderDev/BlenderArchitecture/CustomData
Replaced TFace by MTFace:
This is the same struct, except that it does not contain color, that now
always stays separated in MCol. This was not a good design decision to
begin with, and it is needed for adding multiple color layers later. Note
that this does mean older Blender versions will not be able to read UV
coordinates from the next release, due to an SDNA limitation.
Removed DispListMesh:
This now fully replaced by DerivedMesh. To provide access to arrays of
vertices, edges and faces, like DispListMesh does. The semantics of the
DerivedMesh.getVertArray() and similar functions were changed to return
a pointer to an array if one exists, or otherwise allocate a temporary
one. On releasing the DerivedMesh, this temporary array will be removed
automatically.
Removed ssDM and meshDM DerivedMesh backends:
The ssDM backend was for DispListMesh, so that became obsolete automatically.
The meshDM backend was replaced by the custom data backend, that now figures
out which layers need to be modified, and only duplicates those.
This changes code in many places, and overall removes 2514 lines of code.
So, there's a good chance this might break some stuff, although I've been
testing it for a few days now. The good news is, adding multiple color and
uv layers should now become easy.
2006-11-20 04:28:02 +00:00
|
|
|
me->mvert= mvert;
|
|
|
|
me->mface= mface;
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
a= dl->nr;
|
|
|
|
nors= dl->nors;
|
|
|
|
verts= dl->verts;
|
|
|
|
while(a--) {
|
|
|
|
VECCOPY(mvert->co, verts);
|
|
|
|
mvert->no[0]= (short int)(nors[0]*32767.0);
|
|
|
|
mvert->no[1]= (short int)(nors[1]*32767.0);
|
|
|
|
mvert->no[2]= (short int)(nors[2]*32767.0);
|
|
|
|
mvert++;
|
|
|
|
nors+= 3;
|
|
|
|
verts+= 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
a= dl->parts;
|
|
|
|
index= dl->index;
|
|
|
|
while(a--) {
|
|
|
|
mface->v1= index[0];
|
|
|
|
mface->v2= index[1];
|
|
|
|
mface->v3= index[2];
|
|
|
|
mface->v4= index[3];
|
2006-11-23 00:26:39 +00:00
|
|
|
mface->flag= ME_SMOOTH;
|
|
|
|
|
|
|
|
if(mface->v3==mface->v4)
|
|
|
|
mface->v4= 0;
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
mface++;
|
|
|
|
index+= 4;
|
|
|
|
}
|
Added custom vertex/edge/face data for meshes:
All data layers, including MVert/MEdge/MFace, are now managed as custom
data layers. The pointers like Mesh.mvert, Mesh.dvert or Mesh.mcol are
still used of course, but allocating, copying or freeing these arrays
should be done through the CustomData API.
Work in progress documentation on this is here:
http://mediawiki.blender.org/index.php/BlenderDev/BlenderArchitecture/CustomData
Replaced TFace by MTFace:
This is the same struct, except that it does not contain color, that now
always stays separated in MCol. This was not a good design decision to
begin with, and it is needed for adding multiple color layers later. Note
that this does mean older Blender versions will not be able to read UV
coordinates from the next release, due to an SDNA limitation.
Removed DispListMesh:
This now fully replaced by DerivedMesh. To provide access to arrays of
vertices, edges and faces, like DispListMesh does. The semantics of the
DerivedMesh.getVertArray() and similar functions were changed to return
a pointer to an array if one exists, or otherwise allocate a temporary
one. On releasing the DerivedMesh, this temporary array will be removed
automatically.
Removed ssDM and meshDM DerivedMesh backends:
The ssDM backend was for DispListMesh, so that became obsolete automatically.
The meshDM backend was replaced by the custom data backend, that now figures
out which layers need to be modified, and only duplicates those.
This changes code in many places, and overall removes 2514 lines of code.
So, there's a good chance this might break some stuff, although I've been
testing it for a few days now. The good news is, adding multiple color and
uv layers should now become easy.
2006-11-20 04:28:02 +00:00
|
|
|
|
|
|
|
make_edges(me, 0); // all edges
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-28 16:49:48 +00:00
|
|
|
/* this may fail replacing ob->data, be sure to check ob->type */
|
2002-10-12 11:37:38 +00:00
|
|
|
void nurbs_to_mesh(Object *ob)
|
|
|
|
{
|
|
|
|
Object *ob1;
|
|
|
|
DispList *dl;
|
|
|
|
Mesh *me;
|
|
|
|
Curve *cu;
|
|
|
|
MVert *mvert;
|
|
|
|
MFace *mface;
|
|
|
|
float *data;
|
|
|
|
int a, b, ofs, vertcount, startvert, totvert=0, totvlak=0;
|
|
|
|
int p1, p2, p3, p4, *index;
|
|
|
|
|
|
|
|
cu= ob->data;
|
|
|
|
|
2003-04-26 13:07:59 +00:00
|
|
|
/* count */
|
2002-10-12 11:37:38 +00:00
|
|
|
dl= cu->disp.first;
|
|
|
|
while(dl) {
|
|
|
|
if(dl->type==DL_SEGM) {
|
|
|
|
totvert+= dl->parts*dl->nr;
|
|
|
|
totvlak+= dl->parts*(dl->nr-1);
|
|
|
|
}
|
|
|
|
else if(dl->type==DL_POLY) {
|
|
|
|
/* cyclic polys are filled. except when 3D */
|
|
|
|
if(cu->flag & CU_3D) {
|
|
|
|
totvert+= dl->parts*dl->nr;
|
|
|
|
totvlak+= dl->parts*dl->nr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(dl->type==DL_SURF) {
|
|
|
|
totvert+= dl->parts*dl->nr;
|
2005-08-11 22:27:53 +00:00
|
|
|
totvlak+= (dl->parts-1+((dl->flag & DL_CYCL_V)==2))*(dl->nr-1+(dl->flag & DL_CYCL_U));
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
else if(dl->type==DL_INDEX3) {
|
|
|
|
totvert+= dl->nr;
|
|
|
|
totvlak+= dl->parts;
|
|
|
|
}
|
|
|
|
dl= dl->next;
|
|
|
|
}
|
|
|
|
if(totvert==0) {
|
2007-05-28 16:49:48 +00:00
|
|
|
/* error("can't convert"); */
|
|
|
|
/* Make Sure you check ob->data is a curve */
|
2002-10-12 11:37:38 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-04-26 13:07:59 +00:00
|
|
|
/* make mesh */
|
2007-03-11 16:25:17 +00:00
|
|
|
me= add_mesh("Mesh");
|
2002-10-12 11:37:38 +00:00
|
|
|
me->totvert= totvert;
|
|
|
|
me->totface= totvlak;
|
|
|
|
|
|
|
|
me->totcol= cu->totcol;
|
|
|
|
me->mat= cu->mat;
|
|
|
|
cu->mat= 0;
|
|
|
|
cu->totcol= 0;
|
|
|
|
|
2006-12-12 21:29:09 +00:00
|
|
|
mvert= CustomData_add_layer(&me->vdata, CD_MVERT, CD_CALLOC, NULL, me->totvert);
|
|
|
|
mface= CustomData_add_layer(&me->fdata, CD_MFACE, CD_CALLOC, NULL, me->totface);
|
Added custom vertex/edge/face data for meshes:
All data layers, including MVert/MEdge/MFace, are now managed as custom
data layers. The pointers like Mesh.mvert, Mesh.dvert or Mesh.mcol are
still used of course, but allocating, copying or freeing these arrays
should be done through the CustomData API.
Work in progress documentation on this is here:
http://mediawiki.blender.org/index.php/BlenderDev/BlenderArchitecture/CustomData
Replaced TFace by MTFace:
This is the same struct, except that it does not contain color, that now
always stays separated in MCol. This was not a good design decision to
begin with, and it is needed for adding multiple color layers later. Note
that this does mean older Blender versions will not be able to read UV
coordinates from the next release, due to an SDNA limitation.
Removed DispListMesh:
This now fully replaced by DerivedMesh. To provide access to arrays of
vertices, edges and faces, like DispListMesh does. The semantics of the
DerivedMesh.getVertArray() and similar functions were changed to return
a pointer to an array if one exists, or otherwise allocate a temporary
one. On releasing the DerivedMesh, this temporary array will be removed
automatically.
Removed ssDM and meshDM DerivedMesh backends:
The ssDM backend was for DispListMesh, so that became obsolete automatically.
The meshDM backend was replaced by the custom data backend, that now figures
out which layers need to be modified, and only duplicates those.
This changes code in many places, and overall removes 2514 lines of code.
So, there's a good chance this might break some stuff, although I've been
testing it for a few days now. The good news is, adding multiple color and
uv layers should now become easy.
2006-11-20 04:28:02 +00:00
|
|
|
me->mvert= mvert;
|
|
|
|
me->mface= mface;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2003-04-26 13:07:59 +00:00
|
|
|
/* verts and faces */
|
2002-10-12 11:37:38 +00:00
|
|
|
vertcount= 0;
|
|
|
|
|
|
|
|
dl= cu->disp.first;
|
|
|
|
while(dl) {
|
|
|
|
if(dl->type==DL_SEGM) {
|
|
|
|
startvert= vertcount;
|
|
|
|
a= dl->parts*dl->nr;
|
|
|
|
data= dl->verts;
|
|
|
|
while(a--) {
|
|
|
|
VECCOPY(mvert->co, data);
|
|
|
|
data+=3;
|
|
|
|
vertcount++;
|
|
|
|
mvert++;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(a=0; a<dl->parts; a++) {
|
|
|
|
ofs= a*dl->nr;
|
|
|
|
for(b=1; b<dl->nr; b++) {
|
|
|
|
mface->v1= startvert+ofs+b-1;
|
|
|
|
mface->v2= startvert+ofs+b;
|
|
|
|
mface++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else if(dl->type==DL_POLY) {
|
2003-11-08 13:36:16 +00:00
|
|
|
/* 3d polys are not filled */
|
|
|
|
if(cu->flag & CU_3D) {
|
|
|
|
startvert= vertcount;
|
|
|
|
a= dl->parts*dl->nr;
|
|
|
|
data= dl->verts;
|
|
|
|
while(a--) {
|
|
|
|
VECCOPY(mvert->co, data);
|
|
|
|
data+=3;
|
|
|
|
vertcount++;
|
|
|
|
mvert++;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(a=0; a<dl->parts; a++) {
|
|
|
|
ofs= a*dl->nr;
|
|
|
|
for(b=0; b<dl->nr; b++) {
|
|
|
|
mface->v1= startvert+ofs+b;
|
|
|
|
if(b==dl->nr-1) mface->v2= startvert+ofs;
|
|
|
|
else mface->v2= startvert+ofs+b+1;
|
|
|
|
mface++;
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(dl->type==DL_INDEX3) {
|
|
|
|
startvert= vertcount;
|
|
|
|
a= dl->nr;
|
|
|
|
data= dl->verts;
|
|
|
|
while(a--) {
|
|
|
|
VECCOPY(mvert->co, data);
|
|
|
|
data+=3;
|
|
|
|
vertcount++;
|
|
|
|
mvert++;
|
|
|
|
}
|
|
|
|
|
|
|
|
a= dl->parts;
|
|
|
|
index= dl->index;
|
|
|
|
while(a--) {
|
|
|
|
mface->v1= startvert+index[0];
|
2007-10-23 00:02:29 +00:00
|
|
|
mface->v2= startvert+index[2];
|
|
|
|
mface->v3= startvert+index[1];
|
2002-10-12 11:37:38 +00:00
|
|
|
mface->v4= 0;
|
Added custom vertex/edge/face data for meshes:
All data layers, including MVert/MEdge/MFace, are now managed as custom
data layers. The pointers like Mesh.mvert, Mesh.dvert or Mesh.mcol are
still used of course, but allocating, copying or freeing these arrays
should be done through the CustomData API.
Work in progress documentation on this is here:
http://mediawiki.blender.org/index.php/BlenderDev/BlenderArchitecture/CustomData
Replaced TFace by MTFace:
This is the same struct, except that it does not contain color, that now
always stays separated in MCol. This was not a good design decision to
begin with, and it is needed for adding multiple color layers later. Note
that this does mean older Blender versions will not be able to read UV
coordinates from the next release, due to an SDNA limitation.
Removed DispListMesh:
This now fully replaced by DerivedMesh. To provide access to arrays of
vertices, edges and faces, like DispListMesh does. The semantics of the
DerivedMesh.getVertArray() and similar functions were changed to return
a pointer to an array if one exists, or otherwise allocate a temporary
one. On releasing the DerivedMesh, this temporary array will be removed
automatically.
Removed ssDM and meshDM DerivedMesh backends:
The ssDM backend was for DispListMesh, so that became obsolete automatically.
The meshDM backend was replaced by the custom data backend, that now figures
out which layers need to be modified, and only duplicates those.
This changes code in many places, and overall removes 2514 lines of code.
So, there's a good chance this might break some stuff, although I've been
testing it for a few days now. The good news is, adding multiple color and
uv layers should now become easy.
2006-11-20 04:28:02 +00:00
|
|
|
test_index_face(mface, NULL, 0, 3);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
mface++;
|
|
|
|
index+= 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
else if(dl->type==DL_SURF) {
|
|
|
|
startvert= vertcount;
|
|
|
|
a= dl->parts*dl->nr;
|
|
|
|
data= dl->verts;
|
|
|
|
while(a--) {
|
|
|
|
VECCOPY(mvert->co, data);
|
|
|
|
data+=3;
|
|
|
|
vertcount++;
|
|
|
|
mvert++;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(a=0; a<dl->parts; a++) {
|
|
|
|
|
2005-08-11 22:27:53 +00:00
|
|
|
if( (dl->flag & DL_CYCL_V)==0 && a==dl->parts-1) break;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2005-08-11 22:27:53 +00:00
|
|
|
if(dl->flag & DL_CYCL_U) { /* p2 -> p1 -> */
|
2002-10-12 11:37:38 +00:00
|
|
|
p1= startvert+ dl->nr*a; /* p4 -> p3 -> */
|
2003-04-26 13:07:59 +00:00
|
|
|
p2= p1+ dl->nr-1; /* -----> next row */
|
2002-10-12 11:37:38 +00:00
|
|
|
p3= p1+ dl->nr;
|
|
|
|
p4= p2+ dl->nr;
|
|
|
|
b= 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
p2= startvert+ dl->nr*a;
|
|
|
|
p1= p2+1;
|
|
|
|
p4= p2+ dl->nr;
|
|
|
|
p3= p1+ dl->nr;
|
|
|
|
b= 1;
|
|
|
|
}
|
2005-08-11 22:27:53 +00:00
|
|
|
if( (dl->flag & DL_CYCL_V) && a==dl->parts-1) {
|
2002-10-12 11:37:38 +00:00
|
|
|
p3-= dl->parts*dl->nr;
|
|
|
|
p4-= dl->parts*dl->nr;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(; b<dl->nr; b++) {
|
|
|
|
mface->v1= p1;
|
|
|
|
mface->v2= p3;
|
|
|
|
mface->v3= p4;
|
|
|
|
mface->v4= p2;
|
|
|
|
mface->mat_nr= (unsigned char)dl->col;
|
Added custom vertex/edge/face data for meshes:
All data layers, including MVert/MEdge/MFace, are now managed as custom
data layers. The pointers like Mesh.mvert, Mesh.dvert or Mesh.mcol are
still used of course, but allocating, copying or freeing these arrays
should be done through the CustomData API.
Work in progress documentation on this is here:
http://mediawiki.blender.org/index.php/BlenderDev/BlenderArchitecture/CustomData
Replaced TFace by MTFace:
This is the same struct, except that it does not contain color, that now
always stays separated in MCol. This was not a good design decision to
begin with, and it is needed for adding multiple color layers later. Note
that this does mean older Blender versions will not be able to read UV
coordinates from the next release, due to an SDNA limitation.
Removed DispListMesh:
This now fully replaced by DerivedMesh. To provide access to arrays of
vertices, edges and faces, like DispListMesh does. The semantics of the
DerivedMesh.getVertArray() and similar functions were changed to return
a pointer to an array if one exists, or otherwise allocate a temporary
one. On releasing the DerivedMesh, this temporary array will be removed
automatically.
Removed ssDM and meshDM DerivedMesh backends:
The ssDM backend was for DispListMesh, so that became obsolete automatically.
The meshDM backend was replaced by the custom data backend, that now figures
out which layers need to be modified, and only duplicates those.
This changes code in many places, and overall removes 2514 lines of code.
So, there's a good chance this might break some stuff, although I've been
testing it for a few days now. The good news is, adding multiple color and
uv layers should now become easy.
2006-11-20 04:28:02 +00:00
|
|
|
test_index_face(mface, NULL, 0, 4);
|
2002-10-12 11:37:38 +00:00
|
|
|
mface++;
|
|
|
|
|
|
|
|
p4= p3;
|
|
|
|
p3++;
|
|
|
|
p2= p1;
|
|
|
|
p1++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
dl= dl->next;
|
|
|
|
}
|
|
|
|
|
2005-09-22 17:52:41 +00:00
|
|
|
make_edges(me, 0); // all edges
|
Added custom vertex/edge/face data for meshes:
All data layers, including MVert/MEdge/MFace, are now managed as custom
data layers. The pointers like Mesh.mvert, Mesh.dvert or Mesh.mcol are
still used of course, but allocating, copying or freeing these arrays
should be done through the CustomData API.
Work in progress documentation on this is here:
http://mediawiki.blender.org/index.php/BlenderDev/BlenderArchitecture/CustomData
Replaced TFace by MTFace:
This is the same struct, except that it does not contain color, that now
always stays separated in MCol. This was not a good design decision to
begin with, and it is needed for adding multiple color layers later. Note
that this does mean older Blender versions will not be able to read UV
coordinates from the next release, due to an SDNA limitation.
Removed DispListMesh:
This now fully replaced by DerivedMesh. To provide access to arrays of
vertices, edges and faces, like DispListMesh does. The semantics of the
DerivedMesh.getVertArray() and similar functions were changed to return
a pointer to an array if one exists, or otherwise allocate a temporary
one. On releasing the DerivedMesh, this temporary array will be removed
automatically.
Removed ssDM and meshDM DerivedMesh backends:
The ssDM backend was for DispListMesh, so that became obsolete automatically.
The meshDM backend was replaced by the custom data backend, that now figures
out which layers need to be modified, and only duplicates those.
This changes code in many places, and overall removes 2514 lines of code.
So, there's a good chance this might break some stuff, although I've been
testing it for a few days now. The good news is, adding multiple color and
uv layers should now become easy.
2006-11-20 04:28:02 +00:00
|
|
|
mesh_calc_normals(me->mvert, me->totvert, me->mface, me->totface, NULL);
|
- added mesh_strip_loose_faces, works in conjunction with make_edges
to get rid of faces with MFace.v3==0
- change all Mesh's to have ->medge now. This is forced by make_edges
on readfile, and in the various exotic important routines, and on
conversion back in python.
- make python NMesh structure always have medges now (needs testing)
- with above two changes it is guarenteed that mf->v3 is never ==0
in main blender code (i.e., all MFace's are actually triangles
or quads) and so I went through and removed all the historic tests
to deal with MFace.v3==0. Equals lots of deleting, I am in heaven!
- removed MEdge edcode flag, no longer needed
- added experimental replacement for edge flag system
Still are some inconsistencies in FACESELECT mode edge drawing to
be ironed out.
NOTE: This commit adds an experimental edge flag calc system, based
on 10-seconds-of-thought algorithm by yours truly. Would appreciate
feedback on how this system works, esp compared to old one and esp
on complex or interesting models.
To Use: New system is enabled by setting G.rt to a value between
1 and 1000 (Value of 0 uses old system). Value 1000 is reserved for
"auto" edge, which is more or less identical to old system but also
makes sure that at least 10% of edges are drawn (solves errors for
super subdivided meshes). Values between 1 and 999 act as percent
(out of 1000) of edges that should be drawn, starting with "most
interesting" edges first. Please try it and comment!
2005-08-21 07:19:20 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
if(ob->data) {
|
|
|
|
free_libblock(&G.main->curve, ob->data);
|
|
|
|
}
|
|
|
|
ob->data= me;
|
|
|
|
ob->type= OB_MESH;
|
|
|
|
|
2003-04-26 13:07:59 +00:00
|
|
|
/* other users */
|
2002-10-12 11:37:38 +00:00
|
|
|
ob1= G.main->object.first;
|
|
|
|
while(ob1) {
|
|
|
|
if(ob1->data==cu) {
|
|
|
|
ob1->type= OB_MESH;
|
|
|
|
|
|
|
|
ob1->data= ob->data;
|
|
|
|
id_us_plus((ID *)ob->data);
|
|
|
|
}
|
|
|
|
ob1= ob1->id.next;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2004-03-20 23:59:57 +00:00
|
|
|
void mesh_delete_material_index(Mesh *me, int index) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=0; i<me->totface; i++) {
|
|
|
|
MFace *mf = &((MFace*) me->mface)[i];
|
|
|
|
if (mf->mat_nr && mf->mat_nr>=index)
|
|
|
|
mf->mat_nr--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-07-14 15:48:01 +00:00
|
|
|
void mesh_set_smooth_flag(Object *meshOb, int enableSmooth) {
|
|
|
|
Mesh *me = meshOb->data;
|
2004-03-20 23:59:57 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=0; i<me->totface; i++) {
|
|
|
|
MFace *mf = &((MFace*) me->mface)[i];
|
|
|
|
|
|
|
|
if (enableSmooth) {
|
|
|
|
mf->flag |= ME_SMOOTH;
|
|
|
|
} else {
|
|
|
|
mf->flag &= ~ME_SMOOTH;
|
|
|
|
}
|
|
|
|
}
|
2005-07-14 15:48:01 +00:00
|
|
|
|
2005-07-14 17:10:44 +00:00
|
|
|
DAG_object_flush_update(G.scene, meshOb, OB_RECALC_DATA);
|
2004-03-20 23:59:57 +00:00
|
|
|
}
|
2005-07-17 21:24:43 +00:00
|
|
|
|
|
|
|
void mesh_calc_normals(MVert *mverts, int numVerts, MFace *mfaces, int numFaces, float **faceNors_r)
|
|
|
|
{
|
|
|
|
float (*tnorms)[3]= MEM_callocN(numVerts*sizeof(*tnorms), "tnorms");
|
|
|
|
float *fnors= MEM_mallocN(sizeof(*fnors)*3*numFaces, "meshnormals");
|
|
|
|
int i;
|
Added custom vertex/edge/face data for meshes:
All data layers, including MVert/MEdge/MFace, are now managed as custom
data layers. The pointers like Mesh.mvert, Mesh.dvert or Mesh.mcol are
still used of course, but allocating, copying or freeing these arrays
should be done through the CustomData API.
Work in progress documentation on this is here:
http://mediawiki.blender.org/index.php/BlenderDev/BlenderArchitecture/CustomData
Replaced TFace by MTFace:
This is the same struct, except that it does not contain color, that now
always stays separated in MCol. This was not a good design decision to
begin with, and it is needed for adding multiple color layers later. Note
that this does mean older Blender versions will not be able to read UV
coordinates from the next release, due to an SDNA limitation.
Removed DispListMesh:
This now fully replaced by DerivedMesh. To provide access to arrays of
vertices, edges and faces, like DispListMesh does. The semantics of the
DerivedMesh.getVertArray() and similar functions were changed to return
a pointer to an array if one exists, or otherwise allocate a temporary
one. On releasing the DerivedMesh, this temporary array will be removed
automatically.
Removed ssDM and meshDM DerivedMesh backends:
The ssDM backend was for DispListMesh, so that became obsolete automatically.
The meshDM backend was replaced by the custom data backend, that now figures
out which layers need to be modified, and only duplicates those.
This changes code in many places, and overall removes 2514 lines of code.
So, there's a good chance this might break some stuff, although I've been
testing it for a few days now. The good news is, adding multiple color and
uv layers should now become easy.
2006-11-20 04:28:02 +00:00
|
|
|
|
2005-07-17 21:24:43 +00:00
|
|
|
for (i=0; i<numFaces; i++) {
|
|
|
|
MFace *mf= &mfaces[i];
|
- added mesh_strip_loose_faces, works in conjunction with make_edges
to get rid of faces with MFace.v3==0
- change all Mesh's to have ->medge now. This is forced by make_edges
on readfile, and in the various exotic important routines, and on
conversion back in python.
- make python NMesh structure always have medges now (needs testing)
- with above two changes it is guarenteed that mf->v3 is never ==0
in main blender code (i.e., all MFace's are actually triangles
or quads) and so I went through and removed all the historic tests
to deal with MFace.v3==0. Equals lots of deleting, I am in heaven!
- removed MEdge edcode flag, no longer needed
- added experimental replacement for edge flag system
Still are some inconsistencies in FACESELECT mode edge drawing to
be ironed out.
NOTE: This commit adds an experimental edge flag calc system, based
on 10-seconds-of-thought algorithm by yours truly. Would appreciate
feedback on how this system works, esp compared to old one and esp
on complex or interesting models.
To Use: New system is enabled by setting G.rt to a value between
1 and 1000 (Value of 0 uses old system). Value 1000 is reserved for
"auto" edge, which is more or less identical to old system but also
makes sure that at least 10% of edges are drawn (solves errors for
super subdivided meshes). Values between 1 and 999 act as percent
(out of 1000) of edges that should be drawn, starting with "most
interesting" edges first. Please try it and comment!
2005-08-21 07:19:20 +00:00
|
|
|
float *f_no= &fnors[i*3];
|
2005-07-17 21:24:43 +00:00
|
|
|
|
- added mesh_strip_loose_faces, works in conjunction with make_edges
to get rid of faces with MFace.v3==0
- change all Mesh's to have ->medge now. This is forced by make_edges
on readfile, and in the various exotic important routines, and on
conversion back in python.
- make python NMesh structure always have medges now (needs testing)
- with above two changes it is guarenteed that mf->v3 is never ==0
in main blender code (i.e., all MFace's are actually triangles
or quads) and so I went through and removed all the historic tests
to deal with MFace.v3==0. Equals lots of deleting, I am in heaven!
- removed MEdge edcode flag, no longer needed
- added experimental replacement for edge flag system
Still are some inconsistencies in FACESELECT mode edge drawing to
be ironed out.
NOTE: This commit adds an experimental edge flag calc system, based
on 10-seconds-of-thought algorithm by yours truly. Would appreciate
feedback on how this system works, esp compared to old one and esp
on complex or interesting models.
To Use: New system is enabled by setting G.rt to a value between
1 and 1000 (Value of 0 uses old system). Value 1000 is reserved for
"auto" edge, which is more or less identical to old system but also
makes sure that at least 10% of edges are drawn (solves errors for
super subdivided meshes). Values between 1 and 999 act as percent
(out of 1000) of edges that should be drawn, starting with "most
interesting" edges first. Please try it and comment!
2005-08-21 07:19:20 +00:00
|
|
|
if (mf->v4)
|
|
|
|
CalcNormFloat4(mverts[mf->v1].co, mverts[mf->v2].co, mverts[mf->v3].co, mverts[mf->v4].co, f_no);
|
|
|
|
else
|
|
|
|
CalcNormFloat(mverts[mf->v1].co, mverts[mf->v2].co, mverts[mf->v3].co, f_no);
|
|
|
|
|
|
|
|
VecAddf(tnorms[mf->v1], tnorms[mf->v1], f_no);
|
|
|
|
VecAddf(tnorms[mf->v2], tnorms[mf->v2], f_no);
|
|
|
|
VecAddf(tnorms[mf->v3], tnorms[mf->v3], f_no);
|
|
|
|
if (mf->v4)
|
|
|
|
VecAddf(tnorms[mf->v4], tnorms[mf->v4], f_no);
|
2005-07-17 21:24:43 +00:00
|
|
|
}
|
|
|
|
for (i=0; i<numVerts; i++) {
|
|
|
|
MVert *mv= &mverts[i];
|
|
|
|
float *no= tnorms[i];
|
|
|
|
|
2007-04-04 13:18:41 +00:00
|
|
|
if (Normalize(no)==0.0) {
|
2005-07-23 19:03:43 +00:00
|
|
|
VECCOPY(no, mv->co);
|
2007-04-04 13:18:41 +00:00
|
|
|
Normalize(no);
|
2005-07-23 19:03:43 +00:00
|
|
|
}
|
|
|
|
|
2005-07-17 21:24:43 +00:00
|
|
|
mv->no[0]= (short)(no[0]*32767.0);
|
|
|
|
mv->no[1]= (short)(no[1]*32767.0);
|
|
|
|
mv->no[2]= (short)(no[2]*32767.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
MEM_freeN(tnorms);
|
|
|
|
|
|
|
|
if (faceNors_r) {
|
|
|
|
*faceNors_r = fnors;
|
|
|
|
} else {
|
|
|
|
MEM_freeN(fnors);
|
|
|
|
}
|
|
|
|
}
|
2005-07-22 17:03:50 +00:00
|
|
|
|
|
|
|
float (*mesh_getVertexCos(Mesh *me, int *numVerts_r))[3]
|
|
|
|
{
|
2006-08-20 15:22:56 +00:00
|
|
|
#ifdef WITH_VERSE
|
|
|
|
if(me->vnode) {
|
|
|
|
struct VLayer *vlayer;
|
|
|
|
struct VerseVert *vvert;
|
|
|
|
unsigned int i, numVerts;
|
|
|
|
float (*cos)[3];
|
2005-07-22 17:03:50 +00:00
|
|
|
|
2006-08-20 15:22:56 +00:00
|
|
|
vlayer = find_verse_layer_type((VGeomData*)((VNode*)me->vnode)->data, VERTEX_LAYER);
|
|
|
|
|
|
|
|
vvert = vlayer->dl.lb.first;
|
|
|
|
numVerts = vlayer->dl.da.count;
|
|
|
|
cos = MEM_mallocN(sizeof(*cos)*numVerts, "verse_vertexcos");
|
2005-07-22 17:03:50 +00:00
|
|
|
|
2006-08-20 15:22:56 +00:00
|
|
|
for(i=0; i<numVerts && vvert; vvert = vvert->next, i++) {
|
|
|
|
VECCOPY(cos[i], vvert->co);
|
|
|
|
}
|
|
|
|
|
|
|
|
return cos;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
#endif
|
|
|
|
int i, numVerts = me->totvert;
|
|
|
|
float (*cos)[3] = MEM_mallocN(sizeof(*cos)*numVerts, "vertexcos1");
|
|
|
|
|
|
|
|
if (numVerts_r) *numVerts_r = numVerts;
|
2007-11-04 22:00:24 +00:00
|
|
|
for (i=0; i<numVerts; i++)
|
2006-08-20 15:22:56 +00:00
|
|
|
VECCOPY(cos[i], me->mvert[i].co);
|
|
|
|
|
|
|
|
return cos;
|
|
|
|
#ifdef WITH_VERSE
|
|
|
|
}
|
|
|
|
#endif
|
2005-07-22 17:03:50 +00:00
|
|
|
}
|
2006-01-10 11:36:57 +00:00
|
|
|
|
2007-11-04 22:00:24 +00:00
|
|
|
float (*mesh_getRefKeyCos(Mesh *me, int *numVerts_r))[3]
|
|
|
|
{
|
|
|
|
KeyBlock *kb;
|
|
|
|
float (*cos)[3] = NULL;
|
|
|
|
int totvert;
|
|
|
|
|
|
|
|
if(me->key && me->key->refkey) {
|
|
|
|
if(numVerts_r) *numVerts_r= me->totvert;
|
|
|
|
cos= MEM_mallocN(sizeof(*cos)*me->totvert, "vertexcos1");
|
|
|
|
|
|
|
|
kb= me->key->refkey;
|
|
|
|
totvert= MIN2(kb->totelem, me->totvert);
|
|
|
|
|
|
|
|
memcpy(cos, kb->data, sizeof(*cos)*totvert);
|
|
|
|
}
|
|
|
|
|
|
|
|
return cos;
|
|
|
|
}
|
|
|
|
|
Added custom vertex/edge/face data for meshes:
All data layers, including MVert/MEdge/MFace, are now managed as custom
data layers. The pointers like Mesh.mvert, Mesh.dvert or Mesh.mcol are
still used of course, but allocating, copying or freeing these arrays
should be done through the CustomData API.
Work in progress documentation on this is here:
http://mediawiki.blender.org/index.php/BlenderDev/BlenderArchitecture/CustomData
Replaced TFace by MTFace:
This is the same struct, except that it does not contain color, that now
always stays separated in MCol. This was not a good design decision to
begin with, and it is needed for adding multiple color layers later. Note
that this does mean older Blender versions will not be able to read UV
coordinates from the next release, due to an SDNA limitation.
Removed DispListMesh:
This now fully replaced by DerivedMesh. To provide access to arrays of
vertices, edges and faces, like DispListMesh does. The semantics of the
DerivedMesh.getVertArray() and similar functions were changed to return
a pointer to an array if one exists, or otherwise allocate a temporary
one. On releasing the DerivedMesh, this temporary array will be removed
automatically.
Removed ssDM and meshDM DerivedMesh backends:
The ssDM backend was for DispListMesh, so that became obsolete automatically.
The meshDM backend was replaced by the custom data backend, that now figures
out which layers need to be modified, and only duplicates those.
This changes code in many places, and overall removes 2514 lines of code.
So, there's a good chance this might break some stuff, although I've been
testing it for a few days now. The good news is, adding multiple color and
uv layers should now become easy.
2006-11-20 04:28:02 +00:00
|
|
|
UvVertMap *make_uv_vert_map(struct MFace *mface, struct MTFace *tface, unsigned int totface, unsigned int totvert, int selected, float *limit)
|
2006-01-10 11:36:57 +00:00
|
|
|
{
|
|
|
|
UvVertMap *vmap;
|
|
|
|
UvMapVert *buf;
|
|
|
|
MFace *mf;
|
Added custom vertex/edge/face data for meshes:
All data layers, including MVert/MEdge/MFace, are now managed as custom
data layers. The pointers like Mesh.mvert, Mesh.dvert or Mesh.mcol are
still used of course, but allocating, copying or freeing these arrays
should be done through the CustomData API.
Work in progress documentation on this is here:
http://mediawiki.blender.org/index.php/BlenderDev/BlenderArchitecture/CustomData
Replaced TFace by MTFace:
This is the same struct, except that it does not contain color, that now
always stays separated in MCol. This was not a good design decision to
begin with, and it is needed for adding multiple color layers later. Note
that this does mean older Blender versions will not be able to read UV
coordinates from the next release, due to an SDNA limitation.
Removed DispListMesh:
This now fully replaced by DerivedMesh. To provide access to arrays of
vertices, edges and faces, like DispListMesh does. The semantics of the
DerivedMesh.getVertArray() and similar functions were changed to return
a pointer to an array if one exists, or otherwise allocate a temporary
one. On releasing the DerivedMesh, this temporary array will be removed
automatically.
Removed ssDM and meshDM DerivedMesh backends:
The ssDM backend was for DispListMesh, so that became obsolete automatically.
The meshDM backend was replaced by the custom data backend, that now figures
out which layers need to be modified, and only duplicates those.
This changes code in many places, and overall removes 2514 lines of code.
So, there's a good chance this might break some stuff, although I've been
testing it for a few days now. The good news is, adding multiple color and
uv layers should now become easy.
2006-11-20 04:28:02 +00:00
|
|
|
MTFace *tf;
|
2006-04-03 20:31:10 +00:00
|
|
|
unsigned int a;
|
|
|
|
int i, totuv, nverts;
|
2006-01-10 11:36:57 +00:00
|
|
|
|
|
|
|
totuv = 0;
|
|
|
|
|
|
|
|
/* generate UvMapVert array */
|
|
|
|
mf= mface;
|
|
|
|
tf= tface;
|
|
|
|
for(a=0; a<totface; a++, mf++, tf++)
|
2007-04-29 13:39:46 +00:00
|
|
|
if(!selected || (!(mf->flag & ME_HIDE) && (mf->flag & ME_FACE_SEL)))
|
2006-01-10 11:36:57 +00:00
|
|
|
totuv += (mf->v4)? 4: 3;
|
|
|
|
|
|
|
|
if(totuv==0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
vmap= (UvVertMap*)MEM_mallocN(sizeof(*vmap), "UvVertMap");
|
|
|
|
if (!vmap)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
vmap->vert= (UvMapVert**)MEM_callocN(sizeof(*vmap->vert)*totvert, "UvMapVert*");
|
|
|
|
buf= vmap->buf= (UvMapVert*)MEM_mallocN(sizeof(*vmap->buf)*totuv, "UvMapVert");
|
|
|
|
|
|
|
|
if (!vmap->vert || !vmap->buf) {
|
|
|
|
free_uv_vert_map(vmap);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
mf= mface;
|
|
|
|
tf= tface;
|
|
|
|
for(a=0; a<totface; a++, mf++, tf++) {
|
2007-04-29 13:39:46 +00:00
|
|
|
if(!selected || (!(mf->flag & ME_HIDE) && (mf->flag & ME_FACE_SEL))) {
|
2006-01-10 11:36:57 +00:00
|
|
|
nverts= (mf->v4)? 4: 3;
|
|
|
|
|
|
|
|
for(i=0; i<nverts; i++) {
|
|
|
|
buf->tfindex= i;
|
|
|
|
buf->f= a;
|
|
|
|
buf->separate = 0;
|
|
|
|
buf->next= vmap->vert[*(&mf->v1 + i)];
|
|
|
|
vmap->vert[*(&mf->v1 + i)]= buf;
|
|
|
|
buf++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* sort individual uvs for each vert */
|
|
|
|
tf= tface;
|
|
|
|
for(a=0; a<totvert; a++) {
|
|
|
|
UvMapVert *newvlist= NULL, *vlist=vmap->vert[a];
|
|
|
|
UvMapVert *iterv, *v, *lastv, *next;
|
|
|
|
float *uv, *uv2, uvdiff[2];
|
|
|
|
|
|
|
|
while(vlist) {
|
|
|
|
v= vlist;
|
|
|
|
vlist= vlist->next;
|
|
|
|
v->next= newvlist;
|
|
|
|
newvlist= v;
|
|
|
|
|
|
|
|
uv= (tf+v->f)->uv[v->tfindex];
|
|
|
|
lastv= NULL;
|
|
|
|
iterv= vlist;
|
|
|
|
|
|
|
|
while(iterv) {
|
|
|
|
next= iterv->next;
|
|
|
|
|
|
|
|
uv2= (tf+iterv->f)->uv[iterv->tfindex];
|
|
|
|
Vec2Subf(uvdiff, uv2, uv);
|
|
|
|
|
|
|
|
|
|
|
|
if(fabs(uv[0]-uv2[0]) < limit[0] && fabs(uv[1]-uv2[1]) < limit[1]) {
|
|
|
|
if(lastv) lastv->next= next;
|
|
|
|
else vlist= next;
|
|
|
|
iterv->next= newvlist;
|
|
|
|
newvlist= iterv;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
lastv=iterv;
|
|
|
|
|
|
|
|
iterv= next;
|
|
|
|
}
|
|
|
|
|
|
|
|
newvlist->separate = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
vmap->vert[a]= newvlist;
|
|
|
|
}
|
|
|
|
|
|
|
|
return vmap;
|
|
|
|
}
|
|
|
|
|
|
|
|
UvMapVert *get_uv_map_vert(UvVertMap *vmap, unsigned int v)
|
|
|
|
{
|
|
|
|
return vmap->vert[v];
|
|
|
|
}
|
|
|
|
|
|
|
|
void free_uv_vert_map(UvVertMap *vmap)
|
|
|
|
{
|
|
|
|
if (vmap) {
|
|
|
|
if (vmap->vert) MEM_freeN(vmap->vert);
|
|
|
|
if (vmap->buf) MEM_freeN(vmap->buf);
|
|
|
|
MEM_freeN(vmap);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|