项目作者: edap

项目描述 :
Space Colonization algorithm implementation in openFrameworks
高级语言: C++
项目地址: git://github.com/edap/ofxSpaceColonization.git
创建时间: 2017-04-02T12:43:56Z
项目社区:https://github.com/edap/ofxSpaceColonization

开源协议:

下载


ofxSpaceColonization

Build status
Build status

cover

This addon is an openFrameworks implementation of the paper Modeling Trees with a Space Colonization Algorithm by Adam Runions, Brendan Lane, and Przemyslaw Prusinkiewicz.

Dependecies

It requires ofxBranchesPrimitive. The example example-ofxenvelope requires the addon ofxEnvelope

Usage

  1. //in your header file
  2. ofxSpaceColonization tree;
  3. // in your App.cpp file
  4. void ofApp::setup(){
  5. tree.build();
  6. }
  7. void ofApp::update(){
  8. tree.grow();
  9. }
  10. void ofApp::draw(){
  11. tree.draw();
  12. }

This will generate a tree using this standard options:

  1. static const ofxSpaceColonizationOptions defaultSpaceColOptions = {
  2. 150, // maxDist, leaves are attractive if closer than this distance
  3. 10, // minDist, leaves are attractive if farther than this distance
  4. 150, // trunkLength, the length of the trunk
  5. glm::vec4(0.0f,0.0f,0.0f, 1.0f), // rootPosition, the position of the root
  6. glm::vec3(0.0f, 1.0f, 0.0f), // rootDirection, the direction on which the tree will starts to grow
  7. 7, // branchLength, the length of each branch
  8. false, // doneDrawing, a value that indicates when the grow process is done
  9. false, // cap, if the cylinders that compose the branches have caps or not
  10. 2.0, // radius, the radius of the branch
  11. 16, // resolution, the resolution of the cylinders that compose the geometry
  12. 1, // textureRepeat, how many times a texture has to be repeated on a branch
  13. 0.9997 // radiusScale, how much the radius will increase or decrease at each interaction
  14. };

You can specify yours options using the setup method:

  1. void ofApp::setup(){
  2. auto myOpt = ofxSpaceColonizationOptions({
  3. // ...
  4. });
  5. tree.setup(myOpt);
  6. tree.build();
  7. }

The form of the tree changes depending on these options and on the position of the leaves. By default, some default leaves are provided but you can provide your leaves by using the setLeavesPositions() method. It takes a vector<glm::vec3> as argument.

  1. void ofApp::setup(){
  2. vector<glm::vec3> points;
  3. // ... fullfill the vector
  4. tree.setLeavesPositions(points);
  5. tree.build();
  6. }

I’ve created an addon that can be used to generate the points, it is called ofxEnvelope and you can see in the example example-ofxenvelope how to use it.

Wind

The grow method takes a glm::vec3 as optional parameter. This vector can be used to move the leaves, like this
Example:

  1. void ofApp::update(){
  2. float t = ofGetElapsedTimef();
  3. float n = ofSignedNoise(t * windFreq) * windAmpl;
  4. auto wind = glm::vec3(n,0.0,0.0); // a weird wind that only breezes on the x axis
  5. tree.grow(wind);
  6. }

Examples

example-3d
example-3d

example-ofxenvelope
example-ofxenvelope

License

MIT

References

Procedurally Generated Trees with Space Colonization Algorithm in XNA C#

Daniel Shiffman Video

space-colonization