mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-12-15 06:08:42 +00:00
Changed: #1150 Switched to 3d view plugin
This commit is contained in:
parent
9e436be1fb
commit
adae928850
10 changed files with 876 additions and 252 deletions
|
@ -1,4 +1,10 @@
|
|||
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${LIBXML2_INCLUDE_DIR} ${NEL_INCLUDE_DIR} ${QT_INCLUDES})
|
||||
INCLUDE_DIRECTORIES(
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${LIBXML2_INCLUDE_DIR}
|
||||
${NEL_INCLUDE_DIR}
|
||||
../../../../../nel/tools/3d/object_viewer_widget/src
|
||||
${QT_INCLUDES})
|
||||
INCLUDE( ${QT_USE_FILE} )
|
||||
|
||||
FILE(GLOB GEORGES_EDITOR_SRC *.cpp *.h)
|
||||
|
|
|
@ -76,23 +76,23 @@ CEntity::~CEntity(void)
|
|||
if (_PlayList != NULL)
|
||||
{
|
||||
_PlayList->resetAllChannels();
|
||||
Modules::objView().getPlayListManager()->deletePlayList (_PlayList);
|
||||
//Modules::objViewWid().getPlayListManager()->deletePlayList (_PlayList);
|
||||
_PlayList = NULL;
|
||||
}
|
||||
if (_AnimationSet != NULL)
|
||||
{
|
||||
Modules::objView().getDriver()->deleteAnimationSet(_AnimationSet);
|
||||
//Modules::objViewWid().getDriver()->deleteAnimationSet(_AnimationSet);
|
||||
_AnimationSet = NULL;
|
||||
}
|
||||
if (!_Skeleton.empty())
|
||||
{
|
||||
_Skeleton.detachSkeletonSon(_Instance);
|
||||
Modules::objView().getScene()->deleteSkeleton(_Skeleton);
|
||||
//Modules::objViewWid().getScene()->deleteSkeleton(_Skeleton);
|
||||
_Skeleton = NULL;
|
||||
}
|
||||
if (!_Instance.empty())
|
||||
{
|
||||
Modules::objView().getScene()->deleteInstance(_Instance);
|
||||
//Modules::objViewWid().getScene()->deleteInstance(_Instance);
|
||||
_Instance = NULL;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
|
||||
// Project includes
|
||||
#include "modules.h"
|
||||
#include "georges.h"
|
||||
#include "georgesform_model.h"
|
||||
#include "georgesform_proxy_model.h"
|
||||
#include "formitem.h"
|
||||
|
@ -46,6 +47,8 @@ namespace NLQT
|
|||
CGeorgesTreeViewDialog::CGeorgesTreeViewDialog(QWidget *parent /*= 0*/, bool emptyView /*= false*/)
|
||||
: QDockWidget(parent)
|
||||
{
|
||||
_georges = new NLQT::CGeorges;
|
||||
|
||||
loadedForm = "";
|
||||
_modified = false;
|
||||
|
||||
|
@ -84,7 +87,7 @@ namespace NLQT
|
|||
|
||||
void CGeorgesTreeViewDialog::selectedForm(QString formName)
|
||||
{
|
||||
_form = Modules::georges().loadForm(formName.toStdString());
|
||||
_form = _georges->loadForm(formName.toStdString());
|
||||
|
||||
if (_form)
|
||||
{
|
||||
|
@ -276,9 +279,9 @@ namespace NLQT
|
|||
{
|
||||
if (path.contains(".shape"))
|
||||
{
|
||||
Modules::objView().resetScene();
|
||||
Modules::objViewInt().resetScene();
|
||||
//Modules::config().configRemapExtensions();
|
||||
Modules::objView().loadMesh(path.toStdString(),"");
|
||||
Modules::objViewInt().loadMesh(path.toStdString(),"");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,6 +40,8 @@ using namespace NLGEORGES;
|
|||
namespace NLQT
|
||||
{
|
||||
|
||||
class CGeorges;
|
||||
|
||||
class CGeorgesTreeViewDialog: public QDockWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -71,6 +73,7 @@ namespace NLQT
|
|||
private:
|
||||
Ui::CGeorgesTreeViewDialog _ui;
|
||||
UForm *_form;
|
||||
NLQT::CGeorges *_georges;
|
||||
|
||||
bool _modified;
|
||||
|
||||
|
|
|
@ -18,30 +18,59 @@
|
|||
|
||||
#include "modules.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QPluginLoader>
|
||||
#include <QDir>
|
||||
#include <QString>
|
||||
|
||||
NLQT::CConfiguration *Modules::_configuration = NULL;
|
||||
NLQT::CObjectViewer *Modules::_objectViewer = NULL;
|
||||
NLQT::CObjectViewerWidget *Modules::_objectViewerWidget = NULL;
|
||||
NLQT::CGeorges *Modules::_georges = NULL;
|
||||
NLQT::IObjectViewer *Modules::_objViewerInterface = NULL;
|
||||
NLQT::CMainWindow *Modules::_mainWindow = NULL;
|
||||
|
||||
void Modules::init()
|
||||
{
|
||||
loadPlugin();
|
||||
|
||||
if (_configuration == NULL) _configuration = new NLQT::CConfiguration;
|
||||
config().init();
|
||||
|
||||
if (_objectViewer == NULL) _objectViewer = new NLQT::CObjectViewer;
|
||||
if (_objectViewerWidget == NULL) _objectViewerWidget = new NLQT::CObjectViewerWidget;
|
||||
if (_georges == NULL) _georges = new NLQT::CGeorges;
|
||||
if (_mainWindow == NULL) _mainWindow = new NLQT::CMainWindow;
|
||||
}
|
||||
|
||||
void Modules::release()
|
||||
{
|
||||
delete _mainWindow; _mainWindow = NULL;
|
||||
delete _objectViewer; _objectViewer = NULL;
|
||||
//delete _objectViewerWidget; _objectViewerWidget = NULL;
|
||||
delete _georges; _georges = NULL;
|
||||
|
||||
config().release();
|
||||
delete _configuration; _configuration = NULL;
|
||||
}
|
||||
|
||||
bool Modules::loadPlugin()
|
||||
{
|
||||
QDir pluginsDir(qApp->applicationDirPath());
|
||||
/*#if defined(Q_OS_WIN)
|
||||
if (pluginsDir.dirName().toLower() == "debug" || pluginsDir.dirName().toLower() == "release")
|
||||
pluginsDir.cdUp();
|
||||
#elif defined(Q_OS_MAC)
|
||||
if (pluginsDir.dirName() == "MacOS") {
|
||||
pluginsDir.cdUp();
|
||||
pluginsDir.cdUp();
|
||||
pluginsDir.cdUp();
|
||||
}
|
||||
#endif*/
|
||||
//pluginsDir.cd("plugins");
|
||||
//Q_FOREACH (QString fileName, pluginsDir.entryList(QDir::Files)) {
|
||||
QPluginLoader pluginLoader(pluginsDir.absoluteFilePath("object_viewer_widget_qt.dll"));
|
||||
QObject *plugin = pluginLoader.instance();
|
||||
if (plugin) {
|
||||
_objViewerInterface = qobject_cast<NLQT::IObjectViewer *>(plugin);
|
||||
if (_objViewerInterface)
|
||||
return true;
|
||||
}
|
||||
//}
|
||||
|
||||
return false;
|
||||
}
|
|
@ -20,10 +20,11 @@
|
|||
#define MODULES_H
|
||||
|
||||
#include "configuration.h"
|
||||
#include "object_viewer.h"
|
||||
//#include "object_viewer.h"
|
||||
#include "object_viewer_widget.h"
|
||||
#include "main_window.h"
|
||||
#include "georges.h"
|
||||
|
||||
#include "interfaces.h"
|
||||
|
||||
class Modules
|
||||
{
|
||||
|
@ -32,16 +33,19 @@ public:
|
|||
static void release();
|
||||
|
||||
static NLQT::CConfiguration &config() { return *_configuration; }
|
||||
static NLQT::CObjectViewer &objView() { return *_objectViewer; }
|
||||
static NLQT::IObjectViewer &objViewInt() { return *_objViewerInterface; }
|
||||
static NLQT::CObjectViewerWidget &objViewWid() { return *_objectViewerWidget; }
|
||||
static NLQT::CGeorges &georges() { return *_georges;}
|
||||
//static NLQT::CGeorges &georges() { return *_georges;}
|
||||
static NLQT::CMainWindow &mainWin() { return *_mainWindow; }
|
||||
private:
|
||||
static bool loadPlugin();
|
||||
static NLQT::IObjectViewer *_objViewerInterface;
|
||||
|
||||
static NLQT::CConfiguration *_configuration;
|
||||
static NLQT::CObjectViewer *_objectViewer;
|
||||
//static NLQT::CObjectViewer *_objectViewer;
|
||||
static NLQT::CObjectViewerWidget *_objectViewerWidget;
|
||||
static NLQT::CMainWindow *_mainWindow;
|
||||
static NLQT::CGeorges *_georges;
|
||||
//static NLQT::CGeorges *_georges;
|
||||
};
|
||||
|
||||
#endif // MODULES_H
|
||||
|
|
|
@ -21,17 +21,51 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
// STL includes
|
||||
|
||||
// NeL includes
|
||||
#include <nel/misc/common.h>
|
||||
#include <nel/misc/debug.h>
|
||||
#include <nel/misc/file.h>
|
||||
#include <nel/misc/bitmap.h>
|
||||
#include <nel/misc/path.h>
|
||||
#include <nel/3d/u_driver.h>
|
||||
#include <nel/3d/driver_user.h>
|
||||
#include <nel/3d/u_text_context.h>
|
||||
#include <nel/3d/u_scene.h>
|
||||
#include <nel/3d/u_light.h>
|
||||
#include <nel/3d/u_camera.h>
|
||||
#include <nel/3d/u_instance.h>
|
||||
#include <nel/3d/u_skeleton.h>
|
||||
#include <nel/3d/u_play_list.h>
|
||||
#include <nel/3d/u_animation_set.h>
|
||||
#include <nel/3d/u_animation.h>
|
||||
#include <nel/3d/u_play_list_manager.h>
|
||||
#include <nel/3d/u_3d_mouse_listener.h>
|
||||
#include <nel/3d/bloom_effect.h>
|
||||
|
||||
// Project includes
|
||||
#include "modules.h"
|
||||
|
||||
using namespace NLMISC;
|
||||
using namespace NL3D;
|
||||
using namespace std;
|
||||
|
||||
namespace NLQT
|
||||
{
|
||||
|
||||
CObjectViewerWidget::CObjectViewerWidget()
|
||||
CObjectViewerWidget::CObjectViewerWidget(QWidget *parent)
|
||||
: _isGraphicsInitialized(false), _isGraphicsEnabled(false),
|
||||
_Driver(NULL), _Light(0), _phi(0), _psi(0),_dist(2),
|
||||
_CameraFocal(75), _CurrentInstance(""), _BloomEffect(false),
|
||||
_Scene(0), QWidget(parent)
|
||||
{
|
||||
_isGraphicsEnabled = true;
|
||||
|
||||
// As a special case, a QTimer with a timeout of 0 will time out as soon as all the events in the window system's event queue have been processed.
|
||||
// This can be used to do heavy work while providing a snappy user interface.
|
||||
_mainTimer = new QTimer(this);
|
||||
connect(_mainTimer, SIGNAL(timeout()), this, SLOT(updateRender()));
|
||||
// timer->start(); // <- timeout 0
|
||||
// it's heavy on cpu, though, when no 3d driver initialized :)
|
||||
_mainTimer->start(25); // 25fps
|
||||
}
|
||||
|
||||
CObjectViewerWidget::~CObjectViewerWidget()
|
||||
|
@ -39,6 +73,372 @@ namespace NLQT
|
|||
|
||||
}
|
||||
|
||||
void CObjectViewerWidget::init()
|
||||
{
|
||||
connect(this, SIGNAL(topLevelChanged(bool)),
|
||||
this, SLOT(topLevelChanged(bool)));
|
||||
//H_AUTO2
|
||||
//nldebug("%d %d %d",_nlw->winId(), width(), height());
|
||||
|
||||
#if defined(NL_OS_UNIX) && !defined(NL_OS_MAC)
|
||||
dynamic_cast<QNLWidget*>(widget())->makeCurrent();
|
||||
#endif // defined(NL_OS_UNIX) && !defined(NL_OS_MAC)
|
||||
|
||||
nlWindow wnd = winId();
|
||||
uint16 w = width();
|
||||
uint16 h = height();
|
||||
|
||||
setMouseTracking(true);
|
||||
|
||||
// set background color from config
|
||||
NLMISC::CConfigFile::CVar v = Modules::config().getConfigFile().getVar("BackgroundColor");
|
||||
_BackgroundColor = CRGBA(v.asInt(0), v.asInt(1), v.asInt(2));
|
||||
|
||||
// set graphics driver from config
|
||||
NLMISC::CConfigFile::CVar v2 = Modules::config().getConfigFile().getVar("GraphicsDriver");
|
||||
// Choose driver opengl to work correctly under Linux example
|
||||
_Direct3D = false; //_Driver = OpenGL;
|
||||
|
||||
#ifdef NL_OS_WINDOWS
|
||||
std::string driver = v2.asString();
|
||||
if (driver == "Direct3D") _Direct3D = true; //m_Driver = Direct3D;
|
||||
else if (driver == "OpenGL") _Direct3D = false; //m_Driver = OpenGL;
|
||||
else nlwarning("Invalid driver specified, defaulting to OpenGL");
|
||||
#endif
|
||||
|
||||
//Modules::config().setAndCallback("CameraFocal",CConfigCallback(this,&CObjectViewer::cfcbCameraFocal));
|
||||
//Modules::config().setAndCallback("BloomEffect",CConfigCallback(this,&CObjectViewer::cfcbBloomEffect));
|
||||
|
||||
// create the driver
|
||||
nlassert(!_Driver);
|
||||
|
||||
_Driver = UDriver::createDriver(0, _Direct3D, 0);
|
||||
nlassert(_Driver);
|
||||
|
||||
// initialize the window with config file values
|
||||
_Driver->setDisplay(wnd, NL3D::UDriver::CMode(w, h, 32));
|
||||
|
||||
//_Light = ULight::createLight();
|
||||
|
||||
//// set mode of the light
|
||||
//_Light->setMode(ULight::DirectionalLight);
|
||||
|
||||
//// set position of the light
|
||||
//_Light->setPosition(CVector(-20.f, 30.f, 10.f));
|
||||
|
||||
//// white light
|
||||
//_Light->setAmbiant(CRGBA(255, 255, 255));
|
||||
|
||||
//// set and enable the light
|
||||
//_Driver->setLight(0, *_Light);
|
||||
//_Driver->enableLight(0);
|
||||
|
||||
// Create a scene
|
||||
_Scene = _Driver->createScene(true);
|
||||
|
||||
_PlayListManager = _Scene->createPlayListManager();
|
||||
|
||||
//_Scene->enableLightingSystem(true);
|
||||
|
||||
// create the camera
|
||||
UCamera camera = _Scene->getCam();
|
||||
|
||||
camera.setTransformMode (UTransformable::DirectMatrix);
|
||||
|
||||
setSizeViewport(w, h);
|
||||
|
||||
// camera will look at entities
|
||||
camera.lookAt(NLMISC::CVector(_dist,0,1), NLMISC::CVector(0,0,0.5));
|
||||
|
||||
NLMISC::CVector hotSpot=NLMISC::CVector(0,0,0);
|
||||
|
||||
_MouseListener = _Driver->create3dMouseListener();
|
||||
_MouseListener->setMatrix(_Scene->getCam().getMatrix());
|
||||
_MouseListener->setFrustrum(_Scene->getCam().getFrustum());
|
||||
_MouseListener->setHotSpot(hotSpot);
|
||||
_MouseListener->setMouseMode(U3dMouseListener::edit3d);
|
||||
|
||||
NL3D::CBloomEffect::instance().setDriver(_Driver);
|
||||
NL3D::CBloomEffect::instance().setScene(_Scene);
|
||||
NL3D::CBloomEffect::instance().init(!_Direct3D);
|
||||
//NL3D::CBloomEffect::instance().setDensityBloom(Modules::config().getConfigFile().getVar("BloomDensity").asInt());
|
||||
//NL3D::CBloomEffect::instance().setSquareBloom(Modules::config().getConfigFile().getVar("BloomSquare").asBool());
|
||||
}
|
||||
|
||||
void CObjectViewerWidget::release()
|
||||
{
|
||||
//H_AUTO2
|
||||
nldebug("");
|
||||
|
||||
_Driver->delete3dMouseListener(_MouseListener);
|
||||
|
||||
// delete all entities
|
||||
deleteEntities();
|
||||
|
||||
_Scene->deletePlayListManager(_PlayListManager);
|
||||
|
||||
// delete the scene
|
||||
_Driver->deleteScene(_Scene);
|
||||
|
||||
// delete the light
|
||||
delete _Light;
|
||||
|
||||
// release driver
|
||||
nlassert(_Driver);
|
||||
_Driver->release();
|
||||
delete _Driver;
|
||||
_Driver = NULL;
|
||||
}
|
||||
|
||||
void CObjectViewerWidget::updateRender()
|
||||
{
|
||||
//nldebug("CMainWindow::updateRender");
|
||||
updateInitialization(isVisible());
|
||||
|
||||
//QModelIndex index = _dirModel->setRootPath("D:/Dev/Ryzom/code/ryzom/common/data_leveldesign/leveldesign");
|
||||
//_dirTree->setRootIndex(index);
|
||||
|
||||
if (isVisible())
|
||||
{
|
||||
// call all update functions
|
||||
// 01. Update Utilities (configuration etc)
|
||||
|
||||
// 02. Update Time (deltas)
|
||||
// ...
|
||||
|
||||
// 03. Update Receive (network, servertime, receive messages)
|
||||
// ...
|
||||
|
||||
// 04. Update Input (keyboard controls, etc)
|
||||
if (_isGraphicsInitialized)
|
||||
updateInput();
|
||||
|
||||
// 05. Update Weather (sky, snow, wind, fog, sun)
|
||||
// ...
|
||||
|
||||
// 06. Update Entities (movement, do after possible tp from incoming messages etc)
|
||||
// - Move other entities
|
||||
// - Update self entity
|
||||
// - Move bullets
|
||||
// ...
|
||||
|
||||
// 07. Update Landscape (async zone loading near entity)
|
||||
// ...
|
||||
|
||||
// 08. Update Collisions (entities)
|
||||
// - Update entities
|
||||
// - Update move container (swap with Update entities? todo: check code!)
|
||||
// - Update bullets
|
||||
// ...
|
||||
|
||||
// 09. Update Animations (playlists)
|
||||
// - Needs to be either before or after entities, not sure,
|
||||
// there was a problem with wrong order a while ago!!!
|
||||
|
||||
|
||||
//updateAnimation(_AnimationDialog->getTime());
|
||||
|
||||
// 10. Update Camera (depends on entities)
|
||||
// ...
|
||||
|
||||
// 11. Update Interface (login, ui, etc)
|
||||
// ...
|
||||
|
||||
// 12. Update Sound (sound driver)
|
||||
// ...
|
||||
|
||||
// 13. Update Send (network, send new position etc)
|
||||
// ...
|
||||
|
||||
// 14. Update Debug (stuff for dev)
|
||||
// ...
|
||||
|
||||
if (_isGraphicsInitialized && !getDriver()->isLost())
|
||||
{
|
||||
// 01. Render Driver (background color)
|
||||
renderDriver(); // clear all buffers
|
||||
|
||||
// 02. Render Sky (sky scene)
|
||||
// ...
|
||||
|
||||
// 04. Render Scene (entity scene)
|
||||
renderScene();
|
||||
|
||||
// 05. Render Effects (flare)
|
||||
// ...
|
||||
|
||||
// 06. Render Interface 3D (player names)
|
||||
// ...
|
||||
|
||||
// 07. Render Debug 3D
|
||||
// ...
|
||||
|
||||
// 08. Render Interface 2D (chatboxes etc, optionally does have 3d)
|
||||
// ...
|
||||
|
||||
// 09. Render Debug 2D (stuff for dev)
|
||||
renderDebug2D();
|
||||
|
||||
// swap 3d buffers
|
||||
getDriver()->swapBuffers();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CObjectViewerWidget::updateInitialization(bool visible)
|
||||
{
|
||||
//nldebug("CMainWindow::updateInitialization");
|
||||
bool done;
|
||||
do
|
||||
{
|
||||
done = true; // set false whenever change
|
||||
bool wantGraphics = _isGraphicsEnabled && visible;
|
||||
// bool wantLandscape = wantGraphics && m_IsGraphicsInitialized && isLandscapeEnabled;
|
||||
|
||||
// .. stuff that depends on other stuff goes on top to prioritize deinitialization
|
||||
|
||||
// Landscape
|
||||
// ...
|
||||
|
||||
// Graphics (Driver)
|
||||
if (_isGraphicsInitialized)
|
||||
{
|
||||
if (!wantGraphics)
|
||||
{
|
||||
//_isGraphicsInitialized = false;
|
||||
//release();
|
||||
_mainTimer->stop();
|
||||
//done = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (wantGraphics)
|
||||
{
|
||||
init();
|
||||
_isGraphicsInitialized = true;
|
||||
_mainTimer->start(25);
|
||||
//done = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
while (!done);
|
||||
}
|
||||
|
||||
void CObjectViewerWidget::updateInput()
|
||||
{
|
||||
_Driver->EventServer.pump();
|
||||
|
||||
// New matrix from camera
|
||||
_Scene->getCam().setTransformMode(NL3D::UTransformable::DirectMatrix);
|
||||
_Scene->getCam().setMatrix (_MouseListener->getViewMatrix());
|
||||
|
||||
//nldebug("%s",_Scene->getCam().getMatrix().getPos().asString().c_str());
|
||||
}
|
||||
|
||||
void CObjectViewerWidget::renderDriver()
|
||||
{
|
||||
// Render the scene.
|
||||
if((NL3D::CBloomEffect::instance().getDriver() != NULL) && (_BloomEffect))
|
||||
{
|
||||
NL3D::CBloomEffect::instance().initBloom();
|
||||
}
|
||||
_Driver->clearBuffers(_BackgroundColor);
|
||||
}
|
||||
|
||||
void CObjectViewerWidget::renderScene()
|
||||
{
|
||||
// render the scene
|
||||
_Scene->render();
|
||||
|
||||
if((NL3D::CBloomEffect::instance().getDriver() != NULL) && (_BloomEffect))
|
||||
{
|
||||
NL3D::CBloomEffect::instance().endBloom();
|
||||
NL3D::CBloomEffect::instance().endInterfacesDisplayBloom();
|
||||
}
|
||||
}
|
||||
|
||||
void CObjectViewerWidget::renderDebug2D()
|
||||
{
|
||||
}
|
||||
|
||||
void CObjectViewerWidget::saveScreenshot(const std::string &nameFile, bool jpg, bool png, bool tga)
|
||||
{
|
||||
//H_AUTO2
|
||||
|
||||
// FIXME: create screenshot path if it doesn't exist!
|
||||
|
||||
// empty bitmap
|
||||
CBitmap bitmap;
|
||||
// copy the driver buffer to the bitmap
|
||||
_Driver->getBuffer(bitmap);
|
||||
// create the file name
|
||||
string filename = std::string("./") + nameFile;
|
||||
// write the bitmap as a jpg, png or tga to the file
|
||||
if (jpg)
|
||||
{
|
||||
string newfilename = CFile::findNewFile(filename + ".jpg");
|
||||
COFile outputFile(newfilename);
|
||||
bitmap.writeJPG(outputFile, 100);
|
||||
nlinfo("Screenshot '%s' saved", newfilename.c_str());
|
||||
}
|
||||
if (png)
|
||||
{
|
||||
string newfilename = CFile::findNewFile(filename + ".png");
|
||||
COFile outputFile(newfilename);
|
||||
bitmap.writePNG(outputFile, 24);
|
||||
nlinfo("Screenshot '%s' saved", newfilename.c_str());
|
||||
}
|
||||
if (tga)
|
||||
{
|
||||
string newfilename = CFile::findNewFile(filename + ".tga");
|
||||
COFile outputFile(newfilename);
|
||||
bitmap.writeTGA(outputFile, 24, false);
|
||||
nlinfo("Screenshot '%s' saved", newfilename.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
bool CObjectViewerWidget::loadMesh(const std::string &meshFileName, const std::string &skelFileName)
|
||||
{
|
||||
std::string fileName = CFile::getFilenameWithoutExtension(meshFileName);
|
||||
if ( _Entities.count(fileName) != 0)
|
||||
return false;
|
||||
|
||||
CPath::addSearchPath(CFile::getPath(meshFileName), false, false);
|
||||
|
||||
// create instance of the mesh character
|
||||
UInstance Entity = _Scene->createInstance(meshFileName);
|
||||
|
||||
CAABBox bbox;
|
||||
Entity.getShapeAABBox(bbox);
|
||||
setCamera(bbox , Entity, true);
|
||||
|
||||
_MouseListener->setMatrix(_Scene->getCam().getMatrix());
|
||||
|
||||
USkeleton Skeleton = _Scene->createSkeleton(skelFileName);
|
||||
|
||||
// if we can't create entity, skip it
|
||||
if (Entity.empty()) return false;
|
||||
|
||||
// create a new entity
|
||||
EIT eit = (_Entities.insert (make_pair (fileName, CEntity()))).first;
|
||||
CEntity &entity = (*eit).second;
|
||||
|
||||
// set the entity up
|
||||
entity._Name = fileName;
|
||||
entity._FileNameShape = meshFileName;
|
||||
entity._FileNameSkeleton = skelFileName;
|
||||
entity._Instance = Entity;
|
||||
if (!Skeleton.empty())
|
||||
{
|
||||
entity._Skeleton = Skeleton;
|
||||
entity._Skeleton.bindSkin (entity._Instance);
|
||||
}
|
||||
entity._AnimationSet = _Driver->createAnimationSet(false);
|
||||
entity._PlayList = _PlayListManager->createPlayList(entity._AnimationSet);
|
||||
return true;
|
||||
}
|
||||
|
||||
void CObjectViewerWidget::setVisible(bool visible)
|
||||
{
|
||||
// called by show()
|
||||
|
@ -54,16 +454,253 @@ namespace NLQT
|
|||
}
|
||||
}
|
||||
|
||||
void CObjectViewerWidget::resetScene()
|
||||
{
|
||||
deleteEntities();
|
||||
|
||||
// Reset camera.
|
||||
//..
|
||||
|
||||
// to load files with the same name but located in different directories
|
||||
//CPath::clearMap();
|
||||
|
||||
// load and set search paths from config
|
||||
//Modules::config().configSearchPaths();
|
||||
|
||||
_CurrentInstance = "";
|
||||
|
||||
nlinfo("Scene cleared");
|
||||
}
|
||||
|
||||
void CObjectViewerWidget::setBackgroundColor(NLMISC::CRGBA backgroundColor)
|
||||
{
|
||||
_BackgroundColor = backgroundColor;
|
||||
|
||||
// config file variable changes
|
||||
Modules::config().getConfigFile().getVar("BackgroundColor").setAsInt(_BackgroundColor.R, 0);
|
||||
Modules::config().getConfigFile().getVar("BackgroundColor").setAsInt(_BackgroundColor.G, 1);
|
||||
Modules::config().getConfigFile().getVar("BackgroundColor").setAsInt(_BackgroundColor.B, 2);
|
||||
}
|
||||
|
||||
void CObjectViewerWidget::setGraphicsDriver(bool Direct3D)
|
||||
{
|
||||
_Direct3D = Direct3D;
|
||||
|
||||
if (_Direct3D) Modules::config().getConfigFile().getVar("GraphicsDriver").setAsString("Direct3D");
|
||||
else Modules::config().getConfigFile().getVar("GraphicsDriver").setAsString("OpenGL");
|
||||
}
|
||||
|
||||
void CObjectViewerWidget::setSizeViewport(uint16 w, uint16 h)
|
||||
{
|
||||
_Scene->getCam().setPerspective(_CameraFocal * (float)Pi/180.f, (float)w/h, 0.1f, 1000);
|
||||
}
|
||||
|
||||
void CObjectViewerWidget::setCurrentObject(const std::string &name)
|
||||
{
|
||||
if ((_Entities.count(name) != 0) || ( name.empty() )) _CurrentInstance = name;
|
||||
else nlerror ("Entity %s not found", name.c_str());
|
||||
nlinfo("set current entity %s", _CurrentInstance.c_str());
|
||||
}
|
||||
|
||||
CEntity& CObjectViewerWidget::getEntity(const std::string &name)
|
||||
{
|
||||
if ( _Entities.count(name) == 0) nlerror("Entity %s not found", name.c_str());
|
||||
EIT eit = _Entities.find (name);
|
||||
return (*eit).second;
|
||||
}
|
||||
|
||||
void CObjectViewerWidget::getListObjects(std::vector<std::string> &listObj)
|
||||
{
|
||||
listObj.clear();
|
||||
for (EIT eit = _Entities.begin(); eit != _Entities.end(); ++eit)
|
||||
listObj.push_back((*eit).second._Name);
|
||||
}
|
||||
|
||||
void CObjectViewerWidget::deleteEntity(CEntity &entity)
|
||||
{
|
||||
if (entity._PlayList != NULL)
|
||||
{
|
||||
_PlayListManager->deletePlayList (entity._PlayList);
|
||||
entity._PlayList = NULL;
|
||||
}
|
||||
|
||||
if (entity._AnimationSet != NULL)
|
||||
{
|
||||
_Driver->deleteAnimationSet(entity._AnimationSet);
|
||||
entity._AnimationSet = NULL;
|
||||
}
|
||||
|
||||
if (!entity._Skeleton.empty())
|
||||
{
|
||||
entity._Skeleton.detachSkeletonSon(entity._Instance);
|
||||
|
||||
_Scene->deleteSkeleton(entity._Skeleton);
|
||||
entity._Skeleton = NULL;
|
||||
}
|
||||
|
||||
if (!entity._Instance.empty())
|
||||
{
|
||||
_Scene->deleteInstance(entity._Instance);
|
||||
entity._Instance = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void CObjectViewerWidget::deleteEntities()
|
||||
{
|
||||
for (EIT eit = _Entities.begin(); eit != _Entities.end(); ++eit)
|
||||
{
|
||||
CEntity &entity = (*eit).second;
|
||||
deleteEntity(entity);
|
||||
}
|
||||
_Entities.clear();
|
||||
}
|
||||
|
||||
void CObjectViewerWidget::setCamera(CAABBox &bbox, UTransform &entity, bool high_z)
|
||||
{
|
||||
CVector pos(0.f, 0.f, 0.f);
|
||||
CQuat quat(0.f, 0.f, 0.f, 0.f);
|
||||
NL3D::UInstance inst;
|
||||
inst.cast(entity);
|
||||
if (!inst.empty())
|
||||
{
|
||||
inst.getDefaultPos(pos);
|
||||
inst.getDefaultRotQuat(quat);
|
||||
/*
|
||||
if (quat.getAxis().isNull())
|
||||
{
|
||||
quat.set(0, 0, 0, 0);
|
||||
inst.setRotQuat(quat);
|
||||
}
|
||||
*/
|
||||
// quat.set(1.f, 1.f, 0.f, 0.f);
|
||||
|
||||
// inst.setRotQuat(quat);
|
||||
// inst.getRotQuat(quat);
|
||||
|
||||
// check for presence of all textures from each sets
|
||||
//bool allGood = true;
|
||||
|
||||
//for(uint s = 0; s < 5; ++s)
|
||||
//{
|
||||
// inst.selectTextureSet(s);
|
||||
|
||||
// uint numMat = inst.getNumMaterials();
|
||||
|
||||
// // by default, all textures are present
|
||||
// allGood = true;
|
||||
|
||||
// for(uint i = 0; i < numMat; ++i)
|
||||
// {
|
||||
// UInstanceMaterial mat = inst.getMaterial(i);
|
||||
|
||||
// for(sint j = 0; j <= mat.getLastTextureStage(); ++j)
|
||||
// {
|
||||
// // if a texture is missing
|
||||
// if (mat.isTextureFile(j) && mat.getTextureFileName(j) == "CTextureMultiFile:Dummy")
|
||||
// allGood = false;
|
||||
// }
|
||||
// }
|
||||
|
||||
// // if all textures have been found for this set, skip other sets
|
||||
// if (allGood)
|
||||
// break;
|
||||
//}
|
||||
}
|
||||
|
||||
// fix scale (some shapes have a different value)
|
||||
entity.setScale(1.f, 1.f, 1.f);
|
||||
|
||||
UCamera Camera = _Scene->getCam();
|
||||
CVector max_radius = bbox.getHalfSize();
|
||||
|
||||
CVector center = bbox.getCenter();
|
||||
entity.setPivot(center);
|
||||
center += pos;
|
||||
|
||||
//_Scene->getCam().setPerspective(_CameraFocal * (float)Pi/180.f, (float)w/h, 0.1f, 1000);
|
||||
float fov = float(_CameraFocal * (float)Pi/180.0);
|
||||
//Camera.setPerspective (fov, 1.0f, 0.1f, 1000.0f);
|
||||
float radius = max(max(max_radius.x, max_radius.y), max_radius.z);
|
||||
if (radius == 0.f) radius = 1.f;
|
||||
float left, right, bottom, top, znear, zfar;
|
||||
Camera.getFrustum(left, right, bottom, top, znear, zfar);
|
||||
float dist = radius / (tan(fov/2));
|
||||
CVector eye(center);
|
||||
/* if (axis == CVector::I)
|
||||
eye.y -= dist+radius;
|
||||
else if (axis == CVector::J)
|
||||
eye.x += dist+radius;
|
||||
*/
|
||||
// quat.normalize();
|
||||
|
||||
CVector ax(quat.getAxis());
|
||||
|
||||
// float angle = quat.getAngle();
|
||||
/*
|
||||
if (ax.isNull())
|
||||
{
|
||||
if (int(angle*100.f) == int(NLMISC::Pi * 200.f))
|
||||
{
|
||||
ax = CVector::J;
|
||||
}
|
||||
}
|
||||
else
|
||||
*/
|
||||
if (ax.isNull() || ax == CVector::I)
|
||||
{
|
||||
ax = CVector::J;
|
||||
}
|
||||
else if (ax == -CVector::K)
|
||||
{
|
||||
ax = -CVector::J;
|
||||
}
|
||||
/* else if (ax.x < -0.9f && ax.y == 0.f && ax.z == 0.f)
|
||||
{
|
||||
ax = -CVector::J ;
|
||||
}
|
||||
*/
|
||||
// ax.normalize();
|
||||
|
||||
eye -= ax * (dist+radius);
|
||||
if (high_z)
|
||||
eye.z += max_radius.z/1.0f;
|
||||
Camera.lookAt(eye, center);
|
||||
setupLight(eye, center - eye);
|
||||
}
|
||||
|
||||
bool CObjectViewerWidget::setupLight(const CVector &position, const CVector &direction)
|
||||
{
|
||||
if (!_Light)
|
||||
_Light = ULight::createLight();
|
||||
if (!_Light) return false;
|
||||
|
||||
// set mode of the light
|
||||
_Light->setMode(ULight::DirectionalLight);
|
||||
|
||||
// set position of the light
|
||||
// Light->setupDirectional(settings.light_ambiant, settings.light_diffuse, settings.light_specular, settings.light_direction);
|
||||
NLMISC::CRGBA light_ambiant = CRGBA(0,0,0);
|
||||
NLMISC::CRGBA light_diffuse = CRGBA(255,255,255);
|
||||
NLMISC::CRGBA light_specular = CRGBA(255,255,255);
|
||||
NLMISC::CVector light_direction = CVector(0.25, 0.25, 0.25);
|
||||
_Light->setupPointLight(light_ambiant, light_diffuse, light_specular, position, direction + light_direction);
|
||||
|
||||
// set and enable the light
|
||||
_Driver->setLight(0, *_Light);
|
||||
_Driver->enableLight(0);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#if defined(NL_OS_WINDOWS)
|
||||
|
||||
typedef bool (*winProc)(NL3D::IDriver *driver, HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
|
||||
|
||||
bool CObjectViewerWidget::winEvent(MSG * message, long * result)
|
||||
{
|
||||
if (Modules::objView().getDriver() &&
|
||||
Modules::objView().getDriver()->isActive())
|
||||
if (getDriver() && getDriver()->isActive())
|
||||
{
|
||||
NL3D::IDriver *driver = dynamic_cast<NL3D::CDriverUser*>(Modules::objView().getDriver())->getDriver();
|
||||
NL3D::IDriver *driver = dynamic_cast<NL3D::CDriverUser*>(getDriver())->getDriver();
|
||||
if (driver)
|
||||
{
|
||||
winProc proc = (winProc)driver->getWindowProc();
|
||||
|
@ -83,9 +720,9 @@ namespace NLQT
|
|||
if(caller)
|
||||
nlerror("You are using QtCarbon! Only QtCocoa supported, please upgrade Qt");
|
||||
|
||||
if (Modules::objView().getDriver() && Modules::objView().getDriver()->isActive())
|
||||
if (getDriver() && getDriver()->isActive())
|
||||
{
|
||||
NL3D::IDriver *driver = dynamic_cast<NL3D::CDriverUser*>(Modules::objView().getDriver())->getDriver();
|
||||
NL3D::IDriver *driver = dynamic_cast<NL3D::CDriverUser*>(getDriver())->getDriver();
|
||||
if (driver)
|
||||
{
|
||||
cocoaProc proc = (cocoaProc)driver->getWindowProc();
|
||||
|
@ -102,9 +739,9 @@ namespace NLQT
|
|||
|
||||
bool CObjectViewerWidget::x11Event(XEvent *event)
|
||||
{
|
||||
if (Modules::objView().getDriver() && Modules::objView().getDriver()->isActive())
|
||||
if (getDriver() && getDriver()->isActive())
|
||||
{
|
||||
NL3D::IDriver *driver = dynamic_cast<NL3D::CDriverUser*>(Modules::objView().getDriver())->getDriver();
|
||||
NL3D::IDriver *driver = dynamic_cast<NL3D::CDriverUser*>(getDriver())->getDriver();
|
||||
if (driver)
|
||||
{
|
||||
x11Proc proc = (x11Proc)driver->getWindowProc();
|
||||
|
|
|
@ -21,12 +21,28 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
|
||||
// STL includes
|
||||
|
||||
// NeL includes
|
||||
|
||||
// Qt includes
|
||||
#include <QtOpenGL/QGLWidget>
|
||||
#include <QTimer>
|
||||
|
||||
// NeL includes
|
||||
#include <nel/misc/rgba.h>
|
||||
#include <nel/misc/aabbox.h>
|
||||
|
||||
// Project includes
|
||||
#include "entity.h"
|
||||
|
||||
namespace NL3D
|
||||
{
|
||||
class UDriver;
|
||||
class UScene;
|
||||
class ULight;
|
||||
class UInstance;
|
||||
class UCamera;
|
||||
class USkeleton;
|
||||
class UPlayListManager;
|
||||
class U3dMouseListener;
|
||||
}
|
||||
|
||||
/**
|
||||
namespace NLQT
|
||||
|
@ -40,9 +56,104 @@ namespace NLQT
|
|||
|
||||
public:
|
||||
/// Default constructor.
|
||||
CObjectViewerWidget();
|
||||
CObjectViewerWidget(QWidget *parent = 0);
|
||||
virtual ~CObjectViewerWidget();
|
||||
|
||||
/// Init a driver and create scene.
|
||||
/// @param wnd - handle window.
|
||||
/// @param w - width window.
|
||||
/// @param h - height window.
|
||||
void init();
|
||||
|
||||
/// Release class.
|
||||
void release();
|
||||
|
||||
/// Update mouse and keyboard events. And update camera matrix.
|
||||
void updateInput();
|
||||
|
||||
/// Render Driver (clear all buffers and set background color).
|
||||
void renderDriver();
|
||||
|
||||
/// Render current scene.
|
||||
void renderScene();
|
||||
|
||||
/// Render Debug 2D (stuff for dev).
|
||||
void renderDebug2D();
|
||||
|
||||
/// Make a screenshot of the current scene and save.
|
||||
void saveScreenshot(const std::string &nameFile, bool jpg, bool png, bool tga);
|
||||
|
||||
/// Load a mesh or particle system and add to current scene.
|
||||
/// @param meshFileName - name loading shape or ps file.
|
||||
/// @param skelFileName - name loading skeletin file.
|
||||
/// @return true if file have been loaded, false if file have not been loaded.
|
||||
bool loadMesh (const std::string &meshFileName, const std::string &skelFileName);
|
||||
|
||||
/// Reset current scene.
|
||||
void resetScene();
|
||||
|
||||
/// Update the navigation camera.
|
||||
/// @param deltaPsi - delta angle horizontal (radians).
|
||||
/// @param deltaPhi - delta angle vertical (radians).
|
||||
/// @param deltaDist - delta distance.
|
||||
void updateCamera(float deltaPsi, float deltaPhi, float deltaDist);
|
||||
|
||||
/// Set the background color.
|
||||
/// @param backgroundColor - background color.
|
||||
void setBackgroundColor(NLMISC::CRGBA backgroundColor);
|
||||
|
||||
/// Set type driver.
|
||||
/// @param Direct3D - type driver (true - Direct3D) or (false -OpenGL)
|
||||
void setGraphicsDriver(bool Direct3D);
|
||||
|
||||
/// Set size viewport for correct set perspective
|
||||
/// @param w - width window.
|
||||
/// @param h - height window.
|
||||
void setSizeViewport(uint16 w, uint16 h);
|
||||
|
||||
void setBloomEffect(bool enabled) { _BloomEffect = enabled; }
|
||||
|
||||
/// Select instance from the scene
|
||||
/// @param name - name instance, "" if no instance edited
|
||||
void setCurrentObject(const std::string &name);
|
||||
|
||||
/// Get current instance from the scene
|
||||
/// @return name current instance, "" if no instance edited
|
||||
const std::string& getCurrentObject() { return _CurrentInstance; }
|
||||
|
||||
/// Get entity from the scene
|
||||
/// @return ref Entity
|
||||
CEntity& getEntity(const std::string &name);
|
||||
|
||||
/// Get full list instances from the scene
|
||||
/// @param listObj - ref of return list instances
|
||||
void getListObjects(std::vector<std::string> &listObj);
|
||||
|
||||
/// Get value background color.
|
||||
/// @return background color.
|
||||
NLMISC::CRGBA getBackgroundColor() { return _BackgroundColor; }
|
||||
|
||||
/// Get type driver.
|
||||
/// @return true if have used Direct3D driver, false OpenGL driver.
|
||||
inline bool getDirect3D() { return _Direct3D; }
|
||||
|
||||
inline bool getBloomEffect() const { return _BloomEffect; }
|
||||
|
||||
/// Get a pointer to the driver.
|
||||
/// @return pointer to the driver.
|
||||
inline NL3D::UDriver *getDriver() { return _Driver; }
|
||||
|
||||
/// Get a pointer to the scene.
|
||||
/// @return pointer to the scene.
|
||||
inline NL3D::UScene *getScene() { return _Scene; }
|
||||
|
||||
/// Get a manager of playlist
|
||||
/// @return pointer to the UPlayListManager
|
||||
inline NL3D::UPlayListManager *getPlayListManager() { return _PlayListManager; }
|
||||
|
||||
void setCamera(NLMISC::CAABBox &bbox, NL3D::UTransform &entity, bool high_z);
|
||||
bool setupLight(const NLMISC::CVector &position, const NLMISC::CVector &direction);
|
||||
|
||||
virtual void setVisible(bool visible);
|
||||
|
||||
protected:
|
||||
|
@ -54,6 +165,45 @@ namespace NLQT
|
|||
virtual bool x11Event(XEvent *event);
|
||||
#endif
|
||||
|
||||
private Q_SLOTS:
|
||||
void updateRender();
|
||||
|
||||
private:
|
||||
// render stuff
|
||||
QTimer *_mainTimer;
|
||||
bool _isGraphicsInitialized, _isGraphicsEnabled;
|
||||
|
||||
void updateInitialization(bool visible);
|
||||
|
||||
void deleteEntity (CEntity &entity);
|
||||
|
||||
/// Delete all entities
|
||||
void deleteEntities();
|
||||
|
||||
NLMISC::CRGBA _BackgroundColor;
|
||||
|
||||
NL3D::UDriver *_Driver;
|
||||
NL3D::UScene *_Scene;
|
||||
NL3D::UPlayListManager *_PlayListManager;
|
||||
NL3D::ULight *_Light;
|
||||
NL3D::UCamera *_Camera;
|
||||
NL3D::U3dMouseListener *_MouseListener;
|
||||
|
||||
// The entities storage
|
||||
CEntities _Entities;
|
||||
|
||||
/// Camera parameters.
|
||||
float _phi, _psi, _dist;
|
||||
float _CameraFocal;
|
||||
|
||||
bool _Direct3D;
|
||||
bool _BloomEffect;
|
||||
|
||||
std::string _CurrentInstance;
|
||||
|
||||
// a temporary solution, and later remove
|
||||
friend class CAnimationSetDialog;
|
||||
|
||||
};/* class CObjectViewerWidget */
|
||||
|
||||
} /* namespace NLQT */
|
||||
|
|
|
@ -42,55 +42,17 @@ namespace NLQT
|
|||
{
|
||||
|
||||
CObjectViewerDialog::CObjectViewerDialog(QWidget *parent)
|
||||
: _isGraphicsInitialized(false), _isGraphicsEnabled(false), QDockWidget(parent)
|
||||
: QDockWidget(parent)
|
||||
{
|
||||
_ui.setupUi(this);
|
||||
|
||||
// _nlw = new QNLWidget(_ui.dockWidgetContents);
|
||||
_nlw = &Modules::objViewWid();
|
||||
_nlw = Modules::objViewInt().getWidget();
|
||||
//_nlw->setObjectName(QString::fromUtf8("nlwidget"));
|
||||
_ui.gridLayout->addWidget(_nlw, 0, 0);
|
||||
|
||||
//nlw->setLayout(new QGridLayout(nlw));
|
||||
//_ui.widget = nlw;
|
||||
//QWidget * w = widget();
|
||||
|
||||
_isGraphicsEnabled = true;
|
||||
|
||||
// As a special case, a QTimer with a timeout of 0 will time out as soon as all the events in the window system's event queue have been processed.
|
||||
// This can be used to do heavy work while providing a snappy user interface.
|
||||
_mainTimer = new QTimer(this);
|
||||
connect(_mainTimer, SIGNAL(timeout()), this, SLOT(updateRender()));
|
||||
// timer->start(); // <- timeout 0
|
||||
// it's heavy on cpu, though, when no 3d driver initialized :)
|
||||
_mainTimer->start(25); // 25fps
|
||||
}
|
||||
|
||||
CObjectViewerDialog::~CObjectViewerDialog()
|
||||
{
|
||||
_mainTimer->stop();
|
||||
}
|
||||
|
||||
void CObjectViewerDialog::init()
|
||||
{
|
||||
connect(this, SIGNAL(topLevelChanged(bool)),
|
||||
this, SLOT(topLevelChanged(bool)));
|
||||
//H_AUTO2
|
||||
//nldebug("%d %d %d",_nlw->winId(), width(), height());
|
||||
|
||||
#if defined(NL_OS_UNIX) && !defined(NL_OS_MAC)
|
||||
dynamic_cast<QNLWidget*>(widget())->makeCurrent();
|
||||
#endif // defined(NL_OS_UNIX) && !defined(NL_OS_MAC)
|
||||
|
||||
Modules::objView().init((nlWindow)_nlw->winId(), width(), height());
|
||||
setMouseTracking(true);
|
||||
}
|
||||
|
||||
void CObjectViewerDialog::release()
|
||||
{
|
||||
nldebug("");
|
||||
|
||||
Modules::objView().release();
|
||||
}
|
||||
|
||||
void CObjectViewerDialog::setVisible(bool visible)
|
||||
|
@ -101,7 +63,7 @@ namespace NLQT
|
|||
if (visible)
|
||||
{
|
||||
QDockWidget::setVisible(true);
|
||||
_mainTimer->start(25);
|
||||
//_mainTimer->start(25);
|
||||
//updateInitialization(true);
|
||||
//_nlw->show();
|
||||
}
|
||||
|
@ -112,182 +74,31 @@ namespace NLQT
|
|||
}
|
||||
}
|
||||
|
||||
void CObjectViewerDialog::updateInitialization(bool visible)
|
||||
{
|
||||
//nldebug("CMainWindow::updateInitialization");
|
||||
bool done;
|
||||
do
|
||||
{
|
||||
done = true; // set false whenever change
|
||||
bool wantGraphics = _isGraphicsEnabled && visible;
|
||||
// bool wantLandscape = wantGraphics && m_IsGraphicsInitialized && isLandscapeEnabled;
|
||||
|
||||
// .. stuff that depends on other stuff goes on top to prioritize deinitialization
|
||||
|
||||
// Landscape
|
||||
// ...
|
||||
|
||||
// Graphics (Driver)
|
||||
if (_isGraphicsInitialized)
|
||||
{
|
||||
if (!wantGraphics)
|
||||
{
|
||||
//_isGraphicsInitialized = false;
|
||||
//release();
|
||||
_mainTimer->stop();
|
||||
//done = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (wantGraphics)
|
||||
{
|
||||
init();
|
||||
_isGraphicsInitialized = true;
|
||||
_mainTimer->start(25);
|
||||
//done = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
while (!done);
|
||||
}
|
||||
|
||||
void CObjectViewerDialog::updateRender()
|
||||
{
|
||||
//nldebug("CMainWindow::updateRender");
|
||||
updateInitialization(isVisible());
|
||||
|
||||
//QModelIndex index = _dirModel->setRootPath("D:/Dev/Ryzom/code/ryzom/common/data_leveldesign/leveldesign");
|
||||
//_dirTree->setRootIndex(index);
|
||||
|
||||
if (isVisible())
|
||||
{
|
||||
// call all update functions
|
||||
// 01. Update Utilities (configuration etc)
|
||||
|
||||
// 02. Update Time (deltas)
|
||||
// ...
|
||||
|
||||
// 03. Update Receive (network, servertime, receive messages)
|
||||
// ...
|
||||
|
||||
// 04. Update Input (keyboard controls, etc)
|
||||
if (_isGraphicsInitialized)
|
||||
Modules::objView().updateInput();
|
||||
|
||||
// 05. Update Weather (sky, snow, wind, fog, sun)
|
||||
// ...
|
||||
|
||||
// 06. Update Entities (movement, do after possible tp from incoming messages etc)
|
||||
// - Move other entities
|
||||
// - Update self entity
|
||||
// - Move bullets
|
||||
// ...
|
||||
|
||||
// 07. Update Landscape (async zone loading near entity)
|
||||
// ...
|
||||
|
||||
// 08. Update Collisions (entities)
|
||||
// - Update entities
|
||||
// - Update move container (swap with Update entities? todo: check code!)
|
||||
// - Update bullets
|
||||
// ...
|
||||
|
||||
// 09. Update Animations (playlists)
|
||||
// - Needs to be either before or after entities, not sure,
|
||||
// there was a problem with wrong order a while ago!!!
|
||||
|
||||
|
||||
//Modules::objView().updateAnimation(_AnimationDialog->getTime());
|
||||
|
||||
// 10. Update Camera (depends on entities)
|
||||
// ...
|
||||
|
||||
// 11. Update Interface (login, ui, etc)
|
||||
// ...
|
||||
|
||||
// 12. Update Sound (sound driver)
|
||||
// ...
|
||||
|
||||
// 13. Update Send (network, send new position etc)
|
||||
// ...
|
||||
|
||||
// 14. Update Debug (stuff for dev)
|
||||
// ...
|
||||
|
||||
if (_isGraphicsInitialized && !Modules::objView().getDriver()->isLost())
|
||||
{
|
||||
// 01. Render Driver (background color)
|
||||
Modules::objView().renderDriver(); // clear all buffers
|
||||
|
||||
// 02. Render Sky (sky scene)
|
||||
// ...
|
||||
|
||||
// 04. Render Scene (entity scene)
|
||||
Modules::objView().renderScene();
|
||||
|
||||
// 05. Render Effects (flare)
|
||||
// ...
|
||||
|
||||
// 06. Render Interface 3D (player names)
|
||||
// ...
|
||||
|
||||
// 07. Render Debug 3D
|
||||
// ...
|
||||
|
||||
// 08. Render Interface 2D (chatboxes etc, optionally does have 3d)
|
||||
// ...
|
||||
|
||||
// 09. Render Debug 2D (stuff for dev)
|
||||
Modules::objView().renderDebug2D();
|
||||
|
||||
// swap 3d buffers
|
||||
Modules::objView().getDriver()->swapBuffers();
|
||||
}
|
||||
}
|
||||
void CObjectViewerDialog::topLevelChanged ( bool topLevel ) {
|
||||
//nldebug("topLevel:%d",topLevel);
|
||||
//_georges->init();
|
||||
}
|
||||
|
||||
QAction *CObjectViewerDialog::createSaveScreenshotAction(QObject *parent)
|
||||
{
|
||||
QAction *action = new QAction(parent);
|
||||
connect(action, SIGNAL(triggered()), this, SLOT(saveScreenshot()));
|
||||
connect(action, SIGNAL(triggered()), _nlw, SLOT(saveScreenshot()));
|
||||
return action;
|
||||
}
|
||||
|
||||
QAction *CObjectViewerDialog::createSetBackgroundColor(QObject *parent)
|
||||
{
|
||||
QAction *action = new QAction(parent);
|
||||
connect(action, SIGNAL(triggered()), this, SLOT(setBackgroundColor()));
|
||||
connect(action, SIGNAL(triggered()), _nlw, SLOT(setBackgroundColor()));
|
||||
return action;
|
||||
}
|
||||
|
||||
void CObjectViewerDialog::saveScreenshot()
|
||||
{
|
||||
Modules::objView().saveScreenshot("screenshot", false, true, false);
|
||||
}
|
||||
|
||||
void CObjectViewerDialog::setBackgroundColor()
|
||||
{
|
||||
QColor color = QColorDialog::getColor(QColor(Modules::objView().getBackgroundColor().R,
|
||||
Modules::objView().getBackgroundColor().G,
|
||||
Modules::objView().getBackgroundColor().B));
|
||||
Modules::objView().setBackgroundColor(NLMISC::CRGBA(color.red(), color.green(), color.blue()));
|
||||
}
|
||||
|
||||
void CObjectViewerDialog::topLevelChanged ( bool topLevel ) {
|
||||
//nldebug("CObjectViewerDialog::topLevelChanged topLevel:%d",topLevel);
|
||||
//nldebug("%d %d",winId(), _nlw->winId());
|
||||
// winId changing when re/docking
|
||||
//Modules::georges().init();
|
||||
//Modules::objView().reinit((nlWindow)_nlw->winId(), _nlw->width(), _nlw->height());
|
||||
}
|
||||
|
||||
void CObjectViewerDialog::resizeEvent(QResizeEvent *resizeEvent)
|
||||
{
|
||||
//nldebug("%d %d",_nlw->width(), _nlw->height());
|
||||
QDockWidget::resizeEvent(resizeEvent);
|
||||
if (Modules::objView().getDriver())
|
||||
Modules::objView().setSizeViewport(resizeEvent->size().width(), resizeEvent->size().height());
|
||||
if (Modules::objViewInt().getDriver())
|
||||
Modules::objViewInt().setSizeViewport(resizeEvent->size().width(), resizeEvent->size().height());
|
||||
// The OpenGL driver does not resize automatically.
|
||||
// The Direct3D driver breaks the window mode to include window borders when calling setMode windowed.
|
||||
|
||||
|
|
|
@ -61,22 +61,10 @@ namespace NLQT
|
|||
virtual void setVisible(bool visible);
|
||||
virtual QPaintEngine* paintEngine() const { return NULL; }
|
||||
|
||||
void init();
|
||||
void release();
|
||||
void reinit();
|
||||
|
||||
QAction *createSaveScreenshotAction(QObject *parent);
|
||||
QAction *createSetBackgroundColor(QObject *parent);
|
||||
|
||||
private Q_SLOTS:
|
||||
void updateRender();
|
||||
|
||||
void saveScreenshot();
|
||||
void setBackgroundColor();
|
||||
|
||||
void submitEvents(NLMISC::CEventServer &server, bool allWindows) { }
|
||||
void emulateMouseRawMode(bool) { }
|
||||
|
||||
void topLevelChanged(bool topLevel);
|
||||
|
||||
protected:
|
||||
|
@ -86,14 +74,7 @@ namespace NLQT
|
|||
CObjectViewerDialog(const CObjectViewerDialog &);
|
||||
CObjectViewerDialog &operator=(const CObjectViewerDialog &);
|
||||
|
||||
void updateInitialization(bool visible);
|
||||
|
||||
Ui::CObjectViewerDialog _ui;
|
||||
|
||||
// render stuff
|
||||
QTimer *_mainTimer;
|
||||
bool _isGraphicsInitialized, _isGraphicsEnabled;
|
||||
|
||||
QNLWidget * _nlw;
|
||||
|
||||
friend class CMainWindow;
|
||||
|
|
Loading…
Reference in a new issue