Exemplo n.º 1
0
        public static IEnumerable <CubeBounds> LoadCubeBounds(CubeMetadataContract data, string name, Vector3 cubeSize)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            for (int x = 0; x < data.CubeExists.Length; x++)
            {
                bool[][] xData = data.CubeExists[x];

                for (int y = 0; y < xData.Length; y++)
                {
                    bool[] xyData = xData[y];
                    for (int z = 0; z < xyData.Length; z++)
                    {
                        bool xyzData = xyData[z];

                        if (xyzData)
                        {
                            BoundingBox cubeBoundingBox = new BoundingBox {
                                Min = new Vector3(x, y, z), Max = new Vector3(x + cubeSize.X, y + cubeSize.Y, z + cubeSize.Z)
                            };

                            yield return(new CubeBounds {
                                BoundingBox = cubeBoundingBox, LevelOfDetail = name
                            });
                        }
                    }
                }
            }
        }
        private async Task <List <SetVersionLevelOfDetail> > ExtractDetailLevels(SetMetadataContract setMetadata, Uri baseUrl)
        {
            List <SetVersionLevelOfDetail> detailLevels = new List <SetVersionLevelOfDetail>();

            foreach (int detailLevel in Enumerable.Range(setMetadata.MinimumLod, setMetadata.MaximumLod - setMetadata.MinimumLod + 1))
            {
                string detailLevelName = "L" + detailLevel;

                Uri lodMetadataUri = new Uri(baseUrl, "L" + detailLevel + "/metadata.json");
                CubeMetadataContract cubeMetadata = await this.Deserialize <CubeMetadataContract>(lodMetadataUri);

                OcTree <CubeBounds> octree = MetadataLoader.Load(cubeMetadata, detailLevelName, new Vector3(1, 1, 1));
                octree.UpdateTree();

                Vector3 cubeBounds = cubeMetadata.SetSize;

                ExtentsContract worldBounds        = cubeMetadata.WorldBounds;
                ExtentsContract virtualWorldBounds = cubeMetadata.VirtualWorldBounds;

                SetVersionLevelOfDetail currentSetLevelOfDetail = new SetVersionLevelOfDetail();
                currentSetLevelOfDetail.Metadata    = lodMetadataUri;
                currentSetLevelOfDetail.Number      = detailLevel;
                currentSetLevelOfDetail.Cubes       = octree;
                currentSetLevelOfDetail.ModelBounds = new BoundingBox(
                    new Vector3(worldBounds.XMin, worldBounds.YMin, worldBounds.ZMin),
                    new Vector3(worldBounds.XMax, worldBounds.YMax, worldBounds.ZMax));

                if (virtualWorldBounds != null)
                {
                    currentSetLevelOfDetail.WorldBounds =
                        new BoundingBox(
                            new Vector3(virtualWorldBounds.XMin, virtualWorldBounds.YMin, virtualWorldBounds.ZMin),
                            new Vector3(virtualWorldBounds.XMax, virtualWorldBounds.YMax, virtualWorldBounds.ZMax));
                }
                else
                {
                    currentSetLevelOfDetail.WorldBounds = new BoundingBox(
                        new Vector3(worldBounds.XMin, worldBounds.YMin, worldBounds.ZMin),
                        new Vector3(worldBounds.XMax, worldBounds.YMax, worldBounds.ZMax));
                }

                currentSetLevelOfDetail.SetSize     = new Vector3(cubeBounds.X, cubeBounds.Y, cubeBounds.Z);
                currentSetLevelOfDetail.Name        = "L" + detailLevel.ToString(CultureInfo.InvariantCulture);
                currentSetLevelOfDetail.VertexCount = cubeMetadata.VertexCount;

                currentSetLevelOfDetail.TextureTemplate = new Uri(lodMetadataUri, "texture/{x}_{y}.jpg");
                currentSetLevelOfDetail.ModelTemplate   = new Uri(lodMetadataUri, "{x}_{y}_{z}.{format}");

                currentSetLevelOfDetail.TextureSetSize = cubeMetadata.TextureSetSize;

                detailLevels.Add(currentSetLevelOfDetail);
            }
            return(detailLevels);
        }
Exemplo n.º 3
0
        public static OcTree <CubeBounds> Load(CubeMetadataContract data, OcTree <CubeBounds> ocTree, string name, Vector3 cubeSize)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            if (ocTree == null)
            {
                throw new ArgumentNullException("ocTree");
            }

            ocTree.Add(LoadCubeBounds(data, name, cubeSize));

            return(ocTree);
        }
Exemplo n.º 4
0
 public static OcTree <CubeBounds> Load(CubeMetadataContract data, string name, Vector3 cubeSize)
 {
     return(Load(data, new OcTree <CubeBounds>(), name, cubeSize));
 }
        private async Task <List <SetVersionLevelOfDetail> > ExtractDetailLevels2(SetMetadataContract setMetadata, Uri baseUrl)
        {
            OcTree <CubeBounds> ocTree = new OcTree <CubeBounds>();

            List <LoaderSet> lods = new List <LoaderSet>();

            foreach (int detailLevel in Enumerable.Range(setMetadata.MinimumLod, setMetadata.MaximumLod - setMetadata.MinimumLod + 1))
            {
                // Allow exceptions to propagate here for logging in ELMAH
                string detailLevelName            = "L" + detailLevel;
                Uri    lodMetadataUri             = new Uri(baseUrl, detailLevelName + "/metadata.json");
                CubeMetadataContract cubeMetadata = await this.Deserialize <CubeMetadataContract>(lodMetadataUri);

                lods.Add(new LoaderSet {
                    CubeMetadataContract = cubeMetadata, Name = detailLevelName, DetailLevel = detailLevel, MetadataUrl = lodMetadataUri
                });
            }

            Vector3 maxSetSize = new Vector3(0, 0, 0);

            foreach (var loaderSet in lods)
            {
                if (loaderSet.CubeMetadataContract.SetSize.X > maxSetSize.X)
                {
                    maxSetSize.X = loaderSet.CubeMetadataContract.SetSize.X;
                }

                if (loaderSet.CubeMetadataContract.SetSize.Y > maxSetSize.Y)
                {
                    maxSetSize.Y = loaderSet.CubeMetadataContract.SetSize.Y;
                }

                if (loaderSet.CubeMetadataContract.SetSize.Z > maxSetSize.Z)
                {
                    maxSetSize.Z = loaderSet.CubeMetadataContract.SetSize.Z;
                }
            }

            List <SetVersionLevelOfDetail> detailLevels = new List <SetVersionLevelOfDetail>();

            foreach (LoaderSet loaderSet in lods)
            {
                var cubeMetadata = loaderSet.CubeMetadataContract;

                Vector3 cubeSize = maxSetSize / loaderSet.CubeMetadataContract.SetSize;

                ocTree.Add(MetadataLoader.LoadCubeBounds(loaderSet.CubeMetadataContract, loaderSet.Name, cubeSize));

                Vector3 cubeBounds = cubeMetadata.SetSize;

                ExtentsContract worldBounds        = cubeMetadata.WorldBounds;
                ExtentsContract virtualWorldBounds = cubeMetadata.VirtualWorldBounds;

                SetVersionLevelOfDetail currentSetLevelOfDetail = new SetVersionLevelOfDetail();
                currentSetLevelOfDetail.Metadata    = loaderSet.MetadataUrl;
                currentSetLevelOfDetail.Number      = loaderSet.DetailLevel;
                currentSetLevelOfDetail.Cubes       = ocTree;
                currentSetLevelOfDetail.ModelBounds = new BoundingBox(
                    new Vector3(worldBounds.XMin, worldBounds.YMin, worldBounds.ZMin),
                    new Vector3(worldBounds.XMax, worldBounds.YMax, worldBounds.ZMax));

                if (virtualWorldBounds != null)
                {
                    currentSetLevelOfDetail.WorldBounds =
                        new BoundingBox(
                            new Vector3(virtualWorldBounds.XMin, virtualWorldBounds.YMin, virtualWorldBounds.ZMin),
                            new Vector3(virtualWorldBounds.XMax, virtualWorldBounds.YMax, virtualWorldBounds.ZMax));
                }
                else
                {
                    currentSetLevelOfDetail.WorldBounds = new BoundingBox(
                        new Vector3(worldBounds.XMin, worldBounds.YMin, worldBounds.ZMin),
                        new Vector3(worldBounds.XMax, worldBounds.YMax, worldBounds.ZMax));
                }

                currentSetLevelOfDetail.SetSize     = new Vector3(cubeBounds.X, cubeBounds.Y, cubeBounds.Z);
                currentSetLevelOfDetail.Name        = "L" + loaderSet.DetailLevel.ToString(CultureInfo.InvariantCulture);
                currentSetLevelOfDetail.VertexCount = cubeMetadata.VertexCount;

                currentSetLevelOfDetail.TextureTemplate = new Uri(loaderSet.MetadataUrl, "texture/{x}_{y}.jpg");
                currentSetLevelOfDetail.ModelTemplate   = new Uri(loaderSet.MetadataUrl, "{x}_{y}_{z}.{format}");

                currentSetLevelOfDetail.TextureSetSize = cubeMetadata.TextureSetSize;

                detailLevels.Add(currentSetLevelOfDetail);
            }

            ocTree.UpdateTree();

            return(detailLevels);
        }