Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSybren A. Stüvel <sybren@stuvel.eu>2018-05-17 16:26:59 +0300
committerSybren A. Stüvel <sybren@stuvel.eu>2018-05-17 16:28:51 +0300
commita2438373b317005c19288d183af4b08f54f80428 (patch)
treecb93bdacc7d33fc38ed5de253ab4853aa1aa55ae /source/blender/modifiers/intern/MOD_collision.c
parentc48a3afb166b38bbdf55c3e6d317ef85f90d18bf (diff)
Modifiers: ported Collision DerivedMesh → Mesh
Diffstat (limited to 'source/blender/modifiers/intern/MOD_collision.c')
-rw-r--r--source/blender/modifiers/intern/MOD_collision.c59
1 files changed, 38 insertions, 21 deletions
diff --git a/source/blender/modifiers/intern/MOD_collision.c b/source/blender/modifiers/intern/MOD_collision.c
index c9037074ecc..036954a2774 100644
--- a/source/blender/modifiers/intern/MOD_collision.c
+++ b/source/blender/modifiers/intern/MOD_collision.c
@@ -33,6 +33,7 @@
*/
#include "DNA_object_types.h"
+#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
#include "MEM_guardedalloc.h"
@@ -41,13 +42,17 @@
#include "BLI_utildefines.h"
#include "BKE_collision.h"
-#include "BKE_cdderivedmesh.h"
#include "BKE_global.h"
+#include "BKE_library.h"
+#include "BKE_mesh.h"
#include "BKE_modifier.h"
#include "BKE_pointcache.h"
#include "BKE_scene.h"
#include "MOD_modifiertypes.h"
+#include "MOD_util.h"
+
+#include "DEG_depsgraph_query.h"
static void initData(ModifierData *md)
{
@@ -97,37 +102,48 @@ static bool dependsOnTime(ModifierData *UNUSED(md))
static void deformVerts(
ModifierData *md, const ModifierEvalContext *ctx,
- DerivedMesh *derivedData,
+ Mesh *mesh,
float (*vertexCos)[3],
int UNUSED(numVerts))
{
CollisionModifierData *collmd = (CollisionModifierData *) md;
- DerivedMesh *dm = NULL;
+ Mesh *mesh_src;
MVert *tempVert = NULL;
Object *ob = ctx->object;
- /* if possible use/create DerivedMesh */
- if (derivedData) dm = CDDM_copy(derivedData);
- else if (ob->type == OB_MESH) dm = CDDM_from_mesh(ob->data);
-
+ if (mesh == NULL) {
+ mesh_src = get_mesh(ob, NULL, NULL, NULL, false, false);
+ }
+ else {
+ /* Not possible to use get_mesh() in this case as we'll modify its vertices
+ * and get_mesh() would return 'mesh' directly. */
+ BKE_id_copy_ex(
+ NULL, (ID *)mesh, (ID **)&mesh_src,
+ LIB_ID_CREATE_NO_MAIN |
+ LIB_ID_CREATE_NO_USER_REFCOUNT |
+ LIB_ID_CREATE_NO_DEG_TAG |
+ LIB_ID_COPY_NO_PREVIEW,
+ false);
+ }
+
if (!ob->pd) {
printf("CollisionModifier deformVerts: Should not happen!\n");
return;
}
- if (dm) {
+ if (mesh_src) {
float current_time = 0;
unsigned int mvert_num = 0;
- CDDM_apply_vert_coords(dm, vertexCos);
- CDDM_calc_normals(dm);
+ BKE_mesh_apply_vert_coords(mesh_src, vertexCos);
+ BKE_mesh_calc_normals(mesh_src);
current_time = DEG_get_ctime(ctx->depsgraph);
if (G.debug_value > 0)
printf("current_time %f, collmd->time_xnew %f\n", current_time, collmd->time_xnew);
- mvert_num = dm->getNumVerts(dm);
+ mvert_num = mesh_src->totvert;
if (current_time > collmd->time_xnew) {
unsigned int i;
@@ -138,7 +154,7 @@ static void deformVerts(
if (collmd->time_xnew == -1000) { /* first time */
- collmd->x = dm->dupVertArray(dm); /* frame start position */
+ collmd->x = MEM_dupallocN(mesh_src->mvert); /* frame start position */
for (i = 0; i < mvert_num; i++) {
/* we save global positions */
@@ -152,12 +168,12 @@ static void deformVerts(
collmd->mvert_num = mvert_num;
- collmd->tri_num = dm->getNumLoopTri(dm);
{
- const MLoop *mloop = dm->getLoopArray(dm);
- const MLoopTri *looptri = dm->getLoopTriArray(dm);
+ const MLoop *mloop = mesh_src->mloop;
+ const MLoopTri *looptri = BKE_mesh_runtime_looptri_ensure(mesh_src);
+ collmd->tri_num = BKE_mesh_runtime_looptri_len(mesh_src);
MVertTri *tri = MEM_malloc_arrayN(collmd->tri_num, sizeof(*tri), __func__);
- DM_verttri_from_looptri(tri, mloop, looptri, collmd->tri_num);
+ BKE_mesh_runtime_verttri_from_looptri(tri, mloop, looptri, collmd->tri_num);
collmd->tri = tri;
}
@@ -177,7 +193,7 @@ static void deformVerts(
collmd->xnew = tempVert;
collmd->time_x = collmd->time_xnew;
- memcpy(collmd->xnew, dm->getVertArray(dm), mvert_num * sizeof(MVert));
+ memcpy(collmd->xnew, mesh_src->mvert, mvert_num * sizeof(MVert));
bool is_static = true;
@@ -238,8 +254,9 @@ static void deformVerts(
}
}
- if (dm)
- dm->release(dm);
+ if (mesh_src != mesh) {
+ BKE_id_free(NULL, mesh_src);
+ }
}
@@ -253,14 +270,14 @@ ModifierTypeInfo modifierType_Collision = {
/* copyData */ NULL,
- /* deformVerts_DM */ deformVerts,
+ /* deformVerts_DM */ NULL,
/* deformMatrices_DM */ NULL,
/* deformVertsEM_DM */ NULL,
/* deformMatricesEM_DM*/NULL,
/* applyModifier_DM */ NULL,
/* applyModifierEM_DM */NULL,
- /* deformVerts */ NULL,
+ /* deformVerts */ deformVerts,
/* deformMatrices */ NULL,
/* deformVertsEM */ NULL,
/* deformMatricesEM */ NULL,