Пример #1
0
        public BufferGeometryElem(MeshContainer c, bool hasLightmap, Vector4 lightmapScaleOffset)
        {
            this.Mesh                = c.Mesh;
            this.HasLightmap         = hasLightmap;
            this.LightmapScaleOffset = lightmapScaleOffset;


            Mesh mesh = c.Mesh;


            // vertices
            if (mesh.vertices.Length > 0)
            {
                Vertices = FlattenHelper.Flatten(GLConverter.ConvertDxVectorToGlVector(mesh.vertices));
            }

            // faces
            if (mesh.triangles.Length > 0)
            {
                Faces = GLConverter.ConvertDxTrianglesToGlTriangles(mesh.triangles);
            }

            // normals
            if (mesh.normals.Length > 0)
            {
                Normals = FlattenHelper.Flatten(GLConverter.ConvertDxVectorToGlVector(mesh.normals));
            }

            // colors
            if (mesh.colors.Length > 0)
            {
                Colors = new float[mesh.colors.Length * 3];
                for (int i = 0; i < mesh.colors.Length; i++)
                {
                    var color = mesh.colors[i];
                    Colors[i * 4 + 0] = color.r;
                    Colors[i * 4 + 1] = color.g;
                    Colors[i * 4 + 2] = color.b;
                }
            }

            // uvs
            int uvCount = 0;

            if (mesh.uv.Length > 0)
            {
                uvCount++;
                UV = FlattenHelper.Flatten(GLConverter.ConvertDxTexcoordToGlTexcoord(mesh.uv));
            }

            if (mesh.uv2.Length > 0)
            {
                uvCount++;
                UV2 = ConvertUVToLightmappingUV(mesh.uv2, LightmapScaleOffset);
            }

            if (mesh.uv3.Length > 0)
            {
                uvCount++;
                UV3 = FlattenHelper.Flatten(GLConverter.ConvertDxTexcoordToGlTexcoord(mesh.uv3));
            }

            if (mesh.uv4.Length > 0)
            {
                uvCount++;
                UV4 = FlattenHelper.Flatten(GLConverter.ConvertDxTexcoordToGlTexcoord(mesh.uv4));
            }

            // if use lightmap uv
            if (LightmapScaleOffset != null && UV2 == null)
            {
                uvCount++;
                UV2 = ConvertUVToLightmappingUV(mesh.uv, LightmapScaleOffset);
            }
        }
        public BufferGeometryElem(MeshContainer c)
        {
            Mesh mesh = c.Mesh;

            // vertices
            if (mesh.vertices.Length > 0)
            {
                Vertices = FlattenHelper.Flatten(GLConverter.ConvertDxVectorToGlVector(mesh.vertices));
            }

            // faces
            if (mesh.triangles.Length > 0)
            {
                Faces = GLConverter.ConvertDxTrianglesToGlTriangles(mesh.triangles);
            }

            // normals
            if (mesh.normals.Length > 0)
            {
                Normals = FlattenHelper.Flatten(GLConverter.ConvertDxVectorToGlVector(mesh.normals));
            }

            // colors
            if (mesh.colors.Length > 0)
            {
                Colors = new float[mesh.colors.Length * 3];
                for (int i = 0; i < mesh.colors.Length; i++)
                {
                    var color = mesh.colors[i];
                    Colors[i * 4 + 0] = color.r;
                    Colors[i * 4 + 1] = color.g;
                    Colors[i * 4 + 2] = color.b;
                }
            }

            // uvs
            int uvCount = 0;

            if (mesh.uv.Length > 0)
            {
                uvCount++;
                UV = FlattenHelper.Flatten(GLConverter.ConvertDxTexcoordToGlTexcoord(mesh.uv));
            }

            if (mesh.uv2.Length > 0)
            {
                uvCount++;
                UV2 = FlattenHelper.Flatten(GLConverter.ConvertDxTexcoordToGlTexcoord(mesh.uv2));
            }

            if (mesh.uv3.Length > 0)
            {
                uvCount++;
                UV3 = FlattenHelper.Flatten(GLConverter.ConvertDxTexcoordToGlTexcoord(mesh.uv3));
            }

            if (mesh.uv4.Length > 0)
            {
                uvCount++;
                UV4 = FlattenHelper.Flatten(GLConverter.ConvertDxTexcoordToGlTexcoord(mesh.uv4));
            }
        }