-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: #45 Add Skeleton & Animation Controller
- Loading branch information
1 parent
878504c
commit 58104af
Showing
12 changed files
with
573 additions
and
13 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
Projects/Skylicht/Engine/Source/Animation/CAnimationController.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
!@ | ||
MIT License | ||
Copyright (c) 2019 Skylicht Technology CO., LTD | ||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files | ||
(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, | ||
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, | ||
subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | ||
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
This file is part of the "Skylicht Engine". | ||
https://github.com/skylicht-lab/skylicht-engine | ||
!# | ||
*/ | ||
|
||
#include "pch.h" | ||
#include "GameObject/CGameObject.h" | ||
#include "CAnimationController.h" | ||
|
||
#include "RenderMesh/CRenderMesh.h" | ||
|
||
namespace Skylicht | ||
{ | ||
CAnimationController::CAnimationController() | ||
{ | ||
|
||
} | ||
|
||
CAnimationController::~CAnimationController() | ||
{ | ||
releaseAllSkeleton(); | ||
} | ||
|
||
void CAnimationController::initComponent() | ||
{ | ||
|
||
} | ||
|
||
void CAnimationController::updateComponent() | ||
{ | ||
for (CSkeleton *&skeleton : m_skeletons) | ||
{ | ||
if (skeleton->isEnable() == true) | ||
{ | ||
skeleton->update(); | ||
} | ||
} | ||
} | ||
|
||
CSkeleton* CAnimationController::createSkeleton() | ||
{ | ||
int id = (int)m_skeletons.size(); | ||
|
||
CSkeleton* skeleton = new CSkeleton(id); | ||
|
||
CRenderMesh *renderMesh = m_gameObject->getComponent<CRenderMesh>(); | ||
if (renderMesh != NULL) | ||
skeleton->initSkeleton(renderMesh->getEntities()); | ||
|
||
m_skeletons.push_back(skeleton); | ||
return skeleton; | ||
} | ||
|
||
void CAnimationController::releaseAllSkeleton() | ||
{ | ||
for (CSkeleton *&skeleton : m_skeletons) | ||
{ | ||
delete skeleton; | ||
} | ||
m_skeletons.clear(); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
Projects/Skylicht/Engine/Source/Animation/CAnimationController.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
!@ | ||
MIT License | ||
Copyright (c) 2019 Skylicht Technology CO., LTD | ||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files | ||
(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, | ||
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, | ||
subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | ||
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
This file is part of the "Skylicht Engine". | ||
https://github.com/skylicht-lab/skylicht-engine | ||
!# | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "Skeleton/CSkeleton.h" | ||
#include "Components/CComponentSystem.h" | ||
|
||
namespace Skylicht | ||
{ | ||
class CAnimationController : public CComponentSystem | ||
{ | ||
protected: | ||
std::vector<CSkeleton*> m_skeletons; | ||
|
||
public: | ||
CAnimationController(); | ||
|
||
virtual ~CAnimationController(); | ||
|
||
virtual void initComponent(); | ||
|
||
virtual void updateComponent(); | ||
|
||
public: | ||
|
||
CSkeleton* createSkeleton(); | ||
|
||
void releaseAllSkeleton(); | ||
}; | ||
} |
80 changes: 80 additions & 0 deletions
80
Projects/Skylicht/Engine/Source/Animation/Skeleton/CAnimationTimeline.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
!@ | ||
MIT License | ||
Copyright (c) 2019 Skylicht Technology CO., LTD | ||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files | ||
(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, | ||
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, | ||
subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | ||
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
This file is part of the "Skylicht Engine". | ||
https://github.com/skylicht-lab/skylicht-engine | ||
!# | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "pch.h" | ||
#include "CAnimationTimeline.h" | ||
|
||
namespace Skylicht | ||
{ | ||
|
||
CAnimationTimeline::CAnimationTimeline() : | ||
AnimationFrame(0.0f), | ||
AnimationDuration(0.0f), | ||
AnimationSpeed(1.0f), | ||
AnimationSpeedMultiply(1.0f), | ||
AnimationDurationSyncRatio(1.0f), | ||
AnimationWeight(1.0f), | ||
AnimationSleep(0.0f), | ||
EndTrackSleep(0.0f), | ||
SyncSeekRatio(0.0f), | ||
Pause(false) | ||
{ | ||
|
||
} | ||
|
||
void CAnimationTimeline::update() | ||
{ | ||
float milisecondToSecond = 1.0f / 1000.0f; | ||
if (Pause == false) | ||
{ | ||
float secFrameStep = getTimeStep()*AnimationSpeed*AnimationSpeedMultiply*milisecondToSecond; | ||
|
||
// seek animation frame | ||
AnimationFrame = AnimationFrame + secFrameStep; | ||
|
||
// if end of animation | ||
if (AnimationFrame > AnimationDuration) | ||
{ | ||
AnimationFrame = AnimationDuration; | ||
|
||
// if animation is loop | ||
if (AnimationLoop == true) | ||
{ | ||
if (AnimationSleep > 0) | ||
{ | ||
AnimationSleep = AnimationSleep - secFrameStep; | ||
} | ||
else | ||
{ | ||
AnimationFrame = 0.0f; | ||
AnimationSleep = EndTrackSleep; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
Projects/Skylicht/Engine/Source/Animation/Skeleton/CAnimationTimeline.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
!@ | ||
MIT License | ||
Copyright (c) 2019 Skylicht Technology CO., LTD | ||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files | ||
(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, | ||
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, | ||
subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | ||
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
This file is part of the "Skylicht Engine". | ||
https://github.com/skylicht-lab/skylicht-engine | ||
!# | ||
*/ | ||
|
||
#pragma once | ||
|
||
namespace Skylicht | ||
{ | ||
class CAnimationTimeline | ||
{ | ||
public: | ||
float AnimationDuration; // second | ||
float AnimationDurationSyncRatio; | ||
float AnimationFrame; // second | ||
float AnimationSpeed; // todo use for sync on animation blending | ||
float AnimationSpeedMultiply; | ||
float AnimationWeight; | ||
float AnimationSleep; | ||
float SyncSeekRatio; | ||
float EndTrackSleep; | ||
bool AnimationLoop; | ||
bool Pause; | ||
|
||
public: | ||
CAnimationTimeline(); | ||
|
||
void update(); | ||
}; | ||
} |
41 changes: 41 additions & 0 deletions
41
Projects/Skylicht/Engine/Source/Animation/Skeleton/CAnimationTransformData.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
!@ | ||
MIT License | ||
Copyright (c) 2019 Skylicht Technology CO., LTD | ||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files | ||
(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, | ||
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, | ||
subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | ||
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
This file is part of the "Skylicht Engine". | ||
https://github.com/skylicht-lab/skylicht-engine | ||
!# | ||
*/ | ||
|
||
#include "pch.h" | ||
#include "CAnimationTransformData.h" | ||
|
||
namespace Skylicht | ||
{ | ||
CAnimationTransformData::CAnimationTransformData() : | ||
ParentID(-1), | ||
Depth(0) | ||
{ | ||
|
||
} | ||
|
||
CAnimationTransformData::~CAnimationTransformData() | ||
{ | ||
|
||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
Projects/Skylicht/Engine/Source/Animation/Skeleton/CAnimationTransformData.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
!@ | ||
MIT License | ||
Copyright (c) 2019 Skylicht Technology CO., LTD | ||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files | ||
(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, | ||
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, | ||
subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | ||
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
This file is part of the "Skylicht Engine". | ||
https://github.com/skylicht-lab/skylicht-engine | ||
!# | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "Entity/IEntityData.h" | ||
|
||
#include "Animation/CAnimationTrack.h" | ||
#include "Transform/CWorldTransformData.h" | ||
|
||
namespace Skylicht | ||
{ | ||
class CAnimationTransformData : public IEntityData | ||
{ | ||
public: | ||
std::string Name; | ||
|
||
int ParentID; | ||
int Depth; | ||
|
||
// transform if the entity dont have animation | ||
core::matrix4 DefaultRelativeMatrix; | ||
|
||
core::vector3df DefaultPosition; | ||
core::vector3df DefaultScale; | ||
core::quaternion DefaultRotation; | ||
|
||
// transform get from animation track | ||
core::vector3df AnimPosition; | ||
core::vector3df AnimScale; | ||
core::quaternion AnimRotation; | ||
|
||
CWorldTransformData* WorldTransform; | ||
|
||
// current animation track | ||
CAnimationTrack AnimationTrack; | ||
|
||
public: | ||
CAnimationTransformData(); | ||
|
||
virtual ~CAnimationTransformData(); | ||
}; | ||
} |
Oops, something went wrong.