1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Copyright (C) 2017-2023 David Thompson dthompson2@worcester.edu
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3
or any later version published by the Free Software Foundation;
with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
A copy of the license is included in the section entitled "GNU
Free Documentation License".
A copy of the license is also available from the Free Software
Foundation Web site at http://www.gnu.org/licenses/fdl.html.
* Chickadee: (chickadee). Game programming toolkit for Guile.
The document was typeset with
http://www.texinfo.org/ (GNU Texinfo).
-->
<!-- Created by GNU Texinfo 6.7, http://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Meshes (The Chickadee Game Toolkit)</title>
<meta name="description" content="Meshes (The Chickadee Game Toolkit)" />
<meta name="keywords" content="Meshes (The Chickadee Game Toolkit)" />
<meta name="resource-type" content="document" />
<meta name="distribution" content="global" />
<meta name="Generator" content="makeinfo" />
<link href="index.html" rel="start" title="Top" />
<link href="Index.html" rel="index" title="Index" />
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents" />
<link href="Graphics.html" rel="up" title="Graphics" />
<link href="Buffers.html" rel="next" title="Buffers" />
<link href="Skyboxes.html" rel="prev" title="Skyboxes" />
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.indentedblock {margin-right: 0em}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
kbd {font-style: oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
span.nolinebreak {white-space: nowrap}
span.roman {font-family: initial; font-weight: normal}
span.sansserif {font-family: sans-serif; font-weight: normal}
ul.no-bullet {list-style: none}
@media (min-width: 1140px) {
body {
margin-left: 14rem;
margin-right: 4rem;
max-width: 52rem;
}
}
@media (min-width: 800px) and (max-width: 1140px) {
body {
margin-left: 6rem;
margin-right: 4rem;
max-width: 52rem;
}
}
@media (max-width: 800px) {
body {
margin: 1rem;
}
}
-->
</style>
<link rel="stylesheet" type="text/css" href="https://dthompson.us/css/dthompson.css" />
</head>
<body lang="en">
<span id="Meshes"></span><div class="header">
<p>
Next: <a href="Buffers.html" accesskey="n" rel="next">Buffers</a>, Previous: <a href="Skyboxes.html" accesskey="p" rel="prev">Skyboxes</a>, Up: <a href="Graphics.html" accesskey="u" rel="up">Graphics</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr />
<span id="Meshes-1"></span><h4 class="subsection">5.3.11 Meshes</h4>
<p>The <code>(chickadee graphics mesh)</code> modules provides procedures for
programmatically creating 3D objects (to load 3D models from a file on
disk, see <a href="#Meshes">Meshes</a>.)
</p>
<span id="Materials"></span><h4 class="subsubsection">5.3.11.1 Materials</h4>
<p>Before we talk about meshes themselves, let’s discuss “materials.”
Materials control the appearance of 3D objects. Whether an object
appears like a rough rock, a smooth and shiny metal, etc. depends on
the material that is applied to it. Different types of materials use
different lighting models. Chickadee supports two lighting models:
The classic Blinn-Phong model and a more modern physically based
rendering (PBR) model.
</p>
<p>All materials share some common data:
</p>
<dl>
<dt id="index-material_003f">Procedure: <strong>material?</strong> <em>obj</em></dt>
<dd><p>Return <code>#t</code> if <var>obj</var> is a material.
</p></dd></dl>
<dl>
<dt id="index-material_002dname">Procedure: <strong>material-name</strong> <em>material</em></dt>
<dd><p>Return the name of <var>material</var>.
</p></dd></dl>
<dl>
<dt id="index-material_002dshader">Procedure: <strong>material-shader</strong> <em>material</em></dt>
<dd><p>Return the shader of <var>material</var>.
</p></dd></dl>
<dl>
<dt id="index-material_002dblend_002dmode">Procedure: <strong>material-blend-mode</strong> <em>material</em></dt>
<dd><p>Return the blend mode of <var>material</var>.
</p></dd></dl>
<dl>
<dt id="index-material_002dpolygon_002dmode">Procedure: <strong>material-polygon-mode</strong> <em>material</em></dt>
<dd><p>Return the polygon mode of <var>material</var>.
</p></dd></dl>
<dl>
<dt id="index-material_002dcull_002dface_002dmode">Procedure: <strong>material-cull-face-mode</strong> <em>material</em></dt>
<dd><p>Return the cull face mode of <var>material</var>.
</p></dd></dl>
<dl>
<dt id="index-material_002ddepth_002dtest">Procedure: <strong>material-depth-test</strong> <em>material</em></dt>
<dd><p>Return the depth test of <var>material</var>.
</p></dd></dl>
<dl>
<dt id="index-material_002dstencil_002dtest">Procedure: <strong>material-stencil-test</strong> <em>material</em></dt>
<dd><p>Return the stencil test of <var>material</var>.
</p></dd></dl>
<dl>
<dt id="index-material_002dmultisample_003f">Procedure: <strong>material-multisample?</strong> <em>material</em></dt>
<dd><p>Return <code>#t</code> if <var>material</var> uses multisampling.
</p></dd></dl>
<p>Materials support 5 textures. What each texture is used for depends
on the lighting model.
</p>
<dl>
<dt id="index-material_002dtexture_002d0">Procedure: <strong>material-texture-0</strong> <em>material</em></dt>
<dd><p>Return the first texture of <var>material</var>.
</p></dd></dl>
<dl>
<dt id="index-material_002dtexture_002d1">Procedure: <strong>material-texture-1</strong> <em>material</em></dt>
<dd><p>Return the second texture of <var>material</var>.
</p></dd></dl>
<dl>
<dt id="index-material_002dtexture_002d2">Procedure: <strong>material-texture-2</strong> <em>material</em></dt>
<dd><p>Return the third texture of <var>material</var>.
</p></dd></dl>
<dl>
<dt id="index-material_002dtexture_002d3">Procedure: <strong>material-texture-3</strong> <em>material</em></dt>
<dd><p>Return the fourth texture of <var>material</var>.
</p></dd></dl>
<dl>
<dt id="index-material_002dtexture_002d4">Procedure: <strong>material-texture-4</strong> <em>material</em></dt>
<dd><p>Return the fifth texture of <var>material</var>.
</p></dd></dl>
<p>For all data that is specific to the lighting model, materials have a
“properties” field.
</p>
<dl>
<dt id="index-material_002dproperties">Procedure: <strong>material-properties</strong> <em>material</em></dt>
<dd><p>Return the lighting model specific properties of <var>material</var>.
</p></dd></dl>
<span id="Blinn_002dPhong-Materials"></span><h4 class="subsubsection">5.3.11.2 Blinn-Phong Materials</h4>
<p>The <code>(chickadee graphics phong)</code> module has the Blinn-Phong
lighting model:
</p>
<dl>
<dt id="index-make_002dphong_002dmaterial">Procedure: <strong>make-phong-material</strong> <em>[#:name "anonymous"] [#:blend-mode] [#:polygon-mode] [#:cull-face-mode] [#:depth-test] [#:stencil-test] [#:multisample? #f] [#:ambient-factor (vec3 1 1 1)] [#:diffuse-factor (vec3 1 1 1)] [#:specular-factor (vec3 1 1 1)] [#:shininess 32] [#:ambient-texture] [#:diffuse-texture] [#:specular-texture] [#:normal-texture]</em></dt>
<dd>
<p>Return a new Blinn-Phong material.
</p></dd></dl>
<dl>
<dt id="index-make_002dphong_002dproperties">Procedure: <strong>make-phong-properties</strong> <em>[#:ambient] [#:diffuse] [#:specular] [#:shininess]</em></dt>
<dd>
<p>Return a new Blinn-Phong properties object.
</p></dd></dl>
<dl>
<dt id="index-phong_002dproperties_003f">Procedure: <strong>phong-properties?</strong> <em>obj</em></dt>
<dd><p>Return <code>#t</code> if <var>obj</var> is a Blinn-Phong properties object.
</p></dd></dl>
<dl>
<dt id="index-phong_002dproperties_002dambient">Procedure: <strong>phong-properties-ambient</strong> <em>properties</em></dt>
<dd><p>Return the ambient factor of <var>properties</var>.
</p></dd></dl>
<dl>
<dt id="index-phong_002dproperties_002ddiffuse">Procedure: <strong>phong-properties-diffuse</strong> <em>properties</em></dt>
<dd><p>Return the diffuse factor of <var>properties</var>.
</p></dd></dl>
<dl>
<dt id="index-phong_002dproperties_002dspecular">Procedure: <strong>phong-properties-specular</strong> <em>properties</em></dt>
<dd><p>Return the specular factor of <var>properties</var>.
</p></dd></dl>
<dl>
<dt id="index-phong_002dproperties_002dshininess">Procedure: <strong>phong-properties-shininess</strong> <em>properties</em></dt>
<dd><p>Return the shininess factor of <var>properties</var>.
</p></dd></dl>
<span id="PBR-Materials"></span><h4 class="subsubsection">5.3.11.3 PBR Materials</h4>
<p>The <code>(chickadee graphics pbr)</code> module has the PBR lighting model:
</p>
<dl>
<dt id="index-make_002dpbr_002dmaterial">Procedure: <strong>make-pbr-material</strong> <em>[#:name "anonymous"] [#:blend-mode] [#:polygon-mode] [#:cull-face-mode] [#:depth-test] [#:stencil-test] [#:multisample? #f] [#:base-color-factor (vec3 1 1 1)] [#:base-color-texcoord 0] [#:metallic-factor 1.0] [#:roughness-factor 1.0] [#:metallic-roughness-texcoord 0] [#:normal-texcoord 0] [#:occlusion-texcoord 0] [#:emissive-factor (vec3 1 1 1)] [#:emissive-texcoord 0] [#:alpha-mode opaque] [#:alpha-cutoff 0.5] [#:base-color-texture] [#:metallic-roughness-texture] [#:normal-texture] [#:occlusion-texture] [#:emissive-texture]</em></dt>
<dd>
<p>Return a new PBR material.
</p></dd></dl>
<dl>
<dt id="index-make_002dpbr_002dproperties">Procedure: <strong>make-pbr-properties</strong> <em>[#:base-color-factor] [#:base-color-texcoord] [#:metallic-factor] [#:roughness-factor] [#:metallic-roughness-texcoord] [#:normal-texcoord] [#:occlusion-texcoord] [#:emissive-factor] [#:emissive-texcoord] [#:alpha-mode] [#:alpha-cutoff]</em></dt>
<dd>
<p>Return a new PBR properties object.
</p></dd></dl>
<dl>
<dt id="index-pbr_002dproperties_003f">Procedure: <strong>pbr-properties?</strong> <em>obj</em></dt>
<dd><p>Return <code>#t</code> if <var>obj</var> is a PBR properties object.
</p></dd></dl>
<dl>
<dt id="index-pbr_002dproperties_002dbase_002dcolor_002dfactor">Procedure: <strong>pbr-properties-base-color-factor</strong> <em>properties</em></dt>
<dd><p>Return the base color factor of <var>properties</var>.
</p></dd></dl>
<dl>
<dt id="index-pbr_002dproperties_002dbase_002dcolor_002dtexcoord">Procedure: <strong>pbr-properties-base-color-texcoord</strong> <em>properties</em></dt>
<dd><p>Return the base color texture coordinate attribute index of
<var>properties</var>.
</p></dd></dl>
<dl>
<dt id="index-pbr_002dproperties_002dmetallic_002dfactor">Procedure: <strong>pbr-properties-metallic-factor</strong> <em>properties</em></dt>
<dd><p>Return the metallic factor of <var>properties</var>.
</p></dd></dl>
<dl>
<dt id="index-pbr_002dproperties_002droughness">Procedure: <strong>pbr-properties-roughness</strong> <em>properties</em></dt>
<dd><p>Return the roughness factor of <var>properties</var>.
</p></dd></dl>
<dl>
<dt id="index-pbr_002dproperties_002dmetallic_002droughness_002dtexcoord">Procedure: <strong>pbr-properties-metallic-roughness-texcoord</strong> <em>properties</em></dt>
<dd><p>Return the metallic-roughness texture coordinate attribute index of
<var>properties</var>.
</p></dd></dl>
<dl>
<dt id="index-pbr_002dproperties_002dnormal_002dtexcoord">Procedure: <strong>pbr-properties-normal-texcoord</strong> <em>properties</em></dt>
<dd><p>Return the normal texture coordinate attribute index of
<var>properties</var>.
</p></dd></dl>
<dl>
<dt id="index-pbr_002dproperties_002docclusion_002dtexcoord">Procedure: <strong>pbr-properties-occlusion-texcoord</strong> <em>properties</em></dt>
<dd><p>Return the ambient occlusion texture coordinate attribute index of
<var>properties</var>.
</p></dd></dl>
<dl>
<dt id="index-pbr_002dproperties_002demissive_002dfactor">Procedure: <strong>pbr-properties-emissive-factor</strong> <em>properties</em></dt>
<dd><p>Return the emissive factor of <var>properties</var>.
</p></dd></dl>
<dl>
<dt id="index-pbr_002dproperties_002demissive_002dtexcoord">Procedure: <strong>pbr-properties-emissive-texcoord</strong> <em>properties</em></dt>
<dd><p>Return the emissive texture coordinate attribute index of
<var>properties</var>.
</p></dd></dl>
<dl>
<dt id="index-pbr_002dproperties_002dalpha_002dmode">Procedure: <strong>pbr-properties-alpha-mode</strong> <em>properties</em></dt>
<dd><p>Return the alpha mode of <var>properties</var>.
</p></dd></dl>
<dl>
<dt id="index-pbr_002dproperties_002dalpha_002dcutoff">Procedure: <strong>pbr-properties-alpha-cutoff</strong> <em>properties</em></dt>
<dd><p>Return the alpha cutoff threshold of <var>properties</var>.
</p></dd></dl>
<span id="Primitives-and-Meshes"></span><h4 class="subsubsection">5.3.11.4 Primitives and Meshes</h4>
<p>A mesh is a collection of “primitives,” so we should discuss those
next. A primitive contains vertex data and a material.
</p>
<dl>
<dt id="index-make_002dprimitive">Procedure: <strong>make-primitive</strong> <em>name vertex-array material</em></dt>
<dd><p>Return a new primitive named <var>name</var> that renders
<var>vertex-array</var> (see <a href="Buffers.html">Buffers</a>) using <var>material</var>.
</p></dd></dl>
<dl>
<dt id="index-primitive_003f">Procedure: <strong>primitive?</strong> <em>obj</em></dt>
<dd><p>Return <code>#t</code> if <var>obj</var> is a primitive.
</p></dd></dl>
<dl>
<dt id="index-primitive_002dname">Procedure: <strong>primitive-name</strong> <em>primitive</em></dt>
<dd><p>Return the name of <var>primitive</var>.
</p></dd></dl>
<dl>
<dt id="index-primitive_002dvertex_002darray">Procedure: <strong>primitive-vertex-array</strong> <em>primitive</em></dt>
<dd><p>Return the vertex array of <var>primitive</var>.
</p></dd></dl>
<dl>
<dt id="index-primitive_002dmaterial">Procedure: <strong>primitive-material</strong> <em>primitive</em></dt>
<dd><p>Return the material of <var>primitive</var>.
</p></dd></dl>
<p>Okay, now we can talk about meshes, which are just a glorified list of
primitive objects.
</p>
<dl>
<dt id="index-make_002dmesh">Procedure: <strong>make-mesh</strong> <em>name primitives</em></dt>
<dd><p>Return a new mesh named <var>name</var> that is composed of the list
<var>primitives</var>.
</p></dd></dl>
<dl>
<dt id="index-mesh_003f">Procedure: <strong>mesh?</strong> <em>obj</em></dt>
<dd><p>Return <code>#t</code> if <var>obj</var> is a mesh.
</p></dd></dl>
<dl>
<dt id="index-mesh_002dname">Procedure: <strong>mesh-name</strong> <em>mesh</em></dt>
<dd><p>Return the name of <var>mesh</var>.
</p></dd></dl>
<dl>
<dt id="index-mesh_002dprimitives">Procedure: <strong>mesh-primitives</strong> <em>mesh</em></dt>
<dd><p>Return the list of primitives for <var>mesh</var>.
</p></dd></dl>
<p>The mesh module also conveniently provides procedures to build several
basic 3D shapes.
</p>
<dl>
<dt id="index-make_002dplane">Procedure: <strong>make-plane</strong> <em>length width material</em></dt>
<dd><p>Return a new mesh that forms a flat plane on the XZ axis that is
<var>width</var> units long along the X axis and <var>length</var> units long
along the Z axis.
</p></dd></dl>
<dl>
<dt id="index-make_002dtesselated_002dplane">Procedure: <strong>make-tesselated-plane</strong> <em>length width resolution material</em></dt>
<dd><p>Return a new mesh that forms a tesselated plane on the XZ axis that is
<var>width</var> units long along the X axis and <var>length</var> units long
along the Z axis.
</p>
<p>A regular plane is a single rectangle, but a tesselated plane is
subdivided into many smaller rectangles by <var>resolution</var>. This
allows for transforming the vertices in a shader to achieve effects
such as waves in water or mountainous terrain.
</p></dd></dl>
<dl>
<dt id="index-make_002dcube">Procedure: <strong>make-cube</strong> <em>size material</em></dt>
<dd><p>Return a new mesh that forms a cube that is <var>size</var> units big.
</p></dd></dl>
<dl>
<dt id="index-make_002dsphere">Procedure: <strong>make-sphere</strong> <em>radius material [#:quality 2]</em></dt>
<dd><p>Return a new mesh that forms a sphere that has a radius of
<var>radius</var> units. Since 3D models are composed of triangles, the
quality of a sphere is entirely dependent upon how many triangles are
used to appromixate the shape. The higher the value of <var>quality</var>,
the better the appromixation, but the more time it will take to
generate and the more expensive it will be to draw. The number of
triangles in the resulting sphere increases exponentially with each
increment to <var>quality</var>.
</p></dd></dl>
<hr />
<div class="header">
<p>
Next: <a href="Buffers.html" accesskey="n" rel="next">Buffers</a>, Previous: <a href="Skyboxes.html" accesskey="p" rel="prev">Skyboxes</a>, Up: <a href="Graphics.html" accesskey="u" rel="up">Graphics</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Index.html" title="Index" rel="index">Index</a>]</p>
</div>
</body>
</html>
|