llphysshapebuilderutil.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /**
  2. * @file llphysshapebuilderutil.h
  3. * @brief Generic system to convert LL(Physics)VolumeParams to physics shapes
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2010, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #ifndef LL_PHYSICS_SHAPE_BUILDER_H
  33. #define LL_PHYSICS_SHAPE_BUILDER_H
  34. #include "indra_constants.h"
  35. #include "llpreprocessor.h"
  36. #include "llvolume.h"
  37. #define USE_SHAPE_QUANTIZATION 0
  38. #define SHAPE_BUILDER_DEFAULT_VOLUME_DETAIL 1
  39. #define SHAPE_BUILDER_IMPLICIT_THRESHOLD_HOLLOW 0.10f
  40. #define SHAPE_BUILDER_IMPLICIT_THRESHOLD_HOLLOW_SPHERES 0.90f
  41. #define SHAPE_BUILDER_IMPLICIT_THRESHOLD_PATH_CUT 0.05f
  42. #define SHAPE_BUILDER_IMPLICIT_THRESHOLD_TAPER 0.05f
  43. #define SHAPE_BUILDER_IMPLICIT_THRESHOLD_TWIST 0.09f
  44. #define SHAPE_BUILDER_IMPLICIT_THRESHOLD_SHEAR 0.05f
  45. constexpr F32 COLLISION_TOLERANCE = 0.1f;
  46. constexpr F32 SHAPE_BUILDER_ENTRY_SNAP_SCALE_BIN_SIZE = 0.15f;
  47. constexpr F32 SHAPE_BUILDER_ENTRY_SNAP_PARAMETER_BIN_SIZE = 0.01f;
  48. constexpr F32 SHAPE_BUILDER_MIN_GEOMETRY_SIZE = 0.5f * COLLISION_TOLERANCE;
  49. constexpr F32 SHAPE_BUILDER_CONVEXIFICATION_SIZE = 2.f * COLLISION_TOLERANCE;
  50. constexpr F32 SHAPE_BUILDER_CONVEXIFICATION_SIZE_MESH = 0.5f;
  51. class LLPhysicsVolumeParams : public LLVolumeParams
  52. {
  53. public:
  54. LL_INLINE LLPhysicsVolumeParams(const LLVolumeParams& params,
  55. bool force_convex)
  56. : LLVolumeParams(params),
  57. mForceConvex(force_convex)
  58. {
  59. }
  60. LL_INLINE bool operator==(const LLPhysicsVolumeParams& params) const
  61. {
  62. return (LLVolumeParams::operator==(params) &&
  63. mForceConvex == params.mForceConvex);
  64. }
  65. LL_INLINE bool operator!=(const LLPhysicsVolumeParams& params) const
  66. {
  67. return !operator==(params);
  68. }
  69. LL_INLINE bool operator<(const LLPhysicsVolumeParams& params) const
  70. {
  71. if (LLVolumeParams::operator!=(params))
  72. {
  73. return LLVolumeParams::operator<(params);
  74. }
  75. return !params.mForceConvex && mForceConvex;
  76. }
  77. LL_INLINE bool shouldForceConvex() const { return mForceConvex; }
  78. private:
  79. bool mForceConvex;
  80. };
  81. // Purely static class
  82. class LLPhysShapeBuilderUtil
  83. {
  84. public:
  85. LLPhysShapeBuilderUtil() = delete;
  86. ~LLPhysShapeBuilderUtil() = delete;
  87. class ShapeSpec
  88. {
  89. friend class LLPhysShapeBuilderUtil;
  90. public:
  91. enum ShapeType
  92. {
  93. // Primitive types
  94. BOX,
  95. SPHERE,
  96. CYLINDER,
  97. // User specified they wanted the convex hull of the volume
  98. USER_CONVEX,
  99. // Either a volume that is inherently convex but not a primitive
  100. // type, or a shape with dimensions such that will convexify it
  101. // anyway.
  102. PRIM_CONVEX,
  103. // Special case for traditional sculpts--they are the convex hull
  104. // of a single particular set of volume params
  105. SCULPT,
  106. // A user mesh. May or may not contain a convex decomposition.
  107. USER_MESH,
  108. // A non-convex volume which we have to represent accurately
  109. PRIM_MESH,
  110. INVALID
  111. };
  112. LL_INLINE ShapeSpec()
  113. : mType(INVALID),
  114. mScale(0.f, 0.f, 0.f),
  115. mCenter(0.f, 0.f, 0.f)
  116. {
  117. }
  118. LL_INLINE bool isConvex()
  119. {
  120. return mType != USER_MESH && mType != PRIM_MESH &&
  121. mType != INVALID;
  122. }
  123. LL_INLINE bool isMesh()
  124. {
  125. return mType == USER_MESH || mType == PRIM_MESH;
  126. }
  127. LL_INLINE ShapeType getType() { return mType; }
  128. LL_INLINE const LLVector3& getScale() { return mScale; }
  129. LL_INLINE const LLVector3& getCenter() { return mCenter; }
  130. private:
  131. ShapeType mType;
  132. // Dimensions of an AABB around the shape
  133. LLVector3 mScale;
  134. // Offset of shape from origin of primitive's reference frame
  135. LLVector3 mCenter;
  136. };
  137. static void getPhysShape(const LLPhysicsVolumeParams& vol_params,
  138. const LLVector3& scale, bool has_decomp,
  139. ShapeSpec& spec_out);
  140. };
  141. #endif //LL_PHYSICS_SHAPE_BUILDER_H