Page 1 of 1

My Custom SceneNode doesn't work

Posted: Tue Feb 14, 2012 10:59 am
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));
        }
}
 

Re: My Custom SceneNode doesn't work

Posted: Tue Feb 14, 2012 11:05 am
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.

Re: My Custom SceneNode doesn't work

Posted: Tue Feb 14, 2012 11:10 am
by hanpcship
getMaterialCount return 1 in previous code, but doesn't work. return 0 is what modified recently

Re: My Custom SceneNode doesn't work

Posted: Tue Feb 14, 2012 12:58 pm
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.

Re: My Custom SceneNode doesn't work

Posted: Tue Feb 14, 2012 2:40 pm
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.

Re: My Custom SceneNode doesn't work

Posted: Tue Feb 14, 2012 3:53 pm
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.

Re: My Custom SceneNode doesn't work

Posted: Tue Feb 14, 2012 4:07 pm
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();

Re: My Custom SceneNode doesn't work

Posted: Tue Feb 14, 2012 4:53 pm
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.

Re: My Custom SceneNode doesn't work

Posted: Wed Feb 15, 2012 3:42 am
by hanpcship
i do hybrid's opinion but no one has shown.

Re: My Custom SceneNode doesn't work

Posted: Wed Feb 15, 2012 8:23 pm
by codebaker
i don't know but i miss the OnRegister-procedure. Can it be?

Re: My Custom SceneNode doesn't work

Posted: Wed Feb 15, 2012 8:25 pm
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^^

Re: My Custom SceneNode doesn't work

Posted: Thu Feb 16, 2012 1:11 am
by hanpcship
it works Well !!
Thank you zerochan. I never forget your help in my life.