summaryrefslogtreecommitdiff
path: root/indra/newview/gltf/asset.h
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview/gltf/asset.h')
-rw-r--r--indra/newview/gltf/asset.h146
1 files changed, 96 insertions, 50 deletions
diff --git a/indra/newview/gltf/asset.h b/indra/newview/gltf/asset.h
index 5a62313705..1d707cbeba 100644
--- a/indra/newview/gltf/asset.h
+++ b/indra/newview/gltf/asset.h
@@ -32,9 +32,16 @@
#include "accessor.h"
#include "primitive.h"
#include "animation.h"
+#include "boost/json.hpp"
+#include "common.h"
extern F32SecondsImplicit gFrameTimeSeconds;
+// wingdi defines OPAQUE, which conflicts with our enum
+#if defined(OPAQUE)
+#undef OPAQUE
+#endif
+
// LL GLTF Implementation
namespace LL
{
@@ -45,13 +52,26 @@ namespace LL
class Material
{
public:
+
+ enum class AlphaMode
+ {
+ OPAQUE,
+ MASK,
+ BLEND
+ };
+
class TextureInfo
{
public:
S32 mIndex = INVALID_INDEX;
S32 mTexCoord = 0;
+ bool operator==(const TextureInfo& rhs) const;
+ bool operator!=(const TextureInfo& rhs) const;
+
const TextureInfo& operator=(const tinygltf::TextureInfo& src);
+ const TextureInfo& operator=(const Value& src);
+ void serialize(boost::json::object& dst) const;
};
class NormalTextureInfo : public TextureInfo
@@ -60,6 +80,8 @@ namespace LL
F32 mScale = 1.0f;
const NormalTextureInfo& operator=(const tinygltf::NormalTextureInfo& src);
+ const NormalTextureInfo& operator=(const Value& src);
+ void serialize(boost::json::object& dst) const;
};
class OcclusionTextureInfo : public TextureInfo
@@ -68,17 +90,24 @@ namespace LL
F32 mStrength = 1.0f;
const OcclusionTextureInfo& operator=(const tinygltf::OcclusionTextureInfo& src);
+ const OcclusionTextureInfo& operator=(const Value& src);
+ void serialize(boost::json::object& dst) const;
};
class PbrMetallicRoughness
{
public:
- glh::vec4f mBaseColorFactor = glh::vec4f(1.f,1.f,1.f,1.f);
+ vec4 mBaseColorFactor = vec4(1.f,1.f,1.f,1.f);
TextureInfo mBaseColorTexture;
F32 mMetallicFactor = 1.0f;
F32 mRoughnessFactor = 1.0f;
TextureInfo mMetallicRoughnessTexture;
+
+ bool operator==(const PbrMetallicRoughness& rhs) const;
+ bool operator!=(const PbrMetallicRoughness& rhs) const;
const PbrMetallicRoughness& operator=(const tinygltf::PbrMetallicRoughness& src);
+ const PbrMetallicRoughness& operator=(const Value& src);
+ void serialize(boost::json::object& dst) const;
};
@@ -93,13 +122,16 @@ namespace LL
std::string mName;
- glh::vec3f mEmissiveFactor = glh::vec3f(0.f, 0.f, 0.f);
- std::string mAlphaMode = "OPAQUE";
+ vec3 mEmissiveFactor = vec3(0.f, 0.f, 0.f);
+ AlphaMode mAlphaMode = AlphaMode::OPAQUE;
F32 mAlphaCutoff = 0.5f;
bool mDoubleSided = false;
-
+ // bind for rendering
+ void bind(Asset& asset);
const Material& operator=(const tinygltf::Material& src);
+ const Material& operator=(const Value& src);
+ void serialize(boost::json::object& dst) const;
void allocateGLResources(Asset& asset);
};
@@ -112,6 +144,8 @@ namespace LL
std::string mName;
const Mesh& operator=(const tinygltf::Mesh& src);
+ const Mesh& operator=(const Value& src);
+ void serialize(boost::json::object& dst) const;
void allocateGLResources(Asset& asset);
};
@@ -119,14 +153,14 @@ namespace LL
class Node
{
public:
- LLMatrix4a mMatrix; //local transform
- LLMatrix4a mRenderMatrix; //transform for rendering
- LLMatrix4a mAssetMatrix; //transform from local to asset space
- LLMatrix4a mAssetMatrixInv; //transform from asset to local space
+ mat4 mMatrix = glm::identity<mat4>(); //local transform
+ mat4 mRenderMatrix; //transform for rendering
+ mat4 mAssetMatrix; //transform from local to asset space
+ mat4 mAssetMatrixInv; //transform from asset to local space
- glh::vec3f mTranslation;
- glh::quaternionf mRotation;
- glh::vec3f mScale;
+ vec3 mTranslation = vec3(0,0,0);
+ quat mRotation = glm::identity<quat>();
+ vec3 mScale = vec3(1.f,1.f,1.f);
// if true, mMatrix is valid and up to date
bool mMatrixValid = false;
@@ -145,13 +179,15 @@ namespace LL
std::string mName;
const Node& operator=(const tinygltf::Node& src);
+ const Node& operator=(const Value& src);
+ void serialize(boost::json::object& dst) const;
// Set mRenderMatrix to a transform that can be used for the current render pass
// modelview -- parent's render matrix
- void updateRenderTransforms(Asset& asset, const LLMatrix4a& modelview);
+ void updateRenderTransforms(Asset& asset, const mat4& modelview);
// update mAssetMatrix and mAssetMatrixInv
- void updateTransforms(Asset& asset, const LLMatrix4a& parentMatrix);
+ void updateTransforms(Asset& asset, const mat4& parentMatrix);
// ensure mMatrix is valid -- if mMatrixValid is false and mTRSValid is true, will update mMatrix to match Translation/Rotation/Scale
void makeMatrixValid();
@@ -161,15 +197,15 @@ namespace LL
// Set rotation of this node
// SIDE EFFECT: invalidates mMatrix
- void setRotation(const glh::quaternionf& rotation);
+ void setRotation(const quat& rotation);
// Set translation of this node
// SIDE EFFECT: invalidates mMatrix
- void setTranslation(const glh::vec3f& translation);
+ void setTranslation(const vec3& translation);
// Set scale of this node
// SIDE EFFECT: invalidates mMatrix
- void setScale(const glh::vec3f& scale);
+ void setScale(const vec3& scale);
};
class Skin
@@ -179,12 +215,14 @@ namespace LL
S32 mSkeleton = INVALID_INDEX;
std::vector<S32> mJoints;
std::string mName;
- std::vector<glh::matrix4f> mInverseBindMatricesData;
+ std::vector<mat4> mInverseBindMatricesData;
void allocateGLResources(Asset& asset);
void uploadMatrixPalette(Asset& asset, Node& node);
const Skin& operator=(const tinygltf::Skin& src);
+ const Skin& operator=(const Value& src);
+ void serialize(boost::json::object& dst) const;
};
class Scene
@@ -194,9 +232,11 @@ namespace LL
std::string mName;
const Scene& operator=(const tinygltf::Scene& src);
-
+ const Scene& operator=(const Value& src);
+ void serialize(boost::json::object& dst) const;
+
void updateTransforms(Asset& asset);
- void updateRenderTransforms(Asset& asset, const LLMatrix4a& modelview);
+ void updateRenderTransforms(Asset& asset, const mat4& modelview);
};
class Texture
@@ -207,18 +247,22 @@ namespace LL
std::string mName;
const Texture& operator=(const tinygltf::Texture& src);
+ const Texture& operator=(const Value& src);
+ void serialize(boost::json::object& dst) const;
};
class Sampler
{
public:
- S32 mMagFilter;
- S32 mMinFilter;
- S32 mWrapS;
- S32 mWrapT;
+ S32 mMagFilter = LINEAR;
+ S32 mMinFilter = LINEAR_MIPMAP_LINEAR;
+ S32 mWrapS = REPEAT;
+ S32 mWrapT = REPEAT;
std::string mName;
const Sampler& operator=(const tinygltf::Sampler& src);
+ const Sampler& operator=(const Value& src);
+ void serialize(boost::json::object& dst) const;
};
class Image
@@ -231,43 +275,35 @@ namespace LL
S32 mBufferView = INVALID_INDEX;
std::vector<U8> mData;
- S32 mWidth;
- S32 mHeight;
- S32 mComponent;
- S32 mBits;
- S32 mPixelType;
+ S32 mWidth = -1;
+ S32 mHeight = -1;
+ S32 mComponent = -1;
+ S32 mBits = -1;
+ S32 mPixelType = -1;
LLPointer<LLViewerFetchedTexture> mTexture;
- const Image& operator=(const tinygltf::Image& src)
- {
- mName = src.name;
- mUri = src.uri;
- mMimeType = src.mimeType;
- mData = src.image;
- mWidth = src.width;
- mHeight = src.height;
- mComponent = src.component;
- mBits = src.bits;
- mBufferView = src.bufferView;
- mPixelType = src.pixel_type;
- return *this;
- }
-
+ const Image& operator=(const tinygltf::Image& src);
+ const Image& operator=(const Value& src);
+ void serialize(boost::json::object& dst) const;
+
// save image clear local data, and set uri
void decompose(Asset& asset, const std::string& filename);
- void allocateGLResources()
- {
- // allocate texture
+ // erase the buffer view associated with this image
+ // free any associated resources
+ // preserve only uri and name
+ void clearData(Asset& asset);
- }
+ void allocateGLResources();
};
// C++ representation of a GLTF Asset
class Asset
{
public:
+
+ static const std::string minVersion_default;
std::vector<Scene> mScenes;
std::vector<Node> mNodes;
std::vector<Mesh> mMeshes;
@@ -287,14 +323,15 @@ namespace LL
std::string mCopyright;
S32 mDefaultScene = INVALID_INDEX;
- tinygltf::Value mExtras;
+ Value mExtras;
+ U32 mPendingBuffers = 0;
// the last time update() was called according to gFrameTimeSeconds
F32 mLastUpdateTime = gFrameTimeSeconds;
// prepare the asset for rendering
- void allocateGLResources(const std::string& filename, const tinygltf::Model& model);
+ void allocateGLResources(const std::string& filename = "", const tinygltf::Model& model = tinygltf::Model());
// Called periodically (typically once per frame)
// Any ongoing work (such as animations) should be handled here
@@ -307,7 +344,7 @@ namespace LL
void updateTransforms();
// update node render transforms
- void updateRenderTransforms(const LLMatrix4a& modelview);
+ void updateRenderTransforms(const mat4& modelview);
void render(bool opaque, bool rigged = false);
void renderOpaque();
@@ -323,7 +360,13 @@ namespace LL
S32* primitive_hitp = nullptr // return the index of the primitive that was hit
);
+ Asset() = default;
+ Asset(const tinygltf::Model& src);
+ Asset(const Value& src);
+
const Asset& operator=(const tinygltf::Model& src);
+ const Asset& operator=(const Value& src);
+ void serialize(boost::json::object& dst) const;
// save the asset to a tinygltf model
void save(tinygltf::Model& dst);
@@ -335,5 +378,8 @@ namespace LL
// updates all bufferview indices in this Asset as needed
void eraseBufferView(S32 bufferView);
};
+
+ Material::AlphaMode gltf_alpha_mode_to_enum(const std::string& alpha_mode);
+ std::string enum_to_gltf_alpha_mode(Material::AlphaMode alpha_mode);
}
}