@@ -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
361425GameObject* 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);
0 commit comments