Skip to content

Commit

Permalink
feat: #45 Add Skeleton & Animation Controller
Browse files Browse the repository at this point in the history
  • Loading branch information
ducphamhong committed Jan 10, 2020
1 parent 878504c commit 58104af
Show file tree
Hide file tree
Showing 12 changed files with 573 additions and 13 deletions.
81 changes: 81 additions & 0 deletions Projects/Skylicht/Engine/Source/Animation/CAnimationController.cpp
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 Projects/Skylicht/Engine/Source/Animation/CAnimationController.h
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();
};
}
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;
}
}
}
}
}

}
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();
};
}
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()
{

}
}
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();
};
}
Loading

0 comments on commit 58104af

Please sign in to comment.