public async Task LoadAndRender_ACShadedObject()
        {
            await TestUtilities.InitializeWithGraphicsAsync();

            using (var memRenderTarget = new MemoryRenderTarget(1024, 1024))
            {
                memRenderTarget.ClearColor = Color4.CornflowerBlue;

                // Get and configure the camera
                var camera = (PerspectiveCamera3D)memRenderTarget.Camera;
                camera.Position = new Vector3(-1.5f, 3f, -1.5f);
                camera.Target   = new Vector3(1f, -1f, 1f);
                camera.UpdateCamera();

                // Define scene
                SceneSpacialObject?newMesh = null;
                await memRenderTarget.Scene.ManipulateSceneAsync(manipulator =>
                {
                    var resGeometry = manipulator.AddResource(
                        _ => new GeometryResource(ACFileLoader.ImportGeometry(
                                                      TestUtilities.CreateResourceLink("Models", "ModelShaded.ac"))));
                    var resMaterial = manipulator.AddStandardMaterialResource();

                    newMesh         = manipulator.AddMeshObject(resGeometry, resMaterial);
                    newMesh.Scaling = new Vector3(0.5f, 0.5f, 0.5f);
                });

                await memRenderTarget.Scene.WaitUntilVisibleAsync(newMesh !, memRenderTarget.RenderLoop);

                // Take screenshot
                var screenshot = await memRenderTarget.RenderLoop.GetScreenshotGdiAsync();

                //TestUtilities.DumpToDesktop(screenshot, "Blub.png");

                // Calculate and check difference
                var isNearEqual = BitmapComparison.IsNearEqual(
                    screenshot, TestUtilities.LoadBitmapFromResource("GeometryLoadingAndRendering", "ShadedObject.png"));
                Assert.IsTrue(isNearEqual, "Difference to reference image is to big!");
            }

            // Finishing checks
            Assert.IsTrue(GraphicsCore.Current.MainLoop !.RegisteredRenderLoopCount == 0, "RenderLoops where not disposed correctly!");
        }
Beispiel #2
0
        public async Task LoadAndRender_ACTexturedObject()
        {
            await UnitTestHelper.InitializeWithGrahicsAsync();

            using (MemoryRenderTarget memRenderTarget = new MemoryRenderTarget(1024, 1024))
            {
                memRenderTarget.ClearColor = Color4.CornflowerBlue;

                // Get and configure the camera
                PerspectiveCamera3D camera = memRenderTarget.Camera as PerspectiveCamera3D;
                camera.Position = new Vector3(-1f, 1f, -1f);
                camera.Target   = new Vector3(0f, 0f, 0f);
                camera.UpdateCamera();

                // Define scene
                SceneObject newObject = null;
                await memRenderTarget.Scene.ManipulateSceneAsync((manipulator) =>
                {
                    NamedOrGenericKey geoResource = manipulator.AddResource <GeometryResource>(
                        () => new GeometryResource(ACFileLoader.ImportObjectType(new AssemblyResourceLink(
                                                                                     Assembly.GetExecutingAssembly(),
                                                                                     "SeeingSharp.Tests.Rendering.Ressources.Models",
                                                                                     "ModelTextured.ac"))));

                    newObject = manipulator.AddGeneric(geoResource);
                });

                await memRenderTarget.Scene.WaitUntilVisibleAsync(newObject, memRenderTarget.RenderLoop);

                // Take screenshot
                GDI.Bitmap screenshot = await memRenderTarget.RenderLoop.GetScreenshotGdiAsync();

                //screenshot.DumpToDesktop(TEST_DUMMY_FILE_NAME);

                // Calculate and check difference
                bool isNearEqual = BitmapComparison.IsNearEqual(
                    screenshot, Properties.Resources.ReferenceImage_TexturedObject);
                Assert.True(isNearEqual, "Difference to reference image is to big!");
            }

            // Finishing checks
            Assert.True(GraphicsCore.Current.MainLoop.RegisteredRenderLoopCount == 0, "RenderLoops where not disposed correctly!");
        }
Beispiel #3
0
        /// <summary>
        /// Called when the sample has to startup.
        /// </summary>
        /// <param name="targetRenderLoop">The target render loop.</param>
        public override async Task OnStartupAsync(RenderLoop targetRenderLoop)
        {
            targetRenderLoop.EnsureNotNull(nameof(targetRenderLoop));

            // Build dummy scene
            m_renderLoop = targetRenderLoop;
            Scene        scene  = m_renderLoop.Scene;
            Camera3DBase camera = m_renderLoop.Camera as Camera3DBase;

            // Build scene initially if we are on first load
            if (scene.CountObjects <= 0)
            {
                NamedOrGenericKey resGeometry = NamedOrGenericKey.Empty;

                await scene.ManipulateSceneAsync((manipulator) =>
                {
                    // Create floor
                    SampleSceneBuilder.BuildStandardFloor(
                        manipulator, Scene.DEFAULT_LAYER_NAME);

                    // Define banana object
                    ObjectType bananaType = ACFileLoader.ImportObjectType(
                        new AssemblyResourceLink(
                            typeof(SeeingSharpSampleResources),
                            "Models.Banana.ac"));
                    resGeometry = manipulator.AddGeometry(bananaType);
                });

                // Triggers async object creation
                TriggerAsyncObjectCreation(m_renderLoop, resGeometry);

                // Configure camera
                camera.Position = new Vector3(-10f, 8f, -10f);
                camera.Target   = new Vector3(5f, 0f, 5f);
                camera.UpdateCamera();
            }
        }
Beispiel #4
0
        /// <summary>
        /// Called when the sample has to startup.
        /// </summary>
        /// <param name="targetRenderLoop">The target render loop.</param>
        public override async Task OnStartupAsync(RenderLoop targetRenderLoop)
        {
            targetRenderLoop.EnsureNotNull(nameof(targetRenderLoop));

            // Build dummy scene
            Scene        scene  = targetRenderLoop.Scene;
            Camera3DBase camera = targetRenderLoop.Camera as Camera3DBase;

            // Build scene initially if we are on first load
            if (scene.CountObjects <= 0)
            {
                await scene.ManipulateSceneAsync((manipulator) =>
                {
                    // Create floor
                    SampleSceneBuilder.BuildStandardFloor(
                        manipulator, Scene.DEFAULT_LAYER_NAME);

                    // Load model resource
                    ObjectType modelType = ACFileLoader.ImportObjectType(
                        new AssemblyResourceLink(
                            typeof(SeeingSharpSampleResources),
                            "Models.Penguin.ac"));
                    var resModel = manipulator.AddResource(() => new GeometryResource(modelType));

                    // Create and add an instance to the scene
                    GenericObject modelObject = new GenericObject(resModel);
                    modelObject.Scaling       = new Vector3(10f, 10f, 10f);
                    manipulator.Add(modelObject);
                });

                // Configure camera
                camera.Position = new Vector3(-10f, 20f, 20f);
                camera.Target   = new Vector3(0f, 6f, 0f);
                camera.UpdateCamera();
            }
        }