HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
XUSD_HydraInstancer.h
Go to the documentation of this file.
1 /*
2  * Copyright 2019 Side Effects Software Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * NAME: XUSD_HydraInstancer.h (HUSD Library, C++)
17  *
18  * COMMENTS: Basic instancer for creating instance transforms.
19  *
20  */
21 
22 #ifndef XUSD_HydraInstancer_h
23 #define XUSD_HydraInstancer_h
24 
25 #include "HUSD_API.h"
26 #include "HUSD_Path.h"
27 #include <UT/UT_Lock.h>
28 #include <UT/UT_Map.h>
29 #include <UT/UT_StringMap.h>
30 #include <UT/UT_SmallArray.h>
31 #include <UT/UT_UniquePtr.h>
32 #include <GT/GT_Transform.h>
33 #include <GT/GT_TransformArray.h>
34 
35 #include <pxr/pxr.h>
38 #include <pxr/base/tf/hashmap.h>
39 #include <pxr/base/tf/token.h>
40 
41 class HUSD_Scene;
42 
44 
46 {
47 public:
49  SdfPath const& id);
50  ~XUSD_HydraInstancer() override;
51 
52  void Sync(HdSceneDelegate* delegate,
53  HdRenderParam* renderParam,
54  HdDirtyBits* dirtyBits) override;
55 
56  // Grab the transforms for this instancer, and flatten it with any parent
57  // instancers if 'recurse' is true. syncPrimvars() must be called first.
58  VtMatrix4dArray computeTransforms(
59  const SdfPath &protoId,
60  bool recurse,
61  int hou_proto_id);
62 
63  // Grab the transforms and scene ids for each instance. If 'recurse' is
64  // true, flatten both the transforms and ids for nested instancers.
65  // syncPrimvars() must be called first.
66  VtMatrix4dArray computeTransformsAndIDs(
67  const SdfPath &protoId,
68  bool recurse,
69  int level,
71  HUSD_Scene *scene,
72  int hou_proto_id,
73  bool dirty_indices);
74 
75  int id() const { return myID; }
76 
77  const VtValue &primvarValue(const TfToken &name) const;
78 
79 private:
80  // Checks the change tracker to determine whether instance primvars are
81  // dirty, and if so pulls them. Since primvars can only be pulled once,
82  // and are cached, this function is not re-entrant. However, this function
83  // is called by ComputeInstanceTransforms, which is called (potentially)
84  // by HdMantraMesh::Sync(), which is dispatched in parallel, so it needs
85  // to be guarded by _instanceLock.
86  //
87  // Pulled primvars are cached in _primvarMap.
88  void syncPrimvars(HdSceneDelegate* delegate,
89  HdRenderParam* renderParam,
90  HdDirtyBits* dirtyBits);
91 
92  // Map of the latest primvar data for this instancer, keyed by
93  // primvar name. Primvar values are VtValue, an any-type; they are
94  // interpreted at consumption time (here, in ComputeInstanceTransforms).
96 
97  mutable UT_Lock myLock;
98 
99  UT_StringHolder findParentInstancer() const;
100 
101  VtMatrix4dArray privComputeTransforms(const SdfPath &prototypeId,
102  bool recurse,
103  int level,
104  UT_IntArray *ids,
105  HUSD_Scene *scene,
106  int hou_proto_id,
107  bool dirty_indices,
108  XUSD_HydraInstancer *child_instancer);
109 
110  int myID;
111 };
112 
114 {
115 public:
116  XUSD_HydraTransforms() : myDataId(-1) {}
117  ~XUSD_HydraTransforms() override {}
118 
119  void setDataId(int64 id) { myDataId = id; }
120  int64 getDataId() const override { return myDataId; }
121 
122 private:
123  int64 myDataId;
124 };
125 
127 
128 #endif
virtual HD_API void Sync(HdSceneDelegate *sceneDelegate, HdRenderParam *renderParam, HdDirtyBits *dirtyBits)
uint32_t HdDirtyBits
Definition: types.h:158
GLint level
Definition: glcorearb.h:108
#define HUSD_API
Definition: HUSD_API.h:32
Definition: token.h:87
long long int64
Definition: SYS_Types.h:116
GLuint id
Definition: glcorearb.h:655
GLuint const GLchar * name
Definition: glcorearb.h:786
Definition: path.h:291
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1441
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
int64 getDataId() const override
Data id support for derived classes (-1 means always re-update).
GLuint * ids
Definition: glcorearb.h:652
Definition: value.h:167