Import/Make terrain?

Hi, I’m trying to build a world builder and I wonder if you can in some way import or make a terrain outside unity (in a standalone) and the be able to edit it?.

See here: Unity - Scripting API: Mesh

I guess you’d want to have painting of height and stuff which I think would be do-able by casting a ray from the camera to the cursor, and where it hits the terrain model you could tell it to raise the verticies within a certain radius of where the ray hit?

I think theres also a script floating around somewhere (maybe on the unify wiki) which will allow exporting of a mesh as an OBJ if you also want to export the mesh.

I would have thought importing a mesh would also be possible relativley easily although I’m not sure how off the top of my head; I’m sure someone else more knowledgable can reply and tell you :).

Hi.
Thanks for your tips, although I tried another thing, and I run into a problem,
when trying to use TerrainData.SetHeights (see script reference) it does not accept a float[ ] it says:

The best overload for the method ‘UnityEngine.TerrainData.SetHeights(int, int, (float, 2))’ is not compatible with the argument list ‘(int, int, (float))’.

Do you know what that can mean?

It needs a 2-dimensional float array–that’s what (float, 2) means. For some reason you can’t make a 2D float array in Javascript from scratch (or 3D for that matter), but you can get one by using GetHeights. Or you can use C#.

–Eric

Eric,

Is it difficult to paint some extra trees on an allready existing terrain using scripts ?

I am using a terrain which I set its height myself based on a heightmap texture, but now I would like to make function which could for example place 100 instances of a tree onto the terrain, but only at places where the terrain is between 50 a 100 units high.

Possible? Impossible? Difficult ?

I know I could just instantiate tree GOs, but the purpose is that they should be picked up by the terrain engine to do the billboarding trick in the distance.

That’s possible, but it uses undocumented APIs, and offhand I don’t know what they are. Anything that’s done with the terrain editor in Unity can be done with scripts, since the editor itself is a C# script.

–Eric

Hi.
Now I have managed to make 2 scripts, one to import a heightmap(running in game) and one to paint height on the “real” terrain. Although the height paint script is running quite slow (even though I have made some really big optimisations), I have a plan for an even greater optimisation but for that I have to get my script into c (I can’t make 2 dimensional arrays in .js) so I wonder if someone can help me, because I’m not so good at c?

Here is the script:

95101–3709–$terrainheight_801.js (2.41 KB)

There is a really simple vehicle demo, made by Ctrl-J (I don’t know his Username). I have provided a copy, since it uses a really cool script to make editable terrain. Open 'er up and give it a try! I have made a working prefab of the editable terrain and attached it. I don’t know how to make the terrain go down, but you can paint it, and raise it, and it works really fast (single click, 1m x 1m squares).

95143–3710–$editableterrainprefab_107.zip (2.28 KB)

Hi, thanks, but it could be good if you provided the script (make a Unity Package).

/Aron