City Generator Scripting

For x in range (0,2) adds 4 tiles and moves the spawner forward not right:D


import bge,random


scene = bge.logic.getCurrentScene()
spawner = scene.objects['spawner']


def addtiles(cont):
    own = cont.owner
    tiles = []
    
    for obj in scene.objectsInactive:
        if 'tile' in obj:
            tiles.append(obj)


    for x in range(0,2):
        scene.addObject(random.choice(tiles),'spawner',0)
        spawner.worldPosition[1] += 8


        if x >= 1:
            spawner.worldPosition[1] = 0
            spawner.worldPosition[0] += 8
            
                
        
    
    

For some reason I think that this had to add 3 squares, but it adds 4!

I think it’s because is doing it twice. Once when the controller gets activated and again when it deactivates.
I made another road generator that had a feedback effect or runaway effect and crashed Blender. LOL
Like one segment spawns 3 more and those 3 spawn the first one again which adds 3 more again for each and it’s going to crash.

Attachments

Tile System 003.blend (107 KB)

Here is a blendfile of dynamic terrain loading.

http://www.pasteall.org/blend/36377

It doesn’t appear to be dynamic terrain!

Sorry, i had to correct it.I had to add the other ground plane on another layer.And put the trees and leaves on that layer as well.The player
is from blueprintrandom and the dynamic terrain loading and ground planes are from yule.I made the trees from the addon that comes with blender.

http://www.pasteall.org/blend/36378

I don’t understand that dynamic loading example. Is it loading tiles from hard drive or it just adds the tile from second layer ?

Adding tiles from a second layer.

I’m trying to make an automatic road builder for the city generator where it takes road segments from second layer and assembles a road but this is what I get. The logic circuit is a bit screwy because I have to force it somehow to not align anymore segments that where aligned already.

Attachments

autoAlignB.blend (90.3 KB)

Here is one that is almost doing it. Come on people we need an automatic road builder/assembler/constructor.

Attachments

autoAlignC.blend (89.6 KB)autoAlignD.blend (96.4 KB)


import bge,random


scene = bge.logic.getCurrentScene()


def align(cont):
    own = cont.owner
    
    if not "init" in own:
        own["init"] = True
        objlist = []       
        
        for obj in scene.objects:
            if 'road-segment' in obj:
                objlist.append(obj)
                
        random.shuffle(objlist)
        
        own["objlist"] = objlist
        own["open"] = []
    
        
    if len( own["objlist"] ):
        newTile = own["objlist"].pop()
        
        newTile.worldPosition = (0,0,0)
        
        if len(own["open"]):
            presentTile = own["open"].pop()
            presentTileJoint = presentTile.children[0]
            newTile.worldPosition = presentTileJoint.worldPosition
            newTile.worldOrientation = presentTileJoint.worldOrientation
        
        own["open"].append(newTile)

For the D example.
I would really advise against using your current method.
You would do better by using a graph later on.
Eliminate overlaps and much more adaptive layouts.

Offtopic, sad that there were no T Y X etc intersections…

Attachments

autoAlignD.blend (208 KB)

what about making a few nodes, that are connected via a path finding algorithm? (like smoking mirror has done?) I think you can get that .blend in resources even?

something that generates X’s Y’s T’s? maybe something that adds little dead end streets later?

maybe even a round about generator?

then populate the road with a base house mesh, that is the target of a system like where the faces move to match the geometry and use a atlas… grab the uv’s out of the host mesh somehow?

this way, it’s all 1 draw call for all the buildings.

Ok I see. First I have to add T-Y-X-O intersections but you guys are talking about some super complication in script. I need a road segments assembler that even kids can understand. Something at noob-ish level. Did SmokyMirrors make a road generator with nodes or that blend file is something else ?

Hey VegetableJuiceF, I tried your code and it’s doing something different but it still has same problems as mine. Some of the segments don’t look aligned properly while others seem to align pretty good.

import bge
cont = bge.logic.getCurrentController()
own = cont.owner
reset = cont.sensors['reset']
if 'init' not in own:
    own['PhysicsList']=[]
    own['CloseList']=[]
    for objects in bge.logic.getCurrentScene().objects:
        if 'PhysicsMesh' in objects:
            own['PhysicsList'].append(objects)
        if 'centroid' in objects:
            own['Center']=objects
if reset.positive:
    own['CloseList']=[]
    index=0
    for objects in own['PhysicsList]:
        if objects.invalid:
                  own['PhysicsList'].pop(index)

        else:
            if own['Center'].getDistanceTo(objects)<Max and objects['Populated']==False:
                own['CloseList'].append(objects)
        index+=1

here is the logic to build a list of physics meshes,
solarlune has a method where he has a single ‘gfx’ mesh, and he moves all the faces to match physics cubes in the scene,

now I need something from the gpu culling data, to build a list of any culled faces (outside the draw)

and move those to objects on the closelists faces, and then pop the item from the close list…

so the faces that are to far away to be seen are moved (x per frame)

this way, the whole world is 1 draw call. :smiley:

but you HAVE to use a texture atlas, even for grass :expressionless:

The thing is, your problem is because of your broken road block:


It’s orientation is wrong. Nothing wrong with my script.
EDIT:after fix image:

What mine does differently is that it does not place two tiles on the same empty, what yours did.
(even though you tried to avoid that it seems)

  1. The problem with it being easy as kids stuff, is that kids can understand that solid objects can’t intersect, but blender can’t. So to how to you plan to avoid intersection?
    Also, random road generation can be create small dense circle or a long line. Neither would look appealing.

I forgot to apply rotation and scale that’s why it was not doing it properly. This is what we have so far after some fixing and stuff.
How do I intend to prevent intersections ? Most likely we are going to get into ray casting or something. I have to try a few things first.

If ray length matching current segment hits something pick a different segment … Randomly … It needs to be 100% random so it can surprise me. If it’s too predictable is not going to be interesting enough.

Press P to watch it work … LOL … work it , work it … It’s about time the computer starts doing some work for us.

Attachments

autoAlignE.blend (176 KB)

Hey Blueprint, It looks likes I missed your post about the physics code. Is that some optimization to enable collisions only where they are needed ? I’ll have to check it out it’s just going to take me forever to figure out all this code.

I’m hypnotized when I watch this thing construct roads (the one that VegetableJuiceF made). Sometimes the roads look like race tracks , other times they look like the floor plan of a building. Other times you get lots of circles.

Another idea is to actually place an intersection segment where things start to overlap but I have no idea yet how to detect that with code.

This blend should help you understand i hope.

[ATTACH]382441[/ATTACH]

How about monster’s blend for inspiration.Here it is.

[ATTACH]382442[/ATTACH]

Here is another version. This one has intersections added but the script is not cycling to collect all children so that it links all of them. This also explains why I didn’t want to start with intersections.

Attachments

autoAlignF.blend (240 KB)

Did you look at the blends I gave you?
I would give each road piece a particular property and then align them by that.Maybe somebody can make a example for you if do not get it.