Example #1
0
        public static void CopyTo(this MaterialChannel srcChannel, Materials.ChannelBuilder dstChannel)
        {
            Guard.NotNull(srcChannel, nameof(srcChannel));
            Guard.NotNull(dstChannel, nameof(dstChannel));

            dstChannel.Parameter = srcChannel.Parameter;

            if (srcChannel.Texture == null)
            {
                return;
            }

            if (dstChannel.Texture == null)
            {
                dstChannel.UseTexture();
            }

            dstChannel.Texture.CoordinateSet = srcChannel.TextureCoordinate;
            dstChannel.Texture.MinFilter     = srcChannel.TextureSampler.MinFilter;
            dstChannel.Texture.MagFilter     = srcChannel.TextureSampler.MagFilter;
            dstChannel.Texture.WrapS         = srcChannel.TextureSampler.WrapS;
            dstChannel.Texture.WrapT         = srcChannel.TextureSampler.WrapT;

            /*
             * dstChannel.Texture.Rotation = srcChannel.Transform?.Rotation ?? 0;
             * dstChannel.Texture.Offset = srcChannel.Transform?.Offset ?? Vector2.Zero;
             * dstChannel.Texture.Scale = srcChannel.Transform?.Scale ?? Vector2.One;
             */

            dstChannel.Texture.ImageContent = srcChannel.Texture.Image.GetImageContent();
        }
Example #2
0
        public static void CopyTo(this ChannelBuilder srcChannel, MaterialChannel dstChannel)
        {
            Guard.NotNull(srcChannel, nameof(srcChannel));
            Guard.NotNull(dstChannel, nameof(dstChannel));

            foreach (var dstProp in dstChannel.Parameters)
            {
                dstProp.Value = srcChannel.Parameters[dstProp.Name].ToTypeless();
            }

            var srcTex = srcChannel.GetValidTexture();

            if (srcTex == null)
            {
                return;
            }

            Image primary  = null;
            Image fallback = null;

            if (ImageBuilder.IsValid(srcTex.PrimaryImage))
            {
                primary = dstChannel
                          .LogicalParent
                          .LogicalParent
                          .UseImageWithContent(srcTex.PrimaryImage.Content);

                srcTex.PrimaryImage.TryCopyNameAndExtrasTo(primary);
            }

            if (primary == null)
            {
                return;
            }

            if (ImageBuilder.IsValid(srcTex.FallbackImage))
            {
                fallback = dstChannel
                           .LogicalParent
                           .LogicalParent
                           .UseImageWithContent(srcTex.FallbackImage.Content);

                srcTex.FallbackImage.TryCopyNameAndExtrasTo(fallback);
            }

            var dstTex = dstChannel.SetTexture(srcTex.CoordinateSet, primary, fallback, srcTex.WrapS, srcTex.WrapT, srcTex.MinFilter, srcTex.MagFilter);

            srcTex.TryCopyNameAndExtrasTo(dstTex);

            var srcXform = srcTex.Transform;

            if (srcXform != null)
            {
                dstChannel.SetTransform(srcXform.Offset, srcXform.Scale, srcXform.Rotation, srcXform.CoordinateSetOverride);
            }
        }
Example #3
0
        public static void CopyTo(this MaterialChannel srcChannel, ChannelBuilder dstChannel)
        {
            Guard.NotNull(srcChannel, nameof(srcChannel));
            Guard.NotNull(dstChannel, nameof(dstChannel));

            foreach (var srcProp in srcChannel.Parameters)
            {
                dstChannel.Parameters[srcProp.Name] = MaterialValue.CreateFrom(srcProp.Value);
            }

            if (srcChannel.Texture == null)
            {
                return;
            }
            if (dstChannel.Texture == null)
            {
                dstChannel.UseTexture();
            }

            dstChannel.Texture.SetNameAndExtrasFrom(srcChannel.Texture);

            dstChannel.Texture.CoordinateSet = srcChannel.TextureCoordinate;

            if (srcChannel.TextureSampler != null)
            {
                dstChannel.Texture.MinFilter = srcChannel.TextureSampler.MinFilter;
                dstChannel.Texture.MagFilter = srcChannel.TextureSampler.MagFilter;
                dstChannel.Texture.WrapS     = srcChannel.TextureSampler.WrapS;
                dstChannel.Texture.WrapT     = srcChannel.TextureSampler.WrapT;
            }

            var srcXform = srcChannel.TextureTransform;

            if (srcXform != null)
            {
                dstChannel.Texture.WithTransform(srcXform.Offset, srcXform.Scale, srcXform.Rotation, srcXform.TextureCoordinateOverride);
            }

            ImageBuilder _convert(Image src)
            {
                if (src == null)
                {
                    return(null);
                }
                return(ImageBuilder.From(src.Content, src.Name, src.Extras.DeepClone()));
            }

            dstChannel.Texture.PrimaryImage  = _convert(srcChannel.Texture.PrimaryImage);
            dstChannel.Texture.FallbackImage = _convert(srcChannel.Texture.FallbackImage);
        }
Example #4
0
 public bool Equals(MaterialChannel other)
 {
     if (this._Material == null && other._Material == null)
     {
         return(true);
     }
     if (this._Material != other._Material)
     {
         return(false);
     }
     if (this._Key != other._Key)
     {
         return(false);
     }
     return(true);
 }
Example #5
0
        public static void CopyTo(this Materials.ChannelBuilder srcChannel, MaterialChannel dstChannel)
        {
            Guard.NotNull(srcChannel, nameof(srcChannel));
            Guard.NotNull(dstChannel, nameof(dstChannel));

            dstChannel.Parameter = srcChannel.Parameter;

            var srcTex = srcChannel.Texture;

            if (srcTex == null)
            {
                return;
            }

            Image primary  = null;
            Image fallback = null;

            if (srcTex.PrimaryImage.IsValid)
            {
                primary = dstChannel
                          .LogicalParent
                          .LogicalParent
                          .UseImageWithContent(srcTex.PrimaryImage.GetBuffer().ToArray());
            }

            if (srcTex.FallbackImage.IsValid)
            {
                fallback = dstChannel
                           .LogicalParent
                           .LogicalParent
                           .UseImageWithContent(srcTex.FallbackImage.GetBuffer().ToArray());
            }

            dstChannel.SetTexture(srcTex.CoordinateSet, primary, fallback, srcTex.WrapS, srcTex.WrapT, srcTex.MinFilter, srcTex.MagFilter);

            var srcXform = srcTex.Transform;

            if (srcXform != null)
            {
                dstChannel.SetTransform(srcXform.Offset, srcXform.Scale, srcXform.Rotation, srcXform.CoordinateSetOverride);
            }
        }
Example #6
0
        public static void CopyTo(this Materials.ChannelBuilder srcChannel, MaterialChannel dstChannel)
        {
            Guard.NotNull(srcChannel, nameof(srcChannel));
            Guard.NotNull(dstChannel, nameof(dstChannel));

            dstChannel.Parameter = srcChannel.Parameter;

            var srcTex = srcChannel.Texture;

            if (srcTex == null)
            {
                return;
            }

            var image = dstChannel.LogicalParent.LogicalParent.UseImageWithContent(srcTex.ImageContent.ToArray());

            dstChannel.SetTexture(srcTex.CoordinateSet, image, srcTex.MinFilter, srcTex.MagFilter, srcTex.WrapS, srcTex.WrapT);

            // dstChannel.SetTransform(srcTex.CoordinateSet, srcTex.Offset, srcTex.Scale, srcTex.Rotation);
        }
Example #7
0
        public static void CopyTo(this MaterialChannel srcChannel, Materials.ChannelBuilder dstChannel)
        {
            Guard.NotNull(srcChannel, nameof(srcChannel));
            Guard.NotNull(dstChannel, nameof(dstChannel));

            dstChannel.Parameter = srcChannel.Parameter;

            if (srcChannel.Texture == null)
            {
                return;
            }

            if (dstChannel.Texture == null)
            {
                dstChannel.UseTexture();
            }

            dstChannel.Texture.CoordinateSet = srcChannel.TextureCoordinate;

            if (srcChannel.TextureSampler != null)
            {
                dstChannel.Texture.MinFilter = srcChannel.TextureSampler.MinFilter;
                dstChannel.Texture.MagFilter = srcChannel.TextureSampler.MagFilter;
                dstChannel.Texture.WrapS     = srcChannel.TextureSampler.WrapS;
                dstChannel.Texture.WrapT     = srcChannel.TextureSampler.WrapT;
            }

            var srcXform = srcChannel.TextureTransform;

            if (srcXform != null)
            {
                dstChannel.Texture.WithTransform(srcXform.Offset, srcXform.Scale, srcXform.Rotation, srcXform.TextureCoordinateOverride);
            }

            dstChannel.Texture.PrimaryImageContent = srcChannel.Texture.PrimaryImage.GetImageContent();

            if (srcChannel.Texture.FallbackImage != null)
            {
                dstChannel.Texture.FallbackImageContent = srcChannel.Texture.FallbackImage.GetImageContent();
            }
        }