public float EvaluateItem(TC_SelectItem selectItem, float time)
        {
            float r1, r2, r3;

            float blend = (mix + 0.001f) / totalActive;

            r2 = selectItem.range.x;
            r3 = selectItem.range.y;

            r2 += blend / 2;
            r3 -= blend / 2;

            r1 = r2 - blend;

            float range = 1 / blend;

            // Debug.Log(r1 + ", " + r2 + ", " + r3);
            // Debug.Log(range);

            if (time < r3)
            {
                return(Mathf.Lerp(0, 1, Mathf.Clamp01(time - r1) * range));
            }
            else
            {
                return(Mathf.Lerp(1, 0, Mathf.Clamp01(time - r3) * range));
            }
        }
        public void CenterRange(TC_SelectItem changedSelectItem)
        {
            if (!changedSelectItem.active)
            {
                return;
            }

            float average = 1.0f / totalActive;
            float x       = 0;

            int index = 0;

            for (int i = 0; i < itemList.Count; i++)
            {
                TC_SelectItem selectItem = itemList[i];

                if (selectItem == changedSelectItem)
                {
                    selectItem.range = new Vector2(x, x + average); index = i; break;
                }
                if (selectItem.active)
                {
                    x += average;
                }
            }

            SetRanges(itemList[index], true);
        }
        public void CreateItemMixBuffer()
        {
            // Debug.Log("Create Item Mix buffer");

            if (indices == null)
            {
                indices = new Vector4[totalActive];
            }
            else if (indices.Length != itemList.Count)
            {
                indices = new Vector4[totalActive];
            }

            int index = 0;

            for (int i = 0; i < itemList.Count; i++)
            {
                TC_SelectItem item = itemList[i];

                if (item.active)
                {
                    indices[index++] = new Vector4(item.globalListIndex, item.range.x, item.range.y, item.opacity * opacity);
                }
            }
        }
        public void CreateColorMixBuffer()
        {
            if (colorMixBuffer == null)
            {
                colorMixBuffer = new ColorItem[totalActive];
            }
            if (colorMixBuffer.Length != totalActive)
            {
                colorMixBuffer = new ColorItem[totalActive];
            }

            float blend = (mix + 0.001f) / totalActive;
            float range = 1 / blend;

            int index = 0;

            for (int i = 0; i < itemList.Count; i++)
            {
                TC_SelectItem item = itemList[i];

                if (item.active)
                {
                    colorMixBuffer[index++] = new ColorItem(new Vector3(item.range.x - blend, item.range.y, range), item.color);
                }
                // Debug.Log(colorMixBuffer[i].select);
            }
        }
Exemple #5
0
        public void CreateItemMixBuffer()
        {
            // Debug.Log("Create Item Mix buffer");

            if (indices == null)
            {
                indices = new ItemSettings[totalActive];
            }
            else if (indices.Length != itemList.Count)
            {
                indices = new ItemSettings[totalActive];
            }

            int index = 0;

            for (int i = 0; i < itemList.Count; i++)
            {
                TC_SelectItem item = itemList[i];

                if (item.active)
                {
                    indices[index++] = new ItemSettings(item.globalListIndex, outputId == TC.treeOutput ? item.tree.randomPosition : item.spawnObject.randomPosition, item.range, item.opacity * opacity);
                    // Debug.Log(indices[index - 1].randomPosition);
                }
            }
        }
 TC_SelectItem GetActiveItemUp(int index)
 {
     for (int i = index; i < itemList.Count; i++)
     {
         TC_SelectItem selectItem = itemList[i];
         if (selectItem.active)
         {
             return(selectItem);
         }
     }
     return(null);
 }
        TC_SelectItem GetActiveItemDown(int index)
        {
            // Debug.Log(index + " " + itemList.Count);
            for (int i = index; i >= 0; i--)
            {
                TC_SelectItem selectItem = itemList[i];
                if (selectItem.active)
                {
                    return(selectItem);
                }
            }

            return(null);
        }
Exemple #8
0
        public void CreateSplatMixBuffer()
        {
            // Debug.Log("Create splat mix buffer");

            if (splatMixBuffer == null)
            {
                splatMixBuffer = new SplatCustom[totalActive];
            }
            if (splatMixBuffer.Length != totalActive)
            {
                splatMixBuffer = new SplatCustom[totalActive];
            }

            float splatCustomTotal;

            float[] splatCustomValues;
            Vector4 custom0, custom1;

            float blend = (mix + 0.001f) / totalActive;
            float range = 1 / blend;

            int index = 0;

            for (int i = 0; i < itemList.Count; ++i)
            {
                TC_SelectItem selectItem = itemList[i];

                if (selectItem.active)
                {
                    if (selectItem.splatCustom)
                    {
                        splatCustomTotal  = selectItem.splatCustomTotal;
                        splatCustomValues = selectItem.splatCustomValues;

                        custom0 = new Vector4(splatCustomValues[0] / splatCustomTotal, splatCustomValues[1] / splatCustomTotal, splatCustomValues[2] / splatCustomTotal, splatCustomValues[3] / splatCustomTotal);
                        custom1 = new Vector4(splatCustomValues[4] / splatCustomTotal, splatCustomValues[5] / splatCustomTotal, splatCustomValues[6] / splatCustomTotal, splatCustomValues[7] / splatCustomTotal);

                        // Debug.Log(custom0 + " - " + custom1);
                    }
                    else
                    {
                        custom0 = Vector4.zero;
                        custom1 = Vector4.zero;
                    }

                    splatMixBuffer[index++] = new SplatCustom(new Vector4(selectItem.range.x - blend, selectItem.range.y, range, selectItem.splatCustom ? -1 : selectItem.selectIndex), custom0, custom1, custom0, custom1);
                }
            }
        }
        // static public FilterGroupNode parent;
        static public void DrawSplatCustomPreview(TC_SelectItem selectItem, Rect rect)
        {
            // selectItem.CalcSplatCustomTotal();

            GUI.color = Color.black;
            EditorGUI.DrawPreviewTexture(rect, Texture2D.whiteTexture);

            for (int i = 0; i < selectItem.splatCustomValues.Length; i++)
            {
                GUI.color = new Color(1, 1, 1, (selectItem.splatCustomValues[i] / selectItem.splatCustomTotal) * 1.5f);
                EditorGUI.DrawPreviewTexture(rect, TC_Settings.instance.masterTerrain.terrainData.splatPrototypes[i].texture);
            }

            GUI.color = Color.white;
        }
Exemple #10
0
        static public TC_ItemBehaviour AddItem(TC_ItemBehaviour item, bool clone, bool addNodeGroup = false)
        {
            TC_ItemBehaviour itemToDrop = null;

            if (!clone)
            {
                if (item.GetType() == typeof(TC_Node))
                {
                    if (addNodeGroup)
                    {
                        itemToDrop = (TC_ItemBehaviour)item.Add <TC_NodeGroup>("Node Group", true);
                    }
                    else
                    {
                        itemToDrop = (TC_ItemBehaviour)item.Add <TC_Node>("", true);
                    }
                }
                else if (item.GetType() == typeof(TC_SelectItem))
                {
                    itemToDrop = (TC_ItemBehaviour)item.Add <TC_SelectItem>("", true);

                    TC_SelectItem newSelectItem = (TC_SelectItem)itemToDrop;
                    TC_SelectItem selectItem    = (TC_SelectItem)item;

                    if (selectItem.dropPosition == DropPosition.Right)
                    {
                        newSelectItem.selectIndex = Mathf.Min(selectItem.selectIndex + 1, Mathf.Max(0, newSelectItem.GetItemTotalFromTerrain() - 1));
                    }
                    else
                    {
                        newSelectItem.selectIndex = Mathf.Max(selectItem.selectIndex - 1, 0);
                    }
                }
                Undo.RegisterCreatedObjectUndo(item.gameObject, "Created " + item.name);
            }
            else
            {
                itemToDrop = item;
            }

            itemToDrop = TD.DropItemSameLevel(item, itemToDrop, clone, false);

            Selection.activeTransform = itemToDrop.t;

            return(itemToDrop);
        }
        public void ResetRanges()
        {
            if (itemList.Count == 0)
            {
                return;
            }

            float average = 1.0f / totalActive;
            float x       = 0;

            for (int i = 0; i < itemList.Count; i++)
            {
                TC_SelectItem selectItem = itemList[i];

                if (selectItem.active)
                {
                    selectItem.range = new Vector2(x, x + average);
                    x += average;
                }
            }

            SetRanges(itemList[0], true);
        }
Exemple #12
0
        static public void Draw(TC_SelectItemGroup selectItemGroup, float activeMulti, int index, bool nodeFoldout, ref Vector2 pos, Color color)
        {
            TC_SelectItem selectItem = selectItemGroup.itemList[index];

            Undo.RecordObject(selectItem, selectItem.name);

            Rect rectPreview;
            bool isCulled = false;

            if (selectItem.outputId == TC.colorOutput)
            {
                if (selectItem.texColor != null && selectItem.parentItem.itemList.Count == 1)
                {
                    rectPreview = TD.DrawNode(selectItem, pos, color, Color.white, ref isCulled, activeMulti, nodeFoldout, false, false);
                }
                else
                {
                    rectPreview = TD.DrawNode(selectItem, pos, color, selectItem.color, ref isCulled, activeMulti, nodeFoldout, false, false);
                }
            }
            else
            {
                rectPreview = TD.DrawNode(selectItem, pos, color, Color.white, ref isCulled, activeMulti, nodeFoldout, false, !selectItem.splatCustom);
            }
            if (isCulled || !nodeFoldout)
            {
                return;
            }

            if (TC_Settings.instance.hasMasterTerrain)
            {
                Vector2 sliderPos = TD.GetPositionScaled(new Vector2(pos.x + 10.5f, pos.y + 297.5f));
                GUIUtility.ScaleAroundPivot(new Vector2(TD.scale * 2.25f, TD.scale * 2.25f), new Vector2(sliderPos.x, sliderPos.y));

                if (selectItem.outputId != TC.objectOutput)
                {
                    if (selectItem.outputId == TC.colorOutput)
                    {
                        Color colOld = selectItem.color;
                        if (Event.current.button != 2)
                        {
                            selectItem.color = EditorGUI.ColorField(new Rect(sliderPos.x, sliderPos.y + 4, 93, 10), selectItem.color);
                        }
                        else
                        {
                            EditorGUI.ColorField(new Rect(sliderPos.x, sliderPos.y + 4, 93, 10), selectItem.color);
                        }
                        selectItem.color.a = 1;
                        if (selectItem.color != colOld)
                        {
                            selectItem.Refresh();
                        }
                    }
                    else
                    {
                        int selectIndexOld = selectItem.selectIndex;
                        int total          = selectItem.GetItemTotalFromTerrain();
                        if (total > 1)
                        {
                            if (selectItem.outputId == TC.treeOutput)
                            {
                                sliderPos.y -= 17;
                            }
                            if (Event.current.button != 2)
                            {
                                selectItem.selectIndex = (int)GUI.HorizontalSlider(new Rect(sliderPos.x, sliderPos.y, 110, 16), selectItem.selectIndex, 0, total - 1);
                            }
                            else
                            {
                                GUI.HorizontalSlider(new Rect(sliderPos.x, sliderPos.y, 110, 16), selectItem.selectIndex, 0, total - 1);
                            }
                        }

                        if (selectItem.selectIndex != selectIndexOld)
                        {
                            selectItem.Refresh();
                        }
                    }
                }

                if (selectItem.outputId == TC.splatOutput)
                {
                    // if (selectItem.splatCustom) DrawSplatCustomPreview(selectItem, rectPreview);
                }

                GUI.matrix = Matrix4x4.Scale(new Vector3(1, 1, 1));

                TC_NodeGUI.DrawAddItem(rectPreview, pos, selectItem);
                TC_NodeGUI.LeftClickMenu(rectPreview, selectItem);
            }

            if (selectItem.outputId != TC.colorOutput)
            {
                Rect colorRect = new Rect(rectPreview.x + 0 * TD.scale, rectPreview.y + 0 * TD.scale, 60 * TD.scale, 16f * TD.scale);
                GUI.color = new Color(selectItem.color.r, selectItem.color.g, selectItem.color.b, 0.75f);
                GUI.DrawTexture(colorRect, Texture2D.whiteTexture);
                GUI.color = Color.white;
            }
        }
        public void SetRanges(TC_SelectItem changedSelectItem = null, bool resetInActive = false)
        {
            if (itemList.Count == 0)
            {
                untouched = true; return;
            }
            if (changedSelectItem == null)
            {
                changedSelectItem = itemList[0];
            }

            TC_SelectItem selectItem;

            int index = changedSelectItem.active ? changedSelectItem.listIndex : 0;

            float x = itemList[index].range.x;
            float y = itemList[index].range.y;

            if (!resetInActive)
            {
                untouched = false;
            }

            for (int i = index + 1; i < itemList.Count; ++i)
            {
                selectItem = itemList[i];

                if (selectItem.active)
                {
                    selectItem.range.x = y;
                    selectItem.range.y = y = Mathf.Max(selectItem.range.x, selectItem.range.y);
                }
            }

            for (int i = index - 1; i >= 0; --i)
            {
                selectItem = itemList[i];

                if (selectItem.active)
                {
                    selectItem.range.y = x;
                    selectItem.range.x = x = Mathf.Min(selectItem.range.x, selectItem.range.y);
                }
            }

            selectItem = GetActiveItemUp(0);
            if (selectItem != null)
            {
                selectItem.range.x = 0;
            }

            selectItem = GetActiveItemDown(itemList.Count - 1);
            if (selectItem != null)
            {
                selectItem.range.y = 1;
            }

            if (resetInActive)
            {
                TC_SelectItem neighborItem;

                for (int i = 0; i < itemList.Count; i++)
                {
                    selectItem = itemList[i];

                    if (!selectItem.active)
                    {
                        neighborItem = GetActiveItemDown(i - 1);
                        if (neighborItem != null)
                        {
                            selectItem.range.y = selectItem.range.x = neighborItem.range.y;
                        }
                        else
                        {
                            selectItem.range.y = 0;
                        }

                        neighborItem = GetActiveItemUp(i + 1);
                        if (neighborItem != null)
                        {
                            selectItem.range.x = selectItem.range.y = neighborItem.range.x;
                        }
                        else
                        {
                            selectItem.range.x = 1;
                        }
                    }
                }
            }

            CalcPreview();
        }
        public override void GetItems(bool refresh, bool rebuildGlobalLists, bool resetTextures)
        {
            if (resetTextures)
            {
                DisposeTextures();
            }

            itemList.Clear();

            totalActive = 0;

            int listIndex = 0;

            for (int i = t.childCount - 1; i >= 0; i--)
            {
                Transform child = t.GetChild(i);

                TC_SelectItem selectItem = child.GetComponent <TC_SelectItem>();
                if (selectItem == null)
                {
                    TC.MoveToDustbin(child);
                }
                else
                {
                    selectItem.SetParameters(this, listIndex);
                    selectItem.parentItem = this;

                    selectItem.active = selectItem.visible;

                    if (outputId == TC.splatOutput && selectItem.splatCustom)
                    {
                        if (TC_Settings.instance.hasMasterTerrain)
                        {
                            if (selectItem.splatCustomValues.Length != TC_Settings.instance.masterTerrain.terrainData.splatPrototypes.Length)
                            {
                                selectItem.splatCustomValues = Mathw.ResizeArray <float>(selectItem.splatCustomValues, TC_Settings.instance.masterTerrain.terrainData.splatPrototypes.Length);
                            }
                        }
                        selectItem.CalcSplatCustomTotal();
                    }

                    selectItem.SetPreviewItemTexture(); // Put deactive if listIndex is out of bounds

                    if (selectItem.active)
                    {
                        ++totalActive;
                    }

                    if (outputId == TC.treeOutput)
                    {
                        if (selectItem.tree == null)
                        {
                            selectItem.tree = new TC_SelectItem.Tree();
                        }

                        if (selectItem.active)
                        {
                            bool addToList = true;

                            List <TC_SelectItem> treeSelectItems = TC_Area2D.current.terrainLayer.treeSelectItems;

                            if (!rebuildGlobalLists)
                            {
                                int index = treeSelectItems.IndexOf(selectItem);
                                if (index != -1)
                                {
                                    addToList = false; selectItem.globalListIndex = index;
                                }
                            }

                            if (addToList)
                            {
                                treeSelectItems.Add(selectItem);
                                selectItem.globalListIndex = treeSelectItems.Count - 1;
                            }
                        }
                    }
                    else if (outputId == TC.objectOutput)
                    {
                        if (selectItem.spawnObject == null)
                        {
                            selectItem.spawnObject = new TC_SelectItem.SpawnObject();
                        }
                        if (selectItem.spawnObject.go == null)
                        {
                            selectItem.active = false;
                            TC_Area2D.current.terrainLayer.objectSelectItems.Remove(selectItem);
                            // Debug.Log("Remove from list");
                        }

                        if (selectItem.active)
                        {
                            bool addToList = true;

                            List <TC_SelectItem> objectSelectItems = TC_Area2D.current.terrainLayer.objectSelectItems;

                            if (!rebuildGlobalLists)
                            {
                                int index = objectSelectItems.IndexOf(selectItem);
                                if (index != -1)
                                {
                                    addToList = false; selectItem.globalListIndex = index;
                                }
                            }

                            if (addToList)
                            {
                                objectSelectItems.Add(selectItem);
                                selectItem.globalListIndex = objectSelectItems.Count - 1;
                            }
                            selectItem.selectIndex = listIndex;
                        }
                    }

                    selectItem.SetPreviewItemTexture();
                    selectItem.SetPreviewColor();

                    itemList.Add(selectItem);
                    listIndex++;
                }
            }

            if (refreshRangeItem != null || refreshRanges)
            {
                refreshRanges = false;
                RefreshRanges();
                refreshRangeItem = null;
            }
            else if (refresh || TC.refreshPreviewImages)
            {
                CalcPreview();
            }
        }
        void CalcPreview(Texture2D[] texArray)
        {
            preview.Init(128);

            float resolution = preview.tex.width;

            // TC_Reporter.BenchmarkStart();

            Color[] splatColors = TC_Settings.instance.global.previewColors;

            for (float y = 0; y < resolution; y++)
            {
                float normY = y / resolution;

                for (float x = 0; x < resolution; x++)
                {
                    Color color = Color.black;
                    float total = 0;

                    float normX = x / resolution;

                    if (normX > 0.90f)
                    {
                        color = Color.white * normY;
                    }

                    for (int i = 0; i < itemList.Count; i++)
                    {
                        TC_SelectItem item = itemList[i];
                        if (!item.active)
                        {
                            continue;
                        }

                        float v = EvaluateItem(item, normY);

                        if ((normY) < item.range.y + 0.004f && (normY) > item.range.y - 0.004f)
                        {
                            color = Color.red;
                            total = 1;
                            break;
                        }
                        else if (normX > 0.80f && normX <= 0.90f && outputId != TC.colorOutput)
                        {
                            float g = (normX - 0.80f) * 50;
                            if (item.splatCustom)
                            {
                                for (int j = 0; j < texArray.Length; j++)
                                {
                                    color += (item.splatCustomValues[j] / item.splatCustomTotal) * splatColors[j] * v * g;
                                }
                            }
                            else
                            {
                                color += item.color * v * g;
                            }
                            total += v * g;
                        }
                        if ((v > 0 && normX <= 0.9f) || outputId == TC.colorOutput)
                        {
                            if (item.splatCustom)
                            {
                                for (int j = 0; j < texArray.Length; j++)
                                {
                                    color += (item.splatCustomValues[j] / item.splatCustomTotal) * texArray[j].GetPixel(Mathf.RoundToInt(normX * item.preview.tex.width), Mathf.RoundToInt(normY * item.preview.tex.height)) * v;
                                }
                            }
                            else
                            {
                                if (outputId != TC.colorOutput && item.preview.tex != null)
                                {
                                    color += item.preview.tex.GetPixel(Mathf.RoundToInt(normX * item.preview.tex.width), Mathf.RoundToInt(normY * item.preview.tex.height)) * v * Mathf.Lerp(1, 0, (normX - 0.8f) * 10);
                                }
                                else
                                {
                                    color += item.color * v * Mathf.Lerp(1, 0, (normX - 0.8f) * 10);
                                }
                            }
                            total += v * Mathf.Lerp(1, 0, (normX - 0.8f) * 10);
                        }
                    }

                    if (normX <= 0.9f)
                    {
                        color /= total;
                    }

                    preview.SetPixelColor(Mathf.RoundToInt(normX * resolution), Mathf.RoundToInt(normY * resolution), color);
                }
            }

            // TC_Reporter.BenchmarkStop();
            preview.UploadTexture();
        }