コード例 #1
0
        public static async Task <FitToCylinderObject3D> Create(IObject3D itemToFit)
        {
            var fitToBounds = new FitToCylinderObject3D();

            using (fitToBounds.RebuildLock())
            {
                using (new CenterAndHeightMantainer(itemToFit))
                {
                    var aabb   = itemToFit.GetAxisAlignedBoundingBox();
                    var bounds = new Object3D()
                    {
                        Visible = false,
                        Color   = new Color(Color.Red, 100),
                        Mesh    = PlatonicSolids.CreateCube()
                    };

                    // add all the children
                    var scaleItem = new Object3D();
                    fitToBounds.Children.Add(scaleItem);
                    scaleItem.Children.Add(itemToFit);
                    fitToBounds.Children.Add(bounds);

                    fitToBounds.Diameter     = Math.Sqrt(aabb.XSize * aabb.XSize + aabb.YSize * aabb.YSize);
                    fitToBounds.boundsSize.Z = aabb.ZSize;

                    fitToBounds.SizeZ = aabb.ZSize;

                    await fitToBounds.Rebuild();
                }
            }

            return(fitToBounds);
        }
コード例 #2
0
        public static async Task <FitToCylinderObject3D> Create(IObject3D itemToFit)
        {
            var fitToBounds = new FitToCylinderObject3D();

            using (fitToBounds.RebuildLock())
            {
                var startingAabb = itemToFit.GetAxisAlignedBoundingBox();

                // add the fit item
                var scaleItem = new Object3D();
                fitToBounds.Children.Add(scaleItem);
                scaleItem.Children.Add(itemToFit);

                // create an object that just represents the bounds in the scene
                var fitBounds = new Object3D()
                {
                    Visible = false,
                    Color   = new Color(Color.Red, 100),
                    Mesh    = PlatonicSolids.CreateCube()
                };
                // add the item that holds the bounds
                fitToBounds.Children.Add(fitBounds);

                fitToBounds.Diameter = Math.Sqrt(startingAabb.XSize * startingAabb.XSize + startingAabb.YSize * startingAabb.YSize);
                fitToBounds.SizeZ    = startingAabb.ZSize;

                fitToBounds.SizeZ = startingAabb.ZSize;

                await fitToBounds.Rebuild();

                var finalAabb = fitToBounds.GetAxisAlignedBoundingBox();
                fitToBounds.Translate(startingAabb.Center - finalAabb.Center);
            }

            return(fitToBounds);
        }