[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:
Turky Mohammed 2022-07-05 09:48:46 +03:00 committed by GitHub
parent 5edbfa5448
commit 656babac78
59 changed files with 2066 additions and 2177 deletions

8
RENAMED_TYPES.md Normal file
View File

@ -0,0 +1,8 @@
adxe-1.0 ??
### Classes & Types
* ```Sprite3D``` => ```MeshRenderer```
### Functions & Methods
* ```Director::isDisplayStats()``` => ```Director::isStatsDisplay()```

View File

@ -24,7 +24,7 @@
****************************************************************************/ ****************************************************************************/
#include "3d/CCAnimate3D.h" #include "3d/CCAnimate3D.h"
#include "3d/CCSprite3D.h" #include "3d/CCMeshRenderer.h"
#include "3d/CCSkeleton3D.h" #include "3d/CCSkeleton3D.h"
#include "platform/CCFileUtils.h" #include "platform/CCFileUtils.h"
#include "base/CCConfiguration.h" #include "base/CCConfiguration.h"
@ -156,9 +156,9 @@ void Animate3D::startWithTarget(Node* target)
_nodeCurves.clear(); _nodeCurves.clear();
bool hasCurve = false; bool hasCurve = false;
Sprite3D* sprite = dynamic_cast<Sprite3D*>(target); MeshRenderer* mesh = dynamic_cast<MeshRenderer*>(target);
if (sprite) if (mesh)
{ {
if (_animation) if (_animation)
{ {
@ -166,7 +166,7 @@ void Animate3D::startWithTarget(Node* target)
for (const auto& iter : boneCurves) for (const auto& iter : boneCurves)
{ {
std::string_view boneName = iter.first; std::string_view boneName = iter.first;
auto skin = sprite->getSkeleton(); auto skin = mesh->getSkeleton();
if (skin) if (skin)
{ {
auto bone = skin->getBoneByName(boneName); auto bone = skin->getBoneByName(boneName);

View File

@ -37,7 +37,7 @@
NS_CC_BEGIN NS_CC_BEGIN
class Bone3D; class Bone3D;
class Sprite3D; class MeshRenderer;
class EventCustom; class EventCustom;
enum class Animate3DQuality 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 class CC_DLL Animate3D : public ActionInterval
{ {
@ -174,7 +174,7 @@ protected:
std::unordered_map<int, EventCustom*> _keyFrameEvent; std::unordered_map<int, EventCustom*> _keyFrameEvent;
std::unordered_map<int, Animate3DDisplayedEventInfo> _displayedEventInfo; 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_fadeInAnimates;
static std::unordered_map<Node*, Animate3D*> s_fadeOutAnimates; static std::unordered_map<Node*, Animate3D*> s_fadeOutAnimates;
static std::unordered_map<Node*, Animate3D*> s_runningAnimates; static std::unordered_map<Node*, Animate3D*> s_runningAnimates;

View File

@ -38,9 +38,9 @@ class Bone3D;
/** /**
* @brief attach a node to a bone * @brief attach a node to a bone
* usage: auto sprite = Sprite3D::create("girl.c3b"); * usage: auto mesh = MeshRenderer::create("girl.c3b");
* auto weapon = Sprite3D::create("weapon.c3b"); * auto weapon = MeshRenderer::create("weapon.c3b");
* auto attachNode = sprite->getAttachNode("left hand"); * auto attachNode = mesh->getAttachNode("left hand");
* attachNode->addChild(weapon); * attachNode->addChild(weapon);
*/ */
class CC_DLL AttachNode : public Node class CC_DLL AttachNode : public Node

View File

@ -109,7 +109,7 @@ struct NodeData
struct NodeDatas struct NodeDatas
{ {
std::vector<NodeData*> skeleton; // skeleton 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(); } virtual ~NodeDatas() { resetData(); }

View File

@ -61,7 +61,7 @@ class Buffer;
*/ */
class CC_DLL Mesh : public Ref class CC_DLL Mesh : public Ref
{ {
friend class Sprite3D; friend class MeshRenderer;
public: public:
typedef std::vector<unsigned short> IndexArray; typedef std::vector<unsigned short> IndexArray;
@ -234,7 +234,7 @@ public:
void calculateAABB(); 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; } void setForce2DQueue(bool force2D) { _force2DQueue = force2D; }

View File

@ -23,7 +23,7 @@
THE SOFTWARE. THE SOFTWARE.
****************************************************************************/ ****************************************************************************/
#include "3d/CCSprite3DMaterial.h" #include "3d/CCMeshMaterial.h"
#include "3d/CCMesh.h" #include "3d/CCMesh.h"
#include "platform/CCFileUtils.h" #include "platform/CCFileUtils.h"
#include "renderer/CCTexture2D.h" #include "renderer/CCTexture2D.h"
@ -36,102 +36,102 @@
NS_CC_BEGIN NS_CC_BEGIN
Sprite3DMaterialCache* Sprite3DMaterialCache::_cacheInstance = nullptr; MeshMaterialCache* MeshMaterialCache::_cacheInstance = nullptr;
std::unordered_map<std::string, Sprite3DMaterial*> Sprite3DMaterial::_materials; std::unordered_map<std::string, MeshMaterial*> MeshMaterial::_materials;
Sprite3DMaterial* Sprite3DMaterial::_unLitMaterial = nullptr; MeshMaterial* MeshMaterial::_unLitMaterial = nullptr;
Sprite3DMaterial* Sprite3DMaterial::_unLitNoTexMaterial = nullptr; MeshMaterial* MeshMaterial::_unLitNoTexMaterial = nullptr;
Sprite3DMaterial* Sprite3DMaterial::_vertexLitMaterial = nullptr; MeshMaterial* MeshMaterial::_vertexLitMaterial = nullptr;
Sprite3DMaterial* Sprite3DMaterial::_diffuseMaterial = nullptr; MeshMaterial* MeshMaterial::_diffuseMaterial = nullptr;
Sprite3DMaterial* Sprite3DMaterial::_diffuseNoTexMaterial = nullptr; MeshMaterial* MeshMaterial::_diffuseNoTexMaterial = nullptr;
Sprite3DMaterial* Sprite3DMaterial::_bumpedDiffuseMaterial = nullptr; MeshMaterial* MeshMaterial::_bumpedDiffuseMaterial = nullptr;
Sprite3DMaterial* Sprite3DMaterial::_unLitMaterialSkin = nullptr; MeshMaterial* MeshMaterial::_unLitMaterialSkin = nullptr;
Sprite3DMaterial* Sprite3DMaterial::_vertexLitMaterialSkin = nullptr; MeshMaterial* MeshMaterial::_vertexLitMaterialSkin = nullptr;
Sprite3DMaterial* Sprite3DMaterial::_diffuseMaterialSkin = nullptr; MeshMaterial* MeshMaterial::_diffuseMaterialSkin = nullptr;
Sprite3DMaterial* Sprite3DMaterial::_bumpedDiffuseMaterialSkin = nullptr; MeshMaterial* MeshMaterial::_bumpedDiffuseMaterialSkin = nullptr;
backend::ProgramState* Sprite3DMaterial::_unLitMaterialProgState = nullptr; backend::ProgramState* MeshMaterial::_unLitMaterialProgState = nullptr;
backend::ProgramState* Sprite3DMaterial::_unLitNoTexMaterialProgState = nullptr; backend::ProgramState* MeshMaterial::_unLitNoTexMaterialProgState = nullptr;
backend::ProgramState* Sprite3DMaterial::_vertexLitMaterialProgState = nullptr; backend::ProgramState* MeshMaterial::_vertexLitMaterialProgState = nullptr;
backend::ProgramState* Sprite3DMaterial::_diffuseMaterialProgState = nullptr; backend::ProgramState* MeshMaterial::_diffuseMaterialProgState = nullptr;
backend::ProgramState* Sprite3DMaterial::_diffuseNoTexMaterialProgState = nullptr; backend::ProgramState* MeshMaterial::_diffuseNoTexMaterialProgState = nullptr;
backend::ProgramState* Sprite3DMaterial::_bumpedDiffuseMaterialProgState = nullptr; backend::ProgramState* MeshMaterial::_bumpedDiffuseMaterialProgState = nullptr;
backend::ProgramState* Sprite3DMaterial::_unLitMaterialSkinProgState = nullptr; backend::ProgramState* MeshMaterial::_unLitMaterialSkinProgState = nullptr;
backend::ProgramState* Sprite3DMaterial::_vertexLitMaterialSkinProgState = nullptr; backend::ProgramState* MeshMaterial::_vertexLitMaterialSkinProgState = nullptr;
backend::ProgramState* Sprite3DMaterial::_diffuseMaterialSkinProgState = nullptr; backend::ProgramState* MeshMaterial::_diffuseMaterialSkinProgState = nullptr;
backend::ProgramState* Sprite3DMaterial::_bumpedDiffuseMaterialSkinProgState = nullptr; backend::ProgramState* MeshMaterial::_bumpedDiffuseMaterialSkinProgState = nullptr;
void Sprite3DMaterial::createBuiltInMaterial() void MeshMaterial::createBuiltInMaterial()
{ {
auto* program = backend::Program::getBuiltinProgram(backend::ProgramType::SKINPOSITION_TEXTURE_3D); auto* program = backend::Program::getBuiltinProgram(backend::ProgramType::SKINPOSITION_TEXTURE_3D);
_unLitMaterialSkinProgState = new backend::ProgramState(program); _unLitMaterialSkinProgState = new backend::ProgramState(program);
_unLitMaterialSkin = new Sprite3DMaterial(); _unLitMaterialSkin = new MeshMaterial();
if (_unLitMaterialSkin && _unLitMaterialSkin->initWithProgramState(_unLitMaterialSkinProgState)) 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); program = backend::Program::getBuiltinProgram(backend::ProgramType::SKINPOSITION_NORMAL_TEXTURE_3D);
_diffuseMaterialSkinProgState = new backend::ProgramState(program); _diffuseMaterialSkinProgState = new backend::ProgramState(program);
_diffuseMaterialSkin = new Sprite3DMaterial(); _diffuseMaterialSkin = new MeshMaterial();
if (_diffuseMaterialSkin && _diffuseMaterialSkin->initWithProgramState(_diffuseMaterialSkinProgState)) 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); program = backend::Program::getBuiltinProgram(backend::ProgramType::POSITION_NORMAL_TEXTURE_3D);
_diffuseMaterialProgState = new backend::ProgramState(program); _diffuseMaterialProgState = new backend::ProgramState(program);
_diffuseMaterial = new Sprite3DMaterial(); _diffuseMaterial = new MeshMaterial();
if (_diffuseMaterial && _diffuseMaterial->initWithProgramState(_diffuseMaterialProgState)) if (_diffuseMaterial && _diffuseMaterial->initWithProgramState(_diffuseMaterialProgState))
{ {
_diffuseMaterial->_type = Sprite3DMaterial::MaterialType::DIFFUSE; _diffuseMaterial->_type = MeshMaterial::MaterialType::DIFFUSE;
} }
program = backend::Program::getBuiltinProgram(backend::ProgramType::POSITION_TEXTURE_3D); program = backend::Program::getBuiltinProgram(backend::ProgramType::POSITION_TEXTURE_3D);
_unLitMaterialProgState = new backend::ProgramState(program); _unLitMaterialProgState = new backend::ProgramState(program);
_unLitMaterial = new Sprite3DMaterial(); _unLitMaterial = new MeshMaterial();
if (_unLitMaterial && _unLitMaterial->initWithProgramState(_unLitMaterialProgState)) if (_unLitMaterial && _unLitMaterial->initWithProgramState(_unLitMaterialProgState))
{ {
_unLitMaterial->_type = Sprite3DMaterial::MaterialType::UNLIT; _unLitMaterial->_type = MeshMaterial::MaterialType::UNLIT;
} }
program = backend::Program::getBuiltinProgram(backend::ProgramType::POSITION_3D); program = backend::Program::getBuiltinProgram(backend::ProgramType::POSITION_3D);
_unLitNoTexMaterialProgState = new backend::ProgramState(program); _unLitNoTexMaterialProgState = new backend::ProgramState(program);
_unLitNoTexMaterial = new Sprite3DMaterial(); _unLitNoTexMaterial = new MeshMaterial();
if (_unLitNoTexMaterial && _unLitNoTexMaterial->initWithProgramState(_unLitNoTexMaterialProgState)) 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); program = backend::Program::getBuiltinProgram(backend::ProgramType::POSITION_NORMAL_3D);
_diffuseNoTexMaterialProgState = new backend::ProgramState(program); _diffuseNoTexMaterialProgState = new backend::ProgramState(program);
_diffuseNoTexMaterial = new Sprite3DMaterial(); _diffuseNoTexMaterial = new MeshMaterial();
if (_diffuseNoTexMaterial && _diffuseNoTexMaterial->initWithProgramState(_diffuseNoTexMaterialProgState)) 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); program = backend::Program::getBuiltinProgram(backend::ProgramType::POSITION_BUMPEDNORMAL_TEXTURE_3D);
_bumpedDiffuseMaterialProgState = new backend::ProgramState(program); _bumpedDiffuseMaterialProgState = new backend::ProgramState(program);
_bumpedDiffuseMaterial = new Sprite3DMaterial(); _bumpedDiffuseMaterial = new MeshMaterial();
if (_bumpedDiffuseMaterial && _bumpedDiffuseMaterial->initWithProgramState(_bumpedDiffuseMaterialProgState)) 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); program = backend::Program::getBuiltinProgram(backend::ProgramType::SKINPOSITION_BUMPEDNORMAL_TEXTURE_3D);
_bumpedDiffuseMaterialSkinProgState = new backend::ProgramState(program); _bumpedDiffuseMaterialSkinProgState = new backend::ProgramState(program);
_bumpedDiffuseMaterialSkin = new Sprite3DMaterial(); _bumpedDiffuseMaterialSkin = new MeshMaterial();
if (_bumpedDiffuseMaterialSkin && if (_bumpedDiffuseMaterialSkin &&
_bumpedDiffuseMaterialSkin->initWithProgramState(_bumpedDiffuseMaterialSkinProgState)) _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(_unLitMaterial);
CC_SAFE_RELEASE_NULL(_unLitMaterialSkin); CC_SAFE_RELEASE_NULL(_unLitMaterialSkin);
@ -159,7 +159,7 @@ void Sprite3DMaterial::releaseBuiltInMaterial()
CC_SAFE_RELEASE_NULL(_bumpedDiffuseMaterialSkinProgState); CC_SAFE_RELEASE_NULL(_bumpedDiffuseMaterialSkinProgState);
} }
void Sprite3DMaterial::releaseCachedMaterial() void MeshMaterial::releaseCachedMaterial()
{ {
for (auto& it : _materials) for (auto& it : _materials)
{ {
@ -169,11 +169,10 @@ void Sprite3DMaterial::releaseCachedMaterial()
_materials.clear(); _materials.clear();
} }
Material* Sprite3DMaterial::clone() const Material* MeshMaterial::clone() const
{ {
auto material = new Sprite3DMaterial(); auto material = new MeshMaterial();
// RenderState::cloneInto(material);
material->_renderState = _renderState; material->_renderState = _renderState;
for (const auto& technique : _techniques) for (const auto& technique : _techniques)
@ -196,36 +195,36 @@ Material* Sprite3DMaterial::clone() const
return material; return material;
} }
Sprite3DMaterial* Sprite3DMaterial::createBuiltInMaterial(MaterialType type, bool skinned) MeshMaterial* MeshMaterial::createBuiltInMaterial(MaterialType type, bool skinned)
{ {
///// /////
if (_diffuseMaterial == nullptr) if (_diffuseMaterial == nullptr)
createBuiltInMaterial(); createBuiltInMaterial();
Sprite3DMaterial* material = nullptr; MeshMaterial* material = nullptr;
switch (type) switch (type)
{ {
case Sprite3DMaterial::MaterialType::UNLIT: case MeshMaterial::MaterialType::UNLIT:
material = skinned ? _unLitMaterialSkin : _unLitMaterial; material = skinned ? _unLitMaterialSkin : _unLitMaterial;
break; break;
case Sprite3DMaterial::MaterialType::UNLIT_NOTEX: case MeshMaterial::MaterialType::UNLIT_NOTEX:
material = _unLitNoTexMaterial; material = _unLitNoTexMaterial;
break; break;
case Sprite3DMaterial::MaterialType::VERTEX_LIT: case MeshMaterial::MaterialType::VERTEX_LIT:
CCASSERT(0, "not implement"); CCASSERT(0, "not implemented.");
break; break;
case Sprite3DMaterial::MaterialType::DIFFUSE: case MeshMaterial::MaterialType::DIFFUSE:
material = skinned ? _diffuseMaterialSkin : _diffuseMaterial; material = skinned ? _diffuseMaterialSkin : _diffuseMaterial;
break; break;
case Sprite3DMaterial::MaterialType::DIFFUSE_NOTEX: case MeshMaterial::MaterialType::DIFFUSE_NOTEX:
material = _diffuseNoTexMaterial; material = _diffuseNoTexMaterial;
break; break;
case Sprite3DMaterial::MaterialType::BUMPED_DIFFUSE: case MeshMaterial::MaterialType::BUMPED_DIFFUSE:
material = skinned ? _bumpedDiffuseMaterialSkin : _bumpedDiffuseMaterial; material = skinned ? _bumpedDiffuseMaterialSkin : _bumpedDiffuseMaterial;
break; break;
@ -233,41 +232,41 @@ Sprite3DMaterial* Sprite3DMaterial::createBuiltInMaterial(MaterialType type, boo
break; break;
} }
if (material) if (material)
return (Sprite3DMaterial*)material->clone(); return (MeshMaterial*)material->clone();
return nullptr; return nullptr;
} }
Sprite3DMaterial* Sprite3DMaterial::createWithFilename(std::string_view path) MeshMaterial* MeshMaterial::createWithFilename(std::string_view path)
{ {
auto validfilename = FileUtils::getInstance()->fullPathForFilename(path); auto validfilename = FileUtils::getInstance()->fullPathForFilename(path);
if (!validfilename.empty()) if (!validfilename.empty())
{ {
auto it = _materials.find(validfilename); auto it = _materials.find(validfilename);
if (it != _materials.end()) 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)) if (material->initWithFile(path))
{ {
material->_type = Sprite3DMaterial::MaterialType::CUSTOM; material->_type = MeshMaterial::MaterialType::CUSTOM;
_materials[validfilename] = material; _materials[validfilename] = material;
return (Sprite3DMaterial*)material->clone(); return (MeshMaterial*)material->clone();
} }
CC_SAFE_DELETE(material); CC_SAFE_DELETE(material);
} }
return nullptr; 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)) if (mat->initWithProgramState(programState))
{ {
mat->_type = Sprite3DMaterial::MaterialType::CUSTOM; mat->_type = MeshMaterial::MaterialType::CUSTOM;
mat->autorelease(); mat->autorelease();
return mat; return mat;
} }
@ -275,7 +274,7 @@ Sprite3DMaterial* Sprite3DMaterial::createWithProgramState(backend::ProgramState
return nullptr; return nullptr;
} }
void Sprite3DMaterial::setTexture(Texture2D* tex, NTextureData::Usage usage) void MeshMaterial::setTexture(Texture2D* tex, NTextureData::Usage usage)
{ {
const auto& passes = getTechnique()->getPasses(); const auto& passes = getTechnique()->getPasses();
for (auto& pass : passes) 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) if (!_cacheInstance)
{ {
_cacheInstance = new Sprite3DMaterialCache(); _cacheInstance = new MeshMaterialCache();
} }
return _cacheInstance; return _cacheInstance;
} }
void Sprite3DMaterialCache::destroyInstance() void MeshMaterialCache::destroyInstance()
{ {
if (_cacheInstance) 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); auto itr = _materials.find(key);
if (itr == _materials.end()) if (itr == _materials.end())
@ -323,7 +322,7 @@ bool Sprite3DMaterialCache::addSprite3DMaterial(std::string_view key, Texture2D*
return false; return false;
} }
Texture2D* Sprite3DMaterialCache::getSprite3DMaterial(std::string_view key) Texture2D* MeshMaterialCache::getMeshMaterial(std::string_view key)
{ {
auto itr = _materials.find(key); auto itr = _materials.find(key);
if (itr != _materials.end()) if (itr != _materials.end())
@ -333,7 +332,7 @@ Texture2D* Sprite3DMaterialCache::getSprite3DMaterial(std::string_view key)
return nullptr; return nullptr;
} }
void Sprite3DMaterialCache::removeAllSprite3DMaterial() void MeshMaterialCache::removeAllMeshMaterial()
{ {
for (auto& itr : _materials) for (auto& itr : _materials)
{ {
@ -341,14 +340,14 @@ void Sprite3DMaterialCache::removeAllSprite3DMaterial()
} }
_materials.clear(); _materials.clear();
} }
void Sprite3DMaterialCache::removeUnusedSprite3DMaterial() void MeshMaterialCache::removeUnusedMeshMaterial()
{ {
for (auto it = _materials.cbegin(), itCend = _materials.cend(); it != itCend; /* nothing */) for (auto it = _materials.cbegin(), itCend = _materials.cend(); it != itCend; /* nothing */)
{ {
auto value = it->second; auto value = it->second;
if (value->getReferenceCount() == 1) if (value->getReferenceCount() == 1)
{ {
CCLOG("cocos2d: Sprite3DMaterialCache: removing unused Sprite3DMaterial"); CCLOG("cocos2d: MeshMaterialCache: removing unused mesh renderer materials.");
value->release(); value->release();
it = _materials.erase(it); it = _materials.erase(it);

View File

@ -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: 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 enum class MaterialType
{ {
// Built in material // Built in materials
UNLIT, // unlit material UNLIT, // unlit material
UNLIT_NOTEX, // unlit material without texture UNLIT_NOTEX, // unlit material (without texture)
VERTEX_LIT, // vertex lit VERTEX_LIT, // vertex lit
DIFFUSE, // diffuse (pixel lighting) DIFFUSE, // diffuse (pixel lighting)
DIFFUSE_NOTEX, // diffuse (without texture) DIFFUSE_NOTEX, // diffuse (without texture)
BUMPED_DIFFUSE, // bumped diffuse BUMPED_DIFFUSE, // bumped diffuse
// Custom material // 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 * Create built in material from material type
* @param type Material type * @param type Material type
* @param skinned Has skin? * @param skinned Has hardware skinning?
* @return Created material * @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 * Create material with file name, it creates material from cache if it is previously loaded
* @param path Path of material file * @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 * @param programState GLProgramState instance
* @return Created material * @return An autorelease material object
*/ */
// static Sprite3DMaterial* createWithGLStateProgram(GLProgramState* programState); static MeshMaterial* createWithProgramState(backend::ProgramState* programState);
static Sprite3DMaterial* createWithProgramState(backend::ProgramState* programState);
void setTexture(Texture2D* tex, NTextureData::Usage usage); void setTexture(Texture2D* tex, NTextureData::Usage usage);
/** /**
* Create all build in materials * Create all built-in materials
*/ */
static void createBuiltInMaterial(); static void createBuiltInMaterial();
/** /**
* Release all built in materials * Release all built-in materials
*/ */
static void releaseBuiltInMaterial(); static void releaseBuiltInMaterial();
@ -115,24 +114,24 @@ public:
static void releaseCachedMaterial(); static void releaseCachedMaterial();
/** /**
* Clone material * Clone this material.
*/ */
virtual Material* clone() const override; virtual Material* clone() const override;
protected: protected:
MaterialType _type; MaterialType _type;
static std::unordered_map<std::string, Sprite3DMaterial*> _materials; // cached material static std::unordered_map<std::string, MeshMaterial*> _materials; // cached material
static Sprite3DMaterial* _unLitMaterial; static MeshMaterial* _unLitMaterial;
static Sprite3DMaterial* _unLitNoTexMaterial; static MeshMaterial* _unLitNoTexMaterial;
static Sprite3DMaterial* _vertexLitMaterial; static MeshMaterial* _vertexLitMaterial;
static Sprite3DMaterial* _diffuseMaterial; static MeshMaterial* _diffuseMaterial;
static Sprite3DMaterial* _diffuseNoTexMaterial; static MeshMaterial* _diffuseNoTexMaterial;
static Sprite3DMaterial* _bumpedDiffuseMaterial; static MeshMaterial* _bumpedDiffuseMaterial;
static Sprite3DMaterial* _unLitMaterialSkin; static MeshMaterial* _unLitMaterialSkin;
static Sprite3DMaterial* _vertexLitMaterialSkin; static MeshMaterial* _vertexLitMaterialSkin;
static Sprite3DMaterial* _diffuseMaterialSkin; static MeshMaterial* _diffuseMaterialSkin;
static Sprite3DMaterial* _bumpedDiffuseMaterialSkin; static MeshMaterial* _bumpedDiffuseMaterialSkin;
static backend::ProgramState* _unLitMaterialProgState; static backend::ProgramState* _unLitMaterialProgState;
static backend::ProgramState* _unLitNoTexMaterialProgState; 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 * @js NA
* @lua NA * @lua NA
*/ */
class Sprite3DMaterialCache class MeshMaterialCache
{ {
public: public:
/**get & destroy cache*/ static MeshMaterialCache* getInstance();
static Sprite3DMaterialCache* getInstance();
/**destroy the instance*/
static void destroyInstance(); static void destroyInstance();
/**add to cache*/ /** add a material to cache */
bool addSprite3DMaterial(std::string_view key, Texture2D* tex); bool addMeshMaterial(std::string_view key, Texture2D* tex);
/**get material from cache*/ /** get material from cache */
Texture2D* getSprite3DMaterial(std::string_view key); Texture2D* getMeshMaterial(std::string_view key);
/**remove all spritematerial*/ /** remove all cached materials */
void removeAllSprite3DMaterial(); void removeAllMeshMaterial();
/**remove unused spritematerial*/ /** remove unused cached materials */
void removeUnusedSprite3DMaterial(); void removeUnusedMeshMaterial();
Sprite3DMaterialCache(); MeshMaterialCache();
~Sprite3DMaterialCache(); ~MeshMaterialCache();
protected: protected:
static Sprite3DMaterialCache* _cacheInstance; // instance static MeshMaterialCache* _cacheInstance; // cache instance
hlookup::string_map<Texture2D*> _materials; // cached material hlookup::string_map<Texture2D*> _materials; // cached materials
}; };
// end of 3d group // end of 3d group

View File

@ -23,11 +23,11 @@
THE SOFTWARE. THE SOFTWARE.
****************************************************************************/ ****************************************************************************/
#include "3d/CCSprite3D.h" #include "3d/CCMeshRenderer.h"
#include "3d/CCObjLoader.h" #include "3d/CCObjLoader.h"
#include "3d/CCMeshSkin.h" #include "3d/CCMeshSkin.h"
#include "3d/CCBundle3D.h" #include "3d/CCBundle3D.h"
#include "3d/CCSprite3DMaterial.h" #include "3d/CCMeshMaterial.h"
#include "3d/CCAttachNode.h" #include "3d/CCAttachNode.h"
#include "3d/CCMesh.h" #include "3d/CCMesh.h"
@ -48,87 +48,87 @@
NS_CC_BEGIN 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(); auto mesh = new MeshRenderer();
if (sprite->init()) if (mesh->init())
{ {
sprite->autorelease(); mesh->autorelease();
return sprite; return mesh;
} }
CC_SAFE_DELETE(sprite); CC_SAFE_DELETE(mesh);
return nullptr; 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(); auto mesh = new MeshRenderer();
if (sprite->initWithFile(modelPath)) if (mesh->initWithFile(modelPath))
{ {
sprite->_contentSize = sprite->getBoundingBox().size; mesh->_contentSize = mesh->getBoundingBox().size;
sprite->autorelease(); mesh->autorelease();
return sprite; return mesh;
} }
CC_SAFE_DELETE(sprite); CC_SAFE_DELETE(mesh);
return nullptr; 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); auto mesh = create(modelPath);
if (sprite) if (mesh)
{ {
sprite->setTexture(texturePath); mesh->setTexture(texturePath);
} }
return sprite; return mesh;
} }
void Sprite3D::createAsync(std::string_view modelPath, void MeshRenderer::createAsync(std::string_view modelPath,
const std::function<void(Sprite3D*, void*)>& callback, const std::function<void(MeshRenderer*, void*)>& callback,
void* callbackparam) void* callbackparam)
{ {
createAsync(modelPath, "", callback, callbackparam); createAsync(modelPath, "", callback, callbackparam);
} }
void Sprite3D::createAsync(std::string_view modelPath, void MeshRenderer::createAsync(std::string_view modelPath,
std::string_view texturePath, std::string_view texturePath,
const std::function<void(Sprite3D*, void*)>& callback, const std::function<void(MeshRenderer*, void*)>& callback,
void* callbackparam) void* callbackparam)
{ {
Sprite3D* sprite = new Sprite3D(); MeshRenderer* mesh = new MeshRenderer();
if (sprite->loadFromCache(modelPath)) if (mesh->loadFromCache(modelPath))
{ {
sprite->autorelease(); mesh->autorelease();
if (!texturePath.empty()) if (!texturePath.empty())
sprite->setTexture(texturePath); mesh->setTexture(texturePath);
callback(sprite, callbackparam); callback(mesh, callbackparam);
return; return;
} }
sprite->_asyncLoadParam.afterLoadCallback = callback; mesh->_asyncLoadParam.afterLoadCallback = callback;
sprite->_asyncLoadParam.texPath = texturePath; mesh->_asyncLoadParam.texPath = texturePath;
sprite->_asyncLoadParam.modelPath = modelPath; mesh->_asyncLoadParam.modelPath = modelPath;
sprite->_asyncLoadParam.modelFullPath = FileUtils::getInstance()->fullPathForFilename(modelPath); mesh->_asyncLoadParam.modelFullPath = FileUtils::getInstance()->fullPathForFilename(modelPath);
sprite->_asyncLoadParam.callbackParam = callbackparam; mesh->_asyncLoadParam.callbackParam = callbackparam;
sprite->_asyncLoadParam.materialdatas = new MaterialDatas(); mesh->_asyncLoadParam.materialdatas = new MaterialDatas();
sprite->_asyncLoadParam.meshdatas = new MeshDatas(); mesh->_asyncLoadParam.meshdatas = new MeshDatas();
sprite->_asyncLoadParam.nodeDatas = new NodeDatas(); mesh->_asyncLoadParam.nodeDatas = new NodeDatas();
AsyncTaskPool::getInstance()->enqueue( AsyncTaskPool::getInstance()->enqueue(
AsyncTaskPool::TaskType::TASK_IO, CC_CALLBACK_1(Sprite3D::afterAsyncLoad, sprite), AsyncTaskPool::TaskType::TASK_IO, CC_CALLBACK_1(MeshRenderer::afterAsyncLoad, mesh),
(void*)(&sprite->_asyncLoadParam), [sprite]() { (void*)(&mesh->_asyncLoadParam), [mesh]() {
sprite->_asyncLoadParam.result = mesh->_asyncLoadParam.result =
sprite->loadFromFile(sprite->_asyncLoadParam.modelFullPath, sprite->_asyncLoadParam.nodeDatas, mesh->loadFromFile(mesh->_asyncLoadParam.modelFullPath, mesh->_asyncLoadParam.nodeDatas,
sprite->_asyncLoadParam.meshdatas, sprite->_asyncLoadParam.materialdatas); 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(); autorelease();
if (asyncParam) if (asyncParam)
{ {
@ -145,11 +145,11 @@ void Sprite3D::afterAsyncLoad(void* param)
auto& nodeDatas = asyncParam->nodeDatas; auto& nodeDatas = asyncParam->nodeDatas;
if (initFrom(*nodeDatas, *meshdatas, *materialdatas)) if (initFrom(*nodeDatas, *meshdatas, *materialdatas))
{ {
auto spritedata = Sprite3DCache::getInstance()->getSpriteData(asyncParam->modelPath); auto meshdata = MeshRendererCache::getInstance()->getMeshData(asyncParam->modelPath);
if (spritedata == nullptr) if (meshdata == nullptr)
{ {
// add to cache // add to cache
auto data = new Sprite3DCache::Sprite3DData(); auto data = new MeshRendererCache::MeshRendererData();
data->materialdatas = materialdatas; data->materialdatas = materialdatas;
data->nodedatas = nodeDatas; data->nodedatas = nodeDatas;
data->meshVertexDatas = _meshVertexDatas; data->meshVertexDatas = _meshVertexDatas;
@ -158,7 +158,7 @@ void Sprite3D::afterAsyncLoad(void* param)
data->programStates.pushBack(mesh->getProgramState()); data->programStates.pushBack(mesh->getProgramState());
} }
Sprite3DCache::getInstance()->addSprite3DData(asyncParam->modelPath, data); MeshRendererCache::getInstance()->addMeshRendererData(asyncParam->modelPath, data);
CC_SAFE_DELETE(meshdatas); CC_SAFE_DELETE(meshdatas);
materialdatas = nullptr; materialdatas = nullptr;
@ -176,13 +176,13 @@ void Sprite3D::afterAsyncLoad(void* param)
} }
else 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); asyncParam->afterLoadCallback(this, asyncParam->callbackParam);
} }
} }
AABB Sprite3D::getAABBRecursivelyImp(Node* node) AABB MeshRenderer::getAABBRecursivelyImp(Node* node)
{ {
AABB aabb; AABB aabb;
for (auto iter : node->getChildren()) for (auto iter : node->getChildren())
@ -190,46 +190,46 @@ AABB Sprite3D::getAABBRecursivelyImp(Node* node)
aabb.merge(getAABBRecursivelyImp(iter)); aabb.merge(getAABBRecursivelyImp(iter));
} }
Sprite3D* sprite3d = dynamic_cast<Sprite3D*>(node); MeshRenderer* meshRenderer = dynamic_cast<MeshRenderer*>(node);
if (sprite3d) if (meshRenderer)
aabb.merge(sprite3d->getAABB()); aabb.merge(meshRenderer->getAABB());
return aabb; return aabb;
} }
bool Sprite3D::loadFromCache(std::string_view path) bool MeshRenderer::loadFromCache(std::string_view path)
{ {
auto spritedata = Sprite3DCache::getInstance()->getSpriteData(path); auto meshdata = MeshRendererCache::getInstance()->getMeshData(path);
if (spritedata) if (meshdata)
{ {
for (auto it : spritedata->meshVertexDatas) for (auto it : meshdata->meshVertexDatas)
{ {
_meshVertexDatas.pushBack(it); _meshVertexDatas.pushBack(it);
} }
_skeleton = Skeleton3D::create(spritedata->nodedatas->skeleton); _skeleton = Skeleton3D::create(meshdata->nodedatas->skeleton);
CC_SAFE_RETAIN(_skeleton); CC_SAFE_RETAIN(_skeleton);
const bool singleSprite = (spritedata->nodedatas->nodes.size() == 1); const bool singleMesh = (meshdata->nodedatas->nodes.size() == 1);
for (const auto& it : spritedata->nodedatas->nodes) for (const auto& it : meshdata->nodedatas->nodes)
{ {
if (it) 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) if (it)
{ {
createAttachSprite3DNode(it, *(spritedata->materialdatas)); createAttachMeshRendererNode(it, *(meshdata->materialdatas));
} }
} }
for (ssize_t i = 0, size = _meshes.size(); i < size; ++i) for (ssize_t i = 0, size = _meshes.size(); i < size; ++i)
{ {
// cloning is needed in order to have one state per sprite // cloning is needed in order to have one state per mesh
auto glstate = spritedata->programStates.at(i); auto glstate = meshdata->programStates.at(i);
_meshes.at(i)->setProgramState(glstate->clone()); _meshes.at(i)->setProgramState(glstate->clone());
} }
return true; return true;
@ -238,7 +238,7 @@ bool Sprite3D::loadFromCache(std::string_view path)
return false; return false;
} }
bool Sprite3D::loadFromFile(std::string_view path, bool MeshRenderer::loadFromFile(std::string_view path,
NodeDatas* nodedatas, NodeDatas* nodedatas,
MeshDatas* meshdatas, MeshDatas* meshdatas,
MaterialDatas* materialdatas) MaterialDatas* materialdatas)
@ -269,7 +269,7 @@ bool Sprite3D::loadFromFile(std::string_view path,
return false; return false;
} }
Sprite3D::Sprite3D() MeshRenderer::MeshRenderer()
: _skeleton(nullptr) : _skeleton(nullptr)
, _blend(BlendFunc::ALPHA_NON_PREMULTIPLIED) , _blend(BlendFunc::ALPHA_NON_PREMULTIPLIED)
, _aabbDirty(true) , _aabbDirty(true)
@ -279,7 +279,7 @@ Sprite3D::Sprite3D()
, _usingAutogeneratedGLProgram(true) , _usingAutogeneratedGLProgram(true)
{} {}
Sprite3D::~Sprite3D() MeshRenderer::~MeshRenderer()
{ {
_meshes.clear(); _meshes.clear();
_meshVertexDatas.clear(); _meshVertexDatas.clear();
@ -287,7 +287,7 @@ Sprite3D::~Sprite3D()
removeAllAttachNode(); removeAllAttachNode();
} }
bool Sprite3D::init() bool MeshRenderer::init()
{ {
if (Node::init()) if (Node::init())
{ {
@ -296,7 +296,7 @@ bool Sprite3D::init()
return false; return false;
} }
bool Sprite3D::initWithFile(std::string_view path) bool MeshRenderer::initWithFile(std::string_view path)
{ {
_aabbDirty = true; _aabbDirty = true;
_meshes.clear(); _meshes.clear();
@ -315,7 +315,7 @@ bool Sprite3D::initWithFile(std::string_view path)
if (initFrom(*nodeDatas, *meshdatas, *materialdatas)) if (initFrom(*nodeDatas, *meshdatas, *materialdatas))
{ {
// add to cache // add to cache
auto data = new Sprite3DCache::Sprite3DData(); auto data = new MeshRendererCache::MeshRendererData();
data->materialdatas = materialdatas; data->materialdatas = materialdatas;
data->nodedatas = nodeDatas; data->nodedatas = nodeDatas;
data->meshVertexDatas = _meshVertexDatas; data->meshVertexDatas = _meshVertexDatas;
@ -324,7 +324,7 @@ bool Sprite3D::initWithFile(std::string_view path)
data->programStates.pushBack(mesh->getProgramState()); data->programStates.pushBack(mesh->getProgramState());
} }
Sprite3DCache::getInstance()->addSprite3DData(path, data); MeshRendererCache::getInstance()->addMeshRendererData(path, data);
CC_SAFE_DELETE(meshdatas); CC_SAFE_DELETE(meshdatas);
_contentSize = getBoundingBox().size; _contentSize = getBoundingBox().size;
return true; return true;
@ -337,7 +337,7 @@ bool Sprite3D::initWithFile(std::string_view path)
return false; 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) for (const auto& it : meshdatas.meshDatas)
{ {
@ -364,7 +364,7 @@ bool Sprite3D::initFrom(const NodeDatas& nodeDatas, const MeshDatas& meshdatas,
{ {
if (it) if (it)
{ {
createAttachSprite3DNode(it, materialdatas); createAttachMeshRendererNode(it, materialdatas);
} }
} }
genMaterial(); genMaterial();
@ -372,11 +372,11 @@ bool Sprite3D::initFrom(const NodeDatas& nodeDatas, const MeshDatas& meshdatas,
return true; 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)); auto mesh = Mesh::create(nodedata->id, getMeshIndexData(modeldata->subMeshId));
if (_skeleton && modeldata->bones.size()) if (_skeleton && modeldata->bones.size())
@ -434,46 +434,46 @@ Sprite3D* Sprite3D::createSprite3DNode(NodeData* nodedata, ModelData* modeldata,
Quaternion qua; Quaternion qua;
Vec3 scale; Vec3 scale;
nodedata->transform.decompose(&scale, &qua, &pos); nodedata->transform.decompose(&scale, &qua, &pos);
sprite->setPosition3D(pos); meshRenderer->setPosition3D(pos);
sprite->setRotationQuat(qua); meshRenderer->setRotationQuat(qua);
sprite->setScaleX(scale.x); meshRenderer->setScaleX(scale.x);
sprite->setScaleY(scale.y); meshRenderer->setScaleY(scale.y);
sprite->setScaleZ(scale.z); meshRenderer->setScaleZ(scale.z);
sprite->addMesh(mesh); meshRenderer->addMesh(mesh);
sprite->autorelease(); meshRenderer->autorelease();
sprite->genMaterial(); 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) for (const auto& it : nodedata->modelNodeDatas)
{ {
if (it && getAttachNode(nodedata->id)) if (it && getAttachNode(nodedata->id))
{ {
auto sprite = createSprite3DNode(nodedata, it, materialdatas); auto mesh = createMeshRendererNode(nodedata, it, materialdatas);
if (sprite) if (mesh)
{ {
getAttachNode(nodedata->id)->addChild(sprite); getAttachNode(nodedata->id)->addChild(mesh);
} }
} }
} }
for (const auto& it : nodedata->children) 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); setMaterial(material, -1);
} }
void Sprite3D::setMaterial(Material* material, int meshIndex) void MeshRenderer::setMaterial(Material* material, int meshIndex)
{ {
CCASSERT(material, "Invalid Material"); 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) if (meshIndex == -1)
{ {
@ -491,21 +491,21 @@ void Sprite3D::setMaterial(Material* material, int meshIndex)
_usingAutogeneratedGLProgram = false; _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(); return _meshes.at(meshIndex)->getMaterial();
} }
void Sprite3D::genMaterial(bool useLight) void MeshRenderer::genMaterial(bool useLight)
{ {
_shaderUsingLight = useLight; _shaderUsingLight = useLight;
std::unordered_map<const MeshVertexData*, Sprite3DMaterial*> materials; std::unordered_map<const MeshVertexData*, MeshMaterial*> materials;
for (auto meshVertexData : _meshVertexDatas) for (auto meshVertexData : _meshVertexDatas)
{ {
auto material = getSprite3DMaterialForAttribs(meshVertexData, useLight); auto material = getMeshRendererMaterialForAttribs(meshVertexData, useLight);
CCASSERT(material, "material should not be null"); CCASSERT(material, "material should cannot be null.");
materials[meshVertexData] = material; 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; Node* node = nullptr;
for (const auto& it : nodedata->modelNodeDatas) for (const auto& it : nodedata->modelNodeDatas)
{ {
if (it) if (it)
{ {
if (!it->bones.empty() || singleSprite) if (!it->bones.empty() || singleMesh)
{ {
if (singleSprite && root != nullptr) if (singleMesh && root != nullptr)
root->setName(nodedata->id); root->setName(nodedata->id);
auto mesh = Mesh::create(nodedata->id, getMeshIndexData(it->subMeshId)); auto mesh = Mesh::create(nodedata->id, getMeshIndexData(it->subMeshId));
if (mesh) 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); auto skin = MeshSkin::create(_skeleton, it->bones, it->invBindPose);
mesh->setSkin(skin); mesh->setSkin(skin);
} }
mesh->_visibleChanged = std::bind(&Sprite3D::onAABBDirty, this); mesh->_visibleChanged = std::bind(&MeshRenderer::onAABBDirty, this);
if (it->materialId == "" && materialdatas.materials.size()) if (it->materialId == "" && materialdatas.materials.size())
{ {
@ -610,15 +610,15 @@ void Sprite3D::createNode(NodeData* nodedata, Node* root, const MaterialDatas& m
} }
else else
{ {
auto sprite = createSprite3DNode(nodedata, it, materialdatas); auto mesh = createMeshRendererNode(nodedata, it, materialdatas);
if (sprite) if (mesh)
{ {
if (root) 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) for (auto it : _meshVertexDatas)
{ {
@ -665,27 +665,27 @@ MeshIndexData* Sprite3D::getMeshIndexData(std::string_view indexId) const
return nullptr; return nullptr;
} }
void Sprite3D::addMesh(Mesh* mesh) void MeshRenderer::addMesh(Mesh* mesh)
{ {
auto meshVertex = mesh->getMeshIndexData()->_vertexData; auto meshVertex = mesh->getMeshIndexData()->_vertexData;
_meshVertexDatas.pushBack(meshVertex); _meshVertexDatas.pushBack(meshVertex);
_meshes.pushBack(mesh); _meshes.pushBack(mesh);
} }
void Sprite3D::setTexture(std::string_view texFile) void MeshRenderer::setTexture(std::string_view texFile)
{ {
auto tex = _director->getTextureCache()->addImage(texFile); auto tex = _director->getTextureCache()->addImage(texFile);
setTexture(tex); setTexture(tex);
} }
void Sprite3D::setTexture(Texture2D* texture) void MeshRenderer::setTexture(Texture2D* texture)
{ {
for (auto mesh : _meshes) for (auto mesh : _meshes)
{ {
mesh->setTexture(texture); mesh->setTexture(texture);
} }
} }
AttachNode* Sprite3D::getAttachNode(std::string_view boneName) AttachNode* MeshRenderer::getAttachNode(std::string_view boneName)
{ {
auto it = _attachments.find(boneName); auto it = _attachments.find(boneName);
if (it != _attachments.end()) if (it != _attachments.end())
@ -706,7 +706,7 @@ AttachNode* Sprite3D::getAttachNode(std::string_view boneName)
return nullptr; return nullptr;
} }
void Sprite3D::removeAttachNode(std::string_view boneName) void MeshRenderer::removeAttachNode(std::string_view boneName)
{ {
auto it = _attachments.find(boneName); auto it = _attachments.find(boneName);
if (it != _attachments.end()) 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) for (auto& it : _attachments)
{ {
@ -725,7 +725,7 @@ void Sprite3D::removeAllAttachNode()
_attachments.clear(); _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. // quick return if not visible. children won't be drawn.
if (!_visible) if (!_visible)
@ -772,7 +772,7 @@ void Sprite3D::visit(cocos2d::Renderer* renderer, const cocos2d::Mat4& parentTra
_director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); _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 #if CC_USE_CULLING
// TODO new-renderer: interface isVisibleInFrustum removal // 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)) if (Node::setProgramState(programState, needsRetain))
{ {
@ -828,7 +828,7 @@ bool Sprite3D::setProgramState(backend::ProgramState* programState, bool needsRe
return false; return false;
} }
void Sprite3D::setBlendFunc(const BlendFunc& blendFunc) void MeshRenderer::setBlendFunc(const BlendFunc& blendFunc)
{ {
if (_blend.src != blendFunc.src || _blend.dst != blendFunc.dst) 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; return _blend;
} }
AABB Sprite3D::getAABBRecursively() AABB MeshRenderer::getAABBRecursively()
{ {
return getAABBRecursivelyImp(this); return getAABBRecursivelyImp(this);
} }
const AABB& Sprite3D::getAABB() const const AABB& MeshRenderer::getAABB() const
{ {
Mat4 nodeToWorldTransform(getNodeToWorldTransform()); Mat4 nodeToWorldTransform(getNodeToWorldTransform());
@ -880,45 +880,43 @@ const AABB& Sprite3D::getAABB() const
return _aabb; return _aabb;
} }
Action* Sprite3D::runAction(Action* action) Action* MeshRenderer::runAction(Action* action)
{ {
setForceDepthWrite(true); setForceDepthWrite(true);
return Node::runAction(action); return Node::runAction(action);
} }
Rect Sprite3D::getBoundingBox() const Rect MeshRenderer::getBoundingBox() const
{ {
AABB aabb = getAABB(); AABB aabb = getAABB();
Rect ret(aabb._min.x, aabb._min.y, (aabb._max.x - aabb._min.x), (aabb._max.y - aabb._min.y)); Rect ret(aabb._min.x, aabb._min.y, (aabb._max.x - aabb._min.x), (aabb._max.y - aabb._min.y));
return ret; return ret;
} }
void Sprite3D::setCullFace(CullFaceSide side) void MeshRenderer::setCullFace(CullFaceSide side)
{ {
for (auto& it : _meshes) for (auto& it : _meshes)
{ {
it->getMaterial()->getStateBlock().setCullFaceSide(side); it->getMaterial()->getStateBlock().setCullFaceSide(side);
// it->getMeshCommand().setCullFace(cullFace);
} }
} }
void Sprite3D::setCullFaceEnabled(bool enable) void MeshRenderer::setCullFaceEnabled(bool enable)
{ {
for (auto& it : _meshes) for (auto& it : _meshes)
{ {
it->getMaterial()->getStateBlock().setCullFace(enable); 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); return _meshes.at(index);
} }
/**get Mesh by Name */ /**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) for (const auto& it : _meshes)
{ {
@ -928,7 +926,7 @@ Mesh* Sprite3D::getMeshByName(std::string_view name) const
return nullptr; 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; std::vector<Mesh*> meshes;
for (const auto& it : _meshes) for (const auto& it : _meshes)
@ -939,7 +937,7 @@ std::vector<Mesh*> Sprite3D::getMeshArrayByName(std::string_view name) const
return meshes; return meshes;
} }
Mesh* Sprite3D::getMesh() const Mesh* MeshRenderer::getMesh() const
{ {
if (_meshes.empty()) if (_meshes.empty())
{ {
@ -948,7 +946,7 @@ Mesh* Sprite3D::getMesh() const
return _meshes.at(0); return _meshes.at(0);
} }
void Sprite3D::setForce2DQueue(bool force2D) void MeshRenderer::setForce2DQueue(bool force2D)
{ {
for (const auto& mesh : _meshes) for (const auto& mesh : _meshes)
{ {
@ -957,14 +955,14 @@ void Sprite3D::setForce2DQueue(bool force2D)
} }
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
Sprite3DCache* Sprite3DCache::_cacheInstance = nullptr; MeshRendererCache* MeshRendererCache::_cacheInstance = nullptr;
Sprite3DCache* Sprite3DCache::getInstance() MeshRendererCache* MeshRendererCache::getInstance()
{ {
if (_cacheInstance == nullptr) if (_cacheInstance == nullptr)
_cacheInstance = new Sprite3DCache(); _cacheInstance = new MeshRendererCache();
return _cacheInstance; return _cacheInstance;
} }
void Sprite3DCache::destroyInstance() void MeshRendererCache::destroyInstance()
{ {
if (_cacheInstance) 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); auto it = _meshDatas.find(key);
if (it != _spriteDatas.end()) if (it != _meshDatas.end())
return it->second; return it->second;
return nullptr; 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); auto it = _meshDatas.find(key);
if (it == _spriteDatas.end()) if (it == _meshDatas.end())
{ {
_spriteDatas.emplace(key, spritedata); // _spriteDatas[key] = spritedata; _meshDatas.emplace(key, meshdata);
return true; return true;
} }
return false; return false;
} }
void Sprite3DCache::removeSprite3DData(std::string_view key) void MeshRendererCache::removeMeshRendererData(std::string_view key)
{ {
auto it = _spriteDatas.find(key); auto it = _meshDatas.find(key);
if (it != _spriteDatas.end()) if (it != _meshDatas.end())
{ {
delete it->second; 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; delete it.second;
} }
_spriteDatas.clear(); _meshDatas.clear();
} }
Sprite3DCache::Sprite3DCache() {} MeshRendererCache::MeshRendererCache() {}
Sprite3DCache::~Sprite3DCache() MeshRendererCache::~MeshRendererCache()
{ {
removeAllSprite3DData(); removeAllMeshRendererData();
} }
// static MeshMaterial* getMeshRendererMaterialForAttribs(MeshVertexData* meshVertexData, bool usesLight)
// MARK: Helpers
//
static Sprite3DMaterial* getSprite3DMaterialForAttribs(MeshVertexData* meshVertexData, bool usesLight)
{ {
bool textured = meshVertexData->hasVertexAttrib(shaderinfos::VertexKey::VERTEX_ATTRIB_TEX_COORD); bool textured = meshVertexData->hasVertexAttrib(shaderinfos::VertexKey::VERTEX_ATTRIB_TEX_COORD);
bool hasSkin = meshVertexData->hasVertexAttrib(shaderinfos::VertexKey::VERTEX_ATTRIB_BLEND_INDEX) && 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 hasNormal = meshVertexData->hasVertexAttrib(shaderinfos::VertexKey::VERTEX_ATTRIB_NORMAL);
bool hasTangentSpace = meshVertexData->hasVertexAttrib(shaderinfos::VertexKey::VERTEX_ATTRIB_TANGENT) && bool hasTangentSpace = meshVertexData->hasVertexAttrib(shaderinfos::VertexKey::VERTEX_ATTRIB_TANGENT) &&
meshVertexData->hasVertexAttrib(shaderinfos::VertexKey::VERTEX_ATTRIB_BINORMAL); meshVertexData->hasVertexAttrib(shaderinfos::VertexKey::VERTEX_ATTRIB_BINORMAL);
Sprite3DMaterial::MaterialType type; MeshMaterial::MaterialType type;
if (textured) if (textured)
{ {
if (hasTangentSpace) if (hasTangentSpace)
{ {
type = hasNormal && usesLight ? Sprite3DMaterial::MaterialType::BUMPED_DIFFUSE type = hasNormal && usesLight ? MeshMaterial::MaterialType::BUMPED_DIFFUSE
: Sprite3DMaterial::MaterialType::UNLIT; : MeshMaterial::MaterialType::UNLIT;
} }
else else
{ {
type = hasNormal && usesLight ? Sprite3DMaterial::MaterialType::DIFFUSE type = hasNormal && usesLight ? MeshMaterial::MaterialType::DIFFUSE
: Sprite3DMaterial::MaterialType::UNLIT; : MeshMaterial::MaterialType::UNLIT;
} }
} }
else else
{ {
type = hasNormal && usesLight ? Sprite3DMaterial::MaterialType::DIFFUSE_NOTEX type = hasNormal && usesLight ? MeshMaterial::MaterialType::DIFFUSE_NOTEX
: Sprite3DMaterial::MaterialType::UNLIT_NOTEX; : MeshMaterial::MaterialType::UNLIT_NOTEX;
} }
return Sprite3DMaterial::createBuiltInMaterial(type, hasSkin); return MeshMaterial::createBuiltInMaterial(type, hasSkin);
} }
NS_CC_END NS_CC_END

View File

@ -23,8 +23,8 @@
THE SOFTWARE. THE SOFTWARE.
****************************************************************************/ ****************************************************************************/
#ifndef __CCSPRITE3D_H__ #ifndef __CC_MESH_RENDERER_H__
#define __CCSPRITE3D_H__ #define __CC_MESH_RENDERER_H__
#include <unordered_map> #include <unordered_map>
@ -33,7 +33,7 @@
#include "base/CCProtocols.h" #include "base/CCProtocols.h"
#include "2d/CCNode.h" #include "2d/CCNode.h"
#include "renderer/CCMeshCommand.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/CCAABB.h"
#include "3d/CCBundle3DData.h" #include "3d/CCBundle3DData.h"
#include "3d/CCMeshVertexIndexData.h" #include "3d/CCMeshVertexIndexData.h"
@ -50,49 +50,52 @@ class Texture2D;
class MeshSkin; class MeshSkin;
class AttachNode; class AttachNode;
struct NodeData; struct NodeData;
/** @brief Sprite3D: A sprite can be loaded from 3D model files, .obj, .c3t, .c3b, then can be drawn as sprite */ /** @brief MeshRenderer: A mesh can be loaded from model files, .obj, .c3t, .c3b
class CC_DLL Sprite3D : public Node, public BlendProtocol *and a mesh renderer renders a list of these loaded meshes with specified materials
*/
class CC_DLL MeshRenderer : public Node, public BlendProtocol
{ {
public: 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*/ /** creates a MeshRenderer with a specified path */
static Sprite3D* create(std::string_view modelPath); static MeshRenderer* create(std::string_view modelPath);
// creates a Sprite3D. It only supports one texture, and overrides the internal texture with 'texturePath' /** creates a MeshRenderer. A mesh can only have one texture, the default texture can be overridden with 'texturePath' */
static Sprite3D* create(std::string_view modelPath, std::string_view texturePath); static MeshRenderer* create(std::string_view modelPath, std::string_view texturePath);
/** create 3d sprite asynchronously /** create 3d mesh asynchronously
* If the 3d model was previously loaded, it will create a new 3d sprite and the callback will be called at once. * 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 sprite is loaded, the callback will be * 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 Sprite3D and a user-defined parameter. The callback will be called from the main thread, * 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 cocos2d object from the callback. * so it is safe to create any object from the callback.
* @param modelPath model to be loaded * @param modelPath model to be loaded
* @param callback callback after loading * @param callback callback when loading is finished
* @param callbackparam user defined parameter for the callback * @param callbackparam user-defined parameter for the callback
*/ */
static void createAsync(std::string_view modelPath, static void createAsync(std::string_view modelPath,
const std::function<void(Sprite3D*, void*)>& callback, const std::function<void(MeshRenderer*, void*)>& callback,
void* callbackparam); void* callbackparam);
static void createAsync(std::string_view modelPath, static void createAsync(std::string_view modelPath,
std::string_view texturePath, std::string_view texturePath,
const std::function<void(Sprite3D*, void*)>& callback, const std::function<void(MeshRenderer*, void*)>& callback,
void* callbackparam); 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(std::string_view texFile);
void setTexture(Texture2D* texture); void setTexture(Texture2D* texture);
/**get Mesh by index*/ /** get Mesh by index */
Mesh* getMeshByIndex(int index) const; 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; Mesh* getMeshByName(std::string_view name) const;
/** /**
@ -102,7 +105,7 @@ public:
*/ */
std::vector<Mesh*> getMeshArrayByName(std::string_view name) const; std::vector<Mesh*> getMeshArrayByName(std::string_view name) const;
/**get mesh*/ /** get mesh at index 0 which is the default mesh */
Mesh* getMesh() const; Mesh* getMesh() const;
/** get mesh count */ /** get mesh count */
@ -110,13 +113,13 @@ public:
Skeleton3D* getSkeleton() const { return _skeleton; } 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); AttachNode* getAttachNode(std::string_view boneName);
/**remove attach node*/ /** remove an attached node */
void removeAttachNode(std::string_view boneName); void removeAttachNode(std::string_view boneName);
/**remove all attach nodes*/ /** remove all attached nodes */
void removeAllAttachNode(); void removeAllAttachNode();
// overrides // overrides
@ -124,91 +127,88 @@ public:
virtual const BlendFunc& getBlendFunc() const override; virtual const BlendFunc& getBlendFunc() const override;
// overrides // 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; bool setProgramState(backend::ProgramState* programState, bool needsRetain = true) override;
/* /*
* Get AABB * Get AABB
* If the sprite has animation, it can't be calculated accurately, * If the mesh has animations, it can't be calculated accurately,
* because bone can drive the vertices, we just use the origin vertices * because a bone can transform the vertices, and the untransformed vertices are used
* to calculate the AABB. * to calculate the AABB.
*/ */
const AABB& getAABB() const; const AABB& getAABB() const;
/* /*
* Get AABB Recursively * Get AABB Recursively
* Because some times we may have an empty Sprite3D Node as parent, but * Because sometimes we may have an empty MeshRenderer Node as parent, If
* the Sprite3D don't contain any meshes, so getAABB() * the MeshRenderer doesn't contain any meshes, then we use getAABB()
* will return a wrong value at that time.
*/ */
AABB getAABBRecursively(); AABB getAABBRecursively();
/** /**
* Executes an action, and returns the action that is executed. For Sprite3D special logic are needed to take care * Executes an action, and returns the action that is executed. For the MeshRenderer special logic is needed to take
* of Fading. * care of Fading.
* *
* This node becomes the action's target. Refer to Action::getTarget() * This node becomes the action's target. Refer to Action::getTarget()
* @warning Actions don't retain their target. * @warning Actions don't retain their target.
* *
* @return An Action pointer * @return a pointer to Action
*/ */
virtual Action* runAction(Action* action) override; 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; } void setForceDepthWrite(bool value) { _forceDepthWrite = value; }
bool isForceDepthWrite() const { return _forceDepthWrite; }; bool isForceDepthWrite() const { return _forceDepthWrite; };
/** /**
* Returns 2d bounding-box * Returns a 2d bounding-box
* Note: the bounding-box is just get from the AABB which as Z=0, so that is not very accurate. * Note: the bounding-box is taken from the mesh's AABB with Z-axis ignored.
*/ */
virtual Rect getBoundingBox() const override; 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); virtual void setCullFace(CullFaceSide side);
// set cull face enable or not // set face culling enabled.
void setCullFaceEnabled(bool enable); void setCullFaceEnabled(bool enable);
/** light mask getter & setter, light works only when _lightmask & light's flag is true, default value of _lightmask /** light mask getter & setter, lighting only works when _lightmask & light's flag are set to true, the default
* is 0xffff */ value of _lightmask is 0xffff */
void setLightMask(unsigned int mask) { _lightMask = mask; } void setLightMask(unsigned int mask) { _lightMask = mask; }
unsigned int getLightMask() const { return _lightMask; } 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; virtual void draw(Renderer* renderer, const Mat4& transform, uint32_t flags) override;
/** Adds a new material to the sprite. /** Adds a new material to this mesh renderer.
The Material will be applied to all the meshes that belong to the sprite. The Material will be applied to all the meshes that belong to the mesh renderer.
Internally it will call `setMaterial(material,-1)` It will internally call `setMaterial(material,-1)`
*/ */
void setMaterial(Material* material); void setMaterial(Material* material);
/** Adds a new material to a particular mesh of the sprite. /** Adds a new material to a particular mesh in this mesh renderer.
meshIndex is the mesh that will be applied to. * if meshIndex == -1, then it will be applied to all the meshes that belong to this mesh renderer.
if meshIndex == -1, then it will be applied to all the meshes that belong to the sprite. *
* @param meshIndex Index of the mesh to apply the material to.
*/ */
void setMaterial(Material* material, int meshIndex); void setMaterial(Material* material, int meshIndex);
/** Adds a new material to a particular mesh of the sprite. /** Adds a new material to a particular mesh in this mesh renderer.
meshIndex is the mesh that will be applied to. * if meshIndex == -1, then it will be applied to all the meshes that belong to this mesh renderer.
if meshIndex == -1, then it will be applied to all the meshes that belong to the sprite. *
* @param meshIndex Index of the mesh to apply the material to.
*/ */
Material* getMaterial(int meshIndex) const; Material* getMaterial(int meshIndex) const;
/** /** force render this mesh renderer in 2D queue. */
* force set this Sprite3D to 2D render queue
*/
void setForce2DQueue(bool force2D); void setForce2DQueue(bool force2D);
/** /** Get list of meshes used in this mesh renderer. */
* Get meshes used in sprite 3d
*/
const Vector<Mesh*>& getMeshes() const { return _meshes; } const Vector<Mesh*>& getMeshes() const { return _meshes; }
Sprite3D(); MeshRenderer();
virtual ~Sprite3D(); virtual ~MeshRenderer();
virtual bool init() override; virtual bool init() override;
@ -216,27 +216,28 @@ public:
bool initFrom(const NodeDatas& nodedatas, const MeshDatas& meshdatas, const MaterialDatas& materialdatas); 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); 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 /** load a file and feed it's content into meshedatas, nodedatas and materialdatas, obj file and .mtl file
* directory if exist */ should be in the same directory. */
bool loadFromFile(std::string_view path, NodeDatas* nodedatas, MeshDatas* meshdatas, MaterialDatas* materialdatas); bool loadFromFile(std::string_view path, NodeDatas* nodedatas, MeshDatas* meshdatas, MaterialDatas* materialdatas);
/** /**
* Visits this Sprite3D's children and draw them recursively. * Visits this MeshRenderer's children and draws them recursively.
* Note: all its children will rendered as 3D objects * 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; virtual void visit(Renderer* renderer, const Mat4& parentTransform, uint32_t parentFlags) override;
/**generate default material*/ /** generate default material. */
void genMaterial(bool useLight = false); void genMaterial(bool useLight = false);
void createNode(NodeData* nodedata, Node* root, const MaterialDatas& materialdatas, bool singleSprite); void createNode(NodeData* nodedata, Node* root, const MaterialDatas& materialdatas, bool singleMesh);
void createAttachSprite3DNode(NodeData* nodedata, const MaterialDatas& materialdatas); void createAttachMeshRendererNode(NodeData* nodedata, const MaterialDatas& materialdatas);
Sprite3D* createSprite3DNode(NodeData* nodedata, ModelData* modeldata, 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; MeshIndexData* getMeshIndexData(std::string_view indexId) const;
void addMesh(Mesh* mesh); void addMesh(Mesh* mesh);
@ -248,7 +249,7 @@ public:
static AABB getAABBRecursivelyImp(Node* node); static AABB getAABBRecursivelyImp(Node* node);
protected: protected:
Skeleton3D* _skeleton; // skeleton Skeleton3D* _skeleton;
Vector<MeshVertexData*> _meshVertexDatas; Vector<MeshVertexData*> _meshVertexDatas;
@ -259,21 +260,21 @@ protected:
Vector<Mesh*> _meshes; Vector<Mesh*> _meshes;
mutable AABB _aabb; // cache current aabb mutable AABB _aabb; // cache current aabb
mutable Mat4 _nodeToWorldTransform; // cache the matrix mutable Mat4 _nodeToWorldTransform; // cache current matrix
mutable bool _aabbDirty; mutable bool _aabbDirty;
unsigned int _lightMask; 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 _forceDepthWrite; // Always write to depth buffer
bool _usingAutogeneratedGLProgram; bool _usingAutogeneratedGLProgram;
struct AsyncLoadParam struct AsyncLoadParam
{ {
std::function<void(Sprite3D*, void*)> afterLoadCallback; // callback after load std::function<void(MeshRenderer*, void*)> afterLoadCallback; // callback after loading is finished
void* callbackParam; void* callbackParam;
bool result; // sprite load result bool result; // mesh renderer loading result
std::string modelPath; std::string modelPath;
std::string modelFullPath; std::string modelFullPath;
std::string texPath; // std::string texPath;
MeshDatas* meshdatas; MeshDatas* meshdatas;
MaterialDatas* materialdatas; MaterialDatas* materialdatas;
NodeDatas* nodeDatas; NodeDatas* nodeDatas;
@ -283,19 +284,18 @@ protected:
/////////////////////////////////////////////////////// ///////////////////////////////////////////////////////
/** /**
* Sprite3DCache * @brief MeshRendererCache: the cache data of MeshRenderer, used to speed up the creation process of MeshRenderer
* @brief the cache data of Sprite3D, use to speed up Sprite3D::create
*/ */
class CC_DLL Sprite3DCache class CC_DLL MeshRendererCache
{ {
public: public:
struct Sprite3DData struct MeshRendererData
{ {
Vector<MeshVertexData*> meshVertexDatas; Vector<MeshVertexData*> meshVertexDatas;
Vector<backend::ProgramState*> programStates; Vector<backend::ProgramState*> programStates;
NodeDatas* nodedatas; NodeDatas* nodedatas;
MaterialDatas* materialdatas; MaterialDatas* materialdatas;
~Sprite3DData() ~MeshRendererData()
{ {
if (nodedatas) if (nodedatas)
delete nodedatas; delete nodedatas;
@ -306,40 +306,39 @@ public:
} }
}; };
/**get & destroy*/ static MeshRendererCache* getInstance();
static Sprite3DCache* getInstance();
static void destroyInstance(); static void destroyInstance();
/** /**
* get the SpriteData struct * get a MeshData object by key
* *
* @lua NA * @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 * @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*/ /** remove a MeshData from the MeshRenderer with a specified key */
void removeSprite3DData(std::string_view key); void removeMeshRendererData(std::string_view key);
/**remove all the SpriteData from Sprite3D*/ /** remove all the MeshData objects from the MeshRenderer */
void removeAllSprite3DData(); void removeAllMeshRendererData();
Sprite3DCache(); MeshRendererCache();
~Sprite3DCache(); ~MeshRendererCache();
protected: protected:
static Sprite3DCache* _cacheInstance; static MeshRendererCache* _cacheInstance;
hlookup::string_map<Sprite3DData*> _spriteDatas; // cached sprite data hlookup::string_map<MeshRendererData*> _meshDatas; // cached mesh data
}; };
// end of 3d group // end of 3d group
/// @} /// @}
NS_CC_END NS_CC_END
#endif // __SPRITE3D_H_ #endif // __CC_MESH_RENDERER_H__

View File

@ -30,7 +30,7 @@
#include "3d/CCMeshVertexIndexData.h" #include "3d/CCMeshVertexIndexData.h"
#include "3d/CCObjLoader.h" #include "3d/CCObjLoader.h"
#include "3d/CCSprite3DMaterial.h" #include "3d/CCMeshMaterial.h"
#include "3d/CCMesh.h" #include "3d/CCMesh.h"
#include "3d/CCBundle3D.h" #include "3d/CCBundle3D.h"

View File

@ -95,7 +95,7 @@ protected:
MeshData::IndexArray _indexData; MeshData::IndexArray _indexData;
friend class MeshVertexData; friend class MeshVertexData;
friend class Sprite3D; friend class MeshRenderer;
#if CC_ENABLE_CACHE_TEXTURE_DATA #if CC_ENABLE_CACHE_TEXTURE_DATA
EventListenerCustom* _backToForegroundListener = nullptr; EventListenerCustom* _backToForegroundListener = nullptr;
#endif #endif
@ -107,7 +107,7 @@ protected:
*/ */
class CC_DLL MeshVertexData : public Ref class CC_DLL MeshVertexData : public Ref
{ {
friend class Sprite3D; friend class MeshRenderer;
friend class Mesh; friend class Mesh;
public: public:

View File

@ -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 * @brief Oriented Bounding Box(OBB): OBB is similar to AABB except the bounding box has the same direction as the
* detection more precise than AABB * MeshRenderer. so collision detection is more precise than AABB.
* @js NA * @js NA
*/ */
class CC_DLL OBB class CC_DLL OBB

View File

@ -2,7 +2,6 @@ set(COCOS_3D_HEADER
3d/CCBillBoard.h 3d/CCBillBoard.h
3d/CCFrustum.h 3d/CCFrustum.h
3d/CCSprite3DMaterial.h
3d/CCMeshVertexIndexData.h 3d/CCMeshVertexIndexData.h
3d/CCPlane.h 3d/CCPlane.h
3d/CCRay.h 3d/CCRay.h
@ -10,7 +9,8 @@ set(COCOS_3D_HEADER
3d/CCAnimate3D.h 3d/CCAnimate3D.h
3d/CCTerrain.h 3d/CCTerrain.h
3d/CCAnimationCurve.h 3d/CCAnimationCurve.h
3d/CCSprite3D.h 3d/CCMeshRenderer.h
3d/CCMeshMaterial.h
3d/CCOBB.h 3d/CCOBB.h
3d/CCAnimation3D.h 3d/CCAnimation3D.h
3d/CCMotionStreak3D.h 3d/CCMotionStreak3D.h
@ -49,8 +49,8 @@ set(COCOS_3D_SRC
3d/CCRay.cpp 3d/CCRay.cpp
3d/CCSkeleton3D.cpp 3d/CCSkeleton3D.cpp
3d/CCSkybox.cpp 3d/CCSkybox.cpp
3d/CCSprite3D.cpp 3d/CCMeshRenderer.cpp
3d/CCSprite3DMaterial.cpp 3d/CCMeshMaterial.cpp
3d/CCTerrain.cpp 3d/CCTerrain.cpp
3d/CCVertexAttribBinding.cpp 3d/CCVertexAttribBinding.cpp
3d/CC3DProgramInfo.cpp 3d/CC3DProgramInfo.cpp

View File

@ -265,8 +265,8 @@ THE SOFTWARE.
#include "3d/CCRay.h" #include "3d/CCRay.h"
#include "3d/CCSkeleton3D.h" #include "3d/CCSkeleton3D.h"
#include "3d/CCSkybox.h" #include "3d/CCSkybox.h"
#include "3d/CCSprite3D.h" #include "3d/CCMeshRenderer.h"
#include "3d/CCSprite3DMaterial.h" #include "3d/CCMeshMaterial.h"
#include "3d/CCTerrain.h" #include "3d/CCTerrain.h"
#include "3d/CCVertexAttribBinding.h" #include "3d/CCVertexAttribBinding.h"

View File

@ -176,34 +176,34 @@ public:
*/ */
bool supportsMapBuffer() const; 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 * @since v3.3
*/ */
int getMaxSupportDirLightInShader() const; 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 * @since v3.3
*/ */
int getMaxSupportPointLightInShader() const; 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 * @since v3.3
*/ */
int getMaxSupportSpotLightInShader() const; int getMaxSupportSpotLightInShader() const;
/** get 3d animate quality*/ /** get 3d animate quality */
Animate3DQuality getAnimate3DQuality() const; 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. * @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; bool checkForGLExtension(std::string_view searchName) const;

View File

@ -32,7 +32,7 @@
#if CC_USE_3D_PHYSICS #if CC_USE_3D_PHYSICS
# include "physics3d/CCPhysics3DShape.h" # include "physics3d/CCPhysics3DShape.h"
# include "physics3d/CCPhysicsSprite3D.h" # include "physics3d/CCPhysicsMeshRenderer.h"
# include "physics3d/CCPhysics3DWorld.h" # include "physics3d/CCPhysics3DWorld.h"
# include "physics3d/CCPhysics3DDebugDrawer.h" # include "physics3d/CCPhysics3DDebugDrawer.h"
# include "physics3d/CCPhysics3DObject.h" # include "physics3d/CCPhysics3DObject.h"

View File

@ -31,12 +31,12 @@
NS_CC_BEGIN NS_CC_BEGIN
PhysicsSprite3D* PhysicsSprite3D::create(std::string_view modelPath, PhysicsMeshRenderer* PhysicsMeshRenderer::create(std::string_view modelPath,
Physics3DRigidBodyDes* rigidDes, Physics3DRigidBodyDes* rigidDes,
const cocos2d::Vec3& translateInPhysics, const cocos2d::Vec3& translateInPhysics,
const cocos2d::Quaternion& rotInPhsyics) const cocos2d::Quaternion& rotInPhsyics)
{ {
auto ret = new PhysicsSprite3D(); auto ret = new PhysicsMeshRenderer();
if (ret->initWithFile(modelPath)) if (ret->initWithFile(modelPath))
{ {
auto obj = Physics3DRigidBody::create(rigidDes); auto obj = Physics3DRigidBody::create(rigidDes);
@ -50,12 +50,12 @@ PhysicsSprite3D* PhysicsSprite3D::create(std::string_view modelPath,
return ret; return ret;
} }
PhysicsSprite3D* PhysicsSprite3D::createWithCollider(std::string_view modelPath, PhysicsMeshRenderer* PhysicsMeshRenderer::createWithCollider(std::string_view modelPath,
Physics3DColliderDes* colliderDes, Physics3DColliderDes* colliderDes,
const cocos2d::Vec3& translateInPhysics, const cocos2d::Vec3& translateInPhysics,
const cocos2d::Quaternion& rotInPhsyics) const cocos2d::Quaternion& rotInPhsyics)
{ {
auto ret = new PhysicsSprite3D(); auto ret = new PhysicsMeshRenderer();
if (ret->initWithFile(modelPath)) if (ret->initWithFile(modelPath))
{ {
auto obj = Physics3DCollider::create(colliderDes); auto obj = Physics3DCollider::create(colliderDes);
@ -69,31 +69,31 @@ PhysicsSprite3D* PhysicsSprite3D::createWithCollider(std::string_view modelPath,
return ret; return ret;
} }
Physics3DObject* PhysicsSprite3D::getPhysicsObj() const Physics3DObject* PhysicsMeshRenderer::getPhysicsObj() const
{ {
return _physicsComponent->getPhysics3DObject(); return _physicsComponent->getPhysics3DObject();
} }
void PhysicsSprite3D::setSyncFlag(Physics3DComponent::PhysicsSyncFlag syncFlag) void PhysicsMeshRenderer::setSyncFlag(Physics3DComponent::PhysicsSyncFlag syncFlag)
{ {
if (_physicsComponent) if (_physicsComponent)
_physicsComponent->setSyncFlag(syncFlag); _physicsComponent->setSyncFlag(syncFlag);
} }
void PhysicsSprite3D::syncNodeToPhysics() void PhysicsMeshRenderer::syncNodeToPhysics()
{ {
if (_physicsComponent) if (_physicsComponent)
_physicsComponent->syncNodeToPhysics(); _physicsComponent->syncNodeToPhysics();
} }
void PhysicsSprite3D::syncPhysicsToNode() void PhysicsMeshRenderer::syncPhysicsToNode()
{ {
if (_physicsComponent) if (_physicsComponent)
_physicsComponent->syncPhysicsToNode(); _physicsComponent->syncPhysicsToNode();
} }
PhysicsSprite3D::PhysicsSprite3D() : _physicsComponent(nullptr) {} PhysicsMeshRenderer::PhysicsMeshRenderer() : _physicsComponent(nullptr) {}
PhysicsSprite3D::~PhysicsSprite3D() {} PhysicsMeshRenderer::~PhysicsMeshRenderer() {}
NS_CC_END NS_CC_END

View File

@ -23,11 +23,11 @@
THE SOFTWARE. THE SOFTWARE.
****************************************************************************/ ****************************************************************************/
#ifndef __PHYSICS_SPRITE_3D_H__ #ifndef __PHYSICS_MESH_RENDERER_H__
#define __PHYSICS_SPRITE_3D_H__ #define __PHYSICS_MESH_RENDERER_H__
#include "base/ccConfig.h" #include "base/ccConfig.h"
#include "3d/CCSprite3D.h" #include "3d/CCMeshRenderer.h"
#include "physics3d/CCPhysics3DObject.h" #include "physics3d/CCPhysics3DObject.h"
#include "physics3d/CCPhysics3DComponent.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: public:
/** creates a PhysicsSprite3D*/ /** creates a PhysicsMeshRenderer */
static PhysicsSprite3D* create(std::string_view modelPath, static PhysicsMeshRenderer* create(std::string_view modelPath,
Physics3DRigidBodyDes* rigidDes, Physics3DRigidBodyDes* rigidDes,
const cocos2d::Vec3& translateInPhysics = cocos2d::Vec3::ZERO, const cocos2d::Vec3& translateInPhysics = cocos2d::Vec3::ZERO,
const cocos2d::Quaternion& rotInPhsyics = cocos2d::Quaternion::ZERO); const cocos2d::Quaternion& rotInPhsyics = cocos2d::Quaternion::ZERO);
/** creates a PhysicsSprite3D as a collider*/ /** creates a PhysicsMeshRenderer with a collider */
static PhysicsSprite3D* createWithCollider(std::string_view modelPath, static PhysicsMeshRenderer* createWithCollider(std::string_view modelPath,
Physics3DColliderDes* colliderDes, Physics3DColliderDes* colliderDes,
const cocos2d::Vec3& translateInPhysics = cocos2d::Vec3::ZERO, const cocos2d::Vec3& translateInPhysics = cocos2d::Vec3::ZERO,
const cocos2d::Quaternion& rotInPhsyics = cocos2d::Quaternion::ZERO); const cocos2d::Quaternion& rotInPhsyics = cocos2d::Quaternion::ZERO);
@ -71,8 +71,8 @@ public:
/** synchronize physics transformation to node. */ /** synchronize physics transformation to node. */
void syncPhysicsToNode(); void syncPhysicsToNode();
PhysicsSprite3D(); PhysicsMeshRenderer();
virtual ~PhysicsSprite3D(); virtual ~PhysicsMeshRenderer();
protected: protected:
Physics3DComponent* _physicsComponent; Physics3DComponent* _physicsComponent;
@ -86,4 +86,4 @@ NS_CC_END
#endif // CC_USE_3D_PHYSICS #endif // CC_USE_3D_PHYSICS
#endif // __PHYSICS_SPRITE_3D_H__ #endif // __PHYSICS_MESH_RENDERER_H__

View File

@ -3,7 +3,7 @@ set(COCOS_PHYSICS3D_HEADER
physics3d/CCPhysics3DShape.h physics3d/CCPhysics3DShape.h
physics3d/CCPhysics3D.h physics3d/CCPhysics3D.h
physics3d/CCPhysics3DWorld.h physics3d/CCPhysics3DWorld.h
physics3d/CCPhysicsSprite3D.h physics3d/CCPhysicsMeshRenderer.h
physics3d/CCPhysics3DObject.h physics3d/CCPhysics3DObject.h
physics3d/CCPhysics3DComponent.h physics3d/CCPhysics3DComponent.h
physics3d/CCPhysics3DDebugDrawer.h physics3d/CCPhysics3DDebugDrawer.h
@ -17,5 +17,5 @@ set(COCOS_PHYSICS3D_SRC
physics3d/CCPhysics3DObject.cpp physics3d/CCPhysics3DObject.cpp
physics3d/CCPhysics3DShape.cpp physics3d/CCPhysics3DShape.cpp
physics3d/CCPhysics3DWorld.cpp physics3d/CCPhysics3DWorld.cpp
physics3d/CCPhysicsSprite3D.cpp physics3d/CCPhysicsMeshRenderer.cpp
) )

View File

@ -34,7 +34,7 @@
#include "renderer/backend/Device.h" #include "renderer/backend/Device.h"
#include "renderer/ccShaders.h" #include "renderer/ccShaders.h"
#include "base/CCDirector.h" #include "base/CCDirector.h"
#include "3d/CCSprite3D.h" #include "3d/CCMeshRenderer.h"
#include "2d/CCCamera.h" #include "2d/CCCamera.h"
NS_CC_BEGIN NS_CC_BEGIN
@ -280,10 +280,10 @@ void Particle3DQuadRender::reset()
} }
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
Particle3DModelRender::Particle3DModelRender() : _spriteSize(Vec3::ONE) {} Particle3DModelRender::Particle3DModelRender() : _meshSize(Vec3::ONE) {}
Particle3DModelRender::~Particle3DModelRender() Particle3DModelRender::~Particle3DModelRender()
{ {
for (auto iter : _spriteList) for (auto iter : _meshList)
{ {
iter->release(); iter->release();
} }
@ -302,26 +302,26 @@ void Particle3DModelRender::render(Renderer* renderer, const Mat4& transform, Pa
if (!_isVisible) if (!_isVisible)
return; return;
if (_spriteList.empty()) if (_meshList.empty())
{ {
for (unsigned int i = 0; i < particleSystem->getParticleQuota(); ++i) for (unsigned int i = 0; i < particleSystem->getParticleQuota(); ++i)
{ {
Sprite3D* sprite = Sprite3D::create(_modelFile); MeshRenderer* mesh = MeshRenderer::create(_modelFile);
if (sprite == nullptr) if (mesh == nullptr)
{ {
CCLOG("failed to load file %s", _modelFile.c_str()); CCLOG("failed to load file %s", _modelFile.c_str());
continue; continue;
} }
sprite->setTexture(_texFile); mesh->setTexture(_texFile);
sprite->retain(); mesh->retain();
_spriteList.push_back(sprite); _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]; Vec3 corners[8];
aabb.getCorners(corners); 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; auto particle = iter;
Mat4::createRotation(q * particle->orientation, &rotMat); Mat4::createRotation(q * particle->orientation, &rotMat);
sclMat.m[0] = particle->width / _spriteSize.x; sclMat.m[0] = particle->width / _meshSize.x;
sclMat.m[5] = particle->height / _spriteSize.y; sclMat.m[5] = particle->height / _meshSize.y;
sclMat.m[10] = particle->depth / _spriteSize.z; sclMat.m[10] = particle->depth / _meshSize.z;
mat = rotMat * sclMat; mat = rotMat * sclMat;
mat.m[12] = particle->position.x; mat.m[12] = particle->position.x;
mat.m[13] = particle->position.y; mat.m[13] = particle->position.y;
mat.m[14] = particle->position.z; mat.m[14] = particle->position.z;
_spriteList[index++]->draw(renderer, mat, 0); _meshList[index++]->draw(renderer, mat, 0);
} }
} }
void Particle3DModelRender::reset() void Particle3DModelRender::reset()
{ {
for (auto iter : _spriteList) for (auto iter : _meshList)
{ {
iter->release(); iter->release();
} }
_spriteList.clear(); _meshList.clear();
} }
// MARK: Particle3DRender // MARK: Particle3DRender

View File

@ -41,7 +41,7 @@ NS_CC_BEGIN
class ParticleSystem3D; class ParticleSystem3D;
class Renderer; class Renderer;
class MeshCommand; class MeshCommand;
class Sprite3D; class MeshRenderer;
class GLProgramState; class GLProgramState;
class IndexBuffer; class IndexBuffer;
class VertexBuffer; class VertexBuffer;
@ -141,7 +141,7 @@ protected:
bool _rendererDepthWrite = false; bool _rendererDepthWrite = false;
}; };
// particle render for Sprite3D // particle renderer using MeshRenderer
class CC_EX_DLL Particle3DModelRender : public Particle3DRender class CC_EX_DLL Particle3DModelRender : public Particle3DRender
{ {
public: public:
@ -154,10 +154,10 @@ public:
virtual ~Particle3DModelRender(); virtual ~Particle3DModelRender();
protected: protected:
std::vector<Sprite3D*> _spriteList; std::vector<MeshRenderer*> _meshList;
std::string _modelFile; std::string _modelFile;
std::string _texFile; std::string _texFile;
Vec3 _spriteSize; Vec3 _meshSize;
}; };
NS_CC_END NS_CC_END

View File

@ -34,7 +34,7 @@
#include "renderer/CCTextureCache.h" #include "renderer/CCTextureCache.h"
#include "renderer/backend/ProgramState.h" #include "renderer/backend/ProgramState.h"
#include "base/CCDirector.h" #include "base/CCDirector.h"
#include "3d/CCSprite3D.h" #include "3d/CCMeshRenderer.h"
#include "3d/CCMesh.h" #include "3d/CCMesh.h"
#include "2d/CCCamera.h" #include "2d/CCCamera.h"
#include <sstream> #include <sstream>

View File

@ -36,7 +36,7 @@
#include "renderer/backend/Buffer.h" #include "renderer/backend/Buffer.h"
#include "renderer/backend/Device.h" #include "renderer/backend/Device.h"
#include "2d/CCCamera.h" #include "2d/CCCamera.h"
#include "3d/CCSprite3D.h" #include "3d/CCMeshRenderer.h"
NS_CC_BEGIN NS_CC_BEGIN

View File

@ -36,7 +36,7 @@
#include "renderer/backend/Device.h" #include "renderer/backend/Device.h"
#include "renderer/backend/Buffer.h" #include "renderer/backend/Buffer.h"
#include "base/CCDirector.h" #include "base/CCDirector.h"
#include "3d/CCSprite3D.h" #include "3d/CCMeshRenderer.h"
#include "3d/CCMesh.h" #include "3d/CCMesh.h"
#include "2d/CCCamera.h" #include "2d/CCCamera.h"
@ -501,28 +501,28 @@ void PUParticle3DModelRender::render(Renderer* renderer, const Mat4& transform,
if (!_isVisible) if (!_isVisible)
return; return;
if (_spriteList.empty()) if (_meshList.empty())
{ {
for (unsigned int i = 0; i < particleSystem->getParticleQuota(); ++i) for (unsigned int i = 0; i < particleSystem->getParticleQuota(); ++i)
{ {
Sprite3D* sprite = Sprite3D::create(_modelFile); MeshRenderer* mesh = MeshRenderer::create(_modelFile);
if (sprite == nullptr) if (mesh == nullptr)
{ {
CCLOG("failed to load file %s", _modelFile.c_str()); CCLOG("failed to load file %s", _modelFile.c_str());
continue; continue;
} }
sprite->setTexture(_texFile); mesh->setTexture(_texFile);
sprite->setBlendFunc(particleSystem->getBlendFunc()); mesh->setBlendFunc(particleSystem->getBlendFunc());
sprite->setCullFaceEnabled(false); mesh->setCullFaceEnabled(false);
sprite->retain(); mesh->retain();
_spriteList.push_back(sprite); _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]; Vec3 corners[8];
aabb.getCorners(corners); aabb.getCorners(corners);
_spriteSize = corners[3] - corners[6]; _meshSize = corners[3] - corners[6];
} }
else else
{ {
@ -543,19 +543,19 @@ void PUParticle3DModelRender::render(Renderer* renderer, const Mat4& transform,
{ {
auto particle = static_cast<PUParticle3D*>(iter); auto particle = static_cast<PUParticle3D*>(iter);
Mat4::createRotation(q * particle->orientation, &rotMat); Mat4::createRotation(q * particle->orientation, &rotMat);
sclMat.m[0] = particle->width / _spriteSize.x; sclMat.m[0] = particle->width / _meshSize.x;
sclMat.m[5] = particle->height / _spriteSize.y; sclMat.m[5] = particle->height / _meshSize.y;
sclMat.m[10] = particle->depth / _spriteSize.z; sclMat.m[10] = particle->depth / _meshSize.z;
mat = rotMat * sclMat; mat = rotMat * sclMat;
mat.m[12] = particle->position.x; mat.m[12] = particle->position.x;
mat.m[13] = particle->position.y; mat.m[13] = particle->position.y;
mat.m[14] = particle->position.z; mat.m[14] = particle->position.z;
if (_spriteList[index]->getCameraMask() != particleSystem->getCameraMask()) if (_meshList[index]->getCameraMask() != particleSystem->getCameraMask())
_spriteList[index]->setCameraMask(particleSystem->getCameraMask()); _meshList[index]->setCameraMask(particleSystem->getCameraMask());
_spriteList[index]->setColor( _meshList[index]->setColor(
Color3B(particle->color.x * 255, particle->color.y * 255, particle->color.z * 255)); Color3B(particle->color.x * 255, particle->color.y * 255, particle->color.z * 255));
_spriteList[index]->setOpacity(particle->color.w * 255); _meshList[index]->setOpacity(particle->color.w * 255);
_spriteList[index]->visit(renderer, mat, Node::FLAGS_DIRTY_MASK); _meshList[index]->visit(renderer, mat, Node::FLAGS_DIRTY_MASK);
++index; ++index;
} }
} }
@ -567,7 +567,7 @@ PUParticle3DModelRender::PUParticle3DModelRender()
PUParticle3DModelRender::~PUParticle3DModelRender() PUParticle3DModelRender::~PUParticle3DModelRender()
{ {
for (auto iter : _spriteList) for (auto iter : _meshList)
{ {
iter->release(); iter->release();
} }
@ -587,11 +587,11 @@ PUParticle3DModelRender* PUParticle3DModelRender::clone()
void PUParticle3DModelRender::reset() void PUParticle3DModelRender::reset()
{ {
for (auto iter : _spriteList) for (auto iter : _meshList)
{ {
iter->release(); iter->release();
} }
_spriteList.clear(); _meshList.clear();
} }
PUParticle3DEntityRender::PUParticle3DEntityRender() PUParticle3DEntityRender::PUParticle3DEntityRender()

View File

@ -55,7 +55,7 @@ public:
public: public:
bool autoRotate; // Means that the objects to render automatically rotate if the node to which the particle system 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: protected:
std::string _renderType; std::string _renderType;
@ -203,10 +203,10 @@ public:
virtual ~PUParticle3DModelRender(); virtual ~PUParticle3DModelRender();
protected: protected:
std::vector<Sprite3D*> _spriteList; std::vector<MeshRenderer*> _meshList;
std::string _modelFile; std::string _modelFile;
std::string _texFile; std::string _texFile;
Vec3 _spriteSize; Vec3 _meshSize;
}; };
class CC_EX_DLL PUParticle3DBoxRender : public PUParticle3DEntityRender class CC_EX_DLL PUParticle3DBoxRender : public PUParticle3DEntityRender

View File

@ -32,7 +32,7 @@
#include "renderer/CCTextureCache.h" #include "renderer/CCTextureCache.h"
#include "renderer/backend/ProgramState.h" #include "renderer/backend/ProgramState.h"
#include "2d/CCCamera.h" #include "2d/CCCamera.h"
#include "3d/CCSprite3D.h" #include "3d/CCMeshRenderer.h"
NS_CC_BEGIN NS_CC_BEGIN

View File

@ -32,7 +32,7 @@
#include "renderer/CCRenderer.h" #include "renderer/CCRenderer.h"
#include "renderer/CCTextureCache.h" #include "renderer/CCTextureCache.h"
#include "base/CCDirector.h" #include "base/CCDirector.h"
#include "3d/CCSprite3D.h" #include "3d/CCMeshRenderer.h"
#include "3d/CCMesh.h" #include "3d/CCMesh.h"
#include "2d/CCCamera.h" #include "2d/CCCamera.h"
#include <sstream> #include <sstream>

View File

@ -69,7 +69,7 @@
#include "WidgetReader/ListViewReader/ListViewReader.h" #include "WidgetReader/ListViewReader/ListViewReader.h"
#include "WidgetReader/ArmatureNodeReader/ArmatureNodeReader.h" #include "WidgetReader/ArmatureNodeReader/ArmatureNodeReader.h"
#include "WidgetReader/Node3DReader/Node3DReader.h" #include "WidgetReader/Node3DReader/Node3DReader.h"
#include "WidgetReader/Sprite3DReader/Sprite3DReader.h" #include "WidgetReader/MeshReader/MeshReader.h"
#include "WidgetReader/UserCameraReader/UserCameraReader.h" #include "WidgetReader/UserCameraReader/UserCameraReader.h"
#include "WidgetReader/Particle3DReader/Particle3DReader.h" #include "WidgetReader/Particle3DReader/Particle3DReader.h"
#include "WidgetReader/GameNode3DReader/GameNode3DReader.h" #include "WidgetReader/GameNode3DReader/GameNode3DReader.h"
@ -226,7 +226,7 @@ CSLoader::CSLoader()
CREATE_CLASS_NODE_READER_INFO(ArmatureNodeReader); CREATE_CLASS_NODE_READER_INFO(ArmatureNodeReader);
CREATE_CLASS_NODE_READER_INFO(Node3DReader); 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(UserCameraReader);
CREATE_CLASS_NODE_READER_INFO(Particle3DReader); CREATE_CLASS_NODE_READER_INFO(Particle3DReader);
CREATE_CLASS_NODE_READER_INFO(GameNode3DReader); CREATE_CLASS_NODE_READER_INFO(GameNode3DReader);

View File

@ -24,7 +24,7 @@
#include "WidgetReader/ListViewReader/ListViewReader.h" #include "WidgetReader/ListViewReader/ListViewReader.h"
#include "WidgetReader/ArmatureNodeReader/ArmatureNodeReader.h" #include "WidgetReader/ArmatureNodeReader/ArmatureNodeReader.h"
#include "WidgetReader/Node3DReader/Node3DReader.h" #include "WidgetReader/Node3DReader/Node3DReader.h"
#include "WidgetReader/Sprite3DReader/Sprite3DReader.h" #include "WidgetReader/MeshReader/MeshReader.h"
#include "WidgetReader/UserCameraReader/UserCameraReader.h" #include "WidgetReader/UserCameraReader/UserCameraReader.h"
#include "WidgetReader/Particle3DReader/Particle3DReader.h" #include "WidgetReader/Particle3DReader/Particle3DReader.h"
@ -57,7 +57,7 @@ void destroyCocosStudio()
ArmatureNodeReader::destroyInstance(); ArmatureNodeReader::destroyInstance();
Node3DReader::destroyInstance(); Node3DReader::destroyInstance();
Sprite3DReader::destroyInstance(); MeshReader::destroyInstance();
UserCameraReader::destroyInstance(); UserCameraReader::destroyInstance();
Particle3DReader::destroyInstance(); Particle3DReader::destroyInstance();

View File

@ -24,11 +24,11 @@
****************************************************************************/ ****************************************************************************/
#include "2d/CCLight.h" #include "2d/CCLight.h"
#include "3d/CCSprite3D.h" #include "3d/CCMeshRenderer.h"
#include "3d/CCAnimate3D.h" #include "3d/CCAnimate3D.h"
#include "3d/CCAnimation3D.h" #include "3d/CCAnimation3D.h"
#include "platform/CCFileUtils.h" #include "platform/CCFileUtils.h"
#include "WidgetReader/Sprite3DReader/Sprite3DReader.h" #include "WidgetReader/MeshReader/MeshReader.h"
#include "CSParseBinary_generated.h" #include "CSParseBinary_generated.h"
#include "CSParse3DBinary_generated.h" #include "CSParse3DBinary_generated.h"
@ -43,35 +43,35 @@ using namespace flatbuffers;
namespace cocostudio 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) if (!attribute)
return Vec2::ZERO; return Vec2::ZERO;
@ -99,7 +99,7 @@ Vec2 Sprite3DReader::getVec2Attribute(pugi::xml_attribute attribute) const
return ret; return ret;
} }
Offset<Table> Sprite3DReader::createOptionsWithFlatBuffers(pugi::xml_node objectData, Offset<Table> MeshReader::createOptionsWithFlatBuffers(pugi::xml_node objectData,
flatbuffers::FlatBufferBuilder* builder) flatbuffers::FlatBufferBuilder* builder)
{ {
auto temp = Node3DReader::getInstance()->createOptionsWithFlatBuffers(objectData, builder); auto temp = Node3DReader::getInstance()->createOptionsWithFlatBuffers(objectData, builder);
@ -205,9 +205,9 @@ Offset<Table> Sprite3DReader::createOptionsWithFlatBuffers(pugi::xml_node object
return *(Offset<Table>*)(&options); 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; auto options = (Sprite3DOptions*)sprite3DOptions;
@ -224,7 +224,7 @@ void Sprite3DReader::setPropsWithFlatBuffers(cocos2d::Node* node, const flatbuff
{ {
Animate3D* animate = Animate3D::create(animation); Animate3D* animate = Animate3D::create(animation);
Action* action = RepeatForever::create(animate); 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) if (alpha != 255)
{ {
sprite3D->setOpacity(alpha); mesh->setOpacity(alpha);
} }
if (red != 255 || green != 255 || blue != 255) if (red != 255 || green != 255 || blue != 255)
{ {
sprite3D->setColor(Color3B(red, green, blue)); mesh->setColor(Color3B(red, green, blue));
} }
if (isFlipped) if (isFlipped)
{ {
sprite3D->setCullFaceEnabled(true); mesh->setCullFaceEnabled(true);
sprite3D->setCullFace(CullFaceSide::FRONT); mesh->setCullFace(CullFaceSide::FRONT);
} }
if (lightFlag <= 0) if (lightFlag <= 0)
{ {
lightFlag = 1; lightFlag = 1;
} }
sprite3D->setLightMask(lightFlag); mesh->setLightMask(lightFlag);
auto node3DReader = Node3DReader::getInstance(); 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 options = (Sprite3DOptions*)sprite3DOptions;
auto fileData = options->fileData(); auto fileData = options->fileData();
std::string path = fileData->path()->c_str(); std::string path = fileData->path()->c_str();
Sprite3D* ret = Sprite3D::create(); MeshRenderer* ret = MeshRenderer::create();
if (FileUtils::getInstance()->isFileExist(path)) if (FileUtils::getInstance()->isFileExist(path))
{ {
ret->initWithFile(path); ret->initWithFile(path);

View File

@ -32,15 +32,15 @@
namespace cocostudio 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 DECLARE_CLASS_NODE_READER_INFO
public: public:
Sprite3DReader(); MeshReader();
~Sprite3DReader(); ~MeshReader();
static Sprite3DReader* getInstance(); static MeshReader* getInstance();
/** @deprecated Use method destroyInstance() instead */ /** @deprecated Use method destroyInstance() instead */
CC_DEPRECATED_ATTRIBUTE static void purge(); CC_DEPRECATED_ATTRIBUTE static void purge();
static void destroyInstance(); static void destroyInstance();

View File

@ -3972,10 +3972,10 @@ int lua_register_cocos2dx_physics3d_Physics3DComponent(lua_State* tolua_S)
return 1; 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; int argc = 0;
cocos2d::PhysicsSprite3D* cobj = nullptr; cocos2d::PhysicsMeshRenderer* cobj = nullptr;
bool ok = true; bool ok = true;
#if COCOS2D_DEBUG >= 1 #if COCOS2D_DEBUG >= 1
@ -3984,15 +3984,15 @@ int lua_cocos2dx_physics3d_PhysicsSprite3D_syncNodeToPhysics(lua_State* tolua_S)
#if COCOS2D_DEBUG >= 1 #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 #endif
cobj = (cocos2d::PhysicsSprite3D*)tolua_tousertype(tolua_S,1,0); cobj = (cocos2d::PhysicsMeshRenderer*)tolua_tousertype(tolua_S,1,0);
#if COCOS2D_DEBUG >= 1 #if COCOS2D_DEBUG >= 1
if (!cobj) 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; return 0;
} }
#endif #endif
@ -4002,27 +4002,27 @@ int lua_cocos2dx_physics3d_PhysicsSprite3D_syncNodeToPhysics(lua_State* tolua_S)
{ {
if(!ok) 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; return 0;
} }
cobj->syncNodeToPhysics(); cobj->syncNodeToPhysics();
lua_settop(tolua_S, 1); lua_settop(tolua_S, 1);
return 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; return 0;
#if COCOS2D_DEBUG >= 1 #if COCOS2D_DEBUG >= 1
tolua_lerror: 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 #endif
return 0; 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; int argc = 0;
cocos2d::PhysicsSprite3D* cobj = nullptr; cocos2d::PhysicsMeshRenderer* cobj = nullptr;
bool ok = true; bool ok = true;
#if COCOS2D_DEBUG >= 1 #if COCOS2D_DEBUG >= 1
@ -4031,15 +4031,15 @@ int lua_cocos2dx_physics3d_PhysicsSprite3D_syncPhysicsToNode(lua_State* tolua_S)
#if COCOS2D_DEBUG >= 1 #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 #endif
cobj = (cocos2d::PhysicsSprite3D*)tolua_tousertype(tolua_S,1,0); cobj = (cocos2d::PhysicsMeshRenderer*)tolua_tousertype(tolua_S,1,0);
#if COCOS2D_DEBUG >= 1 #if COCOS2D_DEBUG >= 1
if (!cobj) 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; return 0;
} }
#endif #endif
@ -4049,27 +4049,27 @@ int lua_cocos2dx_physics3d_PhysicsSprite3D_syncPhysicsToNode(lua_State* tolua_S)
{ {
if(!ok) 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; return 0;
} }
cobj->syncPhysicsToNode(); cobj->syncPhysicsToNode();
lua_settop(tolua_S, 1); lua_settop(tolua_S, 1);
return 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; return 0;
#if COCOS2D_DEBUG >= 1 #if COCOS2D_DEBUG >= 1
tolua_lerror: 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 #endif
return 0; 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; int argc = 0;
cocos2d::PhysicsSprite3D* cobj = nullptr; cocos2d::PhysicsMeshRenderer* cobj = nullptr;
bool ok = true; bool ok = true;
#if COCOS2D_DEBUG >= 1 #if COCOS2D_DEBUG >= 1
@ -4078,15 +4078,15 @@ int lua_cocos2dx_physics3d_PhysicsSprite3D_getPhysicsObj(lua_State* tolua_S)
#if COCOS2D_DEBUG >= 1 #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 #endif
cobj = (cocos2d::PhysicsSprite3D*)tolua_tousertype(tolua_S,1,0); cobj = (cocos2d::PhysicsMeshRenderer*)tolua_tousertype(tolua_S,1,0);
#if COCOS2D_DEBUG >= 1 #if COCOS2D_DEBUG >= 1
if (!cobj) 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; return 0;
} }
#endif #endif
@ -4096,27 +4096,27 @@ int lua_cocos2dx_physics3d_PhysicsSprite3D_getPhysicsObj(lua_State* tolua_S)
{ {
if(!ok) 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; return 0;
} }
cocos2d::Physics3DObject* ret = cobj->getPhysicsObj(); cocos2d::Physics3DObject* ret = cobj->getPhysicsObj();
object_to_luaval<cocos2d::Physics3DObject>(tolua_S, "cc.Physics3DObject",(cocos2d::Physics3DObject*)ret); object_to_luaval<cocos2d::Physics3DObject>(tolua_S, "cc.Physics3DObject",(cocos2d::Physics3DObject*)ret);
return 1; 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; return 0;
#if COCOS2D_DEBUG >= 1 #if COCOS2D_DEBUG >= 1
tolua_lerror: 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 #endif
return 0; 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; int argc = 0;
cocos2d::PhysicsSprite3D* cobj = nullptr; cocos2d::PhysicsMeshRenderer* cobj = nullptr;
bool ok = true; bool ok = true;
#if COCOS2D_DEBUG >= 1 #if COCOS2D_DEBUG >= 1
@ -4125,15 +4125,15 @@ int lua_cocos2dx_physics3d_PhysicsSprite3D_setSyncFlag(lua_State* tolua_S)
#if COCOS2D_DEBUG >= 1 #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 #endif
cobj = (cocos2d::PhysicsSprite3D*)tolua_tousertype(tolua_S,1,0); cobj = (cocos2d::PhysicsMeshRenderer*)tolua_tousertype(tolua_S,1,0);
#if COCOS2D_DEBUG >= 1 #if COCOS2D_DEBUG >= 1
if (!cobj) 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; return 0;
} }
#endif #endif
@ -4143,30 +4143,30 @@ int lua_cocos2dx_physics3d_PhysicsSprite3D_setSyncFlag(lua_State* tolua_S)
{ {
cocos2d::Physics3DComponent::PhysicsSyncFlag arg0; 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) 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; return 0;
} }
cobj->setSyncFlag(arg0); cobj->setSyncFlag(arg0);
lua_settop(tolua_S, 1); lua_settop(tolua_S, 1);
return 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; return 0;
#if COCOS2D_DEBUG >= 1 #if COCOS2D_DEBUG >= 1
tolua_lerror: 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 #endif
return 0; 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; int argc = 0;
cocos2d::PhysicsSprite3D* cobj = nullptr; cocos2d::PhysicsMeshRenderer* cobj = nullptr;
bool ok = true; bool ok = true;
#if COCOS2D_DEBUG >= 1 #if COCOS2D_DEBUG >= 1
@ -4180,47 +4180,47 @@ int lua_cocos2dx_physics3d_PhysicsSprite3D_constructor(lua_State* tolua_S)
{ {
if(!ok) 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; return 0;
} }
cobj = new cocos2d::PhysicsSprite3D(); cobj = new cocos2d::PhysicsMeshRenderer();
cobj->autorelease(); cobj->autorelease();
int ID = (int)cobj->_ID ; int ID = (int)cobj->_ID ;
int* luaID = &cobj->_luaID ; 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; 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; return 0;
#if COCOS2D_DEBUG >= 1 #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 #endif
return 0; 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; 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_usertype(tolua_S,"cc.PhysicsMeshRenderer");
tolua_cclass(tolua_S,"PhysicsSprite3D","cc.PhysicsSprite3D","cc.Sprite3D",nullptr); tolua_cclass(tolua_S,"PhysicsMeshRenderer","cc.PhysicsMeshRenderer","cc.Sprite3D",nullptr);
tolua_beginmodule(tolua_S,"PhysicsSprite3D"); tolua_beginmodule(tolua_S,"PhysicsMeshRenderer");
tolua_function(tolua_S,"new",lua_cocos2dx_physics3d_PhysicsSprite3D_constructor); tolua_function(tolua_S,"new",lua_cocos2dx_physics3d_PhysicsMeshRenderer_constructor);
tolua_function(tolua_S,"syncNodeToPhysics",lua_cocos2dx_physics3d_PhysicsSprite3D_syncNodeToPhysics); tolua_function(tolua_S,"syncNodeToPhysics",lua_cocos2dx_physics3d_PhysicsMeshRenderer_syncNodeToPhysics);
tolua_function(tolua_S,"syncPhysicsToNode",lua_cocos2dx_physics3d_PhysicsSprite3D_syncPhysicsToNode); tolua_function(tolua_S,"syncPhysicsToNode",lua_cocos2dx_physics3d_PhysicsMeshRenderer_syncPhysicsToNode);
tolua_function(tolua_S,"getPhysicsObj",lua_cocos2dx_physics3d_PhysicsSprite3D_getPhysicsObj); tolua_function(tolua_S,"getPhysicsObj",lua_cocos2dx_physics3d_PhysicsMeshRenderer_getPhysicsObj);
tolua_function(tolua_S,"setSyncFlag",lua_cocos2dx_physics3d_PhysicsSprite3D_setSyncFlag); tolua_function(tolua_S,"setSyncFlag",lua_cocos2dx_physics3d_PhysicsMeshRenderer_setSyncFlag);
tolua_endmodule(tolua_S); tolua_endmodule(tolua_S);
auto typeName = typeid(cocos2d::PhysicsSprite3D).name(); // rtti is literal storage auto typeName = typeid(cocos2d::PhysicsMeshRenderer).name(); // rtti is literal storage
g_luaType[reinterpret_cast<uintptr_t>(typeName)] = "cc.PhysicsSprite3D"; g_luaType[reinterpret_cast<uintptr_t>(typeName)] = "cc.PhysicsMeshRenderer";
g_typeCast[typeName] = "cc.PhysicsSprite3D"; g_typeCast[typeName] = "cc.PhysicsMeshRenderer";
return 1; 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_Physics3DComponent(tolua_S);
lua_register_cocos2dx_physics3d_Physics3DConeTwistConstraint(tolua_S); lua_register_cocos2dx_physics3d_Physics3DConeTwistConstraint(tolua_S);
lua_register_cocos2dx_physics3d_Physics3DPointToPointConstraint(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_Physics3DHingeConstraint(tolua_S);
lua_register_cocos2dx_physics3d_Physics3DShape(tolua_S); lua_register_cocos2dx_physics3d_Physics3DShape(tolua_S);

View File

@ -27,29 +27,29 @@
#include "scripting/lua-bindings/manual/LuaBasicConversions.h" #include "scripting/lua-bindings/manual/LuaBasicConversions.h"
#include "scripting/lua-bindings/manual/CCLuaEngine.h" #include "scripting/lua-bindings/manual/CCLuaEngine.h"
#include "3d/CCBundle3D.h" #include "3d/CCBundle3D.h"
#include "3d/CCSprite3D.h" #include "3d/CCMeshRenderer.h"
#include "3d/CCTerrain.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; int argc = 0;
cocos2d::Sprite3D* cobj = nullptr; cocos2d::MeshRenderer* cobj = nullptr;
#if COCOS2D_DEBUG >= 1 #if COCOS2D_DEBUG >= 1
tolua_Error tolua_err; tolua_Error tolua_err;
#endif #endif
#if COCOS2D_DEBUG >= 1 #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; goto tolua_lerror;
#endif #endif
cobj = (cocos2d::Sprite3D*)tolua_tousertype(L, 1, 0); cobj = (cocos2d::MeshRenderer*)tolua_tousertype(L, 1, 0);
#if COCOS2D_DEBUG >= 1 #if COCOS2D_DEBUG >= 1
if (!cobj) 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; return 0;
} }
#endif #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); object_to_luaval<cocos2d::AABB>(L, "cc.AABB", (cocos2d::AABB*)ret);
return 1; 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; return 0;
#if COCOS2D_DEBUG >= 1 #if COCOS2D_DEBUG >= 1
tolua_lerror: 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 #endif
return 0; return 0;
} }
int lua_cocos2dx_3d_Sprite3D_createAsync(lua_State* L) int lua_cocos2dx_3d_MeshRenderer_createAsync(lua_State* L)
{ {
int argc = 0; int argc = 0;
bool ok = true; bool ok = true;
@ -80,7 +80,7 @@ int lua_cocos2dx_3d_Sprite3D_createAsync(lua_State* L)
#endif #endif
#if COCOS2D_DEBUG >= 1 #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; goto tolua_lerror;
#endif #endif
@ -91,11 +91,11 @@ int lua_cocos2dx_3d_Sprite3D_createAsync(lua_State* L)
if (argc == 3) if (argc == 3)
{ {
std::string modelPath; 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) if (!ok)
break; break;
std::string texturePath; 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) if (!ok)
break; break;
@ -107,13 +107,13 @@ int lua_cocos2dx_3d_Sprite3D_createAsync(lua_State* L)
#endif #endif
LUA_FUNCTION handler = toluafix_ref_function(L, 4, 0); LUA_FUNCTION handler = toluafix_ref_function(L, 4, 0);
cocos2d::Sprite3D::createAsync( cocos2d::MeshRenderer::createAsync(
modelPath, texturePath, modelPath, texturePath,
[=](cocos2d::Sprite3D* sprite, void* callbackparam) { [=](cocos2d::MeshRenderer* mesh, void* callbackparam) {
auto stack = LuaEngine::getInstance()->getLuaStack(); auto stack = LuaEngine::getInstance()->getLuaStack();
int id = (sprite) ? (int)sprite->_ID : -1; int id = (mesh) ? (int)mesh->_ID : -1;
int* luaID = (sprite) ? &sprite->_luaID : nullptr; int* luaID = (mesh) ? &mesh->_luaID : nullptr;
toluafix_pushusertype_ccobject(stack->getLuaState(), id, luaID, (void*)sprite, "cc.Sprite3D"); toluafix_pushusertype_ccobject(stack->getLuaState(), id, luaID, (void*)mesh, "cc.MeshRenderer");
stack->executeFunctionByHandler(handler, 1); stack->executeFunctionByHandler(handler, 1);
}, },
nullptr); nullptr);
@ -128,7 +128,7 @@ int lua_cocos2dx_3d_Sprite3D_createAsync(lua_State* L)
if (argc == 2) if (argc == 2)
{ {
std::string modelPath; 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) if (!ok)
break; break;
@ -140,13 +140,13 @@ int lua_cocos2dx_3d_Sprite3D_createAsync(lua_State* L)
#endif #endif
LUA_FUNCTION handler = toluafix_ref_function(L, 3, 0); LUA_FUNCTION handler = toluafix_ref_function(L, 3, 0);
cocos2d::Sprite3D::createAsync( cocos2d::MeshRenderer::createAsync(
modelPath, modelPath,
[=](cocos2d::Sprite3D* sprite, void* callbackparam) { [=](cocos2d::MeshRenderer* mesh, void* callbackparam) {
auto stack = LuaEngine::getInstance()->getLuaStack(); auto stack = LuaEngine::getInstance()->getLuaStack();
int id = (sprite) ? (int)sprite->_ID : -1; int id = (mesh) ? (int)mesh->_ID : -1;
int* luaID = (sprite) ? &sprite->_luaID : nullptr; int* luaID = (mesh) ? &mesh->_luaID : nullptr;
toluafix_pushusertype_ccobject(stack->getLuaState(), id, luaID, (void*)sprite, "cc.Sprite3D"); toluafix_pushusertype_ccobject(stack->getLuaState(), id, luaID, (void*)mesh, "cc.MeshRenderer");
stack->executeFunctionByHandler(handler, 1); stack->executeFunctionByHandler(handler, 1);
}, },
nullptr); nullptr);
@ -156,23 +156,23 @@ int lua_cocos2dx_3d_Sprite3D_createAsync(lua_State* L)
} }
} while (0); } while (0);
ok = true; 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; return 0;
#if COCOS2D_DEBUG >= 1 #if COCOS2D_DEBUG >= 1
tolua_lerror: 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 #endif
return 0; 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); lua_rawget(L, LUA_REGISTRYINDEX);
if (lua_istable(L, -1)) if (lua_istable(L, -1))
{ {
tolua_function(L, "getAABB", lua_cocos2dx_3d_Sprite3D_getAABB); tolua_function(L, "getAABB", lua_cocos2dx_3d_MeshRenderer_getAABB);
tolua_function(L, "createAsync", lua_cocos2dx_3d_Sprite3D_createAsync); tolua_function(L, "createAsync", lua_cocos2dx_3d_MeshRenderer_createAsync);
} }
lua_pop(L, 1); lua_pop(L, 1);
} }
@ -656,7 +656,7 @@ static int register_all_cocos2dx_3d_manual(lua_State* L)
if (nullptr == L) if (nullptr == L)
return 0; return 0;
extendSprite3D(L); extendMeshRenderer(L);
extendTerrain(L); extendTerrain(L);
extendBundle3D(L); extendBundle3D(L);
return 0; return 0;

View File

@ -186,7 +186,7 @@ void Physics3DWorld_HitResult_to_luaval(lua_State* L, const cocos2d::Physics3DWo
lua_rawset(L, -3); 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; int argc = 0;
bool ok = true; bool ok = true;
@ -196,7 +196,7 @@ int lua_cocos2dx_physics3d_PhysicsSprite3D_create(lua_State* L)
# endif # endif
# if COCOS2D_DEBUG >= 1 # 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; goto tolua_lerror;
# endif # endif
@ -206,15 +206,15 @@ int lua_cocos2dx_physics3d_PhysicsSprite3D_create(lua_State* L)
{ {
std::string arg0; std::string arg0;
cocos2d::Physics3DRigidBodyDes arg1; cocos2d::Physics3DRigidBodyDes arg1;
ok &= luaval_to_std_string(L, 2, &arg0, "cc.PhysicsSprite3D:create"); ok &= luaval_to_std_string(L, 2, &arg0, "cc.PhysicsMeshRenderer:create");
ok &= luaval_to_Physics3DRigidBodyDes(L, 3, &arg1, "cc.PhysicsSprite3D:create"); ok &= luaval_to_Physics3DRigidBodyDes(L, 3, &arg1, "cc.PhysicsMeshRenderer:create");
if (!ok) 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; return 0;
} }
cocos2d::PhysicsSprite3D* ret = cocos2d::PhysicsSprite3D::create(arg0, &arg1); cocos2d::PhysicsMeshRenderer* ret = cocos2d::PhysicsMeshRenderer::create(arg0, &arg1);
object_to_luaval<cocos2d::PhysicsSprite3D>(L, "cc.PhysicsSprite3D", (cocos2d::PhysicsSprite3D*)ret); object_to_luaval<cocos2d::PhysicsMeshRenderer>(L, "cc.PhysicsMeshRenderer", (cocos2d::PhysicsMeshRenderer*)ret);
return 1; return 1;
} }
if (argc == 3) if (argc == 3)
@ -222,16 +222,16 @@ int lua_cocos2dx_physics3d_PhysicsSprite3D_create(lua_State* L)
std::string arg0; std::string arg0;
cocos2d::Physics3DRigidBodyDes arg1; cocos2d::Physics3DRigidBodyDes arg1;
cocos2d::Vec3 arg2; cocos2d::Vec3 arg2;
ok &= luaval_to_std_string(L, 2, &arg0, "cc.PhysicsSprite3D:create"); ok &= luaval_to_std_string(L, 2, &arg0, "cc.PhysicsMeshRenderer:create");
ok &= luaval_to_Physics3DRigidBodyDes(L, 3, &arg1, "cc.PhysicsSprite3D:create"); ok &= luaval_to_Physics3DRigidBodyDes(L, 3, &arg1, "cc.PhysicsMeshRenderer:create");
ok &= luaval_to_vec3(L, 4, &arg2, "cc.PhysicsSprite3D:create"); ok &= luaval_to_vec3(L, 4, &arg2, "cc.PhysicsMeshRenderer:create");
if (!ok) 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; return 0;
} }
cocos2d::PhysicsSprite3D* ret = cocos2d::PhysicsSprite3D::create(arg0, &arg1, arg2); cocos2d::PhysicsMeshRenderer* ret = cocos2d::PhysicsMeshRenderer::create(arg0, &arg1, arg2);
object_to_luaval<cocos2d::PhysicsSprite3D>(L, "cc.PhysicsSprite3D", (cocos2d::PhysicsSprite3D*)ret); object_to_luaval<cocos2d::PhysicsMeshRenderer>(L, "cc.PhysicsMeshRenderer", (cocos2d::PhysicsMeshRenderer*)ret);
return 1; return 1;
} }
if (argc == 4) if (argc == 4)
@ -240,35 +240,35 @@ int lua_cocos2dx_physics3d_PhysicsSprite3D_create(lua_State* L)
cocos2d::Physics3DRigidBodyDes arg1; cocos2d::Physics3DRigidBodyDes arg1;
cocos2d::Vec3 arg2; cocos2d::Vec3 arg2;
cocos2d::Quaternion arg3; cocos2d::Quaternion arg3;
ok &= luaval_to_std_string(L, 2, &arg0, "cc.PhysicsSprite3D:create"); ok &= luaval_to_std_string(L, 2, &arg0, "cc.PhysicsMeshRenderer:create");
ok &= luaval_to_Physics3DRigidBodyDes(L, 3, &arg1, "cc.PhysicsSprite3D:create"); ok &= luaval_to_Physics3DRigidBodyDes(L, 3, &arg1, "cc.PhysicsMeshRenderer:create");
ok &= luaval_to_vec3(L, 4, &arg2, "cc.PhysicsSprite3D:create"); ok &= luaval_to_vec3(L, 4, &arg2, "cc.PhysicsMeshRenderer:create");
ok &= luaval_to_quaternion(L, 5, &arg3); ok &= luaval_to_quaternion(L, 5, &arg3);
if (!ok) 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; return 0;
} }
cocos2d::PhysicsSprite3D* ret = cocos2d::PhysicsSprite3D::create(arg0, &arg1, arg2, arg3); cocos2d::PhysicsMeshRenderer* ret = cocos2d::PhysicsMeshRenderer::create(arg0, &arg1, arg2, arg3);
object_to_luaval<cocos2d::PhysicsSprite3D>(L, "cc.PhysicsSprite3D", (cocos2d::PhysicsSprite3D*)ret); object_to_luaval<cocos2d::PhysicsMeshRenderer>(L, "cc.PhysicsMeshRenderer", (cocos2d::PhysicsMeshRenderer*)ret);
return 1; 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; return 0;
# if COCOS2D_DEBUG >= 1 # if COCOS2D_DEBUG >= 1
tolua_lerror: 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 # endif
return 0; 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); lua_rawget(L, LUA_REGISTRYINDEX);
if (lua_istable(L, -1)) 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); lua_pop(L, 1);
} }
@ -847,7 +847,7 @@ int register_all_physics3d_manual(lua_State* L)
if (nullptr == L) if (nullptr == L)
return 0; return 0;
extendPhysicsSprite3D(L); extendPhysicsMeshRenderer(L);
extendPhysics3DRigidBody(L); extendPhysics3DRigidBody(L);
extendPhysics3DComponent(L); extendPhysics3DComponent(L);
extendPhysics3DWorld(L); extendPhysics3DWorld(L);

View File

@ -160,8 +160,8 @@ list(APPEND GAME_HEADER
Classes/ExtensionsTest/ExtensionsTest.h Classes/ExtensionsTest/ExtensionsTest.h
Classes/ExtensionsTest/TableViewTest/CustomTableViewCell.h Classes/ExtensionsTest/TableViewTest/CustomTableViewCell.h
Classes/ExtensionsTest/TableViewTest/TableViewTestScene.h Classes/ExtensionsTest/TableViewTest/TableViewTestScene.h
Classes/Sprite3DTest/Sprite3DTest.h Classes/MeshRendererTest/MeshRendererTest.h
Classes/Sprite3DTest/DrawNode3D.h Classes/MeshRendererTest/DrawNode3D.h
Classes/BaseTest.h Classes/BaseTest.h
Classes/SceneTest/SceneTest.h Classes/SceneTest/SceneTest.h
Classes/ReleasePoolTest/ReleasePoolTest.h Classes/ReleasePoolTest/ReleasePoolTest.h
@ -296,8 +296,8 @@ list(APPEND GAME_SOURCE
Classes/ShaderTest/ShaderTest2.cpp Classes/ShaderTest/ShaderTest2.cpp
Classes/SpineTest/SpineTest.cpp Classes/SpineTest/SpineTest.cpp
# Classes/Scene3DTest/Scene3DTest.cpp # Classes/Scene3DTest/Scene3DTest.cpp
Classes/Sprite3DTest/DrawNode3D.cpp Classes/MeshRendererTest/DrawNode3D.cpp
Classes/Sprite3DTest/Sprite3DTest.cpp Classes/MeshRendererTest/MeshRendererTest.cpp
Classes/SpritePolygonTest/SpritePolygonTest.cpp Classes/SpritePolygonTest/SpritePolygonTest.cpp
Classes/SpriteTest/SpriteTest.cpp Classes/SpriteTest/SpriteTest.cpp
Classes/TerrainTest/TerrainTest.cpp Classes/TerrainTest/TerrainTest.cpp

View File

@ -85,7 +85,12 @@ bool AppDelegate::applicationDidFinishLaunching()
} }
director->setStatsDisplay(true); director->setStatsDisplay(true);
#ifdef CC_PLATFORM_PC
director->setAnimationInterval(1.0f / glfwGetVideoMode(glfwGetPrimaryMonitor())->refreshRate);
#else
director->setAnimationInterval(1.0f / 60); director->setAnimationInterval(1.0f / 60);
#endif
auto screenSize = glview->getFrameSize(); auto screenSize = glview->getFrameSize();

View File

@ -47,11 +47,11 @@ BillBoardTests::BillBoardTests()
//------------------------------------------------------------------ //------------------------------------------------------------------
BillBoardRotationTest::BillBoardRotationTest() BillBoardRotationTest::BillBoardRotationTest()
{ {
auto root = Sprite3D::create(); auto root = MeshRenderer::create();
root->setPositionNormalized(Vec2(0.5f, 0.25f)); root->setPositionNormalized(Vec2(0.5f, 0.25f));
addChild(root); addChild(root);
auto model = Sprite3D::create("Sprite3DTest/orc.c3b"); auto model = MeshRenderer::create("MeshRendererTest/orc.c3b");
model->setScale(5); model->setScale(5);
model->setRotation3D(Vec3(0.0f, 180.0f, 0.0f)); model->setRotation3D(Vec3(0.0f, 180.0f, 0.0f));
root->addChild(model); root->addChild(model);
@ -150,11 +150,11 @@ BillBoardTest::BillBoardTest() : _camera(nullptr)
_billboards.push_back(billboard); _billboards.push_back(billboard);
_billboards.push_back(billboard2); _billboards.push_back(billboard2);
auto sprite3d = Sprite3D::create("Sprite3DTest/orc.c3t"); auto mesh = MeshRenderer::create("MeshRendererTest/orc.c3t");
sprite3d->setScale(2.0f); mesh->setScale(2.0f);
sprite3d->addChild(billboard); mesh->addChild(billboard);
sprite3d->runAction(RepeatForever::create(RotateBy::create(10.0f, Vec3(0.0f, 360.0f, 0.0f)))); mesh->runAction(RepeatForever::create(RotateBy::create(10.0f, Vec3(0.0f, 360.0f, 0.0f))));
_layerBillBoard->addChild(sprite3d); _layerBillBoard->addChild(mesh);
} }
addNewBillBoardWithCoords(Vec3(20.0f, 5.0f, 0.0f)); addNewBillBoardWithCoords(Vec3(20.0f, 5.0f, 0.0f));

View File

@ -40,15 +40,15 @@ bool Bug15594Layer::init()
{ {
if (BugsTestBase::init()) if (BugsTestBase::init())
{ {
auto sprite3d = Sprite3D::create("Images/bugs/bug15594.c3t", "Images/bugs/bug15594.jpg"); auto mesh = MeshRenderer::create("Images/bugs/bug15594.c3t", "Images/bugs/bug15594.jpg");
addChild(sprite3d); addChild(mesh);
auto size = Director::getInstance()->getWinSize(); auto size = Director::getInstance()->getWinSize();
sprite3d->setPosition(size / 2); mesh->setPosition(size / 2);
auto animation = Animation3D::create("Images/bugs/bug15594.c3t"); auto animation = Animation3D::create("Images/bugs/bug15594.c3t");
auto animate = Animate3D::create(animation); auto animate = Animate3D::create(animation);
auto repeat = RepeatForever::create(animate); auto repeat = RepeatForever::create(animate);
sprite3d->runAction(repeat); mesh->runAction(repeat);
return true; return true;
} }

View File

@ -77,14 +77,14 @@ CameraRotationTest::CameraRotationTest()
_camNode->setPositionZ(Camera::getDefaultCamera()->getPosition3D().z); _camNode->setPositionZ(Camera::getDefaultCamera()->getPosition3D().z);
_camControlNode->addChild(_camNode); _camControlNode->addChild(_camNode);
auto sp3d = Sprite3D::create(); auto mesh = MeshRenderer::create();
sp3d->setPosition(s.width / 2, s.height / 2); mesh->setPosition(s.width / 2, s.height / 2);
addChild(sp3d); addChild(mesh);
auto lship = Label::create(); auto lship = Label::create();
lship->setString("Ship"); lship->setString("Ship");
lship->setPosition(0, 20); lship->setPosition(0, 20);
sp3d->addChild(lship); mesh->addChild(lship);
// Billboards // Billboards
// Yellow is at the back // Yellow is at the back
@ -92,7 +92,7 @@ CameraRotationTest::CameraRotationTest()
bill1->setPosition3D(Vec3(50.0f, 10.0f, -10.0f)); bill1->setPosition3D(Vec3(50.0f, 10.0f, -10.0f));
bill1->setColor(Color3B::YELLOW); bill1->setColor(Color3B::YELLOW);
bill1->setScale(0.6f); bill1->setScale(0.6f);
sp3d->addChild(bill1); mesh->addChild(bill1);
l1 = Label::create(); l1 = Label::create();
l1->setPosition(Vec2(0.0f, -10.0f)); l1->setPosition(Vec2(0.0f, -10.0f));
@ -108,7 +108,7 @@ CameraRotationTest::CameraRotationTest()
bill2 = BillBoard::create("Images/Icon.png"); bill2 = BillBoard::create("Images/Icon.png");
bill2->setPosition3D(Vec3(-50.0f, -10.0f, 10.0f)); bill2->setPosition3D(Vec3(-50.0f, -10.0f, 10.0f));
bill2->setScale(0.6f); bill2->setScale(0.6f);
sp3d->addChild(bill2); mesh->addChild(bill2);
l2 = Label::create(); l2 = Label::create();
l2->setString("Billboard2"); l2->setString("Billboard2");
@ -122,9 +122,9 @@ CameraRotationTest::CameraRotationTest()
bill2->addChild(p2); bill2->addChild(p2);
// 3D models // 3D models
auto model = Sprite3D::create("Sprite3DTest/boss1.obj"); auto model = MeshRenderer::create("MeshRendererTest/boss1.obj");
model->setScale(4); model->setScale(4);
model->setTexture("Sprite3DTest/boss.png"); model->setTexture("MeshRendererTest/boss.png");
model->setPosition3D(Vec3(s.width / 2, s.height / 2, 0)); model->setPosition3D(Vec3(s.width / 2, s.height / 2, 0));
addChild(model); addChild(model);
@ -226,8 +226,8 @@ void Camera3DTestDemo::SwitchViewCallback(Ref* sender, CameraType cameraType)
_cameraType = cameraType; _cameraType = cameraType;
if (_cameraType == CameraType::Free) if (_cameraType == CameraType::Free)
{ {
_camera->setPosition3D(Vec3(0, 130, 130) + _sprite3D->getPosition3D()); _camera->setPosition3D(Vec3(0, 130, 130) + _mesh->getPosition3D());
_camera->lookAt(_sprite3D->getPosition3D()); _camera->lookAt(_mesh->getPosition3D());
_RotateRightlabel->setColor(Color3B::WHITE); _RotateRightlabel->setColor(Color3B::WHITE);
_RotateLeftlabel->setColor(Color3B::WHITE); _RotateLeftlabel->setColor(Color3B::WHITE);
@ -237,10 +237,10 @@ void Camera3DTestDemo::SwitchViewCallback(Ref* sender, CameraType cameraType)
else if (_cameraType == CameraType::FirstPerson) else if (_cameraType == CameraType::FirstPerson)
{ {
Vec3 newFaceDir; Vec3 newFaceDir;
_sprite3D->getWorldToNodeTransform().getForwardVector(&newFaceDir); _mesh->getWorldToNodeTransform().getForwardVector(&newFaceDir);
newFaceDir.normalize(); newFaceDir.normalize();
_camera->setPosition3D(Vec3(0, 35, 0) + _sprite3D->getPosition3D()); _camera->setPosition3D(Vec3(0, 35, 0) + _mesh->getPosition3D());
_camera->lookAt(_sprite3D->getPosition3D() + newFaceDir * 50); _camera->lookAt(_mesh->getPosition3D() + newFaceDir * 50);
_RotateRightlabel->setColor(Color3B::WHITE); _RotateRightlabel->setColor(Color3B::WHITE);
_RotateLeftlabel->setColor(Color3B::WHITE); _RotateLeftlabel->setColor(Color3B::WHITE);
@ -249,8 +249,8 @@ void Camera3DTestDemo::SwitchViewCallback(Ref* sender, CameraType cameraType)
} }
else if (_cameraType == CameraType::ThirdPerson) else if (_cameraType == CameraType::ThirdPerson)
{ {
_camera->setPosition3D(Vec3(0, 130, 130) + _sprite3D->getPosition3D()); _camera->setPosition3D(Vec3(0, 130, 130) + _mesh->getPosition3D());
_camera->lookAt(_sprite3D->getPosition3D()); _camera->lookAt(_mesh->getPosition3D());
_RotateRightlabel->setColor(Color3B::GRAY); _RotateRightlabel->setColor(Color3B::GRAY);
_RotateLeftlabel->setColor(Color3B::GRAY); _RotateLeftlabel->setColor(Color3B::GRAY);
@ -261,7 +261,7 @@ void Camera3DTestDemo::SwitchViewCallback(Ref* sender, CameraType cameraType)
void Camera3DTestDemo::onEnter() void Camera3DTestDemo::onEnter()
{ {
CameraBaseTest::onEnter(); CameraBaseTest::onEnter();
_sprite3D = nullptr; _mesh = nullptr;
auto s = Director::getInstance()->getWinSize(); auto s = Director::getInstance()->getWinSize();
auto listener = EventListenerTouchAllAtOnce::create(); auto listener = EventListenerTouchAllAtOnce::create();
listener->onTouchesBegan = CC_CALLBACK_2(Camera3DTestDemo::onTouchesBegan, this); listener->onTouchesBegan = CC_CALLBACK_2(Camera3DTestDemo::onTouchesBegan, this);
@ -272,7 +272,7 @@ void Camera3DTestDemo::onEnter()
addChild(layer3D, 0); addChild(layer3D, 0);
_layer3D = layer3D; _layer3D = layer3D;
_curState = State_None; _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); TTFConfig ttfConfig("fonts/arial.ttf", 20);
auto containerForLabel1 = Node::create(); auto containerForLabel1 = Node::create();
@ -389,25 +389,25 @@ void Camera3DTestDemo::addNewSpriteWithCoords(Vec3 p,
float scale, float scale,
bool bindCamera) bool bindCamera)
{ {
auto sprite = Sprite3D::create(fileName); auto mesh = MeshRenderer::create(fileName);
_layer3D->addChild(sprite); _layer3D->addChild(mesh);
float globalZOrder = sprite->getGlobalZOrder(); float globalZOrder = mesh->getGlobalZOrder();
sprite->setPosition3D(Vec3(p.x, p.y, p.z)); mesh->setPosition3D(Vec3(p.x, p.y, p.z));
sprite->setGlobalZOrder(globalZOrder); mesh->setGlobalZOrder(globalZOrder);
if (playAnimation) if (playAnimation)
{ {
auto animation = Animation3D::create(fileName, "Take 001"); auto animation = Animation3D::create(fileName, "Take 001");
if (animation) if (animation)
{ {
auto animate = Animate3D::create(animation); auto animate = Animate3D::create(animation);
sprite->runAction(RepeatForever::create(animate)); mesh->runAction(RepeatForever::create(animate));
} }
} }
if (bindCamera) 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::onTouchesBegan(const std::vector<Touch*>& touches, cocos2d::Event* event) {}
void Camera3DTestDemo::onTouchesMoved(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 += cameraDir * newPos.y * 0.1f;
cameraPos += cameraRightDir * newPos.x * 0.1f; cameraPos += cameraRightDir * newPos.x * 0.1f;
_camera->setPosition3D(cameraPos); _camera->setPosition3D(cameraPos);
if (_sprite3D && _cameraType == CameraType::FirstPerson) if (_mesh && _cameraType == CameraType::FirstPerson)
{ {
_sprite3D->setPosition3D(Vec3(_camera->getPositionX(), 0, _camera->getPositionZ())); _mesh->setPosition3D(Vec3(_camera->getPositionX(), 0, _camera->getPositionZ()));
_targetPos = _sprite3D->getPosition3D(); _targetPos = _mesh->getPosition3D();
} }
} }
} }
} }
void Camera3DTestDemo::move3D(float elapsedTime) void Camera3DTestDemo::move3D(float elapsedTime)
{ {
if (_sprite3D) if (_mesh)
{ {
Vec3 curPos = _sprite3D->getPosition3D(); Vec3 curPos = _mesh->getPosition3D();
Vec3 newFaceDir = _targetPos - curPos; Vec3 newFaceDir = _targetPos - curPos;
newFaceDir.y = 0.0f; newFaceDir.y = 0.0f;
newFaceDir.normalize(); newFaceDir.normalize();
Vec3 offset = newFaceDir * 25.0f * elapsedTime; Vec3 offset = newFaceDir * 25.0f * elapsedTime;
curPos += offset; curPos += offset;
_sprite3D->setPosition3D(curPos); _mesh->setPosition3D(curPos);
if (_cameraType == CameraType::ThirdPerson) if (_cameraType == CameraType::ThirdPerson)
{ {
Vec3 cameraPos = _camera->getPosition3D(); Vec3 cameraPos = _camera->getPosition3D();
@ -461,11 +461,11 @@ void Camera3DTestDemo::move3D(float elapsedTime)
} }
void Camera3DTestDemo::updateState(float elapsedTime) void Camera3DTestDemo::updateState(float elapsedTime)
{ {
if (_sprite3D) if (_mesh)
{ {
Vec3 curPos = _sprite3D->getPosition3D(); Vec3 curPos = _mesh->getPosition3D();
Vec3 curFaceDir; Vec3 curFaceDir;
_sprite3D->getNodeToWorldTransform().getForwardVector(&curFaceDir); _mesh->getNodeToWorldTransform().getForwardVector(&curFaceDir);
curFaceDir = -curFaceDir; curFaceDir = -curFaceDir;
curFaceDir.normalize(); curFaceDir.normalize();
Vec3 newFaceDir = _targetPos - curPos; Vec3 newFaceDir = _targetPos - curPos;
@ -497,7 +497,7 @@ void Camera3DTestDemo::onTouchesEnded(const std::vector<Touch*>& touches, cocos2
auto location = touch->getLocationInView(); auto location = touch->getLocationInView();
if (_camera) if (_camera)
{ {
if (_sprite3D && _cameraType == CameraType::ThirdPerson && _bZoomOut == false && _bZoomIn == false && if (_mesh && _cameraType == CameraType::ThirdPerson && _bZoomOut == false && _bZoomIn == false &&
_bRotateLeft == false && _bRotateRight == false) _bRotateLeft == false && _bRotateRight == false)
{ {
Vec3 nearP(location.x, location.y, -1.0f), farP(location.x, location.y, 1.0f); 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 onTouchesCancelled(const std::vector<Touch*>& touches, cocos2d::Event* event) {}
void Camera3DTestDemo::updateCamera(float fDelta) void Camera3DTestDemo::updateCamera(float fDelta)
{ {
if (_sprite3D) if (_mesh)
{ {
if (_cameraType == CameraType::ThirdPerson) if (_cameraType == CameraType::ThirdPerson)
{ {
@ -541,13 +541,13 @@ void Camera3DTestDemo::updateCamera(float fDelta)
move3D(fDelta); move3D(fDelta);
if (isState(_curState, State_Rotate)) if (isState(_curState, State_Rotate))
{ {
Vec3 curPos = _sprite3D->getPosition3D(); Vec3 curPos = _mesh->getPosition3D();
Vec3 newFaceDir = _targetPos - curPos; Vec3 newFaceDir = _targetPos - curPos;
newFaceDir.y = 0; newFaceDir.y = 0;
newFaceDir.normalize(); newFaceDir.normalize();
Vec3 up; Vec3 up;
_sprite3D->getNodeToWorldTransform().getUpVector(&up); _mesh->getNodeToWorldTransform().getUpVector(&up);
up.normalize(); up.normalize();
Vec3 right; Vec3 right;
Vec3::cross(-newFaceDir, up, &right); Vec3::cross(-newFaceDir, up, &right);
@ -573,7 +573,7 @@ void Camera3DTestDemo::updateCamera(float fDelta)
mat.m[13] = pos.y; mat.m[13] = pos.y;
mat.m[14] = pos.z; mat.m[14] = pos.z;
mat.m[15] = 1.0f; mat.m[15] = 1.0f;
_sprite3D->setAdditionalTransform(&mat); _mesh->setAdditionalTransform(&mat);
} }
} }
} }
@ -583,7 +583,7 @@ void Camera3DTestDemo::updateCamera(float fDelta)
{ {
if (_cameraType == CameraType::ThirdPerson) if (_cameraType == CameraType::ThirdPerson)
{ {
Vec3 lookDir = _camera->getPosition3D() - _sprite3D->getPosition3D(); Vec3 lookDir = _camera->getPosition3D() - _mesh->getPosition3D();
Vec3 cameraPos = _camera->getPosition3D(); Vec3 cameraPos = _camera->getPosition3D();
if (lookDir.length() <= 300) if (lookDir.length() <= 300)
{ {
@ -608,7 +608,7 @@ void Camera3DTestDemo::updateCamera(float fDelta)
{ {
if (_cameraType == CameraType::ThirdPerson) if (_cameraType == CameraType::ThirdPerson)
{ {
Vec3 lookDir = _camera->getPosition3D() - _sprite3D->getPosition3D(); Vec3 lookDir = _camera->getPosition3D() - _mesh->getPosition3D();
Vec3 cameraPos = _camera->getPosition3D(); Vec3 cameraPos = _camera->getPosition3D();
if (lookDir.length() >= 50) if (lookDir.length() >= 50)
{ {
@ -747,9 +747,9 @@ void CameraCullingDemo::onEnter()
// + - // + -
MenuItemFont::setFontSize(40); 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)); 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)); increase->setColor(Color3B(0, 200, 20));
menu = Menu::create(decrease, increase, nullptr); menu = Menu::create(decrease, increase, nullptr);
@ -758,10 +758,10 @@ void CameraCullingDemo::onEnter()
addChild(menu, 1); addChild(menu, 1);
TTFConfig ttfCount("fonts/Marker Felt.ttf", 30); TTFConfig ttfCount("fonts/Marker Felt.ttf", 30);
_labelSprite3DCount = Label::createWithTTF(ttfCount, "0 sprits"); _labelMeshCount = Label::createWithTTF(ttfCount, "0 sprits");
_labelSprite3DCount->setColor(Color3B(0, 200, 20)); _labelMeshCount->setColor(Color3B(0, 200, 20));
_labelSprite3DCount->setPosition(Vec2(s.width / 2, VisibleRect::top().y - 70)); _labelMeshCount->setPosition(Vec2(s.width / 2, VisibleRect::top().y - 70));
addChild(_labelSprite3DCount); addChild(_labelMeshCount);
// aabb drawNode3D // aabb drawNode3D
_drawAABB = DrawNode3D::create(); _drawAABB = DrawNode3D::create();
@ -777,7 +777,7 @@ void CameraCullingDemo::onEnter()
switchViewCallback(this); switchViewCallback(this);
// add sprite // add sprite
addSpriteCallback(nullptr); addMeshCallback(nullptr);
} }
void CameraCullingDemo::onExit() void CameraCullingDemo::onExit()
@ -805,7 +805,7 @@ void CameraCullingDemo::update(float dt)
for (const auto& iter : children) 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)) if (_cameraFirst->isVisibleInFrustum(&aabb))
{ {
aabb.getCorners(corners); aabb.getCorners(corners);
@ -872,7 +872,7 @@ void CameraCullingDemo::switchViewCallback(Ref* sender)
} }
} }
void CameraCullingDemo::addSpriteCallback(Ref* sender) void CameraCullingDemo::addMeshCallback(Ref* sender)
{ {
_layer3D->removeAllChildren(); _layer3D->removeAllChildren();
_objects.clear(); _objects.clear();
@ -883,7 +883,7 @@ void CameraCullingDemo::addSpriteCallback(Ref* sender)
{ {
for (int z = -_row; z < _row; z++) 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->setPosition3D(Vec3(x * 30.0f, 0.0f, z * 30.0f));
sprite->setRotation3D(Vec3(0.0f, 180.0f, 0.0f)); sprite->setRotation3D(Vec3(0.0f, 180.0f, 0.0f));
_objects.push_back(sprite); _objects.push_back(sprite);
@ -897,10 +897,10 @@ void CameraCullingDemo::addSpriteCallback(Ref* sender)
// update sprite number // update sprite number
char szText[16]; char szText[16];
sprintf(szText, "%d sprits", static_cast<int32_t>(_layer3D->getChildrenCount())); 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) if (_row == 0)
return; return;
@ -913,7 +913,7 @@ void CameraCullingDemo::delSpriteCallback(Ref* sender)
{ {
for (int z = -_row; z < _row; z++) 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->setPosition3D(Vec3(x * 30.0f, 0.0f, z * 30.0f));
_objects.push_back(sprite); _objects.push_back(sprite);
_layer3D->addChild(sprite); _layer3D->addChild(sprite);
@ -926,7 +926,7 @@ void CameraCullingDemo::delSpriteCallback(Ref* sender)
// update sprite number // update sprite number
char szText[16]; char szText[16];
sprintf(szText, "%l sprits", static_cast<int32_t>(_layer3D->getChildrenCount())); sprintf(szText, "%l sprits", static_cast<int32_t>(_layer3D->getChildrenCount()));
_labelSprite3DCount->setString(szText); _labelMeshCount->setString(szText);
} }
void CameraCullingDemo::drawCameraFrustum() void CameraCullingDemo::drawCameraFrustum()
@ -993,8 +993,8 @@ CameraArcBallDemo::CameraArcBallDemo()
, _operate(OperateCamType::RotateCamera) , _operate(OperateCamType::RotateCamera)
, _center(Vec3(0, 0, 0)) , _center(Vec3(0, 0, 0))
, _target(0) , _target(0)
, _sprite3D1(nullptr) , _mesh1(nullptr)
, _sprite3D2(nullptr) , _mesh2(nullptr)
{} {}
CameraArcBallDemo::~CameraArcBallDemo() {} CameraArcBallDemo::~CameraArcBallDemo() {}
@ -1043,17 +1043,17 @@ void CameraArcBallDemo::onEnter()
_layer3D->addChild(_camera); _layer3D->addChild(_camera);
} }
_sprite3D1 = Sprite3D::create("Sprite3DTest/orc.c3b"); _mesh1 = MeshRenderer::create("MeshRendererTest/orc.c3b");
_sprite3D1->setScale(0.5); _mesh1->setScale(0.5);
_sprite3D1->setRotation3D(Vec3(0.0f, 180.0f, 0.0f)); _mesh1->setRotation3D(Vec3(0.0f, 180.0f, 0.0f));
_sprite3D1->setPosition3D(Vec3(0, 0, 0)); _mesh1->setPosition3D(Vec3(0, 0, 0));
_layer3D->addChild(_sprite3D1); _layer3D->addChild(_mesh1);
_sprite3D2 = Sprite3D::create("Sprite3DTest/boss.c3b"); _mesh2 = MeshRenderer::create("MeshRendererTest/boss.c3b");
_sprite3D2->setScale(0.6f); _mesh2->setScale(0.6f);
_sprite3D2->setRotation3D(Vec3(-90.0f, 0.0f, 0.0f)); _mesh2->setRotation3D(Vec3(-90.0f, 0.0f, 0.0f));
_sprite3D2->setPosition3D(Vec3(20.0f, 0.0f, 0.0f)); _mesh2->setPosition3D(Vec3(20.0f, 0.0f, 0.0f));
_layer3D->addChild(_sprite3D2); _layer3D->addChild(_mesh2);
_drawGrid = DrawNode3D::create(); _drawGrid = DrawNode3D::create();
@ -1187,13 +1187,13 @@ void CameraArcBallDemo::switchTargetCallback(Ref* sender)
if (_target == 0) if (_target == 0)
{ {
_target = 1; _target = 1;
_center = _sprite3D2->getPosition3D(); _center = _mesh2->getPosition3D();
updateCameraTransform(); updateCameraTransform();
} }
else if (_target == 1) else if (_target == 1)
{ {
_target = 0; _target = 0;
_center = _sprite3D1->getPosition3D(); _center = _mesh1->getPosition3D();
updateCameraTransform(); updateCameraTransform();
} }
} }
@ -1253,18 +1253,18 @@ void FogTestDemo::onEnter()
CC_SAFE_RELEASE_NULL(_programState1); CC_SAFE_RELEASE_NULL(_programState1);
CC_SAFE_RELEASE_NULL(_programState2); CC_SAFE_RELEASE_NULL(_programState2);
auto vertexSource = FileUtils::getInstance()->getStringFromFile("Sprite3DTest/fog.vert"); auto vertexSource = FileUtils::getInstance()->getStringFromFile("MeshRendererTest/fog.vert");
auto fragSource = FileUtils::getInstance()->getStringFromFile("Sprite3DTest/fog.frag"); auto fragSource = FileUtils::getInstance()->getStringFromFile("MeshRendererTest/fog.frag");
auto program = backend::Device::getInstance()->newProgram(vertexSource, fragSource); auto program = backend::Device::getInstance()->newProgram(vertexSource, fragSource);
_programState1 = new backend::ProgramState(program); _programState1 = new backend::ProgramState(program);
_programState2 = new backend::ProgramState(program); _programState2 = new backend::ProgramState(program);
CC_SAFE_RELEASE(program); CC_SAFE_RELEASE(program);
_sprite3D1 = Sprite3D::create("Sprite3DTest/teapot.c3b"); _mesh1 = MeshRenderer::create("MeshRendererTest/teapot.c3b");
_sprite3D2 = Sprite3D::create("Sprite3DTest/teapot.c3b"); _mesh2 = MeshRenderer::create("MeshRendererTest/teapot.c3b");
_sprite3D1->setProgramState(_programState1); _mesh1->setProgramState(_programState1);
_sprite3D2->setProgramState(_programState2); _mesh2->setProgramState(_programState2);
auto fogColor = Vec4(0.5, 0.5, 0.5, 1.0); auto fogColor = Vec4(0.5, 0.5, 0.5, 1.0);
float fogStart = 10; float fogStart = 10;
@ -1276,15 +1276,15 @@ void FogTestDemo::onEnter()
SET_UNIFORM("u_fogEnd", &fogEnd, sizeof(fogEnd)); SET_UNIFORM("u_fogEnd", &fogEnd, sizeof(fogEnd));
SET_UNIFORM("u_fogEquation", &fogEquation, sizeof(fogEquation)); SET_UNIFORM("u_fogEquation", &fogEquation, sizeof(fogEquation));
_layer3D->addChild(_sprite3D1); _layer3D->addChild(_mesh1);
_sprite3D1->setPosition3D(Vec3(0, 0, 0)); _mesh1->setPosition3D(Vec3(0, 0, 0));
_sprite3D1->setScale(2.0f); _mesh1->setScale(2.0f);
_sprite3D1->setRotation3D(Vec3(-90.0f, 180.0f, 0.0f)); _mesh1->setRotation3D(Vec3(-90.0f, 180.0f, 0.0f));
_layer3D->addChild(_sprite3D2); _layer3D->addChild(_mesh2);
_sprite3D2->setPosition3D(Vec3(0.0f, 0.0f, -20.0f)); _mesh2->setPosition3D(Vec3(0.0f, 0.0f, -20.0f));
_sprite3D2->setScale(2.0f); _mesh2->setScale(2.0f);
_sprite3D2->setRotation3D(Vec3(-90.0f, 180.0f, 0.0f)); _mesh2->setRotation3D(Vec3(-90.0f, 180.0f, 0.0f));
if (_camera == nullptr) if (_camera == nullptr)
{ {
@ -1303,14 +1303,14 @@ void FogTestDemo::onEnter()
CC_SAFE_RELEASE_NULL(_programState1); CC_SAFE_RELEASE_NULL(_programState1);
CC_SAFE_RELEASE_NULL(_programState2); CC_SAFE_RELEASE_NULL(_programState2);
auto vertexSource = FileUtils::getInstance()->getStringFromFile("Sprite3DTest/fog.vert"); auto vertexSource = FileUtils::getInstance()->getStringFromFile("MeshRendererTest/fog.vert");
auto fragSource = FileUtils::getInstance()->getStringFromFile("Sprite3DTest/fog.frag"); auto fragSource = FileUtils::getInstance()->getStringFromFile("MeshRendererTest/fog.frag");
auto program = backend::Device::getInstance()->newProgram(vertexSource, fragSource); auto program = backend::Device::getInstance()->newProgram(vertexSource, fragSource);
_programState1 = new backend::ProgramState(program); _programState1 = new backend::ProgramState(program);
_programState2 = new backend::ProgramState(program); _programState2 = new backend::ProgramState(program);
_sprite3D1->setProgramState(_programState1); _mesh1->setProgramState(_programState1);
_sprite3D2->setProgramState(_programState2); _mesh2->setProgramState(_programState2);
CC_SAFE_RELEASE(program); CC_SAFE_RELEASE(program);
auto fogColor = Vec4(0.5, 0.5, 0.5, 1.0); 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(); // CameraBaseTest::onEnter();
// //auto sprite = Sprite::createWithTexture(fbo); // //auto sprite = Sprite::createWithTexture(fbo);
// //sprite->setPosition(Vec2(100,100)); // //sprite->setPosition(Vec2(100,100));
// //std::string filename = "Sprite3DTest/girl.c3b"; // //std::string filename = "MeshRendererTest/girl.c3b";
// //auto sprite = Sprite3D::create(filename); // //auto sprite = MeshRenderer::create(filename);
// //sprite->setScale(1.0); // //sprite->setScale(1.0);
// //auto animation = Animation3D::create(filename); // //auto animation = Animation3D::create(filename);
// //if (animation) // //if (animation)
@ -1500,10 +1500,10 @@ void BackgroundColorBrushTest::onEnter()
addChild(camera); addChild(camera);
// 3D model // 3D model
auto model = Sprite3D::create("Sprite3DTest/boss1.obj"); auto model = MeshRenderer::create("MeshRendererTest/boss1.obj");
model->setScale(4); model->setScale(4);
model->setPosition3D(Vec3(20.0f, 0.0f, 0.0f)); 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)); model->setCameraMask(static_cast<unsigned short>(CameraFlag::USER1));
addChild(model); addChild(model);
model->runAction(RepeatForever::create(RotateBy::create(1.f, Vec3(10.0f, 20.0f, 30.0f)))); model->runAction(RepeatForever::create(RotateBy::create(1.f, Vec3(10.0f, 20.0f, 30.0f))));
@ -1538,10 +1538,10 @@ void BackgroundColorBrushTest::onEnter()
addChild(slider); addChild(slider);
// 3D model for 2nd camera // 3D model for 2nd camera
auto model = Sprite3D::create("Sprite3DTest/boss1.obj"); auto model = MeshRenderer::create("MeshRendererTest/boss1.obj");
model->setScale(4); model->setScale(4);
model->setPosition3D(Vec3(-20.0f, 0.0f, 0.0f)); 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)); model->setCameraMask(static_cast<unsigned short>(CameraFlag::USER2));
base->addChild(model); base->addChild(model);
model->runAction(RepeatForever::create(RotateBy::create(1.f, Vec3(10.0f, 20.0f, 30.0f)))); model->runAction(RepeatForever::create(RotateBy::create(1.f, Vec3(10.0f, 20.0f, 30.0f))));

View File

@ -26,7 +26,7 @@ THE SOFTWARE.
#pragma once #pragma once
#include "../BaseTest.h" #include "../BaseTest.h"
#include "../Sprite3DTest/DrawNode3D.h" #include "../MeshRendererTest/DrawNode3D.h"
#include "renderer/backend/ProgramState.h" #include "renderer/backend/ProgramState.h"
#include "renderer/backend/Types.h" #include "renderer/backend/Types.h"
@ -35,7 +35,7 @@ THE SOFTWARE.
namespace cocos2d namespace cocos2d
{ {
class Sprite3D; class MeshRenderer;
class Delay; class Delay;
} // namespace cocos2d } // namespace cocos2d
@ -142,7 +142,7 @@ public:
protected: protected:
std::string _title; std::string _title;
cocos2d::Layer* _layer3D; cocos2d::Layer* _layer3D;
cocos2d::Sprite3D* _sprite3D; cocos2d::MeshRenderer* _mesh;
cocos2d::Vec3 _targetPos; cocos2d::Vec3 _targetPos;
CameraType _cameraType; CameraType _cameraType;
cocos2d::MenuItem* _incRot; cocos2d::MenuItem* _incRot;
@ -176,15 +176,15 @@ public:
virtual std::string title() const override; virtual std::string title() const override;
void reachEndCallBack(); void reachEndCallBack();
void switchViewCallback(cocos2d::Ref* sender); void switchViewCallback(cocos2d::Ref* sender);
void addSpriteCallback(cocos2d::Ref* sender); void addMeshCallback(cocos2d::Ref* sender);
void delSpriteCallback(cocos2d::Ref* sender); void delMeshCallback(cocos2d::Ref* sender);
void drawCameraFrustum(); void drawCameraFrustum();
protected: protected:
cocos2d::Label* _labelSprite3DCount; cocos2d::Label* _labelMeshCount;
cocos2d::Layer* _layer3D; cocos2d::Layer* _layer3D;
std::vector<cocos2d::Sprite3D*> _objects; std::vector<cocos2d::MeshRenderer*> _objects;
CameraType _cameraType; CameraType _cameraType;
cocos2d::Camera* _cameraFirst; cocos2d::Camera* _cameraFirst;
cocos2d::Camera* _cameraThird; cocos2d::Camera* _cameraThird;
@ -232,8 +232,8 @@ protected:
OperateCamType _operate; // switch rotate or zoom OperateCamType _operate; // switch rotate or zoom
cocos2d::Vec3 _center; // camera look target cocos2d::Vec3 _center; // camera look target
int _target; // switch camera look target int _target; // switch camera look target
cocos2d::Sprite3D* _sprite3D1; cocos2d::MeshRenderer* _mesh1;
cocos2d::Sprite3D* _sprite3D2; cocos2d::MeshRenderer* _mesh2;
}; };
class FogTestDemo : public CameraBaseTest class FogTestDemo : public CameraBaseTest
@ -259,8 +259,8 @@ protected:
CameraType _cameraType = CameraType::Free; CameraType _cameraType = CameraType::Free;
cocos2d::Layer* _layer3D = nullptr; cocos2d::Layer* _layer3D = nullptr;
cocos2d::Camera* _camera = nullptr; cocos2d::Camera* _camera = nullptr;
cocos2d::Sprite3D* _sprite3D1 = nullptr; cocos2d::MeshRenderer* _mesh1 = nullptr;
cocos2d::Sprite3D* _sprite3D2 = nullptr; cocos2d::MeshRenderer* _mesh2 = nullptr;
cocos2d::backend::ProgramState* _programState1 = nullptr; cocos2d::backend::ProgramState* _programState1 = nullptr;
cocos2d::backend::ProgramState* _programState2 = nullptr; cocos2d::backend::ProgramState* _programState2 = nullptr;

View File

@ -108,8 +108,8 @@ void LightTest::addSprite()
auto s = Director::getInstance()->getWinSize(); auto s = Director::getInstance()->getWinSize();
//{ //{
// std::string fileName = "Sprite3DTest/plane.c3b"; // std::string fileName = "MeshRendererTest/plane.c3b";
// auto sprite = Sprite3D::create(fileName); // auto sprite = MeshRenderer::create(fileName);
// sprite->setRotation3D(Vec3(-90.0, 0.0, 0.0)); // sprite->setRotation3D(Vec3(-90.0, 0.0, 0.0));
// sprite->setScale(5.0f); // sprite->setScale(5.0f);
// sprite->setPosition(Vec2(0.0, -50.0)); // sprite->setPosition(Vec2(0.0, -50.0));
@ -118,35 +118,35 @@ void LightTest::addSprite()
//} //}
{ {
std::string fileName = "Sprite3DTest/orc.c3b"; std::string fileName = "MeshRendererTest/orc.c3b";
auto sprite = Sprite3D::create(fileName); auto mesh = MeshRenderer::create(fileName);
sprite->setRotation3D(Vec3(0.0f, 180.0f, 0.0f)); mesh->setRotation3D(Vec3(0.0f, 180.0f, 0.0f));
sprite->setPosition(Vec2(0.0f, 0.0f)); mesh->setPosition(Vec2(0.0f, 0.0f));
sprite->setScale(2.0); mesh->setScale(2.0);
auto sp = Sprite3D::create("Sprite3DTest/axe.c3b"); auto m = MeshRenderer::create("MeshRendererTest/axe.c3b");
sprite->getAttachNode("Bip001 R Hand")->addChild(sp); mesh->getAttachNode("Bip001 R Hand")->addChild(m);
auto animation = Animation3D::create(fileName); auto animation = Animation3D::create(fileName);
if (animation) if (animation)
{ {
auto animate = Animate3D::create(animation); auto animate = Animate3D::create(animation);
sprite->runAction(RepeatForever::create(animate)); mesh->runAction(RepeatForever::create(animate));
} }
addChild(sprite); addChild(mesh);
sprite->setCameraMask(2); mesh->setCameraMask(2);
} }
{ {
std::string fileName = "Sprite3DTest/sphere.c3b"; std::string fileName = "MeshRendererTest/sphere.c3b";
auto sprite = Sprite3D::create(fileName); auto sprite = MeshRenderer::create(fileName);
sprite->setPosition(Vec2(30.0f, 0.0f)); sprite->setPosition(Vec2(30.0f, 0.0f));
addChild(sprite); addChild(sprite);
sprite->setCameraMask(2); sprite->setCameraMask(2);
} }
{ {
std::string fileName = "Sprite3DTest/sphere.c3b"; std::string fileName = "MeshRendererTest/sphere.c3b";
auto sprite = Sprite3D::create(fileName); auto sprite = MeshRenderer::create(fileName);
sprite->setScale(0.5f); sprite->setScale(0.5f);
sprite->setPosition(Vec2(-50.0f, 0.0f)); sprite->setPosition(Vec2(-50.0f, 0.0f));
addChild(sprite); addChild(sprite);
@ -154,8 +154,8 @@ void LightTest::addSprite()
} }
{ {
std::string fileName = "Sprite3DTest/sphere.c3b"; std::string fileName = "MeshRendererTest/sphere.c3b";
auto sprite = Sprite3D::create(fileName); auto sprite = MeshRenderer::create(fileName);
sprite->setScale(0.5f); sprite->setScale(0.5f);
sprite->setPosition(Vec2(-30.0f, 10.0f)); sprite->setPosition(Vec2(-30.0f, 10.0f));
addChild(sprite); addChild(sprite);

View File

@ -45,8 +45,8 @@ MaterialSystemTest::MaterialSystemTest()
ADD_TEST_CASE(Material_AutoBindings); ADD_TEST_CASE(Material_AutoBindings);
ADD_TEST_CASE(Material_setTechnique); ADD_TEST_CASE(Material_setTechnique);
ADD_TEST_CASE(Material_clone); ADD_TEST_CASE(Material_clone);
ADD_TEST_CASE(Material_MultipleSprite3D); ADD_TEST_CASE(Material_MultipleMeshRenderer);
ADD_TEST_CASE(Material_Sprite3DTest); ADD_TEST_CASE(Material_MeshRendererTest);
ADD_TEST_CASE(Material_parsePerformance); ADD_TEST_CASE(Material_parsePerformance);
} }
@ -57,30 +57,30 @@ std::string MaterialSystemBaseTest::title() const
// MARK: Tests start here // MARK: Tests start here
void Material_Sprite3DTest::onEnter() void Material_MeshRendererTest::onEnter()
{ {
MaterialSystemBaseTest::onEnter(); MaterialSystemBaseTest::onEnter();
auto sprite = Sprite3D::create("Sprite3DTest/boss1.obj"); auto mesh = MeshRenderer::create("MeshRendererTest/boss1.obj");
sprite->setScale(8.f); mesh->setScale(8.f);
sprite->setTexture("Sprite3DTest/boss.png"); mesh->setTexture("MeshRendererTest/boss.png");
this->addChild(sprite); this->addChild(mesh);
sprite->setPositionNormalized(Vec2(0.5f, 0.5f)); 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(); MaterialSystemBaseTest::onEnter();
const char* names[] = { const char* names[] = {
"Sprite3DTest/ReskinGirl.c3b", "Sprite3DTest/ReskinGirl.c3b", "Sprite3DTest/ReskinGirl.c3b", "MeshRendererTest/ReskinGirl.c3b", "MeshRendererTest/ReskinGirl.c3b", "MeshRendererTest/ReskinGirl.c3b",
"Sprite3DTest/ReskinGirl.c3b", "Sprite3DTest/ReskinGirl.c3b", "Sprite3DTest/ReskinGirl.c3b", "MeshRendererTest/ReskinGirl.c3b", "MeshRendererTest/ReskinGirl.c3b", "MeshRendererTest/ReskinGirl.c3b",
"Sprite3DTest/ReskinGirl.c3b", "Sprite3DTest/ReskinGirl.c3b", "MeshRendererTest/ReskinGirl.c3b", "MeshRendererTest/ReskinGirl.c3b",
}; };
const int totalNames = sizeof(names) / sizeof(names[0]); const int totalNames = sizeof(names) / sizeof(names[0]);
@ -89,14 +89,14 @@ void Material_MultipleSprite3D::onEnter()
for (int i = 0; i < totalNames; i++) for (int i = 0; i < totalNames; i++)
{ {
auto sprite = Sprite3D::create(names[i]); auto mesh = MeshRenderer::create(names[i]);
this->addChild(sprite); this->addChild(mesh);
sprite->setPosition(Vec2((size.width / (totalNames + 1)) * (i + 1), size.height / 4)); mesh->setPosition(Vec2((size.width / (totalNames + 1)) * (i + 1), size.height / 4));
sprite->setScale(3); mesh->setScale(3);
} }
} }
std::string Material_MultipleSprite3D::subtitle() const std::string Material_MultipleMeshRenderer::subtitle() const
{ {
return "Sprites with multiple meshes"; return "Sprites with multiple meshes";
} }
@ -115,40 +115,40 @@ void Material_2DEffects::onEnter()
Material* mat1 = Material::createWithProperties(properties); Material* mat1 = Material::createWithProperties(properties);
auto spriteBlur = Sprite::create("Images/grossini.png"); auto meshBlur = Sprite::create("Images/grossini.png");
spriteBlur->setPositionNormalized(Vec2(0.2f, 0.5f)); meshBlur->setPositionNormalized(Vec2(0.2f, 0.5f));
this->addChild(spriteBlur); this->addChild(meshBlur);
spriteBlur->setProgramState(mat1->getTechniqueByName("blur")->getPassByIndex(0)->getProgramState()); meshBlur->setProgramState(mat1->getTechniqueByName("blur")->getPassByIndex(0)->getProgramState());
auto spriteOutline = Sprite::create("Images/grossini.png"); auto meshOutline = Sprite::create("Images/grossini.png");
spriteOutline->setPositionNormalized(Vec2(0.4f, 0.5f)); meshOutline->setPositionNormalized(Vec2(0.4f, 0.5f));
this->addChild(spriteOutline); this->addChild(meshOutline);
spriteOutline->setProgramState(mat1->getTechniqueByName("outline")->getPassByIndex(0)->getProgramState()); meshOutline->setProgramState(mat1->getTechniqueByName("outline")->getPassByIndex(0)->getProgramState());
auto spriteNoise = Sprite::create("Images/grossini.png"); auto meshNoise = Sprite::create("Images/grossini.png");
spriteNoise->setPositionNormalized(Vec2(0.6f, 0.5f)); meshNoise->setPositionNormalized(Vec2(0.6f, 0.5f));
this->addChild(spriteNoise); this->addChild(meshNoise);
spriteNoise->setProgramState(mat1->getTechniqueByName("noise")->getPassByIndex(0)->getProgramState()); meshNoise->setProgramState(mat1->getTechniqueByName("noise")->getPassByIndex(0)->getProgramState());
auto spriteEdgeDetect = Sprite::create("Images/grossini.png"); auto meshEdgeDetect = Sprite::create("Images/grossini.png");
spriteEdgeDetect->setPositionNormalized(Vec2(0.8f, 0.5f)); meshEdgeDetect->setPositionNormalized(Vec2(0.8f, 0.5f));
this->addChild(spriteEdgeDetect); this->addChild(meshEdgeDetect);
spriteEdgeDetect->setProgramState(mat1->getTechniqueByName("edge_detect")->getPassByIndex(0)->getProgramState()); meshEdgeDetect->setProgramState(mat1->getTechniqueByName("edge_detect")->getPassByIndex(0)->getProgramState());
timeUniforms.clear(); timeUniforms.clear();
#define FETCH_CCTIME_LOCATION(sprite) \ #define FETCH_CCTIME_LOCATION(mesh) \
do \ do \
{ \ { \
auto programState = sprite->getProgramState(); \ auto programState = mesh->getProgramState(); \
auto location = programState->getUniformLocation("u_Time"); \ auto location = programState->getUniformLocation("u_Time"); \
timeUniforms.emplace_back(programState, location); \ timeUniforms.emplace_back(programState, location); \
} while (0) } while (0)
FETCH_CCTIME_LOCATION(spriteBlur); FETCH_CCTIME_LOCATION(meshBlur);
FETCH_CCTIME_LOCATION(spriteOutline); FETCH_CCTIME_LOCATION(meshOutline);
FETCH_CCTIME_LOCATION(spriteNoise); FETCH_CCTIME_LOCATION(meshNoise);
FETCH_CCTIME_LOCATION(spriteEdgeDetect); FETCH_CCTIME_LOCATION(meshEdgeDetect);
schedule(CC_SCHEDULE_SELECTOR(Material_2DEffects::updateCCTimeUniforms)); schedule(CC_SCHEDULE_SELECTOR(Material_2DEffects::updateCCTimeUniforms));
@ -245,27 +245,27 @@ void Material_AutoBindings::onEnter()
Material* mat1 = Material::createWithProperties(properties); Material* mat1 = Material::createWithProperties(properties);
auto spriteBlur = Sprite::create("Images/grossini.png"); auto meshBlur = Sprite::create("Images/grossini.png");
spriteBlur->setPositionNormalized(Vec2(0.2f, 0.5f)); meshBlur->setPositionNormalized(Vec2(0.2f, 0.5f));
this->addChild(spriteBlur); this->addChild(meshBlur);
spriteBlur->setProgramState(mat1->getTechniqueByName("blur")->getPassByIndex(0)->getProgramState()); meshBlur->setProgramState(mat1->getTechniqueByName("blur")->getPassByIndex(0)->getProgramState());
auto spriteOutline = Sprite::create("Images/grossini.png"); auto meshOutline = Sprite::create("Images/grossini.png");
spriteOutline->setPositionNormalized(Vec2(0.4f, 0.5f)); meshOutline->setPositionNormalized(Vec2(0.4f, 0.5f));
this->addChild(spriteOutline); this->addChild(meshOutline);
spriteOutline->setProgramState(mat1->getTechniqueByName("outline")->getPassByIndex(0)->getProgramState()); meshOutline->setProgramState(mat1->getTechniqueByName("outline")->getPassByIndex(0)->getProgramState());
auto spriteNoise = Sprite::create("Images/grossini.png"); auto meshNoise = Sprite::create("Images/grossini.png");
spriteNoise->setPositionNormalized(Vec2(0.6f, 0.5f)); meshNoise->setPositionNormalized(Vec2(0.6f, 0.5f));
this->addChild(spriteNoise); this->addChild(meshNoise);
spriteNoise->setProgramState(mat1->getTechniqueByName("noise")->getPassByIndex(0)->getProgramState()); meshNoise->setProgramState(mat1->getTechniqueByName("noise")->getPassByIndex(0)->getProgramState());
auto spriteEdgeDetect = Sprite::create("Images/grossini.png"); auto meshEdgeDetect = Sprite::create("Images/grossini.png");
spriteEdgeDetect->setPositionNormalized(Vec2(0.8f, 0.5f)); meshEdgeDetect->setPositionNormalized(Vec2(0.8f, 0.5f));
this->addChild(spriteEdgeDetect); this->addChild(meshEdgeDetect);
spriteEdgeDetect->setProgramState(mat1->getTechniqueByName("edge_detect")->getPassByIndex(0)->getProgramState()); meshEdgeDetect->setProgramState(mat1->getTechniqueByName("edge_detect")->getPassByIndex(0)->getProgramState());
_noiseProgramState = spriteNoise->getProgramState(); _noiseProgramState = meshNoise->getProgramState();
_locationTime = _noiseProgramState->getUniformLocation("u_Time"); _locationTime = _noiseProgramState->getUniformLocation("u_Time");
schedule(CC_SCHEDULE_SELECTOR(Material_AutoBindings::updateUniformTime)); schedule(CC_SCHEDULE_SELECTOR(Material_AutoBindings::updateUniformTime));
@ -292,14 +292,14 @@ void Material_setTechnique::onEnter()
{ {
MaterialSystemBaseTest::onEnter(); MaterialSystemBaseTest::onEnter();
auto sprite = Sprite3D::create("Sprite3DTest/boss1.obj"); auto mesh = MeshRenderer::create("MeshRendererTest/boss1.obj");
sprite->setScale(6); mesh->setScale(6);
this->addChild(sprite); this->addChild(mesh);
sprite->setPositionNormalized(Vec2(0.5f, 0.5f)); mesh->setPositionNormalized(Vec2(0.5f, 0.5f));
_sprite = sprite; _mesh = mesh;
Material* mat = Material::createWithFilename("Materials/3d_effects.material"); Material* mat = Material::createWithFilename("Materials/3d_effects.material");
sprite->setMaterial(mat); mesh->setMaterial(mat);
// lights // lights
auto light1 = AmbientLight::create(Color3B::RED); 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 rot = RotateBy::create(5, Vec3(30.0f, 60.0f, 270.0f));
auto repeat = RepeatForever::create(rot); auto repeat = RepeatForever::create(rot);
sprite->runAction(repeat); mesh->runAction(repeat);
} }
std::string Material_setTechnique::subtitle() const std::string Material_setTechnique::subtitle() const
@ -327,13 +327,13 @@ void Material_setTechnique::changeMaterial(float dt)
switch (_techniqueState) switch (_techniqueState)
{ {
case 0: case 0:
_sprite->getMaterial(0)->setTechnique("lit"); _mesh->getMaterial(0)->setTechnique("lit");
break; break;
case 1: case 1:
_sprite->getMaterial(0)->setTechnique("normal"); _mesh->getMaterial(0)->setTechnique("normal");
break; break;
case 2: case 2:
_sprite->getMaterial(0)->setTechnique("outline"); _mesh->getMaterial(0)->setTechnique("outline");
break; break;
default: default:
break; break;
@ -349,40 +349,40 @@ void Material_clone::onEnter()
{ {
MaterialSystemBaseTest::onEnter(); MaterialSystemBaseTest::onEnter();
auto sprite = Sprite3D::create("Sprite3DTest/boss1.obj"); auto mesh = MeshRenderer::create("MeshRendererTest/boss1.obj");
sprite->setScale(3); mesh->setScale(3);
this->addChild(sprite); this->addChild(mesh);
sprite->setPositionNormalized(Vec2(0.25f, 0.5f)); mesh->setPositionNormalized(Vec2(0.25f, 0.5f));
Material* mat = Material::createWithFilename("Materials/3d_effects.material"); 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 rot = RotateBy::create(5, Vec3(360.0f, 240.0f, 120.0f));
auto repeat = RepeatForever::create(rot); auto repeat = RepeatForever::create(rot);
sprite->runAction(repeat); mesh->runAction(repeat);
// sprite 2... using same material // mesh 2... using same material
auto sprite2 = Sprite3D::create("Sprite3DTest/boss1.obj"); auto mesh2 = MeshRenderer::create("MeshRendererTest/boss1.obj");
sprite2->setScale(3); mesh2->setScale(3);
this->addChild(sprite2); this->addChild(mesh2);
sprite2->setPositionNormalized(Vec2(0.5f, 0.5f)); mesh2->setPositionNormalized(Vec2(0.5f, 0.5f));
sprite2->setMaterial(mat); mesh2->setMaterial(mat);
sprite2->runAction(repeat->clone()); mesh2->runAction(repeat->clone());
// sprite 3... using cloned material // mesh 3... using cloned material
auto sprite3 = Sprite3D::create("Sprite3DTest/boss1.obj"); auto mesh3 = MeshRenderer::create("MeshRendererTest/boss1.obj");
sprite3->setScale(3); mesh3->setScale(3);
this->addChild(sprite3); this->addChild(mesh3);
sprite3->setPositionNormalized(Vec2(0.75f, 0.5f)); mesh3->setPositionNormalized(Vec2(0.75f, 0.5f));
auto mat2 = mat->clone(); auto mat2 = mat->clone();
sprite3->setMaterial(mat2); mesh3->setMaterial(mat2);
sprite3->runAction(repeat->clone()); mesh3->runAction(repeat->clone());
// testing clone // testing clone
// should affect both sprite 1 and sprite 2 // should affect both mesh 1 and mesh 2
mat->setTechnique("outline"); mat->setTechnique("outline");
// should affect only sprite 3 // should affect only mesh 3
// mat2->setTechnique("normal"); // mat2->setTechnique("normal");
} }

View File

@ -39,19 +39,19 @@ public:
virtual std::string title() const override; virtual std::string title() const override;
}; };
class Material_Sprite3DTest : public MaterialSystemBaseTest class Material_MeshRendererTest : public MaterialSystemBaseTest
{ {
public: public:
CREATE_FUNC(Material_Sprite3DTest); CREATE_FUNC(Material_MeshRendererTest);
virtual void onEnter() override; virtual void onEnter() override;
virtual std::string subtitle() const override; virtual std::string subtitle() const override;
}; };
class Material_MultipleSprite3D : public MaterialSystemBaseTest class Material_MultipleMeshRenderer : public MaterialSystemBaseTest
{ {
public: public:
CREATE_FUNC(Material_MultipleSprite3D); CREATE_FUNC(Material_MultipleMeshRenderer);
virtual void onEnter() override; virtual void onEnter() override;
virtual std::string subtitle() const override; virtual std::string subtitle() const override;
@ -110,7 +110,7 @@ public:
private: private:
void changeMaterial(float dt); void changeMaterial(float dt);
cocos2d::Sprite3D* _sprite; cocos2d::MeshRenderer* _mesh;
int _techniqueState; int _techniqueState;
}; };

View File

@ -31,7 +31,7 @@
namespace cocos2d namespace cocos2d
{ {
class Animate3D; class Animate3D;
class Sprite3D; class MeshRenderer;
class Delay; class Delay;
class Ray; class Ray;
class DrawNode3D; class DrawNode3D;
@ -39,53 +39,53 @@ class GLProgramState;
class MotionStreak3D; class MotionStreak3D;
} // namespace cocos2d } // namespace cocos2d
DEFINE_TEST_SUITE(Sprite3DTests); DEFINE_TEST_SUITE(MeshRendererTests);
class Sprite3DTestDemo : public TestCase class MeshRendererTestDemo : public TestCase
{ {
public: public:
// overrides // overrides
virtual std::string title() const override; virtual std::string title() const override;
virtual ~Sprite3DTestDemo(); virtual ~MeshRendererTestDemo();
}; };
class Sprite3DForceDepthTest : public Sprite3DTestDemo class MeshRendererForceDepthTest : public MeshRendererTestDemo
{ {
public: public:
CREATE_FUNC(Sprite3DForceDepthTest); CREATE_FUNC(MeshRendererForceDepthTest);
Sprite3DForceDepthTest(); MeshRendererForceDepthTest();
virtual std::string title() const override; virtual std::string title() const override;
virtual std::string subtitle() const override; virtual std::string subtitle() const override;
}; };
class Sprite3DEmptyTest : public Sprite3DTestDemo class MeshRendererEmptyTest : public MeshRendererTestDemo
{ {
public: public:
CREATE_FUNC(Sprite3DEmptyTest); CREATE_FUNC(MeshRendererEmptyTest);
Sprite3DEmptyTest(); MeshRendererEmptyTest();
virtual std::string title() const override; virtual std::string title() const override;
virtual std::string subtitle() const override; virtual std::string subtitle() const override;
}; };
class Sprite3DBasicTest : public Sprite3DTestDemo class MeshRendererBasicTest : public MeshRendererTestDemo
{ {
public: public:
CREATE_FUNC(Sprite3DBasicTest); CREATE_FUNC(MeshRendererBasicTest);
Sprite3DBasicTest(); MeshRendererBasicTest();
virtual std::string title() const override; virtual std::string title() const override;
virtual std::string subtitle() 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); void onTouchesEnded(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event* event);
}; };
class Sprite3DUVAnimationTest : public Sprite3DTestDemo class MeshRendererUVAnimationTest : public MeshRendererTestDemo
{ {
public: public:
CREATE_FUNC(Sprite3DUVAnimationTest); CREATE_FUNC(MeshRendererUVAnimationTest);
Sprite3DUVAnimationTest(); MeshRendererUVAnimationTest();
virtual ~Sprite3DUVAnimationTest(); virtual ~MeshRendererUVAnimationTest();
virtual std::string title() const override; virtual std::string title() const override;
virtual std::string subtitle() const override; virtual std::string subtitle() const override;
@ -101,7 +101,7 @@ protected:
#endif #endif
}; };
class Sprite3DFakeShadowTest : public Sprite3DTestDemo class MeshRendererFakeShadowTest : public MeshRendererTestDemo
{ {
public: public:
enum State enum State
@ -111,9 +111,9 @@ public:
State_Move = 0x02, State_Move = 0x02,
State_Rotate = 0x04 State_Rotate = 0x04
}; };
CREATE_FUNC(Sprite3DFakeShadowTest); CREATE_FUNC(MeshRendererFakeShadowTest);
Sprite3DFakeShadowTest(); MeshRendererFakeShadowTest();
virtual ~Sprite3DFakeShadowTest(); virtual ~MeshRendererFakeShadowTest();
virtual std::string title() const override; virtual std::string title() const override;
virtual std::string subtitle() const override; virtual std::string subtitle() const override;
void Move(cocos2d::Ref* sender, int value); void Move(cocos2d::Ref* sender, int value);
@ -129,8 +129,8 @@ private:
cocos2d::Camera* _camera; cocos2d::Camera* _camera;
cocos2d::Vec3 _targetPos; cocos2d::Vec3 _targetPos;
unsigned int _curState; unsigned int _curState;
cocos2d::Sprite3D* _plane; cocos2d::MeshRenderer* _plane;
cocos2d::Sprite3D* _orc; cocos2d::MeshRenderer* _orc;
cocos2d::backend::ProgramState* _state = nullptr; cocos2d::backend::ProgramState* _state = nullptr;
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
@ -138,12 +138,12 @@ private:
#endif #endif
}; };
class Sprite3DLightMapTest : public Sprite3DTestDemo class MeshRendererLightMapTest : public MeshRendererTestDemo
{ {
public: public:
CREATE_FUNC(Sprite3DLightMapTest); CREATE_FUNC(MeshRendererLightMapTest);
Sprite3DLightMapTest(); MeshRendererLightMapTest();
virtual ~Sprite3DLightMapTest(); virtual ~MeshRendererLightMapTest();
virtual std::string title() const override; virtual std::string title() const override;
virtual std::string subtitle() const override; virtual std::string subtitle() const override;
void onTouchesMoved(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event* event); void onTouchesMoved(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event* event);
@ -152,12 +152,12 @@ private:
cocos2d::Camera* _camera; cocos2d::Camera* _camera;
}; };
class Sprite3DBasicToonShaderTest : public Sprite3DTestDemo class MeshRendererBasicToonShaderTest : public MeshRendererTestDemo
{ {
public: public:
CREATE_FUNC(Sprite3DBasicToonShaderTest); CREATE_FUNC(MeshRendererBasicToonShaderTest);
Sprite3DBasicToonShaderTest(); MeshRendererBasicToonShaderTest();
virtual ~Sprite3DBasicToonShaderTest(); virtual ~MeshRendererBasicToonShaderTest();
virtual std::string title() const override; virtual std::string title() const override;
virtual std::string subtitle() const override; virtual std::string subtitle() const override;
@ -169,62 +169,62 @@ protected:
#endif #endif
}; };
class Sprite3DHitTest : public Sprite3DTestDemo class MeshRendererHitTest : public MeshRendererTestDemo
{ {
public: public:
CREATE_FUNC(Sprite3DHitTest); CREATE_FUNC(MeshRendererHitTest);
Sprite3DHitTest(); MeshRendererHitTest();
virtual std::string title() const override; virtual std::string title() const override;
virtual std::string subtitle() const override; virtual std::string subtitle() const override;
}; };
class Sprite3DEffectTest : public Sprite3DTestDemo class MeshRendererEffectTest : public MeshRendererTestDemo
{ {
public: public:
CREATE_FUNC(Sprite3DEffectTest); CREATE_FUNC(MeshRendererEffectTest);
Sprite3DEffectTest(); MeshRendererEffectTest();
virtual ~Sprite3DEffectTest(); virtual ~MeshRendererEffectTest();
virtual std::string title() const override; virtual std::string title() const override;
virtual std::string subtitle() 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); void onTouchesEnded(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event* event);
protected: protected:
std::vector<cocos2d::Sprite3D*> _sprites; std::vector<cocos2d::MeshRenderer*> _meshes;
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
cocos2d::EventListenerCustom* _backToForegroundListener; cocos2d::EventListenerCustom* _backToForegroundListener;
#endif #endif
}; };
class AsyncLoadSprite3DTest : public Sprite3DTestDemo class AsyncLoadMeshRendererTest : public MeshRendererTestDemo
{ {
public: public:
CREATE_FUNC(AsyncLoadSprite3DTest); CREATE_FUNC(AsyncLoadMeshRendererTest);
AsyncLoadSprite3DTest(); AsyncLoadMeshRendererTest();
virtual ~AsyncLoadSprite3DTest(); virtual ~AsyncLoadMeshRendererTest();
virtual std::string title() const override; virtual std::string title() const override;
virtual std::string subtitle() 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: protected:
std::vector<std::string> _paths; // model paths to be loaded std::vector<std::string> _paths; // model paths to be loaded
}; };
class Sprite3DWithSkinTest : public Sprite3DTestDemo class MeshRendererWithSkinTest : public MeshRendererTestDemo
{ {
public: public:
CREATE_FUNC(Sprite3DWithSkinTest); CREATE_FUNC(MeshRendererWithSkinTest);
Sprite3DWithSkinTest(); MeshRendererWithSkinTest();
virtual std::string title() const override; virtual std::string title() const override;
virtual std::string subtitle() const override; virtual std::string subtitle() const override;
void addNewSpriteWithCoords(cocos2d::Vec2 p); void addNewMeshWithCoords(cocos2d::Vec2 p);
void switchAnimationQualityCallback(cocos2d::Ref* sender); void switchAnimationQualityCallback(cocos2d::Ref* sender);
void onTouchesEnded(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event* event); void onTouchesEnded(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event* event);
@ -232,33 +232,33 @@ public:
std::string getAnimationQualityMessage() const; std::string getAnimationQualityMessage() const;
private: private:
std::vector<cocos2d::Sprite3D*> _sprits; std::vector<cocos2d::MeshRenderer*> _meshes;
int _animateQuality; int _animateQuality;
cocos2d::MenuItemFont* _menuItem; cocos2d::MenuItemFont* _menuItem;
}; };
class Sprite3DWithSkinOutlineTest : public Sprite3DTestDemo class MeshRendererWithSkinOutlineTest : public MeshRendererTestDemo
{ {
public: public:
CREATE_FUNC(Sprite3DWithSkinOutlineTest); CREATE_FUNC(MeshRendererWithSkinOutlineTest);
Sprite3DWithSkinOutlineTest(); MeshRendererWithSkinOutlineTest();
virtual ~Sprite3DWithSkinOutlineTest(); virtual ~MeshRendererWithSkinOutlineTest();
virtual std::string title() const override; virtual std::string title() const override;
virtual std::string subtitle() 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); void onTouchesEnded(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event* event);
protected: protected:
std::vector<cocos2d::Sprite3D*> _sprites; std::vector<cocos2d::MeshRenderer*> _meshes;
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
cocos2d::EventListenerCustom* _backToForegroundListener; cocos2d::EventListenerCustom* _backToForegroundListener;
#endif #endif
}; };
class Animate3DTest : public Sprite3DTestDemo class Animate3DTest : public MeshRendererTestDemo
{ {
public: public:
CREATE_FUNC(Animate3DTest); CREATE_FUNC(Animate3DTest);
@ -272,7 +272,7 @@ public:
virtual void update(float dt) override; virtual void update(float dt) override;
protected: protected:
void addSprite3D(); void addMeshRenderer();
enum class State enum class State
{ {
@ -286,7 +286,7 @@ protected:
void renewCallBack(); void renewCallBack();
cocos2d::Sprite3D* _sprite; cocos2d::MeshRenderer* _mesh;
cocos2d::Action* _swim; cocos2d::Action* _swim;
cocos2d::Animate3D* _hurt; cocos2d::Animate3D* _hurt;
@ -298,7 +298,7 @@ protected:
cocos2d::MoveTo* _moveAction; cocos2d::MoveTo* _moveAction;
}; };
class AttachmentTest : public Sprite3DTestDemo class AttachmentTest : public MeshRendererTestDemo
{ {
public: public:
CREATE_FUNC(AttachmentTest); CREATE_FUNC(AttachmentTest);
@ -308,22 +308,22 @@ public:
void onTouchesEnded(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event* event); void onTouchesEnded(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event* event);
void addNewSpriteWithCoords(cocos2d::Vec2 p); void addNewMeshWithCoords(cocos2d::Vec2 p);
protected: protected:
bool _hasWeapon; bool _hasWeapon;
cocos2d::Sprite3D* _sprite; cocos2d::MeshRenderer* _mesh;
}; };
class Sprite3DReskinTest : public Sprite3DTestDemo class MeshRendererReskinTest : public MeshRendererTestDemo
{ {
public: public:
CREATE_FUNC(Sprite3DReskinTest); CREATE_FUNC(MeshRendererReskinTest);
Sprite3DReskinTest(); MeshRendererReskinTest();
virtual std::string title() const override; virtual std::string title() const override;
virtual std::string subtitle() const override; virtual std::string subtitle() const override;
void onTouchesEnded(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event* event); 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); void menuCallback_reSkin(cocos2d::Ref* sender);
@ -344,19 +344,19 @@ protected:
std::vector<std::string> _skins[(int)SkinType::MAX_TYPE]; // all skins std::vector<std::string> _skins[(int)SkinType::MAX_TYPE]; // all skins
int _curSkin[(int)SkinType::MAX_TYPE]; // current skin index int _curSkin[(int)SkinType::MAX_TYPE]; // current skin index
cocos2d::Sprite3D* _sprite; cocos2d::MeshRenderer* _mesh;
}; };
class Sprite3DWithOBBPerformanceTest : public Sprite3DTestDemo class MeshRendererWithOBBPerformanceTest : public MeshRendererTestDemo
{ {
public: public:
CREATE_FUNC(Sprite3DWithOBBPerformanceTest); CREATE_FUNC(MeshRendererWithOBBPerformanceTest);
Sprite3DWithOBBPerformanceTest(); MeshRendererWithOBBPerformanceTest();
virtual std::string title() const override; virtual std::string title() const override;
virtual std::string subtitle() const override; virtual std::string subtitle() const override;
virtual void update(float dt) override; virtual void update(float dt) override;
void addNewOBBWithCoords(cocos2d::Vec2 p); 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 onTouchesBegan(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event* event);
void onTouchesEnded(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); void onTouchesMoved(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event* event);
@ -366,7 +366,7 @@ public:
void delOBBWithCount(float value); void delOBBWithCount(float value);
protected: protected:
cocos2d::Sprite3D* _sprite; cocos2d::MeshRenderer* _mesh;
std::vector<cocos2d::OBB> _obb; std::vector<cocos2d::OBB> _obb;
cocos2d::DrawNode3D* _drawOBB; cocos2d::DrawNode3D* _drawOBB;
cocos2d::Label* _labelCubeCount; cocos2d::Label* _labelCubeCount;
@ -386,23 +386,23 @@ protected:
void calculateRayByLocationInView(cocos2d::Ray* ray, const cocos2d::Vec2& location); void calculateRayByLocationInView(cocos2d::Ray* ray, const cocos2d::Vec2& location);
}; };
class Sprite3DMirrorTest : public Sprite3DTestDemo class MeshRendererMirrorTest : public MeshRendererTestDemo
{ {
public: public:
CREATE_FUNC(Sprite3DMirrorTest); CREATE_FUNC(MeshRendererMirrorTest);
Sprite3DMirrorTest(); MeshRendererMirrorTest();
virtual std::string title() const override; virtual std::string title() const override;
virtual std::string subtitle() const override; virtual std::string subtitle() const override;
void addNewSpriteWithCoords(cocos2d::Vec2 p); void addNewMeshWithCoords(cocos2d::Vec2 p);
protected: protected:
bool _hasWeapon; bool _hasWeapon;
cocos2d::Sprite3D* _sprite; cocos2d::MeshRenderer* _mesh;
cocos2d::Sprite3D* _mirrorSprite; cocos2d::MeshRenderer* _mirrorMesh;
}; };
class QuaternionTest : public Sprite3DTestDemo class QuaternionTest : public MeshRendererTestDemo
{ {
public: public:
CREATE_FUNC(QuaternionTest); CREATE_FUNC(QuaternionTest);
@ -410,22 +410,22 @@ public:
virtual std::string title() const override; virtual std::string title() const override;
virtual std::string subtitle() const override; virtual std::string subtitle() const override;
void addNewSpriteWithCoords(cocos2d::Vec2 p); void addNewMeshWithCoords(cocos2d::Vec2 p);
virtual void update(float delta) override; virtual void update(float delta) override;
protected: protected:
cocos2d::Sprite3D* _sprite; cocos2d::MeshRenderer* _mesh;
float _arcSpeed; float _arcSpeed;
float _radius; float _radius;
float _accAngle; float _accAngle;
}; };
// 3d + 2d use case // 3d + 2d use case
class UseCaseSprite3D : public Sprite3DTestDemo class UseCaseMeshRenderer : public MeshRendererTestDemo
{ {
public: public:
CREATE_FUNC(UseCaseSprite3D); CREATE_FUNC(UseCaseMeshRenderer);
UseCaseSprite3D(); UseCaseMeshRenderer();
virtual std::string title() const override; virtual std::string title() const override;
virtual std::string subtitle() 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 // node animation test, cocos2d-x supports both skeletal animation and node animation
class NodeAnimationTest : public Sprite3DTestDemo class NodeAnimationTest : public MeshRendererTestDemo
{ {
public: public:
CREATE_FUNC(NodeAnimationTest); CREATE_FUNC(NodeAnimationTest);
@ -456,10 +456,10 @@ public:
virtual std::string title() const override; virtual std::string title() const override;
virtual std::string subtitle() const override; virtual std::string subtitle() const override;
void addNewSpriteWithCoords(cocos2d::Vec2 p); void addNewMeshWithCoords(cocos2d::Vec2 p);
protected: protected:
std::vector<cocos2d::Sprite3D*> _sprites; std::vector<cocos2d::MeshRenderer*> _meshes;
int _vectorIndex; int _vectorIndex;
}; };
@ -469,23 +469,23 @@ class TextureCube;
class Skybox; class Skybox;
} // namespace cocos2d } // namespace cocos2d
class Sprite3DCubeMapTest : public Sprite3DTestDemo class MeshRendererCubeMapTest : public MeshRendererTestDemo
{ {
public: public:
CREATE_FUNC(Sprite3DCubeMapTest); CREATE_FUNC(MeshRendererCubeMapTest);
Sprite3DCubeMapTest(); MeshRendererCubeMapTest();
~Sprite3DCubeMapTest(); ~MeshRendererCubeMapTest();
virtual std::string title() const override; virtual std::string title() const override;
virtual std::string subtitle() 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); void onTouchesMoved(const std::vector<cocos2d::Touch*>& touches, cocos2d::Event* event);
protected: protected:
cocos2d::TextureCube* _textureCube; cocos2d::TextureCube* _textureCube;
cocos2d::Skybox* _skyBox; cocos2d::Skybox* _skyBox;
cocos2d::Sprite3D* _teapot; cocos2d::MeshRenderer* _teapot;
cocos2d::Camera* _camera; cocos2d::Camera* _camera;
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
@ -494,7 +494,7 @@ protected:
}; };
/// issue 9767 setGLProgram /// issue 9767 setGLProgram
class Issue9767 : public Sprite3DTestDemo class Issue9767 : public MeshRendererTestDemo
{ {
enum class ShaderType enum class ShaderType
{ {
@ -513,21 +513,21 @@ public:
protected: protected:
ShaderType _shaderType; ShaderType _shaderType;
cocos2d::Sprite3D* _sprite; cocos2d::MeshRenderer* _mesh;
}; };
/// Clipping Sprite3D /// Clipping MeshRenderer
class Sprite3DClippingTest : public Sprite3DTestDemo class MeshRendererClippingTest : public MeshRendererTestDemo
{ {
public: public:
CREATE_FUNC(Sprite3DClippingTest); CREATE_FUNC(MeshRendererClippingTest);
Sprite3DClippingTest(); MeshRendererClippingTest();
~Sprite3DClippingTest(); ~MeshRendererClippingTest();
virtual std::string title() const override; virtual std::string title() const override;
virtual std::string subtitle() const override; virtual std::string subtitle() const override;
}; };
class Animate3DCallbackTest : public Sprite3DTestDemo class Animate3DCallbackTest : public MeshRendererTestDemo
{ {
public: public:
CREATE_FUNC(Animate3DCallbackTest); CREATE_FUNC(Animate3DCallbackTest);
@ -537,10 +537,10 @@ public:
virtual std::string subtitle() const override; virtual std::string subtitle() const override;
protected: protected:
cocos2d::Sprite3D* _sprite3d; cocos2d::MeshRenderer* _meshRenderer;
}; };
class CameraBackgroundClearTest : public Sprite3DTestDemo class CameraBackgroundClearTest : public MeshRendererTestDemo
{ {
public: public:
CREATE_FUNC(CameraBackgroundClearTest); CREATE_FUNC(CameraBackgroundClearTest);
@ -555,24 +555,24 @@ protected:
cocos2d::Label* _label; cocos2d::Label* _label;
}; };
class Sprite3DVertexColorTest : public Sprite3DTestDemo class MeshRendererVertexColorTest : public MeshRendererTestDemo
{ {
public: public:
CREATE_FUNC(Sprite3DVertexColorTest); CREATE_FUNC(MeshRendererVertexColorTest);
Sprite3DVertexColorTest(); MeshRendererVertexColorTest();
virtual std::string title() const override; virtual std::string title() const override;
virtual std::string subtitle() const override; virtual std::string subtitle() const override;
virtual ~Sprite3DVertexColorTest(); virtual ~MeshRendererVertexColorTest();
protected: protected:
cocos2d::Sprite3D* _sprite; cocos2d::MeshRenderer* _mesh;
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
cocos2d::EventListenerCustom* _backToForegroundListener; cocos2d::EventListenerCustom* _backToForegroundListener;
#endif #endif
}; };
class MotionStreak3DTest : public Sprite3DTestDemo class MotionStreak3DTest : public MeshRendererTestDemo
{ {
public: public:
CREATE_FUNC(MotionStreak3DTest); CREATE_FUNC(MotionStreak3DTest);
@ -582,27 +582,27 @@ public:
virtual void update(float delta) override; virtual void update(float delta) override;
protected: protected:
cocos2d::Sprite3D* _sprite; cocos2d::MeshRenderer* _mesh;
cocos2d::MotionStreak3D* _streak; cocos2d::MotionStreak3D* _streak;
}; };
class Sprite3DNormalMappingTest : public Sprite3DTestDemo class MeshRendererNormalMappingTest : public MeshRendererTestDemo
{ {
public: public:
CREATE_FUNC(Sprite3DNormalMappingTest); CREATE_FUNC(MeshRendererNormalMappingTest);
Sprite3DNormalMappingTest(); MeshRendererNormalMappingTest();
virtual std::string title() const override; virtual std::string title() const override;
virtual std::string subtitle() const override; virtual std::string subtitle() const override;
virtual void update(float dt) override; virtual void update(float dt) override;
virtual ~Sprite3DNormalMappingTest(); virtual ~MeshRendererNormalMappingTest();
}; };
class Sprite3DPropertyTest : public Sprite3DTestDemo class MeshRendererPropertyTest : public MeshRendererTestDemo
{ {
public: public:
CREATE_FUNC(Sprite3DPropertyTest); CREATE_FUNC(MeshRendererPropertyTest);
Sprite3DPropertyTest(); MeshRendererPropertyTest();
virtual std::string title() const override; virtual std::string title() const override;
virtual std::string subtitle() const override; virtual std::string subtitle() const override;
virtual void update(float delta) override; virtual void update(float delta) override;
@ -611,15 +611,15 @@ public:
void removeUsedTexture(cocos2d::Ref* sender); void removeUsedTexture(cocos2d::Ref* sender);
void resetTexture(cocos2d::Ref* sender); void resetTexture(cocos2d::Ref* sender);
void refreshSpriteRender(); void refreshMeshRender();
protected: protected:
cocos2d::Sprite3D* _sprite; cocos2d::MeshRenderer* _mesh;
cocos2d::Texture2D* _meshTex; cocos2d::Texture2D* _meshTex;
std::string _texFile; std::string _texFile;
}; };
class Issue16155Test : public Sprite3DTestDemo class Issue16155Test : public MeshRendererTestDemo
{ {
public: public:
CREATE_FUNC(Issue16155Test); CREATE_FUNC(Issue16155Test);

View File

@ -146,10 +146,10 @@ void NavMeshBaseTestDemo::initScene()
rbDes.shape = Physics3DShape::createMesh(&trianglesList[0], (int)trianglesList.size() / 3); rbDes.shape = Physics3DShape::createMesh(&trianglesList[0], (int)trianglesList.size() / 3);
auto rigidBody = Physics3DRigidBody::create(&rbDes); auto rigidBody = Physics3DRigidBody::create(&rbDes);
auto component = Physics3DComponent::create(rigidBody); auto component = Physics3DComponent::create(rigidBody);
auto sprite = Sprite3D::create("NavMesh/scene.obj"); auto mesh = MeshRenderer::create("NavMesh/scene.obj");
sprite->addComponent(component); mesh->addComponent(component);
sprite->setCameraMask((unsigned short)CameraFlag::USER1); mesh->setCameraMask((unsigned short)CameraFlag::USER1);
this->addChild(sprite); this->addChild(mesh);
setPhysics3DDebugCamera(_camera); setPhysics3DDebugCamera(_camera);
auto navMesh = NavMesh::create("NavMesh/all_tiles_tilecache.bin", "NavMesh/geomset.txt"); 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) void NavMeshBaseTestDemo::createAgent(const Vec3& pos)
{ {
std::string filePath = "Sprite3DTest/girl.c3b"; std::string filePath = "MeshRendererTest/girl.c3b";
NavMeshAgentParam param; NavMeshAgentParam param;
param.radius = 2.0f; param.radius = 2.0f;
param.height = 8.0f; param.height = 8.0f;
param.maxSpeed = 8.0f; param.maxSpeed = 8.0f;
auto agent = NavMeshAgent::create(param); auto agent = NavMeshAgent::create(param);
auto agentNode = Sprite3D::create(filePath); auto agentNode = MeshRenderer::create(filePath);
agent->setOrientationRefAxes(Vec3(-1.0f, 0.0f, 1.0f)); agent->setOrientationRefAxes(Vec3(-1.0f, 0.0f, 1.0f));
AgentUserData* data = new AgentUserData{0.0f}; AgentUserData* data = new AgentUserData{0.0f};
agent->setUserData(data); agent->setUserData(data);
@ -201,7 +201,7 @@ void NavMeshBaseTestDemo::createAgent(const Vec3& pos)
void NavMeshBaseTestDemo::createObstacle(const Vec3& pos) void NavMeshBaseTestDemo::createObstacle(const Vec3& pos)
{ {
auto obstacle = NavMeshObstacle::create(2.0f, 8.0f); 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->setPosition3D(pos + Vec3(0.0f, -0.5f, 0.0f));
obstacleNode->setRotation3D(Vec3(-90.0f, 0.0f, 0.0f)); obstacleNode->setRotation3D(Vec3(-90.0f, 0.0f, 0.0f));
obstacleNode->setScale(0.3f); obstacleNode->setScale(0.3f);

View File

@ -48,7 +48,7 @@ Particle3DTests::Particle3DTests()
ADD_TEST_CASE(Particle3DCanOfWormsDemo); ADD_TEST_CASE(Particle3DCanOfWormsDemo);
ADD_TEST_CASE(Particle3DRibbonTrailDemo); ADD_TEST_CASE(Particle3DRibbonTrailDemo);
ADD_TEST_CASE(Particle3DWeaponTrailDemo); ADD_TEST_CASE(Particle3DWeaponTrailDemo);
ADD_TEST_CASE(Particle3DWithSprite3DDemo); ADD_TEST_CASE(Particle3DWithMeshRendererDemo);
} }
std::string Particle3DTestDemo::title() const std::string Particle3DTestDemo::title() const
@ -63,7 +63,7 @@ bool Particle3DTestDemo::init()
FileUtils::getInstance()->addSearchPath("Particle3D/materials"); FileUtils::getInstance()->addSearchPath("Particle3D/materials");
FileUtils::getInstance()->addSearchPath("Particle3D/scripts"); FileUtils::getInstance()->addSearchPath("Particle3D/scripts");
FileUtils::getInstance()->addSearchPath("Sprite3DTest"); FileUtils::getInstance()->addSearchPath("MeshRendererTest");
// FileUtils::getInstance()->addSearchPath("Particle3D/textures"); // FileUtils::getInstance()->addSearchPath("Particle3D/textures");
Size size = Director::getInstance()->getWinSize(); Size size = Director::getInstance()->getWinSize();
@ -427,18 +427,18 @@ bool Particle3DWeaponTrailDemo::init()
return true; 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()) if (!Particle3DTestDemo::init())
return false; return false;
std::string c3bfileName = "Sprite3DTest/orc.c3b"; std::string c3bfileName = "MeshRendererTest/orc.c3b";
auto sprite = Sprite3D::create(c3bfileName); auto sprite = MeshRenderer::create(c3bfileName);
this->addChild(sprite); this->addChild(sprite);
sprite->setPosition3D(Vec3(-20.0f, 0.0f, 0.0f)); sprite->setPosition3D(Vec3(-20.0f, 0.0f, 0.0f));
sprite->setRotation3D(Vec3(0, 180, 0)); sprite->setRotation3D(Vec3(0, 180, 0));

View File

@ -223,12 +223,12 @@ public:
virtual bool init() override; virtual bool init() override;
}; };
class Particle3DWithSprite3DDemo : public Particle3DTestDemo class Particle3DWithMeshRendererDemo : public Particle3DTestDemo
{ {
public: public:
CREATE_FUNC(Particle3DWithSprite3DDemo); CREATE_FUNC(Particle3DWithMeshRendererDemo);
Particle3DWithSprite3DDemo(){}; Particle3DWithMeshRendererDemo(){};
virtual ~Particle3DWithSprite3DDemo(){}; virtual ~Particle3DWithMeshRendererDemo(){};
virtual std::string subtitle() const override; virtual std::string subtitle() const override;

View File

@ -196,25 +196,25 @@ void Physics3DTestDemo::shootBox(const cocos2d::Vec3& des)
rbDes.originalTransform.translate(_camera->getPosition3D()); rbDes.originalTransform.translate(_camera->getPosition3D());
rbDes.mass = 1.f; rbDes.mass = 1.f;
rbDes.shape = Physics3DShape::createBox(Vec3(0.5f, 0.5f, 0.5f)); rbDes.shape = Physics3DShape::createBox(Vec3(0.5f, 0.5f, 0.5f));
auto sprite = PhysicsSprite3D::create("Sprite3DTest/box.c3t", &rbDes); auto mesh = PhysicsMeshRenderer::create("MeshRendererTest/box.c3t", &rbDes);
sprite->setTexture("Images/Icon.png"); mesh->setTexture("Images/Icon.png");
auto rigidBody = static_cast<Physics3DRigidBody*>(sprite->getPhysicsObj()); auto rigidBody = static_cast<Physics3DRigidBody*>(mesh->getPhysicsObj());
rigidBody->setLinearFactor(Vec3::ONE); rigidBody->setLinearFactor(Vec3::ONE);
rigidBody->setLinearVelocity(linearVel); rigidBody->setLinearVelocity(linearVel);
rigidBody->setAngularVelocity(Vec3::ZERO); rigidBody->setAngularVelocity(Vec3::ZERO);
rigidBody->setCcdMotionThreshold(0.5f); rigidBody->setCcdMotionThreshold(0.5f);
rigidBody->setCcdSweptSphereRadius(0.4f); rigidBody->setCcdSweptSphereRadius(0.4f);
this->addChild(sprite); this->addChild(mesh);
sprite->setPosition3D(_camera->getPosition3D()); mesh->setPosition3D(_camera->getPosition3D());
sprite->setScale(0.5f); mesh->setScale(0.5f);
sprite->syncNodeToPhysics(); mesh->syncNodeToPhysics();
// optimize, only sync node to physics // 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 std::string BasicPhysics3DDemo::subtitle() const
@ -232,8 +232,8 @@ bool BasicPhysics3DDemo::init()
rbDes.mass = 0.0f; rbDes.mass = 0.0f;
rbDes.shape = Physics3DShape::createBox(Vec3(60.0f, 1.0f, 60.0f)); rbDes.shape = Physics3DShape::createBox(Vec3(60.0f, 1.0f, 60.0f));
auto floor = PhysicsSprite3D::create("Sprite3DTest/box.c3t", &rbDes); auto floor = PhysicsMeshRenderer::create("MeshRendererTest/box.c3t", &rbDes);
floor->setTexture("Sprite3DTest/plane.png"); floor->setTexture("MeshRendererTest/plane.png");
floor->setScaleX(60); floor->setScaleX(60);
floor->setScaleZ(60); floor->setScaleZ(60);
this->addChild(floor); this->addChild(floor);
@ -242,7 +242,7 @@ bool BasicPhysics3DDemo::init()
// static object sync is not needed // static object sync is not needed
floor->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::NONE); floor->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::NONE);
// create several boxes using PhysicsSprite3D // create several boxes using PhysicsMeshRenderer
rbDes.mass = 1.f; rbDes.mass = 1.f;
rbDes.shape = Physics3DShape::createBox(Vec3(0.8f, 0.8f, 0.8f)); rbDes.shape = Physics3DShape::createBox(Vec3(0.8f, 0.8f, 0.8f));
float start_x = START_POS_X - ARRAY_SIZE_X / 2; 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 y = 5.0 + 1.0 * k + start_y;
float z = 1.0 * j + start_z; float z = 1.0 * j + start_z;
auto sprite = PhysicsSprite3D::create("Sprite3DTest/box.c3t", &rbDes); auto mesh = PhysicsMeshRenderer::create("MeshRendererTest/box.c3t", &rbDes);
sprite->setTexture("Images/CyanSquare.png"); mesh->setTexture("Images/CyanSquare.png");
sprite->setPosition3D(Vec3(x, y, z)); mesh->setPosition3D(Vec3(x, y, z));
sprite->syncNodeToPhysics(); mesh->syncNodeToPhysics();
sprite->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::PHYSICS_TO_NODE); mesh->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::PHYSICS_TO_NODE);
sprite->setCameraMask((unsigned short)CameraFlag::USER1); mesh->setCameraMask((unsigned short)CameraFlag::USER1);
sprite->setScale(0.8f); mesh->setScale(0.8f);
this->addChild(sprite); this->addChild(mesh);
} }
} }
} }
@ -295,8 +295,8 @@ bool Physics3DKinematicDemo::init()
Physics3DRigidBodyDes rbDes; Physics3DRigidBodyDes rbDes;
rbDes.mass = 0.0f; rbDes.mass = 0.0f;
rbDes.shape = Physics3DShape::createBox(Vec3(60.0f, 1.0f, 60.0f)); rbDes.shape = Physics3DShape::createBox(Vec3(60.0f, 1.0f, 60.0f));
auto floor = PhysicsSprite3D::create("Sprite3DTest/box.c3t", &rbDes); auto floor = PhysicsMeshRenderer::create("MeshRendererTest/box.c3t", &rbDes);
floor->setTexture("Sprite3DTest/plane.png"); floor->setTexture("MeshRendererTest/plane.png");
floor->setScaleX(60); floor->setScaleX(60);
floor->setScaleZ(60); floor->setScaleZ(60);
floor->setPosition3D(Vec3(0.f, -1.f, 0.f)); 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.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)); rbDes.shape = Physics3DShape::createBox(Vec3(2.0f, 2.0f, 2.0f));
auto sprite = PhysicsSprite3D::create("Sprite3DTest/box.c3t", &rbDes); auto mesh = PhysicsMeshRenderer::create("MeshRendererTest/box.c3t", &rbDes);
sprite->setTexture("Images/CyanSquare.png"); mesh->setTexture("Images/CyanSquare.png");
sprite->setCameraMask((unsigned short)CameraFlag::USER1); mesh->setCameraMask((unsigned short)CameraFlag::USER1);
auto rigidBody = static_cast<Physics3DRigidBody*>(sprite->getPhysicsObj()); auto rigidBody = static_cast<Physics3DRigidBody*>(mesh->getPhysicsObj());
rigidBody->setKinematic(true); rigidBody->setKinematic(true);
this->addChild(sprite); this->addChild(mesh);
sprite->setScale(2.0f); mesh->setScale(2.0f);
sprite->setPosition3D(Vec3(-15.0f, 0.0f, 15.0f - 15.0f * i)); 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)); 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 // create Dynamic
@ -347,15 +347,15 @@ bool Physics3DKinematicDemo::init()
rbDes.originalTransform.setIdentity(); rbDes.originalTransform.setIdentity();
rbDes.originalTransform.translate(x, y, z); rbDes.originalTransform.translate(x, y, z);
auto sprite = PhysicsSprite3D::create("Sprite3DTest/sphere.c3b", &rbDes); auto mesh = PhysicsMeshRenderer::create("MeshRendererTest/sphere.c3b", &rbDes);
sprite->setTexture("Sprite3DTest/plane.png"); mesh->setTexture("MeshRendererTest/plane.png");
sprite->setCameraMask((unsigned short)CameraFlag::USER1); mesh->setCameraMask((unsigned short)CameraFlag::USER1);
sprite->setScale(1.0f / sprite->getContentSize().width); mesh->setScale(1.0f / mesh->getContentSize().width);
this->addChild(sprite); this->addChild(mesh);
sprite->setPosition3D(Vec3(x, y, z)); mesh->setPosition3D(Vec3(x, y, z));
sprite->syncNodeToPhysics(); 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()) if (!Physics3DTestDemo::init())
return false; return false;
// PhysicsSprite3D = Sprite3D + Physics3DComponent // PhysicsMeshRenderer = MeshRenderer + Physics3DComponent
Physics3DRigidBodyDes rbDes; Physics3DRigidBodyDes rbDes;
rbDes.disableSleep = true; rbDes.disableSleep = true;
// create box // create box
auto sprite = Sprite3D::create("Sprite3DTest/orc.c3b"); auto mesh = MeshRenderer::create("MeshRendererTest/orc.c3b");
rbDes.mass = 10.f; rbDes.mass = 10.f;
rbDes.shape = Physics3DShape::createBox(Vec3(5.0f, 5.0f, 5.0f)); rbDes.shape = Physics3DShape::createBox(Vec3(5.0f, 5.0f, 5.0f));
auto rigidBody = Physics3DRigidBody::create(&rbDes); 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); 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); auto component = Physics3DComponent::create(rigidBody, Vec3(0.f, -3.f, 0.f), quat);
sprite->addComponent(component); mesh->addComponent(component);
addChild(sprite); addChild(mesh);
sprite->setCameraMask((unsigned short)CameraFlag::USER1); mesh->setCameraMask((unsigned short)CameraFlag::USER1);
sprite->setScale(0.4f); mesh->setScale(0.4f);
sprite->setPosition3D(Vec3(-20.f, 5.f, 0.f)); mesh->setPosition3D(Vec3(-20.f, 5.f, 0.f));
// sync node position to physics // sync node position to physics
component->syncNodeToPhysics(); component->syncNodeToPhysics();
// physics controlled, we will not set position for it, so we can skip sync node position to physics // 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)); rbDes.shape = Physics3DShape::createBox(Vec3(8.0f, 8.0f, 1.f));
rigidBody = Physics3DRigidBody::create(&rbDes); rigidBody = Physics3DRigidBody::create(&rbDes);
component = Physics3DComponent::create(rigidBody); component = Physics3DComponent::create(rigidBody);
sprite = Sprite3D::create("Sprite3DTest/box.c3t"); mesh = MeshRenderer::create("MeshRendererTest/box.c3t");
sprite->setTexture("Sprite3DTest/plane.png"); mesh->setTexture("MeshRendererTest/plane.png");
sprite->setScaleX(8.f); mesh->setScaleX(8.f);
sprite->setScaleY(8.f); mesh->setScaleY(8.f);
sprite->setPosition3D(Vec3(5.f, 0.f, 0.f)); mesh->setPosition3D(Vec3(5.f, 0.f, 0.f));
sprite->addComponent(component); mesh->addComponent(component);
sprite->setCameraMask((unsigned short)CameraFlag::USER1); mesh->setCameraMask((unsigned short)CameraFlag::USER1);
this->addChild(sprite); this->addChild(mesh);
component->syncNodeToPhysics(); component->syncNodeToPhysics();
rigidBody->setAngularVelocity(Vec3(0, 3, 0)); rigidBody->setAngularVelocity(Vec3(0, 3, 0));
constraint = Physics3DHingeConstraint::create(rigidBody, Vec3(4.f, 4.f, 0.5f), Vec3(0.f, 1.f, 0.f)); 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)); rbDes.shape = Physics3DShape::createBox(Vec3(3.0f, 2.0f, 3.f));
rigidBody = Physics3DRigidBody::create(&rbDes); rigidBody = Physics3DRigidBody::create(&rbDes);
component = Physics3DComponent::create(rigidBody); component = Physics3DComponent::create(rigidBody);
sprite = Sprite3D::create("Sprite3DTest/box.c3t"); mesh = MeshRenderer::create("MeshRendererTest/box.c3t");
sprite->setTexture("Sprite3DTest/plane.png"); mesh->setTexture("MeshRendererTest/plane.png");
sprite->setScaleX(3.f); mesh->setScaleX(3.f);
sprite->setScaleZ(3.f); mesh->setScaleZ(3.f);
sprite->setPosition3D(Vec3(30.f, 15.f, 0.f)); mesh->setPosition3D(Vec3(30.f, 15.f, 0.f));
sprite->addComponent(component); mesh->addComponent(component);
sprite->setCameraMask((unsigned short)CameraFlag::USER1); mesh->setCameraMask((unsigned short)CameraFlag::USER1);
this->addChild(sprite); this->addChild(mesh);
component->syncNodeToPhysics(); component->syncNodeToPhysics();
rigidBody->setLinearVelocity(Vec3(0, 3, 0)); rigidBody->setLinearVelocity(Vec3(0, 3, 0));
@ -436,13 +436,13 @@ bool Physics3DConstraintDemo::init()
rbDes.shape = Physics3DShape::createBox(Vec3(3.0f, 3.0f, 3.f)); rbDes.shape = Physics3DShape::createBox(Vec3(3.0f, 3.0f, 3.f));
auto rigidBodyB = Physics3DRigidBody::create(&rbDes); auto rigidBodyB = Physics3DRigidBody::create(&rbDes);
component = Physics3DComponent::create(rigidBodyB); component = Physics3DComponent::create(rigidBodyB);
sprite = Sprite3D::create("Sprite3DTest/box.c3t"); mesh = MeshRenderer::create("MeshRendererTest/box.c3t");
sprite->setTexture("Sprite3DTest/plane.png"); mesh->setTexture("MeshRendererTest/plane.png");
sprite->setScale(3.f); mesh->setScale(3.f);
sprite->setPosition3D(Vec3(30.f, 5.f, 0.f)); mesh->setPosition3D(Vec3(30.f, 5.f, 0.f));
sprite->addComponent(component); mesh->addComponent(component);
sprite->setCameraMask((unsigned short)CameraFlag::USER1); mesh->setCameraMask((unsigned short)CameraFlag::USER1);
this->addChild(sprite); this->addChild(mesh);
component->syncNodeToPhysics(); component->syncNodeToPhysics();
Mat4 frameInA, frameInB; Mat4 frameInA, frameInB;
@ -460,13 +460,13 @@ bool Physics3DConstraintDemo::init()
rbDes.shape = Physics3DShape::createBox(Vec3(3.f, 3.f, 3.f)); rbDes.shape = Physics3DShape::createBox(Vec3(3.f, 3.f, 3.f));
rigidBody = Physics3DRigidBody::create(&rbDes); rigidBody = Physics3DRigidBody::create(&rbDes);
component = Physics3DComponent::create(rigidBody); component = Physics3DComponent::create(rigidBody);
sprite = Sprite3D::create("Sprite3DTest/box.c3t"); mesh = MeshRenderer::create("MeshRendererTest/box.c3t");
sprite->setTexture("Sprite3DTest/plane.png"); mesh->setTexture("MeshRendererTest/plane.png");
sprite->setScale(3.f); mesh->setScale(3.f);
sprite->setPosition3D(Vec3(-10.f, 5.f, 0.f)); mesh->setPosition3D(Vec3(-10.f, 5.f, 0.f));
sprite->addComponent(component); mesh->addComponent(component);
sprite->setCameraMask((unsigned short)CameraFlag::USER1); mesh->setCameraMask((unsigned short)CameraFlag::USER1);
this->addChild(sprite); this->addChild(mesh);
component->syncNodeToPhysics(); component->syncNodeToPhysics();
Mat4::createRotationZ(CC_DEGREES_TO_RADIANS(90), &frameInA); 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)); rbDes.shape = Physics3DShape::createBox(Vec3(3.0f, 3.0f, 3.f));
rigidBody = Physics3DRigidBody::create(&rbDes); rigidBody = Physics3DRigidBody::create(&rbDes);
component = Physics3DComponent::create(rigidBody); component = Physics3DComponent::create(rigidBody);
sprite = Sprite3D::create("Sprite3DTest/box.c3t"); mesh = MeshRenderer::create("MeshRendererTest/box.c3t");
sprite->setTexture("Sprite3DTest/plane.png"); mesh->setTexture("MeshRendererTest/plane.png");
sprite->setScale(3.f); mesh->setScale(3.f);
sprite->setPosition3D(Vec3(30.f, -5.f, 0.f)); mesh->setPosition3D(Vec3(30.f, -5.f, 0.f));
sprite->addComponent(component); mesh->addComponent(component);
sprite->setCameraMask((unsigned short)CameraFlag::USER1); mesh->setCameraMask((unsigned short)CameraFlag::USER1);
this->addChild(sprite); this->addChild(mesh);
component->syncNodeToPhysics(); component->syncNodeToPhysics();
frameInA.setIdentity(); frameInA.setIdentity();
constraint = Physics3D6DofConstraint::create(rigidBody, frameInA, false); constraint = Physics3D6DofConstraint::create(rigidBody, frameInA, false);
@ -617,30 +617,30 @@ bool Physics3DTerrainDemo::init()
float y = 5.0 + 1.0 * k + start_y; float y = 5.0 + 1.0 * k + start_y;
float z = 1.0 * j + start_z; float z = 1.0 * j + start_z;
auto sprite = PhysicsSprite3D::create("Sprite3DTest/sphere.c3b", &rbDes); auto mesh = PhysicsMeshRenderer::create("MeshRendererTest/sphere.c3b", &rbDes);
sprite->setTexture("Sprite3DTest/plane.png"); mesh->setTexture("MeshRendererTest/plane.png");
sprite->setCameraMask((unsigned short)CameraFlag::USER1); mesh->setCameraMask((unsigned short)CameraFlag::USER1);
sprite->setScale(1.0f / sprite->getContentSize().width); mesh->setScale(1.0f / mesh->getContentSize().width);
sprite->setPosition3D(Vec3(x, y, z)); mesh->setPosition3D(Vec3(x, y, z));
this->addChild(sprite); this->addChild(mesh);
sprite->syncNodeToPhysics(); mesh->syncNodeToPhysics();
sprite->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::PHYSICS_TO_NODE); mesh->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::PHYSICS_TO_NODE);
} }
} }
} }
// create mesh // 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); colliderDes.shape = Physics3DShape::createMesh(&trianglesList[0], (int)trianglesList.size() / 3);
auto sprite = PhysicsSprite3D::createWithCollider("Sprite3DTest/boss.c3b", &colliderDes); auto mesh = PhysicsMeshRenderer::createWithCollider("MeshRendererTest/boss.c3b", &colliderDes);
sprite->setRotation3D(Vec3(-90.0f, 0.0f, 0.0f)); mesh->setRotation3D(Vec3(-90.0f, 0.0f, 0.0f));
sprite->setPosition3D(Vec3(0.0f, 15.0f, 0.0f)); mesh->setPosition3D(Vec3(0.0f, 15.0f, 0.0f));
sprite->setCameraMask(2); mesh->setCameraMask(2);
this->addChild(sprite); this->addChild(mesh);
sprite->syncNodeToPhysics(); mesh->syncNodeToPhysics();
sprite->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::NONE); mesh->setSyncFlag(Physics3DComponent::PhysicsSyncFlag::NONE);
std::vector<std::pair<Physics3DShape*, Mat4>> shapeList; std::vector<std::pair<Physics3DShape*, Mat4>> shapeList;
{ {
@ -668,13 +668,13 @@ bool Physics3DTerrainDemo::init()
rbDes.shape = Physics3DShape::createCompoundShape(shapeList); rbDes.shape = Physics3DShape::createCompoundShape(shapeList);
auto rigidBody = Physics3DRigidBody::create(&rbDes); auto rigidBody = Physics3DRigidBody::create(&rbDes);
component = Physics3DComponent::create(rigidBody); component = Physics3DComponent::create(rigidBody);
auto sprite = Sprite3D::create("Sprite3DTest/orc.c3b"); auto mesh = MeshRenderer::create("MeshRendererTest/orc.c3b");
sprite->addComponent(component); mesh->addComponent(component);
sprite->setRotation3D(Vec3(0.0f, 180.0f, 0.0f)); mesh->setRotation3D(Vec3(0.0f, 180.0f, 0.0f));
sprite->setPosition3D(Vec3(-5.0f, 20.0f, 0.0f)); mesh->setPosition3D(Vec3(-5.0f, 20.0f, 0.0f));
sprite->setScale(0.4f); mesh->setScale(0.4f);
sprite->setCameraMask(2); mesh->setCameraMask(2);
this->addChild(sprite); this->addChild(mesh);
} }
physicsScene->setPhysics3DDebugCamera(_camera); physicsScene->setPhysics3DDebugCamera(_camera);
@ -700,7 +700,7 @@ bool Physics3DCollisionCallbackDemo::init()
Physics3DRigidBodyDes rbDes; Physics3DRigidBodyDes rbDes;
float scale = 2.0f; 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) for (auto& it : trianglesList)
{ {
it *= scale; it *= scale;
@ -710,12 +710,12 @@ bool Physics3DCollisionCallbackDemo::init()
rbDes.shape = Physics3DShape::createMesh(&trianglesList[0], (int)trianglesList.size() / 3); rbDes.shape = Physics3DShape::createMesh(&trianglesList[0], (int)trianglesList.size() / 3);
auto rigidBody = Physics3DRigidBody::create(&rbDes); auto rigidBody = Physics3DRigidBody::create(&rbDes);
auto component = Physics3DComponent::create(rigidBody); auto component = Physics3DComponent::create(rigidBody);
auto sprite = Sprite3D::create("Sprite3DTest/boss.c3b"); auto mesh = MeshRenderer::create("MeshRendererTest/boss.c3b");
sprite->addComponent(component); mesh->addComponent(component);
sprite->setRotation3D(Vec3(-90.0f, 0.0f, 0.0f)); mesh->setRotation3D(Vec3(-90.0f, 0.0f, 0.0f));
sprite->setScale(scale); mesh->setScale(scale);
sprite->setCameraMask((unsigned short)CameraFlag::USER1); mesh->setCameraMask((unsigned short)CameraFlag::USER1);
this->addChild(sprite); this->addChild(mesh);
// preload // preload
// //
rigidBody->setCollisionCallback([=](const Physics3DCollisionInfo& ci) { rigidBody->setCollisionCallback([=](const Physics3DCollisionInfo& ci) {
@ -766,15 +766,15 @@ bool Physics3DColliderDemo::init()
auto playerBody = Physics3DRigidBody::create(&rbDes); auto playerBody = Physics3DRigidBody::create(&rbDes);
auto component = Physics3DComponent::create(playerBody); auto component = Physics3DComponent::create(playerBody);
playerBody->setKinematic(true); playerBody->setKinematic(true);
auto sprite = Sprite3D::create("Sprite3DTest/box.c3t"); auto mesh = MeshRenderer::create("MeshRendererTest/box.c3t");
sprite->setTexture("Sprite3DTest/plane.png"); mesh->setTexture("MeshRendererTest/plane.png");
sprite->setScale(3.f); mesh->setScale(3.f);
sprite->setPosition3D(Vec3(0.0f, 0.f, 30.f)); mesh->setPosition3D(Vec3(0.0f, 0.f, 30.f));
sprite->addComponent(component); mesh->addComponent(component);
sprite->setCameraMask((unsigned short)CameraFlag::USER1); mesh->setCameraMask((unsigned short)CameraFlag::USER1);
auto moveby = MoveBy::create(5.0f, Vec3(0.0f, 0.0f, -60.0f)); auto moveby = MoveBy::create(5.0f, Vec3(0.0f, 0.0f, -60.0f));
sprite->runAction(RepeatForever::create(Sequence::create(moveby, moveby->reverse(), nullptr))); mesh->runAction(RepeatForever::create(Sequence::create(moveby, moveby->reverse(), nullptr)));
this->addChild(sprite); this->addChild(mesh);
{ {
Physics3DColliderDes colliderDes; Physics3DColliderDes colliderDes;
@ -793,8 +793,8 @@ bool Physics3DColliderDemo::init()
auto rigidBody = Physics3DRigidBody::create(&rbDes); auto rigidBody = Physics3DRigidBody::create(&rbDes);
component = Physics3DComponent::create(rigidBody); component = Physics3DComponent::create(rigidBody);
rigidBody->setKinematic(true); rigidBody->setKinematic(true);
auto doorLeft = Sprite3D::create("Sprite3DTest/box.c3t"); auto doorLeft = MeshRenderer::create("MeshRendererTest/box.c3t");
doorLeft->setTexture("Sprite3DTest/plane.png"); doorLeft->setTexture("MeshRendererTest/plane.png");
doorLeft->setScaleX(10.0f); doorLeft->setScaleX(10.0f);
doorLeft->setScaleY(10.0f); doorLeft->setScaleY(10.0f);
doorLeft->setScaleZ(1.0f); doorLeft->setScaleZ(1.0f);
@ -808,8 +808,8 @@ bool Physics3DColliderDemo::init()
rigidBody = Physics3DRigidBody::create(&rbDes); rigidBody = Physics3DRigidBody::create(&rbDes);
component = Physics3DComponent::create(rigidBody); component = Physics3DComponent::create(rigidBody);
rigidBody->setKinematic(true); rigidBody->setKinematic(true);
auto doorRight = Sprite3D::create("Sprite3DTest/box.c3t"); auto doorRight = MeshRenderer::create("MeshRendererTest/box.c3t");
doorRight->setTexture("Sprite3DTest/plane.png"); doorRight->setTexture("MeshRendererTest/plane.png");
doorRight->setScaleX(10.0f); doorRight->setScaleX(10.0f);
doorRight->setScaleY(10.0f); doorRight->setScaleY(10.0f);
doorRight->setScaleZ(1.0f); doorRight->setScaleZ(1.0f);

View File

@ -37,7 +37,6 @@ RenderTextureTests::RenderTextureTests()
ADD_TEST_CASE(SpriteRenderTextureBug); ADD_TEST_CASE(SpriteRenderTextureBug);
ADD_TEST_CASE(RenderTexturePartTest); ADD_TEST_CASE(RenderTexturePartTest);
ADD_TEST_CASE(Issue16113Test); 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"; 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";
}

View File

@ -182,25 +182,4 @@ public:
virtual std::string subtitle() const override; 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 #endif

View File

@ -136,7 +136,7 @@ TerrainWalkThru::TerrainWalkThru()
_terrain->setSkirtHeightRatio(3); _terrain->setSkirtHeightRatio(3);
_terrain->setLODDistance(64, 128, 192); _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->setCameraMask(2);
_player->setScale(0.08f); _player->setScale(0.08f);
_player->setPositionY(_terrain->getHeight(_player->getPositionX(), _player->getPositionZ()) + PLAYER_HEIGHT); _player->setPositionY(_terrain->getHeight(_player->getPositionX(), _player->getPositionZ()) + PLAYER_HEIGHT);
@ -154,7 +154,7 @@ TerrainWalkThru::TerrainWalkThru()
billboard->setCameraMask((unsigned short)CameraFlag::USER1); billboard->setCameraMask((unsigned short)CameraFlag::USER1);
_player->addChild(billboard); _player->addChild(billboard);
auto animation = Animation3D::create("Sprite3DTest/girl.c3b", "Take 001"); auto animation = Animation3D::create("MeshRendererTest/girl.c3b", "Take 001");
if (animation) if (animation)
{ {
auto animate = Animate3D::create(animation); auto animate = Animate3D::create(animation);
@ -210,7 +210,7 @@ bool Player::isDone() const
void Player::update(float dt) void Player::update(float dt)
{ {
auto player = (Sprite3D*)this; auto player = (MeshRenderer*)this;
switch (_playerState) switch (_playerState)
{ {
case PLAYER_STATE_IDLE: case PLAYER_STATE_IDLE:
@ -301,7 +301,7 @@ void Player::backward()
void Player::updateState() void Player::updateState()
{ {
auto player = (Sprite3D*)this; auto player = (MeshRenderer*)this;
switch (_playerState) switch (_playerState)
{ {
case PLAYER_STATE_FORWARD: case PLAYER_STATE_FORWARD:
@ -323,18 +323,18 @@ void Player::updateState()
Player* Player::create(const char* file, Camera* cam, Terrain* terrain) Player* Player::create(const char* file, Camera* cam, Terrain* terrain)
{ {
// //
auto sprite = new Player(); auto player = new Player();
if (sprite->initWithFile(file)) if (player->initWithFile(file))
{ {
sprite->_headingAngle = 0; player->_headingAngle = 0;
sprite->_playerState = PLAYER_STATE_IDLE; player->_playerState = PLAYER_STATE_IDLE;
sprite->_cam = cam; player->_cam = cam;
sprite->_terrain = terrain; player->_terrain = terrain;
sprite->autorelease(); player->autorelease();
sprite->scheduleUpdate(); player->scheduleUpdate();
return sprite; return player;
} }
CC_SAFE_DELETE(sprite); CC_SAFE_DELETE(player);
return nullptr; return nullptr;
} }

View File

@ -24,12 +24,12 @@
#ifndef TERRAIN_TESH_H #ifndef TERRAIN_TESH_H
# include "../BaseTest.h" #include "../BaseTest.h"
# include "3d/CCSprite3D.h" #include "3d/CCMeshRenderer.h"
# include "3d/CCTerrain.h" #include "3d/CCTerrain.h"
# include "2d/CCCamera.h" #include "2d/CCCamera.h"
# include "2d/CCAction.h" #include "2d/CCAction.h"
DEFINE_TEST_SUITE(TerrainTests); DEFINE_TEST_SUITE(TerrainTests);
@ -59,7 +59,7 @@ protected:
# define PLAYER_STATE_FORWARD 3 # define PLAYER_STATE_FORWARD 3
# define PLAYER_STATE_BACKWARD 4 # define PLAYER_STATE_BACKWARD 4
class Player : public cocos2d::Sprite3D class Player : public cocos2d::MeshRenderer
{ {
public: public:
static Player* create(const char* file, cocos2d::Camera* cam, cocos2d::Terrain* terrain); static Player* create(const char* file, cocos2d::Camera* cam, cocos2d::Terrain* terrain);

View File

@ -102,7 +102,7 @@ public:
addTest("Node: Scene", []() { return new SceneTests(); }); addTest("Node: Scene", []() { return new SceneTests(); });
addTest("Node: Spine", []() { return new SpineTests(); }); addTest("Node: Spine", []() { return new SpineTests(); });
addTest("Node: Sprite", []() { return new SpriteTests(); }); 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: SpritePolygon", []() { return new SpritePolygonTest(); });
addTest("Node: Terrain", []() { return new TerrainTests(); }); addTest("Node: Terrain", []() { return new TerrainTests(); });
addTest("Node: FastTileMap", []() { return new FastTileMapTests(); }); addTest("Node: FastTileMap", []() { return new FastTileMapTests(); });

View File

@ -101,7 +101,7 @@
#include "ShaderTest/ShaderTest.h" #include "ShaderTest/ShaderTest.h"
#include "ShaderTest/ShaderTest2.h" #include "ShaderTest/ShaderTest2.h"
#include "SpineTest/SpineTest.h" #include "SpineTest/SpineTest.h"
#include "Sprite3DTest/Sprite3DTest.h" #include "MeshRendererTest/MeshRendererTest.h"
#include "SpritePolygonTest/SpritePolygonTest.h" #include "SpritePolygonTest/SpritePolygonTest.h"
#include "SpriteTest/SpriteTest.h" #include "SpriteTest/SpriteTest.h"
#include "TerrainTest/TerrainTest.h" #include "TerrainTest/TerrainTest.h"