private async void OnMainWindow_Loaded(object sender, RoutedEventArgs e) { CtrlRenderPanel.RenderLoop.ClearColor = Color4.CornflowerBlue; // Build scene graph await CtrlRenderPanel.Scene.ManipulateSceneAsync((manipulator) => { // Create pallet geometry resource PalletType pType = new PalletType(); pType.ContentColor = Color4.GreenColor; 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, EngineMath.RAD_45DEG), TimeSpan.FromSeconds(2.0)) .WaitFinished() .RotateEulerAnglesTo(new Vector3(0f, EngineMath.RAD_360DEG, EngineMath.RAD_45DEG), TimeSpan.FromSeconds(2.0)) .WaitFinished() .RotateEulerAnglesTo(new Vector3(0f, 0f, 0f), TimeSpan.FromSeconds(2.0)) .WaitFinished() .CallAction(() => palletObject.RotationEuler = Vector3.Zero) .ApplyAndRewind(); }); // Configure camera Camera3DBase camera = CtrlRenderPanel.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; 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(); }
/// <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(); } }
private async void OnMainPage_Loaded(object sender, RoutedEventArgs e) { if (m_panelPainter != null) { return; } // Attach the painter to the target render panel m_panelPainter = new SeeingSharpPanelPainter(this.RenderTargetPanel); m_panelPainter.RenderLoop.ClearColor = Color4.CornflowerBlue; // Build scene graph await m_panelPainter.Scene.ManipulateSceneAsync((manipulator) => { // Define a BACKGROUND layer and configure layer IDs // => Ensures correct render order SceneLayer bgLayer = manipulator.AddLayer("BACKGROUND"); manipulator.SetLayerOrderID(bgLayer, 0); manipulator.SetLayerOrderID(Scene.DEFAULT_LAYER_NAME, 1); // Add the background texture painter to the BACKGROUND layer var resBackgroundTexture = manipulator.AddTexture( new AssemblyResourceUriBuilder( "SeeingSharp.Tutorials.Introduction03", true, "Assets/Textures/Background.png")); manipulator.Add(new FullscreenTextureObject(resBackgroundTexture), bgLayer.Name); // Create pallet geometry resource PalletType pType = new PalletType(); pType.ContentColor = Color4.GreenColor; var resPalletGeometry = manipulator.AddResource <GeometryResource>( () => new GeometryResource(pType)); // Create pallet object and add it to the scene // => The DEFAULT layer is used by default GenericObject palletObject = manipulator.AddGeneric(resPalletGeometry); palletObject.Color = Color4.GreenColor; palletObject.EnableShaderGeneratedBorder(); palletObject.BuildAnimationSequence() .RotateEulerAnglesTo(new Vector3(0f, EngineMath.RAD_180DEG, EngineMath.RAD_45DEG), TimeSpan.FromSeconds(2.0)) .WaitFinished() .RotateEulerAnglesTo(new Vector3(0f, EngineMath.RAD_360DEG, EngineMath.RAD_45DEG), TimeSpan.FromSeconds(2.0)) .WaitFinished() .RotateEulerAnglesTo(new Vector3(0f, 0f, 0f), TimeSpan.FromSeconds(2.0)) .WaitFinished() .CallAction(() => palletObject.RotationEuler = Vector3.Zero) .ApplyAndRewind(); }); // Configure camera Camera3DBase camera = m_panelPainter.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> /// <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(); } }
/// <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(); }); }
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(); }
/// <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(); }
/// <summary> /// A method that starts the app view. /// </summary> public void Run() { RenderLoop targetRenderLoop = m_mainWindowPainter.RenderLoop; Camera3DBase camera = targetRenderLoop.Camera; // Configure camera camera.Position = new Vector3(-5f, -5f, -5f); camera.Target = new Vector3(0f, 0.5f, 0f); camera.UpdateCamera(); targetRenderLoop.Scene.ManipulateSceneAsync((manipulator) => { // 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.Position = new Vector3(); 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(); }).FireAndForget(); targetRenderLoop.SceneComponents.Add( new FreeMovingCameraComponent()); m_mainWindow.Activate(); m_mainWindow.Dispatcher.ProcessEvents(CoreProcessEventsOption.ProcessUntilQuit); }
/// <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(); }
/// <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(); } }
/// <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(); } }
/// <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; // Create all objects for animation List <Vector2> starLocations = new List <Vector2>(); m_starBitmap = new StandardBitmapResource( new AssemblyResourceLink( typeof(SeeingSharpSampleResources), "Bitmaps.StarColored_128x128.png")); m_borderBrush = new SolidBrushResource(Color4.SteelBlue); Random starCreateRandomizer = new Random(); // 2D rendering is made here Custom2DDrawingLayer d2dDrawingLayer = new Custom2DDrawingLayer((graphics) => { // Draw background RectangleF d2dRectangle = new RectangleF(10, 10, 236, 236); graphics.Clear(Color4.LightBlue); // Dynamically create new stars if ((starLocations.Count < 50) && (starCreateRandomizer.Next(0, 100) <= 70)) { starLocations.Add(new Vector2( (float)starCreateRandomizer.Next(0, 256), -32f)); } // Update and draw all stars for (int loopStar = 0; loopStar < starLocations.Count; loopStar++) { Vector2 actLocation = starLocations[loopStar]; if (actLocation.Y > 270f) { starLocations.RemoveAt(loopStar); loopStar--; continue; } actLocation.Y = actLocation.Y + 4f; starLocations[loopStar] = actLocation; graphics.DrawBitmap( m_starBitmap, new RectangleF( actLocation.X - 16f, actLocation.Y - 16f, 32f, 32f), 0.6f, BitmapInterpolationMode.Linear); } // Draw a simple border graphics.DrawRectangle(graphics.ScreenBounds, m_borderBrush, 2f); }); // 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(); }
/// <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(); }
protected override async void OnLoad(EventArgs e) { base.OnLoad(e); // Attach the painter to the target render panel m_ctrlRenderControl.RenderLoop.ClearColor = Color4.CornflowerBlue; // Build scene graph await m_ctrlRenderControl.Scene.ManipulateSceneAsync((manipulator) => { // Define a BACKGROUND layer and configure layer IDs // => Ensures correct render order SceneLayer bgLayer = manipulator.AddLayer("BACKGROUND"); manipulator.SetLayerOrderID(bgLayer, 0); manipulator.SetLayerOrderID(Scene.DEFAULT_LAYER_NAME, 1); // Add the background texture painter to the BACKGROUND layer var resBackgroundTexture = manipulator.AddTexture( new AssemblyResourceUriBuilder( "SeeingSharp.Tutorials.Introduction04", true, "Assets/Textures/Background.png")); manipulator.Add(new FullscreenTextureObject(resBackgroundTexture), bgLayer.Name); // Create pallet geometry resource PalletType pType = new PalletType(); pType.ContentColor = Color4.GreenColor; var resPalletGeometry = manipulator.AddResource <GeometryResource>( () => new GeometryResource(pType)); // Create pallet object and add it to the scene // => The DEFAULT layer is used by default for (int loopX = 0; loopX < 11; loopX++) { for (int loopY = 0; loopY < 11; loopY++) { GenericObject palletObject = manipulator.AddGeneric(resPalletGeometry); palletObject.Color = Color4.GreenColor; palletObject.Position = new Vector3( -10f + loopX * 2f, -10f + loopY * 2f, 0f); palletObject.Tag1 = $"Pallet (X={loopX}, Y={loopY})"; palletObject.EnableShaderGeneratedBorder(); palletObject.BuildAnimationSequence() .RotateEulerAnglesTo(new Vector3(0f, EngineMath.RAD_180DEG, EngineMath.RAD_45DEG), TimeSpan.FromSeconds(2.0)) .WaitFinished() .RotateEulerAnglesTo(new Vector3(0f, EngineMath.RAD_360DEG, EngineMath.RAD_45DEG), TimeSpan.FromSeconds(2.0)) .WaitFinished() .RotateEulerAnglesTo(new Vector3(0f, 0f, 0f), TimeSpan.FromSeconds(2.0)) .WaitFinished() .CallAction(() => palletObject.RotationEuler = Vector3.Zero) .ApplyAndRewind(); } } }); // Configure camera Camera3DBase camera = m_ctrlRenderControl.Camera; camera.Position = new Vector3(0f, 0f, -25f); camera.Target = new Vector3(0f, 0f, 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)); // 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(); }); }
/// <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(); }