Exemplo n.º 1
0
 internal void SetTextureBackgroundInternal(string filename, float repeatX = 1, float repeatY = 1, float red = 1, float green = 1, float blue = 1, float intensity = 1, bool isFile = true)
 {
     if (filename == null || filename.Length < 1)
     {
         _textureBackground     = -1;
         _textureBackgroundTint = Vector4.Zero;
     }
     else
     {
         if (KWEngine.CustomTextures[this].ContainsKey(filename))
         {
             _textureBackground = KWEngine.CustomTextures[this][filename];
         }
         else
         {
             _textureBackground = isFile ? HelperTexture.LoadTextureForBackgroundExternal(filename) : HelperTexture.LoadTextureForBackgroundInternal(filename);
             KWEngine.CustomTextures[this].Add(filename, _textureBackground);
         }
         _textureBackgroundTint.X      = HelperGL.Clamp(red, 0, 1);
         _textureBackgroundTint.Y      = HelperGL.Clamp(green, 0, 1);
         _textureBackgroundTint.Z      = HelperGL.Clamp(blue, 0, 1);
         _textureBackgroundTint.W      = HelperGL.Clamp(intensity, 0, 1);
         _textureBackgroundTransform.X = HelperGL.Clamp(repeatX, 0.001f, 8192);
         _textureBackgroundTransform.Y = HelperGL.Clamp(repeatY, 0.001f, 8192);
         _textureSkybox = -1;
     }
 }
Exemplo n.º 2
0
        private void SetTextureBottom(string texture, TextureType type, bool isFile)
        {
            int texId = -1;

            if (KWEngine.CustomTextures[GLWindow.CurrentWindow.CurrentWorld].ContainsKey(texture))
            {
                texId = KWEngine.CustomTextures[GLWindow.CurrentWindow.CurrentWorld][texture];
            }
            else
            {
                texId = isFile ? HelperTexture.LoadTextureForModelExternal(texture) : HelperTexture.LoadTextureForModelInternal(texture);
            }

            if (type == TextureType.Diffuse)
            {
                EditTextureObject(ref GeoTextureBottom, texId, type, texture);
            }
            else if (type == TextureType.Normal)
            {
                EditTextureObject(ref GeoTextureBottomNormal, texId, type, texture);
            }
            else if (type == TextureType.Specular)
            {
                EditTextureObject(ref GeoTextureBottomSpecular, texId, type, texture);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Loading of basic assets and setup
        /// </summary>
        /// <param name="e">Event arguments</param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            _renderProgram      = new Renderer();
            _renderProgramBloom = new RendererBloom();

            GeoQuad.InitialiseStatic();
            _quadBloom = new GeoQuad();

            _viewMatrix = Matrix4.LookAt(0, 0, 1, 0, 0, 0, 0, 1, 0);

            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);

            GL.Disable(EnableCap.DepthTest);

            GL.UseProgram(_renderProgram.GetProgramId());

            _defaultTextureId = HelperTexture.LoadTextureFromAssembly("default.png");

            Color4 backColor = new Color4();

            backColor.A = 1.0f;
            backColor.R = (0f / 255.0f);
            backColor.G = (0f / 255.0f);
            backColor.B = (0f / 255.0f);
            GL.ClearColor(backColor);

            LoadDefaultWorld();
        }
Exemplo n.º 4
0
        internal static void InitializeParticles()
        {
            int tex;

            // Bursts:
            tex = HelperTexture.LoadTextureInternal("fire01.png");
            ParticleDictionary.Add(ParticleType.BurstFire1, new ParticleInfo(tex, 8, 64));

            tex = HelperTexture.LoadTextureInternal("fire02.png");
            ParticleDictionary.Add(ParticleType.BurstFire2, new ParticleInfo(tex, 7, 49));

            tex = HelperTexture.LoadTextureInternal("fire03.png");
            ParticleDictionary.Add(ParticleType.BurstFire3, new ParticleInfo(tex, 9, 81));

            tex = HelperTexture.LoadTextureInternal("fire04.png");
            ParticleDictionary.Add(ParticleType.BurstElectricity, new ParticleInfo(tex, 4, 16));

            tex = HelperTexture.LoadTextureInternal("particleburst_bubbles.png");
            ParticleDictionary.Add(ParticleType.BurstBubblesColored, new ParticleInfo(tex, 6, 36));

            tex = HelperTexture.LoadTextureInternal("particleburst_bubbles_unicolor.png");
            ParticleDictionary.Add(ParticleType.BurstBubblesMonochrome, new ParticleInfo(tex, 6, 36));

            tex = HelperTexture.LoadTextureInternal("particleburst_explosioncolored.png");
            ParticleDictionary.Add(ParticleType.BurstFirework1, new ParticleInfo(tex, 7, 49));

            tex = HelperTexture.LoadTextureInternal("particleburst_firework.png");
            ParticleDictionary.Add(ParticleType.BurstFirework2, new ParticleInfo(tex, 7, 49));

            tex = HelperTexture.LoadTextureInternal("particleburst_hearts.png");
            ParticleDictionary.Add(ParticleType.BurstHearts, new ParticleInfo(tex, 7, 49));

            tex = HelperTexture.LoadTextureInternal("particleburst_plusplusplus.png");
            ParticleDictionary.Add(ParticleType.BurstOneUps, new ParticleInfo(tex, 6, 36));

            tex = HelperTexture.LoadTextureInternal("particleburst_shield.png");
            ParticleDictionary.Add(ParticleType.BurstShield, new ParticleInfo(tex, 6, 36));

            tex = HelperTexture.LoadTextureInternal("particleburst_teleport1.png");
            ParticleDictionary.Add(ParticleType.BurstTeleport1, new ParticleInfo(tex, 4, 16));

            tex = HelperTexture.LoadTextureInternal("particleburst_teleport2.png");
            ParticleDictionary.Add(ParticleType.BurstTeleport2, new ParticleInfo(tex, 4, 16));

            tex = HelperTexture.LoadTextureInternal("particleburst_teleport3.png");
            ParticleDictionary.Add(ParticleType.BurstTeleport3, new ParticleInfo(tex, 4, 16));

            // Loops:

            tex = HelperTexture.LoadTextureInternal("smoke01.png");
            ParticleDictionary.Add(ParticleType.LoopSmoke1, new ParticleInfo(tex, 4, 16));

            tex = HelperTexture.LoadTextureInternal("smoke02.png");
            ParticleDictionary.Add(ParticleType.LoopSmoke2, new ParticleInfo(tex, 7, 46));

            tex = HelperTexture.LoadTextureInternal("smoke03.png");
            ParticleDictionary.Add(ParticleType.LoopSmoke3, new ParticleInfo(tex, 6, 32));
        }
Exemplo n.º 5
0
 internal void SetTexture(string texture)
 {
     lock (KWEngine.CustomTextures)
     {
         if (KWEngine.CustomTextures[_currentWorld].ContainsKey(texture))
         {
             _textureId = KWEngine.CustomTextures[_currentWorld][texture];
         }
         else
         {
             _textureId = HelperTexture.LoadTextureForModelExternal(texture);
             if (_textureId > 0)
             {
                 KWEngine.CustomTextures[_currentWorld].Add(texture, _textureId);
             }
         }
     }
 }
Exemplo n.º 6
0
        private void SetTextureAll(string texture, TextureType type, bool isFile)
        {
            int texAll;

            if (KWEngine.CustomTextures[GLWindow.CurrentWindow.CurrentWorld].ContainsKey(texture))
            {
                texAll = KWEngine.CustomTextures[GLWindow.CurrentWindow.CurrentWorld][texture];
            }
            else
            {
                Assembly a = Assembly.GetEntryAssembly();
                texAll = isFile ? HelperTexture.LoadTextureForModelExternal(texture) : HelperTexture.LoadTextureForModelInternal(texture);
                KWEngine.CustomTextures[GLWindow.CurrentWindow.CurrentWorld].Add(texture, texAll);
            }

            if (type == TextureType.Diffuse)
            {
                EditTextureObject(ref GeoTextureFront, texAll, type, texture);
                EditTextureObject(ref GeoTextureBack, texAll, type, texture);
                EditTextureObject(ref GeoTextureLeft, texAll, type, texture);
                EditTextureObject(ref GeoTextureRight, texAll, type, texture);
                EditTextureObject(ref GeoTextureTop, texAll, type, texture);
                EditTextureObject(ref GeoTextureBottom, texAll, type, texture);
            }
            else if (type == TextureType.Normal)
            {
                EditTextureObject(ref GeoTextureFrontNormal, texAll, type, texture);
                EditTextureObject(ref GeoTextureBackNormal, texAll, type, texture);
                EditTextureObject(ref GeoTextureLeftNormal, texAll, type, texture);
                EditTextureObject(ref GeoTextureRightNormal, texAll, type, texture);
                EditTextureObject(ref GeoTextureTopNormal, texAll, type, texture);
                EditTextureObject(ref GeoTextureBottomNormal, texAll, type, texture);
            }
            else if (type == TextureType.Specular)
            {
                EditTextureObject(ref GeoTextureFrontSpecular, texAll, type, texture);
                EditTextureObject(ref GeoTextureBackSpecular, texAll, type, texture);
                EditTextureObject(ref GeoTextureLeftSpecular, texAll, type, texture);
                EditTextureObject(ref GeoTextureRightSpecular, texAll, type, texture);
                EditTextureObject(ref GeoTextureTopSpecular, texAll, type, texture);
                EditTextureObject(ref GeoTextureBottomSpecular, texAll, type, texture);
            }
        }
Exemplo n.º 7
0
 internal void SetTextureSkyboxInternal(string filename, float red = 1, float green = 1, float blue = 1, float intensity = 1, bool isFile = true)
 {
     if (filename == null || filename.Length < 1)
     {
         _textureSkybox = -1;
     }
     else
     {
         if (KWEngine.CustomTextures[this].ContainsKey(filename))
         {
             _textureSkybox = KWEngine.CustomTextures[this][filename];
         }
         else
         {
             _textureSkybox = HelperTexture.LoadTextureSkybox(filename, !isFile);
         }
         _textureBackground = -1;
     }
 }
Exemplo n.º 8
0
 internal void SetTextureInternal(string filename, bool isFile)
 {
     if (File.Exists(filename) && _type == HUDObjectType.Image)
     {
         lock (KWEngine.CustomTextures)
         {
             if (KWEngine.CustomTextures[KWEngine.CurrentWorld].ContainsKey(filename))
             {
                 _textureIds[0] = KWEngine.CustomTextures[KWEngine.CurrentWorld][filename];
             }
             else
             {
                 _textureIds[0] = isFile ? HelperTexture.LoadTextureForBackgroundExternal(filename) : HelperTexture.LoadTextureForBackgroundInternal(filename);
                 KWEngine.CustomTextures[KWEngine.CurrentWorld].Add(filename, _textureIds[0]);
             }
         }
         _count = 1;
     }
     else
     {
         throw new Exception("Error: Is your HUD Type set to 'Image'? Or maybe the file " + filename + " does not exist?");
     }
 }
Exemplo n.º 9
0
 internal void SetTextureBackgroundInternal(string filename, float repeatX = 1, float repeatY = 1, float clipX = 1, float clipY = 1, bool isFile = true)
 {
     if (filename == null || filename.Length < 1)
     {
         _textureBackground = -1;
     }
     else
     {
         if (KWEngine.CustomTextures[this].ContainsKey(filename))
         {
             _textureBackground = KWEngine.CustomTextures[this][filename];
         }
         else
         {
             _textureBackground = isFile ? HelperTexture.LoadTextureForBackgroundExternal(filename) : HelperTexture.LoadTextureForBackgroundInternal(filename);
             KWEngine.CustomTextures[this].Add(filename, _textureBackground);
         }
         _textureBackgroundTransform = new Vector2(HelperGeneral.Clamp(repeatX, 0.001f, 8192), HelperGeneral.Clamp(repeatY, 0.001f, 8192));
         _textureBackgroundClip      = new Vector2(HelperGeneral.Clamp(clipX, 0, 1), HelperGeneral.Clamp(clipY, 0, 1));
         _textureBackgroundOffset    = new Vector2(0, 0);
         _textureSkybox = -1;
     }
 }
Exemplo n.º 10
0
 internal void SetTextureInternal(string filename, bool isFile)
 {
     if (File.Exists(filename) && _type == HUDObjectType.Image)
     {
         lock (KWEngine.CustomTextures)
         {
             if (KWEngine.CustomTextures[KWEngine.CurrentWorld].ContainsKey(filename))
             {
                 _textureId = KWEngine.CustomTextures[KWEngine.CurrentWorld][filename];
             }
             else
             {
                 _textureId = isFile ? HelperTexture.LoadTextureForBackgroundExternal(filename) : HelperTexture.LoadTextureForBackgroundInternal(filename);
                 KWEngine.CustomTextures[KWEngine.CurrentWorld].Add(filename, _textureId);
             }
         }
         _count = 1;
     }
     else
     {
         HelperGeneral.ShowErrorAndQuit("HUDObject::SetTexture()", "Invalid call. Is your HUD Type set to 'Image' ? Or maybe the file " + filename + " does not exist ? ");
         return;
     }
 }
Exemplo n.º 11
0
 public void SetTexture(string texture)
 {
     _quad.SetTexture(HelperTexture.LoadTextureFromDisk(texture, out int w, out int h));
     SetScale(w, h);
 }
Exemplo n.º 12
0
        private static void ProcessMaterialsForMesh(Scene scene, Mesh mesh, ref GeoModel model, ref GeoMesh geoMesh, bool isKWCube = false)
        {
            GeoMaterial geoMaterial = new GeoMaterial();
            Material    material    = null;

            if (isKWCube)
            {
                if (mesh.MaterialIndex >= 0)
                {
                    material                  = scene.Materials[mesh.MaterialIndex];
                    geoMaterial.Name          = model.Filename == "kwcube.obj" ? "KWCube" : material.Name;
                    geoMaterial.BlendMode     = material.BlendMode == BlendMode.Default ? OpenTK.Graphics.OpenGL4.BlendingFactor.OneMinusSrcAlpha : OpenTK.Graphics.OpenGL4.BlendingFactor.One; // TODO: Check if this is correct!
                    geoMaterial.ColorDiffuse  = new Vector4(1, 1, 1, 1);
                    geoMaterial.ColorEmissive = new Vector4(0, 0, 0, 1);
                }
                else
                {
                    geoMaterial.Name          = "kw-undefined.";
                    geoMaterial.BlendMode     = OpenTK.Graphics.OpenGL4.BlendingFactor.OneMinusSrcAlpha;
                    geoMaterial.ColorDiffuse  = new Vector4(1, 1, 1, 1);
                    geoMaterial.ColorEmissive = new Vector4(0, 0, 0, 1);
                }
                geoMaterial.SpecularArea  = 1024;
                geoMaterial.SpecularPower = 0;
            }
            else
            {
                if (mesh.MaterialIndex >= 0)
                {
                    material         = scene.Materials[mesh.MaterialIndex];
                    geoMaterial.Name = material.Name;

                    if (material.Name == "DefaultMaterial")
                    {
                        geoMaterial.BlendMode     = OpenTK.Graphics.OpenGL4.BlendingFactor.OneMinusSrcAlpha;
                        geoMaterial.ColorDiffuse  = new Vector4(1, 1, 1, 1);
                        geoMaterial.ColorEmissive = new Vector4(0, 0, 0, 1);
                        geoMaterial.SpecularPower = 0;
                        geoMaterial.SpecularArea  = 1024;
                        geoMaterial.TextureSpecularIsRoughness = false;
                        if (mesh.Name != null && mesh.Name.ToLower().Contains("_invisible"))
                        {
                            geoMaterial.Opacity = 0;
                        }
                    }
                    else
                    {
                        geoMaterial.BlendMode = material.BlendMode == BlendMode.Default ? OpenTK.Graphics.OpenGL4.BlendingFactor.OneMinusSrcAlpha : OpenTK.Graphics.OpenGL4.BlendingFactor.One; // TODO: Check if this is correct!
                        if (model.AssemblyMode == AssemblyMode.Internal && material.Name == "System")
                        {
                            geoMaterial.ColorDiffuse = new Vector4(1, 1, 1, 1);
                        }
                        else if (model.AssemblyMode == AssemblyMode.Internal && material.Name == "X")
                        {
                            geoMaterial.ColorDiffuse = new Vector4(1, 0, 0, 1);
                        }
                        else if (model.AssemblyMode == AssemblyMode.Internal && material.Name == "Y")
                        {
                            geoMaterial.ColorDiffuse = new Vector4(0, 1, 0, 1);
                        }
                        else if (model.AssemblyMode == AssemblyMode.Internal && material.Name == "Z")
                        {
                            geoMaterial.ColorDiffuse = new Vector4(0, 0, 1, 1);
                        }
                        else
                        {
                            geoMaterial.ColorDiffuse = material.HasColorDiffuse ? new Vector4(material.ColorDiffuse.R, material.ColorDiffuse.G, material.ColorDiffuse.B, material.ColorDiffuse.A) : new Vector4(1, 1, 1, 1);
                        }
                        geoMaterial.ColorEmissive = material.HasColorEmissive ? new Vector4(material.ColorEmissive.R, material.ColorEmissive.G, material.ColorEmissive.B, material.ColorEmissive.A) : new Vector4(0, 0, 0, 1);
                        geoMaterial.SpecularPower = material.ShininessStrength;
                        geoMaterial.SpecularArea  = material.Shininess;
                        geoMaterial.TextureSpecularIsRoughness = false;
                        geoMaterial.Opacity = material.HasOpacity ? material.Opacity : 1;
                        if (mesh.Name != null && mesh.Name.ToLower().Contains("_invisible"))
                        {
                            geoMaterial.Opacity = 0;
                        }
                    }
                }
                else
                {
                    geoMaterial.Name          = "kw-undefined.";
                    geoMaterial.BlendMode     = OpenTK.Graphics.OpenGL4.BlendingFactor.OneMinusSrcAlpha;
                    geoMaterial.ColorDiffuse  = new Vector4(1, 1, 1, 1);
                    geoMaterial.ColorEmissive = new Vector4(0, 0, 0, 1);
                    geoMaterial.SpecularArea  = 1024;
                    geoMaterial.SpecularPower = 0;
                    geoMaterial.TextureSpecularIsRoughness = false;
                    if (mesh.Name != null && mesh.Name.ToLower().Contains("_invisible"))
                    {
                        geoMaterial.Opacity = 0;
                    }
                }
            }

            // Process Textures:
            if (material != null)
            {
                bool          roughnessUsed      = false;
                TextureSlot[] texturesOfMaterial = material.GetAllMaterialTextures();
                foreach (TextureSlot slot in texturesOfMaterial)
                {
                    if (slot.TextureType == TextureType.Shininess) // this is PBR Roughness
                    {
                        GeoTexture tex = new GeoTexture();
                        tex.UVTransform = new OpenTK.Vector2(1, 1);
                        tex.Filename    = slot.FilePath;
                        tex.UVMapIndex  = slot.UVIndex;
                        if (model.Textures.ContainsKey(tex.Filename))
                        {
                            tex.OpenGLID = model.Textures[tex.Filename].OpenGLID;
                        }
                        else
                        {
                            if (model.AssemblyMode == AssemblyMode.File)
                            {
                                tex.OpenGLID = HelperTexture.LoadTextureForModelExternal(
                                    FindTextureInSubs(StripPathFromFile(tex.Filename), model.PathAbsolute), true
                                    );
                            }
                            else
                            {
                                string path = StripFileNameFromAssemblyPath(model.PathAbsolute).Substring(model.PathAbsolute.IndexOf('.') + 1) + StripPathFromFile(tex.Filename);
                                tex.OpenGLID = HelperTexture.LoadTextureForModelInternal(path, true);
                            }
                            if (tex.OpenGLID > 0)
                            {
                                tex.Type = GeoTexture.TexType.Specular;
                                model.Textures.Add(tex.Filename, tex);
                                geoMaterial.TextureSpecular            = tex;
                                geoMaterial.TextureSpecularIsRoughness = true;
                                roughnessUsed = true;
                            }
                            else
                            {
                                geoMaterial.TextureSpecular            = tex;
                                geoMaterial.TextureSpecularIsRoughness = false;
                                tex.OpenGLID = KWEngine.TextureBlack;
                            }
                        }
                        break;
                    }
                }


                // Diffuse texture
                if (material.HasTextureDiffuse)
                {
                    GeoTexture tex = new GeoTexture();
                    tex.UVTransform = new OpenTK.Vector2(1, 1);
                    tex.Filename    = material.TextureDiffuse.FilePath;
                    tex.UVMapIndex  = material.TextureDiffuse.UVIndex;
                    tex.Type        = GeoTexture.TexType.Diffuse;
                    if (model.Textures.ContainsKey(tex.Filename))
                    {
                        tex.OpenGLID = model.Textures[tex.Filename].OpenGLID;
                        geoMaterial.TextureDiffuse = tex;
                    }
                    else if (CheckIfOtherModelsShareTexture(tex.Filename, model.Path, out GeoTexture sharedTexture))
                    {
                        geoMaterial.TextureDiffuse = sharedTexture;
                    }
                    else
                    {
                        if (model.AssemblyMode == AssemblyMode.File)
                        {
                            tex.OpenGLID = HelperTexture.LoadTextureForModelExternal(
                                FindTextureInSubs(StripPathFromFile(tex.Filename), model.PathAbsolute)
                                );
                        }
                        else
                        {
                            string path = StripFileNameFromAssemblyPath(model.PathAbsolute).Substring(model.PathAbsolute.IndexOf('.') + 1) + StripPathFromFile(tex.Filename);
                            tex.OpenGLID = HelperTexture.LoadTextureForModelInternal(path, true);
                        }
                        if (tex.OpenGLID > 0)
                        {
                            geoMaterial.TextureDiffuse = tex;
                            model.Textures.Add(tex.Filename, tex);
                        }
                        else
                        {
                            tex.OpenGLID = KWEngine.TextureDefault;
                            geoMaterial.TextureDiffuse = tex;
                        }
                    }
                }

                // Normal map texture
                if (material.HasTextureNormal)
                {
                    GeoTexture tex = new GeoTexture();
                    tex.UVTransform = new OpenTK.Vector2(1, 1);
                    tex.Filename    = material.TextureNormal.FilePath;
                    tex.UVMapIndex  = material.TextureNormal.UVIndex;
                    tex.Type        = GeoTexture.TexType.Normal;
                    if (model.Textures.ContainsKey(tex.Filename))
                    {
                        tex.OpenGLID = model.Textures[tex.Filename].OpenGLID;
                        geoMaterial.TextureNormal = tex;
                    }
                    else if (CheckIfOtherModelsShareTexture(tex.Filename, model.Path, out GeoTexture sharedTexture))
                    {
                        geoMaterial.TextureNormal = sharedTexture;
                    }
                    else
                    {
                        if (model.AssemblyMode == AssemblyMode.File)
                        {
                            tex.OpenGLID = HelperTexture.LoadTextureForModelExternal(
                                FindTextureInSubs(StripPathFromFile(tex.Filename), model.PathAbsolute)
                                );
                        }
                        else
                        {
                            string path = StripFileNameFromAssemblyPath(model.PathAbsolute).Substring(model.PathAbsolute.IndexOf('.') + 1) + StripPathFromFile(tex.Filename);
                            tex.OpenGLID = HelperTexture.LoadTextureForModelInternal(path, true);
                        }
                        if (tex.OpenGLID > 0)
                        {
                            model.Textures.Add(tex.Filename, tex);
                            geoMaterial.TextureNormal = tex;
                        }
                        else
                        {
                            tex.OpenGLID = KWEngine.TextureBlack;
                            //geoMaterial.TextureNormal = tex;
                        }
                    }
                }

                // Specular map texture
                if (material.HasTextureSpecular && roughnessUsed == false)
                {
                    GeoTexture tex = new GeoTexture();
                    tex.UVTransform = new OpenTK.Vector2(1, 1);
                    tex.Filename    = material.TextureSpecular.FilePath;
                    tex.UVMapIndex  = material.TextureSpecular.UVIndex;
                    tex.Type        = GeoTexture.TexType.Specular;
                    if (model.Textures.ContainsKey(tex.Filename))
                    {
                        tex.OpenGLID = model.Textures[tex.Filename].OpenGLID;
                        geoMaterial.TextureSpecular = tex;
                    }
                    else if (CheckIfOtherModelsShareTexture(tex.Filename, model.Path, out GeoTexture sharedTexture))
                    {
                        geoMaterial.TextureSpecular = sharedTexture;
                    }
                    else
                    {
                        if (model.AssemblyMode == AssemblyMode.File)
                        {
                            tex.OpenGLID = HelperTexture.LoadTextureForModelExternal(
                                FindTextureInSubs(StripPathFromFile(tex.Filename), model.PathAbsolute)
                                );
                        }
                        else
                        {
                            string path = StripFileNameFromAssemblyPath(model.PathAbsolute).Substring(model.PathAbsolute.IndexOf('.') + 1) + StripPathFromFile(tex.Filename);
                            tex.OpenGLID = HelperTexture.LoadTextureForModelInternal(path, true);
                        }
                        if (tex.OpenGLID > 0)
                        {
                            geoMaterial.TextureSpecular = tex;

                            model.Textures.Add(tex.Filename, tex);
                        }
                        else
                        {
                            tex.OpenGLID = KWEngine.TextureBlack;
                            geoMaterial.TextureSpecular = tex;
                        }
                    }
                }
                else
                {
                    if (material.HasTextureSpecular && roughnessUsed)
                    {
                        Debug.WriteLine("Skipping specular texture for " + model.Filename + " because roughness texture was found.");
                    }
                }

                // Emissive map texture
                if (material.HasTextureEmissive)
                {
                    GeoTexture tex = new GeoTexture();
                    tex.UVTransform = new OpenTK.Vector2(1, 1);
                    tex.Filename    = material.TextureEmissive.FilePath;
                    tex.UVMapIndex  = material.TextureEmissive.UVIndex;
                    tex.Type        = GeoTexture.TexType.Emissive;
                    if (model.Textures.ContainsKey(tex.Filename))
                    {
                        tex.OpenGLID = model.Textures[tex.Filename].OpenGLID;
                        geoMaterial.TextureEmissive = tex;
                    }
                    else if (CheckIfOtherModelsShareTexture(tex.Filename, model.Path, out GeoTexture sharedTexture))
                    {
                        geoMaterial.TextureEmissive = sharedTexture;
                    }
                    else
                    {
                        if (model.AssemblyMode == AssemblyMode.File)
                        {
                            tex.OpenGLID = HelperTexture.LoadTextureForModelExternal(
                                FindTextureInSubs(StripPathFromFile(tex.Filename), model.PathAbsolute)
                                );
                        }
                        else
                        {
                            string path = StripFileNameFromAssemblyPath(model.PathAbsolute).Substring(model.PathAbsolute.IndexOf('.') + 1) + StripPathFromFile(tex.Filename);
                            tex.OpenGLID = HelperTexture.LoadTextureForModelInternal(path, true);
                        }
                        if (tex.OpenGLID > 0)
                        {
                            geoMaterial.TextureEmissive = tex;

                            model.Textures.Add(tex.Filename, tex);
                        }
                        else
                        {
                            tex.OpenGLID = KWEngine.TextureBlack;
                            geoMaterial.TextureEmissive = tex;
                        }
                    }
                }

                // Light map texture
                if (material.HasTextureLightMap)
                {
                    GeoTexture tex = new GeoTexture();
                    tex.UVTransform = new OpenTK.Vector2(1, 1);
                    tex.Filename    = material.TextureLightMap.FilePath;
                    tex.UVMapIndex  = material.TextureLightMap.UVIndex;
                    tex.Type        = GeoTexture.TexType.Light;
                    if (model.Textures.ContainsKey(tex.Filename))
                    {
                        tex.OpenGLID             = model.Textures[tex.Filename].OpenGLID;
                        geoMaterial.TextureLight = tex;
                    }
                    else if (CheckIfOtherModelsShareTexture(tex.Filename, model.Path, out GeoTexture sharedTexture))
                    {
                        geoMaterial.TextureLight = sharedTexture;
                    }
                    else
                    {
                        if (model.AssemblyMode == AssemblyMode.File)
                        {
                            tex.OpenGLID = HelperTexture.LoadTextureForModelExternal(
                                FindTextureInSubs(StripPathFromFile(tex.Filename), model.PathAbsolute)
                                );
                        }
                        else
                        {
                            string path = StripFileNameFromAssemblyPath(model.PathAbsolute).Substring(model.PathAbsolute.IndexOf('.') + 1) + StripPathFromFile(tex.Filename);
                            tex.OpenGLID = HelperTexture.LoadTextureForModelInternal(path, true);
                        }
                        if (tex.OpenGLID > 0)
                        {
                            model.Textures.Add(tex.Filename, tex);
                            geoMaterial.TextureLight = tex;
                        }
                        else
                        {
                            tex.OpenGLID = KWEngine.TextureBlack;
                            //geoMaterial.TextureLight = tex;
                        }
                    }
                }
            }

            geoMesh.Material = geoMaterial;
        }
Exemplo n.º 13
0
        /// <summary>
        /// Baut ein Terrain-Modell
        /// </summary>
        /// <param name="name">Name des Modells</param>
        /// <param name="heightmap">Height Map Textur</param>
        /// <param name="texture">Textur der Oberfläche</param>
        /// <param name="width">Breite</param>
        /// <param name="height">Höhe</param>
        /// <param name="depth">Tiefe</param>
        /// <param name="texRepeatX">Texturwiederholung Breite</param>
        /// <param name="texRepeatZ">Texturwiederholung Tiefe</param>
        /// <param name="isFile">false, wenn die Texturen Teil der EXE sind (Eingebettete Ressource)</param>
        public static void BuildTerrainModel(string name, string heightmap, string texture, float width, float height, float depth, float texRepeatX = 1, float texRepeatZ = 1, bool isFile = true)
        {
            if (Models.ContainsKey(name))
            {
                throw new Exception("There already is a model with that name. Please choose a different name.");
            }
            GeoModel terrainModel = new GeoModel();

            terrainModel.Name    = name;
            terrainModel.Meshes  = new Dictionary <string, GeoMesh>();
            terrainModel.IsValid = true;

            GeoMeshHitbox meshHitBox = new GeoMeshHitbox(0 + width / 2, 0 + height / 2, 0 + depth / 2, 0 - width / 2, 0 - height / 2, 0 - depth / 2);

            meshHitBox.Model = terrainModel;
            meshHitBox.Name  = name;

            terrainModel.MeshHitboxes = new List <GeoMeshHitbox>();
            terrainModel.MeshHitboxes.Add(meshHitBox);

            GeoTerrain t           = new GeoTerrain();
            GeoMesh    terrainMesh = t.BuildTerrain(new Vector3(0, 0, 0), heightmap, width, height, depth, texRepeatX, texRepeatZ, isFile);

            terrainMesh.Terrain = t;
            GeoMaterial mat = new GeoMaterial();

            mat.BlendMode     = OpenTK.Graphics.OpenGL4.BlendingFactor.OneMinusSrcAlpha;
            mat.ColorDiffuse  = new Vector4(1, 1, 1, 1);
            mat.ColorEmissive = new Vector4(0, 0, 0, 0);
            mat.Name          = name + "-Material";
            mat.SpecularArea  = 512;
            mat.SpecularPower = 0;

            GeoTexture texDiffuse = new GeoTexture(name + "-TextureDiffuse");

            texDiffuse.Filename    = texture;
            texDiffuse.Type        = GeoTexture.TexType.Diffuse;
            texDiffuse.UVMapIndex  = 0;
            texDiffuse.UVTransform = new Vector2(texRepeatX, texRepeatZ);

            bool dictFound = CustomTextures.TryGetValue(CurrentWorld, out Dictionary <string, int> texDict);

            if (dictFound && texDict.ContainsKey(texture))
            {
                texDiffuse.OpenGLID = texDict[texture];
            }
            else
            {
                texDiffuse.OpenGLID = isFile ? HelperTexture.LoadTextureForModelExternal(texture) : HelperTexture.LoadTextureForModelInternal(texture);
                if (dictFound)
                {
                    texDict.Add(texture, texDiffuse.OpenGLID);
                }
            }
            mat.TextureDiffuse = texDiffuse;


            terrainMesh.Material = mat;
            terrainModel.Meshes.Add("Terrain", terrainMesh);
            KWEngine.Models.Add(name, terrainModel);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Baut ein Terrain-Modell
        /// </summary>
        /// <param name="name">Name des Modells</param>
        /// <param name="heightmap">Height Map Textur</param>
        /// <param name="texture">Textur der Oberfläche</param>
        /// <param name="width">Breite</param>
        /// <param name="height">Höhe</param>
        /// <param name="depth">Tiefe</param>
        /// <param name="texRepeatX">Texturwiederholung Breite</param>
        /// <param name="texRepeatZ">Texturwiederholung Tiefe</param>
        /// <param name="isFile">false, wenn die Texturen Teil der EXE sind (Eingebettete Ressource)</param>
        public static void BuildTerrainModel(string name, string heightmap, string texture, float width, float height, float depth, float texRepeatX = 1, float texRepeatZ = 1, bool isFile = true)
        {
            if (Models.ContainsKey(name))
            {
                HelperGeneral.ShowErrorAndQuit("KWEngine::BuildTerrainModel()", "There already is a model with that name. Please choose a different name.");
                return;
            }
            GeoModel terrainModel = new GeoModel();

            terrainModel.Name    = name;
            terrainModel.Meshes  = new Dictionary <string, GeoMesh>();
            terrainModel.IsValid = true;

            GeoMeshHitbox meshHitBox = new GeoMeshHitbox(0 + width / 2, 0 + height / 2, 0 + depth / 2, 0 - width / 2, 0 - height / 2, 0 - depth / 2, null);

            meshHitBox.Model = terrainModel;
            meshHitBox.Name  = name;

            terrainModel.MeshHitboxes = new List <GeoMeshHitbox>();
            terrainModel.MeshHitboxes.Add(meshHitBox);

            GeoTerrain t           = new GeoTerrain();
            GeoMesh    terrainMesh = t.BuildTerrain2(new Vector3(0, 0, 0), heightmap, width, height, depth, texRepeatX, texRepeatZ, isFile);

            terrainMesh.Terrain = t;
            GeoMaterial mat = new GeoMaterial();

            mat.BlendMode     = BlendingFactor.OneMinusSrcAlpha;
            mat.ColorAlbedo   = new Vector4(1, 1, 1, 1);
            mat.ColorEmissive = new Vector4(0, 0, 0, 0);
            mat.Opacity       = 1;
            mat.Metalness     = 0;
            mat.Roughness     = 1;

            GeoTexture texDiffuse = new GeoTexture();

            texDiffuse.Filename    = texture;
            texDiffuse.Type        = TextureType.Albedo;
            texDiffuse.UVMapIndex  = 0;
            texDiffuse.UVTransform = new Vector2(texRepeatX, texRepeatZ);

            bool dictFound = CustomTextures.TryGetValue(CurrentWorld, out Dictionary <string, int> texDict);

            if (dictFound && texDict.ContainsKey(texture))
            {
                texDiffuse.OpenGLID = texDict[texture];
            }
            else
            {
                int texId = isFile ? HelperTexture.LoadTextureForModelExternal(texture) : HelperTexture.LoadTextureForModelInternal(texture);
                texDiffuse.OpenGLID = texId > 0 ? texId : KWEngine.TextureDefault;

                if (dictFound && texId > 0)
                {
                    texDict.Add(texture, texDiffuse.OpenGLID);
                }
            }
            mat.TextureAlbedo = texDiffuse;


            terrainMesh.Material = mat;
            terrainModel.Meshes.Add("Terrain", terrainMesh);
            KWEngine.Models.Add(name, terrainModel);
        }