Page 1 of 3
Python code for Boise de Vaux
Posted:
Thu May 13, 2010 6:20 am
by Godot
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.
Re: Python code for Boise de Vaux
Posted:
Thu May 13, 2010 7:41 am
by diafero
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
Re: Python code for Boise de Vaux
Posted:
Thu May 13, 2010 9:18 am
by Godot
I was unable to upload the file as a .txt so I changed it to .rtf
Copy the text into the Blender text window.
- flower.rtf
- you can change the extension to .txt
- (3.23 KiB) Downloaded 399 times
Re: Python code for Boise de Vaux
Posted:
Thu May 13, 2010 9:41 am
by Godot
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()
Re: Python code for Boise de Vaux
Posted:
Thu May 13, 2010 11:41 am
by diafero
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...
Re: Python code for Boise de Vaux
Posted:
Thu May 13, 2010 12:04 pm
by Godot
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.
Re: Python code for Boise de Vaux
Posted:
Thu May 13, 2010 3:22 pm
by Tsar Hoikas
Please embed code inside a [code] bbcode. Thanks.
Re: Python code for Boise de Vaux
Posted:
Thu May 13, 2010 4:28 pm
by Nadnerb
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
Posted:
Thu May 13, 2010 8:21 pm
by Paradox
It shouldn't render objects that are beyond the Yon value set in the .fni file.
Re: Python code for Boise de Vaux
Posted:
Sat May 15, 2010 3:46 am
by tachzusamm
(same as in top post / attached .rtf file, just the formatted code, for easier reading here)
- 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