From 136bc8874f5bea4ba775e498e932e3a097acc56c Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Sat, 13 Jun 2020 12:08:01 -0500 Subject: [PATCH] adds an animspeed and animoffset to tsstatic instances so clones can be set to break up syncing on multiples --- Engine/source/T3D/tsStatic.cpp | 46 ++++++++++++++++++++++++++-------- Engine/source/T3D/tsStatic.h | 10 ++++++-- 2 files changed, 43 insertions(+), 13 deletions(-) diff --git a/Engine/source/T3D/tsStatic.cpp b/Engine/source/T3D/tsStatic.cpp index 99c969fac..3c030556c 100644 --- a/Engine/source/T3D/tsStatic.cpp +++ b/Engine/source/T3D/tsStatic.cpp @@ -142,6 +142,8 @@ TSStatic::TSStatic() #ifdef TORQUE_AFX_ENABLED afxZodiacData::convertGradientRangeFromDegrees(mGradientRange, mGradientRangeUser); #endif + mAnimOffset = 0.0f; + mAnimSpeed = 1.0f; mShapeAsset = StringTable->EmptyString(); mShapeAssetId = StringTable->EmptyString(); @@ -164,9 +166,17 @@ ImplementEnumType(TSMeshType, { TSStatic::VisibleMesh, "Visible Mesh", "Rendered mesh polygons." }, EndImplementEnumType; +FRangeValidator percentValidator(0.0f, 1.0f); +F32 AnimSpeedMax = 4.0f; +FRangeValidator speedValidator(0.0f, AnimSpeedMax); void TSStatic::initPersistFields() { + addFieldV("AnimOffset", TypeF32, Offset(mAnimOffset, TSStatic), &percentValidator, + "Percent Animation Offset."); + + addFieldV("AnimSpeed", TypeF32, Offset(mAnimSpeed, TSStatic), &speedValidator, + "Percent Animation Speed."); addGroup("Shape"); addProtectedField("shapeAsset", TypeShapeAssetId, Offset(mShapeAssetId, TSStatic), @@ -454,12 +464,8 @@ bool TSStatic::_createShape() mShapeInstance = new TSShapeInstance(mShape, isClientObject()); if (isClientObject()) - { mShapeInstance->cloneMaterialList(); - } - if (isClientObject()) - mShapeInstance->cloneMaterialList(); if (isGhost()) { // Reapply the current skin @@ -475,8 +481,8 @@ bool TSStatic::_createShape() if (ambientSeq > -1 && !mAmbientThread) mAmbientThread = mShapeInstance->addThread(); - if (mAmbientThread) - mShapeInstance->setSequence(mAmbientThread, ambientSeq, 0); + if ( mAmbientThread ) + mShapeInstance->setSequence(mAmbientThread, ambientSeq, mAnimOffset); // Resolve CubeReflectorDesc. if (cubeDescName.isNotEmpty()) @@ -720,9 +726,11 @@ void TSStatic::reSkin() void TSStatic::processTick(const Move* move) { - if (isServerObject() && mPlayAmbient && mAmbientThread) - mShapeInstance->advanceTime(TickSec, mAmbientThread); - + if ( isServerObject() && mPlayAmbient && mAmbientThread ) + { + mShapeInstance->setTimeScale(mAmbientThread, mAnimSpeed); + mShapeInstance->advanceTime( TickSec, mAmbientThread ); + } if (isMounted()) { MatrixF mat(true); @@ -737,8 +745,11 @@ void TSStatic::interpolateTick(F32 delta) void TSStatic::advanceTime(F32 dt) { - if (mPlayAmbient && mAmbientThread) - mShapeInstance->advanceTime(dt, mAmbientThread); + if ( mPlayAmbient && mAmbientThread ) + { + mShapeInstance->setTimeScale(mAmbientThread, mAnimSpeed); + mShapeInstance->advanceTime( dt, mAmbientThread ); + } if (isMounted()) { @@ -982,6 +993,12 @@ U32 TSStatic::packUpdate(NetConnection* con, U32 mask, BitStream* stream) stream->write(mForceDetail); + if (stream->writeFlag(mAnimOffset != 0.0f)) + stream->writeFloat(mAnimOffset, 7); + + if (stream->writeFlag(mAnimSpeed != 1.0f)) + stream->writeSignedFloat(mAnimSpeed / AnimSpeedMax, 7); + stream->writeFlag(mPlayAmbient); } @@ -1094,6 +1111,13 @@ void TSStatic::unpackUpdate(NetConnection* con, BitStream* stream) stream->read(&mRenderNormalScalar); stream->read(&mForceDetail); + + if (stream->readFlag()) + mAnimOffset = stream->readFloat(7); + + if (stream->readFlag()) + mAnimSpeed = stream->readSignedFloat(7) * AnimSpeedMax; + mPlayAmbient = stream->readFlag(); diff --git a/Engine/source/T3D/tsStatic.h b/Engine/source/T3D/tsStatic.h index a26e2b016..067d4614d 100644 --- a/Engine/source/T3D/tsStatic.h +++ b/Engine/source/T3D/tsStatic.h @@ -48,6 +48,10 @@ #include "scene/reflector.h" #endif +#ifndef _COLLADA_UTILS_H_ +#include "ts/collada/colladaUtils.h" +#endif + #ifndef _ASSET_PTR_H_ #include "assets/assetPtr.h" #endif @@ -202,8 +206,9 @@ protected: String mAppliedSkinName; bool mPlayAmbient; - TSThread* mAmbientThread; - + TSThread* mAmbientThread; + F32 mAnimOffset; + F32 mAnimSpeed; /// The type of mesh data to return for collision queries. MeshType mCollisionType; @@ -272,6 +277,7 @@ public: const Vector& getCollisionDetails() const { return mCollisionDetails; } const Vector& getLOSDetails() const { return mLOSDetails; } + bool hasAnim() { return mAmbientThread != NULL; } virtual void onInspect(GuiInspector*);