Skip to content

Commit f9324dc

Browse files
committed
Samples updated
1 parent 25f2b8d commit f9324dc

File tree

10 files changed

+119
-49
lines changed

10 files changed

+119
-49
lines changed

Samples/03_ThirdPerson/Application.cpp

Lines changed: 84 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ void SampleApplication::Initialize()
138138
m_WorldRenderView = MakeRef<WorldRenderView>();
139139
m_WorldRenderView->SetWorld(m_World);
140140
m_WorldRenderView->bClearBackground = true;
141-
m_WorldRenderView->BackgroundColor = Color3::sBlack();
141+
m_WorldRenderView->BackgroundColor = Color3(0.2f, 0.2f, 0.3f);
142142
m_WorldRenderView->bDrawDebug = true;
143143
mainViewport->SetWorldRenderView(m_WorldRenderView);
144144

@@ -190,16 +190,27 @@ void SampleApplication::CreateResources()
190190
auto& materialMngr = sGetMaterialManager();
191191

192192
materialMngr.LoadLibrary("/Root/default/materials/default.mlib");
193+
materialMngr.LoadLibrary("/Root/thirdparty/freepbr.com/freepbr.mlib");
194+
materialMngr.LoadLibrary("/Root/thirdparty/sketchfab.com/sketchfab.mlib");
193195

194196
// List of resources used in scene
195197
ResourceID sceneResources[] = {
196198
resourceMngr.GetResource<MeshResource>("/Root/default/box.mesh"),
197199
resourceMngr.GetResource<MeshResource>("/Root/default/sphere.mesh"),
198200
resourceMngr.GetResource<MeshResource>("/Root/default/capsule.mesh"),
199201
resourceMngr.GetResource<MaterialResource>("/Root/default/materials/compiled/default.mat"),
202+
resourceMngr.GetResource<TextureResource>("/Root/black.png"),
200203
resourceMngr.GetResource<TextureResource>("/Root/grid8.webp"),
201204
resourceMngr.GetResource<TextureResource>("/Root/blank256.webp"),
202-
resourceMngr.GetResource<TextureResource>("/Root/blank512.webp")
205+
resourceMngr.GetResource<TextureResource>("/Root/blank512.webp"),
206+
resourceMngr.GetResource<TextureResource>("/Root/thirdparty/freepbr.com/grime-alley-brick2/albedo.tex"),
207+
resourceMngr.GetResource<TextureResource>("/Root/thirdparty/freepbr.com/grime-alley-brick2/orm.tex"),
208+
resourceMngr.GetResource<TextureResource>("/Root/thirdparty/freepbr.com/grime-alley-brick2/normal.tex"),
209+
resourceMngr.GetResource<MaterialResource>("/Root/default/materials/compiled/default_orm.mat"),
210+
resourceMngr.GetResource<MeshResource>("/Root/thirdparty/sketchfab.com/barrel/barrel.mesh"),
211+
resourceMngr.GetResource<TextureResource>("/Root/thirdparty/sketchfab.com/barrel/albedo.tex"),
212+
resourceMngr.GetResource<TextureResource>("/Root/thirdparty/sketchfab.com/barrel/orm.tex"),
213+
resourceMngr.GetResource<TextureResource>("/Root/thirdparty/sketchfab.com/barrel/normal.tex")
203214
};
204215

205216
// Load resources asynchronously
@@ -215,11 +226,31 @@ void SampleApplication::CreateScene()
215226
auto& resourceMngr = GameApplication::sGetResourceManager();
216227
auto& materialMngr = GameApplication::sGetMaterialManager();
217228

218-
CreateSceneFromMap(m_World, "/Root/maps/sample3.map");
229+
CreateSceneFromMap(m_World, "/Root/maps/sample3.map", "grime-alley-brick2");
219230

220231
Float3 playerSpawnPosition = Float3(12,0,0);
221232
Quat playerSpawnRotation = Quat::sRotationY(Math::_HALF_PI);
222233

234+
// Light
235+
{
236+
Float3 lightDirection = Float3(0.5f, -1, -0.1f).Normalized();
237+
238+
GameObjectDesc desc;
239+
desc.IsDynamic = true;
240+
241+
GameObject* object;
242+
m_World->CreateObject(desc, object);
243+
object->SetDirection(lightDirection);
244+
245+
DirectionalLightComponent* dirlight;
246+
object->CreateComponent(dirlight);
247+
dirlight->SetIlluminance(20000.0f);
248+
dirlight->SetShadowMaxDistance(50);
249+
dirlight->SetShadowCascadeResolution(2048);
250+
dirlight->SetShadowCascadeOffset(0.0f);
251+
dirlight->SetShadowCascadeSplitLambda(0.8f);
252+
}
253+
223254
{
224255
GameObjectDesc desc;
225256
desc.Name.FromString("Light");
@@ -267,22 +298,25 @@ void SampleApplication::CreateScene()
267298

268299
for (int i = 0; i < HK_ARRAY_SIZE(positions); i++)
269300
{
270-
GameObjectDesc desc;
271-
desc.Position = positions[i] + Float3(22-33, 0, -28-6);
272-
desc.Rotation.FromAngles(0, Math::Radians(yaws[i]), 0);
273-
desc.Scale = Float3(1.5f);
274-
desc.IsDynamic = true;
275-
GameObject* object;
276-
m_World->CreateObject(desc, object);
277-
DynamicBodyComponent* phys;
278-
object->CreateComponent(phys);
279-
phys->Mass = 30;
280-
object->CreateComponent<BoxCollider>();
281-
DynamicMeshComponent* mesh;
282-
object->CreateComponent(mesh);
283-
mesh->SetMesh(resourceMngr.GetResource<MeshResource>("/Root/default/box.mesh"));
284-
mesh->SetMaterial(materialMngr.TryGet("blank256"));
285-
mesh->SetLocalBoundingBox({Float3(-0.5f),Float3(0.5f)});
301+
Quat rotation;
302+
rotation.FromAngles(0, Math::Radians(yaws[i]), 0);
303+
SpawnBarrel(positions[i] + Float3(22-33, 0, -28-6), rotation);
304+
//GameObjectDesc desc;
305+
//desc.Position = positions[i] + Float3(22-33, 0, -28-6);
306+
//desc.Rotation.FromAngles(0, Math::Radians(yaws[i]), 0);
307+
//desc.Scale = Float3(1.5f);
308+
//desc.IsDynamic = true;
309+
//GameObject* object;
310+
//m_World->CreateObject(desc, object);
311+
//DynamicBodyComponent* phys;
312+
//object->CreateComponent(phys);
313+
//phys->Mass = 30;
314+
//object->CreateComponent<BoxCollider>();
315+
//DynamicMeshComponent* mesh;
316+
//object->CreateComponent(mesh);
317+
//mesh->SetMesh(resourceMngr.GetResource<MeshResource>("/Root/default/box.mesh"));
318+
//mesh->SetMaterial(materialMngr.TryGet("blank256"));
319+
//mesh->SetLocalBoundingBox({Float3(-0.5f),Float3(0.5f)});
286320
}
287321
}
288322

@@ -355,8 +389,38 @@ void SampleApplication::CreateScene()
355389
}
356390

357391
m_PlayerSpawnPoints.Add({playerSpawnPosition, playerSpawnRotation});
392+
393+
RenderInterface& render = m_World->GetInterface<RenderInterface>();
394+
render.SetAmbient(0.01f);
358395
}
359396

397+
void SampleApplication::SpawnBarrel(Float3 const& position, Quat const& rotation)
398+
{
399+
auto& resourceMngr = sGetResourceManager();
400+
auto& materialMngr = sGetMaterialManager();
401+
402+
static MeshHandle meshHandle = resourceMngr.GetResource<MeshResource>("/Root/thirdparty/sketchfab.com/barrel/barrel.mesh");
403+
404+
GameObjectDesc desc;
405+
desc.Position = position;
406+
desc.Rotation = rotation;
407+
desc.IsDynamic = true;
408+
GameObject* object;
409+
m_World->CreateObject(desc, object);
410+
DynamicBodyComponent* phys;
411+
object->CreateComponent(phys);
412+
phys->Mass = 50;
413+
CylinderCollider* collider;
414+
object->CreateComponent<CylinderCollider>(collider);
415+
collider->Height = 0.85f;
416+
collider->Radius = 0.35f;
417+
DynamicMeshComponent* mesh;
418+
object->CreateComponent(mesh);
419+
mesh->SetMesh(meshHandle);
420+
mesh->SetMaterial(0, materialMngr.TryGet("thirdparty/sketchfab/barrel"));
421+
mesh->SetMaterial(1, materialMngr.TryGet("thirdparty/sketchfab/barrel"));
422+
mesh->SetLocalBoundingBox({Float3(-0.5f),Float3(0.5f)});
423+
}
360424

361425
GameObject* SampleApplication::CreatePlayer(Float3 const& position, Quat const& rotation)
362426
{
@@ -427,7 +491,7 @@ GameObject* SampleApplication::CreatePlayer(Float3 const& position, Quat const&
427491
PunctualLightComponent* light;
428492
torch->CreateComponent(light);
429493
light->SetCastShadow(true);
430-
light->SetLumens(100);
494+
light->SetLumens(1000);
431495
light->SetTemperature(2600);
432496
LightAnimator* animator;
433497
torch->CreateComponent(animator);

Samples/03_ThirdPerson/Application.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class SampleApplication final : public GameApplication
4848
private:
4949
void CreateResources();
5050
void CreateScene();
51+
void SpawnBarrel(Float3 const& position, Quat const& rotation);
5152
GameObject* CreatePlayer(Float3 const& position, Quat const& rotation);
5253
void Pause();
5354
void Quit();

Samples/06_SkeletalAnimation/Application.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,10 @@ void SampleApplication::OnStartPlay()
212212
CreateScene();
213213

214214
// Create player
215-
m_Player = CreatePlayer(Float3(0,0,4), Quat::sIdentity());
215+
GameObject* player = CreatePlayer(Float3(0,0,4), Quat::sIdentity());
216+
m_Player = player->GetHandle();
216217

217-
if (GameObject* camera = m_Player->FindChildren(StringID("Camera")))
218+
if (GameObject* camera = player->FindChildren(StringID("Camera")))
218219
{
219220
// Set camera for rendering
220221
m_WorldRenderView->SetCamera(camera->GetComponentHandle<CameraComponent>());
@@ -223,7 +224,7 @@ void SampleApplication::OnStartPlay()
223224
// Bind input to the player
224225
InputInterface& input = m_World->GetInterface<InputInterface>();
225226
input.SetActive(true);
226-
input.BindInput(m_Player->GetComponentHandle<FirstPersonComponent>(), PlayerController::_1);
227+
input.BindInput(player->GetComponentHandle<FirstPersonComponent>(), PlayerController::_1);
227228
}
228229

229230
void SampleApplication::Pause()
@@ -467,11 +468,11 @@ GameObject* SampleApplication::CreatePlayer(Float3 const& position, Quat const&
467468

468469
void SampleApplication::SpawnPaladin()
469470
{
470-
if (m_Player)
471+
if (GameObject* player = m_World->GetObject(m_Player))
471472
{
472-
if (GameObject* camera = m_Player->FindChildren(StringID("Camera")))
473+
if (GameObject* camera = player->FindChildren(StringID("Camera")))
473474
{
474-
Float3 rayPos = m_Player->GetPosition() + camera->GetWorldForwardVector() + Float3::sAxisY();
475+
Float3 rayPos = player->GetPosition() + camera->GetWorldForwardVector() + Float3::sAxisY();
475476

476477
RayCastResult rayResult;
477478
RayCastFilter rayFilter;
@@ -837,11 +838,11 @@ void SampleApplication::SpawnBarrel(Float3 const& position, Quat const& rotation
837838

838839
void SampleApplication::DropBarrel()
839840
{
840-
if (m_Player)
841+
if (GameObject* player = m_World->GetObject(m_Player))
841842
{
842-
if (GameObject* camera = m_Player->FindChildren(StringID("Camera")))
843+
if (GameObject* camera = player->FindChildren(StringID("Camera")))
843844
{
844-
SpawnBarrel(m_Player->GetPosition() + camera->GetWorldForwardVector() * 0.8f + Float3::sAxisY(), Quat::sIdentity());
845+
SpawnBarrel(player->GetPosition() + camera->GetWorldForwardVector() * 0.8f + Float3::sAxisY(), Quat::sIdentity());
845846
}
846847
}
847848
}

Samples/06_SkeletalAnimation/Application.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class SampleApplication final : public GameApplication
7979
TextureHandle m_LoadingTexture;
8080
World* m_World{};
8181
Ref<WorldRenderView> m_WorldRenderView;
82-
GameObject* m_Player{};
82+
GameObjectHandle m_Player;
8383
Handle32<class AnimatorComponent> m_Animator;
8484
};
8585

Samples/10_InverseKinematics/Application.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -264,12 +264,13 @@ void SampleApplication::OnStartPlay()
264264
ShowLoadingScreen(false);
265265

266266
// Create player
267-
m_Player = CreatePlayer(Float3(0,0,4), Quat::sIdentity());
267+
GameObject* player = CreatePlayer(Float3(0,0,4), Quat::sIdentity());
268+
m_Player = player->GetHandle();
268269

269270
// Create scene
270271
CreateScene();
271272

272-
if (GameObject* camera = m_Player->FindChildren(StringID("Camera")))
273+
if (GameObject* camera = player->FindChildren(StringID("Camera")))
273274
{
274275
// Set camera for rendering
275276
m_WorldRenderView->SetCamera(camera->GetComponentHandle<CameraComponent>());
@@ -278,7 +279,7 @@ void SampleApplication::OnStartPlay()
278279
// Bind input to the player
279280
InputInterface& input = m_World->GetInterface<InputInterface>();
280281
input.SetActive(true);
281-
input.BindInput(m_Player->GetComponentHandle<FirstPersonComponent>(), PlayerController::_1);
282+
input.BindInput(player->GetComponentHandle<FirstPersonComponent>(), PlayerController::_1);
282283
}
283284

284285
void SampleApplication::Pause()
@@ -507,11 +508,11 @@ GameObject* SampleApplication::CreatePlayer(Float3 const& position, Quat const&
507508

508509
void SampleApplication::SpawnPaladin()
509510
{
510-
if (m_Player)
511+
if (GameObject* player = m_World->GetObject(m_Player))
511512
{
512-
if (GameObject* camera = m_Player->FindChildren(StringID("Camera")))
513+
if (GameObject* camera = player->FindChildren(StringID("Camera")))
513514
{
514-
Float3 rayPos = m_Player->GetPosition() + camera->GetWorldForwardVector() + Float3::sAxisY();
515+
Float3 rayPos = player->GetPosition() + camera->GetWorldForwardVector() + Float3::sAxisY();
515516

516517
RayCastResult rayResult;
517518
RayCastFilter rayFilter;
@@ -563,7 +564,10 @@ void SampleApplication::SpawnPaladin(Float3 const& position, Quat const& rotatio
563564

564565
PaladinHeadController* headController;
565566
object->CreateComponent(headController);
566-
headController->Target = m_Player->FindChildren(StringID("Camera"))->GetHandle();
567+
568+
GameObject* player = m_World->GetObject(m_Player);
569+
GameObject* playerCamera = player->FindChildren(StringID("Camera"));
570+
headController->Target = playerCamera->GetHandle();
567571

568572
StaticVector<StringView, 4> jointsChain = {"mixamorig:Head", "mixamorig:Neck", "mixamorig:Spine2", "mixamorig:Spine1"};
569573

Samples/10_InverseKinematics/Application.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class SampleApplication final : public GameApplication
7373
TextureHandle m_LoadingTexture;
7474
World* m_World{};
7575
Ref<WorldRenderView> m_WorldRenderView;
76-
GameObject* m_Player{};
76+
GameObjectHandle m_Player;
7777
Handle32<class AnimatorComponent> m_Animator;
7878
bool m_Play{};
7979
};

Samples/11_WaterVolume/Application.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,10 @@ void SampleApplication::OnStartPlay()
178178
CreateScene();
179179

180180
// Create player
181-
m_Player = CreatePlayer(Float3(0,0,20), Quat::sIdentity());
181+
GameObject* player = CreatePlayer(Float3(0,0,20), Quat::sIdentity());
182+
m_Player = player->GetHandle();
182183

183-
if (GameObject* camera = m_Player->FindChildren(StringID("Camera")))
184+
if (GameObject* camera = player->FindChildren(StringID("Camera")))
184185
{
185186
// Set camera for rendering
186187
m_WorldRenderView->SetCamera(camera->GetComponentHandle<CameraComponent>());
@@ -189,7 +190,7 @@ void SampleApplication::OnStartPlay()
189190
// Bind input to the player
190191
InputInterface& input = m_World->GetInterface<InputInterface>();
191192
input.SetActive(true);
192-
input.BindInput(m_Player->GetComponentHandle<FirstPersonComponent>(), PlayerController::_1);
193+
input.BindInput(player->GetComponentHandle<FirstPersonComponent>(), PlayerController::_1);
193194
}
194195

195196
void SampleApplication::Pause()
@@ -520,11 +521,11 @@ GameObject* SampleApplication::SpawnBarrel(Float3 const& position, Quat const& r
520521

521522
void SampleApplication::DropBarrel()
522523
{
523-
if (m_Player)
524+
if (GameObject* player = m_World->GetObject(m_Player))
524525
{
525-
if (GameObject* camera = m_Player->FindChildren(StringID("Camera")))
526+
if (GameObject* camera = player->FindChildren(StringID("Camera")))
526527
{
527-
GameObject* barrel = SpawnBarrel(m_Player->GetPosition() + camera->GetWorldForwardVector() * 0.8f + Float3::sAxisY() * 1.3f, camera->GetWorldRotation() * Quat::sRotationZ(Math::_HALF_PI));
528+
GameObject* barrel = SpawnBarrel(player->GetPosition() + camera->GetWorldForwardVector() * 0.8f + Float3::sAxisY() * 1.3f, camera->GetWorldRotation() * Quat::sRotationZ(Math::_HALF_PI));
528529

529530
if (auto body = barrel->GetComponent<DynamicBodyComponent>())
530531
{

Samples/11_WaterVolume/Application.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class SampleApplication final : public GameApplication
7171
TextureHandle m_LoadingTexture;
7272
World* m_World{};
7373
Ref<WorldRenderView> m_WorldRenderView;
74-
GameObject* m_Player{};
74+
GameObjectHandle m_Player;
7575
};
7676

7777
HK_NAMESPACE_END

Samples/12_Terrain/Application.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,12 @@ void SampleApplication::OnStartPlay()
182182
ShowLoadingScreen(false);
183183

184184
// Create player
185-
m_Player = CreatePlayer(Float3(0,0,4), Quat::sIdentity());
185+
GameObject* player = CreatePlayer(Float3(0,0,4), Quat::sIdentity());
186186

187187
// Create scene
188188
CreateScene();
189189

190-
if (GameObject* camera = m_Player->FindChildren(StringID("Camera")))
190+
if (GameObject* camera = player->FindChildren(StringID("Camera")))
191191
{
192192
// Set camera for rendering
193193
m_WorldRenderView->SetCamera(camera->GetComponentHandle<CameraComponent>());
@@ -196,7 +196,7 @@ void SampleApplication::OnStartPlay()
196196
// Bind input to the player
197197
InputInterface& input = m_World->GetInterface<InputInterface>();
198198
input.SetActive(true);
199-
input.BindInput(m_Player->GetComponentHandle<FirstPersonComponent>(), PlayerController::_1);
199+
input.BindInput(player->GetComponentHandle<FirstPersonComponent>(), PlayerController::_1);
200200
}
201201

202202
void SampleApplication::Pause()

Samples/12_Terrain/Application.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ class SampleApplication final : public GameApplication
6969
TextureHandle m_LoadingTexture;
7070
World* m_World{};
7171
Ref<WorldRenderView> m_WorldRenderView;
72-
GameObject* m_Player{};
7372
};
7473

7574
HK_NAMESPACE_END

0 commit comments

Comments
 (0)