public static bool HasTransform(this Schema.Tile tile)
 {
     if (tile.Transform == null || tile.Transform.Count == 0)
     {
         return(false);
     }
     return(true);
 }
        public static Matrix4x4 UnityTransform(this Schema.Tile tile)
        {
            if (!tile.HasTransform())
            {
                return(Matrix4x4.identity);
            }
            var m = new Matrix4x4();

            m.SetColumn(0, new Vector4((float)tile.Transform[0], (float)tile.Transform[1], (float)tile.Transform[2], (float)tile.Transform[3]));
            m.SetColumn(1, new Vector4((float)tile.Transform[4], (float)tile.Transform[5], (float)tile.Transform[6], (float)tile.Transform[7]));
            m.SetColumn(2, new Vector4((float)tile.Transform[8], (float)tile.Transform[9], (float)tile.Transform[10], (float)tile.Transform[11]));
            m.SetColumn(3, new Vector4((float)tile.Transform[12], (float)tile.Transform[13], (float)tile.Transform[14], (float)tile.Transform[15]));
            return(m);
        }
Example #3
0
        public Unity3DTile(Unity3DTileset tileset, string basePath, Schema.Tile tile, Unity3DTile parent)
        {
            this.hashCode   = (int)Random.Range(0, int.MaxValue);
            this.tileset    = tileset;
            this.tile       = tile;
            this.FrameState = new TileFrameState();
            if (tile.Content != null)
            {
                this.Id = Path.GetFileNameWithoutExtension(tile.Content.Url);
            }
            if (parent != null)
            {
                parent.Children.Add(this);
                this.Depth = parent.Depth + 1;
            }

            // TODO: Consider using a double percision Matrix library for doing 3d tiles root transform calculations
            // Set the local transform for this tile, default to identity matrix
            this.transform = this.tile.UnityTransform();

            var parentTransform = (parent != null) ? parent.computedTransform : Matrix4x4.identity;

            this.computedTransform = parentTransform * this.transform;
            this.BoundingVolume    = CreateBoundingVolume(tile.BoundingVolume, this.computedTransform);
            // TODO: Add 2D bounding volumes

            if (tile.Content != null && tile.Content.BoundingVolume.IsDefined())
            {
                // Non-leaf tiles may have a content bounding-volume, which is a tight-fit bounding volume
                // around only the features in the tile.  This box is useful for culling for rendering,
                // but not for culling for traversing the tree since it does not guarantee spatial coherence, i.e.,
                // since it only bounds features in the tile, not the entire tile, children may be
                // outside of this box.
                this.ContentBoundingVolume = CreateBoundingVolume(tile.Content.BoundingVolume, this.computedTransform);
            }
            else
            {
                // Default to tile bounding volume
                this.ContentBoundingVolume = CreateBoundingVolume(tile.BoundingVolume, this.computedTransform);
            }
            // TODO: Add viewer request volume support
            //if(tile.ViewerRequestVolume != null && tile.ViewerRequestVolume.IsDefined())
            //{
            //    this.viewerRequestVolume = CreateBoundingVolume(tile.ViewerRequestVolume, transform);
            //}

            if (!tile.Refine.HasValue)
            {
                tile.Refine = (parent == null) ? Schema.TileRefine.REPLACE : parent.tile.Refine.Value;
            }

            this.Parent = parent;

            if (this.HasEmptyContent)
            {
                this.ContentState = Unity3DTileContentState.READY;
            }
            else
            {
                ContentState    = Unity3DTileContentState.UNLOADED;
                this.ContentUrl = UriHelper.JoinUrls(basePath, tile.Content.Url);
            }

            this.HasRenderableContent = false;
            this.HasTilesetContent    = false;
        }