Skip to content

Commit f8cfec5

Browse files
committed
edited page titles, added examples and updated text to custom geometry tutorial
1 parent 40c5c81 commit f8cfec5

File tree

6 files changed

+110
-64
lines changed

6 files changed

+110
-64
lines changed

i18n-tracking.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
es:
22
src/data/en.yml:
3+
line 368: ' getting-started-in-webgl-coords-and-transform-title'
34
line 369: ''
45
line 370: ' getting-started-in-webgl-title'
56
line 374: ' getting-started-in-webgl-custom-geometry'
@@ -285,7 +286,6 @@ es:
285286
line 365: ' project-a-3-1-chung'
286287
line 366: ' project-a-3-2-chung'
287288
line 367: ' project-a-4-1-chung'
288-
line 368: ' project-a-4-2-chung'
289289
line 380: ' project-a-2-2-casey-louise'
290290
line 381: ' project-a-3-1-casey-louise'
291291
line 382: ' project-a-3-2-casey-louise'
@@ -1905,8 +1905,10 @@ hi:
19051905
line 377: ' getting-started-in-webgl-shaders-title'
19061906
line 378: ' getting-started-in-webgl-shaders'
19071907
line 379: ''
1908+
line 368: ' getting-started-in-webgl-coords-and-transform-title'
19081909
ko:
19091910
src/data/en.yml:
1911+
line 368: ' getting-started-in-webgl-coords-and-transform-title'
19101912
line 369: ''
19111913
line 370: ' getting-started-in-webgl-title'
19121914
line 374: ' getting-started-in-webgl-custom-geometry'
@@ -2192,7 +2194,6 @@ ko:
21922194
line 365: ' project-a-3-1-chung'
21932195
line 366: ' project-a-3-2-chung'
21942196
line 367: ' project-a-4-1-chung'
2195-
line 368: ' project-a-4-2-chung'
21962197
line 380: ' project-a-2-2-casey-louise'
21972198
line 381: ' project-a-3-1-casey-louise'
21982199
line 382: ' project-a-3-2-casey-louise'
@@ -3746,6 +3747,7 @@ ko:
37463747
line 84: ' copyright1'
37473748
zh-Hans:
37483749
src/data/en.yml:
3750+
line 368: ' getting-started-in-webgl-coords-and-transform-title'
37493751
line 369: ''
37503752
line 370: ' getting-started-in-webgl-title'
37513753
line 374: ' getting-started-in-webgl-custom-geometry'
@@ -4030,7 +4032,6 @@ zh-Hans:
40304032
line 365: ' project-a-3-1-chung'
40314033
line 366: ' project-a-3-2-chung'
40324034
line 367: ' project-a-4-1-chung'
4033-
line 368: ' project-a-4-2-chung'
40344035
line 380: ' project-a-2-2-casey-louise'
40354036
line 381: ' project-a-3-1-casey-louise'
40364037
line 382: ' project-a-3-2-casey-louise'

src/data/en.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ learn:
364364
beyond-the-canvas: Creating and manipulating elements on the page beyond the canvas.
365365

366366
getting-started-in-webgl-title: Getting Started in WebGL
367-
getting-started-in-webgl-coords-and-transform-title: Getting Started in 3D
367+
getting-started-in-webgl-coords-and-transform-title: Coordinates and Transformations
368368
getting-started-in-webgl-coords-and-transform: Basics of 3D setup, coordinates, and transformations
369369
getting-started-in-webgl-custom-geometry-title: Creating Custom Geometry
370370
getting-started-in-webgl-custom-geometry: Creating custom geometry in WebGL

src/data/learn/learn.json

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,6 @@
3131
"url": "https://github.com/processing/p5.js/wiki/p5.js,-node.js,-socket.io"
3232
}
3333
],
34-
"getting-started-in-webgl-title": [
35-
{
36-
"name": "getting-started-in-webgl-coords-and-transform",
37-
"url": "getting-started-in-webgl-coords-and-transform.html"
38-
},
39-
{
40-
"name": "getting-started-in-webgl-custom-geometry",
41-
"url": "getting-started-in-webgl-custom-geometry.html"
42-
},
43-
{
44-
"name": "getting-started-in-webgl-appearance",
45-
"url": "getting-started-in-webgl-appearance.html"
46-
},
47-
{
48-
"name": "getting-started-in-webgl-shaders",
49-
"url": "getting-started-in-webgl-shaders.html"
50-
}
51-
],
5234
"programming-topics-title": [
5335
{
5436
"name": "beyond-the-canvas",
@@ -74,6 +56,24 @@
7456
"name": "program-flow",
7557
"url": "program-flow.html"
7658
}
59+
],
60+
"getting-started-in-webgl-title": [
61+
{
62+
"name": "getting-started-in-webgl-coords-and-transform",
63+
"url": "getting-started-in-webgl-coords-and-transform.html"
64+
},
65+
{
66+
"name": "getting-started-in-webgl-custom-geometry",
67+
"url": "getting-started-in-webgl-custom-geometry.html"
68+
},
69+
{
70+
"name": "getting-started-in-webgl-appearance",
71+
"url": "getting-started-in-webgl-appearance.html"
72+
},
73+
{
74+
"name": "getting-started-in-webgl-shaders",
75+
"url": "getting-started-in-webgl-shaders.html"
76+
}
7777
],
7878
"becoming-a-better-programmer-title": [
7979
{

src/templates/pages/learn/getting-started-in-webgl-appearance.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ slug: learn/
6363

6464
<p>The camera is an important piece to the 3D scene; it gives us the sense of space and dimension that we are
6565
often looking for in 3D. In p5.js, the WebGL mode provides us with a perspective camera by default, but we can
66-
change this using <a class="code">perspective()</a> or <a class="code">ortho()</a>.</p>
66+
change this using <a class="code" href="{{root}}/reference/#/p5/perspective">perspective()</a> or <a class="code" href="{{root}}/reference/#/p5/ortho">ortho()</a>.</p>
6767

6868
<img style="padding:60px;" src='{{assets}}/learn/basic3D/images/cameraTypeIllustration.png'
6969
alt="an illustration showing the difference between perspective and orthographic camera types">
@@ -73,7 +73,7 @@ slug: learn/
7373
size as it gets further away and has no vanishing point. </p>
7474

7575
<p>Constantly moving and adjusting the camera in code can be tedious, especially when you are experimenting with
76-
ideas. p5.js has a special camera method, <a class="code">orbitControl()</a>, that can be used to zoom, pan,
76+
ideas. p5.js has a special camera method, <a class="code" href="{{root}}/reference/#/p5/orbitControl">orbitControl()</a>, that can be used to zoom, pan,
7777
and position the camera using the mouse.</p>
7878

7979
<ul>

src/templates/pages/learn/getting-started-in-webgl-coords-and-transform.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ slug: learn/
4343
<iframe src="{{assets}}/learn/basic3D/titleExample.html" width="720" height="350">
4444
</iframe>
4545

46-
<h1>Getting Started with 3D in p5.js</h1>
46+
<h1>Coordinates and Transformations</h1>
4747

4848
<p>p5.js is a powerful tool for creating 2D graphics but it's also capable of 3D graphics.
4949
Before we can get started in 3D there are some new concepts to learn and this document will introduce some ideas

src/templates/pages/learn/getting-started-in-webgl-custom-geometry.hbs

Lines changed: 84 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ slug: learn/
5050
(like Blender) or from code. This tutorial will walk through how to import 3D models into p5.js, as well as how
5151
to create a basic geometry from scratch. </p>
5252

53-
<div class="additionalInformation">If you are new to 3D it's recommended that you check out the <a href="{{root}}/learn/getting-started-in-webgl-coords-and-transform.html">Getting Started
54-
With 3D</a> tutorial before continuing with this tutorial. </div>
53+
<div class="additionalInformation">If you are new to 3D it's recommended that you check out the <a
54+
href="{{root}}/learn/getting-started-in-webgl-coords-and-transform.html">Getting Started
55+
With 3D</a> tutorial before continuing with this tutorial. </div>
5556

5657
<div class="toc">
5758
<h3>Table of Contents</h3>
@@ -73,7 +74,7 @@ slug: learn/
7374
loadModel() method includes a normalize parameter that will resize the model to something that works better in
7475
p5.js.</p>
7576

76-
Widget example of teapot model and loadModel
77+
{{!-- Widget example of teapot model and loadModel --}}
7778
<script type="text/p5" data-autoplay data-p5-version="{{ version }}">
7879
var teapotModel;
7980
@@ -102,8 +103,8 @@ function draw(){
102103
formed using your own set of rules. There are a number of methods that can be used to create 3D geometry in a
103104
way that is similar to 2D drawing in p5.js.</p>
104105

105-
Example using triangle and quad
106-
{{!-- TODO push and pop example --}}
106+
107+
{{!-- Example using triangle and quad --}}
107108
<script type="text/p5" data-autoplay data-p5-version="{{ version }}">
108109
function setup() {
109110
createCanvas(windowWidth, windowHeight, WEBGL);
@@ -123,51 +124,95 @@ function draw(){
123124
}
124125
</script>
125126

126-
<p>There are also methods that offer greater control of the geometry</p>
127+
<p>There are also methods that offer greater control of the geometry. A shape can be defined point-by-point using
128+
<a class="code" href="{{root}}/reference/#/p5/beginShape">beginShape()</a>, <a class="code"
129+
href="{{root}}/reference/#/p5/vertex">vertex()</a>, and <a class="code"
130+
href="{{root}}/reference/#/p5/endShape">endShape()</a></p>
127131

128-
Example using beginShape and endShape
129-
{{!-- TODO push and pop example --}}
132+
{{!-- Example using beginShape and endShape --}}
130133
<script type="text/p5" data-autoplay data-p5-version="{{ version }}">
131-
function setup() {
132-
createCanvas(windowWidth, windowHeight, WEBGL);
133-
}
134-
135-
function draw(){
136-
background(255);
137-
//
138-
push(); // detach our coordinate system
139-
// draw a box 100 units to the right
140-
translate(100,0,0);
141-
box();
142-
pop(); // return to our original coordinate system
134+
function setup() {
135+
createCanvas(windowWidth, windowHeight, WEBGL);
136+
}
143137
144-
translate(-100,0,0);
145-
box();
146-
}
138+
function draw(){
139+
background(220);
140+
141+
// click+drag on canvas to look around the shape
142+
orbitControl();
143+
144+
fill(255,0,0,128)
145+
146+
var numVertices = 100;
147+
translate(0,numVertices,0)
148+
rotateY(millis()/1000)
149+
scale(20)
150+
beginShape();
151+
// a simple spiral shape
152+
for(let i = 0; i < numVertices; i++) {
153+
vertex(
154+
sin((i/numVertices*TWO_PI)*5)*sin(i/numVertices*PI)*2,
155+
-i/10,
156+
cos((i/numVertices*TWO_PI)*5)*sin(i/numVertices*PI)*2,
157+
);
158+
}
159+
endShape();
160+
}
147161
</script>
148162

149163
<p>There is also a powerful class, p5.Geometry, which p5 uses internally for loadModel() but can also be used to
150164
define custom geometry, offering tools that can be helpful in calculating faces and normals. </p>
151165

152-
Example using p5.Geometry
153-
{{!-- TODO push and pop example --}}
166+
167+
{{!-- Example using p5.Geometry --}}
154168
<script type="text/p5" data-autoplay data-p5-version="{{ version }}">
155-
function setup() {
156-
createCanvas(windowWidth, windowHeight, WEBGL);
169+
var myGeometry
170+
171+
function setup() {
172+
createCanvas(400, 400, WEBGL);
173+
174+
// debugMode()
175+
176+
let detailX = 20;
177+
let detailY = 20;
178+
myGeometry = new p5.Geometry(detailX,detailY, function() {
179+
180+
// must be detailX + 1, detailY + 1
181+
for(let x = 0; x <= detailX; x++) {
182+
for(let y = 0; y <= detailY; y++) {
183+
this.vertices.push(new p5.Vector(
184+
x/detailX,
185+
y/detailY,
186+
(sin(x/detailX*TWO_PI*4) + cos(y/detailY*TWO_PI)) / 10
187+
// random()/10
188+
))
157189
}
190+
}
158191
159-
function draw(){
160-
background(255);
161-
//
162-
push(); // detach our coordinate system
163-
// draw a box 100 units to the right
164-
translate(100,0,0);
165-
box();
166-
pop(); // return to our original coordinate system
192+
// this will attach all our vertices and create faces automatically
193+
this.computeFaces()
194+
// this will calculate the normals to help with lighting
195+
this.computeNormals()
196+
})
197+
}
167198
168-
translate(-100,0,0);
169-
box();
170-
}
199+
function draw() {
200+
background(220);
201+
202+
orbitControl()
203+
204+
//set a basic light
205+
pointLight(255,255,0,0,50,-50)
206+
207+
push();
208+
stroke(128)
209+
var geoSize = width/2
210+
rotateY(cos(millis() / 1000)*PI/4)
211+
translate(-geoSize/2,-geoSize/2)
212+
scale(geoSize)
213+
model(myGeometry)
214+
pop()
215+
}
171216
</script>
172217

173218
<h2 id="glossary">Glossary</h2>
@@ -194,7 +239,7 @@ function draw(){
194239
materials. </p>
195240

196241
<h3>Normalization</h3>
197-
<p>Taking something in changing its size so that it fits within a standard range.</p>
242+
<p>Changing something so that it fits within a standard range.</p>
198243

199244
</main>
200245

0 commit comments

Comments
 (0)