This commit is contained in:
yangxiao 2014-06-16 16:45:43 +08:00
commit bc31d6b082
7 changed files with 12120 additions and 27049 deletions

View File

@ -130,56 +130,16 @@ bool Bundle3D::load(const std::string& path)
bool Bundle3D::loadMeshData(const std::string& id, MeshData* meshdata)
{
meshdata->resetData();
// meshdata->vertexSizeInFloat = 13 * 4;
// meshdata->vertex.resize(meshdata->vertexSizeInFloat);
// float vert[] = {0.f,50.f,0.f, 0.f,0.f, 0.f,0.f,0.f,0.f, 1.f,0.f,0.f,0.f,
// 0.f,0.f,50.f, 1.f,1.f, 0.f,0.f,0.f,0.f, 1.f,0.f,0.f,0.f,
// 50.f,0.f,0.f, 1.f,1.f, 0.f,0.f,0.f,0.f, 1.f,0.f,0.f,0.f,
// -50.f,0.f,0.f, 1.f,1.f, 0.f,0.f,0.f,0.f, 1.f,0.f,0.f,0.f};
const rapidjson::Value& mash_data_val_array = document["mesh_data"];
assert(mash_data_val_array.IsArray());
const rapidjson::Value& mash_data_val = mash_data_val_array[(rapidjson::SizeType)0];
assert(mash_data_val.IsObject());
assert(document.HasMember("mesh_data"));
const rapidjson::Value& mash_data_array = document["mesh_data"];
assert(mash_data_array.IsArray());
const rapidjson::Value& mash_data_val = mash_data_array[(rapidjson::SizeType)0];
assert(mash_data_val.HasMember("body"));
const rapidjson::Value& mesh_data_body_array = mash_data_val["body"];
// memcpy(&meshdata->vertex[0], vert, meshdata->vertexSizeInFloat * sizeof(float));
//
// meshdata->numIndex = 4 * 3;
// //meshdata->numIndex = 3;
// meshdata->indices.resize(meshdata->numIndex);
// unsigned short index[] = {0,1,2, 0,3,1, 0,2,3, 3,2,1};
// //unsigned short index[] = {0,3,2};
// //unsigned short index[] = {0,1,2};
// memcpy(&meshdata->indices[0], index, meshdata->numIndex * sizeof(unsigned short));
//
// meshdata->attribCount = 4;
// meshdata->attribs.resize(meshdata->attribCount);
// meshdata->attribs[0].attribSizeBytes = 3 * sizeof(float);
// meshdata->attribs[0].size = 3;
// meshdata->attribs[0].type = GL_FLOAT;
// meshdata->attribs[0].vertexAttrib = GLProgram::VERTEX_ATTRIB_POSITION;
//
// meshdata->attribs[1].attribSizeBytes = 2 * sizeof(float);
// meshdata->attribs[1].size = 2;
// meshdata->attribs[1].type = GL_FLOAT;
// meshdata->attribs[1].vertexAttrib = GLProgram::VERTEX_ATTRIB_TEX_COORD;
//
// meshdata->attribs[2].attribSizeBytes = 4 * sizeof(float);
// meshdata->attribs[2].size = 4;
// meshdata->attribs[2].type = GL_FLOAT;
// meshdata->attribs[2].vertexAttrib = GLProgram::VERTEX_ATTRIB_BLEND_INDEX;
//
// meshdata->attribs[3].attribSizeBytes = 4 * sizeof(float);
// meshdata->attribs[3].size = 4;
// meshdata->attribs[3].type = GL_FLOAT;
// meshdata->attribs[3].vertexAttrib = GLProgram::VERTEX_ATTRIB_BLEND_WEIGHT;
assert(mesh_data_body_array.IsArray());
const rapidjson::Value& mesh_data_body_val = mesh_data_body_array[(rapidjson::SizeType)0];
@ -229,23 +189,13 @@ bool Bundle3D::loadSkinData(const std::string& id, SkinData* skindata)
{
skindata->resetData();
assert(document.HasMember("skin_data"));
if (!document.HasMember("skin_data")) return false;
const rapidjson::Value& skin_data_array = document["skin_data"];
assert(skin_data_array.IsArray());
const rapidjson::Value& skin_data_array_val_0 = skin_data_array[(rapidjson::SizeType)0];
const rapidjson::Value& skin_data_bind_shape = skin_data_array_val_0["bind_shape"];
assert(skin_data_bind_shape.Size() == 16);
for (rapidjson::SizeType i = 0; i < skin_data_bind_shape.Size(); i++)
{
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();
assert(skin_data_array.IsArray());
const rapidjson::Value& skin_data_array_val_0 = skin_data_array[(rapidjson::SizeType)0];
const rapidjson::Value& skin_data_bones = skin_data_array_val_0["bones"];
for (rapidjson::SizeType i = 0; i < skin_data_bones.Size(); i++)
@ -253,35 +203,19 @@ bool Bundle3D::loadSkinData(const std::string& id, SkinData* skindata)
const rapidjson::Value& skin_data_bone = skin_data_bones[i];
std::string name = skin_data_bone["node"].GetString();
skindata->boneNames.push_back(name);
const rapidjson::Value& bind_pos = skin_data_bone["bind_pos"];
const rapidjson::Value& bind_pos = skin_data_bone["bind_shape"];
Mat4 mat_bind_pos;
for (rapidjson::SizeType j = 0; j < bind_pos.Size(); j++)
{
mat_bind_pos.m[j] = bind_pos[j].GetDouble();
}
skindata->inverseBindPoseMatrices.push_back(mat_bind_pos.getInversed());
skindata->inverseBindPoseMatrices.push_back(mat_bind_pos);
}
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];
skindata->rootBoneIndex = skindata->getBoneNameIndex(bone_val_0["id"].GetString());
//skindata->inverseBindPoseMatrices.resize(skindata->boneNames.size(), Mat4::IDENTITY);
getChildMap(skindata->boneChild, skindata, bone_val_0);
std::map<std::string, std::vector<std::string> > map_child;
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;
}
@ -291,6 +225,7 @@ bool Bundle3D::loadSkinData(const std::string& id, SkinData* skindata)
*/
bool Bundle3D::loadMaterialData(const std::string& id, MaterialData* materialdata)
{
assert(document.HasMember("material_data"));
if (!document.HasMember("material_data"))
return false;
@ -319,11 +254,11 @@ bool Bundle3D::loadAnimationData(const std::string& id, Animation3DData* animati
assert(document.HasMember("animation_3d_data"));
if (!document.HasMember("animation_3d_data")) return false;
animationdata->_totalTime = 3;
const rapidjson::Value& animation_data_array_val = document["animation_3d_data"];
const rapidjson::Value& animation_data_array_val_0 = animation_data_array_val[(rapidjson::SizeType)0];
animationdata->_totalTime = animation_data_array_val_0["length"].GetDouble();
const rapidjson::Value& bones = animation_data_array_val_0["bones"];
rapidjson::SizeType bone_size = bones.Size();
for (rapidjson::SizeType i = 0; i < bone_size/*bones.Size()*/; i++)
@ -342,7 +277,7 @@ bool Bundle3D::loadAnimationData(const std::string& id, Animation3DData* animati
if ( bone_keyframe.HasMember("translation"))
{
const rapidjson::Value& bone_keyframe_translation = bone_keyframe["translation"];
float keytime = bone_keyframe["keytime"].GetDouble() / 1200.f;
float keytime = bone_keyframe["keytime"].GetDouble();
Vec3 val = Vec3(bone_keyframe_translation[(rapidjson::SizeType)0].GetDouble(), bone_keyframe_translation[1].GetDouble(), bone_keyframe_translation[2].GetDouble());
animationdata->_translationKeys[bone_name].push_back(Animation3DData::Vec3Key(keytime,val));
}
@ -350,7 +285,7 @@ bool Bundle3D::loadAnimationData(const std::string& id, Animation3DData* animati
if ( bone_keyframe.HasMember("rotation"))
{
const rapidjson::Value& bone_keyframe_rotation = bone_keyframe["rotation"];
float keytime = bone_keyframe["keytime"].GetDouble() / 1200.f;
float keytime = bone_keyframe["keytime"].GetDouble();
Quaternion val = Quaternion(bone_keyframe_rotation[(rapidjson::SizeType)0].GetDouble(),bone_keyframe_rotation[1].GetDouble(),bone_keyframe_rotation[2].GetDouble(),bone_keyframe_rotation[3].GetDouble());
animationdata->_rotationKeys[bone_name].push_back(Animation3DData::QuatKey(keytime,val));
}
@ -358,7 +293,7 @@ bool Bundle3D::loadAnimationData(const std::string& id, Animation3DData* animati
if ( bone_keyframe.HasMember("scale"))
{
const rapidjson::Value& bone_keyframe_scale = bone_keyframe["scale"];
float keytime = bone_keyframe["keytime"].GetDouble() / 1200.f;
float keytime = bone_keyframe["keytime"].GetDouble();
Vec3 val = Vec3(bone_keyframe_scale[(rapidjson::SizeType)0].GetDouble(), bone_keyframe_scale[1].GetDouble(), bone_keyframe_scale[2].GetDouble());
animationdata->_scaleKeys[bone_name].push_back(Animation3DData::Vec3Key(keytime,val));
}
@ -366,56 +301,6 @@ bool Bundle3D::loadAnimationData(const std::string& id, Animation3DData* animati
}
}
animationdata->_totalTime = 3;
// animationdata->_translationKeys[boneName].push_back(Animation3DData::Vec3Key(keytime1[0], Vec3(0.0f, 0.0f, 0.0f)));
// animationdata->_translationKeys[boneName].push_back(Animation3DData::Vec3Key(keytime1[1], Vec3(0.0f, 20.0f, 0.0f)));
// animationdata->_translationKeys[boneName].push_back(Animation3DData::Vec3Key(keytime1[2], Vec3(20.0f, 0.0f, 0.0f)));
// animationdata->_translationKeys[boneName].push_back(Animation3DData::Vec3Key(keytime1[3], Vec3(0.0f, 0.0f, 20.0f)));
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;
}

View File

@ -65,7 +65,7 @@ void Bone::updateWorldMat()
const Mat4& Bone::getWorldMat()
{
//if (_worldDirty)
if (_worldDirty)
{
updateLocalMat();
if (_parent)
@ -123,7 +123,6 @@ void Bone::setAnimationValue(float* trans, float* rot, float* scale, float weigh
state.localScale.set(scale);
state.weight = weight;
_blendStates.clear();
_blendStates.push_back(state);
_localDirty = true;
}
@ -214,16 +213,11 @@ Bone::~Bone()
void Bone::updateLocalMat()
{
if (_blendStates.size() == 0)
return;
if (!_localDirty)
return;
Vec3 translate(0.f, 0.f, 0.f), scale(0.f, 0.f, 0.f);
Quaternion quat(0.f, 0.f, 0.f, 0.f);
if (_blendStates.size())
{
Vec3 translate(Vec3::ZERO), scale(Vec3::ONE);
Quaternion quat(Quaternion::identity());
float total = 0.f;
for (auto it: _blendStates) {
total += it.weight;
@ -262,30 +256,9 @@ void Bone::updateLocalMat()
}
}
bool hasTrans = !translate.isZero();
bool hasRot = !quat.isZero();
bool hasScale = !scale.isZero();
if (hasTrans)
{
Mat4::createTranslation(translate, &_local);
if (hasRot)
_local.rotate(quat);
if (hasScale)
_local.scale(scale);
}
else if (hasRot)
{
Mat4::createRotation(quat, &_local);
if (hasScale)
_local.scale(scale);
}
else if (hasScale)
{
Mat4::createScale(scale, &_local);
}
else
_local.setIdentity();
Mat4::createTranslation(translate, &_local);
_local.rotate(quat);
_local.scale(scale);
_blendStates.clear();
_localDirty = false;

View File

@ -108,10 +108,10 @@ protected:
Vec3 localScale;
float weight;
BoneBlendState()
: localTranslate(0.f, 0.f, 0.f)
, localRot(0.f, 0.f, 0.f, 1.0f)
, localScale(1.f, 1.f, 1.f)
, weight(0.f)
: localTranslate(Vec3::ZERO)
, localRot(Quaternion::identity())
, localScale(Vec3::ONE)
, weight(1.f)
{
}

View File

@ -541,7 +541,7 @@ std::string Sprite3DWithSkinTest::subtitle() const
void Sprite3DWithSkinTest::addNewSpriteWithCoords(Vec2 p)
{
auto sprite = Sprite3D::create("Sprite3DTest/girl2.c3t");
auto sprite = Sprite3D::create("Sprite3DTest/girl.c3t");
//auto sprite = Sprite3D::create("Sprite3DTest/cube_anim.c3t");
//sprite->setScale(2.f);
sprite->setTexture("Sprite3DTest/girl.png");
@ -552,7 +552,7 @@ void Sprite3DWithSkinTest::addNewSpriteWithCoords(Vec2 p)
//sprite->setRotationSkewY(90);
sprite->setPosition( Vec2( p.x, p.y) );
auto animation = Animation3D::getOrCreate("Sprite3DTest/girl2.c3t");
auto animation = Animation3D::getOrCreate("Sprite3DTest/girl.c3t");
auto animate = Animate3D::create(animation);
if(std::rand() %3 == 0)
{

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -7516,11 +7516,6 @@
"id": "Bip001 Head",
"bind_shape": [ 0.985542, 0.167319, -0.026683, 0.000000, -0.157796, 0.963757, 0.215111, 0.000000, 0.061709, -0.207790, 0.976225, 0.000000, 5.469170, 0.000002, -0.000001, 1.000000],
"children": [
{
"version": 1.200000,
"id": "Bip001 HeadNub",
"bind_shape": [ 1.000000, -0.000000, -0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, -0.000000, 1.000000, 0.000000, 22.780975, 0.000000, -0.000000, 1.000000]
},
{
"version": 1.200000,
"id": "Bip001 Ponytail1",
@ -7573,14 +7568,8 @@
{
"version": 1.200000,
"id": "Bip001 L Toe0",
"bind_shape": [-0.000000, 1.000000, 0.000000, 0.000000, -1.000000, -0.000000, -0.000000, 0.000000, -0.000000, -0.000000, 1.000000, 0.000000, 17.426956, 10.792505, 0.000005, 1.000000],
"children": [
{
"version": 1.200000,
"id": "Bip001 L Toe0Nub",
"bind_shape": [ 1.000000, -0.000000, -0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, -0.000000, 0.000000, -1.000000, 0.000000, 11.620661, 0.000000, 0.000000, 1.000000]
}
]
"bind_shape": [-0.000000, 1.000000, 0.000000, 0.000000, -1.000000, -0.000000, -0.000000, 0.000000, -0.000000, -0.000000, 1.000000, 0.000000, 17.426956, 10.792505, 0.000005, 1.000000]
}
]
}
@ -7606,14 +7595,8 @@
{
"version": 1.200000,
"id": "Bip001 R Toe0",
"bind_shape": [-0.000000, 1.000000, -0.000000, 0.000000, -1.000000, -0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 17.426960, 10.792509, -0.000001, 1.000000],
"children": [
{
"version": 1.200000,
"id": "Bip001 R Toe0Nub",
"bind_shape": [ 1.000000, -0.000000, -0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, -0.000000, 1.000000, 0.000000, 11.620655, -0.000001, 0.000001, 1.000000]
}
]
"bind_shape": [-0.000000, 1.000000, -0.000000, 0.000000, -1.000000, -0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 17.426960, 10.792509, -0.000001, 1.000000]
}
]
}