mirror of https://github.com/axmolengine/axmol.git
Merge branch 'v3' of https://github.com/cocos2d/cocos2d-x into v3_armature_reader
This commit is contained in:
commit
d543f8f6a2
|
@ -256,21 +256,8 @@ cocos_find_package(TIFF TIFF REQUIRED)
|
|||
cocos_find_package(WEBSOCKETS WEBSOCKETS REQUIRED)
|
||||
cocos_find_package(CURL CURL REQUIRED)
|
||||
|
||||
# flatbuffers (not prebuilded, exists as source)
|
||||
# TODO: for now we can't use upstream flatbuffers because these files:
|
||||
# cocos/editor-support/cocostudio/CSParseBinary_generated.h
|
||||
# was generated by concrete version of flatbuffers compiler
|
||||
# and source file not provided. So these files can be
|
||||
# compiled only with our in-source version of flatbuffers
|
||||
## if(USE_PREBUILT_LIBS)
|
||||
add_subdirectory(external/flatbuffers)
|
||||
set(FLATBUFFERS_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external)
|
||||
set(FLATBUFFERS_LIBRARIES flatbuffers)
|
||||
## else()
|
||||
## cocos_find_package(Flatbuffers REQUIRED FLATBUFFERS_LIBRARIES)
|
||||
## set(FLATBUFFERS_INCLUDE_DIRS ${FLATBUFFERS_INCLUDE_DIRS})
|
||||
## endif()
|
||||
message(STATUS "Flatbuffers libs: ${FLATBUFFERS_LIBRARIES}")
|
||||
add_subdirectory(external/flatbuffers)
|
||||
set(FLATBUFFERS_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external)
|
||||
message(STATUS "Flatbuffers include dirs: ${FLATBUFFERS_INCLUDE_DIRS}")
|
||||
|
||||
|
||||
|
|
|
@ -1929,6 +1929,10 @@
|
|||
B60C5BD519AC68B10056FBDE /* CCBillBoard.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B60C5BD219AC68B10056FBDE /* CCBillBoard.cpp */; };
|
||||
B60C5BD619AC68B10056FBDE /* CCBillBoard.h in Headers */ = {isa = PBXBuildFile; fileRef = B60C5BD319AC68B10056FBDE /* CCBillBoard.h */; };
|
||||
B60C5BD719AC68B10056FBDE /* CCBillBoard.h in Headers */ = {isa = PBXBuildFile; fileRef = B60C5BD319AC68B10056FBDE /* CCBillBoard.h */; };
|
||||
B63990CC1A490AFE00B07923 /* CCAsyncTaskPool.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B63990CA1A490AFE00B07923 /* CCAsyncTaskPool.cpp */; };
|
||||
B63990CD1A490AFE00B07923 /* CCAsyncTaskPool.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B63990CA1A490AFE00B07923 /* CCAsyncTaskPool.cpp */; };
|
||||
B63990CE1A490AFE00B07923 /* CCAsyncTaskPool.h in Headers */ = {isa = PBXBuildFile; fileRef = B63990CB1A490AFE00B07923 /* CCAsyncTaskPool.h */; };
|
||||
B63990CF1A490AFE00B07923 /* CCAsyncTaskPool.h in Headers */ = {isa = PBXBuildFile; fileRef = B63990CB1A490AFE00B07923 /* CCAsyncTaskPool.h */; };
|
||||
D0FD03491A3B51AA00825BB5 /* CCAllocatorBase.h in Headers */ = {isa = PBXBuildFile; fileRef = D0FD033B1A3B51AA00825BB5 /* CCAllocatorBase.h */; };
|
||||
D0FD034A1A3B51AA00825BB5 /* CCAllocatorBase.h in Headers */ = {isa = PBXBuildFile; fileRef = D0FD033B1A3B51AA00825BB5 /* CCAllocatorBase.h */; };
|
||||
D0FD034B1A3B51AA00825BB5 /* CCAllocatorDiagnostics.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D0FD033C1A3B51AA00825BB5 /* CCAllocatorDiagnostics.cpp */; };
|
||||
|
@ -3009,6 +3013,8 @@
|
|||
B3AF019F1842FBA400A98B85 /* b2MotorJoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b2MotorJoint.h; sourceTree = "<group>"; };
|
||||
B60C5BD219AC68B10056FBDE /* CCBillBoard.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCBillBoard.cpp; sourceTree = "<group>"; };
|
||||
B60C5BD319AC68B10056FBDE /* CCBillBoard.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCBillBoard.h; sourceTree = "<group>"; };
|
||||
B63990CA1A490AFE00B07923 /* CCAsyncTaskPool.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CCAsyncTaskPool.cpp; path = ../base/CCAsyncTaskPool.cpp; sourceTree = "<group>"; };
|
||||
B63990CB1A490AFE00B07923 /* CCAsyncTaskPool.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CCAsyncTaskPool.h; path = ../base/CCAsyncTaskPool.h; sourceTree = "<group>"; };
|
||||
B67C624319D4186F00F11FC6 /* ccShader_3D_ColorNormal.frag */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = ccShader_3D_ColorNormal.frag; sourceTree = "<group>"; };
|
||||
B67C624419D4186F00F11FC6 /* ccShader_3D_ColorNormalTex.frag */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = ccShader_3D_ColorNormalTex.frag; sourceTree = "<group>"; };
|
||||
B67C624519D4186F00F11FC6 /* ccShader_3D_PositionNormalTex.vert */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = ccShader_3D_PositionNormalTex.vert; sourceTree = "<group>"; };
|
||||
|
@ -3232,6 +3238,8 @@
|
|||
1A5700A2180BC5E60088DEC7 /* base */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
B63990CA1A490AFE00B07923 /* CCAsyncTaskPool.cpp */,
|
||||
B63990CB1A490AFE00B07923 /* CCAsyncTaskPool.h */,
|
||||
D0FD03391A3B51AA00825BB5 /* allocator */,
|
||||
299CF1F919A434BC00C378C1 /* ccRandom.cpp */,
|
||||
299CF1FA19A434BC00C378C1 /* ccRandom.h */,
|
||||
|
@ -5217,6 +5225,7 @@
|
|||
5034CA3F191D591100CE6051 /* ccShader_Position_uColor.vert in Headers */,
|
||||
B29A7DD319EE1B7700872B35 /* Skin.h in Headers */,
|
||||
50ABBD461925AB0000A911A9 /* CCVertex.h in Headers */,
|
||||
B63990CE1A490AFE00B07923 /* CCAsyncTaskPool.h in Headers */,
|
||||
15AE180A19AAD2F700C27E9E /* CCAABB.h in Headers */,
|
||||
46A170E71807CECA005B8026 /* CCPhysicsBody.h in Headers */,
|
||||
15AE1A5A19AAD40300C27E9E /* b2StackAllocator.h in Headers */,
|
||||
|
@ -6229,6 +6238,7 @@
|
|||
B29A7DF019EE1B7700872B35 /* SkeletonBounds.h in Headers */,
|
||||
15AE1BE919AAE01E00C27E9E /* CCControl.h in Headers */,
|
||||
15AE193719AAD35100C27E9E /* CCArmature.h in Headers */,
|
||||
B63990CF1A490AFE00B07923 /* CCAsyncTaskPool.h in Headers */,
|
||||
15AE1BC319AADFFB00C27E9E /* cocos-ext.h in Headers */,
|
||||
15AE1B8B19AADA9A00C27E9E /* UIImageView.h in Headers */,
|
||||
15AE1A4619AAD3D500C27E9E /* b2TimeOfImpact.h in Headers */,
|
||||
|
@ -6497,6 +6507,7 @@
|
|||
B24AA985195A675C007B4522 /* CCFastTMXLayer.cpp in Sources */,
|
||||
15AE1A6A19AAD40300C27E9E /* b2ChainAndCircleContact.cpp in Sources */,
|
||||
15B3708819EE414C00ABE682 /* Manifest.cpp in Sources */,
|
||||
B63990CC1A490AFE00B07923 /* CCAsyncTaskPool.cpp in Sources */,
|
||||
1A5701EA180BCB8C0088DEC7 /* CCTransitionPageTurn.cpp in Sources */,
|
||||
15AE186B19AAD31D00C27E9E /* SimpleAudioEngine.mm in Sources */,
|
||||
50ABBDAD1925AB4100A911A9 /* CCRenderer.cpp in Sources */,
|
||||
|
@ -7174,6 +7185,7 @@
|
|||
15AE180919AAD2F700C27E9E /* CCAABB.cpp in Sources */,
|
||||
15AE1AA719AAD40300C27E9E /* b2Island.cpp in Sources */,
|
||||
3E6176741960F89B00DE83F5 /* CCEventController.cpp in Sources */,
|
||||
B63990CD1A490AFE00B07923 /* CCAsyncTaskPool.cpp in Sources */,
|
||||
50ABBE361925AB6F00A911A9 /* CCConsole.cpp in Sources */,
|
||||
B29A7E1419EE1B7700872B35 /* Bone.c in Sources */,
|
||||
503DD8E51926736A00CD74DD /* CCDirectorCaller-ios.mm in Sources */,
|
||||
|
|
|
@ -248,6 +248,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\chipmunk\prebuilt\win32\release-lib\*.*
|
|||
<ClCompile Include="..\base\allocator\CCAllocatorGlobalNewDelete.cpp" />
|
||||
<ClCompile Include="..\base\atitc.cpp" />
|
||||
<ClCompile Include="..\base\base64.cpp" />
|
||||
<ClCompile Include="..\base\CCAsyncTaskPool.cpp" />
|
||||
<ClCompile Include="..\base\CCAutoreleasePool.cpp" />
|
||||
<ClCompile Include="..\base\ccCArray.cpp" />
|
||||
<ClCompile Include="..\base\CCConfiguration.cpp" />
|
||||
|
@ -625,6 +626,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\chipmunk\prebuilt\win32\release-lib\*.*
|
|||
<ClInclude Include="..\base\allocator\CCAllocatorStrategyPool.h" />
|
||||
<ClInclude Include="..\base\atitc.h" />
|
||||
<ClInclude Include="..\base\base64.h" />
|
||||
<ClInclude Include="..\base\CCAsyncTaskPool.h" />
|
||||
<ClInclude Include="..\base\CCAutoreleasePool.h" />
|
||||
<ClInclude Include="..\base\ccCArray.h" />
|
||||
<ClInclude Include="..\base\ccConfig.h" />
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="physics">
|
||||
|
@ -1295,6 +1295,9 @@
|
|||
<ClCompile Include="..\editor-support\cocostudio\WidgetCallBackHandlerProtocol.cpp">
|
||||
<Filter>cocostudio\json</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\base\CCAsyncTaskPool.cpp">
|
||||
<Filter>base</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\base\allocator\CCAllocatorDiagnostics.cpp">
|
||||
<Filter>base\allocator</Filter>
|
||||
</ClCompile>
|
||||
|
@ -2523,6 +2526,9 @@
|
|||
<ClInclude Include="..\editor-support\cocostudio\WidgetCallBackHandlerProtocol.h">
|
||||
<Filter>cocostudio\json</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\base\CCAsyncTaskPool.h">
|
||||
<Filter>base</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\base\allocator\CCAllocatorGlobal.h">
|
||||
<Filter>base\allocator</Filter>
|
||||
</ClInclude>
|
||||
|
|
|
@ -38,7 +38,7 @@ Animation3D* Animation3D::create(const std::string& fileName, const std::string&
|
|||
|
||||
//load animation here
|
||||
animation = new (std::nothrow) Animation3D();
|
||||
auto bundle = Bundle3D::getInstance();
|
||||
auto bundle = Bundle3D::createBundle();
|
||||
Animation3DData animationdata;
|
||||
if (bundle->load(fullPath) && bundle->loadAnimationData(animationName, &animationdata) && animation->init(animationdata))
|
||||
{
|
||||
|
@ -51,6 +51,7 @@ Animation3D* Animation3D::create(const std::string& fileName, const std::string&
|
|||
animation = nullptr;
|
||||
}
|
||||
|
||||
Bundle3D::destroyBundle(bundle);
|
||||
return animation;
|
||||
}
|
||||
|
||||
|
|
|
@ -146,24 +146,15 @@ void getChildMap(std::map<int, std::vector<int> >& map, SkinData* skinData, cons
|
|||
}
|
||||
}
|
||||
|
||||
Bundle3D* Bundle3D::_instance = nullptr;
|
||||
|
||||
void Bundle3D::setBundleInstance(Bundle3D* bundleInstance)
|
||||
Bundle3D* Bundle3D::createBundle()
|
||||
{
|
||||
CC_SAFE_DELETE(_instance);
|
||||
_instance = bundleInstance;
|
||||
auto bundle = new (std::nothrow) Bundle3D();
|
||||
return bundle;
|
||||
}
|
||||
|
||||
Bundle3D* Bundle3D::getInstance()
|
||||
void Bundle3D::destroyBundle(Bundle3D* bundle)
|
||||
{
|
||||
if (_instance == nullptr)
|
||||
_instance = new (std::nothrow) Bundle3D();
|
||||
return _instance;
|
||||
}
|
||||
|
||||
void Bundle3D::destroyInstance()
|
||||
{
|
||||
CC_SAFE_DELETE(_instance);
|
||||
delete bundle;
|
||||
}
|
||||
|
||||
void Bundle3D::clear()
|
||||
|
|
|
@ -42,12 +42,10 @@ class Data;
|
|||
class CC_DLL Bundle3D
|
||||
{
|
||||
public:
|
||||
/**you can define yourself bundle and set it, use default bundle otherwise*/
|
||||
static void setBundleInstance(Bundle3D* bundleInstance);
|
||||
// create a new bundle, destroy it when finish using it
|
||||
static Bundle3D* createBundle();
|
||||
|
||||
static Bundle3D* getInstance();
|
||||
|
||||
static void destroyInstance();
|
||||
static void destroyBundle(Bundle3D* bundle);
|
||||
|
||||
virtual void clear();
|
||||
|
||||
|
@ -158,7 +156,6 @@ CC_CONSTRUCTOR_ACCESS:
|
|||
virtual ~Bundle3D();
|
||||
|
||||
protected:
|
||||
static Bundle3D* _instance;
|
||||
std::string _modelPath;
|
||||
std::string _path;
|
||||
std::string _version;// the c3b or c3t version
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#include "3d/CCMesh.h"
|
||||
|
||||
#include "base/CCDirector.h"
|
||||
#include "base/CCAsyncTaskPool.h"
|
||||
#include "2d/CCLight.h"
|
||||
#include "2d/CCCamera.h"
|
||||
#include "base/ccMacros.h"
|
||||
|
@ -73,6 +74,87 @@ Sprite3D* Sprite3D::create(const std::string &modelPath, const std::string &text
|
|||
return sprite;
|
||||
}
|
||||
|
||||
void Sprite3D::createAsync(const std::string &modelPath, const std::function<void(Sprite3D*, void*)>& callback, void* callbackparam)
|
||||
{
|
||||
createAsync(modelPath, "", callback, callbackparam);
|
||||
}
|
||||
|
||||
void Sprite3D::createAsync(const std::string &modelPath, const std::string &texturePath, const std::function<void(Sprite3D*, void*)>& callback, void* callbackparam)
|
||||
{
|
||||
Sprite3D *sprite = new (std::nothrow) Sprite3D();
|
||||
if (sprite->loadFromCache(modelPath))
|
||||
{
|
||||
sprite->autorelease();
|
||||
if (!texturePath.empty())
|
||||
sprite->setTexture(texturePath);
|
||||
callback(sprite, callbackparam);
|
||||
return;
|
||||
}
|
||||
|
||||
sprite->_asyncLoadParam.afterLoadCallback = callback;
|
||||
sprite->_asyncLoadParam.texPath = texturePath;
|
||||
sprite->_asyncLoadParam.modlePath = modelPath;
|
||||
sprite->_asyncLoadParam.callbackParam = callbackparam;
|
||||
sprite->_asyncLoadParam.materialdatas = new (std::nothrow) MaterialDatas();
|
||||
sprite->_asyncLoadParam.meshdatas = new (std::nothrow) MeshDatas();
|
||||
sprite->_asyncLoadParam.nodeDatas = new (std::nothrow) NodeDatas();
|
||||
AsyncTaskPool::getInstance()->enqueue(AsyncTaskPool::TaskType::TASK_IO, CC_CALLBACK_1(Sprite3D::afterAsyncLoad, sprite), (void*)(&sprite->_asyncLoadParam), [sprite]()
|
||||
{
|
||||
sprite->_asyncLoadParam.result = sprite->loadFromFile(sprite->_asyncLoadParam.modlePath, sprite->_asyncLoadParam.nodeDatas, sprite->_asyncLoadParam.meshdatas, sprite->_asyncLoadParam.materialdatas);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
void Sprite3D::afterAsyncLoad(void* param)
|
||||
{
|
||||
Sprite3D::AsyncLoadParam* asyncParam = (Sprite3D::AsyncLoadParam*)param;
|
||||
autorelease();
|
||||
if (asyncParam)
|
||||
{
|
||||
if (asyncParam->result)
|
||||
{
|
||||
_meshes.clear();
|
||||
_meshVertexDatas.clear();
|
||||
CC_SAFE_RELEASE_NULL(_skeleton);
|
||||
removeAllAttachNode();
|
||||
|
||||
//create in the main thread
|
||||
auto& meshdatas = asyncParam->meshdatas;
|
||||
auto& materialdatas = asyncParam->materialdatas;
|
||||
auto& nodeDatas = asyncParam->nodeDatas;
|
||||
if (initFrom(*nodeDatas, *meshdatas, *materialdatas))
|
||||
{
|
||||
auto spritedata = Sprite3DCache::getInstance()->getSpriteData(asyncParam->modlePath);
|
||||
if (spritedata == nullptr)
|
||||
{
|
||||
//add to cache
|
||||
auto data = new (std::nothrow) Sprite3DCache::Sprite3DData();
|
||||
data->materialdatas = materialdatas;
|
||||
data->nodedatas = nodeDatas;
|
||||
data->meshVertexDatas = _meshVertexDatas;
|
||||
for (const auto mesh : _meshes) {
|
||||
data->glProgramStates.pushBack(mesh->getGLProgramState());
|
||||
}
|
||||
|
||||
Sprite3DCache::getInstance()->addSprite3DData(asyncParam->modlePath, data);
|
||||
meshdatas = nullptr;
|
||||
materialdatas = nullptr;
|
||||
nodeDatas = nullptr;
|
||||
}
|
||||
}
|
||||
delete meshdatas;
|
||||
delete materialdatas;
|
||||
delete nodeDatas;
|
||||
|
||||
if (asyncParam->texPath != "")
|
||||
{
|
||||
setTexture(asyncParam->texPath);
|
||||
}
|
||||
}
|
||||
asyncParam->afterLoadCallback(this, asyncParam->callbackParam);
|
||||
}
|
||||
}
|
||||
|
||||
bool Sprite3D::loadFromCache(const std::string& path)
|
||||
{
|
||||
auto spritedata = Sprite3DCache::getInstance()->getSpriteData(path);
|
||||
|
@ -109,66 +191,32 @@ bool Sprite3D::loadFromCache(const std::string& path)
|
|||
return false;
|
||||
}
|
||||
|
||||
//.mtl file should at the same directory with the same name if exist
|
||||
bool Sprite3D::loadFromObj(const std::string& path)
|
||||
bool Sprite3D::loadFromFile(const std::string& path, NodeDatas* nodedatas, MeshDatas* meshdatas, MaterialDatas* materialdatas)
|
||||
{
|
||||
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(path);
|
||||
|
||||
MeshDatas meshdatas;
|
||||
MaterialDatas* materialdatas = new (std::nothrow) MaterialDatas();
|
||||
NodeDatas* nodeDatas = new (std::nothrow) NodeDatas();
|
||||
bool ret = Bundle3D::loadObj(meshdatas, *materialdatas, *nodeDatas, fullPath);
|
||||
if (ret && initFrom(*nodeDatas, meshdatas, *materialdatas))
|
||||
std::string ext = path.substr(path.length() - 4, 4);
|
||||
std::transform(ext.begin(), ext.end(), ext.begin(), tolower);
|
||||
if (ext == ".obj")
|
||||
{
|
||||
//add to cache
|
||||
auto data = new (std::nothrow) Sprite3DCache::Sprite3DData();
|
||||
data->materialdatas = materialdatas;
|
||||
data->nodedatas = nodeDatas;
|
||||
data->meshVertexDatas = _meshVertexDatas;
|
||||
for (const auto mesh : _meshes) {
|
||||
data->glProgramStates.pushBack(mesh->getGLProgramState());
|
||||
return Bundle3D::loadObj(*meshdatas, *materialdatas, *nodedatas, fullPath);
|
||||
}
|
||||
else if (ext == ".c3b" || ext == ".c3t")
|
||||
{
|
||||
//load from .c3b or .c3t
|
||||
auto bundle = Bundle3D::createBundle();
|
||||
if (!bundle->load(fullPath))
|
||||
{
|
||||
Bundle3D::destroyBundle(bundle);
|
||||
return false;
|
||||
}
|
||||
|
||||
Sprite3DCache::getInstance()->addSprite3DData(path, data);
|
||||
return true;
|
||||
auto ret = bundle->loadMeshDatas(*meshdatas)
|
||||
&& bundle->loadMaterials(*materialdatas) && bundle->loadNodes(*nodedatas);
|
||||
Bundle3D::destroyBundle(bundle);
|
||||
|
||||
return ret;
|
||||
}
|
||||
delete materialdatas;
|
||||
delete nodeDatas;
|
||||
|
||||
return false;
|
||||
}
|
||||
bool Sprite3D::loadFromC3x(const std::string& path)
|
||||
{
|
||||
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(path);
|
||||
|
||||
//load from .c3b or .c3t
|
||||
auto bundle = Bundle3D::getInstance();
|
||||
if (!bundle->load(fullPath))
|
||||
return false;
|
||||
|
||||
MeshDatas meshdatas;
|
||||
MaterialDatas* materialdatas = new (std::nothrow) MaterialDatas();
|
||||
NodeDatas* nodeDatas = new (std::nothrow) NodeDatas();
|
||||
if (bundle->loadMeshDatas(meshdatas)
|
||||
&& bundle->loadMaterials(*materialdatas)
|
||||
&& bundle->loadNodes(*nodeDatas)
|
||||
&& initFrom(*nodeDatas, meshdatas, *materialdatas))
|
||||
{
|
||||
//add to cache
|
||||
auto data = new (std::nothrow) Sprite3DCache::Sprite3DData();
|
||||
data->materialdatas = materialdatas;
|
||||
data->nodedatas = nodeDatas;
|
||||
data->meshVertexDatas = _meshVertexDatas;
|
||||
for (const auto mesh : _meshes) {
|
||||
data->glProgramStates.pushBack(mesh->getGLProgramState());
|
||||
}
|
||||
Sprite3DCache::getInstance()->addSprite3DData(path, data);
|
||||
return true;
|
||||
}
|
||||
|
||||
delete materialdatas;
|
||||
delete nodeDatas;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -199,18 +247,29 @@ bool Sprite3D::initWithFile(const std::string &path)
|
|||
if (loadFromCache(path))
|
||||
return true;
|
||||
|
||||
//load from file
|
||||
std::string ext = path.substr(path.length() - 4, 4);
|
||||
std::transform(ext.begin(), ext.end(), ext.begin(), tolower);
|
||||
|
||||
if (ext == ".obj")
|
||||
MeshDatas* meshdatas = new (std::nothrow) MeshDatas();
|
||||
MaterialDatas* materialdatas = new (std::nothrow) MaterialDatas();
|
||||
NodeDatas* nodeDatas = new (std::nothrow) NodeDatas();
|
||||
if (loadFromFile(path, nodeDatas, meshdatas, materialdatas))
|
||||
{
|
||||
return loadFromObj(path);
|
||||
}
|
||||
else if (ext == ".c3b" || ext == ".c3t")
|
||||
{
|
||||
return loadFromC3x(path);
|
||||
if (initFrom(*nodeDatas, *meshdatas, *materialdatas))
|
||||
{
|
||||
//add to cache
|
||||
auto data = new (std::nothrow) Sprite3DCache::Sprite3DData();
|
||||
data->materialdatas = materialdatas;
|
||||
data->nodedatas = nodeDatas;
|
||||
data->meshVertexDatas = _meshVertexDatas;
|
||||
for (const auto mesh : _meshes) {
|
||||
data->glProgramStates.pushBack(mesh->getGLProgramState());
|
||||
}
|
||||
|
||||
Sprite3DCache::getInstance()->addSprite3DData(path, data);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
delete meshdatas;
|
||||
delete materialdatas;
|
||||
delete nodeDatas;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -56,6 +56,18 @@ public:
|
|||
// creates a Sprite3D. It only supports one texture, and overrides the internal texture with 'texturePath'
|
||||
static Sprite3D* create(const std::string &modelPath, const std::string &texturePath);
|
||||
|
||||
/** create 3d sprite asynchronously
|
||||
* If the 3d model was previously loaded, it will create a new 3d sprite and the callback will be called at once.
|
||||
* Otherwise it will load the model file in a new thread, and when the 3d sprite is loaded, the callback will be called with the created Sprite3D and a userdefined parameter.
|
||||
* The callback will be called from the main thread, so it is safe to create any cocos2d object from the callback.
|
||||
* @param modelPath model to be loaded
|
||||
* @param callback callback after loading
|
||||
* @param callbackparam user defined parameter for the callback
|
||||
*/
|
||||
static void createAsync(const std::string &modelPath, const std::function<void(Sprite3D*, void*)>& callback, void* callbackparam);
|
||||
|
||||
static void createAsync(const std::string &modelPath, const std::string &texturePath, const std::function<void(Sprite3D*, void*)>& callback, void* callbackparam);
|
||||
|
||||
/**set texture, set the first if multiple textures exist*/
|
||||
void setTexture(const std::string& texFile);
|
||||
void setTexture(Texture2D* texture);
|
||||
|
@ -133,11 +145,8 @@ CC_CONSTRUCTOR_ACCESS:
|
|||
/**load sprite3d from cache, return true if succeed, false otherwise*/
|
||||
bool loadFromCache(const std::string& path);
|
||||
|
||||
/**.mtl file should at the same directory with the same name if exist*/
|
||||
bool loadFromObj(const std::string& path);
|
||||
|
||||
/**load from .c3b or .c3t*/
|
||||
bool loadFromC3x(const std::string& path);
|
||||
/** load file and set it to meshedatas, nodedatas and materialdatas, obj file .mtl file should be at the same directory if exist */
|
||||
bool loadFromFile(const std::string& path, NodeDatas* nodedatas, MeshDatas* meshdatas, MaterialDatas* materialdatas);
|
||||
|
||||
/**draw*/
|
||||
virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) override;
|
||||
|
@ -156,6 +165,8 @@ CC_CONSTRUCTOR_ACCESS:
|
|||
|
||||
void onAABBDirty() { _aabbDirty = true; }
|
||||
|
||||
void afterAsyncLoad(void* param);
|
||||
|
||||
protected:
|
||||
|
||||
Skeleton3D* _skeleton; //skeleton
|
||||
|
@ -173,10 +184,23 @@ protected:
|
|||
bool _aabbDirty;
|
||||
unsigned int _lightMask;
|
||||
bool _shaderUsingLight; // is current shader using light ?
|
||||
|
||||
struct AsyncLoadParam
|
||||
{
|
||||
std::function<void(Sprite3D*, void*)> afterLoadCallback; // callback after load
|
||||
void* callbackParam;
|
||||
bool result; // sprite load result
|
||||
std::string modlePath;
|
||||
std::string texPath; //
|
||||
MeshDatas* meshdatas;
|
||||
MaterialDatas* materialdatas;
|
||||
NodeDatas* nodeDatas;
|
||||
};
|
||||
AsyncLoadParam _asyncLoadParam;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////
|
||||
class Sprite3DCache
|
||||
class CC_DLL Sprite3DCache
|
||||
{
|
||||
public:
|
||||
struct Sprite3DData
|
||||
|
|
|
@ -92,6 +92,7 @@ math/TransformUtils.cpp \
|
|||
math/Vec2.cpp \
|
||||
math/Vec3.cpp \
|
||||
math/Vec4.cpp \
|
||||
base/CCAsyncTaskPool.cpp \
|
||||
base/CCAutoreleasePool.cpp \
|
||||
base/CCConfiguration.cpp \
|
||||
base/CCConsole.cpp \
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010 cocos2d-x.org
|
||||
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "base/CCAsyncTaskPool.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
AsyncTaskPool* AsyncTaskPool::s_asyncTaskPool = nullptr;
|
||||
|
||||
AsyncTaskPool* AsyncTaskPool::getInstance()
|
||||
{
|
||||
if (s_asyncTaskPool == nullptr)
|
||||
{
|
||||
s_asyncTaskPool = new (std::nothrow) AsyncTaskPool();
|
||||
}
|
||||
return s_asyncTaskPool;
|
||||
}
|
||||
|
||||
void AsyncTaskPool::destoryInstance()
|
||||
{
|
||||
delete s_asyncTaskPool;
|
||||
s_asyncTaskPool = nullptr;
|
||||
}
|
||||
|
||||
AsyncTaskPool::AsyncTaskPool()
|
||||
{
|
||||
}
|
||||
|
||||
AsyncTaskPool::~AsyncTaskPool()
|
||||
{
|
||||
}
|
||||
|
||||
NS_CC_END
|
|
@ -0,0 +1,205 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010 cocos2d-x.org
|
||||
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __CCSYNC_TASK_POOL_H_
|
||||
#define __CCSYNC_TASK_POOL_H_
|
||||
|
||||
#include "platform/CCPlatformMacros.h"
|
||||
#include "base/CCDirector.h"
|
||||
#include "base/CCScheduler.h"
|
||||
#include <vector>
|
||||
#include <queue>
|
||||
#include <memory>
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
#include <future>
|
||||
#include <functional>
|
||||
#include <stdexcept>
|
||||
|
||||
NS_CC_BEGIN
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class CC_DLL AsyncTaskPool
|
||||
{
|
||||
public:
|
||||
typedef std::function<void(void*)> TaskCallBack;
|
||||
|
||||
enum class TaskType
|
||||
{
|
||||
TASK_IO,
|
||||
TASK_NETWORK,
|
||||
TASK_OTHER,
|
||||
TASK_MAX_TYPE,
|
||||
};
|
||||
/**
|
||||
* get instance
|
||||
*/
|
||||
static AsyncTaskPool* getInstance();
|
||||
/**
|
||||
* destroy instance
|
||||
*/
|
||||
static void destoryInstance();
|
||||
|
||||
/**
|
||||
* stop tasks
|
||||
* @param type task type you want to stop
|
||||
*/
|
||||
void stopTasks(TaskType type);
|
||||
|
||||
/**
|
||||
* enqueue a asynchronous task
|
||||
* @param type task type is io task, network task or others, each type of task has a thread to deal with it.
|
||||
* @param callback callback when the task is finished. The callback is called in the main thread instead of task thread
|
||||
* @param callbackParam parameter used by the callback
|
||||
* @param f task can be lambda function
|
||||
* @param args task parameters
|
||||
*/
|
||||
template<class F>
|
||||
inline void enqueue(TaskType type, const TaskCallBack& callback, void* callbackParam, F&& f);
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
AsyncTaskPool();
|
||||
~AsyncTaskPool();
|
||||
|
||||
protected:
|
||||
|
||||
// thread tasks internally used
|
||||
class ThreadTasks {
|
||||
struct AsyncTaskCallBack
|
||||
{
|
||||
TaskCallBack callback;
|
||||
void* callbackParam;
|
||||
};
|
||||
public:
|
||||
ThreadTasks()
|
||||
: _stop(false)
|
||||
{
|
||||
_thread = std::thread(
|
||||
[this]
|
||||
{
|
||||
for(;;)
|
||||
{
|
||||
std::function<void()> task;
|
||||
AsyncTaskCallBack callback;
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(this->_queueMutex);
|
||||
this->_condition.wait(lock,
|
||||
[this]{ return this->_stop || !this->_tasks.empty(); });
|
||||
if(this->_stop && this->_tasks.empty())
|
||||
return;
|
||||
task = std::move(this->_tasks.front());
|
||||
callback = std::move(this->_taskCallBacks.front());
|
||||
this->_tasks.pop();
|
||||
this->_taskCallBacks.pop();
|
||||
}
|
||||
|
||||
task();
|
||||
Director::getInstance()->getScheduler()->performFunctionInCocosThread([&, callback]{ callback.callback(callback.callbackParam); });
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
~ThreadTasks()
|
||||
{
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(_queueMutex);
|
||||
_stop = true;
|
||||
|
||||
while(_tasks.size())
|
||||
_tasks.pop();
|
||||
while (_taskCallBacks.size())
|
||||
_taskCallBacks.pop();
|
||||
}
|
||||
_condition.notify_all();
|
||||
_thread.join();
|
||||
}
|
||||
void clear()
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(_queueMutex);
|
||||
while(_tasks.size())
|
||||
_tasks.pop();
|
||||
while (_taskCallBacks.size())
|
||||
_taskCallBacks.pop();
|
||||
}
|
||||
template<class F>
|
||||
void enqueue(const TaskCallBack& callback, void* callbackParam, F&& f)
|
||||
{
|
||||
auto task = f;//std::bind(std::forward<F>(f), std::forward<Args>(args)...);
|
||||
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(_queueMutex);
|
||||
|
||||
// don't allow enqueueing after stopping the pool
|
||||
if(_stop)
|
||||
{
|
||||
CC_ASSERT(0 && "already stop");
|
||||
return;
|
||||
}
|
||||
|
||||
AsyncTaskCallBack taskCallBack;
|
||||
taskCallBack.callback = callback;
|
||||
taskCallBack.callbackParam = callbackParam;
|
||||
_tasks.emplace([task](){ task(); });
|
||||
_taskCallBacks.emplace(taskCallBack);
|
||||
}
|
||||
_condition.notify_one();
|
||||
}
|
||||
private:
|
||||
|
||||
// need to keep track of thread so we can join them
|
||||
std::thread _thread;
|
||||
// the task queue
|
||||
std::queue< std::function<void()> > _tasks;
|
||||
std::queue<AsyncTaskCallBack> _taskCallBacks;
|
||||
|
||||
// synchronization
|
||||
std::mutex _queueMutex;
|
||||
std::condition_variable _condition;
|
||||
bool _stop;
|
||||
};
|
||||
|
||||
//tasks
|
||||
ThreadTasks _threadTasks[int(TaskType::TASK_MAX_TYPE)];
|
||||
|
||||
static AsyncTaskPool* s_asyncTaskPool;
|
||||
};
|
||||
|
||||
inline void AsyncTaskPool::stopTasks(TaskType type)
|
||||
{
|
||||
auto& threadTask = _threadTasks[(int)type];
|
||||
threadTask.clear();
|
||||
}
|
||||
|
||||
template<class F>
|
||||
inline void AsyncTaskPool::enqueue(AsyncTaskPool::TaskType type, const TaskCallBack& callback, void* callbackParam, F&& f)
|
||||
{
|
||||
auto& threadTask = _threadTasks[(int)type];
|
||||
|
||||
threadTask.enqueue(callback, callbackParam, f);
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
#endif //__CCSYNC_TASK_POOL_H_
|
|
@ -57,6 +57,7 @@ THE SOFTWARE.
|
|||
#include "base/CCConsole.h"
|
||||
#include "base/CCAutoreleasePool.h"
|
||||
#include "base/CCConfiguration.h"
|
||||
#include "base/CCAsyncTaskPool.h"
|
||||
#include "platform/CCApplication.h"
|
||||
//#include "platform/CCGLViewImpl.h"
|
||||
|
||||
|
@ -982,6 +983,7 @@ void Director::purgeDirector()
|
|||
GLProgramCache::destroyInstance();
|
||||
GLProgramStateCache::destroyInstance();
|
||||
FileUtils::destroyInstance();
|
||||
AsyncTaskPool::destoryInstance();
|
||||
|
||||
// cocos2d-x specific data structures
|
||||
UserDefault::destroyInstance();
|
||||
|
|
|
@ -12,6 +12,7 @@ set(COCOS_BASE_SRC
|
|||
base/allocator/CCAllocatorGlobal.cpp
|
||||
base/allocator/CCAllocatorGlobalNewDelete.cpp
|
||||
base/ccFPSImages.c
|
||||
base/CCAsyncTaskPool.cpp
|
||||
base/CCAutoreleasePool.cpp
|
||||
base/CCConfiguration.cpp
|
||||
base/CCConsole.cpp
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
pthread_mutex_lock(&m);
|
||||
#define MUTEX_UNLOCK(m) \
|
||||
pthread_mutex_unlock(&m);
|
||||
#elif CC_TARGET_PLATFORM == CC_PLATFORM_WIN32
|
||||
#elif CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_WP8 || CC_TARGET_PLATFORM == CC_PLATFORM_WINRT
|
||||
#include "windows.h"
|
||||
#define MUTEX HANDLE
|
||||
#define MUTEX_INIT(m) \
|
||||
|
@ -51,7 +51,11 @@
|
|||
#define MUTEX_UNLOCK(m) \
|
||||
ReleaseMutex(m)
|
||||
#else
|
||||
#error "Unsupported platform for AllocatorMutex"
|
||||
#message "Unsupported platform for AllocatorMutex, Locking semantics will not be supported"
|
||||
#define MUTEX
|
||||
#define MUTEX_INIT(...)
|
||||
#define MUTEX_LOCK(...)
|
||||
#define MUTEX_UNLOCK(...)
|
||||
#endif
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
|
|
@ -100,6 +100,16 @@
|
|||
-- @param #string texturePath
|
||||
-- @return Sprite3D#Sprite3D ret (return value: cc.Sprite3D)
|
||||
|
||||
--------------------------------
|
||||
-- @overload self, string, string, function, void
|
||||
-- @overload self, string, function, void
|
||||
-- @function [parent=#Sprite3D] createAsync
|
||||
-- @param self
|
||||
-- @param #string modelPath
|
||||
-- @param #string texturePath
|
||||
-- @param #function callback
|
||||
-- @param #void callbackparam
|
||||
|
||||
--------------------------------
|
||||
-- Returns 2d bounding-box<br>
|
||||
-- Note: the bouding-box is just get from the AABB which as Z=0, so that is not very accurate.
|
||||
|
|
|
@ -1102,6 +1102,77 @@ int lua_cocos2dx_3d_Sprite3D_create(lua_State* tolua_S)
|
|||
#endif
|
||||
return 0;
|
||||
}
|
||||
int lua_cocos2dx_3d_Sprite3D_createAsync(lua_State* tolua_S)
|
||||
{
|
||||
int argc = 0;
|
||||
bool ok = true;
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
tolua_Error tolua_err;
|
||||
#endif
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
if (!tolua_isusertable(tolua_S,1,"cc.Sprite3D",0,&tolua_err)) goto tolua_lerror;
|
||||
#endif
|
||||
|
||||
argc = lua_gettop(tolua_S)-1;
|
||||
|
||||
do
|
||||
{
|
||||
if (argc == 4)
|
||||
{
|
||||
std::string arg0;
|
||||
ok &= luaval_to_std_string(tolua_S, 2,&arg0, "cc.Sprite3D:createAsync");
|
||||
if (!ok) { break; }
|
||||
std::string arg1;
|
||||
ok &= luaval_to_std_string(tolua_S, 3,&arg1, "cc.Sprite3D:createAsync");
|
||||
if (!ok) { break; }
|
||||
std::function<void (cocos2d::Sprite3D *, void *)> arg2;
|
||||
do {
|
||||
// Lambda binding for lua is not supported.
|
||||
assert(false);
|
||||
} while(0)
|
||||
;
|
||||
if (!ok) { break; }
|
||||
void* arg3;
|
||||
#pragma warning NO CONVERSION TO NATIVE FOR void*
|
||||
ok = false;
|
||||
if (!ok) { break; }
|
||||
cocos2d::Sprite3D::createAsync(arg0, arg1, arg2, arg3);
|
||||
return 0;
|
||||
}
|
||||
} while (0);
|
||||
ok = true;
|
||||
do
|
||||
{
|
||||
if (argc == 3)
|
||||
{
|
||||
std::string arg0;
|
||||
ok &= luaval_to_std_string(tolua_S, 2,&arg0, "cc.Sprite3D:createAsync");
|
||||
if (!ok) { break; }
|
||||
std::function<void (cocos2d::Sprite3D *, void *)> arg1;
|
||||
do {
|
||||
// Lambda binding for lua is not supported.
|
||||
assert(false);
|
||||
} while(0)
|
||||
;
|
||||
if (!ok) { break; }
|
||||
void* arg2;
|
||||
#pragma warning NO CONVERSION TO NATIVE FOR void*
|
||||
ok = false;
|
||||
if (!ok) { break; }
|
||||
cocos2d::Sprite3D::createAsync(arg0, arg1, arg2);
|
||||
return 0;
|
||||
}
|
||||
} while (0);
|
||||
ok = true;
|
||||
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d", "cc.Sprite3D:createAsync",argc, 3);
|
||||
return 0;
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
tolua_lerror:
|
||||
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_3d_Sprite3D_createAsync'.",&tolua_err);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
static int lua_cocos2dx_3d_Sprite3D_finalize(lua_State* tolua_S)
|
||||
{
|
||||
printf("luabindings: finalizing LUA object (Sprite3D)");
|
||||
|
@ -1129,6 +1200,7 @@ int lua_register_cocos2dx_3d_Sprite3D(lua_State* tolua_S)
|
|||
tolua_function(tolua_S,"getMeshByName",lua_cocos2dx_3d_Sprite3D_getMeshByName);
|
||||
tolua_function(tolua_S,"getAttachNode",lua_cocos2dx_3d_Sprite3D_getAttachNode);
|
||||
tolua_function(tolua_S,"create", lua_cocos2dx_3d_Sprite3D_create);
|
||||
tolua_function(tolua_S,"createAsync", lua_cocos2dx_3d_Sprite3D_createAsync);
|
||||
tolua_endmodule(tolua_S);
|
||||
std::string typeName = typeid(cocos2d::Sprite3D).name();
|
||||
g_luaType[typeName] = "cc.Sprite3D";
|
||||
|
|
|
@ -60,6 +60,7 @@ int register_all_cocos2dx_3d(lua_State* tolua_S);
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // __cocos2dx_3d_h__
|
||||
|
|
|
@ -83,9 +83,14 @@ public:
|
|||
|
||||
static void changeLayoutSystemActiveState(bool bActive);
|
||||
|
||||
private:
|
||||
/**
|
||||
*@brief restrict capInsetSize, when the capInsets's width is larger than the textureSize, it will restrict to 0,
|
||||
* the height goes the same way as width.
|
||||
*@param capInsets A user defined capInsets.
|
||||
*@param textureSize The size of a scale9enabled texture
|
||||
*@return a restricted capInset.
|
||||
*/
|
||||
static Rect restrictCapInsetRect(const Rect& capInsets, const Size& textureSize);
|
||||
friend class Button;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ THE SOFTWARE.
|
|||
|
||||
#include "ui/UIImageView.h"
|
||||
#include "ui/UIScale9Sprite.h"
|
||||
#include "ui/UIHelper.h"
|
||||
#include "2d/CCSprite.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
@ -203,12 +204,12 @@ void ImageView::ignoreContentAdaptWithSize(bool ignore)
|
|||
|
||||
void ImageView::setCapInsets(const Rect &capInsets)
|
||||
{
|
||||
_capInsets = capInsets;
|
||||
_capInsets = ui::Helper::restrictCapInsetRect(capInsets, _imageTextureSize);
|
||||
if (!_scale9Enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_imageRenderer->setCapInsets(capInsets);
|
||||
_imageRenderer->setCapInsets(_capInsets);
|
||||
}
|
||||
|
||||
const Rect& ImageView::getCapInsets()const
|
||||
|
|
|
@ -270,7 +270,7 @@ public:
|
|||
/**
|
||||
* force refresh widget layout
|
||||
*/
|
||||
void forceDoLayout();
|
||||
virtual void forceDoLayout();
|
||||
|
||||
/**
|
||||
* request to refresh widget layout
|
||||
|
|
|
@ -453,6 +453,17 @@ void ListView::refreshView()
|
|||
updateInnerContainerSize();
|
||||
}
|
||||
|
||||
void ListView::forceDoLayout()
|
||||
{
|
||||
if (_refreshViewDirty)
|
||||
{
|
||||
refreshView();
|
||||
_refreshViewDirty = false;
|
||||
}
|
||||
|
||||
this->_innerContainer->forceDoLayout();
|
||||
}
|
||||
|
||||
void ListView::doLayout()
|
||||
{
|
||||
Layout::doLayout();
|
||||
|
|
|
@ -162,6 +162,8 @@ public:
|
|||
|
||||
float getItemsMargin()const;
|
||||
|
||||
virtual void forceDoLayout()override;
|
||||
|
||||
virtual void doLayout() override;
|
||||
|
||||
virtual void addChild(Node* child)override;
|
||||
|
|
|
@ -23,6 +23,7 @@ THE SOFTWARE.
|
|||
****************************************************************************/
|
||||
|
||||
#include "ui/UILoadingBar.h"
|
||||
#include "ui/UIHelper.h"
|
||||
#include "ui/UIScale9Sprite.h"
|
||||
#include "2d/CCSprite.h"
|
||||
|
||||
|
@ -225,12 +226,12 @@ bool LoadingBar::isScale9Enabled()const
|
|||
|
||||
void LoadingBar::setCapInsets(const Rect &capInsets)
|
||||
{
|
||||
_capInsets = capInsets;
|
||||
_capInsets = ui::Helper::restrictCapInsetRect(capInsets, _barRendererTextureSize);
|
||||
if (!_scale9Enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_barRenderer->setCapInsets(capInsets);
|
||||
_barRenderer->setCapInsets(_capInsets);
|
||||
}
|
||||
|
||||
const Rect& LoadingBar::getCapInsets()const
|
||||
|
|
|
@ -24,6 +24,7 @@ THE SOFTWARE.
|
|||
|
||||
#include "ui/UISlider.h"
|
||||
#include "ui/UIScale9Sprite.h"
|
||||
#include "ui/UIHelper.h"
|
||||
#include "2d/CCSprite.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
@ -222,12 +223,12 @@ void Slider::setCapInsets(const Rect &capInsets)
|
|||
|
||||
void Slider::setCapInsetsBarRenderer(const Rect &capInsets)
|
||||
{
|
||||
_capInsetsBarRenderer = capInsets;
|
||||
_capInsetsBarRenderer = ui::Helper::restrictCapInsetRect(capInsets, _barRenderer->getContentSize());
|
||||
if (!_scale9Enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_barRenderer->setCapInsets(capInsets);
|
||||
_barRenderer->setCapInsets(_capInsetsBarRenderer);
|
||||
}
|
||||
|
||||
const Rect& Slider::getCapInsetsBarRenderer()const
|
||||
|
@ -237,12 +238,13 @@ const Rect& Slider::getCapInsetsBarRenderer()const
|
|||
|
||||
void Slider::setCapInsetProgressBarRebderer(const Rect &capInsets)
|
||||
{
|
||||
_capInsetsProgressBarRenderer = capInsets;
|
||||
_capInsetsProgressBarRenderer = ui::Helper::restrictCapInsetRect(capInsets, _progressBarRenderer->getContentSize());
|
||||
|
||||
if (!_scale9Enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_progressBarRenderer->setCapInsets(capInsets);
|
||||
_progressBarRenderer->setCapInsets(_capInsetsProgressBarRenderer);
|
||||
}
|
||||
|
||||
const Rect& Slider::getCapInsetsProgressBarRebderer()const
|
||||
|
|
|
@ -346,6 +346,8 @@
|
|||
"cocos/audio/wp8/MediaStreamer.cpp",
|
||||
"cocos/audio/wp8/MediaStreamer.h",
|
||||
"cocos/audio/wp8/SimpleAudioEngine.cpp",
|
||||
"cocos/base/CCAsyncTaskPool.cpp",
|
||||
"cocos/base/CCAsyncTaskPool.h",
|
||||
"cocos/base/CCAutoreleasePool.cpp",
|
||||
"cocos/base/CCAutoreleasePool.h",
|
||||
"cocos/base/CCConfiguration.cpp",
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
****************************************************************************/
|
||||
|
||||
#include "Sprite3DTest.h"
|
||||
#include "base/CCAsyncTaskPool.h"
|
||||
#include "3d/CCAnimation3D.h"
|
||||
#include "3d/CCAnimate3D.h"
|
||||
#include "3d/CCAttachNode.h"
|
||||
|
@ -49,6 +50,7 @@ static std::function<Layer*()> createFunctions[] =
|
|||
{
|
||||
CL(Sprite3DBasicTest),
|
||||
CL(Sprite3DHitTest),
|
||||
CL(AsyncLoadSprite3DTest),
|
||||
#if (CC_TARGET_PLATFORM != CC_PLATFORM_WP8) && (CC_TARGET_PLATFORM != CC_PLATFORM_WINRT)
|
||||
// 3DEffect use custom shader which is not supported on WP8/WinRT yet.
|
||||
CL(Sprite3DEffectTest),
|
||||
|
@ -1116,6 +1118,73 @@ void Sprite3DEffectTest::onTouchesEnded(const std::vector<Touch*>& touches, Even
|
|||
}
|
||||
}
|
||||
|
||||
AsyncLoadSprite3DTest::AsyncLoadSprite3DTest()
|
||||
{
|
||||
_paths.push_back("Sprite3DTest/boss.obj");
|
||||
_paths.push_back("Sprite3DTest/girl.c3b");
|
||||
_paths.push_back("Sprite3DTest/orc.c3b");
|
||||
_paths.push_back("Sprite3DTest/ReskinGirl.c3b");
|
||||
_paths.push_back("Sprite3DTest/axe.c3b");
|
||||
|
||||
TTFConfig ttfConfig("fonts/arial.ttf", 15);
|
||||
auto label1 = Label::createWithTTF(ttfConfig,"AsyncLoad Sprite3D");
|
||||
auto item1 = MenuItemLabel::create(label1,CC_CALLBACK_1(AsyncLoadSprite3DTest::menuCallback_asyncLoadSprite,this) );
|
||||
|
||||
auto s = Director::getInstance()->getWinSize();
|
||||
item1->setPosition( s.width * .5f, s.height * .8f);
|
||||
|
||||
auto pMenu1 = CCMenu::create(item1, nullptr);
|
||||
pMenu1->setPosition(Vec2(0,0));
|
||||
this->addChild(pMenu1, 10);
|
||||
|
||||
auto node = Node::create();
|
||||
node->setTag(101);
|
||||
this->addChild(node);
|
||||
|
||||
menuCallback_asyncLoadSprite(nullptr);
|
||||
}
|
||||
|
||||
AsyncLoadSprite3DTest::~AsyncLoadSprite3DTest()
|
||||
{
|
||||
}
|
||||
|
||||
std::string AsyncLoadSprite3DTest::title() const
|
||||
{
|
||||
return "Testing Sprite3D::createAsync";
|
||||
}
|
||||
std::string AsyncLoadSprite3DTest::subtitle() const
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
void AsyncLoadSprite3DTest::menuCallback_asyncLoadSprite(Ref* sender)
|
||||
{
|
||||
//Note that you must stop the tasks before leaving the scene.
|
||||
AsyncTaskPool::getInstance()->stopTasks(AsyncTaskPool::TaskType::TASK_IO);
|
||||
|
||||
auto node = getChildByTag(101);
|
||||
node->removeAllChildren(); //remove all loaded sprite
|
||||
|
||||
//remove cache data
|
||||
Sprite3DCache::getInstance()->removeAllSprite3DData();
|
||||
long index = 0;
|
||||
for (const auto& path : _paths) {
|
||||
Sprite3D::createAsync(path, CC_CALLBACK_2(AsyncLoadSprite3DTest::asyncLoad_Callback, this), (void*)index++);
|
||||
}
|
||||
}
|
||||
|
||||
void AsyncLoadSprite3DTest::asyncLoad_Callback(Sprite3D* sprite, void* param)
|
||||
{
|
||||
long index = (long)param;
|
||||
auto node = getChildByTag(101);
|
||||
auto s = Director::getInstance()->getWinSize();
|
||||
float width = s.width / _paths.size();
|
||||
Vec2 point(width * (0.5f + index), s.height / 2.f);
|
||||
sprite->setPosition(point);
|
||||
node->addChild(sprite);
|
||||
}
|
||||
|
||||
|
||||
Sprite3DWithSkinTest::Sprite3DWithSkinTest()
|
||||
{
|
||||
auto listener = EventListenerTouchAllAtOnce::create();
|
||||
|
|
|
@ -228,6 +228,23 @@ public:
|
|||
void onTouchesEnded(const std::vector<Touch*>& touches, Event* event);
|
||||
};
|
||||
|
||||
class AsyncLoadSprite3DTest : public Sprite3DTestDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(AsyncLoadSprite3DTest);
|
||||
AsyncLoadSprite3DTest();
|
||||
virtual ~AsyncLoadSprite3DTest();
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
|
||||
void menuCallback_asyncLoadSprite(Ref* sender);
|
||||
|
||||
void asyncLoad_Callback(Sprite3D* sprite, void* param);
|
||||
|
||||
protected:
|
||||
std::vector<std::string> _paths; //model paths to be loaded
|
||||
};
|
||||
|
||||
class Sprite3DWithSkinTest : public Sprite3DTestDemo
|
||||
{
|
||||
public:
|
||||
|
|
Loading…
Reference in New Issue