Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.83 KB | None | 0 0
  1. int api_yaf(){ // for test
  2. //-----
  3. //---
  4. double colR=0.4,colG=0.5,colB=0.9;
  5. //---
  6. double lightR=0.9, lightG=0.9, lightB=0.9;
  7. //---
  8. yafrayInterface_t *yi = new yafrayInterface_t();
  9.  
  10. string mypath("h:/Mydemo/plugins");
  11.  
  12. yi->loadPlugins(mypath.c_str()); //you may call loadPlugins with additional paths
  13.  
  14. //first of all, start scene
  15. cout << "starting scene" << endl;
  16. yi->startScene();
  17.  
  18. //create a simple texture
  19. yi->paramsClearAll();
  20. string texName("rgb_cube1");
  21. yi->paramsSetString("type", "rgb_cube");
  22. yi->createTexture(texName.c_str());
  23.  
  24. //create simple material
  25. yi->paramsClearAll();
  26. yi->paramsSetString("type", "shinydiffusemat");
  27.  
  28. yi->paramsPushList();
  29. yi->paramsSetString("type", "texture_mapper");
  30. yi->paramsSetString("name", "rgbcube_mapper");
  31. yi->paramsSetString("texco", "uv");
  32. yi->paramsSetString("texture", texName.c_str() );
  33. yi->paramsEndList();
  34.  
  35. yi->paramsSetString("diffuse_shader", "rgbcube_mapper");
  36.  
  37. material_t *mat = yi->createMaterial("myMat");
  38.  
  39. if(! yi->startGeometry() ) cout << "error occured on startGeometry\n";
  40. unsigned int id = 0;
  41. //create a cube with UVs
  42. yi->startTriMesh(id, 8, 12, false, true);
  43. //vertices:
  44. const double size = 0.5;
  45. int a,b,c,d,e,f,g,h;
  46. a = yi->addVertex(size,size,size);
  47. b = yi->addVertex(size,-size,size);
  48. c = yi->addVertex(size,-size,-size);
  49. d = yi->addVertex(size,size,-size);
  50.  
  51. e = yi->addVertex(-size,size,-size);
  52. f = yi->addVertex(-size,-size,-size);
  53. g = yi->addVertex(-size,-size,size);
  54. h = yi->addVertex(-size,size,size);
  55. //UVs:
  56. int ua,ub,uc,ud,ue,uf,ug,uh,ui,uj;
  57. ua = yi->addUV(0.0, 0.0);
  58. ub = yi->addUV(0.0, 0.25);
  59. uc = yi->addUV(0.0, 0.5);
  60. ud = yi->addUV(0.0, 0.75);
  61. ue = yi->addUV(0.0, 1.0);
  62.  
  63. uf = yi->addUV(1.0, 0.0);
  64. ug = yi->addUV(1.0, 0.25);
  65. uh = yi->addUV(1.0, 0.5);
  66. ui = yi->addUV(1.0, 0.75);
  67. uj = yi->addUV(1.0, 1.0);
  68. //faces:
  69. yi->addTriangle(a, b, c, uf, ug, ub, mat);
  70. yi->addTriangle(c, d, a, ub, ua, uf, mat);
  71. // left N.set(-1,0,0);
  72. yi->addTriangle(e, f, g, ud, uc, uh, mat);
  73. yi->addTriangle(g, h, e, uh, ui, ud, mat);
  74. // front N.set(0,-1,0);
  75. yi->addTriangle(g, f, c, uh, uc, ub, mat);
  76. yi->addTriangle(g, c, b, uh, ub, ug, mat);
  77. // back N.set(0,1,0);
  78. yi->addTriangle(a, e, h, uj, ud, ui, mat);
  79. yi->addTriangle(e, a, d, ud, uj, ue, mat);
  80. // top N.set(0,0,1);
  81. yi->addTriangle(a, g, b, uf, ue, ua, mat);
  82. yi->addTriangle(g, a, h, ue, uf, uj, mat);
  83. // bottom N.set(0,0,-1);
  84. yi->addTriangle(d, c, f, uf, ua, ue, mat);
  85. yi->addTriangle(f, e, d, ue, uj, uf, mat);
  86.  
  87. yi->endTriMesh();
  88. yi->endGeometry();
  89.  
  90. // create an integrator
  91. yi->paramsClearAll();
  92. yi->paramsSetString("type", "directlighting");
  93. integrator_t* integrator = yi->createIntegrator("myDL");
  94. if(!integrator) exit(1);
  95.  
  96. // create a volume integrator
  97. yi->paramsClearAll();
  98. yi->paramsSetString("type", "none");
  99. integrator = yi->createIntegrator("volintegr");
  100. if(!integrator) exit(1);
  101.  
  102. // create light
  103. yi->paramsClearAll();
  104. yi->paramsSetString("type", "directional");
  105. yi->paramsSetPoint("direction", -0.3, -0.3, 0.8 );
  106. yi->paramsSetColor("color", colR, colG, colB );
  107. yi->paramsSetFloat("power", 1.0 );
  108. yi->createLight("myDirectional");
  109.  
  110. // create background
  111. yi->paramsClearAll();
  112. yi->paramsSetString("type", "constant");
  113.  
  114. yi->paramsSetColor("color", colR, colG, colB );
  115. yi->createBackground("world_background");
  116.  
  117. // create camera
  118. yi->paramsClearAll();
  119. yi->paramsSetString("type", "perspective");
  120. yi->paramsSetPoint("from", -1.5, -2.0, 1.7 );
  121. yi->paramsSetPoint("to", 0, 0, 0.2 );
  122. yi->paramsSetPoint("up", -1.5, -2.0, 2.7 );
  123. yi->paramsSetInt("resx", 640);
  124. yi->paramsSetInt("resy", 480);
  125. yi->paramsSetFloat("focal", 1.4);
  126. yi->createCamera("camera");
  127. //image film:
  128.  
  129. //render
  130. yi->paramsClearAll();
  131. yi->paramsSetString("camera_name", "camera");
  132. yi->paramsSetString("integrator_name", "myDL");
  133. yi->paramsSetString("volintegrator_name", "volintegr");
  134. yi->paramsSetInt("threads", -1);
  135. yi->paramsSetInt("AA_minsamples", 4);
  136. yi->paramsSetFloat("AA_pixelwidth", 1.5);
  137. yi->paramsSetString("filter_type", "mitchell");
  138. yi->paramsSetInt("width", 640);
  139. yi->paramsSetInt("height", 480);
  140. yi->paramsSetString("background_name", "world_background");
  141. /*
  142. // image file
  143. string format = "tga";
  144. string outName = "test." + format;
  145. string outPath = outName;
  146. yi->paramsSetString("type", "tga");
  147. imageHandler_t *ih = yi->createImageHandler("outFile");
  148. colorOutput_t *output = new imageOutput_t(ih, "test.tga", 0, 0); // the problem..
  149.  
  150. */
  151. // create output
  152. colorOutput_t *output = NULL;
  153.  
  154. yi->paramsClearAll();
  155. yi->paramsSetString("type", "tga");
  156. yi->paramsSetInt("width", 640);
  157. yi->paramsSetInt("height", 480);
  158. imageHandler_t *ih = yi->createImageHandler("outFile");
  159.  
  160. if(ih)
  161. {
  162. output = new imageOutput_t(ih,"test.tga", 0, 0);
  163. if(!output) return 1;
  164. }
  165. else return 1;
  166.  
  167.  
  168. yi->render(*output);
  169. yi->clearAll();
  170. delete yi;
  171.  
  172.  
  173. //save tga file:
  174. output->flush();
  175.  
  176. return 0;
  177.  
  178. //---
  179. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement