1. move drawnode3d to Sprite3DTest

2. add getAABB to sprite3D and mesh
This commit is contained in:
lvlong 2014-08-08 17:54:39 +08:00
parent ceb6549ec8
commit 8101e2ff1a
11 changed files with 446 additions and 49 deletions

View File

@ -7867,7 +7867,6 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = YES;
ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
CLANG_CXX_LANGUAGE_STANDARD = "c++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_WARN_BOOL_CONVERSION = YES;
@ -7905,7 +7904,6 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = YES;
ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
CLANG_CXX_LANGUAGE_STANDARD = "c++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_WARN_BOOL_CONVERSION = YES;
@ -7940,7 +7938,6 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = YES;
ARCHS = "$(ARCHS_STANDARD)";
EXECUTABLE_EXTENSION = a;
EXECUTABLE_PREFIX = "";
GCC_PRECOMPILE_PREFIX_HEADER = YES;
@ -7973,7 +7970,6 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = YES;
ARCHS = "$(ARCHS_STANDARD)";
EXECUTABLE_EXTENSION = a;
EXECUTABLE_PREFIX = "";
GCC_GENERATE_DEBUGGING_SYMBOLS = NO;
@ -8006,7 +8002,6 @@
A03F2CB61780BD04006731B9 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD)";
EXECUTABLE_PREFIX = "";
GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS = NO;
HEADER_SEARCH_PATHS = "";
@ -8017,7 +8012,6 @@
A03F2CB71780BD04006731B9 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD)";
EXECUTABLE_PREFIX = "";
GCC_GENERATE_DEBUGGING_SYMBOLS = NO;
GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS = NO;
@ -8029,7 +8023,6 @@
A03F2D991780BDF7006731B9 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD)";
CLANG_WARN_BOOL_CONVERSION = NO;
CLANG_WARN_CONSTANT_CONVERSION = NO;
EXECUTABLE_PREFIX = "";
@ -8045,7 +8038,6 @@
A03F2D9A1780BDF7006731B9 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD)";
CLANG_WARN_BOOL_CONVERSION = NO;
CLANG_WARN_CONSTANT_CONVERSION = NO;
EXECUTABLE_PREFIX = "";
@ -8062,7 +8054,6 @@
A03F2E90178141C1006731B9 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD)";
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"COCOS2D_DEBUG=1",
@ -8079,7 +8070,6 @@
A03F2E91178141C1006731B9 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD)";
HEADER_SEARCH_PATHS = (
"$(inherited)",
"/Applications/Xcode\\ 2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include",
@ -8091,7 +8081,6 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = YES;
ARCHS = "$(ARCHS_STANDARD)";
EXECUTABLE_PREFIX = "";
GCC_PREPROCESSOR_DEFINITIONS = CC_TARGET_OS_MAC;
GCC_TREAT_WARNINGS_AS_ERRORS = NO;
@ -8104,7 +8093,6 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = YES;
ARCHS = "$(ARCHS_STANDARD)";
EXECUTABLE_PREFIX = "";
GCC_GENERATE_DEBUGGING_SYMBOLS = NO;
GCC_PREPROCESSOR_DEFINITIONS = CC_TARGET_OS_MAC;
@ -8118,7 +8106,6 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = YES;
ARCHS = "$(ARCHS_STANDARD)";
CODE_SIGN_IDENTITY = "";
EXECUTABLE_PREFIX = "";
GCC_PREPROCESSOR_DEFINITIONS = (
@ -8137,7 +8124,6 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = YES;
ARCHS = "$(ARCHS_STANDARD)";
CODE_SIGN_IDENTITY = "";
EXECUTABLE_PREFIX = "";
GCC_GENERATE_DEBUGGING_SYMBOLS = NO;
@ -8157,7 +8143,6 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = YES;
ARCHS = "$(ARCHS_STANDARD)";
EXECUTABLE_PREFIX = "";
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "../cocos/cocos2d-prefix.pch";
@ -8187,7 +8172,6 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = YES;
ARCHS = "$(ARCHS_STANDARD)";
EXECUTABLE_PREFIX = "";
GCC_GENERATE_DEBUGGING_SYMBOLS = NO;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
@ -8217,7 +8201,6 @@
A07A4E0D178386390073F6A7 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)";
IPHONEOS_DEPLOYMENT_TARGET = 5.1;
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
@ -8227,7 +8210,6 @@
A07A4E0E178386390073F6A7 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)";
IPHONEOS_DEPLOYMENT_TARGET = 5.1;
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
@ -8238,7 +8220,6 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = YES;
ARCHS = "$(ARCHS_STANDARD)";
EXECUTABLE_PREFIX = "";
GCC_PREPROCESSOR_DEFINITIONS = (
"$(inherited)",
@ -8258,7 +8239,6 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = YES;
ARCHS = "$(ARCHS_STANDARD)";
EXECUTABLE_PREFIX = "";
GCC_GENERATE_DEBUGGING_SYMBOLS = NO;
GCC_PREPROCESSOR_DEFINITIONS = (
@ -8278,7 +8258,6 @@
A07A4F39178387670073F6A7 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD)";
EXECUTABLE_PREFIX = "";
HEADER_SEARCH_PATHS = "";
IPHONEOS_DEPLOYMENT_TARGET = 5.1.1;
@ -8291,7 +8270,6 @@
A07A4F3A178387670073F6A7 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD)";
EXECUTABLE_PREFIX = "";
GCC_GENERATE_DEBUGGING_SYMBOLS = NO;
HEADER_SEARCH_PATHS = "";
@ -8305,7 +8283,6 @@
A07A4F9C1783876B0073F6A7 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD)";
CLANG_WARN_BOOL_CONVERSION = NO;
CLANG_WARN_CONSTANT_CONVERSION = NO;
EXECUTABLE_PREFIX = "";
@ -8324,7 +8301,6 @@
A07A4F9D1783876B0073F6A7 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD)";
CLANG_WARN_BOOL_CONVERSION = NO;
CLANG_WARN_CONSTANT_CONVERSION = NO;
EXECUTABLE_PREFIX = "";
@ -8345,7 +8321,6 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = YES;
ARCHS = "$(ARCHS_STANDARD)";
EXECUTABLE_PREFIX = "";
GCC_PREPROCESSOR_DEFINITIONS = (
"$(inherited)",
@ -8364,7 +8339,6 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = YES;
ARCHS = "$(ARCHS_STANDARD)";
EXECUTABLE_PREFIX = "";
GCC_GENERATE_DEBUGGING_SYMBOLS = NO;
GCC_PREPROCESSOR_DEFINITIONS = (
@ -8384,7 +8358,6 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = YES;
ARCHS = "$(ARCHS_STANDARD)";
EXECUTABLE_PREFIX = "";
GCC_PREPROCESSOR_DEFINITIONS = (
"$(inherited)",
@ -8403,7 +8376,6 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = YES;
ARCHS = "$(ARCHS_STANDARD)";
EXECUTABLE_PREFIX = "";
GCC_GENERATE_DEBUGGING_SYMBOLS = NO;
GCC_PREPROCESSOR_DEFINITIONS = (
@ -8423,7 +8395,6 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = YES;
ARCHS = "$(ARCHS_STANDARD)";
EXECUTABLE_PREFIX = "";
GCC_PREPROCESSOR_DEFINITIONS = (
"$(inherited)",
@ -8444,7 +8415,6 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = YES;
ARCHS = "$(ARCHS_STANDARD)";
EXECUTABLE_PREFIX = "";
GCC_GENERATE_DEBUGGING_SYMBOLS = NO;
GCC_PREPROCESSOR_DEFINITIONS = (
@ -8466,7 +8436,6 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = YES;
ARCHS = "$(ARCHS_STANDARD)";
EXECUTABLE_PREFIX = "";
GCC_PREPROCESSOR_DEFINITIONS = (
"$(inherited)",
@ -8487,7 +8456,6 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = YES;
ARCHS = "$(ARCHS_STANDARD)";
EXECUTABLE_PREFIX = "";
GCC_GENERATE_DEBUGGING_SYMBOLS = NO;
GCC_PREPROCESSOR_DEFINITIONS = (
@ -8509,7 +8477,6 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = YES;
ARCHS = "$(ARCHS_STANDARD)";
EXECUTABLE_PREFIX = "";
GCC_PREPROCESSOR_DEFINITIONS = (
"$(inherited)",
@ -8530,7 +8497,6 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = YES;
ARCHS = "$(ARCHS_STANDARD)";
EXECUTABLE_PREFIX = "";
GCC_GENERATE_DEBUGGING_SYMBOLS = NO;
GCC_PREPROCESSOR_DEFINITIONS = (
@ -8552,7 +8518,6 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = YES;
ARCHS = "$(ARCHS_STANDARD)";
EXECUTABLE_PREFIX = "";
GCC_PREPROCESSOR_DEFINITIONS = (
"$(inherited)",
@ -8573,7 +8538,6 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = YES;
ARCHS = "$(ARCHS_STANDARD)";
EXECUTABLE_PREFIX = "";
GCC_GENERATE_DEBUGGING_SYMBOLS = NO;
GCC_PREPROCESSOR_DEFINITIONS = (
@ -8595,7 +8559,6 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = YES;
ARCHS = "$(ARCHS_STANDARD)";
EXECUTABLE_PREFIX = "";
GCC_PREPROCESSOR_DEFINITIONS = (
"$(inherited)",
@ -8619,7 +8582,6 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = YES;
ARCHS = "$(ARCHS_STANDARD)";
EXECUTABLE_PREFIX = "";
GCC_GENERATE_DEBUGGING_SYMBOLS = NO;
GCC_PREPROCESSOR_DEFINITIONS = (
@ -8644,7 +8606,6 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = YES;
ARCHS = "$(ARCHS_STANDARD)";
EXECUTABLE_PREFIX = "";
GCC_PREPROCESSOR_DEFINITIONS = (
"$(inherited)",
@ -8663,7 +8624,6 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = YES;
ARCHS = "$(ARCHS_STANDARD)";
EXECUTABLE_PREFIX = "";
GCC_GENERATE_DEBUGGING_SYMBOLS = NO;
GCC_PREPROCESSOR_DEFINITIONS = (
@ -8683,7 +8643,6 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = YES;
ARCHS = "$(ARCHS_STANDARD)";
EXECUTABLE_PREFIX = "";
GCC_PREPROCESSOR_DEFINITIONS = (
"$(inherited)",
@ -8702,7 +8661,6 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = YES;
ARCHS = "$(ARCHS_STANDARD)";
EXECUTABLE_PREFIX = "";
GCC_GENERATE_DEBUGGING_SYMBOLS = NO;
GCC_PREPROCESSOR_DEFINITIONS = (
@ -8722,7 +8680,6 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = YES;
ARCHS = "$(ARCHS_STANDARD)";
EXECUTABLE_PREFIX = "";
GCC_PREPROCESSOR_DEFINITIONS = (
"$(inherited)",
@ -8741,7 +8698,6 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = YES;
ARCHS = "$(ARCHS_STANDARD)";
EXECUTABLE_PREFIX = "";
GCC_GENERATE_DEBUGGING_SYMBOLS = NO;
GCC_PREPROCESSOR_DEFINITIONS = (
@ -8761,7 +8717,6 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = YES;
ARCHS = "$(ARCHS_STANDARD)";
EXECUTABLE_PREFIX = "";
GCC_PREPROCESSOR_DEFINITIONS = (
"$(inherited)",
@ -8783,7 +8738,6 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = YES;
ARCHS = "$(ARCHS_STANDARD)";
EXECUTABLE_PREFIX = "";
GCC_GENERATE_DEBUGGING_SYMBOLS = NO;
GCC_PREPROCESSOR_DEFINITIONS = (

View File

@ -969,6 +969,8 @@
3EA0FB72191C844400B170C8 /* UIVideoPlayerTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3EA0FB70191C844400B170C8 /* UIVideoPlayerTest.cpp */; };
59620E8F1921E5CF002021B6 /* Bug-Child.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 59620E8D1921E5CF002021B6 /* Bug-Child.cpp */; };
59620E901921E5CF002021B6 /* Bug-Child.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 59620E8D1921E5CF002021B6 /* Bug-Child.cpp */; };
5EBEECB01995247000429821 /* DrawNode3D.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5EBEECAE1995247000429821 /* DrawNode3D.cpp */; };
5EBEECB11995247000429821 /* DrawNode3D.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5EBEECAE1995247000429821 /* DrawNode3D.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 */; };
@ -3659,6 +3661,8 @@
46A15F9C1807A4F8005B8026 /* cocos2d_libs.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; path = cocos2d_libs.xcodeproj; sourceTree = "<group>"; };
59620E8D1921E5CF002021B6 /* Bug-Child.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = "Bug-Child.cpp"; sourceTree = "<group>"; };
59620E8E1921E5CF002021B6 /* Bug-Child.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "Bug-Child.h"; sourceTree = "<group>"; };
5EBEECAE1995247000429821 /* DrawNode3D.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DrawNode3D.cpp; path = Sprite3DTest/DrawNode3D.cpp; sourceTree = "<group>"; };
5EBEECAF1995247000429821 /* DrawNode3D.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DrawNode3D.h; path = Sprite3DTest/DrawNode3D.h; sourceTree = "<group>"; };
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>"; };
A035A71117822E9E00987F6C /* libsqlite3.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libsqlite3.dylib; path = usr/lib/libsqlite3.dylib; sourceTree = SDKROOT; };
@ -7891,6 +7895,8 @@
3E92EA7D1921A0C60094CD21 /* Sprite3DTest */ = {
isa = PBXGroup;
children = (
5EBEECAE1995247000429821 /* DrawNode3D.cpp */,
5EBEECAF1995247000429821 /* DrawNode3D.h */,
3E92EA801921A1400094CD21 /* Sprite3DTest.cpp */,
3E92EA811921A1400094CD21 /* Sprite3DTest.h */,
);
@ -9154,6 +9160,7 @@
29080DC3191B595E0066F8DF /* UIScene.cpp in Sources */,
29080D9B191B595E0066F8DF /* CustomParticleWidget.cpp in Sources */,
29080D8D191B595E0066F8DF /* CocosGUIScene.cpp in Sources */,
5EBEECB01995247000429821 /* DrawNode3D.cpp in Sources */,
1AC35BED18CECF0C00F37B72 /* CCControlStepperTest.cpp in Sources */,
1AC35C3318CECF0C00F37B72 /* PerformanceScenarioTest.cpp in Sources */,
1AC35C5918CECF0C00F37B72 /* TextureAtlasEncryptionTest.cpp in Sources */,
@ -9248,6 +9255,7 @@
29080DB4191B595E0066F8DF /* UILayoutTest_Editor.cpp in Sources */,
1AC35C4E18CECF0C00F37B72 /* SpineTest.cpp in Sources */,
1AC35C1E18CECF0C00F37B72 /* NewRendererTest.cpp in Sources */,
5EBEECB11995247000429821 /* DrawNode3D.cpp in Sources */,
1AC35B6818CECF0C00F37B72 /* AnimationsTestLayer.cpp in Sources */,
29080D8E191B595E0066F8DF /* CocosGUIScene.cpp in Sources */,
1AC35BFA18CECF0C00F37B72 /* WebSocketTest.cpp in Sources */,

View File

@ -207,6 +207,9 @@ bool Mesh::init(const std::vector<float>& positions, const std::vector<float>& n
buildSubMeshes();
buildBuffer();
calcuOriginAABB(positions, 3);
return true;
}
@ -220,6 +223,10 @@ bool Mesh::init(const std::vector<float>& vertices, int vertexSizeInFloat, const
buildSubMeshes();
buildBuffer();
unsigned int perVertexSize = _renderdata.calVertexSizeBytes() / sizeof(float);
calcuOriginAABB(vertices, perVertexSize);
return true;
}
@ -245,6 +252,16 @@ void Mesh::cleanAndFreeBuffers()
}
}
void Mesh::calcuOriginAABB(const std::vector<float>& vertices, unsigned int stride)
{
ssize_t vertexNum = vertices.size() / stride;
for(unsigned int i = 0; i < vertexNum; i++)
{
Vec3 point = Vec3(vertices[i * stride], vertices[i * stride + 1], vertices[i * stride + 2]);
_originAABB.updateMinMax(&point, 1);
}
}
void Mesh::buildBuffer()
{
cleanAndFreeBuffers();
@ -273,6 +290,11 @@ void Mesh::restore()
buildBuffer();
}
const AABB& Mesh::getOriginAABB() const
{
return _originAABB;
}
/**
* MeshCache
*/

View File

@ -37,6 +37,9 @@
#include "math/CCMath.h"
#include "renderer/CCGLProgram.h"
#include "CCAABB.h"
NS_CC_BEGIN
class EventListenerCustom;
@ -121,6 +124,9 @@ public:
/**build vertex buffer from renderdata*/
void restore();
/** get origin aabb that calculate from vertices*/
const AABB& getOriginAABB() const;
/**to be deprecated, those functions have been moved to SubMesh*/
/** get primitive type*/
CC_DEPRECATED_ATTRIBUTE PrimitiveType getPrimitiveType() const { return _subMeshes.at(0)->getPrimitiveType(); }
@ -147,12 +153,21 @@ CC_CONSTRUCTOR_ACCESS:
void buildBuffer();
/**free buffer*/
void cleanAndFreeBuffers();
/*
* calculate AABB by origin vertices
* @param the vertices list
* @param stride the stride between two vertex's position data.
*/
void calcuOriginAABB(const std::vector<float>& vertices, unsigned int stride);
protected:
GLuint _vertexBuffer;
Vector<SubMesh*> _subMeshes;
RenderMeshData _renderdata;
AABB _originAABB;
};
/**

View File

@ -399,4 +399,29 @@ const BlendFunc& Sprite3D::getBlendFunc() const
return _blend;
}
AABB Sprite3D::getAABB() const
{
AABB aabb = _mesh->getOriginAABB();
Mat4 transform;
if (getSkin() && getSkin()->getRootBone())
{
transform = getNodeToWorldTransform() * getSkin()->getRootBone()->getWorldMat();
}
else
{
transform = getNodeToWorldTransform();
}
aabb.transform(transform);
return aabb;
}
Rect Sprite3D::getBoundingBox() const
{
AABB aabb = getAABB();
Rect ret(aabb._min.x, aabb._min.y, (aabb._max.x - aabb._min.x), (aabb._max.y - aabb._min.y));
return ret;
}
NS_CC_END

View File

@ -33,6 +33,7 @@
#include "base/CCProtocols.h"
#include "2d/CCNode.h"
#include "renderer/CCMeshCommand.h"
#include "CCAABB.h"
NS_CC_BEGIN
@ -79,6 +80,20 @@ public:
// overrides
virtual void setBlendFunc(const BlendFunc &blendFunc) override;
virtual const BlendFunc &getBlendFunc() const override;
/*
* Get AABB
* If the sprite has animation, it can't be calculated accuratly,
* because bone can drive the vertices, we just use the origin vertices
* to calculate the AABB.
*/
AABB getAABB() const;
/**
* Returns 2d bounding-box
* Note: the bouding-box is just get from the AABB which as Z=0, so that is not very accurate.
*/
virtual Rect getBoundingBox() const override;
CC_CONSTRUCTOR_ACCESS:

View File

@ -168,6 +168,7 @@ Classes/ShaderTest/ShaderTest.cpp \
Classes/ShaderTest/ShaderTest2.cpp \
Classes/SpineTest/SpineTest.cpp \
Classes/SpriteTest/SpriteTest.cpp \
Classes/Sprite3DTest/DrawNode3D.cpp \
Classes/Sprite3DTest/Sprite3DTest.cpp \
Classes/TextInputTest/TextInputTest.cpp \
Classes/Texture2dTest/Texture2dTest.cpp \

View File

@ -0,0 +1,240 @@
/****************************************************************************
Copyright (c) 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 "DrawNode3D.h"
#include "CCGL.h"
#include "base/CCEventType.h"
#include "base/CCConfiguration.h"
#include "renderer/CCCustomCommand.h"
#include "renderer/CCRenderer.h"
#include "renderer/CCGLProgramState.h"
#include "base/CCDirector.h"
#include "base/CCEventListenerCustom.h"
#include "base/CCEventDispatcher.h"
NS_CC_BEGIN
DrawNode3D::DrawNode3D()
: _vao(0)
, _vbo(0)
, _bufferCapacity(0)
, _bufferCount(0)
, _buffer(nullptr)
, _dirty(false)
{
_blendFunc = BlendFunc::ALPHA_PREMULTIPLIED;
}
DrawNode3D::~DrawNode3D()
{
free(_buffer);
_buffer = nullptr;
glDeleteBuffers(1, &_vbo);
_vbo = 0;
if (Configuration::getInstance()->supportsShareableVAO())
{
glDeleteVertexArrays(1, &_vao);
GL::bindVAO(0);
_vao = 0;
}
}
DrawNode3D* DrawNode3D::create()
{
DrawNode3D* ret = new DrawNode3D();
if (ret && ret->init())
{
ret->autorelease();
}
else
{
CC_SAFE_DELETE(ret);
}
return ret;
}
void DrawNode3D::ensureCapacity(int count)
{
CCASSERT(count>=0, "capacity must be >= 0");
if(_bufferCount + count > _bufferCapacity)
{
_bufferCapacity += MAX(_bufferCapacity, count);
_buffer = (V3F_C4B*)realloc(_buffer, _bufferCapacity*sizeof(V3F_C4B));
}
}
bool DrawNode3D::init()
{
_blendFunc = BlendFunc::ALPHA_PREMULTIPLIED;
setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_COLOR));
ensureCapacity(512);
if (Configuration::getInstance()->supportsShareableVAO())
{
glGenVertexArrays(1, &_vao);
GL::bindVAO(_vao);
}
glGenBuffers(1, &_vbo);
glBindBuffer(GL_ARRAY_BUFFER, _vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(V3F_C4B)* _bufferCapacity, _buffer, GL_STREAM_DRAW);
glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_POSITION);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 3, GL_FLOAT, GL_FALSE, sizeof(V3F_C4B), (GLvoid *)offsetof(V3F_C4B, vertices));
glEnableVertexAttribArray(GLProgram::VERTEX_ATTRIB_COLOR);
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(V3F_C4B), (GLvoid *)offsetof(V3F_C4B, colors));
glBindBuffer(GL_ARRAY_BUFFER, 0);
if (Configuration::getInstance()->supportsShareableVAO())
{
GL::bindVAO(0);
}
CHECK_GL_ERROR_DEBUG();
_dirty = true;
#if CC_ENABLE_CACHE_TEXTURE_DATA
// Need to listen the event only when not use batchnode, because it will use VBO
auto listener = EventListenerCustom::create(EVENT_COME_TO_FOREGROUND, [this](EventCustom* event){
/** listen the event that coming to foreground on Android */
this->init();
});
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
#endif
return true;
}
void DrawNode3D::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
{
_customCommand.init(_globalZOrder);
_customCommand.func = CC_CALLBACK_0(DrawNode3D::onDraw, this, transform, flags);
renderer->addCommand(&_customCommand);
}
void DrawNode3D::onDraw(const Mat4 &transform, uint32_t flags)
{
auto glProgram = getGLProgram();
glProgram->use();
glProgram->setUniformsForBuiltins(transform);
glEnable(GL_DEPTH_TEST);
GL::blendFunc(_blendFunc.src, _blendFunc.dst);
if (_dirty)
{
glBindBuffer(GL_ARRAY_BUFFER, _vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(V3F_C4B)*_bufferCapacity, _buffer, GL_STREAM_DRAW);
_dirty = false;
}
if (Configuration::getInstance()->supportsShareableVAO())
{
GL::bindVAO(_vao);
}
else
{
GL::enableVertexAttribs(GL::VERTEX_ATTRIB_FLAG_POS_COLOR_TEX);
glBindBuffer(GL_ARRAY_BUFFER, _vbo);
// vertex
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 3, GL_FLOAT, GL_FALSE, sizeof(V3F_C4B), (GLvoid *)offsetof(V3F_C4B, vertices));
// color
glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(V3F_C4B), (GLvoid *)offsetof(V3F_C4B, colors));
}
glDrawArrays(GL_LINES, 0, _bufferCount);
glBindBuffer(GL_ARRAY_BUFFER, 0);
CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1,_bufferCount);
glDisable(GL_DEPTH_TEST);
CHECK_GL_ERROR_DEBUG();
}
void DrawNode3D::drawLine(const Vec3 &from, const Vec3 &to, const Color4F &color)
{
unsigned int vertex_count = 2;
ensureCapacity(vertex_count);
Color4B col = Color4B(color);
V3F_C4B a = {Vec3(from.x, from.y, from.z), col};
V3F_C4B b = {Vec3(to.x, to.y, to.z), col, };
V3F_C4B *lines = (V3F_C4B *)(_buffer + _bufferCount);
lines[0] = a;
lines[1] = b;
_bufferCount += vertex_count;
_dirty = true;
}
void DrawNode3D::drawCube(Vec3* vertices, const Color4F &color)
{
// front face
drawLine(vertices[0], vertices[1], color);
drawLine(vertices[1], vertices[2], color);
drawLine(vertices[2], vertices[3], color);
drawLine(vertices[3], vertices[0], color);
// back face
drawLine(vertices[4], vertices[5], color);
drawLine(vertices[5], vertices[6], color);
drawLine(vertices[6], vertices[7], color);
drawLine(vertices[7], vertices[4], color);
// edge
drawLine(vertices[0], vertices[7], color);
drawLine(vertices[1], vertices[6], color);
drawLine(vertices[2], vertices[5], color);
drawLine(vertices[3], vertices[4], color);
}
void DrawNode3D::clear()
{
_bufferCount = 0;
_dirty = true;
}
const BlendFunc& DrawNode3D::getBlendFunc() const
{
return _blendFunc;
}
void DrawNode3D::setBlendFunc(const BlendFunc &blendFunc)
{
_blendFunc = blendFunc;
}
NS_CC_END

View File

@ -0,0 +1,117 @@
/****************************************************************************
Copyright (c) 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 __DRAW_NODE_3D_H__
#define __DRAW_NODE_3D_H__
#include "2d/CCNode.h"
#include "base/ccTypes.h"
#include "renderer/CCCustomCommand.h"
NS_CC_BEGIN
/**
* Copy DrawNode for 3D geometry drawing.
*/
class DrawNode3D: public Node
{
public:
/** creates and initialize a DrawNode3D node */
static DrawNode3D* create();
/**
* Draw 3D Line
*/
void drawLine(const Vec3 &from, const Vec3 &to, const Color4F &color);
/**
* Draw 3D cube
* @param point to a vertex array who has 8 element.
* vertices[0]:Left-top-front,
* vertices[1]:Left-bottom-front,
* vertices[2]:Right-bottom-front,
* vertices[3]:Right-top-front,
* vertices[4]:Right-top-back,
* vertices[5]:Right-bottom-back,
* vertices[6]:Left-bottom-back,
* vertices[7]:Left-top-back.
* @param color
*/
void drawCube(Vec3* vertices, const Color4F &color);
/** Clear the geometry in the node's buffer. */
void clear();
/**
* @js NA
* @lua NA
*/
const BlendFunc& getBlendFunc() const;
/**
* @code
* When this function bound into js or lua,the parameter will be changed
* In js: var setBlendFunc(var src, var dst)
* @endcode
* @lua NA
*/
void setBlendFunc(const BlendFunc &blendFunc);
void onDraw(const Mat4 &transform, uint32_t flags);
// Overrides
virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) override;
CC_CONSTRUCTOR_ACCESS:
DrawNode3D();
virtual ~DrawNode3D();
virtual bool init();
protected:
struct V3F_C4B
{
Vec3 vertices;
Color4B colors;
};
void ensureCapacity(int count);
GLuint _vao;
GLuint _vbo;
int _bufferCapacity;
GLsizei _bufferCount;
V3F_C4B* _buffer;
BlendFunc _blendFunc;
CustomCommand _customCommand;
bool _dirty;
private:
CC_DISALLOW_COPY_AND_ASSIGN(DrawNode3D);
};
NS_CC_END
#endif // __DRAW_NODE_3D_H__

View File

@ -29,6 +29,7 @@
#include "3d/CCSubMesh.h"
#include "3d/CCAttachNode.h"
#include "3d/CCRay.h"
#include "DrawNode3D.h"
#include <algorithm>
#include "../testResource.h"
@ -1026,9 +1027,7 @@ void Sprite3DWithOBBPerfromanceTest::addNewSpriteWithCoords(Vec2 p)
seq->setTag(100);
sprite->runAction(seq);
//Generate OBB by AABB
Vec3 extents = Vec3(50, 25, 25);
AABB aabb(-extents, extents);
AABB aabb = _sprite->getAABB();
_obbt = OBB(aabb);
_drawDebug = DrawNode3D::create();

View File

@ -34,6 +34,7 @@ namespace cocos2d {
class Sprite3D;
class Delay;
class Ray;
class DrawNode3D;
}
class Sprite3DTestDemo : public BaseTest