Creating 3D trees in City Engine?

6910
8
Jump to solution
01-24-2013 10:31 AM
AnnaRoyar
New Contributor
Hello!
I was wondering if anyone could give me some hints about how to make those neat 3D trees that people have in their city engine models? I have tree points with Z values. I have looked online and through the help and don't see anything about how to make those into trees.
Any advice?
Thanks so much!
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
MatthiasBuehler1
Frequent Contributor II
hi !


use center()


first, usually, do the s(), then center(), then i(). use t() after the i() to fix any issues left.



notes:
1]
s(0,0,0) uses the asset's original size.
s(0,treeHeight,0) will scale your asset proportinally to the given size
2]
after scatter(), use alignScopeToAxes(y) to align the scope vertically, to make the tree stand vertically.


ok?

View solution in original post

0 Kudos
8 Replies
JoanneO_Brien
Occasional Contributor
You just need to insert an obj tree at the point. You can use the obj's supplied by CE or get some from sketchup.
For the point you just assign the LotTree startrule and generate.

tree_tex = fileRandom("assets/trees/alleyTree_*_v1.obj")

LotTree--> s(0,rand(8,12),0) center(xz) i(tree_tex) Tree.
0 Kudos
amamalalalalal
New Contributor
Hi,

I have tested this code, it perfectly works but i want to do the same operation with an attribute :

I have a shape called "TREE" and an attribute called "HEIGHT". How can i generate tree of different height with the attribute of the tree?
Next, how can i adapt this code to link different representation like pine, palm with obj?

tree_tex = fileRandom("assets/trees/alleyTree_*_v1.obj")

LotTree--> s(0,rand(8,12),0) center(xz) i(tree_tex) Tree.

:)

Thank you very much,

aurelien
0 Kudos
MatthiasBuehler1
Frequent Contributor II
hi ..

written from my head .. please test the code, it may contain errors.



attr HEIGHT = 0 # connect to GIS attr
@Range( "palm", "pine", "eucalyptus" )
attr TREETYPE = "palm"

getAssetPath =
    fileRandom ( "assets/trees/" + TREETYPE + "/*.obj" )

@StartRule
TREE -->
    alignScopeToAxes(y)
    s(0,HEIGHT,0)
    i(getAssetPath)
    center(xz)
    Tree.

amamalalalalal
New Contributor
Hi,

wonderful, you are a master. it is a code very useful for generating trees from shape data.
Is there a listing of cga rule file? it will be interesting to create a topic with all the cga rule file which works.

Thanks for the code. ;)
0 Kudos
MatthiasBuehler1
Frequent Contributor II
working on it ..
0 Kudos
gulhunduran
New Contributor
Hi,
I'm trying to create a natural greenspace code with LOD options. Low LOD option works but High LOD creates trees far away from the original shape. Can anyone help me find what is wrong with my code. Thanks in advance!

[PHP]@Range ("high", "low")
attr LOD = "high"

@StartRule
Lot-->  Forest
  Green

Forest-->
  scatter(surface, 200, gaussian, left, '0.5) { Tree }

treetex_high =fileRandom("tree_eu/*.obj")
treetex_low = fileRandom("alleyTree/alleyTree_*_v1.obj")

Tree-->
case LOD == "high" :
  i(treetex_high)
  t(0,0.2,0)
  s(5,rand (5, 15),5)
else:
  i(treetex_low)
  t(0,0.2,0)
  s(10,rand (15, 25),8)
  color("#86ad6f")
Green-->
  set(material.opacity, 0.5)
  t(0,0.2,0)
  color (0,1,0)
[/PHP]
0 Kudos
MatthiasBuehler1
Frequent Contributor II
hi !


use center()


first, usually, do the s(), then center(), then i(). use t() after the i() to fix any issues left.



notes:
1]
s(0,0,0) uses the asset's original size.
s(0,treeHeight,0) will scale your asset proportinally to the given size
2]
after scatter(), use alignScopeToAxes(y) to align the scope vertically, to make the tree stand vertically.


ok?
0 Kudos
gulhunduran
New Contributor
Yeah it's OK! :)
0 Kudos