2019-11-23 20:27:39 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
|
|
|
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-10-01 16:24:52 +08:00
|
|
|
https://axmolengine.github.io/
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "base/CCRef.h"
|
|
|
|
#include "math/CCMath.h"
|
|
|
|
#include "extensions/Particle3D/CCParticle3DRender.h"
|
|
|
|
#include "renderer/CCRenderState.h"
|
|
|
|
#include "renderer/backend/Types.h"
|
|
|
|
#include "renderer/backend/Buffer.h"
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_BEGIN
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
// particle render for quad
|
|
|
|
struct PUParticle3D;
|
|
|
|
|
2022-07-16 10:43:05 +08:00
|
|
|
class AX_EX_DLL PURender : public Particle3DRender
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual void prepare(){};
|
|
|
|
virtual void unPrepare(){};
|
|
|
|
virtual void updateRender(PUParticle3D* particle, float deltaTime, bool firstParticle);
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
std::string_view getRenderType() const { return _renderType; };
|
|
|
|
void setRenderType(std::string_view observerType) { _renderType = observerType; };
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
virtual PURender* clone() = 0;
|
|
|
|
void copyAttributesTo(PURender* render);
|
|
|
|
|
|
|
|
public:
|
2021-12-25 10:04:45 +08:00
|
|
|
bool autoRotate; // Means that the objects to render automatically rotate if the node to which the particle system
|
2022-07-05 14:48:46 +08:00
|
|
|
// is attached to rotates.
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
std::string _renderType;
|
|
|
|
};
|
|
|
|
|
2022-07-16 10:43:05 +08:00
|
|
|
class AX_EX_DLL PUParticle3DEntityRender : public PURender
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
public:
|
2021-12-25 10:04:45 +08:00
|
|
|
void copyAttributesTo(PUParticle3DEntityRender* render);
|
|
|
|
virtual void reset() override;
|
2022-03-18 21:46:07 +08:00
|
|
|
PUParticle3DEntityRender();
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual ~PUParticle3DEntityRender();
|
|
|
|
|
|
|
|
protected:
|
2021-12-31 12:12:40 +08:00
|
|
|
bool initRender(std::string_view texFile);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
void onBeforeDraw();
|
|
|
|
|
|
|
|
void onAfterDraw();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
struct VertexInfo
|
|
|
|
{
|
|
|
|
Vec3 position;
|
|
|
|
Vec2 uv;
|
|
|
|
Vec4 color;
|
|
|
|
};
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
MeshCommand _meshCommand;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
RenderState::StateBlock _stateBlock;
|
|
|
|
Texture2D* _texture = nullptr;
|
|
|
|
backend::ProgramState* _programState = nullptr;
|
|
|
|
backend::Buffer* _indexBuffer = nullptr; // index buffer
|
|
|
|
backend::Buffer* _vertexBuffer = nullptr; // vertex buffer
|
|
|
|
|
|
|
|
std::vector<VertexInfo> _vertices;
|
2019-11-23 20:27:39 +08:00
|
|
|
std::vector<uint16_t> _indices;
|
|
|
|
|
|
|
|
std::string _texFile;
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
backend::UniformLocation _locColor;
|
|
|
|
backend::UniformLocation _locTexture;
|
|
|
|
backend::UniformLocation _locPMatrix;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
// renderer state cache variables
|
|
|
|
bool _rendererDepthTestEnabled = true;
|
|
|
|
backend::CompareFunction _rendererDepthCmpFunc = backend::CompareFunction::LESS;
|
|
|
|
backend::CullMode _rendererCullMode = backend::CullMode::BACK;
|
|
|
|
backend::Winding _rendererWinding = backend::Winding::COUNTER_CLOCK_WISE;
|
|
|
|
bool _rendererDepthWrite = false;
|
2019-11-23 20:27:39 +08:00
|
|
|
};
|
|
|
|
|
2022-07-16 10:43:05 +08:00
|
|
|
class AX_EX_DLL PUParticle3DQuadRender : public PUParticle3DEntityRender
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum Type
|
|
|
|
{
|
|
|
|
POINT,
|
|
|
|
ORIENTED_COMMON,
|
|
|
|
ORIENTED_SELF,
|
|
|
|
ORIENTED_SHAPE,
|
|
|
|
PERPENDICULAR_COMMON,
|
|
|
|
PERPENDICULAR_SELF,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum Origin
|
|
|
|
{
|
|
|
|
TOP_LEFT,
|
|
|
|
TOP_CENTER,
|
|
|
|
TOP_RIGHT,
|
|
|
|
CENTER_LEFT,
|
|
|
|
CENTER,
|
|
|
|
CENTER_RIGHT,
|
|
|
|
BOTTOM_LEFT,
|
|
|
|
BOTTOM_CENTER,
|
|
|
|
BOTTOM_RIGHT
|
|
|
|
};
|
|
|
|
|
|
|
|
enum RotateType
|
|
|
|
{
|
|
|
|
TEXTURE_COORDS,
|
|
|
|
VERTEX
|
|
|
|
};
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
static PUParticle3DQuadRender* create(std::string_view texFile = "");
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
void setType(Type type);
|
|
|
|
Type getType() const { return _type; }
|
|
|
|
void setOrigin(Origin origin) { _origin = origin; }
|
|
|
|
Origin getOrigin() const { return _origin; }
|
|
|
|
void setRotateType(RotateType type) { _rotateType = type; }
|
|
|
|
RotateType getRotateType() const { return _rotateType; }
|
2021-12-25 10:04:45 +08:00
|
|
|
void setCommonDirection(const Vec3& dir) { _commonDir = dir; }
|
2019-11-23 20:27:39 +08:00
|
|
|
const Vec3& getCommonDirection() const { return _commonDir; }
|
2021-12-25 10:04:45 +08:00
|
|
|
void setCommonUp(const Vec3& up) { _commonUp = up; }
|
2019-11-23 20:27:39 +08:00
|
|
|
const Vec3& getCommonUp() const { return _commonUp; }
|
|
|
|
|
|
|
|
unsigned short getTextureCoordsRows() const;
|
|
|
|
void setTextureCoordsRows(unsigned short textureCoordsRows);
|
|
|
|
unsigned short getTextureCoordsColumns() const;
|
|
|
|
void setTextureCoordsColumns(unsigned short textureCoordsColumns);
|
|
|
|
unsigned int getNumTextureCoords();
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
virtual void render(Renderer* renderer, const Mat4& transform, ParticleSystem3D* particleSystem) override;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
virtual PUParticle3DQuadRender* clone() override;
|
2021-12-25 10:04:45 +08:00
|
|
|
void copyAttributesTo(PUParticle3DQuadRender* render);
|
|
|
|
|
2022-03-18 21:46:07 +08:00
|
|
|
PUParticle3DQuadRender();
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual ~PUParticle3DQuadRender();
|
|
|
|
|
|
|
|
protected:
|
2021-12-25 10:04:45 +08:00
|
|
|
void getOriginOffset(int& offsetX, int& offsetY);
|
|
|
|
void determineUVCoords(PUParticle3D* particle);
|
|
|
|
void fillVertex(unsigned short index, const Vec3& pos, const Vec4& color, const Vec2& uv);
|
2019-11-23 20:27:39 +08:00
|
|
|
void fillTriangle(unsigned short index, unsigned short v0, unsigned short v1, unsigned short v2);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
Type _type;
|
|
|
|
Origin _origin;
|
|
|
|
RotateType _rotateType;
|
|
|
|
Vec3 _commonDir;
|
|
|
|
Vec3 _commonUp;
|
|
|
|
|
|
|
|
unsigned short _textureCoordsRows;
|
|
|
|
unsigned short _textureCoordsColumns;
|
|
|
|
float _textureCoordsRowStep;
|
|
|
|
float _textureCoordsColStep;
|
|
|
|
};
|
|
|
|
|
2022-07-06 12:21:13 +08:00
|
|
|
// particle render for MeshRenderer
|
2022-07-16 10:43:05 +08:00
|
|
|
class AX_EX_DLL PUParticle3DModelRender : public PURender
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
public:
|
2021-12-31 12:12:40 +08:00
|
|
|
static PUParticle3DModelRender* create(std::string_view modelFile, std::string_view texFile = "");
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
virtual void render(Renderer* renderer, const Mat4& transform, ParticleSystem3D* particleSystem) override;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
virtual PUParticle3DModelRender* clone() override;
|
2021-12-25 10:04:45 +08:00
|
|
|
void copyAttributesTo(PUParticle3DModelRender* render);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
virtual void reset() override;
|
2022-03-18 21:46:07 +08:00
|
|
|
PUParticle3DModelRender();
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual ~PUParticle3DModelRender();
|
|
|
|
|
|
|
|
protected:
|
2022-07-05 14:48:46 +08:00
|
|
|
std::vector<MeshRenderer*> _meshList;
|
2019-11-23 20:27:39 +08:00
|
|
|
std::string _modelFile;
|
|
|
|
std::string _texFile;
|
2022-07-05 14:48:46 +08:00
|
|
|
Vec3 _meshSize;
|
2019-11-23 20:27:39 +08:00
|
|
|
};
|
|
|
|
|
2022-07-16 10:43:05 +08:00
|
|
|
class AX_EX_DLL PUParticle3DBoxRender : public PUParticle3DEntityRender
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
public:
|
2021-12-31 12:12:40 +08:00
|
|
|
static PUParticle3DBoxRender* create(std::string_view texFile = "");
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
virtual void render(Renderer* renderer, const Mat4& transform, ParticleSystem3D* particleSystem) override;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
virtual PUParticle3DBoxRender* clone() override;
|
|
|
|
|
2022-03-18 21:46:07 +08:00
|
|
|
PUParticle3DBoxRender();
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual ~PUParticle3DBoxRender();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void reBuildIndices(unsigned short count);
|
|
|
|
};
|
|
|
|
|
2022-07-16 10:43:05 +08:00
|
|
|
class AX_EX_DLL PUSphereRender : public PUParticle3DEntityRender
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
public:
|
2021-12-31 12:12:40 +08:00
|
|
|
static PUSphereRender* create(std::string_view texFile = "");
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
virtual void render(Renderer* renderer, const Mat4& transform, ParticleSystem3D* particleSystem) override;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
virtual PUSphereRender* clone() override;
|
2021-12-25 10:04:45 +08:00
|
|
|
void copyAttributesTo(PUSphereRender* render);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2022-03-18 21:46:07 +08:00
|
|
|
PUSphereRender();
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual ~PUSphereRender();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void buildBuffers(unsigned short count);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
unsigned short _numberOfRings;
|
|
|
|
unsigned short _numberOfSegments;
|
|
|
|
std::vector<VertexInfo> _vertexTemplate;
|
|
|
|
};
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_END
|