Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "IIndexedMesh.h"
- #include <assimp/Importer.hpp> // C++ importer interface
- #include <assimp/scene.h> // Output data structure
- #include <assimp/postprocess.h> // Post processing flags
- #pragma comment(lib, "assimp.lib")
- void CmdAssimpTest(IConsoleCmdArgs *pArgs)
- {
- auto pFile = pArgs->GetArg(1);
- // Create an instance of the Importer class
- Assimp::Importer importer;
- // And have it read the given file with some example postprocessing
- // Usually - if speed is not the most important aspect for you - you'll
- // propably to request more postprocessing than we do in this example.
- const aiScene* scene = importer.ReadFile( pFile,
- aiProcess_CalcTangentSpace |
- aiProcess_Triangulate |
- //aiProcess_JoinIdenticalVertices |
- aiProcess_GenNormals |
- aiProcess_SortByPType);
- // If the import failed, report it
- if( !scene)
- {
- CryLogAlways( importer.GetErrorString());
- return;
- }
- // Now we can access the file's contents.
- if (scene->HasMeshes())
- {
- for (int i = 0; i < scene->mNumMeshes; ++i)
- {
- auto assimp_mesh = scene->mMeshes[i];
- auto obj = gEnv->p3DEngine->CreateStatObj();
- obj->AddRef();
- obj->Refresh(FRO_GEOMETRY);
- auto imesh = obj->GetIndexedMesh(true);
- CMesh mesh;
- mesh.SetVertexCount( assimp_mesh->mNumVertices );
- mesh.SetFacesCount( assimp_mesh->mNumFaces );
- //mesh.SetIndexCount( assimp_mesh->mFaces->mNumIndices );
- auto vertices = mesh.GetStreamPtr<Vec3>(CMesh::POSITIONS);
- auto normals = mesh.GetStreamPtr<Vec3>(CMesh::NORMALS);
- //auto indices = mesh.GetStreamPtr<uint16>(CMesh::INDICES);
- for (int i = 0; i < assimp_mesh->mNumVertices; ++i)
- {
- vertices[i] = Vec3(assimp_mesh->mVertices[i].x, assimp_mesh->mVertices[i].y, assimp_mesh->mVertices[i].z);
- }
- for (int i = 0; i < assimp_mesh->mNumVertices; ++i)
- {
- normals[i] = Vec3(assimp_mesh->mNormals[i].x, assimp_mesh->mNormals[i].y, assimp_mesh->mNormals[i].z);
- }
- /*for (int i = 0; i < assimp_mesh->mFaces->mNumIndices; ++i)
- {
- indices[i] = assimp_mesh->mFaces->mIndices[i];
- }*/
- SMeshSubset sub;
- sub.nFirstIndexId = 0;
- sub.nFirstVertId = 0;
- //sub.nNumIndices = assimp_mesh->mFaces->mNumIndices;
- sub.nNumVerts = assimp_mesh->mNumVertices;
- mesh.m_subsets.push_back( sub );
- mesh.m_bbox = obj->GetAABB();
- const char *error;
- if (!mesh.Validate(&error))
- {
- CryLogAlways("mesh validation error: %s", error);
- }
- imesh->SetMesh(mesh);
- imesh->Invalidate();
- auto rmesh = obj->GetRenderMesh();
- rmesh->SetMesh(mesh);
- SEntitySpawnParams params;
- params.pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass("BasicEntity");
- params.vPosition = Vec3(10,10,1);
- auto ent = gEnv->pEntitySystem->SpawnEntity(params);
- ent->Activate (true);
- {
- SEntityPhysicalizeParams params;
- params.type = PE_RIGID;
- params.nSlot = -1;
- params.mass = 50;
- params.density = 1.0f;
- ent->Physicalize(params);
- }
- int slotCount = ent->GetSlotCount();
- int slotId = ent->SetStatObj(obj, -1, false);
- int slotCount2 = ent->GetSlotCount();
- }
- }
- // We're done. Everything will be cleaned up by the importer destructor
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement