/// <summary> /// The h 2 parsed prtm. /// </summary> /// <param name="meta">The meta.</param> /// <remarks></remarks> public void H2ParsedPRTM(ref Meta meta) { string[] temps = meta.name.Split('\\'); name = temps[temps.Length - 1]; BoundingBox = new BoundingBoxContainer(); BinaryReader BR = new BinaryReader(meta.MS); RawDataMetaChunks = new RawDataMetaChunk[1]; RawDataMetaChunks[0] = new PRTMRawDataMetaChunk(ref meta); BR.BaseStream.Position = 28; int tempshad = BR.ReadInt32(); int shadid = meta.Map.Functions.ForMeta.FindMetaByID(tempshad); Shaders = new ShaderContainer(); Shaders.Shader = new ShaderInfo[1]; Shaders.Shader[0] = new ShaderInfo(shadid, meta.Map); // LOD = new LODInfo(ref meta, meta.Map, ref RawDataMetaChunks); Display = new DisplayedInfo(); Display.Chunk.Add(0); Display.ShaderIndex = new int[1]; Display.ShaderIndex[0] = 0; // MessageBox.Show("test"); }
/// <summary> /// The dispose. /// </summary> /// <remarks></remarks> public void Dispose() { this.BoundingBox = null; this.Display = null; this.hlmt = null; this.LOD = null; this.RawDataMetaChunks = null; for (int i = 0; i < this.Shaders.Shader.Length; i++) { this.Shaders.Shader[i].Bitmaps.Clear(); this.Shaders.Shader[i].BitmapNames.Clear(); } this.Shaders = null; GC.SuppressFinalize(this); }
/// <summary> /// The ce parsed model. /// </summary> /// <param name="meta">The meta.</param> /// <remarks></remarks> public void CEParsedModel(ref Meta meta) { Display = new DisplayedInfo(); string[] temps = meta.name.Split('\\'); name = temps[temps.Length - 1]; BoundingBox = new BoundingBoxContainer(); BinaryReader BR = new BinaryReader(meta.MS); BR.BaseStream.Position = 208; int tempc = BR.ReadInt32(); int tempr = BR.ReadInt32() - meta.magic - meta.offset; BR.BaseStream.Position = tempr + 36; tempc = BR.ReadInt32(); RawDataMetaChunks = new RawDataMetaChunk[meta.raw.rawChunks.Count / 2]; for (int x = 0; x < meta.raw.rawChunks.Count / 2; x++) { RawDataMetaChunks[x] = new RawDataMetaChunk(); RawDataMetaChunks[x].IndiceCount = meta.raw.rawChunks[x * 2].size / 2; BinaryReader BRX = new BinaryReader(meta.raw.rawChunks[x * 2].MS); BRX.BaseStream.Position = 0; RawDataMetaChunks[x].Indices = new short[RawDataMetaChunks[x].IndiceCount]; for (int y = 0; y < RawDataMetaChunks[x].IndiceCount; y++) { RawDataMetaChunks[x].Indices[y] = BRX.ReadInt16(); } RawDataMetaChunks[x].Indices = Renderer.DecompressIndices( RawDataMetaChunks[x].Indices, 0, RawDataMetaChunks[x].Indices.Length); RawDataMetaChunks[x].IndiceCount = RawDataMetaChunks[x].Indices.Length; RawDataMetaChunks[x].FaceCount = RawDataMetaChunks[x].IndiceCount / 3; RawDataMetaChunks[x].SubMeshInfo = new RawDataMetaChunk.ModelSubMeshInfo[1]; RawDataMetaChunks[x].SubMeshInfo[0] = new RawDataMetaChunk.ModelSubMeshInfo(); RawDataMetaChunks[x].SubMeshInfo[0].IndiceCount = RawDataMetaChunks[x].IndiceCount; RawDataMetaChunks[x].SubMeshInfo[0].ShaderNumber = meta.raw.rawChunks[x * 2].shadernumber; RawDataMetaChunks[x].Vertices = new List<Vector3>(); RawDataMetaChunks[x].UVs = new List<Vector2>(); RawDataMetaChunks[x].Normals = new List<Vector3>(); RawDataMetaChunks[x].Binormals = new List<Vector3>(); RawDataMetaChunks[x].Tangents = new List<Vector3>(); int chunksize = 68; if (meta.Map.HaloVersion == HaloVersionEnum.Halo1) { chunksize = 32; } RawDataMetaChunks[x].VerticeCount = meta.raw.rawChunks[x * 2 + 1].size / chunksize; BRX = new BinaryReader(meta.raw.rawChunks[x * 2 + 1].MS); for (int y = 0; y < RawDataMetaChunks[x].VerticeCount; y++) { BRX.BaseStream.Position = y * chunksize; Vector3 vertice = new Vector3(BRX.ReadSingle(), BRX.ReadSingle(), BRX.ReadSingle()); RawDataMetaChunks[x].Vertices.Add(vertice); switch (meta.Map.HaloVersion) { case HaloVersionEnum.HaloCE: Vector3 normal = new Vector3(BRX.ReadSingle(), BRX.ReadSingle(), BRX.ReadSingle()); RawDataMetaChunks[x].Normals.Add(normal); Vector3 binormal = new Vector3(BRX.ReadSingle(), BRX.ReadSingle(), BRX.ReadSingle()); RawDataMetaChunks[x].Binormals.Add(binormal); Vector3 tangent = new Vector3(BRX.ReadSingle(), BRX.ReadSingle(), BRX.ReadSingle()); RawDataMetaChunks[x].Tangents.Add(tangent); Vector2 uv = new Vector2(BRX.ReadSingle(), BRX.ReadSingle()); RawDataMetaChunks[x].UVs.Add(uv); break; case HaloVersionEnum.Halo1: int test = BRX.ReadInt32(); Vector3 normal2 = DecompressNormal(test); RawDataMetaChunks[x].Normals.Add(normal2); test = BRX.ReadInt32(); Vector3 binormal2 = DecompressNormal(test); RawDataMetaChunks[x].Binormals.Add(binormal2); test = BRX.ReadInt32(); Vector3 tangent2 = DecompressNormal(test); RawDataMetaChunks[x].Tangents.Add(tangent2); short testx = BRX.ReadInt16(); float u = DecompressVertice(Convert.ToSingle(testx), -1, 1); // %1 ; testx = BRX.ReadInt16(); float v = DecompressVertice(Convert.ToSingle(testx), -1, 1); // % 1; Vector2 uv2 = new Vector2(u, v); RawDataMetaChunks[x].UVs.Add(uv2); break; } } if (x < tempc) { Display.Chunk.Add(x); } } Shaders = new ShaderContainer(); BR.BaseStream.Position = 220; tempc = BR.ReadInt32(); tempr = BR.ReadInt32() - meta.magic - meta.offset; Shaders.Shader = new ShaderInfo[tempc]; Display.ShaderIndex = new int[tempc]; for (int x = 0; x < tempc; x++) { Display.ShaderIndex[x] = x; BR.BaseStream.Position = tempr + (x * 32) + 12; int temptag = meta.Map.Functions.ForMeta.FindMetaByID(BR.ReadInt32()); Shaders.Shader[x] = new ShaderInfo(temptag, meta.Map); } }
/// <summary> /// The h 2 parsed model. /// </summary> /// <param name="meta">The meta.</param> /// <remarks></remarks> public void H2ParsedModel(ref Meta meta) { if (meta.MS.Length == 0) { return; } string[] temps = meta.name.Split('\\'); name = temps[temps.Length - 1]; BoundingBox = new BoundingBoxContainer(ref meta); BinaryReader BR = new BinaryReader(meta.MS); BR.BaseStream.Position = 36; int tempc = BR.ReadInt32(); int tempr = BR.ReadInt32() - meta.magic - meta.offset; RawDataMetaChunks = new RawDataMetaChunk[tempc]; for (int x = 0; x < tempc; x++) { RawDataMetaChunks[x] = new RawDataMetaChunk(tempr + (x * 92), x, BoundingBox, ref meta); } Shaders = new ShaderContainer(ref meta); LOD = new LODInfo(ref meta, ref RawDataMetaChunks); int temphlmt = -1; for (int x = 0; x < meta.Map.IndexHeader.metaCount; x++) { if ("hlmt" == meta.Map.MetaInfo.TagType[x] && meta.Map.FileNames.Name[x] == meta.name) { temphlmt = x; break; } } if (temphlmt != -1) { hlmt = new hlmtContainer(temphlmt, meta.Map); PermutationString = hlmt.Permutations.Name; } // ** Length of Distance LOD Display = DisplayedInfo.FindDisplayedPieces(4, this); Frames = new FrameHierarchy(); Frames.GetFramesFromHalo2Model(ref meta); }
public void Render(Camera camera) { if (Sphere == null) { Sphere = new Sphere(); } if (Capsule == null) { Capsule = new Capsule(); } if (Line == null) { Line = new Line(); } var sphereShader = ShaderContainer.GetShader("Sphere"); var capsuleShader = ShaderContainer.GetShader("Capsule"); var lineShader = ShaderContainer.GetShader("Line"); Matrix4 mvp = camera.MvpMatrix; List <Collision> collisions = new List <Collision>(); collisions.AddRange(Attacks); collisions.AddRange(Grabs); GL.Disable(EnableCap.DepthTest); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); for (int i = 0; i < collisions.Count; i++) { Collision coll = collisions[i]; if (!coll.Enabled) { continue; } Vector4 collColor = new Vector4(Collision.IDColors[i % Collision.IDColors.Length], 0.5f); Matrix4 boneTransform = Skel.GetAnimationSingleBindsTransform(BoneIDs[coll.Bone]); Matrix4 boneNoScale = Matrix4.CreateFromQuaternion(boneTransform.ExtractRotation()) * Matrix4.CreateTranslation(boneTransform.ExtractTranslation()); if (IsSphere(coll)) { Sphere.Render(sphereShader, coll.Size, coll.Pos, boneNoScale, mvp, collColor); } else if (coll.ShapeType == Collision.Shape.capsule) { Capsule.Render(capsuleShader, coll.Size, coll.Pos, coll.Pos2, boneNoScale, mvp, collColor); } //angle marker if (coll is Attack attack) { int angle = attack.Angle; Vector4 angleColor = new Vector4(1, 1, 1, 1); GL.LineWidth(2f); if (angle < 361) { float radian = angle * (float)Math.PI / 180f; Line.Render(lineShader, radian, coll.Size, coll.Pos, boneNoScale, mvp, angleColor); } else if (angle == 361) { float radian = (float)Math.PI / 2f; for (int j = 0; j < 4; j++) { Line.Render(lineShader, radian * j, coll.Size / 2, coll.Pos, boneNoScale, mvp, angleColor); } } else if (angle == 368) { //set_vec_target_pos uses a second position to pull opponents toward //this is represented by a line drawn between hitbox center and that point if (attack.VecTargetPos_node != 0) { var attackVecBone = Skel.GetAnimationSingleBindsTransform(BoneIDs[attack.VecTargetPos_node]); var attackVecBoneNoScale = Matrix4.CreateFromQuaternion(attackVecBone.ExtractRotation()) * Matrix4.CreateTranslation(attackVecBone.ExtractTranslation()); Line.Render(lineShader, boneNoScale, attackVecBoneNoScale, coll.Pos, Vector3.Zero, Vector3.Zero, new Vector3(attack.VecTargetPos_pos.Z, attack.VecTargetPos_pos.Y, 0), mvp, angleColor ); } } else { float radian = (float)Math.PI / 2f; float add = (float)Math.PI / 4f; for (int j = 0; j < 4; j++) { Line.Render(lineShader, radian * j + add, coll.Size / 2, coll.Pos, boneNoScale, mvp, angleColor); } } } } GL.Enable(EnableCap.DepthTest); GL.Disable(EnableCap.Blend); }
public static void Render(Camera camera) { if (Skel == null) { return; } if (capsule == null) { capsule = new Capsule(); } if (sphere == null) { sphere = new Sphere(); } var capsuleShader = ShaderContainer.GetShader("Capsule"); var sphereShader = ShaderContainer.GetShader("Sphere"); var polygonShader = ShaderContainer.GetShader("Polygon"); if (RenderSettings.Instance.RenderHitCollisions) { GL.Disable(EnableCap.DepthTest); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); foreach (var hit in HitData) { if (hit.Enabled) { //some param files refer to bone hashes that don't exist on the skeleton if (!BoneIDs.TryGetValue(hit.Bone, out int boneIndex)) { continue; } Matrix4 bone = Skel.GetAnimationSingleBindsTransform(boneIndex); Vector4 color = new Vector4(hit.Color, 0.3f); //if (BoneIDs[hit.Bone] == 0)//special purpose HitData attached to trans or top // color = new Vector4(1, 0.3f, 0.3f, 0.3f); if (hit.Pos != hit.Pos2) { capsule.Render(capsuleShader, hit.Size, hit.Pos, hit.Pos2, bone, camera.MvpMatrix, color); } else { sphere.Render(sphereShader, hit.Size, hit.Pos, bone, camera.MvpMatrix, color); } } } GL.Enable(EnableCap.DepthTest); GL.Disable(EnableCap.Blend); } Matrix4 transN = Skel.GetAnimationSingleBindsTransform(0).ClearRotation().ClearScale(); int cliffHangID = RenderSettings.Instance.CliffHangID; if (cliffHangID >= 0 && cliffHangID < CliffHangData.Length) { GL.Disable(EnableCap.DepthTest); CliffHangShape shape = CliffHangData[cliffHangID]; Vector3 v1; Vector3 v2; Vector3 v3; Vector3 v4; //this makes sure the rectangle is always front facing //I had trouble using OpenGL's culling mode, I don't know why if ((shape.p1.X - shape.p2.X) * (shape.p1.Y - shape.p2.Y) > 0) { v1 = new Vector3(0, shape.p1.Y, shape.p1.X); v2 = new Vector3(0, shape.p1.Y, shape.p2.X); v3 = new Vector3(0, shape.p2.Y, shape.p2.X); v4 = new Vector3(0, shape.p2.Y, shape.p1.X); } else { v1 = new Vector3(0, shape.p1.Y, shape.p1.X); v2 = new Vector3(0, shape.p2.Y, shape.p1.X); v3 = new Vector3(0, shape.p2.Y, shape.p2.X); v4 = new Vector3(0, shape.p1.Y, shape.p2.X); } quad = new Polygon(new List <Vector3>() { v1, v2, v3, v4 }); quad.Render(polygonShader, transN, camera.MvpMatrix, new Vector4(Collision.IDColors[cliffHangID % 9], 1f)); GL.Enable(EnableCap.DepthTest); } }
public Window(ILogger <Window> logger, GameWindowSettings gameWindowSettings, NativeWindowSettings nativeWindowSettings) : base(gameWindowSettings, nativeWindowSettings) { _logger = logger; _shaderContainer = new ShaderContainer(); }
public RModel() { boneUniformBuffer = new SFGenericModel.Materials.UniformBlock(ShaderContainer.GetShader("RModel"), "Bones"); }