fbxlodgroup.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. /****************************************************************************************
  2. Copyright (C) 2015 Autodesk, Inc.
  3. All rights reserved.
  4. Use of this software is subject to the terms of the Autodesk license agreement
  5. provided at the time of installation or download, or which otherwise accompanies
  6. this software in either electronic or hard copy form.
  7. ****************************************************************************************/
  8. //! \file fbxlodgroup.h
  9. #ifndef _FBXSDK_SCENE_GEOMETRY_LOD_GROUP_H_
  10. #define _FBXSDK_SCENE_GEOMETRY_LOD_GROUP_H_
  11. #include <fbxsdk/fbxsdk_def.h>
  12. #include <fbxsdk/scene/geometry/fbxnodeattribute.h>
  13. #include <fbxsdk/fbxsdk_nsbegin.h>
  14. /** Defines a LOD (Level of Detail) group.
  15. * This LodGroup node is a group node that can be used to detect how
  16. * close a group of objects is to a camera. Typically this node is
  17. * used for controlling "Level of Detail" visibility.
  18. *
  19. * Properties in the class are designed according to Maya implementation.
  20. * So these properties may be incompatible with other software, like 3ds Max.
  21. *
  22. * In Maya, with "Level of Detail",the visibility of the children of this
  23. * transform are controlled by the distance of a group to the camera and the
  24. * threshold values.
  25. *
  26. * For example, under a LOD group node, there are three children:
  27. * ship_detailed, ship_medium, and ship_rough. There are 2 threshold
  28. * values: 5, 10. When the camera is less than 5 units away of the group
  29. * bounding box, only ship_detailed is visible. When the view is zoomed out and
  30. * the camera is between 5 and 10 units away from the group, only ship_medium is
  31. * visible. Finally, when the view is zoomed out more and the camera is 10 or
  32. * more units away from the group, only ship_rough is visible.
  33. *
  34. * This node attribute contains the properties of a null node.
  35. *
  36. * Example code to create LODGroup:
  37. * \code
  38. * FbxNode *lLodGroup = FbxNode::Create(pScene, "LODNode");
  39. * FbxLODGroup *lLodGroupAttr = FbxLODGroup::Create(pScene, "LODGroup1");
  40. * // Array lChildNodes contains geometries of all LOD levels
  41. * for (int j = 0; j < lChildNodes.GetCount(); j++)
  42. * {
  43. * lLodGroup->AddChild(lChildNodes.GetAt(j));
  44. * }
  45. * \endcode
  46. *
  47. * This object can also be configured to define thresholds as percentage values.
  48. * Typically, these percentage values represent the ratio between the group bounding
  49. * box height (in screen space) and the viewing screen height.
  50. *
  51. * To switch to this mode, the client application must set the value of the
  52. * ThresholdsUsedAsPercentage property to "true" before the calls to the AddThreshold/
  53. * SetThreshold methods. Client applications should always check the return value of
  54. * these methods to validate that the action was successful.
  55. *
  56. * Note that, for backward compatibility, the data is always stored as FbxDistance type.
  57. * The client application should always check the return value of this method to validate
  58. * that the argument contains a meaningful value (see GetThreshold for more details).
  59. *
  60. * Example code to create LODGroup that store percentage values:
  61. * \code
  62. * FbxNode *lLodGroup = FbxNode::Create(pScene, "LODNode");
  63. * FbxLODGroup *lLodGroupAttr = FbxLODGroup::Create(pScene, "LODGroup1");
  64. * lLodGroupAttr->ThresholdsUsedAsPercentage.Set(true);
  65. * FBX_ASSERT(lLodGroupAttr->AddThreshold(33.3)) == true);
  66. * FBX_ASSERT(lLodGroupAttr->AddThreshold(66.6)) == true);
  67. * FBX_ASSERT(lLodGroupAttr->AddThreshold(FbxDistance(0.6f, "cm")) == false);
  68. *
  69. * FbxDistance dval;
  70. * FbxDouble val = 0.0;
  71. * bool res;
  72. * res = lLodGroupAttr->GetThreshold(0, val); // res = true, val = 33.3
  73. * res = lLodGroupAttr->GetThreshold(0, dval); // res = false, dval.value()=33.3
  74. * res = lLodGroupAttr->GetThreshold(2, val); // res = false, val = 1.0
  75. * \nosubgrouping
  76. */
  77. class FBXSDK_DLL FbxLODGroup : public FbxNodeAttribute
  78. {
  79. FBXSDK_OBJECT_DECLARE(FbxLODGroup, FbxNodeAttribute);
  80. public:
  81. //! Return the type of node attribute which is EType::eLODGroup.
  82. virtual FbxNodeAttribute::EType GetAttributeType() const;
  83. /** \enum EDisplayLevel types to determine how to display nodes in LODGroup.
  84. * - \e eUseLOD Display the node according LOD threshold
  85. * - \e eShow Always show this node
  86. * - \e eHide Always hide this node
  87. */
  88. enum EDisplayLevel
  89. {
  90. eUseLOD,
  91. eShow,
  92. eHide
  93. };
  94. //////////////////////////////////////////////////////////////////////////
  95. //
  96. // Properties
  97. //
  98. //////////////////////////////////////////////////////////////////////////
  99. /** Specifies if the threshold values stored by this LOD object are defining
  100. * a distance to the camera (by default) or a percentage value.
  101. *
  102. * \remarks This property needs to be set before any call to the Add\SetThreshold
  103. * methods since its value is used to validate that the correct method is
  104. * called.
  105. *
  106. * To access this property do: ThresholdsUsedAsPercentage.Get().
  107. * To set this property do: ThresholdsUsedAsPercentage.Set(bool).
  108. *
  109. * Default value is false
  110. */
  111. FbxPropertyT<FbxBool> ThresholdsUsedAsPercentage;
  112. /**
  113. * \name Distance Mode
  114. * The properties in this block are meaningful only if ThresholdsUsedAsPercentage
  115. * is set to false and should be ignored otherwise.
  116. */
  117. //@{
  118. /** This property handles the use of the Min/Max distances.
  119. * Enables the minimum and maximum distance to take effect.
  120. * For example, if the distance between the group and the camera is smaller
  121. * than the minimum distance, then the whole group disappears.
  122. *
  123. * To access this property do: MinMaxDistance.Get().
  124. * To set this property do: MinMaxDistance.Set(bool).
  125. *
  126. * Default value is false.
  127. */
  128. FbxPropertyT<FbxBool> MinMaxDistance;
  129. /** The minimum distance at which the group is displayed.
  130. *
  131. * To access this property do: MinDistance.Get().
  132. * To set this property do: MinDistance.Set(double).
  133. *
  134. * Default value is -100
  135. */
  136. FbxPropertyT<FbxDouble> MinDistance;
  137. /** The maximum distance at which the group is displayed.
  138. *
  139. * To access this property do: MaxDistance.Get().
  140. * To set this property do: MaxDistance.Set(double).
  141. *
  142. * Default value is 100
  143. */
  144. FbxPropertyT<FbxDouble> MaxDistance;
  145. /** Work in world space of transform or local space If true,
  146. * the camera distance to the LOD group will be computed in world space.
  147. * This means it is possible to parent the LOD transform below other transforms
  148. * and still have it work as expected. If this attribute is set to false,
  149. * the distance computation ignores any parent transforms of the LOD transform.
  150. *
  151. * To access this property do: WorldSpace.Get().
  152. * To set this property do: WorldSpace.Set(bool).
  153. *
  154. * Default value is false
  155. */
  156. FbxPropertyT<FbxBool> WorldSpace;
  157. //@}
  158. //////////////////////////////////////////////////////////////////////////
  159. //
  160. // Methods
  161. //
  162. //////////////////////////////////////////////////////////////////////////
  163. /** Get the number of elements in the threshold list.
  164. * In correct situations, the size of this list is one less than the LOD node
  165. * children objects count.
  166. * \return The current size of the threshold list.
  167. */
  168. int GetNumThresholds() const;
  169. /** Add a new threshold.
  170. * \param pThreshValue Threshold value (distance).
  171. * \return true if successful and false otherwise.
  172. * \remarks The thresholds list can only expand. Removing items is not
  173. * possible unless a new FbxLODGroup is created to replace this one.
  174. * \remarks This method does not check the received value and blindly adds it
  175. * to the list. Identical values can exist in different positions in
  176. * the list.
  177. * \remarks This method will fail if ThresholdsUsedAsPercentage=true.
  178. */
  179. bool AddThreshold(const FbxDistance& pThreshValue);
  180. /** Add a new threshold.
  181. * \param pThreshValue Threshold value (percentage).
  182. * \return true if successful and false otherwise.
  183. * \remarks The thresholds list can only expand. Removing items is not
  184. * possible unless a new FbxLODGroup is created to replace this one.
  185. * \remarks This method does not check the received value and blindly adds it
  186. * to the list. Identical values can exist in different positions in
  187. * the list.
  188. * \remarks This method will fail if ThresholdsUsedAsPercentage=false.
  189. */
  190. bool AddThreshold(FbxDouble pThreshValue);
  191. /** Replace the value of the specified threshold.
  192. * \param pEl Element index in the thresholds list.
  193. * \param pThreshValue New threshold value (distance).
  194. * \return true if successful and false otherwise.
  195. * \remarks This method will fail if ThresholdsUsedAsPercentage=true.
  196. */
  197. bool SetThreshold(int pEl, const FbxDistance& pThreshValue);
  198. /** Replace the value of the specified threshold.
  199. * \param pEl Element index in the thresholds list.
  200. * \param pThreshValue New threshold value (percentage).
  201. * \return true if successful and false otherwise.
  202. * \remarks This method will fail if ThresholdsUsedAsPercentage=false.
  203. */
  204. bool SetThreshold(int pEl, FbxDouble pThreshValue);
  205. /** Get the value of the specified threshold.
  206. * \param pEl Element index in the thresholds list.
  207. * \param pThreshValue The current threshold value.
  208. * \return true if successful and false otherwise.
  209. * \remarks pThreshValue is left unchanged if a bad index is provided,
  210. * else the value stored in the list is returned in pThreshValue
  211. * but may be irrelevant if ThresholdsUsedAsPercentage=true. In
  212. * this case, the return of this function will also be \c false.
  213. */
  214. bool GetThreshold(int pEl, FbxDistance& pThreshValue) const;
  215. /** Get the value of the specified threshold.
  216. * \param pEl Element index in the thresholds list.
  217. * \param pThreshValue The current threshold value.
  218. * \return true if successful and false otherwise.
  219. * \remarks pThreshValue is left unchanged if a bad index is provided,
  220. * else the value stored in the list is returned in pThreshValue
  221. * but may be irrelevant if ThresholdsUsedAsPercentage=false. In
  222. * this case, the return of this function will also be \c false.
  223. */
  224. bool GetThreshold(int pEl, FbxDouble& pThreshValue) const;
  225. /** Get the number of elements in the displayLevel list.
  226. * In correct situations, the size of this list equals the LOD node
  227. * children objects count.
  228. * \return The current size of the displayLevel list.
  229. */
  230. int GetNumDisplayLevels() const;
  231. /** Add a new displayLevel value to the current list.
  232. *
  233. * The value overrides the display of any level and can force it to hide
  234. * or show the object at that level. For example, if the distance between
  235. * the group and the camera is smaller than the first threshold, then the
  236. * object at level 0 is visible. If the display level for the object at
  237. * level 2 is changed to eShow, ie. if the attribute displayLevel[2] is
  238. * set to eShow, then the object at level 2 will show regardless of
  239. * the current active level.
  240. *
  241. * \param pValue Display level value
  242. * \return true if successful and false if any error occurred.
  243. * \remarks Removing items is not possible unless a new FbxLODGroup is
  244. * created to replace this one.
  245. * \remarks This method does not check the received value and blindly adds it
  246. * to the list. Identical values can exist in different positions in
  247. * the list.
  248. */
  249. bool AddDisplayLevel(FbxLODGroup::EDisplayLevel pValue);
  250. /** Set the display level value for the specified child object.
  251. * \param pEl The index of the object.
  252. * \param pValue New display level value.
  253. * \return true if successful and false otherwise.
  254. */
  255. bool SetDisplayLevel(int pEl, FbxLODGroup::EDisplayLevel pValue);
  256. /** Get the display level value for the specified child object.
  257. * \param pEl The index of the object.
  258. * \param pValue the current display level value.
  259. * \return true if successful and false otherwise.
  260. * \remarks In case of failure, the pValue is left unchanged.
  261. */
  262. bool GetDisplayLevel(int pEl, FbxLODGroup::EDisplayLevel& pValue) const;
  263. /*****************************************************************************************************************************
  264. ** WARNING! Anything beyond these lines is for internal use, may not be documented and is subject to change without notice! **
  265. *****************************************************************************************************************************/
  266. #ifndef DOXYGEN_SHOULD_SKIP_THIS
  267. virtual FbxObject& Copy(const FbxObject& pObject);
  268. protected:
  269. virtual void Construct(const FbxObject* pFrom);
  270. virtual void ConstructProperties(bool pForceSet);
  271. private:
  272. int mNbThresholds;
  273. FbxProperty mThresholds;
  274. bool RetrieveThreshold(int pEl, FbxDistance& pThreshValue) const;
  275. bool StoreThreshold(int pEl, const FbxDistance& pThreshValue);
  276. int mNbDisplayLevels;
  277. FbxProperty mDisplayLevels;
  278. bool DisplayLevel(int pEl, FbxLODGroup::EDisplayLevel pValue);
  279. public:
  280. virtual FbxStringList GetTypeFlags() const;
  281. #endif /* !DOXYGEN_SHOULD_SKIP_THIS *****************************************************************************************/
  282. };
  283. inline EFbxType FbxTypeOf(const FbxLODGroup::EDisplayLevel&){ return eFbxEnum; }
  284. #include <fbxsdk/fbxsdk_nsend.h>
  285. #endif /* _FBXSDK_SCENE_GEOMETRY_LOD_GROUP_H_ */