Skip to content

Commit f7356cd

Browse files
committed
address review: trim internal details, backtick code links, add orbit controls to examples
1 parent 5783139 commit f7356cd

3 files changed

Lines changed: 61 additions & 39 deletions

File tree

src/webgl/3d_primitives.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,6 @@ function primitives3D(p5, fn) {
113113
* once to create the new 3D shape.
114114
* Note: `buildGeometry()` can only be used in WebGL mode.
115115
*
116-
* Changing the material partway through the callback splits the result into
117-
* parts. For example, calling <a href="#/p5/texture">texture()</a> with one
118-
* image before a <a href="#/p5/box">box()</a>, then with another image before
119-
* a <a href="#/p5/sphere">sphere()</a>, creates a shape that keeps both
120-
* materials. It's drawn the same way a multi-material model loaded from a
121-
* file is, so building a shape in code and loading one from disk behave
122-
* alike. Changing only the <a href="#/p5/fill">fill()</a> color doesn't split
123-
* the shape, since a flat color is stored for each vertex.
124-
*
125116
* @method buildGeometry
126117
* @param {Function} callback function that draws the shape.
127118
* @returns {p5.Geometry} new 3D shape.

src/webgl/loading.js

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,11 @@ function buildMaterialParts(model, faceMaterials, materials) {
225225
function loading(p5, fn) {
226226
/**
227227
* Loads a 3D model to create a
228-
* <a href="#/p5.Geometry">p5.Geometry</a> object.
228+
* <a href="#/p5.Geometry">`p5.Geometry`</a> object.
229229
*
230230
* `loadModel()` can load 3D models from OBJ and STL files. Once the model is
231231
* loaded, it can be displayed with the
232-
* <a href="#/p5/model">model()</a> function, as in `model(shape)`.
232+
* <a href="#/p5/model">`model()`</a> function, as in `model(shape)`.
233233
*
234234
* There are three ways to call `loadModel()` with optional parameters to help
235235
* process the model.
@@ -240,9 +240,8 @@ function loading(p5, fn) {
240240
* security. The `path` parameter can also be defined as a [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request)
241241
* object for more advanced usage.
242242
* Note: When a `.obj` file references materials stored in a `.mtl` file,
243-
* p5.js loads and applies them. A model with several materials is drawn one
244-
* part per material, so it appears the way it was exported instead of as a
245-
* single flat gray shape. Each material can use diffuse (`map_Kd`), specular
243+
* p5.js loads and applies them, so a model with several materials appears the
244+
* way it was exported. Each material can use diffuse (`map_Kd`), specular
246245
* (`map_Ks`), ambient (`map_Ka`), shininess (`map_Ns`), and normal
247246
* (`map_Bump`) texture maps. Keep the `.mtl` file and its images alongside
248247
* the `.obj` file so their paths resolve. A texture that fails to load is
@@ -308,9 +307,9 @@ function loading(p5, fn) {
308307
* @param {String} [fileType] model’s file extension. Either `'.obj'` or `'.stl'`.
309308
* @param {Boolean} [normalize] if `true`, scale the model to fit the canvas.
310309
* @param {function(p5.Geometry)} [successCallback] function to call once the model is loaded. Will be passed
311-
* the <a href="#/p5.Geometry">p5.Geometry</a> object.
310+
* the <a href="#/p5.Geometry">`p5.Geometry`</a> object.
312311
* @param {function(Event)} [failureCallback] function to call if the model fails to load. Will be passed an `Error` event object.
313-
* @return {Promise<p5.Geometry>} the <a href="#/p5.Geometry">p5.Geometry</a> object
312+
* @return {Promise<p5.Geometry>} the <a href="#/p5.Geometry">`p5.Geometry`</a> object
314313
*
315314
* @example
316315
* // Click and drag the mouse to view the scene from different angles.
@@ -1165,21 +1164,21 @@ function loading(p5, fn) {
11651164
}
11661165

11671166
/**
1168-
* Draws a <a href="#/p5.Geometry">p5.Geometry</a> object to the canvas.
1167+
* Draws a <a href="#/p5.Geometry">`p5.Geometry`</a> object to the canvas.
11691168
*
11701169
* The first parameter, `model`, is the
1171-
* <a href="#/p5.Geometry">p5.Geometry</a> object to draw.
1172-
* <a href="#/p5.Geometry">p5.Geometry</a> objects can be built with
1173-
* <a href="#/p5/buildGeometry">buildGeometry()</a>. They can also be loaded from
1174-
* a file with <a href="#/p5/loadGeometry">loadGeometry()</a>.
1170+
* <a href="#/p5.Geometry">`p5.Geometry`</a> object to draw.
1171+
* <a href="#/p5.Geometry">`p5.Geometry`</a> objects can be built with
1172+
* <a href="#/p5/buildGeometry">`buildGeometry()`</a>. They can also be loaded from
1173+
* a file with <a href="#/p5/loadGeometry">`loadGeometry()`</a>.
11751174
*
11761175
* Note: `model()` can only be used in WebGL mode.
11771176
*
11781177
* A model with several materials, such as a character with separate skin,
1179-
* shirt, and shoe materials, is drawn one part per material, each with its own
1180-
* colors and textures. The call to `model()` is the same whether the model has
1181-
* one material or many, so a model made in software such as Blender appears
1182-
* the way it was exported.
1178+
* shirt, and shoe materials, keeps each material's own colors and textures.
1179+
* The call to `model()` is the same whether the model has one material or
1180+
* many, so a model made in software such as Blender appears the way it was
1181+
* exported.
11831182
*
11841183
* ```js example
11851184
* // Click and drag the mouse to view the scene from different angles.

src/webgl/material.js

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2569,7 +2569,7 @@ function material(p5, fn) {
25692569
/**
25702570
* Sets a normal map to add surface detail to shapes under lighting.
25712571
*
2572-
* `normalTexture()` works like <a href="#/p5/texture">texture()</a>, but for a
2572+
* `normalTexture()` works like <a href="#/p5/texture">`texture()`</a>, but for a
25732573
* tangent-space normal map: an image whose red, green, and blue channels
25742574
* encode the direction of the surface normal (not brightness). Call it before
25752575
* drawing a shape and its surface normals get perturbed by the map, so lights
@@ -2591,6 +2591,8 @@ function material(p5, fn) {
25912591
* @chainable
25922592
*
25932593
* @example
2594+
* // Click and drag the mouse to view the scene from different angles.
2595+
*
25942596
* let normalMap;
25952597
*
25962598
* function setup() {
@@ -2621,6 +2623,12 @@ function material(p5, fn) {
26212623
* function draw() {
26222624
* background(0);
26232625
*
2626+
* // Enable orbiting with the mouse.
2627+
* orbitControl();
2628+
*
2629+
* // Rock the shape so the lighting shifts across it.
2630+
* rotateY(sin(millis() * 0.002) * PI * 0.1);
2631+
*
26242632
* // Light the sphere from the upper left.
26252633
* ambientLight(60);
26262634
* pointLight(255, 255, 255, -80, -80, 150);
@@ -2643,17 +2651,17 @@ function material(p5, fn) {
26432651
* Sets an image that controls where a shape looks glossy.
26442652
*
26452653
* A specular map lets one shape mix polished and worn surfaces. It works like
2646-
* <a href="#/p5/texture">texture()</a>, but instead of setting the base color,
2654+
* <a href="#/p5/texture">`texture()`</a>, but instead of setting the base color,
26472655
* the map's color at each point scales the highlight set by
2648-
* <a href="#/p5/specularMaterial">specularMaterial()</a>. Bright parts of the
2656+
* <a href="#/p5/specularMaterial">`specularMaterial()`</a>. Bright parts of the
26492657
* map stay shiny and dark parts look matte.
26502658
*
26512659
* The parameter, `tex`, is the image to use as the specular map. Passing
26522660
* `null` clears it, as in `specularTexture(null)`. The map can also be scoped
2653-
* between <a href="#/p5/push">push()</a> and <a href="#/p5/pop">pop()</a>.
2661+
* between <a href="#/p5/push">`push()`</a> and <a href="#/p5/pop">`pop()`</a>.
26542662
*
26552663
* A light source is needed to see the effect. Models loaded with
2656-
* <a href="#/p5/loadModel">loadModel()</a> apply their own specular map from
2664+
* <a href="#/p5/loadModel">`loadModel()`</a> apply their own specular map from
26572665
* the `.mtl` file's `map_Ks`.
26582666
*
26592667
* Note: `specularTexture()` can only be used in WebGL mode.
@@ -2663,6 +2671,8 @@ function material(p5, fn) {
26632671
* @chainable
26642672
*
26652673
* @example
2674+
* // Click and drag the mouse to view the scene from different angles.
2675+
*
26662676
* let specularMap;
26672677
*
26682678
* function setup() {
@@ -2691,6 +2701,12 @@ function material(p5, fn) {
26912701
* function draw() {
26922702
* background(0);
26932703
*
2704+
* // Enable orbiting with the mouse.
2705+
* orbitControl();
2706+
*
2707+
* // Rock the shape so the lighting shifts across it.
2708+
* rotateY(sin(millis() * 0.002) * PI * 0.1);
2709+
*
26942710
* // Light the surface head on so the highlight spreads across it.
26952711
* ambientLight(50);
26962712
* pointLight(255, 255, 255, 0, 0, 300);
@@ -2715,17 +2731,17 @@ function material(p5, fn) {
27152731
* Sets an image that controls the color a shape reflects from ambient light.
27162732
*
27172733
* An ambient map varies the color set by
2718-
* <a href="#/p5/ambientMaterial">ambientMaterial()</a> across a surface, so
2734+
* <a href="#/p5/ambientMaterial">`ambientMaterial()`</a> across a surface, so
27192735
* different parts of one shape can pick up ambient light differently. It works
2720-
* like <a href="#/p5/texture">texture()</a>, but the map's color is applied to
2736+
* like <a href="#/p5/texture">`texture()`</a>, but the map's color is applied to
27212737
* the ambient term rather than the base color.
27222738
*
27232739
* The parameter, `tex`, is the image to use as the ambient map. Passing `null`
27242740
* clears it, as in `ambientTexture(null)`. The map can also be scoped between
2725-
* <a href="#/p5/push">push()</a> and <a href="#/p5/pop">pop()</a>.
2741+
* <a href="#/p5/push">`push()`</a> and <a href="#/p5/pop">`pop()`</a>.
27262742
*
2727-
* An <a href="#/p5/ambientLight">ambientLight()</a> is needed to see the
2728-
* effect. Models loaded with <a href="#/p5/loadModel">loadModel()</a> apply
2743+
* An <a href="#/p5/ambientLight">`ambientLight()`</a> is needed to see the
2744+
* effect. Models loaded with <a href="#/p5/loadModel">`loadModel()`</a> apply
27292745
* their own ambient map from the `.mtl` file's `map_Ka`.
27302746
*
27312747
* Note: `ambientTexture()` can only be used in WebGL mode.
@@ -2735,6 +2751,8 @@ function material(p5, fn) {
27352751
* @chainable
27362752
*
27372753
* @example
2754+
* // Click and drag the mouse to view the scene from different angles.
2755+
*
27382756
* let ambientMap;
27392757
*
27402758
* function setup() {
@@ -2761,6 +2779,12 @@ function material(p5, fn) {
27612779
* function draw() {
27622780
* background(0);
27632781
*
2782+
* // Enable orbiting with the mouse.
2783+
* orbitControl();
2784+
*
2785+
* // Rock the shape so the lighting shifts across it.
2786+
* rotateY(sin(millis() * 0.002) * PI * 0.1);
2787+
*
27642788
* // Ambient light reveals the map's colors.
27652789
* ambientLight(200);
27662790
* noStroke();
@@ -2780,18 +2804,18 @@ function material(p5, fn) {
27802804
* Sets an image that controls how tight a shape's highlights are.
27812805
*
27822806
* A shininess map varies the value set by
2783-
* <a href="#/p5/shininess">shininess()</a> across a surface. Only the map's
2807+
* <a href="#/p5/shininess">`shininess()`</a> across a surface. Only the map's
27842808
* red channel is read, and it scales the base shininess, so bright areas get
27852809
* a small, sharp highlight and dark areas get a broad, soft one. This lets a
27862810
* single shape look polished in some places and dull in others.
27872811
*
27882812
* The parameter, `tex`, is the image to use as the shininess map. Passing
27892813
* `null` clears it, as in `shininessTexture(null)`. The map can also be scoped
2790-
* between <a href="#/p5/push">push()</a> and <a href="#/p5/pop">pop()</a>.
2814+
* between <a href="#/p5/push">`push()`</a> and <a href="#/p5/pop">`pop()`</a>.
27912815
*
27922816
* A light source and
2793-
* <a href="#/p5/specularMaterial">specularMaterial()</a> are needed to see the
2794-
* effect. Models loaded with <a href="#/p5/loadModel">loadModel()</a> apply
2817+
* <a href="#/p5/specularMaterial">`specularMaterial()`</a> are needed to see the
2818+
* effect. Models loaded with <a href="#/p5/loadModel">`loadModel()`</a> apply
27952819
* their own shininess map from the `.mtl` file's `map_Ns`.
27962820
*
27972821
* Note: `shininessTexture()` can only be used in WebGL mode.
@@ -2801,6 +2825,8 @@ function material(p5, fn) {
28012825
* @chainable
28022826
*
28032827
* @example
2828+
* // Click and drag the mouse to view the scene from different angles.
2829+
*
28042830
* let shininessMap;
28052831
*
28062832
* function setup() {
@@ -2830,6 +2856,12 @@ function material(p5, fn) {
28302856
* function draw() {
28312857
* background(0);
28322858
*
2859+
* // Enable orbiting with the mouse.
2860+
* orbitControl();
2861+
*
2862+
* // Rock the shape so the lighting shifts across it.
2863+
* rotateY(sin(millis() * 0.002) * PI * 0.1);
2864+
*
28332865
* // Light the surface from the upper left.
28342866
* ambientLight(40);
28352867
* pointLight(255, 255, 255, -60, -60, 180);

0 commit comments

Comments
 (0)