0
$\begingroup$

I have an array of z coordinates and I want to generate a terrain. I don't understand how to do it.

enter image description here

In java it was simple:

float[] heightmap = new float[2048];
TerrainQuad terrain = new TerrainQuad("terrain", 65, 2049, heightmap);

But in Blender I can't do it.

While i was experimenting generate meshes in blender api, blender crashed several times, and i don't have the code to show my attempts. Just that... enter image description here

$\endgroup$
1
  • $\begingroup$ Have you tried going into edit mode ? You're creating a single face between 4 vertices that have random coordinates, of course it will create something horrible. Try using triangles only $\endgroup$
    – Gorgious
    Commented Jun 26, 2023 at 8:14

1 Answer 1

0
$\begingroup$

AI Icon Warning, Potential AI generated content⚠️

This post is suspected to have been generated with the help of an artificial intelligence, chat bot, or other language model tools without proper attribution.

There is reason to believe this post was not written by a human due to its structure, and grammatical construction, and has been marked by our community.
Current AI chat bots are a language models, that means they are like a parrot, they can mimic human language well, but they are built to write seemingly logical, seemingly factual grammatically valid text, rather than actually be correct, like a human would.
The veracity of the following content cannot be ascertained. See the Concerns regarding AI generated content.

ChatGPT generated a code for me and it works. Instead of a random Z value array, I put a heightmap, and the correct value of the size.

import bpy
import numpy as np

# create a 2D z array
size = 10
z_array = np.random.rand(size, size)

# create a new mesh
mesh = bpy.data.meshes.new('MyMesh')

# define vertices from z array
verts = []
for i in range(size):
    for j in range(size):
        z_value = z_array[i][j]
        verts.append((i, j, z_value))

# define faces
faces = []
for i in range(size-1):
    for j in range(size-1):
        a = i * size + j
        b = i * size + (j+1)
        c = (i+1) * size + j
        d = (i+1) * size + (j+1)
        faces.append((a, b, d, c))

# create the mesh object
mesh.from_pydata(verts, [], faces)
mesh.update(calc_edges=True)

# create a new object and link it to the scene
obj = bpy.data.objects.new('MyObject', mesh)
bpy.context.scene.objects.link(obj)
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .