Exemple #1
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);
        }
        public static void CopyTo(this MaterialChannel srcChannel, 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.PrimaryImage  = srcChannel.Texture.PrimaryImage?.Content ?? Memory.MemoryImage.Empty;
            dstChannel.Texture.FallbackImage = srcChannel.Texture.FallbackImage?.Content ?? Memory.MemoryImage.Empty;
        }