Пример #1
0
        public List <SerializableEntityTable> ComputeEntityTables(Dictionary <string, int> stringLookup)
        {
            // Create the new Entity tables
            var tableList = new List <SerializableEntityTable>();

            // Create the geometry table
            {
                var tb = GetTableBuilderOrCreate(TableNames.Geometry);
                tb.Clear();
                // We have to force evaluation because as an enumerable the bounding box could be evaluated 6 times more
                tb.AddField(Geometries.Select(g => AABox.Create(g.Vertices)).ToArray(), "Box");
                tb.AddField(Geometries.Select(g => g.Vertices.Count), "VertexCount");
                tb.AddField(Geometries.Select(g => g.Indices.Count / 3), "FaceCount");
            }

            // TODO: add bounding box information to the nodes

            foreach (var tb in Tables.Values)
            {
                var table = new SerializableEntityTable
                {
                    // Set the table name
                    Name = tb.Name,

                    // Convert the columns to named buffers
                    IndexColumns = tb.IndexColumns
                                   .Select(kv => kv.Value.ToNamedBuffer(kv.Key))
                                   .ToList(),
                    NumericColumns = tb.NumericColumns
                                     .Select(kv => kv.Value.ToNamedBuffer(kv.Key))
                                     .ToList(),
                    StringColumns = tb.StringColumns
                                    .Select(kv => kv.Value
                                            .Select(s => stringLookup[s ?? string.Empty])
                                            .ToArray()
                                            .ToNamedBuffer(kv.Key))
                                    .ToList()
                };

                // Assure that all columns are the same length
                var nRows = -1;
                foreach (var c in table.IndexColumns)
                {
                    var n = c.NumElements();
                    if (nRows < 0)
                    {
                        nRows = n;
                    }
                    else if (nRows != n)
                    {
                        throw new Exception($"Invalid number of rows {n} expected {nRows}");
                    }
                }
                foreach (var c in table.NumericColumns)
                {
                    var n = c.NumElements();
                    if (nRows < 0)
                    {
                        nRows = n;
                    }
                    else if (nRows != n)
                    {
                        throw new Exception($"Invalid number of rows {n} expected {nRows}");
                    }
                }
                foreach (var c in table.StringColumns)
                {
                    var n = c.NumElements();
                    if (nRows < 0)
                    {
                        nRows = n;
                    }
                    else if (nRows != n)
                    {
                        throw new Exception($"Invalid number of rows {n} expected {nRows}");
                    }
                }

                // Properties
                table.Properties = tb.Properties.Select(p => new SerializableProperty
                {
                    EntityIndex = p.EntityId,
                    Name        = stringLookup[p.Name],
                    Value       = stringLookup[p.Value]
                }).ToArray();

                tableList.Add(table);
            }


            return(tableList);
        }
Пример #2
0
 public static AABox BoundingBox(this IScene scene)
 => AABox.Create(scene.AllVertices());
Пример #3
0
 public static AABox NodePositionBoundingBox(this IScene scene)
 => AABox.Create(scene.NodePositions().ToEnumerable());
Пример #4
0
 public static AABox BoundingBox(this IArray <Vector3> vertices)
 => AABox.Create(vertices.ToEnumerable());