Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "BsApplication.h"
- #include "Scene/BsSceneObject.h"
- #include "Scene/BsSceneManager.h"
- #include "Scene/BsPrefab.h"
- #include "Resources/BsResources.h"
- #include "Resources/BsBuiltinResources.h"
- #include "Resources/BsResourceManifest.h"
- #include "Material/BsMaterial.h"
- #include "Mesh/BsMesh.h"
- #include "Importer/BsImporter.h"
- #include "Importer/BsMeshImportOptions.h"
- #include "Importer/BsTextureImportOptions.h"
- #include "Components/BsCCamera.h"
- #include "Components/BsCRenderable.h"
- #include "Components/BsCLight.h"
- #include "RenderAPI/BsRenderWindow.h"
- #include "RenderAPI/BsVertexDataDesc.h"
- #include "Image/BsColorGradient.h"
- #include "Image/BsSpriteTexture.h"
- #include "RenderAPI/BsSamplerState.h"
- #include "Image/BsTexture.h"
- #include "Input/BsInput.h"
- int main()
- {
- using namespace bs;
- VideoMode videoMode(720, 480);
- Application::startUp(videoMode, "Example", false);
- HSceneObject lightSO = SceneObject::create("Light");
- HLight light = lightSO->addComponent<CLight>();
- light->setType(LightType::Radial);
- HSceneObject so = SceneObject::create("My object");
- HCamera camera = so->addComponent<CCamera>();
- HShader shader = gBuiltinResources().getBuiltinShader(BuiltinShader::Standard);
- HMaterial material = Material::create(shader);
- auto io = TextureImportOptions::create();
- io->setFormat(PF_RGBA8);
- io->setGenerateMipmaps(true);
- io->setSRGB(true);
- io->setCPUCached(true);
- HTexture texture = gImporter().import<Texture>("greasy-pan-2-metal.png", io);
- SPtr<PixelData> pixelData = PixelData::create(2048, 2048, 1, PF_RGBA8);
- texture->readCachedData(*pixelData);
- Color color = pixelData->getColorAt(50, 50);
- gDebug().logDebug("Color: " + toString(color));
- auto& props = texture->getProperties();
- gDebug().logDebug("Width: " + toString(props.getWidth()));
- gDebug().logDebug("Height: " + toString(props.getHeight()));
- gDebug().logDebug("Format: " + toString(props.getFormat()));
- gDebug().logDebug("Num. mip maps: " + toString(props.getNumMipmaps()));
- material->setTexture("gAlbedoTex", texture);
- auto importOptions = MeshImportOptions::create();
- importOptions->setCPUCached(true);
- HMesh mesh = gImporter().import<Mesh>("Drone.fbx", importOptions);
- SPtr<VertexDataDesc> vertexDesc = VertexDataDesc::create();
- vertexDesc->addVertElem(VET_FLOAT3, VES_POSITION);
- SPtr<MeshData> meshData = mesh->getCachedData();
- gDebug().logDebug(toString(meshData->getNumVertices()));
- Vector<Vector3> vertices(8124);
- meshData->getVertexData(VES_POSITION, vertices.data(), vertices.size() * sizeof(Vector3));
- auto& meshProps = mesh->getProperties();
- gDebug().logDebug("Num. vertices: " + toString(meshProps.getNumVertices()));
- UINT32 numSubMeshes = meshProps.getNumSubMeshes();
- gDebug().logDebug("Num. submeshes: " + toString(numSubMeshes));
- gDebug().logDebug("Num. indices: " + toString(meshProps.getNumIndices()));
- gDebug().logDebug("Radius: " + toString(meshProps.getBounds().getSphere().getRadius()));
- HSceneObject renderableSO = SceneObject::create("3D object");
- HRenderable renderable = renderableSO->addComponent<CRenderable>();
- renderable->setMesh(mesh);
- renderable->setMaterial(material);
- renderableSO->setPosition(Vector3(0.0f, 15.0f, 47.0f));
- SPtr<RenderWindow> primaryWindow = gApplication().getPrimaryWindow();
- so->setPosition(Vector3(0.0f, 16.0f, 45.0f));
- so->lookAt(Vector3(0.0f, 15.0f, 160.0f));
- camera->setMain(true);
- HSceneObject sceneRoot = gSceneManager().getRootNode();
- HPrefab scenePrefab = Prefab::create(sceneRoot, true);
- gResources().save(scenePrefab, "scenePrefab.asset", true, true);
- //SPtr<ResourceManifest> manifest = gResources().getResourceManifest("Default");
- //ResourceManifest::save(manifest, "x.asset", "test");
- //SPtr<ResourceManifest> manifest2 = ResourceManifest::load("x.asset", "test");
- //gResources().registerResourceManifest(manifest2);
- HPrefab loadedScenePrefab = gResources().load<Prefab>("scenePrefab.asset");
- HSceneObject newSceneHierarchy = loadedScenePrefab->instantiate();
- gSceneManager().setRootNode(newSceneHierarchy);
- for (int i = 0; i < 3; i++)
- gDebug().logDebug(newSceneHierarchy->getChild(i)->getName());
- Vector3 position(BsZero);
- gDebug().logDebug(toString(position));
- if(not gInput().isButtonHeld(BC_W))
- {
- position.z += 5.0f;
- gDebug().logDebug(toString(position));
- }
- Application::instance().runMainLoop();
- Application::shutDown();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement