create from data

This commit is contained in:
yangxiao 2014-08-15 17:41:04 +08:00
parent 6f0fc48e8e
commit d09695b118
6 changed files with 64 additions and 2 deletions

View File

@ -37,6 +37,7 @@ static int PALETTE_ROWS = 3;
MeshSkin::MeshSkin()
: _rootBone(nullptr)
, _matrixPalette(nullptr)
, _skeleton(nullptr)
{
}
@ -85,6 +86,23 @@ MeshSkin* MeshSkin::create(Skeleton3D* skeleton, const std::string& filename, co
return nullptr;
}
MeshSkin* MeshSkin::create(Skeleton3D* skeleton, const std::vector<std::string>& boneNames, const std::vector<Mat4>& invBindPose)
{
auto skin = new MeshSkin();
skin->_skeleton = skeleton;
skeleton->retain();
CCASSERT(boneNames.size() == invBindPose.size(), "bone names' num should equals to invBindPose's num");
for (const auto& it : boneNames) {
auto bone = skeleton->getBoneByName(it);
skin->addSkinBone(bone);
}
skin->_invBindPoses = invBindPose;
skin->autorelease();
return skin;
}
bool MeshSkin::initFromSkinData(const SkinData& skindata)
{
ssize_t i = 0;

View File

@ -52,6 +52,8 @@ public:
/**create a new meshskin if do not want to share meshskin*/
static MeshSkin* create(Skeleton3D* skeleton, const std::string& filename, const std::string& name);
static MeshSkin* create(Skeleton3D* skeleton, const std::vector<std::string>& boneNames, const std::vector<Mat4>& invBindPose);
/**get total bone count, skin bone + node bone*/
ssize_t getBoneCount() const;

View File

@ -294,6 +294,18 @@ Skeleton3D* Skeleton3D::create(const std::string& filename, const std::string& n
return nullptr;
}
Skeleton3D* Skeleton3D::create(const std::vector<NodeData*>& skeletondata)
{
auto skeleton = new Skeleton3D();
for (const auto& it : skeletondata) {
auto bone = createBone3D(*it);
skeleton->_rootBones.pushBack(bone);
bone->release();
}
skeleton->autorelease();
return skeleton;
}
bool Skeleton3D::initFromSkeletonData(const Skeleton3DData& skeletondata)
{
ssize_t i = 0;
@ -361,7 +373,7 @@ ssize_t Skeleton3D::getRootCount() const
Bone3D* Skeleton3D::getRootBone(int index) const
{
return _rootBones[index];
return _rootBones.at(index);
}
int Skeleton3D::getBoneIndex(Bone3D* bone) const
@ -386,6 +398,7 @@ void Skeleton3D::removeAllBones()
{
_bones.clear();
CC_SAFE_RELEASE(_rootBone);
_rootBones.clear();
}
void Skeleton3D::addBone(Bone3D* bone)
@ -393,6 +406,17 @@ void Skeleton3D::addBone(Bone3D* bone)
_bones.pushBack(bone);
}
Bone3D* Skeleton3D::createBone3D(const NodeData& nodedata)
{
auto bone = Bone3D::create(nodedata.id);
for (const auto& it : nodedata.children) {
auto child = createBone3D(*it);
bone->addChildBone(child);
child->release();
}
return bone;
}
////////////////////////////////////////////////////////////////////////
Skeleton3DDataCache* Skeleton3DDataCache::_cacheInstance = nullptr;

View File

@ -190,6 +190,8 @@ public:
/**create a new meshskin if do not want to share Skeleton3D*/
static Skeleton3D* create(const std::string& filename, const std::string& name);
static Skeleton3D* create(const std::vector<NodeData*>& skeletondata);
/**get total bone count*/
ssize_t getBoneCount() const;
@ -224,12 +226,15 @@ CC_CONSTRUCTOR_ACCESS:
/**add bone*/
void addBone(Bone3D* bone);
/** create Bone3D from NodeData */
static Bone3D* createBone3D(const NodeData& nodedata);
protected:
Vector<Bone3D*> _bones; // bones
Bone3D* _rootBone;
std::vector<Bone3D*> _rootBones;
Vector<Bone3D*> _rootBones;
};
/**

View File

@ -68,6 +68,17 @@ SubMeshState* SubMeshState::create()
return state;
}
SubMeshState* SubMeshState::create(const ModelNodeData& modelNodeData)
{
auto state = new SubMeshState();
state->autorelease();
state->_name = modelNodeData.id;
//not finished
return state;
}
void SubMeshState::setTexture(Texture2D* tex)
{
if (tex != _texture)

View File

@ -49,6 +49,8 @@ public:
/**create submesh from primitivetype indexformat and indices*/
static SubMeshState* create();
static SubMeshState* create(const ModelNodeData& modelNodeData);
/**texture getter and setter*/
void setTexture(Texture2D* tex);