{
  "Name": "LoadImage",
  "_id": "384b6557-a535-4766-bce2-6c8c1e6fcf14",
  "Namespace": "lib.image.load",
  "Description": "Loads an image file. Click on [...] to select a file.\r\n\r\nWe support most file-types. Use the two additional outputs for Width and Height. \r\n\r\nUse a combination like this to use Image as texture:\r\n\r\n[SetTexture           ]\r\n[Rectange] [Image]\r\n",
  "Inputs": [
    {
      "Name": "ImagePath",
      "MetaInstanceID": "2ddcf044-4709-4e79-b466-0780b0c1e1e4",
      "DefaultValue": {
        "Type": "Text",
        "Value": "assets-common/image/chipmunk.jpg"
      },
      "MetaID": "c522a66e-3260-4692-b3e3-79fd0361fa3d",
      "IsMultiInput": "False",
      "Relevance": "Relevant",
      "Description": "",
      "Min": "-100000",
      "Max": "100000",
      "Scale": "1",
      "ScaleType": "Linear",
      "EnumValues": []
    }
  ],
  "Outputs": [
    {
      "Name": "Image",
      "MetaInstanceID": "fad40dfa-a94e-4c07-a008-3d6d59f5438a",
      "MetaID": "9848060d-fd84-45b0-b658-d0d531c61dab"
    },
    {
      "Name": "Size.X",
      "MetaInstanceID": "2998c0f8-d12b-46b2-9d36-c6a139a67c84",
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506"
    },
    {
      "Name": "Size.Y",
      "MetaInstanceID": "d138566f-37dd-4127-9737-680d5e17d05e",
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506"
    }
  ],
  "OperatorParts": [
    {
      "MetaInstanceID": "0c0af9c2-4a01-4e53-b753-46f919b52d32",
      "MetaID": "0948afa7-a2c6-4724-905d-187d73805eef",
      "Name": "LoadImageFunc",
      "Version": "0d2f4ea2-32d5-4056-adfb-30eaaa2d20ba",
      "Type": "Float",
      "IsMultiInput": "True",
      "Script": [
        "//>>> _using",
        "using System;",
        "using System.Collections.Generic;",
        "using System.Linq;",
        "using System.Text;",
        "using SharpDX;",
        "using SharpDX.Direct3D11;",
        "using SharpDX.Windows;",
        "//<<< _using",
        "using System.IO;",
        "",
        "namespace Framefield.Core.ID0948afa7_a2c6_4724_905d_187d73805eef",
        "{",
        "    public class Class_LoadImage : OperatorPart.Function",
        "    {",
        "        //>>> _inputids",
        "        private enum InputId",
        "        {",
        "            ImagePath = 0",
        "        }",
        "        //<<< _inputids",
        "",
        "        //>>> _outputids",
        "        private enum OutputId",
        "        {",
        "            Image = 0,",
        "            SizeX = 1,",
        "            SizeY = 2",
        "        }",
        "        //<<< _outputids",
        "",
        "        public override void Dispose() {",
        "            Utilities.DisposeObj(ref _imageResource);",
        "            Utilities.DisposeObj(ref _depthImageResource);",
        "        }",
        "",
        "        public override OperatorPartContext Eval(OperatorPartContext context, List<OperatorPart> inputs, int outputIdx) ",
        "        {",
        "            //>>> _params",
        "            var ImagePath = inputs[(int)InputId.ImagePath].Eval(context).Text;",
        "            //<<< _params",
        "",
        "            if (ImagePath == _lastImage)",
        "                Changed = false;",
        "",
        "            _lastImage = ImagePath;",
        "",
        "            if (Changed)",
        "            {",
        "                Dispose();",
        "                if (File.Exists(ImagePath))",
        "                {",
        "                    _imageResource = ResourceManager.ReadImage(ImagePath);",
        "                    _size = new Vector2(_imageResource.Image.Description.Width, _imageResource.Image.Description.Height); ",
        "                }",
        "                else",
        "                {",
        "                    Logger.Error(this,\"Imagefile not found '{0}'\", ImagePath);",
        "                }",
        "",
        "                //somehow this will cause an exception",
        "                //FileInfo fi = new FileInfo(ImagePath);",
        "                //var depthFilename = fi.DirectoryName + \"\\\\\" + Path.GetFileNameWithoutExtension(fi.Name) + \"_depth.dds\";",
        "                //Logger.Error(this,\"'{0}'\", depthFilename);",
        "                //if (File.Exists(depthFilename))",
        "                //{",
        "                //    _depthImageResource = ResourceManager.ReadImage(depthFilename);",
        "                //}",
        "                Changed = false;",
        "            }",
        "",
        "            if (_imageResource != null)",
        "            {",
        "                switch ((OutputId)outputIdx)",
        "                {",
        "                    case OutputId.Image:",
        "                        context.Image = _imageResource.Image;",
        "                        if (_depthImageResource != null) {",
        "                            //context.BlendState = OperatorPartContext.DefaultRenderer.DisabledBlendState;",
        "                            context.DepthImage = _depthImageResource.Image;",
        "                        }",
        "                        break;",
        "                    case OutputId.SizeX:",
        "                        context.Value = _size.X;",
        "                        break;",
        "                    case OutputId.SizeY:",
        "                        context.Value = _size.Y;",
        "                        break;",
        "                }",
        "            }",
        "            else",
        "            {",
        "                switch (outputIdx)",
        "                {",
        "                    case (int)OutputId.Image:",
        "                        context.Image = null;",
        "                        context.DepthImage = null;",
        "                        break;",
        "                    case (int)OutputId.SizeX:",
        "                        context.Value = 0;",
        "                        break;",
        "                    case (int)OutputId.SizeY:",
        "                        context.Value = 0;",
        "                        break;",
        "                }",
        "            }",
        "",
        "            return context;",
        "        }",
        "",
        "        ImageResource _imageResource;",
        "        ImageResource _depthImageResource;",
        "        Vector2 _size;",
        "        String _lastImage = String.Empty;",
        "    }",
        "}",
        "",
        ""
      ],
      "AdditionalAssemblies": []
    }
  ],
  "Operators": [],
  "Connections": [
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "0c0af9c2-4a01-4e53-b753-46f919b52d32",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "fad40dfa-a94e-4c07-a008-3d6d59f5438a"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "2ddcf044-4709-4e79-b466-0780b0c1e1e4",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "0c0af9c2-4a01-4e53-b753-46f919b52d32"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "0c0af9c2-4a01-4e53-b753-46f919b52d32",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "2998c0f8-d12b-46b2-9d36-c6a139a67c84"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "0c0af9c2-4a01-4e53-b753-46f919b52d32",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "d138566f-37dd-4127-9737-680d5e17d05e"
    }
  ]
}