diff --git a/code/nel/tools/3d/object_viewer_qt/src/CMakeLists.txt b/code/nel/tools/3d/object_viewer_qt/src/CMakeLists.txt index 5a690018f..6bfa4eb96 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/CMakeLists.txt +++ b/code/nel/tools/3d/object_viewer_qt/src/CMakeLists.txt @@ -22,7 +22,7 @@ SET(OBJECT_VIEWER_HDR main_window.h graphics_viewport.h animation_dialog.h vegetable_dialog.h global_wind_dialog.h day_night_dialog.h sun_color_dialog.h vegetable_noise_value_widget.h vegetable_density_page.h vegetable_landscape_page.h vegetable_scale_page.h vegetable_appearance_page.h vegetable_rotate_page.h - tune_mrm_dialog.h tune_timer_dialog.h + tune_mrm_dialog.h tune_timer_dialog.h camera_control.h extension_system/iplugin_manager.h extension_system/plugin_manager.h) SET(OBJECT_VIEWER_UIS animation_form.ui animation_set_form.ui settings_form.ui diff --git a/code/nel/tools/3d/object_viewer_qt/src/camera_control.cpp b/code/nel/tools/3d/object_viewer_qt/src/camera_control.cpp new file mode 100644 index 000000000..2216fb88d --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/camera_control.cpp @@ -0,0 +1,281 @@ +/* + Object Viewer Qt + Copyright (C) 2010 Dzmitry Kamiahin + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +*/ + +#include "stdpch.h" +#include "camera_control.h" + +// STL includes + +// Qt includes + +// NeL includes +#include "nel/misc/debug.h" +#include "nel/3d/u_driver.h" +#include "nel/3d/u_scene.h" +#include +#include + +// Project includes +#include "modules.h" + +static int camId = 0; + +namespace NLQT +{ + +CCameraItem::CCameraItem(const QString &name): + _cameraFocal(75), + _speed(5.0), + _active(false), + _name(name) +{ + _camera = Modules::objView().getScene()->createCamera(); + _camera.setTransformMode (NL3D::UTransformable::DirectMatrix); + reset(); +} + +CCameraItem::~CCameraItem() +{ +} + +void CCameraItem::setActive(bool active) +{ + if (active) + { + sint w = Modules::objView().getDriver()->getWindowWidth(); + sint h = Modules::objView().getDriver()->getWindowHeight(); + _camera.setPerspective(_cameraFocal * float(NLMISC::Pi) / 180.f, float(w) / h, 0.1f, 1000); + Modules::objView().getScene()->setCam(_camera); + setupListener(); + } + else + { + _hotSpot = Modules::objView().get3dMouseListener()->getHotSpot(); + } + _active = active; +} + +void CCameraItem::setSpeed(float value) +{ + _speed = value; + Modules::objView().get3dMouseListener()->setSpeed(_speed); +} + +void CCameraItem::reset() +{ + _hotSpot = NLMISC::CVector(0, 0, 0); + float radius=10.f; + + // Setup camera + _camera.lookAt(_hotSpot + NLMISC::CVector(0.57735f, 0.57735f, 0.57735f) * radius, _hotSpot); + + if (_active) + setupListener(); +} + +void CCameraItem::setupListener() +{ + NL3D::U3dMouseListener *_mouseListener = Modules::objView().get3dMouseListener(); + _mouseListener->setMatrix (_camera.getMatrix()); + _mouseListener->setFrustrum (_camera.getFrustum()); + _mouseListener->setViewport (NL3D::CViewport()); + _mouseListener->setHotSpot (_hotSpot); + Modules::objView().get3dMouseListener()->setSpeed(_speed); +} + +CCameraControl::CCameraControl(QWidget *parent) + : QObject(parent), + _currentCamera(0) +{ + _camToolBar = new QToolBar(tr("CameraControl"), parent); + + _fpsAction = _camToolBar->addAction(tr("Fly")); + _fpsAction->setStatusTip(tr("Set firstPerson camera mode")); + _fpsAction->setCheckable(true); + + _edit3dAction = _camToolBar->addAction(tr("Edit")); + _edit3dAction->setStatusTip(tr("Set edit3d camera mode")); + _edit3dAction->setCheckable(true); + + QActionGroup *cameraModeGroup = new QActionGroup(this); + cameraModeGroup->addAction(_fpsAction); + cameraModeGroup->addAction(_edit3dAction); + _edit3dAction->setChecked(true); + + connect(_fpsAction, SIGNAL(triggered()), this, SLOT(setFirstPersonMode())); + connect(_edit3dAction, SIGNAL(triggered()), this, SLOT(setEditMode())); + + _renderModeMenu = new QMenu(tr("Render Mode"), _camToolBar); + _renderModeMenu->setIcon(QIcon(":/images/polymode.png")); + _camToolBar->addAction(_renderModeMenu->menuAction()); + connect(_renderModeMenu->menuAction(), SIGNAL(triggered()), this, SLOT(setRenderMode())); + + QSignalMapper *modeMapper = new QSignalMapper(this); + + _pointRenderModeAction = _renderModeMenu->addAction(tr("Point mode")); + _pointRenderModeAction->setIcon(QIcon(":/images/rmpoints.png")); + _pointRenderModeAction->setStatusTip(tr("Set point render mode")); + connect(_pointRenderModeAction, SIGNAL(triggered()), modeMapper, SLOT(map())); + modeMapper->setMapping(_pointRenderModeAction, 0); + + _lineRenderModeAction = _renderModeMenu->addAction(tr("Line mode")); + _lineRenderModeAction->setStatusTip(tr("Set line render mode")); + _lineRenderModeAction->setIcon(QIcon(":/images/rmline.png")); + connect(_lineRenderModeAction, SIGNAL(triggered()), modeMapper, SLOT(map())); + modeMapper->setMapping(_lineRenderModeAction, 1); + + _fillRenderModeAction = _renderModeMenu->addAction(tr("Fill mode")); + _fillRenderModeAction->setIcon(QIcon(":/images/rmfill.png")); + _fillRenderModeAction->setStatusTip(tr("Set fill render mode")); + connect(_fillRenderModeAction, SIGNAL(triggered()), modeMapper, SLOT(map())); + modeMapper->setMapping(_fillRenderModeAction, 2); + + connect(modeMapper, SIGNAL(mapped(int)), this, SLOT(setRenderMode(int))); + + _camToolBar->addSeparator(); + _speedLabel = new QLabel(tr("Speed:"), _camToolBar); + _camToolBar->addWidget(_speedLabel); + _speedSpinBox = new QSpinBox(_camToolBar); + _speedSpinBox->setMinimum(1); + _speedSpinBox->setMaximum(1000); + _camToolBar->addWidget(_speedSpinBox); + connect(_speedSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setSpeed(int))); + + _camToolBar->addSeparator(); + _addCamAction = _camToolBar->addAction(tr("Create camera")); + _addCamAction->setIcon(QIcon(":/images/cam_add.png")); + _addCamAction->setStatusTip(tr("Create new camera")); + connect(_addCamAction, SIGNAL(triggered()), this, SLOT(addCamera())); + + _delCamAction = _camToolBar->addAction(tr("Delete camera")); + _delCamAction->setIcon(QIcon(":/images/cam_del.png")); + _delCamAction->setStatusTip(tr("Delete current camera")); + connect(_delCamAction, SIGNAL(triggered()), this, SLOT(delCamera())); + + _listCamComboBox = new QComboBox(_camToolBar); + connect(_listCamComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(changeCamera(int))); + _listCamComboBox->setCurrentIndex(createCamera(tr("defaultCamera"))); + _camToolBar->addWidget(_listCamComboBox); + + _camToolBar->addSeparator(); + _resetCamAction = _camToolBar->addAction(tr("Reset camera")); + _resetCamAction->setStatusTip(tr("Reset current camera")); + //_resetCamAction->setShortcut(tr("Ctrl+R")); + connect(_resetCamAction, SIGNAL(triggered()), this, SLOT(resetCamera())); +} + +CCameraControl::~CCameraControl() +{ +} + +void CCameraControl::setEditMode() +{ + Modules::objView().get3dMouseListener()->setMouseMode(NL3D::U3dMouseListener::edit3d); +} + +void CCameraControl::setFirstPersonMode() +{ + Modules::objView().get3dMouseListener()->setMouseMode(NL3D::U3dMouseListener::firstPerson); +} + +void CCameraControl::addCamera() +{ + _listCamComboBox->setCurrentIndex(createCamera(tr("%1_Camera").arg(++camId))); +} + +void CCameraControl::delCamera() +{ + int index = _listCamComboBox->currentIndex(); + _listCamComboBox->setCurrentIndex(index - 1); + + _listCamComboBox->removeItem(index); + delete _cameraList[index]; + _cameraList.erase(_cameraList.begin() + index); +} + +void CCameraControl::setSpeed(int value) +{ + nlassert(_currentCamera); + _currentCamera->setSpeed(value); +} + +void CCameraControl::changeCamera(int index) +{ + if (_currentCamera) + _currentCamera->setActive(false); + + if (index == 0) + _delCamAction->setEnabled(false); + else + _delCamAction->setEnabled(true); + + _currentCamera = _cameraList[index]; + + nlassert(_currentCamera); + _currentCamera->setActive(true); + _speedSpinBox->setValue(int(_currentCamera->getSpeed())); +} + +void CCameraControl::setRenderMode(int value) +{ + switch (value) + { + case 0: + Modules::objView().getDriver()->setPolygonMode (NL3D::UDriver::Point); + break; + case 1: + Modules::objView().getDriver()->setPolygonMode (NL3D::UDriver::Line); + break; + case 2: + Modules::objView().getDriver()->setPolygonMode (NL3D::UDriver::Filled); + break; + } +} + +void CCameraControl::setRenderMode() +{ + switch (Modules::objView().getDriver()->getPolygonMode()) + { + case NL3D::UDriver::Filled: + Modules::objView().getDriver()->setPolygonMode (NL3D::UDriver::Line); + break; + case NL3D::UDriver::Line: + Modules::objView().getDriver()->setPolygonMode (NL3D::UDriver::Point); + break; + case NL3D::UDriver::Point: + Modules::objView().getDriver()->setPolygonMode (NL3D::UDriver::Filled); + break; + } +} + +void CCameraControl::resetCamera() +{ + nlassert(_currentCamera); + _currentCamera->reset(); +} + +int CCameraControl::createCamera(const QString &name) +{ + CCameraItem *newCamera = new CCameraItem(name); + _cameraList.push_back(newCamera); + _listCamComboBox->addItem(newCamera->getName()); + return _cameraList.size() - 1; +} + +} /* namespace NLQT */ diff --git a/code/nel/tools/3d/object_viewer_qt/src/camera_control.h b/code/nel/tools/3d/object_viewer_qt/src/camera_control.h new file mode 100644 index 000000000..50d10a230 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/camera_control.h @@ -0,0 +1,125 @@ +/* + Object Viewer Qt + Copyright (C) 2010 Dzmitry Kamiahin + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +*/ + +#ifndef CAMERA_CONTROL_H +#define CAMERA_CONTROL_H + +// STL includes + +// Qt includes +#include +#include +#include +#include +#include +#include +#include + +// NeL includes +#include +#include "nel/misc/vector.h" + +// Project includes + +namespace NLQT +{ + +class CCameraItem +{ +public: + CCameraItem(const QString &name); + ~CCameraItem(); + + void setSpeed(float value); + float getSpeed() + { + return _speed; + } + void setActive(bool active); + void setName(const QString &name) + { + _name = name; + } + QString getName() const + { + return _name; + } + void reset(); + +private: + void setupListener(); + + NL3D::UCamera _camera; + NLMISC::CVector _hotSpot; + + float _cameraFocal; + float _speed; + bool _active; + QString _name; +}; + +class CCameraControl: public QObject +{ + Q_OBJECT + +public: + CCameraControl(QWidget *parent = 0); + ~CCameraControl(); + + QToolBar *getToolBar() const + { + return _camToolBar; + } + +public Q_SLOTS: + void setEditMode(); + void setFirstPersonMode(); + void addCamera(); + void delCamera(); + void setSpeed(int value); + void changeCamera(int index); + void setRenderMode(int value); + void setRenderMode(); + void resetCamera(); + +private: + int createCamera(const QString &name); + + QAction *_fpsAction; + QAction *_edit3dAction; + QAction *_pointRenderModeAction; + QAction *_lineRenderModeAction; + QAction *_fillRenderModeAction; + QAction *_addCamAction; + QAction *_delCamAction; + QAction *_resetCamAction; + QSpinBox *_speedSpinBox; + QComboBox *_listCamComboBox; + QMenu *_renderModeMenu; + QLabel *_speedLabel; + QToolBar *_camToolBar; + + CCameraItem *_currentCamera; + std::vector _cameraList; + +}; /* class CCameraControl */ + +} /* namespace NLQT */ + +#endif // CAMERA_CONTROL_H diff --git a/code/nel/tools/3d/object_viewer_qt/src/images/cam_add.png b/code/nel/tools/3d/object_viewer_qt/src/images/cam_add.png new file mode 100644 index 000000000..dbc579d43 Binary files /dev/null and b/code/nel/tools/3d/object_viewer_qt/src/images/cam_add.png differ diff --git a/code/nel/tools/3d/object_viewer_qt/src/images/cam_del.png b/code/nel/tools/3d/object_viewer_qt/src/images/cam_del.png new file mode 100644 index 000000000..1f6bee21f Binary files /dev/null and b/code/nel/tools/3d/object_viewer_qt/src/images/cam_del.png differ diff --git a/code/nel/tools/3d/object_viewer_qt/src/images/rmfill.png b/code/nel/tools/3d/object_viewer_qt/src/images/rmfill.png new file mode 100644 index 000000000..fa187ea27 Binary files /dev/null and b/code/nel/tools/3d/object_viewer_qt/src/images/rmfill.png differ diff --git a/code/nel/tools/3d/object_viewer_qt/src/images/rmline.png b/code/nel/tools/3d/object_viewer_qt/src/images/rmline.png new file mode 100644 index 000000000..82d9783e1 Binary files /dev/null and b/code/nel/tools/3d/object_viewer_qt/src/images/rmline.png differ diff --git a/code/nel/tools/3d/object_viewer_qt/src/images/rmpoints.png b/code/nel/tools/3d/object_viewer_qt/src/images/rmpoints.png new file mode 100644 index 000000000..b7a4b2f28 Binary files /dev/null and b/code/nel/tools/3d/object_viewer_qt/src/images/rmpoints.png differ diff --git a/code/nel/tools/3d/object_viewer_qt/src/main_window.cpp b/code/nel/tools/3d/object_viewer_qt/src/main_window.cpp index ece609dac..5a75e7423 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/main_window.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/main_window.cpp @@ -49,6 +49,7 @@ #include "sun_color_dialog.h" #include "tune_mrm_dialog.h" #include "tune_timer_dialog.h" +#include "camera_control.h" using namespace std; using namespace NLMISC; @@ -58,13 +59,13 @@ namespace NLQT CMainWindow::CMainWindow(QWidget *parent) : QMainWindow(parent), - _isGraphicsInitialized(false), - _isGraphicsEnabled(false), - _isSoundInitialized(false), - _isSoundEnabled(false), - _GraphicsViewport(NULL), - _lastDir("."), - _mouseMode(NL3D::U3dMouseListener::edit3d) + _isGraphicsInitialized(false), + _isGraphicsEnabled(false), + _isSoundInitialized(false), + _isSoundEnabled(false), + _GraphicsViewport(NULL), + _lastDir("."), + _mouseMode(NL3D::U3dMouseListener::edit3d) { nldebug("CMainWindow::CMainWindow:"); setObjectName("CMainWindow"); @@ -83,7 +84,7 @@ CMainWindow::CMainWindow(QWidget *parent) _GraphicsViewport->init(); _isGraphicsInitialized = true; - + if (_isSoundEnabled) { Modules::sound().init(); @@ -144,7 +145,7 @@ CMainWindow::~CMainWindow() delete _TuneTimerDialog; delete _ParticleControlDialog; delete _ParticleWorkspaceDialog; - + if (_isSoundInitialized) Modules::sound().releaseGraphics(); @@ -162,7 +163,7 @@ void CMainWindow::setVisible(bool visible) { QMainWindow::setVisible(true); if (_isSoundInitialized) - Modules::sound().initGraphics(); + Modules::sound().initGraphics(); _mainTimer->start(); _statusBarTimer->start(1000); } @@ -202,7 +203,7 @@ void CMainWindow::open() tr("NeL skeleton file (*.skel)")); Q_FOREACH(QString fileName, list) - loadFile(fileName, skelFileName); + loadFile(fileName, skelFileName); _AnimationSetDialog->updateListObject(); _AnimationSetDialog->updateListAnim(); @@ -220,43 +221,6 @@ void CMainWindow::resetScene() _SkeletonTreeModel->resetTreeModel(); } -void CMainWindow::changeRenderMode() -{ - // Change render mode - switch (Modules::objView().getDriver()->getPolygonMode()) - { - case NL3D::UDriver::Filled: - Modules::objView().getDriver()->setPolygonMode (NL3D::UDriver::Line); - break; - case NL3D::UDriver::Line: - Modules::objView().getDriver()->setPolygonMode (NL3D::UDriver::Point); - break; - case NL3D::UDriver::Point: - Modules::objView().getDriver()->setPolygonMode (NL3D::UDriver::Filled); - break; - } -} - -void CMainWindow::resetCamera() -{ - Modules::objView().resetCamera(); -} - -void CMainWindow::changeCameraMode() -{ - switch (_mouseMode) - { - case NL3D::U3dMouseListener::edit3d: - Modules::objView().get3dMouseListener()->setMouseMode(NL3D::U3dMouseListener::firstPerson); - _mouseMode = NL3D::U3dMouseListener::firstPerson; - break; - case NL3D::U3dMouseListener::firstPerson: - _mouseMode = NL3D::U3dMouseListener::edit3d; - Modules::objView().get3dMouseListener()->setMouseMode(NL3D::U3dMouseListener::edit3d); - break; - } -} - void CMainWindow::reloadTextures() { Modules::objView().reloadTextures(); @@ -286,10 +250,10 @@ void CMainWindow::updateStatusBar() if (_isGraphicsInitialized) { _statusInfo->setText(QString("%1, Nb tri: %2 , Texture used (Mb): %3 , fps: %4 ").arg( - Modules::objView().getDriver()->getVideocardInformation()).arg( - _numTri).arg( - _texMem, 0,'f',4).arg( - _fps, 0,'f',2)); + Modules::objView().getDriver()->getVideocardInformation()).arg( + _numTri).arg( + _texMem, 0,'f',4).arg( + _fps, 0,'f',2)); } } @@ -314,18 +278,11 @@ void CMainWindow::createActions() _resetCameraAction = new QAction(tr("Reset camera"), this); _resetCameraAction->setShortcut(tr("Ctrl+R")); _resetCameraAction->setStatusTip(tr("Reset current camera")); - connect(_resetCameraAction, SIGNAL(triggered()), this, SLOT(resetCamera())); _renderModeAction = new QAction("Change render mode", this); _renderModeAction->setIcon(QIcon(":/images/polymode.png")); _renderModeAction->setShortcut(tr("Ctrl+M")); _renderModeAction->setStatusTip(tr("Change render mode (Line, Point, Filled)")); - connect(_renderModeAction, SIGNAL(triggered()), this, SLOT(changeRenderMode())); - - _cameraModeAction = new QAction("Change camera mode", this); - _cameraModeAction->setShortcut(tr("Ctrl+W")); - _cameraModeAction->setStatusTip(tr("Change camera mode (edit3d, firstPerson)")); - connect(_cameraModeAction, SIGNAL(triggered()), this, SLOT(changeCameraMode())); _resetSceneAction = new QAction(tr("&Reset scene"), this); _resetSceneAction->setStatusTip(tr("Reset current scene")); @@ -366,7 +323,6 @@ void CMainWindow::createMenus() _viewMenu->addAction(_setBackColorAction); _viewMenu->addAction(_resetCameraAction); _viewMenu->addAction(_renderModeAction); - _viewMenu->addAction(_cameraModeAction); _viewMenu->addAction(_SetupFog->toggleViewAction()); _sceneMenu = menuBar()->addMenu(tr("&Scene")); @@ -457,6 +413,12 @@ void CMainWindow::createToolBars() _toolsBar->addAction(_TuneTimerDialog->toggleViewAction()); _toolsBar->addAction(_SkeletonScaleDialog->toggleViewAction()); _toolsBar->addAction(_TuneMRMDialog->toggleViewAction()); + + _cameraControl = new CCameraControl(this); + this->addToolBar(_cameraControl->getToolBar()); + + connect(_resetCameraAction, SIGNAL(triggered()), _cameraControl, SLOT(resetCamera())); + connect(_renderModeAction, SIGNAL(triggered()), _cameraControl, SLOT(setRenderMode())); } void CMainWindow::createStatusBar() @@ -555,7 +517,7 @@ bool CMainWindow::loadFile(const QString &fileName, const QString &skelName) bool loaded; if (fileInfo.suffix() == "ig") loaded = Modules::objView().loadInstanceGroup(fileName.toStdString()); - else + else loaded = Modules::objView().loadMesh(fileName.toStdString(), skelName.toStdString()); if (!loaded) @@ -646,17 +608,17 @@ void CMainWindow::updateRender() // 14. Update Debug (stuff for dev) // ... - - // 15. Calc FPS - static sint64 lastTime = NLMISC::CTime::getPerformanceTime (); - sint64 newTime = NLMISC::CTime::getPerformanceTime (); - _fps = float(1.0 / NLMISC::CTime::ticksToSecond (newTime-lastTime)); + + // 15. Calc FPS + static sint64 lastTime = NLMISC::CTime::getPerformanceTime (); + sint64 newTime = NLMISC::CTime::getPerformanceTime (); + _fps = float(1.0 / NLMISC::CTime::ticksToSecond (newTime-lastTime)); lastTime = newTime; if (_isGraphicsInitialized && !Modules::objView().getDriver()->isLost()) { // 01. Render Driver (background color) - //Modules::objView().getDriver()->activate(); + //Modules::objView().getDriver()->activate(); Modules::objView().renderDriver(); // clear all buffers // 02. Render Sky (sky scene) @@ -681,7 +643,7 @@ void CMainWindow::updateRender() Modules::objView().renderDebug2D(); // 10. Get profile information - NL3D::CPrimitiveProfile in, out; + NL3D::CPrimitiveProfile in, out; Modules::objView().getDriver()->profileRenderedPrimitives (in, out); _numTri = in.NLines+in.NPoints+in.NQuads*2+in.NTriangles+in.NTriangleStrips; diff --git a/code/nel/tools/3d/object_viewer_qt/src/main_window.h b/code/nel/tools/3d/object_viewer_qt/src/main_window.h index 9cc146aee..8864b1c6b 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/main_window.h +++ b/code/nel/tools/3d/object_viewer_qt/src/main_window.h @@ -56,6 +56,8 @@ class CSunColorDialog; class CTuneMRMDialog; class CTuneTimerDialog; +class CCameraControl; + class CMainWindow : public QMainWindow { Q_OBJECT @@ -79,9 +81,6 @@ public: private Q_SLOTS: void open(); void resetScene(); - void changeRenderMode(); - void resetCamera(); - void changeCameraMode(); void reloadTextures(); void settings(); void about(); @@ -122,6 +121,8 @@ private: CSkeletonTreeModel *_SkeletonTreeModel; CTuneTimerDialog *_TuneTimerDialog; + CCameraControl *_cameraControl; + QPalette _originalPalette; QString _lastDir; @@ -143,7 +144,6 @@ private: QAction *_frameDelayAction; QAction *_lightGroupAction; QAction *_reloadTexturesAction; - QAction *_cameraModeAction; QAction *_resetCameraAction; QAction *_resetSceneAction; QAction *_saveScreenshotAction; diff --git a/code/nel/tools/3d/object_viewer_qt/src/object_viewer.cpp b/code/nel/tools/3d/object_viewer_qt/src/object_viewer.cpp index ac34152fa..07882f14a 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/object_viewer.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/object_viewer.cpp @@ -23,7 +23,6 @@ // STL includes // NeL includes -#include #include #include #include @@ -59,13 +58,13 @@ namespace NLQT CObjectViewer::CObjectViewer() : _IDriver(0), - _CScene(0), - _Driver(0), - _Scene(0), - _TextContext(0), - _CameraFocal(75), - _CurrentInstance(""), - _BloomEffect(false) + _CScene(0), + _Driver(0), + _Scene(0), + _TextContext(0), + _CameraFocal(75), + _CurrentInstance(""), + _BloomEffect(false) { } @@ -115,19 +114,11 @@ void CObjectViewer::init(nlWindow wnd, uint16 w, uint16 h) _Scene->enableLightingSystem(true); - // create the camera - UCamera camera = _Scene->getCam(); - camera.setTransformMode (UTransformable::DirectMatrix); - - setSizeViewport(w, h); - NLMISC::CVector hotSpot=NLMISC::CVector(0,0,0); _MouseListener = _Driver->create3dMouseListener(); _MouseListener->setMouseMode(U3dMouseListener::edit3d); - resetCamera(); - // set the cache size for the font manager(in bytes) _Driver->setFontManagerMaxMemory(2097152); @@ -184,7 +175,7 @@ void CObjectViewer::release() void CObjectViewer::updateInput() { _Driver->EventServer.pump(); - + // New matrix from camera _Scene->getCam().setTransformMode(NL3D::UTransformable::DirectMatrix); _Scene->getCam().setMatrix (_MouseListener->getViewMatrix()); @@ -218,53 +209,38 @@ void CObjectViewer::renderDebug2D() void CObjectViewer::reloadTextures() { - // For each instances - std::vector listObjects; - getListObjects(listObjects); - - for (size_t i = 0; i < listObjects.size(); ++i) - { - // Get the shape - NL3D::UInstance instance = getEntity(listObjects[i]).getInstance(); - - // For each material - if (!instance.empty()) - { - uint numMaterial = instance.getNumMaterials(); - uint mat; - for (mat = 0; mat < numMaterial; mat++) - { - // Get the material - NL3D::CMaterial *material = instance.getMaterial(mat).getObjectPtr(); - - // For each texture - int tex; - for (tex = 0; tex < NL3D::IDRV_MAT_MAXTEXTURES; tex++) - { - ITexture *texture = material->getTexture(tex); - - // Touch it! - if (texture) - getIDriver()->invalidateShareTexture(*texture); - } - } - } - } -} + // For each instances + std::vector listObjects; + getListObjects(listObjects); -void CObjectViewer::resetCamera() -{ - CVector hotSpot = CVector (0,0,0); - float radius=10.f; - - // Setup camera - _Scene->getCam().lookAt(hotSpot + CVector(0.57735f, 0.57735f, 0.57735f) * radius, hotSpot); - - // Setup mouse listener - _MouseListener->setMatrix (_Scene->getCam().getMatrix()); - _MouseListener->setFrustrum (_Scene->getCam().getFrustum()); - _MouseListener->setViewport (CViewport()); - _MouseListener->setHotSpot (hotSpot); + for (size_t i = 0; i < listObjects.size(); ++i) + { + // Get the shape + NL3D::UInstance instance = getEntity(listObjects[i]).getInstance(); + + // For each material + if (!instance.empty()) + { + uint numMaterial = instance.getNumMaterials(); + uint mat; + for (mat = 0; mat < numMaterial; mat++) + { + // Get the material + NL3D::CMaterial *material = instance.getMaterial(mat).getObjectPtr(); + + // For each texture + int tex; + for (tex = 0; tex < NL3D::IDRV_MAT_MAXTEXTURES; tex++) + { + ITexture *texture = material->getTexture(tex); + + // Touch it! + if (texture) + getIDriver()->invalidateShareTexture(*texture); + } + } + } + } } void CObjectViewer::saveScreenshot(const std::string &nameFile, bool jpg, bool png, bool tga) @@ -316,11 +292,11 @@ bool CObjectViewer::loadMesh(const std::string &meshFileName, const std::string // if we can't create entity, skip it if (Entity.empty()) return false; - - CAABBox bbox; - Entity.getShapeAABBox(bbox); - setCamera(bbox , Entity, true); - + + CAABBox bbox; + Entity.getShapeAABBox(bbox); + setCamera(bbox , Entity, true); + _MouseListener->setMatrix(_Scene->getCam().getMatrix()); USkeleton Skeleton = _Scene->createSkeleton(skelFileName); @@ -348,57 +324,57 @@ bool CObjectViewer::loadInstanceGroup(const std::string &igName) { CPath::addSearchPath (CFile::getPath(igName)); UInstanceGroup *ig = UInstanceGroup::createInstanceGroup(igName); - if (ig == 0) + if (ig == 0) return false; ig->addToScene(*_Scene, _Driver); ig->unfreezeHRC(); _ListIG.push_back(ig); return true; } - -void CObjectViewer::setCamera(NLMISC::CAABBox &bbox, NL3D::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); - } - - // 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; - float fov = float(_CameraFocal * (float)Pi/180.0); - 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); - - CVector ax(quat.getAxis()); - - if (ax.isNull() || ax == CVector::I) - { - ax = CVector::J; - } - else if (ax == -CVector::K) - { - ax = -CVector::J; - } - - eye -= ax * (dist+radius); - if (high_z) - eye.z += max_radius.z/1.0f; - get3dMouseListener()->setHotSpot(center); - Camera.lookAt(eye, center); + +void CObjectViewer::setCamera(NLMISC::CAABBox &bbox, NL3D::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); + } + + // 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; + float fov = float(_CameraFocal * (float)Pi/180.0); + 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); + + CVector ax(quat.getAxis()); + + if (ax.isNull() || ax == CVector::I) + { + ax = CVector::J; + } + else if (ax == -CVector::K) + { + ax = -CVector::J; + } + + eye -= ax * (dist+radius); + if (high_z) + eye.z += max_radius.z/1.0f; + get3dMouseListener()->setHotSpot(center); + Camera.lookAt(eye, center); } void CObjectViewer::resetScene() diff --git a/code/nel/tools/3d/object_viewer_qt/src/object_viewer.h b/code/nel/tools/3d/object_viewer_qt/src/object_viewer.h index 2cdefe426..b74544a3c 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/object_viewer.h +++ b/code/nel/tools/3d/object_viewer_qt/src/object_viewer.h @@ -100,8 +100,6 @@ public: void reloadTextures(); - void resetCamera(); - /// Make a screenshot of the current scene and save. void saveScreenshot(const std::string &nameFile, bool jpg, bool png, bool tga); @@ -188,19 +186,19 @@ public: { return _Driver; } - + NL3D::IDriver *getIDriver() const { return _IDriver; } - + /// Get a game interface for scene. /// @return pointer to the scene. inline NL3D::UScene *getScene() const { return _Scene; } - + NL3D::CScene *getCScene() const { return _CScene; diff --git a/code/nel/tools/3d/object_viewer_qt/src/object_viewer_qt.qrc b/code/nel/tools/3d/object_viewer_qt/src/object_viewer_qt.qrc index 5b14b74f6..1957bf1ea 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/object_viewer_qt.qrc +++ b/code/nel/tools/3d/object_viewer_qt/src/object_viewer_qt.qrc @@ -36,8 +36,13 @@ images/save-as.png images/save.png images/insert-horizontal.png - images/polymode.png - + images/polymode.png + images/rmfill.png + images/rmline.png + images/rmpoints.png + images/cam_del.png + images/cam_add.png + images/Emitter.bmp images/Force.bmp