diff options
Diffstat (limited to 'indra/newview/gltf/primitive.cpp')
-rw-r--r-- | indra/newview/gltf/primitive.cpp | 86 |
1 files changed, 37 insertions, 49 deletions
diff --git a/indra/newview/gltf/primitive.cpp b/indra/newview/gltf/primitive.cpp index 1bde7327e6..886b8f79c9 100644 --- a/indra/newview/gltf/primitive.cpp +++ b/indra/newview/gltf/primitive.cpp @@ -9,7 +9,7 @@ * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; - * version 2.1 of the License only. + * version 2.1 of the License only. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -30,12 +30,10 @@ #include "buffer_util.h" #include "../llviewershadermgr.h" -#include "../lltinygltfhelper.h" - using namespace LL::GLTF; using namespace boost::json; -void Primitive::allocateGLResources(Asset& asset) +bool Primitive::prep(Asset& asset) { // allocate vertex buffer // We diverge from the intent of the GLTF format here to work with our existing render pipeline @@ -85,10 +83,19 @@ void Primitive::allocateGLResources(Asset& asset) { Accessor& accessor = asset.mAccessors[mIndices]; copy(asset, accessor, mIndexArray); + + for (auto& idx : mIndexArray) + { + if (idx >= mPositions.size()) + { + LL_WARNS("GLTF") << "Invalid index array" << LL_ENDL; + return false; + } + } } U32 mask = ATTRIBUTE_MASK; - + if (!mWeights.empty()) { mask |= LLVertexBuffer::MAP_WEIGHT4; @@ -130,7 +137,7 @@ void Primitive::allocateGLResources(Asset& asset) { mColors.resize(mPositions.size(), LLColor4U::white); } - + // bake material basecolor into color array if (mMaterial != INVALID_INDEX) { @@ -148,7 +155,7 @@ void Primitive::allocateGLResources(Asset& asset) { mNormals.resize(mPositions.size(), LLVector4a(0, 0, 1, 0)); } - + mVertexBuffer->setNormalData(mNormals.data()); if (mTangents.empty()) @@ -175,10 +182,12 @@ void Primitive::allocateGLResources(Asset& asset) mVertexBuffer->setWeight4Data(weight_data.data()); } - + createOctree(); - + mVertexBuffer->unbind(); + + return true; } void initOctreeTriangle(LLVolumeTriangle* tri, F32 scaler, S32 i0, S32 i1, S32 i2, const LLVector4a& v0, const LLVector4a& v1, const LLVector4a& v2) @@ -224,7 +233,7 @@ void Primitive::createOctree() F32 scaler = 0.25f; - if (mMode == TINYGLTF_MODE_TRIANGLES) + if (mMode == Mode::TRIANGLES) { const U32 num_triangles = mVertexBuffer->getNumIndices() / 3; // Initialize all the triangles we need @@ -241,14 +250,14 @@ void Primitive::createOctree() const LLVector4a& v0 = mPositions[i0]; const LLVector4a& v1 = mPositions[i1]; const LLVector4a& v2 = mPositions[i2]; - + initOctreeTriangle(tri, scaler, i0, i1, i2, v0, v1, v2); - + //insert mOctree->insert(tri); } } - else if (mMode == TINYGLTF_MODE_TRIANGLE_STRIP) + else if (mMode == Mode::TRIANGLE_STRIP) { const U32 num_triangles = mVertexBuffer->getNumIndices() - 2; // Initialize all the triangles we need @@ -272,7 +281,7 @@ void Primitive::createOctree() mOctree->insert(tri); } } - else if (mMode == TINYGLTF_MODE_TRIANGLE_FAN) + else if (mMode == Mode::TRIANGLE_FAN) { const U32 num_triangles = mVertexBuffer->getNumIndices() - 2; // Initialize all the triangles we need @@ -296,14 +305,14 @@ void Primitive::createOctree() mOctree->insert(tri); } } - else if (mMode == TINYGLTF_MODE_POINTS || - mMode == TINYGLTF_MODE_LINE || - mMode == TINYGLTF_MODE_LINE_LOOP || - mMode == TINYGLTF_MODE_LINE_STRIP) + else if (mMode == Mode::POINTS || + mMode == Mode::LINES || + mMode == Mode::LINE_LOOP || + mMode == Mode::LINE_STRIP) { // nothing to do, no volume... maybe add some collision geometry around these primitive types? } - + else { LL_ERRS() << "Unsupported Primitive mode" << LL_ENDL; @@ -357,23 +366,23 @@ Primitive::~Primitive() mOctree = nullptr; } -U32 gltf_mode_to_gl_mode(U32 mode) +LLRender::eGeomModes gltf_mode_to_gl_mode(Primitive::Mode mode) { switch (mode) { - case TINYGLTF_MODE_POINTS: + case Primitive::Mode::POINTS: return LLRender::POINTS; - case TINYGLTF_MODE_LINE: + case Primitive::Mode::LINES: return LLRender::LINES; - case TINYGLTF_MODE_LINE_LOOP: + case Primitive::Mode::LINE_LOOP: return LLRender::LINE_LOOP; - case TINYGLTF_MODE_LINE_STRIP: + case Primitive::Mode::LINE_STRIP: return LLRender::LINE_STRIP; - case TINYGLTF_MODE_TRIANGLES: + case Primitive::Mode::TRIANGLES: return LLRender::TRIANGLES; - case TINYGLTF_MODE_TRIANGLE_STRIP: + case Primitive::Mode::TRIANGLE_STRIP: return LLRender::TRIANGLE_STRIP; - case TINYGLTF_MODE_TRIANGLE_FAN: + case Primitive::Mode::TRIANGLE_FAN: return LLRender::TRIANGLE_FAN; default: return LLRender::TRIANGLES; @@ -383,7 +392,7 @@ U32 gltf_mode_to_gl_mode(U32 mode) void Primitive::serialize(boost::json::object& dst) const { write(mMaterial, "material", dst, -1); - write(mMode, "mode", dst, TINYGLTF_MODE_TRIANGLES); + write(mMode, "mode", dst, Primitive::Mode::TRIANGLES); write(mIndices, "indices", dst, INVALID_INDEX); write(mAttributes, "attributes", dst); } @@ -402,24 +411,3 @@ const Primitive& Primitive::operator=(const Value& src) return *this; } -const Primitive& Primitive::operator=(const tinygltf::Primitive& src) -{ - // load material - mMaterial = src.material; - - // load mode - mMode = src.mode; - - // load indices - mIndices = src.indices; - - // load attributes - for (auto& it : src.attributes) - { - mAttributes[it.first] = it.second; - } - - mGLMode = gltf_mode_to_gl_mode(mMode); - - return *this; -} |