Ejemplo n.º 1
0
        public int CollectOpenThemeFillValueFlags(TileTheme theme)
        {
            int flags = 0;
            int index = FindThemeIndex(theme);

            if (index >= 0 && elems[index].OpenTowardsThemes != null)
            {
                foreach (var openTheme in elems[index].OpenTowardsThemes)
                {
                    int otherIndex = FindThemeIndex(openTheme);
                    if (otherIndex >= 0)
                    {
                        int otherFillValue = elems[otherIndex].FillValue;
                        if (otherFillValue > 31)
                        {
                            Debug.LogError("fill value can't be used as a flag, you are either using too many themes or this should be reimplemented!");
                        }
                        else
                        {
                            flags |= 1 << otherFillValue;
                        }
                    }
                }
            }
            return(flags);
        }
Ejemplo n.º 2
0
        public void InitDeferred(NativeList <DataInstance> instanceList, TileTheme theme)
        {
            sourceType = SourceType.FromTheme;

            meshFilters = null;
            meshes      = null;
            matrices    = null;

            deferred         = true;
            deferredHandler  = new Deferred(instanceList);
            immediateHandler = null;

            SourceMeshData = theme.TileThemeCache.MeshData;

            Inited();
        }
Ejemplo n.º 3
0
        public void Init(NativeArray <DataInstance> instanceArray, TileTheme theme)
        {
            sourceType = SourceType.FromTheme;

            meshFilters = null;
            meshes      = null;
            matrices    = null;

            deferred         = false;
            immediateHandler = new Immediate(instanceArray);
            deferredHandler  = null;

            SourceMeshData = theme.TileThemeCache.MeshData;

            Inited();
        }
Ejemplo n.º 4
0
        public int FindThemeIndex(TileTheme theme)
        {
            if (elems != null)
            {
                for (int i = 0; i < elems.Length; ++i)
                {
                    if (elems[i] == null || elems[i].Theme == null)
                    {
                        continue;
                    }

                    if (elems[i].Theme == theme)
                    {
                        return(i);
                    }
                }
            }
            return(-1);
        }
Ejemplo n.º 5
0
        public void Init(DataVolume dataVolume, int yLevel, int fillValue, TileTheme theme, TileThemePalette themePalette, float3 cellSize = default, Settings settings = null)
        {
            Dispose();

            this.cellSize = cellSize;

            if (cellSize.x == 0 && cellSize.y == 0 && cellSize.z == 0)
            {
                this.cellSize = new float3(1, 1, 1);
            }

            theme.Init();
            if (theme.Configs.Length < TileTheme.Type2DConfigCount)
            {
                Debug.LogError("TileMesher theme has less than the required number of configurations! " + theme.ThemeName);
                return;
            }

            Data           = dataVolume;
            ThemePalette   = themePalette;
            FillValue      = fillValue;
            MesherSettings = settings ?? DefaultSettings;

            Theme = theme;

            YLevel = Mathf.Clamp(yLevel, 0, dataVolume.YLength - 1);
            if (YLevel != yLevel)
            {
                Debug.LogError("TileMesher2D yLevel is out of bounds:" + yLevel + " it is clamped!");
            }

            int x = Data.XLength;
            int y = Data.YLength;
            int z = Data.ZLength;

            dataExtents = new Extents(x, y, z);
            tileExtents = new Extents(x + 1, 1, z + 1);

            generationType = GenerationType.FromDataUncached;

            Inited();
        }
Ejemplo n.º 6
0
        private void FillFromFile(Object obj)
        {
            if (obj == null)
            {
                Debug.LogError("Set a Mesh Asset File first!");
                return;
            }

            List <Mesh> meshes = new List <Mesh>();

            string path   = AssetDatabase.GetAssetPath(obj);
            var    assets = AssetDatabase.LoadAllAssetRepresentationsAtPath(path);

            foreach (var asset in assets)
            {
                var mesh = asset as Mesh;
                if (mesh != null)
                {
                    meshes.Add(mesh);
                }
            }

            if (meshes.Count > 0)
            {
                TileTheme theme = (TileTheme)target;
                if (fillOptions.UseOptions)
                {
                    theme.FillBaseVariantsFromMeshList(meshes, fillOptions.filter, fillOptions.configPrefix);
                }
                else
                {
                    theme.FillBaseVariantsFromMeshList(meshes, null, null);
                }
                EditorUtility.SetDirty(theme);
            }
            else
            {
                Debug.LogError("Couldn't find any Mesh sub-asset in given Mesh Asset file:" + path);
            }
        }
Ejemplo n.º 7
0
        protected JobHandle ScheduleDeferredCombineMeshes(NativeList <DataInstance> instanceList, TileTheme theme, JobHandle dependOn)
        {
            combinationBuilder = new MeshCombinationBuilder();
            AddTemp(combinationBuilder);

            combinationBuilder.InitDeferred(instanceList, theme);
            dependOn = combinationBuilder.Start(dependOn);

            return(dependOn);
        }
Ejemplo n.º 8
0
        protected JobHandle ScheduleCombineMeshes(NativeArray <DataInstance> instanceArray, TileTheme theme, JobHandle dependOn)
        {
            combinationBuilder = new MeshCombinationBuilder();
            AddTemp(combinationBuilder);

            combinationBuilder.Init(instanceArray, theme);
            dependOn = combinationBuilder.Start(dependOn);

            return(dependOn);
        }
Ejemplo n.º 9
0
        protected JobHandle ScheduleCombineMeshes(NativeArray <MeshInstance> instanceData, TileTheme theme, JobHandle dependOn)
        {
            var instanceArray = new NativeArray <DataInstance>(instanceData.Length, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);

            AddTemp(instanceArray);

            for (int i = 0; i < instanceData.Length; ++i)
            {
                var data = instanceData[i];
                instanceArray[i] = new DataInstance()
                {
                    dataOffsets = theme.TileThemeCache.GetMeshDataOffset(data.basePieceIndex, data.variantIndex),
                    transform   = instanceData[i].transform
                };
            }

            return(ScheduleCombineMeshes(instanceArray, theme, dependOn));
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Combines the mesh instance array int a single mesh, using the base pieces from the theme.
        /// It merges the submeshes properly (a submesh in the piece will be in the same submesh in the result mesh).
        /// </summary>
        /// <param name="mesh">The result will be generated into this</param>
        /// <param name="instanceData">Input data. NOTE: the MeshInstance structs have to be initialized, except for the mesh field of the CombineInstance struct, this will be set from the theme.</param>
        /// <param name="theme">Theme which provides the base mesh pieces.</param>
        static protected void CombineMeshes(Mesh mesh, NativeArray <MeshInstance> instanceData, TileTheme theme)
        {
            var basePieces = theme.BaseVariants;

            using (var combineList = new NativeList <CombineInstance>(instanceData.Length, Allocator.Temp))
                using (var currentList = new NativeList <CombineInstance>(instanceData.Length, Allocator.Temp))
                {
                    int maxSubMeshCount = 0;
                    for (int i = 0; i < instanceData.Length; ++i)
                    {
                        var data = instanceData[i];

                        if (data.basePieceIndex >= 0)
                        {
                            var variants    = basePieces[data.basePieceIndex].Variants;
                            var variantMesh = variants[data.variantIndex];

                            if (variantMesh != null)
                            {
                                maxSubMeshCount = Mathf.Max(maxSubMeshCount, variantMesh.subMeshCount);
                                for (int subIndex = 0; subIndex < variantMesh.subMeshCount; ++subIndex)
                                {
                                    combineList.Add(new CombineInstance {
                                        transform = data.transform, mesh = variantMesh, subMeshIndex = subIndex
                                    });
                                }
                            }
                        }
                    }

                    CombineInstance[] submeshInstArray = new CombineInstance[maxSubMeshCount];

                    int currentSubIndex = 0;
                    while (combineList.Length > 0 && currentSubIndex < maxSubMeshCount)
                    {
                        currentList.Clear();
                        for (int i = combineList.Length - 1; i >= 0; --i)
                        {
                            if (combineList[i].subMeshIndex == currentSubIndex)
                            {
                                currentList.Add(combineList[i]);
                                combineList.RemoveAtSwapBack(i);
                            }
                        }

                        var subMesh = new Mesh();
                        subMesh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32;
                        subMesh.CombineMeshes(currentList.ToArray(), true, true);
                        submeshInstArray[currentSubIndex] = new CombineInstance {
                            mesh = subMesh
                        };

                        ++currentSubIndex;
                    }

                    mesh.CombineMeshes(submeshInstArray, false, false);
                }
        }
Ejemplo n.º 11
0
 public void Init(DataVolume dataVolume, int yLevel, int fillValue, TileTheme theme, float3 cellSize = default, Settings settings = null)
 {
     Init(dataVolume, yLevel, fillValue, theme, null, cellSize, settings);
 }