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

Public Member Functions

 RESOURCE_DEFINE_CONSTRUCTOR (MeshSurface)
 
 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)
 
void SetValue (std::string name_str, Arguments value) override
 
std::string PrintValue () const override
 
- Public Member Functions inherited from CSE::SISurface
 SISurface (std::string &&classType)
 
- Public Member Functions inherited from CSE::SResource
 SResource (std::string classType)
 
 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)
 
std::string GetHash () const
 
- Public Member Functions inherited from CSE::VariableBinder
- Public Member Functions inherited from CSE::ReflectionObject
 ReflectionObject (std::string type)
 
void SetClassType (std::string type)
 
const char * GetClassType () const
 
bool IsSameClass (const char *classType) 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)
 
static SResourceCreate (const std::string &name, const std::string &classType)
 
template<class T >
static T * Create (const AssetMgr::AssetReference *asset)
 
static SResourceCreate (const AssetMgr::AssetReference *asset, const std::string &classType)
 
template<class T >
static T * Get (std::string name)
 
static SResourceGet (std::string &name)
 
- Static Public Member Functions inherited from CSE::ReflectionObject
static ReflectionObjectNewObject (const std::string &name)
 

Protected Member Functions

void Init (const AssetMgr::AssetReference *asset) override
 
- Protected Member Functions inherited from CSE::SResource
- Protected Member Functions inherited from CSE::VariableBinder

Additional Inherited Members

- Public Attributes inherited from CSE::SISurface
GLMeshID m_meshId
 
- Protected Types inherited from CSE::VariableBinder
typedef std::vector< std::string > Arguments
 
- Protected Attributes inherited from CSE::SObject
std::string m_hash
 
- Protected Attributes inherited from CSE::ReflectionObject
std::string m_class
 

Detailed Description

Definition at line 9 of file MeshSurface.h.

Member Function Documentation

◆ Destroy()

void MeshSurface::Destroy ( )
overridevirtual

Reimplemented from CSE::SObject.

Definition at line 190 of file MeshSurface.cpp.

190 {
191 CORE->GetCore(MemoryMgr)->ReleaseObject(this);
192}

◆ Exterminate()

void MeshSurface::Exterminate ( )
overridevirtual

Implements CSE::SObject.

Definition at line 181 of file MeshSurface.cpp.

181 {
182 const GLuint vertexBuffer = m_meshId.m_vertexBuffer;
183 const GLuint indexBuffer = m_meshId.m_indexBuffer;
184
185 glDeleteBuffers(1, &vertexBuffer);
186 glDeleteBuffers(1, &indexBuffer);
187}

◆ GenerateBottomTriangle()

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

Definition at line 157 of file MeshSurface.cpp.

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

◆ GenerateLineIndices()

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

Implements CSE::SISurface.

Definition at line 125 of file MeshSurface.cpp.

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

◆ GenerateTopTriangle()

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

Definition at line 139 of file MeshSurface.cpp.

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

◆ GenerateTriangleIndices()

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

Implements CSE::SISurface.

Definition at line 130 of file MeshSurface.cpp.

130 {
131 indices.resize(GetTriangleIndexCount() * 3);
132 indices = m_Indics;
133}

◆ GenerateVertices()

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

Implements CSE::SISurface.

Definition at line 119 of file MeshSurface.cpp.

119 {
120 vertices.resize(GetVertexCount() * 14); // xzy + xyz + st
121 vertices = m_Verts;
122
123}

◆ GetLineIndexCount()

int MeshSurface::GetLineIndexCount ( ) const
overridevirtual

Implements CSE::SISurface.

Definition at line 111 of file MeshSurface.cpp.

111 {
112 return -1;
113}

◆ GetTriangleIndexCount()

int MeshSurface::GetTriangleIndexCount ( ) const
overridevirtual

Implements CSE::SISurface.

Definition at line 115 of file MeshSurface.cpp.

115 {
116 return m_indexSize;
117}

◆ GetVertexCount()

int MeshSurface::GetVertexCount ( ) const
overridevirtual

Implements CSE::SISurface.

Definition at line 107 of file MeshSurface.cpp.

107 {
108 return m_vertexSize;
109}

◆ HasJoint()

bool MeshSurface::HasJoint ( ) const

Definition at line 135 of file MeshSurface.cpp.

135 {
136 return m_meshId.m_hasJoint;
137}

◆ Init()

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

Implements CSE::SResource.

Definition at line 194 of file MeshSurface.cpp.

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

◆ LerpFilter()

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

Definition at line 175 of file MeshSurface.cpp.

175 {
176 vec3 v = v1 * kCoff + (v0 * (1.0f - kCoff));
177 return v;
178}

◆ MakeIndices()

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

Definition at line 92 of file MeshSurface.cpp.

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

◆ 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 const auto d = vec3::Distance(vec3::Zero, vertex_tmp->Position);
51 if (d > m_meshId.m_maxSize)
52 m_meshId.m_maxSize = d;
53
54 if (normals == nullptr) {
55 vertex_tmp->Normal.Set(0, 0, 0);
56 } else {
57 vertex_tmp->Normal.x = *(normals)++;
58 vertex_tmp->Normal.y = *(normals)++;
59 vertex_tmp->Normal.z = *(normals)++;
60 }
61
62 if (texCoords == nullptr) {
63 vertex_tmp->TexCoord.x = 0;
64 vertex_tmp->TexCoord.y = 0;
65 } else {
66 vertex_tmp->TexCoord.x = *(texCoords)++;
67 vertex_tmp->TexCoord.y = *(texCoords)++;
68 }
69
70 if (weights == nullptr) {
71 vertex_tmp->Weight.Set(0, 0, 0);
72 } else {
73 vertex_tmp->Weight.x = *(weights)++;
74 vertex_tmp->Weight.y = *(weights)++;
75 vertex_tmp->Weight.z = *(weights)++;
76 }
77
78 if (jointIds == nullptr) {
79 vertex_tmp->JointId.Set(0, 0, 0);
80 } else {
81 vertex_tmp->JointId.x = *(jointIds)++;
82 vertex_tmp->JointId.y = *(jointIds)++;
83 vertex_tmp->JointId.z = *(jointIds)++;
84 }
85 vertex_tmp++;
86 }
87 m_vertexSize = sizeVert;
88 return true;
89}

◆ PrintValue()

std::string MeshSurface::PrintValue ( ) const
overridevirtual

Implements CSE::VariableBinder.

Definition at line 215 of file MeshSurface.cpp.

215 {
216 return {};
217}

◆ SetValue()

void MeshSurface::SetValue ( std::string name_str,
Arguments value )
overridevirtual

Used to get serialized values. All classes that inherit from VariableBinder will unconditionally call this function first during initialization.

Parameters
name_strName of values
valueSerialized values

Implements CSE::VariableBinder.

Definition at line 212 of file MeshSurface.cpp.

212 {
213}

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