pixospritz-core 0.10.1 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (157) hide show
  1. package/README.md +36 -286
  2. package/dist/bundle.js +13 -3
  3. package/dist/bundle.js.map +1 -1
  4. package/dist/style.css +1 -0
  5. package/package.json +43 -44
  6. package/src/components/WebGLView.jsx +318 -0
  7. package/src/css/pixos.css +372 -0
  8. package/src/engine/actions/animate.js +41 -0
  9. package/src/engine/actions/changezone.js +135 -0
  10. package/src/engine/actions/chat.js +109 -0
  11. package/src/engine/actions/dialogue.js +90 -0
  12. package/src/engine/actions/face.js +22 -0
  13. package/src/engine/actions/greeting.js +28 -0
  14. package/src/engine/actions/interact.js +86 -0
  15. package/src/engine/actions/move.js +67 -0
  16. package/src/engine/actions/patrol.js +109 -0
  17. package/src/engine/actions/prompt.js +185 -0
  18. package/src/engine/actions/script.js +42 -0
  19. package/src/engine/core/audio/AudioSystem.js +543 -0
  20. package/src/engine/core/cutscene/PxcPlayer.js +956 -0
  21. package/src/engine/core/cutscene/manager.js +243 -0
  22. package/src/engine/core/database/index.js +75 -0
  23. package/src/engine/core/debug/index.js +371 -0
  24. package/src/engine/core/hud/index.js +765 -0
  25. package/src/engine/core/index.js +540 -0
  26. package/src/engine/core/input/gamepad/Controller.js +71 -0
  27. package/src/engine/core/input/gamepad/ControllerButtons.js +231 -0
  28. package/src/engine/core/input/gamepad/ControllerStick.js +173 -0
  29. package/src/engine/core/input/gamepad/index.js +592 -0
  30. package/src/engine/core/input/keyboard.js +196 -0
  31. package/src/engine/core/input/manager.js +485 -0
  32. package/src/engine/core/input/mouse.js +203 -0
  33. package/src/engine/core/input/touch.js +175 -0
  34. package/src/engine/core/mode/manager.js +199 -0
  35. package/src/engine/core/net/manager.js +535 -0
  36. package/src/engine/core/queue/action.js +83 -0
  37. package/src/engine/core/queue/event.js +82 -0
  38. package/src/engine/core/queue/index.js +44 -0
  39. package/src/engine/core/queue/loadable.js +33 -0
  40. package/src/engine/core/render/CameraEffects.js +494 -0
  41. package/src/engine/core/render/FrustumCuller.js +417 -0
  42. package/src/engine/core/render/LODManager.js +285 -0
  43. package/src/engine/core/render/ParticleManager.js +529 -0
  44. package/src/engine/core/render/TextureAtlas.js +465 -0
  45. package/src/engine/core/render/camera.js +338 -0
  46. package/src/engine/core/render/light.js +197 -0
  47. package/src/engine/core/render/manager.js +1079 -0
  48. package/src/engine/core/render/shaders.js +110 -0
  49. package/src/engine/core/render/skybox.js +342 -0
  50. package/src/engine/core/resource/manager.js +133 -0
  51. package/src/engine/core/resource/object.js +611 -0
  52. package/src/engine/core/resource/texture.js +103 -0
  53. package/src/engine/core/resource/tileset.js +177 -0
  54. package/src/engine/core/scene/avatar.js +215 -0
  55. package/src/engine/core/scene/speech.js +138 -0
  56. package/src/engine/core/scene/sprite.js +702 -0
  57. package/src/engine/core/scene/spritz.js +189 -0
  58. package/src/engine/core/scene/world.js +681 -0
  59. package/src/engine/core/scene/zone.js +1167 -0
  60. package/src/engine/core/store/index.js +110 -0
  61. package/src/engine/dynamic/animatedSprite.js +64 -0
  62. package/src/engine/dynamic/animatedTile.js +98 -0
  63. package/src/engine/dynamic/avatar.js +110 -0
  64. package/src/engine/dynamic/map.js +174 -0
  65. package/src/engine/dynamic/sprite.js +255 -0
  66. package/src/engine/dynamic/spritz.js +119 -0
  67. package/src/engine/events/EventSystem.js +609 -0
  68. package/src/engine/events/camera.js +142 -0
  69. package/src/engine/events/chat.js +75 -0
  70. package/src/engine/events/menu.js +186 -0
  71. package/src/engine/scripting/CallbackManager.js +514 -0
  72. package/src/engine/scripting/PixoScriptInterpreter.js +81 -0
  73. package/src/engine/scripting/PixoScriptLibrary.js +704 -0
  74. package/src/engine/shaders/effects/index.js +450 -0
  75. package/src/engine/shaders/fs.js +222 -0
  76. package/src/engine/shaders/particles/fs.js +41 -0
  77. package/src/engine/shaders/particles/vs.js +61 -0
  78. package/src/engine/shaders/picker/fs.js +34 -0
  79. package/src/engine/shaders/picker/init.js +62 -0
  80. package/src/engine/shaders/picker/vs.js +42 -0
  81. package/src/engine/shaders/pxsl/README.md +250 -0
  82. package/src/engine/shaders/pxsl/index.js +25 -0
  83. package/src/engine/shaders/pxsl/library.js +608 -0
  84. package/src/engine/shaders/pxsl/manager.js +338 -0
  85. package/src/engine/shaders/pxsl/specification.js +363 -0
  86. package/src/engine/shaders/pxsl/transpiler.js +753 -0
  87. package/src/engine/shaders/skybox/cosmic/fs.js +147 -0
  88. package/src/engine/shaders/skybox/cosmic/vs.js +23 -0
  89. package/src/engine/shaders/skybox/matrix/fs.js +127 -0
  90. package/src/engine/shaders/skybox/matrix/vs.js +23 -0
  91. package/src/engine/shaders/skybox/morning/fs.js +109 -0
  92. package/src/engine/shaders/skybox/morning/vs.js +23 -0
  93. package/src/engine/shaders/skybox/neon/fs.js +119 -0
  94. package/src/engine/shaders/skybox/neon/vs.js +23 -0
  95. package/src/engine/shaders/skybox/sky/fs.js +114 -0
  96. package/src/engine/shaders/skybox/sky/vs.js +23 -0
  97. package/src/engine/shaders/skybox/sunset/fs.js +101 -0
  98. package/src/engine/shaders/skybox/sunset/vs.js +23 -0
  99. package/src/engine/shaders/transition/blur/fs.js +42 -0
  100. package/src/engine/shaders/transition/blur/vs.js +26 -0
  101. package/src/engine/shaders/transition/cross/fs.js +36 -0
  102. package/src/engine/shaders/transition/cross/vs.js +26 -0
  103. package/src/engine/shaders/transition/crossBlur/fs.js +41 -0
  104. package/src/engine/shaders/transition/crossBlur/vs.js +25 -0
  105. package/src/engine/shaders/transition/dissolve/fs.js +78 -0
  106. package/src/engine/shaders/transition/dissolve/vs.js +24 -0
  107. package/src/engine/shaders/transition/fade/fs.js +31 -0
  108. package/src/engine/shaders/transition/fade/vs.js +27 -0
  109. package/src/engine/shaders/transition/iris/fs.js +52 -0
  110. package/src/engine/shaders/transition/iris/vs.js +24 -0
  111. package/src/engine/shaders/transition/pixelate/fs.js +44 -0
  112. package/src/engine/shaders/transition/pixelate/vs.js +24 -0
  113. package/src/engine/shaders/transition/slide/fs.js +53 -0
  114. package/src/engine/shaders/transition/slide/vs.js +24 -0
  115. package/src/engine/shaders/transition/swirl/fs.js +39 -0
  116. package/src/engine/shaders/transition/swirl/vs.js +26 -0
  117. package/src/engine/shaders/transition/wipe/fs.js +50 -0
  118. package/src/engine/shaders/transition/wipe/vs.js +24 -0
  119. package/src/engine/shaders/vs.js +60 -0
  120. package/src/engine/utils/CameraController.js +506 -0
  121. package/src/engine/utils/ObjHelper.js +551 -0
  122. package/src/engine/utils/debug-logger.js +110 -0
  123. package/src/engine/utils/enums.js +305 -0
  124. package/src/engine/utils/generator.js +156 -0
  125. package/src/engine/utils/index.js +21 -0
  126. package/src/engine/utils/loaders/ActionLoader.js +77 -0
  127. package/src/engine/utils/loaders/AudioLoader.js +157 -0
  128. package/src/engine/utils/loaders/EventLoader.js +66 -0
  129. package/src/engine/utils/loaders/ObjectLoader.js +67 -0
  130. package/src/engine/utils/loaders/SpriteLoader.js +77 -0
  131. package/src/engine/utils/loaders/TilesetLoader.js +103 -0
  132. package/src/engine/utils/loaders/index.js +21 -0
  133. package/src/engine/utils/math/matrix4.js +367 -0
  134. package/src/engine/utils/math/vector.js +458 -0
  135. package/src/engine/utils/obj/_old_js/index.js +46 -0
  136. package/src/engine/utils/obj/_old_js/layout.js +308 -0
  137. package/src/engine/utils/obj/_old_js/material.js +711 -0
  138. package/src/engine/utils/obj/_old_js/mesh.js +761 -0
  139. package/src/engine/utils/obj/_old_js/utils.js +647 -0
  140. package/src/engine/utils/obj/index.js +24 -0
  141. package/src/engine/utils/obj/js/index.js +277 -0
  142. package/src/engine/utils/obj/js/loader.js +232 -0
  143. package/src/engine/utils/obj/layout.js +246 -0
  144. package/src/engine/utils/obj/material.js +665 -0
  145. package/src/engine/utils/obj/mesh.js +657 -0
  146. package/src/engine/utils/obj/ts/index.ts +72 -0
  147. package/src/engine/utils/obj/ts/layout.ts +265 -0
  148. package/src/engine/utils/obj/ts/material.ts +760 -0
  149. package/src/engine/utils/obj/ts/mesh.ts +785 -0
  150. package/src/engine/utils/obj/ts/utils.ts +501 -0
  151. package/src/engine/utils/obj/utils.js +428 -0
  152. package/src/engine/utils/resources.js +18 -0
  153. package/src/index.jsx +55 -0
  154. package/src/spritz/player.js +18 -0
  155. package/src/spritz/readme.md +18 -0
  156. package/LICENSE +0 -437
  157. package/dist/bundle.js.LICENSE.txt +0 -31
@@ -0,0 +1,711 @@
1
+ "use strict";
2
+ var __read = (this && this.__read) || function (o, n) {
3
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
4
+ if (!m) return o;
5
+ var i = m.call(o), r, ar = [], e;
6
+ try {
7
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
8
+ }
9
+ catch (error) { e = { error: error }; }
10
+ finally {
11
+ try {
12
+ if (r && !r.done && (m = i["return"])) m.call(i);
13
+ }
14
+ finally { if (e) throw e.error; }
15
+ }
16
+ return ar;
17
+ };
18
+ var __values = (this && this.__values) || function(o) {
19
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
20
+ if (m) return m.call(o);
21
+ if (o && typeof o.length === "number") return {
22
+ next: function () {
23
+ if (o && i >= o.length) o = void 0;
24
+ return { value: o && o[i++], done: !o };
25
+ }
26
+ };
27
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
28
+ };
29
+ exports.__esModule = true;
30
+ exports.MaterialLibrary = exports.Material = void 0;
31
+ /**
32
+ * The Material class.
33
+ */
34
+ var Material = /** @class */ (function () {
35
+ function Material(name) {
36
+ this.name = name;
37
+ /**
38
+ * Constructor
39
+ * @param {String} name the unique name of the material
40
+ */
41
+ // The values for the following attibutes
42
+ // are an array of R, G, B normalized values.
43
+ // Ka - Ambient Reflectivity
44
+ this.ambient = [0, 0, 0];
45
+ // Kd - Defuse Reflectivity
46
+ this.diffuse = [0, 0, 0];
47
+ // Ks
48
+ this.specular = [0, 0, 0];
49
+ // Ke
50
+ this.emissive = [0, 0, 0];
51
+ // Tf
52
+ this.transmissionFilter = [0, 0, 0];
53
+ // d
54
+ this.dissolve = 0;
55
+ // valid range is between 0 and 1000
56
+ this.specularExponent = 0;
57
+ // either d or Tr; valid values are normalized
58
+ this.transparency = 0;
59
+ // illum - the enum of the illumination model to use
60
+ this.illumination = 0;
61
+ // Ni - Set to "normal" (air).
62
+ this.refractionIndex = 1;
63
+ // sharpness
64
+ this.sharpness = 0;
65
+ // map_Kd
66
+ this.mapDiffuse = emptyTextureOptions();
67
+ // map_Ka
68
+ this.mapAmbient = emptyTextureOptions();
69
+ // map_Ks
70
+ this.mapSpecular = emptyTextureOptions();
71
+ // map_Ns
72
+ this.mapSpecularExponent = emptyTextureOptions();
73
+ // map_d
74
+ this.mapDissolve = emptyTextureOptions();
75
+ // map_aat
76
+ this.antiAliasing = false;
77
+ // map_bump or bump
78
+ this.mapBump = emptyTextureOptions();
79
+ // disp
80
+ this.mapDisplacement = emptyTextureOptions();
81
+ // decal
82
+ this.mapDecal = emptyTextureOptions();
83
+ // map_Ke
84
+ this.mapEmissive = emptyTextureOptions();
85
+ // refl - when the reflection type is a cube, there will be multiple refl
86
+ // statements for each side of the cube. If it's a spherical
87
+ // reflection, there should only ever be one.
88
+ this.mapReflections = [];
89
+ }
90
+ return Material;
91
+ }());
92
+ exports.Material = Material;
93
+ var SENTINEL_MATERIAL = new Material("sentinel");
94
+ /**
95
+ * https://en.wikipedia.org/wiki/Wavefront_.obj_file
96
+ * http://paulbourke.net/dataformats/mtl/
97
+ */
98
+ var MaterialLibrary = /** @class */ (function () {
99
+ function MaterialLibrary(data) {
100
+ this.data = data;
101
+ /**
102
+ * Constructs the Material Parser
103
+ * @param mtlData the MTL file contents
104
+ */
105
+ this.currentMaterial = SENTINEL_MATERIAL;
106
+ this.materials = {};
107
+ this.parse();
108
+ }
109
+ /* eslint-disable camelcase */
110
+ /* the function names here disobey camelCase conventions
111
+ to make parsing/routing easier. see the parse function
112
+ documentation for more information. */
113
+ /**
114
+ * Creates a new Material object and adds to the registry.
115
+ * @param tokens the tokens associated with the directive
116
+ */
117
+ MaterialLibrary.prototype.parse_newmtl = function (tokens) {
118
+ var name = tokens[0];
119
+ // console.info('Parsing new Material:', name);
120
+ this.currentMaterial = new Material(name);
121
+ this.materials[name] = this.currentMaterial;
122
+ };
123
+ /**
124
+ * See the documenation for parse_Ka below for a better understanding.
125
+ *
126
+ * Given a list of possible color tokens, returns an array of R, G, and B
127
+ * color values.
128
+ *
129
+ * @param tokens the tokens associated with the directive
130
+ * @return {*} a 3 element array containing the R, G, and B values
131
+ * of the color.
132
+ */
133
+ MaterialLibrary.prototype.parseColor = function (tokens) {
134
+ if (tokens[0] == "spectral") {
135
+ throw new Error("The MTL parser does not support spectral curve files. You will " +
136
+ "need to convert the MTL colors to either RGB or CIEXYZ.");
137
+ }
138
+ if (tokens[0] == "xyz") {
139
+ throw new Error("The MTL parser does not currently support XYZ colors. Either convert the " +
140
+ "XYZ values to RGB or create an issue to add support for XYZ");
141
+ }
142
+ // from my understanding of the spec, RGB values at this point
143
+ // will either be 3 floats or exactly 1 float, so that's the check
144
+ // that i'm going to perform here
145
+ if (tokens.length == 3) {
146
+ var _a = __read(tokens, 3), x = _a[0], y = _a[1], z = _a[2];
147
+ return [parseFloat(x), parseFloat(y), parseFloat(z)];
148
+ }
149
+ // Since tokens at this point has a length of 3, we're going to assume
150
+ // it's exactly 1, skipping the check for 2.
151
+ var value = parseFloat(tokens[0]);
152
+ // in this case, all values are equivalent
153
+ return [value, value, value];
154
+ };
155
+ /**
156
+ * Parse the ambient reflectivity
157
+ *
158
+ * A Ka directive can take one of three forms:
159
+ * - Ka r g b
160
+ * - Ka spectral file.rfl
161
+ * - Ka xyz x y z
162
+ * These three forms are mutually exclusive in that only one
163
+ * declaration can exist per material. It is considered a syntax
164
+ * error otherwise.
165
+ *
166
+ * The "Ka" form specifies the ambient reflectivity using RGB values.
167
+ * The "g" and "b" values are optional. If only the "r" value is
168
+ * specified, then the "g" and "b" values are assigned the value of
169
+ * "r". Values are normally in the range 0.0 to 1.0. Values outside
170
+ * of this range increase or decrease the reflectivity accordingly.
171
+ *
172
+ * The "Ka spectral" form specifies the ambient reflectivity using a
173
+ * spectral curve. "file.rfl" is the name of the ".rfl" file containing
174
+ * the curve data. "factor" is an optional argument which is a multiplier
175
+ * for the values in the .rfl file and defaults to 1.0 if not specified.
176
+ *
177
+ * The "Ka xyz" form specifies the ambient reflectivity using CIEXYZ values.
178
+ * "x y z" are the values of the CIEXYZ color space. The "y" and "z" arguments
179
+ * are optional and take on the value of the "x" component if only "x" is
180
+ * specified. The "x y z" values are normally in the range of 0.0 to 1.0 and
181
+ * increase or decrease ambient reflectivity accordingly outside of that
182
+ * range.
183
+ *
184
+ * @param tokens the tokens associated with the directive
185
+ */
186
+ MaterialLibrary.prototype.parse_Ka = function (tokens) {
187
+ this.currentMaterial.ambient = this.parseColor(tokens);
188
+ };
189
+ /**
190
+ * Diffuse Reflectivity
191
+ *
192
+ * Similar to the Ka directive. Simply replace "Ka" with "Kd" and the rules
193
+ * are the same
194
+ *
195
+ * @param tokens the tokens associated with the directive
196
+ */
197
+ MaterialLibrary.prototype.parse_Kd = function (tokens) {
198
+ this.currentMaterial.diffuse = this.parseColor(tokens);
199
+ };
200
+ /**
201
+ * Spectral Reflectivity
202
+ *
203
+ * Similar to the Ka directive. Simply replace "Ks" with "Kd" and the rules
204
+ * are the same
205
+ *
206
+ * @param tokens the tokens associated with the directive
207
+ */
208
+ MaterialLibrary.prototype.parse_Ks = function (tokens) {
209
+ this.currentMaterial.specular = this.parseColor(tokens);
210
+ };
211
+ /**
212
+ * Emissive
213
+ *
214
+ * The amount and color of light emitted by the object.
215
+ *
216
+ * @param tokens the tokens associated with the directive
217
+ */
218
+ MaterialLibrary.prototype.parse_Ke = function (tokens) {
219
+ this.currentMaterial.emissive = this.parseColor(tokens);
220
+ };
221
+ /**
222
+ * Transmission Filter
223
+ *
224
+ * Any light passing through the object is filtered by the transmission
225
+ * filter, which only allows specific colors to pass through. For example, Tf
226
+ * 0 1 0 allows all of the green to pass through and filters out all of the
227
+ * red and blue.
228
+ *
229
+ * Similar to the Ka directive. Simply replace "Ks" with "Tf" and the rules
230
+ * are the same
231
+ *
232
+ * @param tokens the tokens associated with the directive
233
+ */
234
+ MaterialLibrary.prototype.parse_Tf = function (tokens) {
235
+ this.currentMaterial.transmissionFilter = this.parseColor(tokens);
236
+ };
237
+ /**
238
+ * Specifies the dissolve for the current material.
239
+ *
240
+ * Statement: d [-halo] `factor`
241
+ *
242
+ * Example: "d 0.5"
243
+ *
244
+ * The factor is the amount this material dissolves into the background. A
245
+ * factor of 1.0 is fully opaque. This is the default when a new material is
246
+ * created. A factor of 0.0 is fully dissolved (completely transparent).
247
+ *
248
+ * Unlike a real transparent material, the dissolve does not depend upon
249
+ * material thickness nor does it have any spectral character. Dissolve works
250
+ * on all illumination models.
251
+ *
252
+ * The dissolve statement allows for an optional "-halo" flag which indicates
253
+ * that a dissolve is dependent on the surface orientation relative to the
254
+ * viewer. For example, a sphere with the following dissolve, "d -halo 0.0",
255
+ * will be fully dissolved at its center and will appear gradually more opaque
256
+ * toward its edge.
257
+ *
258
+ * "factor" is the minimum amount of dissolve applied to the material. The
259
+ * amount of dissolve will vary between 1.0 (fully opaque) and the specified
260
+ * "factor". The formula is:
261
+ *
262
+ * dissolve = 1.0 - (N*v)(1.0-factor)
263
+ *
264
+ * @param tokens the tokens associated with the directive
265
+ */
266
+ MaterialLibrary.prototype.parse_d = function (tokens) {
267
+ // this ignores the -halo option as I can't find any documentation on what
268
+ // it's supposed to be.
269
+ this.currentMaterial.dissolve = parseFloat(tokens.pop() || "0");
270
+ };
271
+ /**
272
+ * The "illum" statement specifies the illumination model to use in the
273
+ * material. Illumination models are mathematical equations that represent
274
+ * various material lighting and shading effects.
275
+ *
276
+ * The illumination number can be a number from 0 to 10. The following are
277
+ * the list of illumination enumerations and their summaries:
278
+ * 0. Color on and Ambient off
279
+ * 1. Color on and Ambient on
280
+ * 2. Highlight on
281
+ * 3. Reflection on and Ray trace on
282
+ * 4. Transparency: Glass on, Reflection: Ray trace on
283
+ * 5. Reflection: Fresnel on and Ray trace on
284
+ * 6. Transparency: Refraction on, Reflection: Fresnel off and Ray trace on
285
+ * 7. Transparency: Refraction on, Reflection: Fresnel on and Ray trace on
286
+ * 8. Reflection on and Ray trace off
287
+ * 9. Transparency: Glass on, Reflection: Ray trace off
288
+ * 10. Casts shadows onto invisible surfaces
289
+ *
290
+ * Example: "illum 2" to specify the "Highlight on" model
291
+ *
292
+ * @param tokens the tokens associated with the directive
293
+ */
294
+ MaterialLibrary.prototype.parse_illum = function (tokens) {
295
+ this.currentMaterial.illumination = parseInt(tokens[0]);
296
+ };
297
+ /**
298
+ * Optical Density (AKA Index of Refraction)
299
+ *
300
+ * Statement: Ni `index`
301
+ *
302
+ * Example: Ni 1.0
303
+ *
304
+ * Specifies the optical density for the surface. `index` is the value
305
+ * for the optical density. The values can range from 0.001 to 10. A value of
306
+ * 1.0 means that light does not bend as it passes through an object.
307
+ * Increasing the optical_density increases the amount of bending. Glass has
308
+ * an index of refraction of about 1.5. Values of less than 1.0 produce
309
+ * bizarre results and are not recommended
310
+ *
311
+ * @param tokens the tokens associated with the directive
312
+ */
313
+ MaterialLibrary.prototype.parse_Ni = function (tokens) {
314
+ this.currentMaterial.refractionIndex = parseFloat(tokens[0]);
315
+ };
316
+ /**
317
+ * Specifies the specular exponent for the current material. This defines the
318
+ * focus of the specular highlight.
319
+ *
320
+ * Statement: Ns `exponent`
321
+ *
322
+ * Example: "Ns 250"
323
+ *
324
+ * `exponent` is the value for the specular exponent. A high exponent results
325
+ * in a tight, concentrated highlight. Ns Values normally range from 0 to
326
+ * 1000.
327
+ *
328
+ * @param tokens the tokens associated with the directive
329
+ */
330
+ MaterialLibrary.prototype.parse_Ns = function (tokens) {
331
+ this.currentMaterial.specularExponent = parseInt(tokens[0]);
332
+ };
333
+ /**
334
+ * Specifies the sharpness of the reflections from the local reflection map.
335
+ *
336
+ * Statement: sharpness `value`
337
+ *
338
+ * Example: "sharpness 100"
339
+ *
340
+ * If a material does not have a local reflection map defined in its material
341
+ * defintions, sharpness will apply to the global reflection map defined in
342
+ * PreView.
343
+ *
344
+ * `value` can be a number from 0 to 1000. The default is 60. A high value
345
+ * results in a clear reflection of objects in the reflection map.
346
+ *
347
+ * Tip: sharpness values greater than 100 introduce aliasing effects in
348
+ * flat surfaces that are viewed at a sharp angle.
349
+ *
350
+ * @param tokens the tokens associated with the directive
351
+ */
352
+ MaterialLibrary.prototype.parse_sharpness = function (tokens) {
353
+ this.currentMaterial.sharpness = parseInt(tokens[0]);
354
+ };
355
+ /**
356
+ * Parses the -cc flag and updates the options object with the values.
357
+ *
358
+ * @param values the values passed to the -cc flag
359
+ * @param options the Object of all image options
360
+ */
361
+ MaterialLibrary.prototype.parse_cc = function (values, options) {
362
+ options.colorCorrection = values[0] == "on";
363
+ };
364
+ /**
365
+ * Parses the -blendu flag and updates the options object with the values.
366
+ *
367
+ * @param values the values passed to the -blendu flag
368
+ * @param options the Object of all image options
369
+ */
370
+ MaterialLibrary.prototype.parse_blendu = function (values, options) {
371
+ options.horizontalBlending = values[0] == "on";
372
+ };
373
+ /**
374
+ * Parses the -blendv flag and updates the options object with the values.
375
+ *
376
+ * @param values the values passed to the -blendv flag
377
+ * @param options the Object of all image options
378
+ */
379
+ MaterialLibrary.prototype.parse_blendv = function (values, options) {
380
+ options.verticalBlending = values[0] == "on";
381
+ };
382
+ /**
383
+ * Parses the -boost flag and updates the options object with the values.
384
+ *
385
+ * @param values the values passed to the -boost flag
386
+ * @param options the Object of all image options
387
+ */
388
+ MaterialLibrary.prototype.parse_boost = function (values, options) {
389
+ options.boostMipMapSharpness = parseFloat(values[0]);
390
+ };
391
+ /**
392
+ * Parses the -mm flag and updates the options object with the values.
393
+ *
394
+ * @param values the values passed to the -mm flag
395
+ * @param options the Object of all image options
396
+ */
397
+ MaterialLibrary.prototype.parse_mm = function (values, options) {
398
+ options.modifyTextureMap.brightness = parseFloat(values[0]);
399
+ options.modifyTextureMap.contrast = parseFloat(values[1]);
400
+ };
401
+ /**
402
+ * Parses and sets the -o, -s, and -t u, v, and w values
403
+ *
404
+ * @param values the values passed to the -o, -s, -t flag
405
+ * @param {Object} option the Object of either the -o, -s, -t option
406
+ * @param {Integer} defaultValue the Object of all image options
407
+ */
408
+ MaterialLibrary.prototype.parse_ost = function (values, option, defaultValue) {
409
+ while (values.length < 3) {
410
+ values.push(defaultValue.toString());
411
+ }
412
+ option.u = parseFloat(values[0]);
413
+ option.v = parseFloat(values[1]);
414
+ option.w = parseFloat(values[2]);
415
+ };
416
+ /**
417
+ * Parses the -o flag and updates the options object with the values.
418
+ *
419
+ * @param values the values passed to the -o flag
420
+ * @param options the Object of all image options
421
+ */
422
+ MaterialLibrary.prototype.parse_o = function (values, options) {
423
+ this.parse_ost(values, options.offset, 0);
424
+ };
425
+ /**
426
+ * Parses the -s flag and updates the options object with the values.
427
+ *
428
+ * @param values the values passed to the -s flag
429
+ * @param options the Object of all image options
430
+ */
431
+ MaterialLibrary.prototype.parse_s = function (values, options) {
432
+ this.parse_ost(values, options.scale, 1);
433
+ };
434
+ /**
435
+ * Parses the -t flag and updates the options object with the values.
436
+ *
437
+ * @param values the values passed to the -t flag
438
+ * @param options the Object of all image options
439
+ */
440
+ MaterialLibrary.prototype.parse_t = function (values, options) {
441
+ this.parse_ost(values, options.turbulence, 0);
442
+ };
443
+ /**
444
+ * Parses the -texres flag and updates the options object with the values.
445
+ *
446
+ * @param values the values passed to the -texres flag
447
+ * @param options the Object of all image options
448
+ */
449
+ MaterialLibrary.prototype.parse_texres = function (values, options) {
450
+ options.textureResolution = parseFloat(values[0]);
451
+ };
452
+ /**
453
+ * Parses the -clamp flag and updates the options object with the values.
454
+ *
455
+ * @param values the values passed to the -clamp flag
456
+ * @param options the Object of all image options
457
+ */
458
+ MaterialLibrary.prototype.parse_clamp = function (values, options) {
459
+ options.clamp = values[0] == "on";
460
+ };
461
+ /**
462
+ * Parses the -bm flag and updates the options object with the values.
463
+ *
464
+ * @param values the values passed to the -bm flag
465
+ * @param options the Object of all image options
466
+ */
467
+ MaterialLibrary.prototype.parse_bm = function (values, options) {
468
+ options.bumpMultiplier = parseFloat(values[0]);
469
+ };
470
+ /**
471
+ * Parses the -imfchan flag and updates the options object with the values.
472
+ *
473
+ * @param values the values passed to the -imfchan flag
474
+ * @param options the Object of all image options
475
+ */
476
+ MaterialLibrary.prototype.parse_imfchan = function (values, options) {
477
+ options.imfChan = values[0];
478
+ };
479
+ /**
480
+ * This only exists for relection maps and denotes the type of reflection.
481
+ *
482
+ * @param values the values passed to the -type flag
483
+ * @param options the Object of all image options
484
+ */
485
+ MaterialLibrary.prototype.parse_type = function (values, options) {
486
+ options.reflectionType = values[0];
487
+ };
488
+ /**
489
+ * Parses the texture's options and returns an options object with the info
490
+ *
491
+ * @param tokens all of the option tokens to pass to the texture
492
+ * @return {Object} a complete object of objects to apply to the texture
493
+ */
494
+ MaterialLibrary.prototype.parseOptions = function (tokens) {
495
+ var options = emptyTextureOptions();
496
+ var option;
497
+ var values;
498
+ var optionsToValues = {};
499
+ tokens.reverse();
500
+ while (tokens.length) {
501
+ // token is guaranteed to exists here, hence the explicit "as"
502
+ var token = tokens.pop();
503
+ if (token.startsWith("-")) {
504
+ option = token.substr(1);
505
+ optionsToValues[option] = [];
506
+ }
507
+ else if (option) {
508
+ optionsToValues[option].push(token);
509
+ }
510
+ }
511
+ for (option in optionsToValues) {
512
+ if (!optionsToValues.hasOwnProperty(option)) {
513
+ continue;
514
+ }
515
+ values = optionsToValues[option];
516
+ var optionMethod = this["parse_".concat(option)];
517
+ if (optionMethod) {
518
+ optionMethod.bind(this)(values, options);
519
+ }
520
+ }
521
+ return options;
522
+ };
523
+ /**
524
+ * Parses the given texture map line.
525
+ *
526
+ * @param tokens all of the tokens representing the texture
527
+ * @return a complete object of objects to apply to the texture
528
+ */
529
+ MaterialLibrary.prototype.parseMap = function (tokens) {
530
+ var _a;
531
+ // according to wikipedia:
532
+ // (https://en.wikipedia.org/wiki/Wavefront_.obj_file#Vendor_specific_alterations)
533
+ // there is at least one vendor that places the filename before the options
534
+ // rather than after (which is to spec). All options start with a '-'
535
+ // so if the first token doesn't start with a '-', we're going to assume
536
+ // it's the name of the map file.
537
+ var optionsString;
538
+ var filename = "";
539
+ if (!tokens[0].startsWith("-")) {
540
+ _a = __read(tokens), filename = _a[0], optionsString = _a.slice(1);
541
+ }
542
+ else {
543
+ filename = tokens.pop();
544
+ optionsString = tokens;
545
+ }
546
+ var options = this.parseOptions(optionsString);
547
+ options.filename = filename.replace(/\\/g, "/");
548
+ return options;
549
+ };
550
+ /**
551
+ * Parses the ambient map.
552
+ *
553
+ * @param tokens list of tokens for the map_Ka direcive
554
+ */
555
+ MaterialLibrary.prototype.parse_map_Ka = function (tokens) {
556
+ this.currentMaterial.mapAmbient = this.parseMap(tokens);
557
+ };
558
+ /**
559
+ * Parses the diffuse map.
560
+ *
561
+ * @param tokens list of tokens for the map_Kd direcive
562
+ */
563
+ MaterialLibrary.prototype.parse_map_Kd = function (tokens) {
564
+ this.currentMaterial.mapDiffuse = this.parseMap(tokens);
565
+ };
566
+ /**
567
+ * Parses the specular map.
568
+ *
569
+ * @param tokens list of tokens for the map_Ks direcive
570
+ */
571
+ MaterialLibrary.prototype.parse_map_Ks = function (tokens) {
572
+ this.currentMaterial.mapSpecular = this.parseMap(tokens);
573
+ };
574
+ /**
575
+ * Parses the emissive map.
576
+ *
577
+ * @param tokens list of tokens for the map_Ke direcive
578
+ */
579
+ MaterialLibrary.prototype.parse_map_Ke = function (tokens) {
580
+ this.currentMaterial.mapEmissive = this.parseMap(tokens);
581
+ };
582
+ /**
583
+ * Parses the specular exponent map.
584
+ *
585
+ * @param tokens list of tokens for the map_Ns direcive
586
+ */
587
+ MaterialLibrary.prototype.parse_map_Ns = function (tokens) {
588
+ this.currentMaterial.mapSpecularExponent = this.parseMap(tokens);
589
+ };
590
+ /**
591
+ * Parses the dissolve map.
592
+ *
593
+ * @param tokens list of tokens for the map_d direcive
594
+ */
595
+ MaterialLibrary.prototype.parse_map_d = function (tokens) {
596
+ this.currentMaterial.mapDissolve = this.parseMap(tokens);
597
+ };
598
+ /**
599
+ * Parses the anti-aliasing option.
600
+ *
601
+ * @param tokens list of tokens for the map_aat direcive
602
+ */
603
+ MaterialLibrary.prototype.parse_map_aat = function (tokens) {
604
+ this.currentMaterial.antiAliasing = tokens[0] == "on";
605
+ };
606
+ /**
607
+ * Parses the bump map.
608
+ *
609
+ * @param tokens list of tokens for the map_bump direcive
610
+ */
611
+ MaterialLibrary.prototype.parse_map_bump = function (tokens) {
612
+ this.currentMaterial.mapBump = this.parseMap(tokens);
613
+ };
614
+ /**
615
+ * Parses the bump map.
616
+ *
617
+ * @param tokens list of tokens for the bump direcive
618
+ */
619
+ MaterialLibrary.prototype.parse_bump = function (tokens) {
620
+ this.parse_map_bump(tokens);
621
+ };
622
+ /**
623
+ * Parses the disp map.
624
+ *
625
+ * @param tokens list of tokens for the disp direcive
626
+ */
627
+ MaterialLibrary.prototype.parse_disp = function (tokens) {
628
+ this.currentMaterial.mapDisplacement = this.parseMap(tokens);
629
+ };
630
+ /**
631
+ * Parses the decal map.
632
+ *
633
+ * @param tokens list of tokens for the map_decal direcive
634
+ */
635
+ MaterialLibrary.prototype.parse_decal = function (tokens) {
636
+ this.currentMaterial.mapDecal = this.parseMap(tokens);
637
+ };
638
+ /**
639
+ * Parses the refl map.
640
+ *
641
+ * @param tokens list of tokens for the refl direcive
642
+ */
643
+ MaterialLibrary.prototype.parse_refl = function (tokens) {
644
+ this.currentMaterial.mapReflections.push(this.parseMap(tokens));
645
+ };
646
+ /**
647
+ * Parses the MTL file.
648
+ *
649
+ * Iterates line by line parsing each MTL directive.
650
+ *
651
+ * This function expects the first token in the line
652
+ * to be a valid MTL directive. That token is then used
653
+ * to try and run a method on this class. parse_[directive]
654
+ * E.g., the `newmtl` directive would try to call the method
655
+ * parse_newmtl. Each parsing function takes in the remaining
656
+ * list of tokens and updates the currentMaterial class with
657
+ * the attributes provided.
658
+ */
659
+ MaterialLibrary.prototype.parse = function () {
660
+ var e_1, _a;
661
+ var lines = this.data.split(/\r?\n/);
662
+ try {
663
+ for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {
664
+ var line = lines_1_1.value;
665
+ line = line.trim();
666
+ if (!line || line.startsWith("#")) {
667
+ continue;
668
+ }
669
+ var _b = __read(line.split(/\s/)), directive = _b[0], tokens = _b.slice(1);
670
+ var parseMethod = this["parse_".concat(directive)];
671
+ if (!parseMethod) {
672
+ console.warn("Don't know how to parse the directive: \"".concat(directive, "\""));
673
+ continue;
674
+ }
675
+ parseMethod.bind(this)(tokens);
676
+ }
677
+ }
678
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
679
+ finally {
680
+ try {
681
+ if (lines_1_1 && !lines_1_1.done && (_a = lines_1["return"])) _a.call(lines_1);
682
+ }
683
+ finally { if (e_1) throw e_1.error; }
684
+ }
685
+ // some cleanup. These don't need to be exposed as public data.
686
+ delete this.data;
687
+ this.currentMaterial = SENTINEL_MATERIAL;
688
+ };
689
+ return MaterialLibrary;
690
+ }());
691
+ exports.MaterialLibrary = MaterialLibrary;
692
+ function emptyTextureOptions() {
693
+ return {
694
+ colorCorrection: false,
695
+ horizontalBlending: true,
696
+ verticalBlending: true,
697
+ boostMipMapSharpness: 0,
698
+ modifyTextureMap: {
699
+ brightness: 0,
700
+ contrast: 1
701
+ },
702
+ offset: { u: 0, v: 0, w: 0 },
703
+ scale: { u: 1, v: 1, w: 1 },
704
+ turbulence: { u: 0, v: 0, w: 0 },
705
+ clamp: false,
706
+ textureResolution: null,
707
+ bumpMultiplier: 1,
708
+ imfChan: null,
709
+ filename: ""
710
+ };
711
+ }