User Tools

Site Tools


tutorials:leaf-triangulation

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
tutorials:leaf-triangulation [2024/12/05 19:54] – created MHtutorials:leaf-triangulation [2024/12/09 21:51] (current) – changed some minors MH
Line 23: Line 23:
 import de.grogra.xl.util.FloatList; import de.grogra.xl.util.FloatList;
  
-static final float[] p0 = {0,0,0}; +const float[] p0 = {0,0,0}; 
-static final float[] p1 = {-2.85,4,0}; +const float[] p1 = {-2.85,4,0}; 
-static final float[] p2 = {0,10,0}; +const float[] p2 = {0,10,0}; 
-static final float[] p3 = {2.85,3.1,0};+const float[] p3 = {2.85,3.1,0};
  
-private static const FloatList vertexDataLeaflet = new FloatList(new float[] {+const FloatList vertexDataLeaflet = new FloatList(new float[] {
 //left //left
 p0[0], p0[1], p0[2], p1[0], p1[1], p1[2], p2[0], p2[1], p2[2],//T1 p0[0], p0[1], p0[2], p1[0], p1[1], p1[2], p2[0], p2[1], p2[2],//T1
Line 51: Line 51:
 </code> </code>
  
-The output of the above code could then look like this:+The output of the above code could then look like this. Note: The blue lines to highlight the edges are just added to increase understanding - they will be not shown when running the above code.:
  
-{{ :tutorials:leaflet_model_s.png?direct&400 |}}+{{ :tutorials:leaf_s.png?direct&400 |}}
  
 +For convex shapes, the //Library// function //leaf3d// can be used to generate a triangulation like the above one. It assumes that the first point is the origin of all faces and builds a series of triangles from this point on. In XL this could look like this:
 +
 +<code java>
 +const float[] pointlist = new float[] {0,0,0,-2.85,4,0,0,10,0,2.85,3.1,0};
 +
 +protected void init() [
 + Axiom ==> leaf3d(pointlist);
 +]
 +</code>
  
-The //Library// function //getMesh// takes a //FloatList// of triangulated points and does the whole conversion to //PolygonMesh// and //MeshNode// for us.+Coming back to the //PolygonMesh// version, the //Library// function //getMesh// takes a //FloatList// of triangulated points and does the whole conversion to //PolygonMesh// and //MeshNode// for us.
  
 <code java> <code java>
Line 95: Line 104:
 import de.grogra.xl.util.FloatList; import de.grogra.xl.util.FloatList;
  
-static final float[] p0 = {0,0,0}; +const float[] p0 = {0,0,0}; 
-static final float[] p1 = {-0.1,-0.066,0.3}; +const float[] p1 = {-0.1,-0.066,0.3}; 
-static final float[] p2 = {-0.2,0.06,0}; +const float[] p2 = {-0.2,0.06,0}; 
-static final float[] p3 = {-0.25,0.2,0}; +const float[] p3 = {-0.25,0.2,0}; 
-static final float[] p4 = {0,0.2,-0.4}; +const float[] p4 = {0,0.2,-0.4}; 
-static final float[] p5 = {-0.285,0.4,0}; +const float[] p5 = {-0.285,0.4,0}; 
-static final float[] p6 = {0,0.4,-0.5}; +const float[] p6 = {0,0.4,-0.5}; 
-static final float[] p7 = {-0.22,0.53,0}; +const float[] p7 = {-0.22,0.53,0}; 
-static final float[] p8 = {0,0.53,-0.3}; +const float[] p8 = {0,0.53,-0.3}; 
-static final float[] p9 = {0,1,1.0};+const float[] p9 = {0,1,1.0};
  
-private static const FloatList vertexDataLeaflet = new FloatList(new float[] {+const FloatList vertexDataLeaflet = new FloatList(new float[] {
 //left //left
 p0[0], p0[1], p0[2], p1[0], p1[1], p1[2], p2[0], p2[1], p2[2],//T1 p0[0], p0[1], p0[2], p1[0], p1[1], p1[2], p2[0], p2[1], p2[2],//T1
Line 127: Line 136:
 }); });
  
-const PolygonMesh polygonMesh = new PolygonMesh();+static MeshNode LeafletMesh;
 static { static {
-    int[] tmp new int[vertexDataLeaflet.size()/3]; +    LeafletMesh getMesh(vertexDataLeaflet);
-    for(int i = 0; i<tmp.length; i++) tmp[i]=i; +
-    // set a list of the indices of the used list of vertices +
-    // normally = {0,1,2,3,...,n}, where n is the number of used vertices minus one  +
-    polygonMesh.setIndexData(new IntList(tmp)); +
-    // set the list of vertices +
-    polygonMesh.setVertexData(vertexDataLeaflet);+
 } }
  
 protected void init() [ protected void init() [
-    Axiom ==> Scale(0.07, 0.07, 0.01)  MeshNode.(setPolygons(polygonMesh), setShader(GREEN)); +    Axiom ==> Scale(0.07, 0.07, 0.01) LeafletMesh.(setShader(GREEN)); 
 ] ]
 </code> </code>
Line 159: Line 162:
  
 as it was used within Zhang //et al.// 2021 (High resolution 3D simulation of light climate and thermal performance of a solar greenhouse model under tomato canopy structure; //Renewable Energy//, 160, 730-745, doi: [[https://doi.org/10.1016/j.renene.2020.06.144]]). as it was used within Zhang //et al.// 2021 (High resolution 3D simulation of light climate and thermal performance of a solar greenhouse model under tomato canopy structure; //Renewable Energy//, 160, 730-745, doi: [[https://doi.org/10.1016/j.renene.2020.06.144]]).
 +
 +GroIMP provides a few predefined 3D leaves that can be accessed using the Library function leaf3d(id). There are shapes for: "artificial", "maple", "undefined", "poplar", "cotton", "birch", "undefined", "oak". The identifier starts from zero for the first "artificial" shape and goes up to seven for the oak leaf.
 +
 +The code below will generate them one by one next to each other.
 +
 +<code java>
 +protected void init() [
 +  Axiom ==>
 +    for(int i=0; i<DEFAULT_LEAF3D.length; i++) (
 +      [ Null(i*0.3,0,0) leaf3d(i) ]
 +    )
 +]
 +</code>
 +
 +The predefined 3D leaf shapes will look as shown below:
 +
 +{{ :tutorials:leaf3d.png?direct&625 |}}
 +
  
  
  
  
tutorials/leaf-triangulation.1733424867.txt.gz · Last modified: 2024/12/05 19:54 by MH