[1.5] cannot get terrain vertices

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
white tiger
Posts: 269
Joined: Tue Oct 31, 2006 3:24 pm
Contact:

[1.5] cannot get terrain vertices

Post by white tiger »

I cannot get terrain vertices with 1.5. I updated the routine to follow new 1.5 way to retrieve terrain vertex and index buffer, but it simply does not work. here are it:

Code: Select all

 scene::CDynamicMeshBuffer* mb2 = new scene::CDynamicMeshBuffer(video::EVT_2TCOORDS, video::EIT_16BIT);
    ((scene::ITerrainSceneNode*)node)->getMeshBufferForLOD(*mb2,LOD);

    scene::IVertexBuffer& vertices = mb2->getVertexBuffer();
	scene::IIndexBuffer& indices = mb2->getIndexBuffer();
	u16 index_count = indices.size();

	core::vector3df mapsize = node->getScale();
	//core::vector3df mapsize = core::vector3df(1,1,1);
	std::cout << "index count: " << index_count << std::endl;

	// create collision tree faces
	for (int i = 0; i < index_count ; i += 3)
	{
	   v1i = indices[i];
	   v2i = indices[i + 1];
	   v3i = indices[i + 2];

		// build face data
		vArray[0] = vertices[v1i].Pos.X * mapsize.X * IrrToNewton;
		vArray[1] = vertices[v1i].Pos.Y * mapsize.Y * IrrToNewton;
		vArray[2] = vertices[v1i].Pos.Z * mapsize.Z * IrrToNewton;

		vArray[3] = vertices[v2i].Pos.X * mapsize.X * IrrToNewton;
		vArray[4] = vertices[v2i].Pos.Y * mapsize.Y * IrrToNewton;
		vArray[5] = vertices[v2i].Pos.Z * mapsize.Z * IrrToNewton;

		vArray[6] = vertices[v3i].Pos.X * mapsize.X * IrrToNewton;
		vArray[7] = vertices[v3i].Pos.Y * mapsize.Y * IrrToNewton;
		vArray[8] = vertices[v3i].Pos.Z * mapsize.Z * IrrToNewton;

		// make sure we do not add degenerated polygons to the tree
		core::vector3df irrvArray[3] ={
			core::vector3df(vArray[0],vArray[1],vArray[2]),
			core::vector3df(vArray[3],vArray[4],vArray[5]),
			core::vector3df(vArray[6],vArray[7],vArray[8])
		};

		core::vector3df e0 (irrvArray[1] - irrvArray[0]);
		core::vector3df e1 (irrvArray[2] - irrvArray[0]);

		// the area of the face is the cross product
		core::vector3df area (e0.crossProduct (e1));

		// skip faces with very small area
		/*
		irr::f32 mag = area.dotProduct (area);
		if (mag > 1.0e-6f) {
			// add face to tree
			NewtonTreeCollisionAddFace(nCollision , 3, (float*)vArray, 12, 11);
			PolyCount++;
		}// if (mag > 1.0e-6f) {
		*/
	}

it does not work either using node->getVertexBuffer().getData() and casting the result to S3DVertex
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Code: Select all

        /* If you need access to the terrain data you can also do this directly via the following code fragment.
        */
        scene::CDynamicMeshBuffer* buffer = new scene::CDynamicMeshBuffer(video::EVT_2TCOORDS, video::EIT_16BIT);
        terrain->getMeshBufferForLOD(*buffer, 0);
        video::S3DVertex2TCoords* data = (video::S3DVertex2TCoords*)buffer->getVertexBuffer().getData();
        // Work on data or get the IndexBuffer with a similar call.
        buffer->drop(); // When done drop the buffer again.
That's what the example says, and that was tested with the usual Irrlicht render methods (i.e. I rendered the data and it looked almost like the original terrain).
white tiger
Posts: 269
Joined: Tue Oct 31, 2006 3:24 pm
Contact:

Post by white tiger »

i have also tried this way
white tiger wrote:it does not work either using node->getVertexBuffer().getData() and casting the result to S3DVertex
it does not work nor using the [] operator of the vertex buffer class neither using getData(), casting and retrieve the arrray directly

i need to investigate more BTW
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Did you try to render the data you got? How does it look like - i.e. what are the problems you encounter?
Also note that the default Irrlicht 1.5 SDK uses 32bit indices even for the heightmap in the SDK (although not necessary). So make sure you got the proper index type.
white tiger
Posts: 269
Joined: Tue Oct 31, 2006 3:24 pm
Contact:

Post by white tiger »

i rendered it and it give me only a part of the terrain. I got only the vertices on the yellow part, and i know for sure there is no error in the rendering since the parts wich are not colored do not collide with the camera, and that means there are no vertices for them

i don't think this depends by 32 bits indices, since i use directly the [] operator of the indexbuffer class, do not cast to an array

Image
white tiger
Posts: 269
Joined: Tue Oct 31, 2006 3:24 pm
Contact:

Post by white tiger »

it works now. forgot to change index_count to be an u32

thanks you hybrid
Post Reply