|
|
|
@ -6,15 +6,17 @@
|
|
|
|
|
#include <osg/Texture2D>
|
|
|
|
|
#include <osg/ClipNode>
|
|
|
|
|
#include <osg/FrontFace>
|
|
|
|
|
#include <osg/BlendFunc>
|
|
|
|
|
#include <osg/Depth>
|
|
|
|
|
#include <components/sceneutil/visitor.hpp>
|
|
|
|
|
#include <components/sceneutil/shadow.hpp>
|
|
|
|
|
#include <osgViewer/Renderer>
|
|
|
|
|
#include "../mwrender/util.hpp"
|
|
|
|
|
#include "../mwrender/renderbin.hpp"
|
|
|
|
|
|
|
|
|
|
namespace MWVR
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Menus : public osg::Camera
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
@ -22,16 +24,17 @@ public:
|
|
|
|
|
{
|
|
|
|
|
setRenderOrder(osg::Camera::PRE_RENDER);
|
|
|
|
|
setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
|
|
|
// Give bg a tint of green just to stand out, for testing
|
|
|
|
|
setClearColor(osg::Vec4(0.f,0.f,0.f,.75f));
|
|
|
|
|
setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);
|
|
|
|
|
setReferenceFrame(osg::Camera::ABSOLUTE_RF);
|
|
|
|
|
setSmallFeatureCullingPixelSize(Settings::Manager::getInt("small feature culling pixel size", "Water"));
|
|
|
|
|
setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);
|
|
|
|
|
setName("ReflectionCamera");
|
|
|
|
|
setName("MenuCamera");
|
|
|
|
|
|
|
|
|
|
setCullMask(MWRender::Mask_GUI);
|
|
|
|
|
setNodeMask(MWRender::Mask_RenderToTexture);
|
|
|
|
|
|
|
|
|
|
unsigned int rttSize = 1000;
|
|
|
|
|
unsigned int rttSize = 4000;
|
|
|
|
|
setViewport(0, 0, rttSize, rttSize);
|
|
|
|
|
|
|
|
|
|
// No need for Update traversal since the mSceneRoot is already updated as part of the main scene graph
|
|
|
|
@ -40,23 +43,18 @@ public:
|
|
|
|
|
|
|
|
|
|
mMenuTexture = new osg::Texture2D;
|
|
|
|
|
mMenuTexture->setTextureSize(rttSize, rttSize);
|
|
|
|
|
mMenuTexture->setInternalFormat(GL_RGB);
|
|
|
|
|
mMenuTexture->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR);
|
|
|
|
|
mMenuTexture->setInternalFormat(GL_RGBA);
|
|
|
|
|
mMenuTexture->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR_MIPMAP_LINEAR);
|
|
|
|
|
mMenuTexture->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR);
|
|
|
|
|
mMenuTexture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE);
|
|
|
|
|
mMenuTexture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
attach(osg::Camera::COLOR_BUFFER, mMenuTexture);
|
|
|
|
|
|
|
|
|
|
// XXX: should really flip the FrontFace on each renderable instead of forcing clockwise.
|
|
|
|
|
//osg::ref_ptr<osg::FrontFace> frontFace(new osg::FrontFace);
|
|
|
|
|
//frontFace->setMode(osg::FrontFace::CLOCKWISE);
|
|
|
|
|
//getOrCreateStateSet()->setAttributeAndModes(frontFace, osg::StateAttribute::ON);
|
|
|
|
|
|
|
|
|
|
//mClipCullNode = new ClipCullNode;
|
|
|
|
|
//addChild(mClipCullNode);
|
|
|
|
|
|
|
|
|
|
SceneUtil::ShadowManager::disableShadowsForStateSet(getOrCreateStateSet());
|
|
|
|
|
getOrCreateStateSet()->setRenderBinDetails(-1, "RenderBin");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setScene(osg::Node* scene)
|
|
|
|
@ -65,6 +63,7 @@ public:
|
|
|
|
|
removeChild(mScene);
|
|
|
|
|
mScene = scene;
|
|
|
|
|
addChild(scene);
|
|
|
|
|
Log(Debug::Verbose) << "Set new scene: " << mScene->getName();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
osg::Texture2D* getMenuTexture() const
|
|
|
|
@ -127,29 +126,27 @@ private:
|
|
|
|
|
osg::ref_ptr<osg::Vec3Array> normals{ new osg::Vec3Array(1) };
|
|
|
|
|
osg::ref_ptr<osg::Vec4Array> colors{ new osg::Vec4Array(1) };
|
|
|
|
|
|
|
|
|
|
extent_meters *= OpenXREnvironment::get().unitsPerMeter() / 2.f;
|
|
|
|
|
// Units are divided by 2 because geometry has an extent of 2 (-1 to 1)
|
|
|
|
|
auto extent_units = extent_meters * OpenXREnvironment::get().unitsPerMeter() / 2.f;
|
|
|
|
|
|
|
|
|
|
float w = extent_meters.x();
|
|
|
|
|
float h = extent_meters.y();
|
|
|
|
|
|
|
|
|
|
osg::Vec3 top_left (-w, h, 1);
|
|
|
|
|
osg::Vec3 bottom_left(-w, -h, 1);
|
|
|
|
|
osg::Vec3 bottom_right(w, -h, 1);
|
|
|
|
|
osg::Vec3 top_right (w, h, 1);
|
|
|
|
|
osg::Vec3 top_left (-1, 1, 1);
|
|
|
|
|
osg::Vec3 bottom_left(-1, -1, 1);
|
|
|
|
|
osg::Vec3 bottom_right(1, -1, 1);
|
|
|
|
|
osg::Vec3 top_right (1, 1, 1);
|
|
|
|
|
(*vertices)[0] = top_left;
|
|
|
|
|
(*vertices)[1] = bottom_left;
|
|
|
|
|
(*vertices)[2] = bottom_right;
|
|
|
|
|
(*vertices)[3] = top_right;
|
|
|
|
|
mGeometry->setVertexArray(vertices);
|
|
|
|
|
(*texCoords)[0].set(0.0f, 0.0f);
|
|
|
|
|
(*texCoords)[1].set(1.0f, 0.0f);
|
|
|
|
|
(*texCoords)[2].set(1.0f, 1.0f);
|
|
|
|
|
(*texCoords)[3].set(0.0f, 1.0f);
|
|
|
|
|
(*texCoords)[0].set(0.0f, 1.0f);
|
|
|
|
|
(*texCoords)[1].set(0.0f, 0.0f);
|
|
|
|
|
(*texCoords)[2].set(1.0f, 0.0f);
|
|
|
|
|
(*texCoords)[3].set(1.0f, 1.0f);
|
|
|
|
|
mGeometry->setTexCoordArray(0, texCoords);
|
|
|
|
|
(*normals)[0].set(0.0f, -1.0f, 0.0f);
|
|
|
|
|
(*colors)[0].set(1.0f, 1.0f, 1.0f, 0.0f);
|
|
|
|
|
(*colors)[0].set(1.0f, 1.0f, 1.0f, 1.0f);
|
|
|
|
|
mGeometry->setNormalArray(normals, osg::Array::BIND_OVERALL);
|
|
|
|
|
mGeometry->setColorArray(colors, osg::Array::BIND_OVERALL);
|
|
|
|
|
//mGeometry->setColorArray(colors, osg::Array::BIND_OVERALL);
|
|
|
|
|
mGeometry->addPrimitiveSet(new osg::DrawArrays(GL_QUADS, 0, 4));
|
|
|
|
|
mGeometry->setDataVariance(osg::Object::DYNAMIC);
|
|
|
|
|
mGeometry->setSupportsDisplayList(false);
|
|
|
|
@ -159,28 +156,35 @@ private:
|
|
|
|
|
|
|
|
|
|
mStateSet->setTextureAttributeAndModes(0, menuTexture(), osg::StateAttribute::ON);
|
|
|
|
|
mStateSet->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
|
|
|
|
|
mStateSet->setMode(GL_BLEND, osg::StateAttribute::ON);
|
|
|
|
|
mStateSet->setAttributeAndModes(new osg::BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
|
|
|
|
|
mStateSet->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mGeometry->setStateSet(mStateSet);
|
|
|
|
|
|
|
|
|
|
// Units are divided by 2 because geometry has side lengths of 2 units.
|
|
|
|
|
|
|
|
|
|
// mTransform->setScale(osg::Vec3(extent_meters.x(), extent_meters.y(), 1.f));
|
|
|
|
|
mTransform->setScale(osg::Vec3(1.f, 1.f, 1.f));
|
|
|
|
|
mTransform->setScale(osg::Vec3(extent_units.x(), extent_units.y(), 1.f));
|
|
|
|
|
mTransform->setAttitude(pose.orientation);
|
|
|
|
|
mTransform->setPosition(pose.position);
|
|
|
|
|
|
|
|
|
|
mGeode->addDrawable(mGeometry);
|
|
|
|
|
mTransform->addChild(mGeode);
|
|
|
|
|
mParent->addChild(mTransform);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mParent->addChild(mMenuCamera.get());
|
|
|
|
|
SceneUtil::FindByNameVisitor findRootVisitor("OpenXRRoot", osg::NodeVisitor::TRAVERSE_PARENTS);
|
|
|
|
|
mParent->accept(findRootVisitor);
|
|
|
|
|
findRootVisitor.mFoundNode->addChild(mMenuCamera.get());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OpenXRMenu::~OpenXRMenu()
|
|
|
|
|
{
|
|
|
|
|
mParent->removeChild(mTransform);
|
|
|
|
|
mParent->removeChild(mMenuCamera.get());
|
|
|
|
|
|
|
|
|
|
SceneUtil::FindByNameVisitor findRootVisitor("OpenXRRoot", osg::NodeVisitor::TRAVERSE_PARENTS);
|
|
|
|
|
mParent->accept(findRootVisitor);
|
|
|
|
|
findRootVisitor.mFoundNode->removeChild(mMenuCamera.get());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OpenXRMenu::updateCallback()
|
|
|
|
@ -217,9 +221,22 @@ private:
|
|
|
|
|
root->accept(findGUIVisitor);
|
|
|
|
|
mGuiRoot = findGUIVisitor.mFoundNode;
|
|
|
|
|
if (!mGuiRoot)
|
|
|
|
|
throw std::logic_error("Gui root doesn't exist");
|
|
|
|
|
{
|
|
|
|
|
Log(Debug::Error) << "GUI Root doesn't exist";
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SceneUtil::FindByNameVisitor findSceneVisitor("Scene Root");
|
|
|
|
|
root->accept(findSceneVisitor);
|
|
|
|
|
if(!findSceneVisitor.mFoundNode)
|
|
|
|
|
{
|
|
|
|
|
Log(Debug::Error) << "Scene Root doesn't exist";
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Log(Debug::Verbose) << "Root note: " << root->getName();
|
|
|
|
|
|
|
|
|
|
root->asGroup()->addChild(mMenusRoot);
|
|
|
|
|
findSceneVisitor.mFoundNode->addChild(mMenusRoot);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OpenXRMenuManager::~OpenXRMenuManager(void)
|
|
|
|
@ -239,7 +256,7 @@ private:
|
|
|
|
|
mMenusRoot,
|
|
|
|
|
mGuiRoot,
|
|
|
|
|
"Main Menu",
|
|
|
|
|
osg::Vec2(2.f, 2.f),
|
|
|
|
|
osg::Vec2(1.5f, 1.5f),
|
|
|
|
|
mPose,
|
|
|
|
|
width,
|
|
|
|
|
height,
|
|
|
|
@ -270,10 +287,10 @@ private:
|
|
|
|
|
|
|
|
|
|
camera->getViewMatrixAsLookAt(eye, center, up);
|
|
|
|
|
|
|
|
|
|
// Position the menu half a meter in front of the player
|
|
|
|
|
// Position the menu about two thirds of a meter in front of the player
|
|
|
|
|
osg::Vec3 dir = center - eye;
|
|
|
|
|
dir.normalize();
|
|
|
|
|
mPose.position = eye + dir * OpenXREnvironment::get().unitsPerMeter();
|
|
|
|
|
mPose.position = eye + dir * OpenXREnvironment::get().unitsPerMeter() * 2.f / 3.f;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mPose.orientation = camera->getViewMatrix().getRotate().inverse();
|
|
|
|
|