HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HUSD_Xform.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  */
17 
18 #ifndef __HUSD_Xform_h__
19 #define __HUSD_Xform_h__
20 
21 #include "HUSD_API.h"
22 #include "HUSD_DataHandle.h"
23 #include "HUSD_Path.h"
24 #include "HUSD_TimeCode.h"
25 
26 #include <OP/OP_ItemId.h>
27 #include <UT/UT_Matrix4.h>
28 #include <UT/UT_StringHolder.h>
29 #include <UT/UT_StringMap.h>
30 #include <UT/UT_XformOrder.h>
31 
32 class HUSD_FindPrims;
33 enum class HUSD_XformAxis;
34 enum class HUSD_XformAxisOrder;
35 enum class HUSD_TimeSampling;
36 
38 {
53 };
54 
56 {
57  return (style == HUSD_XFORM_BASIC_COMMON_API_APPEND ||
60 }
61 
63 {
64  return (style == HUSD_XFORM_COMMON_API_APPEND ||
68 }
69 
71 {
72 public:
74  {
79  };
80 
81  // Default-construct: identity matrix
83 
84  // Matrix constructor
86  const UT_Matrix4D &matrix,
87  const HUSD_TimeCode &timecode,
88  bool write_pivot = false,
89  const UT_Vector3D &pivot = UT_Vector3D(0.0),
90  const UT_Vector3D &pivot_rotate = UT_Vector3D(0.0),
94  );
95 
96  // Component constructor
98  const HUSD_XformEntryComponents &components,
99  const HUSD_TimeCode &timecode,
100  bool write_pivot = false,
101  const UT_Vector3D &pivot = UT_Vector3D(0.0),
102  const UT_Vector3D &pivot_rotate = UT_Vector3D(0.0),
106  );
107 
108  // Set the active member and the mode flag
109  void setXformMatrix(const UT_Matrix4D &matrix);
110  void setXformComponents(
111  const HUSD_XformEntryComponents &components);
112 
113  // Returns a matrix regardless of the underlying representation. If the
114  // entry holds components, compose them with myOrder and
115  // PivotSpace(myPivot, myPivotRotate).
116  UT_Matrix4D getXformMatrix() const;
117 
118  // Returns components regardless of the underlying representation. If
119  // the entry holds a matrix, decompose it using explode()
120  // with the same order and PivotSpace
122  getXformComponents() const;
123 
124  bool useXformComponents() const
125  { return myUseXformComponents; }
126 
130  UT_Vector3D myPivot{0.,0.,0.};
131  UT_Vector3D myPivotRotate{0.,0.,0.};
132  // If true, overwrite with myPivot/myPivotRotate
133  // If false, preserve the pivot already authored on the prim
134  bool myWritePivot = false;
135 
136 private:
137  union
138  {
141  };
142  bool myUseXformComponents = false;
143 };
146 
148 {
149 public:
152  const UT_StringHolder &lookat_prim,
153  const UT_Vector3D &lookat_pos,
154  const UT_Vector3D &up_vec,
155  fpreal twist,
156  const HUSD_TimeCode &timecode);
157 
159  UT_Vector3D myLookAtPos{0., 0., 0.};
160  UT_Vector3D myUpVec{0., 1., 0.};
161  fpreal myTwist = 0.0;
163 };
166 
168 {
169 public:
171  int prim_editor_node_id = OP_INVALID_NODE_ID);
172  ~HUSD_Xform();
173 
174  // Append an entry for each prim matched by findprims to xform_map.
175  // Used to accumulate entries across multiple calls (e.g. one per
176  // time sample), to be committed by a single applyXforms call.
177  void appendToXformMap(const HUSD_FindPrims &findprims,
178  const UT_Matrix4D *xform,
180  *components,
181  const HUSD_TimeCode &timecode,
182  const UT_Vector3D *pivot,
183  const UT_Vector3D *pivot_rotate,
184  const UT_XformOrder *xform_order,
185  HUSD_XformEntryMap &xform_map) const;
186 
187  // For each primpath apply the corresponding xform
188  bool applyXforms(const HUSD_XformEntryMap &xform_map,
189  const UT_StringRef &name_suffix,
190  HUSD_XformStyle xform_style) const;
191 
192  // Append a lookat entry for each prim matched by findprims to lookat_map.
193  // Used to accumulate entries across multiple calls (e.g. one per
194  // time sample), to be committed by a single applyLookAts call.
195  void appendToLookAtMap(const HUSD_FindPrims &findprims,
196  const UT_StringRef &lookat_prim,
197  const UT_Vector3D &lookat_pos,
198  const UT_Vector3D &up_vec,
199  fpreal twist,
200  const HUSD_TimeCode &timecode,
201  HUSD_LookAtEntryMap &lookat_map) const;
202 
203  // Author a "lookat" xformOp for every (prim, timecode) entry in
204  // lookat_map. All world-xform reads happen before any authoring, so
205  // entries observe a consistent pre-author state and no identity-reset
206  // of the lookat op is needed.
207  bool applyLookAts(
208  const HUSD_LookAtEntryMap &lookat_map) const;
209 
210  /// @{ Add a given transform operation to the given primitives.
211  /// The @p name_suffix is used to construct the transform operation full
212  /// name. The transform name is equivalent to the full attribute name
213  /// and the the entry in the transform order string array attribute.
214  ///
215  /// When @p is_timecode_strict is true, the op attriubte is set at a given
216  /// time code, otherwise the given time code, if it's the default value,
217  /// may be cast to a specific frame time code, if the attribute
218  /// has some time samples already.
219  ///
220  /// See HUSD_Info::getXformName().
221  bool addXform(const HUSD_FindPrims &findprims,
222  const UT_StringRef &name_suffix,
223  const UT_Matrix4D &xform,
224  const HUSD_TimeCode &timecode,
225  bool is_timecode_strict = true) const;
226  bool addTranslate(const HUSD_FindPrims &findprims,
227  const UT_StringRef &name_suffix,
228  const UT_Vector3D &t,
229  const HUSD_TimeCode &timecode,
230  bool is_timecode_strict = true) const;
231  bool addRotate(const HUSD_FindPrims &findprims,
232  const UT_StringRef &name_suffix,
233  HUSD_XformAxisOrder xyz_order,
234  const UT_Vector3D &r,
235  const HUSD_TimeCode &timecode,
236  bool is_timecode_strict = true) const;
237  bool addRotate(const HUSD_FindPrims &findprims,
238  const UT_StringRef &name_suffix,
239  HUSD_XformAxis xyz_axis, double angle,
240  const HUSD_TimeCode &timecode,
241  bool is_timecode_strict = true) const;
242  bool addScale(const HUSD_FindPrims &findprims,
243  const UT_StringRef &name_suffix,
244  const UT_Vector3D &s,
245  const HUSD_TimeCode &timecode,
246  bool is_timecode_strict = true) const;
247  bool addOrient(const HUSD_FindPrims &findprims,
248  const UT_StringRef &name_suffix,
249  const UT_QuaternionD &o,
250  const HUSD_TimeCode &timecode,
251  bool is_timecode_strict = true) const;
252  /// @}
253 
254  /// @{ Appends the given transform to the given primitives.
255  /// The @p full_name is the transform operation full name,
256  /// which is equivalent to the full attribute name and the entry in
257  /// the transform order string array attribute.
258  /// See HUSD_Info::getXformName().
259  bool addToXformOrder(const HUSD_FindPrims &findprims,
260  const UT_StringRef &full_name) const;
261  bool addInverseToXformOrder(const HUSD_FindPrims &findprims,
262  const UT_StringRef &full_name) const;
263  /// @}
264 
265  /// Sets the transform order attribute to the given sequence of transform
266  /// operations. The @order contains transforms full names (see above).
267  bool setXformOrder(const HUSD_FindPrims &findprims,
268  const UT_StringArray &order) const;
269 
270  /// Clears the primitive's xform order string array attribute,
271  /// effectively earasing the local transform.
272  bool clearXformOrder(const HUSD_FindPrims &findprims) const;
273 
274  /// Sets the flag to ignore primitive parent's transform, when calculating
275  /// world transform of this primitive. Ie, if the reset flag is set,
276  /// the primitive does not inherit the transformation from the parent.
277  bool setXformReset( const HUSD_FindPrims &findprims,
278  bool reset) const;
279 
280  /// Control whether or not warnings should be added if this object is
281  /// told to transform a prim that is not xformable. Defaults to true.
282  void setWarnBadPrimTypes(bool warn_bad_prim_types)
283  { myWarnBadPrimTypes = warn_bad_prim_types; }
284  bool warnBadPrimTypes() const
285  { return myWarnBadPrimTypes; }
286 
287  /// Control whether or not this operation should check for the
288  /// "houdini:editable" attribute on primitives before transforming them.
289  /// Warnings are added for prims with this flag set to false.
290  void setCheckEditableFlag(bool check_editable_flag)
291  { myCheckEditableFlag = check_editable_flag; }
292  bool checkEditableFlag() const
293  { return myCheckEditableFlag; }
294 
295  /// Control whether or not this operation should check for the
296  /// "houdini:editable" attribute on primitives before transforming them.
297  /// Warnings are added for prims with this flag set to false.
298  void setClearExistingFlag(bool clear_existing_flag)
299  { myClearExistingFlag = clear_existing_flag; }
300  bool clearExistingFlag() const
301  { return myClearExistingFlag; }
302 
303  /// Returns true if the transform that was set on primitives
304  /// may be time-varying.
305  bool getIsTimeVarying() const;
306 
307 private:
308  HUSD_AutoWriteLock &myWriteLock;
309  int myPrimEditorNodeId;
310  bool myWarnBadPrimTypes;
311  bool myCheckEditableFlag;
312  bool myClearExistingFlag;
313  mutable HUSD_TimeSampling myTimeSampling;
314 };
315 
316 #endif
317 
UT_Matrix4D myXformMatrix
Definition: HUSD_Xform.h:139
UT_Vector3D myR
Definition: HUSD_Xform.h:76
SIM_API const UT_StringHolder angle
HUSD_XformStyle
Definition: HUSD_Xform.h:37
int myOrder
Definition: GT_CurveEval.h:263
UT_StringMap< HUSD_XformEntryArray > HUSD_XformEntryMap
Definition: HUSD_Xform.h:145
Transformation order of scales, rotates, and translates.
Definition: UT_XformOrder.h:23
void setCheckEditableFlag(bool check_editable_flag)
Definition: HUSD_Xform.h:290
bool clearExistingFlag() const
Definition: HUSD_Xform.h:300
GA_API const UT_StringHolder twist
UT_Vector3D myShear
Definition: HUSD_Xform.h:78
#define HUSD_API
Definition: HUSD_API.h:31
GLdouble s
Definition: glad.h:3009
Definition: HUSD_Xform.h:73
UT_Vector3D myS
Definition: HUSD_Xform.h:77
#define OP_INVALID_NODE_ID
Definition: OP_ItemId.h:24
HUSD_XformAxis
Enum of rotation axis.
Definition: HUSD_Utils.h:343
Definition: HUSD_Xform.h:147
bool useXformComponents() const
Definition: HUSD_Xform.h:124
HUSD_TimeCode myTimeCode
Definition: HUSD_Xform.h:127
GLboolean reset
Definition: glad.h:5138
UT_StringHolder myLookAtPrim
Definition: HUSD_Xform.h:158
HUSD_TimeCode myTimeCode
Definition: HUSD_Xform.h:162
HUSD_TimeSampling
Definition: HUSD_Utils.h:104
GLdouble GLdouble GLint GLint order
Definition: glad.h:2676
void setWarnBadPrimTypes(bool warn_bad_prim_types)
Definition: HUSD_Xform.h:282
UT_Vector3T< fpreal64 > UT_Vector3D
GLdouble t
Definition: glad.h:2397
fpreal64 fpreal
Definition: SYS_Types.h:283
UT_Array< HUSD_XformEntry > HUSD_XformEntryArray
Definition: HUSD_Xform.h:144
bool HUSDisBasicXformAPIStyle(HUSD_XformStyle style)
Definition: HUSD_Xform.h:55
bool warnBadPrimTypes() const
Definition: HUSD_Xform.h:284
HUSD_XformAxisOrder
Enum of rotation order.
Definition: HUSD_Utils.h:346
GA_API const UT_StringHolder pivot
GU_API void xform(CE_Context &context, bool recompile, int npts, const cl::Buffer &outPos, const cl::Buffer &inPos, const cl::Buffer &surfacexform, const cl::Buffer *grp=nullptr)
UT_Array< HUSD_LookAtEntry > HUSD_LookAtEntryArray
Definition: HUSD_Xform.h:164
Definition: HUSD_Xform.h:70
HUSD_XformEntryComponents myXformComponents
Definition: HUSD_Xform.h:140
GLboolean r
Definition: glcorearb.h:1222
void setClearExistingFlag(bool clear_existing_flag)
Definition: HUSD_Xform.h:298
bool checkEditableFlag() const
Definition: HUSD_Xform.h:292
bool HUSDisExtendedXformAPIStyle(HUSD_XformStyle style)
Definition: HUSD_Xform.h:62
UT_StringMap< HUSD_LookAtEntryArray > HUSD_LookAtEntryMap
Definition: HUSD_Xform.h:165
UT_Vector3D myT
Definition: HUSD_Xform.h:75