public static void Init(int pixelsPerCharH, int pixelsPerCharV) { if (Sprite == null) { Sprite = ResourceLoader.GetT2D(@"Content\Effects\Visual\DebugMenu\texture.png"); } BufferWidth = 1920 / pixelsPerCharH; BufferHeight = 1080 / pixelsPerCharV; ASCIIBuffer = new byte[BufferWidth * BufferHeight]; ASCIIBufferColors = new Color[BufferWidth * BufferHeight]; ASCIIBufferBackgroundColors = new Color[BufferWidth * BufferHeight]; ASCIIBufferDirty = new bool[BufferWidth * BufferHeight]; VertexBuffer = new VertexPositionColorTexture[BufferWidth * BufferHeight * 6]; VertexBufferBackground = new VertexPositionColorTexture[BufferWidth * BufferHeight * 6]; unitH = (float)pixelsPerCharH; unitV = (float)pixelsPerCharV; for (int i = 0; i < ASCIIBuffer.Length; i++) { ASCIIBuffer[i] = 0; ASCIIBufferDirty[i] = true; ASCIIBufferColors[i] = Color.TransparentBlack; ASCIIBufferBackgroundColors[i] = Color.TransparentBlack; float x = (i % BufferWidth) * unitH; float y = (i / BufferWidth) * unitV; VertexBuffer[i * 6 + 0].Position = new Vector3((-1920f / 2f) + x, (1080f / 2f) - y, 0); VertexBuffer[i * 6 + 1].Position = new Vector3((-1920f / 2f) + x + unitH, (1080f / 2f) - y, 0); VertexBuffer[i * 6 + 2].Position = new Vector3((-1920f / 2f) + x + unitH, (1080f / 2f) - y - unitV, 0); VertexBuffer[i * 6 + 3].Position = new Vector3((-1920f / 2f) + x, (1080f / 2f) - y, 0); VertexBuffer[i * 6 + 4].Position = new Vector3((-1920f / 2f) + x + unitH, (1080f / 2f) - y - unitV, 0); VertexBuffer[i * 6 + 5].Position = new Vector3((-1920f / 2f) + x, (1080f / 2f) - y - unitV, 0); VertexBufferBackground[i * 6 + 0].Position = VertexBuffer[i * 6 + 0].Position; VertexBufferBackground[i * 6 + 1].Position = VertexBuffer[i * 6 + 1].Position; VertexBufferBackground[i * 6 + 2].Position = VertexBuffer[i * 6 + 2].Position; VertexBufferBackground[i * 6 + 3].Position = VertexBuffer[i * 6 + 3].Position; VertexBufferBackground[i * 6 + 4].Position = VertexBuffer[i * 6 + 4].Position; VertexBufferBackground[i * 6 + 5].Position = VertexBuffer[i * 6 + 5].Position; VertexBuffer[i * 6 + 0].Color = Color.Transparent; VertexBuffer[i * 6 + 1].Color = Color.Transparent; VertexBuffer[i * 6 + 2].Color = Color.Transparent; VertexBuffer[i * 6 + 3].Color = Color.Transparent; VertexBuffer[i * 6 + 4].Color = Color.Transparent; VertexBuffer[i * 6 + 5].Color = Color.Transparent; VertexBufferBackground[i * 6 + 0].Color = Color.Transparent; VertexBufferBackground[i * 6 + 1].Color = Color.Transparent; VertexBufferBackground[i * 6 + 2].Color = Color.Transparent; VertexBufferBackground[i * 6 + 3].Color = Color.Transparent; VertexBufferBackground[i * 6 + 4].Color = Color.Transparent; VertexBufferBackground[i * 6 + 5].Color = Color.Transparent; } }
public Trail(string texture) { this.T2D = ResourceLoader.GetT2D(@"Content\Effects\Visual\KeybladeTrails\" + texture + @"\texture.png"); vpct = new VertexPositionColorTexture[6 * 1000]; positionsCount = 0; for (int i = 0; i < vpct.Length; i += 6) { vpct[i + 0].Color = Color.White; vpct[i + 1].Color = Color.White; vpct[i + 2].Color = Color.White; vpct[i + 3].Color = Color.White; vpct[i + 4].Color = Color.White; vpct[i + 5].Color = Color.White; } }
public static void Init() { string[] input = File.ReadAllLines(@"Content\Effects\Visual\LoadingScreen\heart.obj"); List <Vector3> pos = new List <Vector3>(0); List <Vector3> normal = new List <Vector3>(0); List <Vector2> texcoord = new List <Vector2>(0); List <VertexPositionNormalTexture> output = new List <VertexPositionNormalTexture>(0); string[] spli, spli2; for (int i = 0; i < input.Length; i++) { spli = input[i].Split(' '); if (spli[0] == "v") { pos.Add(new Vector3( MainGame.SingleParse(spli[1]), MainGame.SingleParse(spli[2]), MainGame.SingleParse(spli[3]) )); } if (spli[0] == "vt") { texcoord.Add(new Vector2( MainGame.SingleParse(spli[1]), MainGame.SingleParse(spli[2]) )); } if (spli[0] == "vn") { normal.Add(new Vector3( MainGame.SingleParse(spli[1]), MainGame.SingleParse(spli[2]), MainGame.SingleParse(spli[3]) )); } if (spli[0] == "f") { spli2 = spli[1].Split('/'); int iv = int.Parse(spli2[0]); int ivt = int.Parse(spli2[1]); int ivn = int.Parse(spli2[2]); VertexPositionNormalTexture vpn1 = new VertexPositionNormalTexture(); vpn1.Position = pos[iv - 1]; vpn1.TextureCoordinate = texcoord[ivt - 1]; vpn1.Normal = normal[ivn - 1]; spli2 = spli[2].Split('/'); iv = int.Parse(spli2[0]); ivt = int.Parse(spli2[1]); ivn = int.Parse(spli2[2]); VertexPositionNormalTexture vpn2 = new VertexPositionNormalTexture(); vpn2.Position = pos[iv - 1]; vpn2.TextureCoordinate = texcoord[ivt - 1]; vpn2.Normal = normal[ivn - 1]; spli2 = spli[3].Split('/'); iv = int.Parse(spli2[0]); ivt = int.Parse(spli2[1]); ivn = int.Parse(spli2[2]); VertexPositionNormalTexture vpn3 = new VertexPositionNormalTexture(); vpn3.Position = pos[iv - 1]; vpn3.TextureCoordinate = texcoord[ivt - 1]; vpn3.Normal = normal[ivn - 1]; output.Add(vpn3); output.Add(vpn2); output.Add(vpn1); } } vpnt = output.ToArray(); output.Clear(); output = null; pos.Clear(); pos = null; normal.Clear(); normal = null; texcoord.Clear(); texcoord = null; texture = ResourceLoader.GetT2D(@"Content\Effects\Visual\LoadingScreen\texture.png"); for (int i = 0; i < vpnt.Length; i++) { vpnt[i].Position = Vector3.Transform(vpnt[i].Position, Matrix.CreateScale(5f)); } dnewV = new Viewport(); dnewV.Bounds = Program.game.graphics.GraphicsDevice.Viewport.Bounds; dnewV.X = 100; }
public new unsafe void Parse() { byte[] array = File.ReadAllBytes(this.FileName); int address = 0; this.ModelType = (MDType)(sbyte)array[address]; address++; this.NoCull = (sbyte)array[address] < 0; address++; this.ZIndex = (int)(sbyte)array[address]; address++; address++; int textureCount = BitConverter.ToInt32(array, address); address += 4; address += 8; //int addressCopy = address; //address = 16 + textureCount * 0x30; /*new System.Threading.Thread(() => * { * System.Threading.Thread.CurrentThread.Priority = System.Threading.ThreadPriority.Highest; */ for (int i = 0; i < textureCount; i++) { byte length = array[address]; address++; string fname = "Content\\" + Encoding.ASCII.GetString(array, address, length); address += length; this.materialFileNames.Add(fname); //this.Textures.Add(Texture2D.FromStream(Program.game.GraphicsDevice, new FileStream(fname, FileMode.Open, FileAccess.Read, FileShare.Open))); this.Textures.Add(ResourceLoader.GetT2D(fname)); //this.Textures.Add(ResourceLoader.EmptyT2D); if (0x30 - (length + 1) > 0) { address += 0x30 - (length + 1); } } /* while (this.vBuffer.VertexCount == 0) { } * array = null; * }).Start();*/ int meshCount = BitConverter.ToInt32(array, address); address += 4; BitConverter.ToInt32(array, address); address += 4; BitConverter.ToInt32(array, address); address += 4; BitConverter.ToInt32(array, address); address += 4; int vertexCount = 0; for (int i = 0; i < meshCount; i++) { this.MaterialIndices.Add(BitConverter.ToInt32(array, address)); address += 4; int[] off = new int[2]; off[0] = BitConverter.ToInt32(array, address); address += 4; off[1] = BitConverter.ToInt32(array, address); address += 4; this.MeshesOffsets.Add(off); vertexCount += off[1]; } if (meshCount % 4 > 0) { for (int i = 0; i < (4 - (meshCount % 4)); i++) { BitConverter.ToInt32(array, address); address += 4; } } this.VertexBuffer_c = new ComputedVertex[vertexCount]; this.VertexBufferColor = new VertexPositionColorTexture[vertexCount]; this.ShadowBuffer = new VertexPositionColorTexture[this.ModelType == MDType.Human ? 6:0]; //for (int i = 0; i < this.VertexBufferShadow2.Length; i++) // VertexBufferShadow2[i].Color = new Color(0, 0, 0, 0); for (int i = 0; i < vertexCount; i++) { int infs = BitConverter.ToInt32(array, address); address += 4; VertexPositionColorTexture vpct = new VertexPositionColorTexture { TextureCoordinate = new Vector2(BitConverter.ToSingle(array, address), BitConverter.ToSingle(array, address + 4)), Position = new Vector3(0, 0, 0), Color = new Microsoft.Xna.Framework.Color(array[address + 8], array[address + 9], array[address + 10], array[address + 11]) }; address += 12; if (!this.HasColor && (vpct.Color.R < 1 || vpct.Color.G < 1 || vpct.Color.B < 1 || vpct.Color.A < 1)) { this.HasColor = true; } int ind = ((i / 3) * 3 + (2 - (i % 3))); this.VertexBuffer_c[ind] = new ComputedVertex { Count = infs }; int ind_ = 0; for (int j = 0; j < infs; j += 4) { this.VertexBuffer_c[ind].Matis[ind_] = BitConverter.ToInt16(array, address); address += 16; this.VertexBuffer_c[ind].Vertices[j] = BitConverter.ToSingle(array, address); this.VertexBuffer_c[ind].Vertices[j + 1] = BitConverter.ToSingle(array, address + 4); this.VertexBuffer_c[ind].Vertices[j + 2] = BitConverter.ToSingle(array, address + 8); this.VertexBuffer_c[ind].Vertices[j + 3] = BitConverter.ToSingle(array, address + 12); address += 16; ind_++; } this.VertexBufferColor[ind] = vpct; } //array = null; byte[] array2; this.vBuffer = new VertexBuffer(KHDebug.Program.game.graphics.GraphicsDevice, typeof(VertexPositionColorTexture), this.VertexBufferColor.Length, BufferUsage.None); this.vBuffer.SetData <VertexPositionColorTexture>(this.VertexBufferColor); if (File.Exists(Path.GetDirectoryName(this.FileName) + @"\" + this.Name + ".skel")) { array2 = File.ReadAllBytes(Path.GetDirectoryName(this.FileName) + @"\" + this.Name + ".skel"); } else { array2 = File.ReadAllBytes(@"Content\default\skeleton.skel"); } address = 4; int count = BitConverter.ToInt32(array2, address); address += 4; for (int i = 0; i < count; i++) { address = 16 + i * 16; if (BitConverter.ToInt32(array2, address) == 4) { address += 4; BitConverter.ToInt32(array2, address); address += 4; address = BitConverter.ToInt32(array2, address) + 0xA0; break; } else { address += 4; } } short boneCount = BitConverter.ToInt16(array2, address); address += 4; address = address - 0x14 + BitConverter.ToInt32(array2, address); this.Skeleton = new Skeleton { Bones = new List <Bone>(0) }; List <int> parents = new List <int>(0); for (int i = 0; i < boneCount; i++) { Bone currBone = new Bone("bone" + BitConverter.ToInt32(array2, address).ToString("d3")); address += 4; parents.Add(BitConverter.ToInt32(array2, address)); address += 12; currBone.ScaleX = BitConverter.ToSingle(array2, address); address += 4; currBone.ScaleY = BitConverter.ToSingle(array2, address); address += 4; currBone.ScaleZ = BitConverter.ToSingle(array2, address); address += 4; address += 4; currBone.RotateX = BitConverter.ToSingle(array2, address); address += 4; currBone.RotateY = BitConverter.ToSingle(array2, address); address += 4; currBone.RotateZ = BitConverter.ToSingle(array2, address); address += 4; address += 4; currBone.TranslateX = BitConverter.ToSingle(array2, address); address += 4; currBone.TranslateY = BitConverter.ToSingle(array2, address); address += 4; currBone.TranslateZ = BitConverter.ToSingle(array2, address); address += 4; address += 4; currBone.GlobalMatrix = Matrix.CreateScale(new Vector3(currBone.ScaleX, currBone.ScaleY, currBone.ScaleZ)); currBone.GlobalMatrix.Translation = new Vector3(currBone.TranslateX, currBone.TranslateY, currBone.TranslateZ); currBone.localMatrix = currBone.GlobalMatrix; this.Skeleton.Bones.Add(currBone); } array2 = null; for (int i = 0; i < parents.Count; i++) { if (parents[i] > -1) { this.Skeleton.Bones[i].Parent = this.Skeleton.Bones[parents[i]]; } } this.Skeleton.ComputeMatrices(); this.RecreateVertexBuffer(true); }