/*
-Minetest-c55
-Copyright (C) 2010-2011 celeron55, Perttu Ahola <celeron55@gmail.com>
+Minetest
+Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
+GNU Lesser General Public License for more details.
-You should have received a copy of the GNU General Public License along
+You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "mesh.h"
+#include "debug.h"
+#include "log.h"
+#include <iostream>
#include <IAnimatedMesh.h>
#include <SAnimatedMesh.h>
{
scene::IMeshBuffer *buf = new scene::SMeshBuffer();
buf->append(vertices + 4 * i, 4, indices, 6);
+ // Set default material
+ buf->getMaterial().setFlag(video::EMF_LIGHTING, false);
+ buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false);
+ buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
+ // Add mesh buffer to mesh
mesh->addMeshBuffer(buf);
buf->drop();
}
+
scene::SAnimatedMesh *anim_mesh = new scene::SAnimatedMesh(mesh);
mesh->drop();
scaleMesh(anim_mesh, scale); // also recalculates bounding box
}
}
+ delete[] solidity;
+
// Add to mesh
scene::SMesh *mesh = new scene::SMesh();
mesh->addMeshBuffer(buf);
// img1 is in the texture's color format, convert to 8-bit ARGB
video::IImage *img2 = driver->createImage(video::ECF_A8R8G8B8, size);
- if (img2 != NULL)
+ if (img2 == NULL)
{
- img1->copyTo(img2);
img1->drop();
-
- mesh = extrudeARGB(size.Width, size.Height, (u8*) img2->lock());
- img2->unlock();
- img2->drop();
+ return NULL;
}
+
+ img1->copyTo(img2);
img1->drop();
+ mesh = extrudeARGB(size.Width, size.Height, (u8*) img2->lock());
+ img2->unlock();
+ img2->drop();
}
+
+ // Set default material
+ mesh->getMeshBuffer(0)->getMaterial().setTexture(0, texture);
+ mesh->getMeshBuffer(0)->getMaterial().setFlag(video::EMF_LIGHTING, false);
+ mesh->getMeshBuffer(0)->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false);
+ mesh->getMeshBuffer(0)->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
+
scaleMesh(mesh, scale); // also recalculates bounding box
return mesh;
}
mesh->setBoundingBox(bbox);
}
+void translateMesh(scene::IMesh *mesh, v3f vec)
+{
+ if(mesh == NULL)
+ return;
+
+ core::aabbox3d<f32> bbox;
+ bbox.reset(0,0,0);
+
+ u16 mc = mesh->getMeshBufferCount();
+ for(u16 j=0; j<mc; j++)
+ {
+ scene::IMeshBuffer *buf = mesh->getMeshBuffer(j);
+ video::S3DVertex *vertices = (video::S3DVertex*)buf->getVertices();
+ u16 vc = buf->getVertexCount();
+ for(u16 i=0; i<vc; i++)
+ {
+ vertices[i].Pos += vec;
+ }
+ buf->recalculateBoundingBox();
+
+ // calculate total bounding box
+ if(j == 0)
+ bbox = buf->getBoundingBox();
+ else
+ bbox.addInternalBox(buf->getBoundingBox());
+ }
+ mesh->setBoundingBox(bbox);
+}
+
void setMeshColor(scene::IMesh *mesh, const video::SColor &color)
{
if(mesh == NULL)