Beispiel #1
0
        public void GenerateGeometry(RenderManager Render)
        {
            Dictionary <string, GeometryModel> Models = Render.Models;

            //Generate
            foreach (KeyValuePair <string, GeometryModel> entry in Models)
            {
                Geometry3D NewBatch = new Geometry3D(entry.Key);
                NewBatch.SetVertexBuffer(entry.Value.GetBufferData(Render.Graphics), entry.Value.VertexList.ToArray());
                NewBatch.Shader      = entry.Value.Shader.Clone();
                NewBatch.DepthShader = entry.Value.DepthShader.Clone();
                NewBatch.SetIndexBuffer(GraphicsUtil.GenerateIndexBuffer(Render.Graphics, entry.Value.VertexList.Count));

                //TODO
                //Add Proper System for texture import
                foreach (KeyValuePair <string, string> Textures in entry.Value.Textures)
                {
                    if (NewBatch.Shader.Parameters[Textures.Key] != null)
                    {
                        NewBatch.Shader.Parameters[Textures.Key].SetValue(Render.Textures[Textures.Value]);
                    }
                }

                NewBatch.CurrentRenderMode = Geometry3D.RenderMode.Instanced;
                //set VertexBuffer
                Batches.Add(NewBatch);
            }
        }
Beispiel #2
0
        public void GenerateLookatCube(GraphicsDevice Graphics)
        {
            int[] Indices = new int[] { 2, 0, 1, 1, 3, 2, 7, 5, 4, 4, 6, 7, 6, 4, 0, 0, 2, 6, 3, 1, 5, 5, 7, 3, 6, 2, 3, 3, 7, 6, 0, 4, 5, 5, 1, 0 };

            Vector3[] LineLookup = new Vector3[8]
            {
                //X Axis
                new Vector3(-1.0f, -1.0f, -1.0f) * (Size + Buffer),
                new Vector3(1.0f, -1.0f, -1.0f) * (Size + Buffer),
                new Vector3(-1.0f, -1.0f, 1.0f) * (Size + Buffer),
                new Vector3(1.0f, -1.0f, 1.0f) * (Size + Buffer),

                new Vector3(-1.0f, 1.0f, -1.0f) * (Size + Buffer),
                new Vector3(1.0f, 1.0f, -1.0f) * (Size + Buffer),
                new Vector3(-1.0f, 1.0f, 1.0f) * (Size + Buffer),
                new Vector3(1.0f, 1.0f, 1.0f) * (Size + Buffer)
            };

            Geom = new Geometry3D("LookatCube");
            Geom.SetTextures(new string[] { "GridColors" });
            BasicEffect BasicEffect = new BasicEffect(Graphics);

            BasicEffect.TextureEnabled = true;
            Geom.Shader       = BasicEffect;
            Geom.Position     = Position;
            Geom.HasCull      = false;
            Geom.RenderBucket = RenderQueue.Solid;

            List <VertexPositionTexture> VertexList = new List <VertexPositionTexture>();
            Vector2 Color = new Vector2();

            switch (CubeColor)
            {
            case "red":
                Color = new Vector2(0.1875f, 0.1875f);
                break;

            case "green":
                Color = new Vector2(0.1875f, 0.3125f);
                break;

            case "blue":
                Color = new Vector2(0.3125f, 0.1875f);
                break;

            case "gray":
                Color = new Vector2(0.3125f, 0.3125f);
                break;

            default:
                Color = new Vector2(0.8125f, 0.8125f);
                break;
            }

            for (int i = Indices.Length - 1; i >= 0; i--)
            {
                VertexList.Add(new VertexPositionTexture(LineLookup[Indices[i]], Color));
            }

            VertexBuffer VertexBuffer = new VertexBuffer(Graphics, CubeVertex.VertexDeclaration, VertexList.Count, BufferUsage.WriteOnly);

            VertexBuffer.SetData(VertexList.ToArray());
            Geom.SetVertexBuffer(VertexBuffer);
        }
Beispiel #3
0
        public void GenerateGeometry(RenderManager Render)
        {
            Vector2[] tex = new Vector2[14]
            {
                new Vector2(0.25f, 0.001f),
                new Vector2(0.5f, 0.001f),
                new Vector2(0, 0.3333f),
                new Vector2(0.25f, 0.3333f),

                new Vector2(0.5f, 0.3333f),
                new Vector2(0.75f, 0.3333f),
                new Vector2(0.999f, 0.3333f),
                new Vector2(0, 0.6666f),

                new Vector2(0.25f, 0.6666f),
                new Vector2(0.5f, 0.6666f),
                new Vector2(0.75f, 0.6666f),
                new Vector2(0.9999f, 0.6666f),

                new Vector2(0.5f, 0.9999f),
                new Vector2(0.5f, 0.9999f),
            };

            Vector3[] pos = new Vector3[8]
            {
                new Vector3(-SkyBoxDistance, -SkyBoxDistance, -SkyBoxDistance),
                new Vector3(-SkyBoxDistance, SkyBoxDistance, -SkyBoxDistance),
                new Vector3(SkyBoxDistance, -SkyBoxDistance, -SkyBoxDistance),
                new Vector3(SkyBoxDistance, SkyBoxDistance, -SkyBoxDistance),

                new Vector3(-SkyBoxDistance, -SkyBoxDistance, SkyBoxDistance),
                new Vector3(-SkyBoxDistance, SkyBoxDistance, SkyBoxDistance),
                new Vector3(SkyBoxDistance, -SkyBoxDistance, SkyBoxDistance),
                new Vector3(SkyBoxDistance, SkyBoxDistance, SkyBoxDistance)
            };

            SkyBoxVertex[] Vertices = new SkyBoxVertex[36]
            {
                //bottom
                new SkyBoxVertex(pos[1], tex[8]),
                new SkyBoxVertex(pos[3], tex[9]),
                new SkyBoxVertex(pos[2], tex[13]),
                new SkyBoxVertex(pos[2], tex[13]),
                new SkyBoxVertex(pos[0], tex[12]),
                new SkyBoxVertex(pos[1], tex[8]),
                //east
                new SkyBoxVertex(pos[3], tex[9]),
                new SkyBoxVertex(pos[7], tex[4]),
                new SkyBoxVertex(pos[6], tex[5]),
                new SkyBoxVertex(pos[6], tex[5]),
                new SkyBoxVertex(pos[2], tex[10]),
                new SkyBoxVertex(pos[3], tex[9]),
                //top
                new SkyBoxVertex(pos[7], tex[4]),
                new SkyBoxVertex(pos[5], tex[3]),
                new SkyBoxVertex(pos[4], tex[0]),
                new SkyBoxVertex(pos[4], tex[0]),
                new SkyBoxVertex(pos[6], tex[1]),
                new SkyBoxVertex(pos[7], tex[4]),
                //west
                new SkyBoxVertex(pos[5], tex[3]),
                new SkyBoxVertex(pos[1], tex[8]),
                new SkyBoxVertex(pos[0], tex[7]),
                new SkyBoxVertex(pos[0], tex[7]),
                new SkyBoxVertex(pos[4], tex[2]),
                new SkyBoxVertex(pos[5], tex[3]),
                //north
                new SkyBoxVertex(pos[3], tex[9]),
                new SkyBoxVertex(pos[1], tex[8]),
                new SkyBoxVertex(pos[5], tex[3]),
                new SkyBoxVertex(pos[5], tex[3]),
                new SkyBoxVertex(pos[7], tex[4]),
                new SkyBoxVertex(pos[3], tex[9]),
                //south
                new SkyBoxVertex(pos[0], tex[11]),
                new SkyBoxVertex(pos[2], tex[10]),
                new SkyBoxVertex(pos[6], tex[5]),
                new SkyBoxVertex(pos[6], tex[5]),
                new SkyBoxVertex(pos[4], tex[6]),
                new SkyBoxVertex(pos[0], tex[11])
            };

            //Geom.SetVertexBuffer(VertexList.ToArray());
            Geom        = new Geometry3D("LookatCube");
            Geom.Shader = Render.Shaders["SkyBox"].Clone();

            VertexBuffer VertexBuffer = new VertexBuffer(Render.Graphics, SkyBoxVertex.VertexDeclaration, Vertices.Length, BufferUsage.WriteOnly);

            VertexBuffer.SetData(Vertices);
            Geom.SetVertexBuffer(VertexBuffer);

            Geom.HasCull      = false;
            Geom.Position     = new Vector3();
            Geom.RenderBucket = Geometry3D.RenderQueue.Solid;
            Geom.Shader.Parameters["DiffuseMap"].SetValue(Render.Textures["SkyMap"]);
        }