worldmat cache in bone

This commit is contained in:
yangxiao 2014-06-05 18:21:25 +08:00
parent 32ba5f2873
commit 87c7e2b0e9
4 changed files with 81 additions and 5 deletions

View File

@ -51,6 +51,45 @@ bool Bundle3D::load(const std::string& path)
return true; return true;
} }
/**
* load mesh data from bundle
* @param id The ID of the mesh, load the first Mesh in the bundle if it is empty
*/
bool Bundle3D::loadMeshData(const std::string& id, MeshData* meshdata)
{
//meshdata->vertex;
return true;
}
//
/**
* load skin data from bundle
* @param id The ID of the skin, load the first Skin in the bundle if it is empty
*/
bool Bundle3D::loadSkinData(const std::string& id, SkinData* skindata)
{
return true;
}
//
/**
* load material data from bundle
* @param id The ID of the material, load the first Material in the bundle if it is empty
*/
bool Bundle3D::loadMaterialData(const std::string& id, MaterialData* materialdata)
{
return true;
}
/**
* load material data from bundle
* @param id The ID of the animation, load the first animation in the bundle if it is empty
*/
bool Bundle3D::loadAnimationData(const std::string& id, Animation3DData* animationdata)
{
return true;
}
Bundle3D::Bundle3D() Bundle3D::Bundle3D()
{ {

View File

@ -45,6 +45,18 @@ const Mat4& Bone::getInverseBindPose()
return _bindPose; return _bindPose;
} }
bool Bone::needUpdateWorldMat() const
{
bool needupdate = _worldDirty;
auto bone = _parent;
while (!needupdate && bone) {
needupdate = bone->_worldDirty;
bone = bone->_parent;
}
return needupdate;
}
//update own world matrix and children's //update own world matrix and children's
void Bone::updateWorldMat() void Bone::updateWorldMat()
{ {
@ -56,11 +68,17 @@ void Bone::updateWorldMat()
const Mat4& Bone::getWorldMat() const Mat4& Bone::getWorldMat()
{ {
if (_parent) if (needUpdateWorldMat())
{ {
updateLocalMat(); if (_parent)
_world = _parent->getWorldMat() * _local; {
updateLocalMat();
_world = _parent->getWorldMat() * _local;
}
else
_world = _local;
} }
return _world; return _world;
} }
@ -165,6 +183,7 @@ Bone::Bone(const std::string& id)
: _name(id) : _name(id)
, _parent(nullptr) , _parent(nullptr)
, _dirtyFlag(0) , _dirtyFlag(0)
, _worldDirty(true)
{ {
} }

View File

@ -50,6 +50,8 @@ public:
*/ */
const Mat4& getInverseBindPose(); const Mat4& getInverseBindPose();
bool needUpdateWorldMat() const;
//update own world matrix and children's //update own world matrix and children's
void updateWorldMat(); void updateWorldMat();
@ -138,6 +140,7 @@ protected:
Vector<Bone*> _children; Vector<Bone*> _children;
int _dirtyFlag; int _dirtyFlag;
bool _worldDirty;
Mat4 _world; Mat4 _world;
Mat4 _local; Mat4 _local;
Vec3 _localTranslate; Vec3 _localTranslate;

View File

@ -141,10 +141,25 @@ bool Sprite3D::loadFromC3x(const std::string& path)
{ {
//load from .c3b or .c3t //load from .c3b or .c3t
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(path); std::string fullPath = FileUtils::getInstance()->fullPathForFilename(path);
if (!Bundle3D::getInstance()->load(fullPath)) auto bundle = Bundle3D::getInstance();
if (!bundle->load(fullPath))
return false; return false;
//Bundle3D::getInstance()->loadMeshData(<#const std::string &id#>, <#cocos2d::Bundle3D::MeshData *meshdata#>) Bundle3D::MeshData meshdata;
bool ret = bundle->loadMeshData("", &meshdata);
if (!ret)
{
return false;
}
_mesh = Mesh::create(meshdata.vertex, meshdata.vertexSizeInFloat, meshdata.indices, meshdata.numIndex, meshdata.attribs, meshdata.attribCount);
_mesh->retain();
Bundle3D::SkinData skindata;
ret = bundle->loadSkinData("", &skindata);
Bundle3D::MaterialData materialdata;
ret = bundle->loadMaterialData("", &materialdata);
return true; return true;
} }