Beispiel #1
0
        float[] ConvertUVToLightmappingUV(Vector2[] uv, Vector4 lightmapScaleOffset)
        {
            var uv2 = FlattenHelper.Flatten(GLConverter.ConvertDxTexcoordToGlTexcoord(uv));

            for (int i = 0; i < uv2.Length; i += 2)
            {
                uv2[i]     = uv2[i] * lightmapScaleOffset[0] + lightmapScaleOffset[2];
                uv2[i + 1] = uv2[i + 1] * lightmapScaleOffset[1] + lightmapScaleOffset[3];
            }
            return(uv2);
        }
Beispiel #2
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));
            }
        }