Beispiel #1
0
        protected override void ondispose()
        {
            if (vbo != null)
            {
                vbo.dispose();
            }

            vbo             = null;
            hasTexCoord0    = false;
            hasTexCoord1    = false;
            hasColor        = false;
            hasNormal       = false;
            stride          = 0;
            vertexOffset    = 0;
            texCoord0Offset = 0;
            texCoord1Offset = 0;
            colorOffset     = 0;
            normalOffset    = 0;
            indexCount      = 0;
            //if (vboVertexBuffer != 0)
            //{
            //    //bufferPool.dispose(vboVertexBuffer);
            //    vboVertexBuffer = 0;
            //}
            //if (vboIndexBuffer != 0)
            //{
            //    //bufferPool.dispose(vboIndexBuffer);
            //    vboIndexBuffer = 0;
            //}
        }
Beispiel #2
0
        private void buildMesh(MeshData data)
        {
            //this.data = data;
            //this.data = newData;
            stride          = 0;
            vertexCount     = 0;
            indexCount      = 0;
            vertexOffset    = 0;
            texCoord0Offset = 0;
            texCoord1Offset = 0;
            colorOffset     = 0;
            normalOffset    = 0;
            hasTexCoord0    = false;
            hasTexCoord1    = false;
            hasNormal       = false;
            hasColor        = false;

            if (vbo != null)
            {
                vbo.dispose();
            }


            var verts = data.getVertices();

            if (verts != null && verts.Length > 0)
            {
                var indx = data.getIndices();
                if (indx != null && indx.Length > 0)
                {
                    vbo         = new OpenTKVBO();
                    vertexCount = verts.Length;
                    indexCount  = indx.Length;

                    var tex0 = data.getTexCoord0();
                    var tex1 = data.getTexCoord1();
                    var norm = data.getNormals();
                    var colr = data.getColors();

                    hasTexCoord0 = tex0 != null && tex0.Length == vertexCount;
                    hasTexCoord1 = tex1 != null && tex1.Length == vertexCount;
                    hasNormal    = norm != null && norm.Length == vertexCount;
                    hasColor     = colr != null && colr.Length == vertexCount;

                    vertexOffset = 0;
                    stride       = VERTEX_SIZE;
                    if (hasTexCoord0)
                    {
                        texCoord0Offset = stride * FLOAT_SIZE;
                        stride         += TEX_COORD_0_SIZE;
                    }

                    if (hasTexCoord1)
                    {
                        texCoord1Offset = stride * FLOAT_SIZE;
                        stride         += TEX_COORD_1_SIZE;
                    }

                    if (hasNormal)
                    {
                        normalOffset = stride * FLOAT_SIZE;
                        stride      += NORMAL_SIZE;
                    }

                    if (hasColor)
                    {
                        colorOffset = stride * FLOAT_SIZE;
                        stride     += COLOR_SIZE;
                    }

                    var parts = new float[stride * vertexCount];
                    //var indices = new ushort[vertexCount];

                    var partIndex = 0;
                    for (var i = 0; i < vertexCount; i++)
                    {
                        parts[partIndex++] = verts[i].X;
                        parts[partIndex++] = verts[i].Y;
                        parts[partIndex++] = verts[i].Z;

                        if (hasTexCoord0)
                        {
                            parts[partIndex++] = tex0[i].X;
                            parts[partIndex++] = tex0[i].Y;
                        }

                        if (hasTexCoord1)
                        {
                            parts[partIndex++] = tex1[i].X;
                            parts[partIndex++] = tex1[i].Y;
                        }

                        if (hasNormal)
                        {
                            parts[partIndex++] = norm[i].X;
                            parts[partIndex++] = norm[i].Y;
                            parts[partIndex++] = norm[i].Z;
                        }

                        if (hasColor)
                        {
                            parts[partIndex++] = colr[i].X;
                            parts[partIndex++] = colr[i].Y;
                            parts[partIndex++] = colr[i].Z;
                            parts[partIndex++] = colr[i].W;
                        }
                    }

                    vbo.load(parts, indx, stride);

                    ////List<TFloatIterator> parts = Lists.newArrayList();
                    ////TIntList partSizes = new TIntArrayList();
                    //int vertexCount = newData.getVertices().Length;
                    //int vertexSize = VERTEX_SIZE;
                    //parts.add(newData.getVertices().iterator());
                    //partSizes.add(VERTEX_SIZE);

                    //if (newData.getTexCoord0() != null && newData.getTexCoord0().size() / TEX_COORD_0_SIZE == vertexCount)
                    //{
                    //    parts.add(newData.getTexCoord0().iterator());
                    //    partSizes.add(TEX_COORD_0_SIZE);
                    //    texCoord0Offset = vertexSize * FLOAT_SIZE;
                    //    vertexSize += TEX_COORD_0_SIZE;
                    //    hasTexCoord0 = true;
                    //}
                    //if (newData.getTexCoord1() != null && newData.getTexCoord1().size() / TEX_COORD_1_SIZE == vertexCount)
                    //{
                    //    parts.add(newData.getTexCoord1().iterator());
                    //    partSizes.add(TEX_COORD_1_SIZE);
                    //    texCoord1Offset = vertexSize * FLOAT_SIZE;
                    //    vertexSize += TEX_COORD_1_SIZE;
                    //    hasTexCoord1 = true;
                    //}
                    //if (newData.getNormals() != null && newData.getNormals().size() / NORMAL_SIZE == vertexCount)
                    //{
                    //    parts.add(newData.getNormals().iterator());
                    //    partSizes.add(NORMAL_SIZE);
                    //    normalOffset = vertexSize * FLOAT_SIZE;
                    //    vertexSize += NORMAL_SIZE;
                    //    hasNormal = true;
                    //}
                    //if (newData.getColors() != null && newData.getColors().size() / COLOR_SIZE == vertexCount)
                    //{
                    //    parts.add(newData.getColors().iterator());
                    //    partSizes.add(COLOR_SIZE);
                    //    colorOffset = vertexSize * FLOAT_SIZE;
                    //    vertexSize += COLOR_SIZE;
                    //    hasColor = true;
                    //}
                    //stride = vertexSize * FLOAT_SIZE;
                    //indexCount = newData.getIndices().size();

                    //createVertexBuffer(parts, partSizes, vertexCount, vertexSize);
                    //createIndexBuffer(newData.getIndices());

                    //aabb = AABB.createEncompasing(newData.getVertices());
                }
            }
        }