Commit 6e1fc8d7 authored by bitplane's avatar bitplane

Add sky dome type and to default node factory, add serialization and clone...

Add sky dome type and to default node factory, add serialization and clone methods (bug #2656990 reported by lab_zj)

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@2254 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 6036a8e3
Changes in 1.6
- SkyDome is now serialized correctly
- Added PLY mesh reader and writer
- Ensure ListBox on combo box doesn't hang off the bottom of the GUI root, by Matthias Specht
......
......@@ -36,6 +36,9 @@ namespace scene
//! Sky Box Scene Node
ESNT_SKY_BOX = MAKE_IRR_ID('s','k','y','_'),
//! Sky Dome Scene Node
ESNT_SKY_DOME = MAKE_IRR_ID('s','k','y','d'),
//! Shadow Volume Scene Node
ESNT_SHADOW_VOLUME = MAKE_IRR_ID('s','h','d','w'),
......
......@@ -36,6 +36,7 @@ CDefaultSceneNodeFactory::CDefaultSceneNodeFactory(ISceneManager* mgr)
SupportedSceneNodeTypes.push_back(SSceneNodeTypePair(ESNT_WATER_SURFACE, "waterSurface"));
SupportedSceneNodeTypes.push_back(SSceneNodeTypePair(ESNT_TERRAIN, "terrain"));
SupportedSceneNodeTypes.push_back(SSceneNodeTypePair(ESNT_SKY_BOX, "skyBox"));
SupportedSceneNodeTypes.push_back(SSceneNodeTypePair(ESNT_SKY_DOME, "skyDome"));
SupportedSceneNodeTypes.push_back(SSceneNodeTypePair(ESNT_SHADOW_VOLUME, "shadowVolume"));
SupportedSceneNodeTypes.push_back(SSceneNodeTypePair(ESNT_OCT_TREE, "octTree"));
SupportedSceneNodeTypes.push_back(SSceneNodeTypePair(ESNT_MESH, "mesh"));
......@@ -77,6 +78,8 @@ ISceneNode* CDefaultSceneNodeFactory::addSceneNode(ESCENE_NODE_TYPE type, IScene
4, ETPS_17, 0, true);
case ESNT_SKY_BOX:
return Manager->addSkyBoxSceneNode(0,0,0,0,0,0, parent);
case ESNT_SKY_DOME:
return Manager->addSkyDomeSceneNode(0, 16, 8, 0.9f, 2.0f, 1000.0f, parent);
case ESNT_SHADOW_VOLUME:
return 0;
case ESNT_OCT_TREE:
......
......@@ -33,18 +33,14 @@ namespace scene
CSkyDomeSceneNode::CSkyDomeSceneNode(video::ITexture* sky, u32 horiRes, u32 vertRes,
f32 texturePercentage, f32 spherePercentage, f32 radius,
ISceneNode* parent, ISceneManager* mgr, s32 id)
: ISceneNode(parent, mgr, id), Buffer(0)
: ISceneNode(parent, mgr, id), Buffer(0),
HorizontalResolution(horiRes), VerticalResolution(vertRes), TexturePercentage(texturePercentage),
SpherePercentage(spherePercentage), Radius(radius)
{
#ifdef _DEBUG
setDebugName("CSkyDomeSceneNode");
#endif
f32 azimuth, azimuth_step;
f32 elevation, elevation_step;
u32 k;
video::S3DVertex vtx;
setAutomaticCulling ( scene::EAC_OFF );
Buffer = new SMeshBuffer();
......@@ -55,30 +51,49 @@ CSkyDomeSceneNode::CSkyDomeSceneNode(video::ITexture* sky, u32 horiRes, u32 vert
Buffer->BoundingBox.MaxEdge.set(0,0,0);
Buffer->BoundingBox.MinEdge.set(0,0,0);
azimuth_step = (core::PI * 2.f ) /horiRes;
if (spherePercentage<0.)
spherePercentage=-spherePercentage;
if (spherePercentage>2.)
spherePercentage=2.;
elevation_step = spherePercentage*core::HALF_PI/ (f32) vertRes;
Buffer->Vertices.clear();
Buffer->Indices.clear();
}
Buffer->Vertices.reallocate((horiRes+1)*(vertRes+1));
Buffer->Indices.reallocate(3*(2*vertRes-1)*horiRes);
CSkyDomeSceneNode::~CSkyDomeSceneNode()
{
if (Buffer)
Buffer->drop();
}
void CSkyDomeSceneNode::generateMesh()
{
f32 azimuth, azimuth_step;
f32 elevation, elevation_step;
u32 k;
video::S3DVertex vtx;
azimuth_step = (core::PI * 2.f ) / HorizontalResolution;
if (SpherePercentage < 0.f)
SpherePercentage = -SpherePercentage;
if (SpherePercentage > 2.f)
SpherePercentage = 2.f;
elevation_step = SpherePercentage * core::HALF_PI / (f32)VerticalResolution;
Buffer->Vertices.reallocate( (HorizontalResolution + 1) * (VerticalResolution + 1) );
Buffer->Indices.reallocate(3 * (2*VerticalResolution - 1) * HorizontalResolution);
vtx.Color.set(255,255,255,255);
vtx.Normal.set(0.0f,-1.f,0.0f);
const f32 tcV = texturePercentage / vertRes;
for (k = 0, azimuth = 0; k <= horiRes; ++k)
const f32 tcV = TexturePercentage / VerticalResolution;
for (k = 0, azimuth = 0; k <= HorizontalResolution; ++k)
{
elevation = core::HALF_PI;
const f32 tcU = (f32) k / (f32) horiRes;
const f32 tcU = (f32)k / (f32)HorizontalResolution;
const f32 sinA = sinf(azimuth);
const f32 cosA = cosf(azimuth);
for (u32 j = 0; j <= vertRes; ++j)
for (u32 j = 0; j <= VerticalResolution; ++j)
{
const f32 cosEr = radius*cosf(elevation);
vtx.Pos.set( cosEr*sinA,radius*sinf(elevation)+0.0f,cosEr*cosA);
const f32 cosEr = Radius * cosf(elevation);
vtx.Pos.set(cosEr*sinA, Radius*sinf(elevation)+0.0f, cosEr*cosA);
vtx.TCoords.set(tcU, j*tcV);
vtx.Normal = -vtx.Pos;
......@@ -90,33 +105,26 @@ CSkyDomeSceneNode::CSkyDomeSceneNode(video::ITexture* sky, u32 horiRes, u32 vert
azimuth += azimuth_step;
}
for (k = 0; k < horiRes; ++k)
for (k = 0; k < HorizontalResolution; ++k)
{
Buffer->Indices.push_back(vertRes+2+(vertRes+1)*k);
Buffer->Indices.push_back(1+(vertRes+1)*k);
Buffer->Indices.push_back(0+(vertRes+1)*k);
Buffer->Indices.push_back(VerticalResolution + 2 + (VerticalResolution + 1)*k);
Buffer->Indices.push_back(1 + (VerticalResolution + 1)*k);
Buffer->Indices.push_back(0 + (VerticalResolution + 1)*k);
for (u32 j = 1; j < vertRes; ++j)
for (u32 j = 1; j < VerticalResolution; ++j)
{
Buffer->Indices.push_back(vertRes+2+(vertRes+1)*k+j);
Buffer->Indices.push_back(1+(vertRes+1)*k+j);
Buffer->Indices.push_back(0+(vertRes+1)*k+j);
Buffer->Indices.push_back(VerticalResolution + 2 + (VerticalResolution + 1)*k + j);
Buffer->Indices.push_back(1 + (VerticalResolution + 1)*k + j);
Buffer->Indices.push_back(0 + (VerticalResolution + 1)*k + j);
Buffer->Indices.push_back(vertRes+1+(vertRes+1)*k+j);
Buffer->Indices.push_back(vertRes+2+(vertRes+1)*k+j);
Buffer->Indices.push_back(0+(vertRes+1)*k+j);
Buffer->Indices.push_back(VerticalResolution + 1 + (VerticalResolution + 1)*k + j);
Buffer->Indices.push_back(VerticalResolution + 2 + (VerticalResolution + 1)*k + j);
Buffer->Indices.push_back(0 + (VerticalResolution + 1)*k + j);
}
}
}
CSkyDomeSceneNode::~CSkyDomeSceneNode()
{
if (Buffer)
Buffer->drop();
}
//! renders the node.
void CSkyDomeSceneNode::render()
{
......@@ -228,7 +236,51 @@ u32 CSkyDomeSceneNode::getMaterialCount() const
return 1;
}
//! Writes attributes of the scene node.
void CSkyDomeSceneNode::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const
{
ISceneNode::serializeAttributes(out, options);
out->addInt ("HorizontalResolution", HorizontalResolution);
out->addInt ("VerticalResolution", VerticalResolution);
out->addFloat("TexturePercentage", TexturePercentage);
out->addFloat("SpherePercentage", SpherePercentage);
out->addFloat("Radius", Radius);
}
//! Reads attributes of the scene node.
void CSkyDomeSceneNode::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options)
{
HorizontalResolution = in->getAttributeAsInt ("HorizontalResolution");
VerticalResolution = in->getAttributeAsInt ("VerticalResolution");
TexturePercentage = in->getAttributeAsFloat("TexturePercentage");
SpherePercentage = in->getAttributeAsFloat("SpherePercentage");
Radius = in->getAttributeAsFloat("Radius");
ISceneNode::deserializeAttributes(in, options);
// regenerate the mesh
generateMesh();
}
//! Creates a clone of this scene node and its children.
ISceneNode* CSkyDomeSceneNode::clone(ISceneNode* newParent, ISceneManager* newManager)
{
if (!newParent)
newParent = Parent;
if (!newManager)
newManager = SceneManager;
CSkyDomeSceneNode* nb = new CSkyDomeSceneNode(Buffer->Material.TextureLayer[0].Texture, HorizontalResolution, VerticalResolution, TexturePercentage,
SpherePercentage, Radius, newParent, newManager, ID);
nb->cloneMembers(this, newManager);
nb->drop();
return nb;
}
} // namespace scene
} // namespace irr
......@@ -19,17 +19,27 @@ class CSkyDomeSceneNode : public ISceneNode
public:
CSkyDomeSceneNode(video::ITexture* texture, u32 horiRes, u32 vertRes,
f32 texturePercentage, f32 spherePercentage, f32 radius,
ISceneNode* root, ISceneManager* smgr, s32 id);
ISceneNode* parent, ISceneManager* smgr, s32 id);
virtual ~CSkyDomeSceneNode();
virtual void OnRegisterSceneNode();
virtual void render();
virtual const core::aabbox3d<f32>& getBoundingBox() const;
virtual video::SMaterial& getMaterial(u32 i);
virtual u32 getMaterialCount() const;
virtual ESCENE_NODE_TYPE getType() const { return ESNT_SKY_BOX; }
virtual ESCENE_NODE_TYPE getType() const { return ESNT_SKY_DOME; }
virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const;
virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options);
virtual ISceneNode* clone(ISceneNode* newParent=0, ISceneManager* newManager=0);
private:
void generateMesh();
SMeshBuffer* Buffer;
u32 HorizontalResolution, VerticalResolution;
f32 TexturePercentage, SpherePercentage, Radius;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment