This commit is contained in:
dnk-88 2010-12-12 22:42:28 +02:00
commit 248b86bd94
31 changed files with 729 additions and 2363 deletions

View file

@ -736,7 +736,9 @@ inline void CIndexBuffer::lock (CIndexBufferReadWrite &accessor, uint first, uin
} }
} }
else else
{
nlassert ((first==0)&&(last==0)); nlassert ((first==0)&&(last==0));
}
_LockCounter++; _LockCounter++;
} }
@ -771,7 +773,9 @@ inline void CIndexBuffer::lock (CIndexBufferRead &accessor, uint first, uint las
} }
} }
else else
{
nlassert ((first==0)&&(last==0)); nlassert ((first==0)&&(last==0));
}
_LockCounter++; _LockCounter++;
} }

View file

@ -1177,7 +1177,9 @@ inline void CVertexBuffer::lock (CVertexBufferReadWrite &accessor, uint first, u
} }
} }
else else
{
nlassert ((first==0)&&(last==0)); nlassert ((first==0)&&(last==0));
}
_LockCounter++; _LockCounter++;
} }
@ -1212,7 +1214,9 @@ inline void CVertexBuffer::lock (CVertexBufferRead &accessor, uint first, uint l
} }
} }
else else
{
nlassert ((first==0)&&(last==0)); nlassert ((first==0)&&(last==0));
}
_LockCounter++; _LockCounter++;
} }

View file

@ -1023,7 +1023,7 @@ bool CDriverGL::setDisplay(nlWindow wnd, const GfxMode &mode, bool show, bool re
[_ctx flushBuffer]; [_ctx flushBuffer];
[_glView display]; [_glView display];
_EventEmitter.init(this, _glView); _EventEmitter.init(this, _glView, _DestroyWindow);
#elif defined(NL_OS_UNIX) #elif defined(NL_OS_UNIX)

View file

@ -222,10 +222,12 @@ static bool isTextKeyEvent(NSEvent* event)
return false; return false;
} }
void CCocoaEventEmitter::init(NL3D::IDriver* driver, CocoaOpenGLView* glView) void CCocoaEventEmitter::init(
NL3D::IDriver* driver, CocoaOpenGLView* glView, bool eventLoop)
{ {
_driver = driver; _driver = driver;
_glView = glView; _glView = glView;
_eventLoop = eventLoop;
} }
bool CCocoaEventEmitter::processMessage(NSEvent* event, CEventServer* server) bool CCocoaEventEmitter::processMessage(NSEvent* event, CEventServer* server)
@ -443,7 +445,8 @@ typedef bool (*cocoaProc)(NL3D::IDriver*, const void* e);
void CCocoaEventEmitter::submitEvents(CEventServer& server, bool /* allWins */) void CCocoaEventEmitter::submitEvents(CEventServer& server, bool /* allWins */)
{ {
// break if there was no event to handle // break if there was no event to handle
while(true) // if running embedded in e.g. qt, _eventLoop will be false
while(_eventLoop)
{ {
// get the next event to handle // get the next event to handle
NSEvent* event = [NSApp nextEventMatchingMask:NSAnyEventMask NSEvent* event = [NSApp nextEventMatchingMask:NSAnyEventMask

View file

@ -34,6 +34,7 @@ class CCocoaEventEmitter : public IEventEmitter
{ {
bool _emulateRawMode; bool _emulateRawMode;
bool _setToEmulateRawMode; bool _setToEmulateRawMode;
bool _eventLoop;
NL3D::IDriver* _driver; NL3D::IDriver* _driver;
CocoaOpenGLView* _glView; CocoaOpenGLView* _glView;
@ -48,7 +49,7 @@ public:
_glView(nil), _glView(nil),
_server(NULL) { } _server(NULL) { }
void init(NL3D::IDriver* driver, CocoaOpenGLView* glView); void init(NL3D::IDriver*, CocoaOpenGLView*, bool eventLoop);
bool processMessage(NSEvent* event, CEventServer* server = NULL); bool processMessage(NSEvent* event, CEventServer* server = NULL);
virtual void submitEvents(CEventServer& server, bool allWindows); virtual void submitEvents(CEventServer& server, bool allWindows);
virtual void emulateMouseRawMode(bool enable); virtual void emulateMouseRawMode(bool enable);

View file

@ -104,13 +104,13 @@ CFontGenerator::CFontGenerator (const std::string &fontFileName, const std::stri
} }
string fontEx = fontExFileName; string fontEx = fontExFileName;
if (fontEx == "") if (fontEx.empty())
{ {
// try to see if the ex filename exists based on the fontExFileName // try to see if the ex filename exists based on the fontExFileName
fontEx = CPath::lookup(CFile::getFilenameWithoutExtension (fontFileName)+".afm", false, false); fontEx = CPath::lookup(CFile::getFilenameWithoutExtension (fontFileName)+".afm", false, false);
} }
if (fontEx != "") if (!fontEx.empty())
{ {
error = FT_Attach_File (_Face, fontEx.c_str ()); error = FT_Attach_File (_Face, fontEx.c_str ());
if (error) if (error)

View file

@ -300,7 +300,7 @@ CTextureFont::SLetterInfo* CTextureFont::getLetterInfo (SLetterKey& k)
uint32 width, height; uint32 width, height;
//k.FontGenerator->getSizes (k.Char, k.Size, width, height); //k.FontGenerator->getSizes (k.Char, k.Size, width, height);
// \todo mat : Temporaire !!! Essayer de faire intervenir le cache de freetype // \todo mat : Temp !!! Try to use freetype cache
uint32 nPitch, nGlyphIndex; uint32 nPitch, nGlyphIndex;
sint32 nLeft, nTop, nAdvX; sint32 nLeft, nTop, nAdvX;
k.FontGenerator->getBitmap (k.Char, k.Size, width, height, nPitch, nLeft, nTop, k.FontGenerator->getBitmap (k.Char, k.Size, width, height, nPitch, nLeft, nTop,

View file

@ -23,6 +23,10 @@ ADD_LIBRARY(ovqt_plugin_example SHARED ${SRC} ${OVQT_PLUG_EXAMPLE_MOC_SRC} ${OVQ
TARGET_LINK_LIBRARIES(ovqt_plugin_example nelmisc ${QT_LIBRARIES}) TARGET_LINK_LIBRARIES(ovqt_plugin_example nelmisc ${QT_LIBRARIES})
IF(WITH_STLPORT)
TARGET_LINK_LIBRARIES(ovqt_plugin_example ${CMAKE_THREAD_LIBS_INIT})
ENDIF(WITH_STLPORT)
NL_DEFAULT_PROPS(ovqt_plugin_example "NeL, Tools, 3D: Object Viewer Qt Plugin: Example") NL_DEFAULT_PROPS(ovqt_plugin_example "NeL, Tools, 3D: Object Viewer Qt Plugin: Example")
NL_ADD_RUNTIME_FLAGS(ovqt_plugin_example) NL_ADD_RUNTIME_FLAGS(ovqt_plugin_example)
NL_ADD_LIB_SUFFIX(ovqt_plugin_example) NL_ADD_LIB_SUFFIX(ovqt_plugin_example)

View file

@ -27,6 +27,10 @@ ADD_LIBRARY(ovqt_plugin_log SHARED ${SRC} ${OVQT_PLUG_LOG_MOC_SRC} ${OVQT_EXT_SY
TARGET_LINK_LIBRARIES(ovqt_plugin_log nelmisc ${QT_LIBRARIES}) TARGET_LINK_LIBRARIES(ovqt_plugin_log nelmisc ${QT_LIBRARIES})
IF(WITH_STLPORT)
TARGET_LINK_LIBRARIES(ovqt_plugin_log ${CMAKE_THREAD_LIBS_INIT})
ENDIF(WITH_STLPORT)
NL_DEFAULT_PROPS(ovqt_plugin_log "NeL, Tools, 3D: Object Viewer Qt Plugin: Log") NL_DEFAULT_PROPS(ovqt_plugin_log "NeL, Tools, 3D: Object Viewer Qt Plugin: Log")
NL_ADD_RUNTIME_FLAGS(ovqt_plugin_log) NL_ADD_RUNTIME_FLAGS(ovqt_plugin_log)
NL_ADD_LIB_SUFFIX(ovqt_plugin_log) NL_ADD_LIB_SUFFIX(ovqt_plugin_log)

View file

@ -17,7 +17,7 @@ QT4_WRAP_CPP( OBJECT_VIEWER_WIDGET_MOC_SRCS ${OBJECT_VIEWER_WIDGET_HDR} )
SOURCE_GROUP(QtGeneratedMocSrc FILES ${OBJECT_VIEWER_WIDGET_MOC_SRCS}) SOURCE_GROUP(QtGeneratedMocSrc FILES ${OBJECT_VIEWER_WIDGET_MOC_SRCS})
ADD_LIBRARY(object_viewer_widget_qt SHARED ADD_LIBRARY(object_viewer_widget_qt MODULE
${OBJECT_VIEWER_WIDGET_SRC} ${OBJECT_VIEWER_WIDGET_SRC}
${OBJECT_VIEWER_WIDGET_MOC_SRCS}) ${OBJECT_VIEWER_WIDGET_MOC_SRCS})
@ -27,13 +27,17 @@ TARGET_LINK_LIBRARIES(object_viewer_widget_qt
${QT_LIBRARIES} ${QT_LIBRARIES}
${QT_QTOPENGL_LIBRARY}) ${QT_QTOPENGL_LIBRARY})
IF(WITH_STLPORT)
TARGET_LINK_LIBRARIES(object_viewer_widget_qt ${CMAKE_THREAD_LIBS_INIT})
ENDIF(WITH_STLPORT)
ADD_DEFINITIONS(-DQT_NO_KEYWORDS ${LIBXML2_DEFINITIONS} ${QT_DEFINITIONS}) ADD_DEFINITIONS(-DQT_NO_KEYWORDS ${LIBXML2_DEFINITIONS} ${QT_DEFINITIONS})
ADD_DEFINITIONS(-DQT_PLUGIN) ADD_DEFINITIONS(-DQT_PLUGIN)
ADD_DEFINITIONS(-DQT_SHARED) ADD_DEFINITIONS(-DQT_SHARED)
#ADD_DEFINITIONS(-DQT_NO_DEBUG) #ADD_DEFINITIONS(-DQT_NO_DEBUG)
NL_DEFAULT_PROPS(object_viewer_widget_qt "NeL, Tools, 3D: Object Viewer Qt Widget") NL_DEFAULT_PROPS(object_viewer_widget_qt "NeL, Tools, 3D: Object Viewer Qt Widget")
#NL_ADD_RUNTIME_FLAGS(object_viewer_widget_qt) NL_ADD_RUNTIME_FLAGS(object_viewer_widget_qt)
IF(WITH_PCH) IF(WITH_PCH)
ADD_NATIVE_PRECOMPILED_HEADER(object_viewer_widget_qt ${CMAKE_CURRENT_SOURCE_DIR}/stdpch.h ${CMAKE_CURRENT_SOURCE_DIR}/stdpch.cpp) ADD_NATIVE_PRECOMPILED_HEADER(object_viewer_widget_qt ${CMAKE_CURRENT_SOURCE_DIR}/stdpch.h ${CMAKE_CURRENT_SOURCE_DIR}/stdpch.cpp)

View file

@ -1,19 +1,19 @@
/* /*
Object Viewer Qt Object Viewer Qt Widget
Copyright (C) 2010 Dzmitry Kamiahin <dnk-88@tut.by> Copyright (C) 2010 Adrian Jaekel <aj at elane2k dot com>
This program is free software: you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
@ -40,379 +40,380 @@
using namespace NLMISC; using namespace NLMISC;
using namespace NL3D; using namespace NL3D;
namespace NLQT { namespace NLQT
CSlotInfo& CSlotInfo::operator=(const CSlotInfo & slotInfo)
{ {
if ( this != &slotInfo)
{
Animation = slotInfo.Animation;
ClampMode = slotInfo.ClampMode;
Enable = slotInfo.Enable;
EndBlend = slotInfo.EndBlend;
EndTime = slotInfo.EndTime;
Offset = slotInfo.Offset;
Skeleton = slotInfo.Skeleton;
SkeletonInverted = slotInfo.SkeletonInverted;
Smoothness = slotInfo.Smoothness;
SpeedFactor = slotInfo.SpeedFactor;
StartBlend = slotInfo.StartBlend;
StartTime = slotInfo.StartTime;
}
return *this;
}
CEntity::CEntity(void): CSlotInfo& CSlotInfo::operator=(const CSlotInfo & slotInfo)
_Name("<Unknown>"), _FileNameShape(""), {
if ( this != &slotInfo)
{
Animation = slotInfo.Animation;
ClampMode = slotInfo.ClampMode;
Enable = slotInfo.Enable;
EndBlend = slotInfo.EndBlend;
EndTime = slotInfo.EndTime;
Offset = slotInfo.Offset;
Skeleton = slotInfo.Skeleton;
SkeletonInverted = slotInfo.SkeletonInverted;
Smoothness = slotInfo.Smoothness;
SpeedFactor = slotInfo.SpeedFactor;
StartBlend = slotInfo.StartBlend;
StartTime = slotInfo.StartTime;
}
return *this;
}
CEntity::CEntity(void):
_Name("<Unknown>"), _FileNameShape(""),
_FileNameSkeleton(""), _inPlace(false), _incPos(false), _FileNameSkeleton(""), _inPlace(false), _incPos(false),
_Instance(NULL), _Skeleton(NULL), _Instance(NULL), _Skeleton(NULL),
_PlayList(NULL), _AnimationSet(NULL) _PlayList(NULL), _AnimationSet(NULL)
{
_CharacterScalePos = 1;
}
CEntity::~CEntity(void)
{
if (_PlayList != NULL)
{ {
_PlayList->resetAllChannels(); _CharacterScalePos = 1;
CObjectViewerWidget::objViewWid().getPlayListManager()->deletePlayList (_PlayList);
_PlayList = NULL;
} }
if (_AnimationSet != NULL)
CEntity::~CEntity(void)
{ {
CObjectViewerWidget::objViewWid().getDriver()->deleteAnimationSet(_AnimationSet); if (_PlayList != NULL)
_AnimationSet = NULL; {
_PlayList->resetAllChannels();
CObjectViewerWidget::objViewWid().getPlayListManager()->deletePlayList (_PlayList);
_PlayList = NULL;
}
if (_AnimationSet != NULL)
{
CObjectViewerWidget::objViewWid().getDriver()->deleteAnimationSet(_AnimationSet);
_AnimationSet = NULL;
}
if (!_Skeleton.empty())
{
_Skeleton.detachSkeletonSon(_Instance);
CObjectViewerWidget::objViewWid().getScene()->deleteSkeleton(_Skeleton);
_Skeleton = NULL;
}
if (!_Instance.empty())
{
CObjectViewerWidget::objViewWid().getScene()->deleteInstance(_Instance);
_Instance = NULL;
}
} }
if (!_Skeleton.empty())
void CEntity::loadAnimation(std::string &fileName)
{ {
_Skeleton.detachSkeletonSon(_Instance); uint id = _AnimationSet->addAnimation(fileName.c_str(),CFile::getFilenameWithoutExtension(fileName).c_str());
CObjectViewerWidget::objViewWid().getScene()->deleteSkeleton(_Skeleton); _AnimationList.push_back(_AnimationSet->getAnimationName(id));
_Skeleton = NULL; _AnimationSet->build();
if (!_Skeleton.empty()) _PlayList->registerTransform(_Skeleton);
else _PlayList->registerTransform(_Instance);
} }
if (!_Instance.empty())
void CEntity::loadSWT(std::string &fileName)
{ {
CObjectViewerWidget::objViewWid().getScene()->deleteInstance(_Instance); uint id = _AnimationSet->addSkeletonWeight(fileName.c_str(),CFile::getFilenameWithoutExtension(fileName).c_str());
_Instance = NULL; _SWTList.push_back(_AnimationSet->getSkeletonWeightName(id));
} }
}
void CEntity::loadAnimation(std::string &fileName) void CEntity::addAnimToPlayList(std::string &name)
{ {
uint id = _AnimationSet->addAnimation(fileName.c_str(),CFile::getFilenameWithoutExtension(fileName).c_str()); _PlayListAnimation.push_back(name);
_AnimationList.push_back(_AnimationSet->getAnimationName(id));
_AnimationSet->build();
if (!_Skeleton.empty()) _PlayList->registerTransform(_Skeleton);
else _PlayList->registerTransform(_Instance);
}
void CEntity::loadSWT(std::string &fileName) _AnimationStatus.EndAnim = this->getPlayListLength();
{
uint id = _AnimationSet->addSkeletonWeight(fileName.c_str(),CFile::getFilenameWithoutExtension(fileName).c_str());
_SWTList.push_back(_AnimationSet->getSkeletonWeightName(id));
}
void CEntity::addAnimToPlayList(std::string &name)
{
_PlayListAnimation.push_back(name);
_AnimationStatus.EndAnim = this->getPlayListLength();
_Instance.start();
}
void CEntity::removeAnimToPlayList(uint row)
{
if (row < _PlayListAnimation.size())
_PlayListAnimation.erase(_PlayListAnimation.begin() + row);
_AnimationStatus.EndAnim = this->getPlayListLength();
}
void CEntity::swapAnimToPlayList(uint row1, uint row2)
{
if ((row1 < _PlayListAnimation.size()) && (row2 < _PlayListAnimation.size()))
std::swap(_PlayListAnimation[row1], _PlayListAnimation[row2]);
}
void CEntity::playbackAnim(bool play)
{
_AnimationStatus.PlayAnim = play;
if (play)
_Instance.start(); _Instance.start();
else }
_Instance.freezeHRC();
}
void CEntity::reset() void CEntity::removeAnimToPlayList(uint row)
{
_PlayListAnimation.clear();
_AnimationList.clear();
_SWTList.clear();
_PlayList->resetAllChannels();
}
float CEntity::getPlayListLength()
{
// Accumul all the time
float time = 0;
for(size_t i = 0; i < _PlayListAnimation.size(); ++i)
time += getAnimLength(_PlayListAnimation[i]);
return time;
}
float CEntity::getAnimLength(std::string name)
{
uint id = _AnimationSet->getAnimationIdByName(name.c_str());
NL3D::UAnimation *anim = _AnimationSet->getAnimation(id);
return anim->getEndTime() - anim->getBeginTime();
}
void CEntity::update(NL3D::TAnimationTime time)
{
this->resetChannel();
switch (_AnimationStatus.Mode)
{ {
if (row < _PlayListAnimation.size())
_PlayListAnimation.erase(_PlayListAnimation.begin() + row);
_AnimationStatus.EndAnim = this->getPlayListLength();
}
void CEntity::swapAnimToPlayList(uint row1, uint row2)
{
if ((row1 < _PlayListAnimation.size()) && (row2 < _PlayListAnimation.size()))
std::swap(_PlayListAnimation[row1], _PlayListAnimation[row2]);
}
void CEntity::playbackAnim(bool play)
{
_AnimationStatus.PlayAnim = play;
if (play)
_Instance.start();
else
_Instance.freezeHRC();
}
void CEntity::reset()
{
_PlayListAnimation.clear();
_AnimationList.clear();
_SWTList.clear();
_PlayList->resetAllChannels();
}
float CEntity::getPlayListLength()
{
// Accumul all the time
float time = 0;
for(size_t i = 0; i < _PlayListAnimation.size(); ++i)
time += getAnimLength(_PlayListAnimation[i]);
return time;
}
float CEntity::getAnimLength(std::string name)
{
uint id = _AnimationSet->getAnimationIdByName(name.c_str());
NL3D::UAnimation *anim = _AnimationSet->getAnimation(id);
return anim->getEndTime() - anim->getBeginTime();
}
void CEntity::update(NL3D::TAnimationTime time)
{
this->resetChannel();
switch (_AnimationStatus.Mode)
{
case Mode::PlayList: case Mode::PlayList:
animatePlayList(time); animatePlayList(time);
break; break;
case Mode::Mixer: case Mode::Mixer:
animateChannelMixer(); animateChannelMixer();
break; break;
}
}
void CEntity::resetChannel()
{
for(uint i = 0; i < NL3D::CChannelMixer::NumAnimationSlot; i++)
_PlayList->setAnimation(i, UPlayList::empty);
}
void CEntity::addTransformation (CMatrix &current, UAnimation *anim, float begin, float end, UTrack *posTrack, UTrack *rotquatTrack,
UTrack *nextPosTrack, UTrack *nextRotquatTrack, bool removeLast)
{
// In place ?
if (_inPlace)
{
// Just identity
current.identity();
}
else
{
// Remove the start of the animation
CQuat rotEnd (0,0,0,1);
CVector posEnd (0,0,0);
if (rotquatTrack)
{
// Interpolate the rotation
rotquatTrack->interpolate (end, rotEnd);
} }
if (posTrack) }
void CEntity::resetChannel()
{
for(uint i = 0; i < NL3D::CChannelMixer::NumAnimationSlot; i++)
_PlayList->setAnimation(i, UPlayList::empty);
}
void CEntity::addTransformation (CMatrix &current, UAnimation *anim, float begin, float end, UTrack *posTrack, UTrack *rotquatTrack,
UTrack *nextPosTrack, UTrack *nextRotquatTrack, bool removeLast)
{
// In place ?
if (_inPlace)
{ {
// Interpolate the position // Just identity
posTrack->interpolate (end, posEnd); current.identity();
} }
// Add the final rotation and position
CMatrix tmp;
tmp.identity ();
tmp.setRot (rotEnd);
tmp.setPos (posEnd);
// Incremental ?
if (_incPos)
current *= tmp;
else else
current = tmp;
if (removeLast)
{ {
CQuat rotStart (0,0,0,1); // Remove the start of the animation
CVector posStart (0,0,0); CQuat rotEnd (0,0,0,1);
if (nextRotquatTrack) CVector posEnd (0,0,0);
if (rotquatTrack)
{ {
// Interpolate the rotation // Interpolate the rotation
nextRotquatTrack->interpolate (begin, rotStart); rotquatTrack->interpolate (end, rotEnd);
} }
if (nextPosTrack) if (posTrack)
{ {
// Interpolate the position // Interpolate the position
nextPosTrack->interpolate (begin, posStart); posTrack->interpolate (end, posEnd);
} }
// Remove the init rotation and position of the next animation
// Add the final rotation and position
CMatrix tmp;
tmp.identity (); tmp.identity ();
tmp.setRot (rotStart); tmp.setRot (rotEnd);
tmp.setPos (posStart); tmp.setPos (posEnd);
tmp.invert ();
current *= tmp;
// Normalize the mt // Incremental ?
CVector I = current.getI (); if (_incPos)
CVector J = current.getJ (); current *= tmp;
I.z = 0; else
J.z = 0; current = tmp;
J.normalize ();
CVector K = I^J; if (removeLast)
K.normalize (); {
I = J^K; CQuat rotStart (0,0,0,1);
I.normalize (); CVector posStart (0,0,0);
tmp.setRot (I, J, K); if (nextRotquatTrack)
tmp.setPos (current.getPos ()); {
current = tmp; // Interpolate the rotation
nextRotquatTrack->interpolate (begin, rotStart);
}
if (nextPosTrack)
{
// Interpolate the position
nextPosTrack->interpolate (begin, posStart);
}
// Remove the init rotation and position of the next animation
tmp.identity ();
tmp.setRot (rotStart);
tmp.setPos (posStart);
tmp.invert ();
current *= tmp;
// Normalize the mt
CVector I = current.getI ();
CVector J = current.getJ ();
I.z = 0;
J.z = 0;
J.normalize ();
CVector K = I^J;
K.normalize ();
I = J^K;
I.normalize ();
tmp.setRot (I, J, K);
tmp.setPos (current.getPos ());
current = tmp;
}
} }
} }
}
void CEntity::animatePlayList(NL3D::TAnimationTime time) void CEntity::animatePlayList(NL3D::TAnimationTime time)
{
if (!_PlayListAnimation.empty())
{ {
// Animation index if (!_PlayListAnimation.empty())
uint id = _AnimationSet->getAnimationIdByName(_PlayListAnimation[0].c_str());
// Try channel AnimationSet
NL3D::UAnimation *anim = _AnimationSet->getAnimation(id);
bool there = false;
UTrack *posTrack = NULL;
UTrack *rotQuatTrack = NULL;
// Current matrix
CMatrix current;
current.identity();
// read an animation for init matrix
rotQuatTrack = anim->getTrackByName("rotquat");
posTrack = anim->getTrackByName("pos");
there = posTrack || rotQuatTrack;
// Accumul time
float startTime = 0;
float endTime = anim->getEndTime() - anim->getBeginTime();
uint index = 0;
while (time >= endTime)
{ {
index++; // Animation index
if (index < _PlayListAnimation.size()) uint id = _AnimationSet->getAnimationIdByName(_PlayListAnimation[0].c_str());
// Try channel AnimationSet
NL3D::UAnimation *anim = _AnimationSet->getAnimation(id);
bool there = false;
UTrack *posTrack = NULL;
UTrack *rotQuatTrack = NULL;
// Current matrix
CMatrix current;
current.identity();
// read an animation for init matrix
rotQuatTrack = anim->getTrackByName("rotquat");
posTrack = anim->getTrackByName("pos");
there = posTrack || rotQuatTrack;
// Accumul time
float startTime = 0;
float endTime = anim->getEndTime() - anim->getBeginTime();
uint index = 0;
while (time >= endTime)
{ {
index++;
if (index < _PlayListAnimation.size())
{
id = _AnimationSet->getAnimationIdByName(_PlayListAnimation[index].c_str());
NL3D::UAnimation *newAnim = _AnimationSet->getAnimation(id);
UTrack *newPosTrack = newAnim->getTrackByName ("pos");
UTrack *newRotquatTrack = newAnim->getTrackByName ("rotquat");
// Add the transformation
addTransformation (current, anim, newAnim->getBeginTime(), anim->getEndTime(), posTrack, rotQuatTrack, newPosTrack, newRotquatTrack, true);
anim = newAnim;
posTrack = newPosTrack;
rotQuatTrack = newRotquatTrack;
// Add start time
startTime = endTime;
endTime = startTime + (anim->getEndTime() - anim->getBeginTime());
}
else
{
// Add the transformation
addTransformation (current, anim, 0, anim->getEndTime(), posTrack, rotQuatTrack, NULL, NULL, false);
break;
}
}
// Time cropped ?
if (index >= _PlayListAnimation.size())
{
// Yes
index--;
id = _AnimationSet->getAnimationIdByName(_PlayListAnimation[index].c_str()); id = _AnimationSet->getAnimationIdByName(_PlayListAnimation[index].c_str());
NL3D::UAnimation *newAnim = _AnimationSet->getAnimation(id); anim = _AnimationSet->getAnimation(id);
UTrack *newPosTrack = newAnim->getTrackByName ("pos"); // End time for last anim
UTrack *newRotquatTrack = newAnim->getTrackByName ("rotquat"); startTime = anim->getEndTime() - time;
// Add the transformation
addTransformation (current, anim, newAnim->getBeginTime(), anim->getEndTime(), posTrack, rotQuatTrack, newPosTrack, newRotquatTrack, true);
anim = newAnim;
posTrack = newPosTrack;
rotQuatTrack = newRotquatTrack;
// Add start time
startTime = endTime;
endTime = startTime + (anim->getEndTime() - anim->getBeginTime());
} }
else else
{ {
// No
// Add the transformation // Add the transformation
addTransformation (current, anim, 0, anim->getEndTime(), posTrack, rotQuatTrack, NULL, NULL, false); addTransformation (current, anim, 0, anim->getBeginTime() + time - startTime, posTrack, rotQuatTrack, NULL, NULL, false);
break;
id = _AnimationSet->getAnimationIdByName(_PlayListAnimation[index].c_str());
anim = _AnimationSet->getAnimation(id);
// Final time
startTime -= anim->getBeginTime();
} }
}
// Time cropped ? // Set the slot
if (index >= _PlayListAnimation.size()) _PlayList->setAnimation(0, id);
{ _PlayList->setTimeOrigin(0, startTime);
// Yes _PlayList->setSpeedFactor(0, 1.0f);
index--; _PlayList->setWeightSmoothness(0, 1.0f);
id = _AnimationSet->getAnimationIdByName(_PlayListAnimation[index].c_str()); _PlayList->setStartWeight(0, 1, 0);
anim = _AnimationSet->getAnimation(id); _PlayList->setEndWeight(0, 1, 1);
_PlayList->setWrapMode(0, UPlayList::Clamp);
// End time for last anim // Setup the pos and rot for this shape
startTime = anim->getEndTime() - time; if (there)
}
else
{
// No
// Add the transformation
addTransformation (current, anim, 0, anim->getBeginTime() + time - startTime, posTrack, rotQuatTrack, NULL, NULL, false);
id = _AnimationSet->getAnimationIdByName(_PlayListAnimation[index].c_str());
anim = _AnimationSet->getAnimation(id);
// Final time
startTime -= anim->getBeginTime();
}
// Set the slot
_PlayList->setAnimation(0, id);
_PlayList->setTimeOrigin(0, startTime);
_PlayList->setSpeedFactor(0, 1.0f);
_PlayList->setWeightSmoothness(0, 1.0f);
_PlayList->setStartWeight(0, 1, 0);
_PlayList->setEndWeight(0, 1, 1);
_PlayList->setWrapMode(0, UPlayList::Clamp);
// Setup the pos and rot for this shape
if (there)
{
CVector pos = current.getPos();
// If a skeleton model
if(!_Skeleton.empty())
{ {
// scale animated pos value with the CFG scale CVector pos = current.getPos();
pos *= _CharacterScalePos;
_Skeleton.setPos(pos); // If a skeleton model
_Skeleton.setRotQuat(current.getRot()); if(!_Skeleton.empty())
} {
else // scale animated pos value with the CFG scale
{ pos *= _CharacterScalePos;
_Instance.setPos(pos); _Skeleton.setPos(pos);
_Instance.setRotQuat(current.getRot()); _Skeleton.setRotQuat(current.getRot());
}
else
{
_Instance.setPos(pos);
_Instance.setRotQuat(current.getRot());
}
} }
} }
} }
}
void CEntity::animateChannelMixer() void CEntity::animateChannelMixer()
{
for (uint i = 0; i < NL3D::CChannelMixer::NumAnimationSlot; i++)
{ {
if (_SlotInfo[i].Enable) for (uint i = 0; i < NL3D::CChannelMixer::NumAnimationSlot; i++)
{ {
// Set the animation if (_SlotInfo[i].Enable)
uint animId = _AnimationSet->getAnimationIdByName(_SlotInfo[i].Animation);
if (animId == UAnimationSet::NotFound)
_PlayList->setAnimation(i, UPlayList::empty);
else
_PlayList->setAnimation(i, animId);
// Set the skeleton weight
uint skelId = _AnimationSet->getSkeletonWeightIdByName(_SlotInfo[i].Skeleton);
if (skelId == UAnimationSet::NotFound)
_PlayList->setSkeletonWeight(i, UPlayList::empty, false);
else
_PlayList->setSkeletonWeight(i, skelId, _SlotInfo[i].SkeletonInverted);
// Set others values
_PlayList->setTimeOrigin(i, _SlotInfo[i].Offset);
_PlayList->setSpeedFactor(i, _SlotInfo[i].SpeedFactor);
_PlayList->setStartWeight(i, _SlotInfo[i].StartBlend, _SlotInfo[i].StartTime);
_PlayList->setEndWeight(i, _SlotInfo[i].EndBlend, _SlotInfo[i].EndTime);
_PlayList->setWeightSmoothness(i, _SlotInfo[i].Smoothness);
// Switch between wrap modes
switch (_SlotInfo[i].ClampMode)
{ {
// Set the animation
uint animId = _AnimationSet->getAnimationIdByName(_SlotInfo[i].Animation);
if (animId == UAnimationSet::NotFound)
_PlayList->setAnimation(i, UPlayList::empty);
else
_PlayList->setAnimation(i, animId);
// Set the skeleton weight
uint skelId = _AnimationSet->getSkeletonWeightIdByName(_SlotInfo[i].Skeleton);
if (skelId == UAnimationSet::NotFound)
_PlayList->setSkeletonWeight(i, UPlayList::empty, false);
else
_PlayList->setSkeletonWeight(i, skelId, _SlotInfo[i].SkeletonInverted);
// Set others values
_PlayList->setTimeOrigin(i, _SlotInfo[i].Offset);
_PlayList->setSpeedFactor(i, _SlotInfo[i].SpeedFactor);
_PlayList->setStartWeight(i, _SlotInfo[i].StartBlend, _SlotInfo[i].StartTime);
_PlayList->setEndWeight(i, _SlotInfo[i].EndBlend, _SlotInfo[i].EndTime);
_PlayList->setWeightSmoothness(i, _SlotInfo[i].Smoothness);
// Switch between wrap modes
switch (_SlotInfo[i].ClampMode)
{
case 0: case 0:
_PlayList->setWrapMode (i, UPlayList::Clamp); _PlayList->setWrapMode (i, UPlayList::Clamp);
break; break;
@ -422,9 +423,9 @@ void CEntity::animateChannelMixer()
case 2: case 2:
_PlayList->setWrapMode (i, UPlayList::Disable); _PlayList->setWrapMode (i, UPlayList::Disable);
break; break;
}
} }
} }
} }
}
} /* namespace NLQT */ } /* namespace NLQT */

View file

@ -1,19 +1,19 @@
/* /*
Object Viewer Qt Object Viewer Qt Widget
Copyright (C) 2010 Dzmitry Kamiahin <dnk-88@tut.by> Copyright (C) 2010 Adrian Jaekel <aj at elane2k dot com>
This program is free software: you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
@ -36,223 +36,225 @@
#include <nel/3d/u_skeleton.h> #include <nel/3d/u_skeleton.h>
#include <nel/3d/channel_mixer.h> #include <nel/3d/channel_mixer.h>
namespace NL3D { namespace NL3D
{
class UPlayList; class UPlayList;
class UAnimationSet; class UAnimationSet;
} }
namespace NLQT { namespace NLQT
class CSlotInfo
{ {
public:
CSlotInfo ():
Animation("empty"), Skeleton("empty"),
Offset(0), StartTime(0), EndTime(0),
StartBlend(1), EndBlend (1), Smoothness(1),
SpeedFactor(1), ClampMode(0),
SkeletonInverted(false),
Enable(true) {} ;
std::string Animation; class CSlotInfo
std::string Skeleton;
float Offset;
float StartTime;
float EndTime;
float StartBlend;
float EndBlend;
float Smoothness;
float SpeedFactor;
sint32 ClampMode;
bool SkeletonInverted;
bool Enable;
CSlotInfo &operator=(const CSlotInfo &);
};
/**
@class CEntity
@brief Class manage animated shape.
@details
Allows you to load animations for shape and skeleton weight.
Contains a built-in playlist. Has management and playback Playlists or Mixer.
*/
class CEntity
{
public:
struct Mode
{ {
enum List public:
CSlotInfo ():
Animation("empty"), Skeleton("empty"),
Offset(0), StartTime(0), EndTime(0),
StartBlend(1), EndBlend (1), Smoothness(1),
SpeedFactor(1), ClampMode(0),
SkeletonInverted(false),
Enable(true) {} ;
std::string Animation;
std::string Skeleton;
float Offset;
float StartTime;
float EndTime;
float StartBlend;
float EndBlend;
float Smoothness;
float SpeedFactor;
sint32 ClampMode;
bool SkeletonInverted;
bool Enable;
CSlotInfo &operator=(const CSlotInfo &);
};
/**
@class CEntity
@brief Class manage animated shape.
@details
Allows you to load animations for shape and skeleton weight.
Contains a built-in playlist. Has management and playback Playlists or Mixer.
*/
class CEntity
{
public:
struct Mode
{ {
PlayList = 1, enum List
Mixer {
PlayList = 1,
Mixer
};
}; };
};
/// Will need for a single or multiple animation shape /// Will need for a single or multiple animation shape
struct SAnimationStatus struct SAnimationStatus
{ {
bool LoopAnim; bool LoopAnim;
bool PlayAnim; bool PlayAnim;
float CurrentTimeAnim; float CurrentTimeAnim;
float StartAnim; float StartAnim;
float EndAnim; float EndAnim;
float SpeedAnim; float SpeedAnim;
int Mode; int Mode;
SAnimationStatus(): SAnimationStatus():
LoopAnim(false), PlayAnim(false), LoopAnim(false), PlayAnim(false),
CurrentTimeAnim(0), StartAnim(0), CurrentTimeAnim(0), StartAnim(0),
EndAnim(0), SpeedAnim(1), Mode(Mode::PlayList) {} EndAnim(0), SpeedAnim(1), Mode(Mode::PlayList) {}
}; };
/// Destructor /// Destructor
~CEntity(void); ~CEntity(void);
/// Loads a file animations /// Loads a file animations
/// @param fileName - name animation file /// @param fileName - name animation file
void loadAnimation(std::string &fileName); void loadAnimation(std::string &fileName);
/// Loads a file skeleton weight /// Loads a file skeleton weight
void loadSWT(std::string &fileName); void loadSWT(std::string &fileName);
/// Adds an animation to a playlist /// Adds an animation to a playlist
/// @param name - name loaded animations /// @param name - name loaded animations
void addAnimToPlayList(std::string &name); void addAnimToPlayList(std::string &name);
/// Removes the animation from a playlist /// Removes the animation from a playlist
/// @param row - number of animations in the playlist /// @param row - number of animations in the playlist
void removeAnimToPlayList(uint row); void removeAnimToPlayList(uint row);
/// Swaps animations to a playlist /// Swaps animations to a playlist
/// @param row1 - first number of animations in the playlist /// @param row1 - first number of animations in the playlist
/// @param row2 - second number of animations in the playlist /// @param row2 - second number of animations in the playlist
void swapAnimToPlayList(uint row1, uint row2); void swapAnimToPlayList(uint row1, uint row2);
/// Playback animation /// Playback animation
void playbackAnim(bool play); void playbackAnim(bool play);
/// Reset playlist and animation /// Reset playlist and animation
void reset(); void reset();
/// Get the total time of animation playlist /// Get the total time of animation playlist
/// @return total time of animation /// @return total time of animation
float getPlayListLength(); float getPlayListLength();
/// get time length single animation /// get time length single animation
float getAnimLength(std::string name); float getAnimLength(std::string name);
/// Get slot infomation /// Get slot infomation
void setSlotInfo(uint num, CSlotInfo& slotInfo) { _SlotInfo[num] = slotInfo; } void setSlotInfo(uint num, CSlotInfo& slotInfo) { _SlotInfo[num] = slotInfo; }
/// Set use mode playlist or mixer /// Set use mode playlist or mixer
void setMode(int mode) { _AnimationStatus.Mode = mode; } void setMode(int mode) { _AnimationStatus.Mode = mode; }
/// Set in place mode animation /// Set in place mode animation
void setInPlace(bool enabled) { _inPlace = enabled; } void setInPlace(bool enabled) { _inPlace = enabled; }
/// Get in place mode /// Get in place mode
bool getInPlace() { return _inPlace; } bool getInPlace() { return _inPlace; }
/// Set inc position /// Set inc position
void setIncPos(bool enabled) { _incPos = enabled; } void setIncPos(bool enabled) { _incPos = enabled; }
/// Get inc position /// Get inc position
bool getIncPos() { return _incPos; } bool getIncPos() { return _incPos; }
/// Get information about the current status of playing a playlist /// Get information about the current status of playing a playlist
/// @return struct containing current information playback /// @return struct containing current information playback
SAnimationStatus getStatus() { return _AnimationStatus; } SAnimationStatus getStatus() { return _AnimationStatus; }
/// Get name entity /// Get name entity
/// @return name entity /// @return name entity
std::string getName() { return _Name; } std::string getName() { return _Name; }
/// Get file name shape /// Get file name shape
/// @return file name shape /// @return file name shape
std::string getFileNameShape() { return _FileNameShape; } std::string getFileNameShape() { return _FileNameShape; }
/// Get file name skeleton /// Get file name skeleton
/// @return file name skeleton /// @return file name skeleton
std::string getFileNameSkeleton() { return _FileNameSkeleton; } std::string getFileNameSkeleton() { return _FileNameSkeleton; }
/// Get slot information /// Get slot information
CSlotInfo getSlotInfo(uint num) { return _SlotInfo[num]; } CSlotInfo getSlotInfo(uint num) { return _SlotInfo[num]; }
/// Get list loaded animations files /// Get list loaded animations files
std::vector<std::string>& getAnimationList() { return _AnimationList; } std::vector<std::string>& getAnimationList() { return _AnimationList; }
/// Get playlist animations /// Get playlist animations
std::vector<std::string>& getPlayListAnimation() { return _PlayListAnimation; } std::vector<std::string>& getPlayListAnimation() { return _PlayListAnimation; }
/// Get list loaded skeleton weight template files /// Get list loaded skeleton weight template files
std::vector<std::string>& getSWTList() { return _SWTList; } std::vector<std::string>& getSWTList() { return _SWTList; }
/// Get game interface for manipulating Skeleton. /// Get game interface for manipulating Skeleton.
NL3D::USkeleton getSkeleton() const { return _Skeleton; } NL3D::USkeleton getSkeleton() const { return _Skeleton; }
private: private:
/// Constructor /// Constructor
CEntity(void); CEntity(void);
/// Update the animate from the playlist or channel mixer /// Update the animate from the playlist or channel mixer
/// @param time - current time in second /// @param time - current time in second
void update(NL3D::TAnimationTime time); void update(NL3D::TAnimationTime time);
void resetChannel(); void resetChannel();
/// Update the animate from the playlist /// Update the animate from the playlist
void animatePlayList(NL3D::TAnimationTime time); void animatePlayList(NL3D::TAnimationTime time);
/// Update the animate from the mixer /// Update the animate from the mixer
void animateChannelMixer(); void animateChannelMixer();
void addTransformation (NLMISC::CMatrix &current, NL3D::UAnimation *anim, void addTransformation (NLMISC::CMatrix &current, NL3D::UAnimation *anim,
float begin, float end, float begin, float end,
NL3D::UTrack *posTrack, NL3D::UTrack *rotquatTrack, NL3D::UTrack *posTrack, NL3D::UTrack *rotquatTrack,
NL3D::UTrack *nextPosTrack, NL3D::UTrack *nextRotquatTrack, NL3D::UTrack *nextPosTrack, NL3D::UTrack *nextRotquatTrack,
bool removeLast); bool removeLast);
// The name of the entity // The name of the entity
std::string _Name; std::string _Name;
std::string _FileNameShape; std::string _FileNameShape;
std::string _FileNameSkeleton; std::string _FileNameSkeleton;
SAnimationStatus _AnimationStatus; SAnimationStatus _AnimationStatus;
bool _inPlace; bool _inPlace;
bool _incPos; bool _incPos;
float _CharacterScalePos; float _CharacterScalePos;
// The mesh instance associated to this entity // The mesh instance associated to this entity
NL3D::UInstance _Instance; NL3D::UInstance _Instance;
// The skeleton binded to the instance // The skeleton binded to the instance
NL3D::USkeleton _Skeleton; NL3D::USkeleton _Skeleton;
NL3D::UPlayList *_PlayList; NL3D::UPlayList *_PlayList;
NL3D::UAnimationSet *_AnimationSet; NL3D::UAnimationSet *_AnimationSet;
// Animation input file // Animation input file
std::vector<std::string> _AnimationList; std::vector<std::string> _AnimationList;
// Skeleton weight input file // Skeleton weight input file
std::vector<std::string> _SWTList; std::vector<std::string> _SWTList;
// Play list animation // Play list animation
std::vector<std::string > _PlayListAnimation; std::vector<std::string > _PlayListAnimation;
// Slot info for this object // Slot info for this object
CSlotInfo _SlotInfo[NL3D::CChannelMixer::NumAnimationSlot]; CSlotInfo _SlotInfo[NL3D::CChannelMixer::NumAnimationSlot];
friend class CObjectViewerWidget; friend class CObjectViewerWidget;
}; /* class CEntity */ }; /* class CEntity */
typedef std::map<std::string, CEntity> CEntities; typedef std::map<std::string, CEntity> CEntities;
typedef CEntities::iterator EIT; typedef CEntities::iterator EIT;
} /* namespace NLQT */ } /* namespace NLQT */

View file

@ -19,10 +19,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef INTERFACES_H #ifndef INTERFACES_H
#define INTERFACES_H #define INTERFACES_H
#include "stdpch.h"
#include "entity.h"
#include <QtPlugin> #include <QtPlugin>
namespace NL3D { namespace NL3D
{
class UPlayListManager; class UPlayListManager;
class UDriver;
class UScene;
} }
namespace NLQT namespace NLQT
@ -65,6 +71,7 @@ namespace NLQT
virtual bool setupLight(const NLMISC::CVector &position, const NLMISC::CVector &direction) = 0; virtual bool setupLight(const NLMISC::CVector &position, const NLMISC::CVector &direction) = 0;
virtual void setVisible(bool visible) = 0; virtual void setVisible(bool visible) = 0;
virtual QWidget* getWidget() = 0; virtual QWidget* getWidget() = 0;
virtual void setNelContext(NLMISC::INelContext &nelContext) = 0;
}; };

View file

@ -78,13 +78,20 @@ namespace NLQT
} }
void CObjectViewerWidget::setNelContext(NLMISC::INelContext &nelContext)
{
_LibContext = new CLibraryContext(nelContext);
}
void CObjectViewerWidget::init() void CObjectViewerWidget::init()
{ {
connect(this, SIGNAL(topLevelChanged(bool)), connect(this, SIGNAL(topLevelChanged(bool)),
this, SLOT(topLevelChanged(bool))); this, SLOT(topLevelChanged(bool)));
//H_AUTO2 //H_AUTO2
//nldebug("%d %d %d",_nlw->winId(), width(), height()); //nldebug("%d %d %d",_nlw->winId(), width(), height());
#if defined(NL_OS_UNIX) && !defined(NL_OS_MAC) #if defined(NL_OS_UNIX) && !defined(NL_OS_MAC)
//dynamic_cast<QNLWidget*>(widget())->makeCurrent(); //dynamic_cast<QNLWidget*>(widget())->makeCurrent();
#endif // defined(NL_OS_UNIX) && !defined(NL_OS_MAC) #endif // defined(NL_OS_UNIX) && !defined(NL_OS_MAC)
@ -410,7 +417,6 @@ namespace NLQT
if ( _Entities.count(fileName) != 0) if ( _Entities.count(fileName) != 0)
return false; return false;
CPath::display();
CPath::addSearchPath(CFile::getPath(meshFileName), false, false); CPath::addSearchPath(CFile::getPath(meshFileName), false, false);
// create instance of the mesh character // create instance of the mesh character

View file

@ -63,12 +63,13 @@ namespace NLQT
CObjectViewerWidget(QWidget *parent = 0); CObjectViewerWidget(QWidget *parent = 0);
virtual ~CObjectViewerWidget(); virtual ~CObjectViewerWidget();
virtual QPaintEngine* paintEngine() const { return NULL; }
void setNelContext(NLMISC::INelContext &nelContext);
static CObjectViewerWidget &objViewWid() { return *_objectViewerWidget; } static CObjectViewerWidget &objViewWid() { return *_objectViewerWidget; }
/// Init a driver and create scene. /// Init a driver and create scene.
/// @param wnd - handle window.
/// @param w - width window.
/// @param h - height window.
void init(); void init();
/// Release class. /// Release class.
@ -176,6 +177,8 @@ namespace NLQT
static CObjectViewerWidget *_objectViewerWidget; static CObjectViewerWidget *_objectViewerWidget;
NLMISC::CLibraryContext *_LibContext;
// render stuff // render stuff
QTimer *_mainTimer; QTimer *_mainTimer;
bool _isGraphicsInitialized, _isGraphicsEnabled; bool _isGraphicsInitialized, _isGraphicsEnabled;

View file

@ -1,19 +1,19 @@
/* /*
Georges Editor Qt Object Viewer Qt Widget
Copyright (C) 2010 Adrian Jaekel <aj at elane2k dot com> Copyright (C) 2010 Adrian Jaekel <aj at elane2k dot com>
This program is free software: you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "stdpch.h" #include "stdpch.h"

View file

@ -1,19 +1,19 @@
/* /*
Object Viewer Qt Object Viewer Qt Widget
Copyright (C) 2010 Dzmitry Kamiahin <dnk-88@tut.by> Copyright (C) 2010 Adrian Jaekel <aj at elane2k dot com>
This program is free software: you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */

View file

@ -43,7 +43,7 @@ SOURCE_GROUP("r2" FILES ${SRC_R2})
# on Mac, create a .App Bundle # on Mac, create a .App Bundle
if(APPLE) if(APPLE)
SET(MACOSX_BUNDLE_INFO_STRING "Ryzom Core Client") SET(MACOSX_BUNDLE_INFO_STRING "Ryzom Core Client")
SET(MACOSX_BUNDLE_ICON_FILE "") SET(MACOSX_BUNDLE_ICON_FILE "atys.icns")
SET(MACOSX_BUNDLE_GUI_IDENTIFIER "") SET(MACOSX_BUNDLE_GUI_IDENTIFIER "")
SET(MACOSX_BUNDLE_LONG_VERSION_STRING ${NL_VERSION}) SET(MACOSX_BUNDLE_LONG_VERSION_STRING ${NL_VERSION})
SET(MACOSX_BUNDLE_BUNDLE_NAME "Ryzom Core Client") SET(MACOSX_BUNDLE_BUNDLE_NAME "Ryzom Core Client")

View file

@ -558,7 +558,7 @@ void CMicroLifeManager::tileAdded(const NL3D::CTileAddedInfo &infos)
#if !FINAL_VERSION #if !FINAL_VERSION
// for debug display, tells that it was generated dynamically // for debug display, tells that it was generated dynamically
newFX.FromIG = false; newFX.FromIG = false;
#endif #endif
// spawn a primitive on the quad // spawn a primitive on the quad
float weight[3]; float weight[3];
// compute weight values by computing some noise values around // compute weight values by computing some noise values around

Binary file not shown.

After

Width:  |  Height:  |  Size: 779 KiB

View file

@ -9,7 +9,7 @@ INCLUDE( ${QT_USE_FILE} )
FILE(GLOB GEORGES_EDITOR_SRC *.cpp *.h) FILE(GLOB GEORGES_EDITOR_SRC *.cpp *.h)
SET(GEORGES_EDITOR_HDR georges_dirtree_dialog.h georges_treeview_dialog.h main_window.h SET(GEORGES_EDITOR_HDR georges_dirtree_dialog.h georges_treeview_dialog.h main_window.h
objectviewer_dialog.h settings_dialog.h progress_dialog.h object_viewer_widget.h) objectviewer_dialog.h settings_dialog.h progress_dialog.h)
SET(GEORGES_EDITOR_UIS settings_form.ui objectviewer_form.ui log_form.ui georges_treeview_form.ui georges_dirtree_form.ui) SET(GEORGES_EDITOR_UIS settings_form.ui objectviewer_form.ui log_form.ui georges_treeview_form.ui georges_dirtree_form.ui)
SET(GEORGES_EDITOR_RCS georges_editor_qt.qrc) SET(GEORGES_EDITOR_RCS georges_editor_qt.qrc)
@ -24,6 +24,17 @@ SOURCE_GROUP(QtResources FILES ${GEORGES_EDITOR_UIS} ${GEORGES_EDITOR_RCS})
SOURCE_GROUP(QtGeneratedUiHdr FILES ${GEORGES_EDITOR_UI_HDRS}) SOURCE_GROUP(QtGeneratedUiHdr FILES ${GEORGES_EDITOR_UI_HDRS})
SOURCE_GROUP(QtGeneratedMocSrc FILES ${GEORGES_EDITOR_MOC_SRCS}) SOURCE_GROUP(QtGeneratedMocSrc FILES ${GEORGES_EDITOR_MOC_SRCS})
if(APPLE)
SET(MACOSX_BUNDLE_INFO_STRING "Georges Editor Qt")
SET(MACOSX_BUNDLE_ICON_FILE "georges_logo.icns")
SET(MACOSX_BUNDLE_GUI_IDENTIFIER "")
SET(MACOSX_BUNDLE_LONG_VERSION_STRING ${NL_VERSION})
SET(MACOSX_BUNDLE_BUNDLE_NAME "Georges Editor Qt")
SET(MACOSX_BUNDLE_SHORT_VERSION_STRING "0.9")
SET(MACOSX_BUNDLE_BUNDLE_VERSION "0.9")
SET(MACOSX_BUNDLE_COPYRIGHT "Winchgate and The Ryzom Core Community")
ENDIF(APPLE)
ADD_EXECUTABLE(georges_editor_qt WIN32 MACOSX_BUNDLE ${GEORGES_EDITOR_SRC} ${GEORGES_EDITOR_MOC_SRCS} ${GEORGES_EDITOR_RC_SRCS} ${GEORGES_EDITOR_UI_HDRS}) ADD_EXECUTABLE(georges_editor_qt WIN32 MACOSX_BUNDLE ${GEORGES_EDITOR_SRC} ${GEORGES_EDITOR_MOC_SRCS} ${GEORGES_EDITOR_RC_SRCS} ${GEORGES_EDITOR_UI_HDRS})
TARGET_LINK_LIBRARIES(georges_editor_qt TARGET_LINK_LIBRARIES(georges_editor_qt

View file

@ -76,23 +76,23 @@ CEntity::~CEntity(void)
if (_PlayList != NULL) if (_PlayList != NULL)
{ {
_PlayList->resetAllChannels(); _PlayList->resetAllChannels();
//Modules::objViewWid().getPlayListManager()->deletePlayList (_PlayList); Modules::objViewInt().getPlayListManager()->deletePlayList (_PlayList);
_PlayList = NULL; _PlayList = NULL;
} }
if (_AnimationSet != NULL) if (_AnimationSet != NULL)
{ {
//Modules::objViewWid().getDriver()->deleteAnimationSet(_AnimationSet); Modules::objViewInt().getDriver()->deleteAnimationSet(_AnimationSet);
_AnimationSet = NULL; _AnimationSet = NULL;
} }
if (!_Skeleton.empty()) if (!_Skeleton.empty())
{ {
_Skeleton.detachSkeletonSon(_Instance); _Skeleton.detachSkeletonSon(_Instance);
//Modules::objViewWid().getScene()->deleteSkeleton(_Skeleton); Modules::objViewInt().getScene()->deleteSkeleton(_Skeleton);
_Skeleton = NULL; _Skeleton = NULL;
} }
if (!_Instance.empty()) if (!_Instance.empty())
{ {
//Modules::objViewWid().getScene()->deleteInstance(_Instance); Modules::objViewInt().getScene()->deleteInstance(_Instance);
_Instance = NULL; _Instance = NULL;
} }
} }

View file

@ -1,19 +1,19 @@
/* /*
Georges Editor Qt Georges Editor Qt
Copyright (C) 2010 Adrian Jaekel <aj at elane2k dot com> Copyright (C) 2010 Adrian Jaekel <aj at elane2k dot com>
This program is free software: you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "modules.h" #include "modules.h"
@ -23,8 +23,9 @@
#include <QDir> #include <QDir>
#include <QString> #include <QString>
#include <nel/misc/debug.h>
NLQT::CConfiguration *Modules::_configuration = NULL; NLQT::CConfiguration *Modules::_configuration = NULL;
NLQT::CObjectViewerWidget *Modules::_objectViewerWidget = NULL;
NLQT::IObjectViewer *Modules::_objViewerInterface = NULL; NLQT::IObjectViewer *Modules::_objViewerInterface = NULL;
NLQT::CMainWindow *Modules::_mainWindow = NULL; NLQT::CMainWindow *Modules::_mainWindow = NULL;
@ -32,45 +33,71 @@ void Modules::init()
{ {
loadPlugin(); loadPlugin();
_objViewerInterface->setNelContext(NLMISC::INelContext::getInstance());
if (_configuration == NULL) _configuration = new NLQT::CConfiguration; if (_configuration == NULL) _configuration = new NLQT::CConfiguration;
config().init(); config().init();
if (_objectViewerWidget == NULL) _objectViewerWidget = new NLQT::CObjectViewerWidget;
if (_mainWindow == NULL) _mainWindow = new NLQT::CMainWindow; if (_mainWindow == NULL) _mainWindow = new NLQT::CMainWindow;
} }
void Modules::release() void Modules::release()
{ {
delete _mainWindow; _mainWindow = NULL; delete _mainWindow; _mainWindow = NULL;
//delete _objectViewerWidget; _objectViewerWidget = NULL;
config().release(); config().release();
delete _configuration; _configuration = NULL; delete _configuration; _configuration = NULL;
} }
bool Modules::loadPlugin() bool Modules::loadPlugin()
{ {
QDir pluginsDir(qApp->applicationDirPath()); #if defined(Q_OS_WIN)
/*#if defined(Q_OS_WIN) QString pluginPath = qApp->applicationDirPath();
if (pluginsDir.dirName().toLower() == "debug" || pluginsDir.dirName().toLower() == "release") QString pluginFilename = "object_viewer_widget_qt.dll";
pluginsDir.cdUp(); #elif defined(Q_OS_MAC)
#elif defined(Q_OS_MAC) QString pluginPath = qApp->applicationDirPath() + "/../PlugIns/";
if (pluginsDir.dirName() == "MacOS") { QString pluginFilename = "libobject_viewer_widget_qt.so";
pluginsDir.cdUp(); #else // LINUX
pluginsDir.cdUp(); QString pluginPath = qApp->applicationDirPath();
pluginsDir.cdUp(); QString pluginFilename = "libobject_viewer_widget_qt.so";
} #endif
#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; // if(!QFile::exists(pluginPath + pluginFilename))
} // {
// nlwarning("Cannot find %s in %s, fallback to working dir",
// pluginFilename.toStdString().c_str(), pluginPath.toStdString().c_str());
//
// pluginPath = "";
//
// Q_FOREACH (QString path, qApp->libraryPaths())
// nlwarning("libraryPaths %s", path.toStdString().c_str());
// }
QDir pluginsDir(pluginPath);
QPluginLoader pluginLoader(pluginsDir.absoluteFilePath(pluginFilename));
QObject *plugin = pluginLoader.instance();
if (plugin)
{
_objViewerInterface = qobject_cast<NLQT::IObjectViewer *>(plugin);
if (_objViewerInterface)
{
nlinfo("Loaded %s",
pluginsDir.absoluteFilePath(pluginFilename).toStdString().c_str());
return true;
}
else
{
nlwarning("Loaded %s, but cannot cast to NLQT::IObjectViewer*",
pluginFilename.toStdString().c_str());
}
}
else
{
nlwarning("Cannot get plugin instance for %s (searched in %s)",
pluginFilename.toStdString().c_str(),
(qApp->applicationDirPath() + pluginPath).toStdString().c_str());
}
return false;
}

View file

@ -20,10 +20,7 @@
#define MODULES_H #define MODULES_H
#include "configuration.h" #include "configuration.h"
//#include "object_viewer.h"
#include "object_viewer_widget.h"
#include "main_window.h" #include "main_window.h"
#include "interfaces.h" #include "interfaces.h"
class Modules class Modules
@ -34,18 +31,13 @@ public:
static NLQT::CConfiguration &config() { return *_configuration; } static NLQT::CConfiguration &config() { return *_configuration; }
static NLQT::IObjectViewer &objViewInt() { return *_objViewerInterface; } static NLQT::IObjectViewer &objViewInt() { return *_objViewerInterface; }
static NLQT::CObjectViewerWidget &objViewWid() { return *_objectViewerWidget; }
//static NLQT::CGeorges &georges() { return *_georges;}
static NLQT::CMainWindow &mainWin() { return *_mainWindow; } static NLQT::CMainWindow &mainWin() { return *_mainWindow; }
private: private:
static bool loadPlugin(); static bool loadPlugin();
static NLQT::IObjectViewer *_objViewerInterface;
static NLQT::IObjectViewer *_objViewerInterface;
static NLQT::CConfiguration *_configuration; static NLQT::CConfiguration *_configuration;
//static NLQT::CObjectViewer *_objectViewer;
static NLQT::CObjectViewerWidget *_objectViewerWidget;
static NLQT::CMainWindow *_mainWindow; static NLQT::CMainWindow *_mainWindow;
//static NLQT::CGeorges *_georges;
}; };
#endif // MODULES_H #endif // MODULES_H

View file

@ -1,541 +0,0 @@
/*
Georges Editor Qt
Copyright (C) 2010 Adrian Jaekel <aj at elane2k dot com>
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 <http://www.gnu.org/licenses/>.
*/
#include "object_viewer.h"
// 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/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>
//#include <nel/3d/event_mouse_listener.h>
// Project includes
#include "modules.h"
#include "configuration.h"
using namespace std;
using namespace NLMISC;
using namespace NL3D;
namespace NLQT
{
CObjectViewer::CObjectViewer()
: _Driver(NULL), _Light(0),
_phi(0), _psi(0),_dist(2),
_CameraFocal(75),
_CurrentInstance(""),
_BloomEffect(false), _Scene(0)
{
}
CObjectViewer::~CObjectViewer()
{
}
void CObjectViewer::reinit(nlWindow wnd, uint16 w, uint16 h)
{
nldebug("CObjectViewert::reinit");
//release();
//init(wnd, w, h);
//_Driver->setDisplay(wnd, NL3D::UDriver::CMode(w, h, 32));
}
void CObjectViewer::init(nlWindow wnd, uint16 w, uint16 h)
{
nldebug("CObjectViewer::init");
// 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 CObjectViewer::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 CObjectViewer::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 CObjectViewer::renderDriver()
{
// Render the scene.
if((NL3D::CBloomEffect::instance().getDriver() != NULL) && (_BloomEffect))
{
NL3D::CBloomEffect::instance().initBloom();
}
_Driver->clearBuffers(_BackgroundColor);
}
void CObjectViewer::renderScene()
{
// render the scene
_Scene->render();
if((NL3D::CBloomEffect::instance().getDriver() != NULL) && (_BloomEffect))
{
NL3D::CBloomEffect::instance().endBloom();
NL3D::CBloomEffect::instance().endInterfacesDisplayBloom();
}
}
void CObjectViewer::renderDebug2D()
{
}
void CObjectViewer::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 CObjectViewer::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 CObjectViewer::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 CObjectViewer::updateCamera(float deltaPsi, float deltaPhi, float deltaDist)
{
}
void CObjectViewer::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 CObjectViewer::setGraphicsDriver(bool Direct3D)
{
_Direct3D = Direct3D;
if (_Direct3D) Modules::config().getConfigFile().getVar("GraphicsDriver").setAsString("Direct3D");
else Modules::config().getConfigFile().getVar("GraphicsDriver").setAsString("OpenGL");
}
void CObjectViewer::setSizeViewport(uint16 w, uint16 h)
{
_Scene->getCam().setPerspective(_CameraFocal * (float)Pi/180.f, (float)w/h, 0.1f, 1000);
}
void CObjectViewer::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& CObjectViewer::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 CObjectViewer::getListObjects(std::vector<std::string> &listObj)
{
listObj.clear();
for (EIT eit = _Entities.begin(); eit != _Entities.end(); ++eit)
listObj.push_back((*eit).second._Name);
}
void CObjectViewer::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 CObjectViewer::deleteEntities()
{
for (EIT eit = _Entities.begin(); eit != _Entities.end(); ++eit)
{
CEntity &entity = (*eit).second;
deleteEntity(entity);
}
_Entities.clear();
}
void CObjectViewer::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 CObjectViewer::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;
}
} /* namespace NLQT */

View file

@ -1,198 +0,0 @@
/*
Georges Editor Qt
Copyright (C) 2010 Adrian Jaekel <aj at elane2k dot com>
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 <http://www.gnu.org/licenses/>.
*/
#ifndef OBJECT_VIEWER_H
#define OBJECT_VIEWER_H
#include <nel/misc/types_nl.h>
// STL includes
#include <string>
#include <map>
// NeL includes
#include <nel/misc/config_file.h>
#include <nel/misc/rgba.h>
#include <nel/3d/event_mouse_listener.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
@brief namespace NLQT
*/
namespace NLQT
{
/**
@class CObjectViewer
A CObjectViewer class loading and viewing shape, particle system files.
*/
class CObjectViewer
{
public:
/// Default constructor.
CObjectViewer();
virtual ~CObjectViewer();
/// Init a driver and create scene.
/// @param wnd - handle window.
/// @param w - width window.
/// @param h - height window.
void init(nlWindow wnd, uint16 w, uint16 h);
void reinit(nlWindow wnd, uint16 w, uint16 h);
/// 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);
private:
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 CObjectViewer */
} /* namespace NLQT */
#endif // OBJECT_VIEWER_H

View file

@ -1,756 +0,0 @@
/*
Georges Editor Qt
Copyright (C) 2010 Adrian Jaekel <aj at elane2k dot com>
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 <http://www.gnu.org/licenses/>.
*/
#include "object_viewer_widget.h"
// 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(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()
{
}
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()
// code assuming visible window needed to init the 3d driver
nldebug("%d", visible);
if (visible)
{
QWidget::setVisible(true);
}
else
{
QWidget::setVisible(false);
}
}
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 (getDriver() && getDriver()->isActive())
{
NL3D::IDriver *driver = dynamic_cast<NL3D::CDriverUser*>(getDriver())->getDriver();
if (driver)
{
winProc proc = (winProc)driver->getWindowProc();
return proc(driver, message->hwnd, message->message, message->wParam, message->lParam);
}
}
return false;
}
#elif defined(NL_OS_MAC)
typedef bool (*cocoaProc)(NL3D::IDriver*, const void* e);
bool CObjectViewerWidget::macEvent(EventHandlerCallRef caller, EventRef event)
{
if(caller)
nlerror("You are using QtCarbon! Only QtCocoa supported, please upgrade Qt");
if (getDriver() && getDriver()->isActive())
{
NL3D::IDriver *driver = dynamic_cast<NL3D::CDriverUser*>(getDriver())->getDriver();
if (driver)
{
cocoaProc proc = (cocoaProc)driver->getWindowProc();
return proc(driver, event);
}
}
return false;
}
#elif defined(NL_OS_UNIX)
typedef bool (*x11Proc)(NL3D::IDriver *drv, XEvent *e);
bool CObjectViewerWidget::x11Event(XEvent *event)
{
if (getDriver() && getDriver()->isActive())
{
NL3D::IDriver *driver = dynamic_cast<NL3D::CDriverUser*>(getDriver())->getDriver();
if (driver)
{
x11Proc proc = (x11Proc)driver->getWindowProc();
return proc(driver, event);
}
}
return false;
}
#endif
} /* namespace NLQT */

View file

@ -1,211 +0,0 @@
/*
Georges Editor Qt
Copyright (C) 2010 Adrian Jaekel <aj at elane2k dot com>
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 <http://www.gnu.org/licenses/>.
*/
#ifndef OBJECT_VIEWER_WIDGET_H
#define OBJECT_VIEWER_WIDGET_H
// STL 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
@brief namespace NLQT
*/
namespace NLQT
{
class CObjectViewerWidget: public QWidget
{
Q_OBJECT
public:
/// Default constructor.
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:
#if defined(NL_OS_WINDOWS)
virtual bool winEvent(MSG * message, long * result);
#elif defined(NL_OS_MAC)
virtual bool macEvent(EventHandlerCallRef caller, EventRef event);
#elif defined(NL_OS_UNIX)
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 */
#endif // OBJECT_VIEWER_WIDGET_H

View file

@ -46,7 +46,7 @@ namespace NLQT
{ {
_ui.setupUi(this); _ui.setupUi(this);
_nlw = Modules::objViewInt().getWidget(); _nlw = dynamic_cast<QNLWidget*>(Modules::objViewInt().getWidget());
//_nlw->setObjectName(QString::fromUtf8("nlwidget")); //_nlw->setObjectName(QString::fromUtf8("nlwidget"));
_ui.gridLayout->addWidget(_nlw, 0, 0); _ui.gridLayout->addWidget(_nlw, 0, 0);
} }

View file

@ -59,7 +59,6 @@ namespace NLQT
~CObjectViewerDialog(); ~CObjectViewerDialog();
virtual void setVisible(bool visible); virtual void setVisible(bool visible);
virtual QPaintEngine* paintEngine() const { return NULL; }
QAction *createSaveScreenshotAction(QObject *parent); QAction *createSaveScreenshotAction(QObject *parent);
QAction *createSetBackgroundColor(QObject *parent); QAction *createSetBackgroundColor(QObject *parent);