Thin Transparent Mesh layer

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
mnunesvsc
Posts: 22
Joined: Sun May 28, 2006 9:04 pm
Contact:

Thin Transparent Mesh layer

Post by mnunesvsc »

For someone who can could help, i am trying to create a thin mesh layer to display altitude and some others infos and nothing happens after all tryies, here follows the code, if some helpfull soul could lend me a hand i appreciate.

here follows the class

Code: Select all

 
/*
------------------------------------->
    Copyright 2007  Marcelo Nunes
------------------------------------->
*/
#include "ILineNode.h"
 
//
ILineNode::ILineNode(core::vector3df center, f32 radius, core::vector3df normal, ISceneNode* parent, ISceneManager* smgr, s32 id):ISceneNode(parent,smgr,id)
{
    Driver = SceneManager->getVideoDriver();
 
    // Set the color
    this->lAlpha = 32;
    this->lColor = video::SColor(this->lAlpha, 0, 0xC0, 0);
 
    if(Parent) Parent->addChild(this);
    updateAbsolutePosition();
    createLine(center, radius, normal);
    // AutomaticCullingState = EAC_OFF; //   _FRUSTUM_BOX;
}
 
//
void ILineNode::OnRegisterSceneNode()
{
  if(IsVisible) SceneManager->registerNodeForRendering(this);
  ISceneNode::OnRegisterSceneNode();
}
 
//
void ILineNode::render()
{
    // Prep to render
    Driver->setMaterial(Material);
    Driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
    u16 indices[] = {
            0,1,2
            ,1,2,0
            ,2,0,1
            ,0,1,2
    };
 
    // render
    Driver->drawVertexPrimitiveList(&lstVertices[0], lstVertices.size(), &indices[0], 3, irr::video::EVT_STANDARD, irr::scene::EPT_TRIANGLE_FAN, video::EIT_16BIT); // scene::EPT_TRIANGLES
}
 
//
const core::aabbox3d<f32>& ILineNode::getBoundingBox() const
{
    return Box;
}
 
//
u32 ILineNode::getMaterialCount()
{
    return 1;
}
 
//
video::SMaterial& ILineNode::getMaterial(u32 i)
{
    return this->Material;
}
 
// Set material alpha
void ILineNode::setMaterialAlpha(u32 iAlpha)
{
    this->lAlpha = iAlpha;
    // Set the color
    this->lColor = video::SColor(this->lAlpha, 0, 0xFE, 0);
}
 
//
void ILineNode::setMaterial(video::SMaterial newMaterial)
{
    this->Material = newMaterial;
}
 
//
void ILineNode::setColor(video::SColor iColor)
{
    // Change color
    this->lColor = iColor;
}
 
//
void ILineNode::createLine(core::vector3df center, f32 radius, core::vector3df normal)
{
    //
    normal.normalize();
 
    //
    lstIndices.clear();
    lstVertices.clear();
 
    //
    Box.reset(center);
 
    //
    video::S3DVertex Vertices[4];
 
    // sets the color..
    // video::SColor color = video::SColor(0x0A, 0, 0xE6, 0);
 
    //
    Vertices[0] = video::S3DVertex(center.X, center.Y, center.Z, 1,1,0, video::SColor(255,0,255,255), 0, 1);
    Vertices[0].Color = this->lColor;
    Vertices[1].Color.setAlpha(this->lAlpha);
        lstVertices.push_back(Vertices[0]);
        lstIndices.push_back(lstVertices.size());
    Vertices[1] = video::S3DVertex(center.X, center.Y - radius, center.Z, 1,1,0, video::SColor(255,0,255,255), 0, 1);
    Vertices[1].Color = this->lColor;
    Vertices[1].Color.setAlpha(this->lAlpha);
        lstVertices.push_back(Vertices[1]);
        lstIndices.push_back(lstVertices.size());
    Vertices[2] = video::S3DVertex(center.X, center.Y - radius, center.Z + 10, 1,1,0, video::SColor(255,0,255,255), 0, 1);
    Vertices[2].Color = this->lColor;
    Vertices[2].Color.setAlpha(this->lAlpha);
        lstVertices.push_back(Vertices[2]);
        lstIndices.push_back(lstVertices.size());
 
    //
    for (s32 i=0; i<3; ++i)
        Box.addInternalPoint(Vertices[i].Pos);
 
    Radius = radius;
    Center = center;
    Normal = normal;
}
 

and here how to use

Code: Select all

 
    lineNode = new ILineNode(core::vector3df(0, 0, 0), 150, core::vector3df(0,1,0), scenemgr->getRootSceneNode(), scenemgr);
 

[img]
https://www.facebook.com/photo.php?fbid ... =3&theater
[/img]
CuteAlien
Admin
Posts: 9651
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Thin Transparent Mesh layer

Post by CuteAlien »

Given the name ILineNode I suppose you want to draw a line with 2 triangles (aka 4 corners)?
Thought you only create 3 corners then... so probably not. What exactly is the plan?
lstIndices doesn't seem to be used. I suppose lstVertices is basically like Vertices, just a dynamic array (and I hope not a list...)?

In drawVertexPrimitiveList you use EPT_TRIANGLE_STRIP. Which creates a triangle for the first 3 indices. And then one more triangle for each additional index (using the the 2 previous indices for the other 2 points of the triangle). So the number of primitives (number of triangles in this case) you have to pass in there is indexCount-2. You only pass 3 as value - so it would you use the first 5 indices to create 3 triangles. So you get the 3 triangles for vertices (0,1,2), (1,2,1) and (2,1,2). The last 2 being not being real triangles as 2 corners end up on the same point. Which means ... you should get a single triangle.

Which kinda looks like what you get :-)

Maybe easier to use EPT_TRIANGLES. Create 4 vertices (not 3). And indices for your 2 primtives are then (0,1,2) and (2,3,0).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
mnunesvsc
Posts: 22
Joined: Sun May 28, 2006 9:04 pm
Contact:

Re: Thin Transparent Mesh layer

Post by mnunesvsc »

Thanks for the quickly response.

Yes the name was bad formed, but the problem is i need the 'line' or rather the triangle i draw, and it is draw the way i need it;

[img]
http://35.198.25.105/img/Spiral%20Issue.JPG
[/img]

to be transparent green, showing all behind him like on this one

http://irrlicht.sourceforge.net/forum/v ... =1&t=51841

can you help me it is very important, because i will use on a game to be able to track enemy fire on a isometric view

thanks in advanced.
CuteAlien
Admin
Posts: 9651
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Thin Transparent Mesh layer

Post by CuteAlien »

So the only thing you are missing is that you want the green to be half-transparent instead of solid?
You need to set the MaterialType of your material to video::EMT_TRANSPARENT_VERTEX_ALPHA.
Then you can set the vertex-colors to some alpha value.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
mnunesvsc
Posts: 22
Joined: Sun May 28, 2006 9:04 pm
Contact:

Re: Thin Transparent Mesh layer

Post by mnunesvsc »

Well that is what i am doing, but are not working here is the code, can you appoint me what i am doing wrong ?

Code: Select all

 
    SMaterial NM;
    // NM.EmissiveColor = SColor(0x10, 0, 0xCC,0);
    // NM.ColorMaterial = SColor(0x0A, 0, 0xCC,0);
    NM.Lighting = false;
    NM.Thickness = 3.0f;
    NM.FrontfaceCulling = false;
    NM.BackfaceCulling = false;
    //// NM.Wireframe = true;
    NM.setFlag(EMF_LIGHTING, false);
    NM.setFlag(EMF_NORMALIZE_NORMALS, true);
    // NM.setFlag(video::EMF_BLEND_OPERATION, true);
    // NM.setFlag(irr::video::EMF_BLEND_OPERATION, true);
    // NM.ColorMaterial = 100;
    //
    // iMat = irr::video::EMT_ONETEXTURE_BLEND; // video::EMT_TRANSPARENT_VERTEX_ALPHA;
    //
    // NM.MaterialType = irr::video::EMT_ONETEXTURE_BLEND; // (irr::video::E_MATERIAL_TYPE)iMat;
    // NM.MaterialTypeParam = video::pack_textureBlendFunc(video::EBF_SRC_ALPHA, video::EBF_ONE_MINUS_SRC_ALPHA, video::EMFN_MODULATE_1X, video::EAS_TEXTURE | video::EAS_VERTEX_COLOR);
    //// NM.MaterialTypeParam = video::pack_textureBlendFunc(video::EBF_SRC_ALPHA, video::EAS_VERTEX_COLOR);
    NM.MaterialTypeParam = irr::video::pack_textureBlendFunc(irr::video::EBF_SRC_ALPHA, irr::video::EBF_ONE_MINUS_SRC_ALPHA, irr::video::EMFN_MODULATE_1X, irr::video::EAS_VERTEX_COLOR);
 
    // NM.setMaterialTexture(0, device->getVideoDriver()->getTexture("../../media/smoke.bmp"));
    // NM.MaterialType = irr::video::EMT_TRANSPARENT_ADD_COLOR; //   EMT_TRANSPARENT_VERTEX_ALPHA;
    NM.MaterialType = irr::video::EMT_TRANSPARENT_VERTEX_ALPHA;
    iMat = NM.MaterialType;
 
    // NM.ZBuffer = irr::video::ECFN_ALWAYS;
    NM.AmbientColor.setAlpha(127);
    NM.DiffuseColor.setAlpha(127);
    NM.SpecularColor.setAlpha(127);
    NM.EmissiveColor.setAlpha(127);
    NM.AmbientColor = irr::video::SColor(0, 0, 0xC0, 0);
 
    // NM.MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA;
    // NM.setFlag(EMF_BACK_FACE_CULLING, false);
    // NM.setMaterialTexture(0, driver->getTexture("../../media/fire.bmp"));
    // NM.setMaterialType(video::EMT_TRANSPARENT_VERTEX_ALPHA);
    // ps->setMaterialFlag(video::EMF_LIGHTING, false);
    // setMaterialType(video::EMT_TRANSPARENT_VERTEX_ALPHA);
 
    circleNode->setMaterial(NM);
    circleNode->setColor(SColor(127, 0, 0xC0, 0));
    // circleNode->setMaterialFlag(video::EMF_LIGHTING, false);
    // circleNode->setMaterialFlag(video::EMF_BACK_FACE_CULLING, false);
    // circleNode->getMaterial(0).MaterialTypeParam = 0.01f;
    circleNode->setMaterialType(video::EMT_TRANSPARENT_VERTEX_ALPHA);     // Allows alpha channel to work properly in .tga file
    // meshMnp->setVertexColorAlpha(circleNode->getMesh(), 80);
 
    // circleNode->setMaterialFlag(video::EMF_LIGHTING, false);
    // circleNode->setMaterialFlag(video::EMF_ZWRITE_ENABLE, false);
    // circleNode->setMaterialType(video::EMT_TRANSPARENT_VERTEX_ALPHA);
    // circleNode->setMaterialFlag( irr::video::EMF_FRONT_FACE_CULLING, false);
    // circleNode->setMaterialFlag(video::EMF_BACK_FACE_CULLING, false);
    // circleNode->setMaterialFlag(video::EMF_BLEND_OPERATION, true);
    // circleNode->setMaterialFlag(EMF_LIGHTING, false);
    // circleNode->setMaterialFlag(video::EMT_TRANSPARENT_VERTEX_ALPHA);
 
    lineNode->setMaterial(NM);
    lineNode->setColor(SColor(127, 0, 0xC0, 0));
    // meshMnp->setVertexColorAlpha(lineNode->getMesh(), 80);
    ////lineNode->SVertexColorSetAlphaManipulator(127);
    // lineNode->setMaterialFlag(video::EMF_LIGHTING, false);
    // lineNode->setMaterialFlag(video::EMF_ZWRITE_ENABLE, false);
    lineNode->setMaterialType(video::EMT_TRANSPARENT_VERTEX_ALPHA);
 
as you can see i tryed many options, commented, but no one seens to work
CuteAlien
Admin
Posts: 9651
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Thin Transparent Mesh layer

Post by CuteAlien »

Forget about the material-colors. This material-type is about vertex-colors. (I'm not sure if there is any fixed-function material which cares about material-color-alpha's like that, probably not, but would have to experiment).

So it's about the color your set in your "Vertices" variable in ILineNode. I don't know anything about your circleNode as I have no code for that. Setting lighting to false for now makes sense as well (it will also work with lighting, but let's get it working first before starting with lights).

Do not set the pack_textureBlendFunc for now. It's not needed for this (it likely can be used for this as well, but let's keep things simple).

If it still does not work, then I need code which I can compile to reproduce this. I can only guess around when I don't see the full code.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
mnunesvsc
Posts: 22
Joined: Sun May 28, 2006 9:04 pm
Contact:

Re: Thin Transparent Mesh layer

Post by mnunesvsc »

Well i created a project, based on the example 3 custom scene here follow the code, just put on a folder, on the samples of irrlicht to be able to see the media path and compile all

i am using Ming with codeblocks, but on visual studio the problem is the same, the vertex only render on the white back ground, and all is redered in front of him, thanks in advance

main.cpp

Code: Select all

 
/** Example 003 Custom SceneNode */
#include <irrlicht.h>
#include "driverChoice.h"
#include "ILineNode.h"
 
using namespace irr;
 
#ifdef _MSC_VER
#pragma comment(lib, "Irrlicht.lib")
#endif
 
class CSampleSceneNode : public scene::ISceneNode
{
 
    /*
    First, we declare some member variables:
    The bounding box, 4 vertices, and the material of the tetrahedron.
    */
    core::aabbox3d<f32> Box;
    video::S3DVertex Vertices[4];
    video::SMaterial Material;
 
public:
 
    /*
    The parameters of the constructor specify the parent of the scene node,
    a pointer to the scene manager, and an id of the scene node.
    In the constructor we call the parent class' constructor,
    set some properties of the material, and create the 4 vertices of
    the tetrahedron.
    */
 
    CSampleSceneNode(scene::ISceneNode* parent, scene::ISceneManager* mgr, s32 id)
        : scene::ISceneNode(parent, mgr, id)
    {
        Material.Wireframe = false;
        Material.Lighting = false;
 
        Vertices[0] = video::S3DVertex(0,0,10, 1,1,0,
                video::SColor(255,0,255,255), 0, 1);
        Vertices[1] = video::S3DVertex(10,0,-10, 1,0,0,
                video::SColor(255,255,0,255), 1, 1);
        Vertices[2] = video::S3DVertex(0,20,0, 0,1,1,
                video::SColor(255,255,255,0), 1, 0);
        Vertices[3] = video::S3DVertex(-10,0,-10, 0,0,1,
                video::SColor(255,0,255,0), 0, 0);
 
        Box.reset(Vertices[0].Pos);
        for (s32 i=1; i<3; ++i)
            Box.addInternalPoint(Vertices[i].Pos);
    }
 
    virtual void OnRegisterSceneNode()
    {
        if (IsVisible)
            SceneManager->registerNodeForRendering(this);
 
        ISceneNode::OnRegisterSceneNode();
    }
 
    /*
    In the render() method most of the interesting stuff happens: The
    Scene node renders itself. We override this method and draw the
    tetrahedron.
    */
    virtual void render()
    {
        /* Indices into the 'Vertices' array. A triangle needs 3 vertices
        so you have to pass the 3 corresponding indices for each triangle to
        tell which of the vertices should be used for it.   */
        u16 indices[] = {   0,2,3, 2,1,3, 1,0,3, 2,0,1  };
        video::IVideoDriver* driver = SceneManager->getVideoDriver();
 
        driver->setMaterial(Material);
        driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
        driver->drawVertexPrimitiveList(&Vertices[0], 3, &indices[0], 3, video::EVT_STANDARD, scene::EPT_TRIANGLES, video::EIT_16BIT);
        // driver->draw3DLine(core::vector3df(0,0,0), core::vector3df(0,0,0), irr::video::SColor(0xFF, 0xFF, 0xFF, 0xFF) );
    }
 
    /*
    And finally we create three small additional methods.
    irr::scene::ISceneNode::getBoundingBox() returns the bounding box of
    this scene node, irr::scene::ISceneNode::getMaterialCount() returns the
    amount of materials in this scene node (our tetrahedron only has one
    material), and irr::scene::ISceneNode::getMaterial() returns the
    material at an index. Because we have only one material, we can
    return that and assume that no one ever calls getMaterial() with an index
    greater than 0.
    */
    virtual const core::aabbox3d<f32>& getBoundingBox() const
    {
        return Box;
    }
 
    virtual u32 getMaterialCount() const
    {
        return 1;
    }
 
    virtual video::SMaterial& getMaterial(u32 i)
    {
        return Material;
    }
};
 
ILineNode* lineNode;
 
/*
That's it. The Scene node is done. Now we start the engine,
create the scene node and a camera, and look at the result.
*/
int main()
{
    // ask user for driver
    video::E_DRIVER_TYPE driverType=driverChoiceConsole();
    if (driverType==video::EDT_COUNT)
        return 1;
 
    // create device
    IrrlichtDevice *device = createDevice(driverType,
            core::dimension2d<u32>(960, 540), 32, false);
 
 
 
    if (device == 0)
        return 1; // could not create selected driver.
 
    // set window caption, get some pointers, create a camera
 
    device->setWindowCaption(L"Custom Scene Node - Irrlicht Engine Demo");
 
    video::IVideoDriver* driver = device->getVideoDriver();
    scene::ISceneManager* smgr = device->getSceneManager();
 
    // smgr->addCameraSceneNode(0, core::vector3df(0,-40,0), core::vector3df(0,0,0));
 
    //
    SKeyMap keyMap[4];
    keyMap[0].Action = EKA_MOVE_FORWARD;
    keyMap[0].KeyCode = KEY_KEY_W;
    keyMap[1].Action = EKA_MOVE_BACKWARD;
    keyMap[1].KeyCode = KEY_KEY_S;
    keyMap[2].Action = EKA_STRAFE_LEFT;
    keyMap[2].KeyCode = KEY_KEY_A;
    keyMap[3].Action = EKA_STRAFE_RIGHT;
    keyMap[3].KeyCode = KEY_KEY_D;
 
    // add a first person shooter style user controlled camera
    irr::scene::ICameraSceneNode * cameraNode = smgr->addCameraSceneNodeFPS( NULL, 20.0f, 0.02f, -1, keyMap, 4);
    cameraNode->setPosition(vector3df(0,-10, -30));
 
    IAnimatedMesh* hillPlaneMesh = smgr->addHillPlaneMesh( "GROUND",
        core::dimension2d<f32>(10,10),
        core::dimension2d<u32>(200,200), 0, 0,
        core::dimension2d<f32>(0,0),
        core::dimension2d<f32>(10,10));
 
    ISceneNode* planeNode = smgr->addAnimatedMeshSceneNode(hillPlaneMesh);
    planeNode->setMaterialTexture(0, driver->getTexture("../../media/stones.jpg"));
    planeNode->setMaterialFlag(video::EMF_LIGHTING, false);
    planeNode->setPosition(core::vector3df(0, -50, 0));
 
    // Linenode
    lineNode = new ILineNode(core::vector3df(0, 0, 0), 250, 150, core::vector3df(0,1,0), smgr->getRootSceneNode(), smgr);
 
    //
    SMaterial NM;
    // NM.EmissiveColor = SColor(0x10, 0, 0xCC,0);
    // NM.ColorMaterial = SColor(0x0A, 0, 0xCC,0);
    NM.Lighting = false;
    NM.Thickness = 3.0f;
    NM.FrontfaceCulling = false;
    NM.BackfaceCulling = false;
    //// NM.Wireframe = true;
    NM.setFlag(EMF_LIGHTING, false);
    NM.setFlag(EMF_NORMALIZE_NORMALS, true);
    // NM.setFlag(video::EMF_BLEND_OPERATION, true);
    // NM.setFlag(irr::video::EMF_BLEND_OPERATION, true);
    // NM.ColorMaterial = 100;
    //
    // iMat = irr::video::EMT_ONETEXTURE_BLEND; // video::EMT_TRANSPARENT_VERTEX_ALPHA;
    //
    // NM.MaterialType = irr::video::EMT_ONETEXTURE_BLEND; // (irr::video::E_MATERIAL_TYPE)iMat;
    // NM.MaterialTypeParam = video::pack_textureBlendFunc(video::EBF_SRC_ALPHA, video::EBF_ONE_MINUS_SRC_ALPHA, video::EMFN_MODULATE_1X, video::EAS_TEXTURE | video::EAS_VERTEX_COLOR);
    //// NM.MaterialTypeParam = video::pack_textureBlendFunc(video::EBF_SRC_ALPHA, video::EAS_VERTEX_COLOR);
    NM.MaterialTypeParam = irr::video::pack_textureBlendFunc(irr::video::EBF_SRC_ALPHA, irr::video::EBF_ONE_MINUS_SRC_ALPHA, irr::video::EMFN_MODULATE_1X, irr::video::EAS_VERTEX_COLOR);
 
    // NM.setMaterialTexture(0, device->getVideoDriver()->getTexture("../../media/smoke.bmp"));
    // NM.MaterialType = irr::video::EMT_TRANSPARENT_ADD_COLOR; //   EMT_TRANSPARENT_VERTEX_ALPHA;
    NM.MaterialType = irr::video::EMT_TRANSPARENT_VERTEX_ALPHA;
 
    // NM.ZBuffer = irr::video::ECFN_ALWAYS;
    NM.AmbientColor.setAlpha(57);
    NM.DiffuseColor.setAlpha(57);
    NM.SpecularColor.setAlpha(57);
    NM.EmissiveColor.setAlpha(57);
    // NM.AmbientColor = irr::video::SColor(0, 0x4F, 0xFC, 0);
 
    // NM.MaterialType = video::EMT_TRANSPARENT_VERTEX_ALPHA;
    // NM.setFlag(EMF_BACK_FACE_CULLING, false);
    // NM.setMaterialTexture(0, driver->getTexture("../../media/fire.bmp"));
    // NM.setMaterialType(video::EMT_TRANSPARENT_VERTEX_ALPHA);
    // ps->setMaterialFlag(video::EMF_LIGHTING, false);
    // setMaterialType(video::EMT_TRANSPARENT_VERTEX_ALPHA);
 
    lineNode->setMaterial(NM);
    lineNode->setColor(SColor(57, 0x4F, 0xFC, 0));
    // meshMnp->setVertexColorAlpha(lineNode->getMesh(), 80);
    ////lineNode->SVertexColorSetAlphaManipulator(127);
    // lineNode->setMaterialFlag(video::EMF_LIGHTING, false);
    // lineNode->setMaterialFlag(video::EMF_ZWRITE_ENABLE, false);
    lineNode->setMaterialType(video::EMT_TRANSPARENT_VERTEX_ALPHA);
    // lineNode->setMaterialFlag( irr::video::EMF_FRONT_FACE_CULLING, false);
    // lineNode->setMaterialFlag( irr::video::EMF_BACK_FACE_CULLING, false);
 
    // lineNode->setMaterialFlag(video::EMT_TRANSPARENT_VERTEX_ALPHA, true);
 
    /*
    Create our scene node. I don't check the result of calling new, as it
    should throw an exception rather than returning 0 on failure. Because
    the new node will create itself with a reference count of 1, and then
    will have another reference added by its parent scene node when it is
    added to the scene, I need to drop my reference to it. Best practice is
    to drop it only *after* I have finished using it, regardless of what
    the reference count of the object is after creation.
    */
    CSampleSceneNode *myNode =
        new CSampleSceneNode(smgr->getRootSceneNode(), smgr, 666);
 
    /*
    To animate something in this boring scene consisting only of one
    tetrahedron, and to show that you now can use your scene node like any
    other scene node in the engine, we add an animator to the scene node,
    which rotates the node a little bit.
    irr::scene::ISceneManager::createRotationAnimator() could return 0, so
    should be checked.
    */
    scene::ISceneNodeAnimator* anim = smgr->createRotationAnimator(core::vector3df(0.8f, 0, 0.8f));
    scene::ISceneNodeAnimator* aanim = smgr->createRotationAnimator(core::vector3df(0, 0.3f, 0));
 
    if(anim)
    {
        myNode->addAnimator(anim);
        // lineNode->addAnimator(aanim);
        /*
        I'm done referring to anim, so must
        irr::IReferenceCounted::drop() this reference now because it
        was produced by a createFoo() function. As I shouldn't refer to
        it again, ensure that I can't by setting to 0.
        */
        anim->drop();
        aanim->drop();
        anim = 0;
        aanim = 0;
    }
 
    /*
    I'm done with my CSampleSceneNode object, and so must drop my reference.
    This won't delete the object, yet, because it is still attached to the
    scene graph, which prevents the deletion until the graph is deleted or the
    custom scene node is removed from it.
    */
    myNode->drop();
    myNode = 0; // As I shouldn't refer to it again, ensure that I can't
 
    // add sydneys
    IAnimatedMesh* mesh = smgr->getMesh( "../../media/sydney.md2");
    IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );
    if (node)
    {
        node->setMaterialFlag(EMF_LIGHTING, false);
        node->setMD2Animation(scene::EMAT_STAND);
        node->setMaterialTexture( 0, driver->getTexture( "../../media/sydney.bmp") );
    }
 
    node->setPosition(vector3df(0, 0, 0) );
 
    /*
    Now draw everything and finish.
    */
    u32 frames=0;
    while(device->run())
    {
        lineNode->setColor(SColor(127, 0, 0xC0, 0));
        // lineNode->setPosition( vector3df(0, 50, 0) );
        lineNode->setPosition( vector3df(0, 25, -20) );
 
 
        //driver->beginScene(irr::video::ECBF_COLOR | video::ECBF_DEPTH, video::SColor(0,100,100,100));
        driver->beginScene( true, true, video::SColor(255,0xFF,0xFF,0xFF));
 
        smgr->drawAll();
 
        driver->endScene();
        if (++frames==100) // don't update more often, setWindowCaption can be expensive
        {
            core::stringw str = L"Irrlicht Engine [";
            str += driver->getName();
            str += L"] FPS: ";
            str += (s32)driver->getFPS();
 
            device->setWindowCaption(str.c_str());
            frames=0;
        }
    }
 
    device->drop();
 
    return 0;
}
 

ILineNode.cpp

Code: Select all

 
//----------------------------------------------------->
//  Copyright 2007  Marcelo Nunes de Sá Vasconcellos
//----------------------------------------------------->
#include "ILineNode.h"
 
//
ILineNode::ILineNode(core::vector3df center, f32 lheight, f32 lwidth, core::vector3df normal, ISceneNode* parent, ISceneManager* smgr, s32 id):ISceneNode(parent,smgr,id)
{
    //
    Driver = SceneManager->getVideoDriver();
 
    // Set the color
    this->lAlpha = 32;
    this->lColor = video::SColor(this->lAlpha, 0, 0xC0, 0);
 
    // Inclui ao parente este node
    if(Parent) Parent->addChild(this);
 
    //
    updateAbsolutePosition();
    createLine(center, lheight, lwidth, normal);
 
    // AutomaticCullingState = EAC_OFF; //   _FRUSTUM_BOX;
    AutomaticCullingState = irr::scene::EAC_OFF; //   _FRUSTUM_BOX; //  EAC_BOX
 
    //
    // smgr->addMeshSceneNode( this->mesh, smgr->getRootSceneNode() );
    smgr->registerNodeForRendering(this);
}
 
//
void ILineNode::OnRegisterSceneNode()
{
  if(IsVisible) SceneManager->registerNodeForRendering(this);
  ISceneNode::OnRegisterSceneNode();
}
 
//
void ILineNode::render()
{
    // Prep to render
    Driver->setMaterial(Material);
    Driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
    u16 indices[] = {
            0,1,2
            ,1,2,0
            ,2,0,1
    };
    // ,0,1,2
 
    // render
    Driver->drawVertexPrimitiveList(&lstVertices[0], lstVertices.size(), &indices[0], 3, irr::video::EVT_STANDARD, irr::scene::EPT_TRIANGLE_FAN, video::EIT_16BIT); // scene::EPT_TRIANGLES
 
    //
    // this->mesh->setPosition();
}
 
//
const core::aabbox3d<f32>& ILineNode::getBoundingBox() const
{
    return Box;
}
 
//
u32 ILineNode::getMaterialCount()
{
    return 1;
}
 
//
// video::SMaterial& ILineNode::getMaterial(u32 i)
// {
//     return this->Material;
// }
 
// Set material alpha
void ILineNode::setMaterialAlpha(u32 iAlpha)
{
    this->lAlpha = iAlpha;
    // Set the color
    this->lColor = video::SColor(this->lAlpha, 0x4F, 0xFC, 0);
}
 
//
void ILineNode::setMaterial(video::SMaterial newMaterial)
{
    this->Material = newMaterial;
}
 
//
void ILineNode::setColor(video::SColor iColor)
{
    // Change color
    this->lColor = iColor;
}
 
//
void ILineNode::createLine(core::vector3df center, f32 lheigth, f32 lwidth, core::vector3df normal)
{
    // must optimize.... horrible
    u16 indices[] = {
            0,1,2
            ,1,2,0
            ,2,0,1
    };
 
    //
    normal.normalize();
 
    //
    lstIndices.clear();
    lstVertices.clear();
 
    ///////////////////////////////////////////////////////
    // Mesh buffer
 
    //
    scene::SMeshBuffer* buffer = new scene::SMeshBuffer;
 
    //
    buffer->Vertices.reallocate(3);
    buffer->Indices.set_used((3*3));
 
    //
    for (u32 i = 0; i < (3*3); ++i)
    {
        buffer->Indices[i] = indices[i];
    };
 
    //
    Box.reset(center);
 
    //
    video::S3DVertex Vertices[3];
 
    // sets the color..
    // video::SColor color = video::SColor(0x0A, 0, 0xE6, 0);
 
    // Construct the vertices
    Vertices[0] = video::S3DVertex(center.X, center.Y, center.Z, 1,1,0, video::SColor(255,0,255,255), 0, 1);
    Vertices[0].Color = this->lColor;
    Vertices[1].Color.setAlpha(this->lAlpha);
        lstVertices.push_back(Vertices[0]);
        buffer->Vertices.push_back(Vertices[0]);
        lstIndices.push_back(lstVertices.size());
    //
    Vertices[1] = video::S3DVertex(center.X, center.Y - lheigth, center.Z, 1,1,0, video::SColor(255,0,255,255), 0, 1);
    Vertices[1].Color = this->lColor;
    Vertices[1].Color.setAlpha(this->lAlpha);
        lstVertices.push_back(Vertices[1]);
        buffer->Vertices.push_back(Vertices[1]);
        lstIndices.push_back(lstVertices.size());
    //
    Vertices[2] = video::S3DVertex(center.X, center.Y - lheigth, center.Z + lwidth, 1,1,0, video::SColor(255,0,255,255), 0, 1);
    Vertices[2].Color = this->lColor;
    Vertices[2].Color.setAlpha(this->lAlpha);
        lstVertices.push_back(Vertices[2]);
        buffer->Vertices.push_back(Vertices[2]);
        lstIndices.push_back(lstVertices.size());
 
    // Recalculate bounding box
    // buffer->BoundingBox.reset(0, 0, 0);
    buffer->BoundingBox.reset(center);
 
    //
    for (s32 i=0; i<3; ++i)
    {
        buffer->BoundingBox.addInternalPoint(buffer->Vertices[i].Pos);
        Box.addInternalPoint(Vertices[i].Pos);
    }
 
    //
    buffer->Material = this->Material;
    //
    this->mesh = new scene::SMesh;
    this->mesh->addMeshBuffer(buffer);
    this->mesh->recalculateBoundingBox();
    //
    buffer->drop();
    //
    LHeigth = lheigth;
    Center = center;
    Normal = normal;
}
 
ILineNode.h

Code: Select all

 
//----------------------------------------------------->
//  Copyright 2007  Marcelo Nunes de Sá Vasconcellos
//----------------------------------------------------->
#pragma once
#include <irrlicht.h>
 
using namespace irr;
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
 
// classes
class ILineNode :  public scene::ISceneNode
{
  private:
    //
    core::array<video::S3DVertex> lstVertices;
    core::array<u16> lstIndices;
    core::aabbox3df Box;
    core::vector3df Normal;
    core::vector3df Center;
    //
    scene::SMesh* mesh;
    //
    video::SColor lColor;
    video::SMaterial Material;
    video::IVideoDriver* Driver;
    //
    f32 LHeigth;
    u32 lAlpha;
    u16 indices[3];
 
  public:
    ILineNode(core::vector3df center, f32 lheight, f32 lwidth, core::vector3df normal, ISceneNode* parent, ISceneManager* smgr, s32 id=-1);
    virtual void OnRegisterSceneNode();
    virtual void render();
    virtual const core::aabbox3d<f32>& getBoundingBox() const;
    virtual u32 getMaterialCount();
    // virtual video::SMaterial& getMaterial(u32 i);
    virtual void setMaterial(video::SMaterial newMaterial);
    virtual void setMaterialAlpha(u32 iAlplha);
    void setColor(video::SColor iColor);
    void createLine(core::vector3df center, f32 lheight, f32 lwidth, core::vector3df normal);
};
 
CuteAlien
Admin
Posts: 9651
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Thin Transparent Mesh layer

Post by CuteAlien »

Huh, strange. I found a bunch of problems, but none which fixed this so far. Confusing. Will try some more later on maybe

Current code (slightly simpler to hunt this):

Code: Select all

 
#include <irrlicht.h>
 
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
 
#ifdef _MSC_VER
#pragma comment(lib, "Irrlicht.lib")
#endif
 
class ILineNode :  public scene::ISceneNode
{
  private:
    core::array<video::S3DVertex> lstVertices;
 
    core::aabbox3df Box;
    video::SMaterial Material;
    video::IVideoDriver* Driver;
 
    void createLine(core::vector3df center, f32 lheight, f32 lwidth, core::vector3df normal)
    {
        normal.normalize();
 
        lstVertices.clear();
 
        Box.reset(center);
 
        // Set the color
        irr::video::SColor lColor(255, 0, 0xC0, 0);
 
        // Construct the vertices
        video::S3DVertex vertex;
        vertex = video::S3DVertex(center.X, center.Y, center.Z, normal.X, normal.Y, normal.Z, lColor, 0, 1);
        lstVertices.push_back(vertex);
        Box.addInternalPoint(vertex.Pos);
 
        vertex = video::S3DVertex(center.X, center.Y - lheight, center.Z, normal.X, normal.Y, normal.Z, lColor, 0, 1);
        lstVertices.push_back(vertex);
        Box.addInternalPoint(vertex.Pos);
 
        vertex = video::S3DVertex(center.X, center.Y - lheight, center.Z + lwidth, normal.X, normal.Y, normal.Z, lColor, 0, 1);
        lstVertices.push_back(vertex);
        Box.addInternalPoint(vertex.Pos);
    }
 
  public:
    ILineNode(core::vector3df center, f32 lheight, f32 lwidth, core::vector3df normal, ISceneNode* parent, ISceneManager* smgr, s32 id=-1)
    :   ISceneNode(parent,smgr,id)
    {
        Driver = SceneManager->getVideoDriver();
 
        createLine(center, lheight, lwidth, normal);
 
        AutomaticCullingState = irr::scene::EAC_OFF;
 
        Material.Lighting = false;
        Material.BackfaceCulling = false;
        Material.MaterialType = EMT_TRANSPARENT_VERTEX_ALPHA;
//      Material.ZWriteFineControl = EZI_ZBUFFER_FLAG;
//      Material.BlendOperation = EBO_ADD;
    }
 
    virtual void OnRegisterSceneNode()
    {
        if(IsVisible)
            SceneManager->registerNodeForRendering(this);
        ISceneNode::OnRegisterSceneNode();
    }
 
    virtual void render()
    {
        // Prep to render
        Driver->setMaterial(Material);
        Driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
        u16 indices[] = { 0,1,2 };
 
        // render
        Driver->drawVertexPrimitiveList(lstVertices.pointer(), lstVertices.size(), indices, 1, irr::video::EVT_STANDARD, irr::scene::EPT_TRIANGLES, video::EIT_16BIT);
    }
 
    virtual const core::aabbox3d<f32>& getBoundingBox() const
    {
        return Box;
    }
 
    virtual u32 getMaterialCount()
    {
        return 1;
    }
 
    virtual video::SMaterial& getMaterial(u32 i)
    {
        return Material;
    }
 
    virtual void setMaterial(video::SMaterial newMaterial)
    {
        Material = newMaterial;
    }
};
 
int main()
{
    video::E_DRIVER_TYPE driverType = EDT_OPENGL;
    IrrlichtDevice *device = createDevice(driverType,
            core::dimension2d<u32>(960, 540), 32, false);
 
    if (device == 0)
        return 1; // could not create selected driver.
 
    video::IVideoDriver* driver = device->getVideoDriver();
    scene::ISceneManager* smgr = device->getSceneManager();
 
    // add a first person shooter style user controlled camera
    irr::scene::ICameraSceneNode * cameraNode = smgr->addCameraSceneNodeFPS( NULL, 20.0f, 0.02f, -1);
    cameraNode->setPosition(vector3df(0,-10, -30));
 
    // Some floor
    IAnimatedMesh* hillPlaneMesh = smgr->addHillPlaneMesh( "GROUND",
        core::dimension2d<f32>(10,10),
        core::dimension2d<u32>(200,200), 0, 0,
        core::dimension2d<f32>(0,0),
        core::dimension2d<f32>(10,10));
 
    ISceneNode* planeNode = smgr->addAnimatedMeshSceneNode(hillPlaneMesh);
    planeNode->setMaterialTexture(0, driver->getTexture("../../media/stones.jpg"));
    planeNode->setMaterialFlag(video::EMF_LIGHTING, false);
    planeNode->setPosition(core::vector3df(0, -50, 0));
 
    // add sydneys
    IAnimatedMesh* mesh = smgr->getMesh( "../../media/sydney.md2");
    IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );
    if (node)
    {
        node->setMaterialFlag(EMF_LIGHTING, false);
        node->setMD2Animation(scene::EMAT_STAND);
        node->setMaterialTexture( 0, driver->getTexture( "../../media/sydney.bmp") );
    }
 
 
    // Linenode
    ILineNode* lineNode = new ILineNode(vector3df(20, 25, 0), 250, 150, core::vector3df(0,0,1), smgr->getRootSceneNode(), smgr);
 
    while(device->run())
    {
        driver->beginScene( true, true, video::SColor(255,0xFF,0xFF,0xFF));
 
        smgr->drawAll();
 
        driver->endScene();
    }
 
    lineNode->drop();
 
    device->drop();
 
    return 0;
}
 
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
CuteAlien
Admin
Posts: 9651
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Thin Transparent Mesh layer

Post by CuteAlien »

Solved now. You removed the "const" in getMaterialCount(). That makes it a new function and it wasn't called anymore. And because default for getMaterialCount is 0 materials, you got some place that way which no longer did set the material correct as the node said he had no materials. So with fix:

Code: Select all

 
#include <irrlicht.h>
 
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
 
#ifdef _MSC_VER
#pragma comment(lib, "Irrlicht.lib")
#endif
 
class ILineNode :  public scene::ISceneNode
{
  private:
    core::array<video::S3DVertex> lstVertices;
 
    core::aabbox3df Box;
    video::SMaterial Material;
    video::IVideoDriver* Driver;
 
    void createLine(core::vector3df center, f32 lheight, f32 lwidth)
    {
        core::vector3df normal(0,0,1);
 
        lstVertices.clear();
 
        Box.reset(center);
 
        // Set the color
        irr::video::SColor lColor(50, 0, 0xC0, 0);
 
        // Construct the vertices
        video::S3DVertex vertex;
        vertex = video::S3DVertex(center.X, center.Y, center.Z, normal.X, normal.Y, normal.Z, lColor, 0, 1);
        lstVertices.push_back(vertex);
        Box.addInternalPoint(vertex.Pos);
 
        vertex = video::S3DVertex(center.X, center.Y - lheight, center.Z, normal.X, normal.Y, normal.Z, lColor, 0, 1);
        lstVertices.push_back(vertex);
        Box.addInternalPoint(vertex.Pos);
 
        vertex = video::S3DVertex(center.X, center.Y - lheight, center.Z + lwidth, normal.X, normal.Y, normal.Z, lColor, 0, 1);
        lstVertices.push_back(vertex);
        Box.addInternalPoint(vertex.Pos);
    }
 
  public:
    ILineNode(core::vector3df center, f32 lheight, f32 lwidth, ISceneNode* parent, ISceneManager* smgr, s32 id=-1)
    :   ISceneNode(parent,smgr,id)
    {
        Driver = SceneManager->getVideoDriver();
 
        createLine(center, lheight, lwidth);
 
        AutomaticCullingState = irr::scene::EAC_OFF;
 
        Material.Lighting = false;
        Material.BackfaceCulling = false;
        Material.MaterialType = EMT_TRANSPARENT_VERTEX_ALPHA;
    }
 
    virtual void OnRegisterSceneNode()
    {
        if(IsVisible)
            SceneManager->registerNodeForRendering(this);
        ISceneNode::OnRegisterSceneNode();
    }
 
    virtual void render()
    {
        // Prep to render
        Driver->setMaterial(Material);
        Driver->setTransform(video::ETS_WORLD, AbsoluteTransformation);
        u16 indices[] = { 0,1,2 };
 
        // render
        Driver->drawVertexPrimitiveList(lstVertices.pointer(), lstVertices.size(), indices, 1, irr::video::EVT_STANDARD, irr::scene::EPT_TRIANGLES, video::EIT_16BIT);
    }
 
    virtual const core::aabbox3d<f32>& getBoundingBox() const
    {
        return Box;
    }
 
    virtual u32 getMaterialCount() const
    {
        return 1;
    }
 
    virtual video::SMaterial& getMaterial(u32 i)
    {
        return Material;
    }
 
    virtual void setMaterial(video::SMaterial newMaterial)
    {
        Material = newMaterial;
    }
};
 
int main()
{
    video::E_DRIVER_TYPE driverType = EDT_OPENGL;
    IrrlichtDevice *device = createDevice(driverType,
            core::dimension2d<u32>(960, 540), 32, false);
 
    if (device == 0)
        return 1; // could not create selected driver.
 
    video::IVideoDriver* driver = device->getVideoDriver();
    scene::ISceneManager* smgr = device->getSceneManager();
 
    // add a first person shooter style user controlled camera
    irr::scene::ICameraSceneNode * cameraNode = smgr->addCameraSceneNodeFPS( NULL, 20.0f, 0.02f);
    cameraNode->setPosition(vector3df(0,-10, -30));
 
    // Some floor
    IAnimatedMesh* hillPlaneMesh = smgr->addHillPlaneMesh( "GROUND",
        core::dimension2d<f32>(10,10),
        core::dimension2d<u32>(200,200), 0, 0,
        core::dimension2d<f32>(0,0),
        core::dimension2d<f32>(10,10));
 
    ISceneNode* planeNode = smgr->addAnimatedMeshSceneNode(hillPlaneMesh);
    planeNode->setMaterialTexture(0, driver->getTexture("../../media/stones.jpg"));
    planeNode->setMaterialFlag(video::EMF_LIGHTING, false);
    planeNode->setPosition(core::vector3df(0, -50, 0));
 
    // add sydneys
    IAnimatedMesh* mesh = smgr->getMesh( "../../media/sydney.md2");
    IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );
    if (node)
    {
        node->setMaterialFlag(EMF_LIGHTING, false);
        node->setMD2Animation(scene::EMAT_STAND);
        node->setMaterialTexture( 0, driver->getTexture( "../../media/sydney.bmp") );
    }
 
    ILineNode* lineNode = new ILineNode(vector3df(20, 25, 0), 250, 150, smgr->getRootSceneNode(), smgr);
 
    while(device->run())
    {
        driver->beginScene( true, true, video::SColor(255,0xFF,0xFF,0xFF));
 
        smgr->drawAll();
 
        driver->endScene();
    }
 
    lineNode->drop();
 
    device->drop();
 
    return 0;
}
 
And please in future when you post code - reduce it first to the minimum to reproduce a problem (so like it's now).
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
mnunesvsc
Posts: 22
Joined: Sun May 28, 2006 9:04 pm
Contact:

Re: Thin Transparent Mesh layer

Post by mnunesvsc »

THANK YOU VERY MUCH, worked like a charm, sorry for the confusion, so many time without posting, can not express how much i am gratefull

even the circleNode worked with the just that adjust

Image

many thanks
CuteAlien
Admin
Posts: 9651
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Thin Transparent Mesh layer

Post by CuteAlien »

no problem :-)
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply