mirror of https://github.com/axmolengine/axmol.git
load c3t animation work 90%
This commit is contained in:
parent
4ae01d148f
commit
9dd7241176
|
@ -46,13 +46,14 @@ void getChildMap(std::map<int, std::vector<int> >& map, SkinData* skinData, cons
|
||||||
std::string parent_name = val["id"].GetString();
|
std::string parent_name = val["id"].GetString();
|
||||||
int parent_name_index = skinData->getBoneNameIndex(parent_name);
|
int parent_name_index = skinData->getBoneNameIndex(parent_name);
|
||||||
|
|
||||||
const rapidjson::Value& bind_pos = val["bind_shape"];
|
// const rapidjson::Value& bind_pos = val["bind_shape"];
|
||||||
Mat4 mat_bind_pos;
|
// Mat4 mat_bind_pos;
|
||||||
for (rapidjson::SizeType j = 0; j < bind_pos.Size(); j++)
|
// for (rapidjson::SizeType j = 0; j < bind_pos.Size(); j++)
|
||||||
{
|
// {
|
||||||
mat_bind_pos.m[j] = bind_pos[j].GetDouble();
|
// mat_bind_pos.m[j] = bind_pos[j].GetDouble();
|
||||||
}
|
// }
|
||||||
skinData->inverseBindPoseMatrices.push_back(mat_bind_pos);
|
//
|
||||||
|
// skinData->inverseBindPoseMatrices[parent_name_index] = (mat_bind_pos);
|
||||||
|
|
||||||
const rapidjson::Value& children = val["children"];
|
const rapidjson::Value& children = val["children"];
|
||||||
for (rapidjson::SizeType i = 0; i < children.Size(); i++)
|
for (rapidjson::SizeType i = 0; i < children.Size(); i++)
|
||||||
|
@ -202,28 +203,45 @@ bool Bundle3D::loadSkinData(const std::string& id, SkinData* skindata)
|
||||||
skindata->bindShape.m[i] = skin_data_bind_shape[i].GetDouble();
|
skindata->bindShape.m[i] = skin_data_bind_shape[i].GetDouble();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float m[] = {-0.682038f, -0.035225f, 0.730468f, 0.000000f, 0.731315f, -0.035225f, 0.681130f, 0.000000f, 0.001738f, 0.998758f, 0.049786f, 0.000000f, -0.882000f, 78.798103f, -0.868362f, 1.000000f};
|
||||||
|
memcpy(skindata->bindShape.m, m, sizeof(m));
|
||||||
|
//skindata->bindShape.setIdentity();
|
||||||
|
|
||||||
const rapidjson::Value& skin_data_bones = skin_data_array_val_0["bones"];
|
const rapidjson::Value& skin_data_bones = skin_data_array_val_0["bones"];
|
||||||
for (rapidjson::SizeType i = 0; i < skin_data_bones.Size(); i++)
|
for (rapidjson::SizeType i = 0; i < skin_data_bones.Size(); i++)
|
||||||
{
|
{
|
||||||
const rapidjson::Value& skin_data_bone = skin_data_bones[i];
|
const rapidjson::Value& skin_data_bone = skin_data_bones[i];
|
||||||
std::string name = skin_data_bone["node"].GetString();
|
std::string name = skin_data_bone["node"].GetString();
|
||||||
skindata->boneNames.push_back(name);
|
skindata->boneNames.push_back(name);
|
||||||
/*const rapidjson::Value& bind_pos = skin_data_bone["bind_pos"];
|
const rapidjson::Value& bind_pos = skin_data_bone["bind_pos"];
|
||||||
Mat4 mat_bind_pos;
|
Mat4 mat_bind_pos;
|
||||||
for (rapidjson::SizeType j = 0; j < bind_pos.Size(); j++)
|
for (rapidjson::SizeType j = 0; j < bind_pos.Size(); j++)
|
||||||
{
|
{
|
||||||
mat_bind_pos.m[j] = bind_pos[j].GetDouble();
|
mat_bind_pos.m[j] = bind_pos[j].GetDouble();
|
||||||
}
|
}
|
||||||
skindata->inverseBindPoseMatrices.push_back(mat_bind_pos);*/
|
skindata->inverseBindPoseMatrices.push_back(mat_bind_pos.getInversed());
|
||||||
}
|
}
|
||||||
|
|
||||||
const rapidjson::Value& skin_data_array_val_1 = skin_data_array[1];
|
const rapidjson::Value& skin_data_array_val_1 = skin_data_array[1];
|
||||||
const rapidjson::Value& bone_val_0 = skin_data_array_val_1["children"][(rapidjson::SizeType)0];
|
const rapidjson::Value& bone_val_0 = skin_data_array_val_1["children"][(rapidjson::SizeType)0];
|
||||||
skindata->rootBoneIndex = skindata->getBoneNameIndex(bone_val_0["id"].GetString());
|
skindata->rootBoneIndex = skindata->getBoneNameIndex(bone_val_0["id"].GetString());
|
||||||
|
//skindata->inverseBindPoseMatrices.resize(skindata->boneNames.size(), Mat4::IDENTITY);
|
||||||
getChildMap(skindata->boneChild, skindata, bone_val_0);
|
getChildMap(skindata->boneChild, skindata, bone_val_0);
|
||||||
|
|
||||||
std::map<std::string, std::vector<std::string> > map_child;
|
std::map<std::string, std::vector<std::string> > map_child;
|
||||||
getChildMapT(map_child, skindata, bone_val_0);
|
getChildMapT(map_child, skindata, bone_val_0);
|
||||||
|
|
||||||
|
for (auto it : skindata->boneNames) {
|
||||||
|
CCLOG("bonename: %s", it.c_str());
|
||||||
|
}
|
||||||
|
CCLOG("root: %s", skindata->boneNames[skindata->rootBoneIndex].c_str());
|
||||||
|
for (auto itr : skindata->boneChild) {
|
||||||
|
CCLOG("parent: %s", skindata->boneNames[itr.first].c_str());
|
||||||
|
for (auto itr2 : itr.second) {
|
||||||
|
CCLOG("%s", skindata->boneNames[(itr2)].c_str());
|
||||||
|
}
|
||||||
|
CCLOG("////////");
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -307,6 +325,52 @@ bool Bundle3D::loadAnimationData(const std::string& id, Animation3DData* animati
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
animationdata->_totalTime = 3;
|
||||||
|
|
||||||
|
CCLOG("translation:////////////////");
|
||||||
|
//animationdata->_translationKeys.erase(animationdata->_translationKeys.begin(), animationdata->_translationKeys.end());
|
||||||
|
for (auto itr: animationdata->_translationKeys)
|
||||||
|
{
|
||||||
|
CCLOG("%s", itr.first.c_str());
|
||||||
|
auto& keys = itr.second;
|
||||||
|
|
||||||
|
if (keys.size())
|
||||||
|
{
|
||||||
|
float maxtime = keys[keys.size() - 1]._time;
|
||||||
|
for (auto it : keys) {
|
||||||
|
it._time /= maxtime;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CCLOG("rotation:////////////////");
|
||||||
|
//animationdata->_rotationKeys.erase(animationdata->_rotationKeys.begin(), animationdata->_rotationKeys.end());
|
||||||
|
for (auto itr: animationdata->_rotationKeys)
|
||||||
|
{
|
||||||
|
CCLOG("%s", itr.first.c_str());
|
||||||
|
auto& keys = itr.second;
|
||||||
|
if (keys.size())
|
||||||
|
{
|
||||||
|
float maxtime = keys[keys.size() - 1]._time;
|
||||||
|
for (auto it : keys) {
|
||||||
|
it._time /= maxtime;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CCLOG("scale:////////////////");
|
||||||
|
for (auto itr: animationdata->_scaleKeys)
|
||||||
|
{
|
||||||
|
CCLOG("%s", itr.first.c_str());
|
||||||
|
auto& keys = itr.second;
|
||||||
|
if (keys.size())
|
||||||
|
{
|
||||||
|
float maxtime = keys[keys.size() - 1]._time;
|
||||||
|
for (auto it : keys) {
|
||||||
|
it._time /= maxtime;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,8 @@ bool Bone::needUpdateWorldMat() const
|
||||||
bone = bone->_parent;
|
bone = bone->_parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
return needupdate;
|
return true;
|
||||||
|
//return needupdate;
|
||||||
}
|
}
|
||||||
|
|
||||||
//update own world matrix and children's
|
//update own world matrix and children's
|
||||||
|
@ -63,7 +64,7 @@ void Bone::updateWorldMat()
|
||||||
{
|
{
|
||||||
getWorldMat();
|
getWorldMat();
|
||||||
for (auto itor : _children) {
|
for (auto itor : _children) {
|
||||||
itor->getWorldMat();
|
itor->updateWorldMat();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,7 +75,6 @@ const Mat4& Bone::getWorldMat()
|
||||||
updateLocalMat();
|
updateLocalMat();
|
||||||
if (_parent)
|
if (_parent)
|
||||||
{
|
{
|
||||||
updateLocalMat();
|
|
||||||
_world = _parent->getWorldMat() * _local;
|
_world = _parent->getWorldMat() * _local;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -141,8 +141,10 @@ void Bone::updateJointMatrix(const Mat4& bindShape, Vec4* matrixPalette)
|
||||||
//_jointMatrixDirty = false;
|
//_jointMatrixDirty = false;
|
||||||
static Mat4 t;
|
static Mat4 t;
|
||||||
Mat4::multiply(_world, getInverseBindPose(), &t);
|
Mat4::multiply(_world, getInverseBindPose(), &t);
|
||||||
Mat4::multiply(t, bindShape, &t);
|
//Mat4::multiply(t, bindShape, &t);
|
||||||
|
//Mat4::multiply(getInverseBindPose(), _world, &t);
|
||||||
|
|
||||||
|
//t.setIdentity();
|
||||||
matrixPalette[0].set(t.m[0], t.m[4], t.m[8], t.m[12]);
|
matrixPalette[0].set(t.m[0], t.m[4], t.m[8], t.m[12]);
|
||||||
matrixPalette[1].set(t.m[1], t.m[5], t.m[9], t.m[13]);
|
matrixPalette[1].set(t.m[1], t.m[5], t.m[9], t.m[13]);
|
||||||
matrixPalette[2].set(t.m[2], t.m[6], t.m[10], t.m[14]);
|
matrixPalette[2].set(t.m[2], t.m[6], t.m[10], t.m[14]);
|
||||||
|
@ -199,6 +201,11 @@ Bone::~Bone()
|
||||||
|
|
||||||
void Bone::updateLocalMat()
|
void Bone::updateLocalMat()
|
||||||
{
|
{
|
||||||
|
Mat4::createTranslation(_localTranslate, &_local);
|
||||||
|
if (!_localRot.isZero())
|
||||||
|
_local.rotate(_localRot);
|
||||||
|
return;
|
||||||
|
|
||||||
if (_dirtyFlag & Dirty_Translate)
|
if (_dirtyFlag & Dirty_Translate)
|
||||||
{
|
{
|
||||||
Mat4::createTranslation(_localTranslate, &_local);
|
Mat4::createTranslation(_localTranslate, &_local);
|
||||||
|
|
|
@ -297,7 +297,7 @@ void Sprite3D::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
|
||||||
_mesh->getIndexCount(),
|
_mesh->getIndexCount(),
|
||||||
transform);
|
transform);
|
||||||
|
|
||||||
_meshCommand.setCullFaceEnabled(true);
|
//_meshCommand.setCullFaceEnabled(true);
|
||||||
_meshCommand.setDepthTestEnabled(true);
|
_meshCommand.setDepthTestEnabled(true);
|
||||||
if (_skin)
|
if (_skin)
|
||||||
{
|
{
|
||||||
|
|
|
@ -44,22 +44,38 @@ void skinPosition(float blendWeight, int matrixIndex)
|
||||||
vec4 getPosition()
|
vec4 getPosition()
|
||||||
{
|
{
|
||||||
_skinnedPosition = vec4(0.0);
|
_skinnedPosition = vec4(0.0);
|
||||||
|
vec4 matrixPalette1 = vec4(0.0);
|
||||||
|
vec4 matrixPalette2 = vec4(0.0);
|
||||||
|
vec4 matrixPalette3 = vec4(0.0);
|
||||||
|
|
||||||
float blendWeight = a_blendWeight[0];
|
float blendWeight = a_blendWeight[0];
|
||||||
int matrixIndex = int (a_blendIndex[0]) * 3;
|
int matrixIndex = int (a_blendIndex[0]) * 3;
|
||||||
skinPosition(blendWeight, matrixIndex);
|
matrixPalette1 += u_matrixPalette[matrixIndex] * blendWeight;
|
||||||
|
matrixPalette2 += u_matrixPalette[matrixIndex + 1] * blendWeight;
|
||||||
|
matrixPalette3 += u_matrixPalette[matrixIndex + 2] * blendWeight;
|
||||||
|
|
||||||
blendWeight = a_blendWeight[1];
|
blendWeight = a_blendWeight[1];
|
||||||
matrixIndex = int(a_blendIndex[1]) * 3;
|
matrixIndex = int(a_blendIndex[1]) * 3;
|
||||||
skinPosition(blendWeight, matrixIndex);
|
matrixPalette1 += u_matrixPalette[matrixIndex] * blendWeight;
|
||||||
|
matrixPalette2 += u_matrixPalette[matrixIndex + 1] * blendWeight;
|
||||||
|
matrixPalette3 += u_matrixPalette[matrixIndex + 2] * blendWeight;
|
||||||
|
|
||||||
blendWeight = a_blendWeight[2];
|
blendWeight = a_blendWeight[2];
|
||||||
matrixIndex = int(a_blendIndex[2]) * 3;
|
matrixIndex = int(a_blendIndex[2]) * 3;
|
||||||
skinPosition(blendWeight, matrixIndex);
|
matrixPalette1 += u_matrixPalette[matrixIndex] * blendWeight;
|
||||||
|
matrixPalette2 += u_matrixPalette[matrixIndex + 1] * blendWeight;
|
||||||
|
matrixPalette3 += u_matrixPalette[matrixIndex + 2] * blendWeight;
|
||||||
|
|
||||||
blendWeight = a_blendWeight[3];
|
blendWeight = a_blendWeight[3];
|
||||||
matrixIndex = int(a_blendIndex[3]) * 3;
|
matrixIndex = int(a_blendIndex[3]) * 3;
|
||||||
skinPosition(blendWeight, matrixIndex);
|
matrixPalette1 += u_matrixPalette[matrixIndex] * blendWeight;
|
||||||
|
matrixPalette2 += u_matrixPalette[matrixIndex + 1] * blendWeight;
|
||||||
|
matrixPalette3 += u_matrixPalette[matrixIndex + 2] * blendWeight;
|
||||||
|
|
||||||
|
_skinnedPosition.x = dot(a_position, matrixPalette1);
|
||||||
|
_skinnedPosition.y = dot(a_position, matrixPalette2);
|
||||||
|
_skinnedPosition.z = dot(a_position, matrixPalette3);
|
||||||
|
_skinnedPosition.w = a_position.w;
|
||||||
|
|
||||||
return _skinnedPosition;
|
return _skinnedPosition;
|
||||||
}
|
}
|
||||||
|
|
|
@ -543,12 +543,13 @@ void Sprite3DWithSkinTest::addNewSpriteWithCoords(Vec2 p)
|
||||||
{
|
{
|
||||||
auto sprite = Sprite3D::create("Sprite3DTest/girl2.c3t");
|
auto sprite = Sprite3D::create("Sprite3DTest/girl2.c3t");
|
||||||
//auto sprite = Sprite3D::create("Sprite3DTest/cube_anim.c3t");
|
//auto sprite = Sprite3D::create("Sprite3DTest/cube_anim.c3t");
|
||||||
sprite->setScale(1.f);
|
//sprite->setScale(2.f);
|
||||||
sprite->setTexture("Sprite3DTest/girl.png");
|
sprite->setTexture("Sprite3DTest/girl.png");
|
||||||
addChild(sprite);
|
addChild(sprite);
|
||||||
|
|
||||||
//sprite->setPosition3D(Vec3(p.x, p.y, -10.f));
|
//sprite->setPosition3D(Vec3(p.x, p.y, -10.f));
|
||||||
sprite->setRotation3D(Vec3(-90,0,0));
|
//sprite->setRotation3D(Vec3(-90,0,0));
|
||||||
|
//sprite->setRotationSkewY(90);
|
||||||
sprite->setPosition( Vec2( p.x, p.y) );
|
sprite->setPosition( Vec2( p.x, p.y) );
|
||||||
|
|
||||||
auto animation = Animation3D::getOrCreate("Sprite3DTest/girl2.c3t");
|
auto animation = Animation3D::getOrCreate("Sprite3DTest/girl2.c3t");
|
||||||
|
|
Loading…
Reference in New Issue