Mesh.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections.Generic;
  29. using System.IO;
  30. using System.Runtime.InteropServices;
  31. using OpenSim.Region.PhysicsModules.SharedBase;
  32. using PrimMesher;
  33. using OpenMetaverse;
  34. using System.Runtime.Serialization;
  35. using System.Runtime.Serialization.Formatters.Binary;
  36. namespace OpenSim.Region.PhysicsModule.ubODEMeshing
  37. {
  38. public class MeshBuildingData
  39. {
  40. private class vertexcomp : IEqualityComparer<Vertex>
  41. {
  42. public bool Equals(Vertex v1, Vertex v2)
  43. {
  44. if (v1.X == v2.X && v1.Y == v2.Y && v1.Z == v2.Z)
  45. return true;
  46. else
  47. return false;
  48. }
  49. public int GetHashCode(Vertex v)
  50. {
  51. int a = v.X.GetHashCode();
  52. int b = v.Y.GetHashCode();
  53. int c = v.Z.GetHashCode();
  54. return (a << 16) ^ (b << 8) ^ c;
  55. }
  56. }
  57. public Dictionary<Vertex, int> m_vertices;
  58. public List<Triangle> m_triangles;
  59. public float m_obbXmin;
  60. public float m_obbXmax;
  61. public float m_obbYmin;
  62. public float m_obbYmax;
  63. public float m_obbZmin;
  64. public float m_obbZmax;
  65. public Vector3 m_centroid;
  66. public int m_centroidDiv;
  67. public MeshBuildingData()
  68. {
  69. vertexcomp vcomp = new vertexcomp();
  70. m_vertices = new Dictionary<Vertex, int>(vcomp);
  71. m_triangles = new List<Triangle>();
  72. m_centroid = Vector3.Zero;
  73. m_centroidDiv = 0;
  74. m_obbXmin = float.MaxValue;
  75. m_obbXmax = float.MinValue;
  76. m_obbYmin = float.MaxValue;
  77. m_obbYmax = float.MinValue;
  78. m_obbZmin = float.MaxValue;
  79. m_obbZmax = float.MinValue;
  80. }
  81. }
  82. [Serializable()]
  83. public class Mesh : IMesh
  84. {
  85. float[] vertices;
  86. int[] indexes;
  87. Vector3 m_obb;
  88. Vector3 m_obboffset;
  89. [NonSerialized()]
  90. MeshBuildingData m_bdata;
  91. [NonSerialized()]
  92. GCHandle vhandler;
  93. [NonSerialized()]
  94. GCHandle ihandler;
  95. [NonSerialized()]
  96. IntPtr m_verticesPtr = IntPtr.Zero;
  97. [NonSerialized()]
  98. IntPtr m_indicesPtr = IntPtr.Zero;
  99. [NonSerialized()]
  100. int m_vertexCount = 0;
  101. [NonSerialized()]
  102. int m_indexCount = 0;
  103. public int RefCount { get; set; }
  104. public AMeshKey Key { get; set; }
  105. public Mesh(bool forbuild)
  106. {
  107. if(forbuild)
  108. m_bdata = new MeshBuildingData();
  109. m_obb = new Vector3(0.5f, 0.5f, 0.5f);
  110. m_obboffset = Vector3.Zero;
  111. }
  112. public Mesh Scale(Vector3 scale)
  113. {
  114. if (m_verticesPtr == null || m_indicesPtr == null)
  115. return null;
  116. Mesh result = new Mesh(false);
  117. float x = scale.X;
  118. float y = scale.Y;
  119. float z = scale.Z;
  120. float tmp;
  121. tmp = m_obb.X * x;
  122. if(tmp < 0.0005f)
  123. tmp = 0.0005f;
  124. result.m_obb.X = tmp;
  125. tmp = m_obb.Y * y;
  126. if(tmp < 0.0005f)
  127. tmp = 0.0005f;
  128. result.m_obb.Y = tmp;
  129. tmp = m_obb.Z * z;
  130. if(tmp < 0.0005f)
  131. tmp = 0.0005f;
  132. result.m_obb.Z = tmp;
  133. result.m_obboffset.X = m_obboffset.X * x;
  134. result.m_obboffset.Y = m_obboffset.Y * y;
  135. result.m_obboffset.Z = m_obboffset.Z * z;
  136. result.vertices = new float[vertices.Length];
  137. int j = 0;
  138. for (int i = 0; i < m_vertexCount; i++)
  139. {
  140. result.vertices[j] = vertices[j] * x;
  141. j++;
  142. result.vertices[j] = vertices[j] * y;
  143. j++;
  144. result.vertices[j] = vertices[j] * z;
  145. j++;
  146. }
  147. result.indexes = new int[indexes.Length];
  148. indexes.CopyTo(result.indexes,0);
  149. result.pinMemory();
  150. return result;
  151. }
  152. public Mesh Clone()
  153. {
  154. Mesh result = new Mesh(false);
  155. if (m_bdata != null)
  156. {
  157. result.m_bdata = new MeshBuildingData();
  158. foreach (Triangle t in m_bdata.m_triangles)
  159. {
  160. result.Add(new Triangle(t.v1.Clone(), t.v2.Clone(), t.v3.Clone()));
  161. }
  162. result.m_bdata.m_centroid = m_bdata.m_centroid;
  163. result.m_bdata.m_centroidDiv = m_bdata.m_centroidDiv;
  164. result.m_bdata.m_obbXmin = m_bdata.m_obbXmin;
  165. result.m_bdata.m_obbXmax = m_bdata.m_obbXmax;
  166. result.m_bdata.m_obbYmin = m_bdata.m_obbYmin;
  167. result.m_bdata.m_obbYmax = m_bdata.m_obbYmax;
  168. result.m_bdata.m_obbZmin = m_bdata.m_obbZmin;
  169. result.m_bdata.m_obbZmax = m_bdata.m_obbZmax;
  170. }
  171. result.m_obb = m_obb;
  172. result.m_obboffset = m_obboffset;
  173. return result;
  174. }
  175. public void addVertexLStats(Vertex v)
  176. {
  177. float x = v.X;
  178. float y = v.Y;
  179. float z = v.Z;
  180. m_bdata.m_centroid.X += x;
  181. m_bdata.m_centroid.Y += y;
  182. m_bdata.m_centroid.Z += z;
  183. m_bdata.m_centroidDiv++;
  184. if (x > m_bdata.m_obbXmax)
  185. m_bdata.m_obbXmax = x;
  186. if (x < m_bdata.m_obbXmin)
  187. m_bdata.m_obbXmin = x;
  188. if (y > m_bdata.m_obbYmax)
  189. m_bdata.m_obbYmax = y;
  190. if (y < m_bdata.m_obbYmin)
  191. m_bdata.m_obbYmin = y;
  192. if (z > m_bdata.m_obbZmax)
  193. m_bdata.m_obbZmax = z;
  194. if (z < m_bdata.m_obbZmin)
  195. m_bdata.m_obbZmin = z;
  196. }
  197. public void Add(Triangle triangle)
  198. {
  199. if (m_indicesPtr != IntPtr.Zero || m_verticesPtr != IntPtr.Zero)
  200. throw new NotSupportedException("Attempt to Add to a pinned Mesh");
  201. triangle.v1.X = (float)Math.Round(triangle.v1.X, 6);
  202. triangle.v1.Y = (float)Math.Round(triangle.v1.Y, 6);
  203. triangle.v1.Z = (float)Math.Round(triangle.v1.Z, 6);
  204. triangle.v2.X = (float)Math.Round(triangle.v2.X, 6);
  205. triangle.v2.Y = (float)Math.Round(triangle.v2.Y, 6);
  206. triangle.v2.Z = (float)Math.Round(triangle.v2.Z, 6);
  207. triangle.v3.X = (float)Math.Round(triangle.v3.X, 6);
  208. triangle.v3.Y = (float)Math.Round(triangle.v3.Y, 6);
  209. triangle.v3.Z = (float)Math.Round(triangle.v3.Z, 6);
  210. if ((triangle.v1.X == triangle.v2.X && triangle.v1.Y == triangle.v2.Y && triangle.v1.Z ==
  211. triangle.v2.Z)
  212. || (triangle.v1.X == triangle.v3.X && triangle.v1.Y == triangle.v3.Y && triangle.v1.Z ==
  213. triangle.v3.Z)
  214. || (triangle.v2.X == triangle.v3.X && triangle.v2.Y == triangle.v3.Y && triangle.v2.Z ==
  215. triangle.v3.Z)
  216. )
  217. {
  218. return;
  219. }
  220. if (m_bdata.m_vertices.Count == 0)
  221. {
  222. m_bdata.m_centroidDiv = 0;
  223. m_bdata.m_centroid = Vector3.Zero;
  224. }
  225. if (!m_bdata.m_vertices.ContainsKey(triangle.v1))
  226. {
  227. m_bdata.m_vertices[triangle.v1] = m_bdata.m_vertices.Count;
  228. addVertexLStats(triangle.v1);
  229. }
  230. if (!m_bdata.m_vertices.ContainsKey(triangle.v2))
  231. {
  232. m_bdata.m_vertices[triangle.v2] = m_bdata.m_vertices.Count;
  233. addVertexLStats(triangle.v2);
  234. }
  235. if (!m_bdata.m_vertices.ContainsKey(triangle.v3))
  236. {
  237. m_bdata.m_vertices[triangle.v3] = m_bdata.m_vertices.Count;
  238. addVertexLStats(triangle.v3);
  239. }
  240. m_bdata.m_triangles.Add(triangle);
  241. }
  242. public Vector3 GetCentroid()
  243. {
  244. return m_obboffset;
  245. }
  246. public Vector3 GetOBB()
  247. {
  248. return m_obb;
  249. /*
  250. float x, y, z;
  251. if (m_bdata.m_centroidDiv > 0)
  252. {
  253. x = (m_bdata.m_obbXmax - m_bdata.m_obbXmin) * 0.5f;
  254. y = (m_bdata.m_obbYmax - m_bdata.m_obbYmin) * 0.5f;
  255. z = (m_bdata.m_obbZmax - m_bdata.m_obbZmin) * 0.5f;
  256. }
  257. else // ??
  258. {
  259. x = 0.5f;
  260. y = 0.5f;
  261. z = 0.5f;
  262. }
  263. return new Vector3(x, y, z);
  264. */
  265. }
  266. public int numberVertices()
  267. {
  268. return m_bdata.m_vertices.Count;
  269. }
  270. public int numberTriangles()
  271. {
  272. return m_bdata.m_triangles.Count;
  273. }
  274. public List<Vector3> getVertexList()
  275. {
  276. List<Vector3> result = new List<Vector3>();
  277. foreach (Vertex v in m_bdata.m_vertices.Keys)
  278. {
  279. result.Add(new Vector3(v.X, v.Y, v.Z));
  280. }
  281. return result;
  282. }
  283. public float[] getVertexListAsFloat()
  284. {
  285. if (m_bdata.m_vertices == null)
  286. throw new NotSupportedException();
  287. float[] result = new float[m_bdata.m_vertices.Count * 3];
  288. int k = 0;
  289. foreach (KeyValuePair<Vertex, int> kvp in m_bdata.m_vertices)
  290. {
  291. Vertex v = kvp.Key;
  292. int i = kvp.Value;
  293. k = 3 * i;
  294. result[k] = v.X;
  295. result[k + 1] = v.Y;
  296. result[k + 2] = v.Z;
  297. }
  298. return result;
  299. }
  300. public float[] getVertexListAsFloatLocked()
  301. {
  302. return null;
  303. }
  304. public void getVertexListAsPtrToFloatArray(out IntPtr _vertices, out int vertexStride, out int vertexCount)
  305. {
  306. // A vertex is 3 floats
  307. vertexStride = 3 * sizeof(float);
  308. // If there isn't an unmanaged array allocated yet, do it now
  309. if (m_verticesPtr == IntPtr.Zero && m_bdata != null)
  310. {
  311. vertices = getVertexListAsFloat();
  312. // Each vertex is 3 elements (floats)
  313. m_vertexCount = vertices.Length / 3;
  314. vhandler = GCHandle.Alloc(vertices, GCHandleType.Pinned);
  315. m_verticesPtr = vhandler.AddrOfPinnedObject();
  316. GC.AddMemoryPressure(Buffer.ByteLength(vertices));
  317. }
  318. _vertices = m_verticesPtr;
  319. vertexCount = m_vertexCount;
  320. }
  321. public int[] getIndexListAsInt()
  322. {
  323. if (m_bdata.m_triangles == null)
  324. throw new NotSupportedException();
  325. int[] result = new int[m_bdata.m_triangles.Count * 3];
  326. int k;
  327. for (int i = 0; i < m_bdata.m_triangles.Count; i++)
  328. {
  329. k= 3 * i;
  330. Triangle t = m_bdata.m_triangles[i];
  331. result[k] = m_bdata.m_vertices[t.v1];
  332. result[k + 1] = m_bdata.m_vertices[t.v2];
  333. result[k + 2] = m_bdata.m_vertices[t.v3];
  334. }
  335. return result;
  336. }
  337. /// <summary>
  338. /// creates a list of index values that defines triangle faces. THIS METHOD FREES ALL NON-PINNED MESH DATA
  339. /// </summary>
  340. /// <returns></returns>
  341. public int[] getIndexListAsIntLocked()
  342. {
  343. return null;
  344. }
  345. public void getIndexListAsPtrToIntArray(out IntPtr indices, out int triStride, out int indexCount)
  346. {
  347. // If there isn't an unmanaged array allocated yet, do it now
  348. if (m_indicesPtr == IntPtr.Zero && m_bdata != null)
  349. {
  350. indexes = getIndexListAsInt();
  351. m_indexCount = indexes.Length;
  352. ihandler = GCHandle.Alloc(indexes, GCHandleType.Pinned);
  353. m_indicesPtr = ihandler.AddrOfPinnedObject();
  354. GC.AddMemoryPressure(Buffer.ByteLength(indexes));
  355. }
  356. // A triangle is 3 ints (indices)
  357. triStride = 3 * sizeof(int);
  358. indices = m_indicesPtr;
  359. indexCount = m_indexCount;
  360. }
  361. public void releasePinned()
  362. {
  363. if (m_verticesPtr != IntPtr.Zero)
  364. {
  365. vhandler.Free();
  366. GC.RemoveMemoryPressure(Buffer.ByteLength(vertices));
  367. vertices = null;
  368. m_verticesPtr = IntPtr.Zero;
  369. }
  370. if (m_indicesPtr != IntPtr.Zero)
  371. {
  372. ihandler.Free();
  373. GC.RemoveMemoryPressure(Buffer.ByteLength(indexes));
  374. indexes = null;
  375. m_indicesPtr = IntPtr.Zero;
  376. }
  377. }
  378. /// <summary>
  379. /// frees up the source mesh data to minimize memory - call this method after calling get*Locked() functions
  380. /// </summary>
  381. public void releaseSourceMeshData()
  382. {
  383. if (m_bdata != null)
  384. {
  385. m_bdata.m_triangles = null;
  386. m_bdata.m_vertices = null;
  387. }
  388. }
  389. public void releaseBuildingMeshData()
  390. {
  391. if (m_bdata != null)
  392. {
  393. m_bdata.m_triangles = null;
  394. m_bdata.m_vertices = null;
  395. m_bdata = null;
  396. }
  397. }
  398. public void Append(IMesh newMesh)
  399. {
  400. if (m_indicesPtr != IntPtr.Zero || m_verticesPtr != IntPtr.Zero)
  401. throw new NotSupportedException("Attempt to Append to a pinned Mesh");
  402. if (!(newMesh is Mesh))
  403. return;
  404. foreach (Triangle t in ((Mesh)newMesh).m_bdata.m_triangles)
  405. Add(t);
  406. }
  407. // Do a linear transformation of mesh.
  408. public void TransformLinear(float[,] matrix, float[] offset)
  409. {
  410. if (m_indicesPtr != IntPtr.Zero || m_verticesPtr != IntPtr.Zero)
  411. throw new NotSupportedException("Attempt to TransformLinear a pinned Mesh");
  412. foreach (Vertex v in m_bdata.m_vertices.Keys)
  413. {
  414. if (v == null)
  415. continue;
  416. float x, y, z;
  417. x = v.X * matrix[0, 0] + v.Y * matrix[1, 0] + v.Z * matrix[2, 0];
  418. y = v.X * matrix[0, 1] + v.Y * matrix[1, 1] + v.Z * matrix[2, 1];
  419. z = v.X * matrix[0, 2] + v.Y * matrix[1, 2] + v.Z * matrix[2, 2];
  420. v.X = x + offset[0];
  421. v.Y = y + offset[1];
  422. v.Z = z + offset[2];
  423. }
  424. }
  425. public void DumpRaw(String path, String name, String title)
  426. {
  427. if (path == null)
  428. return;
  429. if (m_bdata == null)
  430. return;
  431. String fileName = name + "_" + title + ".raw";
  432. String completePath = System.IO.Path.Combine(path, fileName);
  433. StreamWriter sw = new StreamWriter(completePath);
  434. foreach (Triangle t in m_bdata.m_triangles)
  435. {
  436. String s = t.ToStringRaw();
  437. sw.WriteLine(s);
  438. }
  439. sw.Close();
  440. }
  441. public void TrimExcess()
  442. {
  443. m_bdata.m_triangles.TrimExcess();
  444. }
  445. public void pinMemory()
  446. {
  447. m_vertexCount = vertices.Length / 3;
  448. vhandler = GCHandle.Alloc(vertices, GCHandleType.Pinned);
  449. m_verticesPtr = vhandler.AddrOfPinnedObject();
  450. GC.AddMemoryPressure(Buffer.ByteLength(vertices));
  451. m_indexCount = indexes.Length;
  452. ihandler = GCHandle.Alloc(indexes, GCHandleType.Pinned);
  453. m_indicesPtr = ihandler.AddrOfPinnedObject();
  454. GC.AddMemoryPressure(Buffer.ByteLength(indexes));
  455. }
  456. public void PrepForOde()
  457. {
  458. // If there isn't an unmanaged array allocated yet, do it now
  459. if (m_verticesPtr == IntPtr.Zero)
  460. vertices = getVertexListAsFloat();
  461. // If there isn't an unmanaged array allocated yet, do it now
  462. if (m_indicesPtr == IntPtr.Zero)
  463. indexes = getIndexListAsInt();
  464. float x, y, z;
  465. if (m_bdata.m_centroidDiv > 0)
  466. {
  467. m_obboffset = new Vector3(m_bdata.m_centroid.X / m_bdata.m_centroidDiv, m_bdata.m_centroid.Y / m_bdata.m_centroidDiv, m_bdata.m_centroid.Z / m_bdata.m_centroidDiv);
  468. x = (m_bdata.m_obbXmax - m_bdata.m_obbXmin) * 0.5f;
  469. if(x < 0.0005f)
  470. x = 0.0005f;
  471. y = (m_bdata.m_obbYmax - m_bdata.m_obbYmin) * 0.5f;
  472. if(y < 0.0005f)
  473. y = 0.0005f;
  474. z = (m_bdata.m_obbZmax - m_bdata.m_obbZmin) * 0.5f;
  475. if(z < 0.0005f)
  476. z = 0.0005f;
  477. }
  478. else
  479. {
  480. m_obboffset = Vector3.Zero;
  481. x = 0.5f;
  482. y = 0.5f;
  483. z = 0.5f;
  484. }
  485. m_obb = new Vector3(x, y, z);
  486. releaseBuildingMeshData();
  487. pinMemory();
  488. }
  489. public bool ToStream(Stream st)
  490. {
  491. if (m_indicesPtr == IntPtr.Zero || m_verticesPtr == IntPtr.Zero)
  492. return false;
  493. bool ok = true;
  494. try
  495. {
  496. using(BinaryWriter bw = new BinaryWriter(st))
  497. {
  498. bw.Write(m_vertexCount);
  499. bw.Write(m_indexCount);
  500. for (int i = 0; i < 3 * m_vertexCount; i++)
  501. bw.Write(vertices[i]);
  502. for (int i = 0; i < m_indexCount; i++)
  503. bw.Write(indexes[i]);
  504. bw.Write(m_obb.X);
  505. bw.Write(m_obb.Y);
  506. bw.Write(m_obb.Z);
  507. bw.Write(m_obboffset.X);
  508. bw.Write(m_obboffset.Y);
  509. bw.Write(m_obboffset.Z);
  510. bw.Flush();
  511. bw.Close();
  512. }
  513. }
  514. catch
  515. {
  516. ok = false;
  517. }
  518. return ok;
  519. }
  520. public static Mesh FromStream(Stream st, AMeshKey key)
  521. {
  522. Mesh mesh = new Mesh(false);
  523. bool ok = true;
  524. try
  525. {
  526. using(BinaryReader br = new BinaryReader(st))
  527. {
  528. mesh.m_vertexCount = br.ReadInt32();
  529. mesh.m_indexCount = br.ReadInt32();
  530. int n = 3 * mesh.m_vertexCount;
  531. mesh.vertices = new float[n];
  532. for (int i = 0; i < n; i++)
  533. mesh.vertices[i] = br.ReadSingle();
  534. mesh.indexes = new int[mesh.m_indexCount];
  535. for (int i = 0; i < mesh.m_indexCount; i++)
  536. mesh.indexes[i] = br.ReadInt32();
  537. mesh.m_obb.X = br.ReadSingle();
  538. mesh.m_obb.Y = br.ReadSingle();
  539. mesh.m_obb.Z = br.ReadSingle();
  540. mesh.m_obboffset.X = br.ReadSingle();
  541. mesh.m_obboffset.Y = br.ReadSingle();
  542. mesh.m_obboffset.Z = br.ReadSingle();
  543. }
  544. }
  545. catch
  546. {
  547. ok = false;
  548. }
  549. if (ok)
  550. {
  551. mesh.pinMemory();
  552. mesh.Key = key;
  553. mesh.RefCount = 1;
  554. return mesh;
  555. }
  556. mesh.vertices = null;
  557. mesh.indexes = null;
  558. return null;
  559. }
  560. }
  561. }