Merge branch 'newcode' into merge-bundle

Conflicts:
	cocos/3d/CCBundle3D.cpp
This commit is contained in:
lvlong 2014-08-20 14:00:25 +08:00
commit 8e0d80d4c6
6 changed files with 5128 additions and 5069 deletions

View File

@ -291,12 +291,13 @@ bool Bundle3D::loadObj(MeshDatas& meshdatas, MaterialDatas& materialdatas, NodeD
meshdata->subMeshIndices.push_back(it.mesh.indices); meshdata->subMeshIndices.push_back(it.mesh.indices);
meshdata->subMeshIds.push_back(str); meshdata->subMeshIds.push_back(str);
auto node = new NodeData();
auto modelnode = new ModelNodeData(); auto modelnode = new ModelNodeData();
modelnode->matrialId = str; modelnode->matrialId = str;
modelnode->subMeshId = str; modelnode->subMeshId = str;
modelnode->id = it.name; modelnode->id = it.name;
nodedatas.nodes.push_back(modelnode); node->modelNodeDatas.push_back(modelnode);
nodedatas.nodes.push_back(node);
} }
return true; return true;
} }
@ -786,13 +787,15 @@ bool Bundle3D::loadNodes(NodeDatas& nodedatas)
} }
} }
nodedatas.skeleton.push_back(nodeDatas[skinData.rootBoneIndex]); nodedatas.skeleton.push_back(nodeDatas[skinData.rootBoneIndex]);
auto node= new NodeData();
auto modelnode = new ModelNodeData(); auto modelnode = new ModelNodeData();
modelnode->matrialId = ""; modelnode->matrialId = "";
modelnode->subMeshId = ""; modelnode->subMeshId = "";
modelnode->id = ""; modelnode->id = "";
modelnode->bones = skinData.skinBoneNames; modelnode->bones = skinData.skinBoneNames;
modelnode->invBindPose = skinData.inverseBindPoseMatrices; modelnode->invBindPose = skinData.inverseBindPoseMatrices;
nodedatas.nodes.push_back(modelnode); node->modelNodeDatas.push_back(modelnode);
nodedatas.nodes.push_back(node);
} }
else else
{ {
@ -1685,11 +1688,11 @@ bool Bundle3D::loadNodesJson(NodeDatas& nodedatas)
} }
NodeData* Bundle3D::parseNodesRecursivelyJson(const rapidjson::Value& jvalue) NodeData* Bundle3D::parseNodesRecursivelyJson(const rapidjson::Value& jvalue)
{ {
NodeData* nodedata; NodeData* nodedata = new NodeData();;
if (jvalue.HasMember(PARTS)) //if (jvalue.HasMember(PARTS))
nodedata = new ModelNodeData(); // nodedata = new ModelNodeData();
else //else
nodedata = new NodeData(); //nodedata = new NodeData();
// id // id
nodedata->id = jvalue[ID].GetString(); nodedata->id = jvalue[ID].GetString();
@ -1709,10 +1712,11 @@ NodeData* Bundle3D::parseNodesRecursivelyJson(const rapidjson::Value& jvalue)
if (jvalue.HasMember(PARTS)) if (jvalue.HasMember(PARTS))
{ {
const rapidjson::Value& parts = jvalue[PARTS]; const rapidjson::Value& parts = jvalue[PARTS];
ModelNodeData* modelnodedata = dynamic_cast<ModelNodeData*>(nodedata);
for (rapidjson::SizeType i = 0; i < parts.Size(); i++) for (rapidjson::SizeType i = 0; i < parts.Size(); i++)
{ {
ModelNodeData* modelnodedata = new ModelNodeData();;
const rapidjson::Value& part = parts[i]; const rapidjson::Value& part = parts[i];
modelnodedata->subMeshId = part[MESHPARTID].GetString(); modelnodedata->subMeshId = part[MESHPARTID].GetString();
modelnodedata->matrialId = part[MATERIALID].GetString(); modelnodedata->matrialId = part[MATERIALID].GetString();
@ -1753,6 +1757,7 @@ NodeData* Bundle3D::parseNodesRecursivelyJson(const rapidjson::Value& jvalue)
modelnodedata->invBindPose.push_back(invbindpos); modelnodedata->invBindPose.push_back(invbindpos);
} }
} }
nodedata->modelNodeDatas.push_back(modelnodedata);
} }
} }
@ -1767,7 +1772,6 @@ NodeData* Bundle3D::parseNodesRecursivelyJson(const rapidjson::Value& jvalue)
nodedata->children.push_back(tempdata); nodedata->children.push_back(tempdata);
} }
} }
return nodedata; return nodedata;
} }
@ -1820,16 +1824,14 @@ NodeData* Bundle3D::parseNodesRecursivelyBinary(bool& skeleton)
return nullptr; return nullptr;
} }
NodeData* nodedata; NodeData* nodedata = new NodeData();
if (partsSize > 0)
{
nodedata = new ModelNodeData();
nodedata->id = id; nodedata->id = id;
nodedata->transform = transform; nodedata->transform = transform;
ModelNodeData* modelnodedata = dynamic_cast<ModelNodeData*>(nodedata); if (partsSize > 0)
{
for (rapidjson::SizeType i = 0; i < partsSize; i++) for (rapidjson::SizeType i = 0; i < partsSize; i++)
{ {
ModelNodeData* modelnodedata = new ModelNodeData();
modelnodedata->subMeshId = _binaryReader.readString(); modelnodedata->subMeshId = _binaryReader.readString();
modelnodedata->matrialId = _binaryReader.readString(); modelnodedata->matrialId = _binaryReader.readString();
@ -1887,14 +1889,15 @@ NodeData* Bundle3D::parseNodesRecursivelyBinary(bool& skeleton)
} }
} }
} }
nodedata->modelNodeDatas.push_back(modelnodedata);
} }
} }
else //else
{ //{
nodedata = new NodeData(); // nodedata = new NodeData();
nodedata->id = id; // nodedata->id = id;
nodedata->transform = transform; // nodedata->transform = transform;
} //}
unsigned int childrenSize = 0; unsigned int childrenSize = 0;
if (_binaryReader.read(&childrenSize, 4, 1) != 1) if (_binaryReader.read(&childrenSize, 4, 1) != 1)

View File

@ -54,6 +54,7 @@ struct NodeData
{ {
std::string id; std::string id;
Mat4 transform; Mat4 transform;
std::vector<ModelNodeData*> modelNodeDatas;
std::vector<NodeData*> children; std::vector<NodeData*> children;
virtual ~NodeData() virtual ~NodeData()

View File

@ -280,31 +280,32 @@ GLProgram* Sprite3D::getDefaultGLProgram(bool textured)
void Sprite3D::createNode(NodeData* nodedata, Node* root, const MaterialDatas& matrialdatas, bool singleSprite) void Sprite3D::createNode(NodeData* nodedata, Node* root, const MaterialDatas& matrialdatas, bool singleSprite)
{ {
Node* node=nullptr; Node* node=nullptr;
ModelNodeData* modelNodeData=nodedata->asModelNodeData(); for(const auto& it : nodedata->modelNodeDatas)
if(modelNodeData)
{ {
if(modelNodeData->bones.size() > 0 || singleSprite) if(it)
{ {
auto subMeshState = SubMeshState::create(modelNodeData->id); if(it->bones.size() > 0 || singleSprite)
{
auto subMeshState = SubMeshState::create(it->id);
if(subMeshState) if(subMeshState)
{ {
_subMeshStates.pushBack(subMeshState); _subMeshStates.pushBack(subMeshState);
subMeshState->setSubMesh(getSubMesh(modelNodeData->subMeshId)); subMeshState->setSubMesh(getSubMesh(it->subMeshId));
if (_skeleton && modelNodeData->bones.size()) if (_skeleton && it->bones.size())
{ {
auto skin = MeshSkin::create(_skeleton, modelNodeData->bones, modelNodeData->invBindPose); auto skin = MeshSkin::create(_skeleton, it->bones, it->invBindPose);
subMeshState->setSkin(skin); subMeshState->setSkin(skin);
} }
subMeshState->_visibleChanged = std::bind(&Sprite3D::onAABBDirty, this); subMeshState->_visibleChanged = std::bind(&Sprite3D::onAABBDirty, this);
if (modelNodeData->matrialId == "" && matrialdatas.materials.size()) if (it->matrialId == "" && matrialdatas.materials.size())
{ {
const NTextureData* textureData = matrialdatas.materials[0].getTextureData(NTextureData::Usage::Diffuse); const NTextureData* textureData = matrialdatas.materials[0].getTextureData(NTextureData::Usage::Diffuse);
subMeshState->setTexture(textureData->filename); subMeshState->setTexture(textureData->filename);
} }
else else
{ {
const NMaterialData* materialData=matrialdatas.getMaterialData(modelNodeData->matrialId); const NMaterialData* materialData=matrialdatas.getMaterialData(it->matrialId);
if(materialData) if(materialData)
{ {
const NTextureData* textureData = materialData->getTextureData(NTextureData::Usage::Diffuse); const NTextureData* textureData = materialData->getTextureData(NTextureData::Usage::Diffuse);
@ -332,16 +333,16 @@ void Sprite3D::createNode(NodeData* nodedata, Node* root, const MaterialDatas& m
auto sprite = new Sprite3D(); auto sprite = new Sprite3D();
if (sprite) if (sprite)
{ {
auto subMeshState = SubMeshState::create(modelNodeData->id); auto subMeshState = SubMeshState::create(it->id);
subMeshState->setSubMesh(getSubMesh(modelNodeData->subMeshId)); subMeshState->setSubMesh(getSubMesh(it->subMeshId));
if (modelNodeData->matrialId == "" && matrialdatas.materials.size()) if (it->matrialId == "" && matrialdatas.materials.size())
{ {
const NTextureData* textureData = matrialdatas.materials[0].getTextureData(NTextureData::Usage::Diffuse); const NTextureData* textureData = matrialdatas.materials[0].getTextureData(NTextureData::Usage::Diffuse);
subMeshState->setTexture(textureData->filename); subMeshState->setTexture(textureData->filename);
} }
else else
{ {
const NMaterialData* materialData=matrialdatas.getMaterialData(modelNodeData->matrialId); const NMaterialData* materialData=matrialdatas.getMaterialData(it->matrialId);
if(materialData) if(materialData)
{ {
const NTextureData* textureData = materialData->getTextureData(NTextureData::Usage::Diffuse); const NTextureData* textureData = materialData->getTextureData(NTextureData::Usage::Diffuse);
@ -374,7 +375,8 @@ void Sprite3D::createNode(NodeData* nodedata, Node* root, const MaterialDatas& m
node=sprite; node=sprite;
} }
} }
else }
if(nodedata->modelNodeDatas.size() ==0 )
{ {
node= Node::create(); node= Node::create();
if(node) if(node)

File diff suppressed because it is too large Load Diff

@ -1 +1 @@
Subproject commit b2a0338f0a6d51878ce96c4e0521d083e232e67b Subproject commit 5db5a4283aa22e362901e2924146ad66c2e1484f