My Custom SceneNode doesn't work

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
hanpcship
Posts: 8
Joined: Tue Feb 14, 2012 10:33 am

My Custom SceneNode doesn't work

Post by hanpcship »

the scenenode code is same as other custom scenenodes, but mesh do not output on screen absolutely.
I don't know what problem is exist in my source code.

Code: Select all

 
// IAdvencedTerrainSceneNode.h
 
#ifndef __I_ADVENCEDTERRAIN_SCENE_NODE_H__
#define __I_ADVENCEDTERRAIN_SCENE_NODE_H__
 
#include <irrlicht.h>
#include "Mapdata.h"
#include "SMaterial.h"
 
#define TILE_SIZE 1.0f
 
namespace irr
{
using namespace video;
namespace io
{
        class IReadFile;
} // end namespace io
namespace scene
{
        class IMesh;
 
        class IAdvencedTerrainSceneNode : public IMeshSceneNode
        {
        public:
                //! Constructor
                IAdvencedTerrainSceneNode(
                        ISceneNode* parent, 
                        ISceneManager* mgr, 
                        s32 id,
                        CMapdata * pMap);
                ~IAdvencedTerrainSceneNode();
                IMesh * CreateMesh();
                
                
                virtual void render();
                virtual const core::aabbox3d<f32>& getBoundingBox() const
                {
                        return m_pMesh->getBoundingBox();
                }
                virtual u32 getMaterialCount() const
                {
                        return 0;
                }
        
                virtual video::SMaterial& getMaterial(u32 i)
                {
                        return m_Material;
                }
                
                // IMeshSceneNode 
                virtual void setMesh(IMesh* mesh) {};
                virtual IMesh* getMesh(void) { return m_pMesh; }
                virtual void setReadOnlyMaterials(bool readonly) {}
                virtual bool isReadOnlyMaterials() const { return false; }
 
        protected:
                IMesh * m_pMesh;
                CMapdata * m_pMap;
                IDynamicMeshBuffer * m_RenderBuffer;
                SMaterial m_Material;
        };
 
} // end namespace scene
} // end namespace irr
 
 
#endif // __I_TERRAIN_SCENE_NODE_H__
 
mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm

Code: Select all

 
// IAdvencedTerrainSceneNode.cpp
 
#include "IAdvencedTerrainSceneNode.h"
 
 
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
 
IAdvencedTerrainSceneNode::IAdvencedTerrainSceneNode(
        ISceneNode* parent, 
        ISceneManager* mgr, 
        s32 id,
        CMapdata * pMap) 
        : IMeshSceneNode(parent,mgr,id)
{
        m_pMesh = NULL;
        //m_pMaterial = NULL; 
        m_pMap = pMap;
        
        if (m_pMesh)
                m_pMesh->drop();
        m_pMesh = CreateMesh();
        m_Material.Wireframe = false;
        m_Material.Lighting = false;
        //if (m_pMaterial)
        //      delete m_pMaterial;
        //m_pMaterial = CreateMaterial();
}
IAdvencedTerrainSceneNode::~IAdvencedTerrainSceneNode()
{
        if (m_pMesh)
                m_pMesh->drop();
        //if (m_pMaterial)
        //      delete m_pMaterial;
}
IMesh* IAdvencedTerrainSceneNode::CreateMesh()
{
        int i,j, iWidth=m_pMap->m_iMapwidth, iLength=m_pMap->m_iMaplength;
        
        SMeshBuffer* pBuffer = new SMeshBuffer();
 
 
        S3DVertex vertex;
 
        vertex.Color = SColor(255,255,255,255);
        for (i=0; i<iWidth; i++)
        {
                for(j=0; j<iLength; j++)
                {
                        
                        vertex.Pos.X = i*TILE_SIZE;
                        vertex.Pos.Z = j*TILE_SIZE;
                        vertex.Pos.Y = 0.0f;
                        
                        vertex.Normal = vertex.Pos;
                        
                        vertex.TCoords.X = 0.0f;
                        vertex.TCoords.Y = 0.0f;
                        
                        pBuffer->Vertices.push_back(vertex);
                        
                        
                        vertex.Pos.X = (i+1)*TILE_SIZE;
                        vertex.Pos.Z = j*TILE_SIZE;
                        vertex.Pos.Y = 0.0f;
                        
                        vertex.Normal = vertex.Pos;
                        
                        vertex.TCoords.X = 1.0f;
                        vertex.TCoords.Y = 0.0f;
                        
                        pBuffer->Vertices.push_back(vertex);
                        
                        
                        vertex.Pos.X = i*TILE_SIZE;
                        vertex.Pos.Z = (j+1)*TILE_SIZE;
                        vertex.Pos.Y = 0.0f;
                        
                        vertex.Normal = vertex.Pos;
                        
                        vertex.TCoords.X = 0.0f;
                        vertex.TCoords.Y = 1.0f;
                        
                        pBuffer->Vertices.push_back(vertex);
                        
                        
                        vertex.Pos.X = (i+1)*TILE_SIZE;
                        vertex.Pos.Z = (j+1)*TILE_SIZE;
                        vertex.Pos.Y = 0.0f;
                        
                        vertex.Normal = vertex.Pos;
                        
                        vertex.TCoords.X = 1.0f;
                        vertex.TCoords.Y = 1.0f;
                        
                        pBuffer->Vertices.push_back(vertex);
                }
        }
        int _WL = iWidth * iLength;
        for (i=0; i<_WL; i++)
        {
                pBuffer->Indices.push_back(4*i + 1);
                pBuffer->Indices.push_back(4*i + 2);
                pBuffer->Indices.push_back(4*i);
                        
                pBuffer->Indices.push_back(4*i + 1);
                pBuffer->Indices.push_back(4*i + 3);
                pBuffer->Indices.push_back(4*i + 2);
                
                /*pBuffer->Indices.push_back(4*i);
                pBuffer->Indices.push_back(4*i + 2);
                pBuffer->Indices.push_back(4*i + 1);
                        
                pBuffer->Indices.push_back(4*i + 2);
                pBuffer->Indices.push_back(4*i + 3);
                pBuffer->Indices.push_back(4*i + 1);*/
        }
 
        pBuffer->recalculateBoundingBox();
        
        SMesh* mesh = new irr::scene::SMesh();
        
        mesh->addMeshBuffer(pBuffer);
        mesh->recalculateBoundingBox();
        
        pBuffer->drop();
 
        return mesh;
}
 
 
void IAdvencedTerrainSceneNode::render()
{
        
        IVideoDriver *driver = SceneManager->getVideoDriver();
        driver->setMaterial(getMaterial(0));
        driver->setTransform(irr::video::ETS_WORLD,AbsoluteTransformation);
        
        driver->drawMeshBuffer(m_pMesh->getMeshBuffer(0));
        if(DebugDataVisible)
        {
                driver->draw3DBox(m_pMesh->getBoundingBox(), irr::video::SColor(255,255,0,0));
        }
}
 
Last edited by hanpcship on Tue Feb 14, 2012 11:12 am, edited 1 time in total.
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: My Custom SceneNode doesn't work

Post by CuteAlien »

Too much code ... but on first view it seems that getMaterialCount returns 0, probably should be 1 instead.
Hint: you can use code flags in this forum for nicer formating of 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
hanpcship
Posts: 8
Joined: Tue Feb 14, 2012 10:33 am

Re: My Custom SceneNode doesn't work

Post by hanpcship »

getMaterialCount return 1 in previous code, but doesn't work. return 0 is what modified recently
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: My Custom SceneNode doesn't work

Post by hybrid »

Yeah, must be 1 at least, otherwise strange material problems can occur. Here, I'd suggest to disable culling (not sure if you update the bounding box) and backface culling (in case you have a wrong winding order).
In case you just need a manually created mesh, the suggested way is to create a simple SMesh anyway, instead of a custom scene node. Those are just for implementing specialized rendering techniques.
hanpcship
Posts: 8
Joined: Tue Feb 14, 2012 10:33 am

Re: My Custom SceneNode doesn't work

Post by hanpcship »

i do disable frontface & backface culling and change return value of getMaterialCount to 1. but it still doesn't work.

i need to let my team members who have no 3D knowledge can edit map. in addition completed scene node algorism is in my notebook... so i should not give up custom scene node.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Re: My Custom SceneNode doesn't work

Post by hybrid »

Make sure to disable lighting (at least for testing) and maybe try to enable wireframe. This will sometimes show something even if the full picture is broken.
hanpcship
Posts: 8
Joined: Tue Feb 14, 2012 10:33 am

Re: My Custom SceneNode doesn't work

Post by hanpcship »

lighting is already disabled. i try to enable wireframe but nothing is shown.

* setting code is :

CMapdata map;

IAdvencedTerrainSceneNode *pNode = NULL;
pNode = new IAdvencedTerrainSceneNode(smgr->getRootSceneNode(), smgr, 1, &map);
pNode->drop();
Iyad
Posts: 140
Joined: Sat Mar 07, 2009 1:18 am
Location: Montreal, Canada

Re: My Custom SceneNode doesn't work

Post by Iyad »

OFF-TOPIC
hybrid wrote:Make sure to disable lighting (at least for testing) and maybe try to enable wireframe. This will sometimes show something even if the full picture is broken.
This is hybrid's 13000 post.
#include <Iyad.h>
hanpcship
Posts: 8
Joined: Tue Feb 14, 2012 10:33 am

Re: My Custom SceneNode doesn't work

Post by hanpcship »

i do hybrid's opinion but no one has shown.
codebaker
Posts: 8
Joined: Mon Feb 13, 2012 12:15 pm
Location: Germany

Re: My Custom SceneNode doesn't work

Post by codebaker »

i don't know but i miss the OnRegister-procedure. Can it be?
zerochen
Posts: 273
Joined: Wed Jan 07, 2009 1:17 am
Location: Germany

Re: My Custom SceneNode doesn't work

Post by zerochen »

hi

i think the node is not registered to the render process

maybe add something like this

Code: Select all

 
//! frame
void IAdvencedTerrainSceneNode::OnRegisterSceneNode()
{
        if (IsVisible)
                SceneManager->registerNodeForRendering(this);
 
        ISceneNode::OnRegisterSceneNode();
}
btw it is called Advanced :)

edit: damn to late^^
Last edited by zerochen on Thu Feb 16, 2012 2:02 am, edited 1 time in total.
hanpcship
Posts: 8
Joined: Tue Feb 14, 2012 10:33 am

Re: My Custom SceneNode doesn't work

Post by hanpcship »

it works Well !!
Thank you zerochan. I never forget your help in my life.
Post Reply