Skip to content

Commit 1f6702b

Browse files
authored
hemesh: Add a new example (#247)
Signed-off-by: Ce Gao <[email protected]>
1 parent aea78c5 commit 1f6702b

File tree

2 files changed

+126
-0
lines changed

2 files changed

+126
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
n1 <- 0
2+
n2 <- 0
3+
n3 <- 0
4+
5+
settings <- function() {
6+
size(800, 800)
7+
importLibrary("hemesh")
8+
}
9+
10+
setup <- function() {
11+
# Perlin Noise, implementation from Processing core
12+
n1 = WB_PNoise$new()$setDetail(as.integer(8), 0.5)
13+
n1$setScale(0.005)
14+
15+
# Simplex noise
16+
n2 = WB_SNoise$new()
17+
n2$setScale(0.01)
18+
19+
# Open simplex noise
20+
n3 = WB_OSNoise$new()
21+
n3$setScale(0.02)
22+
}
23+
24+
draw <- function() {
25+
background(255)
26+
stroke(0)
27+
for (i in 0:width) {
28+
point(i, 200 - 100 * n1$value1D(i + frameCount))
29+
point(i, 400 - 100 * n2$value1D(i + frameCount))
30+
point(i, 600 - 100 * n3$value1D(i + frameCount))
31+
}
32+
stroke(255, 0, 0)
33+
line(0, 200, width, 200)
34+
line(0, 400, width, 400)
35+
line(0, 600, width, 600)
36+
}

examples/Libraries/He_Mesh/demo.rpde

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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

Comments
 (0)