/** * @file llgltfprimitive.h * @brief LL GLTF Implementation * * $LicenseInfo:firstyear=2024&license=viewergpl$ * * Copyright (c) 2024, Linden Research, Inc. * * Second Life Viewer Source Code * The source code in this file ("Source Code") is provided by Linden Lab * to you under the terms of the GNU General Public License, version 2.0 * ("GPL"), unless you have obtained a separate licensing agreement * ("Other License"), formally executed by you and Linden Lab. Terms of * the GPL can be found in doc/GPL-license.txt in this distribution, or * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2 * * There are special exceptions to the terms and conditions of the GPL as * it is applied to this Source Code. View the full text of the exception * in the file doc/FLOSS-exception.txt in this software distribution, or * online at * http://secondlifegrid.net/programs/open_source/licensing/flossexception * * By copying, modifying or distributing this software, you acknowledge * that you have read and understood your obligations described above, * and agree to abide by those obligations. * * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, * COMPLETENESS OR PERFORMANCE. * $/LicenseInfo$ */ #ifndef LL_LLGLTFPRIMITIVE_H #define LL_LLGLTFPRIMITIVE_H #include "hbfastmap.h" #include "llmemory.h" // For LL_ALIGNED16_NEW_DELETE #include "llvertexbuffer.h" #include "llvolumeoctree.h" // Saves from including "tinygltf/tiny_gltf.h" here. HB namespace tinygltf { struct Primitive; } namespace LLGLTF { class Asset; constexpr U32 ATTRIBUTE_MASK = LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_NORMAL | LLVertexBuffer::MAP_TEXCOORD0 | LLVertexBuffer::MAP_TANGENT | LLVertexBuffer::MAP_COLOR; // Note 16-byte aligned because we use vectors of LLVector4a. HB class alignas(16) Primitive { protected: LOG_CLASS(LLGLTF::Primitive); public: LL_ALIGNED16_NEW_DELETE Primitive(); ~Primitive(); // Creates an octree based on vertex buffer; must be called before // buffer is unmapped and after buffer is populated with valid data. void createOctree(); // Gets the LLVolumeTriangle that intersects with the given line // segment at the point closest to start. Moves end to the point of // intersection. Returns NULL if no intersection. // Line segment must be in the same coordinate frame as this Primitive. const LLVolumeTriangle* lineSegmentIntersect(const LLVector4a& start, const LLVector4a& end, LLVector4a* interp = NULL, LLVector2* tcoordp = NULL, LLVector4a* normp = NULL, LLVector4a* tgtp = NULL); const Primitive& operator=(const tinygltf::Primitive& src); // Returns true on success, or false on failure. HB bool allocateGLResources(Asset& asset); public: // Aligned members first... // CPU copy of mesh data std::vector mNormals; std::vector mTangents; std::vector mPositions; std::vector mJoints; std::vector mWeights; // ... then the rest. std::vector mTexCoords; std::vector mColors; std::vector mIndexArray; // Raycast acceleration structure std::vector mOctreeTriangles; LLPointer mOctree; // GPU copy of mesh data LLPointer mVertexBuffer; fast_hmap mAttributes; S32 mMaterial; U32 mMode; U32 mGLMode; S32 mIndices; }; } #endif // LL_LLGLTFPRIMITIVE_H