Mesh.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  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. foreach (KeyValuePair<Vertex, int> kvp in m_bdata.m_vertices)
  289. {
  290. Vertex v = kvp.Key;
  291. int i = kvp.Value;
  292. result[3 * i + 0] = v.X;
  293. result[3 * i + 1] = v.Y;
  294. result[3 * i + 2] = v.Z;
  295. }
  296. return result;
  297. }
  298. public float[] getVertexListAsFloatLocked()
  299. {
  300. return null;
  301. }
  302. public void getVertexListAsPtrToFloatArray(out IntPtr _vertices, out int vertexStride, out int vertexCount)
  303. {
  304. // A vertex is 3 floats
  305. vertexStride = 3 * sizeof(float);
  306. // If there isn't an unmanaged array allocated yet, do it now
  307. if (m_verticesPtr == IntPtr.Zero && m_bdata != null)
  308. {
  309. vertices = getVertexListAsFloat();
  310. // Each vertex is 3 elements (floats)
  311. m_vertexCount = vertices.Length / 3;
  312. vhandler = GCHandle.Alloc(vertices, GCHandleType.Pinned);
  313. m_verticesPtr = vhandler.AddrOfPinnedObject();
  314. GC.AddMemoryPressure(Buffer.ByteLength(vertices));
  315. }
  316. _vertices = m_verticesPtr;
  317. vertexCount = m_vertexCount;
  318. }
  319. public int[] getIndexListAsInt()
  320. {
  321. if (m_bdata.m_triangles == null)
  322. throw new NotSupportedException();
  323. int[] result = new int[m_bdata.m_triangles.Count * 3];
  324. for (int i = 0; i < m_bdata.m_triangles.Count; i++)
  325. {
  326. Triangle t = m_bdata.m_triangles[i];
  327. result[3 * i + 0] = m_bdata.m_vertices[t.v1];
  328. result[3 * i + 1] = m_bdata.m_vertices[t.v2];
  329. result[3 * i + 2] = m_bdata.m_vertices[t.v3];
  330. }
  331. return result;
  332. }
  333. /// <summary>
  334. /// creates a list of index values that defines triangle faces. THIS METHOD FREES ALL NON-PINNED MESH DATA
  335. /// </summary>
  336. /// <returns></returns>
  337. public int[] getIndexListAsIntLocked()
  338. {
  339. return null;
  340. }
  341. public void getIndexListAsPtrToIntArray(out IntPtr indices, out int triStride, out int indexCount)
  342. {
  343. // If there isn't an unmanaged array allocated yet, do it now
  344. if (m_indicesPtr == IntPtr.Zero && m_bdata != null)
  345. {
  346. indexes = getIndexListAsInt();
  347. m_indexCount = indexes.Length;
  348. ihandler = GCHandle.Alloc(indexes, GCHandleType.Pinned);
  349. m_indicesPtr = ihandler.AddrOfPinnedObject();
  350. GC.AddMemoryPressure(Buffer.ByteLength(indexes));
  351. }
  352. // A triangle is 3 ints (indices)
  353. triStride = 3 * sizeof(int);
  354. indices = m_indicesPtr;
  355. indexCount = m_indexCount;
  356. }
  357. public void releasePinned()
  358. {
  359. if (m_verticesPtr != IntPtr.Zero)
  360. {
  361. vhandler.Free();
  362. GC.RemoveMemoryPressure(Buffer.ByteLength(vertices));
  363. vertices = null;
  364. m_verticesPtr = IntPtr.Zero;
  365. }
  366. if (m_indicesPtr != IntPtr.Zero)
  367. {
  368. ihandler.Free();
  369. GC.RemoveMemoryPressure(Buffer.ByteLength(indexes));
  370. indexes = null;
  371. m_indicesPtr = IntPtr.Zero;
  372. }
  373. }
  374. /// <summary>
  375. /// frees up the source mesh data to minimize memory - call this method after calling get*Locked() functions
  376. /// </summary>
  377. public void releaseSourceMeshData()
  378. {
  379. if (m_bdata != null)
  380. {
  381. m_bdata.m_triangles = null;
  382. m_bdata.m_vertices = null;
  383. }
  384. }
  385. public void releaseBuildingMeshData()
  386. {
  387. if (m_bdata != null)
  388. {
  389. m_bdata.m_triangles = null;
  390. m_bdata.m_vertices = null;
  391. m_bdata = null;
  392. }
  393. }
  394. public void Append(IMesh newMesh)
  395. {
  396. if (m_indicesPtr != IntPtr.Zero || m_verticesPtr != IntPtr.Zero)
  397. throw new NotSupportedException("Attempt to Append to a pinned Mesh");
  398. if (!(newMesh is Mesh))
  399. return;
  400. foreach (Triangle t in ((Mesh)newMesh).m_bdata.m_triangles)
  401. Add(t);
  402. }
  403. // Do a linear transformation of mesh.
  404. public void TransformLinear(float[,] matrix, float[] offset)
  405. {
  406. if (m_indicesPtr != IntPtr.Zero || m_verticesPtr != IntPtr.Zero)
  407. throw new NotSupportedException("Attempt to TransformLinear a pinned Mesh");
  408. foreach (Vertex v in m_bdata.m_vertices.Keys)
  409. {
  410. if (v == null)
  411. continue;
  412. float x, y, z;
  413. x = v.X*matrix[0, 0] + v.Y*matrix[1, 0] + v.Z*matrix[2, 0];
  414. y = v.X*matrix[0, 1] + v.Y*matrix[1, 1] + v.Z*matrix[2, 1];
  415. z = v.X*matrix[0, 2] + v.Y*matrix[1, 2] + v.Z*matrix[2, 2];
  416. v.X = x + offset[0];
  417. v.Y = y + offset[1];
  418. v.Z = z + offset[2];
  419. }
  420. }
  421. public void DumpRaw(String path, String name, String title)
  422. {
  423. if (path == null)
  424. return;
  425. if (m_bdata == null)
  426. return;
  427. String fileName = name + "_" + title + ".raw";
  428. String completePath = System.IO.Path.Combine(path, fileName);
  429. StreamWriter sw = new StreamWriter(completePath);
  430. foreach (Triangle t in m_bdata.m_triangles)
  431. {
  432. String s = t.ToStringRaw();
  433. sw.WriteLine(s);
  434. }
  435. sw.Close();
  436. }
  437. public void TrimExcess()
  438. {
  439. m_bdata.m_triangles.TrimExcess();
  440. }
  441. public void pinMemory()
  442. {
  443. m_vertexCount = vertices.Length / 3;
  444. vhandler = GCHandle.Alloc(vertices, GCHandleType.Pinned);
  445. m_verticesPtr = vhandler.AddrOfPinnedObject();
  446. GC.AddMemoryPressure(Buffer.ByteLength(vertices));
  447. m_indexCount = indexes.Length;
  448. ihandler = GCHandle.Alloc(indexes, GCHandleType.Pinned);
  449. m_indicesPtr = ihandler.AddrOfPinnedObject();
  450. GC.AddMemoryPressure(Buffer.ByteLength(indexes));
  451. }
  452. public void PrepForOde()
  453. {
  454. // If there isn't an unmanaged array allocated yet, do it now
  455. if (m_verticesPtr == IntPtr.Zero)
  456. vertices = getVertexListAsFloat();
  457. // If there isn't an unmanaged array allocated yet, do it now
  458. if (m_indicesPtr == IntPtr.Zero)
  459. indexes = getIndexListAsInt();
  460. float x, y, z;
  461. if (m_bdata.m_centroidDiv > 0)
  462. {
  463. 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);
  464. x = (m_bdata.m_obbXmax - m_bdata.m_obbXmin) * 0.5f;
  465. if(x < 0.0005f)
  466. x = 0.0005f;
  467. y = (m_bdata.m_obbYmax - m_bdata.m_obbYmin) * 0.5f;
  468. if(y < 0.0005f)
  469. y = 0.0005f;
  470. z = (m_bdata.m_obbZmax - m_bdata.m_obbZmin) * 0.5f;
  471. if(z < 0.0005f)
  472. z = 0.0005f;
  473. }
  474. else
  475. {
  476. m_obboffset = Vector3.Zero;
  477. x = 0.5f;
  478. y = 0.5f;
  479. z = 0.5f;
  480. }
  481. m_obb = new Vector3(x, y, z);
  482. releaseBuildingMeshData();
  483. pinMemory();
  484. }
  485. public bool ToStream(Stream st)
  486. {
  487. if (m_indicesPtr == IntPtr.Zero || m_verticesPtr == IntPtr.Zero)
  488. return false;
  489. bool ok = true;
  490. try
  491. {
  492. using(BinaryWriter bw = new BinaryWriter(st))
  493. {
  494. bw.Write(m_vertexCount);
  495. bw.Write(m_indexCount);
  496. for (int i = 0; i < 3 * m_vertexCount; i++)
  497. bw.Write(vertices[i]);
  498. for (int i = 0; i < m_indexCount; i++)
  499. bw.Write(indexes[i]);
  500. bw.Write(m_obb.X);
  501. bw.Write(m_obb.Y);
  502. bw.Write(m_obb.Z);
  503. bw.Write(m_obboffset.X);
  504. bw.Write(m_obboffset.Y);
  505. bw.Write(m_obboffset.Z);
  506. bw.Flush();
  507. bw.Close();
  508. }
  509. }
  510. catch
  511. {
  512. ok = false;
  513. }
  514. return ok;
  515. }
  516. public static Mesh FromStream(Stream st, AMeshKey key)
  517. {
  518. Mesh mesh = new Mesh(false);
  519. bool ok = true;
  520. try
  521. {
  522. using(BinaryReader br = new BinaryReader(st))
  523. {
  524. mesh.m_vertexCount = br.ReadInt32();
  525. mesh.m_indexCount = br.ReadInt32();
  526. int n = 3 * mesh.m_vertexCount;
  527. mesh.vertices = new float[n];
  528. for (int i = 0; i < n; i++)
  529. mesh.vertices[i] = br.ReadSingle();
  530. mesh.indexes = new int[mesh.m_indexCount];
  531. for (int i = 0; i < mesh.m_indexCount; i++)
  532. mesh.indexes[i] = br.ReadInt32();
  533. mesh.m_obb.X = br.ReadSingle();
  534. mesh.m_obb.Y = br.ReadSingle();
  535. mesh.m_obb.Z = br.ReadSingle();
  536. mesh.m_obboffset.X = br.ReadSingle();
  537. mesh.m_obboffset.Y = br.ReadSingle();
  538. mesh.m_obboffset.Z = br.ReadSingle();
  539. }
  540. }
  541. catch
  542. {
  543. ok = false;
  544. }
  545. if (ok)
  546. {
  547. mesh.pinMemory();
  548. mesh.Key = key;
  549. mesh.RefCount = 1;
  550. return mesh;
  551. }
  552. mesh.vertices = null;
  553. mesh.indexes = null;
  554. return null;
  555. }
  556. }
  557. }