コード例 #1
0
ファイル: Weld.cs プロジェクト: LeJuiceBOX/nvgd-roadtocarsons
        private static void WeldDraftToMain(TerrainTile reference, TerrainTile welded, Coord weldDir)
        /// Lowers edges on welding to main tile
        {
            if (welded.draft.edges.heightEdges.IsEmpty)
            {
                welded.draft.edges.heightEdges.ReadFloats2D(welded.draft.terrain.terrainData.GetHeights(0, 0, welded.draft.terrain.terrainData.heightmapResolution, welded.draft.terrain.terrainData.heightmapResolution));
            }
            //for an unknown reason ready chunks in scene do not have their edges (generated or saved). Leads to "Empty weld array" error. Forcing to read from terrain.

            EdgesSet refEdges  = reference.main.edges;
            EdgesSet weldEdges = welded.draft.edges;

            //loading saved edges big array
            float[] refArr = refEdges.heightEdges.GetArr(weldDir);

            //duplicating neig saved edges short array
            float[] weldArr     = weldEdges.heightEdges.GetArr(-weldDir);
            float[] weldArrCopy = new float[weldArr.Length];
            //Array.Copy(weldArr, weldArrCopy, weldArr.Length); //will be re-filled anyways

            //welding and apply to terrain
            Weld.WeldArrays(refArr, weldArrCopy, lowerOnMismatch: true);

            Weld.ApplyToTerrain(welded.draft.terrain.terrainData, weldArrCopy, -weldDir);
        }
コード例 #2
0
ファイル: Weld.cs プロジェクト: louis030195/niwrad
        private static void RestoreDraftWeld(TerrainTile welded, Coord weldDir)
        /// Restoring height edges if they were lowered by welding with main
        {
            EdgesSet edges = welded.draft.edges;

            float[] arr = edges.heightEdges.GetArr(weldDir);
            Weld.ApplyToTerrain(welded.draft.terrain.terrainData, arr, weldDir);
        }
コード例 #3
0
ファイル: Weld.cs プロジェクト: LeJuiceBOX/nvgd-roadtocarsons
        public static void WeldEdgesInThread(EdgesSet thisEdges, TerrainTileManager tileManager, Coord coord, bool isDraft = false)
        /// Welds edges (does not affect data)
        {
            if (tileManager == null)
            {
                return;
            }

            for (int d = 0; d < weldDirections.Length; d++)
            {
                TerrainTile neigTile = tileManager[coord + weldDirections[d]];
                if (neigTile == null ||
                    (isDraft && neigTile.draft == null) || (isDraft && !neigTile.draft.generateReady) ||
                    (!isDraft && neigTile.main == null) || (!isDraft && !neigTile.main.generateReady))
                {
                    continue;
                }
                //if null or not generate-ready

                EdgesSet neigEdges = isDraft ? neigTile.draft?.edges : neigTile.main?.edges;
                if (neigEdges == null || !neigEdges.ready)
                {
                    continue;
                }

                //height
                if (neigEdges.heightEdges != null && neigEdges.heightEdges.SizeX == thisEdges.heightEdges.SizeX)
                {
                    Weld.WeldEdges(neigEdges.heightEdges, neigTile.coord, thisEdges.heightEdges, coord);
                }

                //splats
                if (neigEdges.splatEdges != null && thisEdges.splatEdges != null && thisEdges.splatEdges.Length == neigEdges.splatEdges.Length)
                {
                    for (int i = 0; i < thisEdges.splatEdges.Length; i++)
                    {
                        if (thisEdges.splatEdges[i].SizeX == neigEdges.splatEdges[i].SizeX)
                        {
                            Weld.WeldEdges(neigEdges.splatEdges[i], neigTile.coord, thisEdges.splatEdges[i], coord);
                        }
                    }
                }

                //textures
                if (neigEdges.controlEdges != null && thisEdges.controlEdges != null && thisEdges.controlEdges.Length == neigEdges.controlEdges.Length)
                {
                    for (int i = 0; i < thisEdges.controlEdges.Length; i++)
                    {
                        if (thisEdges.controlEdges[i].SizeX == neigEdges.controlEdges[i].SizeX)
                        {
                            Weld.WeldEdges(neigEdges.controlEdges[i], neigTile.coord, thisEdges.controlEdges[i], coord);
                        }
                    }
                }
            }
        }
コード例 #4
0
ファイル: Weld.cs プロジェクト: LeJuiceBOX/nvgd-roadtocarsons
        public static void ReadEdges(TileData thisData, EdgesSet thisEdges)
        /// Reads apply data and converts to edges. Edges are ready to use after this stage.
        {
            HeightOutput200.ApplySetData heightDataFull = thisData.ApplyOfType <HeightOutput200.ApplySetData>();
            if (heightDataFull != null)
            {
                thisEdges.heightEdges.ReadFloats2D(heightDataFull.heights2D);
            }

            HeightOutput200.ApplySplitData heightSplitData = thisData.ApplyOfType <HeightOutput200.ApplySplitData>();
            if (heightSplitData != null)
            {
                thisEdges.heightEdges.ReadSplitFloats2D(heightSplitData.heights2DSplits);
            }

                                #if UNITY_2019_1_OR_NEWER
            HeightOutput200.ApplyTexData heightTexData = thisData.ApplyOfType <HeightOutput200.ApplyTexData>();
            if (heightTexData != null)
            {
                thisEdges.heightEdges.ReadRawFloat(heightTexData.texBytes);
            }
                                #endif


            TexturesOutput200.ApplyData texturesData = thisData.ApplyOfType <TexturesOutput200.ApplyData>();
            if (texturesData != null && texturesData.splats != null)
            {
                int numChs = texturesData.splats.GetLength(2);
                if (thisEdges.splatEdges == null || thisEdges.splatEdges.Length != numChs)
                {
                    Array.Resize(ref thisEdges.splatEdges, numChs);
                }

                for (int ch = 0; ch < numChs; ch++)
                {
                    if (thisEdges.splatEdges[ch] == null)
                    {
                        thisEdges.splatEdges[ch] = new Edges(0, 0);
                    }

                    thisEdges.splatEdges[ch].ReadSplats(texturesData.splats, ch);
                }
            }

            ReadEdgesCustom?.Invoke(thisData, thisEdges);

            thisEdges.ready = true;
        }
コード例 #5
0
ファイル: Weld.cs プロジェクト: louis030195/niwrad
        private static void WeldDraftToMain(TerrainTile reference, TerrainTile welded, Coord weldDir)
        /// Lowers edges on welding to main tile
        {
            EdgesSet refEdges  = reference.main.edges;
            EdgesSet weldEdges = welded.draft.edges;

            //loading saved edges big array
            float[] refArr = refEdges.heightEdges.GetArr(weldDir);

            //duplicating neig saved edges short array
            float[] weldArr     = weldEdges.heightEdges.GetArr(-weldDir);
            float[] weldArrCopy = new float[weldArr.Length];
            //Array.Copy(weldArr, weldArrCopy, weldArr.Length); //will be re-filled anyways

            //welding and apply to terrain
            Weld.WeldArrays(refArr, weldArrCopy, lowerOnMismatch: true);

            Weld.ApplyToTerrain(welded.draft.terrain.terrainData, weldArrCopy, -weldDir);
        }
コード例 #6
0
ファイル: Weld.cs プロジェクト: LeJuiceBOX/nvgd-roadtocarsons
        public static void WriteEdges(TileData thisData, EdgesSet thisEdges)
        /// Writes edges back to apply data after they have been changed
        {
            HeightOutput200.ApplySetData heightDataFull = thisData.ApplyOfType <HeightOutput200.ApplySetData>();
            if (heightDataFull != null)
            {
                thisEdges.heightEdges.WriteFloats2D(heightDataFull.heights2D);
            }

            HeightOutput200.ApplySplitData heightSplitData = thisData.ApplyOfType <HeightOutput200.ApplySplitData>();
            if (heightSplitData != null)
            {
                thisEdges.heightEdges.WriteSplitFloats2D(heightSplitData.heights2DSplits);
            }

                                #if UNITY_2019_1_OR_NEWER
            HeightOutput200.ApplyTexData heightTexData = thisData.ApplyOfType <HeightOutput200.ApplyTexData>();
            if (heightTexData != null)
            {
                thisEdges.heightEdges.WriteRawFloat(heightTexData.texBytes);
            }
                                #endif


            TexturesOutput200.ApplyData texturesData = thisData.ApplyOfType <TexturesOutput200.ApplyData>();
            if (texturesData != null && texturesData.splats != null)
            {
                int numChs = texturesData.splats.GetLength(2);
                if (thisEdges.splatEdges == null || thisEdges.splatEdges.Length != numChs)
                {
                    Array.Resize(ref thisEdges.splatEdges, numChs);
                }

                for (int ch = 0; ch < numChs; ch++)
                {
                    thisEdges.splatEdges[ch].WriteSplats(texturesData.splats, ch);
                }
            }

            WriteEdgesCustom?.Invoke(thisData, thisEdges);
        }