Advertisement
Amourreux

assimp model importing

Jul 17th, 2013
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -(void) setup3dObjectsWithThread
  2. {
  3.     /*
  4.     dispatch_queue_t queue = dispatch_queue_create("", NULL);
  5.     dispatch_async(queue, ^{
  6.         //code to be executed in the background
  7.         NSString* dataPath = [[NSBundle mainBundle] resourcePath];        
  8.         NSString * m1 = @"Apple.3ds";
  9.         model1 = new REVuModel([dataPath UTF8String], [m1 UTF8String]) ;
  10.        
  11.         if(model1->isValid)
  12.         {
  13.             model1->TranslateTo(0, 0, 0);
  14.             model1->ScaleUniformTo(0.4);
  15.             model1->RotateTo(0, 0, 0);
  16.             model1->Alpha(1.0);
  17.             model1->SwitchLight(true);
  18.         }
  19.        
  20.         dispatch_async(dispatch_get_main_queue(), ^{
  21.             //code to be executed on the main thread when background task is finished
  22.             NSLog(@"Ending Point of loading models %@ and start of main_queue", queue);
  23.         });
  24.     });*/
  25.    
  26.     NSThread* myThread = [[NSThread alloc] initWithTarget:self
  27.                                                  selector:@selector(myThread_MainMethod:)
  28.                                                    object:nil];
  29.     [myThread start];
  30. }
  31.  
  32. -(void) myThread_MainMethod:(id)sender
  33. {
  34.     NSString* dataPath = [[NSBundle mainBundle] resourcePath];
  35.     NSString * m1 = @"Apple.3ds";
  36.     model1 = new REVuModel([dataPath UTF8String], [m1 UTF8String]) ;
  37.    
  38.     if(model1->isValid)
  39.     {
  40.         model1->TranslateTo(0, 0, 0);
  41.         model1->ScaleUniformTo(0.4);
  42.         model1->RotateTo(0, 0, 0);
  43.         model1->Alpha(1.0);
  44.         model1->SwitchLight(true);
  45.     }
  46. }
  47.  
  48. REVuModel::REVuModel(const char *dataPath, const char * modelName)
  49. {
  50.     rootPath.Set(dataPath);
  51.     rootPath.Append("/");
  52.     aiString  modelPath = rootPath;
  53.     modelPath.Append("/");
  54.     modelPath.Append(modelName);
  55.    
  56.     scene = NULL;
  57.     isValid = false;
  58.    
  59.     //DEFAULTS
  60.     _scale = vec3(1.0 , 1.0, 1.0);
  61.     _position = vec3(0.0, 0.0, 0.0);
  62.     _rotation = vec3(kInitalRoation, 0.0, 0.0);
  63.     _lightDirection = vec3(0.0, 0., -1.0); //FRONT & ABOVE
  64.     _alpha =1.0;
  65.     _customTexture = false;
  66.     _customMaterial = false;
  67.  
  68.     Assimp::Importer* importer =  new Assimp::Importer();
  69.    
  70.     printf("\nASSIMP Version %i.%i.%i\n", aiGetVersionMajor(), aiGetVersionMinor(),aiGetVersionRevision());
  71.     //printf("FREEIMAGE Version %s \n\n", FreeImage_GetVersion());
  72.    
  73.     scene = importer->ReadFile(modelPath.data,aiProcessPreset_TargetRealtime_MaxQuality);
  74.    
  75.     if(!scene || !initShaders())
  76.     {
  77.         isValid = false;
  78.         printf("nASSIMP model loader: failed to load %s \n\n", modelName);
  79.     }
  80.     else
  81.     {
  82.         aiVector3D scene_min, scene_max;
  83.         getBoundingBoxWithMinVector(&scene_min, &scene_max);
  84.        
  85.         normalizedScale = scene_max.x-scene_min.x;
  86.         normalizedScale = aisgl_max(scene_max.y - scene_min.y,normalizedScale);
  87.         normalizedScale = aisgl_max(scene_max.z - scene_min.z,normalizedScale);
  88.         normalizedScale = 1.f / normalizedScale * 255; //????
  89.        
  90.         _scale = vec3(normalizedScale , normalizedScale, normalizedScale);
  91.         loadGLResources();
  92.         isValid = true;
  93.         printf("nASSIMP model loader: %s loaded \n\n", modelName);
  94.     }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement