public void SaveAsFile(string dir, int id) { if (_block[id].tar != null) { if (_block[id].mesh) { var countV = _block[id].tar[0]; var blockV = _block[id].tar[1]; var blockF = _block[id].tar[3]; var meshHBM = new HitmanPRM.MeshHBM(_block[blockV].data, _block[blockF].data, countV); File.WriteAllText(string.Format(@"{0}/{1} {2}.obj", dir, Path.GetFileNameWithoutExtension(path), id), meshHBM.ToOBJ()); } } }
public void ImportOBJ(int num, string path) { var countV = _block[num].tar[0]; var blockV = _block[num].tar[1]; var blockF = _block[num].tar[3]; var meshHBM = new HitmanPRM.MeshHBM(_block[blockV].data, _block[blockF].data, countV); var OBJ = new OBJ(path); var vertexList = OBJ.BuildVertexArray(0, false); meshHBM._p = new float[vertexList.Length][]; meshHBM._t = new float[vertexList.Length][]; meshHBM._a1 = new int[vertexList.Length][]; meshHBM._a2 = new int[vertexList.Length][]; for (int i = 0; i < vertexList.Length; i++) { // P meshHBM._p[i] = new[] { vertexList[i][0], vertexList[i][1], vertexList[i][2] }; // N var res = new byte[3]; res[0] = (byte)(((vertexList[i][3] + 1) * 127) + 1); res[1] = (byte)(((vertexList[i][4] + 1) * 127) + 1); res[2] = (byte)(((vertexList[i][5] + 1) * 127) + 1); var nh = BitConverter.ToInt32(new byte[] { (byte)res[2], (byte)res[1], (byte)res[0], 0 }, 0); meshHBM._a1[i] = new[] { nh, -1 }; // T meshHBM._t[i] = new[] { vertexList[i][6], vertexList[i][7] }; // N2? meshHBM._a2[i] = new[] { 8421888, 8388732, 0 }; } meshHBM._face = OBJ.BuildIndexArray(0); _block[blockF].data = meshHBM.BuildIndexArray(); _block[blockV].data = meshHBM.BuildVertexArray(); _block[num].tar[0] = meshHBM._p.Length; }