Can edit terrain node, but normals won't update!

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
ultramedia
Posts: 175
Joined: Wed Dec 20, 2006 12:04 pm

Can edit terrain node, but normals won't update!

Post by ultramedia »

Hi Everyone,

I've been playing with changing a terrain node dynamically, can now adjust the positions of the individual vertices with the following code (which is just a test) :

Code: Select all

scene::IMesh* pMesh = terrain->getMesh();
     
    s32 b;
    for (b=0; b<pMesh->getMeshBufferCount(); ++b){
        scene::IMeshBuffer* pMeshBuffer = pMesh->getMeshBuffer(b);
        // skip mesh buffers that are not the right type
        if (pMeshBuffer->getVertexType() != video::EVT_2TCOORDS) continue;
     
        video::S3DVertex2TCoords* pVertices = (video::S3DVertex2TCoords*)pMeshBuffer->getVertices();
 
        u32 vertCount = 262144; // (512*512)
 
        // adjust vert position
        for(int i=0; i<65536; i++)
        {
            S3DVertex currentVert = pVertices[i];
            currentVert.Pos.Y = 500;
            currentVert.Normal = vector3df(0,1,0);
            pVertices[i] = currentVert;
 
            int a=1;
        }
 
    }
    
    // force terrain render buffer to reload
    terrain->setPosition(terrain->getPosition());
Problem is, can't find a way to make the normals update as well (setDirty doesn't make any difference) :

Image

Need help pretty badly, have spent a couple of weeks on this and have run out of time to get it going :(
ultramedia
Posts: 175
Joined: Wed Dec 20, 2006 12:04 pm

Re: Can edit terrain node, but normals won't update!

Post by ultramedia »

Sorry, I'm a goose, got the image url wrong... (fixed now)
Marthog
Posts: 31
Joined: Sun Oct 03, 2010 8:33 pm
Contact:

Re: Can edit terrain node, but normals won't update!

Post by Marthog »

Use SceneManager->getMeshManipulator()->recalculateNormals
Rust fanboy
Post Reply