HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FBX_SceneProxy.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: FBX_SceneProxy.h (FBX Library, C++)
7  *
8  * COMMENTS:
9  *
10  */
11 
12 #ifndef __FBX_SCENEPROXY_H_INCLUDED__
13 #define __FBX_SCENEPROXY_H_INCLUDED__
14 
15 #include "FBX_API.h"
16 #include "FBX_SceneProxySupport.h"
17 #include <GU/GU_DetailHandle.h>
18 #include <OP/OP_Director.h>
19 #include <UT/UT_StringArray.h>
20 #include <UT/UT_UniquePtr.h>
21 #include <UT/UT_VectorTypes.h>
22 #include <UT/UT_TransformUtil.h>
23 #include <SYS/SYS_Types.h>
24 
25 
26 class FBX_ErrorManager;
27 class GU_Detail;
28 
29 FBX_SCENEPROXY_DECLARE_ID(FBX_NodeID);
30 FBX_SCENEPROXY_DECLARE_ID(FBX_GeometryID);
31 FBX_SCENEPROXY_DECLARE_ID(FBX_ClipID);
32 FBX_SCENEPROXY_DECLARE_ID(FBX_AnimCurveID);
33 FBX_SCENEPROXY_DECLARE_ID(FBX_AnimLayerID);
34 
35 FBX_SCENEPROXY_DECLARE_ID(FBX_PropertyID);
36 
37 template <typename T>
38 class FBX_Property : public FBX_PropertyID
39 {
40 public:
41  using value_type = T;
42 
43  using FBX_PropertyID::FBX_PropertyID;
44 
45 private:
46  friend class FBX_SceneProxy;
47 };
49 
51 struct FBX_AxisSystem;
52 
54 {
55 public:
57  {
58  bool myConvertUnits = true;
59  bool myConvertAxisSystem = true;
60  bool myConvertAxisSystemForceYUp = true; // only used when converting
61  bool myImportTemplates = true;
62  bool myImportPivots = true;
63  bool myImportGlobalSettings = true;
64  bool myImportCharacters = true;
65  bool myImportConstraints = true;
66  bool myImportGobos = true;
67  bool myImportShapes = true;
68  bool myImportLinks = true;
69  bool myImportTextures = true;
70  bool myImportModels = true;
71  bool myImportAnimations = true;
72  bool myImportMaterials = false; // should also enable
73  // myExtractEmbeddedMedia when enabling
74  // this.
75  bool myExtractEmbeddedData = false; // evil!
76  };
77 
79  ~FBX_SceneProxy();
80 
81  bool load(const char* path,
82  const LoadOptions& options,
83  FBX_ErrorManager& errors);
84  bool load(const char* path,
85  bool convert_units,
86  FBX_ErrorManager& errors)
87  {
88  LoadOptions options;
89  options.myConvertUnits = convert_units;
90  return load(path, options, errors);
91  }
92 
93  bool save(const char* path,
94  FBX_ErrorManager& errors,
95  bool binary = true,
96  bool animation_only = false) const;
97 
98  fpreal globalFrameRate() const;
99  void setGlobalFrameRate(fpreal fps);
100 
101  void getGlobalTimeRange(fpreal& start, fpreal &stop) const;
102 
103  /// Get the scene's current axis system
104  FBX_AxisSystem globalAxisSystem() const;
105 
106  /// Set the scene's current axis system
107  /// @{
108  void setGlobalAxisSystem(const FBX_AxisSystem& axis_system);
109  void setGlobalAxisSystem(OP_Director::OrientationMode orientation_mode);
110  /// @}
111 
112  /// Convert the scene to the given axis system
113  void convertAxisSystem(const FBX_AxisSystem& target);
114 
115  const char* nodeName(FBX_NodeID node) const;
116  FBX_NodeID findNode(const char* name) const;
117 
118  int nodeCount() const;
119  FBX_NodeID node(int i) const;
120 
121  FBX_NodeID rootNode() const;
122  FBX_NodeID parentNode(FBX_NodeID node) const;
123  int childNodeCount(FBX_NodeID node) const;
124  FBX_NodeID childNode(FBX_NodeID node, int i) const;
125 
126  enum NodeType
127  {
128  eUnknown, // Unknown
129  eNull, // Null object
130  eMarker, // Mocap marker OR IK/FK effector
131  eSkeleton, // Bone/Joint
132  eMesh, // Geometry
133  eNurbs, // Geometry
134  ePatch, // Geometry
135  eCamera, // Camera
136  eCameraStereo, // Stereo camera
137  eCameraSwitcher, // Switch between child cameras
138  eLight, // Light
139  eOpticalReference, // Mocap marker
140  eOpticalMarker, // Mocap marker OR IK/FK effector
141  eNurbsCurve, // Geometry
142  eTrimNurbsSurface, // Geometry
143  eBoundary, // Geometry
144  eNurbsSurface, // Geometry
145  eShape, // Blendshape
146  eLODGroup, // Group of objects with different levels of detail
147  eSubDiv, // Geometry
148  eCachedEffect, // Particles, fluids, hair, etc. cache
149  eLine // Geometry
150  };
151  NodeType nodeType(FBX_NodeID node) const;
152 
153  bool visibility(FBX_NodeID node) const;
154 
155  FBX_GeometryID geometry(FBX_NodeID node) const;
156  FBX_NodeID geometryNode(FBX_GeometryID geometry) const;
157  int geometrySkinDeformerCount(FBX_GeometryID geometry) const;
158 
159  int skinDeformerCount() const;
160  FBX_GeometryID skinDeformerGeometry(int i) const;
161 
162  /// Convert geometry into GU_Detail, with skin deformers converted into
163  /// a boneCapture attribute. If world_xform is given, the result including
164  /// the transforms within boneCapture will have this baked into it.
165  /// When add_unused_joints is true, add ancestor joints for any captured
166  /// joints will also be added to the boneCapture attribute with identity
167  /// transforsm.
168  bool convertGeometry(
169  GU_Detail& detail,
170  FBX_GeometryID geometry,
171  FBX_ErrorManager& errors,
172  bool add_unused_joints,
173  const UT_Matrix4D* world_xform = nullptr) const;
174 
176  {
180  eBlend
181  };
182  /// Returns the skinning type for the i'th skin deformer in the geometry.
183  SkinningType geometrySkinDeformerType(FBX_GeometryID geometry, int i) const;
184 
185  /// Returns the number of blend shape deformers for the geometry.
186  int blendshapeCount(FBX_GeometryID geometry) const;
187  /// Returns the number of channels for the i'th blend shape deformer.
188  int blendshapeChannelCount(
189  FBX_GeometryID geometry, int blendshape_idx) const;
190  /// Returns the name of the specified blendshape channel.
191  UT_StringHolder blendshapeChannelName(FBX_GeometryID geometry,
192  int blendshape_idx, int channel_idx) const;
193 
194  /// Returns the geometry, name, and weight (multiplied by 0.01) for each of
195  /// the channel's target shapes. Multiple targets imply that there are
196  /// in-between shapes, and the shapes are sorted by weight in ascending
197  /// order.
198  void blendShapeChannelTargets(FBX_GeometryID geometry,
199  int blendshape_idx, int channel_idx,
200  UT_Array<GU_DetailHandle> &details,
202 
203  /// Returns curve for the blend shape channel's values.
204  FBX_AnimCurveID blendshapeChannelCurve(FBX_GeometryID geometry,
205  int blendshape_idx, int channel_idx) const;
206 
207  /// Evaluate an animation curve at the given time
208  fpreal animCurveEval(
209  FBX_AnimCurveID curve, fpreal time_seconds) const;
210 
211  /// Number of keys in anim curve
212  int animCurveKeyCount(FBX_AnimCurveID curve) const;
213 
214  /// Get the time range of the anim curve
215  void getAnimCurveTimeInterval(
216  FBX_AnimCurveID curve,
217  fpreal &start, fpreal &end) const;
218 
219  /// Local translation property of node
220  FBX_Property3D nodeLocalTranslate(FBX_NodeID node) const;
221 
222  /// Local rotation property of node
223  FBX_Property3D nodeLocalRotate(FBX_NodeID node) const;
224 
225  /// Local scale property of node
226  FBX_Property3D nodeLocalScale(FBX_NodeID node) const;
227 
228  /// Local pre-rotation property of node. Should only be used when
229  /// nodeIsRotationActive() is true.
230  FBX_Property3D nodeLocalPreRotation(FBX_NodeID node) const;
231 
232  /// When nodeIsRotationActive() is false, then these node properties are
233  /// ignored from the FBX file:
234  /// rotation order, pivots, pre/post rotation values, rotation limits
235  bool nodeIsRotationActive(FBX_NodeID node) const;
236 
237  /// Return the transform order for given node. For FBX, we always return a
238  /// transform order of SRT, so really only the rotation order is pertinent
239  /// here.
240  /// @note Returns a default value when !nodeIsRotationActive()
241  UT_XformOrder nodeTransformOrder(FBX_NodeID node) const;
242 
243  /// Return the rotation pivot for given node.
244  /// @note Returns a default value when !nodeIsRotationActive()
245  UT_Vector3D nodeRotationPivot(FBX_NodeID node) const;
246 
247  int animLayerCount(FBX_ClipID clip) const;
248  FBX_AnimLayerID animLayer(FBX_ClipID clip, int i) const;
249 
250  /// Create a new animation layer. If given clip, the layer is added to it.
251  FBX_AnimLayerID createAnimLayer(const char* name,
252  FBX_ClipID clip = FBX_ClipID{});
253 
254  /// Destroy give animation layer. If recurse_unused is true, then
255  /// recursively destroy all unused dst objects as a result.
256  void destroyAnimLayer(FBX_AnimLayerID layer,
257  bool recurse_unused = false);
258 
259  /// Add/remove a layer to clip as a src object
260  /// @{
261  void addAnimLayer(FBX_ClipID clip, FBX_AnimLayerID layer);
262  void removeAnimLayer(FBX_ClipID clip, FBX_AnimLayerID layer);
263  /// @}
264 
265  /// Return src object count of layer
266  int animLayerSrcCount(FBX_AnimLayerID layer) const;
267 
268  FBX_AnimCurveID propertyAnimCurve(
269  FBX_PropertyID property,
270  FBX_AnimLayerID layer,
271  int component,
272  bool create = false);
273 
274  fpreal propertyEvalFloat(
275  FBX_PropertyID property,
276  fpreal time_seconds);
277  UT_Vector3R propertyEvalVector(
279  fpreal time_seconds);
280 
281  /// Scene scale to convert from internal FBX scene. Determined by load()
282  /// This is currently only used by nodeGlobalTransform()
283  double sceneScale() const;
284 
285  /// Return a node's global transform, scaled by sceneScale()
286  UT_Matrix4D nodeGlobalTransform(
287  FBX_NodeID node, fpreal time_seconds) const;
288 
289  /// Get a node's local transform at given time.
290  /// @note This transform is NOT scaled by sceneScale()
291  UT_Matrix4D nodeLocalTransform(
292  FBX_NodeID node, fpreal time_seconds) const;
293 
294  /// Get a node's geometric transform. Returns false if there is none.
295  /// A geometric transform is a transform that is only applied to the node's
296  /// geometry and is not part of its global transform.
297  /// @note This transform is NOT scaled by sceneScale()
298  bool nodeGeometricTransform(
299  FBX_NodeID node, UT_Matrix4D& transform) const;
300 
301  /// Compute a scene scale needed convert transforms from
302  /// nodeGlobalTransform() to the Houdini unit length.
303  /// This will be 1.0 if the file was loaded with convert_units=true.
304  double computeConversionFactor() const;
305 
307  nodeScaleInheritanceMode(FBX_NodeID node) const;
308 
309  void setNodeScaleInheritanceMode(
310  FBX_NodeID node, UT_ScaleInheritanceMode inherit);
311 
312  int clipCount() const;
313  FBX_ClipID clip(int i) const;
314 
315  FBX_ClipID findClip(const char* name) const;
316  const char* clipName(FBX_ClipID clip) const;
317 
318  void setActiveClip(FBX_ClipID clip);
319  FBX_ClipID activeClip() const;
320 
321  FBX_ClipID createClip(const char* name);
322 
323  /// Get/set the *inclusive* time range for the given clip in seconds
324  /// @{
325  void getClipTimeRange(
326  FBX_ClipID clip, fpreal& start, fpreal &stop) const;
327  void setClipTimeRange(
328  FBX_ClipID clip, fpreal start, fpreal stop);
329  /// @}
330 
331  /// Iterates over a node's user properties.
333  {
334  public:
335  PropertyIterator(FBX_NodeID node);
336  ~PropertyIterator();
337 
338  bool isValid();
339  void advance();
340 
341  const char *getName() const;
342  fpreal evalFloat(fpreal time_seconds) const;
343 
344  enum DataType
345  {
369  eDateTime
370  };
371 
372  DataType getDataType() const;
373 
374  private:
375  struct Impl;
376  UT_UniquePtr<Impl> myImpl;
377  };
378 
379 private:
380  template <typename FBX_T, typename ID_T>
381  static inline FBX_T * castID(ID_T id);
382 
383 private:
384  struct Impl;
385  UT_UniquePtr<Impl> myImpl;
386 
387  friend FBX_AnimCurveModifier;
388 };
389 
390 enum class FBX_KeyInterp
391 {
392  CONSTANT,
393  LINEAR,
394  CUBIC
395 };
396 
398 {
399 public:
400  FBX_AnimCurveModifier() = default;
401  FBX_AnimCurveModifier(FBX_AnimCurveID curve);
403 
404  void reset(FBX_AnimCurveID curve);
405 
406  void clearKeys();
407  int addKey(fpreal time_seconds);
408 
409  void setKeyInterpolation(int key_i, FBX_KeyInterp interp);
410  FBX_KeyInterp keyInterpolation(int key_i) const;
411 
412  void setKeyValue(int key_i, fpreal val);
413  fpreal keyValue(int key_i) const;
414 
415  FBX_AnimCurveID curve() const { return myCurve; }
416  int lastKeyIndex() const { return myLastKeyIndex; }
417 
418 private:
419  template <typename FBX_T, typename ID_T>
420  static inline FBX_T * castID(ID_T id)
421  { return FBX_SceneProxy::castID<FBX_T,ID_T>(id); }
422 
423 private:
424  FBX_AnimCurveID myCurve = FBX_AnimCurveID{};
425  int myLastKeyIndex = 0;
426 };
427 
429 {
430  enum class UpVector
431  {
432  XAxis,
433  YAxis,
434  ZAxis
435  };
436  enum class FrontVector
437  {
438  ParityEven,
439  ParityOdd
440  };
441  enum class CoordSystem
442  {
443  RightHanded,
444  LeftHanded
445  };
446 
450 
451  bool operator==(const FBX_AxisSystem &x) const
452  {
453  return myUpVector == x.myUpVector &&
454  myFrontVector == x.myFrontVector &&
455  myCoordSystem == x.myCoordSystem;
456  }
457  bool operator!=(const FBX_AxisSystem &x) const
458  {
459  return !(*this == x);
460  }
461 };
462 
463 #endif // __FBX_SCENEPROXY_H_INCLUDED__
GLbyte * weights
Definition: glew.h:7551
FrontVector myFrontVector
GLuint id
Definition: glew.h:1679
GLuint const GLchar * name
Definition: glew.h:1814
CoordSystem myCoordSystem
GLuint GLenum GLenum transform
Definition: glew.h:14742
GLenum target
Definition: glew.h:2865
GLuint const GLfloat * val
Definition: glew.h:2794
int lastKeyIndex() const
GLboolean reset
Definition: glew.h:4959
bool operator!=(const FBX_AxisSystem &x) const
GLuint interp
Definition: glew.h:8277
FBX_KeyInterp
#define FBX_API
Definition: FBX_API.h:10
GLint GLint GLint GLint GLint x
Definition: glew.h:1252
const GLuint GLenum const void * binary
Definition: glew.h:3502
GLuint GLuint end
Definition: glew.h:1253
INT property
Definition: wglew.h:145
GLuint const GLuint * names
Definition: glew.h:2690
UpVector myUpVector
bool load(const char *path, bool convert_units, FBX_ErrorManager &errors)
GLuint start
Definition: glew.h:1253
GLsizei const GLchar *const * path
Definition: glew.h:6461
double fpreal
Definition: SYS_Types.h:276
IMATH_INTERNAL_NAMESPACE_HEADER_ENTER T clip(const T &p, const Box< T > &box)
Definition: ImathBoxAlgo.h:89
bool operator==(const FBX_AxisSystem &x) const
GLint GLboolean GLint layer
Definition: glew.h:3601
FBX_AnimCurveID curve() const
Iterates over a node's user properties.
UT_ScaleInheritanceMode
Scale inheritance modes.
FBX_SCENEPROXY_DECLARE_ID(FBX_NodeID)