mirror of https://github.com/axmolengine/axmol.git
Merge branch 'newcode' into merge-bundle
Conflicts: cocos/3d/CCBundle3D.cpp
This commit is contained in:
commit
8e0d80d4c6
|
@ -291,12 +291,13 @@ bool Bundle3D::loadObj(MeshDatas& meshdatas, MaterialDatas& materialdatas, NodeD
|
|||
|
||||
meshdata->subMeshIndices.push_back(it.mesh.indices);
|
||||
meshdata->subMeshIds.push_back(str);
|
||||
|
||||
auto node = new NodeData();
|
||||
auto modelnode = new ModelNodeData();
|
||||
modelnode->matrialId = str;
|
||||
modelnode->subMeshId = str;
|
||||
modelnode->id = it.name;
|
||||
nodedatas.nodes.push_back(modelnode);
|
||||
node->modelNodeDatas.push_back(modelnode);
|
||||
nodedatas.nodes.push_back(node);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -786,13 +787,15 @@ bool Bundle3D::loadNodes(NodeDatas& nodedatas)
|
|||
}
|
||||
}
|
||||
nodedatas.skeleton.push_back(nodeDatas[skinData.rootBoneIndex]);
|
||||
auto node= new NodeData();
|
||||
auto modelnode = new ModelNodeData();
|
||||
modelnode->matrialId = "";
|
||||
modelnode->subMeshId = "";
|
||||
modelnode->id = "";
|
||||
modelnode->bones = skinData.skinBoneNames;
|
||||
modelnode->invBindPose = skinData.inverseBindPoseMatrices;
|
||||
nodedatas.nodes.push_back(modelnode);
|
||||
node->modelNodeDatas.push_back(modelnode);
|
||||
nodedatas.nodes.push_back(node);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1685,11 +1688,11 @@ bool Bundle3D::loadNodesJson(NodeDatas& nodedatas)
|
|||
}
|
||||
NodeData* Bundle3D::parseNodesRecursivelyJson(const rapidjson::Value& jvalue)
|
||||
{
|
||||
NodeData* nodedata;
|
||||
if (jvalue.HasMember(PARTS))
|
||||
nodedata = new ModelNodeData();
|
||||
else
|
||||
nodedata = new NodeData();
|
||||
NodeData* nodedata = new NodeData();;
|
||||
//if (jvalue.HasMember(PARTS))
|
||||
// nodedata = new ModelNodeData();
|
||||
//else
|
||||
//nodedata = new NodeData();
|
||||
|
||||
// id
|
||||
nodedata->id = jvalue[ID].GetString();
|
||||
|
@ -1709,10 +1712,11 @@ NodeData* Bundle3D::parseNodesRecursivelyJson(const rapidjson::Value& jvalue)
|
|||
if (jvalue.HasMember(PARTS))
|
||||
{
|
||||
const rapidjson::Value& parts = jvalue[PARTS];
|
||||
ModelNodeData* modelnodedata = dynamic_cast<ModelNodeData*>(nodedata);
|
||||
|
||||
|
||||
for (rapidjson::SizeType i = 0; i < parts.Size(); i++)
|
||||
{
|
||||
ModelNodeData* modelnodedata = new ModelNodeData();;
|
||||
const rapidjson::Value& part = parts[i];
|
||||
modelnodedata->subMeshId = part[MESHPARTID].GetString();
|
||||
modelnodedata->matrialId = part[MATERIALID].GetString();
|
||||
|
@ -1753,6 +1757,7 @@ NodeData* Bundle3D::parseNodesRecursivelyJson(const rapidjson::Value& jvalue)
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
||||
return nodedata;
|
||||
}
|
||||
|
||||
|
@ -1820,16 +1824,14 @@ NodeData* Bundle3D::parseNodesRecursivelyBinary(bool& skeleton)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
NodeData* nodedata;
|
||||
NodeData* nodedata = new NodeData();
|
||||
nodedata->id = id;
|
||||
nodedata->transform = transform;
|
||||
if (partsSize > 0)
|
||||
{
|
||||
nodedata = new ModelNodeData();
|
||||
nodedata->id = id;
|
||||
nodedata->transform = transform;
|
||||
ModelNodeData* modelnodedata = dynamic_cast<ModelNodeData*>(nodedata);
|
||||
|
||||
for (rapidjson::SizeType i = 0; i < partsSize; i++)
|
||||
{
|
||||
ModelNodeData* modelnodedata = new ModelNodeData();
|
||||
modelnodedata->subMeshId = _binaryReader.readString();
|
||||
modelnodedata->matrialId = _binaryReader.readString();
|
||||
|
||||
|
@ -1887,14 +1889,15 @@ NodeData* Bundle3D::parseNodesRecursivelyBinary(bool& skeleton)
|
|||
}
|
||||
}
|
||||
}
|
||||
nodedata->modelNodeDatas.push_back(modelnodedata);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
nodedata = new NodeData();
|
||||
nodedata->id = id;
|
||||
nodedata->transform = transform;
|
||||
}
|
||||
//else
|
||||
//{
|
||||
// nodedata = new NodeData();
|
||||
// nodedata->id = id;
|
||||
// nodedata->transform = transform;
|
||||
//}
|
||||
|
||||
unsigned int childrenSize = 0;
|
||||
if (_binaryReader.read(&childrenSize, 4, 1) != 1)
|
||||
|
|
|
@ -54,8 +54,9 @@ struct NodeData
|
|||
{
|
||||
std::string id;
|
||||
Mat4 transform;
|
||||
std::vector<NodeData*> children;
|
||||
|
||||
std::vector<ModelNodeData*> modelNodeDatas;
|
||||
std::vector<NodeData*> children;
|
||||
|
||||
virtual ~NodeData()
|
||||
{
|
||||
resetData();
|
||||
|
|
|
@ -280,101 +280,103 @@ GLProgram* Sprite3D::getDefaultGLProgram(bool textured)
|
|||
void Sprite3D::createNode(NodeData* nodedata, Node* root, const MaterialDatas& matrialdatas, bool singleSprite)
|
||||
{
|
||||
Node* node=nullptr;
|
||||
ModelNodeData* modelNodeData=nodedata->asModelNodeData();
|
||||
if(modelNodeData)
|
||||
for(const auto& it : nodedata->modelNodeDatas)
|
||||
{
|
||||
if(modelNodeData->bones.size() > 0 || singleSprite)
|
||||
if(it)
|
||||
{
|
||||
auto subMeshState = SubMeshState::create(modelNodeData->id);
|
||||
if(subMeshState)
|
||||
if(it->bones.size() > 0 || singleSprite)
|
||||
{
|
||||
_subMeshStates.pushBack(subMeshState);
|
||||
subMeshState->setSubMesh(getSubMesh(modelNodeData->subMeshId));
|
||||
if (_skeleton && modelNodeData->bones.size())
|
||||
auto subMeshState = SubMeshState::create(it->id);
|
||||
if(subMeshState)
|
||||
{
|
||||
auto skin = MeshSkin::create(_skeleton, modelNodeData->bones, modelNodeData->invBindPose);
|
||||
subMeshState->setSkin(skin);
|
||||
}
|
||||
subMeshState->_visibleChanged = std::bind(&Sprite3D::onAABBDirty, this);
|
||||
|
||||
if (modelNodeData->matrialId == "" && matrialdatas.materials.size())
|
||||
{
|
||||
const NTextureData* textureData = matrialdatas.materials[0].getTextureData(NTextureData::Usage::Diffuse);
|
||||
subMeshState->setTexture(textureData->filename);
|
||||
}
|
||||
else
|
||||
{
|
||||
const NMaterialData* materialData=matrialdatas.getMaterialData(modelNodeData->matrialId);
|
||||
if(materialData)
|
||||
_subMeshStates.pushBack(subMeshState);
|
||||
subMeshState->setSubMesh(getSubMesh(it->subMeshId));
|
||||
if (_skeleton && it->bones.size())
|
||||
{
|
||||
const NTextureData* textureData = materialData->getTextureData(NTextureData::Usage::Diffuse);
|
||||
if(textureData)
|
||||
{
|
||||
auto tex = Director::getInstance()->getTextureCache()->addImage(textureData->filename);
|
||||
if(tex)
|
||||
{
|
||||
Texture2D::TexParams texParams;
|
||||
texParams.minFilter = GL_LINEAR;
|
||||
texParams.magFilter = GL_LINEAR;
|
||||
texParams.wrapS = textureData->wrapS;
|
||||
texParams.wrapT = textureData->wrapT;
|
||||
tex->setTexParameters(texParams);
|
||||
subMeshState->setTexture(tex);
|
||||
}
|
||||
auto skin = MeshSkin::create(_skeleton, it->bones, it->invBindPose);
|
||||
subMeshState->setSkin(skin);
|
||||
}
|
||||
subMeshState->_visibleChanged = std::bind(&Sprite3D::onAABBDirty, this);
|
||||
|
||||
if (it->matrialId == "" && matrialdatas.materials.size())
|
||||
{
|
||||
const NTextureData* textureData = matrialdatas.materials[0].getTextureData(NTextureData::Usage::Diffuse);
|
||||
subMeshState->setTexture(textureData->filename);
|
||||
}
|
||||
else
|
||||
{
|
||||
const NMaterialData* materialData=matrialdatas.getMaterialData(it->matrialId);
|
||||
if(materialData)
|
||||
{
|
||||
const NTextureData* textureData = materialData->getTextureData(NTextureData::Usage::Diffuse);
|
||||
if(textureData)
|
||||
{
|
||||
auto tex = Director::getInstance()->getTextureCache()->addImage(textureData->filename);
|
||||
if(tex)
|
||||
{
|
||||
Texture2D::TexParams texParams;
|
||||
texParams.minFilter = GL_LINEAR;
|
||||
texParams.magFilter = GL_LINEAR;
|
||||
texParams.wrapS = textureData->wrapS;
|
||||
texParams.wrapT = textureData->wrapT;
|
||||
tex->setTexParameters(texParams);
|
||||
subMeshState->setTexture(tex);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
auto sprite = new Sprite3D();
|
||||
if (sprite)
|
||||
else
|
||||
{
|
||||
auto subMeshState = SubMeshState::create(modelNodeData->id);
|
||||
subMeshState->setSubMesh(getSubMesh(modelNodeData->subMeshId));
|
||||
if (modelNodeData->matrialId == "" && matrialdatas.materials.size())
|
||||
auto sprite = new Sprite3D();
|
||||
if (sprite)
|
||||
{
|
||||
const NTextureData* textureData = matrialdatas.materials[0].getTextureData(NTextureData::Usage::Diffuse);
|
||||
subMeshState->setTexture(textureData->filename);
|
||||
}
|
||||
else
|
||||
{
|
||||
const NMaterialData* materialData=matrialdatas.getMaterialData(modelNodeData->matrialId);
|
||||
if(materialData)
|
||||
auto subMeshState = SubMeshState::create(it->id);
|
||||
subMeshState->setSubMesh(getSubMesh(it->subMeshId));
|
||||
if (it->matrialId == "" && matrialdatas.materials.size())
|
||||
{
|
||||
const NTextureData* textureData = materialData->getTextureData(NTextureData::Usage::Diffuse);
|
||||
if(textureData)
|
||||
const NTextureData* textureData = matrialdatas.materials[0].getTextureData(NTextureData::Usage::Diffuse);
|
||||
subMeshState->setTexture(textureData->filename);
|
||||
}
|
||||
else
|
||||
{
|
||||
const NMaterialData* materialData=matrialdatas.getMaterialData(it->matrialId);
|
||||
if(materialData)
|
||||
{
|
||||
auto tex = Director::getInstance()->getTextureCache()->addImage(textureData->filename);
|
||||
if(tex)
|
||||
const NTextureData* textureData = materialData->getTextureData(NTextureData::Usage::Diffuse);
|
||||
if(textureData)
|
||||
{
|
||||
Texture2D::TexParams texParams;
|
||||
texParams.minFilter = GL_LINEAR;
|
||||
texParams.magFilter = GL_LINEAR;
|
||||
texParams.wrapS = textureData->wrapS;
|
||||
texParams.wrapT = textureData->wrapT;
|
||||
tex->setTexParameters(texParams);
|
||||
subMeshState->setTexture(tex);
|
||||
}
|
||||
auto tex = Director::getInstance()->getTextureCache()->addImage(textureData->filename);
|
||||
if(tex)
|
||||
{
|
||||
Texture2D::TexParams texParams;
|
||||
texParams.minFilter = GL_LINEAR;
|
||||
texParams.magFilter = GL_LINEAR;
|
||||
texParams.wrapS = textureData->wrapS;
|
||||
texParams.wrapT = textureData->wrapT;
|
||||
tex->setTexParameters(texParams);
|
||||
subMeshState->setTexture(tex);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
sprite->setAdditionalTransform(&nodedata->transform);
|
||||
sprite->addSubMeshState(subMeshState);
|
||||
sprite->autorelease();
|
||||
sprite->genGLProgramState();
|
||||
if(root)
|
||||
{
|
||||
root->addChild(sprite);
|
||||
}
|
||||
}
|
||||
sprite->setAdditionalTransform(&nodedata->transform);
|
||||
sprite->addSubMeshState(subMeshState);
|
||||
sprite->autorelease();
|
||||
sprite->genGLProgramState();
|
||||
if(root)
|
||||
{
|
||||
root->addChild(sprite);
|
||||
}
|
||||
}
|
||||
node=sprite;
|
||||
node=sprite;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
if(nodedata->modelNodeDatas.size() ==0 )
|
||||
{
|
||||
node= Node::create();
|
||||
if(node)
|
||||
|
|
Binary file not shown.
File diff suppressed because it is too large
Load Diff
|
@ -1 +1 @@
|
|||
Subproject commit b2a0338f0a6d51878ce96c4e0521d083e232e67b
|
||||
Subproject commit 5db5a4283aa22e362901e2924146ad66c2e1484f
|
Loading…
Reference in New Issue