Add RenderableVideoPlane class

This commit is contained in:
Malin E
2023-03-22 16:09:06 +01:00
parent e74e0e4fe8
commit c1e1b8b693
6 changed files with 184 additions and 2 deletions

View File

@@ -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})

View File

@@ -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 <modules/base/rendering/renderableplane.h>
#include <modules/video/include/videoplayer.h>
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__

View File

@@ -88,7 +88,7 @@ private:
bool _sphereIsDirty = false;
};
} // namespace openspace

View File

@@ -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 <modules/video/include/renderablevideoplane.h>
#include <openspace/documentation/documentation.h>
#include <openspace/documentation/verifier.h>
namespace {
struct [[codegen::Dictionary(RenderableVideoPlane)]] Parameters {
};
#include "renderablevideoplane_codegen.cpp"
} // namespace
namespace openspace {
documentation::Documentation RenderableVideoPlane::Documentation() {
return codegen::doc<Parameters>("renderable_video_plane");
}
RenderableVideoPlane::RenderableVideoPlane(const ghoul::Dictionary& dictionary)
: RenderablePlane(dictionary)
, _videoPlayer(dictionary)
{
const Parameters p = codegen::bake<Parameters>(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

View File

@@ -26,6 +26,7 @@
#include <modules/video/include/videotileprovider.h>
#include <modules/video/include/screenspacevideo.h>
#include <modules/video/include/renderablevideosphere.h>
#include <modules/video/include/renderablevideoplane.h>
#include <modules/globebrowsing/src/tileprovider/tileprovider.h>
#include <openspace/util/factorymanager.h>
#include <openspace/documentation/documentation.h>
@@ -78,6 +79,7 @@ void VideoModule::internalInitialize(const ghoul::Dictionary& dict) {
FactoryManager::ref().factory<Renderable>();
ghoul_assert(fRenderable, "Renderable factory was not created");
fRenderable->registerClass<RenderableVideoSphere>("RenderableVideoSphere");
fRenderable->registerClass<RenderableVideoPlane>("RenderableVideoPlane");
}
std::vector<documentation::Documentation> VideoModule::documentations() const {
@@ -91,7 +93,7 @@ scripting::LuaLibrary VideoModule::luaLibrary() const {
return {
"video",
{
}
};
}

View File

@@ -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)