HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
pointInstancer.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef USDGEOM_GENERATED_POINTINSTANCER_H
25 #define USDGEOM_GENERATED_POINTINSTANCER_H
26 
27 /// \file usdGeom/pointInstancer.h
28 
29 #include "pxr/pxr.h"
30 #include "pxr/usd/usdGeom/api.h"
32 #include "pxr/usd/usd/prim.h"
33 #include "pxr/usd/usd/stage.h"
34 #include "pxr/usd/usdGeom/tokens.h"
35 
36 #include "pxr/base/vt/value.h"
37 
38 #include "pxr/base/gf/vec3d.h"
39 #include "pxr/base/gf/vec3f.h"
40 #include "pxr/base/gf/matrix4d.h"
41 
42 #include "pxr/base/tf/token.h"
43 #include "pxr/base/tf/type.h"
44 
46 
47 class SdfAssetPath;
48 
49 // -------------------------------------------------------------------------- //
50 // POINTINSTANCER //
51 // -------------------------------------------------------------------------- //
52 
53 /// \class UsdGeomPointInstancer
54 ///
55 /// Encodes vectorized instancing of multiple, potentially
56 /// animated, prototypes (object/instance masters), which can be arbitrary
57 /// prims/subtrees on a UsdStage.
58 ///
59 /// PointInstancer is a "multi instancer", as it allows multiple prototypes
60 /// to be scattered among its "points". We use a UsdRelationship
61 /// \em prototypes to identify and order all of the possible prototypes, by
62 /// targeting the root prim of each prototype. The ordering imparted by
63 /// relationships associates a zero-based integer with each prototype, and
64 /// it is these integers we use to identify the prototype of each instance,
65 /// compactly, and allowing prototypes to be swapped out without needing to
66 /// reauthor all of the per-instance data.
67 ///
68 /// The PointInstancer schema is designed to scale to billions of instances,
69 /// which motivates the choice to split the per-instance transformation into
70 /// position, (quaternion) orientation, and scales, rather than a
71 /// 4x4 matrix per-instance. In addition to requiring fewer bytes even if
72 /// all elements are authored (32 bytes vs 64 for a single-precision 4x4
73 /// matrix), we can also be selective about which attributes need to animate
74 /// over time, for substantial data reduction in many cases.
75 ///
76 /// Note that PointInstancer is \em not a Gprim, since it is not a graphical
77 /// primitive by any stretch of the imagination. It \em is, however,
78 /// Boundable, since we will sometimes want to treat the entire PointInstancer
79 /// similarly to a procedural, from the perspective of inclusion or framing.
80 ///
81 /// \section UsdGeomPointInstancer_varyingTopo Varying Instance Identity over Time
82 ///
83 /// PointInstancers originating from simulations often have the characteristic
84 /// that points/instances are "born", move around for some time period, and then
85 /// die (or leave the area of interest). In such cases, billions of instances
86 /// may be birthed over time, while at any \em specific time, only a much
87 /// smaller number are actually alive. To encode this situation efficiently,
88 /// the simulator may re-use indices in the instance arrays, when a particle
89 /// dies, its index will be taken over by a new particle that may be birthed in
90 /// a much different location. This presents challenges both for
91 /// identity-tracking, and for motion-blur.
92 ///
93 /// We facilitate identity tracking by providing an optional, animatable
94 /// \em ids attribute, that specifies the 64 bit integer ID of the particle
95 /// at each index, at each point in time. If the simulator keeps monotonically
96 /// increasing a particle-count each time a new particle is birthed, it will
97 /// serve perfectly as particle \em ids.
98 ///
99 /// We facilitate motion blur for varying-topology particle streams by
100 /// optionally allowing per-instance \em velocities and \em angularVelocities
101 /// to be authored. If instance transforms are requested at a time between
102 /// samples and either of the velocity attributes is authored, then we will
103 /// not attempt to interpolate samples of \em positions or \em orientations.
104 /// If not authored, and the bracketing samples have the same length, then we
105 /// will interpolate.
106 ///
107 /// \section UsdGeomPointInstancer_transform Computing an Instance Transform
108 ///
109 /// Each instance's transformation is a combination of the SRT affine transform
110 /// described by its scale, orientation, and position, applied \em after
111 /// (i.e. less locally than) the local to parent transformation computed at
112 /// the root of the prototype it is instancing.
113 ///
114 /// If your processing of prototype geometry naturally takes into account the
115 /// transform of the prototype root, then this term can be omitted from the
116 /// computation of each instance transform, and this can be controlled when
117 /// computing instance transformation matrices using the
118 /// UsdGeomPointInstancer::PrototypeXformInclusion enumeration.
119 ///
120 /// To understand the computation of the instance transform, in order to put
121 /// an instance of a PointInstancer into the space of the PointInstancer's
122 /// parent prim we do the following:
123 ///
124 /// 1. Apply (most locally) the authored local to parent transformation for
125 /// <em>prototypes[protoIndices[i]]</em>
126 /// 2. If *scales* is authored, next apply the scaling matrix from *scales[i]*
127 /// 3. If *orientations* is authored: **if *angularVelocities* is authored**,
128 /// first multiply *orientations[i]* by the unit quaternion derived by scaling
129 /// *angularVelocities[i]* by the \ref UsdGeom_PITimeScaling "time differential"
130 /// from the left-bracketing timeSample for *orientation* to the requested
131 /// evaluation time *t*, storing the result in *R*, **else** assign *R*
132 /// directly from *orientations[i]*. Apply the rotation matrix derived
133 /// from *R*.
134 /// 4. Apply the translation derived from *positions[i]*. If *velocities* is
135 /// authored, apply the translation deriving from *velocities[i]* scaled by
136 /// the time differential from the left-bracketing timeSample for *positions*
137 /// to the requested evaluation time *t*.
138 /// 5. Least locally, apply the transformation authored on the PointInstancer
139 /// prim itself (or the UsdGeomImageable::ComputeLocalToWorldTransform() of the
140 /// PointInstancer to put the instance directly into world space)
141 ///
142 /// If neither *velocities* nor *angularVelocities* are authored, we fallback to
143 /// standard position and orientation computation logic (using linear
144 /// interpolation between timeSamples) as described by
145 /// \ref UsdGeom_VelocityInterpolation .
146 ///
147 /// \anchor UsdGeom_PITimeScaling
148 /// <b>Scaling Velocities for Interpolation</b>
149 ///
150 /// When computing time-differentials by which to apply velocity or
151 /// angularVelocity to positions or orientations, we must scale by
152 /// ( 1.0 / UsdStage::GetTimeCodesPerSecond() ), because velocities are recorded
153 /// in units/second, while we are interpolating in UsdTimeCode ordinates.
154 ///
155 /// We provide both high and low-level API's for dealing with the
156 /// transformation as a matrix, both will compute the instance matrices using
157 /// multiple threads; the low-level API allows the client to cache unvarying
158 /// inputs so that they need not be read duplicately when computing over
159 /// time.
160 ///
161 /// See also \ref UsdGeom_VelocityInterpolation .
162 ///
163 /// \section UsdGeomPointInstancer_primvars Primvars on PointInstancer
164 ///
165 /// \ref UsdGeomPrimvar "Primvars" authored on a PointInstancer prim should
166 /// always be applied to each instance with \em constant interpolation at
167 /// the root of the instance. When you are authoring primvars on a
168 /// PointInstancer, think about it as if you were authoring them on a
169 /// point-cloud (e.g. a UsdGeomPoints gprim). The same
170 /// <A HREF="https://renderman.pixar.com/resources/RenderMan_20/appnote.22.html#classSpecifiers">interpolation rules for points</A> apply here, substituting
171 /// "instance" for "point".
172 ///
173 /// In other words, the (constant) value extracted for each instance
174 /// from the authored primvar value depends on the authored \em interpolation
175 /// and \em elementSize of the primvar, as follows:
176 /// \li <b>constant</b> or <b>uniform</b> : the entire authored value of the
177 /// primvar should be applied exactly to each instance.
178 /// \li <b>varying</b>, <b>vertex</b>, or <b>faceVarying</b>: the first
179 /// \em elementSize elements of the authored primvar array should be assigned to
180 /// instance zero, the second \em elementSize elements should be assigned to
181 /// instance one, and so forth.
182 ///
183 ///
184 /// \section UsdGeomPointInstancer_masking Masking Instances: "Deactivating" and Invising
185 ///
186 /// Often a PointInstancer is created "upstream" in a graphics pipeline, and
187 /// the needs of "downstream" clients necessitate eliminating some of the
188 /// instances from further consideration. Accomplishing this pruning by
189 /// re-authoring all of the per-instance attributes is not very attractive,
190 /// since it may mean destructively editing a large quantity of data. We
191 /// therefore provide means of "masking" instances by ID, such that the
192 /// instance data is unmolested, but per-instance transform and primvar data
193 /// can be retrieved with the no-longer-desired instances eliminated from the
194 /// (smaller) arrays. PointInstancer allows two independent means of masking
195 /// instances by ID, each with different features that meet the needs of
196 /// various clients in a pipeline. Both pruning features' lists of ID's are
197 /// combined to produce the mask returned by ComputeMaskAtTime().
198 ///
199 /// \note If a PointInstancer has no authored \em ids attribute, the masking
200 /// features will still be available, with the integers specifying element
201 /// position in the \em protoIndices array rather than ID.
202 ///
203 /// \subsection UsdGeomPointInstancer_inactiveIds InactiveIds: List-edited, Unvarying Masking
204 ///
205 /// The first masking feature encodes a list of IDs in a list-editable metadatum
206 /// called \em inactiveIds, which, although it does not have any similar
207 /// impact to stage population as \ref UsdPrim::SetActive() "prim activation",
208 /// it shares with that feature that its application is uniform over all time.
209 /// Because it is list-editable, we can \em sparsely add and remove instances
210 /// from it in many layers.
211 ///
212 /// This sparse application pattern makes \em inactiveIds a good choice when
213 /// further downstream clients may need to reverse masking decisions made
214 /// upstream, in a manner that is robust to many kinds of future changes to
215 /// the upstream data.
216 ///
217 /// See ActivateId(), ActivateIds(), DeactivateId(), DeactivateIds(),
218 /// ActivateAllIds()
219 ///
220 /// \subsection UsdGeomPointInstancer_invisibleIds invisibleIds: Animatable Masking
221 ///
222 /// The second masking feature encodes a list of IDs in a time-varying
223 /// Int64Array-valued UsdAttribute called \em invisibleIds , since it shares
224 /// with \ref UsdGeomImageable::GetVisibilityAttr() "Imageable visibility"
225 /// the ability to animate object visibility.
226 ///
227 /// Unlike \em inactiveIds, overriding a set of opinions for \em invisibleIds
228 /// is not at all straightforward, because one will, in general need to
229 /// reauthor (in the overriding layer) **all** timeSamples for the attribute
230 /// just to change one Id's visibility state, so it cannot be authored
231 /// sparsely. But it can be a very useful tool for situations like encoding
232 /// pre-computed camera-frustum culling of geometry when either or both of
233 /// the instances or the camera is animated.
234 ///
235 /// See VisId(), VisIds(), InvisId(), InvisIds(), VisAllIds()
236 ///
237 /// \section UsdGeomPointInstancer_protoProcessing Processing and Not Processing Prototypes
238 ///
239 /// Any prim in the scenegraph can be targeted as a prototype by the
240 /// \em prototypes relationship. We do not, however, provide a specific
241 /// mechanism for identifying prototypes as geometry that should not be drawn
242 /// (or processed) in their own, local spaces in the scenegraph. We
243 /// encourage organizing all prototypes as children of the PointInstancer
244 /// prim that consumes them, and pruning "raw" processing and drawing
245 /// traversals when they encounter a PointInstancer prim; this is what the
246 /// UsdGeomBBoxCache and UsdImaging engines do.
247 ///
248 /// There \em is a pattern one can deploy for organizing the prototypes
249 /// such that they will automatically be skipped by basic UsdPrim::GetChildren()
250 /// or UsdPrimRange traversals. Usd prims each have a
251 /// \ref Usd_PrimSpecifiers "specifier" of "def", "over", or "class". The
252 /// default traversals skip over prims that are "pure overs" or classes. So
253 /// to protect prototypes from all generic traversals and processing, place
254 /// them under a prim that is just an "over". For example,
255 /// \code
256 /// 01 def PointInstancer "Crowd_Mid"
257 /// 02 {
258 /// 03 rel prototypes = [ </Crowd_Mid/Prototypes/MaleThin_Business>, </Crowd_Mid/Prototypes/MaleThin_Casual> ]
259 /// 04
260 /// 05 over "Prototypes"
261 /// 06 {
262 /// 07 def "MaleThin_Business" (
263 /// 08 references = [@MaleGroupA/usd/MaleGroupA.usd@</MaleGroupA>]
264 /// 09 variants = {
265 /// 10 string modelingVariant = "Thin"
266 /// 11 string costumeVariant = "BusinessAttire"
267 /// 12 }
268 /// 13 )
269 /// 14 { ... }
270 /// 15
271 /// 16 def "MaleThin_Casual"
272 /// 17 ...
273 /// 18 }
274 /// 19 }
275 /// \endcode
276 ///
277 ///
279 {
280 public:
281  /// Compile time constant representing what kind of schema this class is.
282  ///
283  /// \sa UsdSchemaKind
285 
286  /// Construct a UsdGeomPointInstancer on UsdPrim \p prim .
287  /// Equivalent to UsdGeomPointInstancer::Get(prim.GetStage(), prim.GetPath())
288  /// for a \em valid \p prim, but will not immediately throw an error for
289  /// an invalid \p prim
290  explicit UsdGeomPointInstancer(const UsdPrim& prim=UsdPrim())
291  : UsdGeomBoundable(prim)
292  {
293  }
294 
295  /// Construct a UsdGeomPointInstancer on the prim held by \p schemaObj .
296  /// Should be preferred over UsdGeomPointInstancer(schemaObj.GetPrim()),
297  /// as it preserves SchemaBase state.
298  explicit UsdGeomPointInstancer(const UsdSchemaBase& schemaObj)
299  : UsdGeomBoundable(schemaObj)
300  {
301  }
302 
303  /// Destructor.
305  virtual ~UsdGeomPointInstancer();
306 
307  /// Return a vector of names of all pre-declared attributes for this schema
308  /// class and all its ancestor classes. Does not include attributes that
309  /// may be authored by custom/extended methods of the schemas involved.
311  static const TfTokenVector &
312  GetSchemaAttributeNames(bool includeInherited=true);
313 
314  /// Return a UsdGeomPointInstancer holding the prim adhering to this
315  /// schema at \p path on \p stage. If no prim exists at \p path on
316  /// \p stage, or if the prim at that path does not adhere to this schema,
317  /// return an invalid schema object. This is shorthand for the following:
318  ///
319  /// \code
320  /// UsdGeomPointInstancer(stage->GetPrimAtPath(path));
321  /// \endcode
322  ///
324  static UsdGeomPointInstancer
325  Get(const UsdStagePtr &stage, const SdfPath &path);
326 
327  /// Attempt to ensure a \a UsdPrim adhering to this schema at \p path
328  /// is defined (according to UsdPrim::IsDefined()) on this stage.
329  ///
330  /// If a prim adhering to this schema at \p path is already defined on this
331  /// stage, return that prim. Otherwise author an \a SdfPrimSpec with
332  /// \a specifier == \a SdfSpecifierDef and this schema's prim type name for
333  /// the prim at \p path at the current EditTarget. Author \a SdfPrimSpec s
334  /// with \p specifier == \a SdfSpecifierDef and empty typeName at the
335  /// current EditTarget for any nonexistent, or existing but not \a Defined
336  /// ancestors.
337  ///
338  /// The given \a path must be an absolute prim path that does not contain
339  /// any variant selections.
340  ///
341  /// If it is impossible to author any of the necessary PrimSpecs, (for
342  /// example, in case \a path cannot map to the current UsdEditTarget's
343  /// namespace) issue an error and return an invalid \a UsdPrim.
344  ///
345  /// Note that this method may return a defined prim whose typeName does not
346  /// specify this schema class, in case a stronger typeName opinion overrides
347  /// the opinion at the current EditTarget.
348  ///
350  static UsdGeomPointInstancer
351  Define(const UsdStagePtr &stage, const SdfPath &path);
352 
353 protected:
354  /// Returns the kind of schema this class belongs to.
355  ///
356  /// \sa UsdSchemaKind
358  UsdSchemaKind _GetSchemaKind() const override;
359 
360 private:
361  // needs to invoke _GetStaticTfType.
362  friend class UsdSchemaRegistry;
364  static const TfType &_GetStaticTfType();
365 
366  static bool _IsTypedSchema();
367 
368  // override SchemaBase virtuals.
370  const TfType &_GetTfType() const override;
371 
372 public:
373  // --------------------------------------------------------------------- //
374  // PROTOINDICES
375  // --------------------------------------------------------------------- //
376  /// <b>Required property</b>. Per-instance index into
377  /// \em prototypes relationship that identifies what geometry should be
378  /// drawn for each instance. <b>Topology attribute</b> - can be animated,
379  /// but at a potential performance impact for streaming.
380  ///
381  /// | ||
382  /// | -- | -- |
383  /// | Declaration | `int[] protoIndices` |
384  /// | C++ Type | VtArray<int> |
385  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->IntArray |
388 
389  /// See GetProtoIndicesAttr(), and also
390  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
391  /// If specified, author \p defaultValue as the attribute's default,
392  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
393  /// the default for \p writeSparsely is \c false.
395  UsdAttribute CreateProtoIndicesAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
396 
397 public:
398  // --------------------------------------------------------------------- //
399  // IDS
400  // --------------------------------------------------------------------- //
401  /// Ids are optional; if authored, the ids array should be the same
402  /// length as the \em protoIndices array, specifying (at each timeSample if
403  /// instance identities are changing) the id of each instance. The
404  /// type is signed intentionally, so that clients can encode some
405  /// binary state on Id'd instances without adding a separate primvar.
406  /// See also \ref UsdGeomPointInstancer_varyingTopo
407  ///
408  /// | ||
409  /// | -- | -- |
410  /// | Declaration | `int64[] ids` |
411  /// | C++ Type | VtArray<int64_t> |
412  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Int64Array |
414  UsdAttribute GetIdsAttr() const;
415 
416  /// See GetIdsAttr(), and also
417  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
418  /// If specified, author \p defaultValue as the attribute's default,
419  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
420  /// the default for \p writeSparsely is \c false.
422  UsdAttribute CreateIdsAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
423 
424 public:
425  // --------------------------------------------------------------------- //
426  // POSITIONS
427  // --------------------------------------------------------------------- //
428  /// <b>Required property</b>. Per-instance position. See also
429  /// \ref UsdGeomPointInstancer_transform .
430  ///
431  /// | ||
432  /// | -- | -- |
433  /// | Declaration | `point3f[] positions` |
434  /// | C++ Type | VtArray<GfVec3f> |
435  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Point3fArray |
438 
439  /// See GetPositionsAttr(), and also
440  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
441  /// If specified, author \p defaultValue as the attribute's default,
442  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
443  /// the default for \p writeSparsely is \c false.
445  UsdAttribute CreatePositionsAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
446 
447 public:
448  // --------------------------------------------------------------------- //
449  // ORIENTATIONS
450  // --------------------------------------------------------------------- //
451  /// If authored, per-instance orientation of each instance about its
452  /// prototype's origin, represented as a unit length quaternion, which
453  /// allows us to encode it with sufficient precision in a compact GfQuath.
454  ///
455  /// It is client's responsibility to ensure that authored quaternions are
456  /// unit length; the convenience API below for authoring orientations from
457  /// rotation matrices will ensure that quaternions are unit length, though
458  /// it will not make any attempt to select the "better (for interpolation
459  /// with respect to neighboring samples)" of the two possible quaternions
460  /// that encode the rotation.
461  ///
462  /// See also \ref UsdGeomPointInstancer_transform .
463  ///
464  /// | ||
465  /// | -- | -- |
466  /// | Declaration | `quath[] orientations` |
467  /// | C++ Type | VtArray<GfQuath> |
468  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->QuathArray |
471 
472  /// See GetOrientationsAttr(), and also
473  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
474  /// If specified, author \p defaultValue as the attribute's default,
475  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
476  /// the default for \p writeSparsely is \c false.
478  UsdAttribute CreateOrientationsAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
479 
480 public:
481  // --------------------------------------------------------------------- //
482  // ORIENTATIONSF
483  // --------------------------------------------------------------------- //
484  /// If authored, per-instance orientation of each instance about its
485  /// prototype's origin, represented as a unit length quaternion, encoded
486  /// as a GfQuatf to support higher precision computations.
487  ///
488  /// It is client's responsibility to ensure that authored quaternions are
489  /// unit length; the convenience API below for authoring orientations from
490  /// rotation matrices will ensure that quaternions are unit length, though
491  /// it will not make any attempt to select the "better (for interpolation
492  /// with respect to neighboring samples)" of the two possible quaternions
493  /// that encode the rotation. Note that if the earliest time sample (or
494  /// default value if there are no time samples) of orientationsf is not empty
495  /// orientationsf will be preferred over orientations if both are authored.
496  ///
497  /// See also \ref UsdGeomPointInstancer_transform .
498  ///
499  /// | ||
500  /// | -- | -- |
501  /// | Declaration | `quatf[] orientationsf` |
502  /// | C++ Type | VtArray<GfQuatf> |
503  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->QuatfArray |
506 
507  /// See GetOrientationsfAttr(), and also
508  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
509  /// If specified, author \p defaultValue as the attribute's default,
510  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
511  /// the default for \p writeSparsely is \c false.
513  UsdAttribute CreateOrientationsfAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
514 
515 public:
516  // --------------------------------------------------------------------- //
517  // SCALES
518  // --------------------------------------------------------------------- //
519  /// If authored, per-instance scale to be applied to
520  /// each instance, before any rotation is applied.
521  ///
522  /// See also \ref UsdGeomPointInstancer_transform .
523  ///
524  /// | ||
525  /// | -- | -- |
526  /// | Declaration | `float3[] scales` |
527  /// | C++ Type | VtArray<GfVec3f> |
528  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Float3Array |
530  UsdAttribute GetScalesAttr() const;
531 
532  /// See GetScalesAttr(), and also
533  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
534  /// If specified, author \p defaultValue as the attribute's default,
535  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
536  /// the default for \p writeSparsely is \c false.
538  UsdAttribute CreateScalesAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
539 
540 public:
541  // --------------------------------------------------------------------- //
542  // VELOCITIES
543  // --------------------------------------------------------------------- //
544  /// If provided, per-instance 'velocities' will be used to
545  /// compute positions between samples for the 'positions' attribute,
546  /// rather than interpolating between neighboring 'positions' samples.
547  /// Velocities should be considered mandatory if both \em protoIndices
548  /// and \em positions are animated. Velocity is measured in position
549  /// units per second, as per most simulation software. To convert to
550  /// position units per UsdTimeCode, divide by
551  /// UsdStage::GetTimeCodesPerSecond().
552  ///
553  /// See also \ref UsdGeomPointInstancer_transform,
554  /// \ref UsdGeom_VelocityInterpolation .
555  ///
556  /// | ||
557  /// | -- | -- |
558  /// | Declaration | `vector3f[] velocities` |
559  /// | C++ Type | VtArray<GfVec3f> |
560  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Vector3fArray |
563 
564  /// See GetVelocitiesAttr(), and also
565  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
566  /// If specified, author \p defaultValue as the attribute's default,
567  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
568  /// the default for \p writeSparsely is \c false.
570  UsdAttribute CreateVelocitiesAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
571 
572 public:
573  // --------------------------------------------------------------------- //
574  // ACCELERATIONS
575  // --------------------------------------------------------------------- //
576  /// If authored, per-instance 'accelerations' will be used with
577  /// velocities to compute positions between samples for the 'positions'
578  /// attribute rather than interpolating between neighboring 'positions'
579  /// samples. Acceleration is measured in position units per second-squared.
580  /// To convert to position units per squared UsdTimeCode, divide by the
581  /// square of UsdStage::GetTimeCodesPerSecond().
582  ///
583  /// | ||
584  /// | -- | -- |
585  /// | Declaration | `vector3f[] accelerations` |
586  /// | C++ Type | VtArray<GfVec3f> |
587  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Vector3fArray |
590 
591  /// See GetAccelerationsAttr(), and also
592  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
593  /// If specified, author \p defaultValue as the attribute's default,
594  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
595  /// the default for \p writeSparsely is \c false.
597  UsdAttribute CreateAccelerationsAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
598 
599 public:
600  // --------------------------------------------------------------------- //
601  // ANGULARVELOCITIES
602  // --------------------------------------------------------------------- //
603  /// If authored, per-instance angular velocity vector to be used for
604  /// interoplating orientations. Angular velocities should be considered
605  /// mandatory if both \em protoIndices and \em orientations are animated.
606  /// Angular velocity is measured in <b>degrees</b> per second. To convert
607  /// to degrees per UsdTimeCode, divide by
608  /// UsdStage::GetTimeCodesPerSecond().
609  ///
610  /// See also \ref UsdGeomPointInstancer_transform .
611  ///
612  /// | ||
613  /// | -- | -- |
614  /// | Declaration | `vector3f[] angularVelocities` |
615  /// | C++ Type | VtArray<GfVec3f> |
616  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Vector3fArray |
619 
620  /// See GetAngularVelocitiesAttr(), and also
621  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
622  /// If specified, author \p defaultValue as the attribute's default,
623  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
624  /// the default for \p writeSparsely is \c false.
626  UsdAttribute CreateAngularVelocitiesAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
627 
628 public:
629  // --------------------------------------------------------------------- //
630  // INVISIBLEIDS
631  // --------------------------------------------------------------------- //
632  /// A list of id's to make invisible at the evaluation time.
633  /// See \ref UsdGeomPointInstancer_invisibleIds .
634  ///
635  /// | ||
636  /// | -- | -- |
637  /// | Declaration | `int64[] invisibleIds = []` |
638  /// | C++ Type | VtArray<int64_t> |
639  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Int64Array |
642 
643  /// See GetInvisibleIdsAttr(), and also
644  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
645  /// If specified, author \p defaultValue as the attribute's default,
646  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
647  /// the default for \p writeSparsely is \c false.
649  UsdAttribute CreateInvisibleIdsAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
650 
651 public:
652  // --------------------------------------------------------------------- //
653  // PROTOTYPES
654  // --------------------------------------------------------------------- //
655  /// <b>Required property</b>. Orders and targets the prototype root
656  /// prims, which can be located anywhere in the scenegraph that is convenient,
657  /// although we promote organizing prototypes as children of the
658  /// PointInstancer. The position of a prototype in this relationship defines
659  /// the value an instance would specify in the \em protoIndices attribute to
660  /// instance that prototype. Since relationships are uniform, this property
661  /// cannot be animated.
662  ///
665 
666  /// See GetPrototypesRel(), and also
667  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create
670 
671 public:
672  // ===================================================================== //
673  // Feel free to add custom code below this line, it will be preserved by
674  // the code generator.
675  //
676  // Just remember to:
677  // - Close the class declaration with };
678  // - Close the namespace with PXR_NAMESPACE_CLOSE_SCOPE
679  // - Close the include guard with #endif
680  // ===================================================================== //
681  // --(BEGIN CUSTOM CODE)--
682 
683  // --------------------------------------------------------------------- //
684  /// \name Id-based Instance Masking/Pruning
685  /// See \ref UsdGeomPointInstancer_masking
686  /// @{
687  // --------------------------------------------------------------------- //
688 
689  /// Ensure that the instance identified by \p id is active over all time.
690  /// This activation is encoded sparsely, affecting no other instances.
691  ///
692  /// This does not guarantee that the instance will be rendered, because
693  /// it may still be "invisible" due to \p id being present in the
694  /// \em invisibleIds attribute (see VisId(), InvisId())
696  bool ActivateId(int64_t id) const;
697 
698  /// Ensure that the instances identified by \p ids are active over all time.
699  /// This activation is encoded sparsely, affecting no other instances.
700  ///
701  /// This does not guarantee that the instances will be rendered, because
702  /// each may still be "invisible" due to its presence in the
703  /// \em invisibleIds attribute (see VisId(), InvisId())
705  bool ActivateIds(VtInt64Array const &ids) const;
706 
707  /// Ensure that all instances are active over all time.
708  ///
709  /// This does not guarantee that the instances will be rendered, because
710  /// each may still be "invisible" due to its presence in the
711  /// \em invisibleIds attribute (see VisId(), InvisId())
713  bool ActivateAllIds() const;
714 
715  /// Ensure that the instance identified by \p id is inactive over all time.
716  /// This deactivation is encoded sparsely, affecting no other instances.
717  ///
718  /// A deactivated instance is guaranteed not to render if the renderer
719  /// honors masking.
721  bool DeactivateId(int64_t id) const;
722 
723  /// Ensure that the instances identified by \p ids are inactive over all time.
724  /// This deactivation is encoded sparsely, affecting no other instances.
725  ///
726  /// A deactivated instance is guaranteed not to render if the renderer
727  /// honors masking.
729  bool DeactivateIds(VtInt64Array const &ids) const;
730 
731 
732  /// Ensure that the instance identified by \p id is visible at \p time.
733  /// This will cause \em invisibleIds to first be broken down (keyed)
734  /// at \p time, causing all animation in weaker layers that the current
735  /// UsdEditTarget to be overridden. Has no effect on any timeSamples other
736  /// than the one at \p time. If the \em invisibleIds attribute is not
737  /// authored or is blocked, this operation is a no-op.
738  ///
739  /// This does not guarantee that the instance will be rendered, because
740  /// it may still be "inactive" due to \p id being present in the
741  /// \em inactivevIds metadata (see ActivateId(), DeactivateId())
743  bool VisId(int64_t id, UsdTimeCode const &time) const;
744 
745  /// Ensure that the instances identified by \p ids are visible at \p time.
746  /// This will cause \em invisibleIds to first be broken down (keyed)
747  /// at \p time, causing all animation in weaker layers that the current
748  /// UsdEditTarget to be overridden. Has no effect on any timeSamples other
749  /// than the one at \p time. If the \em invisibleIds attribute is not
750  /// authored or is blocked, this operation is a no-op.
751  ///
752  /// This does not guarantee that the instances will be rendered, because
753  /// each may still be "inactive" due to \p id being present in the
754  /// \em inactivevIds metadata (see ActivateId(), DeactivateId())
756  bool VisIds(VtInt64Array const &ids, UsdTimeCode const &time) const;
757 
758  /// Ensure that all instances are visible at \p time.
759  /// Operates by authoring an empty array at \p time.
760  ///
761  /// This does not guarantee that the instances will be rendered, because
762  /// each may still be "inactive" due to its id being present in the
763  /// \em inactivevIds metadata (see ActivateId(), DeactivateId())
765  bool VisAllIds(UsdTimeCode const &time) const;
766 
767  /// Ensure that the instance identified by \p id is invisible at \p time.
768  /// This will cause \em invisibleIds to first be broken down (keyed)
769  /// at \p time, causing all animation in weaker layers that the current
770  /// UsdEditTarget to be overridden. Has no effect on any timeSamples other
771  /// than the one at \p time.
772  ///
773  /// An invised instance is guaranteed not to render if the renderer
774  /// honors masking.
776  bool InvisId(int64_t id, UsdTimeCode const &time) const;
777 
778  /// Ensure that the instances identified by \p ids are invisible at \p time.
779  /// This will cause \em invisibleIds to first be broken down (keyed)
780  /// at \p time, causing all animation in weaker layers that the current
781  /// UsdEditTarget to be overridden. Has no effect on any timeSamples other
782  /// than the one at \p time.
783  ///
784  /// An invised instance is guaranteed not to render if the renderer
785  /// honors masking.
787  bool InvisIds(VtInt64Array const &ids, UsdTimeCode const &time) const;
788 
789  /// Computes a presence mask to be applied to per-instance data arrays
790  /// based on authored \em inactiveIds, \em invisibleIds, and \em ids .
791  ///
792  /// If no \em ids attribute has been authored, then the values in
793  /// \em inactiveIds and \em invisibleIds will be interpreted directly
794  /// as indices of \em protoIndices .
795  ///
796  /// If \p ids is non-NULL, it is assumed to be the id-mapping to apply,
797  /// and must match the length of \em protoIndices at \p time .
798  /// If NULL, we will call GetIdsAttr().Get(time)
799  ///
800  /// \note If all "live" instances at UsdTimeCode \p time pass the mask,
801  /// we will return an <b>empty</b> mask so that clients can trivially
802  /// recognize the common "no masking" case.
803  ///
804  /// The returned mask can be used with ApplyMaskToArray(), and will contain
805  /// a \c true value for every element that should survive.
807  std::vector<bool> ComputeMaskAtTime(UsdTimeCode time,
808  VtInt64Array const *ids = nullptr) const;
809 
810  /// Contract \p dataArray in-place to contain only the elements whose
811  /// index in \p mask is \c true.
812  ///
813  /// \note an empty \p mask specifies "all pass", in which case \p dataArray
814  /// is trivially unmodified
815  ///
816  /// - It is an error for \p dataArray to be NULL .
817  /// - If \em elementSize times \em mask.size() does not equal
818  /// \em dataArray->size(), warn and fail.
819  ///
820  /// \return true on success, false on failure.
821  /// \sa ComputeMaskAtTime()
822  template <class T>
823  static bool ApplyMaskToArray(std::vector<bool> const &mask,
824  VtArray<T> *dataArray,
825  const int elementSize = 1);
826 
827  /// Determines if we should prefer orientationsf over orientations
828  /// based on whether or not orientationsf has been authored to a non
829  /// empty array. Assumes that orientationsf is empty if the earliest time
830  /// sample or default value if there are no time samples are empty
831  ///
832  /// \param rotationsAttr the outparameter for the corresponding attribute. If
833  /// this function returns true then orientationsf will be
834  /// stored in rotationsAttr, and orientations if not
836  bool UsesOrientationsf(UsdAttribute &rotationsAttr) const;
837 
838  // --------------------------------------------------------------------- //
839  /// @}
840  // --------------------------------------------------------------------- //
841 
842  /// \enum ProtoXformInclusion
843  ///
844  /// Encodes whether to include each prototype's root prim's transformation
845  /// as the most-local component of computed instance transforms.
847  IncludeProtoXform, //!< Include the transform on the proto's root
848  ExcludeProtoXform //!< Exclude the transform on the proto's root
849  };
850 
851 
852  /// \enum MaskApplication
853  ///
854  /// Encodes whether to evaluate and apply the PointInstancer's
855  /// mask to computed results.
856  /// \sa ComputeMaskAtTime()
858  ApplyMask, //!< Compute and apply the PointInstancer mask
859  IgnoreMask //!< Ignore the PointInstancer mask
860  };
861 
862 
863  /// Compute the per-instance, "PointInstancer relative" transforms given
864  /// the positions, scales, orientations, velocities and angularVelocities
865  /// at \p time, as described in \ref UsdGeomPointInstancer_transform .
866  ///
867  /// This will return \c false and leave \p xforms untouched if:
868  /// - \p xforms is NULL
869  /// - one of \p time and \p baseTime is numeric and the other is
870  /// UsdTimeCode::Default() (they must either both be numeric or both be
871  /// default)
872  /// - there is no authored \em protoIndices attribute or \em positions
873  /// attribute
874  /// - the size of any of the per-instance attributes does not match the
875  /// size of \em protoIndices
876  /// - \p doProtoXforms is \c IncludeProtoXform but an index value in
877  /// \em protoIndices is outside the range [0, prototypes.size())
878  /// - \p applyMask is \c ApplyMask and a mask is set but the size of the
879  /// mask does not match the size of \em protoIndices.
880  ///
881  /// If there is no error, we will return \c true and \p xforms will contain
882  /// the computed transformations.
883  ///
884  /// \param xforms - the out parameter for the transformations. Its size
885  /// will depend on the authored data and \p applyMask
886  /// \param time - UsdTimeCode at which we want to evaluate the transforms
887  /// \param baseTime - required for correct interpolation between samples
888  /// when \em velocities or \em angularVelocities are
889  /// present. If there are samples for \em positions and
890  /// \em velocities at t1 and t2, normal value resolution
891  /// would attempt to interpolate between the two samples,
892  /// and if they could not be interpolated because they
893  /// differ in size (common in cases where velocity is
894  /// authored), will choose the sample at t1. When
895  /// sampling for the purposes of motion-blur, for example,
896  /// it is common, when rendering the frame at t2, to
897  /// sample at [ t2-shutter/2, t2+shutter/2 ] for a
898  /// shutter interval of \em shutter. The first sample
899  /// falls between t1 and t2, but we must sample at t2
900  /// and apply velocity-based interpolation based on those
901  /// samples to get a correct result. In such scenarios,
902  /// one should provide a \p baseTime of t2 when querying
903  /// \em both samples. If your application does not care
904  /// about off-sample interpolation, it can supply the
905  /// same value for \p baseTime that it does for \p time.
906  /// When \p baseTime is less than or equal to \p time,
907  /// we will choose the lower bracketing timeSample.
908  /// Selecting sample times with respect to baseTime will
909  /// be performed independently for positions and
910  /// orientations.
911  /// \param doProtoXforms - specifies whether to include the root
912  /// transformation of each instance's prototype in the
913  /// instance's transform. Default is to include it, but
914  /// some clients may want to apply the proto transform as
915  /// part of the prototype itself, so they can specify
916  /// \c ExcludeProtoXform instead.
917  /// \param applyMask - specifies whether to apply ApplyMaskToArray() to the
918  /// computed result. The default is \c ApplyMask.
920  bool
922  VtArray<GfMatrix4d>* xforms,
923  const UsdTimeCode time,
924  const UsdTimeCode baseTime,
925  const ProtoXformInclusion doProtoXforms = IncludeProtoXform,
926  const MaskApplication applyMask = ApplyMask) const;
927 
928  /// Compute the per-instance transforms as in
929  /// ComputeInstanceTransformsAtTime, but using multiple sample times. An
930  /// array of matrix arrays is returned where each matrix array contains the
931  /// instance transforms for the corresponding time in \p times .
932  ///
933  /// \param times - A vector containing the UsdTimeCodes at which we want to
934  /// sample.
936  bool
938  std::vector<VtArray<GfMatrix4d>>* xformsArray,
939  const std::vector<UsdTimeCode>& times,
940  const UsdTimeCode baseTime,
941  const ProtoXformInclusion doProtoXforms = IncludeProtoXform,
942  const MaskApplication applyMask = ApplyMask) const;
943 
944  /// \overload
945  /// Perform the per-instance transform computation as described in
946  /// \ref UsdGeomPointInstancer_transform . This does the same computation as
947  /// the non-static ComputeInstanceTransformsAtTime method, but takes all
948  /// data as parameters rather than accessing authored data.
949  ///
950  /// \param xforms - the out parameter for the transformations. Its size
951  /// will depend on the given data and \p applyMask
952  /// \param stage - the UsdStage
953  /// \param time - time at which we want to evaluate the transforms
954  /// \param protoIndices - array containing all instance prototype indices.
955  /// \param positions - array containing all instance positions. This array
956  /// must be the same size as \p protoIndices .
957  /// \param velocities - array containing all instance velocities. This array
958  /// must be either the same size as \p protoIndices or
959  /// empty. If it is empty, transforms are computed as if
960  /// all velocities were zero in all dimensions.
961  /// \param velocitiesSampleTime - time at which the samples from
962  /// \p velocities were taken.
963  /// \param accelerations - array containing all instance accelerations.
964  /// This array must be either the same size as
965  /// \p protoIndicesor empty. If it is empty, transforms
966  /// are computed as if all accelerations were zero in
967  /// all dimensions.
968  /// \param scales - array containing all instance scales. This array must be
969  /// either the same size as \p protoIndices or empty. If it
970  /// is empty, transforms are computed with no change in
971  /// scale.
972  /// \param orientations - array containing all instance orientations. This
973  /// array must be either the same size as
974  /// \p protoIndices or empty. If it is empty,
975  /// transforms are computed with no change in
976  /// orientation
977  /// \param angularVelocities - array containing all instance angular
978  /// velocities. This array must be either the
979  /// same size as \p protoIndices or empty. If it
980  /// is empty, transforms are computed as if all
981  /// angular velocities were zero in all
982  /// dimensions.
983  /// \param angularVelocitiesSampleTime - time at which the samples from
984  /// \p angularVelocities were taken.
985  /// \param protoPaths - array containing the paths for all instance
986  /// prototypes. If this array is not empty, prototype
987  /// transforms are applied to the instance transforms.
988  /// \param mask - vector containing a mask to apply to the computed result.
989  /// This vector must be either the same size as
990  /// \p protoIndices or empty. If it is empty, no mask is
991  /// applied.
992  /// \param velocityScale - \deprecated.
994  static bool
996  VtArray<GfMatrix4d>* xforms,
997  UsdStageWeakPtr& stage,
999  const VtIntArray& protoIndices,
1000  const VtVec3fArray& positions,
1001  const VtVec3fArray& velocities,
1002  UsdTimeCode velocitiesSampleTime,
1003  const VtVec3fArray& accelerations,
1004  const VtVec3fArray& scales,
1005  const VtQuatfArray& orientations,
1006  const VtVec3fArray& angularVelocities,
1007  UsdTimeCode angularVelocitiesSampleTime,
1008  const SdfPathVector& protoPaths,
1009  const std::vector<bool>& mask,
1010  float velocityScale = 1.0);
1011 
1012  /// \overload Perform the per-instance transform computation as described
1013  /// in \ref UsdGeomPointInstancer_transform . This does the same
1014  /// computation as the static ComputeInstanceTransformsAtTime method, but
1015  /// supports half precision rotations
1016  USDGEOM_API
1017  static bool
1019  VtArray<GfMatrix4d>* xforms,
1020  UsdStageWeakPtr& stage,
1021  UsdTimeCode time,
1022  const VtIntArray& protoIndices,
1023  const VtVec3fArray& positions,
1024  const VtVec3fArray& velocities,
1025  UsdTimeCode velocitiesSampleTime,
1026  const VtVec3fArray& accelerations,
1027  const VtVec3fArray& scales,
1028  const VtQuathArray& orientations,
1029  const VtVec3fArray& angularVelocities,
1030  UsdTimeCode angularVelocitiesSampleTime,
1031  const SdfPathVector& protoPaths,
1032  const std::vector<bool>& mask,
1033  float velocityScale = 1.0);
1034 
1035 private:
1036 
1037  // Get the authored prototype paths. Fail if there are no authored prototype
1038  // paths or the prototype indices are out of bounds.
1039  bool _GetPrototypePathsForInstanceTransforms(
1040  const VtIntArray& protoIndices,
1041  SdfPathVector* protoPaths) const;
1042 
1043  // Get the authored prototype indices for instance transform computation.
1044  // Fail if prototype indices are not authored.
1045  bool _GetProtoIndicesForInstanceTransforms(
1046  UsdTimeCode baseTime,
1047  VtIntArray* protoIndices) const;
1048 
1049  // Fetches data from attributes specific to UsdGeomPointInstancer
1050  // required for instance transform calculations; this includes
1051  // protoIndices, protoPaths, and the mask.
1052  bool _ComputePointInstancerAttributesPreamble(
1053  const UsdTimeCode baseTime,
1054  const ProtoXformInclusion doProtoXforms,
1055  const MaskApplication applyMask,
1056  VtIntArray* protoIndices,
1057  SdfPathVector* protoPaths,
1058  std::vector<bool>* mask) const;
1059 
1060  /// Compute the per-instance transforms as in
1061  /// ComputeInstanceTransformsAtTime, but using multiple sample times.
1062  /// Returns am array of matrix arrays where each matrix array contains the
1063  /// instance transforms for the corresponding time in \p times . Templated
1064  /// to support both full and half precision rotations.
1065  template<class QuatType>
1066  bool _DoComputeInstanceTransformsAtTimes(
1067  std::vector<VtArray<GfMatrix4d>>* xformsArray,
1068  const std::vector<UsdTimeCode>& times,
1069  const UsdTimeCode baseTime,
1070  const ProtoXformInclusion doProtoXforms,
1071  const MaskApplication applyMask,
1072  const UsdAttribute orientationsAttr) const;
1073 
1074  /// Helper implementation for static ComputeInstanceTransformsAtTime
1075  template <class QuatType>
1076  static bool _DoComputeInstanceTransformsAtTime(
1077  VtArray<GfMatrix4d>* xforms,
1078  UsdStageWeakPtr& stage,
1079  UsdTimeCode time,
1080  const VtIntArray& protoIndices,
1081  const VtVec3fArray& positions,
1082  const VtVec3fArray& velocities,
1083  UsdTimeCode velocitiesSampleTime,
1084  const VtVec3fArray& accelerations,
1085  const VtVec3fArray& scales,
1086  const VtArray<QuatType>& orientations,
1087  const VtVec3fArray& angularVelocities,
1088  UsdTimeCode angularVelocitiesSampleTime,
1089  const SdfPathVector& protoPaths,
1090  const std::vector<bool>& mask,
1091  float velocityScale = 1.0);
1092 
1093 public:
1094 
1095  /// Compute the extent of the point instancer based on the per-instance,
1096  /// "PointInstancer relative" transforms at \p time, as described in
1097  /// \ref UsdGeomPointInstancer_transform .
1098  ///
1099  /// If there is no error, we return \c true and \p extent will be the
1100  /// tightest bounds we can compute efficiently. If an error occurs,
1101  /// \c false will be returned and \p extent will be left untouched.
1102  ///
1103  /// For now, this uses a UsdGeomBBoxCache with the "default", "proxy", and
1104  /// "render" purposes.
1105  ///
1106  /// \param extent - the out parameter for the extent. On success, it will
1107  /// contain two elements representing the min and max.
1108  /// \param time - UsdTimeCode at which we want to evaluate the extent
1109  /// \param baseTime - required for correct interpolation between samples
1110  /// when \em velocities or \em angularVelocities are
1111  /// present. If there are samples for \em positions and
1112  /// \em velocities at t1 and t2, normal value resolution
1113  /// would attempt to interpolate between the two samples,
1114  /// and if they could not be interpolated because they
1115  /// differ in size (common in cases where velocity is
1116  /// authored), will choose the sample at t1. When
1117  /// sampling for the purposes of motion-blur, for example,
1118  /// it is common, when rendering the frame at t2, to
1119  /// sample at [ t2-shutter/2, t2+shutter/2 ] for a
1120  /// shutter interval of \em shutter. The first sample
1121  /// falls between t1 and t2, but we must sample at t2
1122  /// and apply velocity-based interpolation based on those
1123  /// samples to get a correct result. In such scenarios,
1124  /// one should provide a \p baseTime of t2 when querying
1125  /// \em both samples. If your application does not care
1126  /// about off-sample interpolation, it can supply the
1127  /// same value for \p baseTime that it does for \p time.
1128  /// When \p baseTime is less than or equal to \p time,
1129  /// we will choose the lower bracketing timeSample.
1130  USDGEOM_API
1131  bool ComputeExtentAtTime(
1132  VtVec3fArray* extent,
1133  const UsdTimeCode time,
1134  const UsdTimeCode baseTime) const;
1135 
1136  /// \overload
1137  /// Computes the extent as if the matrix \p transform was first applied.
1138  USDGEOM_API
1139  bool ComputeExtentAtTime(
1140  VtVec3fArray* extent,
1141  const UsdTimeCode time,
1142  const UsdTimeCode baseTime,
1143  const GfMatrix4d& transform) const;
1144 
1145  /// Compute the extent of the point instancer as in
1146  /// \ref ComputeExtentAtTime , but across multiple \p times . This is
1147  /// equivalent to, but more efficient than, calling ComputeExtentAtTime
1148  /// several times. Each element in \p extents is the computed extent at the
1149  /// corresponding time in \p times .
1150  ///
1151  /// As in \ref ComputeExtentAtTime, if there is no error, we return \c true
1152  /// and \p extents will be the tightest bounds we can compute efficiently.
1153  /// If an error occurs computing the extent at any time, \c false will be
1154  /// returned and \p extents will be left untouched.
1155  ///
1156  /// \param times - A vector containing the UsdTimeCodes at which we want to
1157  /// sample.
1158  USDGEOM_API
1159  bool ComputeExtentAtTimes(
1160  std::vector<VtVec3fArray>* extents,
1161  const std::vector<UsdTimeCode>& times,
1162  const UsdTimeCode baseTime) const;
1163 
1164  /// \overload
1165  /// Computes the extent as if the matrix \p transform was first applied at
1166  /// each time.
1167  USDGEOM_API
1168  bool ComputeExtentAtTimes(
1169  std::vector<VtVec3fArray>* extents,
1170  const std::vector<UsdTimeCode>& times,
1171  const UsdTimeCode baseTime,
1172  const GfMatrix4d& transform) const;
1173 
1174  /// Returns the number of instances as defined by the size of the
1175  /// _protoIndices_ array at _timeCode_.
1176  ///
1177  /// \snippetdoc snippets.dox GetCount
1178  /// \sa GetProtoIndicesAttr()
1179  USDGEOM_API
1180  size_t GetInstanceCount(UsdTimeCode timeCode = UsdTimeCode::Default()) const;
1181 
1182 private:
1183 
1184  bool _ComputeExtentAtTimePreamble(
1185  UsdTimeCode baseTime,
1186  VtIntArray* protoIndices,
1187  std::vector<bool>* mask,
1188  UsdRelationship* prototypes,
1189  SdfPathVector* protoPaths) const;
1190 
1191  bool _ComputeExtentFromTransforms(
1192  VtVec3fArray* extent,
1193  const VtIntArray& protoIndices,
1194  const std::vector<bool>& mask,
1195  const UsdRelationship& prototypes,
1196  const SdfPathVector& protoPaths,
1197  const VtMatrix4dArray& instanceTransforms,
1198  UsdTimeCode time,
1199  const GfMatrix4d* transform) const;
1200 
1201  bool _ComputeExtentAtTime(
1202  VtVec3fArray* extent,
1203  const UsdTimeCode time,
1204  const UsdTimeCode baseTime,
1205  const GfMatrix4d* transform) const;
1206 
1207  bool _ComputeExtentAtTimes(
1208  std::vector<VtVec3fArray>* extent,
1209  const std::vector<UsdTimeCode>& times,
1210  const UsdTimeCode baseTime,
1211  const GfMatrix4d* transform) const;
1212 };
1213 
1214 template <class T>
1215 bool
1217  VtArray<T> *dataArray,
1218  const int elementSize)
1219 {
1220  if (!dataArray) {
1221  TF_CODING_ERROR("NULL dataArray.");
1222  return false;
1223  }
1224  size_t maskSize = mask.size();
1225  if (maskSize == 0 || dataArray->size() == (size_t)elementSize){
1226  return true;
1227  }
1228  else if ((maskSize * elementSize) != dataArray->size()){
1229  TF_WARN("Input mask's size (%zu) is not compatible with the "
1230  "input dataArray (%zu) and elementSize (%d).",
1231  maskSize, dataArray->size(), elementSize);
1232  return false;
1233  }
1234 
1235  T* beginData = dataArray->data();
1236  T* currData = beginData;
1237  size_t numPreserved = 0;
1238  for (size_t i = 0; i < maskSize; ++i) {
1239  // XXX Could add a fast-path for elementSize == 1 ?
1240  if (mask[i]) {
1241  for (int j = 0; j < elementSize; ++j) {
1242  *currData = beginData[i + j];
1243  ++currData;
1244  }
1245  numPreserved += elementSize;
1246  }
1247  }
1248  if (numPreserved < dataArray->size()) {
1249  dataArray->resize(numPreserved);
1250  }
1251  return true;
1252 }
1253 
1254 /// Returns true if list ops should be composed with SdfListOp::ApplyOperations()
1255 /// Returns false if list ops should be composed with SdfListOp::ComposeOperations().
1257 bool
1259 
1260 /// Applies a list operation of type \p op using \p items
1261 /// over the existing list operation on \p prim with the name
1262 /// \p metadataName.
1263 USDGEOM_API
1264 bool
1265 UsdGeomPointInstancerSetOrMergeOverOp(std::vector<int64_t> const &items,
1266  SdfListOpType op,
1267  UsdPrim const &prim,
1268  TfToken const &metadataName);
1269 
1271 
1272 #endif
Exclude the transform on the proto's root.
UsdGeomPointInstancer(const UsdSchemaBase &schemaObj)
Compute and apply the PointInstancer mask.
USDGEOM_API UsdRelationship CreatePrototypesRel() const
USDGEOM_API bool DeactivateIds(VtInt64Array const &ids) const
static constexpr UsdTimeCode Default()
Definition: timeCode.h:112
USDGEOM_API bool ComputeExtentAtTimes(std::vector< VtVec3fArray > *extents, const std::vector< UsdTimeCode > &times, const UsdTimeCode baseTime) const
USDGEOM_API UsdAttribute CreateOrientationsAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
GT_API const UT_StringHolder time
USDGEOM_API UsdAttribute CreatePositionsAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
USDGEOM_API UsdAttribute CreateIdsAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
USDGEOM_API bool UsesOrientationsf(UsdAttribute &rotationsAttr) const
#define TF_CODING_ERROR
static const UsdSchemaKind schemaKind
USDGEOM_API bool ActivateId(int64_t id) const
USDGEOM_API UsdRelationship GetPrototypesRel() const
USDGEOM_API UsdAttribute CreateAngularVelocitiesAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
UsdGeomPointInstancer(const UsdPrim &prim=UsdPrim())
USDGEOM_API UsdAttribute CreateAccelerationsAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
UsdStagePtr UsdStageWeakPtr
Definition: common.h:55
USDGEOM_API UsdAttribute CreateScalesAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
USDGEOM_API UsdAttribute CreateProtoIndicesAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
static bool ApplyMaskToArray(std::vector< bool > const &mask, VtArray< T > *dataArray, const int elementSize=1)
static USDGEOM_API const TfTokenVector & GetSchemaAttributeNames(bool includeInherited=true)
Definition: token.h:87
Represents a concrete typed schema.
USDGEOM_API UsdAttribute GetOrientationsAttr() const
USDGEOM_API UsdAttribute GetPositionsAttr() const
USDGEOM_API bool InvisIds(VtInt64Array const &ids, UsdTimeCode const &time) const
SdfListOpType
Definition: listOp.h:46
#define TF_WARN
USDGEOM_API size_t GetInstanceCount(UsdTimeCode timeCode=UsdTimeCode::Default()) const
USDGEOM_API bool UsdGeomPointInstancerSetOrMergeOverOp(std::vector< int64_t > const &items, SdfListOpType op, UsdPrim const &prim, TfToken const &metadataName)
GLint GLuint mask
Definition: glcorearb.h:124
USDGEOM_API UsdAttribute GetScalesAttr() const
USDGEOM_API UsdAttribute GetAccelerationsAttr() const
Definition: prim.h:133
virtual USDGEOM_API ~UsdGeomPointInstancer()
Destructor.
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:457
USDGEOM_API bool ComputeExtentAtTime(VtVec3fArray *extent, const UsdTimeCode time, const UsdTimeCode baseTime) const
Definition: types.h:170
Definition: path.h:290
static USDGEOM_API UsdGeomPointInstancer Get(const UsdStagePtr &stage, const SdfPath &path)
USDGEOM_API std::vector< bool > ComputeMaskAtTime(UsdTimeCode time, VtInt64Array const *ids=nullptr) const
GA_API const UT_StringHolder transform
std::vector< class SdfPath > SdfPathVector
A vector of SdfPaths.
Definition: path.h:211
USDGEOM_API UsdSchemaKind _GetSchemaKind() const override
USDGEOM_API UsdAttribute CreateInvisibleIdsAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
USDGEOM_API bool UsdGeomPointInstancerApplyNewStyleListOps()
USDGEOM_API UsdAttribute GetVelocitiesAttr() const
UsdSchemaKind
Definition: common.h:129
GLint j
Definition: glad.h:2733
GLsizeiptr size
Definition: glcorearb.h:664
USDGEOM_API UsdAttribute GetAngularVelocitiesAttr() const
USDGEOM_API bool VisId(int64_t id, UsdTimeCode const &time) const
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1432
USDGEOM_API UsdAttribute GetInvisibleIdsAttr() const
USDGEOM_API bool ActivateAllIds() const
USDGEOM_API UsdAttribute GetOrientationsfAttr() const
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
USDGEOM_API bool InvisId(int64_t id, UsdTimeCode const &time) const
Definition: type.h:64
static USDGEOM_API UsdGeomPointInstancer Define(const UsdStagePtr &stage, const SdfPath &path)
USDGEOM_API bool VisIds(VtInt64Array const &ids, UsdTimeCode const &time) const
USDGEOM_API bool ActivateIds(VtInt64Array const &ids) const
USDGEOM_API UsdAttribute CreateVelocitiesAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
USDGEOM_API bool ComputeInstanceTransformsAtTime(VtArray< GfMatrix4d > *xforms, const UsdTimeCode time, const UsdTimeCode baseTime, const ProtoXformInclusion doProtoXforms=IncludeProtoXform, const MaskApplication applyMask=ApplyMask) const
#define USDGEOM_API
Definition: api.h:40
USDGEOM_API bool VisAllIds(UsdTimeCode const &time) const
USDGEOM_API UsdAttribute GetProtoIndicesAttr() const
Ignore the PointInstancer mask.
GLuint * ids
Definition: glcorearb.h:652
USDGEOM_API bool ComputeInstanceTransformsAtTimes(std::vector< VtArray< GfMatrix4d >> *xformsArray, const std::vector< UsdTimeCode > &times, const UsdTimeCode baseTime, const ProtoXformInclusion doProtoXforms=IncludeProtoXform, const MaskApplication applyMask=ApplyMask) const
Definition: value.h:164
USDGEOM_API UsdAttribute CreateOrientationsfAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
USDGEOM_API UsdAttribute GetIdsAttr() const
USDGEOM_API bool DeactivateId(int64_t id) const
Include the transform on the proto's root.