Пример #1
0
        private void GenerateMaterial(string name, string texAmbient, string texDiffuse, string texSpecular,
                                      Color4 ambient, Color4 diffuse, Color4 specular, float alpha, ref Dictionary <string, Material> materials)
        {
            if (materials.ContainsKey(name))
            {
                return;
            }

            if (alpha != -1.0f)
            {
                ambient.A = diffuse.A = alpha;
            }

            Texture.Texture texture = null;

            if (texAmbient != string.Empty)
            {
                texture = TextureLoader.Load(texAmbient);
            }
            else if (texDiffuse != string.Empty)
            {
                texture = TextureLoader.Load(texDiffuse);
            }
            else if (texSpecular != string.Empty)
            {
                texture = TextureLoader.Load(texSpecular);
            }
            else
            {
                return;
            }

            materials.Add(name, new Material(texture, ambient, diffuse, specular));
        }
Пример #2
0
        public static DLCSong ConvertDLCSong(DataArray songDta, GameArchives.IDirectory songRoot)
        {
            var path          = songDta.Array("song").Array("name").String(1);
            var hopoThreshold = songDta.Array("song").Array("hopo_threshold")?.Int(1) ?? 170;
            var shortname     = path.Split('/').Last();
            var midPath       = shortname + ".mid";
            var artPath       = $"gen/{shortname}_keep.png_xbox";
            var miloPath      = $"gen/{shortname}.milo_xbox";
            var songId        = songDta.Array("song_id").Node(1);
            var name          = songDta.Array("name").String(1);
            var artist        = songDta.Array("artist").String(1);
            var mid           = MidiCS.MidiFileReader.FromBytes(songRoot.GetFileAtPath(midPath).GetBytes());

            // TODO: Catch possible conversion exceptions? i.e. Unsupported milo version
            var milo     = MiloFile.ReadFromStream(songRoot.GetFileAtPath(miloPath).GetStream());
            var songData = SongDataConverter.ToSongData(songDta);

            Texture.Texture artwork = null;
            if (songData.AlbumArt)
            {
                artwork = Texture.TextureConverter.MiloPngToTexture(songRoot.GetFileAtPath(artPath).GetStream());
            }
            return(new DLCSong
            {
                SongData = songData,
                Lipsync = LipsyncConverter.FromMilo(milo),
                Mogg = songRoot.GetFile(shortname + ".mogg"),
                MoggDta = MakeMoggDta(songDta),
                MoggSong = DTX.FromDtaString($"(mogg_path \"{shortname}.mogg\")\r\n(midi_path \"{shortname}.rbmid\")\r\n"),
                RBMidi = RBMidConverter.ToRBMid(mid, hopoThreshold),
                Artwork = artwork,
                RBSong = MakeRBSong(songDta)
            });
        }
Пример #3
0
 public void SetParameter(string name, Texture.Texture texture)
 {
     if (!SetParam(name, texture, RenderParameterType.Texture))
     {
         parameters.Add(name, new TextureParameter(texture));
     }
 }
Пример #4
0
 public Material(Texture.Texture texture, Vector4 ambient, Vector4 diffuse, Vector4 specular)
     : this()
 {
     Texture  = texture;
     Ambient  = new Color4(ambient.X, ambient.Y, ambient.Z, ambient.W);
     Diffuse  = new Color4(diffuse.X, diffuse.Y, diffuse.Z, diffuse.W);
     Specular = new Color4(specular.X, specular.Y, specular.Z, specular.W);
 }
Пример #5
0
 public Material(Texture.Texture texture, Color4 ambient, Color4 diffuse, Color4 specular)
     : this()
 {
     Texture  = texture;
     Ambient  = ambient;
     Diffuse  = diffuse;
     Specular = specular;
 }
Пример #6
0
            public void AnimateColor(Texture.Texture texture, Color4 to, int frame, Func <double, double> easing = null)
            {
                if (frame == 0)
                {
                    return;
                }

                frame /= 2;
                easing = easing ?? EasingFunctions.Linear;

                this.targetObject  = texture;
                this.targetPropery = "color";

                Color4 from      = new Color4();
                bool   noCompile = false;

                float dr = 0f, dg = 0f, db = 0f, da = 0f;

                Process.Invoke(() =>
                {
                    texture.NoCompile = true;
                    from      = texture.Color;
                    noCompile = texture.NoCompile;

                    dr = (to.R - from.R);
                    dg = (to.G - from.G);
                    db = (to.B - from.B);
                    da = (to.A - from.A);
                });

                for (int i = 0, j = 1; i < frame; i++)
                {
                    Process.WaitFrame(1);
                    Process.Invoke(() =>
                    {
                        float f       = (float)easing(j++ / (double)frame);
                        texture.Color = new Color4((from.R + dr * f).Clamp(1f, 0f),
                                                   (from.G + dg * f).Clamp(1f, 0f),
                                                   (from.B + db * f).Clamp(1f, 0f),
                                                   (from.A + da * f).Clamp(1f, 0f));
                    });
                }

                Process.Invoke(() =>
                {
                    if (!noCompile)
                    {
                        texture.NoCompile = false;
                    }
                });
            }
Пример #7
0
        private void AsignmentTexture(int id, Texture.Texture texture)
        {
            int key;

            if (this.asignment.ContainsKey(id))
            {
                key = this.asignment[id];
                this.Window.Textures.Remove(key, true);
                this.Window.Textures.Add(key, texture);
            }
            else
            {
                key = this.Window.Textures.AddLast(texture);
                this.asignment.Add(id, key);
            }
        }
Пример #8
0
        /// <summary>
        /// テキストオプションと描画先のテクスチャを指定して新しい TextRenderer クラスの新しいインスタンスを初期化します。
        /// </summary>
        /// <param name="options">使用されるテキストオプション。</param>
        /// <param name="texture">描画先のテクスチャ。</param>
        public TextRenderer(TextOptions options, Texture.Texture texture)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            if (texture == null)
            {
                throw new ArgumentNullException("texture");
            }

            this.options  = options;
            this.bitmap   = texture.BaseBitmap;
            this.graphics = Graphics.FromImage(texture.BaseBitmap);
        }
Пример #9
0
            public void AnimatePosition(Texture.Texture texture, PointF to, int frame, Func <double, double> easing = null)
            {
                if (frame == 0)
                {
                    return;
                }

                frame /= 2;
                easing = easing ?? EasingFunctions.Linear;

                this.targetObject  = texture;
                this.targetPropery = "position";

                PointF from      = new PointF();
                bool   noCompile = false;

                float dx = 0f, dy = 0f;

                Process.Invoke(() =>
                {
                    texture.NoCompile = true;
                    from      = texture.Position;
                    noCompile = texture.NoCompile;

                    dx = (to.X - from.X);
                    dy = (to.Y - from.Y);
                });

                for (int i = 0, j = 1; i < frame; i++)
                {
                    Process.WaitFrame(1);
                    Process.Invoke(() =>
                    {
                        float f          = (float)easing(j++ / (double)frame);
                        texture.Position = new PointF(from.X + dx * f, from.Y + dy * f);
                    });
                }

                Process.Invoke(() =>
                {
                    if (!noCompile)
                    {
                        texture.NoCompile = false;
                    }
                });
            }
Пример #10
0
 public Material(Texture.Texture texture)
     : this()
 {
     Texture = texture;
 }
Пример #11
0
        protected override void OnLoad(EventArgs e)
        {
            face = new Texture.Texture("face.png", out facedt);
            //Brickon.Model.Model.Load("leg.3d", out Points, out Col);
            // Points.Add(new Vector3(0, 1, 0));

            // Load the source of the vertex shader and compile it.
            VertexShader = GL.CreateShader(ShaderType.VertexShader);
            GL.ShaderSource(VertexShader, VertexShaderSource);
            GL.CompileShader(VertexShader);

            // Load the source of the fragment shader and compile it.
            FragmentShader = GL.CreateShader(ShaderType.FragmentShader);
            GL.ShaderSource(FragmentShader, FragmentShaderSource);
            GL.CompileShader(FragmentShader);

            // Create the shader program, attach the vertex and fragment shaders and link the program.
            ShaderProgram = GL.CreateProgram();
            GL.AttachShader(ShaderProgram, VertexShader);
            GL.AttachShader(ShaderProgram, FragmentShader);
            GL.LinkProgram(ShaderProgram);
            model      = Matrix4.Identity * Matrix4.CreateRotationX((float)MathHelper.DegreesToRadians(1));
            projection = Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(55f), this.Size.Width / (float)this.Size.Height, 0.1f, 100.0f);
            view       = Matrix4.CreateTranslation(0.0f, 0.0f, -3.0f);

            GL.UniformMatrix4(GL.GetUniformLocation(ShaderProgram, "projection"), true, ref projection);

            GL.UniformMatrix4(GL.GetUniformLocation(ShaderProgram, "model"), true, ref model);

            GL.UniformMatrix4(GL.GetUniformLocation(ShaderProgram, "view"), true, ref view);

            GL.Uniform1(GL.GetUniformLocation(ShaderProgram, "texdt"), facedt);

            // Create the vertex buffer object (VBO) for the vertex data.
            VertexBufferObject = GL.GenBuffer();
            VertexColBuffer    = GL.GenBuffer();
            // Bind the VBO and copy the vertex data into it.
            GL.BindVertexArray(VertexArrayObject);

            GL.BindBuffer(BufferTarget.ArrayBuffer, VertexBufferObject);
            //Send data to bound buffer in the specified "slot"
            //The kind of buffer, The size of the array i(the array length * size of an element), The data(because we had a list we convert it to an array), Buffer Usage, doesn't matter that much nowadays
            GL.BufferData(BufferTarget.ArrayBuffer, Points.Count * Vector3.SizeInBytes, Points.ToArray(), BufferUsageHint.StaticDraw);
            //Same thing but for colors
            GL.BindBuffer(BufferTarget.ArrayBuffer, VertexColBuffer);
            GL.BufferData(BufferTarget.ArrayBuffer, Col.Count * Vector4.SizeInBytes, Col.ToArray(), BufferUsageHint.StaticDraw);


            // Retrive the position location from the program.
            var positionLocation = GL.GetAttribLocation(ShaderProgram, "position");
            var colLocation      = GL.GetAttribLocation(ShaderProgram, "coldt");

            // Create the vertex array object (VAO) for the program.
            VertexArrayObject = GL.GenVertexArray();
            GL.BindVertexArray(VertexArrayObject);

            //No clue what I did exactly but array locations might be hardcoded in the shader
            GL.EnableVertexAttribArray(0);
            GL.EnableVertexAttribArray(1);

            //Set some info for the shader to know how big each buffer, how many bytes each element take, their offset, etc their kind
            //Bind the buffer we want to be used in the "slot" we specify in the next call
            GL.BindBuffer(BufferTarget.ArrayBuffer, VertexBufferObject);
            //We have a vector 3 for the positions so 3 floats, not normalized, the stride is 3 because we don't store anything else in this buffer and offset 0 because we start from start
            GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, 3 * sizeof(float), 0);
            //Same but for the colors
            GL.BindBuffer(BufferTarget.ArrayBuffer, VertexColBuffer);
            GL.VertexAttribPointer(1, 4, VertexAttribPointerType.Float, false, 4 * sizeof(float), 0);

            //Some bad equivalent to GL.End
            //Bind the buffer which to be used
            GL.BindBuffer(BufferTarget.ArrayBuffer, VertexBufferObject);
            //Send data to bound buffer in the specified "slot"
            //The kind of buffer, The size of the array i(the array length * size of an element), The data(because we had a list we convert it to an array), Buffer Usage, doesn't matter that much nowadays
            GL.BufferData(BufferTarget.ArrayBuffer, Points.Count * Vector3.SizeInBytes, Points.ToArray(), BufferUsageHint.StaticDraw);
            //Same thing but for colors
            GL.BindBuffer(BufferTarget.ArrayBuffer, VertexColBuffer);
            GL.BufferData(BufferTarget.ArrayBuffer, Col.Count * Vector4.SizeInBytes, Col.ToArray(), BufferUsageHint.StaticDraw);
            // Set the clear color to blue

            arm1.setup1();
            arm.setup1();
            torso.setup1();
            head.setup1();
            leg1.setup1();
            leg.setup1();

            GL.ClearColor(0.0f, 0.0f, 1.0f, 1.0f);



            Console.WriteLine(GL.GetShaderInfoLog(VertexShader));
            Console.WriteLine(GL.GetShaderInfoLog(FragmentShader));


            base.OnLoad(e);
        }
Пример #12
0
 public Font(Texture.Texture texture, Dictionary<char, CharacterData> characters)
 {
     this._texture = texture;
     this.Characters = characters;
 }
Пример #13
0
 public Font(Texture.Texture texture, string filePath)
 {
     this._texture = texture;
     this.FilePath = filePath;
     Characters = Parse(filePath);
 }
Пример #14
0
        private void GetTextures()
        {
            var palettes = new List <TexPalette>();
            var textures = new List <TexImage>();

            int texId     = 0;
            int paletteId = 0;

            if (_scene.HasTextures)
            {
                throw new NotImplementedException("Embedded Textures aren't implemented yet");

                /*foreach (var tex in scene.Textures)
                 * {
                 *
                 * }*/
            }
            else
            {
                foreach (var mat in _scene.Materials)
                {
                    if (mat.HasTextureDiffuse)
                    {
                        var tex = mat.GetMaterialTextures(TextureType.Diffuse)[0];

                        if (_imd.Body.TexImageArray == null)
                        {
                            _imd.Body.TexImageArray = new TexImageArray();
                        }

                        var texPath = Path.GetFullPath(Path.Combine(_modelDirectory,
                                                                    tex.FilePath.Substring(0, 2) == "//" ? tex.FilePath.Remove(0, 2) : tex.FilePath));
                        var texName = Path.GetFileNameWithoutExtension(texPath);


                        //Prevents doubled textures
                        bool repeated = false;
                        foreach (var prevTex in textures)
                        {
                            if (prevTex.Name == texName)
                            {
                                repeated = true;
                                break;
                            }
                        }

                        if (repeated)
                        {
                            continue;
                        }

                        var texture = new Texture.Texture(texPath);

                        if (_imd.Body.TexPaletteArray == null && texture.Format != "direct")
                        {
                            _imd.Body.TexPaletteArray = new TexPaletteArray();
                        }

                        var texImage = new TexImage
                        {
                            Index  = texId++,
                            Name   = texture.TextureName,
                            Path   = texPath,
                            Height = texture.Height,
                            Width  = texture.Width,
                            Bitmap = new TexBitmap
                            {
                                Size  = texture.BitmapSize,
                                Value = texture.BitmapData
                            },
                            Format         = texture.Format,
                            OriginalHeight = texture.Height,
                            OriginalWidth  = texture.Width,
                            PaletteName    = texture.PaletteName
                        };

                        if (texture.Format == "tex4x4")
                        {
                            texImage.Tex4x4PaletteIndex = new Tex4x4PaletteIndex
                            {
                                Size  = texture.Tex4x4PaletteIndexSize,
                                Value = texture.Tex4x4PaletteIndexData
                            };
                        }
                        else if (texture.Format == "palette4" || texture.Format == "palette16" ||
                                 texture.Format == "palette256")
                        {
                            texImage.Color0Mode = texture.Color0Transparent ? "transparency" : "color";
                        }

                        textures.Add(texImage);

                        if (texture.Format != "direct")
                        {
                            palettes.Add(new TexPalette
                            {
                                ColorSize = texture.PaletteSize,
                                Index     = paletteId++,
                                Name      = texture.PaletteName,
                                Value     = texture.PaletteData
                            });
                        }
                    }
                }
            }

            if (_imd.Body.TexImageArray != null)
            {
                _imd.Body.TexImageArray.TexImages = textures;

                if (_imd.Body.TexPaletteArray != null)
                {
                    _imd.Body.TexPaletteArray.TexPalettes = palettes;
                }
            }
        }