Merge pull request #35 from dabingnn/v3Animation

V3 animation
This commit is contained in:
Huabing.Xu 2014-06-11 23:23:55 +08:00
commit 8ca8715a85
9 changed files with 127 additions and 79 deletions

View File

@ -1745,6 +1745,8 @@
B29594CF1926D61F003EEF37 /* CCSprite3DDataCache.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B29594BF1926D61F003EEF37 /* CCSprite3DDataCache.cpp */; };
B29594D01926D61F003EEF37 /* CCSprite3DDataCache.h in Headers */ = {isa = PBXBuildFile; fileRef = B29594C01926D61F003EEF37 /* CCSprite3DDataCache.h */; };
B29594D11926D61F003EEF37 /* CCSprite3DDataCache.h in Headers */ = {isa = PBXBuildFile; fileRef = B29594C01926D61F003EEF37 /* CCSprite3DDataCache.h */; };
B2D3D3B91948613300BA4831 /* CCBundle3DData.h in Headers */ = {isa = PBXBuildFile; fileRef = B2D3D3B81948613300BA4831 /* CCBundle3DData.h */; };
B2D3D3BA1948613300BA4831 /* CCBundle3DData.h in Headers */ = {isa = PBXBuildFile; fileRef = B2D3D3B81948613300BA4831 /* CCBundle3DData.h */; };
B37510711823AC9F00B3BA6A /* CCPhysicsBodyInfo_chipmunk.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B37510451823AC7B00B3BA6A /* CCPhysicsBodyInfo_chipmunk.cpp */; };
B37510721823AC9F00B3BA6A /* CCPhysicsBodyInfo_chipmunk.h in Headers */ = {isa = PBXBuildFile; fileRef = B37510461823AC7B00B3BA6A /* CCPhysicsBodyInfo_chipmunk.h */; };
B37510731823AC9F00B3BA6A /* CCPhysicsContactInfo_chipmunk.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B37510471823AC7B00B3BA6A /* CCPhysicsContactInfo_chipmunk.cpp */; };
@ -2812,6 +2814,7 @@
B29594BE1926D61F003EEF37 /* CCSprite3D.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCSprite3D.h; sourceTree = "<group>"; };
B29594BF1926D61F003EEF37 /* CCSprite3DDataCache.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCSprite3DDataCache.cpp; sourceTree = "<group>"; };
B29594C01926D61F003EEF37 /* CCSprite3DDataCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCSprite3DDataCache.h; sourceTree = "<group>"; };
B2D3D3B81948613300BA4831 /* CCBundle3DData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCBundle3DData.h; sourceTree = "<group>"; };
B37510451823AC7B00B3BA6A /* CCPhysicsBodyInfo_chipmunk.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCPhysicsBodyInfo_chipmunk.cpp; sourceTree = "<group>"; };
B37510461823AC7B00B3BA6A /* CCPhysicsBodyInfo_chipmunk.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCPhysicsBodyInfo_chipmunk.h; sourceTree = "<group>"; };
B37510471823AC7B00B3BA6A /* CCPhysicsContactInfo_chipmunk.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCPhysicsContactInfo_chipmunk.cpp; sourceTree = "<group>"; };
@ -4863,6 +4866,7 @@
B29594BE1926D61F003EEF37 /* CCSprite3D.h */,
B29594BF1926D61F003EEF37 /* CCSprite3DDataCache.cpp */,
B29594C01926D61F003EEF37 /* CCSprite3DDataCache.h */,
B2D3D3B81948613300BA4831 /* CCBundle3DData.h */,
);
name = 3d;
path = ../cocos/3d;
@ -4930,6 +4934,7 @@
50ABBD8D1925AB4100A911A9 /* CCGLProgram.h in Headers */,
50ABBEA11925AB6F00A911A9 /* CCScheduler.h in Headers */,
50ABBDB71925AB4100A911A9 /* CCTexture2D.h in Headers */,
B2D3D3B91948613300BA4831 /* CCBundle3DData.h in Headers */,
2905FA6C18CF08D100240AA3 /* UIPageView.h in Headers */,
50FCEB9518C72017004AD434 /* ButtonReader.h in Headers */,
50ABBE811925AB6F00A911A9 /* CCEventType.h in Headers */,
@ -5418,6 +5423,7 @@
1A01C68918F57BE800EFE3A6 /* CCBool.h in Headers */,
1A57007C180BC5A10088DEC7 /* CCActionInstant.h in Headers */,
50ABBE781925AB6F00A911A9 /* CCEventListenerTouch.h in Headers */,
B2D3D3BA1948613300BA4831 /* CCBundle3DData.h in Headers */,
B37510861823ACA100B3BA6A /* CCPhysicsWorldInfo_chipmunk.h in Headers */,
1A570080180BC5A10088DEC7 /* CCActionInterval.h in Headers */,
1A570084180BC5A10088DEC7 /* CCActionManager.h in Headers */,

View File

@ -116,7 +116,6 @@ void Animate3D::update(float t)
if (curve->rotCurve)
{
curve->rotCurve->evaluate(t, dst, QuatSlerp);
CCLOG("%f,%f,%f,%f", dst[0], dst[1], dst[2], dst[3]);
bone->setAnimationValueRotation(dst);
}
if (curve->scaleCurve)

View File

@ -42,7 +42,7 @@ Animation3D* Animation3D::getOrCreate(const std::string& fileName, const std::st
auto bundle = Bundle3D::getInstance();
if (bundle->load(fullPath))
{
Bundle3D::Animation3DData animationdata;
Animation3DData animationdata;
animationdata.animation = new Animation3D();
bundle->loadAnimationData(animationName, &animationdata);
animation = animationdata.animation;

View File

@ -35,30 +35,6 @@ NS_CC_BEGIN
Bundle3D* Bundle3D::_instance = nullptr;
Bundle3D::MeshData::MeshData()
: vertex(nullptr)
, vertexSizeInFloat(0)
, indices(nullptr)
, numIndex(0)
, attribs(nullptr)
, attribCount(0)
{
}
Bundle3D::MeshData::~MeshData()
{
resetData();
}
void Bundle3D::MeshData::resetData()
{
CC_SAFE_DELETE_ARRAY(vertex);
CC_SAFE_DELETE_ARRAY(indices);
CC_SAFE_DELETE_ARRAY(attribs);
vertexSizeInFloat = 0;
numIndex = 0;
attribCount = 0;
}
Bundle3D* Bundle3D::getInstance()
{
if (_instance == nullptr)

View File

@ -32,51 +32,20 @@
#include "base/ccTypes.h"
#include "3d/CCMesh.h"
#include "3d/CCBundle3DData.h"
NS_CC_BEGIN
class Animation3D;
struct Animation3DData
{
Animation3D* animation;
};
class Bundle3D
{
public:
struct MeshData
{
float* vertex;
int vertexSizeInFloat;
unsigned short* indices;
int numIndex;
MeshVertexAttrib* attribs;
int attribCount;
void resetData();
MeshData();
~MeshData();
};
struct SkinData
{
Mat4 bindShape;
std::vector<std::string> boneNames;
std::vector<Mat4> inverseBindPoseMatrices; //bind pose of bone
std::map<int, std::vector<int> > boneChild;//key parent, value child
int rootBoneIndex;
void resetData()
{
bindShape.setIdentity();
boneNames.clear();
inverseBindPoseMatrices.clear();
boneChild.clear();
rootBoneIndex = -1;
}
};
struct MaterialData
{
std::string texturePath;
};
struct Animation3DData
{
Animation3D* animation;
};
static Bundle3D* getInstance();

109
cocos/3d/CCBundle3DData.h Normal file
View File

@ -0,0 +1,109 @@
/****************************************************************************
Copyright (c) 2014 Chukong Technologies Inc.
http://www.cocos2d-x.org
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.
****************************************************************************/
#ifndef __CC_BUNDLE_3D_DATA_H__
#define __CC_BUNDLE_3D_DATA_H__
#include "base/CCRef.h"
#include "base/ccTypes.h"
#include "math/CCMath.h"
#include <vector>
#include <map>
NS_CC_BEGIN
//mesh vertex attribute
struct MeshVertexAttrib
{
//attribute size
GLint size;
//GL_FLOAT
GLenum type;
//VERTEX_ATTRIB_POSITION,VERTEX_ATTRIB_COLOR,VERTEX_ATTRIB_TEX_COORD,VERTEX_ATTRIB_NORMAL, VERTEX_ATTRIB_BLEND_WEIGHT, VERTEX_ATTRIB_BLEND_INDEX, GLProgram for detail
int vertexAttrib;
//size in bytes
int attribSizeBytes;
};
struct MeshData
{
float* vertex;
int vertexSizeInFloat;
unsigned short* indices;
int numIndex;
MeshVertexAttrib* attribs;
int attribCount;
public:
void resetData()
{
CC_SAFE_DELETE_ARRAY(vertex);
CC_SAFE_DELETE_ARRAY(indices);
CC_SAFE_DELETE_ARRAY(attribs);
vertexSizeInFloat = 0;
numIndex = 0;
attribCount = 0;
}
MeshData()
: vertex(nullptr)
, vertexSizeInFloat(0)
, indices(nullptr)
, numIndex(0)
, attribs(nullptr)
, attribCount(0)
{
}
~MeshData()
{
resetData();
}
};
struct SkinData
{
Mat4 bindShape;
std::vector<std::string> boneNames;
std::vector<Mat4> inverseBindPoseMatrices; //bind pose of bone
std::map<int, std::vector<int> > boneChild;//key parent, value child
int rootBoneIndex;
void resetData()
{
bindShape.setIdentity();
boneNames.clear();
inverseBindPoseMatrices.clear();
boneChild.clear();
rootBoneIndex = -1;
}
};
struct MaterialData
{
std::string texturePath;
};
NS_CC_END
#endif //__CC_BUNDLE_3D_DATA_H__

View File

@ -33,20 +33,9 @@
#include "math/CCMath.h"
#include "renderer/CCGLProgram.h"
NS_CC_BEGIN
#include "3d/CCBundle3DData.h"
//mesh vertex attribute
struct MeshVertexAttrib
{
//attribute size
GLint size;
//GL_FLOAT
GLenum type;
//VERTEX_ATTRIB_POSITION,VERTEX_ATTRIB_COLOR,VERTEX_ATTRIB_TEX_COORD,VERTEX_ATTRIB_NORMAL, VERTEX_ATTRIB_BLEND_WEIGHT, VERTEX_ATTRIB_BLEND_INDEX, GLProgram for detail
int vertexAttrib;
//size in bytes
int attribSizeBytes;
};
NS_CC_BEGIN
class RenderMeshData
{

View File

@ -259,7 +259,7 @@ MeshSkin* MeshSkin::create(const std::string& filename, const std::string& name)
bool ret = instance->load(fullPath);
if (ret)
{
Bundle3D::SkinData skindata;
SkinData skindata;
if (instance->loadSkinData(name, &skindata))
{
auto skin = new MeshSkin();

View File

@ -145,7 +145,7 @@ bool Sprite3D::loadFromC3x(const std::string& path)
if (!bundle->load(fullPath))
return false;
Bundle3D::MeshData meshdata;
MeshData meshdata;
bool ret = bundle->loadMeshData("", &meshdata);
if (!ret)
{
@ -158,7 +158,7 @@ bool Sprite3D::loadFromC3x(const std::string& path)
_skin = MeshSkin::create(fullPath, "");
CC_SAFE_RETAIN(_skin);
Bundle3D::MaterialData materialdata;
MaterialData materialdata;
ret = bundle->loadMaterialData("", &materialdata);
if (ret)
{