Esempio n. 1
0
        public void CalcPreview(bool calcValues = true)
        {
            if (!TC_Settings.instance.hasMasterTerrain)
            {
                return;
            }

            if (itemList.Count > 1)
            {
                int length = TC.GetTerrainSplatTextureLength(TC_Settings.instance.masterTerrain);

                if (outputId == TC.splatOutput)
                {
                    Texture2D[] texArray = TC.GetTerrainSplatTextures(TC_Settings.instance.masterTerrain);

                    for (int i = 0; i < length; i++)
                    {
                        TC.SetTextureReadWrite(texArray[i]);
                    }
                    CalcPreview(texArray);
                }
                else
                {
                    if (outputId == TC.grassOutput)
                    {
                        for (int i = 0; i < itemList.Count; i++)
                        {
                            TC.SetTextureReadWrite(itemList[i].preview.tex);
                        }
                    }
                    CalcPreview(null);
                }
            }

            CreateMixBuffer();

            // Debug.Log("CalcPreview");
            TC.AutoGenerate();
        }
Esempio n. 2
0
        public int GetItemTotalFromTerrain()
        {
            TC_Settings localSettings = TC_Settings.instance;

            if (!localSettings.hasMasterTerrain)
            {
                return(0);
            }

            if (outputId == TC.splatOutput)
            {
                return(TC.GetTerrainSplatTextureLength(localSettings.masterTerrain));
            }
            if (outputId == TC.grassOutput)
            {
                return(localSettings.masterTerrain.terrainData.detailPrototypes.Length);
            }
            if (outputId == TC.treeOutput)
            {
                return(localSettings.masterTerrain.terrainData.treePrototypes.Length);
            }

            return(0);
        }
Esempio n. 3
0
        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)
                        {
                            int length = TC.GetTerrainSplatTextureLength(TC_Settings.instance.masterTerrain);
                            if (selectItem.splatCustomValues == null)
                            {
                                selectItem.splatCustomValues = new float[length];
                            }
                            else if (selectItem.splatCustomValues.Length != length)
                            {
                                selectItem.splatCustomValues = Mathw.ResizeArray(selectItem.splatCustomValues, 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.spawnObject.parentMode == TC_SelectItem.SpawnObject.ParentMode.Existing && selectItem.spawnObject.parentT == null) ||
                            (selectItem.spawnObject.parentMode == TC_SelectItem.SpawnObject.ParentMode.Create && selectItem.spawnObject.parentName == ""))
                        {
                            selectItem.active = false;
                            TC_Area2D.current.terrainLayer.objectSelectItems.Remove(selectItem);
                            // Debug.Log("Remove from list");
                        }

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

                            TC_Area2D area2D;

                            if (TC_Area2D.current == null)
                            {
                                area2D = FindObjectOfType <TC_Area2D>();
                            }
                            else
                            {
                                area2D = TC_Area2D.current;
                            }

                            List <TC_SelectItem> objectSelectItems = area2D.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();
                    if (selectItem.outputId != TC.colorOutput)
                    {
                        selectItem.SetPreviewColor();
                    }

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

            if (refreshRangeItem != null || refreshRanges)
            {
                refreshRanges = false;
                RefreshRanges();
                refreshRangeItem = null;
            }
            else if (refresh || TC.refreshPreviewImages)
            {
                CalcPreview();
            }
        }
Esempio n. 4
0
        public bool SetCurrentArea(TCUnityTerrain tcTerrain, int outputId)
        {
            // Debug.Log(tcTerrain.terrain.name);
            SetCurrentArea(tcTerrain);
            Terrain terrain = currentTerrain;

            if (!currentTCUnityTerrain.active)
            {
                return(false);
            }

            intResolution = new Int2();
            Int2 resolution2 = new Int2();

            if (terrain.terrainData.heightmapResolution > 2049)
            {
                resExpandBorder     = 0;
                resExpandBorderSize = 0;
            }
            else
            {
                resExpandBorder     = Mathf.RoundToInt((terrain.terrainData.heightmapResolution - 1) * TC_Settings.instance.resExpandBorderPercentage);
                resExpandBorderSize = terrain.terrainData.size.x * TC_Settings.instance.resExpandBorderPercentage;
            }

            // Debug.Log(resExpandBorder);
            // Debug.Log(resExpandBorderSize);

            if (outputId == TC.heightOutput)
            {
                intResolution.x = intResolution.y = (terrain.terrainData.heightmapResolution) + (resExpandBorder * 2);
                resolution2     = new Int2(terrain.terrainData.heightmapResolution, terrain.terrainData.heightmapResolution);
            }
            else if (outputId == TC.splatOutput)
            {
                intResolution.x = intResolution.y = terrain.terrainData.alphamapResolution;
                resolution2     = intResolution;
                splatLength     = TC.GetTerrainSplatTextureLength(currentTerrain);
                splatmapLength  = currentTerrain.terrainData.alphamapTextures.Length;
            }
            else if (outputId == TC.treeOutput)
            {
                intResolution.x = intResolution.y = (int)(terrain.terrainData.size.x / terrainLayer.treeResolutionPM); resolution2 = intResolution;
            }
            else if (outputId == TC.grassOutput)
            {
                intResolution.x = intResolution.y = terrain.terrainData.detailResolution; resolution2 = intResolution;
            }
            else if (outputId == TC.objectOutput)
            {
                intResolution.x = intResolution.y = (int)(terrain.terrainData.size.x / terrainLayer.objectResolutionPM); resolution2 = intResolution;
                //if (false)
                //{
                //    area.center = new Vector2((int)terrainLayer.objectTransform.position.x, (int)terrainLayer.objectTransform.position.z);
                //    area.size = new Vector2(terrainLayer.objectResolutionPM, terrainLayer.objectResolutionPM);
                //    totalArea.position = area.position;
                //    totalArea.size = terrainLayer.objectAreaSize;
                //    resolutionPM = new Vector2(terrainLayer.objectAreaSize.x / (resolution2.x), terrainLayer.objectAreaSize.y / (resolution2.y));
                //}
            }
            else if (outputId == TC.colorOutput)
            {
                intResolution.x = intResolution.y = terrainLayer.colormapResolution; resolution2 = intResolution;
            }

            outputOffsetV2 = new Vector2(terrainLayer.layerGroups[outputId].t.position.x, terrainLayer.layerGroups[outputId].t.position.z);
            outputOffsetV3 = new Vector3(outputOffsetV2.x, 0, outputOffsetV2.y);

            resolution = intResolution.ToVector2();

            if (intResolution.x < TC_Settings.instance.previewResolution)
            {
                previewResolution = intResolution.x; TC_Reporter.Log("From " + TC_Settings.instance.previewResolution + " To " + previewResolution);
            }
            else
            {
                previewResolution = TC_Settings.instance.previewResolution;
            }

            resToPreview = new Vector2((previewResolution - 0) / (totalArea.width + 0), (previewResolution - 0) / (totalArea.height + 0));

            if (outputId == TC.heightOutput || outputId == TC.splatOutput)
            {
                resolutionPM = new Vector2(terrain.terrainData.size.x / (resolution2.x - 1), terrain.terrainData.size.z / (resolution2.y - 1));
            }
            else
            {
                resolutionPM = new Vector2(terrain.terrainData.size.x / (resolution2.x - 0), terrain.terrainData.size.z / (resolution2.y - 0));
            }

            // if (outputId == TC.objectOutput) Debug.Log(resolutionPM);

            // resolutionPM = new Vector2(terrain.terrainData.size.x / (resolution2.x - 1), terrain.terrainData.size.z / (resolution2.y - 1));

            if (outputId == TC.heightOutput)
            {
                // area = new Rect(terrain.transform.position.x - resolutionPM.x, terrain.transform.position.z - resolutionPM.y, intResolution.x - 0, intResolution.y - 0);
                area = new Rect(terrain.transform.position.x - (resolutionPM.x * resExpandBorder), terrain.transform.position.z - (resolutionPM.y * resExpandBorder), intResolution.x - 0, intResolution.y - 0);
            }
            else
            {
                // resolutionPM = new Vector2(terrain.terrainData.size.x / (resolution2.x), terrain.terrainData.size.z / (resolution2.y));
                Vector2 posSnap;
                posSnap.x = Mathw.Snap(terrain.transform.position.x, resolutionPM.x);
                posSnap.y = Mathw.Snap(terrain.transform.position.z, resolutionPM.y);

                if (outputId == TC.treeOutput || outputId == TC.objectOutput)
                {
                    // posSnap += resolutionPM / 2;
                }
                area = new Rect(posSnap.x, posSnap.y, intResolution.x, intResolution.y);

                snapOffsetUV    = (new Vector2(terrain.transform.position.x, terrain.transform.position.z) - posSnap);
                snapOffsetUV.x /= terrain.terrainData.size.x;
                snapOffsetUV.y /= terrain.terrainData.size.z;

                // Debug.Log(area);
            }

            bounds      = new Bounds(terrain.transform.position + terrain.terrainData.size / 2, terrain.terrainData.size);
            startPos    = new Vector3(area.xMin, terrain.transform.position.y, area.yMin);
            terrainSize = terrain.terrainData.size;

            return(true);
        }