23#include <pxr/usd/usdGeom/pointInstancer.h>
53 pxr::VtArray<pxr::GfVec3f> usd_positions;
54 pxr::VtArray<pxr::GfVec3f> usd_scales;
55 pxr::VtArray<pxr::GfQuath> usd_orientations;
56 pxr::VtInt64Array usd_ids;
57 pxr::VtArray<int> usd_proto_indices;
58 std::vector<bool> usd_mask = point_instancer_prim_.ComputeMaskAtTime(params.
motion_sample_time);
60 point_instancer_prim_.GetPositionsAttr().Get(&usd_positions, params.
motion_sample_time);
62 point_instancer_prim_.GetOrientationsAttr().Get(&usd_orientations, params.
motion_sample_time);
64 point_instancer_prim_.GetProtoIndicesAttr().Get(&usd_proto_indices, params.
motion_sample_time);
67 if (pointcloud->
totpoint != usd_positions.size()) {
73 point_positions.
copy_from(
Span(usd_positions.cdata(), usd_positions.size()).cast<
float3>());
82 if (usd_scales.size() < usd_positions.size()) {
87 for (
const int i :
IndexRange(std::min(usd_scales.size(), usd_positions.size()))) {
88 scales_attribute.
span[i] =
float3(scales[i][0], scales[i][1], scales[i][2]);
97 if (usd_orientations.size() < usd_positions.size()) {
102 for (
const int i :
IndexRange(std::min(usd_orientations.size(), usd_positions.size()))) {
104 orientations[i].GetImaginary()[0],
105 orientations[i].GetImaginary()[1],
106 orientations[i].GetImaginary()[2]);
109 orientations_attribute.
finish();
111 if (!usd_ids.empty()) {
115 const Span<int64_t> usd_data(usd_ids.cdata(), usd_ids.size());
116 if (usd_data.size() < ids_attribute.
span.size()) {
117 ids_attribute.
span.fill(0);
120 for (
const int i :
IndexRange(std::min(usd_data.size(), ids_attribute.
span.size()))) {
122 ids_attribute.
span[i] = int(usd_data[i]);
131 if (usd_proto_indices.size() < usd_positions.size()) {
132 proto_indices_attribute.
span.fill(0);
135 Span<int> proto_indices =
Span(usd_proto_indices.cdata(), usd_proto_indices.size());
136 for (
const int i :
IndexRange(std::min(usd_proto_indices.size(), usd_positions.size()))) {
137 proto_indices_attribute.
span[i] = proto_indices[i];
140 proto_indices_attribute.
finish();
145 if (usd_mask.size() < usd_positions.size()) {
146 mask_attribute.
span.fill(
true);
149 for (
const int i :
IndexRange(std::min(usd_mask.size(), usd_positions.size()))) {
150 mask_attribute.
span[i] = usd_mask[i];
173 if (read_pointcloud != pointcloud) {
203 instance_on_points_node->
location[0] = 300.0f;
205 *instance_on_points_node,
SOCK_IN,
"Pick Instance"_ustr);
209 mask_attrib_node->location[0] = 100.0f;
210 mask_attrib_node->location[1] = -100.0f;
214 collection_info_node->
location[0] = 100.0f;
215 collection_info_node->
location[1] = -300.0f;
220 indices_attrib_node->location[0] = 100.0f;
221 indices_attrib_node->location[1] = -500.0f;
225 rotation_attrib_node->
location[0] = 100.0f;
226 rotation_attrib_node->
location[1] = -700.0f;
229 scale_attrib_node->
location[0] = 100.0f;
230 scale_attrib_node->
location[1] = -900.0f;
235 *instance_on_points_node,
241 *instance_on_points_node,
246 *indices_attrib_node,
248 *instance_on_points_node,
254 *instance_on_points_node,
258 *rotation_attrib_node,
260 *instance_on_points_node,
264 *collection_info_node,
266 *instance_on_points_node,
270 *instance_on_points_node,
273 *group_output->
inputs.first());
284 pxr::SdfPathVector paths;
285 point_instancer_prim_.GetPrototypesRel().GetTargets(&paths);
310 if (!collection_node) {
324 if (socket_data->
value != &coll) {
325 socket_data->
value = &coll;
334 is_animated |= point_instancer_prim_.GetPositionsAttr().ValueMightBeTimeVarying();
335 is_animated |= point_instancer_prim_.GetScalesAttr().ValueMightBeTimeVarying();
336 is_animated |= point_instancer_prim_.GetOrientationsAttr().ValueMightBeTimeVarying();
337 is_animated |= point_instancer_prim_.GetProtoIndicesAttr().ValueMightBeTimeVarying();
#define NODE_GROUP_OUTPUT
#define GEO_NODE_INPUT_NAMED_ATTRIBUTE
#define GEO_NODE_INSTANCE_ON_POINTS
#define GEO_NODE_COLLECTION_INFO
General operations, lookup, etc. for blender objects.
General operations for point clouds.
Object groups, one object can be in many groups at once.
#define BLI_assert_unreachable()
constexpr IndexRange()=default
constexpr void copy_from(Span< T > values) const
constexpr const char * c_str() const
GSpanAttributeWriter lookup_or_add_for_write_only_span(StringRef name, AttrDomain domain, AttrType data_type)
void add_cache_modifier()
pxr::SdfPathVector proto_paths() const
void read_geometry(bke::GeometrySet &geometry_set, USDMeshReadParams params, const char **r_err_str) override
void create_object(Main *bmain) override
void set_collection(Main *bmain, Collection &coll)
void read_object_data(Main *bmain, pxr::UsdTimeCode time) override
const USDImportParams & import_params_
#define storage(slot, qualifiers)
bNode * node_find_node_by_name(bNodeTree &ntree, StringRefNull name)
bNode * node_add_static_node(const bContext *C, bNodeTree &ntree, int type)
bNodeLink & node_add_link(bNodeTree &ntree, bNode &fromnode, bNodeSocket &fromsock, bNode &tonode, bNodeSocket &tosock)
bNodeTree * node_tree_add_tree(Main *bmain, StringRef name, StringRef idname)
bNodeSocket * node_find_socket(bNode &node, eNodeSocketInOut in_out, UString identifier)
USDMeshReadParams create_mesh_read_params(const double motion_sample_time, const int read_flags)
static bNode * add_input_named_attrib_node(bNodeTree *ntree, const char *name, int8_t prop_type)
QuaternionBase< float > Quaternion
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void BKE_pointcloud_nomain_to_pointcloud(PointCloud *pointcloud_src, PointCloud *pointcloud_dst)
void BKE_ntree_update_tag_socket_property(bNodeTree *ntree, bNodeSocket *socket)
void BKE_modifiers_persistent_uid_init(const Object &object, ModifierData &md)
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
ModifierData * BKE_modifier_new(int type)
PointCloud * BKE_pointcloud_add(Main *bmain, const char *name)
void BKE_ntree_update_after_single_tree_change(Main &bmain, bNodeTree &modified_tree, const NodeTreeUpdateExtraParams ¶ms={})
ModifierData * BKE_modifiers_findby_type(const Object *ob, ModifierType type)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
PointCloud * BKE_pointcloud_new_nomain(PointCloudType type, int totpoint)
@ NODE_INTERFACE_SOCKET_OUTPUT
@ NODE_INTERFACE_SOCKET_INPUT
VecBase< float, 3 > float3
Object * BKE_object_add_only_object(Main *bmain, ObjectType type, const char *name) ATTR_RETURNS_NONNULL
void BKE_object_modifier_set_active(Object *ob, ModifierData *md)
struct bNodeTree * node_group
ListBaseT< ModifierData > modifiers
struct Collection * value
bNodeTreeInterface tree_interface
ListBaseT< bNodeSocket > outputs
ListBaseT< bNodeSocket > inputs
GeometryComponent & get_component_for_write(GeometryComponent::Type component_type)
PointCloud * get_pointcloud_for_write()
void replace_pointcloud(PointCloud *pointcloud, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
static GeometrySet from_pointcloud(PointCloud *pointcloud, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
MutableVArraySpan< T > span
MeshSeqCacheModifierReadFlag mesh_read_flag
double motion_sample_time
static QuaternionBase identity()