MLR_I_C_DeT_TMesh.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  1. //===========================================================================//
  2. // Copyright (C) Microsoft Corporation. All rights reserved. //
  3. //===========================================================================//
  4. #include "MLRHeaders.hpp"
  5. #if defined(TRACE_ENABLED) && defined(MLR_TRACE)
  6. BitTrace *MLR_I_C_DeT_TMesh_Clip;
  7. #endif
  8. //#############################################################################
  9. //######## MLRIndexedTriMesh with color no lighting and detail texture ########
  10. //#############################################################################
  11. MLR_I_C_DeT_TMesh::ClassData*
  12. MLR_I_C_DeT_TMesh::DefaultData = NULL;
  13. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  14. //
  15. void
  16. MLR_I_C_DeT_TMesh::InitializeClass()
  17. {
  18. Verify(!DefaultData);
  19. Verify(gos_GetCurrentHeap() == StaticHeap);
  20. DefaultData =
  21. new ClassData(
  22. MLR_I_C_DeT_TMeshClassID,
  23. "MidLevelRenderer::MLR_I_C_DeT_TMesh",
  24. MLR_I_DeT_TMesh::DefaultData,
  25. (MLRPrimitiveBase::Factory)&Make
  26. );
  27. Register_Object(DefaultData);
  28. #if defined(TRACE_ENABLED) && defined(MLR_TRACE)
  29. MLR_I_C_DeT_TMesh_Clip = new BitTrace("MLR_I_C_DeT_TMesh_Clip");
  30. Register_Object(MLR_I_C_DeT_TMesh_Clip);
  31. #endif
  32. }
  33. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  34. //
  35. void
  36. MLR_I_C_DeT_TMesh::TerminateClass()
  37. {
  38. Unregister_Object(DefaultData);
  39. delete DefaultData;
  40. DefaultData = NULL;
  41. #if defined(TRACE_ENABLED) && defined(MLR_TRACE)
  42. Unregister_Object(MLR_I_C_DeT_TMesh_Clip);
  43. delete MLR_I_C_DeT_TMesh_Clip;
  44. #endif
  45. }
  46. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  47. //
  48. MLR_I_C_DeT_TMesh::MLR_I_C_DeT_TMesh(
  49. ClassData *class_data,
  50. MemoryStream *stream,
  51. int version
  52. ):
  53. MLR_I_DeT_TMesh(class_data, stream, version)
  54. {
  55. Check_Pointer(this);
  56. Check_Pointer(stream);
  57. Verify(gos_GetCurrentHeap() == Heap);
  58. switch(version)
  59. {
  60. case 1:
  61. case 2:
  62. {
  63. STOP(("This class got created only after version 2 !"));
  64. }
  65. break;
  66. default:
  67. {
  68. #if COLOR_AS_DWORD
  69. MemoryStreamIO_Read(stream, &colors);
  70. #else
  71. Stuff::DynamicArrayOf<DWORD> smallColors;
  72. MemoryStreamIO_Read(stream, &smallColors);
  73. int i, len = smallColors.GetLength();
  74. colors.SetLength(len);
  75. DWORD theColor;
  76. for(i=0;i<len;i++)
  77. {
  78. theColor = smallColors[i];
  79. colors[i].blue = (theColor & 0xff) * One_Over_256;
  80. theColor = theColor>>8;
  81. colors[i].green = (theColor & 0xff) * One_Over_256;
  82. theColor = theColor>>8;
  83. colors[i].red = (theColor & 0xff) * One_Over_256;
  84. theColor = theColor>>8;
  85. colors[i].alpha = (theColor & 0xff) * One_Over_256;
  86. }
  87. #endif
  88. }
  89. break;
  90. }
  91. actualColors = &colors;
  92. }
  93. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  94. //
  95. MLR_I_C_DeT_TMesh::MLR_I_C_DeT_TMesh(ClassData *class_data):
  96. MLR_I_DeT_TMesh(class_data), colors(0)
  97. {
  98. Check_Pointer(this);
  99. Verify(gos_GetCurrentHeap() == Heap);
  100. actualColors = &colors;
  101. }
  102. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  103. //
  104. MLR_I_C_DeT_TMesh::~MLR_I_C_DeT_TMesh()
  105. {
  106. Check_Object(this);
  107. }
  108. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  109. //
  110. MLR_I_C_DeT_TMesh*
  111. MLR_I_C_DeT_TMesh::Make(
  112. MemoryStream *stream,
  113. int version
  114. )
  115. {
  116. Check_Object(stream);
  117. gos_PushCurrentHeap(Heap);
  118. MLR_I_C_DeT_TMesh *mesh = new MLR_I_C_DeT_TMesh(DefaultData, stream, version);
  119. gos_PopCurrentHeap();
  120. return mesh;
  121. }
  122. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  123. //
  124. void
  125. MLR_I_C_DeT_TMesh::Save(MemoryStream *stream)
  126. {
  127. Check_Object(this);
  128. Check_Object(stream);
  129. MLR_I_TMesh::Save(stream);
  130. #if COLOR_AS_DWORD
  131. MemoryStreamIO_Write(stream, &colors);
  132. #else
  133. Stuff::DynamicArrayOf<DWORD> smallColors;
  134. int i, len = colors.GetLength();
  135. const Stuff::RGBAColor *data = colors.GetData();
  136. smallColors.SetLength(len);
  137. for(i=0;i<len;i++)
  138. {
  139. smallColors[i] = GOSCopyColor(data+i);
  140. }
  141. MemoryStreamIO_Write(stream, &smallColors);
  142. #endif
  143. }
  144. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  145. //
  146. bool
  147. MLR_I_C_DeT_TMesh::Copy(MLR_I_C_DeT_PMesh *pMesh)
  148. {
  149. Check_Object(this);
  150. Check_Object(pMesh);
  151. int len;
  152. #if COLOR_AS_DWORD
  153. DWORD *_colors;
  154. #else
  155. RGBAColor *_colors;
  156. #endif
  157. MLR_I_DeT_TMesh::Copy(pMesh);
  158. pMesh->GetColorData(&_colors, &len);
  159. SetColorData(_colors, len);
  160. return true;
  161. }
  162. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  163. //
  164. void
  165. MLR_I_C_DeT_TMesh::Copy(
  166. MLR_I_C_TMesh *tMesh,
  167. MLRState detailState,
  168. Stuff::Scalar xOff,
  169. Stuff::Scalar yOff,
  170. Stuff::Scalar xFac,
  171. Stuff::Scalar yFac
  172. )
  173. {
  174. Check_Object(this);
  175. Check_Object(tMesh);
  176. Verify(gos_GetCurrentHeap() == Heap);
  177. int len;
  178. #if COLOR_AS_DWORD
  179. DWORD *_colors;
  180. #else
  181. RGBAColor *_colors;
  182. #endif
  183. MLR_I_DeT_TMesh::Copy(tMesh, detailState, xOff, yOff, xFac, yFac);
  184. tMesh->GetColorData(&_colors, &len);
  185. SetColorData(_colors, len);
  186. }
  187. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  188. //
  189. void
  190. MLR_I_C_DeT_TMesh::SetColorData(
  191. #if COLOR_AS_DWORD
  192. const DWORD *data,
  193. #else
  194. const RGBAColor *data,
  195. #endif
  196. int dataSize
  197. )
  198. {
  199. Check_Object(this);
  200. Check_Pointer(data);
  201. Verify(coords.GetLength() == 0 || dataSize == coords.GetLength());
  202. Verify(texCoords.GetLength() == 0 || dataSize == texCoords.GetLength());
  203. colors.AssignData(data, dataSize);
  204. }
  205. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  206. //
  207. void
  208. MLR_I_C_DeT_TMesh::GetColorData(
  209. #if COLOR_AS_DWORD
  210. DWORD **data,
  211. #else
  212. RGBAColor **data,
  213. #endif
  214. int *dataSize
  215. )
  216. {
  217. Check_Object(this);
  218. *data = colors.GetData();
  219. *dataSize = colors.GetLength();
  220. }
  221. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  222. //
  223. void
  224. MLR_I_C_DeT_TMesh::PaintMe(
  225. #if COLOR_AS_DWORD
  226. const DWORD *paintMe
  227. #else
  228. const RGBAColor *paintMe
  229. #endif
  230. )
  231. {
  232. Check_Object(this);
  233. // original color is lost !!!;
  234. int k, len = colors.GetLength();
  235. #if COLOR_AS_DWORD
  236. DWORD argb = GOSCopyColor(paintMe);
  237. for(k=0;k<len;k++)
  238. {
  239. colors[k] = argb;
  240. }
  241. #else
  242. for(k=0;k<len;k++)
  243. {
  244. colors[k] = *paintMe;
  245. }
  246. #endif
  247. }
  248. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  249. //
  250. void
  251. MLR_I_C_DeT_TMesh::TestInstance() const
  252. {
  253. Verify(IsDerivedFrom(DefaultData));
  254. }
  255. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  256. //
  257. void
  258. MLR_I_C_DeT_TMesh::HurtMe(const Stuff::LinearMatrix4D& pain, Stuff::Scalar radius)
  259. {
  260. Check_Object(this);
  261. Verify(colors.GetLength() == coords.GetLength());
  262. int i, len = colors.GetLength();
  263. Point3D painpoint;
  264. Vector3D diff;
  265. UnitVector3D up, left, forward;
  266. Scalar x, y, sqRadius = radius*radius;
  267. painpoint = pain;
  268. pain.GetLocalLeftInWorld(&left);
  269. pain.GetLocalUpInWorld(&up);
  270. pain.GetLocalForwardInWorld(&forward);
  271. if(FindBackFace(painpoint) && FindVisibleVertices())
  272. {
  273. for(i=0;i<len;i++)
  274. {
  275. if(visibleIndexedVertices[i]>0)
  276. {
  277. diff.Subtract(coords[i], painpoint);
  278. x = diff*left;
  279. y = diff*up;
  280. if((x*x + y*y) < sqRadius)
  281. {
  282. #if COLOR_AS_DWORD
  283. colors[i] |= 0xff000000;
  284. #else
  285. colors[i].alpha = 1.0f;
  286. #endif
  287. }
  288. }
  289. }
  290. }
  291. visibleIndexedVerticesKey = false;
  292. }
  293. extern DWORD gEnableTextureSort, gEnableAlphaSort;
  294. #define I_SAY_YES_TO_DETAIL_TEXTURES
  295. #undef I_SAY_YES_TO_DUAL_TEXTURES
  296. #define I_SAY_YES_TO_COLOR
  297. #undef I_SAY_YES_TO_LIGHTING
  298. #define CLASSNAME MLR_I_C_DeT_TMesh
  299. #if defined(TRACE_ENABLED) && defined(MLR_TRACE)
  300. #define SET_MLR_TMESH_CLIP() MLR_I_C_DeT_TMesh_Clip->Set()
  301. #define CLEAR_MLR_TMESH_CLIP() MLR_I_C_DeT_TMesh_Clip->Clear()
  302. #else
  303. #define SET_MLR_TMESH_CLIP()
  304. #define CLEAR_MLR_TMESH_CLIP()
  305. #endif
  306. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  307. // This include contains follwing functions:
  308. // void MLR_I_C_DeT_TMesh::TransformNoClip(Matrix4D*, GOSVertexPool*);
  309. // int MLR_I_C_DeT_TMesh::Clip(MLRClippingState, GOSVertexPool*);
  310. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  311. #include <MLR\MLRTriangleClipping.hpp>
  312. #undef I_SAY_YES_TO_DETAIL_TEXTURES
  313. #undef I_SAY_YES_TO_COLOR
  314. #undef CLASSNAME
  315. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  316. //
  317. MLR_I_C_DeT_TMesh*
  318. MidLevelRenderer::CreateIndexedTriCube_Color_NoLit_DetTex(
  319. Scalar half,
  320. MLRState *state
  321. )
  322. {
  323. #if 0
  324. gos_PushCurrentHeap(Heap);
  325. MLR_I_C_DeT_TMesh *ret = new MLR_I_C_DeT_TMesh();
  326. Register_Object(ret);
  327. Point3D *coords = new Point3D [8];
  328. Register_Object(coords);
  329. coords[0] = Point3D( half, -half, half);
  330. coords[1] = Point3D(-half, -half, half);
  331. coords[2] = Point3D( half, -half, -half);
  332. coords[3] = Point3D(-half, -half, -half);
  333. coords[4] = Point3D(-half, half, half);
  334. coords[5] = Point3D( half, half, half);
  335. coords[6] = Point3D( half, half, -half);
  336. coords[7] = Point3D(-half, half, -half);
  337. unsigned char *lengths = new unsigned char [6];
  338. Register_Pointer(lengths);
  339. int i;
  340. for(i=0;i<6;i++)
  341. {
  342. lengths[i] = 4;
  343. }
  344. ret->SetSubprimitiveLengths(lengths, 6);
  345. ret->SetCoordData(coords, 8);
  346. unsigned short *index = new unsigned short [6*4];
  347. Register_Pointer(index);
  348. index[0] = 0;
  349. index[1] = 2;
  350. index[2] = 6;
  351. index[3] = 5;
  352. index[4] = 0;
  353. index[5] = 5;
  354. index[6] = 4;
  355. index[7] = 1;
  356. index[8] = 5;
  357. index[9] = 6;
  358. index[10] = 7;
  359. index[11] = 4;
  360. index[12] = 2;
  361. index[13] = 3;
  362. index[14] = 7;
  363. index[15] = 6;
  364. index[16] = 1;
  365. index[17] = 4;
  366. index[18] = 7;
  367. index[19] = 3;
  368. index[20] = 0;
  369. index[21] = 1;
  370. index[22] = 3;
  371. index[23] = 2;
  372. ret->SetIndexData(index, 6*4);
  373. ret->FindFacePlanes();
  374. Vector2DScalar *texCoords = new Vector2DScalar[8];
  375. Register_Object(texCoords);
  376. texCoords[0] = Vector2DScalar(0.0f, 0.0f);
  377. texCoords[1] = Vector2DScalar(0.0f, 0.0f);
  378. texCoords[2] = Vector2DScalar(0.0f, 0.0f);
  379. texCoords[3] = Vector2DScalar(0.0f, 0.0f);
  380. texCoords[4] = Vector2DScalar(0.0f, 0.0f);
  381. texCoords[5] = Vector2DScalar(0.0f, 0.0f);
  382. texCoords[6] = Vector2DScalar(0.0f, 0.0f);
  383. texCoords[7] = Vector2DScalar(0.0f, 0.0f);
  384. if(state != NULL)
  385. {
  386. ret->SetReferenceState(*state);
  387. if(state->GetTextureHandle() > 0)
  388. {
  389. texCoords[0] = Vector2DScalar(0.0f, 0.0f);
  390. texCoords[1] = Vector2DScalar(1.0f, 0.0f);
  391. texCoords[2] = Vector2DScalar(0.25f, 0.25f);
  392. texCoords[3] = Vector2DScalar(0.75f, 0.25f);
  393. texCoords[4] = Vector2DScalar(1.0f, 1.0f);
  394. texCoords[5] = Vector2DScalar(0.0f, 1.0f);
  395. texCoords[6] = Vector2DScalar(0.25f, 0.75f);
  396. texCoords[7] = Vector2DScalar(0.75f, 0.75f);
  397. }
  398. }
  399. ret->SetTexCoordData(texCoords, 8);
  400. Unregister_Object(texCoords);
  401. delete [] texCoords;
  402. Unregister_Pointer(index);
  403. delete [] index;
  404. Unregister_Pointer(lengths);
  405. delete [] lengths;
  406. Unregister_Object(coords);
  407. delete [] coords;
  408. gos_PopCurrentHeap();
  409. return ret;
  410. #endif
  411. return NULL;
  412. }
  413. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  414. //
  415. MLRShape*
  416. MidLevelRenderer::CreateIndexedTriIcosahedron_Color_NoLit_DetTex(
  417. IcoInfo& icoInfo,
  418. MLRState *state,
  419. MLRState *stateDet
  420. )
  421. {
  422. gos_PushCurrentHeap(Heap);
  423. MLRShape *ret = new MLRShape(20);
  424. Register_Object(ret);
  425. int i, j, k;
  426. long nrTri = (long) ceil (icoInfo.all * pow (4.0f, icoInfo.depth));
  427. Point3D v[3];
  428. if(3*nrTri >= Limits::Max_Number_Vertices_Per_Mesh)
  429. {
  430. nrTri = Limits::Max_Number_Vertices_Per_Mesh/3;
  431. }
  432. Point3D *coords = new Point3D [nrTri*3];
  433. Register_Pointer(coords);
  434. Point3D *collapsedCoords = NULL;
  435. if(icoInfo.indexed==true)
  436. {
  437. collapsedCoords = new Point3D [nrTri*3];
  438. Register_Pointer(collapsedCoords);
  439. }
  440. unsigned short *index = new unsigned short [nrTri*3];
  441. Register_Pointer(index);
  442. Vector2DScalar *texCoords = new Vector2DScalar[nrTri*3];
  443. Register_Pointer(texCoords);
  444. RGBAColor *colors = new RGBAColor[nrTri*3];
  445. Register_Pointer(colors);
  446. int uniquePoints = 0;
  447. for (k=0;k<20;k++)
  448. {
  449. triDrawn = 0;
  450. MLR_I_C_DeT_TMesh *mesh = new MLR_I_C_DeT_TMesh();
  451. Register_Object(mesh);
  452. // setup vertex position information
  453. for (j=0;j<3;j++)
  454. {
  455. v[j].x = vdata[tindices[k][j]][0];
  456. v[j].y = vdata[tindices[k][j]][1];
  457. v[j].z = vdata[tindices[k][j]][2];
  458. }
  459. subdivide (coords, v[0], v[1], v[2], icoInfo.depth, nrTri, icoInfo.radius);
  460. mesh->SetSubprimitiveLengths(NULL, nrTri);
  461. if(icoInfo.indexed==true)
  462. {
  463. uniquePoints = 1;
  464. collapsedCoords[0] = coords[0];
  465. index[0] = 0;
  466. for(i=1;i<nrTri*3;i++)
  467. {
  468. for(j=0;j<uniquePoints;j++)
  469. {
  470. if(coords[i] == collapsedCoords[j])
  471. {
  472. break;
  473. }
  474. }
  475. if(j==uniquePoints)
  476. {
  477. collapsedCoords[uniquePoints++] = coords[i];
  478. }
  479. index[i] = static_cast<unsigned short>(j);
  480. }
  481. mesh->SetCoordData(collapsedCoords, uniquePoints);
  482. }
  483. else
  484. {
  485. uniquePoints = nrTri*3;
  486. for(i=0;i<nrTri*3;i++)
  487. {
  488. index[i] = static_cast<unsigned short>(i);
  489. }
  490. mesh->SetCoordData(coords, nrTri*3);
  491. }
  492. mesh->SetIndexData(index, nrTri*3);
  493. mesh->FindFacePlanes();
  494. if(state == NULL)
  495. {
  496. for(i=0;i<uniquePoints;i++)
  497. {
  498. texCoords[i] = Vector2DScalar(0.0f, 0.0f);
  499. }
  500. }
  501. else
  502. {
  503. state->SetMultiTextureMode(MLRState::MultiTextureLightmapMode);
  504. mesh->SetReferenceState(*state);
  505. state->SetMultiTextureMode(MLRState::MultiTextureOffMode);
  506. if(state->GetTextureHandle() > 0)
  507. {
  508. if(icoInfo.indexed==true)
  509. {
  510. for(i=0;i<uniquePoints;i++)
  511. {
  512. texCoords[i] =
  513. Vector2DScalar(
  514. (1.0f + collapsedCoords[i].x)/2.0f,
  515. (1.0f + collapsedCoords[i].y)/2.0f
  516. );
  517. }
  518. }
  519. else
  520. {
  521. for(i=0;i<nrTri;i++)
  522. {
  523. texCoords[3*i] =
  524. Vector2DScalar(
  525. (1.0f + coords[3*i].x)/2.0f,
  526. (1.0f + coords[3*i].y)/2.0f
  527. );
  528. texCoords[3*i+1] =
  529. Vector2DScalar(
  530. (1.0f + coords[3*i+1].x)/2.0f,
  531. (1.0f + coords[3*i+1].y)/2.0f
  532. );
  533. texCoords[3*i+2] =
  534. Vector2DScalar(
  535. (1.0f + coords[3*i+2].x)/2.0f,
  536. (1.0f + coords[3*i+2].y)/2.0f
  537. );
  538. }
  539. }
  540. }
  541. else
  542. {
  543. for(i=0;i<uniquePoints;i++)
  544. {
  545. texCoords[i] = Vector2DScalar(0.0f, 0.0f);
  546. }
  547. }
  548. }
  549. mesh->SetTexCoordData(texCoords, uniquePoints);
  550. if(icoInfo.indexed==true)
  551. {
  552. for(i=0;i<uniquePoints;i++)
  553. {
  554. colors[i] =
  555. RGBAColor(
  556. (1.0f + collapsedCoords[i].x)/2.0f,
  557. (1.0f + collapsedCoords[i].y)/2.0f,
  558. (1.0f + collapsedCoords[i].z)/2.0f,
  559. 1.0f
  560. );
  561. }
  562. }
  563. else
  564. {
  565. for(i=0;i<uniquePoints;i++)
  566. {
  567. colors[i] =
  568. RGBAColor(
  569. (1.0f + coords[i].x)/2.0f,
  570. (1.0f + coords[i].y)/2.0f,
  571. (1.0f + coords[i].z)/2.0f,
  572. 1.0f
  573. );
  574. }
  575. }
  576. mesh->SetColorData(colors, uniquePoints);
  577. mesh->SetDetailData(0.0f, 0.0f, 16.0f, 16.0f, 50.0f, 70.0f);
  578. mesh->SetReferenceState(*stateDet, 1);
  579. ret->Add(mesh);
  580. mesh->DetachReference();
  581. }
  582. Unregister_Pointer(colors);
  583. delete [] colors;
  584. Unregister_Pointer(texCoords);
  585. delete [] texCoords;
  586. Unregister_Pointer(index);
  587. delete [] index;
  588. if(icoInfo.indexed==true)
  589. {
  590. Unregister_Pointer(collapsedCoords);
  591. delete [] collapsedCoords;
  592. }
  593. Unregister_Pointer(coords);
  594. delete [] coords;
  595. gos_PopCurrentHeap();
  596. return ret;
  597. }