diff --git a/modules/video/CMakeLists.txt b/modules/video/CMakeLists.txt index e77d6548b1..34f57f4e88 100644 --- a/modules/video/CMakeLists.txt +++ b/modules/video/CMakeLists.txt @@ -30,6 +30,7 @@ set(HEADER_FILES include/videoplayer.h include/screenspacevideo.h include/renderablevideosphere.h + include/renderablevideoplane.h ) source_group("Header Files" FILES ${HEADER_FILES}) @@ -40,6 +41,7 @@ set(SOURCE_FILES src/videoplayer.cpp src/screenspacevideo.cpp src/renderablevideosphere.cpp + src/renderablevideoplane.cpp ) source_group("Source Files" FILES ${SOURCE_FILES}) diff --git a/modules/video/include/renderablevideoplane.h b/modules/video/include/renderablevideoplane.h new file mode 100644 index 0000000000..cce4d40242 --- /dev/null +++ b/modules/video/include/renderablevideoplane.h @@ -0,0 +1,59 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2023 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#ifndef __OPENSPACE_MODULE_BASE___RENDERABLEVIDEOPLANE___H__ +#define __OPENSPACE_MODULE_BASE___RENDERABLEVIDEOPLANE___H__ + +#include + +#include + +namespace openspace { + +namespace documentation { struct Documentation; } + +class RenderableVideoPlane : public RenderablePlane { +public: + RenderableVideoPlane(const ghoul::Dictionary& dictionary); + + void initializeGL() override; + void deinitializeGL() override; + + bool isReady() const override; + + void render(const RenderData& data, RendererTasks& rendererTask) override; + void update(const UpdateData& data) override; + + static documentation::Documentation Documentation(); + +protected: + virtual void bindTexture() override; + +private: + VideoPlayer _videoPlayer; +}; + +} // namespace openspace + +#endif // __OPENSPACE_MODULE_BASE___RENDERABLEVIDEOPLANE___H__ diff --git a/modules/video/include/renderablevideosphere.h b/modules/video/include/renderablevideosphere.h index b9765fd483..3a029d8c4c 100644 --- a/modules/video/include/renderablevideosphere.h +++ b/modules/video/include/renderablevideosphere.h @@ -88,7 +88,7 @@ private: bool _sphereIsDirty = false; }; - + } // namespace openspace diff --git a/modules/video/src/renderablevideoplane.cpp b/modules/video/src/renderablevideoplane.cpp new file mode 100644 index 0000000000..6826ecdc00 --- /dev/null +++ b/modules/video/src/renderablevideoplane.cpp @@ -0,0 +1,86 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2023 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#include + +#include +#include + +namespace { + struct [[codegen::Dictionary(RenderableVideoPlane)]] Parameters { + + }; +#include "renderablevideoplane_codegen.cpp" +} // namespace + +namespace openspace { + +documentation::Documentation RenderableVideoPlane::Documentation() { + return codegen::doc("renderable_video_plane"); +} + +RenderableVideoPlane::RenderableVideoPlane(const ghoul::Dictionary& dictionary) + : RenderablePlane(dictionary) + , _videoPlayer(dictionary) +{ + const Parameters p = codegen::bake(dictionary); + + addPropertySubOwner(_videoPlayer); +} + +void RenderableVideoPlane::initializeGL() { + RenderablePlane::initializeGL(); + _videoPlayer.initialize(); +} + +void RenderableVideoPlane::deinitializeGL() { + _videoPlayer.destroy(); + RenderablePlane::deinitializeGL(); +} + +bool RenderableVideoPlane::isReady() const { + return RenderablePlane::isReady() && _videoPlayer.isInitialized(); +} + +void RenderableVideoPlane::render(const RenderData& data, RendererTasks& rendererTask) { + if (!_videoPlayer.isInitialized()) { + return; + } + + RenderablePlane::render(data, rendererTask); +} + +void RenderableVideoPlane::update(const UpdateData& data) { + _videoPlayer.update(); + + if (!_videoPlayer.isInitialized()) { + return; + } +} + +void RenderableVideoPlane::bindTexture() { + _videoPlayer.frameTexture()->bind(); +} + +} // namespace openspace diff --git a/modules/video/videomodule.cpp b/modules/video/videomodule.cpp index 95387cf856..2e916ff5f2 100644 --- a/modules/video/videomodule.cpp +++ b/modules/video/videomodule.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -78,6 +79,7 @@ void VideoModule::internalInitialize(const ghoul::Dictionary& dict) { FactoryManager::ref().factory(); ghoul_assert(fRenderable, "Renderable factory was not created"); fRenderable->registerClass("RenderableVideoSphere"); + fRenderable->registerClass("RenderableVideoPlane"); } std::vector VideoModule::documentations() const { @@ -91,7 +93,7 @@ scripting::LuaLibrary VideoModule::luaLibrary() const { return { "video", { - + } }; } diff --git a/modules/video/videoplane.asset b/modules/video/videoplane.asset new file mode 100644 index 0000000000..3ed715053e --- /dev/null +++ b/modules/video/videoplane.asset @@ -0,0 +1,33 @@ +local transforms = asset.require("scene/solarsystem/planets/earth/transforms") + +local plane = { + Identifier = "VideoPlaneVeryCool", + Parent = transforms.EarthCenter.Identifier, + Transform = { + Translation = { + Type = "StaticTranslation", + Position = { 0.0, -11E7, 0.0 } + } + }, + Renderable = { + Type = "RenderableVideoPlane", + MirrorBackside = true, + Size = 3E7, + Video = "C:/Users/malej60/Videos/test/4096-4.mp4", + PlaybackMode = "RealTimeLoop" + }, + GUI = { + Name = "Test Plane Cool", + Path = "/Other/Planes" + } +} + +asset.onInitialize(function() + openspace.addSceneGraphNode(plane) +end) + +asset.onDeinitialize(function() + openspace.removeSceneGraphNode(plane) +end) + +asset.export(plane)