Changeset View
Changeset View
Standalone View
Standalone View
source/blender/nodes/geometry/nodes/node_geo_attribute_randomize.cc
| Show First 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | |||||
| static void geo_node_attribute_randomize_update(bNodeTree *UNUSED(ntree), bNode *node) | static void geo_node_attribute_randomize_update(bNodeTree *UNUSED(ntree), bNode *node) | ||||
| { | { | ||||
| bNodeSocket *sock_min_vector = (bNodeSocket *)BLI_findlink(&node->inputs, 2); | bNodeSocket *sock_min_vector = (bNodeSocket *)BLI_findlink(&node->inputs, 2); | ||||
| bNodeSocket *sock_max_vector = sock_min_vector->next; | bNodeSocket *sock_max_vector = sock_min_vector->next; | ||||
| bNodeSocket *sock_min_float = sock_max_vector->next; | bNodeSocket *sock_min_float = sock_max_vector->next; | ||||
| bNodeSocket *sock_max_float = sock_min_float->next; | bNodeSocket *sock_max_float = sock_min_float->next; | ||||
| const int data_type = node->custom1; | const CustomDataType data_type = static_cast<CustomDataType>(node->custom1); | ||||
| nodeSetSocketAvailability(sock_min_vector, data_type == CD_PROP_FLOAT3); | nodeSetSocketAvailability(sock_min_vector, data_type == CD_PROP_FLOAT3); | ||||
| nodeSetSocketAvailability(sock_max_vector, data_type == CD_PROP_FLOAT3); | nodeSetSocketAvailability(sock_max_vector, data_type == CD_PROP_FLOAT3); | ||||
| nodeSetSocketAvailability(sock_min_float, data_type == CD_PROP_FLOAT); | nodeSetSocketAvailability(sock_min_float, data_type == CD_PROP_FLOAT); | ||||
| nodeSetSocketAvailability(sock_max_float, data_type == CD_PROP_FLOAT); | nodeSetSocketAvailability(sock_max_float, data_type == CD_PROP_FLOAT); | ||||
| } | } | ||||
| namespace blender::nodes { | namespace blender::nodes { | ||||
| Show All 18 Lines | static void randomize_attribute_bool(BooleanWriteAttribute attribute, | ||||
| MutableSpan<bool> attribute_span = attribute.get_span(); | MutableSpan<bool> attribute_span = attribute.get_span(); | ||||
| for (const int i : IndexRange(attribute.size())) { | for (const int i : IndexRange(attribute.size())) { | ||||
| const bool value = noise_from_index(seed, (int)hashes[i]) > 0.5f; | const bool value = noise_from_index(seed, (int)hashes[i]) > 0.5f; | ||||
| attribute_span[i] = value; | attribute_span[i] = value; | ||||
| } | } | ||||
| attribute.apply_span(); | attribute.apply_span(); | ||||
| } | } | ||||
| static void randomize_attribute_float( | static void randomize_attribute_float(FloatWriteAttribute attribute, | ||||
| FloatWriteAttribute attribute, float min, float max, Span<uint32_t> hashes, const int seed) | const float min, | ||||
| const float max, | |||||
| Span<uint32_t> hashes, | |||||
| const int seed) | |||||
| { | { | ||||
| MutableSpan<float> attribute_span = attribute.get_span(); | MutableSpan<float> attribute_span = attribute.get_span(); | ||||
| for (const int i : IndexRange(attribute.size())) { | for (const int i : IndexRange(attribute.size())) { | ||||
| const float value = noise_from_index(seed, (int)hashes[i]) * (max - min) + min; | const float value = noise_from_index(seed, (int)hashes[i]) * (max - min) + min; | ||||
| attribute_span[i] = value; | attribute_span[i] = value; | ||||
| } | } | ||||
| attribute.apply_span(); | attribute.apply_span(); | ||||
| } | } | ||||
| static void randomize_attribute_float3( | static void randomize_attribute_float3(Float3WriteAttribute attribute, | ||||
| Float3WriteAttribute attribute, float3 min, float3 max, Span<uint32_t> hashes, const int seed) | const float3 min, | ||||
| const float3 max, | |||||
| Span<uint32_t> hashes, | |||||
| const int seed) | |||||
| { | { | ||||
| MutableSpan<float3> attribute_span = attribute.get_span(); | MutableSpan<float3> attribute_span = attribute.get_span(); | ||||
| for (const int i : IndexRange(attribute.size())) { | for (const int i : IndexRange(attribute.size())) { | ||||
| const float x = noise_from_index_and_mutator(seed, (int)hashes[i], 47); | const float x = noise_from_index_and_mutator(seed, (int)hashes[i], 47); | ||||
| const float y = noise_from_index_and_mutator(seed, (int)hashes[i], 8); | const float y = noise_from_index_and_mutator(seed, (int)hashes[i], 8); | ||||
| const float z = noise_from_index_and_mutator(seed, (int)hashes[i], 64); | const float z = noise_from_index_and_mutator(seed, (int)hashes[i], 64); | ||||
| const float3 value = float3(x, y, z) * (max - min) + min; | const float3 value = float3(x, y, z) * (max - min) + min; | ||||
| attribute_span[i] = value; | attribute_span[i] = value; | ||||
| Show All 14 Lines | if (hash_attribute) { | ||||
| const CPPType &cpp_type = hash_attribute->cpp_type(); | const CPPType &cpp_type = hash_attribute->cpp_type(); | ||||
| fn::GSpan items = hash_attribute->get_span(); | fn::GSpan items = hash_attribute->get_span(); | ||||
| for (const int i : hashes.index_range()) { | for (const int i : hashes.index_range()) { | ||||
| hashes[i] = cpp_type.hash(items[i]); | hashes[i] = cpp_type.hash(items[i]); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| /* If there is no "id" attribute for per-point variation, just create it here. */ | /* If there is no "id" attribute for per-point variation, just create it here. */ | ||||
| RandomNumberGenerator rng; | RandomNumberGenerator rng(0); | ||||
| rng.seed(0); | |||||
| for (const int i : hashes.index_range()) { | for (const int i : hashes.index_range()) { | ||||
| hashes[i] = rng.get_uint32(); | hashes[i] = rng.get_uint32(); | ||||
| } | } | ||||
| } | } | ||||
| return hashes; | return hashes; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 74 Lines • Show Last 20 Lines | |||||