mirror of https://github.com/axmolengine/axmol.git
Merge branch 'v3' of https://github.com/super626/cocos2d-x into merge-bundle
This commit is contained in:
commit
24bb827ef4
|
@ -90,12 +90,12 @@ Animate3D* Animate3D::reverse() const
|
||||||
void Animate3D::startWithTarget(Node *target)
|
void Animate3D::startWithTarget(Node *target)
|
||||||
{
|
{
|
||||||
Sprite3D* sprite = dynamic_cast<Sprite3D*>(target);
|
Sprite3D* sprite = dynamic_cast<Sprite3D*>(target);
|
||||||
CCASSERT(sprite && sprite->getSkin() && _animation, "Animate3D apply to Sprite3D only");
|
CCASSERT(sprite && sprite->getSkeleton() && _animation, "Animate3D apply to Sprite3D only");
|
||||||
|
|
||||||
ActionInterval::startWithTarget(target);
|
ActionInterval::startWithTarget(target);
|
||||||
|
|
||||||
_boneCurves.clear();
|
_boneCurves.clear();
|
||||||
auto skin = sprite->getSkin();
|
auto skin = sprite->getSkeleton();
|
||||||
for (unsigned int i = 0; i < skin->getBoneCount(); i++) {
|
for (unsigned int i = 0; i < skin->getBoneCount(); i++) {
|
||||||
auto bone = skin->getBoneByIndex(i);
|
auto bone = skin->getBoneByIndex(i);
|
||||||
auto curve = _animation->getBoneCurveByName(bone->getName());
|
auto curve = _animation->getBoneCurveByName(bone->getName());
|
||||||
|
|
|
@ -75,6 +75,7 @@ static const char* BONES = "bones";
|
||||||
static const char* MATERIALS = "materials";
|
static const char* MATERIALS = "materials";
|
||||||
static const char* ANIMATIONS = "animations";
|
static const char* ANIMATIONS = "animations";
|
||||||
static const char* TRANSFORM = "transform";
|
static const char* TRANSFORM = "transform";
|
||||||
|
static const char* OLDTRANSFORM = "tansform";
|
||||||
|
|
||||||
static const char* MATERIALDATA_MATERIAL = "material";
|
static const char* MATERIALDATA_MATERIAL = "material";
|
||||||
static const char* MATERIALDATA_MATERIALS = "materials";
|
static const char* MATERIALDATA_MATERIALS = "materials";
|
||||||
|
@ -100,7 +101,7 @@ void getChildMap(std::map<int, std::vector<int> >& map, SkinData* skinData, cons
|
||||||
|
|
||||||
// get transform matrix
|
// get transform matrix
|
||||||
Mat4 transform;
|
Mat4 transform;
|
||||||
const rapidjson::Value& parent_tranform = val[TRANSFORM];
|
const rapidjson::Value& parent_tranform = val[OLDTRANSFORM];
|
||||||
for (rapidjson::SizeType j = 0; j < parent_tranform.Size(); j++)
|
for (rapidjson::SizeType j = 0; j < parent_tranform.Size(); j++)
|
||||||
{
|
{
|
||||||
transform.m[j] = parent_tranform[j].GetDouble();
|
transform.m[j] = parent_tranform[j].GetDouble();
|
||||||
|
@ -371,7 +372,7 @@ bool Bundle3D::loadNodes(NodeDatas& nodedatas)
|
||||||
if (_version == "1.2" || _version == "0.2")
|
if (_version == "1.2" || _version == "0.2")
|
||||||
{
|
{
|
||||||
SkinData skinData;
|
SkinData skinData;
|
||||||
loadSkinDataJson(&skinData);
|
loadSkinData("", &skinData);
|
||||||
auto nodeDatas = new NodeData*[skinData.skinBoneNames.size() + skinData.nodeBoneNames.size()];
|
auto nodeDatas = new NodeData*[skinData.skinBoneNames.size() + skinData.nodeBoneNames.size()];
|
||||||
int index = 0;
|
int index = 0;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
|
@ -206,7 +206,9 @@ Mesh* Mesh::create(const MeshData& meshdata)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < (int)mesh->getSubMeshCount(); i++) {
|
for (int i = 0; i < (int)mesh->getSubMeshCount(); i++) {
|
||||||
auto submesh = mesh->getSubMesh(i);
|
auto submesh = mesh->getSubMesh(i);
|
||||||
submesh->_id = meshdata.subMeshIds[i];
|
if (meshdata.subMeshIds.size())
|
||||||
|
submesh->_id = meshdata.subMeshIds[i];
|
||||||
|
submesh->_mesh = mesh;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mesh->autorelease();
|
mesh->autorelease();
|
||||||
|
|
|
@ -220,8 +220,8 @@ ssize_t MeshSkin::getMatrixPaletteSize() const
|
||||||
//refresh bone world matrix
|
//refresh bone world matrix
|
||||||
void MeshSkin::updateBoneMatrix()
|
void MeshSkin::updateBoneMatrix()
|
||||||
{
|
{
|
||||||
_rootBone->setWorldMatDirty(true);
|
// _rootBone->setWorldMatDirty(true);
|
||||||
_rootBone->updateWorldMat();
|
// _rootBone->updateWorldMat();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MeshSkin::removeAllBones()
|
void MeshSkin::removeAllBones()
|
||||||
|
|
|
@ -298,14 +298,22 @@ Skeleton3D* Skeleton3D::create(const std::vector<NodeData*>& skeletondata)
|
||||||
{
|
{
|
||||||
auto skeleton = new Skeleton3D();
|
auto skeleton = new Skeleton3D();
|
||||||
for (const auto& it : skeletondata) {
|
for (const auto& it : skeletondata) {
|
||||||
auto bone = createBone3D(*it);
|
auto bone = skeleton->createBone3D(*it);
|
||||||
skeleton->_rootBones.pushBack(bone);
|
skeleton->_rootBones.pushBack(bone);
|
||||||
bone->release();
|
skeleton->printBone(bone);
|
||||||
}
|
}
|
||||||
skeleton->autorelease();
|
skeleton->autorelease();
|
||||||
return skeleton;
|
return skeleton;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Skeleton3D::printBone(Bone3D* bone)
|
||||||
|
{
|
||||||
|
CCLOG("%s", bone->getName().c_str());
|
||||||
|
for (auto it : bone->_children) {
|
||||||
|
printBone(it);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool Skeleton3D::initFromSkeletonData(const Skeleton3DData& skeletondata)
|
bool Skeleton3D::initFromSkeletonData(const Skeleton3DData& skeletondata)
|
||||||
{
|
{
|
||||||
ssize_t i = 0;
|
ssize_t i = 0;
|
||||||
|
@ -390,8 +398,12 @@ int Skeleton3D::getBoneIndex(Bone3D* bone) const
|
||||||
//refresh bone world matrix
|
//refresh bone world matrix
|
||||||
void Skeleton3D::updateBoneMatrix()
|
void Skeleton3D::updateBoneMatrix()
|
||||||
{
|
{
|
||||||
_rootBone->setWorldMatDirty(true);
|
//_rootBone->setWorldMatDirty(true);
|
||||||
_rootBone->updateWorldMat();
|
//_rootBone->updateWorldMat();
|
||||||
|
for (const auto& it : _rootBones) {
|
||||||
|
it->setWorldMatDirty(true);
|
||||||
|
it->updateWorldMat();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Skeleton3D::removeAllBones()
|
void Skeleton3D::removeAllBones()
|
||||||
|
@ -412,8 +424,10 @@ Bone3D* Skeleton3D::createBone3D(const NodeData& nodedata)
|
||||||
for (const auto& it : nodedata.children) {
|
for (const auto& it : nodedata.children) {
|
||||||
auto child = createBone3D(*it);
|
auto child = createBone3D(*it);
|
||||||
bone->addChildBone(child);
|
bone->addChildBone(child);
|
||||||
|
child->_parent = bone;
|
||||||
child->release();
|
child->release();
|
||||||
}
|
}
|
||||||
|
_bones.pushBack(bone);
|
||||||
return bone;
|
return bone;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -227,7 +227,9 @@ CC_CONSTRUCTOR_ACCESS:
|
||||||
void addBone(Bone3D* bone);
|
void addBone(Bone3D* bone);
|
||||||
|
|
||||||
/** create Bone3D from NodeData */
|
/** create Bone3D from NodeData */
|
||||||
static Bone3D* createBone3D(const NodeData& nodedata);
|
Bone3D* createBone3D(const NodeData& nodedata);
|
||||||
|
|
||||||
|
void printBone(Bone3D* bone);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
|
|
@ -291,34 +291,46 @@ bool Sprite3D::initWithFile(const std::string &path)
|
||||||
|
|
||||||
void Sprite3D::genGLProgramState()
|
void Sprite3D::genGLProgramState()
|
||||||
{
|
{
|
||||||
auto programstate = GLProgramState::getOrCreateWithGLProgram(getDefaultGLProgram(_mesh->hasVertexAttrib(GLProgram::VERTEX_ATTRIB_TEX_COORD)));
|
if (_meshes.size() == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
//all the mesh should have the same attributes, FIX ME
|
||||||
|
auto mesh = _meshes.at(0);
|
||||||
|
|
||||||
|
auto programstate = GLProgramState::getOrCreateWithGLProgram(getDefaultGLProgram(mesh->hasVertexAttrib(GLProgram::VERTEX_ATTRIB_TEX_COORD)));
|
||||||
long offset = 0;
|
long offset = 0;
|
||||||
auto attributeCount = _mesh->getMeshVertexAttribCount();
|
auto attributeCount = mesh->getMeshVertexAttribCount();
|
||||||
for (auto k = 0; k < attributeCount; k++) {
|
for (auto k = 0; k < attributeCount; k++) {
|
||||||
auto meshattribute = _mesh->getMeshVertexAttribute(k);
|
auto meshattribute = mesh->getMeshVertexAttribute(k);
|
||||||
programstate->setVertexAttribPointer(s_attributeNames[meshattribute.vertexAttrib],
|
programstate->setVertexAttribPointer(s_attributeNames[meshattribute.vertexAttrib],
|
||||||
meshattribute.size,
|
meshattribute.size,
|
||||||
meshattribute.type,
|
meshattribute.type,
|
||||||
GL_FALSE,
|
GL_FALSE,
|
||||||
_mesh->getVertexSizeInBytes(),
|
mesh->getVertexSizeInBytes(),
|
||||||
(GLvoid*)offset);
|
(GLvoid*)offset);
|
||||||
offset += meshattribute.attribSizeBytes;
|
offset += meshattribute.attribSizeBytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
setGLProgramState(programstate);
|
setGLProgramState(programstate);
|
||||||
auto count = _mesh->getSubMeshCount();
|
auto count = mesh->getSubMeshCount();
|
||||||
_meshCommands.resize(count);
|
_meshCommands.resize(count);
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
auto tex = _subMeshStates.at(i)->getTexture();
|
auto tex = _subMeshStates.at(i)->getTexture();
|
||||||
GLuint texID = tex ? tex->getName() : 0;
|
GLuint texID = tex ? tex->getName() : 0;
|
||||||
_meshCommands[i].genMaterialID(texID, programstate, _mesh, _blend);
|
_meshCommands[i].genMaterialID(texID, programstate, _meshes.at(i), _blend);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GLProgram* Sprite3D::getDefaultGLProgram(bool textured)
|
GLProgram* Sprite3D::getDefaultGLProgram(bool textured)
|
||||||
{
|
{
|
||||||
bool hasSkin = _skin && _mesh->hasVertexAttrib(GLProgram::VERTEX_ATTRIB_BLEND_INDEX)
|
if (_meshes.size() == 0)
|
||||||
&& _mesh->hasVertexAttrib(GLProgram::VERTEX_ATTRIB_BLEND_WEIGHT);
|
return nullptr;
|
||||||
|
|
||||||
|
//all the mesh should have the same attributes, FIX ME
|
||||||
|
auto mesh = _meshes.at(0);
|
||||||
|
|
||||||
|
bool hasSkin = mesh->hasVertexAttrib(GLProgram::VERTEX_ATTRIB_BLEND_INDEX)
|
||||||
|
&& mesh->hasVertexAttrib(GLProgram::VERTEX_ATTRIB_BLEND_WEIGHT);
|
||||||
|
|
||||||
if(textured)
|
if(textured)
|
||||||
{
|
{
|
||||||
|
@ -348,29 +360,31 @@ void Sprite3D::createNode(NodeData* nodedata, Node* root, const MaterialDatas& m
|
||||||
|
|
||||||
if (modelNodeData->matrialId == "" && matrialdatas.materials.size())
|
if (modelNodeData->matrialId == "" && matrialdatas.materials.size())
|
||||||
{
|
{
|
||||||
NTextureData::Usage type = NTextureData::Usage::Diffuse;
|
const NTextureData* textureData = matrialdatas.materials[0].getTextureData(NTextureData::Usage::Diffuse);
|
||||||
const NTextureData* textureData = matrialdatas.materials[0].getTextureData(type);
|
subMeshState->setTexture(textureData->filename);
|
||||||
}
|
}
|
||||||
const NMaterialData* materialData=matrialdatas.getMaterialData(modelNodeData->matrialId);
|
else
|
||||||
if(materialData)
|
|
||||||
{
|
{
|
||||||
NTextureData::Usage type = NTextureData::Usage::Diffuse;
|
const NMaterialData* materialData=matrialdatas.getMaterialData(modelNodeData->matrialId);
|
||||||
const NTextureData* textureData = materialData->getTextureData(type);
|
if(materialData)
|
||||||
if(textureData)
|
{
|
||||||
{
|
const NTextureData* textureData = materialData->getTextureData(NTextureData::Usage::Diffuse);
|
||||||
auto tex = Director::getInstance()->getTextureCache()->addImage(textureData->filename);
|
if(textureData)
|
||||||
if(tex)
|
{
|
||||||
{
|
auto tex = Director::getInstance()->getTextureCache()->addImage(textureData->filename);
|
||||||
Texture2D::TexParams texParams;
|
if(tex)
|
||||||
texParams.minFilter = GL_LINEAR;
|
{
|
||||||
texParams.magFilter = GL_LINEAR;
|
Texture2D::TexParams texParams;
|
||||||
texParams.wrapS = textureData->wrapS;
|
texParams.minFilter = GL_LINEAR;
|
||||||
texParams.wrapT = textureData->wrapT;
|
texParams.magFilter = GL_LINEAR;
|
||||||
tex->setTexParameters(texParams);
|
texParams.wrapS = textureData->wrapS;
|
||||||
subMeshState->setTexture(tex);
|
texParams.wrapT = textureData->wrapT;
|
||||||
}
|
tex->setTexParameters(texParams);
|
||||||
|
subMeshState->setTexture(tex);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,6 +70,8 @@ public:
|
||||||
/**get skin*/
|
/**get skin*/
|
||||||
MeshSkin* getSkin() const { return _skin; }
|
MeshSkin* getSkin() const { return _skin; }
|
||||||
|
|
||||||
|
Skeleton3D* getSkeleton() const { return _skeleton; }
|
||||||
|
|
||||||
/**get AttachNode by bone name, return nullptr if not exist*/
|
/**get AttachNode by bone name, return nullptr if not exist*/
|
||||||
AttachNode* getAttachNode(const std::string& boneName);
|
AttachNode* getAttachNode(const std::string& boneName);
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,7 @@ static int sceneIdx = -1;
|
||||||
|
|
||||||
static std::function<Layer*()> createFunctions[] =
|
static std::function<Layer*()> createFunctions[] =
|
||||||
{
|
{
|
||||||
|
CL(Sprite3DMirrorTest),
|
||||||
CL(Sprite3DBasicTest),
|
CL(Sprite3DBasicTest),
|
||||||
CL(Sprite3DHitTest),
|
CL(Sprite3DHitTest),
|
||||||
#if (CC_TARGET_PLATFORM != CC_PLATFORM_WP8) && (CC_TARGET_PLATFORM != CC_PLATFORM_WINRT)
|
#if (CC_TARGET_PLATFORM != CC_PLATFORM_WP8) && (CC_TARGET_PLATFORM != CC_PLATFORM_WINRT)
|
||||||
|
@ -1271,17 +1272,17 @@ std::string Sprite3DMirrorTest::subtitle() const
|
||||||
|
|
||||||
void Sprite3DMirrorTest::addNewSpriteWithCoords(Vec2 p)
|
void Sprite3DMirrorTest::addNewSpriteWithCoords(Vec2 p)
|
||||||
{
|
{
|
||||||
std::string fileName = "Sprite3DTest/orc.c3b";
|
std::string fileName = "Sprite3DTest/orc.c3t";
|
||||||
auto sprite = Sprite3D::create(fileName);
|
auto sprite = Sprite3D::create(fileName);
|
||||||
sprite->setScale(5);
|
sprite->setScale(6);
|
||||||
sprite->setRotation3D(Vec3(0,180,0));
|
sprite->setRotation3D(Vec3(90,0,0));
|
||||||
addChild(sprite);
|
addChild(sprite);
|
||||||
sprite->setPosition( Vec2( p.x - 80, p.y) );
|
sprite->setPosition( Vec2( p.x - 80, p.y) );
|
||||||
|
|
||||||
//test attach
|
// //test attach
|
||||||
auto sp = Sprite3D::create("Sprite3DTest/axe.c3b");
|
// auto sp = Sprite3D::create("Sprite3DTest/axe.c3b");
|
||||||
sprite->getAttachNode("Bip001 R Hand")->addChild(sp);
|
// sprite->getAttachNode("Bip001 R Hand")->addChild(sp);
|
||||||
|
//
|
||||||
auto animation = Animation3D::create(fileName);
|
auto animation = Animation3D::create(fileName);
|
||||||
if (animation)
|
if (animation)
|
||||||
{
|
{
|
||||||
|
@ -1292,25 +1293,25 @@ void Sprite3DMirrorTest::addNewSpriteWithCoords(Vec2 p)
|
||||||
_sprite = sprite;
|
_sprite = sprite;
|
||||||
_hasWeapon = true;
|
_hasWeapon = true;
|
||||||
|
|
||||||
//create mirror Sprite3D
|
// //create mirror Sprite3D
|
||||||
sprite = Sprite3D::create(fileName);
|
// sprite = Sprite3D::create(fileName);
|
||||||
sprite->setScale(5);
|
// sprite->setScale(5);
|
||||||
sprite->setScaleX(-5);
|
// sprite->setScaleX(-5);
|
||||||
sprite->setCullFace(GL_FRONT);
|
// sprite->setCullFace(GL_FRONT);
|
||||||
sprite->setRotation3D(Vec3(0,180,0));
|
// sprite->setRotation3D(Vec3(0,180,0));
|
||||||
addChild(sprite);
|
// addChild(sprite);
|
||||||
sprite->setPosition( Vec2( p.x + 80, p.y) );
|
// sprite->setPosition( Vec2( p.x + 80, p.y) );
|
||||||
|
//
|
||||||
//test attach
|
// //test attach
|
||||||
sp = Sprite3D::create("Sprite3DTest/axe.c3b");
|
// sp = Sprite3D::create("Sprite3DTest/axe.c3b");
|
||||||
sprite->getAttachNode("Bip001 R Hand")->addChild(sp);
|
// sprite->getAttachNode("Bip001 R Hand")->addChild(sp);
|
||||||
|
//
|
||||||
animation = Animation3D::create(fileName);
|
// animation = Animation3D::create(fileName);
|
||||||
if (animation)
|
// if (animation)
|
||||||
{
|
// {
|
||||||
auto animate = Animate3D::create(animation);
|
// auto animate = Animate3D::create(animation);
|
||||||
|
//
|
||||||
sprite->runAction(RepeatForever::create(animate));
|
// sprite->runAction(RepeatForever::create(animate));
|
||||||
}
|
// }
|
||||||
_mirrorSprite = sprite;
|
// _mirrorSprite = sprite;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue