Cinema 4D Cinema 4D Visualize, Broadcast, Studio MoGraph Other Objects and Tags MoSpline
Function available in CINEMA 4D Broadcast, Studio
MoSpline

Basic Coord. Object Simple Turtle Values Spline Effectors Fields

Turtle

The parameters in the Turtle and Values tabs are meant for advanced users with programming experience (these tabs contain an entire L-System). Those of you with little or no programming experience should, however, not be scared off. In the following are several variable examples.

Make sure you first set Mode to Turtle.

Brief introduction to L-Systems

In the following pages, the L(indenmayer)-Systems are briefly explained. Additional books or online resources are available that offer an in-depth explanation of these systems (the pdf document "The Algorithmic Beauty of Plants" from Przemyslaw Prusinkiewicz and Astrid Lindenmayer is based on use with Cinema 4D and can be downloaded at http://algorithmicbotany.org/papers#abop).

L-Systems are usually used for simulating plant growth and similar effects. Combined with MoGraph, these can be used to create spectacular growth simulations by placing a MoSpline object into a Sweep object, thus creating a renderable object (Splines can be rendered directly using Sketch and Toon or HAIR).

Simply put, an L-System executes a series of commands that define how and where new branches should grow. It is a self-producing system that can replace existing branches with new ones.

The basic principles are fairly simple and are based on a system called "Turtle System". A (virtual) turtle is sent on its way via simple commands. This path is represented by a Spline.

The 3 most important commands are:

If you enter the sequence F++F++F in the Premise field it translates to: "Take one step Forward; turn twice to the right; take another step Forward; turn twice to the right; take another step Forward."

How big each step is and how large the angle of rotation is can be defined in the Values tab via the Default Movement and Default Angle values, respectively. Or, as described below, by placing them in parenthesis. If Default Angle is set to 60° a perfect triangle will result for our example:

Two different command codes: left F++F++F; right: F-F++F-F (each with a Default Angle of 60°.

This lets you create branch-like shapes. A very interesting function of L-Systems is its integrated replacement system with which individual branches can be replaced by others. This can also be done recursively, which lets you create very complex branching with simple command codes. If this sounds confusing, the following example can shed some more light on what’s involved:

So far you have only entered single-line command codes that were executed only once. Now enter the following command code into the respective fields:

Premise field: F++F++F

Rules field: F = F-F++F-F

As you can see, the Rules code line contains an assignment (in the following referred to as Rule) in which "F" is assigned several symbols that in turn will (internally) be inserted into the Premise line of code.

If written out in its entirety, the command line code would read as follows (replace the F in the Premise line of code with the code following the "F" in the Rules line of code):

F-F++F-F++F-F++F-F++F-F++F-F

This represents the second shape from left in the image below. Since each F in the Premise code is replaced by the Rule, each straight line will be replaced by the more complex line.

Change of shape when each F is replaced by the "F-F++F-F" code.

And this replacement process can be repeated indefinitely (well, not quite, since your computer will probably throw in the towel after the exponentially increasing complexity of the Splines starts to grow … ). How often this replacement process is repeated is defined by the Growth value, which replaces each F with the Rules code. Incidentally, fractals work the same way.

Of course placeholders can be used as well so that not necessarily each F has to be used. After all, this would be unrealistic for growing formations - growth in length does not always occur only at the end of branches, etc.

For this you can use placeholders (letters that do not represent any Turtle command) such as A, B, C, D, (but NOT "F" because it is the default "one unit forward command").

Type the following into the respective fields:

Premise: FA

Rules: A=+F-FA

Since the Rule ends with an A, an increasing Growth value will result in the formation growing endlessly (Default Angle is set to 90°).

Tip:
This simple-looking replacement rules can create an amazingly complex geometry over several generations (see below). If symbols are used incorrectly you can end up crashing your computer. So be careful when experimenting and save your work often (even in a simple text editor). It is also very helpful if you set Display Mode to Line.

The code we have used so far has consisted of a single, uninterrupted line of code. However, L-Systems first become interesting when real branches are created, i.e., new lines that branch from existing lines. And this can be achieved by using square brackets ([ ]). The command sequence within a square bracket is viewed as a separate branch (and creates a new Turtle). After the branch has been created the turtle will return to the starting point prior to the square brackets and continue with the command sequence following the square brackets.

Type the following into the Premise field:

F[+F][-F[-F]F]F[+F][-F]

This is the result of the command code above with a Default Angle of 30°.

If you now enter F into the Premise field and the above code (F=F[+F][-F[-F]F]F[+F][-F] ) into the Rules field, each F will be replaced by the braches at the left of the image. Increasing the Growth value will let the branch continue to grow because each straight line will be perpetually replaced by a new branch. If you look closely you will see the branch pattern at the left repeated in the tree at the right (highlighted in green).

This is an easy method of creating complex plant-like branching:

Various command codes. Note that any letter (in this example "A") can be used as a placeholder. At the bottom right of the image a Default Angle value of 90° was used.

Until now we have generated everything on a flat plane. Since branching doesn’t only take place on a single plane but in every direction, command symbols exist that also makes this possible.

These are (a degree value can be added in brackets after the command symbols):

& or ^: rotate around the Turtle’s transverse axis

\ or ]: rotate around the Turtle’s longitudal axis

Type the following into the Premise field: F&F\ (90)^F+F:

The 90° after the "/" are not really necessary because the Default Angle value will be applied for small specifications.

The result is the Spline pictured above. The turtle moves forward (F), rotates at a right-angle around its transverse axis (&, Default Angle is set to 90°), moves forward again (F), rotates 90° around its longitudal axis (\ (90)), then 90° around its transverse axis (^), moves forward again (F), turns right (+) and finally moves forward again (F).

If you use this method to create branched spatial formations, real bushes and trees can be created.

User Data

You can use the User Data as variables in a sequence of symbols. In the image above an Angle parameter was added to the User Data that was then substituted in parenthesis for ^ (turtle rotates around transverse axis) in the Premise field.

Special characters and spaces should not be included in the variable names. Underscores are recognized (e.g., "second_length") as is capitalization.

Formulas

Formulas, including defined variables (e.g., F(_growth*2), can be used instead of normal digits. The following are available:

Example "Total/Index"

Let’s say you have the string F(_index)F(_index), which consists of two commands. The string performs the same function as F(1)F(2) (one unit forwards then two units forward). For example, since "_total" is the total number of commands, a spiral can be created with the following command:

Premise: FA

Rule: A=+(20*_index/_total)FA

Example "_RND"

The following command:

Startstring: A

Regel: A=+(_rnd*90)FA

The, _rnd*90’ command will ascertain a random angle between -90 and +90 for each growth spurt, i.e., a "wobbly" line with random rotations will result.

Example "_level"

Let’s say you have the following command:

Premise: A

Rule: A=FA

The following level values will result (shown here in parentheses for demonstration purposes - these will NOT actually be shown):

Growth = 0 : A(0)

Growth = 1 : F(1)A(1)

Growth = 2 : F(1)F(2)A(2)

Growth = 3 : F(1)F(2)F(3)A(3)

Now that you know how the "_index" numbering is done, take a look at the following command:

Premise: FA

Rule: A=+F(_level*10)A

… creates the following spiral with Default Angle set to 90°:

Example "_arg"

Just as you can define F(a,b,c)=F(a*2,b*2,c*2) to set parameters for Turtle commands (in this example F) you can also use the "_arg" command. These don’t have to be evaluated at the beginning. F=F (_arg1*2,_arg2*2,_arg3*2) does the same as the command above.

Advanced syntax variations

The following syntax is also possible:

Premise: F(2)F(1,2)F(2,3)

Rule : F(a,b) = F(a*2,b*2)

All Fs will be replaced and wherever "a" or "b" appear within the Rule existing F arguments will be handled as follows:

F(2*2,1*2)F(1*2,2*2)F(2*2,3*2) which logically equates to F(4,2)F(2,4)F(4,6).

Rule constructs like the following are also possible:

F(a,b):(a>10)=F(a,b)+F(a/2)

This Rule will, for example. only be applied if the value of the first argument is greater than 10.

In the following example both syntax variations above were combined and produce an interesting effect:

Example "fruits"

In the example above, several branches grow simultaneously. When one branch has finished growing a sphere will be placed at the end of the branch (requires the command J, see example: Cloner Object).

Note that "B(6)" is defined in the first Rule and that "B(h-1)" reduces the argument by 1 in Rule 2 until "h=0" finally sets the sphere in Rule 3.

Take a look at the console to see the entire string (but first click on the Result String to Console button).

Further details regarding formulas can be found in the attachment.

Premise

Enter the premise here. This is most often a single-letter command (see Rules) or a placeholder to which content is added in the Rule field. In the following pages you will find numerous examples of how strings can look.

Context Ignore

Here you can define a series of symbols (commands) that will be ignored by context rules. Example:

You have the following constellation:

Premise: A+B+C+D+E+F

Rules: A<B=C

Rules

Example, creating polygons’

Take a look at the second line of the Rule field:

L=[{.-f.+f.+f.++++f.+f.+f.+f}]

Between the curly brackets (these define a polygon), a specific number of polygon points is defined (each begins with a ".") between which a polygon is created. Because the curly brackets are contained within square brackets, the turtle will be reset to its point prior to creating the leaf after each leaf has been created.

The entire leaf will be assigned to an "L" and the Rule in the line above will create a complete leaf wherever an "L" exists.

Note that the MoSpline can produce either a Spline OR a polygon. If you want to produce both simultaneously, use the Destination Spline.

Example "multiply/divide"

If you use a self-replacing sequence of symbols in the Rules field (e.g., A=F+BA), a multiplier or divisor (", !, ;, _, ?, @) can be used to increase or decrease the value of each new Generator.

Example "cutting a branch"

If you take a look at this Rule you will see that the placeholders A, B, C and D have been added to the premise. For various Growth values, the Rules now define the replacement of each placeholder with a % value, which means that the following symbols will be cut off at that point on (and per) each branch.

Example "Cloner object"

If the Growth value is animated, this structure can grow exuberantly (incl. growing clone).

Note how J and K are used in the Rule (these could be replaced with (1,1,1,1) and (1,1,1,1), respectively, and if the parentheses argument were omitted each would use the standard value) that refers to the clones of a Cloner object. The mode must be set accordingly for both Cloner objects:

I(1,1,1,1) reflects Group 1

J(1,1,1,1) reflects Group 2

K(1,1,1,1) reflects Group 3

L(1,1,1,1) reflects Group 4

Note that one Rule

Premise: FA

Rules: A=FX

X=J(1,1,1,1)

may function but the clones don’t grow steplessly but are simply displayed abruptly.

Example "index"

A Cloner object’s Child objects are numbered sequentially (starting with "0"). If, for example, you define A=FJ(2,1,1,1)A (the RGB values can be omitted), the Cloner object will only use the object with the index "2" (left of the sphere). If you use A=J(rnd(2))A on the right side, a clone will be placed randomly in accordance with a number between "0" and "2" that is also chosen randomly.

Example "random growth"

Different limits generate different shapes.

This Rule in combination with varied User Data values for Limit1 and Limit2 (together, these values should equal 100%) can be used to create differing but very similar "plants" (Stochastic L-Systems. The conditions (rnd(1)<) or (rnd(1)>) determine randomly which of the 3 Rules will be applied (each with a new random selection for each new Generator, i.e., larger Growth parameter).

Example "context rules"

Rules can also be written in the following form:

Premise: ABC

Rule: A<B=C

Result (if Growth > 1): ACC

So what will happen? This depends on the sequence within the result string. The Rule "A<B=C" searches for instances within the string where a "B" directly follows an "A" and replaces the "B" by a "C".

If, on the other hand, you enter "A>B=C", the "A" to the left of a "B" will replaced by "C" (the result would be "CBC").

For the Rule "AB=C" it cannot be determined which symbol should be replaced by "C". In this case both will be replaced by "C" (the result would be "CCC").

Result

Displays syntax errors.

Result String to Console

Clicking on this button will display the symbol sequence currently in effect, taking into account all Rules and the Growth parameter, in the Console. Such a sequence can, for example, look like this (this is the sequence of symbols from the fruits example with Growth set to 4):