Exemplo n.º 1
0
        /// <summary>Applies the MeshBuilder's data to a StaticObject</summary>
        public void Apply(ref StaticObject Object, bool EnableHacks = false)
        {
            if (TransformMatrix != Matrix4D.NoTransformation)
            {
                for (int i = 0; i < Vertices.Length; i++)
                {
                    Vertices[i].Coordinates.Transform(TransformMatrix);
                }
            }
            if (Faces.Length != 0)
            {
                int mf = Object.Mesh.Faces.Length;
                int mm = Object.Mesh.Materials.Length;
                int mv = Object.Mesh.Vertices.Length;
                Array.Resize <MeshFace>(ref Object.Mesh.Faces, mf + Faces.Length);
                Array.Resize <MeshMaterial>(ref Object.Mesh.Materials, mm + Materials.Length);
                Array.Resize <VertexTemplate>(ref Object.Mesh.Vertices, mv + Vertices.Length);
                for (int i = 0; i < Vertices.Length; i++)
                {
                    Object.Mesh.Vertices[mv + i] = Vertices[i];
                }

                for (int i = 0; i < Faces.Length; i++)
                {
                    Object.Mesh.Faces[mf + i] = Faces[i];
                    for (int j = 0; j < Object.Mesh.Faces[mf + i].Vertices.Length; j++)
                    {
                        Object.Mesh.Faces[mf + i].Vertices[j].Index += (ushort)mv;
                    }

                    Object.Mesh.Faces[mf + i].Material += (ushort)mm;
                }

                for (int i = 0; i < Materials.Length; i++)
                {
                    if (EnableHacks && !string.IsNullOrEmpty(Materials[i].DaytimeTexture))
                    {
                        if (!string.IsNullOrEmpty(Materials[i].NighttimeTexture))
                        {
                            if (Materials[i].EmissiveColorUsed == false)
                            {
                                /*
                                 * Versions of openBVE prior to 1.7.0 rendered polygons with two defined textures as unlit
                                 * The new GL 3.2 renderer corrects this behaviour
                                 * Horrid workaround....
                                 */
                                Materials[i].EmissiveColorUsed = true;
                                Materials[i].EmissiveColor     = Color24.White;
                            }
                        }
                    }

                    Object.Mesh.Materials[mm + i].Flags = new MaterialFlags();
                    if (Materials[i].EmissiveColorUsed)
                    {
                        Object.Mesh.Materials[mm + i].Flags |= MaterialFlags.Emissive;
                    }
                    if (Materials[i].TransparentColorUsed)
                    {
                        Object.Mesh.Materials[mm + i].Flags |= MaterialFlags.TransparentColor;
                    }
                    Object.Mesh.Materials[mm + i].Color            = Materials[i].Color;
                    Object.Mesh.Materials[mm + i].TransparentColor = Materials[i].TransparentColor;
                    if (Materials[i].DaytimeTexture != null || Materials[i].Text != null)
                    {
                        Textures.Texture tday;
                        if (Materials[i].Text != null)
                        {
                            Bitmap bitmap = null;
                            if (Materials[i].DaytimeTexture != null)
                            {
                                bitmap = new Bitmap(Materials[i].DaytimeTexture);
                            }

                            Bitmap texture = TextOverlay.AddTextToBitmap(bitmap, Materials[i].Text, Materials[i].Font, 12, Materials[i].BackgroundColor, Materials[i].TextColor, Materials[i].TextPadding);
                            currentHost.RegisterTexture(texture, new TextureParameters(null, new Color24(Materials[i].TransparentColor.R, Materials[i].TransparentColor.G, Materials[i].TransparentColor.B)), out tday);
                        }
                        else
                        {
                            if (Materials[i].TransparentColorUsed)
                            {
                                currentHost.RegisterTexture(Materials[i].DaytimeTexture, new TextureParameters(null,
                                                                                                               new Color24(Materials[i].TransparentColor.R, Materials[i].TransparentColor.G,
                                                                                                                           Materials[i].TransparentColor.B)), out tday);
                            }
                            else
                            {
                                currentHost.RegisterTexture(Materials[i].DaytimeTexture, new TextureParameters(null, null), out tday);
                            }
                        }

                        Object.Mesh.Materials[mm + i].DaytimeTexture = tday;
                    }
                    else
                    {
                        Object.Mesh.Materials[mm + i].DaytimeTexture = null;
                    }

                    Object.Mesh.Materials[mm + i].EmissiveColor = Materials[i].EmissiveColor;
                    if (Materials[i].NighttimeTexture != null)
                    {
                        Textures.Texture tnight;
                        if (Materials[i].TransparentColorUsed)
                        {
                            currentHost.RegisterTexture(Materials[i].NighttimeTexture, new TextureParameters(null, new Color24(Materials[i].TransparentColor.R, Materials[i].TransparentColor.G, Materials[i].TransparentColor.B)), out tnight);
                        }
                        else
                        {
                            currentHost.RegisterTexture(Materials[i].NighttimeTexture, new TextureParameters(null, null), out tnight);
                        }

                        Object.Mesh.Materials[mm + i].NighttimeTexture = tnight;
                    }
                    else
                    {
                        Object.Mesh.Materials[mm + i].NighttimeTexture = null;
                    }

                    Object.Mesh.Materials[mm + i].DaytimeNighttimeBlend = 0;
                    Object.Mesh.Materials[mm + i].BlendMode             = Materials[i].BlendMode;
                    Object.Mesh.Materials[mm + i].GlowAttenuationData   = Materials[i].GlowAttenuationData;
                    Object.Mesh.Materials[mm + i].WrapMode = Materials[i].WrapMode;
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>Applies the MeshBuilder's data to a StaticObject</summary>
        public void Apply(ref StaticObject Object)
        {
            if (TransformMatrix != Matrix4D.NoTransformation)
            {
                for (int i = 0; i < Vertices.Length; i++)
                {
                    Vertices[i].Coordinates.Transform(TransformMatrix);
                }
            }
            if (Faces.Length != 0)
            {
                int mf = Object.Mesh.Faces.Length;
                int mm = Object.Mesh.Materials.Length;
                int mv = Object.Mesh.Vertices.Length;
                Array.Resize <MeshFace>(ref Object.Mesh.Faces, mf + Faces.Length);
                Array.Resize <MeshMaterial>(ref Object.Mesh.Materials, mm + Materials.Length);
                Array.Resize <VertexTemplate>(ref Object.Mesh.Vertices, mv + Vertices.Length);
                for (int i = 0; i < Vertices.Length; i++)
                {
                    Object.Mesh.Vertices[mv + i] = Vertices[i];
                }

                for (int i = 0; i < Faces.Length; i++)
                {
                    Object.Mesh.Faces[mf + i] = Faces[i];
                    for (int j = 0; j < Object.Mesh.Faces[mf + i].Vertices.Length; j++)
                    {
                        Object.Mesh.Faces[mf + i].Vertices[j].Index += (ushort)mv;
                    }

                    Object.Mesh.Faces[mf + i].Material += (ushort)mm;
                }

                for (int i = 0; i < Materials.Length; i++)
                {
                    Object.Mesh.Materials[mm + i].Flags            = (byte)((Materials[i].EmissiveColorUsed ? MeshMaterial.EmissiveColorMask : 0) | (Materials[i].TransparentColorUsed ? MeshMaterial.TransparentColorMask : 0));
                    Object.Mesh.Materials[mm + i].Color            = Materials[i].Color;
                    Object.Mesh.Materials[mm + i].TransparentColor = Materials[i].TransparentColor;
                    if (Materials[i].DaytimeTexture != null || Materials[i].Text != null)
                    {
                        Textures.Texture tday;
                        if (Materials[i].Text != null)
                        {
                            Bitmap bitmap = null;
                            if (Materials[i].DaytimeTexture != null)
                            {
                                bitmap = new Bitmap(Materials[i].DaytimeTexture);
                            }

                            Bitmap texture = TextOverlay.AddTextToBitmap(bitmap, Materials[i].Text, Materials[i].Font, 12, Materials[i].BackgroundColor, Materials[i].TextColor, Materials[i].TextPadding);
                            currentHost.RegisterTexture(texture, new TextureParameters(null, new Color24(Materials[i].TransparentColor.R, Materials[i].TransparentColor.G, Materials[i].TransparentColor.B)), out tday);
                        }
                        else
                        {
                            if (Materials[i].TransparentColorUsed)
                            {
                                currentHost.RegisterTexture(Materials[i].DaytimeTexture, new TextureParameters(null,
                                                                                                               new Color24(Materials[i].TransparentColor.R, Materials[i].TransparentColor.G,
                                                                                                                           Materials[i].TransparentColor.B)), out tday);
                            }
                            else
                            {
                                currentHost.RegisterTexture(Materials[i].DaytimeTexture, new TextureParameters(null, null), out tday);
                            }
                        }

                        Object.Mesh.Materials[mm + i].DaytimeTexture = tday;
                    }
                    else
                    {
                        Object.Mesh.Materials[mm + i].DaytimeTexture = null;
                    }

                    Object.Mesh.Materials[mm + i].EmissiveColor = Materials[i].EmissiveColor;
                    if (Materials[i].NighttimeTexture != null)
                    {
                        Textures.Texture tnight;
                        if (Materials[i].TransparentColorUsed)
                        {
                            currentHost.RegisterTexture(Materials[i].NighttimeTexture, new TextureParameters(null, new Color24(Materials[i].TransparentColor.R, Materials[i].TransparentColor.G, Materials[i].TransparentColor.B)), out tnight);
                        }
                        else
                        {
                            currentHost.RegisterTexture(Materials[i].NighttimeTexture, new TextureParameters(null, null), out tnight);
                        }

                        Object.Mesh.Materials[mm + i].NighttimeTexture = tnight;
                    }
                    else
                    {
                        Object.Mesh.Materials[mm + i].NighttimeTexture = null;
                    }

                    Object.Mesh.Materials[mm + i].DaytimeNighttimeBlend = 0;
                    Object.Mesh.Materials[mm + i].BlendMode             = Materials[i].BlendMode;
                    Object.Mesh.Materials[mm + i].GlowAttenuationData   = Materials[i].GlowAttenuationData;
                    Object.Mesh.Materials[mm + i].WrapMode = Materials[i].WrapMode;
                }
            }
        }