|
|
|
@ -43,6 +43,7 @@
|
|
|
|
|
#include "interface_v3/people_interraction.h"
|
|
|
|
|
#include "interface_v3/bar_manager.h"
|
|
|
|
|
#include "interface_v3/group_compas.h"
|
|
|
|
|
#include "misc.h"
|
|
|
|
|
// 3D
|
|
|
|
|
#include "nel/3d/quad_tree.h"
|
|
|
|
|
// Interface 3D
|
|
|
|
@ -65,11 +66,13 @@
|
|
|
|
|
#include "player_r2_cl.h"
|
|
|
|
|
#include "r2/editor.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///////////
|
|
|
|
|
// USING //
|
|
|
|
|
///////////
|
|
|
|
|
using namespace NLMISC;
|
|
|
|
|
using namespace NL3D;
|
|
|
|
|
using namespace NLPACS;
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -400,6 +403,7 @@ CEntityManager::CEntityManager()
|
|
|
|
|
_NbPlayer = 0;
|
|
|
|
|
_NbChar = 0;
|
|
|
|
|
_LastEntityUnderPos= NULL;
|
|
|
|
|
_LastRemovedInstance = -1;
|
|
|
|
|
}// CEntityManager //
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------
|
|
|
|
@ -522,22 +526,179 @@ void CEntityManager::reinit()
|
|
|
|
|
initialize(_NbMaxEntity);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CShapeInstanceReference CEntityManager::createInstance(const string& shape, const CVector &pos, const string& text, const string& url, bool bbox_active)
|
|
|
|
|
CShapeInstanceReference CEntityManager::createInstance(const string& shape, const CVector &pos, const string& text, const string& url, bool haveCollisions, sint32& idx)
|
|
|
|
|
{
|
|
|
|
|
idx = -1;
|
|
|
|
|
CShapeInstanceReference nullinstref(UInstance(), string(""), string(""));
|
|
|
|
|
if (!Scene) return nullinstref;
|
|
|
|
|
|
|
|
|
|
UInstance instance = Scene->createInstance(shape);
|
|
|
|
|
if (text.empty())
|
|
|
|
|
bbox_active = false;
|
|
|
|
|
CShapeInstanceReference instref = CShapeInstanceReference(instance, text, url, bbox_active);
|
|
|
|
|
|
|
|
|
|
if(!instance.empty())
|
|
|
|
|
{
|
|
|
|
|
_ShapeInstances.push_back(instref);
|
|
|
|
|
UMovePrimitive *primitive = NULL;
|
|
|
|
|
|
|
|
|
|
if (PACS && haveCollisions)
|
|
|
|
|
{
|
|
|
|
|
primitive = PACS->addCollisionablePrimitive(dynamicWI, 1);
|
|
|
|
|
primitive->setDontSnapToGround(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Put instance in last deleted position if found
|
|
|
|
|
if (_LastRemovedInstance != -1)
|
|
|
|
|
{
|
|
|
|
|
idx = _LastRemovedInstance;
|
|
|
|
|
nlinfo("OK adding to index : %d", idx);
|
|
|
|
|
_ShapeInstances[idx].Instance = instance;
|
|
|
|
|
_ShapeInstances[idx].Primitive = primitive;
|
|
|
|
|
_ShapeInstances[idx].ContextText = text;
|
|
|
|
|
_ShapeInstances[idx].ContextURL = url;
|
|
|
|
|
_ShapeInstances[idx].BboxActive = !text.empty() || !url.empty();
|
|
|
|
|
_ShapeInstances[idx].Deleted = false;
|
|
|
|
|
|
|
|
|
|
_LastRemovedInstance = _ShapeInstances[idx].LastDeleted;
|
|
|
|
|
_ShapeInstances[idx].LastDeleted = -1;
|
|
|
|
|
return _ShapeInstances[idx];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
nlinfo("OK url, text = %s, %s", url.c_str(), text.c_str());
|
|
|
|
|
CShapeInstanceReference instref = CShapeInstanceReference(instance, text, url, !text.empty() || !url.empty());
|
|
|
|
|
instref.Primitive = primitive;
|
|
|
|
|
idx = _ShapeInstances.size();
|
|
|
|
|
_ShapeInstances.push_back(instref);
|
|
|
|
|
return instref;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return nullinstref;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CEntityManager::deleteInstance(uint32 idx)
|
|
|
|
|
{
|
|
|
|
|
if (!Scene || idx >= _ShapeInstances.size())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (!_ShapeInstances[idx].Instance.empty())
|
|
|
|
|
Scene->deleteInstance(_ShapeInstances[idx].Instance);
|
|
|
|
|
UMovePrimitive *primitive = _ShapeInstances[idx].Primitive;
|
|
|
|
|
if (primitive)
|
|
|
|
|
{
|
|
|
|
|
PACS->removePrimitive(primitive);
|
|
|
|
|
}
|
|
|
|
|
_ShapeInstances[idx].Primitive = NULL;
|
|
|
|
|
_ShapeInstances[idx].Deleted = true;
|
|
|
|
|
_ShapeInstances[idx].LastDeleted = _LastRemovedInstance;
|
|
|
|
|
_LastRemovedInstance = idx;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CVector CEntityManager::getInstancePos(uint32 idx)
|
|
|
|
|
{
|
|
|
|
|
if (!Scene || idx >= _ShapeInstances.size() || _ShapeInstances[idx].Deleted)
|
|
|
|
|
return CVector(0,0,0);
|
|
|
|
|
|
|
|
|
|
UInstance instance = _ShapeInstances[idx].Instance;
|
|
|
|
|
if(instance.empty())
|
|
|
|
|
return CVector(0,0,0);
|
|
|
|
|
|
|
|
|
|
return instance.getPos();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CEntityManager::setInstancePos(uint32 idx, CVector pos)
|
|
|
|
|
{
|
|
|
|
|
if (!Scene || idx >= _ShapeInstances.size() || _ShapeInstances[idx].Deleted)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
UInstance instance = _ShapeInstances[idx].Instance;
|
|
|
|
|
if(instance.empty())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
UMovePrimitive *primitive = _ShapeInstances[idx].Primitive;
|
|
|
|
|
if (primitive)
|
|
|
|
|
{
|
|
|
|
|
primitive->setGlobalPosition(_ShapeInstances[idx].PrimRelativePos + pos, dynamicWI);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
instance.setPos(pos);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CVector CEntityManager::getInstanceRot(uint32 idx)
|
|
|
|
|
{
|
|
|
|
|
if (!Scene || idx >= _ShapeInstances.size() || _ShapeInstances[idx].Deleted)
|
|
|
|
|
return CVector(0,0,0);
|
|
|
|
|
|
|
|
|
|
UInstance instance = _ShapeInstances[idx].Instance;
|
|
|
|
|
if(instance.empty())
|
|
|
|
|
return CVector(0,0,0);
|
|
|
|
|
|
|
|
|
|
return instance.getRotEuler();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CEntityManager::setInstanceRot(uint32 idx, CVector rot)
|
|
|
|
|
{
|
|
|
|
|
if (!Scene || idx >= _ShapeInstances.size() || _ShapeInstances[idx].Deleted)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
UInstance instance = _ShapeInstances[idx].Instance;
|
|
|
|
|
if(instance.empty())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
instance.setRotEuler(rot);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CVector CEntityManager::getInstanceScale(uint32 idx)
|
|
|
|
|
{
|
|
|
|
|
if (!Scene || idx >= _ShapeInstances.size() || _ShapeInstances[idx].Deleted)
|
|
|
|
|
return CVector(0,0,0);
|
|
|
|
|
|
|
|
|
|
UInstance instance = _ShapeInstances[idx].Instance;
|
|
|
|
|
if(instance.empty())
|
|
|
|
|
return CVector(0,0,0);
|
|
|
|
|
|
|
|
|
|
return instance.getScale();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CVector CEntityManager::getInstanceColPos(uint32 idx)
|
|
|
|
|
{
|
|
|
|
|
if (!Scene || idx >= _ShapeInstances.size() || _ShapeInstances[idx].Deleted)
|
|
|
|
|
return CVector(0,0,0);
|
|
|
|
|
|
|
|
|
|
return _ShapeInstances[idx].PrimRelativePos;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CVector CEntityManager::getInstanceColScale(uint32 idx)
|
|
|
|
|
{
|
|
|
|
|
if (!Scene || idx >= _ShapeInstances.size() || _ShapeInstances[idx].Deleted)
|
|
|
|
|
return CVector(0,0,0);
|
|
|
|
|
|
|
|
|
|
UMovePrimitive *primitive = _ShapeInstances[idx].Primitive;
|
|
|
|
|
if (!primitive)
|
|
|
|
|
return CVector(0,0,0);
|
|
|
|
|
|
|
|
|
|
float width, depth;
|
|
|
|
|
primitive->getSize(width, depth);
|
|
|
|
|
float height = primitive->getHeight();
|
|
|
|
|
|
|
|
|
|
return CVector(width, depth, height);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double CEntityManager::getInstanceColOrient(uint32 idx)
|
|
|
|
|
{
|
|
|
|
|
if (!Scene || idx >= _ShapeInstances.size() || _ShapeInstances[idx].Deleted)
|
|
|
|
|
return 0.f;
|
|
|
|
|
|
|
|
|
|
UMovePrimitive *primitive = _ShapeInstances[idx].Primitive;
|
|
|
|
|
if (!primitive)
|
|
|
|
|
return 0.f;
|
|
|
|
|
|
|
|
|
|
return primitive->getOrientation(dynamicWI);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool CEntityManager::removeInstances()
|
|
|
|
|
{
|
|
|
|
|
if (!Scene) return false;
|
|
|
|
@ -546,9 +707,16 @@ bool CEntityManager::removeInstances()
|
|
|
|
|
{
|
|
|
|
|
if (!_ShapeInstances[i].Instance.empty())
|
|
|
|
|
Scene->deleteInstance(_ShapeInstances[i].Instance);
|
|
|
|
|
|
|
|
|
|
UMovePrimitive *primitive = _ShapeInstances[i].Primitive;
|
|
|
|
|
if (primitive)
|
|
|
|
|
{
|
|
|
|
|
PACS->removePrimitive(primitive);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
_ShapeInstances.clear();
|
|
|
|
|
_InstancesRemoved = true;
|
|
|
|
|
_LastRemovedInstance = -1;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -559,10 +727,165 @@ bool CEntityManager::instancesRemoved()
|
|
|
|
|
return instRemoved;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CShapeInstanceReference CEntityManager::getShapeInstanceUnderPos(float x, float y)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool CEntityManager::setupInstance(uint32 idx, const vector<string> &keys, const vector<string> &values) {
|
|
|
|
|
if (!Scene || idx >= _ShapeInstances.size() || _ShapeInstances[idx].Deleted)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
UInstance instance = _ShapeInstances[idx].Instance;
|
|
|
|
|
if(instance.empty())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
UMovePrimitive *primitive = _ShapeInstances[idx].Primitive;
|
|
|
|
|
|
|
|
|
|
for (uint32 i=0; i < keys.size(); i++)
|
|
|
|
|
{
|
|
|
|
|
nlinfo("Setup [%s] with [%s]", keys[i].c_str(), values[i].c_str());
|
|
|
|
|
|
|
|
|
|
string param = keys[i];
|
|
|
|
|
if (param == "transparency")
|
|
|
|
|
{
|
|
|
|
|
uint t;
|
|
|
|
|
if( fromString( values[i], t ) ) {
|
|
|
|
|
t = max(0, min((int)t, 255));
|
|
|
|
|
makeInstanceTransparent(instance, t, t == 255);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (param == "colorize")
|
|
|
|
|
{
|
|
|
|
|
CRGBA c;
|
|
|
|
|
if( fromString( values[i], c ) )
|
|
|
|
|
{
|
|
|
|
|
for(uint j=0;j<instance.getNumMaterials();j++)
|
|
|
|
|
{
|
|
|
|
|
instance.getMaterial(j).setShininess( 1000.0f );
|
|
|
|
|
instance.getMaterial(j).setEmissive(c);
|
|
|
|
|
instance.getMaterial(j).setDiffuse(c);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (param == "texture")
|
|
|
|
|
{
|
|
|
|
|
if (!values[i].empty())
|
|
|
|
|
{
|
|
|
|
|
for(uint j=0;j<instance.getNumMaterials();j++)
|
|
|
|
|
{
|
|
|
|
|
sint numStages = instance.getMaterial(j).getLastTextureStage() + 1;
|
|
|
|
|
for(sint l = 0; l < numStages; l++)
|
|
|
|
|
{
|
|
|
|
|
if (instance.getMaterial(j).isTextureFile((uint) l))
|
|
|
|
|
instance.getMaterial(j).setTextureFileName(values[i], (uint) l);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (param == "scale x" || param == "scale y" || param == "scale z")
|
|
|
|
|
{
|
|
|
|
|
float v;
|
|
|
|
|
CVector scale = instance.getScale();
|
|
|
|
|
|
|
|
|
|
if( getRelativeFloatFromString( values[i], v ) ) {
|
|
|
|
|
updateVector(param, scale, v, true);
|
|
|
|
|
} else {
|
|
|
|
|
updateVector(param, scale, v, false);
|
|
|
|
|
}
|
|
|
|
|
instance.setScale(scale);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Primitive colissions setups
|
|
|
|
|
|
|
|
|
|
if (!primitive) continue;
|
|
|
|
|
|
|
|
|
|
if (param == "col size x" || param == "col size y" || param == "col size z")
|
|
|
|
|
{
|
|
|
|
|
float width, depth;
|
|
|
|
|
primitive->getSize(width, depth);
|
|
|
|
|
float height = primitive->getHeight();
|
|
|
|
|
|
|
|
|
|
CVector size = CVector(width, depth, height);
|
|
|
|
|
float v;
|
|
|
|
|
if( getRelativeFloatFromString( values[i], v ) ) {
|
|
|
|
|
updateVector(param, size, v, true);
|
|
|
|
|
} else {
|
|
|
|
|
updateVector(param, size, v, false);
|
|
|
|
|
}
|
|
|
|
|
primitive->setSize(size.x, size.y);
|
|
|
|
|
primitive->setHeight(size.z);
|
|
|
|
|
}
|
|
|
|
|
else if (param == "col pos x" || param == "col pos y" || param == "col pos z")
|
|
|
|
|
{
|
|
|
|
|
CVector pos = instance.getPos();
|
|
|
|
|
float v;
|
|
|
|
|
|
|
|
|
|
if( getRelativeFloatFromString( values[i], v ) ) {
|
|
|
|
|
updateVector(param, _ShapeInstances[idx].PrimRelativePos, v, false);
|
|
|
|
|
} else {
|
|
|
|
|
if (param == "col pos x")
|
|
|
|
|
_ShapeInstances[idx].PrimRelativePos.x = v - pos.x;
|
|
|
|
|
if (param == "col pos y")
|
|
|
|
|
_ShapeInstances[idx].PrimRelativePos.y = v - pos.y;
|
|
|
|
|
if (param == "col pos z")
|
|
|
|
|
_ShapeInstances[idx].PrimRelativePos.z = v - pos.z;
|
|
|
|
|
}
|
|
|
|
|
primitive->setGlobalPosition(pos + _ShapeInstances[idx].PrimRelativePos, dynamicWI);
|
|
|
|
|
}
|
|
|
|
|
else if (param == "col orientation")
|
|
|
|
|
{
|
|
|
|
|
double orient = primitive->getOrientation(dynamicWI);
|
|
|
|
|
double v = 0.f;
|
|
|
|
|
|
|
|
|
|
if (values[i].empty())
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (values[i][0] == '+')
|
|
|
|
|
{
|
|
|
|
|
fromString(values[i].substr(1), v);
|
|
|
|
|
orient += v;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fromString(values[i], v);
|
|
|
|
|
orient = v;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
primitive->setOrientation(orient, dynamicWI);
|
|
|
|
|
}
|
|
|
|
|
else if (param == "col mask player")
|
|
|
|
|
{
|
|
|
|
|
bool active;
|
|
|
|
|
fromString(values[i], active);
|
|
|
|
|
UMovePrimitive::TCollisionMask mask=primitive->getCollisionMask();
|
|
|
|
|
if (active)
|
|
|
|
|
primitive->setCollisionMask(mask|MaskColPlayer);
|
|
|
|
|
else
|
|
|
|
|
primitive->setCollisionMask(mask&~MaskColPlayer);
|
|
|
|
|
}
|
|
|
|
|
else if (param == "col mask door")
|
|
|
|
|
{
|
|
|
|
|
bool active;
|
|
|
|
|
fromString(values[i], active);
|
|
|
|
|
UMovePrimitive::TCollisionMask mask=primitive->getCollisionMask();
|
|
|
|
|
if (active)
|
|
|
|
|
primitive->setCollisionMask(mask|MaskColDoor);
|
|
|
|
|
else
|
|
|
|
|
primitive->setCollisionMask(mask&~MaskColDoor);
|
|
|
|
|
}
|
|
|
|
|
else if (param == "col obstacle")
|
|
|
|
|
{
|
|
|
|
|
bool active;
|
|
|
|
|
fromString(values[i], active);
|
|
|
|
|
primitive->setObstacle(active);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CShapeInstanceReference CEntityManager::getShapeInstanceUnderPos(float x, float y, sint32 &idx)
|
|
|
|
|
{
|
|
|
|
|
CShapeInstanceReference selectedInstance(UInstance(), string(""), string(""));
|
|
|
|
|
_LastInstanceUnderPos= NULL;
|
|
|
|
|
idx = -1;
|
|
|
|
|
|
|
|
|
|
// If not initialised, return
|
|
|
|
|
if (_ShapeInstances.empty())
|
|
|
|
@ -583,13 +906,14 @@ CShapeInstanceReference CEntityManager::getShapeInstanceUnderPos(float x, float
|
|
|
|
|
float bestDist = 255;
|
|
|
|
|
for(uint i=0; i<_ShapeInstances.size(); i++)
|
|
|
|
|
{
|
|
|
|
|
if (_ShapeInstances[i].BboxActive)
|
|
|
|
|
if (!_ShapeInstances[i].Deleted && _ShapeInstances[i].BboxActive)
|
|
|
|
|
{
|
|
|
|
|
H_AUTO(RZ_Client_GEUP_box_intersect)
|
|
|
|
|
|
|
|
|
|
// if intersect the bbox
|
|
|
|
|
NLMISC::CAABBox bbox;
|
|
|
|
|
//= _ShapeInstances[i].SelectionBox;
|
|
|
|
|
if(!_ShapeInstances[i].Instance.empty()) {
|
|
|
|
|
_ShapeInstances[i].Instance.getShapeAABBox(bbox);
|
|
|
|
|
if (bbox.getCenter() == CVector::Null)
|
|
|
|
|
{
|
|
|
|
@ -599,13 +923,15 @@ CShapeInstanceReference CEntityManager::getShapeInstanceUnderPos(float x, float
|
|
|
|
|
{
|
|
|
|
|
bbox.setMinMax((bbox.getMin()*_ShapeInstances[i].Instance.getScale().x)+_ShapeInstances[i].Instance.getPos(), (bbox.getMax()*_ShapeInstances[i].Instance.getScale().x)+_ShapeInstances[i].Instance.getPos());
|
|
|
|
|
}
|
|
|
|
|
if(bbox.intersect(pos, pos+dir*15.0f))
|
|
|
|
|
if(bbox.intersect(pos, pos+dir*50.0f))
|
|
|
|
|
{
|
|
|
|
|
float dist = (bbox.getCenter()-pos).norm();
|
|
|
|
|
if (dist < bestDist)
|
|
|
|
|
{
|
|
|
|
|
selectedInstance = _ShapeInstances[i];
|
|
|
|
|
bestDist = dist;
|
|
|
|
|
idx = (sint32)i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|