Advertisement
Guest User

Untitled

a guest
Mar 17th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.62 KB | None | 0 0
  1. #include "BsApplication.h"
  2. #include "Scene/BsSceneObject.h"
  3. #include "Scene/BsSceneManager.h"
  4. #include "Scene/BsPrefab.h"
  5. #include "Resources/BsResources.h"
  6. #include "Resources/BsBuiltinResources.h"
  7. #include "Resources/BsResourceManifest.h"
  8. #include "Material/BsMaterial.h"
  9. #include "Mesh/BsMesh.h"
  10. #include "Importer/BsImporter.h"
  11. #include "Importer/BsMeshImportOptions.h"
  12. #include "Importer/BsTextureImportOptions.h"
  13. #include "Components/BsCCamera.h"
  14. #include "Components/BsCRenderable.h"
  15. #include "Components/BsCLight.h"
  16. #include "RenderAPI/BsRenderWindow.h"
  17. #include "RenderAPI/BsVertexDataDesc.h"
  18. #include "Image/BsColorGradient.h"
  19. #include "Image/BsSpriteTexture.h"
  20. #include "RenderAPI/BsSamplerState.h"
  21. #include "Image/BsTexture.h"
  22. #include "Input/BsInput.h"
  23.  
  24. int main()
  25. {
  26. using namespace bs;
  27.  
  28. VideoMode videoMode(720, 480);
  29. Application::startUp(videoMode, "Example", false);
  30.  
  31. HSceneObject lightSO = SceneObject::create("Light");
  32. HLight light = lightSO->addComponent<CLight>();
  33. light->setType(LightType::Radial);
  34.  
  35. HSceneObject so = SceneObject::create("My object");
  36. HCamera camera = so->addComponent<CCamera>();
  37.  
  38. HShader shader = gBuiltinResources().getBuiltinShader(BuiltinShader::Standard);
  39. HMaterial material = Material::create(shader);
  40.  
  41. auto io = TextureImportOptions::create();
  42. io->setFormat(PF_RGBA8);
  43. io->setGenerateMipmaps(true);
  44. io->setSRGB(true);
  45. io->setCPUCached(true);
  46. HTexture texture = gImporter().import<Texture>("greasy-pan-2-metal.png", io);
  47. SPtr<PixelData> pixelData = PixelData::create(2048, 2048, 1, PF_RGBA8);
  48. texture->readCachedData(*pixelData);
  49. Color color = pixelData->getColorAt(50, 50);
  50. gDebug().logDebug("Color: " + toString(color));
  51. auto& props = texture->getProperties();
  52.  
  53. gDebug().logDebug("Width: " + toString(props.getWidth()));
  54. gDebug().logDebug("Height: " + toString(props.getHeight()));
  55. gDebug().logDebug("Format: " + toString(props.getFormat()));
  56. gDebug().logDebug("Num. mip maps: " + toString(props.getNumMipmaps()));
  57. material->setTexture("gAlbedoTex", texture);
  58.  
  59. auto importOptions = MeshImportOptions::create();
  60. importOptions->setCPUCached(true);
  61.  
  62. HMesh mesh = gImporter().import<Mesh>("Drone.fbx", importOptions);
  63.  
  64. SPtr<VertexDataDesc> vertexDesc = VertexDataDesc::create();
  65. vertexDesc->addVertElem(VET_FLOAT3, VES_POSITION);
  66.  
  67. SPtr<MeshData> meshData = mesh->getCachedData();
  68. gDebug().logDebug(toString(meshData->getNumVertices()));
  69. Vector<Vector3> vertices(8124);
  70. meshData->getVertexData(VES_POSITION, vertices.data(), vertices.size() * sizeof(Vector3));
  71.  
  72. auto& meshProps = mesh->getProperties();
  73. gDebug().logDebug("Num. vertices: " + toString(meshProps.getNumVertices()));
  74. UINT32 numSubMeshes = meshProps.getNumSubMeshes();
  75. gDebug().logDebug("Num. submeshes: " + toString(numSubMeshes));
  76. gDebug().logDebug("Num. indices: " + toString(meshProps.getNumIndices()));
  77. gDebug().logDebug("Radius: " + toString(meshProps.getBounds().getSphere().getRadius()));
  78.  
  79. HSceneObject renderableSO = SceneObject::create("3D object");
  80. HRenderable renderable = renderableSO->addComponent<CRenderable>();
  81.  
  82. renderable->setMesh(mesh);
  83. renderable->setMaterial(material);
  84.  
  85. renderableSO->setPosition(Vector3(0.0f, 15.0f, 47.0f));
  86. SPtr<RenderWindow> primaryWindow = gApplication().getPrimaryWindow();
  87.  
  88. so->setPosition(Vector3(0.0f, 16.0f, 45.0f));
  89. so->lookAt(Vector3(0.0f, 15.0f, 160.0f));
  90. camera->setMain(true);
  91.  
  92. HSceneObject sceneRoot = gSceneManager().getRootNode();
  93. HPrefab scenePrefab = Prefab::create(sceneRoot, true);
  94. gResources().save(scenePrefab, "scenePrefab.asset", true, true);
  95. //SPtr<ResourceManifest> manifest = gResources().getResourceManifest("Default");
  96. //ResourceManifest::save(manifest, "x.asset", "test");
  97.  
  98. //SPtr<ResourceManifest> manifest2 = ResourceManifest::load("x.asset", "test");
  99. //gResources().registerResourceManifest(manifest2);
  100. HPrefab loadedScenePrefab = gResources().load<Prefab>("scenePrefab.asset");
  101. HSceneObject newSceneHierarchy = loadedScenePrefab->instantiate();
  102. gSceneManager().setRootNode(newSceneHierarchy);
  103. for (int i = 0; i < 3; i++)
  104. gDebug().logDebug(newSceneHierarchy->getChild(i)->getName());
  105.  
  106. Vector3 position(BsZero);
  107. gDebug().logDebug(toString(position));
  108. if(not gInput().isButtonHeld(BC_W))
  109. {
  110. position.z += 5.0f;
  111. gDebug().logDebug(toString(position));
  112. }
  113. Application::instance().runMainLoop();
  114. Application::shutDown();
  115.  
  116. return 0;
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement