llgltfprimitive.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /**
  2. * @file llgltfprimitive.h
  3. * @brief LL GLTF Implementation
  4. *
  5. * $LicenseInfo:firstyear=2024&license=viewergpl$
  6. *
  7. * Copyright (c) 2024, 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_LLGLTFPRIMITIVE_H
  33. #define LL_LLGLTFPRIMITIVE_H
  34. #include "hbfastmap.h"
  35. #include "llmemory.h" // For LL_ALIGNED16_NEW_DELETE
  36. #include "llvertexbuffer.h"
  37. #include "llvolumeoctree.h"
  38. // Saves from including "tinygltf/tiny_gltf.h" here. HB
  39. namespace tinygltf
  40. {
  41. struct Primitive;
  42. }
  43. namespace LLGLTF
  44. {
  45. class Asset;
  46. constexpr U32 ATTRIBUTE_MASK = LLVertexBuffer::MAP_VERTEX |
  47. LLVertexBuffer::MAP_NORMAL |
  48. LLVertexBuffer::MAP_TEXCOORD0 |
  49. LLVertexBuffer::MAP_TANGENT |
  50. LLVertexBuffer::MAP_COLOR;
  51. // Note 16-byte aligned because we use vectors of LLVector4a. HB
  52. class alignas(16) Primitive
  53. {
  54. protected:
  55. LOG_CLASS(LLGLTF::Primitive);
  56. public:
  57. LL_ALIGNED16_NEW_DELETE
  58. Primitive();
  59. ~Primitive();
  60. // Creates an octree based on vertex buffer; must be called before
  61. // buffer is unmapped and after buffer is populated with valid data.
  62. void createOctree();
  63. // Gets the LLVolumeTriangle that intersects with the given line
  64. // segment at the point closest to start. Moves end to the point of
  65. // intersection. Returns NULL if no intersection.
  66. // Line segment must be in the same coordinate frame as this Primitive.
  67. const LLVolumeTriangle* lineSegmentIntersect(const LLVector4a& start,
  68. const LLVector4a& end,
  69. LLVector4a* interp = NULL,
  70. LLVector2* tcoordp = NULL,
  71. LLVector4a* normp = NULL,
  72. LLVector4a* tgtp = NULL);
  73. const Primitive& operator=(const tinygltf::Primitive& src);
  74. // Returns true on success, or false on failure. HB
  75. bool allocateGLResources(Asset& asset);
  76. public:
  77. // Aligned members first...
  78. // CPU copy of mesh data
  79. std::vector<LLVector4a> mNormals;
  80. std::vector<LLVector4a> mTangents;
  81. std::vector<LLVector4a> mPositions;
  82. std::vector<LLVector4a> mJoints;
  83. std::vector<LLVector4a> mWeights;
  84. // ... then the rest.
  85. std::vector<LLVector2> mTexCoords;
  86. std::vector<LLColor4U> mColors;
  87. std::vector<U32> mIndexArray;
  88. // Raycast acceleration structure
  89. std::vector<LLVolumeTriangle> mOctreeTriangles;
  90. LLPointer<LLVolumeOctree> mOctree;
  91. // GPU copy of mesh data
  92. LLPointer<LLVertexBuffer> mVertexBuffer;
  93. fast_hmap<std::string, S32> mAttributes;
  94. S32 mMaterial;
  95. U32 mMode;
  96. U32 mGLMode;
  97. S32 mIndices;
  98. };
  99. }
  100. #endif // LL_LLGLTFPRIMITIVE_H