/// <summary> /// Initializes a new instance of the <see cref="VideoTextureResource"/> class. /// </summary> /// <param name="videoSource">The video source.</param> public VideoTextureResource(ResourceLink videoSource) { videoSource.EnsureNotNull(nameof(videoSource)); m_videoReader = new AsyncRealtimeVideoReader(videoSource, immediateStart: true); m_videoReader.VideoReachedEnd += (sender, eArgs) => { m_videoReader.SetCurrentPosition(TimeSpan.Zero); }; m_currentWidth = m_videoReader.FrameSize.Width; m_currentHeight = m_videoReader.FrameSize.Height; m_lastFrameTimestamp = DateTime.MinValue; }
/// <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(); }); }
/// <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(); }); }