Skip to content

Commit

Permalink
Merge pull request cocos2d#12818 from zilongshanren/v3
Browse files Browse the repository at this point in the history
merge v3.7 back to v3
  • Loading branch information
zilongshanren committed Jul 14, 2015
2 parents 69a7001 + ef5d4dd commit e1ae363
Show file tree
Hide file tree
Showing 49 changed files with 1,397 additions and 911 deletions.
16 changes: 16 additions & 0 deletions build/cocos2d_tests.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,10 @@
688669711AE8E8B500C2CFD9 /* SpritePolygonTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6886696F1AE8E8B500C2CFD9 /* SpritePolygonTest.cpp */; };
688669721AE8E8B500C2CFD9 /* SpritePolygonTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6886696F1AE8E8B500C2CFD9 /* SpritePolygonTest.cpp */; };
826294431AAF071500CB7CF7 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 826294421AAF071500CB7CF7 /* Security.framework */; };
94D793D91B4B7A3600F60F10 /* Bug-CCDrawNode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 94D793D51B4B7A3600F60F10 /* Bug-CCDrawNode.cpp */; };
94D793DA1B4B7A3600F60F10 /* Bug-CCDrawNode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 94D793D51B4B7A3600F60F10 /* Bug-CCDrawNode.cpp */; };
94D793DB1B4B7A3600F60F10 /* Bug-PageViewLayout.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 94D793D71B4B7A3600F60F10 /* Bug-PageViewLayout.cpp */; };
94D793DC1B4B7A3600F60F10 /* Bug-PageViewLayout.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 94D793D71B4B7A3600F60F10 /* Bug-PageViewLayout.cpp */; };
A05FCACA177C124500BE600E /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 15C64822165F391E007D4F18 /* Cocoa.framework */; };
A07A521E1783A1D20073F6A7 /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 15C6482E165F399D007D4F18 /* libz.dylib */; };
A07A521F1783A1D20073F6A7 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 15C64832165F3AFD007D4F18 /* Foundation.framework */; };
Expand Down Expand Up @@ -1945,6 +1949,10 @@
70A7F72D191D3E4900F0F206 /* shaderTest.psh.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = shaderTest.psh.h; sourceTree = "<group>"; };
70A7F730191D421B00F0F206 /* ShaderTest.vsh.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ShaderTest.vsh.h; sourceTree = "<group>"; };
826294421AAF071500CB7CF7 /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = System/Library/Frameworks/Security.framework; sourceTree = SDKROOT; };
94D793D51B4B7A3600F60F10 /* Bug-CCDrawNode.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = "Bug-CCDrawNode.cpp"; sourceTree = "<group>"; };
94D793D61B4B7A3600F60F10 /* Bug-CCDrawNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "Bug-CCDrawNode.h"; sourceTree = "<group>"; };
94D793D71B4B7A3600F60F10 /* Bug-PageViewLayout.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = "Bug-PageViewLayout.cpp"; sourceTree = "<group>"; };
94D793D81B4B7A3600F60F10 /* Bug-PageViewLayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "Bug-PageViewLayout.h"; sourceTree = "<group>"; };
A035A71117822E9E00987F6C /* libsqlite3.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libsqlite3.dylib; path = usr/lib/libsqlite3.dylib; sourceTree = SDKROOT; };
A07A52291783A1D20073F6A7 /* cpp-tests iOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "cpp-tests iOS.app"; sourceTree = BUILT_PRODUCTS_DIR; };
A07A52B71783AE6D0073F6A7 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/System/Library/Frameworks/UIKit.framework; sourceTree = DEVELOPER_DIR; };
Expand Down Expand Up @@ -2733,6 +2741,10 @@
1AC3597618CECF0B00F37B72 /* BugsTest */ = {
isa = PBXGroup;
children = (
94D793D51B4B7A3600F60F10 /* Bug-CCDrawNode.cpp */,
94D793D61B4B7A3600F60F10 /* Bug-CCDrawNode.h */,
94D793D71B4B7A3600F60F10 /* Bug-PageViewLayout.cpp */,
94D793D81B4B7A3600F60F10 /* Bug-PageViewLayout.h */,
1AC3597718CECF0B00F37B72 /* Bug-1159.cpp */,
1AC3597818CECF0B00F37B72 /* Bug-1159.h */,
1AC3597918CECF0B00F37B72 /* Bug-1174.cpp */,
Expand Down Expand Up @@ -5388,6 +5400,7 @@
1AC35BEB18CECF0C00F37B72 /* CCControlSliderTest.cpp in Sources */,
1AC35C4D18CECF0C00F37B72 /* SpineTest.cpp in Sources */,
3E92EA821921A1400094CD21 /* Sprite3DTest.cpp in Sources */,
94D793DB1B4B7A3600F60F10 /* Bug-PageViewLayout.cpp in Sources */,
1AC35C1D18CECF0C00F37B72 /* NewRendererTest.cpp in Sources */,
1AC35B6718CECF0C00F37B72 /* AnimationsTestLayer.cpp in Sources */,
29080DB7191B595E0066F8DF /* UIListViewTest_Editor.cpp in Sources */,
Expand Down Expand Up @@ -5533,6 +5546,7 @@
1AC35B2518CECF0C00F37B72 /* ActionsProgressTest.cpp in Sources */,
1AC35B6518CECF0C00F37B72 /* EffectsTest.cpp in Sources */,
1AC35B7118CECF0C00F37B72 /* TestHeaderLayer.cpp in Sources */,
94D793D91B4B7A3600F60F10 /* Bug-CCDrawNode.cpp in Sources */,
29080D93191B595E0066F8DF /* CustomImageTest.cpp in Sources */,
1AC35B2118CECF0C00F37B72 /* ActionManagerTest.cpp in Sources */,
1AC35C3D18CECF0C00F37B72 /* PhysicsTest.cpp in Sources */,
Expand Down Expand Up @@ -5673,6 +5687,7 @@
1AC35B2818CECF0C00F37B72 /* ActionsTest.cpp in Sources */,
1AC35C4A18CECF0C00F37B72 /* ShaderTest.cpp in Sources */,
B609E67419C18DAD003D0074 /* BillBoardTest.cpp in Sources */,
94D793DC1B4B7A3600F60F10 /* Bug-PageViewLayout.cpp in Sources */,
C04F935B1941B05400E9FEAB /* TileMapTest2.cpp in Sources */,
1AC35B4418CECF0C00F37B72 /* Bug-624.cpp in Sources */,
1AC35BF818CECF0C00F37B72 /* SocketIOTest.cpp in Sources */,
Expand Down Expand Up @@ -5781,6 +5796,7 @@
1AC35BEA18CECF0C00F37B72 /* CCControlSceneManager.cpp in Sources */,
182C5CBB1A95B30500C30D34 /* CocosStudio3DTest.cpp in Sources */,
1AC35B7418CECF0C00F37B72 /* TimelineCallbackTestLayer.cpp in Sources */,
94D793DA1B4B7A3600F60F10 /* Bug-CCDrawNode.cpp in Sources */,
29080D9E191B595E0066F8DF /* CustomParticleWidgetReader.cpp in Sources */,
1AC35BFC18CECF0C00F37B72 /* NotificationCenterTest.cpp in Sources */,
29FBBBFF196A9ECD00E65826 /* CocostudioParserJsonTest.cpp in Sources */,
Expand Down
8 changes: 6 additions & 2 deletions cocos/2d/CCDrawNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,9 @@ void DrawNode::onDrawGLLine(const Mat4 &transform, uint32_t flags)
auto glProgram = GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_NAME_POSITION_LENGTH_TEXTURE_COLOR);
glProgram->use();
glProgram->setUniformsForBuiltins(transform);


GL::blendFunc(_blendFunc.src, _blendFunc.dst);

if (_dirtyGLLine)
{
glBindBuffer(GL_ARRAY_BUFFER, _vboGLLine);
Expand Down Expand Up @@ -415,7 +417,9 @@ void DrawNode::onDrawGLPoint(const Mat4 &transform, uint32_t flags)
auto glProgram = GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_NAME_POSITION_COLOR_TEXASPOINTSIZE);
glProgram->use();
glProgram->setUniformsForBuiltins(transform);


GL::blendFunc(_blendFunc.src, _blendFunc.dst);

if (_dirtyGLPoint)
{
glBindBuffer(GL_ARRAY_BUFFER, _vboGLPoint);
Expand Down
14 changes: 1 addition & 13 deletions cocos/2d/CCLabel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -782,19 +782,7 @@ void Label::updateQuads()
_reusedRect.size.width = letterDef.width;
_reusedRect.origin.x = letterDef.U;
_reusedRect.origin.y = letterDef.V;
if (_labelHeight > 0.f)
{
if (_lettersInfo[ctr].position.y > _contentSize.height)
{
auto clipTop = _lettersInfo[ctr].position.y - _contentSize.height;
_reusedRect.origin.y += clipTop;
_lettersInfo[ctr].position.y -= clipTop;
}
if (_lettersInfo[ctr].position.y - letterDef.height < 0.f)
{
_reusedRect.size.height = _lettersInfo[ctr].position.y < 0.f ? 0.f : _lettersInfo[ctr].position.y;
}
}

_reusedLetter->setTextureRect(_reusedRect,false,_reusedRect.size);

_reusedLetter->setPosition(_lettersInfo[ctr].position);
Expand Down
4 changes: 2 additions & 2 deletions cocos/2d/CCLabelTextFormatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ bool LabelTextFormatter::createStringSprites(Label *theLabel)
auto labelHeightPixel = theLabel->_labelHeight * contentScaleFactor;
if (totalHeight > labelHeightPixel)
{
int numLines = MIN(ceil(labelHeightPixel / theLabel->_commonLineHeight), theLabel->_currNumLines);
int numLines = labelHeightPixel / theLabel->_commonLineHeight;
totalHeight = numLines * theLabel->_commonLineHeight;
}
switch (theLabel->_vAlignment)
Expand Down Expand Up @@ -379,7 +379,7 @@ bool LabelTextFormatter::createStringSprites(Label *theLabel)
nextFontPositionY -= theLabel->_commonLineHeight;

theLabel->recordPlaceholderInfo(i);
if(nextFontPositionY < 0.f)
if (nextFontPositionY < theLabel->_commonLineHeight)
break;

lineStart = true;
Expand Down
2 changes: 1 addition & 1 deletion cocos/2d/CCTMXXMLParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ void TMXMapInfo::startElement(void *ctx, const char *name, const char **atts)
// Y
int y = attributeDict["y"].asInt();

Vec2 p(x + objectGroup->getPositionOffset().x, _mapSize.height * _tileSize.height - y - objectGroup->getPositionOffset().x - attributeDict["height"].asInt());
Vec2 p(x + objectGroup->getPositionOffset().x, _mapSize.height * _tileSize.height - y - objectGroup->getPositionOffset().y - attributeDict["height"].asInt());
p = CC_POINT_PIXELS_TO_POINTS(p);
dict["x"] = Value(p.x);
dict["y"] = Value(p.y);
Expand Down
151 changes: 87 additions & 64 deletions cocos/3d/CCBundle3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,93 +216,116 @@ bool Bundle3D::loadObj(MeshDatas& meshdatas, MaterialDatas& materialdatas, NodeD
else
mtlPath = fullPath.substr(0, fullPath.find_last_of("\\/") + 1).c_str();

ObjLoader::shapes_t shapes;
auto ret = ObjLoader::LoadObj(shapes, fullPath.c_str(), mtlPath.c_str());
std::vector<tinyobj::shape_t> shapes;
std::vector<tinyobj::material_t> materials;
auto ret = tinyobj::LoadObj(shapes, materials, fullPath.c_str(), mtlPath.c_str());
if (ret.empty())
{
//fill data
MeshData* meshdata = new (std::nothrow) MeshData();
MeshVertexAttrib attrib;
attrib.size = 3;
attrib.type = GL_FLOAT;
if (shapes.positions.size())
{
attrib.vertexAttrib = GLProgram::VERTEX_ATTRIB_POSITION;
attrib.attribSizeBytes = attrib.size * sizeof(float);
meshdata->attribs.push_back(attrib);

}
bool hasnormal = false, hastex = false;
if (shapes.normals.size())
{
hasnormal = true;
attrib.vertexAttrib = GLProgram::VERTEX_ATTRIB_NORMAL;
attrib.attribSizeBytes = attrib.size * sizeof(float);;
meshdata->attribs.push_back(attrib);
}
if (shapes.texcoords.size())
{
hastex = true;
attrib.size = 2;
attrib.vertexAttrib = GLProgram::VERTEX_ATTRIB_TEX_COORD;
attrib.attribSizeBytes = attrib.size * sizeof(float);
meshdata->attribs.push_back(attrib);
}
auto vertexNum = shapes.positions.size() / 3;
for(unsigned int i = 0; i < vertexNum; i++)
{
meshdata->vertex.push_back(shapes.positions[i * 3]);
meshdata->vertex.push_back(shapes.positions[i * 3 + 1]);
meshdata->vertex.push_back(shapes.positions[i * 3 + 2]);

if (hasnormal)
{
meshdata->vertex.push_back(shapes.normals[i * 3]);
meshdata->vertex.push_back(shapes.normals[i * 3 + 1]);
meshdata->vertex.push_back(shapes.normals[i * 3 + 2]);
}

if (hastex)
{
meshdata->vertex.push_back(shapes.texcoords[i * 2]);
meshdata->vertex.push_back(shapes.texcoords[i * 2 + 1]);
}
}
meshdatas.meshDatas.push_back(meshdata);

//convert material
int i = 0;
char str[20];
std::string dir = "";
auto last = fullPath.rfind("/");
if (last != -1)
dir = fullPath.substr(0, last + 1);

for (const auto& it : shapes.shapes)
{
for (auto& material : materials) {
NMaterialData materialdata;

NTextureData tex;
tex.filename = it.material.diffuse_texname.empty() ? it.material.diffuse_texname : dir + it.material.diffuse_texname;
tex.filename = material.diffuse_texname.empty() ? material.diffuse_texname : dir + material.diffuse_texname;
tex.type = NTextureData::Usage::Diffuse;
tex.wrapS = GL_CLAMP_TO_EDGE;
tex.wrapT = GL_CLAMP_TO_EDGE;

sprintf(str, "%d", i++);
materialdata.textures.push_back(tex);
materialdata.id = str;
material.name = str;
materialdatas.materials.push_back(materialdata);

meshdata->subMeshIndices.push_back(it.mesh.indices);
meshdata->subMeshAABB.push_back(calculateAABB(meshdata->vertex, meshdata->getPerVertexSize(), it.mesh.indices));
meshdata->subMeshIds.push_back(str);
}

//convert mesh
i = 0;
for (auto& shape : shapes) {
auto mesh = shape.mesh;
MeshData* meshdata = new (std::nothrow) MeshData();
MeshVertexAttrib attrib;
attrib.size = 3;
attrib.type = GL_FLOAT;

if (mesh.positions.size())
{
attrib.vertexAttrib = GLProgram::VERTEX_ATTRIB_POSITION;
attrib.attribSizeBytes = attrib.size * sizeof(float);
meshdata->attribs.push_back(attrib);

}
bool hasnormal = false, hastex = false;
if (mesh.normals.size())
{
hasnormal = true;
attrib.vertexAttrib = GLProgram::VERTEX_ATTRIB_NORMAL;
attrib.attribSizeBytes = attrib.size * sizeof(float);;
meshdata->attribs.push_back(attrib);
}
if (mesh.texcoords.size())
{
hastex = true;
attrib.size = 2;
attrib.vertexAttrib = GLProgram::VERTEX_ATTRIB_TEX_COORD;
attrib.attribSizeBytes = attrib.size * sizeof(float);
meshdata->attribs.push_back(attrib);
}

auto vertexNum = mesh.positions.size() / 3;
for(unsigned int k = 0; k < vertexNum; k++)
{
meshdata->vertex.push_back(mesh.positions[k * 3]);
meshdata->vertex.push_back(mesh.positions[k * 3 + 1]);
meshdata->vertex.push_back(mesh.positions[k * 3 + 2]);

if (hasnormal)
{
meshdata->vertex.push_back(mesh.normals[k * 3]);
meshdata->vertex.push_back(mesh.normals[k * 3 + 1]);
meshdata->vertex.push_back(mesh.normals[k * 3 + 2]);
}

if (hastex)
{
meshdata->vertex.push_back(mesh.texcoords[k * 2]);
meshdata->vertex.push_back(mesh.texcoords[k * 2 + 1]);
}
}

//split into submesh according to material
std::map<int, std::vector<unsigned short> > subMeshMap;
for (size_t k = 0; k < mesh.material_ids.size(); k++) {
int id = mesh.material_ids[k];
size_t idx = k * 3;
subMeshMap[id].push_back(mesh.indices[idx]);
subMeshMap[id].push_back(mesh.indices[idx + 1]);
subMeshMap[id].push_back(mesh.indices[idx + 2]);
}

auto node = new (std::nothrow) NodeData();
auto modelnode = new (std::nothrow) ModelData();
modelnode->matrialId = str;
modelnode->subMeshId = str;
node->id = it.name;
node->modelNodeDatas.push_back(modelnode);
node->id = shape.name;
for (auto& submesh : subMeshMap) {
meshdata->subMeshIndices.push_back(submesh.second);
meshdata->subMeshAABB.push_back(calculateAABB(meshdata->vertex, meshdata->getPerVertexSize(), submesh.second));
sprintf(str, "%d", i++);
meshdata->subMeshIds.push_back(str);

auto modelnode = new (std::nothrow) ModelData();
modelnode->matrialId = submesh.first == -1 ? "" : materials[submesh.first].name;
modelnode->subMeshId = str;
node->modelNodeDatas.push_back(modelnode);
}
nodedatas.nodes.push_back(node);
meshdatas.meshDatas.push_back(meshdata);
}

return true;
}
CCLOG("warning: load %s file error: %s", fullPath.c_str(), ret.c_str());
Expand Down
3 changes: 3 additions & 0 deletions cocos/3d/CCMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@ void Mesh::setTexture(Texture2D* tex)
// Texture must be saved for future use
// it doesn't matter if the material is already set or not
// This functionality is added for compatibility issues
if (tex == nullptr)
tex = getDummyTexture();

if (tex != _texture)
{
CC_SAFE_RETAIN(tex);
Expand Down
Loading

0 comments on commit e1ae363

Please sign in to comment.