From 4c6533255026b8e7263b2dca20dc87e00e13bcf7 Mon Sep 17 00:00:00 2001 From: lvlonggame Date: Sun, 1 Feb 2015 21:14:37 +0800 Subject: [PATCH 1/8] add project function to camera --- cocos/2d/CCCamera.cpp | 17 +++++++++++++++++ cocos/2d/CCCamera.h | 2 ++ 2 files changed, 19 insertions(+) diff --git a/cocos/2d/CCCamera.cpp b/cocos/2d/CCCamera.cpp index 89baefd956..e4d1513761 100644 --- a/cocos/2d/CCCamera.cpp +++ b/cocos/2d/CCCamera.cpp @@ -234,6 +234,23 @@ bool Camera::initOrthographic(float zoomX, float zoomY, float nearPlane, float f return true; } +void Camera::project(const Rect& viewport, const Vec3& position, Vec2* out) const +{ + + // Transform the point to clip-space. + Vec4 clipPos; + getViewProjectionMatrix().transformVector(Vec4(position.x, position.y, position.z, 1.0f), &clipPos); + + // Compute normalized device coordinates. + GP_ASSERT(clipPos.w != 0.0f); + float ndcX = clipPos.x / clipPos.w; + float ndcY = clipPos.y / clipPos.w; + + // Compute screen coordinates by applying our viewport transformation. + out->x = viewport.origin.x + (ndcX + 1.0f) * 0.5f * viewport.size.width; + out->y = viewport.origin.y + (1.0f - (ndcY + 1.0f) * 0.5f) * viewport.size.height; +} + void Camera::unproject(const Size& viewport, Vec3* src, Vec3* dst) const { assert(dst); diff --git a/cocos/2d/CCCamera.h b/cocos/2d/CCCamera.h index bd4e73fb15..35188abe70 100644 --- a/cocos/2d/CCCamera.h +++ b/cocos/2d/CCCamera.h @@ -131,6 +131,8 @@ public: /**get view projection matrix*/ const Mat4& getViewProjectionMatrix() const; + void project(const Rect& viewport, const Vec3& position, Vec2* out) const; + /** * Convert the specified point of viewport from screenspace coordinate into the worldspace coordinate. */ From 6d92b7adc9753a6cd7a24764ee78958bc10477f3 Mon Sep 17 00:00:00 2001 From: lvlong Date: Tue, 3 Feb 2015 11:59:43 +0800 Subject: [PATCH 2/8] modify Camera::project --- cocos/2d/CCCamera.cpp | 16 ++++++---------- cocos/2d/CCCamera.h | 19 +++++++++++++++---- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/cocos/2d/CCCamera.cpp b/cocos/2d/CCCamera.cpp index e4d1513761..0c071f5a33 100644 --- a/cocos/2d/CCCamera.cpp +++ b/cocos/2d/CCCamera.cpp @@ -234,21 +234,17 @@ bool Camera::initOrthographic(float zoomX, float zoomY, float nearPlane, float f return true; } -void Camera::project(const Rect& viewport, const Vec3& position, Vec2* out) const +void Camera::project(const Size& viewport, Vec3* src, Vec2* dst) const { - - // Transform the point to clip-space. Vec4 clipPos; - getViewProjectionMatrix().transformVector(Vec4(position.x, position.y, position.z, 1.0f), &clipPos); - - // Compute normalized device coordinates. + getViewProjectionMatrix().transformVector(Vec4(src->x, src->y, src->z, 1.0f), &clipPos); + GP_ASSERT(clipPos.w != 0.0f); float ndcX = clipPos.x / clipPos.w; float ndcY = clipPos.y / clipPos.w; - - // Compute screen coordinates by applying our viewport transformation. - out->x = viewport.origin.x + (ndcX + 1.0f) * 0.5f * viewport.size.width; - out->y = viewport.origin.y + (1.0f - (ndcY + 1.0f) * 0.5f) * viewport.size.height; + + dst->x = (ndcX + 1.0f) * 0.5f * viewport.width; + dst->y = (1.0f - (ndcY + 1.0f) * 0.5f) * viewport.height; } void Camera::unproject(const Size& viewport, Vec3* src, Vec3* dst) const diff --git a/cocos/2d/CCCamera.h b/cocos/2d/CCCamera.h index 35188abe70..cf20bbc86e 100644 --- a/cocos/2d/CCCamera.h +++ b/cocos/2d/CCCamera.h @@ -131,11 +131,22 @@ public: /**get view projection matrix*/ const Mat4& getViewProjectionMatrix() const; - void project(const Rect& viewport, const Vec3& position, Vec2* out) const; - /** - * Convert the specified point of viewport from screenspace coordinate into the worldspace coordinate. - */ + * convert the specified point of viewport from world-space coordinates into the screen-space coordinates. + * + * @param viewport The viewport size to use. + * @param src The world-space position. + * @param dst The screen-space position. + */ + void project(const Size& viewport, Vec3* src, Vec2* dst) const; + + /** + * Convert the specified point of viewport from screen-space coordinate into the world-space coordinate. + * + * @param viewport The viewport size to use. + * @param src The screen-space position. + * @param dst The world-space position. + */ void unproject(const Size& viewport, Vec3* src, Vec3* dst) const; /** From a0c7723edbf7db5149f1722a3dc05ad5676bb24b Mon Sep 17 00:00:00 2001 From: lvlong Date: Tue, 3 Feb 2015 14:21:12 +0800 Subject: [PATCH 3/8] add GP_ASSERT --- cocos/2d/CCCamera.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cocos/2d/CCCamera.cpp b/cocos/2d/CCCamera.cpp index 0c071f5a33..e610139df4 100644 --- a/cocos/2d/CCCamera.cpp +++ b/cocos/2d/CCCamera.cpp @@ -236,6 +236,9 @@ bool Camera::initOrthographic(float zoomX, float zoomY, float nearPlane, float f void Camera::project(const Size& viewport, Vec3* src, Vec2* dst) const { + GP_ASSERT(src); + GP_ASSERT(dst); + Vec4 clipPos; getViewProjectionMatrix().transformVector(Vec4(src->x, src->y, src->z, 1.0f), &clipPos); @@ -249,7 +252,9 @@ void Camera::project(const Size& viewport, Vec3* src, Vec2* dst) const void Camera::unproject(const Size& viewport, Vec3* src, Vec3* dst) const { - assert(dst); + GP_ASSERT(src); + GP_ASSERT(dst); + Vec4 screen(src->x / viewport.width, ((viewport.height - src->y)) / viewport.height, src->z, 1.0f); screen.x = screen.x * 2.0f - 1.0f; screen.y = screen.y * 2.0f - 1.0f; From 6152925739245ea6fa6e92a151dd299604d6901f Mon Sep 17 00:00:00 2001 From: lvlong Date: Wed, 4 Feb 2015 16:19:30 +0800 Subject: [PATCH 4/8] If parse the vertex attribute is fail, then discard the vertex attribute. --- cocos/3d/CCBundle3D.cpp | 110 ++++++++++++++++++++++++---------------- cocos/3d/CCBundle3D.h | 2 +- 2 files changed, 68 insertions(+), 44 deletions(-) diff --git a/cocos/3d/CCBundle3D.cpp b/cocos/3d/CCBundle3D.cpp index bb8879e41c..ef0da6f433 100644 --- a/cocos/3d/CCBundle3D.cpp +++ b/cocos/3d/CCBundle3D.cpp @@ -375,31 +375,39 @@ bool Bundle3D::loadMeshDatasBinary(MeshDatas& meshdatas) for(int i = 0; i < meshSize ; i++ ) { MeshData* meshData = new (std::nothrow) MeshData(); - unsigned int attribSize=0; + unsigned int attribSize=0; // read mesh data if (_binaryReader.read(&attribSize, 4, 1) != 1 || attribSize < 1) { CCLOG("warning: Failed to read meshdata: attribCount '%s'.", _path.c_str()); return false; } - meshData->attribCount = attribSize; - meshData->attribs.resize(meshData->attribCount); - for (ssize_t j = 0; j < meshData->attribCount; j++) + + for (ssize_t j = 0; j < attribSize; j++) { - std::string attribute=""; unsigned int vSize; if (_binaryReader.read(&vSize, 4, 1) != 1) { CCLOG("warning: Failed to read meshdata: usage or size '%s'.", _path.c_str()); return false; } + + MeshVertexAttrib attrib; std::string type = _binaryReader.readString(); - attribute=_binaryReader.readString(); - meshData->attribs[j].size = vSize; - meshData->attribs[j].attribSizeBytes = meshData->attribs[j].size * 4; - meshData->attribs[j].type = parseGLType(type); - meshData->attribs[j].vertexAttrib = parseGLProgramAttribute(attribute); + std::string attribute = _binaryReader.readString(); + attrib.size = vSize; + attrib.attribSizeBytes = attrib.size * 4; + attrib.type = parseGLType(type); + + // check whether the vertex-attribute is valide + attrib.vertexAttrib = parseGLProgramAttribute(attribute); + if (attrib.vertexAttrib < 0) + continue; + + meshData->attribs.push_back(attrib); } + meshData->attribCount = (int)meshData->attribs.size(); + unsigned int vertexSizeInFloat = 0; // Read vertex data if (_binaryReader.read(&vertexSizeInFloat, 4, 1) != 1 || vertexSizeInFloat == 0) @@ -692,13 +700,11 @@ bool Bundle3D::loadMeshDatasJson(MeshDatas& meshdatas) const rapidjson::Value& mesh_data = mesh_data_array[index]; // mesh_vertex_attribute const rapidjson::Value& mesh_vertex_attribute = mesh_data[ATTRIBUTES]; - MeshVertexAttrib tempAttrib; - meshData->attribCount=mesh_vertex_attribute.Size(); - meshData->attribs.resize(meshData->attribCount); - for (int i = 0; i < mesh_vertex_attribute.Size(); i++) + unsigned int attributeCount = mesh_vertex_attribute.Size(); + for (int i = 0; i < attributeCount; i++) { + MeshVertexAttrib tempAttrib; const rapidjson::Value& mesh_vertex_attribute_val = mesh_vertex_attribute[i]; - int size = mesh_vertex_attribute_val[ATTRIBUTESIZE].GetInt(); std::string type = mesh_vertex_attribute_val[TYPE].GetString(); std::string attribute = mesh_vertex_attribute_val[ATTRIBUTE].GetString(); @@ -706,9 +712,16 @@ bool Bundle3D::loadMeshDatasJson(MeshDatas& meshdatas) tempAttrib.size = size; tempAttrib.attribSizeBytes = sizeof(float) * size; tempAttrib.type = parseGLType(type); + + // check whether the vertex-attribute is valide tempAttrib.vertexAttrib = parseGLProgramAttribute(attribute); - meshData->attribs[i]=tempAttrib; + if (tempAttrib.vertexAttrib < 0) + continue; + + meshData->attribs.push_back(tempAttrib); } + meshData->attribCount = (int)meshData->attribs.size(); + // mesh vertices //////////////////////////////////////////////////////////////////////////////////////////////// const rapidjson::Value& mesh_data_vertex_array = mesh_data[VERTICES]; @@ -1079,17 +1092,23 @@ bool Bundle3D::loadMeshDataJson_0_1(MeshDatas& meshdatas) // mesh_vertex_attribute const rapidjson::Value& mesh_vertex_attribute = mesh_data_val[ATTRIBUTES]; - meshdata->attribCount = mesh_vertex_attribute.Size(); - meshdata->attribs.resize(meshdata->attribCount); - for (rapidjson::SizeType i = 0; i < mesh_vertex_attribute.Size(); i++) + unsigned int attribCount = mesh_vertex_attribute.Size(); + for (rapidjson::SizeType i = 0; i < attribCount; i++) { const rapidjson::Value& mesh_vertex_attribute_val = mesh_vertex_attribute[i]; - - meshdata->attribs[i].size = mesh_vertex_attribute_val[ATTRIBUTESIZE].GetUint(); - meshdata->attribs[i].attribSizeBytes = meshdata->attribs[i].size * 4; - meshdata->attribs[i].type = parseGLType(mesh_vertex_attribute_val[TYPE].GetString()); - meshdata->attribs[i].vertexAttrib = parseGLProgramAttribute(mesh_vertex_attribute_val[ATTRIBUTE].GetString()); + MeshVertexAttrib tempAttrib; + tempAttrib.size = mesh_vertex_attribute_val[ATTRIBUTESIZE].GetUint(); + tempAttrib.attribSizeBytes = tempAttrib.size * 4; + tempAttrib.type = parseGLType(mesh_vertex_attribute_val[TYPE].GetString()); + + // check whether the vertex-attribute is valide + tempAttrib.vertexAttrib = parseGLProgramAttribute(mesh_vertex_attribute_val[ATTRIBUTE].GetString()); + if (tempAttrib.vertexAttrib < 0) + continue; + + meshdata->attribs.push_back(tempAttrib); } + meshdata->attribCount = (int)meshdata->attribs.size(); // vertices meshdata->vertexSizeInFloat = mesh_data_body_array_0[VERTEXSIZE].GetInt(); @@ -1124,17 +1143,23 @@ bool Bundle3D::loadMeshDataJson_0_2(MeshDatas& meshdatas) // mesh_vertex_attribute const rapidjson::Value& mesh_vertex_attribute = mesh_array_0[ATTRIBUTES]; - meshdata->attribCount = mesh_vertex_attribute.Size(); - meshdata->attribs.resize(meshdata->attribCount); - for (rapidjson::SizeType i = 0; i < mesh_vertex_attribute.Size(); i++) + unsigned int attribCount = mesh_vertex_attribute.Size(); + for (rapidjson::SizeType i = 0; i < attribCount; i++) { const rapidjson::Value& mesh_vertex_attribute_val = mesh_vertex_attribute[i]; - - meshdata->attribs[i].size = mesh_vertex_attribute_val[ATTRIBUTESIZE].GetUint(); - meshdata->attribs[i].attribSizeBytes = meshdata->attribs[i].size * 4; - meshdata->attribs[i].type = parseGLType(mesh_vertex_attribute_val[TYPE].GetString()); - meshdata->attribs[i].vertexAttrib = parseGLProgramAttribute(mesh_vertex_attribute_val[ATTRIBUTE].GetString()); + MeshVertexAttrib tempAttrib; + tempAttrib.size = mesh_vertex_attribute_val[ATTRIBUTESIZE].GetUint(); + tempAttrib.attribSizeBytes = tempAttrib.size * 4; + tempAttrib.type = parseGLType(mesh_vertex_attribute_val[TYPE].GetString()); + + // check whether the vertex-attribute is valide + tempAttrib.vertexAttrib = parseGLProgramAttribute(mesh_vertex_attribute_val[ATTRIBUTE].GetString()); + if (tempAttrib.vertexAttrib < 0) + continue; + + meshdata->attribs.push_back(tempAttrib); } + meshdata->attribCount = (int)meshdata->attribs.size(); // vertices const rapidjson::Value& mesh_data_vertex = mesh_array_0[VERTEX]; @@ -1152,7 +1177,6 @@ bool Bundle3D::loadMeshDataJson_0_2(MeshDatas& meshdatas) for (rapidjson::SizeType i = 0; i < mesh_submesh_array.Size(); i++) { const rapidjson::Value& mesh_submesh_val = mesh_submesh_array[i]; - //std::string id = mesh_submesh_val[ID].GetString(); // index_number unsigned int indexnum = mesh_submesh_val[INDEXNUM].GetUint(); @@ -1927,7 +1951,7 @@ NTextureData::Usage Bundle3D::parseGLTextureType(const std::string& str) return NTextureData::Usage::Unknown; } } -unsigned int Bundle3D::parseGLProgramAttribute(const std::string& str) +int Bundle3D::parseGLProgramAttribute(const std::string& str) { if (str == "VERTEX_ATTRIB_POSITION") { @@ -1984,7 +2008,7 @@ unsigned int Bundle3D::parseGLProgramAttribute(const std::string& str) } else { - CCASSERT(false, "Wrong Attribute type"); + CCLOG("warning: can not parse the attribute type:'%s'", str.c_str()); return -1; } } @@ -2023,14 +2047,14 @@ Reference* Bundle3D::seekToFirstType(unsigned int type, const std::string& id) } Bundle3D::Bundle3D() - : _modelPath(""), - _path(""), - _version(""), - _jsonBuffer(nullptr), - _binaryBuffer(nullptr), - _referenceCount(0), - _references(nullptr), - _isBinary(false) +: _modelPath(""), +_path(""), +_version(""), +_jsonBuffer(nullptr), +_binaryBuffer(nullptr), +_referenceCount(0), +_references(nullptr), +_isBinary(false) { } diff --git a/cocos/3d/CCBundle3D.h b/cocos/3d/CCBundle3D.h index 571a58ffa2..d066de5496 100644 --- a/cocos/3d/CCBundle3D.h +++ b/cocos/3d/CCBundle3D.h @@ -136,7 +136,7 @@ protected: * get vertex attribute type * @param str The type in string */ - unsigned int parseGLProgramAttribute(const std::string& str); + int parseGLProgramAttribute(const std::string& str); /* * get model path From ee03bb8eeaba0ebaf63fed7c8d926d9ff4f30c5f Mon Sep 17 00:00:00 2001 From: lvlong Date: Thu, 12 Feb 2015 09:24:04 +0800 Subject: [PATCH 5/8] setCameraMask for cocostudio-ui --- cocos/2d/CCNode.h | 2 +- cocos/2d/CCProtectedNode.cpp | 13 +++++++++++++ cocos/2d/CCProtectedNode.h | 1 + cocos/ui/UIScale9Sprite.cpp | 13 +++++++++++++ cocos/ui/UIScale9Sprite.h | 1 + 5 files changed, 29 insertions(+), 1 deletion(-) diff --git a/cocos/2d/CCNode.h b/cocos/2d/CCNode.h index 89f8d8da82..2f1cc05e49 100644 --- a/cocos/2d/CCNode.h +++ b/cocos/2d/CCNode.h @@ -1575,7 +1575,7 @@ public: /** get & set camera mask, the node is visible by the camera whose camera flag & node's camera mask is true */ unsigned short getCameraMask() const { return _cameraMask; } - void setCameraMask(unsigned short mask, bool applyChildren = true); + virtual void setCameraMask(unsigned short mask, bool applyChildren = true); CC_CONSTRUCTOR_ACCESS: // Nodes should be created using create(); diff --git a/cocos/2d/CCProtectedNode.cpp b/cocos/2d/CCProtectedNode.cpp index b5f078a394..3acb2cd79a 100644 --- a/cocos/2d/CCProtectedNode.cpp +++ b/cocos/2d/CCProtectedNode.cpp @@ -431,4 +431,17 @@ void ProtectedNode::disableCascadeOpacity() } } +void ProtectedNode::setCameraMask(unsigned short mask, bool applyChildren) +{ + Node::setCameraMask(mask, applyChildren); + if (applyChildren) + { + for (auto& iter: _protectedChildren) + { + iter->setCameraMask(mask); + } + } + +} + NS_CC_END diff --git a/cocos/2d/CCProtectedNode.h b/cocos/2d/CCProtectedNode.h index dff7fae398..6d9bc816de 100644 --- a/cocos/2d/CCProtectedNode.h +++ b/cocos/2d/CCProtectedNode.h @@ -163,6 +163,7 @@ public: virtual void updateDisplayedColor(const Color3B& parentColor) override; virtual void disableCascadeColor() override; virtual void disableCascadeOpacity()override; + virtual void setCameraMask(unsigned short mask, bool applyChildren = true) override; CC_CONSTRUCTOR_ACCESS: ProtectedNode(); virtual ~ProtectedNode(); diff --git a/cocos/ui/UIScale9Sprite.cpp b/cocos/ui/UIScale9Sprite.cpp index 2eb24bca17..32562578aa 100644 --- a/cocos/ui/UIScale9Sprite.cpp +++ b/cocos/ui/UIScale9Sprite.cpp @@ -1335,4 +1335,17 @@ namespace ui { return this->getScaleX(); } + void Scale9Sprite::setCameraMask(unsigned short mask, bool applyChildren) + { + Node::setCameraMask(mask, applyChildren); + + if(_scale9Image) + _scale9Image->setCameraMask(mask,applyChildren); + + for(auto& iter: _protectedChildren) + { + iter->setCameraMask(mask); + } + } + }} diff --git a/cocos/ui/UIScale9Sprite.h b/cocos/ui/UIScale9Sprite.h index c0f0bc2bdf..2fd95c0e93 100644 --- a/cocos/ui/UIScale9Sprite.h +++ b/cocos/ui/UIScale9Sprite.h @@ -376,6 +376,7 @@ namespace ui { virtual float getScaleY() const override; virtual float getScale() const override; using Node::getScaleZ; + virtual void setCameraMask(unsigned short mask, bool applyChildren = true) override; protected: void updateCapInset(); void updatePositions(); From 7437bfad15638672ddda0d27a513b38d2ca1dc75 Mon Sep 17 00:00:00 2001 From: lvlong Date: Wed, 25 Feb 2015 10:33:16 +0800 Subject: [PATCH 6/8] recover bundle3D. --- cocos/3d/CCBundle3D.cpp | 114 ++++++++++++++++------------------------ cocos/3d/CCBundle3D.h | 2 +- 2 files changed, 46 insertions(+), 70 deletions(-) diff --git a/cocos/3d/CCBundle3D.cpp b/cocos/3d/CCBundle3D.cpp index d4dd1b4c00..bb8879e41c 100644 --- a/cocos/3d/CCBundle3D.cpp +++ b/cocos/3d/CCBundle3D.cpp @@ -375,39 +375,31 @@ bool Bundle3D::loadMeshDatasBinary(MeshDatas& meshdatas) for(int i = 0; i < meshSize ; i++ ) { MeshData* meshData = new (std::nothrow) MeshData(); - unsigned int attribSize=0; + unsigned int attribSize=0; // read mesh data if (_binaryReader.read(&attribSize, 4, 1) != 1 || attribSize < 1) { CCLOG("warning: Failed to read meshdata: attribCount '%s'.", _path.c_str()); return false; } - - for (ssize_t j = 0; j < attribSize; j++) + meshData->attribCount = attribSize; + meshData->attribs.resize(meshData->attribCount); + for (ssize_t j = 0; j < meshData->attribCount; j++) { + std::string attribute=""; unsigned int vSize; if (_binaryReader.read(&vSize, 4, 1) != 1) { CCLOG("warning: Failed to read meshdata: usage or size '%s'.", _path.c_str()); return false; } - - MeshVertexAttrib attrib; std::string type = _binaryReader.readString(); - std::string attribute = _binaryReader.readString(); - attrib.size = vSize; - attrib.attribSizeBytes = attrib.size * 4; - attrib.type = parseGLType(type); - - // check whether the vertex-attribute is valide - attrib.vertexAttrib = parseGLProgramAttribute(attribute); - if (attrib.vertexAttrib < 0) - continue; - - meshData->attribs.push_back(attrib); + attribute=_binaryReader.readString(); + meshData->attribs[j].size = vSize; + meshData->attribs[j].attribSizeBytes = meshData->attribs[j].size * 4; + meshData->attribs[j].type = parseGLType(type); + meshData->attribs[j].vertexAttrib = parseGLProgramAttribute(attribute); } - meshData->attribCount = (int)meshData->attribs.size(); - unsigned int vertexSizeInFloat = 0; // Read vertex data if (_binaryReader.read(&vertexSizeInFloat, 4, 1) != 1 || vertexSizeInFloat == 0) @@ -700,11 +692,13 @@ bool Bundle3D::loadMeshDatasJson(MeshDatas& meshdatas) const rapidjson::Value& mesh_data = mesh_data_array[index]; // mesh_vertex_attribute const rapidjson::Value& mesh_vertex_attribute = mesh_data[ATTRIBUTES]; - unsigned int attributeCount = mesh_vertex_attribute.Size(); - for (int i = 0; i < attributeCount; i++) + MeshVertexAttrib tempAttrib; + meshData->attribCount=mesh_vertex_attribute.Size(); + meshData->attribs.resize(meshData->attribCount); + for (int i = 0; i < mesh_vertex_attribute.Size(); i++) { - MeshVertexAttrib tempAttrib; const rapidjson::Value& mesh_vertex_attribute_val = mesh_vertex_attribute[i]; + int size = mesh_vertex_attribute_val[ATTRIBUTESIZE].GetInt(); std::string type = mesh_vertex_attribute_val[TYPE].GetString(); std::string attribute = mesh_vertex_attribute_val[ATTRIBUTE].GetString(); @@ -712,16 +706,9 @@ bool Bundle3D::loadMeshDatasJson(MeshDatas& meshdatas) tempAttrib.size = size; tempAttrib.attribSizeBytes = sizeof(float) * size; tempAttrib.type = parseGLType(type); - - // check whether the vertex-attribute is valide tempAttrib.vertexAttrib = parseGLProgramAttribute(attribute); - if (tempAttrib.vertexAttrib < 0) - continue; - - meshData->attribs.push_back(tempAttrib); + meshData->attribs[i]=tempAttrib; } - meshData->attribCount = (int)meshData->attribs.size(); - // mesh vertices //////////////////////////////////////////////////////////////////////////////////////////////// const rapidjson::Value& mesh_data_vertex_array = mesh_data[VERTICES]; @@ -1092,23 +1079,17 @@ bool Bundle3D::loadMeshDataJson_0_1(MeshDatas& meshdatas) // mesh_vertex_attribute const rapidjson::Value& mesh_vertex_attribute = mesh_data_val[ATTRIBUTES]; - unsigned int attribCount = mesh_vertex_attribute.Size(); - for (rapidjson::SizeType i = 0; i < attribCount; i++) + meshdata->attribCount = mesh_vertex_attribute.Size(); + meshdata->attribs.resize(meshdata->attribCount); + for (rapidjson::SizeType i = 0; i < mesh_vertex_attribute.Size(); i++) { const rapidjson::Value& mesh_vertex_attribute_val = mesh_vertex_attribute[i]; - MeshVertexAttrib tempAttrib; - tempAttrib.size = mesh_vertex_attribute_val[ATTRIBUTESIZE].GetUint(); - tempAttrib.attribSizeBytes = tempAttrib.size * 4; - tempAttrib.type = parseGLType(mesh_vertex_attribute_val[TYPE].GetString()); - - // check whether the vertex-attribute is valide - tempAttrib.vertexAttrib = parseGLProgramAttribute(mesh_vertex_attribute_val[ATTRIBUTE].GetString()); - if (tempAttrib.vertexAttrib < 0) - continue; - - meshdata->attribs.push_back(tempAttrib); + + meshdata->attribs[i].size = mesh_vertex_attribute_val[ATTRIBUTESIZE].GetUint(); + meshdata->attribs[i].attribSizeBytes = meshdata->attribs[i].size * 4; + meshdata->attribs[i].type = parseGLType(mesh_vertex_attribute_val[TYPE].GetString()); + meshdata->attribs[i].vertexAttrib = parseGLProgramAttribute(mesh_vertex_attribute_val[ATTRIBUTE].GetString()); } - meshdata->attribCount = (int)meshdata->attribs.size(); // vertices meshdata->vertexSizeInFloat = mesh_data_body_array_0[VERTEXSIZE].GetInt(); @@ -1143,23 +1124,17 @@ bool Bundle3D::loadMeshDataJson_0_2(MeshDatas& meshdatas) // mesh_vertex_attribute const rapidjson::Value& mesh_vertex_attribute = mesh_array_0[ATTRIBUTES]; - unsigned int attribCount = mesh_vertex_attribute.Size(); - for (rapidjson::SizeType i = 0; i < attribCount; i++) + meshdata->attribCount = mesh_vertex_attribute.Size(); + meshdata->attribs.resize(meshdata->attribCount); + for (rapidjson::SizeType i = 0; i < mesh_vertex_attribute.Size(); i++) { const rapidjson::Value& mesh_vertex_attribute_val = mesh_vertex_attribute[i]; - MeshVertexAttrib tempAttrib; - tempAttrib.size = mesh_vertex_attribute_val[ATTRIBUTESIZE].GetUint(); - tempAttrib.attribSizeBytes = tempAttrib.size * 4; - tempAttrib.type = parseGLType(mesh_vertex_attribute_val[TYPE].GetString()); - - // check whether the vertex-attribute is valide - tempAttrib.vertexAttrib = parseGLProgramAttribute(mesh_vertex_attribute_val[ATTRIBUTE].GetString()); - if (tempAttrib.vertexAttrib < 0) - continue; - - meshdata->attribs.push_back(tempAttrib); + + meshdata->attribs[i].size = mesh_vertex_attribute_val[ATTRIBUTESIZE].GetUint(); + meshdata->attribs[i].attribSizeBytes = meshdata->attribs[i].size * 4; + meshdata->attribs[i].type = parseGLType(mesh_vertex_attribute_val[TYPE].GetString()); + meshdata->attribs[i].vertexAttrib = parseGLProgramAttribute(mesh_vertex_attribute_val[ATTRIBUTE].GetString()); } - meshdata->attribCount = (int)meshdata->attribs.size(); // vertices const rapidjson::Value& mesh_data_vertex = mesh_array_0[VERTEX]; @@ -1177,6 +1152,7 @@ bool Bundle3D::loadMeshDataJson_0_2(MeshDatas& meshdatas) for (rapidjson::SizeType i = 0; i < mesh_submesh_array.Size(); i++) { const rapidjson::Value& mesh_submesh_val = mesh_submesh_array[i]; + //std::string id = mesh_submesh_val[ID].GetString(); // index_number unsigned int indexnum = mesh_submesh_val[INDEXNUM].GetUint(); @@ -1821,7 +1797,7 @@ NodeData* Bundle3D::parseNodesRecursivelyBinary(bool& skeleton) CCLOG("warning: Failed to read nodedata: uvMapping '%s'.", _path.c_str()); return nullptr; } - for(int j = 0 ; j < uvMapping ; j++) + for( int j = 0 ;j < uvMapping ; j++ ) { unsigned int textureIndexSize=0; if (_binaryReader.read(&textureIndexSize, 4, 1) != 1) @@ -1829,7 +1805,7 @@ NodeData* Bundle3D::parseNodesRecursivelyBinary(bool& skeleton) CCLOG("warning: Failed to read meshdata: attribCount '%s'.", _path.c_str()); return nullptr; } - for(unsigned int k = 0; k < textureIndexSize ; k++) + for(int k =0; k < textureIndexSize ; k++ ) { unsigned int index=0; if (_binaryReader.read(&index, 4, 1) != 1) @@ -1951,7 +1927,7 @@ NTextureData::Usage Bundle3D::parseGLTextureType(const std::string& str) return NTextureData::Usage::Unknown; } } -int Bundle3D::parseGLProgramAttribute(const std::string& str) +unsigned int Bundle3D::parseGLProgramAttribute(const std::string& str) { if (str == "VERTEX_ATTRIB_POSITION") { @@ -2008,7 +1984,7 @@ int Bundle3D::parseGLProgramAttribute(const std::string& str) } else { - CCLOG("warning: can not parse the attribute type:'%s'", str.c_str()); + CCASSERT(false, "Wrong Attribute type"); return -1; } } @@ -2047,14 +2023,14 @@ Reference* Bundle3D::seekToFirstType(unsigned int type, const std::string& id) } Bundle3D::Bundle3D() -: _modelPath(""), -_path(""), -_version(""), -_jsonBuffer(nullptr), -_binaryBuffer(nullptr), -_referenceCount(0), -_references(nullptr), -_isBinary(false) + : _modelPath(""), + _path(""), + _version(""), + _jsonBuffer(nullptr), + _binaryBuffer(nullptr), + _referenceCount(0), + _references(nullptr), + _isBinary(false) { } diff --git a/cocos/3d/CCBundle3D.h b/cocos/3d/CCBundle3D.h index d066de5496..571a58ffa2 100644 --- a/cocos/3d/CCBundle3D.h +++ b/cocos/3d/CCBundle3D.h @@ -136,7 +136,7 @@ protected: * get vertex attribute type * @param str The type in string */ - int parseGLProgramAttribute(const std::string& str); + unsigned int parseGLProgramAttribute(const std::string& str); /* * get model path From 2d89ee34eff25c6bf843f90891ba3f81a0f1b2c0 Mon Sep 17 00:00:00 2001 From: lvlong Date: Wed, 25 Feb 2015 10:54:49 +0800 Subject: [PATCH 7/8] recover bundle3d --- cocos/3d/CCBundle3D.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cocos/3d/CCBundle3D.cpp b/cocos/3d/CCBundle3D.cpp index bb8879e41c..d2d16ece57 100644 --- a/cocos/3d/CCBundle3D.cpp +++ b/cocos/3d/CCBundle3D.cpp @@ -1797,7 +1797,7 @@ NodeData* Bundle3D::parseNodesRecursivelyBinary(bool& skeleton) CCLOG("warning: Failed to read nodedata: uvMapping '%s'.", _path.c_str()); return nullptr; } - for( int j = 0 ;j < uvMapping ; j++ ) + for(int j = 0 ;j < uvMapping ; j++ ) { unsigned int textureIndexSize=0; if (_binaryReader.read(&textureIndexSize, 4, 1) != 1) @@ -1805,7 +1805,7 @@ NodeData* Bundle3D::parseNodesRecursivelyBinary(bool& skeleton) CCLOG("warning: Failed to read meshdata: attribCount '%s'.", _path.c_str()); return nullptr; } - for(int k =0; k < textureIndexSize ; k++ ) + for(unsigned int k = 0; k < textureIndexSize ; k++) { unsigned int index=0; if (_binaryReader.read(&index, 4, 1) != 1) From ac5d34b93d5e5f20b780614e521a64c198be1621 Mon Sep 17 00:00:00 2001 From: lvlong Date: Wed, 25 Feb 2015 10:56:01 +0800 Subject: [PATCH 8/8] recover bundle3d --- cocos/3d/CCBundle3D.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/3d/CCBundle3D.cpp b/cocos/3d/CCBundle3D.cpp index d2d16ece57..b430d55e45 100644 --- a/cocos/3d/CCBundle3D.cpp +++ b/cocos/3d/CCBundle3D.cpp @@ -1797,7 +1797,7 @@ NodeData* Bundle3D::parseNodesRecursivelyBinary(bool& skeleton) CCLOG("warning: Failed to read nodedata: uvMapping '%s'.", _path.c_str()); return nullptr; } - for(int j = 0 ;j < uvMapping ; j++ ) + for(int j = 0 ; j < uvMapping ; j++) { unsigned int textureIndexSize=0; if (_binaryReader.read(&textureIndexSize, 4, 1) != 1)