Exemplo n.º 1
0
    /// <summary>
    /// Generates a preview texture
    /// </summary>
    private Texture2D Generate(int size)
    {
        Texture2D texture = new Texture2D(size, size, TextureFormat.ARGB32, false);

        Color[] colors = new Color[size * size];

        // get module from the node
        ModuleBase module = null;

        switch (type)
        {
        case WINDOWTYPE.GENERATOR:
            module     = generatorNode.GetModule();
            node.title = generatorNode.type.ToString();
            break;

        case WINDOWTYPE.OPERATOR:
            module     = operatorNode.GetModule();
            node.title = operatorNode.type.ToString();
            break;

        case WINDOWTYPE.OUTPUT:
            module = outputNode.GetModule();
            break;

        case WINDOWTYPE.MACRO:
            module = macroNode.GetModule();
            break;
        }
        // check that node is not null
        if (module != null)
        {
            minValue = Mathf.Infinity;
            maxValue = Mathf.NegativeInfinity;

            for (int y = 0; y < size; y++)
            {
                for (int x = 0; x < size; x++)
                {
                    float value = module.GetValue(Surface.SperifyPoint(new Vector3(-1f + (x / (float)size) * zoom + tx, (y / (float)size) * zoom - 1f + ty, 1f)));
                    if (value < minValue)
                    {
                        minValue = value;
                    }
                    if (value > maxValue)
                    {
                        maxValue = value;
                    }
                    value = (value + 1f) / 2f;
                    colors[y * size + x] = new Color(value, value, value);
                }
            }
            texture.SetPixels(colors);
            texture.Apply();
        }

        return(texture);
    }