2018-05-08 10:07:21 +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
|
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
*
|
|
|
|
|
* The Original Code is Copyright (C) 2005 Blender Foundation.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*/
|
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup bke
|
2018-05-08 10:07:21 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "atomic_ops.h"
|
|
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
|
|
#include "DNA_mesh_types.h"
|
|
|
|
|
#include "DNA_meshdata_types.h"
|
2018-06-05 16:58:08 +02:00
|
|
|
#include "DNA_object_types.h"
|
2018-05-08 10:07:21 +02:00
|
|
|
|
|
|
|
|
#include "BLI_math_geom.h"
|
2021-06-22 18:17:48 +02:00
|
|
|
#include "BLI_task.h"
|
2018-05-08 10:07:21 +02:00
|
|
|
#include "BLI_threads.h"
|
|
|
|
|
|
2018-05-11 15:48:14 -03:00
|
|
|
#include "BKE_bvhutils.h"
|
2020-02-10 12:58:59 +01:00
|
|
|
#include "BKE_lib_id.h"
|
2018-05-08 10:07:21 +02:00
|
|
|
#include "BKE_mesh.h"
|
2018-06-05 15:59:53 +02:00
|
|
|
#include "BKE_mesh_runtime.h"
|
Shrinkwrap: new mode that projects along the target normal.
The Nearest Surface Point shrink method, while fast, is neither
smooth nor continuous: as the source point moves, the projected
point can both stop and jump. This causes distortions in the
deformation of the shrinkwrap modifier, and the motion of an
animated object with a shrinkwrap constraint.
This patch implements a new mode, which, instead of using the simple
nearest point search, iteratively solves an equation for each triangle
to find a point which has its interpolated normal point to or from the
original vertex. Non-manifold boundary edges are treated as infinitely
thin cylinders that cast normals in all perpendicular directions.
Since this is useful for the constraint, and having multiple
objects with constraints targeting the same guide mesh is a quite
reasonable use case, rather than calculating the mesh boundary edge
data over and over again, it is precomputed and cached in the mesh.
Reviewers: mont29
Differential Revision: https://developer.blender.org/D3836
2018-11-06 21:04:53 +03:00
|
|
|
#include "BKE_shrinkwrap.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BKE_subdiv_ccg.h"
|
2018-05-08 10:07:21 +02:00
|
|
|
|
2018-06-05 15:54:12 +02:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Mesh Runtime Struct Utils
|
|
|
|
|
* \{ */
|
2018-05-08 10:07:21 +02:00
|
|
|
|
2018-05-09 15:38:58 +02:00
|
|
|
/**
|
2021-11-10 13:50:00 +01:00
|
|
|
* \brief Initialize the runtime mutexes of the given mesh.
|
|
|
|
|
*
|
|
|
|
|
* Any existing mutexes will be overridden.
|
2018-05-09 15:38:58 +02:00
|
|
|
*/
|
2021-11-10 13:50:00 +01:00
|
|
|
static void mesh_runtime_init_mutexes(Mesh *mesh)
|
2018-05-09 15:38:58 +02:00
|
|
|
{
|
2019-05-27 11:45:33 +02:00
|
|
|
mesh->runtime.eval_mutex = MEM_mallocN(sizeof(ThreadMutex), "mesh runtime eval_mutex");
|
|
|
|
|
BLI_mutex_init(mesh->runtime.eval_mutex);
|
2021-10-26 18:16:33 -03:00
|
|
|
mesh->runtime.render_mutex = MEM_mallocN(sizeof(ThreadMutex), "mesh runtime render_mutex");
|
|
|
|
|
BLI_mutex_init(mesh->runtime.render_mutex);
|
2018-05-09 15:38:58 +02:00
|
|
|
}
|
2018-05-08 10:07:21 +02:00
|
|
|
|
2021-11-10 13:50:00 +01:00
|
|
|
/**
|
|
|
|
|
* \brief free the mutexes of the given mesh runtime.
|
|
|
|
|
*/
|
|
|
|
|
static void mesh_runtime_free_mutexes(Mesh *mesh)
|
|
|
|
|
{
|
|
|
|
|
if (mesh->runtime.eval_mutex != NULL) {
|
|
|
|
|
BLI_mutex_end(mesh->runtime.eval_mutex);
|
|
|
|
|
MEM_freeN(mesh->runtime.eval_mutex);
|
|
|
|
|
mesh->runtime.eval_mutex = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (mesh->runtime.render_mutex != NULL) {
|
|
|
|
|
BLI_mutex_end(mesh->runtime.render_mutex);
|
|
|
|
|
MEM_freeN(mesh->runtime.render_mutex);
|
|
|
|
|
mesh->runtime.render_mutex = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BKE_mesh_runtime_init_data(Mesh *mesh)
|
|
|
|
|
{
|
|
|
|
|
mesh_runtime_init_mutexes(mesh);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BKE_mesh_runtime_free_data(Mesh *mesh)
|
|
|
|
|
{
|
|
|
|
|
BKE_mesh_runtime_clear_cache(mesh);
|
|
|
|
|
mesh_runtime_free_mutexes(mesh);
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-13 14:29:27 +01:00
|
|
|
void BKE_mesh_runtime_reset_on_copy(Mesh *mesh, const int UNUSED(flag))
|
2018-12-17 12:28:16 +01:00
|
|
|
{
|
|
|
|
|
Mesh_Runtime *runtime = &mesh->runtime;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-05-27 11:45:33 +02:00
|
|
|
runtime->mesh_eval = NULL;
|
2018-12-17 12:28:16 +01:00
|
|
|
runtime->edit_data = NULL;
|
|
|
|
|
runtime->batch_cache = NULL;
|
|
|
|
|
runtime->subdiv_ccg = NULL;
|
|
|
|
|
memset(&runtime->looptris, 0, sizeof(runtime->looptris));
|
|
|
|
|
runtime->bvh_cache = NULL;
|
|
|
|
|
runtime->shrinkwrap_data = NULL;
|
2019-05-27 11:45:33 +02:00
|
|
|
|
2021-11-10 13:50:00 +01:00
|
|
|
mesh_runtime_init_mutexes(mesh);
|
2018-12-17 12:28:16 +01:00
|
|
|
}
|
|
|
|
|
|
2018-05-11 15:48:14 -03:00
|
|
|
void BKE_mesh_runtime_clear_cache(Mesh *mesh)
|
|
|
|
|
{
|
2019-05-27 11:45:33 +02:00
|
|
|
if (mesh->runtime.mesh_eval != NULL) {
|
|
|
|
|
mesh->runtime.mesh_eval->edit_mesh = NULL;
|
|
|
|
|
BKE_id_free(NULL, mesh->runtime.mesh_eval);
|
|
|
|
|
mesh->runtime.mesh_eval = NULL;
|
|
|
|
|
}
|
2018-05-11 15:48:14 -03:00
|
|
|
BKE_mesh_runtime_clear_geometry(mesh);
|
|
|
|
|
BKE_mesh_batch_cache_free(mesh);
|
|
|
|
|
BKE_mesh_runtime_clear_edit_data(mesh);
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-08 10:07:21 +02:00
|
|
|
/**
|
|
|
|
|
* Ensure the array is large enough
|
|
|
|
|
*
|
2019-04-27 12:07:07 +10:00
|
|
|
* \note This function must always be thread-protected by caller.
|
|
|
|
|
* It should only be used by internal code.
|
2018-05-08 10:07:21 +02:00
|
|
|
*/
|
|
|
|
|
static void mesh_ensure_looptri_data(Mesh *mesh)
|
|
|
|
|
{
|
2021-12-07 17:19:15 +11:00
|
|
|
/* This is a ported copy of `DM_ensure_looptri_data(dm)`. */
|
2021-06-18 14:27:41 +10:00
|
|
|
const uint totpoly = mesh->totpoly;
|
2018-05-08 19:36:02 +02:00
|
|
|
const int looptris_len = poly_to_tri_count(totpoly, mesh->totloop);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-08 10:07:21 +02:00
|
|
|
BLI_assert(mesh->runtime.looptris.array_wip == NULL);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-08 10:07:21 +02:00
|
|
|
SWAP(MLoopTri *, mesh->runtime.looptris.array, mesh->runtime.looptris.array_wip);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-08 19:36:02 +02:00
|
|
|
if ((looptris_len > mesh->runtime.looptris.len_alloc) ||
|
|
|
|
|
(looptris_len < mesh->runtime.looptris.len_alloc * 2) || (totpoly == 0)) {
|
2018-05-08 10:07:21 +02:00
|
|
|
MEM_SAFE_FREE(mesh->runtime.looptris.array_wip);
|
2018-05-08 19:36:02 +02:00
|
|
|
mesh->runtime.looptris.len_alloc = 0;
|
|
|
|
|
mesh->runtime.looptris.len = 0;
|
2018-05-08 10:07:21 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-08 10:07:21 +02:00
|
|
|
if (totpoly) {
|
|
|
|
|
if (mesh->runtime.looptris.array_wip == NULL) {
|
2018-05-08 19:36:02 +02:00
|
|
|
mesh->runtime.looptris.array_wip = MEM_malloc_arrayN(
|
|
|
|
|
looptris_len, sizeof(*mesh->runtime.looptris.array_wip), __func__);
|
|
|
|
|
mesh->runtime.looptris.len_alloc = looptris_len;
|
2018-05-08 10:07:21 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-08 19:36:02 +02:00
|
|
|
mesh->runtime.looptris.len = looptris_len;
|
2018-05-08 10:07:21 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-08 19:26:36 +02:00
|
|
|
void BKE_mesh_runtime_looptri_recalc(Mesh *mesh)
|
2018-05-08 10:07:21 +02:00
|
|
|
{
|
|
|
|
|
mesh_ensure_looptri_data(mesh);
|
|
|
|
|
BLI_assert(mesh->totpoly == 0 || mesh->runtime.looptris.array_wip != NULL);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-08 10:07:21 +02:00
|
|
|
BKE_mesh_recalc_looptri(mesh->mloop,
|
|
|
|
|
mesh->mpoly,
|
|
|
|
|
mesh->mvert,
|
|
|
|
|
mesh->totloop,
|
|
|
|
|
mesh->totpoly,
|
|
|
|
|
mesh->runtime.looptris.array_wip);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-08 10:07:21 +02:00
|
|
|
BLI_assert(mesh->runtime.looptris.array == NULL);
|
|
|
|
|
atomic_cas_ptr((void **)&mesh->runtime.looptris.array,
|
|
|
|
|
mesh->runtime.looptris.array,
|
|
|
|
|
mesh->runtime.looptris.array_wip);
|
|
|
|
|
mesh->runtime.looptris.array_wip = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-08 19:26:36 +02:00
|
|
|
int BKE_mesh_runtime_looptri_len(const Mesh *mesh)
|
2018-05-08 10:07:21 +02:00
|
|
|
{
|
2021-12-07 17:19:15 +11:00
|
|
|
/* This is a ported copy of `dm_getNumLoopTri(dm)`. */
|
2018-05-08 19:26:36 +02:00
|
|
|
const int looptri_len = poly_to_tri_count(mesh->totpoly, mesh->totloop);
|
2018-05-08 19:36:02 +02:00
|
|
|
BLI_assert(ELEM(mesh->runtime.looptris.len, 0, looptri_len));
|
2018-05-08 19:26:36 +02:00
|
|
|
return looptri_len;
|
2018-05-08 10:07:21 +02:00
|
|
|
}
|
|
|
|
|
|
2021-06-22 18:17:48 +02:00
|
|
|
static void mesh_runtime_looptri_recalc_isolated(void *userdata)
|
|
|
|
|
{
|
|
|
|
|
Mesh *mesh = userdata;
|
|
|
|
|
BKE_mesh_runtime_looptri_recalc(mesh);
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-02 11:37:01 -05:00
|
|
|
const MLoopTri *BKE_mesh_runtime_looptri_ensure(const Mesh *mesh)
|
2018-05-08 10:07:21 +02:00
|
|
|
{
|
2020-07-29 17:36:27 +02:00
|
|
|
ThreadMutex *mesh_eval_mutex = (ThreadMutex *)mesh->runtime.eval_mutex;
|
|
|
|
|
BLI_mutex_lock(mesh_eval_mutex);
|
|
|
|
|
|
2020-12-27 21:46:57 -06:00
|
|
|
MLoopTri *looptri = mesh->runtime.looptris.array;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-08 10:07:21 +02:00
|
|
|
if (looptri != NULL) {
|
2018-05-08 19:36:02 +02:00
|
|
|
BLI_assert(BKE_mesh_runtime_looptri_len(mesh) == mesh->runtime.looptris.len);
|
2018-05-08 10:07:21 +02:00
|
|
|
}
|
|
|
|
|
else {
|
2021-06-22 18:17:48 +02:00
|
|
|
/* Must isolate multithreaded tasks while holding a mutex lock. */
|
2021-07-02 11:56:29 -05:00
|
|
|
BLI_task_isolate(mesh_runtime_looptri_recalc_isolated, (void *)mesh);
|
2018-05-08 10:07:21 +02:00
|
|
|
looptri = mesh->runtime.looptris.array;
|
|
|
|
|
}
|
2020-07-29 17:36:27 +02:00
|
|
|
|
|
|
|
|
BLI_mutex_unlock(mesh_eval_mutex);
|
|
|
|
|
|
2018-05-08 10:07:21 +02:00
|
|
|
return looptri;
|
|
|
|
|
}
|
2018-05-11 15:48:14 -03:00
|
|
|
|
2018-06-05 15:54:12 +02:00
|
|
|
void BKE_mesh_runtime_verttri_from_looptri(MVertTri *r_verttri,
|
|
|
|
|
const MLoop *mloop,
|
|
|
|
|
const MLoopTri *looptri,
|
|
|
|
|
int looptri_num)
|
2018-05-17 15:26:59 +02:00
|
|
|
{
|
2020-12-27 21:46:57 -06:00
|
|
|
for (int i = 0; i < looptri_num; i++) {
|
2018-05-17 15:26:59 +02:00
|
|
|
r_verttri[i].tri[0] = mloop[looptri[i].tri[0]].v;
|
|
|
|
|
r_verttri[i].tri[1] = mloop[looptri[i].tri[1]].v;
|
|
|
|
|
r_verttri[i].tri[2] = mloop[looptri[i].tri[2]].v;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-11 15:48:14 -03:00
|
|
|
bool BKE_mesh_runtime_ensure_edit_data(struct Mesh *mesh)
|
|
|
|
|
{
|
|
|
|
|
if (mesh->runtime.edit_data != NULL) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mesh->runtime.edit_data = MEM_callocN(sizeof(EditMeshData), "EditMeshData");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-24 22:09:40 +10:00
|
|
|
bool BKE_mesh_runtime_reset_edit_data(Mesh *mesh)
|
|
|
|
|
{
|
|
|
|
|
EditMeshData *edit_data = mesh->runtime.edit_data;
|
|
|
|
|
if (edit_data == NULL) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MEM_SAFE_FREE(edit_data->polyCos);
|
|
|
|
|
MEM_SAFE_FREE(edit_data->polyNos);
|
|
|
|
|
MEM_SAFE_FREE(edit_data->vertexCos);
|
|
|
|
|
MEM_SAFE_FREE(edit_data->vertexNos);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-11 15:48:14 -03:00
|
|
|
bool BKE_mesh_runtime_clear_edit_data(Mesh *mesh)
|
|
|
|
|
{
|
|
|
|
|
if (mesh->runtime.edit_data == NULL) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2020-06-24 22:09:40 +10:00
|
|
|
BKE_mesh_runtime_reset_edit_data(mesh);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-06-24 22:09:40 +10:00
|
|
|
MEM_freeN(mesh->runtime.edit_data);
|
|
|
|
|
mesh->runtime.edit_data = NULL;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-11 15:48:14 -03:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BKE_mesh_runtime_clear_geometry(Mesh *mesh)
|
|
|
|
|
{
|
2020-06-02 15:59:30 +02:00
|
|
|
if (mesh->runtime.bvh_cache) {
|
|
|
|
|
bvhcache_free(mesh->runtime.bvh_cache);
|
|
|
|
|
mesh->runtime.bvh_cache = NULL;
|
|
|
|
|
}
|
2018-05-11 15:48:14 -03:00
|
|
|
MEM_SAFE_FREE(mesh->runtime.looptris.array);
|
2018-09-06 17:06:17 +02:00
|
|
|
/* TODO(sergey): Does this really belong here? */
|
2018-09-25 10:32:34 +02:00
|
|
|
if (mesh->runtime.subdiv_ccg != NULL) {
|
|
|
|
|
BKE_subdiv_ccg_destroy(mesh->runtime.subdiv_ccg);
|
|
|
|
|
mesh->runtime.subdiv_ccg = NULL;
|
2018-09-06 17:06:17 +02:00
|
|
|
}
|
Shrinkwrap: new mode that projects along the target normal.
The Nearest Surface Point shrink method, while fast, is neither
smooth nor continuous: as the source point moves, the projected
point can both stop and jump. This causes distortions in the
deformation of the shrinkwrap modifier, and the motion of an
animated object with a shrinkwrap constraint.
This patch implements a new mode, which, instead of using the simple
nearest point search, iteratively solves an equation for each triangle
to find a point which has its interpolated normal point to or from the
original vertex. Non-manifold boundary edges are treated as infinitely
thin cylinders that cast normals in all perpendicular directions.
Since this is useful for the constraint, and having multiple
objects with constraints targeting the same guide mesh is a quite
reasonable use case, rather than calculating the mesh boundary edge
data over and over again, it is precomputed and cached in the mesh.
Reviewers: mont29
Differential Revision: https://developer.blender.org/D3836
2018-11-06 21:04:53 +03:00
|
|
|
BKE_shrinkwrap_discard_boundary_data(mesh);
|
2018-05-11 15:48:14 -03:00
|
|
|
}
|
|
|
|
|
|
2018-06-05 15:54:12 +02:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Mesh Batch Cache Callbacks
|
|
|
|
|
* \{ */
|
|
|
|
|
|
2018-05-11 15:48:14 -03:00
|
|
|
/* Draw Engine */
|
2020-10-09 07:27:18 +02:00
|
|
|
void (*BKE_mesh_batch_cache_dirty_tag_cb)(Mesh *me, eMeshBatchDirtyMode mode) = NULL;
|
2018-05-11 15:48:14 -03:00
|
|
|
void (*BKE_mesh_batch_cache_free_cb)(Mesh *me) = NULL;
|
|
|
|
|
|
2020-10-09 07:27:18 +02:00
|
|
|
void BKE_mesh_batch_cache_dirty_tag(Mesh *me, eMeshBatchDirtyMode mode)
|
2018-05-11 15:48:14 -03:00
|
|
|
{
|
|
|
|
|
if (me->runtime.batch_cache) {
|
2018-08-23 10:14:29 -03:00
|
|
|
BKE_mesh_batch_cache_dirty_tag_cb(me, mode);
|
2018-05-11 15:48:14 -03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void BKE_mesh_batch_cache_free(Mesh *me)
|
|
|
|
|
{
|
|
|
|
|
if (me->runtime.batch_cache) {
|
|
|
|
|
BKE_mesh_batch_cache_free_cb(me);
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-06-05 15:54:12 +02:00
|
|
|
|
|
|
|
|
/** \} */
|
2018-06-22 17:54:18 +02:00
|
|
|
|
2018-06-05 15:54:12 +02:00
|
|
|
/* -------------------------------------------------------------------- */
|
2021-12-14 15:49:31 +11:00
|
|
|
/** \name Mesh Runtime Debug Helpers
|
2018-06-22 17:54:18 +02:00
|
|
|
* \{ */
|
2021-12-14 15:49:31 +11:00
|
|
|
|
|
|
|
|
/* Evaluated mesh info printing function, to help track down differences output. */
|
2018-06-22 17:54:18 +02:00
|
|
|
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
|
# include "BLI_dynstr.h"
|
|
|
|
|
|
|
|
|
|
static void mesh_runtime_debug_info_layers(DynStr *dynstr, CustomData *cd)
|
|
|
|
|
{
|
|
|
|
|
int type;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-06-22 17:54:18 +02:00
|
|
|
for (type = 0; type < CD_NUMTYPES; type++) {
|
|
|
|
|
if (CustomData_has_layer(cd, type)) {
|
2021-07-03 23:08:40 +10:00
|
|
|
/* NOTE: doesn't account for multiple layers. */
|
2018-06-22 17:54:18 +02:00
|
|
|
const char *name = CustomData_layertype_name(type);
|
|
|
|
|
const int size = CustomData_sizeof(type);
|
|
|
|
|
const void *pt = CustomData_get_layer(cd, type);
|
|
|
|
|
const int pt_size = pt ? (int)(MEM_allocN_len(pt) / size) : 0;
|
|
|
|
|
const char *structname;
|
|
|
|
|
int structnum;
|
|
|
|
|
CustomData_file_write_info(type, &structname, &structnum);
|
2018-07-13 08:37:20 +02:00
|
|
|
BLI_dynstr_appendf(
|
|
|
|
|
dynstr,
|
|
|
|
|
" dict(name='%s', struct='%s', type=%d, ptr='%p', elem=%d, length=%d),\n",
|
|
|
|
|
name,
|
|
|
|
|
structname,
|
|
|
|
|
type,
|
|
|
|
|
(const void *)pt,
|
|
|
|
|
size,
|
|
|
|
|
pt_size);
|
2018-06-22 17:54:18 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char *BKE_mesh_runtime_debug_info(Mesh *me_eval)
|
|
|
|
|
{
|
|
|
|
|
DynStr *dynstr = BLI_dynstr_new();
|
|
|
|
|
char *ret;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-24 16:09:46 +11:00
|
|
|
BLI_dynstr_append(dynstr, "{\n");
|
2018-06-22 17:54:18 +02:00
|
|
|
BLI_dynstr_appendf(dynstr, " 'ptr': '%p',\n", (void *)me_eval);
|
|
|
|
|
# if 0
|
|
|
|
|
const char *tstr;
|
|
|
|
|
switch (me_eval->type) {
|
2019-04-17 08:50:46 +02:00
|
|
|
case DM_TYPE_CDDM:
|
|
|
|
|
tstr = "DM_TYPE_CDDM";
|
|
|
|
|
break;
|
|
|
|
|
case DM_TYPE_CCGDM:
|
|
|
|
|
tstr = "DM_TYPE_CCGDM";
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
tstr = "UNKNOWN";
|
|
|
|
|
break;
|
2018-06-22 17:54:18 +02:00
|
|
|
}
|
|
|
|
|
BLI_dynstr_appendf(dynstr, " 'type': '%s',\n", tstr);
|
|
|
|
|
# endif
|
|
|
|
|
BLI_dynstr_appendf(dynstr, " 'totvert': %d,\n", me_eval->totvert);
|
|
|
|
|
BLI_dynstr_appendf(dynstr, " 'totedge': %d,\n", me_eval->totedge);
|
|
|
|
|
BLI_dynstr_appendf(dynstr, " 'totface': %d,\n", me_eval->totface);
|
|
|
|
|
BLI_dynstr_appendf(dynstr, " 'totpoly': %d,\n", me_eval->totpoly);
|
|
|
|
|
BLI_dynstr_appendf(dynstr, " 'deformed_only': %d,\n", me_eval->runtime.deformed_only);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-24 16:09:46 +11:00
|
|
|
BLI_dynstr_append(dynstr, " 'vertexLayers': (\n");
|
2018-06-22 17:54:18 +02:00
|
|
|
mesh_runtime_debug_info_layers(dynstr, &me_eval->vdata);
|
2019-03-24 16:09:46 +11:00
|
|
|
BLI_dynstr_append(dynstr, " ),\n");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-24 16:09:46 +11:00
|
|
|
BLI_dynstr_append(dynstr, " 'edgeLayers': (\n");
|
2018-06-22 17:54:18 +02:00
|
|
|
mesh_runtime_debug_info_layers(dynstr, &me_eval->edata);
|
2019-03-24 16:09:46 +11:00
|
|
|
BLI_dynstr_append(dynstr, " ),\n");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-24 16:09:46 +11:00
|
|
|
BLI_dynstr_append(dynstr, " 'loopLayers': (\n");
|
2018-06-22 17:54:18 +02:00
|
|
|
mesh_runtime_debug_info_layers(dynstr, &me_eval->ldata);
|
2019-03-24 16:09:46 +11:00
|
|
|
BLI_dynstr_append(dynstr, " ),\n");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-24 16:09:46 +11:00
|
|
|
BLI_dynstr_append(dynstr, " 'polyLayers': (\n");
|
2018-06-22 17:54:18 +02:00
|
|
|
mesh_runtime_debug_info_layers(dynstr, &me_eval->pdata);
|
2019-03-24 16:09:46 +11:00
|
|
|
BLI_dynstr_append(dynstr, " ),\n");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-24 16:09:46 +11:00
|
|
|
BLI_dynstr_append(dynstr, " 'tessFaceLayers': (\n");
|
2018-06-22 17:54:18 +02:00
|
|
|
mesh_runtime_debug_info_layers(dynstr, &me_eval->fdata);
|
2019-03-24 16:09:46 +11:00
|
|
|
BLI_dynstr_append(dynstr, " ),\n");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-24 16:09:46 +11:00
|
|
|
BLI_dynstr_append(dynstr, "}\n");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-06-22 17:54:18 +02:00
|
|
|
ret = BLI_dynstr_get_cstring(dynstr);
|
|
|
|
|
BLI_dynstr_free(dynstr);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BKE_mesh_runtime_debug_print(Mesh *me_eval)
|
|
|
|
|
{
|
|
|
|
|
char *str = BKE_mesh_runtime_debug_info(me_eval);
|
|
|
|
|
puts(str);
|
|
|
|
|
fflush(stdout);
|
|
|
|
|
MEM_freeN(str);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BKE_mesh_runtime_debug_print_cdlayers(CustomData *data)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
const CustomDataLayer *layer;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-06-22 17:54:18 +02:00
|
|
|
printf("{\n");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-06-22 17:54:18 +02:00
|
|
|
for (i = 0, layer = data->layers; i < data->totlayer; i++, layer++) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-06-22 17:54:18 +02:00
|
|
|
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,
|
|
|
|
|
(const void *)layer->data,
|
|
|
|
|
size,
|
|
|
|
|
(int)(MEM_allocN_len(layer->data) / size));
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-06-22 17:54:18 +02:00
|
|
|
printf("}\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool BKE_mesh_runtime_is_valid(Mesh *me_eval)
|
|
|
|
|
{
|
|
|
|
|
const bool do_verbose = true;
|
|
|
|
|
const bool do_fixes = false;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-06-22 17:54:18 +02:00
|
|
|
bool is_valid = true;
|
|
|
|
|
bool changed = true;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-06-22 17:54:18 +02:00
|
|
|
if (do_verbose) {
|
|
|
|
|
printf("MESH: %s\n", me_eval->id.name + 2);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-06-22 17:54:18 +02:00
|
|
|
is_valid &= BKE_mesh_validate_all_customdata(
|
2018-12-03 16:19:08 +01:00
|
|
|
&me_eval->vdata,
|
|
|
|
|
me_eval->totvert,
|
|
|
|
|
&me_eval->edata,
|
|
|
|
|
me_eval->totedge,
|
|
|
|
|
&me_eval->ldata,
|
|
|
|
|
me_eval->totloop,
|
|
|
|
|
&me_eval->pdata,
|
|
|
|
|
me_eval->totpoly,
|
2018-07-13 08:37:20 +02:00
|
|
|
false, /* setting mask here isn't useful, gives false positives */
|
|
|
|
|
do_verbose,
|
|
|
|
|
do_fixes,
|
|
|
|
|
&changed);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-06-22 17:54:18 +02:00
|
|
|
is_valid &= BKE_mesh_validate_arrays(me_eval,
|
2018-07-13 08:37:20 +02:00
|
|
|
me_eval->mvert,
|
|
|
|
|
me_eval->totvert,
|
|
|
|
|
me_eval->medge,
|
|
|
|
|
me_eval->totedge,
|
|
|
|
|
me_eval->mface,
|
|
|
|
|
me_eval->totface,
|
|
|
|
|
me_eval->mloop,
|
|
|
|
|
me_eval->totloop,
|
|
|
|
|
me_eval->mpoly,
|
|
|
|
|
me_eval->totpoly,
|
|
|
|
|
me_eval->dvert,
|
|
|
|
|
do_verbose,
|
|
|
|
|
do_fixes,
|
|
|
|
|
&changed);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-06-22 17:54:18 +02:00
|
|
|
BLI_assert(changed == false);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-06-22 17:54:18 +02:00
|
|
|
return is_valid;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif /* NDEBUG */
|
|
|
|
|
|
|
|
|
|
/** \} */
|