Shorah all
I have developed a python script that I use to automagically generate the forest for my age of Vaux. I thought that it might be useful to the community as inspiration and as a learning tool for new python coders. I have stripped out some of the details to make it easier to understand but it is still useful as a demo. Just copy the script to a text window in Blender and run it on a default project. It will draw the tree trunks on the fly and distribute them in a Fibonacci distribution. The distribution is spread out (forest size) so you will need to scroll out to a larger scale to see the result. This code can also be used to create realistic flowers. I hope you can have fun with it.
See the code below. Thank you tachzusamm.
Python code for Boise de Vaux
Python code for Boise de Vaux
Last edited by Godot on Sat May 15, 2010 7:44 am, edited 4 times in total.
-
- Deep Island Admin
- Posts: 2972
- Joined: Mon May 05, 2008 5:50 am
- MOULa KI#: 0
- Location: Germany
Re: Python code for Boise de Vaux
Thanks a lot for sharing 
The indention got completely lost, could you perhaps upload it as attachment? Oh, and I'd be interested in some screenshots

The indention got completely lost, could you perhaps upload it as attachment? Oh, and I'd be interested in some screenshots

I prefer e-mails to "diafero arcor de" (after adding the at and the dot) over PMs.
"Many people's horizon is a circle with a radius of zero. They call it their point of view."
Deep Island Shard | Offline KI
"Many people's horizon is a circle with a radius of zero. They call it their point of view."
Deep Island Shard | Offline KI
Re: Python code for Boise de Vaux
I was unable to upload the file as a .txt so I changed it to .rtf
Copy the text into the Blender text window.
Copy the text into the Blender text window.
Last edited by Godot on Thu May 13, 2010 7:21 pm, edited 1 time in total.
Re: Python code for Boise de Vaux
This is a simple version of what Boise de Vaux looks like from the top view except that Vaux has the treetop foliage. The central opening contains the lumber mill and paper mill. The gap between the woods contains the cottage and gardens along with a maze so that the player can explore and discover elements of the story. The edge of the age is blocked by a hedge along the inside of the outer forest. The background is beyond the outer edge of the outer forest. The forest of Vaux has 5000 trees in the center and 1000 in the outer forests. This takes quit a long time to render with my current computer with all of the textures and branches etc. The top level code to generate this scene;
scn = Blender.Scene.GetCurrent()
forest(100, 500, 7) # inner woods
forest(1000, 500, 7) # outer woods
Blender.Window.Redraw()
scn = Blender.Scene.GetCurrent()
forest(100, 500, 7) # inner woods
forest(1000, 500, 7) # outer woods
Blender.Window.Redraw()
- Attachments
-
- test run
- treetopview.jpg (290.97 KiB) Viewed 9603 times
-
- Deep Island Admin
- Posts: 2972
- Joined: Mon May 05, 2008 5:50 am
- MOULa KI#: 0
- Location: Germany
Re: Python code for Boise de Vaux
You might also try to zip the text file, that should be accepted as attachment.
Wow, indeed this looks naturally distributed. However I fear Uru will not be able to render such huge amounts of trees, or flowers, or whatever...
Wow, indeed this looks naturally distributed. However I fear Uru will not be able to render such huge amounts of trees, or flowers, or whatever...
I prefer e-mails to "diafero arcor de" (after adding the at and the dot) over PMs.
"Many people's horizon is a circle with a radius of zero. They call it their point of view."
Deep Island Shard | Offline KI
"Many people's horizon is a circle with a radius of zero. They call it their point of view."
Deep Island Shard | Offline KI
Re: Python code for Boise de Vaux
The game engine only renders objects that are within the view of the player. I also use mist to limit the field of view.
The idea is that the forest needs to be large enough that the player can feel lost and isolated.
I use a modified version of this code to generate flowers then create a texture from the render.
The texture is then added to a simple geometry for the game.
I have been able to download the code file by clicking on the link.
The idea is that the forest needs to be large enough that the player can feel lost and isolated.
I use a modified version of this code to generate flowers then create a texture from the render.
The texture is then added to a simple geometry for the game.
I have been able to download the code file by clicking on the link.
-
- Councilor of Technical Direction
- Posts: 2180
- Joined: Fri Nov 16, 2007 9:45 pm
- MOULa KI#: 23335
- Location: South Georgia
- Contact:
-
- Posts: 1057
- Joined: Fri Sep 28, 2007 8:01 pm
- MOULa KI#: 23247
- Location: US (Eastern Time)
- Contact:
Re: Python code for Boise de Vaux
Godot wrote:The game engine only renders objects that are within the view of the player.
In the case of Plasma, this is not entirely true. It does do frustrum culling, such that only objects that you're facing are rendered, but it doesn't do any kind of occlusion culling, (ie, not rendering objects hidden by other objects) and I'm not entirely clear on what it does about objects that are beyond the max z depth. ("beyond the mist") Generally visibility concerns in large ages are handled in plasma by the use of manually placed regions that control whether an object is drawn or not.
Re: Python code for Boise de Vaux
It shouldn't render objects that are beyond the Yon value set in the .fni file.
- tachzusamm
- Posts: 575
- Joined: Thu May 29, 2008 2:03 am
- MOULa KI#: 0
- Location: Germany
Re: Python code for Boise de Vaux
(same as in top post / attached .rtf file, just the formatted code, for easier reading here)
Oh, by the way:
Nature by Numbers

Code: Select all
""" flower of Fibonacci
uses the golden mean, phi, to generate coordinates for
objects to be arranged in a natural order.
A two dimensional graph of the data will resemble a sunflower.
The angular displacement between buds is (phi * 360) or
222.5 degrees (137.5)
PARAMETERS:
firstBud -- relative location of the start of the distribution
Default = 1 is the center of the scene
numBuds -- the number of coordinates to be generated.
The z dimension is set to 0.0 to allow the
user of the data to set the elevation.
scale -- set the average distance between buds.
default value = 1 Blender unit.
"""
#================================
import math
def flower(firstBud = 1, numBuds = 1, scale = 1):
locations = []
phi = (math.sqrt(5) - 1) / 2
radians = 2 * math.pi * phi
for index in range(firstBud, firstBud + numBuds + 1):
distance = math.sqrt(index) * scale
angle = index * radians
coord = []
coord.append(distance * math.cos(angle))
coord.append(distance * math.sin(angle))
coord.append(0.0)
locations.append(coord)
return locations
#================================
import Blender
from Blender import *
import bpy
def stump():
coords = [[1.0,1.0,0.0], [1.0,-1.0,0.0], [-1.0,-1.0,0.0], [-1.0,1.0,0.0],
[1.0,0.333333,0.0], [1.0,-0.333333,0.0], [0.333333,1.0,0.0],
[-0.333333,1.0,0.0], [-1.0,-0.333333,0.0], [-1.0,0.333333,0.0],
[0.333333,-1.0,0.0], [-0.333333,-1.0,0.0],
[1.0,0.333333,20.0], [1.0,-0.333333,20.0], [0.333333,1.0,20.0],
[-0.333333,1.0,20.0], [-1.0,-0.333333,20.0], [-1.0,0.333333,20.0],
[0.333333,-1.0,20.0], [-0.333333,-1.0,20.0]]
faces = [[0,6,4], [10,1,5], [2,8,11], [3,7,9],
[4,5,13,12], [6,7,15,14], [4,6,14,12], [9,8,16,17],
[11,10,18,19], [10,5,13,18], [9,7,15,17], [11,8,16,19]]
me = bpy.data.meshes.new('Stump') # create a new mesh
me.verts.extend(coords)
me.faces.extend(faces)
return me
#================================
def forest(firstTree, numTrees, scale):
locations = flower(firstTree, numTrees, scale)
me = stump()
for index in range(0, numTrees):
tree = scn.objects.new(me, 'stump')
x = round(locations[index][0])
if x % 2:
x += 1
y = round(locations[index][1])
if y % 2:
y += 1
z = locations[index][2]
tree.setLocation(x, y, z)
#================================
# prepare the scene
scn = Blender.Scene.GetCurrent()
forest(100, 100, 7)
Blender.Window.Redraw()
Oh, by the way:
Nature by Numbers
