Esempio n. 1
0
        public static int[] GetIndexArray(V2i size, List <int> invalidPoints)
        {
            if (invalidPoints != null)
            {
                return(OpcIndices.ComputeIndexArray(size, invalidPoints));
            }

            if (s_indexArrayTable == null)
            {
                s_indexArrayTable = new ConcurrentDictionary <V2i, int[]>();
            }

            lock (s_indexArrayTable)
            {
                int[] indices;
                s_indexArrayTable.TryGetValue(size, out indices);

                if (indices != null)
                {
                    return(indices);
                }
                else
                {
                    Report.Begin("Computing Index Array Table for {0}", size);
                    indices = OpcIndices.ComputeIndexArray(size, invalidPoints);
                    if (!s_indexArrayTable.ContainsKey(size))
                    {
                        s_indexArrayTable.TryAdd(size, indices);
                    }
                    Report.End();

                    return(indices);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Creates normals for the OPC in opcBasePath and saves them as Normals.aara.
        /// </summary>
        public static void BuildNormals(OpcPaths opcPaths, bool overrideExisting = false, IObserver <Tup <float, string> > progress = null, CancellationToken cancelToken = default(CancellationToken))
        {
            var normalFileName = "Normals.aara";

            var posFiles = StorageConfig.GetDirectories(opcPaths.PatchesSubDir)
                           .SelectMany(x => StorageConfig.GetFiles(x))
                           .Where(fileWpath => fileWpath.EndsWith("Positions.aara", StringComparison.OrdinalIgnoreCase));

            foreach (var file in posFiles)
            {
                if (cancelToken.IsCancellationRequested)
                {
                    if (progress != null)
                    {
                        progress.OnNext(Tup.Create(0f, "Building normals cancelled."));
                        progress.OnCompleted();
                    }
                    cancelToken.ThrowIfCancellationRequested();
                }

                var normalsFilePath = Path.Combine(Path.GetDirectoryName(file), normalFileName);

                if (overrideExisting || !StorageConfig.FileExists(normalsFilePath))
                {
                    var posAara  = AaraData.FromFile(file);
                    var tileSize = new V2i(posAara.Size[0], posAara.Size[1]);

                    var posArray = AaraData.ConvertArrayToV3ds[posAara.DataTypeAsSymbol](posAara.LoadElements());

                    var invalidPoints = OpcIndices.GetInvalidPositions(posArray);
                    var indices       = OpcIndices.ComputeIndexArray(tileSize, invalidPoints);
                    var normals       = OpcIndices.GenerateVertexNormals(indices, posArray)
                                        .Select(p => p.ToV3f()).ToArray();

                    WriteV3fArrayAsAara(normalsFilePath, normals, tileSize);
                }

                if (progress != null)
                {
                    progress.OnNext(Tup.Create(1f / posFiles.Count(), ""));
                }
            }

            if (progress != null)
            {
                progress.OnCompleted();
            }
        }
Esempio n. 3
0
        public static int[] GetTriangleStripIndexArray(V2i size)
        {
            if (s_triangleStripIndexArrayTable == null)
            {
                s_triangleStripIndexArrayTable = new ConcurrentDictionary <V2i, int[]>();
            }

            int[] indices;
            s_triangleStripIndexArrayTable.TryGetValue(size, out indices);

            try
            {
                if (indices != null)
                {
                    return(indices);
                }
                else
                {
                    indices = OpcIndices.ComputeTriangleStripIndexArray(size);
                    s_triangleStripIndexArrayTable.TryAdd(size, indices);

                    return(indices);
                }
            }
            catch (ArgumentException)
            {
                return(s_triangleStripIndexArrayTable[size]);
            }

            //if (s_triangleStripIndexArrayTable.ContainsKey(size))
            //    return s_triangleStripIndexArrayTable[size];
            //else
            //{
            //    s_triangleStripIndexArrayTable.Add(size, OpcTile.ComputeTriangleStripIndexArray(size));
            //    return s_triangleStripIndexArrayTable[size];
            //}
        }