Changeset View
Changeset View
Standalone View
Standalone View
source/blender/nodes/geometry/nodes/node_geo_point_instance.cc
| Show First 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | |||||
| namespace blender::nodes { | namespace blender::nodes { | ||||
| static void geo_node_point_instance_update(bNodeTree *UNUSED(tree), bNode *node) | static void geo_node_point_instance_update(bNodeTree *UNUSED(tree), bNode *node) | ||||
| { | { | ||||
| bNodeSocket *object_socket = (bNodeSocket *)BLI_findlink(&node->inputs, 1); | bNodeSocket *object_socket = (bNodeSocket *)BLI_findlink(&node->inputs, 1); | ||||
| bNodeSocket *collection_socket = object_socket->next; | bNodeSocket *collection_socket = object_socket->next; | ||||
| bNodeSocket *seed_socket = collection_socket->next; | bNodeSocket *seed_socket = collection_socket->next; | ||||
| GeometryNodePointInstanceType type = (GeometryNodePointInstanceType)node->custom1; | NodeGeometryPointInstance *node_storage = (NodeGeometryPointInstance *)node->storage; | ||||
| const bool use_whole_collection = node->custom2 == 0; | GeometryNodePointInstanceType type = (GeometryNodePointInstanceType)node_storage->instance_type; | ||||
| const bool use_whole_collection = (node_storage->flag & | |||||
| GEO_NODE_POINT_INSTANCE_WHOLE_COLLECTION) != 0; | |||||
| nodeSetSocketAvailability(object_socket, type == GEO_NODE_POINT_INSTANCE_TYPE_OBJECT); | nodeSetSocketAvailability(object_socket, type == GEO_NODE_POINT_INSTANCE_TYPE_OBJECT); | ||||
| nodeSetSocketAvailability(collection_socket, type == GEO_NODE_POINT_INSTANCE_TYPE_COLLECTION); | nodeSetSocketAvailability(collection_socket, type == GEO_NODE_POINT_INSTANCE_TYPE_COLLECTION); | ||||
| nodeSetSocketAvailability( | nodeSetSocketAvailability( | ||||
| seed_socket, type == GEO_NODE_POINT_INSTANCE_TYPE_COLLECTION && !use_whole_collection); | seed_socket, type == GEO_NODE_POINT_INSTANCE_TYPE_COLLECTION && !use_whole_collection); | ||||
| } | } | ||||
| static void get_instanced_data__object(const GeoNodeExecParams ¶ms, | static void get_instanced_data__object(const GeoNodeExecParams ¶ms, | ||||
| Show All 14 Lines | |||||
| } | } | ||||
| static void get_instanced_data__collection( | static void get_instanced_data__collection( | ||||
| const GeoNodeExecParams ¶ms, | const GeoNodeExecParams ¶ms, | ||||
| const GeometryComponent &component, | const GeometryComponent &component, | ||||
| MutableSpan<std::optional<InstancedData>> r_instances_data) | MutableSpan<std::optional<InstancedData>> r_instances_data) | ||||
| { | { | ||||
| const bNode &node = params.node(); | const bNode &node = params.node(); | ||||
| NodeGeometryPointInstance *node_storage = (NodeGeometryPointInstance *)node.storage; | |||||
| bke::PersistentCollectionHandle collection_handle = | bke::PersistentCollectionHandle collection_handle = | ||||
| params.get_input<bke::PersistentCollectionHandle>("Collection"); | params.get_input<bke::PersistentCollectionHandle>("Collection"); | ||||
| Collection *collection = params.handle_map().lookup(collection_handle); | Collection *collection = params.handle_map().lookup(collection_handle); | ||||
| if (collection == nullptr) { | if (collection == nullptr) { | ||||
| return; | return; | ||||
| } | } | ||||
| const bool use_whole_collection = node.custom2 == 0; | const bool use_whole_collection = (node_storage->flag & | ||||
| GEO_NODE_POINT_INSTANCE_WHOLE_COLLECTION) != 0; | |||||
| if (use_whole_collection) { | if (use_whole_collection) { | ||||
| InstancedData instance; | InstancedData instance; | ||||
| instance.type = INSTANCE_DATA_TYPE_COLLECTION; | instance.type = INSTANCE_DATA_TYPE_COLLECTION; | ||||
| instance.data.collection = collection; | instance.data.collection = collection; | ||||
| r_instances_data.fill(instance); | r_instances_data.fill(instance); | ||||
| } | } | ||||
| else { | else { | ||||
| Vector<InstancedData> possible_instances; | Vector<InstancedData> possible_instances; | ||||
| Show All 25 Lines | static void get_instanced_data__collection( | ||||
| } | } | ||||
| } | } | ||||
| static Array<std::optional<InstancedData>> get_instanced_data(const GeoNodeExecParams ¶ms, | static Array<std::optional<InstancedData>> get_instanced_data(const GeoNodeExecParams ¶ms, | ||||
| const GeometryComponent &component, | const GeometryComponent &component, | ||||
| const int amount) | const int amount) | ||||
| { | { | ||||
| const bNode &node = params.node(); | const bNode &node = params.node(); | ||||
| const GeometryNodePointInstanceType type = (GeometryNodePointInstanceType)node.custom1; | NodeGeometryPointInstance *node_storage = (NodeGeometryPointInstance *)node.storage; | ||||
| const GeometryNodePointInstanceType type = (GeometryNodePointInstanceType) | |||||
| node_storage->instance_type; | |||||
| Array<std::optional<InstancedData>> instances_data(amount); | Array<std::optional<InstancedData>> instances_data(amount); | ||||
| switch (type) { | switch (type) { | ||||
| case GEO_NODE_POINT_INSTANCE_TYPE_OBJECT: { | case GEO_NODE_POINT_INSTANCE_TYPE_OBJECT: { | ||||
| get_instanced_data__object(params, instances_data); | get_instanced_data__object(params, instances_data); | ||||
| break; | break; | ||||
| } | } | ||||
| case GEO_NODE_POINT_INSTANCE_TYPE_COLLECTION: { | case GEO_NODE_POINT_INSTANCE_TYPE_COLLECTION: { | ||||
| ▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | static void geo_node_point_instance_exec(GeoNodeExecParams params) | ||||
| } | } | ||||
| if (geometry_set.has<PointCloudComponent>()) { | if (geometry_set.has<PointCloudComponent>()) { | ||||
| add_instances_from_geometry_component( | add_instances_from_geometry_component( | ||||
| instances, *geometry_set.get_component_for_read<PointCloudComponent>(), params); | instances, *geometry_set.get_component_for_read<PointCloudComponent>(), params); | ||||
| } | } | ||||
| params.set_output("Geometry", std::move(geometry_set_out)); | params.set_output("Geometry", std::move(geometry_set_out)); | ||||
| } | } | ||||
| static void geo_node_point_instance_init(bNodeTree *UNUSED(tree), bNode *node) | |||||
| { | |||||
| NodeGeometryPointInstance *data = (NodeGeometryPointInstance *)MEM_callocN( | |||||
| sizeof(NodeGeometryPointInstance), __func__); | |||||
| data->instance_type = GEO_NODE_POINT_INSTANCE_TYPE_OBJECT; | |||||
| data->flag |= GEO_NODE_POINT_INSTANCE_WHOLE_COLLECTION; | |||||
| node->storage = data; | |||||
| } | |||||
| } // namespace blender::nodes | } // namespace blender::nodes | ||||
| void register_node_type_geo_point_instance() | void register_node_type_geo_point_instance() | ||||
| { | { | ||||
| static bNodeType ntype; | static bNodeType ntype; | ||||
| geo_node_type_base(&ntype, GEO_NODE_POINT_INSTANCE, "Point Instance", NODE_CLASS_GEOMETRY, 0); | geo_node_type_base(&ntype, GEO_NODE_POINT_INSTANCE, "Point Instance", NODE_CLASS_GEOMETRY, 0); | ||||
| node_type_socket_templates(&ntype, geo_node_point_instance_in, geo_node_point_instance_out); | node_type_socket_templates(&ntype, geo_node_point_instance_in, geo_node_point_instance_out); | ||||
| node_type_init(&ntype, blender::nodes::geo_node_point_instance_init); | |||||
| node_type_storage( | |||||
| &ntype, "NodeGeometryPointInstance", node_free_standard_storage, node_copy_standard_storage); | |||||
| node_type_update(&ntype, blender::nodes::geo_node_point_instance_update); | node_type_update(&ntype, blender::nodes::geo_node_point_instance_update); | ||||
| ntype.geometry_node_execute = blender::nodes::geo_node_point_instance_exec; | ntype.geometry_node_execute = blender::nodes::geo_node_point_instance_exec; | ||||
| nodeRegisterType(&ntype); | nodeRegisterType(&ntype); | ||||
| } | } | ||||