mirror of https://github.com/axmolengine/axmol.git
merge node transform problem!!!
This commit is contained in:
parent
5c20d49cd7
commit
5ce4fbe6df
|
@ -1616,7 +1616,7 @@ bool Bundle3D::loadNodesJson(NodeDatas& nodedatas)
|
|||
{
|
||||
const rapidjson::Value& jnode = nodes[i];
|
||||
std::string id = jnode[ID].GetString();
|
||||
NodeData* nodedata = parseNodesRecursivelyJson(jnode);
|
||||
NodeData* nodedata = parseNodesRecursivelyJson(jnode, nodes.Size() == 1);
|
||||
|
||||
bool isSkeleton = jnode[SKELETON].GetBool();
|
||||
if (isSkeleton)
|
||||
|
@ -1626,22 +1626,24 @@ bool Bundle3D::loadNodesJson(NodeDatas& nodedatas)
|
|||
}
|
||||
return true;
|
||||
}
|
||||
NodeData* Bundle3D::parseNodesRecursivelyJson(const rapidjson::Value& jvalue)
|
||||
NodeData* Bundle3D::parseNodesRecursivelyJson(const rapidjson::Value& jvalue, bool singleSprite)
|
||||
{
|
||||
NodeData* nodedata = new (std::nothrow) NodeData();;
|
||||
// id
|
||||
nodedata->id = jvalue[ID].GetString();
|
||||
|
||||
// transform
|
||||
Mat4 tranform;
|
||||
Mat4 transform;
|
||||
const rapidjson::Value& jtransform = jvalue[TRANSFORM];
|
||||
|
||||
for (rapidjson::SizeType j = 0; j < jtransform.Size(); j++)
|
||||
{
|
||||
tranform.m[j] = jtransform[j].GetDouble();
|
||||
transform.m[j] = jtransform[j].GetDouble();
|
||||
}
|
||||
|
||||
nodedata->transform = tranform;
|
||||
nodedata->transform = transform;
|
||||
|
||||
bool isSkin = false;
|
||||
|
||||
// parts
|
||||
if (jvalue.HasMember(PARTS))
|
||||
|
@ -1690,11 +1692,31 @@ NodeData* Bundle3D::parseNodesRecursivelyJson(const rapidjson::Value& jvalue)
|
|||
//invbindpos.inverse();
|
||||
modelnodedata->invBindPose.push_back(invbindpos);
|
||||
}
|
||||
|
||||
if (bones.Size() > 0)
|
||||
isSkin = true;
|
||||
}
|
||||
nodedata->modelNodeDatas.push_back(modelnodedata);
|
||||
}
|
||||
}
|
||||
|
||||
// set transform
|
||||
if(_version == "0.1" || _version == "0.2" || _version == "0.3" || _version == "0.4" || _version == "0.5" || _version == "0.6")
|
||||
{
|
||||
if(isSkin || singleSprite)
|
||||
{
|
||||
nodedata->transform = Mat4::IDENTITY;
|
||||
}
|
||||
else
|
||||
{
|
||||
nodedata->transform = transform;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
nodedata->transform = transform;
|
||||
}
|
||||
|
||||
if (jvalue.HasMember(CHILDREN))
|
||||
{
|
||||
const rapidjson::Value& children = jvalue[CHILDREN];
|
||||
|
@ -1702,7 +1724,7 @@ NodeData* Bundle3D::parseNodesRecursivelyJson(const rapidjson::Value& jvalue)
|
|||
{
|
||||
const rapidjson::Value& child = children[i];
|
||||
|
||||
NodeData* tempdata = parseNodesRecursivelyJson(child);
|
||||
NodeData* tempdata = parseNodesRecursivelyJson(child, singleSprite);
|
||||
nodedata->children.push_back(tempdata);
|
||||
}
|
||||
}
|
||||
|
@ -1725,7 +1747,7 @@ bool Bundle3D::loadNodesBinary(NodeDatas& nodedatas)
|
|||
for (rapidjson::SizeType i = 0; i < nodeSize; i++)
|
||||
{
|
||||
bool skeleton = false;
|
||||
NodeData* nodedata = parseNodesRecursivelyBinary(skeleton);
|
||||
NodeData* nodedata = parseNodesRecursivelyBinary(skeleton, nodeSize == 1);
|
||||
|
||||
if (skeleton)
|
||||
nodedatas.skeleton.push_back(nodedata);
|
||||
|
@ -1734,7 +1756,7 @@ bool Bundle3D::loadNodesBinary(NodeDatas& nodedatas)
|
|||
}
|
||||
return true;
|
||||
}
|
||||
NodeData* Bundle3D::parseNodesRecursivelyBinary(bool& skeleton)
|
||||
NodeData* Bundle3D::parseNodesRecursivelyBinary(bool& skeleton, bool singleSprite)
|
||||
{
|
||||
// id
|
||||
std::string id = _binaryReader.readString();
|
||||
|
@ -1765,7 +1787,9 @@ NodeData* Bundle3D::parseNodesRecursivelyBinary(bool& skeleton)
|
|||
|
||||
NodeData* nodedata = new (std::nothrow) NodeData();
|
||||
nodedata->id = id;
|
||||
nodedata->transform = transform;
|
||||
|
||||
bool isSkin = false;
|
||||
|
||||
if (partsSize > 0)
|
||||
{
|
||||
for (unsigned int i = 0; i < partsSize; i++)
|
||||
|
@ -1804,6 +1828,7 @@ NodeData* Bundle3D::parseNodesRecursivelyBinary(bool& skeleton)
|
|||
|
||||
modelnodedata->invBindPose.push_back(invbindpos);
|
||||
}
|
||||
isSkin = true;
|
||||
}
|
||||
unsigned int uvMapping = 0;
|
||||
if (_binaryReader.read(&uvMapping, 4, 1) != 1)
|
||||
|
@ -1832,6 +1857,23 @@ NodeData* Bundle3D::parseNodesRecursivelyBinary(bool& skeleton)
|
|||
}
|
||||
}
|
||||
|
||||
// set transform
|
||||
if(_version == "0.1" || _version == "0.2" || _version == "0.3" || _version == "0.4" || _version == "0.5" || _version == "0.6")
|
||||
{
|
||||
if(isSkin || singleSprite)
|
||||
{
|
||||
nodedata->transform = Mat4::IDENTITY;
|
||||
}
|
||||
else
|
||||
{
|
||||
nodedata->transform = transform;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
nodedata->transform = transform;
|
||||
}
|
||||
|
||||
unsigned int childrenSize = 0;
|
||||
if (_binaryReader.read(&childrenSize, 4, 1) != 1)
|
||||
{
|
||||
|
@ -1842,7 +1884,7 @@ NodeData* Bundle3D::parseNodesRecursivelyBinary(bool& skeleton)
|
|||
{
|
||||
for (unsigned int i = 0; i < childrenSize; i++)
|
||||
{
|
||||
NodeData* tempdata = parseNodesRecursivelyBinary(skeleton);
|
||||
NodeData* tempdata = parseNodesRecursivelyBinary(skeleton, singleSprite);
|
||||
nodedata->children.push_back(tempdata);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -112,13 +112,13 @@ protected:
|
|||
* load nodes of json
|
||||
*/
|
||||
bool loadNodesJson(NodeDatas& nodedatas);
|
||||
NodeData* parseNodesRecursivelyJson(const rapidjson::Value& jvalue);
|
||||
NodeData* parseNodesRecursivelyJson(const rapidjson::Value& jvalue, bool singleSprite);
|
||||
|
||||
/**
|
||||
* load nodes of binary
|
||||
*/
|
||||
bool loadNodesBinary(NodeDatas& nodedatas);
|
||||
NodeData* parseNodesRecursivelyBinary(bool& skeleton);
|
||||
NodeData* parseNodesRecursivelyBinary(bool& skeleton, bool singleSprite);
|
||||
|
||||
/**
|
||||
* get define data type
|
||||
|
|
|
@ -518,6 +518,8 @@ void Sprite3D::createNode(NodeData* nodedata, Node* root, const MaterialDatas& m
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
setAdditionalTransform(&nodedata->transform);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
Loading…
Reference in New Issue