Exemplo n.º 1
0
        public static FitToBoundsObject3D_2 Create(IObject3D itemToFit)
        {
            var fitToBounds = new FitToBoundsObject3D_2();
            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.SizeX = aabb.XSize;
            fitToBounds.SizeY = aabb.YSize;
            fitToBounds.SizeZ = aabb.ZSize;

            return(fitToBounds);
        }
Exemplo n.º 2
0
        public override Task Rebuild()
        {
            this.DebugDepth("Rebuild");

            var rebuildLock = RebuildLock();

            return(Task.Run(() =>
            {
                using (new CenterAndHeightMaintainer(this))
                {
                    bool valuesChanged = false;
                    var height = Height.ClampIfNotCalculated(this, .01, 1000000, ref valuesChanged);
                    var nameToWrite = NameToWrite.Value(this);
                    if (string.IsNullOrWhiteSpace(nameToWrite))
                    {
                        Mesh = PlatonicSolids.CreateCube(20, 10, height);
                    }
                    else
                    {
                        Mesh = null;
                        this.Children.Modify(list =>
                        {
                            list.Clear();

                            var offest = 0.0;
                            double pointsToMm = 0.352778;

                            foreach (var letter in nameToWrite.ToCharArray())
                            {
                                var style = new StyledTypeFace(ApplicationController.GetTypeFace(this.Font), PointSize.Value(this));
                                var letterPrinter = new TypeFacePrinter(letter.ToString(), style)
                                {
                                    ResolutionScale = 10
                                };
                                var scaledLetterPrinter = new VertexSourceApplyTransform(letterPrinter, Affine.NewScaling(pointsToMm));

                                list.Add(new Object3D()
                                {
                                    Mesh = VertexSourceToMesh.Extrude(scaledLetterPrinter, this.Height.Value(this)),
                                    Matrix = Matrix4X4.CreateTranslation(offest, 0, 0),
                                    Name = letter.ToString()
                                });

                                offest += letterPrinter.GetSize(letter.ToString()).X *pointsToMm;
                            }
                        });
                    }
                }

                UiThread.RunOnIdle(() =>
                {
                    rebuildLock.Dispose();
                    Invalidate(InvalidateType.DisplayValues);
                    Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Children));
                });
            }));
        }
Exemplo n.º 3
0
        public void AmfFilesSaveObjectProperties()
        {
            AssetObject3D.AssetManager = new AssetManager();

            var scene = new InteractiveScene();

            scene.Children.Add(new Object3D
            {
                Mesh          = PlatonicSolids.CreateCube(20, 20, 20),
                Name          = "test1",
                OutputType    = PrintOutputTypes.Support,
                Color         = Color.Red,
                MaterialIndex = 2,
            });

            scene.Children.Add(new Object3D
            {
                Mesh   = PlatonicSolids.CreateCube(20, 20, 20),
                Name   = "test2",
                Matrix = Matrix4X4.CreateTranslation(30, 0, 0)
            });

            string tempPath = GetSceneTempPath();

            Object3D.AssetsPath = Path.Combine(tempPath, "Assets");

            string filePath = Path.Combine(tempPath, "exportTest.amf");

            scene.SetSelection(scene.Children.ToList());
            AmfDocument.Save(scene.SelectedItem, filePath);

            Assert.IsTrue(File.Exists(filePath));

            IObject3D loadedItem = Object3D.Load(filePath, CancellationToken.None);

            Assert.IsTrue(loadedItem.Children.Count == 2);

            IObject3D item1 = loadedItem.Children.Last();

            Assert.AreEqual("test1", item1.Name);
            Assert.AreEqual(PrintOutputTypes.Support, item1.OutputType);
            Assert.AreEqual(2, item1.MaterialIndex);
            Assert.AreEqual(Color.Red, item1.Color);
            Assert.AreEqual(12, item1.Mesh.Faces.Count);
            var aabb1 = item1.GetAxisAlignedBoundingBox();

            Assert.True(new AxisAlignedBoundingBox(-10, -10, -10, 10, 10, 10).Equals(aabb1, .001));

            IObject3D item2 = loadedItem.Children.First();

            Assert.AreEqual("test2", item2.Name);
            Assert.AreEqual(Color.White, item2.Color);
            Assert.AreEqual(12, item2.Mesh.Faces.Count);
            var aabb2 = item2.GetAxisAlignedBoundingBox();

            Assert.True(new AxisAlignedBoundingBox(20, -10, -10, 40, 10, 10).Equals(aabb2, .001));
        }