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:
authorJoseph Eagar <joeedh@gmail.com>2021-08-06 22:51:18 +0300
committerJoseph Eagar <joeedh@gmail.com>2021-08-06 22:51:18 +0300
commit8ed4c5fc61b6fd78dea219f62644faf7e05650bc (patch)
treee7416bb4f2d89aa10138fdd7b69f2abbc5d849bf /source/blender/modifiers/intern
parent76bd253be73370145404aa4e31139911d9afb579 (diff)
parent3fab16fe8eb4a99607e00d5716ba88bf24020354 (diff)
Merge branch 'master' into temp_bmesh_multires
Also fixed a pbvh corruption bug
Diffstat (limited to 'source/blender/modifiers/intern')
-rw-r--r--source/blender/modifiers/intern/MOD_laplaciansmooth.c24
-rw-r--r--source/blender/modifiers/intern/MOD_meshsequencecache.c63
-rw-r--r--source/blender/modifiers/intern/MOD_nodes.cc8
-rw-r--r--source/blender/modifiers/intern/MOD_nodes_evaluator.cc59
-rw-r--r--source/blender/modifiers/intern/MOD_nodes_evaluator.hh2
-rw-r--r--source/blender/modifiers/intern/MOD_ocean.c14
-rw-r--r--source/blender/modifiers/intern/MOD_remesh.c2
-rw-r--r--source/blender/modifiers/intern/MOD_solidify_nonmanifold.c13
8 files changed, 129 insertions, 56 deletions
diff --git a/source/blender/modifiers/intern/MOD_laplaciansmooth.c b/source/blender/modifiers/intern/MOD_laplaciansmooth.c
index 63495c4104e..a36a8c386b4 100644
--- a/source/blender/modifiers/intern/MOD_laplaciansmooth.c
+++ b/source/blender/modifiers/intern/MOD_laplaciansmooth.c
@@ -66,7 +66,7 @@ struct BLaplacianSystem {
int numVerts; /* Number of verts. */
short *numNeFa; /* Number of neighbors faces around vertice. */
short *numNeEd; /* Number of neighbors Edges around vertice. */
- short *zerola; /* Is zero area or length. */
+ bool *zerola; /* Is zero area or length. */
/* Pointers to data. */
float (*vertexCos)[3];
@@ -130,7 +130,7 @@ static void memset_laplacian_system(LaplacianSystem *sys, int val)
memset(sys->ring_areas, val, sizeof(float) * sys->numVerts);
memset(sys->vlengths, val, sizeof(float) * sys->numVerts);
memset(sys->vweights, val, sizeof(float) * sys->numVerts);
- memset(sys->zerola, val, sizeof(short) * sys->numVerts);
+ memset(sys->zerola, val, sizeof(bool) * sys->numVerts);
}
static LaplacianSystem *init_laplacian_system(int a_numEdges,
@@ -152,7 +152,7 @@ static LaplacianSystem *init_laplacian_system(int a_numEdges,
sys->ring_areas = MEM_calloc_arrayN(sys->numVerts, sizeof(float), __func__);
sys->vlengths = MEM_calloc_arrayN(sys->numVerts, sizeof(float), __func__);
sys->vweights = MEM_calloc_arrayN(sys->numVerts, sizeof(float), __func__);
- sys->zerola = MEM_calloc_arrayN(sys->numVerts, sizeof(short), __func__);
+ sys->zerola = MEM_calloc_arrayN(sys->numVerts, sizeof(bool), __func__);
return sys;
}
@@ -225,8 +225,8 @@ static void init_laplacian_matrix(LaplacianSystem *sys)
sys->numNeEd[idv2] = sys->numNeEd[idv2] + 1;
w1 = len_v3v3(v1, v2);
if (w1 < sys->min_area) {
- sys->zerola[idv1] = 1;
- sys->zerola[idv2] = 1;
+ sys->zerola[idv1] = true;
+ sys->zerola[idv2] = true;
}
else {
w1 = 1.0f / w1;
@@ -253,7 +253,7 @@ static void init_laplacian_matrix(LaplacianSystem *sys)
areaf = area_tri_v3(v_prev, v_curr, v_next);
if (areaf < sys->min_area) {
- sys->zerola[l_curr->v] = 1;
+ sys->zerola[l_curr->v] = true;
}
sys->ring_areas[l_prev->v] += areaf;
@@ -300,7 +300,7 @@ static void fill_laplacian_matrix(LaplacianSystem *sys)
const uint l_curr_index = l_curr - sys->mloop;
/* Is ring if number of faces == number of edges around vertice. */
- if (sys->numNeEd[l_curr->v] == sys->numNeFa[l_curr->v] && sys->zerola[l_curr->v] == 0) {
+ if (sys->numNeEd[l_curr->v] == sys->numNeFa[l_curr->v] && sys->zerola[l_curr->v] == false) {
EIG_linear_solver_matrix_add(sys->context,
l_curr->v,
l_next->v,
@@ -310,7 +310,7 @@ static void fill_laplacian_matrix(LaplacianSystem *sys)
l_prev->v,
sys->fweights[l_curr_index][1] * sys->vweights[l_curr->v]);
}
- if (sys->numNeEd[l_next->v] == sys->numNeFa[l_next->v] && sys->zerola[l_next->v] == 0) {
+ if (sys->numNeEd[l_next->v] == sys->numNeFa[l_next->v] && sys->zerola[l_next->v] == false) {
EIG_linear_solver_matrix_add(sys->context,
l_next->v,
l_curr->v,
@@ -320,7 +320,7 @@ static void fill_laplacian_matrix(LaplacianSystem *sys)
l_prev->v,
sys->fweights[l_curr_index][0] * sys->vweights[l_next->v]);
}
- if (sys->numNeEd[l_prev->v] == sys->numNeFa[l_prev->v] && sys->zerola[l_prev->v] == 0) {
+ if (sys->numNeEd[l_prev->v] == sys->numNeFa[l_prev->v] && sys->zerola[l_prev->v] == false) {
EIG_linear_solver_matrix_add(sys->context,
l_prev->v,
l_curr->v,
@@ -338,7 +338,7 @@ static void fill_laplacian_matrix(LaplacianSystem *sys)
idv2 = sys->medges[i].v2;
/* Is boundary */
if (sys->numNeEd[idv1] != sys->numNeFa[idv1] && sys->numNeEd[idv2] != sys->numNeFa[idv2] &&
- sys->zerola[idv1] == 0 && sys->zerola[idv2] == 0) {
+ sys->zerola[idv1] == false && sys->zerola[idv2] == false) {
EIG_linear_solver_matrix_add(
sys->context, idv1, idv2, sys->eweights[i] * sys->vlengths[idv1]);
EIG_linear_solver_matrix_add(
@@ -358,7 +358,7 @@ static void validate_solution(LaplacianSystem *sys, short flag, float lambda, fl
sys->vert_centroid, sys->vertexCos, sys->mpoly, sys->numPolys, sys->mloop);
}
for (i = 0; i < sys->numVerts; i++) {
- if (sys->zerola[i] == 0) {
+ if (sys->zerola[i] == false) {
lam = sys->numNeEd[i] == sys->numNeFa[i] ? (lambda >= 0.0f ? 1.0f : -1.0f) :
(lambda_border >= 0.0f ? 1.0f : -1.0f);
if (flag & MOD_LAPLACIANSMOOTH_X) {
@@ -442,7 +442,7 @@ static void laplaciansmoothModifier_do(
wpaint = 1.0f;
}
- if (sys->zerola[i] == 0) {
+ if (sys->zerola[i] == false) {
if (smd->flag & MOD_LAPLACIANSMOOTH_NORMALIZED) {
w = sys->vweights[i];
sys->vweights[i] = (w == 0.0f) ? 0.0f : -fabsf(smd->lambda) * wpaint / w;
diff --git a/source/blender/modifiers/intern/MOD_meshsequencecache.c b/source/blender/modifiers/intern/MOD_meshsequencecache.c
index c2f9cd8c867..3e6081e0a18 100644
--- a/source/blender/modifiers/intern/MOD_meshsequencecache.c
+++ b/source/blender/modifiers/intern/MOD_meshsequencecache.c
@@ -55,18 +55,29 @@
#include "MOD_modifiertypes.h"
#include "MOD_ui_common.h"
-#ifdef WITH_ALEMBIC
-# include "ABC_alembic.h"
+#if defined(WITH_USD) || defined(WITH_ALEMBIC)
# include "BKE_global.h"
# include "BKE_lib_id.h"
#endif
+#ifdef WITH_ALEMBIC
+# include "ABC_alembic.h"
+#endif
+
+#ifdef WITH_USD
+# include "usd.h"
+#endif
+
static void initData(ModifierData *md)
{
MeshSeqCacheModifierData *mcmd = (MeshSeqCacheModifierData *)md;
BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(mcmd, modifier));
+ mcmd->cache_file = NULL;
+ mcmd->object_path[0] = '\0';
+ mcmd->read_flag = MOD_MESHSEQ_READ_ALL;
+
MEMCPY_STRUCT_AFTER(mcmd, DNA_struct_default_get(MeshSeqCacheModifierData), modifier);
}
@@ -109,7 +120,7 @@ static bool isDisabled(const struct Scene *UNUSED(scene),
static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh)
{
-#ifdef WITH_ALEMBIC
+#if defined(WITH_USD) || defined(WITH_ALEMBIC)
MeshSeqCacheModifierData *mcmd = (MeshSeqCacheModifierData *)md;
/* Only used to check whether we are operating on org data or not... */
@@ -127,16 +138,32 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
BKE_cachefile_reader_open(cache_file, &mcmd->reader, ctx->object, mcmd->object_path);
if (!mcmd->reader) {
BKE_modifier_set_error(
- ctx->object, md, "Could not create Alembic reader for file %s", cache_file->filepath);
+ ctx->object, md, "Could not create reader for file %s", cache_file->filepath);
return mesh;
}
}
- /* If this invocation is for the ORCO mesh, and the mesh in Alembic hasn't changed topology, we
+ /* If this invocation is for the ORCO mesh, and the mesh hasn't changed topology, we
* must return the mesh as-is instead of deforming it. */
- if (ctx->flag & MOD_APPLY_ORCO &&
- !ABC_mesh_topology_changed(mcmd->reader, ctx->object, mesh, time, &err_str)) {
- return mesh;
+ if (ctx->flag & MOD_APPLY_ORCO) {
+ switch (cache_file->type) {
+ case CACHEFILE_TYPE_ALEMBIC:
+# ifdef WITH_ALEMBIC
+ if (!ABC_mesh_topology_changed(mcmd->reader, ctx->object, mesh, time, &err_str)) {
+ return mesh;
+ }
+# endif
+ break;
+ case CACHEFILE_TYPE_USD:
+# ifdef WITH_USD
+ if (!USD_mesh_topology_changed(mcmd->reader, ctx->object, mesh, time, &err_str)) {
+ return mesh;
+ }
+# endif
+ break;
+ case CACHE_FILE_TYPE_INVALID:
+ break;
+ }
}
if (me != NULL) {
@@ -156,7 +183,23 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
}
}
- Mesh *result = ABC_read_mesh(mcmd->reader, ctx->object, mesh, time, &err_str, mcmd->read_flag);
+ Mesh *result = NULL;
+
+ switch (cache_file->type) {
+ case CACHEFILE_TYPE_ALEMBIC:
+# ifdef WITH_ALEMBIC
+ result = ABC_read_mesh(mcmd->reader, ctx->object, mesh, time, &err_str, mcmd->read_flag);
+# endif
+ break;
+ case CACHEFILE_TYPE_USD:
+# ifdef WITH_USD
+ result = USD_read_mesh(
+ mcmd->reader, ctx->object, mesh, time * FPS, &err_str, mcmd->read_flag);
+# endif
+ break;
+ case CACHE_FILE_TYPE_INVALID:
+ break;
+ }
mcmd->velocity_delta = 1.0f;
if (mcmd->cache_file->velocity_unit == CACHEFILE_VELOCITY_UNIT_SECOND) {
@@ -187,7 +230,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *
static bool dependsOnTime(ModifierData *md)
{
-#ifdef WITH_ALEMBIC
+#if defined(WITH_USD) || defined(WITH_ALEMBIC)
MeshSeqCacheModifierData *mcmd = (MeshSeqCacheModifierData *)md;
return (mcmd->cache_file != NULL);
#else
diff --git a/source/blender/modifiers/intern/MOD_nodes.cc b/source/blender/modifiers/intern/MOD_nodes.cc
index 5fa11ffdd10..3853b345c14 100644
--- a/source/blender/modifiers/intern/MOD_nodes.cc
+++ b/source/blender/modifiers/intern/MOD_nodes.cc
@@ -721,17 +721,17 @@ static void initialize_group_input(NodesModifierData &nmd,
return;
}
if (nmd.settings.properties == nullptr) {
- blender::nodes::socket_cpp_value_get(socket, r_value);
+ socket.typeinfo->get_geometry_nodes_cpp_value(socket, r_value);
return;
}
const IDProperty *property = IDP_GetPropertyFromGroup(nmd.settings.properties,
socket.identifier);
if (property == nullptr) {
- blender::nodes::socket_cpp_value_get(socket, r_value);
+ socket.typeinfo->get_geometry_nodes_cpp_value(socket, r_value);
return;
}
if (!property_type->is_correct_type(*property)) {
- blender::nodes::socket_cpp_value_get(socket, r_value);
+ socket.typeinfo->get_geometry_nodes_cpp_value(socket, r_value);
return;
}
property_type->init_cpp_value(*property, r_value);
@@ -883,7 +883,7 @@ static GeometrySet compute_geometry(const DerivedNodeTree &tree,
/* Initialize remaining group inputs. */
for (const OutputSocketRef *socket : remaining_input_sockets) {
- const CPPType &cpp_type = *blender::nodes::socket_cpp_type_get(*socket->typeinfo());
+ const CPPType &cpp_type = *socket->typeinfo()->get_geometry_nodes_cpp_type();
void *value_in = allocator.allocate(cpp_type.size(), cpp_type.alignment());
initialize_group_input(*nmd, *socket->bsocket(), cpp_type, value_in);
group_inputs.add_new({root_context, socket}, {cpp_type, value_in});
diff --git a/source/blender/modifiers/intern/MOD_nodes_evaluator.cc b/source/blender/modifiers/intern/MOD_nodes_evaluator.cc
index e652eb8353d..47dfd9bc8f6 100644
--- a/source/blender/modifiers/intern/MOD_nodes_evaluator.cc
+++ b/source/blender/modifiers/intern/MOD_nodes_evaluator.cc
@@ -10,7 +10,7 @@
* 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,
+ * along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
@@ -294,7 +294,11 @@ class LockedNode : NonCopyable, NonMovable {
static const CPPType *get_socket_cpp_type(const SocketRef &socket)
{
- const CPPType *type = nodes::socket_cpp_type_get(*socket.typeinfo());
+ const bNodeSocketType *typeinfo = socket.typeinfo();
+ if (typeinfo->get_geometry_nodes_cpp_type == nullptr) {
+ return nullptr;
+ }
+ const CPPType *type = typeinfo->get_geometry_nodes_cpp_type();
if (type == nullptr) {
return nullptr;
}
@@ -310,6 +314,12 @@ static const CPPType *get_socket_cpp_type(const DSocket socket)
return get_socket_cpp_type(*socket.socket_ref());
}
+static void get_socket_value(const SocketRef &socket, void *r_value)
+{
+ const bNodeSocketType *typeinfo = socket.typeinfo();
+ typeinfo->get_geometry_nodes_cpp_value(*socket.bsocket(), r_value);
+}
+
static bool node_supports_laziness(const DNode node)
{
return node->typeinfo()->geometry_node_execute_supports_laziness;
@@ -1235,14 +1245,8 @@ class GeometryNodesEvaluator {
void *buffer = allocator.allocate(to_type.size(), to_type.alignment());
GMutablePointer value{to_type, buffer};
- if (conversions_.is_convertible(from_type, to_type)) {
- /* Do the conversion if possible. */
- conversions_.convert_to_uninitialized(from_type, to_type, value_to_forward.get(), buffer);
- }
- else {
- /* Cannot convert, use default value instead. */
- to_type.copy_construct(to_type.default_value(), buffer);
- }
+ this->convert_value(from_type, to_type, value_to_forward.get(), buffer);
+
/* Multi input socket values are logged once all values are available. */
if (!to_socket->is_multi_input_socket()) {
this->log_socket_value({to_socket}, value);
@@ -1363,25 +1367,36 @@ class GeometryNodesEvaluator {
{
LinearAllocator<> &allocator = local_allocators_.local();
- bNodeSocket *bsocket = socket->bsocket();
const CPPType &type = *get_socket_cpp_type(socket);
void *buffer = allocator.allocate(type.size(), type.alignment());
- blender::nodes::socket_cpp_value_get(*bsocket, buffer);
+ get_socket_value(*socket.socket_ref(), buffer);
if (type == required_type) {
return {type, buffer};
}
- if (conversions_.is_convertible(type, required_type)) {
- /* Convert the loaded value to the required type if possible. */
- void *converted_buffer = allocator.allocate(required_type.size(), required_type.alignment());
- conversions_.convert_to_uninitialized(type, required_type, buffer, converted_buffer);
- type.destruct(buffer);
- return {required_type, converted_buffer};
+ void *converted_buffer = allocator.allocate(required_type.size(), required_type.alignment());
+ this->convert_value(type, required_type, buffer, converted_buffer);
+ return {required_type, converted_buffer};
+ }
+
+ void convert_value(const CPPType &from_type,
+ const CPPType &to_type,
+ const void *from_value,
+ void *to_value)
+ {
+ if (from_type == to_type) {
+ from_type.copy_construct(from_value, to_value);
+ return;
+ }
+
+ if (conversions_.is_convertible(from_type, to_type)) {
+ /* Do the conversion if possible. */
+ conversions_.convert_to_uninitialized(from_type, to_type, from_value, to_value);
+ }
+ else {
+ /* Cannot convert, use default value instead. */
+ to_type.copy_construct(to_type.default_value(), to_value);
}
- /* Use a default fallback value when the loaded type is not compatible. */
- void *default_buffer = allocator.allocate(required_type.size(), required_type.alignment());
- required_type.copy_construct(required_type.default_value(), default_buffer);
- return {required_type, default_buffer};
}
NodeState &get_node_state(const DNode node)
diff --git a/source/blender/modifiers/intern/MOD_nodes_evaluator.hh b/source/blender/modifiers/intern/MOD_nodes_evaluator.hh
index f4ee6242dcb..d8c60d31986 100644
--- a/source/blender/modifiers/intern/MOD_nodes_evaluator.hh
+++ b/source/blender/modifiers/intern/MOD_nodes_evaluator.hh
@@ -10,7 +10,7 @@
* 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,
+ * along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
diff --git a/source/blender/modifiers/intern/MOD_ocean.c b/source/blender/modifiers/intern/MOD_ocean.c
index 8f3206da5be..1c502b94bdb 100644
--- a/source/blender/modifiers/intern/MOD_ocean.c
+++ b/source/blender/modifiers/intern/MOD_ocean.c
@@ -95,8 +95,9 @@ static void initData(ModifierData *md)
BKE_modifier_path_init(omd->cachepath, sizeof(omd->cachepath), "cache_ocean");
omd->ocean = BKE_ocean_add();
- BKE_ocean_init_from_modifier(omd->ocean, omd, omd->viewport_resolution);
- simulate_ocean_modifier(omd);
+ if (BKE_ocean_init_from_modifier(omd->ocean, omd, omd->viewport_resolution)) {
+ simulate_ocean_modifier(omd);
+ }
#else /* WITH_OCEANSIM */
UNUSED_VARS(md);
#endif /* WITH_OCEANSIM */
@@ -132,8 +133,9 @@ static void copyData(const ModifierData *md, ModifierData *target, const int fla
tomd->oceancache = NULL;
tomd->ocean = BKE_ocean_add();
- BKE_ocean_init_from_modifier(tomd->ocean, tomd, tomd->viewport_resolution);
- simulate_ocean_modifier(tomd);
+ if (BKE_ocean_init_from_modifier(tomd->ocean, tomd, tomd->viewport_resolution)) {
+ simulate_ocean_modifier(tomd);
+ }
#else /* WITH_OCEANSIM */
/* unused */
(void)md;
@@ -323,6 +325,10 @@ static Mesh *generate_ocean_geometry(OceanModifierData *omd, Mesh *mesh_orig, co
static Mesh *doOcean(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh)
{
OceanModifierData *omd = (OceanModifierData *)md;
+ if (omd->ocean && !BKE_ocean_is_valid(omd->ocean)) {
+ BKE_modifier_set_error(ctx->object, md, "Failed to allocate memory");
+ return mesh;
+ }
int cfra_scene = (int)DEG_get_ctime(ctx->depsgraph);
Object *ob = ctx->object;
bool allocated_ocean = false;
diff --git a/source/blender/modifiers/intern/MOD_remesh.c b/source/blender/modifiers/intern/MOD_remesh.c
index 4677a9bc253..df3db894f4e 100644
--- a/source/blender/modifiers/intern/MOD_remesh.c
+++ b/source/blender/modifiers/intern/MOD_remesh.c
@@ -159,7 +159,7 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *UNUSED(ctx)
if (rmd->voxel_size == 0.0f) {
return NULL;
}
- result = BKE_mesh_remesh_voxel_to_mesh_nomain(mesh, rmd->voxel_size, rmd->adaptivity, 0.0f);
+ result = BKE_mesh_remesh_voxel(mesh, rmd->voxel_size, rmd->adaptivity, 0.0f);
if (result == NULL) {
return NULL;
}
diff --git a/source/blender/modifiers/intern/MOD_solidify_nonmanifold.c b/source/blender/modifiers/intern/MOD_solidify_nonmanifold.c
index b872f04b60f..18d308e5f02 100644
--- a/source/blender/modifiers/intern/MOD_solidify_nonmanifold.c
+++ b/source/blender/modifiers/intern/MOD_solidify_nonmanifold.c
@@ -71,6 +71,15 @@ static float angle_signed_on_axis_normalized_v3v3_v3(const float n[3],
return angle;
}
+static float clamp_nonzero(const float value, const float epsilon)
+{
+ BLI_assert(!(epsilon < 0.0f));
+ if (value < 0.0f) {
+ return min_ff(value, -epsilon);
+ }
+ return max_ff(value, epsilon);
+}
+
/** \} */
/* -------------------------------------------------------------------- */
@@ -164,8 +173,8 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md,
const float ofs_front = (smd->offset_fac + 1.0f) * 0.5f * smd->offset;
const float ofs_back = ofs_front - smd->offset * smd->offset_fac;
- const float ofs_front_clamped = max_ff(1e-5f, fabsf(smd->offset > 0 ? ofs_front : ofs_back));
- const float ofs_back_clamped = max_ff(1e-5f, fabsf(smd->offset > 0 ? ofs_back : ofs_front));
+ const float ofs_front_clamped = clamp_nonzero(smd->offset > 0 ? ofs_front : ofs_back, 1e-5f);
+ const float ofs_back_clamped = clamp_nonzero(smd->offset > 0 ? ofs_back : ofs_front, 1e-5f);
const float offset_fac_vg = smd->offset_fac_vg;
const float offset_fac_vg_inv = 1.0f - smd->offset_fac_vg;
const float offset = fabsf(smd->offset) * smd->offset_clamp;