|
| 1 | +mesh <- 0 |
| 2 | +tree <- 0 |
| 3 | +render <- 0 |
| 4 | +rnds <- 0 |
| 5 | +randomRay <- 0 |
| 6 | +bias <- 0 |
| 7 | +growing <- 0 |
| 8 | +counter <- 0 |
| 9 | + |
| 10 | +settings <- function() { |
| 11 | + # Please install the peasycam before you run the example. |
| 12 | + importLibrary("hemesh") |
| 13 | + fullScreen(P3D) |
| 14 | + smooth(as.integer(8)) |
| 15 | +} |
| 16 | + |
| 17 | +setup <- function() { |
| 18 | + render <- WB_Render$new(processing) |
| 19 | + rnds <- WB_RandomOnSphere$new() |
| 20 | + creator <- HEC_Beethoven$new() |
| 21 | + creator$setScale(5)$setZAngle(PI/3) |
| 22 | + mesh <- HE_Mesh$new(creator) |
| 23 | + mesh$simplify(HES_TriDec$new()$setGoal(0.5)) |
| 24 | + tree <- WB_AABBTree$new(mesh, as.integer(10)) |
| 25 | + |
| 26 | + growing <- TRUE |
| 27 | + counter <- 0 |
| 28 | + bias <- rnds$nextVector() |
| 29 | +} |
| 30 | + |
| 31 | +createMesh <- function() { |
| 32 | + creator <- HEC_Beethoven$new() |
| 33 | + creator$setScale(5)$setZAngle(PI/3) |
| 34 | + mesh <- HE_Mesh$new(creator) |
| 35 | + mesh$simplify(HES_TriDec$new()$setGoal(0.5)) |
| 36 | + tree <- WB_AABBTree$new(mesh, as.integer(10)) |
| 37 | + |
| 38 | + growing <- TRUE |
| 39 | + counter <- 0 |
| 40 | + bias <- rnds$nextVector() |
| 41 | +} |
| 42 | + |
| 43 | + |
| 44 | +draw <- function() { |
| 45 | + background(20) |
| 46 | + directionalLight(255, 255, 255, 1, 1, -1) |
| 47 | + directionalLight(127, 127, 127, -1, -1, 1) |
| 48 | + translate(width/2, height/2, 0) |
| 49 | + rotateY(map(mouseX, 0, width, -PI, PI)) |
| 50 | + rotateX(map(mouseY, 0, height, PI, -PI)) |
| 51 | + |
| 52 | + # hint(DISABLE_DEPTH_TEST) |
| 53 | + noLights() |
| 54 | + fill(255) |
| 55 | + noStroke() |
| 56 | + pushMatrix() |
| 57 | + scale(1.8) |
| 58 | + render$drawFaces(mesh) |
| 59 | + popMatrix() |
| 60 | + |
| 61 | + # # hint(ENABLE_DEPTH_TEST) directionalLight(255, 255, 255, 1, 1, |
| 62 | + # -1) directionalLight(127, 127, 127, -1, -1, 1) scale(1.6) |
| 63 | + # fill(255) noStroke() render$drawFaces(mesh) noFill() stroke(0, |
| 64 | + # 50) render$drawEdges(mesh) |
| 65 | + |
| 66 | + |
| 67 | + # if (growing) { for (i in 0:5) { grow() counter <- counter + 1 } |
| 68 | + # } |
| 69 | + |
| 70 | + # if (counter == 500) { mesh$subdivide(HES_CatmullClark$new()) |
| 71 | + # growing <- false counter <- counter + 1 } |
| 72 | +} |
| 73 | + |
| 74 | +grow <- function() { |
| 75 | + rayOrigin <- WB_Point$new(bias)$mulSelf(-500) |
| 76 | + rayDirection <- bias$add(random(-0.3, 0.3), random(-0.3, 0.3), |
| 77 | + random(-0.3, 0.3)) |
| 78 | + randomRay <- WB_Ray$new(rayOrigin, rayDirection) |
| 79 | + fi <- HET_MeshOp$getFurthestIntersection(tree, randomRay) |
| 80 | + point <- 0 |
| 81 | + # if (!is.null(fi)) { print(fi$point) point <- fi$point |
| 82 | + # point$addMulSelf(120, randomRay$getDirection()) |
| 83 | + # HEM_TriSplit$splitFaceTri(mesh, fi$face, point) tree <- |
| 84 | + # WB_AABBTree$new(mesh, 10) stroke(255,0,0) |
| 85 | + # render$drawRay(randomRay,1500) } |
| 86 | +} |
| 87 | + |
| 88 | +mousePressed <- function() { |
| 89 | + createMesh() |
| 90 | +} |
0 commit comments