{
  "Name": "Replicate",
  "_id": "a6ad4fc4-172a-4e64-881c-c1782829c605",
  "Namespace": "lib.3d.modify",
  "Description": "Instanciates the incoming geometry ",
  "Inputs": [
    {
      "Name": "SceneInput",
      "MetaInstanceID": "ee8bce1e-80db-404b-8c3a-a09db8e25edc",
      "DefaultValue": {
        "Type": "Scene",
        "Value": "Framefield.Core.Scene"
      },
      "MetaID": "79122951-7bc4-4c68-b085-866eab828248",
      "IsMultiInput": "True",
      "Relevance": "Required",
      "Description": "",
      "Min": "-100000",
      "Max": "100000",
      "Scale": "1",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "Count",
      "MetaInstanceID": "38b8d0e0-db39-4c69-8919-3f84b9389076",
      "DefaultValue": {
        "Type": "Float",
        "Value": "50"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "0",
      "Max": "100000",
      "Scale": "1",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "Radius",
      "MetaInstanceID": "b8acce2c-dc07-4886-b02d-20461d8bed2b",
      "DefaultValue": {
        "Type": "Float",
        "Value": "3"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "-100000",
      "Max": "100000",
      "Scale": "0.1",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "Stretch.X",
      "MetaInstanceID": "04f1d2a3-3db0-45aa-895b-cdd6a398b8a2",
      "DefaultValue": {
        "Type": "Float",
        "Value": "1"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "-10000",
      "Max": "10000",
      "Scale": "0.1",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "Stretch.Y",
      "MetaInstanceID": "bf9a5d22-dc4d-4d89-ba26-0dc4f12b40a4",
      "DefaultValue": {
        "Type": "Float",
        "Value": "1"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "-10000",
      "Max": "10000",
      "Scale": "0.1",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "Stretch.Z",
      "MetaInstanceID": "17856a47-a5f2-4253-8550-5057328ee385",
      "DefaultValue": {
        "Type": "Float",
        "Value": "1"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "-10000",
      "Max": "10000",
      "Scale": "0.1",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "Shape",
      "MetaInstanceID": "94240fd4-bdf9-4924-a5b1-72cf22cb5366",
      "DefaultValue": {
        "Type": "Float",
        "Value": "0"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "-100000",
      "Max": "100000",
      "Scale": "0.1",
      "ScaleType": "Linear",
      "EnumValues": [
        {
          "Name": "Point",
          "Value": "0"
        },
        {
          "Name": "Sphere",
          "Value": "1"
        },
        {
          "Name": "Ring",
          "Value": "2"
        },
        {
          "Name": "Box",
          "Value": "3"
        }
      ]
    },
    {
      "Name": "Layer.X",
      "MetaInstanceID": "fa1ef39a-f0aa-4e8b-8621-3c4c7e210c5a",
      "DefaultValue": {
        "Type": "Float",
        "Value": "1"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "-10000",
      "Max": "10000",
      "Scale": "0.1",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "Layer.Y",
      "MetaInstanceID": "26e649d0-0fe5-40b6-b312-9ac579c8d3a6",
      "DefaultValue": {
        "Type": "Float",
        "Value": "1"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "-10000",
      "Max": "10000",
      "Scale": "0.1",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "Scatter",
      "MetaInstanceID": "5cb64123-dfc6-4029-aafb-57d4297cac33",
      "DefaultValue": {
        "Type": "Float",
        "Value": "0"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "0",
      "Max": "100000",
      "Scale": "0.1",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "Offset.X",
      "MetaInstanceID": "d6849876-0bbc-4722-9b31-159e409ad9eb",
      "DefaultValue": {
        "Type": "Float",
        "Value": "0"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "-10000",
      "Max": "10000",
      "Scale": "0.1",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "Offset.Y",
      "MetaInstanceID": "3cc26782-1e05-4a04-8c75-677f994a465a",
      "DefaultValue": {
        "Type": "Float",
        "Value": "0"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "-10000",
      "Max": "10000",
      "Scale": "0.1",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "Offset.Z",
      "MetaInstanceID": "4f223027-698c-492e-87f7-319417ab2371",
      "DefaultValue": {
        "Type": "Float",
        "Value": "0"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "-10000",
      "Max": "10000",
      "Scale": "0.1",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "OffsetRandom.X",
      "MetaInstanceID": "fa1944ca-6a42-4cd7-83ee-c9b43b52eb45",
      "DefaultValue": {
        "Type": "Float",
        "Value": "0"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "-10000",
      "Max": "10000",
      "Scale": "0.1",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "OffsetRandom.Y",
      "MetaInstanceID": "2c61758f-cb2e-4c40-a52f-9b08d95f5c15",
      "DefaultValue": {
        "Type": "Float",
        "Value": "0"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "-10000",
      "Max": "10000",
      "Scale": "0.1",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "OffsetRandom.Z",
      "MetaInstanceID": "701020d6-b3ae-4c41-a136-18b06d98f4b8",
      "DefaultValue": {
        "Type": "Float",
        "Value": "0"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "-10000",
      "Max": "10000",
      "Scale": "0.1",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "NoiseTime",
      "MetaInstanceID": "65324148-b778-4d5a-b6f9-34c51023cfd3",
      "DefaultValue": {
        "Type": "Float",
        "Value": "0"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "-100000",
      "Max": "100000",
      "Scale": "0.1",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "NoiseAmount",
      "MetaInstanceID": "38e5156f-e441-4c01-b3eb-645255752b17",
      "DefaultValue": {
        "Type": "Float",
        "Value": "0"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "-100000",
      "Max": "100000",
      "Scale": "0.1",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "NoiseScale",
      "MetaInstanceID": "11d78574-8efa-4dc7-a61a-dca5d62be8d4",
      "DefaultValue": {
        "Type": "Float",
        "Value": "1"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "-100000",
      "Max": "100000",
      "Scale": "0.1",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "Size",
      "MetaInstanceID": "ffd57221-3c5c-4e7b-a535-65ea6181ad42",
      "DefaultValue": {
        "Type": "Float",
        "Value": "1"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "-100000",
      "Max": "100000",
      "Scale": "0.01",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "SizeRandom",
      "MetaInstanceID": "57e11aa3-392c-4761-8ea7-a3a4375d6e65",
      "DefaultValue": {
        "Type": "Float",
        "Value": "0"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "-100000",
      "Max": "100000",
      "Scale": "0.1",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "Orientation",
      "MetaInstanceID": "e1c807f6-4a8e-47d1-a8ba-9ad89c020946",
      "DefaultValue": {
        "Type": "Float",
        "Value": "0"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "-100000",
      "Max": "100000",
      "Scale": "0.1",
      "ScaleType": "Linear",
      "EnumValues": [
        {
          "Name": "Surface",
          "Value": "0"
        },
        {
          "Name": "Fixed",
          "Value": "1"
        },
        {
          "Name": "FaceCamera",
          "Value": "2"
        }
      ]
    },
    {
      "Name": "Rotate.X",
      "MetaInstanceID": "9c2bb5db-4332-4da8-943d-205e4ffa9a39",
      "DefaultValue": {
        "Type": "Float",
        "Value": "0"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "-10000",
      "Max": "10000",
      "Scale": "1",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "Rotate.Y",
      "MetaInstanceID": "02efebba-f6f2-4869-93c7-d021ef0c69e9",
      "DefaultValue": {
        "Type": "Float",
        "Value": "0"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "-10000",
      "Max": "10000",
      "Scale": "1",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "Rotate.Z",
      "MetaInstanceID": "bc63710e-28fa-4288-b429-77bf68d1437a",
      "DefaultValue": {
        "Type": "Float",
        "Value": "0"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "-10000",
      "Max": "10000",
      "Scale": "1",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "RotateRandom.X",
      "MetaInstanceID": "8769e9c4-540e-41d5-b822-82bca4807c20",
      "DefaultValue": {
        "Type": "Float",
        "Value": "0"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "-10000",
      "Max": "10000",
      "Scale": "1",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "RotateRandom.Y",
      "MetaInstanceID": "f801beae-f599-4610-b379-fe43ebfcbe4a",
      "DefaultValue": {
        "Type": "Float",
        "Value": "0"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "-10000",
      "Max": "10000",
      "Scale": "1",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "RotateRandom.Z",
      "MetaInstanceID": "9d52f731-30b2-4252-b804-c9af7c08d3ce",
      "DefaultValue": {
        "Type": "Float",
        "Value": "0"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "-10000",
      "Max": "10000",
      "Scale": "1",
      "ScaleType": "Linear",
      "EnumValues": []
    },
    {
      "Name": "Seed",
      "MetaInstanceID": "64847bf4-bde0-45f0-b71b-5f8126bee97e",
      "DefaultValue": {
        "Type": "Float",
        "Value": "0"
      },
      "MetaID": "3f76dee3-3897-44ac-82d6-25ce9f53a506",
      "IsMultiInput": "False",
      "Relevance": "Optional",
      "Description": "",
      "Min": "0",
      "Max": "100000",
      "Scale": "1",
      "ScaleType": "Linear",
      "EnumValues": []
    }
  ],
  "Outputs": [
    {
      "Name": "SceneTransformOut",
      "MetaInstanceID": "13eff2ca-59c8-4a7b-a636-a4cc54535242",
      "MetaID": "79122951-7bc4-4c68-b085-866eab828248"
    }
  ],
  "OperatorParts": [
    {
      "MetaInstanceID": "2249740b-6d72-4bc8-b178-8c494483b48d",
      "MetaID": "da3fbf4a-e0f6-44d0-9a6a-8f5eb319fedb",
      "Name": "ReplicateFunc",
      "Version": "bd871682-3f11-489d-a270-be5b44bca5de",
      "Type": "Scene",
      "IsMultiInput": "True",
      "Script": [
        "using System;",
        "using System.Collections.Generic;",
        "using SharpDX;",
        "",
        "namespace Framefield.Core.IDda3fbf4a_e0f6_44d0_9a6a_8f5eb319fedb",
        "{",
        "    public class Class_Replicate : OperatorPart.Function",
        "    {",
        "        //>>> _inputids",
        "        private enum InputId",
        "        {",
        "            SceneInput = 0,",
        "            Count = 1,",
        "            Radius = 2,",
        "            StretchX = 3,",
        "            StretchY = 4,",
        "            StretchZ = 5,",
        "            Shape = 6,",
        "            LayerX = 7,",
        "            LayerY = 8,",
        "            Scatter = 9,",
        "            OffsetX = 10,",
        "            OffsetY = 11,",
        "            OffsetZ = 12,",
        "            OffsetRandomX = 13,",
        "            OffsetRandomY = 14,",
        "            OffsetRandomZ = 15,",
        "            NoiseTime = 16,",
        "            NoiseAmount = 17,",
        "            NoiseScale = 18,",
        "            Size = 19,",
        "            SizeRandom = 20,",
        "            Orientation = 21,",
        "            RotateX = 22,",
        "            RotateY = 23,",
        "            RotateZ = 24,",
        "            RotateRandomX = 25,",
        "            RotateRandomY = 26,",
        "            RotateRandomZ = 27,",
        "            Seed = 28",
        "        }",
        "        //<<< _inputids",
        "        public override OperatorPartContext Eval(OperatorPartContext context, List<OperatorPart> inputs, int outputIdx)",
        "        {",
        "            //>>> _params",
        "            var SceneInput = inputs[(int)InputId.SceneInput];",
        "            var Count = inputs[(int)InputId.Count].Eval(context).Value;",
        "            var Radius = inputs[(int)InputId.Radius].Eval(context).Value;",
        "            var StretchX = inputs[(int)InputId.StretchX].Eval(context).Value;",
        "            var StretchY = inputs[(int)InputId.StretchY].Eval(context).Value;",
        "            var StretchZ = inputs[(int)InputId.StretchZ].Eval(context).Value;",
        "            var Stretch = new Vector3(StretchX, StretchY, StretchZ);",
        "            var Shape = (int) inputs[(int)InputId.Shape].Eval(context).Value;",
        "            var LayerX = inputs[(int)InputId.LayerX].Eval(context).Value;",
        "            var LayerY = inputs[(int)InputId.LayerY].Eval(context).Value;",
        "            var Layer = new Vector2(LayerX, LayerY);",
        "            var Scatter = inputs[(int)InputId.Scatter].Eval(context).Value;",
        "            var OffsetX = inputs[(int)InputId.OffsetX].Eval(context).Value;",
        "            var OffsetY = inputs[(int)InputId.OffsetY].Eval(context).Value;",
        "            var OffsetZ = inputs[(int)InputId.OffsetZ].Eval(context).Value;",
        "            var Offset = new Vector3(OffsetX, OffsetY, OffsetZ);",
        "            var OffsetRandomX = inputs[(int)InputId.OffsetRandomX].Eval(context).Value;",
        "            var OffsetRandomY = inputs[(int)InputId.OffsetRandomY].Eval(context).Value;",
        "            var OffsetRandomZ = inputs[(int)InputId.OffsetRandomZ].Eval(context).Value;",
        "            var OffsetRandom = new Vector3(OffsetRandomX, OffsetRandomY, OffsetRandomZ);",
        "            var NoiseTime = inputs[(int)InputId.NoiseTime].Eval(context).Value;",
        "            var NoiseAmount = inputs[(int)InputId.NoiseAmount].Eval(context).Value;",
        "            var NoiseScale = inputs[(int)InputId.NoiseScale].Eval(context).Value;",
        "            var Size = inputs[(int)InputId.Size].Eval(context).Value;",
        "            var SizeRandom = inputs[(int)InputId.SizeRandom].Eval(context).Value;",
        "            var Orientation = (int) inputs[(int)InputId.Orientation].Eval(context).Value;",
        "            var RotateX = inputs[(int)InputId.RotateX].Eval(context).Value;",
        "            var RotateY = inputs[(int)InputId.RotateY].Eval(context).Value;",
        "            var RotateZ = inputs[(int)InputId.RotateZ].Eval(context).Value;",
        "            var Rotate = new Vector3(RotateX, RotateY, RotateZ);",
        "            var RotateRandomX = inputs[(int)InputId.RotateRandomX].Eval(context).Value;",
        "            var RotateRandomY = inputs[(int)InputId.RotateRandomY].Eval(context).Value;",
        "            var RotateRandomZ = inputs[(int)InputId.RotateRandomZ].Eval(context).Value;",
        "            var RotateRandom = new Vector3(RotateRandomX, RotateRandomY, RotateRandomZ);",
        "            var Seed = inputs[(int)InputId.Seed].Eval(context).Value;",
        "            //<<< _params        ",
        "",
        "            if (SceneInput.Connections.Count == 0)",
        "            {",
        "                return context;",
        "            }",
        "",
        "            const float toRad = (float) Math.PI/180f;",
        "",
        "            var prevTransform = context.ObjectTWorld;",
        "            var rand = new Random((int) Seed);",
        "            Layer.X = Math.Max(1, (int) Layer.X);",
        "            Layer.Y = Math.Max(1, (int) Layer.Y);",
        "",
        "            for (var i = 0; i < Count; ++i)",
        "            {",
        "                    Vector3 t = new Vector3();",
        "",
        "                    ",
        "                    switch (Shape)",
        "                    {",
        "                        // Point",
        "                        case 0:",
        "                            t = Vector3.Normalize(new Vector3(",
        "                                            (float) (rand.NextDouble() - 0.5)*Radius*StretchX,",
        "                                            (float) (rand.NextDouble() - 0.5)*Radius*StretchY,",
        "                                            (float) (rand.NextDouble() - 0.5)*Radius*StretchZ)) ",
        "                               * (float)rand.NextDouble() * Radius;",
        "                                      ",
        "                            break;",
        "                        // Sphere",
        "                        case 1:",
        "                        {",
        "                            var inc = Math.PI*(3 - Math.Sqrt(5));",
        "                            var off = 2/(Count + 1);",
        "                            //var y = i*off*Stretch.Y + Stretch.Z - 1 + (off/2);",
        "                            var y = i*off*Stretch.Y - 1 + (off/2);",
        "                            var r = Math.Sqrt(1 - y*y);",
        "                            var phi = i*Stretch.X*inc;",
        "                            t = new Vector3((float) (Math.Cos(phi)*r*Radius),",
        "                                            (float) (y*Radius),",
        "                                            (float) (Math.Sin(phi)*r*Radius));",
        "                            break;",
        "                        }",
        "                        // Ring",
        "                        case 2:",
        "                        {",
        "                            float itemsPerShell =  Count/(Layer.X);    // with even distribution                            ",
        "                            float indexInShell = i%itemsPerShell;",
        "                            float shellIndex = (i-indexInShell)/itemsPerShell;",
        "                            ",
        "                            float itemsPerRing = (itemsPerShell / Math.Max(1,Layer.Y));",
        "                            float indexInRing = (int)(indexInShell % itemsPerRing);",
        "                            float layerIndex = (int)(indexInShell / itemsPerRing);",
        "                          ",
        "                            float a = indexInRing / itemsPerRing;",
        "                            ",
        "                            t = new Vector3((float) (Math.Sin(Math.PI*2*a)*(Radius + shellIndex * Stretch.X)),",
        "                                            Layer.Y <= 1 ? 0",
        "                                                         : (layerIndex/(Layer.Y-1)  -0.5f) *Stretch.Y ,",
        "                                            (float) (Math.Cos(Math.PI*2*a)*(Radius + shellIndex*Stretch.Z)));",
        "                            break;",
        "                        }",
        "                        // Box (can also be used as a plane)",
        "                        case 3:",
        "                        {                            ",
        "                            var volume = Math.Abs(StretchX) * Math.Abs(StretchY) * Math.Abs(StretchZ);                            ",
        "                            var s1= new Vector3(Math.Abs(StretchX), Math.Abs(StretchY), Math.Abs(StretchZ));",
        "                            ",
        "                            /*",
        "                           var volumePerUnit = volume/Count;",
        "                           ",
        "                           ",
        "                           ",
        "                           ",
        "                           var gridResolution = new Vector3 ((float)Math.Ceiling(gridResolution.X),(float)Math.Ceiling(gridResolution.Y),(float)Math.Ceiling(gridResolution.Z));",
        "                           ",
        "                           ",
        "                           var numGridCells = gridResolution.X*gridResolution.Y*gridResolution.Z;",
        "                           ",
        "            ",
        "                           ",
        "                           var gridCoords = new Vector3(i % gridResolution.X,",
        "                                        (float)Math.Floor(i/gridResolution.X) % gridResolution.Y,",
        "                                        (float)Math.Floor(i / (gridResolution.X * gridResolution.Y)) % gridResolution.Z);",
        "                           ",
        "                           ",
        "                           ",
        "                           var gridCellSize = new Vector3((float)(s1.X/gridResolution.X), (float)(s1.Y/gridResolution.Y), (float)(s1.Z/gridResolution.Z));",
        "                    ",
        "                           ",
        "                           t = 0.5f*gridCellSize + gridCellSize*gridCoords - 0.5f*Stretch;",
        "                           */",
        "                            ",
        "                            ",
        "                            s1.Normalize();",
        "                            var a= s1.Y/s1.X;",
        "                            var b= s1.Z/s1.X;",
        "                            ",
        "                            var xx = (float)Math.Pow( 1/ (a*b), 1.0/3.0);",
        "                            var s2 = s1 * (xx/s1.X);",
        "",
        "                            var edgeCount= Math.Pow(Count,1.0/3.0);",
        "",
        "                            var itemsX= Math.Max(1, edgeCount * s2.X);",
        "                            var itemsY= Math.Max(1, edgeCount * s2.Y);",
        "                            var itemsZ= Math.Max(1, edgeCount * s2.Z);",
        "                            //var itemsX= Math.Max(1, Math.Floor(edgeCount * s2.X));",
        "                            //var itemsY= Math.Max(1, Math.Floor(edgeCount * s2.Y));",
        "                            //var itemsZ= Math.Max(1, Math.Floor(edgeCount * s2.Z));",
        "                            ",
        "                            var x = (int)(i % itemsX)          / itemsX;",
        "                            var y = (int)((i/itemsX) % itemsY) / itemsY;",
        "                            var z = (int)((i/itemsX/itemsY))   / itemsZ;",
        "                            ",
        "                            ",
        "                            t = new Vector3((float) (x),",
        "                                            (float) (y),",
        "                                            (float) (z)) * Stretch - 0.5f * Stretch;",
        "                            ",
        "                            break;",
        "                        }",
        "                    }",
        "",
        "/*                    if (NoiseAmount != 0)",
        "                    {",
        "                        _noiseTime = NoiseTime;",
        "                        _frequency = 1/NoiseScale;",
        "                        var noiseOffset = new Vector3(",
        "                            getNoise(t.X / Radius - 36.1f), ",
        "                            getNoise(t.Y / Radius + 1.0f), ",
        "                            getNoise((t.Z + 12.1f))",
        "                        );",
        "                        t += noiseOffset * NoiseAmount;",
        "                    }*/",
        "",
        "",
        "                    if (NoiseAmount != 0)",
        "                    {",
        "                        _noiseTime = NoiseTime;",
        "                        _frequency = 1/NoiseScale;",
        "                        var noiseOffset = new Vector3(getNoise(t.X / Radius - 6.3f), getNoise(t.Z / Radius + 9.3f), getNoise((t.Y - 0.3f)));",
        "                        t += noiseOffset * NoiseAmount;",
        "                    }",
        "",
        "                    float s = Size + (float)rand.NextDouble() * SizeRandom;",
        "                    var scale = new Vector3(s, s, s);",
        "                    ",
        "                    //Matrix rotation;",
        "                    Matrix transform;",
        "                    Matrix.RotationYawPitchRoll(Rotate.Y * toRad + (float)(rand.NextDouble()) * RotateRandom.Y * toRad,",
        "                                                Rotate.X * toRad + (float)(rand.NextDouble()) * RotateRandom.X * toRad,",
        "                                                Rotate.Z * toRad + (float)(rand.NextDouble()) * RotateRandom.Z * toRad,",
        "                                                out transform);",
        "                    ",
        "                                                                    ",
        "                    var tScale = Matrix.Scaling( scale.X, scale.Y, scale.Z);",
        "                    transform= tScale * transform;",
        "                    var t2= Matrix.Translation(new Vector3(OffsetX + (float)(rand.NextDouble() -0.5f) * (OffsetRandomX + Scatter),",
        "                                                           OffsetY + (float)(rand.NextDouble() -0.5f) * (OffsetRandomY + Scatter),",
        "                                                           OffsetZ + (float)(rand.NextDouble() -0.5f) * (OffsetRandomZ + Scatter)));",
        "                    transform = t2*transform;",
        "",
        "                    if (Orientation == 0)",
        "                    {",
        "                        if (t.Length() > 0)",
        "                        {",
        "                            var dir = -t;",
        "                            dir.Normalize();",
        "                            var helperDir = new Vector3(0, -1, 0);",
        "                            if (Math.Abs(dir.X) < 0.001 && Math.Abs(dir.Z) < 0.001)",
        "                                helperDir = new Vector3(0, 0, 1);",
        "                            var xAxis = Vector3.Cross(dir, helperDir);",
        "                            xAxis.Normalize();",
        "                            var yAxis = Vector3.Cross(-xAxis, dir);",
        "                            yAxis.Normalize();",
        "                            var m = Matrix.Identity;",
        "                            m.Row1 = new Vector4(xAxis, 0);",
        "                            m.Row2 = new Vector4(yAxis, 0);",
        "                            m.Row3 = new Vector4(dir, 0);",
        "                            transform *= m;",
        "                        }",
        "                    }",
        "                    else if (Orientation == 2)",
        "                    {",
        "                        //if (Shape == 2)",
        "                        //{",
        "                        //    var rotationAroundCenter = Matrix.Identity;",
        "                        //    Matrix.RotationY((float)(2 * Math.PI * i / Count), out rotationAroundCenter);",
        "                        //    transform *= rotationAroundCenter;",
        "                        //}",
        "                        var cameraToWorld = context.WorldToCamera;",
        "                        cameraToWorld.Invert();",
        "                        var newObjectToWorld = context.ObjectTWorld * cameraToWorld;",
        "                        newObjectToWorld.Row4 = context.ObjectTWorld.Row4;",
        "                        transform *=    newObjectToWorld;                     ",
        "                        ",
        "                    }",
        "",
        "                    transform *= Matrix.Transformation(new Vector3(), new Quaternion(), new Vector3(1,1,1), new Vector3(), new Quaternion(), t);",
        "                    ",
        "                    ",
        "                    transform *= prevTransform; ",
        "                context.ObjectTWorld = transform*prevTransform;",
        "                SceneInput.Connections[i%SceneInput.Connections.Count].Eval(context);",
        "                context.ObjectTWorld = prevTransform;",
        "                ",
        "                //SceneInput.Connections[i%SceneInput.Connections.Count].Eval(context);",
        "                //context.ObjectTWorld = prevTransform;",
        "            }",
        "",
        "            context.ObjectTWorld = prevTransform;",
        "",
        "            return context;",
        "        }",
        "",
        "        #region helpers",
        "",
        "        public float Noise(int x, int seed)",
        "        {",
        "            int n = x + seed;",
        "            n = (n << 13) ^ n;",
        "            return (float) (1.0 - ((n*(n*n*15731 + 789221) + 1376312589) & 0x7fffffff)/1073741824.0);",
        "        }",
        "",
        "        public float Lerp(float a, float b, float t)",
        "        {",
        "            return a + t*(b - a);",
        "        }",
        "",
        "        public float Fade(float t)",
        "        {",
        "            return t*t*t*(t*(t*6 - 15) + 10);",
        "        }",
        "",
        "        public float Interpolate(float a, float b, float t)",
        "        {",
        "            float ft = t*3.1415927f;",
        "            float f = (float) (1.0 - Math.Cos(ft))*0.5f;",
        "            return a*(1.0f - f) + b*f;",
        "        }",
        "",
        "        private float getNoise(float value)",
        "        {",
        "            float noiseSum = 0.0f;",
        "            value *= _frequency;",
        "            value += _noiseTime+10000;  // Noise is not static between -0.0001 and 0.0001",
        "",
        "",
        "            noiseSum = Lerp(Noise((int) value, _seed),",
        "                            Noise((int) value + 1, _seed),",
        "                            Fade(value - (float) Math.Floor(value)));",
        "            //Logger.Info(\"{0:0.000} -> {1:0.00}\", value, noiseSum);                            ",
        "            return noiseSum;",
        "        }",
        "        ",
        "        //private Vector getNoise3(float value)",
        "        //{",
        "        //}        ",
        "",
        "        #endregion",
        "",
        "        private int _seed = 0;",
        "        private float _frequency = 1;",
        "        private float _noiseTime;",
        "    }",
        "}",
        "",
        ""
      ],
      "AdditionalAssemblies": []
    }
  ],
  "Operators": [],
  "Connections": [
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "ee8bce1e-80db-404b-8c3a-a09db8e25edc",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "2249740b-6d72-4bc8-b178-8c494483b48d"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "38b8d0e0-db39-4c69-8919-3f84b9389076",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "2249740b-6d72-4bc8-b178-8c494483b48d"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "b8acce2c-dc07-4886-b02d-20461d8bed2b",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "2249740b-6d72-4bc8-b178-8c494483b48d"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "04f1d2a3-3db0-45aa-895b-cdd6a398b8a2",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "2249740b-6d72-4bc8-b178-8c494483b48d"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "bf9a5d22-dc4d-4d89-ba26-0dc4f12b40a4",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "2249740b-6d72-4bc8-b178-8c494483b48d"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "17856a47-a5f2-4253-8550-5057328ee385",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "2249740b-6d72-4bc8-b178-8c494483b48d"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "94240fd4-bdf9-4924-a5b1-72cf22cb5366",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "2249740b-6d72-4bc8-b178-8c494483b48d"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "fa1ef39a-f0aa-4e8b-8621-3c4c7e210c5a",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "2249740b-6d72-4bc8-b178-8c494483b48d"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "26e649d0-0fe5-40b6-b312-9ac579c8d3a6",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "2249740b-6d72-4bc8-b178-8c494483b48d"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "5cb64123-dfc6-4029-aafb-57d4297cac33",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "2249740b-6d72-4bc8-b178-8c494483b48d"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "d6849876-0bbc-4722-9b31-159e409ad9eb",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "2249740b-6d72-4bc8-b178-8c494483b48d"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "3cc26782-1e05-4a04-8c75-677f994a465a",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "2249740b-6d72-4bc8-b178-8c494483b48d"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "4f223027-698c-492e-87f7-319417ab2371",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "2249740b-6d72-4bc8-b178-8c494483b48d"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "fa1944ca-6a42-4cd7-83ee-c9b43b52eb45",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "2249740b-6d72-4bc8-b178-8c494483b48d"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "2c61758f-cb2e-4c40-a52f-9b08d95f5c15",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "2249740b-6d72-4bc8-b178-8c494483b48d"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "701020d6-b3ae-4c41-a136-18b06d98f4b8",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "2249740b-6d72-4bc8-b178-8c494483b48d"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "65324148-b778-4d5a-b6f9-34c51023cfd3",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "2249740b-6d72-4bc8-b178-8c494483b48d"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "38e5156f-e441-4c01-b3eb-645255752b17",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "2249740b-6d72-4bc8-b178-8c494483b48d"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "11d78574-8efa-4dc7-a61a-dca5d62be8d4",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "2249740b-6d72-4bc8-b178-8c494483b48d"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "ffd57221-3c5c-4e7b-a535-65ea6181ad42",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "2249740b-6d72-4bc8-b178-8c494483b48d"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "57e11aa3-392c-4761-8ea7-a3a4375d6e65",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "2249740b-6d72-4bc8-b178-8c494483b48d"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "e1c807f6-4a8e-47d1-a8ba-9ad89c020946",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "2249740b-6d72-4bc8-b178-8c494483b48d"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "9c2bb5db-4332-4da8-943d-205e4ffa9a39",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "2249740b-6d72-4bc8-b178-8c494483b48d"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "02efebba-f6f2-4869-93c7-d021ef0c69e9",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "2249740b-6d72-4bc8-b178-8c494483b48d"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "bc63710e-28fa-4288-b429-77bf68d1437a",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "2249740b-6d72-4bc8-b178-8c494483b48d"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "8769e9c4-540e-41d5-b822-82bca4807c20",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "2249740b-6d72-4bc8-b178-8c494483b48d"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "f801beae-f599-4610-b379-fe43ebfcbe4a",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "2249740b-6d72-4bc8-b178-8c494483b48d"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "9d52f731-30b2-4252-b804-c9af7c08d3ce",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "2249740b-6d72-4bc8-b178-8c494483b48d"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "64847bf4-bde0-45f0-b71b-5f8126bee97e",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "2249740b-6d72-4bc8-b178-8c494483b48d"
    },
    {
      "SourceOp": "00000000-0000-0000-0000-000000000000",
      "SourceOpPart": "2249740b-6d72-4bc8-b178-8c494483b48d",
      "TargetOp": "00000000-0000-0000-0000-000000000000",
      "TargetOpPart": "13eff2ca-59c8-4a7b-a636-a4cc54535242"
    }
  ]
}