This commit is contained in:
kaile.yin 2014-12-09 13:33:39 +08:00
commit cb509aa69f
13 changed files with 217 additions and 88 deletions

View File

@ -1,3 +1,8 @@
cocos2d-x-3.3 Dec.12
[FIX] Billboard: allow billboard rotate along z axis
[FIX] Bundle3D: create aabb for mesh whose aabb does not exist (user custom mesh)
[FIX] FileUtils: createDirectory(): doesn't invoke closedir() after opendir on platforms other than WP8/WinRT/Windows
cocos2d-x-3.3-rc2 Dec.5
[FIX] C++: use 100% of one core on Windows
[FIX] Label: when a label is added to a invisible parent node, app will crash if switching from background

View File

@ -99,14 +99,12 @@ BillBoard* BillBoard::create(Mode mode)
void BillBoard::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
{
auto camera = Camera::getVisitingCamera();
const Mat4& camWorldMat = camera->getNodeToWorldTransform();
if (memcmp(_camWorldMat.m, camWorldMat.m, sizeof(float) * 16) != 0 || memcmp(_mvTransform.m, transform.m, sizeof(float) * 16) != 0 || _modeDirty)
{
Vec3 anchorPoint(_anchorPointInPoints.x , _anchorPointInPoints.y , 0.0f);
Mat4 localToWorld = transform;
localToWorld.translate(anchorPoint);
Vec3 camDir;
switch (_mode)
{
@ -121,14 +119,20 @@ void BillBoard::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
break;
}
_modeDirty = false;
if (camDir.length() < MATH_TOLERANCE)
{
camDir.set(camWorldMat.m[8], camWorldMat.m[9], camWorldMat.m[10]);
}
camDir.normalize();
static Vec3 upAxis(0.0f, 1.0f, 0.0f);
Quaternion rotationQuaternion;
this->getNodeToWorldTransform().getRotation(&rotationQuaternion);
// fetch the rotation angle of z
float rotationZ = atan2(2*(rotationQuaternion.w*rotationQuaternion.z + rotationQuaternion.x*rotationQuaternion.y),
(1 - 2* (rotationQuaternion.y*rotationQuaternion.y + rotationQuaternion.z *rotationQuaternion.z)));
Mat4 rotationMatrix;
rotationMatrix.setIdentity();
rotationMatrix.rotateZ(rotationZ);
Vec3 upAxis = Vec3(rotationMatrix.m[4],rotationMatrix.m[5],rotationMatrix.m[6]);
Vec3 x, y;
camWorldMat.transformVector(upAxis, &y);
Vec3::cross(camDir, y, &x);

View File

@ -79,6 +79,9 @@ public:
//load .obj file
static bool loadObj(MeshDatas& meshdatas, MaterialDatas& materialdatas, NodeDatas& nodedatas, const std::string& fullPath, const char* mtl_basepath = nullptr);
//calculate aabb
static AABB calculateAABB(const std::vector<float>& vertex, int stride, const std::vector<unsigned short>& index);
protected:
@ -154,8 +157,6 @@ CC_CONSTRUCTOR_ACCESS:
Bundle3D();
virtual ~Bundle3D();
static AABB calculateAABB(const std::vector<float>& vertex, int stride, const std::vector<unsigned short>& index);
protected:
static Bundle3D* _instance;
std::string _modelPath;

View File

@ -31,6 +31,7 @@
#include "3d/CCObjLoader.h"
#include "3d/CCSprite3DMaterial.h"
#include "3d/CCMesh.h"
#include "3d/CCBundle3D.h"
#include "base/ccMacros.h"
#include "base/CCEventCustom.h"
@ -102,14 +103,22 @@ MeshVertexData* MeshVertexData::create(const MeshData& meshdata)
vertexdata->_vertexBuffer->updateVertices((void*)&meshdata.vertex[0], (int)meshdata.vertex.size() * 4 / vertexdata->_vertexBuffer->getSizePerVertex(), 0);
}
bool needCalcAABB = (meshdata.subMeshAABB.size() != meshdata.subMeshIndices.size());
for (size_t i = 0; i < meshdata.subMeshIndices.size(); i++) {
auto& index = meshdata.subMeshIndices[i];
auto indexBuffer = IndexBuffer::create(IndexBuffer::IndexType::INDEX_TYPE_SHORT_16, (int)(index.size()));
indexBuffer->updateIndices(&index[0], (int)index.size(), 0);
std::string id = (i < meshdata.subMeshIds.size() ? meshdata.subMeshIds[i] : "");
MeshIndexData* indexdata = MeshIndexData::create(id, vertexdata, indexBuffer, meshdata.subMeshAABB[i]);
MeshIndexData* indexdata = nullptr;
if (needCalcAABB)
{
auto aabb = Bundle3D::calculateAABB(meshdata.vertex, meshdata.getPerVertexSize(), index);
indexdata = MeshIndexData::create(id, vertexdata, indexBuffer, aabb);
}
else
indexdata = MeshIndexData::create(id, vertexdata, indexBuffer, meshdata.subMeshAABB[i]);
vertexdata->_indexs.pushBack(indexdata);
}

View File

@ -921,7 +921,13 @@ Offset<TimeLineTextureFrame> FlatBuffersSerialize::createTimeLineTextureFrame(co
if (attriname == "Path")
{
path = value;
std::string inFullpath = FileUtils::getInstance()->fullPathForFilename(value).c_str();
// xml read
if (!FileUtils::getInstance()->isFileExist(inFullpath))
path = "";
else
path = value;
}
else if (attriname == "Type")
{
@ -930,6 +936,17 @@ Offset<TimeLineTextureFrame> FlatBuffersSerialize::createTimeLineTextureFrame(co
else if (attriname == "Plist")
{
plistFile = value;
std::string inFullpath = FileUtils::getInstance()->fullPathForFilename(value).c_str();
// xml read
if (!FileUtils::getInstance()->isFileExist(inFullpath))
{
path = "";
plistFile = "";
}
else
plistFile = value;
}
attribute = attribute->Next();

View File

@ -609,9 +609,20 @@ namespace cocostudio
button->setBright(displaystate);
button->setEnabled(displaystate);
Size contentSize;
if (!button->isScale9Enabled())
{
button->setUnifySizeEnabled(true);
contentSize = button->getVirtualRendererSize();
}
auto widgetReader = WidgetReader::getInstance();
widgetReader->setPropsWithFlatBuffers(node, (Table*)options->widgetOptions());
if (!button->isScale9Enabled())
{
button->setContentSize(contentSize);
}
}
Node* ButtonReader::createNodeWithFlatBuffers(const flatbuffers::Table *buttonOptions)

View File

@ -41,7 +41,7 @@ THE SOFTWARE.
#endif
#include <sys/stat.h>
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT || CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
#include <regex>
#endif
@ -1102,17 +1102,28 @@ bool FileUtils::createDirectory(const std::string& path)
// Create path recursively
subpath = "";
for (int i = 0; i < dirs.size(); ++i) {
for (int i = 0; i < dirs.size(); ++i)
{
subpath += dirs[i];
dir = opendir(subpath.c_str());
if (!dir)
{
// directory doesn't exist, should create a new one
int ret = mkdir(subpath.c_str(), S_IRWXU | S_IRWXG | S_IRWXO);
if (ret != 0 && (errno != EEXIST))
{
// current directory can not be created, sub directories can not be created too
// should return
return false;
}
}
else
{
// directory exists, should close opened dir
closedir(dir);
}
}
return true;
#endif
@ -1122,8 +1133,9 @@ bool FileUtils::createDirectory(const std::string& path)
static int unlink_cb(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf)
{
auto ret = remove(fpath);
if (ret) {
log("Fail to remove:%s ",fpath);
if (ret)
{
log("Fail to remove: %s ",fpath);
}
return ret;
@ -1242,33 +1254,44 @@ bool FileUtils::renameFile(const std::string &path, const std::string &oldname,
CCASSERT(!path.empty(), "Invalid path");
std::string oldPath = path + oldname;
std::string newPath = path + name;
// Rename a file
#if (CC_TARGET_PLATFORM != CC_PLATFORM_WIN32)
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT || CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
std::regex pat("\\/");
std::string _old = std::regex_replace(oldPath, pat, "\\");
std::string _new = std::regex_replace(newPath, pat, "\\");
if (MoveFileEx(std::wstring(_old.begin(), _old.end()).c_str(),
std::wstring(_new.begin(), _new.end()).c_str(),
MOVEFILE_REPLACE_EXISTING & MOVEFILE_WRITE_THROUGH))
{
return true;
}
return false;
#elif (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
std::regex pat("\\/");
std::string _old = std::regex_replace(oldPath, pat, "\\");
std::string _new = std::regex_replace(newPath, pat, "\\");
if(FileUtils::getInstance()->isFileExist(_new))
{
DeleteFileA(_new.c_str());
}
MoveFileA(_old.c_str(), _new.c_str());
if (0 == GetLastError())
return true;
else
return false;
#else
int errorCode = rename(oldPath.c_str(), newPath.c_str());
if (0 != errorCode)
{
CCLOGERROR("Fail to rename file %s to %s !Error code is %d", oldPath.c_str(), newPath.c_str(), errorCode);
return false;
}
return true;
#else
std::regex pat("\\/");
std::string _old = std::regex_replace(oldPath, pat, "\\");
std::string _new = std::regex_replace(newPath, pat, "\\");
if(FileUtils::getInstance()->isFileExist(_new))
{
DeleteFileA(_new.c_str());
}
MoveFileA(_old.c_str(), _new.c_str());
if(0 == GetLastError())
return true;
else
return false;
#endif
}

View File

@ -51,6 +51,12 @@
-- @param self
-- @param #bool isPropagate
--------------------------------
-- return true represent the widget use Unify Size, false represent the widget couldn't use Unify Size
-- @function [parent=#Widget] isUnifySizeEnabled
-- @param self
-- @return bool#bool ret (return value: bool)
--------------------------------
-- Returns size percent of widget<br>
-- return size percent

View File

@ -1204,6 +1204,53 @@ int lua_cocos2dx_ui_Widget_setPropagateTouchEvents(lua_State* tolua_S)
return 0;
}
int lua_cocos2dx_ui_Widget_isUnifySizeEnabled(lua_State* tolua_S)
{
int argc = 0;
cocos2d::ui::Widget* cobj = nullptr;
bool ok = true;
#if COCOS2D_DEBUG >= 1
tolua_Error tolua_err;
#endif
#if COCOS2D_DEBUG >= 1
if (!tolua_isusertype(tolua_S,1,"ccui.Widget",0,&tolua_err)) goto tolua_lerror;
#endif
cobj = (cocos2d::ui::Widget*)tolua_tousertype(tolua_S,1,0);
#if COCOS2D_DEBUG >= 1
if (!cobj)
{
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_ui_Widget_isUnifySizeEnabled'", nullptr);
return 0;
}
#endif
argc = lua_gettop(tolua_S)-1;
if (argc == 0)
{
if(!ok)
{
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_ui_Widget_isUnifySizeEnabled'", nullptr);
return 0;
}
bool ret = cobj->isUnifySizeEnabled();
tolua_pushboolean(tolua_S,(bool)ret);
return 1;
}
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "ccui.Widget:isUnifySizeEnabled",argc, 0);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_ui_Widget_isUnifySizeEnabled'.",&tolua_err);
#endif
return 0;
}
int lua_cocos2dx_ui_Widget_getSizePercent(lua_State* tolua_S)
{
int argc = 0;
@ -3980,6 +4027,7 @@ int lua_register_cocos2dx_ui_Widget(lua_State* tolua_S)
tolua_function(tolua_S,"setCallbackName",lua_cocos2dx_ui_Widget_setCallbackName);
tolua_function(tolua_S,"getVirtualRenderer",lua_cocos2dx_ui_Widget_getVirtualRenderer);
tolua_function(tolua_S,"setPropagateTouchEvents",lua_cocos2dx_ui_Widget_setPropagateTouchEvents);
tolua_function(tolua_S,"isUnifySizeEnabled",lua_cocos2dx_ui_Widget_isUnifySizeEnabled);
tolua_function(tolua_S,"getSizePercent",lua_cocos2dx_ui_Widget_getSizePercent);
tolua_function(tolua_S,"setPositionPercent",lua_cocos2dx_ui_Widget_setPositionPercent);
tolua_function(tolua_S,"setSwallowTouches",lua_cocos2dx_ui_Widget_setSwallowTouches);

View File

@ -486,6 +486,7 @@ int register_all_cocos2dx_ui(lua_State* tolua_S);
#endif // __cocos2dx_ui_h__

View File

@ -619,7 +619,10 @@ public:
*@return void
*/
void setUnifySizeEnabled(bool enable);
/**
*@return true represent the widget use Unify Size, false represent the widget couldn't use Unify Size
*/
bool isUnifySizeEnabled()const;
/**
* callbackName getter and setter.
*/
@ -667,10 +670,6 @@ CC_CONSTRUCTOR_ACCESS:
*@return void
*/
void dispatchFocusEvent(Widget* widgetLoseFocus, Widget* widgetGetFocus);
/**
*@return true represent the widget use Unify Size, false represent the widget couldn't use Unify Size
*/
bool isUnifySizeEnabled()const;
protected:
//call back function called when size changed.

View File

@ -1,53 +1,54 @@
# cocos2d-x v3.3rc1 Release Notes #
# cocos2d-x v3.3rc2 Release Notes #
**Table of Contents** *generated with [DocToc](http://doctoc.herokuapp.com/)*
- [cocos2d-x v3.3rc1 Release Notes](#)
- [Misc Information](#)
- [Requirements](#)
- [Runtime Requirements](#)
- [Compiler Requirements](#)
- [How to run tests](#)
- [Mac OSX & iOS](#)
- [Android](#)
- [Windows](#)
- [Linux](#)
- [How to start a new game](#)
- [Notes of v3.3rc1](#)
- [Highlights of v3.3rc1](#)
- [Notes of v3.3rc0](#)
- [Highlights of v3.3rc0](#)
- [Features in detail](#)
- [Light](#)
- [Spine runtime](#)
- [AssetsManagerEx](#)
- [Application::openURL](#)
- [ClippingRectangleNode](#)
- [Facebook platform support](#)
- [Highlights of v3.3beta0](#)
- [Features in detail](#)
- [BillBoard](#)
- [Triangles command](#)
- [WebView](#)
- [New audio](#)
- [Highlights of v3.3alpha0](#)
- [Features in detail](#)
- [Camera](#)
- [Reskin](#)
- [Attachment](#)
- [Better support for FBX](#)
- [New fbx-conv](#)
- [AABB, OBB and Ray](#)
- [ui::Scale9Sprite](#)
- [c++11 random support](#)
- [RenderTexture save function](#)
- [Primitive](#)
- [Consistent way to set GL context attributes](#)
- [Only two libraries left](#)
- [cocos2d-x v3.3rc2 Release Notes](#cocos2d-x-v33rc2-release-notes)
- [Misc Information](#misc-information)
- [Requirements](#requirements)
- [Runtime Requirements](#runtime-requirements)
- [Compiler Requirements](#compiler-requirements)
- [How to run tests](#how-to-run-tests)
- [Mac OSX & iOS](#mac-osx-&-ios)
- [Android](#android)
- [Windows](#windows)
- [Linux](#linux)
- [How to start a new game](#how-to-start-a-new-game)
- [Highlights of v3.3rc2](#highlights-of-v33rc2)
- [Notes of v3.3rc1](#notes-of-v33rc1)
- [Highlights of v3.3rc1](#highlights-of-v33rc1)
- [Notes of v3.3rc0](#notes-of-v33rc0)
- [Highlights of v3.3rc0](#highlights-of-v33rc0)
- [Features in detail](#features-in-detail)
- [Light](#light)
- [Spine runtime](#spine-runtime)
- [AssetsManagerEx](#assetsmanagerex)
- [Application::openURL](#applicationopenurl)
- [ClippingRectangleNode](#clippingrectanglenode)
- [Facebook platform support](#facebook-platform-support)
- [Highlights of v3.3beta0](#highlights-of-v33beta0)
- [Features in detail](#features-in-detail-1)
- [BillBoard](#billboard)
- [Triangles command](#triangles-command)
- [WebView](#webview)
- [New audio](#new-audio)
- [Highlights of v3.3alpha0](#highlights-of-v33alpha0)
- [Features in detail](#features-in-detail-2)
- [Camera](#camera)
- [Reskin](#reskin)
- [Attachment](#attachment)
- [Better support for FBX](#better-support-for-fbx)
- [New fbx-conv](#new-fbx-conv)
- [AABB, OBB and Ray](#aabb-obb-and-ray)
- [ui::Scale9Sprite](#uiscale9sprite)
- [c++11 random support](#c11-random-support)
- [RenderTexture save function](#rendertexture-save-function)
- [Primitive](#primitive)
- [Consistent way to set GL context attributes](#consistent-way-to-set-gl-context-attributes)
- [Only two libraries left](#only-two-libraries-left)
# Misc Information
* Full Changelog: https://github.com/cocos2d/cocos2d-x/blob/cocos2d-x-3.3rc1/CHANGELOG
* Full Changelog: https://github.com/cocos2d/cocos2d-x/blob/cocos2d-x-3.3rc2/CHANGELOG
* v3.0 Release Notes can be found here: [v3.0 Release Notes](https://github.com/cocos2d/cocos2d-x/blob/cocos2d-x-3.0/docs/RELEASE_NOTES.md)
# Requirements
@ -133,6 +134,10 @@ Run
Please refer to this document: [ReadMe](../README.md)
# Highlights of v3.3rc2
* Support for android arm64 architecture, all test cases run on Nexus 9
* Cocos Studio Reader: Replace [Protobuffer](https://github.com/google/protobuf) by [FlatBuffer](https://github.com/google/flatbuffers)
# Notes of v3.3rc1
**android**
@ -206,7 +211,7 @@ require "cocos.init"
* Application: added openURL()
* Added `AssetsManagerEx`, it is an enhancement version of `AssetsManager`
* TileMap: supported staggered tile map
* Added `ClippingRectangNode`, it is more effecient for renctangle clipping
* Added `ClippingRectangleNode`, it is more efficient for renctangle clipping
* Node: schedule/unschedule lambda functions
* Facebook platform support in `plugin` on iOS and Android, all features has been added, but the API needs to be polished with Facebook guys
@ -318,7 +323,7 @@ You can refer to [this document](http://www.cocos2d-x.org/wiki/Integrate_the_Fac
* 3d: `BillBoard`
* audio: new audio is added on iOS and Android
* DrawNode: added as many functions as `DrawPrimitive`, and `DrawPrimitive` is deprecated
* Renderer: added `trianle command`
* Renderer: added `triangle command`
* UI: added `WebView` on iOS and Android
* Many other small features added and many bugs fixed
@ -417,13 +422,13 @@ Full test case please refer to `tests/cpp-tests/Classes/NewAudioEngineTest/NewAu
# Highlights of v3.3alpha0
* 3d: `Camera`, 'Reskin', 'Attachment', 'Better support for FBX', 'New fbx-conv', `AABB`, `OBB` and `Ray`
* 3d: `Camera`, `Reskin`, `Attachment`, `Better support for FBX`, `New fbx-conv`, `AABB`, `OBB` and `Ray`
* ui: added `Scale9Sprite`
* FileUitls: added `isDirectoryExist()`, `createDirectory()`, `removeDirectory()`, `removeFile()`, `renameFile()` and `getFileSize()`
* Device: added `setKeepScreenOn()` on iOS and Android
* Added c++11 random support
* RenderTexture: added a call back function for `saveToFile()`
* Primitive: Support Points, Lines and Triagles for rendering
* Primitive: Support Points, Lines and Triangles for rendering
* SpriteFrameCache: support loading from plist file content data
* Added a consistent way to set GL context attributes for all platforms
* Only two libraries in cocos2d-x, one for c++ codes, another one for lua-binding codes

@ -1 +1 @@
Subproject commit 1c8f9616f6e160f25e79cf87fec77754e6958822
Subproject commit 7508bd1b3984d30942362b6717863f832d435703