Advertisement
AVasK

1

Nov 24th, 2017
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.85 KB | None | 0 0
  1. /
  2. //  main.cpp
  3. //  3d_test
  4. //
  5.  
  6. #include <iostream>
  7. #include "assimp/Importer.hpp"
  8. #include "assimp/cimport.h"
  9. #include "assimp/scene.h"
  10. #include "assimp/postprocess.h"
  11. // Includes for Embree:
  12. #include "embree2/rtcore.h"
  13. #include "embree2/rtcore_ray.h"
  14. // Embree boost:
  15. #include <xmmintrin.h>
  16. #include <pmmintrin.h>
  17. // Vectors:
  18. #include <vector>
  19.  
  20. using std::vector;
  21.  
  22.  
  23. class Buffer {
  24.     vector<aiVector3D> vertices;
  25.     vector<int> indices;
  26. };
  27.  
  28. void importer() {
  29.     Assimp::Importer importer;
  30.     const char * path = "model.obj";
  31.     auto scene = importer.ReadFile(path, aiProcess_Triangulate
  32.                                | aiProcess_GenSmoothNormals | aiProcess_FlipUVs | aiProcess_JoinIdenticalVertices);
  33.  
  34.  
  35.     // Keeping the data here for now
  36.     unsigned int num_of_vertices = 0;
  37.     unsigned int num_of_faces = 0;
  38.  
  39.     if (!scene) {
  40.         printf("WTF, MAN?\n");
  41.     }
  42.     else {
  43.    
  44.         auto pmesh = scene -> mMeshes;
  45.         auto mesh = *pmesh;
  46.        
  47.         auto geomID = rtcNewTriangleMesh(new_scene, RTC_GEOMETRY_STATIC, mesh->mNumFaces, mesh->mNumVertices);
  48.        
  49.         auto num_of_mashes = scene -> mNumMeshes;
  50.         auto meshes = scene -> mMeshes;
  51.         for (; pmesh < meshes + num_of_mashes; pmesh++) {
  52.             auto mesh = *pmesh;
  53.             auto vertices = mesh->mVertices;
  54.             num_of_vertices = mesh->mNumVertices;
  55.             //auto num_of_faces = mesh->mNumFaces;
  56.             num_of_faces = mesh->mNumFaces;
  57.             auto faces = mesh->mFaces;
  58.             for (auto face = faces; face < faces + num_of_faces; face++) {
  59.                 auto idx = face->mIndices;
  60.                 auto p1 = vertices[idx[0]];
  61.                 auto p2 = vertices[idx[1]];
  62.                 auto p3 = vertices[idx[2]];
  63.                 printf("%u : {%.2f, %.2f, %.2f}, %u : {%.2f, %.2f, %.2f}, %u : {%.2f, %.2f, %.2f}\n",
  64.                        idx[0], p1.x, p1.y, p1.z, idx[1], p2.x, p2.y, p2.z, idx[2], p3.x, p3.y, p3.z);
  65.             }
  66.         }
  67.     }
  68. }
  69.  
  70.  
  71.  
  72. int main(int argc, const char * argv[]) {
  73.     // Embree boost enabled:
  74.     _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON);
  75.     _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON);
  76.    
  77.     importer();
  78.     // Object imported
  79.     // Setting up scene:
  80.     //Init app startup:
  81.     RTCDevice device = rtcNewDevice(NULL);
  82.    
  83.     // Create scene
  84.     RTCScene new_scene = rtcDeviceNewScene(device, RTC_SCENE_STATIC, RTC_INTERSECT1);
  85.     // Add geometry
  86.     // Construct of type: unsigned int geomID = rtcNewTriangleMesh(main_scene, numTriangles, numVertices, 1);
  87.     //unsigned int geomID = rtcNewTriangleMesh(new_scene, size_t(num_of_faces), size_t(num_of_vertices), 1);
  88.    
  89.     // Commit changes
  90.     rtcCommit(new_scene);
  91.     // Raytrace
  92.    
  93.     // Cleanup
  94.     rtcDeleteScene(new_scene);
  95.     rtcDeleteDevice(device);
  96.    
  97.    
  98.    
  99.    
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement