summaryrefslogtreecommitdiff
path: root/Runtime/Graphics/ParticleSystem/Modules/ShapeModule.h
blob: 1f95d335f76dc34d680ba0f6e091eed6b6dd8cd6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#ifndef SHURIKENMODULESHAPE_H
#define SHURIKENMODULESHAPE_H

#include "Runtime/BaseClasses/BaseObject.h"
#include "ParticleSystemModule.h"
#include "Runtime/Math/Random/rand.h"
#include "Runtime/Utilities/LinkedList.h"

struct MeshTriangleData
{
	float area;
	UInt16 indices[3];
};

struct ParticleSystemEmitterMeshVertex
{
	Vector3f position;
	Vector3f normal;
	ColorRGBA32 color;
};

class Mesh;

class ShapeModule : public ParticleSystemModule
{
public:
	DECLARE_MODULE (ShapeModule)
	ShapeModule ();

	enum MeshPlacementMode { kVertex, kEdge, kTriangle, kModeMax };
	enum { kSphere, kSphereShell, kHemiSphere, kHemiSphereShell, kCone, kBox, kMesh, kConeShell, kConeVolume, kConeVolumeShell, kMax };

	void AwakeFromLoad (ParticleSystem* system, const ParticleSystemReadOnlyState& roState);
	void ResetSeed(const ParticleSystemReadOnlyState& roState);
	void DidModifyMeshData ();
	void DidDeleteMesh (ParticleSystem* system);
	
	PPtr<Mesh> GetMeshEmitterShape () { return m_Mesh; }
	
	void Start (const ParticleSystemReadOnlyState& roState, const ParticleSystemState& state, ParticleSystemParticles& ps, const Matrix4x4f& matrix, size_t fromIndex, float t);
	void CalculateProceduralBounds(MinMaxAABB& bounds, const Vector3f& emitterScale, Vector2f minMaxBounds) const;
	void CheckConsistency ();

	inline void SetShapeType(int type) { m_Type = type; };
	inline void SetRadius(float radius) { m_Radius = radius; };

	template<class TransferFunction>
	void Transfer (TransferFunction& transfer);
	
private:
	Rand& GetRandom();
	
	int m_Type;

	// Primitive stuff
	float m_Radius;
	float m_Angle;
	float m_Length;
	float m_BoxX;
	float m_BoxY;
	float m_BoxZ;
	
	// Mesh stuff
	int m_PlacementMode;
	PPtr<Mesh>	m_Mesh;
	Mesh*	m_CachedMesh;
	dynamic_array<ParticleSystemEmitterMeshVertex> m_CachedVertexData;
	dynamic_array<MeshTriangleData> m_CachedTriangleData;
	float m_CachedTotalTriangleArea;	
	ListNode<Object> m_MeshNode;
	
	bool m_RandomDirection;
	Rand m_Random; 
#if UNITY_EDITOR
public:
	Rand m_EditorRandom;
#endif
};

#endif // SHURIKENMODULESHAPE_H