[Bf-blender-cvs] [182a56e3b00] functions: improve SurfaceLocations members
Jacques Lucke
noreply at git.blender.org
Wed Dec 4 14:28:13 CET 2019
Commit: 182a56e3b002406b42e1031cded6dcbb2bf6aacf
Author: Jacques Lucke
Date: Wed Dec 4 12:17:22 2019 +0100
Branches: functions
https://developer.blender.org/rB182a56e3b002406b42e1031cded6dcbb2bf6aacf
improve SurfaceLocations members
===================================================================
M source/blender/blenkernel/BKE_surface_location.h
M source/blender/functions/FN_multi_function_common_contexts.h
M source/blender/functions/intern/multi_functions/mixed.cc
M source/blender/simulations/bparticles/node_frontend.cpp
===================================================================
diff --git a/source/blender/blenkernel/BKE_surface_location.h b/source/blender/blenkernel/BKE_surface_location.h
index 53d69fdf79f..217c8579f1e 100644
--- a/source/blender/blenkernel/BKE_surface_location.h
+++ b/source/blender/blenkernel/BKE_surface_location.h
@@ -12,6 +12,13 @@ namespace BKE {
using BLI::float3;
+namespace SurfaceLocationType {
+enum Enum {
+ None,
+ MeshObject,
+};
+}
+
/**
* References a point on a surface. If the surface moves, the point moves with it. The surface is
* identified by an integer.
@@ -20,11 +27,13 @@ using BLI::float3;
*/
class SurfaceLocation {
private:
+ SurfaceLocationType::Enum m_type;
+
/**
- * Identifies the surface that is being referenced. This is usually a hash of the name of an
- * object. The location is invalid, if this id is negative.
+ * Identifies the surface that is being referenced. This can e.g. be a hash of the name of an
+ * object.
*/
- int32_t m_surface_id;
+ uint32_t m_surface_id;
/* Index of the triangle that contains the referenced location. */
uint32_t m_triangle_index;
@@ -33,41 +42,51 @@ class SurfaceLocation {
float3 m_bary_coords;
public:
- SurfaceLocation() : m_surface_id(-1)
+ SurfaceLocation() : m_type(SurfaceLocationType::None)
+ {
+ }
+
+ SurfaceLocation(uint32_t surface_id, uint32_t triangle_index, float3 bary_coords)
+ : m_type(SurfaceLocationType::MeshObject),
+ m_surface_id(surface_id),
+ m_triangle_index(triangle_index),
+ m_bary_coords(bary_coords)
+ {
+ }
+
+ SurfaceLocationType::Enum type() const
{
+ return m_type;
}
- SurfaceLocation(int32_t surface_id, uint32_t triangle_index, float3 bary_coords)
- : m_surface_id(surface_id), m_triangle_index(triangle_index), m_bary_coords(bary_coords)
+ bool is_valid() const
{
+ return m_type != SurfaceLocationType::None;
}
- int32_t surface_id() const
+ uint32_t surface_id() const
{
+ BLI_assert(this->is_valid());
return m_surface_id;
}
uint32_t triangle_index() const
{
+ BLI_assert(m_type == SurfaceLocationType::MeshObject);
return m_triangle_index;
}
float3 bary_coords() const
{
+ BLI_assert(m_type == SurfaceLocationType::MeshObject);
return m_bary_coords;
}
- bool is_valid() const
- {
- return m_surface_id >= 0;
- }
-
- static int32_t ComputeObjectSurfaceID(const Object *ob)
+ static uint32_t ComputeObjectSurfaceID(const Object *ob)
{
BLI_assert(ob != nullptr);
- /* Set the highest bit to zero, to make the number positive. */
- return BLI_hash_string(ob->id.name) & ~(1 << 31);
+ return BLI_hash_string(ob->id.name);
}
};
diff --git a/source/blender/functions/FN_multi_function_common_contexts.h b/source/blender/functions/FN_multi_function_common_contexts.h
index 963d43b849f..b2a749867b5 100644
--- a/source/blender/functions/FN_multi_function_common_contexts.h
+++ b/source/blender/functions/FN_multi_function_common_contexts.h
@@ -42,15 +42,15 @@ class ParticleAttributesContext : public MFElementContext {
class PersistentSurfacesLookupContext : public MFElementContext {
private:
- Map<int32_t, Object *> m_object_by_id;
+ Map<uint32_t, Object *> m_object_by_id;
public:
- PersistentSurfacesLookupContext(Map<int32_t, Object *> object_by_id)
+ PersistentSurfacesLookupContext(Map<uint32_t, Object *> object_by_id)
: m_object_by_id(object_by_id)
{
}
- Object *lookup(int32_t id) const
+ Object *lookup(uint32_t id) const
{
return m_object_by_id.lookup_default(id, nullptr);
}
diff --git a/source/blender/functions/intern/multi_functions/mixed.cc b/source/blender/functions/intern/multi_functions/mixed.cc
index 5d89ff100d3..c63fa8aeaab 100644
--- a/source/blender/functions/intern/multi_functions/mixed.cc
+++ b/source/blender/functions/intern/multi_functions/mixed.cc
@@ -297,12 +297,12 @@ void MF_GetPositionOnSurface::call(MFMask mask, MFParams params, MFContext conte
for (uint i : mask.indices()) {
SurfaceLocation location = locations[i];
- if (!location.is_valid()) {
+ if (location.type() != BKE::SurfaceLocationType::MeshObject) {
r_positions[i] = {0, 0, 0};
continue;
}
- Object *object = persistent_surfaces_opt->data->lookup((uint32_t)location.surface_id());
+ Object *object = persistent_surfaces_opt->data->lookup(location.surface_id());
if (object == nullptr) {
r_positions[i] = {0, 0, 0};
continue;
@@ -360,12 +360,12 @@ void MF_GetNormalOnSurface::call(MFMask mask, MFParams params, MFContext context
for (uint i : mask.indices()) {
SurfaceLocation location = locations[i];
- if (!location.is_valid()) {
+ if (location.type() != BKE::SurfaceLocationType::MeshObject) {
r_normals[i] = {0, 0, 1};
continue;
}
- Object *object = persistent_surfaces_opt->data->lookup((uint32_t)location.surface_id());
+ Object *object = persistent_surfaces_opt->data->lookup(location.surface_id());
if (object == nullptr) {
r_normals[i] = {0, 0, 1};
continue;
@@ -418,7 +418,7 @@ void MF_GetWeightOnSurface::call(MFMask mask, MFParams params, MFContext context
for (uint i : mask.indices()) {
SurfaceLocation location = locations[i];
- if (!location.is_valid()) {
+ if (location.type() != BKE::SurfaceLocationType::MeshObject) {
r_weights[i] = 0.0f;
continue;
}
@@ -486,7 +486,7 @@ static void get_colors_on_surface(MFMask mask,
for (uint i : mask.indices()) {
SurfaceLocation location = locations[i];
- if (!location.is_valid()) {
+ if (location.type() != BKE::SurfaceLocationType::MeshObject) {
r_colors[i] = default_color;
continue;
}
@@ -981,7 +981,7 @@ void MF_ClosestLocationOnObject::call(MFMask mask, MFParams params, MFContext co
Mesh *mesh = (Mesh *)object->data;
const MLoopTri *triangles = BKE_mesh_runtime_looptri_ensure(mesh);
- int32_t object_surface_id = SurfaceLocation::ComputeObjectSurfaceID(object);
+ uint32_t object_surface_id = SurfaceLocation::ComputeObjectSurfaceID(object);
float4x4 global_to_local = float4x4(object->obmat).inverted__LocRotScale();
diff --git a/source/blender/simulations/bparticles/node_frontend.cpp b/source/blender/simulations/bparticles/node_frontend.cpp
index c42213fe3ae..056218243a0 100644
--- a/source/blender/simulations/bparticles/node_frontend.cpp
+++ b/source/blender/simulations/bparticles/node_frontend.cpp
@@ -97,9 +97,9 @@ class VTreeData {
: m_inlined_tree_data_graph(inlined_tree_data), m_persistent_surface_lookup({})
{
Set<Object *> objects = get_used_objects(inlined_tree_data.inlined_tree());
- Map<int32_t, Object *> object_by_id;
+ Map<uint32_t, Object *> object_by_id;
for (Object *ob : objects) {
- int32_t surface_id = BKE::SurfaceLocation::ComputeObjectSurfaceID(ob);
+ uint32_t surface_id = BKE::SurfaceLocation::ComputeObjectSurfaceID(ob);
object_by_id.add_new(surface_id, ob);
}
m_persistent_surface_lookup.~PersistentSurfacesLookupContext();
More information about the Bf-blender-cvs
mailing list