Exemplo n.º 1
0
        public override async Task OnStartupAsync(RenderLoop mainRenderLoop, SampleSettings settings)
        {
            mainRenderLoop.EnsureNotNull(nameof(mainRenderLoop));

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

                // Create text geometry
                var textOptions                = TextGeometryOptions.Default;
                textOptions.FontSize           = 50;
                textOptions.MakeVolumetricText = true;
                textOptions.SurfaceVertexColor = Color.Blue;
                textOptions.VolumetricSideSurfaceVertexColor = Color4.CornflowerBlue;
                var resGeometry = manipulator.Add3DTextGeometryResource(
                    $"SeeingSharp 2 {Environment.NewLine} Text3D Sample",
                    textOptions);

                // Create material
                var resMaterial = manipulator.AddStandardMaterialResource();

                // Create text geometry and object
                var textObject  = manipulator.AddMeshObject(resGeometry, resMaterial);
                textObject.YPos = textOptions.VolumetricTextDepth;
            });
        }
        public override async Task OnStartupAsync(RenderLoop mainRenderLoop, SampleSettings settings)
        {
            mainRenderLoop.EnsureNotNull(nameof(mainRenderLoop));

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

                // Create resources
                var resGeometry = manipulator.AddGeometryResource(new CubeGeometryFactory());
                var resMaterial = manipulator.AddStandardMaterialResource(enableShaderGeneratedBorder: true);

                // Create cube object
                var cubeMesh      = new Mesh(resGeometry, resMaterial);
                cubeMesh.Color    = Color4.GreenColor;
                cubeMesh.Position = new Vector3(0f, 0.5f, 0f);
                cubeMesh.BuildAnimationSequence()
                .RotateEulerAnglesTo(new Vector3(0f, EngineMath.RAD_180DEG, 0f), TimeSpan.FromSeconds(2.0))
                .WaitFinished()
                .RotateEulerAnglesTo(new Vector3(0f, EngineMath.RAD_360DEG, 0f), TimeSpan.FromSeconds(2.0))
                .WaitFinished()
                .CallAction(() => cubeMesh.RotationEuler = Vector3.Zero)
                .ApplyAndRewind();
                manipulator.AddObject(cubeMesh);

                // Create cube object
                var wireframeMaterial               = manipulator.AddResource(device => new WireframeMaterialResource());
                var wireframeCube                   = new Mesh(resGeometry, wireframeMaterial);
                wireframeCube.Color                 = Color4.Black;
                wireframeCube.TransformationType    = SpacialTransformationType.TakeFromOtherObject;
                wireframeCube.TransformSourceObject = cubeMesh;
                manipulator.AddObject(wireframeCube);
            });
        }
        /// <summary>
        /// Called when the sample has to startup.
        /// </summary>
        /// <param name="targetRenderLoop">The target render loop.</param>
        /// <returns></returns>
        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);

                    // Create the wall in the middle
                    AppendWallObjectToScene(manipulator);

                    // Now create all pallets
                    AppendPalletObjectsToScene(manipulator);
                });

                // Configure camera
                camera.Position = new Vector3(30f, 30f, 30f);
                camera.Target   = new Vector3(0f, 0f, 0f);
                camera.UpdateCamera();
            }
        }
Exemplo n.º 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;

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

                TextGeometryOptions textOptions = TextGeometryOptions.Default;
                textOptions.FontSize            = 50;
                textOptions.MakeVolumetricText  = true;
                textOptions.SurfaceVertexColor  = Color.Blue;
                textOptions.VolumetricSideSurfaceVertexColor = Color4.CornflowerBlue;

                GenericObject textObject = manipulator.Add3DText($"Seeing# {Environment.NewLine} Text3D Sample", textOptions);
                textObject.YPos          = textOptions.VolumetricTextDepth;
            });

            // Configure camera
            camera.Position       = new Vector3(0.7f, 8.5f, -15f);
            camera.RelativeTarget = new Vector3(0.44f, -0.62f, 0.64f);
            camera.UpdateCamera();
        }
Exemplo n.º 5
0
        public override async Task OnStartupAsync(RenderLoop mainRenderLoop, SampleSettings settings)
        {
            mainRenderLoop.EnsureNotNull(nameof(mainRenderLoop));

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

                // Define texture and material resource
                var resTexture = manipulator.AddTextureResource(
                    new AssemblyResourceLink(this.GetType(),
                                             "SimpleTexture.png"));
                var resMaterials = new[]
                {
                    manipulator.AddStandardMaterialResource(
                        materialDiffuseColor: Color4.White,
                        useVertexColors: false,
                        enableShaderGeneratedBorder: true),
                    manipulator.AddStandardMaterialResource(resTexture),
                    manipulator.AddStandardMaterialResource(
                        materialDiffuseColor: Color4.CornflowerBlue,
                        useVertexColors: false,
                        enableShaderGeneratedBorder: true)
                };

                // Create cube geometry resource
                var resGeometry = manipulator.AddGeometryResource(
                    new CustomGeometryFactory(BuildCustomGeometry));

                // Create cube meshes
                var meshes = new List <Mesh>(3);
                meshes.Add(new Mesh(resGeometry, resMaterials[1])
                {
                    Position = new Vector3(-3f, 0.5f, 0f)
                });
                meshes.Add(new Mesh(resGeometry, resMaterials)
                {
                    Position = new Vector3(0, 0.5f, 0f)
                });
                meshes.Add(new Mesh(resGeometry, resMaterials[0], resMaterials[1])
                {
                    Position = new Vector3(3f, 0.5f, 0f)
                });
                foreach (var actCubeMesh in meshes)
                {
                    var actCubeMeshInner = actCubeMesh;
                    actCubeMeshInner.BuildAnimationSequence()
                    .RotateEulerAnglesTo(new Vector3(0f, EngineMath.RAD_180DEG, 0f), TimeSpan.FromSeconds(2.0))
                    .WaitFinished()
                    .RotateEulerAnglesTo(new Vector3(0f, EngineMath.RAD_360DEG, 0f), TimeSpan.FromSeconds(2.0))
                    .WaitFinished()
                    .CallAction(() => actCubeMeshInner.RotationEuler = Vector3.Zero)
                    .ApplyAndRewind();
                    manipulator.AddObject(actCubeMeshInner);
                }
            });
        }
Exemplo n.º 6
0
        public override Task OnStartupAsync(RenderLoop mainRenderLoop, SampleSettings settings)
        {
            mainRenderLoop.EnsureNotNull(nameof(mainRenderLoop));

            _sampleSettings = (Primitive3DSampleSettings)settings;

            return(Task.CompletedTask);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Applies the given sample to the given RenderLoop.
        /// </summary>
        /// <param name="renderLoop">The render loop.</param>
        /// <param name="sampleDesc">The sample to be applied.</param>
        public SampleBase ApplySample(RenderLoop renderLoop, SampleDescription sampleDesc)
        {
            renderLoop.EnsureNotNull(nameof(renderLoop));
            sampleDesc.EnsureNotNull(nameof(sampleDesc));

            SampleBase sample = Activator.CreateInstance(sampleDesc.SampleClass) as SampleBase;

            sample.OnStartupAsync(renderLoop);
            return(sample);
        }
        public override async Task OnStartupAsync(RenderLoop mainRenderLoop, SampleSettings settings)
        {
            mainRenderLoop.EnsureNotNull(nameof(mainRenderLoop));

            var castedSettings = settings as Direct2DTextureSampleSettings ?? new Direct2DTextureSampleSettings();

            // 2D rendering is made here
            _solidBrush = new SolidBrushResource(Color4.Gray);
            _textFormat = new TextFormatResource("Arial", 36);
            _textBrush  = new SolidBrushResource(Color4.RedColor);

            var d2DDrawingLayer = new Custom2DDrawingLayer(graphics =>
            {
                var d2DRectangle = new RectangleF(10, 10, 236, 236);
                graphics.Clear(Color4.LightBlue);
                graphics.FillRoundedRectangle(
                    d2DRectangle, 30, 30,
                    _solidBrush);

                d2DRectangle.Inflate(-10, -10);
                graphics.DrawText(
                    castedSettings.DisplayText,
                    _textFormat, d2DRectangle, _textBrush);
            });

            // Build 3D scene
            await mainRenderLoop.Scene.ManipulateSceneAsync(manipulator =>
            {
                // Create floor
                this.BuildStandardFloor(
                    manipulator, Scene.DEFAULT_LAYER_NAME);

                // Define Direct2D texture resource
                var resD2DTexture = manipulator.AddResource(
                    _ => new Direct2DTextureResource(d2DDrawingLayer, 256, 256));
                var resD2DMaterial = manipulator.AddStandardMaterialResource(resD2DTexture, enableShaderGeneratedBorder: true);

                // Create cube geometry resource
                var resGeometry = manipulator.AddResource(
                    _ => new GeometryResource(new CubeGeometryFactory()));

                // Create cube object
                var cubeMesh   = new Mesh(resGeometry, resD2DMaterial);
                cubeMesh.Color = Color4.GreenColor;
                cubeMesh.YPos  = 0.5f;
                cubeMesh.BuildAnimationSequence()
                .RotateEulerAnglesTo(new Vector3(0f, EngineMath.RAD_180DEG, 0f), TimeSpan.FromSeconds(2.0))
                .WaitFinished()
                .RotateEulerAnglesTo(new Vector3(0f, EngineMath.RAD_360DEG, 0f), TimeSpan.FromSeconds(2.0))
                .WaitFinished()
                .CallAction(() => cubeMesh.RotationEuler = Vector3.Zero)
                .ApplyAndRewind();
                manipulator.AddObject(cubeMesh);
            });
        }
Exemplo n.º 9
0
        public override Task OnStartupAsync(RenderLoop mainRenderLoop, SampleSettings settings)
        {
            mainRenderLoop.EnsureNotNull(nameof(mainRenderLoop));

            _castedSettings = (RectangleSampleSettings)settings;

            _fillBrush            = new SolidBrushResource(Color4.Gray);
            _fillBrushTransparent = new SolidBrushResource(Color4.Gray, 0.5f);

            return(Task.FromResult <object?>(null));
        }
Exemplo n.º 10
0
        /// <summary>
        /// Called when the sample has to startup.
        /// </summary>
        /// <param name="targetRenderLoop">The target render loop.</param>
        /// <returns></returns>
        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);

                    // Create pallet geometry resource
                    PalletType pType      = new PalletType();
                    pType.ContentColor    = Color4.Transparent;
                    var resPalletGeometry = manipulator.AddResource <GeometryResource>(
                        () => new GeometryResource(pType));

                    // Create pallet object
                    GenericObject palletObject = manipulator.AddGeneric(resPalletGeometry);
                    palletObject.Color         = Color4.GreenColor;
                    palletObject.EnableShaderGeneratedBorder();
                    palletObject.BuildAnimationSequence()
                    .RotateEulerAnglesTo(new Vector3(0f, EngineMath.RAD_180DEG, 0f), TimeSpan.FromSeconds(2.0))
                    .WaitFinished()
                    .RotateEulerAnglesTo(new Vector3(0f, EngineMath.RAD_360DEG, 0f), TimeSpan.FromSeconds(2.0))
                    .WaitFinished()
                    .CallAction(() => palletObject.RotationEuler = Vector3.Zero)
                    .ApplyAndRewind();

                    var resSkyboxTexture = manipulator.AddTexture(
                        new AssemblyResourceLink(
                            typeof(SeeingSharpSampleResources),
                            "Textures.SkyBox.dds"));

                    // Create the skybox on a new layer
                    manipulator.AddLayer("Skybox");
                    SkyboxObject skyboxObject = new SkyboxObject(resSkyboxTexture);
                    manipulator.Add(skyboxObject, "Skybox");
                });

                // Configure camera
                camera.Position = new Vector3(5f, 3f, 5f);
                camera.Target   = new Vector3(0f, 2f, 0f);
                camera.UpdateCamera();
            }
        }
Exemplo n.º 11
0
        public override Task OnStartupAsync(RenderLoop mainRenderLoop, SampleSettings settings)
        {
            mainRenderLoop.EnsureNotNull(nameof(mainRenderLoop));

            _castedSettings = (ImageSampleSettings)settings;

            _bitmap = new StandardBitmapResource(
                new AssemblyResourceLink(
                    this.GetType(),
                    "SimpleImage.png"));

            return(Task.FromResult <object?>(null));
        }
Exemplo n.º 12
0
        private async Task OnStartupAsync_Fallback(RenderLoop targetRenderLoop)
        {
            targetRenderLoop.EnsureNotNull(nameof(targetRenderLoop));

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

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

                // Define texture and material resource
                var resTexture = manipulator.AddTexture(
                    new AssemblyResourceLink(
                        typeof(SeeingSharpSampleResources),
                        "Textures.NoCaptureDevice.png"));
                var resMaterial = manipulator.AddSimpleColoredMaterial(resTexture);

                // Create pallet geometry resource
                PalletType pType      = new PalletType();
                pType.ContentMaterial = resMaterial;
                var resPalletGeometry = manipulator.AddResource <GeometryResource>(
                    () => new GeometryResource(pType));

                // Create pallet object
                GenericObject palletObject = manipulator.AddGeneric(resPalletGeometry);
                palletObject.Color         = Color4.GreenColor;
                palletObject.EnableShaderGeneratedBorder();
                palletObject.BuildAnimationSequence()
                .RotateEulerAnglesTo(new Vector3(0f, EngineMath.RAD_180DEG, 0f), TimeSpan.FromSeconds(2.0))
                .WaitFinished()
                .RotateEulerAnglesTo(new Vector3(0f, EngineMath.RAD_360DEG, 0f), TimeSpan.FromSeconds(2.0))
                .WaitFinished()
                .RotateEulerAnglesTo(new Vector3(0f, 0f, 0f), TimeSpan.FromSeconds(2.0))
                .WaitFinished()
                .CallAction(() => palletObject.RotationEuler = Vector3.Zero)
                .ApplyAndRewind();
            });

            // Configure camera
            camera.Position = new Vector3(2f, 2f, 2f);
            camera.Target   = new Vector3(0f, 0.5f, 0f);
            camera.UpdateCamera();
        }
Exemplo n.º 13
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));

            // Get and configure the camera
            Camera3DBase camera = targetRenderLoop.Camera as PerspectiveCamera3D;

            camera.Position = new Vector3(0f, 5f, -7f);
            camera.Target   = new Vector3(0f, 0f, 0f);
            camera.UpdateCamera();

            // Open the video file
            //  see original vide at: https://www.flickr.com/photos/mlinksva/20939860191/in/photolist-xUofUg-xzKr45-xzKn65-xzhfV1-xPfMqh-wTxmUk-wSd5bL-xwAUF3-wSbSW3-xNqVYR-xNqUyB-xKte5J-xKtbMh-wQKVu5-wQVbiV-wQLHns-xKsHiQ-xvapef-xKsF1y-xMMyY2-xvbbXC-xvb5Xy-xNqkBK-xvb25o-xvafSW-xvb4FW-xKsavw-xMM69V-wQUtWn-xvgDSv-xLW62q-xvbig9-wQL8p7-xMMFog-wQV8CK-wQLGcS-wQLLZY-wQKN9U-xvhorD-xNq5we-xvbh7f-wQU3KF-xLWiZE-xvgVqe-wQKKEq-xvaJN3-xNqjhF-wQUEhH-xKspPw-wQRXGt
            //  Licensed under public domain
            ResourceLink videoLink = new AssemblyResourceLink(
                typeof(SeeingSharpSampleResources),
                "Videos.DummyVideoLandscape.mp4");

            m_videoReader = new AsyncRealtimeVideoReader(videoLink);
            m_videoReader.VideoReachedEnd += (sender, eArgs) =>
            {
                m_videoReader.SetCurrentPosition(TimeSpan.Zero);
            };

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

                // Define texture and resource
                var resVideoTexture = manipulator.AddResource <VideoTextureResource>(
                    () => new VideoTextureResource(m_videoReader));
                var resVideoMaterial = manipulator.AddSimpleColoredMaterial(resVideoTexture, addToAlpha: 1f);
                var geoResource      = manipulator.AddResource <GeometryResource>(
                    () => new GeometryResource(new PalletType(
                                                   palletMaterial: NamedOrGenericKey.Empty,
                                                   contentMaterial: resVideoMaterial)));

                // Add the object
                GenericObject newObject = manipulator.AddGeneric(geoResource);
                newObject.RotationEuler = new Vector3(0f, EngineMath.RAD_90DEG / 2f, 0f);
                newObject.Scaling       = new Vector3(2f, 2f, 2f);
                newObject.EnableShaderGeneratedBorder();
            });
        }
        public override async Task OnStartupAsync(RenderLoop mainRenderLoop, SampleSettings settings)
        {
            mainRenderLoop.EnsureNotNull(nameof(mainRenderLoop));

            _castedSettings = (ObjectFilteringSettings)settings;

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

                // Create material
                var resMaterial = manipulator.AddStandardMaterialResource();

                // Create resources
                var resGeometryCube = manipulator.AddResource(
                    _ => new GeometryResource(new CubeGeometryFactory()));
                var resGeometrySphere = manipulator.AddResource(
                    _ => new GeometryResource(new GeosphereGeometryFactory()));
                var resGeometryPyramid = manipulator.AddResource(
                    _ => new GeometryResource(new PyramidGeometryFactory()));

                // Create all objects and write a simple type name into the Tag1 property
                // We will use this Tag1 property for filter visible objects by the object type
                for (var loop = 0; loop < 3; loop++)
                {
                    var newMesh      = new Mesh(resGeometrySphere, resMaterial);
                    newMesh.Color    = Color4.BlueColor;
                    newMesh.Position = new Vector3(-1.5f, 1f, -1.5f + loop * 1.5f);
                    newMesh.Tag1     = "Sphere";
                    manipulator.AddObject(newMesh);

                    newMesh          = new Mesh(resGeometryCube, resMaterial);
                    newMesh.Color    = Color4.GreenColor;
                    newMesh.Position = new Vector3(0f, 1f, -1.5f + loop * 1.5f);
                    newMesh.Tag1     = "Cube";
                    manipulator.AddObject(newMesh);

                    newMesh          = new Mesh(resGeometryPyramid, resMaterial);
                    newMesh.Color    = Color4.RedColor;
                    newMesh.Position = new Vector3(1.5f, 1f, -1.5f + loop * 1.5f);
                    newMesh.Tag1     = "Pyramid";
                    manipulator.AddObject(newMesh);
                }
            });
        }
Exemplo n.º 15
0
        /// <summary>
        /// Updates all currently active input handlers for the given view.
        /// </summary>
        /// <param name="viewObject">The object of the view control.</param>
        /// <param name="inputHandlers">The collection of input handlers managed by the view object.</param>
        /// <param name="renderLoop">The renderloop used by the view object.</param>
        /// <param name="currentlyDispsoing">Is the view currently disposing?</param>
        internal static void UpdateInputHandlerList(
            IInputEnabledView viewObject,
            List <IInputHandler> inputHandlers,
            RenderLoop renderLoop,
            bool currentlyDispsoing)
        {
            viewObject.EnsureNotNull(nameof(viewObject));
            inputHandlers.EnsureNotNull(nameof(inputHandlers));
            renderLoop.EnsureNotNull(nameof(renderLoop));

            // Clear previous input handlers
            if (inputHandlers.Count > 0)
            {
                foreach (var actHandler in inputHandlers)
                {
                    actHandler.Stop();
                }
                inputHandlers.Clear();
            }

            // Check whether this object is disposed
            if (currentlyDispsoing)
            {
                return;
            }

            // Check for other dependencies
            if ((renderLoop == null) ||
                (renderLoop.Camera == null))
            {
                return;
            }

            // Get all possible input handlers
            inputHandlers.AddRange(GraphicsCore.Current.InputHandlers.GetInputHandler(
                                       viewObject.GetType()));

            // Start them all
            foreach (var actInputHandler in inputHandlers)
            {
                actInputHandler.Start(viewObject);
            }
        }
Exemplo n.º 16
0
        public override async Task OnStartupAsync(RenderLoop mainRenderLoop, SampleSettings settings)
        {
            mainRenderLoop.EnsureNotNull(nameof(mainRenderLoop));

            _castedSettings = (FocusSampleSettings)settings;

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

                var defaultLayer = manipulator.GetLayer(Scene.DEFAULT_LAYER_NAME);

                // Create the focus effect and attach it to a new 'Focus' layer
                var keyPostprocess = manipulator.AddResource(
                    _ => new FocusPostprocessEffectResource());
                var focusLayer = manipulator.AddLayer("Focus");
                focusLayer.PostprocessEffectKey = keyPostprocess;

                var resGeometry = manipulator.AddResource(
                    _ => new GeometryResource(new CubeGeometryFactory()));
                var resMaterial = manipulator.AddStandardMaterialResource();

                var frontMesh      = manipulator.AddMeshObject(resGeometry, defaultLayer.Name, resMaterial);
                frontMesh.Color    = Color4.BlueColor;
                frontMesh.Scaling  = new Vector3(1f, 0.5f, 0.5f);
                frontMesh.Position = new Vector3(1f, 2f, 1f);

                var backMesh           = manipulator.AddMeshObject(resGeometry, defaultLayer.Name, resMaterial);
                backMesh.RotationEuler = new Vector3(0f, EngineMath.RAD_90DEG / 3f, 0f);
                backMesh.Scaling       = new Vector3(2f, 2f, 2f);
                backMesh.Color         = Color4.RedColor;

                // This mesh will render the focus effect itself (it is placed on the focus layer)
                _focusMesh = manipulator.AddMeshObject(resGeometry, focusLayer.Name, resMaterial);
                _focusMesh.TransformSourceObject = backMesh;
                _focusMesh.TransformationType    = SpacialTransformationType.TakeFromOtherObject;
                _focusMesh.Color = Color4.RedColor;
            });
        }
        /// <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;

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

                // Define texture and material resource
                var resTexture = manipulator.AddTexture(
                    new AssemblyResourceLink(
                        typeof(SeeingSharpSampleResources),
                        "Textures.SimpleTexture.png"));
                var resMaterial = manipulator.AddSimpleColoredMaterial(resTexture);

                // Create pallet geometry resource
                PalletType pType      = new PalletType();
                pType.ContentMaterial = resMaterial;
                var resPalletGeometry = manipulator.AddResource <GeometryResource>(
                    () => new GeometryResource(pType));

                // Create pallet object
                CustomPalletObject palletObject = new CustomPalletObject(resPalletGeometry);
                palletObject.Color = Color4.GreenColor;
                palletObject.EnableShaderGeneratedBorder();
                manipulator.Add(palletObject);
            });

            // Configure camera
            camera.Position = new Vector3(0f, 4f, -4f);
            camera.Target   = new Vector3(0f, 0.5f, 0f);
            camera.UpdateCamera();
        }
Exemplo n.º 18
0
        public override async Task OnStartupAsync(RenderLoop mainRenderLoop, SampleSettings settings)
        {
            mainRenderLoop.EnsureNotNull(nameof(mainRenderLoop));

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

                // Create edge detect resource
                var resEdgeDetect = manipulator.AddResource(device => new EdgeDetectPostprocessEffectResource
                {
                    BorderColor = Color4.BlueColor,
                    Thickness   = 5f
                });

                var edgeLayer = manipulator.AddLayer("EdgeDetectLayer");
                edgeLayer.PostprocessEffectKey = resEdgeDetect;

                // Create resources
                var resGeometry = manipulator.AddResource(
                    device => new GeometryResource(new CubeGeometryFactory()));
                var resMaterial = manipulator.AddStandardMaterialResource(enableShaderGeneratedBorder: true);

                // Create object and put it on the EdgeDetectLayer
                var cubeMesh      = new Mesh(resGeometry, resMaterial);
                cubeMesh.Color    = Color4.GreenColor;
                cubeMesh.Position = new Vector3(0f, 0.5f, 0f);
                cubeMesh.BuildAnimationSequence()
                .RotateEulerAnglesTo(new Vector3(0f, EngineMath.RAD_180DEG, 0f), TimeSpan.FromSeconds(2.0))
                .WaitFinished()
                .RotateEulerAnglesTo(new Vector3(0f, EngineMath.RAD_360DEG, 0f), TimeSpan.FromSeconds(2.0))
                .WaitFinished()
                .CallAction(() => cubeMesh.RotationEuler = Vector3.Zero)
                .ApplyAndRewind();
                manipulator.AddObject(cubeMesh, "EdgeDetectLayer");
            });
        }
Exemplo n.º 19
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;

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

                // Create pallet geometry resource
                PalletType pType      = new PalletType();
                pType.ContentColor    = Color4.Transparent;
                var resPalletGeometry = manipulator.AddResource <GeometryResource>(
                    () => new GeometryResource(pType));

                // Create pallet object
                GenericObject palletObject = manipulator.AddGeneric(resPalletGeometry);
                palletObject.Color         = Color4.GreenColor;
                palletObject.EnableShaderGeneratedBorder();
                palletObject.BuildAnimationSequence()
                .RotateEulerAnglesTo(new Vector3(0f, EngineMath.RAD_180DEG, 0f), TimeSpan.FromSeconds(2.0))
                .WaitFinished()
                .RotateEulerAnglesTo(new Vector3(0f, EngineMath.RAD_360DEG, 0f), TimeSpan.FromSeconds(2.0))
                .WaitFinished()
                .CallAction(() => palletObject.RotationEuler = Vector3.Zero)
                .ApplyAndRewind();
            });

            // Configure camera
            camera.Position = new Vector3(2f, 2f, 2f);
            camera.Target   = new Vector3(0f, 0.5f, 0f);
            camera.UpdateCamera();
        }
Exemplo n.º 20
0
        public override async Task OnReloadAsync(RenderLoop mainRenderLoop, SampleSettings settings)
        {
            mainRenderLoop.EnsureNotNull(nameof(mainRenderLoop));

            await mainRenderLoop.Scene.ManipulateSceneAsync(manipulator =>
            {
                // Clear previous scene
                manipulator.Clear();

                // Create floor
                this.BuildStandardFloor(
                    manipulator, Scene.DEFAULT_LAYER_NAME);

                // Create material resource
                NamedOrGenericKey resMaterial;
                if (_sampleSettings !.Textured)
                {
                    var resTexture = manipulator.AddTextureResource(
                        new AssemblyResourceLink(
                            typeof(Primitive3DSampleBase),
                            "PrimitiveTexture.png"));
                    resMaterial = manipulator.AddStandardMaterialResource(resTexture);
                }
Exemplo n.º 21
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();
            }
        }
Exemplo n.º 22
0
        public override async Task OnStartupAsync(RenderLoop mainRenderLoop, SampleSettings settings)
        {
            mainRenderLoop.EnsureNotNull(nameof(mainRenderLoop));

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

                // Create resources
                var resGeometry = manipulator.AddGeometryResource(new CubeGeometryFactory());
                var resMaterial = manipulator.AddStandardMaterialResource(enableShaderGeneratedBorder: true);

                // Create cube object
                var cubeMesh      = new Mesh(resGeometry, resMaterial);
                cubeMesh.Color    = Color4.GreenColor;
                cubeMesh.Position = new Vector3(0f, 0.5f, 0f);
                cubeMesh.BuildAnimationSequence()
                .RotateEulerAnglesTo(new Vector3(0f, EngineMath.RAD_180DEG, 0f), TimeSpan.FromSeconds(2.0))
                .WaitFinished()
                .RotateEulerAnglesTo(new Vector3(0f, EngineMath.RAD_360DEG, 0f), TimeSpan.FromSeconds(2.0))
                .WaitFinished()
                .CallAction(() => cubeMesh.RotationEuler = Vector3.Zero)
                .ApplyAndRewind();
                manipulator.AddObject(cubeMesh);

                var resSkyboxTexture = manipulator.AddTextureResource(
                    new AssemblyResourceLink(this.GetType(),
                                             "SkyBox.dds"));

                // Create the skybox on a new layer
                manipulator.AddLayer("Skybox");
                var skyboxObject = new Skybox(resSkyboxTexture);
                manipulator.AddObject(skyboxObject, "Skybox");
            });
        }
Exemplo n.º 23
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();
            }
        }
Exemplo n.º 24
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 pallet geometry resource
                    PalletType pType      = new PalletType();
                    pType.ContentColor    = Color4.Transparent;
                    var resPalletGeometry = manipulator.AddResource <GeometryResource>(
                        () => new GeometryResource(pType));

                    // Create floor
                    SampleSceneBuilder.BuildStandardFloor(
                        manipulator, Scene.DEFAULT_LAYER_NAME);

                    // Build the wall object
                    AppendWallObjectToScene(manipulator, SIDE_LENGTH);

                    // Trigger building of the pallet stack
                    BuildPalletCubes(manipulator, new NamedOrGenericKey[] { resPalletGeometry }, SIDE_LENGTH);
                });

                // Configure camera
                camera.Position = new Vector3(30f, 30f, 30f);
                camera.Target   = new Vector3(0f, 10f, 0f);
                camera.UpdateCamera();
            }
        }
        /// <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;

            // Define 2D overlay
            m_solidBrush = new SolidBrushResource(Color4.LightSteelBlue.ChangeAlphaTo(0.7f));
            m_textFormat = new TextFormatResource("Arial", 36);
            m_textBrush  = new SolidBrushResource(Color4.RedColor);
            Action <Graphics2D> draw2DAction = (graphics) =>
            {
                // 2D rendering is made here
                RectangleF d2dRectangle = new RectangleF(
                    10, 10,
                    graphics.ScreenSize.Width - 20,
                    graphics.ScreenSize.Height - 20);
                if (d2dRectangle.Width < 100)
                {
                    return;
                }
                if (d2dRectangle.Height < 100)
                {
                    return;
                }

                // Draw background rectangle
                graphics.FillRoundedRectangle(
                    d2dRectangle,
                    30, 30,
                    m_solidBrush);

                // Draw the text
                d2dRectangle.Inflate(-10, -10);
                d2dRectangle.Y = d2dRectangle.Y + 15f;
                graphics.DrawText("Hello Direct2D!", m_textFormat, d2dRectangle, m_textBrush);
            };

            await targetRenderLoop.Scene.ManipulateSceneAsync((manipulator) =>
            {
                // Add the 2D layer to the scene
                manipulator.AddDrawingLayer(draw2DAction);

                // Create floor
                SampleSceneBuilder.BuildStandardFloor(
                    manipulator, Scene.DEFAULT_LAYER_NAME);

                // Create pallet geometry resource
                PalletType pType      = new PalletType();
                pType.ContentColor    = Color4.Transparent;
                var resPalletGeometry = manipulator.AddResource <GeometryResource>(
                    () => new GeometryResource(pType));

                // Create pallet object
                GenericObject palletObject = manipulator.AddGeneric(resPalletGeometry);
                palletObject.Color         = Color4.GreenColor;
                palletObject.EnableShaderGeneratedBorder();
                palletObject.BuildAnimationSequence()
                .RotateEulerAnglesTo(new Vector3(0f, EngineMath.RAD_180DEG, 0f), TimeSpan.FromSeconds(2.0))
                .WaitFinished()
                .RotateEulerAnglesTo(new Vector3(0f, EngineMath.RAD_360DEG, 0f), TimeSpan.FromSeconds(2.0))
                .WaitFinished()
                .CallAction(() => palletObject.RotationEuler = Vector3.Zero)
                .ApplyAndRewind();
            });

            // Configure camera
            camera.Position = new Vector3(2f, 2f, 2f);
            camera.Target   = new Vector3(0f, 0.5f, 0f);
            camera.UpdateCamera();
        }
        /// <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;

            // 2D rendering is made here
            m_solidBrush = new SolidBrushResource(Color4.Gray);
            m_textFormat = new TextFormatResource("Arial", 36);
            m_textBrush  = new SolidBrushResource(Color4.RedColor);
            Custom2DDrawingLayer d2dDrawingLayer = new Custom2DDrawingLayer((graphics) =>
            {
                RectangleF d2dRectangle = new RectangleF(10, 10, 236, 236);
                graphics.Clear(Color4.LightBlue);
                graphics.FillRoundedRectangle(
                    d2dRectangle, 30, 30,
                    m_solidBrush);

                d2dRectangle.Inflate(-10, -10);
                graphics.DrawText("Hello Direct2D!", m_textFormat, d2dRectangle, m_textBrush);
            });

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

                // Define Direct2D texture resource
                var resD2DTexture = manipulator.AddResource <Direct2DTextureResource>(
                    () => new Direct2DTextureResource(d2dDrawingLayer, 256, 256));
                var resD2DMaterial = manipulator.AddSimpleColoredMaterial(resD2DTexture);

                // Create pallet geometry resource
                PalletType pType      = new PalletType();
                pType.PalletMaterial  = NamedOrGenericKey.Empty;
                pType.ContentMaterial = resD2DMaterial;
                var resPalletGeometry = manipulator.AddResource <GeometryResource>(
                    () => new GeometryResource(pType));

                // Create pallet object
                GenericObject palletObject = manipulator.AddGeneric(resPalletGeometry);
                palletObject.Color         = Color4.GreenColor;
                palletObject.EnableShaderGeneratedBorder();
                palletObject.BuildAnimationSequence()
                .RotateEulerAnglesTo(new Vector3(0f, EngineMath.RAD_180DEG, 0f), TimeSpan.FromSeconds(2.0))
                .WaitFinished()
                .RotateEulerAnglesTo(new Vector3(0f, EngineMath.RAD_360DEG, 0f), TimeSpan.FromSeconds(2.0))
                .WaitFinished()
                .CallAction(() => palletObject.RotationEuler = Vector3.Zero)
                .ApplyAndRewind();
            });

            // Configure camera
            camera.Position = new Vector3(2f, 2f, 2f);
            camera.Target   = new Vector3(0f, 0.5f, 0f);
            camera.UpdateCamera();
        }
Exemplo n.º 27
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;

            // Define resources
            m_starBitmap = new StandardBitmapResource(
                new AssemblyResourceLink(
                    typeof(SeeingSharpSampleResources),
                    "Bitmaps.StarColored_128x128.png"));
            m_startBitmapShaded = new GaussianBlurEffectResource(m_starBitmap);
            m_startBitmapShaded.StandardDeviation = 4f;

            // Define 2D overlay
            Action <Graphics2D> draw2DAction = (graphics) =>
            {
                graphics.DrawBitmap(
                    m_starBitmap,
                    new Vector2(10f, 10f),
                    1f,
                    BitmapInterpolationMode.Linear);
                graphics.DrawImage(
                    m_startBitmapShaded,
                    new Vector2(150f, 10f));
            };

            await targetRenderLoop.Scene.ManipulateSceneAsync((manipulator) =>
            {
                // Add the 2D layer to the scene
                manipulator.AddDrawingLayer(draw2DAction);

                // Create floor
                SampleSceneBuilder.BuildStandardFloor(
                    manipulator, Scene.DEFAULT_LAYER_NAME);

                // Create pallet geometry resource
                PalletType pType      = new PalletType();
                pType.ContentColor    = Color4.Transparent;
                var resPalletGeometry = manipulator.AddResource <GeometryResource>(
                    () => new GeometryResource(pType));

                // Create pallet object
                GenericObject palletObject = manipulator.AddGeneric(resPalletGeometry);
                palletObject.Color         = Color4.GreenColor;
                palletObject.EnableShaderGeneratedBorder();
                palletObject.BuildAnimationSequence()
                .RotateEulerAnglesTo(new Vector3(0f, EngineMath.RAD_180DEG, 0f), TimeSpan.FromSeconds(2.0))
                .WaitFinished()
                .RotateEulerAnglesTo(new Vector3(0f, EngineMath.RAD_360DEG, 0f), TimeSpan.FromSeconds(2.0))
                .WaitFinished()
                .CallAction(() => palletObject.RotationEuler = Vector3.Zero)
                .ApplyAndRewind();
            });

            // Configure camera
            camera.Position = new Vector3(2f, 2f, 2f);
            camera.Target   = new Vector3(0f, 0.5f, 0f);
            camera.UpdateCamera();
        }
Exemplo n.º 28
0
        public override async Task OnStartupAsync(RenderLoop mainRenderLoop, SampleSettings settings)
        {
            mainRenderLoop.EnsureNotNull(nameof(mainRenderLoop));

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

                // Create cube geometry resource
                var resCubeGeometry = manipulator.AddGeometryResource(new CubeGeometryFactory());
                var resMaterial     = manipulator.AddStandardMaterialResource(enableShaderGeneratedBorder: true);

                //********************************
                // Create parent object
                var cubeMesh      = new Mesh(resCubeGeometry, resMaterial);
                cubeMesh.Color    = Color4.GreenColor;
                cubeMesh.Position = new Vector3(0f, 0.5f, 0f);
                cubeMesh.BuildAnimationSequence()
                .RotateEulerAnglesTo(new Vector3(0f, EngineMath.RAD_180DEG, 0f), TimeSpan.FromSeconds(2.0))
                .WaitFinished()
                .RotateEulerAnglesTo(new Vector3(0f, EngineMath.RAD_360DEG, 0f), TimeSpan.FromSeconds(2.0))
                .WaitFinished()
                .CallAction(() => cubeMesh.RotationEuler = Vector3.Zero)
                .ApplyAndRewind();
                manipulator.AddObject(cubeMesh);

                //********************************
                // Create first level child
                var actChild      = new Mesh(resCubeGeometry, resMaterial);
                actChild.Position = new Vector3(-2f, 0f, 0f);
                actChild.Scaling  = new Vector3(0.5f, 0.5f, 0.5f);
                manipulator.AddObject(actChild);
                manipulator.AddChildObject(cubeMesh, actChild);

                actChild          = new Mesh(resCubeGeometry, resMaterial);
                actChild.Position = new Vector3(0f, 0f, 2f);
                actChild.Scaling  = new Vector3(0.5f, 0.5f, 0.5f);
                manipulator.AddObject(actChild);
                manipulator.AddChildObject(cubeMesh, actChild);

                //********************************
                // Create second level parent/child relationships
                var actSecondLevelParent      = new Mesh(resCubeGeometry, resMaterial);
                actSecondLevelParent.Position = new Vector3(3f, 0f, 0f);
                actSecondLevelParent.Scaling  = new Vector3(0.8f, 0.8f, 0.8f);
                actSecondLevelParent.Color    = Color4.BlueColor;
                actSecondLevelParent.BuildAnimationSequence()
                .RotateEulerAnglesTo(new Vector3(0f, EngineMath.RAD_180DEG, 0f), TimeSpan.FromSeconds(2.0))
                .WaitFinished()
                .RotateEulerAnglesTo(new Vector3(0f, EngineMath.RAD_360DEG, 0f), TimeSpan.FromSeconds(2.0))
                .WaitFinished()
                .CallAction(() => actSecondLevelParent.RotationEuler = Vector3.Zero)
                .ApplyAndRewind();
                manipulator.AddObject(actSecondLevelParent);
                manipulator.AddChildObject(cubeMesh, actSecondLevelParent);

                var actSecondLevelChild      = new Mesh(resCubeGeometry, resMaterial);
                actSecondLevelChild.Position = new Vector3(1f, 0f, 0f);
                actSecondLevelChild.Scaling  = new Vector3(0.4f, 0.4f, 0.4f);
                manipulator.AddObject(actSecondLevelChild);
                manipulator.AddChildObject(actSecondLevelParent, actSecondLevelChild);

                actSecondLevelChild          = new Mesh(resCubeGeometry, resMaterial);
                actSecondLevelChild.Position = new Vector3(-1f, 0f, 0f);
                actSecondLevelChild.Scaling  = new Vector3(0.4f, 0.4f, 0.4f);
                manipulator.AddObject(actSecondLevelChild);
                manipulator.AddChildObject(actSecondLevelParent, actSecondLevelChild);

                actSecondLevelChild          = new Mesh(resCubeGeometry, resMaterial);
                actSecondLevelChild.Position = new Vector3(0f, 0f, 1f);
                actSecondLevelChild.Scaling  = new Vector3(0.4f, 0.4f, 0.4f);
                manipulator.AddObject(actSecondLevelChild);
                manipulator.AddChildObject(actSecondLevelParent, actSecondLevelChild);
            });
        }
Exemplo n.º 29
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));

            // Start the device chooser
            m_deviceChooser = new CaptureDeviceChooser();

            // Show fallback-scene if we don't have a capture device
            if (m_deviceChooser.DeviceCount <= 0)
            {
                await OnStartupAsync_Fallback(targetRenderLoop);

                return;
            }

            // Get and configure the camera
            Camera3DBase camera = targetRenderLoop.Camera as PerspectiveCamera3D;

            camera.Position = new Vector3(0f, 5f, -7f);
            camera.Target   = new Vector3(0f, 0f, 0f);
            camera.UpdateCamera();

            // Open the video file
            m_videoReader = new AsyncRealtimeVideoReader(m_deviceChooser.DeviceInfos.First());
            m_videoReader.VideoReachedEnd += (sender, eArgs) =>
            {
                m_videoReader.SetCurrentPosition(TimeSpan.Zero);
            };

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

                // Define texture and resource
                var resVideoTexture = manipulator.AddResource <VideoTextureResource>(
                    () => new VideoTextureResource(m_videoReader));
                var resVideoMaterial = manipulator.AddSimpleColoredMaterial(resVideoTexture, addToAlpha: 1f);
                var geoResource      = manipulator.AddResource <GeometryResource>(
                    () => new GeometryResource(new PalletType(
                                                   palletMaterial: NamedOrGenericKey.Empty,
                                                   contentMaterial: resVideoMaterial)));

                // Add the object
                GenericObject newObject = manipulator.AddGeneric(geoResource);
                newObject.RotationEuler = new Vector3(0f, EngineMath.RAD_90DEG / 2f, 0f);
                newObject.Scaling       = new Vector3(2f, 2f, 2f);
                newObject.EnableShaderGeneratedBorder();

                // Start pallet rotating animation
                newObject.BuildAnimationSequence()
                .RotateEulerAnglesTo(new Vector3(0f, EngineMath.RAD_180DEG, 0f), TimeSpan.FromSeconds(2.0))
                .WaitFinished()
                .RotateEulerAnglesTo(new Vector3(0f, EngineMath.RAD_360DEG, 0f), TimeSpan.FromSeconds(2.0))
                .WaitFinished()
                .RotateEulerAnglesTo(new Vector3(0f, 0f, 0f), TimeSpan.FromSeconds(2.0))
                .WaitFinished()
                .CallAction(() => newObject.RotationEuler = Vector3.Zero)
                .ApplyAndRewind();
            });
        }
        public override async Task OnStartupAsync(RenderLoop mainRenderLoop, SampleSettings settings)
        {
            mainRenderLoop.EnsureNotNull(nameof(mainRenderLoop));

            // Whole animation takes x milliseconds
            const float ANIMATION_MILLIS = 3000f;

            // 2D rendering is made here
            _solidBrush        = new SolidBrushResource(Color4.Gray);
            _animatedRectBrush = new SolidBrushResource(Color4.RedColor);

            var d2DDrawingLayer = new Custom2DDrawingLayer(graphics =>
            {
                // Draw the background
                var d2DRectangle = new RectangleF(10, 10, 236, 236);
                graphics.Clear(Color4.LightBlue);
                graphics.FillRoundedRectangle(
                    d2DRectangle, 30, 30,
                    _solidBrush);

                // Recalculate current location of the red rectangle on each frame
                var currentLocation = (float)(DateTime.UtcNow - DateTime.UtcNow.Date).TotalMilliseconds % ANIMATION_MILLIS / ANIMATION_MILLIS;
                var rectPos         = this.GetAnimationLocation(currentLocation, 165f, 165f);
                graphics.FillRectangle(
                    new RectangleF(
                        20f + rectPos.x,
                        20f + rectPos.y,
                        50f, 50f),
                    _animatedRectBrush);
            });

            // Build 3D scene
            await mainRenderLoop.Scene.ManipulateSceneAsync(manipulator =>
            {
                // Create floor
                this.BuildStandardFloor(
                    manipulator, Scene.DEFAULT_LAYER_NAME);

                // Define Direct2D texture resource
                var resD2DTexture = manipulator.AddResource(
                    _ => new Direct2DTextureResource(d2DDrawingLayer, 256, 256));
                var resD2DMaterial = manipulator.AddStandardMaterialResource(resD2DTexture);

                // Create cube geometry resource
                var resGeometry = manipulator.AddResource(
                    _ => new GeometryResource(new CubeGeometryFactory()));

                // Create cube object
                var cubeMesh   = new Mesh(resGeometry, resD2DMaterial);
                cubeMesh.Color = Color4.GreenColor;
                cubeMesh.YPos  = 0.5f;
                cubeMesh.BuildAnimationSequence()
                .RotateEulerAnglesTo(new Vector3(0f, EngineMath.RAD_180DEG, 0f), TimeSpan.FromSeconds(2.0))
                .WaitFinished()
                .RotateEulerAnglesTo(new Vector3(0f, EngineMath.RAD_360DEG, 0f), TimeSpan.FromSeconds(2.0))
                .WaitFinished()
                .CallAction(() => cubeMesh.RotationEuler = Vector3.Zero)
                .ApplyAndRewind();
                manipulator.AddObject(cubeMesh);
            });
        }