//sewer's code public static void DetermineRenderStuff2(CLFile data) { List <Vertex> QuadNodeVertexList = new List <Vertex>(); List <Int32> QuadNodeIndexList = new List <Int32>(); Int32 k = 0; foreach (CLQuadNode i in data.CLQuadNodeList) { if (Program.collisionEditor.checkedListBox1.CheckedIndices.Contains(i.Index)) { QuadNodeVertexList.Add(new Vertex(new Vector3(i.NodeSquare.X, 100 / (i.Depth + 1), i.NodeSquare.Y))); QuadNodeIndexList.Add(k); QuadNodeIndexList.Add(k + 1); QuadNodeVertexList.Add(new Vertex(new Vector3(i.NodeSquare.X + i.NodeSquare.Width, 100 / (i.Depth + 1), i.NodeSquare.Y))); QuadNodeIndexList.Add(k + 1); QuadNodeIndexList.Add(k + 2); QuadNodeVertexList.Add(new Vertex(new Vector3(i.NodeSquare.X + i.NodeSquare.Width, 100 / (i.Depth + 1), i.NodeSquare.Y + i.NodeSquare.Height))); QuadNodeIndexList.Add(k + 2); QuadNodeIndexList.Add(k + 3); QuadNodeVertexList.Add(new Vertex(new Vector3(i.NodeSquare.X, 100 / (i.Depth + 1), i.NodeSquare.Y + i.NodeSquare.Height))); QuadNodeIndexList.Add(k + 3); QuadNodeIndexList.Add(k); k += 4; } } secondQuadTreeMesh = SharpMesh.Create(SharpRenderer.device, QuadNodeVertexList.ToArray(), QuadNodeIndexList.ToArray(), new List <SharpSubSet>() { new SharpSubSet(0, QuadNodeIndexList.Count, null) }, SharpDX.Direct3D.PrimitiveTopology.LineList); secondQuadtreeRenderData.Color = new Vector4(0.3f, 0.9f, 0.6f, 1f); }
public static bool ReBuildQuadtree(ref CLFile data) { data.CLQuadNodeList[0].NodeSquare.X = data.quadCenterX - (data.quadLenght / 2); data.CLQuadNodeList[0].NodeSquare.Y = data.quadCenterZ - (data.quadLenght / 2); data.CLQuadNodeList[0].NodeSquare.Height = data.quadLenght; data.CLQuadNodeList[0].NodeSquare.Width = data.quadLenght; for (int i = 0; i < data.CLQuadNodeList.Count; i++) { if (data.CLQuadNodeList[i].Child != 0) { GiveSquareToChild(ref data, data.CLQuadNodeList[i].NodeSquare, data.CLQuadNodeList[i].Child, 0); GiveSquareToChild(ref data, data.CLQuadNodeList[i].NodeSquare, data.CLQuadNodeList[i].Child, 1); GiveSquareToChild(ref data, data.CLQuadNodeList[i].NodeSquare, data.CLQuadNodeList[i].Child, 2); GiveSquareToChild(ref data, data.CLQuadNodeList[i].NodeSquare, data.CLQuadNodeList[i].Child, 3); } Program.collisionEditor.progressBar1.PerformStep(); } //sewer's code Program.collisionEditor.checkedListBox1.Items.Clear(); foreach (CLQuadNode i in data.CLQuadNodeList) { Program.collisionEditor.checkedListBox1.Items.Add(i); } // end return(true); }
public static void DetermineQuadtreeRenderStuff(ref CLFile data) { List <Vertex> QuadNodeVertexList = new List <Vertex>(); List <Int32> QuadNodeIndexList = new List <Int32>(); Int32 k = 0; foreach (CLQuadNode i in data.CLQuadNodeList) { Program.collisionEditor.progressBar1.PerformStep(); if (i.Child == 0 | i.Index == 0) { QuadNodeVertexList.Add(new Vertex(new Vector3(i.NodeSquare.X, 0, i.NodeSquare.Y))); QuadNodeIndexList.Add(k); QuadNodeIndexList.Add(k + 1); QuadNodeVertexList.Add(new Vertex(new Vector3(i.NodeSquare.X + i.NodeSquare.Width, 0, i.NodeSquare.Y))); QuadNodeIndexList.Add(k + 1); QuadNodeIndexList.Add(k + 2); QuadNodeVertexList.Add(new Vertex(new Vector3(i.NodeSquare.X + i.NodeSquare.Width, 0, i.NodeSquare.Y + i.NodeSquare.Height))); QuadNodeIndexList.Add(k + 2); QuadNodeIndexList.Add(k + 3); QuadNodeVertexList.Add(new Vertex(new Vector3(i.NodeSquare.X, 0, i.NodeSquare.Y + i.NodeSquare.Height))); QuadNodeIndexList.Add(k + 3); QuadNodeIndexList.Add(k); k += 4; } } quadTreeMesh = SharpMesh.Create(device, QuadNodeVertexList.ToArray(), QuadNodeIndexList.ToArray(), new List <SharpSubSet>() { new SharpSubSet(0, QuadNodeIndexList.Count, null) }, SharpDX.Direct3D.PrimitiveTopology.LineList); mainQuadtreeRenderData.Color = new Vector4(0.9f, 0.3f, 0.6f, 1f); }
public void ConvertOBJtoCL(string InputFile, string OutputFile, ushort basePower, byte depthLevel, bool flipNormals, ProgressBar bar) { CLFile data = new CLFile(depthLevel); bar.Minimum = 0; bar.Value = 0; bar.Step = 1; if (ReadOBJFile(InputFile, ref data, flipNormals, bar)) { if (GenerateCollision(ref data, basePower, bar)) { CreateCLFile(OutputFile, ref data, bar); } } }
public void GiveSquareToChild(ref CLFile data, RectangleF r, int Child, int Offset) { data.CLQuadNodeList[Child + Offset].NodeSquare = new RectangleF(r.X, r.Y, r.Width / 2, r.Height / 2); if (Offset == 1) { data.CLQuadNodeList[Child + Offset].NodeSquare.X += data.CLQuadNodeList[Child + Offset].NodeSquare.Width; } else if (Offset == 2) { data.CLQuadNodeList[Child + Offset].NodeSquare.Y += data.CLQuadNodeList[Child + Offset].NodeSquare.Height; } else if (Offset == 3) { data.CLQuadNodeList[Child + Offset].NodeSquare.X += data.CLQuadNodeList[Child + Offset].NodeSquare.Width; data.CLQuadNodeList[Child + Offset].NodeSquare.Y += data.CLQuadNodeList[Child + Offset].NodeSquare.Height; } }
public void ConvertCLtoOBJ(string fileName, ref CLFile data) { StreamWriter FileCloser = new StreamWriter(new FileStream(fileName, FileMode.Create)); FileCloser.WriteLine("#Exported by Heroes Power Plant"); FileCloser.WriteLine("#Number of vertices: " + data.CLVertexArray.Count().ToString()); FileCloser.WriteLine("#Number of faces: " + data.CLTriangleArray.Count().ToString()); FileCloser.WriteLine(); foreach (VertexColoredNormalized i in data.CLVertexArray) { FileCloser.WriteLine("v " + i.Position.X.ToString() + " " + i.Position.Y.ToString() + " " + i.Position.Z.ToString()); } FileCloser.WriteLine(); foreach (UInt64 i in data.MeshTypeList) { byte[] TempByte = BitConverter.GetBytes(i); FileCloser.WriteLine("g mesh" + TempByte[4].ToString("X2") + TempByte[5].ToString("X2") + "_" + TempByte[0].ToString("X2") + TempByte[1].ToString("X2") + TempByte[2].ToString("X2") + TempByte[3].ToString("X2")); FileCloser.WriteLine(); foreach (Triangle j in data.CLTriangleArray) { if ((j.ColFlags[0] == TempByte[0]) & (j.ColFlags[1] == TempByte[1]) & (j.ColFlags[2] == TempByte[2]) & (j.ColFlags[3] == TempByte[3]) & (j.ColFlags[4] == TempByte[4]) & (j.ColFlags[5] == TempByte[5])) { FileCloser.WriteLine("f " + (j.Vertices[0] + 1).ToString() + " " + (j.Vertices[1] + 1).ToString() + " " + (j.Vertices[2] + 1).ToString()); } } FileCloser.WriteLine(); } FileCloser.Close(); }
public bool BuildQuadtree(ref CLFile data, ProgressBar bar) { QuadNode TempNode = new QuadNode(); TempNode.NodeSquare.X = data.quadCenterX - (data.quadLength / 2); TempNode.NodeSquare.Y = data.quadCenterZ - (data.quadLength / 2); TempNode.NodeSquare.Width = data.quadLength; TempNode.NodeSquare.Height = data.quadLength; TempNode.Child = 1; TempNode.NodeTriangleArray = Range((ushort)data.CLTriangleArray.Count()); data.CLQuadNodeList.Add(TempNode); bar.PerformStep(); int i = 0; while (i < data.CLQuadNodeList.Count) { if (data.CLQuadNodeList[i].Depth != data.MaxDepth & data.CLQuadNodeList[i].NodeTriangleArray.Count() > 0) { data.CLQuadNodeList[i].Child = (ushort)data.CLQuadNodeList.Count; data.CLQuadNodeList.Add(CreateNode(data.CLQuadNodeList[i], 0, (ushort)data.CLQuadNodeList.Count, data.basePower, data.CLTriangleArray)); bar.PerformStep(); data.CLQuadNodeList.Add(CreateNode(data.CLQuadNodeList[i], 1, (ushort)data.CLQuadNodeList.Count, data.basePower, data.CLTriangleArray)); bar.PerformStep(); data.CLQuadNodeList.Add(CreateNode(data.CLQuadNodeList[i], 2, (ushort)data.CLQuadNodeList.Count, data.basePower, data.CLTriangleArray)); bar.PerformStep(); data.CLQuadNodeList.Add(CreateNode(data.CLQuadNodeList[i], 3, (ushort)data.CLQuadNodeList.Count, data.basePower, data.CLTriangleArray)); bar.PerformStep(); data.CLQuadNodeList[i].NodeTriangleArray = null; data.CLQuadNodeList[i].NodeTriangleAmount = 0; } i += 1; } bar.Maximum = 2 * data.CLVertexArray.Count() + 2 * data.CLTriangleArray.Count() + 4 * data.CLQuadNodeList.Count(); return(true); }
public void DetermineQuadtreeRenderStuff(ref CLFile data, SharpDevice device, ProgressBar bar) { List <Vertex> QuadNodeVertexList = new List <Vertex>(); List <int> QuadNodeIndexList = new List <int>(); int k = 0; foreach (QuadNode i in data.CLQuadNodeList) { bar.PerformStep(); if (i.Child == 0 | i.Index == 0) { QuadNodeVertexList.Add(new Vertex(new Vector3(i.NodeSquare.X, 0, i.NodeSquare.Y))); QuadNodeIndexList.Add(k); QuadNodeIndexList.Add(k + 1); QuadNodeVertexList.Add(new Vertex(new Vector3(i.NodeSquare.X + i.NodeSquare.Width, 0, i.NodeSquare.Y))); QuadNodeIndexList.Add(k + 1); QuadNodeIndexList.Add(k + 2); QuadNodeVertexList.Add(new Vertex(new Vector3(i.NodeSquare.X + i.NodeSquare.Width, 0, i.NodeSquare.Y + i.NodeSquare.Height))); QuadNodeIndexList.Add(k + 2); QuadNodeIndexList.Add(k + 3); QuadNodeVertexList.Add(new Vertex(new Vector3(i.NodeSquare.X, 0, i.NodeSquare.Y + i.NodeSquare.Height))); QuadNodeIndexList.Add(k + 3); QuadNodeIndexList.Add(k); k += 4; } } if (quadTreeMesh != null) { quadTreeMesh.Dispose(); } quadTreeMesh = SharpMesh.Create(device, QuadNodeVertexList.ToArray(), QuadNodeIndexList.ToArray(), new List <SharpSubSet>() { new SharpSubSet(0, QuadNodeIndexList.Count, null) }, SharpDX.Direct3D.PrimitiveTopology.LineList); mainQuadtreeRenderData.Color = new Vector4(0.9f, 0.3f, 0.6f, 1f); }
public bool ReBuildQuadtree(ref CLFile data, ProgressBar bar) { data.CLQuadNodeList[0].NodeSquare.X = data.quadCenterX - (data.quadLength / 2); data.CLQuadNodeList[0].NodeSquare.Y = data.quadCenterZ - (data.quadLength / 2); data.CLQuadNodeList[0].NodeSquare.Height = data.quadLength; data.CLQuadNodeList[0].NodeSquare.Width = data.quadLength; for (int i = 0; i < data.CLQuadNodeList.Count; i++) { if (data.CLQuadNodeList[i].Child != 0) { GiveSquareToChild(ref data, data.CLQuadNodeList[i].NodeSquare, data.CLQuadNodeList[i].Child, 0); GiveSquareToChild(ref data, data.CLQuadNodeList[i].NodeSquare, data.CLQuadNodeList[i].Child, 1); GiveSquareToChild(ref data, data.CLQuadNodeList[i].NodeSquare, data.CLQuadNodeList[i].Child, 2); GiveSquareToChild(ref data, data.CLQuadNodeList[i].NodeSquare, data.CLQuadNodeList[i].Child, 3); } bar.PerformStep(); } return(true); }
public CLFile LoadCLFile(string FileName, SharpDevice device, ProgressBar bar) { CLFile data = new CLFile(0); BinaryReader CLReader = new BinaryReader(new FileStream(FileName, FileMode.Open)); CLReader.BaseStream.Position = 0; data.numBytes = Switch(CLReader.ReadUInt32()); //Get total number of bytes in file if (data.numBytes != CLReader.BaseStream.Length) { throw new ArgumentException("Not a valid CL file."); } //Get offset of structs data.pointQuadtree = Switch(CLReader.ReadUInt32()); data.pointTriangle = Switch(CLReader.ReadUInt32()); data.pointVertex = Switch(CLReader.ReadUInt32()); //Get quadtree center and radius data.quadCenterX = Switch(CLReader.ReadSingle()); data.quadCenterY = Switch(CLReader.ReadSingle()); data.quadCenterZ = Switch(CLReader.ReadSingle()); data.quadLength = Switch(CLReader.ReadSingle()); //Get amount of stuff data.basePower = Switch(CLReader.ReadUInt16()); data.numTriangles = Switch(CLReader.ReadUInt16()); data.numVertices = Switch(CLReader.ReadUInt16()); data.numQuadnodes = Switch(CLReader.ReadUInt16()); bar.Maximum = data.numTriangles + data.numVertices + 3 * data.numQuadnodes; List <Triangle> CLTriangleList = new List <Triangle>(data.numTriangles); List <CollisionVertex> CLVertexList = new List <CollisionVertex>(data.numVertices); data.MeshTypeList = new List <UInt64>(); for (int i = 0; i < data.numVertices; i++) { CLReader.BaseStream.Position = data.pointVertex + i * 0xC; CLVertexList.Add(new CollisionVertex(Switch(CLReader.ReadSingle()), Switch(CLReader.ReadSingle()), Switch(CLReader.ReadSingle()))); bar.PerformStep(); } for (int i = 0; i < data.numTriangles; i++) { CLReader.BaseStream.Position = data.pointTriangle + i * 0x20; CLTriangleList.Add(new Triangle(Switch(CLReader.ReadUInt16()), Switch(CLReader.ReadUInt16()), Switch(CLReader.ReadUInt16()))); CLReader.BaseStream.Position += 6; Vector3 Normals = new Vector3(Switch(CLReader.ReadSingle()), Switch(CLReader.ReadSingle()), Switch(CLReader.ReadSingle())); CLVertexList[CLTriangleList[i].Vertices[0]].NormalList.Add(Normals); CLVertexList[CLTriangleList[i].Vertices[1]].NormalList.Add(Normals); CLVertexList[CLTriangleList[i].Vertices[2]].NormalList.Add(Normals); UInt64 FlagsAsUint64 = CLReader.ReadUInt64(); CLTriangleList[i].ColFlags = BitConverter.GetBytes(FlagsAsUint64); if (!data.MeshTypeList.Contains(FlagsAsUint64)) { data.MeshTypeList.Add(FlagsAsUint64); } Color TempColor = new Color(CLTriangleList[i].ColFlags[1], CLTriangleList[i].ColFlags[2], CLTriangleList[i].ColFlags[3]); if (TempColor.R == 0) { TempColor.R = 255; } else { TempColor.R = (byte)(256 - (Math.Log(TempColor.R, 2) + 1) * 32); } if (TempColor.G == 0) { TempColor.G = 255; } else { TempColor.G = (byte)(256 - (Math.Log(TempColor.G, 2) + 1) * 32); } if (TempColor.B == 0) { TempColor.B = 255; } else { TempColor.B = (byte)(256 - (Math.Log(TempColor.B, 2) + 1) * 32); } CLVertexList[CLTriangleList[i].Vertices[0]].Color = TempColor; CLVertexList[CLTriangleList[i].Vertices[1]].Color = TempColor; CLVertexList[CLTriangleList[i].Vertices[2]].Color = TempColor; bar.PerformStep(); } data.CLTriangleArray = CLTriangleList.ToArray(); for (int i = 0; i < data.numQuadnodes; i++) { CLReader.BaseStream.Position = data.pointQuadtree + i * 0x20; QuadNode TempNode = new QuadNode { Index = Switch(CLReader.ReadUInt16()), Parent = Switch(CLReader.ReadUInt16()), Child = Switch(CLReader.ReadUInt16()) }; CLReader.BaseStream.Position += 8; TempNode.NodeTriangleAmount = Switch(CLReader.ReadUInt16()); TempNode.TriListOffset = Switch(CLReader.ReadUInt32()); TempNode.PosValueX = Switch(CLReader.ReadUInt16()); TempNode.PosValueZ = Switch(CLReader.ReadUInt16()); TempNode.Depth = CLReader.ReadByte(); data.CLQuadNodeList.Add(TempNode); bar.PerformStep(); } ReBuildQuadtree(ref data, bar); DetermineQuadtreeRenderStuff(ref data, device, bar); CLReader.Close(); data.CLVertexArray = new VertexColoredNormalized[CLVertexList.Count()]; for (int i = 0; i < CLVertexList.Count; i++) { data.CLVertexArray[i] = new VertexColoredNormalized(CLVertexList[i].Position, CLVertexList[i].CalculateNormals(), CLVertexList[i].Color); } int[] IndexArray = new int[data.CLTriangleArray.Count() * 3]; for (int i = 0; i < data.CLTriangleArray.Count() * 3; i++) { IndexArray[i] = data.CLTriangleArray[i / 3].Vertices[i % 3]; } if (collisionMesh != null) { collisionMesh.Dispose(); } collisionMesh = SharpMesh.Create(device, data.CLVertexArray, IndexArray, new List <SharpSubSet>() { new SharpSubSet(0, IndexArray.Count(), null) }, SharpDX.Direct3D.PrimitiveTopology.TriangleList); return(data); }
public bool ReadOBJFile(string InputFile, ref CLFile data, bool flipNormals, ProgressBar bar) { string[] OBJFile = File.ReadAllLines(InputFile); bar.Maximum = 65535 + OBJFile.Length; int CurrentMeshNum = -1; byte[] TempColFlags = { 0, 0, 0, 0x0 }; List <Triangle> CLTriangleList = new List <Triangle>(65535); List <CollisionVertex> CLVertexList = new List <CollisionVertex>(65535); bool lastadded = true; foreach (string j in OBJFile) { if (j.StartsWith("v ")) { string a = Regex.Replace(j, @"\s+", " "); string[] SubStrings = a.Split(' '); CLVertexList.Add(new CollisionVertex(Convert.ToSingle(SubStrings[1]), Convert.ToSingle(SubStrings[2]), Convert.ToSingle(SubStrings[3]))); bar.PerformStep(); } else if (j.StartsWith("f ")) { string[] SubStrings = j.Split(' '); CLTriangleList.Add(new Triangle( (ushort)(Convert.ToUInt16(SubStrings[1].Split('/')[0]) - 1), (ushort)(Convert.ToUInt16(SubStrings[2].Split('/')[0]) - 1), (ushort)(Convert.ToUInt16(SubStrings[3].Split('/')[0]) - 1), CurrentMeshNum, TempColFlags, CLVertexList, flipNormals)); bar.PerformStep(); lastadded = true; } else if (j.StartsWith("g ") || j.StartsWith("o ")) { if (lastadded) { CurrentMeshNum += 1; } lastadded = false; TempColFlags = new byte[] { 0, 0, 0, 0 }; if (j.Contains('_')) { if (j.Split('_').Last().Count() == 8) { try { string a = j.Split('_').Last(); TempColFlags[0] = Convert.ToByte(new string(new char[] { a[0], a[1] }), 16); TempColFlags[1] = Convert.ToByte(new string(new char[] { a[2], a[3] }), 16); TempColFlags[2] = Convert.ToByte(new string(new char[] { a[4], a[5] }), 16); TempColFlags[3] = Convert.ToByte(new string(new char[] { a[6], a[7] }), 16); } catch { TempColFlags = new byte[] { 0, 0, 0, 0 }; } } else { if (j.Split('_').Last().Contains("b")) //bingo { TempColFlags[0] = 0x40; } else if (j.Split('_').Last().Contains("p")) //pinball { TempColFlags[0] = 0x80; } else if (j.Split('_').Last().Contains("x")) //death { TempColFlags[1] = 0x01; } else if (j.Split('_').Last().Contains("l")) //slippery { TempColFlags[1] = 0x04; } else if (j.Split('_').Last().Contains("t")) //triangle jump { TempColFlags[1] = 0x08; } else if (j.Split('_').Last().Contains("w")) //wall { TempColFlags[2] = 0x01; } else if (j.Split('_').Last().Contains("s")) //stairs { TempColFlags[2] = 0x04; } else if (j.Split('_').Last().Contains("k")) //barrier { TempColFlags[2] = 0x80; } else if (j.Split('_').Last().Contains("i")) // invisible wall { TempColFlags[2] = 0x01; TempColFlags[3] = 0x80; } else if (j.Split('_').Last().Contains("a")) // water { TempColFlags[3] = 0x02; } } } } } bar.Maximum = 65535 + CLVertexList.Count() + CLTriangleList.Count(); if (CLVertexList.Count >= 0xffff) { MessageBox.Show("Error: Maximum amount of 65535 vertices reached."); return(false); } if (CLTriangleList.Count >= 0xffff) { MessageBox.Show("Error: Maximum amount of 65535 triangles reached."); return(false); } data.CLVertexArray = new VertexColoredNormalized[CLVertexList.Count()]; for (int i = 0; i < CLVertexList.Count; i++) { data.CLVertexArray[i] = new VertexColoredNormalized(CLVertexList[i].Position, CLVertexList[i].CalculateNormals(), CLVertexList[i].Color); } data.CLTriangleArray = CLTriangleList.ToArray(); return(true); }
public void LoadCLFile(SharpDevice device, ProgressBar bar) { collisionRenderer.Dispose(); data = collisionRenderer.LoadCLFile(CurrentCLfileName, device, bar); }
public bool CreateCLFile(string FileName, ref CLFile data, ProgressBar bar) { //Finally, let's write the file BinaryWriter FileWriter = new BinaryWriter(new MemoryStream( 0x20 * data.CLQuadNodeList.Count() + 0x20 * data.CLTriangleArray.Count() + 0xC * data.CLVertexArray.Count() + 0x28)); FileWriter.BaseStream.Position = 0x28; for (ushort i = 0; i < data.CLQuadNodeList.Count; i++) { if ((data.CLQuadNodeList[i].Depth == data.MaxDepth) & (data.CLQuadNodeList[i].NodeTriangleAmount > 0)) { data.CLQuadNodeList[i].TriListOffset = (uint)FileWriter.BaseStream.Position; foreach (UInt16 j in data.CLQuadNodeList[i].NodeTriangleArray) { FileWriter.Write(Switch(j)); } } bar.PerformStep(); } if (FileWriter.BaseStream.Position % 4 == 2) { FileWriter.Write((ushort)0); } data.pointQuadtree = (uint)FileWriter.BaseStream.Position; foreach (QuadNode i in data.CLQuadNodeList) { FileWriter.Write(Switch(i.Index)); FileWriter.Write(Switch(i.Parent)); FileWriter.Write(Switch(i.Child)); FileWriter.Write((ushort)0); FileWriter.Write((ushort)0); FileWriter.Write((ushort)0); FileWriter.Write((ushort)0); FileWriter.Write(Switch(i.NodeTriangleAmount)); FileWriter.Write(Switch(i.TriListOffset)); FileWriter.Write(Switch(i.PosValueX)); FileWriter.Write(Switch(i.PosValueZ)); FileWriter.Write(i.Depth); FileWriter.Write((byte)0); FileWriter.Write((ushort)0); FileWriter.Write(0); bar.PerformStep(); } data.pointTriangle = (uint)FileWriter.BaseStream.Position; foreach (Triangle i in data.CLTriangleArray) { FileWriter.Write(Switch(i.Vertices[0])); FileWriter.Write(Switch(i.Vertices[1])); FileWriter.Write(Switch(i.Vertices[2])); FileWriter.Write((ushort)0xFFFF); FileWriter.Write((ushort)0xFFFF); FileWriter.Write((ushort)0xFFFF); FileWriter.Write(Switch(i.Normals.X)); FileWriter.Write(Switch(i.Normals.Y)); FileWriter.Write(Switch(i.Normals.Z)); FileWriter.Write(i.ColFlags[0]); FileWriter.Write(i.ColFlags[1]); FileWriter.Write(i.ColFlags[2]); FileWriter.Write(i.ColFlags[3]); FileWriter.Write(Switch(i.MeshNum)); FileWriter.Write((ushort)0); bar.PerformStep(); } data.pointVertex = (uint)FileWriter.BaseStream.Position; foreach (VertexColoredNormalized i in data.CLVertexArray) { FileWriter.Write(Switch(i.Position.X)); FileWriter.Write(Switch(i.Position.Y)); FileWriter.Write(Switch(i.Position.Z)); bar.PerformStep(); } data.numBytes = (uint)FileWriter.BaseStream.Position; FileWriter.BaseStream.Position = 0; FileWriter.Write(Switch(data.numBytes)); FileWriter.Write(Switch(data.pointQuadtree)); FileWriter.Write(Switch(data.pointTriangle)); FileWriter.Write(Switch(data.pointVertex)); FileWriter.Write(Switch(data.quadCenterX)); FileWriter.Write(Switch(data.quadCenterY)); FileWriter.Write(Switch(data.quadCenterZ)); FileWriter.Write(Switch(data.quadLength)); FileWriter.Write(Switch(data.basePower)); FileWriter.Write(Switch(data.numTriangles)); FileWriter.Write(Switch(data.numVertices)); FileWriter.Write(Switch(data.numQuadnodes)); File.WriteAllBytes(FileName, ((MemoryStream)FileWriter.BaseStream).ToArray()); return(true); }
public bool GenerateCollision(ref CLFile data, ushort basePower, ProgressBar bar) { //Let's start with quadtree maximums, minimums and center float MaxX = data.CLVertexArray[0].Position.X; float MaxY = data.CLVertexArray[0].Position.Y; float MaxZ = data.CLVertexArray[0].Position.Z; float MinX = data.CLVertexArray[0].Position.X; float MinY = data.CLVertexArray[0].Position.Y; float MinZ = data.CLVertexArray[0].Position.Z; foreach (VertexColoredNormalized i in data.CLVertexArray) { if (i.Position.X > MaxX) { MaxX = i.Position.X; } if (i.Position.Y > MaxY) { MaxY = i.Position.Y; } if (i.Position.Z > MaxZ) { MaxZ = i.Position.Z; } if (i.Position.X < MinX) { MinX = i.Position.X; } if (i.Position.Y < MinY) { MinY = i.Position.Y; } if (i.Position.Z < MinZ) { MinZ = i.Position.Z; } } data.quadCenterX = (MaxX + MinX) / 2.0f; data.quadCenterY = (MaxY + MinY) / 2.0f; data.quadCenterZ = (MaxZ + MinZ) / 2.0f; data.quadLength = Math.Max(MaxX - MinX, MaxZ - MinZ); data.quadLength = (float)Math.Ceiling(data.quadLength); if (data.quadLength % 16 != 0) { data.quadLength = (((int)(data.quadLength) / 16) + 1) * 16; } if (data.MaxDepth == 0) { data.MaxDepth = (byte)(Math.Log(data.quadLength / 50) / (Math.Log(2))); if (data.MaxDepth > 10) { data.MaxDepth = 10; } } data.numTriangles = (ushort)data.CLTriangleArray.Count(); data.numVertices = (ushort)data.CLVertexArray.Count(); //Now let's build the quadtree data.basePower = basePower; if (BuildQuadtree(ref data, bar)) { data.numQuadnodes = (ushort)data.CLQuadNodeList.Count; return(true); } return(false); }