1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010-2018 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
6 // Copyright (C) 2015-2020 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
8 // This program is free software: you can redistribute it and/or modify
9 // it under the terms of the GNU Affero General Public License as
10 // published by the Free Software Foundation, either version 3 of the
11 // License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU Affero General Public License for more details.
18 // You should have received a copy of the GNU Affero General Public License
19 // along with this program. If not, see <http://www.gnu.org/licenses/>.
23 // ----------------------------------------------------------------------------
26 #include "interface_3d_scene.h"
27 #include "interface_manager.h"
28 #include "character_3d.h"
29 #include "../time_client.h"
30 #include "../entities.h"
32 #include "nel/3d/u_point_light.h"
33 #include "nel/3d/u_particle_system_instance.h"
34 #include "nel/3d/u_animation_set.h"
37 #include "nel/misc/xml_auto_ptr.h"
38 #include "nel/gui/action_handler.h"
40 #include "nel/gui/lua_ihm.h"
42 // ----------------------------------------------------------------------------
45 using namespace NLMISC
;
47 // ----------------------------------------------------------------------------
49 // ----------------------------------------------------------------------------
50 CInterface3DScene::CInterface3DScene(const TCtorParam
¶m
)
51 : CInterfaceGroup(param
)
59 _UserInteraction
= false;
60 _RotYFactor
= _RotZFactor
= 0.005f
;
61 _RotYLimitMin
= _RotZLimitMin
= -(float)(180.0f
/ NLMISC::Pi
);
62 _RotYLimitMax
= _RotZLimitMax
= (float)(180.0f
/ NLMISC::Pi
);
64 _DistLimitMax
= 15.0f
;
68 // ----------------------------------------------------------------------------
69 CInterface3DScene::~CInterface3DScene()
73 for (i
= 0; i
< _Characters
.size(); ++i
)
74 delete _Characters
[i
];
75 for (i
= 0; i
< _IGs
.size(); ++i
)
77 for (i
= 0; i
< _Cameras
.size(); ++i
)
79 for (i
= 0; i
< _Lights
.size(); ++i
)
81 for (i
= 0; i
< _Shapes
.size(); ++i
)
83 for (i
= 0; i
< _FXs
.size(); ++i
)
86 NL3D::UDriver
*Driver
= CViewRenderer::getInstance()->getDriver();
88 Driver
->deleteScene (_Scene
);
90 if (_AutoAnimSet
!= NULL
)
91 Driver
->deleteAnimationSet(_AutoAnimSet
);
94 // ----------------------------------------------------------------------------
95 CInterface3DCharacter
*CInterface3DScene::getCharacter3D(uint index
)
97 nlassert(index
< _Characters
.size());
98 return _Characters
[index
];
101 // ----------------------------------------------------------------------------
102 CInterface3DCamera
*CInterface3DScene::getCamera(uint index
)
104 nlassert(index
< _Cameras
.size());
105 return _Cameras
[index
];
108 // ----------------------------------------------------------------------------
109 bool CInterface3DScene::parse (xmlNodePtr cur
, CInterfaceGroup
*parentGroup
)
111 CInterfaceManager
*pIM
= CInterfaceManager::getInstance();
112 if (!CInterfaceElement::parse(cur
, parentGroup
))
118 // Check for user interaction properties
119 ptr
= (char*) xmlGetProp( cur
, (xmlChar
*)"user_interaction" );
120 if (ptr
) _UserInteraction
= convertBool(ptr
);
122 ptr
= (char*) xmlGetProp( cur
, (xmlChar
*)"rotz_limit_min" );
125 fromString((const char*)ptr
, value
);
126 _RotZLimitMin
= (float)(value
* (NLMISC::Pi
/180.0));
129 ptr
= (char*) xmlGetProp( cur
, (xmlChar
*)"rotz_limit_max" );
132 fromString((const char*)ptr
, value
);
133 _RotZLimitMax
= (float)(value
* (NLMISC::Pi
/180.0));
136 ptr
= (char*) xmlGetProp( cur
, (xmlChar
*)"rotz_factor" );
137 if (ptr
) fromString((const char*)ptr
, _RotZFactor
);
139 ptr
= (char*) xmlGetProp( cur
, (xmlChar
*)"roty_limit_min" );
142 fromString((const char*)ptr
, value
);
143 _RotYLimitMin
= (float)(value
* (NLMISC::Pi
/180.0));
146 ptr
= (char*) xmlGetProp( cur
, (xmlChar
*)"roty_limit_max" );
149 fromString((const char*)ptr
, value
);
150 _RotYLimitMax
= (float)(value
* (NLMISC::Pi
/180.0));
153 ptr
= (char*) xmlGetProp( cur
, (xmlChar
*)"roty_factor" );
154 if (ptr
) fromString((const char*)ptr
, _RotYFactor
);
156 ptr
= (char*) xmlGetProp( cur
, (xmlChar
*)"dist_limit_min" );
157 if (ptr
) fromString((const char*)ptr
, _DistLimitMin
);
159 ptr
= (char*) xmlGetProp( cur
, (xmlChar
*)"dist_limit_max" );
160 if (ptr
) fromString((const char*)ptr
, _DistLimitMax
);
162 ptr
= (char*) xmlGetProp( cur
, (xmlChar
*)"dist_factor" );
163 if (ptr
) fromString((const char*)ptr
, _DistFactor
);
165 // Check right now if this is a reference view
166 ptr
= (char*) xmlGetProp( cur
, (xmlChar
*)"reference" );
170 CInterfaceElement
*pIE
= CWidgetManager::getInstance()->getElementFromId(this->getId(), ptr
.str());
171 _Ref3DScene
= dynamic_cast<CInterface3DScene
*>(pIE
);
173 if (_Ref3DScene
!= NULL
)
175 ptr
= (char*) xmlGetProp( cur
, (xmlChar
*)"curcam" );
176 if (ptr
) setCurrentCamera (ptr
.str());
180 NL3D::UDriver
*Driver
= CViewRenderer::getInstance()->getDriver();
181 nlassert ( Driver
!= NULL
);
183 _Scene
= Driver
->createScene(true);
185 _Scene
->enableLightingSystem(true);
188 ptr
= (char*) xmlGetProp( cur
, (xmlChar
*)"ambient" );
189 rgbaTmp
= CRGBA::Black
;
190 if (ptr
) rgbaTmp
= convertColor(ptr
);
191 _Scene
->setAmbientGlobal(rgbaTmp
);
193 ptr
= (char*) xmlGetProp( cur
, (xmlChar
*)"sun_ambient" );
194 rgbaTmp
= CRGBA(50,50,50);
195 if (ptr
) rgbaTmp
= convertColor(ptr
);
196 _Scene
->setSunAmbient(rgbaTmp
);
198 ptr
= (char*) xmlGetProp( cur
, (xmlChar
*)"sun_diffuse" );
199 rgbaTmp
= CRGBA::White
;
200 if (ptr
) rgbaTmp
= convertColor(ptr
);
201 _Scene
->setSunDiffuse(rgbaTmp
);
203 ptr
= (char*) xmlGetProp( cur
, (xmlChar
*)"sun_specular" );
204 rgbaTmp
= CRGBA::White
;
205 if (ptr
) rgbaTmp
= convertColor(ptr
);
206 _Scene
->setSunSpecular(rgbaTmp
);
209 ptr
= (char*) xmlGetProp( cur
, (xmlChar
*)"sun_direction" );
210 if (ptr
) v
= convertVector(ptr
);
211 _Scene
->setSunDirection(v
);
218 // Check that this is a camera node
219 if ( stricmp((char*)cur
->name
,"character3d") == 0 )
221 CInterface3DCharacter
*pCha
= new CInterface3DCharacter
;
222 if (!pCha
->parse(cur
,this))
225 nlwarning("character3d not added to scene3d");
229 _Characters
.push_back(pCha
);
232 else if ( stricmp((char*)cur
->name
,"ig") == 0 )
234 CInterface3DIG
*pIG
= new CInterface3DIG
;
235 if (!pIG
->parse(cur
,this))
238 nlwarning("ig not added to scene3d");
245 else if ( stricmp((char*)cur
->name
,"shape") == 0 )
247 CInterface3DShape
*pShp
= new CInterface3DShape
;
248 if (!pShp
->parse(cur
,this))
251 nlwarning("shape not added to scene3d");
255 _Shapes
.push_back(pShp
);
258 else if ( stricmp((char*)cur
->name
,"camera") == 0 )
260 CInterface3DCamera
*pCam
= new CInterface3DCamera
;
261 if (!pCam
->parse(cur
,this))
264 nlwarning("camera not added to scene3d");
268 _Cameras
.push_back(pCam
);
271 else if ( stricmp((char*)cur
->name
,"light") == 0 )
273 CInterface3DLight
*pLig
= new CInterface3DLight
;
274 if (!pLig
->parse(cur
,this))
277 nlwarning("light not added to scene3d");
281 _Lights
.push_back(pLig
);
284 else if ( stricmp((char*)cur
->name
,"fx") == 0 )
286 CInterface3DFX
*pFX
= new CInterface3DFX
;
287 if (!pFX
->parse(cur
,this))
290 nlwarning("fx not added to scene3d");
297 else if ( stricmp((char*)cur
->name
,"auto_anim") == 0 )
299 CXMLAutoPtr
ptr((const char*)xmlGetProp (cur
, (xmlChar
*)"name"));
302 animName
= toLowerAscii(CFile::getFilenameWithoutExtension(ptr
.str()));
304 if (!animName
.empty())
306 if (_AutoAnimSet
== NULL
)
307 _AutoAnimSet
= CViewRenderer::getInstance()->getDriver()->createAnimationSet();
308 uint id
= _AutoAnimSet
->addAnimation (ptr
, animName
.c_str ());
309 if (id
== UAnimationSet::NotFound
)
311 nlwarning ("Can't load automatic animation '%s'", animName
.c_str());
316 nlwarning ("Can't get automatic animation name");
323 // if some auto_anim, found, compile and set auto_anim
324 if (_AutoAnimSet
!= NULL
)
326 _AutoAnimSet
->build ();
327 _Scene
->setAutomaticAnimationSet (_AutoAnimSet
);
330 // If no camera create the default one
331 if (_Cameras
.empty())
333 CInterface3DCamera
*pCam
= new CInterface3DCamera
;
334 _Cameras
.push_back(pCam
);
339 // Initialize all camera distance
340 for (uint i
= 0; i
< _Cameras
.size(); ++i
)
342 CInterface3DCamera
*pCam
= _Cameras
[i
];
343 pCam
->setDist ((pCam
->getPos() - pCam
->getTarget()).norm());
346 // Get the current camera
347 ptr
= (char*) xmlGetProp( cur
, (xmlChar
*)"curcam" );
348 if (ptr
) setCurrentCamera(ptr
.str());
353 // ----------------------------------------------------------------------------
354 void CInterface3DScene::checkCoords()
358 for (i
= 0; i
< _Characters
.size(); ++i
)
359 _Characters
[i
]->checkCoords();
360 for (i
= 0; i
< _IGs
.size(); ++i
)
361 _IGs
[i
]->checkCoords();
362 for (i
= 0; i
< _Cameras
.size(); ++i
)
363 _Cameras
[i
]->checkCoords();
364 for (i
= 0; i
< _Lights
.size(); ++i
)
365 _Lights
[i
]->checkCoords();
366 for (i
= 0; i
< _FXs
.size(); ++i
)
367 _FXs
[i
]->checkCoords();
368 for (i
= 0; i
< _Shapes
.size(); ++i
)
369 _Shapes
[i
]->checkCoords();
372 _Scene
->animate (TimeInSec
-FirstTimeInSec
);
375 // ----------------------------------------------------------------------------
376 void CInterface3DScene::updateCoords ()
378 CViewBase::updateCoords();
381 // ----------------------------------------------------------------------------
382 void CInterface3DScene::draw ()
384 H_AUTO( RZ_Interface_CInterface3DScene_draw
)
386 NL3D::UDriver
*Driver
= CViewRenderer::getInstance()->getDriver();
391 // No Op if screen minimized
392 CInterfaceManager
*pIM
= CInterfaceManager::getInstance();
393 CViewRenderer
&rVR
= *CViewRenderer::getInstance();
394 if(rVR
.isMinimized())
397 CInterface3DScene
*pDisp
= this;
398 // If this is a reference view
399 if (_Ref3DScene
!= NULL
)
402 pDisp
->setFlareContext(1);
406 pDisp
->setFlareContext(0);
409 // This is not a reference view !
410 if (pDisp
->_Scene
== NULL
)
413 CInterface3DCamera
*pI3DCam
= pDisp
->_Cameras
[_CurrentCamera
];
415 // TEMP TEMP TEMP DISPLAY BACKGROUND
416 //rVR.drawRotFlipBitmap (_RenderLayer, _XReal, _YReal, _WReal, _HReal, 0, false,
417 // rVR.getBlankTextureId(), CRGBA(255,255,255,255) );
422 // Viewport and frustrum
425 sint32 oldSciX
, oldSciY
, oldSciW
, oldSciH
;
426 makeNewClip (oldSciX
, oldSciY
, oldSciW
, oldSciH
);
428 // Display sons only if not total clipped
429 if( rVR
.isClipWindowEmpty() )
431 restoreClip (oldSciX
, oldSciY
, oldSciW
, oldSciH
);
435 sint32 clipx
,clipy
,clipw
,cliph
;
436 getClip (clipx
, clipy
, clipw
, cliph
);
438 rVR
.getScreenSize (wsw
, wsh
);
439 NL3D::CViewport oldVP
= Driver
->getViewport();
440 NL3D::CViewport newVP
;
441 float vpX
= (float) (clipx
) / iavoid0(wsw
);
442 float vpY
= (float) (clipy
) / iavoid0(wsh
);
443 float vpW
= (float) clipw
/ iavoid0(wsw
);
444 float vpH
= (float) cliph
/ iavoid0(wsh
);
445 newVP
.init(vpX
, vpY
, vpW
, vpH
);
446 NL3D::CFrustum oldFrustum
= CViewRenderer::getInstance()->getDriver()->getFrustum();
447 NL3D::CFrustum newFrustum
;
448 newFrustum
.initPerspective (pI3DCam
->getFOV() * (float) (NLMISC::Pi
/ 180), (float) _WReal
/ iavoid0(_HReal
), 0.1f
, 100.f
);
450 // Ajust frustum when there's clamping on border of screen
456 // We assume that the viewport has dimensions < to those of the screen
457 if ((_XReal
+_WReal
) > (clipx
+clipw
)) // right clamp ?
459 xRight
= ((clipx
+clipw
) - _XReal
) / (float) _WReal
;
461 else if (_XReal
< clipx
) // left clamp
463 xLeft
= (clipx
- _XReal
) / (float) _WReal
;
465 if ((_YReal
+ _HReal
) > (clipy
+cliph
)) // top clamp ?
467 yTop
= ((clipy
+cliph
) - _YReal
) / (float) _HReal
;
469 else if (_YReal
< clipy
) // bottom clamp
471 yBottom
= (clipy
- _YReal
) / (float) _HReal
;
475 float fWidth
= newFrustum
.Right
- newFrustum
.Left
;
476 float fLeft
= newFrustum
.Left
;
477 newFrustum
.Left
= fLeft
+ fWidth
* xLeft
;
478 newFrustum
.Right
= fLeft
+ fWidth
* xRight
;
479 float fHeight
= newFrustum
.Top
- newFrustum
.Bottom
;
480 float fBottom
= newFrustum
.Bottom
;
481 newFrustum
.Bottom
= fBottom
+ fHeight
* yBottom
;
482 newFrustum
.Top
= fBottom
+ fHeight
* yTop
;
484 pDisp
->_Scene
->setViewport(newVP
);
485 NL3D::UCamera cam
= pDisp
->_Scene
->getCam();
486 cam
.setFrustum(newFrustum
);
488 // Rotate the camera position around the target with the rot parameters
489 CVector pos
= pI3DCam
->getPos() - pI3DCam
->getTarget();
490 // float dist = pos.norm();
494 m
.rotateZ(pI3DCam
->getRotZ());
495 m
.rotateX(pI3DCam
->getRotY());
496 pos
= m
.mulVector(pos
);
497 pos
= pos
* pI3DCam
->getDist();
498 pos
= pos
+ pI3DCam
->getTarget();
499 cam
.lookAt (pos
, pI3DCam
->getTarget(), pI3DCam
->getRoll() * (float) (NLMISC::Pi
/ 180));
504 for (i
= 0; i
< _Characters
.size(); ++i
)
505 _Characters
[i
]->setClusterSystem (_IGs
[_CurrentCS
]->getIG());
506 for (i
= 0; i
< _Shapes
.size(); ++i
)
507 _Shapes
[i
]->getShape().setClusterSystem (_IGs
[_CurrentCS
]->getIG());
508 for (i
= 0; i
< _FXs
.size(); ++i
)
509 if (!_FXs
[i
]->getPS().empty())
510 _FXs
[i
]->getPS().setClusterSystem (_IGs
[_CurrentCS
]->getIG());
511 cam
.setClusterSystem (_IGs
[_CurrentCS
]->getIG());
515 for (i
= 0; i
< _Characters
.size(); ++i
)
516 _Characters
[i
]->setClusterSystem ((UInstanceGroup
*)-1);
517 for (i
= 0; i
< _Shapes
.size(); ++i
)
519 if (!_Shapes
[i
]->getShape().empty())
520 _Shapes
[i
]->getShape().setClusterSystem ((UInstanceGroup
*)-1);
522 for (i
= 0; i
< _FXs
.size(); ++i
)
523 if (!_FXs
[i
]->getPS().empty())
524 _FXs
[i
]->getPS().setClusterSystem ((UInstanceGroup
*)-1);
525 cam
.setClusterSystem ((UInstanceGroup
*)-1);
528 ////////////////////////
529 // Clear the Z-Buffer //
530 ////////////////////////
531 NL3D::CScissor oldScissor
= Driver
->getScissor();
532 NL3D::CScissor newScissor
;
535 newScissor
.Width
= vpW
;
536 newScissor
.Height
= vpH
;
537 Driver
->setScissor(newScissor
);
538 Driver
->clearZBuffer();
539 Driver
->setScissor(oldScissor
);
540 ///////////////////////////////////////////////
542 pDisp
->_Scene
->render();
544 Driver
->setViewport(oldVP
);
545 Driver
->setFrustum(oldFrustum
);
547 // Restore render states
548 CViewRenderer::getInstance()->setRenderStates();
550 restoreClip (oldSciX
, oldSciY
, oldSciW
, oldSciH
);
553 // ----------------------------------------------------------------------------
554 bool CInterface3DScene::handleEvent (const NLGUI::CEventDescriptor
&event
)
556 if (!_UserInteraction
)
561 // if focus is lost then cancel rotation / zoom
562 if (event
.getType() == NLGUI::CEventDescriptor::system
)
564 const NLGUI::CEventDescriptorSystem
&eds
= (const NLGUI::CEventDescriptorSystem
&) event
;
565 if (eds
.getEventTypeExtended() == NLGUI::CEventDescriptorSystem::setfocus
)
567 const NLGUI::CEventDescriptorSetFocus
&edsf
= (const NLGUI::CEventDescriptorSetFocus
&) eds
;
568 if (edsf
.hasFocus() == false)
576 if (event
.getType() == NLGUI::CEventDescriptor::mouse
)
578 const NLGUI::CEventDescriptorMouse
&eventDesc
= (const NLGUI::CEventDescriptorMouse
&)event
;
579 if ((CWidgetManager::getInstance()->getCapturePointerLeft() != this) &&
580 (CWidgetManager::getInstance()->getCapturePointerRight() != this) &&
581 (!((eventDesc
.getX() >= _XReal
) &&
582 (eventDesc
.getX() < (_XReal
+ _WReal
))&&
583 (eventDesc
.getY() > _YReal
) &&
584 (eventDesc
.getY() <= (_YReal
+ _HReal
)))))
587 if (eventDesc
.getEventTypeExtended() == NLGUI::CEventDescriptorMouse::mouseleftdown
)
590 _MouseLDownX
= eventDesc
.getX();
591 _MouseLDownY
= eventDesc
.getY();
592 CInterfaceManager
*pIM
= CInterfaceManager::getInstance();
593 CWidgetManager::getInstance()->setCapturePointerLeft(this); // Because we are not just a control
596 if (eventDesc
.getEventTypeExtended() == NLGUI::CEventDescriptorMouse::mouseleftup
)
601 if (eventDesc
.getEventTypeExtended() == NLGUI::CEventDescriptorMouse::mouserightdown
)
604 _MouseRDownX
= eventDesc
.getX();
605 _MouseRDownY
= eventDesc
.getY();
606 CInterfaceManager
*pIM
= CInterfaceManager::getInstance();
607 CWidgetManager::getInstance()->setCapturePointerRight(this); // Because we are not just a control
610 if (eventDesc
.getEventTypeExtended() == NLGUI::CEventDescriptorMouse::mouserightup
)
615 if (eventDesc
.getEventTypeExtended() == NLGUI::CEventDescriptorMouse::mousemove
)
619 sint32 dx
= eventDesc
.getX() - _MouseLDownX
;
620 sint32 dy
= eventDesc
.getY() - _MouseLDownY
;
622 _MouseLDownX
= eventDesc
.getX();
623 _MouseLDownY
= eventDesc
.getY();
627 sint32 dx
= eventDesc
.getX() - _MouseRDownX
;
628 sint32 dy
= eventDesc
.getY() - _MouseRDownY
;
630 _MouseRDownX
= eventDesc
.getX();
631 _MouseRDownY
= eventDesc
.getY();
639 // ----------------------------------------------------------------------------
640 void CInterface3DScene::mouseLMove (sint32 dx
, sint32 dy
)
642 const CInterface3DScene
*pI3DS
= (_Ref3DScene
!= NULL
) ? _Ref3DScene
: this;
643 CInterface3DCamera
*pI3DCam
= pI3DS
->_Cameras
[_CurrentCamera
];
644 float ang
= pI3DCam
->getRotY() + ((float)dy
)*_RotYFactor
;
645 clamp (ang
, _RotYLimitMin
, _RotYLimitMax
);
646 pI3DCam
->setRotY (ang
);
647 ang
= pI3DCam
->getRotZ() - ((float)dx
)*_RotZFactor
;
648 clamp (ang
,_RotZLimitMin
, _RotZLimitMax
);
649 pI3DCam
->setRotZ (ang
);
652 // ----------------------------------------------------------------------------
653 void CInterface3DScene::mouseRMove (sint32
/* dx */, sint32 dy
)
655 const CInterface3DScene
*pI3DS
= (_Ref3DScene
!= NULL
) ? _Ref3DScene
: this;
656 CInterface3DCamera
*pI3DCam
= pI3DS
->_Cameras
[_CurrentCamera
];
657 float dist
= pI3DCam
->getDist() - ((float)dy
)*_DistFactor
;
658 clamp (dist
, _DistLimitMin
, _DistLimitMax
);
659 pI3DCam
->setDist (dist
);
662 // ----------------------------------------------------------------------------
663 CInterfaceElement
* CInterface3DScene::getElement (const string
&id
)
668 string sTmp
= id
.substr(0, getId().size());
669 //if (sTmp != getId()) return NULL;
673 for (i
= 0; i
< _Characters
.size(); ++i
)
674 if (id
== _Characters
[i
]->getId() || id
== toString("character#%d", i
))
675 return _Characters
[i
];
677 for (i
= 0; i
< _IGs
.size(); ++i
)
678 if (id
== _IGs
[i
]->getId())
681 for (i
= 0; i
< _Shapes
.size(); ++i
) {
682 if (id
== _Shapes
[i
]->getId() || id
== toString("shape#%d", i
))
686 for (i
= 0; i
< _Cameras
.size(); ++i
)
687 if (id
== _Cameras
[i
]->getId() || id
== toString("camera#%d", i
))
690 for (i
= 0; i
< _Lights
.size(); ++i
)
691 if (id
== _Lights
[i
]->getId())
694 for (i
= 0; i
< _FXs
.size(); ++i
)
695 if (id
== _FXs
[i
]->getId())
701 int CInterface3DScene::luaGetElement(CLuaState
&ls
)
703 CLuaIHM::checkArgCount(ls
, "CInterfaceGroup::find", 1);
704 CLuaIHM::checkArgType(ls
, "CInterfaceGroup::find", 1, LUA_TSTRING
);
705 std::string id
= ls
.toString(1);
706 CInterfaceElement
* element
= getElement(id
);
713 CLuaIHM::pushUIOnStack(ls
, element
);
718 // ----------------------------------------------------------------------------
719 string
CInterface3DScene::getCurrentCamera() const
721 const CInterface3DScene
*pI3DS
= (_Ref3DScene
!= NULL
) ? _Ref3DScene
: this;
722 string name
= pI3DS
->_Cameras
[_CurrentCamera
]->getId();
723 name
= name
.substr(name
.rfind(':'));
727 // ----------------------------------------------------------------------------
728 void CInterface3DScene::setCurrentCamera (const string
&name
)
730 CInterfaceManager
*pIM
= CInterfaceManager::getInstance();
731 CInterface3DScene
*pI3DS
= (_Ref3DScene
!= NULL
) ? _Ref3DScene
: this;
732 CInterfaceElement
*pIE
= CWidgetManager::getInstance()->getElementFromId(pI3DS
->getId(), name
);
733 CInterface3DCamera
*pI3DCam
= dynamic_cast<CInterface3DCamera
*>(pIE
);
737 for (i
= 0; i
< pI3DS
->_Cameras
.size(); ++i
)
738 if (pI3DS
->_Cameras
[i
] == pI3DCam
)
740 if (i
!= pI3DS
->_Cameras
.size())
745 // ----------------------------------------------------------------------------
746 string
CInterface3DScene::getCurrentClusterSystem () const
748 const CInterface3DScene
*pI3DS
= (_Ref3DScene
!= NULL
) ? _Ref3DScene
: this;
749 string name
= pI3DS
->_IGs
[_CurrentCS
]->getId();
750 name
= name
.substr(name
.rfind(':'));
754 // ----------------------------------------------------------------------------
755 void CInterface3DScene::setCurrentClusterSystem(const string
&sCSName
)
757 CInterfaceManager
*pIM
= CInterfaceManager::getInstance();
758 CInterface3DScene
*pI3DS
= (_Ref3DScene
!= NULL
) ? _Ref3DScene
: this;
759 CInterfaceElement
*pIE
= CWidgetManager::getInstance()->getElementFromId(pI3DS
->getId(), sCSName
);
760 CInterface3DIG
*pI3DIG
= dynamic_cast<CInterface3DIG
*>(pIE
);
764 for (i
= 0; i
< pI3DS
->_IGs
.size(); ++i
)
765 if (pI3DS
->_IGs
[i
] == pI3DIG
)
767 if (i
!= pI3DS
->_IGs
.size())
772 // ----------------------------------------------------------------------------
773 void CInterface3DScene::remove(NL3D::UInstanceGroup
*pIG
)
776 for (i
= 0; i
< _Characters
.size(); ++i
)
777 _Characters
[i
]->setClusterSystem ((UInstanceGroup
*)NULL
);
778 for (i
= 0; i
< _Shapes
.size(); ++i
)
779 _Shapes
[i
]->getShape().setClusterSystem ((UInstanceGroup
*)NULL
);
780 for (i
= 0; i
< _FXs
.size(); ++i
)
781 if (!_FXs
[i
]->getPS().empty())
782 _FXs
[i
]->getPS().setClusterSystem ((UInstanceGroup
*)NULL
);
784 CInterface3DScene
*pDisp
= this;
785 if (_Ref3DScene
!= NULL
)
787 if (pDisp
->_Scene
== NULL
)
789 NL3D::UCamera cam
= pDisp
->_Scene
->getCam();
790 cam
.setClusterSystem ((UInstanceGroup
*)NULL
);
792 pIG
->removeFromScene(*_Scene
);
793 _Scene
->deleteInstanceGroup(pIG
);
796 // ----------------------------------------------------------------------------
797 // CInterface3DCharacter
798 // ----------------------------------------------------------------------------
800 // ----------------------------------------------------------------------------
801 CInterface3DCharacter::CInterface3DCharacter()
806 // ----------------------------------------------------------------------------
807 CInterface3DCharacter::~CInterface3DCharacter()
812 // ----------------------------------------------------------------------------
813 bool CInterface3DCharacter::parse (xmlNodePtr cur
, CInterfaceGroup
*parentGroup
)
815 if (!CInterfaceElement::parse(cur
, parentGroup
))
818 CXMLAutoPtr
ptr((const char*)xmlGetProp (cur
, (xmlChar
*)"dblink"));
820 if (ptr
) _DBLink
= (const char *)ptr
;
822 CVector
pos(0,0,0), rot(0,0,0);
823 ptr
= xmlGetProp (cur
, (xmlChar
*)"pos");
824 if (ptr
) pos
= convertVector(ptr
);
826 ptr
= xmlGetProp (cur
, (xmlChar
*)"rot");
827 if (ptr
) rot
= convertVector(ptr
);
829 bool copyAnim
= false;
830 ptr
= xmlGetProp (cur
, (xmlChar
*)"copy_anim");
831 if (ptr
) copyAnim
= convertBool(ptr
);
833 _Char3D
= new CCharacter3D
;
834 _Char3D
->copyAnimation(copyAnim
);
835 _Char3D
->init (dynamic_cast<CInterface3DScene
*>(parentGroup
)->getScene());
836 _Char3D
->setPos (pos
.x
, pos
.y
, pos
.z
);
837 _Char3D
->setRotEuler ( rot
.x
* ((float)(NLMISC::Pi
/ 180)),
838 rot
.y
* ((float)(NLMISC::Pi
/ 180)),
839 rot
.z
* ((float)(NLMISC::Pi
/ 180)) );
845 // ----------------------------------------------------------------------------
846 void CInterface3DCharacter::checkCoords()
850 SCharacter3DSetup c3Ds
= _Char3D
->getCurrentSetup();
851 if ((_DBLink
.empty()) || (_DBLink
== "player"))
852 c3Ds
.setupFromSERVERDataBase();
853 else if (_DBLink
== "target")
855 if (UserEntity
!= NULL
)
857 CEntityCL
*selection
= EntitiesMngr
.entity(UserEntity
->selection());
858 if (selection
!= NULL
)
859 c3Ds
.setupFromSERVERDataBase(selection
->slot());
863 c3Ds
.setupFromDataBase (_DBLink
);
864 _Char3D
->setup (c3Ds
);
865 _Char3D
->animate (TimeInSec
);
869 // ----------------------------------------------------------------------------
870 void CInterface3DCharacter::setupCharacter3D(sint32 slot
)
872 SCharacter3DSetup c3Ds
= _Char3D
->getCurrentSetup();
873 c3Ds
.setupFromSERVERDataBase((uint8
)slot
);
874 _Char3D
->setup(c3Ds
);
877 // ----------------------------------------------------------------------------
878 int CInterface3DCharacter::luaSetupCharacter3D(CLuaState
&ls
)
880 const char *funcName
= "setupCharacter3D";
881 CLuaIHM::checkArgCount(ls
, funcName
, 1);
882 CLuaIHM::checkArgType(ls
, funcName
, 1, LUA_TNUMBER
);
883 setupCharacter3D((sint32
) ls
.toInteger(1));
887 // ----------------------------------------------------------------------------
888 int CInterface3DCharacter::luaEnableLOD(CLuaState
&ls
)
890 const char *funcName
= "enableLOD";
891 CLuaIHM::checkArgCount(ls
, funcName
, 1);
892 CLuaIHM::checkArgType(ls
, funcName
, 1, LUA_TBOOLEAN
);
893 if (!_Char3D
->getSkeleton().empty())
895 _Char3D
->getSkeleton().enableLOD(ls
.toBoolean(1));
900 // ----------------------------------------------------------------------------
901 void CInterface3DCharacter::setClusterSystem (UInstanceGroup
*pIG
)
904 _Char3D
->setClusterSystem (pIG
);
907 // ----------------------------------------------------------------------------
908 float CInterface3DCharacter::getPosX () const
910 if (_Char3D
== NULL
) return 0.0;
912 _Char3D
->getPos (x
, y
, z
);
916 // ----------------------------------------------------------------------------
917 float CInterface3DCharacter::getPosY () const
919 if (_Char3D
== NULL
) return 0.0;
921 _Char3D
->getPos (x
, y
, z
);
925 // ----------------------------------------------------------------------------
926 float CInterface3DCharacter::getPosZ () const
928 if (_Char3D
== NULL
) return 0.0;
930 _Char3D
->getPos (x
, y
, z
);
934 // ----------------------------------------------------------------------------
935 void CInterface3DCharacter::setPosX (float f
)
937 if (_Char3D
== NULL
) return;
939 _Char3D
->getPos(x
, y
, z
);
941 _Char3D
->setPos(x
, y
, z
);
944 // ----------------------------------------------------------------------------
945 void CInterface3DCharacter::setPosY (float f
)
947 if (_Char3D
== NULL
) return;
949 _Char3D
->getPos(x
, y
, z
);
951 _Char3D
->setPos(x
, y
, z
);
954 // ----------------------------------------------------------------------------
955 void CInterface3DCharacter::setPosZ (float f
)
957 if (_Char3D
== NULL
) return;
959 _Char3D
->getPos(x
, y
, z
);
961 _Char3D
->setPos(x
, y
, z
);
964 // ----------------------------------------------------------------------------
965 float CInterface3DCharacter::getRotX () const
967 if (_Char3D
== NULL
) return 0.0;
969 _Char3D
->getRotEuler(x
, y
, z
);
970 return x
/ ((float)(NLMISC::Pi
/ 180));
973 // ----------------------------------------------------------------------------
974 float CInterface3DCharacter::getRotY () const
976 if (_Char3D
== NULL
) return 0.0;
978 _Char3D
->getRotEuler(x
, y
, z
);
979 return y
/ ((float)(NLMISC::Pi
/ 180));
982 // ----------------------------------------------------------------------------
983 float CInterface3DCharacter::getRotZ () const
985 if (_Char3D
== NULL
) return 0.0;
987 _Char3D
->getRotEuler(x
, y
, z
);
988 return z
/ ((float)(NLMISC::Pi
/ 180));
991 // ----------------------------------------------------------------------------
992 void CInterface3DCharacter::setRotX (float f
)
994 if (_Char3D
== NULL
) return;
996 _Char3D
->getRotEuler(x
, y
, z
);
997 x
= f
* ((float)(NLMISC::Pi
/ 180));
998 _Char3D
->setRotEuler(x
, y
, z
);
1001 // ----------------------------------------------------------------------------
1002 void CInterface3DCharacter::setRotY (float f
)
1004 if (_Char3D
== NULL
) return;
1006 _Char3D
->getRotEuler(x
, y
, z
);
1007 y
= f
* ((float)(NLMISC::Pi
/ 180));
1008 _Char3D
->setRotEuler(x
, y
, z
);
1011 // ----------------------------------------------------------------------------
1012 void CInterface3DCharacter::setRotZ (float f
)
1014 if (_Char3D
== NULL
) return;
1016 _Char3D
->getRotEuler(x
, y
, z
);
1017 z
= f
* ((float)(NLMISC::Pi
/ 180));
1018 _Char3D
->setRotEuler(x
, y
, z
);
1021 // ----------------------------------------------------------------------------
1022 float CInterface3DCharacter::getHeadX () const
1024 if (_Char3D
== NULL
) return 0.0;
1026 _Char3D
->getHeadPos (x
, y
, z
);
1030 // ----------------------------------------------------------------------------
1031 float CInterface3DCharacter::getHeadY () const
1033 if (_Char3D
== NULL
) return 0.0;
1035 _Char3D
->getHeadPos (x
, y
, z
);
1039 // ----------------------------------------------------------------------------
1040 float CInterface3DCharacter::getHeadZ () const
1042 if (_Char3D
== NULL
) return 0.0;
1044 _Char3D
->getHeadPos (x
, y
, z
);
1048 // ----------------------------------------------------------------------------
1049 void CInterface3DCharacter::setAnim (sint32 anim
)
1052 _Char3D
->setAnim(anim
);
1057 // ----------------------------------------------------------------------------
1058 void CInterface3DCharacter::setPeople(const std::string
& people
)
1060 _Char3D
->setPeople(EGSPD::CPeople::fromString(people
));
1063 // ----------------------------------------------------------------------------
1064 std::string
CInterface3DCharacter::getPeople() const
1066 return EGSPD::CPeople::toString(_Char3D
->getPeople());
1069 // ----------------------------------------------------------------------------
1070 void CInterface3DCharacter::setSex(bool male
)
1072 _Char3D
->setSex(male
);
1075 // ----------------------------------------------------------------------------
1076 bool CInterface3DCharacter::getSex() const
1078 return _Char3D
->getSex();
1082 // ----------------------------------------------------------------------------
1084 // ----------------------------------------------------------------------------
1086 // ----------------------------------------------------------------------------
1087 CInterface3DIG::~CInterface3DIG()
1089 CInterface3DScene
*pI3DS
= dynamic_cast<CInterface3DScene
*>(_Parent
);
1090 nlassert(pI3DS
!= NULL
);
1093 _IG
->removeFromScene(*pI3DS
->getScene());
1094 pI3DS
->getScene()->deleteInstanceGroup(_IG
);
1099 // ----------------------------------------------------------------------------
1100 bool CInterface3DIG::parse (xmlNodePtr cur
, CInterfaceGroup
*parentGroup
)
1102 if (!CInterfaceElement::parse(cur
, parentGroup
))
1105 CXMLAutoPtr
ptr((const char*)xmlGetProp (cur
, (xmlChar
*)"pos"));
1106 if (ptr
) _Pos
= convertVector(ptr
);
1108 ptr
= xmlGetProp (cur
, (xmlChar
*)"rot");
1109 if (ptr
) _Rot
= convertVector(ptr
);
1111 ptr
= xmlGetProp (cur
, (xmlChar
*)"name");
1112 if (ptr
) _Name
= toLowerAscii((const char*)ptr
);
1114 _IG
= UInstanceGroup::createInstanceGroup(_Name
);
1116 return true; // Create anyway
1118 //_IG->setRot (_Rot);
1122 _IG
->addToScene (*dynamic_cast<CInterface3DScene
*>(parentGroup
)->getScene(), CViewRenderer::getInstance()->getDriver() );
1123 dynamic_cast<CInterface3DScene
*>(parentGroup
)->getScene()->setToGlobalInstanceGroup (_IG
);
1128 // ----------------------------------------------------------------------------
1129 float CInterface3DIG::getPosX () const
1134 // ----------------------------------------------------------------------------
1135 float CInterface3DIG::getPosY () const
1140 // ----------------------------------------------------------------------------
1141 float CInterface3DIG::getPosZ () const
1146 // ----------------------------------------------------------------------------
1147 void CInterface3DIG::setPosX (float f
)
1150 if (_IG
!= NULL
) _IG
->setPos(_Pos
);
1153 // ----------------------------------------------------------------------------
1154 void CInterface3DIG::setPosY (float f
)
1157 if (_IG
!= NULL
) _IG
->setPos(_Pos
);
1160 // ----------------------------------------------------------------------------
1161 void CInterface3DIG::setPosZ (float f
)
1164 if (_IG
!= NULL
) _IG
->setPos(_Pos
);
1167 // ----------------------------------------------------------------------------
1168 float CInterface3DIG::getRotX () const
1173 // ----------------------------------------------------------------------------
1174 float CInterface3DIG::getRotY () const
1179 // ----------------------------------------------------------------------------
1180 float CInterface3DIG::getRotZ () const
1185 // ----------------------------------------------------------------------------
1186 void CInterface3DIG::setRotX (float f
)
1191 m
.setRot (_Rot
,CMatrix::XYZ
);
1192 CQuat q
= m
.getRot();
1193 _IG
->setRotQuat (q
);
1196 // ----------------------------------------------------------------------------
1197 void CInterface3DIG::setRotY (float f
)
1202 m
.setRot (_Rot
,CMatrix::XYZ
);
1203 CQuat q
= m
.getRot();
1204 _IG
->setRotQuat (q
);
1207 // ----------------------------------------------------------------------------
1208 void CInterface3DIG::setRotZ (float f
)
1213 m
.setRot (_Rot
,CMatrix::XYZ
);
1214 CQuat q
= m
.getRot();
1215 _IG
->setRotQuat (q
);
1218 // ----------------------------------------------------------------------------
1219 std::string
CInterface3DIG::getName() const
1224 // ----------------------------------------------------------------------------
1225 void CInterface3DIG::setName (const std::string
&ht
)
1227 string lwrname
= toLowerAscii(ht
);
1228 if (lwrname
!= _Name
)
1230 CInterface3DScene
*pI3DS
= dynamic_cast<CInterface3DScene
*>(_Parent
);
1231 nlassert(pI3DS
!= NULL
);
1240 _IG
= UInstanceGroup::createInstanceGroup(_Name
);
1241 if (_IG
== NULL
) return;
1243 _IG
->addToScene (*pI3DS
->getScene(), CViewRenderer::getInstance()->getDriver() );
1244 pI3DS
->getScene()->setToGlobalInstanceGroup (_IG
);
1248 // ----------------------------------------------------------------------------
1249 // CInterface3DShape
1250 // ----------------------------------------------------------------------------
1252 // ----------------------------------------------------------------------------
1253 CInterface3DShape::~CInterface3DShape()
1255 CInterface3DScene
*pI3DS
= dynamic_cast<CInterface3DScene
*>(_Parent
);
1256 nlassert(pI3DS
!= NULL
);
1257 if (!_Instance
.empty())
1258 pI3DS
->getScene()->deleteInstance(_Instance
);
1259 if (!_Skeleton
.empty())
1260 pI3DS
->getScene()->deleteSkeleton(_Skeleton
);
1261 if (_PlayListManager
)
1263 _PlayListManager
->deletePlayList(_PlayList
);
1265 CViewRenderer::getInstance()->getDriver()->deleteAnimationSet(_AnimationSet
);
1266 _AnimationSet
= NULL
;
1267 pI3DS
->getScene()->deletePlayListManager(_PlayListManager
);
1268 _PlayListManager
= NULL
;
1272 // ----------------------------------------------------------------------------
1273 bool CInterface3DShape::parse (xmlNodePtr cur
, CInterfaceGroup
*parentGroup
)
1275 if (!CInterfaceElement::parse(cur
, parentGroup
))
1278 CXMLAutoPtr
ptr((const char*)xmlGetProp (cur
, (xmlChar
*)"pos"));
1279 if (ptr
) _Pos
= convertVector(ptr
);
1281 ptr
= xmlGetProp (cur
, (xmlChar
*)"rot");
1282 if (ptr
) _Rot
= convertVector(ptr
);
1284 ptr
= xmlGetProp (cur
, (xmlChar
*)"name");
1285 if (ptr
) _Name
= toLowerAscii((const char*)ptr
);
1287 _Instance
= dynamic_cast<CInterface3DScene
*>(parentGroup
)->getScene()->createInstance(_Name
);
1288 if (_Instance
.empty())
1291 _Instance
.setTransformMode(UTransformable::RotEuler
);
1292 _Instance
.setPos (_Pos
);
1293 _Instance
.setRotEuler (_Rot
.x
, _Rot
.y
, _Rot
.z
);
1299 // ----------------------------------------------------------------------------
1300 void CInterface3DShape::checkCoords()
1302 if (_PlayListManager
)
1303 _PlayListManager
->animate(TimeInSec
);
1307 float CInterface3DShape::getBBoxSizeX () const
1310 _Instance
.getShapeAABBox(bbox
);
1312 if (bbox
.getCenter() == CVector::Null
)
1315 return bbox
.getMax().x
- bbox
.getMin().x
;
1318 float CInterface3DShape::getBBoxSizeY () const
1321 _Instance
.getShapeAABBox(bbox
);
1323 if (bbox
.getCenter() == CVector::Null
)
1326 return bbox
.getMax().y
- bbox
.getMin().y
;
1329 float CInterface3DShape::getBBoxSizeZ () const
1332 _Instance
.getShapeAABBox(bbox
);
1334 if (bbox
.getCenter() == CVector::Null
)
1337 return bbox
.getMax().z
- bbox
.getMin().z
;
1340 // ----------------------------------------------------------------------------
1341 float CInterface3DShape::getPosX () const
1346 // ----------------------------------------------------------------------------
1347 float CInterface3DShape::getPosY () const
1352 // ----------------------------------------------------------------------------
1353 float CInterface3DShape::getPosZ () const
1358 // ----------------------------------------------------------------------------
1359 void CInterface3DShape::setPosX (float f
)
1362 if (!_Instance
.empty()) _Instance
.setPos(_Pos
);
1365 // ----------------------------------------------------------------------------
1366 void CInterface3DShape::setPosY (float f
)
1369 if (!_Instance
.empty()) _Instance
.setPos(_Pos
);
1372 // ----------------------------------------------------------------------------
1373 void CInterface3DShape::setPosZ (float f
)
1376 if (!_Skeleton
.empty()) _Skeleton
.setPos(_Pos
);
1377 if (!_Instance
.empty()) _Instance
.setPos(_Pos
);
1380 // ----------------------------------------------------------------------------
1381 float CInterface3DShape::getRotX () const
1383 return _Rot
.x
/ ((float)(NLMISC::Pi
/ 180));
1386 // ----------------------------------------------------------------------------
1387 float CInterface3DShape::getRotY () const
1389 return _Rot
.y
/ ((float)(NLMISC::Pi
/ 180));
1392 // ----------------------------------------------------------------------------
1393 float CInterface3DShape::getRotZ () const
1395 return _Rot
.z
/ ((float)(NLMISC::Pi
/ 180));
1398 // ----------------------------------------------------------------------------
1399 void CInterface3DShape::setRotX (float f
)
1401 _Rot
.x
= f
* ((float)(NLMISC::Pi
/ 180));
1402 if (!_Instance
.empty()) _Instance
.setRotEuler (_Rot
.x
, _Rot
.y
, _Rot
.z
);
1405 // ----------------------------------------------------------------------------
1406 void CInterface3DShape::setRotY (float f
)
1408 _Rot
.y
= f
* ((float)(NLMISC::Pi
/ 180));
1409 if (!_Instance
.empty()) _Instance
.setRotEuler (_Rot
.x
, _Rot
.y
, _Rot
.z
);
1412 // ----------------------------------------------------------------------------
1413 void CInterface3DShape::setRotZ (float f
)
1415 _Rot
.z
= f
* ((float)(NLMISC::Pi
/ 180));
1416 if (!_Instance
.empty()) _Instance
.setRotEuler (_Rot
.x
, _Rot
.y
, _Rot
.z
);
1419 // ----------------------------------------------------------------------------
1420 std::string
CInterface3DShape::getName() const
1425 // ----------------------------------------------------------------------------
1426 void CInterface3DShape::setName (const std::string
&ht
)
1430 CInterface3DScene
*pI3DS
= dynamic_cast<CInterface3DScene
*>(_Parent
);
1431 nlassert(pI3DS
!= NULL
);
1433 if (!_Instance
.empty())
1435 pI3DS
->getScene()->deleteInstance(_Instance
);
1441 string lwrname
= toLowerAscii(ht
);
1442 if (lwrname
!= _Name
)
1444 CInterface3DScene
*pI3DS
= dynamic_cast<CInterface3DScene
*>(_Parent
);
1445 nlassert(pI3DS
!= NULL
);
1447 if (!_Instance
.empty())
1449 pI3DS
->getScene()->deleteInstance(_Instance
);
1453 _Instance
= pI3DS
->getScene()->createInstance(_Name
);
1454 if (_Instance
.empty()) return;
1455 _Instance
.setTransformMode(UTransformable::RotEuler
);
1456 _Instance
.setPos (_Pos
);
1457 _Instance
.setRotEuler (_Rot
.x
, _Rot
.y
, _Rot
.z
);
1461 std::string
CInterface3DShape::getTextures() const
1467 void CInterface3DShape::setTextures(const std::string
&textures
)
1469 if (textures
.empty())
1472 _Textures
= textures
;
1473 vector
<string
> texList
;
1474 splitString(textures
, " ", texList
);
1476 for(uint j
=0;j
<_Instance
.getNumMaterials();j
++)
1478 sint numStages
= _Instance
.getMaterial(j
).getLastTextureStage() + 1;
1479 for(sint l
= 0; l
< numStages
; l
++)
1481 if (_Instance
.getMaterial(j
).isTextureFile((uint
) l
))
1483 _Instance
.getMaterial(j
).setTextureFileName(texList
[std::min((int)j
, (int)texList
.size()-1)], (uint
) l
);
1489 std::string
CInterface3DShape::getSkeleton() const
1491 return _SkeletonName
;
1495 void CInterface3DShape::setSkeleton(const std::string
&skeleton
)
1497 if (skeleton
.empty())
1499 _SkeletonName
= skeleton
;
1501 CInterface3DScene
*pI3DS
= dynamic_cast<CInterface3DScene
*>(_Parent
);
1502 nlassert(pI3DS
!= NULL
);
1504 if (!_Skeleton
.empty())
1505 pI3DS
->getScene()->deleteSkeleton(_Skeleton
);
1507 _Skeleton
= pI3DS
->getScene()->createSkeleton(skeleton
);
1508 if (!_Skeleton
.empty())
1510 _Skeleton
.bindSkin(_Instance
);
1511 // _Skeleton.setTransformMode(UTransformable::RotEuler);
1512 // _Skeleton.setPos(_Pos);
1513 // _Skeleton.setRotEuler(_Rot.x, _Rot.y, _Rot.z);
1517 std::string
CInterface3DShape::getAnim() const
1523 void CInterface3DShape::setAnim(const std::string
&anim
)
1525 CInterface3DScene
*pI3DS
= dynamic_cast<CInterface3DScene
*>(_Parent
);
1526 nlassert(pI3DS
!= NULL
);
1528 if (!_PlayListManager
)
1529 _PlayListManager
= pI3DS
->getScene()->createPlayListManager();
1531 _AnimationSet
= CViewRenderer::getInstance()->getDriver()->createAnimationSet();
1536 idAnim
= _AnimationSet
->addAnimation( (anim
+".anim").c_str(), anim
.c_str() );
1540 nlwarning( "CInterface3DShape::setAnim Animation %s not found", anim
.c_str() );
1544 _AnimationSet
->build();
1545 _PlayList
= _PlayListManager
->createPlayList( _AnimationSet
);
1547 if (!_Skeleton
.empty())
1548 _PlayList
->registerTransform( _Skeleton
);
1550 _PlayList
->registerTransform( _Instance
);
1552 _PlayList
->setAnimation(0, idAnim
);
1553 _PlayList
->setTimeOrigin(0, 0 );
1554 _PlayList
->setSpeedFactor( 0, 1 );
1555 _PlayListManager
->animate( 0 );
1561 // ----------------------------------------------------------------------------
1562 // CInterface3DCamera
1563 // ----------------------------------------------------------------------------
1565 // ----------------------------------------------------------------------------
1566 bool CInterface3DCamera::parse (xmlNodePtr cur
, CInterfaceGroup
*parentGroup
)
1568 if (!CInterfaceElement::parse(cur
, parentGroup
))
1571 CXMLAutoPtr
ptr((const char*)xmlGetProp (cur
, (xmlChar
*)"pos"));
1572 if (ptr
) _Pos
= convertVector(ptr
);
1573 ptr
= xmlGetProp (cur
, (xmlChar
*)"target");
1574 if (ptr
) _Target
= convertVector(ptr
);
1575 ptr
= xmlGetProp (cur
, (xmlChar
*)"fov");
1576 if (ptr
) fromString((const char*)ptr
, _FOV
);
1577 ptr
= xmlGetProp (cur
, (xmlChar
*)"roll");
1578 if (ptr
) fromString((const char*)ptr
, _Roll
);
1583 // ----------------------------------------------------------------------------
1584 void CInterface3DCamera::reset()
1587 _Rot
= NLMISC::CVector(0,0,0);
1590 // ----------------------------------------------------------------------------
1591 // CInterface3DLight
1592 // ----------------------------------------------------------------------------
1594 // ----------------------------------------------------------------------------
1595 CInterface3DLight::~CInterface3DLight()
1597 CInterface3DScene
*pI3DS
= dynamic_cast<CInterface3DScene
*>(_Parent
);
1598 nlassert(pI3DS
!= NULL
);
1599 pI3DS
->getScene()->deletePointLight(_Light
);
1602 // ----------------------------------------------------------------------------
1603 bool CInterface3DLight::parse (xmlNodePtr cur
, CInterfaceGroup
*parentGroup
)
1605 if (!CInterfaceElement::parse(cur
, parentGroup
))
1608 _Light
= dynamic_cast<CInterface3DScene
*>(parentGroup
)->getScene()->createPointLight();
1610 CXMLAutoPtr
ptr((const char*)xmlGetProp (cur
, (xmlChar
*)"pos"));
1611 if (ptr
) _Pos
= convertVector(ptr
);
1612 ptr
= xmlGetProp (cur
, (xmlChar
*)"color");
1613 if (ptr
) _Color
= convertColor(ptr
);
1614 ptr
= xmlGetProp (cur
, (xmlChar
*)"near");
1615 if (ptr
) fromString((const char*)ptr
, _Near
);
1616 ptr
= xmlGetProp (cur
, (xmlChar
*)"far");
1617 if (ptr
) fromString((const char*)ptr
, _Far
);
1619 _Light
.setPos(_Pos
);
1620 _Light
.setAmbient (CRGBA(0,0,0));
1621 _Light
.setDiffuse (CRGBA(255,255,255));
1622 _Light
.setSpecular (CRGBA(255,255,255));
1623 _Light
.setColor (_Color
);
1624 _Light
.setupAttenuation (_Near
, _Far
);
1629 // ----------------------------------------------------------------------------
1630 void CInterface3DLight::setPosX(float f
)
1633 _Light
.setPos(_Pos
);
1636 // ----------------------------------------------------------------------------
1637 void CInterface3DLight::setPosY(float f
)
1640 _Light
.setPos(_Pos
);
1643 // ----------------------------------------------------------------------------
1644 void CInterface3DLight::setPosZ(float f
)
1647 _Light
.setPos(_Pos
);
1650 // ----------------------------------------------------------------------------
1651 void CInterface3DLight::setNear(float f
)
1654 _Light
.setupAttenuation (_Near
, _Far
);
1657 // ----------------------------------------------------------------------------
1658 void CInterface3DLight::setFar(float f
)
1661 _Light
.setupAttenuation (_Near
, _Far
);
1664 // ----------------------------------------------------------------------------
1665 void CInterface3DLight::setColR(sint32 f
)
1667 _Color
.R
= (uint8
)f
;
1668 _Light
.setColor (_Color
);
1671 // ----------------------------------------------------------------------------
1672 void CInterface3DLight::setColG(sint32 f
)
1674 _Color
.G
= (uint8
)f
;
1675 _Light
.setColor (_Color
);
1678 // ----------------------------------------------------------------------------
1679 void CInterface3DLight::setColB(sint32 f
)
1681 _Color
.B
= (uint8
)f
;
1682 _Light
.setColor (_Color
);
1685 // ----------------------------------------------------------------------------
1687 // ----------------------------------------------------------------------------
1689 // ----------------------------------------------------------------------------
1690 CInterface3DFX::~CInterface3DFX()
1694 // ----------------------------------------------------------------------------
1695 bool CInterface3DFX::parse (xmlNodePtr cur
, CInterfaceGroup
*parentGroup
)
1697 if (!CInterfaceElement::parse(cur
, parentGroup
))
1700 CXMLAutoPtr
ptr((const char*)xmlGetProp (cur
, (xmlChar
*)"pos"));
1701 if (ptr
) _Pos
= convertVector(ptr
);
1703 ptr
= xmlGetProp (cur
, (xmlChar
*)"rot");
1704 if (ptr
) _Rot
= convertVector(ptr
);
1706 ptr
= xmlGetProp (cur
, (xmlChar
*)"name");
1707 if (ptr
) _Name
= toLowerAscii((const char*)ptr
);
1712 // ----------------------------------------------------------------------------
1713 void CInterface3DFX::checkCoords()
1719 CInterface3DScene
*pI3DS
= dynamic_cast<CInterface3DScene
*>(_Parent
);
1720 nlassert(pI3DS
!= NULL
);
1721 pI3DS
->getScene()->deleteInstance(_FX
);
1726 // ----------------------------------------------------------------------------
1727 float CInterface3DFX::getPosX () const
1732 // ----------------------------------------------------------------------------
1733 float CInterface3DFX::getPosY () const
1738 // ----------------------------------------------------------------------------
1739 float CInterface3DFX::getPosZ () const
1744 // ----------------------------------------------------------------------------
1745 void CInterface3DFX::setPosX (float f
)
1748 if (!_FX
.empty()) _FX
.setPos (_Pos
);
1751 // ----------------------------------------------------------------------------
1752 void CInterface3DFX::setPosY (float f
)
1755 if (!_FX
.empty()) _FX
.setPos (_Pos
);
1758 // ----------------------------------------------------------------------------
1759 void CInterface3DFX::setPosZ (float f
)
1762 if (!_FX
.empty()) _FX
.setPos (_Pos
);
1765 // ----------------------------------------------------------------------------
1766 float CInterface3DFX::getRotX () const
1768 return _Rot
.x
/ ((float)(NLMISC::Pi
/ 180));
1771 // ----------------------------------------------------------------------------
1772 float CInterface3DFX::getRotY () const
1774 return _Rot
.y
/ ((float)(NLMISC::Pi
/ 180));
1777 // ----------------------------------------------------------------------------
1778 float CInterface3DFX::getRotZ () const
1780 return _Rot
.z
/ ((float)(NLMISC::Pi
/ 180));
1783 // ----------------------------------------------------------------------------
1784 void CInterface3DFX::setRotX (float f
)
1787 if (!_FX
.empty()) _FX
.setRotEuler(_Rot
);
1790 // ----------------------------------------------------------------------------
1791 void CInterface3DFX::setRotY (float f
)
1794 if (!_FX
.empty()) _FX
.setRotEuler(_Rot
);
1797 // ----------------------------------------------------------------------------
1798 void CInterface3DFX::setRotZ (float f
)
1801 if (!_FX
.empty()) _FX
.setRotEuler(_Rot
);
1804 // ----------------------------------------------------------------------------
1805 std::string
CInterface3DFX::getName() const
1810 // ----------------------------------------------------------------------------
1811 void CInterface3DFX::setName (const std::string
&ht
)
1818 // ----------------------------------------------------------------------------
1819 bool CInterface3DFX::getStarted() const
1821 return (!_FX
.empty());
1824 // ----------------------------------------------------------------------------
1825 void CInterface3DFX::setStarted (bool b
)
1829 CInterface3DScene
*pI3DS
= dynamic_cast<CInterface3DScene
*>(_Parent
);
1830 nlassert(pI3DS
!= NULL
);
1832 pI3DS
->getScene()->deleteInstance(_FX
);
1833 _FX
.cast (pI3DS
->getScene()->createInstance(_Name
));
1836 _FX
.setTransformMode(UTransformable::RotEuler
);
1838 _FX
.setRotEuler (_Rot
.x
, _Rot
.y
, _Rot
.z
);
1842 CInterface3DScene
*pI3DS
= dynamic_cast<CInterface3DScene
*>(_Parent
);
1843 nlassert(pI3DS
!= NULL
);
1845 pI3DS
->getScene()->deleteInstance(_FX
);
1853 /* end of interface_3d_scene.cpp */