]> git.lizzy.rs Git - minetest.git/blobdiff - src/tile.cpp
inventorycube: use all three specified textures; also moved mesh creation / modificat...
[minetest.git] / src / tile.cpp
index bf0e264c6424ad09e02e8cf2e516481d13b3241a..89f3451973e078dc8b47fa10916110df8e891e3e 100644 (file)
@@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "filesys.h"
 #include "utility.h"
 #include "settings.h"
+#include "mesh.h"
 #include <ICameraSceneNode.h>
 #include "log.h"
 #include "mapnode.h" // For texture atlas making
@@ -332,7 +333,7 @@ class TextureSource : public IWritableTextureSource
        // Gets a separate texture
        video::ITexture* getTextureRaw(const std::string &name)
        {
-               AtlasPointer ap = getTexture(name);
+               AtlasPointer ap = getTexture(name + "^[forcesingle");
                return ap.atlas;
        }
 
@@ -906,10 +907,14 @@ void TextureSource::buildMainAtlas(class IGameDef *gamedef)
                for(u32 j=0; j<xwise_tiling; j++)
                {
                        // Copy the copy to the atlas
-                       img2->copyToWithAlpha(atlas_img,
+                       /*img2->copyToWithAlpha(atlas_img,
                                        pos_in_atlas + v2s32(j*dim.Width,0),
                                        core::rect<s32>(v2s32(0,0), dim),
                                        video::SColor(255,255,255,255),
+                                       NULL);*/
+                       img2->copyTo(atlas_img,
+                                       pos_in_atlas + v2s32(j*dim.Width,0),
+                                       core::rect<s32>(v2s32(0,0), dim),
                                        NULL);
                }
 
@@ -1166,6 +1171,15 @@ bool generate_image(std::string part_of_name, video::IImage *& baseimg,
                */
                if(part_of_name == "[forcesingle")
                {
+                       // If base image is NULL, create a random color
+                       if(baseimg == NULL)
+                       {
+                               core::dimension2d<u32> dim(1,1);
+                               baseimg = driver->createImage(video::ECF_A8R8G8B8, dim);
+                               assert(baseimg);
+                               baseimg->setPixel(0,0, video::SColor(255,myrand()%256,
+                                               myrand()%256,myrand()%256));
+                       }
                }
                /*
                        [crackN
@@ -1455,11 +1469,14 @@ bool generate_image(std::string part_of_name, video::IImage *& baseimg,
                        assert(img_top && img_left && img_right);
 
                        // Create textures from images
-                       // TODO: Use them all
                        video::ITexture *texture_top = driver->addTexture(
                                        (imagename_top + "__temp__").c_str(), img_top);
-                       assert(texture_top);
-                       
+                       video::ITexture *texture_left = driver->addTexture(
+                                       (imagename_left + "__temp__").c_str(), img_left);
+                       video::ITexture *texture_right = driver->addTexture(
+                                       (imagename_right + "__temp__").c_str(), img_right);
+                       assert(texture_top && texture_left && texture_right);
+
                        // Drop images
                        img_top->drop();
                        img_left->drop();
@@ -1486,17 +1503,24 @@ bool generate_image(std::string part_of_name, video::IImage *& baseimg,
                                Create scene:
                                - An unit cube is centered at 0,0,0
                                - Camera looks at cube from Y+, Z- towards Y-, Z+
-                               NOTE: Cube has to be changed to something else because
-                               the textures cannot be set individually (or can they?)
                        */
 
-                       scene::ISceneNode* cube = smgr->addCubeSceneNode(1.0, NULL, -1,
-                                       v3f(0,0,0), v3f(0, 45, 0));
+                       scene::IMesh* cube = createCubeMesh(v3f(1, 1, 1));
+                       setMeshColor(cube, video::SColor(255, 255, 255, 255));
+
+                       scene::IMeshSceneNode* cubenode = smgr->addMeshSceneNode(cube, NULL, -1, v3f(0,0,0), v3f(0,45,0), v3f(1,1,1), true);
+                       cube->drop();
+
                        // Set texture of cube
-                       cube->setMaterialTexture(0, texture_top);
-                       //cube->setMaterialFlag(video::EMF_LIGHTING, false);
-                       cube->setMaterialFlag(video::EMF_ANTI_ALIASING, false);
-                       cube->setMaterialFlag(video::EMF_BILINEAR_FILTER, false);
+                       cubenode->getMaterial(0).setTexture(0, texture_top);
+                       cubenode->getMaterial(1).setTexture(0, texture_top);
+                       cubenode->getMaterial(2).setTexture(0, texture_right);
+                       cubenode->getMaterial(3).setTexture(0, texture_right);
+                       cubenode->getMaterial(4).setTexture(0, texture_left);
+                       cubenode->getMaterial(5).setTexture(0, texture_left);
+                       cubenode->setMaterialFlag(video::EMF_LIGHTING, true);
+                       cubenode->setMaterialFlag(video::EMF_ANTI_ALIASING, true);
+                       cubenode->setMaterialFlag(video::EMF_BILINEAR_FILTER, true);
 
                        scene::ICameraSceneNode* camera = smgr->addCameraSceneNode(0,
                                        v3f(0, 1.0, -1.5), v3f(0, 0, 0));
@@ -1506,7 +1530,7 @@ bool generate_image(std::string part_of_name, video::IImage *& baseimg,
                        camera->setProjectionMatrix(pm, true);
 
                        /*scene::ILightSceneNode *light =*/ smgr->addLightSceneNode(0,
-                                       v3f(-50, 100, 0), video::SColorf(0.5,0.5,0.5), 1000);
+                                       v3f(-50, 100, -75), video::SColorf(0.5,0.5,0.5), 1000);
 
                        smgr->setAmbientLight(video::SColorf(0.2,0.2,0.2));
 
@@ -1527,8 +1551,9 @@ bool generate_image(std::string part_of_name, video::IImage *& baseimg,
                        driver->setRenderTarget(0, true, true, 0);
 
                        // Free textures of images
-                       // TODO: When all are used, free them all
                        driver->removeTexture(texture_top);
+                       driver->removeTexture(texture_left);
+                       driver->removeTexture(texture_right);
                        
                        // Create image of render target
                        video::IImage *image = driver->createImage(rtt, v2s32(0,0), dim);