コード例 #1
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;
        }
コード例 #2
0
        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>();
        }