123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- /**
- * @file llgltfanimation.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_LLGLTFANIMATION_H
- #define LL_LLGLTFANIMATION_H
- #include "llgltfaccessor.h"
- // *TODO: get rid of this (again) ! HB
- #include "glh_linear.h"
- // Saves from including "tinygltf/tiny_gltf.h" here. HB
- namespace tinygltf
- {
- struct Animation;
- struct AnimationChannel;
- struct AnimationSampler;
- }
- namespace LLGLTF
- {
- class Asset;
- class Animation
- {
- public:
- Animation();
- class Sampler
- {
- public:
- Sampler();
- void allocateGLResources(Asset& asset);
- const Sampler& operator=(const tinygltf::AnimationSampler& src);
- // Gets the frame index and time for the specified time. 'asset' is
- // the asset to reference for Accessors, 'time' is the animation
- // time to get the frame info for 'frame_idx' is the index of the
- // closest frame that precedes the specified time, and 't' is the
- // interpolant value between the frameIndex and the next frame.
- void getFrameInfo(Asset& asset, F32 time, U32& frame_idx, F32& t);
- public:
- std::vector<F32> mFrameTimes;
- std::string mInterpolation;
- F32 mMinTime;
- F32 mMaxTime;
- S32 mInput;
- S32 mOutput;
- };
- class Channel
- {
- public:
- Channel();
- const Channel& operator=(const tinygltf::AnimationChannel& src);
- class Target
- {
- public:
- LL_INLINE Target()
- : mNode(INVALID_INDEX)
- {
- }
- public:
- std::string mPath;
- S32 mNode;
- };
- public:
- std::string mTargetPath;
- std::string mName;
- Target mTarget;
- S32 mSampler;
- };
- class RotationChannel : public Channel
- {
- public:
- const RotationChannel& operator=(const tinygltf::AnimationChannel& src);
- // Prepares data needed for rendering. 'asset' is the asset to
- // reference for Accessors. 'sampler' is the sampler associated
- // with this channel.
- void allocateGLResources(Asset& asset, Sampler& sampler);
- void apply(Asset& asset, Sampler& sampler, F32 time);
- public:
- std::vector<glh::quaternionf> mRotations;
- };
- class TranslationChannel : public Channel
- {
- public:
- const TranslationChannel& operator=(const tinygltf::AnimationChannel& src);
- // Prepares data needed for rendering. 'asset' is the asset to
- // reference for Accessors. 'sampler' is the sampler associated
- // with this channel.
- void allocateGLResources(Asset& asset, Sampler& sampler);
- void apply(Asset& asset, Sampler& sampler, F32 time);
- public:
- std::vector<glh::vec3f> mTranslations;
- };
- class ScaleChannel : public Channel
- {
- public:
- const ScaleChannel& operator=(const tinygltf::AnimationChannel& src);
- // Prepares data needed for rendering. 'asset' is the asset to
- // reference for Accessors. 'sampler' is the sampler associated
- // with this channel.
- void allocateGLResources(Asset& asset, Sampler& sampler);
- void apply(Asset& asset, Sampler& sampler, F32 time);
- public:
- std::vector<glh::vec3f> mScales;
- };
- const Animation& operator=(const tinygltf::Animation& src);
-
- void allocateGLResources(Asset& asset);
- void update(Asset& asset, float dt);
- // apply this animation at the specified time
- void apply(Asset& asset, F32 time);
- public:
- std::string mName;
- std::vector<Sampler> mSamplers;
- std::vector<RotationChannel> mRotationChannels;
- std::vector<TranslationChannel> mTranslationChannels;
- std::vector<ScaleChannel> mScaleChannels;
- // Min/max time values for all samplers combined
- F32 mMinTime;
- F32 mMaxTime;
-
- // Current time of the animation
- F32 mTime;
- };
- }
- #endif // LL_LLGLTFANIMATION_H
|