CSEngine
Loading...
Searching...
No Matches
FirstDemoScene Class Reference
Inheritance diagram for FirstDemoScene:
CSE::Scene CSE::SObject

Public Member Functions

void Init () override
 
void Tick (float elapsedTime) override
 
void Destroy () override
 
- Public Member Functions inherited from CSE::Scene
void Exterminate () override
 
- Public Member Functions inherited from CSE::SObject
 SObject (bool isRegister)
 
virtual void SetUndestroyable (bool enable)
 
std::string GetHash () const
 
virtual void SetHash (std::string &hash)
 

Additional Inherited Members

- Public Attributes inherited from CSE::Scene
std::string m_name
 
- Static Protected Member Functions inherited from CSE::Scene
static void SetScene (Scene *scene)
 
- Protected Attributes inherited from CSE::SObject
std::string m_hash
 

Detailed Description

Definition at line 6 of file FirstDemoScene.h.

Member Function Documentation

◆ Destroy()

void FirstDemoScene::Destroy ( )
overridevirtual

Implements CSE::Scene.

Definition at line 308 of file FirstDemoScene.cpp.

308 {
309}

◆ Init()

void FirstDemoScene::Init ( )
overridevirtual

Implements CSE::Scene.

Definition at line 27 of file FirstDemoScene.cpp.

27 {
28 //===============
29
30 //DAE test
31// SPrefab* jack = MeshLoader::LoadModel("jack.model");
32 SPrefab* jack = SResource::Create<SPrefab>("jack.prefab");
33 SPrefab* plane = SResource::Create<SPrefab>("plane_circle.prefab");
34 SPrefab* roomPrefab = SResource::Create<SPrefab>("room.prefab");
36
37// daeLoader->GeneratePrefab();
38
39// SGameObject* aa = new SGameObject();
40//
41//
42//
43// aa->CreateComponent<DrawableStaticMeshComponent>();
44// aa->GetComponent<DrawableStaticMeshComponent>()->SetMesh(*(daeLoader->GetMesh()));
45// aa->CreateComponent<MaterialComponent>();
46// aa->GetComponent<MaterialComponent>()->SetMaterialAmbient(vec3{ 1, 1, 0 });
47// aa->GetComponent<MaterialComponent>()->SetShininess(40);
48//
49// aa->CreateComponent<RenderComponent>();
50// aa->GetComponent<RenderComponent>()->SetShaderHandle(0);
51// float scale = 0.1f;
52// aa->GetTransform()->m_scale = vec3{scale, scale, scale};
53 // aa->GetTransform()->m_rotation.x = 90.f;
54// aa->GetTransform()->m_position.y = -0.3f;
55// aa->CreateComponent<CustomComponent>();
56// aa->GetComponent<CustomComponent>()->SetClassName("TestScript");
57// aa->SetName("dae mesh");
58// aa->GetComponent<RenderComponent>()->SetIsEnable(false);
59
60 // cube = daeLoader->GetMesh();
61 // cube->SetUndestroyable(false);
62
63
64 SGameObject* root = new SGameObject("root");
65 root->GetTransform()->m_position = vec3{0, 0, 0};
66
67 auto room = roomPrefab->Clone(vec3{0, 0.2f, 0}, root);
68 room->GetTransform()->m_scale = vec3{ 4.f, 4.f, 4.f };
69// room->GetTransform()->m_rotation.Rotate(Quaternion::AngleAxis(vec3{0, 1, 0}, 3.14f / 2));
70
71 const auto& room_children = room->GetChildren();
72 for (const auto& gameObject : room_children) {
73 const auto& component = gameObject->GetComponent<RenderComponent>();
74 if(component == nullptr) continue;
75 component->SetMaterial(SResource::Create<SMaterial>("File:Material/Room.mat"));
76 const auto& meshComp = gameObject->GetComponent<DrawableStaticMeshComponent>();
77 const auto& mesh = meshComp->GetMeshID();
78// generator->GenerateVolumeTexture(8, mesh, *SResource::Create<SMaterial>("File:Material/Room.mat"));
79 }
80
81 //Managing Memory Test
82 SGameObject* b = new SGameObject();
83 b->SetParent(root);
84 d = new SGameObject();
85 d->SetParent(root);
86// STexture* empty = new STexture();
87// empty->LoadEmpty();
88
89 cube = new MeshSurface(CH02::teapot_smoothNumVerts, CH02::teapot_smoothVerts, CH02::teapot_smoothNormals);
90 cube->SetUndestroyable(false);
91 SFrameBuffer* buffer = new SFrameBuffer();
92 buffer->GenerateFramebuffer(SFrameBuffer::PLANE, 512, 512);
93 const auto& buf_tex = buffer->GenerateTexturebuffer(SFrameBuffer::RENDER, GL_RGB);
94 buf_tex->SetName("framebuffer_test");
95 buf_tex->SetAbsoluteID("framebuffer_test");
96 buffer->RasterizeFramebuffer();
97 b->Destroy();
98
99 SGameObject* testing = new SGameObject("root of mesh");
100 root->AddChild(testing);
101
102 auto* camera_gm = new SGameObject("ct");
103 camera_gm->SetParent(testing);
104 camera_gm->GetTransform()->m_position = vec3{ 0, -0.3f, 0 };
105 {
106 const auto& sc = camera_gm->CreateComponent<CustomComponent>();
107 sc->SetClassName("testScript.script");
108 }
109
110 auto* light_gm = new SGameObject("lt");
111 light_gm->SetParent(testing);
112 light_gm->GetTransform()->m_scale = vec3{ 0.2f, 0.2f, 0.2f };
113 {
114 const auto& sc = light_gm->CreateComponent<CustomComponent>();
115 sc->SetClassName("testScriptFast.script");
116 }
117
118 SGameObject* a = new SGameObject("camera");
119 a->SetParent(camera_gm);
120
121 SGameObject* ab = jack->Clone(vec3{ 0, -0.15f, 0 }, testing);
122 SGameObject* ab2 = jack->Clone(vec3{ 0.1f, -0.45f, 0.12f }, testing);
123 ab->GetTransform()->m_scale = vec3{ 0.0002f, 0.0002f, 0.0002f };
124 ab2->GetTransform()->m_scale = vec3{ 0.0002f, 0.0002f, 0.0002f };
125 ab2->GetTransform()->m_rotation.Rotate(Quaternion::AngleAxis(vec3{1, 0, 0}, 3.14f / 2));
126 ab2->GetTransform()->m_rotation.Rotate(Quaternion::AngleAxis(vec3{0, 1, 0}, 1.f));
127// ab->CreateComponent<CustomComponent>();
128// ab->GetComponent<CustomComponent>()->SetClassName("testScript.script");
129// auto ab_m = ab->GetComponent<RenderComponent>()->GetMaterial();
130 {
131 const auto& ab_children = ab->GetChildren();
132 for (const auto& gameObject : ab_children) {
133 const auto& component = gameObject->GetComponent<RenderComponent>();
134 if (component == nullptr) continue;
135 if(gameObject->GetName() == "Mesh-mesh") {
136 const auto& material = SResource::Create<SMaterial>("File:Material/Jack.mat");
137 material->SetOrderLayer(5500);
138 component->SetMaterial(material);
139 }
140 else {
141 const auto& material = SResource::Create<SMaterial>("File:Material/Label.mat");
142 component->SetMaterial(material);
143 }
144 }
145 }
146 {
147 const auto& ab_children = ab2->GetChildren();
148 for (const auto& gameObject : ab_children) {
149 const auto& component = gameObject->GetComponent<RenderComponent>();
150 if (component == nullptr) continue;
151 if(gameObject->GetName() == "Mesh-mesh") {
152 const auto& material = SResource::Create<SMaterial>("File:Material/Jack.mat");
153 material->SetOrderLayer(5500);
154 component->SetMaterial(material);
155 }
156 else {
157 const auto& material = SResource::Create<SMaterial>("File:Material/Label.mat");
158 component->SetMaterial(material);
159 }
160 }
161 }
162
163 c2 = new SGameObject();
164 c2->SetParent(testing);
165 // c2->AddComponent(c->GetComponent<DrawableStaticMeshComponent>());
166 c2->CreateComponent<DrawableStaticMeshComponent>();
167 c2->GetComponent<DrawableStaticMeshComponent>()->SetMesh(*cube);
168// c2->GetComponent<MaterialComponent>()->SetMaterialAmbient(vec3{ 1, 0, 0 });
169// c2->GetComponent<MaterialComponent>()->SetAlbedoTexture(empty);
170 c2->GetTransform()->m_position = vec3{ -0.2f, -0.3f, -0.2f };
171 c2->GetTransform()->m_scale = vec3{ 0.5f, 0.5f, 0.5f };
172 {
173 const auto& render = c2->CreateComponent<RenderComponent>();
174 const auto& material = SResource::Create<SMaterial>("File:Material/SSS_PBR.mat");
175 material->SetOrderLayer(6000);
176 render->SetMaterial(material);
177 const auto& meshComp = c2->GetComponent<DrawableStaticMeshComponent>();
178 const auto& mesh = meshComp->GetMeshID();
179// generator->GenerateVolumeTexture(8, mesh, *material);
180 }
181// c2->GetComponent<RenderComponent>()->SetShaderHandle("PBR.shader");
182
183 c3 = new SGameObject("testscript2 object");
184 c3->SetParent(root);
185 c3->GetTransform()->m_position.y = -0.7f;
186
187 c3->CreateComponent<CustomComponent>();
188 c3->GetComponent<CustomComponent>()->SetClassName("testScript2.script");
189// {
190// std::vector<std::string> variable = {
191// "materialComp", c3->GetID(c3->GetComponent<MaterialComponent>()), "comp"
192// };
193// c3->GetComponent<CustomComponent>()->SetValue("__variable__", variable);
194// }
195// {
196// std::vector<std::string> variable = {
197// "testScript", c->GetID(c->GetComponent<CustomComponent>()), "nut"
198// };
199// c3->GetComponent<CustomComponent>()->SetValue("__variable__", variable);
200// }
201
202
203// c3->GetComponent<RenderComponent>()->SetShaderHandle("PBR.shader");
204
205 auto c4 = SCloneFactory::Clone(c3, c3);
206// c4->GetComponent<MaterialComponent>()->SetMaterialAmbient(vec3{ 1, 0, 1 });
207// c4->GetComponent<MaterialComponent>()->SetAlbedoTexture(empty);
208 c4->GetTransform()->m_position.y = -0.1f;
209 c4->GetTransform()->m_position.x = -2.f;
210 c4->GetTransform()->m_scale.Set(0.5, 0.5, 0.5);
211 c4->DeleteComponent(c4->GetComponent<CustomComponent>());
212
213
214 SGameObject* direction = new SGameObject();
215 direction->SetParent(root);
216 direction->SetName("directional");
217 direction->GetTransform()->m_position = vec3{ 0.f, 1.f, 0.f };
218 direction->CreateComponent<LightComponent>();
219// direction->GetComponent<LightComponent>()->SetColorAmbient(vec4{ 0.07f, 0.07f, 0.07f, 1 });
220// direction->GetComponent<LightComponent>()->SetColorDiffuse(vec4{ 0.3f, 0.5f, 0.5f, 1 });
221 direction->GetComponent<LightComponent>()->SetSunrising(true);
222 direction->GetComponent<LightComponent>()->SetLightType(LightComponent::DIRECTIONAL);
223 direction->GetComponent<LightComponent>()->SetDirection(vec4{ 0.0f, 1.0f, 1, 0 });
224 direction->GetComponent<LightComponent>()->SetShadow(true);
225
226 direction->CreateComponent<CustomComponent>();
227 direction->GetComponent<CustomComponent>()->SetClassName("directionalLight.script");
228//
229//
230// SComponent* test_comp = direction->GetComponent<CustomComponent>();
231//
232// auto auto_comp = test_comp->GetComponent();
233
234 d->SetName("light");
235 d->CreateComponent<LightComponent>();
236 d->GetTransform()->m_position = vec3{ -2.8f, -1.5f, 0 };
237 light_gm->AddChild(d);
238 d->GetComponent<LightComponent>()->SetDirection(vec4{ 1.f, 0.5f, 1.f, 1.0f });
239 d->GetComponent<LightComponent>()->SetColor(vec3{ 5, 5, 5 });
240 d->GetComponent<LightComponent>()->SetLightType(LightComponent::POINT);
241 d->GetComponent<LightComponent>()->SetLightRadius(1);
242 d->GetComponent<LightComponent>()->SetShadow(false);
243// d->CreateComponent<DrawableStaticMeshComponent>();
244// d->GetComponent<DrawableStaticMeshComponent>()->SetMesh(*cube);
245// d->CreateComponent<MaterialComponent>();
246// d->GetComponent<MaterialComponent>()->AttachMaterials("File:Material/DefaultPBR.mat");
247// d->GetComponent<MaterialComponent>()->SetDiffuseMaterial(vec4{ 1, 1, 1, 1 });
248// d->GetComponent<MaterialComponent>()->SetAlbedo(vec3{ 1, 1, 1 });
249// d->GetComponent<MaterialComponent>()->SetAlbedoTexture(empty);
250// auto d_r = d->CreateComponent<RenderComponent>();
251// d_r->GetMaterial()->SetVec3("FLOAT_ALBEDO", vec3{ 0, 1, 0 });
252// d->GetComponent<RenderComponent>()->SetShaderHandle("PBR.shader");
253 //d->GetComponent<LightComponent>()->DisableDiffuse = true;
254
255 a->CreateComponent<CameraComponent>();
256// a->GetComponent<CameraComponent>()->SetOrtho(-3.f, 3.f, -3.f, 3.f);
257// a->GetComponent<CameraComponent>()->SetCameraType(CSE::CameraComponent::ORTHO);
258 a->GetTransform()->m_position = vec3{ 0, 0.2f, 0.8f };
259// a->GetTransform()->m_position = vec3{ 0.f, 2.f, 4.f };
260// a->GetTransform()->m_scale = vec3{ 2.f, 2.f, 2.f };
261// a->GetComponent<CameraComponent>()->SetTarget(vec3{ 0.0f, -1.0f, -1.f });
262 auto a_cam = a->GetComponent<CameraComponent>();
263 a_cam->SetTarget(c2);
264 a_cam->SetBackgroundSkybox();
265 a_cam->SetBackgroundType(CameraBase::SKYBOX);
266// a->CreateComponent<CustomComponent>();
267// a->GetComponent<CustomComponent>()->SetClassName("testcamerar.script");
268
269 c4->CreateComponent<CameraComponent>();
270 c4->GetComponent<CameraComponent>()->SetTarget(d);
271 c4->GetComponent<CameraComponent>()->SetBackgroundSkybox();
272 c4->GetComponent<CameraComponent>()->SetBackgroundType(CameraBase::SKYBOX);
273 c4->GetComponent<CameraComponent>()->SetFrameBuffer(
274 SResource::Create<SFrameBuffer>("File:Texture/TestFrameBuffer.framebuffer"));
275 //===============
276
277 SSceneLoader::SavePrefab(root, CSE::NativeAssetsPath() + "Scene/test_scene.scene");
278 SAFE_DELETE(generator);
279}
STexture * GenerateTexturebuffer(BufferType type, int channel, int level=0)
void GenerateFramebuffer(BufferDimension dimension, int width, int height)
void Destroy() override
자동 삭제가 아닌 특정한 상황에서 삭제될 때 호출되는 함수

◆ Tick()

void FirstDemoScene::Tick ( float elapsedTime)
overridevirtual

Implements CSE::Scene.

Definition at line 282 of file FirstDemoScene.cpp.

282 {
283
284 if (startTIme == 0) {
285 startTIme = elapsedTime;
286 }
287
288 c2->GetTransform()->m_position.x = sinf(elapsedTime*0.001) * 1.0f;;
289 c2->GetTransform()->m_position.y = cosf(elapsedTime*0.001) * 0.5f;;
290 c2->GetTransform()->m_position.z = cosf(elapsedTime*0.001) * 0.5f;;
291
292 //===============
293// SGameObject* d = GameObjectMgr::getInstance()->Find("dae mesh");
294// d->GetTransform()->m_position.x = sinf(elapsedTime*0.001) * 1.f;
295// d->GetTransform()->m_position.z = cosf(elapsedTime*0.001) * 1.f;
296 //c->GetTransform()->m_rotation.y += 0.1f;
297// c->GetTransform()->m_position.y = sinf(elapsedTime * 0.001) * 0.1f;
298 //===============
299
300 if (elapsedTime - startTIme > 3000) {
301 startTIme = elapsedTime;
302 isInvisible = !isInvisible;
303// switchingObject();
304 }
305}

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