public void Init(OBJData data, int i)
        {
            this.data   = data;
            lines       = new List <RenderLine>();
            boundingBox = new RenderBoundingBox();
            boundingBox.Init(new BoundingBox(new Vector3(-0.5f), new Vector3(0.5f)));
            boundingBox.SetTransform(Matrix.Translation(data.vertices[i].position));

            if (data.vertices[i].unk3 < data.vertices.Length)
            {
                RenderLine line = new RenderLine();
                Vector3    pos1 = data.vertices[i].position;
                Vector3    pos2 = data.vertices[data.vertices[i].unk3].position;
                line.Init(new Vector3[] { pos1, pos2 });
                lines.Add(line);
            }

            if (data.vertices[i].unk4 < data.vertices.Length)
            {
                RenderLine line = new RenderLine();
                line.Init(new Vector3[] { data.vertices[i].position, data.vertices[data.vertices[i].unk4].position });
                lines.Add(line);
            }

            if (data.vertices[i].unk5 < data.vertices.Length)
            {
                RenderLine line = new RenderLine();
                line.Init(new Vector3[] { data.vertices[i].position, data.vertices[data.vertices[i].unk5].position });
                lines.Add(line);
            }
        }
Beispiel #2
0
        public void Shutdown()
        {
            WorldSettings.Shutdown();
            WorldSettings = null;
            Camera        = null;

            foreach (IRenderer RenderAsset in Assets.Values)
            {
                RenderAsset.Shutdown();
            }

            foreach (SpatialGrid grid in navigationGrids)
            {
                grid?.Shutdown();
            }

            navigationGrids = null;
            translokatorGrid?.Shutdown();
            translokatorGrid = null;
            selectionBox.Shutdown();
            selectionBox = null;
            TranslationGizmo.Shutdown();
            TranslationGizmo = null;
            clouds.Shutdown();
            clouds = null;
            sky.Shutdown();
            sky    = null;
            Assets = null;
            D3D?.Shutdown();
            D3D = null;
        }
 public RenderStaticCollision()
 {
     DoRender        = true;
     Transform       = Matrix.Identity;
     BoundingBox     = new RenderBoundingBox();
     SelectionColour = new Vector4(1.0f);
 }
Beispiel #4
0
 public RenderATP()
 {
     DoRender  = true;
     Transform = Matrix4x4.Identity;
     BBox      = new RenderBoundingBox();
     Path      = new RenderLine();
 }
Beispiel #5
0
 public RenderModel()
 {
     DoRender        = true;
     isUpdatedNeeded = false;
     Transform       = Matrix.Identity;
     BoundingBox     = new RenderBoundingBox();
 }
Beispiel #6
0
        public void ConvertMTKToRenderModel(M2TStructure structure)
        {
            List <Vertex[]> vertices = new List <Vertex[]>();

            LODs = new LOD[structure.Lods.Length];
            for (int i = 0; i != structure.Lods.Length; i++)
            {
                M2TStructure.Lod lod = structure.Lods[i];
                vertices.Add(lod.Vertices);
                LOD lod2 = new LOD();
                lod2.Indices    = lod.Indices;
                lod2.ModelParts = new ModelPart[lod.Parts.Length];
                for (int y = 0; y != lod.Parts.Length; y++)
                {
                    ModelPart part = new ModelPart();
                    part.NumFaces     = lod.Parts[y].NumFaces;
                    part.StartIndex   = lod.Parts[y].StartIndex;
                    part.MaterialHash = lod.Parts[y].Hash;


                    switch (part.MaterialHash)
                    {
                    case 1337:
                        part.Material = RenderStorageSingleton.Instance.Prefabs.GizmoRed;
                        break;

                    case 1338:
                        part.Material = RenderStorageSingleton.Instance.Prefabs.GizmoBlue;
                        break;

                    case 1339:
                        part.Material = RenderStorageSingleton.Instance.Prefabs.GizmoGreen;
                        break;

                    default:
                        part.Material = MaterialsManager.LookupMaterialByHash(part.MaterialHash);
                        break;
                    }
                    lod2.ModelParts[y] = part;
                }

                lod2.Vertices = new VertexLayouts.NormalLayout.Vertex[lod.Vertices.Length];
                for (int y = 0; y != lod.Vertices.Length; y++)
                {
                    var vertice = new VertexLayouts.NormalLayout.Vertex();
                    vertice.Position  = lod.Vertices[y].Position;
                    vertice.Normal    = lod.Vertices[y].Normal;
                    vertice.TexCoord0 = lod.Vertices[y].UVs[0];
                    vertice.TexCoord7 = lod.Vertices[y].UVs[3];
                    lod2.Vertices[y]  = vertice;
                }
                LODs[i] = lod2;
            }
            BoundingBox = new RenderBoundingBox();
            BoundingBox.Init(BoundingBoxExtenders.CalculateBounds(vertices));
            BoundingBox.SetTransform(Transform);
            BoundingBox.DoRender = false;
            SetupShaders();
        }
 public RenderModel()
 {
     DoRender        = true;
     isUpdatedNeeded = false;
     Transform       = Matrix.Identity;
     BoundingBox     = new RenderBoundingBox();
     SelectionColour = new Vector4(1.0f);
 }
Beispiel #8
0
        public GraphicsClass()
        {
            InitObjectStack  = new Dictionary <int, IRenderer>();
            Profile          = new Profiler();
            Assets           = new Dictionary <int, IRenderer>();
            selectionBox     = new RenderBoundingBox();
            translokatorGrid = new SpatialGrid();
            navigationGrids  = new SpatialGrid[0];

            OnSelectedObjectUpdated += OnSelectedObjectHasUpdated;
        }
Beispiel #9
0
 public void Init(OBJData data, int i)
 {
     DoRender      = true;
     this.data     = data;
     lines         = new List <RenderLine>();
     navigationBox = new RenderBoundingBox();
     navigationBox.Init(new BoundingBox(new Vector3(-0.1f), new Vector3(0.1f)));
     navigationBox.SetColour(System.Drawing.Color.Green);
     navigationBox.SetTransform(Matrix.Translation(data.vertices[i].Position));
     vertex = data.vertices[i];
 }
        public void ConvertCollisionToRender(ResourceTypes.ItemDesc.CollisionConvex convex)
        {
            DoRender    = true;
            BoundingBox = new RenderBoundingBox();
            BoundingBox.Init(new BoundingBox(new Vector3(-0.5f), new Vector3(0.5f)));
            BoundingBox.DoRender = false;

            Indices   = convex.indices;
            Vertices  = new VertexLayouts.CollisionLayout.Vertex[convex.vertices.Length];
            materials = new CollisionMaterials[convex.vertices.Length];
            for (int i = 0; i != convex.vertices.Length; i++)
            {
                VertexLayouts.CollisionLayout.Vertex vertex = new VertexLayouts.CollisionLayout.Vertex();
                vertex.Position = convex.vertices[i];
                vertex.Normal   = new Vector3(0.0f);
                vertex.Colour   = new Vector4(1.0f);
                Vertices[i]     = vertex;
            }
            CalculateNormals();
        }
Beispiel #11
0
        public void Init(OBJData data)
        {
            DoRender  = true;
            this.data = data;

            string VertexBatchID = string.Format("NavObjData_{0}", RefManager.GetNewRefID());

            PathVertexBatch = new PrimitiveBatch(PrimitiveType.Box, VertexBatchID);
            foreach (OBJData.VertexStruct Vertex in data.vertices)
            {
                RenderBoundingBox navigationBox = new RenderBoundingBox();
                navigationBox.Init(new BoundingBox(new Vector3(-0.1f), new Vector3(0.1f)));
                navigationBox.SetColour(System.Drawing.Color.Green);
                navigationBox.SetTransform(Matrix4x4.CreateTranslation(Vertex.Position));

                int PathHandle = RefManager.GetNewRefID();
                PathVertexBatch.AddObject(PathHandle, navigationBox);
                BoundingBoxes.Add(navigationBox);
            }

            OwnGraphics.OurPrimitiveManager.AddPrimitiveBatch(PathVertexBatch);
            OwnGraphics.OurPrimitiveManager.AddPrimitiveBatch(PointConnectionsBatch);
        }
Beispiel #12
0
        public GraphicsClass()
        {
            InitObjectStack     = new Dictionary <int, IRenderer>();
            Profile             = new Profiler();
            Assets              = new Dictionary <int, IRenderer>();
            selectionBox        = new RenderBoundingBox();
            translokatorGrid    = new SpatialGrid();
            navigationGrids     = new SpatialGrid[0];
            OurPrimitiveManager = new PrimitiveManager();

            OnSelectedObjectUpdated += OnSelectedObjectHasUpdated;

            // Create bespoke batches for any lines or boxes passed in via the construct stack
            string LineBatchID = string.Format("Graphics_LineBatcher_{0}", RefManager.GetNewRefID());

            LineBatch = new PrimitiveBatch(PrimitiveType.Line, LineBatchID);

            string BBoxBatchID = string.Format("Graphics_BBoxBatcher_{0}", RefManager.GetNewRefID());

            BBoxBatch = new PrimitiveBatch(PrimitiveType.Box, BBoxBatchID);

            OurPrimitiveManager.AddPrimitiveBatch(LineBatch);
            OurPrimitiveManager.AddPrimitiveBatch(BBoxBatch);
        }
Beispiel #13
0
        ////TEMP
        //public void ConvertNavOBJDataToRender(ResourceTypes.Navigation.NAVData.OBJData data)
        //{
        //    SetTransform(new Vector3(), new Matrix33());
        //    Indices = data.indices;
        //    numTriangles = (uint)(data.indices.Length);
        //    Vertices = new VertexLayouts.BasicLayout.Vertex[data.vertices.Length];
        //    for (int i = 0; i < data.vertices.Length; i++)
        //    {
        //        VertexLayouts.BasicLayout.Vertex vertex = new VertexLayouts.BasicLayout.Vertex();
        //        vertex.Position = data.vertices[i].position;
        //        vertex.Colour = new Vector4(1.0f, 0.0f, 0.0f, 1.0f);
        //        Vertices[i] = vertex;
        //    }
        //}

        public void ConvertCollisionToRender(MeshData data)
        {
            DoRender    = true;
            BoundingBox = new RenderBoundingBox();
            BoundingBox.Init(data.BoundingBox);
            BoundingBox.DoRender = false;

            Indices      = data.Indices;
            numTriangles = Convert.ToUInt32(data.Indices.Length * 3);
            Vertices     = new VertexLayouts.BasicLayout.Vertex[data.Vertices.Length];
            materials    = data.Materials;
            for (int i = 0; i != data.Vertices.Length; i++)
            {
                VertexLayouts.BasicLayout.Vertex vertex = new VertexLayouts.BasicLayout.Vertex();
                vertex.Position = data.Vertices[i];
                vertex.Colour   = new Vector4(1.0f);
                Vertices[i]     = vertex;
            }

            int materialIDX = 0;

            for (int i = 0; i != data.Indices.Length; i += 3)
            {
                switch (materials[materialIDX])
                {
                case CollisionMaterials.GrassAndSnow:
                    Vertices[data.Indices[i]].Colour     = new Vector4(0, 0.4f, 0, 1.0f);
                    Vertices[data.Indices[i + 1]].Colour = new Vector4(0, 0.4f, 0, 1.0f);
                    Vertices[data.Indices[i + 2]].Colour = new Vector4(0, 0.4f, 0, 1.0f);
                    break;

                case CollisionMaterials.Water:
                    Vertices[data.Indices[i]].Colour     = new Vector4(0, 0.3f, 0.8f, 1.0f);
                    Vertices[data.Indices[i + 1]].Colour = new Vector4(0, 0.3f, 0.8f, 1.0f);
                    Vertices[data.Indices[i + 2]].Colour = new Vector4(0, 0.3f, 0.8f, 1.0f);
                    break;

                case CollisionMaterials.Gravel:
                case CollisionMaterials.Tarmac:
                case CollisionMaterials.Sidewalk:
                case CollisionMaterials.SidewalkEdge:
                    Vertices[data.Indices[i]].Colour     = new Vector4(0.5f, 0.5f, 0.5f, 1.0f);
                    Vertices[data.Indices[i + 1]].Colour = new Vector4(0.5f, 0.5f, 0.5f, 1.0f);
                    Vertices[data.Indices[i + 2]].Colour = new Vector4(0.5f, 0.5f, 0.5f, 1.0f);
                    break;

                case CollisionMaterials.Mud:
                    Vertices[data.Indices[i]].Colour     = new Vector4(0.4f, 0.2f, 0.0f, 1.0f);
                    Vertices[data.Indices[i + 1]].Colour = new Vector4(0.4f, 0.2f, 0.0f, 1.0f);
                    Vertices[data.Indices[i + 2]].Colour = new Vector4(0.4f, 0.2f, 0.0f, 1.0f);
                    break;

                case CollisionMaterials.PlayerCollision:
                    Vertices[data.Indices[i]].Colour     = new Vector4(1.0f, 1.0f, 1.0f, 1.0f);
                    Vertices[data.Indices[i + 1]].Colour = new Vector4(1.0f, 1.0f, 1.0f, 1.0f);
                    Vertices[data.Indices[i + 2]].Colour = new Vector4(1.0f, 1.0f, 1.0f, 1.0f);
                    break;
                }
                materialIDX++;
            }
        }
Beispiel #14
0
 public RenderStaticCollision()
 {
     DoRender    = true;
     Transform   = Matrix.Identity;
     BoundingBox = new RenderBoundingBox();
 }
        public void ConvertCollisionToRender(TriangleMesh triangleMesh)
        {
            DoRender    = true;
            BoundingBox = new RenderBoundingBox();
            BoundingBox.Init(triangleMesh.BoundingBox);
            BoundingBox.DoRender = false;

            Indices   = triangleMesh.Triangles.SelectMany(t => new[] { t.v0, t.v1, t.v2 }).ToArray();
            Vertices  = new VertexLayouts.CollisionLayout.Vertex[triangleMesh.Vertices.Count];
            materials = triangleMesh.MaterialIndices.Select(m => (CollisionMaterials)m).ToArray();
            for (int i = 0; i != triangleMesh.Vertices.Count; i++)
            {
                VertexLayouts.CollisionLayout.Vertex vertex = new VertexLayouts.CollisionLayout.Vertex();
                vertex.Position = triangleMesh.Vertices[i];
                vertex.Normal   = new Vector3(0.0f);
                vertex.Colour   = new Vector4(1.0f);
                Vertices[i]     = vertex;
            }

            int materialIDX = 0;

            for (int i = 0; i != triangleMesh.Triangles.Count; i++)
            {
                switch (materials[materialIDX])
                {
                case CollisionMaterials.GrassAndSnow:
                    Vertices[triangleMesh.Triangles[i].v0].Colour = new Vector4(0, 0.4f, 0, 1.0f);
                    Vertices[triangleMesh.Triangles[i].v1].Colour = new Vector4(0, 0.4f, 0, 1.0f);
                    Vertices[triangleMesh.Triangles[i].v2].Colour = new Vector4(0, 0.4f, 0, 1.0f);
                    break;

                case CollisionMaterials.Water:
                    Vertices[triangleMesh.Triangles[i].v0].Colour = new Vector4(0, 0.3f, 0.8f, 1.0f);
                    Vertices[triangleMesh.Triangles[i].v1].Colour = new Vector4(0, 0.3f, 0.8f, 1.0f);
                    Vertices[triangleMesh.Triangles[i].v2].Colour = new Vector4(0, 0.3f, 0.8f, 1.0f);
                    break;

                case CollisionMaterials.Gravel:
                case CollisionMaterials.Tarmac:
                case CollisionMaterials.Sidewalk:
                case CollisionMaterials.SidewalkEdge:
                    Vertices[triangleMesh.Triangles[i].v0].Colour = new Vector4(0.5f, 0.5f, 0.5f, 1.0f);
                    Vertices[triangleMesh.Triangles[i].v1].Colour = new Vector4(0.5f, 0.5f, 0.5f, 1.0f);
                    Vertices[triangleMesh.Triangles[i].v2].Colour = new Vector4(0.5f, 0.5f, 0.5f, 1.0f);
                    break;

                case CollisionMaterials.Mud:
                    Vertices[triangleMesh.Triangles[i].v0].Colour = new Vector4(0.4f, 0.2f, 0.0f, 1.0f);
                    Vertices[triangleMesh.Triangles[i].v1].Colour = new Vector4(0.4f, 0.2f, 0.0f, 1.0f);
                    Vertices[triangleMesh.Triangles[i].v2].Colour = new Vector4(0.4f, 0.2f, 0.0f, 1.0f);
                    break;

                case CollisionMaterials.PlayerCollision:
                    Vertices[triangleMesh.Triangles[i].v0].Colour = new Vector4(1.0f, 1.0f, 1.0f, 1.0f);
                    Vertices[triangleMesh.Triangles[i].v1].Colour = new Vector4(1.0f, 1.0f, 1.0f, 1.0f);
                    Vertices[triangleMesh.Triangles[i].v2].Colour = new Vector4(1.0f, 1.0f, 1.0f, 1.0f);
                    break;

                default:
                    Vertices[triangleMesh.Triangles[i].v0].Colour = new Vector4(1.0f);
                    Vertices[triangleMesh.Triangles[i].v1].Colour = new Vector4(1.0f);
                    Vertices[triangleMesh.Triangles[i].v2].Colour = new Vector4(1.0f);
                    break;
                }
                materialIDX++;
            }
            CalculateNormals();
        }
Beispiel #16
0
        public bool ConvertFrameToRenderModel(FrameObjectSingleMesh mesh, FrameGeometry geom, FrameMaterial mats, IndexBuffer[] indexBuffers, VertexBuffer[] vertexBuffers)
        {
            if (mesh == null || geom == null || mats == null || indexBuffers == null || vertexBuffers == null)
            {
                return(false);
            }

            aoHash = mesh.OMTextureHash;
            SetTransform(mesh.Matrix.Position, mesh.Matrix.Matrix);
            //DoRender = (mesh.SecondaryFlags == 4097 ? true : false);
            BoundingBox = new RenderBoundingBox();
            BoundingBox.Init(mesh.Boundings);
            BoundingBox.SetTransform(Transform);
            BoundingBox.DoRender = false;
            LODs = new LOD[geom.NumLods];

            for (int i = 0; i != geom.NumLods; i++)
            {
                LOD lod = new LOD();
                lod.Indices    = indexBuffers[i].Data;
                lod.ModelParts = new ModelPart[mats.LodMatCount[i]];

                for (int z = 0; z != mats.Materials[i].Length; z++)
                {
                    lod.ModelParts[z]              = new ModelPart();
                    lod.ModelParts[z].NumFaces     = (uint)mats.Materials[i][z].NumFaces;
                    lod.ModelParts[z].StartIndex   = (uint)mats.Materials[i][z].StartIndex;
                    lod.ModelParts[z].MaterialHash = mats.Materials[i][z].MaterialHash;
                    lod.ModelParts[z].Material     = MaterialsManager.LookupMaterialByHash(lod.ModelParts[z].MaterialHash);
                }

                lod.Vertices = new VertexLayouts.NormalLayout.Vertex[geom.LOD[i].NumVertsPr];
                int vertexSize;
                Dictionary <VertexFlags, FrameLOD.VertexOffset> vertexOffsets = geom.LOD[i].GetVertexOffsets(out vertexSize);

                for (int x = 0; x != lod.Vertices.Length; x++)
                {
                    VertexLayouts.NormalLayout.Vertex vertex = new VertexLayouts.NormalLayout.Vertex();

                    if (geom.LOD[i].VertexDeclaration.HasFlag(VertexFlags.Position))
                    {
                        int startIndex = x * vertexSize + vertexOffsets[VertexFlags.Position].Offset;
                        vertex.Position = VertexTranslator.ReadPositionDataFromVB(vertexBuffers[i].Data, startIndex, geom.DecompressionFactor, geom.DecompressionOffset);
                    }

                    if (geom.LOD[i].VertexDeclaration.HasFlag(VertexFlags.Tangent))
                    {
                        int startIndex = x * vertexSize + vertexOffsets[VertexFlags.Position].Offset;
                        vertex.Tangent = VertexTranslator.ReadTangentDataFromVB(vertexBuffers[i].Data, startIndex);
                    }

                    if (geom.LOD[i].VertexDeclaration.HasFlag(VertexFlags.Normals))
                    {
                        int startIndex = x * vertexSize + vertexOffsets[VertexFlags.Normals].Offset;
                        vertex.Normal = VertexTranslator.ReadNormalDataFromVB(vertexBuffers[i].Data, startIndex);
                    }

                    if (geom.LOD[i].VertexDeclaration.HasFlag(VertexFlags.Skin))
                    {
                        //int startIndex = v * vertexSize + vertexOffsets[VertexFlags.BlendData].Offset;
                        // vertex.BlendWeight = VertexTranslator.ReadBlendWeightFromVB(vertexBuffer.Data, startIndex);
                        // vertex.BoneID = VertexTranslator.ReadBlendIDFromVB(vertexBuffer.Data, startIndex);
                    }

                    if (geom.LOD[i].VertexDeclaration.HasFlag(VertexFlags.Color))
                    {
                        //unknown
                    }

                    if (geom.LOD[i].VertexDeclaration.HasFlag(VertexFlags.TexCoords0))
                    {
                        int startIndex = x * vertexSize + vertexOffsets[VertexFlags.TexCoords0].Offset;
                        vertex.TexCoord0 = VertexTranslator.ReadTexcoordFromVB(vertexBuffers[i].Data, startIndex);
                    }

                    if (geom.LOD[i].VertexDeclaration.HasFlag(VertexFlags.TexCoords1))
                    {
                        //int startIndex = v * vertexSize + vertexOffsets[VertexFlags.TexCoords1].Offset;
                        //vertex.UVs[1] = VertexTranslator.ReadTexcoordFromVB(vertexBuffer.Data, startIndex);
                    }

                    if (geom.LOD[i].VertexDeclaration.HasFlag(VertexFlags.TexCoords2))
                    {
                        //int startIndex = v * vertexSize + vertexOffsets[VertexFlags.TexCoords2].Offset;
                        //vertex.UVs[2] = VertexTranslator.ReadTexcoordFromVB(vertexBuffer.Data, startIndex);
                    }

                    if (geom.LOD[i].VertexDeclaration.HasFlag(VertexFlags.ShadowTexture))
                    {
                        int startIndex = x * vertexSize + vertexOffsets[VertexFlags.ShadowTexture].Offset;
                        vertex.TexCoord7 = VertexTranslator.ReadTexcoordFromVB(vertexBuffers[i].Data, startIndex);
                    }

                    if (geom.LOD[i].VertexDeclaration.HasFlag(VertexFlags.Color1))
                    {
                        //unknown
                    }

                    if (geom.LOD[i].VertexDeclaration.HasFlag(VertexFlags.BBCoeffs))
                    {
                        //unknown
                    }

                    if (geom.LOD[i].VertexDeclaration.HasFlag(VertexFlags.DamageGroup))
                    {
                        //int startIndex = v * vertexSize + vertexOffsets[VertexFlags.DamageGroup].Offset;
                        //vertex.DamageGroup = VertexTranslator.ReadDamageGroupFromVB(vertexBuffer.Data, startIndex);
                    }

                    lod.Vertices[x] = vertex;
                }
                LODs[i] = lod;
            }

            SetupShaders();
            return(true);
        }