Using XNA. Unfortunately, when I bring up this old project and convert it to Visual Studio 2010 it will no longer compile and just throws tons of errors.
I'm looking for something very simple. Is there a 3D terrain single texture XNA example floating around out there that I can convert? I haven't touched XNA since about 2009 or 2010 and none of my old code will run anymore (I have no idea what's going on).
I need to do a 3D terrain proof of concept where the terrain texture is stretched over the height map. Nothing fancy. Maybe XNA.
Generate a set of vertices that form a grid made of triangles in a regular pattern like
A -- B -- C -- ...
| \ | / | \
| \ | / | \
D -- E -- F -- ...
| / | \ | /
| / | \ | /
... ... ...
Each of A, B, C, et cetera represents a vertex in the grid. It also represents a point on the height; read the height value from the map at the appropriate point and use that times some scalar factor to set the Z coordinate of the vertex.
You can generate the UVs at each point by stepping by (1 / number of cells) in either dimesion; this will let you easily map your texture onto that geometry as well.
Then render the geometry with your color map.
July 15, 2016 22:33 PM
I have been able to do this using the 3d modeling software Blender. I used UV mapping to map the texture and the displacement modifier to apply the height map. If you need some form of XNA code for this, I cannot supply it. Here it is as a 3d terrain. Surprisingly, it worked best on a uniformly square mesh.
The steps required to create the terrain like i did in blender:
Download blender for your operating system from here.
Install and open blender.
Delete the default cube by right clicking on it and hitting Del then Enter.
Press shift-a and select Mesh->Plane from the dialogue box that pops up and press Enter.
Scale it up a bit by pressing s and dragging your mouse towards the corner of the screen. Then press Enter.
At the bottom of the window, towards the left, you will see a dialogue box that says Object Mode. Change that to Edit Mode.
Make sure the whole plane is selected. The edges, vertices and faces will be highlighted in orange if it is selected. If it is not, press a to select all of the mesh.
Press w and select Subdivide from the dialogue box that appears. Do this about 5 times.
On the far left towards the bottom of the screen, you will now see a new section appear with one field being called number of cuts. Change it from 1 to 8 or whatever resolution you want for your terrain.
Now with the whole plane selected, press u and select unwrap from the dialogue box. This will take more time if you did more subdivisions.
On the center top of your screen, select the dropdown menu that says Blender Render and change it to Cycles Render.
On the middle right hand side, you will see a window section with small buttons that look like a camera, a photo, some primitive shapes, a globe, etc. Click on the button that looks like a tiled sphere.
Click on the button that says New. You have now created a new material. To apply the image to your plane, on the section that says Surface, go to the field called Color and click on the small dotted box next to the color. From the popup box, under Texture select Image Texture.
Navigate to your image and select it.
Now, making sure you are in Edit Mode, select the whole plane and press u and select Unwrap from the dropdown menu. This may take your computer anywhere from 10 seconds to 2 minutes and the program may freeze depending on how many subdivisions you did.
Navigate back to the window with all the buttons and look at the top left of that window. You should see a symbol that looks like two pills with up and down arrows next to it. Select it and select UV/Image Editor from the dropdown menu.
At the bottom of the UV/Image Editor window, you should see a button that says Open. Select it and navigate to your texture again. That should do it for texturing.
If the orange rectangle (your mapped mesh) doesn't perfectly fit the rectangle of the texture, scale the rectangle in the UV/Image Editor window with s. Then press x for x axis scaling or s and then y for y axis scaling. And move it with g and x for x axis translation and g and y for y axis translation. Press enter each time you finish a transformation/scale. Try to fit the rectangle as well as you can to the image. Otherwise, just leave it as is.
Navigate back to the button you clicked at the top left of the window (it is now on the bottom left) where the pills were previously and now the UV/Image Editor icon (looks like a photo of a sunset) is and select Properties (the pill icon) from the dropdown menu.
Now from the buttons, select the one that looks like a wrench. Select the Add Modifier dropdown and select the Displace option from the dropdown menu.
Where you see the Texture section of the Displace modifier, click the New button.
Where the tiled sphere, primitive shape, wrench, etc are, select the one that looks like a tiled square.
From the dropdown box where it says Image Texture select Displace - Texture instead.
In the Image section, select Open and find your height map and select it.
Click on the Image Mapping section and select Clip.
Switch to Object Mode and see how the displacement map worked out. If there's a section that looks too straight on the edge either going straight up or dipping down, go back to edit mode, select your plane with a, and scale it up or down a tiny bit with s. Keep doing this until it's fixed.
Go back to the wrench and in the Displace modifier, change the strength to something like .2
Now to view the model textured, next to the Object Mode dropdown, there is a sphere dropdown. Select texture instead of solid.
As one final step, there is a window on the top left with a section called Shading. Click on smooth. And you should get something like the results below.