Ejemplo n.º 1
0
        public void ComputeHeight(ref ComputeBuffer layerBuffer, ref ComputeBuffer maskBuffer, float seedParent, bool first = false)
        {
            TC_Compute compute = TC_Compute.instance;

            float seedTotal = seed + seedParent;

            layerBuffer = selectNodeGroup.ComputeValue(seedTotal);

            if (layerBuffer != null)
            {
                if (maskNodeGroup.active)
                {
                    maskBuffer = maskNodeGroup.ComputeValue(seedTotal);
                }

                if (maskBuffer != null)
                {
                    if (method != Method.Lerp || first)
                    {
                        InitPreviewRenderTexture(true, "rtPreview_Layer_" + TC.outputNames[outputId]);
                        compute.RunComputeMethod(null, null, layerBuffer, ref maskBuffer, 0, rtPreview);
                    }
                }
                else
                {
                    rtDisplay = selectNodeGroup.rtDisplay;
                }
            }
            else
            {
                TC_Reporter.Log("Layerbuffer " + listIndex + " = null, reporting from layer");
            }
        }
Ejemplo n.º 2
0
        // Compute height, trees and objects
        public ComputeBuffer ComputeSingle(ref ComputeBuffer totalBuffer, float seedParent, bool first = false)
        {
            if (!groupResult.active)
            {
                return(null);
            }

            TC_Compute compute = TC_Compute.instance;

            float seedTotal = seed + seedParent;

            totalBuffer = groupResult.ComputeSingle(seedTotal, first);

            // Debug.Log("layerMaskBuffer " + layerMaskBuffer == null);
            ComputeBuffer maskBuffer = null;

            if (maskNodeGroup.active)
            {
                maskBuffer = maskNodeGroup.ComputeValue(seedTotal);
            }

            if (maskBuffer != null)
            {
                TC_Compute.InitPreviewRenderTexture(ref rtPreview, "rtPreview_LayerGroup");

                if (method != Method.Lerp || first)
                {
                    if (outputId == TC.heightOutput)
                    {
                        compute.RunComputeMethod(null, null, totalBuffer, ref maskBuffer, 0, rtPreview);
                    }
                    else
                    {
                        compute.RunItemComputeMask(this, ref rtPreview, groupResult.rtDisplay, ref totalBuffer, ref maskBuffer);
                    }
                }

                rtDisplay = rtPreview;
            }
            else
            {
                if (outputId == TC.heightOutput || level == 0 || groupResult.totalActive == 1)
                {
                    rtDisplay = groupResult.rtDisplay;
                }
                else
                {
                    rtDisplay = rtPreview;
                }
            }

            if (totalBuffer == null)
            {
                TC_Reporter.Log("Layer buffer null");
            }

            return(maskBuffer);
        }
Ejemplo n.º 3
0
        public bool ComputeMulti(ref RenderTexture[] renderTextures, ref ComputeBuffer maskBuffer, float seedParent, bool first = false)
        {
            TC_Compute compute    = TC_Compute.instance;
            bool       didCompute = false;

            float seedTotal = seed + seedParent;

            ComputeBuffer layerBuffer = selectNodeGroup.ComputeValue(seedTotal);

            if (layerBuffer != null)
            {
                didCompute = true;

                TC_Compute.InitPreviewRenderTexture(ref rtPreview, "rtPreview_Layer");

                if (maskNodeGroup.active)
                {
                    maskBuffer = maskNodeGroup.ComputeValue(seedTotal);
                }

                TC_Compute.InitPreviewRenderTexture(ref selectNodeGroup.rtColorPreview, "rtNodeGroupPreview_" + TC.outputNames[outputId]);

                if (outputId == TC.colorOutput)
                {
                    compute.RunColorCompute(selectNodeGroup, selectItemGroup, ref renderTextures[0], ref layerBuffer);
                }
                else
                {
                    compute.RunSplatCompute(selectNodeGroup, selectItemGroup, ref renderTextures, ref layerBuffer);
                }

                compute.DisposeBuffer(ref layerBuffer);

                if (maskBuffer != null)
                {
                    TC_Reporter.Log("Run layer select * mask");
                    if (method != Method.Lerp || first)
                    {
                        if (outputId == TC.colorOutput)
                        {
                            compute.RunComputeColorMethod(this, ref renderTextures[0], maskBuffer, rtPreview);
                        }
                        else
                        {
                            compute.RunComputeMultiMethod(this, doNormalize, ref renderTextures, maskBuffer, rtPreview);
                        }
                    }
                    rtDisplay = rtPreview;
                }
                else
                {
                    TC_Reporter.Log("No mask buffer assign colorPreviewTex to layer");
                    rtDisplay = selectNodeGroup.rtColorPreview;
                }
            }

            return(didCompute);
        }
Ejemplo n.º 4
0
 public bool OutOfBounds()
 {
     // Debug.Log(bounds + " " + Area2D.current.bounds);
     if (bounds.Intersects(TC_Area2D.current.bounds))
     {
         return(false);
     }
     else
     {
         TC_Reporter.Log(name + " Out of bounds!");
         return(true);
     }
 }
Ejemplo n.º 5
0
        // Compute trees and objects
        public bool ComputeItem(ref ComputeBuffer itemMapBuffer, ref ComputeBuffer maskBuffer, float seedParent, bool first = false)
        {
            TC_Compute compute    = TC_Compute.instance;
            bool       didCompute = false;

            float seedTotal = seed + seedParent;

            ComputeBuffer selectBuffer = selectNodeGroup.ComputeValue(seedTotal);

            if (selectBuffer != null)
            {
                didCompute = true;

                TC_Compute.InitPreviewRenderTexture(ref rtPreview, "rtPreview_Layer_" + TC.outputNames[outputId]);
                rtDisplay = rtPreview;
                TC_Compute.InitPreviewRenderTexture(ref selectNodeGroup.rtColorPreview, "rtColorPreview");
                compute.RunItemCompute(this, ref itemMapBuffer, ref selectBuffer);
                compute.DisposeBuffer(ref selectBuffer);

                // compute.shader.SetBuffer(compute.terrainSplatmap0Kernel, "itemMapBuffer", itemMapBuffer);
                // compute.RunItemPositionCompute(itemMapBuffer, TC.treeOutput);

                if (maskNodeGroup.active)
                {
                    maskBuffer = maskNodeGroup.ComputeValue(seedTotal);
                }

                if (maskBuffer != null)
                {
                    TC_Reporter.Log("Run layer select * mask");
                    if (method != Method.Lerp || first)
                    {
                        compute.RunItemComputeMask(this, ref rtPreview, selectNodeGroup.rtColorPreview, ref itemMapBuffer, ref maskBuffer);
                    }
                }
            }

            return(didCompute);
        }
Ejemplo n.º 6
0
 void OnDestroy()
 {
     TC_Reporter.Log("OnDestroy");
     instance = null;
 }
Ejemplo n.º 7
0
        //public void ComputeValue(ref ComputeBuffer totalBuffer)
        //{
        //    TCCompute compute = TCCompute.singleton;
        //    LayerGroupItem item;
        //    ComputeBuffer layerBuffer = null;
        //    ComputeBuffer layerMaskBuffer = null;
        //    // ComputeBuffer layerGroupBuffer = null;
        //    TCLayerGroup layerLevel;

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

        //        if (i == 0)
        //        {
        //            layerMaskBuffer = layerLevel.ComputeValue(ref totalBuffer, TC.heightOutput);
        //        }
        //        else
        //        {
        //            layerMaskBuffer = layerLevel.ComputeValue(ref layerBuffer, TC.heightOutput);
        //            if (layerBuffer != null) compute.RunComputeMethod(this, layerLevel, totalBuffer, ref layerBuffer, itemList.Count, i < itemList.Count - 1 ? null : m_previewRenderTex, true, layerMaskBuffer);
        //        }
        //    }

        //    if (layerMaskBuffer != null) { compute.DisposeBuffer(ref layerMaskBuffer); }


        //    if (totalBuffer == null) Debug.Log("Layer buffer null");
        //}

        //public override void GetItems()
        //{
        //    Transform child;
        //    TCLayerGroup layerLevel;
        //    int childCount = t.childCount;

        //    Init();
        //    itemList.Clear();

        //    // if (preview.tex == null || preview.bytes == null) preview.Create();

        //    for (int i = 0; i < childCount; i++)
        //    {
        //        child = t.GetChild(i);
        //        layerLevel = child.GetComponent<TCLayerLevel>();
        //        if (layerLevel != null)
        //        {
        //            layerLevel.outputId = i;
        //            layerLevel.active = layerLevel.go.activeSelf;
        //            itemList.Add(new LayerGroupMultiItem(layerLevel));
        //            layerLevel.GetItems();
        //        }
        //    }
        //}

        public override void GetItems(bool refresh, bool rebuildGlobalLists, bool resetTextures)
        {
            Transform            child;
            TC_TerrainLayerGroup terrainLayerGroup;
            TC_TerrainLayer      terrainLayer;
            int childCount = transform.childCount;

            // Init();
            itemList.Clear();

            lastActive  = -1;
            totalActive = 0;

            // if (preview.tex == null || preview.bytes == null) preview.Create();
            bool newBounds = true;

            active = visible;

            int listIndex = 0;

            for (int i = childCount - 1; i >= 0; i--)
            {
                child        = transform.GetChild(i);
                terrainLayer = child.GetComponent <TC_TerrainLayer>();
                if (terrainLayer != null)
                {
                    terrainLayer.SetParameters(this, listIndex++);
                    terrainLayer.terrainLevel = terrainLevel + 1;

                    terrainLayer.GetItems(refresh, rebuildGlobalLists, resetTextures);
                    terrainLayer.GetItem(outputId, rebuildGlobalLists, resetTextures);
                    //{
                    ++totalActive;
                    itemList.Add(new TerrainLayerGroupItem(null, terrainLayer));
                    lastActive = itemList.Count - 1;
                    if (newBounds)
                    {
                        bounds = terrainLayer.bounds; newBounds = false;
                    }
                    else
                    {
                        bounds.Encapsulate(terrainLayer.bounds);
                    }
                    //}
                    // else layer.displayRenderTex = null;
                }
                else
                {
                    terrainLayerGroup = child.GetComponent <TC_TerrainLayerGroup>();
                    if (terrainLayerGroup != null)
                    {
                        terrainLayerGroup.SetParameters(this, listIndex++);
                        terrainLayerGroup.terrainLevel = terrainLevel + 1;

                        terrainLayerGroup.GetItems(refresh, rebuildGlobalLists, resetTextures);

                        ++totalActive;
                        itemList.Add(new TerrainLayerGroupItem(terrainLayerGroup, null));
                        lastActive = itemList.Count - 1;
                        if (newBounds)
                        {
                            bounds = terrainLayerGroup.bounds; newBounds = false;
                        }
                        else
                        {
                            bounds.Encapsulate(terrainLayerGroup.bounds);
                        }
                    }
                }
            }

            TC_Reporter.Log(TC.outputNames[outputId] + " Level " + level + " activeTotal " + totalActive);

            if (!active)
            {
                totalActive = 0;
            }
            else if (totalActive == 0)
            {
                active = false;
            }
            else
            {
                active = visible;
            }
        }
Ejemplo n.º 8
0
        void OnGUI()
        {
            ShowMessages();

            if (correctSetup == -1)
            {
                TC.AddMessage("Close and re-open the TerrainComposer window.");
                return;
            }

            if (correctSetup == -2)
            {
                TC.AddMessage("Can't load default project.\nThis file is needed -> TerrainComposer2/Defaults/TerrainComposer2.prefab.\n\n Please try to close and re-open the TerrainComposer window.");
                return;
            }

            if (correctSetup != 0)
            {
                return;
            }

            if (!TD.Init())
            {
                return;
            }

            settings = TC_Settings.instance;
            TC_Reporter.BenchmarkStart();

            TD.countDrawNode = TD.countDrawNodeCulled = 0;

            TD.hoverItem = null;

            TD.rectWindow = new Rect(0, 0, TC_NodeWindow.window.position.width, TC_NodeWindow.window.position.height);

            settings.selectionOld = Selection.activeTransform;

            if (terrainLayer == null)
            {
                GetLayerLevel();
            }

            Keys();
            ScrollInterface();

            TD.eventCurrent = eventCurrent;

            GUI.DrawTexture(new Rect(0, 0, TC_NodeWindow.window.position.width, TC_NodeWindow.window.position.height), TD.texShelfBackground1);

            settings.HasMasterTerrain();

            TD.showSelectRect = false;

            CaptureWindowEvents();

            TD.scrollMax = Vector2.zero;

            TC_TerrainLayerGUI.Draw(terrainLayer);
            DrawCommand.DrawCommandLists();

            TC_ItemBehaviourEditor.CheckKeyLockOnSelection(eventCurrent);

            TD.DrawCenter(Color.red, 21, 1);
            TD.DrawCenter(Color.red, 11, 3);

            DrawMenu();

            DropDownMenuMain();

            if (settings.showFps)
            {
                if (!EditorGUIUtility.isProSkin)
                {
                    GUI.color = new Color(1, 1, 1, 0.5f);
                    GUI.DrawTexture(new Rect(180, 0, 250, 17), Texture2D.whiteTexture);
                    GUI.color = Color.white;
                }
                string fps = TC_Reporter.BenchmarkStop("| fps ", false);
                EditorGUI.LabelField(new Rect((TC_NodeWindow.window.position.width / 2) - 200, 0, 250, 17), "Node Draw " + TD.countDrawNode + "| Nodes Culled " + TD.countDrawNodeCulled + fps);
            }

            //if (onFocus && correctSetup == 0 && ++frame == 20)
            //{
            //    frame = 0;
            //    Repaint();
            //}
        }
Ejemplo n.º 9
0
        public bool DropTextureEditor(Texture tex)
        {
            #if UNITY_EDITOR
            if (tex != null)
            {
                pathTexStamp = UnityEditor.AssetDatabase.GetAssetPath(tex);
                string path  = pathTexStamp;
                int    index = path.LastIndexOf("/");
                path = path.Insert(index, "/RawFiles");

                index = path.IndexOf("/Resources/");
                isStampInResourcesFolder = (index != -1);

                if (isStampInResourcesFolder)
                {
                    path            = path.Substring(index + 11);
                    path            = path.Remove(path.Length - 4);
                    resourcesFolder = path;
                    // Debug.Log(path);
                }
                else
                {
                    path = path.Remove(path.Length - 3) + "raw";

                    if (!TC.FileExistsPath(path))
                    {
                        path = path.Remove(path.Length - 3) + "r16";
                    }

                    if (!TC.FileExistsPath(path))
                    {
                        // TC.AddMessage("Cannot find the file " + path.Remove(path.Length - 3, 3) + "\n\nThe file extension needs to be .raw or .r16");
                        if (rawImage != null)
                        {
                            rawImage.UnregisterReference();
                        }
                        inputFile = InputFile.Image;
                        stampTex  = tex;
                        TC.AutoGenerate();
                        return(false);
                    }
                }

                TC_RawImage oldRawImage = rawImage;
                if (oldRawImage)
                {
                    oldRawImage.UnregisterReference();
                }

                // Debug.Log(path);

                rawImage = TC_Settings.instance.AddRawFile(path, isStampInResourcesFolder);
            }
            #else
            if (isStampInResourcesFolder)
            {
                rawImage = TC_Settings.instance.AddRawFile(resourcesFolder, isStampInResourcesFolder);
            }
            #endif

            if (rawImage != null)
            {
                stampTex = tex;
                TC.RefreshOutputReferences(outputId, true);

                // TC_Reporter.Log(path);
                TC_Reporter.Log("Node index " + rawImage.name);
                return(true);
            }
            else
            {
                TC.AddMessage("This is not a stamp preview image.\n\nThe raw heightmap file needs to be placed in a 'RawFiles' folder, then TC2 will automatically make a preview image one folder before it.\nThis image needs to be used for dropping on the node.", 0, 4);
            }

            return(false);
        }
Ejemplo n.º 10
0
        public bool ComputeMulti(ref RenderTexture[] renderTextures, float seedParent, bool doNormalize, bool first = false)
        {
            TC_Compute compute = TC_Compute.instance;

            RenderTexture[] rtsLayer       = null;
            RenderTexture   rtRightPreview = null;
            RenderTexture   rtLeftPreview  = null;

            RenderTexture[] rtsPreview = null;
            // RenderTexture rtPreview2 = null;
            ComputeBuffer layerMaskBuffer = null;
            TC_LayerGroup layerGroup;
            TC_Layer      layer;
            bool          firstCompute = false;
            bool          lastCompute  = false;

            int even = 0;

            rtsPreview = new RenderTexture[2];

            SetPreviewTextureBefore();

            float seedTotal = seed + seedParent;

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

                if (layer != null)
                {
                    if (!layer.active)
                    {
                        continue;
                    }
                    // InitPreview(ref layer.previewRenderTex);

                    if (!firstCompute)
                    {
                        firstCompute = layer.ComputeMulti(ref renderTextures, ref layerMaskBuffer, seedTotal, i == firstActive);

                        if (firstCompute)
                        {
                            rtLeftPreview = layer.rtDisplay;
                            TC_Reporter.Log("firt compute " + layer.maskNodeGroup.totalActive);
                            compute.DisposeBuffer(ref layerMaskBuffer);
                        }
                    }
                    else
                    {
                        TC_Compute.InitRenderTextures(ref rtsLayer, "rtsLayer", renderTextures.Length);
                        lastCompute = layer.ComputeMulti(ref rtsLayer, ref layerMaskBuffer, seedTotal);

                        if (lastCompute)
                        {
                            TC_Reporter.Log("Run layer method multi");
                            rtRightPreview = (layer.method == Method.Lerp) ? layer.selectNodeGroup.rtColorPreview : layer.rtDisplay;
                            // Debug.Log(rtRight.name+ " "+ (layer.maskNodeGroup.activeTotal == 0 || layer.method == Method.Lerp));

                            if (outputId == TC.colorOutput)
                            {
                                compute.RunComputeColorMethod(layer, layer.method, ref renderTextures[0], ref rtsLayer[0], layerMaskBuffer, rtPreview, ref rtsPreview[even++ % 2], ref rtLeftPreview, rtRightPreview);
                            }
                            else
                            {
                                compute.RunComputeMultiMethod(layer, layer.method, i == lastActive && doNormalize, ref renderTextures, ref rtsLayer, layerMaskBuffer, rtPreview, ref rtsPreview[even++ % 2], ref rtLeftPreview, rtRightPreview);
                            }

                            compute.DisposeBuffer(ref layerMaskBuffer);
                        }
                    }
                }
                else
                {
                    layerGroup = itemList[i] as TC_LayerGroup;
                    if (layerGroup == null)
                    {
                        continue;
                    }
                    if (!layerGroup.active)
                    {
                        continue;
                    }

                    if (!firstCompute)
                    {
                        firstCompute = layerGroup.ComputeMulti(ref renderTextures, ref layerMaskBuffer, seedTotal, i == firstActive);
                        if (firstCompute)
                        {
                            rtLeftPreview = layerGroup.rtDisplay;
                            compute.DisposeBuffer(ref layerMaskBuffer);
                            TC_Reporter.Log("LayerGroup did first compute");
                        }
                    }
                    else
                    {
                        TC_Compute.InitRenderTextures(ref rtsLayer, "rtsLayer", renderTextures.Length);
                        lastCompute = layerGroup.ComputeMulti(ref rtsLayer, ref layerMaskBuffer, seedTotal);
                        if (lastCompute)
                        {
                            // if (layerGroup.groupResult.activeTotal == 1) rtRight = layerGroup.rtDisplay; else rtRight = layerGroup.rtPreview;
                            rtRightPreview = (layerGroup.method == Method.Lerp) ? layerGroup.groupResult.rtDisplay : layerGroup.rtDisplay;

                            if (outputId == TC.colorOutput)
                            {
                                compute.RunComputeColorMethod(layerGroup, layerGroup.method, ref renderTextures[0], ref rtsLayer[0], layerMaskBuffer, rtPreview, ref rtsPreview[even++ % 2], ref rtLeftPreview, rtRightPreview);
                            }
                            else
                            {
                                compute.RunComputeMultiMethod(layerGroup, layerGroup.method, i == lastActive && doNormalize, ref renderTextures, ref rtsLayer, layerMaskBuffer, rtPreview, ref rtsPreview[even++ % 2], ref rtLeftPreview, rtRightPreview);
                            }

                            compute.DisposeBuffer(ref layerMaskBuffer);
                        }
                    }
                }
            }

            SetPreviewTextureAfter();

            if (layerMaskBuffer != null)
            {
                compute.DisposeBuffer(ref layerMaskBuffer); TC_Reporter.Log("Dispose layerMaskBuffer");
            }

            TC_Compute.DisposeRenderTextures(ref rtsPreview);
            TC_Compute.DisposeRenderTextures(ref rtsLayer);

            return(firstCompute);
        }
Ejemplo n.º 11
0
        // Compute height, trees and objects
        public ComputeBuffer ComputeSingle(float seedParent, bool first = false)
        {
            TC_Compute compute = TC_Compute.instance;

            ComputeBuffer totalBuffer     = null;
            ComputeBuffer layerBuffer     = null;
            ComputeBuffer layerMaskBuffer = null;

            RenderTexture[] rtsPreview     = null;
            RenderTexture   rtRightPreview = null;
            RenderTexture   rtLeftPreview  = null;

            if (outputId != TC.heightOutput)
            {
                rtsPreview = new RenderTexture[2];
            }

            SetPreviewTextureBefore();

            int even = 0;

            float seedTotal = seed + seedParent;

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

                if (layer != null)
                {
                    if (!layer.active)
                    {
                        TC_Reporter.Log("Inactive layer " + i); continue;
                    }

                    if (totalBuffer == null)
                    {
                        if (outputId == TC.heightOutput)
                        {
                            layer.ComputeHeight(ref totalBuffer, ref layerMaskBuffer, seedTotal, i == firstActive);
                        }
                        else
                        {
                            layer.ComputeItem(ref totalBuffer, ref layerMaskBuffer, seedTotal, i == firstActive);
                            if (totalBuffer != null)
                            {
                                rtLeftPreview = layer.rtDisplay;
                            }
                        }

                        TC_Area2D.current.layerGroupBuffer = totalBuffer; // Portal

                        compute.DisposeBuffer(ref layerMaskBuffer);
                    }
                    else
                    {
                        if (outputId == TC.heightOutput)
                        {
                            layer.ComputeHeight(ref layerBuffer, ref layerMaskBuffer, seedTotal);
                        }
                        else
                        {
                            layer.ComputeItem(ref layerBuffer, ref layerMaskBuffer, seedTotal);
                        }

                        if (layerBuffer != null)
                        {
                            if (outputId == TC.heightOutput)
                            {
                                compute.RunComputeMethod(this, layer, totalBuffer, ref layerBuffer, totalActive, i == lastActive ? rtPreview : null, layerMaskBuffer);
                            }
                            else
                            {
                                rtRightPreview = layer.rtDisplay;
                                compute.RunComputeObjectMethod(this, layer, totalBuffer, ref layerBuffer, layerMaskBuffer, rtPreview, ref rtsPreview[even++ % 2], ref rtLeftPreview, rtRightPreview);
                            }
                            TC_Area2D.current.layerGroupBuffer = totalBuffer;
                        }
                        compute.DisposeBuffer(ref layerMaskBuffer);
                    }
                }
                else
                {
                    TC_LayerGroup layerGroup = itemList[i] as TC_LayerGroup;
                    if (layerGroup == null)
                    {
                        continue;
                    }
                    if (!layerGroup.active)
                    {
                        continue;
                    }

                    if (totalBuffer == null)
                    {
                        layerMaskBuffer = layerGroup.ComputeSingle(ref totalBuffer, seedTotal, i == firstActive);
                        if (totalBuffer != null)
                        {
                            rtLeftPreview = layerGroup.rtDisplay;
                        }

                        TC_Area2D.current.layerGroupBuffer = totalBuffer;

                        compute.DisposeBuffer(ref layerMaskBuffer);
                    }
                    else
                    {
                        layerMaskBuffer = layerGroup.ComputeSingle(ref layerBuffer, seedTotal);

                        if (layerBuffer != null)
                        {
                            if (outputId == TC.heightOutput)
                            {
                                compute.RunComputeMethod(this, layerGroup, totalBuffer, ref layerBuffer, totalActive, i == lastActive ? rtPreview : null, layerMaskBuffer);
                            }
                            else
                            {
                                rtRightPreview = layerGroup.rtDisplay;
                                compute.RunComputeObjectMethod(this, layerGroup, totalBuffer, ref layerBuffer, layerMaskBuffer, rtPreview, ref rtsPreview[even++ % 2], ref rtLeftPreview, rtRightPreview);
                            }
                            TC_Area2D.current.layerGroupBuffer = totalBuffer;
                        }
                        compute.DisposeBuffer(ref layerMaskBuffer);
                    }
                }
            }

            SetPreviewTextureAfter();

            if (outputId != TC.heightOutput)
            {
                TC_Compute.DisposeRenderTextures(ref rtsPreview);
            }
            compute.DisposeBuffer(ref layerMaskBuffer);

            if (totalBuffer == null)
            {
                TC_Reporter.Log("Layer buffer null");
            }
            return(totalBuffer);
        }
Ejemplo n.º 12
0
 void OnDisable()
 {
     instance = null;
 }
Ejemplo n.º 13
0
 void OnEnable()
 {
     instance = this;
 }
Ejemplo n.º 14
0
 public TC_Reporter()
 {
     instance = this;
 }
Ejemplo n.º 15
0
        public override void GetItems(bool refresh, bool rebuildGlobalLists, bool resetTextures)
        {
            if (resetTextures)
            {
                DisposeTextures();
            }

            active = visible;
            // Init();
            // InitPreview(ref rtPreview);
            bool newBounds = true;

            maskNodeGroup = GetGroup <TC_NodeGroup>(0, refresh, resetTextures);
            if (maskNodeGroup != null)
            {
                maskNodeGroup.type = NodeGroupType.Mask;
                if (maskNodeGroup.totalActive > 0)
                {
                    bounds    = maskNodeGroup.bounds;
                    newBounds = false;
                }
            }

            selectNodeGroup = GetGroup <TC_NodeGroup>(1, refresh, resetTextures);
            if (selectNodeGroup != null)
            {
                selectNodeGroup.type = NodeGroupType.Select;
                if (selectNodeGroup.totalActive == 0)
                {
                    TC_Reporter.Log("SelectNodeGroup 0 active"); active = false;
                }
                else
                {
                    if (newBounds)
                    {
                        bounds = selectNodeGroup.bounds;
                    }
                    else
                    {
                        bounds.Encapsulate(selectNodeGroup.bounds);
                    }
                }
            }
            else
            {
                active = false;
            }

            if (outputId != TC.heightOutput)
            {
                selectItemGroup = GetGroup <TC_SelectItemGroup>(2, refresh, resetTextures);
                if (selectItemGroup != null)
                {
                    if (selectItemGroup.totalActive == 0)
                    {
                        TC_Reporter.Log("itemGroup 0 active"); active = false;
                    }
                    else if (selectItemGroup.itemList.Count <= 1)
                    {
                        // TODO: Make better solution for this
                        selectNodeGroup.useConstant = true;
                        if (selectNodeGroup.itemList.Count > 0)
                        {
                            selectNodeGroup.itemList[0].visible = true;
                            active = visible;
                            GetGroup <TC_NodeGroup>(1, true, resetTextures);
                        }
                    }
                    else
                    {
                        selectNodeGroup.useConstant = false;
                    }
                }
                else
                {
                    active = false;
                }
            }
        }
Ejemplo n.º 16
0
        public bool SetCurrentArea(TCUnityTerrain tcTerrain, int outputId)
        {
            // Debug.Log(tcTerrain.terrain.name);
            Terrain terrain = currentTerrain = tcTerrain.terrain;

            currentTCUnityTerrain = tcTerrain;
            currentTCTerrain      = tcTerrain;
            currentTerrainArea    = terrainAreas[0];

            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) * resExpandBorderPercentage);
                resExpandBorderSize = terrain.terrainData.size.x * 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     = currentTerrain.terrainData.splatPrototypes.Length;
                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);
        }
Ejemplo n.º 17
0
        public void LoadRawImage(string path)
        {
            this.path = path;

            string fullPath = Application.dataPath.Replace("Assets", "/") + path;

            // Debug.Log(fullPath);

            if (tex != null)
            {
                return;
            }

                        #if UNITY_EDITOR
            if (!isResourcesFolder)
            {
                if (!TC.FileExists(fullPath))
                {
                    return;
                }
            }
                        #endif

            TC_Reporter.Log("Load Raw file " + fullPath);

            // Debug.Log(bytes.Length);
            byte[] bytes = null;

            if (isResourcesFolder)
            {
                // Debug.Log("LoadRawImage " + path);
                TextAsset textAsset = Resources.Load <TextAsset>(path);
                if (textAsset != null)
                {
                    bytes = textAsset.bytes;
                }
                else
                {
                    Debug.Log("Can't find file");
                }
            }
            else
            {
                                #if !UNITY_WEBPLAYER
                bytes = File.ReadAllBytes(fullPath);
                                #else
                // TC.AddMessage("You are in Webplayer build mode, loading from disk is protected in this mode and stamp textures don't work.\nThis will be fixed.\n\nFor now another build mode in needed.", 0, 5);
                WWW request = new WWW("file:///" + fullPath);

                while (!request.isDone)
                {
                }
                if (request.error != null)
                {
                    TC.AddMessage(request.error);
                }

                bytes = request.bytes;
                                #endif
            }

            if (bytes == null)
            {
                return;
            }
            if (bytes.Length == 0)
            {
                return;
            }

            GetResolutionFromLength(bytes.Length);
            tex           = new Texture2D(resolution.x, resolution.y, TextureFormat.R16, false);
            tex.hideFlags = HideFlags.DontSave;
            tex.LoadRawTextureData(bytes);
            tex.Apply();

            // For use of mipmap
            //rt = new RenderTexture(resolution.x, resolution.y, 0, RenderTextureFormat.RFloat, RenderTextureReadWrite.Linear);
            //rt.useMipMap = true;
            //rt.hideFlags = HideFlags.DontSave;
            //rt.Create();

            // Graphics.Blit(tex2, rt);
            // Debug.Log("Load");
        }
Ejemplo n.º 18
0
        public override void GetItems(bool refresh, bool rebuildGlobalLists, bool resetTextures)
        {
            if (resetTextures)
            {
                DisposeTextures();
            }

            active = visible;

            itemList.Clear();

            firstActive = lastActive = -1;
            totalActive = 0;

            bool newBounds = true;
            int  listIndex = 0;

            // Debug.Log(name + " GetItems");

            for (int i = t.childCount - 1; i >= 0; i--)
            {
                Transform child = transform.GetChild(i);
                TC_Layer  layer = child.GetComponent <TC_Layer>();

                if (layer != null)
                {
                    layer.SetParameters(this, listIndex);

                    layer.GetItems(refresh, rebuildGlobalLists, resetTextures);
                    if (layer.active)
                    {
                        ++totalActive;
                        lastActive = listIndex;
                        if (firstActive == -1)
                        {
                            firstActive = lastActive;
                        }
                    }
                    itemList.Add(layer);
                    ++listIndex;

                    if (newBounds)
                    {
                        bounds = layer.bounds; newBounds = false;
                    }
                    else
                    {
                        bounds.Encapsulate(layer.bounds);
                    }
                }
                else
                {
                    TC_LayerGroup layerGroup = child.GetComponent <TC_LayerGroup>();

                    if (layerGroup == null)
                    {
                        TC.MoveToDustbin(child);
                    }
                    else
                    {
                        layerGroup.SetParameters(this, listIndex);
                        layerGroup.GetItems(refresh, rebuildGlobalLists, resetTextures);

                        if (layerGroup.active)
                        {
                            ++totalActive;
                            lastActive = listIndex;
                            if (firstActive == -1)
                            {
                                firstActive = lastActive;
                            }
                        }

                        if (layerGroup.groupResult == null)
                        {
                            TC.MoveToDustbin(child);
                        }
                        else
                        {
                            itemList.Add(layerGroup);
                            listIndex++;
                        }
                        if (newBounds)
                        {
                            bounds = layerGroup.bounds; newBounds = false;
                        }
                        else
                        {
                            bounds.Encapsulate(layerGroup.bounds);
                        }
                    }
                }
            }

            TC_Reporter.Log(TC.outputNames[outputId] + " Level " + level + " activeTotal " + totalActive);

            if (!active)
            {
                totalActive = 0;
            }
            else if (totalActive == 0)
            {
                active = false;
            }
        }