Пример #1
0
            public SSMeshOBJSubsetData(SSVertex_PosNormTex[] vertices,
                                       UInt16[] indices, UInt16[] wireframeIndices)
            {
                SSVertexBuffer <SSVertex_PosNormTex> vbo
                    = new SSVertexBuffer <SSVertex_PosNormTex>(vertices, BufferUsageHint.StaticDraw);
                SSIndexBuffer triIbo       = new SSIndexBuffer(indices, vbo, BufferUsageHint.StaticDraw);
                SSIndexBuffer wireframeIbo = new SSIndexBuffer(wireframeIndices, vbo, BufferUsageHint.StaticDraw);

                this.triangleMesh  = new SSIndexedMesh <SSVertex_PosNormTex>(vbo, triIbo);
                this.wireframeMesh = new SSIndexedMesh <SSVertex_PosNormTex>(vbo, wireframeIbo);
            }
Пример #2
0
        public SSIndexedMesh(SSVertexBuffer <V> vbo, SSIndexBuffer ibo)
        {
            if (vbo == null)
            {
                _vbo = new SSVertexBuffer <V> (BufferUsageHint.DynamicDraw);
            }
            else
            {
                _vbo = vbo;
            }

            if (ibo == null)
            {
                _ibo = new SSIndexBuffer(vbo, BufferUsageHint.DynamicDraw);
            }
            else
            {
                _ibo = ibo;
            }
        }
Пример #3
0
        /// <summary>
        /// Initialize given arrays of vertices and/or indices.
        /// </summary>
        public SSIndexedMesh(V[] vertices, UInt16[] indices)
            : base()
        {
            if (vertices == null)
            {
                _vbo = new SSVertexBuffer <V> (BufferUsageHint.DynamicDraw);
            }
            else
            {
                _vbo = new SSVertexBuffer <V> (vertices);
            }

            if (indices == null)
            {
                _ibo = new SSIndexBuffer(_vbo, BufferUsageHint.DynamicDraw);
            }
            else
            {
                _ibo = new SSIndexBuffer(indices, _vbo);
            }
        }
Пример #4
0
 /// <summary>
 /// Initialize based on buffer usage. Default to dynamic draw.
 /// </summary>
 public SSIndexedMesh(BufferUsageHint vertUsage  = BufferUsageHint.DynamicDraw,
                      BufferUsageHint indexUsage = BufferUsageHint.DynamicDraw)
 {
     _vbo = new SSVertexBuffer <V> (vertUsage);
     _ibo = new SSIndexBuffer(_vbo, indexUsage);
 }
Пример #5
0
 public SSIndexedMeshTrianglesBVH(SSVertexBuffer <V> vbo, SSIndexBuffer ibo, int maxTrianglesPerLeaf = 1)
     : base(new SSIndexedMeshTriangleBVHNodeAdaptor(vbo, ibo), new List <UInt16>(), maxTrianglesPerLeaf)
 {
 }
Пример #6
0
 public SSIndexedMeshTriangleBVHNodeAdaptor(SSVertexBuffer <V> vbo, SSIndexBuffer ibo)
 {
     _vbo = vbo;
     _ibo = ibo;
 }
Пример #7
0
        private void _Create(int divisions)
        {
            var icoSphereCreator = new IcoSphereCreator();

            geom = icoSphereCreator.Create(divisions);
            var positions = geom.Positions.ToArray();

            var vertexSoup = new Util3d.VertexSoup <SSVertex_PosNormDiffTex1>();
            var indexList  = new List <UInt16>();

            // we have to process each face in the IcoSphere, so we can
            // properly "wrap" the texture-coordinates that fall across the left/right border
            foreach (TriangleIndices face in geom.Faces)
            {
                var vp1 = positions[face.v1];
                var vp2 = positions[face.v2];
                var vp3 = positions[face.v3];

                var normal1 = vp1.Normalized();
                var normal2 = vp2.Normalized();
                var normal3 = vp3.Normalized();

                float s1, s2, s3, t1, t2, t3;

                _computeEquirectangularUVForSpherePoint(normal1, out s1, out t1);
                _computeEquirectangularUVForSpherePoint(normal2, out s2, out t2);
                _computeEquirectangularUVForSpherePoint(normal3, out s3, out t3);

                // configure verticies

                var v1 = new SSVertex_PosNormDiffTex1();
                v1.Position = vp1;
                v1.Normal   = normal1;
                v1.Tu       = s1;
                v1.Tv       = t1;

                var v2 = new SSVertex_PosNormDiffTex1();
                v2.Position = vp2;
                v2.Normal   = normal2;
                v2.Tu       = s2;
                v2.Tv       = t2;

                var v3 = new SSVertex_PosNormDiffTex1();
                v3.Position = vp3;
                v3.Normal   = normal3;
                v3.Tu       = s3;
                v3.Tv       = t3;

                // if a triangle spans the left/right seam where U transitions from 1 to -1
                bool v1_left = vp1.X < 0.0f;
                bool v2_left = vp2.X < 0.0f;
                bool v3_left = vp3.X < 0.0f;
                if (vp1.Z < 0.0f && vp2.Z < 0.0f && vp3.Z < 0.0f &&
                    ((v2_left != v1_left) || (v3_left != v1_left)))
                {
                    // we need to "wrap" texture coordinates
                    if (v1.Tu < 0.5f)
                    {
                        v1.Tu += 1.0f;
                    }
                    if (v2.Tu < 0.5f)
                    {
                        v2.Tu += 1.0f;
                    }
                    if (v3.Tu < 0.5f)
                    {
                        v3.Tu += 1.0f;
                    }
                }

                // add configured verticies to mesh..

                UInt16 idx1 = vertexSoup.digestVertex(ref v1);
                UInt16 idx2 = vertexSoup.digestVertex(ref v2);
                UInt16 idx3 = vertexSoup.digestVertex(ref v3);

                indexList.Add(idx1);
                indexList.Add(idx2);
                indexList.Add(idx3);
            }

            var vertexArr = vertexSoup.verticies.ToArray();
            var idxArr    = indexList.ToArray();

            // upload to GL
            vbo = new SSVertexBuffer <SSVertex_PosNormDiffTex1>(vertexArr);
            ibo = new SSIndexBuffer(idxArr, vbo);
        }
Пример #8
0
 public SSMeshOBJSubsetData(SSVertex_PosNormTexDiff[] vertices, 
                            UInt16[] indices, UInt16[] wireframeIndices)
 {
     SSVertexBuffer<SSVertex_PosNormTexDiff> vbo
         = new SSVertexBuffer<SSVertex_PosNormTexDiff>(vertices, BufferUsageHint.StaticDraw);
     SSIndexBuffer triIbo = new SSIndexBuffer(indices, vbo, BufferUsageHint.StaticDraw);
     SSIndexBuffer wireframeIbo = new SSIndexBuffer(wireframeIndices, vbo, BufferUsageHint.StaticDraw);
     this.triangleMesh = new SSIndexedMesh<SSVertex_PosNormTexDiff>(vbo, triIbo);
     this.wireframeMesh = new SSIndexedMesh<SSVertex_PosNormTexDiff>(vbo, wireframeIbo);
 }