Planet Generation - 3

Step by step how to generate a planet made of tiles, and it can generate multiple LOD’s we can store, to later use in BPY to make single tiles with multiple LOD levels.

if anything is unclear don’t hesitate to ask questions.

1 Like

it looks like mathutils.geometry.normal is broken - ended up getting a solution from stack exchange using numpy

1 Like

almost able to re-create meshes in bpy

import bpy
import pickle
import bmesh
from mathutils import Vector

    path =  bpy.path.abspath("//")
    file = "Planet_data.txt"
    with open(path+file, 'rb') as f:
        MasterList = pickle.load(f)
    print('loaded patch data from disk')
    print('failed to load')    

scn = bpy.context.scene

patch =['Patch']
for entry in MasterList:
    new_obj = patch.copy() = ="Gen_Patch_"+str(entry)
    new_obj.location = MasterList[entry]["Pos"]
    new_obj.rotation_euler  = MasterList[entry]["Rot"]
    print('added a mesh') = new_obj
    bpy.ops.object.mode_set(mode = 'EDIT')
    bm = bmesh.from_edit_mesh(
    colors =
    if not colors:
        colors ="Col")
    for i in range(MasterList[entry]["L"]):
        data = MasterList[entry][i]
        bm.verts[i].select = True
        verts = [ v for v in bm.verts if ]
        if verts:
            colors =
            if not colors:
                colors ="Col")
            for v in verts:
                for loop in v.link_loops:
                    loop[colors] = data[1]
                v.normal = data[2]
       = Vector(data[0])


so - here is the code I am pickling the meshes with

        import pickle
        if 'saved' not in own:
                path = bge.logic.expandPath("//")
                file = "Planet_data.txt"
                with open(path+file, 'rb') as f:
                    MasterList = pickle.load(f)
                print('loaded patch data from disk')
                print('failed to load')
                MasterList = {}
            for entry in own['quads']:
                target = own['quads'][entry][4]
                L = target.meshes[0].getVertexArrayLength(0)
                TileDict = {"Pos":tuple(target.worldPosition),"Rot":tuple(target.worldOrientation.to_euler()), "L":L }
                for index in range(L):
                    vert = target.meshes[0].getVertex(0,index)
                    pos = tuple(vert.XYZ)
                    color = tuple(vert.color)
                    norm = tuple(vert.normal)
                    TileDict[index] = (pos,color,norm)
                MasterList[entry] = TileDict
            print('generated patch data')
            path = bge.logic.expandPath("//")
            file = "Planet_data.txt"
            with open(path+file, 'wb') as f: 
                pickle.dump(MasterList, f) 
            print('saved pickle')

ok I have it working kinda, it looks like the vert index is different in bpy, will have to sort the patch array vertex and compare arrays to make a converter.

ok I have generated a vertex array in bpy

now I can use a vertex array[x][y] to set it’s data instead of index, since bpy index seems a little different than upbge index.

got it working !

I have a issue though in that the generated mesh vertex are invisible :stuck_out_tongue:
code that is making ‘ghost’ meshes

getting close though, livin’ the dream.

I did it!

mesh generated in game / manipulated in game can be saved and exported to bpy


the key to matching up a bpy mesh, and bge mesh is sorting mesh into a vertex array

array[x][y][z] = vert_index

one in bge, one in bpy.

so now we can deform kit instances, build levels - save the level - regenerate in bpy.

ok shit just got real.

can there be more one planet with gravity?Can I have spaceships that I can fly from one planet to other with this?

I can add more planets etc, however now the focus is getting the 1 streaming at 60 fps at a decent speed.

testing batch grouping the highest LOD level of tiles


engine 4,096 tiles

current progress - trying to generate UV

what are you going to do to add houses and streets to the planets?that would be hard

to do without using an algorithm.

Ok ! now the generated terrain has UV - so I can bake vertex color over to a cube map

here is 1/6th a cubesphere

perfs with 4096 tiles joined as 1 object

uv’s cube map unwrap - baking of vertex color - second uv layer (cube projected unwrap)