#ifndef __C_SCENE_MANAGER_H_INCLUDED__
#define __C_SCENE_MANAGER_H_INCLUDED__
#include "ISceneManager.h"
#include "ISceneNode.h"
#include "ICursorControl.h"
#include "irrString.h"
#include "irrArray.h"
#include "IMeshLoader.h"
#include "CAttributes.h"
#include "ILightManager.h"
namespace irr
{
namespace io
{
class IXMLWriter;
class IFileSystem;
}
namespace scene
{
class IMeshCache;
class IGeometryCreator;
class CSceneManager : public ISceneManager, public ISceneNode
{
public:
CSceneManager(video::IVideoDriver* driver, io::IFileSystem* fs,
gui::ICursorControl* cursorControl, IMeshCache* cache = 0,
gui::IGUIEnvironment *guiEnvironment = 0);
virtual ~CSceneManager();
virtual IAnimatedMesh* getMesh(const io::path& filename);
virtual IAnimatedMesh* getMesh(io::IReadFile* file);
virtual IMeshCache* getMeshCache();
virtual video::IVideoDriver* getVideoDriver();
virtual gui::IGUIEnvironment* getGUIEnvironment();
virtual io::IFileSystem* getFileSystem();
virtual IVolumeLightSceneNode* addVolumeLightSceneNode(ISceneNode* parent=0, s32 id=-1,
const u32 subdivU = 32, const u32 subdivV = 32,
const video::SColor foot = video::SColor(51, 0, 230, 180),
const video::SColor tail = video::SColor(0, 0, 0, 0),
const core::vector3df& position = core::vector3df(0,0,0),
const core::vector3df& rotation = core::vector3df(0,0,0),
const core::vector3df& scale = core::vector3df(1.0f, 1.0f, 1.0f));
virtual IMeshSceneNode* addCubeSceneNode(f32 size=10.0f, ISceneNode* parent=0, s32 id=-1,
const core::vector3df& position = core::vector3df(0,0,0), const core::vector3df& rotation = core::vector3df(0,0,0), const core::vector3df& scale = core::vector3df(1.0f, 1.0f, 1.0f));
virtual IMeshSceneNode* addSphereSceneNode(f32 radius=5.0f, s32 polyCount=16, ISceneNode* parent=0, s32 id=-1,
const core::vector3df& position = core::vector3df(0,0,0),
const core::vector3df& rotation = core::vector3df(0,0,0),
const core::vector3df& scale = core::vector3df(1.0f, 1.0f, 1.0f));
virtual IAnimatedMeshSceneNode* addAnimatedMeshSceneNode(IAnimatedMesh* mesh, ISceneNode* parent=0, s32 id=-1,
const core::vector3df& position = core::vector3df(0,0,0),
const core::vector3df& rotation = core::vector3df(0,0,0),
const core::vector3df& scale = core::vector3df(1.0f, 1.0f, 1.0f),
bool alsoAddIfMeshPointerZero=false);
virtual IMeshSceneNode* addMeshSceneNode(IMesh* mesh, ISceneNode* parent=0, s32 id=-1,
const core::vector3df& position = core::vector3df(0,0,0),
const core::vector3df& rotation = core::vector3df(0,0,0),
const core::vector3df& scale = core::vector3df(1.0f, 1.0f, 1.0f),
bool alsoAddIfMeshPointerZero=false);
virtual ISceneNode* addWaterSurfaceSceneNode(IMesh* mesh, f32 waveHeight, f32 waveSpeed, f32 wlenght, ISceneNode* parent=0, s32 id=-1,
const core::vector3df& position = core::vector3df(0,0,0),
const core::vector3df& rotation = core::vector3df(0,0,0),
const core::vector3df& scale = core::vector3df(1.0f, 1.0f, 1.0f));
virtual void render();
virtual const core::aabbox3d<f32>& getBoundingBox() const;
virtual u32 registerNodeForRendering(ISceneNode* node, E_SCENE_NODE_RENDER_PASS pass = ESNRP_AUTOMATIC);
virtual void drawAll();
virtual ICameraSceneNode* addCameraSceneNode(ISceneNode* parent = 0,
const core::vector3df& position = core::vector3df(0,0,0),
const core::vector3df& lookat = core::vector3df(0,0,100),
s32 id=-1, bool makeActive=true);
virtual ICameraSceneNode* addCameraSceneNodeMaya(ISceneNode* parent = 0,
f32 rotateSpeed = -1500.0f, f32 zoomSpeed = 200.0f,
f32 translationSpeed = 1500.0f, s32 id=-1,
bool makeActive=true);
virtual ICameraSceneNode* addCameraSceneNodeFPS(ISceneNode* parent = 0,
f32 rotateSpeed = 100.0f, f32 moveSpeed = .5f, s32 id=-1,
SKeyMap* keyMapArray=0, s32 keyMapSize=0,
bool noVerticalMovement=false, f32 jumpSpeed = 0.f,
bool invertMouseY=false, bool makeActive=true);
virtual ILightSceneNode* addLightSceneNode(ISceneNode* parent = 0,
const core::vector3df& position = core::vector3df(0,0,0),
video::SColorf color = video::SColorf(1.0f, 1.0f, 1.0f),
f32 range=100.0f, s32 id=-1);
virtual IBillboardSceneNode* addBillboardSceneNode(ISceneNode* parent = 0,
const core::dimension2d<f32>& size = core::dimension2d<f32>(10.0f, 10.0f),
const core::vector3df& position = core::vector3df(0,0,0), s32 id=-1,
video::SColor shadeTop = 0xFFFFFFFF, video::SColor shadeBottom = 0xFFFFFFFF);
virtual ISceneNode* addSkyBoxSceneNode(video::ITexture* top, video::ITexture* bottom,
video::ITexture* left, video::ITexture* right, video::ITexture* front,
video::ITexture* back, ISceneNode* parent = 0, s32 id=-1);
virtual ISceneNode* addSkyDomeSceneNode(video::ITexture* texture,
u32 horiRes=16, u32 vertRes=8,
f32 texturePercentage=0.9, f32 spherePercentage=2.0,f32 radius = 1000.f,
ISceneNode* parent=0, s32 id=-1);
virtual ITextSceneNode* addTextSceneNode(gui::IGUIFont* font, const wchar_t* text,
video::SColor color=video::SColor(100,255,255,255),
ISceneNode* parent = 0, const core::vector3df& position = core::vector3df(0,0,0),
s32 id=-1);
virtual IBillboardTextSceneNode* addBillboardTextSceneNode(gui::IGUIFont* font, const wchar_t* text,
ISceneNode* parent = 0,
const core::dimension2d<f32>& size = core::dimension2d<f32>(10.0f, 10.0f),
const core::vector3df& position = core::vector3df(0,0,0), s32 id=-1,
video::SColor colorTop = 0xFFFFFFFF, video::SColor colorBottom = 0xFFFFFFFF);
virtual IAnimatedMesh* addHillPlaneMesh(const io::path& name,
const core::dimension2d<f32>& tileSize, const core::dimension2d<u32>& tileCount,
video::SMaterial* material = 0, f32 hillHeight = 0.0f,
const core::dimension2d<f32>& countHills = core::dimension2d<f32>(1.0f, 1.0f),
const core::dimension2d<f32>& textureRepeatCount = core::dimension2d<f32>(1.0f, 1.0f));
virtual IAnimatedMesh* addTerrainMesh(const io::path& meshname, video::IImage* texture, video::IImage* heightmap,
const core::dimension2d<f32>& stretchSize = core::dimension2d<f32>(10.0f,10.0f),
f32 maxHeight=200.0f,
const core::dimension2d<u32>& defaultVertexBlockSize = core::dimension2d<u32>(64,64));
virtual IAnimatedMesh* addArrowMesh(const io::path& name,
video::SColor vtxColor0, video::SColor vtxColor1,
u32 tesselationCylinder, u32 tesselationCone,
f32 height, f32 cylinderHeight, f32 width0,
f32 width1);
IAnimatedMesh* addSphereMesh(const io::path& name,
f32 radius=5.f, u32 polyCountX=16, u32 polyCountY=16);
IAnimatedMesh* addVolumeLightMesh(const io::path& name,
const u32 SubdivideU = 32, const u32 SubdivideV = 32,
const video::SColor FootColor = video::SColor(51, 0, 230, 180),
const video::SColor TailColor = video::SColor(0, 0, 0, 0));
virtual IParticleSystemSceneNode* addParticleSystemSceneNode(
bool withDefaultEmitter=true, ISceneNode* parent=0, s32 id=-1,
const core::vector3df& position = core::vector3df(0,0,0),
const core::vector3df& rotation = core::vector3df(0,0,0),
const core::vector3df& scale = core::vector3df(1.0f, 1.0f, 1.0f));
virtual ITerrainSceneNode* addTerrainSceneNode(
const io::path& heightMapFileName,
ISceneNode* parent=0, s32 id=-1,
const core::vector3df& position = core::vector3df(0.0f,0.0f,0.0f),
const core::vector3df& rotation = core::vector3df(0.0f,0.0f,0.0f),
const core::vector3df& scale = core::vector3df(1.0f,1.0f,1.0f),
video::SColor vertexColor = video::SColor(255,255,255,255),
s32 maxLOD=4, E_TERRAIN_PATCH_SIZE patchSize=ETPS_17,s32 smoothFactor=0,
bool addAlsoIfHeightmapEmpty = false);
virtual ITerrainSceneNode* addTerrainSceneNode(
io::IReadFile* heightMap,
ISceneNode* parent=0, s32 id=-1,
const core::vector3df& position = core::vector3df(0.0f,0.0f,0.0f),
const core::vector3df& rotation = core::vector3df(0.0f,0.0f,0.0f),
const core::vector3df& scale = core::vector3df(1.0f,1.0f,1.0f),
video::SColor vertexColor = video::SColor(255,255,255,255),
s32 maxLOD=4, E_TERRAIN_PATCH_SIZE patchSize=ETPS_17,s32 smoothFactor=0,
bool addAlsoIfHeightmapEmpty=false);
virtual IDummyTransformationSceneNode* addDummyTransformationSceneNode(
ISceneNode* parent=0, s32 id=-1);
virtual ISceneNode* addEmptySceneNode(ISceneNode* parent, s32 id=-1);
virtual ISceneNode* getRootSceneNode();
virtual ICameraSceneNode* getActiveCamera() const;
virtual void setActiveCamera(ICameraSceneNode* camera);
virtual ISceneNodeAnimator* createRotationAnimator(const core::vector3df& rotationPerSecond);
virtual ISceneNodeAnimator* createFlyCircleAnimator(
const core::vector3df& center=core::vector3df(0.f, 0.f, 0.f),
f32 radius=100.f, f32 speed=0.001f,
const core::vector3df& direction=core::vector3df(0.f, 1.f, 0.f),
f32 startPosition = 0.f,
f32 radiusEllipsoid = 0.f);
virtual ISceneNodeAnimator* createFlyStraightAnimator(const core::vector3df& startPoint,
const core::vector3df& endPoint, u32 timeForWay, bool loop=false,bool pingpong = false);
virtual ISceneNodeAnimator* createTextureAnimator(const core::array<video::ITexture*>& textures,
s32 timePerFrame, bool loop);
virtual ISceneNodeAnimator* createDeleteAnimator(u32 timeMS);
virtual ISceneNodeAnimatorCollisionResponse* createCollisionResponseAnimator(
ITriangleSelector* world, ISceneNode* sceneNode,
const core::vector3df& ellipsoidRadius = core::vector3df(30,60,30),
const core::vector3df& gravityPerSecond = core::vector3df(0,-1.0f,0),
const core::vector3df& ellipsoidTranslation = core::vector3df(0,0,0),
f32 slidingValue = 0.0005f);
virtual ISceneNodeAnimator* createFollowSplineAnimator(s32 startTime,
const core::array< core::vector3df >& points,
f32 speed, f32 tightness, bool loop, bool pingpong);
virtual ITriangleSelector* createTriangleSelector(IMesh* mesh, ISceneNode* node);
virtual ITriangleSelector* createTriangleSelector(IAnimatedMeshSceneNode* node);
virtual ITriangleSelector* createOctreeTriangleSelector(IMesh* mesh,
ISceneNode* node, s32 minimalPolysPerNode);
virtual ITriangleSelector* createTriangleSelectorFromBoundingBox(
ISceneNode* node);
virtual IMetaTriangleSelector* createMetaTriangleSelector();
virtual ITriangleSelector* createTerrainTriangleSelector(
ITerrainSceneNode* node, s32 LOD=0);
virtual void addExternalMeshLoader(IMeshLoader* externalLoader);
virtual u32 getMeshLoaderCount() const;
virtual IMeshLoader* getMeshLoader(u32 index) const;
virtual void addExternalSceneLoader(ISceneLoader* externalLoader);
virtual u32 getSceneLoaderCount() const;
virtual ISceneLoader* getSceneLoader(u32 index) const;
virtual ISceneCollisionManager* getSceneCollisionManager();
virtual IMeshManipulator* getMeshManipulator();
virtual void setShadowColor(video::SColor color);
virtual video::SColor getShadowColor() const;
virtual void addToDeletionQueue(ISceneNode* node);
virtual ISceneNode* getSceneNodeFromId(s32 id, ISceneNode* start=0);
virtual ISceneNode* getSceneNodeFromName(const c8* name, ISceneNode* start=0);
virtual ISceneNode* getSceneNodeFromType(scene::ESCENE_NODE_TYPE type, ISceneNode* start=0);
virtual void getSceneNodesFromType(ESCENE_NODE_TYPE type, core::array<scene::ISceneNode*>& outNodes, ISceneNode* start=0);
virtual bool postEventFromUser(const SEvent& event);
virtual void clear();
virtual void removeAll();
virtual io::IAttributes* getParameters();
virtual E_SCENE_NODE_RENDER_PASS getSceneNodeRenderPass() const;
virtual ISceneManager* createNewSceneManager(bool cloneContent);
virtual ESCENE_NODE_TYPE getType() const { return ESNT_UNKNOWN; }
virtual ISceneNodeFactory* getDefaultSceneNodeFactory();
virtual void registerSceneNodeFactory(ISceneNodeFactory* factoryToAdd);
virtual u32 getRegisteredSceneNodeFactoryCount() const;
virtual ISceneNodeFactory* getSceneNodeFactory(u32 index);
virtual const c8* getSceneNodeTypeName(ESCENE_NODE_TYPE type);
virtual const c8* getAnimatorTypeName(ESCENE_NODE_ANIMATOR_TYPE type);
virtual ISceneNode* addSceneNode(const char* sceneNodeTypeName, ISceneNode* parent=0);
virtual ISceneNodeAnimatorFactory* getDefaultSceneNodeAnimatorFactory();
virtual void registerSceneNodeAnimatorFactory(ISceneNodeAnimatorFactory* factoryToAdd);
virtual u32 getRegisteredSceneNodeAnimatorFactoryCount() const;
virtual ISceneNodeAnimatorFactory* getSceneNodeAnimatorFactory(u32 index);
virtual bool saveScene(const io::path& filename, ISceneUserDataSerializer* userDataSerializer=0, ISceneNode* node=0);
virtual bool saveScene(io::IWriteFile* file, ISceneUserDataSerializer* userDataSerializer=0, ISceneNode* node=0);
virtual bool loadScene(const io::path& filename, ISceneUserDataSerializer* userDataSerializer=0, ISceneNode* rootNode=0);
virtual bool loadScene(io::IReadFile* file, ISceneUserDataSerializer* userDataSerializer=0, ISceneNode* rootNode=0);
virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) const;
virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0);
virtual IMeshWriter* createMeshWriter(EMESH_WRITER_TYPE type);
virtual ISkinnedMesh* createSkinnedMesh();
virtual void setAmbientLight(const video::SColorf &ambientColor);
virtual const video::SColorf& getAmbientLight() const;
virtual const IGeometryCreator* getGeometryCreator(void) const { return GeometryCreator; }
virtual bool isCulled(const ISceneNode* node) const;
private:
void clearDeletionList();
void writeSceneNode(io::IXMLWriter* writer, ISceneNode* node, ISceneUserDataSerializer* userDataSerializer, const c8* currentPath=0, bool init=false);
struct DefaultNodeEntry
{
DefaultNodeEntry(ISceneNode* n) :
Node(n), TextureValue(0)
{
if (n->getMaterialCount())
TextureValue = (n->getMaterial(0).getTexture(0));
}
bool operator < (const DefaultNodeEntry& other) const
{
return (TextureValue < other.TextureValue);
}
ISceneNode* Node;
private:
void* TextureValue;
};
struct TransparentNodeEntry
{
TransparentNodeEntry(ISceneNode* n, const core::vector3df& camera)
: Node(n)
{
Distance = Node->getAbsoluteTransformation().getTranslation().getDistanceFromSQ(camera);
}
bool operator < (const TransparentNodeEntry& other) const
{
return Distance > other.Distance;
}
ISceneNode* Node;
private:
f64 Distance;
};
struct DistanceNodeEntry
{
DistanceNodeEntry(ISceneNode* n, const core::vector3df& cameraPos)
: Node(n)
{
setNodeAndDistanceFromPosition(n, cameraPos);
}
bool operator < (const DistanceNodeEntry& other) const
{
return Distance < other.Distance;
}
void setNodeAndDistanceFromPosition(ISceneNode* n, const core::vector3df & fromPosition)
{
Node = n;
Distance = Node->getAbsoluteTransformation().getTranslation().getDistanceFromSQ(fromPosition);
Distance -= Node->getBoundingBox().getExtent().getLengthSQ() * 0.5;
}
ISceneNode* Node;
private:
f64 Distance;
};
video::IVideoDriver* Driver;
io::IFileSystem* FileSystem;
gui::IGUIEnvironment* GUIEnvironment;
gui::ICursorControl* CursorControl;
ISceneCollisionManager* CollisionManager;
core::array<ISceneNode*> CameraList;
core::array<ILightSceneNode*> LightList;
core::array<ISceneNode*> ShadowNodeList;
core::array<ISceneNode*> SkyBoxList;
core::array<DefaultNodeEntry> SolidNodeList;
core::array<TransparentNodeEntry> TransparentNodeList;
core::array<TransparentNodeEntry> TransparentEffectNodeList;
core::array<IMeshLoader*> MeshLoaderList;
core::array<ISceneLoader*> SceneLoaderList;
core::array<ISceneNode*> DeletionList;
core::array<ISceneNodeFactory*> SceneNodeFactoryList;
core::array<ISceneNodeAnimatorFactory*> SceneNodeAnimatorFactoryList;
ICameraSceneNode* ActiveCamera;
core::vector3df camWorldPos;
video::SColor ShadowColor;
video::SColorf AmbientLight;
io::CAttributes Parameters;
IMeshCache* MeshCache;
E_SCENE_NODE_RENDER_PASS CurrentRendertime;
const core::stringw IRR_XML_FORMAT_SCENE;
const core::stringw IRR_XML_FORMAT_NODE;
const core::stringw IRR_XML_FORMAT_NODE_ATTR_TYPE;
IGeometryCreator* GeometryCreator;
};
}
}
#endif