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 <UT/UT_StringArray.h>
19 #include <UT/UT_UniquePtr.h>
20 #include <UT/UT_VectorTypes.h>
21 #include <UT/UT_TransformUtil.h>
22 #include <SYS/SYS_Types.h>
23 
24 
25 class FBX_ErrorManager;
26 class GU_Detail;
27 
28 FBX_SCENEPROXY_DECLARE_ID(FBX_NodeID);
29 FBX_SCENEPROXY_DECLARE_ID(FBX_GeometryID);
30 FBX_SCENEPROXY_DECLARE_ID(FBX_ClipID);
31 FBX_SCENEPROXY_DECLARE_ID(FBX_AnimCurveID);
32 FBX_SCENEPROXY_DECLARE_ID(FBX_AnimLayerID);
33 
34 FBX_SCENEPROXY_DECLARE_ID(FBX_PropertyID);
35 
36 template <typename T>
37 class FBX_Property : public FBX_PropertyID
38 {
39 public:
40  using value_type = T;
41 
42  using FBX_PropertyID::FBX_PropertyID;
43 
44 private:
45  friend class FBX_SceneProxy;
46 };
48 
50 
52 {
53 public:
55  {
56  bool myConvertUnits = true;
57  bool myImportTemplates = true;
58  bool myImportPivots = true;
59  bool myImportGlobalSettings = true;
60  bool myImportCharacters = true;
61  bool myImportConstraints = true;
62  bool myImportGobos = true;
63  bool myImportShapes = true;
64  bool myImportLinks = true;
65  bool myImportTextures = true;
66  bool myImportModels = true;
67  bool myImportAnimations = true;
68  bool myImportMaterials = false; // should also enable
69  // myExtractEmbeddedMedia when enabling
70  // this.
71  bool myExtractEmbeddedData = false; // evil!
72  };
73 
75  ~FBX_SceneProxy();
76 
77  bool load(const char* path,
78  const LoadOptions& options,
79  FBX_ErrorManager& errors);
80  bool load(const char* path,
81  bool convert_units,
82  FBX_ErrorManager& errors)
83  {
84  LoadOptions options;
85  options.myConvertUnits = convert_units;
86  return load(path, options, errors);
87  }
88 
89  bool save(const char* path,
90  FBX_ErrorManager& errors,
91  bool binary = true,
92  bool animation_only = false) const;
93 
94  fpreal globalFrameRate() const;
95  void setGlobalFrameRate(fpreal fps);
96 
97  void getGlobalTimeRange(fpreal& start, fpreal &stop) const;
98 
99  const char* nodeName(FBX_NodeID node) const;
100  FBX_NodeID findNode(const char* name) const;
101 
102  int nodeCount() const;
103  FBX_NodeID node(int i) const;
104 
105  FBX_NodeID rootNode() const;
106  FBX_NodeID parentNode(FBX_NodeID node) const;
107  int childNodeCount(FBX_NodeID node) const;
108  FBX_NodeID childNode(FBX_NodeID node, int i) const;
109 
110  enum NodeType
111  {
112  eUnknown, // Unknown
113  eNull, // Null object
114  eMarker, // Mocap marker OR IK/FK effector
115  eSkeleton, // Bone/Joint
116  eMesh, // Geometry
117  eNurbs, // Geometry
118  ePatch, // Geometry
119  eCamera, // Camera
120  eCameraStereo, // Stereo camera
121  eCameraSwitcher, // Switch between child cameras
122  eLight, // Light
123  eOpticalReference, // Mocap marker
124  eOpticalMarker, // Mocap marker OR IK/FK effector
125  eNurbsCurve, // Geometry
126  eTrimNurbsSurface, // Geometry
127  eBoundary, // Geometry
128  eNurbsSurface, // Geometry
129  eShape, // Blendshape
130  eLODGroup, // Group of objects with different levels of detail
131  eSubDiv, // Geometry
132  eCachedEffect, // Particles, fluids, hair, etc. cache
133  eLine // Geometry
134  };
135  NodeType nodeType(FBX_NodeID node) const;
136 
137  bool visibility(FBX_NodeID node) const;
138 
139  FBX_GeometryID geometry(FBX_NodeID node) const;
140  FBX_NodeID geometryNode(FBX_GeometryID geometry) const;
141  int geometrySkinDeformerCount(FBX_GeometryID geometry) const;
142 
143  int skinDeformerCount() const;
144  FBX_GeometryID skinDeformerGeometry(int i) const;
145 
146  /// Convert geometry into GU_Detail, with skin deformers converted into
147  /// a boneCapture attribute. If world_xform is given, the result including
148  /// the transforms within boneCapture will have this baked into it.
149  /// When add_unused_joints is true, add ancestor joints for any captured
150  /// joints will also be added to the boneCapture attribute with identity
151  /// transforsm.
152  bool convertGeometry(
153  GU_Detail& detail,
154  FBX_GeometryID geometry,
155  FBX_ErrorManager& errors,
156  bool add_unused_joints,
157  const UT_Matrix4D* world_xform = nullptr) const;
158 
160  {
164  eBlend
165  };
166  /// Returns the skinning type for the i'th skin deformer in the geometry.
167  SkinningType geometrySkinDeformerType(FBX_GeometryID geometry, int i) const;
168 
169  /// Returns the number of blend shape deformers for the geometry.
170  int blendshapeCount(FBX_GeometryID geometry) const;
171  /// Returns the number of channels for the i'th blend shape deformer.
172  int blendshapeChannelCount(
173  FBX_GeometryID geometry, int blendshape_idx) const;
174  /// Returns the name of the specified blendshape channel.
175  UT_StringHolder blendshapeChannelName(FBX_GeometryID geometry,
176  int blendshape_idx, int channel_idx) const;
177 
178  /// Returns the geometry, name, and weight (multiplied by 0.01) for each of
179  /// the channel's target shapes. Multiple targets imply that there are
180  /// in-between shapes, and the shapes are sorted by weight in ascending
181  /// order.
182  void blendShapeChannelTargets(FBX_GeometryID geometry,
183  int blendshape_idx, int channel_idx,
184  UT_Array<GU_DetailHandle> &details,
186 
187  /// Returns curve for the blend shape channel's values.
188  FBX_AnimCurveID blendshapeChannelCurve(FBX_GeometryID geometry,
189  int blendshape_idx, int channel_idx) const;
190 
191  /// Evaluate an animation curve at the given time
192  fpreal animCurveEval(
193  FBX_AnimCurveID curve, fpreal time_seconds) const;
194 
195  int animCurveKeyCount(FBX_AnimCurveID curve) const;
196  void getAnimCurveTimeInterval(
197  FBX_AnimCurveID curve,
198  fpreal &start, fpreal &end) const;
199 
200  FBX_Property3D nodeLocalTranslate(FBX_NodeID node) const;
201  FBX_Property3D nodeLocalRotate(FBX_NodeID node) const;
202  FBX_Property3D nodeLocalScale(FBX_NodeID node) const;
203  FBX_Property3D nodeLocalPreRotation(FBX_NodeID node) const;
204 
205  int animLayerCount(FBX_ClipID clip) const;
206  FBX_AnimLayerID animLayer(FBX_ClipID clip, int i) const;
207 
208  /// Create a new animation layer. If given clip, the layer is added to it.
209  FBX_AnimLayerID createAnimLayer(const char* name,
210  FBX_ClipID clip = FBX_ClipID{});
211 
212  /// Destroy give animation layer. If recurse_unused is true, then
213  /// recursively destroy all unused dst objects as a result.
214  void destroyAnimLayer(FBX_AnimLayerID layer,
215  bool recurse_unused = false);
216 
217  /// Add/remove a layer to clip as a src object
218  /// @{
219  void addAnimLayer(FBX_ClipID clip, FBX_AnimLayerID layer);
220  void removeAnimLayer(FBX_ClipID clip, FBX_AnimLayerID layer);
221  /// @}
222 
223  /// Return src object count of layer
224  int animLayerSrcCount(FBX_AnimLayerID layer) const;
225 
226  FBX_AnimCurveID propertyAnimCurve(
227  FBX_PropertyID property,
228  FBX_AnimLayerID layer,
229  int component,
230  bool create = false);
231 
232  fpreal propertyEvalFloat(
233  FBX_PropertyID property,
234  fpreal time_seconds);
235  UT_Vector3R propertyEvalVector(
237  fpreal time_seconds);
238 
239  /// Scene scale to convert from internal FBX scene. Determined by load()
240  /// This is currently only used by nodeGlobalTransform()
241  double sceneScale() const;
242 
243  /// Return a node's global transform, scaled by sceneScale()
244  UT_Matrix4D nodeGlobalTransform(
245  FBX_NodeID node, fpreal time_seconds) const;
246 
247  /// Get a node's geometric transform. Returns false if there is none.
248  /// A geometric transform is a transform that is only applied to the node's
249  /// geometry and is not part of its global transform.
250  /// @note This transform is NOT scaled by sceneScale()
251  bool nodeGeometricTransform(
252  FBX_NodeID node, UT_Matrix4D& transform) const;
253 
254  /// Compute a scene scale needed convert transforms from
255  /// nodeGlobalTransform() to the Houdini unit length.
256  /// This will be 1.0 if the file was loaded with convert_units=true.
257  double computeConversionFactor() const;
258 
260  nodeScaleInheritanceMode(FBX_NodeID node) const;
261 
262  void setNodeScaleInheritanceMode(
263  FBX_NodeID node, UT_ScaleInheritanceMode inherit);
264 
265  int clipCount() const;
266  FBX_ClipID clip(int i) const;
267 
268  FBX_ClipID findClip(const char* name) const;
269  const char* clipName(FBX_ClipID clip) const;
270 
271  void setActiveClip(FBX_ClipID clip);
272  FBX_ClipID activeClip() const;
273 
274  FBX_ClipID createClip(const char* name);
275 
276  /// Get/set the *inclusive* time range for the given clip in seconds
277  /// @{
278  void getClipTimeRange(
279  FBX_ClipID clip, fpreal& start, fpreal &stop) const;
280  void setClipTimeRange(
281  FBX_ClipID clip, fpreal start, fpreal stop);
282  /// @}
283 
284  /// Iterates over a node's user properties.
286  {
287  public:
288  PropertyIterator(FBX_NodeID node);
289  ~PropertyIterator();
290 
291  bool isValid();
292  void advance();
293 
294  const char *getName() const;
295  fpreal evalFloat(fpreal time_seconds) const;
296 
297  enum DataType
298  {
322  eDateTime
323  };
324 
325  DataType getDataType() const;
326 
327  private:
328  struct Impl;
329  UT_UniquePtr<Impl> myImpl;
330  };
331 
332 private:
333  template <typename FBX_T, typename ID_T>
334  static inline FBX_T * castID(ID_T id);
335 
336 private:
337  struct Impl;
338  UT_UniquePtr<Impl> myImpl;
339 
340  friend FBX_AnimCurveModifier;
341 };
342 
343 enum class FBX_KeyInterp
344 {
345  CONSTANT,
346  LINEAR,
347  CUBIC
348 };
349 
351 {
352 public:
353  FBX_AnimCurveModifier() = default;
354  FBX_AnimCurveModifier(FBX_AnimCurveID curve);
356 
357  void reset(FBX_AnimCurveID curve);
358 
359  void clearKeys();
360  int addKey(fpreal time_seconds);
361 
362  void setKeyInterpolation(int key_i, FBX_KeyInterp interp);
363  FBX_KeyInterp keyInterpolation(int key_i) const;
364 
365  void setKeyValue(int key_i, fpreal val);
366  fpreal keyValue(int key_i) const;
367 
368  FBX_AnimCurveID curve() const { return myCurve; }
369  int lastKeyIndex() const { return myLastKeyIndex; }
370 
371 private:
372  template <typename FBX_T, typename ID_T>
373  static inline FBX_T * castID(ID_T id)
374  { return FBX_SceneProxy::castID<FBX_T,ID_T>(id); }
375 
376 private:
377  FBX_AnimCurveID myCurve = FBX_AnimCurveID{};
378  int myLastKeyIndex = 0;
379 };
380 
381 #endif // __FBX_SCENEPROXY_H_INCLUDED__
GLbyte * weights
Definition: glew.h:7551
GLuint id
Definition: glew.h:1679
GLuint const GLchar * name
Definition: glew.h:1814
GLuint GLenum GLenum transform
Definition: glew.h:14742
GLuint const GLfloat * val
Definition: glew.h:2794
int lastKeyIndex() const
GLboolean reset
Definition: glew.h:4959
GLuint interp
Definition: glew.h:8277
FBX_KeyInterp
#define FBX_API
Definition: FBX_API.h:10
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
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
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)