mirror of
https://github.com/luanti-org/luanti.git
synced 2025-07-07 16:48:40 +00:00
added plantlike luaentity
This commit is contained in:
parent
285f5a0259
commit
f0679969b2
3 changed files with 108 additions and 18 deletions
|
@ -1802,6 +1802,15 @@ public:
|
||||||
m_meshnode = smgr->addMeshSceneNode(mesh, NULL);
|
m_meshnode = smgr->addMeshSceneNode(mesh, NULL);
|
||||||
mesh->drop();
|
mesh->drop();
|
||||||
|
|
||||||
|
m_meshnode->setScale(v3f(1));
|
||||||
|
// Will be shown when we know the brightness
|
||||||
|
m_meshnode->setVisible(false);
|
||||||
|
} else if (m_prop->visual == "plant") {
|
||||||
|
infostream<<"LuaEntityCAO::addToScene(): plant"<<std::endl;
|
||||||
|
scene::IMesh *mesh = createPlantMesh(v3f(BS,BS,BS));
|
||||||
|
m_meshnode = smgr->addMeshSceneNode(mesh, NULL);
|
||||||
|
mesh->drop();
|
||||||
|
|
||||||
m_meshnode->setScale(v3f(1));
|
m_meshnode->setScale(v3f(1));
|
||||||
// Will be shown when we know the brightness
|
// Will be shown when we know the brightness
|
||||||
m_meshnode->setVisible(false);
|
m_meshnode->setVisible(false);
|
||||||
|
@ -1957,26 +1966,51 @@ public:
|
||||||
tsrc->getTextureRaw(texturestring));
|
tsrc->getTextureRaw(texturestring));
|
||||||
}
|
}
|
||||||
if(m_meshnode){
|
if(m_meshnode){
|
||||||
for (u32 i = 0; i < 6; ++i)
|
if (m_prop->visual == "plant") {
|
||||||
{
|
for (u32 i = 0; i < 4; ++i) {
|
||||||
std::string texturestring = "unknown_block.png";
|
std::string texturestring = "unknown_block.png";
|
||||||
if(m_prop->textures.size() > i)
|
if(m_prop->textures.size() > 0)
|
||||||
texturestring = m_prop->textures[i];
|
texturestring = m_prop->textures[0];
|
||||||
texturestring += mod;
|
texturestring += mod;
|
||||||
AtlasPointer ap = tsrc->getTexture(texturestring);
|
AtlasPointer ap = tsrc->getTexture(texturestring);
|
||||||
|
|
||||||
// Get the tile texture and atlas transformation
|
// Get the tile texture and atlas transformation
|
||||||
video::ITexture* atlas = ap.atlas;
|
video::ITexture* atlas = ap.atlas;
|
||||||
v2f pos = ap.pos;
|
v2f pos = ap.pos;
|
||||||
v2f size = ap.size;
|
v2f size = ap.size;
|
||||||
|
|
||||||
// Set material flags and texture
|
// Set material flags and texture
|
||||||
video::SMaterial& material = m_meshnode->getMaterial(i);
|
video::SMaterial& material = m_meshnode->getMaterial(i);
|
||||||
material.setFlag(video::EMF_LIGHTING, false);
|
material.setFlag(video::EMF_LIGHTING, false);
|
||||||
material.setFlag(video::EMF_BILINEAR_FILTER, false);
|
material.setFlag(video::EMF_BILINEAR_FILTER, false);
|
||||||
material.setTexture(0, atlas);
|
material.setTexture(0, atlas);
|
||||||
material.getTextureMatrix(0).setTextureTranslate(pos.X, pos.Y);
|
material.getTextureMatrix(0).setTextureTranslate(pos.X, pos.Y);
|
||||||
material.getTextureMatrix(0).setTextureScale(size.X, size.Y);
|
material.getTextureMatrix(0).setTextureScale(size.X, size.Y);
|
||||||
|
material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
for (u32 i = 0; i < 6; ++i) {
|
||||||
|
std::string texturestring = "unknown_block.png";
|
||||||
|
if(m_prop->textures.size() > i)
|
||||||
|
texturestring = m_prop->textures[i];
|
||||||
|
texturestring += mod;
|
||||||
|
AtlasPointer ap = tsrc->getTexture(texturestring);
|
||||||
|
|
||||||
|
// Get the tile texture and atlas transformation
|
||||||
|
video::ITexture* atlas = ap.atlas;
|
||||||
|
v2f pos = ap.pos;
|
||||||
|
v2f size = ap.size;
|
||||||
|
|
||||||
|
// Set material flags and texture
|
||||||
|
video::SMaterial& material = m_meshnode->getMaterial(i);
|
||||||
|
material.setFlag(video::EMF_LIGHTING, false);
|
||||||
|
material.setFlag(video::EMF_BILINEAR_FILTER, false);
|
||||||
|
material.setTexture(0, atlas);
|
||||||
|
material.getTextureMatrix(0).setTextureTranslate(pos.X, pos.Y);
|
||||||
|
material.getTextureMatrix(0).setTextureScale(size.X, size.Y);
|
||||||
|
material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
46
src/mesh.cpp
46
src/mesh.cpp
|
@ -82,6 +82,52 @@ scene::IAnimatedMesh* createCubeMesh(v3f scale)
|
||||||
return anim_mesh;
|
return anim_mesh;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
scene::IAnimatedMesh* createPlantMesh(v3f scale)
|
||||||
|
{
|
||||||
|
video::SColor c(255,255,255,255);
|
||||||
|
video::S3DVertex vertices[16] =
|
||||||
|
{
|
||||||
|
// Plane 1 Front
|
||||||
|
video::S3DVertex(-0.5,-0.5,-0.5, 0.5,0,-0.5, c, 0,1),
|
||||||
|
video::S3DVertex(-0.5,+0.5,-0.5, 0.5,0,-0.5, c, 0,0),
|
||||||
|
video::S3DVertex(+0.5,+0.5,+0.5, 0.5,0,-0.5, c, 1,0),
|
||||||
|
video::S3DVertex(+0.5,-0.5,+0.5, 0.5,0,-0.5, c, 1,1),
|
||||||
|
// Plane 1 Back
|
||||||
|
video::S3DVertex(+0.5,-0.5,+0.5, -0.5,0,0.5, c, 1,1),
|
||||||
|
video::S3DVertex(+0.5,+0.5,+0.5, -0.5,0,0.5, c, 1,0),
|
||||||
|
video::S3DVertex(-0.5,+0.5,-0.5, -0.5,0,0.5, c, 0,0),
|
||||||
|
video::S3DVertex(-0.5,-0.5,-0.5, -0.5,0,0.5, c, 0,1),
|
||||||
|
|
||||||
|
// Plane 2 Front
|
||||||
|
video::S3DVertex(-0.5,-0.5,+0.5, -0.5,0,-0.5, c, 1,1),
|
||||||
|
video::S3DVertex(-0.5,+0.5,+0.5, -0.5,0,-0.5, c, 1,0),
|
||||||
|
video::S3DVertex(+0.5,+0.5,-0.5, -0.5,0,-0.5, c, 0,0),
|
||||||
|
video::S3DVertex(+0.5,-0.5,-0.5, -0.5,0,-0.5, c, 0,1),
|
||||||
|
|
||||||
|
// Plane 2 Back
|
||||||
|
video::S3DVertex(+0.5,-0.5,-0.5, 0.5,0,0.5, c, 0,1),
|
||||||
|
video::S3DVertex(+0.5,+0.5,-0.5, 0.5,0,0.5, c, 0,0),
|
||||||
|
video::S3DVertex(-0.5,+0.5,+0.5, 0.5,0,0.5, c, 1,0),
|
||||||
|
video::S3DVertex(-0.5,-0.5,+0.5, 0.5,0,0.5, c, 1,1)
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
u16 indices[6] = {0,1,2,2,3,0};
|
||||||
|
|
||||||
|
scene::SMesh *mesh = new scene::SMesh();
|
||||||
|
for (u32 i=0; i<4; ++i)
|
||||||
|
{
|
||||||
|
scene::IMeshBuffer *buf = new scene::SMeshBuffer();
|
||||||
|
buf->append(vertices + 4 * i, 4, indices, 6);
|
||||||
|
mesh->addMeshBuffer(buf);
|
||||||
|
buf->drop();
|
||||||
|
}
|
||||||
|
scene::SAnimatedMesh *anim_mesh = new scene::SAnimatedMesh(mesh);
|
||||||
|
mesh->drop();
|
||||||
|
scaleMesh(anim_mesh, scale); // also recalculates bounding box
|
||||||
|
return anim_mesh;
|
||||||
|
}
|
||||||
|
|
||||||
static scene::IAnimatedMesh* extrudeARGB(u32 twidth, u32 theight, u8 *data)
|
static scene::IAnimatedMesh* extrudeARGB(u32 twidth, u32 theight, u8 *data)
|
||||||
{
|
{
|
||||||
const s32 argb_wstep = 4 * twidth;
|
const s32 argb_wstep = 4 * twidth;
|
||||||
|
|
10
src/mesh.h
10
src/mesh.h
|
@ -41,6 +41,16 @@ scene::IAnimatedMesh* createCubeMesh(v3f scale);
|
||||||
scene::IAnimatedMesh* createExtrudedMesh(video::ITexture *texture,
|
scene::IAnimatedMesh* createExtrudedMesh(video::ITexture *texture,
|
||||||
video::IVideoDriver *driver, v3f scale);
|
video::IVideoDriver *driver, v3f scale);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
Create a new cube mesh.
|
||||||
|
Vertices are at (+-scale.X/2, +-scale.Y/2, +-scale.Z/2).
|
||||||
|
|
||||||
|
The resulting mesh has 6 materials (up, down, right, left, back, front)
|
||||||
|
which must be defined by the caller.
|
||||||
|
*/
|
||||||
|
scene::IAnimatedMesh* createPlantMesh(v3f scale);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Multiplies each vertex coordinate by the specified scaling factors
|
Multiplies each vertex coordinate by the specified scaling factors
|
||||||
(componentwise vector multiplication).
|
(componentwise vector multiplication).
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue