/// <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 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 parent 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(); //******************************** // Create first level childs GenericObject actChild = manipulator.AddGeneric(resPalletGeometry); actChild.Position = new Vector3(-2f, 0f, 0f); actChild.Scaling = new Vector3(0.5f, 0.5f, 0.5f); manipulator.AddChild(palletObject, actChild); actChild = manipulator.AddGeneric(resPalletGeometry); actChild.Position = new Vector3(0f, 0f, 2f); actChild.Scaling = new Vector3(0.5f, 0.5f, 0.5f); manipulator.AddChild(palletObject, actChild); //******************************** // Create second level parent/child relationships GenericObject actSecondLevelParent = manipulator.AddGeneric(resPalletGeometry); 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.AddChild(palletObject, actSecondLevelParent); GenericObject actSecondLevelChild = manipulator.AddGeneric(resPalletGeometry); actSecondLevelChild.Position = new Vector3(1f, 0f, 0f); actSecondLevelChild.Scaling = new Vector3(0.4f, 0.4f, 0.4f); manipulator.AddChild(actSecondLevelParent, actSecondLevelChild); actSecondLevelChild = manipulator.AddGeneric(resPalletGeometry); actSecondLevelChild.Position = new Vector3(-1f, 0f, 0f); actSecondLevelChild.Scaling = new Vector3(0.4f, 0.4f, 0.4f); manipulator.AddChild(actSecondLevelParent, actSecondLevelChild); actSecondLevelChild = manipulator.AddGeneric(resPalletGeometry); actSecondLevelChild.Position = new Vector3(0f, 0f, 1f); actSecondLevelChild.Scaling = new Vector3(0.4f, 0.4f, 0.4f); manipulator.AddChild(actSecondLevelParent, actSecondLevelChild); }); // Configure camera camera.Position = new Vector3(5f, 5f, 5f); 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 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(); }
/// <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(); }
/// <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; // 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(); }