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"
|
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"
|
2011-06-08 21:05:17 +02:00
|
|
|
#include "DNA_armature_types.h"
|
2005-03-27 22:34:18 +02:00
|
|
|
#include "DNA_object_types.h"
|
2005-09-18 15:27:12 +02:00
|
|
|
#include "DNA_scene_types.h" // N_T
|
2005-03-27 22:34:18 +02:00
|
|
|
|
2005-03-27 23:27:12 +02:00
|
|
|
#include "BLI_blenlib.h"
|
2010-03-22 12:59:36 +01:00
|
|
|
#include "BLI_math.h"
|
2008-07-29 17:48:31 +02:00
|
|
|
#include "BLI_memarena.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"
|
2005-03-27 22:34:18 +02:00
|
|
|
|
2012-12-15 16:59:25 +01:00
|
|
|
#include "BKE_pbvh.h"
|
2006-08-28 03:12:36 +02:00
|
|
|
#include "BKE_cdderivedmesh.h"
|
2005-03-27 22:34:18 +02:00
|
|
|
#include "BKE_displist.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"
|
|
|
|
#include "BKE_modifier.h"
|
2005-03-27 22:34:18 +02:00
|
|
|
#include "BKE_mesh.h"
|
2014-01-21 16:32:36 +01:00
|
|
|
#include "BKE_mesh_mapping.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"
|
2007-10-31 14:56:07 +01:00
|
|
|
#include "BKE_texture.h"
|
2011-01-31 21:02:51 +01:00
|
|
|
#include "BKE_multires.h"
|
2011-09-14 04:04:26 +02:00
|
|
|
#include "BKE_armature.h"
|
Particles
=========
Merge of the famous particle patch by Janne Karhu, a full rewrite
of the Blender particle system. This includes:
- Emitter, Hair and Reactor particle types.
- Newtonian, Keyed and Boids physics.
- Various particle visualisation and rendering types.
- Vertex group and texture control for various properties.
- Interpolated child particles from parents.
- Hair editing with combing, growing, cutting, .. .
- Explode modifier.
- Harmonic, Magnetic fields, and multiple falloff types.
.. and lots of other things, some more info is here:
http://wiki.blender.org/index.php/BlenderDev/Particles_Rewrite
http://wiki.blender.org/index.php/BlenderDev/Particles_Rewrite_Doc
The new particle system cannot be backwards compatible. Old particle
systems are being converted to the new system, but will require
tweaking to get them looking the same as before.
Point Cache
===========
The new system to replace manual baking, based on automatic caching
on disk. This is currently used by softbodies and the particle system.
See the Cache API section on:
http://wiki.blender.org/index.php/BlenderDev/PhysicsSprint
Documentation
=============
These new features still need good docs for the release logs, help
for this is appreciated.
2007-11-26 23:09:57 +01:00
|
|
|
#include "BKE_particle.h"
|
2013-04-13 22:31:52 +02:00
|
|
|
#include "BKE_editmesh.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"
|
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
|
|
|
#include "BKE_global.h" /* For debug flag, DM_update_tessface_data() func. */
|
2005-03-27 22:34:18 +02:00
|
|
|
|
2011-10-09 23:11:51 +02:00
|
|
|
#ifdef WITH_GAMEENGINE
|
|
|
|
#include "BKE_navmesh_conversion.h"
|
2011-10-11 06:09:11 +02:00
|
|
|
static DerivedMesh *navmesh_dm_createNavMeshForVisualization(DerivedMesh *dm);
|
2011-10-09 23:11:51 +02:00
|
|
|
#endif
|
|
|
|
|
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
|
|
|
|
2011-09-14 02:37:27 +02:00
|
|
|
#include "GL/glew.h"
|
2005-03-27 22:34:18 +02:00
|
|
|
|
2010-07-14 12:46:12 +02:00
|
|
|
#include "GPU_buffers.h"
|
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
|
|
|
#include "GPU_draw.h"
|
|
|
|
#include "GPU_extensions.h"
|
|
|
|
#include "GPU_material.h"
|
2006-03-29 16:57:14 +02:00
|
|
|
|
2013-09-04 03:29:34 +02:00
|
|
|
/* very slow! enable for testing only! */
|
|
|
|
// #define USE_MODIFIER_VALIDATE
|
|
|
|
|
|
|
|
#ifdef USE_MODIFIER_VALIDATE
|
|
|
|
# define ASSERT_IS_VALID_DM(dm) (BLI_assert((dm == NULL) || (DM_is_valid(dm) == true)))
|
|
|
|
#else
|
|
|
|
# define ASSERT_IS_VALID_DM(dm)
|
|
|
|
#endif
|
|
|
|
|
2011-04-15 07:20:18 +02:00
|
|
|
static void add_shapekey_layers(DerivedMesh *dm, Mesh *me, Object *ob);
|
|
|
|
static void shapekey_layers_to_keyblocks(DerivedMesh *dm, Mesh *me, int actshape_uid);
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2013-01-19 03:37:04 +01:00
|
|
|
MVert *tmp = MEM_mallocN(sizeof(*tmp) * dm->getNumVerts(dm),
|
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
|
|
|
{
|
2013-01-19 03:37:04 +01:00
|
|
|
MEdge *tmp = MEM_mallocN(sizeof(*tmp) * dm->getNumEdges(dm),
|
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
|
|
|
{
|
2013-01-19 03:37:04 +01:00
|
|
|
MFace *tmp = MEM_mallocN(sizeof(*tmp) * dm->getNumTessFaces(dm),
|
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)
|
|
|
|
{
|
2013-01-19 03:37:04 +01:00
|
|
|
MLoop *tmp = MEM_mallocN(sizeof(*tmp) * dm->getNumLoops(dm),
|
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)
|
|
|
|
{
|
2013-01-19 03:37:04 +01:00
|
|
|
MPoly *tmp = MEM_mallocN(sizeof(*tmp) * dm->getNumPolys(dm),
|
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;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
|
|
|
bvhcache_init(&dm->bvhCache);
|
2006-08-28 03:12:36 +02:00
|
|
|
}
|
|
|
|
|
2010-01-13 08:26:11 +01:00
|
|
|
void DM_init(DerivedMesh *dm, DerivedMeshType type, int numVerts, int numEdges,
|
2012-04-21 15:37:26 +02:00
|
|
|
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);
|
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;
|
2011-12-10 00:26:06 +01:00
|
|
|
dm->auto_bump_scale = -1.0f;
|
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 */
|
|
|
|
fill_vn_i(dm->vertData.typemap, CD_NUMTYPES, -1);
|
|
|
|
fill_vn_i(dm->edgeData.typemap, CD_NUMTYPES, -1);
|
|
|
|
fill_vn_i(dm->faceData.typemap, CD_NUMTYPES, -1);
|
|
|
|
fill_vn_i(dm->loopData.typemap, CD_NUMTYPES, -1);
|
|
|
|
fill_vn_i(dm->polyData.typemap, CD_NUMTYPES, -1);
|
2006-08-28 03:12:36 +02:00
|
|
|
}
|
|
|
|
|
2010-01-06 13:05:46 +01:00
|
|
|
void DM_from_template(DerivedMesh *dm, DerivedMesh *source, DerivedMeshType type,
|
2011-11-30 19:03:56 +01:00
|
|
|
int numVerts, int numEdges, int numTessFaces,
|
|
|
|
int numLoops, int numPolys)
|
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
|
|
|
CustomData_copy(&source->vertData, &dm->vertData, CD_MASK_DERIVEDMESH,
|
2012-05-12 21:18:02 +02:00
|
|
|
CD_CALLOC, numVerts);
|
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_copy(&source->edgeData, &dm->edgeData, CD_MASK_DERIVEDMESH,
|
2012-05-12 21:18:02 +02:00
|
|
|
CD_CALLOC, numEdges);
|
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_copy(&source->faceData, &dm->faceData, CD_MASK_DERIVEDMESH,
|
2012-05-12 21:18:02 +02:00
|
|
|
CD_CALLOC, 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
|
|
|
CustomData_copy(&source->loopData, &dm->loopData, CD_MASK_DERIVEDMESH,
|
|
|
|
CD_CALLOC, numLoops);
|
|
|
|
CustomData_copy(&source->polyData, &dm->polyData, CD_MASK_DERIVEDMESH,
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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);
|
2012-04-29 17:47:02 +02:00
|
|
|
GPU_drawobject_free(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
|
|
|
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
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2012-01-05 13:40:09 +01:00
|
|
|
/* note: until all modifiers can take MPoly's as input,
|
|
|
|
* use this at the start of modifiers */
|
|
|
|
void DM_ensure_tessface(DerivedMesh *dm)
|
|
|
|
{
|
|
|
|
const int numTessFaces = dm->getNumTessFaces(dm);
|
|
|
|
const int numPolys = dm->getNumPolys(dm);
|
|
|
|
|
2012-04-29 19:11:40 +02:00
|
|
|
if ((numTessFaces == 0) && (numPolys != 0)) {
|
2012-03-02 17:05:54 +01:00
|
|
|
dm->recalcTessellation(dm);
|
2012-01-05 13:40:09 +01:00
|
|
|
|
2012-01-20 00:34:53 +01:00
|
|
|
if (dm->getNumTessFaces(dm) != 0) {
|
|
|
|
/* printf("info %s: polys -> ngons calculated\n", __func__); */
|
2012-01-05 13:40:09 +01:00
|
|
|
}
|
|
|
|
else {
|
2012-01-20 00:34:53 +01:00
|
|
|
printf("warning %s: could not create tessfaces from %d polygons, dm->type=%d\n",
|
|
|
|
__func__, numPolys, dm->type);
|
2012-01-05 13:40:09 +01:00
|
|
|
}
|
|
|
|
}
|
2012-04-01 17:02:19 +02:00
|
|
|
|
2012-09-15 08:30:40 +02:00
|
|
|
else if (dm->dirty & DM_DIRTY_TESS_CDLAYERS) {
|
2012-12-06 09:10:24 +01:00
|
|
|
BLI_assert(CustomData_has_layer(&dm->faceData, CD_ORIGINDEX) || numTessFaces == 0);
|
2012-04-01 17:02:19 +02:00
|
|
|
DM_update_tessface_data(dm);
|
|
|
|
}
|
|
|
|
|
|
|
|
dm->dirty &= ~DM_DIRTY_TESS_CDLAYERS;
|
2012-01-05 13:40:09 +01:00
|
|
|
}
|
|
|
|
|
2012-03-20 23:56:26 +01:00
|
|
|
/* Update tessface CD data from loop/poly ones. Needed when not retessellating after modstack evaluation. */
|
|
|
|
/* NOTE: Assumes dm has valid tessellated data! */
|
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
|
|
|
void DM_update_tessface_data(DerivedMesh *dm)
|
|
|
|
{
|
2014-01-22 19:49:14 +01:00
|
|
|
MFace *mf, *mface = dm->getTessFaceArray(dm);
|
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
|
|
|
MPoly *mp = dm->getPolyArray(dm);
|
|
|
|
MLoop *ml = dm->getLoopArray(dm);
|
|
|
|
|
|
|
|
CustomData *fdata = dm->getTessFaceDataLayout(dm);
|
|
|
|
CustomData *pdata = dm->getPolyDataLayout(dm);
|
|
|
|
CustomData *ldata = dm->getLoopDataLayout(dm);
|
|
|
|
|
2013-09-09 05:12:23 +02:00
|
|
|
const int totface = dm->getNumTessFaces(dm);
|
|
|
|
int mf_idx;
|
2014-01-21 16:32:36 +01:00
|
|
|
|
|
|
|
int *polyindex = CustomData_get_layer(fdata, CD_ORIGINDEX);
|
|
|
|
unsigned int (*loopindex)[4];
|
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
|
|
|
|
|
|
|
/* Should never occure, but better abort than segfault! */
|
|
|
|
if (!polyindex)
|
|
|
|
return;
|
|
|
|
|
|
|
|
CustomData_from_bmeshpoly(fdata, pdata, ldata, totface);
|
|
|
|
|
2014-01-21 16:32:36 +01:00
|
|
|
if (CustomData_has_layer(fdata, CD_MTFACE) ||
|
|
|
|
CustomData_has_layer(fdata, CD_MCOL) ||
|
|
|
|
CustomData_has_layer(fdata, CD_PREVIEW_MCOL) ||
|
|
|
|
CustomData_has_layer(fdata, CD_ORIGSPACE))
|
|
|
|
{
|
|
|
|
loopindex = MEM_mallocN(sizeof(*loopindex) * totface, __func__);
|
|
|
|
|
2014-01-22 19:49:14 +01:00
|
|
|
for (mf_idx = 0, mf = mface; mf_idx < totface; mf_idx++, mf++) {
|
2014-01-21 16:32:36 +01:00
|
|
|
const int mf_len = mf->v4 ? 4 : 3;
|
|
|
|
unsigned int *ml_idx = loopindex[mf_idx];
|
|
|
|
int i, not_done;
|
|
|
|
|
|
|
|
/* Find out loop indices. */
|
|
|
|
/* NOTE: This assumes tessface are valid and in sync with loop/poly... Else, most likely, segfault! */
|
|
|
|
for (i = mp[polyindex[mf_idx]].loopstart, not_done = mf_len; not_done; i++) {
|
|
|
|
const int tf_v = BKE_MESH_TESSFACE_VINDEX_ORDER(mf, ml[i].v);
|
|
|
|
if (tf_v != -1) {
|
|
|
|
ml_idx[tf_v] = i;
|
|
|
|
not_done--;
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
}
|
2014-01-21 16:32:36 +01:00
|
|
|
|
2014-01-22 19:49:14 +01:00
|
|
|
/* NOTE: quad detection issue - forth vertidx vs forth loopidx:
|
|
|
|
* Here, our tfaces' forth vertex index is never 0 for a quad. However, we know our forth loop index may be
|
|
|
|
* 0 for quads (because our quads may have been rotated compared to their org poly, see tessellation code).
|
|
|
|
* So we pass the MFace's, and BKE_mesh_loops_to_tessdata will use MFace->v4 index as quad test.
|
|
|
|
*/
|
|
|
|
BKE_mesh_loops_to_tessdata(fdata, ldata, pdata, mface, polyindex, loopindex, totface);
|
2014-01-21 16:32:36 +01:00
|
|
|
|
|
|
|
MEM_freeN(loopindex);
|
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
|
|
|
}
|
|
|
|
|
2012-03-31 02:59:17 +02:00
|
|
|
if (G.debug & G_DEBUG)
|
2012-04-12 16:36:57 +02:00
|
|
|
printf("%s: Updated tessellated customdata of dm %p\n", __func__, dm);
|
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 &= ~DM_DIRTY_TESS_CDLAYERS;
|
|
|
|
}
|
|
|
|
|
2013-05-05 07:56:41 +02:00
|
|
|
void DM_to_mesh(DerivedMesh *dm, Mesh *me, Object *ob, CustomDataMask mask)
|
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;
|
2011-04-15 07:20:18 +02:00
|
|
|
|
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
|
|
|
|
2013-05-05 07:56:41 +02:00
|
|
|
CustomData_copy(&dm->vertData, &tmp.vdata, mask, CD_DUPLICATE, totvert);
|
|
|
|
CustomData_copy(&dm->edgeData, &tmp.edata, mask, CD_DUPLICATE, totedge);
|
|
|
|
CustomData_copy(&dm->loopData, &tmp.ldata, mask, CD_DUPLICATE, totloop);
|
|
|
|
CustomData_copy(&dm->polyData, &tmp.pdata, mask, CD_DUPLICATE, totpoly);
|
2013-02-26 15:32:53 +01:00
|
|
|
tmp.cd_flag = dm->cd_flag;
|
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;
|
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);
|
|
|
|
}
|
2011-04-15 07:20:18 +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 */
|
2012-03-24 07:18:31 +01:00
|
|
|
if (!CustomData_has_layer(&tmp.vdata, CD_MVERT))
|
2006-12-12 22:29:09 +01:00
|
|
|
CustomData_add_layer(&tmp.vdata, CD_MVERT, CD_ASSIGN, dm->dupVertArray(dm), totvert);
|
2012-03-24 07:18:31 +01:00
|
|
|
if (!CustomData_has_layer(&tmp.edata, CD_MEDGE))
|
2006-12-12 22:29:09 +01:00
|
|
|
CustomData_add_layer(&tmp.edata, CD_MEDGE, CD_ASSIGN, dm->dupEdgeArray(dm), totedge);
|
2012-03-24 07:18:31 +01:00
|
|
|
if (!CustomData_has_layer(&tmp.pdata, CD_MPOLY)) {
|
2011-06-14 05:16:08 +02:00
|
|
|
tmp.mloop = dm->dupLoopArray(dm);
|
|
|
|
tmp.mpoly = dm->dupPolyArray(dm);
|
|
|
|
|
|
|
|
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);
|
|
|
|
CustomData_add_layer(&tmp.ldata, CD_MDISPS, CD_DUPLICATE, 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
|
2012-03-09 19:28:30 +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);
|
2012-03-24 07:18:31 +01:00
|
|
|
if (tmp.key) tmp.key->id.us--;
|
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 */
|
|
|
|
tmp.mselect = NULL;
|
|
|
|
tmp.totselect = 0;
|
|
|
|
if (me->mselect) {
|
|
|
|
MEM_freeN(me->mselect);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
*me = tmp;
|
2006-08-28 03:12:36 +02:00
|
|
|
}
|
|
|
|
|
2009-11-22 14:44:09 +01:00
|
|
|
void DM_to_meshkey(DerivedMesh *dm, Mesh *me, KeyBlock *kb)
|
|
|
|
{
|
|
|
|
int a, totvert = dm->getNumVerts(dm);
|
|
|
|
float *fp;
|
|
|
|
MVert *mvert;
|
|
|
|
|
2012-05-12 21:18:02 +02:00
|
|
|
if (totvert == 0 || me->totvert == 0 || me->totvert != totvert) return;
|
2009-11-22 14:44:09 +01:00
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (kb->data) MEM_freeN(kb->data);
|
2013-01-19 03:37:04 +01:00
|
|
|
kb->data = MEM_mallocN(me->key->elemsize * me->totvert, "kb->data");
|
2012-05-12 21:18:02 +02:00
|
|
|
kb->totelem = totvert;
|
2009-11-22 14:44:09 +01:00
|
|
|
|
2012-05-12 21:18:02 +02:00
|
|
|
fp = kb->data;
|
|
|
|
mvert = dm->getVertDataArray(dm, CD_MVERT);
|
2009-11-22 14:44:09 +01:00
|
|
|
|
2012-05-12 21:18:02 +02:00
|
|
|
for (a = 0; a < kb->totelem; a++, fp += 3, mvert++) {
|
2011-11-06 16:39:20 +01:00
|
|
|
copy_v3_v3(fp, mvert->co);
|
2009-11-22 14:44:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2006-12-12 22:29:09 +01:00
|
|
|
void DM_add_vert_layer(DerivedMesh *dm, int type, int 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
|
|
|
}
|
|
|
|
|
2006-12-12 22:29:09 +01:00
|
|
|
void DM_add_edge_layer(DerivedMesh *dm, int type, int 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
|
|
|
}
|
|
|
|
|
2009-08-15 19:31:28 +02:00
|
|
|
void DM_add_tessface_layer(DerivedMesh *dm, int type, int 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
|
|
|
}
|
|
|
|
|
2011-11-16 18:09:41 +01:00
|
|
|
void DM_add_loop_layer(DerivedMesh *dm, int type, int alloctype, void *layer)
|
2009-08-15 19:31:28 +02:00
|
|
|
{
|
|
|
|
CustomData_add_layer(&dm->loopData, type, alloctype, layer, dm->numLoopData);
|
|
|
|
}
|
|
|
|
|
2011-11-29 06:09:54 +01:00
|
|
|
void DM_add_poly_layer(DerivedMesh *dm, int type, int 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);
|
|
|
|
}
|
|
|
|
|
2006-08-28 03:12:36 +02:00
|
|
|
void DM_interp_vert_data(DerivedMesh *source, DerivedMesh *dest,
|
2012-05-12 21:18:02 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
void DM_interp_edge_data(DerivedMesh *source, DerivedMesh *dest,
|
2012-05-12 21:18:02 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
(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_interp_tessface_data(DerivedMesh *source, DerivedMesh *dest,
|
2012-05-12 21:18:02 +02:00
|
|
|
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
|
|
|
|
2010-07-19 06:44:37 +02:00
|
|
|
void DM_swap_tessface_data(DerivedMesh *dm, int index, const int *corner_indices)
|
2005-07-17 19:41:03 +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
|
|
|
CustomData_swap(&dm->faceData, index, corner_indices);
|
2005-07-17 19:41:03 +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_interp_loop_data(DerivedMesh *source, DerivedMesh *dest,
|
|
|
|
int *src_indices,
|
|
|
|
float *weights, int count, int dest_index)
|
|
|
|
{
|
|
|
|
CustomData_interp(&source->loopData, &dest->loopData, src_indices,
|
|
|
|
weights, NULL, count, dest_index);
|
|
|
|
}
|
|
|
|
|
2011-11-29 06:09:54 +01:00
|
|
|
void DM_interp_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 *src_indices,
|
|
|
|
float *weights, int count, int dest_index)
|
|
|
|
{
|
|
|
|
CustomData_interp(&source->polyData, &dest->polyData, src_indices,
|
|
|
|
weights, NULL, count, dest_index);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
///
|
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);
|
2008-07-25 20:57:16 +02:00
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (!dm)
|
2008-07-25 20:57:16 +02:00
|
|
|
return NULL;
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2011-04-15 07:20:18 +02:00
|
|
|
DerivedMesh *mesh_create_derived_for_modifier(Scene *scene, Object *ob,
|
2012-01-30 04:54:24 +01:00
|
|
|
ModifierData *md, int build_shapekey_layers)
|
2005-07-26 02:45:19 +02:00
|
|
|
{
|
|
|
|
Mesh *me = ob->data;
|
2005-08-03 06:04:05 +02:00
|
|
|
ModifierTypeInfo *mti = modifierType_getInfo(md->type);
|
2005-07-26 02:45:19 +02:00
|
|
|
DerivedMesh *dm;
|
2012-01-30 04:54:24 +01:00
|
|
|
KeyBlock *kb;
|
2005-07-26 02:45:19 +02:00
|
|
|
|
2012-05-12 21:18:02 +02:00
|
|
|
md->scene = scene;
|
2009-01-04 15:14:06 +01:00
|
|
|
|
2012-05-12 21:18:02 +02:00
|
|
|
if (!(md->mode & eModifierMode_Realtime)) return NULL;
|
2009-11-25 15:07:12 +01:00
|
|
|
if (mti->isDisabled && mti->isDisabled(md, 0)) return NULL;
|
2011-04-15 07:20:18 +02:00
|
|
|
|
2012-05-12 21:18:02 +02:00
|
|
|
if (build_shapekey_layers && me->key && (kb = BLI_findlink(&me->key->block, ob->shapenr - 1))) {
|
2012-09-19 12:12:07 +02:00
|
|
|
BKE_key_convert_to_mesh(kb, me);
|
2011-04-15 07:20:18 +02:00
|
|
|
}
|
|
|
|
|
2012-05-12 21:18:02 +02:00
|
|
|
if (mti->type == eModifierTypeType_OnlyDeform) {
|
2005-07-26 02:45:19 +02:00
|
|
|
int numVerts;
|
2013-03-26 08:29:01 +01:00
|
|
|
float (*deformedVerts)[3] = BKE_mesh_vertexCos_get(me, &numVerts);
|
2005-07-26 02:45:19 +02:00
|
|
|
|
2013-05-30 19:36:43 +02:00
|
|
|
modwrap_deformVerts(md, ob, NULL, deformedVerts, numVerts, 0);
|
2013-12-25 22:26:41 +01:00
|
|
|
dm = mesh_create_derived(me, deformedVerts);
|
2006-08-20 17:22:56 +02:00
|
|
|
|
2011-04-15 07:20:18 +02:00
|
|
|
if (build_shapekey_layers)
|
|
|
|
add_shapekey_layers(dm, me, ob);
|
|
|
|
|
2005-07-26 02:45:19 +02:00
|
|
|
MEM_freeN(deformedVerts);
|
2012-03-24 07:18:31 +01:00
|
|
|
}
|
|
|
|
else {
|
2013-12-25 22:26:41 +01:00
|
|
|
DerivedMesh *tdm = mesh_create_derived(me, NULL);
|
2011-04-15 07:20:18 +02:00
|
|
|
|
|
|
|
if (build_shapekey_layers)
|
|
|
|
add_shapekey_layers(tdm, me, ob);
|
|
|
|
|
2013-05-30 19:36:43 +02:00
|
|
|
dm = modwrap_applyModifier(md, ob, tdm, 0);
|
2013-09-04 03:29:34 +02:00
|
|
|
ASSERT_IS_VALID_DM(dm);
|
2006-08-28 03:12:36 +02:00
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (tdm != dm) tdm->release(tdm);
|
2005-07-26 02:45:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return dm;
|
|
|
|
}
|
|
|
|
|
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 */
|
|
|
|
|
2012-12-21 08:28:14 +01:00
|
|
|
orco = MEM_mallocN(sizeof(float) * 3 * em->bm->totvert, "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
|
|
|
}
|
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 */
|
2012-12-21 08:28:14 +01:00
|
|
|
static float (*get_orco_coords_dm(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
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (kb->data)
|
2011-12-05 00:13:28 +01:00
|
|
|
return kb->data;
|
2010-03-30 13:49:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-09-04 07:31:25 +02:00
|
|
|
static DerivedMesh *create_orco_dm(Object *ob, Mesh *me, BMEditMesh *em, int layer)
|
2007-12-05 13:40:54 +01:00
|
|
|
{
|
|
|
|
DerivedMesh *dm;
|
|
|
|
float (*orco)[3];
|
2010-03-30 13:49:07 +02:00
|
|
|
int free;
|
2007-12-05 13:40:54 +01:00
|
|
|
|
2014-01-23 14:50:50 +01:00
|
|
|
if (em) dm = CDDM_from_editbmesh(em, false, false);
|
2013-12-25 22:26:41 +01:00
|
|
|
else dm = CDDM_from_mesh(me);
|
2010-03-30 13:49:07 +02:00
|
|
|
|
2012-05-12 21:18:02 +02:00
|
|
|
orco = get_orco_coords_dm(ob, em, layer, &free);
|
2010-03-30 13:49:07 +02:00
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (orco) {
|
2010-03-30 13:49:07 +02:00
|
|
|
CDDM_apply_vert_coords(dm, orco);
|
2012-03-24 07:18:31 +01:00
|
|
|
if (free) MEM_freeN(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
|
|
|
}
|
|
|
|
|
2007-12-05 13:40:54 +01:00
|
|
|
return dm;
|
|
|
|
}
|
|
|
|
|
2010-07-19 06:44:37 +02:00
|
|
|
static void add_orco_dm(Object *ob, BMEditMesh *em, DerivedMesh *dm,
|
2012-05-12 21:18:02 +02:00
|
|
|
DerivedMesh *orcodm, int layer)
|
2007-12-05 13:40:54 +01:00
|
|
|
{
|
|
|
|
float (*orco)[3], (*layerorco)[3];
|
2010-03-30 13:49:07 +02:00
|
|
|
int totvert, free;
|
2007-12-05 13:40:54 +01:00
|
|
|
|
2012-05-12 21:18:02 +02:00
|
|
|
totvert = dm->getNumVerts(dm);
|
2007-12-05 13:40:54 +01:00
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (orcodm) {
|
2012-05-12 21:18:02 +02:00
|
|
|
orco = MEM_callocN(sizeof(float) * 3 * totvert, "dm orco");
|
|
|
|
free = 1;
|
2007-12-05 13:40:54 +01:00
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (orcodm->getNumVerts(orcodm) == totvert)
|
2007-12-05 13:40:54 +01:00
|
|
|
orcodm->getVertCos(orcodm, orco);
|
|
|
|
else
|
|
|
|
dm->getVertCos(dm, orco);
|
|
|
|
}
|
2010-03-30 13:49:07 +02:00
|
|
|
else
|
2012-05-12 21:18:02 +02:00
|
|
|
orco = get_orco_coords_dm(ob, em, layer, &free);
|
2007-12-05 13:40:54 +01:00
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (orco) {
|
|
|
|
if (layer == CD_ORCO)
|
2012-05-05 23:28:12 +02:00
|
|
|
BKE_mesh_orco_verts_transform(ob->data, orco, totvert, 0);
|
2007-12-05 13:40:54 +01:00
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (!(layerorco = DM_get_vert_data_layer(dm, layer))) {
|
2010-03-30 13:49:07 +02:00
|
|
|
DM_add_vert_layer(dm, layer, CD_CALLOC, NULL);
|
|
|
|
layerorco = DM_get_vert_data_layer(dm, layer);
|
|
|
|
}
|
2007-12-05 13:40:54 +01:00
|
|
|
|
2012-05-12 21:18:02 +02:00
|
|
|
memcpy(layerorco, orco, sizeof(float) * 3 * totvert);
|
2012-03-24 07:18:31 +01:00
|
|
|
if (free) MEM_freeN(orco);
|
2007-12-05 13:40:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-23 05:24:15 +02:00
|
|
|
/* weight paint colors */
|
|
|
|
|
|
|
|
/* Something of a hack, at the moment deal with weightpaint
|
|
|
|
* by tucking into colors during modifier eval, only in
|
|
|
|
* wpaint mode. Works ok but need to make sure recalc
|
|
|
|
* happens on enter/exit wpaint.
|
|
|
|
*/
|
|
|
|
|
2011-11-26 04:13:54 +01:00
|
|
|
void weight_to_rgb(float r_rgb[3], const float weight)
|
2009-05-23 05:24:15 +02:00
|
|
|
{
|
2012-05-12 21:18:02 +02:00
|
|
|
const float blend = ((weight / 2.0f) + 0.5f);
|
2011-11-26 04:13:54 +01:00
|
|
|
|
2012-07-07 01:56:59 +02:00
|
|
|
if (weight <= 0.25f) { /* blue->cyan */
|
2012-05-12 21:18:02 +02:00
|
|
|
r_rgb[0] = 0.0f;
|
|
|
|
r_rgb[1] = blend * weight * 4.0f;
|
|
|
|
r_rgb[2] = blend;
|
2009-05-23 05:24:15 +02:00
|
|
|
}
|
2012-07-07 01:56:59 +02:00
|
|
|
else if (weight <= 0.50f) { /* cyan->green */
|
2012-05-12 21:18:02 +02:00
|
|
|
r_rgb[0] = 0.0f;
|
|
|
|
r_rgb[1] = blend;
|
|
|
|
r_rgb[2] = blend * (1.0f - ((weight - 0.25f) * 4.0f));
|
2009-05-23 05:24:15 +02:00
|
|
|
}
|
2012-07-07 01:56:59 +02:00
|
|
|
else if (weight <= 0.75f) { /* green->yellow */
|
2012-05-12 21:18:02 +02:00
|
|
|
r_rgb[0] = blend * ((weight - 0.50f) * 4.0f);
|
|
|
|
r_rgb[1] = blend;
|
|
|
|
r_rgb[2] = 0.0f;
|
2009-05-23 05:24:15 +02:00
|
|
|
}
|
2012-07-07 01:56:59 +02:00
|
|
|
else if (weight <= 1.0f) { /* yellow->red */
|
2012-05-12 21:18:02 +02:00
|
|
|
r_rgb[0] = blend;
|
|
|
|
r_rgb[1] = blend * (1.0f - ((weight - 0.75f) * 4.0f));
|
|
|
|
r_rgb[2] = 0.0f;
|
2009-05-23 05:24:15 +02:00
|
|
|
}
|
2011-12-07 08:13:33 +01:00
|
|
|
else {
|
|
|
|
/* exceptional value, unclamped or nan,
|
|
|
|
* avoid uninitialized memory use */
|
2012-05-12 21:18:02 +02:00
|
|
|
r_rgb[0] = 1.0f;
|
|
|
|
r_rgb[1] = 0.0f;
|
|
|
|
r_rgb[2] = 1.0f;
|
2011-12-07 08:13:33 +01:00
|
|
|
}
|
2009-05-23 05:24:15 +02:00
|
|
|
}
|
|
|
|
|
2011-09-14 04:04:26 +02:00
|
|
|
/* draw_flag's for calc_weightpaint_vert_color */
|
|
|
|
enum {
|
2013-02-22 05:09:04 +01:00
|
|
|
/* only one of these should be set, keep first (for easy bit-shifting) */
|
|
|
|
CALC_WP_GROUP_USER_ACTIVE = (1 << 1),
|
|
|
|
CALC_WP_GROUP_USER_ALL = (1 << 2),
|
|
|
|
|
|
|
|
CALC_WP_MULTIPAINT = (1 << 3),
|
|
|
|
CALC_WP_AUTO_NORMALIZE = (1 << 4)
|
2011-09-14 04:04:26 +02:00
|
|
|
};
|
|
|
|
|
2013-03-05 21:30:38 +01:00
|
|
|
typedef struct DMWeightColorInfo {
|
2013-03-06 03:57:31 +01:00
|
|
|
const ColorBand *coba;
|
|
|
|
const char *alert_color;
|
2013-03-05 21:30:38 +01:00
|
|
|
} DMWeightColorInfo;
|
|
|
|
|
|
|
|
|
2013-04-13 22:20:21 +02:00
|
|
|
static int dm_drawflag_calc(ToolSettings *ts)
|
|
|
|
{
|
|
|
|
return ((ts->multipaint ? CALC_WP_MULTIPAINT :
|
|
|
|
/* CALC_WP_GROUP_USER_ACTIVE or CALC_WP_GROUP_USER_ALL*/
|
|
|
|
(1 << ts->weightuser)) |
|
|
|
|
(ts->auto_normalize ? CALC_WP_AUTO_NORMALIZE : 0));
|
|
|
|
}
|
|
|
|
|
2013-03-05 21:30:38 +01:00
|
|
|
static void weightpaint_color(unsigned char r_col[4], DMWeightColorInfo *dm_wcinfo, const float input)
|
2011-12-18 13:54:50 +01:00
|
|
|
{
|
|
|
|
float colf[4];
|
|
|
|
|
2013-03-10 20:10:20 +01:00
|
|
|
if (dm_wcinfo && dm_wcinfo->coba) {
|
2013-03-05 21:30:38 +01:00
|
|
|
do_colorband(dm_wcinfo->coba, input, colf);
|
2012-03-18 00:26:25 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
weight_to_rgb(colf, input);
|
|
|
|
}
|
2011-12-18 13:54:50 +01:00
|
|
|
|
2012-03-18 00:37:14 +01:00
|
|
|
/* don't use rgb_float_to_uchar() here because
|
|
|
|
* the resulting float doesn't need 0-1 clamp check */
|
|
|
|
r_col[0] = (unsigned char)(colf[0] * 255.0f);
|
|
|
|
r_col[1] = (unsigned char)(colf[1] * 255.0f);
|
|
|
|
r_col[2] = (unsigned char)(colf[2] * 255.0f);
|
|
|
|
r_col[3] = 255;
|
2011-12-18 13:54:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-07 19:22:16 +01:00
|
|
|
static void calc_weightpaint_vert_color(
|
2011-12-18 13:54:50 +01:00
|
|
|
unsigned char r_col[4],
|
2013-03-05 21:30:38 +01:00
|
|
|
MDeformVert *dv,
|
2013-03-06 03:57:31 +01:00
|
|
|
DMWeightColorInfo *dm_wcinfo,
|
2011-12-18 13:54:50 +01:00
|
|
|
const int defbase_tot, const int defbase_act,
|
2013-05-15 17:52:48 +02:00
|
|
|
const bool *defbase_sel, const int defbase_sel_tot,
|
2012-09-05 05:45:32 +02:00
|
|
|
const int draw_flag)
|
2009-05-23 05:24:15 +02:00
|
|
|
{
|
2011-12-07 08:13:33 +01:00
|
|
|
float input = 0.0f;
|
2011-09-18 19:10:28 +02:00
|
|
|
|
2013-03-06 03:57:31 +01:00
|
|
|
bool show_alert_color = false;
|
2009-04-02 16:38:40 +02:00
|
|
|
|
2012-09-05 05:45:32 +02:00
|
|
|
if ((defbase_sel_tot > 1) && (draw_flag & CALC_WP_MULTIPAINT)) {
|
2013-03-06 03:57:31 +01:00
|
|
|
/* Multi-Paint feature */
|
|
|
|
bool was_a_nonzero = false;
|
2011-12-19 23:55:04 +01:00
|
|
|
unsigned int i;
|
2011-12-18 13:54:50 +01:00
|
|
|
|
2012-05-12 21:18:02 +02:00
|
|
|
MDeformWeight *dw = dv->dw;
|
2011-12-19 23:55:04 +01:00
|
|
|
for (i = dv->totweight; i != 0; i--, dw++) {
|
2011-12-18 13:54:50 +01:00
|
|
|
/* in multipaint, get the average if auto normalize is inactive
|
|
|
|
* get the sum if it is active */
|
|
|
|
if (dw->def_nr < defbase_tot) {
|
2012-09-05 05:45:32 +02:00
|
|
|
if (defbase_sel[dw->def_nr]) {
|
2011-12-18 13:54:50 +01:00
|
|
|
if (dw->weight) {
|
|
|
|
input += dw->weight;
|
2013-03-06 03:57:31 +01:00
|
|
|
was_a_nonzero = true;
|
2011-06-10 21:47:53 +02:00
|
|
|
}
|
|
|
|
}
|
2011-06-08 21:05:17 +02:00
|
|
|
}
|
2011-12-18 13:54:50 +01:00
|
|
|
}
|
2009-05-23 05:24:15 +02:00
|
|
|
|
2011-12-18 13:54:50 +01:00
|
|
|
/* make it black if the selected groups have no weight on a vertex */
|
2013-03-06 03:57:31 +01:00
|
|
|
if (was_a_nonzero == false) {
|
|
|
|
show_alert_color = true;
|
2011-09-14 04:04:26 +02:00
|
|
|
}
|
2011-12-18 13:54:50 +01:00
|
|
|
else if ((draw_flag & CALC_WP_AUTO_NORMALIZE) == FALSE) {
|
2012-09-05 05:45:32 +02:00
|
|
|
input /= defbase_sel_tot; /* get the average */
|
2011-06-10 21:47:53 +02:00
|
|
|
}
|
2011-06-08 21:05:17 +02:00
|
|
|
}
|
2011-12-18 13:54:50 +01:00
|
|
|
else {
|
|
|
|
/* default, non tricky behavior */
|
2012-05-12 21:18:02 +02:00
|
|
|
input = defvert_find_weight(dv, defbase_act);
|
2013-02-22 05:09:04 +01:00
|
|
|
|
|
|
|
if (draw_flag & CALC_WP_GROUP_USER_ACTIVE) {
|
|
|
|
if (input == 0.0f) {
|
2013-03-06 03:57:31 +01:00
|
|
|
show_alert_color = true;
|
2013-02-22 05:09:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (draw_flag & CALC_WP_GROUP_USER_ALL) {
|
|
|
|
if (input == 0.0f) {
|
2013-03-06 03:57:31 +01:00
|
|
|
show_alert_color = defvert_is_weight_zero(dv, defbase_tot);
|
2013-02-22 05:09:04 +01:00
|
|
|
}
|
|
|
|
}
|
2011-12-18 13:54:50 +01:00
|
|
|
}
|
|
|
|
|
2013-03-06 03:57:31 +01:00
|
|
|
if (show_alert_color == false) {
|
2011-12-07 08:13:33 +01:00
|
|
|
CLAMP(input, 0.0f, 1.0f);
|
2013-03-05 21:30:38 +01:00
|
|
|
weightpaint_color(r_col, dm_wcinfo, input);
|
2011-12-07 08:13:33 +01:00
|
|
|
}
|
2013-03-06 03:57:31 +01:00
|
|
|
else {
|
|
|
|
copy_v3_v3_char((char *)r_col, dm_wcinfo->alert_color);
|
|
|
|
r_col[3] = 255;
|
|
|
|
}
|
2009-05-23 05:24:15 +02:00
|
|
|
}
|
|
|
|
|
2013-03-16 15:33:32 +01:00
|
|
|
static DMWeightColorInfo G_dm_wcinfo;
|
2013-03-06 03:57:31 +01:00
|
|
|
|
|
|
|
void vDM_ColorBand_store(const ColorBand *coba, const char alert_color[4])
|
2009-05-23 05:24:15 +02:00
|
|
|
{
|
2013-03-16 15:33:32 +01:00
|
|
|
G_dm_wcinfo.coba = coba;
|
|
|
|
G_dm_wcinfo.alert_color = alert_color;
|
2009-05-23 05:24:15 +02:00
|
|
|
}
|
|
|
|
|
2011-12-20 03:04:35 +01:00
|
|
|
/* return an array of vertex weight colors, caller must free.
|
|
|
|
*
|
|
|
|
* note that we could save some memory and allocate RGB only but then we'd need to
|
|
|
|
* re-arrange the colors when copying to the face since MCol has odd ordering,
|
|
|
|
* so leave this as is - campbell */
|
2013-04-13 22:20:21 +02:00
|
|
|
static void calc_weightpaint_vert_array(Object *ob, DerivedMesh *dm, int const draw_flag, DMWeightColorInfo *dm_wcinfo,
|
|
|
|
unsigned char (*r_wtcol_v)[4])
|
2009-05-23 05:24:15 +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
|
|
|
MDeformVert *dv = DM_get_vert_data_layer(dm, CD_MDEFORMVERT);
|
|
|
|
int numVerts = dm->getNumVerts(dm);
|
2011-12-18 13:54:50 +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
|
|
|
if (dv) {
|
2013-04-13 22:20:21 +02:00
|
|
|
unsigned char (*wc)[4] = r_wtcol_v;
|
2011-12-19 23:55:04 +01:00
|
|
|
unsigned int i;
|
2011-12-18 13:54:50 +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
|
|
|
/* variables for multipaint */
|
2011-12-18 13:54:50 +01:00
|
|
|
const int defbase_tot = BLI_countlist(&ob->defbase);
|
2012-05-12 21:18:02 +02:00
|
|
|
const int defbase_act = ob->actdef - 1;
|
2012-09-05 05:45:32 +02:00
|
|
|
|
|
|
|
int defbase_sel_tot = 0;
|
2013-05-15 17:52:48 +02:00
|
|
|
bool *defbase_sel = NULL;
|
2012-09-05 05:45:32 +02:00
|
|
|
|
|
|
|
if (draw_flag & CALC_WP_MULTIPAINT) {
|
|
|
|
defbase_sel = BKE_objdef_selected_get(ob, defbase_tot, &defbase_sel_tot);
|
|
|
|
}
|
2011-12-18 13:54:50 +01:00
|
|
|
|
2013-04-13 22:20:21 +02:00
|
|
|
for (i = numVerts; i != 0; i--, wc++, dv++) {
|
|
|
|
calc_weightpaint_vert_color((unsigned char *)wc, dv, dm_wcinfo, defbase_tot, defbase_act, defbase_sel, defbase_sel_tot, draw_flag);
|
2011-12-18 13:54:50 +01:00
|
|
|
}
|
|
|
|
|
2012-09-05 05:45:32 +02:00
|
|
|
if (defbase_sel) {
|
|
|
|
MEM_freeN(defbase_sel);
|
|
|
|
}
|
2011-12-18 13:54:50 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
int col_i;
|
2013-02-22 05:09:04 +01:00
|
|
|
if (draw_flag & (CALC_WP_GROUP_USER_ACTIVE | CALC_WP_GROUP_USER_ALL)) {
|
|
|
|
col_i = 0;
|
|
|
|
}
|
|
|
|
else {
|
2013-03-05 21:30:38 +01:00
|
|
|
weightpaint_color((unsigned char *)&col_i, dm_wcinfo, 0.0f);
|
2013-02-22 05:09:04 +01:00
|
|
|
}
|
2013-04-13 22:20:21 +02:00
|
|
|
fill_vn_i((int *)r_wtcol_v, numVerts, col_i);
|
2011-12-19 23:55: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
|
|
|
/* return an array of vertex weight colors from given weights, caller must free.
|
|
|
|
*
|
|
|
|
* note that we could save some memory and allocate RGB only but then we'd need to
|
|
|
|
* re-arrange the colors when copying to the face since MCol has odd ordering,
|
|
|
|
* so leave this as is - campbell */
|
2013-04-13 22:20:21 +02:00
|
|
|
static void calc_colors_from_weights_array(const int num, const float *weights,
|
|
|
|
unsigned char (*r_wtcol_v)[4])
|
2011-12-19 23:55:04 +01:00
|
|
|
{
|
2013-04-13 22:20:21 +02:00
|
|
|
unsigned char (*wc)[4] = r_wtcol_v;
|
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
|
|
|
int i;
|
2011-12-19 23:55:04 +01:00
|
|
|
|
2013-04-13 22:20:21 +02:00
|
|
|
for (i = 0; i < num; i++, wc++, weights++) {
|
|
|
|
weightpaint_color((unsigned char *)wc, NULL, *weights);
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
void DM_update_weight_mcol(Object *ob, DerivedMesh *dm, int const draw_flag,
|
|
|
|
float *weights, int num, const int *indices)
|
2011-12-19 23:55:04 +01:00
|
|
|
{
|
2013-04-16 07:59:48 +02:00
|
|
|
BMEditMesh *em = (dm->type == DM_TYPE_EDITBMESH) ? BKE_editmesh_from_object(ob) : NULL;
|
2013-04-13 22:20:21 +02:00
|
|
|
unsigned char (*wtcol_v)[4];
|
2012-01-22 21:05:26 +01:00
|
|
|
int numVerts = dm->getNumVerts(dm);
|
2013-04-15 10:43:17 +02:00
|
|
|
int i;
|
2011-12-19 23:55:04 +01:00
|
|
|
|
2013-04-13 22:20:21 +02:00
|
|
|
if (em) {
|
2013-04-18 19:09:56 +02:00
|
|
|
BKE_editmesh_color_ensure(em, BM_VERT);
|
|
|
|
wtcol_v = em->derivedVertColor;
|
2013-04-13 22:20:21 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
wtcol_v = MEM_mallocN(sizeof(*wtcol_v) * numVerts, __func__);
|
|
|
|
}
|
|
|
|
|
2012-12-03 15:12:40 +01:00
|
|
|
/* Weights are given by caller. */
|
|
|
|
if (weights) {
|
|
|
|
float *w = weights;
|
|
|
|
/* If indices is not NULL, it means we do not have weights for all vertices,
|
|
|
|
* so we must create them (and set them to zero)... */
|
|
|
|
if (indices) {
|
|
|
|
w = MEM_callocN(sizeof(float) * numVerts, "Temp weight array DM_update_weight_mcol");
|
|
|
|
i = num;
|
|
|
|
while (i--)
|
|
|
|
w[indices[i]] = weights[i];
|
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
|
|
|
}
|
2011-12-20 02:33:14 +01:00
|
|
|
|
2012-12-03 15:12:40 +01:00
|
|
|
/* Convert float weights to colors. */
|
2013-04-13 22:20:21 +02:00
|
|
|
calc_colors_from_weights_array(numVerts, w, wtcol_v);
|
2011-12-20 02:33:14 +01:00
|
|
|
|
2012-12-03 15:12:40 +01:00
|
|
|
if (indices)
|
|
|
|
MEM_freeN(w);
|
|
|
|
}
|
2013-03-16 15:33:32 +01:00
|
|
|
else {
|
|
|
|
/* No weights given, take them from active vgroup(s). */
|
2013-04-13 22:20:21 +02:00
|
|
|
calc_weightpaint_vert_array(ob, dm, draw_flag, &G_dm_wcinfo, wtcol_v);
|
2013-03-16 15:33:32 +01:00
|
|
|
}
|
2012-12-03 15:12:40 +01:00
|
|
|
|
2013-04-13 22:20:21 +02:00
|
|
|
if (dm->type == DM_TYPE_EDITBMESH) {
|
2013-11-05 05:23:46 +01:00
|
|
|
/* editmesh draw function checks specifically for this */
|
2012-12-03 15:12:40 +01:00
|
|
|
}
|
|
|
|
else {
|
2013-05-02 03:49:10 +02:00
|
|
|
const int dm_totpoly = dm->getNumPolys(dm);
|
|
|
|
const int dm_totloop = dm->getNumLoops(dm);
|
2013-04-15 10:43:17 +02:00
|
|
|
unsigned char(*wtcol_l)[4] = CustomData_get_layer(dm->getLoopDataLayout(dm), CD_PREVIEW_MLOOPCOL);
|
|
|
|
MLoop *mloop = dm->getLoopArray(dm), *ml;
|
|
|
|
MPoly *mp = dm->getPolyArray(dm);
|
2013-05-03 10:37:18 +02:00
|
|
|
int l_index;
|
2013-04-15 10:43:17 +02:00
|
|
|
int j;
|
|
|
|
|
2013-04-13 22:20:21 +02:00
|
|
|
/* now add to loops, so the data can be passed through the modifier stack */
|
|
|
|
/* If no CD_PREVIEW_MLOOPCOL existed yet, we have to add a new one! */
|
|
|
|
if (!wtcol_l) {
|
2013-05-02 03:49:10 +02:00
|
|
|
wtcol_l = MEM_mallocN(sizeof(*wtcol_l) * dm_totloop, __func__);
|
2013-05-03 10:37:18 +02:00
|
|
|
CustomData_add_layer(&dm->loopData, CD_PREVIEW_MLOOPCOL, CD_ASSIGN, wtcol_l, dm_totloop);
|
2013-04-13 22:20:21 +02:00
|
|
|
}
|
2011-06-14 05:16:08 +02:00
|
|
|
|
2013-05-03 10:37:18 +02:00
|
|
|
l_index = 0;
|
2013-05-02 03:49:10 +02:00
|
|
|
for (i = 0; i < dm_totpoly; i++, mp++) {
|
|
|
|
ml = mloop + mp->loopstart;
|
|
|
|
|
2013-05-03 10:37:18 +02:00
|
|
|
for (j = 0; j < mp->totloop; j++, ml++, l_index++) {
|
|
|
|
copy_v4_v4_char((char *)&wtcol_l[l_index],
|
2013-05-02 03:49:10 +02:00
|
|
|
(char *)&wtcol_v[ml->v]);
|
2012-01-22 21:05:26 +01:00
|
|
|
}
|
2009-08-31 17:57:13 +02:00
|
|
|
}
|
2013-04-13 22:20:21 +02:00
|
|
|
MEM_freeN(wtcol_v);
|
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
|
|
|
|
2013-04-13 22:20:21 +02:00
|
|
|
dm->dirty |= DM_DIRTY_TESS_CDLAYERS;
|
|
|
|
}
|
2009-05-23 05:24:15 +02:00
|
|
|
}
|
|
|
|
|
2013-04-17 11:27:23 +02:00
|
|
|
static void DM_update_statvis_color(Scene *scene, Object *ob, DerivedMesh *dm)
|
|
|
|
{
|
|
|
|
BMEditMesh *em = BKE_editmesh_from_object(ob);
|
|
|
|
|
2013-04-18 19:09:56 +02:00
|
|
|
BKE_editmesh_statvis_calc(em, dm, &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;
|
|
|
|
|
|
|
|
if (!me->key)
|
2012-10-21 07:46:41 +02:00
|
|
|
return;
|
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];
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (kb->data)
|
|
|
|
MEM_freeN(kb->data);
|
|
|
|
|
|
|
|
cos = CustomData_get_layer_n(&dm->vertData, CD_SHAPEKEY, i);
|
|
|
|
kb->totelem = dm->numVertData;
|
|
|
|
|
2012-05-12 21:18:02 +02:00
|
|
|
kb->data = kbcos = MEM_mallocN(sizeof(float) * 3 * kb->totelem, "kbcos DerivedMesh.c");
|
2011-04-15 07:20:18 +02:00
|
|
|
if (kb->uid == actshape_uid) {
|
|
|
|
MVert *mvert = dm->getVertArray(dm);
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
kb->totelem = dm->numVertData;
|
2012-05-12 21:18:02 +02:00
|
|
|
kb->data = MEM_callocN(sizeof(float) * 3 * kb->totelem, "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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-09 16:32:55 +02:00
|
|
|
static void add_shapekey_layers(DerivedMesh *dm, Mesh *me, Object *UNUSED(ob))
|
2011-04-15 07:20:18 +02:00
|
|
|
{
|
|
|
|
KeyBlock *kb;
|
|
|
|
Key *key = me->key;
|
2012-01-30 02:18:49 +01:00
|
|
|
int i;
|
|
|
|
const size_t shape_alloc_len = sizeof(float) * 3 * me->totvert;
|
|
|
|
|
2011-04-15 07:20:18 +02:00
|
|
|
if (!me->key)
|
|
|
|
return;
|
2012-01-30 02:18:49 +01:00
|
|
|
|
|
|
|
/* ensure we can use mesh vertex count for derived mesh custom data */
|
|
|
|
if (me->totvert != dm->getNumVerts(dm)) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"%s: vertex size mismatch (mesh/dm) '%s' (%d != %d)\n",
|
2012-05-12 21:18:02 +02:00
|
|
|
__func__, me->id.name + 2, me->totvert, dm->getNumVerts(dm));
|
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;
|
|
|
|
|
|
|
|
if (me->totvert != kb->totelem) {
|
|
|
|
fprintf(stderr,
|
2012-04-12 16:36:57 +02:00
|
|
|
"%s: vertex size mismatch (Mesh '%s':%d != KeyBlock '%s':%d)\n",
|
|
|
|
__func__, me->id.name + 2, me->totvert, kb->name, kb->totelem);
|
2012-01-30 02:18:49 +01:00
|
|
|
array = MEM_callocN(shape_alloc_len, __func__);
|
2011-04-15 07:20:18 +02:00
|
|
|
}
|
2012-01-30 02:18:49 +01:00
|
|
|
else {
|
|
|
|
array = MEM_mallocN(shape_alloc_len, __func__);
|
|
|
|
memcpy(array, kb->data, shape_alloc_len);
|
2011-04-15 07:20:18 +02:00
|
|
|
}
|
2012-01-30 02:18:49 +01:00
|
|
|
|
|
|
|
CustomData_add_layer_named(&dm->vertData, CD_SHAPEKEY, CD_ASSIGN, array, dm->numVertData, kb->name);
|
|
|
|
ci = CustomData_get_layer_index_n(&dm->vertData, CD_SHAPEKEY, i);
|
|
|
|
|
|
|
|
dm->vertData.layers[ci].uid = kb->uid;
|
2011-04-15 07:20:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-30 19:36:43 +02:00
|
|
|
/**
|
|
|
|
* Called after calculating all modifiers.
|
|
|
|
*
|
|
|
|
* \note tessfaces should already be calculated.
|
|
|
|
*/
|
|
|
|
static void dm_ensure_display_normals(DerivedMesh *dm)
|
|
|
|
{
|
2013-05-30 20:09:19 +02:00
|
|
|
/* this is for final output only, up until now this layer should be missing */
|
|
|
|
BLI_assert(CustomData_has_layer(&dm->polyData, CD_NORMAL) == false);
|
|
|
|
|
2013-05-30 19:36:43 +02:00
|
|
|
if ((dm->type == DM_TYPE_CDDM) &&
|
|
|
|
((dm->dirty & DM_DIRTY_NORMALS) || CustomData_has_layer(&dm->faceData, CD_NORMAL) == FALSE))
|
|
|
|
{
|
|
|
|
/* if normals are dirty we want to calculate vertex normals too */
|
|
|
|
CDDM_calc_normals_mapping_ex(dm, (dm->dirty & DM_DIRTY_NORMALS) ? false : true);
|
|
|
|
}
|
|
|
|
}
|
2009-06-08 22:08:19 +02:00
|
|
|
/* new value for useDeform -1 (hack for the gameengine):
|
|
|
|
* - apply only the modifier stack of the object, skipping the virtual modifiers,
|
|
|
|
* - don't apply the key
|
|
|
|
* - apply deform modifiers and input vertexco
|
|
|
|
*/
|
2009-01-04 15:14:06 +01:00
|
|
|
static void mesh_calc_modifiers(Scene *scene, Object *ob, float (*inputVertexCos)[3],
|
2012-05-12 21:18:02 +02:00
|
|
|
DerivedMesh **deform_r, DerivedMesh **final_r,
|
|
|
|
int useRenderParams, int useDeform,
|
|
|
|
int needMapping, CustomDataMask dataMask,
|
|
|
|
int index, int useCache, int build_shapekey_layers)
|
2005-03-27 22:34:18 +02:00
|
|
|
{
|
2005-07-20 06:44:02 +02:00
|
|
|
Mesh *me = ob->data;
|
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;
|
2012-05-12 21:18:02 +02:00
|
|
|
DerivedMesh *dm = NULL, *orcodm, *clothorcodm, *finaldm;
|
- 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
|
|
|
int numVerts = me->totvert;
|
2006-08-28 03:12:36 +02:00
|
|
|
int required_mode;
|
2012-05-12 21:18:02 +02:00
|
|
|
int isPrevDeform = FALSE;
|
2010-10-02 18:42:12 +02:00
|
|
|
int skipVirtualArmature = (useDeform < 0);
|
2012-05-12 21:18:02 +02:00
|
|
|
MultiresModifierData *mmd = get_multires_modifier(scene, ob, 0);
|
2011-01-31 21:02:51 +01:00
|
|
|
int has_multires = mmd != NULL, multires_applied = 0;
|
|
|
|
int sculpt_mode = ob->mode & OB_MODE_SCULPT && ob->sculpt;
|
2012-12-30 19:29:41 +01:00
|
|
|
int sculpt_dyntopo = (sculpt_mode && ob->sculpt->bm);
|
2013-04-13 22:20:21 +02:00
|
|
|
int draw_flag = dm_drawflag_calc(scene->toolsettings);
|
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! */
|
|
|
|
const int do_mod_mcol = (ob->mode == OB_MODE_OBJECT);
|
|
|
|
#if 0 /* XXX Will re-enable this when we have global mod stack options. */
|
|
|
|
const int do_final_wmcol = (scene->toolsettings->weights_preview == WP_WPREVIEW_FINAL) && do_wmcol;
|
|
|
|
#endif
|
|
|
|
const int do_final_wmcol = FALSE;
|
2012-03-22 09:41:50 +01:00
|
|
|
int do_init_wmcol = ((dataMask & CD_MASK_PREVIEW_MCOL) && (ob->mode & OB_MODE_WEIGHT_PAINT) && !do_final_wmcol);
|
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 Same as above... For now, only weights preview in WPaint mode. */
|
|
|
|
const int do_mod_wmcol = do_init_wmcol;
|
2011-09-14 04:04:26 +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;
|
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;
|
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (mmd && !mmd->sculptlvl)
|
2011-01-31 21:02:51 +01:00
|
|
|
has_multires = 0;
|
2005-03-27 22:34:18 +02:00
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (!skipVirtualArmature) {
|
2013-08-19 11:05:34 +02:00
|
|
|
firstmd = modifiers_getVirtualModifierList(ob, &virtualModifierData);
|
2010-10-02 18:42:12 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* game engine exception */
|
|
|
|
firstmd = ob->modifiers.first;
|
2012-03-24 07:18:31 +01:00
|
|
|
if (firstmd && firstmd->type == eModifierType_Armature)
|
2010-10-02 18:42:12 +02:00
|
|
|
firstmd = firstmd->next;
|
|
|
|
}
|
2005-03-27 22:34:18 +02:00
|
|
|
|
2010-10-02 18:42:12 +02:00
|
|
|
md = firstmd;
|
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
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (useRenderParams) required_mode = eModifierMode_Render;
|
2009-06-15 13:48:42 +02:00
|
|
|
else required_mode = eModifierMode_Realtime;
|
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (do_mod_wmcol || 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
|
|
|
|
|
|
|
/* even if the modifier doesn't need the data, to make a preview it may */
|
|
|
|
if (previewmd) {
|
|
|
|
if (do_mod_wmcol) {
|
|
|
|
previewmask = CD_MASK_MDEFORMVERT;
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2013-06-13 02:33:48 +02:00
|
|
|
datamasks = modifiers_calcDataMasks(scene, ob, md, dataMask, required_mode, previewmd, previewmask);
|
|
|
|
curr = datamasks;
|
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (deform_r) *deform_r = NULL;
|
2005-07-19 02:21:01 +02:00
|
|
|
*final_r = NULL;
|
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (useDeform) {
|
|
|
|
if (inputVertexCos)
|
2009-06-08 22:08:19 +02:00
|
|
|
deformedVerts = inputVertexCos;
|
2005-09-26 17:34:21 +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) {
|
2005-08-03 06:04:05 +02:00
|
|
|
ModifierTypeInfo *mti = modifierType_getInfo(md->type);
|
2005-07-19 22:14:17 +02:00
|
|
|
|
2012-05-12 21:18:02 +02:00
|
|
|
md->scene = scene;
|
2009-01-04 15:14:06 +01:00
|
|
|
|
2012-03-24 07:18:31 +01: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)
|
2013-03-26 08:29:01 +01:00
|
|
|
deformedVerts = BKE_mesh_vertexCos_get(me, &numVerts);
|
2005-07-19 22:14:17 +02:00
|
|
|
|
2013-05-30 19:36:43 +02:00
|
|
|
modwrap_deformVerts(md, ob, NULL, deformedVerts, numVerts, deform_app_flags);
|
2012-03-24 07:18:31 +01:00
|
|
|
}
|
|
|
|
else {
|
2005-07-19 22:14:17 +02:00
|
|
|
break;
|
|
|
|
}
|
2008-07-28 13:01:34 +02:00
|
|
|
|
|
|
|
/* grab modifiers until index i */
|
2012-12-15 06:46:41 +01:00
|
|
|
if ((index >= 0) && (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.)
|
|
|
|
*/
|
2006-08-30 05:05:30 +02:00
|
|
|
if (deform_r) {
|
2013-12-25 22:26:41 +01:00
|
|
|
*deform_r = CDDM_from_mesh(me);
|
2011-12-05 00:13:28 +01:00
|
|
|
|
2011-04-15 07:20:18 +02:00
|
|
|
if (build_shapekey_layers)
|
|
|
|
add_shapekey_layers(dm, me, ob);
|
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (deformedVerts) {
|
2006-08-30 05:05:30 +02:00
|
|
|
CDDM_apply_vert_coords(*deform_r, 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
|
2013-03-26 08:29:01 +01:00
|
|
|
deformedVerts = BKE_mesh_vertexCos_get(me, &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
|
|
|
|
* OnlyDeform ones.
|
|
|
|
*/
|
2005-07-19 22:14:17 +02:00
|
|
|
dm = NULL;
|
2007-12-05 13:40:54 +01:00
|
|
|
orcodm = NULL;
|
2010-03-30 13:49:07 +02:00
|
|
|
clothorcodm = 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) {
|
2005-08-03 06:04:05 +02:00
|
|
|
ModifierTypeInfo *mti = modifierType_getInfo(md->type);
|
2005-07-19 22:14:17 +02:00
|
|
|
|
2012-05-12 21:18:02 +02:00
|
|
|
md->scene = scene;
|
2011-01-31 21:02:51 +01:00
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (!modifier_isEnabled(scene, md, required_mode)) continue;
|
|
|
|
if (mti->type == eModifierTypeType_OnlyDeform && !useDeform) continue;
|
|
|
|
if ((mti->flags & eModifierTypeFlag_RequiresOriginalData) && dm) {
|
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;
|
|
|
|
}
|
2012-12-30 19:29:41 +01:00
|
|
|
if (sculpt_mode &&
|
2014-01-12 12:05:24 +01:00
|
|
|
(!has_multires || multires_applied || ob->sculpt->bm))
|
2012-12-30 19:29:41 +01:00
|
|
|
{
|
2012-05-12 21:18:02 +02:00
|
|
|
int unsupported = 0;
|
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. */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-05-15 10:25:42 +02:00
|
|
|
if (sculpt_dyntopo && !useRenderParams)
|
2012-12-30 19:29:41 +01:00
|
|
|
unsupported = TRUE;
|
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (scene->toolsettings->sculpt->flags & SCULPT_ONLY_DEFORM)
|
2012-05-12 21:18:02 +02: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) {
|
2012-10-27 13:12:09 +02:00
|
|
|
modifier_setError(md, "Not supported in sculpt mode");
|
2011-01-31 21:02:51 +01:00
|
|
|
continue;
|
|
|
|
}
|
2011-05-04 15:15:42 +02:00
|
|
|
}
|
2012-03-24 07:18:31 +01:00
|
|
|
if (needMapping && !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;
|
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (dm && (mask & CD_MASK_ORCO))
|
2010-03-30 13:49:07 +02:00
|
|
|
add_orco_dm(ob, NULL, dm, orcodm, CD_ORCO);
|
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
|
|
|
|
* a result of previous modifiers (could be a DerivedMesh or just
|
|
|
|
* 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) {
|
|
|
|
if (dm) {
|
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.
|
|
|
|
*/
|
2005-07-19 22:14:17 +02:00
|
|
|
numVerts = dm->getNumVerts(dm);
|
2006-08-28 03:12:36 +02:00
|
|
|
deformedVerts =
|
2012-05-12 21:18:02 +02:00
|
|
|
MEM_mallocN(sizeof(*deformedVerts) * numVerts, "dfmv");
|
2005-07-19 22:14:17 +02:00
|
|
|
dm->getVertCos(dm, deformedVerts);
|
2012-03-24 07:18:31 +01:00
|
|
|
}
|
|
|
|
else {
|
2013-03-26 08:29:01 +01:00
|
|
|
deformedVerts = BKE_mesh_vertexCos_get(me, &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 */
|
2012-03-24 07:18:31 +01:00
|
|
|
if (dm && dm->type == DM_TYPE_CDDM) {
|
2010-09-30 12:51:36 +02:00
|
|
|
CDDM_apply_vert_coords(dm, deformedVerts);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-30 19:36:43 +02:00
|
|
|
modwrap_deformVerts(md, ob, dm, deformedVerts, numVerts, deform_app_flags);
|
2012-03-24 07:18:31 +01:00
|
|
|
}
|
|
|
|
else {
|
2006-08-28 03:12:36 +02:00
|
|
|
DerivedMesh *ndm;
|
2005-07-19 22:14:17 +02:00
|
|
|
|
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
|
|
|
|
2006-08-28 03:12:36 +02:00
|
|
|
/* apply vertex coordinates or build a DerivedMesh as necessary */
|
2012-03-24 07:18:31 +01:00
|
|
|
if (dm) {
|
|
|
|
if (deformedVerts) {
|
2012-01-29 22:59:47 +01:00
|
|
|
DerivedMesh *tdm = CDDM_copy(dm);
|
2006-08-28 03:12:36 +02:00
|
|
|
dm->release(dm);
|
|
|
|
dm = tdm;
|
|
|
|
|
|
|
|
CDDM_apply_vert_coords(dm, deformedVerts);
|
|
|
|
}
|
2012-03-24 07:18:31 +01:00
|
|
|
}
|
|
|
|
else {
|
2013-12-25 22:26:41 +01:00
|
|
|
dm = CDDM_from_mesh(me);
|
2013-09-04 03:29:34 +02:00
|
|
|
ASSERT_IS_VALID_DM(dm);
|
2006-08-28 03:12:36 +02:00
|
|
|
|
2011-04-15 07:20:18 +02:00
|
|
|
if (build_shapekey_layers)
|
|
|
|
add_shapekey_layers(dm, me, ob);
|
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (deformedVerts) {
|
2006-08-28 03:12:36 +02:00
|
|
|
CDDM_apply_vert_coords(dm, deformedVerts);
|
|
|
|
}
|
2009-05-23 05:24:15 +02:00
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (do_init_wmcol)
|
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
|
|
|
DM_update_weight_mcol(ob, dm, draw_flag, NULL, 0, NULL);
|
2010-02-09 19:06:57 +01: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.
|
|
|
|
*/
|
2012-03-24 07:18:31 +01:00
|
|
|
if (needMapping || (nextmask & CD_MASK_ORIGINDEX)) {
|
2010-10-21 03:08:12 +02:00
|
|
|
/* calc */
|
2010-02-09 19:06:57 +01:00
|
|
|
DM_add_vert_layer(dm, CD_ORIGINDEX, CD_CALLOC, NULL);
|
|
|
|
DM_add_edge_layer(dm, CD_ORIGINDEX, CD_CALLOC, NULL);
|
2011-11-29 06:09:54 +01:00
|
|
|
DM_add_poly_layer(dm, CD_ORIGINDEX, CD_CALLOC, NULL);
|
2010-02-09 19:06:57 +01:00
|
|
|
|
2013-09-09 07:42:26 +02:00
|
|
|
#pragma omp parallel sections if (dm->numVertData + dm->numEdgeData + dm->numPolyData >= BKE_MESH_OMP_LIMIT)
|
2013-01-18 07:26:06 +01:00
|
|
|
{
|
|
|
|
#pragma omp section
|
|
|
|
{ range_vn_i(DM_get_vert_data_layer(dm, CD_ORIGINDEX), dm->numVertData, 0); }
|
|
|
|
#pragma omp section
|
|
|
|
{ range_vn_i(DM_get_edge_data_layer(dm, CD_ORIGINDEX), dm->numEdgeData, 0); }
|
|
|
|
#pragma omp section
|
|
|
|
{ range_vn_i(DM_get_poly_data_layer(dm, CD_ORIGINDEX), dm->numPolyData, 0); }
|
|
|
|
}
|
2010-02-09 19:06:57 +01:00
|
|
|
}
|
2006-08-28 03:12:36 +02:00
|
|
|
}
|
|
|
|
|
2010-03-30 13:49:07 +02:00
|
|
|
|
2006-12-05 18:42:03 +01:00
|
|
|
/* set the DerivedMesh to only copy needed data */
|
2012-05-12 21:18:02 +02:00
|
|
|
mask = curr->mask;
|
2011-08-01 08:50:24 +02:00
|
|
|
/* needMapping check here fixes bug [#28112], otherwise its
|
|
|
|
* possible that it wont be copied */
|
2011-07-08 13:03:37 +02:00
|
|
|
mask |= append_mask;
|
2011-08-01 08:50:24 +02:00
|
|
|
DM_set_only_copy(dm, mask | (needMapping ? CD_MASK_ORIGINDEX : 0));
|
Particles
=========
Merge of the famous particle patch by Janne Karhu, a full rewrite
of the Blender particle system. This includes:
- Emitter, Hair and Reactor particle types.
- Newtonian, Keyed and Boids physics.
- Various particle visualisation and rendering types.
- Vertex group and texture control for various properties.
- Interpolated child particles from parents.
- Hair editing with combing, growing, cutting, .. .
- Explode modifier.
- Harmonic, Magnetic fields, and multiple falloff types.
.. and lots of other things, some more info is here:
http://wiki.blender.org/index.php/BlenderDev/Particles_Rewrite
http://wiki.blender.org/index.php/BlenderDev/Particles_Rewrite_Doc
The new particle system cannot be backwards compatible. Old particle
systems are being converted to the new system, but will require
tweaking to get them looking the same as before.
Point Cache
===========
The new system to replace manual baking, based on automatic caching
on disk. This is currently used by softbodies and the particle system.
See the Cache API section on:
http://wiki.blender.org/index.php/BlenderDev/PhysicsSprint
Documentation
=============
These new features still need good docs for the release logs, help
for this is appreciated.
2007-11-26 23:09:57 +01:00
|
|
|
|
2010-03-30 13:49:07 +02:00
|
|
|
/* add cloth rest shape key if need */
|
2012-03-24 07:18:31 +01:00
|
|
|
if (mask & CD_MASK_CLOTH_ORCO)
|
2010-03-30 13:49:07 +02:00
|
|
|
add_orco_dm(ob, NULL, dm, clothorcodm, CD_CLOTH_ORCO);
|
|
|
|
|
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) {
|
2012-03-24 07:18:31 +01:00
|
|
|
if (!CustomData_has_layer(&dm->loopData, CD_ORIGSPACE_MLOOP)) {
|
2012-02-05 12:30:26 +01:00
|
|
|
DM_add_loop_layer(dm, CD_ORIGSPACE_MLOOP, CD_CALLOC, NULL);
|
|
|
|
DM_init_origspace(dm);
|
|
|
|
}
|
|
|
|
}
|
2007-12-05 13:40:54 +01:00
|
|
|
|
2013-05-30 19:36:43 +02:00
|
|
|
ndm = modwrap_applyModifier(md, ob, dm, app_flags);
|
2013-09-04 03:29:34 +02:00
|
|
|
ASSERT_IS_VALID_DM(ndm);
|
2006-08-28 03:12:36 +02:00
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (ndm) {
|
2006-08-28 03:12:36 +02:00
|
|
|
/* if the modifier returned a new dm, release the old one */
|
2012-03-24 07:18:31 +01:00
|
|
|
if (dm && dm != ndm) dm->release(dm);
|
2005-08-03 06:04:05 +02:00
|
|
|
|
2005-07-26 04:44:59 +02:00
|
|
|
dm = ndm;
|
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (deformedVerts) {
|
|
|
|
if (deformedVerts != inputVertexCos)
|
2005-07-26 04:44:59 +02:00
|
|
|
MEM_freeN(deformedVerts);
|
2006-08-28 03:12:36 +02:00
|
|
|
|
2005-07-26 04:44:59 +02:00
|
|
|
deformedVerts = NULL;
|
2005-07-19 22:14:17 +02:00
|
|
|
}
|
2012-04-01 17:02:19 +02:00
|
|
|
}
|
2010-03-30 13:49:07 +02:00
|
|
|
|
|
|
|
/* create an orco derivedmesh in parallel */
|
2012-03-24 07:18:31 +01:00
|
|
|
if (nextmask & CD_MASK_ORCO) {
|
|
|
|
if (!orcodm)
|
2012-05-12 21:18:02 +02:00
|
|
|
orcodm = create_orco_dm(ob, me, NULL, CD_ORCO);
|
2010-03-30 13:49:07 +02:00
|
|
|
|
|
|
|
nextmask &= ~CD_MASK_ORCO;
|
2012-05-28 23:02:44 +02:00
|
|
|
DM_set_only_copy(orcodm, 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
|
|
|
|
|
|
|
ndm = modwrap_applyModifier(md, ob, orcodm, (app_flags & ~MOD_APPLY_USECACHE) | MOD_APPLY_ORCO);
|
2013-09-04 03:29:34 +02:00
|
|
|
ASSERT_IS_VALID_DM(ndm);
|
2010-03-30 13:49:07 +02:00
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (ndm) {
|
2010-03-30 13:49:07 +02:00
|
|
|
/* if the modifier returned a new dm, release the old one */
|
2012-03-24 07:18:31 +01:00
|
|
|
if (orcodm && orcodm != ndm) orcodm->release(orcodm);
|
2010-03-30 13:49:07 +02:00
|
|
|
orcodm = ndm;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* create cloth orco derivedmesh in parallel */
|
2012-03-24 07:18:31 +01:00
|
|
|
if (nextmask & CD_MASK_CLOTH_ORCO) {
|
|
|
|
if (!clothorcodm)
|
2012-05-12 21:18:02 +02:00
|
|
|
clothorcodm = create_orco_dm(ob, me, NULL, CD_CLOTH_ORCO);
|
2010-03-30 13:49:07 +02:00
|
|
|
|
|
|
|
nextmask &= ~CD_MASK_CLOTH_ORCO;
|
2010-10-21 03:08:12 +02:00
|
|
|
DM_set_only_copy(clothorcodm, nextmask | CD_MASK_ORIGINDEX);
|
2013-05-30 19:36:43 +02:00
|
|
|
|
|
|
|
ndm = modwrap_applyModifier(md, ob, clothorcodm, (app_flags & ~MOD_APPLY_USECACHE) | MOD_APPLY_ORCO);
|
2013-09-04 03:29:34 +02:00
|
|
|
ASSERT_IS_VALID_DM(ndm);
|
2010-03-30 13:49:07 +02:00
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (ndm) {
|
2010-03-30 13:49:07 +02:00
|
|
|
/* if the modifier returned a new dm, release the old one */
|
2012-03-24 07:18:31 +01:00
|
|
|
if (clothorcodm && clothorcodm != ndm) clothorcodm->release(clothorcodm);
|
2010-03-30 13:49:07 +02:00
|
|
|
clothorcodm = ndm;
|
|
|
|
}
|
|
|
|
}
|
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;
|
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
|
|
|
/* In case of active preview modifier, make sure preview mask remains for following modifiers. */
|
|
|
|
else if ((md == previewmd) && (do_mod_wmcol)) {
|
|
|
|
DM_update_weight_mcol(ob, dm, draw_flag, NULL, 0, NULL);
|
2012-03-22 09:41:50 +01:00
|
|
|
append_mask |= CD_MASK_PREVIEW_MLOOPCOL;
|
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
|
|
|
}
|
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 */
|
2012-12-15 06:46:41 +01:00
|
|
|
if ((index >= 0) && (BLI_findindex(&ob->modifiers, md) >= index))
|
2008-07-28 13:01:34 +02:00
|
|
|
break;
|
2011-01-31 21:02:51 +01:00
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (sculpt_mode && md->type == eModifierType_Multires)
|
2011-01-31 21:02:51 +01:00
|
|
|
multires_applied = 1;
|
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);
|
|
|
|
|
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.
|
|
|
|
*/
|
2012-03-24 07:18:31 +01:00
|
|
|
if (dm && deformedVerts) {
|
2012-01-29 22:59:47 +01:00
|
|
|
finaldm = CDDM_copy(dm);
|
2005-07-19 22:14:17 +02:00
|
|
|
|
|
|
|
dm->release(dm);
|
|
|
|
|
2007-12-05 13:40:54 +01:00
|
|
|
CDDM_apply_vert_coords(finaldm, deformedVerts);
|
2009-04-02 16:38:40 +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
|
|
|
#if 0 /* For later nice mod preview! */
|
2012-03-22 09:41:50 +01:00
|
|
|
/* In case we need modified weights in CD_PREVIEW_MCOL, we have to re-compute it. */
|
2012-03-24 07:18:31 +01:00
|
|
|
if (do_final_wmcol)
|
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
|
|
|
DM_update_weight_mcol(ob, finaldm, draw_flag, NULL, 0, NULL);
|
|
|
|
#endif
|
2012-03-24 07:18:31 +01:00
|
|
|
}
|
|
|
|
else if (dm) {
|
2007-12-05 13:40:54 +01:00
|
|
|
finaldm = dm;
|
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
|
|
|
|
|
|
|
#if 0 /* For later nice mod preview! */
|
2012-03-22 09:41:50 +01:00
|
|
|
/* In case we need modified weights in CD_PREVIEW_MCOL, we have to re-compute it. */
|
2012-03-24 07:18:31 +01:00
|
|
|
if (do_final_wmcol)
|
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
|
|
|
DM_update_weight_mcol(ob, finaldm, draw_flag, NULL, 0, NULL);
|
|
|
|
#endif
|
2012-03-24 07:18:31 +01:00
|
|
|
}
|
|
|
|
else {
|
2013-12-25 22:26:41 +01:00
|
|
|
finaldm = CDDM_from_mesh(me);
|
2011-04-15 07:20:18 +02:00
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (build_shapekey_layers) {
|
2011-04-15 07:20:18 +02:00
|
|
|
add_shapekey_layers(finaldm, me, ob);
|
2011-09-07 14:47:23 +02:00
|
|
|
}
|
2011-04-15 07:20:18 +02:00
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (deformedVerts) {
|
2007-12-05 13:40:54 +01:00
|
|
|
CDDM_apply_vert_coords(finaldm, deformedVerts);
|
2006-09-07 08:44:25 +02:00
|
|
|
}
|
2009-04-02 16:38:40 +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
|
|
|
/* In this case, we should never have weight-modifying modifiers in stack... */
|
2012-03-24 07:18:31 +01:00
|
|
|
if (do_init_wmcol)
|
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
|
|
|
DM_update_weight_mcol(ob, finaldm, draw_flag, NULL, 0, NULL);
|
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) {
|
2010-03-30 13:49:07 +02:00
|
|
|
add_orco_dm(ob, NULL, finaldm, orcodm, CD_ORCO);
|
2007-12-05 13:40:54 +01:00
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (deform_r && *deform_r)
|
2010-03-30 13:49:07 +02:00
|
|
|
add_orco_dm(ob, NULL, *deform_r, NULL, CD_ORCO);
|
2008-01-09 15:40:25 +01:00
|
|
|
}
|
2007-12-05 13:40:54 +01:00
|
|
|
|
2012-02-06 07:56:54 +01:00
|
|
|
{
|
|
|
|
/* calculating normals can re-calculate tessfaces in some cases */
|
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
|
|
|
#if 0
|
2012-02-06 07:56:54 +01:00
|
|
|
int num_tessface = finaldm->getNumTessFaces(finaldm);
|
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
|
|
|
#endif
|
2012-02-06 07:56:54 +01:00
|
|
|
/* --------------------------------------------------------------------- */
|
2012-03-02 17:05:54 +01:00
|
|
|
/* First calculate the polygon and vertex normals, re-tessellation
|
2012-02-06 07:56:54 +01:00
|
|
|
* copies these into the tessface's normal layer */
|
2012-02-09 15:28:59 +01:00
|
|
|
|
|
|
|
|
|
|
|
/* comment because this causes a bug when deform is applied after a
|
|
|
|
* bug when applied after a subsurf modifier (SubSurf -> Cast) for eg,
|
|
|
|
* it also looks like this isn't even needed since code above recalc's
|
|
|
|
* normals - campbell */
|
|
|
|
#if 0
|
2012-02-06 07:56:54 +01:00
|
|
|
finaldm->calcNormals(finaldm);
|
2012-02-09 15:28:59 +01:00
|
|
|
#endif
|
2012-02-06 07:56:54 +01:00
|
|
|
|
2012-03-02 17:05:54 +01:00
|
|
|
/* Re-tessellation is necessary to push render data (uvs, textures, colors)
|
2012-02-06 07:56:54 +01:00
|
|
|
* from loops and polys onto the tessfaces. This may be currently be
|
2012-03-02 17:05:54 +01:00
|
|
|
* redundant in cases where the render mode doesn't use these inputs, but
|
|
|
|
* ideally eventually tessellation would happen on-demand, and this is one
|
2012-02-06 07:56:54 +01:00
|
|
|
* of the primary places it would be needed. */
|
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
|
|
|
#if 0
|
|
|
|
if (num_tessface == 0 && finaldm->getNumTessFaces(finaldm) == 0)
|
|
|
|
#else
|
2012-10-30 20:20:17 +01:00
|
|
|
if (finaldm->getNumTessFaces(finaldm) == 0) /* || !CustomData_has_layer(&finaldm->faceData, CD_ORIGINDEX)) */
|
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
|
|
|
#endif
|
|
|
|
{
|
2012-03-02 17:05:54 +01:00
|
|
|
finaldm->recalcTessellation(finaldm);
|
2012-02-06 07:56:54 +01:00
|
|
|
}
|
2012-08-25 01:22:34 +02:00
|
|
|
/* Even if tessellation is not needed, some modifiers might have modified CD layers
|
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
|
|
|
* (like mloopcol or mloopuv), hence we have to update those. */
|
|
|
|
else if (finaldm->dirty & DM_DIRTY_TESS_CDLAYERS) {
|
2012-10-30 20:20:17 +01:00
|
|
|
/* A tessellation already exists, it should always have a CD_ORIGINDEX. */
|
|
|
|
BLI_assert(CustomData_has_layer(&finaldm->faceData, CD_ORIGINDEX));
|
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_update_tessface_data(finaldm);
|
|
|
|
}
|
2012-02-06 07:56:54 +01:00
|
|
|
/* Need to watch this, it can cause issues, see bug [#29338] */
|
|
|
|
/* take care with this block, we really need testing frameworks */
|
|
|
|
/* --------------------------------------------------------------------- */
|
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.
|
2012-03-18 07:49:32 +01:00
|
|
|
*/
|
2013-05-30 19:36:43 +02:00
|
|
|
dm_ensure_display_normals(finaldm);
|
2012-02-06 07:56:54 +01:00
|
|
|
}
|
2011-12-07 02:12:53 +01:00
|
|
|
|
2012-04-16 15:53:30 +02:00
|
|
|
#ifdef WITH_GAMEENGINE
|
|
|
|
/* NavMesh - this is a hack but saves having a NavMesh modifier */
|
|
|
|
if ((ob->gameflag & OB_NAVMESH) && (finaldm->type == DM_TYPE_CDDM)) {
|
|
|
|
DerivedMesh *tdm;
|
2012-05-12 21:18:02 +02:00
|
|
|
tdm = navmesh_dm_createNavMeshForVisualization(finaldm);
|
2012-04-16 15:53:30 +02:00
|
|
|
if (finaldm != tdm) {
|
|
|
|
finaldm->release(finaldm);
|
2012-05-12 21:18:02 +02:00
|
|
|
finaldm = tdm;
|
2012-04-16 15:53:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* WITH_GAMEENGINE */
|
|
|
|
|
2007-12-05 13:40:54 +01:00
|
|
|
*final_r = finaldm;
|
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (orcodm)
|
2007-12-05 13:40:54 +01:00
|
|
|
orcodm->release(orcodm);
|
2012-03-24 07:18:31 +01:00
|
|
|
if (clothorcodm)
|
2010-03-30 13:49:07 +02:00
|
|
|
clothorcodm->release(clothorcodm);
|
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
|
|
|
}
|
|
|
|
|
2012-12-21 08:28:14 +01:00
|
|
|
float (*editbmesh_get_vertex_cos(BMEditMesh *em, int *numVerts_r))[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;
|
|
|
|
|
|
|
|
*numVerts_r = 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
|
|
|
|
2012-12-21 08:28:14 +01:00
|
|
|
cos = MEM_mallocN(sizeof(float) * 3 * em->bm->totvert, "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
|
|
|
}
|
|
|
|
|
2011-02-27 07:19:40 +01:00
|
|
|
int editbmesh_modifier_is_enabled(Scene *scene, ModifierData *md, DerivedMesh *dm)
|
2007-07-28 23:04:30 +02:00
|
|
|
{
|
|
|
|
ModifierTypeInfo *mti = modifierType_getInfo(md->type);
|
|
|
|
int required_mode = eModifierMode_Realtime | eModifierMode_Editmode;
|
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (!modifier_isEnabled(scene, md, required_mode)) return 0;
|
|
|
|
if ((mti->flags & eModifierTypeFlag_RequiresOriginalData) && dm) {
|
2012-10-27 13:12:09 +02:00
|
|
|
modifier_setError(md, "Modifier requires original data, bad stack position");
|
2007-07-28 23:04:30 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-05-18 10:46:04 +02:00
|
|
|
static void editbmesh_calc_modifiers(Scene *scene, Object *ob, BMEditMesh *em, DerivedMesh **cage_r,
|
2012-05-12 21:18:02 +02:00
|
|
|
DerivedMesh **final_r,
|
|
|
|
CustomDataMask dataMask)
|
2013-07-05 02:13:14 +02:00
|
|
|
{
|
2013-07-01 02:42:44 +02:00
|
|
|
ModifierData *md, *previewmd = NULL;
|
- 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;
|
2013-07-05 00:24:39 +02:00
|
|
|
CustomDataMask mask, previewmask = 0, append_mask = 0;
|
2012-01-02 07:53:09 +01:00
|
|
|
DerivedMesh *dm, *orcodm = NULL;
|
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;
|
2009-06-15 13:48:42 +02:00
|
|
|
int required_mode = eModifierMode_Realtime | eModifierMode_Editmode;
|
2013-04-13 22:20:21 +02:00
|
|
|
int draw_flag = dm_drawflag_calc(scene->toolsettings);
|
|
|
|
|
|
|
|
// const int do_mod_mcol = true; // (ob->mode == OB_MODE_OBJECT);
|
|
|
|
#if 0 /* XXX Will re-enable this when we have global mod stack options. */
|
|
|
|
const int do_final_wmcol = (scene->toolsettings->weights_preview == WP_WPREVIEW_FINAL) && do_wmcol;
|
|
|
|
#endif
|
|
|
|
const int do_final_wmcol = FALSE;
|
|
|
|
int do_init_wmcol = ((((Mesh *)ob->data)->drawflag & ME_DRAWEIGHT) && !do_final_wmcol);
|
2013-04-17 11:27:23 +02:00
|
|
|
int do_init_statvis = ((((Mesh *)ob->data)->drawflag & ME_DRAW_STATVIS) && !do_init_wmcol);
|
2013-07-01 02:42:44 +02:00
|
|
|
const int do_mod_wmcol = do_init_wmcol;
|
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
|
|
|
|
- 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
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (cage_r && cageIndex == -1) {
|
2009-05-16 18:18:08 +02:00
|
|
|
*cage_r = getEditDerivedBMesh(em, ob, NULL);
|
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
|
|
|
|
2012-01-02 07:53:09 +01:00
|
|
|
dm = NULL;
|
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 */
|
|
|
|
if (do_mod_wmcol) {
|
|
|
|
previewmd = modifiers_getLastPreview(scene, md, required_mode);
|
|
|
|
/* even if the modifier doesn't need the data, to make a preview it may */
|
|
|
|
if (previewmd) {
|
|
|
|
if (do_mod_wmcol) {
|
|
|
|
previewmask = CD_MASK_MDEFORMVERT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
datamasks = modifiers_calcDataMasks(scene, ob, md, dataMask, required_mode, previewmd, previewmask);
|
2006-12-05 18:42:03 +01:00
|
|
|
|
|
|
|
curr = datamasks;
|
2012-03-24 07:18:31 +01:00
|
|
|
for (i = 0; md; i++, md = md->next, curr = curr->next) {
|
2005-08-03 06:04:05 +02:00
|
|
|
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
|
|
|
|
2012-05-12 21:18:02 +02:00
|
|
|
md->scene = scene;
|
2009-01-04 15:14:06 +01:00
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (!editbmesh_modifier_is_enabled(scene, md, dm))
|
- 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;
|
- 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 */
|
2012-03-24 07:18:31 +01:00
|
|
|
if (dm && mti->requiredDataMask) {
|
2009-06-15 13:48:42 +02:00
|
|
|
mask = mti->requiredDataMask(ob, md);
|
2012-03-24 07:18:31 +01:00
|
|
|
if (mask & CD_MASK_ORCO)
|
2010-03-30 13:49:07 +02:00
|
|
|
add_orco_dm(ob, em, dm, orcodm, 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) {
|
|
|
|
if (dm) {
|
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.
|
|
|
|
*/
|
- 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
|
|
|
numVerts = dm->getNumVerts(dm);
|
2006-08-28 03:12:36 +02:00
|
|
|
deformedVerts =
|
2012-05-12 21:18:02 +02:00
|
|
|
MEM_mallocN(sizeof(*deformedVerts) * numVerts, "dfmv");
|
- 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
|
|
|
dm->getVertCos(dm, deformedVerts);
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-03 12:09:26 +02:00
|
|
|
if (mti->deformVertsEM)
|
2013-05-30 19:36:43 +02:00
|
|
|
modwrap_deformVertsEM(md, ob, em, dm, deformedVerts, numVerts);
|
2012-05-09 17:00:26 +02:00
|
|
|
else
|
2013-05-30 19:36:43 +02:00
|
|
|
modwrap_deformVerts(md, ob, dm, deformedVerts, numVerts, 0);
|
2012-03-24 07:18:31 +01:00
|
|
|
}
|
|
|
|
else {
|
2006-08-28 03:12:36 +02:00
|
|
|
DerivedMesh *ndm;
|
|
|
|
|
|
|
|
/* apply vertex coordinates or build a DerivedMesh as necessary */
|
2012-03-24 07:18:31 +01:00
|
|
|
if (dm) {
|
|
|
|
if (deformedVerts) {
|
2012-01-29 22:59:47 +01:00
|
|
|
DerivedMesh *tdm = CDDM_copy(dm);
|
2012-03-24 07:18:31 +01:00
|
|
|
if (!(cage_r && dm == *cage_r)) dm->release(dm);
|
2006-08-28 03:12:36 +02:00
|
|
|
dm = tdm;
|
|
|
|
|
|
|
|
CDDM_apply_vert_coords(dm, deformedVerts);
|
2012-03-24 07:18:31 +01:00
|
|
|
}
|
|
|
|
else if (cage_r && dm == *cage_r) {
|
2006-08-28 03:12:36 +02:00
|
|
|
/* dm may be changed by this modifier, so we need to copy it
|
|
|
|
*/
|
2012-01-29 22:59:47 +01:00
|
|
|
dm = CDDM_copy(dm);
|
2006-08-28 03:12:36 +02:00
|
|
|
}
|
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
}
|
|
|
|
else {
|
2014-01-23 14:50:50 +01:00
|
|
|
dm = CDDM_from_editbmesh(em, false, false);
|
2013-09-04 03:29:34 +02:00
|
|
|
ASSERT_IS_VALID_DM(dm);
|
2006-08-28 03:12:36 +02:00
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (deformedVerts) {
|
2006-08-28 03:12:36 +02:00
|
|
|
CDDM_apply_vert_coords(dm, deformedVerts);
|
|
|
|
}
|
2013-04-13 22:20:21 +02:00
|
|
|
|
|
|
|
if (do_init_wmcol) {
|
|
|
|
DM_update_weight_mcol(ob, dm, draw_flag, NULL, 0, NULL);
|
|
|
|
}
|
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) {
|
|
|
|
if (!orcodm)
|
2012-05-12 21:18:02 +02:00
|
|
|
orcodm = create_orco_dm(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;
|
2010-10-21 03:08:12 +02:00
|
|
|
DM_set_only_copy(orcodm, mask | CD_MASK_ORIGINDEX);
|
2010-05-03 12:09:26 +02:00
|
|
|
|
2013-09-12 10:28:41 +02:00
|
|
|
if (mti->applyModifierEM) {
|
2013-05-30 19:36:43 +02:00
|
|
|
ndm = modwrap_applyModifierEM(md, ob, em, orcodm, MOD_APPLY_ORCO);
|
2013-09-12 10:28:41 +02:00
|
|
|
}
|
2013-09-12 12:41:00 +02:00
|
|
|
else {
|
2013-05-30 19:36:43 +02:00
|
|
|
ndm = modwrap_applyModifier(md, ob, orcodm, MOD_APPLY_ORCO);
|
2013-09-12 10:28:41 +02:00
|
|
|
}
|
2013-09-04 03:29:34 +02:00
|
|
|
ASSERT_IS_VALID_DM(ndm);
|
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-03-24 07:18:31 +01:00
|
|
|
if (ndm) {
|
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 */
|
2012-03-24 07:18:31 +01:00
|
|
|
if (orcodm && orcodm != ndm) orcodm->release(orcodm);
|
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
|
|
|
orcodm = ndm;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2010-10-21 03:08:12 +02:00
|
|
|
DM_set_only_copy(dm, mask | CD_MASK_ORIGINDEX);
|
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (mask & CD_MASK_ORIGSPACE_MLOOP) {
|
|
|
|
if (!CustomData_has_layer(&dm->loopData, CD_ORIGSPACE_MLOOP)) {
|
2012-02-05 12:30:26 +01:00
|
|
|
DM_add_loop_layer(dm, CD_ORIGSPACE_MLOOP, CD_CALLOC, NULL);
|
|
|
|
DM_init_origspace(dm);
|
|
|
|
}
|
|
|
|
}
|
2013-05-30 19:36:43 +02:00
|
|
|
|
2010-05-03 12:09:26 +02:00
|
|
|
if (mti->applyModifierEM)
|
2013-05-30 19:36:43 +02:00
|
|
|
ndm = modwrap_applyModifierEM(md, ob, em, dm, MOD_APPLY_USECACHE);
|
2010-05-03 12:09:26 +02:00
|
|
|
else
|
2013-06-19 17:05:02 +02:00
|
|
|
ndm = modwrap_applyModifier(md, ob, dm, MOD_APPLY_USECACHE);
|
2013-09-04 03:29:34 +02:00
|
|
|
ASSERT_IS_VALID_DM(ndm);
|
2005-08-03 06:04:05 +02:00
|
|
|
|
|
|
|
if (ndm) {
|
2012-03-24 07:18:31 +01:00
|
|
|
if (dm && dm != ndm)
|
2006-08-28 03:12:36 +02:00
|
|
|
dm->release(dm);
|
2005-08-03 06:04:05 +02:00
|
|
|
|
|
|
|
dm = ndm;
|
|
|
|
|
|
|
|
if (deformedVerts) {
|
|
|
|
MEM_freeN(deformedVerts);
|
|
|
|
deformedVerts = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
- 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-07-05 00:24:39 +02:00
|
|
|
/* In case of active preview modifier, make sure preview mask remains for following modifiers. */
|
|
|
|
if ((md == previewmd) && (do_mod_wmcol)) {
|
|
|
|
DM_update_weight_mcol(ob, dm, draw_flag, NULL, 0, NULL);
|
|
|
|
append_mask |= CD_MASK_PREVIEW_MLOOPCOL;
|
|
|
|
}
|
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (cage_r && i == cageIndex) {
|
|
|
|
if (dm && deformedVerts) {
|
2012-01-29 22:59:47 +01:00
|
|
|
*cage_r = CDDM_copy(dm);
|
2006-08-28 03:12:36 +02:00
|
|
|
CDDM_apply_vert_coords(*cage_r, deformedVerts);
|
2012-03-24 07:18:31 +01:00
|
|
|
}
|
|
|
|
else if (dm) {
|
2005-08-03 06:04:05 +02:00
|
|
|
*cage_r = dm;
|
2012-03-24 07:18:31 +01:00
|
|
|
}
|
|
|
|
else {
|
2006-08-28 03:12:36 +02:00
|
|
|
*cage_r =
|
2012-05-12 21:18:02 +02:00
|
|
|
getEditDerivedBMesh(em, ob,
|
|
|
|
deformedVerts ? MEM_dupallocN(deformedVerts) : NULL);
|
- 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.
|
|
|
|
*/
|
2012-03-24 07:18:31 +01:00
|
|
|
if (dm && deformedVerts) {
|
2012-01-29 22:59:47 +01:00
|
|
|
*final_r = CDDM_copy(dm);
|
- 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 (!(cage_r && dm == *cage_r)) dm->release(dm);
|
2006-08-28 03:12:36 +02:00
|
|
|
|
|
|
|
CDDM_apply_vert_coords(*final_r, deformedVerts);
|
2012-02-28 11:22:21 +01:00
|
|
|
}
|
|
|
|
else if (dm) {
|
2012-01-02 07:53:09 +01:00
|
|
|
*final_r = dm;
|
2012-02-28 11:22:21 +01:00
|
|
|
}
|
|
|
|
else if (!deformedVerts && cage_r && *cage_r) {
|
|
|
|
/* cage should already have up to date normals */
|
2012-01-02 07:53:09 +01:00
|
|
|
*final_r = *cage_r;
|
2013-04-13 22:20:21 +02:00
|
|
|
|
|
|
|
/* In this case, we should never have weight-modifying modifiers in stack... */
|
|
|
|
if (do_init_wmcol)
|
|
|
|
DM_update_weight_mcol(ob, *final_r, draw_flag, NULL, 0, NULL);
|
2013-04-17 11:27:23 +02:00
|
|
|
if (do_init_statvis)
|
|
|
|
DM_update_statvis_color(scene, ob, *final_r);
|
2012-02-28 11:22:21 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* this is just a copy of the editmesh, no need to calc normals */
|
2012-01-02 07:53:09 +01:00
|
|
|
*final_r = getEditDerivedBMesh(em, ob, deformedVerts);
|
2007-02-03 15:46:30 +01:00
|
|
|
deformedVerts = NULL;
|
2013-04-13 22:20:21 +02:00
|
|
|
|
|
|
|
/* In this case, we should never have weight-modifying modifiers in stack... */
|
|
|
|
if (do_init_wmcol)
|
|
|
|
DM_update_weight_mcol(ob, *final_r, draw_flag, NULL, 0, NULL);
|
2013-04-17 11:27:23 +02:00
|
|
|
if (do_init_statvis)
|
|
|
|
DM_update_statvis_color(scene, ob, *final_r);
|
- 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
|
|
|
|
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. */
|
|
|
|
if ((*final_r)->type != DM_TYPE_EDITBMESH) {
|
|
|
|
DM_ensure_tessface(*final_r);
|
|
|
|
}
|
2012-09-14 08:17:14 +02:00
|
|
|
if (cage_r && *cage_r) {
|
2012-02-28 11:22:21 +01:00
|
|
|
if ((*cage_r)->type != DM_TYPE_EDITBMESH) {
|
|
|
|
if (*cage_r != *final_r) {
|
|
|
|
DM_ensure_tessface(*cage_r);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-01-20 14:53:47 +01:00
|
|
|
/* --- */
|
2012-01-20 00:34:53 +01:00
|
|
|
|
2013-05-30 19:36:43 +02:00
|
|
|
/* same as mesh_calc_modifiers */
|
|
|
|
dm_ensure_display_normals(*final_r);
|
|
|
|
|
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)
|
2010-03-30 13:49:07 +02:00
|
|
|
add_orco_dm(ob, em, *final_r, orcodm, 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
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (orcodm)
|
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
|
|
|
orcodm->release(orcodm);
|
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (deformedVerts)
|
2007-02-03 15:46:30 +01:00
|
|
|
MEM_freeN(deformedVerts);
|
- 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
|
|
|
}
|
|
|
|
|
2011-04-15 07:20:18 +02:00
|
|
|
static void mesh_build_data(Scene *scene, Object *ob, CustomDataMask dataMask,
|
2012-01-30 02:18:49 +01:00
|
|
|
int build_shapekey_layers)
|
- 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-05-12 21:18:02 +02:00
|
|
|
Object *obact = scene->basact ? scene->basact->object : NULL;
|
2009-09-16 19:43:09 +02:00
|
|
|
int editing = paint_facesel_test(ob);
|
2011-01-18 02:58:19 +01:00
|
|
|
/* weight paint and face select need original indices because of selection buffer drawing */
|
2012-05-12 21:18:02 +02:00
|
|
|
int needMapping = (ob == obact) && (editing || (ob->mode & (OB_MODE_WEIGHT_PAINT | OB_MODE_VERTEX_PAINT | OB_MODE_TEXTURE_PAINT)));
|
2010-02-09 19:06:57 +01:00
|
|
|
|
2012-11-21 01:31:47 +01:00
|
|
|
BLI_assert(ob->type == OB_MESH);
|
|
|
|
|
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
|
|
|
|
2009-05-23 05:24:15 +02:00
|
|
|
mesh_calc_modifiers(scene, ob, NULL, &ob->derivedDeform,
|
2012-05-12 21:18:02 +02:00
|
|
|
&ob->derivedFinal, 0, 1,
|
|
|
|
needMapping, dataMask, -1, 1, build_shapekey_layers);
|
2009-01-02 20:10:35 +01:00
|
|
|
|
2012-05-12 21:18:02 +02:00
|
|
|
DM_set_object_boundbox(ob, ob->derivedFinal);
|
2005-07-19 04:36:21 +02:00
|
|
|
|
2009-01-02 20:10:35 +01:00
|
|
|
ob->derivedFinal->needsFree = 0;
|
|
|
|
ob->derivedDeform->needsFree = 0;
|
|
|
|
ob->lastDataMask = dataMask;
|
2012-03-14 07:30:55 +01:00
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if ((ob->mode & OB_MODE_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) */
|
2012-05-12 21:18:02 +02:00
|
|
|
ob->sculpt->pbvh = ob->derivedFinal->getPBVH(ob, ob->derivedFinal);
|
2012-03-14 07:30:55 +01:00
|
|
|
}
|
2013-05-30 19:36:43 +02:00
|
|
|
|
|
|
|
BLI_assert(!(ob->derivedFinal->dirty & DM_DIRTY_NORMALS));
|
- 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
|
|
|
}
|
|
|
|
|
2009-05-18 10:46:04 +02:00
|
|
|
static void editbmesh_build_data(Scene *scene, 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
|
|
|
|
|
|
|
if (em->derivedFinal) {
|
2012-05-12 21:18:02 +02:00
|
|
|
if (em->derivedFinal != em->derivedCage) {
|
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
|
|
|
em->derivedFinal->needsFree = 1;
|
- 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
|
|
|
em->derivedFinal->release(em->derivedFinal);
|
|
|
|
}
|
|
|
|
em->derivedFinal = NULL;
|
|
|
|
}
|
|
|
|
if (em->derivedCage) {
|
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
|
|
|
em->derivedCage->needsFree = 1;
|
- 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
|
|
|
em->derivedCage->release(em->derivedCage);
|
|
|
|
em->derivedCage = NULL;
|
|
|
|
}
|
|
|
|
|
2009-05-16 18:18:08 +02:00
|
|
|
editbmesh_calc_modifiers(scene, obedit, em, &em->derivedCage, &em->derivedFinal, dataMask);
|
2012-05-12 21:18:02 +02:00
|
|
|
DM_set_object_boundbox(obedit, em->derivedFinal);
|
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;
|
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
|
|
|
em->derivedFinal->needsFree = 0;
|
|
|
|
em->derivedCage->needsFree = 0;
|
2013-05-30 19:36:43 +02:00
|
|
|
|
|
|
|
BLI_assert(!(em->derivedFinal->dirty & DM_DIRTY_NORMALS));
|
2005-07-19 04:36:21 +02:00
|
|
|
}
|
|
|
|
|
2013-05-01 16:34:12 +02:00
|
|
|
static CustomDataMask object_get_datamask(Scene *scene, Object *ob)
|
|
|
|
{
|
|
|
|
Object *actob = scene->basact ? scene->basact->object : NULL;
|
|
|
|
CustomDataMask mask = ob->customdata_mask;
|
|
|
|
|
|
|
|
if (ob == actob) {
|
|
|
|
/* check if we need tfaces & mcols due to face select or texture paint */
|
|
|
|
if (paint_facesel_test(ob) || (ob->mode & OB_MODE_TEXTURE_PAINT)) {
|
|
|
|
mask |= CD_MASK_MTFACE | CD_MASK_MCOL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check if we need mcols due to vertex paint or weightpaint */
|
|
|
|
if (ob->mode & OB_MODE_VERTEX_PAINT) {
|
|
|
|
mask |= CD_MASK_MCOL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ob->mode & OB_MODE_WEIGHT_PAINT) {
|
|
|
|
mask |= CD_MASK_PREVIEW_MCOL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ob->mode & OB_MODE_EDIT)
|
|
|
|
mask |= CD_MASK_MVERT_SKIN;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mask;
|
|
|
|
}
|
|
|
|
|
2011-04-15 07:20:18 +02:00
|
|
|
void makeDerivedMesh(Scene *scene, Object *ob, BMEditMesh *em,
|
2012-01-30 02:18:49 +01:00
|
|
|
CustomDataMask dataMask, int build_shapekey_layers)
|
2005-07-19 04:36:21 +02:00
|
|
|
{
|
2013-05-01 16:34:12 +02:00
|
|
|
dataMask |= object_get_datamask(scene, ob);
|
|
|
|
|
2008-12-31 18:11:42 +01:00
|
|
|
if (em) {
|
2009-05-16 18:18:08 +02:00
|
|
|
editbmesh_build_data(scene, ob, em, dataMask);
|
2012-03-24 07:18:31 +01:00
|
|
|
}
|
|
|
|
else {
|
2011-04-15 07:20:18 +02:00
|
|
|
mesh_build_data(scene, ob, dataMask, build_shapekey_layers);
|
- 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
|
|
|
}
|
|
|
|
|
|
|
|
/***/
|
|
|
|
|
2009-01-04 15:14:06 +01:00
|
|
|
DerivedMesh *mesh_get_derived_final(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
|
|
|
|
*/
|
2013-05-01 16:34:12 +02:00
|
|
|
dataMask |= object_get_datamask(scene, ob);
|
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (!ob->derivedFinal || (dataMask & ob->lastDataMask) != dataMask)
|
2011-04-15 07:20:18 +02:00
|
|
|
mesh_build_data(scene, ob, dataMask, 0);
|
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
|
|
|
}
|
|
|
|
|
2009-01-04 15:14:06 +01:00
|
|
|
DerivedMesh *mesh_get_derived_deform(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
|
|
|
|
*/
|
2013-05-01 16:34:12 +02:00
|
|
|
dataMask |= object_get_datamask(scene, ob);
|
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (!ob->derivedDeform || (dataMask & ob->lastDataMask) != dataMask)
|
2011-04-15 07:20:18 +02:00
|
|
|
mesh_build_data(scene, ob, dataMask, 0);
|
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
|
|
|
}
|
|
|
|
|
2009-01-04 15:14:06 +01:00
|
|
|
DerivedMesh *mesh_create_derived_render(Scene *scene, Object *ob, CustomDataMask dataMask)
|
2007-01-22 00:46:00 +01:00
|
|
|
{
|
|
|
|
DerivedMesh *final;
|
|
|
|
|
2011-04-15 07:20:18 +02:00
|
|
|
mesh_calc_modifiers(scene, ob, NULL, NULL, &final, 1, 1, 0, dataMask, -1, 0, 0);
|
2008-07-28 13:01:34 +02:00
|
|
|
|
|
|
|
return final;
|
|
|
|
}
|
|
|
|
|
2009-01-04 15:14:06 +01:00
|
|
|
DerivedMesh *mesh_create_derived_index_render(Scene *scene, Object *ob, CustomDataMask dataMask, int index)
|
2008-07-28 13:01:34 +02:00
|
|
|
{
|
|
|
|
DerivedMesh *final;
|
|
|
|
|
2011-04-15 07:20:18 +02:00
|
|
|
mesh_calc_modifiers(scene, ob, NULL, NULL, &final, 1, 1, 0, dataMask, index, 0, 0);
|
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
|
|
|
}
|
|
|
|
|
2009-01-04 15:14:06 +01:00
|
|
|
DerivedMesh *mesh_create_derived_view(Scene *scene, 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;
|
|
|
|
|
2011-04-15 07:20:18 +02:00
|
|
|
mesh_calc_modifiers(scene, ob, NULL, NULL, &final, 0, 1, 0, dataMask, -1, 0, 0);
|
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;
|
|
|
|
}
|
|
|
|
|
2009-01-04 15:14:06 +01:00
|
|
|
DerivedMesh *mesh_create_derived_no_deform(Scene *scene, Object *ob, float (*vertCos)[3],
|
2012-05-12 21:18:02 +02:00
|
|
|
CustomDataMask dataMask)
|
2005-07-17 03:18:59 +02:00
|
|
|
{
|
2005-07-19 02:21:01 +02:00
|
|
|
DerivedMesh *final;
|
2007-01-22 00:46:00 +01:00
|
|
|
|
2011-04-15 07:20:18 +02:00
|
|
|
mesh_calc_modifiers(scene, ob, vertCos, NULL, &final, 0, 0, 0, dataMask, -1, 0, 0);
|
2005-07-17 03:18:59 +02:00
|
|
|
|
2005-07-19 02:21:01 +02:00
|
|
|
return final;
|
2005-07-17 03:18:59 +02:00
|
|
|
}
|
|
|
|
|
2009-06-08 22:08:19 +02:00
|
|
|
DerivedMesh *mesh_create_derived_no_virtual(Scene *scene, Object *ob, float (*vertCos)[3],
|
2012-05-12 21:18:02 +02:00
|
|
|
CustomDataMask dataMask)
|
2005-07-17 03:18:59 +02:00
|
|
|
{
|
2005-07-19 02:21:01 +02:00
|
|
|
DerivedMesh *final;
|
2007-01-22 00:46:00 +01:00
|
|
|
|
2011-04-15 07:20:18 +02:00
|
|
|
mesh_calc_modifiers(scene, ob, vertCos, NULL, &final, 0, -1, 0, dataMask, -1, 0, 0);
|
2005-07-17 03:18:59 +02:00
|
|
|
|
2005-07-19 02:21:01 +02:00
|
|
|
return final;
|
2005-07-17 03:18:59 +02:00
|
|
|
}
|
|
|
|
|
2011-01-23 18:17:21 +01:00
|
|
|
DerivedMesh *mesh_create_derived_physics(Scene *scene, Object *ob, float (*vertCos)[3],
|
2012-05-12 21:18:02 +02:00
|
|
|
CustomDataMask dataMask)
|
2011-01-23 18:17:21 +01:00
|
|
|
{
|
|
|
|
DerivedMesh *final;
|
|
|
|
|
2011-04-15 07:20:18 +02:00
|
|
|
mesh_calc_modifiers(scene, ob, vertCos, NULL, &final, 0, -1, 1, dataMask, -1, 0, 0);
|
2011-01-23 18:17:21 +01:00
|
|
|
|
|
|
|
return final;
|
|
|
|
}
|
|
|
|
|
2009-01-04 15:14:06 +01:00
|
|
|
DerivedMesh *mesh_create_derived_no_deform_render(Scene *scene, Object *ob,
|
2012-05-12 21:18:02 +02:00
|
|
|
float (*vertCos)[3],
|
|
|
|
CustomDataMask dataMask)
|
2005-03-28 23:49:49 +02:00
|
|
|
{
|
2005-07-19 02:21:01 +02:00
|
|
|
DerivedMesh *final;
|
2005-03-28 23:49:49 +02:00
|
|
|
|
2011-04-15 07:20:18 +02:00
|
|
|
mesh_calc_modifiers(scene, ob, vertCos, NULL, &final, 1, 0, 0, dataMask, -1, 0, 0);
|
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
|
|
|
/***/
|
|
|
|
|
2009-05-18 10:46:04 +02:00
|
|
|
DerivedMesh *editbmesh_get_derived_cage_and_final(Scene *scene, Object *obedit, BMEditMesh *em, DerivedMesh **final_r,
|
2012-05-12 21:18:02 +02:00
|
|
|
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
|
|
|
|
*/
|
2013-05-01 16:34:12 +02:00
|
|
|
dataMask |= object_get_datamask(scene, obedit);
|
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (!em->derivedCage ||
|
2012-04-28 08:31:57 +02:00
|
|
|
(em->lastDataMask & dataMask) != dataMask)
|
|
|
|
{
|
2009-05-16 18:18:08 +02:00
|
|
|
editbmesh_build_data(scene, obedit, em, dataMask);
|
2012-04-28 08:31:57 +02:00
|
|
|
}
|
2005-03-27 22:34:18 +02:00
|
|
|
|
2008-12-31 18:11:42 +01:00
|
|
|
*final_r = em->derivedFinal;
|
2013-05-30 19:36:43 +02:00
|
|
|
if (em->derivedFinal) { BLI_assert(!(em->derivedFinal->dirty & DM_DIRTY_NORMALS)); }
|
2008-12-31 18:11:42 +01:00
|
|
|
return em->derivedCage;
|
2005-03-27 22:34:18 +02:00
|
|
|
}
|
2005-03-28 07:58:43 +02:00
|
|
|
|
2009-05-18 10:46:04 +02:00
|
|
|
DerivedMesh *editbmesh_get_derived_cage(Scene *scene, Object *obedit, BMEditMesh *em, 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
|
|
|
|
*/
|
2013-05-01 16:34:12 +02:00
|
|
|
dataMask |= object_get_datamask(scene, obedit);
|
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (!em->derivedCage ||
|
2012-04-28 08:31:57 +02:00
|
|
|
(em->lastDataMask & dataMask) != dataMask)
|
|
|
|
{
|
2009-05-16 18:18:08 +02:00
|
|
|
editbmesh_build_data(scene, obedit, em, dataMask);
|
2012-04-28 08:31:57 +02:00
|
|
|
}
|
2005-03-28 07:58:43 +02:00
|
|
|
|
2008-12-31 18:11:42 +01:00
|
|
|
return em->derivedCage;
|
2005-03-28 07:58:43 +02:00
|
|
|
}
|
2005-08-06 22:44:59 +02:00
|
|
|
|
2009-05-18 10:46:04 +02:00
|
|
|
DerivedMesh *editbmesh_get_derived_base(Object *obedit, BMEditMesh *em)
|
2005-08-06 22:44:59 +02:00
|
|
|
{
|
2009-05-16 18:18:08 +02:00
|
|
|
return getEditDerivedBMesh(em, obedit, NULL);
|
2005-08-06 22:44:59 +02:00
|
|
|
}
|
2005-09-18 15:27:12 +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;
|
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;
|
|
|
|
|
2012-05-12 21:18:02 +02:00
|
|
|
dm = mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH | CD_MASK_ORIGINDEX);
|
2005-11-12 11:35:14 +01:00
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (dm->foreachMappedVert) {
|
2013-01-19 03:37:04 +01:00
|
|
|
vertexcosnos = MEM_callocN(sizeof(DMCoNo) * me->totvert, "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 {
|
2013-01-19 03:37:04 +01:00
|
|
|
DMCoNo *v_co_no = vertexcosnos = MEM_mallocN(sizeof(DMCoNo) * me->totvert, "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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
/* ******************* GLSL ******************** */
|
2007-07-28 23:04:30 +02:00
|
|
|
|
2012-05-12 21:18:02 +02:00
|
|
|
typedef struct {
|
|
|
|
float *precomputedFaceNormals;
|
2012-07-07 01:56:59 +02:00
|
|
|
MTFace *mtface; /* texture coordinates */
|
|
|
|
MFace *mface; /* indices */
|
|
|
|
MVert *mvert; /* vertices & normals */
|
2011-02-14 19:18:46 +01:00
|
|
|
float (*orco)[3];
|
2012-07-07 01:56:59 +02:00
|
|
|
float (*tangent)[4]; /* destination */
|
2011-11-30 19:03:56 +01:00
|
|
|
int numTessFaces;
|
2007-07-28 23:04:30 +02:00
|
|
|
|
2011-02-14 19:18:46 +01:00
|
|
|
} SGLSLMeshToTangent;
|
2007-07-28 23:04:30 +02:00
|
|
|
|
2012-07-07 01:56:59 +02:00
|
|
|
/* interface */
|
2011-02-14 19:18:46 +01:00
|
|
|
#include "mikktspace.h"
|
2007-07-28 23:04:30 +02:00
|
|
|
|
2012-05-12 21:18:02 +02:00
|
|
|
static int GetNumFaces(const SMikkTSpaceContext *pContext)
|
2011-02-14 19:18:46 +01:00
|
|
|
{
|
2012-05-12 21:18:02 +02:00
|
|
|
SGLSLMeshToTangent *pMesh = (SGLSLMeshToTangent *) pContext->m_pUserData;
|
2011-11-30 19:03:56 +01:00
|
|
|
return pMesh->numTessFaces;
|
2011-02-14 19:18:46 +01:00
|
|
|
}
|
2007-07-28 23:04:30 +02:00
|
|
|
|
2012-05-12 21:18:02 +02:00
|
|
|
static int GetNumVertsOfFace(const SMikkTSpaceContext *pContext, const int face_num)
|
2011-02-14 19:18:46 +01:00
|
|
|
{
|
2012-05-12 21:18:02 +02:00
|
|
|
SGLSLMeshToTangent *pMesh = (SGLSLMeshToTangent *) pContext->m_pUserData;
|
|
|
|
return pMesh->mface[face_num].v4 != 0 ? 4 : 3;
|
2011-02-14 19:18:46 +01:00
|
|
|
}
|
2007-07-28 23:04:30 +02:00
|
|
|
|
2013-03-26 08:29:01 +01:00
|
|
|
static void GetPosition(const SMikkTSpaceContext *pContext, float r_co[3], const int face_num, const int vert_index)
|
2011-02-14 19:18:46 +01:00
|
|
|
{
|
2012-10-23 05:38:26 +02:00
|
|
|
//assert(vert_index >= 0 && vert_index < 4);
|
2012-05-12 21:18:02 +02:00
|
|
|
SGLSLMeshToTangent *pMesh = (SGLSLMeshToTangent *) pContext->m_pUserData;
|
|
|
|
const float *co = pMesh->mvert[(&pMesh->mface[face_num].v1)[vert_index]].co;
|
2013-03-26 08:29:01 +01:00
|
|
|
copy_v3_v3(r_co, co);
|
2011-02-14 19:18:46 +01:00
|
|
|
}
|
2007-07-28 23:04:30 +02:00
|
|
|
|
2013-03-26 08:29:01 +01:00
|
|
|
static void GetTextureCoordinate(const SMikkTSpaceContext *pContext, float r_uv[2], const int face_num, const int vert_index)
|
2011-02-14 19:18:46 +01:00
|
|
|
{
|
2012-10-23 05:38:26 +02:00
|
|
|
//assert(vert_index >= 0 && vert_index < 4);
|
2012-05-12 21:18:02 +02:00
|
|
|
SGLSLMeshToTangent *pMesh = (SGLSLMeshToTangent *) pContext->m_pUserData;
|
2007-07-28 23:04:30 +02:00
|
|
|
|
2012-05-12 21:18:02 +02:00
|
|
|
if (pMesh->mtface != NULL) {
|
2013-03-26 08:29:01 +01:00
|
|
|
const float *uv = pMesh->mtface[face_num].uv[vert_index];
|
|
|
|
copy_v2_v2(r_uv, uv);
|
2007-07-28 23:04:30 +02:00
|
|
|
}
|
2011-04-14 19:06:55 +02:00
|
|
|
else {
|
2012-05-12 21:18:02 +02:00
|
|
|
const float *orco = pMesh->orco[(&pMesh->mface[face_num].v1)[vert_index]];
|
2013-03-26 08:29:01 +01:00
|
|
|
map_to_sphere(&r_uv[0], &r_uv[1], orco[0], orco[1], orco[2]);
|
2011-02-14 19:18:46 +01:00
|
|
|
}
|
|
|
|
}
|
2007-07-28 23:04:30 +02:00
|
|
|
|
2013-03-26 08:29:01 +01:00
|
|
|
static void GetNormal(const SMikkTSpaceContext *pContext, float r_no[3], const int face_num, const int vert_index)
|
2011-02-14 19:18:46 +01:00
|
|
|
{
|
2012-10-23 05:38:26 +02:00
|
|
|
//assert(vert_index >= 0 && vert_index < 4);
|
2012-05-12 21:18:02 +02:00
|
|
|
SGLSLMeshToTangent *pMesh = (SGLSLMeshToTangent *) pContext->m_pUserData;
|
2007-07-28 23:04:30 +02:00
|
|
|
|
2011-02-14 19:18:46 +01:00
|
|
|
const int smoothnormal = (pMesh->mface[face_num].flag & ME_SMOOTH);
|
2012-05-12 21:18:02 +02:00
|
|
|
if (!smoothnormal) { // flat
|
2012-03-24 07:18:31 +01:00
|
|
|
if (pMesh->precomputedFaceNormals) {
|
2013-03-26 08:29:01 +01:00
|
|
|
copy_v3_v3(r_no, &pMesh->precomputedFaceNormals[3 * face_num]);
|
2011-02-14 19:18:46 +01:00
|
|
|
}
|
2011-04-14 19:06:55 +02:00
|
|
|
else {
|
2012-05-12 21:18:02 +02:00
|
|
|
MFace *mf = &pMesh->mface[face_num];
|
2013-03-26 08:29:01 +01:00
|
|
|
const float *p0 = pMesh->mvert[mf->v1].co;
|
|
|
|
const float *p1 = pMesh->mvert[mf->v2].co;
|
|
|
|
const float *p2 = pMesh->mvert[mf->v3].co;
|
2011-04-14 19:06:55 +02:00
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (mf->v4) {
|
2013-03-26 08:29:01 +01:00
|
|
|
const float *p3 = pMesh->mvert[mf->v4].co;
|
|
|
|
normal_quad_v3(r_no, p0, p1, p2, p3);
|
2011-02-14 19:18:46 +01:00
|
|
|
}
|
|
|
|
else {
|
2013-03-26 08:29:01 +01:00
|
|
|
normal_tri_v3(r_no, p0, p1, p2);
|
2011-02-14 19:18:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-04-14 19:06:55 +02:00
|
|
|
else {
|
2012-05-12 21:18:02 +02:00
|
|
|
const short *no = pMesh->mvert[(&pMesh->mface[face_num].v1)[vert_index]].no;
|
2013-03-26 08:29:01 +01:00
|
|
|
normal_short_to_float_v3(r_no, no);
|
2011-02-14 19:18:46 +01:00
|
|
|
}
|
|
|
|
}
|
2014-01-11 11:31:44 +01:00
|
|
|
|
2013-03-26 08:29:01 +01:00
|
|
|
static void SetTSpace(const SMikkTSpaceContext *pContext, const float fvTangent[3], const float fSign, const int face_num, const int iVert)
|
2011-02-14 19:18:46 +01:00
|
|
|
{
|
2012-10-23 05:38:26 +02:00
|
|
|
//assert(vert_index >= 0 && vert_index < 4);
|
2012-05-12 21:18:02 +02:00
|
|
|
SGLSLMeshToTangent *pMesh = (SGLSLMeshToTangent *) pContext->m_pUserData;
|
|
|
|
float *pRes = pMesh->tangent[4 * face_num + iVert];
|
2011-11-06 16:39:20 +01:00
|
|
|
copy_v3_v3(pRes, fvTangent);
|
2012-05-12 21:18:02 +02:00
|
|
|
pRes[3] = fSign;
|
2007-07-28 23:04:30 +02:00
|
|
|
}
|
2005-11-12 11:35:14 +01:00
|
|
|
|
2008-07-29 17:48:31 +02:00
|
|
|
void DM_add_tangent_layer(DerivedMesh *dm)
|
2005-09-18 15:27:12 +02:00
|
|
|
{
|
2008-07-29 17:48:31 +02:00
|
|
|
/* mesh vars */
|
2012-10-23 16:57:49 +02:00
|
|
|
MVert *mvert;
|
|
|
|
MTFace *mtface;
|
|
|
|
MFace *mface;
|
2012-05-12 21:18:02 +02:00
|
|
|
float (*orco)[3] = NULL, (*tangent)[4];
|
2012-10-23 18:32:39 +02:00
|
|
|
int /* totvert, */ totface;
|
2011-02-14 19:18:46 +01:00
|
|
|
float *nors;
|
2005-09-18 15:27:12 +02:00
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (CustomData_get_layer_index(&dm->faceData, CD_TANGENT) != -1)
|
2005-09-18 15:27:12 +02:00
|
|
|
return;
|
|
|
|
|
2011-02-27 07:19:40 +01:00
|
|
|
nors = dm->getTessFaceDataArray(dm, CD_NORMAL);
|
2011-02-14 19:18:46 +01:00
|
|
|
|
2008-07-29 17:48:31 +02:00
|
|
|
/* check we have all the needed layers */
|
2012-10-23 18:32:39 +02:00
|
|
|
/* totvert = dm->getNumVerts(dm); */ /* UNUSED */
|
2012-05-12 21:18:02 +02:00
|
|
|
totface = dm->getNumTessFaces(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
|
|
|
|
2012-05-12 21:18:02 +02:00
|
|
|
mvert = dm->getVertArray(dm);
|
|
|
|
mface = dm->getTessFaceArray(dm);
|
|
|
|
mtface = dm->getTessFaceDataArray(dm, CD_MTFACE);
|
2005-09-18 15:27:12 +02:00
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (!mtface) {
|
2012-05-12 21:18:02 +02:00
|
|
|
orco = dm->getVertDataArray(dm, CD_ORCO);
|
2012-03-24 07:18:31 +01:00
|
|
|
if (!orco)
|
2008-07-29 17:48:31 +02:00
|
|
|
return;
|
2006-05-11 10:09:02 +02:00
|
|
|
}
|
2008-07-29 17:48:31 +02:00
|
|
|
|
|
|
|
/* create tangent layer */
|
2009-08-15 19:31:28 +02:00
|
|
|
DM_add_tessface_layer(dm, CD_TANGENT, CD_CALLOC, NULL);
|
2012-05-12 21:18:02 +02:00
|
|
|
tangent = DM_get_tessface_data_layer(dm, CD_TANGENT);
|
2008-07-29 17:48:31 +02:00
|
|
|
|
2012-07-07 01:56:59 +02:00
|
|
|
/* new computation method */
|
2012-10-23 16:57:49 +02:00
|
|
|
{
|
2013-08-07 05:55:21 +02:00
|
|
|
SGLSLMeshToTangent mesh2tangent = {NULL};
|
|
|
|
SMikkTSpaceContext sContext = {NULL};
|
|
|
|
SMikkTSpaceInterface sInterface = {NULL};
|
2011-02-14 19:18:46 +01:00
|
|
|
|
|
|
|
mesh2tangent.precomputedFaceNormals = nors;
|
|
|
|
mesh2tangent.mtface = mtface;
|
|
|
|
mesh2tangent.mface = mface;
|
|
|
|
mesh2tangent.mvert = mvert;
|
|
|
|
mesh2tangent.orco = orco;
|
|
|
|
mesh2tangent.tangent = tangent;
|
2011-11-30 19:03:56 +01:00
|
|
|
mesh2tangent.numTessFaces = totface;
|
2011-02-14 19:18:46 +01:00
|
|
|
|
|
|
|
sContext.m_pUserData = &mesh2tangent;
|
|
|
|
sContext.m_pInterface = &sInterface;
|
|
|
|
sInterface.m_getNumFaces = GetNumFaces;
|
|
|
|
sInterface.m_getNumVerticesOfFace = GetNumVertsOfFace;
|
|
|
|
sInterface.m_getPosition = GetPosition;
|
|
|
|
sInterface.m_getTexCoord = GetTextureCoordinate;
|
|
|
|
sInterface.m_getNormal = GetNormal;
|
|
|
|
sInterface.m_setTSpaceBasic = SetTSpace;
|
|
|
|
|
2012-07-07 01:56:59 +02:00
|
|
|
/* 0 if failed */
|
2012-10-23 16:57:49 +02:00
|
|
|
genTangSpaceDefault(&sContext);
|
2011-02-14 19:18:46 +01:00
|
|
|
}
|
Sorry for the big commit, but I've been fixing many of these
issues in parallel... So this commit contains: an update of
the solver (e.g. moving objects), integration of blender IPOs,
improved rendering (motion blur, smoothed normals) and a first particle
test. In more detail:
Solver update:
- Moving objects using a relatively simple model, and not yet fully optimized - ok
for box falling into water, water in a moving glass might cause trouble. Simulation
times are influenced by overall no. of triangles of the mesh, scaling meshes up a lot
might also cause slowdowns.
- Additional obstacle settings: noslip (as before), free slip (move along wall freely)
and part slip (mix of both).
- Obstacle settings also added for domain boundaries now, the six walls of the domain are
obstacles after all as well
- Got rid of templates, should make compiling for e.g. macs more convenient,
for linux there's not much difference. Finally got rid of parser (and some other code
parts), the simulation now uses the internal API to transfer data.
- Some unnecessary file were removed, the GUI now needs 3 settings buttons...
This should still be changed (maybe by adding a new panel for domain objects).
IPOs:
- Animated params: viscosity, time and gravity for domains. In contrast
to normal time IPO for Blender objects, the fluidsim one scales the time
step size - so a constant 1 has no effect, values towards 0 slow it down,
larger ones speed the simulation up (-> longer time steps, more compuations).
The viscosity IPO is also only a factor for the selected viscosity (again, 1=no effect).
- For objects that are enabled for fluidsim, a new IPO type shows up. Inflow
objects can use the velocity channels to animate the inflow. Obstacles, in/outflow
objects can be switched on (Active IPO>0) and off (<0) during the simulation.
- Movement, rotation and scaling of those 3 types is exported from the normal
Blender channels (Loc,dLoc,etc.).
Particles:
- This is still experimental, so it might be deactivated for a
release... It should at some point be used to model smaller splashes,
depending on the the realworld size and the particle generation
settings particles are generated during simulation (stored in _particles_X.gz
files).
- These are loaded by enabling the particle field for an arbitrary object,
which should be given a halo material. For each frame, similar to the mesh
loading, the particle system them loads the simulated particle positions.
- For rendering, I "abused" the part->rt field - I couldnt find any use
for it in the code and it seems to work fine. The fluidsim particles
store their size there.
Rendering:
- The fluidims particles use scaled sizes and alpha values to give a more varied
appearance. In convertblender.c fluidsim particle systems use the p->rt field
to scale up the size and down the alpha of "smaller particles". Setting the
influence fields in the fluidims settings to 0 gives equally sized particles
with same alpha everywhere. Higher values cause larger differences.
- Smoothed normals: for unmodified fluid meshes (e.g. no subdivision) the normals
computed by the solver are used. This is basically done by switching off the
normal recalculation in convertblender.c (the function calc_fluidsimnormals
handles other mesh inits instead of calc_vertexnormals).
This could also be used to e.g. modify mesh normals in a modifier...
- Another change is that fluidsim meshes load the velocities computed
during the simulation for image based motion blur. This is inited in
load_fluidsimspeedvectors for the vector pass (they're loaded during the
normal load in DerivedMesh readBobjgz). Generation and loading can be switched
off in the settings. Vector pass currently loads the fluidism meshes 3 times,
so this should still be optimized.
Examples:
- smoothed normals versus normals from subdividing once:
http://www10.informatik.uni-erlangen.de/~sinithue/temp/v060227_1smoothnorms.png
http://www10.informatik.uni-erlangen.de/~sinithue/temp/v060227_2subdivnorms.png
- fluidsim particles, size/alpha influence 0:
http://www10.informatik.uni-erlangen.de/~sinithue/temp/v060227_3particlesnorm.png
size influence 1:
http://www10.informatik.uni-erlangen.de/~sinithue/temp/v060227_4particlessize.png
size & alpha influence 1:
http://www10.informatik.uni-erlangen.de/~sinithue/temp/v060227_5particlesalpha.png
- the standard drop with motion blur and particles:
http://www10.informatik.uni-erlangen.de/~sinithue/temp/elbeemupdate_t2new.mpg
(here's how it looks without
http://www10.informatik.uni-erlangen.de/~sinithue/temp/elbeemupdate_t1old.mpg)
- another inflow animation (moving, switched on/off) with a moving obstacle
(and strong mblur :)
http://www10.informatik.uni-erlangen.de/~sinithue/temp/elbeemupdate_t3ipos.mpg
Things still to fix:
- rotating & scaling domains causes wrong speed vectors
- get rid of SDL code for threading, use pthreads as well?
- update wiki documentation
- cool effects for rendering would be photon maps for caustics,
and motion blur for particles :)
2006-02-27 12:45:42 +01:00
|
|
|
}
|
|
|
|
|
2011-12-10 00:26:06 +01:00
|
|
|
void DM_calc_auto_bump_scale(DerivedMesh *dm)
|
|
|
|
{
|
2012-10-26 06:14:10 +02:00
|
|
|
/* int totvert = dm->getNumVerts(dm); */ /* UNUSED */
|
2012-05-12 21:18:02 +02:00
|
|
|
int totface = dm->getNumTessFaces(dm);
|
2011-12-10 00:26:06 +01:00
|
|
|
|
2012-05-12 21:18:02 +02:00
|
|
|
MVert *mvert = dm->getVertArray(dm);
|
|
|
|
MFace *mface = dm->getTessFaceArray(dm);
|
|
|
|
MTFace *mtface = dm->getTessFaceDataArray(dm, CD_MTFACE);
|
2011-12-10 00:26:06 +01:00
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (mtface) {
|
2011-12-10 00:26:06 +01:00
|
|
|
double dsum = 0.0;
|
|
|
|
int nr_accumulated = 0;
|
|
|
|
int f;
|
|
|
|
|
2012-05-12 21:18:02 +02:00
|
|
|
for (f = 0; f < totface; f++) {
|
2011-12-10 00:26:06 +01:00
|
|
|
{
|
2012-05-12 21:18:02 +02:00
|
|
|
float *verts[4], *tex_coords[4];
|
|
|
|
const int nr_verts = mface[f].v4 != 0 ? 4 : 3;
|
2011-12-10 00:26:06 +01:00
|
|
|
int i, is_degenerate;
|
|
|
|
|
2012-05-12 21:18:02 +02:00
|
|
|
verts[0] = mvert[mface[f].v1].co; verts[1] = mvert[mface[f].v2].co; verts[2] = mvert[mface[f].v3].co;
|
|
|
|
tex_coords[0] = mtface[f].uv[0]; tex_coords[1] = mtface[f].uv[1]; tex_coords[2] = mtface[f].uv[2];
|
|
|
|
if (nr_verts == 4) {
|
|
|
|
verts[3] = mvert[mface[f].v4].co;
|
|
|
|
tex_coords[3] = mtface[f].uv[3];
|
2011-12-10 00:26:06 +01:00
|
|
|
}
|
|
|
|
|
2012-07-07 01:56:59 +02:00
|
|
|
/* discard degenerate faces */
|
2011-12-10 00:26:06 +01:00
|
|
|
is_degenerate = 0;
|
2012-05-12 21:18:02 +02:00
|
|
|
if (equals_v3v3(verts[0], verts[1]) || equals_v3v3(verts[0], verts[2]) || equals_v3v3(verts[1], verts[2]) ||
|
|
|
|
equals_v2v2(tex_coords[0], tex_coords[1]) || equals_v2v2(tex_coords[0], tex_coords[2]) || equals_v2v2(tex_coords[1], tex_coords[2]))
|
2011-12-10 00:26:06 +01:00
|
|
|
{
|
|
|
|
is_degenerate = 1;
|
|
|
|
}
|
|
|
|
|
2012-07-07 01:56:59 +02:00
|
|
|
/* verify last vertex as well if this is a quad */
|
2012-03-06 19:40:15 +01:00
|
|
|
if (is_degenerate == 0 && nr_verts == 4) {
|
|
|
|
if (equals_v3v3(verts[3], verts[0]) || equals_v3v3(verts[3], verts[1]) || equals_v3v3(verts[3], verts[2]) ||
|
2012-04-29 19:11:40 +02:00
|
|
|
equals_v2v2(tex_coords[3], tex_coords[0]) || equals_v2v2(tex_coords[3], tex_coords[1]) || equals_v2v2(tex_coords[3], tex_coords[2]))
|
2011-12-10 00:26:06 +01:00
|
|
|
{
|
|
|
|
is_degenerate = 1;
|
|
|
|
}
|
|
|
|
|
2012-07-07 01:56:59 +02:00
|
|
|
/* verify the winding is consistent */
|
2012-03-06 19:40:15 +01:00
|
|
|
if (is_degenerate == 0) {
|
2011-12-10 00:26:06 +01:00
|
|
|
float prev_edge[2];
|
|
|
|
int is_signed = 0;
|
|
|
|
sub_v2_v2v2(prev_edge, tex_coords[0], tex_coords[3]);
|
|
|
|
|
|
|
|
i = 0;
|
2012-03-06 19:40:15 +01:00
|
|
|
while (is_degenerate == 0 && i < 4) {
|
2011-12-10 00:26:06 +01:00
|
|
|
float cur_edge[2], signed_area;
|
2012-05-12 21:18:02 +02:00
|
|
|
sub_v2_v2v2(cur_edge, tex_coords[(i + 1) & 0x3], tex_coords[i]);
|
|
|
|
signed_area = prev_edge[0] * cur_edge[1] - prev_edge[1] * cur_edge[0];
|
2011-12-10 00:26:06 +01:00
|
|
|
|
2012-05-12 21:18:02 +02:00
|
|
|
if (i == 0) {
|
2012-03-06 19:40:15 +01:00
|
|
|
is_signed = (signed_area < 0.0f) ? 1 : 0;
|
|
|
|
}
|
2012-03-24 07:18:31 +01:00
|
|
|
else if ((is_signed != 0) != (signed_area < 0.0f)) {
|
2012-03-06 19:40:15 +01:00
|
|
|
is_degenerate = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_degenerate == 0) {
|
2011-12-10 00:26:06 +01:00
|
|
|
copy_v2_v2(prev_edge, cur_edge);
|
2012-05-09 11:24:15 +02:00
|
|
|
i++;
|
2011-12-10 00:26:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-07 01:56:59 +02:00
|
|
|
/* proceed if not a degenerate face */
|
2012-03-06 19:40:15 +01:00
|
|
|
if (is_degenerate == 0) {
|
2012-05-12 21:18:02 +02:00
|
|
|
int nr_tris_to_pile = 0;
|
2012-07-07 01:56:59 +02:00
|
|
|
/* quads split at shortest diagonal */
|
|
|
|
int offs = 0; /* initial triangulation is 0,1,2 and 0, 2, 3 */
|
2012-03-06 19:40:15 +01:00
|
|
|
if (nr_verts == 4) {
|
2011-12-10 00:26:06 +01:00
|
|
|
float pos_len_diag0, pos_len_diag1;
|
2013-09-04 00:22:45 +02:00
|
|
|
|
|
|
|
pos_len_diag0 = len_squared_v3v3(verts[2], verts[0]);
|
|
|
|
pos_len_diag1 = len_squared_v3v3(verts[3], verts[1]);
|
2011-12-10 00:26:06 +01:00
|
|
|
|
2012-05-12 21:18:02 +02:00
|
|
|
if (pos_len_diag1 < pos_len_diag0) {
|
|
|
|
offs = 1; // alter split
|
2012-03-06 19:40:15 +01:00
|
|
|
}
|
2012-05-12 21:18:02 +02:00
|
|
|
else if (pos_len_diag0 == pos_len_diag1) { /* do UV check instead */
|
2011-12-10 00:26:06 +01:00
|
|
|
float tex_len_diag0, tex_len_diag1;
|
|
|
|
|
2013-09-04 00:22:45 +02:00
|
|
|
tex_len_diag0 = len_squared_v2v2(tex_coords[2], tex_coords[0]);
|
|
|
|
tex_len_diag1 = len_squared_v2v2(tex_coords[3], tex_coords[1]);
|
2011-12-10 00:26:06 +01:00
|
|
|
|
2012-05-12 21:18:02 +02:00
|
|
|
if (tex_len_diag1 < tex_len_diag0) {
|
|
|
|
offs = 1; /* alter split */
|
2011-12-10 00:26:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-02-27 11:35:39 +01:00
|
|
|
nr_tris_to_pile = nr_verts - 2;
|
2012-05-12 21:18:02 +02:00
|
|
|
if (nr_tris_to_pile == 1 || nr_tris_to_pile == 2) {
|
2013-09-04 00:22:45 +02:00
|
|
|
const int indices[6] = {offs + 0, offs + 1, offs + 2, offs + 0, offs + 2, (offs + 3) & 0x3 };
|
2011-12-10 00:26:06 +01:00
|
|
|
int t;
|
2012-05-12 21:18:02 +02:00
|
|
|
for (t = 0; t < nr_tris_to_pile; t++) {
|
2011-12-10 00:26:06 +01:00
|
|
|
float f2x_area_uv;
|
2012-05-12 21:18:02 +02:00
|
|
|
float *p0 = verts[indices[t * 3 + 0]];
|
|
|
|
float *p1 = verts[indices[t * 3 + 1]];
|
|
|
|
float *p2 = verts[indices[t * 3 + 2]];
|
2011-12-10 00:26:06 +01:00
|
|
|
|
|
|
|
float edge_t0[2], edge_t1[2];
|
2012-05-12 21:18:02 +02:00
|
|
|
sub_v2_v2v2(edge_t0, tex_coords[indices[t * 3 + 1]], tex_coords[indices[t * 3 + 0]]);
|
|
|
|
sub_v2_v2v2(edge_t1, tex_coords[indices[t * 3 + 2]], tex_coords[indices[t * 3 + 0]]);
|
2011-12-10 00:26:06 +01:00
|
|
|
|
2012-05-12 21:18:02 +02:00
|
|
|
f2x_area_uv = fabsf(edge_t0[0] * edge_t1[1] - edge_t0[1] * edge_t1[0]);
|
|
|
|
if (f2x_area_uv > FLT_EPSILON) {
|
2011-12-10 00:26:06 +01:00
|
|
|
float norm[3], v0[3], v1[3], f2x_surf_area, fsurf_ratio;
|
|
|
|
sub_v3_v3v3(v0, p1, p0);
|
|
|
|
sub_v3_v3v3(v1, p2, p0);
|
|
|
|
cross_v3_v3v3(norm, v0, v1);
|
|
|
|
|
|
|
|
f2x_surf_area = len_v3(norm);
|
2013-09-04 00:22:45 +02:00
|
|
|
fsurf_ratio = f2x_surf_area / f2x_area_uv; /* tri area divided by texture area */
|
2011-12-10 00:26:06 +01:00
|
|
|
|
2012-05-09 11:24:15 +02:00
|
|
|
nr_accumulated++;
|
2011-12-10 00:26:06 +01:00
|
|
|
dsum += (double)(fsurf_ratio);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-07 01:56:59 +02:00
|
|
|
/* finalize */
|
2011-12-10 00:26:06 +01:00
|
|
|
{
|
2012-05-12 21:18:02 +02:00
|
|
|
const float avg_area_ratio = (nr_accumulated > 0) ? ((float)(dsum / nr_accumulated)) : 1.0f;
|
|
|
|
const float use_as_render_bump_scale = sqrtf(avg_area_ratio); // use width of average surface ratio as your bump scale
|
2011-12-10 00:26:06 +01:00
|
|
|
dm->auto_bump_scale = use_as_render_bump_scale;
|
|
|
|
}
|
|
|
|
}
|
2012-03-06 19:40:15 +01:00
|
|
|
else {
|
2011-12-10 00:26:06 +01:00
|
|
|
dm->auto_bump_scale = 1.0f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
void DM_vertex_attributes_from_gpu(DerivedMesh *dm, GPUVertexAttribs *gattribs, DMVertexAttribs *attribs)
|
2005-11-12 11:35:14 +01: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
|
|
|
CustomData *vdata, *fdata, *tfdata = NULL;
|
|
|
|
int a, b, layer;
|
2005-11-09 08:56:26 +01: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
|
|
|
/* From the layers requested by the GLSL shader, figure out which ones are
|
|
|
|
* actually available for this derivedmesh, and retrieve the pointers */
|
2005-11-23 13:49:22 +01: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
|
|
|
memset(attribs, 0, sizeof(DMVertexAttribs));
|
2005-11-23 13:49:22 +01: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
|
|
|
vdata = &dm->vertData;
|
2010-09-04 07:31:25 +02:00
|
|
|
fdata = tfdata = dm->getTessFaceDataLayout(dm);
|
|
|
|
|
2011-12-10 00:26:06 +01:00
|
|
|
/* calc auto bump scale if necessary */
|
2012-04-17 13:02:32 +02:00
|
|
|
if (dm->auto_bump_scale <= 0.0f)
|
2011-12-10 00:26:06 +01:00
|
|
|
DM_calc_auto_bump_scale(dm);
|
|
|
|
|
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 a tangent layer if necessary */
|
2012-03-24 07:18:31 +01:00
|
|
|
for (b = 0; b < gattribs->totlayer; b++)
|
|
|
|
if (gattribs->layer[b].type == CD_TANGENT)
|
|
|
|
if (CustomData_get_layer_index(fdata, CD_TANGENT) == -1)
|
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
|
|
|
DM_add_tangent_layer(dm);
|
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
for (b = 0; b < gattribs->totlayer; b++) {
|
|
|
|
if (gattribs->layer[b].type == CD_MTFACE) {
|
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
|
|
|
/* uv coordinates */
|
2012-04-21 14:51:47 +02:00
|
|
|
if (dm->type == DM_TYPE_EDITBMESH) {
|
2012-04-17 13:02:32 +02:00
|
|
|
/* exception .. */
|
|
|
|
CustomData *ldata = dm->getLoopDataLayout(dm);
|
2005-11-09 08:56:26 +01:00
|
|
|
|
2012-04-17 13:02:32 +02:00
|
|
|
if (gattribs->layer[b].name[0])
|
|
|
|
layer = CustomData_get_named_layer_index(ldata, CD_MLOOPUV,
|
2012-05-12 21:18:02 +02:00
|
|
|
gattribs->layer[b].name);
|
2012-04-17 13:02:32 +02:00
|
|
|
else
|
|
|
|
layer = CustomData_get_active_layer_index(ldata, CD_MLOOPUV);
|
|
|
|
|
2013-10-17 16:04:10 +02:00
|
|
|
a = attribs->tottface++;
|
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
|
|
|
|
2013-10-17 16:04:10 +02:00
|
|
|
if (layer != -1) {
|
2012-04-17 13:02:32 +02:00
|
|
|
attribs->tface[a].array = tfdata->layers[layer].data;
|
2013-02-23 07:56:10 +01:00
|
|
|
attribs->tface[a].em_offset = ldata->layers[layer].offset;
|
2012-04-17 13:02:32 +02:00
|
|
|
}
|
2013-10-17 16:04:10 +02:00
|
|
|
else {
|
|
|
|
attribs->tface[a].array = NULL;
|
|
|
|
attribs->tface[a].em_offset = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
attribs->tface[a].gl_index = gattribs->layer[b].glindex;
|
|
|
|
attribs->tface[a].gl_texco = gattribs->layer[b].gltexco;
|
2011-12-05 00:13:28 +01:00
|
|
|
}
|
2012-03-09 19:28:30 +01:00
|
|
|
else {
|
2012-03-24 07:18:31 +01:00
|
|
|
if (gattribs->layer[b].name[0])
|
2012-04-17 13:02:32 +02:00
|
|
|
layer = CustomData_get_named_layer_index(tfdata, CD_MTFACE,
|
2012-05-12 21:18:02 +02:00
|
|
|
gattribs->layer[b].name);
|
2011-05-10 19:01:26 +02:00
|
|
|
else
|
2012-04-17 13:02:32 +02:00
|
|
|
layer = CustomData_get_active_layer_index(tfdata, CD_MTFACE);
|
|
|
|
|
2013-10-17 16:04:10 +02:00
|
|
|
a = attribs->tottface++;
|
2012-04-17 13:02:32 +02:00
|
|
|
|
2013-10-17 16:04:10 +02:00
|
|
|
if (layer != -1) {
|
2012-04-17 13:02:32 +02:00
|
|
|
attribs->tface[a].array = tfdata->layers[layer].data;
|
2012-05-04 13:50:11 +02:00
|
|
|
attribs->tface[a].em_offset = tfdata->layers[layer].offset;
|
2011-05-10 19:01:26 +02:00
|
|
|
}
|
2013-10-17 16:04:10 +02:00
|
|
|
else {
|
|
|
|
attribs->tface[a].array = NULL;
|
|
|
|
attribs->tface[a].em_offset = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
attribs->tface[a].gl_index = gattribs->layer[b].glindex;
|
|
|
|
attribs->tface[a].gl_texco = gattribs->layer[b].gltexco;
|
2011-12-05 00:13:28 +01:00
|
|
|
}
|
2006-03-29 09:35:54 +02:00
|
|
|
}
|
2012-03-24 07:18:31 +01:00
|
|
|
else if (gattribs->layer[b].type == CD_MCOL) {
|
2012-04-21 14:51:47 +02:00
|
|
|
if (dm->type == DM_TYPE_EDITBMESH) {
|
2012-04-17 13:02:32 +02:00
|
|
|
/* exception .. */
|
|
|
|
CustomData *ldata = dm->getLoopDataLayout(dm);
|
2005-11-09 08:56:26 +01:00
|
|
|
|
2012-04-17 13:02:32 +02:00
|
|
|
if (gattribs->layer[b].name[0])
|
|
|
|
layer = CustomData_get_named_layer_index(ldata, CD_MLOOPCOL,
|
2012-05-12 21:18:02 +02:00
|
|
|
gattribs->layer[b].name);
|
2012-04-17 13:02:32 +02:00
|
|
|
else
|
|
|
|
layer = CustomData_get_active_layer_index(ldata, CD_MLOOPCOL);
|
|
|
|
|
2013-10-17 16:04:10 +02:00
|
|
|
a = attribs->totmcol++;
|
Sorry for the big commit, but I've been fixing many of these
issues in parallel... So this commit contains: an update of
the solver (e.g. moving objects), integration of blender IPOs,
improved rendering (motion blur, smoothed normals) and a first particle
test. In more detail:
Solver update:
- Moving objects using a relatively simple model, and not yet fully optimized - ok
for box falling into water, water in a moving glass might cause trouble. Simulation
times are influenced by overall no. of triangles of the mesh, scaling meshes up a lot
might also cause slowdowns.
- Additional obstacle settings: noslip (as before), free slip (move along wall freely)
and part slip (mix of both).
- Obstacle settings also added for domain boundaries now, the six walls of the domain are
obstacles after all as well
- Got rid of templates, should make compiling for e.g. macs more convenient,
for linux there's not much difference. Finally got rid of parser (and some other code
parts), the simulation now uses the internal API to transfer data.
- Some unnecessary file were removed, the GUI now needs 3 settings buttons...
This should still be changed (maybe by adding a new panel for domain objects).
IPOs:
- Animated params: viscosity, time and gravity for domains. In contrast
to normal time IPO for Blender objects, the fluidsim one scales the time
step size - so a constant 1 has no effect, values towards 0 slow it down,
larger ones speed the simulation up (-> longer time steps, more compuations).
The viscosity IPO is also only a factor for the selected viscosity (again, 1=no effect).
- For objects that are enabled for fluidsim, a new IPO type shows up. Inflow
objects can use the velocity channels to animate the inflow. Obstacles, in/outflow
objects can be switched on (Active IPO>0) and off (<0) during the simulation.
- Movement, rotation and scaling of those 3 types is exported from the normal
Blender channels (Loc,dLoc,etc.).
Particles:
- This is still experimental, so it might be deactivated for a
release... It should at some point be used to model smaller splashes,
depending on the the realworld size and the particle generation
settings particles are generated during simulation (stored in _particles_X.gz
files).
- These are loaded by enabling the particle field for an arbitrary object,
which should be given a halo material. For each frame, similar to the mesh
loading, the particle system them loads the simulated particle positions.
- For rendering, I "abused" the part->rt field - I couldnt find any use
for it in the code and it seems to work fine. The fluidsim particles
store their size there.
Rendering:
- The fluidims particles use scaled sizes and alpha values to give a more varied
appearance. In convertblender.c fluidsim particle systems use the p->rt field
to scale up the size and down the alpha of "smaller particles". Setting the
influence fields in the fluidims settings to 0 gives equally sized particles
with same alpha everywhere. Higher values cause larger differences.
- Smoothed normals: for unmodified fluid meshes (e.g. no subdivision) the normals
computed by the solver are used. This is basically done by switching off the
normal recalculation in convertblender.c (the function calc_fluidsimnormals
handles other mesh inits instead of calc_vertexnormals).
This could also be used to e.g. modify mesh normals in a modifier...
- Another change is that fluidsim meshes load the velocities computed
during the simulation for image based motion blur. This is inited in
load_fluidsimspeedvectors for the vector pass (they're loaded during the
normal load in DerivedMesh readBobjgz). Generation and loading can be switched
off in the settings. Vector pass currently loads the fluidism meshes 3 times,
so this should still be optimized.
Examples:
- smoothed normals versus normals from subdividing once:
http://www10.informatik.uni-erlangen.de/~sinithue/temp/v060227_1smoothnorms.png
http://www10.informatik.uni-erlangen.de/~sinithue/temp/v060227_2subdivnorms.png
- fluidsim particles, size/alpha influence 0:
http://www10.informatik.uni-erlangen.de/~sinithue/temp/v060227_3particlesnorm.png
size influence 1:
http://www10.informatik.uni-erlangen.de/~sinithue/temp/v060227_4particlessize.png
size & alpha influence 1:
http://www10.informatik.uni-erlangen.de/~sinithue/temp/v060227_5particlesalpha.png
- the standard drop with motion blur and particles:
http://www10.informatik.uni-erlangen.de/~sinithue/temp/elbeemupdate_t2new.mpg
(here's how it looks without
http://www10.informatik.uni-erlangen.de/~sinithue/temp/elbeemupdate_t1old.mpg)
- another inflow animation (moving, switched on/off) with a moving obstacle
(and strong mblur :)
http://www10.informatik.uni-erlangen.de/~sinithue/temp/elbeemupdate_t3ipos.mpg
Things still to fix:
- rotating & scaling domains causes wrong speed vectors
- get rid of SDL code for threading, use pthreads as well?
- update wiki documentation
- cool effects for rendering would be photon maps for caustics,
and motion blur for particles :)
2006-02-27 12:45:42 +01:00
|
|
|
|
2013-10-17 16:04:10 +02:00
|
|
|
if (layer != -1) {
|
2012-04-17 13:02:32 +02:00
|
|
|
attribs->mcol[a].array = tfdata->layers[layer].data;
|
2013-02-23 07:56:10 +01:00
|
|
|
/* odd, store the offset for a different layer type here, but editmode draw code expects it */
|
|
|
|
attribs->mcol[a].em_offset = ldata->layers[layer].offset;
|
2012-04-17 13:02:32 +02:00
|
|
|
}
|
2013-10-17 16:04:10 +02:00
|
|
|
else {
|
|
|
|
attribs->mcol[a].array = NULL;
|
|
|
|
attribs->mcol[a].em_offset = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
attribs->mcol[a].gl_index = gattribs->layer[b].glindex;
|
2012-04-17 13:02:32 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* vertex colors */
|
|
|
|
if (gattribs->layer[b].name[0])
|
|
|
|
layer = CustomData_get_named_layer_index(tfdata, CD_MCOL,
|
2012-05-12 21:18:02 +02:00
|
|
|
gattribs->layer[b].name);
|
2012-04-17 13:02:32 +02:00
|
|
|
else
|
|
|
|
layer = CustomData_get_active_layer_index(tfdata, CD_MCOL);
|
|
|
|
|
2013-10-17 16:04:10 +02:00
|
|
|
a = attribs->totmcol++;
|
2012-04-17 13:02:32 +02:00
|
|
|
|
2013-10-17 16:04:10 +02:00
|
|
|
if (layer != -1) {
|
2012-04-17 13:02:32 +02:00
|
|
|
attribs->mcol[a].array = tfdata->layers[layer].data;
|
2013-02-23 07:56:10 +01:00
|
|
|
/* odd, store the offset for a different layer type here, but editmode draw code expects it */
|
2012-05-04 13:50:11 +02:00
|
|
|
attribs->mcol[a].em_offset = tfdata->layers[layer].offset;
|
2012-04-17 13:02:32 +02:00
|
|
|
}
|
2013-10-17 16:04:10 +02:00
|
|
|
else {
|
|
|
|
attribs->mcol[a].array = NULL;
|
|
|
|
attribs->mcol[a].em_offset = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
attribs->mcol[a].gl_index = gattribs->layer[b].glindex;
|
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-03-24 07:18:31 +01:00
|
|
|
else if (gattribs->layer[b].type == CD_TANGENT) {
|
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
|
|
|
/* tangents */
|
|
|
|
layer = CustomData_get_layer_index(fdata, CD_TANGENT);
|
Sorry for the big commit, but I've been fixing many of these
issues in parallel... So this commit contains: an update of
the solver (e.g. moving objects), integration of blender IPOs,
improved rendering (motion blur, smoothed normals) and a first particle
test. In more detail:
Solver update:
- Moving objects using a relatively simple model, and not yet fully optimized - ok
for box falling into water, water in a moving glass might cause trouble. Simulation
times are influenced by overall no. of triangles of the mesh, scaling meshes up a lot
might also cause slowdowns.
- Additional obstacle settings: noslip (as before), free slip (move along wall freely)
and part slip (mix of both).
- Obstacle settings also added for domain boundaries now, the six walls of the domain are
obstacles after all as well
- Got rid of templates, should make compiling for e.g. macs more convenient,
for linux there's not much difference. Finally got rid of parser (and some other code
parts), the simulation now uses the internal API to transfer data.
- Some unnecessary file were removed, the GUI now needs 3 settings buttons...
This should still be changed (maybe by adding a new panel for domain objects).
IPOs:
- Animated params: viscosity, time and gravity for domains. In contrast
to normal time IPO for Blender objects, the fluidsim one scales the time
step size - so a constant 1 has no effect, values towards 0 slow it down,
larger ones speed the simulation up (-> longer time steps, more compuations).
The viscosity IPO is also only a factor for the selected viscosity (again, 1=no effect).
- For objects that are enabled for fluidsim, a new IPO type shows up. Inflow
objects can use the velocity channels to animate the inflow. Obstacles, in/outflow
objects can be switched on (Active IPO>0) and off (<0) during the simulation.
- Movement, rotation and scaling of those 3 types is exported from the normal
Blender channels (Loc,dLoc,etc.).
Particles:
- This is still experimental, so it might be deactivated for a
release... It should at some point be used to model smaller splashes,
depending on the the realworld size and the particle generation
settings particles are generated during simulation (stored in _particles_X.gz
files).
- These are loaded by enabling the particle field for an arbitrary object,
which should be given a halo material. For each frame, similar to the mesh
loading, the particle system them loads the simulated particle positions.
- For rendering, I "abused" the part->rt field - I couldnt find any use
for it in the code and it seems to work fine. The fluidsim particles
store their size there.
Rendering:
- The fluidims particles use scaled sizes and alpha values to give a more varied
appearance. In convertblender.c fluidsim particle systems use the p->rt field
to scale up the size and down the alpha of "smaller particles". Setting the
influence fields in the fluidims settings to 0 gives equally sized particles
with same alpha everywhere. Higher values cause larger differences.
- Smoothed normals: for unmodified fluid meshes (e.g. no subdivision) the normals
computed by the solver are used. This is basically done by switching off the
normal recalculation in convertblender.c (the function calc_fluidsimnormals
handles other mesh inits instead of calc_vertexnormals).
This could also be used to e.g. modify mesh normals in a modifier...
- Another change is that fluidsim meshes load the velocities computed
during the simulation for image based motion blur. This is inited in
load_fluidsimspeedvectors for the vector pass (they're loaded during the
normal load in DerivedMesh readBobjgz). Generation and loading can be switched
off in the settings. Vector pass currently loads the fluidism meshes 3 times,
so this should still be optimized.
Examples:
- smoothed normals versus normals from subdividing once:
http://www10.informatik.uni-erlangen.de/~sinithue/temp/v060227_1smoothnorms.png
http://www10.informatik.uni-erlangen.de/~sinithue/temp/v060227_2subdivnorms.png
- fluidsim particles, size/alpha influence 0:
http://www10.informatik.uni-erlangen.de/~sinithue/temp/v060227_3particlesnorm.png
size influence 1:
http://www10.informatik.uni-erlangen.de/~sinithue/temp/v060227_4particlessize.png
size & alpha influence 1:
http://www10.informatik.uni-erlangen.de/~sinithue/temp/v060227_5particlesalpha.png
- the standard drop with motion blur and particles:
http://www10.informatik.uni-erlangen.de/~sinithue/temp/elbeemupdate_t2new.mpg
(here's how it looks without
http://www10.informatik.uni-erlangen.de/~sinithue/temp/elbeemupdate_t1old.mpg)
- another inflow animation (moving, switched on/off) with a moving obstacle
(and strong mblur :)
http://www10.informatik.uni-erlangen.de/~sinithue/temp/elbeemupdate_t3ipos.mpg
Things still to fix:
- rotating & scaling domains causes wrong speed vectors
- get rid of SDL code for threading, use pthreads as well?
- update wiki documentation
- cool effects for rendering would be photon maps for caustics,
and motion blur for particles :)
2006-02-27 12:45:42 +01:00
|
|
|
|
2013-10-17 16:04:10 +02:00
|
|
|
attribs->tottang = 1;
|
2005-11-23 13:49:22 +01:00
|
|
|
|
2013-10-17 16:04:10 +02:00
|
|
|
if (layer != -1) {
|
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
|
|
|
attribs->tang.array = fdata->layers[layer].data;
|
2012-05-04 13:50:11 +02:00
|
|
|
attribs->tang.em_offset = fdata->layers[layer].offset;
|
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
|
|
|
}
|
2013-10-17 16:04:10 +02:00
|
|
|
else {
|
|
|
|
attribs->tang.array = NULL;
|
|
|
|
attribs->tang.em_offset = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
attribs->tang.gl_index = gattribs->layer[b].glindex;
|
Sorry for the big commit, but I've been fixing many of these
issues in parallel... So this commit contains: an update of
the solver (e.g. moving objects), integration of blender IPOs,
improved rendering (motion blur, smoothed normals) and a first particle
test. In more detail:
Solver update:
- Moving objects using a relatively simple model, and not yet fully optimized - ok
for box falling into water, water in a moving glass might cause trouble. Simulation
times are influenced by overall no. of triangles of the mesh, scaling meshes up a lot
might also cause slowdowns.
- Additional obstacle settings: noslip (as before), free slip (move along wall freely)
and part slip (mix of both).
- Obstacle settings also added for domain boundaries now, the six walls of the domain are
obstacles after all as well
- Got rid of templates, should make compiling for e.g. macs more convenient,
for linux there's not much difference. Finally got rid of parser (and some other code
parts), the simulation now uses the internal API to transfer data.
- Some unnecessary file were removed, the GUI now needs 3 settings buttons...
This should still be changed (maybe by adding a new panel for domain objects).
IPOs:
- Animated params: viscosity, time and gravity for domains. In contrast
to normal time IPO for Blender objects, the fluidsim one scales the time
step size - so a constant 1 has no effect, values towards 0 slow it down,
larger ones speed the simulation up (-> longer time steps, more compuations).
The viscosity IPO is also only a factor for the selected viscosity (again, 1=no effect).
- For objects that are enabled for fluidsim, a new IPO type shows up. Inflow
objects can use the velocity channels to animate the inflow. Obstacles, in/outflow
objects can be switched on (Active IPO>0) and off (<0) during the simulation.
- Movement, rotation and scaling of those 3 types is exported from the normal
Blender channels (Loc,dLoc,etc.).
Particles:
- This is still experimental, so it might be deactivated for a
release... It should at some point be used to model smaller splashes,
depending on the the realworld size and the particle generation
settings particles are generated during simulation (stored in _particles_X.gz
files).
- These are loaded by enabling the particle field for an arbitrary object,
which should be given a halo material. For each frame, similar to the mesh
loading, the particle system them loads the simulated particle positions.
- For rendering, I "abused" the part->rt field - I couldnt find any use
for it in the code and it seems to work fine. The fluidsim particles
store their size there.
Rendering:
- The fluidims particles use scaled sizes and alpha values to give a more varied
appearance. In convertblender.c fluidsim particle systems use the p->rt field
to scale up the size and down the alpha of "smaller particles". Setting the
influence fields in the fluidims settings to 0 gives equally sized particles
with same alpha everywhere. Higher values cause larger differences.
- Smoothed normals: for unmodified fluid meshes (e.g. no subdivision) the normals
computed by the solver are used. This is basically done by switching off the
normal recalculation in convertblender.c (the function calc_fluidsimnormals
handles other mesh inits instead of calc_vertexnormals).
This could also be used to e.g. modify mesh normals in a modifier...
- Another change is that fluidsim meshes load the velocities computed
during the simulation for image based motion blur. This is inited in
load_fluidsimspeedvectors for the vector pass (they're loaded during the
normal load in DerivedMesh readBobjgz). Generation and loading can be switched
off in the settings. Vector pass currently loads the fluidism meshes 3 times,
so this should still be optimized.
Examples:
- smoothed normals versus normals from subdividing once:
http://www10.informatik.uni-erlangen.de/~sinithue/temp/v060227_1smoothnorms.png
http://www10.informatik.uni-erlangen.de/~sinithue/temp/v060227_2subdivnorms.png
- fluidsim particles, size/alpha influence 0:
http://www10.informatik.uni-erlangen.de/~sinithue/temp/v060227_3particlesnorm.png
size influence 1:
http://www10.informatik.uni-erlangen.de/~sinithue/temp/v060227_4particlessize.png
size & alpha influence 1:
http://www10.informatik.uni-erlangen.de/~sinithue/temp/v060227_5particlesalpha.png
- the standard drop with motion blur and particles:
http://www10.informatik.uni-erlangen.de/~sinithue/temp/elbeemupdate_t2new.mpg
(here's how it looks without
http://www10.informatik.uni-erlangen.de/~sinithue/temp/elbeemupdate_t1old.mpg)
- another inflow animation (moving, switched on/off) with a moving obstacle
(and strong mblur :)
http://www10.informatik.uni-erlangen.de/~sinithue/temp/elbeemupdate_t3ipos.mpg
Things still to fix:
- rotating & scaling domains causes wrong speed vectors
- get rid of SDL code for threading, use pthreads as well?
- update wiki documentation
- cool effects for rendering would be photon maps for caustics,
and motion blur for particles :)
2006-02-27 12:45:42 +01:00
|
|
|
}
|
2012-03-24 07:18:31 +01:00
|
|
|
else if (gattribs->layer[b].type == 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
|
|
|
/* original coordinates */
|
|
|
|
layer = CustomData_get_layer_index(vdata, CD_ORCO);
|
2013-10-17 16:04:10 +02:00
|
|
|
attribs->totorco = 1;
|
Sorry for the big commit, but I've been fixing many of these
issues in parallel... So this commit contains: an update of
the solver (e.g. moving objects), integration of blender IPOs,
improved rendering (motion blur, smoothed normals) and a first particle
test. In more detail:
Solver update:
- Moving objects using a relatively simple model, and not yet fully optimized - ok
for box falling into water, water in a moving glass might cause trouble. Simulation
times are influenced by overall no. of triangles of the mesh, scaling meshes up a lot
might also cause slowdowns.
- Additional obstacle settings: noslip (as before), free slip (move along wall freely)
and part slip (mix of both).
- Obstacle settings also added for domain boundaries now, the six walls of the domain are
obstacles after all as well
- Got rid of templates, should make compiling for e.g. macs more convenient,
for linux there's not much difference. Finally got rid of parser (and some other code
parts), the simulation now uses the internal API to transfer data.
- Some unnecessary file were removed, the GUI now needs 3 settings buttons...
This should still be changed (maybe by adding a new panel for domain objects).
IPOs:
- Animated params: viscosity, time and gravity for domains. In contrast
to normal time IPO for Blender objects, the fluidsim one scales the time
step size - so a constant 1 has no effect, values towards 0 slow it down,
larger ones speed the simulation up (-> longer time steps, more compuations).
The viscosity IPO is also only a factor for the selected viscosity (again, 1=no effect).
- For objects that are enabled for fluidsim, a new IPO type shows up. Inflow
objects can use the velocity channels to animate the inflow. Obstacles, in/outflow
objects can be switched on (Active IPO>0) and off (<0) during the simulation.
- Movement, rotation and scaling of those 3 types is exported from the normal
Blender channels (Loc,dLoc,etc.).
Particles:
- This is still experimental, so it might be deactivated for a
release... It should at some point be used to model smaller splashes,
depending on the the realworld size and the particle generation
settings particles are generated during simulation (stored in _particles_X.gz
files).
- These are loaded by enabling the particle field for an arbitrary object,
which should be given a halo material. For each frame, similar to the mesh
loading, the particle system them loads the simulated particle positions.
- For rendering, I "abused" the part->rt field - I couldnt find any use
for it in the code and it seems to work fine. The fluidsim particles
store their size there.
Rendering:
- The fluidims particles use scaled sizes and alpha values to give a more varied
appearance. In convertblender.c fluidsim particle systems use the p->rt field
to scale up the size and down the alpha of "smaller particles". Setting the
influence fields in the fluidims settings to 0 gives equally sized particles
with same alpha everywhere. Higher values cause larger differences.
- Smoothed normals: for unmodified fluid meshes (e.g. no subdivision) the normals
computed by the solver are used. This is basically done by switching off the
normal recalculation in convertblender.c (the function calc_fluidsimnormals
handles other mesh inits instead of calc_vertexnormals).
This could also be used to e.g. modify mesh normals in a modifier...
- Another change is that fluidsim meshes load the velocities computed
during the simulation for image based motion blur. This is inited in
load_fluidsimspeedvectors for the vector pass (they're loaded during the
normal load in DerivedMesh readBobjgz). Generation and loading can be switched
off in the settings. Vector pass currently loads the fluidism meshes 3 times,
so this should still be optimized.
Examples:
- smoothed normals versus normals from subdividing once:
http://www10.informatik.uni-erlangen.de/~sinithue/temp/v060227_1smoothnorms.png
http://www10.informatik.uni-erlangen.de/~sinithue/temp/v060227_2subdivnorms.png
- fluidsim particles, size/alpha influence 0:
http://www10.informatik.uni-erlangen.de/~sinithue/temp/v060227_3particlesnorm.png
size influence 1:
http://www10.informatik.uni-erlangen.de/~sinithue/temp/v060227_4particlessize.png
size & alpha influence 1:
http://www10.informatik.uni-erlangen.de/~sinithue/temp/v060227_5particlesalpha.png
- the standard drop with motion blur and particles:
http://www10.informatik.uni-erlangen.de/~sinithue/temp/elbeemupdate_t2new.mpg
(here's how it looks without
http://www10.informatik.uni-erlangen.de/~sinithue/temp/elbeemupdate_t1old.mpg)
- another inflow animation (moving, switched on/off) with a moving obstacle
(and strong mblur :)
http://www10.informatik.uni-erlangen.de/~sinithue/temp/elbeemupdate_t3ipos.mpg
Things still to fix:
- rotating & scaling domains causes wrong speed vectors
- get rid of SDL code for threading, use pthreads as well?
- update wiki documentation
- cool effects for rendering would be photon maps for caustics,
and motion blur for particles :)
2006-02-27 12:45:42 +01:00
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (layer != -1) {
|
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
|
|
|
attribs->orco.array = vdata->layers[layer].data;
|
2012-05-04 13:50:11 +02:00
|
|
|
attribs->orco.em_offset = vdata->layers[layer].offset;
|
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
|
|
|
}
|
2013-10-17 16:04:10 +02:00
|
|
|
else {
|
|
|
|
attribs->orco.array = NULL;
|
|
|
|
attribs->orco.em_offset = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
attribs->orco.gl_index = gattribs->layer[b].glindex;
|
|
|
|
attribs->orco.gl_texco = gattribs->layer[b].gltexco;
|
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
|
|
|
}
|
Sorry for the big commit, but I've been fixing many of these
issues in parallel... So this commit contains: an update of
the solver (e.g. moving objects), integration of blender IPOs,
improved rendering (motion blur, smoothed normals) and a first particle
test. In more detail:
Solver update:
- Moving objects using a relatively simple model, and not yet fully optimized - ok
for box falling into water, water in a moving glass might cause trouble. Simulation
times are influenced by overall no. of triangles of the mesh, scaling meshes up a lot
might also cause slowdowns.
- Additional obstacle settings: noslip (as before), free slip (move along wall freely)
and part slip (mix of both).
- Obstacle settings also added for domain boundaries now, the six walls of the domain are
obstacles after all as well
- Got rid of templates, should make compiling for e.g. macs more convenient,
for linux there's not much difference. Finally got rid of parser (and some other code
parts), the simulation now uses the internal API to transfer data.
- Some unnecessary file were removed, the GUI now needs 3 settings buttons...
This should still be changed (maybe by adding a new panel for domain objects).
IPOs:
- Animated params: viscosity, time and gravity for domains. In contrast
to normal time IPO for Blender objects, the fluidsim one scales the time
step size - so a constant 1 has no effect, values towards 0 slow it down,
larger ones speed the simulation up (-> longer time steps, more compuations).
The viscosity IPO is also only a factor for the selected viscosity (again, 1=no effect).
- For objects that are enabled for fluidsim, a new IPO type shows up. Inflow
objects can use the velocity channels to animate the inflow. Obstacles, in/outflow
objects can be switched on (Active IPO>0) and off (<0) during the simulation.
- Movement, rotation and scaling of those 3 types is exported from the normal
Blender channels (Loc,dLoc,etc.).
Particles:
- This is still experimental, so it might be deactivated for a
release... It should at some point be used to model smaller splashes,
depending on the the realworld size and the particle generation
settings particles are generated during simulation (stored in _particles_X.gz
files).
- These are loaded by enabling the particle field for an arbitrary object,
which should be given a halo material. For each frame, similar to the mesh
loading, the particle system them loads the simulated particle positions.
- For rendering, I "abused" the part->rt field - I couldnt find any use
for it in the code and it seems to work fine. The fluidsim particles
store their size there.
Rendering:
- The fluidims particles use scaled sizes and alpha values to give a more varied
appearance. In convertblender.c fluidsim particle systems use the p->rt field
to scale up the size and down the alpha of "smaller particles". Setting the
influence fields in the fluidims settings to 0 gives equally sized particles
with same alpha everywhere. Higher values cause larger differences.
- Smoothed normals: for unmodified fluid meshes (e.g. no subdivision) the normals
computed by the solver are used. This is basically done by switching off the
normal recalculation in convertblender.c (the function calc_fluidsimnormals
handles other mesh inits instead of calc_vertexnormals).
This could also be used to e.g. modify mesh normals in a modifier...
- Another change is that fluidsim meshes load the velocities computed
during the simulation for image based motion blur. This is inited in
load_fluidsimspeedvectors for the vector pass (they're loaded during the
normal load in DerivedMesh readBobjgz). Generation and loading can be switched
off in the settings. Vector pass currently loads the fluidism meshes 3 times,
so this should still be optimized.
Examples:
- smoothed normals versus normals from subdividing once:
http://www10.informatik.uni-erlangen.de/~sinithue/temp/v060227_1smoothnorms.png
http://www10.informatik.uni-erlangen.de/~sinithue/temp/v060227_2subdivnorms.png
- fluidsim particles, size/alpha influence 0:
http://www10.informatik.uni-erlangen.de/~sinithue/temp/v060227_3particlesnorm.png
size influence 1:
http://www10.informatik.uni-erlangen.de/~sinithue/temp/v060227_4particlessize.png
size & alpha influence 1:
http://www10.informatik.uni-erlangen.de/~sinithue/temp/v060227_5particlesalpha.png
- the standard drop with motion blur and particles:
http://www10.informatik.uni-erlangen.de/~sinithue/temp/elbeemupdate_t2new.mpg
(here's how it looks without
http://www10.informatik.uni-erlangen.de/~sinithue/temp/elbeemupdate_t1old.mpg)
- another inflow animation (moving, switched on/off) with a moving obstacle
(and strong mblur :)
http://www10.informatik.uni-erlangen.de/~sinithue/temp/elbeemupdate_t3ipos.mpg
Things still to fix:
- rotating & scaling domains causes wrong speed vectors
- get rid of SDL code for threading, use pthreads as well?
- update wiki documentation
- cool effects for rendering would be photon maps for caustics,
and motion blur for particles :)
2006-02-27 12:45:42 +01:00
|
|
|
}
|
2005-11-09 08:56:26 +01:00
|
|
|
}
|
|
|
|
|
2010-03-05 17:47:52 +01:00
|
|
|
/* Set object's bounding box based on DerivedMesh min/max data */
|
|
|
|
void DM_set_object_boundbox(Object *ob, DerivedMesh *dm)
|
|
|
|
{
|
|
|
|
float min[3], max[3];
|
|
|
|
|
|
|
|
INIT_MINMAX(min, max);
|
|
|
|
|
|
|
|
dm->getMinMax(dm, min, max);
|
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (!ob->bb)
|
2012-05-12 21:18:02 +02:00
|
|
|
ob->bb = MEM_callocN(sizeof(BoundBox), "DM-BoundBox");
|
2010-03-05 17:47:52 +01:00
|
|
|
|
2012-05-05 16:03:12 +02:00
|
|
|
BKE_boundbox_init_from_minmax(ob->bb, min, max);
|
2010-03-05 17:47:52 +01:00
|
|
|
}
|
2011-10-09 23:11:51 +02:00
|
|
|
|
|
|
|
/* --- NAVMESH (begin) --- */
|
|
|
|
#ifdef WITH_GAMEENGINE
|
|
|
|
|
2012-02-13 05:52:41 +01:00
|
|
|
/* BMESH_TODO, navmesh is not working right currently
|
|
|
|
* All tools set this as MPoly data, but derived mesh currently draws from MFace (tessface)
|
|
|
|
*
|
|
|
|
* Proposed solution, rather then copy CD_RECAST into the MFace array,
|
|
|
|
* use ORIGINDEX to get the original poly index and then get the CD_RECAST
|
|
|
|
* data from the original me->mpoly layer. - campbell
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2012-03-20 09:42:26 +01:00
|
|
|
BLI_INLINE int navmesh_bit(int a, int b)
|
2011-10-09 23:11:51 +02:00
|
|
|
{
|
|
|
|
return (a & (1 << b)) >> b;
|
|
|
|
}
|
|
|
|
|
2012-03-20 09:42:26 +01:00
|
|
|
BLI_INLINE void navmesh_intToCol(int i, float col[3])
|
2011-10-09 23:11:51 +02:00
|
|
|
{
|
2012-05-12 21:18:02 +02:00
|
|
|
int r = navmesh_bit(i, 0) + navmesh_bit(i, 3) * 2 + 1;
|
|
|
|
int g = navmesh_bit(i, 1) + navmesh_bit(i, 4) * 2 + 1;
|
|
|
|
int b = navmesh_bit(i, 2) + navmesh_bit(i, 5) * 2 + 1;
|
|
|
|
col[0] = 1 - r * 63.0f / 255.0f;
|
|
|
|
col[1] = 1 - g * 63.0f / 255.0f;
|
|
|
|
col[2] = 1 - b * 63.0f / 255.0f;
|
2011-10-09 23:11:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void navmesh_drawColored(DerivedMesh *dm)
|
|
|
|
{
|
|
|
|
int a, glmode;
|
|
|
|
MVert *mvert = (MVert *)CustomData_get_layer(&dm->vertData, CD_MVERT);
|
|
|
|
MFace *mface = (MFace *)CustomData_get_layer(&dm->faceData, CD_MFACE);
|
2012-04-16 15:53:30 +02:00
|
|
|
int *polygonIdx = (int *)CustomData_get_layer(&dm->polyData, CD_RECAST);
|
2011-10-09 23:11:51 +02:00
|
|
|
float col[3];
|
|
|
|
|
|
|
|
if (!polygonIdx)
|
|
|
|
return;
|
|
|
|
|
2012-03-09 19:28:30 +01:00
|
|
|
#if 0
|
2011-10-09 23:11:51 +02:00
|
|
|
//UI_ThemeColor(TH_WIRE);
|
|
|
|
glDisable(GL_LIGHTING);
|
|
|
|
glLineWidth(2.0);
|
|
|
|
dm->drawEdges(dm, 0, 1);
|
|
|
|
glLineWidth(1.0);
|
2012-03-09 19:28:30 +01:00
|
|
|
glEnable(GL_LIGHTING);
|
|
|
|
#endif
|
2011-10-09 23:11:51 +02:00
|
|
|
|
|
|
|
glDisable(GL_LIGHTING);
|
2012-05-20 21:49:27 +02:00
|
|
|
/* if (GPU_buffer_legacy(dm) ) */ { /* TODO - VBO draw code, not high priority - campbell */
|
2012-04-29 19:11:40 +02:00
|
|
|
DEBUG_VBO("Using legacy code. drawNavMeshColored\n");
|
2011-10-09 23:11:51 +02:00
|
|
|
//glShadeModel(GL_SMOOTH);
|
|
|
|
glBegin(glmode = GL_QUADS);
|
2012-03-24 07:18:31 +01:00
|
|
|
for (a = 0; a < dm->numTessFaceData; a++, mface++) {
|
2012-05-12 21:18:02 +02:00
|
|
|
int new_glmode = mface->v4 ? GL_QUADS : GL_TRIANGLES;
|
2011-10-10 09:21:42 +02:00
|
|
|
int pi = polygonIdx[a];
|
|
|
|
if (pi <= 0) {
|
|
|
|
zero_v3(col);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
navmesh_intToCol(pi, col);
|
|
|
|
}
|
2011-10-09 23:11:51 +02:00
|
|
|
|
2012-03-24 07:18:31 +01:00
|
|
|
if (new_glmode != glmode) {
|
2011-10-09 23:11:51 +02:00
|
|
|
glEnd();
|
|
|
|
glBegin(glmode = new_glmode);
|
|
|
|
}
|
|
|
|
glColor3fv(col);
|
|
|
|
glVertex3fv(mvert[mface->v1].co);
|
|
|
|
glVertex3fv(mvert[mface->v2].co);
|
|
|
|
glVertex3fv(mvert[mface->v3].co);
|
2012-03-24 07:18:31 +01:00
|
|
|
if (mface->v4) {
|
2011-10-09 23:11:51 +02:00
|
|
|
glVertex3fv(mvert[mface->v4].co);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
glEnd();
|
|
|
|
}
|
|
|
|
glEnable(GL_LIGHTING);
|
|
|
|
}
|
|
|
|
|
2011-12-01 13:12:39 +01:00
|
|
|
static void navmesh_DM_drawFacesTex(DerivedMesh *dm,
|
2012-05-12 21:18:02 +02:00
|
|
|
DMSetDrawOptionsTex setDrawOptions,
|
|
|
|
DMCompareDrawOptions compareDrawOptions,
|
|
|
|
void *userData)
|
2011-10-09 23:11:51 +02:00
|
|
|
{
|
|
|
|
(void) setDrawOptions;
|
2011-12-01 13:12:39 +01:00
|
|
|
(void) compareDrawOptions;
|
|
|
|
(void) userData;
|
2011-10-09 23:11:51 +02:00
|
|
|
|
|
|
|
navmesh_drawColored(dm);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void navmesh_DM_drawFacesSolid(DerivedMesh *dm,
|
2011-10-09 23:43:13 +02:00
|
|
|
float (*partial_redraw_planes)[4],
|
2012-03-08 10:14:10 +01:00
|
|
|
int UNUSED(fast), DMSetMaterial setMaterial)
|
2011-10-09 23:11:51 +02:00
|
|
|
{
|
|
|
|
(void) partial_redraw_planes;
|
|
|
|
(void) setMaterial;
|
|
|
|
|
|
|
|
//drawFacesSolid_original(dm, partial_redraw_planes, fast, setMaterial);
|
|
|
|
navmesh_drawColored(dm);
|
|
|
|
}
|
|
|
|
|
|
|
|
static DerivedMesh *navmesh_dm_createNavMeshForVisualization(DerivedMesh *dm)
|
|
|
|
{
|
|
|
|
DerivedMesh *result;
|
2011-11-29 14:01:51 +01:00
|
|
|
int maxFaces = dm->getNumPolys(dm);
|
2011-10-09 23:11:51 +02:00
|
|
|
int *recastData;
|
2012-05-12 21:18:02 +02:00
|
|
|
int vertsPerPoly = 0, nverts = 0, ndtris = 0, npolys = 0;
|
|
|
|
float *verts = NULL;
|
|
|
|
unsigned short *dtris = NULL, *dmeshes = NULL, *polys = NULL;
|
|
|
|
int *dtrisToPolysMap = NULL, *dtrisToTrisMap = NULL, *trisToFacesMap = NULL;
|
2011-10-09 23:11:51 +02:00
|
|
|
int res;
|
|
|
|
|
2012-01-29 23:32:00 +01:00
|
|
|
result = CDDM_copy(dm);
|
2012-04-16 15:53:30 +02:00
|
|
|
if (!CustomData_has_layer(&result->polyData, CD_RECAST)) {
|
2012-05-12 21:18:02 +02:00
|
|
|
int *sourceRecastData = (int *)CustomData_get_layer(&dm->polyData, CD_RECAST);
|
2011-10-10 04:56:26 +02:00
|
|
|
if (sourceRecastData) {
|
2012-04-16 15:53:30 +02:00
|
|
|
CustomData_add_layer_named(&result->polyData, CD_RECAST, CD_DUPLICATE,
|
2011-10-10 04:56:26 +02:00
|
|
|
sourceRecastData, maxFaces, "recastData");
|
|
|
|
}
|
2011-10-09 23:11:51 +02:00
|
|
|
}
|
2012-05-12 21:18:02 +02:00
|
|
|
recastData = (int *)CustomData_get_layer(&result->polyData, CD_RECAST);
|
2011-10-09 23:43:13 +02:00
|
|
|
|
|
|
|
/* note: This is not good design! - really should not be doing this */
|
2011-10-09 23:11:51 +02:00
|
|
|
result->drawFacesTex = navmesh_DM_drawFacesTex;
|
|
|
|
result->drawFacesSolid = navmesh_DM_drawFacesSolid;
|
|
|
|
|
|
|
|
|
2011-10-09 23:43:13 +02:00
|
|
|
/* process mesh */
|
2011-10-09 23:11:51 +02:00
|
|
|
res = buildNavMeshDataByDerivedMesh(dm, &vertsPerPoly, &nverts, &verts, &ndtris, &dtris,
|
2011-10-09 23:43:13 +02:00
|
|
|
&npolys, &dmeshes, &polys, &dtrisToPolysMap, &dtrisToTrisMap,
|
|
|
|
&trisToFacesMap);
|
|
|
|
if (res) {
|
2011-10-09 23:11:51 +02:00
|
|
|
size_t polyIdx;
|
|
|
|
|
2011-10-09 23:43:13 +02:00
|
|
|
/* invalidate concave polygon */
|
2012-05-12 21:18:02 +02:00
|
|
|
for (polyIdx = 0; polyIdx < (size_t)npolys; polyIdx++) {
|
|
|
|
unsigned short *poly = &polys[polyIdx * 2 * vertsPerPoly];
|
2011-10-09 23:43:13 +02:00
|
|
|
if (!polyIsConvex(poly, vertsPerPoly, verts)) {
|
|
|
|
/* set negative polygon idx to all faces */
|
2012-05-12 21:18:02 +02:00
|
|
|
unsigned short *dmesh = &dmeshes[4 * polyIdx];
|
2011-10-09 23:11:51 +02:00
|
|
|
unsigned short tbase = dmesh[2];
|
|
|
|
unsigned short tnum = dmesh[3];
|
|
|
|
unsigned short ti;
|
|
|
|
|
2012-05-12 21:18:02 +02:00
|
|
|
for (ti = 0; ti < tnum; ti++) {
|
|
|
|
unsigned short triidx = dtrisToTrisMap[tbase + ti];
|
2011-10-09 23:11:51 +02:00
|
|
|
unsigned short faceidx = trisToFacesMap[triidx];
|
2011-10-09 23:43:13 +02:00
|
|
|
if (recastData[faceidx] > 0) {
|
2011-10-09 23:11:51 +02:00
|
|
|
recastData[faceidx] = -recastData[faceidx];
|
2011-10-09 23:43:13 +02:00
|
|
|
}
|
2011-10-09 23:11:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-10-09 23:43:13 +02:00
|
|
|
else {
|
2013-07-20 00:07:38 +02:00
|
|
|
printf("Navmesh: Unable to generate valid Navmesh");
|
2011-10-09 23:11:51 +02:00
|
|
|
}
|
|
|
|
|
2011-10-09 23:43:13 +02:00
|
|
|
/* clean up */
|
2012-05-12 21:18:02 +02:00
|
|
|
if (verts != NULL)
|
2011-10-09 23:11:51 +02:00
|
|
|
MEM_freeN(verts);
|
2012-05-12 21:18:02 +02:00
|
|
|
if (dtris != NULL)
|
2011-10-09 23:11:51 +02:00
|
|
|
MEM_freeN(dtris);
|
2012-05-12 21:18:02 +02:00
|
|
|
if (dmeshes != NULL)
|
2011-10-09 23:11:51 +02:00
|
|
|
MEM_freeN(dmeshes);
|
2012-05-12 21:18:02 +02:00
|
|
|
if (polys != NULL)
|
2011-10-09 23:11:51 +02:00
|
|
|
MEM_freeN(polys);
|
2012-05-12 21:18:02 +02:00
|
|
|
if (dtrisToPolysMap != NULL)
|
2011-10-09 23:11:51 +02:00
|
|
|
MEM_freeN(dtrisToPolysMap);
|
2012-05-12 21:18:02 +02:00
|
|
|
if (dtrisToTrisMap != NULL)
|
2011-10-09 23:11:51 +02:00
|
|
|
MEM_freeN(dtrisToTrisMap);
|
2012-05-12 21:18:02 +02:00
|
|
|
if (trisToFacesMap != NULL)
|
2011-10-09 23:11:51 +02:00
|
|
|
MEM_freeN(trisToFacesMap);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* WITH_GAMEENGINE */
|
|
|
|
|
|
|
|
/* --- NAVMESH (end) --- */
|
2012-01-19 01:18:25 +01:00
|
|
|
|
|
|
|
|
2012-02-05 12:30:26 +01:00
|
|
|
void DM_init_origspace(DerivedMesh *dm)
|
|
|
|
{
|
|
|
|
static float default_osf[4][2] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}};
|
|
|
|
|
|
|
|
OrigSpaceLoop *lof_array = CustomData_get_layer(&dm->loopData, CD_ORIGSPACE_MLOOP);
|
|
|
|
OrigSpaceLoop *lof;
|
|
|
|
const int numpoly = dm->getNumPolys(dm);
|
|
|
|
// const int numloop = dm->getNumLoops(dm);
|
|
|
|
MPoly *mp = dm->getPolyArray(dm);
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
for (i = 0; i < numpoly; i++, mp++) {
|
|
|
|
/* only quads/tri's for now */
|
|
|
|
if (mp->totloop == 3 || mp->totloop == 4) {
|
|
|
|
lof = lof_array + mp->loopstart;
|
|
|
|
for (j = 0; j < mp->totloop; j++, lof++) {
|
|
|
|
copy_v2_v2(lof->uv, default_osf[j]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-04-01 17:02:19 +02:00
|
|
|
|
|
|
|
dm->dirty |= DM_DIRTY_TESS_CDLAYERS;
|
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"
|
|
|
|
|
2013-05-30 15:13:43 +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)) {
|
|
|
|
/* note: doesnt 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",
|
2013-05-30 15:13:43 +02:00
|
|
|
name, structname, type, (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;
|
2012-01-19 12:31:31 +01:00
|
|
|
case DM_TYPE_EDITBMESH: tstr = "DM_TYPE_EDITMESH"; break;
|
2012-01-19 01:18:25 +01:00
|
|
|
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;
|
|
|
|
CustomDataLayer *layer;
|
|
|
|
|
|
|
|
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",
|
|
|
|
name, structname, layer->type, (void *)layer->data, size, (int)(MEM_allocN_len(layer->data) / size));
|
|
|
|
}
|
|
|
|
|
|
|
|
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(
|
|
|
|
dm->getVertDataLayout(dm),
|
|
|
|
dm->getEdgeDataLayout(dm),
|
|
|
|
dm->getLoopDataLayout(dm),
|
|
|
|
dm->getPolyDataLayout(dm),
|
|
|
|
0, /* 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 */
|