Morph surface of model
Morph surface of model
How i can transform surface of model?
I want to create randomly generated terrain or maybe planets.
I want to create randomly generated terrain or maybe planets.
Nerexis
Sorry for bad English.
Sorry for bad English.
-
- Posts: 208
- Joined: Sun Apr 02, 2006 9:20 pm
I am quite not sure what you want. You used the word Morph in the title which suggests that you were going to want to animate a mesh. But if you are after a terrain or planet I assume you will want a static mesh.
I created a command for my FreeBasic - Irrlicht Wrapper that enabled a user to create a mesh with a simple call using the equally simple Irrlicht commands, the code was as follows: -
Another way would be to create your own scene node, there is an Irrlicht example of this in examples/03.CustomSceneNode[/code]
I created a command for my FreeBasic - Irrlicht Wrapper that enabled a user to create a mesh with a simple call using the equally simple Irrlicht commands, the code was as follows: -
Code: Select all
/* ----------------------------------------------------------------------------
create a mesh from an array of verticies, an array of incidies to those
verticies that connect them to form triangles and finally texture co-ordinates
to map the verticies against a texture plane
*/
void * DLL_EXPORT IrrCreateMesh(
char *cptrMeshName,
int iVertexCount,
IRR_VERT *vVertices,
int iIndicesCount,
unsigned short *usIndices )
{
int iLoop;
/* get the mesh cache for the scene */
IMeshCache *mcache = smgr->getMeshCache();
SMeshBuffer *smeshbuffer = new SMeshBuffer;
SMesh *smesh = new SMesh;
SAnimatedMesh * sanimmesh = new SAnimatedMesh;
// add all of the verts
printf( "Adding %d verts\n", iVertexCount );
smeshbuffer->Vertices.set_used(iVertexCount);
for ( iLoop = 0; iLoop < iVertexCount; iLoop++ )
{
smeshbuffer->Vertices[iLoop].Pos.set(
vVertices[iLoop].x,
vVertices[iLoop].y,
vVertices[iLoop].z );
smeshbuffer->Vertices[iLoop].Normal.set(
vVertices[iLoop].normal_x,
vVertices[iLoop].normal_y,
vVertices[iLoop].normal_z );
smeshbuffer->Vertices[iLoop].Color.color = vVertices[iLoop].vcolor;
smeshbuffer->Vertices[iLoop].TCoords.set(
vVertices[iLoop].texture_x,
vVertices[iLoop].texture_y );
}
// add all of the indices
printf( "Adding %d indicies\n", iIndicesCount );
smeshbuffer->Indices.set_used(iIndicesCount);
for ( iLoop = 0; iLoop < iIndicesCount; iLoop++ )
{
smeshbuffer->Indices[iLoop] = usIndices[iLoop];
}
// assemble the mesh objects
smesh->addMeshBuffer( smeshbuffer );
sanimmesh->addMesh( smesh );
mcache->addMesh( cptrMeshName, sanimmesh );
// recalculate the bounding box around the object for clipping purposes
sanimmesh->recalculateBoundingBox();
return (void *)sanimmesh;
}
Thx for the function but i made this:
Terrain made by this function is ugly.. who knows better way to do it?
and how i can subdivide vertices in this mesh to make terrain smooth?
Code: Select all
IAnimatedMesh *Obiekt_mesh =
smgr->addHillPlaneMesh("hill",
dimension2d< f32 >(10,10),
dimension2d< u32 >(100,100),
&material,
0.0f,
dimension2d< f32 >(0.0f, 0.0f),
dimension2d< f32 >(1.0f, 1.0f)
);
IAnimatedMeshSceneNode *Obiekt = smgr->addAnimatedMeshSceneNode(Obiekt_mesh);
IMeshBuffer * buffer = Obiekt->getMesh()->getMesh(0)->getMeshBuffer(0);
S3DVertex * vertices = static_cast<video::S3DVertex *>(buffer->getVertices());
Obiekt->setMaterialTexture(0,driver->getTexture("meshes/OakBark.png"));
Obiekt->setMaterialTexture(1,driver->getTexture("meshes/detailmap.jpg"));
Obiekt->getMaterial(0).getTextureMatrix(0).setTextureScale(100,100);
printf("Generating random terrain mesh...\n");
int all = Obiekt->getMesh()->getMesh(0)->getMeshBuffer(0)->getVertexCount();
for(int i = 0; i < all; i+=3)
{
vector3df oldpos;
oldpos = vertices[i].Pos;
vertices[i].Pos += vector3df(0,rand()%5,0);
for(int b = 0; b<all; b++)
{
if(vertices[b].Pos==oldpos) vertices[b].Pos = vertices[i].Pos;
}
printf("Vertex: %i%%\r",i*100/all);
}
printf("Done.\n");
Terrain made by this function is ugly.. who knows better way to do it?
and how i can subdivide vertices in this mesh to make terrain smooth?
Nerexis
Sorry for bad English.
Sorry for bad English.
look in a app like photoshop, gimp, milkshape3d or blender and you can render a heightmap/'clouds' which is just a grayscale texture created using perlin noise (look it up) which randomises the image. Then you can load that image as a heightmap in irrlicht (have you looked at the terrain example?), et voila, lovely terrain.
I read about perlin noise and i editted my code:
NoiseFunction:
Generated terrain is almost good but i dont why it looks like that:
Whats wrong??
Code: Select all
all = Obiekt->getMesh()->getMesh(0)->getMeshBuffer(0)->getVertexCount();
for(int c = 0; c<all; c++)
{
vector3df oldpos;
oldpos = vertices[c].Pos;
float perlin_noise;
for(int d = 0; d<5; d++)
perlin_noise+=NoiseFunction(rand()%10000);
vertices[c].Pos.Y = perlin_noise;
for(int b = 0; b<all; b++)
{
if(vertices[b].Pos==oldpos) vertices[b].Pos = vertices[c].Pos;
}
printf("Vertex: %i%%\r",c*100/all);
}
Code: Select all
float NoiseFunction(int x)
{
x = (x<<13) ^ x;
return ( 1.0 - ( (x * (x * x * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824.0);
}
Generated terrain is almost good but i dont why it looks like that:
Whats wrong??
Nerexis
Sorry for bad English.
Sorry for bad English.
-
- Posts: 1691
- Joined: Sun May 18, 2008 9:42 pm
ummm
You could just have like ten different hightmaps generated in photoshop, with a cloud filter, and load them based on a randomly generated number,
like "if integer = 1 load heightmap 1,
or else load heightmap 2".
like "if integer = 1 load heightmap 1,
or else load heightmap 2".
That would be illogical captain...
My first full game:
http://www.kongregate.com/games/3DModel ... tor#tipjar
My first full game:
http://www.kongregate.com/games/3DModel ... tor#tipjar