Add new cube mesh type ECMT_1BUF_24VTX_NP. CubeSceneNodes can now use different cube mesh types.

1 Meshbuffer with 24 vertices, so each side has it's own vertices.
Normals perpendicular to the cube-sides.
CubeSceneNode accepts now a ECUBE_MESH_TYPE
CubeSceneNode::clone now also clones rotation and scale (not sure why it didn't do that before - hope there was no reason, but can't think of any).
ISceneManager::addCubeSceneNode accepts now a ECUBE_MESH_TYPE and passes it through.
Example 22.MaterialViewer using new cube type. Also a few more beauty fixes there.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6313 dfc29bdd-3216-0410-991c-e03cc46cb475
This commit is contained in:
cutealien
2022-03-22 22:08:33 +00:00
parent f61b8614ab
commit 669ad7860a
8 changed files with 120 additions and 19 deletions

View File

@ -37,9 +37,10 @@ namespace scene
//! constructor
CCubeSceneNode::CCubeSceneNode(f32 size, ISceneNode* parent, ISceneManager* mgr,
s32 id, const core::vector3df& position,
const core::vector3df& rotation, const core::vector3df& scale)
const core::vector3df& rotation, const core::vector3df& scale,
ECUBE_MESH_TYPE type)
: IMeshSceneNode(parent, mgr, id, position, rotation, scale),
Mesh(0), Shadow(0), Size(size)
Mesh(0), Shadow(0), Size(size), MeshType(type)
{
#ifdef _DEBUG
setDebugName("CCubeSceneNode");
@ -62,7 +63,7 @@ void CCubeSceneNode::setSize()
{
if (Mesh)
Mesh->drop();
Mesh = SceneManager->getGeometryCreator()->createCubeMesh(core::vector3df(Size));
Mesh = SceneManager->getGeometryCreator()->createCubeMesh(core::vector3df(Size), MeshType);
}
@ -135,7 +136,7 @@ const core::aabbox3d<f32>& CCubeSceneNode::getBoundingBox() const
//! Removes a child from this scene node.
//! Implemented here, to be able to remove the shadow properly, if there is one,
//! or to remove attached childs.
//! or to remove attached child.
bool CCubeSceneNode::removeChild(ISceneNode* child)
{
if (child && Shadow == child)
@ -199,17 +200,20 @@ void CCubeSceneNode::serializeAttributes(io::IAttributes* out, io::SAttributeRea
ISceneNode::serializeAttributes(out, options);
out->addFloat("Size", Size);
out->addEnum("MeshType", (irr::s32)MeshType, CubeMeshTypeNames);
}
//! Reads attributes of the scene node.
void CCubeSceneNode::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options)
{
f32 newSize = in->getAttributeAsFloat("Size");
f32 newSize = in->getAttributeAsFloat("Size", Size);
ECUBE_MESH_TYPE newMeshType = (ECUBE_MESH_TYPE)in->getAttributeAsEnumeration("MeshType", CubeMeshTypeNames, (irr::s32)MeshType);
newSize = core::max_(newSize, 0.0001f);
if (newSize != Size)
if (newSize != Size || newMeshType != MeshType)
{
Size = newSize;
MeshType = newMeshType;
setSize();
}
@ -226,7 +230,7 @@ ISceneNode* CCubeSceneNode::clone(ISceneNode* newParent, ISceneManager* newManag
newManager = SceneManager;
CCubeSceneNode* nb = new CCubeSceneNode(Size, newParent,
newManager, ID, RelativeTranslation);
newManager, ID, RelativeTranslation, RelativeRotation, RelativeScale, MeshType);
nb->cloneMembers(this, newManager);
nb->getMaterial(0) = getMaterial(0);

View File

@ -7,6 +7,7 @@
#include "IMeshSceneNode.h"
#include "SMesh.h"
#include "IGeometryCreator.h"
namespace irr
{
@ -20,7 +21,8 @@ namespace scene
CCubeSceneNode(f32 size, ISceneNode* parent, ISceneManager* mgr, s32 id,
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));
const core::vector3df& scale = core::vector3df(1.0f, 1.0f, 1.0f),
ECUBE_MESH_TYPE type=ECMT_1BUF_12VTX_NA);
virtual ~CCubeSceneNode();
@ -84,6 +86,7 @@ namespace scene
IMesh* Mesh;
IShadowVolumeSceneNode* Shadow;
f32 Size;
ECUBE_MESH_TYPE MeshType;
};
} // end namespace scene

View File

@ -140,6 +140,69 @@ IMesh* CGeometryCreator::createCubeMesh(const core::vector3df& size, ECUBE_MESH_
buffer->drop();
}
}
else if ( type == ECMT_1BUF_24VTX_NP )
{
SMeshBuffer* buffer = new SMeshBuffer();
// Create indices (pos, neg describes normal direction of front-face)
const u16 u[36] = { 0,2,1, 0,3,2, // NEG_Z
4,7,6, 4,5,7, // POS_X
8,10,11, 8,9,10, // POS_Z
15,13,12, 15,14,13, // NEG_X
19,17,16, 19,18,17, // POS_Y
20,23,22, 20,22,21}; // NEG_Y
buffer->Indices.set_used(36);
for (u32 i=0; i<36; ++i)
buffer->Indices[i] = u[i];
// Create vertices
buffer->Vertices.reallocate(24);
buffer->Vertices.push_back(video::S3DVertex(0,0,0, 0, 0,-1, clr, 0, 1)); // 0
buffer->Vertices.push_back(video::S3DVertex(1,0,0, 0, 0,-1, clr, 1, 1)); // 1
buffer->Vertices.push_back(video::S3DVertex(1,1,0, 0, 0,-1, clr, 1, 0)); // 2
buffer->Vertices.push_back(video::S3DVertex(0,1,0, 0, 0,-1, clr, 0, 0)); // 3
buffer->Vertices.push_back(video::S3DVertex(1,0,0, 1, 0, 0, clr, 1, 1)); // 4 (1)
buffer->Vertices.push_back(video::S3DVertex(1,1,0, 1, 0, 0, clr, 1, 0)); // 5 (2)
buffer->Vertices.push_back(video::S3DVertex(1,0,1, 1, 0, 0, clr, 0, 1)); // 6 (4)
buffer->Vertices.push_back(video::S3DVertex(1,1,1, 1, 0, 0, clr, 0, 0)); // 7 (5)
buffer->Vertices.push_back(video::S3DVertex(1,0,1, 0, 0, 1, clr, 0, 1)); // 8 (4)
buffer->Vertices.push_back(video::S3DVertex(1,1,1, 0, 0, 1, clr, 0, 0)); // 9 (5)
buffer->Vertices.push_back(video::S3DVertex(0,1,1, 0, 0, 1, clr, 1, 0)); // 10 (6)
buffer->Vertices.push_back(video::S3DVertex(0,0,1, 0, 0, 1, clr, 1, 1)); // 11 (7)
buffer->Vertices.push_back(video::S3DVertex(0,0,0, -1, 0, 0, clr, 0, 1)); // 12 (0)
buffer->Vertices.push_back(video::S3DVertex(0,1,0, -1, 0, 0, clr, 0, 0)); // 13 (3)
buffer->Vertices.push_back(video::S3DVertex(0,1,1, -1, 0, 0, clr, 1, 0)); // 14 (6)
buffer->Vertices.push_back(video::S3DVertex(0,0,1, -1, 0, 0, clr, 1, 1)); // 15 (7)
buffer->Vertices.push_back(video::S3DVertex(1,1,0, 0, 1, 0, clr, 1, 0)); // 16 (2)
buffer->Vertices.push_back(video::S3DVertex(1,1,1, 0, 1, 0, clr, 0, 0)); // 17 (5)
buffer->Vertices.push_back(video::S3DVertex(0,1,1, 0, 1, 0, clr, 0, 1)); // 18 (8)
buffer->Vertices.push_back(video::S3DVertex(0,1,0, 0, 1, 0, clr, 1, 1)); // 19 (9)
buffer->Vertices.push_back(video::S3DVertex(0,0,0, 0,-1, 0, clr, 0, 1)); // 20 (0)
buffer->Vertices.push_back(video::S3DVertex(0,0,1, 0,-1, 0, clr, 1, 1)); // 21 (7)
buffer->Vertices.push_back(video::S3DVertex(1,0,1, 0,-1, 0, clr, 1, 0)); // 22 (10)
buffer->Vertices.push_back(video::S3DVertex(1,0,0, 0,-1, 0, clr, 0, 0)); // 23 (11)
// Recalculate bounding box and set cube size
buffer->BoundingBox.reset(0,0,0);
for (u32 i=0; i<24; ++i)
{
buffer->Vertices[i].Pos -= core::vector3df(0.5f, 0.5f, 0.5f);
buffer->Vertices[i].Pos *= size;
buffer->BoundingBox.addInternalPoint(buffer->Vertices[i].Pos);
}
mesh->addMeshBuffer(buffer);
buffer->drop();
}
mesh->recalculateBoundingBox();
return mesh;

View File

@ -609,13 +609,14 @@ IVolumeLightSceneNode* CSceneManager::addVolumeLightSceneNode(
//! the returned pointer must not be dropped.
IMeshSceneNode* CSceneManager::addCubeSceneNode(f32 size, ISceneNode* parent,
s32 id, const core::vector3df& position,
const core::vector3df& rotation, const core::vector3df& scale)
const core::vector3df& rotation, const core::vector3df& scale,
ECUBE_MESH_TYPE type)
{
#ifdef _IRR_COMPILE_WITH_CUBE_SCENENODE_
if (!parent)
parent = this;
IMeshSceneNode* node = new CCubeSceneNode(size, parent, this, id, position, rotation, scale);
IMeshSceneNode* node = new CCubeSceneNode(size, parent, this, id, position, rotation, scale, type);
node->drop();
return node;

View File

@ -73,7 +73,8 @@ namespace scene
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)) IRR_OVERRIDE;
const core::vector3df& scale = core::vector3df(1.0f, 1.0f, 1.0f),
ECUBE_MESH_TYPE type=ECMT_1BUF_12VTX_NA) IRR_OVERRIDE;
//! Adds a sphere scene node to the scene.
virtual IMeshSceneNode* addSphereSceneNode(f32 radius=5.0f, s32 polyCount=16, ISceneNode* parent=0, s32 id=-1,