Blender V5.3
usd_writer_pointinstancer.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2025 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
7#include "usd_utils.hh"
8
10#include "BKE_collection.hh"
11#include "BKE_geometry_set.hh"
13#include "BKE_instances.hh"
14#include "BKE_lib_id.hh"
15#include "BKE_report.hh"
16
17#include "BLI_math_euler.hh"
18#include "BLI_math_matrix.hh"
19
21#include "DNA_layer_types.h"
22#include "DNA_object_types.h"
23
24#include <pxr/base/gf/quatf.h>
25#include <pxr/base/gf/vec3d.h>
26#include <pxr/base/gf/vec3f.h>
27#include <pxr/base/vt/array.h>
28#include <pxr/usd/usdGeom/pointInstancer.h>
29#include <pxr/usd/usdGeom/primvarsAPI.h>
30
32
33namespace blender::io::usd {
34
36 const USDExporterContext &ctx,
37 const Set<std::pair<pxr::SdfPath, Object *>> &prototype_paths,
38 std::unique_ptr<USDAbstractWriter> base_writer)
39 : USDAbstractWriter(ctx),
40 base_writer_(std::move(base_writer)),
41 prototype_paths_(prototype_paths)
42{
43}
44
46{
47 /* Write the base data first (e.g., mesh, curves, points) */
48 if (base_writer_) {
49 base_writer_->write(context);
50
54 {
55 usd_export_context_.add_skel_mapping_fn(context.object, base_writer_->usd_path());
56 }
57 }
58
59 const pxr::UsdStageRefPtr stage = usd_export_context_.stage;
60 const Object *object_eval = context.object;
61 bke::GeometrySet instance_geometry_set = bke::object_get_evaluated_geometry_set(*object_eval);
62
63 const bke::GeometryComponent *component = instance_geometry_set.get_component(
65
66 const bke::Instances *instances = static_cast<const bke::InstancesComponent &>(*component).get();
67
68 int instance_num = instances->instances_num();
69 const pxr::SdfPath &usd_path = usd_export_context_.usd_path;
70 const pxr::UsdGeomPointInstancer usd_instancer = pxr::UsdGeomPointInstancer::Define(stage,
71 usd_path);
72 const pxr::UsdTimeCode time = get_export_time_code();
73
74 Span<float4x4> transforms = instances->transforms();
75 BLI_assert(transforms.size() >= instance_num);
76
77 if (transforms.size() != instance_num) {
78 BKE_reportf(this->reports(),
80 "Instances number '%d' does not match transforms size '%d'",
81 instance_num,
82 int(transforms.size()));
83 return;
84 }
85
86 /* evaluated positions */
87 pxr::UsdAttribute position_attr = usd_instancer.CreatePositionsAttr();
88 pxr::VtArray<pxr::GfVec3f> positions(instance_num);
89 for (int i = 0; i < instance_num; i++) {
90 const float3 &pos = transforms[i].location();
91 positions[i] = pxr::GfVec3f(pos.x, pos.y, pos.z);
92 }
93 io::usd::set_attribute(position_attr, positions, time, usd_value_writer_);
94
95 /* orientations */
96 pxr::UsdAttribute orientations_attr = usd_instancer.CreateOrientationsAttr();
97 pxr::VtArray<pxr::GfQuath> orientation(instance_num);
98 for (int i = 0; i < instance_num; i++) {
99 const float3 euler = float3(math::to_euler(math::normalize(transforms[i])));
101 orientation[i] = pxr::GfQuath(quat.w, pxr::GfVec3h(quat.x, quat.y, quat.z));
102 }
103 io::usd::set_attribute(orientations_attr, orientation, time, usd_value_writer_);
104
105 /* scales */
106 pxr::UsdAttribute scales_attr = usd_instancer.CreateScalesAttr();
107 pxr::VtArray<pxr::GfVec3f> scales(instance_num);
108 for (int i = 0; i < instance_num; i++) {
109 const MatBase<float, 4, 4> &mat = transforms[i];
110 float3 scale_vec = math::to_scale<true>(mat);
111 scales[i] = pxr::GfVec3f(scale_vec.x, scale_vec.y, scale_vec.z);
112 }
113 io::usd::set_attribute(scales_attr, scales, time, usd_value_writer_);
114
115 /* IDs */
116 const Span<int> ids = instances->unique_ids();
117 pxr::VtInt64Array usd_ids(ids.begin(), ids.end());
118 pxr::UsdAttribute attr_ids = usd_instancer.CreateIdsAttr();
119 io::usd::set_attribute(attr_ids, usd_ids, time, usd_value_writer_);
120
121 /* other attr */
122 bke::AttributeAccessor attributes_eval = *component->attributes();
123 attributes_eval.foreach_attribute([&](const bke::AttributeIter &iter) {
124 if (iter.name[0] == '.' || bke::attribute_name_is_anonymous(iter.name) ||
125 ELEM(iter.name, "instance_transform", "scale", "orientation", "mask", "proto_index", "id"))
126 {
127 return;
128 }
129
130 this->write_attribute_data(iter, usd_instancer, time);
131 });
132
133 /* prototypes relations */
134 const pxr::SdfPath protoParentPath = usd_path.AppendChild(pxr::TfToken("Prototypes"));
135 pxr::UsdPrim prototypesOver = stage->DefinePrim(protoParentPath);
136 pxr::SdfPathVector proto_wrapper_paths;
137
138 Map<std::string, int> proto_index_map;
139 Map<std::string, pxr::SdfPath> proto_path_map;
140
141 if (!prototype_paths_.is_empty() && usd_instancer) {
142 int iter = 0;
143
144 for (const std::pair<pxr::SdfPath, Object *> &entry : prototype_paths_) {
145 const pxr::SdfPath &source_path = entry.first;
146 Object *obj = entry.second;
147
148 if (source_path.IsEmpty()) {
149 continue;
150 }
151
152 const pxr::SdfPath proto_path = protoParentPath.AppendChild(
153 pxr::TfToken("Prototype_" + std::to_string(iter)));
154
155 pxr::UsdPrim prim = stage->DefinePrim(proto_path);
156
157 /* To avoid USD error of Unresolved reference prim path, make sure the referenced path
158 * exists. */
159 stage->DefinePrim(source_path);
160 prim.GetReferences().AddReference(pxr::SdfReference("", source_path));
161 proto_wrapper_paths.push_back(proto_path);
162
163 std::string ob_name = BKE_id_name(obj->id);
164 proto_index_map.add_new(ob_name, iter);
165 proto_path_map.add_new(ob_name, proto_path);
166
167 ++iter;
168 }
169 usd_instancer.GetPrototypesRel().SetTargets(proto_wrapper_paths);
170 }
171
172 /* proto indices */
173 /* must be the last to populate */
174 pxr::UsdAttribute proto_indices_attr = usd_instancer.CreateProtoIndicesAttr();
175 pxr::VtArray<int> proto_indices;
176 Vector<std::pair<int, int>> collection_instance_object_count_map;
177
178 Span<int> reference_handles = instances->reference_handles();
179 Span<bke::InstanceReference> references = instances->references();
180 Map<std::string, int> final_proto_index_map;
181
182 for (int i = 0; i < instance_num; i++) {
183 bke::InstanceReference reference = references[reference_handles[i]];
184
185 process_instance_reference(reference,
186 i,
187 proto_index_map,
188 final_proto_index_map,
189 proto_path_map,
190 stage,
191 proto_indices,
192 collection_instance_object_count_map);
193 }
194
195 io::usd::set_attribute(proto_indices_attr, proto_indices, time, usd_value_writer_);
196
197 /* Handle Collection Prototypes */
198 if (!collection_instance_object_count_map.is_empty()) {
199 handle_collection_prototypes(
200 usd_instancer, time, instance_num, collection_instance_object_count_map);
201 }
202
203 /* Clean unused prototype. When finding prototype paths under the context of a point instancer,
204 * all the prototypes are collected, even those used by lower-level nested child PointInstancers.
205 * It can happen that different levels in nested PointInstancers share the same prototypes, but
206 * if not, we need to clean the extra prototypes from the prototype relationship for a cleaner
207 * USD export. */
208 compact_prototypes(usd_instancer, time, proto_wrapper_paths);
209}
210
211void USDPointInstancerWriter::process_instance_reference(
212 const bke::InstanceReference &reference,
213 int instance_index,
214 Map<std::string, int> &proto_index_map,
215 Map<std::string, int> &final_proto_index_map,
216 Map<std::string, pxr::SdfPath> &proto_path_map,
217 pxr::UsdStageRefPtr stage,
218 pxr::VtArray<int> &proto_indices,
219 Vector<std::pair<int, int>> &collection_instance_object_count_map)
220{
221 /* TODO: Verify logic around the `add_overwrite` calls below. Using `add_new` will trigger
222 * asserts because multiple items are being added to the map with the same key. Original code
223 * was using std::map and repeatedly reassigning with `final_proto_index_map[ob_name] = ...` */
224 switch (reference.type()) {
226 Object &object = reference.object();
227 std::string ob_name = BKE_id_name(object.id);
228
229 if (proto_index_map.contains(ob_name)) {
230 proto_indices.push_back(proto_index_map.lookup(ob_name));
231
232 final_proto_index_map.add_overwrite(ob_name, proto_index_map.lookup(ob_name));
233
234 /* If the reference is Object, clear prototype's local transform to identity to avoid
235 * double transforms. The PointInstancer will fully control instance placement. */
236 override_transform(stage, proto_path_map.lookup(ob_name), float4x4::identity());
237 }
238 break;
239 }
240
242 Collection &collection = reference.collection();
243 int object_num = 0;
244 FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN (&collection, object) {
245 std::string ob_name = BKE_id_name(object->id);
246
247 if (proto_index_map.contains(ob_name)) {
248 object_num += 1;
249 proto_indices.push_back(proto_index_map.lookup(ob_name));
250
251 final_proto_index_map.add_overwrite(ob_name, proto_index_map.lookup(ob_name));
252 }
253 }
255 collection_instance_object_count_map.append(std::make_pair(instance_index, object_num));
256 break;
257 }
258
260 bke::GeometrySet geometry_set = reference.geometry_set();
261 const StringRef set_name = geometry_set.name();
262
263 if (proto_index_map.contains_as(set_name)) {
264 proto_indices.push_back(proto_index_map.lookup_as(set_name));
265
266 final_proto_index_map.add_overwrite(set_name, proto_index_map.lookup_as(set_name));
267 }
268
269 Vector<const bke::GeometryComponent *> components = geometry_set.get_components();
270 for (const bke::GeometryComponent *comp : components) {
271 if (const bke::Instances *instances =
272 static_cast<const bke::InstancesComponent &>(*comp).get())
273 {
274 Span<int> ref_handles = instances->reference_handles();
275 Span<bke::InstanceReference> refs = instances->references();
276
277 /* If the top-level GeometrySet is not in proto_index_map, recursively traverse child
278 * InstanceReferences to resolve prototype indices. If the name matches proto_index_map,
279 * skip traversal to avoid duplicates, since GeometrySet names may overlap with object
280 * names. */
281 if (!proto_index_map.contains(set_name)) {
282 for (int index = 0; index < ref_handles.size(); ++index) {
283 const bke::InstanceReference &child_ref = refs[ref_handles[index]];
284
285 /* Recursively traverse nested GeometrySets to resolve prototype indices for all
286 * instances. */
287 process_instance_reference(child_ref,
289 proto_index_map,
290 final_proto_index_map,
291 proto_path_map,
292 stage,
293 proto_indices,
294 collection_instance_object_count_map);
295 }
296 }
297
298 /* If the reference is GeometrySet, then override the transform with the transform of the
299 * Instance inside this GeometrySet. */
300 Span<float4x4> transforms = instances->transforms();
301 if (transforms.size() == 1) {
302 if (proto_path_map.contains(set_name)) {
303 override_transform(stage, proto_path_map.lookup(set_name), transforms[0]);
304 }
305 }
306 }
307 }
308 break;
309 }
310
312 default:
313 break;
314 }
315}
316
317void USDPointInstancerWriter::compact_prototypes(const pxr::UsdGeomPointInstancer &usd_instancer,
318 const pxr::UsdTimeCode time,
319 const pxr::SdfPathVector &proto_paths) const
320{
321 pxr::UsdAttribute proto_indices_attr = usd_instancer.GetProtoIndicesAttr();
322 pxr::VtArray<int> proto_indices;
323 if (!proto_indices_attr.Get(&proto_indices, time)) {
324 return;
325 }
326
327 /* Find actually used prototype indices. */
328 Set<int> used_proto_indices;
329 used_proto_indices.add_multiple(Span(proto_indices.cbegin(), proto_indices.size()));
330
331 Map<int, int> remap;
332 int new_index = 0;
333 for (int i = 0; i < proto_paths.size(); ++i) {
334 if (used_proto_indices.contains(i)) {
335 remap.add(i, new_index++);
336 }
337 }
338
339 /* Remap protoIndices. */
340 for (int &idx : proto_indices) {
341 idx = remap.lookup(idx);
342 }
343 proto_indices_attr.Set(proto_indices, time);
344
345 pxr::SdfPathVector compact_proto_paths;
346 for (int i = 0; i < proto_paths.size(); ++i) {
347 if (used_proto_indices.contains(i)) {
348 compact_proto_paths.push_back(proto_paths[i]);
349 }
350 }
351
352 usd_instancer.GetPrototypesRel().SetTargets(compact_proto_paths);
353}
354
355void USDPointInstancerWriter::override_transform(const pxr::UsdStageRefPtr stage,
356 const pxr::SdfPath &proto_path,
357 const float4x4 &transform) const
358{
359 pxr::UsdPrim prim = stage->GetPrimAtPath(proto_path);
360 if (!prim) {
361 return;
362 }
363
364 /* Extract translation. */
365 const float3 &pos = transform.location();
366 pxr::GfVec3d override_position(pos.x, pos.y, pos.z);
367
368 /* Extract rotation. */
369 const float3 euler = float3(math::to_euler(math::normalize(transform)));
370 pxr::GfVec3f override_rotation(euler.x, euler.y, euler.z);
371
372 /* Extract scale. */
373 const float3 scale_vec = math::to_scale<true>(transform);
374 pxr::GfVec3f override_scale(scale_vec.x, scale_vec.y, scale_vec.z);
375
376 pxr::UsdGeomXformable xformable(prim);
377 xformable.ClearXformOpOrder();
378 xformable.AddTranslateOp().Set(override_position);
379 xformable.AddRotateXYZOp().Set(override_rotation);
380 xformable.AddScaleOp().Set(override_scale);
381}
382
383template<typename T>
384static pxr::VtArray<T> DuplicateArray(const pxr::VtArray<T> &original, size_t copies)
385{
386 pxr::VtArray<T> newArray;
387 size_t originalSize = original.size();
388 newArray.resize(originalSize * copies);
389 for (size_t i = 0; i < copies; ++i) {
390 std::copy(original.begin(), original.end(), newArray.begin() + i * originalSize);
391 }
392 return newArray;
393}
394
395template<typename T, typename GetterFunc, typename CreatorFunc>
396static void DuplicatePerInstanceAttribute(const GetterFunc &getter,
397 const CreatorFunc &creator,
398 size_t copies,
399 const pxr::UsdTimeCode &time)
400{
401 pxr::VtArray<T> values;
402 if (getter().Get(&values, time) && !values.empty()) {
403 auto newValues = DuplicateArray(values, copies);
404 creator().Set(newValues, time);
405 }
406}
407
408template<typename T, typename GetterFunc, typename CreatorFunc>
409static void ExpandAttributePerInstance(const GetterFunc &getter,
410 const CreatorFunc &creator,
411 const Span<std::pair<int, int>> instance_object_map,
412 const pxr::UsdTimeCode &time)
413{
414 /* MARK: Handle Collection Prototypes
415 * ----------------------------------
416 * In Blender, a Collection is not an actual Object type. When exporting, the iterator
417 * flattens the Collection hierarchy, treating each object inside the Collection as an
418 * individual prototype. However, all these prototypes share the same instance attributes
419 * (e.g., positions, orientations, scales).
420 *
421 * To ensure correct arrangement, reading, and drawing in OpenUSD, we need to explicitly
422 * duplicate the instance attributes across all prototypes derived from the Collection. */
423 pxr::VtArray<T> original_values;
424 if (!getter().Get(&original_values, time) || original_values.empty()) {
425 return;
426 }
427
428 pxr::VtArray<T> expanded_values;
429 for (const auto &[instance_index, object_count] : instance_object_map) {
430 if (instance_index < int(original_values.size())) {
431 for (int i = 0; i < object_count; ++i) {
432 expanded_values.push_back(original_values[instance_index]);
433 }
434 }
435 }
436
437 creator().Set(expanded_values, time);
438}
439
440void USDPointInstancerWriter::handle_collection_prototypes(
441 const pxr::UsdGeomPointInstancer &usd_instancer,
442 const pxr::UsdTimeCode time,
443 const int instance_num,
444 const Span<std::pair<int, int>> collection_instance_object_count_map) const
445{
446 /* Duplicate attributes. */
447 if (usd_instancer.GetPositionsAttr().HasAuthoredValue()) {
448 ExpandAttributePerInstance<pxr::GfVec3f>([&]() { return usd_instancer.GetPositionsAttr(); },
449 [&]() { return usd_instancer.CreatePositionsAttr(); },
450 collection_instance_object_count_map,
451 time);
452 }
453 if (usd_instancer.GetOrientationsAttr().HasAuthoredValue()) {
455 [&]() { return usd_instancer.GetOrientationsAttr(); },
456 [&]() { return usd_instancer.CreateOrientationsAttr(); },
457 collection_instance_object_count_map,
458 time);
459 }
460 if (usd_instancer.GetScalesAttr().HasAuthoredValue()) {
461 ExpandAttributePerInstance<pxr::GfVec3f>([&]() { return usd_instancer.GetScalesAttr(); },
462 [&]() { return usd_instancer.CreateScalesAttr(); },
463 collection_instance_object_count_map,
464 time);
465 }
466 if (usd_instancer.GetVelocitiesAttr().HasAuthoredValue()) {
468 [&]() { return usd_instancer.GetVelocitiesAttr(); },
469 [&]() { return usd_instancer.CreateVelocitiesAttr(); },
470 collection_instance_object_count_map,
471 time);
472 }
473 if (usd_instancer.GetAngularVelocitiesAttr().HasAuthoredValue()) {
475 [&]() { return usd_instancer.GetAngularVelocitiesAttr(); },
476 [&]() { return usd_instancer.CreateAngularVelocitiesAttr(); },
477 collection_instance_object_count_map,
478 time);
479 }
480
481 /* Duplicate Primvars. */
482 const pxr::UsdGeomPrimvarsAPI primvars_api(usd_instancer);
483 for (const pxr::UsdGeomPrimvar &primvar : primvars_api.GetPrimvars()) {
484 if (!primvar.HasAuthoredValue()) {
485 continue;
486 }
487 const pxr::TfToken pv_name = primvar.GetPrimvarName();
488 const pxr::SdfValueTypeName pv_type = primvar.GetTypeName();
489 const pxr::TfToken pv_interp = primvar.GetInterpolation();
490 auto create = [&]() { return primvars_api.CreatePrimvar(pv_name, pv_type, pv_interp); };
491
492 if (pv_type == pxr::SdfValueTypeNames->FloatArray) {
494 [&]() { return primvar; }, create, collection_instance_object_count_map, time);
495 }
496 else if (pv_type == pxr::SdfValueTypeNames->IntArray) {
498 [&]() { return primvar; }, create, collection_instance_object_count_map, time);
499 }
500 else if (pv_type == pxr::SdfValueTypeNames->UCharArray) {
502 [&]() { return primvar; }, create, collection_instance_object_count_map, time);
503 }
504 else if (pv_type == pxr::SdfValueTypeNames->Float2Array) {
506 [&]() { return primvar; }, create, collection_instance_object_count_map, time);
507 }
508 else if (ELEM(pv_type,
509 pxr::SdfValueTypeNames->Float3Array,
510 pxr::SdfValueTypeNames->Color3fArray,
511 pxr::SdfValueTypeNames->Color4fArray))
512 {
514 [&]() { return primvar; }, create, collection_instance_object_count_map, time);
515 }
516 else if (pv_type == pxr::SdfValueTypeNames->QuatfArray) {
518 [&]() { return primvar; }, create, collection_instance_object_count_map, time);
519 }
520 else if (pv_type == pxr::SdfValueTypeNames->BoolArray) {
522 [&]() { return primvar; }, create, collection_instance_object_count_map, time);
523 }
524 else if (pv_type == pxr::SdfValueTypeNames->StringArray) {
526 [&]() { return primvar; }, create, collection_instance_object_count_map, time);
527 }
528 }
529
530 /* MARK: Ensure Instance Indices Exist
531 * -----------------------------------
532 * If the PointInstancer has no authored instance indices, manually generate a default
533 * sequence of indices to ensure the PointInstancer functions correctly in OpenUSD.
534 * This guarantees that each instance can correctly reference its prototype. */
535 pxr::UsdAttribute proto_indices_attr = usd_instancer.GetProtoIndicesAttr();
536 if (!proto_indices_attr.HasAuthoredValue()) {
537 Vector<int> index;
538 for (int i = 0; i < prototype_paths_.size(); i++) {
539 index.append_n_times(i, instance_num);
540 }
541
542 proto_indices_attr.Set(pxr::VtArray<int>(index.begin(), index.end()));
543 }
544}
545
546void USDPointInstancerWriter::write_attribute_data(const bke::AttributeIter &attr,
547 const pxr::UsdGeomPointInstancer &usd_instancer,
548 const pxr::UsdTimeCode time)
549{
550 const std::optional<pxr::SdfValueTypeName> pv_type = convert_blender_type_to_usd(attr.data_type);
551
552 if (!pv_type) {
553 BKE_reportf(this->reports(),
555 "Attribute '%s' (Blender domain %d, type %d) cannot be converted to USD",
556 attr.name.c_str(),
557 int(attr.domain),
558 int(attr.data_type));
559 return;
560 }
561
562 const GVArray attribute = *attr.get();
563 if (attribute.is_empty()) {
564 return;
565 }
566
567 if (attr.name == "mask") {
568 pxr::UsdAttribute idsAttr = usd_instancer.GetIdsAttr();
569 if (!idsAttr) {
570 idsAttr = usd_instancer.CreateIdsAttr();
571 }
572
573 pxr::UsdAttribute invisibleIdsAttr = usd_instancer.GetInvisibleIdsAttr();
574 if (!invisibleIdsAttr) {
575 invisibleIdsAttr = usd_instancer.CreateInvisibleIdsAttr();
576 }
577
578 Vector<bool> mask_values(attribute.size());
579 attribute.materialize(IndexMask(attribute.size()), mask_values.data());
580
581 pxr::VtArray<int64_t> ids;
582 pxr::VtArray<int64_t> invisibleIds;
583 ids.reserve(mask_values.size());
584
585 for (int64_t i = 0; i < mask_values.size(); i++) {
586 ids.push_back(i);
587 if (!mask_values[i]) {
588 invisibleIds.push_back(i);
589 }
590 }
591
592 io::usd::set_attribute(idsAttr, ids, time, usd_value_writer_);
593 io::usd::set_attribute(invisibleIdsAttr, invisibleIds, time, usd_value_writer_);
594 }
595
596 const pxr::TfToken pv_name(
598 const pxr::UsdGeomPrimvarsAPI pv_api = pxr::UsdGeomPrimvarsAPI(usd_instancer);
599
600 pxr::UsdGeomPrimvar pv_attr = pv_api.CreatePrimvar(pv_name, *pv_type);
601
602 copy_blender_attribute_to_primvar(attribute, attr.data_type, time, pv_attr, usd_value_writer_);
603}
604
605} /* namespace blender::io::usd */
#define FOREACH_COLLECTION_OBJECT_RECURSIVE_END
#define FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN(_collection, _object)
Object groups, one object can be in many groups at once.
Object is a sort of wrapper for general info.
#define ELEM(...)
constexpr int64_t size() const
Definition BLI_span.hh:256
bool add_overwrite(const Key &key, const Value &value)
Definition BLI_map.hh:325
const Value & lookup(const Key &key) const
Definition BLI_map.hh:545
void add_new(const Key &key, const Value &value)
Definition BLI_map.hh:265
const Value & lookup_as(const ForwardKey &key) const
Definition BLI_map.hh:553
bool contains_as(const ForwardKey &key) const
Definition BLI_map.hh:357
bool contains(const Key &key) const
Definition BLI_map.hh:353
constexpr Span()=default
constexpr int64_t size() const
Definition BLI_span.hh:256
constexpr const T * end() const
Definition BLI_span.hh:228
constexpr const T * begin() const
Definition BLI_span.hh:224
bool is_empty() const
void foreach_attribute(const FunctionRef< void(const AttributeIter &)> fn) const
virtual std::optional< AttributeAccessor > attributes() const
Collection & collection() const
Span< int > reference_handles() const
Definition instances.cc:222
Span< float4x4 > transforms() const
Definition instances.cc:235
Span< InstanceReference > references() const
Definition instances.cc:290
int instances_num() const
Definition instances.cc:408
Span< int > unique_ids() const
Definition instances.cc:520
const pxr::SdfPath & usd_path() const
pxr::UsdTimeCode get_export_time_code() const
pxr::UsdUtilsSparseValueWriter usd_value_writer_
USDAbstractWriter(const USDExporterContext &usd_export_context)
const USDExporterContext usd_export_context_
USDPointInstancerWriter(const USDExporterContext &ctx, const Set< std::pair< pxr::SdfPath, Object * > > &prototype_paths, std::unique_ptr< USDAbstractWriter > base_writer)
void do_write(HierarchyContext &context) override
#define instance_index
#define index(i)
#define attribute(slot)
std::unique_ptr< IDProperty, IDPropertyDeleter > create(StringRef prop_name, int32_t value, eIDPropertyFlag flags={})
Allocate a new IDProperty of type IDP_INT, set its name and value.
bool attribute_name_is_anonymous(const StringRef name)
GeometrySet object_get_evaluated_geometry_set(const Object &object, bool apply_subdiv=true)
std::string time(const std::tm &date_time, TimeFormat format=TimeFormat::H24)
void copy_blender_attribute_to_primvar(const GVArray &attribute, const bke::AttrType data_type, const pxr::UsdTimeCode time, const pxr::UsdGeomPrimvar &primvar, pxr::UsdUtilsSparseValueWriter &value_writer)
std::optional< pxr::SdfValueTypeName > convert_blender_type_to_usd(const bke::AttrType blender_type, bool use_color3f_type)
static pxr::VtArray< T > DuplicateArray(const pxr::VtArray< T > &original, size_t copies)
void set_attribute(const pxr::UsdAttribute &attr, const USDT value, pxr::UsdTimeCode time, pxr::UsdUtilsSparseValueWriter &value_writer)
static void ExpandAttributePerInstance(const GetterFunc &getter, const CreatorFunc &creator, const Span< std::pair< int, int > > instance_object_map, const pxr::UsdTimeCode &time)
static void DuplicatePerInstanceAttribute(const GetterFunc &getter, const CreatorFunc &creator, size_t copies, const pxr::UsdTimeCode &time)
std::string make_safe_primvar_name(const StringRef name, bool allow_unicode)
Definition usd_utils.cc:88
QuaternionBase< float > Quaternion
QuaternionBase< T > to_quaternion(const AxisAngleBase< T, AngleT > &axis_angle)
EulerXYZBase< float > EulerXYZ
MatBase< T, NumCol, NumRow > normalize(const MatBase< T, NumCol, NumRow > &a)
VecBase< T, 3 > to_scale(const MatBase< T, NumCol, NumRow > &mat)
Euler3Base< T > to_euler(const AxisAngleBase< T, AngleT > &axis_angle, EulerOrder order)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
__int64 int64_t
Definition BKE_text.h:90
@ RPT_WARNING
Definition BKE_report.hh:40
MatBase< float, 4, 4 > float4x4
const char * BKE_id_name(const ID &id)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
Definition report.cc:191
VecBase< float, 3 > float3
float4 transform(float4 hs_position)
StringRefNull name() const
const GeometryComponent * get_component(GeometryComponent::Type component_type) const
std::function< void(const Object *, const pxr::SdfPath &)> add_skel_mapping_fn
float z
Definition sky_math.h:136
float y
Definition sky_math.h:136
float x
Definition sky_math.h:136