/// <summary>
        ///		Tell the SceneNode to update the world bound info it stores.
        /// </summary>
        protected virtual void UpdateBounds()
        {
            // reset bounds
            worldAABB.IsNull           = true;
            worldBoundingSphere.Center = this.DerivedPosition;
            float radius = worldBoundingSphere.Radius = 0;

            // update bounds from attached objects
            foreach (MovableObject obj in objectList.Values)
            {
                // update
                worldAABB.Merge(obj.GetWorldBoundingBox(true));

                radius = MathUtil.Max(obj.BoundingRadius, radius);
            }

            // merge with Children
            foreach (SceneNode child in childNodes.Values)
            {
                // merge our bounding box with that of the child node
                worldAABB.Merge(child.worldAABB);
                radius = MathUtil.Max(child.worldBoundingSphere.Radius, radius);
            }
            worldBoundingSphere.Radius = radius;
        }
Beispiel #2
0
        public void Assign(QueuedSubMesh qsm)
        {
            queuedSubMeshes.Add(qsm);
            // update lod distances
            Mesh   mesh      = qsm.submesh.Parent;
            ushort lodLevels = (ushort)(mesh.IsLodManual ? 1 : mesh.LodLevelCount);

            if (qsm.geometryLodList.Count != lodLevels)
            {
                string msg = string.Format("QueuedSubMesh '{0}' lod count of {1} does not match parent count of {2}",
                                           qsm.submesh.Name, qsm.geometryLodList.Count, lodLevels);
                throw new AxiomException(msg);
            }

            while (lodSquaredDistances.Count < lodLevels)
            {
                lodSquaredDistances.Add(0.0f);
            }
            // Make sure LOD levels are max of all at the requested level
            for (ushort lod = 1; lod < lodLevels; ++lod)
            {
                MeshLodUsage meshLod = qsm.submesh.Parent.GetLodLevel(lod);
                lodSquaredDistances[lod] = Math.Max((float)lodSquaredDistances[lod], meshLod.fromSquaredDepth);
            }

            // update bounds
            // Transform world bounds relative to our center
            AxisAlignedBox localBounds = new AxisAlignedBox(qsm.worldBounds.Minimum - center, qsm.worldBounds.Maximum - center);

            aabb.Merge(localBounds);
            foreach (Vector3 corner in localBounds.Corners)
            {
                boundingRadius = Math.Max(boundingRadius, corner.Length);
            }
        }
Beispiel #3
0
        static void _Create(IContextState context, IEnumerable <IFileGeometry3D> meshes,
                            FileInfo texture, string name, LoadedVisualObject visual)
        {
            List <ElementTag> t    = new List <ElementTag>();
            var            details = new LoadedObjectDetails();
            var            baseTag = ElementTag.New();
            var            index   = 0;
            AxisAlignedBox fullBox = AxisAlignedBox.Zero;

            foreach (var geo in meshes)
            {
                var tag = Create(context, baseTag.WithPrefix(geo.Name ?? index.ToString()),
                                 new GeometryStructures <IFileGeometry3D>(geo), texture, out var box);
                t.Add(tag);
                fullBox                = fullBox.Merge(box.Bounds);
                details.VertexCount   += geo.Positions.Count;
                details.TriangleCount += (geo.Indices.Count / 3);
                index++;
            }

            visual.tags.AddRange(t);
            visual.Details = details;

            var size = fullBox.Size();

            visual.worldX = VisualPolylineObject.Create(context, baseTag.WithPrefix("WorldX"),
                                                        new[] { Vector3.Zero + Vector3.UnitX * size.X * -2f, Vector3.Zero + Vector3.UnitX * size.X * 2f }, V4Colors.Red, false);
            visual.worldX.IsVisible = false;
            visual.worldY           = VisualPolylineObject.Create(context, baseTag.WithPrefix("WorldY"),
                                                                  new[] { Vector3.Zero + Vector3.UnitY * size.Y * -2f, Vector3.Zero + Vector3.UnitY * size.Y * 2f }, V4Colors.Green, false);
            visual.worldY.IsVisible = false;
            visual.worldZ           = VisualPolylineObject.Create(context, baseTag.WithPrefix("WorldZ"),
                                                                  new[] { Vector3.Zero + Vector3.UnitZ * size.Z * -2f, Vector3.Zero + Vector3.UnitZ * size.Z * 2f }, V4Colors.Blue, false);
            visual.worldZ.IsVisible = false;
        }
        /// <summary>
        /// (possibly) increase the bounding box of the forest to include the area of the bounding
        /// box.
        /// </summary>
        /// <param name="treeBox">The AxisAlignedBox that describes the tree or tree group's bounding box</param>
        private void AddBounds(AxisAlignedBox treeBox)
        {
            if (bounds == null)
            {
                bounds = new AxisAlignedBox();
            }

            bounds.Merge(treeBox);

            box = bounds;
        }
Beispiel #5
0
        public void TestMergePoint()
        {
            AxisAlignedBox actual   = new AxisAlignedBox(new Vector3(0, 0, 0), new Vector3(50, 50, 50));
            AxisAlignedBox expected = new AxisAlignedBox(new Vector3(0, 0, 0), new Vector3(150, 150, 150));

            Vector3 point = new Vector3(150, 150, 150);

            actual.Merge(point);

            Assert.AreEqual(expected, actual);
        }
        /// <summary>
        ///     Same as SceneNode, only it doesn't care about children...
        /// </summary>
        protected override void UpdateBounds()
        {
            //update bounds from attached objects
            foreach (MovableObject obj in objectList.Values)
            {
                localAABB.Merge(obj.BoundingBox);

                worldAABB = obj.GetWorldBoundingBox(true);
            }

            if (!worldAABB.IsNull)
            {
                OctreeSceneManager oManager = (OctreeSceneManager)this.creator;
                oManager.UpdateOctreeNode(this);
            }
        }
Beispiel #7
0
        private AxisAlignedBox RetrieveBoundingBoxFromVertices(Entity ent)
        {
            AxisAlignedBox      aabb    = new AxisAlignedBox(Vector3.Zero, Vector3.Zero);
            TriangleListBuilder builder = new TriangleListBuilder();

            builder.AddObject(ent.Mesh, 0);
            List <TriangleVertices> vertices = (List <TriangleVertices>)builder.Build();

            foreach (TriangleVertices tv in vertices)
            {
                foreach (Vector3 v in tv.Vertices)
                {
                    aabb.Merge(v);
                }
            }

            return(aabb);
        }
        protected override void Executing(ISceneSnapshot snapshot)
        {
            var emanager = ContextState.GetEntityManager();

            var world = emanager.GetEntity(snapshot.WorldTag);

            if (!world.Contains <ZoomToAllCompponent>())
            {
                return;
            }

            var fullBox = new AxisAlignedBox();

            foreach (var entity in emanager.GetEntities())
            {
                if (entity.TryGetComponents <GeometryBoundsComponent, TransformComponent, RenderableComponent>
                        (out var box, out var tr, out var renderable) && renderable.IsRenderable)
                {
                    fullBox = fullBox.Merge(box.Bounds.Transform(tr.MatrixWorld));
                }
            }

            var surface     = snapshot.Surface.Size;
            var aspectRatio = surface.Width / surface.Height;

            var size = fullBox.Size();

            var camera = ContextState.GetEntityManager().GetEntity(snapshot.CurrentCameraTag);
            var com    = OrthographicCameraComponent.Clone(camera.GetComponent <OrthographicCameraComponent>());

            var move = Math.Max(Math.Abs(com.LookDirection.X * size.X),
                                Math.Max(Math.Abs(com.LookDirection.Y * size.Y), Math.Abs(com.LookDirection.Z * size.Z)));

            com.Position    = fullBox.Center + com.LookDirection * -move * 10;
            com.RotatePoint = fullBox.Center;
            com.Width       = Math.Max(size.X, Math.Max(size.Y, size.Z)) * aspectRatio;
            com.Scale       = 1;

            camera.UpdateComponent(com);



            world.RemoveComponent <ZoomToAllCompponent>();
        }