/// <summary>
 ///
 /// </summary>
 /// <param name="reader"></param>
 private static void ReadSRT2D(BinaryDataReader reader)
 {
     ValueSrt2D = new Srt2D();
     Syroot.Maths.Vector2F scaleVector2F = new Syroot.Maths.Vector2F(reader.ReadSingle(), reader.ReadSingle());
     ValueSrt2D.Scaling  = scaleVector2F;
     ValueSrt2D.Rotation = reader.ReadSingle();
     Syroot.Maths.Vector2F transVector2F = new Syroot.Maths.Vector2F(reader.ReadSingle(), reader.ReadSingle());
     ValueSrt2D.Translation = transVector2F;
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="reader"></param>
 private static void ReadTexSrt(BinaryDataReader reader)
 {
     ValueTexSrt      = new TexSrt();
     ValueTexSrt.Mode = reader.ReadEnum <TexSrtMode>(false);
     Syroot.Maths.Vector2F scaleVector2F = new Syroot.Maths.Vector2F(reader.ReadSingle(), reader.ReadSingle());
     ValueTexSrt.Scaling  = scaleVector2F;
     ValueTexSrt.Rotation = reader.ReadSingle();
     Syroot.Maths.Vector2F transVector2F = new Syroot.Maths.Vector2F(reader.ReadSingle(), reader.ReadSingle());
     ValueTexSrt.Translation = transVector2F;
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="reader"></param>
 private static void ReadTexSrtEx(BinaryDataReader reader)
 {
     ValueTexSrtEx      = new TexSrtEx();
     ValueTexSrtEx.Mode = reader.ReadEnum <TexSrtMode>(true);
     Syroot.Maths.Vector2F scaleVector2F = new Syroot.Maths.Vector2F(reader.ReadSingle(), reader.ReadSingle());
     ValueTexSrtEx.Scaling  = scaleVector2F;
     ValueTexSrtEx.Rotation = reader.ReadSingle();
     Syroot.Maths.Vector2F transVector2F = new Syroot.Maths.Vector2F(reader.ReadSingle(), reader.ReadSingle());
     ValueTexSrtEx.Translation   = transVector2F;
     ValueTexSrtEx.MatrixPointer = reader.ReadUInt32();
 }
 public void Write(Syroot.Maths.Vector2F v)
 {
     Write(v.X);
     Write(v.Y);
 }
Exemple #5
0
 public static string DataToString(Syroot.Maths.Vector2F v)
 {
     return($"{v.X},{v.Y}");
 }
Exemple #6
0
 public static Vector2 ToVec2(Syroot.Maths.Vector2F v)
 {
     return(new Vector2(v.X, v.Y));
 }
Exemple #7
0
 public static OpenTK.Vector2 ToTKVector2(this Syroot.Maths.Vector2F vec2)
 {
     return(new OpenTK.Vector2(vec2.X, vec2.Y));
 }
Exemple #8
0
        public static void LoadTextureUniforms(BxlytShader shader, BxlytMaterial material,
                                               Dictionary <string, STGenericTexture> textures)
        {
            shader.SetInt("hasTexture0", 0);
            shader.SetInt("hasTexture1", 0);
            shader.SetInt("hasTexture2", 0);
            shader.SetInt("textures0", 0);
            shader.SetInt("textures1", 0);
            shader.SetInt("textures2", 0);

            BindTextureUniforms(shader, material);

            if (material.TextureMaps.Length > 0 || Runtime.LayoutEditor.Shading == Runtime.LayoutEditor.DebugShading.UVTestPattern)
            {
                GL.Enable(EnableCap.Texture2D);
            }

            for (int i = 0; i < 3; i++)
            {
                //Default UVs as centered
                var matTranslate = Matrix4.CreateTranslation(0 / 1 - 0.5f, 0 / 1 - 0.5f, 0);
                shader.SetMatrix(String.Format("textureTransforms[{0}]", i), ref matTranslate);
            }

            int id = 1;

            for (int i = 0; i < material.TextureMaps.Length; i++)
            {
                string TexName = material.TextureMaps[i].Name;

                if (material.animController.TexturePatterns.ContainsKey((LTPTarget)i))
                {
                    TexName = material.animController.TexturePatterns[(LTPTarget)i];
                }

                if (textures.ContainsKey(TexName))
                {
                    GL.ActiveTexture(TextureUnit.Texture0 + id);
                    shader.SetInt($"textures{i}", id);
                    bool isBinded = BxlytToGL.BindGLTexture(material.TextureMaps[i], textures[TexName]);
                    if (isBinded)
                    {
                        shader.SetInt($"hasTexture{i}", 1);
                    }

                    var   scale     = new Syroot.Maths.Vector2F(1, 1);
                    float rotate    = 0;
                    var   translate = new Syroot.Maths.Vector2F(0, 0);

                    int index = i;

                    if (material.TextureTransforms.Length > index)
                    {
                        var transform = material.TextureTransforms[index];
                        scale     = transform.Scale;
                        rotate    = transform.Rotate;
                        translate = transform.Translate;

                        foreach (var animItem in material.animController.TextureSRTS)
                        {
                            switch (animItem.Key)
                            {
                            case LTSTarget.ScaleS: scale.X = animItem.Value; break;

                            case LTSTarget.ScaleT: scale.Y = animItem.Value; break;

                            case LTSTarget.Rotate: rotate = animItem.Value; break;

                            case LTSTarget.TranslateS: translate.X = animItem.Value; break;

                            case LTSTarget.TranslateT: translate.Y = animItem.Value; break;
                            }
                        }
                    }


                    var matScale     = Matrix4.CreateScale(scale.X, scale.Y, 1.0f);
                    var matRotate    = Matrix4.CreateFromAxisAngle(new Vector3(0, 0, 1), MathHelper.DegreesToRadians(rotate));
                    var matTranslate = Matrix4.CreateTranslation(
                        translate.X / scale.X - 0.5f,
                        translate.Y / scale.Y - 0.5f, 0);

                    Matrix4 matTransform = matRotate * matTranslate * matScale;
                    shader.SetMatrix(String.Format("textureTransforms[{0}]", i), ref matTransform);

                    id++;
                }
            }
        }