mirror of https://github.com/axmolengine/axmol.git
[IMPROVMENT] Change class name `Sprite3D` to `MeshRenderer` (#705)
* First draft [skip ci] * Improve comments [skip ci] * Rename MeshRendererMaterial to MeshMaterial [skip ci] * Update dependent classes. * Replace occurrences of Sprite3D with MeshRenderer. * Update cpp-tests and extensions. * Fix compilation. * Try fixing lua-bindings * Try fixing lua-bindings * Update lua_cocos2dx_3d_manual.cpp [skip ci] * Create RENAMED_TYPES.md
This commit is contained in:
parent
5edbfa5448
commit
656babac78
|
@ -0,0 +1,8 @@
|
|||
adxe-1.0 ??
|
||||
|
||||
### Classes & Types
|
||||
* ```Sprite3D``` => ```MeshRenderer```
|
||||
|
||||
### Functions & Methods
|
||||
* ```Director::isDisplayStats()``` => ```Director::isStatsDisplay()```
|
||||
|
|
@ -24,7 +24,7 @@
|
|||
****************************************************************************/
|
||||
|
||||
#include "3d/CCAnimate3D.h"
|
||||
#include "3d/CCSprite3D.h"
|
||||
#include "3d/CCMeshRenderer.h"
|
||||
#include "3d/CCSkeleton3D.h"
|
||||
#include "platform/CCFileUtils.h"
|
||||
#include "base/CCConfiguration.h"
|
||||
|
@ -156,9 +156,9 @@ void Animate3D::startWithTarget(Node* target)
|
|||
_nodeCurves.clear();
|
||||
|
||||
bool hasCurve = false;
|
||||
Sprite3D* sprite = dynamic_cast<Sprite3D*>(target);
|
||||
MeshRenderer* mesh = dynamic_cast<MeshRenderer*>(target);
|
||||
|
||||
if (sprite)
|
||||
if (mesh)
|
||||
{
|
||||
if (_animation)
|
||||
{
|
||||
|
@ -166,7 +166,7 @@ void Animate3D::startWithTarget(Node* target)
|
|||
for (const auto& iter : boneCurves)
|
||||
{
|
||||
std::string_view boneName = iter.first;
|
||||
auto skin = sprite->getSkeleton();
|
||||
auto skin = mesh->getSkeleton();
|
||||
if (skin)
|
||||
{
|
||||
auto bone = skin->getBoneByName(boneName);
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
NS_CC_BEGIN
|
||||
|
||||
class Bone3D;
|
||||
class Sprite3D;
|
||||
class MeshRenderer;
|
||||
class EventCustom;
|
||||
|
||||
enum class Animate3DQuality
|
||||
|
@ -54,7 +54,7 @@ enum class Animate3DQuality
|
|||
*/
|
||||
|
||||
/**
|
||||
* @brief Animate3D, Animates a Sprite3D given with an Animation3D
|
||||
* @brief Animate3D, Animates a MeshRenderer given with an Animation3D
|
||||
*/
|
||||
class CC_DLL Animate3D : public ActionInterval
|
||||
{
|
||||
|
@ -174,7 +174,7 @@ protected:
|
|||
std::unordered_map<int, EventCustom*> _keyFrameEvent;
|
||||
std::unordered_map<int, Animate3DDisplayedEventInfo> _displayedEventInfo;
|
||||
|
||||
// sprite animates
|
||||
// mesh animations
|
||||
static std::unordered_map<Node*, Animate3D*> s_fadeInAnimates;
|
||||
static std::unordered_map<Node*, Animate3D*> s_fadeOutAnimates;
|
||||
static std::unordered_map<Node*, Animate3D*> s_runningAnimates;
|
||||
|
|
|
@ -38,9 +38,9 @@ class Bone3D;
|
|||
|
||||
/**
|
||||
* @brief attach a node to a bone
|
||||
* usage: auto sprite = Sprite3D::create("girl.c3b");
|
||||
* auto weapon = Sprite3D::create("weapon.c3b");
|
||||
* auto attachNode = sprite->getAttachNode("left hand");
|
||||
* usage: auto mesh = MeshRenderer::create("girl.c3b");
|
||||
* auto weapon = MeshRenderer::create("weapon.c3b");
|
||||
* auto attachNode = mesh->getAttachNode("left hand");
|
||||
* attachNode->addChild(weapon);
|
||||
*/
|
||||
class CC_DLL AttachNode : public Node
|
||||
|
|
|
@ -109,7 +109,7 @@ struct NodeData
|
|||
struct NodeDatas
|
||||
{
|
||||
std::vector<NodeData*> skeleton; // skeleton
|
||||
std::vector<NodeData*> nodes; // nodes, CCNode, Sprite3D or part of Sprite3D
|
||||
std::vector<NodeData*> nodes; // nodes, CCNode, MeshRenderer or parts of MeshRenderer
|
||||
|
||||
virtual ~NodeDatas() { resetData(); }
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@ class Buffer;
|
|||
*/
|
||||
class CC_DLL Mesh : public Ref
|
||||
{
|
||||
friend class Sprite3D;
|
||||
friend class MeshRenderer;
|
||||
|
||||
public:
|
||||
typedef std::vector<unsigned short> IndexArray;
|
||||
|
@ -234,7 +234,7 @@ public:
|
|||
void calculateAABB();
|
||||
|
||||
/**
|
||||
* force set this Sprite3D to 2D render queue
|
||||
* force set this Mesh renderer to 2D render queue
|
||||
*/
|
||||
void setForce2DQueue(bool force2D) { _force2DQueue = force2D; }
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "3d/CCSprite3DMaterial.h"
|
||||
#include "3d/CCMeshMaterial.h"
|
||||
#include "3d/CCMesh.h"
|
||||
#include "platform/CCFileUtils.h"
|
||||
#include "renderer/CCTexture2D.h"
|
||||
|
@ -36,102 +36,102 @@
|
|||
|
||||
NS_CC_BEGIN
|
||||
|
||||
Sprite3DMaterialCache* Sprite3DMaterialCache::_cacheInstance = nullptr;
|
||||
MeshMaterialCache* MeshMaterialCache::_cacheInstance = nullptr;
|
||||
|
||||
std::unordered_map<std::string, Sprite3DMaterial*> Sprite3DMaterial::_materials;
|
||||
Sprite3DMaterial* Sprite3DMaterial::_unLitMaterial = nullptr;
|
||||
Sprite3DMaterial* Sprite3DMaterial::_unLitNoTexMaterial = nullptr;
|
||||
Sprite3DMaterial* Sprite3DMaterial::_vertexLitMaterial = nullptr;
|
||||
Sprite3DMaterial* Sprite3DMaterial::_diffuseMaterial = nullptr;
|
||||
Sprite3DMaterial* Sprite3DMaterial::_diffuseNoTexMaterial = nullptr;
|
||||
Sprite3DMaterial* Sprite3DMaterial::_bumpedDiffuseMaterial = nullptr;
|
||||
std::unordered_map<std::string, MeshMaterial*> MeshMaterial::_materials;
|
||||
MeshMaterial* MeshMaterial::_unLitMaterial = nullptr;
|
||||
MeshMaterial* MeshMaterial::_unLitNoTexMaterial = nullptr;
|
||||
MeshMaterial* MeshMaterial::_vertexLitMaterial = nullptr;
|
||||
MeshMaterial* MeshMaterial::_diffuseMaterial = nullptr;
|
||||
MeshMaterial* MeshMaterial::_diffuseNoTexMaterial = nullptr;
|
||||
MeshMaterial* MeshMaterial::_bumpedDiffuseMaterial = nullptr;
|
||||
|
||||
Sprite3DMaterial* Sprite3DMaterial::_unLitMaterialSkin = nullptr;
|
||||
Sprite3DMaterial* Sprite3DMaterial::_vertexLitMaterialSkin = nullptr;
|
||||
Sprite3DMaterial* Sprite3DMaterial::_diffuseMaterialSkin = nullptr;
|
||||
Sprite3DMaterial* Sprite3DMaterial::_bumpedDiffuseMaterialSkin = nullptr;
|
||||
MeshMaterial* MeshMaterial::_unLitMaterialSkin = nullptr;
|
||||
MeshMaterial* MeshMaterial::_vertexLitMaterialSkin = nullptr;
|
||||
MeshMaterial* MeshMaterial::_diffuseMaterialSkin = nullptr;
|
||||
MeshMaterial* MeshMaterial::_bumpedDiffuseMaterialSkin = nullptr;
|
||||
|
||||
backend::ProgramState* Sprite3DMaterial::_unLitMaterialProgState = nullptr;
|
||||
backend::ProgramState* Sprite3DMaterial::_unLitNoTexMaterialProgState = nullptr;
|
||||
backend::ProgramState* Sprite3DMaterial::_vertexLitMaterialProgState = nullptr;
|
||||
backend::ProgramState* Sprite3DMaterial::_diffuseMaterialProgState = nullptr;
|
||||
backend::ProgramState* Sprite3DMaterial::_diffuseNoTexMaterialProgState = nullptr;
|
||||
backend::ProgramState* Sprite3DMaterial::_bumpedDiffuseMaterialProgState = nullptr;
|
||||
backend::ProgramState* MeshMaterial::_unLitMaterialProgState = nullptr;
|
||||
backend::ProgramState* MeshMaterial::_unLitNoTexMaterialProgState = nullptr;
|
||||
backend::ProgramState* MeshMaterial::_vertexLitMaterialProgState = nullptr;
|
||||
backend::ProgramState* MeshMaterial::_diffuseMaterialProgState = nullptr;
|
||||
backend::ProgramState* MeshMaterial::_diffuseNoTexMaterialProgState = nullptr;
|
||||
backend::ProgramState* MeshMaterial::_bumpedDiffuseMaterialProgState = nullptr;
|
||||
|
||||
backend::ProgramState* Sprite3DMaterial::_unLitMaterialSkinProgState = nullptr;
|
||||
backend::ProgramState* Sprite3DMaterial::_vertexLitMaterialSkinProgState = nullptr;
|
||||
backend::ProgramState* Sprite3DMaterial::_diffuseMaterialSkinProgState = nullptr;
|
||||
backend::ProgramState* Sprite3DMaterial::_bumpedDiffuseMaterialSkinProgState = nullptr;
|
||||
backend::ProgramState* MeshMaterial::_unLitMaterialSkinProgState = nullptr;
|
||||
backend::ProgramState* MeshMaterial::_vertexLitMaterialSkinProgState = nullptr;
|
||||
backend::ProgramState* MeshMaterial::_diffuseMaterialSkinProgState = nullptr;
|
||||
backend::ProgramState* MeshMaterial::_bumpedDiffuseMaterialSkinProgState = nullptr;
|
||||
|
||||
void Sprite3DMaterial::createBuiltInMaterial()
|
||||
void MeshMaterial::createBuiltInMaterial()
|
||||
{
|
||||
auto* program = backend::Program::getBuiltinProgram(backend::ProgramType::SKINPOSITION_TEXTURE_3D);
|
||||
_unLitMaterialSkinProgState = new backend::ProgramState(program);
|
||||
_unLitMaterialSkin = new Sprite3DMaterial();
|
||||
_unLitMaterialSkin = new MeshMaterial();
|
||||
if (_unLitMaterialSkin && _unLitMaterialSkin->initWithProgramState(_unLitMaterialSkinProgState))
|
||||
{
|
||||
_unLitMaterialSkin->_type = Sprite3DMaterial::MaterialType::UNLIT;
|
||||
_unLitMaterialSkin->_type = MeshMaterial::MaterialType::UNLIT;
|
||||
}
|
||||
|
||||
program = backend::Program::getBuiltinProgram(backend::ProgramType::SKINPOSITION_NORMAL_TEXTURE_3D);
|
||||
_diffuseMaterialSkinProgState = new backend::ProgramState(program);
|
||||
_diffuseMaterialSkin = new Sprite3DMaterial();
|
||||
_diffuseMaterialSkin = new MeshMaterial();
|
||||
if (_diffuseMaterialSkin && _diffuseMaterialSkin->initWithProgramState(_diffuseMaterialSkinProgState))
|
||||
{
|
||||
_diffuseMaterialSkin->_type = Sprite3DMaterial::MaterialType::DIFFUSE;
|
||||
_diffuseMaterialSkin->_type = MeshMaterial::MaterialType::DIFFUSE;
|
||||
}
|
||||
|
||||
program = backend::Program::getBuiltinProgram(backend::ProgramType::POSITION_NORMAL_TEXTURE_3D);
|
||||
_diffuseMaterialProgState = new backend::ProgramState(program);
|
||||
_diffuseMaterial = new Sprite3DMaterial();
|
||||
_diffuseMaterial = new MeshMaterial();
|
||||
if (_diffuseMaterial && _diffuseMaterial->initWithProgramState(_diffuseMaterialProgState))
|
||||
{
|
||||
_diffuseMaterial->_type = Sprite3DMaterial::MaterialType::DIFFUSE;
|
||||
_diffuseMaterial->_type = MeshMaterial::MaterialType::DIFFUSE;
|
||||
}
|
||||
|
||||
program = backend::Program::getBuiltinProgram(backend::ProgramType::POSITION_TEXTURE_3D);
|
||||
_unLitMaterialProgState = new backend::ProgramState(program);
|
||||
_unLitMaterial = new Sprite3DMaterial();
|
||||
_unLitMaterial = new MeshMaterial();
|
||||
if (_unLitMaterial && _unLitMaterial->initWithProgramState(_unLitMaterialProgState))
|
||||
{
|
||||
_unLitMaterial->_type = Sprite3DMaterial::MaterialType::UNLIT;
|
||||
_unLitMaterial->_type = MeshMaterial::MaterialType::UNLIT;
|
||||
}
|
||||
|
||||
program = backend::Program::getBuiltinProgram(backend::ProgramType::POSITION_3D);
|
||||
_unLitNoTexMaterialProgState = new backend::ProgramState(program);
|
||||
_unLitNoTexMaterial = new Sprite3DMaterial();
|
||||
_unLitNoTexMaterial = new MeshMaterial();
|
||||
if (_unLitNoTexMaterial && _unLitNoTexMaterial->initWithProgramState(_unLitNoTexMaterialProgState))
|
||||
{
|
||||
_unLitNoTexMaterial->_type = Sprite3DMaterial::MaterialType::UNLIT_NOTEX;
|
||||
_unLitNoTexMaterial->_type = MeshMaterial::MaterialType::UNLIT_NOTEX;
|
||||
}
|
||||
|
||||
program = backend::Program::getBuiltinProgram(backend::ProgramType::POSITION_NORMAL_3D);
|
||||
_diffuseNoTexMaterialProgState = new backend::ProgramState(program);
|
||||
_diffuseNoTexMaterial = new Sprite3DMaterial();
|
||||
_diffuseNoTexMaterial = new MeshMaterial();
|
||||
if (_diffuseNoTexMaterial && _diffuseNoTexMaterial->initWithProgramState(_diffuseNoTexMaterialProgState))
|
||||
{
|
||||
_diffuseNoTexMaterial->_type = Sprite3DMaterial::MaterialType::DIFFUSE_NOTEX;
|
||||
_diffuseNoTexMaterial->_type = MeshMaterial::MaterialType::DIFFUSE_NOTEX;
|
||||
}
|
||||
|
||||
program = backend::Program::getBuiltinProgram(backend::ProgramType::POSITION_BUMPEDNORMAL_TEXTURE_3D);
|
||||
_bumpedDiffuseMaterialProgState = new backend::ProgramState(program);
|
||||
_bumpedDiffuseMaterial = new Sprite3DMaterial();
|
||||
_bumpedDiffuseMaterial = new MeshMaterial();
|
||||
if (_bumpedDiffuseMaterial && _bumpedDiffuseMaterial->initWithProgramState(_bumpedDiffuseMaterialProgState))
|
||||
{
|
||||
_bumpedDiffuseMaterial->_type = Sprite3DMaterial::MaterialType::BUMPED_DIFFUSE;
|
||||
_bumpedDiffuseMaterial->_type = MeshMaterial::MaterialType::BUMPED_DIFFUSE;
|
||||
}
|
||||
|
||||
program = backend::Program::getBuiltinProgram(backend::ProgramType::SKINPOSITION_BUMPEDNORMAL_TEXTURE_3D);
|
||||
_bumpedDiffuseMaterialSkinProgState = new backend::ProgramState(program);
|
||||
_bumpedDiffuseMaterialSkin = new Sprite3DMaterial();
|
||||
_bumpedDiffuseMaterialSkin = new MeshMaterial();
|
||||
if (_bumpedDiffuseMaterialSkin &&
|
||||
_bumpedDiffuseMaterialSkin->initWithProgramState(_bumpedDiffuseMaterialSkinProgState))
|
||||
{
|
||||
_bumpedDiffuseMaterialSkin->_type = Sprite3DMaterial::MaterialType::BUMPED_DIFFUSE;
|
||||
_bumpedDiffuseMaterialSkin->_type = MeshMaterial::MaterialType::BUMPED_DIFFUSE;
|
||||
}
|
||||
}
|
||||
|
||||
void Sprite3DMaterial::releaseBuiltInMaterial()
|
||||
void MeshMaterial::releaseBuiltInMaterial()
|
||||
{
|
||||
CC_SAFE_RELEASE_NULL(_unLitMaterial);
|
||||
CC_SAFE_RELEASE_NULL(_unLitMaterialSkin);
|
||||
|
@ -159,7 +159,7 @@ void Sprite3DMaterial::releaseBuiltInMaterial()
|
|||
CC_SAFE_RELEASE_NULL(_bumpedDiffuseMaterialSkinProgState);
|
||||
}
|
||||
|
||||
void Sprite3DMaterial::releaseCachedMaterial()
|
||||
void MeshMaterial::releaseCachedMaterial()
|
||||
{
|
||||
for (auto& it : _materials)
|
||||
{
|
||||
|
@ -169,11 +169,10 @@ void Sprite3DMaterial::releaseCachedMaterial()
|
|||
_materials.clear();
|
||||
}
|
||||
|
||||
Material* Sprite3DMaterial::clone() const
|
||||
Material* MeshMaterial::clone() const
|
||||
{
|
||||
auto material = new Sprite3DMaterial();
|
||||
auto material = new MeshMaterial();
|
||||
|
||||
// RenderState::cloneInto(material);
|
||||
material->_renderState = _renderState;
|
||||
|
||||
for (const auto& technique : _techniques)
|
||||
|
@ -196,36 +195,36 @@ Material* Sprite3DMaterial::clone() const
|
|||
return material;
|
||||
}
|
||||
|
||||
Sprite3DMaterial* Sprite3DMaterial::createBuiltInMaterial(MaterialType type, bool skinned)
|
||||
MeshMaterial* MeshMaterial::createBuiltInMaterial(MaterialType type, bool skinned)
|
||||
{
|
||||
/////
|
||||
if (_diffuseMaterial == nullptr)
|
||||
createBuiltInMaterial();
|
||||
|
||||
Sprite3DMaterial* material = nullptr;
|
||||
MeshMaterial* material = nullptr;
|
||||
switch (type)
|
||||
{
|
||||
case Sprite3DMaterial::MaterialType::UNLIT:
|
||||
case MeshMaterial::MaterialType::UNLIT:
|
||||
material = skinned ? _unLitMaterialSkin : _unLitMaterial;
|
||||
break;
|
||||
|
||||
case Sprite3DMaterial::MaterialType::UNLIT_NOTEX:
|
||||
case MeshMaterial::MaterialType::UNLIT_NOTEX:
|
||||
material = _unLitNoTexMaterial;
|
||||
break;
|
||||
|
||||
case Sprite3DMaterial::MaterialType::VERTEX_LIT:
|
||||
CCASSERT(0, "not implement");
|
||||
case MeshMaterial::MaterialType::VERTEX_LIT:
|
||||
CCASSERT(0, "not implemented.");
|
||||
break;
|
||||
|
||||
case Sprite3DMaterial::MaterialType::DIFFUSE:
|
||||
case MeshMaterial::MaterialType::DIFFUSE:
|
||||
material = skinned ? _diffuseMaterialSkin : _diffuseMaterial;
|
||||
break;
|
||||
|
||||
case Sprite3DMaterial::MaterialType::DIFFUSE_NOTEX:
|
||||
case MeshMaterial::MaterialType::DIFFUSE_NOTEX:
|
||||
material = _diffuseNoTexMaterial;
|
||||
break;
|
||||
|
||||
case Sprite3DMaterial::MaterialType::BUMPED_DIFFUSE:
|
||||
case MeshMaterial::MaterialType::BUMPED_DIFFUSE:
|
||||
material = skinned ? _bumpedDiffuseMaterialSkin : _bumpedDiffuseMaterial;
|
||||
break;
|
||||
|
||||
|
@ -233,41 +232,41 @@ Sprite3DMaterial* Sprite3DMaterial::createBuiltInMaterial(MaterialType type, boo
|
|||
break;
|
||||
}
|
||||
if (material)
|
||||
return (Sprite3DMaterial*)material->clone();
|
||||
return (MeshMaterial*)material->clone();
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Sprite3DMaterial* Sprite3DMaterial::createWithFilename(std::string_view path)
|
||||
MeshMaterial* MeshMaterial::createWithFilename(std::string_view path)
|
||||
{
|
||||
auto validfilename = FileUtils::getInstance()->fullPathForFilename(path);
|
||||
if (!validfilename.empty())
|
||||
{
|
||||
auto it = _materials.find(validfilename);
|
||||
if (it != _materials.end())
|
||||
return (Sprite3DMaterial*)it->second->clone();
|
||||
return (MeshMaterial*)it->second->clone();
|
||||
|
||||
auto material = new Sprite3DMaterial();
|
||||
auto material = new MeshMaterial();
|
||||
if (material->initWithFile(path))
|
||||
{
|
||||
material->_type = Sprite3DMaterial::MaterialType::CUSTOM;
|
||||
material->_type = MeshMaterial::MaterialType::CUSTOM;
|
||||
_materials[validfilename] = material;
|
||||
|
||||
return (Sprite3DMaterial*)material->clone();
|
||||
return (MeshMaterial*)material->clone();
|
||||
}
|
||||
CC_SAFE_DELETE(material);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Sprite3DMaterial* Sprite3DMaterial::createWithProgramState(backend::ProgramState* programState)
|
||||
MeshMaterial* MeshMaterial::createWithProgramState(backend::ProgramState* programState)
|
||||
{
|
||||
CCASSERT(programState, "Invalid GL Program State");
|
||||
CCASSERT(programState, "Invalid program state.");
|
||||
|
||||
auto mat = new Sprite3DMaterial();
|
||||
auto mat = new MeshMaterial();
|
||||
if (mat->initWithProgramState(programState))
|
||||
{
|
||||
mat->_type = Sprite3DMaterial::MaterialType::CUSTOM;
|
||||
mat->_type = MeshMaterial::MaterialType::CUSTOM;
|
||||
mat->autorelease();
|
||||
return mat;
|
||||
}
|
||||
|
@ -275,7 +274,7 @@ Sprite3DMaterial* Sprite3DMaterial::createWithProgramState(backend::ProgramState
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
void Sprite3DMaterial::setTexture(Texture2D* tex, NTextureData::Usage usage)
|
||||
void MeshMaterial::setTexture(Texture2D* tex, NTextureData::Usage usage)
|
||||
{
|
||||
const auto& passes = getTechnique()->getPasses();
|
||||
for (auto& pass : passes)
|
||||
|
@ -286,24 +285,24 @@ void Sprite3DMaterial::setTexture(Texture2D* tex, NTextureData::Usage usage)
|
|||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Sprite3DMaterialCache::Sprite3DMaterialCache() {}
|
||||
MeshMaterialCache::MeshMaterialCache() {}
|
||||
|
||||
Sprite3DMaterialCache::~Sprite3DMaterialCache()
|
||||
MeshMaterialCache::~MeshMaterialCache()
|
||||
{
|
||||
removeAllSprite3DMaterial();
|
||||
removeAllMeshMaterial();
|
||||
}
|
||||
|
||||
Sprite3DMaterialCache* Sprite3DMaterialCache::getInstance()
|
||||
MeshMaterialCache* MeshMaterialCache::getInstance()
|
||||
{
|
||||
if (!_cacheInstance)
|
||||
{
|
||||
_cacheInstance = new Sprite3DMaterialCache();
|
||||
_cacheInstance = new MeshMaterialCache();
|
||||
}
|
||||
|
||||
return _cacheInstance;
|
||||
}
|
||||
|
||||
void Sprite3DMaterialCache::destroyInstance()
|
||||
void MeshMaterialCache::destroyInstance()
|
||||
{
|
||||
if (_cacheInstance)
|
||||
{
|
||||
|
@ -311,7 +310,7 @@ void Sprite3DMaterialCache::destroyInstance()
|
|||
}
|
||||
}
|
||||
|
||||
bool Sprite3DMaterialCache::addSprite3DMaterial(std::string_view key, Texture2D* texture)
|
||||
bool MeshMaterialCache::addMeshMaterial(std::string_view key, Texture2D* texture)
|
||||
{
|
||||
auto itr = _materials.find(key);
|
||||
if (itr == _materials.end())
|
||||
|
@ -323,7 +322,7 @@ bool Sprite3DMaterialCache::addSprite3DMaterial(std::string_view key, Texture2D*
|
|||
return false;
|
||||
}
|
||||
|
||||
Texture2D* Sprite3DMaterialCache::getSprite3DMaterial(std::string_view key)
|
||||
Texture2D* MeshMaterialCache::getMeshMaterial(std::string_view key)
|
||||
{
|
||||
auto itr = _materials.find(key);
|
||||
if (itr != _materials.end())
|
||||
|
@ -333,7 +332,7 @@ Texture2D* Sprite3DMaterialCache::getSprite3DMaterial(std::string_view key)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
void Sprite3DMaterialCache::removeAllSprite3DMaterial()
|
||||
void MeshMaterialCache::removeAllMeshMaterial()
|
||||
{
|
||||
for (auto& itr : _materials)
|
||||
{
|
||||
|
@ -341,14 +340,14 @@ void Sprite3DMaterialCache::removeAllSprite3DMaterial()
|
|||
}
|
||||
_materials.clear();
|
||||
}
|
||||
void Sprite3DMaterialCache::removeUnusedSprite3DMaterial()
|
||||
void MeshMaterialCache::removeUnusedMeshMaterial()
|
||||
{
|
||||
for (auto it = _materials.cbegin(), itCend = _materials.cend(); it != itCend; /* nothing */)
|
||||
{
|
||||
auto value = it->second;
|
||||
if (value->getReferenceCount() == 1)
|
||||
{
|
||||
CCLOG("cocos2d: Sprite3DMaterialCache: removing unused Sprite3DMaterial");
|
||||
CCLOG("cocos2d: MeshMaterialCache: removing unused mesh renderer materials.");
|
||||
|
||||
value->release();
|
||||
it = _materials.erase(it);
|
|
@ -46,26 +46,26 @@ class ProgramState;
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief Sprite3DMaterial: Material for Sprite3D.
|
||||
* @brief MeshMaterial: a mesh material for MeshRenderers.
|
||||
*/
|
||||
class CC_DLL Sprite3DMaterial : public Material
|
||||
class CC_DLL MeshMaterial : public Material
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Material type, there are mainly two types of materials. Built in materials and Custom material
|
||||
* Material types, there are mainly two types of materials. Built-in materials and Custom materials.
|
||||
*/
|
||||
enum class MaterialType
|
||||
{
|
||||
// Built in material
|
||||
// Built in materials
|
||||
UNLIT, // unlit material
|
||||
UNLIT_NOTEX, // unlit material without texture
|
||||
UNLIT_NOTEX, // unlit material (without texture)
|
||||
VERTEX_LIT, // vertex lit
|
||||
DIFFUSE, // diffuse (pixel lighting)
|
||||
DIFFUSE_NOTEX, // diffuse (without texture)
|
||||
BUMPED_DIFFUSE, // bumped diffuse
|
||||
|
||||
// Custom material
|
||||
CUSTOM, // Create from material file
|
||||
CUSTOM, // Create from a material file
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -77,35 +77,34 @@ public:
|
|||
/**
|
||||
* Create built in material from material type
|
||||
* @param type Material type
|
||||
* @param skinned Has skin?
|
||||
* @return Created material
|
||||
* @param skinned Has hardware skinning?
|
||||
* @return An autorelease material object
|
||||
*/
|
||||
static Sprite3DMaterial* createBuiltInMaterial(MaterialType type, bool skinned);
|
||||
static MeshMaterial* createBuiltInMaterial(MaterialType type, bool skinned);
|
||||
|
||||
/**
|
||||
* Create material with file name, it creates material from cache if it is previously loaded
|
||||
* @param path Path of material file
|
||||
* @return Created material
|
||||
* @return An autorelease material object
|
||||
*/
|
||||
static Sprite3DMaterial* createWithFilename(std::string_view path);
|
||||
static MeshMaterial* createWithFilename(std::string_view path);
|
||||
|
||||
/**
|
||||
* Create material with GLProgramState
|
||||
* Create material with a ProgramState
|
||||
* @param programState GLProgramState instance
|
||||
* @return Created material
|
||||
* @return An autorelease material object
|
||||
*/
|
||||
// static Sprite3DMaterial* createWithGLStateProgram(GLProgramState* programState);
|
||||
static Sprite3DMaterial* createWithProgramState(backend::ProgramState* programState);
|
||||
static MeshMaterial* createWithProgramState(backend::ProgramState* programState);
|
||||
|
||||
void setTexture(Texture2D* tex, NTextureData::Usage usage);
|
||||
|
||||
/**
|
||||
* Create all build in materials
|
||||
* Create all built-in materials
|
||||
*/
|
||||
static void createBuiltInMaterial();
|
||||
|
||||
/**
|
||||
* Release all built in materials
|
||||
* Release all built-in materials
|
||||
*/
|
||||
static void releaseBuiltInMaterial();
|
||||
|
||||
|
@ -115,24 +114,24 @@ public:
|
|||
static void releaseCachedMaterial();
|
||||
|
||||
/**
|
||||
* Clone material
|
||||
* Clone this material.
|
||||
*/
|
||||
virtual Material* clone() const override;
|
||||
|
||||
protected:
|
||||
MaterialType _type;
|
||||
static std::unordered_map<std::string, Sprite3DMaterial*> _materials; // cached material
|
||||
static Sprite3DMaterial* _unLitMaterial;
|
||||
static Sprite3DMaterial* _unLitNoTexMaterial;
|
||||
static Sprite3DMaterial* _vertexLitMaterial;
|
||||
static Sprite3DMaterial* _diffuseMaterial;
|
||||
static Sprite3DMaterial* _diffuseNoTexMaterial;
|
||||
static Sprite3DMaterial* _bumpedDiffuseMaterial;
|
||||
static std::unordered_map<std::string, MeshMaterial*> _materials; // cached material
|
||||
static MeshMaterial* _unLitMaterial;
|
||||
static MeshMaterial* _unLitNoTexMaterial;
|
||||
static MeshMaterial* _vertexLitMaterial;
|
||||
static MeshMaterial* _diffuseMaterial;
|
||||
static MeshMaterial* _diffuseNoTexMaterial;
|
||||
static MeshMaterial* _bumpedDiffuseMaterial;
|
||||
|
||||
static Sprite3DMaterial* _unLitMaterialSkin;
|
||||
static Sprite3DMaterial* _vertexLitMaterialSkin;
|
||||
static Sprite3DMaterial* _diffuseMaterialSkin;
|
||||
static Sprite3DMaterial* _bumpedDiffuseMaterialSkin;
|
||||
static MeshMaterial* _unLitMaterialSkin;
|
||||
static MeshMaterial* _vertexLitMaterialSkin;
|
||||
static MeshMaterial* _diffuseMaterialSkin;
|
||||
static MeshMaterial* _bumpedDiffuseMaterialSkin;
|
||||
|
||||
static backend::ProgramState* _unLitMaterialProgState;
|
||||
static backend::ProgramState* _unLitNoTexMaterialProgState;
|
||||
|
@ -148,36 +147,33 @@ protected:
|
|||
};
|
||||
|
||||
/**
|
||||
* @brief the sprite3D material is only texture for now
|
||||
* @brief MeshMaterialCache: the MeshRenderer material cache, it can only cache textures for now.
|
||||
* @js NA
|
||||
* @lua NA
|
||||
*/
|
||||
class Sprite3DMaterialCache
|
||||
class MeshMaterialCache
|
||||
{
|
||||
public:
|
||||
/**get & destroy cache*/
|
||||
static Sprite3DMaterialCache* getInstance();
|
||||
|
||||
/**destroy the instance*/
|
||||
static MeshMaterialCache* getInstance();
|
||||
static void destroyInstance();
|
||||
|
||||
/**add to cache*/
|
||||
bool addSprite3DMaterial(std::string_view key, Texture2D* tex);
|
||||
/** add a material to cache */
|
||||
bool addMeshMaterial(std::string_view key, Texture2D* tex);
|
||||
|
||||
/**get material from cache*/
|
||||
Texture2D* getSprite3DMaterial(std::string_view key);
|
||||
/** get material from cache */
|
||||
Texture2D* getMeshMaterial(std::string_view key);
|
||||
|
||||
/**remove all spritematerial*/
|
||||
void removeAllSprite3DMaterial();
|
||||
/**remove unused spritematerial*/
|
||||
void removeUnusedSprite3DMaterial();
|
||||
/** remove all cached materials */
|
||||
void removeAllMeshMaterial();
|
||||
/** remove unused cached materials */
|
||||
void removeUnusedMeshMaterial();
|
||||
|
||||
Sprite3DMaterialCache();
|
||||
~Sprite3DMaterialCache();
|
||||
MeshMaterialCache();
|
||||
~MeshMaterialCache();
|
||||
|
||||
protected:
|
||||
static Sprite3DMaterialCache* _cacheInstance; // instance
|
||||
hlookup::string_map<Texture2D*> _materials; // cached material
|
||||
static MeshMaterialCache* _cacheInstance; // cache instance
|
||||
hlookup::string_map<Texture2D*> _materials; // cached materials
|
||||
};
|
||||
|
||||
// end of 3d group
|
|
@ -23,11 +23,11 @@
|
|||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "3d/CCSprite3D.h"
|
||||
#include "3d/CCMeshRenderer.h"
|
||||
#include "3d/CCObjLoader.h"
|
||||
#include "3d/CCMeshSkin.h"
|
||||
#include "3d/CCBundle3D.h"
|
||||
#include "3d/CCSprite3DMaterial.h"
|
||||
#include "3d/CCMeshMaterial.h"
|
||||
#include "3d/CCAttachNode.h"
|
||||
#include "3d/CCMesh.h"
|
||||
|
||||
|
@ -48,87 +48,87 @@
|
|||
|
||||
NS_CC_BEGIN
|
||||
|
||||
static Sprite3DMaterial* getSprite3DMaterialForAttribs(MeshVertexData* meshVertexData, bool usesLight);
|
||||
static MeshMaterial* getMeshRendererMaterialForAttribs(MeshVertexData* meshVertexData, bool usesLight);
|
||||
|
||||
Sprite3D* Sprite3D::create()
|
||||
MeshRenderer* MeshRenderer::create()
|
||||
{
|
||||
auto sprite = new Sprite3D();
|
||||
if (sprite->init())
|
||||
auto mesh = new MeshRenderer();
|
||||
if (mesh->init())
|
||||
{
|
||||
sprite->autorelease();
|
||||
return sprite;
|
||||
mesh->autorelease();
|
||||
return mesh;
|
||||
}
|
||||
CC_SAFE_DELETE(sprite);
|
||||
CC_SAFE_DELETE(mesh);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Sprite3D* Sprite3D::create(std::string_view modelPath)
|
||||
MeshRenderer* MeshRenderer::create(std::string_view modelPath)
|
||||
{
|
||||
CCASSERT(modelPath.length() >= 4, "invalid filename for Sprite3D");
|
||||
CCASSERT(modelPath.length() >= 4, "Invalid filename.");
|
||||
|
||||
auto sprite = new Sprite3D();
|
||||
if (sprite->initWithFile(modelPath))
|
||||
auto mesh = new MeshRenderer();
|
||||
if (mesh->initWithFile(modelPath))
|
||||
{
|
||||
sprite->_contentSize = sprite->getBoundingBox().size;
|
||||
sprite->autorelease();
|
||||
return sprite;
|
||||
mesh->_contentSize = mesh->getBoundingBox().size;
|
||||
mesh->autorelease();
|
||||
return mesh;
|
||||
}
|
||||
CC_SAFE_DELETE(sprite);
|
||||
CC_SAFE_DELETE(mesh);
|
||||
return nullptr;
|
||||
}
|
||||
Sprite3D* Sprite3D::create(std::string_view modelPath, std::string_view texturePath)
|
||||
MeshRenderer* MeshRenderer::create(std::string_view modelPath, std::string_view texturePath)
|
||||
{
|
||||
auto sprite = create(modelPath);
|
||||
if (sprite)
|
||||
auto mesh = create(modelPath);
|
||||
if (mesh)
|
||||
{
|
||||
sprite->setTexture(texturePath);
|
||||
mesh->setTexture(texturePath);
|
||||
}
|
||||
|
||||
return sprite;
|
||||
return mesh;
|
||||
}
|
||||
|
||||
void Sprite3D::createAsync(std::string_view modelPath,
|
||||
const std::function<void(Sprite3D*, void*)>& callback,
|
||||
void MeshRenderer::createAsync(std::string_view modelPath,
|
||||
const std::function<void(MeshRenderer*, void*)>& callback,
|
||||
void* callbackparam)
|
||||
{
|
||||
createAsync(modelPath, "", callback, callbackparam);
|
||||
}
|
||||
|
||||
void Sprite3D::createAsync(std::string_view modelPath,
|
||||
void MeshRenderer::createAsync(std::string_view modelPath,
|
||||
std::string_view texturePath,
|
||||
const std::function<void(Sprite3D*, void*)>& callback,
|
||||
const std::function<void(MeshRenderer*, void*)>& callback,
|
||||
void* callbackparam)
|
||||
{
|
||||
Sprite3D* sprite = new Sprite3D();
|
||||
if (sprite->loadFromCache(modelPath))
|
||||
MeshRenderer* mesh = new MeshRenderer();
|
||||
if (mesh->loadFromCache(modelPath))
|
||||
{
|
||||
sprite->autorelease();
|
||||
mesh->autorelease();
|
||||
if (!texturePath.empty())
|
||||
sprite->setTexture(texturePath);
|
||||
callback(sprite, callbackparam);
|
||||
mesh->setTexture(texturePath);
|
||||
callback(mesh, callbackparam);
|
||||
return;
|
||||
}
|
||||
|
||||
sprite->_asyncLoadParam.afterLoadCallback = callback;
|
||||
sprite->_asyncLoadParam.texPath = texturePath;
|
||||
sprite->_asyncLoadParam.modelPath = modelPath;
|
||||
sprite->_asyncLoadParam.modelFullPath = FileUtils::getInstance()->fullPathForFilename(modelPath);
|
||||
sprite->_asyncLoadParam.callbackParam = callbackparam;
|
||||
sprite->_asyncLoadParam.materialdatas = new MaterialDatas();
|
||||
sprite->_asyncLoadParam.meshdatas = new MeshDatas();
|
||||
sprite->_asyncLoadParam.nodeDatas = new NodeDatas();
|
||||
mesh->_asyncLoadParam.afterLoadCallback = callback;
|
||||
mesh->_asyncLoadParam.texPath = texturePath;
|
||||
mesh->_asyncLoadParam.modelPath = modelPath;
|
||||
mesh->_asyncLoadParam.modelFullPath = FileUtils::getInstance()->fullPathForFilename(modelPath);
|
||||
mesh->_asyncLoadParam.callbackParam = callbackparam;
|
||||
mesh->_asyncLoadParam.materialdatas = new MaterialDatas();
|
||||
mesh->_asyncLoadParam.meshdatas = new MeshDatas();
|
||||
mesh->_asyncLoadParam.nodeDatas = new 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.modelFullPath, sprite->_asyncLoadParam.nodeDatas,
|
||||
sprite->_asyncLoadParam.meshdatas, sprite->_asyncLoadParam.materialdatas);
|
||||
AsyncTaskPool::TaskType::TASK_IO, CC_CALLBACK_1(MeshRenderer::afterAsyncLoad, mesh),
|
||||
(void*)(&mesh->_asyncLoadParam), [mesh]() {
|
||||
mesh->_asyncLoadParam.result =
|
||||
mesh->loadFromFile(mesh->_asyncLoadParam.modelFullPath, mesh->_asyncLoadParam.nodeDatas,
|
||||
mesh->_asyncLoadParam.meshdatas, mesh->_asyncLoadParam.materialdatas);
|
||||
});
|
||||
}
|
||||
|
||||
void Sprite3D::afterAsyncLoad(void* param)
|
||||
void MeshRenderer::afterAsyncLoad(void* param)
|
||||
{
|
||||
Sprite3D::AsyncLoadParam* asyncParam = (Sprite3D::AsyncLoadParam*)param;
|
||||
MeshRenderer::AsyncLoadParam* asyncParam = (MeshRenderer::AsyncLoadParam*)param;
|
||||
autorelease();
|
||||
if (asyncParam)
|
||||
{
|
||||
|
@ -145,11 +145,11 @@ void Sprite3D::afterAsyncLoad(void* param)
|
|||
auto& nodeDatas = asyncParam->nodeDatas;
|
||||
if (initFrom(*nodeDatas, *meshdatas, *materialdatas))
|
||||
{
|
||||
auto spritedata = Sprite3DCache::getInstance()->getSpriteData(asyncParam->modelPath);
|
||||
if (spritedata == nullptr)
|
||||
auto meshdata = MeshRendererCache::getInstance()->getMeshData(asyncParam->modelPath);
|
||||
if (meshdata == nullptr)
|
||||
{
|
||||
// add to cache
|
||||
auto data = new Sprite3DCache::Sprite3DData();
|
||||
auto data = new MeshRendererCache::MeshRendererData();
|
||||
data->materialdatas = materialdatas;
|
||||
data->nodedatas = nodeDatas;
|
||||
data->meshVertexDatas = _meshVertexDatas;
|
||||
|
@ -158,7 +158,7 @@ void Sprite3D::afterAsyncLoad(void* param)
|
|||
data->programStates.pushBack(mesh->getProgramState());
|
||||
}
|
||||
|
||||
Sprite3DCache::getInstance()->addSprite3DData(asyncParam->modelPath, data);
|
||||
MeshRendererCache::getInstance()->addMeshRendererData(asyncParam->modelPath, data);
|
||||
|
||||
CC_SAFE_DELETE(meshdatas);
|
||||
materialdatas = nullptr;
|
||||
|
@ -176,13 +176,13 @@ void Sprite3D::afterAsyncLoad(void* param)
|
|||
}
|
||||
else
|
||||
{
|
||||
CCLOG("file load failed: %s ", asyncParam->modelPath.c_str());
|
||||
CCLOG("file load failed: %s\n", asyncParam->modelPath.c_str());
|
||||
}
|
||||
asyncParam->afterLoadCallback(this, asyncParam->callbackParam);
|
||||
}
|
||||
}
|
||||
|
||||
AABB Sprite3D::getAABBRecursivelyImp(Node* node)
|
||||
AABB MeshRenderer::getAABBRecursivelyImp(Node* node)
|
||||
{
|
||||
AABB aabb;
|
||||
for (auto iter : node->getChildren())
|
||||
|
@ -190,46 +190,46 @@ AABB Sprite3D::getAABBRecursivelyImp(Node* node)
|
|||
aabb.merge(getAABBRecursivelyImp(iter));
|
||||
}
|
||||
|
||||
Sprite3D* sprite3d = dynamic_cast<Sprite3D*>(node);
|
||||
if (sprite3d)
|
||||
aabb.merge(sprite3d->getAABB());
|
||||
MeshRenderer* meshRenderer = dynamic_cast<MeshRenderer*>(node);
|
||||
if (meshRenderer)
|
||||
aabb.merge(meshRenderer->getAABB());
|
||||
|
||||
return aabb;
|
||||
}
|
||||
|
||||
bool Sprite3D::loadFromCache(std::string_view path)
|
||||
bool MeshRenderer::loadFromCache(std::string_view path)
|
||||
{
|
||||
auto spritedata = Sprite3DCache::getInstance()->getSpriteData(path);
|
||||
if (spritedata)
|
||||
auto meshdata = MeshRendererCache::getInstance()->getMeshData(path);
|
||||
if (meshdata)
|
||||
{
|
||||
for (auto it : spritedata->meshVertexDatas)
|
||||
for (auto it : meshdata->meshVertexDatas)
|
||||
{
|
||||
_meshVertexDatas.pushBack(it);
|
||||
}
|
||||
_skeleton = Skeleton3D::create(spritedata->nodedatas->skeleton);
|
||||
_skeleton = Skeleton3D::create(meshdata->nodedatas->skeleton);
|
||||
CC_SAFE_RETAIN(_skeleton);
|
||||
|
||||
const bool singleSprite = (spritedata->nodedatas->nodes.size() == 1);
|
||||
for (const auto& it : spritedata->nodedatas->nodes)
|
||||
const bool singleMesh = (meshdata->nodedatas->nodes.size() == 1);
|
||||
for (const auto& it : meshdata->nodedatas->nodes)
|
||||
{
|
||||
if (it)
|
||||
{
|
||||
createNode(it, this, *(spritedata->materialdatas), singleSprite);
|
||||
createNode(it, this, *(meshdata->materialdatas), singleMesh);
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto& it : spritedata->nodedatas->skeleton)
|
||||
for (const auto& it : meshdata->nodedatas->skeleton)
|
||||
{
|
||||
if (it)
|
||||
{
|
||||
createAttachSprite3DNode(it, *(spritedata->materialdatas));
|
||||
createAttachMeshRendererNode(it, *(meshdata->materialdatas));
|
||||
}
|
||||
}
|
||||
|
||||
for (ssize_t i = 0, size = _meshes.size(); i < size; ++i)
|
||||
{
|
||||
// cloning is needed in order to have one state per sprite
|
||||
auto glstate = spritedata->programStates.at(i);
|
||||
// cloning is needed in order to have one state per mesh
|
||||
auto glstate = meshdata->programStates.at(i);
|
||||
_meshes.at(i)->setProgramState(glstate->clone());
|
||||
}
|
||||
return true;
|
||||
|
@ -238,7 +238,7 @@ bool Sprite3D::loadFromCache(std::string_view path)
|
|||
return false;
|
||||
}
|
||||
|
||||
bool Sprite3D::loadFromFile(std::string_view path,
|
||||
bool MeshRenderer::loadFromFile(std::string_view path,
|
||||
NodeDatas* nodedatas,
|
||||
MeshDatas* meshdatas,
|
||||
MaterialDatas* materialdatas)
|
||||
|
@ -269,7 +269,7 @@ bool Sprite3D::loadFromFile(std::string_view path,
|
|||
return false;
|
||||
}
|
||||
|
||||
Sprite3D::Sprite3D()
|
||||
MeshRenderer::MeshRenderer()
|
||||
: _skeleton(nullptr)
|
||||
, _blend(BlendFunc::ALPHA_NON_PREMULTIPLIED)
|
||||
, _aabbDirty(true)
|
||||
|
@ -279,7 +279,7 @@ Sprite3D::Sprite3D()
|
|||
, _usingAutogeneratedGLProgram(true)
|
||||
{}
|
||||
|
||||
Sprite3D::~Sprite3D()
|
||||
MeshRenderer::~MeshRenderer()
|
||||
{
|
||||
_meshes.clear();
|
||||
_meshVertexDatas.clear();
|
||||
|
@ -287,7 +287,7 @@ Sprite3D::~Sprite3D()
|
|||
removeAllAttachNode();
|
||||
}
|
||||
|
||||
bool Sprite3D::init()
|
||||
bool MeshRenderer::init()
|
||||
{
|
||||
if (Node::init())
|
||||
{
|
||||
|
@ -296,7 +296,7 @@ bool Sprite3D::init()
|
|||
return false;
|
||||
}
|
||||
|
||||
bool Sprite3D::initWithFile(std::string_view path)
|
||||
bool MeshRenderer::initWithFile(std::string_view path)
|
||||
{
|
||||
_aabbDirty = true;
|
||||
_meshes.clear();
|
||||
|
@ -315,7 +315,7 @@ bool Sprite3D::initWithFile(std::string_view path)
|
|||
if (initFrom(*nodeDatas, *meshdatas, *materialdatas))
|
||||
{
|
||||
// add to cache
|
||||
auto data = new Sprite3DCache::Sprite3DData();
|
||||
auto data = new MeshRendererCache::MeshRendererData();
|
||||
data->materialdatas = materialdatas;
|
||||
data->nodedatas = nodeDatas;
|
||||
data->meshVertexDatas = _meshVertexDatas;
|
||||
|
@ -324,7 +324,7 @@ bool Sprite3D::initWithFile(std::string_view path)
|
|||
data->programStates.pushBack(mesh->getProgramState());
|
||||
}
|
||||
|
||||
Sprite3DCache::getInstance()->addSprite3DData(path, data);
|
||||
MeshRendererCache::getInstance()->addMeshRendererData(path, data);
|
||||
CC_SAFE_DELETE(meshdatas);
|
||||
_contentSize = getBoundingBox().size;
|
||||
return true;
|
||||
|
@ -337,7 +337,7 @@ bool Sprite3D::initWithFile(std::string_view path)
|
|||
return false;
|
||||
}
|
||||
|
||||
bool Sprite3D::initFrom(const NodeDatas& nodeDatas, const MeshDatas& meshdatas, const MaterialDatas& materialdatas)
|
||||
bool MeshRenderer::initFrom(const NodeDatas& nodeDatas, const MeshDatas& meshdatas, const MaterialDatas& materialdatas)
|
||||
{
|
||||
for (const auto& it : meshdatas.meshDatas)
|
||||
{
|
||||
|
@ -364,7 +364,7 @@ bool Sprite3D::initFrom(const NodeDatas& nodeDatas, const MeshDatas& meshdatas,
|
|||
{
|
||||
if (it)
|
||||
{
|
||||
createAttachSprite3DNode(it, materialdatas);
|
||||
createAttachMeshRendererNode(it, materialdatas);
|
||||
}
|
||||
}
|
||||
genMaterial();
|
||||
|
@ -372,11 +372,11 @@ bool Sprite3D::initFrom(const NodeDatas& nodeDatas, const MeshDatas& meshdatas,
|
|||
return true;
|
||||
}
|
||||
|
||||
Sprite3D* Sprite3D::createSprite3DNode(NodeData* nodedata, ModelData* modeldata, const MaterialDatas& materialdatas)
|
||||
MeshRenderer* MeshRenderer::createMeshRendererNode(NodeData* nodedata, ModelData* modeldata, const MaterialDatas& materialdatas)
|
||||
{
|
||||
auto sprite = new Sprite3D();
|
||||
auto meshRenderer = new MeshRenderer();
|
||||
|
||||
sprite->setName(nodedata->id);
|
||||
meshRenderer->setName(nodedata->id);
|
||||
auto mesh = Mesh::create(nodedata->id, getMeshIndexData(modeldata->subMeshId));
|
||||
|
||||
if (_skeleton && modeldata->bones.size())
|
||||
|
@ -434,46 +434,46 @@ Sprite3D* Sprite3D::createSprite3DNode(NodeData* nodedata, ModelData* modeldata,
|
|||
Quaternion qua;
|
||||
Vec3 scale;
|
||||
nodedata->transform.decompose(&scale, &qua, &pos);
|
||||
sprite->setPosition3D(pos);
|
||||
sprite->setRotationQuat(qua);
|
||||
sprite->setScaleX(scale.x);
|
||||
sprite->setScaleY(scale.y);
|
||||
sprite->setScaleZ(scale.z);
|
||||
meshRenderer->setPosition3D(pos);
|
||||
meshRenderer->setRotationQuat(qua);
|
||||
meshRenderer->setScaleX(scale.x);
|
||||
meshRenderer->setScaleY(scale.y);
|
||||
meshRenderer->setScaleZ(scale.z);
|
||||
|
||||
sprite->addMesh(mesh);
|
||||
sprite->autorelease();
|
||||
sprite->genMaterial();
|
||||
meshRenderer->addMesh(mesh);
|
||||
meshRenderer->autorelease();
|
||||
meshRenderer->genMaterial();
|
||||
|
||||
return sprite;
|
||||
return meshRenderer;
|
||||
}
|
||||
void Sprite3D::createAttachSprite3DNode(NodeData* nodedata, const MaterialDatas& materialdatas)
|
||||
void MeshRenderer::createAttachMeshRendererNode(NodeData* nodedata, const MaterialDatas& materialdatas)
|
||||
{
|
||||
for (const auto& it : nodedata->modelNodeDatas)
|
||||
{
|
||||
if (it && getAttachNode(nodedata->id))
|
||||
{
|
||||
auto sprite = createSprite3DNode(nodedata, it, materialdatas);
|
||||
if (sprite)
|
||||
auto mesh = createMeshRendererNode(nodedata, it, materialdatas);
|
||||
if (mesh)
|
||||
{
|
||||
getAttachNode(nodedata->id)->addChild(sprite);
|
||||
getAttachNode(nodedata->id)->addChild(mesh);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const auto& it : nodedata->children)
|
||||
{
|
||||
createAttachSprite3DNode(it, materialdatas);
|
||||
createAttachMeshRendererNode(it, materialdatas);
|
||||
}
|
||||
}
|
||||
|
||||
void Sprite3D::setMaterial(Material* material)
|
||||
void MeshRenderer::setMaterial(Material* material)
|
||||
{
|
||||
setMaterial(material, -1);
|
||||
}
|
||||
|
||||
void Sprite3D::setMaterial(Material* material, int meshIndex)
|
||||
void MeshRenderer::setMaterial(Material* material, int meshIndex)
|
||||
{
|
||||
CCASSERT(material, "Invalid Material");
|
||||
CCASSERT(meshIndex == -1 || (meshIndex >= 0 && meshIndex < _meshes.size()), "Invalid meshIndex");
|
||||
CCASSERT(meshIndex == -1 || (meshIndex >= 0 && meshIndex < _meshes.size()), "Invalid meshIndex.");
|
||||
|
||||
if (meshIndex == -1)
|
||||
{
|
||||
|
@ -491,21 +491,21 @@ void Sprite3D::setMaterial(Material* material, int meshIndex)
|
|||
_usingAutogeneratedGLProgram = false;
|
||||
}
|
||||
|
||||
Material* Sprite3D::getMaterial(int meshIndex) const
|
||||
Material* MeshRenderer::getMaterial(int meshIndex) const
|
||||
{
|
||||
CCASSERT(meshIndex >= 0 && meshIndex < _meshes.size(), "Invalid meshIndex");
|
||||
CCASSERT(meshIndex >= 0 && meshIndex < _meshes.size(), "Invalid meshIndex.");
|
||||
return _meshes.at(meshIndex)->getMaterial();
|
||||
}
|
||||
|
||||
void Sprite3D::genMaterial(bool useLight)
|
||||
void MeshRenderer::genMaterial(bool useLight)
|
||||
{
|
||||
_shaderUsingLight = useLight;
|
||||
|
||||
std::unordered_map<const MeshVertexData*, Sprite3DMaterial*> materials;
|
||||
std::unordered_map<const MeshVertexData*, MeshMaterial*> materials;
|
||||
for (auto meshVertexData : _meshVertexDatas)
|
||||
{
|
||||
auto material = getSprite3DMaterialForAttribs(meshVertexData, useLight);
|
||||
CCASSERT(material, "material should not be null");
|
||||
auto material = getMeshRendererMaterialForAttribs(meshVertexData, useLight);
|
||||
CCASSERT(material, "material should cannot be null.");
|
||||
materials[meshVertexData] = material;
|
||||
}
|
||||
|
||||
|
@ -526,16 +526,16 @@ void Sprite3D::genMaterial(bool useLight)
|
|||
}
|
||||
}
|
||||
|
||||
void Sprite3D::createNode(NodeData* nodedata, Node* root, const MaterialDatas& materialdatas, bool singleSprite)
|
||||
void MeshRenderer::createNode(NodeData* nodedata, Node* root, const MaterialDatas& materialdatas, bool singleMesh)
|
||||
{
|
||||
Node* node = nullptr;
|
||||
for (const auto& it : nodedata->modelNodeDatas)
|
||||
{
|
||||
if (it)
|
||||
{
|
||||
if (!it->bones.empty() || singleSprite)
|
||||
if (!it->bones.empty() || singleMesh)
|
||||
{
|
||||
if (singleSprite && root != nullptr)
|
||||
if (singleMesh && root != nullptr)
|
||||
root->setName(nodedata->id);
|
||||
auto mesh = Mesh::create(nodedata->id, getMeshIndexData(it->subMeshId));
|
||||
if (mesh)
|
||||
|
@ -546,7 +546,7 @@ void Sprite3D::createNode(NodeData* nodedata, Node* root, const MaterialDatas& m
|
|||
auto skin = MeshSkin::create(_skeleton, it->bones, it->invBindPose);
|
||||
mesh->setSkin(skin);
|
||||
}
|
||||
mesh->_visibleChanged = std::bind(&Sprite3D::onAABBDirty, this);
|
||||
mesh->_visibleChanged = std::bind(&MeshRenderer::onAABBDirty, this);
|
||||
|
||||
if (it->materialId == "" && materialdatas.materials.size())
|
||||
{
|
||||
|
@ -610,15 +610,15 @@ void Sprite3D::createNode(NodeData* nodedata, Node* root, const MaterialDatas& m
|
|||
}
|
||||
else
|
||||
{
|
||||
auto sprite = createSprite3DNode(nodedata, it, materialdatas);
|
||||
if (sprite)
|
||||
auto mesh = createMeshRendererNode(nodedata, it, materialdatas);
|
||||
if (mesh)
|
||||
{
|
||||
if (root)
|
||||
{
|
||||
root->addChild(sprite);
|
||||
root->addChild(mesh);
|
||||
}
|
||||
}
|
||||
node = sprite;
|
||||
node = mesh;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -654,7 +654,7 @@ void Sprite3D::createNode(NodeData* nodedata, Node* root, const MaterialDatas& m
|
|||
}
|
||||
}
|
||||
|
||||
MeshIndexData* Sprite3D::getMeshIndexData(std::string_view indexId) const
|
||||
MeshIndexData* MeshRenderer::getMeshIndexData(std::string_view indexId) const
|
||||
{
|
||||
for (auto it : _meshVertexDatas)
|
||||
{
|
||||
|
@ -665,27 +665,27 @@ MeshIndexData* Sprite3D::getMeshIndexData(std::string_view indexId) const
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
void Sprite3D::addMesh(Mesh* mesh)
|
||||
void MeshRenderer::addMesh(Mesh* mesh)
|
||||
{
|
||||
auto meshVertex = mesh->getMeshIndexData()->_vertexData;
|
||||
_meshVertexDatas.pushBack(meshVertex);
|
||||
_meshes.pushBack(mesh);
|
||||
}
|
||||
|
||||
void Sprite3D::setTexture(std::string_view texFile)
|
||||
void MeshRenderer::setTexture(std::string_view texFile)
|
||||
{
|
||||
auto tex = _director->getTextureCache()->addImage(texFile);
|
||||
setTexture(tex);
|
||||
}
|
||||
|
||||
void Sprite3D::setTexture(Texture2D* texture)
|
||||
void MeshRenderer::setTexture(Texture2D* texture)
|
||||
{
|
||||
for (auto mesh : _meshes)
|
||||
{
|
||||
mesh->setTexture(texture);
|
||||
}
|
||||
}
|
||||
AttachNode* Sprite3D::getAttachNode(std::string_view boneName)
|
||||
AttachNode* MeshRenderer::getAttachNode(std::string_view boneName)
|
||||
{
|
||||
auto it = _attachments.find(boneName);
|
||||
if (it != _attachments.end())
|
||||
|
@ -706,7 +706,7 @@ AttachNode* Sprite3D::getAttachNode(std::string_view boneName)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
void Sprite3D::removeAttachNode(std::string_view boneName)
|
||||
void MeshRenderer::removeAttachNode(std::string_view boneName)
|
||||
{
|
||||
auto it = _attachments.find(boneName);
|
||||
if (it != _attachments.end())
|
||||
|
@ -716,7 +716,7 @@ void Sprite3D::removeAttachNode(std::string_view boneName)
|
|||
}
|
||||
}
|
||||
|
||||
void Sprite3D::removeAllAttachNode()
|
||||
void MeshRenderer::removeAllAttachNode()
|
||||
{
|
||||
for (auto& it : _attachments)
|
||||
{
|
||||
|
@ -725,7 +725,7 @@ void Sprite3D::removeAllAttachNode()
|
|||
_attachments.clear();
|
||||
}
|
||||
|
||||
void Sprite3D::visit(cocos2d::Renderer* renderer, const cocos2d::Mat4& parentTransform, uint32_t parentFlags)
|
||||
void MeshRenderer::visit(cocos2d::Renderer* renderer, const cocos2d::Mat4& parentTransform, uint32_t parentFlags)
|
||||
{
|
||||
// quick return if not visible. children won't be drawn.
|
||||
if (!_visible)
|
||||
|
@ -772,7 +772,7 @@ void Sprite3D::visit(cocos2d::Renderer* renderer, const cocos2d::Mat4& parentTra
|
|||
_director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
|
||||
}
|
||||
|
||||
void Sprite3D::draw(Renderer* renderer, const Mat4& transform, uint32_t flags)
|
||||
void MeshRenderer::draw(Renderer* renderer, const Mat4& transform, uint32_t flags)
|
||||
{
|
||||
#if CC_USE_CULLING
|
||||
// TODO new-renderer: interface isVisibleInFrustum removal
|
||||
|
@ -815,7 +815,7 @@ void Sprite3D::draw(Renderer* renderer, const Mat4& transform, uint32_t flags)
|
|||
}
|
||||
}
|
||||
|
||||
bool Sprite3D::setProgramState(backend::ProgramState* programState, bool needsRetain)
|
||||
bool MeshRenderer::setProgramState(backend::ProgramState* programState, bool needsRetain)
|
||||
{
|
||||
if (Node::setProgramState(programState, needsRetain))
|
||||
{
|
||||
|
@ -828,7 +828,7 @@ bool Sprite3D::setProgramState(backend::ProgramState* programState, bool needsRe
|
|||
return false;
|
||||
}
|
||||
|
||||
void Sprite3D::setBlendFunc(const BlendFunc& blendFunc)
|
||||
void MeshRenderer::setBlendFunc(const BlendFunc& blendFunc)
|
||||
{
|
||||
if (_blend.src != blendFunc.src || _blend.dst != blendFunc.dst)
|
||||
{
|
||||
|
@ -840,17 +840,17 @@ void Sprite3D::setBlendFunc(const BlendFunc& blendFunc)
|
|||
}
|
||||
}
|
||||
|
||||
const BlendFunc& Sprite3D::getBlendFunc() const
|
||||
const BlendFunc& MeshRenderer::getBlendFunc() const
|
||||
{
|
||||
return _blend;
|
||||
}
|
||||
|
||||
AABB Sprite3D::getAABBRecursively()
|
||||
AABB MeshRenderer::getAABBRecursively()
|
||||
{
|
||||
return getAABBRecursivelyImp(this);
|
||||
}
|
||||
|
||||
const AABB& Sprite3D::getAABB() const
|
||||
const AABB& MeshRenderer::getAABB() const
|
||||
{
|
||||
Mat4 nodeToWorldTransform(getNodeToWorldTransform());
|
||||
|
||||
|
@ -880,45 +880,43 @@ const AABB& Sprite3D::getAABB() const
|
|||
return _aabb;
|
||||
}
|
||||
|
||||
Action* Sprite3D::runAction(Action* action)
|
||||
Action* MeshRenderer::runAction(Action* action)
|
||||
{
|
||||
setForceDepthWrite(true);
|
||||
return Node::runAction(action);
|
||||
}
|
||||
|
||||
Rect Sprite3D::getBoundingBox() const
|
||||
Rect MeshRenderer::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;
|
||||
}
|
||||
|
||||
void Sprite3D::setCullFace(CullFaceSide side)
|
||||
void MeshRenderer::setCullFace(CullFaceSide side)
|
||||
{
|
||||
for (auto& it : _meshes)
|
||||
{
|
||||
it->getMaterial()->getStateBlock().setCullFaceSide(side);
|
||||
// it->getMeshCommand().setCullFace(cullFace);
|
||||
}
|
||||
}
|
||||
|
||||
void Sprite3D::setCullFaceEnabled(bool enable)
|
||||
void MeshRenderer::setCullFaceEnabled(bool enable)
|
||||
{
|
||||
for (auto& it : _meshes)
|
||||
{
|
||||
it->getMaterial()->getStateBlock().setCullFace(enable);
|
||||
// it->getMeshCommand().setCullFaceEnabled(enable);
|
||||
}
|
||||
}
|
||||
|
||||
Mesh* Sprite3D::getMeshByIndex(int index) const
|
||||
Mesh* MeshRenderer::getMeshByIndex(int index) const
|
||||
{
|
||||
CCASSERT(index < _meshes.size(), "invalid index");
|
||||
CCASSERT(index < _meshes.size(), "Invalid index.");
|
||||
return _meshes.at(index);
|
||||
}
|
||||
|
||||
/**get Mesh by Name */
|
||||
Mesh* Sprite3D::getMeshByName(std::string_view name) const
|
||||
Mesh* MeshRenderer::getMeshByName(std::string_view name) const
|
||||
{
|
||||
for (const auto& it : _meshes)
|
||||
{
|
||||
|
@ -928,7 +926,7 @@ Mesh* Sprite3D::getMeshByName(std::string_view name) const
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
std::vector<Mesh*> Sprite3D::getMeshArrayByName(std::string_view name) const
|
||||
std::vector<Mesh*> MeshRenderer::getMeshArrayByName(std::string_view name) const
|
||||
{
|
||||
std::vector<Mesh*> meshes;
|
||||
for (const auto& it : _meshes)
|
||||
|
@ -939,7 +937,7 @@ std::vector<Mesh*> Sprite3D::getMeshArrayByName(std::string_view name) const
|
|||
return meshes;
|
||||
}
|
||||
|
||||
Mesh* Sprite3D::getMesh() const
|
||||
Mesh* MeshRenderer::getMesh() const
|
||||
{
|
||||
if (_meshes.empty())
|
||||
{
|
||||
|
@ -948,7 +946,7 @@ Mesh* Sprite3D::getMesh() const
|
|||
return _meshes.at(0);
|
||||
}
|
||||
|
||||
void Sprite3D::setForce2DQueue(bool force2D)
|
||||
void MeshRenderer::setForce2DQueue(bool force2D)
|
||||
{
|
||||
for (const auto& mesh : _meshes)
|
||||
{
|
||||
|
@ -957,14 +955,14 @@ void Sprite3D::setForce2DQueue(bool force2D)
|
|||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
Sprite3DCache* Sprite3DCache::_cacheInstance = nullptr;
|
||||
Sprite3DCache* Sprite3DCache::getInstance()
|
||||
MeshRendererCache* MeshRendererCache::_cacheInstance = nullptr;
|
||||
MeshRendererCache* MeshRendererCache::getInstance()
|
||||
{
|
||||
if (_cacheInstance == nullptr)
|
||||
_cacheInstance = new Sprite3DCache();
|
||||
_cacheInstance = new MeshRendererCache();
|
||||
return _cacheInstance;
|
||||
}
|
||||
void Sprite3DCache::destroyInstance()
|
||||
void MeshRendererCache::destroyInstance()
|
||||
{
|
||||
if (_cacheInstance)
|
||||
{
|
||||
|
@ -973,54 +971,51 @@ void Sprite3DCache::destroyInstance()
|
|||
}
|
||||
}
|
||||
|
||||
Sprite3DCache::Sprite3DData* Sprite3DCache::getSpriteData(std::string_view key) const
|
||||
MeshRendererCache::MeshRendererData* MeshRendererCache::getMeshData(std::string_view key) const
|
||||
{
|
||||
auto it = _spriteDatas.find(key);
|
||||
if (it != _spriteDatas.end())
|
||||
auto it = _meshDatas.find(key);
|
||||
if (it != _meshDatas.end())
|
||||
return it->second;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool Sprite3DCache::addSprite3DData(std::string_view key, Sprite3DCache::Sprite3DData* spritedata)
|
||||
bool MeshRendererCache::addMeshRendererData(std::string_view key, MeshRendererCache::MeshRendererData* meshdata)
|
||||
{
|
||||
auto it = _spriteDatas.find(key);
|
||||
if (it == _spriteDatas.end())
|
||||
auto it = _meshDatas.find(key);
|
||||
if (it == _meshDatas.end())
|
||||
{
|
||||
_spriteDatas.emplace(key, spritedata); // _spriteDatas[key] = spritedata;
|
||||
_meshDatas.emplace(key, meshdata);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Sprite3DCache::removeSprite3DData(std::string_view key)
|
||||
void MeshRendererCache::removeMeshRendererData(std::string_view key)
|
||||
{
|
||||
auto it = _spriteDatas.find(key);
|
||||
if (it != _spriteDatas.end())
|
||||
auto it = _meshDatas.find(key);
|
||||
if (it != _meshDatas.end())
|
||||
{
|
||||
delete it->second;
|
||||
_spriteDatas.erase(it);
|
||||
_meshDatas.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
void Sprite3DCache::removeAllSprite3DData()
|
||||
void MeshRendererCache::removeAllMeshRendererData()
|
||||
{
|
||||
for (auto& it : _spriteDatas)
|
||||
for (auto& it : _meshDatas)
|
||||
{
|
||||
delete it.second;
|
||||
}
|
||||
_spriteDatas.clear();
|
||||
_meshDatas.clear();
|
||||
}
|
||||
|
||||
Sprite3DCache::Sprite3DCache() {}
|
||||
Sprite3DCache::~Sprite3DCache()
|
||||
MeshRendererCache::MeshRendererCache() {}
|
||||
MeshRendererCache::~MeshRendererCache()
|
||||
{
|
||||
removeAllSprite3DData();
|
||||
removeAllMeshRendererData();
|
||||
}
|
||||
|
||||
//
|
||||
// MARK: Helpers
|
||||
//
|
||||
static Sprite3DMaterial* getSprite3DMaterialForAttribs(MeshVertexData* meshVertexData, bool usesLight)
|
||||
static MeshMaterial* getMeshRendererMaterialForAttribs(MeshVertexData* meshVertexData, bool usesLight)
|
||||
{
|
||||
bool textured = meshVertexData->hasVertexAttrib(shaderinfos::VertexKey::VERTEX_ATTRIB_TEX_COORD);
|
||||
bool hasSkin = meshVertexData->hasVertexAttrib(shaderinfos::VertexKey::VERTEX_ATTRIB_BLEND_INDEX) &&
|
||||
|
@ -1028,27 +1023,27 @@ static Sprite3DMaterial* getSprite3DMaterialForAttribs(MeshVertexData* meshVerte
|
|||
bool hasNormal = meshVertexData->hasVertexAttrib(shaderinfos::VertexKey::VERTEX_ATTRIB_NORMAL);
|
||||
bool hasTangentSpace = meshVertexData->hasVertexAttrib(shaderinfos::VertexKey::VERTEX_ATTRIB_TANGENT) &&
|
||||
meshVertexData->hasVertexAttrib(shaderinfos::VertexKey::VERTEX_ATTRIB_BINORMAL);
|
||||
Sprite3DMaterial::MaterialType type;
|
||||
MeshMaterial::MaterialType type;
|
||||
if (textured)
|
||||
{
|
||||
if (hasTangentSpace)
|
||||
{
|
||||
type = hasNormal && usesLight ? Sprite3DMaterial::MaterialType::BUMPED_DIFFUSE
|
||||
: Sprite3DMaterial::MaterialType::UNLIT;
|
||||
type = hasNormal && usesLight ? MeshMaterial::MaterialType::BUMPED_DIFFUSE
|
||||
: MeshMaterial::MaterialType::UNLIT;
|
||||
}
|
||||
else
|
||||
{
|
||||
type = hasNormal && usesLight ? Sprite3DMaterial::MaterialType::DIFFUSE
|
||||
: Sprite3DMaterial::MaterialType::UNLIT;
|
||||
type = hasNormal && usesLight ? MeshMaterial::MaterialType::DIFFUSE
|
||||
: MeshMaterial::MaterialType::UNLIT;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
type = hasNormal && usesLight ? Sprite3DMaterial::MaterialType::DIFFUSE_NOTEX
|
||||
: Sprite3DMaterial::MaterialType::UNLIT_NOTEX;
|
||||
type = hasNormal && usesLight ? MeshMaterial::MaterialType::DIFFUSE_NOTEX
|
||||
: MeshMaterial::MaterialType::UNLIT_NOTEX;
|
||||
}
|
||||
|
||||
return Sprite3DMaterial::createBuiltInMaterial(type, hasSkin);
|
||||
return MeshMaterial::createBuiltInMaterial(type, hasSkin);
|
||||
}
|
||||
|
||||
NS_CC_END
|
|
@ -23,8 +23,8 @@
|
|||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __CCSPRITE3D_H__
|
||||
#define __CCSPRITE3D_H__
|
||||
#ifndef __CC_MESH_RENDERER_H__
|
||||
#define __CC_MESH_RENDERER_H__
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
|
@ -33,7 +33,7 @@
|
|||
#include "base/CCProtocols.h"
|
||||
#include "2d/CCNode.h"
|
||||
#include "renderer/CCMeshCommand.h"
|
||||
#include "3d/CCSkeleton3D.h" // need to include for lua-binding
|
||||
#include "3d/CCSkeleton3D.h" // needs to be included for lua-bindings
|
||||
#include "3d/CCAABB.h"
|
||||
#include "3d/CCBundle3DData.h"
|
||||
#include "3d/CCMeshVertexIndexData.h"
|
||||
|
@ -50,49 +50,52 @@ class Texture2D;
|
|||
class MeshSkin;
|
||||
class AttachNode;
|
||||
struct NodeData;
|
||||
/** @brief Sprite3D: A sprite can be loaded from 3D model files, .obj, .c3t, .c3b, then can be drawn as sprite */
|
||||
class CC_DLL Sprite3D : public Node, public BlendProtocol
|
||||
/** @brief MeshRenderer: A mesh can be loaded from model files, .obj, .c3t, .c3b
|
||||
*and a mesh renderer renders a list of these loaded meshes with specified materials
|
||||
*/
|
||||
class CC_DLL MeshRenderer : public Node, public BlendProtocol
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Creates an empty sprite3D without 3D model and texture.
|
||||
* Creates an empty MeshRenderer without a mesh or a texture.
|
||||
* Can be used to create procedural meshes on runtime.
|
||||
*
|
||||
* @return An autoreleased sprite3D object.
|
||||
* @return An autoreleased MeshRenderer object.
|
||||
*/
|
||||
static Sprite3D* create();
|
||||
static MeshRenderer* create();
|
||||
|
||||
/** creates a Sprite3D*/
|
||||
static Sprite3D* create(std::string_view modelPath);
|
||||
/** creates a MeshRenderer with a specified path */
|
||||
static MeshRenderer* create(std::string_view modelPath);
|
||||
|
||||
// creates a Sprite3D. It only supports one texture, and overrides the internal texture with 'texturePath'
|
||||
static Sprite3D* create(std::string_view modelPath, std::string_view texturePath);
|
||||
/** creates a MeshRenderer. A mesh can only have one texture, the default texture can be overridden with 'texturePath' */
|
||||
static MeshRenderer* create(std::string_view modelPath, std::string_view 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 user-defined parameter. The callback will be called from the main thread,
|
||||
* so it is safe to create any cocos2d object from the callback.
|
||||
/** create 3d mesh asynchronously
|
||||
* If the 3d model was previously loaded, it will create a new 3d mesh and the callback will be called once.
|
||||
* Otherwise it will load the model file in a new thread, and when the 3d mesh is loaded, the callback will be
|
||||
* called with the created MeshRenderer and a user-defined parameter. The callback will be called from the main thread,
|
||||
* so it is safe to create any object from the callback.
|
||||
* @param modelPath model to be loaded
|
||||
* @param callback callback after loading
|
||||
* @param callbackparam user defined parameter for the callback
|
||||
* @param callback callback when loading is finished
|
||||
* @param callbackparam user-defined parameter for the callback
|
||||
*/
|
||||
static void createAsync(std::string_view modelPath,
|
||||
const std::function<void(Sprite3D*, void*)>& callback,
|
||||
const std::function<void(MeshRenderer*, void*)>& callback,
|
||||
void* callbackparam);
|
||||
|
||||
static void createAsync(std::string_view modelPath,
|
||||
std::string_view texturePath,
|
||||
const std::function<void(Sprite3D*, void*)>& callback,
|
||||
const std::function<void(MeshRenderer*, void*)>& callback,
|
||||
void* callbackparam);
|
||||
|
||||
/**set diffuse texture, set the first if multiple textures exist*/
|
||||
/** set diffuse texture, set the first mesh's texture if multiple textures exist */
|
||||
void setTexture(std::string_view texFile);
|
||||
void setTexture(Texture2D* texture);
|
||||
|
||||
/**get Mesh by index*/
|
||||
/** get Mesh by index */
|
||||
Mesh* getMeshByIndex(int index) const;
|
||||
|
||||
/**get Mesh by Name, it returns the first one if there are more than one mesh with the same name */
|
||||
/** get Mesh by Name, returns the first one if there are more than one mesh with the same name */
|
||||
Mesh* getMeshByName(std::string_view name) const;
|
||||
|
||||
/**
|
||||
|
@ -102,7 +105,7 @@ public:
|
|||
*/
|
||||
std::vector<Mesh*> getMeshArrayByName(std::string_view name) const;
|
||||
|
||||
/**get mesh*/
|
||||
/** get mesh at index 0 which is the default mesh */
|
||||
Mesh* getMesh() const;
|
||||
|
||||
/** get mesh count */
|
||||
|
@ -110,13 +113,13 @@ public:
|
|||
|
||||
Skeleton3D* getSkeleton() const { return _skeleton; }
|
||||
|
||||
/**get AttachNode by bone name, return nullptr if not exist*/
|
||||
/** return an AttachNode by bone name. Otherwise, return nullptr if it doesn't exist */
|
||||
AttachNode* getAttachNode(std::string_view boneName);
|
||||
|
||||
/**remove attach node*/
|
||||
/** remove an attached node */
|
||||
void removeAttachNode(std::string_view boneName);
|
||||
|
||||
/**remove all attach nodes*/
|
||||
/** remove all attached nodes */
|
||||
void removeAllAttachNode();
|
||||
|
||||
// overrides
|
||||
|
@ -124,91 +127,88 @@ public:
|
|||
virtual const BlendFunc& getBlendFunc() const override;
|
||||
|
||||
// overrides
|
||||
/** Sets ProgramState, you should bind attributes by yourself */
|
||||
/** Sets ProgramState, attributes should be bound by the user */
|
||||
bool setProgramState(backend::ProgramState* programState, bool needsRetain = true) override;
|
||||
|
||||
/*
|
||||
* Get AABB
|
||||
* If the sprite has animation, it can't be calculated accurately,
|
||||
* because bone can drive the vertices, we just use the origin vertices
|
||||
* If the mesh has animations, it can't be calculated accurately,
|
||||
* because a bone can transform the vertices, and the untransformed vertices are used
|
||||
* to calculate the AABB.
|
||||
*/
|
||||
const AABB& getAABB() const;
|
||||
|
||||
/*
|
||||
* Get AABB Recursively
|
||||
* Because some times we may have an empty Sprite3D Node as parent, but
|
||||
* the Sprite3D don't contain any meshes, so getAABB()
|
||||
* will return a wrong value at that time.
|
||||
* Because sometimes we may have an empty MeshRenderer Node as parent, If
|
||||
* the MeshRenderer doesn't contain any meshes, then we use getAABB()
|
||||
*/
|
||||
AABB getAABBRecursively();
|
||||
|
||||
/**
|
||||
* Executes an action, and returns the action that is executed. For Sprite3D special logic are needed to take care
|
||||
* of Fading.
|
||||
* Executes an action, and returns the action that is executed. For the MeshRenderer special logic is needed to take
|
||||
* care of Fading.
|
||||
*
|
||||
* This node becomes the action's target. Refer to Action::getTarget()
|
||||
* @warning Actions don't retain their target.
|
||||
*
|
||||
* @return An Action pointer
|
||||
* @return a pointer to Action
|
||||
*/
|
||||
virtual Action* runAction(Action* action) override;
|
||||
|
||||
/**
|
||||
* Force to write to depth buffer, this is useful if you want to achieve effects like fading.
|
||||
* Force depth buffer writing, this is useful if you want to achieve effects like fading.
|
||||
*/
|
||||
void setForceDepthWrite(bool value) { _forceDepthWrite = value; }
|
||||
bool isForceDepthWrite() const { return _forceDepthWrite; };
|
||||
|
||||
/**
|
||||
* Returns 2d bounding-box
|
||||
* Note: the bounding-box is just get from the AABB which as Z=0, so that is not very accurate.
|
||||
* Returns a 2d bounding-box
|
||||
* Note: the bounding-box is taken from the mesh's AABB with Z-axis ignored.
|
||||
*/
|
||||
virtual Rect getBoundingBox() const override;
|
||||
|
||||
// set which face is going to cull, CullFaceSide::BACK, CullFaceSide::FRONT and CullFaceSide::NONE.
|
||||
// set face culling side, CullFaceSide::BACK, CullFaceSide::FRONT and CullFaceSide::NONE.
|
||||
virtual void setCullFace(CullFaceSide side);
|
||||
// set cull face enable or not
|
||||
// set face culling enabled.
|
||||
void setCullFaceEnabled(bool enable);
|
||||
|
||||
/** light mask getter & setter, light works only when _lightmask & light's flag is true, default value of _lightmask
|
||||
* is 0xffff */
|
||||
/** light mask getter & setter, lighting only works when _lightmask & light's flag are set to true, the default
|
||||
value of _lightmask is 0xffff */
|
||||
void setLightMask(unsigned int mask) { _lightMask = mask; }
|
||||
unsigned int getLightMask() const { return _lightMask; }
|
||||
|
||||
/**draw*/
|
||||
/** render all meshes within this mesh renderer */
|
||||
virtual void draw(Renderer* renderer, const Mat4& transform, uint32_t flags) override;
|
||||
|
||||
/** Adds a new material to the sprite.
|
||||
The Material will be applied to all the meshes that belong to the sprite.
|
||||
Internally it will call `setMaterial(material,-1)`
|
||||
/** Adds a new material to this mesh renderer.
|
||||
The Material will be applied to all the meshes that belong to the mesh renderer.
|
||||
It will internally call `setMaterial(material,-1)`
|
||||
*/
|
||||
void setMaterial(Material* material);
|
||||
|
||||
/** Adds a new material to a particular mesh of the sprite.
|
||||
meshIndex is the mesh that will be applied to.
|
||||
if meshIndex == -1, then it will be applied to all the meshes that belong to the sprite.
|
||||
/** Adds a new material to a particular mesh in this mesh renderer.
|
||||
* if meshIndex == -1, then it will be applied to all the meshes that belong to this mesh renderer.
|
||||
*
|
||||
* @param meshIndex Index of the mesh to apply the material to.
|
||||
*/
|
||||
void setMaterial(Material* material, int meshIndex);
|
||||
|
||||
/** Adds a new material to a particular mesh of the sprite.
|
||||
meshIndex is the mesh that will be applied to.
|
||||
if meshIndex == -1, then it will be applied to all the meshes that belong to the sprite.
|
||||
/** Adds a new material to a particular mesh in this mesh renderer.
|
||||
* if meshIndex == -1, then it will be applied to all the meshes that belong to this mesh renderer.
|
||||
*
|
||||
* @param meshIndex Index of the mesh to apply the material to.
|
||||
*/
|
||||
Material* getMaterial(int meshIndex) const;
|
||||
|
||||
/**
|
||||
* force set this Sprite3D to 2D render queue
|
||||
*/
|
||||
/** force render this mesh renderer in 2D queue. */
|
||||
void setForce2DQueue(bool force2D);
|
||||
|
||||
/**
|
||||
* Get meshes used in sprite 3d
|
||||
*/
|
||||
/** Get list of meshes used in this mesh renderer. */
|
||||
const Vector<Mesh*>& getMeshes() const { return _meshes; }
|
||||
|
||||
Sprite3D();
|
||||
virtual ~Sprite3D();
|
||||
MeshRenderer();
|
||||
virtual ~MeshRenderer();
|
||||
|
||||
virtual bool init() override;
|
||||
|
||||
|
@ -216,27 +216,28 @@ public:
|
|||
|
||||
bool initFrom(const NodeDatas& nodedatas, const MeshDatas& meshdatas, const MaterialDatas& materialdatas);
|
||||
|
||||
/**load sprite3d from cache, return true if succeed, false otherwise*/
|
||||
/** load a mesh renderer from cache, returns true if succeeded, false otherwise. */
|
||||
bool loadFromCache(std::string_view path);
|
||||
|
||||
/** load file and set it to meshedatas, nodedatas and materialdatas, obj file .mtl file should be at the same
|
||||
* directory if exist */
|
||||
/** load a file and feed it's content into meshedatas, nodedatas and materialdatas, obj file and .mtl file
|
||||
should be in the same directory. */
|
||||
bool loadFromFile(std::string_view path, NodeDatas* nodedatas, MeshDatas* meshdatas, MaterialDatas* materialdatas);
|
||||
|
||||
/**
|
||||
* Visits this Sprite3D's children and draw them recursively.
|
||||
* Note: all its children will rendered as 3D objects
|
||||
* Visits this MeshRenderer's children and draws them recursively.
|
||||
* Note: all children will be rendered in 3D space with depth, this behaviour can be changed using
|
||||
* setForce2DQueue()
|
||||
*/
|
||||
virtual void visit(Renderer* renderer, const Mat4& parentTransform, uint32_t parentFlags) override;
|
||||
|
||||
/**generate default material*/
|
||||
/** generate default material. */
|
||||
void genMaterial(bool useLight = false);
|
||||
|
||||
void createNode(NodeData* nodedata, Node* root, const MaterialDatas& materialdatas, bool singleSprite);
|
||||
void createAttachSprite3DNode(NodeData* nodedata, const MaterialDatas& materialdatas);
|
||||
Sprite3D* createSprite3DNode(NodeData* nodedata, ModelData* modeldata, const MaterialDatas& materialdatas);
|
||||
void createNode(NodeData* nodedata, Node* root, const MaterialDatas& materialdatas, bool singleMesh);
|
||||
void createAttachMeshRendererNode(NodeData* nodedata, const MaterialDatas& materialdatas);
|
||||
MeshRenderer* createMeshRendererNode(NodeData* nodedata, ModelData* modeldata, const MaterialDatas& materialdatas);
|
||||
|
||||
/**get MeshIndexData by Id*/
|
||||
/** get MeshIndexData by Id */
|
||||
MeshIndexData* getMeshIndexData(std::string_view indexId) const;
|
||||
|
||||
void addMesh(Mesh* mesh);
|
||||
|
@ -248,7 +249,7 @@ public:
|
|||
static AABB getAABBRecursivelyImp(Node* node);
|
||||
|
||||
protected:
|
||||
Skeleton3D* _skeleton; // skeleton
|
||||
Skeleton3D* _skeleton;
|
||||
|
||||
Vector<MeshVertexData*> _meshVertexDatas;
|
||||
|
||||
|
@ -259,21 +260,21 @@ protected:
|
|||
Vector<Mesh*> _meshes;
|
||||
|
||||
mutable AABB _aabb; // cache current aabb
|
||||
mutable Mat4 _nodeToWorldTransform; // cache the matrix
|
||||
mutable Mat4 _nodeToWorldTransform; // cache current matrix
|
||||
mutable bool _aabbDirty;
|
||||
unsigned int _lightMask;
|
||||
bool _shaderUsingLight; // is current shader using light ?
|
||||
bool _shaderUsingLight; // Is the current shader using lighting?
|
||||
bool _forceDepthWrite; // Always write to depth buffer
|
||||
bool _usingAutogeneratedGLProgram;
|
||||
|
||||
struct AsyncLoadParam
|
||||
{
|
||||
std::function<void(Sprite3D*, void*)> afterLoadCallback; // callback after load
|
||||
std::function<void(MeshRenderer*, void*)> afterLoadCallback; // callback after loading is finished
|
||||
void* callbackParam;
|
||||
bool result; // sprite load result
|
||||
bool result; // mesh renderer loading result
|
||||
std::string modelPath;
|
||||
std::string modelFullPath;
|
||||
std::string texPath; //
|
||||
std::string texPath;
|
||||
MeshDatas* meshdatas;
|
||||
MaterialDatas* materialdatas;
|
||||
NodeDatas* nodeDatas;
|
||||
|
@ -283,19 +284,18 @@ protected:
|
|||
|
||||
///////////////////////////////////////////////////////
|
||||
/**
|
||||
* Sprite3DCache
|
||||
* @brief the cache data of Sprite3D, use to speed up Sprite3D::create
|
||||
* @brief MeshRendererCache: the cache data of MeshRenderer, used to speed up the creation process of MeshRenderer
|
||||
*/
|
||||
class CC_DLL Sprite3DCache
|
||||
class CC_DLL MeshRendererCache
|
||||
{
|
||||
public:
|
||||
struct Sprite3DData
|
||||
struct MeshRendererData
|
||||
{
|
||||
Vector<MeshVertexData*> meshVertexDatas;
|
||||
Vector<backend::ProgramState*> programStates;
|
||||
NodeDatas* nodedatas;
|
||||
MaterialDatas* materialdatas;
|
||||
~Sprite3DData()
|
||||
~MeshRendererData()
|
||||
{
|
||||
if (nodedatas)
|
||||
delete nodedatas;
|
||||
|
@ -306,40 +306,39 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
/**get & destroy*/
|
||||
static Sprite3DCache* getInstance();
|
||||
static MeshRendererCache* getInstance();
|
||||
static void destroyInstance();
|
||||
|
||||
/**
|
||||
* get the SpriteData struct
|
||||
* get a MeshData object by key
|
||||
*
|
||||
* @lua NA
|
||||
*/
|
||||
Sprite3DData* getSpriteData(std::string_view key) const;
|
||||
MeshRendererData* getMeshData(std::string_view key) const;
|
||||
|
||||
/**
|
||||
* add the SpriteData into Sprite3D by given the specified key
|
||||
* add a MeshData object into the MeshRenderer with a specified key
|
||||
*
|
||||
* @lua NA
|
||||
*/
|
||||
bool addSprite3DData(std::string_view key, Sprite3DData* spritedata);
|
||||
bool addMeshRendererData(std::string_view key, MeshRendererData* meshdata);
|
||||
|
||||
/**remove the SpriteData from Sprite3D by given the specified key*/
|
||||
void removeSprite3DData(std::string_view key);
|
||||
/** remove a MeshData from the MeshRenderer with a specified key */
|
||||
void removeMeshRendererData(std::string_view key);
|
||||
|
||||
/**remove all the SpriteData from Sprite3D*/
|
||||
void removeAllSprite3DData();
|
||||
/** remove all the MeshData objects from the MeshRenderer */
|
||||
void removeAllMeshRendererData();
|
||||
|
||||
Sprite3DCache();
|
||||
~Sprite3DCache();
|
||||
MeshRendererCache();
|
||||
~MeshRendererCache();
|
||||
|
||||
protected:
|
||||
static Sprite3DCache* _cacheInstance;
|
||||
hlookup::string_map<Sprite3DData*> _spriteDatas; // cached sprite data
|
||||
static MeshRendererCache* _cacheInstance;
|
||||
hlookup::string_map<MeshRendererData*> _meshDatas; // cached mesh data
|
||||
};
|
||||
|
||||
// end of 3d group
|
||||
/// @}
|
||||
|
||||
NS_CC_END
|
||||
#endif // __SPRITE3D_H_
|
||||
#endif // __CC_MESH_RENDERER_H__
|
|
@ -30,7 +30,7 @@
|
|||
|
||||
#include "3d/CCMeshVertexIndexData.h"
|
||||
#include "3d/CCObjLoader.h"
|
||||
#include "3d/CCSprite3DMaterial.h"
|
||||
#include "3d/CCMeshMaterial.h"
|
||||
#include "3d/CCMesh.h"
|
||||
#include "3d/CCBundle3D.h"
|
||||
|
||||
|
|
|
@ -95,7 +95,7 @@ protected:
|
|||
MeshData::IndexArray _indexData;
|
||||
|
||||
friend class MeshVertexData;
|
||||
friend class Sprite3D;
|
||||
friend class MeshRenderer;
|
||||
#if CC_ENABLE_CACHE_TEXTURE_DATA
|
||||
EventListenerCustom* _backToForegroundListener = nullptr;
|
||||
#endif
|
||||
|
@ -107,7 +107,7 @@ protected:
|
|||
*/
|
||||
class CC_DLL MeshVertexData : public Ref
|
||||
{
|
||||
friend class Sprite3D;
|
||||
friend class MeshRenderer;
|
||||
friend class Mesh;
|
||||
|
||||
public:
|
||||
|
|
|
@ -36,9 +36,9 @@ NS_CC_BEGIN
|
|||
*/
|
||||
|
||||
/**
|
||||
* Oriented Bounding Box(OBB)
|
||||
* @brief the OBB is similar to the AABB but the bounding box has the same direction as Sprite3D. so it's collision
|
||||
* detection more precise than AABB
|
||||
*
|
||||
* @brief Oriented Bounding Box(OBB): OBB is similar to AABB except the bounding box has the same direction as the
|
||||
* MeshRenderer. so collision detection is more precise than AABB.
|
||||
* @js NA
|
||||
*/
|
||||
class CC_DLL OBB
|
||||
|
|
|
@ -2,7 +2,6 @@ set(COCOS_3D_HEADER
|
|||
|
||||
3d/CCBillBoard.h
|
||||
3d/CCFrustum.h
|
||||
3d/CCSprite3DMaterial.h
|
||||
3d/CCMeshVertexIndexData.h
|
||||
3d/CCPlane.h
|
||||
3d/CCRay.h
|
||||
|
@ -10,7 +9,8 @@ set(COCOS_3D_HEADER
|
|||
3d/CCAnimate3D.h
|
||||
3d/CCTerrain.h
|
||||
3d/CCAnimationCurve.h
|
||||
3d/CCSprite3D.h
|
||||
3d/CCMeshRenderer.h
|
||||
3d/CCMeshMaterial.h
|
||||
3d/CCOBB.h
|
||||
3d/CCAnimation3D.h
|
||||
3d/CCMotionStreak3D.h
|
||||
|
@ -49,8 +49,8 @@ set(COCOS_3D_SRC
|
|||
3d/CCRay.cpp
|
||||
3d/CCSkeleton3D.cpp
|
||||
3d/CCSkybox.cpp
|
||||
3d/CCSprite3D.cpp
|
||||
3d/CCSprite3DMaterial.cpp
|
||||
3d/CCMeshRenderer.cpp
|
||||
3d/CCMeshMaterial.cpp
|
||||
3d/CCTerrain.cpp
|
||||
3d/CCVertexAttribBinding.cpp
|
||||
3d/CC3DProgramInfo.cpp
|
||||
|
|
|
@ -265,8 +265,8 @@ THE SOFTWARE.
|
|||
#include "3d/CCRay.h"
|
||||
#include "3d/CCSkeleton3D.h"
|
||||
#include "3d/CCSkybox.h"
|
||||
#include "3d/CCSprite3D.h"
|
||||
#include "3d/CCSprite3DMaterial.h"
|
||||
#include "3d/CCMeshRenderer.h"
|
||||
#include "3d/CCMeshMaterial.h"
|
||||
#include "3d/CCTerrain.h"
|
||||
#include "3d/CCVertexAttribBinding.h"
|
||||
|
||||
|
|
|
@ -176,34 +176,34 @@ public:
|
|||
*/
|
||||
bool supportsMapBuffer() const;
|
||||
|
||||
/** Max support directional light in shader, for Sprite3D.
|
||||
/** Max supported directional lights in a shader, for MeshRenderer.
|
||||
*
|
||||
* @return Maximum supports directional light in shader.
|
||||
* @return Maximum supported directional lights in a shader.
|
||||
* @since v3.3
|
||||
*/
|
||||
int getMaxSupportDirLightInShader() const;
|
||||
|
||||
/** Max support point light in shader, for Sprite3D.
|
||||
/** Max supported point lights in a shader, for MeshRenderer.
|
||||
*
|
||||
* @return Maximum supports point light in shader.
|
||||
* @return Maximum supported point lights in a shader.
|
||||
* @since v3.3
|
||||
*/
|
||||
int getMaxSupportPointLightInShader() const;
|
||||
|
||||
/** Max support spot light in shader, for Sprite3D.
|
||||
/** Max supported spot lights in a shader, for MeshRenderer.
|
||||
*
|
||||
* @return Maximum supports spot light in shader.
|
||||
* @return Maximum supported spot lights in a shader.
|
||||
* @since v3.3
|
||||
*/
|
||||
int getMaxSupportSpotLightInShader() const;
|
||||
|
||||
/** get 3d animate quality*/
|
||||
/** get 3d animate quality */
|
||||
Animate3DQuality getAnimate3DQuality() const;
|
||||
|
||||
/** Returns whether or not an OpenGL is supported.
|
||||
/** Returns whether or not an OpenGL extension is supported.
|
||||
*
|
||||
* @param searchName A given search name.
|
||||
* @return Is true if an OpenGL is supported.
|
||||
* @return Is true if an OpenGL extension is supported.
|
||||
*/
|
||||
bool checkForGLExtension(std::string_view searchName) const;
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
#if CC_USE_3D_PHYSICS
|
||||
|
||||
# include "physics3d/CCPhysics3DShape.h"
|
||||
# include "physics3d/CCPhysicsSprite3D.h"
|
||||
# include "physics3d/CCPhysicsMeshRenderer.h"
|
||||
# include "physics3d/CCPhysics3DWorld.h"
|
||||
# include "physics3d/CCPhysics3DDebugDrawer.h"
|
||||
# include "physics3d/CCPhysics3DObject.h"
|
||||
|
|
|
@ -31,12 +31,12 @@
|
|||
|
||||
NS_CC_BEGIN
|
||||
|
||||
PhysicsSprite3D* PhysicsSprite3D::create(std::string_view modelPath,
|
||||
PhysicsMeshRenderer* PhysicsMeshRenderer::create(std::string_view modelPath,
|
||||
Physics3DRigidBodyDes* rigidDes,
|
||||
const cocos2d::Vec3& translateInPhysics,
|
||||
const cocos2d::Quaternion& rotInPhsyics)
|
||||
{
|
||||
auto ret = new PhysicsSprite3D();
|
||||
auto ret = new PhysicsMeshRenderer();
|
||||
if (ret->initWithFile(modelPath))
|
||||
{
|
||||
auto obj = Physics3DRigidBody::create(rigidDes);
|
||||
|
@ -50,12 +50,12 @@ PhysicsSprite3D* PhysicsSprite3D::create(std::string_view modelPath,
|
|||
return ret;
|
||||
}
|
||||
|
||||
PhysicsSprite3D* PhysicsSprite3D::createWithCollider(std::string_view modelPath,
|
||||
PhysicsMeshRenderer* PhysicsMeshRenderer::createWithCollider(std::string_view modelPath,
|
||||
Physics3DColliderDes* colliderDes,
|
||||
const cocos2d::Vec3& translateInPhysics,
|
||||
const cocos2d::Quaternion& rotInPhsyics)
|
||||
{
|
||||
auto ret = new PhysicsSprite3D();
|
||||
auto ret = new PhysicsMeshRenderer();
|
||||
if (ret->initWithFile(modelPath))
|
||||
{
|
||||
auto obj = Physics3DCollider::create(colliderDes);
|
||||
|
@ -69,31 +69,31 @@ PhysicsSprite3D* PhysicsSprite3D::createWithCollider(std::string_view modelPath,
|
|||
return ret;
|
||||
}
|
||||
|
||||
Physics3DObject* PhysicsSprite3D::getPhysicsObj() const
|
||||
Physics3DObject* PhysicsMeshRenderer::getPhysicsObj() const
|
||||
{
|
||||
return _physicsComponent->getPhysics3DObject();
|
||||
}
|
||||
|
||||
void PhysicsSprite3D::setSyncFlag(Physics3DComponent::PhysicsSyncFlag syncFlag)
|
||||
void PhysicsMeshRenderer::setSyncFlag(Physics3DComponent::PhysicsSyncFlag syncFlag)
|
||||
{
|
||||
if (_physicsComponent)
|
||||
_physicsComponent->setSyncFlag(syncFlag);
|
||||
}
|
||||
|
||||
void PhysicsSprite3D::syncNodeToPhysics()
|
||||
void PhysicsMeshRenderer::syncNodeToPhysics()
|
||||
{
|
||||
if (_physicsComponent)
|
||||
_physicsComponent->syncNodeToPhysics();
|
||||
}
|
||||
|
||||
void PhysicsSprite3D::syncPhysicsToNode()
|
||||
void PhysicsMeshRenderer::syncPhysicsToNode()
|
||||
{
|
||||
if (_physicsComponent)
|
||||
_physicsComponent->syncPhysicsToNode();
|
||||
}
|
||||
|
||||
PhysicsSprite3D::PhysicsSprite3D() : _physicsComponent(nullptr) {}
|
||||
PhysicsSprite3D::~PhysicsSprite3D() {}
|
||||
PhysicsMeshRenderer::PhysicsMeshRenderer() : _physicsComponent(nullptr) {}
|
||||
PhysicsMeshRenderer::~PhysicsMeshRenderer() {}
|
||||
|
||||
NS_CC_END
|
||||
|
|
@ -23,11 +23,11 @@
|
|||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __PHYSICS_SPRITE_3D_H__
|
||||
#define __PHYSICS_SPRITE_3D_H__
|
||||
#ifndef __PHYSICS_MESH_RENDERER_H__
|
||||
#define __PHYSICS_MESH_RENDERER_H__
|
||||
|
||||
#include "base/ccConfig.h"
|
||||
#include "3d/CCSprite3D.h"
|
||||
#include "3d/CCMeshRenderer.h"
|
||||
#include "physics3d/CCPhysics3DObject.h"
|
||||
#include "physics3d/CCPhysics3DComponent.h"
|
||||
|
||||
|
@ -42,19 +42,19 @@ NS_CC_BEGIN
|
|||
*/
|
||||
|
||||
/**
|
||||
* @brief Convenient class to create a rigid body with Sprite3D
|
||||
* @brief Convenient class to create a rigid body with a MeshRenderer
|
||||
*/
|
||||
class CC_DLL PhysicsSprite3D : public cocos2d::Sprite3D
|
||||
class CC_DLL PhysicsMeshRenderer : public cocos2d::MeshRenderer
|
||||
{
|
||||
public:
|
||||
/** creates a PhysicsSprite3D*/
|
||||
static PhysicsSprite3D* create(std::string_view modelPath,
|
||||
/** creates a PhysicsMeshRenderer */
|
||||
static PhysicsMeshRenderer* create(std::string_view modelPath,
|
||||
Physics3DRigidBodyDes* rigidDes,
|
||||
const cocos2d::Vec3& translateInPhysics = cocos2d::Vec3::ZERO,
|
||||
const cocos2d::Quaternion& rotInPhsyics = cocos2d::Quaternion::ZERO);
|
||||
|
||||
/** creates a PhysicsSprite3D as a collider*/
|
||||
static PhysicsSprite3D* createWithCollider(std::string_view modelPath,
|
||||
/** creates a PhysicsMeshRenderer with a collider */
|
||||
static PhysicsMeshRenderer* createWithCollider(std::string_view modelPath,
|
||||
Physics3DColliderDes* colliderDes,
|
||||
const cocos2d::Vec3& translateInPhysics = cocos2d::Vec3::ZERO,
|
||||
const cocos2d::Quaternion& rotInPhsyics = cocos2d::Quaternion::ZERO);
|
||||
|
@ -71,8 +71,8 @@ public:
|
|||
/** synchronize physics transformation to node. */
|
||||
void syncPhysicsToNode();
|
||||
|
||||
PhysicsSprite3D();
|
||||
virtual ~PhysicsSprite3D();
|
||||
PhysicsMeshRenderer();
|
||||
virtual ~PhysicsMeshRenderer();
|
||||
|
||||
protected:
|
||||
Physics3DComponent* _physicsComponent;
|
||||
|
@ -86,4 +86,4 @@ NS_CC_END
|
|||
|
||||
#endif // CC_USE_3D_PHYSICS
|
||||
|
||||
#endif // __PHYSICS_SPRITE_3D_H__
|
||||
#endif // __PHYSICS_MESH_RENDERER_H__
|
|
@ -3,7 +3,7 @@ set(COCOS_PHYSICS3D_HEADER
|
|||
physics3d/CCPhysics3DShape.h
|
||||
physics3d/CCPhysics3D.h
|
||||
physics3d/CCPhysics3DWorld.h
|
||||
physics3d/CCPhysicsSprite3D.h
|
||||
physics3d/CCPhysicsMeshRenderer.h
|
||||
physics3d/CCPhysics3DObject.h
|
||||
physics3d/CCPhysics3DComponent.h
|
||||
physics3d/CCPhysics3DDebugDrawer.h
|
||||
|
@ -17,5 +17,5 @@ set(COCOS_PHYSICS3D_SRC
|
|||
physics3d/CCPhysics3DObject.cpp
|
||||
physics3d/CCPhysics3DShape.cpp
|
||||
physics3d/CCPhysics3DWorld.cpp
|
||||
physics3d/CCPhysicsSprite3D.cpp
|
||||
physics3d/CCPhysicsMeshRenderer.cpp
|
||||
)
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
#include "renderer/backend/Device.h"
|
||||
#include "renderer/ccShaders.h"
|
||||
#include "base/CCDirector.h"
|
||||
#include "3d/CCSprite3D.h"
|
||||
#include "3d/CCMeshRenderer.h"
|
||||
#include "2d/CCCamera.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
@ -280,10 +280,10 @@ void Particle3DQuadRender::reset()
|
|||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
Particle3DModelRender::Particle3DModelRender() : _spriteSize(Vec3::ONE) {}
|
||||
Particle3DModelRender::Particle3DModelRender() : _meshSize(Vec3::ONE) {}
|
||||
Particle3DModelRender::~Particle3DModelRender()
|
||||
{
|
||||
for (auto iter : _spriteList)
|
||||
for (auto iter : _meshList)
|
||||
{
|
||||
iter->release();
|
||||
}
|
||||
|
@ -302,26 +302,26 @@ void Particle3DModelRender::render(Renderer* renderer, const Mat4& transform, Pa
|
|||
if (!_isVisible)
|
||||
return;
|
||||
|
||||
if (_spriteList.empty())
|
||||
if (_meshList.empty())
|
||||
{
|
||||
for (unsigned int i = 0; i < particleSystem->getParticleQuota(); ++i)
|
||||
{
|
||||
Sprite3D* sprite = Sprite3D::create(_modelFile);
|
||||
if (sprite == nullptr)
|
||||
MeshRenderer* mesh = MeshRenderer::create(_modelFile);
|
||||
if (mesh == nullptr)
|
||||
{
|
||||
CCLOG("failed to load file %s", _modelFile.c_str());
|
||||
continue;
|
||||
}
|
||||
sprite->setTexture(_texFile);
|
||||
sprite->retain();
|
||||
_spriteList.push_back(sprite);
|
||||
mesh->setTexture(_texFile);
|
||||
mesh->retain();
|
||||
_meshList.push_back(mesh);
|
||||
}
|
||||
if (!_spriteList.empty())
|
||||
if (!_meshList.empty())
|
||||
{
|
||||
const AABB& aabb = _spriteList[0]->getAABB();
|
||||
const AABB& aabb = _meshList[0]->getAABB();
|
||||
Vec3 corners[8];
|
||||
aabb.getCorners(corners);
|
||||
_spriteSize = corners[3] - corners[6];
|
||||
_meshSize = corners[3] - corners[6];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -337,24 +337,24 @@ void Particle3DModelRender::render(Renderer* renderer, const Mat4& transform, Pa
|
|||
{
|
||||
auto particle = iter;
|
||||
Mat4::createRotation(q * particle->orientation, &rotMat);
|
||||
sclMat.m[0] = particle->width / _spriteSize.x;
|
||||
sclMat.m[5] = particle->height / _spriteSize.y;
|
||||
sclMat.m[10] = particle->depth / _spriteSize.z;
|
||||
sclMat.m[0] = particle->width / _meshSize.x;
|
||||
sclMat.m[5] = particle->height / _meshSize.y;
|
||||
sclMat.m[10] = particle->depth / _meshSize.z;
|
||||
mat = rotMat * sclMat;
|
||||
mat.m[12] = particle->position.x;
|
||||
mat.m[13] = particle->position.y;
|
||||
mat.m[14] = particle->position.z;
|
||||
_spriteList[index++]->draw(renderer, mat, 0);
|
||||
_meshList[index++]->draw(renderer, mat, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void Particle3DModelRender::reset()
|
||||
{
|
||||
for (auto iter : _spriteList)
|
||||
for (auto iter : _meshList)
|
||||
{
|
||||
iter->release();
|
||||
}
|
||||
_spriteList.clear();
|
||||
_meshList.clear();
|
||||
}
|
||||
|
||||
// MARK: Particle3DRender
|
||||
|
|
|
@ -41,7 +41,7 @@ NS_CC_BEGIN
|
|||
class ParticleSystem3D;
|
||||
class Renderer;
|
||||
class MeshCommand;
|
||||
class Sprite3D;
|
||||
class MeshRenderer;
|
||||
class GLProgramState;
|
||||
class IndexBuffer;
|
||||
class VertexBuffer;
|
||||
|
@ -141,7 +141,7 @@ protected:
|
|||
bool _rendererDepthWrite = false;
|
||||
};
|
||||
|
||||
// particle render for Sprite3D
|
||||
// particle renderer using MeshRenderer
|
||||
class CC_EX_DLL Particle3DModelRender : public Particle3DRender
|
||||
{
|
||||
public:
|
||||
|
@ -154,10 +154,10 @@ public:
|
|||
virtual ~Particle3DModelRender();
|
||||
|
||||
protected:
|
||||
std::vector<Sprite3D*> _spriteList;
|
||||
std::vector<MeshRenderer*> _meshList;
|
||||
std::string _modelFile;
|
||||
std::string _texFile;
|
||||
Vec3 _spriteSize;
|
||||
Vec3 _meshSize;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
#include "renderer/CCTextureCache.h"
|
||||
#include "renderer/backend/ProgramState.h"
|
||||
#include "base/CCDirector.h"
|
||||
#include "3d/CCSprite3D.h"
|
||||
#include "3d/CCMeshRenderer.h"
|
||||
#include "3d/CCMesh.h"
|
||||
#include "2d/CCCamera.h"
|
||||
#include <sstream>
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
#include "renderer/backend/Buffer.h"
|
||||
#include "renderer/backend/Device.h"
|
||||
#include "2d/CCCamera.h"
|
||||
#include "3d/CCSprite3D.h"
|
||||
#include "3d/CCMeshRenderer.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
#include "renderer/backend/Device.h"
|
||||
#include "renderer/backend/Buffer.h"
|
||||
#include "base/CCDirector.h"
|
||||
#include "3d/CCSprite3D.h"
|
||||
#include "3d/CCMeshRenderer.h"
|
||||
#include "3d/CCMesh.h"
|
||||
#include "2d/CCCamera.h"
|
||||
|
||||
|
@ -501,28 +501,28 @@ void PUParticle3DModelRender::render(Renderer* renderer, const Mat4& transform,
|
|||
if (!_isVisible)
|
||||
return;
|
||||
|
||||
if (_spriteList.empty())
|
||||
if (_meshList.empty())
|
||||
{
|
||||
for (unsigned int i = 0; i < particleSystem->getParticleQuota(); ++i)
|
||||
{
|
||||
Sprite3D* sprite = Sprite3D::create(_modelFile);
|
||||
if (sprite == nullptr)
|
||||
MeshRenderer* mesh = MeshRenderer::create(_modelFile);
|
||||
if (mesh == nullptr)
|
||||
{
|
||||
CCLOG("failed to load file %s", _modelFile.c_str());
|
||||
continue;
|
||||
}
|
||||
sprite->setTexture(_texFile);
|
||||
sprite->setBlendFunc(particleSystem->getBlendFunc());
|
||||
sprite->setCullFaceEnabled(false);
|
||||
sprite->retain();
|
||||
_spriteList.push_back(sprite);
|
||||
mesh->setTexture(_texFile);
|
||||
mesh->setBlendFunc(particleSystem->getBlendFunc());
|
||||
mesh->setCullFaceEnabled(false);
|
||||
mesh->retain();
|
||||
_meshList.push_back(mesh);
|
||||
}
|
||||
if (!_spriteList.empty())
|
||||
if (!_meshList.empty())
|
||||
{
|
||||
const AABB& aabb = _spriteList[0]->getAABB();
|
||||
const AABB& aabb = _meshList[0]->getAABB();
|
||||
Vec3 corners[8];
|
||||
aabb.getCorners(corners);
|
||||
_spriteSize = corners[3] - corners[6];
|
||||
_meshSize = corners[3] - corners[6];
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -543,19 +543,19 @@ void PUParticle3DModelRender::render(Renderer* renderer, const Mat4& transform,
|
|||
{
|
||||
auto particle = static_cast<PUParticle3D*>(iter);
|
||||
Mat4::createRotation(q * particle->orientation, &rotMat);
|
||||
sclMat.m[0] = particle->width / _spriteSize.x;
|
||||
sclMat.m[5] = particle->height / _spriteSize.y;
|
||||
sclMat.m[10] = particle->depth / _spriteSize.z;
|
||||
sclMat.m[0] = particle->width / _meshSize.x;
|
||||
sclMat.m[5] = particle->height / _meshSize.y;
|
||||
sclMat.m[10] = particle->depth / _meshSize.z;
|
||||
mat = rotMat * sclMat;
|
||||
mat.m[12] = particle->position.x;
|
||||
mat.m[13] = particle->position.y;
|
||||
mat.m[14] = particle->position.z;
|
||||
if (_spriteList[index]->getCameraMask() != particleSystem->getCameraMask())
|
||||
_spriteList[index]->setCameraMask(particleSystem->getCameraMask());
|
||||
_spriteList[index]->setColor(
|
||||
if (_meshList[index]->getCameraMask() != particleSystem->getCameraMask())
|
||||
_meshList[index]->setCameraMask(particleSystem->getCameraMask());
|
||||
_meshList[index]->setColor(
|
||||
Color3B(particle->color.x * 255, particle->color.y * 255, particle->color.z * 255));
|
||||
_spriteList[index]->setOpacity(particle->color.w * 255);
|
||||
_spriteList[index]->visit(renderer, mat, Node::FLAGS_DIRTY_MASK);
|
||||
_meshList[index]->setOpacity(particle->color.w * 255);
|
||||
_meshList[index]->visit(renderer, mat, Node::FLAGS_DIRTY_MASK);
|
||||
++index;
|
||||
}
|
||||
}
|
||||
|
@ -567,7 +567,7 @@ PUParticle3DModelRender::PUParticle3DModelRender()
|
|||
|
||||
PUParticle3DModelRender::~PUParticle3DModelRender()
|
||||
{
|
||||
for (auto iter : _spriteList)
|
||||
for (auto iter : _meshList)
|
||||
{
|
||||
iter->release();
|
||||
}
|
||||
|
@ -587,11 +587,11 @@ PUParticle3DModelRender* PUParticle3DModelRender::clone()
|
|||
|
||||
void PUParticle3DModelRender::reset()
|
||||
{
|
||||
for (auto iter : _spriteList)
|
||||
for (auto iter : _meshList)
|
||||
{
|
||||
iter->release();
|
||||
}
|
||||
_spriteList.clear();
|
||||
_meshList.clear();
|
||||
}
|
||||
|
||||
PUParticle3DEntityRender::PUParticle3DEntityRender()
|
||||
|
|
|
@ -55,7 +55,7 @@ public:
|
|||
|
||||
public:
|
||||
bool autoRotate; // Means that the objects to render automatically rotate if the node to which the particle system
|
||||
// is attached, rotates.
|
||||
// is attached to rotates.
|
||||
|
||||
protected:
|
||||
std::string _renderType;
|
||||
|
@ -203,10 +203,10 @@ public:
|
|||
virtual ~PUParticle3DModelRender();
|
||||
|
||||
protected:
|
||||
std::vector<Sprite3D*> _spriteList;
|
||||
std::vector<MeshRenderer*> _meshList;
|
||||
std::string _modelFile;
|
||||
std::string _texFile;
|
||||
Vec3 _spriteSize;
|
||||
Vec3 _meshSize;
|
||||
};
|
||||
|
||||
class CC_EX_DLL PUParticle3DBoxRender : public PUParticle3DEntityRender
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
#include "renderer/CCTextureCache.h"
|
||||
#include "renderer/backend/ProgramState.h"
|
||||
#include "2d/CCCamera.h"
|
||||
#include "3d/CCSprite3D.h"
|
||||
#include "3d/CCMeshRenderer.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
#include "renderer/CCRenderer.h"
|
||||
#include "renderer/CCTextureCache.h"
|
||||
#include "base/CCDirector.h"
|
||||
#include "3d/CCSprite3D.h"
|
||||
#include "3d/CCMeshRenderer.h"
|
||||
#include "3d/CCMesh.h"
|
||||
#include "2d/CCCamera.h"
|
||||
#include <sstream>
|
||||
|
|
|
@ -69,7 +69,7 @@
|
|||
#include "WidgetReader/ListViewReader/ListViewReader.h"
|
||||
#include "WidgetReader/ArmatureNodeReader/ArmatureNodeReader.h"
|
||||
#include "WidgetReader/Node3DReader/Node3DReader.h"
|
||||
#include "WidgetReader/Sprite3DReader/Sprite3DReader.h"
|
||||
#include "WidgetReader/MeshReader/MeshReader.h"
|
||||
#include "WidgetReader/UserCameraReader/UserCameraReader.h"
|
||||
#include "WidgetReader/Particle3DReader/Particle3DReader.h"
|
||||
#include "WidgetReader/GameNode3DReader/GameNode3DReader.h"
|
||||
|
@ -226,7 +226,7 @@ CSLoader::CSLoader()
|
|||
|
||||
CREATE_CLASS_NODE_READER_INFO(ArmatureNodeReader);
|
||||
CREATE_CLASS_NODE_READER_INFO(Node3DReader);
|
||||
CREATE_CLASS_NODE_READER_INFO(Sprite3DReader);
|
||||
CREATE_CLASS_NODE_READER_INFO(MeshReader);
|
||||
CREATE_CLASS_NODE_READER_INFO(UserCameraReader);
|
||||
CREATE_CLASS_NODE_READER_INFO(Particle3DReader);
|
||||
CREATE_CLASS_NODE_READER_INFO(GameNode3DReader);
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
#include "WidgetReader/ListViewReader/ListViewReader.h"
|
||||
#include "WidgetReader/ArmatureNodeReader/ArmatureNodeReader.h"
|
||||
#include "WidgetReader/Node3DReader/Node3DReader.h"
|
||||
#include "WidgetReader/Sprite3DReader/Sprite3DReader.h"
|
||||
#include "WidgetReader/MeshReader/MeshReader.h"
|
||||
#include "WidgetReader/UserCameraReader/UserCameraReader.h"
|
||||
#include "WidgetReader/Particle3DReader/Particle3DReader.h"
|
||||
|
||||
|
@ -57,7 +57,7 @@ void destroyCocosStudio()
|
|||
|
||||
ArmatureNodeReader::destroyInstance();
|
||||
Node3DReader::destroyInstance();
|
||||
Sprite3DReader::destroyInstance();
|
||||
MeshReader::destroyInstance();
|
||||
UserCameraReader::destroyInstance();
|
||||
Particle3DReader::destroyInstance();
|
||||
|
||||
|
|
|
@ -24,11 +24,11 @@
|
|||
****************************************************************************/
|
||||
|
||||
#include "2d/CCLight.h"
|
||||
#include "3d/CCSprite3D.h"
|
||||
#include "3d/CCMeshRenderer.h"
|
||||
#include "3d/CCAnimate3D.h"
|
||||
#include "3d/CCAnimation3D.h"
|
||||
#include "platform/CCFileUtils.h"
|
||||
#include "WidgetReader/Sprite3DReader/Sprite3DReader.h"
|
||||
#include "WidgetReader/MeshReader/MeshReader.h"
|
||||
|
||||
#include "CSParseBinary_generated.h"
|
||||
#include "CSParse3DBinary_generated.h"
|
||||
|
@ -43,35 +43,35 @@ using namespace flatbuffers;
|
|||
|
||||
namespace cocostudio
|
||||
{
|
||||
IMPLEMENT_CLASS_NODE_READER_INFO(Sprite3DReader)
|
||||
IMPLEMENT_CLASS_NODE_READER_INFO(MeshReader)
|
||||
|
||||
Sprite3DReader::Sprite3DReader() {}
|
||||
MeshReader::MeshReader() {}
|
||||
|
||||
Sprite3DReader::~Sprite3DReader() {}
|
||||
MeshReader::~MeshReader() {}
|
||||
|
||||
static Sprite3DReader* _instanceSprite3DReader = nullptr;
|
||||
static MeshReader* _instanceMeshReader = nullptr;
|
||||
|
||||
Sprite3DReader* Sprite3DReader::getInstance()
|
||||
MeshReader* MeshReader::getInstance()
|
||||
{
|
||||
if (!_instanceSprite3DReader)
|
||||
if (!_instanceMeshReader)
|
||||
{
|
||||
_instanceSprite3DReader = new Sprite3DReader();
|
||||
_instanceMeshReader = new MeshReader();
|
||||
}
|
||||
|
||||
return _instanceSprite3DReader;
|
||||
return _instanceMeshReader;
|
||||
}
|
||||
|
||||
void Sprite3DReader::purge()
|
||||
void MeshReader::purge()
|
||||
{
|
||||
CC_SAFE_DELETE(_instanceSprite3DReader);
|
||||
CC_SAFE_DELETE(_instanceMeshReader);
|
||||
}
|
||||
|
||||
void Sprite3DReader::destroyInstance()
|
||||
void MeshReader::destroyInstance()
|
||||
{
|
||||
CC_SAFE_DELETE(_instanceSprite3DReader);
|
||||
CC_SAFE_DELETE(_instanceMeshReader);
|
||||
}
|
||||
|
||||
Vec2 Sprite3DReader::getVec2Attribute(pugi::xml_attribute attribute) const
|
||||
Vec2 MeshReader::getVec2Attribute(pugi::xml_attribute attribute) const
|
||||
{
|
||||
if (!attribute)
|
||||
return Vec2::ZERO;
|
||||
|
@ -99,7 +99,7 @@ Vec2 Sprite3DReader::getVec2Attribute(pugi::xml_attribute attribute) const
|
|||
return ret;
|
||||
}
|
||||
|
||||
Offset<Table> Sprite3DReader::createOptionsWithFlatBuffers(pugi::xml_node objectData,
|
||||
Offset<Table> MeshReader::createOptionsWithFlatBuffers(pugi::xml_node objectData,
|
||||
flatbuffers::FlatBufferBuilder* builder)
|
||||
{
|
||||
auto temp = Node3DReader::getInstance()->createOptionsWithFlatBuffers(objectData, builder);
|
||||
|
@ -205,9 +205,9 @@ Offset<Table> Sprite3DReader::createOptionsWithFlatBuffers(pugi::xml_node object
|
|||
return *(Offset<Table>*)(&options);
|
||||
}
|
||||
|
||||
void Sprite3DReader::setPropsWithFlatBuffers(cocos2d::Node* node, const flatbuffers::Table* sprite3DOptions)
|
||||
void MeshReader::setPropsWithFlatBuffers(cocos2d::Node* node, const flatbuffers::Table* sprite3DOptions)
|
||||
{
|
||||
Sprite3D* sprite3D = static_cast<Sprite3D*>(node);
|
||||
MeshRenderer* mesh = static_cast<MeshRenderer*>(node);
|
||||
|
||||
auto options = (Sprite3DOptions*)sprite3DOptions;
|
||||
|
||||
|
@ -224,7 +224,7 @@ void Sprite3DReader::setPropsWithFlatBuffers(cocos2d::Node* node, const flatbuff
|
|||
{
|
||||
Animate3D* animate = Animate3D::create(animation);
|
||||
Action* action = RepeatForever::create(animate);
|
||||
sprite3D->runAction(action);
|
||||
mesh->runAction(action);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -237,36 +237,36 @@ void Sprite3DReader::setPropsWithFlatBuffers(cocos2d::Node* node, const flatbuff
|
|||
|
||||
if (alpha != 255)
|
||||
{
|
||||
sprite3D->setOpacity(alpha);
|
||||
mesh->setOpacity(alpha);
|
||||
}
|
||||
if (red != 255 || green != 255 || blue != 255)
|
||||
{
|
||||
sprite3D->setColor(Color3B(red, green, blue));
|
||||
mesh->setColor(Color3B(red, green, blue));
|
||||
}
|
||||
if (isFlipped)
|
||||
{
|
||||
sprite3D->setCullFaceEnabled(true);
|
||||
sprite3D->setCullFace(CullFaceSide::FRONT);
|
||||
mesh->setCullFaceEnabled(true);
|
||||
mesh->setCullFace(CullFaceSide::FRONT);
|
||||
}
|
||||
|
||||
if (lightFlag <= 0)
|
||||
{
|
||||
lightFlag = 1;
|
||||
}
|
||||
sprite3D->setLightMask(lightFlag);
|
||||
mesh->setLightMask(lightFlag);
|
||||
|
||||
auto node3DReader = Node3DReader::getInstance();
|
||||
node3DReader->setPropsWithFlatBuffers(sprite3D, (Table*)(options->node3DOption()));
|
||||
node3DReader->setPropsWithFlatBuffers(mesh, (Table*)(options->node3DOption()));
|
||||
}
|
||||
|
||||
Node* Sprite3DReader::createNodeWithFlatBuffers(const flatbuffers::Table* sprite3DOptions)
|
||||
Node* MeshReader::createNodeWithFlatBuffers(const flatbuffers::Table* sprite3DOptions)
|
||||
{
|
||||
auto options = (Sprite3DOptions*)sprite3DOptions;
|
||||
|
||||
auto fileData = options->fileData();
|
||||
std::string path = fileData->path()->c_str();
|
||||
|
||||
Sprite3D* ret = Sprite3D::create();
|
||||
MeshRenderer* ret = MeshRenderer::create();
|
||||
if (FileUtils::getInstance()->isFileExist(path))
|
||||
{
|
||||
ret->initWithFile(path);
|
|
@ -32,15 +32,15 @@
|
|||
|
||||
namespace cocostudio
|
||||
{
|
||||
class CCS_DLL Sprite3DReader : public cocos2d::Ref, public NodeReaderProtocol
|
||||
class CCS_DLL MeshReader : public cocos2d::Ref, public NodeReaderProtocol
|
||||
{
|
||||
DECLARE_CLASS_NODE_READER_INFO
|
||||
|
||||
public:
|
||||
Sprite3DReader();
|
||||
~Sprite3DReader();
|
||||
MeshReader();
|
||||
~MeshReader();
|
||||
|
||||
static Sprite3DReader* getInstance();
|
||||
static MeshReader* getInstance();
|
||||
/** @deprecated Use method destroyInstance() instead */
|
||||
CC_DEPRECATED_ATTRIBUTE static void purge();
|
||||
static void destroyInstance();
|
File diff suppressed because it is too large
Load Diff
|
@ -3972,10 +3972,10 @@ int lua_register_cocos2dx_physics3d_Physics3DComponent(lua_State* tolua_S)
|
|||
return 1;
|
||||
}
|
||||
|
||||
int lua_cocos2dx_physics3d_PhysicsSprite3D_syncNodeToPhysics(lua_State* tolua_S)
|
||||
int lua_cocos2dx_physics3d_PhysicsMeshRenderer_syncNodeToPhysics(lua_State* tolua_S)
|
||||
{
|
||||
int argc = 0;
|
||||
cocos2d::PhysicsSprite3D* cobj = nullptr;
|
||||
cocos2d::PhysicsMeshRenderer* cobj = nullptr;
|
||||
bool ok = true;
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
|
@ -3984,15 +3984,15 @@ int lua_cocos2dx_physics3d_PhysicsSprite3D_syncNodeToPhysics(lua_State* tolua_S)
|
|||
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
if (!tolua_isusertype(tolua_S,1,"cc.PhysicsSprite3D",0,&tolua_err)) goto tolua_lerror;
|
||||
if (!tolua_isusertype(tolua_S,1,"cc.PhysicsMeshRenderer",0,&tolua_err)) goto tolua_lerror;
|
||||
#endif
|
||||
|
||||
cobj = (cocos2d::PhysicsSprite3D*)tolua_tousertype(tolua_S,1,0);
|
||||
cobj = (cocos2d::PhysicsMeshRenderer*)tolua_tousertype(tolua_S,1,0);
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
if (!cobj)
|
||||
{
|
||||
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_physics3d_PhysicsSprite3D_syncNodeToPhysics'", nullptr);
|
||||
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_physics3d_PhysicsMeshRenderer_syncNodeToPhysics'", nullptr);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
@ -4002,27 +4002,27 @@ int lua_cocos2dx_physics3d_PhysicsSprite3D_syncNodeToPhysics(lua_State* tolua_S)
|
|||
{
|
||||
if(!ok)
|
||||
{
|
||||
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_physics3d_PhysicsSprite3D_syncNodeToPhysics'", nullptr);
|
||||
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_physics3d_PhysicsMeshRenderer_syncNodeToPhysics'", nullptr);
|
||||
return 0;
|
||||
}
|
||||
cobj->syncNodeToPhysics();
|
||||
lua_settop(tolua_S, 1);
|
||||
return 1;
|
||||
}
|
||||
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.PhysicsSprite3D:syncNodeToPhysics",argc, 0);
|
||||
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.PhysicsMeshRenderer:syncNodeToPhysics",argc, 0);
|
||||
return 0;
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
tolua_lerror:
|
||||
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_physics3d_PhysicsSprite3D_syncNodeToPhysics'.",&tolua_err);
|
||||
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_physics3d_PhysicsMeshRenderer_syncNodeToPhysics'.",&tolua_err);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
int lua_cocos2dx_physics3d_PhysicsSprite3D_syncPhysicsToNode(lua_State* tolua_S)
|
||||
int lua_cocos2dx_physics3d_PhysicsMeshRenderer_syncPhysicsToNode(lua_State* tolua_S)
|
||||
{
|
||||
int argc = 0;
|
||||
cocos2d::PhysicsSprite3D* cobj = nullptr;
|
||||
cocos2d::PhysicsMeshRenderer* cobj = nullptr;
|
||||
bool ok = true;
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
|
@ -4031,15 +4031,15 @@ int lua_cocos2dx_physics3d_PhysicsSprite3D_syncPhysicsToNode(lua_State* tolua_S)
|
|||
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
if (!tolua_isusertype(tolua_S,1,"cc.PhysicsSprite3D",0,&tolua_err)) goto tolua_lerror;
|
||||
if (!tolua_isusertype(tolua_S,1,"cc.PhysicsMeshRenderer",0,&tolua_err)) goto tolua_lerror;
|
||||
#endif
|
||||
|
||||
cobj = (cocos2d::PhysicsSprite3D*)tolua_tousertype(tolua_S,1,0);
|
||||
cobj = (cocos2d::PhysicsMeshRenderer*)tolua_tousertype(tolua_S,1,0);
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
if (!cobj)
|
||||
{
|
||||
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_physics3d_PhysicsSprite3D_syncPhysicsToNode'", nullptr);
|
||||
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_physics3d_PhysicsMeshRenderer_syncPhysicsToNode'", nullptr);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
@ -4049,27 +4049,27 @@ int lua_cocos2dx_physics3d_PhysicsSprite3D_syncPhysicsToNode(lua_State* tolua_S)
|
|||
{
|
||||
if(!ok)
|
||||
{
|
||||
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_physics3d_PhysicsSprite3D_syncPhysicsToNode'", nullptr);
|
||||
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_physics3d_PhysicsMeshRenderer_syncPhysicsToNode'", nullptr);
|
||||
return 0;
|
||||
}
|
||||
cobj->syncPhysicsToNode();
|
||||
lua_settop(tolua_S, 1);
|
||||
return 1;
|
||||
}
|
||||
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.PhysicsSprite3D:syncPhysicsToNode",argc, 0);
|
||||
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.PhysicsMeshRenderer:syncPhysicsToNode",argc, 0);
|
||||
return 0;
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
tolua_lerror:
|
||||
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_physics3d_PhysicsSprite3D_syncPhysicsToNode'.",&tolua_err);
|
||||
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_physics3d_PhysicsMeshRenderer_syncPhysicsToNode'.",&tolua_err);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
int lua_cocos2dx_physics3d_PhysicsSprite3D_getPhysicsObj(lua_State* tolua_S)
|
||||
int lua_cocos2dx_physics3d_PhysicsMeshRenderer_getPhysicsObj(lua_State* tolua_S)
|
||||
{
|
||||
int argc = 0;
|
||||
cocos2d::PhysicsSprite3D* cobj = nullptr;
|
||||
cocos2d::PhysicsMeshRenderer* cobj = nullptr;
|
||||
bool ok = true;
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
|
@ -4078,15 +4078,15 @@ int lua_cocos2dx_physics3d_PhysicsSprite3D_getPhysicsObj(lua_State* tolua_S)
|
|||
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
if (!tolua_isusertype(tolua_S,1,"cc.PhysicsSprite3D",0,&tolua_err)) goto tolua_lerror;
|
||||
if (!tolua_isusertype(tolua_S,1,"cc.PhysicsMeshRenderer",0,&tolua_err)) goto tolua_lerror;
|
||||
#endif
|
||||
|
||||
cobj = (cocos2d::PhysicsSprite3D*)tolua_tousertype(tolua_S,1,0);
|
||||
cobj = (cocos2d::PhysicsMeshRenderer*)tolua_tousertype(tolua_S,1,0);
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
if (!cobj)
|
||||
{
|
||||
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_physics3d_PhysicsSprite3D_getPhysicsObj'", nullptr);
|
||||
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_physics3d_PhysicsMeshRenderer_getPhysicsObj'", nullptr);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
@ -4096,27 +4096,27 @@ int lua_cocos2dx_physics3d_PhysicsSprite3D_getPhysicsObj(lua_State* tolua_S)
|
|||
{
|
||||
if(!ok)
|
||||
{
|
||||
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_physics3d_PhysicsSprite3D_getPhysicsObj'", nullptr);
|
||||
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_physics3d_PhysicsMeshRenderer_getPhysicsObj'", nullptr);
|
||||
return 0;
|
||||
}
|
||||
cocos2d::Physics3DObject* ret = cobj->getPhysicsObj();
|
||||
object_to_luaval<cocos2d::Physics3DObject>(tolua_S, "cc.Physics3DObject",(cocos2d::Physics3DObject*)ret);
|
||||
return 1;
|
||||
}
|
||||
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.PhysicsSprite3D:getPhysicsObj",argc, 0);
|
||||
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.PhysicsMeshRenderer:getPhysicsObj",argc, 0);
|
||||
return 0;
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
tolua_lerror:
|
||||
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_physics3d_PhysicsSprite3D_getPhysicsObj'.",&tolua_err);
|
||||
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_physics3d_PhysicsMeshRenderer_getPhysicsObj'.",&tolua_err);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
int lua_cocos2dx_physics3d_PhysicsSprite3D_setSyncFlag(lua_State* tolua_S)
|
||||
int lua_cocos2dx_physics3d_PhysicsMeshRenderer_setSyncFlag(lua_State* tolua_S)
|
||||
{
|
||||
int argc = 0;
|
||||
cocos2d::PhysicsSprite3D* cobj = nullptr;
|
||||
cocos2d::PhysicsMeshRenderer* cobj = nullptr;
|
||||
bool ok = true;
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
|
@ -4125,15 +4125,15 @@ int lua_cocos2dx_physics3d_PhysicsSprite3D_setSyncFlag(lua_State* tolua_S)
|
|||
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
if (!tolua_isusertype(tolua_S,1,"cc.PhysicsSprite3D",0,&tolua_err)) goto tolua_lerror;
|
||||
if (!tolua_isusertype(tolua_S,1,"cc.PhysicsMeshRenderer",0,&tolua_err)) goto tolua_lerror;
|
||||
#endif
|
||||
|
||||
cobj = (cocos2d::PhysicsSprite3D*)tolua_tousertype(tolua_S,1,0);
|
||||
cobj = (cocos2d::PhysicsMeshRenderer*)tolua_tousertype(tolua_S,1,0);
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
if (!cobj)
|
||||
{
|
||||
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_physics3d_PhysicsSprite3D_setSyncFlag'", nullptr);
|
||||
tolua_error(tolua_S,"invalid 'cobj' in function 'lua_cocos2dx_physics3d_PhysicsMeshRenderer_setSyncFlag'", nullptr);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
@ -4143,30 +4143,30 @@ int lua_cocos2dx_physics3d_PhysicsSprite3D_setSyncFlag(lua_State* tolua_S)
|
|||
{
|
||||
cocos2d::Physics3DComponent::PhysicsSyncFlag arg0;
|
||||
|
||||
ok &= luaval_to_int32(tolua_S, 2,(int *)&arg0, "cc.PhysicsSprite3D:setSyncFlag");
|
||||
ok &= luaval_to_int32(tolua_S, 2,(int *)&arg0, "cc.PhysicsMeshRenderer:setSyncFlag");
|
||||
if(!ok)
|
||||
{
|
||||
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_physics3d_PhysicsSprite3D_setSyncFlag'", nullptr);
|
||||
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_physics3d_PhysicsMeshRenderer_setSyncFlag'", nullptr);
|
||||
return 0;
|
||||
}
|
||||
cobj->setSyncFlag(arg0);
|
||||
lua_settop(tolua_S, 1);
|
||||
return 1;
|
||||
}
|
||||
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.PhysicsSprite3D:setSyncFlag",argc, 1);
|
||||
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.PhysicsMeshRenderer:setSyncFlag",argc, 1);
|
||||
return 0;
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
tolua_lerror:
|
||||
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_physics3d_PhysicsSprite3D_setSyncFlag'.",&tolua_err);
|
||||
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_physics3d_PhysicsMeshRenderer_setSyncFlag'.",&tolua_err);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
int lua_cocos2dx_physics3d_PhysicsSprite3D_constructor(lua_State* tolua_S)
|
||||
int lua_cocos2dx_physics3d_PhysicsMeshRenderer_constructor(lua_State* tolua_S)
|
||||
{
|
||||
int argc = 0;
|
||||
cocos2d::PhysicsSprite3D* cobj = nullptr;
|
||||
cocos2d::PhysicsMeshRenderer* cobj = nullptr;
|
||||
bool ok = true;
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
|
@ -4180,47 +4180,47 @@ int lua_cocos2dx_physics3d_PhysicsSprite3D_constructor(lua_State* tolua_S)
|
|||
{
|
||||
if(!ok)
|
||||
{
|
||||
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_physics3d_PhysicsSprite3D_constructor'", nullptr);
|
||||
tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_physics3d_PhysicsMeshRenderer_constructor'", nullptr);
|
||||
return 0;
|
||||
}
|
||||
cobj = new cocos2d::PhysicsSprite3D();
|
||||
cobj = new cocos2d::PhysicsMeshRenderer();
|
||||
cobj->autorelease();
|
||||
int ID = (int)cobj->_ID ;
|
||||
int* luaID = &cobj->_luaID ;
|
||||
toluafix_pushusertype_ccobject(tolua_S, ID, luaID, (void*)cobj,"cc.PhysicsSprite3D");
|
||||
toluafix_pushusertype_ccobject(tolua_S, ID, luaID, (void*)cobj,"cc.PhysicsMeshRenderer");
|
||||
return 1;
|
||||
}
|
||||
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.PhysicsSprite3D:PhysicsSprite3D",argc, 0);
|
||||
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.PhysicsMeshRenderer:PhysicsMeshRenderer",argc, 0);
|
||||
return 0;
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_physics3d_PhysicsSprite3D_constructor'.",&tolua_err);
|
||||
tolua_error(tolua_S,"#ferror in function 'lua_cocos2dx_physics3d_PhysicsMeshRenderer_constructor'.",&tolua_err);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int lua_cocos2dx_physics3d_PhysicsSprite3D_finalize(lua_State* tolua_S)
|
||||
static int lua_cocos2dx_physics3d_PhysicsMeshRenderer_finalize(lua_State* tolua_S)
|
||||
{
|
||||
printf("luabindings: finalizing LUA object (PhysicsSprite3D)");
|
||||
printf("luabindings: finalizing LUA object (PhysicsMeshRenderer)");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int lua_register_cocos2dx_physics3d_PhysicsSprite3D(lua_State* tolua_S)
|
||||
int lua_register_cocos2dx_physics3d_PhysicsMeshRenderer(lua_State* tolua_S)
|
||||
{
|
||||
tolua_usertype(tolua_S,"cc.PhysicsSprite3D");
|
||||
tolua_cclass(tolua_S,"PhysicsSprite3D","cc.PhysicsSprite3D","cc.Sprite3D",nullptr);
|
||||
tolua_usertype(tolua_S,"cc.PhysicsMeshRenderer");
|
||||
tolua_cclass(tolua_S,"PhysicsMeshRenderer","cc.PhysicsMeshRenderer","cc.Sprite3D",nullptr);
|
||||
|
||||
tolua_beginmodule(tolua_S,"PhysicsSprite3D");
|
||||
tolua_function(tolua_S,"new",lua_cocos2dx_physics3d_PhysicsSprite3D_constructor);
|
||||
tolua_function(tolua_S,"syncNodeToPhysics",lua_cocos2dx_physics3d_PhysicsSprite3D_syncNodeToPhysics);
|
||||
tolua_function(tolua_S,"syncPhysicsToNode",lua_cocos2dx_physics3d_PhysicsSprite3D_syncPhysicsToNode);
|
||||
tolua_function(tolua_S,"getPhysicsObj",lua_cocos2dx_physics3d_PhysicsSprite3D_getPhysicsObj);
|
||||
tolua_function(tolua_S,"setSyncFlag",lua_cocos2dx_physics3d_PhysicsSprite3D_setSyncFlag);
|
||||
tolua_beginmodule(tolua_S,"PhysicsMeshRenderer");
|
||||
tolua_function(tolua_S,"new",lua_cocos2dx_physics3d_PhysicsMeshRenderer_constructor);
|
||||
tolua_function(tolua_S,"syncNodeToPhysics",lua_cocos2dx_physics3d_PhysicsMeshRenderer_syncNodeToPhysics);
|
||||
tolua_function(tolua_S,"syncPhysicsToNode",lua_cocos2dx_physics3d_PhysicsMeshRenderer_syncPhysicsToNode);
|
||||
tolua_function(tolua_S,"getPhysicsObj",lua_cocos2dx_physics3d_PhysicsMeshRenderer_getPhysicsObj);
|
||||
tolua_function(tolua_S,"setSyncFlag",lua_cocos2dx_physics3d_PhysicsMeshRenderer_setSyncFlag);
|
||||
tolua_endmodule(tolua_S);
|
||||
auto typeName = typeid(cocos2d::PhysicsSprite3D).name(); // rtti is literal storage
|
||||
g_luaType[reinterpret_cast<uintptr_t>(typeName)] = "cc.PhysicsSprite3D";
|
||||
g_typeCast[typeName] = "cc.PhysicsSprite3D";
|
||||
auto typeName = typeid(cocos2d::PhysicsMeshRenderer).name(); // rtti is literal storage
|
||||
g_luaType[reinterpret_cast<uintptr_t>(typeName)] = "cc.PhysicsMeshRenderer";
|
||||
g_typeCast[typeName] = "cc.PhysicsMeshRenderer";
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -12373,7 +12373,7 @@ TOLUA_API int register_all_cocos2dx_physics3d(lua_State* tolua_S)
|
|||
lua_register_cocos2dx_physics3d_Physics3DComponent(tolua_S);
|
||||
lua_register_cocos2dx_physics3d_Physics3DConeTwistConstraint(tolua_S);
|
||||
lua_register_cocos2dx_physics3d_Physics3DPointToPointConstraint(tolua_S);
|
||||
lua_register_cocos2dx_physics3d_PhysicsSprite3D(tolua_S);
|
||||
lua_register_cocos2dx_physics3d_PhysicsMeshRenderer(tolua_S);
|
||||
lua_register_cocos2dx_physics3d_Physics3DHingeConstraint(tolua_S);
|
||||
lua_register_cocos2dx_physics3d_Physics3DShape(tolua_S);
|
||||
|
||||
|
|
|
@ -27,29 +27,29 @@
|
|||
#include "scripting/lua-bindings/manual/LuaBasicConversions.h"
|
||||
#include "scripting/lua-bindings/manual/CCLuaEngine.h"
|
||||
#include "3d/CCBundle3D.h"
|
||||
#include "3d/CCSprite3D.h"
|
||||
#include "3d/CCMeshRenderer.h"
|
||||
#include "3d/CCTerrain.h"
|
||||
|
||||
int lua_cocos2dx_3d_Sprite3D_getAABB(lua_State* L)
|
||||
int lua_cocos2dx_3d_MeshRenderer_getAABB(lua_State* L)
|
||||
{
|
||||
int argc = 0;
|
||||
cocos2d::Sprite3D* cobj = nullptr;
|
||||
cocos2d::MeshRenderer* cobj = nullptr;
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
tolua_Error tolua_err;
|
||||
#endif
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
if (!tolua_isusertype(L, 1, "cc.Sprite3D", 0, &tolua_err))
|
||||
if (!tolua_isusertype(L, 1, "cc.MeshRenderer", 0, &tolua_err))
|
||||
goto tolua_lerror;
|
||||
#endif
|
||||
|
||||
cobj = (cocos2d::Sprite3D*)tolua_tousertype(L, 1, 0);
|
||||
cobj = (cocos2d::MeshRenderer*)tolua_tousertype(L, 1, 0);
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
if (!cobj)
|
||||
{
|
||||
tolua_error(L, "invalid 'cobj' in function 'lua_cocos2dx_3d_Sprite3D_getAABB'", nullptr);
|
||||
tolua_error(L, "invalid 'cobj' in function 'lua_cocos2dx_3d_MeshRenderer_getAABB'", nullptr);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
@ -61,17 +61,17 @@ int lua_cocos2dx_3d_Sprite3D_getAABB(lua_State* L)
|
|||
object_to_luaval<cocos2d::AABB>(L, "cc.AABB", (cocos2d::AABB*)ret);
|
||||
return 1;
|
||||
}
|
||||
luaL_error(L, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.Sprite3D:getAABB", argc, 0);
|
||||
luaL_error(L, "%s has wrong number of arguments: %d, was expecting %d \n", "cc.MeshRenderer:getAABB", argc, 0);
|
||||
return 0;
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
tolua_lerror:
|
||||
tolua_error(L, "#ferror in function 'lua_cocos2dx_3d_Sprite3D_getAABB'.", &tolua_err);
|
||||
tolua_error(L, "#ferror in function 'lua_cocos2dx_3d_MeshRenderer_getAABB'.", &tolua_err);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
int lua_cocos2dx_3d_Sprite3D_createAsync(lua_State* L)
|
||||
int lua_cocos2dx_3d_MeshRenderer_createAsync(lua_State* L)
|
||||
{
|
||||
int argc = 0;
|
||||
bool ok = true;
|
||||
|
@ -80,7 +80,7 @@ int lua_cocos2dx_3d_Sprite3D_createAsync(lua_State* L)
|
|||
#endif
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
if (!tolua_isusertable(L, 1, "cc.Sprite3D", 0, &tolua_err))
|
||||
if (!tolua_isusertable(L, 1, "cc.MeshRenderer", 0, &tolua_err))
|
||||
goto tolua_lerror;
|
||||
#endif
|
||||
|
||||
|
@ -91,11 +91,11 @@ int lua_cocos2dx_3d_Sprite3D_createAsync(lua_State* L)
|
|||
if (argc == 3)
|
||||
{
|
||||
std::string modelPath;
|
||||
ok &= luaval_to_std_string(L, 2, &modelPath, "cc.Sprite3D:createAsync");
|
||||
ok &= luaval_to_std_string(L, 2, &modelPath, "cc.MeshRenderer:createAsync");
|
||||
if (!ok)
|
||||
break;
|
||||
std::string texturePath;
|
||||
ok &= luaval_to_std_string(L, 3, &texturePath, "cc.Sprite3D:createAsync");
|
||||
ok &= luaval_to_std_string(L, 3, &texturePath, "cc.MeshRenderer:createAsync");
|
||||
if (!ok)
|
||||
break;
|
||||
|
||||
|
@ -107,13 +107,13 @@ int lua_cocos2dx_3d_Sprite3D_createAsync(lua_State* L)
|
|||
#endif
|
||||
LUA_FUNCTION handler = toluafix_ref_function(L, 4, 0);
|
||||
|
||||
cocos2d::Sprite3D::createAsync(
|
||||
cocos2d::MeshRenderer::createAsync(
|
||||
modelPath, texturePath,
|
||||
[=](cocos2d::Sprite3D* sprite, void* callbackparam) {
|
||||
[=](cocos2d::MeshRenderer* mesh, void* callbackparam) {
|
||||
auto stack = LuaEngine::getInstance()->getLuaStack();
|
||||
int id = (sprite) ? (int)sprite->_ID : -1;
|
||||
int* luaID = (sprite) ? &sprite->_luaID : nullptr;
|
||||
toluafix_pushusertype_ccobject(stack->getLuaState(), id, luaID, (void*)sprite, "cc.Sprite3D");
|
||||
int id = (mesh) ? (int)mesh->_ID : -1;
|
||||
int* luaID = (mesh) ? &mesh->_luaID : nullptr;
|
||||
toluafix_pushusertype_ccobject(stack->getLuaState(), id, luaID, (void*)mesh, "cc.MeshRenderer");
|
||||
stack->executeFunctionByHandler(handler, 1);
|
||||
},
|
||||
nullptr);
|
||||
|
@ -128,7 +128,7 @@ int lua_cocos2dx_3d_Sprite3D_createAsync(lua_State* L)
|
|||
if (argc == 2)
|
||||
{
|
||||
std::string modelPath;
|
||||
ok &= luaval_to_std_string(L, 2, &modelPath, "cc.Sprite3D:createAsync");
|
||||
ok &= luaval_to_std_string(L, 2, &modelPath, "cc.MeshRenderer:createAsync");
|
||||
if (!ok)
|
||||
break;
|
||||
|
||||
|
@ -140,13 +140,13 @@ int lua_cocos2dx_3d_Sprite3D_createAsync(lua_State* L)
|
|||
#endif
|
||||
LUA_FUNCTION handler = toluafix_ref_function(L, 3, 0);
|
||||
|
||||
cocos2d::Sprite3D::createAsync(
|
||||
cocos2d::MeshRenderer::createAsync(
|
||||
modelPath,
|
||||
[=](cocos2d::Sprite3D* sprite, void* callbackparam) {
|
||||
[=](cocos2d::MeshRenderer* mesh, void* callbackparam) {
|
||||
auto stack = LuaEngine::getInstance()->getLuaStack();
|
||||
int id = (sprite) ? (int)sprite->_ID : -1;
|
||||
int* luaID = (sprite) ? &sprite->_luaID : nullptr;
|
||||
toluafix_pushusertype_ccobject(stack->getLuaState(), id, luaID, (void*)sprite, "cc.Sprite3D");
|
||||
int id = (mesh) ? (int)mesh->_ID : -1;
|
||||
int* luaID = (mesh) ? &mesh->_luaID : nullptr;
|
||||
toluafix_pushusertype_ccobject(stack->getLuaState(), id, luaID, (void*)mesh, "cc.MeshRenderer");
|
||||
stack->executeFunctionByHandler(handler, 1);
|
||||
},
|
||||
nullptr);
|
||||
|
@ -156,23 +156,23 @@ int lua_cocos2dx_3d_Sprite3D_createAsync(lua_State* L)
|
|||
}
|
||||
} while (0);
|
||||
ok = true;
|
||||
luaL_error(L, "%s has wrong number of arguments: %d, was expecting %d", "cc.Sprite3D:createAsync", argc, 3);
|
||||
luaL_error(L, "%s has wrong number of arguments: %d, was expecting %d", "cc.MeshRenderer:createAsync", argc, 3);
|
||||
return 0;
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
tolua_lerror:
|
||||
tolua_error(L, "#ferror in function 'lua_cocos2dx_3d_Sprite3D_createAsync'.", &tolua_err);
|
||||
tolua_error(L, "#ferror in function 'lua_cocos2dx_3d_MeshRenderer_createAsync'.", &tolua_err);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void extendSprite3D(lua_State* L)
|
||||
static void extendMeshRenderer(lua_State* L)
|
||||
{
|
||||
lua_pushstring(L, "cc.Sprite3D");
|
||||
lua_pushstring(L, "cc.MeshRenderer");
|
||||
lua_rawget(L, LUA_REGISTRYINDEX);
|
||||
if (lua_istable(L, -1))
|
||||
{
|
||||
tolua_function(L, "getAABB", lua_cocos2dx_3d_Sprite3D_getAABB);
|
||||
tolua_function(L, "createAsync", lua_cocos2dx_3d_Sprite3D_createAsync);
|
||||
tolua_function(L, "getAABB", lua_cocos2dx_3d_MeshRenderer_getAABB);
|
||||
tolua_function(L, "createAsync", lua_cocos2dx_3d_MeshRenderer_createAsync);
|
||||
}
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
|
@ -656,7 +656,7 @@ static int register_all_cocos2dx_3d_manual(lua_State* L)
|
|||
if (nullptr == L)
|
||||
return 0;
|
||||
|
||||
extendSprite3D(L);
|
||||
extendMeshRenderer(L);
|
||||
extendTerrain(L);
|
||||
extendBundle3D(L);
|
||||
return 0;
|
||||
|
|
|
@ -186,7 +186,7 @@ void Physics3DWorld_HitResult_to_luaval(lua_State* L, const cocos2d::Physics3DWo
|
|||
lua_rawset(L, -3);
|
||||
}
|
||||
|
||||
int lua_cocos2dx_physics3d_PhysicsSprite3D_create(lua_State* L)
|
||||
int lua_cocos2dx_physics3d_PhysicsMeshRenderer_create(lua_State* L)
|
||||
{
|
||||
int argc = 0;
|
||||
bool ok = true;
|
||||
|
@ -196,7 +196,7 @@ int lua_cocos2dx_physics3d_PhysicsSprite3D_create(lua_State* L)
|
|||
# endif
|
||||
|
||||
# if COCOS2D_DEBUG >= 1
|
||||
if (!tolua_isusertable(L, 1, "cc.PhysicsSprite3D", 0, &tolua_err))
|
||||
if (!tolua_isusertable(L, 1, "cc.PhysicsMeshRenderer", 0, &tolua_err))
|
||||
goto tolua_lerror;
|
||||
# endif
|
||||
|
||||
|
@ -206,15 +206,15 @@ int lua_cocos2dx_physics3d_PhysicsSprite3D_create(lua_State* L)
|
|||
{
|
||||
std::string arg0;
|
||||
cocos2d::Physics3DRigidBodyDes arg1;
|
||||
ok &= luaval_to_std_string(L, 2, &arg0, "cc.PhysicsSprite3D:create");
|
||||
ok &= luaval_to_Physics3DRigidBodyDes(L, 3, &arg1, "cc.PhysicsSprite3D:create");
|
||||
ok &= luaval_to_std_string(L, 2, &arg0, "cc.PhysicsMeshRenderer:create");
|
||||
ok &= luaval_to_Physics3DRigidBodyDes(L, 3, &arg1, "cc.PhysicsMeshRenderer:create");
|
||||
if (!ok)
|
||||
{
|
||||
tolua_error(L, "invalid arguments in function 'lua_cocos2dx_physics3d_PhysicsSprite3D_create'", nullptr);
|
||||
tolua_error(L, "invalid arguments in function 'lua_cocos2dx_physics3d_PhysicsMeshRenderer_create'", nullptr);
|
||||
return 0;
|
||||
}
|
||||
cocos2d::PhysicsSprite3D* ret = cocos2d::PhysicsSprite3D::create(arg0, &arg1);
|
||||
object_to_luaval<cocos2d::PhysicsSprite3D>(L, "cc.PhysicsSprite3D", (cocos2d::PhysicsSprite3D*)ret);
|
||||
cocos2d::PhysicsMeshRenderer* ret = cocos2d::PhysicsMeshRenderer::create(arg0, &arg1);
|
||||
object_to_luaval<cocos2d::PhysicsMeshRenderer>(L, "cc.PhysicsMeshRenderer", (cocos2d::PhysicsMeshRenderer*)ret);
|
||||
return 1;
|
||||
}
|
||||
if (argc == 3)
|
||||
|
@ -222,16 +222,16 @@ int lua_cocos2dx_physics3d_PhysicsSprite3D_create(lua_State* L)
|
|||
std::string arg0;
|
||||
cocos2d::Physics3DRigidBodyDes arg1;
|
||||
cocos2d::Vec3 arg2;
|
||||
ok &= luaval_to_std_string(L, 2, &arg0, "cc.PhysicsSprite3D:create");
|
||||
ok &= luaval_to_Physics3DRigidBodyDes(L, 3, &arg1, "cc.PhysicsSprite3D:create");
|
||||
ok &= luaval_to_vec3(L, 4, &arg2, "cc.PhysicsSprite3D:create");
|
||||
ok &= luaval_to_std_string(L, 2, &arg0, "cc.PhysicsMeshRenderer:create");
|
||||
ok &= luaval_to_Physics3DRigidBodyDes(L, 3, &arg1, "cc.PhysicsMeshRenderer:create");
|
||||
ok &= luaval_to_vec3(L, 4, &arg2, "cc.PhysicsMeshRenderer:create");
|
||||
if (!ok)
|
||||
{
|
||||
tolua_error(L, "invalid arguments in function 'lua_cocos2dx_physics3d_PhysicsSprite3D_create'", nullptr);
|
||||
tolua_error(L, "invalid arguments in function 'lua_cocos2dx_physics3d_PhysicsMeshRenderer_create'", nullptr);
|
||||
return 0;
|
||||
}
|
||||
cocos2d::PhysicsSprite3D* ret = cocos2d::PhysicsSprite3D::create(arg0, &arg1, arg2);
|
||||
object_to_luaval<cocos2d::PhysicsSprite3D>(L, "cc.PhysicsSprite3D", (cocos2d::PhysicsSprite3D*)ret);
|
||||
cocos2d::PhysicsMeshRenderer* ret = cocos2d::PhysicsMeshRenderer::create(arg0, &arg1, arg2);
|
||||
object_to_luaval<cocos2d::PhysicsMeshRenderer>(L, "cc.PhysicsMeshRenderer", (cocos2d::PhysicsMeshRenderer*)ret);
|
||||
return 1;
|
||||
}
|
||||
if (argc == 4)
|
||||
|
@ -240,35 +240,35 @@ int lua_cocos2dx_physics3d_PhysicsSprite3D_create(lua_State* L)
|
|||
cocos2d::Physics3DRigidBodyDes arg1;
|
||||
cocos2d::Vec3 arg2;
|
||||
cocos2d::Quaternion arg3;
|
||||
ok &= luaval_to_std_string(L, 2, &arg0, "cc.PhysicsSprite3D:create");
|
||||
ok &= luaval_to_Physics3DRigidBodyDes(L, 3, &arg1, "cc.PhysicsSprite3D:create");
|
||||
ok &= luaval_to_vec3(L, 4, &arg2, "cc.PhysicsSprite3D:create");
|
||||
ok &= luaval_to_std_string(L, 2, &arg0, "cc.PhysicsMeshRenderer:create");
|
||||
ok &= luaval_to_Physics3DRigidBodyDes(L, 3, &arg1, "cc.PhysicsMeshRenderer:create");
|
||||
ok &= luaval_to_vec3(L, 4, &arg2, "cc.PhysicsMeshRenderer:create");
|
||||
ok &= luaval_to_quaternion(L, 5, &arg3);
|
||||
if (!ok)
|
||||
{
|
||||
tolua_error(L, "invalid arguments in function 'lua_cocos2dx_physics3d_PhysicsSprite3D_create'", nullptr);
|
||||
tolua_error(L, "invalid arguments in function 'lua_cocos2dx_physics3d_PhysicsMeshRenderer_create'", nullptr);
|
||||
return 0;
|
||||
}
|
||||
cocos2d::PhysicsSprite3D* ret = cocos2d::PhysicsSprite3D::create(arg0, &arg1, arg2, arg3);
|
||||
object_to_luaval<cocos2d::PhysicsSprite3D>(L, "cc.PhysicsSprite3D", (cocos2d::PhysicsSprite3D*)ret);
|
||||
cocos2d::PhysicsMeshRenderer* ret = cocos2d::PhysicsMeshRenderer::create(arg0, &arg1, arg2, arg3);
|
||||
object_to_luaval<cocos2d::PhysicsMeshRenderer>(L, "cc.PhysicsMeshRenderer", (cocos2d::PhysicsMeshRenderer*)ret);
|
||||
return 1;
|
||||
}
|
||||
luaL_error(L, "%s has wrong number of arguments: %d, was expecting %d\n ", "cc.PhysicsSprite3D:create", argc, 2);
|
||||
luaL_error(L, "%s has wrong number of arguments: %d, was expecting %d\n ", "cc.PhysicsMeshRenderer:create", argc, 2);
|
||||
return 0;
|
||||
# if COCOS2D_DEBUG >= 1
|
||||
tolua_lerror:
|
||||
tolua_error(L, "#ferror in function 'lua_cocos2dx_physics3d_PhysicsSprite3D_create'.", &tolua_err);
|
||||
tolua_error(L, "#ferror in function 'lua_cocos2dx_physics3d_PhysicsMeshRenderer_create'.", &tolua_err);
|
||||
# endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
void extendPhysicsSprite3D(lua_State* L)
|
||||
void extendPhysicsMeshRenderer(lua_State* L)
|
||||
{
|
||||
lua_pushstring(L, "cc.PhysicsSprite3D");
|
||||
lua_pushstring(L, "cc.PhysicsMeshRenderer");
|
||||
lua_rawget(L, LUA_REGISTRYINDEX);
|
||||
if (lua_istable(L, -1))
|
||||
{
|
||||
tolua_function(L, "create", lua_cocos2dx_physics3d_PhysicsSprite3D_create);
|
||||
tolua_function(L, "create", lua_cocos2dx_physics3d_PhysicsMeshRenderer_create);
|
||||
}
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
|
@ -847,7 +847,7 @@ int register_all_physics3d_manual(lua_State* L)
|
|||
if (nullptr == L)
|
||||
return 0;
|
||||
|
||||
extendPhysicsSprite3D(L);
|
||||
extendPhysicsMeshRenderer(L);
|
||||
extendPhysics3DRigidBody(L);
|
||||
extendPhysics3DComponent(L);
|
||||
extendPhysics3DWorld(L);
|
||||
|
|
|
@ -160,8 +160,8 @@ list(APPEND GAME_HEADER
|
|||
Classes/ExtensionsTest/ExtensionsTest.h
|
||||
Classes/ExtensionsTest/TableViewTest/CustomTableViewCell.h
|
||||
Classes/ExtensionsTest/TableViewTest/TableViewTestScene.h
|
||||
Classes/Sprite3DTest/Sprite3DTest.h
|
||||
Classes/Sprite3DTest/DrawNode3D.h
|
||||
Classes/MeshRendererTest/MeshRendererTest.h
|
||||
Classes/MeshRendererTest/DrawNode3D.h
|
||||
Classes/BaseTest.h
|
||||
Classes/SceneTest/SceneTest.h
|
||||
Classes/ReleasePoolTest/ReleasePoolTest.h
|
||||
|
@ -296,8 +296,8 @@ list(APPEND GAME_SOURCE
|
|||
Classes/ShaderTest/ShaderTest2.cpp
|
||||
Classes/SpineTest/SpineTest.cpp
|
||||
# Classes/Scene3DTest/Scene3DTest.cpp
|
||||
Classes/Sprite3DTest/DrawNode3D.cpp
|
||||
Classes/Sprite3DTest/Sprite3DTest.cpp
|
||||
Classes/MeshRendererTest/DrawNode3D.cpp
|
||||
Classes/MeshRendererTest/MeshRendererTest.cpp
|
||||
Classes/SpritePolygonTest/SpritePolygonTest.cpp
|
||||
Classes/SpriteTest/SpriteTest.cpp
|
||||
Classes/TerrainTest/TerrainTest.cpp
|
||||
|
|
|
@ -85,7 +85,12 @@ bool AppDelegate::applicationDidFinishLaunching()
|
|||
}
|
||||
|
||||
director->setStatsDisplay(true);
|
||||
|
||||
#ifdef CC_PLATFORM_PC
|
||||
director->setAnimationInterval(1.0f / glfwGetVideoMode(glfwGetPrimaryMonitor())->refreshRate);
|
||||
#else
|
||||
director->setAnimationInterval(1.0f / 60);
|
||||
#endif
|
||||
|
||||
auto screenSize = glview->getFrameSize();
|
||||
|
||||
|
|
|
@ -47,11 +47,11 @@ BillBoardTests::BillBoardTests()
|
|||
//------------------------------------------------------------------
|
||||
BillBoardRotationTest::BillBoardRotationTest()
|
||||
{
|
||||
auto root = Sprite3D::create();
|
||||
auto root = MeshRenderer::create();
|
||||
root->setPositionNormalized(Vec2(0.5f, 0.25f));
|
||||
addChild(root);
|
||||
|
||||
auto model = Sprite3D::create("Sprite3DTest/orc.c3b");
|
||||
auto model = MeshRenderer::create("MeshRendererTest/orc.c3b");
|
||||
model->setScale(5);
|
||||
model->setRotation3D(Vec3(0.0f, 180.0f, 0.0f));
|
||||
root->addChild(model);
|
||||
|
@ -150,11 +150,11 @@ BillBoardTest::BillBoardTest() : _camera(nullptr)
|
|||
_billboards.push_back(billboard);
|
||||
_billboards.push_back(billboard2);
|
||||
|
||||
auto sprite3d = Sprite3D::create("Sprite3DTest/orc.c3t");
|
||||
sprite3d->setScale(2.0f);
|
||||
sprite3d->addChild(billboard);
|
||||
sprite3d->runAction(RepeatForever::create(RotateBy::create(10.0f, Vec3(0.0f, 360.0f, 0.0f))));
|
||||
_layerBillBoard->addChild(sprite3d);
|
||||
auto mesh = MeshRenderer::create("MeshRendererTest/orc.c3t");
|
||||
mesh->setScale(2.0f);
|
||||
mesh->addChild(billboard);
|
||||
mesh->runAction(RepeatForever::create(RotateBy::create(10.0f, Vec3(0.0f, 360.0f, 0.0f))));
|
||||
_layerBillBoard->addChild(mesh);
|
||||
}
|
||||
|
||||
addNewBillBoardWithCoords(Vec3(20.0f, 5.0f, 0.0f));
|
||||
|
|
|
@ -40,15 +40,15 @@ bool Bug15594Layer::init()
|
|||
{
|
||||
if (BugsTestBase::init())
|
||||
{
|
||||
auto sprite3d = Sprite3D::create("Images/bugs/bug15594.c3t", "Images/bugs/bug15594.jpg");
|
||||
addChild(sprite3d);
|
||||
auto mesh = MeshRenderer::create("Images/bugs/bug15594.c3t", "Images/bugs/bug15594.jpg");
|
||||
addChild(mesh);
|
||||
auto size = Director::getInstance()->getWinSize();
|
||||
sprite3d->setPosition(size / 2);
|
||||
mesh->setPosition(size / 2);
|
||||
|
||||
auto animation = Animation3D::create("Images/bugs/bug15594.c3t");
|
||||
auto animate = Animate3D::create(animation);
|
||||
auto repeat = RepeatForever::create(animate);
|
||||
sprite3d->runAction(repeat);
|
||||
mesh->runAction(repeat);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -77,14 +77,14 @@ CameraRotationTest::CameraRotationTest()
|
|||
_camNode->setPositionZ(Camera::getDefaultCamera()->getPosition3D().z);
|
||||
_camControlNode->addChild(_camNode);
|
||||
|
||||
auto sp3d = Sprite3D::create();
|
||||
sp3d->setPosition(s.width / 2, s.height / 2);
|
||||
addChild(sp3d);
|
||||
auto mesh = MeshRenderer::create();
|
||||
mesh->setPosition(s.width / 2, s.height / 2);
|
||||
addChild(mesh);
|
||||
|
||||
auto lship = Label::create();
|
||||
lship->setString("Ship");
|
||||
lship->setPosition(0, 20);
|
||||
sp3d->addChild(lship);
|
||||
mesh->addChild(lship);
|
||||
|
||||
// Billboards
|
||||
// Yellow is at the back
|
||||
|
@ -92,7 +92,7 @@ CameraRotationTest::CameraRotationTest()
|
|||
bill1->setPosition3D(Vec3(50.0f, 10.0f, -10.0f));
|
||||
bill1->setColor(Color3B::YELLOW);
|
||||
bill1->setScale(0.6f);
|
||||
sp3d->addChild(bill1);
|
||||
mesh->addChild(bill1);
|
||||
|
||||
l1 = Label::create();
|
||||
l1->setPosition(Vec2(0.0f, -10.0f));
|
||||
|
@ -108,7 +108,7 @@ CameraRotationTest::CameraRotationTest()
|
|||
bill2 = BillBoard::create("Images/Icon.png");
|
||||
bill2->setPosition3D(Vec3(-50.0f, -10.0f, 10.0f));
|
||||
bill2->setScale(0.6f);
|
||||
sp3d->addChild(bill2);
|
||||
mesh->addChild(bill2);
|
||||
|
||||
l2 = Label::create();
|
||||
l2->setString("Billboard2");
|
||||
|
@ -122,9 +122,9 @@ CameraRotationTest::CameraRotationTest()
|
|||
bill2->addChild(p2);
|
||||
|
||||
// 3D models
|
||||
auto model = Sprite3D::create("Sprite3DTest/boss1.obj");
|
||||
auto model = MeshRenderer::create("MeshRendererTest/boss1.obj");
|
||||
model->setScale(4);
|
||||
model->setTexture("Sprite3DTest/boss.png");
|
||||
model->setTexture("MeshRendererTest/boss.png");
|
||||
model->setPosition3D(Vec3(s.width / 2, s.height / 2, 0));
|
||||
addChild(model);
|
||||
|
||||
|
@ -226,8 +226,8 @@ void Camera3DTestDemo::SwitchViewCallback(Ref* sender, CameraType cameraType)
|
|||
_cameraType = cameraType;
|
||||
if (_cameraType == CameraType::Free)
|
||||
{
|
||||
_camera->setPosition3D(Vec3(0, 130, 130) + _sprite3D->getPosition3D());
|
||||
_camera->lookAt(_sprite3D->getPosition3D());
|
||||
_camera->setPosition3D(Vec3(0, 130, 130) + _mesh->getPosition3D());
|
||||
_camera->lookAt(_mesh->getPosition3D());
|
||||
|
||||
_RotateRightlabel->setColor(Color3B::WHITE);
|
||||
_RotateLeftlabel->setColor(Color3B::WHITE);
|
||||
|
@ -237,10 +237,10 @@ void Camera3DTestDemo::SwitchViewCallback(Ref* sender, CameraType cameraType)
|
|||
else if (_cameraType == CameraType::FirstPerson)
|
||||
{
|
||||
Vec3 newFaceDir;
|
||||
_sprite3D->getWorldToNodeTransform().getForwardVector(&newFaceDir);
|
||||
_mesh->getWorldToNodeTransform().getForwardVector(&newFaceDir);
|
||||
newFaceDir.normalize();
|
||||
_camera->setPosition3D(Vec3(0, 35, 0) + _sprite3D->getPosition3D());
|
||||
_camera->lookAt(_sprite3D->getPosition3D() + newFaceDir * 50);
|
||||
_camera->setPosition3D(Vec3(0, 35, 0) + _mesh->getPosition3D());
|
||||
_camera->lookAt(_mesh->getPosition3D() + newFaceDir * 50);
|
||||
|
||||
_RotateRightlabel->setColor(Color3B::WHITE);
|
||||
_RotateLeftlabel->setColor(Color3B::WHITE);
|
||||
|
@ -249,8 +249,8 @@ void Camera3DTestDemo::SwitchViewCallback(Ref* sender, CameraType cameraType)
|
|||
}
|
||||
else if (_cameraType == CameraType::ThirdPerson)
|
||||
{
|
||||
_camera->setPosition3D(Vec3(0, 130, 130) + _sprite3D->getPosition3D());
|
||||
_camera->lookAt(_sprite3D->getPosition3D());
|
||||
_camera->setPosition3D(Vec3(0, 130, 130) + _mesh->getPosition3D());
|
||||
_camera->lookAt(_mesh->getPosition3D());
|
||||
|
||||
_RotateRightlabel->setColor(Color3B::GRAY);
|
||||
_RotateLeftlabel->setColor(Color3B::GRAY);
|
||||
|
@ -261,7 +261,7 @@ void Camera3DTestDemo::SwitchViewCallback(Ref* sender, CameraType cameraType)
|
|||
void Camera3DTestDemo::onEnter()
|
||||
{
|
||||
CameraBaseTest::onEnter();
|
||||
_sprite3D = nullptr;
|
||||
_mesh = nullptr;
|
||||
auto s = Director::getInstance()->getWinSize();
|
||||
auto listener = EventListenerTouchAllAtOnce::create();
|
||||
listener->onTouchesBegan = CC_CALLBACK_2(Camera3DTestDemo::onTouchesBegan, this);
|
||||
|
@ -272,7 +272,7 @@ void Camera3DTestDemo::onEnter()
|
|||
addChild(layer3D, 0);
|
||||
_layer3D = layer3D;
|
||||
_curState = State_None;
|
||||
addNewSpriteWithCoords(Vec3(0, 0, 0), "Sprite3DTest/girl.c3b", true, 0.2f, true);
|
||||
addNewSpriteWithCoords(Vec3(0, 0, 0), "MeshRendererTest/girl.c3b", true, 0.2f, true);
|
||||
TTFConfig ttfConfig("fonts/arial.ttf", 20);
|
||||
|
||||
auto containerForLabel1 = Node::create();
|
||||
|
@ -389,25 +389,25 @@ void Camera3DTestDemo::addNewSpriteWithCoords(Vec3 p,
|
|||
float scale,
|
||||
bool bindCamera)
|
||||
{
|
||||
auto sprite = Sprite3D::create(fileName);
|
||||
_layer3D->addChild(sprite);
|
||||
float globalZOrder = sprite->getGlobalZOrder();
|
||||
sprite->setPosition3D(Vec3(p.x, p.y, p.z));
|
||||
sprite->setGlobalZOrder(globalZOrder);
|
||||
auto mesh = MeshRenderer::create(fileName);
|
||||
_layer3D->addChild(mesh);
|
||||
float globalZOrder = mesh->getGlobalZOrder();
|
||||
mesh->setPosition3D(Vec3(p.x, p.y, p.z));
|
||||
mesh->setGlobalZOrder(globalZOrder);
|
||||
if (playAnimation)
|
||||
{
|
||||
auto animation = Animation3D::create(fileName, "Take 001");
|
||||
if (animation)
|
||||
{
|
||||
auto animate = Animate3D::create(animation);
|
||||
sprite->runAction(RepeatForever::create(animate));
|
||||
mesh->runAction(RepeatForever::create(animate));
|
||||
}
|
||||
}
|
||||
if (bindCamera)
|
||||
{
|
||||
_sprite3D = sprite;
|
||||
_mesh = mesh;
|
||||
}
|
||||
sprite->setScale(scale);
|
||||
mesh->setScale(scale);
|
||||
}
|
||||
void Camera3DTestDemo::onTouchesBegan(const std::vector<Touch*>& touches, cocos2d::Event* event) {}
|
||||
void Camera3DTestDemo::onTouchesMoved(const std::vector<Touch*>& touches, cocos2d::Event* event)
|
||||
|
@ -431,25 +431,25 @@ void Camera3DTestDemo::onTouchesMoved(const std::vector<Touch*>& touches, cocos2
|
|||
cameraPos += cameraDir * newPos.y * 0.1f;
|
||||
cameraPos += cameraRightDir * newPos.x * 0.1f;
|
||||
_camera->setPosition3D(cameraPos);
|
||||
if (_sprite3D && _cameraType == CameraType::FirstPerson)
|
||||
if (_mesh && _cameraType == CameraType::FirstPerson)
|
||||
{
|
||||
_sprite3D->setPosition3D(Vec3(_camera->getPositionX(), 0, _camera->getPositionZ()));
|
||||
_targetPos = _sprite3D->getPosition3D();
|
||||
_mesh->setPosition3D(Vec3(_camera->getPositionX(), 0, _camera->getPositionZ()));
|
||||
_targetPos = _mesh->getPosition3D();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
void Camera3DTestDemo::move3D(float elapsedTime)
|
||||
{
|
||||
if (_sprite3D)
|
||||
if (_mesh)
|
||||
{
|
||||
Vec3 curPos = _sprite3D->getPosition3D();
|
||||
Vec3 curPos = _mesh->getPosition3D();
|
||||
Vec3 newFaceDir = _targetPos - curPos;
|
||||
newFaceDir.y = 0.0f;
|
||||
newFaceDir.normalize();
|
||||
Vec3 offset = newFaceDir * 25.0f * elapsedTime;
|
||||
curPos += offset;
|
||||
_sprite3D->setPosition3D(curPos);
|
||||
_mesh->setPosition3D(curPos);
|
||||
if (_cameraType == CameraType::ThirdPerson)
|
||||
{
|
||||
Vec3 cameraPos = _camera->getPosition3D();
|
||||
|
@ -461,11 +461,11 @@ void Camera3DTestDemo::move3D(float elapsedTime)
|
|||
}
|
||||
void Camera3DTestDemo::updateState(float elapsedTime)
|
||||
{
|
||||
if (_sprite3D)
|
||||
if (_mesh)
|
||||
{
|
||||
Vec3 curPos = _sprite3D->getPosition3D();
|
||||
Vec3 curPos = _mesh->getPosition3D();
|
||||
Vec3 curFaceDir;
|
||||
_sprite3D->getNodeToWorldTransform().getForwardVector(&curFaceDir);
|
||||
_mesh->getNodeToWorldTransform().getForwardVector(&curFaceDir);
|
||||
curFaceDir = -curFaceDir;
|
||||
curFaceDir.normalize();
|
||||
Vec3 newFaceDir = _targetPos - curPos;
|
||||
|
@ -497,7 +497,7 @@ void Camera3DTestDemo::onTouchesEnded(const std::vector<Touch*>& touches, cocos2
|
|||
auto location = touch->getLocationInView();
|
||||
if (_camera)
|
||||
{
|
||||
if (_sprite3D && _cameraType == CameraType::ThirdPerson && _bZoomOut == false && _bZoomIn == false &&
|
||||
if (_mesh && _cameraType == CameraType::ThirdPerson && _bZoomOut == false && _bZoomIn == false &&
|
||||
_bRotateLeft == false && _bRotateRight == false)
|
||||
{
|
||||
Vec3 nearP(location.x, location.y, -1.0f), farP(location.x, location.y, 1.0f);
|
||||
|
@ -531,7 +531,7 @@ void Camera3DTestDemo::onTouchesEnded(const std::vector<Touch*>& touches, cocos2
|
|||
void onTouchesCancelled(const std::vector<Touch*>& touches, cocos2d::Event* event) {}
|
||||
void Camera3DTestDemo::updateCamera(float fDelta)
|
||||
{
|
||||
if (_sprite3D)
|
||||
if (_mesh)
|
||||
{
|
||||
if (_cameraType == CameraType::ThirdPerson)
|
||||
{
|
||||
|
@ -541,13 +541,13 @@ void Camera3DTestDemo::updateCamera(float fDelta)
|
|||
move3D(fDelta);
|
||||
if (isState(_curState, State_Rotate))
|
||||
{
|
||||
Vec3 curPos = _sprite3D->getPosition3D();
|
||||
Vec3 curPos = _mesh->getPosition3D();
|
||||
|
||||
Vec3 newFaceDir = _targetPos - curPos;
|
||||
newFaceDir.y = 0;
|
||||
newFaceDir.normalize();
|
||||
Vec3 up;
|
||||
_sprite3D->getNodeToWorldTransform().getUpVector(&up);
|
||||
_mesh->getNodeToWorldTransform().getUpVector(&up);
|
||||
up.normalize();
|
||||
Vec3 right;
|
||||
Vec3::cross(-newFaceDir, up, &right);
|
||||
|
@ -573,7 +573,7 @@ void Camera3DTestDemo::updateCamera(float fDelta)
|
|||
mat.m[13] = pos.y;
|
||||
mat.m[14] = pos.z;
|
||||
mat.m[15] = 1.0f;
|
||||
_sprite3D->setAdditionalTransform(&mat);
|
||||
_mesh->setAdditionalTransform(&mat);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -583,7 +583,7 @@ void Camera3DTestDemo::updateCamera(float fDelta)
|
|||
{
|
||||
if (_cameraType == CameraType::ThirdPerson)
|
||||
{
|
||||
Vec3 lookDir = _camera->getPosition3D() - _sprite3D->getPosition3D();
|
||||
Vec3 lookDir = _camera->getPosition3D() - _mesh->getPosition3D();
|
||||
Vec3 cameraPos = _camera->getPosition3D();
|
||||
if (lookDir.length() <= 300)
|
||||
{
|
||||
|
@ -608,7 +608,7 @@ void Camera3DTestDemo::updateCamera(float fDelta)
|
|||
{
|
||||
if (_cameraType == CameraType::ThirdPerson)
|
||||
{
|
||||
Vec3 lookDir = _camera->getPosition3D() - _sprite3D->getPosition3D();
|
||||
Vec3 lookDir = _camera->getPosition3D() - _mesh->getPosition3D();
|
||||
Vec3 cameraPos = _camera->getPosition3D();
|
||||
if (lookDir.length() >= 50)
|
||||
{
|
||||
|
@ -747,9 +747,9 @@ void CameraCullingDemo::onEnter()
|
|||
|
||||
// + -
|
||||
MenuItemFont::setFontSize(40);
|
||||
auto decrease = MenuItemFont::create(" - ", CC_CALLBACK_1(CameraCullingDemo::delSpriteCallback, this));
|
||||
auto decrease = MenuItemFont::create(" - ", CC_CALLBACK_1(CameraCullingDemo::delMeshCallback, this));
|
||||
decrease->setColor(Color3B(0, 200, 20));
|
||||
auto increase = MenuItemFont::create(" + ", CC_CALLBACK_1(CameraCullingDemo::addSpriteCallback, this));
|
||||
auto increase = MenuItemFont::create(" + ", CC_CALLBACK_1(CameraCullingDemo::addMeshCallback, this));
|
||||
increase->setColor(Color3B(0, 200, 20));
|
||||
|
||||
menu = Menu::create(decrease, increase, nullptr);
|
||||
|
@ -758,10 +758,10 @@ void CameraCullingDemo::onEnter()
|
|||
addChild(menu, 1);
|
||||
|
||||
TTFConfig ttfCount("fonts/Marker Felt.ttf", 30);
|
||||
_labelSprite3DCount = Label::createWithTTF(ttfCount, "0 sprits");
|
||||
_labelSprite3DCount->setColor(Color3B(0, 200, 20));
|
||||
_labelSprite3DCount->setPosition(Vec2(s.width / 2, VisibleRect::top().y - 70));
|
||||
addChild(_labelSprite3DCount);
|
||||
_labelMeshCount = Label::createWithTTF(ttfCount, "0 sprits");
|
||||
_labelMeshCount->setColor(Color3B(0, 200, 20));
|
||||
_labelMeshCount->setPosition(Vec2(s.width / 2, VisibleRect::top().y - 70));
|
||||
addChild(_labelMeshCount);
|
||||
|
||||
// aabb drawNode3D
|
||||
_drawAABB = DrawNode3D::create();
|
||||
|
@ -777,7 +777,7 @@ void CameraCullingDemo::onEnter()
|
|||
switchViewCallback(this);
|
||||
|
||||
// add sprite
|
||||
addSpriteCallback(nullptr);
|
||||
addMeshCallback(nullptr);
|
||||
}
|
||||
|
||||
void CameraCullingDemo::onExit()
|
||||
|
@ -805,7 +805,7 @@ void CameraCullingDemo::update(float dt)
|
|||
|
||||
for (const auto& iter : children)
|
||||
{
|
||||
const AABB& aabb = static_cast<Sprite3D*>(iter)->getAABB();
|
||||
const AABB& aabb = static_cast<MeshRenderer*>(iter)->getAABB();
|
||||
if (_cameraFirst->isVisibleInFrustum(&aabb))
|
||||
{
|
||||
aabb.getCorners(corners);
|
||||
|
@ -872,7 +872,7 @@ void CameraCullingDemo::switchViewCallback(Ref* sender)
|
|||
}
|
||||
}
|
||||
|
||||
void CameraCullingDemo::addSpriteCallback(Ref* sender)
|
||||
void CameraCullingDemo::addMeshCallback(Ref* sender)
|
||||
{
|
||||
_layer3D->removeAllChildren();
|
||||
_objects.clear();
|
||||
|
@ -883,7 +883,7 @@ void CameraCullingDemo::addSpriteCallback(Ref* sender)
|
|||
{
|
||||
for (int z = -_row; z < _row; z++)
|
||||
{
|
||||
auto sprite = Sprite3D::create("Sprite3DTest/orc.c3b");
|
||||
auto sprite = MeshRenderer::create("MeshRendererTest/orc.c3b");
|
||||
sprite->setPosition3D(Vec3(x * 30.0f, 0.0f, z * 30.0f));
|
||||
sprite->setRotation3D(Vec3(0.0f, 180.0f, 0.0f));
|
||||
_objects.push_back(sprite);
|
||||
|
@ -897,10 +897,10 @@ void CameraCullingDemo::addSpriteCallback(Ref* sender)
|
|||
// update sprite number
|
||||
char szText[16];
|
||||
sprintf(szText, "%d sprits", static_cast<int32_t>(_layer3D->getChildrenCount()));
|
||||
_labelSprite3DCount->setString(szText);
|
||||
_labelMeshCount->setString(szText);
|
||||
}
|
||||
|
||||
void CameraCullingDemo::delSpriteCallback(Ref* sender)
|
||||
void CameraCullingDemo::delMeshCallback(Ref* sender)
|
||||
{
|
||||
if (_row == 0)
|
||||
return;
|
||||
|
@ -913,7 +913,7 @@ void CameraCullingDemo::delSpriteCallback(Ref* sender)
|
|||
{
|
||||
for (int z = -_row; z < _row; z++)
|
||||
{
|
||||
auto sprite = Sprite3D::create("Sprite3DTest/orc.c3b");
|
||||
auto sprite = MeshRenderer::create("MeshRendererTest/orc.c3b");
|
||||
sprite->setPosition3D(Vec3(x * 30.0f, 0.0f, z * 30.0f));
|
||||
_objects.push_back(sprite);
|
||||
_layer3D->addChild(sprite);
|
||||
|
@ -926,7 +926,7 @@ void CameraCullingDemo::delSpriteCallback(Ref* sender)
|
|||
// update sprite number
|
||||
char szText[16];
|
||||
sprintf(szText, "%l sprits", static_cast<int32_t>(_layer3D->getChildrenCount()));
|
||||
_labelSprite3DCount->setString(szText);
|
||||
_labelMeshCount->setString(szText);
|
||||
}
|
||||
|
||||
void CameraCullingDemo::drawCameraFrustum()
|
||||
|
@ -993,8 +993,8 @@ CameraArcBallDemo::CameraArcBallDemo()
|
|||
, _operate(OperateCamType::RotateCamera)
|
||||
, _center(Vec3(0, 0, 0))
|
||||
, _target(0)
|
||||
, _sprite3D1(nullptr)
|
||||
, _sprite3D2(nullptr)
|
||||
, _mesh1(nullptr)
|
||||
, _mesh2(nullptr)
|
||||
{}
|
||||
CameraArcBallDemo::~CameraArcBallDemo() {}
|
||||
|
||||
|
@ -1043,17 +1043,17 @@ void CameraArcBallDemo::onEnter()
|
|||
_layer3D->addChild(_camera);
|
||||
}
|
||||
|
||||
_sprite3D1 = Sprite3D::create("Sprite3DTest/orc.c3b");
|
||||
_sprite3D1->setScale(0.5);
|
||||
_sprite3D1->setRotation3D(Vec3(0.0f, 180.0f, 0.0f));
|
||||
_sprite3D1->setPosition3D(Vec3(0, 0, 0));
|
||||
_layer3D->addChild(_sprite3D1);
|
||||
_mesh1 = MeshRenderer::create("MeshRendererTest/orc.c3b");
|
||||
_mesh1->setScale(0.5);
|
||||
_mesh1->setRotation3D(Vec3(0.0f, 180.0f, 0.0f));
|
||||
_mesh1->setPosition3D(Vec3(0, 0, 0));
|
||||
_layer3D->addChild(_mesh1);
|
||||
|
||||
_sprite3D2 = Sprite3D::create("Sprite3DTest/boss.c3b");
|
||||
_sprite3D2->setScale(0.6f);
|
||||
_sprite3D2->setRotation3D(Vec3(-90.0f, 0.0f, 0.0f));
|
||||
_sprite3D2->setPosition3D(Vec3(20.0f, 0.0f, 0.0f));
|
||||
_layer3D->addChild(_sprite3D2);
|
||||
_mesh2 = MeshRenderer::create("MeshRendererTest/boss.c3b");
|
||||
_mesh2->setScale(0.6f);
|
||||
_mesh2->setRotation3D(Vec3(-90.0f, 0.0f, 0.0f));
|
||||
_mesh2->setPosition3D(Vec3(20.0f, 0.0f, 0.0f));
|
||||
_layer3D->addChild(_mesh2);
|
||||
|
||||
_drawGrid = DrawNode3D::create();
|
||||
|
||||
|
@ -1187,13 +1187,13 @@ void CameraArcBallDemo::switchTargetCallback(Ref* sender)
|
|||
if (_target == 0)
|
||||
{
|
||||
_target = 1;
|
||||
_center = _sprite3D2->getPosition3D();
|
||||
_center = _mesh2->getPosition3D();
|
||||
updateCameraTransform();
|
||||
}
|
||||
else if (_target == 1)
|
||||
{
|
||||
_target = 0;
|
||||
_center = _sprite3D1->getPosition3D();
|
||||
_center = _mesh1->getPosition3D();
|
||||
updateCameraTransform();
|
||||
}
|
||||
}
|
||||
|
@ -1253,18 +1253,18 @@ void FogTestDemo::onEnter()
|
|||
CC_SAFE_RELEASE_NULL(_programState1);
|
||||
CC_SAFE_RELEASE_NULL(_programState2);
|
||||
|
||||
auto vertexSource = FileUtils::getInstance()->getStringFromFile("Sprite3DTest/fog.vert");
|
||||
auto fragSource = FileUtils::getInstance()->getStringFromFile("Sprite3DTest/fog.frag");
|
||||
auto vertexSource = FileUtils::getInstance()->getStringFromFile("MeshRendererTest/fog.vert");
|
||||
auto fragSource = FileUtils::getInstance()->getStringFromFile("MeshRendererTest/fog.frag");
|
||||
auto program = backend::Device::getInstance()->newProgram(vertexSource, fragSource);
|
||||
_programState1 = new backend::ProgramState(program);
|
||||
_programState2 = new backend::ProgramState(program);
|
||||
CC_SAFE_RELEASE(program);
|
||||
|
||||
_sprite3D1 = Sprite3D::create("Sprite3DTest/teapot.c3b");
|
||||
_sprite3D2 = Sprite3D::create("Sprite3DTest/teapot.c3b");
|
||||
_mesh1 = MeshRenderer::create("MeshRendererTest/teapot.c3b");
|
||||
_mesh2 = MeshRenderer::create("MeshRendererTest/teapot.c3b");
|
||||
|
||||
_sprite3D1->setProgramState(_programState1);
|
||||
_sprite3D2->setProgramState(_programState2);
|
||||
_mesh1->setProgramState(_programState1);
|
||||
_mesh2->setProgramState(_programState2);
|
||||
|
||||
auto fogColor = Vec4(0.5, 0.5, 0.5, 1.0);
|
||||
float fogStart = 10;
|
||||
|
@ -1276,15 +1276,15 @@ void FogTestDemo::onEnter()
|
|||
SET_UNIFORM("u_fogEnd", &fogEnd, sizeof(fogEnd));
|
||||
SET_UNIFORM("u_fogEquation", &fogEquation, sizeof(fogEquation));
|
||||
|
||||
_layer3D->addChild(_sprite3D1);
|
||||
_sprite3D1->setPosition3D(Vec3(0, 0, 0));
|
||||
_sprite3D1->setScale(2.0f);
|
||||
_sprite3D1->setRotation3D(Vec3(-90.0f, 180.0f, 0.0f));
|
||||
_layer3D->addChild(_mesh1);
|
||||
_mesh1->setPosition3D(Vec3(0, 0, 0));
|
||||
_mesh1->setScale(2.0f);
|
||||
_mesh1->setRotation3D(Vec3(-90.0f, 180.0f, 0.0f));
|
||||
|
||||
_layer3D->addChild(_sprite3D2);
|
||||
_sprite3D2->setPosition3D(Vec3(0.0f, 0.0f, -20.0f));
|
||||
_sprite3D2->setScale(2.0f);
|
||||
_sprite3D2->setRotation3D(Vec3(-90.0f, 180.0f, 0.0f));
|
||||
_layer3D->addChild(_mesh2);
|
||||
_mesh2->setPosition3D(Vec3(0.0f, 0.0f, -20.0f));
|
||||
_mesh2->setScale(2.0f);
|
||||
_mesh2->setRotation3D(Vec3(-90.0f, 180.0f, 0.0f));
|
||||
|
||||
if (_camera == nullptr)
|
||||
{
|
||||
|
@ -1303,14 +1303,14 @@ void FogTestDemo::onEnter()
|
|||
CC_SAFE_RELEASE_NULL(_programState1);
|
||||
CC_SAFE_RELEASE_NULL(_programState2);
|
||||
|
||||
auto vertexSource = FileUtils::getInstance()->getStringFromFile("Sprite3DTest/fog.vert");
|
||||
auto fragSource = FileUtils::getInstance()->getStringFromFile("Sprite3DTest/fog.frag");
|
||||
auto vertexSource = FileUtils::getInstance()->getStringFromFile("MeshRendererTest/fog.vert");
|
||||
auto fragSource = FileUtils::getInstance()->getStringFromFile("MeshRendererTest/fog.frag");
|
||||
auto program = backend::Device::getInstance()->newProgram(vertexSource, fragSource);
|
||||
_programState1 = new backend::ProgramState(program);
|
||||
_programState2 = new backend::ProgramState(program);
|
||||
|
||||
_sprite3D1->setProgramState(_programState1);
|
||||
_sprite3D2->setProgramState(_programState2);
|
||||
_mesh1->setProgramState(_programState1);
|
||||
_mesh2->setProgramState(_programState2);
|
||||
CC_SAFE_RELEASE(program);
|
||||
|
||||
auto fogColor = Vec4(0.5, 0.5, 0.5, 1.0);
|
||||
|
@ -1429,8 +1429,8 @@ void FogTestDemo::onTouchesMoved(const std::vector<Touch*>& touches, cocos2d::Ev
|
|||
// CameraBaseTest::onEnter();
|
||||
// //auto sprite = Sprite::createWithTexture(fbo);
|
||||
// //sprite->setPosition(Vec2(100,100));
|
||||
// //std::string filename = "Sprite3DTest/girl.c3b";
|
||||
// //auto sprite = Sprite3D::create(filename);
|
||||
// //std::string filename = "MeshRendererTest/girl.c3b";
|
||||
// //auto sprite = MeshRenderer::create(filename);
|
||||
// //sprite->setScale(1.0);
|
||||
// //auto animation = Animation3D::create(filename);
|
||||
// //if (animation)
|
||||
|
@ -1500,10 +1500,10 @@ void BackgroundColorBrushTest::onEnter()
|
|||
addChild(camera);
|
||||
|
||||
// 3D model
|
||||
auto model = Sprite3D::create("Sprite3DTest/boss1.obj");
|
||||
auto model = MeshRenderer::create("MeshRendererTest/boss1.obj");
|
||||
model->setScale(4);
|
||||
model->setPosition3D(Vec3(20.0f, 0.0f, 0.0f));
|
||||
model->setTexture("Sprite3DTest/boss.png");
|
||||
model->setTexture("MeshRendererTest/boss.png");
|
||||
model->setCameraMask(static_cast<unsigned short>(CameraFlag::USER1));
|
||||
addChild(model);
|
||||
model->runAction(RepeatForever::create(RotateBy::create(1.f, Vec3(10.0f, 20.0f, 30.0f))));
|
||||
|
@ -1538,10 +1538,10 @@ void BackgroundColorBrushTest::onEnter()
|
|||
addChild(slider);
|
||||
|
||||
// 3D model for 2nd camera
|
||||
auto model = Sprite3D::create("Sprite3DTest/boss1.obj");
|
||||
auto model = MeshRenderer::create("MeshRendererTest/boss1.obj");
|
||||
model->setScale(4);
|
||||
model->setPosition3D(Vec3(-20.0f, 0.0f, 0.0f));
|
||||
model->setTexture("Sprite3DTest/boss.png");
|
||||
model->setTexture("MeshRendererTest/boss.png");
|
||||
model->setCameraMask(static_cast<unsigned short>(CameraFlag::USER2));
|
||||
base->addChild(model);
|
||||
model->runAction(RepeatForever::create(RotateBy::create(1.f, Vec3(10.0f, 20.0f, 30.0f))));
|
||||
|
|
|
@ -26,7 +26,7 @@ THE SOFTWARE.
|
|||
#pragma once
|
||||
|
||||
#include "../BaseTest.h"
|
||||
#include "../Sprite3DTest/DrawNode3D.h"
|
||||
#include "../MeshRendererTest/DrawNode3D.h"
|
||||
|
||||
#include "renderer/backend/ProgramState.h"
|
||||
#include "renderer/backend/Types.h"
|
||||
|
@ -35,7 +35,7 @@ THE SOFTWARE.
|
|||
|
||||
namespace cocos2d
|
||||
{
|
||||
class Sprite3D;
|
||||
class MeshRenderer;
|
||||
class Delay;
|
||||
} // namespace cocos2d
|
||||
|
||||
|
@ -142,7 +142,7 @@ public:
|
|||
protected:
|
||||
std::string _title;
|
||||
cocos2d::Layer* _layer3D;
|
||||
cocos2d::Sprite3D* _sprite3D;
|
||||
cocos2d::MeshRenderer* _mesh;
|
||||
cocos2d::Vec3 _targetPos;
|
||||
CameraType _cameraType;
|
||||
cocos2d::MenuItem* _incRot;
|
||||
|
@ -176,15 +176,15 @@ public:
|
|||
virtual std::string title() const override;
|
||||
void reachEndCallBack();
|
||||
void switchViewCallback(cocos2d::Ref* sender);
|
||||
void addSpriteCallback(cocos2d::Ref* sender);
|
||||
void delSpriteCallback(cocos2d::Ref* sender);
|
||||
void addMeshCallback(cocos2d::Ref* sender);
|
||||
void delMeshCallback(cocos2d::Ref* sender);
|
||||
|
||||
void drawCameraFrustum();
|
||||
|
||||
protected:
|
||||
cocos2d::Label* _labelSprite3DCount;
|
||||
cocos2d::Label* _labelMeshCount;
|
||||
cocos2d::Layer* _layer3D;
|
||||
std::vector<cocos2d::Sprite3D*> _objects;
|
||||
std::vector<cocos2d::MeshRenderer*> _objects;
|
||||
CameraType _cameraType;
|
||||
cocos2d::Camera* _cameraFirst;
|
||||
cocos2d::Camera* _cameraThird;
|
||||
|
@ -232,8 +232,8 @@ protected:
|
|||
OperateCamType _operate; // switch rotate or zoom
|
||||
cocos2d::Vec3 _center; // camera look target
|
||||
int _target; // switch camera look target
|
||||
cocos2d::Sprite3D* _sprite3D1;
|
||||
cocos2d::Sprite3D* _sprite3D2;
|
||||
cocos2d::MeshRenderer* _mesh1;
|
||||
cocos2d::MeshRenderer* _mesh2;
|
||||
};
|
||||
|
||||
class FogTestDemo : public CameraBaseTest
|
||||
|
@ -259,8 +259,8 @@ protected:
|
|||
CameraType _cameraType = CameraType::Free;
|
||||
cocos2d::Layer* _layer3D = nullptr;
|
||||
cocos2d::Camera* _camera = nullptr;
|
||||
cocos2d::Sprite3D* _sprite3D1 = nullptr;
|
||||
cocos2d::Sprite3D* _sprite3D2 = nullptr;
|
||||
cocos2d::MeshRenderer* _mesh1 = nullptr;
|
||||
cocos2d::MeshRenderer* _mesh2 = nullptr;
|
||||
cocos2d::backend::ProgramState* _programState1 = nullptr;
|
||||
cocos2d::backend::ProgramState* _programState2 = nullptr;
|
||||
|
||||
|
|
|
@ -108,8 +108,8 @@ void LightTest::addSprite()
|
|||
auto s = Director::getInstance()->getWinSize();
|
||||
|
||||
//{
|
||||
// std::string fileName = "Sprite3DTest/plane.c3b";
|
||||
// auto sprite = Sprite3D::create(fileName);
|
||||
// std::string fileName = "MeshRendererTest/plane.c3b";
|
||||
// auto sprite = MeshRenderer::create(fileName);
|
||||
// sprite->setRotation3D(Vec3(-90.0, 0.0, 0.0));
|
||||
// sprite->setScale(5.0f);
|
||||
// sprite->setPosition(Vec2(0.0, -50.0));
|
||||
|
@ -118,35 +118,35 @@ void LightTest::addSprite()
|
|||
//}
|
||||
|
||||
{
|
||||
std::string fileName = "Sprite3DTest/orc.c3b";
|
||||
auto sprite = Sprite3D::create(fileName);
|
||||
sprite->setRotation3D(Vec3(0.0f, 180.0f, 0.0f));
|
||||
sprite->setPosition(Vec2(0.0f, 0.0f));
|
||||
sprite->setScale(2.0);
|
||||
auto sp = Sprite3D::create("Sprite3DTest/axe.c3b");
|
||||
sprite->getAttachNode("Bip001 R Hand")->addChild(sp);
|
||||
std::string fileName = "MeshRendererTest/orc.c3b";
|
||||
auto mesh = MeshRenderer::create(fileName);
|
||||
mesh->setRotation3D(Vec3(0.0f, 180.0f, 0.0f));
|
||||
mesh->setPosition(Vec2(0.0f, 0.0f));
|
||||
mesh->setScale(2.0);
|
||||
auto m = MeshRenderer::create("MeshRendererTest/axe.c3b");
|
||||
mesh->getAttachNode("Bip001 R Hand")->addChild(m);
|
||||
auto animation = Animation3D::create(fileName);
|
||||
if (animation)
|
||||
{
|
||||
auto animate = Animate3D::create(animation);
|
||||
sprite->runAction(RepeatForever::create(animate));
|
||||
mesh->runAction(RepeatForever::create(animate));
|
||||
}
|
||||
|
||||
addChild(sprite);
|
||||
sprite->setCameraMask(2);
|
||||
addChild(mesh);
|
||||
mesh->setCameraMask(2);
|
||||
}
|
||||
|
||||
{
|
||||
std::string fileName = "Sprite3DTest/sphere.c3b";
|
||||
auto sprite = Sprite3D::create(fileName);
|
||||
std::string fileName = "MeshRendererTest/sphere.c3b";
|
||||
auto sprite = MeshRenderer::create(fileName);
|
||||
sprite->setPosition(Vec2(30.0f, 0.0f));
|
||||
addChild(sprite);
|
||||
sprite->setCameraMask(2);
|
||||
}
|
||||
|
||||
{
|
||||
std::string fileName = "Sprite3DTest/sphere.c3b";
|
||||
auto sprite = Sprite3D::create(fileName);
|
||||
std::string fileName = "MeshRendererTest/sphere.c3b";
|
||||
auto sprite = MeshRenderer::create(fileName);
|
||||
sprite->setScale(0.5f);
|
||||
sprite->setPosition(Vec2(-50.0f, 0.0f));
|
||||
addChild(sprite);
|
||||
|
@ -154,8 +154,8 @@ void LightTest::addSprite()
|
|||
}
|
||||
|
||||
{
|
||||
std::string fileName = "Sprite3DTest/sphere.c3b";
|
||||
auto sprite = Sprite3D::create(fileName);
|
||||
std::string fileName = "MeshRendererTest/sphere.c3b";
|
||||
auto sprite = MeshRenderer::create(fileName);
|
||||
sprite->setScale(0.5f);
|
||||
sprite->setPosition(Vec2(-30.0f, 10.0f));
|
||||
addChild(sprite);
|
||||
|
|
|
@ -45,8 +45,8 @@ MaterialSystemTest::MaterialSystemTest()
|
|||
ADD_TEST_CASE(Material_AutoBindings);
|
||||
ADD_TEST_CASE(Material_setTechnique);
|
||||
ADD_TEST_CASE(Material_clone);
|
||||
ADD_TEST_CASE(Material_MultipleSprite3D);
|
||||
ADD_TEST_CASE(Material_Sprite3DTest);
|
||||
ADD_TEST_CASE(Material_MultipleMeshRenderer);
|
||||
ADD_TEST_CASE(Material_MeshRendererTest);
|
||||
ADD_TEST_CASE(Material_parsePerformance);
|
||||
}
|
||||
|
||||
|
@ -57,30 +57,30 @@ std::string MaterialSystemBaseTest::title() const
|
|||
|
||||
// MARK: Tests start here
|
||||
|
||||
void Material_Sprite3DTest::onEnter()
|
||||
void Material_MeshRendererTest::onEnter()
|
||||
{
|
||||
MaterialSystemBaseTest::onEnter();
|
||||
|
||||
auto sprite = Sprite3D::create("Sprite3DTest/boss1.obj");
|
||||
sprite->setScale(8.f);
|
||||
sprite->setTexture("Sprite3DTest/boss.png");
|
||||
this->addChild(sprite);
|
||||
sprite->setPositionNormalized(Vec2(0.5f, 0.5f));
|
||||
auto mesh = MeshRenderer::create("MeshRendererTest/boss1.obj");
|
||||
mesh->setScale(8.f);
|
||||
mesh->setTexture("MeshRendererTest/boss.png");
|
||||
this->addChild(mesh);
|
||||
mesh->setPositionNormalized(Vec2(0.5f, 0.5f));
|
||||
}
|
||||
|
||||
std::string Material_Sprite3DTest::subtitle() const
|
||||
std::string Material_MeshRendererTest::subtitle() const
|
||||
{
|
||||
return "Material System on Sprite3D";
|
||||
return "Material System on MeshRenderer";
|
||||
}
|
||||
|
||||
void Material_MultipleSprite3D::onEnter()
|
||||
void Material_MultipleMeshRenderer::onEnter()
|
||||
{
|
||||
MaterialSystemBaseTest::onEnter();
|
||||
|
||||
const char* names[] = {
|
||||
"Sprite3DTest/ReskinGirl.c3b", "Sprite3DTest/ReskinGirl.c3b", "Sprite3DTest/ReskinGirl.c3b",
|
||||
"Sprite3DTest/ReskinGirl.c3b", "Sprite3DTest/ReskinGirl.c3b", "Sprite3DTest/ReskinGirl.c3b",
|
||||
"Sprite3DTest/ReskinGirl.c3b", "Sprite3DTest/ReskinGirl.c3b",
|
||||
"MeshRendererTest/ReskinGirl.c3b", "MeshRendererTest/ReskinGirl.c3b", "MeshRendererTest/ReskinGirl.c3b",
|
||||
"MeshRendererTest/ReskinGirl.c3b", "MeshRendererTest/ReskinGirl.c3b", "MeshRendererTest/ReskinGirl.c3b",
|
||||
"MeshRendererTest/ReskinGirl.c3b", "MeshRendererTest/ReskinGirl.c3b",
|
||||
};
|
||||
|
||||
const int totalNames = sizeof(names) / sizeof(names[0]);
|
||||
|
@ -89,14 +89,14 @@ void Material_MultipleSprite3D::onEnter()
|
|||
|
||||
for (int i = 0; i < totalNames; i++)
|
||||
{
|
||||
auto sprite = Sprite3D::create(names[i]);
|
||||
this->addChild(sprite);
|
||||
sprite->setPosition(Vec2((size.width / (totalNames + 1)) * (i + 1), size.height / 4));
|
||||
sprite->setScale(3);
|
||||
auto mesh = MeshRenderer::create(names[i]);
|
||||
this->addChild(mesh);
|
||||
mesh->setPosition(Vec2((size.width / (totalNames + 1)) * (i + 1), size.height / 4));
|
||||
mesh->setScale(3);
|
||||
}
|
||||
}
|
||||
|
||||
std::string Material_MultipleSprite3D::subtitle() const
|
||||
std::string Material_MultipleMeshRenderer::subtitle() const
|
||||
{
|
||||
return "Sprites with multiple meshes";
|
||||
}
|
||||
|
@ -115,40 +115,40 @@ void Material_2DEffects::onEnter()
|
|||
|
||||
Material* mat1 = Material::createWithProperties(properties);
|
||||
|
||||
auto spriteBlur = Sprite::create("Images/grossini.png");
|
||||
spriteBlur->setPositionNormalized(Vec2(0.2f, 0.5f));
|
||||
this->addChild(spriteBlur);
|
||||
spriteBlur->setProgramState(mat1->getTechniqueByName("blur")->getPassByIndex(0)->getProgramState());
|
||||
auto meshBlur = Sprite::create("Images/grossini.png");
|
||||
meshBlur->setPositionNormalized(Vec2(0.2f, 0.5f));
|
||||
this->addChild(meshBlur);
|
||||
meshBlur->setProgramState(mat1->getTechniqueByName("blur")->getPassByIndex(0)->getProgramState());
|
||||
|
||||
auto spriteOutline = Sprite::create("Images/grossini.png");
|
||||
spriteOutline->setPositionNormalized(Vec2(0.4f, 0.5f));
|
||||
this->addChild(spriteOutline);
|
||||
spriteOutline->setProgramState(mat1->getTechniqueByName("outline")->getPassByIndex(0)->getProgramState());
|
||||
auto meshOutline = Sprite::create("Images/grossini.png");
|
||||
meshOutline->setPositionNormalized(Vec2(0.4f, 0.5f));
|
||||
this->addChild(meshOutline);
|
||||
meshOutline->setProgramState(mat1->getTechniqueByName("outline")->getPassByIndex(0)->getProgramState());
|
||||
|
||||
auto spriteNoise = Sprite::create("Images/grossini.png");
|
||||
spriteNoise->setPositionNormalized(Vec2(0.6f, 0.5f));
|
||||
this->addChild(spriteNoise);
|
||||
spriteNoise->setProgramState(mat1->getTechniqueByName("noise")->getPassByIndex(0)->getProgramState());
|
||||
auto meshNoise = Sprite::create("Images/grossini.png");
|
||||
meshNoise->setPositionNormalized(Vec2(0.6f, 0.5f));
|
||||
this->addChild(meshNoise);
|
||||
meshNoise->setProgramState(mat1->getTechniqueByName("noise")->getPassByIndex(0)->getProgramState());
|
||||
|
||||
auto spriteEdgeDetect = Sprite::create("Images/grossini.png");
|
||||
spriteEdgeDetect->setPositionNormalized(Vec2(0.8f, 0.5f));
|
||||
this->addChild(spriteEdgeDetect);
|
||||
spriteEdgeDetect->setProgramState(mat1->getTechniqueByName("edge_detect")->getPassByIndex(0)->getProgramState());
|
||||
auto meshEdgeDetect = Sprite::create("Images/grossini.png");
|
||||
meshEdgeDetect->setPositionNormalized(Vec2(0.8f, 0.5f));
|
||||
this->addChild(meshEdgeDetect);
|
||||
meshEdgeDetect->setProgramState(mat1->getTechniqueByName("edge_detect")->getPassByIndex(0)->getProgramState());
|
||||
|
||||
timeUniforms.clear();
|
||||
|
||||
#define FETCH_CCTIME_LOCATION(sprite) \
|
||||
#define FETCH_CCTIME_LOCATION(mesh) \
|
||||
do \
|
||||
{ \
|
||||
auto programState = sprite->getProgramState(); \
|
||||
auto programState = mesh->getProgramState(); \
|
||||
auto location = programState->getUniformLocation("u_Time"); \
|
||||
timeUniforms.emplace_back(programState, location); \
|
||||
} while (0)
|
||||
|
||||
FETCH_CCTIME_LOCATION(spriteBlur);
|
||||
FETCH_CCTIME_LOCATION(spriteOutline);
|
||||
FETCH_CCTIME_LOCATION(spriteNoise);
|
||||
FETCH_CCTIME_LOCATION(spriteEdgeDetect);
|
||||
FETCH_CCTIME_LOCATION(meshBlur);
|
||||
FETCH_CCTIME_LOCATION(meshOutline);
|
||||
FETCH_CCTIME_LOCATION(meshNoise);
|
||||
FETCH_CCTIME_LOCATION(meshEdgeDetect);
|
||||
|
||||
schedule(CC_SCHEDULE_SELECTOR(Material_2DEffects::updateCCTimeUniforms));
|
||||
|
||||
|
@ -245,27 +245,27 @@ void Material_AutoBindings::onEnter()
|
|||
|
||||
Material* mat1 = Material::createWithProperties(properties);
|
||||
|
||||
auto spriteBlur = Sprite::create("Images/grossini.png");
|
||||
spriteBlur->setPositionNormalized(Vec2(0.2f, 0.5f));
|
||||
this->addChild(spriteBlur);
|
||||
spriteBlur->setProgramState(mat1->getTechniqueByName("blur")->getPassByIndex(0)->getProgramState());
|
||||
auto meshBlur = Sprite::create("Images/grossini.png");
|
||||
meshBlur->setPositionNormalized(Vec2(0.2f, 0.5f));
|
||||
this->addChild(meshBlur);
|
||||
meshBlur->setProgramState(mat1->getTechniqueByName("blur")->getPassByIndex(0)->getProgramState());
|
||||
|
||||
auto spriteOutline = Sprite::create("Images/grossini.png");
|
||||
spriteOutline->setPositionNormalized(Vec2(0.4f, 0.5f));
|
||||
this->addChild(spriteOutline);
|
||||
spriteOutline->setProgramState(mat1->getTechniqueByName("outline")->getPassByIndex(0)->getProgramState());
|
||||
auto meshOutline = Sprite::create("Images/grossini.png");
|
||||
meshOutline->setPositionNormalized(Vec2(0.4f, 0.5f));
|
||||
this->addChild(meshOutline);
|
||||
meshOutline->setProgramState(mat1->getTechniqueByName("outline")->getPassByIndex(0)->getProgramState());
|
||||
|
||||
auto spriteNoise = Sprite::create("Images/grossini.png");
|
||||
spriteNoise->setPositionNormalized(Vec2(0.6f, 0.5f));
|
||||
this->addChild(spriteNoise);
|
||||
spriteNoise->setProgramState(mat1->getTechniqueByName("noise")->getPassByIndex(0)->getProgramState());
|
||||
auto meshNoise = Sprite::create("Images/grossini.png");
|
||||
meshNoise->setPositionNormalized(Vec2(0.6f, 0.5f));
|
||||
this->addChild(meshNoise);
|
||||
meshNoise->setProgramState(mat1->getTechniqueByName("noise")->getPassByIndex(0)->getProgramState());
|
||||
|
||||
auto spriteEdgeDetect = Sprite::create("Images/grossini.png");
|
||||
spriteEdgeDetect->setPositionNormalized(Vec2(0.8f, 0.5f));
|
||||
this->addChild(spriteEdgeDetect);
|
||||
spriteEdgeDetect->setProgramState(mat1->getTechniqueByName("edge_detect")->getPassByIndex(0)->getProgramState());
|
||||
auto meshEdgeDetect = Sprite::create("Images/grossini.png");
|
||||
meshEdgeDetect->setPositionNormalized(Vec2(0.8f, 0.5f));
|
||||
this->addChild(meshEdgeDetect);
|
||||
meshEdgeDetect->setProgramState(mat1->getTechniqueByName("edge_detect")->getPassByIndex(0)->getProgramState());
|
||||
|
||||
_noiseProgramState = spriteNoise->getProgramState();
|
||||
_noiseProgramState = meshNoise->getProgramState();
|
||||
_locationTime = _noiseProgramState->getUniformLocation("u_Time");
|
||||
|
||||
schedule(CC_SCHEDULE_SELECTOR(Material_AutoBindings::updateUniformTime));
|
||||
|
@ -292,14 +292,14 @@ void Material_setTechnique::onEnter()
|
|||
{
|
||||
MaterialSystemBaseTest::onEnter();
|
||||
|
||||
auto sprite = Sprite3D::create("Sprite3DTest/boss1.obj");
|
||||
sprite->setScale(6);
|
||||
this->addChild(sprite);
|
||||
sprite->setPositionNormalized(Vec2(0.5f, 0.5f));
|
||||
_sprite = sprite;
|
||||
auto mesh = MeshRenderer::create("MeshRendererTest/boss1.obj");
|
||||
mesh->setScale(6);
|
||||
this->addChild(mesh);
|
||||
mesh->setPositionNormalized(Vec2(0.5f, 0.5f));
|
||||
_mesh = mesh;
|
||||
|
||||
Material* mat = Material::createWithFilename("Materials/3d_effects.material");
|
||||
sprite->setMaterial(mat);
|
||||
mesh->setMaterial(mat);
|
||||
|
||||
// lights
|
||||
auto light1 = AmbientLight::create(Color3B::RED);
|
||||
|
@ -313,7 +313,7 @@ void Material_setTechnique::onEnter()
|
|||
|
||||
auto rot = RotateBy::create(5, Vec3(30.0f, 60.0f, 270.0f));
|
||||
auto repeat = RepeatForever::create(rot);
|
||||
sprite->runAction(repeat);
|
||||
mesh->runAction(repeat);
|
||||
}
|
||||
|
||||
std::string Material_setTechnique::subtitle() const
|
||||
|
@ -327,13 +327,13 @@ void Material_setTechnique::changeMaterial(float dt)
|
|||
switch (_techniqueState)
|
||||
{
|
||||
case 0:
|
||||
_sprite->getMaterial(0)->setTechnique("lit");
|
||||
_mesh->getMaterial(0)->setTechnique("lit");
|
||||
break;
|
||||
case 1:
|
||||
_sprite->getMaterial(0)->setTechnique("normal");
|
||||
_mesh->getMaterial(0)->setTechnique("normal");
|
||||
break;
|
||||
case 2:
|
||||
_sprite->getMaterial(0)->setTechnique("outline");
|
||||
_mesh->getMaterial(0)->setTechnique("outline");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -349,40 +349,40 @@ void Material_clone::onEnter()
|
|||
{
|
||||
MaterialSystemBaseTest::onEnter();
|
||||
|
||||
auto sprite = Sprite3D::create("Sprite3DTest/boss1.obj");
|
||||
sprite->setScale(3);
|
||||
this->addChild(sprite);
|
||||
sprite->setPositionNormalized(Vec2(0.25f, 0.5f));
|
||||
auto mesh = MeshRenderer::create("MeshRendererTest/boss1.obj");
|
||||
mesh->setScale(3);
|
||||
this->addChild(mesh);
|
||||
mesh->setPositionNormalized(Vec2(0.25f, 0.5f));
|
||||
|
||||
Material* mat = Material::createWithFilename("Materials/3d_effects.material");
|
||||
sprite->setMaterial(mat);
|
||||
mesh->setMaterial(mat);
|
||||
|
||||
auto rot = RotateBy::create(5, Vec3(360.0f, 240.0f, 120.0f));
|
||||
auto repeat = RepeatForever::create(rot);
|
||||
sprite->runAction(repeat);
|
||||
mesh->runAction(repeat);
|
||||
|
||||
// sprite 2... using same material
|
||||
auto sprite2 = Sprite3D::create("Sprite3DTest/boss1.obj");
|
||||
sprite2->setScale(3);
|
||||
this->addChild(sprite2);
|
||||
sprite2->setPositionNormalized(Vec2(0.5f, 0.5f));
|
||||
sprite2->setMaterial(mat);
|
||||
sprite2->runAction(repeat->clone());
|
||||
// mesh 2... using same material
|
||||
auto mesh2 = MeshRenderer::create("MeshRendererTest/boss1.obj");
|
||||
mesh2->setScale(3);
|
||||
this->addChild(mesh2);
|
||||
mesh2->setPositionNormalized(Vec2(0.5f, 0.5f));
|
||||
mesh2->setMaterial(mat);
|
||||
mesh2->runAction(repeat->clone());
|
||||
|
||||
// sprite 3... using cloned material
|
||||
auto sprite3 = Sprite3D::create("Sprite3DTest/boss1.obj");
|
||||
sprite3->setScale(3);
|
||||
this->addChild(sprite3);
|
||||
sprite3->setPositionNormalized(Vec2(0.75f, 0.5f));
|
||||
// mesh 3... using cloned material
|
||||
auto mesh3 = MeshRenderer::create("MeshRendererTest/boss1.obj");
|
||||
mesh3->setScale(3);
|
||||
this->addChild(mesh3);
|
||||
mesh3->setPositionNormalized(Vec2(0.75f, 0.5f));
|
||||
auto mat2 = mat->clone();
|
||||
sprite3->setMaterial(mat2);
|
||||
sprite3->runAction(repeat->clone());
|
||||
mesh3->setMaterial(mat2);
|
||||
mesh3->runAction(repeat->clone());
|
||||
|
||||
// testing clone
|
||||
// should affect both sprite 1 and sprite 2
|
||||
// should affect both mesh 1 and mesh 2
|
||||
mat->setTechnique("outline");
|
||||
|
||||
// should affect only sprite 3
|
||||
// should affect only mesh 3
|
||||
// mat2->setTechnique("normal");
|
||||
}
|
||||
|
||||
|
|
|
@ -39,19 +39,19 @@ public:
|
|||
virtual std::string title() const override;
|
||||
};
|
||||
|
||||
class Material_Sprite3DTest : public MaterialSystemBaseTest
|
||||
class Material_MeshRendererTest : public MaterialSystemBaseTest
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(Material_Sprite3DTest);
|
||||
CREATE_FUNC(Material_MeshRendererTest);
|
||||
|
||||
virtual void onEnter() override;
|
||||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
||||
class Material_MultipleSprite3D : public MaterialSystemBaseTest
|
||||
class Material_MultipleMeshRenderer : public MaterialSystemBaseTest
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(Material_MultipleSprite3D);
|
||||
CREATE_FUNC(Material_MultipleMeshRenderer);
|
||||
|
||||
virtual void onEnter() override;
|
||||
virtual std::string subtitle() const override;
|
||||
|
@ -110,7 +110,7 @@ public:
|
|||
private:
|
||||
void changeMaterial(float dt);
|
||||
|
||||
cocos2d::Sprite3D* _sprite;
|
||||
cocos2d::MeshRenderer* _mesh;
|
||||
int _techniqueState;
|
||||
};
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -31,7 +31,7 @@
|
|||
namespace cocos2d
|
||||
{
|
||||
class Animate3D;
|
||||
class Sprite3D;
|
||||
class MeshRenderer;
|
||||
class Delay;
|
||||
class Ray;
|
||||
class DrawNode3D;
|
||||
|
@ -39,53 +39,53 @@ class GLProgramState;
|
|||
class MotionStreak3D;
|
||||
} // namespace cocos2d
|
||||
|
||||
DEFINE_TEST_SUITE(Sprite3DTests);
|
||||
DEFINE_TEST_SUITE(MeshRendererTests);
|
||||
|
||||
class Sprite3DTestDemo : public TestCase
|
||||
class MeshRendererTestDemo : public TestCase
|
||||
{
|
||||
public:
|
||||
// overrides
|
||||
virtual std::string title() const override;
|
||||
|
||||
virtual ~Sprite3DTestDemo();
|
||||
virtual ~MeshRendererTestDemo();
|
||||
};
|
||||
|
||||
class Sprite3DForceDepthTest : public Sprite3DTestDemo
|
||||
class MeshRendererForceDepthTest : public MeshRendererTestDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(Sprite3DForceDepthTest);
|
||||
Sprite3DForceDepthTest();
|
||||
CREATE_FUNC(MeshRendererForceDepthTest);
|
||||
MeshRendererForceDepthTest();
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
||||
class Sprite3DEmptyTest : public Sprite3DTestDemo
|
||||
class MeshRendererEmptyTest : public MeshRendererTestDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(Sprite3DEmptyTest);
|
||||
Sprite3DEmptyTest();
|
||||
CREATE_FUNC(MeshRendererEmptyTest);
|
||||
MeshRendererEmptyTest();
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
||||
class Sprite3DBasicTest : public Sprite3DTestDemo
|
||||
class MeshRendererBasicTest : public MeshRendererTestDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(Sprite3DBasicTest);
|
||||
Sprite3DBasicTest();
|
||||
CREATE_FUNC(MeshRendererBasicTest);
|
||||
MeshRendererBasicTest();
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
|
||||
void addNewSpriteWithCoords(cocos2d::Vec2 p);
|
||||
void addNewMeshWithCoords(cocos2d::Vec2 p);
|
||||
void onTouchesEnded(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event* event);
|
||||
};
|
||||
|
||||
class Sprite3DUVAnimationTest : public Sprite3DTestDemo
|
||||
class MeshRendererUVAnimationTest : public MeshRendererTestDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(Sprite3DUVAnimationTest);
|
||||
Sprite3DUVAnimationTest();
|
||||
virtual ~Sprite3DUVAnimationTest();
|
||||
CREATE_FUNC(MeshRendererUVAnimationTest);
|
||||
MeshRendererUVAnimationTest();
|
||||
virtual ~MeshRendererUVAnimationTest();
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
|
||||
|
@ -101,7 +101,7 @@ protected:
|
|||
#endif
|
||||
};
|
||||
|
||||
class Sprite3DFakeShadowTest : public Sprite3DTestDemo
|
||||
class MeshRendererFakeShadowTest : public MeshRendererTestDemo
|
||||
{
|
||||
public:
|
||||
enum State
|
||||
|
@ -111,9 +111,9 @@ public:
|
|||
State_Move = 0x02,
|
||||
State_Rotate = 0x04
|
||||
};
|
||||
CREATE_FUNC(Sprite3DFakeShadowTest);
|
||||
Sprite3DFakeShadowTest();
|
||||
virtual ~Sprite3DFakeShadowTest();
|
||||
CREATE_FUNC(MeshRendererFakeShadowTest);
|
||||
MeshRendererFakeShadowTest();
|
||||
virtual ~MeshRendererFakeShadowTest();
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
void Move(cocos2d::Ref* sender, int value);
|
||||
|
@ -129,8 +129,8 @@ private:
|
|||
cocos2d::Camera* _camera;
|
||||
cocos2d::Vec3 _targetPos;
|
||||
unsigned int _curState;
|
||||
cocos2d::Sprite3D* _plane;
|
||||
cocos2d::Sprite3D* _orc;
|
||||
cocos2d::MeshRenderer* _plane;
|
||||
cocos2d::MeshRenderer* _orc;
|
||||
cocos2d::backend::ProgramState* _state = nullptr;
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
|
@ -138,12 +138,12 @@ private:
|
|||
#endif
|
||||
};
|
||||
|
||||
class Sprite3DLightMapTest : public Sprite3DTestDemo
|
||||
class MeshRendererLightMapTest : public MeshRendererTestDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(Sprite3DLightMapTest);
|
||||
Sprite3DLightMapTest();
|
||||
virtual ~Sprite3DLightMapTest();
|
||||
CREATE_FUNC(MeshRendererLightMapTest);
|
||||
MeshRendererLightMapTest();
|
||||
virtual ~MeshRendererLightMapTest();
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
void onTouchesMoved(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event* event);
|
||||
|
@ -152,12 +152,12 @@ private:
|
|||
cocos2d::Camera* _camera;
|
||||
};
|
||||
|
||||
class Sprite3DBasicToonShaderTest : public Sprite3DTestDemo
|
||||
class MeshRendererBasicToonShaderTest : public MeshRendererTestDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(Sprite3DBasicToonShaderTest);
|
||||
Sprite3DBasicToonShaderTest();
|
||||
virtual ~Sprite3DBasicToonShaderTest();
|
||||
CREATE_FUNC(MeshRendererBasicToonShaderTest);
|
||||
MeshRendererBasicToonShaderTest();
|
||||
virtual ~MeshRendererBasicToonShaderTest();
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
|
||||
|
@ -169,62 +169,62 @@ protected:
|
|||
#endif
|
||||
};
|
||||
|
||||
class Sprite3DHitTest : public Sprite3DTestDemo
|
||||
class MeshRendererHitTest : public MeshRendererTestDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(Sprite3DHitTest);
|
||||
Sprite3DHitTest();
|
||||
CREATE_FUNC(MeshRendererHitTest);
|
||||
MeshRendererHitTest();
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
||||
class Sprite3DEffectTest : public Sprite3DTestDemo
|
||||
class MeshRendererEffectTest : public MeshRendererTestDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(Sprite3DEffectTest);
|
||||
Sprite3DEffectTest();
|
||||
virtual ~Sprite3DEffectTest();
|
||||
CREATE_FUNC(MeshRendererEffectTest);
|
||||
MeshRendererEffectTest();
|
||||
virtual ~MeshRendererEffectTest();
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
|
||||
void addNewSpriteWithCoords(cocos2d::Vec2 p);
|
||||
void addNewMeshWithCoords(cocos2d::Vec2 p);
|
||||
|
||||
void onTouchesEnded(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event* event);
|
||||
|
||||
protected:
|
||||
std::vector<cocos2d::Sprite3D*> _sprites;
|
||||
std::vector<cocos2d::MeshRenderer*> _meshes;
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
cocos2d::EventListenerCustom* _backToForegroundListener;
|
||||
#endif
|
||||
};
|
||||
|
||||
class AsyncLoadSprite3DTest : public Sprite3DTestDemo
|
||||
class AsyncLoadMeshRendererTest : public MeshRendererTestDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(AsyncLoadSprite3DTest);
|
||||
AsyncLoadSprite3DTest();
|
||||
virtual ~AsyncLoadSprite3DTest();
|
||||
CREATE_FUNC(AsyncLoadMeshRendererTest);
|
||||
AsyncLoadMeshRendererTest();
|
||||
virtual ~AsyncLoadMeshRendererTest();
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
|
||||
void menuCallback_asyncLoadSprite(cocos2d::Ref* sender);
|
||||
void menuCallback_asyncLoadMesh(cocos2d::Ref* sender);
|
||||
|
||||
void asyncLoad_Callback(cocos2d::Sprite3D* sprite, void* param);
|
||||
void asyncLoad_Callback(cocos2d::MeshRenderer* mesh, void* param);
|
||||
|
||||
protected:
|
||||
std::vector<std::string> _paths; // model paths to be loaded
|
||||
};
|
||||
|
||||
class Sprite3DWithSkinTest : public Sprite3DTestDemo
|
||||
class MeshRendererWithSkinTest : public MeshRendererTestDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(Sprite3DWithSkinTest);
|
||||
Sprite3DWithSkinTest();
|
||||
CREATE_FUNC(MeshRendererWithSkinTest);
|
||||
MeshRendererWithSkinTest();
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
|
||||
void addNewSpriteWithCoords(cocos2d::Vec2 p);
|
||||
void addNewMeshWithCoords(cocos2d::Vec2 p);
|
||||
|
||||
void switchAnimationQualityCallback(cocos2d::Ref* sender);
|
||||
void onTouchesEnded(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event* event);
|
||||
|
@ -232,33 +232,33 @@ public:
|
|||
std::string getAnimationQualityMessage() const;
|
||||
|
||||
private:
|
||||
std::vector<cocos2d::Sprite3D*> _sprits;
|
||||
std::vector<cocos2d::MeshRenderer*> _meshes;
|
||||
int _animateQuality;
|
||||
cocos2d::MenuItemFont* _menuItem;
|
||||
};
|
||||
|
||||
class Sprite3DWithSkinOutlineTest : public Sprite3DTestDemo
|
||||
class MeshRendererWithSkinOutlineTest : public MeshRendererTestDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(Sprite3DWithSkinOutlineTest);
|
||||
Sprite3DWithSkinOutlineTest();
|
||||
virtual ~Sprite3DWithSkinOutlineTest();
|
||||
CREATE_FUNC(MeshRendererWithSkinOutlineTest);
|
||||
MeshRendererWithSkinOutlineTest();
|
||||
virtual ~MeshRendererWithSkinOutlineTest();
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
|
||||
void addNewSpriteWithCoords(cocos2d::Vec2 p);
|
||||
void addNewMeshWithCoords(cocos2d::Vec2 p);
|
||||
|
||||
void onTouchesEnded(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event* event);
|
||||
|
||||
protected:
|
||||
std::vector<cocos2d::Sprite3D*> _sprites;
|
||||
std::vector<cocos2d::MeshRenderer*> _meshes;
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
cocos2d::EventListenerCustom* _backToForegroundListener;
|
||||
#endif
|
||||
};
|
||||
|
||||
class Animate3DTest : public Sprite3DTestDemo
|
||||
class Animate3DTest : public MeshRendererTestDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(Animate3DTest);
|
||||
|
@ -272,7 +272,7 @@ public:
|
|||
virtual void update(float dt) override;
|
||||
|
||||
protected:
|
||||
void addSprite3D();
|
||||
void addMeshRenderer();
|
||||
|
||||
enum class State
|
||||
{
|
||||
|
@ -286,7 +286,7 @@ protected:
|
|||
|
||||
void renewCallBack();
|
||||
|
||||
cocos2d::Sprite3D* _sprite;
|
||||
cocos2d::MeshRenderer* _mesh;
|
||||
|
||||
cocos2d::Action* _swim;
|
||||
cocos2d::Animate3D* _hurt;
|
||||
|
@ -298,7 +298,7 @@ protected:
|
|||
cocos2d::MoveTo* _moveAction;
|
||||
};
|
||||
|
||||
class AttachmentTest : public Sprite3DTestDemo
|
||||
class AttachmentTest : public MeshRendererTestDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(AttachmentTest);
|
||||
|
@ -308,22 +308,22 @@ public:
|
|||
|
||||
void onTouchesEnded(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event* event);
|
||||
|
||||
void addNewSpriteWithCoords(cocos2d::Vec2 p);
|
||||
void addNewMeshWithCoords(cocos2d::Vec2 p);
|
||||
|
||||
protected:
|
||||
bool _hasWeapon;
|
||||
cocos2d::Sprite3D* _sprite;
|
||||
cocos2d::MeshRenderer* _mesh;
|
||||
};
|
||||
|
||||
class Sprite3DReskinTest : public Sprite3DTestDemo
|
||||
class MeshRendererReskinTest : public MeshRendererTestDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(Sprite3DReskinTest);
|
||||
Sprite3DReskinTest();
|
||||
CREATE_FUNC(MeshRendererReskinTest);
|
||||
MeshRendererReskinTest();
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
void onTouchesEnded(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event* event);
|
||||
void addNewSpriteWithCoords(cocos2d::Vec2 p);
|
||||
void addNewMeshWithCoords(cocos2d::Vec2 p);
|
||||
|
||||
void menuCallback_reSkin(cocos2d::Ref* sender);
|
||||
|
||||
|
@ -344,19 +344,19 @@ protected:
|
|||
|
||||
std::vector<std::string> _skins[(int)SkinType::MAX_TYPE]; // all skins
|
||||
int _curSkin[(int)SkinType::MAX_TYPE]; // current skin index
|
||||
cocos2d::Sprite3D* _sprite;
|
||||
cocos2d::MeshRenderer* _mesh;
|
||||
};
|
||||
|
||||
class Sprite3DWithOBBPerformanceTest : public Sprite3DTestDemo
|
||||
class MeshRendererWithOBBPerformanceTest : public MeshRendererTestDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(Sprite3DWithOBBPerformanceTest);
|
||||
Sprite3DWithOBBPerformanceTest();
|
||||
CREATE_FUNC(MeshRendererWithOBBPerformanceTest);
|
||||
MeshRendererWithOBBPerformanceTest();
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
virtual void update(float dt) override;
|
||||
void addNewOBBWithCoords(cocos2d::Vec2 p);
|
||||
void addNewSpriteWithCoords(cocos2d::Vec2 p);
|
||||
void addNewMeshWithCoords(cocos2d::Vec2 p);
|
||||
void onTouchesBegan(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event* event);
|
||||
void onTouchesEnded(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event* event);
|
||||
void onTouchesMoved(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event* event);
|
||||
|
@ -366,7 +366,7 @@ public:
|
|||
void delOBBWithCount(float value);
|
||||
|
||||
protected:
|
||||
cocos2d::Sprite3D* _sprite;
|
||||
cocos2d::MeshRenderer* _mesh;
|
||||
std::vector<cocos2d::OBB> _obb;
|
||||
cocos2d::DrawNode3D* _drawOBB;
|
||||
cocos2d::Label* _labelCubeCount;
|
||||
|
@ -386,23 +386,23 @@ protected:
|
|||
void calculateRayByLocationInView(cocos2d::Ray* ray, const cocos2d::Vec2& location);
|
||||
};
|
||||
|
||||
class Sprite3DMirrorTest : public Sprite3DTestDemo
|
||||
class MeshRendererMirrorTest : public MeshRendererTestDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(Sprite3DMirrorTest);
|
||||
Sprite3DMirrorTest();
|
||||
CREATE_FUNC(MeshRendererMirrorTest);
|
||||
MeshRendererMirrorTest();
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
|
||||
void addNewSpriteWithCoords(cocos2d::Vec2 p);
|
||||
void addNewMeshWithCoords(cocos2d::Vec2 p);
|
||||
|
||||
protected:
|
||||
bool _hasWeapon;
|
||||
cocos2d::Sprite3D* _sprite;
|
||||
cocos2d::Sprite3D* _mirrorSprite;
|
||||
cocos2d::MeshRenderer* _mesh;
|
||||
cocos2d::MeshRenderer* _mirrorMesh;
|
||||
};
|
||||
|
||||
class QuaternionTest : public Sprite3DTestDemo
|
||||
class QuaternionTest : public MeshRendererTestDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(QuaternionTest);
|
||||
|
@ -410,22 +410,22 @@ public:
|
|||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
|
||||
void addNewSpriteWithCoords(cocos2d::Vec2 p);
|
||||
void addNewMeshWithCoords(cocos2d::Vec2 p);
|
||||
virtual void update(float delta) override;
|
||||
|
||||
protected:
|
||||
cocos2d::Sprite3D* _sprite;
|
||||
cocos2d::MeshRenderer* _mesh;
|
||||
float _arcSpeed;
|
||||
float _radius;
|
||||
float _accAngle;
|
||||
};
|
||||
|
||||
// 3d + 2d use case
|
||||
class UseCaseSprite3D : public Sprite3DTestDemo
|
||||
class UseCaseMeshRenderer : public MeshRendererTestDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(UseCaseSprite3D);
|
||||
UseCaseSprite3D();
|
||||
CREATE_FUNC(UseCaseMeshRenderer);
|
||||
UseCaseMeshRenderer();
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
|
||||
|
@ -448,7 +448,7 @@ protected:
|
|||
};
|
||||
|
||||
// node animation test, cocos2d-x supports both skeletal animation and node animation
|
||||
class NodeAnimationTest : public Sprite3DTestDemo
|
||||
class NodeAnimationTest : public MeshRendererTestDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(NodeAnimationTest);
|
||||
|
@ -456,10 +456,10 @@ public:
|
|||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
|
||||
void addNewSpriteWithCoords(cocos2d::Vec2 p);
|
||||
void addNewMeshWithCoords(cocos2d::Vec2 p);
|
||||
|
||||
protected:
|
||||
std::vector<cocos2d::Sprite3D*> _sprites;
|
||||
std::vector<cocos2d::MeshRenderer*> _meshes;
|
||||
int _vectorIndex;
|
||||
};
|
||||
|
||||
|
@ -469,23 +469,23 @@ class TextureCube;
|
|||
class Skybox;
|
||||
} // namespace cocos2d
|
||||
|
||||
class Sprite3DCubeMapTest : public Sprite3DTestDemo
|
||||
class MeshRendererCubeMapTest : public MeshRendererTestDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(Sprite3DCubeMapTest);
|
||||
Sprite3DCubeMapTest();
|
||||
~Sprite3DCubeMapTest();
|
||||
CREATE_FUNC(MeshRendererCubeMapTest);
|
||||
MeshRendererCubeMapTest();
|
||||
~MeshRendererCubeMapTest();
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
|
||||
void addNewSpriteWithCoords(cocos2d::Vec2);
|
||||
void addNewMeshWithCoords(cocos2d::Vec2);
|
||||
|
||||
void onTouchesMoved(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event* event);
|
||||
|
||||
protected:
|
||||
cocos2d::TextureCube* _textureCube;
|
||||
cocos2d::Skybox* _skyBox;
|
||||
cocos2d::Sprite3D* _teapot;
|
||||
cocos2d::MeshRenderer* _teapot;
|
||||
cocos2d::Camera* _camera;
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
|
@ -494,7 +494,7 @@ protected:
|
|||
};
|
||||
|
||||
/// issue 9767 setGLProgram
|
||||
class Issue9767 : public Sprite3DTestDemo
|
||||
class Issue9767 : public MeshRendererTestDemo
|
||||
{
|
||||
enum class ShaderType
|
||||
{
|
||||
|
@ -513,21 +513,21 @@ public:
|
|||
|
||||
protected:
|
||||
ShaderType _shaderType;
|
||||
cocos2d::Sprite3D* _sprite;
|
||||
cocos2d::MeshRenderer* _mesh;
|
||||
};
|
||||
|
||||
/// Clipping Sprite3D
|
||||
class Sprite3DClippingTest : public Sprite3DTestDemo
|
||||
/// Clipping MeshRenderer
|
||||
class MeshRendererClippingTest : public MeshRendererTestDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(Sprite3DClippingTest);
|
||||
Sprite3DClippingTest();
|
||||
~Sprite3DClippingTest();
|
||||
CREATE_FUNC(MeshRendererClippingTest);
|
||||
MeshRendererClippingTest();
|
||||
~MeshRendererClippingTest();
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
||||
class Animate3DCallbackTest : public Sprite3DTestDemo
|
||||
class Animate3DCallbackTest : public MeshRendererTestDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(Animate3DCallbackTest);
|
||||
|
@ -537,10 +537,10 @@ public:
|
|||
virtual std::string subtitle() const override;
|
||||
|
||||
protected:
|
||||
cocos2d::Sprite3D* _sprite3d;
|
||||
cocos2d::MeshRenderer* _meshRenderer;
|
||||
};
|
||||
|
||||
class CameraBackgroundClearTest : public Sprite3DTestDemo
|
||||
class CameraBackgroundClearTest : public MeshRendererTestDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(CameraBackgroundClearTest);
|
||||
|
@ -555,24 +555,24 @@ protected:
|
|||
cocos2d::Label* _label;
|
||||
};
|
||||
|
||||
class Sprite3DVertexColorTest : public Sprite3DTestDemo
|
||||
class MeshRendererVertexColorTest : public MeshRendererTestDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(Sprite3DVertexColorTest);
|
||||
Sprite3DVertexColorTest();
|
||||
CREATE_FUNC(MeshRendererVertexColorTest);
|
||||
MeshRendererVertexColorTest();
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
|
||||
virtual ~Sprite3DVertexColorTest();
|
||||
virtual ~MeshRendererVertexColorTest();
|
||||
|
||||
protected:
|
||||
cocos2d::Sprite3D* _sprite;
|
||||
cocos2d::MeshRenderer* _mesh;
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
||||
cocos2d::EventListenerCustom* _backToForegroundListener;
|
||||
#endif
|
||||
};
|
||||
|
||||
class MotionStreak3DTest : public Sprite3DTestDemo
|
||||
class MotionStreak3DTest : public MeshRendererTestDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(MotionStreak3DTest);
|
||||
|
@ -582,27 +582,27 @@ public:
|
|||
virtual void update(float delta) override;
|
||||
|
||||
protected:
|
||||
cocos2d::Sprite3D* _sprite;
|
||||
cocos2d::MeshRenderer* _mesh;
|
||||
cocos2d::MotionStreak3D* _streak;
|
||||
};
|
||||
|
||||
class Sprite3DNormalMappingTest : public Sprite3DTestDemo
|
||||
class MeshRendererNormalMappingTest : public MeshRendererTestDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(Sprite3DNormalMappingTest);
|
||||
Sprite3DNormalMappingTest();
|
||||
CREATE_FUNC(MeshRendererNormalMappingTest);
|
||||
MeshRendererNormalMappingTest();
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
virtual void update(float dt) override;
|
||||
|
||||
virtual ~Sprite3DNormalMappingTest();
|
||||
virtual ~MeshRendererNormalMappingTest();
|
||||
};
|
||||
|
||||
class Sprite3DPropertyTest : public Sprite3DTestDemo
|
||||
class MeshRendererPropertyTest : public MeshRendererTestDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(Sprite3DPropertyTest);
|
||||
Sprite3DPropertyTest();
|
||||
CREATE_FUNC(MeshRendererPropertyTest);
|
||||
MeshRendererPropertyTest();
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
virtual void update(float delta) override;
|
||||
|
@ -611,15 +611,15 @@ public:
|
|||
void removeUsedTexture(cocos2d::Ref* sender);
|
||||
void resetTexture(cocos2d::Ref* sender);
|
||||
|
||||
void refreshSpriteRender();
|
||||
void refreshMeshRender();
|
||||
|
||||
protected:
|
||||
cocos2d::Sprite3D* _sprite;
|
||||
cocos2d::MeshRenderer* _mesh;
|
||||
cocos2d::Texture2D* _meshTex;
|
||||
std::string _texFile;
|
||||
};
|
||||
|
||||
class Issue16155Test : public Sprite3DTestDemo
|
||||
class Issue16155Test : public MeshRendererTestDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(Issue16155Test);
|
|
@ -146,10 +146,10 @@ void NavMeshBaseTestDemo::initScene()
|
|||
rbDes.shape = Physics3DShape::createMesh(&trianglesList[0], (int)trianglesList.size() / 3);
|
||||
auto rigidBody = Physics3DRigidBody::create(&rbDes);
|
||||
auto component = Physics3DComponent::create(rigidBody);
|
||||
auto sprite = Sprite3D::create("NavMesh/scene.obj");
|
||||
sprite->addComponent(component);
|
||||
sprite->setCameraMask((unsigned short)CameraFlag::USER1);
|
||||
this->addChild(sprite);
|
||||
auto mesh = MeshRenderer::create("NavMesh/scene.obj");
|
||||
mesh->addComponent(component);
|
||||
mesh->setCameraMask((unsigned short)CameraFlag::USER1);
|
||||
this->addChild(mesh);
|
||||
setPhysics3DDebugCamera(_camera);
|
||||
|
||||
auto navMesh = NavMesh::create("NavMesh/all_tiles_tilecache.bin", "NavMesh/geomset.txt");
|
||||
|
@ -168,13 +168,13 @@ void NavMeshBaseTestDemo::initScene()
|
|||
|
||||
void NavMeshBaseTestDemo::createAgent(const Vec3& pos)
|
||||
{
|
||||
std::string filePath = "Sprite3DTest/girl.c3b";
|
||||
std::string filePath = "MeshRendererTest/girl.c3b";
|
||||
NavMeshAgentParam param;
|
||||
param.radius = 2.0f;
|
||||
param.height = 8.0f;
|
||||
param.maxSpeed = 8.0f;
|
||||
auto agent = NavMeshAgent::create(param);
|
||||
auto agentNode = Sprite3D::create(filePath);
|
||||
auto agentNode = MeshRenderer::create(filePath);
|
||||
agent->setOrientationRefAxes(Vec3(-1.0f, 0.0f, 1.0f));
|
||||
AgentUserData* data = new AgentUserData{0.0f};
|
||||
agent->setUserData(data);
|
||||
|
@ -201,7 +201,7 @@ void NavMeshBaseTestDemo::createAgent(const Vec3& pos)
|
|||
void NavMeshBaseTestDemo::createObstacle(const Vec3& pos)
|
||||
{
|
||||
auto obstacle = NavMeshObstacle::create(2.0f, 8.0f);
|
||||
auto obstacleNode = Sprite3D::create("Sprite3DTest/cylinder.c3b");
|
||||
auto obstacleNode = MeshRenderer::create("MeshRendererTest/cylinder.c3b");
|
||||
obstacleNode->setPosition3D(pos + Vec3(0.0f, -0.5f, 0.0f));
|
||||
obstacleNode->setRotation3D(Vec3(-90.0f, 0.0f, 0.0f));
|
||||
obstacleNode->setScale(0.3f);
|
||||
|
|
|
@ -48,7 +48,7 @@ Particle3DTests::Particle3DTests()
|
|||
ADD_TEST_CASE(Particle3DCanOfWormsDemo);
|
||||
ADD_TEST_CASE(Particle3DRibbonTrailDemo);
|
||||
ADD_TEST_CASE(Particle3DWeaponTrailDemo);
|
||||
ADD_TEST_CASE(Particle3DWithSprite3DDemo);
|
||||
ADD_TEST_CASE(Particle3DWithMeshRendererDemo);
|
||||
}
|
||||
|
||||
std::string Particle3DTestDemo::title() const
|
||||
|
@ -63,7 +63,7 @@ bool Particle3DTestDemo::init()
|
|||
|
||||
FileUtils::getInstance()->addSearchPath("Particle3D/materials");
|
||||
FileUtils::getInstance()->addSearchPath("Particle3D/scripts");
|
||||
FileUtils::getInstance()->addSearchPath("Sprite3DTest");
|
||||
FileUtils::getInstance()->addSearchPath("MeshRendererTest");
|
||||
// FileUtils::getInstance()->addSearchPath("Particle3D/textures");
|
||||
|
||||
Size size = Director::getInstance()->getWinSize();
|
||||
|
@ -427,18 +427,18 @@ bool Particle3DWeaponTrailDemo::init()
|
|||
return true;
|
||||
}
|
||||
|
||||
std::string Particle3DWithSprite3DDemo::subtitle() const
|
||||
std::string Particle3DWithMeshRendererDemo::subtitle() const
|
||||
{
|
||||
return "Particle3DWithSprite3D";
|
||||
return "Particle3DWithMeshRenderer";
|
||||
}
|
||||
|
||||
bool Particle3DWithSprite3DDemo::init()
|
||||
bool Particle3DWithMeshRendererDemo::init()
|
||||
{
|
||||
if (!Particle3DTestDemo::init())
|
||||
return false;
|
||||
|
||||
std::string c3bfileName = "Sprite3DTest/orc.c3b";
|
||||
auto sprite = Sprite3D::create(c3bfileName);
|
||||
std::string c3bfileName = "MeshRendererTest/orc.c3b";
|
||||
auto sprite = MeshRenderer::create(c3bfileName);
|
||||
this->addChild(sprite);
|
||||
sprite->setPosition3D(Vec3(-20.0f, 0.0f, 0.0f));
|
||||
sprite->setRotation3D(Vec3(0, 180, 0));
|
||||
|
|
|
@ -223,12 +223,12 @@ public:
|
|||
virtual bool init() override;
|
||||
};
|
||||
|
||||
class Particle3DWithSprite3DDemo : public Particle3DTestDemo
|
||||
class Particle3DWithMeshRendererDemo : public Particle3DTestDemo
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(Particle3DWithSprite3DDemo);
|
||||
Particle3DWithSprite3DDemo(){};
|
||||
virtual ~Particle3DWithSprite3DDemo(){};
|
||||
CREATE_FUNC(Particle3DWithMeshRendererDemo);
|
||||
Particle3DWithMeshRendererDemo(){};
|
||||
virtual ~Particle3DWithMeshRendererDemo(){};
|
||||
|
||||
virtual std::string subtitle() const override;
|
||||
|
||||
|
|
|
@ -196,25 +196,25 @@ void Physics3DTestDemo::shootBox(const cocos2d::Vec3& des)
|
|||
rbDes.originalTransform.translate(_camera->getPosition3D());
|
||||
rbDes.mass = 1.f;
|
||||
rbDes.shape = Physics3DShape::createBox(Vec3(0.5f, 0.5f, 0.5f));
|
||||
auto sprite = PhysicsSprite3D::create("Sprite3DTest/box.c3t", &rbDes);
|
||||
sprite->setTexture("Images/Icon.png");
|
||||
auto mesh = PhysicsMeshRenderer::create("MeshRendererTest/box.c3t", &rbDes);
|
||||
mesh->setTexture("Images/Icon.png");
|
||||
|
||||
auto rigidBody = static_cast<Physics3DRigidBody*>(sprite->getPhysicsObj());
|
||||
auto rigidBody = static_cast<Physics3DRigidBody*>(mesh->getPhysicsObj());
|
||||
rigidBody->setLinearFactor(Vec3::ONE);
|
||||
rigidBody->setLinearVelocity(linearVel);
|
||||
rigidBody->setAngularVelocity(Vec3::ZERO);
|
||||
rigidBody->setCcdMotionThreshold(0.5f);
|
||||
rigidBody->setCcdSweptSphereRadius(0.4f);
|
||||
|
||||
this->addChild(sprite);
|
||||
sprite->setPosition3D(_camera->getPosition3D());
|
||||
sprite->setScale(0.5f);
|
||||
sprite->syncNodeToPhysics();
|
||||
this->addChild(mesh);
|
||||
mesh->setPosition3D(_camera->getPosition3D());
|
||||
mesh->setScale(0.5f);
|
||||
mesh->syncNodeToPhysics();
|
||||
|
||||
// optimize, only sync node to physics
|
||||
sprite->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::PHYSICS_TO_NODE); // sync node to physics
|
||||
mesh->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::PHYSICS_TO_NODE); // sync node to physics
|
||||
|
||||
sprite->setCameraMask((unsigned short)CameraFlag::USER1);
|
||||
mesh->setCameraMask((unsigned short)CameraFlag::USER1);
|
||||
}
|
||||
|
||||
std::string BasicPhysics3DDemo::subtitle() const
|
||||
|
@ -232,8 +232,8 @@ bool BasicPhysics3DDemo::init()
|
|||
rbDes.mass = 0.0f;
|
||||
rbDes.shape = Physics3DShape::createBox(Vec3(60.0f, 1.0f, 60.0f));
|
||||
|
||||
auto floor = PhysicsSprite3D::create("Sprite3DTest/box.c3t", &rbDes);
|
||||
floor->setTexture("Sprite3DTest/plane.png");
|
||||
auto floor = PhysicsMeshRenderer::create("MeshRendererTest/box.c3t", &rbDes);
|
||||
floor->setTexture("MeshRendererTest/plane.png");
|
||||
floor->setScaleX(60);
|
||||
floor->setScaleZ(60);
|
||||
this->addChild(floor);
|
||||
|
@ -242,7 +242,7 @@ bool BasicPhysics3DDemo::init()
|
|||
// static object sync is not needed
|
||||
floor->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::NONE);
|
||||
|
||||
// create several boxes using PhysicsSprite3D
|
||||
// create several boxes using PhysicsMeshRenderer
|
||||
rbDes.mass = 1.f;
|
||||
rbDes.shape = Physics3DShape::createBox(Vec3(0.8f, 0.8f, 0.8f));
|
||||
float start_x = START_POS_X - ARRAY_SIZE_X / 2;
|
||||
|
@ -259,14 +259,14 @@ bool BasicPhysics3DDemo::init()
|
|||
float y = 5.0 + 1.0 * k + start_y;
|
||||
float z = 1.0 * j + start_z;
|
||||
|
||||
auto sprite = PhysicsSprite3D::create("Sprite3DTest/box.c3t", &rbDes);
|
||||
sprite->setTexture("Images/CyanSquare.png");
|
||||
sprite->setPosition3D(Vec3(x, y, z));
|
||||
sprite->syncNodeToPhysics();
|
||||
sprite->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::PHYSICS_TO_NODE);
|
||||
sprite->setCameraMask((unsigned short)CameraFlag::USER1);
|
||||
sprite->setScale(0.8f);
|
||||
this->addChild(sprite);
|
||||
auto mesh = PhysicsMeshRenderer::create("MeshRendererTest/box.c3t", &rbDes);
|
||||
mesh->setTexture("Images/CyanSquare.png");
|
||||
mesh->setPosition3D(Vec3(x, y, z));
|
||||
mesh->syncNodeToPhysics();
|
||||
mesh->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::PHYSICS_TO_NODE);
|
||||
mesh->setCameraMask((unsigned short)CameraFlag::USER1);
|
||||
mesh->setScale(0.8f);
|
||||
this->addChild(mesh);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -295,8 +295,8 @@ bool Physics3DKinematicDemo::init()
|
|||
Physics3DRigidBodyDes rbDes;
|
||||
rbDes.mass = 0.0f;
|
||||
rbDes.shape = Physics3DShape::createBox(Vec3(60.0f, 1.0f, 60.0f));
|
||||
auto floor = PhysicsSprite3D::create("Sprite3DTest/box.c3t", &rbDes);
|
||||
floor->setTexture("Sprite3DTest/plane.png");
|
||||
auto floor = PhysicsMeshRenderer::create("MeshRendererTest/box.c3t", &rbDes);
|
||||
floor->setTexture("MeshRendererTest/plane.png");
|
||||
floor->setScaleX(60);
|
||||
floor->setScaleZ(60);
|
||||
floor->setPosition3D(Vec3(0.f, -1.f, 0.f));
|
||||
|
@ -312,18 +312,18 @@ bool Physics3DKinematicDemo::init()
|
|||
rbDes.mass = 0.f; // kinematic objects. zero mass so that it can not be affected by other dynamic objects
|
||||
rbDes.shape = Physics3DShape::createBox(Vec3(2.0f, 2.0f, 2.0f));
|
||||
|
||||
auto sprite = PhysicsSprite3D::create("Sprite3DTest/box.c3t", &rbDes);
|
||||
sprite->setTexture("Images/CyanSquare.png");
|
||||
sprite->setCameraMask((unsigned short)CameraFlag::USER1);
|
||||
auto rigidBody = static_cast<Physics3DRigidBody*>(sprite->getPhysicsObj());
|
||||
auto mesh = PhysicsMeshRenderer::create("MeshRendererTest/box.c3t", &rbDes);
|
||||
mesh->setTexture("Images/CyanSquare.png");
|
||||
mesh->setCameraMask((unsigned short)CameraFlag::USER1);
|
||||
auto rigidBody = static_cast<Physics3DRigidBody*>(mesh->getPhysicsObj());
|
||||
rigidBody->setKinematic(true);
|
||||
|
||||
this->addChild(sprite);
|
||||
this->addChild(mesh);
|
||||
|
||||
sprite->setScale(2.0f);
|
||||
sprite->setPosition3D(Vec3(-15.0f, 0.0f, 15.0f - 15.0f * i));
|
||||
mesh->setScale(2.0f);
|
||||
mesh->setPosition3D(Vec3(-15.0f, 0.0f, 15.0f - 15.0f * i));
|
||||
auto moveby = MoveBy::create(2.0f + i, Vec3(30.0f, 0.0f, 0.0f));
|
||||
sprite->runAction(RepeatForever::create(Sequence::create(moveby, moveby->reverse(), nullptr)));
|
||||
mesh->runAction(RepeatForever::create(Sequence::create(moveby, moveby->reverse(), nullptr)));
|
||||
}
|
||||
|
||||
// create Dynamic
|
||||
|
@ -347,15 +347,15 @@ bool Physics3DKinematicDemo::init()
|
|||
rbDes.originalTransform.setIdentity();
|
||||
rbDes.originalTransform.translate(x, y, z);
|
||||
|
||||
auto sprite = PhysicsSprite3D::create("Sprite3DTest/sphere.c3b", &rbDes);
|
||||
sprite->setTexture("Sprite3DTest/plane.png");
|
||||
sprite->setCameraMask((unsigned short)CameraFlag::USER1);
|
||||
sprite->setScale(1.0f / sprite->getContentSize().width);
|
||||
this->addChild(sprite);
|
||||
sprite->setPosition3D(Vec3(x, y, z));
|
||||
sprite->syncNodeToPhysics();
|
||||
auto mesh = PhysicsMeshRenderer::create("MeshRendererTest/sphere.c3b", &rbDes);
|
||||
mesh->setTexture("MeshRendererTest/plane.png");
|
||||
mesh->setCameraMask((unsigned short)CameraFlag::USER1);
|
||||
mesh->setScale(1.0f / mesh->getContentSize().width);
|
||||
this->addChild(mesh);
|
||||
mesh->setPosition3D(Vec3(x, y, z));
|
||||
mesh->syncNodeToPhysics();
|
||||
|
||||
sprite->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::PHYSICS_TO_NODE);
|
||||
mesh->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::PHYSICS_TO_NODE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -370,11 +370,11 @@ bool Physics3DConstraintDemo::init()
|
|||
if (!Physics3DTestDemo::init())
|
||||
return false;
|
||||
|
||||
// PhysicsSprite3D = Sprite3D + Physics3DComponent
|
||||
// PhysicsMeshRenderer = MeshRenderer + Physics3DComponent
|
||||
Physics3DRigidBodyDes rbDes;
|
||||
rbDes.disableSleep = true;
|
||||
// create box
|
||||
auto sprite = Sprite3D::create("Sprite3DTest/orc.c3b");
|
||||
auto mesh = MeshRenderer::create("MeshRendererTest/orc.c3b");
|
||||
rbDes.mass = 10.f;
|
||||
rbDes.shape = Physics3DShape::createBox(Vec3(5.0f, 5.0f, 5.0f));
|
||||
auto rigidBody = Physics3DRigidBody::create(&rbDes);
|
||||
|
@ -382,11 +382,11 @@ bool Physics3DConstraintDemo::init()
|
|||
Quaternion::createFromAxisAngle(Vec3(0.f, 1.f, 0.f), CC_DEGREES_TO_RADIANS(180), &quat);
|
||||
auto component = Physics3DComponent::create(rigidBody, Vec3(0.f, -3.f, 0.f), quat);
|
||||
|
||||
sprite->addComponent(component);
|
||||
addChild(sprite);
|
||||
sprite->setCameraMask((unsigned short)CameraFlag::USER1);
|
||||
sprite->setScale(0.4f);
|
||||
sprite->setPosition3D(Vec3(-20.f, 5.f, 0.f));
|
||||
mesh->addComponent(component);
|
||||
addChild(mesh);
|
||||
mesh->setCameraMask((unsigned short)CameraFlag::USER1);
|
||||
mesh->setScale(0.4f);
|
||||
mesh->setPosition3D(Vec3(-20.f, 5.f, 0.f));
|
||||
// sync node position to physics
|
||||
component->syncNodeToPhysics();
|
||||
// physics controlled, we will not set position for it, so we can skip sync node position to physics
|
||||
|
@ -403,14 +403,14 @@ bool Physics3DConstraintDemo::init()
|
|||
rbDes.shape = Physics3DShape::createBox(Vec3(8.0f, 8.0f, 1.f));
|
||||
rigidBody = Physics3DRigidBody::create(&rbDes);
|
||||
component = Physics3DComponent::create(rigidBody);
|
||||
sprite = Sprite3D::create("Sprite3DTest/box.c3t");
|
||||
sprite->setTexture("Sprite3DTest/plane.png");
|
||||
sprite->setScaleX(8.f);
|
||||
sprite->setScaleY(8.f);
|
||||
sprite->setPosition3D(Vec3(5.f, 0.f, 0.f));
|
||||
sprite->addComponent(component);
|
||||
sprite->setCameraMask((unsigned short)CameraFlag::USER1);
|
||||
this->addChild(sprite);
|
||||
mesh = MeshRenderer::create("MeshRendererTest/box.c3t");
|
||||
mesh->setTexture("MeshRendererTest/plane.png");
|
||||
mesh->setScaleX(8.f);
|
||||
mesh->setScaleY(8.f);
|
||||
mesh->setPosition3D(Vec3(5.f, 0.f, 0.f));
|
||||
mesh->addComponent(component);
|
||||
mesh->setCameraMask((unsigned short)CameraFlag::USER1);
|
||||
this->addChild(mesh);
|
||||
component->syncNodeToPhysics();
|
||||
rigidBody->setAngularVelocity(Vec3(0, 3, 0));
|
||||
constraint = Physics3DHingeConstraint::create(rigidBody, Vec3(4.f, 4.f, 0.5f), Vec3(0.f, 1.f, 0.f));
|
||||
|
@ -421,14 +421,14 @@ bool Physics3DConstraintDemo::init()
|
|||
rbDes.shape = Physics3DShape::createBox(Vec3(3.0f, 2.0f, 3.f));
|
||||
rigidBody = Physics3DRigidBody::create(&rbDes);
|
||||
component = Physics3DComponent::create(rigidBody);
|
||||
sprite = Sprite3D::create("Sprite3DTest/box.c3t");
|
||||
sprite->setTexture("Sprite3DTest/plane.png");
|
||||
sprite->setScaleX(3.f);
|
||||
sprite->setScaleZ(3.f);
|
||||
sprite->setPosition3D(Vec3(30.f, 15.f, 0.f));
|
||||
sprite->addComponent(component);
|
||||
sprite->setCameraMask((unsigned short)CameraFlag::USER1);
|
||||
this->addChild(sprite);
|
||||
mesh = MeshRenderer::create("MeshRendererTest/box.c3t");
|
||||
mesh->setTexture("MeshRendererTest/plane.png");
|
||||
mesh->setScaleX(3.f);
|
||||
mesh->setScaleZ(3.f);
|
||||
mesh->setPosition3D(Vec3(30.f, 15.f, 0.f));
|
||||
mesh->addComponent(component);
|
||||
mesh->setCameraMask((unsigned short)CameraFlag::USER1);
|
||||
this->addChild(mesh);
|
||||
component->syncNodeToPhysics();
|
||||
rigidBody->setLinearVelocity(Vec3(0, 3, 0));
|
||||
|
||||
|
@ -436,13 +436,13 @@ bool Physics3DConstraintDemo::init()
|
|||
rbDes.shape = Physics3DShape::createBox(Vec3(3.0f, 3.0f, 3.f));
|
||||
auto rigidBodyB = Physics3DRigidBody::create(&rbDes);
|
||||
component = Physics3DComponent::create(rigidBodyB);
|
||||
sprite = Sprite3D::create("Sprite3DTest/box.c3t");
|
||||
sprite->setTexture("Sprite3DTest/plane.png");
|
||||
sprite->setScale(3.f);
|
||||
sprite->setPosition3D(Vec3(30.f, 5.f, 0.f));
|
||||
sprite->addComponent(component);
|
||||
sprite->setCameraMask((unsigned short)CameraFlag::USER1);
|
||||
this->addChild(sprite);
|
||||
mesh = MeshRenderer::create("MeshRendererTest/box.c3t");
|
||||
mesh->setTexture("MeshRendererTest/plane.png");
|
||||
mesh->setScale(3.f);
|
||||
mesh->setPosition3D(Vec3(30.f, 5.f, 0.f));
|
||||
mesh->addComponent(component);
|
||||
mesh->setCameraMask((unsigned short)CameraFlag::USER1);
|
||||
this->addChild(mesh);
|
||||
component->syncNodeToPhysics();
|
||||
|
||||
Mat4 frameInA, frameInB;
|
||||
|
@ -460,13 +460,13 @@ bool Physics3DConstraintDemo::init()
|
|||
rbDes.shape = Physics3DShape::createBox(Vec3(3.f, 3.f, 3.f));
|
||||
rigidBody = Physics3DRigidBody::create(&rbDes);
|
||||
component = Physics3DComponent::create(rigidBody);
|
||||
sprite = Sprite3D::create("Sprite3DTest/box.c3t");
|
||||
sprite->setTexture("Sprite3DTest/plane.png");
|
||||
sprite->setScale(3.f);
|
||||
sprite->setPosition3D(Vec3(-10.f, 5.f, 0.f));
|
||||
sprite->addComponent(component);
|
||||
sprite->setCameraMask((unsigned short)CameraFlag::USER1);
|
||||
this->addChild(sprite);
|
||||
mesh = MeshRenderer::create("MeshRendererTest/box.c3t");
|
||||
mesh->setTexture("MeshRendererTest/plane.png");
|
||||
mesh->setScale(3.f);
|
||||
mesh->setPosition3D(Vec3(-10.f, 5.f, 0.f));
|
||||
mesh->addComponent(component);
|
||||
mesh->setCameraMask((unsigned short)CameraFlag::USER1);
|
||||
this->addChild(mesh);
|
||||
component->syncNodeToPhysics();
|
||||
|
||||
Mat4::createRotationZ(CC_DEGREES_TO_RADIANS(90), &frameInA);
|
||||
|
@ -483,13 +483,13 @@ bool Physics3DConstraintDemo::init()
|
|||
rbDes.shape = Physics3DShape::createBox(Vec3(3.0f, 3.0f, 3.f));
|
||||
rigidBody = Physics3DRigidBody::create(&rbDes);
|
||||
component = Physics3DComponent::create(rigidBody);
|
||||
sprite = Sprite3D::create("Sprite3DTest/box.c3t");
|
||||
sprite->setTexture("Sprite3DTest/plane.png");
|
||||
sprite->setScale(3.f);
|
||||
sprite->setPosition3D(Vec3(30.f, -5.f, 0.f));
|
||||
sprite->addComponent(component);
|
||||
sprite->setCameraMask((unsigned short)CameraFlag::USER1);
|
||||
this->addChild(sprite);
|
||||
mesh = MeshRenderer::create("MeshRendererTest/box.c3t");
|
||||
mesh->setTexture("MeshRendererTest/plane.png");
|
||||
mesh->setScale(3.f);
|
||||
mesh->setPosition3D(Vec3(30.f, -5.f, 0.f));
|
||||
mesh->addComponent(component);
|
||||
mesh->setCameraMask((unsigned short)CameraFlag::USER1);
|
||||
this->addChild(mesh);
|
||||
component->syncNodeToPhysics();
|
||||
frameInA.setIdentity();
|
||||
constraint = Physics3D6DofConstraint::create(rigidBody, frameInA, false);
|
||||
|
@ -617,30 +617,30 @@ bool Physics3DTerrainDemo::init()
|
|||
float y = 5.0 + 1.0 * k + start_y;
|
||||
float z = 1.0 * j + start_z;
|
||||
|
||||
auto sprite = PhysicsSprite3D::create("Sprite3DTest/sphere.c3b", &rbDes);
|
||||
sprite->setTexture("Sprite3DTest/plane.png");
|
||||
sprite->setCameraMask((unsigned short)CameraFlag::USER1);
|
||||
sprite->setScale(1.0f / sprite->getContentSize().width);
|
||||
sprite->setPosition3D(Vec3(x, y, z));
|
||||
this->addChild(sprite);
|
||||
sprite->syncNodeToPhysics();
|
||||
sprite->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::PHYSICS_TO_NODE);
|
||||
auto mesh = PhysicsMeshRenderer::create("MeshRendererTest/sphere.c3b", &rbDes);
|
||||
mesh->setTexture("MeshRendererTest/plane.png");
|
||||
mesh->setCameraMask((unsigned short)CameraFlag::USER1);
|
||||
mesh->setScale(1.0f / mesh->getContentSize().width);
|
||||
mesh->setPosition3D(Vec3(x, y, z));
|
||||
this->addChild(mesh);
|
||||
mesh->syncNodeToPhysics();
|
||||
mesh->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::PHYSICS_TO_NODE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// create mesh
|
||||
std::vector<Vec3> trianglesList = Bundle3D::getTrianglesList("Sprite3DTest/boss.c3b");
|
||||
std::vector<Vec3> trianglesList = Bundle3D::getTrianglesList("MeshRendererTest/boss.c3b");
|
||||
|
||||
colliderDes.shape = Physics3DShape::createMesh(&trianglesList[0], (int)trianglesList.size() / 3);
|
||||
|
||||
auto sprite = PhysicsSprite3D::createWithCollider("Sprite3DTest/boss.c3b", &colliderDes);
|
||||
sprite->setRotation3D(Vec3(-90.0f, 0.0f, 0.0f));
|
||||
sprite->setPosition3D(Vec3(0.0f, 15.0f, 0.0f));
|
||||
sprite->setCameraMask(2);
|
||||
this->addChild(sprite);
|
||||
sprite->syncNodeToPhysics();
|
||||
sprite->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::NONE);
|
||||
auto mesh = PhysicsMeshRenderer::createWithCollider("MeshRendererTest/boss.c3b", &colliderDes);
|
||||
mesh->setRotation3D(Vec3(-90.0f, 0.0f, 0.0f));
|
||||
mesh->setPosition3D(Vec3(0.0f, 15.0f, 0.0f));
|
||||
mesh->setCameraMask(2);
|
||||
this->addChild(mesh);
|
||||
mesh->syncNodeToPhysics();
|
||||
mesh->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::NONE);
|
||||
|
||||
std::vector<std::pair<Physics3DShape*, Mat4>> shapeList;
|
||||
{
|
||||
|
@ -668,13 +668,13 @@ bool Physics3DTerrainDemo::init()
|
|||
rbDes.shape = Physics3DShape::createCompoundShape(shapeList);
|
||||
auto rigidBody = Physics3DRigidBody::create(&rbDes);
|
||||
component = Physics3DComponent::create(rigidBody);
|
||||
auto sprite = Sprite3D::create("Sprite3DTest/orc.c3b");
|
||||
sprite->addComponent(component);
|
||||
sprite->setRotation3D(Vec3(0.0f, 180.0f, 0.0f));
|
||||
sprite->setPosition3D(Vec3(-5.0f, 20.0f, 0.0f));
|
||||
sprite->setScale(0.4f);
|
||||
sprite->setCameraMask(2);
|
||||
this->addChild(sprite);
|
||||
auto mesh = MeshRenderer::create("MeshRendererTest/orc.c3b");
|
||||
mesh->addComponent(component);
|
||||
mesh->setRotation3D(Vec3(0.0f, 180.0f, 0.0f));
|
||||
mesh->setPosition3D(Vec3(-5.0f, 20.0f, 0.0f));
|
||||
mesh->setScale(0.4f);
|
||||
mesh->setCameraMask(2);
|
||||
this->addChild(mesh);
|
||||
}
|
||||
|
||||
physicsScene->setPhysics3DDebugCamera(_camera);
|
||||
|
@ -700,7 +700,7 @@ bool Physics3DCollisionCallbackDemo::init()
|
|||
Physics3DRigidBodyDes rbDes;
|
||||
|
||||
float scale = 2.0f;
|
||||
std::vector<Vec3> trianglesList = Bundle3D::getTrianglesList("Sprite3DTest/boss.c3b");
|
||||
std::vector<Vec3> trianglesList = Bundle3D::getTrianglesList("MeshRendererTest/boss.c3b");
|
||||
for (auto& it : trianglesList)
|
||||
{
|
||||
it *= scale;
|
||||
|
@ -710,12 +710,12 @@ bool Physics3DCollisionCallbackDemo::init()
|
|||
rbDes.shape = Physics3DShape::createMesh(&trianglesList[0], (int)trianglesList.size() / 3);
|
||||
auto rigidBody = Physics3DRigidBody::create(&rbDes);
|
||||
auto component = Physics3DComponent::create(rigidBody);
|
||||
auto sprite = Sprite3D::create("Sprite3DTest/boss.c3b");
|
||||
sprite->addComponent(component);
|
||||
sprite->setRotation3D(Vec3(-90.0f, 0.0f, 0.0f));
|
||||
sprite->setScale(scale);
|
||||
sprite->setCameraMask((unsigned short)CameraFlag::USER1);
|
||||
this->addChild(sprite);
|
||||
auto mesh = MeshRenderer::create("MeshRendererTest/boss.c3b");
|
||||
mesh->addComponent(component);
|
||||
mesh->setRotation3D(Vec3(-90.0f, 0.0f, 0.0f));
|
||||
mesh->setScale(scale);
|
||||
mesh->setCameraMask((unsigned short)CameraFlag::USER1);
|
||||
this->addChild(mesh);
|
||||
// preload
|
||||
//
|
||||
rigidBody->setCollisionCallback([=](const Physics3DCollisionInfo& ci) {
|
||||
|
@ -766,15 +766,15 @@ bool Physics3DColliderDemo::init()
|
|||
auto playerBody = Physics3DRigidBody::create(&rbDes);
|
||||
auto component = Physics3DComponent::create(playerBody);
|
||||
playerBody->setKinematic(true);
|
||||
auto sprite = Sprite3D::create("Sprite3DTest/box.c3t");
|
||||
sprite->setTexture("Sprite3DTest/plane.png");
|
||||
sprite->setScale(3.f);
|
||||
sprite->setPosition3D(Vec3(0.0f, 0.f, 30.f));
|
||||
sprite->addComponent(component);
|
||||
sprite->setCameraMask((unsigned short)CameraFlag::USER1);
|
||||
auto mesh = MeshRenderer::create("MeshRendererTest/box.c3t");
|
||||
mesh->setTexture("MeshRendererTest/plane.png");
|
||||
mesh->setScale(3.f);
|
||||
mesh->setPosition3D(Vec3(0.0f, 0.f, 30.f));
|
||||
mesh->addComponent(component);
|
||||
mesh->setCameraMask((unsigned short)CameraFlag::USER1);
|
||||
auto moveby = MoveBy::create(5.0f, Vec3(0.0f, 0.0f, -60.0f));
|
||||
sprite->runAction(RepeatForever::create(Sequence::create(moveby, moveby->reverse(), nullptr)));
|
||||
this->addChild(sprite);
|
||||
mesh->runAction(RepeatForever::create(Sequence::create(moveby, moveby->reverse(), nullptr)));
|
||||
this->addChild(mesh);
|
||||
|
||||
{
|
||||
Physics3DColliderDes colliderDes;
|
||||
|
@ -793,8 +793,8 @@ bool Physics3DColliderDemo::init()
|
|||
auto rigidBody = Physics3DRigidBody::create(&rbDes);
|
||||
component = Physics3DComponent::create(rigidBody);
|
||||
rigidBody->setKinematic(true);
|
||||
auto doorLeft = Sprite3D::create("Sprite3DTest/box.c3t");
|
||||
doorLeft->setTexture("Sprite3DTest/plane.png");
|
||||
auto doorLeft = MeshRenderer::create("MeshRendererTest/box.c3t");
|
||||
doorLeft->setTexture("MeshRendererTest/plane.png");
|
||||
doorLeft->setScaleX(10.0f);
|
||||
doorLeft->setScaleY(10.0f);
|
||||
doorLeft->setScaleZ(1.0f);
|
||||
|
@ -808,8 +808,8 @@ bool Physics3DColliderDemo::init()
|
|||
rigidBody = Physics3DRigidBody::create(&rbDes);
|
||||
component = Physics3DComponent::create(rigidBody);
|
||||
rigidBody->setKinematic(true);
|
||||
auto doorRight = Sprite3D::create("Sprite3DTest/box.c3t");
|
||||
doorRight->setTexture("Sprite3DTest/plane.png");
|
||||
auto doorRight = MeshRenderer::create("MeshRendererTest/box.c3t");
|
||||
doorRight->setTexture("MeshRendererTest/plane.png");
|
||||
doorRight->setScaleX(10.0f);
|
||||
doorRight->setScaleY(10.0f);
|
||||
doorRight->setScaleZ(1.0f);
|
||||
|
|
|
@ -37,7 +37,6 @@ RenderTextureTests::RenderTextureTests()
|
|||
ADD_TEST_CASE(SpriteRenderTextureBug);
|
||||
ADD_TEST_CASE(RenderTexturePartTest);
|
||||
ADD_TEST_CASE(Issue16113Test);
|
||||
// ADD_TEST_CASE(RenderTextureWithSprite3DIssue16894); this Test makes no sense
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -811,94 +810,3 @@ std::string Issue16113Test::subtitle() const
|
|||
{
|
||||
return "aaa.png file without white border on iOS";
|
||||
}
|
||||
|
||||
//
|
||||
// RenderTextureWithSprite3DIssue16894
|
||||
//
|
||||
RenderTextureWithSprite3DIssue16894::RenderTextureWithSprite3DIssue16894()
|
||||
{
|
||||
auto visibleSize = Director::getInstance()->getVisibleSize();
|
||||
Vec2 origin = Director::getInstance()->getVisibleOrigin();
|
||||
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
// Ship - Model is from cocos2d-x test project
|
||||
auto ship = Sprite3D::create("Sprite3DTest/boss.c3b");
|
||||
ship->setScale(6);
|
||||
ship->setRotation3D(Vec3(180.0f, 45.0f, 0.0f));
|
||||
ship->setPosition(Vec2(visibleSize.width / 4 + origin.x, visibleSize.height / 2 + origin.y));
|
||||
ship->setForce2DQueue(true);
|
||||
ship->retain();
|
||||
|
||||
if (i == 0)
|
||||
{
|
||||
addChild(ship, 1);
|
||||
//// Rotate Ship
|
||||
auto spin = RotateBy::create(4, Vec3(0.0f, 180.0f, 0.0f));
|
||||
auto repeatspin = RepeatForever::create(spin);
|
||||
ship->runAction(repeatspin);
|
||||
}
|
||||
_ship[i] = ship;
|
||||
}
|
||||
|
||||
// RenderTextures
|
||||
_renderTexDefault = RenderTexture::create(visibleSize.width, visibleSize.height, backend::PixelFormat::RGBA8);
|
||||
_renderTexDefault->setKeepMatrix(true);
|
||||
addChild(_renderTexDefault);
|
||||
_renderTexDefault->setPosition(visibleSize.width / 4 * 3, visibleSize.height / 2);
|
||||
|
||||
_renderTexWithBuffer = RenderTexture::create(visibleSize.width, visibleSize.height, backend::PixelFormat::RGBA8,
|
||||
backend::PixelFormat::D24S8);
|
||||
_renderTexWithBuffer->setKeepMatrix(true);
|
||||
addChild(_renderTexWithBuffer);
|
||||
_renderTexWithBuffer->setPosition(visibleSize.width / 4 * 4, visibleSize.height / 2);
|
||||
|
||||
// Update
|
||||
scheduleUpdate();
|
||||
|
||||
auto label1 = Label::createWithTTF("Normal Sprite3D\n", "fonts/arial.ttf", 10);
|
||||
label1->setPosition(Vec2(visibleSize.width / 4 * 1, 60.0f));
|
||||
this->addChild(label1, 1);
|
||||
|
||||
auto label2 = Label::createWithTTF("RenderTexture\nDefault - No depth buffer", "fonts/arial.ttf", 10);
|
||||
label2->setPosition(Vec2(visibleSize.width / 4 * 2, 60.0f));
|
||||
this->addChild(label2, 1);
|
||||
|
||||
auto label3 = Label::createWithTTF("RenderTexture\nGL_DEPTH24_STENCIL8", "fonts/arial.ttf", 10);
|
||||
label3->setPosition(Vec2(visibleSize.width / 4 * 3, 60.0f));
|
||||
this->addChild(label3, 1);
|
||||
}
|
||||
|
||||
RenderTextureWithSprite3DIssue16894::~RenderTextureWithSprite3DIssue16894()
|
||||
{
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
_ship[i]->release();
|
||||
}
|
||||
}
|
||||
|
||||
void RenderTextureWithSprite3DIssue16894::visit(Renderer* renderer, const Mat4& parentTransform, uint32_t parentFlags)
|
||||
{
|
||||
RenderTextureTest::visit(renderer, parentTransform, parentFlags);
|
||||
|
||||
_ship[1]->setRotation3D(_ship[0]->getRotation3D());
|
||||
_ship[2]->setRotation3D(_ship[0]->getRotation3D());
|
||||
|
||||
_renderTexDefault->beginWithClear(0, 0, 0, 0, 0, 0);
|
||||
_ship[1]->visit(Director::getInstance()->getRenderer(), Mat4::IDENTITY, 0);
|
||||
_renderTexDefault->end();
|
||||
|
||||
_renderTexWithBuffer->beginWithClear(0, 0, 0, 0, 1, 0);
|
||||
_ship[2]->visit(Director::getInstance()->getRenderer(), Mat4::IDENTITY, 0);
|
||||
_renderTexWithBuffer->end();
|
||||
}
|
||||
|
||||
std::string RenderTextureWithSprite3DIssue16894::title() const
|
||||
{
|
||||
return "Issue16894: Render Sprite3D to texture";
|
||||
}
|
||||
|
||||
std::string RenderTextureWithSprite3DIssue16894::subtitle() const
|
||||
{
|
||||
return "3 ships, 1st & 3rd are the same";
|
||||
}
|
||||
|
|
|
@ -182,25 +182,4 @@ public:
|
|||
virtual std::string subtitle() const override;
|
||||
};
|
||||
|
||||
class RenderTextureWithSprite3DIssue16894 : public RenderTextureTest
|
||||
{
|
||||
public:
|
||||
CREATE_FUNC(RenderTextureWithSprite3DIssue16894);
|
||||
RenderTextureWithSprite3DIssue16894();
|
||||
virtual ~RenderTextureWithSprite3DIssue16894();
|
||||
|
||||
virtual void visit(cocos2d::Renderer* renderer,
|
||||
const cocos2d::Mat4& parentTransform,
|
||||
uint32_t parentFlags) override;
|
||||
|
||||
virtual std::string title() const override;
|
||||
virtual std::string subtitle() const override;
|
||||
|
||||
private:
|
||||
cocos2d::Sprite3D* _ship[3];
|
||||
|
||||
cocos2d::RenderTexture* _renderTexDefault;
|
||||
cocos2d::RenderTexture* _renderTexWithBuffer;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -136,7 +136,7 @@ TerrainWalkThru::TerrainWalkThru()
|
|||
|
||||
_terrain->setSkirtHeightRatio(3);
|
||||
_terrain->setLODDistance(64, 128, 192);
|
||||
_player = Player::create("Sprite3DTest/girl.c3b", _camera, _terrain);
|
||||
_player = Player::create("MeshRendererTest/girl.c3b", _camera, _terrain);
|
||||
_player->setCameraMask(2);
|
||||
_player->setScale(0.08f);
|
||||
_player->setPositionY(_terrain->getHeight(_player->getPositionX(), _player->getPositionZ()) + PLAYER_HEIGHT);
|
||||
|
@ -154,7 +154,7 @@ TerrainWalkThru::TerrainWalkThru()
|
|||
billboard->setCameraMask((unsigned short)CameraFlag::USER1);
|
||||
_player->addChild(billboard);
|
||||
|
||||
auto animation = Animation3D::create("Sprite3DTest/girl.c3b", "Take 001");
|
||||
auto animation = Animation3D::create("MeshRendererTest/girl.c3b", "Take 001");
|
||||
if (animation)
|
||||
{
|
||||
auto animate = Animate3D::create(animation);
|
||||
|
@ -210,7 +210,7 @@ bool Player::isDone() const
|
|||
|
||||
void Player::update(float dt)
|
||||
{
|
||||
auto player = (Sprite3D*)this;
|
||||
auto player = (MeshRenderer*)this;
|
||||
switch (_playerState)
|
||||
{
|
||||
case PLAYER_STATE_IDLE:
|
||||
|
@ -301,7 +301,7 @@ void Player::backward()
|
|||
|
||||
void Player::updateState()
|
||||
{
|
||||
auto player = (Sprite3D*)this;
|
||||
auto player = (MeshRenderer*)this;
|
||||
switch (_playerState)
|
||||
{
|
||||
case PLAYER_STATE_FORWARD:
|
||||
|
@ -323,18 +323,18 @@ void Player::updateState()
|
|||
Player* Player::create(const char* file, Camera* cam, Terrain* terrain)
|
||||
{
|
||||
//
|
||||
auto sprite = new Player();
|
||||
if (sprite->initWithFile(file))
|
||||
auto player = new Player();
|
||||
if (player->initWithFile(file))
|
||||
{
|
||||
sprite->_headingAngle = 0;
|
||||
sprite->_playerState = PLAYER_STATE_IDLE;
|
||||
sprite->_cam = cam;
|
||||
sprite->_terrain = terrain;
|
||||
sprite->autorelease();
|
||||
sprite->scheduleUpdate();
|
||||
return sprite;
|
||||
player->_headingAngle = 0;
|
||||
player->_playerState = PLAYER_STATE_IDLE;
|
||||
player->_cam = cam;
|
||||
player->_terrain = terrain;
|
||||
player->autorelease();
|
||||
player->scheduleUpdate();
|
||||
return player;
|
||||
}
|
||||
CC_SAFE_DELETE(sprite);
|
||||
CC_SAFE_DELETE(player);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,12 +24,12 @@
|
|||
|
||||
#ifndef TERRAIN_TESH_H
|
||||
|
||||
# include "../BaseTest.h"
|
||||
#include "../BaseTest.h"
|
||||
|
||||
# include "3d/CCSprite3D.h"
|
||||
# include "3d/CCTerrain.h"
|
||||
# include "2d/CCCamera.h"
|
||||
# include "2d/CCAction.h"
|
||||
#include "3d/CCMeshRenderer.h"
|
||||
#include "3d/CCTerrain.h"
|
||||
#include "2d/CCCamera.h"
|
||||
#include "2d/CCAction.h"
|
||||
|
||||
DEFINE_TEST_SUITE(TerrainTests);
|
||||
|
||||
|
@ -59,7 +59,7 @@ protected:
|
|||
# define PLAYER_STATE_FORWARD 3
|
||||
# define PLAYER_STATE_BACKWARD 4
|
||||
|
||||
class Player : public cocos2d::Sprite3D
|
||||
class Player : public cocos2d::MeshRenderer
|
||||
{
|
||||
public:
|
||||
static Player* create(const char* file, cocos2d::Camera* cam, cocos2d::Terrain* terrain);
|
||||
|
|
|
@ -102,7 +102,7 @@ public:
|
|||
addTest("Node: Scene", []() { return new SceneTests(); });
|
||||
addTest("Node: Spine", []() { return new SpineTests(); });
|
||||
addTest("Node: Sprite", []() { return new SpriteTests(); });
|
||||
addTest("Node: Sprite3D", []() { return new Sprite3DTests(); });
|
||||
addTest("Node: MeshRenderer", []() { return new MeshRendererTests(); });
|
||||
addTest("Node: SpritePolygon", []() { return new SpritePolygonTest(); });
|
||||
addTest("Node: Terrain", []() { return new TerrainTests(); });
|
||||
addTest("Node: FastTileMap", []() { return new FastTileMapTests(); });
|
||||
|
|
|
@ -101,7 +101,7 @@
|
|||
#include "ShaderTest/ShaderTest.h"
|
||||
#include "ShaderTest/ShaderTest2.h"
|
||||
#include "SpineTest/SpineTest.h"
|
||||
#include "Sprite3DTest/Sprite3DTest.h"
|
||||
#include "MeshRendererTest/MeshRendererTest.h"
|
||||
#include "SpritePolygonTest/SpritePolygonTest.h"
|
||||
#include "SpriteTest/SpriteTest.h"
|
||||
#include "TerrainTest/TerrainTest.h"
|
||||
|
|
Loading…
Reference in New Issue