Skip to content

Commit

Permalink
Merge pull request #44 from skylicht-lab/feature/#43-add-collada-anim…
Browse files Browse the repository at this point in the history
…ation-loader

feat: #43 Add Collada Animation loader
  • Loading branch information
ducphamhong authored Jan 8, 2020
2 parents 7712175 + 9490324 commit eb46b17
Show file tree
Hide file tree
Showing 10 changed files with 2,439 additions and 18 deletions.
8 changes: 4 additions & 4 deletions Documents/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Do some thing 2
Remember tag your issues id ex: #282 on your commit message, and branch name
## Code style
- We try to adhere to the existing [**Irrlicht code style**](http://irrlicht.sourceforge.net/?page_id=140).
- You can use your code style in your local project `Projects/{YourProject}`. When you fix bug or commit a feature on `Projects/Skylicht*`, please follow our style.
- You can use your code style in your local project `Projects/{YourProject}`. If you fix bug or commit a feature on `Projects/Skylicht/*`, please follow our style.
### Code formation
Use **TAB Indent** instead 2 space for C/C++ code.

Expand All @@ -30,7 +30,7 @@ Use **TAB Indent** instead 2 space for C/C++ code.
- On Mac: **`Shift` + `Option` + `F`**
- On Ubuntu: **`Ctrl` + `Shift` + `I`**
### Example code style
**`NOT RECOMMENDED`**
**`NOT RECOMMENDED JS STYLE`**
```
void function(int foo){
...
Expand All @@ -57,7 +57,7 @@ I recommend we don't use ~~c_style_function_name~~ and ~~character _~~ for funct

**`BAD`**
```
// not recommend in .cpp
// not recommend underscore C style in C++ (*.cpp)
void func_style_c_name()
{
// not recommend
Expand All @@ -75,7 +75,7 @@ void MODULE_func_style_c_name()
```
**`GOOD`**
```
void functionJavaNameStyle()
void camelCaseStyle()
{
int variable = 0;
...
Expand Down
110 changes: 110 additions & 0 deletions Projects/Skylicht/Engine/Source/Animation/CAnimationClip.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
!@
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 "CAnimationTrack.h"

namespace Skylicht
{
struct SNodeAnim
{
std::string SceneNodeName;
CFrameData Data;
};

class CAnimationClip
{
public:
std::string AnimName;
float Time;
float Duration;
bool Loop;

std::vector<SNodeAnim*> AnimInfo;
std::map<std::string, SNodeAnim*> AnimNameToInfo;

CAnimationClip()
{
AnimName = "";
Time = 0.0f;
Duration = 0.0f;
Loop = true;
}

virtual ~CAnimationClip()
{
freeAllNodeAnim();
}

void freeAllNodeAnim()
{
for (SNodeAnim* &i : AnimInfo)
{
delete i;
}
AnimInfo.clear();
AnimNameToInfo.clear();
}

void addNodeAnim(SNodeAnim* anim)
{
for (SNodeAnim *&i : AnimInfo)
{
if (i->SceneNodeName == anim->SceneNodeName)
{
delete i;
i = anim;
AnimNameToInfo[i->SceneNodeName] = anim;
return;
}
}

AnimInfo.push_back(anim);
AnimNameToInfo[anim->SceneNodeName] = anim;
}

int getNodeAnimCount()
{
return (int)AnimInfo.size();
}

SNodeAnim* getAnimOfSceneNode(int i)
{
return AnimInfo[i];
}

SNodeAnim* getAnimOfSceneNode(const std::string &sceneNodeName)
{
return AnimNameToInfo[sceneNodeName];
}

float getRealTimeLength(float baseFps = 30.0f)
{
return Duration * 1000.0f / baseFps;
}
};

}
Loading

0 comments on commit eb46b17

Please sign in to comment.