473,503 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can, and if yes how could this be done elegant?

I'm currently developing vegetation creation scripts for the
Blender 3D modelling software. The first attempts work nice, but
they're far to inflexible IMHO.

First let me introduce how the system works: The user supplies a
series of building elements of the plants to be generated (e.g.
stem, stipe, leaf, branches, blossom) and associated those with
template 3D models. For each of those elements there is a list,
which elements can be attached with the current element, and a
probability function, that takes the various parameters for the
element to be constructed (distance to the last branch, distance
to the root, thickness of the last stipe, how much light is
there). Then a pseudo random generator chooses one of the given
elements with the given probability, the element is aligned to
various physical conditions (gravity, light direction). It is
important, that the tree is constructed with a equal distance to
the root, i.e. not whole branches and subbranches at a time, but
first branching level 0, then level 1 and so on. The reason is,
that with every construction level some of the environment
condictions (weight of the material, amount of light) change, so
it's reasonable, that the grow process of the virtual plant
resembles the real one, even if it's a simplified modell.

Now one cool thing would be, if one could use python to describe
the plant model itself, too.

Since the Elements are not to be instanciated, but a collection
of parameters and functions that are fed with the environment
variables.

class Branch(BasicPlantElement):
def p():
return light_scale * light()**light_exponent *
k/distance_to_root()
def geom():
return (light_track * light_vector() - weight() * gravity(),
position())

But obviously this is not valid python (it lacks the self
argument). One might now think of a dictionary

Branch = { "p"=lambda:..., "geom"=lambda:..., }

If you look closely, you also see, that the functions are not
prameterized. Instead, they use some global scope functions.
Here the idea is, that the environment parameters are put on a
stack and each recursion copies the topmost element on the stack
and changes happening there are carried on the stack. But this
is of course very memory consuming. But the real problem is, to
bring those values somehow into the scope of the PED (Plant
Element Descriptor)

Now the challenge:
- I'd like to write the Plant Element Descriptors in a
class/member like notation, but don't instanciate it - not
directly at least. Eventually there will be factory functions,
that take a PED and create a reparameterized version of it.
- Calling the functions in the PED somehow needs to bring the
branching stack into the scope. I have no idea how to do that.

Of course all this might not be possible directly, but that would
then mean, that I can't use python to describe plants, but have
to invent a custom language for that then. (Something like POV
Scene Description Language or similair).

Wolfgang Draxinger
--
E-Mail address works, Jabber: he******@jabber.org, ICQ: 134682867
GPG key FP: 2FC8 319E C7D7 1ADC 0408 65C6 05F5 A645 1FD3 BD3E

Aug 22 '06 #1
1 1465
Wolfgang Draxinger wrote:
I'm currently developing vegetation creation scripts for the
Blender 3D modelling software. The first attempts work nice, but
they're far to inflexible IMHO.

First let me introduce how the system works: The user supplies a
series of building elements of the plants to be generated (e.g.
stem, stipe, leaf, branches, blossom) and associated those with
template 3D models. For each of those elements there is a list,
which elements can be attached with the current element, and a
probability function, that takes the various parameters for the
element to be constructed (distance to the last branch, distance
to the root, thickness of the last stipe, how much light is
there). Then a pseudo random generator chooses one of the given
elements with the given probability, the element is aligned to
various physical conditions (gravity, light direction). It is
important, that the tree is constructed with a equal distance to
the root, i.e. not whole branches and subbranches at a time, but
first branching level 0, then level 1 and so on. The reason is,
that with every construction level some of the environment
condictions (weight of the material, amount of light) change, so
it's reasonable, that the grow process of the virtual plant
resembles the real one, even if it's a simplified modell.

Now one cool thing would be, if one could use python to describe
the plant model itself, too.

Since the Elements are not to be instanciated, but a collection
of parameters and functions that are fed with the environment
variables.

class Branch(BasicPlantElement):
def p():
return light_scale * light()**light_exponent *
k/distance_to_root()
def geom():
return (light_track * light_vector() - weight() * gravity(),
position())

But obviously this is not valid python (it lacks the self
argument). One might now think of a dictionary

Branch = { "p"=lambda:..., "geom"=lambda:..., }

If you look closely, you also see, that the functions are not
prameterized. Instead, they use some global scope functions.
Here the idea is, that the environment parameters are put on a
stack and each recursion copies the topmost element on the stack
and changes happening there are carried on the stack. But this
is of course very memory consuming. But the real problem is, to
bring those values somehow into the scope of the PED (Plant
Element Descriptor)

Now the challenge:
- I'd like to write the Plant Element Descriptors in a
class/member like notation, but don't instanciate it - not
directly at least. Eventually there will be factory functions,
that take a PED and create a reparameterized version of it.
- Calling the functions in the PED somehow needs to bring the
branching stack into the scope. I have no idea how to do that.

Of course all this might not be possible directly, but that would
then mean, that I can't use python to describe plants, but have
to invent a custom language for that then. (Something like POV
Scene Description Language or similair).
Let me see if I understand:

You have a bunch of physical parameters (gravity, light
direction,etc.).

Every time you recurse to a deeper level, all these physical parameters
change (I suppose because there's a transformation of coordinates).
When creating a new Branch, using some data called Element as a kind of
template, you want to first update the parameters to their new values,
then use those parameters to create a new Branch. And you hope that
you can do both things (update parameters, generate branch) with a
single class. How close am I?

You're doing this recursively, so there's really no way to get rid of
the stack entirely. I don't know much about your code, but I quite
doubt that it would put much strain your memory at all.

We can, perhaps, help you organize your code better, though. But I
think you'll need to make another pass at describing your problem.
Carl Banks

Aug 22 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2034
by: steve | last post by:
Hi, In my script (phpnuke), whenever there is access to database, there is this line of code: message_die(GENERAL_ERROR, ’some error msg’, ’’, __LINE__, __FILE__, $sql); Is there a more...
9
2248
by: William S. Huizinga | last post by:
I've got an array.array of unsigned char and would like to make a slice of that array (e.g. a) become one long like I would in "C" : l = ((unsigned long *) (&a)); I have been getting what I...
2
3989
by: Dave | last post by:
Whenever I try to load a bitmap using the standard code: Bitmap myBitmap = new Bitmap(this.GetType(), "bitmapResourceName") I always end up with an error of the form "Resource...
28
3017
by: Rob Cowie | last post by:
Hi all, I wish to generate a sequence of the form 'aaa', 'aab', aac'.... 'aba', 'abb', 'abc' etc. all the way to 'zzz'. How would you construct a generator to acheive this? A simple,...
18
1961
by: _dee | last post by:
Question about best use of interfaces: Say there's a 'Master' class that needs to implement a few interfaces: class Master : I1, I2, I3 { } The actual code already exists in smaller...
32
1997
by: r.z. | last post by:
class vector3 { public: union { float data; struct { float x, y, z; };
5
3701
by: Helmut Jarausch | last post by:
Hi, I'm looking for an elegant solution to the following (quite common) problem: Given a string of substrings separated by white space, split this into tuple/list of elements. The problem...
3
1561
by: Anonymous | last post by:
I want to be able to restrict the set of classes for which a template class can be instantiated (i.e enforce that all instantiation MUST be for classes taht derive from a base type BaseType). ...
12
1303
by: Helmut Jarausch | last post by:
Hi, I'm looking for an elegant solution of the following tiny but common problem. I have a list of tuples (Unique_ID,Date) both of which are strings. I want to delete the tuple (element) with...
0
7203
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7087
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7334
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6993
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7462
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5014
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3168
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
737
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.