Exemple #1
0
        public void Construct(Octahedron settings, Action <Vector3, Vector3, Vector2> appendVertex, Action <Int3> appendIndex)
        {
            // This is the golden ratio
            float t = (1.0f + (float)Math.Sqrt(5.0f)) / 2.0f;

            Pos3Norm3Tex2Vertex v = new Pos3Norm3Tex2Vertex();

            v.Position = Vector3.Normalize(new Vector3(1.0f, 0, 0)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0);
            appendVertex(v.Position * settings.Size, v.Normals, v.TexCoords);
            v.Position = Vector3.Normalize(new Vector3(-1.0f, 0, 0)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0);
            appendVertex(v.Position * settings.Size, v.Normals, v.TexCoords);
            v.Position = Vector3.Normalize(new Vector3(0, 1.0f, 0)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0);
            appendVertex(v.Position * settings.Size, v.Normals, v.TexCoords);
            v.Position = Vector3.Normalize(new Vector3(0, -1.0f, 0)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0);
            appendVertex(v.Position * settings.Size, v.Normals, v.TexCoords);

            v.Position = Vector3.Normalize(new Vector3(0, 0, -1.0f)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0);
            appendVertex(v.Position * settings.Size, v.Normals, v.TexCoords);
            v.Position = Vector3.Normalize(new Vector3(0, 0, 1.0f)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0);
            appendVertex(v.Position * settings.Size, v.Normals, v.TexCoords);

            appendIndex(new Int3(0, 4, 2));
            appendIndex(new Int3(0, 2, 5));
            appendIndex(new Int3(0, 3, 4));
            appendIndex(new Int3(0, 5, 3));
            appendIndex(new Int3(1, 2, 4));
            appendIndex(new Int3(1, 5, 2));
            appendIndex(new Int3(1, 4, 3));
            appendIndex(new Int3(1, 3, 5));
        }
Exemple #2
0
        public static DX11VertexGeometry LineStrip3d(DX11RenderContext context, List <Vector3> points, List <Vector3> directions, bool loop)
        {
            //Use direction verctor as normal, useful when we have analytical derivatives for direction
            DX11VertexGeometry geom = new DX11VertexGeometry(context);

            int ptcnt = Math.Max(points.Count, directions.Count);

            int vcount = loop ? ptcnt + 1 : ptcnt;

            FeralTic.DX11.Geometry.Pos3Norm3Tex2Vertex[] verts = new FeralTic.DX11.Geometry.Pos3Norm3Tex2Vertex[vcount];

            float inc = loop ? 1.0f / (float)vcount : 1.0f / ((float)vcount + 1.0f);

            float curr = 0.0f;


            for (int i = 0; i < ptcnt; i++)
            {
                verts[i].Position    = points[i % points.Count];
                verts[i].Normals     = directions[i % directions.Count];
                verts[i].TexCoords.X = curr;
                curr += inc;
            }

            if (loop)
            {
                verts[ptcnt].Position    = points[0];
                verts[ptcnt].Normals     = directions[0];
                verts[ptcnt].TexCoords.X = 1.0f;
            }


            DataStream ds = new DataStream(vcount * FeralTic.DX11.Geometry.Pos3Norm3Tex2Vertex.VertexSize, true, true);

            ds.Position = 0;
            ds.WriteRange(verts);
            ds.Position = 0;

            var vbuffer = new SlimDX.Direct3D11.Buffer(context.Device, ds, new BufferDescription()
            {
                BindFlags      = BindFlags.VertexBuffer,
                CpuAccessFlags = CpuAccessFlags.None,
                OptionFlags    = ResourceOptionFlags.None,
                SizeInBytes    = (int)ds.Length,
                Usage          = ResourceUsage.Default
            });

            ds.Dispose();

            geom.VertexBuffer  = vbuffer;
            geom.InputLayout   = FeralTic.DX11.Geometry.Pos3Norm3Tex2Vertex.Layout;
            geom.Topology      = PrimitiveTopology.LineStrip;
            geom.VerticesCount = vcount;
            geom.VertexSize    = FeralTic.DX11.Geometry.Pos3Norm3Tex2Vertex.VertexSize;

            geom.HasBoundingBox = false;

            return(geom);
        }
        public DX11VertexGeometry LineStrip3d(List<Vector3> points,List<Vector3> directions, bool loop)
        {
            //Use direction verctor as normal, useful when we have analytical derivatives for direction
            DX11VertexGeometry geom = new DX11VertexGeometry(context);

            int ptcnt = Math.Max(points.Count, directions.Count);

            int vcount = loop ? ptcnt + 1 : ptcnt;

            Pos3Norm3Tex2Vertex[] verts = new Pos3Norm3Tex2Vertex[vcount];

            float inc = loop ? 1.0f / (float)vcount : 1.0f / ((float)vcount + 1.0f);

            float curr = 0.0f;


            for (int i = 0; i < ptcnt; i++)
            {
                verts[i].Position = points[i % points.Count];
                verts[i].Normals = directions[i % directions.Count];
                verts[i].TexCoords.X = curr;
                curr += inc;
            }

            if (loop)
            {
                verts[ptcnt].Position = points[0];
                verts[ptcnt].Normals = directions[0];
                verts[ptcnt].TexCoords.X = 1.0f;
            }


            DataStream ds = new DataStream(vcount * Pos3Tex2Vertex.VertexSize, true, true);
            ds.Position = 0;
            ds.WriteRange(verts);
            ds.Position = 0;

            var vbuffer = new SlimDX.Direct3D11.Buffer(context.Device, ds, new BufferDescription()
            {
                BindFlags = BindFlags.VertexBuffer,
                CpuAccessFlags = CpuAccessFlags.None,
                OptionFlags = ResourceOptionFlags.None,
                SizeInBytes = (int)ds.Length,
                Usage = ResourceUsage.Default
            });

            ds.Dispose();

            geom.VertexBuffer = vbuffer;
            geom.InputLayout = Pos3Norm3Tex2Vertex.Layout;
            geom.Topology = PrimitiveTopology.LineStrip;
            geom.VerticesCount = vcount;
            geom.VertexSize = Pos3Norm3Tex2Vertex.VertexSize;

            geom.HasBoundingBox = false;

            return geom;
        }
Exemple #4
0
 public TextTesselator()
 {
     vertex = new Pos3Norm3Tex2Vertex()
     {
         Position  = Vector3.Zero,
         Normals   = norm,
         TexCoords = uv
     };
 }
        public void Construct(Isocahedron settings, Action <Vector3, Vector3, Vector2> appendVertex, Action <Int3> appendIndex)
        {
            // This is the golden ratio
            float t = (1.0f + (float)Math.Sqrt(5.0f)) / 2.0f;

            Pos3Norm3Tex2Vertex v = new Pos3Norm3Tex2Vertex();

            v.Position = Vector3.Normalize(new Vector3(-1, t, 0)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0);
            appendVertex(v.Position * settings.Size, v.Normals, v.TexCoords);
            v.Position = Vector3.Normalize(new Vector3(1, t, 0)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0);
            appendVertex(v.Position * settings.Size, v.Normals, v.TexCoords);
            v.Position = Vector3.Normalize(new Vector3(-1, -t, 0)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0);
            appendVertex(v.Position * settings.Size, v.Normals, v.TexCoords);
            v.Position = Vector3.Normalize(new Vector3(1, -t, 0)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0);
            appendVertex(v.Position * settings.Size, v.Normals, v.TexCoords);

            v.Position = Vector3.Normalize(new Vector3(0, -1, t)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0);
            appendVertex(v.Position * settings.Size, v.Normals, v.TexCoords);
            v.Position = Vector3.Normalize(new Vector3(0, 1, t)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0);
            appendVertex(v.Position * settings.Size, v.Normals, v.TexCoords);
            v.Position = Vector3.Normalize(new Vector3(0, -1, -t)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0);
            appendVertex(v.Position * settings.Size, v.Normals, v.TexCoords);
            v.Position = Vector3.Normalize(new Vector3(0, 1, -t)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0);
            appendVertex(v.Position * settings.Size, v.Normals, v.TexCoords);

            v.Position = Vector3.Normalize(new Vector3(t, 0, -1)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0);
            appendVertex(v.Position * settings.Size, v.Normals, v.TexCoords);
            v.Position = Vector3.Normalize(new Vector3(t, 0, 1)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0);
            appendVertex(v.Position * settings.Size, v.Normals, v.TexCoords);
            v.Position = Vector3.Normalize(new Vector3(-t, 0, -1)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0);
            appendVertex(v.Position * settings.Size, v.Normals, v.TexCoords);
            v.Position = Vector3.Normalize(new Vector3(-t, 0, 1)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0);
            appendVertex(v.Position * settings.Size, v.Normals, v.TexCoords);

            appendIndex(new Int3(0, 11, 5));
            appendIndex(new Int3(0, 5, 1));
            appendIndex(new Int3(0, 1, 7));
            appendIndex(new Int3(0, 7, 10));
            appendIndex(new Int3(0, 10, 11));
            appendIndex(new Int3(1, 5, 9));
            appendIndex(new Int3(5, 11, 4));
            appendIndex(new Int3(11, 10, 2));
            appendIndex(new Int3(10, 7, 6));
            appendIndex(new Int3(7, 1, 8));
            appendIndex(new Int3(3, 9, 4));
            appendIndex(new Int3(3, 4, 2));
            appendIndex(new Int3(3, 2, 6));
            appendIndex(new Int3(3, 6, 8));
            appendIndex(new Int3(3, 8, 9));
            appendIndex(new Int3(4, 9, 5));
            appendIndex(new Int3(2, 4, 11));
            appendIndex(new Int3(6, 2, 10));
            appendIndex(new Int3(8, 6, 7));
            appendIndex(new Int3(9, 8, 1));
        }
        public DX11IndexedGeometry Tetrahedron(Tetrahedron settings)
        {
            DX11IndexedGeometry geom = new DX11IndexedGeometry(context);

            geom.Tag           = settings;
            geom.PrimitiveType = settings.PrimitiveType;
            geom.VerticesCount = 4;
            geom.InputLayout   = Pos3Norm3Tex2Vertex.Layout;
            geom.VertexSize    = Pos3Norm3Tex2Vertex.VertexSize;
            geom.Topology      = PrimitiveTopology.TriangleList;


            DataStream ds = new DataStream(4 * Pos3Norm3Tex2Vertex.VertexSize, false, true);

            Pos3Norm3Tex2Vertex v = new Pos3Norm3Tex2Vertex();

            v.Position  = Vector3.Normalize(new Vector3(1, 1, 1)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0);
            v.Position *= settings.Radius;
            ds.Write <Pos3Norm3Tex2Vertex>(v);

            v.Position  = Vector3.Normalize(new Vector3(-1, -1, 1)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0);
            v.Position *= settings.Radius;
            ds.Write <Pos3Norm3Tex2Vertex>(v);

            v.Position  = Vector3.Normalize(new Vector3(1, -1, -1)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0);
            v.Position *= settings.Radius;
            ds.Write <Pos3Norm3Tex2Vertex>(v);

            v.Position  = Vector3.Normalize(new Vector3(-1, 1, -1)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0);
            v.Position *= settings.Radius;
            ds.Write <Pos3Norm3Tex2Vertex>(v);


            geom.VertexBuffer = BufferHelper.CreateVertexBuffer(context, ds, true);

            var indexstream = new DataStream(12 * 4, true, true);

            int[] inds = new int[] {
                0, 1, 2,
                1, 2, 3,
                2, 3, 0,
                3, 0, 1
            };

            indexstream.WriteRange(inds);

            geom.IndexBuffer = new DX11IndexBuffer(context, indexstream, false, true);

            geom.HasBoundingBox = true;
            geom.BoundingBox    = new BoundingBox(new Vector3(-1, -1, -1), new Vector3(1, 1, 1));
            return(geom);
        }
        public DX11IndexedGeometry Tetrahedron(Vector3 size)
        {
            DX11IndexedGeometry geom = new DX11IndexedGeometry(context);
            geom.VerticesCount = 4;
            geom.InputLayout = Pos3Norm3Tex2Vertex.Layout;
            geom.VertexSize = Pos3Norm3Tex2Vertex.VertexSize;
            geom.Topology = PrimitiveTopology.TriangleList;

            // This is the golden ratio
            float t = (1.0f + (float)Math.Sqrt(5.0f)) / 2.0f;

            DataStream ds = new DataStream(4 * Pos3Norm3Tex2Vertex.VertexSize, false, true);

            Pos3Norm3Tex2Vertex v = new Pos3Norm3Tex2Vertex();

            // TODO fibo 2012-03-21:
            // should be nice to have the four tetrahedra embedded in a dodecahedron
            // that's why I just commented the coordinates of the dodecahedron points
            //v.Position = new Vector3(-1, t, 0); v.Normals = v.Position; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v);
            v.Position = new Vector3(1, t, 0); v.Normals = v.Position; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v);
            //v.Position = new Vector3(-1, -t, 0); v.Normals = v.Position; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v);
            //v.Position = new Vector3(1, -t, 0); v.Normals = v.Position; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v);

            //v.Position = new Vector3(0, -1, t); v.Normals = v.Position; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v);
            v.Position = new Vector3(0, 1, t); v.Normals = v.Position; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v);
            //v.Position = new Vector3(0, -1, -t); v.Normals = v.Position; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v);
            //v.Position = new Vector3(0, 1, -t); v.Normals = v.Position; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v);

            //v.Position = new Vector3(t, 0, -1); v.Normals = v.Position; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v);
            v.Position = new Vector3(t, 0, 1); v.Normals = v.Position; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v);
            //v.Position = new Vector3(-t, 0, -1); v.Normals = v.Position; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v);
            //v.Position = new Vector3(-t, 0, 1); v.Normals = v.Position; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v);

            geom.VertexBuffer = BufferHelper.CreateVertexBuffer(context, ds, true);

            var indexstream = new DataStream(12 * 4, true, true);

            int[] inds = new int[] {
                0,1,2,
                1,2,3,
                2,3,0,
                3,0,1 };

            indexstream.WriteRange(inds);

            geom.IndexBuffer = new DX11IndexBuffer(context, indexstream, false, true);

            geom.HasBoundingBox = true;
            geom.BoundingBox = new BoundingBox(new Vector3(-1, -1, -1), new Vector3(1, 1, 1));
            return geom;
        }
        public DX11IndexedGeometry Octahedron(Octahedron settings)
        {
            DX11IndexedGeometry geom = new DX11IndexedGeometry(context);
            geom.PrimitiveType = settings.PrimitiveType;
            geom.Tag = settings;
            geom.VerticesCount = 6;
            geom.InputLayout = Pos3Norm3Tex2Vertex.Layout;
            geom.VertexSize = Pos3Norm3Tex2Vertex.VertexSize;
            geom.Topology = PrimitiveTopology.TriangleList;

            DataStream ds = new DataStream(6 * Pos3Norm3Tex2Vertex.VertexSize, false, true);

            Pos3Norm3Tex2Vertex v = new Pos3Norm3Tex2Vertex();

            Vector3 size = settings.Size;

            v.Position = Vector3.Normalize(new Vector3(1.0f,0,0)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v);
            v.Position = Vector3.Normalize(new Vector3(-1.0f,0,0)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v);
            v.Position = Vector3.Normalize(new Vector3(0,1.0f,0)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v);
            v.Position = Vector3.Normalize(new Vector3(0,-1.0f,0)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v);

            v.Position = Vector3.Normalize(new Vector3(0,0,-1.0f)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v);
            v.Position = Vector3.Normalize(new Vector3(0,0, 1.0f)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v);

            

            geom.VertexBuffer = BufferHelper.CreateVertexBuffer(context, ds, true);

            var indexstream = new DataStream(24 * 4, true, true);

            int[] inds = new int[] { 
                0,4,2,
                0,2,5, 
                0,3,4,
                0,5,3,
                1,2,4,
                1,5,2,
                1,4,3,
                1,3,5 };

            indexstream.WriteRange(inds);
            
            geom.IndexBuffer = new DX11IndexBuffer(context, indexstream, false, true);

            geom.HasBoundingBox = true;
            geom.BoundingBox = new BoundingBox(new Vector3(-1, -1, -1), new Vector3(1, 1, 1));
            return geom;
        }
        public void Update(IPluginIO pin, DX11RenderContext context)
        {
            for (int i = 0; i < this.FOutput.SliceCount; i++)
            {
                bool update = this.FInvalidate;
                DX11IndexedGeometry geom;
                if (!this.FOutput[i].Contains(context))
                {
                    geom = new DX11IndexedGeometry(context);
                    geom.InputLayout = Pos3Norm3Tex2Vertex.Layout;
                    geom.VertexSize = Pos3Norm3Tex2Vertex.VertexSize;
                    geom.HasBoundingBox = false;
                    geom.Topology = PrimitiveTopology.TriangleList;

                    var indexstream = new DataStream(KinectRuntime.FACE_INDICES.Length * 4, true, true);
                    indexstream.WriteRange(KinectRuntime.FACE_INDICES);
                    indexstream.Position = 0;

                    geom.IndexBuffer = new DX11IndexBuffer(context, indexstream, false, true);

                    geom.VerticesCount = this.FInFrame[i].GetProjected3DShape().Count;

                    var vbuffer = new SlimDX.Direct3D11.Buffer(context.Device, new BufferDescription()
                    {
                        BindFlags = BindFlags.VertexBuffer,
                        CpuAccessFlags = CpuAccessFlags.Write,
                        OptionFlags = ResourceOptionFlags.None,
                        SizeInBytes = geom.VerticesCount * geom.VertexSize,
                        Usage = ResourceUsage.Dynamic
                    });
                    geom.VertexBuffer = vbuffer;

                    this.FOutput[i][context] = geom;
                    update = true;
                }
                else
                {
                    geom = this.FOutput[i][context];
                }

                if (update)
                {
                    DataStream ds = geom.LockVertexBuffer();
                    ds.Position = 0;

                    EnumIndexableCollection<FeaturePoint, PointF> pp = this.FInFrame[i].GetProjected3DShape();
                    EnumIndexableCollection<FeaturePoint, Vector3DF> p = this.FInFrame[i].Get3DShape();

                    Vector3[] norms = new Vector3[p.Count];

                    int[] inds = KinectRuntime.FACE_INDICES;
                    int tricount = inds.Length / 3;
                    //Compute smoothed normals
                    for (int j = 0; j < tricount; j++)
                    {
                        int i1 = inds[j * 3];
                        int i2 = inds[j * 3 + 1];
                        int i3 = inds[j * 3 + 2];

                        Vector3 v1 = p[i1].SlimVector();
                        Vector3 v2 = p[i2].SlimVector();
                        Vector3 v3 = p[i3].SlimVector();

                        Vector3 faceEdgeA = v2 - v1;
                        Vector3 faceEdgeB = v1 - v3;
                        Vector3 norm = Vector3.Cross(faceEdgeB, faceEdgeA);

                        norms[i1] += norm; norms[i2] += norm; norms[i3] += norm;

                    }

                    for (int j = 0; j < geom.VerticesCount; j++)
                    {
                        Pos3Norm3Tex2Vertex vertex = new Pos3Norm3Tex2Vertex();
                        Vector3DF v = p[j];
                        vertex.Position = new Vector3(v.X, v.Y, v.Z);
                        vertex.Normals = Vector3.Normalize(norms[j]);
                        vertex.TexCoords = new Vector2(0, 0);
                        ds.Write<Pos3Norm3Tex2Vertex>(vertex);
                    }

                    geom.UnlockVertexBuffer();
                }
            }
        }
        public DX11IndexedGeometry Isocahedron(Vector3 size)
        {
            DX11IndexedGeometry geom = new DX11IndexedGeometry(context);
            geom.VerticesCount = 12;
            geom.InputLayout = Pos3Norm3Tex2Vertex.Layout;
            geom.VertexSize = Pos3Norm3Tex2Vertex.VertexSize;
            geom.Topology = PrimitiveTopology.TriangleList;

            float t = (1.0f + (float)Math.Sqrt(5.0f)) / 2.0f;

            DataStream ds = new DataStream(12 * Pos3Norm3Tex2Vertex.VertexSize, false, true);

            Pos3Norm3Tex2Vertex v = new Pos3Norm3Tex2Vertex();

            v.Position = Vector3.Normalize(new Vector3(-1, t, 0))*0.5f; v.Normals = v.Position*2.0f; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v);
            v.Position = Vector3.Normalize(new Vector3(1, t, 0)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v);
            v.Position = Vector3.Normalize(new Vector3(-1, -t, 0)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v);
            v.Position = Vector3.Normalize(new Vector3(1, -t, 0)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v);

            v.Position = Vector3.Normalize(new Vector3(0, -1, t)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v);
            v.Position = Vector3.Normalize(new Vector3(0, 1, t)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v);
            v.Position = Vector3.Normalize(new Vector3(0, -1, -t)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v);
            v.Position = Vector3.Normalize(new Vector3(0, 1, -t)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v);

            v.Position = Vector3.Normalize(new Vector3(t, 0, -1)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v);
            v.Position = Vector3.Normalize(new Vector3(t, 0, 1)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v);
            v.Position = Vector3.Normalize(new Vector3(-t, 0, -1)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v);
            v.Position = Vector3.Normalize(new Vector3(-t, 0, 1)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0); ds.Write<Pos3Norm3Tex2Vertex>(v);

            geom.VertexBuffer = BufferHelper.CreateVertexBuffer(context, ds, true);

            var indexstream = new DataStream(60 * 4, true, true);

            int[] inds = new int[] {
                0,11,5,
                0,5,1,
                0,1,7,
                0,7,10,
                0,10,11,
                1,5,9,
                5,11,4,
                11,10,2,
                10,7,6,
                7,1,8,
                3,9,4,
                3,4,2,
                3,2,6,
                3,6,8,
                3,8,9,
                4,9,5,
                2,4,11,
                6,2,10,
                8,6,7,
                9,8,1 };

            indexstream.WriteRange(inds);

            geom.IndexBuffer = new DX11IndexBuffer(context, indexstream, false, true);

            geom.HasBoundingBox = true;
            geom.BoundingBox = new BoundingBox(new Vector3(-1, -1, -1), new Vector3(1, 1, 1));
            return geom;
        }
Exemple #11
0
        public DX11IndexedGeometry Isocahedron(Isocahedron settings)
        {
            DX11IndexedGeometry geom = new DX11IndexedGeometry(context);

            geom.PrimitiveType = settings.PrimitiveType;
            geom.Tag           = settings;
            geom.VerticesCount = 12;
            geom.InputLayout   = Pos3Norm3Tex2Vertex.Layout;
            geom.VertexSize    = Pos3Norm3Tex2Vertex.VertexSize;
            geom.Topology      = PrimitiveTopology.TriangleList;

            // This is the golden ratio
            float t = (1.0f + (float)Math.Sqrt(5.0f)) / 2.0f;

            DataStream ds = new DataStream(12 * Pos3Norm3Tex2Vertex.VertexSize, false, true);

            Pos3Norm3Tex2Vertex v = new Pos3Norm3Tex2Vertex();

            v.Position  = Vector3.Normalize(new Vector3(-1, t, 0)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0);
            v.Position *= settings.Radius;
            ds.Write <Pos3Norm3Tex2Vertex>(v);

            v.Position  = Vector3.Normalize(new Vector3(1, t, 0)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0);
            v.Position *= settings.Radius;
            ds.Write <Pos3Norm3Tex2Vertex>(v);

            v.Position  = Vector3.Normalize(new Vector3(-1, -t, 0)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0);
            v.Position *= settings.Radius;
            ds.Write <Pos3Norm3Tex2Vertex>(v);

            v.Position  = Vector3.Normalize(new Vector3(1, -t, 0)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0);
            v.Position *= settings.Radius;
            ds.Write <Pos3Norm3Tex2Vertex>(v);

            v.Position  = Vector3.Normalize(new Vector3(0, -1, t)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0);
            v.Position *= settings.Radius;
            ds.Write <Pos3Norm3Tex2Vertex>(v);

            v.Position  = Vector3.Normalize(new Vector3(0, 1, t)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0);
            v.Position *= settings.Radius;
            ds.Write <Pos3Norm3Tex2Vertex>(v);

            v.Position  = Vector3.Normalize(new Vector3(0, -1, -t)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0);
            v.Position *= settings.Radius;
            ds.Write <Pos3Norm3Tex2Vertex>(v);

            v.Position  = Vector3.Normalize(new Vector3(0, 1, -t)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0);
            v.Position *= settings.Radius;
            ds.Write <Pos3Norm3Tex2Vertex>(v);

            v.Position  = Vector3.Normalize(new Vector3(t, 0, -1)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0);
            v.Position *= settings.Radius;
            ds.Write <Pos3Norm3Tex2Vertex>(v);

            v.Position  = Vector3.Normalize(new Vector3(t, 0, 1)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0);
            v.Position *= settings.Radius;
            ds.Write <Pos3Norm3Tex2Vertex>(v);

            v.Position  = Vector3.Normalize(new Vector3(-t, 0, -1)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0);
            v.Position *= settings.Radius;
            ds.Write <Pos3Norm3Tex2Vertex>(v);

            v.Position  = Vector3.Normalize(new Vector3(-t, 0, 1)) * 0.5f; v.Normals = v.Position * 2.0f; v.TexCoords = new Vector2(0, 0);
            v.Position *= settings.Radius;
            ds.Write <Pos3Norm3Tex2Vertex>(v);



            geom.VertexBuffer = BufferHelper.CreateVertexBuffer(context, ds, true);

            var indexstream = new DataStream(60 * 4, true, true);

            int[] inds = new int[] {
                0, 11, 5,
                0, 5, 1,
                0, 1, 7,
                0, 7, 10,
                0, 10, 11,
                1, 5, 9,
                5, 11, 4,
                11, 10, 2,
                10, 7, 6,
                7, 1, 8,
                3, 9, 4,
                3, 4, 2,
                3, 2, 6,
                3, 6, 8,
                3, 8, 9,
                4, 9, 5,
                2, 4, 11,
                6, 2, 10,
                8, 6, 7,
                9, 8, 1
            };

            indexstream.WriteRange(inds);

            geom.IndexBuffer = new DX11IndexBuffer(context, indexstream, false, true);

            geom.HasBoundingBox = true;
            geom.BoundingBox    = new BoundingBox(new Vector3(-1, -1, -1), new Vector3(1, 1, 1));
            return(geom);
        }
Exemple #12
0
        public void Construct(IcoSphere settings, Action <Vector3, Vector3, Vector2> appendVertex, Action <Int3> appendIndex)
        {
            float radius = settings.Radius;
            int   subdiv = settings.SubDivisions;


            List <Pos3Norm3Tex2Vertex> vertices = new List <Pos3Norm3Tex2Vertex>();
            Pos3Norm3Tex2Vertex        v        = new Pos3Norm3Tex2Vertex();

            float t = (1.0f + (float)Math.Sqrt(5.0f)) / 2.0f;

            //TODO : Add texcoord
            v.TexCoords = new Vector2(0, 0);

            //Isocahedron
            v.Normals = Vector3.Normalize(new Vector3(-1, t, 0)); v.Position = v.Normals * radius; vertices.Add(v);
            v.Normals = Vector3.Normalize(new Vector3(1, t, 0)); v.Position = v.Normals * radius; vertices.Add(v);
            v.Normals = Vector3.Normalize(new Vector3(-1, -t, 0)); v.Position = v.Normals * radius; vertices.Add(v);
            v.Normals = Vector3.Normalize(new Vector3(1, -t, 0)); v.Position = v.Normals * radius; vertices.Add(v);

            v.Normals = Vector3.Normalize(new Vector3(0, -1, t)); v.Position = v.Normals * radius; vertices.Add(v);
            v.Normals = Vector3.Normalize(new Vector3(0, 1, t)); v.Position = v.Normals * radius; vertices.Add(v);
            v.Normals = Vector3.Normalize(new Vector3(0, -1, -t)); v.Position = v.Normals * radius; vertices.Add(v);
            v.Normals = Vector3.Normalize(new Vector3(0, 1, -t)); v.Position = v.Normals * radius; vertices.Add(v);

            v.Normals = Vector3.Normalize(new Vector3(t, 0, -1)); v.Position = v.Normals * radius; vertices.Add(v);
            v.Normals = Vector3.Normalize(new Vector3(t, 0, 1)); v.Position = v.Normals * radius; vertices.Add(v);
            v.Normals = Vector3.Normalize(new Vector3(-t, 0, -1)); v.Position = v.Normals * radius; vertices.Add(v);
            v.Normals = Vector3.Normalize(new Vector3(-t, 0, 1)); v.Position = v.Normals * radius; vertices.Add(v);

            int[] inds = new int[] {
                0, 11, 5,
                0, 5, 1,
                0, 1, 7,
                0, 7, 10,
                0, 10, 11,
                1, 5, 9,
                5, 11, 4,
                11, 10, 2,
                10, 7, 6,
                7, 1, 8,
                3, 9, 4,
                3, 4, 2,
                3, 2, 6,
                3, 6, 8,
                3, 8, 9,
                4, 9, 5,
                2, 4, 11,
                6, 2, 10,
                8, 6, 7,
                9, 8, 1
            };

            List <int> indices = new List <int>(inds);

            Pos3Norm3Tex2Vertex newvertex = new Pos3Norm3Tex2Vertex();

            for (int iter = 0; iter < subdiv; iter++)
            {
                List <int> newindices = new List <int>();

                for (int i = 0; i < indices.Count / 3; i++)
                {
                    //Grab Indices
                    int i1 = indices[i * 3];
                    int i2 = indices[i * 3 + 1];
                    int i3 = indices[i * 3 + 2];

                    //Get Vertices
                    Pos3Norm3Tex2Vertex v1 = vertices[i1];
                    Pos3Norm3Tex2Vertex v2 = vertices[i2];
                    Pos3Norm3Tex2Vertex v3 = vertices[i3];

                    Vector3 e1 = (v1.Position + v2.Position) * 0.5f;
                    Vector3 e2 = (v2.Position + v3.Position) * 0.5f;
                    Vector3 e3 = (v3.Position + v1.Position) * 0.5f;

                    int ie1 = vertices.Count;
                    int ie2 = vertices.Count + 1;
                    int ie3 = vertices.Count + 2;

                    //Push 3 new vertices
                    newvertex.Normals  = Vector3.Normalize(e1);
                    newvertex.Position = newvertex.Normals * radius;
                    vertices.Add(newvertex);
                    newvertex.Normals  = Vector3.Normalize(e2);
                    newvertex.Position = newvertex.Normals * radius;
                    vertices.Add(newvertex);
                    newvertex.Normals  = Vector3.Normalize(e3);
                    newvertex.Position = newvertex.Normals * radius;
                    vertices.Add(newvertex);

                    //Push 4 triangles
                    newindices.Add(ie1); newindices.Add(ie2); newindices.Add(ie3);
                    newindices.Add(i1); newindices.Add(ie1); newindices.Add(ie3);
                    newindices.Add(i2); newindices.Add(ie2); newindices.Add(ie1);
                    newindices.Add(i3); newindices.Add(ie3); newindices.Add(ie2);
                }

                //Swap
                indices = newindices;
            }

            vertices.ForEach(ve => appendVertex(ve.Position, ve.Normals, ve.TexCoords));
            for (int i = 0; i < indices.Count / 3; i++)
            {
                int i1 = indices[i * 3];
                int i2 = indices[i * 3 + 1];
                int i3 = indices[i * 3 + 2];
                appendIndex(new Int3(i1, i2, i3));
            }
        }
        public DX11IndexedGeometry IcoSphere(IcoSphere settings)
        {
            float radius = settings.Radius;
            int   subdiv = settings.SubDivisions;


            List <Pos3Norm3Tex2Vertex> vertices = new List <Pos3Norm3Tex2Vertex>();
            Pos3Norm3Tex2Vertex        v        = new Pos3Norm3Tex2Vertex();

            float t = (1.0f + (float)Math.Sqrt(5.0f)) / 2.0f;

            //TODO : Add texcoord
            v.TexCoords = new Vector2(0, 0);

            //Isocahedron
            v.Normals = Vector3.Normalize(new Vector3(-1, t, 0)); v.Position = v.Normals * radius; vertices.Add(v);
            v.Normals = Vector3.Normalize(new Vector3(1, t, 0)); v.Position = v.Normals * radius; vertices.Add(v);
            v.Normals = Vector3.Normalize(new Vector3(-1, -t, 0)); v.Position = v.Normals * radius; vertices.Add(v);
            v.Normals = Vector3.Normalize(new Vector3(1, -t, 0)); v.Position = v.Normals * radius; vertices.Add(v);

            v.Normals = Vector3.Normalize(new Vector3(0, -1, t)); v.Position = v.Normals * radius; vertices.Add(v);
            v.Normals = Vector3.Normalize(new Vector3(0, 1, t)); v.Position = v.Normals * radius; vertices.Add(v);
            v.Normals = Vector3.Normalize(new Vector3(0, -1, -t)); v.Position = v.Normals * radius; vertices.Add(v);
            v.Normals = Vector3.Normalize(new Vector3(0, 1, -t)); v.Position = v.Normals * radius; vertices.Add(v);

            v.Normals = Vector3.Normalize(new Vector3(t, 0, -1)); v.Position = v.Normals * radius; vertices.Add(v);
            v.Normals = Vector3.Normalize(new Vector3(t, 0, 1)); v.Position = v.Normals * radius; vertices.Add(v);
            v.Normals = Vector3.Normalize(new Vector3(-t, 0, -1)); v.Position = v.Normals * radius; vertices.Add(v);
            v.Normals = Vector3.Normalize(new Vector3(-t, 0, 1)); v.Position = v.Normals * radius; vertices.Add(v);

            int[] inds = new int[] {
                0, 11, 5,
                0, 5, 1,
                0, 1, 7,
                0, 7, 10,
                0, 10, 11,
                1, 5, 9,
                5, 11, 4,
                11, 10, 2,
                10, 7, 6,
                7, 1, 8,
                3, 9, 4,
                3, 4, 2,
                3, 2, 6,
                3, 6, 8,
                3, 8, 9,
                4, 9, 5,
                2, 4, 11,
                6, 2, 10,
                8, 6, 7,
                9, 8, 1
            };

            List <int> indices = new List <int>(inds);

            Pos3Norm3Tex2Vertex newvertex = new Pos3Norm3Tex2Vertex();

            for (int iter = 0; iter < subdiv; iter++)
            {
                List <int> newindices = new List <int>();

                for (int i = 0; i < indices.Count / 3; i++)
                {
                    //Grab Indices
                    int i1 = indices[i * 3];
                    int i2 = indices[i * 3 + 1];
                    int i3 = indices[i * 3 + 2];

                    //Get Vertices
                    Pos3Norm3Tex2Vertex v1 = vertices[i1];
                    Pos3Norm3Tex2Vertex v2 = vertices[i2];
                    Pos3Norm3Tex2Vertex v3 = vertices[i3];

                    Vector3 e1 = (v1.Position + v2.Position) * 0.5f;
                    Vector3 e2 = (v2.Position + v3.Position) * 0.5f;
                    Vector3 e3 = (v3.Position + v1.Position) * 0.5f;

                    int ie1 = vertices.Count;
                    int ie2 = vertices.Count + 1;
                    int ie3 = vertices.Count + 2;

                    //Push 3 new vertices
                    newvertex.Normals  = Vector3.Normalize(e1);
                    newvertex.Position = newvertex.Normals * radius;
                    vertices.Add(newvertex);
                    newvertex.Normals  = Vector3.Normalize(e2);
                    newvertex.Position = newvertex.Normals * radius;
                    vertices.Add(newvertex);
                    newvertex.Normals  = Vector3.Normalize(e3);
                    newvertex.Position = newvertex.Normals * radius;
                    vertices.Add(newvertex);

                    //Push 4 triangles
                    newindices.Add(ie1); newindices.Add(ie2); newindices.Add(ie3);
                    newindices.Add(i1); newindices.Add(ie1); newindices.Add(ie3);
                    newindices.Add(i2); newindices.Add(ie2); newindices.Add(ie1);
                    newindices.Add(i3); newindices.Add(ie3); newindices.Add(ie2);
                }

                //Swap
                indices = newindices;
            }

            DX11IndexedGeometry geom = DX11IndexedGeometry.CreateFrom <Pos3Norm3Tex2Vertex>(context, vertices.ToArray(), indices.ToArray(), Pos3Norm3Tex2Vertex.Layout);

            geom.HasBoundingBox = true;
            geom.BoundingBox    = new BoundingBox(new Vector3(-radius), new Vector3(radius));
            geom.Tag            = settings;
            geom.PrimitiveType  = settings.PrimitiveType;

            return(geom);
        }
Exemple #14
0
        public void Construct(Segment settings, Action <Vector3, Vector3, Vector2> appendVertex, Action <Int3> appendIndex)
        {
            float phase  = settings.Phase;
            float cycles = settings.Cycles;
            float inner  = settings.InnerRadius;
            int   res    = settings.Resolution;
            bool  flat   = settings.Flat;

            int vcount = res * 2;
            int icount = (res - 1) * 6;

            float inc = Convert.ToSingle((Math.PI * 2.0 * cycles) / (res - 1.0));
            float phi = Convert.ToSingle(phase * (Math.PI * 2.0));

            Pos3Norm3Tex2Vertex innerv = new Pos3Norm3Tex2Vertex();

            innerv.Normals = new Vector3(0.0f, 0.0f, 1.0f);

            Pos3Norm3Tex2Vertex outerv = new Pos3Norm3Tex2Vertex();

            outerv.Normals = new Vector3(0.0f, 0.0f, 1.0f);

            Pos4Norm3Tex2Vertex[] vertices = new Pos4Norm3Tex2Vertex[res * 2];

            for (int i = 0; i < res; i++)
            {
                float x = Convert.ToSingle(0.5 * inner * Math.Cos(phi));
                float y = Convert.ToSingle(0.5 * inner * Math.Sin(phi));

                innerv.Position = new Vector3(x, y, 0.0f);
                if (flat)
                {
                    innerv.TexCoords = new Vector2(0.5f - x, 0.5f - y);
                }
                else
                {
                    innerv.TexCoords = new Vector2((1.0f * (float)i) / ((float)res - 1.0f), 0.0f);
                }
                appendVertex(innerv.Position, innerv.Normals, innerv.TexCoords);
                phi += inc;
            }

            phi = Convert.ToSingle(phase * (Math.PI * 2.0));
            for (int i = 0; i < res; i++)
            {
                float x = Convert.ToSingle(0.5 * Math.Cos(phi));
                float y = Convert.ToSingle(0.5 * Math.Sin(phi));
                outerv.Position = new Vector3(x, y, 0.0f);

                if (flat)
                {
                    outerv.TexCoords = new Vector2(0.5f - x, 0.5f - y);
                }
                else
                {
                    outerv.TexCoords = new Vector2((1.0f * (float)i) / ((float)res - 1.0f), 1.0f);
                }

                appendVertex(outerv.Position, outerv.Normals, outerv.TexCoords);
                phi += inc;
            }



            for (int i = 0; i < res - 1; i++)
            {
                appendIndex(new Int3(i, i + 1, res + i));
                appendIndex(new Int3(i + 1, res + i + 1, res + i));
            }
        }
        public DX11IndexedGeometry IcoSphere(IcoSphere settings)
        {
            float radius = settings.Radius;
            int subdiv = settings.SubDivisions;


            List<Pos3Norm3Tex2Vertex> vertices = new List<Pos3Norm3Tex2Vertex>();
            Pos3Norm3Tex2Vertex v = new Pos3Norm3Tex2Vertex();

            float t = (1.0f + (float)Math.Sqrt(5.0f)) / 2.0f;
            //TODO : Add texcoord
            v.TexCoords = new Vector2(0, 0);

            //Isocahedron
            v.Normals = Vector3.Normalize(new Vector3(-1, t, 0)); v.Position = v.Normals * radius; vertices.Add(v);
            v.Normals = Vector3.Normalize(new Vector3(1, t, 0)); v.Position = v.Normals * radius; vertices.Add(v);
            v.Normals = Vector3.Normalize(new Vector3(-1, -t, 0)); v.Position = v.Normals * radius; vertices.Add(v);
            v.Normals = Vector3.Normalize(new Vector3(1, -t, 0)); v.Position = v.Normals * radius; vertices.Add(v);

            v.Normals = Vector3.Normalize(new Vector3(0, -1, t)); v.Position = v.Normals * radius; vertices.Add(v);
            v.Normals = Vector3.Normalize(new Vector3(0, 1, t)); v.Position = v.Normals * radius; vertices.Add(v);
            v.Normals = Vector3.Normalize(new Vector3(0, -1, -t)); v.Position = v.Normals * radius; vertices.Add(v);
            v.Normals = Vector3.Normalize(new Vector3(0, 1, -t)); v.Position = v.Normals * radius; vertices.Add(v);

            v.Normals = Vector3.Normalize(new Vector3(t, 0, -1)); v.Position = v.Normals * radius; vertices.Add(v);
            v.Normals = Vector3.Normalize(new Vector3(t, 0, 1)); v.Position = v.Normals * radius; vertices.Add(v);
            v.Normals = Vector3.Normalize(new Vector3(-t, 0, -1)); v.Position = v.Normals * radius; vertices.Add(v);
            v.Normals = Vector3.Normalize(new Vector3(-t, 0, 1)); v.Position = v.Normals * radius; vertices.Add(v);

            int[] inds = new int[] { 
                0,11,5,
                0,5,1,
                0,1,7,
                0,7,10,
                0,10,11,
                1,5,9,
                5,11,4,
                11,10,2,
                10,7,6,
                7,1,8,
                3,9,4,
                3,4,2,
                3,2,6,
                3,6,8,
                3,8,9,
                4,9,5,
                2,4,11,
                6,2,10,
                8,6,7,
                9,8,1 };

            List<int> indices = new List<int>(inds);

            Pos3Norm3Tex2Vertex newvertex = new Pos3Norm3Tex2Vertex();

            for (int iter = 0; iter < subdiv; iter++)
            {
                List<int> newindices = new List<int>();

                for (int i = 0; i < indices.Count / 3; i++)
                {
                    //Grab Indices
                    int i1 = indices[i * 3];
                    int i2 = indices[i * 3 + 1];
                    int i3 = indices[i * 3 + 2];

                    //Get Vertices
                    Pos3Norm3Tex2Vertex v1 = vertices[i1];
                    Pos3Norm3Tex2Vertex v2 = vertices[i2];
                    Pos3Norm3Tex2Vertex v3 = vertices[i3];

                    Vector3 e1 = (v1.Position + v2.Position) * 0.5f;
                    Vector3 e2 = (v2.Position + v3.Position) * 0.5f;
                    Vector3 e3 = (v3.Position + v1.Position) * 0.5f;

                    int ie1 = vertices.Count;
                    int ie2 = vertices.Count + 1;
                    int ie3 = vertices.Count + 2;

                    //Push 3 new vertices
                    newvertex.Normals = Vector3.Normalize(e1);
                    newvertex.Position = newvertex.Normals * radius;
                    vertices.Add(newvertex);
                    newvertex.Normals = Vector3.Normalize(e2);
                    newvertex.Position = newvertex.Normals * radius;
                    vertices.Add(newvertex);
                    newvertex.Normals = Vector3.Normalize(e3);
                    newvertex.Position = newvertex.Normals * radius;
                    vertices.Add(newvertex);

                    //Push 4 triangles
                    newindices.Add(ie1); newindices.Add(ie2); newindices.Add(ie3);
                    newindices.Add(i1); newindices.Add(ie1); newindices.Add(ie3);
                    newindices.Add(i2); newindices.Add(ie2); newindices.Add(ie1);
                    newindices.Add(i3); newindices.Add(ie3); newindices.Add(ie2);
                }

                //Swap
                indices = newindices;
            }

            DX11IndexedGeometry geom = DX11IndexedGeometry.CreateFrom<Pos3Norm3Tex2Vertex>(context, vertices.ToArray(), indices.ToArray(), Pos3Norm3Tex2Vertex.Layout);
            geom.HasBoundingBox = true;
            geom.BoundingBox = new BoundingBox(new Vector3(-radius), new Vector3(radius));
            geom.Tag = settings;
            geom.PrimitiveType = settings.PrimitiveType;

            return geom;
        }