23#include <pxr/usd/usdGeom/pointInstancer.h>
46 this->
object_->data = pointcloud;
53 pxr::VtArray<pxr::GfVec3f> usd_positions;
54 pxr::VtArray<pxr::GfVec3f> usd_scales;
55 pxr::VtArray<pxr::GfQuath> usd_orientations;
56 pxr::VtArray<int> usd_proto_indices;
57 std::vector<bool> usd_mask = point_instancer_prim_.ComputeMaskAtTime(
params.motion_sample_time);
59 point_instancer_prim_.GetPositionsAttr().Get(&usd_positions,
params.motion_sample_time);
60 point_instancer_prim_.GetScalesAttr().Get(&usd_scales,
params.motion_sample_time);
61 point_instancer_prim_.GetOrientationsAttr().Get(&usd_orientations,
params.motion_sample_time);
62 point_instancer_prim_.GetProtoIndicesAttr().Get(&usd_proto_indices,
params.motion_sample_time);
65 if (pointcloud->
totpoint != usd_positions.size()) {
80 if (usd_scales.size() < usd_positions.size()) {
85 for (
const int i :
IndexRange(std::min(usd_scales.size(), usd_positions.size()))) {
86 scales_attribute.
span[
i] =
float3(scales[
i][0], scales[
i][1], scales[
i][2]);
95 if (usd_orientations.size() < usd_positions.size()) {
100 for (
const int i :
IndexRange(std::min(usd_orientations.size(), usd_positions.size()))) {
102 orientations[
i].GetImaginary()[0],
103 orientations[
i].GetImaginary()[1],
104 orientations[
i].GetImaginary()[2]);
107 orientations_attribute.
finish();
112 if (usd_proto_indices.size() < usd_positions.size()) {
113 proto_indices_attribute.
span.fill(0);
116 Span<int> proto_indices =
Span(usd_proto_indices.cdata(), usd_proto_indices.size());
117 for (
const int i :
IndexRange(std::min(usd_proto_indices.size(), usd_positions.size()))) {
118 proto_indices_attribute.
span[
i] = proto_indices[
i];
121 proto_indices_attribute.
finish();
126 if (usd_mask.size() < usd_positions.size()) {
127 mask_attribute.
span.fill(
true);
130 for (
const int i :
IndexRange(std::min(usd_mask.size(), usd_positions.size()))) {
131 mask_attribute.
span[
i] = usd_mask[
i];
154 if (read_pointcloud != pointcloud) {
184 instance_on_points_node->
location[0] = 300.0f;
189 mask_attrib_node->location[0] = 100.0f;
190 mask_attrib_node->location[1] = -100.0f;
194 collection_info_node->
location[0] = 100.0f;
195 collection_info_node->
location[1] = -300.0f;
200 indices_attrib_node->location[0] = 100.0f;
201 indices_attrib_node->location[1] = -500.0f;
205 rotation_attrib_node->
location[0] = 100.0f;
206 rotation_attrib_node->
location[1] = -700.0f;
209 scale_attrib_node->
location[0] = 100.0f;
210 scale_attrib_node->
location[1] = -900.0f;
215 *instance_on_points_node,
221 *instance_on_points_node,
225 *indices_attrib_node,
227 *instance_on_points_node,
233 *instance_on_points_node,
237 *rotation_attrib_node,
239 *instance_on_points_node,
243 *collection_info_node,
245 *instance_on_points_node,
249 *instance_on_points_node,
263 pxr::SdfPathVector paths;
264 point_instancer_prim_.GetPrototypesRel().GetTargets(&paths);
289 if (!collection_node) {
303 if (socket_data->
value != &coll) {
304 socket_data->
value = &coll;
313 is_animated |= point_instancer_prim_.GetPositionsAttr().ValueMightBeTimeVarying();
314 is_animated |= point_instancer_prim_.GetScalesAttr().ValueMightBeTimeVarying();
315 is_animated |= point_instancer_prim_.GetOrientationsAttr().ValueMightBeTimeVarying();
316 is_animated |= point_instancer_prim_.GetProtoIndicesAttr().ValueMightBeTimeVarying();
ModifierData * BKE_modifiers_findby_type(const Object *ob, ModifierType type)
void BKE_modifiers_persistent_uid_init(const Object &object, ModifierData &md)
ModifierData * BKE_modifier_new(int type)
#define NODE_GROUP_OUTPUT
#define GEO_NODE_INPUT_NAMED_ATTRIBUTE
#define GEO_NODE_INSTANCE_ON_POINTS
#define GEO_NODE_COLLECTION_INFO
void BKE_ntree_update_after_single_tree_change(Main &bmain, bNodeTree &modified_tree, const NodeTreeUpdateExtraParams ¶ms={})
void BKE_ntree_update_tag_socket_property(bNodeTree *ntree, bNodeSocket *socket)
General operations, lookup, etc. for blender objects.
void BKE_object_modifier_set_active(Object *ob, ModifierData *md)
Object * BKE_object_add_only_object(Main *bmain, int type, const char *name) ATTR_RETURNS_NONNULL
General operations for point clouds.
PointCloud * BKE_pointcloud_add(Main *bmain, const char *name)
void BKE_pointcloud_nomain_to_pointcloud(PointCloud *pointcloud_src, PointCloud *pointcloud_dst)
PointCloud * BKE_pointcloud_new_nomain(int totpoint)
#define BLI_assert_unreachable()
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
Object groups, one object can be in many groups at once.
@ NODE_INTERFACE_SOCKET_OUTPUT
@ NODE_INTERFACE_SOCKET_INPUT
constexpr void copy_from(Span< T > values) const
Span< NewT > constexpr cast() const
GSpanAttributeWriter lookup_or_add_for_write_only_span(StringRef attribute_id, 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_
bNode * node_find_node_by_name(bNodeTree &ntree, StringRefNull name)
bNodeSocket * node_find_socket(bNode &node, eNodeSocketInOut in_out, StringRef identifier)
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)
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
VecBase< float, 3 > float3
struct bNodeTree * node_group
struct Collection * value
bNodeTreeInterface tree_interface
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
static QuaternionBase identity()