2011-02-23 11:52:22 +01:00
|
|
|
/*
|
2008-01-07 20:13:47 +01:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
2005-03-27 22:34:18 +02:00
|
|
|
*
|
|
|
|
* 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
|
2008-01-07 20:13:47 +01:00
|
|
|
* of the License, or (at your option) any later version.
|
2005-03-27 22:34:18 +02:00
|
|
|
*
|
|
|
|
* 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,
|
2010-02-12 14:34:04 +01:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2005-03-27 22:34:18 +02:00
|
|
|
*
|
2005-03-29 18:43:39 +02:00
|
|
|
* The Original Code is Copyright (C) 2005 Blender Foundation.
|
2005-03-27 22:34:18 +02:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* The Original Code is: all of this file.
|
|
|
|
*
|
|
|
|
* Contributor(s): none yet.
|
|
|
|
*
|
2008-01-07 20:13:47 +01:00
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
2005-03-27 22:34:18 +02:00
|
|
|
*/
|
|
|
|
|
2011-02-27 21:40:57 +01:00
|
|
|
/** \file blender/blenkernel/intern/DerivedMesh.c
|
|
|
|
* \ingroup bke
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2005-08-23 22:04:10 +02:00
|
|
|
#include <string.h>
|
2012-04-06 07:53:01 +02:00
|
|
|
#include <limits.h>
|
2005-07-23 21:15:08 +02:00
|
|
|
|
2005-03-27 22:34:18 +02:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
2010-03-30 13:49:07 +02:00
|
|
|
#include "DNA_cloth_types.h"
|
2006-08-28 03:12:36 +02:00
|
|
|
#include "DNA_key_types.h"
|
2014-07-21 12:02:05 +02:00
|
|
|
#include "DNA_material_types.h"
|
2012-02-19 23:17:30 +01:00
|
|
|
#include "DNA_mesh_types.h"
|
2005-03-27 22:34:18 +02:00
|
|
|
#include "DNA_meshdata_types.h"
|
|
|
|
#include "DNA_object_types.h"
|
2014-04-27 18:22:03 +02:00
|
|
|
#include "DNA_scene_types.h"
|
2005-03-27 22:34:18 +02:00
|
|
|
|
Fix T47038: Particles in Particle Edit Mode get added in completely wrong location.
It also fixes another issue (crash) related to symmetric editing.
Quite involved, we (try to!) fix complete broken logic of parts of particle code, which would use poly index
as tessface one (or vice-versa). Issue most probably goes back to BMesh integration time...
This patch mostly fixes particle editing mode:
- Adding/removing particles when using generative modifiers (like subsurf) should now work.
- Adding/removing particles with a non-tessellated mesh (i.e. one having ngons) should also mostly work.
- X-axis-mirror-editing particles over ngons does not really work, not sure why currently.
- All this in both 'modes' (with or without using modifier stack for particles).
Tech side:
- Store a deformed-only DM in particle modifier data.
- Rename existing DM to make it clear it's a final one.
- Use deformed-only DM's tessface2poly mapping to 'solve' poly/tessface mismatches.
- Make (part of) mirror-editing code able to use a DM instead of raw mesh, so that we can mirror based on final DM
when editing particles using modifier stack (mandatory, since there is no way currently to find orig tessface
from an final DM tessface index).
Note that this patch is not really nice and clean (current particles are beyond hope on this side anyway),
it's more like some urgency bandage. Whole crap needs complete rewrite anyway,
BMesh's polygons make it really hard to work with current system (and looptri would not help much here).
Also, did not test everything possibly affected by those changes, so it needs some users' testing & validation too.
Reviewers: psy-fi
Subscribers: dfelinto, eyecandy
Maniphest Tasks: T47038
Differential Revision: https://developer.blender.org/D1685
2016-01-04 12:19:45 +01:00
|
|
|
#include "BLI_array.h"
|
2005-03-27 23:27:12 +02:00
|
|
|
#include "BLI_blenlib.h"
|
2014-09-04 09:53:10 +02:00
|
|
|
#include "BLI_bitmap.h"
|
2010-03-22 12:59:36 +01:00
|
|
|
#include "BLI_math.h"
|
2011-01-07 19:36:47 +01:00
|
|
|
#include "BLI_utildefines.h"
|
2011-10-22 03:53:35 +02:00
|
|
|
#include "BLI_linklist.h"
|
2016-04-26 10:43:02 +02:00
|
|
|
#include "BLI_task.h"
|
2005-03-27 22:34:18 +02:00
|
|
|
|
2006-08-28 03:12:36 +02:00
|
|
|
#include "BKE_cdderivedmesh.h"
|
2017-12-07 05:36:26 +01:00
|
|
|
#include "BKE_colorband.h"
|
2013-04-18 19:09:56 +02:00
|
|
|
#include "BKE_editmesh.h"
|
2007-10-31 14:56:07 +01:00
|
|
|
#include "BKE_key.h"
|
2017-04-18 14:55:31 +02:00
|
|
|
#include "BKE_layer.h"
|
2015-11-09 19:47:10 +01:00
|
|
|
#include "BKE_library.h"
|
2014-04-09 03:03:25 +02:00
|
|
|
#include "BKE_material.h"
|
2007-10-31 14:56:07 +01:00
|
|
|
#include "BKE_modifier.h"
|
2005-03-27 22:34:18 +02:00
|
|
|
#include "BKE_mesh.h"
|
2018-10-09 07:52:46 +02:00
|
|
|
#include "BKE_mesh_iterators.h"
|
2014-01-21 16:32:36 +01:00
|
|
|
#include "BKE_mesh_mapping.h"
|
2018-06-05 15:59:53 +02:00
|
|
|
#include "BKE_mesh_runtime.h"
|
2017-05-24 14:33:21 +02:00
|
|
|
#include "BKE_mesh_tangent.h"
|
2005-03-27 22:34:18 +02:00
|
|
|
#include "BKE_object.h"
|
2012-09-05 05:45:32 +02:00
|
|
|
#include "BKE_object_deform.h"
|
2009-08-15 21:48:50 +02:00
|
|
|
#include "BKE_paint.h"
|
2011-01-31 21:02:51 +01:00
|
|
|
#include "BKE_multires.h"
|
2009-05-23 05:24:15 +02:00
|
|
|
#include "BKE_bvhutils.h"
|
2011-12-07 08:13:33 +01:00
|
|
|
#include "BKE_deform.h"
|
2005-03-27 22:34:18 +02:00
|
|
|
|
2013-05-28 21:35:26 +02:00
|
|
|
#include "BLI_sys_types.h" /* for intptr_t support */
|
2008-08-17 19:08:00 +02:00
|
|
|
|
2018-04-16 20:45:43 +02:00
|
|
|
#include "DEG_depsgraph.h"
|
|
|
|
#include "DEG_depsgraph_query.h"
|
Shrinkwrap: new mode that projects along the target normal.
The Nearest Surface Point shrink method, while fast, is neither
smooth nor continuous: as the source point moves, the projected
point can both stop and jump. This causes distortions in the
deformation of the shrinkwrap modifier, and the motion of an
animated object with a shrinkwrap constraint.
This patch implements a new mode, which, instead of using the simple
nearest point search, iteratively solves an equation for each triangle
to find a point which has its interpolated normal point to or from the
original vertex. Non-manifold boundary edges are treated as infinitely
thin cylinders that cast normals in all perpendicular directions.
Since this is useful for the constraint, and having multiple
objects with constraints targeting the same guide mesh is a quite
reasonable use case, rather than calculating the mesh boundary edge
data over and over again, it is precomputed and cached in the mesh.
Reviewers: mont29
Differential Revision: https://developer.blender.org/D3836
2018-11-06 19:04:53 +01:00
|
|
|
#include "BKE_shrinkwrap.h"
|
2018-04-16 20:45:43 +02:00
|
|
|
|
2015-08-03 20:35:43 +02:00
|
|
|
#ifdef WITH_OPENSUBDIV
|
|
|
|
# include "DNA_userdef_types.h"
|
|
|
|
#endif
|
|
|
|
|
2013-09-04 03:29:34 +02:00
|
|
|
/* very slow! enable for testing only! */
|
2014-12-02 13:49:40 +01:00
|
|
|
//#define USE_MODIFIER_VALIDATE
|
2013-09-04 03:29:34 +02:00
|
|
|
|
|
|
|
#ifdef USE_MODIFIER_VALIDATE
|
|
|
|
# define ASSERT_IS_VALID_DM(dm) (BLI_assert((dm == NULL) || (DM_is_valid(dm) == true)))
|
2018-05-11 09:53:52 +02:00
|
|
|
# define ASSERT_IS_VALID_MESH(mesh) (BLI_assert((mesh == NULL) || (BKE_mesh_is_valid(mesh) == true)))
|
2013-09-04 03:29:34 +02:00
|
|
|
#else
|
|
|
|
# define ASSERT_IS_VALID_DM(dm)
|
2018-05-11 09:53:52 +02:00
|
|
|
# define ASSERT_IS_VALID_MESH(mesh)
|
2013-09-04 03:29:34 +02:00
|
|
|
#endif
|
|
|
|
|
2017-08-11 16:51:19 +02:00
|
|
|
|
2017-09-19 13:09:35 +02:00
|
|
|
static ThreadRWMutex loops_cache_lock = PTHREAD_RWLOCK_INITIALIZER;
|
2017-08-11 16:51:19 +02:00
|
|
|
|
|
|
|
|
2011-04-15 07:20:18 +02:00
|
|
|
static void shapekey_layers_to_keyblocks(DerivedMesh *dm, Mesh *me, int actshape_uid);
|
|
|
|
|
2018-05-11 09:53:52 +02:00
|
|
|
static void mesh_init_origspace(Mesh *mesh);
|
|
|
|
|
2013-09-04 03:29:34 +02:00
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
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 05:28:02 +01:00
|
|
|
|
2008-09-29 19:08:11 +02:00
|
|
|
static MVert *dm_getVertArray(DerivedMesh *dm)
|
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 05:28:02 +01:00
|
|
|
{
|
|
|
|
MVert *mvert = CustomData_get_layer(&dm->vertData, CD_MVERT);
|
|
|
|
|
|
|
|
if (!mvert) {
|
2006-12-12 22:29:09 +01:00
|
|
|
mvert = CustomData_add_layer(&dm->vertData, CD_MVERT, CD_CALLOC, NULL,
|
2012-05-12 21:18:02 +02:00
|
|
|
dm->getNumVerts(dm));
|
2006-12-12 22:29:09 +01:00
|
|
|
CustomData_set_layer_flag(&dm->vertData, CD_MVERT, CD_FLAG_TEMPORARY);
|
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 05:28:02 +01:00
|
|
|
dm->copyVertArray(dm, mvert);
|
|
|
|
}
|
|
|
|
|
|
|
|
return mvert;
|
|
|
|
}
|
|
|
|
|
2008-09-29 19:08:11 +02:00
|
|
|
static MEdge *dm_getEdgeArray(DerivedMesh *dm)
|
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 05:28:02 +01:00
|
|
|
{
|
|
|
|
MEdge *medge = CustomData_get_layer(&dm->edgeData, CD_MEDGE);
|
|
|
|
|
|
|
|
if (!medge) {
|
2006-12-12 22:29:09 +01:00
|
|
|
medge = CustomData_add_layer(&dm->edgeData, CD_MEDGE, CD_CALLOC, NULL,
|
2012-05-12 21:18:02 +02:00
|
|
|
dm->getNumEdges(dm));
|
2006-12-12 22:29:09 +01:00
|
|
|
CustomData_set_layer_flag(&dm->edgeData, CD_MEDGE, CD_FLAG_TEMPORARY);
|
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 05:28:02 +01:00
|
|
|
dm->copyEdgeArray(dm, medge);
|
|
|
|
}
|
|
|
|
|
|
|
|
return medge;
|
|
|
|
}
|
|
|
|
|
2011-11-30 19:03:56 +01:00
|
|
|
static MFace *dm_getTessFaceArray(DerivedMesh *dm)
|
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 05:28:02 +01:00
|
|
|
{
|
|
|
|
MFace *mface = CustomData_get_layer(&dm->faceData, CD_MFACE);
|
|
|
|
|
|
|
|
if (!mface) {
|
2012-03-14 15:09:56 +01:00
|
|
|
int numTessFaces = dm->getNumTessFaces(dm);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2012-03-14 15:09:56 +01:00
|
|
|
if (!numTessFaces) {
|
|
|
|
/* Do not add layer if there's no elements in it, this leads to issues later when
|
|
|
|
* this layer is needed with non-zero size, but currently CD stuff does not check
|
|
|
|
* for requested layer size on creation and just returns layer which was previously
|
|
|
|
* added (sergey) */
|
|
|
|
return NULL;
|
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2012-03-14 15:09:56 +01:00
|
|
|
mface = CustomData_add_layer(&dm->faceData, CD_MFACE, CD_CALLOC, NULL, numTessFaces);
|
2006-12-12 22:29:09 +01:00
|
|
|
CustomData_set_layer_flag(&dm->faceData, CD_MFACE, CD_FLAG_TEMPORARY);
|
(NOTE: DO NOT TEST)
Start of planned DerivedMesh refactoring. The mface
interfaces in DerivedMesh have been renamed to reflect
their new status as tesselated face interfaces (rather
then the primary ones, which are now stored in mpolys).
short review: mpolys store "primary" face data, while
mfaces store the tesselated form of the mesh (generally
as triangles). mpolys are defined by mloops, and each
mpoly defines a range of loops it "owns" in the main
mloop array.
I've also added basic read-only face iterators, which
are implemented for CDDM, ccgsubsurf, and the bmeditmesh
derivedmesh. Since faces are now variable-length things,
trying to implement the same interface as mfaces would not
have worked well (especially since faces are stored as
an mpoly + a range of mloops).
I figure first we can evaluate these simple read-only
face iterators, then decide if a) we like using iterators
in DerivedMesh, b) how much of it should use them, and c)
if we want write-capable iterators.
I plan to write official docs on this design after I get
it more stable; I'm committing now because there's a rather
lot of changes, and I might do a merge soon.
2009-06-10 12:06:25 +02:00
|
|
|
dm->copyTessFaceArray(dm, mface);
|
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 05:28:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return mface;
|
|
|
|
}
|
2006-08-28 03:12:36 +02:00
|
|
|
|
2011-06-14 05:16:08 +02:00
|
|
|
static MLoop *dm_getLoopArray(DerivedMesh *dm)
|
|
|
|
{
|
|
|
|
MLoop *mloop = CustomData_get_layer(&dm->loopData, CD_MLOOP);
|
|
|
|
|
|
|
|
if (!mloop) {
|
|
|
|
mloop = CustomData_add_layer(&dm->loopData, CD_MLOOP, CD_CALLOC, NULL,
|
2012-05-12 21:18:02 +02:00
|
|
|
dm->getNumLoops(dm));
|
2011-06-14 05:16:08 +02:00
|
|
|
CustomData_set_layer_flag(&dm->loopData, CD_MLOOP, CD_FLAG_TEMPORARY);
|
|
|
|
dm->copyLoopArray(dm, mloop);
|
|
|
|
}
|
|
|
|
|
|
|
|
return mloop;
|
|
|
|
}
|
|
|
|
|
|
|
|
static MPoly *dm_getPolyArray(DerivedMesh *dm)
|
|
|
|
{
|
|
|
|
MPoly *mpoly = CustomData_get_layer(&dm->polyData, CD_MPOLY);
|
|
|
|
|
|
|
|
if (!mpoly) {
|
|
|
|
mpoly = CustomData_add_layer(&dm->polyData, CD_MPOLY, CD_CALLOC, NULL,
|
2012-05-12 21:18:02 +02:00
|
|
|
dm->getNumPolys(dm));
|
2011-06-14 05:16:08 +02:00
|
|
|
CustomData_set_layer_flag(&dm->polyData, CD_MPOLY, CD_FLAG_TEMPORARY);
|
|
|
|
dm->copyPolyArray(dm, mpoly);
|
|
|
|
}
|
|
|
|
|
|
|
|
return mpoly;
|
|
|
|
}
|
|
|
|
|
2008-09-29 19:08:11 +02:00
|
|
|
static MVert *dm_dupVertArray(DerivedMesh *dm)
|
2006-08-28 03:12:36 +02:00
|
|
|
{
|
2018-01-14 22:14:20 +01:00
|
|
|
MVert *tmp = MEM_malloc_arrayN(dm->getNumVerts(dm), sizeof(*tmp),
|
2012-05-12 21:18:02 +02:00
|
|
|
"dm_dupVertArray tmp");
|
2006-08-28 03:12:36 +02:00
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (tmp) dm->copyVertArray(dm, tmp);
|
2006-08-28 03:12:36 +02:00
|
|
|
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
2008-09-29 19:08:11 +02:00
|
|
|
static MEdge *dm_dupEdgeArray(DerivedMesh *dm)
|
2006-08-28 03:12:36 +02:00
|
|
|
{
|
2018-01-14 22:14:20 +01:00
|
|
|
MEdge *tmp = MEM_malloc_arrayN(dm->getNumEdges(dm), sizeof(*tmp),
|
2012-05-12 21:18:02 +02:00
|
|
|
"dm_dupEdgeArray tmp");
|
2006-08-28 03:12:36 +02:00
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (tmp) dm->copyEdgeArray(dm, tmp);
|
2006-08-28 03:12:36 +02:00
|
|
|
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
2008-09-29 19:08:11 +02:00
|
|
|
static MFace *dm_dupFaceArray(DerivedMesh *dm)
|
2006-08-28 03:12:36 +02:00
|
|
|
{
|
2018-01-14 22:14:20 +01:00
|
|
|
MFace *tmp = MEM_malloc_arrayN(dm->getNumTessFaces(dm), sizeof(*tmp),
|
2012-05-12 21:18:02 +02:00
|
|
|
"dm_dupFaceArray tmp");
|
2006-08-28 03:12:36 +02:00
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (tmp) dm->copyTessFaceArray(dm, tmp);
|
2006-08-28 03:12:36 +02:00
|
|
|
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
2011-06-14 05:16:08 +02:00
|
|
|
static MLoop *dm_dupLoopArray(DerivedMesh *dm)
|
|
|
|
{
|
2018-01-14 22:14:20 +01:00
|
|
|
MLoop *tmp = MEM_malloc_arrayN(dm->getNumLoops(dm), sizeof(*tmp),
|
2012-05-12 21:18:02 +02:00
|
|
|
"dm_dupLoopArray tmp");
|
2011-06-14 05:16:08 +02:00
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (tmp) dm->copyLoopArray(dm, tmp);
|
2011-06-14 05:16:08 +02:00
|
|
|
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
static MPoly *dm_dupPolyArray(DerivedMesh *dm)
|
|
|
|
{
|
2018-01-14 22:14:20 +01:00
|
|
|
MPoly *tmp = MEM_malloc_arrayN(dm->getNumPolys(dm), sizeof(*tmp),
|
2012-05-12 21:18:02 +02:00
|
|
|
"dm_dupPolyArray tmp");
|
2011-06-14 05:16:08 +02:00
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (tmp) dm->copyPolyArray(dm, tmp);
|
2011-06-14 05:16:08 +02:00
|
|
|
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
2015-07-16 19:36:03 +02:00
|
|
|
static int dm_getNumLoopTri(DerivedMesh *dm)
|
|
|
|
{
|
2016-11-23 20:19:03 +01:00
|
|
|
const int numlooptris = poly_to_tri_count(dm->getNumPolys(dm), dm->getNumLoops(dm));
|
|
|
|
BLI_assert(ELEM(dm->looptris.num, 0, numlooptris));
|
|
|
|
return numlooptris;
|
2015-07-16 19:36:03 +02:00
|
|
|
}
|
|
|
|
|
2017-08-11 15:41:53 +02:00
|
|
|
static const MLoopTri *dm_getLoopTriArray(DerivedMesh *dm)
|
|
|
|
{
|
2017-09-19 13:09:35 +02:00
|
|
|
MLoopTri *looptri;
|
|
|
|
|
|
|
|
BLI_rw_mutex_lock(&loops_cache_lock, THREAD_LOCK_READ);
|
|
|
|
looptri = dm->looptris.array;
|
|
|
|
BLI_rw_mutex_unlock(&loops_cache_lock);
|
|
|
|
|
|
|
|
if (looptri != NULL) {
|
2017-08-11 16:18:01 +02:00
|
|
|
BLI_assert(dm->getNumLoopTri(dm) == dm->looptris.num);
|
2017-08-11 15:41:53 +02:00
|
|
|
}
|
|
|
|
else {
|
2017-09-19 13:09:35 +02:00
|
|
|
BLI_rw_mutex_lock(&loops_cache_lock, THREAD_LOCK_WRITE);
|
2017-08-11 16:51:19 +02:00
|
|
|
/* We need to ensure array is still NULL inside mutex-protected code, some other thread might have already
|
|
|
|
* recomputed those looptris. */
|
|
|
|
if (dm->looptris.array == NULL) {
|
|
|
|
dm->recalcLoopTri(dm);
|
|
|
|
}
|
2017-09-19 13:09:35 +02:00
|
|
|
looptri = dm->looptris.array;
|
|
|
|
BLI_rw_mutex_unlock(&loops_cache_lock);
|
2017-08-11 15:41:53 +02:00
|
|
|
}
|
2017-09-19 13:09:35 +02:00
|
|
|
return looptri;
|
2017-08-11 15:41:53 +02:00
|
|
|
}
|
|
|
|
|
2011-05-11 04:14:43 +02:00
|
|
|
static CustomData *dm_getVertCData(DerivedMesh *dm)
|
2009-06-23 07:35:49 +02:00
|
|
|
{
|
|
|
|
return &dm->vertData;
|
|
|
|
}
|
|
|
|
|
2011-05-11 04:14:43 +02:00
|
|
|
static CustomData *dm_getEdgeCData(DerivedMesh *dm)
|
2009-06-23 07:35:49 +02:00
|
|
|
{
|
|
|
|
return &dm->edgeData;
|
|
|
|
}
|
|
|
|
|
2011-11-30 19:03:56 +01:00
|
|
|
static CustomData *dm_getTessFaceCData(DerivedMesh *dm)
|
2009-06-23 07:35:49 +02:00
|
|
|
{
|
|
|
|
return &dm->faceData;
|
|
|
|
}
|
|
|
|
|
2011-05-11 04:14:43 +02:00
|
|
|
static CustomData *dm_getLoopCData(DerivedMesh *dm)
|
2009-06-23 07:35:49 +02:00
|
|
|
{
|
|
|
|
return &dm->loopData;
|
|
|
|
}
|
|
|
|
|
2011-05-11 04:14:43 +02:00
|
|
|
static CustomData *dm_getPolyCData(DerivedMesh *dm)
|
2009-06-23 07:35:49 +02:00
|
|
|
{
|
|
|
|
return &dm->polyData;
|
|
|
|
}
|
|
|
|
|
2015-07-02 08:20:22 +02:00
|
|
|
/**
|
|
|
|
* Utility function to initialize a DerivedMesh's function pointers to
|
|
|
|
* the default implementation (for those functions which have a default)
|
|
|
|
*/
|
2006-08-28 03:12:36 +02:00
|
|
|
void DM_init_funcs(DerivedMesh *dm)
|
|
|
|
{
|
|
|
|
/* default function implementations */
|
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 05:28:02 +01:00
|
|
|
dm->getVertArray = dm_getVertArray;
|
|
|
|
dm->getEdgeArray = dm_getEdgeArray;
|
2011-11-30 19:03:56 +01:00
|
|
|
dm->getTessFaceArray = dm_getTessFaceArray;
|
2011-06-14 05:16:08 +02:00
|
|
|
dm->getLoopArray = dm_getLoopArray;
|
|
|
|
dm->getPolyArray = dm_getPolyArray;
|
2006-08-28 03:12:36 +02:00
|
|
|
dm->dupVertArray = dm_dupVertArray;
|
|
|
|
dm->dupEdgeArray = dm_dupEdgeArray;
|
(NOTE: DO NOT TEST)
Start of planned DerivedMesh refactoring. The mface
interfaces in DerivedMesh have been renamed to reflect
their new status as tesselated face interfaces (rather
then the primary ones, which are now stored in mpolys).
short review: mpolys store "primary" face data, while
mfaces store the tesselated form of the mesh (generally
as triangles). mpolys are defined by mloops, and each
mpoly defines a range of loops it "owns" in the main
mloop array.
I've also added basic read-only face iterators, which
are implemented for CDDM, ccgsubsurf, and the bmeditmesh
derivedmesh. Since faces are now variable-length things,
trying to implement the same interface as mfaces would not
have worked well (especially since faces are stored as
an mpoly + a range of mloops).
I figure first we can evaluate these simple read-only
face iterators, then decide if a) we like using iterators
in DerivedMesh, b) how much of it should use them, and c)
if we want write-capable iterators.
I plan to write official docs on this design after I get
it more stable; I'm committing now because there's a rather
lot of changes, and I might do a merge soon.
2009-06-10 12:06:25 +02:00
|
|
|
dm->dupTessFaceArray = dm_dupFaceArray;
|
2011-06-14 05:16:08 +02:00
|
|
|
dm->dupLoopArray = dm_dupLoopArray;
|
|
|
|
dm->dupPolyArray = dm_dupPolyArray;
|
2006-08-28 03:12:36 +02:00
|
|
|
|
2017-08-11 15:41:53 +02:00
|
|
|
dm->getLoopTriArray = dm_getLoopTriArray;
|
|
|
|
|
2015-07-16 19:36:03 +02:00
|
|
|
/* subtypes handle getting actual data */
|
|
|
|
dm->getNumLoopTri = dm_getNumLoopTri;
|
|
|
|
|
2009-06-23 07:35:49 +02:00
|
|
|
dm->getVertDataLayout = dm_getVertCData;
|
|
|
|
dm->getEdgeDataLayout = dm_getEdgeCData;
|
2011-11-30 19:03:56 +01:00
|
|
|
dm->getTessFaceDataLayout = dm_getTessFaceCData;
|
2009-06-23 07:35:49 +02:00
|
|
|
dm->getLoopDataLayout = dm_getLoopCData;
|
2011-11-29 14:01:51 +01:00
|
|
|
dm->getPolyDataLayout = dm_getPolyCData;
|
2009-06-23 07:35:49 +02:00
|
|
|
|
2006-08-28 03:12:36 +02:00
|
|
|
dm->getVertData = DM_get_vert_data;
|
|
|
|
dm->getEdgeData = DM_get_edge_data;
|
2011-11-29 06:09:54 +01:00
|
|
|
dm->getTessFaceData = DM_get_tessface_data;
|
2012-10-30 20:20:17 +01:00
|
|
|
dm->getPolyData = DM_get_poly_data;
|
2006-08-28 03:12:36 +02:00
|
|
|
dm->getVertDataArray = DM_get_vert_data_layer;
|
|
|
|
dm->getEdgeDataArray = DM_get_edge_data_layer;
|
2009-08-15 19:31:28 +02:00
|
|
|
dm->getTessFaceDataArray = DM_get_tessface_data_layer;
|
2012-10-30 20:20:17 +01:00
|
|
|
dm->getPolyDataArray = DM_get_poly_data_layer;
|
2013-04-03 22:10:08 +02:00
|
|
|
dm->getLoopDataArray = DM_get_loop_data_layer;
|
2009-05-23 05:24:15 +02:00
|
|
|
|
2018-05-09 01:00:51 +02:00
|
|
|
dm->bvhCache = NULL;
|
2006-08-28 03:12:36 +02:00
|
|
|
}
|
|
|
|
|
2015-07-02 08:20:22 +02:00
|
|
|
/**
|
|
|
|
* Utility function to initialize a DerivedMesh for the desired number
|
|
|
|
* of vertices, edges and faces (doesn't allocate memory for them, just
|
|
|
|
* sets up the custom data layers)
|
|
|
|
*/
|
|
|
|
void DM_init(
|
|
|
|
DerivedMesh *dm, DerivedMeshType type, int numVerts, int numEdges,
|
|
|
|
int numTessFaces, int numLoops, int numPolys)
|
2006-08-28 03:12:36 +02:00
|
|
|
{
|
2010-01-06 13:05:46 +01:00
|
|
|
dm->type = type;
|
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 05:28:02 +01:00
|
|
|
dm->numVertData = numVerts;
|
|
|
|
dm->numEdgeData = numEdges;
|
2011-11-30 19:03:56 +01:00
|
|
|
dm->numTessFaceData = numTessFaces;
|
(NOTE: DO NOT TEST)
Start of planned DerivedMesh refactoring. The mface
interfaces in DerivedMesh have been renamed to reflect
their new status as tesselated face interfaces (rather
then the primary ones, which are now stored in mpolys).
short review: mpolys store "primary" face data, while
mfaces store the tesselated form of the mesh (generally
as triangles). mpolys are defined by mloops, and each
mpoly defines a range of loops it "owns" in the main
mloop array.
I've also added basic read-only face iterators, which
are implemented for CDDM, ccgsubsurf, and the bmeditmesh
derivedmesh. Since faces are now variable-length things,
trying to implement the same interface as mfaces would not
have worked well (especially since faces are stored as
an mpoly + a range of mloops).
I figure first we can evaluate these simple read-only
face iterators, then decide if a) we like using iterators
in DerivedMesh, b) how much of it should use them, and c)
if we want write-capable iterators.
I plan to write official docs on this design after I get
it more stable; I'm committing now because there's a rather
lot of changes, and I might do a merge soon.
2009-06-10 12:06:25 +02:00
|
|
|
dm->numLoopData = numLoops;
|
2011-11-30 19:03:56 +01:00
|
|
|
dm->numPolyData = numPolys;
|
2006-08-28 03:12:36 +02:00
|
|
|
|
|
|
|
DM_init_funcs(dm);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
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 05:28:02 +01:00
|
|
|
dm->needsFree = 1;
|
Fix [#30234] Various problems with CD layers and tesselation, related to modifiers stack.
Should also fix [#30266], [#29451], and partly [#30316].
Here are the changes made by this commit:
* It adds a "dirty" flag to DerivedMesh struct (for now, only DM_DIRTY_TESS_CDLAYERS, but more might be added as needed).
* It adds a new func, DM_update_tessface_data, which assumes tessfaces themselves are valid, but updates tessellated customdata from their poly/loop counter parts.
* At end of modstack, when valid tessellated faces are present in finaldm , but the cdlayers dirty flag is set, call that function (instead of recomputing the whole tessellation).
* Edits to the codes concerned (UVProject, DynamicPaint, and Subsurf modifiers).
* Also add to subsurf dm generation code the creation of a CD_POLYINDEX layer (mandatory for DM_update_tessface_data to work well, and imho all tessellated dm should have one).
Note: some pieces of old code are just #if 0’ed, will clean them later.
2012-03-18 23:06:57 +01:00
|
|
|
dm->dirty = 0;
|
2012-10-31 10:50:24 +01:00
|
|
|
|
|
|
|
/* don't use CustomData_reset(...); because we dont want to touch customdata */
|
2015-05-05 09:08:29 +02:00
|
|
|
copy_vn_i(dm->vertData.typemap, CD_NUMTYPES, -1);
|
|
|
|
copy_vn_i(dm->edgeData.typemap, CD_NUMTYPES, -1);
|
|
|
|
copy_vn_i(dm->faceData.typemap, CD_NUMTYPES, -1);
|
|
|
|
copy_vn_i(dm->loopData.typemap, CD_NUMTYPES, -1);
|
|
|
|
copy_vn_i(dm->polyData.typemap, CD_NUMTYPES, -1);
|
2006-08-28 03:12:36 +02:00
|
|
|
}
|
|
|
|
|
2015-07-02 08:20:22 +02:00
|
|
|
/**
|
|
|
|
* Utility function to initialize a DerivedMesh for the desired number
|
|
|
|
* of vertices, edges and faces, with a layer setup copied from source
|
|
|
|
*/
|
2015-09-23 14:57:00 +02:00
|
|
|
void DM_from_template_ex(
|
2015-07-02 08:20:22 +02:00
|
|
|
DerivedMesh *dm, DerivedMesh *source, DerivedMeshType type,
|
|
|
|
int numVerts, int numEdges, int numTessFaces,
|
2015-09-23 14:57:00 +02:00
|
|
|
int numLoops, int numPolys,
|
|
|
|
CustomDataMask mask)
|
2006-08-28 03:12:36 +02:00
|
|
|
{
|
2015-09-23 14:57:00 +02:00
|
|
|
CustomData_copy(&source->vertData, &dm->vertData, mask, CD_CALLOC, numVerts);
|
|
|
|
CustomData_copy(&source->edgeData, &dm->edgeData, mask, CD_CALLOC, numEdges);
|
|
|
|
CustomData_copy(&source->faceData, &dm->faceData, mask, CD_CALLOC, numTessFaces);
|
|
|
|
CustomData_copy(&source->loopData, &dm->loopData, mask, CD_CALLOC, numLoops);
|
|
|
|
CustomData_copy(&source->polyData, &dm->polyData, mask, CD_CALLOC, numPolys);
|
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 05:28:02 +01:00
|
|
|
|
2013-01-10 05:43:31 +01:00
|
|
|
dm->cd_flag = source->cd_flag;
|
|
|
|
|
2010-01-06 13:05:46 +01:00
|
|
|
dm->type = type;
|
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 05:28:02 +01:00
|
|
|
dm->numVertData = numVerts;
|
|
|
|
dm->numEdgeData = numEdges;
|
2011-11-30 19:03:56 +01:00
|
|
|
dm->numTessFaceData = numTessFaces;
|
(NOTE: DO NOT TEST)
Start of planned DerivedMesh refactoring. The mface
interfaces in DerivedMesh have been renamed to reflect
their new status as tesselated face interfaces (rather
then the primary ones, which are now stored in mpolys).
short review: mpolys store "primary" face data, while
mfaces store the tesselated form of the mesh (generally
as triangles). mpolys are defined by mloops, and each
mpoly defines a range of loops it "owns" in the main
mloop array.
I've also added basic read-only face iterators, which
are implemented for CDDM, ccgsubsurf, and the bmeditmesh
derivedmesh. Since faces are now variable-length things,
trying to implement the same interface as mfaces would not
have worked well (especially since faces are stored as
an mpoly + a range of mloops).
I figure first we can evaluate these simple read-only
face iterators, then decide if a) we like using iterators
in DerivedMesh, b) how much of it should use them, and c)
if we want write-capable iterators.
I plan to write official docs on this design after I get
it more stable; I'm committing now because there's a rather
lot of changes, and I might do a merge soon.
2009-06-10 12:06:25 +02:00
|
|
|
dm->numLoopData = numLoops;
|
|
|
|
dm->numPolyData = numPolys;
|
2006-08-28 03:12:36 +02:00
|
|
|
|
|
|
|
DM_init_funcs(dm);
|
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 05:28:02 +01:00
|
|
|
|
|
|
|
dm->needsFree = 1;
|
Fix [#30234] Various problems with CD layers and tesselation, related to modifiers stack.
Should also fix [#30266], [#29451], and partly [#30316].
Here are the changes made by this commit:
* It adds a "dirty" flag to DerivedMesh struct (for now, only DM_DIRTY_TESS_CDLAYERS, but more might be added as needed).
* It adds a new func, DM_update_tessface_data, which assumes tessfaces themselves are valid, but updates tessellated customdata from their poly/loop counter parts.
* At end of modstack, when valid tessellated faces are present in finaldm , but the cdlayers dirty flag is set, call that function (instead of recomputing the whole tessellation).
* Edits to the codes concerned (UVProject, DynamicPaint, and Subsurf modifiers).
* Also add to subsurf dm generation code the creation of a CD_POLYINDEX layer (mandatory for DM_update_tessface_data to work well, and imho all tessellated dm should have one).
Note: some pieces of old code are just #if 0’ed, will clean them later.
2012-03-18 23:06:57 +01:00
|
|
|
dm->dirty = 0;
|
2006-08-28 03:12:36 +02:00
|
|
|
}
|
2015-09-23 14:57:00 +02:00
|
|
|
void DM_from_template(
|
|
|
|
DerivedMesh *dm, DerivedMesh *source, DerivedMeshType type,
|
|
|
|
int numVerts, int numEdges, int numTessFaces,
|
|
|
|
int numLoops, int numPolys)
|
|
|
|
{
|
|
|
|
DM_from_template_ex(
|
|
|
|
dm, source, type,
|
|
|
|
numVerts, numEdges, numTessFaces,
|
|
|
|
numLoops, numPolys,
|
|
|
|
CD_MASK_DERIVEDMESH);
|
|
|
|
}
|
2006-08-28 03:12:36 +02:00
|
|
|
|
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 05:28:02 +01:00
|
|
|
int DM_release(DerivedMesh *dm)
|
2006-08-28 03:12:36 +02:00
|
|
|
{
|
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 05:28:02 +01:00
|
|
|
if (dm->needsFree) {
|
2009-05-23 05:24:15 +02:00
|
|
|
bvhcache_free(&dm->bvhCache);
|
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 05:28:02 +01:00
|
|
|
CustomData_free(&dm->vertData, dm->numVertData);
|
|
|
|
CustomData_free(&dm->edgeData, dm->numEdgeData);
|
2011-11-30 19:03:56 +01:00
|
|
|
CustomData_free(&dm->faceData, dm->numTessFaceData);
|
(NOTE: DO NOT TEST)
Start of planned DerivedMesh refactoring. The mface
interfaces in DerivedMesh have been renamed to reflect
their new status as tesselated face interfaces (rather
then the primary ones, which are now stored in mpolys).
short review: mpolys store "primary" face data, while
mfaces store the tesselated form of the mesh (generally
as triangles). mpolys are defined by mloops, and each
mpoly defines a range of loops it "owns" in the main
mloop array.
I've also added basic read-only face iterators, which
are implemented for CDDM, ccgsubsurf, and the bmeditmesh
derivedmesh. Since faces are now variable-length things,
trying to implement the same interface as mfaces would not
have worked well (especially since faces are stored as
an mpoly + a range of mloops).
I figure first we can evaluate these simple read-only
face iterators, then decide if a) we like using iterators
in DerivedMesh, b) how much of it should use them, and c)
if we want write-capable iterators.
I plan to write official docs on this design after I get
it more stable; I'm committing now because there's a rather
lot of changes, and I might do a merge soon.
2009-06-10 12:06:25 +02:00
|
|
|
CustomData_free(&dm->loopData, dm->numLoopData);
|
|
|
|
CustomData_free(&dm->polyData, dm->numPolyData);
|
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 05:28:02 +01:00
|
|
|
|
2014-04-09 17:37:54 +02:00
|
|
|
if (dm->mat) {
|
|
|
|
MEM_freeN(dm->mat);
|
|
|
|
dm->mat = NULL;
|
|
|
|
dm->totmat = 0;
|
|
|
|
}
|
|
|
|
|
2015-07-16 19:36:03 +02:00
|
|
|
MEM_SAFE_FREE(dm->looptris.array);
|
|
|
|
dm->looptris.num = 0;
|
|
|
|
dm->looptris.num_alloc = 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 05:28:02 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
CustomData_free_temporary(&dm->vertData, dm->numVertData);
|
|
|
|
CustomData_free_temporary(&dm->edgeData, dm->numEdgeData);
|
2011-11-30 19:03:56 +01:00
|
|
|
CustomData_free_temporary(&dm->faceData, dm->numTessFaceData);
|
2009-06-16 22:08:40 +02:00
|
|
|
CustomData_free_temporary(&dm->loopData, dm->numLoopData);
|
|
|
|
CustomData_free_temporary(&dm->polyData, dm->numPolyData);
|
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 05:28:02 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2006-08-28 03:12:36 +02:00
|
|
|
}
|
|
|
|
|
2011-06-14 05:16:08 +02:00
|
|
|
void DM_DupPolys(DerivedMesh *source, DerivedMesh *target)
|
(NOTE: DO NOT TEST)
Start of planned DerivedMesh refactoring. The mface
interfaces in DerivedMesh have been renamed to reflect
their new status as tesselated face interfaces (rather
then the primary ones, which are now stored in mpolys).
short review: mpolys store "primary" face data, while
mfaces store the tesselated form of the mesh (generally
as triangles). mpolys are defined by mloops, and each
mpoly defines a range of loops it "owns" in the main
mloop array.
I've also added basic read-only face iterators, which
are implemented for CDDM, ccgsubsurf, and the bmeditmesh
derivedmesh. Since faces are now variable-length things,
trying to implement the same interface as mfaces would not
have worked well (especially since faces are stored as
an mpoly + a range of mloops).
I figure first we can evaluate these simple read-only
face iterators, then decide if a) we like using iterators
in DerivedMesh, b) how much of it should use them, and c)
if we want write-capable iterators.
I plan to write official docs on this design after I get
it more stable; I'm committing now because there's a rather
lot of changes, and I might do a merge soon.
2009-06-10 12:06:25 +02:00
|
|
|
{
|
2011-10-27 14:17:02 +02:00
|
|
|
CustomData_free(&target->loopData, source->numLoopData);
|
|
|
|
CustomData_free(&target->polyData, source->numPolyData);
|
|
|
|
|
|
|
|
CustomData_copy(&source->loopData, &target->loopData, CD_MASK_DERIVEDMESH, CD_DUPLICATE, source->numLoopData);
|
|
|
|
CustomData_copy(&source->polyData, &target->polyData, CD_MASK_DERIVEDMESH, CD_DUPLICATE, source->numPolyData);
|
2009-08-18 22:05:08 +02:00
|
|
|
|
2011-06-14 05:16:08 +02:00
|
|
|
target->numLoopData = source->numLoopData;
|
|
|
|
target->numPolyData = source->numPolyData;
|
2009-08-18 22:05:08 +02:00
|
|
|
|
2011-06-14 05:16:08 +02:00
|
|
|
if (!CustomData_has_layer(&target->polyData, CD_MPOLY)) {
|
|
|
|
MPoly *mpoly;
|
|
|
|
MLoop *mloop;
|
2009-08-18 22:05:08 +02:00
|
|
|
|
2011-06-14 05:16:08 +02:00
|
|
|
mloop = source->dupLoopArray(source);
|
|
|
|
mpoly = source->dupPolyArray(source);
|
|
|
|
CustomData_add_layer(&target->loopData, CD_MLOOP, CD_ASSIGN, mloop, source->numLoopData);
|
|
|
|
CustomData_add_layer(&target->polyData, CD_MPOLY, CD_ASSIGN, mpoly, source->numPolyData);
|
(NOTE: DO NOT TEST)
Start of planned DerivedMesh refactoring. The mface
interfaces in DerivedMesh have been renamed to reflect
their new status as tesselated face interfaces (rather
then the primary ones, which are now stored in mpolys).
short review: mpolys store "primary" face data, while
mfaces store the tesselated form of the mesh (generally
as triangles). mpolys are defined by mloops, and each
mpoly defines a range of loops it "owns" in the main
mloop array.
I've also added basic read-only face iterators, which
are implemented for CDDM, ccgsubsurf, and the bmeditmesh
derivedmesh. Since faces are now variable-length things,
trying to implement the same interface as mfaces would not
have worked well (especially since faces are stored as
an mpoly + a range of mloops).
I figure first we can evaluate these simple read-only
face iterators, then decide if a) we like using iterators
in DerivedMesh, b) how much of it should use them, and c)
if we want write-capable iterators.
I plan to write official docs on this design after I get
it more stable; I'm committing now because there's a rather
lot of changes, and I might do a merge soon.
2009-06-10 12:06:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-30 19:36:43 +02:00
|
|
|
void DM_ensure_normals(DerivedMesh *dm)
|
|
|
|
{
|
|
|
|
if (dm->dirty & DM_DIRTY_NORMALS) {
|
|
|
|
dm->calcNormals(dm);
|
|
|
|
}
|
|
|
|
BLI_assert((dm->dirty & DM_DIRTY_NORMALS) == 0);
|
|
|
|
}
|
|
|
|
|
2015-07-16 19:36:03 +02:00
|
|
|
/**
|
|
|
|
* Ensure the array is large enough
|
2017-09-19 13:57:46 +02:00
|
|
|
*
|
|
|
|
* /note This function must always be thread-protected by caller. It should only be used by internal code.
|
2015-07-16 19:36:03 +02:00
|
|
|
*/
|
|
|
|
void DM_ensure_looptri_data(DerivedMesh *dm)
|
|
|
|
{
|
|
|
|
const unsigned int totpoly = dm->numPolyData;
|
|
|
|
const unsigned int totloop = dm->numLoopData;
|
|
|
|
const int looptris_num = poly_to_tri_count(totpoly, totloop);
|
|
|
|
|
2017-09-19 13:57:46 +02:00
|
|
|
BLI_assert(dm->looptris.array_wip == NULL);
|
|
|
|
|
|
|
|
SWAP(MLoopTri *, dm->looptris.array, dm->looptris.array_wip);
|
|
|
|
|
2015-07-16 19:36:03 +02:00
|
|
|
if ((looptris_num > dm->looptris.num_alloc) ||
|
|
|
|
(looptris_num < dm->looptris.num_alloc * 2) ||
|
|
|
|
(totpoly == 0))
|
|
|
|
{
|
2017-09-19 13:57:46 +02:00
|
|
|
MEM_SAFE_FREE(dm->looptris.array_wip);
|
2015-07-16 19:36:03 +02:00
|
|
|
dm->looptris.num_alloc = 0;
|
|
|
|
dm->looptris.num = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (totpoly) {
|
2017-09-19 13:57:46 +02:00
|
|
|
if (dm->looptris.array_wip == NULL) {
|
2018-01-14 22:14:20 +01:00
|
|
|
dm->looptris.array_wip = MEM_malloc_arrayN(looptris_num, sizeof(*dm->looptris.array_wip), __func__);
|
2015-07-16 19:36:03 +02:00
|
|
|
dm->looptris.num_alloc = looptris_num;
|
|
|
|
}
|
|
|
|
|
|
|
|
dm->looptris.num = looptris_num;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-18 20:00:23 +01:00
|
|
|
void DM_to_mesh(DerivedMesh *dm, Mesh *me, Object *ob, CustomDataMask mask, bool take_ownership)
|
2006-08-28 03:12:36 +02:00
|
|
|
{
|
|
|
|
/* dm might depend on me, so we need to do everything with a local copy */
|
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 05:28:02 +01:00
|
|
|
Mesh tmp = *me;
|
2011-11-16 18:09:41 +01:00
|
|
|
int totvert, totedge /*, totface */ /* UNUSED */, totloop, totpoly;
|
2012-05-12 21:18:02 +02:00
|
|
|
int did_shapekeys = 0;
|
2018-05-30 10:28:24 +02:00
|
|
|
eCDAllocType alloctype = CD_DUPLICATE;
|
2015-02-18 20:00:23 +01:00
|
|
|
|
|
|
|
if (take_ownership && dm->type == DM_TYPE_CDDM && dm->needsFree) {
|
|
|
|
bool has_any_referenced_layers =
|
|
|
|
CustomData_has_referenced(&dm->vertData) ||
|
|
|
|
CustomData_has_referenced(&dm->edgeData) ||
|
|
|
|
CustomData_has_referenced(&dm->loopData) ||
|
|
|
|
CustomData_has_referenced(&dm->faceData) ||
|
|
|
|
CustomData_has_referenced(&dm->polyData);
|
|
|
|
if (!has_any_referenced_layers) {
|
|
|
|
alloctype = CD_ASSIGN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-31 10:50:24 +01:00
|
|
|
CustomData_reset(&tmp.vdata);
|
|
|
|
CustomData_reset(&tmp.edata);
|
|
|
|
CustomData_reset(&tmp.fdata);
|
|
|
|
CustomData_reset(&tmp.ldata);
|
|
|
|
CustomData_reset(&tmp.pdata);
|
2006-08-28 03:12:36 +02:00
|
|
|
|
2013-06-04 18:02:54 +02:00
|
|
|
DM_ensure_normals(dm);
|
|
|
|
|
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 05:28:02 +01:00
|
|
|
totvert = tmp.totvert = dm->getNumVerts(dm);
|
|
|
|
totedge = tmp.totedge = dm->getNumEdges(dm);
|
2011-12-03 03:11:38 +01:00
|
|
|
totloop = tmp.totloop = dm->getNumLoops(dm);
|
2011-11-29 14:01:51 +01:00
|
|
|
totpoly = tmp.totpoly = dm->getNumPolys(dm);
|
2013-01-10 06:50:21 +01:00
|
|
|
tmp.totface = 0;
|
2006-08-28 03:12:36 +02:00
|
|
|
|
2015-02-18 20:00:23 +01:00
|
|
|
CustomData_copy(&dm->vertData, &tmp.vdata, mask, alloctype, totvert);
|
|
|
|
CustomData_copy(&dm->edgeData, &tmp.edata, mask, alloctype, totedge);
|
|
|
|
CustomData_copy(&dm->loopData, &tmp.ldata, mask, alloctype, totloop);
|
|
|
|
CustomData_copy(&dm->polyData, &tmp.pdata, mask, alloctype, totpoly);
|
2013-02-26 15:32:53 +01:00
|
|
|
tmp.cd_flag = dm->cd_flag;
|
2018-05-15 13:26:24 +02:00
|
|
|
tmp.runtime.deformed_only = dm->deformedOnly;
|
2006-08-28 03:12:36 +02:00
|
|
|
|
2011-04-15 07:20:18 +02:00
|
|
|
if (CustomData_has_layer(&dm->vertData, CD_SHAPEKEY)) {
|
|
|
|
KeyBlock *kb;
|
2012-01-30 04:54:24 +01:00
|
|
|
int uid;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2011-04-15 07:20:18 +02:00
|
|
|
if (ob) {
|
2012-05-12 21:18:02 +02:00
|
|
|
kb = BLI_findlink(&me->key->block, ob->shapenr - 1);
|
2012-01-30 04:54:24 +01:00
|
|
|
if (kb) {
|
|
|
|
uid = kb->uid;
|
2011-04-15 07:20:18 +02:00
|
|
|
}
|
2012-01-30 04:54:24 +01:00
|
|
|
else {
|
2011-11-25 00:09:55 +01:00
|
|
|
printf("%s: error - could not find active shapekey %d!\n",
|
2012-05-12 21:18:02 +02:00
|
|
|
__func__, ob->shapenr - 1);
|
2011-11-25 00:09:55 +01:00
|
|
|
|
2012-01-30 04:54:24 +01:00
|
|
|
uid = INT_MAX;
|
2011-04-15 07:20:18 +02:00
|
|
|
}
|
2012-01-30 04:54:24 +01:00
|
|
|
}
|
|
|
|
else {
|
2012-08-17 16:43:20 +02:00
|
|
|
/* if no object, set to INT_MAX so we don't mess up any shapekey layers */
|
2012-01-30 04:54:24 +01:00
|
|
|
uid = INT_MAX;
|
2011-04-15 07:20:18 +02:00
|
|
|
}
|
2012-01-30 04:54:24 +01:00
|
|
|
|
|
|
|
shapekey_layers_to_keyblocks(dm, me, uid);
|
2011-04-15 07:20:18 +02:00
|
|
|
did_shapekeys = 1;
|
|
|
|
}
|
2013-06-10 15:01:41 +02:00
|
|
|
|
|
|
|
/* copy texture space */
|
2013-08-04 01:58:17 +02:00
|
|
|
if (ob) {
|
|
|
|
BKE_mesh_texspace_copy_from_object(&tmp, ob);
|
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
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 05:28:02 +01:00
|
|
|
/* not all DerivedMeshes store their verts/edges/faces in CustomData, so
|
2012-03-09 19:28:30 +01:00
|
|
|
* we set them here in case they are missing */
|
2015-02-18 20:00:23 +01:00
|
|
|
if (!CustomData_has_layer(&tmp.vdata, CD_MVERT)) {
|
|
|
|
CustomData_add_layer(&tmp.vdata, CD_MVERT, CD_ASSIGN,
|
|
|
|
(alloctype == CD_ASSIGN) ? dm->getVertArray(dm) : dm->dupVertArray(dm),
|
|
|
|
totvert);
|
|
|
|
}
|
|
|
|
if (!CustomData_has_layer(&tmp.edata, CD_MEDGE)) {
|
|
|
|
CustomData_add_layer(&tmp.edata, CD_MEDGE, CD_ASSIGN,
|
|
|
|
(alloctype == CD_ASSIGN) ? dm->getEdgeArray(dm) : dm->dupEdgeArray(dm),
|
|
|
|
totedge);
|
|
|
|
}
|
2012-03-24 07:18:31 +01:00
|
|
|
if (!CustomData_has_layer(&tmp.pdata, CD_MPOLY)) {
|
2015-02-18 20:00:23 +01:00
|
|
|
tmp.mloop = (alloctype == CD_ASSIGN) ? dm->getLoopArray(dm) : dm->dupLoopArray(dm);
|
|
|
|
tmp.mpoly = (alloctype == CD_ASSIGN) ? dm->getPolyArray(dm) : dm->dupPolyArray(dm);
|
2011-06-14 05:16:08 +02:00
|
|
|
|
|
|
|
CustomData_add_layer(&tmp.ldata, CD_MLOOP, CD_ASSIGN, tmp.mloop, tmp.totloop);
|
|
|
|
CustomData_add_layer(&tmp.pdata, CD_MPOLY, CD_ASSIGN, tmp.mpoly, tmp.totpoly);
|
|
|
|
}
|
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 05:28:02 +01:00
|
|
|
|
2010-09-26 20:29:54 +02:00
|
|
|
/* object had got displacement layer, should copy this layer to save sculpted data */
|
|
|
|
/* NOTE: maybe some other layers should be copied? nazgul */
|
2012-03-24 07:18:31 +01:00
|
|
|
if (CustomData_has_layer(&me->ldata, CD_MDISPS)) {
|
2011-04-15 07:20:18 +02:00
|
|
|
if (totloop == me->totloop) {
|
|
|
|
MDisps *mdisps = CustomData_get_layer(&me->ldata, CD_MDISPS);
|
2015-02-18 20:00:23 +01:00
|
|
|
CustomData_add_layer(&tmp.ldata, CD_MDISPS, alloctype, mdisps, totloop);
|
2010-09-26 20:29:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-20 23:56:26 +01:00
|
|
|
/* yes, must be before _and_ after tessellate */
|
2013-03-17 20:55:10 +01:00
|
|
|
BKE_mesh_update_customdata_pointers(&tmp, false);
|
2011-11-25 23:32:58 +01:00
|
|
|
|
2013-01-10 06:50:21 +01:00
|
|
|
/* since 2.65 caller must do! */
|
|
|
|
// BKE_mesh_tessface_calc(&tmp);
|
2011-11-25 23:32:58 +01:00
|
|
|
|
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 05:28:02 +01:00
|
|
|
CustomData_free(&me->vdata, me->totvert);
|
|
|
|
CustomData_free(&me->edata, me->totedge);
|
|
|
|
CustomData_free(&me->fdata, me->totface);
|
2009-06-16 22:08:40 +02:00
|
|
|
CustomData_free(&me->ldata, me->totloop);
|
|
|
|
CustomData_free(&me->pdata, me->totpoly);
|
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 05:28:02 +01:00
|
|
|
|
2012-03-09 19:28:30 +01:00
|
|
|
/* ok, this should now use new CD shapekey data,
|
2012-08-25 01:22:34 +02:00
|
|
|
* which should be fed through the modifier
|
2016-01-28 06:30:50 +01:00
|
|
|
* stack */
|
2012-03-24 07:18:31 +01:00
|
|
|
if (tmp.totvert != me->totvert && !did_shapekeys && me->key) {
|
2012-04-12 16:36:57 +02:00
|
|
|
printf("%s: YEEK! this should be recoded! Shape key loss!: ID '%s'\n", __func__, tmp.id.name);
|
2018-05-18 15:10:48 +02:00
|
|
|
if (tmp.key && !(tmp.id.tag & LIB_TAG_NO_MAIN)) {
|
2015-11-09 19:47:10 +01:00
|
|
|
id_us_min(&tmp.key->id);
|
2018-05-18 15:10:48 +02:00
|
|
|
}
|
2010-06-23 12:18:51 +02:00
|
|
|
tmp.key = NULL;
|
2006-08-28 03:12:36 +02:00
|
|
|
}
|
|
|
|
|
2013-02-04 12:28:31 +01:00
|
|
|
/* Clear selection history */
|
2016-03-03 14:44:05 +01:00
|
|
|
MEM_SAFE_FREE(tmp.mselect);
|
2013-02-04 12:28:31 +01:00
|
|
|
tmp.totselect = 0;
|
2016-03-03 14:44:05 +01:00
|
|
|
BLI_assert(ELEM(tmp.bb, NULL, me->bb));
|
2016-02-22 13:20:18 +01:00
|
|
|
if (me->bb) {
|
|
|
|
MEM_freeN(me->bb);
|
2016-03-03 14:44:05 +01:00
|
|
|
tmp.bb = NULL;
|
2016-02-22 13:20:18 +01:00
|
|
|
}
|
2013-02-04 12:28:31 +01:00
|
|
|
|
2014-06-24 15:50:12 +02:00
|
|
|
/* skip the listbase */
|
|
|
|
MEMCPY_STRUCT_OFS(me, &tmp, id.prev);
|
2015-02-18 20:00:23 +01:00
|
|
|
|
|
|
|
if (take_ownership) {
|
|
|
|
if (alloctype == CD_ASSIGN) {
|
|
|
|
CustomData_free_typemask(&dm->vertData, dm->numVertData, ~mask);
|
|
|
|
CustomData_free_typemask(&dm->edgeData, dm->numEdgeData, ~mask);
|
|
|
|
CustomData_free_typemask(&dm->loopData, dm->numLoopData, ~mask);
|
|
|
|
CustomData_free_typemask(&dm->polyData, dm->numPolyData, ~mask);
|
|
|
|
}
|
|
|
|
dm->release(dm);
|
|
|
|
}
|
2006-08-28 03:12:36 +02:00
|
|
|
}
|
|
|
|
|
2018-06-21 18:24:32 +02:00
|
|
|
/** Utility function to convert an (evaluated) Mesh to a shape key block. */
|
|
|
|
/* Just a shallow wrapper around BKE_keyblock_convert_from_mesh,
|
|
|
|
* that ensures both evaluated mesh and original one has same number of vertices. */
|
|
|
|
void BKE_mesh_runtime_eval_to_meshkey(Mesh *me_deformed, Mesh *me, KeyBlock *kb)
|
2009-11-22 14:44:09 +01:00
|
|
|
{
|
2018-06-21 18:24:32 +02:00
|
|
|
const int totvert = me_deformed->totvert;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2015-07-02 08:20:22 +02:00
|
|
|
if (totvert == 0 || me->totvert == 0 || me->totvert != totvert) {
|
|
|
|
return;
|
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2018-06-21 18:24:32 +02:00
|
|
|
BKE_keyblock_convert_from_mesh(me_deformed, me->key, kb);
|
2009-11-22 14:44:09 +01:00
|
|
|
}
|
|
|
|
|
2015-07-02 08:20:22 +02:00
|
|
|
/**
|
|
|
|
* set the CD_FLAG_NOCOPY flag in custom data layers where the mask is
|
|
|
|
* zero for the layer type, so only layer types specified by the mask
|
|
|
|
* will be copied
|
|
|
|
*/
|
2006-12-05 18:42:03 +01:00
|
|
|
void DM_set_only_copy(DerivedMesh *dm, CustomDataMask mask)
|
|
|
|
{
|
|
|
|
CustomData_set_only_copy(&dm->vertData, mask);
|
|
|
|
CustomData_set_only_copy(&dm->edgeData, mask);
|
|
|
|
CustomData_set_only_copy(&dm->faceData, mask);
|
2012-10-01 16:23:57 +02:00
|
|
|
/* this wasn't in 2.63 and is disabled for 2.64 because it gives problems with
|
|
|
|
* weight paint mode when there are modifiers applied, needs further investigation,
|
|
|
|
* see replies to r50969, Campbell */
|
|
|
|
#if 0
|
2012-10-01 06:59:21 +02:00
|
|
|
CustomData_set_only_copy(&dm->loopData, mask);
|
|
|
|
CustomData_set_only_copy(&dm->polyData, mask);
|
2012-10-01 16:23:57 +02:00
|
|
|
#endif
|
2006-12-05 18:42:03 +01:00
|
|
|
}
|
|
|
|
|
2018-05-16 12:44:49 +02:00
|
|
|
static void mesh_set_only_copy(Mesh *mesh, CustomDataMask mask)
|
2018-05-11 09:53:52 +02:00
|
|
|
{
|
|
|
|
CustomData_set_only_copy(&mesh->vdata, mask);
|
|
|
|
CustomData_set_only_copy(&mesh->edata, mask);
|
|
|
|
CustomData_set_only_copy(&mesh->fdata, mask);
|
|
|
|
/* this wasn't in 2.63 and is disabled for 2.64 because it gives problems with
|
|
|
|
* weight paint mode when there are modifiers applied, needs further investigation,
|
|
|
|
* see replies to r50969, Campbell */
|
|
|
|
#if 0
|
|
|
|
CustomData_set_only_copy(&mesh->ldata, mask);
|
|
|
|
CustomData_set_only_copy(&mesh->pdata, mask);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-05-30 10:28:24 +02:00
|
|
|
void DM_add_vert_layer(DerivedMesh *dm, int type, eCDAllocType alloctype, void *layer)
|
2006-08-28 03:12:36 +02:00
|
|
|
{
|
2006-12-12 22:29:09 +01:00
|
|
|
CustomData_add_layer(&dm->vertData, type, alloctype, layer, dm->numVertData);
|
2006-08-28 03:12:36 +02:00
|
|
|
}
|
|
|
|
|
2018-05-30 10:28:24 +02:00
|
|
|
void DM_add_edge_layer(DerivedMesh *dm, int type, eCDAllocType alloctype, void *layer)
|
2006-08-28 03:12:36 +02:00
|
|
|
{
|
2006-12-12 22:29:09 +01:00
|
|
|
CustomData_add_layer(&dm->edgeData, type, alloctype, layer, dm->numEdgeData);
|
2006-08-28 03:12:36 +02:00
|
|
|
}
|
|
|
|
|
2018-05-30 10:28:24 +02:00
|
|
|
void DM_add_tessface_layer(DerivedMesh *dm, int type, eCDAllocType alloctype, void *layer)
|
2006-08-28 03:12:36 +02:00
|
|
|
{
|
2011-11-30 19:03:56 +01:00
|
|
|
CustomData_add_layer(&dm->faceData, type, alloctype, layer, dm->numTessFaceData);
|
2006-08-28 03:12:36 +02:00
|
|
|
}
|
|
|
|
|
2018-05-30 10:28:24 +02:00
|
|
|
void DM_add_loop_layer(DerivedMesh *dm, int type, eCDAllocType alloctype, void *layer)
|
2009-08-15 19:31:28 +02:00
|
|
|
{
|
|
|
|
CustomData_add_layer(&dm->loopData, type, alloctype, layer, dm->numLoopData);
|
|
|
|
}
|
|
|
|
|
2018-05-30 10:28:24 +02:00
|
|
|
void DM_add_poly_layer(DerivedMesh *dm, int type, eCDAllocType alloctype, void *layer)
|
2009-08-15 19:31:28 +02:00
|
|
|
{
|
|
|
|
CustomData_add_layer(&dm->polyData, type, alloctype, layer, dm->numPolyData);
|
|
|
|
}
|
|
|
|
|
2006-08-28 03:12:36 +02:00
|
|
|
void *DM_get_vert_data(DerivedMesh *dm, int index, int type)
|
|
|
|
{
|
2013-07-10 07:38:36 +02:00
|
|
|
BLI_assert(index >= 0 && index < dm->getNumVerts(dm));
|
2006-08-28 03:12:36 +02:00
|
|
|
return CustomData_get(&dm->vertData, index, type);
|
|
|
|
}
|
|
|
|
|
|
|
|
void *DM_get_edge_data(DerivedMesh *dm, int index, int type)
|
|
|
|
{
|
2013-07-10 07:38:36 +02:00
|
|
|
BLI_assert(index >= 0 && index < dm->getNumEdges(dm));
|
2006-08-28 03:12:36 +02:00
|
|
|
return CustomData_get(&dm->edgeData, index, type);
|
|
|
|
}
|
|
|
|
|
2011-11-29 06:09:54 +01:00
|
|
|
void *DM_get_tessface_data(DerivedMesh *dm, int index, int type)
|
2006-08-28 03:12:36 +02:00
|
|
|
{
|
2013-07-10 07:38:36 +02:00
|
|
|
BLI_assert(index >= 0 && index < dm->getNumTessFaces(dm));
|
2006-08-28 03:12:36 +02:00
|
|
|
return CustomData_get(&dm->faceData, index, type);
|
|
|
|
}
|
|
|
|
|
2012-10-30 20:20:17 +01:00
|
|
|
void *DM_get_poly_data(DerivedMesh *dm, int index, int type)
|
|
|
|
{
|
2013-07-10 07:38:36 +02:00
|
|
|
BLI_assert(index >= 0 && index < dm->getNumPolys(dm));
|
2012-10-30 20:20:17 +01:00
|
|
|
return CustomData_get(&dm->polyData, index, type);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-28 03:12:36 +02:00
|
|
|
void *DM_get_vert_data_layer(DerivedMesh *dm, int type)
|
|
|
|
{
|
2012-03-24 07:18:31 +01:00
|
|
|
if (type == CD_MVERT)
|
2010-01-06 13:05:46 +01:00
|
|
|
return dm->getVertArray(dm);
|
|
|
|
|
2006-08-28 03:12:36 +02:00
|
|
|
return CustomData_get_layer(&dm->vertData, type);
|
|
|
|
}
|
|
|
|
|
|
|
|
void *DM_get_edge_data_layer(DerivedMesh *dm, int type)
|
|
|
|
{
|
2012-03-24 07:18:31 +01:00
|
|
|
if (type == CD_MEDGE)
|
2010-01-06 13:05:46 +01:00
|
|
|
return dm->getEdgeArray(dm);
|
|
|
|
|
2006-08-28 03:12:36 +02:00
|
|
|
return CustomData_get_layer(&dm->edgeData, type);
|
|
|
|
}
|
|
|
|
|
2009-08-15 19:31:28 +02:00
|
|
|
void *DM_get_tessface_data_layer(DerivedMesh *dm, int type)
|
2006-08-28 03:12:36 +02:00
|
|
|
{
|
2011-11-13 16:13:59 +01:00
|
|
|
if (type == CD_MFACE)
|
2010-01-13 08:26:11 +01:00
|
|
|
return dm->getTessFaceArray(dm);
|
2010-01-06 13:05:46 +01:00
|
|
|
|
2006-08-28 03:12:36 +02:00
|
|
|
return CustomData_get_layer(&dm->faceData, type);
|
|
|
|
}
|
|
|
|
|
2011-11-29 06:09:54 +01:00
|
|
|
void *DM_get_poly_data_layer(DerivedMesh *dm, int type)
|
2009-08-15 19:31:28 +02:00
|
|
|
{
|
|
|
|
return CustomData_get_layer(&dm->polyData, type);
|
|
|
|
}
|
|
|
|
|
2012-02-05 12:30:26 +01:00
|
|
|
void *DM_get_loop_data_layer(DerivedMesh *dm, int type)
|
|
|
|
{
|
|
|
|
return CustomData_get_layer(&dm->loopData, type);
|
|
|
|
}
|
|
|
|
|
2006-08-28 03:12:36 +02:00
|
|
|
void DM_set_vert_data(DerivedMesh *dm, int index, int type, void *data)
|
|
|
|
{
|
|
|
|
CustomData_set(&dm->vertData, index, type, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DM_set_edge_data(DerivedMesh *dm, int index, int type, void *data)
|
|
|
|
{
|
|
|
|
CustomData_set(&dm->edgeData, index, type, data);
|
|
|
|
}
|
|
|
|
|
2011-11-29 06:09:54 +01:00
|
|
|
void DM_set_tessface_data(DerivedMesh *dm, int index, int type, void *data)
|
2006-08-28 03:12:36 +02:00
|
|
|
{
|
|
|
|
CustomData_set(&dm->faceData, index, type, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DM_copy_vert_data(DerivedMesh *source, DerivedMesh *dest,
|
2012-05-12 21:18:02 +02:00
|
|
|
int source_index, int dest_index, int count)
|
2006-08-28 03:12:36 +02:00
|
|
|
{
|
|
|
|
CustomData_copy_data(&source->vertData, &dest->vertData,
|
2012-05-12 21:18:02 +02:00
|
|
|
source_index, dest_index, count);
|
2006-08-28 03:12:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void DM_copy_edge_data(DerivedMesh *source, DerivedMesh *dest,
|
2012-05-12 21:18:02 +02:00
|
|
|
int source_index, int dest_index, int count)
|
2006-08-28 03:12:36 +02:00
|
|
|
{
|
|
|
|
CustomData_copy_data(&source->edgeData, &dest->edgeData,
|
2012-05-12 21:18:02 +02:00
|
|
|
source_index, dest_index, count);
|
2006-08-28 03:12:36 +02:00
|
|
|
}
|
|
|
|
|
(NOTE: DO NOT TEST)
Start of planned DerivedMesh refactoring. The mface
interfaces in DerivedMesh have been renamed to reflect
their new status as tesselated face interfaces (rather
then the primary ones, which are now stored in mpolys).
short review: mpolys store "primary" face data, while
mfaces store the tesselated form of the mesh (generally
as triangles). mpolys are defined by mloops, and each
mpoly defines a range of loops it "owns" in the main
mloop array.
I've also added basic read-only face iterators, which
are implemented for CDDM, ccgsubsurf, and the bmeditmesh
derivedmesh. Since faces are now variable-length things,
trying to implement the same interface as mfaces would not
have worked well (especially since faces are stored as
an mpoly + a range of mloops).
I figure first we can evaluate these simple read-only
face iterators, then decide if a) we like using iterators
in DerivedMesh, b) how much of it should use them, and c)
if we want write-capable iterators.
I plan to write official docs on this design after I get
it more stable; I'm committing now because there's a rather
lot of changes, and I might do a merge soon.
2009-06-10 12:06:25 +02:00
|
|
|
void DM_copy_tessface_data(DerivedMesh *source, DerivedMesh *dest,
|
2012-05-12 21:18:02 +02:00
|
|
|
int source_index, int dest_index, int count)
|
2006-08-28 03:12:36 +02:00
|
|
|
{
|
|
|
|
CustomData_copy_data(&source->faceData, &dest->faceData,
|
2012-05-12 21:18:02 +02:00
|
|
|
source_index, dest_index, count);
|
2006-08-28 03:12:36 +02:00
|
|
|
}
|
|
|
|
|
(NOTE: DO NOT TEST)
Start of planned DerivedMesh refactoring. The mface
interfaces in DerivedMesh have been renamed to reflect
their new status as tesselated face interfaces (rather
then the primary ones, which are now stored in mpolys).
short review: mpolys store "primary" face data, while
mfaces store the tesselated form of the mesh (generally
as triangles). mpolys are defined by mloops, and each
mpoly defines a range of loops it "owns" in the main
mloop array.
I've also added basic read-only face iterators, which
are implemented for CDDM, ccgsubsurf, and the bmeditmesh
derivedmesh. Since faces are now variable-length things,
trying to implement the same interface as mfaces would not
have worked well (especially since faces are stored as
an mpoly + a range of mloops).
I figure first we can evaluate these simple read-only
face iterators, then decide if a) we like using iterators
in DerivedMesh, b) how much of it should use them, and c)
if we want write-capable iterators.
I plan to write official docs on this design after I get
it more stable; I'm committing now because there's a rather
lot of changes, and I might do a merge soon.
2009-06-10 12:06:25 +02:00
|
|
|
void DM_copy_loop_data(DerivedMesh *source, DerivedMesh *dest,
|
|
|
|
int source_index, int dest_index, int count)
|
|
|
|
{
|
|
|
|
CustomData_copy_data(&source->loopData, &dest->loopData,
|
|
|
|
source_index, dest_index, count);
|
|
|
|
}
|
|
|
|
|
2011-11-29 06:09:54 +01:00
|
|
|
void DM_copy_poly_data(DerivedMesh *source, DerivedMesh *dest,
|
(NOTE: DO NOT TEST)
Start of planned DerivedMesh refactoring. The mface
interfaces in DerivedMesh have been renamed to reflect
their new status as tesselated face interfaces (rather
then the primary ones, which are now stored in mpolys).
short review: mpolys store "primary" face data, while
mfaces store the tesselated form of the mesh (generally
as triangles). mpolys are defined by mloops, and each
mpoly defines a range of loops it "owns" in the main
mloop array.
I've also added basic read-only face iterators, which
are implemented for CDDM, ccgsubsurf, and the bmeditmesh
derivedmesh. Since faces are now variable-length things,
trying to implement the same interface as mfaces would not
have worked well (especially since faces are stored as
an mpoly + a range of mloops).
I figure first we can evaluate these simple read-only
face iterators, then decide if a) we like using iterators
in DerivedMesh, b) how much of it should use them, and c)
if we want write-capable iterators.
I plan to write official docs on this design after I get
it more stable; I'm committing now because there's a rather
lot of changes, and I might do a merge soon.
2009-06-10 12:06:25 +02:00
|
|
|
int source_index, int dest_index, int count)
|
|
|
|
{
|
|
|
|
CustomData_copy_data(&source->polyData, &dest->polyData,
|
|
|
|
source_index, dest_index, count);
|
|
|
|
}
|
|
|
|
|
2006-08-28 03:12:36 +02:00
|
|
|
void DM_free_vert_data(struct DerivedMesh *dm, int index, int count)
|
|
|
|
{
|
|
|
|
CustomData_free_elem(&dm->vertData, index, count);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DM_free_edge_data(struct DerivedMesh *dm, int index, int count)
|
|
|
|
{
|
|
|
|
CustomData_free_elem(&dm->edgeData, index, count);
|
|
|
|
}
|
|
|
|
|
(NOTE: DO NOT TEST)
Start of planned DerivedMesh refactoring. The mface
interfaces in DerivedMesh have been renamed to reflect
their new status as tesselated face interfaces (rather
then the primary ones, which are now stored in mpolys).
short review: mpolys store "primary" face data, while
mfaces store the tesselated form of the mesh (generally
as triangles). mpolys are defined by mloops, and each
mpoly defines a range of loops it "owns" in the main
mloop array.
I've also added basic read-only face iterators, which
are implemented for CDDM, ccgsubsurf, and the bmeditmesh
derivedmesh. Since faces are now variable-length things,
trying to implement the same interface as mfaces would not
have worked well (especially since faces are stored as
an mpoly + a range of mloops).
I figure first we can evaluate these simple read-only
face iterators, then decide if a) we like using iterators
in DerivedMesh, b) how much of it should use them, and c)
if we want write-capable iterators.
I plan to write official docs on this design after I get
it more stable; I'm committing now because there's a rather
lot of changes, and I might do a merge soon.
2009-06-10 12:06:25 +02:00
|
|
|
void DM_free_tessface_data(struct DerivedMesh *dm, int index, int count)
|
2006-08-28 03:12:36 +02:00
|
|
|
{
|
|
|
|
CustomData_free_elem(&dm->faceData, index, count);
|
|
|
|
}
|
|
|
|
|
(NOTE: DO NOT TEST)
Start of planned DerivedMesh refactoring. The mface
interfaces in DerivedMesh have been renamed to reflect
their new status as tesselated face interfaces (rather
then the primary ones, which are now stored in mpolys).
short review: mpolys store "primary" face data, while
mfaces store the tesselated form of the mesh (generally
as triangles). mpolys are defined by mloops, and each
mpoly defines a range of loops it "owns" in the main
mloop array.
I've also added basic read-only face iterators, which
are implemented for CDDM, ccgsubsurf, and the bmeditmesh
derivedmesh. Since faces are now variable-length things,
trying to implement the same interface as mfaces would not
have worked well (especially since faces are stored as
an mpoly + a range of mloops).
I figure first we can evaluate these simple read-only
face iterators, then decide if a) we like using iterators
in DerivedMesh, b) how much of it should use them, and c)
if we want write-capable iterators.
I plan to write official docs on this design after I get
it more stable; I'm committing now because there's a rather
lot of changes, and I might do a merge soon.
2009-06-10 12:06:25 +02:00
|
|
|
void DM_free_loop_data(struct DerivedMesh *dm, int index, int count)
|
|
|
|
{
|
|
|
|
CustomData_free_elem(&dm->loopData, index, count);
|
|
|
|
}
|
|
|
|
|
2011-11-29 06:09:54 +01:00
|
|
|
void DM_free_poly_data(struct DerivedMesh *dm, int index, int count)
|
(NOTE: DO NOT TEST)
Start of planned DerivedMesh refactoring. The mface
interfaces in DerivedMesh have been renamed to reflect
their new status as tesselated face interfaces (rather
then the primary ones, which are now stored in mpolys).
short review: mpolys store "primary" face data, while
mfaces store the tesselated form of the mesh (generally
as triangles). mpolys are defined by mloops, and each
mpoly defines a range of loops it "owns" in the main
mloop array.
I've also added basic read-only face iterators, which
are implemented for CDDM, ccgsubsurf, and the bmeditmesh
derivedmesh. Since faces are now variable-length things,
trying to implement the same interface as mfaces would not
have worked well (especially since faces are stored as
an mpoly + a range of mloops).
I figure first we can evaluate these simple read-only
face iterators, then decide if a) we like using iterators
in DerivedMesh, b) how much of it should use them, and c)
if we want write-capable iterators.
I plan to write official docs on this design after I get
it more stable; I'm committing now because there's a rather
lot of changes, and I might do a merge soon.
2009-06-10 12:06:25 +02:00
|
|
|
{
|
|
|
|
CustomData_free_elem(&dm->polyData, index, count);
|
|
|
|
}
|
|
|
|
|
2015-07-02 08:20:22 +02:00
|
|
|
/**
|
|
|
|
* interpolates vertex data from the vertices indexed by src_indices in the
|
|
|
|
* source mesh using the given weights and stores the result in the vertex
|
|
|
|
* indexed by dest_index in the dest mesh
|
|
|
|
*/
|
|
|
|
void DM_interp_vert_data(
|
|
|
|
DerivedMesh *source, DerivedMesh *dest,
|
|
|
|
int *src_indices, float *weights,
|
|
|
|
int count, int dest_index)
|
2006-08-28 03:12:36 +02:00
|
|
|
{
|
|
|
|
CustomData_interp(&source->vertData, &dest->vertData, src_indices,
|
2012-05-12 21:18:02 +02:00
|
|
|
weights, NULL, count, dest_index);
|
2006-08-28 03:12:36 +02:00
|
|
|
}
|
|
|
|
|
2015-07-02 08:20:22 +02:00
|
|
|
/**
|
|
|
|
* interpolates edge data from the edges indexed by src_indices in the
|
|
|
|
* source mesh using the given weights and stores the result in the edge indexed
|
|
|
|
* by dest_index in the dest mesh.
|
|
|
|
* if weights is NULL, all weights default to 1.
|
|
|
|
* if vert_weights is non-NULL, any per-vertex edge data is interpolated using
|
|
|
|
* vert_weights[i] multiplied by weights[i].
|
|
|
|
*/
|
|
|
|
void DM_interp_edge_data(
|
|
|
|
DerivedMesh *source, DerivedMesh *dest,
|
|
|
|
int *src_indices,
|
|
|
|
float *weights, EdgeVertWeight *vert_weights,
|
|
|
|
int count, int dest_index)
|
2006-08-28 03:12:36 +02:00
|
|
|
{
|
|
|
|
CustomData_interp(&source->edgeData, &dest->edgeData, src_indices,
|
2012-05-12 21:18:02 +02:00
|
|
|
weights, (float *)vert_weights, count, dest_index);
|
2006-08-28 03:12:36 +02:00
|
|
|
}
|
|
|
|
|
2015-07-02 08:20:22 +02:00
|
|
|
/**
|
|
|
|
* interpolates face data from the faces indexed by src_indices in the
|
|
|
|
* source mesh using the given weights and stores the result in the face indexed
|
|
|
|
* by dest_index in the dest mesh.
|
|
|
|
* if weights is NULL, all weights default to 1.
|
|
|
|
* if vert_weights is non-NULL, any per-vertex face data is interpolated using
|
|
|
|
* vert_weights[i] multiplied by weights[i].
|
|
|
|
*/
|
|
|
|
void DM_interp_tessface_data(
|
|
|
|
DerivedMesh *source, DerivedMesh *dest,
|
|
|
|
int *src_indices,
|
|
|
|
float *weights, FaceVertWeight *vert_weights,
|
|
|
|
int count, int dest_index)
|
2006-08-28 03:12:36 +02:00
|
|
|
{
|
|
|
|
CustomData_interp(&source->faceData, &dest->faceData, src_indices,
|
2012-05-12 21:18:02 +02:00
|
|
|
weights, (float *)vert_weights, count, dest_index);
|
2006-08-28 03:12:36 +02:00
|
|
|
}
|
2005-03-27 22:34:18 +02:00
|
|
|
|
2015-07-02 08:20:22 +02:00
|
|
|
void DM_interp_loop_data(
|
|
|
|
DerivedMesh *source, DerivedMesh *dest,
|
|
|
|
int *src_indices,
|
|
|
|
float *weights, int count, int dest_index)
|
(NOTE: DO NOT TEST)
Start of planned DerivedMesh refactoring. The mface
interfaces in DerivedMesh have been renamed to reflect
their new status as tesselated face interfaces (rather
then the primary ones, which are now stored in mpolys).
short review: mpolys store "primary" face data, while
mfaces store the tesselated form of the mesh (generally
as triangles). mpolys are defined by mloops, and each
mpoly defines a range of loops it "owns" in the main
mloop array.
I've also added basic read-only face iterators, which
are implemented for CDDM, ccgsubsurf, and the bmeditmesh
derivedmesh. Since faces are now variable-length things,
trying to implement the same interface as mfaces would not
have worked well (especially since faces are stored as
an mpoly + a range of mloops).
I figure first we can evaluate these simple read-only
face iterators, then decide if a) we like using iterators
in DerivedMesh, b) how much of it should use them, and c)
if we want write-capable iterators.
I plan to write official docs on this design after I get
it more stable; I'm committing now because there's a rather
lot of changes, and I might do a merge soon.
2009-06-10 12:06:25 +02:00
|
|
|
{
|
|
|
|
CustomData_interp(&source->loopData, &dest->loopData, src_indices,
|
|
|
|
weights, NULL, count, dest_index);
|
|
|
|
}
|
|
|
|
|
2015-07-02 08:20:22 +02:00
|
|
|
void DM_interp_poly_data(
|
|
|
|
DerivedMesh *source, DerivedMesh *dest,
|
|
|
|
int *src_indices,
|
|
|
|
float *weights, int count, int dest_index)
|
(NOTE: DO NOT TEST)
Start of planned DerivedMesh refactoring. The mface
interfaces in DerivedMesh have been renamed to reflect
their new status as tesselated face interfaces (rather
then the primary ones, which are now stored in mpolys).
short review: mpolys store "primary" face data, while
mfaces store the tesselated form of the mesh (generally
as triangles). mpolys are defined by mloops, and each
mpoly defines a range of loops it "owns" in the main
mloop array.
I've also added basic read-only face iterators, which
are implemented for CDDM, ccgsubsurf, and the bmeditmesh
derivedmesh. Since faces are now variable-length things,
trying to implement the same interface as mfaces would not
have worked well (especially since faces are stored as
an mpoly + a range of mloops).
I figure first we can evaluate these simple read-only
face iterators, then decide if a) we like using iterators
in DerivedMesh, b) how much of it should use them, and c)
if we want write-capable iterators.
I plan to write official docs on this design after I get
it more stable; I'm committing now because there's a rather
lot of changes, and I might do a merge soon.
2009-06-10 12:06:25 +02:00
|
|
|
{
|
|
|
|
CustomData_interp(&source->polyData, &dest->polyData, src_indices,
|
|
|
|
weights, NULL, count, dest_index);
|
|
|
|
}
|
|
|
|
|
2013-12-25 22:26:41 +01:00
|
|
|
DerivedMesh *mesh_create_derived(Mesh *me, float (*vertCos)[3])
|
2005-03-27 22:34:18 +02:00
|
|
|
{
|
2013-12-25 22:26:41 +01:00
|
|
|
DerivedMesh *dm = CDDM_from_mesh(me);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (!dm)
|
2008-07-25 20:57:16 +02:00
|
|
|
return NULL;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2013-05-30 19:36:43 +02:00
|
|
|
if (vertCos) {
|
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 05:28:02 +01:00
|
|
|
CDDM_apply_vert_coords(dm, vertCos);
|
2013-05-30 19:36:43 +02:00
|
|
|
}
|
2005-03-27 23:27:12 +02:00
|
|
|
|
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 05:28:02 +01:00
|
|
|
return dm;
|
2005-03-27 22:34:18 +02:00
|
|
|
}
|
|
|
|
|
2012-12-21 08:28:14 +01:00
|
|
|
static float (*get_editbmesh_orco_verts(BMEditMesh *em))[3]
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 22:51:28 +02:00
|
|
|
{
|
2009-05-16 18:18:08 +02:00
|
|
|
BMIter iter;
|
|
|
|
BMVert *eve;
|
2012-12-21 08:28:14 +01:00
|
|
|
float (*orco)[3];
|
|
|
|
int i;
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 22:51:28 +02:00
|
|
|
|
|
|
|
/* these may not really be the orco's, but it's only for preview.
|
|
|
|
* could be solver better once, but isn't simple */
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2018-01-14 22:14:20 +01:00
|
|
|
orco = MEM_malloc_arrayN(em->bm->totvert, sizeof(float) * 3, "BMEditMesh Orco");
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 22:51:28 +02:00
|
|
|
|
2012-12-21 08:28:14 +01:00
|
|
|
BM_ITER_MESH_INDEX (eve, &iter, em->bm, BM_VERTS_OF_MESH, i) {
|
|
|
|
copy_v3_v3(orco[i], eve->co);
|
2011-11-06 16:39:20 +01:00
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 22:51:28 +02:00
|
|
|
return orco;
|
|
|
|
}
|
|
|
|
|
2009-05-23 05:24:15 +02:00
|
|
|
/* orco custom data layer */
|
2018-10-09 06:04:51 +02:00
|
|
|
static float (*get_orco_coords(Object *ob, BMEditMesh *em, int layer, int *free))[3]
|
2010-03-30 13:49:07 +02:00
|
|
|
{
|
2012-05-12 21:18:02 +02:00
|
|
|
*free = 0;
|
2010-03-30 13:49:07 +02:00
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (layer == CD_ORCO) {
|
2010-03-30 13:49:07 +02:00
|
|
|
/* get original coordinates */
|
2012-05-12 21:18:02 +02:00
|
|
|
*free = 1;
|
2010-03-30 13:49:07 +02:00
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (em)
|
2012-12-21 08:28:14 +01:00
|
|
|
return get_editbmesh_orco_verts(em);
|
2010-03-30 13:49:07 +02:00
|
|
|
else
|
2012-12-21 08:28:14 +01:00
|
|
|
return BKE_mesh_orco_verts_get(ob);
|
2010-03-30 13:49:07 +02:00
|
|
|
}
|
2012-03-24 07:18:31 +01:00
|
|
|
else if (layer == CD_CLOTH_ORCO) {
|
2010-03-30 13:49:07 +02:00
|
|
|
/* apply shape key for cloth, this should really be solved
|
2012-03-09 19:28:30 +01:00
|
|
|
* by a more flexible customdata system, but not simple */
|
2012-03-24 07:18:31 +01:00
|
|
|
if (!em) {
|
2010-03-30 13:49:07 +02:00
|
|
|
ClothModifierData *clmd = (ClothModifierData *)modifiers_findByType(ob, eModifierType_Cloth);
|
2012-09-19 12:12:07 +02:00
|
|
|
KeyBlock *kb = BKE_keyblock_from_key(BKE_key_from_object(ob), clmd->sim_parms->shapekey_rest);
|
2011-12-05 00:13:28 +01:00
|
|
|
|
2015-04-13 07:54:37 +02:00
|
|
|
if (kb && kb->data) {
|
2011-12-05 00:13:28 +01:00
|
|
|
return kb->data;
|
2015-04-13 07:54:37 +02:00
|
|
|
}
|
2010-03-30 13:49:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-05-11 09:53:52 +02:00
|
|
|
static Mesh *create_orco_mesh(Object *ob, Mesh *me, BMEditMesh *em, int layer)
|
|
|
|
{
|
|
|
|
Mesh *mesh;
|
|
|
|
float (*orco)[3];
|
|
|
|
int free;
|
|
|
|
|
|
|
|
if (em) {
|
2018-10-10 04:13:17 +02:00
|
|
|
mesh = BKE_mesh_from_bmesh_for_eval_nomain(em->bm, 0);
|
2018-05-11 09:53:52 +02:00
|
|
|
}
|
|
|
|
else {
|
2018-09-20 12:33:45 +02:00
|
|
|
mesh = BKE_mesh_copy_for_eval(me, true);
|
2018-05-11 09:53:52 +02:00
|
|
|
}
|
|
|
|
|
2018-10-09 06:04:51 +02:00
|
|
|
orco = get_orco_coords(ob, em, layer, &free);
|
2018-05-11 09:53:52 +02:00
|
|
|
|
|
|
|
if (orco) {
|
|
|
|
BKE_mesh_apply_vert_coords(mesh, orco);
|
|
|
|
if (free) MEM_freeN(orco);
|
|
|
|
}
|
|
|
|
|
|
|
|
return mesh;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void add_orco_mesh(
|
|
|
|
Object *ob, BMEditMesh *em, Mesh *mesh,
|
2018-10-10 06:00:37 +02:00
|
|
|
Mesh *me_orco, int layer)
|
2018-05-11 09:53:52 +02:00
|
|
|
{
|
|
|
|
float (*orco)[3], (*layerorco)[3];
|
|
|
|
int totvert, free;
|
|
|
|
|
|
|
|
totvert = mesh->totvert;
|
|
|
|
|
2018-10-10 06:00:37 +02:00
|
|
|
if (me_orco) {
|
2018-05-11 09:53:52 +02:00
|
|
|
free = 1;
|
|
|
|
|
2018-10-10 06:00:37 +02:00
|
|
|
if (me_orco->totvert == totvert) {
|
|
|
|
orco = BKE_mesh_vertexCos_get(me_orco, NULL);
|
2018-05-11 09:53:52 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
orco = BKE_mesh_vertexCos_get(mesh, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* TODO(sybren): totvert should potentially change here, as ob->data
|
|
|
|
* or em may have a different number of vertices than dm. */
|
2018-10-09 06:04:51 +02:00
|
|
|
orco = get_orco_coords(ob, em, layer, &free);
|
2018-05-11 09:53:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (orco) {
|
|
|
|
if (layer == CD_ORCO) {
|
|
|
|
BKE_mesh_orco_verts_transform(ob->data, orco, totvert, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(layerorco = CustomData_get_layer(&mesh->vdata, layer))) {
|
|
|
|
CustomData_add_layer(&mesh->vdata, layer, CD_CALLOC, NULL, mesh->totvert);
|
|
|
|
BKE_mesh_update_customdata_pointers(mesh, false);
|
|
|
|
|
|
|
|
layerorco = CustomData_get_layer(&mesh->vdata, layer);
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(layerorco, orco, sizeof(float) * 3 * totvert);
|
|
|
|
if (free) MEM_freeN(orco);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-10 05:28:31 +02:00
|
|
|
static void editmesh_update_statvis_color(const Scene *scene, Object *ob)
|
2013-04-17 11:27:23 +02:00
|
|
|
{
|
|
|
|
BMEditMesh *em = BKE_editmesh_from_object(ob);
|
2018-10-09 06:57:38 +02:00
|
|
|
Mesh *me = ob->data;
|
|
|
|
BKE_mesh_runtime_ensure_edit_data(me);
|
|
|
|
BKE_editmesh_statvis_calc(em, me->runtime.edit_data, &scene->toolsettings->statvis);
|
2013-04-17 11:27:23 +02:00
|
|
|
}
|
2011-04-15 07:20:18 +02:00
|
|
|
|
|
|
|
static void shapekey_layers_to_keyblocks(DerivedMesh *dm, Mesh *me, int actshape_uid)
|
|
|
|
{
|
|
|
|
KeyBlock *kb;
|
|
|
|
int i, j, tot;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2011-04-15 07:20:18 +02:00
|
|
|
if (!me->key)
|
2012-10-21 07:46:41 +02:00
|
|
|
return;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2011-04-15 07:20:18 +02:00
|
|
|
tot = CustomData_number_of_layers(&dm->vertData, CD_SHAPEKEY);
|
2012-05-12 21:18:02 +02:00
|
|
|
for (i = 0; i < tot; i++) {
|
2011-04-15 07:20:18 +02:00
|
|
|
CustomDataLayer *layer = &dm->vertData.layers[CustomData_get_layer_index_n(&dm->vertData, CD_SHAPEKEY, i)];
|
|
|
|
float (*cos)[3], (*kbcos)[3];
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2012-05-12 21:18:02 +02:00
|
|
|
for (kb = me->key->block.first; kb; kb = kb->next) {
|
2011-04-15 07:20:18 +02:00
|
|
|
if (kb->uid == layer->uid)
|
|
|
|
break;
|
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2011-04-15 07:20:18 +02:00
|
|
|
if (!kb) {
|
2012-09-19 12:12:07 +02:00
|
|
|
kb = BKE_keyblock_add(me->key, layer->name);
|
2011-04-15 07:20:18 +02:00
|
|
|
kb->uid = layer->uid;
|
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2011-04-15 07:20:18 +02:00
|
|
|
if (kb->data)
|
|
|
|
MEM_freeN(kb->data);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2011-04-15 07:20:18 +02:00
|
|
|
cos = CustomData_get_layer_n(&dm->vertData, CD_SHAPEKEY, i);
|
|
|
|
kb->totelem = dm->numVertData;
|
|
|
|
|
2018-02-01 15:53:49 +01:00
|
|
|
kb->data = kbcos = MEM_malloc_arrayN(kb->totelem, 3 * sizeof(float), "kbcos DerivedMesh.c");
|
2011-04-15 07:20:18 +02:00
|
|
|
if (kb->uid == actshape_uid) {
|
|
|
|
MVert *mvert = dm->getVertArray(dm);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2012-05-12 21:18:02 +02:00
|
|
|
for (j = 0; j < dm->numVertData; j++, kbcos++, mvert++) {
|
2011-04-15 07:20:18 +02:00
|
|
|
copy_v3_v3(*kbcos, mvert->co);
|
|
|
|
}
|
2012-03-24 07:18:31 +01:00
|
|
|
}
|
|
|
|
else {
|
2012-05-12 21:18:02 +02:00
|
|
|
for (j = 0; j < kb->totelem; j++, cos++, kbcos++) {
|
2011-04-15 07:20:18 +02:00
|
|
|
copy_v3_v3(*kbcos, *cos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2012-05-12 21:18:02 +02:00
|
|
|
for (kb = me->key->block.first; kb; kb = kb->next) {
|
2011-04-15 07:20:18 +02:00
|
|
|
if (kb->totelem != dm->numVertData) {
|
|
|
|
if (kb->data)
|
|
|
|
MEM_freeN(kb->data);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2011-04-15 07:20:18 +02:00
|
|
|
kb->totelem = dm->numVertData;
|
2018-01-14 22:14:20 +01:00
|
|
|
kb->data = MEM_calloc_arrayN(kb->totelem, 3 * sizeof(float), "kb->data derivedmesh.c");
|
2012-04-12 16:36:57 +02:00
|
|
|
fprintf(stderr, "%s: lost a shapekey layer: '%s'! (bmesh internal error)\n", __func__, kb->name);
|
2011-04-15 07:20:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-10 05:36:09 +02:00
|
|
|
static void add_shapekey_layers(Mesh *me_dst, Mesh *me_src, Object *UNUSED(ob))
|
2011-04-15 07:20:18 +02:00
|
|
|
{
|
|
|
|
KeyBlock *kb;
|
2018-10-10 05:36:09 +02:00
|
|
|
Key *key = me_src->key;
|
2012-01-30 02:18:49 +01:00
|
|
|
int i;
|
|
|
|
|
2018-10-10 05:36:09 +02:00
|
|
|
if (!me_src->key)
|
2011-04-15 07:20:18 +02:00
|
|
|
return;
|
2012-01-30 02:18:49 +01:00
|
|
|
|
|
|
|
/* ensure we can use mesh vertex count for derived mesh custom data */
|
2018-10-10 05:36:09 +02:00
|
|
|
if (me_src->totvert != me_dst->totvert) {
|
2012-01-30 02:18:49 +01:00
|
|
|
fprintf(stderr,
|
2018-10-10 05:36:09 +02:00
|
|
|
"%s: vertex size mismatch (mesh/eval) '%s' (%d != %d)\n",
|
|
|
|
__func__, me_src->id.name + 2, me_src->totvert, me_dst->totvert);
|
2011-04-15 07:20:18 +02:00
|
|
|
return;
|
|
|
|
}
|
2012-01-30 02:18:49 +01:00
|
|
|
|
2012-05-12 21:18:02 +02:00
|
|
|
for (i = 0, kb = key->block.first; kb; kb = kb->next, i++) {
|
2012-01-30 02:18:49 +01:00
|
|
|
int ci;
|
|
|
|
float *array;
|
|
|
|
|
2018-10-10 05:36:09 +02:00
|
|
|
if (me_src->totvert != kb->totelem) {
|
2012-01-30 02:18:49 +01:00
|
|
|
fprintf(stderr,
|
2012-04-12 16:36:57 +02:00
|
|
|
"%s: vertex size mismatch (Mesh '%s':%d != KeyBlock '%s':%d)\n",
|
2018-10-10 05:36:09 +02:00
|
|
|
__func__, me_src->id.name + 2, me_src->totvert, kb->name, kb->totelem);
|
|
|
|
array = MEM_calloc_arrayN((size_t)me_src->totvert, sizeof(float[3]), __func__);
|
2011-04-15 07:20:18 +02:00
|
|
|
}
|
2012-01-30 02:18:49 +01:00
|
|
|
else {
|
2018-10-10 05:36:09 +02:00
|
|
|
array = MEM_malloc_arrayN((size_t)me_src->totvert, sizeof(float[3]), __func__);
|
|
|
|
memcpy(array, kb->data, (size_t)me_src->totvert * sizeof(float[3]));
|
2011-04-15 07:20:18 +02:00
|
|
|
}
|
2012-01-30 02:18:49 +01:00
|
|
|
|
2018-10-10 05:36:09 +02:00
|
|
|
CustomData_add_layer_named(&me_dst->vdata, CD_SHAPEKEY, CD_ASSIGN, array, me_dst->totvert, kb->name);
|
|
|
|
ci = CustomData_get_layer_index_n(&me_dst->vdata, CD_SHAPEKEY, i);
|
2012-01-30 02:18:49 +01:00
|
|
|
|
2018-10-10 05:36:09 +02:00
|
|
|
me_dst->vdata.layers[ci].uid = kb->uid;
|
2011-04-15 07:20:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-04 17:52:30 +01:00
|
|
|
static void mesh_copy_autosmooth(Mesh *me, Mesh *me_orig)
|
|
|
|
{
|
|
|
|
if (me_orig->flag & ME_AUTOSMOOTH) {
|
|
|
|
me->flag |= ME_AUTOSMOOTH;
|
|
|
|
me->smoothresh = me_orig->smoothresh;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-02 08:20:22 +02:00
|
|
|
static void mesh_calc_modifiers(
|
2018-04-06 12:07:27 +02:00
|
|
|
struct Depsgraph *depsgraph, Scene *scene, Object *ob, float (*inputVertexCos)[3],
|
2018-05-22 19:42:41 +02:00
|
|
|
int useDeform,
|
2015-07-02 08:20:22 +02:00
|
|
|
const bool need_mapping, CustomDataMask dataMask,
|
|
|
|
const int index, const bool useCache, const bool build_shapekey_layers,
|
|
|
|
/* return args */
|
2018-10-10 06:00:37 +02:00
|
|
|
Mesh **r_deform, Mesh **r_final)
|
2005-03-27 22:34:18 +02:00
|
|
|
{
|
Add weight preview to WeightVG modifiers, and first, simple/basic refactor of how modifiers can generate preview.
User side:
* Preview for DynamicPaint should keep the same behavior (for now). Weight preview should be somawhat quicker, though.
* Preview for WeightVG modifiers is only active in WeightPaint mode, and if the affected vgroup is the active one.
* Last active preview modifier in stack wins!
Note: that modifier preview topic is yet to be further refined, quite raw/incomplete for now.
Dev side:
* In draw code, renamed DRAW_DYNAMIC_PAINT_PREVIEW flag to DRAW_MODIFIERS_PREVIEW
* Removed use of MOD_DPAINT_PREVIEW_READY in DynamicPaint code (seems unecessary, and if it was, should be of more general scope).
* Added eModifierTypeFlag_UsesPreview to ModifierTypeFlag, for modifiers that can generate some preview data.
* Added three new modifier funcs, to handle preview modifiers in draw code / mod stack.
* For weights preview: added the generic DM_update_weight_mcol func, which can update WEIGHT_MCOL layer with either a given array of weights (currently used by DynamicPaint only), or from current active vgroup(s).
So now, draw code is fully generic (i.e. no more modifier-type checking in it). Mod stack code is generic to some extent, but will need more work.
2012-01-22 18:54:23 +01:00
|
|
|
ModifierData *firstmd, *md, *previewmd = NULL;
|
2012-03-26 18:25:21 +02:00
|
|
|
CDMaskLink *datamasks, *curr;
|
2012-03-20 23:56:26 +01:00
|
|
|
/* XXX Always copying POLYINDEX, else tessellated data are no more valid! */
|
2013-06-13 02:33:48 +02:00
|
|
|
CustomDataMask mask, nextmask, previewmask = 0, append_mask = CD_MASK_ORIGINDEX;
|
2005-08-11 05:31:33 +02:00
|
|
|
float (*deformedVerts)[3] = NULL;
|
2018-10-10 06:00:37 +02:00
|
|
|
int numVerts = ((Mesh *)ob->data)->totvert;
|
2018-05-22 19:42:41 +02:00
|
|
|
const bool useRenderParams = (DEG_get_mode(depsgraph) == DAG_EVAL_RENDER);
|
2015-07-02 08:20:22 +02:00
|
|
|
const int required_mode = useRenderParams ? eModifierMode_Render : eModifierMode_Realtime;
|
2014-01-27 17:52:21 +01:00
|
|
|
bool isPrevDeform = false;
|
2012-05-12 21:18:02 +02:00
|
|
|
MultiresModifierData *mmd = get_multires_modifier(scene, ob, 0);
|
2014-01-27 17:52:21 +01:00
|
|
|
const bool has_multires = (mmd && mmd->sculptlvl != 0);
|
|
|
|
bool multires_applied = false;
|
2018-04-05 18:20:27 +02:00
|
|
|
const bool sculpt_mode = ob->mode & OB_MODE_SCULPT && ob->sculpt && !useRenderParams;
|
2014-12-09 12:57:59 +01:00
|
|
|
const bool sculpt_dyntopo = (sculpt_mode && ob->sculpt->bm) && !useRenderParams;
|
2013-02-22 05:09:04 +01:00
|
|
|
|
Add weight preview to WeightVG modifiers, and first, simple/basic refactor of how modifiers can generate preview.
User side:
* Preview for DynamicPaint should keep the same behavior (for now). Weight preview should be somawhat quicker, though.
* Preview for WeightVG modifiers is only active in WeightPaint mode, and if the affected vgroup is the active one.
* Last active preview modifier in stack wins!
Note: that modifier preview topic is yet to be further refined, quite raw/incomplete for now.
Dev side:
* In draw code, renamed DRAW_DYNAMIC_PAINT_PREVIEW flag to DRAW_MODIFIERS_PREVIEW
* Removed use of MOD_DPAINT_PREVIEW_READY in DynamicPaint code (seems unecessary, and if it was, should be of more general scope).
* Added eModifierTypeFlag_UsesPreview to ModifierTypeFlag, for modifiers that can generate some preview data.
* Added three new modifier funcs, to handle preview modifiers in draw code / mod stack.
* For weights preview: added the generic DM_update_weight_mcol func, which can update WEIGHT_MCOL layer with either a given array of weights (currently used by DynamicPaint only), or from current active vgroup(s).
So now, draw code is fully generic (i.e. no more modifier-type checking in it). Mod stack code is generic to some extent, but will need more work.
2012-01-22 18:54:23 +01:00
|
|
|
/* Generic preview only in object mode! */
|
2018-04-05 18:20:27 +02:00
|
|
|
const bool do_mod_mcol = (ob->mode == OB_MODE_OBJECT);
|
2018-10-10 06:00:37 +02:00
|
|
|
const bool do_loop_normals = (((Mesh *)ob->data)->flag & ME_AUTOSMOOTH) != 0;
|
2014-04-13 12:18:51 +02:00
|
|
|
|
2013-08-19 11:05:34 +02:00
|
|
|
VirtualModifierData virtualModifierData;
|
|
|
|
|
2012-05-09 17:00:26 +02:00
|
|
|
ModifierApplyFlag app_flags = useRenderParams ? MOD_APPLY_RENDER : 0;
|
|
|
|
ModifierApplyFlag deform_app_flags = app_flags;
|
2015-07-02 08:20:22 +02:00
|
|
|
|
2018-10-10 06:00:37 +02:00
|
|
|
BLI_assert((((Mesh *)ob->data)->id.tag & LIB_TAG_COPIED_ON_WRITE_EVAL_RESULT) == 0);
|
2015-07-02 08:20:22 +02:00
|
|
|
|
2012-05-12 21:18:02 +02:00
|
|
|
if (useCache)
|
2012-05-09 17:00:26 +02:00
|
|
|
app_flags |= MOD_APPLY_USECACHE;
|
2012-05-12 21:18:02 +02:00
|
|
|
if (useDeform)
|
2012-05-09 17:00:26 +02:00
|
|
|
deform_app_flags |= MOD_APPLY_USECACHE;
|
|
|
|
|
2018-05-01 17:33:04 +02:00
|
|
|
/* TODO(sybren): do we really need three context objects? Or do we modify
|
|
|
|
* them on the fly to change the flags where needed? */
|
|
|
|
const ModifierEvalContext mectx_deform = {depsgraph, ob, deform_app_flags};
|
|
|
|
const ModifierEvalContext mectx_apply = {depsgraph, ob, app_flags};
|
|
|
|
const ModifierEvalContext mectx_orco = {depsgraph, ob, (app_flags & ~MOD_APPLY_USECACHE) | MOD_APPLY_ORCO};
|
|
|
|
|
2018-04-16 14:07:42 +02:00
|
|
|
md = firstmd = modifiers_getVirtualModifierList(ob, &virtualModifierData);
|
2007-12-17 12:47:24 +01:00
|
|
|
|
- added eModifierTypeFlag_RequiresOriginalData for modifiers that
can only follow deform (for example, they store mesh vertex
indices)
- added ModifierType.foreachObjectLink for iterating over Object
links inside modifier data (used for file load, relinking, etc)
- switched various modifiers_ functions to take object argument
instead of ListBase
- added user editable name field to modifiers
- bug fix, duplicate and make single user didn't relink object
pointers in modifier data
- added modifiers to outliner, needs icon
- added armature, hook, and softbody modifiers (softbody doesn't
do anything atm). added conversion of old hooks to modifiers.
NOTE-THE-FIRST: User name field is not initialized on loading 2.38 files
so if you have saved stuff with a cvs blender you will see blank names.
NOTE-THE-SECOND: Since modifiers aren't evaluated yet for non-Mesh
objects, hooks for lattices and curves are broken. Don't updated if
you actually, say, *use* Blender.
NOTE-THE-THIRD: Old hooks used a quirky weighting system during
deformation which can't be extended to modifiers. On the upside,
I doubt anyone relied on the old quirky system and the new system
makes much more sense. (Although the way falloff works is still
quite stupid I think).
2005-08-11 00:05:52 +02:00
|
|
|
modifiers_clearErrors(ob);
|
2005-08-04 09:25:43 +02:00
|
|
|
|
2018-09-30 17:07:38 +02:00
|
|
|
if (do_mod_mcol) {
|
Add weight preview to WeightVG modifiers, and first, simple/basic refactor of how modifiers can generate preview.
User side:
* Preview for DynamicPaint should keep the same behavior (for now). Weight preview should be somawhat quicker, though.
* Preview for WeightVG modifiers is only active in WeightPaint mode, and if the affected vgroup is the active one.
* Last active preview modifier in stack wins!
Note: that modifier preview topic is yet to be further refined, quite raw/incomplete for now.
Dev side:
* In draw code, renamed DRAW_DYNAMIC_PAINT_PREVIEW flag to DRAW_MODIFIERS_PREVIEW
* Removed use of MOD_DPAINT_PREVIEW_READY in DynamicPaint code (seems unecessary, and if it was, should be of more general scope).
* Added eModifierTypeFlag_UsesPreview to ModifierTypeFlag, for modifiers that can generate some preview data.
* Added three new modifier funcs, to handle preview modifiers in draw code / mod stack.
* For weights preview: added the generic DM_update_weight_mcol func, which can update WEIGHT_MCOL layer with either a given array of weights (currently used by DynamicPaint only), or from current active vgroup(s).
So now, draw code is fully generic (i.e. no more modifier-type checking in it). Mod stack code is generic to some extent, but will need more work.
2012-01-22 18:54:23 +01:00
|
|
|
/* Find the last active modifier generating a preview, or NULL if none. */
|
|
|
|
/* XXX Currently, DPaint modifier just ignores this.
|
|
|
|
* Needs a stupid hack...
|
|
|
|
* The whole "modifier preview" thing has to be (re?)designed, anyway! */
|
|
|
|
previewmd = modifiers_getLastPreview(scene, md, required_mode);
|
|
|
|
}
|
|
|
|
|
2013-06-13 02:33:48 +02:00
|
|
|
datamasks = modifiers_calcDataMasks(scene, ob, md, dataMask, required_mode, previewmd, previewmask);
|
|
|
|
curr = datamasks;
|
|
|
|
|
2018-10-10 06:00:37 +02:00
|
|
|
if (r_deform) {
|
|
|
|
*r_deform = NULL;
|
2015-07-02 08:20:22 +02:00
|
|
|
}
|
2018-10-10 06:00:37 +02:00
|
|
|
*r_final = NULL;
|
2005-07-19 02:21:01 +02:00
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (useDeform) {
|
|
|
|
if (inputVertexCos)
|
2009-06-08 22:08:19 +02:00
|
|
|
deformedVerts = inputVertexCos;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2006-08-28 03:12:36 +02:00
|
|
|
/* Apply all leading deforming modifiers */
|
2012-05-12 21:18:02 +02:00
|
|
|
for (; md; md = md->next, curr = curr->next) {
|
2015-03-30 12:17:07 +02:00
|
|
|
const ModifierTypeInfo *mti = modifierType_getInfo(md->type);
|
2005-07-19 22:14:17 +02:00
|
|
|
|
2015-07-02 08:20:22 +02:00
|
|
|
if (!modifier_isEnabled(scene, md, required_mode)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (useDeform < 0 && mti->dependsOnTime && mti->dependsOnTime(md)) {
|
|
|
|
continue;
|
|
|
|
}
|
2006-08-28 03:12:36 +02:00
|
|
|
|
2012-12-30 19:29:41 +01:00
|
|
|
if (mti->type == eModifierTypeType_OnlyDeform && !sculpt_dyntopo) {
|
2012-03-24 07:18:31 +01:00
|
|
|
if (!deformedVerts)
|
2018-10-10 06:00:37 +02:00
|
|
|
deformedVerts = BKE_mesh_vertexCos_get(ob->data, &numVerts);
|
2005-07-19 22:14:17 +02:00
|
|
|
|
2018-10-09 04:19:21 +02:00
|
|
|
modwrap_deformVerts(md, &mectx_deform, NULL, deformedVerts, numVerts);
|
2012-03-24 07:18:31 +01:00
|
|
|
}
|
|
|
|
else {
|
2005-07-19 22:14:17 +02:00
|
|
|
break;
|
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2008-07-28 13:01:34 +02:00
|
|
|
/* grab modifiers until index i */
|
2015-07-02 08:20:22 +02:00
|
|
|
if ((index != -1) && (BLI_findindex(&ob->modifiers, md) >= index))
|
2008-07-28 13:01:34 +02:00
|
|
|
break;
|
2005-07-19 22:14:17 +02:00
|
|
|
}
|
|
|
|
|
2006-08-28 03:12:36 +02:00
|
|
|
/* Result of all leading deforming modifiers is cached for
|
|
|
|
* places that wish to use the original mesh but with deformed
|
|
|
|
* coordinates (vpaint, etc.)
|
|
|
|
*/
|
2018-10-10 06:00:37 +02:00
|
|
|
if (r_deform) {
|
|
|
|
*r_deform = BKE_mesh_copy_for_eval(ob->data, true);
|
2018-05-11 09:53:52 +02:00
|
|
|
|
|
|
|
/* XXX: Is build_shapekey_layers ever even true? This should have crashed long ago... */
|
|
|
|
BLI_assert(!build_shapekey_layers);
|
2018-10-10 05:36:09 +02:00
|
|
|
if (build_shapekey_layers) {
|
2018-10-10 06:00:37 +02:00
|
|
|
add_shapekey_layers(*r_deform, ob->data, ob);
|
2018-10-10 05:36:09 +02:00
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (deformedVerts) {
|
2018-10-10 06:00:37 +02:00
|
|
|
BKE_mesh_apply_vert_coords(*r_deform, deformedVerts);
|
2006-09-07 08:44:25 +02:00
|
|
|
}
|
2006-08-30 05:05:30 +02:00
|
|
|
}
|
2012-03-24 07:18:31 +01:00
|
|
|
}
|
|
|
|
else {
|
2012-03-01 13:20:18 +01:00
|
|
|
/* default behavior for meshes */
|
2012-03-24 07:18:31 +01:00
|
|
|
if (inputVertexCos)
|
2008-07-25 20:57:16 +02:00
|
|
|
deformedVerts = inputVertexCos;
|
|
|
|
else
|
2018-10-10 06:00:37 +02:00
|
|
|
deformedVerts = BKE_mesh_vertexCos_get(ob->data, &numVerts);
|
2005-07-19 02:21:01 +02:00
|
|
|
}
|
|
|
|
|
2005-09-23 16:42:14 +02:00
|
|
|
|
2006-08-28 03:12:36 +02:00
|
|
|
/* Now apply all remaining modifiers. If useDeform is off then skip
|
2018-06-17 17:05:51 +02:00
|
|
|
* OnlyDeform ones.
|
2006-08-28 03:12:36 +02:00
|
|
|
*/
|
2018-10-10 06:00:37 +02:00
|
|
|
Mesh *me = NULL;
|
|
|
|
Mesh *me_orco = NULL;
|
|
|
|
Mesh *me_orco_cloth = NULL;
|
2006-08-30 12:55:46 +02:00
|
|
|
|
2012-05-12 21:18:02 +02:00
|
|
|
for (; md; md = md->next, curr = curr->next) {
|
2015-03-30 12:17:07 +02:00
|
|
|
const ModifierTypeInfo *mti = modifierType_getInfo(md->type);
|
2005-07-19 22:14:17 +02:00
|
|
|
|
2015-07-02 08:20:22 +02:00
|
|
|
if (!modifier_isEnabled(scene, md, required_mode)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mti->type == eModifierTypeType_OnlyDeform && !useDeform) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-10-10 06:00:37 +02:00
|
|
|
if ((mti->flags & eModifierTypeFlag_RequiresOriginalData) && me) {
|
2012-10-27 13:12:09 +02:00
|
|
|
modifier_setError(md, "Modifier requires original data, bad stack position");
|
- added eModifierTypeFlag_RequiresOriginalData for modifiers that
can only follow deform (for example, they store mesh vertex
indices)
- added ModifierType.foreachObjectLink for iterating over Object
links inside modifier data (used for file load, relinking, etc)
- switched various modifiers_ functions to take object argument
instead of ListBase
- added user editable name field to modifiers
- bug fix, duplicate and make single user didn't relink object
pointers in modifier data
- added modifiers to outliner, needs icon
- added armature, hook, and softbody modifiers (softbody doesn't
do anything atm). added conversion of old hooks to modifiers.
NOTE-THE-FIRST: User name field is not initialized on loading 2.38 files
so if you have saved stuff with a cvs blender you will see blank names.
NOTE-THE-SECOND: Since modifiers aren't evaluated yet for non-Mesh
objects, hooks for lattices and curves are broken. Don't updated if
you actually, say, *use* Blender.
NOTE-THE-THIRD: Old hooks used a quirky weighting system during
deformation which can't be extended to modifiers. On the upside,
I doubt anyone relied on the old quirky system and the new system
makes much more sense. (Although the way falloff works is still
quite stupid I think).
2005-08-11 00:05:52 +02:00
|
|
|
continue;
|
|
|
|
}
|
2015-07-02 08:20:22 +02:00
|
|
|
|
2012-12-30 19:29:41 +01:00
|
|
|
if (sculpt_mode &&
|
2014-05-09 10:29:21 +02:00
|
|
|
(!has_multires || multires_applied || sculpt_dyntopo))
|
2012-12-30 19:29:41 +01:00
|
|
|
{
|
2014-01-27 17:52:21 +01:00
|
|
|
bool unsupported = false;
|
2011-05-04 15:15:42 +02:00
|
|
|
|
2013-06-03 10:26:12 +02:00
|
|
|
if (md->type == eModifierType_Multires && ((MultiresModifierData *)md)->sculptlvl == 0) {
|
|
|
|
/* If multires is on level 0 skip it silently without warning message. */
|
2015-07-02 08:20:22 +02:00
|
|
|
if (!sculpt_dyntopo) {
|
2014-05-08 18:25:46 +02:00
|
|
|
continue;
|
2015-07-02 08:20:22 +02:00
|
|
|
}
|
2013-06-03 10:26:12 +02:00
|
|
|
}
|
|
|
|
|
2013-05-15 10:25:42 +02:00
|
|
|
if (sculpt_dyntopo && !useRenderParams)
|
2014-01-27 17:52:21 +01:00
|
|
|
unsupported = true;
|
2012-12-30 19:29:41 +01:00
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (scene->toolsettings->sculpt->flags & SCULPT_ONLY_DEFORM)
|
2014-01-27 17:52:21 +01:00
|
|
|
unsupported |= (mti->type != eModifierTypeType_OnlyDeform);
|
2011-05-04 15:15:42 +02:00
|
|
|
|
2012-05-12 21:18:02 +02:00
|
|
|
unsupported |= multires_applied;
|
2011-05-04 15:15:42 +02:00
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (unsupported) {
|
2014-05-08 18:25:46 +02:00
|
|
|
if (sculpt_dyntopo)
|
|
|
|
modifier_setError(md, "Not supported in dyntopo");
|
|
|
|
else
|
|
|
|
modifier_setError(md, "Not supported in sculpt mode");
|
2011-01-31 21:02:51 +01:00
|
|
|
continue;
|
|
|
|
}
|
2014-05-08 18:15:36 +02:00
|
|
|
else {
|
|
|
|
modifier_setError(md, "Hide, Mask and optimized display disabled");
|
|
|
|
}
|
2011-05-04 15:15:42 +02:00
|
|
|
}
|
2015-07-02 08:20:22 +02:00
|
|
|
|
|
|
|
if (need_mapping && !modifier_supportsMapping(md)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (useDeform < 0 && mti->dependsOnTime && mti->dependsOnTime(md)) {
|
|
|
|
continue;
|
|
|
|
}
|
2005-07-19 22:14:17 +02:00
|
|
|
|
2007-12-05 13:40:54 +01:00
|
|
|
/* add an orco layer if needed by this modifier */
|
2012-03-24 07:18:31 +01:00
|
|
|
if (mti->requiredDataMask)
|
2009-06-15 13:48:42 +02:00
|
|
|
mask = mti->requiredDataMask(ob, md);
|
2010-03-30 13:49:07 +02:00
|
|
|
else
|
|
|
|
mask = 0;
|
|
|
|
|
2018-10-10 06:00:37 +02:00
|
|
|
if (me && (mask & CD_MASK_ORCO)) {
|
|
|
|
add_orco_mesh(ob, NULL, me, me_orco, CD_ORCO);
|
2018-05-11 09:53:52 +02:00
|
|
|
}
|
2007-12-05 13:40:54 +01:00
|
|
|
|
2006-08-28 03:12:36 +02:00
|
|
|
/* How to apply modifier depends on (a) what we already have as
|
2018-05-11 09:53:52 +02:00
|
|
|
* a result of previous modifiers (could be a Mesh or just
|
2006-08-28 03:12:36 +02:00
|
|
|
* deformed vertices) and (b) what type the modifier is.
|
|
|
|
*/
|
2005-07-19 22:14:17 +02:00
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (mti->type == eModifierTypeType_OnlyDeform) {
|
2006-08-28 03:12:36 +02:00
|
|
|
/* No existing verts to deform, need to build them. */
|
2012-03-24 07:18:31 +01:00
|
|
|
if (!deformedVerts) {
|
2018-10-10 06:00:37 +02:00
|
|
|
if (me) {
|
2018-05-11 09:53:52 +02:00
|
|
|
/* Deforming a mesh, read the vertex locations
|
2006-08-28 03:12:36 +02:00
|
|
|
* out of the mesh and deform them. Once done with this
|
|
|
|
* run of deformers verts will be written back.
|
|
|
|
*/
|
2018-10-10 06:00:37 +02:00
|
|
|
deformedVerts = BKE_mesh_vertexCos_get(me, &numVerts);
|
2012-03-24 07:18:31 +01:00
|
|
|
}
|
|
|
|
else {
|
2018-10-10 06:00:37 +02:00
|
|
|
deformedVerts = BKE_mesh_vertexCos_get(ob->data, &numVerts);
|
2005-07-19 22:14:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-30 12:51:36 +02:00
|
|
|
/* if this is not the last modifier in the stack then recalculate the normals
|
|
|
|
* to avoid giving bogus normals to the next modifier see: [#23673] */
|
2012-05-20 21:49:27 +02:00
|
|
|
if (isPrevDeform && mti->dependsOnNormals && mti->dependsOnNormals(md)) {
|
2010-09-30 12:51:36 +02:00
|
|
|
/* XXX, this covers bug #23673, but we may need normal calc for other types */
|
2018-10-10 06:00:37 +02:00
|
|
|
if (me) {
|
|
|
|
BKE_mesh_apply_vert_coords(me, deformedVerts);
|
2010-09-30 12:51:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-10 06:00:37 +02:00
|
|
|
modwrap_deformVerts(md, &mectx_deform, me, deformedVerts, numVerts);
|
2012-03-24 07:18:31 +01:00
|
|
|
}
|
|
|
|
else {
|
2010-10-21 03:08:12 +02:00
|
|
|
/* determine which data layers are needed by following modifiers */
|
2012-03-24 07:18:31 +01:00
|
|
|
if (curr->next)
|
2012-05-12 21:18:02 +02:00
|
|
|
nextmask = curr->next->mask;
|
2010-10-21 03:08:12 +02:00
|
|
|
else
|
2012-05-12 21:18:02 +02:00
|
|
|
nextmask = dataMask;
|
2010-10-21 03:08:12 +02:00
|
|
|
|
2018-05-11 09:53:52 +02:00
|
|
|
/* apply vertex coordinates or build a Mesh as necessary */
|
2018-10-10 06:00:37 +02:00
|
|
|
if (me) {
|
2012-03-24 07:18:31 +01:00
|
|
|
if (deformedVerts) {
|
2018-10-10 06:00:37 +02:00
|
|
|
BKE_mesh_apply_vert_coords(me, deformedVerts);
|
2006-08-28 03:12:36 +02:00
|
|
|
}
|
2012-03-24 07:18:31 +01:00
|
|
|
}
|
|
|
|
else {
|
2018-10-10 06:00:37 +02:00
|
|
|
me = BKE_mesh_copy_for_eval(ob->data, true);
|
|
|
|
ASSERT_IS_VALID_MESH(me);
|
2006-08-28 03:12:36 +02:00
|
|
|
|
2018-10-10 05:36:09 +02:00
|
|
|
if (build_shapekey_layers) {
|
2018-10-10 06:00:37 +02:00
|
|
|
add_shapekey_layers(me, ob->data, ob);
|
2018-10-10 05:36:09 +02:00
|
|
|
}
|
2011-04-15 07:20:18 +02:00
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (deformedVerts) {
|
2018-10-10 06:00:37 +02:00
|
|
|
BKE_mesh_apply_vert_coords(me, deformedVerts);
|
2006-08-28 03:12:36 +02:00
|
|
|
}
|
2009-05-23 05:24:15 +02:00
|
|
|
|
2010-10-21 03:08:12 +02:00
|
|
|
/* Constructive modifiers need to have an origindex
|
|
|
|
* otherwise they wont have anywhere to copy the data from.
|
|
|
|
*
|
|
|
|
* Also create ORIGINDEX data if any of the following modifiers
|
|
|
|
* requests it, this way Mirror, Solidify etc will keep ORIGINDEX
|
|
|
|
* data by using generic DM_copy_vert_data() functions.
|
|
|
|
*/
|
2015-07-02 08:20:22 +02:00
|
|
|
if (need_mapping || (nextmask & CD_MASK_ORIGINDEX)) {
|
2010-10-21 03:08:12 +02:00
|
|
|
/* calc */
|
2018-10-10 06:00:37 +02:00
|
|
|
CustomData_add_layer(&me->vdata, CD_ORIGINDEX, CD_CALLOC, NULL, me->totvert);
|
|
|
|
CustomData_add_layer(&me->edata, CD_ORIGINDEX, CD_CALLOC, NULL, me->totedge);
|
|
|
|
CustomData_add_layer(&me->pdata, CD_ORIGINDEX, CD_CALLOC, NULL, me->totpoly);
|
2010-02-09 19:06:57 +01:00
|
|
|
|
2016-05-29 20:14:42 +02:00
|
|
|
/* Not worth parallelizing this, gives less than 0.1% overall speedup in best of best cases... */
|
2018-10-10 06:00:37 +02:00
|
|
|
range_vn_i(CustomData_get_layer(&me->vdata, CD_ORIGINDEX), me->totvert, 0);
|
|
|
|
range_vn_i(CustomData_get_layer(&me->edata, CD_ORIGINDEX), me->totedge, 0);
|
|
|
|
range_vn_i(CustomData_get_layer(&me->pdata, CD_ORIGINDEX), me->totpoly, 0);
|
2010-02-09 19:06:57 +01:00
|
|
|
}
|
2006-08-28 03:12:36 +02:00
|
|
|
}
|
|
|
|
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2018-05-11 09:53:52 +02:00
|
|
|
/* set the Mesh to only copy needed data */
|
2012-05-12 21:18:02 +02:00
|
|
|
mask = curr->mask;
|
2016-01-28 06:30:50 +01:00
|
|
|
/* needMapping check here fixes bug [#28112], otherwise it's
|
|
|
|
* possible that it won't be copied */
|
2011-07-08 13:03:37 +02:00
|
|
|
mask |= append_mask;
|
2018-10-10 06:00:37 +02:00
|
|
|
mesh_set_only_copy(me, mask | (need_mapping ? CD_MASK_ORIGINDEX : 0));
|
2018-05-11 09:53:52 +02:00
|
|
|
|
2016-01-28 06:30:50 +01:00
|
|
|
/* add cloth rest shape key if needed */
|
2012-03-24 07:18:31 +01:00
|
|
|
if (mask & CD_MASK_CLOTH_ORCO)
|
2018-10-10 06:00:37 +02:00
|
|
|
add_orco_mesh(ob, NULL, me, me_orco, CD_CLOTH_ORCO);
|
2010-03-30 13:49:07 +02:00
|
|
|
|
2007-12-05 13:40:54 +01:00
|
|
|
/* add an origspace layer if needed */
|
2012-03-26 18:25:21 +02:00
|
|
|
if ((curr->mask) & CD_MASK_ORIGSPACE_MLOOP) {
|
2018-10-10 06:00:37 +02:00
|
|
|
if (!CustomData_has_layer(&me->ldata, CD_ORIGSPACE_MLOOP)) {
|
|
|
|
CustomData_add_layer(&me->ldata, CD_ORIGSPACE_MLOOP, CD_CALLOC, NULL, me->totloop);
|
|
|
|
mesh_init_origspace(me);
|
2012-02-05 12:30:26 +01:00
|
|
|
}
|
|
|
|
}
|
2007-12-05 13:40:54 +01:00
|
|
|
|
2018-10-10 06:00:37 +02:00
|
|
|
Mesh *me_next = modwrap_applyModifier(md, &mectx_apply, me);
|
|
|
|
ASSERT_IS_VALID_MESH(me_next);
|
2006-08-28 03:12:36 +02:00
|
|
|
|
2018-10-10 06:00:37 +02:00
|
|
|
if (me_next) {
|
2018-05-11 09:53:52 +02:00
|
|
|
/* if the modifier returned a new mesh, release the old one */
|
2018-10-10 06:00:37 +02:00
|
|
|
if (me && me != me_next) {
|
|
|
|
BLI_assert(me != ob->data);
|
|
|
|
BKE_id_free(NULL, me);
|
2018-05-11 09:53:52 +02:00
|
|
|
}
|
2018-10-10 06:00:37 +02:00
|
|
|
me = me_next;
|
2005-07-26 04:44:59 +02:00
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (deformedVerts) {
|
2018-10-10 06:00:37 +02:00
|
|
|
if (deformedVerts != inputVertexCos) {
|
2005-07-26 04:44:59 +02:00
|
|
|
MEM_freeN(deformedVerts);
|
2018-10-10 06:00:37 +02:00
|
|
|
}
|
2005-07-26 04:44:59 +02:00
|
|
|
deformedVerts = NULL;
|
2005-07-19 22:14:17 +02:00
|
|
|
}
|
2018-12-04 17:52:30 +01:00
|
|
|
|
|
|
|
mesh_copy_autosmooth(me, ob->data);
|
2012-04-01 17:02:19 +02:00
|
|
|
}
|
2010-03-30 13:49:07 +02:00
|
|
|
|
2018-05-11 09:53:52 +02:00
|
|
|
/* create an orco mesh in parallel */
|
2012-03-24 07:18:31 +01:00
|
|
|
if (nextmask & CD_MASK_ORCO) {
|
2018-10-10 06:00:37 +02:00
|
|
|
if (!me_orco) {
|
|
|
|
me_orco = create_orco_mesh(ob, ob->data, NULL, CD_ORCO);
|
2018-05-11 09:53:52 +02:00
|
|
|
}
|
2010-03-30 13:49:07 +02:00
|
|
|
|
|
|
|
nextmask &= ~CD_MASK_ORCO;
|
2018-10-10 06:00:37 +02:00
|
|
|
mesh_set_only_copy(me_orco, nextmask | CD_MASK_ORIGINDEX |
|
2012-11-09 10:33:28 +01:00
|
|
|
(mti->requiredDataMask ?
|
|
|
|
mti->requiredDataMask(ob, md) : 0));
|
2013-05-30 19:36:43 +02:00
|
|
|
|
2018-10-10 06:00:37 +02:00
|
|
|
me_next = modwrap_applyModifier(md, &mectx_orco, me_orco);
|
|
|
|
ASSERT_IS_VALID_MESH(me_next);
|
2010-03-30 13:49:07 +02:00
|
|
|
|
2018-10-10 06:00:37 +02:00
|
|
|
if (me_next) {
|
2018-05-11 09:53:52 +02:00
|
|
|
/* if the modifier returned a new mesh, release the old one */
|
2018-10-10 06:00:37 +02:00
|
|
|
if (me_orco && me_orco != me_next) {
|
|
|
|
BLI_assert(me_orco != ob->data);
|
|
|
|
BKE_id_free(NULL, me_orco);
|
2018-05-11 09:53:52 +02:00
|
|
|
}
|
|
|
|
|
2018-10-10 06:00:37 +02:00
|
|
|
me_orco = me_next;
|
2010-03-30 13:49:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-11 09:53:52 +02:00
|
|
|
/* create cloth orco mesh in parallel */
|
2012-03-24 07:18:31 +01:00
|
|
|
if (nextmask & CD_MASK_CLOTH_ORCO) {
|
2018-10-10 06:00:37 +02:00
|
|
|
if (!me_orco_cloth) {
|
|
|
|
me_orco_cloth = create_orco_mesh(ob, ob->data, NULL, CD_CLOTH_ORCO);
|
2018-05-16 17:35:54 +02:00
|
|
|
}
|
2010-03-30 13:49:07 +02:00
|
|
|
|
|
|
|
nextmask &= ~CD_MASK_CLOTH_ORCO;
|
2018-10-10 06:00:37 +02:00
|
|
|
mesh_set_only_copy(me_orco_cloth, nextmask | CD_MASK_ORIGINDEX);
|
2013-05-30 19:36:43 +02:00
|
|
|
|
2018-10-10 06:00:37 +02:00
|
|
|
me_next = modwrap_applyModifier(md, &mectx_orco, me_orco_cloth);
|
|
|
|
ASSERT_IS_VALID_DM(me_next);
|
2010-03-30 13:49:07 +02:00
|
|
|
|
2018-10-10 06:00:37 +02:00
|
|
|
if (me_next) {
|
2018-05-11 09:53:52 +02:00
|
|
|
/* if the modifier returned a new mesh, release the old one */
|
2018-10-10 06:00:37 +02:00
|
|
|
if (me_orco_cloth && me_orco_cloth != me_next) {
|
|
|
|
BLI_assert(me_orco != ob->data);
|
|
|
|
BKE_id_free(NULL, me_orco_cloth);
|
2015-07-02 08:20:22 +02:00
|
|
|
}
|
2018-05-11 09:53:52 +02:00
|
|
|
|
2018-10-10 06:00:37 +02:00
|
|
|
me_orco_cloth = me_next;
|
2010-03-30 13:49:07 +02:00
|
|
|
}
|
|
|
|
}
|
2011-07-08 13:03:37 +02:00
|
|
|
|
|
|
|
/* in case of dynamic paint, make sure preview mask remains for following modifiers */
|
Add weight preview to WeightVG modifiers, and first, simple/basic refactor of how modifiers can generate preview.
User side:
* Preview for DynamicPaint should keep the same behavior (for now). Weight preview should be somawhat quicker, though.
* Preview for WeightVG modifiers is only active in WeightPaint mode, and if the affected vgroup is the active one.
* Last active preview modifier in stack wins!
Note: that modifier preview topic is yet to be further refined, quite raw/incomplete for now.
Dev side:
* In draw code, renamed DRAW_DYNAMIC_PAINT_PREVIEW flag to DRAW_MODIFIERS_PREVIEW
* Removed use of MOD_DPAINT_PREVIEW_READY in DynamicPaint code (seems unecessary, and if it was, should be of more general scope).
* Added eModifierTypeFlag_UsesPreview to ModifierTypeFlag, for modifiers that can generate some preview data.
* Added three new modifier funcs, to handle preview modifiers in draw code / mod stack.
* For weights preview: added the generic DM_update_weight_mcol func, which can update WEIGHT_MCOL layer with either a given array of weights (currently used by DynamicPaint only), or from current active vgroup(s).
So now, draw code is fully generic (i.e. no more modifier-type checking in it). Mod stack code is generic to some extent, but will need more work.
2012-01-22 18:54:23 +01:00
|
|
|
/* XXX Temp and hackish solution! */
|
2011-07-08 13:03:37 +02:00
|
|
|
if (md->type == eModifierType_DynamicPaint)
|
2012-03-22 09:41:50 +01:00
|
|
|
append_mask |= CD_MASK_PREVIEW_MLOOPCOL;
|
2017-05-29 16:05:35 +02:00
|
|
|
|
2018-10-10 06:00:37 +02:00
|
|
|
me->runtime.deformed_only = false;
|
2005-07-19 22:14:17 +02:00
|
|
|
}
|
2010-05-03 18:06:36 +02:00
|
|
|
|
2012-05-12 21:18:02 +02:00
|
|
|
isPrevDeform = (mti->type == eModifierTypeType_OnlyDeform);
|
2010-09-30 12:51:36 +02:00
|
|
|
|
2008-07-28 13:01:34 +02:00
|
|
|
/* grab modifiers until index i */
|
2015-07-02 08:20:22 +02:00
|
|
|
if ((index != -1) && (BLI_findindex(&ob->modifiers, md) >= index))
|
2008-07-28 13:01:34 +02:00
|
|
|
break;
|
2011-01-31 21:02:51 +01:00
|
|
|
|
2014-01-27 17:52:21 +01:00
|
|
|
if (sculpt_mode && md->type == eModifierType_Multires) {
|
|
|
|
multires_applied = true;
|
|
|
|
}
|
2005-07-19 22:14:17 +02:00
|
|
|
}
|
|
|
|
|
2012-05-12 21:18:02 +02:00
|
|
|
for (md = firstmd; md; md = md->next)
|
2007-12-17 12:47:24 +01:00
|
|
|
modifier_freeTemporaryData(md);
|
|
|
|
|
2018-05-11 09:53:52 +02:00
|
|
|
/* Yay, we are done. If we have a Mesh and deformed vertices
|
|
|
|
* need to apply these back onto the Mesh. If we have no
|
|
|
|
* Mesh then we need to build one.
|
2006-08-28 03:12:36 +02:00
|
|
|
*/
|
2018-10-10 06:00:37 +02:00
|
|
|
if (me) {
|
|
|
|
*r_final = me;
|
2009-04-02 16:38:40 +02:00
|
|
|
|
2018-05-11 09:53:52 +02:00
|
|
|
if (deformedVerts) {
|
2018-10-10 06:00:37 +02:00
|
|
|
BKE_mesh_apply_vert_coords(*r_final, deformedVerts);
|
2018-05-11 09:53:52 +02:00
|
|
|
}
|
2012-03-24 07:18:31 +01:00
|
|
|
}
|
|
|
|
else {
|
2018-10-10 06:00:37 +02:00
|
|
|
*r_final = BKE_mesh_copy_for_eval(ob->data, true);
|
2018-05-11 09:53:52 +02:00
|
|
|
|
2018-10-10 05:36:09 +02:00
|
|
|
if (build_shapekey_layers) {
|
2018-10-10 06:00:37 +02:00
|
|
|
add_shapekey_layers(*r_final, ob->data, ob);
|
2018-10-10 05:36:09 +02:00
|
|
|
}
|
2018-05-11 09:53:52 +02:00
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (deformedVerts) {
|
2018-10-10 06:00:37 +02:00
|
|
|
BKE_mesh_apply_vert_coords(*r_final, deformedVerts);
|
2006-09-07 08:44:25 +02:00
|
|
|
}
|
2005-03-27 22:34:18 +02:00
|
|
|
}
|
|
|
|
|
2007-12-05 13:40:54 +01:00
|
|
|
/* add an orco layer if needed */
|
2012-03-24 07:18:31 +01:00
|
|
|
if (dataMask & CD_MASK_ORCO) {
|
2018-10-10 06:00:37 +02:00
|
|
|
add_orco_mesh(ob, NULL, *r_final, me_orco, CD_ORCO);
|
2007-12-05 13:40:54 +01:00
|
|
|
|
2018-10-10 06:00:37 +02:00
|
|
|
if (r_deform && *r_deform)
|
|
|
|
add_orco_mesh(ob, NULL, *r_deform, NULL, CD_ORCO);
|
2008-01-09 15:40:25 +01:00
|
|
|
}
|
2007-12-05 13:40:54 +01:00
|
|
|
|
2014-04-13 12:18:51 +02:00
|
|
|
if (do_loop_normals) {
|
|
|
|
/* Compute loop normals (note: will compute poly and vert normals as well, if needed!) */
|
2018-10-10 06:00:37 +02:00
|
|
|
BKE_mesh_calc_normals_split(*r_final);
|
|
|
|
BKE_mesh_tessface_clear(*r_final);
|
2014-04-13 12:18:51 +02:00
|
|
|
}
|
2014-04-21 17:56:05 +02:00
|
|
|
|
2015-04-15 20:14:01 +02:00
|
|
|
if (sculpt_dyntopo == false) {
|
2015-07-16 19:36:03 +02:00
|
|
|
/* watch this! after 2.75a we move to from tessface to looptri (by default) */
|
2015-07-17 12:14:17 +02:00
|
|
|
if (dataMask & CD_MASK_MFACE) {
|
2018-10-10 06:00:37 +02:00
|
|
|
BKE_mesh_tessface_ensure(*r_final);
|
2015-07-17 12:14:17 +02:00
|
|
|
}
|
2012-03-18 07:49:32 +01:00
|
|
|
|
|
|
|
/* without this, drawing ngon tri's faces will show ugly tessellated face
|
|
|
|
* normals and will also have to calculate normals on the fly, try avoid
|
|
|
|
* this where possible since calculating polygon normals isn't fast,
|
|
|
|
* note that this isn't a problem for subsurf (only quads) or editmode
|
|
|
|
* which deals with drawing differently.
|
|
|
|
*
|
2013-05-30 19:36:43 +02:00
|
|
|
* Only calc vertex normals if they are flagged as dirty.
|
2014-05-08 17:48:00 +02:00
|
|
|
* If using loop normals, poly nors have already been computed.
|
2012-03-18 07:49:32 +01:00
|
|
|
*/
|
2014-05-08 17:48:00 +02:00
|
|
|
if (!do_loop_normals) {
|
2018-10-11 07:32:49 +02:00
|
|
|
BKE_mesh_ensure_normals_for_display(*r_final);
|
2014-05-08 17:48:00 +02:00
|
|
|
}
|
2012-02-06 07:56:54 +01:00
|
|
|
}
|
2011-12-07 02:12:53 +01:00
|
|
|
|
2017-01-27 18:47:11 +01:00
|
|
|
/* Some modifiers, like datatransfer, may generate those data as temp layer, we do not want to keep them,
|
|
|
|
* as they are used by display code when available (i.e. even if autosmooth is disabled). */
|
2018-10-10 06:00:37 +02:00
|
|
|
if (!do_loop_normals && CustomData_has_layer(&(*r_final)->ldata, CD_NORMAL)) {
|
|
|
|
CustomData_free_layers(&(*r_final)->ldata, CD_NORMAL, (*r_final)->totloop);
|
2017-01-27 18:47:11 +01:00
|
|
|
}
|
|
|
|
|
2018-10-10 06:00:37 +02:00
|
|
|
if (me_orco) {
|
|
|
|
BKE_id_free(NULL, me_orco);
|
2018-05-11 09:53:52 +02:00
|
|
|
}
|
2018-10-10 06:00:37 +02:00
|
|
|
if (me_orco_cloth) {
|
|
|
|
BKE_id_free(NULL, me_orco_cloth);
|
2018-05-11 09:53:52 +02:00
|
|
|
}
|
2007-12-05 13:40:54 +01:00
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (deformedVerts && deformedVerts != inputVertexCos)
|
2005-07-19 02:21:01 +02:00
|
|
|
MEM_freeN(deformedVerts);
|
2006-08-28 03:12:36 +02:00
|
|
|
|
2012-05-12 21:18:02 +02:00
|
|
|
BLI_linklist_free((LinkNode *)datamasks, NULL);
|
2005-03-27 22:34:18 +02:00
|
|
|
}
|
|
|
|
|
2018-05-11 09:53:52 +02:00
|
|
|
static void mesh_calc_modifiers_dm(
|
|
|
|
struct Depsgraph *depsgraph, Scene *scene, Object *ob, float (*inputVertexCos)[3],
|
2018-05-22 19:42:41 +02:00
|
|
|
int useDeform,
|
2018-05-11 09:53:52 +02:00
|
|
|
const bool need_mapping, CustomDataMask dataMask,
|
|
|
|
const int index, const bool useCache, const bool build_shapekey_layers,
|
|
|
|
/* return args */
|
|
|
|
DerivedMesh **r_deformdm, DerivedMesh **r_finaldm)
|
|
|
|
{
|
|
|
|
Mesh *deform_mesh = NULL, *final_mesh = NULL;
|
|
|
|
|
2018-05-20 08:52:10 +02:00
|
|
|
mesh_calc_modifiers(
|
2018-05-22 19:42:41 +02:00
|
|
|
depsgraph, scene, ob, inputVertexCos, useDeform,
|
2018-09-06 11:47:44 +02:00
|
|
|
need_mapping, dataMask, index, useCache, build_shapekey_layers,
|
2018-05-20 08:52:10 +02:00
|
|
|
(r_deformdm ? &deform_mesh : NULL), &final_mesh);
|
2018-05-11 09:53:52 +02:00
|
|
|
|
2018-05-20 08:52:10 +02:00
|
|
|
if (deform_mesh) {
|
2018-05-22 17:53:18 +02:00
|
|
|
*r_deformdm = CDDM_from_mesh_ex(deform_mesh, CD_DUPLICATE, CD_MASK_MESH);
|
2018-05-11 09:53:52 +02:00
|
|
|
BKE_id_free(NULL, deform_mesh);
|
|
|
|
}
|
|
|
|
|
2018-05-22 17:53:18 +02:00
|
|
|
*r_finaldm = CDDM_from_mesh_ex(final_mesh, CD_DUPLICATE, CD_MASK_MESH);
|
2018-05-11 09:53:52 +02:00
|
|
|
BKE_id_free(NULL, final_mesh);
|
|
|
|
}
|
|
|
|
|
2014-03-15 17:24:05 +01:00
|
|
|
float (*editbmesh_get_vertex_cos(BMEditMesh *em, int *r_numVerts))[3]
|
- 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 09:37:15 +02:00
|
|
|
{
|
2009-05-16 18:18:08 +02:00
|
|
|
BMIter iter;
|
|
|
|
BMVert *eve;
|
2012-12-21 08:28:14 +01:00
|
|
|
float (*cos)[3];
|
|
|
|
int i;
|
|
|
|
|
2014-03-15 17:24:05 +01:00
|
|
|
*r_numVerts = em->bm->totvert;
|
- 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 09:37:15 +02:00
|
|
|
|
2018-01-14 22:14:20 +01:00
|
|
|
cos = MEM_malloc_arrayN(em->bm->totvert, 3 * sizeof(float), "vertexcos");
|
2009-05-16 18:18:08 +02:00
|
|
|
|
2012-12-21 08:28:14 +01:00
|
|
|
BM_ITER_MESH_INDEX (eve, &iter, em->bm, BM_VERTS_OF_MESH, i) {
|
2011-11-06 16:39:20 +01:00
|
|
|
copy_v3_v3(cos[i], eve->co);
|
- 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 09:37:15 +02:00
|
|
|
}
|
|
|
|
|
2005-10-09 18:59:10 +02:00
|
|
|
return cos;
|
- 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 09:37:15 +02:00
|
|
|
}
|
|
|
|
|
2018-10-09 06:04:51 +02:00
|
|
|
bool editbmesh_modifier_is_enabled(Scene *scene, ModifierData *md, bool has_prev_mesh)
|
2007-07-28 23:04:30 +02:00
|
|
|
{
|
2015-03-30 12:17:07 +02:00
|
|
|
const ModifierTypeInfo *mti = modifierType_getInfo(md->type);
|
2015-07-02 08:20:22 +02:00
|
|
|
const int required_mode = eModifierMode_Realtime | eModifierMode_Editmode;
|
|
|
|
|
|
|
|
if (!modifier_isEnabled(scene, md, required_mode)) {
|
|
|
|
return false;
|
|
|
|
}
|
2007-07-28 23:04:30 +02:00
|
|
|
|
2018-10-09 06:04:51 +02:00
|
|
|
if ((mti->flags & eModifierTypeFlag_RequiresOriginalData) && has_prev_mesh) {
|
2012-10-27 13:12:09 +02:00
|
|
|
modifier_setError(md, "Modifier requires original data, bad stack position");
|
2014-12-01 17:11:18 +01:00
|
|
|
return false;
|
2007-07-28 23:04:30 +02:00
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2014-12-01 17:11:18 +01:00
|
|
|
return true;
|
2007-07-28 23:04:30 +02:00
|
|
|
}
|
|
|
|
|
2015-07-02 08:20:22 +02:00
|
|
|
static void editbmesh_calc_modifiers(
|
2018-04-06 12:07:27 +02:00
|
|
|
struct Depsgraph *depsgraph, Scene *scene, Object *ob,
|
2017-07-21 11:53:13 +02:00
|
|
|
BMEditMesh *em, CustomDataMask dataMask,
|
2015-07-02 08:20:22 +02:00
|
|
|
/* return args */
|
2018-10-09 06:04:51 +02:00
|
|
|
Mesh **r_cage, Mesh **r_final)
|
2013-07-05 02:13:14 +02:00
|
|
|
{
|
2018-09-30 17:07:38 +02:00
|
|
|
ModifierData *md;
|
- 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 09:37:15 +02:00
|
|
|
float (*deformedVerts)[3] = NULL;
|
2018-09-30 17:07:38 +02:00
|
|
|
CustomDataMask mask = 0, append_mask = 0;
|
2010-01-25 12:39:56 +01:00
|
|
|
int i, numVerts = 0, cageIndex = modifiers_getCageIndex(scene, ob, NULL, 1);
|
2012-03-26 18:25:21 +02:00
|
|
|
CDMaskLink *datamasks, *curr;
|
2015-07-02 08:20:22 +02:00
|
|
|
const int required_mode = eModifierMode_Realtime | eModifierMode_Editmode;
|
2018-10-10 06:11:00 +02:00
|
|
|
const bool do_init_statvis = false; /* FIXME: use V3D_OVERLAY_EDIT_STATVIS. */
|
2013-08-19 11:05:34 +02:00
|
|
|
VirtualModifierData virtualModifierData;
|
- 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 09:37:15 +02:00
|
|
|
|
2018-05-01 17:33:04 +02:00
|
|
|
/* TODO(sybren): do we really need multiple objects, or shall we change the flags where needed? */
|
|
|
|
const ModifierEvalContext mectx = {depsgraph, ob, 0};
|
|
|
|
const ModifierEvalContext mectx_orco = {depsgraph, ob, MOD_APPLY_ORCO};
|
2018-09-06 11:47:44 +02:00
|
|
|
const ModifierEvalContext mectx_cache = {depsgraph, ob, MOD_APPLY_USECACHE};
|
2018-05-01 17:33:04 +02:00
|
|
|
|
2015-01-19 14:11:40 +01:00
|
|
|
const bool do_loop_normals = (((Mesh *)(ob->data))->flag & ME_AUTOSMOOTH) != 0;
|
2014-04-13 12:18:51 +02:00
|
|
|
|
- added eModifierTypeFlag_RequiresOriginalData for modifiers that
can only follow deform (for example, they store mesh vertex
indices)
- added ModifierType.foreachObjectLink for iterating over Object
links inside modifier data (used for file load, relinking, etc)
- switched various modifiers_ functions to take object argument
instead of ListBase
- added user editable name field to modifiers
- bug fix, duplicate and make single user didn't relink object
pointers in modifier data
- added modifiers to outliner, needs icon
- added armature, hook, and softbody modifiers (softbody doesn't
do anything atm). added conversion of old hooks to modifiers.
NOTE-THE-FIRST: User name field is not initialized on loading 2.38 files
so if you have saved stuff with a cvs blender you will see blank names.
NOTE-THE-SECOND: Since modifiers aren't evaluated yet for non-Mesh
objects, hooks for lattices and curves are broken. Don't updated if
you actually, say, *use* Blender.
NOTE-THE-THIRD: Old hooks used a quirky weighting system during
deformation which can't be extended to modifiers. On the upside,
I doubt anyone relied on the old quirky system and the new system
makes much more sense. (Although the way falloff works is still
quite stupid I think).
2005-08-11 00:05:52 +02:00
|
|
|
modifiers_clearErrors(ob);
|
- 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 09:37:15 +02:00
|
|
|
|
2015-07-02 08:20:22 +02:00
|
|
|
if (r_cage && cageIndex == -1) {
|
2018-10-09 06:37:10 +02:00
|
|
|
*r_cage = BKE_mesh_from_editmesh_with_coords_thin_wrap(em, dataMask, NULL);
|
2018-12-04 17:52:30 +01:00
|
|
|
mesh_copy_autosmooth(*r_cage, ob->data);
|
2005-08-03 06:04:05 +02:00
|
|
|
}
|
- 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 09:37:15 +02:00
|
|
|
|
2013-08-19 11:05:34 +02:00
|
|
|
md = modifiers_getVirtualModifierList(ob, &virtualModifierData);
|
2006-12-05 18:42:03 +01:00
|
|
|
|
2013-07-01 02:42:44 +02:00
|
|
|
/* copied from mesh_calc_modifiers */
|
2018-09-30 17:07:38 +02:00
|
|
|
datamasks = modifiers_calcDataMasks(scene, ob, md, dataMask, required_mode, NULL, 0);
|
2006-12-05 18:42:03 +01:00
|
|
|
|
|
|
|
curr = datamasks;
|
2018-10-10 06:00:37 +02:00
|
|
|
|
|
|
|
Mesh *me = NULL;
|
|
|
|
Mesh *me_orco = NULL;
|
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
for (i = 0; md; i++, md = md->next, curr = curr->next) {
|
2015-03-30 12:17:07 +02:00
|
|
|
const ModifierTypeInfo *mti = modifierType_getInfo(md->type);
|
- 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 09:37:15 +02:00
|
|
|
|
2018-10-09 06:04:51 +02:00
|
|
|
if (!editbmesh_modifier_is_enabled(scene, md, me != NULL)) {
|
- added eModifierTypeFlag_RequiresOriginalData for modifiers that
can only follow deform (for example, they store mesh vertex
indices)
- added ModifierType.foreachObjectLink for iterating over Object
links inside modifier data (used for file load, relinking, etc)
- switched various modifiers_ functions to take object argument
instead of ListBase
- added user editable name field to modifiers
- bug fix, duplicate and make single user didn't relink object
pointers in modifier data
- added modifiers to outliner, needs icon
- added armature, hook, and softbody modifiers (softbody doesn't
do anything atm). added conversion of old hooks to modifiers.
NOTE-THE-FIRST: User name field is not initialized on loading 2.38 files
so if you have saved stuff with a cvs blender you will see blank names.
NOTE-THE-SECOND: Since modifiers aren't evaluated yet for non-Mesh
objects, hooks for lattices and curves are broken. Don't updated if
you actually, say, *use* Blender.
NOTE-THE-THIRD: Old hooks used a quirky weighting system during
deformation which can't be extended to modifiers. On the upside,
I doubt anyone relied on the old quirky system and the new system
makes much more sense. (Although the way falloff works is still
quite stupid I think).
2005-08-11 00:05:52 +02:00
|
|
|
continue;
|
2015-07-02 08:20:22 +02:00
|
|
|
}
|
- 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 09:37:15 +02:00
|
|
|
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 22:51:28 +02:00
|
|
|
/* add an orco layer if needed by this modifier */
|
2018-10-09 06:04:51 +02:00
|
|
|
if (me && mti->requiredDataMask) {
|
2009-06-15 13:48:42 +02:00
|
|
|
mask = mti->requiredDataMask(ob, md);
|
2018-10-09 06:04:51 +02:00
|
|
|
if (mask & CD_MASK_ORCO) {
|
|
|
|
add_orco_mesh(ob, em, me, me_orco, CD_ORCO);
|
|
|
|
}
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 22:51:28 +02:00
|
|
|
}
|
|
|
|
|
2006-08-28 03:12:36 +02:00
|
|
|
/* How to apply modifier depends on (a) what we already have as
|
|
|
|
* a result of previous modifiers (could be a DerivedMesh or just
|
|
|
|
* deformed vertices) and (b) what type the modifier is.
|
|
|
|
*/
|
- 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 09:37:15 +02:00
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (mti->type == eModifierTypeType_OnlyDeform) {
|
2006-08-28 03:12:36 +02:00
|
|
|
/* No existing verts to deform, need to build them. */
|
2012-03-24 07:18:31 +01:00
|
|
|
if (!deformedVerts) {
|
2018-10-09 06:04:51 +02:00
|
|
|
if (me) {
|
2006-08-28 03:12:36 +02:00
|
|
|
/* Deforming a derived mesh, read the vertex locations
|
|
|
|
* out of the mesh and deform them. Once done with this
|
|
|
|
* run of deformers verts will be written back.
|
|
|
|
*/
|
2018-10-09 06:04:51 +02:00
|
|
|
deformedVerts = BKE_mesh_vertexCos_get(me, &numVerts);
|
2012-03-24 07:18:31 +01:00
|
|
|
}
|
|
|
|
else {
|
2011-02-27 07:19:40 +01:00
|
|
|
deformedVerts = editbmesh_get_vertex_cos(em, &numVerts);
|
- 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 09:37:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-19 16:59:05 +02:00
|
|
|
if (mti->deformVertsEM)
|
2018-10-09 06:04:51 +02:00
|
|
|
modwrap_deformVertsEM(md, &mectx, em, me, deformedVerts, numVerts);
|
2012-05-09 17:00:26 +02:00
|
|
|
else
|
2018-10-09 06:04:51 +02:00
|
|
|
modwrap_deformVerts(md, &mectx, me, deformedVerts, numVerts);
|
2012-03-24 07:18:31 +01:00
|
|
|
}
|
|
|
|
else {
|
2018-10-09 06:04:51 +02:00
|
|
|
Mesh *me_next;
|
2006-08-28 03:12:36 +02:00
|
|
|
|
|
|
|
/* apply vertex coordinates or build a DerivedMesh as necessary */
|
2018-10-09 06:04:51 +02:00
|
|
|
if (me) {
|
2012-03-24 07:18:31 +01:00
|
|
|
if (deformedVerts) {
|
2018-10-09 06:04:51 +02:00
|
|
|
Mesh *me_temp = BKE_mesh_copy_for_eval(me, false);
|
2006-08-28 03:12:36 +02:00
|
|
|
|
2018-10-09 06:04:51 +02:00
|
|
|
if (!(r_cage && me == *r_cage)) {
|
|
|
|
BKE_id_free(NULL, me);
|
|
|
|
}
|
|
|
|
me = me_temp;
|
|
|
|
BKE_mesh_apply_vert_coords(me, deformedVerts);
|
2012-03-24 07:18:31 +01:00
|
|
|
}
|
2018-10-09 06:04:51 +02:00
|
|
|
else if (r_cage && me == *r_cage) {
|
|
|
|
/* 'me' may be changed by this modifier, so we need to copy it. */
|
|
|
|
me = BKE_mesh_copy_for_eval(me, false);
|
2006-08-28 03:12:36 +02:00
|
|
|
}
|
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
}
|
|
|
|
else {
|
2018-10-10 04:13:17 +02:00
|
|
|
me = BKE_mesh_from_bmesh_for_eval_nomain(em->bm, 0);
|
2018-10-09 06:04:51 +02:00
|
|
|
ASSERT_IS_VALID_MESH(me);
|
2006-08-28 03:12:36 +02:00
|
|
|
|
2018-12-04 17:52:30 +01:00
|
|
|
mesh_copy_autosmooth(me, ob->data);
|
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (deformedVerts) {
|
2018-10-09 06:04:51 +02:00
|
|
|
BKE_mesh_apply_vert_coords(me, deformedVerts);
|
2006-08-28 03:12:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 22:51:28 +02:00
|
|
|
/* create an orco derivedmesh in parallel */
|
2012-05-12 21:18:02 +02:00
|
|
|
mask = curr->mask;
|
2012-03-24 07:18:31 +01:00
|
|
|
if (mask & CD_MASK_ORCO) {
|
2018-10-09 06:04:51 +02:00
|
|
|
if (!me_orco) {
|
|
|
|
me_orco = create_orco_mesh(ob, ob->data, em, CD_ORCO);
|
|
|
|
}
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 22:51:28 +02:00
|
|
|
|
|
|
|
mask &= ~CD_MASK_ORCO;
|
2018-10-09 06:04:51 +02:00
|
|
|
mesh_set_only_copy(me_orco, mask | CD_MASK_ORIGINDEX);
|
2010-05-03 12:09:26 +02:00
|
|
|
|
2018-10-24 14:03:51 +02:00
|
|
|
me_next = modwrap_applyModifier(md, &mectx_orco, me_orco);
|
2018-10-09 06:04:51 +02:00
|
|
|
ASSERT_IS_VALID_MESH(me_next);
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 22:51:28 +02:00
|
|
|
|
2018-10-09 06:04:51 +02:00
|
|
|
if (me_next) {
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 22:51:28 +02:00
|
|
|
/* if the modifier returned a new dm, release the old one */
|
2018-10-09 06:04:51 +02:00
|
|
|
if (me_orco && me_orco != me_next) {
|
|
|
|
BKE_id_free(NULL, me_orco);
|
|
|
|
}
|
|
|
|
me_orco = me_next;
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 22:51:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-05 18:42:03 +01:00
|
|
|
/* set the DerivedMesh to only copy needed data */
|
2013-07-05 00:24:39 +02:00
|
|
|
mask |= append_mask;
|
2012-05-12 21:18:02 +02:00
|
|
|
mask = curr->mask; /* CD_MASK_ORCO may have been cleared above */
|
2006-12-05 18:42:03 +01:00
|
|
|
|
2018-10-09 06:04:51 +02:00
|
|
|
mesh_set_only_copy(me, mask | CD_MASK_ORIGINDEX);
|
2010-10-21 03:08:12 +02:00
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (mask & CD_MASK_ORIGSPACE_MLOOP) {
|
2018-10-09 06:04:51 +02:00
|
|
|
if (!CustomData_has_layer(&me->ldata, CD_ORIGSPACE_MLOOP)) {
|
|
|
|
CustomData_add_layer(&me->ldata, CD_ORIGSPACE_MLOOP, CD_CALLOC, NULL, me->totloop);
|
|
|
|
mesh_init_origspace(me);
|
2012-02-05 12:30:26 +01:00
|
|
|
}
|
|
|
|
}
|
2013-05-30 19:36:43 +02:00
|
|
|
|
2018-10-24 14:03:51 +02:00
|
|
|
me_next = modwrap_applyModifier(md, &mectx_cache, me);
|
2018-10-09 06:04:51 +02:00
|
|
|
ASSERT_IS_VALID_MESH(me_next);
|
2005-08-03 06:04:05 +02:00
|
|
|
|
2018-10-09 06:04:51 +02:00
|
|
|
if (me_next) {
|
|
|
|
if (me && me != me_next) {
|
|
|
|
BKE_id_free(NULL, me);
|
|
|
|
}
|
|
|
|
me = me_next;
|
2005-08-03 06:04:05 +02:00
|
|
|
|
|
|
|
if (deformedVerts) {
|
|
|
|
MEM_freeN(deformedVerts);
|
|
|
|
deformedVerts = NULL;
|
|
|
|
}
|
2018-12-04 17:52:30 +01:00
|
|
|
|
|
|
|
mesh_copy_autosmooth(me, ob->data);
|
2005-08-03 06:04:05 +02:00
|
|
|
}
|
2018-10-09 06:04:51 +02:00
|
|
|
me->runtime.deformed_only = false;
|
2005-08-03 06:04:05 +02:00
|
|
|
}
|
- 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 09:37:15 +02:00
|
|
|
|
2015-07-02 08:20:22 +02:00
|
|
|
if (r_cage && i == cageIndex) {
|
2018-10-09 06:04:51 +02:00
|
|
|
if (me && deformedVerts) {
|
|
|
|
*r_cage = BKE_mesh_copy_for_eval(me, false);
|
|
|
|
BKE_mesh_apply_vert_coords(*r_cage, deformedVerts);
|
2012-03-24 07:18:31 +01:00
|
|
|
}
|
2018-10-09 06:04:51 +02:00
|
|
|
else if (me) {
|
|
|
|
*r_cage = me;
|
2012-03-24 07:18:31 +01:00
|
|
|
}
|
|
|
|
else {
|
2018-10-10 06:18:34 +02:00
|
|
|
Mesh *me_orig = ob->data;
|
2018-10-09 06:04:51 +02:00
|
|
|
if (me_orig->id.tag & LIB_TAG_COPIED_ON_WRITE) {
|
|
|
|
BKE_mesh_runtime_ensure_edit_data(me_orig);
|
|
|
|
me_orig->runtime.edit_data->vertexCos = MEM_dupallocN(deformedVerts);
|
2018-04-19 11:03:58 +02:00
|
|
|
}
|
2018-10-09 06:37:10 +02:00
|
|
|
*r_cage = BKE_mesh_from_editmesh_with_coords_thin_wrap(
|
2018-10-09 06:04:51 +02:00
|
|
|
em, mask,
|
2015-07-02 08:20:22 +02:00
|
|
|
deformedVerts ? MEM_dupallocN(deformedVerts) : NULL);
|
2018-12-04 17:52:30 +01:00
|
|
|
mesh_copy_autosmooth(*r_cage, ob->data);
|
- 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 09:37:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-12 21:18:02 +02:00
|
|
|
BLI_linklist_free((LinkNode *)datamasks, NULL);
|
2006-12-05 18:42:03 +01:00
|
|
|
|
2006-08-28 03:12:36 +02:00
|
|
|
/* Yay, we are done. If we have a DerivedMesh and deformed vertices need
|
|
|
|
* to apply these back onto the DerivedMesh. If we have no DerivedMesh
|
|
|
|
* then we need to build one.
|
|
|
|
*/
|
2018-10-09 06:04:51 +02:00
|
|
|
if (me && deformedVerts) {
|
|
|
|
*r_final = BKE_mesh_copy_for_eval(me, false);
|
- 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 09:37:15 +02:00
|
|
|
|
2018-10-09 06:04:51 +02:00
|
|
|
if (!(r_cage && me == *r_cage)) {
|
|
|
|
BKE_id_free(NULL, me);
|
2015-07-02 08:20:22 +02:00
|
|
|
}
|
2018-10-09 06:04:51 +02:00
|
|
|
BKE_mesh_apply_vert_coords(*r_final, deformedVerts);
|
2012-02-28 11:22:21 +01:00
|
|
|
}
|
2018-10-09 06:04:51 +02:00
|
|
|
else if (me) {
|
|
|
|
*r_final = me;
|
2012-02-28 11:22:21 +01:00
|
|
|
}
|
2015-07-02 08:20:22 +02:00
|
|
|
else if (!deformedVerts && r_cage && *r_cage) {
|
2012-02-28 11:22:21 +01:00
|
|
|
/* cage should already have up to date normals */
|
2015-07-02 08:20:22 +02:00
|
|
|
*r_final = *r_cage;
|
2013-04-13 22:20:21 +02:00
|
|
|
|
|
|
|
/* In this case, we should never have weight-modifying modifiers in stack... */
|
2018-10-09 06:04:51 +02:00
|
|
|
if (do_init_statvis) {
|
2018-10-10 05:28:31 +02:00
|
|
|
editmesh_update_statvis_color(scene, ob);
|
2018-10-09 06:04:51 +02:00
|
|
|
}
|
2012-02-28 11:22:21 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* this is just a copy of the editmesh, no need to calc normals */
|
2018-10-09 06:37:10 +02:00
|
|
|
*r_final = BKE_mesh_from_editmesh_with_coords_thin_wrap(em, dataMask, deformedVerts);
|
2007-02-03 15:46:30 +01:00
|
|
|
deformedVerts = NULL;
|
2013-04-13 22:20:21 +02:00
|
|
|
|
2018-12-04 17:52:30 +01:00
|
|
|
mesh_copy_autosmooth(*r_final, ob->data);
|
|
|
|
|
2013-04-13 22:20:21 +02:00
|
|
|
/* In this case, we should never have weight-modifying modifiers in stack... */
|
2018-10-09 06:04:51 +02:00
|
|
|
if (do_init_statvis) {
|
2018-10-10 05:28:31 +02:00
|
|
|
editmesh_update_statvis_color(scene, ob);
|
2018-10-09 06:04:51 +02:00
|
|
|
}
|
- 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 09:37:15 +02:00
|
|
|
}
|
2007-02-03 15:46:30 +01:00
|
|
|
|
2014-04-13 12:18:51 +02:00
|
|
|
if (do_loop_normals) {
|
|
|
|
/* Compute loop normals */
|
2018-10-09 06:04:51 +02:00
|
|
|
BKE_mesh_calc_normals_split(*r_final);
|
|
|
|
BKE_mesh_tessface_clear(*r_final);
|
2015-07-02 08:20:22 +02:00
|
|
|
if (r_cage && *r_cage && (*r_cage != *r_final)) {
|
2018-10-09 06:04:51 +02:00
|
|
|
BKE_mesh_calc_normals_split(*r_cage);
|
|
|
|
BKE_mesh_tessface_clear(*r_cage);
|
2014-04-13 12:18:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-20 14:53:47 +01:00
|
|
|
/* BMESH_ONLY, ensure tessface's used for drawing,
|
2012-03-18 08:38:51 +01:00
|
|
|
* but don't recalculate if the last modifier in the stack gives us tessfaces
|
|
|
|
* check if the derived meshes are DM_TYPE_EDITBMESH before calling, this isn't essential
|
2012-02-28 11:22:21 +01:00
|
|
|
* but quiets annoying error messages since tessfaces wont be created. */
|
2015-07-17 12:14:17 +02:00
|
|
|
if (dataMask & CD_MASK_MFACE) {
|
2018-10-09 06:04:51 +02:00
|
|
|
if ((*r_final)->edit_btmesh == NULL) {
|
|
|
|
BKE_mesh_tessface_ensure(*r_final);
|
2015-07-17 12:14:17 +02:00
|
|
|
}
|
|
|
|
if (r_cage && *r_cage) {
|
2018-10-09 06:04:51 +02:00
|
|
|
if ((*r_cage)->edit_btmesh == NULL) {
|
2015-07-17 12:14:17 +02:00
|
|
|
if (*r_cage != *r_final) {
|
2018-10-09 06:04:51 +02:00
|
|
|
BKE_mesh_tessface_ensure(*r_cage);
|
2015-07-17 12:14:17 +02:00
|
|
|
}
|
2012-02-28 11:22:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-01-20 14:53:47 +01:00
|
|
|
/* --- */
|
2012-01-20 00:34:53 +01:00
|
|
|
|
2014-04-13 12:18:51 +02:00
|
|
|
/* same as mesh_calc_modifiers (if using loop normals, poly nors have already been computed). */
|
|
|
|
if (!do_loop_normals) {
|
2018-10-11 07:32:49 +02:00
|
|
|
BKE_mesh_ensure_normals_for_display(*r_final);
|
2017-01-27 18:47:11 +01:00
|
|
|
|
2018-12-04 17:52:30 +01:00
|
|
|
if (r_cage && *r_cage && (*r_cage != *r_final)) {
|
|
|
|
BKE_mesh_ensure_normals_for_display(*r_cage);
|
|
|
|
}
|
|
|
|
|
2017-01-27 18:47:11 +01:00
|
|
|
/* Some modifiers, like datatransfer, may generate those data, we do not want to keep them,
|
|
|
|
* as they are used by display code when available (i.e. even if autosmooth is disabled). */
|
2018-10-09 06:04:51 +02:00
|
|
|
if (CustomData_has_layer(&(*r_final)->ldata, CD_NORMAL)) {
|
|
|
|
CustomData_free_layers(&(*r_final)->ldata, CD_NORMAL, (*r_final)->totloop);
|
2017-01-27 18:47:11 +01:00
|
|
|
}
|
2018-10-09 06:04:51 +02:00
|
|
|
if (r_cage && CustomData_has_layer(&(*r_cage)->ldata, CD_NORMAL)) {
|
|
|
|
CustomData_free_layers(&(*r_cage)->ldata, CD_NORMAL, (*r_cage)->totloop);
|
2017-01-27 18:47:11 +01:00
|
|
|
}
|
2014-04-13 12:18:51 +02:00
|
|
|
}
|
2013-05-30 19:36:43 +02:00
|
|
|
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 22:51:28 +02:00
|
|
|
/* add an orco layer if needed */
|
2012-03-24 07:18:31 +01:00
|
|
|
if (dataMask & CD_MASK_ORCO)
|
2018-10-09 06:04:51 +02:00
|
|
|
add_orco_mesh(ob, em, *r_final, me_orco, CD_ORCO);
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 22:51:28 +02:00
|
|
|
|
2018-10-09 06:04:51 +02:00
|
|
|
if (me_orco) {
|
|
|
|
BKE_id_free(NULL, me_orco);
|
|
|
|
}
|
Merge of first part of changes from the apricot branch, especially
the features that are needed to run the game. Compile tested with
scons, make, but not cmake, that seems to have an issue not related
to these changes. The changes include:
* GLSL support in the viewport and game engine, enable in the game
menu in textured draw mode.
* Synced and merged part of the duplicated blender and gameengine/
gameplayer drawing code.
* Further refactoring of game engine drawing code, especially mesh
storage changed a lot.
* Optimizations in game engine armatures to avoid recomputations.
* A python function to get the framerate estimate in game.
* An option take object color into account in materials.
* An option to restrict shadow casters to a lamp's layers.
* Increase from 10 to 18 texture slots for materials, lamps, word.
An extra texture slot shows up once the last slot is used.
* Memory limit for undo, not enabled by default yet because it
needs the .B.blend to be changed.
* Multiple undo for image painting.
* An offset for dupligroups, so not all objects in a group have to
be at the origin.
2008-09-04 22:51:28 +02:00
|
|
|
|
2018-10-09 06:04:51 +02:00
|
|
|
if (deformedVerts) {
|
2007-02-03 15:46:30 +01:00
|
|
|
MEM_freeN(deformedVerts);
|
2018-10-09 06:04:51 +02:00
|
|
|
}
|
- 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 09:37:15 +02:00
|
|
|
}
|
|
|
|
|
2018-05-30 12:56:20 +02:00
|
|
|
static void mesh_finalize_eval(Object *object)
|
|
|
|
{
|
|
|
|
Mesh *mesh = (Mesh *)object->data;
|
|
|
|
Mesh *mesh_eval = object->runtime.mesh_eval;
|
|
|
|
/* Special Tweaks for cases when evaluated mesh came from
|
|
|
|
* BKE_mesh_new_nomain_from_template().
|
|
|
|
*/
|
|
|
|
BLI_strncpy(mesh_eval->id.name, mesh->id.name, sizeof(mesh_eval->id.name));
|
|
|
|
if (mesh_eval->mat != NULL) {
|
|
|
|
MEM_freeN(mesh_eval->mat);
|
|
|
|
}
|
2018-06-04 15:11:09 +02:00
|
|
|
/* Set flag which makes it easier to see what's going on in a debugger. */
|
|
|
|
mesh_eval->id.tag |= LIB_TAG_COPIED_ON_WRITE_EVAL_RESULT;
|
2018-05-30 12:56:20 +02:00
|
|
|
mesh_eval->mat = MEM_dupallocN(mesh->mat);
|
|
|
|
mesh_eval->totcol = mesh->totcol;
|
|
|
|
/* Make evaluated mesh to share same edit mesh pointer as original
|
|
|
|
* and copied meshes.
|
|
|
|
*/
|
|
|
|
mesh_eval->edit_btmesh = mesh->edit_btmesh;
|
|
|
|
/* Copy autosmooth settings from original mesh.
|
|
|
|
* This is not done by BKE_mesh_new_nomain_from_template(), so need to take
|
|
|
|
* extra care here.
|
|
|
|
*/
|
|
|
|
mesh_eval->flag |= (mesh->flag & ME_AUTOSMOOTH);
|
|
|
|
mesh_eval->smoothresh = mesh->smoothresh;
|
|
|
|
/* Replace evaluated object's data with fully evaluated mesh. */
|
|
|
|
/* TODO(sergey): There was statement done by Sybren and Mai that this
|
|
|
|
* caused modifiers to be applied twice. which is weirtd and shouldn't
|
|
|
|
* really happen. But since there is no reference to the report, can not
|
|
|
|
* do much about this.
|
|
|
|
*/
|
2018-06-01 11:44:50 +02:00
|
|
|
|
|
|
|
/* Object is sometimes not evaluated!
|
|
|
|
* TODO(sergey): BAD TEMPORARY HACK FOR UNTIL WE ARE SMARTER */
|
2018-06-04 15:11:09 +02:00
|
|
|
if (object->id.tag & LIB_TAG_COPIED_ON_WRITE) {
|
2018-06-01 11:44:50 +02:00
|
|
|
object->data = mesh_eval;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* evaluated will be available via: 'object->runtime.mesh_eval' */
|
|
|
|
}
|
2018-05-30 12:56:20 +02:00
|
|
|
}
|
|
|
|
|
Shrinkwrap: new mode that projects along the target normal.
The Nearest Surface Point shrink method, while fast, is neither
smooth nor continuous: as the source point moves, the projected
point can both stop and jump. This causes distortions in the
deformation of the shrinkwrap modifier, and the motion of an
animated object with a shrinkwrap constraint.
This patch implements a new mode, which, instead of using the simple
nearest point search, iteratively solves an equation for each triangle
to find a point which has its interpolated normal point to or from the
original vertex. Non-manifold boundary edges are treated as infinitely
thin cylinders that cast normals in all perpendicular directions.
Since this is useful for the constraint, and having multiple
objects with constraints targeting the same guide mesh is a quite
reasonable use case, rather than calculating the mesh boundary edge
data over and over again, it is precomputed and cached in the mesh.
Reviewers: mont29
Differential Revision: https://developer.blender.org/D3836
2018-11-06 19:04:53 +01:00
|
|
|
static void mesh_build_extra_data(struct Depsgraph *depsgraph, Object *ob)
|
|
|
|
{
|
|
|
|
uint32_t eval_flags = DEG_get_eval_flags_for_id(depsgraph, &ob->id);
|
|
|
|
|
|
|
|
if (eval_flags & DAG_EVAL_NEED_SHRINKWRAP_BOUNDARY) {
|
|
|
|
BKE_shrinkwrap_compute_boundary_data(ob->runtime.mesh_eval);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-20 19:25:42 +01:00
|
|
|
static void mesh_runtime_check_normals_valid(const Mesh *mesh)
|
2018-11-20 11:37:51 +01:00
|
|
|
{
|
|
|
|
UNUSED_VARS_NDEBUG(mesh);
|
|
|
|
BLI_assert(!(mesh->runtime.cd_dirty_vert & CD_MASK_NORMAL));
|
|
|
|
BLI_assert(!(mesh->runtime.cd_dirty_loop & CD_MASK_NORMAL));
|
|
|
|
BLI_assert(!(mesh->runtime.cd_dirty_poly & CD_MASK_NORMAL));
|
|
|
|
}
|
|
|
|
|
2015-07-02 08:20:22 +02:00
|
|
|
static void mesh_build_data(
|
2018-04-06 12:07:27 +02:00
|
|
|
struct Depsgraph *depsgraph, Scene *scene, Object *ob, CustomDataMask dataMask,
|
2015-07-02 08:20:22 +02:00
|
|
|
const bool build_shapekey_layers, const bool need_mapping)
|
- shuffled editmesh derived function name/function
- added ModifierTypeInfo.freeData function
- added modifier_{new,free] utility function
- added ccgSubSurf_getUseAgeCounts to query info
- removed subsurf modifier faking (ME_SUBSURF flag is no
longer valid). subsurf modifier gets converted on file load
although there is obscure linked mesh situation where this
can go wrong, will fix shortly. this also means that some
places in the code that test/copy subsurf settings are broken
for the time being.
- shuffled modifier calculation to be simpler. note that
all modifiers are currently disabled in editmode (including
subsurf). don't worry, will return shortly.
- bug fix, build modifier didn't randomize meshes with only verts
- cleaned up subsurf_ccg and adapted for future editmode modifier
work
- added editmesh.derived{Cage,Final}, not used yet
- added SubsurfModifierData.{mCache,emCache}, will be used to cache
subsurf instead of caching in derivedmesh itself
- removed old subsurf buttons
- added do_modifiers_buttons to handle modifier events
- removed count_object counting of modifier (subsurfed) objects...
this would be nice to add back at some point but requires care.
probably requires rewrite of counting system.
New feature: Incremental Subsurf in Object Mode
The previous release introduce incremental subsurf calculation during
editmode but it was not turned on during object mode. In general it
does not make sense to have it always enabled during object mode because
it requires caching a fair amount of information about the mesh which
is a waste of memory unless the mesh is often recalculated.
However, for mesh's that have subsurfed armatures for example, or that
have other modifiers so that the mesh is essentially changing on every
frame, it makes a lot of sense to keep the subsurf'd object around and
that is what the new incremental subsurf modifier toggle is for. The
intent is that the user will enable this option for (a) a mesh that is
currently under active editing or (b) a mesh that is heavily updated
in the scene, such as a character.
I will try to write more about this feature for release, because it
has advantages and disadvantages that are not immediately obvious (the
first user reaction will be to turn it on for ever object, which is
probably not correct).
2005-07-21 22:30:33 +02:00
|
|
|
{
|
2012-11-21 01:31:47 +01:00
|
|
|
BLI_assert(ob->type == OB_MESH);
|
|
|
|
|
2018-12-01 17:06:44 +01:00
|
|
|
/* Evaluated meshes aren't supposed to be created on original instances. If you do,
|
|
|
|
* they aren't cleaned up properly on mode switch, causing crashes, e.g T58150. */
|
|
|
|
BLI_assert(ob->id.tag & LIB_TAG_COPIED_ON_WRITE);
|
|
|
|
|
2013-05-18 12:24:34 +02:00
|
|
|
BKE_object_free_derived_caches(ob);
|
|
|
|
BKE_object_sculpt_modifiers_changed(ob);
|
- shuffled editmesh derived function name/function
- added ModifierTypeInfo.freeData function
- added modifier_{new,free] utility function
- added ccgSubSurf_getUseAgeCounts to query info
- removed subsurf modifier faking (ME_SUBSURF flag is no
longer valid). subsurf modifier gets converted on file load
although there is obscure linked mesh situation where this
can go wrong, will fix shortly. this also means that some
places in the code that test/copy subsurf settings are broken
for the time being.
- shuffled modifier calculation to be simpler. note that
all modifiers are currently disabled in editmode (including
subsurf). don't worry, will return shortly.
- bug fix, build modifier didn't randomize meshes with only verts
- cleaned up subsurf_ccg and adapted for future editmode modifier
work
- added editmesh.derived{Cage,Final}, not used yet
- added SubsurfModifierData.{mCache,emCache}, will be used to cache
subsurf instead of caching in derivedmesh itself
- removed old subsurf buttons
- added do_modifiers_buttons to handle modifier events
- removed count_object counting of modifier (subsurfed) objects...
this would be nice to add back at some point but requires care.
probably requires rewrite of counting system.
New feature: Incremental Subsurf in Object Mode
The previous release introduce incremental subsurf calculation during
editmode but it was not turned on during object mode. In general it
does not make sense to have it always enabled during object mode because
it requires caching a fair amount of information about the mesh which
is a waste of memory unless the mesh is often recalculated.
However, for mesh's that have subsurfed armatures for example, or that
have other modifiers so that the mesh is essentially changing on every
frame, it makes a lot of sense to keep the subsurf'd object around and
that is what the new incremental subsurf modifier toggle is for. The
intent is that the user will enable this option for (a) a mesh that is
currently under active editing or (b) a mesh that is heavily updated
in the scene, such as a character.
I will try to write more about this feature for release, because it
has advantages and disadvantages that are not immediately obvious (the
first user reaction will be to turn it on for ever object, which is
probably not correct).
2005-07-21 22:30:33 +02:00
|
|
|
|
2018-12-01 10:12:18 +01:00
|
|
|
if (need_mapping) {
|
|
|
|
/* Also add the flag so that it is recorded in lastDataMask. */
|
|
|
|
dataMask |= CD_MASK_ORIGINDEX;
|
|
|
|
}
|
|
|
|
|
2018-05-30 12:56:20 +02:00
|
|
|
mesh_calc_modifiers(
|
2018-05-22 19:42:41 +02:00
|
|
|
depsgraph, scene, ob, NULL, 1, need_mapping, dataMask, -1, true, build_shapekey_layers,
|
2018-05-30 12:56:20 +02:00
|
|
|
&ob->runtime.mesh_deform_eval, &ob->runtime.mesh_eval);
|
|
|
|
|
2018-11-20 11:39:48 +01:00
|
|
|
#ifdef USE_DERIVEDMESH
|
2018-10-15 08:14:05 +02:00
|
|
|
/* TODO(campbell): remove these copies, they are expected in various places over the code. */
|
2018-05-30 12:56:20 +02:00
|
|
|
ob->derivedDeform = CDDM_from_mesh_ex(ob->runtime.mesh_deform_eval, CD_REFERENCE, CD_MASK_MESH);
|
|
|
|
ob->derivedFinal = CDDM_from_mesh_ex(ob->runtime.mesh_eval, CD_REFERENCE, CD_MASK_MESH);
|
2018-11-20 11:39:48 +01:00
|
|
|
#endif
|
2009-01-02 20:10:35 +01:00
|
|
|
|
2018-10-15 08:14:05 +02:00
|
|
|
BKE_object_boundbox_calc_from_mesh(ob, ob->runtime.mesh_eval);
|
2018-05-30 12:56:20 +02:00
|
|
|
BKE_mesh_texspace_copy_from_object(ob->runtime.mesh_eval, ob);
|
2005-07-19 04:36:21 +02:00
|
|
|
|
2018-11-25 18:39:57 +01:00
|
|
|
mesh_finalize_eval(ob);
|
|
|
|
|
2018-11-20 11:39:48 +01:00
|
|
|
#ifdef USE_DERIVEDMESH
|
2009-01-02 20:10:35 +01:00
|
|
|
ob->derivedFinal->needsFree = 0;
|
|
|
|
ob->derivedDeform->needsFree = 0;
|
2018-11-20 11:39:48 +01:00
|
|
|
#endif
|
2018-12-03 16:09:45 +01:00
|
|
|
ob->runtime.last_data_mask = dataMask;
|
|
|
|
ob->runtime.last_need_mapping = need_mapping;
|
2012-03-14 07:30:55 +01:00
|
|
|
|
2018-04-05 18:20:27 +02:00
|
|
|
if ((ob->mode & OB_MODE_ALL_SCULPT) && ob->sculpt) {
|
2012-03-14 07:30:55 +01:00
|
|
|
/* create PBVH immediately (would be created on the fly too,
|
2012-04-22 13:54:53 +02:00
|
|
|
* but this avoids waiting on first stroke) */
|
2018-06-19 19:00:25 +02:00
|
|
|
/* XXX Disabled for now.
|
|
|
|
* This can create horrible nasty bugs by generating re-entrant call of mesh_get_eval_final! */
|
|
|
|
// BKE_sculpt_update_mesh_elements(depsgraph, scene, scene->toolsettings->sculpt, ob, false, false);
|
2012-03-14 07:30:55 +01:00
|
|
|
}
|
2013-05-30 19:36:43 +02:00
|
|
|
|
2018-11-20 11:37:51 +01:00
|
|
|
mesh_runtime_check_normals_valid(ob->runtime.mesh_eval);
|
Shrinkwrap: new mode that projects along the target normal.
The Nearest Surface Point shrink method, while fast, is neither
smooth nor continuous: as the source point moves, the projected
point can both stop and jump. This causes distortions in the
deformation of the shrinkwrap modifier, and the motion of an
animated object with a shrinkwrap constraint.
This patch implements a new mode, which, instead of using the simple
nearest point search, iteratively solves an equation for each triangle
to find a point which has its interpolated normal point to or from the
original vertex. Non-manifold boundary edges are treated as infinitely
thin cylinders that cast normals in all perpendicular directions.
Since this is useful for the constraint, and having multiple
objects with constraints targeting the same guide mesh is a quite
reasonable use case, rather than calculating the mesh boundary edge
data over and over again, it is precomputed and cached in the mesh.
Reviewers: mont29
Differential Revision: https://developer.blender.org/D3836
2018-11-06 19:04:53 +01:00
|
|
|
mesh_build_extra_data(depsgraph, ob);
|
- shuffled editmesh derived function name/function
- added ModifierTypeInfo.freeData function
- added modifier_{new,free] utility function
- added ccgSubSurf_getUseAgeCounts to query info
- removed subsurf modifier faking (ME_SUBSURF flag is no
longer valid). subsurf modifier gets converted on file load
although there is obscure linked mesh situation where this
can go wrong, will fix shortly. this also means that some
places in the code that test/copy subsurf settings are broken
for the time being.
- shuffled modifier calculation to be simpler. note that
all modifiers are currently disabled in editmode (including
subsurf). don't worry, will return shortly.
- bug fix, build modifier didn't randomize meshes with only verts
- cleaned up subsurf_ccg and adapted for future editmode modifier
work
- added editmesh.derived{Cage,Final}, not used yet
- added SubsurfModifierData.{mCache,emCache}, will be used to cache
subsurf instead of caching in derivedmesh itself
- removed old subsurf buttons
- added do_modifiers_buttons to handle modifier events
- removed count_object counting of modifier (subsurfed) objects...
this would be nice to add back at some point but requires care.
probably requires rewrite of counting system.
New feature: Incremental Subsurf in Object Mode
The previous release introduce incremental subsurf calculation during
editmode but it was not turned on during object mode. In general it
does not make sense to have it always enabled during object mode because
it requires caching a fair amount of information about the mesh which
is a waste of memory unless the mesh is often recalculated.
However, for mesh's that have subsurfed armatures for example, or that
have other modifiers so that the mesh is essentially changing on every
frame, it makes a lot of sense to keep the subsurf'd object around and
that is what the new incremental subsurf modifier toggle is for. The
intent is that the user will enable this option for (a) a mesh that is
currently under active editing or (b) a mesh that is heavily updated
in the scene, such as a character.
I will try to write more about this feature for release, because it
has advantages and disadvantages that are not immediately obvious (the
first user reaction will be to turn it on for ever object, which is
probably not correct).
2005-07-21 22:30:33 +02:00
|
|
|
}
|
|
|
|
|
2017-08-16 04:45:11 +02:00
|
|
|
static void editbmesh_build_data(
|
2018-04-06 12:07:27 +02:00
|
|
|
struct Depsgraph *depsgraph, Scene *scene,
|
2017-08-16 04:45:11 +02:00
|
|
|
Object *obedit, BMEditMesh *em, CustomDataMask dataMask)
|
- shuffled editmesh derived function name/function
- added ModifierTypeInfo.freeData function
- added modifier_{new,free] utility function
- added ccgSubSurf_getUseAgeCounts to query info
- removed subsurf modifier faking (ME_SUBSURF flag is no
longer valid). subsurf modifier gets converted on file load
although there is obscure linked mesh situation where this
can go wrong, will fix shortly. this also means that some
places in the code that test/copy subsurf settings are broken
for the time being.
- shuffled modifier calculation to be simpler. note that
all modifiers are currently disabled in editmode (including
subsurf). don't worry, will return shortly.
- bug fix, build modifier didn't randomize meshes with only verts
- cleaned up subsurf_ccg and adapted for future editmode modifier
work
- added editmesh.derived{Cage,Final}, not used yet
- added SubsurfModifierData.{mCache,emCache}, will be used to cache
subsurf instead of caching in derivedmesh itself
- removed old subsurf buttons
- added do_modifiers_buttons to handle modifier events
- removed count_object counting of modifier (subsurfed) objects...
this would be nice to add back at some point but requires care.
probably requires rewrite of counting system.
New feature: Incremental Subsurf in Object Mode
The previous release introduce incremental subsurf calculation during
editmode but it was not turned on during object mode. In general it
does not make sense to have it always enabled during object mode because
it requires caching a fair amount of information about the mesh which
is a waste of memory unless the mesh is often recalculated.
However, for mesh's that have subsurfed armatures for example, or that
have other modifiers so that the mesh is essentially changing on every
frame, it makes a lot of sense to keep the subsurf'd object around and
that is what the new incremental subsurf modifier toggle is for. The
intent is that the user will enable this option for (a) a mesh that is
currently under active editing or (b) a mesh that is heavily updated
in the scene, such as a character.
I will try to write more about this feature for release, because it
has advantages and disadvantages that are not immediately obvious (the
first user reaction will be to turn it on for ever object, which is
probably not correct).
2005-07-21 22:30:33 +02:00
|
|
|
{
|
2013-05-18 12:24:34 +02:00
|
|
|
BKE_object_free_derived_caches(obedit);
|
|
|
|
BKE_object_sculpt_modifiers_changed(obedit);
|
- shuffled editmesh derived function name/function
- added ModifierTypeInfo.freeData function
- added modifier_{new,free] utility function
- added ccgSubSurf_getUseAgeCounts to query info
- removed subsurf modifier faking (ME_SUBSURF flag is no
longer valid). subsurf modifier gets converted on file load
although there is obscure linked mesh situation where this
can go wrong, will fix shortly. this also means that some
places in the code that test/copy subsurf settings are broken
for the time being.
- shuffled modifier calculation to be simpler. note that
all modifiers are currently disabled in editmode (including
subsurf). don't worry, will return shortly.
- bug fix, build modifier didn't randomize meshes with only verts
- cleaned up subsurf_ccg and adapted for future editmode modifier
work
- added editmesh.derived{Cage,Final}, not used yet
- added SubsurfModifierData.{mCache,emCache}, will be used to cache
subsurf instead of caching in derivedmesh itself
- removed old subsurf buttons
- added do_modifiers_buttons to handle modifier events
- removed count_object counting of modifier (subsurfed) objects...
this would be nice to add back at some point but requires care.
probably requires rewrite of counting system.
New feature: Incremental Subsurf in Object Mode
The previous release introduce incremental subsurf calculation during
editmode but it was not turned on during object mode. In general it
does not make sense to have it always enabled during object mode because
it requires caching a fair amount of information about the mesh which
is a waste of memory unless the mesh is often recalculated.
However, for mesh's that have subsurfed armatures for example, or that
have other modifiers so that the mesh is essentially changing on every
frame, it makes a lot of sense to keep the subsurf'd object around and
that is what the new incremental subsurf modifier toggle is for. The
intent is that the user will enable this option for (a) a mesh that is
currently under active editing or (b) a mesh that is heavily updated
in the scene, such as a character.
I will try to write more about this feature for release, because it
has advantages and disadvantages that are not immediately obvious (the
first user reaction will be to turn it on for ever object, which is
probably not correct).
2005-07-21 22:30:33 +02:00
|
|
|
|
2014-02-28 10:02:30 +01:00
|
|
|
BKE_editmesh_free_derivedmesh(em);
|
- shuffled editmesh derived function name/function
- added ModifierTypeInfo.freeData function
- added modifier_{new,free] utility function
- added ccgSubSurf_getUseAgeCounts to query info
- removed subsurf modifier faking (ME_SUBSURF flag is no
longer valid). subsurf modifier gets converted on file load
although there is obscure linked mesh situation where this
can go wrong, will fix shortly. this also means that some
places in the code that test/copy subsurf settings are broken
for the time being.
- shuffled modifier calculation to be simpler. note that
all modifiers are currently disabled in editmode (including
subsurf). don't worry, will return shortly.
- bug fix, build modifier didn't randomize meshes with only verts
- cleaned up subsurf_ccg and adapted for future editmode modifier
work
- added editmesh.derived{Cage,Final}, not used yet
- added SubsurfModifierData.{mCache,emCache}, will be used to cache
subsurf instead of caching in derivedmesh itself
- removed old subsurf buttons
- added do_modifiers_buttons to handle modifier events
- removed count_object counting of modifier (subsurfed) objects...
this would be nice to add back at some point but requires care.
probably requires rewrite of counting system.
New feature: Incremental Subsurf in Object Mode
The previous release introduce incremental subsurf calculation during
editmode but it was not turned on during object mode. In general it
does not make sense to have it always enabled during object mode because
it requires caching a fair amount of information about the mesh which
is a waste of memory unless the mesh is often recalculated.
However, for mesh's that have subsurfed armatures for example, or that
have other modifiers so that the mesh is essentially changing on every
frame, it makes a lot of sense to keep the subsurf'd object around and
that is what the new incremental subsurf modifier toggle is for. The
intent is that the user will enable this option for (a) a mesh that is
currently under active editing or (b) a mesh that is heavily updated
in the scene, such as a character.
I will try to write more about this feature for release, because it
has advantages and disadvantages that are not immediately obvious (the
first user reaction will be to turn it on for ever object, which is
probably not correct).
2005-07-21 22:30:33 +02:00
|
|
|
|
2018-10-09 06:04:51 +02:00
|
|
|
Mesh *me_cage;
|
|
|
|
Mesh *me_final;
|
|
|
|
|
2015-07-02 08:20:22 +02:00
|
|
|
editbmesh_calc_modifiers(
|
2018-04-06 12:07:27 +02:00
|
|
|
depsgraph, scene, obedit, em, dataMask,
|
2018-10-09 06:04:51 +02:00
|
|
|
&me_cage, &me_final);
|
|
|
|
|
2018-10-09 07:52:46 +02:00
|
|
|
em->mesh_eval_final = me_final;
|
|
|
|
em->mesh_eval_cage = me_cage;
|
2015-07-02 08:20:22 +02:00
|
|
|
|
2018-10-15 08:14:05 +02:00
|
|
|
BKE_object_boundbox_calc_from_mesh(obedit, em->mesh_eval_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 05:28:02 +01:00
|
|
|
|
2010-03-05 17:47:52 +01:00
|
|
|
em->lastDataMask = dataMask;
|
2013-05-30 19:36:43 +02:00
|
|
|
|
2018-11-20 11:37:51 +01:00
|
|
|
mesh_runtime_check_normals_valid(em->mesh_eval_final);
|
2005-07-19 04:36:21 +02:00
|
|
|
}
|
|
|
|
|
2018-04-06 12:07:27 +02:00
|
|
|
static CustomDataMask object_get_datamask(const Depsgraph *depsgraph, Object *ob, bool *r_need_mapping)
|
2013-05-01 16:34:12 +02:00
|
|
|
{
|
2018-04-06 12:07:27 +02:00
|
|
|
ViewLayer *view_layer = DEG_get_evaluated_view_layer(depsgraph);
|
2018-06-19 18:23:26 +02:00
|
|
|
Object *actob = view_layer->basact ? DEG_get_original_object(view_layer->basact->object) : NULL;
|
2018-12-03 16:09:45 +01:00
|
|
|
CustomDataMask mask = DEG_get_customdata_mask_for_object(depsgraph, ob);
|
2015-06-04 17:39:43 +02:00
|
|
|
|
2015-07-02 08:20:22 +02:00
|
|
|
if (r_need_mapping) {
|
|
|
|
*r_need_mapping = false;
|
|
|
|
}
|
2013-05-01 16:34:12 +02:00
|
|
|
|
2018-06-19 18:29:40 +02:00
|
|
|
if (DEG_get_original_object(ob) == actob) {
|
2018-12-01 10:12:18 +01:00
|
|
|
bool editing = BKE_paint_select_face_test(actob);
|
2015-06-04 17:39:43 +02:00
|
|
|
|
|
|
|
/* weight paint and face select need original indices because of selection buffer drawing */
|
2015-07-02 08:20:22 +02:00
|
|
|
if (r_need_mapping) {
|
2018-04-05 18:20:27 +02:00
|
|
|
*r_need_mapping = (editing || (ob->mode & (OB_MODE_WEIGHT_PAINT | OB_MODE_VERTEX_PAINT)));
|
2015-07-02 08:20:22 +02:00
|
|
|
}
|
2015-06-04 17:39:43 +02:00
|
|
|
|
2013-05-01 16:34:12 +02:00
|
|
|
/* check if we need tfaces & mcols due to face select or texture paint */
|
2018-04-05 18:20:27 +02:00
|
|
|
if ((ob->mode & OB_MODE_TEXTURE_PAINT) || editing) {
|
2018-12-01 10:12:18 +01:00
|
|
|
mask |= CD_MASK_MLOOPUV | CD_MASK_MLOOPCOL | CD_MASK_MTFACE;
|
2013-05-01 16:34:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* check if we need mcols due to vertex paint or weightpaint */
|
2018-04-05 18:20:27 +02:00
|
|
|
if (ob->mode & OB_MODE_VERTEX_PAINT) {
|
2015-07-27 12:59:10 +02:00
|
|
|
mask |= CD_MASK_MLOOPCOL;
|
2013-05-01 16:34:12 +02:00
|
|
|
}
|
|
|
|
|
2018-10-09 13:21:23 +02:00
|
|
|
if (ob->mode & OB_MODE_WEIGHT_PAINT) {
|
|
|
|
mask |= CD_MASK_MDEFORMVERT;
|
|
|
|
}
|
|
|
|
|
2018-04-05 18:20:27 +02:00
|
|
|
if (ob->mode & OB_MODE_EDIT)
|
2013-05-01 16:34:12 +02:00
|
|
|
mask |= CD_MASK_MVERT_SKIN;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mask;
|
|
|
|
}
|
|
|
|
|
2015-07-02 08:20:22 +02:00
|
|
|
void makeDerivedMesh(
|
2018-04-06 12:07:27 +02:00
|
|
|
struct Depsgraph *depsgraph, Scene *scene, Object *ob, BMEditMesh *em,
|
2015-07-02 08:20:22 +02:00
|
|
|
CustomDataMask dataMask, const bool build_shapekey_layers)
|
2005-07-19 04:36:21 +02:00
|
|
|
{
|
2015-07-02 08:20:22 +02:00
|
|
|
bool need_mapping;
|
2018-04-06 12:07:27 +02:00
|
|
|
dataMask |= object_get_datamask(depsgraph, ob, &need_mapping);
|
2013-05-01 16:34:12 +02:00
|
|
|
|
2008-12-31 18:11:42 +01:00
|
|
|
if (em) {
|
2018-04-06 12:07:27 +02:00
|
|
|
editbmesh_build_data(depsgraph, scene, ob, em, dataMask);
|
2012-03-24 07:18:31 +01:00
|
|
|
}
|
|
|
|
else {
|
2018-04-06 12:07:27 +02:00
|
|
|
mesh_build_data(depsgraph, scene, ob, dataMask, build_shapekey_layers, need_mapping);
|
- shuffled editmesh derived function name/function
- added ModifierTypeInfo.freeData function
- added modifier_{new,free] utility function
- added ccgSubSurf_getUseAgeCounts to query info
- removed subsurf modifier faking (ME_SUBSURF flag is no
longer valid). subsurf modifier gets converted on file load
although there is obscure linked mesh situation where this
can go wrong, will fix shortly. this also means that some
places in the code that test/copy subsurf settings are broken
for the time being.
- shuffled modifier calculation to be simpler. note that
all modifiers are currently disabled in editmode (including
subsurf). don't worry, will return shortly.
- bug fix, build modifier didn't randomize meshes with only verts
- cleaned up subsurf_ccg and adapted for future editmode modifier
work
- added editmesh.derived{Cage,Final}, not used yet
- added SubsurfModifierData.{mCache,emCache}, will be used to cache
subsurf instead of caching in derivedmesh itself
- removed old subsurf buttons
- added do_modifiers_buttons to handle modifier events
- removed count_object counting of modifier (subsurfed) objects...
this would be nice to add back at some point but requires care.
probably requires rewrite of counting system.
New feature: Incremental Subsurf in Object Mode
The previous release introduce incremental subsurf calculation during
editmode but it was not turned on during object mode. In general it
does not make sense to have it always enabled during object mode because
it requires caching a fair amount of information about the mesh which
is a waste of memory unless the mesh is often recalculated.
However, for mesh's that have subsurfed armatures for example, or that
have other modifiers so that the mesh is essentially changing on every
frame, it makes a lot of sense to keep the subsurf'd object around and
that is what the new incremental subsurf modifier toggle is for. The
intent is that the user will enable this option for (a) a mesh that is
currently under active editing or (b) a mesh that is heavily updated
in the scene, such as a character.
I will try to write more about this feature for release, because it
has advantages and disadvantages that are not immediately obvious (the
first user reaction will be to turn it on for ever object, which is
probably not correct).
2005-07-21 22:30:33 +02:00
|
|
|
}
|
2005-07-19 04:36:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***/
|
|
|
|
|
2018-06-06 09:29:54 +02:00
|
|
|
#ifdef USE_DERIVEDMESH
|
2018-06-01 12:34:50 +02:00
|
|
|
/* Deprecated DM, use: 'mesh_get_eval_final'. */
|
2017-08-16 04:45:11 +02:00
|
|
|
DerivedMesh *mesh_get_derived_final(
|
2018-04-06 12:07:27 +02:00
|
|
|
struct Depsgraph *depsgraph, Scene *scene, Object *ob, CustomDataMask dataMask)
|
2005-03-27 22:34:18 +02:00
|
|
|
{
|
2006-12-05 18:42:03 +01:00
|
|
|
/* if there's no derived mesh or the last data mask used doesn't include
|
|
|
|
* the data we need, rebuild the derived mesh
|
|
|
|
*/
|
2015-07-02 08:20:22 +02:00
|
|
|
bool need_mapping;
|
2018-04-06 12:07:27 +02:00
|
|
|
dataMask |= object_get_datamask(depsgraph, ob, &need_mapping);
|
2013-05-01 16:34:12 +02:00
|
|
|
|
2015-07-02 08:20:22 +02:00
|
|
|
if (!ob->derivedFinal ||
|
|
|
|
((dataMask & ob->lastDataMask) != dataMask) ||
|
|
|
|
(need_mapping != ob->lastNeedMapping))
|
|
|
|
{
|
2018-04-06 12:07:27 +02:00
|
|
|
mesh_build_data(depsgraph, scene, ob, dataMask, false, need_mapping);
|
2015-07-02 08:20:22 +02:00
|
|
|
}
|
2005-07-13 22:16:35 +02:00
|
|
|
|
2013-05-30 19:36:43 +02:00
|
|
|
if (ob->derivedFinal) { BLI_assert(!(ob->derivedFinal->dirty & DM_DIRTY_NORMALS)); }
|
2005-07-19 04:36:21 +02:00
|
|
|
return ob->derivedFinal;
|
2005-07-19 02:21:01 +02:00
|
|
|
}
|
2018-06-05 16:58:08 +02:00
|
|
|
#endif
|
2018-06-01 12:34:50 +02:00
|
|
|
Mesh *mesh_get_eval_final(
|
|
|
|
struct Depsgraph *depsgraph, Scene *scene, Object *ob, CustomDataMask dataMask)
|
|
|
|
{
|
2018-12-03 13:22:19 +01:00
|
|
|
/* This function isn't thread-safe and can't be used during evaluation. */
|
|
|
|
BLI_assert(DEG_debug_is_evaluating(depsgraph) == false);
|
|
|
|
|
|
|
|
/* Evaluated meshes aren't supposed to be created on original instances. If you do,
|
|
|
|
* they aren't cleaned up properly on mode switch, causing crashes, e.g T58150. */
|
|
|
|
BLI_assert(ob->id.tag & LIB_TAG_COPIED_ON_WRITE);
|
|
|
|
|
2018-06-01 12:34:50 +02:00
|
|
|
/* if there's no evaluated mesh or the last data mask used doesn't include
|
|
|
|
* the data we need, rebuild the derived mesh
|
|
|
|
*/
|
|
|
|
bool need_mapping;
|
|
|
|
dataMask |= object_get_datamask(depsgraph, ob, &need_mapping);
|
|
|
|
|
2018-06-08 15:42:27 +02:00
|
|
|
if (!ob->runtime.mesh_eval ||
|
2018-12-03 16:09:45 +01:00
|
|
|
((dataMask & ob->runtime.last_data_mask) != dataMask) ||
|
|
|
|
(need_mapping && !ob->runtime.last_need_mapping))
|
2018-06-01 12:34:50 +02:00
|
|
|
{
|
2018-12-03 16:09:45 +01:00
|
|
|
mesh_build_data(depsgraph, scene, ob, dataMask | ob->runtime.last_data_mask,
|
|
|
|
false, need_mapping || ob->runtime.last_need_mapping);
|
2018-06-01 12:34:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ob->runtime.mesh_eval) { BLI_assert(!(ob->runtime.mesh_eval->runtime.cd_dirty_vert & CD_MASK_NORMAL)); }
|
|
|
|
return ob->runtime.mesh_eval;
|
|
|
|
}
|
2005-07-19 02:21:01 +02:00
|
|
|
|
2018-06-06 09:29:54 +02:00
|
|
|
#ifdef USE_DERIVEDMESH
|
2018-06-01 12:34:50 +02:00
|
|
|
/* Deprecated DM, use: 'mesh_get_eval_deform' instead. */
|
2018-04-06 12:07:27 +02:00
|
|
|
DerivedMesh *mesh_get_derived_deform(struct Depsgraph *depsgraph, Scene *scene, Object *ob, CustomDataMask dataMask)
|
2005-07-19 02:21:01 +02:00
|
|
|
{
|
2006-12-05 18:42:03 +01:00
|
|
|
/* if there's no derived mesh or the last data mask used doesn't include
|
|
|
|
* the data we need, rebuild the derived mesh
|
|
|
|
*/
|
2015-07-02 08:20:22 +02:00
|
|
|
bool need_mapping;
|
2015-06-04 17:39:43 +02:00
|
|
|
|
2018-04-06 12:07:27 +02:00
|
|
|
dataMask |= object_get_datamask(depsgraph, ob, &need_mapping);
|
2013-05-01 16:34:12 +02:00
|
|
|
|
2015-07-02 08:20:22 +02:00
|
|
|
if (!ob->derivedDeform ||
|
|
|
|
((dataMask & ob->lastDataMask) != dataMask) ||
|
|
|
|
(need_mapping != ob->lastNeedMapping))
|
|
|
|
{
|
2018-04-06 12:07:27 +02:00
|
|
|
mesh_build_data(depsgraph, scene, ob, dataMask, false, need_mapping);
|
2015-07-02 08:20:22 +02:00
|
|
|
}
|
2005-03-28 23:49:49 +02:00
|
|
|
|
2005-07-19 02:21:01 +02:00
|
|
|
return ob->derivedDeform;
|
2005-03-28 23:49:49 +02:00
|
|
|
}
|
2018-06-05 16:58:08 +02:00
|
|
|
#endif
|
2018-06-01 12:34:50 +02:00
|
|
|
Mesh *mesh_get_eval_deform(struct Depsgraph *depsgraph, Scene *scene, Object *ob, CustomDataMask dataMask)
|
|
|
|
{
|
2018-12-03 13:22:19 +01:00
|
|
|
/* This function isn't thread-safe and can't be used during evaluation. */
|
|
|
|
BLI_assert(DEG_debug_is_evaluating(depsgraph) == false);
|
|
|
|
|
|
|
|
/* Evaluated meshes aren't supposed to be created on original instances. If you do,
|
|
|
|
* they aren't cleaned up properly on mode switch, causing crashes, e.g T58150. */
|
|
|
|
BLI_assert(ob->id.tag & LIB_TAG_COPIED_ON_WRITE);
|
|
|
|
|
2018-06-01 12:34:50 +02:00
|
|
|
/* if there's no derived mesh or the last data mask used doesn't include
|
|
|
|
* the data we need, rebuild the derived mesh
|
|
|
|
*/
|
|
|
|
bool need_mapping;
|
|
|
|
|
|
|
|
dataMask |= object_get_datamask(depsgraph, ob, &need_mapping);
|
|
|
|
|
|
|
|
if (!ob->runtime.mesh_deform_eval ||
|
2018-12-03 16:09:45 +01:00
|
|
|
((dataMask & ob->runtime.last_data_mask) != dataMask) ||
|
|
|
|
(need_mapping && !ob->runtime.last_need_mapping))
|
2018-06-01 12:34:50 +02:00
|
|
|
{
|
2018-12-03 16:09:45 +01:00
|
|
|
mesh_build_data(depsgraph, scene, ob, dataMask | ob->runtime.last_data_mask,
|
|
|
|
false, need_mapping || ob->runtime.last_need_mapping);
|
2018-06-01 12:34:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return ob->runtime.mesh_deform_eval;
|
|
|
|
}
|
|
|
|
|
2005-03-28 23:49:49 +02:00
|
|
|
|
2018-10-12 09:05:26 +02:00
|
|
|
#ifdef USE_DERIVEDMESH
|
|
|
|
/* Deprecated, use `mesh_create_eval_final_render` instead. */
|
2018-04-06 12:07:27 +02:00
|
|
|
DerivedMesh *mesh_create_derived_render(struct Depsgraph *depsgraph, Scene *scene, Object *ob, CustomDataMask dataMask)
|
2007-01-22 00:46:00 +01:00
|
|
|
{
|
|
|
|
DerivedMesh *final;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2018-05-11 09:53:52 +02:00
|
|
|
mesh_calc_modifiers_dm(
|
2018-09-06 11:47:44 +02:00
|
|
|
depsgraph, scene, ob, NULL, 1, false, dataMask, -1, false, false,
|
2015-07-02 08:20:22 +02:00
|
|
|
NULL, &final);
|
2008-07-28 13:01:34 +02:00
|
|
|
|
|
|
|
return final;
|
|
|
|
}
|
2018-10-12 09:05:26 +02:00
|
|
|
#endif
|
|
|
|
Mesh *mesh_create_eval_final_render(struct Depsgraph *depsgraph, Scene *scene, Object *ob, CustomDataMask dataMask)
|
|
|
|
{
|
|
|
|
Mesh *final;
|
|
|
|
|
|
|
|
mesh_calc_modifiers(
|
|
|
|
depsgraph, scene, ob, NULL, 1, false, dataMask, -1, false, false,
|
|
|
|
NULL, &final);
|
|
|
|
|
|
|
|
return final;
|
|
|
|
}
|
2008-07-28 13:01:34 +02:00
|
|
|
|
2018-07-05 11:08:05 +02:00
|
|
|
#ifdef USE_DERIVEDMESH
|
|
|
|
/* Deprecated, use `mesh_create_eval_final_index_render` instead. */
|
2018-04-06 12:07:27 +02:00
|
|
|
DerivedMesh *mesh_create_derived_index_render(struct Depsgraph *depsgraph, Scene *scene, Object *ob, CustomDataMask dataMask, int index)
|
2008-07-28 13:01:34 +02:00
|
|
|
{
|
|
|
|
DerivedMesh *final;
|
2015-07-02 08:20:22 +02:00
|
|
|
|
2018-05-11 09:53:52 +02:00
|
|
|
mesh_calc_modifiers_dm(
|
2018-09-06 11:47:44 +02:00
|
|
|
depsgraph, scene, ob, NULL, 1, false, dataMask, index, false, false,
|
2015-07-02 08:20:22 +02:00
|
|
|
NULL, &final);
|
2006-11-06 02:08:26 +01:00
|
|
|
|
2005-07-19 02:21:01 +02:00
|
|
|
return final;
|
2005-07-16 23:03:28 +02:00
|
|
|
}
|
2018-07-05 11:08:05 +02:00
|
|
|
#endif
|
2018-10-10 06:18:34 +02:00
|
|
|
Mesh *mesh_create_eval_final_index_render(
|
2018-07-05 11:08:05 +02:00
|
|
|
struct Depsgraph *depsgraph, struct Scene *scene,
|
|
|
|
struct Object *ob, CustomDataMask dataMask, int index)
|
|
|
|
{
|
|
|
|
Mesh *final;
|
|
|
|
|
|
|
|
mesh_calc_modifiers(
|
2018-09-06 11:47:44 +02:00
|
|
|
depsgraph, scene, ob, NULL, 1, false, dataMask, index, false, false,
|
2018-07-05 11:08:05 +02:00
|
|
|
NULL, &final);
|
|
|
|
|
|
|
|
return final;
|
|
|
|
}
|
2005-07-16 23:03:28 +02:00
|
|
|
|
2018-07-05 15:41:58 +02:00
|
|
|
#ifdef USE_DERIVEDMESH
|
|
|
|
/* Deprecated, use `mesh_create_eval_final_view` instead. */
|
2015-07-02 08:20:22 +02:00
|
|
|
DerivedMesh *mesh_create_derived_view(
|
2018-04-06 12:07:27 +02:00
|
|
|
struct Depsgraph *depsgraph, Scene *scene,
|
2017-07-21 11:53:13 +02:00
|
|
|
Object *ob, CustomDataMask dataMask)
|
2006-09-17 07:15:56 +02:00
|
|
|
{
|
|
|
|
DerivedMesh *final;
|
|
|
|
|
2012-10-18 17:54:24 +02:00
|
|
|
/* XXX hack
|
|
|
|
* psys modifier updates particle state when called during dupli-list generation,
|
|
|
|
* which can lead to wrong transforms. This disables particle system modifier execution.
|
|
|
|
*/
|
|
|
|
ob->transflag |= OB_NO_PSYS_UPDATE;
|
|
|
|
|
2018-05-11 09:53:52 +02:00
|
|
|
mesh_calc_modifiers_dm(
|
2018-09-06 11:47:44 +02:00
|
|
|
depsgraph, scene, ob, NULL, 1, false, dataMask, -1, false, false,
|
2015-07-02 08:20:22 +02:00
|
|
|
NULL, &final);
|
2006-09-17 07:15:56 +02:00
|
|
|
|
2012-10-18 17:54:24 +02:00
|
|
|
ob->transflag &= ~OB_NO_PSYS_UPDATE;
|
|
|
|
|
2006-09-17 07:15:56 +02:00
|
|
|
return final;
|
|
|
|
}
|
2018-07-05 15:41:58 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
Mesh *mesh_create_eval_final_view(
|
|
|
|
struct Depsgraph *depsgraph, Scene *scene,
|
|
|
|
Object *ob, CustomDataMask dataMask)
|
|
|
|
{
|
|
|
|
Mesh *final;
|
|
|
|
|
|
|
|
/* XXX hack
|
|
|
|
* psys modifier updates particle state when called during dupli-list generation,
|
|
|
|
* which can lead to wrong transforms. This disables particle system modifier execution.
|
|
|
|
*/
|
|
|
|
ob->transflag |= OB_NO_PSYS_UPDATE;
|
|
|
|
|
|
|
|
mesh_calc_modifiers(
|
2018-09-06 11:47:44 +02:00
|
|
|
depsgraph, scene, ob, NULL, 1, false, dataMask, -1, false, false,
|
2018-07-05 15:41:58 +02:00
|
|
|
NULL, &final);
|
|
|
|
|
|
|
|
ob->transflag &= ~OB_NO_PSYS_UPDATE;
|
|
|
|
|
|
|
|
return final;
|
|
|
|
}
|
2006-09-17 07:15:56 +02:00
|
|
|
|
2015-07-02 08:20:22 +02:00
|
|
|
DerivedMesh *mesh_create_derived_no_deform(
|
2018-04-06 12:07:27 +02:00
|
|
|
struct Depsgraph *depsgraph, Scene *scene, Object *ob,
|
2017-07-21 11:53:13 +02:00
|
|
|
float (*vertCos)[3], CustomDataMask dataMask)
|
2005-07-17 03:18:59 +02:00
|
|
|
{
|
2005-07-19 02:21:01 +02:00
|
|
|
DerivedMesh *final;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2018-05-11 09:53:52 +02:00
|
|
|
mesh_calc_modifiers_dm(
|
2018-09-06 11:47:44 +02:00
|
|
|
depsgraph, scene, ob, vertCos, 0, false, dataMask, -1, false, false,
|
2015-07-02 08:20:22 +02:00
|
|
|
NULL, &final);
|
2005-04-04 14:22:33 +02:00
|
|
|
|
2005-07-19 02:21:01 +02:00
|
|
|
return final;
|
|
|
|
}
|
2005-04-04 05:38:21 +02:00
|
|
|
|
2005-07-19 02:21:01 +02:00
|
|
|
/***/
|
|
|
|
|
2018-10-09 07:52:46 +02:00
|
|
|
Mesh *editbmesh_get_eval_cage_and_final(
|
2018-04-06 12:07:27 +02:00
|
|
|
struct Depsgraph *depsgraph, Scene *scene, Object *obedit, BMEditMesh *em,
|
2015-07-02 08:20:22 +02:00
|
|
|
CustomDataMask dataMask,
|
|
|
|
/* return args */
|
2018-10-09 07:52:46 +02:00
|
|
|
Mesh **r_final)
|
2005-07-19 02:21:01 +02:00
|
|
|
{
|
2006-12-05 18:42:03 +01:00
|
|
|
/* if there's no derived mesh or the last data mask used doesn't include
|
|
|
|
* the data we need, rebuild the derived mesh
|
|
|
|
*/
|
2018-04-06 12:07:27 +02:00
|
|
|
dataMask |= object_get_datamask(depsgraph, obedit, NULL);
|
2013-05-01 16:34:12 +02:00
|
|
|
|
2018-10-09 07:52:46 +02:00
|
|
|
if (!em->mesh_eval_cage ||
|
2012-04-28 08:31:57 +02:00
|
|
|
(em->lastDataMask & dataMask) != dataMask)
|
|
|
|
{
|
2018-04-06 12:07:27 +02:00
|
|
|
editbmesh_build_data(depsgraph, scene, obedit, em, dataMask);
|
2012-04-28 08:31:57 +02:00
|
|
|
}
|
2005-03-27 22:34:18 +02:00
|
|
|
|
2018-10-09 07:52:46 +02:00
|
|
|
*r_final = em->mesh_eval_final;
|
|
|
|
if (em->mesh_eval_final) { BLI_assert(!(em->mesh_eval_final->runtime.cd_dirty_vert & DM_DIRTY_NORMALS)); }
|
|
|
|
return em->mesh_eval_cage;
|
2005-03-27 22:34:18 +02:00
|
|
|
}
|
2005-03-28 07:58:43 +02:00
|
|
|
|
2018-10-09 07:52:46 +02:00
|
|
|
Mesh *editbmesh_get_eval_cage(
|
2018-04-06 12:07:27 +02:00
|
|
|
struct Depsgraph *depsgraph, Scene *scene, Object *obedit, BMEditMesh *em,
|
2017-08-16 04:45:11 +02:00
|
|
|
CustomDataMask dataMask)
|
2005-03-28 07:58:43 +02:00
|
|
|
{
|
2006-12-05 18:42:03 +01:00
|
|
|
/* if there's no derived mesh or the last data mask used doesn't include
|
|
|
|
* the data we need, rebuild the derived mesh
|
|
|
|
*/
|
2018-04-06 12:07:27 +02:00
|
|
|
dataMask |= object_get_datamask(depsgraph, obedit, NULL);
|
2013-05-01 16:34:12 +02:00
|
|
|
|
2018-10-09 07:52:46 +02:00
|
|
|
if (!em->mesh_eval_cage ||
|
2012-04-28 08:31:57 +02:00
|
|
|
(em->lastDataMask & dataMask) != dataMask)
|
|
|
|
{
|
2018-04-06 12:07:27 +02:00
|
|
|
editbmesh_build_data(depsgraph, scene, obedit, em, dataMask);
|
2012-04-28 08:31:57 +02:00
|
|
|
}
|
2005-03-28 07:58:43 +02:00
|
|
|
|
2018-10-09 07:52:46 +02:00
|
|
|
return em->mesh_eval_cage;
|
2005-03-28 07:58:43 +02:00
|
|
|
}
|
2005-08-06 22:44:59 +02:00
|
|
|
|
2014-08-01 15:42:17 +02:00
|
|
|
/***/
|
|
|
|
|
2013-06-26 20:40:55 +02:00
|
|
|
/* UNUSED */
|
|
|
|
#if 0
|
2005-09-23 16:42:14 +02:00
|
|
|
|
2005-11-12 11:35:14 +01:00
|
|
|
/* ********* For those who don't grasp derived stuff! (ton) :) *************** */
|
|
|
|
|
2012-04-09 09:06:06 +02:00
|
|
|
static void make_vertexcosnos__mapFunc(void *userData, int index, const float co[3],
|
|
|
|
const float no_f[3], const short no_s[3])
|
2005-11-12 11:35:14 +01:00
|
|
|
{
|
2012-12-23 03:32:03 +01:00
|
|
|
DMCoNo *co_no = &((DMCoNo *)userData)[index];
|
2006-08-28 03:12:36 +02:00
|
|
|
|
|
|
|
/* check if we've been here before (normal should not be 0) */
|
2012-12-23 03:32:03 +01:00
|
|
|
if (!is_zero_v3(co_no->no)) {
|
|
|
|
return;
|
|
|
|
}
|
2006-08-28 03:12:36 +02:00
|
|
|
|
2012-12-23 03:32:03 +01:00
|
|
|
copy_v3_v3(co_no->co, co);
|
2012-03-24 07:18:31 +01:00
|
|
|
if (no_f) {
|
2012-12-23 03:32:03 +01:00
|
|
|
copy_v3_v3(co_no->no, no_f);
|
2005-11-12 11:35:14 +01:00
|
|
|
}
|
|
|
|
else {
|
2012-12-23 03:32:03 +01:00
|
|
|
normal_short_to_float_v3(co_no->no, no_s);
|
2005-11-12 11:35:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* always returns original amount me->totvert of vertices and normals, but fully deformed and subsurfered */
|
|
|
|
/* this is needed for all code using vertexgroups (no subsurf support) */
|
|
|
|
/* it stores the normals as floats, but they can still be scaled as shorts (32767 = unit) */
|
|
|
|
/* in use now by vertex/weight paint and particle generating */
|
|
|
|
|
2012-12-15 17:13:27 +01:00
|
|
|
DMCoNo *mesh_get_mapped_verts_nors(Scene *scene, Object *ob)
|
2005-11-12 11:35:14 +01:00
|
|
|
{
|
2012-05-12 21:18:02 +02:00
|
|
|
Mesh *me = ob->data;
|
2005-11-12 15:39:14 +01:00
|
|
|
DerivedMesh *dm;
|
2012-12-15 17:13:27 +01:00
|
|
|
DMCoNo *vertexcosnos;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2005-11-12 11:35:14 +01:00
|
|
|
/* lets prevent crashing... */
|
2012-05-12 21:18:02 +02:00
|
|
|
if (ob->type != OB_MESH || me->totvert == 0)
|
2005-11-12 11:35:14 +01:00
|
|
|
return NULL;
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2012-05-12 21:18:02 +02:00
|
|
|
dm = mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH | CD_MASK_ORIGINDEX);
|
2018-06-17 17:05:51 +02:00
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (dm->foreachMappedVert) {
|
2018-01-14 22:14:20 +01:00
|
|
|
vertexcosnos = MEM_calloc_arrayN(me->totvert, sizeof(DMCoNo), "vertexcosnos map");
|
2005-11-12 11:35:14 +01:00
|
|
|
dm->foreachMappedVert(dm, make_vertexcosnos__mapFunc, vertexcosnos);
|
2005-11-23 20:19:44 +01:00
|
|
|
}
|
2005-11-12 11:35:14 +01:00
|
|
|
else {
|
2018-01-14 22:14:20 +01:00
|
|
|
DMCoNo *v_co_no = vertexcosnos = MEM_malloc_arrayN(me->totvert, sizeof(DMCoNo), "vertexcosnos map");
|
2005-11-12 11:35:14 +01:00
|
|
|
int a;
|
2012-12-15 17:13:27 +01:00
|
|
|
for (a = 0; a < me->totvert; a++, v_co_no++) {
|
|
|
|
dm->getVertCo(dm, a, v_co_no->co);
|
|
|
|
dm->getVertNo(dm, a, v_co_no->no);
|
2005-11-12 11:35:14 +01:00
|
|
|
}
|
|
|
|
}
|
2018-06-17 17:05:51 +02:00
|
|
|
|
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 05:28:02 +01:00
|
|
|
dm->release(dm);
|
2005-11-12 11:35:14 +01:00
|
|
|
return vertexcosnos;
|
|
|
|
}
|
|
|
|
|
2013-06-26 20:40:55 +02:00
|
|
|
#endif
|
|
|
|
|
2014-09-04 09:53:10 +02:00
|
|
|
/* same as above but for vert coords */
|
|
|
|
typedef struct {
|
|
|
|
float (*vertexcos)[3];
|
|
|
|
BLI_bitmap *vertex_visit;
|
|
|
|
} MappedUserData;
|
|
|
|
|
2015-07-02 08:20:22 +02:00
|
|
|
static void make_vertexcos__mapFunc(
|
|
|
|
void *userData, int index, const float co[3],
|
|
|
|
const float UNUSED(no_f[3]), const short UNUSED(no_s[3]))
|
2014-09-04 09:53:10 +02:00
|
|
|
{
|
|
|
|
MappedUserData *mappedData = (MappedUserData *)userData;
|
|
|
|
|
|
|
|
if (BLI_BITMAP_TEST(mappedData->vertex_visit, index) == 0) {
|
|
|
|
/* we need coord from prototype vertex, not from copies,
|
|
|
|
* assume they stored in the beginning of vertex array stored in DM
|
|
|
|
* (mirror modifier for eg does this) */
|
|
|
|
copy_v3_v3(mappedData->vertexcos[index], co);
|
|
|
|
BLI_BITMAP_ENABLE(mappedData->vertex_visit, index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-09 07:52:46 +02:00
|
|
|
void mesh_get_mapped_verts_coords(Mesh *me_eval, float (*r_cos)[3], const int totcos)
|
2014-09-04 09:53:10 +02:00
|
|
|
{
|
2018-10-09 07:52:46 +02:00
|
|
|
if (me_eval->runtime.deformed_only == false) {
|
2014-09-04 09:53:10 +02:00
|
|
|
MappedUserData userData;
|
2014-09-14 10:50:59 +02:00
|
|
|
memset(r_cos, 0, sizeof(*r_cos) * totcos);
|
2014-09-04 09:53:10 +02:00
|
|
|
userData.vertexcos = r_cos;
|
|
|
|
userData.vertex_visit = BLI_BITMAP_NEW(totcos, "vertexcos flags");
|
2018-10-09 07:52:46 +02:00
|
|
|
BKE_mesh_foreach_mapped_vert(me_eval, make_vertexcos__mapFunc, &userData, MESH_FOREACH_NOP);
|
2014-09-04 09:53:10 +02:00
|
|
|
MEM_freeN(userData.vertex_visit);
|
|
|
|
}
|
|
|
|
else {
|
2018-10-09 07:52:46 +02:00
|
|
|
MVert *mv = me_eval->mvert;
|
|
|
|
for (int i = 0; i < totcos; i++, mv++) {
|
|
|
|
copy_v3_v3(r_cos[i], mv->co);
|
2014-09-04 09:53:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-26 10:43:02 +02:00
|
|
|
void DM_add_named_tangent_layer_for_uv(
|
|
|
|
CustomData *uv_data, CustomData *tan_data, int numLoopData,
|
|
|
|
const char *layer_name)
|
|
|
|
{
|
|
|
|
if (CustomData_get_named_layer_index(tan_data, CD_TANGENT, layer_name) == -1 &&
|
|
|
|
CustomData_get_named_layer_index(uv_data, CD_MLOOPUV, layer_name) != -1)
|
|
|
|
{
|
|
|
|
CustomData_add_layer_named(
|
|
|
|
tan_data, CD_TANGENT, CD_CALLOC, NULL,
|
|
|
|
numLoopData, layer_name);
|
|
|
|
}
|
|
|
|
}
|
2016-01-20 05:35:51 +01:00
|
|
|
|
2016-04-26 10:43:02 +02:00
|
|
|
void DM_calc_loop_tangents(
|
|
|
|
DerivedMesh *dm, bool calc_active_tangent,
|
2017-05-24 14:33:21 +02:00
|
|
|
const char (*tangent_names)[MAX_NAME], int tangent_names_len)
|
2016-04-26 10:43:02 +02:00
|
|
|
{
|
2017-05-24 14:33:21 +02:00
|
|
|
BKE_mesh_calc_loop_tangent_ex(
|
|
|
|
dm->getVertArray(dm),
|
|
|
|
dm->getPolyArray(dm), dm->getNumPolys(dm),
|
|
|
|
dm->getLoopArray(dm),
|
|
|
|
dm->getLoopTriArray(dm), dm->getNumLoopTri(dm),
|
|
|
|
&dm->loopData,
|
|
|
|
calc_active_tangent,
|
|
|
|
tangent_names, tangent_names_len,
|
|
|
|
CustomData_get_layer(&dm->polyData, CD_NORMAL),
|
|
|
|
dm->getLoopDataArray(dm, CD_NORMAL),
|
|
|
|
dm->getVertDataArray(dm, CD_ORCO), /* may be NULL */
|
|
|
|
/* result */
|
|
|
|
&dm->loopData, dm->getNumLoops(dm),
|
|
|
|
&dm->tangent_mask);
|
2010-03-05 17:47:52 +01:00
|
|
|
}
|
2011-10-09 23:11:51 +02:00
|
|
|
|
2012-02-05 12:30:26 +01:00
|
|
|
void DM_init_origspace(DerivedMesh *dm)
|
|
|
|
{
|
Fix T47038: Particles in Particle Edit Mode get added in completely wrong location.
It also fixes another issue (crash) related to symmetric editing.
Quite involved, we (try to!) fix complete broken logic of parts of particle code, which would use poly index
as tessface one (or vice-versa). Issue most probably goes back to BMesh integration time...
This patch mostly fixes particle editing mode:
- Adding/removing particles when using generative modifiers (like subsurf) should now work.
- Adding/removing particles with a non-tessellated mesh (i.e. one having ngons) should also mostly work.
- X-axis-mirror-editing particles over ngons does not really work, not sure why currently.
- All this in both 'modes' (with or without using modifier stack for particles).
Tech side:
- Store a deformed-only DM in particle modifier data.
- Rename existing DM to make it clear it's a final one.
- Use deformed-only DM's tessface2poly mapping to 'solve' poly/tessface mismatches.
- Make (part of) mirror-editing code able to use a DM instead of raw mesh, so that we can mirror based on final DM
when editing particles using modifier stack (mandatory, since there is no way currently to find orig tessface
from an final DM tessface index).
Note that this patch is not really nice and clean (current particles are beyond hope on this side anyway),
it's more like some urgency bandage. Whole crap needs complete rewrite anyway,
BMesh's polygons make it really hard to work with current system (and looptri would not help much here).
Also, did not test everything possibly affected by those changes, so it needs some users' testing & validation too.
Reviewers: psy-fi
Subscribers: dfelinto, eyecandy
Maniphest Tasks: T47038
Differential Revision: https://developer.blender.org/D1685
2016-01-04 12:19:45 +01:00
|
|
|
const float default_osf[4][2] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}};
|
2012-02-05 12:30:26 +01:00
|
|
|
|
|
|
|
OrigSpaceLoop *lof_array = CustomData_get_layer(&dm->loopData, CD_ORIGSPACE_MLOOP);
|
|
|
|
const int numpoly = dm->getNumPolys(dm);
|
|
|
|
// const int numloop = dm->getNumLoops(dm);
|
Fix T47038: Particles in Particle Edit Mode get added in completely wrong location.
It also fixes another issue (crash) related to symmetric editing.
Quite involved, we (try to!) fix complete broken logic of parts of particle code, which would use poly index
as tessface one (or vice-versa). Issue most probably goes back to BMesh integration time...
This patch mostly fixes particle editing mode:
- Adding/removing particles when using generative modifiers (like subsurf) should now work.
- Adding/removing particles with a non-tessellated mesh (i.e. one having ngons) should also mostly work.
- X-axis-mirror-editing particles over ngons does not really work, not sure why currently.
- All this in both 'modes' (with or without using modifier stack for particles).
Tech side:
- Store a deformed-only DM in particle modifier data.
- Rename existing DM to make it clear it's a final one.
- Use deformed-only DM's tessface2poly mapping to 'solve' poly/tessface mismatches.
- Make (part of) mirror-editing code able to use a DM instead of raw mesh, so that we can mirror based on final DM
when editing particles using modifier stack (mandatory, since there is no way currently to find orig tessface
from an final DM tessface index).
Note that this patch is not really nice and clean (current particles are beyond hope on this side anyway),
it's more like some urgency bandage. Whole crap needs complete rewrite anyway,
BMesh's polygons make it really hard to work with current system (and looptri would not help much here).
Also, did not test everything possibly affected by those changes, so it needs some users' testing & validation too.
Reviewers: psy-fi
Subscribers: dfelinto, eyecandy
Maniphest Tasks: T47038
Differential Revision: https://developer.blender.org/D1685
2016-01-04 12:19:45 +01:00
|
|
|
MVert *mv = dm->getVertArray(dm);
|
|
|
|
MLoop *ml = dm->getLoopArray(dm);
|
2012-02-05 12:30:26 +01:00
|
|
|
MPoly *mp = dm->getPolyArray(dm);
|
Fix T47038: Particles in Particle Edit Mode get added in completely wrong location.
It also fixes another issue (crash) related to symmetric editing.
Quite involved, we (try to!) fix complete broken logic of parts of particle code, which would use poly index
as tessface one (or vice-versa). Issue most probably goes back to BMesh integration time...
This patch mostly fixes particle editing mode:
- Adding/removing particles when using generative modifiers (like subsurf) should now work.
- Adding/removing particles with a non-tessellated mesh (i.e. one having ngons) should also mostly work.
- X-axis-mirror-editing particles over ngons does not really work, not sure why currently.
- All this in both 'modes' (with or without using modifier stack for particles).
Tech side:
- Store a deformed-only DM in particle modifier data.
- Rename existing DM to make it clear it's a final one.
- Use deformed-only DM's tessface2poly mapping to 'solve' poly/tessface mismatches.
- Make (part of) mirror-editing code able to use a DM instead of raw mesh, so that we can mirror based on final DM
when editing particles using modifier stack (mandatory, since there is no way currently to find orig tessface
from an final DM tessface index).
Note that this patch is not really nice and clean (current particles are beyond hope on this side anyway),
it's more like some urgency bandage. Whole crap needs complete rewrite anyway,
BMesh's polygons make it really hard to work with current system (and looptri would not help much here).
Also, did not test everything possibly affected by those changes, so it needs some users' testing & validation too.
Reviewers: psy-fi
Subscribers: dfelinto, eyecandy
Maniphest Tasks: T47038
Differential Revision: https://developer.blender.org/D1685
2016-01-04 12:19:45 +01:00
|
|
|
int i, j, k;
|
|
|
|
|
|
|
|
float (*vcos_2d)[2] = NULL;
|
|
|
|
BLI_array_staticdeclare(vcos_2d, 64);
|
2012-02-05 12:30:26 +01:00
|
|
|
|
|
|
|
for (i = 0; i < numpoly; i++, mp++) {
|
Fix T47038: Particles in Particle Edit Mode get added in completely wrong location.
It also fixes another issue (crash) related to symmetric editing.
Quite involved, we (try to!) fix complete broken logic of parts of particle code, which would use poly index
as tessface one (or vice-versa). Issue most probably goes back to BMesh integration time...
This patch mostly fixes particle editing mode:
- Adding/removing particles when using generative modifiers (like subsurf) should now work.
- Adding/removing particles with a non-tessellated mesh (i.e. one having ngons) should also mostly work.
- X-axis-mirror-editing particles over ngons does not really work, not sure why currently.
- All this in both 'modes' (with or without using modifier stack for particles).
Tech side:
- Store a deformed-only DM in particle modifier data.
- Rename existing DM to make it clear it's a final one.
- Use deformed-only DM's tessface2poly mapping to 'solve' poly/tessface mismatches.
- Make (part of) mirror-editing code able to use a DM instead of raw mesh, so that we can mirror based on final DM
when editing particles using modifier stack (mandatory, since there is no way currently to find orig tessface
from an final DM tessface index).
Note that this patch is not really nice and clean (current particles are beyond hope on this side anyway),
it's more like some urgency bandage. Whole crap needs complete rewrite anyway,
BMesh's polygons make it really hard to work with current system (and looptri would not help much here).
Also, did not test everything possibly affected by those changes, so it needs some users' testing & validation too.
Reviewers: psy-fi
Subscribers: dfelinto, eyecandy
Maniphest Tasks: T47038
Differential Revision: https://developer.blender.org/D1685
2016-01-04 12:19:45 +01:00
|
|
|
OrigSpaceLoop *lof = lof_array + mp->loopstart;
|
|
|
|
|
2012-02-05 12:30:26 +01:00
|
|
|
if (mp->totloop == 3 || mp->totloop == 4) {
|
|
|
|
for (j = 0; j < mp->totloop; j++, lof++) {
|
|
|
|
copy_v2_v2(lof->uv, default_osf[j]);
|
|
|
|
}
|
|
|
|
}
|
Fix T47038: Particles in Particle Edit Mode get added in completely wrong location.
It also fixes another issue (crash) related to symmetric editing.
Quite involved, we (try to!) fix complete broken logic of parts of particle code, which would use poly index
as tessface one (or vice-versa). Issue most probably goes back to BMesh integration time...
This patch mostly fixes particle editing mode:
- Adding/removing particles when using generative modifiers (like subsurf) should now work.
- Adding/removing particles with a non-tessellated mesh (i.e. one having ngons) should also mostly work.
- X-axis-mirror-editing particles over ngons does not really work, not sure why currently.
- All this in both 'modes' (with or without using modifier stack for particles).
Tech side:
- Store a deformed-only DM in particle modifier data.
- Rename existing DM to make it clear it's a final one.
- Use deformed-only DM's tessface2poly mapping to 'solve' poly/tessface mismatches.
- Make (part of) mirror-editing code able to use a DM instead of raw mesh, so that we can mirror based on final DM
when editing particles using modifier stack (mandatory, since there is no way currently to find orig tessface
from an final DM tessface index).
Note that this patch is not really nice and clean (current particles are beyond hope on this side anyway),
it's more like some urgency bandage. Whole crap needs complete rewrite anyway,
BMesh's polygons make it really hard to work with current system (and looptri would not help much here).
Also, did not test everything possibly affected by those changes, so it needs some users' testing & validation too.
Reviewers: psy-fi
Subscribers: dfelinto, eyecandy
Maniphest Tasks: T47038
Differential Revision: https://developer.blender.org/D1685
2016-01-04 12:19:45 +01:00
|
|
|
else {
|
|
|
|
MLoop *l = &ml[mp->loopstart];
|
|
|
|
float p_nor[3], co[3];
|
|
|
|
float mat[3][3];
|
|
|
|
|
2016-05-11 13:36:42 +02:00
|
|
|
float min[2] = {FLT_MAX, FLT_MAX}, max[2] = {-FLT_MAX, -FLT_MAX};
|
Fix T47038: Particles in Particle Edit Mode get added in completely wrong location.
It also fixes another issue (crash) related to symmetric editing.
Quite involved, we (try to!) fix complete broken logic of parts of particle code, which would use poly index
as tessface one (or vice-versa). Issue most probably goes back to BMesh integration time...
This patch mostly fixes particle editing mode:
- Adding/removing particles when using generative modifiers (like subsurf) should now work.
- Adding/removing particles with a non-tessellated mesh (i.e. one having ngons) should also mostly work.
- X-axis-mirror-editing particles over ngons does not really work, not sure why currently.
- All this in both 'modes' (with or without using modifier stack for particles).
Tech side:
- Store a deformed-only DM in particle modifier data.
- Rename existing DM to make it clear it's a final one.
- Use deformed-only DM's tessface2poly mapping to 'solve' poly/tessface mismatches.
- Make (part of) mirror-editing code able to use a DM instead of raw mesh, so that we can mirror based on final DM
when editing particles using modifier stack (mandatory, since there is no way currently to find orig tessface
from an final DM tessface index).
Note that this patch is not really nice and clean (current particles are beyond hope on this side anyway),
it's more like some urgency bandage. Whole crap needs complete rewrite anyway,
BMesh's polygons make it really hard to work with current system (and looptri would not help much here).
Also, did not test everything possibly affected by those changes, so it needs some users' testing & validation too.
Reviewers: psy-fi
Subscribers: dfelinto, eyecandy
Maniphest Tasks: T47038
Differential Revision: https://developer.blender.org/D1685
2016-01-04 12:19:45 +01:00
|
|
|
float translate[2], scale[2];
|
|
|
|
|
|
|
|
BKE_mesh_calc_poly_normal(mp, l, mv, p_nor);
|
|
|
|
axis_dominant_v3_to_m3(mat, p_nor);
|
|
|
|
|
2018-02-01 02:06:57 +01:00
|
|
|
BLI_array_clear(vcos_2d);
|
Fix T47038: Particles in Particle Edit Mode get added in completely wrong location.
It also fixes another issue (crash) related to symmetric editing.
Quite involved, we (try to!) fix complete broken logic of parts of particle code, which would use poly index
as tessface one (or vice-versa). Issue most probably goes back to BMesh integration time...
This patch mostly fixes particle editing mode:
- Adding/removing particles when using generative modifiers (like subsurf) should now work.
- Adding/removing particles with a non-tessellated mesh (i.e. one having ngons) should also mostly work.
- X-axis-mirror-editing particles over ngons does not really work, not sure why currently.
- All this in both 'modes' (with or without using modifier stack for particles).
Tech side:
- Store a deformed-only DM in particle modifier data.
- Rename existing DM to make it clear it's a final one.
- Use deformed-only DM's tessface2poly mapping to 'solve' poly/tessface mismatches.
- Make (part of) mirror-editing code able to use a DM instead of raw mesh, so that we can mirror based on final DM
when editing particles using modifier stack (mandatory, since there is no way currently to find orig tessface
from an final DM tessface index).
Note that this patch is not really nice and clean (current particles are beyond hope on this side anyway),
it's more like some urgency bandage. Whole crap needs complete rewrite anyway,
BMesh's polygons make it really hard to work with current system (and looptri would not help much here).
Also, did not test everything possibly affected by those changes, so it needs some users' testing & validation too.
Reviewers: psy-fi
Subscribers: dfelinto, eyecandy
Maniphest Tasks: T47038
Differential Revision: https://developer.blender.org/D1685
2016-01-04 12:19:45 +01:00
|
|
|
BLI_array_reserve(vcos_2d, mp->totloop);
|
|
|
|
for (j = 0; j < mp->totloop; j++, l++) {
|
|
|
|
mul_v3_m3v3(co, mat, mv[l->v].co);
|
|
|
|
copy_v2_v2(vcos_2d[j], co);
|
|
|
|
|
|
|
|
for (k = 0; k < 2; k++) {
|
|
|
|
if (co[k] > max[k])
|
|
|
|
max[k] = co[k];
|
|
|
|
else if (co[k] < min[k])
|
|
|
|
min[k] = co[k];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Brings min to (0, 0). */
|
|
|
|
negate_v2_v2(translate, min);
|
|
|
|
|
|
|
|
/* Scale will bring max to (1, 1). */
|
|
|
|
sub_v2_v2v2(scale, max, min);
|
|
|
|
if (scale[0] == 0.0f)
|
|
|
|
scale[0] = 1e-9f;
|
|
|
|
if (scale[1] == 0.0f)
|
|
|
|
scale[1] = 1e-9f;
|
|
|
|
invert_v2(scale);
|
|
|
|
|
2018-09-24 18:46:51 +02:00
|
|
|
/* Finally, transform all vcos_2d into ((0, 0), (1, 1)) square and assign them as origspace. */
|
Fix T47038: Particles in Particle Edit Mode get added in completely wrong location.
It also fixes another issue (crash) related to symmetric editing.
Quite involved, we (try to!) fix complete broken logic of parts of particle code, which would use poly index
as tessface one (or vice-versa). Issue most probably goes back to BMesh integration time...
This patch mostly fixes particle editing mode:
- Adding/removing particles when using generative modifiers (like subsurf) should now work.
- Adding/removing particles with a non-tessellated mesh (i.e. one having ngons) should also mostly work.
- X-axis-mirror-editing particles over ngons does not really work, not sure why currently.
- All this in both 'modes' (with or without using modifier stack for particles).
Tech side:
- Store a deformed-only DM in particle modifier data.
- Rename existing DM to make it clear it's a final one.
- Use deformed-only DM's tessface2poly mapping to 'solve' poly/tessface mismatches.
- Make (part of) mirror-editing code able to use a DM instead of raw mesh, so that we can mirror based on final DM
when editing particles using modifier stack (mandatory, since there is no way currently to find orig tessface
from an final DM tessface index).
Note that this patch is not really nice and clean (current particles are beyond hope on this side anyway),
it's more like some urgency bandage. Whole crap needs complete rewrite anyway,
BMesh's polygons make it really hard to work with current system (and looptri would not help much here).
Also, did not test everything possibly affected by those changes, so it needs some users' testing & validation too.
Reviewers: psy-fi
Subscribers: dfelinto, eyecandy
Maniphest Tasks: T47038
Differential Revision: https://developer.blender.org/D1685
2016-01-04 12:19:45 +01:00
|
|
|
for (j = 0; j < mp->totloop; j++, lof++) {
|
|
|
|
add_v2_v2v2(lof->uv, vcos_2d[j], translate);
|
|
|
|
mul_v2_v2(lof->uv, scale);
|
|
|
|
}
|
|
|
|
}
|
2012-02-05 12:30:26 +01:00
|
|
|
}
|
2012-04-01 17:02:19 +02:00
|
|
|
|
|
|
|
dm->dirty |= DM_DIRTY_TESS_CDLAYERS;
|
Fix T47038: Particles in Particle Edit Mode get added in completely wrong location.
It also fixes another issue (crash) related to symmetric editing.
Quite involved, we (try to!) fix complete broken logic of parts of particle code, which would use poly index
as tessface one (or vice-versa). Issue most probably goes back to BMesh integration time...
This patch mostly fixes particle editing mode:
- Adding/removing particles when using generative modifiers (like subsurf) should now work.
- Adding/removing particles with a non-tessellated mesh (i.e. one having ngons) should also mostly work.
- X-axis-mirror-editing particles over ngons does not really work, not sure why currently.
- All this in both 'modes' (with or without using modifier stack for particles).
Tech side:
- Store a deformed-only DM in particle modifier data.
- Rename existing DM to make it clear it's a final one.
- Use deformed-only DM's tessface2poly mapping to 'solve' poly/tessface mismatches.
- Make (part of) mirror-editing code able to use a DM instead of raw mesh, so that we can mirror based on final DM
when editing particles using modifier stack (mandatory, since there is no way currently to find orig tessface
from an final DM tessface index).
Note that this patch is not really nice and clean (current particles are beyond hope on this side anyway),
it's more like some urgency bandage. Whole crap needs complete rewrite anyway,
BMesh's polygons make it really hard to work with current system (and looptri would not help much here).
Also, did not test everything possibly affected by those changes, so it needs some users' testing & validation too.
Reviewers: psy-fi
Subscribers: dfelinto, eyecandy
Maniphest Tasks: T47038
Differential Revision: https://developer.blender.org/D1685
2016-01-04 12:19:45 +01:00
|
|
|
BLI_array_free(vcos_2d);
|
2012-02-05 12:30:26 +01:00
|
|
|
}
|
|
|
|
|
2018-05-11 09:53:52 +02:00
|
|
|
static void mesh_init_origspace(Mesh *mesh)
|
|
|
|
{
|
|
|
|
const float default_osf[4][2] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}};
|
|
|
|
|
|
|
|
OrigSpaceLoop *lof_array = CustomData_get_layer(&mesh->ldata, CD_ORIGSPACE_MLOOP);
|
|
|
|
const int numpoly = mesh->totpoly;
|
|
|
|
// const int numloop = mesh->totloop;
|
|
|
|
MVert *mv = mesh->mvert;
|
|
|
|
MLoop *ml = mesh->mloop;
|
|
|
|
MPoly *mp = mesh->mpoly;
|
|
|
|
int i, j, k;
|
|
|
|
|
|
|
|
float (*vcos_2d)[2] = NULL;
|
|
|
|
BLI_array_staticdeclare(vcos_2d, 64);
|
|
|
|
|
|
|
|
for (i = 0; i < numpoly; i++, mp++) {
|
|
|
|
OrigSpaceLoop *lof = lof_array + mp->loopstart;
|
|
|
|
|
|
|
|
if (mp->totloop == 3 || mp->totloop == 4) {
|
|
|
|
for (j = 0; j < mp->totloop; j++, lof++) {
|
|
|
|
copy_v2_v2(lof->uv, default_osf[j]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
MLoop *l = &ml[mp->loopstart];
|
|
|
|
float p_nor[3], co[3];
|
|
|
|
float mat[3][3];
|
|
|
|
|
|
|
|
float min[2] = {FLT_MAX, FLT_MAX}, max[2] = {-FLT_MAX, -FLT_MAX};
|
|
|
|
float translate[2], scale[2];
|
|
|
|
|
|
|
|
BKE_mesh_calc_poly_normal(mp, l, mv, p_nor);
|
|
|
|
axis_dominant_v3_to_m3(mat, p_nor);
|
|
|
|
|
|
|
|
BLI_array_clear(vcos_2d);
|
|
|
|
BLI_array_reserve(vcos_2d, mp->totloop);
|
|
|
|
for (j = 0; j < mp->totloop; j++, l++) {
|
|
|
|
mul_v3_m3v3(co, mat, mv[l->v].co);
|
|
|
|
copy_v2_v2(vcos_2d[j], co);
|
|
|
|
|
|
|
|
for (k = 0; k < 2; k++) {
|
|
|
|
if (co[k] > max[k])
|
|
|
|
max[k] = co[k];
|
|
|
|
else if (co[k] < min[k])
|
|
|
|
min[k] = co[k];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Brings min to (0, 0). */
|
|
|
|
negate_v2_v2(translate, min);
|
|
|
|
|
|
|
|
/* Scale will bring max to (1, 1). */
|
|
|
|
sub_v2_v2v2(scale, max, min);
|
|
|
|
if (scale[0] == 0.0f)
|
|
|
|
scale[0] = 1e-9f;
|
|
|
|
if (scale[1] == 0.0f)
|
|
|
|
scale[1] = 1e-9f;
|
|
|
|
invert_v2(scale);
|
|
|
|
|
2018-09-24 17:27:41 +02:00
|
|
|
/* Finally, transform all vcos_2d into ((0, 0), (1, 1)) square and assign them as origspace. */
|
2018-05-11 09:53:52 +02:00
|
|
|
for (j = 0; j < mp->totloop; j++, lof++) {
|
|
|
|
add_v2_v2v2(lof->uv, vcos_2d[j], translate);
|
|
|
|
mul_v2_v2(lof->uv, scale);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-22 17:53:18 +02:00
|
|
|
BKE_mesh_tessface_clear(mesh);
|
2018-05-11 09:53:52 +02:00
|
|
|
BLI_array_free(vcos_2d);
|
|
|
|
}
|
2012-02-05 12:30:26 +01:00
|
|
|
|
|
|
|
|
2012-01-19 01:18:25 +01:00
|
|
|
/* derivedmesh info printing function,
|
|
|
|
* to help track down differences DM output */
|
|
|
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
#include "BLI_dynstr.h"
|
|
|
|
|
2015-07-02 08:20:22 +02:00
|
|
|
static void dm_debug_info_layers(
|
|
|
|
DynStr *dynstr, DerivedMesh *dm, CustomData *cd,
|
|
|
|
void *(*getElemDataArray)(DerivedMesh *, int))
|
2012-01-19 01:18:25 +01:00
|
|
|
{
|
|
|
|
int type;
|
|
|
|
|
|
|
|
for (type = 0; type < CD_NUMTYPES; type++) {
|
2013-05-30 15:13:43 +02:00
|
|
|
if (CustomData_has_layer(cd, type)) {
|
2018-09-24 17:27:41 +02:00
|
|
|
/* note: doesn't account for multiple layers */
|
2012-01-19 01:18:25 +01:00
|
|
|
const char *name = CustomData_layertype_name(type);
|
|
|
|
const int size = CustomData_sizeof(type);
|
2013-05-30 15:13:43 +02:00
|
|
|
const void *pt = getElemDataArray(dm, type);
|
|
|
|
const int pt_size = pt ? (int)(MEM_allocN_len(pt) / size) : 0;
|
2012-01-19 01:18:25 +01:00
|
|
|
const char *structname;
|
|
|
|
int structnum;
|
|
|
|
CustomData_file_write_info(type, &structname, &structnum);
|
|
|
|
BLI_dynstr_appendf(dynstr,
|
|
|
|
" dict(name='%s', struct='%s', type=%d, ptr='%p', elem=%d, length=%d),\n",
|
2015-01-13 19:10:18 +01:00
|
|
|
name, structname, type, (const void *)pt, size, pt_size);
|
2012-01-19 01:18:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
char *DM_debug_info(DerivedMesh *dm)
|
|
|
|
{
|
2012-05-12 21:18:02 +02:00
|
|
|
DynStr *dynstr = BLI_dynstr_new();
|
2012-01-19 01:18:25 +01:00
|
|
|
char *ret;
|
|
|
|
const char *tstr;
|
|
|
|
|
|
|
|
BLI_dynstr_appendf(dynstr, "{\n");
|
|
|
|
BLI_dynstr_appendf(dynstr, " 'ptr': '%p',\n", (void *)dm);
|
|
|
|
switch (dm->type) {
|
|
|
|
case DM_TYPE_CDDM: tstr = "DM_TYPE_CDDM"; break;
|
|
|
|
case DM_TYPE_CCGDM: tstr = "DM_TYPE_CCGDM"; break;
|
|
|
|
default: tstr = "UNKNOWN"; break;
|
|
|
|
}
|
|
|
|
BLI_dynstr_appendf(dynstr, " 'type': '%s',\n", tstr);
|
|
|
|
BLI_dynstr_appendf(dynstr, " 'numVertData': %d,\n", dm->numVertData);
|
|
|
|
BLI_dynstr_appendf(dynstr, " 'numEdgeData': %d,\n", dm->numEdgeData);
|
2012-01-19 12:31:31 +01:00
|
|
|
BLI_dynstr_appendf(dynstr, " 'numTessFaceData': %d,\n", dm->numTessFaceData);
|
|
|
|
BLI_dynstr_appendf(dynstr, " 'numPolyData': %d,\n", dm->numPolyData);
|
2012-01-19 01:18:25 +01:00
|
|
|
BLI_dynstr_appendf(dynstr, " 'deformedOnly': %d,\n", dm->deformedOnly);
|
|
|
|
|
|
|
|
BLI_dynstr_appendf(dynstr, " 'vertexLayers': (\n");
|
2013-05-30 15:13:43 +02:00
|
|
|
dm_debug_info_layers(dynstr, dm, &dm->vertData, dm->getVertDataArray);
|
2012-02-05 12:30:26 +01:00
|
|
|
BLI_dynstr_appendf(dynstr, " ),\n");
|
|
|
|
|
2012-01-19 01:18:25 +01:00
|
|
|
BLI_dynstr_appendf(dynstr, " 'edgeLayers': (\n");
|
2013-05-30 15:13:43 +02:00
|
|
|
dm_debug_info_layers(dynstr, dm, &dm->edgeData, dm->getEdgeDataArray);
|
2012-01-19 01:18:25 +01:00
|
|
|
BLI_dynstr_appendf(dynstr, " ),\n");
|
|
|
|
|
2013-05-30 15:13:43 +02:00
|
|
|
BLI_dynstr_appendf(dynstr, " 'loopLayers': (\n");
|
|
|
|
dm_debug_info_layers(dynstr, dm, &dm->loopData, dm->getLoopDataArray);
|
2012-01-19 12:31:31 +01:00
|
|
|
BLI_dynstr_appendf(dynstr, " ),\n");
|
|
|
|
|
2012-02-05 12:30:26 +01:00
|
|
|
BLI_dynstr_appendf(dynstr, " 'polyLayers': (\n");
|
2013-05-30 15:13:43 +02:00
|
|
|
dm_debug_info_layers(dynstr, dm, &dm->polyData, dm->getPolyDataArray);
|
|
|
|
BLI_dynstr_appendf(dynstr, " ),\n");
|
|
|
|
|
|
|
|
BLI_dynstr_appendf(dynstr, " 'tessFaceLayers': (\n");
|
|
|
|
dm_debug_info_layers(dynstr, dm, &dm->faceData, dm->getTessFaceDataArray);
|
2012-01-19 01:18:25 +01:00
|
|
|
BLI_dynstr_appendf(dynstr, " ),\n");
|
|
|
|
|
|
|
|
BLI_dynstr_appendf(dynstr, "}\n");
|
|
|
|
|
|
|
|
ret = BLI_dynstr_get_cstring(dynstr);
|
|
|
|
BLI_dynstr_free(dynstr);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DM_debug_print(DerivedMesh *dm)
|
|
|
|
{
|
|
|
|
char *str = DM_debug_info(dm);
|
2012-03-18 07:01:33 +01:00
|
|
|
puts(str);
|
2012-01-19 01:18:25 +01:00
|
|
|
fflush(stdout);
|
2012-01-19 05:00:27 +01:00
|
|
|
MEM_freeN(str);
|
2012-01-19 01:18:25 +01:00
|
|
|
}
|
|
|
|
|
2012-09-03 04:41:12 +02:00
|
|
|
void DM_debug_print_cdlayers(CustomData *data)
|
|
|
|
{
|
|
|
|
int i;
|
2015-01-13 19:10:18 +01:00
|
|
|
const CustomDataLayer *layer;
|
2012-09-03 04:41:12 +02:00
|
|
|
|
|
|
|
printf("{\n");
|
|
|
|
|
|
|
|
for (i = 0, layer = data->layers; i < data->totlayer; i++, layer++) {
|
|
|
|
|
|
|
|
const char *name = CustomData_layertype_name(layer->type);
|
|
|
|
const int size = CustomData_sizeof(layer->type);
|
|
|
|
const char *structname;
|
|
|
|
int structnum;
|
|
|
|
CustomData_file_write_info(layer->type, &structname, &structnum);
|
|
|
|
printf(" dict(name='%s', struct='%s', type=%d, ptr='%p', elem=%d, length=%d),\n",
|
2015-01-13 19:10:18 +01:00
|
|
|
name, structname, layer->type, (const void *)layer->data, size, (int)(MEM_allocN_len(layer->data) / size));
|
2012-09-03 04:41:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
printf("}\n");
|
|
|
|
}
|
|
|
|
|
2013-09-04 03:29:34 +02:00
|
|
|
bool DM_is_valid(DerivedMesh *dm)
|
|
|
|
{
|
|
|
|
const bool do_verbose = true;
|
|
|
|
const bool do_fixes = false;
|
|
|
|
|
|
|
|
bool is_valid = true;
|
2013-11-25 20:39:14 +01:00
|
|
|
bool changed = true;
|
2013-09-04 03:29:34 +02:00
|
|
|
|
|
|
|
is_valid &= BKE_mesh_validate_all_customdata(
|
2018-12-03 16:19:08 +01:00
|
|
|
dm->getVertDataLayout(dm), dm->getNumVerts(dm),
|
|
|
|
dm->getEdgeDataLayout(dm), dm->getNumEdges(dm),
|
|
|
|
dm->getLoopDataLayout(dm), dm->getNumLoops(dm),
|
|
|
|
dm->getPolyDataLayout(dm), dm->getNumPolys(dm),
|
2015-02-05 14:03:01 +01:00
|
|
|
false, /* setting mask here isn't useful, gives false positives */
|
2013-11-25 20:39:14 +01:00
|
|
|
do_verbose, do_fixes, &changed);
|
2013-09-04 03:29:34 +02:00
|
|
|
|
|
|
|
is_valid &= BKE_mesh_validate_arrays(
|
|
|
|
NULL,
|
|
|
|
dm->getVertArray(dm), dm->getNumVerts(dm),
|
|
|
|
dm->getEdgeArray(dm), dm->getNumEdges(dm),
|
|
|
|
dm->getTessFaceArray(dm), dm->getNumTessFaces(dm),
|
|
|
|
dm->getLoopArray(dm), dm->getNumLoops(dm),
|
|
|
|
dm->getPolyArray(dm), dm->getNumPolys(dm),
|
|
|
|
dm->getVertDataArray(dm, CD_MDEFORMVERT),
|
2013-11-25 20:39:14 +01:00
|
|
|
do_verbose, do_fixes, &changed);
|
2013-09-04 03:29:34 +02:00
|
|
|
|
2013-11-25 20:39:14 +01:00
|
|
|
BLI_assert(changed == false);
|
2013-09-04 03:29:34 +02:00
|
|
|
|
|
|
|
return is_valid;
|
|
|
|
}
|
|
|
|
|
2012-01-19 01:18:25 +01:00
|
|
|
#endif /* NDEBUG */
|