mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-16 21:19:55 +00:00
Move code to WorldspaceWidget so that UnpagedWorldspaceWidget can be supported.
This commit is contained in:
parent
6c8320a638
commit
68b7532383
4 changed files with 281 additions and 266 deletions
|
@ -13,106 +13,17 @@
|
|||
#include <OgreRoot.h>
|
||||
#include <OgreSceneQuery.h>
|
||||
|
||||
#include <OgreEntity.h> // FIXME: visual highlight, clone
|
||||
#include <OgreMaterialManager.h> // FIXME: visual highlight, material
|
||||
#include <OgreHardwarePixelBuffer.h> // FIXME: visual highlight, texture
|
||||
|
||||
#include <components/esm/loadland.hpp>
|
||||
#include "textoverlay.hpp"
|
||||
#include "overlaymask.hpp"
|
||||
|
||||
#include "../../model/world/tablemimedata.hpp"
|
||||
#include "../../model/world/idtable.hpp"
|
||||
#include "../../model/settings/usersettings.hpp"
|
||||
|
||||
#include "../widget/scenetooltoggle.hpp"
|
||||
#include "../world/physicssystem.hpp"
|
||||
|
||||
#include "elements.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
// FIXME: this section should be removed once the debugging is completed
|
||||
void showHitPoint(Ogre::SceneManager *sceneMgr, std::string name, Ogre::Vector3 point)
|
||||
{
|
||||
if(sceneMgr->hasManualObject("manual" + name))
|
||||
sceneMgr->destroyManualObject("manual" + name);
|
||||
Ogre::ManualObject* manual = sceneMgr->createManualObject("manual" + name);
|
||||
manual->begin("BaseWhite", Ogre::RenderOperation::OT_LINE_LIST);
|
||||
manual-> position(point.x, point.y, point.z-100);
|
||||
manual-> position(point.x, point.y, point.z+100);
|
||||
manual-> position(point.x, point.y-100, point.z);
|
||||
manual-> position(point.x, point.y+100, point.z);
|
||||
manual-> position(point.x-100, point.y, point.z);
|
||||
manual-> position(point.x+100, point.y, point.z);
|
||||
manual->end();
|
||||
sceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(manual);
|
||||
}
|
||||
|
||||
void removeHitPoint(Ogre::SceneManager *sceneMgr, std::string name)
|
||||
{
|
||||
if(sceneMgr->hasManualObject("manual" + name))
|
||||
sceneMgr->destroyManualObject("manual" + name);
|
||||
}
|
||||
|
||||
void initDebug()
|
||||
{
|
||||
// material for visual cue on selected objects
|
||||
Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().getByName("DynamicTrans");
|
||||
if(texture.isNull())
|
||||
{
|
||||
texture = Ogre::TextureManager::getSingleton().createManual(
|
||||
"DynamicTrans", // name
|
||||
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
|
||||
Ogre::TEX_TYPE_2D, // type
|
||||
8, 8, // width & height
|
||||
0, // number of mipmaps
|
||||
Ogre::PF_BYTE_BGRA, // pixel format
|
||||
Ogre::TU_DEFAULT); // usage; should be TU_DYNAMIC_WRITE_ONLY_DISCARDABLE for
|
||||
// textures updated very often (e.g. each frame)
|
||||
|
||||
Ogre::HardwarePixelBufferSharedPtr pixelBuffer = texture->getBuffer();
|
||||
pixelBuffer->lock(Ogre::HardwareBuffer::HBL_NORMAL);
|
||||
const Ogre::PixelBox& pixelBox = pixelBuffer->getCurrentLock();
|
||||
|
||||
uint8_t* pDest = static_cast<uint8_t*>(pixelBox.data);
|
||||
|
||||
// Fill in some pixel data. This will give a semi-transparent colour,
|
||||
// but this is of course dependent on the chosen pixel format.
|
||||
for (size_t j = 0; j < 8; j++)
|
||||
{
|
||||
for(size_t i = 0; i < 8; i++)
|
||||
{
|
||||
*pDest++ = 255; // B
|
||||
*pDest++ = 255; // G
|
||||
*pDest++ = 127; // R
|
||||
*pDest++ = 63; // A
|
||||
}
|
||||
|
||||
pDest += pixelBox.getRowSkip() * Ogre::PixelUtil::getNumElemBytes(pixelBox.format);
|
||||
}
|
||||
pixelBuffer->unlock();
|
||||
}
|
||||
Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().getByName(
|
||||
"TransMaterial");
|
||||
if(material.isNull())
|
||||
{
|
||||
Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().create(
|
||||
"TransMaterial",
|
||||
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, true );
|
||||
Ogre::Pass *pass = material->getTechnique( 0 )->getPass( 0 );
|
||||
pass->setLightingEnabled( false );
|
||||
pass->setDepthWriteEnabled( false );
|
||||
pass->setSceneBlending( Ogre::SBT_TRANSPARENT_ALPHA );
|
||||
|
||||
Ogre::TextureUnitState *tex = pass->createTextureUnitState("CustomState", 0);
|
||||
tex->setTextureName("DynamicTrans");
|
||||
tex->setTextureFiltering( Ogre::TFO_ANISOTROPIC );
|
||||
material->load();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool CSVRender::PagedWorldspaceWidget::adjustCells()
|
||||
{
|
||||
bool modified = false;
|
||||
|
@ -273,15 +184,8 @@ void CSVRender::PagedWorldspaceWidget::mouseReleaseEvent (QMouseEvent *event)
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// mouse picking
|
||||
// FIXME: need to virtualise mouse buttons
|
||||
if(!getCamera()->getViewport())
|
||||
return;
|
||||
|
||||
debugMousePicking((float) event->x() / getCamera()->getViewport()->getActualWidth(),
|
||||
(float) event->y() / getCamera()->getViewport()->getActualHeight());
|
||||
}
|
||||
WorldspaceWidget::mouseReleaseEvent(event);
|
||||
}
|
||||
|
||||
void CSVRender::PagedWorldspaceWidget::mouseDoubleClickEvent (QMouseEvent *event)
|
||||
|
@ -289,19 +193,8 @@ void CSVRender::PagedWorldspaceWidget::mouseDoubleClickEvent (QMouseEvent *event
|
|||
if(event->button() == Qt::RightButton)
|
||||
{
|
||||
std::cout << "double clicked" << std::endl;
|
||||
|
||||
CSMSettings::UserSettings &userSettings = CSMSettings::UserSettings::instance();
|
||||
if(userSettings.setting ("debug/mouse-picking", QString("false")) == "true" ? true : false)
|
||||
{
|
||||
// FIXME: OEngine::PhysicEngine creates only one child scene node for the
|
||||
// debug drawer. Hence only the first subview that creates the debug drawer
|
||||
// can view the debug lines. Will need to keep a map in OEngine if multiple
|
||||
// subviews are to be supported.
|
||||
CSVWorld::PhysicsSystem::instance()->setSceneManager(getSceneManager());
|
||||
CSVWorld::PhysicsSystem::instance()->toggleDebugRendering();
|
||||
flagAsModified();
|
||||
}
|
||||
}
|
||||
WorldspaceWidget::mouseDoubleClickEvent(event);
|
||||
}
|
||||
|
||||
void CSVRender::PagedWorldspaceWidget::updateOverlay()
|
||||
|
@ -416,8 +309,6 @@ CSVRender::PagedWorldspaceWidget::PagedWorldspaceWidget (QWidget* parent, CSMDoc
|
|||
this, SLOT (cellRemoved (const QModelIndex&, int, int)));
|
||||
connect (cells, SIGNAL (rowsInserted (const QModelIndex&, int, int)),
|
||||
this, SLOT (cellAdded (const QModelIndex&, int, int)));
|
||||
|
||||
initDebug();
|
||||
}
|
||||
|
||||
CSVRender::PagedWorldspaceWidget::~PagedWorldspaceWidget()
|
||||
|
@ -438,24 +329,6 @@ CSVRender::PagedWorldspaceWidget::~PagedWorldspaceWidget()
|
|||
|
||||
removeRenderTargetListener(mOverlayMask);
|
||||
delete mOverlayMask;
|
||||
|
||||
// For debugging only
|
||||
std::map<std::string, std::vector<std::string> >::iterator iter = mSelectedEntities.begin();
|
||||
for(;iter != mSelectedEntities.end(); ++iter)
|
||||
{
|
||||
removeHitPoint(getSceneManager(), iter->first);
|
||||
|
||||
if(getSceneManager()->hasSceneNode(iter->first))
|
||||
{
|
||||
Ogre::SceneNode *scene = getSceneManager()->getSceneNode(iter->first);
|
||||
|
||||
if(scene)
|
||||
{
|
||||
scene->removeAndDestroyAllChildren();
|
||||
getSceneManager()->destroySceneNode(iter->first);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CSVRender::PagedWorldspaceWidget::useViewHint (const std::string& hint)
|
||||
|
@ -606,136 +479,3 @@ void CSVRender::PagedWorldspaceWidget::cellAdded (const QModelIndex& index, int
|
|||
if (adjustCells())
|
||||
flagAsModified();
|
||||
}
|
||||
|
||||
|
||||
void CSVRender::PagedWorldspaceWidget::debugMousePicking(float mouseX, float mouseY)
|
||||
{
|
||||
CSMSettings::UserSettings &userSettings = CSMSettings::UserSettings::instance();
|
||||
bool debug = userSettings.setting ("debug/mouse-picking", QString("false")) == "true" ? true : false;
|
||||
|
||||
std::pair<std::string, Ogre::Vector3> result = CSVWorld::PhysicsSystem::instance()->castRay(
|
||||
mouseX, mouseY, NULL, NULL, getCamera());
|
||||
if(debug && result.first != "")
|
||||
{
|
||||
// FIXME: is there a better way to distinguish terrain from objects?
|
||||
QString name = QString(result.first.c_str());
|
||||
if(name.contains(QRegExp("^HeightField")))
|
||||
{
|
||||
// terrain
|
||||
std::cout << "terrain: " << result.first << std::endl;
|
||||
std::cout << " hit pos "+ QString::number(result.second.x).toStdString()
|
||||
+ ", " + QString::number(result.second.y).toStdString()
|
||||
+ ", " + QString::number(result.second.z).toStdString()
|
||||
<< std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string sceneNode =
|
||||
CSVWorld::PhysicsSystem::instance()->referenceToSceneNode(result.first);
|
||||
|
||||
uint32_t visibilityMask = getCamera()->getViewport()->getVisibilityMask();
|
||||
bool ignoreObjects = !(visibilityMask & (uint32_t)CSVRender::Element_Reference);
|
||||
|
||||
if(!ignoreObjects && getSceneManager()->hasSceneNode(sceneNode))
|
||||
{
|
||||
if(userSettings.setting("debug/mouse-picking", QString("false")) == "true" ? true : false)
|
||||
updateSelectionHighlight(sceneNode, result.second);
|
||||
}
|
||||
|
||||
std::cout << "ReferenceId: " << result.first << std::endl;
|
||||
const CSMWorld::CellRef& cellref = mDocument.getData().getReferences().getRecord (result.first).get();
|
||||
//std::cout << "CellRef.mId: " << cellref.mId << std::endl; // Same as ReferenceId
|
||||
std::cout << " CellRef.mCell: " << cellref.mCell << std::endl;
|
||||
|
||||
const CSMWorld::RefCollection& references = mDocument.getData().getReferences();
|
||||
int index = references.searchId(result.first);
|
||||
if (index != -1)
|
||||
{
|
||||
int columnIndex =
|
||||
references.findColumnIndex(CSMWorld::Columns::ColumnId_ReferenceableId);
|
||||
|
||||
std::cout << " index: " + QString::number(index).toStdString()
|
||||
+", column index: " + QString::number(columnIndex).toStdString() << std::endl;
|
||||
}
|
||||
|
||||
std::map<CSMWorld::CellCoordinates, Cell *>::iterator iter (mCells.begin());
|
||||
while (iter!=mCells.end())
|
||||
{
|
||||
if(iter->first.getId("dummy") == cellref.mCell)
|
||||
{
|
||||
//std::cout << "Cell found" << std::endl;
|
||||
break;
|
||||
}
|
||||
++iter;
|
||||
}
|
||||
flagAsModified();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: for debugging only
|
||||
void CSVRender::PagedWorldspaceWidget::updateSelectionHighlight(std::string sceneNode, const Ogre::Vector3 &position)
|
||||
{
|
||||
CSMSettings::UserSettings &userSettings = CSMSettings::UserSettings::instance();
|
||||
bool debugCursor = userSettings.setting(
|
||||
"debug/mouse-position", QString("false")) == "true" ? true : false;
|
||||
|
||||
//TODO: Try http://www.ogre3d.org/tikiwiki/Create+outline+around+a+character
|
||||
Ogre::SceneNode *scene = getSceneManager()->getSceneNode(sceneNode);
|
||||
std::map<std::string, std::vector<std::string> >::iterator iter =
|
||||
mSelectedEntities.find(sceneNode);
|
||||
if(iter != mSelectedEntities.end()) // currently selected
|
||||
{
|
||||
std::vector<std::string> clonedEntities = mSelectedEntities[sceneNode];
|
||||
while(!clonedEntities.empty())
|
||||
{
|
||||
if(getSceneManager()->hasEntity(clonedEntities.back()))
|
||||
{
|
||||
scene->detachObject(clonedEntities.back());
|
||||
getSceneManager()->destroyEntity(clonedEntities.back());
|
||||
}
|
||||
clonedEntities.pop_back();
|
||||
}
|
||||
mSelectedEntities.erase(iter);
|
||||
|
||||
if(debugCursor)
|
||||
removeHitPoint(getSceneManager(), sceneNode);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::vector<std::string> clonedEntities;
|
||||
Ogre::SceneNode::ObjectIterator iter = scene->getAttachedObjectIterator();
|
||||
iter.begin();
|
||||
while(iter.hasMoreElements())
|
||||
{
|
||||
Ogre::MovableObject * element = iter.getNext();
|
||||
if(!element)
|
||||
break;
|
||||
|
||||
if(element->getMovableType() != "Entity")
|
||||
continue;
|
||||
|
||||
Ogre::Entity * entity = dynamic_cast<Ogre::Entity *>(element);
|
||||
if(getSceneManager()->hasEntity(entity->getName()+"cover"))
|
||||
{
|
||||
// FIXME: this shouldn't really happen... but does :(
|
||||
scene->detachObject(entity->getName()+"cover");
|
||||
getSceneManager()->destroyEntity(entity->getName()+"cover");
|
||||
}
|
||||
Ogre::Entity * clone = entity->clone(entity->getName()+"cover");
|
||||
|
||||
Ogre::MaterialPtr mat =
|
||||
Ogre::MaterialManager::getSingleton().getByName("TransMaterial");
|
||||
if(!mat.isNull())
|
||||
{
|
||||
clone->setMaterial(mat);
|
||||
scene->attachObject(clone);
|
||||
clonedEntities.push_back(entity->getName()+"cover");
|
||||
}
|
||||
}
|
||||
mSelectedEntities[sceneNode] = clonedEntities;
|
||||
|
||||
if(debugCursor)
|
||||
showHitPoint(getSceneManager(), sceneNode, position);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,6 @@ namespace CSVRender
|
|||
bool mDisplayCellCoord;
|
||||
std::map<CSMWorld::CellCoordinates, TextOverlay *> mTextOverlays;
|
||||
OverlayMask *mOverlayMask;
|
||||
std::map<std::string, std::vector<std::string> > mSelectedEntities;
|
||||
|
||||
private:
|
||||
|
||||
|
@ -52,9 +51,6 @@ namespace CSVRender
|
|||
|
||||
virtual std::string getStartupInstruction();
|
||||
|
||||
void debugMousePicking(float mouseX, float mouseY);
|
||||
void updateSelectionHighlight(std::string sceneNode, const Ogre::Vector3 &position);
|
||||
|
||||
public:
|
||||
|
||||
PagedWorldspaceWidget (QWidget *parent, CSMDoc::Document& document);
|
||||
|
|
|
@ -7,17 +7,108 @@
|
|||
#include <OgreSceneManager.h>
|
||||
#include <OgreEntity.h>
|
||||
|
||||
#include <OgreManualObject.h> // FIXME: for debugging
|
||||
#include <OgreMaterialManager.h> // FIXME: for debugging
|
||||
#include <OgreHardwarePixelBuffer.h> // FIXME: for debugging
|
||||
|
||||
#include <QMouseEvent>
|
||||
#include <QtGui/qevent.h>
|
||||
|
||||
#include "../../model/world/universalid.hpp"
|
||||
#include "../../model/world/idtable.hpp"
|
||||
#include "../../model/settings/usersettings.hpp"
|
||||
|
||||
#include "../widget/scenetoolmode.hpp"
|
||||
#include "../widget/scenetooltoggle.hpp"
|
||||
#include "../widget/scenetoolrun.hpp"
|
||||
|
||||
#include "../world/physicssystem.hpp"
|
||||
|
||||
#include "elements.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
// FIXME: this section should be removed once the debugging is completed
|
||||
void showHitPoint(Ogre::SceneManager *sceneMgr, std::string name, Ogre::Vector3 point)
|
||||
{
|
||||
if(sceneMgr->hasManualObject("manual" + name))
|
||||
sceneMgr->destroyManualObject("manual" + name);
|
||||
Ogre::ManualObject* manual = sceneMgr->createManualObject("manual" + name);
|
||||
manual->begin("BaseWhite", Ogre::RenderOperation::OT_LINE_LIST);
|
||||
manual-> position(point.x, point.y, point.z-100);
|
||||
manual-> position(point.x, point.y, point.z+100);
|
||||
manual-> position(point.x, point.y-100, point.z);
|
||||
manual-> position(point.x, point.y+100, point.z);
|
||||
manual-> position(point.x-100, point.y, point.z);
|
||||
manual-> position(point.x+100, point.y, point.z);
|
||||
manual->end();
|
||||
sceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(manual);
|
||||
}
|
||||
|
||||
void removeHitPoint(Ogre::SceneManager *sceneMgr, std::string name)
|
||||
{
|
||||
if(sceneMgr->hasManualObject("manual" + name))
|
||||
sceneMgr->destroyManualObject("manual" + name);
|
||||
}
|
||||
|
||||
void initDebug()
|
||||
{
|
||||
// material for visual cue on selected objects
|
||||
Ogre::TexturePtr texture = Ogre::TextureManager::getSingleton().getByName("DynamicTrans");
|
||||
if(texture.isNull())
|
||||
{
|
||||
texture = Ogre::TextureManager::getSingleton().createManual(
|
||||
"DynamicTrans", // name
|
||||
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
|
||||
Ogre::TEX_TYPE_2D, // type
|
||||
8, 8, // width & height
|
||||
0, // number of mipmaps
|
||||
Ogre::PF_BYTE_BGRA, // pixel format
|
||||
Ogre::TU_DEFAULT); // usage; should be TU_DYNAMIC_WRITE_ONLY_DISCARDABLE for
|
||||
// textures updated very often (e.g. each frame)
|
||||
|
||||
Ogre::HardwarePixelBufferSharedPtr pixelBuffer = texture->getBuffer();
|
||||
pixelBuffer->lock(Ogre::HardwareBuffer::HBL_NORMAL);
|
||||
const Ogre::PixelBox& pixelBox = pixelBuffer->getCurrentLock();
|
||||
|
||||
uint8_t* pDest = static_cast<uint8_t*>(pixelBox.data);
|
||||
|
||||
// Fill in some pixel data. This will give a semi-transparent colour,
|
||||
// but this is of course dependent on the chosen pixel format.
|
||||
for (size_t j = 0; j < 8; j++)
|
||||
{
|
||||
for(size_t i = 0; i < 8; i++)
|
||||
{
|
||||
*pDest++ = 255; // B
|
||||
*pDest++ = 255; // G
|
||||
*pDest++ = 127; // R
|
||||
*pDest++ = 63; // A
|
||||
}
|
||||
|
||||
pDest += pixelBox.getRowSkip() * Ogre::PixelUtil::getNumElemBytes(pixelBox.format);
|
||||
}
|
||||
pixelBuffer->unlock();
|
||||
}
|
||||
Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().getByName(
|
||||
"TransMaterial");
|
||||
if(material.isNull())
|
||||
{
|
||||
Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().create(
|
||||
"TransMaterial",
|
||||
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, true );
|
||||
Ogre::Pass *pass = material->getTechnique( 0 )->getPass( 0 );
|
||||
pass->setLightingEnabled( false );
|
||||
pass->setDepthWriteEnabled( false );
|
||||
pass->setSceneBlending( Ogre::SBT_TRANSPARENT_ALPHA );
|
||||
|
||||
Ogre::TextureUnitState *tex = pass->createTextureUnitState("CustomState", 0);
|
||||
tex->setTextureName("DynamicTrans");
|
||||
tex->setTextureFiltering( Ogre::TFO_ANISOTROPIC );
|
||||
material->load();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CSVRender::WorldspaceWidget::WorldspaceWidget (CSMDoc::Document& document, QWidget* parent)
|
||||
: SceneWidget (parent), mDocument(document), mSceneElements(0), mRun(0)
|
||||
{
|
||||
|
@ -50,6 +141,29 @@ CSVRender::WorldspaceWidget::WorldspaceWidget (CSMDoc::Document& document, QWidg
|
|||
this, SLOT (debugProfileDataChanged (const QModelIndex&, const QModelIndex&)));
|
||||
connect (debugProfiles, SIGNAL (rowsAboutToBeRemoved (const QModelIndex&, int, int)),
|
||||
this, SLOT (debugProfileAboutToBeRemoved (const QModelIndex&, int, int)));
|
||||
|
||||
initDebug();
|
||||
}
|
||||
|
||||
CSVRender::WorldspaceWidget::~WorldspaceWidget ()
|
||||
{
|
||||
// For debugging only
|
||||
std::map<std::string, std::vector<std::string> >::iterator iter = mSelectedEntities.begin();
|
||||
for(;iter != mSelectedEntities.end(); ++iter)
|
||||
{
|
||||
removeHitPoint(getSceneManager(), iter->first);
|
||||
|
||||
if(getSceneManager()->hasSceneNode(iter->first))
|
||||
{
|
||||
Ogre::SceneNode *scene = getSceneManager()->getSceneNode(iter->first);
|
||||
|
||||
if(scene)
|
||||
{
|
||||
scene->removeAndDestroyAllChildren();
|
||||
getSceneManager()->destroySceneNode(iter->first);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CSVRender::WorldspaceWidget::selectNavigationMode (const std::string& mode)
|
||||
|
@ -319,3 +433,158 @@ void CSVRender::WorldspaceWidget::elementSelectionChanged()
|
|||
void CSVRender::WorldspaceWidget::updateOverlay()
|
||||
{
|
||||
}
|
||||
|
||||
void CSVRender::WorldspaceWidget::mouseReleaseEvent (QMouseEvent *event)
|
||||
{
|
||||
if(event->button() == Qt::RightButton)
|
||||
{
|
||||
// mouse picking
|
||||
// FIXME: need to virtualise mouse buttons
|
||||
if(!getCamera()->getViewport())
|
||||
return;
|
||||
|
||||
debugMousePicking((float) event->x() / getCamera()->getViewport()->getActualWidth(),
|
||||
(float) event->y() / getCamera()->getViewport()->getActualHeight());
|
||||
}
|
||||
SceneWidget::mouseReleaseEvent(event);
|
||||
}
|
||||
|
||||
void CSVRender::WorldspaceWidget::mouseDoubleClickEvent (QMouseEvent *event)
|
||||
{
|
||||
if(event->button() == Qt::RightButton)
|
||||
{
|
||||
CSMSettings::UserSettings &userSettings = CSMSettings::UserSettings::instance();
|
||||
if(userSettings.setting ("debug/mouse-picking", QString("false")) == "true" ? true : false)
|
||||
{
|
||||
// FIXME: OEngine::PhysicEngine creates only one child scene node for the
|
||||
// debug drawer. Hence only the first subview that creates the debug drawer
|
||||
// can view the debug lines. Will need to keep a map in OEngine if multiple
|
||||
// subviews are to be supported.
|
||||
CSVWorld::PhysicsSystem::instance()->setSceneManager(getSceneManager());
|
||||
CSVWorld::PhysicsSystem::instance()->toggleDebugRendering();
|
||||
flagAsModified();
|
||||
}
|
||||
}
|
||||
//SceneWidget::mouseDoubleClickEvent(event);
|
||||
}
|
||||
|
||||
void CSVRender::WorldspaceWidget::debugMousePicking(float mouseX, float mouseY)
|
||||
{
|
||||
CSMSettings::UserSettings &userSettings = CSMSettings::UserSettings::instance();
|
||||
bool debug = userSettings.setting ("debug/mouse-picking", QString("false")) == "true" ? true : false;
|
||||
|
||||
std::pair<std::string, Ogre::Vector3> result = CSVWorld::PhysicsSystem::instance()->castRay(
|
||||
mouseX, mouseY, NULL, NULL, getCamera());
|
||||
if(debug && result.first != "")
|
||||
{
|
||||
// FIXME: is there a better way to distinguish terrain from objects?
|
||||
QString name = QString(result.first.c_str());
|
||||
if(name.contains(QRegExp("^HeightField")))
|
||||
{
|
||||
// terrain
|
||||
std::cout << "terrain: " << result.first << std::endl;
|
||||
std::cout << " hit pos "+ QString::number(result.second.x).toStdString()
|
||||
+ ", " + QString::number(result.second.y).toStdString()
|
||||
+ ", " + QString::number(result.second.z).toStdString()
|
||||
<< std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string sceneNode =
|
||||
CSVWorld::PhysicsSystem::instance()->referenceToSceneNode(result.first);
|
||||
|
||||
uint32_t visibilityMask = getCamera()->getViewport()->getVisibilityMask();
|
||||
bool ignoreObjects = !(visibilityMask & (uint32_t)CSVRender::Element_Reference);
|
||||
|
||||
if(!ignoreObjects && getSceneManager()->hasSceneNode(sceneNode))
|
||||
{
|
||||
if(userSettings.setting("debug/mouse-picking", QString("false")) == "true" ? true : false)
|
||||
updateSelectionHighlight(sceneNode, result.second);
|
||||
}
|
||||
|
||||
std::cout << "ReferenceId: " << result.first << std::endl;
|
||||
const CSMWorld::CellRef& cellref = mDocument.getData().getReferences().getRecord (result.first).get();
|
||||
//std::cout << "CellRef.mId: " << cellref.mId << std::endl; // Same as ReferenceId
|
||||
std::cout << " CellRef.mCell: " << cellref.mCell << std::endl;
|
||||
|
||||
const CSMWorld::RefCollection& references = mDocument.getData().getReferences();
|
||||
int index = references.searchId(result.first);
|
||||
if (index != -1)
|
||||
{
|
||||
int columnIndex =
|
||||
references.findColumnIndex(CSMWorld::Columns::ColumnId_ReferenceableId);
|
||||
|
||||
std::cout << " index: " + QString::number(index).toStdString()
|
||||
+", column index: " + QString::number(columnIndex).toStdString() << std::endl;
|
||||
}
|
||||
flagAsModified();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: for debugging only
|
||||
void CSVRender::WorldspaceWidget::updateSelectionHighlight(std::string sceneNode, const Ogre::Vector3 &position)
|
||||
{
|
||||
CSMSettings::UserSettings &userSettings = CSMSettings::UserSettings::instance();
|
||||
bool debugCursor = userSettings.setting(
|
||||
"debug/mouse-position", QString("false")) == "true" ? true : false;
|
||||
|
||||
//TODO: Try http://www.ogre3d.org/tikiwiki/Create+outline+around+a+character
|
||||
Ogre::SceneNode *scene = getSceneManager()->getSceneNode(sceneNode);
|
||||
std::map<std::string, std::vector<std::string> >::iterator iter =
|
||||
mSelectedEntities.find(sceneNode);
|
||||
if(iter != mSelectedEntities.end()) // currently selected
|
||||
{
|
||||
std::vector<std::string> clonedEntities = mSelectedEntities[sceneNode];
|
||||
while(!clonedEntities.empty())
|
||||
{
|
||||
if(getSceneManager()->hasEntity(clonedEntities.back()))
|
||||
{
|
||||
scene->detachObject(clonedEntities.back());
|
||||
getSceneManager()->destroyEntity(clonedEntities.back());
|
||||
}
|
||||
clonedEntities.pop_back();
|
||||
}
|
||||
mSelectedEntities.erase(iter);
|
||||
|
||||
if(debugCursor)
|
||||
removeHitPoint(getSceneManager(), sceneNode);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::vector<std::string> clonedEntities;
|
||||
Ogre::SceneNode::ObjectIterator iter = scene->getAttachedObjectIterator();
|
||||
iter.begin();
|
||||
while(iter.hasMoreElements())
|
||||
{
|
||||
Ogre::MovableObject * element = iter.getNext();
|
||||
if(!element)
|
||||
break;
|
||||
|
||||
if(element->getMovableType() != "Entity")
|
||||
continue;
|
||||
|
||||
Ogre::Entity * entity = dynamic_cast<Ogre::Entity *>(element);
|
||||
if(getSceneManager()->hasEntity(entity->getName()+"cover"))
|
||||
{
|
||||
// FIXME: this shouldn't really happen... but does :(
|
||||
scene->detachObject(entity->getName()+"cover");
|
||||
getSceneManager()->destroyEntity(entity->getName()+"cover");
|
||||
}
|
||||
Ogre::Entity * clone = entity->clone(entity->getName()+"cover");
|
||||
|
||||
Ogre::MaterialPtr mat =
|
||||
Ogre::MaterialManager::getSingleton().getByName("TransMaterial");
|
||||
if(!mat.isNull())
|
||||
{
|
||||
clone->setMaterial(mat);
|
||||
scene->attachObject(clone);
|
||||
clonedEntities.push_back(entity->getName()+"cover");
|
||||
}
|
||||
}
|
||||
mSelectedEntities[sceneNode] = clonedEntities;
|
||||
|
||||
if(debugCursor)
|
||||
showHitPoint(getSceneManager(), sceneNode, position);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,6 +34,8 @@ namespace CSVRender
|
|||
CSVWidget::SceneToolRun *mRun;
|
||||
CSMDoc::Document& mDocument;
|
||||
|
||||
std::map<std::string, std::vector<std::string> > mSelectedEntities;
|
||||
|
||||
public:
|
||||
|
||||
enum DropType
|
||||
|
@ -53,6 +55,7 @@ namespace CSVRender
|
|||
};
|
||||
|
||||
WorldspaceWidget (CSMDoc::Document& document, QWidget *parent = 0);
|
||||
~WorldspaceWidget ();
|
||||
|
||||
CSVWidget::SceneToolMode *makeNavigationSelector (CSVWidget::SceneToolbar *parent);
|
||||
///< \attention The created tool is not added to the toolbar (via addTool). Doing that
|
||||
|
@ -90,6 +93,10 @@ namespace CSVRender
|
|||
|
||||
virtual void updateOverlay();
|
||||
|
||||
virtual void mouseReleaseEvent (QMouseEvent *event);
|
||||
|
||||
virtual void mouseDoubleClickEvent (QMouseEvent *event);
|
||||
|
||||
private:
|
||||
|
||||
void dragEnterEvent(QDragEnterEvent *event);
|
||||
|
@ -100,6 +107,9 @@ namespace CSVRender
|
|||
|
||||
virtual std::string getStartupInstruction() = 0;
|
||||
|
||||
void debugMousePicking(float mouseX, float mouseY);
|
||||
void updateSelectionHighlight(std::string sceneNode, const Ogre::Vector3 &position);
|
||||
|
||||
private slots:
|
||||
|
||||
void selectNavigationMode (const std::string& mode);
|
||||
|
|
Loading…
Reference in a new issue