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 #include <UT/UT_Matrix4.h>
26 #include <UT/UT_StringHolder.h>
27 #include <UT/UT_StringMap.h>
28 
29 class HUSD_FindPrims;
30 enum class HUSD_XformAxis;
31 enum class HUSD_XformAxisOrder;
32 enum class HUSD_TimeSampling;
33 
35 {
43 };
44 
46 {
47 public:
50 };
53 
55 {
56 public:
58  ~HUSD_Xform();
59 
60  // Apply a single transform to all primitives
61  bool applyXforms(const HUSD_FindPrims &findprims,
62  const UT_StringRef &name_suffix,
63  const UT_Matrix4D &xform,
64  const HUSD_TimeCode &timecode,
65  HUSD_XformStyle xform_style,
67  suffix_map = nullptr) const;
68 
69  // For each primpath apply the corresponding xform
70  bool applyXforms(const HUSD_XformEntryMap &xform_map,
71  const UT_StringRef &name_suffix,
72  HUSD_XformStyle xform_style,
74  suffix_map = nullptr) const;
75 
76  // Create a new xform to make a prim look at a point in space, which
77  // may be in the local space of some other prim.
78  bool applyLookAt(const HUSD_FindPrims &findprims,
79  const UT_StringRef &lookatprim,
80  const UT_Vector3D &lookatpos,
81  const UT_Vector3D &upvec,
82  fpreal twist,
83  const HUSD_TimeCode &timecode,
85  suffix_map = nullptr) const;
86 
87  /// @{ Add a given transform operation to the given primitives.
88  /// The @p name_suffix is used to construct the transform operation full
89  /// name. The transform name is equivalent to the full attribute name
90  /// and the the entry in the transform order string array attribute.
91  ///
92  /// When @p is_timecode_strict is true, the op attriubte is set at a given
93  /// time code, otherwise the given time code, if it's the default value,
94  /// may be cast to a specific frame time code, if the attribute
95  /// has some time samples already.
96  ///
97  /// See HUSD_Info::getXformName().
98  bool addXform(const HUSD_FindPrims &findprims,
99  const UT_StringRef &name_suffix,
100  const UT_Matrix4D &xform,
101  const HUSD_TimeCode &timecode,
102  bool is_timecode_strict = true) const;
103  bool addTranslate(const HUSD_FindPrims &findprims,
104  const UT_StringRef &name_suffix,
105  const UT_Vector3D &t,
106  const HUSD_TimeCode &timecode,
107  bool is_timecode_strict = true) const;
108  bool addRotate(const HUSD_FindPrims &findprims,
109  const UT_StringRef &name_suffix,
110  HUSD_XformAxisOrder xyz_order,
111  const UT_Vector3D &r,
112  const HUSD_TimeCode &timecode,
113  bool is_timecode_strict = true) const;
114  bool addRotate(const HUSD_FindPrims &findprims,
115  const UT_StringRef &name_suffix,
116  HUSD_XformAxis xyz_axis, double angle,
117  const HUSD_TimeCode &timecode,
118  bool is_timecode_strict = true) const;
119  bool addScale(const HUSD_FindPrims &findprims,
120  const UT_StringRef &name_suffix,
121  const UT_Vector3D &s,
122  const HUSD_TimeCode &timecode,
123  bool is_timecode_strict = true) const;
124  bool addOrient(const HUSD_FindPrims &findprims,
125  const UT_StringRef &name_suffix,
126  const UT_QuaternionD &o,
127  const HUSD_TimeCode &timecode,
128  bool is_timecode_strict = true) const;
129  /// @}
130 
131  /// @{ Appends the given transform to the given primitives.
132  /// The @p full_name is the transform operation full name,
133  /// which is equivalent to the full attribute name and the entry in
134  /// the transform order string array attribute.
135  /// See HUSD_Info::getXformName().
136  bool addToXformOrder(const HUSD_FindPrims &findprims,
137  const UT_StringRef &full_name) const;
138  bool addInverseToXformOrder(const HUSD_FindPrims &findprims,
139  const UT_StringRef &full_name) const;
140  /// @}
141 
142  /// Sets the transform order attribute to the given sequence of transform
143  /// operations. The @order contains transforms full names (see above).
144  bool setXformOrder(const HUSD_FindPrims &findprims,
145  const UT_StringArray &order) const;
146 
147  /// Clears the primitive's xform order string array attribute,
148  /// effectively earasing the local transform.
149  bool clearXformOrder(const HUSD_FindPrims &findprims) const;
150 
151  /// Sets the flag to ignore primitive parent's transform, when calculating
152  /// world transform of this primitive. Ie, if the reset flag is set,
153  /// the primitive does not inherit the transformation from the parent.
154  bool setXformReset( const HUSD_FindPrims &findprims,
155  bool reset) const;
156 
157  /// Control whether or not warnings should be added if this object is
158  /// told to transform a prim that is not xformable. Defaults to true.
159  void setWarnBadPrimTypes(bool warn_bad_prim_types)
160  { myWarnBadPrimTypes = warn_bad_prim_types; }
161  bool warnBadPrimTypes() const
162  { return myWarnBadPrimTypes; }
163 
164  /// Control whether or not this operation should check for the
165  /// "houdini:editable" attribute on primitives before transforming them.
166  /// Warnings are added for prims with this flag set to false.
167  void setCheckEditableFlag(bool check_editable_flag)
168  { myCheckEditableFlag = check_editable_flag; }
169  bool checkEditableFlag() const
170  { return myCheckEditableFlag; }
171 
172  /// Control whether or not this operation should check for the
173  /// "houdini:editable" attribute on primitives before transforming them.
174  /// Warnings are added for prims with this flag set to false.
175  void setClearExistingFlag(bool clear_existing_flag)
176  { myClearExistingFlag = clear_existing_flag; }
177  bool clearExistingFlag() const
178  { return myClearExistingFlag; }
179 
180  /// Returns true if the transform that was set on primitives
181  /// may be time-varying.
182  bool getIsTimeVarying() const;
183 
184 private:
185  HUSD_AutoWriteLock &myWriteLock;
186  bool myWarnBadPrimTypes;
187  bool myCheckEditableFlag;
188  bool myClearExistingFlag;
189  mutable HUSD_TimeSampling myTimeSampling;
190 };
191 
192 #endif
193 
GLuint GLdouble GLdouble GLint GLint order
Definition: glew.h:3460
Unsorted map container.
Definition: UT_Map.h:107
HUSD_XformStyle
Definition: HUSD_Xform.h:34
UT_StringMap< HUSD_XformEntryArray > HUSD_XformEntryMap
Definition: HUSD_Xform.h:52
void setCheckEditableFlag(bool check_editable_flag)
Definition: HUSD_Xform.h:167
bool clearExistingFlag() const
Definition: HUSD_Xform.h:177
GA_API const UT_StringHolder twist
#define HUSD_API
Definition: HUSD_API.h:32
GLdouble GLdouble t
Definition: glew.h:1403
HUSD_XformAxis
Enum of rotation axis.
Definition: HUSD_Utils.h:239
HUSD_TimeCode myTimeCode
Definition: HUSD_Xform.h:49
HUSD_TimeSampling
Definition: HUSD_Utils.h:96
void setWarnBadPrimTypes(bool warn_bad_prim_types)
Definition: HUSD_Xform.h:159
GLboolean reset
Definition: glew.h:4989
UT_Matrix4D myXform
Definition: HUSD_Xform.h:48
fpreal64 fpreal
Definition: SYS_Types.h:277
UT_Array< HUSD_XformEntry > HUSD_XformEntryArray
Definition: HUSD_Xform.h:51
bool warnBadPrimTypes() const
Definition: HUSD_Xform.h:161
HUSD_XformAxisOrder
Enum of rotation order.
Definition: HUSD_Utils.h:242
GLdouble angle
Definition: glew.h:9177
Definition: HUSD_Xform.h:45
GLboolean r
Definition: glcorearb.h:1222
GLdouble s
Definition: glew.h:1395
void setClearExistingFlag(bool clear_existing_flag)
Definition: HUSD_Xform.h:175
bool checkEditableFlag() const
Definition: HUSD_Xform.h:169