CSEngine
Loading...
Searching...
No Matches
CSE::MeshSurface Class Reference
Inheritance diagram for CSE::MeshSurface:
CSE::SISurface CSE::SResource CSE::SObject

Public Member Functions

 MeshSurface (int sizeVert, float *vertices, float *normals)
 
 MeshSurface (int sizeVert, float *vertices, float *normals, float *texCoords)
 
int GetVertexCount () const override
 
int GetLineIndexCount () const override
 
int GetTriangleIndexCount () const override
 
void GenerateVertices (std::vector< float > &vertices, unsigned char flags) const override
 
void GenerateLineIndices (std::vector< unsigned short > &indices) const override
 
void GenerateTriangleIndices (std::vector< unsigned short > &indices) const override
 
bool HasJoint () const
 
void Exterminate () override
 
void Destroy () override
 
bool MakeVertices (int sizeVert, float *vertices, float *normals, float *texCoords, float *weights, short *jointIds)
 
bool MakeIndices (int sizeIndic, int *indices)
 
- Public Member Functions inherited from CSE::SResource
 SResource (bool isRegister)
 
 SResource (const SResource *resource, bool isRegister)
 
void SetName (std::string name)
 
void SetAbsoluteID (std::string id)
 
std::string GetName () const
 
std::string GetAbsoluteID () const
 
AssetMgr::AssetReferenceGetAssetReference (std::string hash="") const
 
void LinkResource (AssetMgr::AssetReference *asset)
 
void LinkResource (std::string name)
 
void SetHash (std::string &hash) override
 
- Public Member Functions inherited from CSE::SObject
 SObject (bool isRegister)
 
virtual void SetUndestroyable (bool enable)
 
virtual void __FORCE_DESTROY__ ()
 
virtual std::string GenerateMeta ()
 
std::string GetHash () const
 

Static Public Member Functions

static vec3 GenerateTopTriangle (const vec3 &v0, const vec3 &v1, const vec3 &v2)
 
static vec3 GenerateBottomTriangle (const vec3 &v0, const vec3 &v1, const vec3 &v2)
 
static vec3 LerpFilter (const vec3 &v0, const vec3 &v1, float kCoff)
 
- Static Public Member Functions inherited from CSE::SResource
template<class T >
static T * Create (const std::string &name)
 
template<class T >
static T * Create (const AssetMgr::AssetReference *asset)
 
template<class T >
static T * Get (std::string name)
 

Protected Member Functions

void Init (const AssetMgr::AssetReference *asset) override
 

Additional Inherited Members

- Public Attributes inherited from CSE::SISurface
GLMeshID m_meshId
 
- Protected Attributes inherited from CSE::SObject
std::string m_hash
 

Detailed Description

Definition at line 9 of file MeshSurface.h.

Constructor & Destructor Documentation

◆ MeshSurface() [1/2]

MeshSurface::MeshSurface ( int  sizeVert,
float *  vertices,
float *  normals 
)

Definition at line 13 of file MeshSurface.cpp.

13 : m_faceSize(0), m_vertexSize(0),
14 m_indexSize(-1) {
15 MakeVertices(sizeVert, vertices, normals, nullptr, nullptr, nullptr);
16}

◆ MeshSurface() [2/2]

MeshSurface::MeshSurface ( int  sizeVert,
float *  vertices,
float *  normals,
float *  texCoords 
)

Definition at line 19 of file MeshSurface.cpp.

19 : m_faceSize(0),
20 m_vertexSize(0),
21 m_indexSize(-1) {
22 MakeVertices(sizeVert, vertices, normals, texCoords, nullptr, nullptr);
23}

Member Function Documentation

◆ Destroy()

void MeshSurface::Destroy ( )
overridevirtual

Reimplemented from CSE::SObject.

Definition at line 186 of file MeshSurface.cpp.

186 {
187 CORE->GetCore(MemoryMgr)->ReleaseObject(this);
188}

◆ Exterminate()

void MeshSurface::Exterminate ( )
overridevirtual

Implements CSE::SObject.

Definition at line 177 of file MeshSurface.cpp.

177 {
178 const GLuint vertexBuffer = m_meshId.m_vertexBuffer;
179 const GLuint indexBuffer = m_meshId.m_indexBuffer;
180
181 glDeleteBuffers(1, &vertexBuffer);
182 glDeleteBuffers(1, &indexBuffer);
183}

◆ GenerateBottomTriangle()

vec3 MeshSurface::GenerateBottomTriangle ( const vec3 v0,
const vec3 v1,
const vec3 v2 
)
static

Definition at line 153 of file MeshSurface.cpp.

153 {
154 float height = v2.y - v0.y;
155 float width = 0.0f;
156 vec3 S;
157 vec3 E;
158 vec3 N;
159
160 for (int i = 0; i < (int)height; ++i) {
161 float kCoff = (float)i / height;
162
163 S = LerpFilter(v0, v2, kCoff);
164 E = LerpFilter(v1, v2, kCoff);
165 N = S.Cross(E).Normalized();
166 }
167 return N;
168}

◆ GenerateLineIndices()

void MeshSurface::GenerateLineIndices ( std::vector< unsigned short > &  indices) const
overridevirtual

Implements CSE::SISurface.

Definition at line 121 of file MeshSurface.cpp.

121 {
122 indices.resize(GetTriangleIndexCount() * 3); //xyz
123 indices = m_Indics;
124}

◆ GenerateTopTriangle()

vec3 MeshSurface::GenerateTopTriangle ( const vec3 v0,
const vec3 v1,
const vec3 v2 
)
static

Definition at line 135 of file MeshSurface.cpp.

135 {
136 float height = v1.y - v0.y;
137 float width = 0.0f;
138 vec3 S;
139 vec3 E;
140 vec3 N;
141
142 for (int i = 0; i < (int)height; ++i) {
143 float kCoff = (float)i / height;
144
145 S = LerpFilter(v0, v1, kCoff);
146 E = LerpFilter(v0, v2, kCoff);
147 N = S.Cross(E).Normalized();
148 }
149 return N;
150}

◆ GenerateTriangleIndices()

void MeshSurface::GenerateTriangleIndices ( std::vector< unsigned short > &  indices) const
overridevirtual

Implements CSE::SISurface.

Definition at line 126 of file MeshSurface.cpp.

126 {
127 indices.resize(GetTriangleIndexCount() * 3);
128 indices = m_Indics;
129}

◆ GenerateVertices()

void MeshSurface::GenerateVertices ( std::vector< float > &  vertices,
unsigned char  flags 
) const
overridevirtual

Implements CSE::SISurface.

Definition at line 115 of file MeshSurface.cpp.

115 {
116 vertices.resize(GetVertexCount() * 14); // xzy + xyz + st
117 vertices = m_Verts;
118
119}

◆ GetLineIndexCount()

int MeshSurface::GetLineIndexCount ( ) const
overridevirtual

Implements CSE::SISurface.

Definition at line 107 of file MeshSurface.cpp.

107 {
108 return -1;
109}

◆ GetTriangleIndexCount()

int MeshSurface::GetTriangleIndexCount ( ) const
overridevirtual

Implements CSE::SISurface.

Definition at line 111 of file MeshSurface.cpp.

111 {
112 return m_indexSize;
113}

◆ GetVertexCount()

int MeshSurface::GetVertexCount ( ) const
overridevirtual

Implements CSE::SISurface.

Definition at line 103 of file MeshSurface.cpp.

103 {
104 return m_vertexSize;
105}

◆ HasJoint()

bool MeshSurface::HasJoint ( ) const

Definition at line 131 of file MeshSurface.cpp.

131 {
132 return m_meshId.m_hasJoint;
133}

◆ Init()

void MeshSurface::Init ( const AssetMgr::AssetReference asset)
overrideprotectedvirtual

Implements CSE::SResource.

Definition at line 190 of file MeshSurface.cpp.

190 {
191 std::string parent_id = split(asset->id, '?')[0];
192 auto model = CORE->GetCore(ResMgr)->GetAssetReference(parent_id);
193 AssetMgr::TYPE type = model->type;
194
195 // 프리팹에 모든 정보가 있으므로 아예 프리팹 새로 생성
196 // 프리팹 객체에서만 모든걸 만들어야 로직이 꼬이지 않기 때문에 해당 예외처리는 허용되지 않음 (삭제 예정)
197// SPrefab* prefab = nullptr;
198//
199// switch (type) {
200// case AssetMgr::DAE:
201// prefab = DAELoader::GeneratePrefab(model->path.c_str(), nullptr, this, nullptr, nullptr);
202// break;
203// default:
204// break;
205// }
206}

◆ LerpFilter()

vec3 MeshSurface::LerpFilter ( const vec3 v0,
const vec3 v1,
float  kCoff 
)
static

Definition at line 171 of file MeshSurface.cpp.

171 {
172 vec3 v = v1 * kCoff + (v0 * (1.0f - kCoff));
173 return v;
174}

◆ MakeIndices()

bool MeshSurface::MakeIndices ( int  sizeIndic,
int *  indices 
)

Definition at line 88 of file MeshSurface.cpp.

88 {
89 if (!m_Indics.empty()) return false;
90
91 m_Indics.resize(sizeIndic * 3);
92
93 for (int i = 0; i < sizeIndic; ++i) {
94 m_Indics[i * 3] = static_cast<unsigned short>(*(indices)++);
95 m_Indics[i * 3 + 1] = static_cast<unsigned short>(*(indices)++);
96 m_Indics[i * 3 + 2] = static_cast<unsigned short>(*(indices)++);
97 }
98
99 m_indexSize = sizeIndic;
100 return true;
101}

◆ MakeVertices()

bool MeshSurface::MakeVertices ( int  sizeVert,
float *  vertices,
float *  normals,
float *  texCoords,
float *  weights,
short *  jointIds 
)

Definition at line 28 of file MeshSurface.cpp.

29 {
30 if (!m_Verts.empty()) return false;
31
32 struct Vertex {
33 vec3 Position;
34 vec3 Normal;
35 vec2 TexCoord;
36 vec3 Weight;
37 vec3 JointId;
38 };
39
40 if(jointIds != nullptr) m_meshId.m_hasJoint = true;
41 m_Verts.resize(sizeVert * 14);
42
43 auto vertex_tmp = reinterpret_cast<Vertex*>(&m_Verts[0]);
44
45 for (int i = 0; i < sizeVert; ++i) {
46 vertex_tmp->Position.x = *(vertices)++;
47 vertex_tmp->Position.y = *(vertices)++;
48 vertex_tmp->Position.z = *(vertices)++;
49
50 if (normals == nullptr) {
51 vertex_tmp->Normal.Set(0, 0, 0);
52 } else {
53 vertex_tmp->Normal.x = *(normals)++;
54 vertex_tmp->Normal.y = *(normals)++;
55 vertex_tmp->Normal.z = *(normals)++;
56 }
57
58 if (texCoords == nullptr) {
59 vertex_tmp->TexCoord.x = 0;
60 vertex_tmp->TexCoord.y = 0;
61 } else {
62 vertex_tmp->TexCoord.x = *(texCoords)++;
63 vertex_tmp->TexCoord.y = *(texCoords)++;
64 }
65
66 if (weights == nullptr) {
67 vertex_tmp->Weight.Set(0, 0, 0);
68 } else {
69 vertex_tmp->Weight.x = *(weights)++;
70 vertex_tmp->Weight.y = *(weights)++;
71 vertex_tmp->Weight.z = *(weights)++;
72 }
73
74 if (jointIds == nullptr) {
75 vertex_tmp->JointId.Set(0, 0, 0);
76 } else {
77 vertex_tmp->JointId.x = *(jointIds)++;
78 vertex_tmp->JointId.y = *(jointIds)++;
79 vertex_tmp->JointId.z = *(jointIds)++;
80 }
81 vertex_tmp++;
82 }
83 m_vertexSize = sizeVert;
84 return true;
85}

The documentation for this class was generated from the following files: