示例#1
0
        private static Record3D CreateThunderbirdsRocket()
        {
            var context = new Record3D();

            ThunderbirdRocket.DrawTo(context);
            return(context);
        }
示例#2
0
        protected Record3D(Record3D other)
        {
            _Commands.Set(other._Commands);
            _GlobalStyle = other._GlobalStyle?.Clone();

            // whenever the original or the clone changes,
            // this will be refreshed, so it's safe to share.
            _ImmutableKey = other._ImmutableKey;
        }
示例#3
0
        public void DrawVolumes()
        {
            var scene = new Record3D();

            scene.DrawPivot(System.Numerics.Matrix4x4.Identity, 2);
            scene.DrawCube(System.Numerics.Matrix4x4.CreateTranslation(5, 0, 0), Color.Red, Color.Green, Color.Blue);
            scene.DrawCube(System.Numerics.Matrix4x4.CreateTranslation(7, 0, 0), (Color.Black, 0.1f));

            var doc = new PlotlyDocumentBuilder().Draw(scene);

            AttachmentInfo.From("Drawing.html").WriteAllText(doc.ToHtml());
        }
示例#4
0
        public static CameraView3D CreateLookingAt(Record3D scene, XYZ direction)
        {
            if (direction == XYZ.Zero)
            {
                direction = -XYZ.UnitZ;
            }

            direction = XYZ.Normalize(direction);

            throw new NotImplementedException();

            // var bounds = scene.SphereBounds;

            // return CreatePerspective(bounds.Center - direction * bounds.Radius * 2, bounds.Center);
        }
示例#5
0
        public static Record3D CreateSideBySideSpheres()
        {
            var      record = new Record3D();
            IScene3D dc     = record;

            for (int i = 0; i < 2; ++i)
            {
                int x = -5 + i * 10;

                dc.DrawSphere((x, 0, -5), 8, (COLOR.Red, COLOR.Blue, 1));
                dc.DrawSphere((x, 0, 5), 8, COLOR.Red);

                dc = new Transforms.Decompose3D(record, 5, 3);
            }

            return(record);
        }
示例#6
0
        public void TestClipScene3D(string sceneName)
        {
            var srcScene = SceneFactory.CreateRecord3D(sceneName);

            var bounds = srcScene.BoundingMatrix;

            for (int i = -1; i <= 1; ++i)
            {
                var dstScene = new Record3D();

                srcScene.DrawTo(new PlaneClip3D(dstScene, new Plane(Vector3.UnitX, i)));

                bounds = dstScene.BoundingMatrix;

                dstScene.AttachToCurrentTest($"{sceneName}_{i}.glb");
                dstScene.AttachToCurrentTest($"{sceneName}_{i}.html");
            }
        }
示例#7
0
        public static string AttachToCurrentTest(this Record3D batch, string filePath)
        {
            var ainfo = NUnit.Framework.AttachmentInfo.From(filePath);

            if (filePath.ToLower().EndsWith(".stl"))
            {
                throw new NotImplementedException();

                /*
                 * var mb = new Backends.STLMeshBuilder();
                 * batch.DrawTo(mb);
                 * var wfcontent = mb.ToAsciiSTL();
                 * System.IO.File.WriteAllText(filePath, wfcontent);
                 * NUnit.Framework.TestContext.AddTestAttachment(filePath);
                 * return;
                 */
            }

            if (filePath.ToLower().EndsWith(".html"))
            {
                var html = PlotlyDocumentBuilder.ConvertToHtml(batch);
                ainfo.WriteAllText(html);
            }

            if (filePath.ToLower().EndsWith(".InteropDrawing"))
            {
            }

            if (filePath.ToLower().EndsWith(".gltf") || filePath.ToLower().EndsWith(".glb") || filePath.ToLower().EndsWith(".obj"))
            {
                var model = GltfSceneBuilder
                            .Convert(batch)
                            .ToGltf2();

                ainfo.WriteObject(f => model.Save(f));
            }

            return(filePath);
        }
示例#8
0
        private static Record3D CreateDNAScene()
        {
            var target = new Record3D();

            for (int i = 0; i < 20; ++i)
            {
                var angle = (float)i / 3;

                var x = (float)Math.Cos(angle) * 10;
                var z = (float)Math.Sin(angle) * 10;
                var y = 10 + i * 10;

                target.DrawSphere(new Vector3(x, y, z), 2, COLOR.SkyBlue);
                target.DrawSphere(new Vector3(-x, y, -z), 2, COLOR.Violet);

                x *= 0.5f;
                z *= 0.5f;

                target.DrawSegment(new Vector3(x, y, z), new Vector3(-x, y, -z), 0.5f, (COLOR.Blue, LineCapStyle.Triangle, LineCapStyle.Triangle));
            }

            return(target);
        }
示例#9
0
        private static Record3D CreateDefaultScene1()
        {
            var context = new Record3D();

            context.DrawPivot(Matrix4x4.CreateTranslation(-10, 0, -10), 2);

            float diamenter = 1;

            context.DrawSegment(Vector3.Zero, Vector3.One * 3, diamenter, (COLOR.White, LineCapStyle.Triangle, LineCapStyle.Triangle));
            context.DrawSegment(Vector3.One * 3, Vector3.UnitX * 7, diamenter, COLOR.Blue);
            context.DrawSegment(Vector3.One * 3, Vector3.One * 3, diamenter, COLOR.Black);

            context.DrawSurface((COLOR.Red.WithAlpha(180), COLOR.Yellow, 0.25f), new Vector3(-1, 0, 10), new Vector3(1, 0, 10), new Vector3(0, 1, 10));

            context.DrawSegment(Vector3.Zero, Vector3.UnitX * 7, diamenter, COLOR.Violet);

            context.DrawSegment(new Vector3(9, 0, 0), new Vector3(9, 10, 0), diamenter, ((COLOR.Red, COLOR.Black, 0.1f), LineCapStyle.Round, LineCapStyle.Round));
            context.DrawSphere(new Vector3(-9, 0, 0), 2, (COLOR.Red, COLOR.Blue, 0.1f));

            // degenerated line falls back to sphere
            context.DrawSegment(new Vector3(0, 9, 0), new Vector3(0, 9, 0), 2, COLOR.Yellow);

            return(context);
        }
示例#10
0
        public void TestPaintersAlgorythmPipeline(string sceneName)
        {
            var scene = new Record3D();

            scene.DrawFloorXZ((-50, 0, -50), (100, 100), 10, COLOR.Green, COLOR.DarkGreen);
            scene.DrawAsset(Matrix4x4.CreateTranslation(0, 5, -10), SceneFactory.CreateRecord3D(sceneName));
            // scene.DrawAsset(Matrix4x4.CreateTranslation(0, 5, 0), SceneFactory.CreateRecord3D(sceneName));
            scene.AttachToCurrentTest("scene.glb");
            scene.AttachToCurrentTest("scene.html");

            // render scene with WPF

            var renderTarget = new WPFRenderTarget(1024, 1024);

            renderTarget.Draw(dc =>
            {
                PerspectiveTransform
                .CreateLookingAtCenter((dc, 1024, 1024), (10, 5, 30))
                .DrawScene(scene);
            });

            AttachmentInfo
            .From($"WPF_{sceneName}.png")
            .WriteObject(f => renderTarget.SaveToPNG(f));

            // render with MemoryBitmap

            var mem = new Bitmaps.MemoryBitmap(1024, 1024, Bitmaps.Pixel.RGBA32.Format);
            var mdc = Backends.InteropDrawing.CreateDrawingContext(mem);

            PerspectiveTransform
            .CreateLookingAtCenter((mdc, 1024, 1024), (10, 5, 30))
            .DrawScene(scene);

            mem.Save(new AttachmentInfo($"Span_{sceneName}.png"));
        }