Advertisement
Guest User

Untitled

a guest
May 30th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.05 KB | None | 0 0
  1. #pragma once
  2.  
  3. // Framework includes
  4. #include "BsApplication.h"
  5. #include "Resources/BsResources.h"
  6. #include "Resources/BsBuiltinResources.h"
  7. #include "Material/BsMaterial.h"
  8. #include "Components/BsCCamera.h"
  9. #include "Components/BsCRenderable.h"
  10. #include "Components/BsCAnimation.h"
  11. #include "Components/BsCSkybox.h"
  12. #include "RenderAPI/BsRenderAPI.h"
  13. #include "RenderAPI/BsRenderWindow.h"
  14. #include "Components/BsCAnimation.h"
  15. #include "Scene/BsSceneObject.h"
  16. #include "Physics/BsPhysicsMaterial.h"
  17. #include "BsPrerequisites.h"
  18. #include "Reflection/BsRTTIType.h"
  19. #include "Resources/BsResources.h"
  20. #include "Resources/BsResourceManifest.h"
  21. #include "Mesh/BsMesh.h"
  22. #include "Importer/BsImporter.h"
  23. #include "Importer/BsMeshImportOptions.h"
  24. #include "Importer/BsTextureImportOptions.h"
  25. #include "Text/BsFontImportOptions.h"
  26. #include "FileSystem/BsFileSystem.h"
  27. #include "Input/BsVirtualInput.h"
  28. #include "Configuration.h"
  29. #include "Framework.h"
  30. #include "Assets.h"
  31.  
  32. namespace bs
  33. {
  34.     struct Assets assets;
  35.  
  36.     /** Load the resources we'll be using throughout the example. */
  37.     Assets loadAssets()
  38.     {
  39.         Assets assets;
  40.  
  41.         // Load the 3D model and the animation clip
  42.         assets.characterSO = SceneObject::create("Character");
  43.         assets.characterAnimation = assets.characterSO->addComponent<CAnimation>();
  44.  
  45.         // Set up a path to the model resource
  46.         const Path dataPath = DATA_PATH;
  47.         const Path meshPath = dataPath + "Meshes/Characters/Character.fbx";
  48.  
  49.         // Set up mesh import options so that we import information about the skeleton and the skin, as well as any
  50.         // animation clips the model might have.
  51.         SPtr<MeshImportOptions> meshImportOptions = MeshImportOptions::create();
  52.         meshImportOptions->setImportSkin(true);
  53.         meshImportOptions->setImportAnimation(true);
  54.  
  55.         // The FBX file contains multiple resources (a mesh and an animation clip), therefore we use importAll() method,
  56.         // which imports all resources in a file.
  57.         //Vector<SubResource> modelResources = gImporter().importAll(meshPath, meshImportOptions);
  58.  
  59.         auto resources = gImporter().importAll(meshPath, meshImportOptions);
  60.  
  61.         assets.characterMesh = static_resource_cast<Mesh>(resources[0].value);
  62.         assets.characterWalkingAnimClip = static_resource_cast<AnimationClip>(resources[1].value);
  63.  
  64.         assets.characterRenderable = assets.characterSO->addComponent<CRenderable>();
  65.         assets.characterRenderable->setMesh(assets.characterMesh);
  66.  
  67.         // Load PBR textures for the 3D model
  68.         assets.characterTexture = Framework::loadTexture(GTexture::HumanTest);
  69.  
  70.         // Create a material using the default physically based shader, and apply the PBR textures we just loaded
  71.         HShader shader = gBuiltinResources().getBuiltinShader(BuiltinShader::Standard);
  72.         assets.characterMaterial = Material::create(shader);
  73.  
  74.         assets.characterMaterial->setTexture("gAlbedoTex", assets.characterTexture);
  75.  
  76.         assets.characterRenderable->setMaterial(assets.characterMaterial);
  77.  
  78.         // Load an environment map
  79.         assets.skyCubemap = Framework::loadTexture(GTexture::WhiteSky, false, true, false);
  80.  
  81.         return assets;
  82.     }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement