1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | (function (global, factory) {
|
10 | typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
11 | typeof define === 'function' && define.amd ? define(factory) :
|
12 | (global = global || self, global.View3D = factory());
|
13 | }(this, (function () { 'use strict';
|
14 |
|
15 | |
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 | var extendStatics = function (d, b) {
|
32 | extendStatics = Object.setPrototypeOf || {
|
33 | __proto__: []
|
34 | } instanceof Array && function (d, b) {
|
35 | d.__proto__ = b;
|
36 | } || function (d, b) {
|
37 | for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
38 | };
|
39 |
|
40 | return extendStatics(d, b);
|
41 | };
|
42 |
|
43 | function __extends(d, b) {
|
44 | extendStatics(d, b);
|
45 |
|
46 | function __() {
|
47 | this.constructor = d;
|
48 | }
|
49 |
|
50 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
51 | }
|
52 | var __assign = function () {
|
53 | __assign = Object.assign || function __assign(t) {
|
54 | for (var s, i = 1, n = arguments.length; i < n; i++) {
|
55 | s = arguments[i];
|
56 |
|
57 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
58 | }
|
59 |
|
60 | return t;
|
61 | };
|
62 |
|
63 | return __assign.apply(this, arguments);
|
64 | };
|
65 | function __awaiter(thisArg, _arguments, P, generator) {
|
66 | function adopt(value) {
|
67 | return value instanceof P ? value : new P(function (resolve) {
|
68 | resolve(value);
|
69 | });
|
70 | }
|
71 |
|
72 | return new (P || (P = Promise))(function (resolve, reject) {
|
73 | function fulfilled(value) {
|
74 | try {
|
75 | step(generator.next(value));
|
76 | } catch (e) {
|
77 | reject(e);
|
78 | }
|
79 | }
|
80 |
|
81 | function rejected(value) {
|
82 | try {
|
83 | step(generator["throw"](value));
|
84 | } catch (e) {
|
85 | reject(e);
|
86 | }
|
87 | }
|
88 |
|
89 | function step(result) {
|
90 | result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
91 | }
|
92 |
|
93 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
94 | });
|
95 | }
|
96 | function __generator(thisArg, body) {
|
97 | var _ = {
|
98 | label: 0,
|
99 | sent: function () {
|
100 | if (t[0] & 1) throw t[1];
|
101 | return t[1];
|
102 | },
|
103 | trys: [],
|
104 | ops: []
|
105 | },
|
106 | f,
|
107 | y,
|
108 | t,
|
109 | g;
|
110 | return g = {
|
111 | next: verb(0),
|
112 | "throw": verb(1),
|
113 | "return": verb(2)
|
114 | }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
|
115 | return this;
|
116 | }), g;
|
117 |
|
118 | function verb(n) {
|
119 | return function (v) {
|
120 | return step([n, v]);
|
121 | };
|
122 | }
|
123 |
|
124 | function step(op) {
|
125 | if (f) throw new TypeError("Generator is already executing.");
|
126 |
|
127 | while (_) try {
|
128 | if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
129 | if (y = 0, t) op = [op[0] & 2, t.value];
|
130 |
|
131 | switch (op[0]) {
|
132 | case 0:
|
133 | case 1:
|
134 | t = op;
|
135 | break;
|
136 |
|
137 | case 4:
|
138 | _.label++;
|
139 | return {
|
140 | value: op[1],
|
141 | done: false
|
142 | };
|
143 |
|
144 | case 5:
|
145 | _.label++;
|
146 | y = op[1];
|
147 | op = [0];
|
148 | continue;
|
149 |
|
150 | case 7:
|
151 | op = _.ops.pop();
|
152 |
|
153 | _.trys.pop();
|
154 |
|
155 | continue;
|
156 |
|
157 | default:
|
158 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
159 | _ = 0;
|
160 | continue;
|
161 | }
|
162 |
|
163 | if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
164 | _.label = op[1];
|
165 | break;
|
166 | }
|
167 |
|
168 | if (op[0] === 6 && _.label < t[1]) {
|
169 | _.label = t[1];
|
170 | t = op;
|
171 | break;
|
172 | }
|
173 |
|
174 | if (t && _.label < t[2]) {
|
175 | _.label = t[2];
|
176 |
|
177 | _.ops.push(op);
|
178 |
|
179 | break;
|
180 | }
|
181 |
|
182 | if (t[2]) _.ops.pop();
|
183 |
|
184 | _.trys.pop();
|
185 |
|
186 | continue;
|
187 | }
|
188 |
|
189 | op = body.call(thisArg, _);
|
190 | } catch (e) {
|
191 | op = [6, e];
|
192 | y = 0;
|
193 | } finally {
|
194 | f = t = 0;
|
195 | }
|
196 |
|
197 | if (op[0] & 5) throw op[1];
|
198 | return {
|
199 | value: op[0] ? op[1] : void 0,
|
200 | done: true
|
201 | };
|
202 | }
|
203 | }
|
204 | function __values(o) {
|
205 | var s = typeof Symbol === "function" && Symbol.iterator,
|
206 | m = s && o[s],
|
207 | i = 0;
|
208 | if (m) return m.call(o);
|
209 | if (o && typeof o.length === "number") return {
|
210 | next: function () {
|
211 | if (o && i >= o.length) o = void 0;
|
212 | return {
|
213 | value: o && o[i++],
|
214 | done: !o
|
215 | };
|
216 | }
|
217 | };
|
218 | throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
219 | }
|
220 | function __read(o, n) {
|
221 | var m = typeof Symbol === "function" && o[Symbol.iterator];
|
222 | if (!m) return o;
|
223 | var i = m.call(o),
|
224 | r,
|
225 | ar = [],
|
226 | e;
|
227 |
|
228 | try {
|
229 | while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
230 | } catch (error) {
|
231 | e = {
|
232 | error: error
|
233 | };
|
234 | } finally {
|
235 | try {
|
236 | if (r && !r.done && (m = i["return"])) m.call(i);
|
237 | } finally {
|
238 | if (e) throw e.error;
|
239 | }
|
240 | }
|
241 |
|
242 | return ar;
|
243 | }
|
244 | function __spread() {
|
245 | for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
|
246 |
|
247 | return ar;
|
248 | }
|
249 |
|
250 | |
251 |
|
252 |
|
253 |
|
254 |
|
255 | var EventEmitter =
|
256 |
|
257 | function () {
|
258 | function EventEmitter() {
|
259 | this._listenerMap = {};
|
260 | }
|
261 |
|
262 | var __proto = EventEmitter.prototype;
|
263 |
|
264 | __proto.on = function (eventName, callback) {
|
265 | var listenerMap = this._listenerMap;
|
266 | var listeners = listenerMap[eventName];
|
267 |
|
268 | if (listeners && listeners.indexOf(callback) < 0) {
|
269 | listeners.push(callback);
|
270 | } else {
|
271 | listenerMap[eventName] = [callback];
|
272 | }
|
273 |
|
274 | return this;
|
275 | };
|
276 |
|
277 | __proto.once = function (eventName, callback) {
|
278 |
|
279 | var listenerMap = this._listenerMap;
|
280 | var listeners = listenerMap[eventName];
|
281 |
|
282 | if (listeners && listeners.indexOf(callback) < 0) {
|
283 | listeners.push(callback);
|
284 | } else {
|
285 | listenerMap[eventName] = [callback];
|
286 | }
|
287 |
|
288 | return this;
|
289 | };
|
290 |
|
291 | __proto.off = function (eventName, callback) {
|
292 | var listenerMap = this._listenerMap;
|
293 |
|
294 | if (!eventName) {
|
295 | this._listenerMap = {};
|
296 | return this;
|
297 | }
|
298 |
|
299 | if (!callback) {
|
300 | delete listenerMap[eventName];
|
301 | return this;
|
302 | }
|
303 |
|
304 | var listeners = listenerMap[eventName];
|
305 |
|
306 | if (listeners) {
|
307 | var callbackIdx = listeners.indexOf(callback);
|
308 |
|
309 | if (callbackIdx >= 0) {
|
310 | listeners.splice(callbackIdx, 1);
|
311 | }
|
312 | }
|
313 |
|
314 | return this;
|
315 | };
|
316 |
|
317 | __proto.emit = function (eventName) {
|
318 | var event = [];
|
319 |
|
320 | for (var _i = 1; _i < arguments.length; _i++) {
|
321 | event[_i - 1] = arguments[_i];
|
322 | }
|
323 |
|
324 | var listeners = this._listenerMap[eventName];
|
325 |
|
326 | if (listeners) {
|
327 | listeners.forEach(function (callback) {
|
328 | callback.apply(void 0, __spread(event));
|
329 | });
|
330 | }
|
331 |
|
332 | return this;
|
333 | };
|
334 |
|
335 | return EventEmitter;
|
336 | }();
|
337 |
|
338 | function _extends() {
|
339 | _extends = Object.assign || function (target) {
|
340 | for (var i = 1; i < arguments.length; i++) {
|
341 | var source = arguments[i];
|
342 |
|
343 | for (var key in source) {
|
344 | if (Object.prototype.hasOwnProperty.call(source, key)) {
|
345 | target[key] = source[key];
|
346 | }
|
347 | }
|
348 | }
|
349 |
|
350 | return target;
|
351 | };
|
352 |
|
353 | return _extends.apply(this, arguments);
|
354 | }
|
355 |
|
356 | function _inheritsLoose(subClass, superClass) {
|
357 | subClass.prototype = Object.create(superClass.prototype);
|
358 | subClass.prototype.constructor = subClass;
|
359 | subClass.__proto__ = superClass;
|
360 | }
|
361 |
|
362 | function _assertThisInitialized(self) {
|
363 | if (self === void 0) {
|
364 | throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
365 | }
|
366 |
|
367 | return self;
|
368 | }
|
369 |
|
370 | var _ENCODINGS;
|
371 | if(Number.EPSILON===undefined){Number.EPSILON=Math.pow(2,-52);}if(Number.isInteger===undefined){
|
372 |
|
373 | Number.isInteger=function(value){return typeof value==='number'&&isFinite(value)&&Math.floor(value)===value;};}
|
374 | if(Math.sign===undefined){
|
375 | Math.sign=function(x){return x<0?-1:x>0?1:+x;};}if('name'in Function.prototype===false){
|
376 |
|
377 | Object.defineProperty(Function.prototype,'name',{get:function get(){return this.toString().match(/^\s*function\s*([^\(\s]*)/)[1];}});}if(Object.assign===undefined){
|
378 |
|
379 | Object.assign=function(target){if(target===undefined||target===null){throw new TypeError('Cannot convert undefined or null to object');}var output=Object(target);for(var index=1;index<arguments.length;index++){var source=arguments[index];if(source!==undefined&&source!==null){for(var nextKey in source){if(Object.prototype.hasOwnProperty.call(source,nextKey)){output[nextKey]=source[nextKey];}}}}return output;};}var REVISION='116';var MOUSE={LEFT:0,MIDDLE:1,RIGHT:2,ROTATE:0,DOLLY:1,PAN:2};var TOUCH={ROTATE:0,PAN:1,DOLLY_PAN:2,DOLLY_ROTATE:3};var CullFaceNone=0;var CullFaceBack=1;var CullFaceFront=2;var CullFaceFrontBack=3;var FrontFaceDirectionCW=0;var FrontFaceDirectionCCW=1;var BasicShadowMap=0;var PCFShadowMap=1;var PCFSoftShadowMap=2;var VSMShadowMap=3;var FrontSide=0;var BackSide=1;var DoubleSide=2;var FlatShading=1;var SmoothShading=2;var NoBlending=0;var NormalBlending=1;var AdditiveBlending=2;var SubtractiveBlending=3;var MultiplyBlending=4;var CustomBlending=5;var AddEquation=100;var SubtractEquation=101;var ReverseSubtractEquation=102;var MinEquation=103;var MaxEquation=104;var ZeroFactor=200;var OneFactor=201;var SrcColorFactor=202;var OneMinusSrcColorFactor=203;var SrcAlphaFactor=204;var OneMinusSrcAlphaFactor=205;var DstAlphaFactor=206;var OneMinusDstAlphaFactor=207;var DstColorFactor=208;var OneMinusDstColorFactor=209;var SrcAlphaSaturateFactor=210;var NeverDepth=0;var AlwaysDepth=1;var LessDepth=2;var LessEqualDepth=3;var EqualDepth=4;var GreaterEqualDepth=5;var GreaterDepth=6;var NotEqualDepth=7;var MultiplyOperation=0;var MixOperation=1;var AddOperation=2;var NoToneMapping=0;var LinearToneMapping=1;var ReinhardToneMapping=2;var Uncharted2ToneMapping=3;var CineonToneMapping=4;var ACESFilmicToneMapping=5;var UVMapping=300;var CubeReflectionMapping=301;var CubeRefractionMapping=302;var EquirectangularReflectionMapping=303;var EquirectangularRefractionMapping=304;var SphericalReflectionMapping=305;var CubeUVReflectionMapping=306;var CubeUVRefractionMapping=307;var RepeatWrapping=1000;var ClampToEdgeWrapping=1001;var MirroredRepeatWrapping=1002;var NearestFilter=1003;var NearestMipmapNearestFilter=1004;var NearestMipMapNearestFilter=1004;var NearestMipmapLinearFilter=1005;var NearestMipMapLinearFilter=1005;var LinearFilter=1006;var LinearMipmapNearestFilter=1007;var LinearMipMapNearestFilter=1007;var LinearMipmapLinearFilter=1008;var LinearMipMapLinearFilter=1008;var UnsignedByteType=1009;var ByteType=1010;var ShortType=1011;var UnsignedShortType=1012;var IntType=1013;var UnsignedIntType=1014;var FloatType=1015;var HalfFloatType=1016;var UnsignedShort4444Type=1017;var UnsignedShort5551Type=1018;var UnsignedShort565Type=1019;var UnsignedInt248Type=1020;var AlphaFormat=1021;var RGBFormat=1022;var RGBAFormat=1023;var LuminanceFormat=1024;var LuminanceAlphaFormat=1025;var RGBEFormat=RGBAFormat;var DepthFormat=1026;var DepthStencilFormat=1027;var RedFormat=1028;var RedIntegerFormat=1029;var RGFormat=1030;var RGIntegerFormat=1031;var RGBIntegerFormat=1032;var RGBAIntegerFormat=1033;var RGB_S3TC_DXT1_Format=33776;var RGBA_S3TC_DXT1_Format=33777;var RGBA_S3TC_DXT3_Format=33778;var RGBA_S3TC_DXT5_Format=33779;var RGB_PVRTC_4BPPV1_Format=35840;var RGB_PVRTC_2BPPV1_Format=35841;var RGBA_PVRTC_4BPPV1_Format=35842;var RGBA_PVRTC_2BPPV1_Format=35843;var RGB_ETC1_Format=36196;var RGB_ETC2_Format=37492;var RGBA_ETC2_EAC_Format=37496;var RGBA_ASTC_4x4_Format=37808;var RGBA_ASTC_5x4_Format=37809;var RGBA_ASTC_5x5_Format=37810;var RGBA_ASTC_6x5_Format=37811;var RGBA_ASTC_6x6_Format=37812;var RGBA_ASTC_8x5_Format=37813;var RGBA_ASTC_8x6_Format=37814;var RGBA_ASTC_8x8_Format=37815;var RGBA_ASTC_10x5_Format=37816;var RGBA_ASTC_10x6_Format=37817;var RGBA_ASTC_10x8_Format=37818;var RGBA_ASTC_10x10_Format=37819;var RGBA_ASTC_12x10_Format=37820;var RGBA_ASTC_12x12_Format=37821;var RGBA_BPTC_Format=36492;var SRGB8_ALPHA8_ASTC_4x4_Format=37840;var SRGB8_ALPHA8_ASTC_5x4_Format=37841;var SRGB8_ALPHA8_ASTC_5x5_Format=37842;var SRGB8_ALPHA8_ASTC_6x5_Format=37843;var SRGB8_ALPHA8_ASTC_6x6_Format=37844;var SRGB8_ALPHA8_ASTC_8x5_Format=37845;var SRGB8_ALPHA8_ASTC_8x6_Format=37846;var SRGB8_ALPHA8_ASTC_8x8_Format=37847;var SRGB8_ALPHA8_ASTC_10x5_Format=37848;var SRGB8_ALPHA8_ASTC_10x6_Format=37849;var SRGB8_ALPHA8_ASTC_10x8_Format=37850;var SRGB8_ALPHA8_ASTC_10x10_Format=37851;var SRGB8_ALPHA8_ASTC_12x10_Format=37852;var SRGB8_ALPHA8_ASTC_12x12_Format=37853;var LoopOnce=2200;var LoopRepeat=2201;var LoopPingPong=2202;var InterpolateDiscrete=2300;var InterpolateLinear=2301;var InterpolateSmooth=2302;var ZeroCurvatureEnding=2400;var ZeroSlopeEnding=2401;var WrapAroundEnding=2402;var NormalAnimationBlendMode=2500;var AdditiveAnimationBlendMode=2501;var TrianglesDrawMode=0;var TriangleStripDrawMode=1;var TriangleFanDrawMode=2;var LinearEncoding=3000;var sRGBEncoding=3001;var GammaEncoding=3007;var RGBEEncoding=3002;var LogLuvEncoding=3003;var RGBM7Encoding=3004;var RGBM16Encoding=3005;var RGBDEncoding=3006;var BasicDepthPacking=3200;var RGBADepthPacking=3201;var TangentSpaceNormalMap=0;var ObjectSpaceNormalMap=1;var ZeroStencilOp=0;var KeepStencilOp=7680;var ReplaceStencilOp=7681;var IncrementStencilOp=7682;var DecrementStencilOp=7683;var IncrementWrapStencilOp=34055;var DecrementWrapStencilOp=34056;var InvertStencilOp=5386;var NeverStencilFunc=512;var LessStencilFunc=513;var EqualStencilFunc=514;var LessEqualStencilFunc=515;var GreaterStencilFunc=516;var NotEqualStencilFunc=517;var GreaterEqualStencilFunc=518;var AlwaysStencilFunc=519;var StaticDrawUsage=35044;var DynamicDrawUsage=35048;var StreamDrawUsage=35040;var StaticReadUsage=35045;var DynamicReadUsage=35049;var StreamReadUsage=35041;var StaticCopyUsage=35046;var DynamicCopyUsage=35050;var StreamCopyUsage=35042; |
380 |
|
381 | function EventDispatcher(){}_extends(EventDispatcher.prototype,{addEventListener:function addEventListener(type,listener){if(this._listeners===undefined)this._listeners={};var listeners=this._listeners;if(listeners[type]===undefined){listeners[type]=[];}if(listeners[type].indexOf(listener)===-1){listeners[type].push(listener);}},hasEventListener:function hasEventListener(type,listener){if(this._listeners===undefined)return false;var listeners=this._listeners;return listeners[type]!==undefined&&listeners[type].indexOf(listener)!==-1;},removeEventListener:function removeEventListener(type,listener){if(this._listeners===undefined)return;var listeners=this._listeners;var listenerArray=listeners[type];if(listenerArray!==undefined){var index=listenerArray.indexOf(listener);if(index!==-1){listenerArray.splice(index,1);}}},dispatchEvent:function dispatchEvent(event){if(this._listeners===undefined)return;var listeners=this._listeners;var listenerArray=listeners[event.type];if(listenerArray!==undefined){event.target=this;
|
382 | var array=listenerArray.slice(0);for(var i=0,l=array.length;i<l;i++){array[i].call(this,event);}}}}); |
383 |
|
384 |
|
385 |
|
386 |
|
387 | var _lut=[];for(var i=0;i<256;i++){_lut[i]=(i<16?'0':'')+i.toString(16);}var MathUtils={DEG2RAD:Math.PI/180,RAD2DEG:180/Math.PI,generateUUID:function generateUUID(){
|
388 | var d0=Math.random()*0xffffffff|0;var d1=Math.random()*0xffffffff|0;var d2=Math.random()*0xffffffff|0;var d3=Math.random()*0xffffffff|0;var uuid=_lut[d0&0xff]+_lut[d0>>8&0xff]+_lut[d0>>16&0xff]+_lut[d0>>24&0xff]+'-'+_lut[d1&0xff]+_lut[d1>>8&0xff]+'-'+_lut[d1>>16&0x0f|0x40]+_lut[d1>>24&0xff]+'-'+_lut[d2&0x3f|0x80]+_lut[d2>>8&0xff]+'-'+_lut[d2>>16&0xff]+_lut[d2>>24&0xff]+_lut[d3&0xff]+_lut[d3>>8&0xff]+_lut[d3>>16&0xff]+_lut[d3>>24&0xff];
|
389 | return uuid.toUpperCase();},clamp:function clamp(value,min,max){return Math.max(min,Math.min(max,value));},
|
390 |
|
391 | euclideanModulo:function euclideanModulo(n,m){return (n%m+m)%m;},
|
392 | mapLinear:function mapLinear(x,a1,a2,b1,b2){return b1+(x-a1)*(b2-b1)/(a2-a1);},
|
393 | lerp:function lerp(x,y,t){return (1-t)*x+t*y;},
|
394 | smoothstep:function smoothstep(x,min,max){if(x<=min)return 0;if(x>=max)return 1;x=(x-min)/(max-min);return x*x*(3-2*x);},smootherstep:function smootherstep(x,min,max){if(x<=min)return 0;if(x>=max)return 1;x=(x-min)/(max-min);return x*x*x*(x*(x*6-15)+10);},
|
395 | randInt:function randInt(low,high){return low+Math.floor(Math.random()*(high-low+1));},
|
396 | randFloat:function randFloat(low,high){return low+Math.random()*(high-low);},
|
397 | randFloatSpread:function randFloatSpread(range){return range*(0.5-Math.random());},degToRad:function degToRad(degrees){return degrees*MathUtils.DEG2RAD;},radToDeg:function radToDeg(radians){return radians*MathUtils.RAD2DEG;},isPowerOfTwo:function isPowerOfTwo(value){return (value&value-1)===0&&value!==0;},ceilPowerOfTwo:function ceilPowerOfTwo(value){return Math.pow(2,Math.ceil(Math.log(value)/Math.LN2));},floorPowerOfTwo:function floorPowerOfTwo(value){return Math.pow(2,Math.floor(Math.log(value)/Math.LN2));},setQuaternionFromProperEuler:function setQuaternionFromProperEuler(q,a,b,c,order){
|
398 |
|
399 |
|
400 |
|
401 | var cos=Math.cos;var sin=Math.sin;var c2=cos(b/2);var s2=sin(b/2);var c13=cos((a+c)/2);var s13=sin((a+c)/2);var c1_3=cos((a-c)/2);var s1_3=sin((a-c)/2);var c3_1=cos((c-a)/2);var s3_1=sin((c-a)/2);switch(order){case'XYX':q.set(c2*s13,s2*c1_3,s2*s1_3,c2*c13);break;case'YZY':q.set(s2*s1_3,c2*s13,s2*c1_3,c2*c13);break;case'ZXZ':q.set(s2*c1_3,s2*s1_3,c2*s13,c2*c13);break;case'XZX':q.set(c2*s13,s2*s3_1,s2*c3_1,c2*c13);break;case'YXY':q.set(s2*c3_1,c2*s13,s2*s3_1,c2*c13);break;case'ZYZ':q.set(s2*s3_1,s2*c3_1,c2*s13,c2*c13);break;default:console.warn('THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: '+order);}}}; |
402 |
|
403 |
|
404 |
|
405 |
|
406 | function Vector2(x,y){this.x=x||0;this.y=y||0;}Object.defineProperties(Vector2.prototype,{"width":{get:function get(){return this.x;},set:function set(value){this.x=value;}},"height":{get:function get(){return this.y;},set:function set(value){this.y=value;}}});_extends(Vector2.prototype,{isVector2:true,set:function set(x,y){this.x=x;this.y=y;return this;},setScalar:function setScalar(scalar){this.x=scalar;this.y=scalar;return this;},setX:function setX(x){this.x=x;return this;},setY:function setY(y){this.y=y;return this;},setComponent:function setComponent(index,value){switch(index){case 0:this.x=value;break;case 1:this.y=value;break;default:throw new Error('index is out of range: '+index);}return this;},getComponent:function getComponent(index){switch(index){case 0:return this.x;case 1:return this.y;default:throw new Error('index is out of range: '+index);}},clone:function clone(){return new this.constructor(this.x,this.y);},copy:function copy(v){this.x=v.x;this.y=v.y;return this;},add:function add(v,w){if(w!==undefined){console.warn('THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');return this.addVectors(v,w);}this.x+=v.x;this.y+=v.y;return this;},addScalar:function addScalar(s){this.x+=s;this.y+=s;return this;},addVectors:function addVectors(a,b){this.x=a.x+b.x;this.y=a.y+b.y;return this;},addScaledVector:function addScaledVector(v,s){this.x+=v.x*s;this.y+=v.y*s;return this;},sub:function sub(v,w){if(w!==undefined){console.warn('THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');return this.subVectors(v,w);}this.x-=v.x;this.y-=v.y;return this;},subScalar:function subScalar(s){this.x-=s;this.y-=s;return this;},subVectors:function subVectors(a,b){this.x=a.x-b.x;this.y=a.y-b.y;return this;},multiply:function multiply(v){this.x*=v.x;this.y*=v.y;return this;},multiplyScalar:function multiplyScalar(scalar){this.x*=scalar;this.y*=scalar;return this;},divide:function divide(v){this.x/=v.x;this.y/=v.y;return this;},divideScalar:function divideScalar(scalar){return this.multiplyScalar(1/scalar);},applyMatrix3:function applyMatrix3(m){var x=this.x,y=this.y;var e=m.elements;this.x=e[0]*x+e[3]*y+e[6];this.y=e[1]*x+e[4]*y+e[7];return this;},min:function min(v){this.x=Math.min(this.x,v.x);this.y=Math.min(this.y,v.y);return this;},max:function max(v){this.x=Math.max(this.x,v.x);this.y=Math.max(this.y,v.y);return this;},clamp:function clamp(min,max){
|
407 | this.x=Math.max(min.x,Math.min(max.x,this.x));this.y=Math.max(min.y,Math.min(max.y,this.y));return this;},clampScalar:function clampScalar(minVal,maxVal){this.x=Math.max(minVal,Math.min(maxVal,this.x));this.y=Math.max(minVal,Math.min(maxVal,this.y));return this;},clampLength:function clampLength(min,max){var length=this.length();return this.divideScalar(length||1).multiplyScalar(Math.max(min,Math.min(max,length)));},floor:function floor(){this.x=Math.floor(this.x);this.y=Math.floor(this.y);return this;},ceil:function ceil(){this.x=Math.ceil(this.x);this.y=Math.ceil(this.y);return this;},round:function round(){this.x=Math.round(this.x);this.y=Math.round(this.y);return this;},roundToZero:function roundToZero(){this.x=this.x<0?Math.ceil(this.x):Math.floor(this.x);this.y=this.y<0?Math.ceil(this.y):Math.floor(this.y);return this;},negate:function negate(){this.x=-this.x;this.y=-this.y;return this;},dot:function dot(v){return this.x*v.x+this.y*v.y;},cross:function cross(v){return this.x*v.y-this.y*v.x;},lengthSq:function lengthSq(){return this.x*this.x+this.y*this.y;},length:function length(){return Math.sqrt(this.x*this.x+this.y*this.y);},manhattanLength:function manhattanLength(){return Math.abs(this.x)+Math.abs(this.y);},normalize:function normalize(){return this.divideScalar(this.length()||1);},angle:function angle(){
|
408 | var angle=Math.atan2(-this.y,-this.x)+Math.PI;return angle;},distanceTo:function distanceTo(v){return Math.sqrt(this.distanceToSquared(v));},distanceToSquared:function distanceToSquared(v){var dx=this.x-v.x,dy=this.y-v.y;return dx*dx+dy*dy;},manhattanDistanceTo:function manhattanDistanceTo(v){return Math.abs(this.x-v.x)+Math.abs(this.y-v.y);},setLength:function setLength(length){return this.normalize().multiplyScalar(length);},lerp:function lerp(v,alpha){this.x+=(v.x-this.x)*alpha;this.y+=(v.y-this.y)*alpha;return this;},lerpVectors:function lerpVectors(v1,v2,alpha){return this.subVectors(v2,v1).multiplyScalar(alpha).add(v1);},equals:function equals(v){return v.x===this.x&&v.y===this.y;},fromArray:function fromArray(array,offset){if(offset===undefined)offset=0;this.x=array[offset];this.y=array[offset+1];return this;},toArray:function toArray(array,offset){if(array===undefined)array=[];if(offset===undefined)offset=0;array[offset]=this.x;array[offset+1]=this.y;return array;},fromBufferAttribute:function fromBufferAttribute(attribute,index,offset){if(offset!==undefined){console.warn('THREE.Vector2: offset has been removed from .fromBufferAttribute().');}this.x=attribute.getX(index);this.y=attribute.getY(index);return this;},rotateAround:function rotateAround(center,angle){var c=Math.cos(angle),s=Math.sin(angle);var x=this.x-center.x;var y=this.y-center.y;this.x=x*c-y*s+center.x;this.y=x*s+y*c+center.y;return this;},random:function random(){this.x=Math.random();this.y=Math.random();return this;}}); |
409 |
|
410 |
|
411 |
|
412 |
|
413 | function Matrix3(){this.elements=[1,0,0,0,1,0,0,0,1];if(arguments.length>0){console.error('THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.');}}_extends(Matrix3.prototype,{isMatrix3:true,set:function set(n11,n12,n13,n21,n22,n23,n31,n32,n33){var te=this.elements;te[0]=n11;te[1]=n21;te[2]=n31;te[3]=n12;te[4]=n22;te[5]=n32;te[6]=n13;te[7]=n23;te[8]=n33;return this;},identity:function identity(){this.set(1,0,0,0,1,0,0,0,1);return this;},clone:function clone(){return new this.constructor().fromArray(this.elements);},copy:function copy(m){var te=this.elements;var me=m.elements;te[0]=me[0];te[1]=me[1];te[2]=me[2];te[3]=me[3];te[4]=me[4];te[5]=me[5];te[6]=me[6];te[7]=me[7];te[8]=me[8];return this;},extractBasis:function extractBasis(xAxis,yAxis,zAxis){xAxis.setFromMatrix3Column(this,0);yAxis.setFromMatrix3Column(this,1);zAxis.setFromMatrix3Column(this,2);return this;},setFromMatrix4:function setFromMatrix4(m){var me=m.elements;this.set(me[0],me[4],me[8],me[1],me[5],me[9],me[2],me[6],me[10]);return this;},multiply:function multiply(m){return this.multiplyMatrices(this,m);},premultiply:function premultiply(m){return this.multiplyMatrices(m,this);},multiplyMatrices:function multiplyMatrices(a,b){var ae=a.elements;var be=b.elements;var te=this.elements;var a11=ae[0],a12=ae[3],a13=ae[6];var a21=ae[1],a22=ae[4],a23=ae[7];var a31=ae[2],a32=ae[5],a33=ae[8];var b11=be[0],b12=be[3],b13=be[6];var b21=be[1],b22=be[4],b23=be[7];var b31=be[2],b32=be[5],b33=be[8];te[0]=a11*b11+a12*b21+a13*b31;te[3]=a11*b12+a12*b22+a13*b32;te[6]=a11*b13+a12*b23+a13*b33;te[1]=a21*b11+a22*b21+a23*b31;te[4]=a21*b12+a22*b22+a23*b32;te[7]=a21*b13+a22*b23+a23*b33;te[2]=a31*b11+a32*b21+a33*b31;te[5]=a31*b12+a32*b22+a33*b32;te[8]=a31*b13+a32*b23+a33*b33;return this;},multiplyScalar:function multiplyScalar(s){var te=this.elements;te[0]*=s;te[3]*=s;te[6]*=s;te[1]*=s;te[4]*=s;te[7]*=s;te[2]*=s;te[5]*=s;te[8]*=s;return this;},determinant:function determinant(){var te=this.elements;var a=te[0],b=te[1],c=te[2],d=te[3],e=te[4],f=te[5],g=te[6],h=te[7],i=te[8];return a*e*i-a*f*h-b*d*i+b*f*g+c*d*h-c*e*g;},getInverse:function getInverse(matrix,throwOnDegenerate){if(throwOnDegenerate!==undefined){console.warn("THREE.Matrix3: .getInverse() can no longer be configured to throw on degenerate.");}var me=matrix.elements,te=this.elements,n11=me[0],n21=me[1],n31=me[2],n12=me[3],n22=me[4],n32=me[5],n13=me[6],n23=me[7],n33=me[8],t11=n33*n22-n32*n23,t12=n32*n13-n33*n12,t13=n23*n12-n22*n13,det=n11*t11+n21*t12+n31*t13;if(det===0)return this.set(0,0,0,0,0,0,0,0,0);var detInv=1/det;te[0]=t11*detInv;te[1]=(n31*n23-n33*n21)*detInv;te[2]=(n32*n21-n31*n22)*detInv;te[3]=t12*detInv;te[4]=(n33*n11-n31*n13)*detInv;te[5]=(n31*n12-n32*n11)*detInv;te[6]=t13*detInv;te[7]=(n21*n13-n23*n11)*detInv;te[8]=(n22*n11-n21*n12)*detInv;return this;},transpose:function transpose(){var tmp,m=this.elements;tmp=m[1];m[1]=m[3];m[3]=tmp;tmp=m[2];m[2]=m[6];m[6]=tmp;tmp=m[5];m[5]=m[7];m[7]=tmp;return this;},getNormalMatrix:function getNormalMatrix(matrix4){return this.setFromMatrix4(matrix4).getInverse(this).transpose();},transposeIntoArray:function transposeIntoArray(r){var m=this.elements;r[0]=m[0];r[1]=m[3];r[2]=m[6];r[3]=m[1];r[4]=m[4];r[5]=m[7];r[6]=m[2];r[7]=m[5];r[8]=m[8];return this;},setUvTransform:function setUvTransform(tx,ty,sx,sy,rotation,cx,cy){var c=Math.cos(rotation);var s=Math.sin(rotation);this.set(sx*c,sx*s,-sx*(c*cx+s*cy)+cx+tx,-sy*s,sy*c,-sy*(-s*cx+c*cy)+cy+ty,0,0,1);},scale:function scale(sx,sy){var te=this.elements;te[0]*=sx;te[3]*=sx;te[6]*=sx;te[1]*=sy;te[4]*=sy;te[7]*=sy;return this;},rotate:function rotate(theta){var c=Math.cos(theta);var s=Math.sin(theta);var te=this.elements;var a11=te[0],a12=te[3],a13=te[6];var a21=te[1],a22=te[4],a23=te[7];te[0]=c*a11+s*a21;te[3]=c*a12+s*a22;te[6]=c*a13+s*a23;te[1]=-s*a11+c*a21;te[4]=-s*a12+c*a22;te[7]=-s*a13+c*a23;return this;},translate:function translate(tx,ty){var te=this.elements;te[0]+=tx*te[2];te[3]+=tx*te[5];te[6]+=tx*te[8];te[1]+=ty*te[2];te[4]+=ty*te[5];te[7]+=ty*te[8];return this;},equals:function equals(matrix){var te=this.elements;var me=matrix.elements;for(var i=0;i<9;i++){if(te[i]!==me[i])return false;}return true;},fromArray:function fromArray(array,offset){if(offset===undefined)offset=0;for(var i=0;i<9;i++){this.elements[i]=array[i+offset];}return this;},toArray:function toArray(array,offset){if(array===undefined)array=[];if(offset===undefined)offset=0;var te=this.elements;array[offset]=te[0];array[offset+1]=te[1];array[offset+2]=te[2];array[offset+3]=te[3];array[offset+4]=te[4];array[offset+5]=te[5];array[offset+6]=te[6];array[offset+7]=te[7];array[offset+8]=te[8];return array;}}); |
414 |
|
415 |
|
416 |
|
417 | var _canvas;var ImageUtils={getDataURL:function getDataURL(image){var canvas;if(typeof HTMLCanvasElement=='undefined'){return image.src;}else if(image instanceof HTMLCanvasElement){canvas=image;}else {if(_canvas===undefined)_canvas=document.createElementNS('http://www.w3.org/1999/xhtml','canvas');_canvas.width=image.width;_canvas.height=image.height;var context=_canvas.getContext('2d');if(image instanceof ImageData){context.putImageData(image,0,0);}else {context.drawImage(image,0,0,image.width,image.height);}canvas=_canvas;}if(canvas.width>2048||canvas.height>2048){return canvas.toDataURL('image/jpeg',0.6);}else {return canvas.toDataURL('image/png');}}}; |
418 |
|
419 |
|
420 |
|
421 | var textureId=0;function Texture(image,mapping,wrapS,wrapT,magFilter,minFilter,format,type,anisotropy,encoding){Object.defineProperty(this,'id',{value:textureId++});this.uuid=MathUtils.generateUUID();this.name='';this.image=image!==undefined?image:Texture.DEFAULT_IMAGE;this.mipmaps=[];this.mapping=mapping!==undefined?mapping:Texture.DEFAULT_MAPPING;this.wrapS=wrapS!==undefined?wrapS:ClampToEdgeWrapping;this.wrapT=wrapT!==undefined?wrapT:ClampToEdgeWrapping;this.magFilter=magFilter!==undefined?magFilter:LinearFilter;this.minFilter=minFilter!==undefined?minFilter:LinearMipmapLinearFilter;this.anisotropy=anisotropy!==undefined?anisotropy:1;this.format=format!==undefined?format:RGBAFormat;this.internalFormat=null;this.type=type!==undefined?type:UnsignedByteType;this.offset=new Vector2(0,0);this.repeat=new Vector2(1,1);this.center=new Vector2(0,0);this.rotation=0;this.matrixAutoUpdate=true;this.matrix=new Matrix3();this.generateMipmaps=true;this.premultiplyAlpha=false;this.flipY=true;this.unpackAlignment=4;
|
422 |
|
423 |
|
424 |
|
425 |
|
426 | this.encoding=encoding!==undefined?encoding:LinearEncoding;this.version=0;this.onUpdate=null;}Texture.DEFAULT_IMAGE=undefined;Texture.DEFAULT_MAPPING=UVMapping;Texture.prototype=_extends(Object.create(EventDispatcher.prototype),{constructor:Texture,isTexture:true,updateMatrix:function updateMatrix(){this.matrix.setUvTransform(this.offset.x,this.offset.y,this.repeat.x,this.repeat.y,this.rotation,this.center.x,this.center.y);},clone:function clone(){return new this.constructor().copy(this);},copy:function copy(source){this.name=source.name;this.image=source.image;this.mipmaps=source.mipmaps.slice(0);this.mapping=source.mapping;this.wrapS=source.wrapS;this.wrapT=source.wrapT;this.magFilter=source.magFilter;this.minFilter=source.minFilter;this.anisotropy=source.anisotropy;this.format=source.format;this.internalFormat=source.internalFormat;this.type=source.type;this.offset.copy(source.offset);this.repeat.copy(source.repeat);this.center.copy(source.center);this.rotation=source.rotation;this.matrixAutoUpdate=source.matrixAutoUpdate;this.matrix.copy(source.matrix);this.generateMipmaps=source.generateMipmaps;this.premultiplyAlpha=source.premultiplyAlpha;this.flipY=source.flipY;this.unpackAlignment=source.unpackAlignment;this.encoding=source.encoding;return this;},toJSON:function toJSON(meta){var isRootObject=meta===undefined||typeof meta==='string';if(!isRootObject&&meta.textures[this.uuid]!==undefined){return meta.textures[this.uuid];}var output={metadata:{version:4.5,type:'Texture',generator:'Texture.toJSON'},uuid:this.uuid,name:this.name,mapping:this.mapping,repeat:[this.repeat.x,this.repeat.y],offset:[this.offset.x,this.offset.y],center:[this.center.x,this.center.y],rotation:this.rotation,wrap:[this.wrapS,this.wrapT],format:this.format,type:this.type,encoding:this.encoding,minFilter:this.minFilter,magFilter:this.magFilter,anisotropy:this.anisotropy,flipY:this.flipY,premultiplyAlpha:this.premultiplyAlpha,unpackAlignment:this.unpackAlignment};if(this.image!==undefined){
|
427 | var image=this.image;if(image.uuid===undefined){image.uuid=MathUtils.generateUUID();
|
428 | }if(!isRootObject&&meta.images[image.uuid]===undefined){var url;if(Array.isArray(image)){
|
429 | url=[];for(var i=0,l=image.length;i<l;i++){url.push(ImageUtils.getDataURL(image[i]));}}else {
|
430 | url=ImageUtils.getDataURL(image);}meta.images[image.uuid]={uuid:image.uuid,url:url};}output.image=image.uuid;}if(!isRootObject){meta.textures[this.uuid]=output;}return output;},dispose:function dispose(){this.dispatchEvent({type:'dispose'});},transformUv:function transformUv(uv){if(this.mapping!==UVMapping)return uv;uv.applyMatrix3(this.matrix);if(uv.x<0||uv.x>1){switch(this.wrapS){case RepeatWrapping:uv.x=uv.x-Math.floor(uv.x);break;case ClampToEdgeWrapping:uv.x=uv.x<0?0:1;break;case MirroredRepeatWrapping:if(Math.abs(Math.floor(uv.x)%2)===1){uv.x=Math.ceil(uv.x)-uv.x;}else {uv.x=uv.x-Math.floor(uv.x);}break;}}if(uv.y<0||uv.y>1){switch(this.wrapT){case RepeatWrapping:uv.y=uv.y-Math.floor(uv.y);break;case ClampToEdgeWrapping:uv.y=uv.y<0?0:1;break;case MirroredRepeatWrapping:if(Math.abs(Math.floor(uv.y)%2)===1){uv.y=Math.ceil(uv.y)-uv.y;}else {uv.y=uv.y-Math.floor(uv.y);}break;}}if(this.flipY){uv.y=1-uv.y;}return uv;}});Object.defineProperty(Texture.prototype,"needsUpdate",{set:function set(value){if(value===true)this.version++;}}); |
431 |
|
432 |
|
433 |
|
434 |
|
435 |
|
436 | function Vector4(x,y,z,w){this.x=x||0;this.y=y||0;this.z=z||0;this.w=w!==undefined?w:1;}Object.defineProperties(Vector4.prototype,{"width":{get:function get(){return this.z;},set:function set(value){this.z=value;}},"height":{get:function get(){return this.w;},set:function set(value){this.w=value;}}});_extends(Vector4.prototype,{isVector4:true,set:function set(x,y,z,w){this.x=x;this.y=y;this.z=z;this.w=w;return this;},setScalar:function setScalar(scalar){this.x=scalar;this.y=scalar;this.z=scalar;this.w=scalar;return this;},setX:function setX(x){this.x=x;return this;},setY:function setY(y){this.y=y;return this;},setZ:function setZ(z){this.z=z;return this;},setW:function setW(w){this.w=w;return this;},setComponent:function setComponent(index,value){switch(index){case 0:this.x=value;break;case 1:this.y=value;break;case 2:this.z=value;break;case 3:this.w=value;break;default:throw new Error('index is out of range: '+index);}return this;},getComponent:function getComponent(index){switch(index){case 0:return this.x;case 1:return this.y;case 2:return this.z;case 3:return this.w;default:throw new Error('index is out of range: '+index);}},clone:function clone(){return new this.constructor(this.x,this.y,this.z,this.w);},copy:function copy(v){this.x=v.x;this.y=v.y;this.z=v.z;this.w=v.w!==undefined?v.w:1;return this;},add:function add(v,w){if(w!==undefined){console.warn('THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');return this.addVectors(v,w);}this.x+=v.x;this.y+=v.y;this.z+=v.z;this.w+=v.w;return this;},addScalar:function addScalar(s){this.x+=s;this.y+=s;this.z+=s;this.w+=s;return this;},addVectors:function addVectors(a,b){this.x=a.x+b.x;this.y=a.y+b.y;this.z=a.z+b.z;this.w=a.w+b.w;return this;},addScaledVector:function addScaledVector(v,s){this.x+=v.x*s;this.y+=v.y*s;this.z+=v.z*s;this.w+=v.w*s;return this;},sub:function sub(v,w){if(w!==undefined){console.warn('THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');return this.subVectors(v,w);}this.x-=v.x;this.y-=v.y;this.z-=v.z;this.w-=v.w;return this;},subScalar:function subScalar(s){this.x-=s;this.y-=s;this.z-=s;this.w-=s;return this;},subVectors:function subVectors(a,b){this.x=a.x-b.x;this.y=a.y-b.y;this.z=a.z-b.z;this.w=a.w-b.w;return this;},multiplyScalar:function multiplyScalar(scalar){this.x*=scalar;this.y*=scalar;this.z*=scalar;this.w*=scalar;return this;},applyMatrix4:function applyMatrix4(m){var x=this.x,y=this.y,z=this.z,w=this.w;var e=m.elements;this.x=e[0]*x+e[4]*y+e[8]*z+e[12]*w;this.y=e[1]*x+e[5]*y+e[9]*z+e[13]*w;this.z=e[2]*x+e[6]*y+e[10]*z+e[14]*w;this.w=e[3]*x+e[7]*y+e[11]*z+e[15]*w;return this;},divideScalar:function divideScalar(scalar){return this.multiplyScalar(1/scalar);},setAxisAngleFromQuaternion:function setAxisAngleFromQuaternion(q){
|
437 |
|
438 | this.w=2*Math.acos(q.w);var s=Math.sqrt(1-q.w*q.w);if(s<0.0001){this.x=1;this.y=0;this.z=0;}else {this.x=q.x/s;this.y=q.y/s;this.z=q.z/s;}return this;},setAxisAngleFromRotationMatrix:function setAxisAngleFromRotationMatrix(m){
|
439 |
|
440 | var angle,x,y,z,
|
441 | epsilon=0.01,
|
442 | epsilon2=0.1,
|
443 | te=m.elements,m11=te[0],m12=te[4],m13=te[8],m21=te[1],m22=te[5],m23=te[9],m31=te[2],m32=te[6],m33=te[10];if(Math.abs(m12-m21)<epsilon&&Math.abs(m13-m31)<epsilon&&Math.abs(m23-m32)<epsilon){
|
444 |
|
445 |
|
446 | if(Math.abs(m12+m21)<epsilon2&&Math.abs(m13+m31)<epsilon2&&Math.abs(m23+m32)<epsilon2&&Math.abs(m11+m22+m33-3)<epsilon2){
|
447 | this.set(1,0,0,0);return this;
|
448 | }
|
449 | angle=Math.PI;var xx=(m11+1)/2;var yy=(m22+1)/2;var zz=(m33+1)/2;var xy=(m12+m21)/4;var xz=(m13+m31)/4;var yz=(m23+m32)/4;if(xx>yy&&xx>zz){
|
450 | if(xx<epsilon){x=0;y=0.707106781;z=0.707106781;}else {x=Math.sqrt(xx);y=xy/x;z=xz/x;}}else if(yy>zz){
|
451 | if(yy<epsilon){x=0.707106781;y=0;z=0.707106781;}else {y=Math.sqrt(yy);x=xy/y;z=yz/y;}}else {
|
452 | if(zz<epsilon){x=0.707106781;y=0.707106781;z=0;}else {z=Math.sqrt(zz);x=xz/z;y=yz/z;}}this.set(x,y,z,angle);return this;
|
453 | }
|
454 | var s=Math.sqrt((m32-m23)*(m32-m23)+(m13-m31)*(m13-m31)+(m21-m12)*(m21-m12));
|
455 | if(Math.abs(s)<0.001)s=1;
|
456 |
|
457 | this.x=(m32-m23)/s;this.y=(m13-m31)/s;this.z=(m21-m12)/s;this.w=Math.acos((m11+m22+m33-1)/2);return this;},min:function min(v){this.x=Math.min(this.x,v.x);this.y=Math.min(this.y,v.y);this.z=Math.min(this.z,v.z);this.w=Math.min(this.w,v.w);return this;},max:function max(v){this.x=Math.max(this.x,v.x);this.y=Math.max(this.y,v.y);this.z=Math.max(this.z,v.z);this.w=Math.max(this.w,v.w);return this;},clamp:function clamp(min,max){
|
458 | this.x=Math.max(min.x,Math.min(max.x,this.x));this.y=Math.max(min.y,Math.min(max.y,this.y));this.z=Math.max(min.z,Math.min(max.z,this.z));this.w=Math.max(min.w,Math.min(max.w,this.w));return this;},clampScalar:function clampScalar(minVal,maxVal){this.x=Math.max(minVal,Math.min(maxVal,this.x));this.y=Math.max(minVal,Math.min(maxVal,this.y));this.z=Math.max(minVal,Math.min(maxVal,this.z));this.w=Math.max(minVal,Math.min(maxVal,this.w));return this;},clampLength:function clampLength(min,max){var length=this.length();return this.divideScalar(length||1).multiplyScalar(Math.max(min,Math.min(max,length)));},floor:function floor(){this.x=Math.floor(this.x);this.y=Math.floor(this.y);this.z=Math.floor(this.z);this.w=Math.floor(this.w);return this;},ceil:function ceil(){this.x=Math.ceil(this.x);this.y=Math.ceil(this.y);this.z=Math.ceil(this.z);this.w=Math.ceil(this.w);return this;},round:function round(){this.x=Math.round(this.x);this.y=Math.round(this.y);this.z=Math.round(this.z);this.w=Math.round(this.w);return this;},roundToZero:function roundToZero(){this.x=this.x<0?Math.ceil(this.x):Math.floor(this.x);this.y=this.y<0?Math.ceil(this.y):Math.floor(this.y);this.z=this.z<0?Math.ceil(this.z):Math.floor(this.z);this.w=this.w<0?Math.ceil(this.w):Math.floor(this.w);return this;},negate:function negate(){this.x=-this.x;this.y=-this.y;this.z=-this.z;this.w=-this.w;return this;},dot:function dot(v){return this.x*v.x+this.y*v.y+this.z*v.z+this.w*v.w;},lengthSq:function lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w;},length:function length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w);},manhattanLength:function manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)+Math.abs(this.w);},normalize:function normalize(){return this.divideScalar(this.length()||1);},setLength:function setLength(length){return this.normalize().multiplyScalar(length);},lerp:function lerp(v,alpha){this.x+=(v.x-this.x)*alpha;this.y+=(v.y-this.y)*alpha;this.z+=(v.z-this.z)*alpha;this.w+=(v.w-this.w)*alpha;return this;},lerpVectors:function lerpVectors(v1,v2,alpha){return this.subVectors(v2,v1).multiplyScalar(alpha).add(v1);},equals:function equals(v){return v.x===this.x&&v.y===this.y&&v.z===this.z&&v.w===this.w;},fromArray:function fromArray(array,offset){if(offset===undefined)offset=0;this.x=array[offset];this.y=array[offset+1];this.z=array[offset+2];this.w=array[offset+3];return this;},toArray:function toArray(array,offset){if(array===undefined)array=[];if(offset===undefined)offset=0;array[offset]=this.x;array[offset+1]=this.y;array[offset+2]=this.z;array[offset+3]=this.w;return array;},fromBufferAttribute:function fromBufferAttribute(attribute,index,offset){if(offset!==undefined){console.warn('THREE.Vector4: offset has been removed from .fromBufferAttribute().');}this.x=attribute.getX(index);this.y=attribute.getY(index);this.z=attribute.getZ(index);this.w=attribute.getW(index);return this;},random:function random(){this.x=Math.random();this.y=Math.random();this.z=Math.random();this.w=Math.random();return this;}}); |
459 |
|
460 |
|
461 |
|
462 | |
463 |
|
464 |
|
465 |
|
466 | function WebGLRenderTarget(width,height,options){this.width=width;this.height=height;this.scissor=new Vector4(0,0,width,height);this.scissorTest=false;this.viewport=new Vector4(0,0,width,height);options=options||{};this.texture=new Texture(undefined,options.mapping,options.wrapS,options.wrapT,options.magFilter,options.minFilter,options.format,options.type,options.anisotropy,options.encoding);this.texture.image={};this.texture.image.width=width;this.texture.image.height=height;this.texture.generateMipmaps=options.generateMipmaps!==undefined?options.generateMipmaps:false;this.texture.minFilter=options.minFilter!==undefined?options.minFilter:LinearFilter;this.depthBuffer=options.depthBuffer!==undefined?options.depthBuffer:true;this.stencilBuffer=options.stencilBuffer!==undefined?options.stencilBuffer:true;this.depthTexture=options.depthTexture!==undefined?options.depthTexture:null;}WebGLRenderTarget.prototype=_extends(Object.create(EventDispatcher.prototype),{constructor:WebGLRenderTarget,isWebGLRenderTarget:true,setSize:function setSize(width,height){if(this.width!==width||this.height!==height){this.width=width;this.height=height;this.texture.image.width=width;this.texture.image.height=height;this.dispose();}this.viewport.set(0,0,width,height);this.scissor.set(0,0,width,height);},clone:function clone(){return new this.constructor().copy(this);},copy:function copy(source){this.width=source.width;this.height=source.height;this.viewport.copy(source.viewport);this.texture=source.texture.clone();this.depthBuffer=source.depthBuffer;this.stencilBuffer=source.stencilBuffer;this.depthTexture=source.depthTexture;return this;},dispose:function dispose(){this.dispatchEvent({type:'dispose'});}}); |
467 |
|
468 |
|
469 | function WebGLMultisampleRenderTarget(width,height,options){WebGLRenderTarget.call(this,width,height,options);this.samples=4;}WebGLMultisampleRenderTarget.prototype=_extends(Object.create(WebGLRenderTarget.prototype),{constructor:WebGLMultisampleRenderTarget,isWebGLMultisampleRenderTarget:true,copy:function copy(source){WebGLRenderTarget.prototype.copy.call(this,source);this.samples=source.samples;return this;}}); |
470 |
|
471 |
|
472 |
|
473 |
|
474 | function Quaternion(x,y,z,w){this._x=x||0;this._y=y||0;this._z=z||0;this._w=w!==undefined?w:1;}_extends(Quaternion,{slerp:function slerp(qa,qb,qm,t){return qm.copy(qa).slerp(qb,t);},slerpFlat:function slerpFlat(dst,dstOffset,src0,srcOffset0,src1,srcOffset1,t){
|
475 | var x0=src0[srcOffset0+0],y0=src0[srcOffset0+1],z0=src0[srcOffset0+2],w0=src0[srcOffset0+3],x1=src1[srcOffset1+0],y1=src1[srcOffset1+1],z1=src1[srcOffset1+2],w1=src1[srcOffset1+3];if(w0!==w1||x0!==x1||y0!==y1||z0!==z1){var s=1-t,cos=x0*x1+y0*y1+z0*z1+w0*w1,dir=cos>=0?1:-1,sqrSin=1-cos*cos;
|
476 | if(sqrSin>Number.EPSILON){var sin=Math.sqrt(sqrSin),len=Math.atan2(sin,cos*dir);s=Math.sin(s*len)/sin;t=Math.sin(t*len)/sin;}var tDir=t*dir;x0=x0*s+x1*tDir;y0=y0*s+y1*tDir;z0=z0*s+z1*tDir;w0=w0*s+w1*tDir;
|
477 | if(s===1-t){var f=1/Math.sqrt(x0*x0+y0*y0+z0*z0+w0*w0);x0*=f;y0*=f;z0*=f;w0*=f;}}dst[dstOffset]=x0;dst[dstOffset+1]=y0;dst[dstOffset+2]=z0;dst[dstOffset+3]=w0;},multiplyQuaternionsFlat:function multiplyQuaternionsFlat(dst,dstOffset,src0,srcOffset0,src1,srcOffset1){var x0=src0[srcOffset0];var y0=src0[srcOffset0+1];var z0=src0[srcOffset0+2];var w0=src0[srcOffset0+3];var x1=src1[srcOffset1];var y1=src1[srcOffset1+1];var z1=src1[srcOffset1+2];var w1=src1[srcOffset1+3];dst[dstOffset]=x0*w1+w0*x1+y0*z1-z0*y1;dst[dstOffset+1]=y0*w1+w0*y1+z0*x1-x0*z1;dst[dstOffset+2]=z0*w1+w0*z1+x0*y1-y0*x1;dst[dstOffset+3]=w0*w1-x0*x1-y0*y1-z0*z1;return dst;}});Object.defineProperties(Quaternion.prototype,{x:{get:function get(){return this._x;},set:function set(value){this._x=value;this._onChangeCallback();}},y:{get:function get(){return this._y;},set:function set(value){this._y=value;this._onChangeCallback();}},z:{get:function get(){return this._z;},set:function set(value){this._z=value;this._onChangeCallback();}},w:{get:function get(){return this._w;},set:function set(value){this._w=value;this._onChangeCallback();}}});_extends(Quaternion.prototype,{isQuaternion:true,set:function set(x,y,z,w){this._x=x;this._y=y;this._z=z;this._w=w;this._onChangeCallback();return this;},clone:function clone(){return new this.constructor(this._x,this._y,this._z,this._w);},copy:function copy(quaternion){this._x=quaternion.x;this._y=quaternion.y;this._z=quaternion.z;this._w=quaternion.w;this._onChangeCallback();return this;},setFromEuler:function setFromEuler(euler,update){if(!(euler&&euler.isEuler)){throw new Error('THREE.Quaternion: .setFromEuler() now expects an Euler rotation rather than a Vector3 and order.');}var x=euler._x,y=euler._y,z=euler._z,order=euler.order;
|
478 |
|
479 |
|
480 | var cos=Math.cos;var sin=Math.sin;var c1=cos(x/2);var c2=cos(y/2);var c3=cos(z/2);var s1=sin(x/2);var s2=sin(y/2);var s3=sin(z/2);switch(order){case'XYZ':this._x=s1*c2*c3+c1*s2*s3;this._y=c1*s2*c3-s1*c2*s3;this._z=c1*c2*s3+s1*s2*c3;this._w=c1*c2*c3-s1*s2*s3;break;case'YXZ':this._x=s1*c2*c3+c1*s2*s3;this._y=c1*s2*c3-s1*c2*s3;this._z=c1*c2*s3-s1*s2*c3;this._w=c1*c2*c3+s1*s2*s3;break;case'ZXY':this._x=s1*c2*c3-c1*s2*s3;this._y=c1*s2*c3+s1*c2*s3;this._z=c1*c2*s3+s1*s2*c3;this._w=c1*c2*c3-s1*s2*s3;break;case'ZYX':this._x=s1*c2*c3-c1*s2*s3;this._y=c1*s2*c3+s1*c2*s3;this._z=c1*c2*s3-s1*s2*c3;this._w=c1*c2*c3+s1*s2*s3;break;case'YZX':this._x=s1*c2*c3+c1*s2*s3;this._y=c1*s2*c3+s1*c2*s3;this._z=c1*c2*s3-s1*s2*c3;this._w=c1*c2*c3-s1*s2*s3;break;case'XZY':this._x=s1*c2*c3-c1*s2*s3;this._y=c1*s2*c3-s1*c2*s3;this._z=c1*c2*s3+s1*s2*c3;this._w=c1*c2*c3+s1*s2*s3;break;default:console.warn('THREE.Quaternion: .setFromEuler() encountered an unknown order: '+order);}if(update!==false)this._onChangeCallback();return this;},setFromAxisAngle:function setFromAxisAngle(axis,angle){
|
481 |
|
482 | var halfAngle=angle/2,s=Math.sin(halfAngle);this._x=axis.x*s;this._y=axis.y*s;this._z=axis.z*s;this._w=Math.cos(halfAngle);this._onChangeCallback();return this;},setFromRotationMatrix:function setFromRotationMatrix(m){
|
483 |
|
484 | var te=m.elements,m11=te[0],m12=te[4],m13=te[8],m21=te[1],m22=te[5],m23=te[9],m31=te[2],m32=te[6],m33=te[10],trace=m11+m22+m33,s;if(trace>0){s=0.5/Math.sqrt(trace+1.0);this._w=0.25/s;this._x=(m32-m23)*s;this._y=(m13-m31)*s;this._z=(m21-m12)*s;}else if(m11>m22&&m11>m33){s=2.0*Math.sqrt(1.0+m11-m22-m33);this._w=(m32-m23)/s;this._x=0.25*s;this._y=(m12+m21)/s;this._z=(m13+m31)/s;}else if(m22>m33){s=2.0*Math.sqrt(1.0+m22-m11-m33);this._w=(m13-m31)/s;this._x=(m12+m21)/s;this._y=0.25*s;this._z=(m23+m32)/s;}else {s=2.0*Math.sqrt(1.0+m33-m11-m22);this._w=(m21-m12)/s;this._x=(m13+m31)/s;this._y=(m23+m32)/s;this._z=0.25*s;}this._onChangeCallback();return this;},setFromUnitVectors:function setFromUnitVectors(vFrom,vTo){
|
485 | var EPS=0.000001;var r=vFrom.dot(vTo)+1;if(r<EPS){r=0;if(Math.abs(vFrom.x)>Math.abs(vFrom.z)){this._x=-vFrom.y;this._y=vFrom.x;this._z=0;this._w=r;}else {this._x=0;this._y=-vFrom.z;this._z=vFrom.y;this._w=r;}}else {
|
486 | this._x=vFrom.y*vTo.z-vFrom.z*vTo.y;this._y=vFrom.z*vTo.x-vFrom.x*vTo.z;this._z=vFrom.x*vTo.y-vFrom.y*vTo.x;this._w=r;}return this.normalize();},angleTo:function angleTo(q){return 2*Math.acos(Math.abs(MathUtils.clamp(this.dot(q),-1,1)));},rotateTowards:function rotateTowards(q,step){var angle=this.angleTo(q);if(angle===0)return this;var t=Math.min(1,step/angle);this.slerp(q,t);return this;},inverse:function inverse(){
|
487 | return this.conjugate();},conjugate:function conjugate(){this._x*=-1;this._y*=-1;this._z*=-1;this._onChangeCallback();return this;},dot:function dot(v){return this._x*v._x+this._y*v._y+this._z*v._z+this._w*v._w;},lengthSq:function lengthSq(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w;},length:function length(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w);},normalize:function normalize(){var l=this.length();if(l===0){this._x=0;this._y=0;this._z=0;this._w=1;}else {l=1/l;this._x=this._x*l;this._y=this._y*l;this._z=this._z*l;this._w=this._w*l;}this._onChangeCallback();return this;},multiply:function multiply(q,p){if(p!==undefined){console.warn('THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.');return this.multiplyQuaternions(q,p);}return this.multiplyQuaternions(this,q);},premultiply:function premultiply(q){return this.multiplyQuaternions(q,this);},multiplyQuaternions:function multiplyQuaternions(a,b){
|
488 | var qax=a._x,qay=a._y,qaz=a._z,qaw=a._w;var qbx=b._x,qby=b._y,qbz=b._z,qbw=b._w;this._x=qax*qbw+qaw*qbx+qay*qbz-qaz*qby;this._y=qay*qbw+qaw*qby+qaz*qbx-qax*qbz;this._z=qaz*qbw+qaw*qbz+qax*qby-qay*qbx;this._w=qaw*qbw-qax*qbx-qay*qby-qaz*qbz;this._onChangeCallback();return this;},slerp:function slerp(qb,t){if(t===0)return this;if(t===1)return this.copy(qb);var x=this._x,y=this._y,z=this._z,w=this._w;
|
489 | var cosHalfTheta=w*qb._w+x*qb._x+y*qb._y+z*qb._z;if(cosHalfTheta<0){this._w=-qb._w;this._x=-qb._x;this._y=-qb._y;this._z=-qb._z;cosHalfTheta=-cosHalfTheta;}else {this.copy(qb);}if(cosHalfTheta>=1.0){this._w=w;this._x=x;this._y=y;this._z=z;return this;}var sqrSinHalfTheta=1.0-cosHalfTheta*cosHalfTheta;if(sqrSinHalfTheta<=Number.EPSILON){var s=1-t;this._w=s*w+t*this._w;this._x=s*x+t*this._x;this._y=s*y+t*this._y;this._z=s*z+t*this._z;this.normalize();this._onChangeCallback();return this;}var sinHalfTheta=Math.sqrt(sqrSinHalfTheta);var halfTheta=Math.atan2(sinHalfTheta,cosHalfTheta);var ratioA=Math.sin((1-t)*halfTheta)/sinHalfTheta,ratioB=Math.sin(t*halfTheta)/sinHalfTheta;this._w=w*ratioA+this._w*ratioB;this._x=x*ratioA+this._x*ratioB;this._y=y*ratioA+this._y*ratioB;this._z=z*ratioA+this._z*ratioB;this._onChangeCallback();return this;},equals:function equals(quaternion){return quaternion._x===this._x&&quaternion._y===this._y&&quaternion._z===this._z&&quaternion._w===this._w;},fromArray:function fromArray(array,offset){if(offset===undefined)offset=0;this._x=array[offset];this._y=array[offset+1];this._z=array[offset+2];this._w=array[offset+3];this._onChangeCallback();return this;},toArray:function toArray(array,offset){if(array===undefined)array=[];if(offset===undefined)offset=0;array[offset]=this._x;array[offset+1]=this._y;array[offset+2]=this._z;array[offset+3]=this._w;return array;},fromBufferAttribute:function fromBufferAttribute(attribute,index){this._x=attribute.getX(index);this._y=attribute.getY(index);this._z=attribute.getZ(index);this._w=attribute.getW(index);return this;},_onChange:function _onChange(callback){this._onChangeCallback=callback;return this;},_onChangeCallback:function _onChangeCallback(){}}); |
490 |
|
491 |
|
492 |
|
493 |
|
494 |
|
495 |
|
496 | var _vector=new Vector3();var _quaternion=new Quaternion();function Vector3(x,y,z){this.x=x||0;this.y=y||0;this.z=z||0;}_extends(Vector3.prototype,{isVector3:true,set:function set(x,y,z){this.x=x;this.y=y;this.z=z;return this;},setScalar:function setScalar(scalar){this.x=scalar;this.y=scalar;this.z=scalar;return this;},setX:function setX(x){this.x=x;return this;},setY:function setY(y){this.y=y;return this;},setZ:function setZ(z){this.z=z;return this;},setComponent:function setComponent(index,value){switch(index){case 0:this.x=value;break;case 1:this.y=value;break;case 2:this.z=value;break;default:throw new Error('index is out of range: '+index);}return this;},getComponent:function getComponent(index){switch(index){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error('index is out of range: '+index);}},clone:function clone(){return new this.constructor(this.x,this.y,this.z);},copy:function copy(v){this.x=v.x;this.y=v.y;this.z=v.z;return this;},add:function add(v,w){if(w!==undefined){console.warn('THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.');return this.addVectors(v,w);}this.x+=v.x;this.y+=v.y;this.z+=v.z;return this;},addScalar:function addScalar(s){this.x+=s;this.y+=s;this.z+=s;return this;},addVectors:function addVectors(a,b){this.x=a.x+b.x;this.y=a.y+b.y;this.z=a.z+b.z;return this;},addScaledVector:function addScaledVector(v,s){this.x+=v.x*s;this.y+=v.y*s;this.z+=v.z*s;return this;},sub:function sub(v,w){if(w!==undefined){console.warn('THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.');return this.subVectors(v,w);}this.x-=v.x;this.y-=v.y;this.z-=v.z;return this;},subScalar:function subScalar(s){this.x-=s;this.y-=s;this.z-=s;return this;},subVectors:function subVectors(a,b){this.x=a.x-b.x;this.y=a.y-b.y;this.z=a.z-b.z;return this;},multiply:function multiply(v,w){if(w!==undefined){console.warn('THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.');return this.multiplyVectors(v,w);}this.x*=v.x;this.y*=v.y;this.z*=v.z;return this;},multiplyScalar:function multiplyScalar(scalar){this.x*=scalar;this.y*=scalar;this.z*=scalar;return this;},multiplyVectors:function multiplyVectors(a,b){this.x=a.x*b.x;this.y=a.y*b.y;this.z=a.z*b.z;return this;},applyEuler:function applyEuler(euler){if(!(euler&&euler.isEuler)){console.error('THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order.');}return this.applyQuaternion(_quaternion.setFromEuler(euler));},applyAxisAngle:function applyAxisAngle(axis,angle){return this.applyQuaternion(_quaternion.setFromAxisAngle(axis,angle));},applyMatrix3:function applyMatrix3(m){var x=this.x,y=this.y,z=this.z;var e=m.elements;this.x=e[0]*x+e[3]*y+e[6]*z;this.y=e[1]*x+e[4]*y+e[7]*z;this.z=e[2]*x+e[5]*y+e[8]*z;return this;},applyNormalMatrix:function applyNormalMatrix(m){return this.applyMatrix3(m).normalize();},applyMatrix4:function applyMatrix4(m){var x=this.x,y=this.y,z=this.z;var e=m.elements;var w=1/(e[3]*x+e[7]*y+e[11]*z+e[15]);this.x=(e[0]*x+e[4]*y+e[8]*z+e[12])*w;this.y=(e[1]*x+e[5]*y+e[9]*z+e[13])*w;this.z=(e[2]*x+e[6]*y+e[10]*z+e[14])*w;return this;},applyQuaternion:function applyQuaternion(q){var x=this.x,y=this.y,z=this.z;var qx=q.x,qy=q.y,qz=q.z,qw=q.w;
|
497 | var ix=qw*x+qy*z-qz*y;var iy=qw*y+qz*x-qx*z;var iz=qw*z+qx*y-qy*x;var iw=-qx*x-qy*y-qz*z;
|
498 | this.x=ix*qw+iw*-qx+iy*-qz-iz*-qy;this.y=iy*qw+iw*-qy+iz*-qx-ix*-qz;this.z=iz*qw+iw*-qz+ix*-qy-iy*-qx;return this;},project:function project(camera){return this.applyMatrix4(camera.matrixWorldInverse).applyMatrix4(camera.projectionMatrix);},unproject:function unproject(camera){return this.applyMatrix4(camera.projectionMatrixInverse).applyMatrix4(camera.matrixWorld);},transformDirection:function transformDirection(m){
|
499 |
|
500 | var x=this.x,y=this.y,z=this.z;var e=m.elements;this.x=e[0]*x+e[4]*y+e[8]*z;this.y=e[1]*x+e[5]*y+e[9]*z;this.z=e[2]*x+e[6]*y+e[10]*z;return this.normalize();},divide:function divide(v){this.x/=v.x;this.y/=v.y;this.z/=v.z;return this;},divideScalar:function divideScalar(scalar){return this.multiplyScalar(1/scalar);},min:function min(v){this.x=Math.min(this.x,v.x);this.y=Math.min(this.y,v.y);this.z=Math.min(this.z,v.z);return this;},max:function max(v){this.x=Math.max(this.x,v.x);this.y=Math.max(this.y,v.y);this.z=Math.max(this.z,v.z);return this;},clamp:function clamp(min,max){
|
501 | this.x=Math.max(min.x,Math.min(max.x,this.x));this.y=Math.max(min.y,Math.min(max.y,this.y));this.z=Math.max(min.z,Math.min(max.z,this.z));return this;},clampScalar:function clampScalar(minVal,maxVal){this.x=Math.max(minVal,Math.min(maxVal,this.x));this.y=Math.max(minVal,Math.min(maxVal,this.y));this.z=Math.max(minVal,Math.min(maxVal,this.z));return this;},clampLength:function clampLength(min,max){var length=this.length();return this.divideScalar(length||1).multiplyScalar(Math.max(min,Math.min(max,length)));},floor:function floor(){this.x=Math.floor(this.x);this.y=Math.floor(this.y);this.z=Math.floor(this.z);return this;},ceil:function ceil(){this.x=Math.ceil(this.x);this.y=Math.ceil(this.y);this.z=Math.ceil(this.z);return this;},round:function round(){this.x=Math.round(this.x);this.y=Math.round(this.y);this.z=Math.round(this.z);return this;},roundToZero:function roundToZero(){this.x=this.x<0?Math.ceil(this.x):Math.floor(this.x);this.y=this.y<0?Math.ceil(this.y):Math.floor(this.y);this.z=this.z<0?Math.ceil(this.z):Math.floor(this.z);return this;},negate:function negate(){this.x=-this.x;this.y=-this.y;this.z=-this.z;return this;},dot:function dot(v){return this.x*v.x+this.y*v.y+this.z*v.z;},
|
502 | lengthSq:function lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z;},length:function length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z);},manhattanLength:function manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z);},normalize:function normalize(){return this.divideScalar(this.length()||1);},setLength:function setLength(length){return this.normalize().multiplyScalar(length);},lerp:function lerp(v,alpha){this.x+=(v.x-this.x)*alpha;this.y+=(v.y-this.y)*alpha;this.z+=(v.z-this.z)*alpha;return this;},lerpVectors:function lerpVectors(v1,v2,alpha){return this.subVectors(v2,v1).multiplyScalar(alpha).add(v1);},cross:function cross(v,w){if(w!==undefined){console.warn('THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.');return this.crossVectors(v,w);}return this.crossVectors(this,v);},crossVectors:function crossVectors(a,b){var ax=a.x,ay=a.y,az=a.z;var bx=b.x,by=b.y,bz=b.z;this.x=ay*bz-az*by;this.y=az*bx-ax*bz;this.z=ax*by-ay*bx;return this;},projectOnVector:function projectOnVector(v){var denominator=v.lengthSq();if(denominator===0)return this.set(0,0,0);var scalar=v.dot(this)/denominator;return this.copy(v).multiplyScalar(scalar);},projectOnPlane:function projectOnPlane(planeNormal){_vector.copy(this).projectOnVector(planeNormal);return this.sub(_vector);},reflect:function reflect(normal){
|
503 |
|
504 | return this.sub(_vector.copy(normal).multiplyScalar(2*this.dot(normal)));},angleTo:function angleTo(v){var denominator=Math.sqrt(this.lengthSq()*v.lengthSq());if(denominator===0)return Math.PI/2;var theta=this.dot(v)/denominator;
|
505 | return Math.acos(MathUtils.clamp(theta,-1,1));},distanceTo:function distanceTo(v){return Math.sqrt(this.distanceToSquared(v));},distanceToSquared:function distanceToSquared(v){var dx=this.x-v.x,dy=this.y-v.y,dz=this.z-v.z;return dx*dx+dy*dy+dz*dz;},manhattanDistanceTo:function manhattanDistanceTo(v){return Math.abs(this.x-v.x)+Math.abs(this.y-v.y)+Math.abs(this.z-v.z);},setFromSpherical:function setFromSpherical(s){return this.setFromSphericalCoords(s.radius,s.phi,s.theta);},setFromSphericalCoords:function setFromSphericalCoords(radius,phi,theta){var sinPhiRadius=Math.sin(phi)*radius;this.x=sinPhiRadius*Math.sin(theta);this.y=Math.cos(phi)*radius;this.z=sinPhiRadius*Math.cos(theta);return this;},setFromCylindrical:function setFromCylindrical(c){return this.setFromCylindricalCoords(c.radius,c.theta,c.y);},setFromCylindricalCoords:function setFromCylindricalCoords(radius,theta,y){this.x=radius*Math.sin(theta);this.y=y;this.z=radius*Math.cos(theta);return this;},setFromMatrixPosition:function setFromMatrixPosition(m){var e=m.elements;this.x=e[12];this.y=e[13];this.z=e[14];return this;},setFromMatrixScale:function setFromMatrixScale(m){var sx=this.setFromMatrixColumn(m,0).length();var sy=this.setFromMatrixColumn(m,1).length();var sz=this.setFromMatrixColumn(m,2).length();this.x=sx;this.y=sy;this.z=sz;return this;},setFromMatrixColumn:function setFromMatrixColumn(m,index){return this.fromArray(m.elements,index*4);},setFromMatrix3Column:function setFromMatrix3Column(m,index){return this.fromArray(m.elements,index*3);},equals:function equals(v){return v.x===this.x&&v.y===this.y&&v.z===this.z;},fromArray:function fromArray(array,offset){if(offset===undefined)offset=0;this.x=array[offset];this.y=array[offset+1];this.z=array[offset+2];return this;},toArray:function toArray(array,offset){if(array===undefined)array=[];if(offset===undefined)offset=0;array[offset]=this.x;array[offset+1]=this.y;array[offset+2]=this.z;return array;},fromBufferAttribute:function fromBufferAttribute(attribute,index,offset){if(offset!==undefined){console.warn('THREE.Vector3: offset has been removed from .fromBufferAttribute().');}this.x=attribute.getX(index);this.y=attribute.getY(index);this.z=attribute.getZ(index);return this;},random:function random(){this.x=Math.random();this.y=Math.random();this.z=Math.random();return this;}});var _v1=new Vector3();var _m1=new Matrix4();var _zero=new Vector3(0,0,0);var _one=new Vector3(1,1,1);var _x=new Vector3();var _y=new Vector3();var _z=new Vector3(); |
506 |
|
507 |
|
508 |
|
509 |
|
510 |
|
511 |
|
512 |
|
513 |
|
514 |
|
515 |
|
516 | function Matrix4(){this.elements=[1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1];if(arguments.length>0){console.error('THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.');}}_extends(Matrix4.prototype,{isMatrix4:true,set:function set(n11,n12,n13,n14,n21,n22,n23,n24,n31,n32,n33,n34,n41,n42,n43,n44){var te=this.elements;te[0]=n11;te[4]=n12;te[8]=n13;te[12]=n14;te[1]=n21;te[5]=n22;te[9]=n23;te[13]=n24;te[2]=n31;te[6]=n32;te[10]=n33;te[14]=n34;te[3]=n41;te[7]=n42;te[11]=n43;te[15]=n44;return this;},identity:function identity(){this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1);return this;},clone:function clone(){return new Matrix4().fromArray(this.elements);},copy:function copy(m){var te=this.elements;var me=m.elements;te[0]=me[0];te[1]=me[1];te[2]=me[2];te[3]=me[3];te[4]=me[4];te[5]=me[5];te[6]=me[6];te[7]=me[7];te[8]=me[8];te[9]=me[9];te[10]=me[10];te[11]=me[11];te[12]=me[12];te[13]=me[13];te[14]=me[14];te[15]=me[15];return this;},copyPosition:function copyPosition(m){var te=this.elements,me=m.elements;te[12]=me[12];te[13]=me[13];te[14]=me[14];return this;},extractBasis:function extractBasis(xAxis,yAxis,zAxis){xAxis.setFromMatrixColumn(this,0);yAxis.setFromMatrixColumn(this,1);zAxis.setFromMatrixColumn(this,2);return this;},makeBasis:function makeBasis(xAxis,yAxis,zAxis){this.set(xAxis.x,yAxis.x,zAxis.x,0,xAxis.y,yAxis.y,zAxis.y,0,xAxis.z,yAxis.z,zAxis.z,0,0,0,0,1);return this;},extractRotation:function extractRotation(m){
|
517 | var te=this.elements;var me=m.elements;var scaleX=1/_v1.setFromMatrixColumn(m,0).length();var scaleY=1/_v1.setFromMatrixColumn(m,1).length();var scaleZ=1/_v1.setFromMatrixColumn(m,2).length();te[0]=me[0]*scaleX;te[1]=me[1]*scaleX;te[2]=me[2]*scaleX;te[3]=0;te[4]=me[4]*scaleY;te[5]=me[5]*scaleY;te[6]=me[6]*scaleY;te[7]=0;te[8]=me[8]*scaleZ;te[9]=me[9]*scaleZ;te[10]=me[10]*scaleZ;te[11]=0;te[12]=0;te[13]=0;te[14]=0;te[15]=1;return this;},makeRotationFromEuler:function makeRotationFromEuler(euler){if(!(euler&&euler.isEuler)){console.error('THREE.Matrix4: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.');}var te=this.elements;var x=euler.x,y=euler.y,z=euler.z;var a=Math.cos(x),b=Math.sin(x);var c=Math.cos(y),d=Math.sin(y);var e=Math.cos(z),f=Math.sin(z);if(euler.order==='XYZ'){var ae=a*e,af=a*f,be=b*e,bf=b*f;te[0]=c*e;te[4]=-c*f;te[8]=d;te[1]=af+be*d;te[5]=ae-bf*d;te[9]=-b*c;te[2]=bf-ae*d;te[6]=be+af*d;te[10]=a*c;}else if(euler.order==='YXZ'){var ce=c*e,cf=c*f,de=d*e,df=d*f;te[0]=ce+df*b;te[4]=de*b-cf;te[8]=a*d;te[1]=a*f;te[5]=a*e;te[9]=-b;te[2]=cf*b-de;te[6]=df+ce*b;te[10]=a*c;}else if(euler.order==='ZXY'){var ce=c*e,cf=c*f,de=d*e,df=d*f;te[0]=ce-df*b;te[4]=-a*f;te[8]=de+cf*b;te[1]=cf+de*b;te[5]=a*e;te[9]=df-ce*b;te[2]=-a*d;te[6]=b;te[10]=a*c;}else if(euler.order==='ZYX'){var ae=a*e,af=a*f,be=b*e,bf=b*f;te[0]=c*e;te[4]=be*d-af;te[8]=ae*d+bf;te[1]=c*f;te[5]=bf*d+ae;te[9]=af*d-be;te[2]=-d;te[6]=b*c;te[10]=a*c;}else if(euler.order==='YZX'){var ac=a*c,ad=a*d,bc=b*c,bd=b*d;te[0]=c*e;te[4]=bd-ac*f;te[8]=bc*f+ad;te[1]=f;te[5]=a*e;te[9]=-b*e;te[2]=-d*e;te[6]=ad*f+bc;te[10]=ac-bd*f;}else if(euler.order==='XZY'){var ac=a*c,ad=a*d,bc=b*c,bd=b*d;te[0]=c*e;te[4]=-f;te[8]=d*e;te[1]=ac*f+bd;te[5]=a*e;te[9]=ad*f-bc;te[2]=bc*f-ad;te[6]=b*e;te[10]=bd*f+ac;}
|
518 | te[3]=0;te[7]=0;te[11]=0;
|
519 | te[12]=0;te[13]=0;te[14]=0;te[15]=1;return this;},makeRotationFromQuaternion:function makeRotationFromQuaternion(q){return this.compose(_zero,q,_one);},lookAt:function lookAt(eye,target,up){var te=this.elements;_z.subVectors(eye,target);if(_z.lengthSq()===0){
|
520 | _z.z=1;}_z.normalize();_x.crossVectors(up,_z);if(_x.lengthSq()===0){
|
521 | if(Math.abs(up.z)===1){_z.x+=0.0001;}else {_z.z+=0.0001;}_z.normalize();_x.crossVectors(up,_z);}_x.normalize();_y.crossVectors(_z,_x);te[0]=_x.x;te[4]=_y.x;te[8]=_z.x;te[1]=_x.y;te[5]=_y.y;te[9]=_z.y;te[2]=_x.z;te[6]=_y.z;te[10]=_z.z;return this;},multiply:function multiply(m,n){if(n!==undefined){console.warn('THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.');return this.multiplyMatrices(m,n);}return this.multiplyMatrices(this,m);},premultiply:function premultiply(m){return this.multiplyMatrices(m,this);},multiplyMatrices:function multiplyMatrices(a,b){var ae=a.elements;var be=b.elements;var te=this.elements;var a11=ae[0],a12=ae[4],a13=ae[8],a14=ae[12];var a21=ae[1],a22=ae[5],a23=ae[9],a24=ae[13];var a31=ae[2],a32=ae[6],a33=ae[10],a34=ae[14];var a41=ae[3],a42=ae[7],a43=ae[11],a44=ae[15];var b11=be[0],b12=be[4],b13=be[8],b14=be[12];var b21=be[1],b22=be[5],b23=be[9],b24=be[13];var b31=be[2],b32=be[6],b33=be[10],b34=be[14];var b41=be[3],b42=be[7],b43=be[11],b44=be[15];te[0]=a11*b11+a12*b21+a13*b31+a14*b41;te[4]=a11*b12+a12*b22+a13*b32+a14*b42;te[8]=a11*b13+a12*b23+a13*b33+a14*b43;te[12]=a11*b14+a12*b24+a13*b34+a14*b44;te[1]=a21*b11+a22*b21+a23*b31+a24*b41;te[5]=a21*b12+a22*b22+a23*b32+a24*b42;te[9]=a21*b13+a22*b23+a23*b33+a24*b43;te[13]=a21*b14+a22*b24+a23*b34+a24*b44;te[2]=a31*b11+a32*b21+a33*b31+a34*b41;te[6]=a31*b12+a32*b22+a33*b32+a34*b42;te[10]=a31*b13+a32*b23+a33*b33+a34*b43;te[14]=a31*b14+a32*b24+a33*b34+a34*b44;te[3]=a41*b11+a42*b21+a43*b31+a44*b41;te[7]=a41*b12+a42*b22+a43*b32+a44*b42;te[11]=a41*b13+a42*b23+a43*b33+a44*b43;te[15]=a41*b14+a42*b24+a43*b34+a44*b44;return this;},multiplyScalar:function multiplyScalar(s){var te=this.elements;te[0]*=s;te[4]*=s;te[8]*=s;te[12]*=s;te[1]*=s;te[5]*=s;te[9]*=s;te[13]*=s;te[2]*=s;te[6]*=s;te[10]*=s;te[14]*=s;te[3]*=s;te[7]*=s;te[11]*=s;te[15]*=s;return this;},determinant:function determinant(){var te=this.elements;var n11=te[0],n12=te[4],n13=te[8],n14=te[12];var n21=te[1],n22=te[5],n23=te[9],n24=te[13];var n31=te[2],n32=te[6],n33=te[10],n34=te[14];var n41=te[3],n42=te[7],n43=te[11],n44=te[15];
|
522 |
|
523 | return n41*(+n14*n23*n32-n13*n24*n32-n14*n22*n33+n12*n24*n33+n13*n22*n34-n12*n23*n34)+n42*(+n11*n23*n34-n11*n24*n33+n14*n21*n33-n13*n21*n34+n13*n24*n31-n14*n23*n31)+n43*(+n11*n24*n32-n11*n22*n34-n14*n21*n32+n12*n21*n34+n14*n22*n31-n12*n24*n31)+n44*(-n13*n22*n31-n11*n23*n32+n11*n22*n33+n13*n21*n32-n12*n21*n33+n12*n23*n31);},transpose:function transpose(){var te=this.elements;var tmp;tmp=te[1];te[1]=te[4];te[4]=tmp;tmp=te[2];te[2]=te[8];te[8]=tmp;tmp=te[6];te[6]=te[9];te[9]=tmp;tmp=te[3];te[3]=te[12];te[12]=tmp;tmp=te[7];te[7]=te[13];te[13]=tmp;tmp=te[11];te[11]=te[14];te[14]=tmp;return this;},setPosition:function setPosition(x,y,z){var te=this.elements;if(x.isVector3){te[12]=x.x;te[13]=x.y;te[14]=x.z;}else {te[12]=x;te[13]=y;te[14]=z;}return this;},getInverse:function getInverse(m,throwOnDegenerate){if(throwOnDegenerate!==undefined){console.warn("THREE.Matrix4: .getInverse() can no longer be configured to throw on degenerate.");}
|
524 | var te=this.elements,me=m.elements,n11=me[0],n21=me[1],n31=me[2],n41=me[3],n12=me[4],n22=me[5],n32=me[6],n42=me[7],n13=me[8],n23=me[9],n33=me[10],n43=me[11],n14=me[12],n24=me[13],n34=me[14],n44=me[15],t11=n23*n34*n42-n24*n33*n42+n24*n32*n43-n22*n34*n43-n23*n32*n44+n22*n33*n44,t12=n14*n33*n42-n13*n34*n42-n14*n32*n43+n12*n34*n43+n13*n32*n44-n12*n33*n44,t13=n13*n24*n42-n14*n23*n42+n14*n22*n43-n12*n24*n43-n13*n22*n44+n12*n23*n44,t14=n14*n23*n32-n13*n24*n32-n14*n22*n33+n12*n24*n33+n13*n22*n34-n12*n23*n34;var det=n11*t11+n21*t12+n31*t13+n41*t14;if(det===0)return this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);var detInv=1/det;te[0]=t11*detInv;te[1]=(n24*n33*n41-n23*n34*n41-n24*n31*n43+n21*n34*n43+n23*n31*n44-n21*n33*n44)*detInv;te[2]=(n22*n34*n41-n24*n32*n41+n24*n31*n42-n21*n34*n42-n22*n31*n44+n21*n32*n44)*detInv;te[3]=(n23*n32*n41-n22*n33*n41-n23*n31*n42+n21*n33*n42+n22*n31*n43-n21*n32*n43)*detInv;te[4]=t12*detInv;te[5]=(n13*n34*n41-n14*n33*n41+n14*n31*n43-n11*n34*n43-n13*n31*n44+n11*n33*n44)*detInv;te[6]=(n14*n32*n41-n12*n34*n41-n14*n31*n42+n11*n34*n42+n12*n31*n44-n11*n32*n44)*detInv;te[7]=(n12*n33*n41-n13*n32*n41+n13*n31*n42-n11*n33*n42-n12*n31*n43+n11*n32*n43)*detInv;te[8]=t13*detInv;te[9]=(n14*n23*n41-n13*n24*n41-n14*n21*n43+n11*n24*n43+n13*n21*n44-n11*n23*n44)*detInv;te[10]=(n12*n24*n41-n14*n22*n41+n14*n21*n42-n11*n24*n42-n12*n21*n44+n11*n22*n44)*detInv;te[11]=(n13*n22*n41-n12*n23*n41-n13*n21*n42+n11*n23*n42+n12*n21*n43-n11*n22*n43)*detInv;te[12]=t14*detInv;te[13]=(n13*n24*n31-n14*n23*n31+n14*n21*n33-n11*n24*n33-n13*n21*n34+n11*n23*n34)*detInv;te[14]=(n14*n22*n31-n12*n24*n31-n14*n21*n32+n11*n24*n32+n12*n21*n34-n11*n22*n34)*detInv;te[15]=(n12*n23*n31-n13*n22*n31+n13*n21*n32-n11*n23*n32-n12*n21*n33+n11*n22*n33)*detInv;return this;},scale:function scale(v){var te=this.elements;var x=v.x,y=v.y,z=v.z;te[0]*=x;te[4]*=y;te[8]*=z;te[1]*=x;te[5]*=y;te[9]*=z;te[2]*=x;te[6]*=y;te[10]*=z;te[3]*=x;te[7]*=y;te[11]*=z;return this;},getMaxScaleOnAxis:function getMaxScaleOnAxis(){var te=this.elements;var scaleXSq=te[0]*te[0]+te[1]*te[1]+te[2]*te[2];var scaleYSq=te[4]*te[4]+te[5]*te[5]+te[6]*te[6];var scaleZSq=te[8]*te[8]+te[9]*te[9]+te[10]*te[10];return Math.sqrt(Math.max(scaleXSq,scaleYSq,scaleZSq));},makeTranslation:function makeTranslation(x,y,z){this.set(1,0,0,x,0,1,0,y,0,0,1,z,0,0,0,1);return this;},makeRotationX:function makeRotationX(theta){var c=Math.cos(theta),s=Math.sin(theta);this.set(1,0,0,0,0,c,-s,0,0,s,c,0,0,0,0,1);return this;},makeRotationY:function makeRotationY(theta){var c=Math.cos(theta),s=Math.sin(theta);this.set(c,0,s,0,0,1,0,0,-s,0,c,0,0,0,0,1);return this;},makeRotationZ:function makeRotationZ(theta){var c=Math.cos(theta),s=Math.sin(theta);this.set(c,-s,0,0,s,c,0,0,0,0,1,0,0,0,0,1);return this;},makeRotationAxis:function makeRotationAxis(axis,angle){
|
525 | var c=Math.cos(angle);var s=Math.sin(angle);var t=1-c;var x=axis.x,y=axis.y,z=axis.z;var tx=t*x,ty=t*y;this.set(tx*x+c,tx*y-s*z,tx*z+s*y,0,tx*y+s*z,ty*y+c,ty*z-s*x,0,tx*z-s*y,ty*z+s*x,t*z*z+c,0,0,0,0,1);return this;},makeScale:function makeScale(x,y,z){this.set(x,0,0,0,0,y,0,0,0,0,z,0,0,0,0,1);return this;},makeShear:function makeShear(x,y,z){this.set(1,y,z,0,x,1,z,0,x,y,1,0,0,0,0,1);return this;},compose:function compose(position,quaternion,scale){var te=this.elements;var x=quaternion._x,y=quaternion._y,z=quaternion._z,w=quaternion._w;var x2=x+x,y2=y+y,z2=z+z;var xx=x*x2,xy=x*y2,xz=x*z2;var yy=y*y2,yz=y*z2,zz=z*z2;var wx=w*x2,wy=w*y2,wz=w*z2;var sx=scale.x,sy=scale.y,sz=scale.z;te[0]=(1-(yy+zz))*sx;te[1]=(xy+wz)*sx;te[2]=(xz-wy)*sx;te[3]=0;te[4]=(xy-wz)*sy;te[5]=(1-(xx+zz))*sy;te[6]=(yz+wx)*sy;te[7]=0;te[8]=(xz+wy)*sz;te[9]=(yz-wx)*sz;te[10]=(1-(xx+yy))*sz;te[11]=0;te[12]=position.x;te[13]=position.y;te[14]=position.z;te[15]=1;return this;},decompose:function decompose(position,quaternion,scale){var te=this.elements;var sx=_v1.set(te[0],te[1],te[2]).length();var sy=_v1.set(te[4],te[5],te[6]).length();var sz=_v1.set(te[8],te[9],te[10]).length();
|
526 | var det=this.determinant();if(det<0)sx=-sx;position.x=te[12];position.y=te[13];position.z=te[14];
|
527 | _m1.copy(this);var invSX=1/sx;var invSY=1/sy;var invSZ=1/sz;_m1.elements[0]*=invSX;_m1.elements[1]*=invSX;_m1.elements[2]*=invSX;_m1.elements[4]*=invSY;_m1.elements[5]*=invSY;_m1.elements[6]*=invSY;_m1.elements[8]*=invSZ;_m1.elements[9]*=invSZ;_m1.elements[10]*=invSZ;quaternion.setFromRotationMatrix(_m1);scale.x=sx;scale.y=sy;scale.z=sz;return this;},makePerspective:function makePerspective(left,right,top,bottom,near,far){if(far===undefined){console.warn('THREE.Matrix4: .makePerspective() has been redefined and has a new signature. Please check the docs.');}var te=this.elements;var x=2*near/(right-left);var y=2*near/(top-bottom);var a=(right+left)/(right-left);var b=(top+bottom)/(top-bottom);var c=-(far+near)/(far-near);var d=-2*far*near/(far-near);te[0]=x;te[4]=0;te[8]=a;te[12]=0;te[1]=0;te[5]=y;te[9]=b;te[13]=0;te[2]=0;te[6]=0;te[10]=c;te[14]=d;te[3]=0;te[7]=0;te[11]=-1;te[15]=0;return this;},makeOrthographic:function makeOrthographic(left,right,top,bottom,near,far){var te=this.elements;var w=1.0/(right-left);var h=1.0/(top-bottom);var p=1.0/(far-near);var x=(right+left)*w;var y=(top+bottom)*h;var z=(far+near)*p;te[0]=2*w;te[4]=0;te[8]=0;te[12]=-x;te[1]=0;te[5]=2*h;te[9]=0;te[13]=-y;te[2]=0;te[6]=0;te[10]=-2*p;te[14]=-z;te[3]=0;te[7]=0;te[11]=0;te[15]=1;return this;},equals:function equals(matrix){var te=this.elements;var me=matrix.elements;for(var i=0;i<16;i++){if(te[i]!==me[i])return false;}return true;},fromArray:function fromArray(array,offset){if(offset===undefined)offset=0;for(var i=0;i<16;i++){this.elements[i]=array[i+offset];}return this;},toArray:function toArray(array,offset){if(array===undefined)array=[];if(offset===undefined)offset=0;var te=this.elements;array[offset]=te[0];array[offset+1]=te[1];array[offset+2]=te[2];array[offset+3]=te[3];array[offset+4]=te[4];array[offset+5]=te[5];array[offset+6]=te[6];array[offset+7]=te[7];array[offset+8]=te[8];array[offset+9]=te[9];array[offset+10]=te[10];array[offset+11]=te[11];array[offset+12]=te[12];array[offset+13]=te[13];array[offset+14]=te[14];array[offset+15]=te[15];return array;}}); |
528 |
|
529 |
|
530 |
|
531 | var _matrix=new Matrix4();var _quaternion$1=new Quaternion();function Euler(x,y,z,order){this._x=x||0;this._y=y||0;this._z=z||0;this._order=order||Euler.DefaultOrder;}Euler.RotationOrders=['XYZ','YZX','ZXY','XZY','YXZ','ZYX'];Euler.DefaultOrder='XYZ';Object.defineProperties(Euler.prototype,{x:{get:function get(){return this._x;},set:function set(value){this._x=value;this._onChangeCallback();}},y:{get:function get(){return this._y;},set:function set(value){this._y=value;this._onChangeCallback();}},z:{get:function get(){return this._z;},set:function set(value){this._z=value;this._onChangeCallback();}},order:{get:function get(){return this._order;},set:function set(value){this._order=value;this._onChangeCallback();}}});_extends(Euler.prototype,{isEuler:true,set:function set(x,y,z,order){this._x=x;this._y=y;this._z=z;this._order=order||this._order;this._onChangeCallback();return this;},clone:function clone(){return new this.constructor(this._x,this._y,this._z,this._order);},copy:function copy(euler){this._x=euler._x;this._y=euler._y;this._z=euler._z;this._order=euler._order;this._onChangeCallback();return this;},setFromRotationMatrix:function setFromRotationMatrix(m,order,update){var clamp=MathUtils.clamp;
|
532 | var te=m.elements;var m11=te[0],m12=te[4],m13=te[8];var m21=te[1],m22=te[5],m23=te[9];var m31=te[2],m32=te[6],m33=te[10];order=order||this._order;switch(order){case'XYZ':this._y=Math.asin(clamp(m13,-1,1));if(Math.abs(m13)<0.9999999){this._x=Math.atan2(-m23,m33);this._z=Math.atan2(-m12,m11);}else {this._x=Math.atan2(m32,m22);this._z=0;}break;case'YXZ':this._x=Math.asin(-clamp(m23,-1,1));if(Math.abs(m23)<0.9999999){this._y=Math.atan2(m13,m33);this._z=Math.atan2(m21,m22);}else {this._y=Math.atan2(-m31,m11);this._z=0;}break;case'ZXY':this._x=Math.asin(clamp(m32,-1,1));if(Math.abs(m32)<0.9999999){this._y=Math.atan2(-m31,m33);this._z=Math.atan2(-m12,m22);}else {this._y=0;this._z=Math.atan2(m21,m11);}break;case'ZYX':this._y=Math.asin(-clamp(m31,-1,1));if(Math.abs(m31)<0.9999999){this._x=Math.atan2(m32,m33);this._z=Math.atan2(m21,m11);}else {this._x=0;this._z=Math.atan2(-m12,m22);}break;case'YZX':this._z=Math.asin(clamp(m21,-1,1));if(Math.abs(m21)<0.9999999){this._x=Math.atan2(-m23,m22);this._y=Math.atan2(-m31,m11);}else {this._x=0;this._y=Math.atan2(m13,m33);}break;case'XZY':this._z=Math.asin(-clamp(m12,-1,1));if(Math.abs(m12)<0.9999999){this._x=Math.atan2(m32,m22);this._y=Math.atan2(m13,m11);}else {this._x=Math.atan2(-m23,m33);this._y=0;}break;default:console.warn('THREE.Euler: .setFromRotationMatrix() encountered an unknown order: '+order);}this._order=order;if(update!==false)this._onChangeCallback();return this;},setFromQuaternion:function setFromQuaternion(q,order,update){_matrix.makeRotationFromQuaternion(q);return this.setFromRotationMatrix(_matrix,order,update);},setFromVector3:function setFromVector3(v,order){return this.set(v.x,v.y,v.z,order||this._order);},reorder:function reorder(newOrder){
|
533 | _quaternion$1.setFromEuler(this);return this.setFromQuaternion(_quaternion$1,newOrder);},equals:function equals(euler){return euler._x===this._x&&euler._y===this._y&&euler._z===this._z&&euler._order===this._order;},fromArray:function fromArray(array){this._x=array[0];this._y=array[1];this._z=array[2];if(array[3]!==undefined)this._order=array[3];this._onChangeCallback();return this;},toArray:function toArray(array,offset){if(array===undefined)array=[];if(offset===undefined)offset=0;array[offset]=this._x;array[offset+1]=this._y;array[offset+2]=this._z;array[offset+3]=this._order;return array;},toVector3:function toVector3(optionalResult){if(optionalResult){return optionalResult.set(this._x,this._y,this._z);}else {return new Vector3(this._x,this._y,this._z);}},_onChange:function _onChange(callback){this._onChangeCallback=callback;return this;},_onChangeCallback:function _onChangeCallback(){}}); |
534 |
|
535 | function Layers(){this.mask=1|0;}_extends(Layers.prototype,{set:function set(channel){this.mask=1<<channel|0;},enable:function enable(channel){this.mask|=1<<channel|0;},enableAll:function enableAll(){this.mask=0xffffffff|0;},toggle:function toggle(channel){this.mask^=1<<channel|0;},disable:function disable(channel){this.mask&=~(1<<channel|0);},disableAll:function disableAll(){this.mask=0;},test:function test(layers){return (this.mask&layers.mask)!==0;}});var _object3DId=0;var _v1$1=new Vector3();var _q1=new Quaternion();var _m1$1=new Matrix4();var _target=new Vector3();var _position=new Vector3();var _scale=new Vector3();var _quaternion$2=new Quaternion();var _xAxis=new Vector3(1,0,0);var _yAxis=new Vector3(0,1,0);var _zAxis=new Vector3(0,0,1);var _addedEvent={type:'added'};var _removedEvent={type:'removed'}; |
536 |
|
537 |
|
538 |
|
539 |
|
540 |
|
541 | function Object3D(){Object.defineProperty(this,'id',{value:_object3DId++});this.uuid=MathUtils.generateUUID();this.name='';this.type='Object3D';this.parent=null;this.children=[];this.up=Object3D.DefaultUp.clone();var position=new Vector3();var rotation=new Euler();var quaternion=new Quaternion();var scale=new Vector3(1,1,1);function onRotationChange(){quaternion.setFromEuler(rotation,false);}function onQuaternionChange(){rotation.setFromQuaternion(quaternion,undefined,false);}rotation._onChange(onRotationChange);quaternion._onChange(onQuaternionChange);Object.defineProperties(this,{position:{configurable:true,enumerable:true,value:position},rotation:{configurable:true,enumerable:true,value:rotation},quaternion:{configurable:true,enumerable:true,value:quaternion},scale:{configurable:true,enumerable:true,value:scale},modelViewMatrix:{value:new Matrix4()},normalMatrix:{value:new Matrix3()}});this.matrix=new Matrix4();this.matrixWorld=new Matrix4();this.matrixAutoUpdate=Object3D.DefaultMatrixAutoUpdate;this.matrixWorldNeedsUpdate=false;this.layers=new Layers();this.visible=true;this.castShadow=false;this.receiveShadow=false;this.frustumCulled=true;this.renderOrder=0;this.userData={};}Object3D.DefaultUp=new Vector3(0,1,0);Object3D.DefaultMatrixAutoUpdate=true;Object3D.prototype=_extends(Object.create(EventDispatcher.prototype),{constructor:Object3D,isObject3D:true,onBeforeRender:function onBeforeRender(){},onAfterRender:function onAfterRender(){},applyMatrix4:function applyMatrix4(matrix){if(this.matrixAutoUpdate)this.updateMatrix();this.matrix.premultiply(matrix);this.matrix.decompose(this.position,this.quaternion,this.scale);},applyQuaternion:function applyQuaternion(q){this.quaternion.premultiply(q);return this;},setRotationFromAxisAngle:function setRotationFromAxisAngle(axis,angle){
|
542 | this.quaternion.setFromAxisAngle(axis,angle);},setRotationFromEuler:function setRotationFromEuler(euler){this.quaternion.setFromEuler(euler,true);},setRotationFromMatrix:function setRotationFromMatrix(m){
|
543 | this.quaternion.setFromRotationMatrix(m);},setRotationFromQuaternion:function setRotationFromQuaternion(q){
|
544 | this.quaternion.copy(q);},rotateOnAxis:function rotateOnAxis(axis,angle){
|
545 |
|
546 | _q1.setFromAxisAngle(axis,angle);this.quaternion.multiply(_q1);return this;},rotateOnWorldAxis:function rotateOnWorldAxis(axis,angle){
|
547 |
|
548 |
|
549 | _q1.setFromAxisAngle(axis,angle);this.quaternion.premultiply(_q1);return this;},rotateX:function rotateX(angle){return this.rotateOnAxis(_xAxis,angle);},rotateY:function rotateY(angle){return this.rotateOnAxis(_yAxis,angle);},rotateZ:function rotateZ(angle){return this.rotateOnAxis(_zAxis,angle);},translateOnAxis:function translateOnAxis(axis,distance){
|
550 |
|
551 | _v1$1.copy(axis).applyQuaternion(this.quaternion);this.position.add(_v1$1.multiplyScalar(distance));return this;},translateX:function translateX(distance){return this.translateOnAxis(_xAxis,distance);},translateY:function translateY(distance){return this.translateOnAxis(_yAxis,distance);},translateZ:function translateZ(distance){return this.translateOnAxis(_zAxis,distance);},localToWorld:function localToWorld(vector){return vector.applyMatrix4(this.matrixWorld);},worldToLocal:function worldToLocal(vector){return vector.applyMatrix4(_m1$1.getInverse(this.matrixWorld));},lookAt:function lookAt(x,y,z){
|
552 | if(x.isVector3){_target.copy(x);}else {_target.set(x,y,z);}var parent=this.parent;this.updateWorldMatrix(true,false);_position.setFromMatrixPosition(this.matrixWorld);if(this.isCamera||this.isLight){_m1$1.lookAt(_position,_target,this.up);}else {_m1$1.lookAt(_target,_position,this.up);}this.quaternion.setFromRotationMatrix(_m1$1);if(parent){_m1$1.extractRotation(parent.matrixWorld);_q1.setFromRotationMatrix(_m1$1);this.quaternion.premultiply(_q1.inverse());}},add:function add(object){if(arguments.length>1){for(var i=0;i<arguments.length;i++){this.add(arguments[i]);}return this;}if(object===this){console.error("THREE.Object3D.add: object can't be added as a child of itself.",object);return this;}if(object&&object.isObject3D){if(object.parent!==null){object.parent.remove(object);}object.parent=this;this.children.push(object);object.dispatchEvent(_addedEvent);}else {console.error("THREE.Object3D.add: object not an instance of THREE.Object3D.",object);}return this;},remove:function remove(object){if(arguments.length>1){for(var i=0;i<arguments.length;i++){this.remove(arguments[i]);}return this;}var index=this.children.indexOf(object);if(index!==-1){object.parent=null;this.children.splice(index,1);object.dispatchEvent(_removedEvent);}return this;},attach:function attach(object){
|
553 | this.updateWorldMatrix(true,false);_m1$1.getInverse(this.matrixWorld);if(object.parent!==null){object.parent.updateWorldMatrix(true,false);_m1$1.multiply(object.parent.matrixWorld);}object.applyMatrix4(_m1$1);object.updateWorldMatrix(false,false);this.add(object);return this;},getObjectById:function getObjectById(id){return this.getObjectByProperty('id',id);},getObjectByName:function getObjectByName(name){return this.getObjectByProperty('name',name);},getObjectByProperty:function getObjectByProperty(name,value){if(this[name]===value)return this;for(var i=0,l=this.children.length;i<l;i++){var child=this.children[i];var object=child.getObjectByProperty(name,value);if(object!==undefined){return object;}}return undefined;},getWorldPosition:function getWorldPosition(target){if(target===undefined){console.warn('THREE.Object3D: .getWorldPosition() target is now required');target=new Vector3();}this.updateMatrixWorld(true);return target.setFromMatrixPosition(this.matrixWorld);},getWorldQuaternion:function getWorldQuaternion(target){if(target===undefined){console.warn('THREE.Object3D: .getWorldQuaternion() target is now required');target=new Quaternion();}this.updateMatrixWorld(true);this.matrixWorld.decompose(_position,target,_scale);return target;},getWorldScale:function getWorldScale(target){if(target===undefined){console.warn('THREE.Object3D: .getWorldScale() target is now required');target=new Vector3();}this.updateMatrixWorld(true);this.matrixWorld.decompose(_position,_quaternion$2,target);return target;},getWorldDirection:function getWorldDirection(target){if(target===undefined){console.warn('THREE.Object3D: .getWorldDirection() target is now required');target=new Vector3();}this.updateMatrixWorld(true);var e=this.matrixWorld.elements;return target.set(e[8],e[9],e[10]).normalize();},raycast:function raycast(){},traverse:function traverse(callback){callback(this);var children=this.children;for(var i=0,l=children.length;i<l;i++){children[i].traverse(callback);}},traverseVisible:function traverseVisible(callback){if(this.visible===false)return;callback(this);var children=this.children;for(var i=0,l=children.length;i<l;i++){children[i].traverseVisible(callback);}},traverseAncestors:function traverseAncestors(callback){var parent=this.parent;if(parent!==null){callback(parent);parent.traverseAncestors(callback);}},updateMatrix:function updateMatrix(){this.matrix.compose(this.position,this.quaternion,this.scale);this.matrixWorldNeedsUpdate=true;},updateMatrixWorld:function updateMatrixWorld(force){if(this.matrixAutoUpdate)this.updateMatrix();if(this.matrixWorldNeedsUpdate||force){if(this.parent===null){this.matrixWorld.copy(this.matrix);}else {this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix);}this.matrixWorldNeedsUpdate=false;force=true;}
|
554 | var children=this.children;for(var i=0,l=children.length;i<l;i++){children[i].updateMatrixWorld(force);}},updateWorldMatrix:function updateWorldMatrix(updateParents,updateChildren){var parent=this.parent;if(updateParents===true&&parent!==null){parent.updateWorldMatrix(true,false);}if(this.matrixAutoUpdate)this.updateMatrix();if(this.parent===null){this.matrixWorld.copy(this.matrix);}else {this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix);}
|
555 | if(updateChildren===true){var children=this.children;for(var i=0,l=children.length;i<l;i++){children[i].updateWorldMatrix(false,true);}}},toJSON:function toJSON(meta){
|
556 | var isRootObject=meta===undefined||typeof meta==='string';var output={};
|
557 |
|
558 |
|
559 | if(isRootObject){
|
560 | meta={geometries:{},materials:{},textures:{},images:{},shapes:{}};output.metadata={version:4.5,type:'Object',generator:'Object3D.toJSON'};}
|
561 | var object={};object.uuid=this.uuid;object.type=this.type;if(this.name!=='')object.name=this.name;if(this.castShadow===true)object.castShadow=true;if(this.receiveShadow===true)object.receiveShadow=true;if(this.visible===false)object.visible=false;if(this.frustumCulled===false)object.frustumCulled=false;if(this.renderOrder!==0)object.renderOrder=this.renderOrder;if(JSON.stringify(this.userData)!=='{}')object.userData=this.userData;object.layers=this.layers.mask;object.matrix=this.matrix.toArray();if(this.matrixAutoUpdate===false)object.matrixAutoUpdate=false;
|
562 | if(this.isInstancedMesh){object.type='InstancedMesh';object.count=this.count;object.instanceMatrix=this.instanceMatrix.toJSON();}
|
563 | function serialize(library,element){if(library[element.uuid]===undefined){library[element.uuid]=element.toJSON(meta);}return element.uuid;}if(this.isMesh||this.isLine||this.isPoints){object.geometry=serialize(meta.geometries,this.geometry);var parameters=this.geometry.parameters;if(parameters!==undefined&¶meters.shapes!==undefined){var shapes=parameters.shapes;if(Array.isArray(shapes)){for(var i=0,l=shapes.length;i<l;i++){var shape=shapes[i];serialize(meta.shapes,shape);}}else {serialize(meta.shapes,shapes);}}}if(this.material!==undefined){if(Array.isArray(this.material)){var uuids=[];for(var i=0,l=this.material.length;i<l;i++){uuids.push(serialize(meta.materials,this.material[i]));}object.material=uuids;}else {object.material=serialize(meta.materials,this.material);}}
|
564 | if(this.children.length>0){object.children=[];for(var i=0;i<this.children.length;i++){object.children.push(this.children[i].toJSON(meta).object);}}if(isRootObject){var geometries=extractFromCache(meta.geometries);var materials=extractFromCache(meta.materials);var textures=extractFromCache(meta.textures);var images=extractFromCache(meta.images);var shapes=extractFromCache(meta.shapes);if(geometries.length>0)output.geometries=geometries;if(materials.length>0)output.materials=materials;if(textures.length>0)output.textures=textures;if(images.length>0)output.images=images;if(shapes.length>0)output.shapes=shapes;}output.object=object;return output;
|
565 |
|
566 |
|
567 | function extractFromCache(cache){var values=[];for(var key in cache){var data=cache[key];delete data.metadata;values.push(data);}return values;}},clone:function clone(recursive){return new this.constructor().copy(this,recursive);},copy:function copy(source,recursive){if(recursive===undefined)recursive=true;this.name=source.name;this.up.copy(source.up);this.position.copy(source.position);this.quaternion.copy(source.quaternion);this.scale.copy(source.scale);this.matrix.copy(source.matrix);this.matrixWorld.copy(source.matrixWorld);this.matrixAutoUpdate=source.matrixAutoUpdate;this.matrixWorldNeedsUpdate=source.matrixWorldNeedsUpdate;this.layers.mask=source.layers.mask;this.visible=source.visible;this.castShadow=source.castShadow;this.receiveShadow=source.receiveShadow;this.frustumCulled=source.frustumCulled;this.renderOrder=source.renderOrder;this.userData=JSON.parse(JSON.stringify(source.userData));if(recursive===true){for(var i=0;i<source.children.length;i++){var child=source.children[i];this.add(child.clone());}}return this;}}); |
568 |
|
569 | function Scene(){Object3D.call(this);this.type='Scene';this.background=null;this.environment=null;this.fog=null;this.overrideMaterial=null;this.autoUpdate=true;
|
570 | if(typeof __THREE_DEVTOOLS__!=='undefined'){__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('observe',{detail:this}));
|
571 | }}Scene.prototype=_extends(Object.create(Object3D.prototype),{constructor:Scene,isScene:true,copy:function copy(source,recursive){Object3D.prototype.copy.call(this,source,recursive);if(source.background!==null)this.background=source.background.clone();if(source.environment!==null)this.environment=source.environment.clone();if(source.fog!==null)this.fog=source.fog.clone();if(source.overrideMaterial!==null)this.overrideMaterial=source.overrideMaterial.clone();this.autoUpdate=source.autoUpdate;this.matrixAutoUpdate=source.matrixAutoUpdate;return this;},toJSON:function toJSON(meta){var data=Object3D.prototype.toJSON.call(this,meta);if(this.background!==null)data.object.background=this.background.toJSON(meta);if(this.environment!==null)data.object.environment=this.environment.toJSON(meta);if(this.fog!==null)data.object.fog=this.fog.toJSON();return data;},dispose:function dispose(){this.dispatchEvent({type:'dispose'});}});var _points=[new Vector3(),new Vector3(),new Vector3(),new Vector3(),new Vector3(),new Vector3(),new Vector3(),new Vector3()];var _vector$1=new Vector3();var _box=new Box3();
|
572 | var _v0=new Vector3();var _v1$2=new Vector3();var _v2=new Vector3();
|
573 | var _f0=new Vector3();var _f1=new Vector3();var _f2=new Vector3();var _center=new Vector3();var _extents=new Vector3();var _triangleNormal=new Vector3();var _testAxis=new Vector3(); |
574 |
|
575 |
|
576 | function Box3(min,max){this.min=min!==undefined?min:new Vector3(+Infinity,+Infinity,+Infinity);this.max=max!==undefined?max:new Vector3(-Infinity,-Infinity,-Infinity);}_extends(Box3.prototype,{isBox3:true,set:function set(min,max){this.min.copy(min);this.max.copy(max);return this;},setFromArray:function setFromArray(array){var minX=+Infinity;var minY=+Infinity;var minZ=+Infinity;var maxX=-Infinity;var maxY=-Infinity;var maxZ=-Infinity;for(var i=0,l=array.length;i<l;i+=3){var x=array[i];var y=array[i+1];var z=array[i+2];if(x<minX)minX=x;if(y<minY)minY=y;if(z<minZ)minZ=z;if(x>maxX)maxX=x;if(y>maxY)maxY=y;if(z>maxZ)maxZ=z;}this.min.set(minX,minY,minZ);this.max.set(maxX,maxY,maxZ);return this;},setFromBufferAttribute:function setFromBufferAttribute(attribute){var minX=+Infinity;var minY=+Infinity;var minZ=+Infinity;var maxX=-Infinity;var maxY=-Infinity;var maxZ=-Infinity;for(var i=0,l=attribute.count;i<l;i++){var x=attribute.getX(i);var y=attribute.getY(i);var z=attribute.getZ(i);if(x<minX)minX=x;if(y<minY)minY=y;if(z<minZ)minZ=z;if(x>maxX)maxX=x;if(y>maxY)maxY=y;if(z>maxZ)maxZ=z;}this.min.set(minX,minY,minZ);this.max.set(maxX,maxY,maxZ);return this;},setFromPoints:function setFromPoints(points){this.makeEmpty();for(var i=0,il=points.length;i<il;i++){this.expandByPoint(points[i]);}return this;},setFromCenterAndSize:function setFromCenterAndSize(center,size){var halfSize=_vector$1.copy(size).multiplyScalar(0.5);this.min.copy(center).sub(halfSize);this.max.copy(center).add(halfSize);return this;},setFromObject:function setFromObject(object){this.makeEmpty();return this.expandByObject(object);},clone:function clone(){return new this.constructor().copy(this);},copy:function copy(box){this.min.copy(box.min);this.max.copy(box.max);return this;},makeEmpty:function makeEmpty(){this.min.x=this.min.y=this.min.z=+Infinity;this.max.x=this.max.y=this.max.z=-Infinity;return this;},isEmpty:function isEmpty(){
|
577 | return this.max.x<this.min.x||this.max.y<this.min.y||this.max.z<this.min.z;},getCenter:function getCenter(target){if(target===undefined){console.warn('THREE.Box3: .getCenter() target is now required');target=new Vector3();}return this.isEmpty()?target.set(0,0,0):target.addVectors(this.min,this.max).multiplyScalar(0.5);},getSize:function getSize(target){if(target===undefined){console.warn('THREE.Box3: .getSize() target is now required');target=new Vector3();}return this.isEmpty()?target.set(0,0,0):target.subVectors(this.max,this.min);},expandByPoint:function expandByPoint(point){this.min.min(point);this.max.max(point);return this;},expandByVector:function expandByVector(vector){this.min.sub(vector);this.max.add(vector);return this;},expandByScalar:function expandByScalar(scalar){this.min.addScalar(-scalar);this.max.addScalar(scalar);return this;},expandByObject:function expandByObject(object){
|
578 |
|
579 | object.updateWorldMatrix(false,false);var geometry=object.geometry;if(geometry!==undefined){if(geometry.boundingBox===null){geometry.computeBoundingBox();}_box.copy(geometry.boundingBox);_box.applyMatrix4(object.matrixWorld);this.union(_box);}var children=object.children;for(var i=0,l=children.length;i<l;i++){this.expandByObject(children[i]);}return this;},containsPoint:function containsPoint(point){return point.x<this.min.x||point.x>this.max.x||point.y<this.min.y||point.y>this.max.y||point.z<this.min.z||point.z>this.max.z?false:true;},containsBox:function containsBox(box){return this.min.x<=box.min.x&&box.max.x<=this.max.x&&this.min.y<=box.min.y&&box.max.y<=this.max.y&&this.min.z<=box.min.z&&box.max.z<=this.max.z;},getParameter:function getParameter(point,target){
|
580 |
|
581 | if(target===undefined){console.warn('THREE.Box3: .getParameter() target is now required');target=new Vector3();}return target.set((point.x-this.min.x)/(this.max.x-this.min.x),(point.y-this.min.y)/(this.max.y-this.min.y),(point.z-this.min.z)/(this.max.z-this.min.z));},intersectsBox:function intersectsBox(box){
|
582 | return box.max.x<this.min.x||box.min.x>this.max.x||box.max.y<this.min.y||box.min.y>this.max.y||box.max.z<this.min.z||box.min.z>this.max.z?false:true;},intersectsSphere:function intersectsSphere(sphere){
|
583 | this.clampPoint(sphere.center,_vector$1);
|
584 | return _vector$1.distanceToSquared(sphere.center)<=sphere.radius*sphere.radius;},intersectsPlane:function intersectsPlane(plane){
|
585 |
|
586 | var min,max;if(plane.normal.x>0){min=plane.normal.x*this.min.x;max=plane.normal.x*this.max.x;}else {min=plane.normal.x*this.max.x;max=plane.normal.x*this.min.x;}if(plane.normal.y>0){min+=plane.normal.y*this.min.y;max+=plane.normal.y*this.max.y;}else {min+=plane.normal.y*this.max.y;max+=plane.normal.y*this.min.y;}if(plane.normal.z>0){min+=plane.normal.z*this.min.z;max+=plane.normal.z*this.max.z;}else {min+=plane.normal.z*this.max.z;max+=plane.normal.z*this.min.z;}return min<=-plane.constant&&max>=-plane.constant;},intersectsTriangle:function intersectsTriangle(triangle){if(this.isEmpty()){return false;}
|
587 | this.getCenter(_center);_extents.subVectors(this.max,_center);
|
588 | _v0.subVectors(triangle.a,_center);_v1$2.subVectors(triangle.b,_center);_v2.subVectors(triangle.c,_center);
|
589 | _f0.subVectors(_v1$2,_v0);_f1.subVectors(_v2,_v1$2);_f2.subVectors(_v0,_v2);
|
590 |
|
591 |
|
592 | var axes=[0,-_f0.z,_f0.y,0,-_f1.z,_f1.y,0,-_f2.z,_f2.y,_f0.z,0,-_f0.x,_f1.z,0,-_f1.x,_f2.z,0,-_f2.x,-_f0.y,_f0.x,0,-_f1.y,_f1.x,0,-_f2.y,_f2.x,0];if(!satForAxes(axes,_v0,_v1$2,_v2,_extents)){return false;}
|
593 | axes=[1,0,0,0,1,0,0,0,1];if(!satForAxes(axes,_v0,_v1$2,_v2,_extents)){return false;}
|
594 |
|
595 | _triangleNormal.crossVectors(_f0,_f1);axes=[_triangleNormal.x,_triangleNormal.y,_triangleNormal.z];return satForAxes(axes,_v0,_v1$2,_v2,_extents);},clampPoint:function clampPoint(point,target){if(target===undefined){console.warn('THREE.Box3: .clampPoint() target is now required');target=new Vector3();}return target.copy(point).clamp(this.min,this.max);},distanceToPoint:function distanceToPoint(point){var clampedPoint=_vector$1.copy(point).clamp(this.min,this.max);return clampedPoint.sub(point).length();},getBoundingSphere:function getBoundingSphere(target){if(target===undefined){console.error('THREE.Box3: .getBoundingSphere() target is now required');
|
596 | }this.getCenter(target.center);target.radius=this.getSize(_vector$1).length()*0.5;return target;},intersect:function intersect(box){this.min.max(box.min);this.max.min(box.max);
|
597 | if(this.isEmpty())this.makeEmpty();return this;},union:function union(box){this.min.min(box.min);this.max.max(box.max);return this;},applyMatrix4:function applyMatrix4(matrix){
|
598 | if(this.isEmpty())return this;
|
599 | _points[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(matrix);
|
600 | _points[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(matrix);
|
601 | _points[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(matrix);
|
602 | _points[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(matrix);
|
603 | _points[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(matrix);
|
604 | _points[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(matrix);
|
605 | _points[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(matrix);
|
606 | _points[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(matrix);
|
607 | this.setFromPoints(_points);return this;},translate:function translate(offset){this.min.add(offset);this.max.add(offset);return this;},equals:function equals(box){return box.min.equals(this.min)&&box.max.equals(this.max);}});function satForAxes(axes,v0,v1,v2,extents){var i,j;for(i=0,j=axes.length-3;i<=j;i+=3){_testAxis.fromArray(axes,i);
|
608 | var r=extents.x*Math.abs(_testAxis.x)+extents.y*Math.abs(_testAxis.y)+extents.z*Math.abs(_testAxis.z);
|
609 | var p0=v0.dot(_testAxis);var p1=v1.dot(_testAxis);var p2=v2.dot(_testAxis);
|
610 | if(Math.max(-Math.max(p0,p1,p2),Math.min(p0,p1,p2))>r){
|
611 |
|
612 | return false;}}return true;}var _box$1=new Box3(); |
613 |
|
614 |
|
615 | function Sphere(center,radius){this.center=center!==undefined?center:new Vector3();this.radius=radius!==undefined?radius:-1;}_extends(Sphere.prototype,{set:function set(center,radius){this.center.copy(center);this.radius=radius;return this;},setFromPoints:function setFromPoints(points,optionalCenter){var center=this.center;if(optionalCenter!==undefined){center.copy(optionalCenter);}else {_box$1.setFromPoints(points).getCenter(center);}var maxRadiusSq=0;for(var i=0,il=points.length;i<il;i++){maxRadiusSq=Math.max(maxRadiusSq,center.distanceToSquared(points[i]));}this.radius=Math.sqrt(maxRadiusSq);return this;},clone:function clone(){return new this.constructor().copy(this);},copy:function copy(sphere){this.center.copy(sphere.center);this.radius=sphere.radius;return this;},isEmpty:function isEmpty(){return this.radius<0;},makeEmpty:function makeEmpty(){this.center.set(0,0,0);this.radius=-1;return this;},containsPoint:function containsPoint(point){return point.distanceToSquared(this.center)<=this.radius*this.radius;},distanceToPoint:function distanceToPoint(point){return point.distanceTo(this.center)-this.radius;},intersectsSphere:function intersectsSphere(sphere){var radiusSum=this.radius+sphere.radius;return sphere.center.distanceToSquared(this.center)<=radiusSum*radiusSum;},intersectsBox:function intersectsBox(box){return box.intersectsSphere(this);},intersectsPlane:function intersectsPlane(plane){return Math.abs(plane.distanceToPoint(this.center))<=this.radius;},clampPoint:function clampPoint(point,target){var deltaLengthSq=this.center.distanceToSquared(point);if(target===undefined){console.warn('THREE.Sphere: .clampPoint() target is now required');target=new Vector3();}target.copy(point);if(deltaLengthSq>this.radius*this.radius){target.sub(this.center).normalize();target.multiplyScalar(this.radius).add(this.center);}return target;},getBoundingBox:function getBoundingBox(target){if(target===undefined){console.warn('THREE.Sphere: .getBoundingBox() target is now required');target=new Box3();}if(this.isEmpty()){
|
616 | target.makeEmpty();return target;}target.set(this.center,this.center);target.expandByScalar(this.radius);return target;},applyMatrix4:function applyMatrix4(matrix){this.center.applyMatrix4(matrix);this.radius=this.radius*matrix.getMaxScaleOnAxis();return this;},translate:function translate(offset){this.center.add(offset);return this;},equals:function equals(sphere){return sphere.center.equals(this.center)&&sphere.radius===this.radius;}});var _vector$2=new Vector3();var _segCenter=new Vector3();var _segDir=new Vector3();var _diff=new Vector3();var _edge1=new Vector3();var _edge2=new Vector3();var _normal=new Vector3(); |
617 |
|
618 | function Ray(origin,direction){this.origin=origin!==undefined?origin:new Vector3();this.direction=direction!==undefined?direction:new Vector3(0,0,-1);}_extends(Ray.prototype,{set:function set(origin,direction){this.origin.copy(origin);this.direction.copy(direction);return this;},clone:function clone(){return new this.constructor().copy(this);},copy:function copy(ray){this.origin.copy(ray.origin);this.direction.copy(ray.direction);return this;},at:function at(t,target){if(target===undefined){console.warn('THREE.Ray: .at() target is now required');target=new Vector3();}return target.copy(this.direction).multiplyScalar(t).add(this.origin);},lookAt:function lookAt(v){this.direction.copy(v).sub(this.origin).normalize();return this;},recast:function recast(t){this.origin.copy(this.at(t,_vector$2));return this;},closestPointToPoint:function closestPointToPoint(point,target){if(target===undefined){console.warn('THREE.Ray: .closestPointToPoint() target is now required');target=new Vector3();}target.subVectors(point,this.origin);var directionDistance=target.dot(this.direction);if(directionDistance<0){return target.copy(this.origin);}return target.copy(this.direction).multiplyScalar(directionDistance).add(this.origin);},distanceToPoint:function distanceToPoint(point){return Math.sqrt(this.distanceSqToPoint(point));},distanceSqToPoint:function distanceSqToPoint(point){var directionDistance=_vector$2.subVectors(point,this.origin).dot(this.direction);
|
619 | if(directionDistance<0){return this.origin.distanceToSquared(point);}_vector$2.copy(this.direction).multiplyScalar(directionDistance).add(this.origin);return _vector$2.distanceToSquared(point);},distanceSqToSegment:function distanceSqToSegment(v0,v1,optionalPointOnRay,optionalPointOnSegment){
|
620 |
|
621 |
|
622 |
|
623 |
|
624 |
|
625 | _segCenter.copy(v0).add(v1).multiplyScalar(0.5);_segDir.copy(v1).sub(v0).normalize();_diff.copy(this.origin).sub(_segCenter);var segExtent=v0.distanceTo(v1)*0.5;var a01=-this.direction.dot(_segDir);var b0=_diff.dot(this.direction);var b1=-_diff.dot(_segDir);var c=_diff.lengthSq();var det=Math.abs(1-a01*a01);var s0,s1,sqrDist,extDet;if(det>0){
|
626 | s0=a01*b1-b0;s1=a01*b0-b1;extDet=segExtent*det;if(s0>=0){if(s1>=-extDet){if(s1<=extDet){
|
627 |
|
628 | var invDet=1/det;s0*=invDet;s1*=invDet;sqrDist=s0*(s0+a01*s1+2*b0)+s1*(a01*s0+s1+2*b1)+c;}else {
|
629 | s1=segExtent;s0=Math.max(0,-(a01*s1+b0));sqrDist=-s0*s0+s1*(s1+2*b1)+c;}}else {
|
630 | s1=-segExtent;s0=Math.max(0,-(a01*s1+b0));sqrDist=-s0*s0+s1*(s1+2*b1)+c;}}else {if(s1<=-extDet){
|
631 | s0=Math.max(0,-(-a01*segExtent+b0));s1=s0>0?-segExtent:Math.min(Math.max(-segExtent,-b1),segExtent);sqrDist=-s0*s0+s1*(s1+2*b1)+c;}else if(s1<=extDet){
|
632 | s0=0;s1=Math.min(Math.max(-segExtent,-b1),segExtent);sqrDist=s1*(s1+2*b1)+c;}else {
|
633 | s0=Math.max(0,-(a01*segExtent+b0));s1=s0>0?segExtent:Math.min(Math.max(-segExtent,-b1),segExtent);sqrDist=-s0*s0+s1*(s1+2*b1)+c;}}}else {
|
634 | s1=a01>0?-segExtent:segExtent;s0=Math.max(0,-(a01*s1+b0));sqrDist=-s0*s0+s1*(s1+2*b1)+c;}if(optionalPointOnRay){optionalPointOnRay.copy(this.direction).multiplyScalar(s0).add(this.origin);}if(optionalPointOnSegment){optionalPointOnSegment.copy(_segDir).multiplyScalar(s1).add(_segCenter);}return sqrDist;},intersectSphere:function intersectSphere(sphere,target){_vector$2.subVectors(sphere.center,this.origin);var tca=_vector$2.dot(this.direction);var d2=_vector$2.dot(_vector$2)-tca*tca;var radius2=sphere.radius*sphere.radius;if(d2>radius2)return null;var thc=Math.sqrt(radius2-d2);
|
635 | var t0=tca-thc;
|
636 | var t1=tca+thc;
|
637 | if(t0<0&&t1<0)return null;
|
638 |
|
639 |
|
640 | if(t0<0)return this.at(t1,target);
|
641 | return this.at(t0,target);},intersectsSphere:function intersectsSphere(sphere){return this.distanceSqToPoint(sphere.center)<=sphere.radius*sphere.radius;},distanceToPlane:function distanceToPlane(plane){var denominator=plane.normal.dot(this.direction);if(denominator===0){
|
642 | if(plane.distanceToPoint(this.origin)===0){return 0;}
|
643 | return null;}var t=-(this.origin.dot(plane.normal)+plane.constant)/denominator;
|
644 | return t>=0?t:null;},intersectPlane:function intersectPlane(plane,target){var t=this.distanceToPlane(plane);if(t===null){return null;}return this.at(t,target);},intersectsPlane:function intersectsPlane(plane){
|
645 | var distToPoint=plane.distanceToPoint(this.origin);if(distToPoint===0){return true;}var denominator=plane.normal.dot(this.direction);if(denominator*distToPoint<0){return true;}
|
646 | return false;},intersectBox:function intersectBox(box,target){var tmin,tmax,tymin,tymax,tzmin,tzmax;var invdirx=1/this.direction.x,invdiry=1/this.direction.y,invdirz=1/this.direction.z;var origin=this.origin;if(invdirx>=0){tmin=(box.min.x-origin.x)*invdirx;tmax=(box.max.x-origin.x)*invdirx;}else {tmin=(box.max.x-origin.x)*invdirx;tmax=(box.min.x-origin.x)*invdirx;}if(invdiry>=0){tymin=(box.min.y-origin.y)*invdiry;tymax=(box.max.y-origin.y)*invdiry;}else {tymin=(box.max.y-origin.y)*invdiry;tymax=(box.min.y-origin.y)*invdiry;}if(tmin>tymax||tymin>tmax)return null;
|
647 |
|
648 | if(tymin>tmin||tmin!==tmin)tmin=tymin;if(tymax<tmax||tmax!==tmax)tmax=tymax;if(invdirz>=0){tzmin=(box.min.z-origin.z)*invdirz;tzmax=(box.max.z-origin.z)*invdirz;}else {tzmin=(box.max.z-origin.z)*invdirz;tzmax=(box.min.z-origin.z)*invdirz;}if(tmin>tzmax||tzmin>tmax)return null;if(tzmin>tmin||tmin!==tmin)tmin=tzmin;if(tzmax<tmax||tmax!==tmax)tmax=tzmax;
|
649 | if(tmax<0)return null;return this.at(tmin>=0?tmin:tmax,target);},intersectsBox:function intersectsBox(box){return this.intersectBox(box,_vector$2)!==null;},intersectTriangle:function intersectTriangle(a,b,c,backfaceCulling,target){
|
650 |
|
651 | _edge1.subVectors(b,a);_edge2.subVectors(c,a);_normal.crossVectors(_edge1,_edge2);
|
652 |
|
653 |
|
654 |
|
655 |
|
656 | var DdN=this.direction.dot(_normal);var sign;if(DdN>0){if(backfaceCulling)return null;sign=1;}else if(DdN<0){sign=-1;DdN=-DdN;}else {return null;}_diff.subVectors(this.origin,a);var DdQxE2=sign*this.direction.dot(_edge2.crossVectors(_diff,_edge2));
|
657 | if(DdQxE2<0){return null;}var DdE1xQ=sign*this.direction.dot(_edge1.cross(_diff));
|
658 | if(DdE1xQ<0){return null;}
|
659 | if(DdQxE2+DdE1xQ>DdN){return null;}
|
660 | var QdN=-sign*_diff.dot(_normal);
|
661 | if(QdN<0){return null;}
|
662 | return this.at(QdN/DdN,target);},applyMatrix4:function applyMatrix4(matrix4){this.origin.applyMatrix4(matrix4);this.direction.transformDirection(matrix4);return this;},equals:function equals(ray){return ray.origin.equals(this.origin)&&ray.direction.equals(this.direction);}}); |
663 |
|
664 | var _vector1=new Vector3();var _vector2=new Vector3();var _normalMatrix=new Matrix3();function Plane(normal,constant){
|
665 | this.normal=normal!==undefined?normal:new Vector3(1,0,0);this.constant=constant!==undefined?constant:0;}_extends(Plane.prototype,{isPlane:true,set:function set(normal,constant){this.normal.copy(normal);this.constant=constant;return this;},setComponents:function setComponents(x,y,z,w){this.normal.set(x,y,z);this.constant=w;return this;},setFromNormalAndCoplanarPoint:function setFromNormalAndCoplanarPoint(normal,point){this.normal.copy(normal);this.constant=-point.dot(this.normal);return this;},setFromCoplanarPoints:function setFromCoplanarPoints(a,b,c){var normal=_vector1.subVectors(c,b).cross(_vector2.subVectors(a,b)).normalize();
|
666 | this.setFromNormalAndCoplanarPoint(normal,a);return this;},clone:function clone(){return new this.constructor().copy(this);},copy:function copy(plane){this.normal.copy(plane.normal);this.constant=plane.constant;return this;},normalize:function normalize(){
|
667 | var inverseNormalLength=1.0/this.normal.length();this.normal.multiplyScalar(inverseNormalLength);this.constant*=inverseNormalLength;return this;},negate:function negate(){this.constant*=-1;this.normal.negate();return this;},distanceToPoint:function distanceToPoint(point){return this.normal.dot(point)+this.constant;},distanceToSphere:function distanceToSphere(sphere){return this.distanceToPoint(sphere.center)-sphere.radius;},projectPoint:function projectPoint(point,target){if(target===undefined){console.warn('THREE.Plane: .projectPoint() target is now required');target=new Vector3();}return target.copy(this.normal).multiplyScalar(-this.distanceToPoint(point)).add(point);},intersectLine:function intersectLine(line,target){if(target===undefined){console.warn('THREE.Plane: .intersectLine() target is now required');target=new Vector3();}var direction=line.delta(_vector1);var denominator=this.normal.dot(direction);if(denominator===0){
|
668 | if(this.distanceToPoint(line.start)===0){return target.copy(line.start);}
|
669 | return undefined;}var t=-(line.start.dot(this.normal)+this.constant)/denominator;if(t<0||t>1){return undefined;}return target.copy(direction).multiplyScalar(t).add(line.start);},intersectsLine:function intersectsLine(line){
|
670 | var startSign=this.distanceToPoint(line.start);var endSign=this.distanceToPoint(line.end);return startSign<0&&endSign>0||endSign<0&&startSign>0;},intersectsBox:function intersectsBox(box){return box.intersectsPlane(this);},intersectsSphere:function intersectsSphere(sphere){return sphere.intersectsPlane(this);},coplanarPoint:function coplanarPoint(target){if(target===undefined){console.warn('THREE.Plane: .coplanarPoint() target is now required');target=new Vector3();}return target.copy(this.normal).multiplyScalar(-this.constant);},applyMatrix4:function applyMatrix4(matrix,optionalNormalMatrix){var normalMatrix=optionalNormalMatrix||_normalMatrix.getNormalMatrix(matrix);var referencePoint=this.coplanarPoint(_vector1).applyMatrix4(matrix);var normal=this.normal.applyMatrix3(normalMatrix).normalize();this.constant=-referencePoint.dot(normal);return this;},translate:function translate(offset){this.constant-=offset.dot(this.normal);return this;},equals:function equals(plane){return plane.normal.equals(this.normal)&&plane.constant===this.constant;}}); |
671 |
|
672 |
|
673 | var _v0$1=new Vector3();var _v1$3=new Vector3();var _v2$1=new Vector3();var _v3=new Vector3();var _vab=new Vector3();var _vac=new Vector3();var _vbc=new Vector3();var _vap=new Vector3();var _vbp=new Vector3();var _vcp=new Vector3();function Triangle(a,b,c){this.a=a!==undefined?a:new Vector3();this.b=b!==undefined?b:new Vector3();this.c=c!==undefined?c:new Vector3();}_extends(Triangle,{getNormal:function getNormal(a,b,c,target){if(target===undefined){console.warn('THREE.Triangle: .getNormal() target is now required');target=new Vector3();}target.subVectors(c,b);_v0$1.subVectors(a,b);target.cross(_v0$1);var targetLengthSq=target.lengthSq();if(targetLengthSq>0){return target.multiplyScalar(1/Math.sqrt(targetLengthSq));}return target.set(0,0,0);},
|
674 |
|
675 | getBarycoord:function getBarycoord(point,a,b,c,target){_v0$1.subVectors(c,a);_v1$3.subVectors(b,a);_v2$1.subVectors(point,a);var dot00=_v0$1.dot(_v0$1);var dot01=_v0$1.dot(_v1$3);var dot02=_v0$1.dot(_v2$1);var dot11=_v1$3.dot(_v1$3);var dot12=_v1$3.dot(_v2$1);var denom=dot00*dot11-dot01*dot01;if(target===undefined){console.warn('THREE.Triangle: .getBarycoord() target is now required');target=new Vector3();}
|
676 | if(denom===0){
|
677 |
|
678 | return target.set(-2,-1,-1);}var invDenom=1/denom;var u=(dot11*dot02-dot01*dot12)*invDenom;var v=(dot00*dot12-dot01*dot02)*invDenom;
|
679 | return target.set(1-u-v,v,u);},containsPoint:function containsPoint(point,a,b,c){Triangle.getBarycoord(point,a,b,c,_v3);return _v3.x>=0&&_v3.y>=0&&_v3.x+_v3.y<=1;},getUV:function getUV(point,p1,p2,p3,uv1,uv2,uv3,target){this.getBarycoord(point,p1,p2,p3,_v3);target.set(0,0);target.addScaledVector(uv1,_v3.x);target.addScaledVector(uv2,_v3.y);target.addScaledVector(uv3,_v3.z);return target;},isFrontFacing:function isFrontFacing(a,b,c,direction){_v0$1.subVectors(c,b);_v1$3.subVectors(a,b);
|
680 | return _v0$1.cross(_v1$3).dot(direction)<0?true:false;}});_extends(Triangle.prototype,{set:function set(a,b,c){this.a.copy(a);this.b.copy(b);this.c.copy(c);return this;},setFromPointsAndIndices:function setFromPointsAndIndices(points,i0,i1,i2){this.a.copy(points[i0]);this.b.copy(points[i1]);this.c.copy(points[i2]);return this;},clone:function clone(){return new this.constructor().copy(this);},copy:function copy(triangle){this.a.copy(triangle.a);this.b.copy(triangle.b);this.c.copy(triangle.c);return this;},getArea:function getArea(){_v0$1.subVectors(this.c,this.b);_v1$3.subVectors(this.a,this.b);return _v0$1.cross(_v1$3).length()*0.5;},getMidpoint:function getMidpoint(target){if(target===undefined){console.warn('THREE.Triangle: .getMidpoint() target is now required');target=new Vector3();}return target.addVectors(this.a,this.b).add(this.c).multiplyScalar(1/3);},getNormal:function getNormal(target){return Triangle.getNormal(this.a,this.b,this.c,target);},getPlane:function getPlane(target){if(target===undefined){console.warn('THREE.Triangle: .getPlane() target is now required');target=new Plane();}return target.setFromCoplanarPoints(this.a,this.b,this.c);},getBarycoord:function getBarycoord(point,target){return Triangle.getBarycoord(point,this.a,this.b,this.c,target);},getUV:function getUV(point,uv1,uv2,uv3,target){return Triangle.getUV(point,this.a,this.b,this.c,uv1,uv2,uv3,target);},containsPoint:function containsPoint(point){return Triangle.containsPoint(point,this.a,this.b,this.c);},isFrontFacing:function isFrontFacing(direction){return Triangle.isFrontFacing(this.a,this.b,this.c,direction);},intersectsBox:function intersectsBox(box){return box.intersectsTriangle(this);},closestPointToPoint:function closestPointToPoint(p,target){if(target===undefined){console.warn('THREE.Triangle: .closestPointToPoint() target is now required');target=new Vector3();}var a=this.a,b=this.b,c=this.c;var v,w;
|
681 |
|
682 |
|
683 |
|
684 |
|
685 | _vab.subVectors(b,a);_vac.subVectors(c,a);_vap.subVectors(p,a);var d1=_vab.dot(_vap);var d2=_vac.dot(_vap);if(d1<=0&&d2<=0){
|
686 | return target.copy(a);}_vbp.subVectors(p,b);var d3=_vab.dot(_vbp);var d4=_vac.dot(_vbp);if(d3>=0&&d4<=d3){
|
687 | return target.copy(b);}var vc=d1*d4-d3*d2;if(vc<=0&&d1>=0&&d3<=0){v=d1/(d1-d3);
|
688 | return target.copy(a).addScaledVector(_vab,v);}_vcp.subVectors(p,c);var d5=_vab.dot(_vcp);var d6=_vac.dot(_vcp);if(d6>=0&&d5<=d6){
|
689 | return target.copy(c);}var vb=d5*d2-d1*d6;if(vb<=0&&d2>=0&&d6<=0){w=d2/(d2-d6);
|
690 | return target.copy(a).addScaledVector(_vac,w);}var va=d3*d6-d5*d4;if(va<=0&&d4-d3>=0&&d5-d6>=0){_vbc.subVectors(c,b);w=(d4-d3)/(d4-d3+(d5-d6));
|
691 | return target.copy(b).addScaledVector(_vbc,w);
|
692 | }
|
693 | var denom=1/(va+vb+vc);
|
694 | v=vb*denom;w=vc*denom;return target.copy(a).addScaledVector(_vab,v).addScaledVector(_vac,w);},equals:function equals(triangle){return triangle.a.equals(this.a)&&triangle.b.equals(this.b)&&triangle.c.equals(this.c);}}); |
695 |
|
696 | var _colorKeywords={'aliceblue':0xF0F8FF,'antiquewhite':0xFAEBD7,'aqua':0x00FFFF,'aquamarine':0x7FFFD4,'azure':0xF0FFFF,'beige':0xF5F5DC,'bisque':0xFFE4C4,'black':0x000000,'blanchedalmond':0xFFEBCD,'blue':0x0000FF,'blueviolet':0x8A2BE2,'brown':0xA52A2A,'burlywood':0xDEB887,'cadetblue':0x5F9EA0,'chartreuse':0x7FFF00,'chocolate':0xD2691E,'coral':0xFF7F50,'cornflowerblue':0x6495ED,'cornsilk':0xFFF8DC,'crimson':0xDC143C,'cyan':0x00FFFF,'darkblue':0x00008B,'darkcyan':0x008B8B,'darkgoldenrod':0xB8860B,'darkgray':0xA9A9A9,'darkgreen':0x006400,'darkgrey':0xA9A9A9,'darkkhaki':0xBDB76B,'darkmagenta':0x8B008B,'darkolivegreen':0x556B2F,'darkorange':0xFF8C00,'darkorchid':0x9932CC,'darkred':0x8B0000,'darksalmon':0xE9967A,'darkseagreen':0x8FBC8F,'darkslateblue':0x483D8B,'darkslategray':0x2F4F4F,'darkslategrey':0x2F4F4F,'darkturquoise':0x00CED1,'darkviolet':0x9400D3,'deeppink':0xFF1493,'deepskyblue':0x00BFFF,'dimgray':0x696969,'dimgrey':0x696969,'dodgerblue':0x1E90FF,'firebrick':0xB22222,'floralwhite':0xFFFAF0,'forestgreen':0x228B22,'fuchsia':0xFF00FF,'gainsboro':0xDCDCDC,'ghostwhite':0xF8F8FF,'gold':0xFFD700,'goldenrod':0xDAA520,'gray':0x808080,'green':0x008000,'greenyellow':0xADFF2F,'grey':0x808080,'honeydew':0xF0FFF0,'hotpink':0xFF69B4,'indianred':0xCD5C5C,'indigo':0x4B0082,'ivory':0xFFFFF0,'khaki':0xF0E68C,'lavender':0xE6E6FA,'lavenderblush':0xFFF0F5,'lawngreen':0x7CFC00,'lemonchiffon':0xFFFACD,'lightblue':0xADD8E6,'lightcoral':0xF08080,'lightcyan':0xE0FFFF,'lightgoldenrodyellow':0xFAFAD2,'lightgray':0xD3D3D3,'lightgreen':0x90EE90,'lightgrey':0xD3D3D3,'lightpink':0xFFB6C1,'lightsalmon':0xFFA07A,'lightseagreen':0x20B2AA,'lightskyblue':0x87CEFA,'lightslategray':0x778899,'lightslategrey':0x778899,'lightsteelblue':0xB0C4DE,'lightyellow':0xFFFFE0,'lime':0x00FF00,'limegreen':0x32CD32,'linen':0xFAF0E6,'magenta':0xFF00FF,'maroon':0x800000,'mediumaquamarine':0x66CDAA,'mediumblue':0x0000CD,'mediumorchid':0xBA55D3,'mediumpurple':0x9370DB,'mediumseagreen':0x3CB371,'mediumslateblue':0x7B68EE,'mediumspringgreen':0x00FA9A,'mediumturquoise':0x48D1CC,'mediumvioletred':0xC71585,'midnightblue':0x191970,'mintcream':0xF5FFFA,'mistyrose':0xFFE4E1,'moccasin':0xFFE4B5,'navajowhite':0xFFDEAD,'navy':0x000080,'oldlace':0xFDF5E6,'olive':0x808000,'olivedrab':0x6B8E23,'orange':0xFFA500,'orangered':0xFF4500,'orchid':0xDA70D6,'palegoldenrod':0xEEE8AA,'palegreen':0x98FB98,'paleturquoise':0xAFEEEE,'palevioletred':0xDB7093,'papayawhip':0xFFEFD5,'peachpuff':0xFFDAB9,'peru':0xCD853F,'pink':0xFFC0CB,'plum':0xDDA0DD,'powderblue':0xB0E0E6,'purple':0x800080,'rebeccapurple':0x663399,'red':0xFF0000,'rosybrown':0xBC8F8F,'royalblue':0x4169E1,'saddlebrown':0x8B4513,'salmon':0xFA8072,'sandybrown':0xF4A460,'seagreen':0x2E8B57,'seashell':0xFFF5EE,'sienna':0xA0522D,'silver':0xC0C0C0,'skyblue':0x87CEEB,'slateblue':0x6A5ACD,'slategray':0x708090,'slategrey':0x708090,'snow':0xFFFAFA,'springgreen':0x00FF7F,'steelblue':0x4682B4,'tan':0xD2B48C,'teal':0x008080,'thistle':0xD8BFD8,'tomato':0xFF6347,'turquoise':0x40E0D0,'violet':0xEE82EE,'wheat':0xF5DEB3,'white':0xFFFFFF,'whitesmoke':0xF5F5F5,'yellow':0xFFFF00,'yellowgreen':0x9ACD32};var _hslA={h:0,s:0,l:0};var _hslB={h:0,s:0,l:0};function Color(r,g,b){if(g===undefined&&b===undefined){
|
697 | return this.set(r);}return this.setRGB(r,g,b);}function hue2rgb(p,q,t){if(t<0)t+=1;if(t>1)t-=1;if(t<1/6)return p+(q-p)*6*t;if(t<1/2)return q;if(t<2/3)return p+(q-p)*6*(2/3-t);return p;}function SRGBToLinear(c){return c<0.04045?c*0.0773993808:Math.pow(c*0.9478672986+0.0521327014,2.4);}function LinearToSRGB(c){return c<0.0031308?c*12.92:1.055*Math.pow(c,0.41666)-0.055;}_extends(Color.prototype,{isColor:true,r:1,g:1,b:1,set:function set(value){if(value&&value.isColor){this.copy(value);}else if(typeof value==='number'){this.setHex(value);}else if(typeof value==='string'){this.setStyle(value);}return this;},setScalar:function setScalar(scalar){this.r=scalar;this.g=scalar;this.b=scalar;return this;},setHex:function setHex(hex){hex=Math.floor(hex);this.r=(hex>>16&255)/255;this.g=(hex>>8&255)/255;this.b=(hex&255)/255;return this;},setRGB:function setRGB(r,g,b){this.r=r;this.g=g;this.b=b;return this;},setHSL:function setHSL(h,s,l){
|
698 | h=MathUtils.euclideanModulo(h,1);s=MathUtils.clamp(s,0,1);l=MathUtils.clamp(l,0,1);if(s===0){this.r=this.g=this.b=l;}else {var p=l<=0.5?l*(1+s):l+s-l*s;var q=2*l-p;this.r=hue2rgb(q,p,h+1/3);this.g=hue2rgb(q,p,h);this.b=hue2rgb(q,p,h-1/3);}return this;},setStyle:function setStyle(style){function handleAlpha(string){if(string===undefined)return;if(parseFloat(string)<1){console.warn('THREE.Color: Alpha component of '+style+' will be ignored.');}}var m;if(m=/^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec(style)){
|
699 | var color;var name=m[1];var components=m[2];switch(name){case'rgb':case'rgba':if(color=/^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec(components)){
|
700 | this.r=Math.min(255,parseInt(color[1],10))/255;this.g=Math.min(255,parseInt(color[2],10))/255;this.b=Math.min(255,parseInt(color[3],10))/255;handleAlpha(color[5]);return this;}if(color=/^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec(components)){
|
701 | this.r=Math.min(100,parseInt(color[1],10))/100;this.g=Math.min(100,parseInt(color[2],10))/100;this.b=Math.min(100,parseInt(color[3],10))/100;handleAlpha(color[5]);return this;}break;case'hsl':case'hsla':if(color=/^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec(components)){
|
702 | var h=parseFloat(color[1])/360;var s=parseInt(color[2],10)/100;var l=parseInt(color[3],10)/100;handleAlpha(color[5]);return this.setHSL(h,s,l);}break;}}else if(m=/^\#([A-Fa-f0-9]+)$/.exec(style)){
|
703 | var hex=m[1];var size=hex.length;if(size===3){
|
704 | this.r=parseInt(hex.charAt(0)+hex.charAt(0),16)/255;this.g=parseInt(hex.charAt(1)+hex.charAt(1),16)/255;this.b=parseInt(hex.charAt(2)+hex.charAt(2),16)/255;return this;}else if(size===6){
|
705 | this.r=parseInt(hex.charAt(0)+hex.charAt(1),16)/255;this.g=parseInt(hex.charAt(2)+hex.charAt(3),16)/255;this.b=parseInt(hex.charAt(4)+hex.charAt(5),16)/255;return this;}}if(style&&style.length>0){return this.setColorName(style);}return this;},setColorName:function setColorName(style){
|
706 | var hex=_colorKeywords[style];if(hex!==undefined){
|
707 | this.setHex(hex);}else {
|
708 | console.warn('THREE.Color: Unknown color '+style);}return this;},clone:function clone(){return new this.constructor(this.r,this.g,this.b);},copy:function copy(color){this.r=color.r;this.g=color.g;this.b=color.b;return this;},copyGammaToLinear:function copyGammaToLinear(color,gammaFactor){if(gammaFactor===undefined)gammaFactor=2.0;this.r=Math.pow(color.r,gammaFactor);this.g=Math.pow(color.g,gammaFactor);this.b=Math.pow(color.b,gammaFactor);return this;},copyLinearToGamma:function copyLinearToGamma(color,gammaFactor){if(gammaFactor===undefined)gammaFactor=2.0;var safeInverse=gammaFactor>0?1.0/gammaFactor:1.0;this.r=Math.pow(color.r,safeInverse);this.g=Math.pow(color.g,safeInverse);this.b=Math.pow(color.b,safeInverse);return this;},convertGammaToLinear:function convertGammaToLinear(gammaFactor){this.copyGammaToLinear(this,gammaFactor);return this;},convertLinearToGamma:function convertLinearToGamma(gammaFactor){this.copyLinearToGamma(this,gammaFactor);return this;},copySRGBToLinear:function copySRGBToLinear(color){this.r=SRGBToLinear(color.r);this.g=SRGBToLinear(color.g);this.b=SRGBToLinear(color.b);return this;},copyLinearToSRGB:function copyLinearToSRGB(color){this.r=LinearToSRGB(color.r);this.g=LinearToSRGB(color.g);this.b=LinearToSRGB(color.b);return this;},convertSRGBToLinear:function convertSRGBToLinear(){this.copySRGBToLinear(this);return this;},convertLinearToSRGB:function convertLinearToSRGB(){this.copyLinearToSRGB(this);return this;},getHex:function getHex(){return this.r*255<<16^this.g*255<<8^this.b*255<<0;},getHexString:function getHexString(){return ('000000'+this.getHex().toString(16)).slice(-6);},getHSL:function getHSL(target){
|
709 | if(target===undefined){console.warn('THREE.Color: .getHSL() target is now required');target={h:0,s:0,l:0};}var r=this.r,g=this.g,b=this.b;var max=Math.max(r,g,b);var min=Math.min(r,g,b);var hue,saturation;var lightness=(min+max)/2.0;if(min===max){hue=0;saturation=0;}else {var delta=max-min;saturation=lightness<=0.5?delta/(max+min):delta/(2-max-min);switch(max){case r:hue=(g-b)/delta+(g<b?6:0);break;case g:hue=(b-r)/delta+2;break;case b:hue=(r-g)/delta+4;break;}hue/=6;}target.h=hue;target.s=saturation;target.l=lightness;return target;},getStyle:function getStyle(){return 'rgb('+(this.r*255|0)+','+(this.g*255|0)+','+(this.b*255|0)+')';},offsetHSL:function offsetHSL(h,s,l){this.getHSL(_hslA);_hslA.h+=h;_hslA.s+=s;_hslA.l+=l;this.setHSL(_hslA.h,_hslA.s,_hslA.l);return this;},add:function add(color){this.r+=color.r;this.g+=color.g;this.b+=color.b;return this;},addColors:function addColors(color1,color2){this.r=color1.r+color2.r;this.g=color1.g+color2.g;this.b=color1.b+color2.b;return this;},addScalar:function addScalar(s){this.r+=s;this.g+=s;this.b+=s;return this;},sub:function sub(color){this.r=Math.max(0,this.r-color.r);this.g=Math.max(0,this.g-color.g);this.b=Math.max(0,this.b-color.b);return this;},multiply:function multiply(color){this.r*=color.r;this.g*=color.g;this.b*=color.b;return this;},multiplyScalar:function multiplyScalar(s){this.r*=s;this.g*=s;this.b*=s;return this;},lerp:function lerp(color,alpha){this.r+=(color.r-this.r)*alpha;this.g+=(color.g-this.g)*alpha;this.b+=(color.b-this.b)*alpha;return this;},lerpHSL:function lerpHSL(color,alpha){this.getHSL(_hslA);color.getHSL(_hslB);var h=MathUtils.lerp(_hslA.h,_hslB.h,alpha);var s=MathUtils.lerp(_hslA.s,_hslB.s,alpha);var l=MathUtils.lerp(_hslA.l,_hslB.l,alpha);this.setHSL(h,s,l);return this;},equals:function equals(c){return c.r===this.r&&c.g===this.g&&c.b===this.b;},fromArray:function fromArray(array,offset){if(offset===undefined)offset=0;this.r=array[offset];this.g=array[offset+1];this.b=array[offset+2];return this;},toArray:function toArray(array,offset){if(array===undefined)array=[];if(offset===undefined)offset=0;array[offset]=this.r;array[offset+1]=this.g;array[offset+2]=this.b;return array;},toJSON:function toJSON(){return this.getHex();}});Color.NAMES=_colorKeywords; |
710 |
|
711 |
|
712 | function Face3(a,b,c,normal,color,materialIndex){this.a=a;this.b=b;this.c=c;this.normal=normal&&normal.isVector3?normal:new Vector3();this.vertexNormals=Array.isArray(normal)?normal:[];this.color=color&&color.isColor?color:new Color();this.vertexColors=Array.isArray(color)?color:[];this.materialIndex=materialIndex!==undefined?materialIndex:0;}_extends(Face3.prototype,{clone:function clone(){return new this.constructor().copy(this);},copy:function copy(source){this.a=source.a;this.b=source.b;this.c=source.c;this.normal.copy(source.normal);this.color.copy(source.color);this.materialIndex=source.materialIndex;for(var i=0,il=source.vertexNormals.length;i<il;i++){this.vertexNormals[i]=source.vertexNormals[i].clone();}for(var i=0,il=source.vertexColors.length;i<il;i++){this.vertexColors[i]=source.vertexColors[i].clone();}return this;}}); |
713 |
|
714 |
|
715 | var materialId=0;function Material(){Object.defineProperty(this,'id',{value:materialId++});this.uuid=MathUtils.generateUUID();this.name='';this.type='Material';this.fog=true;this.blending=NormalBlending;this.side=FrontSide;this.flatShading=false;this.vertexColors=false;this.opacity=1;this.transparent=false;this.blendSrc=SrcAlphaFactor;this.blendDst=OneMinusSrcAlphaFactor;this.blendEquation=AddEquation;this.blendSrcAlpha=null;this.blendDstAlpha=null;this.blendEquationAlpha=null;this.depthFunc=LessEqualDepth;this.depthTest=true;this.depthWrite=true;this.stencilWriteMask=0xff;this.stencilFunc=AlwaysStencilFunc;this.stencilRef=0;this.stencilFuncMask=0xff;this.stencilFail=KeepStencilOp;this.stencilZFail=KeepStencilOp;this.stencilZPass=KeepStencilOp;this.stencilWrite=false;this.clippingPlanes=null;this.clipIntersection=false;this.clipShadows=false;this.shadowSide=null;this.colorWrite=true;this.precision=null;
|
716 | this.polygonOffset=false;this.polygonOffsetFactor=0;this.polygonOffsetUnits=0;this.dithering=false;this.alphaTest=0;this.premultipliedAlpha=false;this.visible=true;this.toneMapped=true;this.userData={};this.version=0;}Material.prototype=_extends(Object.create(EventDispatcher.prototype),{constructor:Material,isMaterial:true,onBeforeCompile:function onBeforeCompile(){},setValues:function setValues(values){if(values===undefined)return;for(var key in values){var newValue=values[key];if(newValue===undefined){console.warn("THREE.Material: '"+key+"' parameter is undefined.");continue;}
|
717 | if(key==='shading'){console.warn('THREE.'+this.type+': .shading has been removed. Use the boolean .flatShading instead.');this.flatShading=newValue===FlatShading?true:false;continue;}var currentValue=this[key];if(currentValue===undefined){console.warn("THREE."+this.type+": '"+key+"' is not a property of this material.");continue;}if(currentValue&¤tValue.isColor){currentValue.set(newValue);}else if(currentValue&¤tValue.isVector3&&newValue&&newValue.isVector3){currentValue.copy(newValue);}else {this[key]=newValue;}}},toJSON:function toJSON(meta){var isRoot=meta===undefined||typeof meta==='string';if(isRoot){meta={textures:{},images:{}};}var data={metadata:{version:4.5,type:'Material',generator:'Material.toJSON'}};
|
718 | data.uuid=this.uuid;data.type=this.type;if(this.name!=='')data.name=this.name;if(this.color&&this.color.isColor)data.color=this.color.getHex();if(this.roughness!==undefined)data.roughness=this.roughness;if(this.metalness!==undefined)data.metalness=this.metalness;if(this.sheen&&this.sheen.isColor)data.sheen=this.sheen.getHex();if(this.emissive&&this.emissive.isColor)data.emissive=this.emissive.getHex();if(this.emissiveIntensity&&this.emissiveIntensity!==1)data.emissiveIntensity=this.emissiveIntensity;if(this.specular&&this.specular.isColor)data.specular=this.specular.getHex();if(this.shininess!==undefined)data.shininess=this.shininess;if(this.clearcoat!==undefined)data.clearcoat=this.clearcoat;if(this.clearcoatRoughness!==undefined)data.clearcoatRoughness=this.clearcoatRoughness;if(this.clearcoatMap&&this.clearcoatMap.isTexture){data.clearcoatMap=this.clearcoatMap.toJSON(meta).uuid;}if(this.clearcoatRoughnessMap&&this.clearcoatRoughnessMap.isTexture){data.clearcoatRoughnessMap=this.clearcoatRoughnessMap.toJSON(meta).uuid;}if(this.clearcoatNormalMap&&this.clearcoatNormalMap.isTexture){data.clearcoatNormalMap=this.clearcoatNormalMap.toJSON(meta).uuid;data.clearcoatNormalScale=this.clearcoatNormalScale.toArray();}if(this.map&&this.map.isTexture)data.map=this.map.toJSON(meta).uuid;if(this.matcap&&this.matcap.isTexture)data.matcap=this.matcap.toJSON(meta).uuid;if(this.alphaMap&&this.alphaMap.isTexture)data.alphaMap=this.alphaMap.toJSON(meta).uuid;if(this.lightMap&&this.lightMap.isTexture)data.lightMap=this.lightMap.toJSON(meta).uuid;if(this.aoMap&&this.aoMap.isTexture){data.aoMap=this.aoMap.toJSON(meta).uuid;data.aoMapIntensity=this.aoMapIntensity;}if(this.bumpMap&&this.bumpMap.isTexture){data.bumpMap=this.bumpMap.toJSON(meta).uuid;data.bumpScale=this.bumpScale;}if(this.normalMap&&this.normalMap.isTexture){data.normalMap=this.normalMap.toJSON(meta).uuid;data.normalMapType=this.normalMapType;data.normalScale=this.normalScale.toArray();}if(this.displacementMap&&this.displacementMap.isTexture){data.displacementMap=this.displacementMap.toJSON(meta).uuid;data.displacementScale=this.displacementScale;data.displacementBias=this.displacementBias;}if(this.roughnessMap&&this.roughnessMap.isTexture)data.roughnessMap=this.roughnessMap.toJSON(meta).uuid;if(this.metalnessMap&&this.metalnessMap.isTexture)data.metalnessMap=this.metalnessMap.toJSON(meta).uuid;if(this.emissiveMap&&this.emissiveMap.isTexture)data.emissiveMap=this.emissiveMap.toJSON(meta).uuid;if(this.specularMap&&this.specularMap.isTexture)data.specularMap=this.specularMap.toJSON(meta).uuid;if(this.envMap&&this.envMap.isTexture){data.envMap=this.envMap.toJSON(meta).uuid;data.reflectivity=this.reflectivity;
|
719 | data.refractionRatio=this.refractionRatio;if(this.combine!==undefined)data.combine=this.combine;if(this.envMapIntensity!==undefined)data.envMapIntensity=this.envMapIntensity;}if(this.gradientMap&&this.gradientMap.isTexture){data.gradientMap=this.gradientMap.toJSON(meta).uuid;}if(this.size!==undefined)data.size=this.size;if(this.sizeAttenuation!==undefined)data.sizeAttenuation=this.sizeAttenuation;if(this.blending!==NormalBlending)data.blending=this.blending;if(this.flatShading===true)data.flatShading=this.flatShading;if(this.side!==FrontSide)data.side=this.side;if(this.vertexColors)data.vertexColors=true;if(this.opacity<1)data.opacity=this.opacity;if(this.transparent===true)data.transparent=this.transparent;data.depthFunc=this.depthFunc;data.depthTest=this.depthTest;data.depthWrite=this.depthWrite;data.stencilWrite=this.stencilWrite;data.stencilWriteMask=this.stencilWriteMask;data.stencilFunc=this.stencilFunc;data.stencilRef=this.stencilRef;data.stencilFuncMask=this.stencilFuncMask;data.stencilFail=this.stencilFail;data.stencilZFail=this.stencilZFail;data.stencilZPass=this.stencilZPass;
|
720 | if(this.rotation&&this.rotation!==0)data.rotation=this.rotation;if(this.polygonOffset===true)data.polygonOffset=true;if(this.polygonOffsetFactor!==0)data.polygonOffsetFactor=this.polygonOffsetFactor;if(this.polygonOffsetUnits!==0)data.polygonOffsetUnits=this.polygonOffsetUnits;if(this.linewidth&&this.linewidth!==1)data.linewidth=this.linewidth;if(this.dashSize!==undefined)data.dashSize=this.dashSize;if(this.gapSize!==undefined)data.gapSize=this.gapSize;if(this.scale!==undefined)data.scale=this.scale;if(this.dithering===true)data.dithering=true;if(this.alphaTest>0)data.alphaTest=this.alphaTest;if(this.premultipliedAlpha===true)data.premultipliedAlpha=this.premultipliedAlpha;if(this.wireframe===true)data.wireframe=this.wireframe;if(this.wireframeLinewidth>1)data.wireframeLinewidth=this.wireframeLinewidth;if(this.wireframeLinecap!=='round')data.wireframeLinecap=this.wireframeLinecap;if(this.wireframeLinejoin!=='round')data.wireframeLinejoin=this.wireframeLinejoin;if(this.morphTargets===true)data.morphTargets=true;if(this.morphNormals===true)data.morphNormals=true;if(this.skinning===true)data.skinning=true;if(this.visible===false)data.visible=false;if(this.toneMapped===false)data.toneMapped=false;if(JSON.stringify(this.userData)!=='{}')data.userData=this.userData;
|
721 | function extractFromCache(cache){var values=[];for(var key in cache){var data=cache[key];delete data.metadata;values.push(data);}return values;}if(isRoot){var textures=extractFromCache(meta.textures);var images=extractFromCache(meta.images);if(textures.length>0)data.textures=textures;if(images.length>0)data.images=images;}return data;},clone:function clone(){return new this.constructor().copy(this);},copy:function copy(source){this.name=source.name;this.fog=source.fog;this.blending=source.blending;this.side=source.side;this.flatShading=source.flatShading;this.vertexColors=source.vertexColors;this.opacity=source.opacity;this.transparent=source.transparent;this.blendSrc=source.blendSrc;this.blendDst=source.blendDst;this.blendEquation=source.blendEquation;this.blendSrcAlpha=source.blendSrcAlpha;this.blendDstAlpha=source.blendDstAlpha;this.blendEquationAlpha=source.blendEquationAlpha;this.depthFunc=source.depthFunc;this.depthTest=source.depthTest;this.depthWrite=source.depthWrite;this.stencilWriteMask=source.stencilWriteMask;this.stencilFunc=source.stencilFunc;this.stencilRef=source.stencilRef;this.stencilFuncMask=source.stencilFuncMask;this.stencilFail=source.stencilFail;this.stencilZFail=source.stencilZFail;this.stencilZPass=source.stencilZPass;this.stencilWrite=source.stencilWrite;var srcPlanes=source.clippingPlanes,dstPlanes=null;if(srcPlanes!==null){var n=srcPlanes.length;dstPlanes=new Array(n);for(var i=0;i!==n;++i){dstPlanes[i]=srcPlanes[i].clone();}}this.clippingPlanes=dstPlanes;this.clipIntersection=source.clipIntersection;this.clipShadows=source.clipShadows;this.shadowSide=source.shadowSide;this.colorWrite=source.colorWrite;this.precision=source.precision;this.polygonOffset=source.polygonOffset;this.polygonOffsetFactor=source.polygonOffsetFactor;this.polygonOffsetUnits=source.polygonOffsetUnits;this.dithering=source.dithering;this.alphaTest=source.alphaTest;this.premultipliedAlpha=source.premultipliedAlpha;this.visible=source.visible;this.toneMapped=source.toneMapped;this.userData=JSON.parse(JSON.stringify(source.userData));return this;},dispose:function dispose(){this.dispatchEvent({type:'dispose'});}});Object.defineProperty(Material.prototype,'needsUpdate',{set:function set(value){if(value===true)this.version++;}}); |
722 |
|
723 |
|
724 |
|
725 |
|
726 |
|
727 |
|
728 |
|
729 |
|
730 |
|
731 |
|
732 |
|
733 |
|
734 |
|
735 |
|
736 |
|
737 |
|
738 |
|
739 |
|
740 |
|
741 |
|
742 |
|
743 |
|
744 |
|
745 |
|
746 |
|
747 |
|
748 |
|
749 |
|
750 |
|
751 |
|
752 |
|
753 |
|
754 | function MeshBasicMaterial(parameters){Material.call(this);this.type='MeshBasicMaterial';this.color=new Color(0xffffff);
|
755 | this.map=null;this.lightMap=null;this.lightMapIntensity=1.0;this.aoMap=null;this.aoMapIntensity=1.0;this.specularMap=null;this.alphaMap=null;this.envMap=null;this.combine=MultiplyOperation;this.reflectivity=1;this.refractionRatio=0.98;this.wireframe=false;this.wireframeLinewidth=1;this.wireframeLinecap='round';this.wireframeLinejoin='round';this.skinning=false;this.morphTargets=false;this.setValues(parameters);}MeshBasicMaterial.prototype=Object.create(Material.prototype);MeshBasicMaterial.prototype.constructor=MeshBasicMaterial;MeshBasicMaterial.prototype.isMeshBasicMaterial=true;MeshBasicMaterial.prototype.copy=function(source){Material.prototype.copy.call(this,source);this.color.copy(source.color);this.map=source.map;this.lightMap=source.lightMap;this.lightMapIntensity=source.lightMapIntensity;this.aoMap=source.aoMap;this.aoMapIntensity=source.aoMapIntensity;this.specularMap=source.specularMap;this.alphaMap=source.alphaMap;this.envMap=source.envMap;this.combine=source.combine;this.reflectivity=source.reflectivity;this.refractionRatio=source.refractionRatio;this.wireframe=source.wireframe;this.wireframeLinewidth=source.wireframeLinewidth;this.wireframeLinecap=source.wireframeLinecap;this.wireframeLinejoin=source.wireframeLinejoin;this.skinning=source.skinning;this.morphTargets=source.morphTargets;return this;}; |
756 |
|
757 | var _vector$3=new Vector3();function BufferAttribute(array,itemSize,normalized){if(Array.isArray(array)){throw new TypeError('THREE.BufferAttribute: array should be a Typed Array.');}this.name='';this.array=array;this.itemSize=itemSize;this.count=array!==undefined?array.length/itemSize:0;this.normalized=normalized===true;this.usage=StaticDrawUsage;this.updateRange={offset:0,count:-1};this.version=0;}Object.defineProperty(BufferAttribute.prototype,'needsUpdate',{set:function set(value){if(value===true)this.version++;}});_extends(BufferAttribute.prototype,{isBufferAttribute:true,onUploadCallback:function onUploadCallback(){},setUsage:function setUsage(value){this.usage=value;return this;},copy:function copy(source){this.name=source.name;this.array=new source.array.constructor(source.array);this.itemSize=source.itemSize;this.count=source.count;this.normalized=source.normalized;this.usage=source.usage;return this;},copyAt:function copyAt(index1,attribute,index2){index1*=this.itemSize;index2*=attribute.itemSize;for(var i=0,l=this.itemSize;i<l;i++){this.array[index1+i]=attribute.array[index2+i];}return this;},copyArray:function copyArray(array){this.array.set(array);return this;},copyColorsArray:function copyColorsArray(colors){var array=this.array,offset=0;for(var i=0,l=colors.length;i<l;i++){var color=colors[i];if(color===undefined){console.warn('THREE.BufferAttribute.copyColorsArray(): color is undefined',i);color=new Color();}array[offset++]=color.r;array[offset++]=color.g;array[offset++]=color.b;}return this;},copyVector2sArray:function copyVector2sArray(vectors){var array=this.array,offset=0;for(var i=0,l=vectors.length;i<l;i++){var vector=vectors[i];if(vector===undefined){console.warn('THREE.BufferAttribute.copyVector2sArray(): vector is undefined',i);vector=new Vector2();}array[offset++]=vector.x;array[offset++]=vector.y;}return this;},copyVector3sArray:function copyVector3sArray(vectors){var array=this.array,offset=0;for(var i=0,l=vectors.length;i<l;i++){var vector=vectors[i];if(vector===undefined){console.warn('THREE.BufferAttribute.copyVector3sArray(): vector is undefined',i);vector=new Vector3();}array[offset++]=vector.x;array[offset++]=vector.y;array[offset++]=vector.z;}return this;},copyVector4sArray:function copyVector4sArray(vectors){var array=this.array,offset=0;for(var i=0,l=vectors.length;i<l;i++){var vector=vectors[i];if(vector===undefined){console.warn('THREE.BufferAttribute.copyVector4sArray(): vector is undefined',i);vector=new Vector4();}array[offset++]=vector.x;array[offset++]=vector.y;array[offset++]=vector.z;array[offset++]=vector.w;}return this;},applyMatrix3:function applyMatrix3(m){for(var i=0,l=this.count;i<l;i++){_vector$3.x=this.getX(i);_vector$3.y=this.getY(i);_vector$3.z=this.getZ(i);_vector$3.applyMatrix3(m);this.setXYZ(i,_vector$3.x,_vector$3.y,_vector$3.z);}return this;},applyMatrix4:function applyMatrix4(m){for(var i=0,l=this.count;i<l;i++){_vector$3.x=this.getX(i);_vector$3.y=this.getY(i);_vector$3.z=this.getZ(i);_vector$3.applyMatrix4(m);this.setXYZ(i,_vector$3.x,_vector$3.y,_vector$3.z);}return this;},applyNormalMatrix:function applyNormalMatrix(m){for(var i=0,l=this.count;i<l;i++){_vector$3.x=this.getX(i);_vector$3.y=this.getY(i);_vector$3.z=this.getZ(i);_vector$3.applyNormalMatrix(m);this.setXYZ(i,_vector$3.x,_vector$3.y,_vector$3.z);}return this;},transformDirection:function transformDirection(m){for(var i=0,l=this.count;i<l;i++){_vector$3.x=this.getX(i);_vector$3.y=this.getY(i);_vector$3.z=this.getZ(i);_vector$3.transformDirection(m);this.setXYZ(i,_vector$3.x,_vector$3.y,_vector$3.z);}return this;},set:function set(value,offset){if(offset===undefined)offset=0;this.array.set(value,offset);return this;},getX:function getX(index){return this.array[index*this.itemSize];},setX:function setX(index,x){this.array[index*this.itemSize]=x;return this;},getY:function getY(index){return this.array[index*this.itemSize+1];},setY:function setY(index,y){this.array[index*this.itemSize+1]=y;return this;},getZ:function getZ(index){return this.array[index*this.itemSize+2];},setZ:function setZ(index,z){this.array[index*this.itemSize+2]=z;return this;},getW:function getW(index){return this.array[index*this.itemSize+3];},setW:function setW(index,w){this.array[index*this.itemSize+3]=w;return this;},setXY:function setXY(index,x,y){index*=this.itemSize;this.array[index+0]=x;this.array[index+1]=y;return this;},setXYZ:function setXYZ(index,x,y,z){index*=this.itemSize;this.array[index+0]=x;this.array[index+1]=y;this.array[index+2]=z;return this;},setXYZW:function setXYZW(index,x,y,z,w){index*=this.itemSize;this.array[index+0]=x;this.array[index+1]=y;this.array[index+2]=z;this.array[index+3]=w;return this;},onUpload:function onUpload(callback){this.onUploadCallback=callback;return this;},clone:function clone(){return new this.constructor(this.array,this.itemSize).copy(this);},toJSON:function toJSON(){return {itemSize:this.itemSize,type:this.array.constructor.name,array:Array.prototype.slice.call(this.array),normalized:this.normalized};}});
|
758 | function Int8BufferAttribute(array,itemSize,normalized){BufferAttribute.call(this,new Int8Array(array),itemSize,normalized);}Int8BufferAttribute.prototype=Object.create(BufferAttribute.prototype);Int8BufferAttribute.prototype.constructor=Int8BufferAttribute;function Uint8BufferAttribute(array,itemSize,normalized){BufferAttribute.call(this,new Uint8Array(array),itemSize,normalized);}Uint8BufferAttribute.prototype=Object.create(BufferAttribute.prototype);Uint8BufferAttribute.prototype.constructor=Uint8BufferAttribute;function Uint8ClampedBufferAttribute(array,itemSize,normalized){BufferAttribute.call(this,new Uint8ClampedArray(array),itemSize,normalized);}Uint8ClampedBufferAttribute.prototype=Object.create(BufferAttribute.prototype);Uint8ClampedBufferAttribute.prototype.constructor=Uint8ClampedBufferAttribute;function Int16BufferAttribute(array,itemSize,normalized){BufferAttribute.call(this,new Int16Array(array),itemSize,normalized);}Int16BufferAttribute.prototype=Object.create(BufferAttribute.prototype);Int16BufferAttribute.prototype.constructor=Int16BufferAttribute;function Uint16BufferAttribute(array,itemSize,normalized){BufferAttribute.call(this,new Uint16Array(array),itemSize,normalized);}Uint16BufferAttribute.prototype=Object.create(BufferAttribute.prototype);Uint16BufferAttribute.prototype.constructor=Uint16BufferAttribute;function Int32BufferAttribute(array,itemSize,normalized){BufferAttribute.call(this,new Int32Array(array),itemSize,normalized);}Int32BufferAttribute.prototype=Object.create(BufferAttribute.prototype);Int32BufferAttribute.prototype.constructor=Int32BufferAttribute;function Uint32BufferAttribute(array,itemSize,normalized){BufferAttribute.call(this,new Uint32Array(array),itemSize,normalized);}Uint32BufferAttribute.prototype=Object.create(BufferAttribute.prototype);Uint32BufferAttribute.prototype.constructor=Uint32BufferAttribute;function Float32BufferAttribute(array,itemSize,normalized){BufferAttribute.call(this,new Float32Array(array),itemSize,normalized);}Float32BufferAttribute.prototype=Object.create(BufferAttribute.prototype);Float32BufferAttribute.prototype.constructor=Float32BufferAttribute;function Float64BufferAttribute(array,itemSize,normalized){BufferAttribute.call(this,new Float64Array(array),itemSize,normalized);}Float64BufferAttribute.prototype=Object.create(BufferAttribute.prototype);Float64BufferAttribute.prototype.constructor=Float64BufferAttribute; |
759 |
|
760 | function DirectGeometry(){this.vertices=[];this.normals=[];this.colors=[];this.uvs=[];this.uvs2=[];this.groups=[];this.morphTargets={};this.skinWeights=[];this.skinIndices=[];
|
761 | this.boundingBox=null;this.boundingSphere=null;
|
762 | this.verticesNeedUpdate=false;this.normalsNeedUpdate=false;this.colorsNeedUpdate=false;this.uvsNeedUpdate=false;this.groupsNeedUpdate=false;}_extends(DirectGeometry.prototype,{computeGroups:function computeGroups(geometry){var group;var groups=[];var materialIndex=undefined;var faces=geometry.faces;for(var i=0;i<faces.length;i++){var face=faces[i];
|
763 | if(face.materialIndex!==materialIndex){materialIndex=face.materialIndex;if(group!==undefined){group.count=i*3-group.start;groups.push(group);}group={start:i*3,materialIndex:materialIndex};}}if(group!==undefined){group.count=i*3-group.start;groups.push(group);}this.groups=groups;},fromGeometry:function fromGeometry(geometry){var faces=geometry.faces;var vertices=geometry.vertices;var faceVertexUvs=geometry.faceVertexUvs;var hasFaceVertexUv=faceVertexUvs[0]&&faceVertexUvs[0].length>0;var hasFaceVertexUv2=faceVertexUvs[1]&&faceVertexUvs[1].length>0;
|
764 | var morphTargets=geometry.morphTargets;var morphTargetsLength=morphTargets.length;var morphTargetsPosition;if(morphTargetsLength>0){morphTargetsPosition=[];for(var i=0;i<morphTargetsLength;i++){morphTargetsPosition[i]={name:morphTargets[i].name,data:[]};}this.morphTargets.position=morphTargetsPosition;}var morphNormals=geometry.morphNormals;var morphNormalsLength=morphNormals.length;var morphTargetsNormal;if(morphNormalsLength>0){morphTargetsNormal=[];for(var i=0;i<morphNormalsLength;i++){morphTargetsNormal[i]={name:morphNormals[i].name,data:[]};}this.morphTargets.normal=morphTargetsNormal;}
|
765 | var skinIndices=geometry.skinIndices;var skinWeights=geometry.skinWeights;var hasSkinIndices=skinIndices.length===vertices.length;var hasSkinWeights=skinWeights.length===vertices.length;
|
766 | if(vertices.length>0&&faces.length===0){console.error('THREE.DirectGeometry: Faceless geometries are not supported.');}for(var i=0;i<faces.length;i++){var face=faces[i];this.vertices.push(vertices[face.a],vertices[face.b],vertices[face.c]);var vertexNormals=face.vertexNormals;if(vertexNormals.length===3){this.normals.push(vertexNormals[0],vertexNormals[1],vertexNormals[2]);}else {var normal=face.normal;this.normals.push(normal,normal,normal);}var vertexColors=face.vertexColors;if(vertexColors.length===3){this.colors.push(vertexColors[0],vertexColors[1],vertexColors[2]);}else {var color=face.color;this.colors.push(color,color,color);}if(hasFaceVertexUv===true){var vertexUvs=faceVertexUvs[0][i];if(vertexUvs!==undefined){this.uvs.push(vertexUvs[0],vertexUvs[1],vertexUvs[2]);}else {console.warn('THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ',i);this.uvs.push(new Vector2(),new Vector2(),new Vector2());}}if(hasFaceVertexUv2===true){var vertexUvs=faceVertexUvs[1][i];if(vertexUvs!==undefined){this.uvs2.push(vertexUvs[0],vertexUvs[1],vertexUvs[2]);}else {console.warn('THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ',i);this.uvs2.push(new Vector2(),new Vector2(),new Vector2());}}
|
767 | for(var j=0;j<morphTargetsLength;j++){var morphTarget=morphTargets[j].vertices;morphTargetsPosition[j].data.push(morphTarget[face.a],morphTarget[face.b],morphTarget[face.c]);}for(var j=0;j<morphNormalsLength;j++){var morphNormal=morphNormals[j].vertexNormals[i];morphTargetsNormal[j].data.push(morphNormal.a,morphNormal.b,morphNormal.c);}
|
768 | if(hasSkinIndices){this.skinIndices.push(skinIndices[face.a],skinIndices[face.b],skinIndices[face.c]);}if(hasSkinWeights){this.skinWeights.push(skinWeights[face.a],skinWeights[face.b],skinWeights[face.c]);}}this.computeGroups(geometry);this.verticesNeedUpdate=geometry.verticesNeedUpdate;this.normalsNeedUpdate=geometry.normalsNeedUpdate;this.colorsNeedUpdate=geometry.colorsNeedUpdate;this.uvsNeedUpdate=geometry.uvsNeedUpdate;this.groupsNeedUpdate=geometry.groupsNeedUpdate;if(geometry.boundingSphere!==null){this.boundingSphere=geometry.boundingSphere.clone();}if(geometry.boundingBox!==null){this.boundingBox=geometry.boundingBox.clone();}return this;}}); |
769 |
|
770 | function arrayMax(array){if(array.length===0)return -Infinity;var max=array[0];for(var i=1,l=array.length;i<l;++i){if(array[i]>max)max=array[i];}return max;} |
771 |
|
772 |
|
773 | var _bufferGeometryId=1;
|
774 | var _m1$2=new Matrix4();var _obj=new Object3D();var _offset=new Vector3();var _box$2=new Box3();var _boxMorphTargets=new Box3();var _vector$4=new Vector3();function BufferGeometry(){Object.defineProperty(this,'id',{value:_bufferGeometryId+=2});this.uuid=MathUtils.generateUUID();this.name='';this.type='BufferGeometry';this.index=null;this.attributes={};this.morphAttributes={};this.morphTargetsRelative=false;this.groups=[];this.boundingBox=null;this.boundingSphere=null;this.drawRange={start:0,count:Infinity};this.userData={};}BufferGeometry.prototype=_extends(Object.create(EventDispatcher.prototype),{constructor:BufferGeometry,isBufferGeometry:true,getIndex:function getIndex(){return this.index;},setIndex:function setIndex(index){if(Array.isArray(index)){this.index=new(arrayMax(index)>65535?Uint32BufferAttribute:Uint16BufferAttribute)(index,1);}else {this.index=index;}},getAttribute:function getAttribute(name){return this.attributes[name];},setAttribute:function setAttribute(name,attribute){this.attributes[name]=attribute;return this;},deleteAttribute:function deleteAttribute(name){delete this.attributes[name];return this;},addGroup:function addGroup(start,count,materialIndex){this.groups.push({start:start,count:count,materialIndex:materialIndex!==undefined?materialIndex:0});},clearGroups:function clearGroups(){this.groups=[];},setDrawRange:function setDrawRange(start,count){this.drawRange.start=start;this.drawRange.count=count;},applyMatrix4:function applyMatrix4(matrix){var position=this.attributes.position;if(position!==undefined){position.applyMatrix4(matrix);position.needsUpdate=true;}var normal=this.attributes.normal;if(normal!==undefined){var normalMatrix=new Matrix3().getNormalMatrix(matrix);normal.applyNormalMatrix(normalMatrix);normal.needsUpdate=true;}var tangent=this.attributes.tangent;if(tangent!==undefined){tangent.transformDirection(matrix);tangent.needsUpdate=true;}if(this.boundingBox!==null){this.computeBoundingBox();}if(this.boundingSphere!==null){this.computeBoundingSphere();}return this;},rotateX:function rotateX(angle){
|
775 | _m1$2.makeRotationX(angle);this.applyMatrix4(_m1$2);return this;},rotateY:function rotateY(angle){
|
776 | _m1$2.makeRotationY(angle);this.applyMatrix4(_m1$2);return this;},rotateZ:function rotateZ(angle){
|
777 | _m1$2.makeRotationZ(angle);this.applyMatrix4(_m1$2);return this;},translate:function translate(x,y,z){
|
778 | _m1$2.makeTranslation(x,y,z);this.applyMatrix4(_m1$2);return this;},scale:function scale(x,y,z){
|
779 | _m1$2.makeScale(x,y,z);this.applyMatrix4(_m1$2);return this;},lookAt:function lookAt(vector){_obj.lookAt(vector);_obj.updateMatrix();this.applyMatrix4(_obj.matrix);return this;},center:function center(){this.computeBoundingBox();this.boundingBox.getCenter(_offset).negate();this.translate(_offset.x,_offset.y,_offset.z);return this;},setFromObject:function setFromObject(object){
|
780 | var geometry=object.geometry;if(object.isPoints||object.isLine){var positions=new Float32BufferAttribute(geometry.vertices.length*3,3);var colors=new Float32BufferAttribute(geometry.colors.length*3,3);this.setAttribute('position',positions.copyVector3sArray(geometry.vertices));this.setAttribute('color',colors.copyColorsArray(geometry.colors));if(geometry.lineDistances&&geometry.lineDistances.length===geometry.vertices.length){var lineDistances=new Float32BufferAttribute(geometry.lineDistances.length,1);this.setAttribute('lineDistance',lineDistances.copyArray(geometry.lineDistances));}if(geometry.boundingSphere!==null){this.boundingSphere=geometry.boundingSphere.clone();}if(geometry.boundingBox!==null){this.boundingBox=geometry.boundingBox.clone();}}else if(object.isMesh){if(geometry&&geometry.isGeometry){this.fromGeometry(geometry);}}return this;},setFromPoints:function setFromPoints(points){var position=[];for(var i=0,l=points.length;i<l;i++){var point=points[i];position.push(point.x,point.y,point.z||0);}this.setAttribute('position',new Float32BufferAttribute(position,3));return this;},updateFromObject:function updateFromObject(object){var geometry=object.geometry;if(object.isMesh){var direct=geometry.__directGeometry;if(geometry.elementsNeedUpdate===true){direct=undefined;geometry.elementsNeedUpdate=false;}if(direct===undefined){return this.fromGeometry(geometry);}direct.verticesNeedUpdate=geometry.verticesNeedUpdate;direct.normalsNeedUpdate=geometry.normalsNeedUpdate;direct.colorsNeedUpdate=geometry.colorsNeedUpdate;direct.uvsNeedUpdate=geometry.uvsNeedUpdate;direct.groupsNeedUpdate=geometry.groupsNeedUpdate;geometry.verticesNeedUpdate=false;geometry.normalsNeedUpdate=false;geometry.colorsNeedUpdate=false;geometry.uvsNeedUpdate=false;geometry.groupsNeedUpdate=false;geometry=direct;}var attribute;if(geometry.verticesNeedUpdate===true){attribute=this.attributes.position;if(attribute!==undefined){attribute.copyVector3sArray(geometry.vertices);attribute.needsUpdate=true;}geometry.verticesNeedUpdate=false;}if(geometry.normalsNeedUpdate===true){attribute=this.attributes.normal;if(attribute!==undefined){attribute.copyVector3sArray(geometry.normals);attribute.needsUpdate=true;}geometry.normalsNeedUpdate=false;}if(geometry.colorsNeedUpdate===true){attribute=this.attributes.color;if(attribute!==undefined){attribute.copyColorsArray(geometry.colors);attribute.needsUpdate=true;}geometry.colorsNeedUpdate=false;}if(geometry.uvsNeedUpdate){attribute=this.attributes.uv;if(attribute!==undefined){attribute.copyVector2sArray(geometry.uvs);attribute.needsUpdate=true;}geometry.uvsNeedUpdate=false;}if(geometry.lineDistancesNeedUpdate){attribute=this.attributes.lineDistance;if(attribute!==undefined){attribute.copyArray(geometry.lineDistances);attribute.needsUpdate=true;}geometry.lineDistancesNeedUpdate=false;}if(geometry.groupsNeedUpdate){geometry.computeGroups(object.geometry);this.groups=geometry.groups;geometry.groupsNeedUpdate=false;}return this;},fromGeometry:function fromGeometry(geometry){geometry.__directGeometry=new DirectGeometry().fromGeometry(geometry);return this.fromDirectGeometry(geometry.__directGeometry);},fromDirectGeometry:function fromDirectGeometry(geometry){var positions=new Float32Array(geometry.vertices.length*3);this.setAttribute('position',new BufferAttribute(positions,3).copyVector3sArray(geometry.vertices));if(geometry.normals.length>0){var normals=new Float32Array(geometry.normals.length*3);this.setAttribute('normal',new BufferAttribute(normals,3).copyVector3sArray(geometry.normals));}if(geometry.colors.length>0){var colors=new Float32Array(geometry.colors.length*3);this.setAttribute('color',new BufferAttribute(colors,3).copyColorsArray(geometry.colors));}if(geometry.uvs.length>0){var uvs=new Float32Array(geometry.uvs.length*2);this.setAttribute('uv',new BufferAttribute(uvs,2).copyVector2sArray(geometry.uvs));}if(geometry.uvs2.length>0){var uvs2=new Float32Array(geometry.uvs2.length*2);this.setAttribute('uv2',new BufferAttribute(uvs2,2).copyVector2sArray(geometry.uvs2));}
|
781 | this.groups=geometry.groups;
|
782 | for(var name in geometry.morphTargets){var array=[];var morphTargets=geometry.morphTargets[name];for(var i=0,l=morphTargets.length;i<l;i++){var morphTarget=morphTargets[i];var attribute=new Float32BufferAttribute(morphTarget.data.length*3,3);attribute.name=morphTarget.name;array.push(attribute.copyVector3sArray(morphTarget.data));}this.morphAttributes[name]=array;}
|
783 | if(geometry.skinIndices.length>0){var skinIndices=new Float32BufferAttribute(geometry.skinIndices.length*4,4);this.setAttribute('skinIndex',skinIndices.copyVector4sArray(geometry.skinIndices));}if(geometry.skinWeights.length>0){var skinWeights=new Float32BufferAttribute(geometry.skinWeights.length*4,4);this.setAttribute('skinWeight',skinWeights.copyVector4sArray(geometry.skinWeights));}
|
784 | if(geometry.boundingSphere!==null){this.boundingSphere=geometry.boundingSphere.clone();}if(geometry.boundingBox!==null){this.boundingBox=geometry.boundingBox.clone();}return this;},computeBoundingBox:function computeBoundingBox(){if(this.boundingBox===null){this.boundingBox=new Box3();}var position=this.attributes.position;var morphAttributesPosition=this.morphAttributes.position;if(position!==undefined){this.boundingBox.setFromBufferAttribute(position);
|
785 | if(morphAttributesPosition){for(var i=0,il=morphAttributesPosition.length;i<il;i++){var morphAttribute=morphAttributesPosition[i];_box$2.setFromBufferAttribute(morphAttribute);if(this.morphTargetsRelative){_vector$4.addVectors(this.boundingBox.min,_box$2.min);this.boundingBox.expandByPoint(_vector$4);_vector$4.addVectors(this.boundingBox.max,_box$2.max);this.boundingBox.expandByPoint(_vector$4);}else {this.boundingBox.expandByPoint(_box$2.min);this.boundingBox.expandByPoint(_box$2.max);}}}}else {this.boundingBox.makeEmpty();}if(isNaN(this.boundingBox.min.x)||isNaN(this.boundingBox.min.y)||isNaN(this.boundingBox.min.z)){console.error('THREE.BufferGeometry.computeBoundingBox: Computed min/max have NaN values. The "position" attribute is likely to have NaN values.',this);}},computeBoundingSphere:function computeBoundingSphere(){if(this.boundingSphere===null){this.boundingSphere=new Sphere();}var position=this.attributes.position;var morphAttributesPosition=this.morphAttributes.position;if(position){
|
786 | var center=this.boundingSphere.center;_box$2.setFromBufferAttribute(position);
|
787 | if(morphAttributesPosition){for(var i=0,il=morphAttributesPosition.length;i<il;i++){var morphAttribute=morphAttributesPosition[i];_boxMorphTargets.setFromBufferAttribute(morphAttribute);if(this.morphTargetsRelative){_vector$4.addVectors(_box$2.min,_boxMorphTargets.min);_box$2.expandByPoint(_vector$4);_vector$4.addVectors(_box$2.max,_boxMorphTargets.max);_box$2.expandByPoint(_vector$4);}else {_box$2.expandByPoint(_boxMorphTargets.min);_box$2.expandByPoint(_boxMorphTargets.max);}}}_box$2.getCenter(center);
|
788 |
|
789 | var maxRadiusSq=0;for(var i=0,il=position.count;i<il;i++){_vector$4.fromBufferAttribute(position,i);maxRadiusSq=Math.max(maxRadiusSq,center.distanceToSquared(_vector$4));}
|
790 | if(morphAttributesPosition){for(var i=0,il=morphAttributesPosition.length;i<il;i++){var morphAttribute=morphAttributesPosition[i];var morphTargetsRelative=this.morphTargetsRelative;for(var j=0,jl=morphAttribute.count;j<jl;j++){_vector$4.fromBufferAttribute(morphAttribute,j);if(morphTargetsRelative){_offset.fromBufferAttribute(position,j);_vector$4.add(_offset);}maxRadiusSq=Math.max(maxRadiusSq,center.distanceToSquared(_vector$4));}}}this.boundingSphere.radius=Math.sqrt(maxRadiusSq);if(isNaN(this.boundingSphere.radius)){console.error('THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.',this);}}},computeFaceNormals:function computeFaceNormals(){
|
791 | },computeVertexNormals:function computeVertexNormals(){var index=this.index;var attributes=this.attributes;if(attributes.position){var positions=attributes.position.array;if(attributes.normal===undefined){this.setAttribute('normal',new BufferAttribute(new Float32Array(positions.length),3));}else {
|
792 | var array=attributes.normal.array;for(var i=0,il=array.length;i<il;i++){array[i]=0;}}var normals=attributes.normal.array;var vA,vB,vC;var pA=new Vector3(),pB=new Vector3(),pC=new Vector3();var cb=new Vector3(),ab=new Vector3();
|
793 | if(index){var indices=index.array;for(var i=0,il=index.count;i<il;i+=3){vA=indices[i+0]*3;vB=indices[i+1]*3;vC=indices[i+2]*3;pA.fromArray(positions,vA);pB.fromArray(positions,vB);pC.fromArray(positions,vC);cb.subVectors(pC,pB);ab.subVectors(pA,pB);cb.cross(ab);normals[vA]+=cb.x;normals[vA+1]+=cb.y;normals[vA+2]+=cb.z;normals[vB]+=cb.x;normals[vB+1]+=cb.y;normals[vB+2]+=cb.z;normals[vC]+=cb.x;normals[vC+1]+=cb.y;normals[vC+2]+=cb.z;}}else {
|
794 | for(var i=0,il=positions.length;i<il;i+=9){pA.fromArray(positions,i);pB.fromArray(positions,i+3);pC.fromArray(positions,i+6);cb.subVectors(pC,pB);ab.subVectors(pA,pB);cb.cross(ab);normals[i]=cb.x;normals[i+1]=cb.y;normals[i+2]=cb.z;normals[i+3]=cb.x;normals[i+4]=cb.y;normals[i+5]=cb.z;normals[i+6]=cb.x;normals[i+7]=cb.y;normals[i+8]=cb.z;}}this.normalizeNormals();attributes.normal.needsUpdate=true;}},merge:function merge(geometry,offset){if(!(geometry&&geometry.isBufferGeometry)){console.error('THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.',geometry);return;}if(offset===undefined){offset=0;console.warn('THREE.BufferGeometry.merge(): Overwriting original geometry, starting at offset=0. '+'Use BufferGeometryUtils.mergeBufferGeometries() for lossless merge.');}var attributes=this.attributes;for(var key in attributes){if(geometry.attributes[key]===undefined)continue;var attribute1=attributes[key];var attributeArray1=attribute1.array;var attribute2=geometry.attributes[key];var attributeArray2=attribute2.array;var attributeOffset=attribute2.itemSize*offset;var length=Math.min(attributeArray2.length,attributeArray1.length-attributeOffset);for(var i=0,j=attributeOffset;i<length;i++,j++){attributeArray1[j]=attributeArray2[i];}}return this;},normalizeNormals:function normalizeNormals(){var normals=this.attributes.normal;for(var i=0,il=normals.count;i<il;i++){_vector$4.x=normals.getX(i);_vector$4.y=normals.getY(i);_vector$4.z=normals.getZ(i);_vector$4.normalize();normals.setXYZ(i,_vector$4.x,_vector$4.y,_vector$4.z);}},toNonIndexed:function toNonIndexed(){function convertBufferAttribute(attribute,indices){var array=attribute.array;var itemSize=attribute.itemSize;var array2=new array.constructor(indices.length*itemSize);var index=0,index2=0;for(var i=0,l=indices.length;i<l;i++){index=indices[i]*itemSize;for(var j=0;j<itemSize;j++){array2[index2++]=array[index++];}}return new BufferAttribute(array2,itemSize);}
|
795 | if(this.index===null){console.warn('THREE.BufferGeometry.toNonIndexed(): Geometry is already non-indexed.');return this;}var geometry2=new BufferGeometry();var indices=this.index.array;var attributes=this.attributes;
|
796 | for(var name in attributes){var attribute=attributes[name];var newAttribute=convertBufferAttribute(attribute,indices);geometry2.setAttribute(name,newAttribute);}
|
797 | var morphAttributes=this.morphAttributes;for(name in morphAttributes){var morphArray=[];var morphAttribute=morphAttributes[name];
|
798 | for(var i=0,il=morphAttribute.length;i<il;i++){var attribute=morphAttribute[i];var newAttribute=convertBufferAttribute(attribute,indices);morphArray.push(newAttribute);}geometry2.morphAttributes[name]=morphArray;}geometry2.morphTargetsRelative=this.morphTargetsRelative;
|
799 | var groups=this.groups;for(var i=0,l=groups.length;i<l;i++){var group=groups[i];geometry2.addGroup(group.start,group.count,group.materialIndex);}return geometry2;},toJSON:function toJSON(){var data={metadata:{version:4.5,type:'BufferGeometry',generator:'BufferGeometry.toJSON'}};
|
800 | data.uuid=this.uuid;data.type=this.type;if(this.name!=='')data.name=this.name;if(Object.keys(this.userData).length>0)data.userData=this.userData;if(this.parameters!==undefined){var parameters=this.parameters;for(var key in parameters){if(parameters[key]!==undefined)data[key]=parameters[key];}return data;}data.data={attributes:{}};var index=this.index;if(index!==null){data.data.index={type:index.array.constructor.name,array:Array.prototype.slice.call(index.array)};}var attributes=this.attributes;for(var key in attributes){var attribute=attributes[key];var attributeData=attribute.toJSON();if(attribute.name!=='')attributeData.name=attribute.name;data.data.attributes[key]=attributeData;}var morphAttributes={};var hasMorphAttributes=false;for(var key in this.morphAttributes){var attributeArray=this.morphAttributes[key];var array=[];for(var i=0,il=attributeArray.length;i<il;i++){var attribute=attributeArray[i];var attributeData=attribute.toJSON();if(attribute.name!=='')attributeData.name=attribute.name;array.push(attributeData);}if(array.length>0){morphAttributes[key]=array;hasMorphAttributes=true;}}if(hasMorphAttributes){data.data.morphAttributes=morphAttributes;data.data.morphTargetsRelative=this.morphTargetsRelative;}var groups=this.groups;if(groups.length>0){data.data.groups=JSON.parse(JSON.stringify(groups));}var boundingSphere=this.boundingSphere;if(boundingSphere!==null){data.data.boundingSphere={center:boundingSphere.center.toArray(),radius:boundingSphere.radius};}return data;},clone:function clone(){ |
801 |
|
802 |
|
803 |
|
804 |
|
805 |
|
806 |
|
807 |
|
808 |
|
809 |
|
810 |
|
811 |
|
812 |
|
813 |
|
814 |
|
815 |
|
816 |
|
817 |
|
818 |
|
819 |
|
820 |
|
821 |
|
822 | return new BufferGeometry().copy(this);},copy:function copy(source){var name,i,l;
|
823 | this.index=null;this.attributes={};this.morphAttributes={};this.groups=[];this.boundingBox=null;this.boundingSphere=null;
|
824 | this.name=source.name;
|
825 | var index=source.index;if(index!==null){this.setIndex(index.clone());}
|
826 | var attributes=source.attributes;for(name in attributes){var attribute=attributes[name];this.setAttribute(name,attribute.clone());}
|
827 | var morphAttributes=source.morphAttributes;for(name in morphAttributes){var array=[];var morphAttribute=morphAttributes[name];
|
828 | for(i=0,l=morphAttribute.length;i<l;i++){array.push(morphAttribute[i].clone());}this.morphAttributes[name]=array;}this.morphTargetsRelative=source.morphTargetsRelative;
|
829 | var groups=source.groups;for(i=0,l=groups.length;i<l;i++){var group=groups[i];this.addGroup(group.start,group.count,group.materialIndex);}
|
830 | var boundingBox=source.boundingBox;if(boundingBox!==null){this.boundingBox=boundingBox.clone();}
|
831 | var boundingSphere=source.boundingSphere;if(boundingSphere!==null){this.boundingSphere=boundingSphere.clone();}
|
832 | this.drawRange.start=source.drawRange.start;this.drawRange.count=source.drawRange.count;
|
833 | this.userData=source.userData;return this;},dispose:function dispose(){this.dispatchEvent({type:'dispose'});}}); |
834 |
|
835 |
|
836 |
|
837 |
|
838 | var _inverseMatrix=new Matrix4();var _ray=new Ray();var _sphere=new Sphere();var _vA=new Vector3();var _vB=new Vector3();var _vC=new Vector3();var _tempA=new Vector3();var _tempB=new Vector3();var _tempC=new Vector3();var _morphA=new Vector3();var _morphB=new Vector3();var _morphC=new Vector3();var _uvA=new Vector2();var _uvB=new Vector2();var _uvC=new Vector2();var _intersectionPoint=new Vector3();var _intersectionPointWorld=new Vector3();function Mesh(geometry,material){Object3D.call(this);this.type='Mesh';this.geometry=geometry!==undefined?geometry:new BufferGeometry();this.material=material!==undefined?material:new MeshBasicMaterial();this.updateMorphTargets();}Mesh.prototype=_extends(Object.create(Object3D.prototype),{constructor:Mesh,isMesh:true,copy:function copy(source){Object3D.prototype.copy.call(this,source);if(source.morphTargetInfluences!==undefined){this.morphTargetInfluences=source.morphTargetInfluences.slice();}if(source.morphTargetDictionary!==undefined){this.morphTargetDictionary=_extends({},source.morphTargetDictionary);}return this;},updateMorphTargets:function updateMorphTargets(){var geometry=this.geometry;var m,ml,name;if(geometry.isBufferGeometry){var morphAttributes=geometry.morphAttributes;var keys=Object.keys(morphAttributes);if(keys.length>0){var morphAttribute=morphAttributes[keys[0]];if(morphAttribute!==undefined){this.morphTargetInfluences=[];this.morphTargetDictionary={};for(m=0,ml=morphAttribute.length;m<ml;m++){name=morphAttribute[m].name||String(m);this.morphTargetInfluences.push(0);this.morphTargetDictionary[name]=m;}}}}else {var morphTargets=geometry.morphTargets;if(morphTargets!==undefined&&morphTargets.length>0){console.error('THREE.Mesh.updateMorphTargets() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');}}},raycast:function raycast(raycaster,intersects){var geometry=this.geometry;var material=this.material;var matrixWorld=this.matrixWorld;if(material===undefined)return;
|
839 | if(geometry.boundingSphere===null)geometry.computeBoundingSphere();_sphere.copy(geometry.boundingSphere);_sphere.applyMatrix4(matrixWorld);if(raycaster.ray.intersectsSphere(_sphere)===false)return;
|
840 | _inverseMatrix.getInverse(matrixWorld);_ray.copy(raycaster.ray).applyMatrix4(_inverseMatrix);
|
841 | if(geometry.boundingBox!==null){if(_ray.intersectsBox(geometry.boundingBox)===false)return;}var intersection;if(geometry.isBufferGeometry){var a,b,c;var index=geometry.index;var position=geometry.attributes.position;var morphPosition=geometry.morphAttributes.position;var morphTargetsRelative=geometry.morphTargetsRelative;var uv=geometry.attributes.uv;var uv2=geometry.attributes.uv2;var groups=geometry.groups;var drawRange=geometry.drawRange;var i,j,il,jl;var group,groupMaterial;var start,end;if(index!==null){
|
842 | if(Array.isArray(material)){for(i=0,il=groups.length;i<il;i++){group=groups[i];groupMaterial=material[group.materialIndex];start=Math.max(group.start,drawRange.start);end=Math.min(group.start+group.count,drawRange.start+drawRange.count);for(j=start,jl=end;j<jl;j+=3){a=index.getX(j);b=index.getX(j+1);c=index.getX(j+2);intersection=checkBufferGeometryIntersection(this,groupMaterial,raycaster,_ray,position,morphPosition,morphTargetsRelative,uv,uv2,a,b,c);if(intersection){intersection.faceIndex=Math.floor(j/3);
|
843 | intersection.face.materialIndex=group.materialIndex;intersects.push(intersection);}}}}else {start=Math.max(0,drawRange.start);end=Math.min(index.count,drawRange.start+drawRange.count);for(i=start,il=end;i<il;i+=3){a=index.getX(i);b=index.getX(i+1);c=index.getX(i+2);intersection=checkBufferGeometryIntersection(this,material,raycaster,_ray,position,morphPosition,morphTargetsRelative,uv,uv2,a,b,c);if(intersection){intersection.faceIndex=Math.floor(i/3);
|
844 | intersects.push(intersection);}}}}else if(position!==undefined){
|
845 | if(Array.isArray(material)){for(i=0,il=groups.length;i<il;i++){group=groups[i];groupMaterial=material[group.materialIndex];start=Math.max(group.start,drawRange.start);end=Math.min(group.start+group.count,drawRange.start+drawRange.count);for(j=start,jl=end;j<jl;j+=3){a=j;b=j+1;c=j+2;intersection=checkBufferGeometryIntersection(this,groupMaterial,raycaster,_ray,position,morphPosition,morphTargetsRelative,uv,uv2,a,b,c);if(intersection){intersection.faceIndex=Math.floor(j/3);
|
846 | intersection.face.materialIndex=group.materialIndex;intersects.push(intersection);}}}}else {start=Math.max(0,drawRange.start);end=Math.min(position.count,drawRange.start+drawRange.count);for(i=start,il=end;i<il;i+=3){a=i;b=i+1;c=i+2;intersection=checkBufferGeometryIntersection(this,material,raycaster,_ray,position,morphPosition,morphTargetsRelative,uv,uv2,a,b,c);if(intersection){intersection.faceIndex=Math.floor(i/3);
|
847 | intersects.push(intersection);}}}}}else if(geometry.isGeometry){var fvA,fvB,fvC;var isMultiMaterial=Array.isArray(material);var vertices=geometry.vertices;var faces=geometry.faces;var uvs;var faceVertexUvs=geometry.faceVertexUvs[0];if(faceVertexUvs.length>0)uvs=faceVertexUvs;for(var f=0,fl=faces.length;f<fl;f++){var face=faces[f];var faceMaterial=isMultiMaterial?material[face.materialIndex]:material;if(faceMaterial===undefined)continue;fvA=vertices[face.a];fvB=vertices[face.b];fvC=vertices[face.c];intersection=checkIntersection(this,faceMaterial,raycaster,_ray,fvA,fvB,fvC,_intersectionPoint);if(intersection){if(uvs&&uvs[f]){var uvs_f=uvs[f];_uvA.copy(uvs_f[0]);_uvB.copy(uvs_f[1]);_uvC.copy(uvs_f[2]);intersection.uv=Triangle.getUV(_intersectionPoint,fvA,fvB,fvC,_uvA,_uvB,_uvC,new Vector2());}intersection.face=face;intersection.faceIndex=f;intersects.push(intersection);}}}},clone:function clone(){return new this.constructor(this.geometry,this.material).copy(this);}});function checkIntersection(object,material,raycaster,ray,pA,pB,pC,point){var intersect;if(material.side===BackSide){intersect=ray.intersectTriangle(pC,pB,pA,true,point);}else {intersect=ray.intersectTriangle(pA,pB,pC,material.side!==DoubleSide,point);}if(intersect===null)return null;_intersectionPointWorld.copy(point);_intersectionPointWorld.applyMatrix4(object.matrixWorld);var distance=raycaster.ray.origin.distanceTo(_intersectionPointWorld);if(distance<raycaster.near||distance>raycaster.far)return null;return {distance:distance,point:_intersectionPointWorld.clone(),object:object};}function checkBufferGeometryIntersection(object,material,raycaster,ray,position,morphPosition,morphTargetsRelative,uv,uv2,a,b,c){_vA.fromBufferAttribute(position,a);_vB.fromBufferAttribute(position,b);_vC.fromBufferAttribute(position,c);var morphInfluences=object.morphTargetInfluences;if(material.morphTargets&&morphPosition&&morphInfluences){_morphA.set(0,0,0);_morphB.set(0,0,0);_morphC.set(0,0,0);for(var i=0,il=morphPosition.length;i<il;i++){var influence=morphInfluences[i];var morphAttribute=morphPosition[i];if(influence===0)continue;_tempA.fromBufferAttribute(morphAttribute,a);_tempB.fromBufferAttribute(morphAttribute,b);_tempC.fromBufferAttribute(morphAttribute,c);if(morphTargetsRelative){_morphA.addScaledVector(_tempA,influence);_morphB.addScaledVector(_tempB,influence);_morphC.addScaledVector(_tempC,influence);}else {_morphA.addScaledVector(_tempA.sub(_vA),influence);_morphB.addScaledVector(_tempB.sub(_vB),influence);_morphC.addScaledVector(_tempC.sub(_vC),influence);}}_vA.add(_morphA);_vB.add(_morphB);_vC.add(_morphC);}if(object.isSkinnedMesh){object.boneTransform(a,_vA);object.boneTransform(b,_vB);object.boneTransform(c,_vC);}var intersection=checkIntersection(object,material,raycaster,ray,_vA,_vB,_vC,_intersectionPoint);if(intersection){if(uv){_uvA.fromBufferAttribute(uv,a);_uvB.fromBufferAttribute(uv,b);_uvC.fromBufferAttribute(uv,c);intersection.uv=Triangle.getUV(_intersectionPoint,_vA,_vB,_vC,_uvA,_uvB,_uvC,new Vector2());}if(uv2){_uvA.fromBufferAttribute(uv2,a);_uvB.fromBufferAttribute(uv2,b);_uvC.fromBufferAttribute(uv2,c);intersection.uv2=Triangle.getUV(_intersectionPoint,_vA,_vB,_vC,_uvA,_uvB,_uvC,new Vector2());}var face=new Face3(a,b,c);Triangle.getNormal(_vA,_vB,_vC,face.normal);intersection.face=face;}return intersection;} |
848 |
|
849 |
|
850 |
|
851 |
|
852 |
|
853 |
|
854 | var _geometryId=0;
|
855 | var _m1$3=new Matrix4();var _obj$1=new Object3D();var _offset$1=new Vector3();function Geometry(){Object.defineProperty(this,'id',{value:_geometryId+=2});this.uuid=MathUtils.generateUUID();this.name='';this.type='Geometry';this.vertices=[];this.colors=[];this.faces=[];this.faceVertexUvs=[[]];this.morphTargets=[];this.morphNormals=[];this.skinWeights=[];this.skinIndices=[];this.lineDistances=[];this.boundingBox=null;this.boundingSphere=null;
|
856 | this.elementsNeedUpdate=false;this.verticesNeedUpdate=false;this.uvsNeedUpdate=false;this.normalsNeedUpdate=false;this.colorsNeedUpdate=false;this.lineDistancesNeedUpdate=false;this.groupsNeedUpdate=false;}Geometry.prototype=_extends(Object.create(EventDispatcher.prototype),{constructor:Geometry,isGeometry:true,applyMatrix4:function applyMatrix4(matrix){var normalMatrix=new Matrix3().getNormalMatrix(matrix);for(var i=0,il=this.vertices.length;i<il;i++){var vertex=this.vertices[i];vertex.applyMatrix4(matrix);}for(var i=0,il=this.faces.length;i<il;i++){var face=this.faces[i];face.normal.applyMatrix3(normalMatrix).normalize();for(var j=0,jl=face.vertexNormals.length;j<jl;j++){face.vertexNormals[j].applyMatrix3(normalMatrix).normalize();}}if(this.boundingBox!==null){this.computeBoundingBox();}if(this.boundingSphere!==null){this.computeBoundingSphere();}this.verticesNeedUpdate=true;this.normalsNeedUpdate=true;return this;},rotateX:function rotateX(angle){
|
857 | _m1$3.makeRotationX(angle);this.applyMatrix4(_m1$3);return this;},rotateY:function rotateY(angle){
|
858 | _m1$3.makeRotationY(angle);this.applyMatrix4(_m1$3);return this;},rotateZ:function rotateZ(angle){
|
859 | _m1$3.makeRotationZ(angle);this.applyMatrix4(_m1$3);return this;},translate:function translate(x,y,z){
|
860 | _m1$3.makeTranslation(x,y,z);this.applyMatrix4(_m1$3);return this;},scale:function scale(x,y,z){
|
861 | _m1$3.makeScale(x,y,z);this.applyMatrix4(_m1$3);return this;},lookAt:function lookAt(vector){_obj$1.lookAt(vector);_obj$1.updateMatrix();this.applyMatrix4(_obj$1.matrix);return this;},fromBufferGeometry:function fromBufferGeometry(geometry){var scope=this;var indices=geometry.index!==null?geometry.index.array:undefined;var attributes=geometry.attributes;if(attributes.position===undefined){console.error('THREE.Geometry.fromBufferGeometry(): Position attribute required for conversion.');return this;}var positions=attributes.position.array;var normals=attributes.normal!==undefined?attributes.normal.array:undefined;var colors=attributes.color!==undefined?attributes.color.array:undefined;var uvs=attributes.uv!==undefined?attributes.uv.array:undefined;var uvs2=attributes.uv2!==undefined?attributes.uv2.array:undefined;if(uvs2!==undefined)this.faceVertexUvs[1]=[];for(var i=0;i<positions.length;i+=3){scope.vertices.push(new Vector3().fromArray(positions,i));if(colors!==undefined){scope.colors.push(new Color().fromArray(colors,i));}}function addFace(a,b,c,materialIndex){var vertexColors=colors===undefined?[]:[scope.colors[a].clone(),scope.colors[b].clone(),scope.colors[c].clone()];var vertexNormals=normals===undefined?[]:[new Vector3().fromArray(normals,a*3),new Vector3().fromArray(normals,b*3),new Vector3().fromArray(normals,c*3)];var face=new Face3(a,b,c,vertexNormals,vertexColors,materialIndex);scope.faces.push(face);if(uvs!==undefined){scope.faceVertexUvs[0].push([new Vector2().fromArray(uvs,a*2),new Vector2().fromArray(uvs,b*2),new Vector2().fromArray(uvs,c*2)]);}if(uvs2!==undefined){scope.faceVertexUvs[1].push([new Vector2().fromArray(uvs2,a*2),new Vector2().fromArray(uvs2,b*2),new Vector2().fromArray(uvs2,c*2)]);}}var groups=geometry.groups;if(groups.length>0){for(var i=0;i<groups.length;i++){var group=groups[i];var start=group.start;var count=group.count;for(var j=start,jl=start+count;j<jl;j+=3){if(indices!==undefined){addFace(indices[j],indices[j+1],indices[j+2],group.materialIndex);}else {addFace(j,j+1,j+2,group.materialIndex);}}}}else {if(indices!==undefined){for(var i=0;i<indices.length;i+=3){addFace(indices[i],indices[i+1],indices[i+2]);}}else {for(var i=0;i<positions.length/3;i+=3){addFace(i,i+1,i+2);}}}this.computeFaceNormals();if(geometry.boundingBox!==null){this.boundingBox=geometry.boundingBox.clone();}if(geometry.boundingSphere!==null){this.boundingSphere=geometry.boundingSphere.clone();}return this;},center:function center(){this.computeBoundingBox();this.boundingBox.getCenter(_offset$1).negate();this.translate(_offset$1.x,_offset$1.y,_offset$1.z);return this;},normalize:function normalize(){this.computeBoundingSphere();var center=this.boundingSphere.center;var radius=this.boundingSphere.radius;var s=radius===0?1:1.0/radius;var matrix=new Matrix4();matrix.set(s,0,0,-s*center.x,0,s,0,-s*center.y,0,0,s,-s*center.z,0,0,0,1);this.applyMatrix4(matrix);return this;},computeFaceNormals:function computeFaceNormals(){var cb=new Vector3(),ab=new Vector3();for(var f=0,fl=this.faces.length;f<fl;f++){var face=this.faces[f];var vA=this.vertices[face.a];var vB=this.vertices[face.b];var vC=this.vertices[face.c];cb.subVectors(vC,vB);ab.subVectors(vA,vB);cb.cross(ab);cb.normalize();face.normal.copy(cb);}},computeVertexNormals:function computeVertexNormals(areaWeighted){if(areaWeighted===undefined)areaWeighted=true;var v,vl,f,fl,face,vertices;vertices=new Array(this.vertices.length);for(v=0,vl=this.vertices.length;v<vl;v++){vertices[v]=new Vector3();}if(areaWeighted){
|
862 |
|
863 | var vA,vB,vC;var cb=new Vector3(),ab=new Vector3();for(f=0,fl=this.faces.length;f<fl;f++){face=this.faces[f];vA=this.vertices[face.a];vB=this.vertices[face.b];vC=this.vertices[face.c];cb.subVectors(vC,vB);ab.subVectors(vA,vB);cb.cross(ab);vertices[face.a].add(cb);vertices[face.b].add(cb);vertices[face.c].add(cb);}}else {this.computeFaceNormals();for(f=0,fl=this.faces.length;f<fl;f++){face=this.faces[f];vertices[face.a].add(face.normal);vertices[face.b].add(face.normal);vertices[face.c].add(face.normal);}}for(v=0,vl=this.vertices.length;v<vl;v++){vertices[v].normalize();}for(f=0,fl=this.faces.length;f<fl;f++){face=this.faces[f];var vertexNormals=face.vertexNormals;if(vertexNormals.length===3){vertexNormals[0].copy(vertices[face.a]);vertexNormals[1].copy(vertices[face.b]);vertexNormals[2].copy(vertices[face.c]);}else {vertexNormals[0]=vertices[face.a].clone();vertexNormals[1]=vertices[face.b].clone();vertexNormals[2]=vertices[face.c].clone();}}if(this.faces.length>0){this.normalsNeedUpdate=true;}},computeFlatVertexNormals:function computeFlatVertexNormals(){var f,fl,face;this.computeFaceNormals();for(f=0,fl=this.faces.length;f<fl;f++){face=this.faces[f];var vertexNormals=face.vertexNormals;if(vertexNormals.length===3){vertexNormals[0].copy(face.normal);vertexNormals[1].copy(face.normal);vertexNormals[2].copy(face.normal);}else {vertexNormals[0]=face.normal.clone();vertexNormals[1]=face.normal.clone();vertexNormals[2]=face.normal.clone();}}if(this.faces.length>0){this.normalsNeedUpdate=true;}},computeMorphNormals:function computeMorphNormals(){var i,il,f,fl,face;
|
864 |
|
865 |
|
866 | for(f=0,fl=this.faces.length;f<fl;f++){face=this.faces[f];if(!face.__originalFaceNormal){face.__originalFaceNormal=face.normal.clone();}else {face.__originalFaceNormal.copy(face.normal);}if(!face.__originalVertexNormals)face.__originalVertexNormals=[];for(i=0,il=face.vertexNormals.length;i<il;i++){if(!face.__originalVertexNormals[i]){face.__originalVertexNormals[i]=face.vertexNormals[i].clone();}else {face.__originalVertexNormals[i].copy(face.vertexNormals[i]);}}}
|
867 | var tmpGeo=new Geometry();tmpGeo.faces=this.faces;for(i=0,il=this.morphTargets.length;i<il;i++){
|
868 | if(!this.morphNormals[i]){this.morphNormals[i]={};this.morphNormals[i].faceNormals=[];this.morphNormals[i].vertexNormals=[];var dstNormalsFace=this.morphNormals[i].faceNormals;var dstNormalsVertex=this.morphNormals[i].vertexNormals;var faceNormal,vertexNormals;for(f=0,fl=this.faces.length;f<fl;f++){faceNormal=new Vector3();vertexNormals={a:new Vector3(),b:new Vector3(),c:new Vector3()};dstNormalsFace.push(faceNormal);dstNormalsVertex.push(vertexNormals);}}var morphNormals=this.morphNormals[i];
|
869 | tmpGeo.vertices=this.morphTargets[i].vertices;
|
870 | tmpGeo.computeFaceNormals();tmpGeo.computeVertexNormals();
|
871 | var faceNormal,vertexNormals;for(f=0,fl=this.faces.length;f<fl;f++){face=this.faces[f];faceNormal=morphNormals.faceNormals[f];vertexNormals=morphNormals.vertexNormals[f];faceNormal.copy(face.normal);vertexNormals.a.copy(face.vertexNormals[0]);vertexNormals.b.copy(face.vertexNormals[1]);vertexNormals.c.copy(face.vertexNormals[2]);}}
|
872 | for(f=0,fl=this.faces.length;f<fl;f++){face=this.faces[f];face.normal=face.__originalFaceNormal;face.vertexNormals=face.__originalVertexNormals;}},computeBoundingBox:function computeBoundingBox(){if(this.boundingBox===null){this.boundingBox=new Box3();}this.boundingBox.setFromPoints(this.vertices);},computeBoundingSphere:function computeBoundingSphere(){if(this.boundingSphere===null){this.boundingSphere=new Sphere();}this.boundingSphere.setFromPoints(this.vertices);},merge:function merge(geometry,matrix,materialIndexOffset){if(!(geometry&&geometry.isGeometry)){console.error('THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.',geometry);return;}var normalMatrix,vertexOffset=this.vertices.length,vertices1=this.vertices,vertices2=geometry.vertices,faces1=this.faces,faces2=geometry.faces,colors1=this.colors,colors2=geometry.colors;if(materialIndexOffset===undefined)materialIndexOffset=0;if(matrix!==undefined){normalMatrix=new Matrix3().getNormalMatrix(matrix);}
|
873 | for(var i=0,il=vertices2.length;i<il;i++){var vertex=vertices2[i];var vertexCopy=vertex.clone();if(matrix!==undefined)vertexCopy.applyMatrix4(matrix);vertices1.push(vertexCopy);}
|
874 | for(var i=0,il=colors2.length;i<il;i++){colors1.push(colors2[i].clone());}
|
875 | for(i=0,il=faces2.length;i<il;i++){var face=faces2[i],faceCopy,normal,color,faceVertexNormals=face.vertexNormals,faceVertexColors=face.vertexColors;faceCopy=new Face3(face.a+vertexOffset,face.b+vertexOffset,face.c+vertexOffset);faceCopy.normal.copy(face.normal);if(normalMatrix!==undefined){faceCopy.normal.applyMatrix3(normalMatrix).normalize();}for(var j=0,jl=faceVertexNormals.length;j<jl;j++){normal=faceVertexNormals[j].clone();if(normalMatrix!==undefined){normal.applyMatrix3(normalMatrix).normalize();}faceCopy.vertexNormals.push(normal);}faceCopy.color.copy(face.color);for(var j=0,jl=faceVertexColors.length;j<jl;j++){color=faceVertexColors[j];faceCopy.vertexColors.push(color.clone());}faceCopy.materialIndex=face.materialIndex+materialIndexOffset;faces1.push(faceCopy);}
|
876 | for(var i=0,il=geometry.faceVertexUvs.length;i<il;i++){var faceVertexUvs2=geometry.faceVertexUvs[i];if(this.faceVertexUvs[i]===undefined)this.faceVertexUvs[i]=[];for(var j=0,jl=faceVertexUvs2.length;j<jl;j++){var uvs2=faceVertexUvs2[j],uvsCopy=[];for(var k=0,kl=uvs2.length;k<kl;k++){uvsCopy.push(uvs2[k].clone());}this.faceVertexUvs[i].push(uvsCopy);}}},mergeMesh:function mergeMesh(mesh){if(!(mesh&&mesh.isMesh)){console.error('THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.',mesh);return;}if(mesh.matrixAutoUpdate)mesh.updateMatrix();this.merge(mesh.geometry,mesh.matrix);}, |
877 |
|
878 |
|
879 |
|
880 | mergeVertices:function mergeVertices(){var verticesMap={};
|
881 | var unique=[],changes=[];var v,key;var precisionPoints=4;
|
882 | var precision=Math.pow(10,precisionPoints);var i,il,face;var indices,j,jl;for(i=0,il=this.vertices.length;i<il;i++){v=this.vertices[i];key=Math.round(v.x*precision)+'_'+Math.round(v.y*precision)+'_'+Math.round(v.z*precision);if(verticesMap[key]===undefined){verticesMap[key]=i;unique.push(this.vertices[i]);changes[i]=unique.length-1;}else {
|
883 | changes[i]=changes[verticesMap[key]];}}
|
884 |
|
885 | var faceIndicesToRemove=[];for(i=0,il=this.faces.length;i<il;i++){face=this.faces[i];face.a=changes[face.a];face.b=changes[face.b];face.c=changes[face.c];indices=[face.a,face.b,face.c];
|
886 |
|
887 | for(var n=0;n<3;n++){if(indices[n]===indices[(n+1)%3]){faceIndicesToRemove.push(i);break;}}}for(i=faceIndicesToRemove.length-1;i>=0;i--){var idx=faceIndicesToRemove[i];this.faces.splice(idx,1);for(j=0,jl=this.faceVertexUvs.length;j<jl;j++){this.faceVertexUvs[j].splice(idx,1);}}
|
888 | var diff=this.vertices.length-unique.length;this.vertices=unique;return diff;},setFromPoints:function setFromPoints(points){this.vertices=[];for(var i=0,l=points.length;i<l;i++){var point=points[i];this.vertices.push(new Vector3(point.x,point.y,point.z||0));}return this;},sortFacesByMaterialIndex:function sortFacesByMaterialIndex(){var faces=this.faces;var length=faces.length;
|
889 | for(var i=0;i<length;i++){faces[i]._id=i;}
|
890 | function materialIndexSort(a,b){return a.materialIndex-b.materialIndex;}faces.sort(materialIndexSort);
|
891 | var uvs1=this.faceVertexUvs[0];var uvs2=this.faceVertexUvs[1];var newUvs1,newUvs2;if(uvs1&&uvs1.length===length)newUvs1=[];if(uvs2&&uvs2.length===length)newUvs2=[];for(var i=0;i<length;i++){var id=faces[i]._id;if(newUvs1)newUvs1.push(uvs1[id]);if(newUvs2)newUvs2.push(uvs2[id]);}if(newUvs1)this.faceVertexUvs[0]=newUvs1;if(newUvs2)this.faceVertexUvs[1]=newUvs2;},toJSON:function toJSON(){var data={metadata:{version:4.5,type:'Geometry',generator:'Geometry.toJSON'}};
|
892 | data.uuid=this.uuid;data.type=this.type;if(this.name!=='')data.name=this.name;if(this.parameters!==undefined){var parameters=this.parameters;for(var key in parameters){if(parameters[key]!==undefined)data[key]=parameters[key];}return data;}var vertices=[];for(var i=0;i<this.vertices.length;i++){var vertex=this.vertices[i];vertices.push(vertex.x,vertex.y,vertex.z);}var faces=[];var normals=[];var normalsHash={};var colors=[];var colorsHash={};var uvs=[];var uvsHash={};for(var i=0;i<this.faces.length;i++){var face=this.faces[i];var hasMaterial=true;var hasFaceUv=false;
|
893 | var hasFaceVertexUv=this.faceVertexUvs[0][i]!==undefined;var hasFaceNormal=face.normal.length()>0;var hasFaceVertexNormal=face.vertexNormals.length>0;var hasFaceColor=face.color.r!==1||face.color.g!==1||face.color.b!==1;var hasFaceVertexColor=face.vertexColors.length>0;var faceType=0;faceType=setBit(faceType,0,0);
|
894 | faceType=setBit(faceType,1,hasMaterial);faceType=setBit(faceType,2,hasFaceUv);faceType=setBit(faceType,3,hasFaceVertexUv);faceType=setBit(faceType,4,hasFaceNormal);faceType=setBit(faceType,5,hasFaceVertexNormal);faceType=setBit(faceType,6,hasFaceColor);faceType=setBit(faceType,7,hasFaceVertexColor);faces.push(faceType);faces.push(face.a,face.b,face.c);faces.push(face.materialIndex);if(hasFaceVertexUv){var faceVertexUvs=this.faceVertexUvs[0][i];faces.push(getUvIndex(faceVertexUvs[0]),getUvIndex(faceVertexUvs[1]),getUvIndex(faceVertexUvs[2]));}if(hasFaceNormal){faces.push(getNormalIndex(face.normal));}if(hasFaceVertexNormal){var vertexNormals=face.vertexNormals;faces.push(getNormalIndex(vertexNormals[0]),getNormalIndex(vertexNormals[1]),getNormalIndex(vertexNormals[2]));}if(hasFaceColor){faces.push(getColorIndex(face.color));}if(hasFaceVertexColor){var vertexColors=face.vertexColors;faces.push(getColorIndex(vertexColors[0]),getColorIndex(vertexColors[1]),getColorIndex(vertexColors[2]));}}function setBit(value,position,enabled){return enabled?value|1<<position:value&~(1<<position);}function getNormalIndex(normal){var hash=normal.x.toString()+normal.y.toString()+normal.z.toString();if(normalsHash[hash]!==undefined){return normalsHash[hash];}normalsHash[hash]=normals.length/3;normals.push(normal.x,normal.y,normal.z);return normalsHash[hash];}function getColorIndex(color){var hash=color.r.toString()+color.g.toString()+color.b.toString();if(colorsHash[hash]!==undefined){return colorsHash[hash];}colorsHash[hash]=colors.length;colors.push(color.getHex());return colorsHash[hash];}function getUvIndex(uv){var hash=uv.x.toString()+uv.y.toString();if(uvsHash[hash]!==undefined){return uvsHash[hash];}uvsHash[hash]=uvs.length/2;uvs.push(uv.x,uv.y);return uvsHash[hash];}data.data={};data.data.vertices=vertices;data.data.normals=normals;if(colors.length>0)data.data.colors=colors;if(uvs.length>0)data.data.uvs=[uvs];
|
895 | data.data.faces=faces;return data;},clone:function clone(){ |
896 |
|
897 |
|
898 |
|
899 |
|
900 |
|
901 |
|
902 |
|
903 |
|
904 |
|
905 |
|
906 |
|
907 |
|
908 |
|
909 |
|
910 |
|
911 |
|
912 |
|
913 |
|
914 |
|
915 |
|
916 |
|
917 | return new Geometry().copy(this);},copy:function copy(source){var i,il,j,jl,k,kl;
|
918 | this.vertices=[];this.colors=[];this.faces=[];this.faceVertexUvs=[[]];this.morphTargets=[];this.morphNormals=[];this.skinWeights=[];this.skinIndices=[];this.lineDistances=[];this.boundingBox=null;this.boundingSphere=null;
|
919 | this.name=source.name;
|
920 | var vertices=source.vertices;for(i=0,il=vertices.length;i<il;i++){this.vertices.push(vertices[i].clone());}
|
921 | var colors=source.colors;for(i=0,il=colors.length;i<il;i++){this.colors.push(colors[i].clone());}
|
922 | var faces=source.faces;for(i=0,il=faces.length;i<il;i++){this.faces.push(faces[i].clone());}
|
923 | for(i=0,il=source.faceVertexUvs.length;i<il;i++){var faceVertexUvs=source.faceVertexUvs[i];if(this.faceVertexUvs[i]===undefined){this.faceVertexUvs[i]=[];}for(j=0,jl=faceVertexUvs.length;j<jl;j++){var uvs=faceVertexUvs[j],uvsCopy=[];for(k=0,kl=uvs.length;k<kl;k++){var uv=uvs[k];uvsCopy.push(uv.clone());}this.faceVertexUvs[i].push(uvsCopy);}}
|
924 | var morphTargets=source.morphTargets;for(i=0,il=morphTargets.length;i<il;i++){var morphTarget={};morphTarget.name=morphTargets[i].name;
|
925 | if(morphTargets[i].vertices!==undefined){morphTarget.vertices=[];for(j=0,jl=morphTargets[i].vertices.length;j<jl;j++){morphTarget.vertices.push(morphTargets[i].vertices[j].clone());}}
|
926 | if(morphTargets[i].normals!==undefined){morphTarget.normals=[];for(j=0,jl=morphTargets[i].normals.length;j<jl;j++){morphTarget.normals.push(morphTargets[i].normals[j].clone());}}this.morphTargets.push(morphTarget);}
|
927 | var morphNormals=source.morphNormals;for(i=0,il=morphNormals.length;i<il;i++){var morphNormal={};
|
928 | if(morphNormals[i].vertexNormals!==undefined){morphNormal.vertexNormals=[];for(j=0,jl=morphNormals[i].vertexNormals.length;j<jl;j++){var srcVertexNormal=morphNormals[i].vertexNormals[j];var destVertexNormal={};destVertexNormal.a=srcVertexNormal.a.clone();destVertexNormal.b=srcVertexNormal.b.clone();destVertexNormal.c=srcVertexNormal.c.clone();morphNormal.vertexNormals.push(destVertexNormal);}}
|
929 | if(morphNormals[i].faceNormals!==undefined){morphNormal.faceNormals=[];for(j=0,jl=morphNormals[i].faceNormals.length;j<jl;j++){morphNormal.faceNormals.push(morphNormals[i].faceNormals[j].clone());}}this.morphNormals.push(morphNormal);}
|
930 | var skinWeights=source.skinWeights;for(i=0,il=skinWeights.length;i<il;i++){this.skinWeights.push(skinWeights[i].clone());}
|
931 | var skinIndices=source.skinIndices;for(i=0,il=skinIndices.length;i<il;i++){this.skinIndices.push(skinIndices[i].clone());}
|
932 | var lineDistances=source.lineDistances;for(i=0,il=lineDistances.length;i<il;i++){this.lineDistances.push(lineDistances[i]);}
|
933 | var boundingBox=source.boundingBox;if(boundingBox!==null){this.boundingBox=boundingBox.clone();}
|
934 | var boundingSphere=source.boundingSphere;if(boundingSphere!==null){this.boundingSphere=boundingSphere.clone();}
|
935 | this.elementsNeedUpdate=source.elementsNeedUpdate;this.verticesNeedUpdate=source.verticesNeedUpdate;this.uvsNeedUpdate=source.uvsNeedUpdate;this.normalsNeedUpdate=source.normalsNeedUpdate;this.colorsNeedUpdate=source.colorsNeedUpdate;this.lineDistancesNeedUpdate=source.lineDistancesNeedUpdate;this.groupsNeedUpdate=source.groupsNeedUpdate;return this;},dispose:function dispose(){this.dispatchEvent({type:'dispose'});}}); |
936 |
|
937 |
|
938 |
|
939 | var BoxGeometry=function(_Geometry){_inheritsLoose(BoxGeometry,_Geometry);function BoxGeometry(width,height,depth,widthSegments,heightSegments,depthSegments){var _this2;_this2=_Geometry.call(this)||this;_this2.type='BoxGeometry';_this2.parameters={width:width,height:height,depth:depth,widthSegments:widthSegments,heightSegments:heightSegments,depthSegments:depthSegments};_this2.fromBufferGeometry(new BoxBufferGeometry(width,height,depth,widthSegments,heightSegments,depthSegments));_this2.mergeVertices();return _this2;}return BoxGeometry;}(Geometry);
|
940 | var BoxBufferGeometry=function(_BufferGeometry){_inheritsLoose(BoxBufferGeometry,_BufferGeometry);function BoxBufferGeometry(width,height,depth,widthSegments,heightSegments,depthSegments){var _this3;_this3=_BufferGeometry.call(this)||this;_this3.type='BoxBufferGeometry';_this3.parameters={width:width,height:height,depth:depth,widthSegments:widthSegments,heightSegments:heightSegments,depthSegments:depthSegments};var scope=_assertThisInitialized(_this3);width=width||1;height=height||1;depth=depth||1;
|
941 | widthSegments=Math.floor(widthSegments)||1;heightSegments=Math.floor(heightSegments)||1;depthSegments=Math.floor(depthSegments)||1;
|
942 | var indices=[];var vertices=[];var normals=[];var uvs=[];
|
943 | var numberOfVertices=0;var groupStart=0;
|
944 | buildPlane('z','y','x',-1,-1,depth,height,width,depthSegments,heightSegments,0);
|
945 | buildPlane('z','y','x',1,-1,depth,height,-width,depthSegments,heightSegments,1);
|
946 | buildPlane('x','z','y',1,1,width,depth,height,widthSegments,depthSegments,2);
|
947 | buildPlane('x','z','y',1,-1,width,depth,-height,widthSegments,depthSegments,3);
|
948 | buildPlane('x','y','z',1,-1,width,height,depth,widthSegments,heightSegments,4);
|
949 | buildPlane('x','y','z',-1,-1,width,height,-depth,widthSegments,heightSegments,5);
|
950 |
|
951 | _this3.setIndex(indices);_this3.setAttribute('position',new Float32BufferAttribute(vertices,3));_this3.setAttribute('normal',new Float32BufferAttribute(normals,3));_this3.setAttribute('uv',new Float32BufferAttribute(uvs,2));function buildPlane(u,v,w,udir,vdir,width,height,depth,gridX,gridY,materialIndex){var segmentWidth=width/gridX;var segmentHeight=height/gridY;var widthHalf=width/2;var heightHalf=height/2;var depthHalf=depth/2;var gridX1=gridX+1;var gridY1=gridY+1;var vertexCounter=0;var groupCount=0;var ix,iy;var vector=new Vector3();
|
952 | for(iy=0;iy<gridY1;iy++){var y=iy*segmentHeight-heightHalf;for(ix=0;ix<gridX1;ix++){var x=ix*segmentWidth-widthHalf;
|
953 | vector[u]=x*udir;vector[v]=y*vdir;vector[w]=depthHalf;
|
954 | vertices.push(vector.x,vector.y,vector.z);
|
955 | vector[u]=0;vector[v]=0;vector[w]=depth>0?1:-1;
|
956 | normals.push(vector.x,vector.y,vector.z);
|
957 | uvs.push(ix/gridX);uvs.push(1-iy/gridY);
|
958 | vertexCounter+=1;}}
|
959 |
|
960 |
|
961 |
|
962 | for(iy=0;iy<gridY;iy++){for(ix=0;ix<gridX;ix++){var a=numberOfVertices+ix+gridX1*iy;var b=numberOfVertices+ix+gridX1*(iy+1);var c=numberOfVertices+(ix+1)+gridX1*(iy+1);var d=numberOfVertices+(ix+1)+gridX1*iy;
|
963 | indices.push(a,b,d);indices.push(b,c,d);
|
964 | groupCount+=6;}}
|
965 | scope.addGroup(groupStart,groupCount,materialIndex);
|
966 | groupStart+=groupCount;
|
967 | numberOfVertices+=vertexCounter;}return _this3;}return BoxBufferGeometry;}(BufferGeometry); |
968 |
|
969 | function cloneUniforms(src){var dst={};for(var u in src){dst[u]={};for(var p in src[u]){var property=src[u][p];if(property&&(property.isColor||property.isMatrix3||property.isMatrix4||property.isVector2||property.isVector3||property.isVector4||property.isTexture)){dst[u][p]=property.clone();}else if(Array.isArray(property)){dst[u][p]=property.slice();}else {dst[u][p]=property;}}}return dst;}function mergeUniforms(uniforms){var merged={};for(var u=0;u<uniforms.length;u++){var tmp=cloneUniforms(uniforms[u]);for(var p in tmp){merged[p]=tmp[p];}}return merged;}
|
970 | var UniformsUtils={clone:cloneUniforms,merge:mergeUniforms};var default_vertex="void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}";var default_fragment="void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}"; |
971 |
|
972 |
|
973 |
|
974 |
|
975 |
|
976 |
|
977 |
|
978 |
|
979 |
|
980 |
|
981 |
|
982 |
|
983 |
|
984 |
|
985 |
|
986 |
|
987 |
|
988 |
|
989 | function ShaderMaterial(parameters){Material.call(this);this.type='ShaderMaterial';this.defines={};this.uniforms={};this.vertexShader=default_vertex;this.fragmentShader=default_fragment;this.linewidth=1;this.wireframe=false;this.wireframeLinewidth=1;this.fog=false;
|
990 | this.lights=false;
|
991 | this.clipping=false;
|
992 | this.skinning=false;
|
993 | this.morphTargets=false;
|
994 | this.morphNormals=false;
|
995 | this.extensions={derivatives:false,
|
996 | fragDepth:false,
|
997 | drawBuffers:false,
|
998 | shaderTextureLOD:false
|
999 | };
|
1000 |
|
1001 | this.defaultAttributeValues={'color':[1,1,1],'uv':[0,0],'uv2':[0,0]};this.index0AttributeName=undefined;this.uniformsNeedUpdate=false;if(parameters!==undefined){if(parameters.attributes!==undefined){console.error('THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.');}this.setValues(parameters);}}ShaderMaterial.prototype=Object.create(Material.prototype);ShaderMaterial.prototype.constructor=ShaderMaterial;ShaderMaterial.prototype.isShaderMaterial=true;ShaderMaterial.prototype.copy=function(source){Material.prototype.copy.call(this,source);this.fragmentShader=source.fragmentShader;this.vertexShader=source.vertexShader;this.uniforms=cloneUniforms(source.uniforms);this.defines=_extends({},source.defines);this.wireframe=source.wireframe;this.wireframeLinewidth=source.wireframeLinewidth;this.lights=source.lights;this.clipping=source.clipping;this.skinning=source.skinning;this.morphTargets=source.morphTargets;this.morphNormals=source.morphNormals;this.extensions=source.extensions;return this;};ShaderMaterial.prototype.toJSON=function(meta){var data=Material.prototype.toJSON.call(this,meta);data.uniforms={};for(var name in this.uniforms){var uniform=this.uniforms[name];var value=uniform.value;if(value&&value.isTexture){data.uniforms[name]={type:'t',value:value.toJSON(meta).uuid};}else if(value&&value.isColor){data.uniforms[name]={type:'c',value:value.getHex()};}else if(value&&value.isVector2){data.uniforms[name]={type:'v2',value:value.toArray()};}else if(value&&value.isVector3){data.uniforms[name]={type:'v3',value:value.toArray()};}else if(value&&value.isVector4){data.uniforms[name]={type:'v4',value:value.toArray()};}else if(value&&value.isMatrix3){data.uniforms[name]={type:'m3',value:value.toArray()};}else if(value&&value.isMatrix4){data.uniforms[name]={type:'m4',value:value.toArray()};}else {data.uniforms[name]={value:value};
|
1002 | }}if(Object.keys(this.defines).length>0)data.defines=this.defines;data.vertexShader=this.vertexShader;data.fragmentShader=this.fragmentShader;var extensions={};for(var key in this.extensions){if(this.extensions[key]===true)extensions[key]=true;}if(Object.keys(extensions).length>0)data.extensions=extensions;return data;}; |
1003 |
|
1004 |
|
1005 |
|
1006 | function Camera(){Object3D.call(this);this.type='Camera';this.matrixWorldInverse=new Matrix4();this.projectionMatrix=new Matrix4();this.projectionMatrixInverse=new Matrix4();}Camera.prototype=_extends(Object.create(Object3D.prototype),{constructor:Camera,isCamera:true,copy:function copy(source,recursive){Object3D.prototype.copy.call(this,source,recursive);this.matrixWorldInverse.copy(source.matrixWorldInverse);this.projectionMatrix.copy(source.projectionMatrix);this.projectionMatrixInverse.copy(source.projectionMatrixInverse);return this;},getWorldDirection:function getWorldDirection(target){if(target===undefined){console.warn('THREE.Camera: .getWorldDirection() target is now required');target=new Vector3();}this.updateMatrixWorld(true);var e=this.matrixWorld.elements;return target.set(-e[8],-e[9],-e[10]).normalize();},updateMatrixWorld:function updateMatrixWorld(force){Object3D.prototype.updateMatrixWorld.call(this,force);this.matrixWorldInverse.getInverse(this.matrixWorld);},updateWorldMatrix:function updateWorldMatrix(updateParents,updateChildren){Object3D.prototype.updateWorldMatrix.call(this,updateParents,updateChildren);this.matrixWorldInverse.getInverse(this.matrixWorld);},clone:function clone(){return new this.constructor().copy(this);}}); |
1007 |
|
1008 |
|
1009 |
|
1010 |
|
1011 | function PerspectiveCamera(fov,aspect,near,far){Camera.call(this);this.type='PerspectiveCamera';this.fov=fov!==undefined?fov:50;this.zoom=1;this.near=near!==undefined?near:0.1;this.far=far!==undefined?far:2000;this.focus=10;this.aspect=aspect!==undefined?aspect:1;this.view=null;this.filmGauge=35;
|
1012 | this.filmOffset=0;
|
1013 | this.updateProjectionMatrix();}PerspectiveCamera.prototype=_extends(Object.create(Camera.prototype),{constructor:PerspectiveCamera,isPerspectiveCamera:true,copy:function copy(source,recursive){Camera.prototype.copy.call(this,source,recursive);this.fov=source.fov;this.zoom=source.zoom;this.near=source.near;this.far=source.far;this.focus=source.focus;this.aspect=source.aspect;this.view=source.view===null?null:_extends({},source.view);this.filmGauge=source.filmGauge;this.filmOffset=source.filmOffset;return this;}, |
1014 |
|
1015 |
|
1016 |
|
1017 |
|
1018 |
|
1019 |
|
1020 | setFocalLength:function setFocalLength(focalLength){
|
1021 | var vExtentSlope=0.5*this.getFilmHeight()/focalLength;this.fov=MathUtils.RAD2DEG*2*Math.atan(vExtentSlope);this.updateProjectionMatrix();}, |
1022 |
|
1023 | getFocalLength:function getFocalLength(){var vExtentSlope=Math.tan(MathUtils.DEG2RAD*0.5*this.fov);return 0.5*this.getFilmHeight()/vExtentSlope;},getEffectiveFOV:function getEffectiveFOV(){return MathUtils.RAD2DEG*2*Math.atan(Math.tan(MathUtils.DEG2RAD*0.5*this.fov)/this.zoom);},getFilmWidth:function getFilmWidth(){
|
1024 | return this.filmGauge*Math.min(this.aspect,1);},getFilmHeight:function getFilmHeight(){
|
1025 | return this.filmGauge/Math.max(this.aspect,1);}, |
1026 |
|
1027 |
|
1028 |
|
1029 |
|
1030 |
|
1031 |
|
1032 |
|
1033 |
|
1034 |
|
1035 |
|
1036 |
|
1037 |
|
1038 |
|
1039 |
|
1040 |
|
1041 |
|
1042 |
|
1043 |
|
1044 |
|
1045 |
|
1046 |
|
1047 |
|
1048 |
|
1049 |
|
1050 |
|
1051 |
|
1052 |
|
1053 |
|
1054 |
|
1055 |
|
1056 |
|
1057 |
|
1058 |
|
1059 | setViewOffset:function setViewOffset(fullWidth,fullHeight,x,y,width,height){this.aspect=fullWidth/fullHeight;if(this.view===null){this.view={enabled:true,fullWidth:1,fullHeight:1,offsetX:0,offsetY:0,width:1,height:1};}this.view.enabled=true;this.view.fullWidth=fullWidth;this.view.fullHeight=fullHeight;this.view.offsetX=x;this.view.offsetY=y;this.view.width=width;this.view.height=height;this.updateProjectionMatrix();},clearViewOffset:function clearViewOffset(){if(this.view!==null){this.view.enabled=false;}this.updateProjectionMatrix();},updateProjectionMatrix:function updateProjectionMatrix(){var near=this.near,top=near*Math.tan(MathUtils.DEG2RAD*0.5*this.fov)/this.zoom,height=2*top,width=this.aspect*height,left=-0.5*width,view=this.view;if(this.view!==null&&this.view.enabled){var fullWidth=view.fullWidth,fullHeight=view.fullHeight;left+=view.offsetX*width/fullWidth;top-=view.offsetY*height/fullHeight;width*=view.width/fullWidth;height*=view.height/fullHeight;}var skew=this.filmOffset;if(skew!==0)left+=near*skew/this.getFilmWidth();this.projectionMatrix.makePerspective(left,left+width,top,top-height,near,this.far);this.projectionMatrixInverse.getInverse(this.projectionMatrix);},toJSON:function toJSON(meta){var data=Object3D.prototype.toJSON.call(this,meta);data.object.fov=this.fov;data.object.zoom=this.zoom;data.object.near=this.near;data.object.far=this.far;data.object.focus=this.focus;data.object.aspect=this.aspect;if(this.view!==null)data.object.view=_extends({},this.view);data.object.filmGauge=this.filmGauge;data.object.filmOffset=this.filmOffset;return data;}}); |
1060 |
|
1061 |
|
1062 |
|
1063 |
|
1064 | var fov=90,aspect=1;function CubeCamera(near,far,cubeResolution,options){Object3D.call(this);this.type='CubeCamera';var cameraPX=new PerspectiveCamera(fov,aspect,near,far);cameraPX.up.set(0,-1,0);cameraPX.lookAt(new Vector3(1,0,0));this.add(cameraPX);var cameraNX=new PerspectiveCamera(fov,aspect,near,far);cameraNX.up.set(0,-1,0);cameraNX.lookAt(new Vector3(-1,0,0));this.add(cameraNX);var cameraPY=new PerspectiveCamera(fov,aspect,near,far);cameraPY.up.set(0,0,1);cameraPY.lookAt(new Vector3(0,1,0));this.add(cameraPY);var cameraNY=new PerspectiveCamera(fov,aspect,near,far);cameraNY.up.set(0,0,-1);cameraNY.lookAt(new Vector3(0,-1,0));this.add(cameraNY);var cameraPZ=new PerspectiveCamera(fov,aspect,near,far);cameraPZ.up.set(0,-1,0);cameraPZ.lookAt(new Vector3(0,0,1));this.add(cameraPZ);var cameraNZ=new PerspectiveCamera(fov,aspect,near,far);cameraNZ.up.set(0,-1,0);cameraNZ.lookAt(new Vector3(0,0,-1));this.add(cameraNZ);options=options||{format:RGBFormat,magFilter:LinearFilter,minFilter:LinearFilter};this.renderTarget=new WebGLCubeRenderTarget(cubeResolution,options);this.renderTarget.texture.name="CubeCamera";this.update=function(renderer,scene){if(this.parent===null)this.updateMatrixWorld();var currentRenderTarget=renderer.getRenderTarget();var renderTarget=this.renderTarget;var generateMipmaps=renderTarget.texture.generateMipmaps;renderTarget.texture.generateMipmaps=false;renderer.setRenderTarget(renderTarget,0);renderer.render(scene,cameraPX);renderer.setRenderTarget(renderTarget,1);renderer.render(scene,cameraNX);renderer.setRenderTarget(renderTarget,2);renderer.render(scene,cameraPY);renderer.setRenderTarget(renderTarget,3);renderer.render(scene,cameraNY);renderer.setRenderTarget(renderTarget,4);renderer.render(scene,cameraPZ);renderTarget.texture.generateMipmaps=generateMipmaps;renderer.setRenderTarget(renderTarget,5);renderer.render(scene,cameraNZ);renderer.setRenderTarget(currentRenderTarget);};this.clear=function(renderer,color,depth,stencil){var currentRenderTarget=renderer.getRenderTarget();var renderTarget=this.renderTarget;for(var i=0;i<6;i++){renderer.setRenderTarget(renderTarget,i);renderer.clear(color,depth,stencil);}renderer.setRenderTarget(currentRenderTarget);};}CubeCamera.prototype=Object.create(Object3D.prototype);CubeCamera.prototype.constructor=CubeCamera; |
1065 |
|
1066 |
|
1067 | function WebGLCubeRenderTarget(size,options,dummy){if(Number.isInteger(options)){console.warn('THREE.WebGLCubeRenderTarget: constructor signature is now WebGLCubeRenderTarget( size, options )');options=dummy;}WebGLRenderTarget.call(this,size,size,options);}WebGLCubeRenderTarget.prototype=Object.create(WebGLRenderTarget.prototype);WebGLCubeRenderTarget.prototype.constructor=WebGLCubeRenderTarget;WebGLCubeRenderTarget.prototype.isWebGLCubeRenderTarget=true;WebGLCubeRenderTarget.prototype.fromEquirectangularTexture=function(renderer,texture){this.texture.type=texture.type;this.texture.format=texture.format;this.texture.encoding=texture.encoding;var scene=new Scene();var shader={uniforms:{tEquirect:{value:null}},vertexShader:["varying vec3 vWorldDirection;","vec3 transformDirection( in vec3 dir, in mat4 matrix ) {"," return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );","}","void main() {"," vWorldDirection = transformDirection( position, modelMatrix );"," #include <begin_vertex>"," #include <project_vertex>","}"].join('\n'),fragmentShader:["uniform sampler2D tEquirect;","varying vec3 vWorldDirection;","#define RECIPROCAL_PI 0.31830988618","#define RECIPROCAL_PI2 0.15915494","void main() {"," vec3 direction = normalize( vWorldDirection );"," vec2 sampleUV;"," sampleUV.y = asin( clamp( direction.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;"," sampleUV.x = atan( direction.z, direction.x ) * RECIPROCAL_PI2 + 0.5;"," gl_FragColor = texture2D( tEquirect, sampleUV );","}"].join('\n')};var material=new ShaderMaterial({type:'CubemapFromEquirect',uniforms:cloneUniforms(shader.uniforms),vertexShader:shader.vertexShader,fragmentShader:shader.fragmentShader,side:BackSide,blending:NoBlending});material.uniforms.tEquirect.value=texture;var mesh=new Mesh(new BoxBufferGeometry(5,5,5),material);scene.add(mesh);var camera=new CubeCamera(1,10,1);camera.renderTarget=this;camera.renderTarget.texture.name='CubeCameraTexture';camera.update(renderer,scene);mesh.geometry.dispose();mesh.material.dispose();return this;}; |
1068 |
|
1069 | function DataTexture(data,width,height,format,type,mapping,wrapS,wrapT,magFilter,minFilter,anisotropy,encoding){Texture.call(this,null,mapping,wrapS,wrapT,magFilter,minFilter,format,type,anisotropy,encoding);this.image={data:data||null,width:width||1,height:height||1};this.magFilter=magFilter!==undefined?magFilter:NearestFilter;this.minFilter=minFilter!==undefined?minFilter:NearestFilter;this.generateMipmaps=false;this.flipY=false;this.unpackAlignment=1;this.needsUpdate=true;}DataTexture.prototype=Object.create(Texture.prototype);DataTexture.prototype.constructor=DataTexture;DataTexture.prototype.isDataTexture=true; |
1070 |
|
1071 |
|
1072 |
|
1073 | var _sphere$1=new Sphere();var _vector$5=new Vector3();function Frustum(p0,p1,p2,p3,p4,p5){this.planes=[p0!==undefined?p0:new Plane(),p1!==undefined?p1:new Plane(),p2!==undefined?p2:new Plane(),p3!==undefined?p3:new Plane(),p4!==undefined?p4:new Plane(),p5!==undefined?p5:new Plane()];}_extends(Frustum.prototype,{set:function set(p0,p1,p2,p3,p4,p5){var planes=this.planes;planes[0].copy(p0);planes[1].copy(p1);planes[2].copy(p2);planes[3].copy(p3);planes[4].copy(p4);planes[5].copy(p5);return this;},clone:function clone(){return new this.constructor().copy(this);},copy:function copy(frustum){var planes=this.planes;for(var i=0;i<6;i++){planes[i].copy(frustum.planes[i]);}return this;},setFromProjectionMatrix:function setFromProjectionMatrix(m){var planes=this.planes;var me=m.elements;var me0=me[0],me1=me[1],me2=me[2],me3=me[3];var me4=me[4],me5=me[5],me6=me[6],me7=me[7];var me8=me[8],me9=me[9],me10=me[10],me11=me[11];var me12=me[12],me13=me[13],me14=me[14],me15=me[15];planes[0].setComponents(me3-me0,me7-me4,me11-me8,me15-me12).normalize();planes[1].setComponents(me3+me0,me7+me4,me11+me8,me15+me12).normalize();planes[2].setComponents(me3+me1,me7+me5,me11+me9,me15+me13).normalize();planes[3].setComponents(me3-me1,me7-me5,me11-me9,me15-me13).normalize();planes[4].setComponents(me3-me2,me7-me6,me11-me10,me15-me14).normalize();planes[5].setComponents(me3+me2,me7+me6,me11+me10,me15+me14).normalize();return this;},intersectsObject:function intersectsObject(object){var geometry=object.geometry;if(geometry.boundingSphere===null)geometry.computeBoundingSphere();_sphere$1.copy(geometry.boundingSphere).applyMatrix4(object.matrixWorld);return this.intersectsSphere(_sphere$1);},intersectsSprite:function intersectsSprite(sprite){_sphere$1.center.set(0,0,0);_sphere$1.radius=0.7071067811865476;_sphere$1.applyMatrix4(sprite.matrixWorld);return this.intersectsSphere(_sphere$1);},intersectsSphere:function intersectsSphere(sphere){var planes=this.planes;var center=sphere.center;var negRadius=-sphere.radius;for(var i=0;i<6;i++){var distance=planes[i].distanceToPoint(center);if(distance<negRadius){return false;}}return true;},intersectsBox:function intersectsBox(box){var planes=this.planes;for(var i=0;i<6;i++){var plane=planes[i];
|
1074 | _vector$5.x=plane.normal.x>0?box.max.x:box.min.x;_vector$5.y=plane.normal.y>0?box.max.y:box.min.y;_vector$5.z=plane.normal.z>0?box.max.z:box.min.z;if(plane.distanceToPoint(_vector$5)<0){return false;}}return true;},containsPoint:function containsPoint(point){var planes=this.planes;for(var i=0;i<6;i++){if(planes[i].distanceToPoint(point)<0){return false;}}return true;}}); |
1075 |
|
1076 | var UniformsLib={common:{diffuse:{value:new Color(0xeeeeee)},opacity:{value:1.0},map:{value:null},uvTransform:{value:new Matrix3()},uv2Transform:{value:new Matrix3()},alphaMap:{value:null}},specularmap:{specularMap:{value:null}},envmap:{envMap:{value:null},flipEnvMap:{value:-1},reflectivity:{value:1.0},refractionRatio:{value:0.98},maxMipLevel:{value:0}},aomap:{aoMap:{value:null},aoMapIntensity:{value:1}},lightmap:{lightMap:{value:null},lightMapIntensity:{value:1}},emissivemap:{emissiveMap:{value:null}},bumpmap:{bumpMap:{value:null},bumpScale:{value:1}},normalmap:{normalMap:{value:null},normalScale:{value:new Vector2(1,1)}},displacementmap:{displacementMap:{value:null},displacementScale:{value:1},displacementBias:{value:0}},roughnessmap:{roughnessMap:{value:null}},metalnessmap:{metalnessMap:{value:null}},gradientmap:{gradientMap:{value:null}},fog:{fogDensity:{value:0.00025},fogNear:{value:1},fogFar:{value:2000},fogColor:{value:new Color(0xffffff)}},lights:{ambientLightColor:{value:[]},lightProbe:{value:[]},directionalLights:{value:[],properties:{direction:{},color:{}}},directionalLightShadows:{value:[],properties:{shadowBias:{},shadowRadius:{},shadowMapSize:{}}},directionalShadowMap:{value:[]},directionalShadowMatrix:{value:[]},spotLights:{value:[],properties:{color:{},position:{},direction:{},distance:{},coneCos:{},penumbraCos:{},decay:{}}},spotLightShadows:{value:[],properties:{shadowBias:{},shadowRadius:{},shadowMapSize:{}}},spotShadowMap:{value:[]},spotShadowMatrix:{value:[]},pointLights:{value:[],properties:{color:{},position:{},decay:{},distance:{}}},pointLightShadows:{value:[],properties:{shadowBias:{},shadowRadius:{},shadowMapSize:{},shadowCameraNear:{},shadowCameraFar:{}}},pointShadowMap:{value:[]},pointShadowMatrix:{value:[]},hemisphereLights:{value:[],properties:{direction:{},skyColor:{},groundColor:{}}},
|
1077 | rectAreaLights:{value:[],properties:{color:{},position:{},width:{},height:{}}}},points:{diffuse:{value:new Color(0xeeeeee)},opacity:{value:1.0},size:{value:1.0},scale:{value:1.0},map:{value:null},alphaMap:{value:null},uvTransform:{value:new Matrix3()}},sprite:{diffuse:{value:new Color(0xeeeeee)},opacity:{value:1.0},center:{value:new Vector2(0.5,0.5)},rotation:{value:0.0},map:{value:null},alphaMap:{value:null},uvTransform:{value:new Matrix3()}}}; |
1078 |
|
1079 | function WebGLAnimation(){var context=null;var isAnimating=false;var animationLoop=null;function onAnimationFrame(time,frame){if(isAnimating===false)return;animationLoop(time,frame);context.requestAnimationFrame(onAnimationFrame);}return {start:function start(){if(isAnimating===true)return;if(animationLoop===null)return;context.requestAnimationFrame(onAnimationFrame);isAnimating=true;},stop:function stop(){isAnimating=false;},setAnimationLoop:function setAnimationLoop(callback){animationLoop=callback;},setContext:function setContext(value){context=value;}};} |
1080 |
|
1081 | function WebGLAttributes(gl,capabilities){var isWebGL2=capabilities.isWebGL2;var buffers=new WeakMap();function createBuffer(attribute,bufferType){var array=attribute.array;var usage=attribute.usage;var buffer=gl.createBuffer();gl.bindBuffer(bufferType,buffer);gl.bufferData(bufferType,array,usage);attribute.onUploadCallback();var type=5126;if(array instanceof Float32Array){type=5126;}else if(array instanceof Float64Array){console.warn('THREE.WebGLAttributes: Unsupported data buffer format: Float64Array.');}else if(array instanceof Uint16Array){type=5123;}else if(array instanceof Int16Array){type=5122;}else if(array instanceof Uint32Array){type=5125;}else if(array instanceof Int32Array){type=5124;}else if(array instanceof Int8Array){type=5120;}else if(array instanceof Uint8Array){type=5121;}return {buffer:buffer,type:type,bytesPerElement:array.BYTES_PER_ELEMENT,version:attribute.version};}function updateBuffer(buffer,attribute,bufferType){var array=attribute.array;var updateRange=attribute.updateRange;gl.bindBuffer(bufferType,buffer);if(updateRange.count===-1){
|
1082 | gl.bufferSubData(bufferType,0,array);}else {if(isWebGL2){gl.bufferSubData(bufferType,updateRange.offset*array.BYTES_PER_ELEMENT,array,updateRange.offset,updateRange.count);}else {gl.bufferSubData(bufferType,updateRange.offset*array.BYTES_PER_ELEMENT,array.subarray(updateRange.offset,updateRange.offset+updateRange.count));}updateRange.count=-1;
|
1083 | }}
|
1084 | function get(attribute){if(attribute.isInterleavedBufferAttribute)attribute=attribute.data;return buffers.get(attribute);}function remove(attribute){if(attribute.isInterleavedBufferAttribute)attribute=attribute.data;var data=buffers.get(attribute);if(data){gl.deleteBuffer(data.buffer);buffers["delete"](attribute);}}function update(attribute,bufferType){if(attribute.isInterleavedBufferAttribute)attribute=attribute.data;var data=buffers.get(attribute);if(data===undefined){buffers.set(attribute,createBuffer(attribute,bufferType));}else if(data.version<attribute.version){updateBuffer(data.buffer,attribute,bufferType);data.version=attribute.version;}}return {get:get,remove:remove,update:update};}/**
|
1085 | * @author mrdoob / http://mrdoob.com/
|
1086 | * @author Mugen87 / https://github.com/Mugen87
|
1087 | */ // PlaneGeometry
|
1088 | function PlaneGeometry(width,height,widthSegments,heightSegments){Geometry.call(this);this.type='PlaneGeometry';this.parameters={width:width,height:height,widthSegments:widthSegments,heightSegments:heightSegments};this.fromBufferGeometry(new PlaneBufferGeometry(width,height,widthSegments,heightSegments));this.mergeVertices();}PlaneGeometry.prototype=Object.create(Geometry.prototype);PlaneGeometry.prototype.constructor=PlaneGeometry;
|
1089 | function PlaneBufferGeometry(width,height,widthSegments,heightSegments){BufferGeometry.call(this);this.type='PlaneBufferGeometry';this.parameters={width:width,height:height,widthSegments:widthSegments,heightSegments:heightSegments};width=width||1;height=height||1;var width_half=width/2;var height_half=height/2;var gridX=Math.floor(widthSegments)||1;var gridY=Math.floor(heightSegments)||1;var gridX1=gridX+1;var gridY1=gridY+1;var segment_width=width/gridX;var segment_height=height/gridY;var ix,iy;
|
1090 | var indices=[];var vertices=[];var normals=[];var uvs=[];
|
1091 | for(iy=0;iy<gridY1;iy++){var y=iy*segment_height-height_half;for(ix=0;ix<gridX1;ix++){var x=ix*segment_width-width_half;vertices.push(x,-y,0);normals.push(0,0,1);uvs.push(ix/gridX);uvs.push(1-iy/gridY);}}
|
1092 | for(iy=0;iy<gridY;iy++){for(ix=0;ix<gridX;ix++){var a=ix+gridX1*iy;var b=ix+gridX1*(iy+1);var c=ix+1+gridX1*(iy+1);var d=ix+1+gridX1*iy;
|
1093 | indices.push(a,b,d);indices.push(b,c,d);}}
|
1094 | this.setIndex(indices);this.setAttribute('position',new Float32BufferAttribute(vertices,3));this.setAttribute('normal',new Float32BufferAttribute(normals,3));this.setAttribute('uv',new Float32BufferAttribute(uvs,2));}PlaneBufferGeometry.prototype=Object.create(BufferGeometry.prototype);PlaneBufferGeometry.prototype.constructor=PlaneBufferGeometry;var alphamap_fragment="#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif";var alphamap_pars_fragment="#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif";var alphatest_fragment="#ifdef ALPHATEST\n\tif ( diffuseColor.a < ALPHATEST ) discard;\n#endif";var aomap_fragment="#ifdef USE_AOMAP\n\tfloat ambientOcclusion = ( texture2D( aoMap, vUv2 ).r - 1.0 ) * aoMapIntensity + 1.0;\n\treflectedLight.indirectDiffuse *= ambientOcclusion;\n\t#if defined( USE_ENVMAP ) && defined( STANDARD )\n\t\tfloat dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n\t\treflectedLight.indirectSpecular *= computeSpecularOcclusion( dotNV, ambientOcclusion, material.specularRoughness );\n\t#endif\n#endif";var aomap_pars_fragment="#ifdef USE_AOMAP\n\tuniform sampler2D aoMap;\n\tuniform float aoMapIntensity;\n#endif";var begin_vertex="vec3 transformed = vec3( position );";var beginnormal_vertex="vec3 objectNormal = vec3( normal );\n#ifdef USE_TANGENT\n\tvec3 objectTangent = vec3( tangent.xyz );\n#endif";var bsdfs="vec2 integrateSpecularBRDF( const in float dotNV, const in float roughness ) {\n\tconst vec4 c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 );\n\tconst vec4 c1 = vec4( 1, 0.0425, 1.04, - 0.04 );\n\tvec4 r = roughness * c0 + c1;\n\tfloat a004 = min( r.x * r.x, exp2( - 9.28 * dotNV ) ) * r.x + r.y;\n\treturn vec2( -1.04, 1.04 ) * a004 + r.zw;\n}\nfloat punctualLightIntensityToIrradianceFactor( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {\n#if defined ( PHYSICALLY_CORRECT_LIGHTS )\n\tfloat distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );\n\tif( cutoffDistance > 0.0 ) {\n\t\tdistanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );\n\t}\n\treturn distanceFalloff;\n#else\n\tif( cutoffDistance > 0.0 && decayExponent > 0.0 ) {\n\t\treturn pow( saturate( -lightDistance / cutoffDistance + 1.0 ), decayExponent );\n\t}\n\treturn 1.0;\n#endif\n}\nvec3 BRDF_Diffuse_Lambert( const in vec3 diffuseColor ) {\n\treturn RECIPROCAL_PI * diffuseColor;\n}\nvec3 F_Schlick( const in vec3 specularColor, const in float dotLH ) {\n\tfloat fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );\n\treturn ( 1.0 - specularColor ) * fresnel + specularColor;\n}\nvec3 F_Schlick_RoughnessDependent( const in vec3 F0, const in float dotNV, const in float roughness ) {\n\tfloat fresnel = exp2( ( -5.55473 * dotNV - 6.98316 ) * dotNV );\n\tvec3 Fr = max( vec3( 1.0 - roughness ), F0 ) - F0;\n\treturn Fr * fresnel + F0;\n}\nfloat G_GGX_Smith( const in float alpha, const in float dotNL, const in float dotNV ) {\n\tfloat a2 = pow2( alpha );\n\tfloat gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\n\tfloat gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\n\treturn 1.0 / ( gl * gv );\n}\nfloat G_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) {\n\tfloat a2 = pow2( alpha );\n\tfloat gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\n\tfloat gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\n\treturn 0.5 / max( gv + gl, EPSILON );\n}\nfloat D_GGX( const in float alpha, const in float dotNH ) {\n\tfloat a2 = pow2( alpha );\n\tfloat denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0;\n\treturn RECIPROCAL_PI * a2 / pow2( denom );\n}\nvec3 BRDF_Specular_GGX( const in IncidentLight incidentLight, const in vec3 viewDir, const in vec3 normal, const in vec3 specularColor, const in float roughness ) {\n\tfloat alpha = pow2( roughness );\n\tvec3 halfDir = normalize( incidentLight.direction + viewDir );\n\tfloat dotNL = saturate( dot( normal, incidentLight.direction ) );\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tfloat dotNH = saturate( dot( normal, halfDir ) );\n\tfloat dotLH = saturate( dot( incidentLight.direction, halfDir ) );\n\tvec3 F = F_Schlick( specularColor, dotLH );\n\tfloat G = G_GGX_SmithCorrelated( alpha, dotNL, dotNV );\n\tfloat D = D_GGX( alpha, dotNH );\n\treturn F * ( G * D );\n}\nvec2 LTC_Uv( const in vec3 N, const in vec3 V, const in float roughness ) {\n\tconst float LUT_SIZE = 64.0;\n\tconst float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE;\n\tconst float LUT_BIAS = 0.5 / LUT_SIZE;\n\tfloat dotNV = saturate( dot( N, V ) );\n\tvec2 uv = vec2( roughness, sqrt( 1.0 - dotNV ) );\n\tuv = uv * LUT_SCALE + LUT_BIAS;\n\treturn uv;\n}\nfloat LTC_ClippedSphereFormFactor( const in vec3 f ) {\n\tfloat l = length( f );\n\treturn max( ( l * l + f.z ) / ( l + 1.0 ), 0.0 );\n}\nvec3 LTC_EdgeVectorFormFactor( const in vec3 v1, const in vec3 v2 ) {\n\tfloat x = dot( v1, v2 );\n\tfloat y = abs( x );\n\tfloat a = 0.8543985 + ( 0.4965155 + 0.0145206 * y ) * y;\n\tfloat b = 3.4175940 + ( 4.1616724 + y ) * y;\n\tfloat v = a / b;\n\tfloat theta_sintheta = ( x > 0.0 ) ? v : 0.5 * inversesqrt( max( 1.0 - x * x, 1e-7 ) ) - v;\n\treturn cross( v1, v2 ) * theta_sintheta;\n}\nvec3 LTC_Evaluate( const in vec3 N, const in vec3 V, const in vec3 P, const in mat3 mInv, const in vec3 rectCoords[ 4 ] ) {\n\tvec3 v1 = rectCoords[ 1 ] - rectCoords[ 0 ];\n\tvec3 v2 = rectCoords[ 3 ] - rectCoords[ 0 ];\n\tvec3 lightNormal = cross( v1, v2 );\n\tif( dot( lightNormal, P - rectCoords[ 0 ] ) < 0.0 ) return vec3( 0.0 );\n\tvec3 T1, T2;\n\tT1 = normalize( V - N * dot( V, N ) );\n\tT2 = - cross( N, T1 );\n\tmat3 mat = mInv * transposeMat3( mat3( T1, T2, N ) );\n\tvec3 coords[ 4 ];\n\tcoords[ 0 ] = mat * ( rectCoords[ 0 ] - P );\n\tcoords[ 1 ] = mat * ( rectCoords[ 1 ] - P );\n\tcoords[ 2 ] = mat * ( rectCoords[ 2 ] - P );\n\tcoords[ 3 ] = mat * ( rectCoords[ 3 ] - P );\n\tcoords[ 0 ] = normalize( coords[ 0 ] );\n\tcoords[ 1 ] = normalize( coords[ 1 ] );\n\tcoords[ 2 ] = normalize( coords[ 2 ] );\n\tcoords[ 3 ] = normalize( coords[ 3 ] );\n\tvec3 vectorFormFactor = vec3( 0.0 );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 0 ], coords[ 1 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 1 ], coords[ 2 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 2 ], coords[ 3 ] );\n\tvectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 3 ], coords[ 0 ] );\n\tfloat result = LTC_ClippedSphereFormFactor( vectorFormFactor );\n\treturn vec3( result );\n}\nvec3 BRDF_Specular_GGX_Environment( const in vec3 viewDir, const in vec3 normal, const in vec3 specularColor, const in float roughness ) {\n\tfloat dotNV = saturate( dot( normal, viewDir ) );\n\tvec2 brdf = integrateSpecularBRDF( dotNV, roughness );\n\treturn specularColor * brdf.x + brdf.y;\n}\nvoid BRDF_Specular_Multiscattering_Environment( const in GeometricContext geometry, const in vec3 specularColor, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) {\n\tfloat dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n\tvec3 F = F_Schlick_RoughnessDependent( specularColor, dotNV, roughness );\n\tvec2 brdf = integrateSpecularBRDF( dotNV, roughness );\n\tvec3 FssEss = F * brdf.x + brdf.y;\n\tfloat Ess = brdf.x + brdf.y;\n\tfloat Ems = 1.0 - Ess;\n\tvec3 Favg = specularColor + ( 1.0 - specularColor ) * 0.047619;\tvec3 Fms = FssEss * Favg / ( 1.0 - Ems * Favg );\n\tsingleScatter += FssEss;\n\tmultiScatter += Fms * Ems;\n}\nfloat G_BlinnPhong_Implicit( ) {\n\treturn 0.25;\n}\nfloat D_BlinnPhong( const in float shininess, const in float dotNH ) {\n\treturn RECIPROCAL_PI * ( shininess * 0.5 + 1.0 ) * pow( dotNH, shininess );\n}\nvec3 BRDF_Specular_BlinnPhong( const in IncidentLight incidentLight, const in GeometricContext geometry, const in vec3 specularColor, const in float shininess ) {\n\tvec3 halfDir = normalize( incidentLight.direction + geometry.viewDir );\n\tfloat dotNH = saturate( dot( geometry.normal, halfDir ) );\n\tfloat dotLH = saturate( dot( incidentLight.direction, halfDir ) );\n\tvec3 F = F_Schlick( specularColor, dotLH );\n\tfloat G = G_BlinnPhong_Implicit( );\n\tfloat D = D_BlinnPhong( shininess, dotNH );\n\treturn F * ( G * D );\n}\nfloat GGXRoughnessToBlinnExponent( const in float ggxRoughness ) {\n\treturn ( 2.0 / pow2( ggxRoughness + 0.0001 ) - 2.0 );\n}\nfloat BlinnExponentToGGXRoughness( const in float blinnExponent ) {\n\treturn sqrt( 2.0 / ( blinnExponent + 2.0 ) );\n}\n#if defined( USE_SHEEN )\nfloat D_Charlie(float roughness, float NoH) {\n\tfloat invAlpha = 1.0 / roughness;\n\tfloat cos2h = NoH * NoH;\n\tfloat sin2h = max(1.0 - cos2h, 0.0078125);\treturn (2.0 + invAlpha) * pow(sin2h, invAlpha * 0.5) / (2.0 * PI);\n}\nfloat V_Neubelt(float NoV, float NoL) {\n\treturn saturate(1.0 / (4.0 * (NoL + NoV - NoL * NoV)));\n}\nvec3 BRDF_Specular_Sheen( const in float roughness, const in vec3 L, const in GeometricContext geometry, vec3 specularColor ) {\n\tvec3 N = geometry.normal;\n\tvec3 V = geometry.viewDir;\n\tvec3 H = normalize( V + L );\n\tfloat dotNH = saturate( dot( N, H ) );\n\treturn specularColor * D_Charlie( roughness, dotNH ) * V_Neubelt( dot(N, V), dot(N, L) );\n}\n#endif";var bumpmap_pars_fragment="#ifdef USE_BUMPMAP\n\tuniform sampler2D bumpMap;\n\tuniform float bumpScale;\n\tvec2 dHdxy_fwd() {\n\t\tvec2 dSTdx = dFdx( vUv );\n\t\tvec2 dSTdy = dFdy( vUv );\n\t\tfloat Hll = bumpScale * texture2D( bumpMap, vUv ).x;\n\t\tfloat dBx = bumpScale * texture2D( bumpMap, vUv + dSTdx ).x - Hll;\n\t\tfloat dBy = bumpScale * texture2D( bumpMap, vUv + dSTdy ).x - Hll;\n\t\treturn vec2( dBx, dBy );\n\t}\n\tvec3 perturbNormalArb( vec3 surf_pos, vec3 surf_norm, vec2 dHdxy ) {\n\t\tvec3 vSigmaX = vec3( dFdx( surf_pos.x ), dFdx( surf_pos.y ), dFdx( surf_pos.z ) );\n\t\tvec3 vSigmaY = vec3( dFdy( surf_pos.x ), dFdy( surf_pos.y ), dFdy( surf_pos.z ) );\n\t\tvec3 vN = surf_norm;\n\t\tvec3 R1 = cross( vSigmaY, vN );\n\t\tvec3 R2 = cross( vN, vSigmaX );\n\t\tfloat fDet = dot( vSigmaX, R1 );\n\t\tfDet *= ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t\tvec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 );\n\t\treturn normalize( abs( fDet ) * surf_norm - vGrad );\n\t}\n#endif";var clipping_planes_fragment="#if NUM_CLIPPING_PLANES > 0\n\tvec4 plane;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) {\n\t\tplane = clippingPlanes[ i ];\n\t\tif ( dot( vClipPosition, plane.xyz ) > plane.w ) discard;\n\t}\n\t#pragma unroll_loop_end\n\t#if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\n\t\tbool clipped = true;\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {\n\t\t\tplane = clippingPlanes[ i ];\n\t\t\tclipped = ( dot( vClipPosition, plane.xyz ) > plane.w ) && clipped;\n\t\t}\n\t\t#pragma unroll_loop_end\n\t\tif ( clipped ) discard;\n\t#endif\n#endif";var clipping_planes_pars_fragment="#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n\tuniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];\n#endif";var clipping_planes_pars_vertex="#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n#endif";var clipping_planes_vertex="#if NUM_CLIPPING_PLANES > 0\n\tvClipPosition = - mvPosition.xyz;\n#endif";var color_fragment="#ifdef USE_COLOR\n\tdiffuseColor.rgb *= vColor;\n#endif";var color_pars_fragment="#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";var color_pars_vertex="#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";var color_vertex="#ifdef USE_COLOR\n\tvColor.xyz = color.xyz;\n#endif";var common="#define PI 3.14159265359\n#define PI2 6.28318530718\n#define PI_HALF 1.5707963267949\n#define RECIPROCAL_PI 0.31830988618\n#define RECIPROCAL_PI2 0.15915494\n#define LOG2 1.442695\n#define EPSILON 1e-6\n#ifndef saturate\n#define saturate(a) clamp( a, 0.0, 1.0 )\n#endif\n#define whiteComplement(a) ( 1.0 - saturate( a ) )\nfloat pow2( const in float x ) { return x*x; }\nfloat pow3( const in float x ) { return x*x*x; }\nfloat pow4( const in float x ) { float x2 = x*x; return x2*x2; }\nfloat average( const in vec3 color ) { return dot( color, vec3( 0.3333 ) ); }\nhighp float rand( const in vec2 uv ) {\n\tconst highp float a = 12.9898, b = 78.233, c = 43758.5453;\n\thighp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );\n\treturn fract(sin(sn) * c);\n}\n#ifdef HIGH_PRECISION\n\tfloat precisionSafeLength( vec3 v ) { return length( v ); }\n#else\n\tfloat max3( vec3 v ) { return max( max( v.x, v.y ), v.z ); }\n\tfloat precisionSafeLength( vec3 v ) {\n\t\tfloat maxComponent = max3( abs( v ) );\n\t\treturn length( v / maxComponent ) * maxComponent;\n\t}\n#endif\nstruct IncidentLight {\n\tvec3 color;\n\tvec3 direction;\n\tbool visible;\n};\nstruct ReflectedLight {\n\tvec3 directDiffuse;\n\tvec3 directSpecular;\n\tvec3 indirectDiffuse;\n\tvec3 indirectSpecular;\n};\nstruct GeometricContext {\n\tvec3 position;\n\tvec3 normal;\n\tvec3 viewDir;\n#ifdef CLEARCOAT\n\tvec3 clearcoatNormal;\n#endif\n};\nvec3 transformDirection( in vec3 dir, in mat4 matrix ) {\n\treturn normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );\n}\nvec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) {\n\treturn normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );\n}\nvec3 projectOnPlane(in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\tfloat distance = dot( planeNormal, point - pointOnPlane );\n\treturn - distance * planeNormal + point;\n}\nfloat sideOfPlane( in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\treturn sign( dot( point - pointOnPlane, planeNormal ) );\n}\nvec3 linePlaneIntersect( in vec3 pointOnLine, in vec3 lineDirection, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\treturn lineDirection * ( dot( planeNormal, pointOnPlane - pointOnLine ) / dot( planeNormal, lineDirection ) ) + pointOnLine;\n}\nmat3 transposeMat3( const in mat3 m ) {\n\tmat3 tmp;\n\ttmp[ 0 ] = vec3( m[ 0 ].x, m[ 1 ].x, m[ 2 ].x );\n\ttmp[ 1 ] = vec3( m[ 0 ].y, m[ 1 ].y, m[ 2 ].y );\n\ttmp[ 2 ] = vec3( m[ 0 ].z, m[ 1 ].z, m[ 2 ].z );\n\treturn tmp;\n}\nfloat linearToRelativeLuminance( const in vec3 color ) {\n\tvec3 weights = vec3( 0.2126, 0.7152, 0.0722 );\n\treturn dot( weights, color.rgb );\n}\nbool isPerspectiveMatrix( mat4 m ) {\n return m[ 2 ][ 3 ] == - 1.0;\n}";var cube_uv_reflection_fragment="#ifdef ENVMAP_TYPE_CUBE_UV\n#define cubeUV_maxMipLevel 8.0\n#define cubeUV_minMipLevel 4.0\n#define cubeUV_maxTileSize 256.0\n#define cubeUV_minTileSize 16.0\nfloat getFace(vec3 direction) {\n vec3 absDirection = abs(direction);\n float face = -1.0;\n if (absDirection.x > absDirection.z) {\n if (absDirection.x > absDirection.y)\n face = direction.x > 0.0 ? 0.0 : 3.0;\n else\n face = direction.y > 0.0 ? 1.0 : 4.0;\n } else {\n if (absDirection.z > absDirection.y)\n face = direction.z > 0.0 ? 2.0 : 5.0;\n else\n face = direction.y > 0.0 ? 1.0 : 4.0;\n }\n return face;\n}\nvec2 getUV(vec3 direction, float face) {\n vec2 uv;\n if (face == 0.0) {\n uv = vec2(-direction.z, direction.y) / abs(direction.x);\n } else if (face == 1.0) {\n uv = vec2(direction.x, -direction.z) / abs(direction.y);\n } else if (face == 2.0) {\n uv = direction.xy / abs(direction.z);\n } else if (face == 3.0) {\n uv = vec2(direction.z, direction.y) / abs(direction.x);\n } else if (face == 4.0) {\n uv = direction.xz / abs(direction.y);\n } else {\n uv = vec2(-direction.x, direction.y) / abs(direction.z);\n }\n return 0.5 * (uv + 1.0);\n}\nvec3 bilinearCubeUV(sampler2D envMap, vec3 direction, float mipInt) {\n float face = getFace(direction);\n float filterInt = max(cubeUV_minMipLevel - mipInt, 0.0);\n mipInt = max(mipInt, cubeUV_minMipLevel);\n float faceSize = exp2(mipInt);\n float texelSize = 1.0 / (3.0 * cubeUV_maxTileSize);\n vec2 uv = getUV(direction, face) * (faceSize - 1.0);\n vec2 f = fract(uv);\n uv += 0.5 - f;\n if (face > 2.0) {\n uv.y += faceSize;\n face -= 3.0;\n }\n uv.x += face * faceSize;\n if(mipInt < cubeUV_maxMipLevel){\n uv.y += 2.0 * cubeUV_maxTileSize;\n }\n uv.y += filterInt * 2.0 * cubeUV_minTileSize;\n uv.x += 3.0 * max(0.0, cubeUV_maxTileSize - 2.0 * faceSize);\n uv *= texelSize;\n vec3 tl = envMapTexelToLinear(texture2D(envMap, uv)).rgb;\n uv.x += texelSize;\n vec3 tr = envMapTexelToLinear(texture2D(envMap, uv)).rgb;\n uv.y += texelSize;\n vec3 br = envMapTexelToLinear(texture2D(envMap, uv)).rgb;\n uv.x -= texelSize;\n vec3 bl = envMapTexelToLinear(texture2D(envMap, uv)).rgb;\n vec3 tm = mix(tl, tr, f.x);\n vec3 bm = mix(bl, br, f.x);\n return mix(tm, bm, f.y);\n}\n#define r0 1.0\n#define v0 0.339\n#define m0 -2.0\n#define r1 0.8\n#define v1 0.276\n#define m1 -1.0\n#define r4 0.4\n#define v4 0.046\n#define m4 2.0\n#define r5 0.305\n#define v5 0.016\n#define m5 3.0\n#define r6 0.21\n#define v6 0.0038\n#define m6 4.0\nfloat roughnessToMip(float roughness) {\n float mip = 0.0;\n if (roughness >= r1) {\n mip = (r0 - roughness) * (m1 - m0) / (r0 - r1) + m0;\n } else if (roughness >= r4) {\n mip = (r1 - roughness) * (m4 - m1) / (r1 - r4) + m1;\n } else if (roughness >= r5) {\n mip = (r4 - roughness) * (m5 - m4) / (r4 - r5) + m4;\n } else if (roughness >= r6) {\n mip = (r5 - roughness) * (m6 - m5) / (r5 - r6) + m5;\n } else {\n mip = -2.0 * log2(1.16 * roughness); }\n return mip;\n}\nvec4 textureCubeUV(sampler2D envMap, vec3 sampleDir, float roughness) {\n float mip = clamp(roughnessToMip(roughness), m0, cubeUV_maxMipLevel);\n float mipF = fract(mip);\n float mipInt = floor(mip);\n vec3 color0 = bilinearCubeUV(envMap, sampleDir, mipInt);\n if (mipF == 0.0) {\n return vec4(color0, 1.0);\n } else {\n vec3 color1 = bilinearCubeUV(envMap, sampleDir, mipInt + 1.0);\n return vec4(mix(color0, color1, mipF), 1.0);\n }\n}\n#endif";var defaultnormal_vertex="vec3 transformedNormal = objectNormal;\n#ifdef USE_INSTANCING\n\tmat3 m = mat3( instanceMatrix );\n\ttransformedNormal /= vec3( dot( m[ 0 ], m[ 0 ] ), dot( m[ 1 ], m[ 1 ] ), dot( m[ 2 ], m[ 2 ] ) );\n\ttransformedNormal = m * transformedNormal;\n#endif\ntransformedNormal = normalMatrix * transformedNormal;\n#ifdef FLIP_SIDED\n\ttransformedNormal = - transformedNormal;\n#endif\n#ifdef USE_TANGENT\n\tvec3 transformedTangent = ( modelViewMatrix * vec4( objectTangent, 0.0 ) ).xyz;\n\t#ifdef FLIP_SIDED\n\t\ttransformedTangent = - transformedTangent;\n\t#endif\n#endif";var displacementmap_pars_vertex="#ifdef USE_DISPLACEMENTMAP\n\tuniform sampler2D displacementMap;\n\tuniform float displacementScale;\n\tuniform float displacementBias;\n#endif";var displacementmap_vertex="#ifdef USE_DISPLACEMENTMAP\n\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, vUv ).x * displacementScale + displacementBias );\n#endif";var emissivemap_fragment="#ifdef USE_EMISSIVEMAP\n\tvec4 emissiveColor = texture2D( emissiveMap, vUv );\n\temissiveColor.rgb = emissiveMapTexelToLinear( emissiveColor ).rgb;\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\n#endif";var emissivemap_pars_fragment="#ifdef USE_EMISSIVEMAP\n\tuniform sampler2D emissiveMap;\n#endif";var encodings_fragment="gl_FragColor = linearToOutputTexel( gl_FragColor );";var encodings_pars_fragment="\nvec4 LinearToLinear( in vec4 value ) {\n\treturn value;\n}\nvec4 GammaToLinear( in vec4 value, in float gammaFactor ) {\n\treturn vec4( pow( value.rgb, vec3( gammaFactor ) ), value.a );\n}\nvec4 LinearToGamma( in vec4 value, in float gammaFactor ) {\n\treturn vec4( pow( value.rgb, vec3( 1.0 / gammaFactor ) ), value.a );\n}\nvec4 sRGBToLinear( in vec4 value ) {\n\treturn vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.a );\n}\nvec4 LinearTosRGB( in vec4 value ) {\n\treturn vec4( mix( pow( value.rgb, vec3( 0.41666 ) ) * 1.055 - vec3( 0.055 ), value.rgb * 12.92, vec3( lessThanEqual( value.rgb, vec3( 0.0031308 ) ) ) ), value.a );\n}\nvec4 RGBEToLinear( in vec4 value ) {\n\treturn vec4( value.rgb * exp2( value.a * 255.0 - 128.0 ), 1.0 );\n}\nvec4 LinearToRGBE( in vec4 value ) {\n\tfloat maxComponent = max( max( value.r, value.g ), value.b );\n\tfloat fExp = clamp( ceil( log2( maxComponent ) ), -128.0, 127.0 );\n\treturn vec4( value.rgb / exp2( fExp ), ( fExp + 128.0 ) / 255.0 );\n}\nvec4 RGBMToLinear( in vec4 value, in float maxRange ) {\n\treturn vec4( value.rgb * value.a * maxRange, 1.0 );\n}\nvec4 LinearToRGBM( in vec4 value, in float maxRange ) {\n\tfloat maxRGB = max( value.r, max( value.g, value.b ) );\n\tfloat M = clamp( maxRGB / maxRange, 0.0, 1.0 );\n\tM = ceil( M * 255.0 ) / 255.0;\n\treturn vec4( value.rgb / ( M * maxRange ), M );\n}\nvec4 RGBDToLinear( in vec4 value, in float maxRange ) {\n\treturn vec4( value.rgb * ( ( maxRange / 255.0 ) / value.a ), 1.0 );\n}\nvec4 LinearToRGBD( in vec4 value, in float maxRange ) {\n\tfloat maxRGB = max( value.r, max( value.g, value.b ) );\n\tfloat D = max( maxRange / maxRGB, 1.0 );\n\tD = clamp( floor( D ) / 255.0, 0.0, 1.0 );\n\treturn vec4( value.rgb * ( D * ( 255.0 / maxRange ) ), D );\n}\nconst mat3 cLogLuvM = mat3( 0.2209, 0.3390, 0.4184, 0.1138, 0.6780, 0.7319, 0.0102, 0.1130, 0.2969 );\nvec4 LinearToLogLuv( in vec4 value ) {\n\tvec3 Xp_Y_XYZp = cLogLuvM * value.rgb;\n\tXp_Y_XYZp = max( Xp_Y_XYZp, vec3( 1e-6, 1e-6, 1e-6 ) );\n\tvec4 vResult;\n\tvResult.xy = Xp_Y_XYZp.xy / Xp_Y_XYZp.z;\n\tfloat Le = 2.0 * log2(Xp_Y_XYZp.y) + 127.0;\n\tvResult.w = fract( Le );\n\tvResult.z = ( Le - ( floor( vResult.w * 255.0 ) ) / 255.0 ) / 255.0;\n\treturn vResult;\n}\nconst mat3 cLogLuvInverseM = mat3( 6.0014, -2.7008, -1.7996, -1.3320, 3.1029, -5.7721, 0.3008, -1.0882, 5.6268 );\nvec4 LogLuvToLinear( in vec4 value ) {\n\tfloat Le = value.z * 255.0 + value.w;\n\tvec3 Xp_Y_XYZp;\n\tXp_Y_XYZp.y = exp2( ( Le - 127.0 ) / 2.0 );\n\tXp_Y_XYZp.z = Xp_Y_XYZp.y / value.y;\n\tXp_Y_XYZp.x = value.x * Xp_Y_XYZp.z;\n\tvec3 vRGB = cLogLuvInverseM * Xp_Y_XYZp.rgb;\n\treturn vec4( max( vRGB, 0.0 ), 1.0 );\n}";var envmap_fragment="#ifdef USE_ENVMAP\n\t#ifdef ENV_WORLDPOS\n\t\tvec3 cameraToFrag;\n\t\t\n\t\tif ( isOrthographic ) {\n\t\t\tcameraToFrag = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );\n\t\t} else {\n\t\t\tcameraToFrag = normalize( vWorldPosition - cameraPosition );\n\t\t}\n\t\tvec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\tvec3 reflectVec = reflect( cameraToFrag, worldNormal );\n\t\t#else\n\t\t\tvec3 reflectVec = refract( cameraToFrag, worldNormal, refractionRatio );\n\t\t#endif\n\t#else\n\t\tvec3 reflectVec = vReflect;\n\t#endif\n\t#ifdef ENVMAP_TYPE_CUBE\n\t\tvec4 envColor = textureCube( envMap, vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );\n\t#elif defined( ENVMAP_TYPE_CUBE_UV )\n\t\tvec4 envColor = textureCubeUV( envMap, reflectVec, 0.0 );\n\t#elif defined( ENVMAP_TYPE_EQUIREC )\n\t\tvec2 sampleUV;\n\t\treflectVec = normalize( reflectVec );\n\t\tsampleUV.y = asin( clamp( reflectVec.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;\n\t\tsampleUV.x = atan( reflectVec.z, reflectVec.x ) * RECIPROCAL_PI2 + 0.5;\n\t\tvec4 envColor = texture2D( envMap, sampleUV );\n\t#elif defined( ENVMAP_TYPE_SPHERE )\n\t\treflectVec = normalize( reflectVec );\n\t\tvec3 reflectView = normalize( ( viewMatrix * vec4( reflectVec, 0.0 ) ).xyz + vec3( 0.0, 0.0, 1.0 ) );\n\t\tvec4 envColor = texture2D( envMap, reflectView.xy * 0.5 + 0.5 );\n\t#else\n\t\tvec4 envColor = vec4( 0.0 );\n\t#endif\n\t#ifndef ENVMAP_TYPE_CUBE_UV\n\t\tenvColor = envMapTexelToLinear( envColor );\n\t#endif\n\t#ifdef ENVMAP_BLENDING_MULTIPLY\n\t\toutgoingLight = mix( outgoingLight, outgoingLight * envColor.xyz, specularStrength * reflectivity );\n\t#elif defined( ENVMAP_BLENDING_MIX )\n\t\toutgoingLight = mix( outgoingLight, envColor.xyz, specularStrength * reflectivity );\n\t#elif defined( ENVMAP_BLENDING_ADD )\n\t\toutgoingLight += envColor.xyz * specularStrength * reflectivity;\n\t#endif\n#endif";var envmap_common_pars_fragment="#ifdef USE_ENVMAP\n\tuniform float envMapIntensity;\n\tuniform float flipEnvMap;\n\tuniform int maxMipLevel;\n\t#ifdef ENVMAP_TYPE_CUBE\n\t\tuniform samplerCube envMap;\n\t#else\n\t\tuniform sampler2D envMap;\n\t#endif\n\t\n#endif";var envmap_pars_fragment="#ifdef USE_ENVMAP\n\tuniform float reflectivity;\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG )\n\t\t#define ENV_WORLDPOS\n\t#endif\n\t#ifdef ENV_WORLDPOS\n\t\tvarying vec3 vWorldPosition;\n\t\tuniform float refractionRatio;\n\t#else\n\t\tvarying vec3 vReflect;\n\t#endif\n#endif";var envmap_pars_vertex="#ifdef USE_ENVMAP\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) ||defined( PHONG )\n\t\t#define ENV_WORLDPOS\n\t#endif\n\t#ifdef ENV_WORLDPOS\n\t\t\n\t\tvarying vec3 vWorldPosition;\n\t#else\n\t\tvarying vec3 vReflect;\n\t\tuniform float refractionRatio;\n\t#endif\n#endif";var envmap_vertex="#ifdef USE_ENVMAP\n\t#ifdef ENV_WORLDPOS\n\t\tvWorldPosition = worldPosition.xyz;\n\t#else\n\t\tvec3 cameraToVertex;\n\t\tif ( isOrthographic ) { \n\t\t\tcameraToVertex = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );\n\t\t} else {\n\t\t\tcameraToVertex = normalize( worldPosition.xyz - cameraPosition );\n\t\t}\n\t\tvec3 worldNormal = inverseTransformDirection( transformedNormal, viewMatrix );\n\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\tvReflect = reflect( cameraToVertex, worldNormal );\n\t\t#else\n\t\t\tvReflect = refract( cameraToVertex, worldNormal, refractionRatio );\n\t\t#endif\n\t#endif\n#endif";var fog_vertex="#ifdef USE_FOG\n\tfogDepth = -mvPosition.z;\n#endif";var fog_pars_vertex="#ifdef USE_FOG\n\tvarying float fogDepth;\n#endif";var fog_fragment="#ifdef USE_FOG\n\t#ifdef FOG_EXP2\n\t\tfloat fogFactor = 1.0 - exp( - fogDensity * fogDensity * fogDepth * fogDepth );\n\t#else\n\t\tfloat fogFactor = smoothstep( fogNear, fogFar, fogDepth );\n\t#endif\n\tgl_FragColor.rgb = mix( gl_FragColor.rgb, fogColor, fogFactor );\n#endif";var fog_pars_fragment="#ifdef USE_FOG\n\tuniform vec3 fogColor;\n\tvarying float fogDepth;\n\t#ifdef FOG_EXP2\n\t\tuniform float fogDensity;\n\t#else\n\t\tuniform float fogNear;\n\t\tuniform float fogFar;\n\t#endif\n#endif";var gradientmap_pars_fragment="#ifdef USE_GRADIENTMAP\n\tuniform sampler2D gradientMap;\n#endif\nvec3 getGradientIrradiance( vec3 normal, vec3 lightDirection ) {\n\tfloat dotNL = dot( normal, lightDirection );\n\tvec2 coord = vec2( dotNL * 0.5 + 0.5, 0.0 );\n\t#ifdef USE_GRADIENTMAP\n\t\treturn texture2D( gradientMap, coord ).rgb;\n\t#else\n\t\treturn ( coord.x < 0.7 ) ? vec3( 0.7 ) : vec3( 1.0 );\n\t#endif\n}";var lightmap_fragment="#ifdef USE_LIGHTMAP\n\tvec4 lightMapTexel= texture2D( lightMap, vUv2 );\n\treflectedLight.indirectDiffuse += PI * lightMapTexelToLinear( lightMapTexel ).rgb * lightMapIntensity;\n#endif";var lightmap_pars_fragment="#ifdef USE_LIGHTMAP\n\tuniform sampler2D lightMap;\n\tuniform float lightMapIntensity;\n#endif";var lights_lambert_vertex="vec3 diffuse = vec3( 1.0 );\nGeometricContext geometry;\ngeometry.position = mvPosition.xyz;\ngeometry.normal = normalize( transformedNormal );\ngeometry.viewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( -mvPosition.xyz );\nGeometricContext backGeometry;\nbackGeometry.position = geometry.position;\nbackGeometry.normal = -geometry.normal;\nbackGeometry.viewDir = geometry.viewDir;\nvLightFront = vec3( 0.0 );\nvIndirectFront = vec3( 0.0 );\n#ifdef DOUBLE_SIDED\n\tvLightBack = vec3( 0.0 );\n\tvIndirectBack = vec3( 0.0 );\n#endif\nIncidentLight directLight;\nfloat dotNL;\nvec3 directLightColor_Diffuse;\nvIndirectFront += getAmbientLightIrradiance( ambientLightColor );\nvIndirectFront += getLightProbeIrradiance( lightProbe, geometry );\n#ifdef DOUBLE_SIDED\n\tvIndirectBack += getAmbientLightIrradiance( ambientLightColor );\n\tvIndirectBack += getLightProbeIrradiance( lightProbe, backGeometry );\n#endif\n#if NUM_POINT_LIGHTS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\t\tgetPointDirectLightIrradiance( pointLights[ i ], geometry, directLight );\n\t\tdotNL = dot( geometry.normal, directLight.direction );\n\t\tdirectLightColor_Diffuse = PI * directLight.color;\n\t\tvLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\n\t\t#endif\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if NUM_SPOT_LIGHTS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n\t\tgetSpotDirectLightIrradiance( spotLights[ i ], geometry, directLight );\n\t\tdotNL = dot( geometry.normal, directLight.direction );\n\t\tdirectLightColor_Diffuse = PI * directLight.color;\n\t\tvLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\n\t\t#endif\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if NUM_DIR_LIGHTS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\t\tgetDirectionalDirectLightIrradiance( directionalLights[ i ], geometry, directLight );\n\t\tdotNL = dot( geometry.normal, directLight.direction );\n\t\tdirectLightColor_Diffuse = PI * directLight.color;\n\t\tvLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\n\t\t#endif\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if NUM_HEMI_LIGHTS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n\t\tvIndirectFront += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry );\n\t\t#ifdef DOUBLE_SIDED\n\t\t\tvIndirectBack += getHemisphereLightIrradiance( hemisphereLights[ i ], backGeometry );\n\t\t#endif\n\t}\n\t#pragma unroll_loop_end\n#endif";var lights_pars_begin="uniform bool receiveShadow;\nuniform vec3 ambientLightColor;\nuniform vec3 lightProbe[ 9 ];\nvec3 shGetIrradianceAt( in vec3 normal, in vec3 shCoefficients[ 9 ] ) {\n\tfloat x = normal.x, y = normal.y, z = normal.z;\n\tvec3 result = shCoefficients[ 0 ] * 0.886227;\n\tresult += shCoefficients[ 1 ] * 2.0 * 0.511664 * y;\n\tresult += shCoefficients[ 2 ] * 2.0 * 0.511664 * z;\n\tresult += shCoefficients[ 3 ] * 2.0 * 0.511664 * x;\n\tresult += shCoefficients[ 4 ] * 2.0 * 0.429043 * x * y;\n\tresult += shCoefficients[ 5 ] * 2.0 * 0.429043 * y * z;\n\tresult += shCoefficients[ 6 ] * ( 0.743125 * z * z - 0.247708 );\n\tresult += shCoefficients[ 7 ] * 2.0 * 0.429043 * x * z;\n\tresult += shCoefficients[ 8 ] * 0.429043 * ( x * x - y * y );\n\treturn result;\n}\nvec3 getLightProbeIrradiance( const in vec3 lightProbe[ 9 ], const in GeometricContext geometry ) {\n\tvec3 worldNormal = inverseTransformDirection( geometry.normal, viewMatrix );\n\tvec3 irradiance = shGetIrradianceAt( worldNormal, lightProbe );\n\treturn irradiance;\n}\nvec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {\n\tvec3 irradiance = ambientLightColor;\n\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\tirradiance *= PI;\n\t#endif\n\treturn irradiance;\n}\n#if NUM_DIR_LIGHTS > 0\n\tstruct DirectionalLight {\n\t\tvec3 direction;\n\t\tvec3 color;\n\t};\n\tuniform DirectionalLight directionalLights[ NUM_DIR_LIGHTS ];\n\t#if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0\n\t\tstruct DirectionalLightShadow {\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];\n\t#endif\n\tvoid getDirectionalDirectLightIrradiance( const in DirectionalLight directionalLight, const in GeometricContext geometry, out IncidentLight directLight ) {\n\t\tdirectLight.color = directionalLight.color;\n\t\tdirectLight.direction = directionalLight.direction;\n\t\tdirectLight.visible = true;\n\t}\n#endif\n#if NUM_POINT_LIGHTS > 0\n\tstruct PointLight {\n\t\tvec3 position;\n\t\tvec3 color;\n\t\tfloat distance;\n\t\tfloat decay;\n\t};\n\tuniform PointLight pointLights[ NUM_POINT_LIGHTS ];\n\t#if defined( USE_SHADOWMAP ) && NUM_POINT_LIGHT_SHADOWS > 0\n\t\tstruct PointLightShadow {\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t\tfloat shadowCameraNear;\n\t\t\tfloat shadowCameraFar;\n\t\t};\n\t\tuniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];\n\t#endif\n\tvoid getPointDirectLightIrradiance( const in PointLight pointLight, const in GeometricContext geometry, out IncidentLight directLight ) {\n\t\tvec3 lVector = pointLight.position - geometry.position;\n\t\tdirectLight.direction = normalize( lVector );\n\t\tfloat lightDistance = length( lVector );\n\t\tdirectLight.color = pointLight.color;\n\t\tdirectLight.color *= punctualLightIntensityToIrradianceFactor( lightDistance, pointLight.distance, pointLight.decay );\n\t\tdirectLight.visible = ( directLight.color != vec3( 0.0 ) );\n\t}\n#endif\n#if NUM_SPOT_LIGHTS > 0\n\tstruct SpotLight {\n\t\tvec3 position;\n\t\tvec3 direction;\n\t\tvec3 color;\n\t\tfloat distance;\n\t\tfloat decay;\n\t\tfloat coneCos;\n\t\tfloat penumbraCos;\n\t};\n\tuniform SpotLight spotLights[ NUM_SPOT_LIGHTS ];\n\t#if defined( USE_SHADOWMAP ) && NUM_SPOT_LIGHT_SHADOWS > 0\n\t\tstruct SpotLightShadow {\n\t\t\tfloat shadowBias;\n\t\t\tfloat shadowRadius;\n\t\t\tvec2 shadowMapSize;\n\t\t};\n\t\tuniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ];\n\t#endif\n\tvoid getSpotDirectLightIrradiance( const in SpotLight spotLight, const in GeometricContext geometry, out IncidentLight directLight ) {\n\t\tvec3 lVector = spotLight.position - geometry.position;\n\t\tdirectLight.direction = normalize( lVector );\n\t\tfloat lightDistance = length( lVector );\n\t\tfloat angleCos = dot( directLight.direction, spotLight.direction );\n\t\tif ( angleCos > spotLight.coneCos ) {\n\t\t\tfloat spotEffect = smoothstep( spotLight.coneCos, spotLight.penumbraCos, angleCos );\n\t\t\tdirectLight.color = spotLight.color;\n\t\t\tdirectLight.color *= spotEffect * punctualLightIntensityToIrradianceFactor( lightDistance, spotLight.distance, spotLight.decay );\n\t\t\tdirectLight.visible = true;\n\t\t} else {\n\t\t\tdirectLight.color = vec3( 0.0 );\n\t\t\tdirectLight.visible = false;\n\t\t}\n\t}\n#endif\n#if NUM_RECT_AREA_LIGHTS > 0\n\tstruct RectAreaLight {\n\t\tvec3 color;\n\t\tvec3 position;\n\t\tvec3 halfWidth;\n\t\tvec3 halfHeight;\n\t};\n\tuniform sampler2D ltc_1;\tuniform sampler2D ltc_2;\n\tuniform RectAreaLight rectAreaLights[ NUM_RECT_AREA_LIGHTS ];\n#endif\n#if NUM_HEMI_LIGHTS > 0\n\tstruct HemisphereLight {\n\t\tvec3 direction;\n\t\tvec3 skyColor;\n\t\tvec3 groundColor;\n\t};\n\tuniform HemisphereLight hemisphereLights[ NUM_HEMI_LIGHTS ];\n\tvec3 getHemisphereLightIrradiance( const in HemisphereLight hemiLight, const in GeometricContext geometry ) {\n\t\tfloat dotNL = dot( geometry.normal, hemiLight.direction );\n\t\tfloat hemiDiffuseWeight = 0.5 * dotNL + 0.5;\n\t\tvec3 irradiance = mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );\n\t\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\t\tirradiance *= PI;\n\t\t#endif\n\t\treturn irradiance;\n\t}\n#endif";var envmap_physical_pars_fragment="#if defined( USE_ENVMAP )\n\t#ifdef ENVMAP_MODE_REFRACTION\n\t\tuniform float refractionRatio;\n\t#endif\n\tvec3 getLightProbeIndirectIrradiance( const in GeometricContext geometry, const in int maxMIPLevel ) {\n\t\tvec3 worldNormal = inverseTransformDirection( geometry.normal, viewMatrix );\n\t\t#ifdef ENVMAP_TYPE_CUBE\n\t\t\tvec3 queryVec = vec3( flipEnvMap * worldNormal.x, worldNormal.yz );\n\t\t\t#ifdef TEXTURE_LOD_EXT\n\t\t\t\tvec4 envMapColor = textureCubeLodEXT( envMap, queryVec, float( maxMIPLevel ) );\n\t\t\t#else\n\t\t\t\tvec4 envMapColor = textureCube( envMap, queryVec, float( maxMIPLevel ) );\n\t\t\t#endif\n\t\t\tenvMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;\n\t\t#elif defined( ENVMAP_TYPE_CUBE_UV )\n\t\t\tvec4 envMapColor = textureCubeUV( envMap, worldNormal, 1.0 );\n\t\t#else\n\t\t\tvec4 envMapColor = vec4( 0.0 );\n\t\t#endif\n\t\treturn PI * envMapColor.rgb * envMapIntensity;\n\t}\n\tfloat getSpecularMIPLevel( const in float roughness, const in int maxMIPLevel ) {\n\t\tfloat maxMIPLevelScalar = float( maxMIPLevel );\n\t\tfloat sigma = PI * roughness * roughness / ( 1.0 + roughness );\n\t\tfloat desiredMIPLevel = maxMIPLevelScalar + log2( sigma );\n\t\treturn clamp( desiredMIPLevel, 0.0, maxMIPLevelScalar );\n\t}\n\tvec3 getLightProbeIndirectRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness, const in int maxMIPLevel ) {\n\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t vec3 reflectVec = reflect( -viewDir, normal );\n\t\t reflectVec = normalize( mix( reflectVec, normal, roughness * roughness) );\n\t\t#else\n\t\t vec3 reflectVec = refract( -viewDir, normal, refractionRatio );\n\t\t#endif\n\t\treflectVec = inverseTransformDirection( reflectVec, viewMatrix );\n\t\tfloat specularMIPLevel = getSpecularMIPLevel( roughness, maxMIPLevel );\n\t\t#ifdef ENVMAP_TYPE_CUBE\n\t\t\tvec3 queryReflectVec = vec3( flipEnvMap * reflectVec.x, reflectVec.yz );\n\t\t\t#ifdef TEXTURE_LOD_EXT\n\t\t\t\tvec4 envMapColor = textureCubeLodEXT( envMap, queryReflectVec, specularMIPLevel );\n\t\t\t#else\n\t\t\t\tvec4 envMapColor = textureCube( envMap, queryReflectVec, specularMIPLevel );\n\t\t\t#endif\n\t\t\tenvMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;\n\t\t#elif defined( ENVMAP_TYPE_CUBE_UV )\n\t\t\tvec4 envMapColor = textureCubeUV( envMap, reflectVec, roughness );\n\t\t#elif defined( ENVMAP_TYPE_EQUIREC )\n\t\t\tvec2 sampleUV;\n\t\t\tsampleUV.y = asin( clamp( reflectVec.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;\n\t\t\tsampleUV.x = atan( reflectVec.z, reflectVec.x ) * RECIPROCAL_PI2 + 0.5;\n\t\t\t#ifdef TEXTURE_LOD_EXT\n\t\t\t\tvec4 envMapColor = texture2DLodEXT( envMap, sampleUV, specularMIPLevel );\n\t\t\t#else\n\t\t\t\tvec4 envMapColor = texture2D( envMap, sampleUV, specularMIPLevel );\n\t\t\t#endif\n\t\t\tenvMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;\n\t\t#elif defined( ENVMAP_TYPE_SPHERE )\n\t\t\tvec3 reflectView = normalize( ( viewMatrix * vec4( reflectVec, 0.0 ) ).xyz + vec3( 0.0,0.0,1.0 ) );\n\t\t\t#ifdef TEXTURE_LOD_EXT\n\t\t\t\tvec4 envMapColor = texture2DLodEXT( envMap, reflectView.xy * 0.5 + 0.5, specularMIPLevel );\n\t\t\t#else\n\t\t\t\tvec4 envMapColor = texture2D( envMap, reflectView.xy * 0.5 + 0.5, specularMIPLevel );\n\t\t\t#endif\n\t\t\tenvMapColor.rgb = envMapTexelToLinear( envMapColor ).rgb;\n\t\t#endif\n\t\treturn envMapColor.rgb * envMapIntensity;\n\t}\n#endif";var lights_toon_fragment="ToonMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;";var lights_toon_pars_fragment="varying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\nstruct ToonMaterial {\n\tvec3\tdiffuseColor;\n\tvec3\tspecularColor;\n\tfloat\tspecularShininess;\n\tfloat\tspecularStrength;\n};\nvoid RE_Direct_Toon( const in IncidentLight directLight, const in GeometricContext geometry, const in ToonMaterial material, inout ReflectedLight reflectedLight ) {\n\tvec3 irradiance = getGradientIrradiance( geometry.normal, directLight.direction ) * directLight.color;\n\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\tirradiance *= PI;\n\t#endif\n\treflectedLight.directDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n\treflectedLight.directSpecular += irradiance * BRDF_Specular_BlinnPhong( directLight, geometry, material.specularColor, material.specularShininess ) * material.specularStrength;\n}\nvoid RE_IndirectDiffuse_Toon( const in vec3 irradiance, const in GeometricContext geometry, const in ToonMaterial material, inout ReflectedLight reflectedLight ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n}\n#define RE_Direct\t\t\t\tRE_Direct_Toon\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_Toon\n#define Material_LightProbeLOD( material )\t(0)";var lights_phong_fragment="BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;";var lights_phong_pars_fragment="varying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\nstruct BlinnPhongMaterial {\n\tvec3\tdiffuseColor;\n\tvec3\tspecularColor;\n\tfloat\tspecularShininess;\n\tfloat\tspecularStrength;\n};\nvoid RE_Direct_BlinnPhong( const in IncidentLight directLight, const in GeometricContext geometry, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {\n\tfloat dotNL = saturate( dot( geometry.normal, directLight.direction ) );\n\tvec3 irradiance = dotNL * directLight.color;\n\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\tirradiance *= PI;\n\t#endif\n\treflectedLight.directDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n\treflectedLight.directSpecular += irradiance * BRDF_Specular_BlinnPhong( directLight, geometry, material.specularColor, material.specularShininess ) * material.specularStrength;\n}\nvoid RE_IndirectDiffuse_BlinnPhong( const in vec3 irradiance, const in GeometricContext geometry, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n}\n#define RE_Direct\t\t\t\tRE_Direct_BlinnPhong\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_BlinnPhong\n#define Material_LightProbeLOD( material )\t(0)";var lights_physical_fragment="PhysicalMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb * ( 1.0 - metalnessFactor );\nvec3 dxy = max( abs( dFdx( geometryNormal ) ), abs( dFdy( geometryNormal ) ) );\nfloat geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );\nmaterial.specularRoughness = max( roughnessFactor, 0.0525 );material.specularRoughness += geometryRoughness;\nmaterial.specularRoughness = min( material.specularRoughness, 1.0 );\n#ifdef REFLECTIVITY\n\tmaterial.specularColor = mix( vec3( MAXIMUM_SPECULAR_COEFFICIENT * pow2( reflectivity ) ), diffuseColor.rgb, metalnessFactor );\n#else\n\tmaterial.specularColor = mix( vec3( DEFAULT_SPECULAR_COEFFICIENT ), diffuseColor.rgb, metalnessFactor );\n#endif\n#ifdef CLEARCOAT\n\tmaterial.clearcoat = clearcoat;\n\tmaterial.clearcoatRoughness = clearcoatRoughness;\n\t#ifdef USE_CLEARCOATMAP\n\t\tmaterial.clearcoat *= texture2D( clearcoatMap, vUv ).x;\n\t#endif\n\t#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\t\tmaterial.clearcoatRoughness *= texture2D( clearcoatRoughnessMap, vUv ).y;\n\t#endif\n\tmaterial.clearcoat = saturate( material.clearcoat );\tmaterial.clearcoatRoughness = max( material.clearcoatRoughness, 0.0525 );\n\tmaterial.clearcoatRoughness += geometryRoughness;\n\tmaterial.clearcoatRoughness = min( material.clearcoatRoughness, 1.0 );\n#endif\n#ifdef USE_SHEEN\n\tmaterial.sheenColor = sheen;\n#endif";var lights_physical_pars_fragment="struct PhysicalMaterial {\n\tvec3\tdiffuseColor;\n\tfloat\tspecularRoughness;\n\tvec3\tspecularColor;\n#ifdef CLEARCOAT\n\tfloat clearcoat;\n\tfloat clearcoatRoughness;\n#endif\n#ifdef USE_SHEEN\n\tvec3 sheenColor;\n#endif\n};\n#define MAXIMUM_SPECULAR_COEFFICIENT 0.16\n#define DEFAULT_SPECULAR_COEFFICIENT 0.04\nfloat clearcoatDHRApprox( const in float roughness, const in float dotNL ) {\n\treturn DEFAULT_SPECULAR_COEFFICIENT + ( 1.0 - DEFAULT_SPECULAR_COEFFICIENT ) * ( pow( 1.0 - dotNL, 5.0 ) * pow( 1.0 - roughness, 2.0 ) );\n}\n#if NUM_RECT_AREA_LIGHTS > 0\n\tvoid RE_Direct_RectArea_Physical( const in RectAreaLight rectAreaLight, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\t\tvec3 normal = geometry.normal;\n\t\tvec3 viewDir = geometry.viewDir;\n\t\tvec3 position = geometry.position;\n\t\tvec3 lightPos = rectAreaLight.position;\n\t\tvec3 halfWidth = rectAreaLight.halfWidth;\n\t\tvec3 halfHeight = rectAreaLight.halfHeight;\n\t\tvec3 lightColor = rectAreaLight.color;\n\t\tfloat roughness = material.specularRoughness;\n\t\tvec3 rectCoords[ 4 ];\n\t\trectCoords[ 0 ] = lightPos + halfWidth - halfHeight;\t\trectCoords[ 1 ] = lightPos - halfWidth - halfHeight;\n\t\trectCoords[ 2 ] = lightPos - halfWidth + halfHeight;\n\t\trectCoords[ 3 ] = lightPos + halfWidth + halfHeight;\n\t\tvec2 uv = LTC_Uv( normal, viewDir, roughness );\n\t\tvec4 t1 = texture2D( ltc_1, uv );\n\t\tvec4 t2 = texture2D( ltc_2, uv );\n\t\tmat3 mInv = mat3(\n\t\t\tvec3( t1.x, 0, t1.y ),\n\t\t\tvec3( 0, 1, 0 ),\n\t\t\tvec3( t1.z, 0, t1.w )\n\t\t);\n\t\tvec3 fresnel = ( material.specularColor * t2.x + ( vec3( 1.0 ) - material.specularColor ) * t2.y );\n\t\treflectedLight.directSpecular += lightColor * fresnel * LTC_Evaluate( normal, viewDir, position, mInv, rectCoords );\n\t\treflectedLight.directDiffuse += lightColor * material.diffuseColor * LTC_Evaluate( normal, viewDir, position, mat3( 1.0 ), rectCoords );\n\t}\n#endif\nvoid RE_Direct_Physical( const in IncidentLight directLight, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\tfloat dotNL = saturate( dot( geometry.normal, directLight.direction ) );\n\tvec3 irradiance = dotNL * directLight.color;\n\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\tirradiance *= PI;\n\t#endif\n\t#ifdef CLEARCOAT\n\t\tfloat ccDotNL = saturate( dot( geometry.clearcoatNormal, directLight.direction ) );\n\t\tvec3 ccIrradiance = ccDotNL * directLight.color;\n\t\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\t\tccIrradiance *= PI;\n\t\t#endif\n\t\tfloat clearcoatDHR = material.clearcoat * clearcoatDHRApprox( material.clearcoatRoughness, ccDotNL );\n\t\treflectedLight.directSpecular += ccIrradiance * material.clearcoat * BRDF_Specular_GGX( directLight, geometry.viewDir, geometry.clearcoatNormal, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearcoatRoughness );\n\t#else\n\t\tfloat clearcoatDHR = 0.0;\n\t#endif\n\t#ifdef USE_SHEEN\n\t\treflectedLight.directSpecular += ( 1.0 - clearcoatDHR ) * irradiance * BRDF_Specular_Sheen(\n\t\t\tmaterial.specularRoughness,\n\t\t\tdirectLight.direction,\n\t\t\tgeometry,\n\t\t\tmaterial.sheenColor\n\t\t);\n\t#else\n\t\treflectedLight.directSpecular += ( 1.0 - clearcoatDHR ) * irradiance * BRDF_Specular_GGX( directLight, geometry.viewDir, geometry.normal, material.specularColor, material.specularRoughness);\n\t#endif\n\treflectedLight.directDiffuse += ( 1.0 - clearcoatDHR ) * irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectDiffuse_Physical( const in vec3 irradiance, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n\treflectedLight.indirectDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectSpecular_Physical( const in vec3 radiance, const in vec3 irradiance, const in vec3 clearcoatRadiance, const in GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight) {\n\t#ifdef CLEARCOAT\n\t\tfloat ccDotNV = saturate( dot( geometry.clearcoatNormal, geometry.viewDir ) );\n\t\treflectedLight.indirectSpecular += clearcoatRadiance * material.clearcoat * BRDF_Specular_GGX_Environment( geometry.viewDir, geometry.clearcoatNormal, vec3( DEFAULT_SPECULAR_COEFFICIENT ), material.clearcoatRoughness );\n\t\tfloat ccDotNL = ccDotNV;\n\t\tfloat clearcoatDHR = material.clearcoat * clearcoatDHRApprox( material.clearcoatRoughness, ccDotNL );\n\t#else\n\t\tfloat clearcoatDHR = 0.0;\n\t#endif\n\tfloat clearcoatInv = 1.0 - clearcoatDHR;\n\tvec3 singleScattering = vec3( 0.0 );\n\tvec3 multiScattering = vec3( 0.0 );\n\tvec3 cosineWeightedIrradiance = irradiance * RECIPROCAL_PI;\n\tBRDF_Specular_Multiscattering_Environment( geometry, material.specularColor, material.specularRoughness, singleScattering, multiScattering );\n\tvec3 diffuse = material.diffuseColor * ( 1.0 - ( singleScattering + multiScattering ) );\n\treflectedLight.indirectSpecular += clearcoatInv * radiance * singleScattering;\n\treflectedLight.indirectSpecular += multiScattering * cosineWeightedIrradiance;\n\treflectedLight.indirectDiffuse += diffuse * cosineWeightedIrradiance;\n}\n#define RE_Direct\t\t\t\tRE_Direct_Physical\n#define RE_Direct_RectArea\t\tRE_Direct_RectArea_Physical\n#define RE_IndirectDiffuse\t\tRE_IndirectDiffuse_Physical\n#define RE_IndirectSpecular\t\tRE_IndirectSpecular_Physical\nfloat computeSpecularOcclusion( const in float dotNV, const in float ambientOcclusion, const in float roughness ) {\n\treturn saturate( pow( dotNV + ambientOcclusion, exp2( - 16.0 * roughness - 1.0 ) ) - 1.0 + ambientOcclusion );\n}";var lights_fragment_begin="\nGeometricContext geometry;\ngeometry.position = - vViewPosition;\ngeometry.normal = normal;\ngeometry.viewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition );\n#ifdef CLEARCOAT\n\tgeometry.clearcoatNormal = clearcoatNormal;\n#endif\nIncidentLight directLight;\n#if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )\n\tPointLight pointLight;\n\t#if defined( USE_SHADOWMAP ) && NUM_POINT_LIGHT_SHADOWS > 0\n\tPointLightShadow pointLightShadow;\n\t#endif\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n\t\tpointLight = pointLights[ i ];\n\t\tgetPointDirectLightIrradiance( pointLight, geometry, directLight );\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS )\n\t\tpointLightShadow = pointLightShadows[ i ];\n\t\tdirectLight.color *= all( bvec2( directLight.visible, receiveShadow ) ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )\n\tSpotLight spotLight;\n\t#if defined( USE_SHADOWMAP ) && NUM_SPOT_LIGHT_SHADOWS > 0\n\tSpotLightShadow spotLightShadow;\n\t#endif\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n\t\tspotLight = spotLights[ i ];\n\t\tgetSpotDirectLightIrradiance( spotLight, geometry, directLight );\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n\t\tspotLightShadow = spotLightShadows[ i ];\n\t\tdirectLight.color *= all( bvec2( directLight.visible, receiveShadow ) ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )\n\tDirectionalLight directionalLight;\n\t#if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0\n\tDirectionalLightShadow directionalLightShadow;\n\t#endif\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n\t\tdirectionalLight = directionalLights[ i ];\n\t\tgetDirectionalDirectLightIrradiance( directionalLight, geometry, directLight );\n\t\t#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )\n\t\tdirectionalLightShadow = directionalLightShadows[ i ];\n\t\tdirectLight.color *= all( bvec2( directLight.visible, receiveShadow ) ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\t\t#endif\n\t\tRE_Direct( directLight, geometry, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea )\n\tRectAreaLight rectAreaLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) {\n\t\trectAreaLight = rectAreaLights[ i ];\n\t\tRE_Direct_RectArea( rectAreaLight, geometry, material, reflectedLight );\n\t}\n\t#pragma unroll_loop_end\n#endif\n#if defined( RE_IndirectDiffuse )\n\tvec3 iblIrradiance = vec3( 0.0 );\n\tvec3 irradiance = getAmbientLightIrradiance( ambientLightColor );\n\tirradiance += getLightProbeIrradiance( lightProbe, geometry );\n\t#if ( NUM_HEMI_LIGHTS > 0 )\n\t\t#pragma unroll_loop_start\n\t\tfor ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n\t\t\tirradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry );\n\t\t}\n\t\t#pragma unroll_loop_end\n\t#endif\n#endif\n#if defined( RE_IndirectSpecular )\n\tvec3 radiance = vec3( 0.0 );\n\tvec3 clearcoatRadiance = vec3( 0.0 );\n#endif";var lights_fragment_maps="#if defined( RE_IndirectDiffuse )\n\t#ifdef USE_LIGHTMAP\n\t\tvec4 lightMapTexel= texture2D( lightMap, vUv2 );\n\t\tvec3 lightMapIrradiance = lightMapTexelToLinear( lightMapTexel ).rgb * lightMapIntensity;\n\t\t#ifndef PHYSICALLY_CORRECT_LIGHTS\n\t\t\tlightMapIrradiance *= PI;\n\t\t#endif\n\t\tirradiance += lightMapIrradiance;\n\t#endif\n\t#if defined( USE_ENVMAP ) && defined( STANDARD ) && defined( ENVMAP_TYPE_CUBE_UV )\n\t\tiblIrradiance += getLightProbeIndirectIrradiance( geometry, maxMipLevel );\n\t#endif\n#endif\n#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )\n\tradiance += getLightProbeIndirectRadiance( geometry.viewDir, geometry.normal, material.specularRoughness, maxMipLevel );\n\t#ifdef CLEARCOAT\n\t\tclearcoatRadiance += getLightProbeIndirectRadiance( geometry.viewDir, geometry.clearcoatNormal, material.clearcoatRoughness, maxMipLevel );\n\t#endif\n#endif";var lights_fragment_end="#if defined( RE_IndirectDiffuse )\n\tRE_IndirectDiffuse( irradiance, geometry, material, reflectedLight );\n#endif\n#if defined( RE_IndirectSpecular )\n\tRE_IndirectSpecular( radiance, iblIrradiance, clearcoatRadiance, geometry, material, reflectedLight );\n#endif";var logdepthbuf_fragment="#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT )\n\tgl_FragDepthEXT = vIsPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;\n#endif";var logdepthbuf_pars_fragment="#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT )\n\tuniform float logDepthBufFC;\n\tvarying float vFragDepth;\n\tvarying float vIsPerspective;\n#endif";var logdepthbuf_pars_vertex="#ifdef USE_LOGDEPTHBUF\n\t#ifdef USE_LOGDEPTHBUF_EXT\n\t\tvarying float vFragDepth;\n\t\tvarying float vIsPerspective;\n\t#else\n\t\tuniform float logDepthBufFC;\n\t#endif\n#endif";var logdepthbuf_vertex="#ifdef USE_LOGDEPTHBUF\n\t#ifdef USE_LOGDEPTHBUF_EXT\n\t\tvFragDepth = 1.0 + gl_Position.w;\n\t\tvIsPerspective = float( isPerspectiveMatrix( projectionMatrix ) );\n\t#else\n\t\tif ( isPerspectiveMatrix( projectionMatrix ) ) {\n\t\t\tgl_Position.z = log2( max( EPSILON, gl_Position.w + 1.0 ) ) * logDepthBufFC - 1.0;\n\t\t\tgl_Position.z *= gl_Position.w;\n\t\t}\n\t#endif\n#endif";var map_fragment="#ifdef USE_MAP\n\tvec4 texelColor = texture2D( map, vUv );\n\ttexelColor = mapTexelToLinear( texelColor );\n\tdiffuseColor *= texelColor;\n#endif";var map_pars_fragment="#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif";var map_particle_fragment="#if defined( USE_MAP ) || defined( USE_ALPHAMAP )\n\tvec2 uv = ( uvTransform * vec3( gl_PointCoord.x, 1.0 - gl_PointCoord.y, 1 ) ).xy;\n#endif\n#ifdef USE_MAP\n\tvec4 mapTexel = texture2D( map, uv );\n\tdiffuseColor *= mapTexelToLinear( mapTexel );\n#endif\n#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, uv ).g;\n#endif";var map_particle_pars_fragment="#if defined( USE_MAP ) || defined( USE_ALPHAMAP )\n\tuniform mat3 uvTransform;\n#endif\n#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif\n#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif";var metalnessmap_fragment="float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n\tvec4 texelMetalness = texture2D( metalnessMap, vUv );\n\tmetalnessFactor *= texelMetalness.b;\n#endif";var metalnessmap_pars_fragment="#ifdef USE_METALNESSMAP\n\tuniform sampler2D metalnessMap;\n#endif";var morphnormal_vertex="#ifdef USE_MORPHNORMALS\n\tobjectNormal *= morphTargetBaseInfluence;\n\tobjectNormal += morphNormal0 * morphTargetInfluences[ 0 ];\n\tobjectNormal += morphNormal1 * morphTargetInfluences[ 1 ];\n\tobjectNormal += morphNormal2 * morphTargetInfluences[ 2 ];\n\tobjectNormal += morphNormal3 * morphTargetInfluences[ 3 ];\n#endif";var morphtarget_pars_vertex="#ifdef USE_MORPHTARGETS\n\tuniform float morphTargetBaseInfluence;\n\t#ifndef USE_MORPHNORMALS\n\tuniform float morphTargetInfluences[ 8 ];\n\t#else\n\tuniform float morphTargetInfluences[ 4 ];\n\t#endif\n#endif";var morphtarget_vertex="#ifdef USE_MORPHTARGETS\n\ttransformed *= morphTargetBaseInfluence;\n\ttransformed += morphTarget0 * morphTargetInfluences[ 0 ];\n\ttransformed += morphTarget1 * morphTargetInfluences[ 1 ];\n\ttransformed += morphTarget2 * morphTargetInfluences[ 2 ];\n\ttransformed += morphTarget3 * morphTargetInfluences[ 3 ];\n\t#ifndef USE_MORPHNORMALS\n\ttransformed += morphTarget4 * morphTargetInfluences[ 4 ];\n\ttransformed += morphTarget5 * morphTargetInfluences[ 5 ];\n\ttransformed += morphTarget6 * morphTargetInfluences[ 6 ];\n\ttransformed += morphTarget7 * morphTargetInfluences[ 7 ];\n\t#endif\n#endif";var normal_fragment_begin="#ifdef FLAT_SHADED\n\tvec3 fdx = vec3( dFdx( vViewPosition.x ), dFdx( vViewPosition.y ), dFdx( vViewPosition.z ) );\n\tvec3 fdy = vec3( dFdy( vViewPosition.x ), dFdy( vViewPosition.y ), dFdy( vViewPosition.z ) );\n\tvec3 normal = normalize( cross( fdx, fdy ) );\n#else\n\tvec3 normal = normalize( vNormal );\n\t#ifdef DOUBLE_SIDED\n\t\tnormal = normal * ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t#endif\n\t#ifdef USE_TANGENT\n\t\tvec3 tangent = normalize( vTangent );\n\t\tvec3 bitangent = normalize( vBitangent );\n\t\t#ifdef DOUBLE_SIDED\n\t\t\ttangent = tangent * ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t\t\tbitangent = bitangent * ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t\t#endif\n\t\t#if defined( TANGENTSPACE_NORMALMAP ) || defined( USE_CLEARCOAT_NORMALMAP )\n\t\t\tmat3 vTBN = mat3( tangent, bitangent, normal );\n\t\t#endif\n\t#endif\n#endif\nvec3 geometryNormal = normal;";var normal_fragment_maps="#ifdef OBJECTSPACE_NORMALMAP\n\tnormal = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\n\t#ifdef FLIP_SIDED\n\t\tnormal = - normal;\n\t#endif\n\t#ifdef DOUBLE_SIDED\n\t\tnormal = normal * ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t#endif\n\tnormal = normalize( normalMatrix * normal );\n#elif defined( TANGENTSPACE_NORMALMAP )\n\tvec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\n\tmapN.xy *= normalScale;\n\t#ifdef USE_TANGENT\n\t\tnormal = normalize( vTBN * mapN );\n\t#else\n\t\tnormal = perturbNormal2Arb( -vViewPosition, normal, mapN );\n\t#endif\n#elif defined( USE_BUMPMAP )\n\tnormal = perturbNormalArb( -vViewPosition, normal, dHdxy_fwd() );\n#endif";var normalmap_pars_fragment="#ifdef USE_NORMALMAP\n\tuniform sampler2D normalMap;\n\tuniform vec2 normalScale;\n#endif\n#ifdef OBJECTSPACE_NORMALMAP\n\tuniform mat3 normalMatrix;\n#endif\n#if ! defined ( USE_TANGENT ) && ( defined ( TANGENTSPACE_NORMALMAP ) || defined ( USE_CLEARCOAT_NORMALMAP ) )\n\tvec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm, vec3 mapN ) {\n\t\tvec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );\n\t\tvec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );\n\t\tvec2 st0 = dFdx( vUv.st );\n\t\tvec2 st1 = dFdy( vUv.st );\n\t\tfloat scale = sign( st1.t * st0.s - st0.t * st1.s );\n\t\tvec3 S = normalize( ( q0 * st1.t - q1 * st0.t ) * scale );\n\t\tvec3 T = normalize( ( - q0 * st1.s + q1 * st0.s ) * scale );\n\t\tvec3 N = normalize( surf_norm );\n\t\tmat3 tsn = mat3( S, T, N );\n\t\tmapN.xy *= ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n\t\treturn normalize( tsn * mapN );\n\t}\n#endif";var clearcoat_normal_fragment_begin="#ifdef CLEARCOAT\n\tvec3 clearcoatNormal = geometryNormal;\n#endif";var clearcoat_normal_fragment_maps="#ifdef USE_CLEARCOAT_NORMALMAP\n\tvec3 clearcoatMapN = texture2D( clearcoatNormalMap, vUv ).xyz * 2.0 - 1.0;\n\tclearcoatMapN.xy *= clearcoatNormalScale;\n\t#ifdef USE_TANGENT\n\t\tclearcoatNormal = normalize( vTBN * clearcoatMapN );\n\t#else\n\t\tclearcoatNormal = perturbNormal2Arb( - vViewPosition, clearcoatNormal, clearcoatMapN );\n\t#endif\n#endif";var clearcoat_pars_fragment="#ifdef USE_CLEARCOATMAP\n\tuniform sampler2D clearcoatMap;\n#endif\n#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n\tuniform sampler2D clearcoatRoughnessMap;\n#endif\n#ifdef USE_CLEARCOAT_NORMALMAP\n\tuniform sampler2D clearcoatNormalMap;\n\tuniform vec2 clearcoatNormalScale;\n#endif";var packing="vec3 packNormalToRGB( const in vec3 normal ) {\n\treturn normalize( normal ) * 0.5 + 0.5;\n}\nvec3 unpackRGBToNormal( const in vec3 rgb ) {\n\treturn 2.0 * rgb.xyz - 1.0;\n}\nconst float PackUpscale = 256. / 255.;const float UnpackDownscale = 255. / 256.;\nconst vec3 PackFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );\nconst vec4 UnpackFactors = UnpackDownscale / vec4( PackFactors, 1. );\nconst float ShiftRight8 = 1. / 256.;\nvec4 packDepthToRGBA( const in float v ) {\n\tvec4 r = vec4( fract( v * PackFactors ), v );\n\tr.yzw -= r.xyz * ShiftRight8;\treturn r * PackUpscale;\n}\nfloat unpackRGBAToDepth( const in vec4 v ) {\n\treturn dot( v, UnpackFactors );\n}\nvec4 pack2HalfToRGBA( vec2 v ) {\n\tvec4 r = vec4( v.x, fract( v.x * 255.0 ), v.y, fract( v.y * 255.0 ));\n\treturn vec4( r.x - r.y / 255.0, r.y, r.z - r.w / 255.0, r.w);\n}\nvec2 unpackRGBATo2Half( vec4 v ) {\n\treturn vec2( v.x + ( v.y / 255.0 ), v.z + ( v.w / 255.0 ) );\n}\nfloat viewZToOrthographicDepth( const in float viewZ, const in float near, const in float far ) {\n\treturn ( viewZ + near ) / ( near - far );\n}\nfloat orthographicDepthToViewZ( const in float linearClipZ, const in float near, const in float far ) {\n\treturn linearClipZ * ( near - far ) - near;\n}\nfloat viewZToPerspectiveDepth( const in float viewZ, const in float near, const in float far ) {\n\treturn (( near + viewZ ) * far ) / (( far - near ) * viewZ );\n}\nfloat perspectiveDepthToViewZ( const in float invClipZ, const in float near, const in float far ) {\n\treturn ( near * far ) / ( ( far - near ) * invClipZ - far );\n}";var premultiplied_alpha_fragment="#ifdef PREMULTIPLIED_ALPHA\n\tgl_FragColor.rgb *= gl_FragColor.a;\n#endif";var project_vertex="vec4 mvPosition = vec4( transformed, 1.0 );\n#ifdef USE_INSTANCING\n\tmvPosition = instanceMatrix * mvPosition;\n#endif\nmvPosition = modelViewMatrix * mvPosition;\ngl_Position = projectionMatrix * mvPosition;";var dithering_fragment="#ifdef DITHERING\n\tgl_FragColor.rgb = dithering( gl_FragColor.rgb );\n#endif";var dithering_pars_fragment="#ifdef DITHERING\n\tvec3 dithering( vec3 color ) {\n\t\tfloat grid_position = rand( gl_FragCoord.xy );\n\t\tvec3 dither_shift_RGB = vec3( 0.25 / 255.0, -0.25 / 255.0, 0.25 / 255.0 );\n\t\tdither_shift_RGB = mix( 2.0 * dither_shift_RGB, -2.0 * dither_shift_RGB, grid_position );\n\t\treturn color + dither_shift_RGB;\n\t}\n#endif";var roughnessmap_fragment="float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n\tvec4 texelRoughness = texture2D( roughnessMap, vUv );\n\troughnessFactor *= texelRoughness.g;\n#endif";var roughnessmap_pars_fragment="#ifdef USE_ROUGHNESSMAP\n\tuniform sampler2D roughnessMap;\n#endif";var shadowmap_pars_fragment="#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\t\tuniform sampler2D directionalShadowMap[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tvarying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\t\tuniform sampler2D spotShadowMap[ NUM_SPOT_LIGHT_SHADOWS ];\n\t\tvarying vec4 vSpotShadowCoord[ NUM_SPOT_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t\tuniform sampler2D pointShadowMap[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tvarying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];\n\t#endif\n\tfloat texture2DCompare( sampler2D depths, vec2 uv, float compare ) {\n\t\treturn step( compare, unpackRGBAToDepth( texture2D( depths, uv ) ) );\n\t}\n\tvec2 texture2DDistribution( sampler2D shadow, vec2 uv ) {\n\t\treturn unpackRGBATo2Half( texture2D( shadow, uv ) );\n\t}\n\tfloat VSMShadow (sampler2D shadow, vec2 uv, float compare ){\n\t\tfloat occlusion = 1.0;\n\t\tvec2 distribution = texture2DDistribution( shadow, uv );\n\t\tfloat hard_shadow = step( compare , distribution.x );\n\t\tif (hard_shadow != 1.0 ) {\n\t\t\tfloat distance = compare - distribution.x ;\n\t\t\tfloat variance = max( 0.00000, distribution.y * distribution.y );\n\t\t\tfloat softness_probability = variance / (variance + distance * distance );\t\t\tsoftness_probability = clamp( ( softness_probability - 0.3 ) / ( 0.95 - 0.3 ), 0.0, 1.0 );\t\t\tocclusion = clamp( max( hard_shadow, softness_probability ), 0.0, 1.0 );\n\t\t}\n\t\treturn occlusion;\n\t}\n\tfloat getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord ) {\n\t\tfloat shadow = 1.0;\n\t\tshadowCoord.xyz /= shadowCoord.w;\n\t\tshadowCoord.z += shadowBias;\n\t\tbvec4 inFrustumVec = bvec4 ( shadowCoord.x >= 0.0, shadowCoord.x <= 1.0, shadowCoord.y >= 0.0, shadowCoord.y <= 1.0 );\n\t\tbool inFrustum = all( inFrustumVec );\n\t\tbvec2 frustumTestVec = bvec2( inFrustum, shadowCoord.z <= 1.0 );\n\t\tbool frustumTest = all( frustumTestVec );\n\t\tif ( frustumTest ) {\n\t\t#if defined( SHADOWMAP_TYPE_PCF )\n\t\t\tvec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n\t\t\tfloat dx0 = - texelSize.x * shadowRadius;\n\t\t\tfloat dy0 = - texelSize.y * shadowRadius;\n\t\t\tfloat dx1 = + texelSize.x * shadowRadius;\n\t\t\tfloat dy1 = + texelSize.y * shadowRadius;\n\t\t\tfloat dx2 = dx0 / 2.0;\n\t\t\tfloat dy2 = dy0 / 2.0;\n\t\t\tfloat dx3 = dx1 / 2.0;\n\t\t\tfloat dy3 = dy1 / 2.0;\n\t\t\tshadow = (\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy2 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy2 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy2 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy3 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy3 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy3 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z )\n\t\t\t) * ( 1.0 / 17.0 );\n\t\t#elif defined( SHADOWMAP_TYPE_PCF_SOFT )\n\t\t\tvec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n\t\t\tfloat dx = texelSize.x;\n\t\t\tfloat dy = texelSize.y;\n\t\t\tvec2 uv = shadowCoord.xy;\n\t\t\tvec2 f = fract( uv * shadowMapSize + 0.5 );\n\t\t\tuv -= f * texelSize;\n\t\t\tshadow = (\n\t\t\t\ttexture2DCompare( shadowMap, uv, shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, uv + vec2( dx, 0.0 ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, uv + vec2( 0.0, dy ), shadowCoord.z ) +\n\t\t\t\ttexture2DCompare( shadowMap, uv + texelSize, shadowCoord.z ) +\n\t\t\t\tmix( texture2DCompare( shadowMap, uv + vec2( -dx, 0.0 ), shadowCoord.z ), \n\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 0.0 ), shadowCoord.z ),\n\t\t\t\t\t f.x ) +\n\t\t\t\tmix( texture2DCompare( shadowMap, uv + vec2( -dx, dy ), shadowCoord.z ), \n\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, dy ), shadowCoord.z ),\n\t\t\t\t\t f.x ) +\n\t\t\t\tmix( texture2DCompare( shadowMap, uv + vec2( 0.0, -dy ), shadowCoord.z ), \n\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 0.0, 2.0 * dy ), shadowCoord.z ),\n\t\t\t\t\t f.y ) +\n\t\t\t\tmix( texture2DCompare( shadowMap, uv + vec2( dx, -dy ), shadowCoord.z ), \n\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( dx, 2.0 * dy ), shadowCoord.z ),\n\t\t\t\t\t f.y ) +\n\t\t\t\tmix( mix( texture2DCompare( shadowMap, uv + vec2( -dx, -dy ), shadowCoord.z ), \n\t\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, -dy ), shadowCoord.z ),\n\t\t\t\t\t\t f.x ),\n\t\t\t\t\t mix( texture2DCompare( shadowMap, uv + vec2( -dx, 2.0 * dy ), shadowCoord.z ), \n\t\t\t\t\t\t texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 2.0 * dy ), shadowCoord.z ),\n\t\t\t\t\t\t f.x ),\n\t\t\t\t\t f.y )\n\t\t\t) * ( 1.0 / 9.0 );\n\t\t#elif defined( SHADOWMAP_TYPE_VSM )\n\t\t\tshadow = VSMShadow( shadowMap, shadowCoord.xy, shadowCoord.z );\n\t\t#else\n\t\t\tshadow = texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z );\n\t\t#endif\n\t\t}\n\t\treturn shadow;\n\t}\n\tvec2 cubeToUV( vec3 v, float texelSizeY ) {\n\t\tvec3 absV = abs( v );\n\t\tfloat scaleToCube = 1.0 / max( absV.x, max( absV.y, absV.z ) );\n\t\tabsV *= scaleToCube;\n\t\tv *= scaleToCube * ( 1.0 - 2.0 * texelSizeY );\n\t\tvec2 planar = v.xy;\n\t\tfloat almostATexel = 1.5 * texelSizeY;\n\t\tfloat almostOne = 1.0 - almostATexel;\n\t\tif ( absV.z >= almostOne ) {\n\t\t\tif ( v.z > 0.0 )\n\t\t\t\tplanar.x = 4.0 - v.x;\n\t\t} else if ( absV.x >= almostOne ) {\n\t\t\tfloat signX = sign( v.x );\n\t\t\tplanar.x = v.z * signX + 2.0 * signX;\n\t\t} else if ( absV.y >= almostOne ) {\n\t\t\tfloat signY = sign( v.y );\n\t\t\tplanar.x = v.x + 2.0 * signY + 2.0;\n\t\t\tplanar.y = v.z * signY - 2.0;\n\t\t}\n\t\treturn vec2( 0.125, 0.25 ) * planar + vec2( 0.375, 0.75 );\n\t}\n\tfloat getPointShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord, float shadowCameraNear, float shadowCameraFar ) {\n\t\tvec2 texelSize = vec2( 1.0 ) / ( shadowMapSize * vec2( 4.0, 2.0 ) );\n\t\tvec3 lightToPosition = shadowCoord.xyz;\n\t\tfloat dp = ( length( lightToPosition ) - shadowCameraNear ) / ( shadowCameraFar - shadowCameraNear );\t\tdp += shadowBias;\n\t\tvec3 bd3D = normalize( lightToPosition );\n\t\t#if defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_PCF_SOFT ) || defined( SHADOWMAP_TYPE_VSM )\n\t\t\tvec2 offset = vec2( - 1, 1 ) * shadowRadius * texelSize.y;\n\t\t\treturn (\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyx, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyx, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxy, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxx, texelSize.y ), dp ) +\n\t\t\t\ttexture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxx, texelSize.y ), dp )\n\t\t\t) * ( 1.0 / 9.0 );\n\t\t#else\n\t\t\treturn texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp );\n\t\t#endif\n\t}\n#endif";var shadowmap_pars_vertex="#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\t\tuniform mat4 directionalShadowMatrix[ NUM_DIR_LIGHT_SHADOWS ];\n\t\tvarying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\t\tuniform mat4 spotShadowMatrix[ NUM_SPOT_LIGHT_SHADOWS ];\n\t\tvarying vec4 vSpotShadowCoord[ NUM_SPOT_LIGHT_SHADOWS ];\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t\tuniform mat4 pointShadowMatrix[ NUM_POINT_LIGHT_SHADOWS ];\n\t\tvarying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];\n\t#endif\n#endif";var shadowmap_vertex="#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {\n\t\tvDirectionalShadowCoord[ i ] = directionalShadowMatrix[ i ] * worldPosition;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHT_SHADOWS; i ++ ) {\n\t\tvSpotShadowCoord[ i ] = spotShadowMatrix[ i ] * worldPosition;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {\n\t\tvPointShadowCoord[ i ] = pointShadowMatrix[ i ] * worldPosition;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n#endif";var shadowmask_pars_fragment="float getShadowMask() {\n\tfloat shadow = 1.0;\n\t#ifdef USE_SHADOWMAP\n\t#if NUM_DIR_LIGHT_SHADOWS > 0\n\tDirectionalLightShadow directionalLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {\n\t\tdirectionalLight = directionalLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_SPOT_LIGHT_SHADOWS > 0\n\tSpotLightShadow spotLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_SPOT_LIGHT_SHADOWS; i ++ ) {\n\t\tspotLight = spotLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowBias, spotLight.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#if NUM_POINT_LIGHT_SHADOWS > 0\n\tPointLightShadow pointLight;\n\t#pragma unroll_loop_start\n\tfor ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {\n\t\tpointLight = pointLightShadows[ i ];\n\t\tshadow *= receiveShadow ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ], pointLight.shadowCameraNear, pointLight.shadowCameraFar ) : 1.0;\n\t}\n\t#pragma unroll_loop_end\n\t#endif\n\t#endif\n\treturn shadow;\n}";var skinbase_vertex="#ifdef USE_SKINNING\n\tmat4 boneMatX = getBoneMatrix( skinIndex.x );\n\tmat4 boneMatY = getBoneMatrix( skinIndex.y );\n\tmat4 boneMatZ = getBoneMatrix( skinIndex.z );\n\tmat4 boneMatW = getBoneMatrix( skinIndex.w );\n#endif";var skinning_pars_vertex="#ifdef USE_SKINNING\n\tuniform mat4 bindMatrix;\n\tuniform mat4 bindMatrixInverse;\n\t#ifdef BONE_TEXTURE\n\t\tuniform highp sampler2D boneTexture;\n\t\tuniform int boneTextureSize;\n\t\tmat4 getBoneMatrix( const in float i ) {\n\t\t\tfloat j = i * 4.0;\n\t\t\tfloat x = mod( j, float( boneTextureSize ) );\n\t\t\tfloat y = floor( j / float( boneTextureSize ) );\n\t\t\tfloat dx = 1.0 / float( boneTextureSize );\n\t\t\tfloat dy = 1.0 / float( boneTextureSize );\n\t\t\ty = dy * ( y + 0.5 );\n\t\t\tvec4 v1 = texture2D( boneTexture, vec2( dx * ( x + 0.5 ), y ) );\n\t\t\tvec4 v2 = texture2D( boneTexture, vec2( dx * ( x + 1.5 ), y ) );\n\t\t\tvec4 v3 = texture2D( boneTexture, vec2( dx * ( x + 2.5 ), y ) );\n\t\t\tvec4 v4 = texture2D( boneTexture, vec2( dx * ( x + 3.5 ), y ) );\n\t\t\tmat4 bone = mat4( v1, v2, v3, v4 );\n\t\t\treturn bone;\n\t\t}\n\t#else\n\t\tuniform mat4 boneMatrices[ MAX_BONES ];\n\t\tmat4 getBoneMatrix( const in float i ) {\n\t\t\tmat4 bone = boneMatrices[ int(i) ];\n\t\t\treturn bone;\n\t\t}\n\t#endif\n#endif";var skinning_vertex="#ifdef USE_SKINNING\n\tvec4 skinVertex = bindMatrix * vec4( transformed, 1.0 );\n\tvec4 skinned = vec4( 0.0 );\n\tskinned += boneMatX * skinVertex * skinWeight.x;\n\tskinned += boneMatY * skinVertex * skinWeight.y;\n\tskinned += boneMatZ * skinVertex * skinWeight.z;\n\tskinned += boneMatW * skinVertex * skinWeight.w;\n\ttransformed = ( bindMatrixInverse * skinned ).xyz;\n#endif";var skinnormal_vertex="#ifdef USE_SKINNING\n\tmat4 skinMatrix = mat4( 0.0 );\n\tskinMatrix += skinWeight.x * boneMatX;\n\tskinMatrix += skinWeight.y * boneMatY;\n\tskinMatrix += skinWeight.z * boneMatZ;\n\tskinMatrix += skinWeight.w * boneMatW;\n\tskinMatrix = bindMatrixInverse * skinMatrix * bindMatrix;\n\tobjectNormal = vec4( skinMatrix * vec4( objectNormal, 0.0 ) ).xyz;\n\t#ifdef USE_TANGENT\n\t\tobjectTangent = vec4( skinMatrix * vec4( objectTangent, 0.0 ) ).xyz;\n\t#endif\n#endif";var specularmap_fragment="float specularStrength;\n#ifdef USE_SPECULARMAP\n\tvec4 texelSpecular = texture2D( specularMap, vUv );\n\tspecularStrength = texelSpecular.r;\n#else\n\tspecularStrength = 1.0;\n#endif";var specularmap_pars_fragment="#ifdef USE_SPECULARMAP\n\tuniform sampler2D specularMap;\n#endif";var tonemapping_fragment="#if defined( TONE_MAPPING )\n\tgl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif";var tonemapping_pars_fragment="#ifndef saturate\n#define saturate(a) clamp( a, 0.0, 1.0 )\n#endif\nuniform float toneMappingExposure;\nuniform float toneMappingWhitePoint;\nvec3 LinearToneMapping( vec3 color ) {\n\treturn toneMappingExposure * color;\n}\nvec3 ReinhardToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\treturn saturate( color / ( vec3( 1.0 ) + color ) );\n}\n#define Uncharted2Helper( x ) max( ( ( x * ( 0.15 * x + 0.10 * 0.50 ) + 0.20 * 0.02 ) / ( x * ( 0.15 * x + 0.50 ) + 0.20 * 0.30 ) ) - 0.02 / 0.30, vec3( 0.0 ) )\nvec3 Uncharted2ToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\treturn saturate( Uncharted2Helper( color ) / Uncharted2Helper( vec3( toneMappingWhitePoint ) ) );\n}\nvec3 OptimizedCineonToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\tcolor = max( vec3( 0.0 ), color - 0.004 );\n\treturn pow( ( color * ( 6.2 * color + 0.5 ) ) / ( color * ( 6.2 * color + 1.7 ) + 0.06 ), vec3( 2.2 ) );\n}\nvec3 ACESFilmicToneMapping( vec3 color ) {\n\tcolor *= toneMappingExposure;\n\treturn saturate( ( color * ( 2.51 * color + 0.03 ) ) / ( color * ( 2.43 * color + 0.59 ) + 0.14 ) );\n}";var uv_pars_fragment="#if ( defined( USE_UV ) && ! defined( UVS_VERTEX_ONLY ) )\n\tvarying vec2 vUv;\n#endif";var uv_pars_vertex="#ifdef USE_UV\n\t#ifdef UVS_VERTEX_ONLY\n\t\tvec2 vUv;\n\t#else\n\t\tvarying vec2 vUv;\n\t#endif\n\tuniform mat3 uvTransform;\n#endif";var uv_vertex="#ifdef USE_UV\n\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n#endif";var uv2_pars_fragment="#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvarying vec2 vUv2;\n#endif";var uv2_pars_vertex="#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tattribute vec2 uv2;\n\tvarying vec2 vUv2;\n\tuniform mat3 uv2Transform;\n#endif";var uv2_vertex="#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvUv2 = ( uv2Transform * vec3( uv2, 1 ) ).xy;\n#endif";var worldpos_vertex="#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP )\n\tvec4 worldPosition = vec4( transformed, 1.0 );\n\t#ifdef USE_INSTANCING\n\t\tworldPosition = instanceMatrix * worldPosition;\n\t#endif\n\tworldPosition = modelMatrix * worldPosition;\n#endif";var background_frag="uniform sampler2D t2D;\nvarying vec2 vUv;\nvoid main() {\n\tvec4 texColor = texture2D( t2D, vUv );\n\tgl_FragColor = mapTexelToLinear( texColor );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n}";var background_vert="varying vec2 vUv;\nuniform mat3 uvTransform;\nvoid main() {\n\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n\tgl_Position = vec4( position.xy, 1.0, 1.0 );\n}";var cube_frag="#include <envmap_common_pars_fragment>\nuniform float opacity;\nvarying vec3 vWorldDirection;\n#include <cube_uv_reflection_fragment>\nvoid main() {\n\tvec3 vReflect = vWorldDirection;\n\t#include <envmap_fragment>\n\tgl_FragColor = envColor;\n\tgl_FragColor.a *= opacity;\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n}";var cube_vert="varying vec3 vWorldDirection;\n#include <common>\nvoid main() {\n\tvWorldDirection = transformDirection( position, modelMatrix );\n\t#include <begin_vertex>\n\t#include <project_vertex>\n\tgl_Position.z = gl_Position.w;\n}";var depth_frag="#if DEPTH_PACKING == 3200\n\tuniform float opacity;\n#endif\n#include <common>\n#include <packing>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvarying vec2 vHighPrecisionZW;\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( 1.0 );\n\t#if DEPTH_PACKING == 3200\n\t\tdiffuseColor.a = opacity;\n\t#endif\n\t#include <map_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <logdepthbuf_fragment>\n\tfloat fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;\n\t#if DEPTH_PACKING == 3200\n\t\tgl_FragColor = vec4( vec3( 1.0 - fragCoordZ ), opacity );\n\t#elif DEPTH_PACKING == 3201\n\t\tgl_FragColor = packDepthToRGBA( fragCoordZ );\n\t#endif\n}";var depth_vert="#include <common>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvarying vec2 vHighPrecisionZW;\nvoid main() {\n\t#include <uv_vertex>\n\t#include <skinbase_vertex>\n\t#ifdef USE_DISPLACEMENTMAP\n\t\t#include <beginnormal_vertex>\n\t\t#include <morphnormal_vertex>\n\t\t#include <skinnormal_vertex>\n\t#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvHighPrecisionZW = gl_Position.zw;\n}";var distanceRGBA_frag="#define DISTANCE\nuniform vec3 referencePosition;\nuniform float nearDistance;\nuniform float farDistance;\nvarying vec3 vWorldPosition;\n#include <common>\n#include <packing>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main () {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( 1.0 );\n\t#include <map_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\tfloat dist = length( vWorldPosition - referencePosition );\n\tdist = ( dist - nearDistance ) / ( farDistance - nearDistance );\n\tdist = saturate( dist );\n\tgl_FragColor = packDepthToRGBA( dist );\n}";var distanceRGBA_vert="#define DISTANCE\nvarying vec3 vWorldPosition;\n#include <common>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <skinbase_vertex>\n\t#ifdef USE_DISPLACEMENTMAP\n\t\t#include <beginnormal_vertex>\n\t\t#include <morphnormal_vertex>\n\t\t#include <skinnormal_vertex>\n\t#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <worldpos_vertex>\n\t#include <clipping_planes_vertex>\n\tvWorldPosition = worldPosition.xyz;\n}";var equirect_frag="uniform sampler2D tEquirect;\nvarying vec3 vWorldDirection;\n#include <common>\nvoid main() {\n\tvec3 direction = normalize( vWorldDirection );\n\tvec2 sampleUV;\n\tsampleUV.y = asin( clamp( direction.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;\n\tsampleUV.x = atan( direction.z, direction.x ) * RECIPROCAL_PI2 + 0.5;\n\tvec4 texColor = texture2D( tEquirect, sampleUV );\n\tgl_FragColor = mapTexelToLinear( texColor );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n}";var equirect_vert="varying vec3 vWorldDirection;\n#include <common>\nvoid main() {\n\tvWorldDirection = transformDirection( position, modelMatrix );\n\t#include <begin_vertex>\n\t#include <project_vertex>\n}";var linedashed_frag="uniform vec3 diffuse;\nuniform float opacity;\nuniform float dashSize;\nuniform float totalSize;\nvarying float vLineDistance;\n#include <common>\n#include <color_pars_fragment>\n#include <fog_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tif ( mod( vLineDistance, totalSize ) > dashSize ) {\n\t\tdiscard;\n\t}\n\tvec3 outgoingLight = vec3( 0.0 );\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <color_fragment>\n\toutgoingLight = diffuseColor.rgb;\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n}";var linedashed_vert="uniform float scale;\nattribute float lineDistance;\nvarying float vLineDistance;\n#include <common>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\tvLineDistance = scale * lineDistance;\n\t#include <color_vertex>\n\t#include <begin_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <fog_vertex>\n}";var meshbasic_frag="uniform vec3 diffuse;\nuniform float opacity;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include <common>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_pars_fragment>\n#include <cube_uv_reflection_fragment>\n#include <fog_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <specularmap_fragment>\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\t#ifdef USE_LIGHTMAP\n\t\n\t\tvec4 lightMapTexel= texture2D( lightMap, vUv2 );\n\t\treflectedLight.indirectDiffuse += lightMapTexelToLinear( lightMapTexel ).rgb * lightMapIntensity;\n\t#else\n\t\treflectedLight.indirectDiffuse += vec3( 1.0 );\n\t#endif\n\t#include <aomap_fragment>\n\treflectedLight.indirectDiffuse *= diffuseColor.rgb;\n\tvec3 outgoingLight = reflectedLight.indirectDiffuse;\n\t#include <envmap_fragment>\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";var meshbasic_vert="#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <envmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <uv2_vertex>\n\t#include <color_vertex>\n\t#include <skinbase_vertex>\n\t#ifdef USE_ENVMAP\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <worldpos_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <envmap_vertex>\n\t#include <fog_vertex>\n}";var meshlambert_frag="uniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float opacity;\nvarying vec3 vLightFront;\nvarying vec3 vIndirectFront;\n#ifdef DOUBLE_SIDED\n\tvarying vec3 vLightBack;\n\tvarying vec3 vIndirectBack;\n#endif\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_pars_fragment>\n#include <cube_uv_reflection_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <fog_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <shadowmask_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <specularmap_fragment>\n\t#include <emissivemap_fragment>\n\t#ifdef DOUBLE_SIDED\n\t\treflectedLight.indirectDiffuse += ( gl_FrontFacing ) ? vIndirectFront : vIndirectBack;\n\t#else\n\t\treflectedLight.indirectDiffuse += vIndirectFront;\n\t#endif\n\t#include <lightmap_fragment>\n\treflectedLight.indirectDiffuse *= BRDF_Diffuse_Lambert( diffuseColor.rgb );\n\t#ifdef DOUBLE_SIDED\n\t\treflectedLight.directDiffuse = ( gl_FrontFacing ) ? vLightFront : vLightBack;\n\t#else\n\t\treflectedLight.directDiffuse = vLightFront;\n\t#endif\n\treflectedLight.directDiffuse *= BRDF_Diffuse_Lambert( diffuseColor.rgb ) * getShadowMask();\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;\n\t#include <envmap_fragment>\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";var meshlambert_vert="#define LAMBERT\nvarying vec3 vLightFront;\nvarying vec3 vIndirectFront;\n#ifdef DOUBLE_SIDED\n\tvarying vec3 vLightBack;\n\tvarying vec3 vIndirectBack;\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <envmap_pars_vertex>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <uv2_vertex>\n\t#include <color_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <worldpos_vertex>\n\t#include <envmap_vertex>\n\t#include <lights_lambert_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}";var meshmatcap_frag="#define MATCAP\nuniform vec3 diffuse;\nuniform float opacity;\nuniform sampler2D matcap;\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include <common>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <fog_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\tvec3 viewDir = normalize( vViewPosition );\n\tvec3 x = normalize( vec3( viewDir.z, 0.0, - viewDir.x ) );\n\tvec3 y = cross( viewDir, x );\n\tvec2 uv = vec2( dot( x, normal ), dot( y, normal ) ) * 0.495 + 0.5;\n\t#ifdef USE_MATCAP\n\t\tvec4 matcapColor = texture2D( matcap, uv );\n\t\tmatcapColor = matcapTexelToLinear( matcapColor );\n\t#else\n\t\tvec4 matcapColor = vec4( 1.0 );\n\t#endif\n\tvec3 outgoingLight = diffuseColor.rgb * matcapColor.rgb;\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";var meshmatcap_vert="#define MATCAP\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <color_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <color_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n\t#ifndef FLAT_SHADED\n\t\tvNormal = normalize( transformedNormal );\n\t#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <fog_vertex>\n\tvViewPosition = - mvPosition.xyz;\n}";var meshtoon_frag="#define TOON\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform vec3 specular;\nuniform float shininess;\nuniform float opacity;\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <gradientmap_pars_fragment>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <lights_toon_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <specularmap_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\t#include <emissivemap_fragment>\n\t#include <lights_toon_fragment>\n\t#include <lights_fragment_begin>\n\t#include <lights_fragment_maps>\n\t#include <lights_fragment_end>\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";var meshtoon_vert="#define TOON\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <uv2_vertex>\n\t#include <color_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n#ifndef FLAT_SHADED\n\tvNormal = normalize( transformedNormal );\n#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}";var meshphong_frag="#define PHONG\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform vec3 specular;\nuniform float shininess;\nuniform float opacity;\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_pars_fragment>\n#include <cube_uv_reflection_fragment>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <lights_phong_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <specularmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <specularmap_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\t#include <emissivemap_fragment>\n\t#include <lights_phong_fragment>\n\t#include <lights_fragment_begin>\n\t#include <lights_fragment_maps>\n\t#include <lights_fragment_end>\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;\n\t#include <envmap_fragment>\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";var meshphong_vert="#define PHONG\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <envmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <uv2_vertex>\n\t#include <color_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n#ifndef FLAT_SHADED\n\tvNormal = normalize( transformedNormal );\n#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <envmap_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}";var meshphysical_frag="#define STANDARD\n#ifdef PHYSICAL\n\t#define REFLECTIVITY\n\t#define CLEARCOAT\n\t#define TRANSPARENCY\n#endif\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float roughness;\nuniform float metalness;\nuniform float opacity;\n#ifdef TRANSPARENCY\n\tuniform float transparency;\n#endif\n#ifdef REFLECTIVITY\n\tuniform float reflectivity;\n#endif\n#ifdef CLEARCOAT\n\tuniform float clearcoat;\n\tuniform float clearcoatRoughness;\n#endif\n#ifdef USE_SHEEN\n\tuniform vec3 sheen;\n#endif\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n\t#ifdef USE_TANGENT\n\t\tvarying vec3 vTangent;\n\t\tvarying vec3 vBitangent;\n\t#endif\n#endif\n#include <common>\n#include <packing>\n#include <dithering_pars_fragment>\n#include <color_pars_fragment>\n#include <uv_pars_fragment>\n#include <uv2_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <aomap_pars_fragment>\n#include <lightmap_pars_fragment>\n#include <emissivemap_pars_fragment>\n#include <bsdfs>\n#include <cube_uv_reflection_fragment>\n#include <envmap_common_pars_fragment>\n#include <envmap_physical_pars_fragment>\n#include <fog_pars_fragment>\n#include <lights_pars_begin>\n#include <lights_physical_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <clearcoat_pars_fragment>\n#include <roughnessmap_pars_fragment>\n#include <metalnessmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\tReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n\tvec3 totalEmissiveRadiance = emissive;\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <color_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <roughnessmap_fragment>\n\t#include <metalnessmap_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\t#include <clearcoat_normal_fragment_begin>\n\t#include <clearcoat_normal_fragment_maps>\n\t#include <emissivemap_fragment>\n\t#include <lights_physical_fragment>\n\t#include <lights_fragment_begin>\n\t#include <lights_fragment_maps>\n\t#include <lights_fragment_end>\n\t#include <aomap_fragment>\n\tvec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;\n\t#ifdef TRANSPARENCY\n\t\tdiffuseColor.a *= saturate( 1. - transparency + linearToRelativeLuminance( reflectedLight.directSpecular + reflectedLight.indirectSpecular ) );\n\t#endif\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n\t#include <dithering_fragment>\n}";var meshphysical_vert="#define STANDARD\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n\t#ifdef USE_TANGENT\n\t\tvarying vec3 vTangent;\n\t\tvarying vec3 vBitangent;\n\t#endif\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <uv2_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <shadowmap_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <uv2_vertex>\n\t#include <color_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n#ifndef FLAT_SHADED\n\tvNormal = normalize( transformedNormal );\n\t#ifdef USE_TANGENT\n\t\tvTangent = normalize( transformedTangent );\n\t\tvBitangent = normalize( cross( vNormal, vTangent ) * tangent.w );\n\t#endif\n#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\tvViewPosition = - mvPosition.xyz;\n\t#include <worldpos_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}";var normal_frag="#define NORMAL\nuniform float opacity;\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( TANGENTSPACE_NORMALMAP )\n\tvarying vec3 vViewPosition;\n#endif\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n\t#ifdef USE_TANGENT\n\t\tvarying vec3 vTangent;\n\t\tvarying vec3 vBitangent;\n\t#endif\n#endif\n#include <packing>\n#include <uv_pars_fragment>\n#include <bumpmap_pars_fragment>\n#include <normalmap_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\t#include <logdepthbuf_fragment>\n\t#include <normal_fragment_begin>\n\t#include <normal_fragment_maps>\n\tgl_FragColor = vec4( packNormalToRGB( normal ), opacity );\n}";var normal_vert="#define NORMAL\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( TANGENTSPACE_NORMALMAP )\n\tvarying vec3 vViewPosition;\n#endif\n#ifndef FLAT_SHADED\n\tvarying vec3 vNormal;\n\t#ifdef USE_TANGENT\n\t\tvarying vec3 vTangent;\n\t\tvarying vec3 vBitangent;\n\t#endif\n#endif\n#include <common>\n#include <uv_pars_vertex>\n#include <displacementmap_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <skinning_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\t#include <beginnormal_vertex>\n\t#include <morphnormal_vertex>\n\t#include <skinbase_vertex>\n\t#include <skinnormal_vertex>\n\t#include <defaultnormal_vertex>\n#ifndef FLAT_SHADED\n\tvNormal = normalize( transformedNormal );\n\t#ifdef USE_TANGENT\n\t\tvTangent = normalize( transformedTangent );\n\t\tvBitangent = normalize( cross( vNormal, vTangent ) * tangent.w );\n\t#endif\n#endif\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <skinning_vertex>\n\t#include <displacementmap_vertex>\n\t#include <project_vertex>\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( TANGENTSPACE_NORMALMAP )\n\tvViewPosition = - mvPosition.xyz;\n#endif\n}";var points_frag="uniform vec3 diffuse;\nuniform float opacity;\n#include <common>\n#include <color_pars_fragment>\n#include <map_particle_pars_fragment>\n#include <fog_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec3 outgoingLight = vec3( 0.0 );\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <map_particle_fragment>\n\t#include <color_fragment>\n\t#include <alphatest_fragment>\n\toutgoingLight = diffuseColor.rgb;\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n\t#include <premultiplied_alpha_fragment>\n}";var points_vert="uniform float size;\nuniform float scale;\n#include <common>\n#include <color_pars_vertex>\n#include <fog_pars_vertex>\n#include <morphtarget_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <color_vertex>\n\t#include <begin_vertex>\n\t#include <morphtarget_vertex>\n\t#include <project_vertex>\n\tgl_PointSize = size;\n\t#ifdef USE_SIZEATTENUATION\n\t\tbool isPerspective = isPerspectiveMatrix( projectionMatrix );\n\t\tif ( isPerspective ) gl_PointSize *= ( scale / - mvPosition.z );\n\t#endif\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <worldpos_vertex>\n\t#include <fog_vertex>\n}";var shadow_frag="uniform vec3 color;\nuniform float opacity;\n#include <common>\n#include <packing>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <shadowmap_pars_fragment>\n#include <shadowmask_pars_fragment>\nvoid main() {\n\tgl_FragColor = vec4( color, opacity * ( 1.0 - getShadowMask() ) );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n}";var shadow_vert="#include <fog_pars_vertex>\n#include <shadowmap_pars_vertex>\nvoid main() {\n\t#include <begin_vertex>\n\t#include <project_vertex>\n\t#include <worldpos_vertex>\n\t#include <shadowmap_vertex>\n\t#include <fog_vertex>\n}";var sprite_frag="uniform vec3 diffuse;\nuniform float opacity;\n#include <common>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <fog_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\t#include <clipping_planes_fragment>\n\tvec3 outgoingLight = vec3( 0.0 );\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\toutgoingLight = diffuseColor.rgb;\n\tgl_FragColor = vec4( outgoingLight, diffuseColor.a );\n\t#include <tonemapping_fragment>\n\t#include <encodings_fragment>\n\t#include <fog_fragment>\n}";var sprite_vert="uniform float rotation;\nuniform vec2 center;\n#include <common>\n#include <uv_pars_vertex>\n#include <fog_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\tvec4 mvPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );\n\tvec2 scale;\n\tscale.x = length( vec3( modelMatrix[ 0 ].x, modelMatrix[ 0 ].y, modelMatrix[ 0 ].z ) );\n\tscale.y = length( vec3( modelMatrix[ 1 ].x, modelMatrix[ 1 ].y, modelMatrix[ 1 ].z ) );\n\t#ifndef USE_SIZEATTENUATION\n\t\tbool isPerspective = isPerspectiveMatrix( projectionMatrix );\n\t\tif ( isPerspective ) scale *= - mvPosition.z;\n\t#endif\n\tvec2 alignedPosition = ( position.xy - ( center - vec2( 0.5 ) ) ) * scale;\n\tvec2 rotatedPosition;\n\trotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;\n\trotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;\n\tmvPosition.xy += rotatedPosition;\n\tgl_Position = projectionMatrix * mvPosition;\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <fog_vertex>\n}";var ShaderChunk={alphamap_fragment:alphamap_fragment,alphamap_pars_fragment:alphamap_pars_fragment,alphatest_fragment:alphatest_fragment,aomap_fragment:aomap_fragment,aomap_pars_fragment:aomap_pars_fragment,begin_vertex:begin_vertex,beginnormal_vertex:beginnormal_vertex,bsdfs:bsdfs,bumpmap_pars_fragment:bumpmap_pars_fragment,clipping_planes_fragment:clipping_planes_fragment,clipping_planes_pars_fragment:clipping_planes_pars_fragment,clipping_planes_pars_vertex:clipping_planes_pars_vertex,clipping_planes_vertex:clipping_planes_vertex,color_fragment:color_fragment,color_pars_fragment:color_pars_fragment,color_pars_vertex:color_pars_vertex,color_vertex:color_vertex,common:common,cube_uv_reflection_fragment:cube_uv_reflection_fragment,defaultnormal_vertex:defaultnormal_vertex,displacementmap_pars_vertex:displacementmap_pars_vertex,displacementmap_vertex:displacementmap_vertex,emissivemap_fragment:emissivemap_fragment,emissivemap_pars_fragment:emissivemap_pars_fragment,encodings_fragment:encodings_fragment,encodings_pars_fragment:encodings_pars_fragment,envmap_fragment:envmap_fragment,envmap_common_pars_fragment:envmap_common_pars_fragment,envmap_pars_fragment:envmap_pars_fragment,envmap_pars_vertex:envmap_pars_vertex,envmap_physical_pars_fragment:envmap_physical_pars_fragment,envmap_vertex:envmap_vertex,fog_vertex:fog_vertex,fog_pars_vertex:fog_pars_vertex,fog_fragment:fog_fragment,fog_pars_fragment:fog_pars_fragment,gradientmap_pars_fragment:gradientmap_pars_fragment,lightmap_fragment:lightmap_fragment,lightmap_pars_fragment:lightmap_pars_fragment,lights_lambert_vertex:lights_lambert_vertex,lights_pars_begin:lights_pars_begin,lights_toon_fragment:lights_toon_fragment,lights_toon_pars_fragment:lights_toon_pars_fragment,lights_phong_fragment:lights_phong_fragment,lights_phong_pars_fragment:lights_phong_pars_fragment,lights_physical_fragment:lights_physical_fragment,lights_physical_pars_fragment:lights_physical_pars_fragment,lights_fragment_begin:lights_fragment_begin,lights_fragment_maps:lights_fragment_maps,lights_fragment_end:lights_fragment_end,logdepthbuf_fragment:logdepthbuf_fragment,logdepthbuf_pars_fragment:logdepthbuf_pars_fragment,logdepthbuf_pars_vertex:logdepthbuf_pars_vertex,logdepthbuf_vertex:logdepthbuf_vertex,map_fragment:map_fragment,map_pars_fragment:map_pars_fragment,map_particle_fragment:map_particle_fragment,map_particle_pars_fragment:map_particle_pars_fragment,metalnessmap_fragment:metalnessmap_fragment,metalnessmap_pars_fragment:metalnessmap_pars_fragment,morphnormal_vertex:morphnormal_vertex,morphtarget_pars_vertex:morphtarget_pars_vertex,morphtarget_vertex:morphtarget_vertex,normal_fragment_begin:normal_fragment_begin,normal_fragment_maps:normal_fragment_maps,normalmap_pars_fragment:normalmap_pars_fragment,clearcoat_normal_fragment_begin:clearcoat_normal_fragment_begin,clearcoat_normal_fragment_maps:clearcoat_normal_fragment_maps,clearcoat_pars_fragment:clearcoat_pars_fragment,packing:packing,premultiplied_alpha_fragment:premultiplied_alpha_fragment,project_vertex:project_vertex,dithering_fragment:dithering_fragment,dithering_pars_fragment:dithering_pars_fragment,roughnessmap_fragment:roughnessmap_fragment,roughnessmap_pars_fragment:roughnessmap_pars_fragment,shadowmap_pars_fragment:shadowmap_pars_fragment,shadowmap_pars_vertex:shadowmap_pars_vertex,shadowmap_vertex:shadowmap_vertex,shadowmask_pars_fragment:shadowmask_pars_fragment,skinbase_vertex:skinbase_vertex,skinning_pars_vertex:skinning_pars_vertex,skinning_vertex:skinning_vertex,skinnormal_vertex:skinnormal_vertex,specularmap_fragment:specularmap_fragment,specularmap_pars_fragment:specularmap_pars_fragment,tonemapping_fragment:tonemapping_fragment,tonemapping_pars_fragment:tonemapping_pars_fragment,uv_pars_fragment:uv_pars_fragment,uv_pars_vertex:uv_pars_vertex,uv_vertex:uv_vertex,uv2_pars_fragment:uv2_pars_fragment,uv2_pars_vertex:uv2_pars_vertex,uv2_vertex:uv2_vertex,worldpos_vertex:worldpos_vertex,background_frag:background_frag,background_vert:background_vert,cube_frag:cube_frag,cube_vert:cube_vert,depth_frag:depth_frag,depth_vert:depth_vert,distanceRGBA_frag:distanceRGBA_frag,distanceRGBA_vert:distanceRGBA_vert,equirect_frag:equirect_frag,equirect_vert:equirect_vert,linedashed_frag:linedashed_frag,linedashed_vert:linedashed_vert,meshbasic_frag:meshbasic_frag,meshbasic_vert:meshbasic_vert,meshlambert_frag:meshlambert_frag,meshlambert_vert:meshlambert_vert,meshmatcap_frag:meshmatcap_frag,meshmatcap_vert:meshmatcap_vert,meshtoon_frag:meshtoon_frag,meshtoon_vert:meshtoon_vert,meshphong_frag:meshphong_frag,meshphong_vert:meshphong_vert,meshphysical_frag:meshphysical_frag,meshphysical_vert:meshphysical_vert,normal_frag:normal_frag,normal_vert:normal_vert,points_frag:points_frag,points_vert:points_vert,shadow_frag:shadow_frag,shadow_vert:shadow_vert,sprite_frag:sprite_frag,sprite_vert:sprite_vert}; |
1095 |
|
1096 |
|
1097 |
|
1098 | var ShaderLib={basic:{uniforms:mergeUniforms([UniformsLib.common,UniformsLib.specularmap,UniformsLib.envmap,UniformsLib.aomap,UniformsLib.lightmap,UniformsLib.fog]),vertexShader:ShaderChunk.meshbasic_vert,fragmentShader:ShaderChunk.meshbasic_frag},lambert:{uniforms:mergeUniforms([UniformsLib.common,UniformsLib.specularmap,UniformsLib.envmap,UniformsLib.aomap,UniformsLib.lightmap,UniformsLib.emissivemap,UniformsLib.fog,UniformsLib.lights,{emissive:{value:new Color(0x000000)}}]),vertexShader:ShaderChunk.meshlambert_vert,fragmentShader:ShaderChunk.meshlambert_frag},phong:{uniforms:mergeUniforms([UniformsLib.common,UniformsLib.specularmap,UniformsLib.envmap,UniformsLib.aomap,UniformsLib.lightmap,UniformsLib.emissivemap,UniformsLib.bumpmap,UniformsLib.normalmap,UniformsLib.displacementmap,UniformsLib.fog,UniformsLib.lights,{emissive:{value:new Color(0x000000)},specular:{value:new Color(0x111111)},shininess:{value:30}}]),vertexShader:ShaderChunk.meshphong_vert,fragmentShader:ShaderChunk.meshphong_frag},standard:{uniforms:mergeUniforms([UniformsLib.common,UniformsLib.envmap,UniformsLib.aomap,UniformsLib.lightmap,UniformsLib.emissivemap,UniformsLib.bumpmap,UniformsLib.normalmap,UniformsLib.displacementmap,UniformsLib.roughnessmap,UniformsLib.metalnessmap,UniformsLib.fog,UniformsLib.lights,{emissive:{value:new Color(0x000000)},roughness:{value:1.0},metalness:{value:0.0},envMapIntensity:{value:1}
|
1099 | }]),vertexShader:ShaderChunk.meshphysical_vert,fragmentShader:ShaderChunk.meshphysical_frag},toon:{uniforms:mergeUniforms([UniformsLib.common,UniformsLib.specularmap,UniformsLib.aomap,UniformsLib.lightmap,UniformsLib.emissivemap,UniformsLib.bumpmap,UniformsLib.normalmap,UniformsLib.displacementmap,UniformsLib.gradientmap,UniformsLib.fog,UniformsLib.lights,{emissive:{value:new Color(0x000000)},specular:{value:new Color(0x111111)},shininess:{value:30}}]),vertexShader:ShaderChunk.meshtoon_vert,fragmentShader:ShaderChunk.meshtoon_frag},matcap:{uniforms:mergeUniforms([UniformsLib.common,UniformsLib.bumpmap,UniformsLib.normalmap,UniformsLib.displacementmap,UniformsLib.fog,{matcap:{value:null}}]),vertexShader:ShaderChunk.meshmatcap_vert,fragmentShader:ShaderChunk.meshmatcap_frag},points:{uniforms:mergeUniforms([UniformsLib.points,UniformsLib.fog]),vertexShader:ShaderChunk.points_vert,fragmentShader:ShaderChunk.points_frag},dashed:{uniforms:mergeUniforms([UniformsLib.common,UniformsLib.fog,{scale:{value:1},dashSize:{value:1},totalSize:{value:2}}]),vertexShader:ShaderChunk.linedashed_vert,fragmentShader:ShaderChunk.linedashed_frag},depth:{uniforms:mergeUniforms([UniformsLib.common,UniformsLib.displacementmap]),vertexShader:ShaderChunk.depth_vert,fragmentShader:ShaderChunk.depth_frag},normal:{uniforms:mergeUniforms([UniformsLib.common,UniformsLib.bumpmap,UniformsLib.normalmap,UniformsLib.displacementmap,{opacity:{value:1.0}}]),vertexShader:ShaderChunk.normal_vert,fragmentShader:ShaderChunk.normal_frag},sprite:{uniforms:mergeUniforms([UniformsLib.sprite,UniformsLib.fog]),vertexShader:ShaderChunk.sprite_vert,fragmentShader:ShaderChunk.sprite_frag},background:{uniforms:{uvTransform:{value:new Matrix3()},t2D:{value:null}},vertexShader:ShaderChunk.background_vert,fragmentShader:ShaderChunk.background_frag}, |
1100 |
|
1101 | cube:{uniforms:mergeUniforms([UniformsLib.envmap,{opacity:{value:1.0}}]),vertexShader:ShaderChunk.cube_vert,fragmentShader:ShaderChunk.cube_frag},equirect:{uniforms:{tEquirect:{value:null}},vertexShader:ShaderChunk.equirect_vert,fragmentShader:ShaderChunk.equirect_frag},distanceRGBA:{uniforms:mergeUniforms([UniformsLib.common,UniformsLib.displacementmap,{referencePosition:{value:new Vector3()},nearDistance:{value:1},farDistance:{value:1000}}]),vertexShader:ShaderChunk.distanceRGBA_vert,fragmentShader:ShaderChunk.distanceRGBA_frag},shadow:{uniforms:mergeUniforms([UniformsLib.lights,UniformsLib.fog,{color:{value:new Color(0x00000)},opacity:{value:1.0}}]),vertexShader:ShaderChunk.shadow_vert,fragmentShader:ShaderChunk.shadow_frag}};ShaderLib.physical={uniforms:mergeUniforms([ShaderLib.standard.uniforms,{clearcoat:{value:0},clearcoatMap:{value:null},clearcoatRoughness:{value:0},clearcoatRoughnessMap:{value:null},clearcoatNormalScale:{value:new Vector2(1,1)},clearcoatNormalMap:{value:null},sheen:{value:new Color(0x000000)},transparency:{value:0}}]),vertexShader:ShaderChunk.meshphysical_vert,fragmentShader:ShaderChunk.meshphysical_frag}; |
1102 |
|
1103 | function WebGLBackground(renderer,state,objects,premultipliedAlpha){var clearColor=new Color(0x000000);var clearAlpha=0;var planeMesh;var boxMesh;var currentBackground=null;var currentBackgroundVersion=0;var currentTonemapping=null;function render(renderList,scene,camera,forceClear){var background=scene.background;
|
1104 |
|
1105 | var xr=renderer.xr;var session=xr.getSession&&xr.getSession();if(session&&session.environmentBlendMode==='additive'){background=null;}if(background===null){setClear(clearColor,clearAlpha);}else if(background&&background.isColor){setClear(background,1);forceClear=true;}if(renderer.autoClear||forceClear){renderer.clear(renderer.autoClearColor,renderer.autoClearDepth,renderer.autoClearStencil);}if(background&&(background.isCubeTexture||background.isWebGLCubeRenderTarget||background.mapping===CubeUVReflectionMapping)){if(boxMesh===undefined){boxMesh=new Mesh(new BoxBufferGeometry(1,1,1),new ShaderMaterial({type:'BackgroundCubeMaterial',uniforms:cloneUniforms(ShaderLib.cube.uniforms),vertexShader:ShaderLib.cube.vertexShader,fragmentShader:ShaderLib.cube.fragmentShader,side:BackSide,depthTest:false,depthWrite:false,fog:false}));boxMesh.geometry.deleteAttribute('normal');boxMesh.geometry.deleteAttribute('uv');boxMesh.onBeforeRender=function(renderer,scene,camera){this.matrixWorld.copyPosition(camera.matrixWorld);};
|
1106 | Object.defineProperty(boxMesh.material,'envMap',{get:function get(){return this.uniforms.envMap.value;}});objects.update(boxMesh);}var texture=background.isWebGLCubeRenderTarget?background.texture:background;boxMesh.material.uniforms.envMap.value=texture;boxMesh.material.uniforms.flipEnvMap.value=texture.isCubeTexture?-1:1;if(currentBackground!==background||currentBackgroundVersion!==texture.version||currentTonemapping!==renderer.toneMapping){boxMesh.material.needsUpdate=true;currentBackground=background;currentBackgroundVersion=texture.version;currentTonemapping=renderer.toneMapping;}
|
1107 | renderList.unshift(boxMesh,boxMesh.geometry,boxMesh.material,0,0,null);}else if(background&&background.isTexture){if(planeMesh===undefined){planeMesh=new Mesh(new PlaneBufferGeometry(2,2),new ShaderMaterial({type:'BackgroundMaterial',uniforms:cloneUniforms(ShaderLib.background.uniforms),vertexShader:ShaderLib.background.vertexShader,fragmentShader:ShaderLib.background.fragmentShader,side:FrontSide,depthTest:false,depthWrite:false,fog:false}));planeMesh.geometry.deleteAttribute('normal');
|
1108 | Object.defineProperty(planeMesh.material,'map',{get:function get(){return this.uniforms.t2D.value;}});objects.update(planeMesh);}planeMesh.material.uniforms.t2D.value=background;if(background.matrixAutoUpdate===true){background.updateMatrix();}planeMesh.material.uniforms.uvTransform.value.copy(background.matrix);if(currentBackground!==background||currentBackgroundVersion!==background.version||currentTonemapping!==renderer.toneMapping){planeMesh.material.needsUpdate=true;currentBackground=background;currentBackgroundVersion=background.version;currentTonemapping=renderer.toneMapping;}
|
1109 | renderList.unshift(planeMesh,planeMesh.geometry,planeMesh.material,0,0,null);}}function setClear(color,alpha){state.buffers.color.setClear(color.r,color.g,color.b,alpha,premultipliedAlpha);}return {getClearColor:function getClearColor(){return clearColor;},setClearColor:function setClearColor(color,alpha){clearColor.set(color);clearAlpha=alpha!==undefined?alpha:1;setClear(clearColor,clearAlpha);},getClearAlpha:function getClearAlpha(){return clearAlpha;},setClearAlpha:function setClearAlpha(alpha){clearAlpha=alpha;setClear(clearColor,clearAlpha);},render:render};} |
1110 |
|
1111 | function WebGLBufferRenderer(gl,extensions,info,capabilities){var isWebGL2=capabilities.isWebGL2;var mode;function setMode(value){mode=value;}function render(start,count){gl.drawArrays(mode,start,count);info.update(count,mode);}function renderInstances(geometry,start,count,primcount){if(primcount===0)return;var extension,methodName;if(isWebGL2){extension=gl;methodName='drawArraysInstanced';}else {extension=extensions.get('ANGLE_instanced_arrays');methodName='drawArraysInstancedANGLE';if(extension===null){console.error('THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.');return;}}extension[methodName](mode,start,count,primcount);info.update(count,mode,primcount);}
|
1112 | this.setMode=setMode;this.render=render;this.renderInstances=renderInstances;} |
1113 |
|
1114 | function WebGLCapabilities(gl,extensions,parameters){var maxAnisotropy;function getMaxAnisotropy(){if(maxAnisotropy!==undefined)return maxAnisotropy;var extension=extensions.get('EXT_texture_filter_anisotropic');if(extension!==null){maxAnisotropy=gl.getParameter(extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT);}else {maxAnisotropy=0;}return maxAnisotropy;}function getMaxPrecision(precision){if(precision==='highp'){if(gl.getShaderPrecisionFormat(35633,36338).precision>0&&gl.getShaderPrecisionFormat(35632,36338).precision>0){return 'highp';}precision='mediump';}if(precision==='mediump'){if(gl.getShaderPrecisionFormat(35633,36337).precision>0&&gl.getShaderPrecisionFormat(35632,36337).precision>0){return 'mediump';}}return 'lowp';}var isWebGL2=typeof WebGL2RenderingContext!=='undefined'&&gl instanceof WebGL2RenderingContext||typeof WebGL2ComputeRenderingContext!=='undefined'&&gl instanceof WebGL2ComputeRenderingContext;var precision=parameters.precision!==undefined?parameters.precision:'highp';var maxPrecision=getMaxPrecision(precision);if(maxPrecision!==precision){console.warn('THREE.WebGLRenderer:',precision,'not supported, using',maxPrecision,'instead.');precision=maxPrecision;}var logarithmicDepthBuffer=parameters.logarithmicDepthBuffer===true;var maxTextures=gl.getParameter(34930);var maxVertexTextures=gl.getParameter(35660);var maxTextureSize=gl.getParameter(3379);var maxCubemapSize=gl.getParameter(34076);var maxAttributes=gl.getParameter(34921);var maxVertexUniforms=gl.getParameter(36347);var maxVaryings=gl.getParameter(36348);var maxFragmentUniforms=gl.getParameter(36349);var vertexTextures=maxVertexTextures>0;var floatFragmentTextures=isWebGL2||!!extensions.get('OES_texture_float');var floatVertexTextures=vertexTextures&&floatFragmentTextures;var maxSamples=isWebGL2?gl.getParameter(36183):0;return {isWebGL2:isWebGL2,getMaxAnisotropy:getMaxAnisotropy,getMaxPrecision:getMaxPrecision,precision:precision,logarithmicDepthBuffer:logarithmicDepthBuffer,maxTextures:maxTextures,maxVertexTextures:maxVertexTextures,maxTextureSize:maxTextureSize,maxCubemapSize:maxCubemapSize,maxAttributes:maxAttributes,maxVertexUniforms:maxVertexUniforms,maxVaryings:maxVaryings,maxFragmentUniforms:maxFragmentUniforms,vertexTextures:vertexTextures,floatFragmentTextures:floatFragmentTextures,floatVertexTextures:floatVertexTextures,maxSamples:maxSamples};} |
1115 |
|
1116 | function WebGLClipping(){var scope=this,globalState=null,numGlobalPlanes=0,localClippingEnabled=false,renderingShadows=false,plane=new Plane(),viewNormalMatrix=new Matrix3(),uniform={value:null,needsUpdate:false};this.uniform=uniform;this.numPlanes=0;this.numIntersection=0;this.init=function(planes,enableLocalClipping,camera){var enabled=planes.length!==0||enableLocalClipping||
|
1117 |
|
1118 | numGlobalPlanes!==0||localClippingEnabled;localClippingEnabled=enableLocalClipping;globalState=projectPlanes(planes,camera,0);numGlobalPlanes=planes.length;return enabled;};this.beginShadows=function(){renderingShadows=true;projectPlanes(null);};this.endShadows=function(){renderingShadows=false;resetGlobalState();};this.setState=function(planes,clipIntersection,clipShadows,camera,cache,fromCache){if(!localClippingEnabled||planes===null||planes.length===0||renderingShadows&&!clipShadows){
|
1119 | if(renderingShadows){
|
1120 | projectPlanes(null);}else {resetGlobalState();}}else {var nGlobal=renderingShadows?0:numGlobalPlanes,lGlobal=nGlobal*4,dstArray=cache.clippingState||null;uniform.value=dstArray;
|
1121 | dstArray=projectPlanes(planes,camera,lGlobal,fromCache);for(var i=0;i!==lGlobal;++i){dstArray[i]=globalState[i];}cache.clippingState=dstArray;this.numIntersection=clipIntersection?this.numPlanes:0;this.numPlanes+=nGlobal;}};function resetGlobalState(){if(uniform.value!==globalState){uniform.value=globalState;uniform.needsUpdate=numGlobalPlanes>0;}scope.numPlanes=numGlobalPlanes;scope.numIntersection=0;}function projectPlanes(planes,camera,dstOffset,skipTransform){var nPlanes=planes!==null?planes.length:0,dstArray=null;if(nPlanes!==0){dstArray=uniform.value;if(skipTransform!==true||dstArray===null){var flatSize=dstOffset+nPlanes*4,viewMatrix=camera.matrixWorldInverse;viewNormalMatrix.getNormalMatrix(viewMatrix);if(dstArray===null||dstArray.length<flatSize){dstArray=new Float32Array(flatSize);}for(var i=0,i4=dstOffset;i!==nPlanes;++i,i4+=4){plane.copy(planes[i]).applyMatrix4(viewMatrix,viewNormalMatrix);plane.normal.toArray(dstArray,i4);dstArray[i4+3]=plane.constant;}}uniform.value=dstArray;uniform.needsUpdate=true;}scope.numPlanes=nPlanes;scope.numIntersection=0;return dstArray;}} |
1122 |
|
1123 | function WebGLExtensions(gl){var extensions={};return {get:function get(name){if(extensions[name]!==undefined){return extensions[name];}var extension;switch(name){case'WEBGL_depth_texture':extension=gl.getExtension('WEBGL_depth_texture')||gl.getExtension('MOZ_WEBGL_depth_texture')||gl.getExtension('WEBKIT_WEBGL_depth_texture');break;case'EXT_texture_filter_anisotropic':extension=gl.getExtension('EXT_texture_filter_anisotropic')||gl.getExtension('MOZ_EXT_texture_filter_anisotropic')||gl.getExtension('WEBKIT_EXT_texture_filter_anisotropic');break;case'WEBGL_compressed_texture_s3tc':extension=gl.getExtension('WEBGL_compressed_texture_s3tc')||gl.getExtension('MOZ_WEBGL_compressed_texture_s3tc')||gl.getExtension('WEBKIT_WEBGL_compressed_texture_s3tc');break;case'WEBGL_compressed_texture_pvrtc':extension=gl.getExtension('WEBGL_compressed_texture_pvrtc')||gl.getExtension('WEBKIT_WEBGL_compressed_texture_pvrtc');break;default:extension=gl.getExtension(name);}if(extension===null){console.warn('THREE.WebGLRenderer: '+name+' extension not supported.');}extensions[name]=extension;return extension;}};} |
1124 |
|
1125 | function WebGLGeometries(gl,attributes,info){var geometries=new WeakMap();var wireframeAttributes=new WeakMap();function onGeometryDispose(event){var geometry=event.target;var buffergeometry=geometries.get(geometry);if(buffergeometry.index!==null){attributes.remove(buffergeometry.index);}for(var name in buffergeometry.attributes){attributes.remove(buffergeometry.attributes[name]);}geometry.removeEventListener('dispose',onGeometryDispose);geometries["delete"](geometry);var attribute=wireframeAttributes.get(buffergeometry);if(attribute){attributes.remove(attribute);wireframeAttributes["delete"](buffergeometry);}
|
1126 | info.memory.geometries--;}function get(object,geometry){var buffergeometry=geometries.get(geometry);if(buffergeometry)return buffergeometry;geometry.addEventListener('dispose',onGeometryDispose);if(geometry.isBufferGeometry){buffergeometry=geometry;}else if(geometry.isGeometry){if(geometry._bufferGeometry===undefined){geometry._bufferGeometry=new BufferGeometry().setFromObject(object);}buffergeometry=geometry._bufferGeometry;}geometries.set(geometry,buffergeometry);info.memory.geometries++;return buffergeometry;}function update(geometry){var index=geometry.index;var geometryAttributes=geometry.attributes;if(index!==null){attributes.update(index,34963);}for(var name in geometryAttributes){attributes.update(geometryAttributes[name],34962);}
|
1127 | var morphAttributes=geometry.morphAttributes;for(var name in morphAttributes){var array=morphAttributes[name];for(var i=0,l=array.length;i<l;i++){attributes.update(array[i],34962);}}}function updateWireframeAttribute(geometry){var indices=[];var geometryIndex=geometry.index;var geometryPosition=geometry.attributes.position;var version=0;if(geometryIndex!==null){var array=geometryIndex.array;version=geometryIndex.version;for(var i=0,l=array.length;i<l;i+=3){var a=array[i+0];var b=array[i+1];var c=array[i+2];indices.push(a,b,b,c,c,a);}}else {var array=geometryPosition.array;version=geometryPosition.version;for(var i=0,l=array.length/3-1;i<l;i+=3){var a=i+0;var b=i+1;var c=i+2;indices.push(a,b,b,c,c,a);}}var attribute=new(arrayMax(indices)>65535?Uint32BufferAttribute:Uint16BufferAttribute)(indices,1);attribute.version=version;attributes.update(attribute,34963);
|
1128 | var previousAttribute=wireframeAttributes.get(geometry);if(previousAttribute)attributes.remove(previousAttribute);
|
1129 | wireframeAttributes.set(geometry,attribute);}function getWireframeAttribute(geometry){var currentAttribute=wireframeAttributes.get(geometry);if(currentAttribute){var geometryIndex=geometry.index;if(geometryIndex!==null){
|
1130 | if(currentAttribute.version<geometryIndex.version){updateWireframeAttribute(geometry);}}}else {updateWireframeAttribute(geometry);}return wireframeAttributes.get(geometry);}return {get:get,update:update,getWireframeAttribute:getWireframeAttribute};}/**
|
1131 | * @author mrdoob / http://mrdoob.com/
|
1132 | */function WebGLIndexedBufferRenderer(gl,extensions,info,capabilities){var isWebGL2=capabilities.isWebGL2;var mode;function setMode(value){mode=value;}var type,bytesPerElement;function setIndex(value){type=value.type;bytesPerElement=value.bytesPerElement;}function render(start,count){gl.drawElements(mode,count,type,start*bytesPerElement);info.update(count,mode);}function renderInstances(geometry,start,count,primcount){if(primcount===0)return;var extension,methodName;if(isWebGL2){extension=gl;methodName='drawElementsInstanced';}else {extension=extensions.get('ANGLE_instanced_arrays');methodName='drawElementsInstancedANGLE';if(extension===null){console.error('THREE.WebGLIndexedBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.');return;}}extension[methodName](mode,count,type,start*bytesPerElement,primcount);info.update(count,mode,primcount);}
|
1133 | this.setMode=setMode;this.setIndex=setIndex;this.render=render;this.renderInstances=renderInstances;} |
1134 |
|
1135 | function WebGLInfo(gl){var memory={geometries:0,textures:0};var render={frame:0,calls:0,triangles:0,points:0,lines:0};function update(count,mode,instanceCount){instanceCount=instanceCount||1;render.calls++;switch(mode){case 4:render.triangles+=instanceCount*(count/3);break;case 1:render.lines+=instanceCount*(count/2);break;case 3:render.lines+=instanceCount*(count-1);break;case 2:render.lines+=instanceCount*count;break;case 0:render.points+=instanceCount*count;break;default:console.error('THREE.WebGLInfo: Unknown draw mode:',mode);break;}}function reset(){render.frame++;render.calls=0;render.triangles=0;render.points=0;render.lines=0;}return {memory:memory,render:render,programs:null,autoReset:true,reset:reset,update:update};} |
1136 |
|
1137 | function absNumericalSort(a,b){return Math.abs(b[1])-Math.abs(a[1]);}function WebGLMorphtargets(gl){var influencesList={};var morphInfluences=new Float32Array(8);function update(object,geometry,material,program){var objectInfluences=object.morphTargetInfluences;
|
1138 |
|
1139 | var length=objectInfluences===undefined?0:objectInfluences.length;var influences=influencesList[geometry.id];if(influences===undefined){
|
1140 | influences=[];for(var i=0;i<length;i++){influences[i]=[i,0];}influencesList[geometry.id]=influences;}var morphTargets=material.morphTargets&&geometry.morphAttributes.position;var morphNormals=material.morphNormals&&geometry.morphAttributes.normal;
|
1141 | for(var i=0;i<length;i++){var influence=influences[i];if(influence[1]!==0){if(morphTargets)geometry.deleteAttribute('morphTarget'+i);if(morphNormals)geometry.deleteAttribute('morphNormal'+i);}}
|
1142 | for(var i=0;i<length;i++){var influence=influences[i];influence[0]=i;influence[1]=objectInfluences[i];}influences.sort(absNumericalSort);
|
1143 | var morphInfluencesSum=0;for(var i=0;i<8;i++){var influence=influences[i];if(influence){var index=influence[0];var value=influence[1];if(value){if(morphTargets)geometry.setAttribute('morphTarget'+i,morphTargets[index]);if(morphNormals)geometry.setAttribute('morphNormal'+i,morphNormals[index]);morphInfluences[i]=value;morphInfluencesSum+=value;continue;}}morphInfluences[i]=0;}
|
1144 |
|
1145 |
|
1146 | var morphBaseInfluence=geometry.morphTargetsRelative?1:1-morphInfluencesSum;program.getUniforms().setValue(gl,'morphTargetBaseInfluence',morphBaseInfluence);program.getUniforms().setValue(gl,'morphTargetInfluences',morphInfluences);}return {update:update};} |
1147 |
|
1148 | function WebGLObjects(gl,geometries,attributes,info){var updateMap=new WeakMap();function update(object){var frame=info.render.frame;var geometry=object.geometry;var buffergeometry=geometries.get(object,geometry);
|
1149 | if(updateMap.get(buffergeometry)!==frame){if(geometry.isGeometry){buffergeometry.updateFromObject(object);}geometries.update(buffergeometry);updateMap.set(buffergeometry,frame);}if(object.isInstancedMesh){attributes.update(object.instanceMatrix,34962);}return buffergeometry;}function dispose(){updateMap=new WeakMap();}return {update:update,dispose:dispose};} |
1150 |
|
1151 | function CubeTexture(images,mapping,wrapS,wrapT,magFilter,minFilter,format,type,anisotropy,encoding){images=images!==undefined?images:[];mapping=mapping!==undefined?mapping:CubeReflectionMapping;format=format!==undefined?format:RGBFormat;Texture.call(this,images,mapping,wrapS,wrapT,magFilter,minFilter,format,type,anisotropy,encoding);this.flipY=false;}CubeTexture.prototype=Object.create(Texture.prototype);CubeTexture.prototype.constructor=CubeTexture;CubeTexture.prototype.isCubeTexture=true;Object.defineProperty(CubeTexture.prototype,'images',{get:function get(){return this.image;},set:function set(value){this.image=value;}}); |
1152 |
|
1153 | function DataTexture2DArray(data,width,height,depth){Texture.call(this,null);this.image={data:data||null,width:width||1,height:height||1,depth:depth||1};this.magFilter=NearestFilter;this.minFilter=NearestFilter;this.wrapR=ClampToEdgeWrapping;this.generateMipmaps=false;this.flipY=false;this.needsUpdate=true;}DataTexture2DArray.prototype=Object.create(Texture.prototype);DataTexture2DArray.prototype.constructor=DataTexture2DArray;DataTexture2DArray.prototype.isDataTexture2DArray=true; |
1154 |
|
1155 | function DataTexture3D(data,width,height,depth){
|
1156 |
|
1157 |
|
1158 |
|
1159 |
|
1160 |
|
1161 |
|
1162 | Texture.call(this,null);this.image={data:data||null,width:width||1,height:height||1,depth:depth||1};this.magFilter=NearestFilter;this.minFilter=NearestFilter;this.wrapR=ClampToEdgeWrapping;this.generateMipmaps=false;this.flipY=false;this.needsUpdate=true;}DataTexture3D.prototype=Object.create(Texture.prototype);DataTexture3D.prototype.constructor=DataTexture3D;DataTexture3D.prototype.isDataTexture3D=true; |
1163 |
|
1164 |
|
1165 |
|
1166 |
|
1167 |
|
1168 |
|
1169 |
|
1170 |
|
1171 |
|
1172 |
|
1173 |
|
1174 |
|
1175 |
|
1176 |
|
1177 |
|
1178 |
|
1179 |
|
1180 |
|
1181 |
|
1182 |
|
1183 |
|
1184 |
|
1185 |
|
1186 |
|
1187 |
|
1188 |
|
1189 |
|
1190 |
|
1191 |
|
1192 |
|
1193 |
|
1194 |
|
1195 |
|
1196 |
|
1197 |
|
1198 |
|
1199 |
|
1200 |
|
1201 |
|
1202 |
|
1203 |
|
1204 |
|
1205 |
|
1206 |
|
1207 | var emptyTexture=new Texture();var emptyTexture2dArray=new DataTexture2DArray();var emptyTexture3d=new DataTexture3D();var emptyCubeTexture=new CubeTexture();
|
1208 |
|
1209 | var arrayCacheF32=[];var arrayCacheI32=[];
|
1210 | var mat4array=new Float32Array(16);var mat3array=new Float32Array(9);var mat2array=new Float32Array(4);
|
1211 | function flatten(array,nBlocks,blockSize){var firstElem=array[0];if(firstElem<=0||firstElem>0)return array;
|
1212 |
|
1213 | var n=nBlocks*blockSize,r=arrayCacheF32[n];if(r===undefined){r=new Float32Array(n);arrayCacheF32[n]=r;}if(nBlocks!==0){firstElem.toArray(r,0);for(var i=1,offset=0;i!==nBlocks;++i){offset+=blockSize;array[i].toArray(r,offset);}}return r;}function arraysEqual(a,b){if(a.length!==b.length)return false;for(var i=0,l=a.length;i<l;i++){if(a[i]!==b[i])return false;}return true;}function copyArray(a,b){for(var i=0,l=b.length;i<l;i++){a[i]=b[i];}}
|
1214 | function allocTexUnits(textures,n){var r=arrayCacheI32[n];if(r===undefined){r=new Int32Array(n);arrayCacheI32[n]=r;}for(var i=0;i!==n;++i){r[i]=textures.allocateTextureUnit();}return r;}
|
1215 |
|
1216 |
|
1217 |
|
1218 | function setValueV1f(gl,v){var cache=this.cache;if(cache[0]===v)return;gl.uniform1f(this.addr,v);cache[0]=v;}
|
1219 | function setValueV2f(gl,v){var cache=this.cache;if(v.x!==undefined){if(cache[0]!==v.x||cache[1]!==v.y){gl.uniform2f(this.addr,v.x,v.y);cache[0]=v.x;cache[1]=v.y;}}else {if(arraysEqual(cache,v))return;gl.uniform2fv(this.addr,v);copyArray(cache,v);}}function setValueV3f(gl,v){var cache=this.cache;if(v.x!==undefined){if(cache[0]!==v.x||cache[1]!==v.y||cache[2]!==v.z){gl.uniform3f(this.addr,v.x,v.y,v.z);cache[0]=v.x;cache[1]=v.y;cache[2]=v.z;}}else if(v.r!==undefined){if(cache[0]!==v.r||cache[1]!==v.g||cache[2]!==v.b){gl.uniform3f(this.addr,v.r,v.g,v.b);cache[0]=v.r;cache[1]=v.g;cache[2]=v.b;}}else {if(arraysEqual(cache,v))return;gl.uniform3fv(this.addr,v);copyArray(cache,v);}}function setValueV4f(gl,v){var cache=this.cache;if(v.x!==undefined){if(cache[0]!==v.x||cache[1]!==v.y||cache[2]!==v.z||cache[3]!==v.w){gl.uniform4f(this.addr,v.x,v.y,v.z,v.w);cache[0]=v.x;cache[1]=v.y;cache[2]=v.z;cache[3]=v.w;}}else {if(arraysEqual(cache,v))return;gl.uniform4fv(this.addr,v);copyArray(cache,v);}}
|
1220 | function setValueM2(gl,v){var cache=this.cache;var elements=v.elements;if(elements===undefined){if(arraysEqual(cache,v))return;gl.uniformMatrix2fv(this.addr,false,v);copyArray(cache,v);}else {if(arraysEqual(cache,elements))return;mat2array.set(elements);gl.uniformMatrix2fv(this.addr,false,mat2array);copyArray(cache,elements);}}function setValueM3(gl,v){var cache=this.cache;var elements=v.elements;if(elements===undefined){if(arraysEqual(cache,v))return;gl.uniformMatrix3fv(this.addr,false,v);copyArray(cache,v);}else {if(arraysEqual(cache,elements))return;mat3array.set(elements);gl.uniformMatrix3fv(this.addr,false,mat3array);copyArray(cache,elements);}}function setValueM4(gl,v){var cache=this.cache;var elements=v.elements;if(elements===undefined){if(arraysEqual(cache,v))return;gl.uniformMatrix4fv(this.addr,false,v);copyArray(cache,v);}else {if(arraysEqual(cache,elements))return;mat4array.set(elements);gl.uniformMatrix4fv(this.addr,false,mat4array);copyArray(cache,elements);}}
|
1221 | function setValueT1(gl,v,textures){var cache=this.cache;var unit=textures.allocateTextureUnit();if(cache[0]!==unit){gl.uniform1i(this.addr,unit);cache[0]=unit;}textures.safeSetTexture2D(v||emptyTexture,unit);}function setValueT2DArray1(gl,v,textures){var cache=this.cache;var unit=textures.allocateTextureUnit();if(cache[0]!==unit){gl.uniform1i(this.addr,unit);cache[0]=unit;}textures.setTexture2DArray(v||emptyTexture2dArray,unit);}function setValueT3D1(gl,v,textures){var cache=this.cache;var unit=textures.allocateTextureUnit();if(cache[0]!==unit){gl.uniform1i(this.addr,unit);cache[0]=unit;}textures.setTexture3D(v||emptyTexture3d,unit);}function setValueT6(gl,v,textures){var cache=this.cache;var unit=textures.allocateTextureUnit();if(cache[0]!==unit){gl.uniform1i(this.addr,unit);cache[0]=unit;}textures.safeSetTextureCube(v||emptyCubeTexture,unit);}
|
1222 | function setValueV1i(gl,v){var cache=this.cache;if(cache[0]===v)return;gl.uniform1i(this.addr,v);cache[0]=v;}function setValueV2i(gl,v){var cache=this.cache;if(arraysEqual(cache,v))return;gl.uniform2iv(this.addr,v);copyArray(cache,v);}function setValueV3i(gl,v){var cache=this.cache;if(arraysEqual(cache,v))return;gl.uniform3iv(this.addr,v);copyArray(cache,v);}function setValueV4i(gl,v){var cache=this.cache;if(arraysEqual(cache,v))return;gl.uniform4iv(this.addr,v);copyArray(cache,v);}
|
1223 | function setValueV1ui(gl,v){var cache=this.cache;if(cache[0]===v)return;gl.uniform1ui(this.addr,v);cache[0]=v;}
|
1224 | function getSingularSetter(type){switch(type){case 0x1406:return setValueV1f;
|
1225 | case 0x8b50:return setValueV2f;
|
1226 | case 0x8b51:return setValueV3f;
|
1227 | case 0x8b52:return setValueV4f;
|
1228 | case 0x8b5a:return setValueM2;
|
1229 | case 0x8b5b:return setValueM3;
|
1230 | case 0x8b5c:return setValueM4;
|
1231 | case 0x1404:case 0x8b56:return setValueV1i;
|
1232 | case 0x8b53:case 0x8b57:return setValueV2i;
|
1233 | case 0x8b54:case 0x8b58:return setValueV3i;
|
1234 | case 0x8b55:case 0x8b59:return setValueV4i;
|
1235 | case 0x1405:return setValueV1ui;
|
1236 | case 0x8b5e:
|
1237 | case 0x8d66:
|
1238 | case 0x8dca:
|
1239 | case 0x8dd2:
|
1240 | case 0x8b62:
|
1241 | return setValueT1;case 0x8b5f:
|
1242 | case 0x8dcb:
|
1243 | case 0x8dd3:
|
1244 | return setValueT3D1;case 0x8b60:
|
1245 | case 0x8dcc:
|
1246 | case 0x8dd4:
|
1247 | case 0x8dc5:
|
1248 | return setValueT6;case 0x8dc1:
|
1249 | case 0x8dcf:
|
1250 | case 0x8dd7:
|
1251 | case 0x8dc4:
|
1252 | return setValueT2DArray1;}}
|
1253 | function setValueV1fArray(gl,v){gl.uniform1fv(this.addr,v);}
|
1254 | function setValueV1iArray(gl,v){gl.uniform1iv(this.addr,v);}function setValueV2iArray(gl,v){gl.uniform2iv(this.addr,v);}function setValueV3iArray(gl,v){gl.uniform3iv(this.addr,v);}function setValueV4iArray(gl,v){gl.uniform4iv(this.addr,v);}
|
1255 | function setValueV2fArray(gl,v){var data=flatten(v,this.size,2);gl.uniform2fv(this.addr,data);}function setValueV3fArray(gl,v){var data=flatten(v,this.size,3);gl.uniform3fv(this.addr,data);}function setValueV4fArray(gl,v){var data=flatten(v,this.size,4);gl.uniform4fv(this.addr,data);}
|
1256 | function setValueM2Array(gl,v){var data=flatten(v,this.size,4);gl.uniformMatrix2fv(this.addr,false,data);}function setValueM3Array(gl,v){var data=flatten(v,this.size,9);gl.uniformMatrix3fv(this.addr,false,data);}function setValueM4Array(gl,v){var data=flatten(v,this.size,16);gl.uniformMatrix4fv(this.addr,false,data);}
|
1257 | function setValueT1Array(gl,v,textures){var n=v.length;var units=allocTexUnits(textures,n);gl.uniform1iv(this.addr,units);for(var i=0;i!==n;++i){textures.safeSetTexture2D(v[i]||emptyTexture,units[i]);}}function setValueT6Array(gl,v,textures){var n=v.length;var units=allocTexUnits(textures,n);gl.uniform1iv(this.addr,units);for(var i=0;i!==n;++i){textures.safeSetTextureCube(v[i]||emptyCubeTexture,units[i]);}}
|
1258 | function getPureArraySetter(type){switch(type){case 0x1406:return setValueV1fArray;
|
1259 | case 0x8b50:return setValueV2fArray;
|
1260 | case 0x8b51:return setValueV3fArray;
|
1261 | case 0x8b52:return setValueV4fArray;
|
1262 | case 0x8b5a:return setValueM2Array;
|
1263 | case 0x8b5b:return setValueM3Array;
|
1264 | case 0x8b5c:return setValueM4Array;
|
1265 | case 0x1404:case 0x8b56:return setValueV1iArray;
|
1266 | case 0x8b53:case 0x8b57:return setValueV2iArray;
|
1267 | case 0x8b54:case 0x8b58:return setValueV3iArray;
|
1268 | case 0x8b55:case 0x8b59:return setValueV4iArray;
|
1269 | case 0x8b5e:
|
1270 | case 0x8d66:
|
1271 | case 0x8dca:
|
1272 | case 0x8dd2:
|
1273 | case 0x8b62:
|
1274 | return setValueT1Array;case 0x8b60:
|
1275 | case 0x8dcc:
|
1276 | case 0x8dd4:
|
1277 | case 0x8dc5:
|
1278 | return setValueT6Array;}}
|
1279 | function SingleUniform(id,activeInfo,addr){this.id=id;this.addr=addr;this.cache=[];this.setValue=getSingularSetter(activeInfo.type);
|
1280 | }function PureArrayUniform(id,activeInfo,addr){this.id=id;this.addr=addr;this.cache=[];this.size=activeInfo.size;this.setValue=getPureArraySetter(activeInfo.type);
|
1281 | }PureArrayUniform.prototype.updateCache=function(data){var cache=this.cache;if(data instanceof Float32Array&&cache.length!==data.length){this.cache=new Float32Array(data.length);}copyArray(cache,data);};function StructuredUniform(id){this.id=id;this.seq=[];this.map={};}StructuredUniform.prototype.setValue=function(gl,value,textures){var seq=this.seq;for(var i=0,n=seq.length;i!==n;++i){var u=seq[i];u.setValue(gl,value[u.id],textures);}};
|
1282 |
|
1283 | var RePathPart=/([\w\d_]+)(\])?(\[|\.)?/g;
|
1284 |
|
1285 |
|
1286 |
|
1287 |
|
1288 |
|
1289 |
|
1290 |
|
1291 | function addUniform(container,uniformObject){container.seq.push(uniformObject);container.map[uniformObject.id]=uniformObject;}function parseUniform(activeInfo,addr,container){var path=activeInfo.name,pathLength=path.length;
|
1292 | RePathPart.lastIndex=0;while(true){var match=RePathPart.exec(path),matchEnd=RePathPart.lastIndex,id=match[1],idIsIndex=match[2]===']',subscript=match[3];if(idIsIndex)id=id|0;
|
1293 | if(subscript===undefined||subscript==='['&&matchEnd+2===pathLength){
|
1294 | addUniform(container,subscript===undefined?new SingleUniform(id,activeInfo,addr):new PureArrayUniform(id,activeInfo,addr));break;}else {
|
1295 | var map=container.map,next=map[id];if(next===undefined){next=new StructuredUniform(id);addUniform(container,next);}container=next;}}}
|
1296 | function WebGLUniforms(gl,program){this.seq=[];this.map={};var n=gl.getProgramParameter(program,35718);for(var i=0;i<n;++i){var info=gl.getActiveUniform(program,i),addr=gl.getUniformLocation(program,info.name);parseUniform(info,addr,this);}}WebGLUniforms.prototype.setValue=function(gl,name,value,textures){var u=this.map[name];if(u!==undefined)u.setValue(gl,value,textures);};WebGLUniforms.prototype.setOptional=function(gl,object,name){var v=object[name];if(v!==undefined)this.setValue(gl,name,v);};
|
1297 | WebGLUniforms.upload=function(gl,seq,values,textures){for(var i=0,n=seq.length;i!==n;++i){var u=seq[i],v=values[u.id];if(v.needsUpdate!==false){
|
1298 | u.setValue(gl,v.value,textures);}}};WebGLUniforms.seqWithValue=function(seq,values){var r=[];for(var i=0,n=seq.length;i!==n;++i){var u=seq[i];if(u.id in values)r.push(u);}return r;}; |
1299 |
|
1300 | function WebGLShader(gl,type,string){var shader=gl.createShader(type);gl.shaderSource(shader,string);gl.compileShader(shader);return shader;} |
1301 |
|
1302 | var programIdCount=0;function addLineNumbers(string){var lines=string.split('\n');for(var i=0;i<lines.length;i++){lines[i]=i+1+': '+lines[i];}return lines.join('\n');}function getEncodingComponents(encoding){switch(encoding){case LinearEncoding:return ['Linear','( value )'];case sRGBEncoding:return ['sRGB','( value )'];case RGBEEncoding:return ['RGBE','( value )'];case RGBM7Encoding:return ['RGBM','( value, 7.0 )'];case RGBM16Encoding:return ['RGBM','( value, 16.0 )'];case RGBDEncoding:return ['RGBD','( value, 256.0 )'];case GammaEncoding:return ['Gamma','( value, float( GAMMA_FACTOR ) )'];case LogLuvEncoding:return ['LogLuv','( value )'];default:throw new Error('unsupported encoding: '+encoding);}}function getShaderErrors(gl,shader,type){var status=gl.getShaderParameter(shader,35713);var log=gl.getShaderInfoLog(shader).trim();if(status&&log==='')return '';
|
1303 |
|
1304 | var source=gl.getShaderSource(shader);return 'THREE.WebGLShader: gl.getShaderInfoLog() '+type+'\n'+log+addLineNumbers(source);}function getTexelDecodingFunction(functionName,encoding){var components=getEncodingComponents(encoding);return 'vec4 '+functionName+'( vec4 value ) { return '+components[0]+'ToLinear'+components[1]+'; }';}function getTexelEncodingFunction(functionName,encoding){var components=getEncodingComponents(encoding);return 'vec4 '+functionName+'( vec4 value ) { return LinearTo'+components[0]+components[1]+'; }';}function getToneMappingFunction(functionName,toneMapping){var toneMappingName;switch(toneMapping){case LinearToneMapping:toneMappingName='Linear';break;case ReinhardToneMapping:toneMappingName='Reinhard';break;case Uncharted2ToneMapping:toneMappingName='Uncharted2';break;case CineonToneMapping:toneMappingName='OptimizedCineon';break;case ACESFilmicToneMapping:toneMappingName='ACESFilmic';break;default:throw new Error('unsupported toneMapping: '+toneMapping);}return 'vec3 '+functionName+'( vec3 color ) { return '+toneMappingName+'ToneMapping( color ); }';}function generateExtensions(parameters){var chunks=[parameters.extensionDerivatives||parameters.envMapCubeUV||parameters.bumpMap||parameters.tangentSpaceNormalMap||parameters.clearcoatNormalMap||parameters.flatShading||parameters.shaderID==='physical'?'#extension GL_OES_standard_derivatives : enable':'',(parameters.extensionFragDepth||parameters.logarithmicDepthBuffer)&¶meters.rendererExtensionFragDepth?'#extension GL_EXT_frag_depth : enable':'',parameters.extensionDrawBuffers&¶meters.rendererExtensionDrawBuffers?'#extension GL_EXT_draw_buffers : require':'',(parameters.extensionShaderTextureLOD||parameters.envMap)&¶meters.rendererExtensionShaderTextureLod?'#extension GL_EXT_shader_texture_lod : enable':''];return chunks.filter(filterEmptyLine).join('\n');}function generateDefines(defines){var chunks=[];for(var name in defines){var value=defines[name];if(value===false)continue;chunks.push('#define '+name+' '+value);}return chunks.join('\n');}function fetchAttributeLocations(gl,program){var attributes={};var n=gl.getProgramParameter(program,35721);for(var i=0;i<n;i++){var info=gl.getActiveAttrib(program,i);var name=info.name;
|
1305 | attributes[name]=gl.getAttribLocation(program,name);}return attributes;}function filterEmptyLine(string){return string!=='';}function replaceLightNums(string,parameters){return string.replace(/NUM_DIR_LIGHTS/g,parameters.numDirLights).replace(/NUM_SPOT_LIGHTS/g,parameters.numSpotLights).replace(/NUM_RECT_AREA_LIGHTS/g,parameters.numRectAreaLights).replace(/NUM_POINT_LIGHTS/g,parameters.numPointLights).replace(/NUM_HEMI_LIGHTS/g,parameters.numHemiLights).replace(/NUM_DIR_LIGHT_SHADOWS/g,parameters.numDirLightShadows).replace(/NUM_SPOT_LIGHT_SHADOWS/g,parameters.numSpotLightShadows).replace(/NUM_POINT_LIGHT_SHADOWS/g,parameters.numPointLightShadows);}function replaceClippingPlaneNums(string,parameters){return string.replace(/NUM_CLIPPING_PLANES/g,parameters.numClippingPlanes).replace(/UNION_CLIPPING_PLANES/g,parameters.numClippingPlanes-parameters.numClipIntersection);}
|
1306 | var includePattern=/^[ \t]*#include +<([\w\d./]+)>/gm;function resolveIncludes(string){return string.replace(includePattern,includeReplacer);}function includeReplacer(match,include){var string=ShaderChunk[include];if(string===undefined){throw new Error('Can not resolve #include <'+include+'>');}return resolveIncludes(string);}
|
1307 | var deprecatedUnrollLoopPattern=/#pragma unroll_loop[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;var unrollLoopPattern=/#pragma unroll_loop_start[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}[\s]+?#pragma unroll_loop_end/g;function unrollLoops(string){return string.replace(unrollLoopPattern,loopReplacer).replace(deprecatedUnrollLoopPattern,deprecatedLoopReplacer);}function deprecatedLoopReplacer(match,start,end,snippet){console.warn('WebGLProgram: #pragma unroll_loop shader syntax is deprecated. Please use #pragma unroll_loop_start syntax instead.');return loopReplacer(match,start,end,snippet);}function loopReplacer(match,start,end,snippet){var string='';for(var i=parseInt(start);i<parseInt(end);i++){string+=snippet.replace(/\[ i \]/g,'[ '+i+' ]').replace(/UNROLLED_LOOP_INDEX/g,i);}return string;}
|
1308 | function generatePrecision(parameters){var precisionstring="precision "+parameters.precision+" float;\nprecision "+parameters.precision+" int;";if(parameters.precision==="highp"){precisionstring+="\n#define HIGH_PRECISION";}else if(parameters.precision==="mediump"){precisionstring+="\n#define MEDIUM_PRECISION";}else if(parameters.precision==="lowp"){precisionstring+="\n#define LOW_PRECISION";}return precisionstring;}function generateShadowMapTypeDefine(parameters){var shadowMapTypeDefine='SHADOWMAP_TYPE_BASIC';if(parameters.shadowMapType===PCFShadowMap){shadowMapTypeDefine='SHADOWMAP_TYPE_PCF';}else if(parameters.shadowMapType===PCFSoftShadowMap){shadowMapTypeDefine='SHADOWMAP_TYPE_PCF_SOFT';}else if(parameters.shadowMapType===VSMShadowMap){shadowMapTypeDefine='SHADOWMAP_TYPE_VSM';}return shadowMapTypeDefine;}function generateEnvMapTypeDefine(parameters){var envMapTypeDefine='ENVMAP_TYPE_CUBE';if(parameters.envMap){switch(parameters.envMapMode){case CubeReflectionMapping:case CubeRefractionMapping:envMapTypeDefine='ENVMAP_TYPE_CUBE';break;case CubeUVReflectionMapping:case CubeUVRefractionMapping:envMapTypeDefine='ENVMAP_TYPE_CUBE_UV';break;case EquirectangularReflectionMapping:case EquirectangularRefractionMapping:envMapTypeDefine='ENVMAP_TYPE_EQUIREC';break;case SphericalReflectionMapping:envMapTypeDefine='ENVMAP_TYPE_SPHERE';break;}}return envMapTypeDefine;}function generateEnvMapModeDefine(parameters){var envMapModeDefine='ENVMAP_MODE_REFLECTION';if(parameters.envMap){switch(parameters.envMapMode){case CubeRefractionMapping:case EquirectangularRefractionMapping:envMapModeDefine='ENVMAP_MODE_REFRACTION';break;}}return envMapModeDefine;}function generateEnvMapBlendingDefine(parameters){var envMapBlendingDefine='ENVMAP_BLENDING_NONE';if(parameters.envMap){switch(parameters.combine){case MultiplyOperation:envMapBlendingDefine='ENVMAP_BLENDING_MULTIPLY';break;case MixOperation:envMapBlendingDefine='ENVMAP_BLENDING_MIX';break;case AddOperation:envMapBlendingDefine='ENVMAP_BLENDING_ADD';break;}}return envMapBlendingDefine;}function WebGLProgram(renderer,cacheKey,parameters){var gl=renderer.getContext();var defines=parameters.defines;var vertexShader=parameters.vertexShader;var fragmentShader=parameters.fragmentShader;var shadowMapTypeDefine=generateShadowMapTypeDefine(parameters);var envMapTypeDefine=generateEnvMapTypeDefine(parameters);var envMapModeDefine=generateEnvMapModeDefine(parameters);var envMapBlendingDefine=generateEnvMapBlendingDefine(parameters);var gammaFactorDefine=renderer.gammaFactor>0?renderer.gammaFactor:1.0;var customExtensions=parameters.isWebGL2?'':generateExtensions(parameters);var customDefines=generateDefines(defines);var program=gl.createProgram();var prefixVertex,prefixFragment;if(parameters.isRawShaderMaterial){prefixVertex=[customDefines].filter(filterEmptyLine).join('\n');if(prefixVertex.length>0){prefixVertex+='\n';}prefixFragment=[customExtensions,customDefines].filter(filterEmptyLine).join('\n');if(prefixFragment.length>0){prefixFragment+='\n';}}else {prefixVertex=[generatePrecision(parameters),'#define SHADER_NAME '+parameters.shaderName,customDefines,parameters.instancing?'#define USE_INSTANCING':'',parameters.supportsVertexTextures?'#define VERTEX_TEXTURES':'','#define GAMMA_FACTOR '+gammaFactorDefine,'#define MAX_BONES '+parameters.maxBones,parameters.useFog&¶meters.fog?'#define USE_FOG':'',parameters.useFog&¶meters.fogExp2?'#define FOG_EXP2':'',parameters.map?'#define USE_MAP':'',parameters.envMap?'#define USE_ENVMAP':'',parameters.envMap?'#define '+envMapModeDefine:'',parameters.lightMap?'#define USE_LIGHTMAP':'',parameters.aoMap?'#define USE_AOMAP':'',parameters.emissiveMap?'#define USE_EMISSIVEMAP':'',parameters.bumpMap?'#define USE_BUMPMAP':'',parameters.normalMap?'#define USE_NORMALMAP':'',parameters.normalMap&¶meters.objectSpaceNormalMap?'#define OBJECTSPACE_NORMALMAP':'',parameters.normalMap&¶meters.tangentSpaceNormalMap?'#define TANGENTSPACE_NORMALMAP':'',parameters.clearcoatMap?'#define USE_CLEARCOATMAP':'',parameters.clearcoatRoughnessMap?'#define USE_CLEARCOAT_ROUGHNESSMAP':'',parameters.clearcoatNormalMap?'#define USE_CLEARCOAT_NORMALMAP':'',parameters.displacementMap&¶meters.supportsVertexTextures?'#define USE_DISPLACEMENTMAP':'',parameters.specularMap?'#define USE_SPECULARMAP':'',parameters.roughnessMap?'#define USE_ROUGHNESSMAP':'',parameters.metalnessMap?'#define USE_METALNESSMAP':'',parameters.alphaMap?'#define USE_ALPHAMAP':'',parameters.vertexTangents?'#define USE_TANGENT':'',parameters.vertexColors?'#define USE_COLOR':'',parameters.vertexUvs?'#define USE_UV':'',parameters.uvsVertexOnly?'#define UVS_VERTEX_ONLY':'',parameters.flatShading?'#define FLAT_SHADED':'',parameters.skinning?'#define USE_SKINNING':'',parameters.useVertexTexture?'#define BONE_TEXTURE':'',parameters.morphTargets?'#define USE_MORPHTARGETS':'',parameters.morphNormals&¶meters.flatShading===false?'#define USE_MORPHNORMALS':'',parameters.doubleSided?'#define DOUBLE_SIDED':'',parameters.flipSided?'#define FLIP_SIDED':'',parameters.shadowMapEnabled?'#define USE_SHADOWMAP':'',parameters.shadowMapEnabled?'#define '+shadowMapTypeDefine:'',parameters.sizeAttenuation?'#define USE_SIZEATTENUATION':'',parameters.logarithmicDepthBuffer?'#define USE_LOGDEPTHBUF':'',parameters.logarithmicDepthBuffer&¶meters.rendererExtensionFragDepth?'#define USE_LOGDEPTHBUF_EXT':'','uniform mat4 modelMatrix;','uniform mat4 modelViewMatrix;','uniform mat4 projectionMatrix;','uniform mat4 viewMatrix;','uniform mat3 normalMatrix;','uniform vec3 cameraPosition;','uniform bool isOrthographic;','#ifdef USE_INSTANCING',' attribute mat4 instanceMatrix;','#endif','attribute vec3 position;','attribute vec3 normal;','attribute vec2 uv;','#ifdef USE_TANGENT',' attribute vec4 tangent;','#endif','#ifdef USE_COLOR',' attribute vec3 color;','#endif','#ifdef USE_MORPHTARGETS',' attribute vec3 morphTarget0;',' attribute vec3 morphTarget1;',' attribute vec3 morphTarget2;',' attribute vec3 morphTarget3;',' #ifdef USE_MORPHNORMALS',' attribute vec3 morphNormal0;',' attribute vec3 morphNormal1;',' attribute vec3 morphNormal2;',' attribute vec3 morphNormal3;',' #else',' attribute vec3 morphTarget4;',' attribute vec3 morphTarget5;',' attribute vec3 morphTarget6;',' attribute vec3 morphTarget7;',' #endif','#endif','#ifdef USE_SKINNING',' attribute vec4 skinIndex;',' attribute vec4 skinWeight;','#endif','\n'].filter(filterEmptyLine).join('\n');prefixFragment=[customExtensions,generatePrecision(parameters),'#define SHADER_NAME '+parameters.shaderName,customDefines,parameters.alphaTest?'#define ALPHATEST '+parameters.alphaTest+(parameters.alphaTest%1?'':'.0'):'',
|
1309 | '#define GAMMA_FACTOR '+gammaFactorDefine,parameters.useFog&¶meters.fog?'#define USE_FOG':'',parameters.useFog&¶meters.fogExp2?'#define FOG_EXP2':'',parameters.map?'#define USE_MAP':'',parameters.matcap?'#define USE_MATCAP':'',parameters.envMap?'#define USE_ENVMAP':'',parameters.envMap?'#define '+envMapTypeDefine:'',parameters.envMap?'#define '+envMapModeDefine:'',parameters.envMap?'#define '+envMapBlendingDefine:'',parameters.lightMap?'#define USE_LIGHTMAP':'',parameters.aoMap?'#define USE_AOMAP':'',parameters.emissiveMap?'#define USE_EMISSIVEMAP':'',parameters.bumpMap?'#define USE_BUMPMAP':'',parameters.normalMap?'#define USE_NORMALMAP':'',parameters.normalMap&¶meters.objectSpaceNormalMap?'#define OBJECTSPACE_NORMALMAP':'',parameters.normalMap&¶meters.tangentSpaceNormalMap?'#define TANGENTSPACE_NORMALMAP':'',parameters.clearcoatMap?'#define USE_CLEARCOATMAP':'',parameters.clearcoatRoughnessMap?'#define USE_CLEARCOAT_ROUGHNESSMAP':'',parameters.clearcoatNormalMap?'#define USE_CLEARCOAT_NORMALMAP':'',parameters.specularMap?'#define USE_SPECULARMAP':'',parameters.roughnessMap?'#define USE_ROUGHNESSMAP':'',parameters.metalnessMap?'#define USE_METALNESSMAP':'',parameters.alphaMap?'#define USE_ALPHAMAP':'',parameters.sheen?'#define USE_SHEEN':'',parameters.vertexTangents?'#define USE_TANGENT':'',parameters.vertexColors?'#define USE_COLOR':'',parameters.vertexUvs?'#define USE_UV':'',parameters.uvsVertexOnly?'#define UVS_VERTEX_ONLY':'',parameters.gradientMap?'#define USE_GRADIENTMAP':'',parameters.flatShading?'#define FLAT_SHADED':'',parameters.doubleSided?'#define DOUBLE_SIDED':'',parameters.flipSided?'#define FLIP_SIDED':'',parameters.shadowMapEnabled?'#define USE_SHADOWMAP':'',parameters.shadowMapEnabled?'#define '+shadowMapTypeDefine:'',parameters.premultipliedAlpha?'#define PREMULTIPLIED_ALPHA':'',parameters.physicallyCorrectLights?'#define PHYSICALLY_CORRECT_LIGHTS':'',parameters.logarithmicDepthBuffer?'#define USE_LOGDEPTHBUF':'',parameters.logarithmicDepthBuffer&¶meters.rendererExtensionFragDepth?'#define USE_LOGDEPTHBUF_EXT':'',(parameters.extensionShaderTextureLOD||parameters.envMap)&¶meters.rendererExtensionShaderTextureLod?'#define TEXTURE_LOD_EXT':'','uniform mat4 viewMatrix;','uniform vec3 cameraPosition;','uniform bool isOrthographic;',parameters.toneMapping!==NoToneMapping?'#define TONE_MAPPING':'',parameters.toneMapping!==NoToneMapping?ShaderChunk['tonemapping_pars_fragment']:'',
|
1310 | parameters.toneMapping!==NoToneMapping?getToneMappingFunction('toneMapping',parameters.toneMapping):'',parameters.dithering?'#define DITHERING':'',parameters.outputEncoding||parameters.mapEncoding||parameters.matcapEncoding||parameters.envMapEncoding||parameters.emissiveMapEncoding||parameters.lightMapEncoding?ShaderChunk['encodings_pars_fragment']:'',
|
1311 | parameters.mapEncoding?getTexelDecodingFunction('mapTexelToLinear',parameters.mapEncoding):'',parameters.matcapEncoding?getTexelDecodingFunction('matcapTexelToLinear',parameters.matcapEncoding):'',parameters.envMapEncoding?getTexelDecodingFunction('envMapTexelToLinear',parameters.envMapEncoding):'',parameters.emissiveMapEncoding?getTexelDecodingFunction('emissiveMapTexelToLinear',parameters.emissiveMapEncoding):'',parameters.lightMapEncoding?getTexelDecodingFunction('lightMapTexelToLinear',parameters.lightMapEncoding):'',parameters.outputEncoding?getTexelEncodingFunction('linearToOutputTexel',parameters.outputEncoding):'',parameters.depthPacking?'#define DEPTH_PACKING '+parameters.depthPacking:'','\n'].filter(filterEmptyLine).join('\n');}vertexShader=resolveIncludes(vertexShader);vertexShader=replaceLightNums(vertexShader,parameters);vertexShader=replaceClippingPlaneNums(vertexShader,parameters);fragmentShader=resolveIncludes(fragmentShader);fragmentShader=replaceLightNums(fragmentShader,parameters);fragmentShader=replaceClippingPlaneNums(fragmentShader,parameters);vertexShader=unrollLoops(vertexShader);fragmentShader=unrollLoops(fragmentShader);if(parameters.isWebGL2&&!parameters.isRawShaderMaterial){var isGLSL3ShaderMaterial=false;var versionRegex=/^\s*#version\s+300\s+es\s*\n/;if(parameters.isShaderMaterial&&vertexShader.match(versionRegex)!==null&&fragmentShader.match(versionRegex)!==null){isGLSL3ShaderMaterial=true;vertexShader=vertexShader.replace(versionRegex,'');fragmentShader=fragmentShader.replace(versionRegex,'');}
|
1312 | prefixVertex=['#version 300 es\n','#define attribute in','#define varying out','#define texture2D texture'].join('\n')+'\n'+prefixVertex;prefixFragment=['#version 300 es\n','#define varying in',isGLSL3ShaderMaterial?'':'out highp vec4 pc_fragColor;',isGLSL3ShaderMaterial?'':'#define gl_FragColor pc_fragColor','#define gl_FragDepthEXT gl_FragDepth','#define texture2D texture','#define textureCube texture','#define texture2DProj textureProj','#define texture2DLodEXT textureLod','#define texture2DProjLodEXT textureProjLod','#define textureCubeLodEXT textureLod','#define texture2DGradEXT textureGrad','#define texture2DProjGradEXT textureProjGrad','#define textureCubeGradEXT textureGrad'].join('\n')+'\n'+prefixFragment;}var vertexGlsl=prefixVertex+vertexShader;var fragmentGlsl=prefixFragment+fragmentShader;
|
1313 |
|
1314 | var glVertexShader=WebGLShader(gl,35633,vertexGlsl);var glFragmentShader=WebGLShader(gl,35632,fragmentGlsl);gl.attachShader(program,glVertexShader);gl.attachShader(program,glFragmentShader);
|
1315 | if(parameters.index0AttributeName!==undefined){gl.bindAttribLocation(program,0,parameters.index0AttributeName);}else if(parameters.morphTargets===true){
|
1316 | gl.bindAttribLocation(program,0,'position');}gl.linkProgram(program);
|
1317 | if(renderer.debug.checkShaderErrors){var programLog=gl.getProgramInfoLog(program).trim();var vertexLog=gl.getShaderInfoLog(glVertexShader).trim();var fragmentLog=gl.getShaderInfoLog(glFragmentShader).trim();var runnable=true;var haveDiagnostics=true;if(gl.getProgramParameter(program,35714)===false){runnable=false;var vertexErrors=getShaderErrors(gl,glVertexShader,'vertex');var fragmentErrors=getShaderErrors(gl,glFragmentShader,'fragment');console.error('THREE.WebGLProgram: shader error: ',gl.getError(),'35715',gl.getProgramParameter(program,35715),'gl.getProgramInfoLog',programLog,vertexErrors,fragmentErrors);}else if(programLog!==''){console.warn('THREE.WebGLProgram: gl.getProgramInfoLog()',programLog);}else if(vertexLog===''||fragmentLog===''){haveDiagnostics=false;}if(haveDiagnostics){this.diagnostics={runnable:runnable,programLog:programLog,vertexShader:{log:vertexLog,prefix:prefixVertex},fragmentShader:{log:fragmentLog,prefix:prefixFragment}};}}
|
1318 |
|
1319 |
|
1320 |
|
1321 | gl.deleteShader(glVertexShader);gl.deleteShader(glFragmentShader);
|
1322 | var cachedUniforms;this.getUniforms=function(){if(cachedUniforms===undefined){cachedUniforms=new WebGLUniforms(gl,program);}return cachedUniforms;};
|
1323 | var cachedAttributes;this.getAttributes=function(){if(cachedAttributes===undefined){cachedAttributes=fetchAttributeLocations(gl,program);}return cachedAttributes;};
|
1324 | this.destroy=function(){gl.deleteProgram(program);this.program=undefined;};
|
1325 | this.name=parameters.shaderName;this.id=programIdCount++;this.cacheKey=cacheKey;this.usedTimes=1;this.program=program;this.vertexShader=glVertexShader;this.fragmentShader=glFragmentShader;return this;} |
1326 |
|
1327 | function WebGLPrograms(renderer,extensions,capabilities){var programs=[];var isWebGL2=capabilities.isWebGL2;var logarithmicDepthBuffer=capabilities.logarithmicDepthBuffer;var floatVertexTextures=capabilities.floatVertexTextures;var precision=capabilities.precision;var maxVertexUniforms=capabilities.maxVertexUniforms;var vertexTextures=capabilities.vertexTextures;var shaderIDs={MeshDepthMaterial:'depth',MeshDistanceMaterial:'distanceRGBA',MeshNormalMaterial:'normal',MeshBasicMaterial:'basic',MeshLambertMaterial:'lambert',MeshPhongMaterial:'phong',MeshToonMaterial:'toon',MeshStandardMaterial:'physical',MeshPhysicalMaterial:'physical',MeshMatcapMaterial:'matcap',LineBasicMaterial:'basic',LineDashedMaterial:'dashed',PointsMaterial:'points',ShadowMaterial:'shadow',SpriteMaterial:'sprite'};var parameterNames=["precision","isWebGL2","supportsVertexTextures","outputEncoding","instancing","map","mapEncoding","matcap","matcapEncoding","envMap","envMapMode","envMapEncoding","envMapCubeUV","lightMap","lightMapEncoding","aoMap","emissiveMap","emissiveMapEncoding","bumpMap","normalMap","objectSpaceNormalMap","tangentSpaceNormalMap","clearcoatMap","clearcoatRoughnessMap","clearcoatNormalMap","displacementMap","specularMap","roughnessMap","metalnessMap","gradientMap","alphaMap","combine","vertexColors","vertexTangents","vertexUvs","uvsVertexOnly","fog","useFog","fogExp2","flatShading","sizeAttenuation","logarithmicDepthBuffer","skinning","maxBones","useVertexTexture","morphTargets","morphNormals","maxMorphTargets","maxMorphNormals","premultipliedAlpha","numDirLights","numPointLights","numSpotLights","numHemiLights","numRectAreaLights","numDirLightShadows","numPointLightShadows","numSpotLightShadows","shadowMapEnabled","shadowMapType","toneMapping",'physicallyCorrectLights',"alphaTest","doubleSided","flipSided","numClippingPlanes","numClipIntersection","depthPacking","dithering","sheen"];function getShaderObject(material,shaderID){var shaderobject;if(shaderID){var shader=ShaderLib[shaderID];shaderobject={name:material.type,uniforms:UniformsUtils.clone(shader.uniforms),vertexShader:shader.vertexShader,fragmentShader:shader.fragmentShader};}else {shaderobject={name:material.type,uniforms:material.uniforms,vertexShader:material.vertexShader,fragmentShader:material.fragmentShader};}return shaderobject;}function allocateBones(object){var skeleton=object.skeleton;var bones=skeleton.bones;if(floatVertexTextures){return 1024;}else {
|
1328 |
|
1329 |
|
1330 |
|
1331 |
|
1332 |
|
1333 | var nVertexUniforms=maxVertexUniforms;var nVertexMatrices=Math.floor((nVertexUniforms-20)/4);var maxBones=Math.min(nVertexMatrices,bones.length);if(maxBones<bones.length){console.warn('THREE.WebGLRenderer: Skeleton has '+bones.length+' bones. This GPU supports '+maxBones+'.');return 0;}return maxBones;}}function getTextureEncodingFromMap(map){var encoding;if(!map){encoding=LinearEncoding;}else if(map.isTexture){encoding=map.encoding;}else if(map.isWebGLRenderTarget){console.warn("THREE.WebGLPrograms.getTextureEncodingFromMap: don't use render targets as textures. Use their .texture property instead.");encoding=map.texture.encoding;}return encoding;}this.getParameters=function(material,lights,shadows,scene,nClipPlanes,nClipIntersection,object){var fog=scene.fog;var environment=material.isMeshStandardMaterial?scene.environment:null;var envMap=material.envMap||environment;var shaderID=shaderIDs[material.type];
|
1334 |
|
1335 | var maxBones=object.isSkinnedMesh?allocateBones(object):0;if(material.precision!==null){precision=capabilities.getMaxPrecision(material.precision);if(precision!==material.precision){console.warn('THREE.WebGLProgram.getParameters:',material.precision,'not supported, using',precision,'instead.');}}var shaderobject=getShaderObject(material,shaderID);material.onBeforeCompile(shaderobject,renderer);var currentRenderTarget=renderer.getRenderTarget();var parameters={isWebGL2:isWebGL2,shaderID:shaderID,shaderName:shaderobject.name,uniforms:shaderobject.uniforms,vertexShader:shaderobject.vertexShader,fragmentShader:shaderobject.fragmentShader,defines:material.defines,isRawShaderMaterial:material.isRawShaderMaterial,isShaderMaterial:material.isShaderMaterial,precision:precision,instancing:object.isInstancedMesh===true,supportsVertexTextures:vertexTextures,outputEncoding:currentRenderTarget!==null?getTextureEncodingFromMap(currentRenderTarget.texture):renderer.outputEncoding,map:!!material.map,mapEncoding:getTextureEncodingFromMap(material.map),matcap:!!material.matcap,matcapEncoding:getTextureEncodingFromMap(material.matcap),envMap:!!envMap,envMapMode:envMap&&envMap.mapping,envMapEncoding:getTextureEncodingFromMap(envMap),envMapCubeUV:!!envMap&&(envMap.mapping===CubeUVReflectionMapping||envMap.mapping===CubeUVRefractionMapping),lightMap:!!material.lightMap,lightMapEncoding:getTextureEncodingFromMap(material.lightMap),aoMap:!!material.aoMap,emissiveMap:!!material.emissiveMap,emissiveMapEncoding:getTextureEncodingFromMap(material.emissiveMap),bumpMap:!!material.bumpMap,normalMap:!!material.normalMap,objectSpaceNormalMap:material.normalMapType===ObjectSpaceNormalMap,tangentSpaceNormalMap:material.normalMapType===TangentSpaceNormalMap,clearcoatMap:!!material.clearcoatMap,clearcoatRoughnessMap:!!material.clearcoatRoughnessMap,clearcoatNormalMap:!!material.clearcoatNormalMap,displacementMap:!!material.displacementMap,roughnessMap:!!material.roughnessMap,metalnessMap:!!material.metalnessMap,specularMap:!!material.specularMap,alphaMap:!!material.alphaMap,gradientMap:!!material.gradientMap,sheen:!!material.sheen,combine:material.combine,vertexTangents:material.normalMap&&material.vertexTangents,vertexColors:material.vertexColors,vertexUvs:!!material.map||!!material.bumpMap||!!material.normalMap||!!material.specularMap||!!material.alphaMap||!!material.emissiveMap||!!material.roughnessMap||!!material.metalnessMap||!!material.clearcoatMap||!!material.clearcoatRoughnessMap||!!material.clearcoatNormalMap||!!material.displacementMap,uvsVertexOnly:!(!!material.map||!!material.bumpMap||!!material.normalMap||!!material.specularMap||!!material.alphaMap||!!material.emissiveMap||!!material.roughnessMap||!!material.metalnessMap||!!material.clearcoatNormalMap)&&!!material.displacementMap,fog:!!fog,useFog:material.fog,fogExp2:fog&&fog.isFogExp2,flatShading:material.flatShading,sizeAttenuation:material.sizeAttenuation,logarithmicDepthBuffer:logarithmicDepthBuffer,skinning:material.skinning&&maxBones>0,maxBones:maxBones,useVertexTexture:floatVertexTextures,morphTargets:material.morphTargets,morphNormals:material.morphNormals,maxMorphTargets:renderer.maxMorphTargets,maxMorphNormals:renderer.maxMorphNormals,numDirLights:lights.directional.length,numPointLights:lights.point.length,numSpotLights:lights.spot.length,numRectAreaLights:lights.rectArea.length,numHemiLights:lights.hemi.length,numDirLightShadows:lights.directionalShadowMap.length,numPointLightShadows:lights.pointShadowMap.length,numSpotLightShadows:lights.spotShadowMap.length,numClippingPlanes:nClipPlanes,numClipIntersection:nClipIntersection,dithering:material.dithering,shadowMapEnabled:renderer.shadowMap.enabled&&shadows.length>0,shadowMapType:renderer.shadowMap.type,toneMapping:material.toneMapped?renderer.toneMapping:NoToneMapping,physicallyCorrectLights:renderer.physicallyCorrectLights,premultipliedAlpha:material.premultipliedAlpha,alphaTest:material.alphaTest,doubleSided:material.side===DoubleSide,flipSided:material.side===BackSide,depthPacking:material.depthPacking!==undefined?material.depthPacking:false,index0AttributeName:material.index0AttributeName,extensionDerivatives:material.extensions&&material.extensions.derivatives,extensionFragDepth:material.extensions&&material.extensions.fragDepth,extensionDrawBuffers:material.extensions&&material.extensions.drawBuffers,extensionShaderTextureLOD:material.extensions&&material.extensions.shaderTextureLOD,rendererExtensionFragDepth:isWebGL2||extensions.get('EXT_frag_depth')!==null,rendererExtensionDrawBuffers:isWebGL2||extensions.get('WEBGL_draw_buffers')!==null,rendererExtensionShaderTextureLod:isWebGL2||extensions.get('EXT_shader_texture_lod')!==null,onBeforeCompile:material.onBeforeCompile};return parameters;};this.getProgramCacheKey=function(parameters){var array=[];if(parameters.shaderID){array.push(parameters.shaderID);}else {array.push(parameters.fragmentShader);array.push(parameters.vertexShader);}if(parameters.defines!==undefined){for(var name in parameters.defines){array.push(name);array.push(parameters.defines[name]);}}if(parameters.isRawShaderMaterial===undefined){for(var i=0;i<parameterNames.length;i++){array.push(parameters[parameterNames[i]]);}array.push(renderer.outputEncoding);array.push(renderer.gammaFactor);}array.push(parameters.onBeforeCompile.toString());return array.join();};this.acquireProgram=function(parameters,cacheKey){var program;
|
1336 | for(var p=0,pl=programs.length;p<pl;p++){var preexistingProgram=programs[p];if(preexistingProgram.cacheKey===cacheKey){program=preexistingProgram;++program.usedTimes;break;}}if(program===undefined){program=new WebGLProgram(renderer,cacheKey,parameters);programs.push(program);}return program;};this.releaseProgram=function(program){if(--program.usedTimes===0){
|
1337 | var i=programs.indexOf(program);programs[i]=programs[programs.length-1];programs.pop();
|
1338 | program.destroy();}};
|
1339 | this.programs=programs;} |
1340 |
|
1341 | function WebGLProperties(){var properties=new WeakMap();function get(object){var map=properties.get(object);if(map===undefined){map={};properties.set(object,map);}return map;}function remove(object){properties["delete"](object);}function update(object,key,value){properties.get(object)[key]=value;}function dispose(){properties=new WeakMap();}return {get:get,remove:remove,update:update,dispose:dispose};}/**
|
1342 | * @author mrdoob / http://mrdoob.com/
|
1343 | */function painterSortStable(a,b){if(a.groupOrder!==b.groupOrder){return a.groupOrder-b.groupOrder;}else if(a.renderOrder!==b.renderOrder){return a.renderOrder-b.renderOrder;}else if(a.program!==b.program){return a.program.id-b.program.id;}else if(a.material.id!==b.material.id){return a.material.id-b.material.id;}else if(a.z!==b.z){return a.z-b.z;}else {return a.id-b.id;}}function reversePainterSortStable(a,b){if(a.groupOrder!==b.groupOrder){return a.groupOrder-b.groupOrder;}else if(a.renderOrder!==b.renderOrder){return a.renderOrder-b.renderOrder;}else if(a.z!==b.z){return b.z-a.z;}else {return a.id-b.id;}}function WebGLRenderList(){var renderItems=[];var renderItemsIndex=0;var opaque=[];var transparent=[];var defaultProgram={id:-1};function init(){renderItemsIndex=0;opaque.length=0;transparent.length=0;}function getNextRenderItem(object,geometry,material,groupOrder,z,group){var renderItem=renderItems[renderItemsIndex];if(renderItem===undefined){renderItem={id:object.id,object:object,geometry:geometry,material:material,program:material.program||defaultProgram,groupOrder:groupOrder,renderOrder:object.renderOrder,z:z,group:group};renderItems[renderItemsIndex]=renderItem;}else {renderItem.id=object.id;renderItem.object=object;renderItem.geometry=geometry;renderItem.material=material;renderItem.program=material.program||defaultProgram;renderItem.groupOrder=groupOrder;renderItem.renderOrder=object.renderOrder;renderItem.z=z;renderItem.group=group;}renderItemsIndex++;return renderItem;}function push(object,geometry,material,groupOrder,z,group){var renderItem=getNextRenderItem(object,geometry,material,groupOrder,z,group);(material.transparent===true?transparent:opaque).push(renderItem);}function unshift(object,geometry,material,groupOrder,z,group){var renderItem=getNextRenderItem(object,geometry,material,groupOrder,z,group);(material.transparent===true?transparent:opaque).unshift(renderItem);}function sort(customOpaqueSort,customTransparentSort){if(opaque.length>1)opaque.sort(customOpaqueSort||painterSortStable);if(transparent.length>1)transparent.sort(customTransparentSort||reversePainterSortStable);}function finish(){
|
1344 | for(var i=renderItemsIndex,il=renderItems.length;i<il;i++){var renderItem=renderItems[i];if(renderItem.id===null)break;renderItem.id=null;renderItem.object=null;renderItem.geometry=null;renderItem.material=null;renderItem.program=null;renderItem.group=null;}}return {opaque:opaque,transparent:transparent,init:init,push:push,unshift:unshift,finish:finish,sort:sort};}function WebGLRenderLists(){var lists=new WeakMap();function onSceneDispose(event){var scene=event.target;scene.removeEventListener('dispose',onSceneDispose);lists["delete"](scene);}function get(scene,camera){var cameras=lists.get(scene);var list;if(cameras===undefined){list=new WebGLRenderList();lists.set(scene,new WeakMap());lists.get(scene).set(camera,list);scene.addEventListener('dispose',onSceneDispose);}else {list=cameras.get(camera);if(list===undefined){list=new WebGLRenderList();cameras.set(camera,list);}}return list;}function dispose(){lists=new WeakMap();}return {get:get,dispose:dispose};}/**
|
1345 | * @author mrdoob / http://mrdoob.com/
|
1346 | */function UniformsCache(){var lights={};return {get:function get(light){if(lights[light.id]!==undefined){return lights[light.id];}var uniforms;switch(light.type){case'DirectionalLight':uniforms={direction:new Vector3(),color:new Color()};break;case'SpotLight':uniforms={position:new Vector3(),direction:new Vector3(),color:new Color(),distance:0,coneCos:0,penumbraCos:0,decay:0};break;case'PointLight':uniforms={position:new Vector3(),color:new Color(),distance:0,decay:0};break;case'HemisphereLight':uniforms={direction:new Vector3(),skyColor:new Color(),groundColor:new Color()};break;case'RectAreaLight':uniforms={color:new Color(),position:new Vector3(),halfWidth:new Vector3(),halfHeight:new Vector3()};break;}lights[light.id]=uniforms;return uniforms;}};}function ShadowUniformsCache(){var lights={};return {get:function get(light){if(lights[light.id]!==undefined){return lights[light.id];}var uniforms;switch(light.type){case'DirectionalLight':uniforms={shadowBias:0,shadowRadius:1,shadowMapSize:new Vector2()};break;case'SpotLight':uniforms={shadowBias:0,shadowRadius:1,shadowMapSize:new Vector2()};break;case'PointLight':uniforms={shadowBias:0,shadowRadius:1,shadowMapSize:new Vector2(),shadowCameraNear:1,shadowCameraFar:1000};break;
|
1347 | }lights[light.id]=uniforms;return uniforms;}};}var nextVersion=0;function shadowCastingLightsFirst(lightA,lightB){return (lightB.castShadow?1:0)-(lightA.castShadow?1:0);}function WebGLLights(){var cache=new UniformsCache();var shadowCache=ShadowUniformsCache();var state={version:0,hash:{directionalLength:-1,pointLength:-1,spotLength:-1,rectAreaLength:-1,hemiLength:-1,numDirectionalShadows:-1,numPointShadows:-1,numSpotShadows:-1},ambient:[0,0,0],probe:[],directional:[],directionalShadow:[],directionalShadowMap:[],directionalShadowMatrix:[],spot:[],spotShadow:[],spotShadowMap:[],spotShadowMatrix:[],rectArea:[],point:[],pointShadow:[],pointShadowMap:[],pointShadowMatrix:[],hemi:[]};for(var i=0;i<9;i++){state.probe.push(new Vector3());}var vector3=new Vector3();var matrix4=new Matrix4();var matrix42=new Matrix4();function setup(lights,shadows,camera){var r=0,g=0,b=0;for(var i=0;i<9;i++){state.probe[i].set(0,0,0);}var directionalLength=0;var pointLength=0;var spotLength=0;var rectAreaLength=0;var hemiLength=0;var numDirectionalShadows=0;var numPointShadows=0;var numSpotShadows=0;var viewMatrix=camera.matrixWorldInverse;lights.sort(shadowCastingLightsFirst);for(var i=0,l=lights.length;i<l;i++){var light=lights[i];var color=light.color;var intensity=light.intensity;var distance=light.distance;var shadowMap=light.shadow&&light.shadow.map?light.shadow.map.texture:null;if(light.isAmbientLight){r+=color.r*intensity;g+=color.g*intensity;b+=color.b*intensity;}else if(light.isLightProbe){for(var j=0;j<9;j++){state.probe[j].addScaledVector(light.sh.coefficients[j],intensity);}}else if(light.isDirectionalLight){var uniforms=cache.get(light);uniforms.color.copy(light.color).multiplyScalar(light.intensity);uniforms.direction.setFromMatrixPosition(light.matrixWorld);vector3.setFromMatrixPosition(light.target.matrixWorld);uniforms.direction.sub(vector3);uniforms.direction.transformDirection(viewMatrix);if(light.castShadow){var shadow=light.shadow;var shadowUniforms=shadowCache.get(light);shadowUniforms.shadowBias=shadow.bias;shadowUniforms.shadowRadius=shadow.radius;shadowUniforms.shadowMapSize=shadow.mapSize;state.directionalShadow[directionalLength]=shadowUniforms;state.directionalShadowMap[directionalLength]=shadowMap;state.directionalShadowMatrix[directionalLength]=light.shadow.matrix;numDirectionalShadows++;}state.directional[directionalLength]=uniforms;directionalLength++;}else if(light.isSpotLight){var uniforms=cache.get(light);uniforms.position.setFromMatrixPosition(light.matrixWorld);uniforms.position.applyMatrix4(viewMatrix);uniforms.color.copy(color).multiplyScalar(intensity);uniforms.distance=distance;uniforms.direction.setFromMatrixPosition(light.matrixWorld);vector3.setFromMatrixPosition(light.target.matrixWorld);uniforms.direction.sub(vector3);uniforms.direction.transformDirection(viewMatrix);uniforms.coneCos=Math.cos(light.angle);uniforms.penumbraCos=Math.cos(light.angle*(1-light.penumbra));uniforms.decay=light.decay;if(light.castShadow){var shadow=light.shadow;var shadowUniforms=shadowCache.get(light);shadowUniforms.shadowBias=shadow.bias;shadowUniforms.shadowRadius=shadow.radius;shadowUniforms.shadowMapSize=shadow.mapSize;state.spotShadow[spotLength]=shadowUniforms;state.spotShadowMap[spotLength]=shadowMap;state.spotShadowMatrix[spotLength]=light.shadow.matrix;numSpotShadows++;}state.spot[spotLength]=uniforms;spotLength++;}else if(light.isRectAreaLight){var uniforms=cache.get(light);
|
1348 |
|
1349 |
|
1350 | uniforms.color.copy(color).multiplyScalar(intensity);uniforms.position.setFromMatrixPosition(light.matrixWorld);uniforms.position.applyMatrix4(viewMatrix);
|
1351 | matrix42.identity();matrix4.copy(light.matrixWorld);matrix4.premultiply(viewMatrix);matrix42.extractRotation(matrix4);uniforms.halfWidth.set(light.width*0.5,0.0,0.0);uniforms.halfHeight.set(0.0,light.height*0.5,0.0);uniforms.halfWidth.applyMatrix4(matrix42);uniforms.halfHeight.applyMatrix4(matrix42);
|
1352 |
|
1353 | state.rectArea[rectAreaLength]=uniforms;rectAreaLength++;}else if(light.isPointLight){var uniforms=cache.get(light);uniforms.position.setFromMatrixPosition(light.matrixWorld);uniforms.position.applyMatrix4(viewMatrix);uniforms.color.copy(light.color).multiplyScalar(light.intensity);uniforms.distance=light.distance;uniforms.decay=light.decay;if(light.castShadow){var shadow=light.shadow;var shadowUniforms=shadowCache.get(light);shadowUniforms.shadowBias=shadow.bias;shadowUniforms.shadowRadius=shadow.radius;shadowUniforms.shadowMapSize=shadow.mapSize;shadowUniforms.shadowCameraNear=shadow.camera.near;shadowUniforms.shadowCameraFar=shadow.camera.far;state.pointShadow[pointLength]=shadowUniforms;state.pointShadowMap[pointLength]=shadowMap;state.pointShadowMatrix[pointLength]=light.shadow.matrix;numPointShadows++;}state.point[pointLength]=uniforms;pointLength++;}else if(light.isHemisphereLight){var uniforms=cache.get(light);uniforms.direction.setFromMatrixPosition(light.matrixWorld);uniforms.direction.transformDirection(viewMatrix);uniforms.direction.normalize();uniforms.skyColor.copy(light.color).multiplyScalar(intensity);uniforms.groundColor.copy(light.groundColor).multiplyScalar(intensity);state.hemi[hemiLength]=uniforms;hemiLength++;}}state.ambient[0]=r;state.ambient[1]=g;state.ambient[2]=b;var hash=state.hash;if(hash.directionalLength!==directionalLength||hash.pointLength!==pointLength||hash.spotLength!==spotLength||hash.rectAreaLength!==rectAreaLength||hash.hemiLength!==hemiLength||hash.numDirectionalShadows!==numDirectionalShadows||hash.numPointShadows!==numPointShadows||hash.numSpotShadows!==numSpotShadows){state.directional.length=directionalLength;state.spot.length=spotLength;state.rectArea.length=rectAreaLength;state.point.length=pointLength;state.hemi.length=hemiLength;state.directionalShadow.length=numDirectionalShadows;state.directionalShadowMap.length=numDirectionalShadows;state.pointShadow.length=numPointShadows;state.pointShadowMap.length=numPointShadows;state.spotShadow.length=numSpotShadows;state.spotShadowMap.length=numSpotShadows;state.directionalShadowMatrix.length=numDirectionalShadows;state.pointShadowMatrix.length=numPointShadows;state.spotShadowMatrix.length=numSpotShadows;hash.directionalLength=directionalLength;hash.pointLength=pointLength;hash.spotLength=spotLength;hash.rectAreaLength=rectAreaLength;hash.hemiLength=hemiLength;hash.numDirectionalShadows=numDirectionalShadows;hash.numPointShadows=numPointShadows;hash.numSpotShadows=numSpotShadows;state.version=nextVersion++;}}return {setup:setup,state:state};} |
1354 |
|
1355 | function WebGLRenderState(){var lights=new WebGLLights();var lightsArray=[];var shadowsArray=[];function init(){lightsArray.length=0;shadowsArray.length=0;}function pushLight(light){lightsArray.push(light);}function pushShadow(shadowLight){shadowsArray.push(shadowLight);}function setupLights(camera){lights.setup(lightsArray,shadowsArray,camera);}var state={lightsArray:lightsArray,shadowsArray:shadowsArray,lights:lights};return {init:init,state:state,setupLights:setupLights,pushLight:pushLight,pushShadow:pushShadow};}function WebGLRenderStates(){var renderStates=new WeakMap();function onSceneDispose(event){var scene=event.target;scene.removeEventListener('dispose',onSceneDispose);renderStates["delete"](scene);}function get(scene,camera){var renderState;if(renderStates.has(scene)===false){renderState=new WebGLRenderState();renderStates.set(scene,new WeakMap());renderStates.get(scene).set(camera,renderState);scene.addEventListener('dispose',onSceneDispose);}else {if(renderStates.get(scene).has(camera)===false){renderState=new WebGLRenderState();renderStates.get(scene).set(camera,renderState);}else {renderState=renderStates.get(scene).get(camera);}}return renderState;}function dispose(){renderStates=new WeakMap();}return {get:get,dispose:dispose};}/**
|
1356 | * @author mrdoob / http://mrdoob.com/
|
1357 | * @author alteredq / http://alteredqualia.com/
|
1358 | * @author bhouston / https://clara.io
|
1359 | * @author WestLangley / http://github.com/WestLangley
|
1360 | *
|
1361 | * parameters = {
|
1362 | *
|
1363 | * opacity: <float>,
|
1364 | *
|
1365 | * map: new THREE.Texture( <Image> ),
|
1366 | *
|
1367 | * alphaMap: new THREE.Texture( <Image> ),
|
1368 | *
|
1369 | * displacementMap: new THREE.Texture( <Image> ),
|
1370 | * displacementScale: <float>,
|
1371 | * displacementBias: <float>,
|
1372 | *
|
1373 | * wireframe: <boolean>,
|
1374 | * wireframeLinewidth: <float>
|
1375 | * }
|
1376 | */function MeshDepthMaterial(parameters){Material.call(this);this.type='MeshDepthMaterial';this.depthPacking=BasicDepthPacking;this.skinning=false;this.morphTargets=false;this.map=null;this.alphaMap=null;this.displacementMap=null;this.displacementScale=1;this.displacementBias=0;this.wireframe=false;this.wireframeLinewidth=1;this.fog=false;this.setValues(parameters);}MeshDepthMaterial.prototype=Object.create(Material.prototype);MeshDepthMaterial.prototype.constructor=MeshDepthMaterial;MeshDepthMaterial.prototype.isMeshDepthMaterial=true;MeshDepthMaterial.prototype.copy=function(source){Material.prototype.copy.call(this,source);this.depthPacking=source.depthPacking;this.skinning=source.skinning;this.morphTargets=source.morphTargets;this.map=source.map;this.alphaMap=source.alphaMap;this.displacementMap=source.displacementMap;this.displacementScale=source.displacementScale;this.displacementBias=source.displacementBias;this.wireframe=source.wireframe;this.wireframeLinewidth=source.wireframeLinewidth;return this;};/**
|
1377 | * @author WestLangley / http://github.com/WestLangley
|
1378 | *
|
1379 | * parameters = {
|
1380 | *
|
1381 | * referencePosition: <float>,
|
1382 | * nearDistance: <float>,
|
1383 | * farDistance: <float>,
|
1384 | *
|
1385 | * skinning: <bool>,
|
1386 | * morphTargets: <bool>,
|
1387 | *
|
1388 | * map: new THREE.Texture( <Image> ),
|
1389 | *
|
1390 | * alphaMap: new THREE.Texture( <Image> ),
|
1391 | *
|
1392 | * displacementMap: new THREE.Texture( <Image> ),
|
1393 | * displacementScale: <float>,
|
1394 | * displacementBias: <float>
|
1395 | *
|
1396 | * }
|
1397 | */function MeshDistanceMaterial(parameters){Material.call(this);this.type='MeshDistanceMaterial';this.referencePosition=new Vector3();this.nearDistance=1;this.farDistance=1000;this.skinning=false;this.morphTargets=false;this.map=null;this.alphaMap=null;this.displacementMap=null;this.displacementScale=1;this.displacementBias=0;this.fog=false;this.setValues(parameters);}MeshDistanceMaterial.prototype=Object.create(Material.prototype);MeshDistanceMaterial.prototype.constructor=MeshDistanceMaterial;MeshDistanceMaterial.prototype.isMeshDistanceMaterial=true;MeshDistanceMaterial.prototype.copy=function(source){Material.prototype.copy.call(this,source);this.referencePosition.copy(source.referencePosition);this.nearDistance=source.nearDistance;this.farDistance=source.farDistance;this.skinning=source.skinning;this.morphTargets=source.morphTargets;this.map=source.map;this.alphaMap=source.alphaMap;this.displacementMap=source.displacementMap;this.displacementScale=source.displacementScale;this.displacementBias=source.displacementBias;return this;};var vsm_frag="uniform sampler2D shadow_pass;\nuniform vec2 resolution;\nuniform float radius;\n#include <packing>\nvoid main() {\n float mean = 0.0;\n float squared_mean = 0.0;\n\tfloat depth = unpackRGBAToDepth( texture2D( shadow_pass, ( gl_FragCoord.xy ) / resolution ) );\n for ( float i = -1.0; i < 1.0 ; i += SAMPLE_RATE) {\n #ifdef HORIZONAL_PASS\n vec2 distribution = unpackRGBATo2Half( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( i, 0.0 ) * radius ) / resolution ) );\n mean += distribution.x;\n squared_mean += distribution.y * distribution.y + distribution.x * distribution.x;\n #else\n float depth = unpackRGBAToDepth( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( 0.0, i ) * radius ) / resolution ) );\n mean += depth;\n squared_mean += depth * depth;\n #endif\n }\n mean = mean * HALF_SAMPLE_RATE;\n squared_mean = squared_mean * HALF_SAMPLE_RATE;\n float std_dev = sqrt( squared_mean - mean * mean );\n gl_FragColor = pack2HalfToRGBA( vec2( mean, std_dev ) );\n}";var vsm_vert="void main() {\n\tgl_Position = vec4( position, 1.0 );\n}";/**
|
1398 | * @author alteredq / http://alteredqualia.com/
|
1399 | * @author mrdoob / http://mrdoob.com/
|
1400 | */function WebGLShadowMap(_renderer,_objects,maxTextureSize){var _frustum=new Frustum(),_shadowMapSize=new Vector2(),_viewportSize=new Vector2(),_viewport=new Vector4(),_depthMaterials=[],_distanceMaterials=[],_materialCache={};var shadowSide={0:BackSide,1:FrontSide,2:DoubleSide};var shadowMaterialVertical=new ShaderMaterial({defines:{SAMPLE_RATE:2.0/8.0,HALF_SAMPLE_RATE:1.0/8.0},uniforms:{shadow_pass:{value:null},resolution:{value:new Vector2()},radius:{value:4.0}},vertexShader:vsm_vert,fragmentShader:vsm_frag});var shadowMaterialHorizonal=shadowMaterialVertical.clone();shadowMaterialHorizonal.defines.HORIZONAL_PASS=1;var fullScreenTri=new BufferGeometry();fullScreenTri.setAttribute("position",new BufferAttribute(new Float32Array([-1,-1,0.5,3,-1,0.5,-1,3,0.5]),3));var fullScreenMesh=new Mesh(fullScreenTri,shadowMaterialVertical);var scope=this;this.enabled=false;this.autoUpdate=true;this.needsUpdate=false;this.type=PCFShadowMap;this.render=function(lights,scene,camera){if(scope.enabled===false)return;if(scope.autoUpdate===false&&scope.needsUpdate===false)return;if(lights.length===0)return;var currentRenderTarget=_renderer.getRenderTarget();var activeCubeFace=_renderer.getActiveCubeFace();var activeMipmapLevel=_renderer.getActiveMipmapLevel();var _state=_renderer.state;// Set GL state for depth map.
|
1401 | _state.setBlending(NoBlending);_state.buffers.color.setClear(1,1,1,1);_state.buffers.depth.setTest(true);_state.setScissorTest(false);// render depth map
|
1402 | for(var i=0,il=lights.length;i<il;i++){var light=lights[i];var shadow=light.shadow;if(shadow===undefined){console.warn('THREE.WebGLShadowMap:',light,'has no shadow.');continue;}_shadowMapSize.copy(shadow.mapSize);var shadowFrameExtents=shadow.getFrameExtents();_shadowMapSize.multiply(shadowFrameExtents);_viewportSize.copy(shadow.mapSize);if(_shadowMapSize.x>maxTextureSize||_shadowMapSize.y>maxTextureSize){if(_shadowMapSize.x>maxTextureSize){_viewportSize.x=Math.floor(maxTextureSize/shadowFrameExtents.x);_shadowMapSize.x=_viewportSize.x*shadowFrameExtents.x;shadow.mapSize.x=_viewportSize.x;}if(_shadowMapSize.y>maxTextureSize){_viewportSize.y=Math.floor(maxTextureSize/shadowFrameExtents.y);_shadowMapSize.y=_viewportSize.y*shadowFrameExtents.y;shadow.mapSize.y=_viewportSize.y;}}if(shadow.map===null&&!shadow.isPointLightShadow&&this.type===VSMShadowMap){var pars={minFilter:LinearFilter,magFilter:LinearFilter,format:RGBAFormat};shadow.map=new WebGLRenderTarget(_shadowMapSize.x,_shadowMapSize.y,pars);shadow.map.texture.name=light.name+".shadowMap";shadow.mapPass=new WebGLRenderTarget(_shadowMapSize.x,_shadowMapSize.y,pars);shadow.camera.updateProjectionMatrix();}if(shadow.map===null){var pars={minFilter:NearestFilter,magFilter:NearestFilter,format:RGBAFormat};shadow.map=new WebGLRenderTarget(_shadowMapSize.x,_shadowMapSize.y,pars);shadow.map.texture.name=light.name+".shadowMap";shadow.camera.updateProjectionMatrix();}_renderer.setRenderTarget(shadow.map);_renderer.clear();var viewportCount=shadow.getViewportCount();for(var vp=0;vp<viewportCount;vp++){var viewport=shadow.getViewport(vp);_viewport.set(_viewportSize.x*viewport.x,_viewportSize.y*viewport.y,_viewportSize.x*viewport.z,_viewportSize.y*viewport.w);_state.viewport(_viewport);shadow.updateMatrices(light,vp);_frustum=shadow.getFrustum();renderObject(scene,camera,shadow.camera,light,this.type);}// do blur pass for VSM
|
1403 | if(!shadow.isPointLightShadow&&this.type===VSMShadowMap){VSMPass(shadow,camera);}}scope.needsUpdate=false;_renderer.setRenderTarget(currentRenderTarget,activeCubeFace,activeMipmapLevel);};function VSMPass(shadow,camera){var geometry=_objects.update(fullScreenMesh);// vertical pass
|
1404 | shadowMaterialVertical.uniforms.shadow_pass.value=shadow.map.texture;shadowMaterialVertical.uniforms.resolution.value=shadow.mapSize;shadowMaterialVertical.uniforms.radius.value=shadow.radius;_renderer.setRenderTarget(shadow.mapPass);_renderer.clear();_renderer.renderBufferDirect(camera,null,geometry,shadowMaterialVertical,fullScreenMesh,null);// horizonal pass
|
1405 | shadowMaterialHorizonal.uniforms.shadow_pass.value=shadow.mapPass.texture;shadowMaterialHorizonal.uniforms.resolution.value=shadow.mapSize;shadowMaterialHorizonal.uniforms.radius.value=shadow.radius;_renderer.setRenderTarget(shadow.map);_renderer.clear();_renderer.renderBufferDirect(camera,null,geometry,shadowMaterialHorizonal,fullScreenMesh,null);}function getDepthMaterialVariant(useMorphing,useSkinning,useInstancing){var index=useMorphing<<0|useSkinning<<1|useInstancing<<2;var material=_depthMaterials[index];if(material===undefined){material=new MeshDepthMaterial({depthPacking:RGBADepthPacking,morphTargets:useMorphing,skinning:useSkinning});_depthMaterials[index]=material;}return material;}function getDistanceMaterialVariant(useMorphing,useSkinning,useInstancing){var index=useMorphing<<0|useSkinning<<1|useInstancing<<2;var material=_distanceMaterials[index];if(material===undefined){material=new MeshDistanceMaterial({morphTargets:useMorphing,skinning:useSkinning});_distanceMaterials[index]=material;}return material;}function getDepthMaterial(object,geometry,material,light,shadowCameraNear,shadowCameraFar,type){var result=null;var getMaterialVariant=getDepthMaterialVariant;var customMaterial=object.customDepthMaterial;if(light.isPointLight===true){getMaterialVariant=getDistanceMaterialVariant;customMaterial=object.customDistanceMaterial;}if(customMaterial===undefined){var useMorphing=false;if(material.morphTargets===true){useMorphing=geometry.morphAttributes&&geometry.morphAttributes.position&&geometry.morphAttributes.position.length>0;}var useSkinning=false;if(object.isSkinnedMesh===true){if(material.skinning===true){useSkinning=true;}else {console.warn('THREE.WebGLShadowMap: THREE.SkinnedMesh with material.skinning set to false:',object);}}var useInstancing=object.isInstancedMesh===true;result=getMaterialVariant(useMorphing,useSkinning,useInstancing);}else {result=customMaterial;}if(_renderer.localClippingEnabled&&material.clipShadows===true&&material.clippingPlanes.length!==0){// in this case we need a unique material instance reflecting the
|
1406 | // appropriate state
|
1407 | var keyA=result.uuid,keyB=material.uuid;var materialsForVariant=_materialCache[keyA];if(materialsForVariant===undefined){materialsForVariant={};_materialCache[keyA]=materialsForVariant;}var cachedMaterial=materialsForVariant[keyB];if(cachedMaterial===undefined){cachedMaterial=result.clone();materialsForVariant[keyB]=cachedMaterial;}result=cachedMaterial;}result.visible=material.visible;result.wireframe=material.wireframe;if(type===VSMShadowMap){result.side=material.shadowSide!==null?material.shadowSide:material.side;}else {result.side=material.shadowSide!==null?material.shadowSide:shadowSide[material.side];}result.clipShadows=material.clipShadows;result.clippingPlanes=material.clippingPlanes;result.clipIntersection=material.clipIntersection;result.wireframeLinewidth=material.wireframeLinewidth;result.linewidth=material.linewidth;if(light.isPointLight===true&&result.isMeshDistanceMaterial===true){result.referencePosition.setFromMatrixPosition(light.matrixWorld);result.nearDistance=shadowCameraNear;result.farDistance=shadowCameraFar;}return result;}function renderObject(object,camera,shadowCamera,light,type){if(object.visible===false)return;var visible=object.layers.test(camera.layers);if(visible&&(object.isMesh||object.isLine||object.isPoints)){if((object.castShadow||object.receiveShadow&&type===VSMShadowMap)&&(!object.frustumCulled||_frustum.intersectsObject(object))){object.modelViewMatrix.multiplyMatrices(shadowCamera.matrixWorldInverse,object.matrixWorld);var geometry=_objects.update(object);var material=object.material;if(Array.isArray(material)){var groups=geometry.groups;for(var k=0,kl=groups.length;k<kl;k++){var group=groups[k];var groupMaterial=material[group.materialIndex];if(groupMaterial&&groupMaterial.visible){var depthMaterial=getDepthMaterial(object,geometry,groupMaterial,light,shadowCamera.near,shadowCamera.far,type);_renderer.renderBufferDirect(shadowCamera,null,geometry,depthMaterial,object,group);}}}else if(material.visible){var depthMaterial=getDepthMaterial(object,geometry,material,light,shadowCamera.near,shadowCamera.far,type);_renderer.renderBufferDirect(shadowCamera,null,geometry,depthMaterial,object,null);}}}var children=object.children;for(var i=0,l=children.length;i<l;i++){renderObject(children[i],camera,shadowCamera,light,type);}}}/**
|
1408 | * @author mrdoob / http://mrdoob.com/
|
1409 | */function WebGLState(gl,extensions,capabilities){var _equationToGL,_factorToGL;var isWebGL2=capabilities.isWebGL2;function ColorBuffer(){var locked=false;var color=new Vector4();var currentColorMask=null;var currentColorClear=new Vector4(0,0,0,0);return {setMask:function setMask(colorMask){if(currentColorMask!==colorMask&&!locked){gl.colorMask(colorMask,colorMask,colorMask,colorMask);currentColorMask=colorMask;}},setLocked:function setLocked(lock){locked=lock;},setClear:function setClear(r,g,b,a,premultipliedAlpha){if(premultipliedAlpha===true){r*=a;g*=a;b*=a;}color.set(r,g,b,a);if(currentColorClear.equals(color)===false){gl.clearColor(r,g,b,a);currentColorClear.copy(color);}},reset:function reset(){locked=false;currentColorMask=null;currentColorClear.set(-1,0,0,0);// set to invalid state
|
1410 | }};}function DepthBuffer(){var locked=false;var currentDepthMask=null;var currentDepthFunc=null;var currentDepthClear=null;return {setTest:function setTest(depthTest){if(depthTest){enable(2929);}else {disable(2929);}},setMask:function setMask(depthMask){if(currentDepthMask!==depthMask&&!locked){gl.depthMask(depthMask);currentDepthMask=depthMask;}},setFunc:function setFunc(depthFunc){if(currentDepthFunc!==depthFunc){if(depthFunc){switch(depthFunc){case NeverDepth:gl.depthFunc(512);break;case AlwaysDepth:gl.depthFunc(519);break;case LessDepth:gl.depthFunc(513);break;case LessEqualDepth:gl.depthFunc(515);break;case EqualDepth:gl.depthFunc(514);break;case GreaterEqualDepth:gl.depthFunc(518);break;case GreaterDepth:gl.depthFunc(516);break;case NotEqualDepth:gl.depthFunc(517);break;default:gl.depthFunc(515);}}else {gl.depthFunc(515);}currentDepthFunc=depthFunc;}},setLocked:function setLocked(lock){locked=lock;},setClear:function setClear(depth){if(currentDepthClear!==depth){gl.clearDepth(depth);currentDepthClear=depth;}},reset:function reset(){locked=false;currentDepthMask=null;currentDepthFunc=null;currentDepthClear=null;}};}function StencilBuffer(){var locked=false;var currentStencilMask=null;var currentStencilFunc=null;var currentStencilRef=null;var currentStencilFuncMask=null;var currentStencilFail=null;var currentStencilZFail=null;var currentStencilZPass=null;var currentStencilClear=null;return {setTest:function setTest(stencilTest){if(!locked){if(stencilTest){enable(2960);}else {disable(2960);}}},setMask:function setMask(stencilMask){if(currentStencilMask!==stencilMask&&!locked){gl.stencilMask(stencilMask);currentStencilMask=stencilMask;}},setFunc:function setFunc(stencilFunc,stencilRef,stencilMask){if(currentStencilFunc!==stencilFunc||currentStencilRef!==stencilRef||currentStencilFuncMask!==stencilMask){gl.stencilFunc(stencilFunc,stencilRef,stencilMask);currentStencilFunc=stencilFunc;currentStencilRef=stencilRef;currentStencilFuncMask=stencilMask;}},setOp:function setOp(stencilFail,stencilZFail,stencilZPass){if(currentStencilFail!==stencilFail||currentStencilZFail!==stencilZFail||currentStencilZPass!==stencilZPass){gl.stencilOp(stencilFail,stencilZFail,stencilZPass);currentStencilFail=stencilFail;currentStencilZFail=stencilZFail;currentStencilZPass=stencilZPass;}},setLocked:function setLocked(lock){locked=lock;},setClear:function setClear(stencil){if(currentStencilClear!==stencil){gl.clearStencil(stencil);currentStencilClear=stencil;}},reset:function reset(){locked=false;currentStencilMask=null;currentStencilFunc=null;currentStencilRef=null;currentStencilFuncMask=null;currentStencilFail=null;currentStencilZFail=null;currentStencilZPass=null;currentStencilClear=null;}};}//
|
1411 | var colorBuffer=new ColorBuffer();var depthBuffer=new DepthBuffer();var stencilBuffer=new StencilBuffer();var maxVertexAttributes=gl.getParameter(34921);var newAttributes=new Uint8Array(maxVertexAttributes);var enabledAttributes=new Uint8Array(maxVertexAttributes);var attributeDivisors=new Uint8Array(maxVertexAttributes);var enabledCapabilities={};var currentProgram=null;var currentBlendingEnabled=null;var currentBlending=null;var currentBlendEquation=null;var currentBlendSrc=null;var currentBlendDst=null;var currentBlendEquationAlpha=null;var currentBlendSrcAlpha=null;var currentBlendDstAlpha=null;var currentPremultipledAlpha=false;var currentFlipSided=null;var currentCullFace=null;var currentLineWidth=null;var currentPolygonOffsetFactor=null;var currentPolygonOffsetUnits=null;var maxTextures=gl.getParameter(35661);var lineWidthAvailable=false;var version=0;var glVersion=gl.getParameter(7938);if(glVersion.indexOf('WebGL')!==-1){version=parseFloat(/^WebGL\ ([0-9])/.exec(glVersion)[1]);lineWidthAvailable=version>=1.0;}else if(glVersion.indexOf('OpenGL ES')!==-1){version=parseFloat(/^OpenGL\ ES\ ([0-9])/.exec(glVersion)[1]);lineWidthAvailable=version>=2.0;}var currentTextureSlot=null;var currentBoundTextures={};var currentScissor=new Vector4();var currentViewport=new Vector4();function createTexture(type,target,count){var data=new Uint8Array(4);// 4 is required to match default unpack alignment of 4.
|
1412 | var texture=gl.createTexture();gl.bindTexture(type,texture);gl.texParameteri(type,10241,9728);gl.texParameteri(type,10240,9728);for(var i=0;i<count;i++){gl.texImage2D(target+i,0,6408,1,1,0,6408,5121,data);}return texture;}var emptyTextures={};emptyTextures[3553]=createTexture(3553,3553,1);emptyTextures[34067]=createTexture(34067,34069,6);// init
|
1413 | colorBuffer.setClear(0,0,0,1);depthBuffer.setClear(1);stencilBuffer.setClear(0);enable(2929);depthBuffer.setFunc(LessEqualDepth);setFlipSided(false);setCullFace(CullFaceBack);enable(2884);setBlending(NoBlending);//
|
1414 | function initAttributes(){for(var i=0,l=newAttributes.length;i<l;i++){newAttributes[i]=0;}}function enableAttribute(attribute){enableAttributeAndDivisor(attribute,0);}function enableAttributeAndDivisor(attribute,meshPerAttribute){newAttributes[attribute]=1;if(enabledAttributes[attribute]===0){gl.enableVertexAttribArray(attribute);enabledAttributes[attribute]=1;}if(attributeDivisors[attribute]!==meshPerAttribute){var extension=isWebGL2?gl:extensions.get('ANGLE_instanced_arrays');extension[isWebGL2?'vertexAttribDivisor':'vertexAttribDivisorANGLE'](attribute,meshPerAttribute);attributeDivisors[attribute]=meshPerAttribute;}}function disableUnusedAttributes(){for(var i=0,l=enabledAttributes.length;i!==l;++i){if(enabledAttributes[i]!==newAttributes[i]){gl.disableVertexAttribArray(i);enabledAttributes[i]=0;}}}function vertexAttribPointer(index,size,type,normalized,stride,offset){if(isWebGL2===true&&(type===5124||type===5125)){gl.vertexAttribIPointer(index,size,type,normalized,stride,offset);}else {gl.vertexAttribPointer(index,size,type,normalized,stride,offset);}}function enable(id){if(enabledCapabilities[id]!==true){gl.enable(id);enabledCapabilities[id]=true;}}function disable(id){if(enabledCapabilities[id]!==false){gl.disable(id);enabledCapabilities[id]=false;}}function useProgram(program){if(currentProgram!==program){gl.useProgram(program);currentProgram=program;return true;}return false;}var equationToGL=(_equationToGL={},_equationToGL[AddEquation]=32774,_equationToGL[SubtractEquation]=32778,_equationToGL[ReverseSubtractEquation]=32779,_equationToGL);if(isWebGL2){equationToGL[MinEquation]=32775;equationToGL[MaxEquation]=32776;}else {var extension=extensions.get('EXT_blend_minmax');if(extension!==null){equationToGL[MinEquation]=extension.MIN_EXT;equationToGL[MaxEquation]=extension.MAX_EXT;}}var factorToGL=(_factorToGL={},_factorToGL[ZeroFactor]=0,_factorToGL[OneFactor]=1,_factorToGL[SrcColorFactor]=768,_factorToGL[SrcAlphaFactor]=770,_factorToGL[SrcAlphaSaturateFactor]=776,_factorToGL[DstColorFactor]=774,_factorToGL[DstAlphaFactor]=772,_factorToGL[OneMinusSrcColorFactor]=769,_factorToGL[OneMinusSrcAlphaFactor]=771,_factorToGL[OneMinusDstColorFactor]=775,_factorToGL[OneMinusDstAlphaFactor]=773,_factorToGL);function setBlending(blending,blendEquation,blendSrc,blendDst,blendEquationAlpha,blendSrcAlpha,blendDstAlpha,premultipliedAlpha){if(blending===NoBlending){if(currentBlendingEnabled){disable(3042);currentBlendingEnabled=false;}return;}if(!currentBlendingEnabled){enable(3042);currentBlendingEnabled=true;}if(blending!==CustomBlending){if(blending!==currentBlending||premultipliedAlpha!==currentPremultipledAlpha){if(currentBlendEquation!==AddEquation||currentBlendEquationAlpha!==AddEquation){gl.blendEquation(32774);currentBlendEquation=AddEquation;currentBlendEquationAlpha=AddEquation;}if(premultipliedAlpha){switch(blending){case NormalBlending:gl.blendFuncSeparate(1,771,1,771);break;case AdditiveBlending:gl.blendFunc(1,1);break;case SubtractiveBlending:gl.blendFuncSeparate(0,0,769,771);break;case MultiplyBlending:gl.blendFuncSeparate(0,768,0,770);break;default:console.error('THREE.WebGLState: Invalid blending: ',blending);break;}}else {switch(blending){case NormalBlending:gl.blendFuncSeparate(770,771,1,771);break;case AdditiveBlending:gl.blendFunc(770,1);break;case SubtractiveBlending:gl.blendFunc(0,769);break;case MultiplyBlending:gl.blendFunc(0,768);break;default:console.error('THREE.WebGLState: Invalid blending: ',blending);break;}}currentBlendSrc=null;currentBlendDst=null;currentBlendSrcAlpha=null;currentBlendDstAlpha=null;currentBlending=blending;currentPremultipledAlpha=premultipliedAlpha;}return;}// custom blending
|
1415 | blendEquationAlpha=blendEquationAlpha||blendEquation;blendSrcAlpha=blendSrcAlpha||blendSrc;blendDstAlpha=blendDstAlpha||blendDst;if(blendEquation!==currentBlendEquation||blendEquationAlpha!==currentBlendEquationAlpha){gl.blendEquationSeparate(equationToGL[blendEquation],equationToGL[blendEquationAlpha]);currentBlendEquation=blendEquation;currentBlendEquationAlpha=blendEquationAlpha;}if(blendSrc!==currentBlendSrc||blendDst!==currentBlendDst||blendSrcAlpha!==currentBlendSrcAlpha||blendDstAlpha!==currentBlendDstAlpha){gl.blendFuncSeparate(factorToGL[blendSrc],factorToGL[blendDst],factorToGL[blendSrcAlpha],factorToGL[blendDstAlpha]);currentBlendSrc=blendSrc;currentBlendDst=blendDst;currentBlendSrcAlpha=blendSrcAlpha;currentBlendDstAlpha=blendDstAlpha;}currentBlending=blending;currentPremultipledAlpha=null;}function setMaterial(material,frontFaceCW){material.side===DoubleSide?disable(2884):enable(2884);var flipSided=material.side===BackSide;if(frontFaceCW)flipSided=!flipSided;setFlipSided(flipSided);material.blending===NormalBlending&&material.transparent===false?setBlending(NoBlending):setBlending(material.blending,material.blendEquation,material.blendSrc,material.blendDst,material.blendEquationAlpha,material.blendSrcAlpha,material.blendDstAlpha,material.premultipliedAlpha);depthBuffer.setFunc(material.depthFunc);depthBuffer.setTest(material.depthTest);depthBuffer.setMask(material.depthWrite);colorBuffer.setMask(material.colorWrite);var stencilWrite=material.stencilWrite;stencilBuffer.setTest(stencilWrite);if(stencilWrite){stencilBuffer.setMask(material.stencilWriteMask);stencilBuffer.setFunc(material.stencilFunc,material.stencilRef,material.stencilFuncMask);stencilBuffer.setOp(material.stencilFail,material.stencilZFail,material.stencilZPass);}setPolygonOffset(material.polygonOffset,material.polygonOffsetFactor,material.polygonOffsetUnits);}//
|
1416 | function setFlipSided(flipSided){if(currentFlipSided!==flipSided){if(flipSided){gl.frontFace(2304);}else {gl.frontFace(2305);}currentFlipSided=flipSided;}}function setCullFace(cullFace){if(cullFace!==CullFaceNone){enable(2884);if(cullFace!==currentCullFace){if(cullFace===CullFaceBack){gl.cullFace(1029);}else if(cullFace===CullFaceFront){gl.cullFace(1028);}else {gl.cullFace(1032);}}}else {disable(2884);}currentCullFace=cullFace;}function setLineWidth(width){if(width!==currentLineWidth){if(lineWidthAvailable)gl.lineWidth(width);currentLineWidth=width;}}function setPolygonOffset(polygonOffset,factor,units){if(polygonOffset){enable(32823);if(currentPolygonOffsetFactor!==factor||currentPolygonOffsetUnits!==units){gl.polygonOffset(factor,units);currentPolygonOffsetFactor=factor;currentPolygonOffsetUnits=units;}}else {disable(32823);}}function setScissorTest(scissorTest){if(scissorTest){enable(3089);}else {disable(3089);}}// texture
|
1417 | function activeTexture(webglSlot){if(webglSlot===undefined)webglSlot=33984+maxTextures-1;if(currentTextureSlot!==webglSlot){gl.activeTexture(webglSlot);currentTextureSlot=webglSlot;}}function bindTexture(webglType,webglTexture){if(currentTextureSlot===null){activeTexture();}var boundTexture=currentBoundTextures[currentTextureSlot];if(boundTexture===undefined){boundTexture={type:undefined,texture:undefined};currentBoundTextures[currentTextureSlot]=boundTexture;}if(boundTexture.type!==webglType||boundTexture.texture!==webglTexture){gl.bindTexture(webglType,webglTexture||emptyTextures[webglType]);boundTexture.type=webglType;boundTexture.texture=webglTexture;}}function unbindTexture(){var boundTexture=currentBoundTextures[currentTextureSlot];if(boundTexture!==undefined&&boundTexture.type!==undefined){gl.bindTexture(boundTexture.type,null);boundTexture.type=undefined;boundTexture.texture=undefined;}}function compressedTexImage2D(){try{gl.compressedTexImage2D.apply(gl,arguments);}catch(error){console.error('THREE.WebGLState:',error);}}function texImage2D(){try{gl.texImage2D.apply(gl,arguments);}catch(error){console.error('THREE.WebGLState:',error);}}function texImage3D(){try{gl.texImage3D.apply(gl,arguments);}catch(error){console.error('THREE.WebGLState:',error);}}//
|
1418 | function scissor(scissor){if(currentScissor.equals(scissor)===false){gl.scissor(scissor.x,scissor.y,scissor.z,scissor.w);currentScissor.copy(scissor);}}function viewport(viewport){if(currentViewport.equals(viewport)===false){gl.viewport(viewport.x,viewport.y,viewport.z,viewport.w);currentViewport.copy(viewport);}}//
|
1419 | function reset(){for(var i=0;i<enabledAttributes.length;i++){if(enabledAttributes[i]===1){gl.disableVertexAttribArray(i);enabledAttributes[i]=0;}}enabledCapabilities={};currentTextureSlot=null;currentBoundTextures={};currentProgram=null;currentBlending=null;currentFlipSided=null;currentCullFace=null;colorBuffer.reset();depthBuffer.reset();stencilBuffer.reset();}return {buffers:{color:colorBuffer,depth:depthBuffer,stencil:stencilBuffer},initAttributes:initAttributes,enableAttribute:enableAttribute,enableAttributeAndDivisor:enableAttributeAndDivisor,disableUnusedAttributes:disableUnusedAttributes,vertexAttribPointer:vertexAttribPointer,enable:enable,disable:disable,useProgram:useProgram,setBlending:setBlending,setMaterial:setMaterial,setFlipSided:setFlipSided,setCullFace:setCullFace,setLineWidth:setLineWidth,setPolygonOffset:setPolygonOffset,setScissorTest:setScissorTest,activeTexture:activeTexture,bindTexture:bindTexture,unbindTexture:unbindTexture,compressedTexImage2D:compressedTexImage2D,texImage2D:texImage2D,texImage3D:texImage3D,scissor:scissor,viewport:viewport,reset:reset};}/**
|
1420 | * @author mrdoob / http://mrdoob.com/
|
1421 | */function WebGLTextures(_gl,extensions,state,properties,capabilities,utils,info){var _wrappingToGL,_filterToGL;var isWebGL2=capabilities.isWebGL2;var maxTextures=capabilities.maxTextures;var maxCubemapSize=capabilities.maxCubemapSize;var maxTextureSize=capabilities.maxTextureSize;var maxSamples=capabilities.maxSamples;var _videoTextures=new WeakMap();var _canvas;// cordova iOS (as of 5.0) still uses UIWebView, which provides OffscreenCanvas,
|
1422 | // also OffscreenCanvas.getContext("webgl"), but not OffscreenCanvas.getContext("2d")!
|
1423 | // Some implementations may only implement OffscreenCanvas partially (e.g. lacking 2d).
|
1424 | var useOffscreenCanvas=false;try{useOffscreenCanvas=typeof OffscreenCanvas!=='undefined'&&new OffscreenCanvas(1,1).getContext("2d")!==null;}catch(err){// Ignore any errors
|
1425 | }function createCanvas(width,height){// Use OffscreenCanvas when available. Specially needed in web workers
|
1426 | return useOffscreenCanvas?new OffscreenCanvas(width,height):document.createElementNS('http://www.w3.org/1999/xhtml','canvas');}function resizeImage(image,needsPowerOfTwo,needsNewCanvas,maxSize){var scale=1;// handle case if texture exceeds max size
|
1427 | if(image.width>maxSize||image.height>maxSize){scale=maxSize/Math.max(image.width,image.height);}// only perform resize if necessary
|
1428 | if(scale<1||needsPowerOfTwo===true){// only perform resize for certain image types
|
1429 | if(typeof HTMLImageElement!=='undefined'&&image instanceof HTMLImageElement||typeof HTMLCanvasElement!=='undefined'&&image instanceof HTMLCanvasElement||typeof ImageBitmap!=='undefined'&&image instanceof ImageBitmap){var floor=needsPowerOfTwo?MathUtils.floorPowerOfTwo:Math.floor;var width=floor(scale*image.width);var height=floor(scale*image.height);if(_canvas===undefined)_canvas=createCanvas(width,height);// cube textures can't reuse the same canvas
|
1430 | var canvas=needsNewCanvas?createCanvas(width,height):_canvas;canvas.width=width;canvas.height=height;var context=canvas.getContext('2d');context.drawImage(image,0,0,width,height);console.warn('THREE.WebGLRenderer: Texture has been resized from ('+image.width+'x'+image.height+') to ('+width+'x'+height+').');return canvas;}else {if('data'in image){console.warn('THREE.WebGLRenderer: Image in DataTexture is too big ('+image.width+'x'+image.height+').');}return image;}}return image;}function isPowerOfTwo(image){return MathUtils.isPowerOfTwo(image.width)&&MathUtils.isPowerOfTwo(image.height);}function textureNeedsPowerOfTwo(texture){if(isWebGL2)return false;return texture.wrapS!==ClampToEdgeWrapping||texture.wrapT!==ClampToEdgeWrapping||texture.minFilter!==NearestFilter&&texture.minFilter!==LinearFilter;}function textureNeedsGenerateMipmaps(texture,supportsMips){return texture.generateMipmaps&&supportsMips&&texture.minFilter!==NearestFilter&&texture.minFilter!==LinearFilter;}function generateMipmap(target,texture,width,height){_gl.generateMipmap(target);var textureProperties=properties.get(texture);// Note: Math.log( x ) * Math.LOG2E used instead of Math.log2( x ) which is not supported by IE11
|
1431 | textureProperties.__maxMipLevel=Math.log(Math.max(width,height))*Math.LOG2E;}function getInternalFormat(internalFormatName,glFormat,glType){if(isWebGL2===false)return glFormat;if(internalFormatName!==null){if(_gl[internalFormatName]!==undefined)return _gl[internalFormatName];console.warn('THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format \''+internalFormatName+'\'');}var internalFormat=glFormat;if(glFormat===6403){if(glType===5126)internalFormat=33326;if(glType===5131)internalFormat=33325;if(glType===5121)internalFormat=33321;}if(glFormat===6407){if(glType===5126)internalFormat=34837;if(glType===5131)internalFormat=34843;if(glType===5121)internalFormat=32849;}if(glFormat===6408){if(glType===5126)internalFormat=34836;if(glType===5131)internalFormat=34842;if(glType===5121)internalFormat=32856;}if(internalFormat===33325||internalFormat===33326||internalFormat===34842||internalFormat===34836){extensions.get('EXT_color_buffer_float');}return internalFormat;}// Fallback filters for non-power-of-2 textures
|
1432 | function filterFallback(f){if(f===NearestFilter||f===NearestMipmapNearestFilter||f===NearestMipmapLinearFilter){return 9728;}return 9729;}//
|
1433 | function onTextureDispose(event){var texture=event.target;texture.removeEventListener('dispose',onTextureDispose);deallocateTexture(texture);if(texture.isVideoTexture){_videoTextures["delete"](texture);}info.memory.textures--;}function onRenderTargetDispose(event){var renderTarget=event.target;renderTarget.removeEventListener('dispose',onRenderTargetDispose);deallocateRenderTarget(renderTarget);info.memory.textures--;}//
|
1434 | function deallocateTexture(texture){var textureProperties=properties.get(texture);if(textureProperties.__webglInit===undefined)return;_gl.deleteTexture(textureProperties.__webglTexture);properties.remove(texture);}function deallocateRenderTarget(renderTarget){var renderTargetProperties=properties.get(renderTarget);var textureProperties=properties.get(renderTarget.texture);if(!renderTarget)return;if(textureProperties.__webglTexture!==undefined){_gl.deleteTexture(textureProperties.__webglTexture);}if(renderTarget.depthTexture){renderTarget.depthTexture.dispose();}if(renderTarget.isWebGLCubeRenderTarget){for(var i=0;i<6;i++){_gl.deleteFramebuffer(renderTargetProperties.__webglFramebuffer[i]);if(renderTargetProperties.__webglDepthbuffer)_gl.deleteRenderbuffer(renderTargetProperties.__webglDepthbuffer[i]);}}else {_gl.deleteFramebuffer(renderTargetProperties.__webglFramebuffer);if(renderTargetProperties.__webglDepthbuffer)_gl.deleteRenderbuffer(renderTargetProperties.__webglDepthbuffer);if(renderTargetProperties.__webglMultisampledFramebuffer)_gl.deleteFramebuffer(renderTargetProperties.__webglMultisampledFramebuffer);if(renderTargetProperties.__webglColorRenderbuffer)_gl.deleteRenderbuffer(renderTargetProperties.__webglColorRenderbuffer);if(renderTargetProperties.__webglDepthRenderbuffer)_gl.deleteRenderbuffer(renderTargetProperties.__webglDepthRenderbuffer);}properties.remove(renderTarget.texture);properties.remove(renderTarget);}//
|
1435 | var textureUnits=0;function resetTextureUnits(){textureUnits=0;}function allocateTextureUnit(){var textureUnit=textureUnits;if(textureUnit>=maxTextures){console.warn('THREE.WebGLTextures: Trying to use '+textureUnit+' texture units while this GPU supports only '+maxTextures);}textureUnits+=1;return textureUnit;}//
|
1436 | function setTexture2D(texture,slot){var textureProperties=properties.get(texture);if(texture.isVideoTexture)updateVideoTexture(texture);if(texture.version>0&&textureProperties.__version!==texture.version){var image=texture.image;if(image===undefined){console.warn('THREE.WebGLRenderer: Texture marked for update but image is undefined');}else if(image.complete===false){console.warn('THREE.WebGLRenderer: Texture marked for update but image is incomplete');}else {uploadTexture(textureProperties,texture,slot);return;}}state.activeTexture(33984+slot);state.bindTexture(3553,textureProperties.__webglTexture);}function setTexture2DArray(texture,slot){var textureProperties=properties.get(texture);if(texture.version>0&&textureProperties.__version!==texture.version){uploadTexture(textureProperties,texture,slot);return;}state.activeTexture(33984+slot);state.bindTexture(35866,textureProperties.__webglTexture);}function setTexture3D(texture,slot){var textureProperties=properties.get(texture);if(texture.version>0&&textureProperties.__version!==texture.version){uploadTexture(textureProperties,texture,slot);return;}state.activeTexture(33984+slot);state.bindTexture(32879,textureProperties.__webglTexture);}function setTextureCube(texture,slot){if(texture.image.length!==6)return;var textureProperties=properties.get(texture);if(texture.version>0&&textureProperties.__version!==texture.version){initTexture(textureProperties,texture);state.activeTexture(33984+slot);state.bindTexture(34067,textureProperties.__webglTexture);_gl.pixelStorei(37440,texture.flipY);var isCompressed=texture&&(texture.isCompressedTexture||texture.image[0].isCompressedTexture);var isDataTexture=texture.image[0]&&texture.image[0].isDataTexture;var cubeImage=[];for(var i=0;i<6;i++){if(!isCompressed&&!isDataTexture){cubeImage[i]=resizeImage(texture.image[i],false,true,maxCubemapSize);}else {cubeImage[i]=isDataTexture?texture.image[i].image:texture.image[i];}}var image=cubeImage[0],supportsMips=isPowerOfTwo(image)||isWebGL2,glFormat=utils.convert(texture.format),glType=utils.convert(texture.type),glInternalFormat=getInternalFormat(texture.internalFormat,glFormat,glType);setTextureParameters(34067,texture,supportsMips);var mipmaps;if(isCompressed){for(var i=0;i<6;i++){mipmaps=cubeImage[i].mipmaps;for(var j=0;j<mipmaps.length;j++){var mipmap=mipmaps[j];if(texture.format!==RGBAFormat&&texture.format!==RGBFormat){if(glFormat!==null){state.compressedTexImage2D(34069+i,j,glInternalFormat,mipmap.width,mipmap.height,0,mipmap.data);}else {console.warn('THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()');}}else {state.texImage2D(34069+i,j,glInternalFormat,mipmap.width,mipmap.height,0,glFormat,glType,mipmap.data);}}}textureProperties.__maxMipLevel=mipmaps.length-1;}else {mipmaps=texture.mipmaps;for(var i=0;i<6;i++){if(isDataTexture){state.texImage2D(34069+i,0,glInternalFormat,cubeImage[i].width,cubeImage[i].height,0,glFormat,glType,cubeImage[i].data);for(var j=0;j<mipmaps.length;j++){var mipmap=mipmaps[j];var mipmapImage=mipmap.image[i].image;state.texImage2D(34069+i,j+1,glInternalFormat,mipmapImage.width,mipmapImage.height,0,glFormat,glType,mipmapImage.data);}}else {state.texImage2D(34069+i,0,glInternalFormat,glFormat,glType,cubeImage[i]);for(var j=0;j<mipmaps.length;j++){var mipmap=mipmaps[j];state.texImage2D(34069+i,j+1,glInternalFormat,glFormat,glType,mipmap.image[i]);}}}textureProperties.__maxMipLevel=mipmaps.length;}if(textureNeedsGenerateMipmaps(texture,supportsMips)){// We assume images for cube map have the same size.
|
1437 | generateMipmap(34067,texture,image.width,image.height);}textureProperties.__version=texture.version;if(texture.onUpdate)texture.onUpdate(texture);}else {state.activeTexture(33984+slot);state.bindTexture(34067,textureProperties.__webglTexture);}}function setTextureCubeDynamic(texture,slot){state.activeTexture(33984+slot);state.bindTexture(34067,properties.get(texture).__webglTexture);}var wrappingToGL=(_wrappingToGL={},_wrappingToGL[RepeatWrapping]=10497,_wrappingToGL[ClampToEdgeWrapping]=33071,_wrappingToGL[MirroredRepeatWrapping]=33648,_wrappingToGL);var filterToGL=(_filterToGL={},_filterToGL[NearestFilter]=9728,_filterToGL[NearestMipmapNearestFilter]=9984,_filterToGL[NearestMipmapLinearFilter]=9986,_filterToGL[LinearFilter]=9729,_filterToGL[LinearMipmapNearestFilter]=9985,_filterToGL[LinearMipmapLinearFilter]=9987,_filterToGL);function setTextureParameters(textureType,texture,supportsMips){if(supportsMips){_gl.texParameteri(textureType,10242,wrappingToGL[texture.wrapS]);_gl.texParameteri(textureType,10243,wrappingToGL[texture.wrapT]);if(textureType===32879||textureType===35866){_gl.texParameteri(textureType,32882,wrappingToGL[texture.wrapR]);}_gl.texParameteri(textureType,10240,filterToGL[texture.magFilter]);_gl.texParameteri(textureType,10241,filterToGL[texture.minFilter]);}else {_gl.texParameteri(textureType,10242,33071);_gl.texParameteri(textureType,10243,33071);if(textureType===32879||textureType===35866){_gl.texParameteri(textureType,32882,33071);}if(texture.wrapS!==ClampToEdgeWrapping||texture.wrapT!==ClampToEdgeWrapping){console.warn('THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.');}_gl.texParameteri(textureType,10240,filterFallback(texture.magFilter));_gl.texParameteri(textureType,10241,filterFallback(texture.minFilter));if(texture.minFilter!==NearestFilter&&texture.minFilter!==LinearFilter){console.warn('THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.');}}var extension=extensions.get('EXT_texture_filter_anisotropic');if(extension){if(texture.type===FloatType&&extensions.get('OES_texture_float_linear')===null)return;if(texture.type===HalfFloatType&&(isWebGL2||extensions.get('OES_texture_half_float_linear'))===null)return;if(texture.anisotropy>1||properties.get(texture).__currentAnisotropy){_gl.texParameterf(textureType,extension.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(texture.anisotropy,capabilities.getMaxAnisotropy()));properties.get(texture).__currentAnisotropy=texture.anisotropy;}}}function initTexture(textureProperties,texture){if(textureProperties.__webglInit===undefined){textureProperties.__webglInit=true;texture.addEventListener('dispose',onTextureDispose);textureProperties.__webglTexture=_gl.createTexture();info.memory.textures++;}}function uploadTexture(textureProperties,texture,slot){var textureType=3553;if(texture.isDataTexture2DArray)textureType=35866;if(texture.isDataTexture3D)textureType=32879;initTexture(textureProperties,texture);state.activeTexture(33984+slot);state.bindTexture(textureType,textureProperties.__webglTexture);_gl.pixelStorei(37440,texture.flipY);_gl.pixelStorei(37441,texture.premultiplyAlpha);_gl.pixelStorei(3317,texture.unpackAlignment);var needsPowerOfTwo=textureNeedsPowerOfTwo(texture)&&isPowerOfTwo(texture.image)===false;var image=resizeImage(texture.image,needsPowerOfTwo,false,maxTextureSize);var supportsMips=isPowerOfTwo(image)||isWebGL2,glFormat=utils.convert(texture.format),glType=utils.convert(texture.type),glInternalFormat=getInternalFormat(texture.internalFormat,glFormat,glType);setTextureParameters(textureType,texture,supportsMips);var mipmap,mipmaps=texture.mipmaps;if(texture.isDepthTexture){// populate depth texture with dummy data
|
1438 | glInternalFormat=6402;if(isWebGL2){if(texture.type===FloatType){glInternalFormat=36012;}else if(texture.type===UnsignedIntType){glInternalFormat=33190;}else if(texture.type===UnsignedInt248Type){glInternalFormat=35056;}else {glInternalFormat=33189;// WebGL2 requires sized internalformat for glTexImage2D
|
1439 | }}else {if(texture.type===FloatType){console.error('WebGLRenderer: Floating point depth texture requires WebGL2.');}}// validation checks for WebGL 1
|
1440 | if(texture.format===DepthFormat&&glInternalFormat===6402){// The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
|
1441 | // DEPTH_COMPONENT and type is not UNSIGNED_SHORT or UNSIGNED_INT
|
1442 | // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
|
1443 | if(texture.type!==UnsignedShortType&&texture.type!==UnsignedIntType){console.warn('THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture.');texture.type=UnsignedShortType;glType=utils.convert(texture.type);}}if(texture.format===DepthStencilFormat&&glInternalFormat===6402){// Depth stencil textures need the DEPTH_STENCIL internal format
|
1444 | // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
|
1445 | glInternalFormat=34041;// The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
|
1446 | // DEPTH_STENCIL and type is not UNSIGNED_INT_24_8_WEBGL.
|
1447 | // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
|
1448 | if(texture.type!==UnsignedInt248Type){console.warn('THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture.');texture.type=UnsignedInt248Type;glType=utils.convert(texture.type);}}//
|
1449 | state.texImage2D(3553,0,glInternalFormat,image.width,image.height,0,glFormat,glType,null);}else if(texture.isDataTexture){// use manually created mipmaps if available
|
1450 | // if there are no manual mipmaps
|
1451 | // set 0 level mipmap and then use GL to generate other mipmap levels
|
1452 | if(mipmaps.length>0&&supportsMips){for(var i=0,il=mipmaps.length;i<il;i++){mipmap=mipmaps[i];state.texImage2D(3553,i,glInternalFormat,mipmap.width,mipmap.height,0,glFormat,glType,mipmap.data);}texture.generateMipmaps=false;textureProperties.__maxMipLevel=mipmaps.length-1;}else {state.texImage2D(3553,0,glInternalFormat,image.width,image.height,0,glFormat,glType,image.data);textureProperties.__maxMipLevel=0;}}else if(texture.isCompressedTexture){for(var i=0,il=mipmaps.length;i<il;i++){mipmap=mipmaps[i];if(texture.format!==RGBAFormat&&texture.format!==RGBFormat){if(glFormat!==null){state.compressedTexImage2D(3553,i,glInternalFormat,mipmap.width,mipmap.height,0,mipmap.data);}else {console.warn('THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()');}}else {state.texImage2D(3553,i,glInternalFormat,mipmap.width,mipmap.height,0,glFormat,glType,mipmap.data);}}textureProperties.__maxMipLevel=mipmaps.length-1;}else if(texture.isDataTexture2DArray){state.texImage3D(35866,0,glInternalFormat,image.width,image.height,image.depth,0,glFormat,glType,image.data);textureProperties.__maxMipLevel=0;}else if(texture.isDataTexture3D){state.texImage3D(32879,0,glInternalFormat,image.width,image.height,image.depth,0,glFormat,glType,image.data);textureProperties.__maxMipLevel=0;}else {// regular Texture (image, video, canvas)
|
1453 | // use manually created mipmaps if available
|
1454 | // if there are no manual mipmaps
|
1455 | // set 0 level mipmap and then use GL to generate other mipmap levels
|
1456 | if(mipmaps.length>0&&supportsMips){for(var i=0,il=mipmaps.length;i<il;i++){mipmap=mipmaps[i];state.texImage2D(3553,i,glInternalFormat,glFormat,glType,mipmap);}texture.generateMipmaps=false;textureProperties.__maxMipLevel=mipmaps.length-1;}else {state.texImage2D(3553,0,glInternalFormat,glFormat,glType,image);textureProperties.__maxMipLevel=0;}}if(textureNeedsGenerateMipmaps(texture,supportsMips)){generateMipmap(textureType,texture,image.width,image.height);}textureProperties.__version=texture.version;if(texture.onUpdate)texture.onUpdate(texture);}// Render targets
|
1457 | // Setup storage for target texture and bind it to correct framebuffer
|
1458 | function setupFrameBufferTexture(framebuffer,renderTarget,attachment,textureTarget){var glFormat=utils.convert(renderTarget.texture.format);var glType=utils.convert(renderTarget.texture.type);var glInternalFormat=getInternalFormat(renderTarget.texture.internalFormat,glFormat,glType);state.texImage2D(textureTarget,0,glInternalFormat,renderTarget.width,renderTarget.height,0,glFormat,glType,null);_gl.bindFramebuffer(36160,framebuffer);_gl.framebufferTexture2D(36160,attachment,textureTarget,properties.get(renderTarget.texture).__webglTexture,0);_gl.bindFramebuffer(36160,null);}// Setup storage for internal depth/stencil buffers and bind to correct framebuffer
|
1459 | function setupRenderBufferStorage(renderbuffer,renderTarget,isMultisample){_gl.bindRenderbuffer(36161,renderbuffer);if(renderTarget.depthBuffer&&!renderTarget.stencilBuffer){var glInternalFormat=33189;if(isMultisample){var depthTexture=renderTarget.depthTexture;if(depthTexture&&depthTexture.isDepthTexture){if(depthTexture.type===FloatType){glInternalFormat=36012;}else if(depthTexture.type===UnsignedIntType){glInternalFormat=33190;}}var samples=getRenderTargetSamples(renderTarget);_gl.renderbufferStorageMultisample(36161,samples,glInternalFormat,renderTarget.width,renderTarget.height);}else {_gl.renderbufferStorage(36161,glInternalFormat,renderTarget.width,renderTarget.height);}_gl.framebufferRenderbuffer(36160,36096,36161,renderbuffer);}else if(renderTarget.depthBuffer&&renderTarget.stencilBuffer){if(isMultisample){var samples=getRenderTargetSamples(renderTarget);_gl.renderbufferStorageMultisample(36161,samples,35056,renderTarget.width,renderTarget.height);}else {_gl.renderbufferStorage(36161,34041,renderTarget.width,renderTarget.height);}_gl.framebufferRenderbuffer(36160,33306,36161,renderbuffer);}else {var glFormat=utils.convert(renderTarget.texture.format);var glType=utils.convert(renderTarget.texture.type);var glInternalFormat=getInternalFormat(renderTarget.texture.internalFormat,glFormat,glType);if(isMultisample){var samples=getRenderTargetSamples(renderTarget);_gl.renderbufferStorageMultisample(36161,samples,glInternalFormat,renderTarget.width,renderTarget.height);}else {_gl.renderbufferStorage(36161,glInternalFormat,renderTarget.width,renderTarget.height);}}_gl.bindRenderbuffer(36161,null);}// Setup resources for a Depth Texture for a FBO (needs an extension)
|
1460 | function setupDepthTexture(framebuffer,renderTarget){var isCube=renderTarget&&renderTarget.isWebGLCubeRenderTarget;if(isCube)throw new Error('Depth Texture with cube render targets is not supported');_gl.bindFramebuffer(36160,framebuffer);if(!(renderTarget.depthTexture&&renderTarget.depthTexture.isDepthTexture)){throw new Error('renderTarget.depthTexture must be an instance of THREE.DepthTexture');}// upload an empty depth texture with framebuffer size
|
1461 | if(!properties.get(renderTarget.depthTexture).__webglTexture||renderTarget.depthTexture.image.width!==renderTarget.width||renderTarget.depthTexture.image.height!==renderTarget.height){renderTarget.depthTexture.image.width=renderTarget.width;renderTarget.depthTexture.image.height=renderTarget.height;renderTarget.depthTexture.needsUpdate=true;}setTexture2D(renderTarget.depthTexture,0);var webglDepthTexture=properties.get(renderTarget.depthTexture).__webglTexture;if(renderTarget.depthTexture.format===DepthFormat){_gl.framebufferTexture2D(36160,36096,3553,webglDepthTexture,0);}else if(renderTarget.depthTexture.format===DepthStencilFormat){_gl.framebufferTexture2D(36160,33306,3553,webglDepthTexture,0);}else {throw new Error('Unknown depthTexture format');}}// Setup GL resources for a non-texture depth buffer
|
1462 | function setupDepthRenderbuffer(renderTarget){var renderTargetProperties=properties.get(renderTarget);var isCube=renderTarget.isWebGLCubeRenderTarget===true;if(renderTarget.depthTexture){if(isCube)throw new Error('target.depthTexture not supported in Cube render targets');setupDepthTexture(renderTargetProperties.__webglFramebuffer,renderTarget);}else {if(isCube){renderTargetProperties.__webglDepthbuffer=[];for(var i=0;i<6;i++){_gl.bindFramebuffer(36160,renderTargetProperties.__webglFramebuffer[i]);renderTargetProperties.__webglDepthbuffer[i]=_gl.createRenderbuffer();setupRenderBufferStorage(renderTargetProperties.__webglDepthbuffer[i],renderTarget,false);}}else {_gl.bindFramebuffer(36160,renderTargetProperties.__webglFramebuffer);renderTargetProperties.__webglDepthbuffer=_gl.createRenderbuffer();setupRenderBufferStorage(renderTargetProperties.__webglDepthbuffer,renderTarget,false);}}_gl.bindFramebuffer(36160,null);}// Set up GL resources for the render target
|
1463 | function setupRenderTarget(renderTarget){var renderTargetProperties=properties.get(renderTarget);var textureProperties=properties.get(renderTarget.texture);renderTarget.addEventListener('dispose',onRenderTargetDispose);textureProperties.__webglTexture=_gl.createTexture();info.memory.textures++;var isCube=renderTarget.isWebGLCubeRenderTarget===true;var isMultisample=renderTarget.isWebGLMultisampleRenderTarget===true;var supportsMips=isPowerOfTwo(renderTarget)||isWebGL2;// Handles WebGL2 RGBFormat fallback - #18858
|
1464 | if(isWebGL2&&renderTarget.texture.format===RGBFormat&&(renderTarget.texture.type===FloatType||renderTarget.texture.type===HalfFloatType)){renderTarget.texture.format=RGBAFormat;console.warn('THREE.WebGLRenderer: Rendering to textures with RGB format is not supported. Using RGBA format instead.');}// Setup framebuffer
|
1465 | if(isCube){renderTargetProperties.__webglFramebuffer=[];for(var i=0;i<6;i++){renderTargetProperties.__webglFramebuffer[i]=_gl.createFramebuffer();}}else {renderTargetProperties.__webglFramebuffer=_gl.createFramebuffer();if(isMultisample){if(isWebGL2){renderTargetProperties.__webglMultisampledFramebuffer=_gl.createFramebuffer();renderTargetProperties.__webglColorRenderbuffer=_gl.createRenderbuffer();_gl.bindRenderbuffer(36161,renderTargetProperties.__webglColorRenderbuffer);var glFormat=utils.convert(renderTarget.texture.format);var glType=utils.convert(renderTarget.texture.type);var glInternalFormat=getInternalFormat(renderTarget.texture.internalFormat,glFormat,glType);var samples=getRenderTargetSamples(renderTarget);_gl.renderbufferStorageMultisample(36161,samples,glInternalFormat,renderTarget.width,renderTarget.height);_gl.bindFramebuffer(36160,renderTargetProperties.__webglMultisampledFramebuffer);_gl.framebufferRenderbuffer(36160,36064,36161,renderTargetProperties.__webglColorRenderbuffer);_gl.bindRenderbuffer(36161,null);if(renderTarget.depthBuffer){renderTargetProperties.__webglDepthRenderbuffer=_gl.createRenderbuffer();setupRenderBufferStorage(renderTargetProperties.__webglDepthRenderbuffer,renderTarget,true);}_gl.bindFramebuffer(36160,null);}else {console.warn('THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.');}}}// Setup color buffer
|
1466 | if(isCube){state.bindTexture(34067,textureProperties.__webglTexture);setTextureParameters(34067,renderTarget.texture,supportsMips);for(var i=0;i<6;i++){setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer[i],renderTarget,36064,34069+i);}if(textureNeedsGenerateMipmaps(renderTarget.texture,supportsMips)){generateMipmap(34067,renderTarget.texture,renderTarget.width,renderTarget.height);}state.bindTexture(34067,null);}else {state.bindTexture(3553,textureProperties.__webglTexture);setTextureParameters(3553,renderTarget.texture,supportsMips);setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer,renderTarget,36064,3553);if(textureNeedsGenerateMipmaps(renderTarget.texture,supportsMips)){generateMipmap(3553,renderTarget.texture,renderTarget.width,renderTarget.height);}state.bindTexture(3553,null);}// Setup depth and stencil buffers
|
1467 | if(renderTarget.depthBuffer){setupDepthRenderbuffer(renderTarget);}}function updateRenderTargetMipmap(renderTarget){var texture=renderTarget.texture;var supportsMips=isPowerOfTwo(renderTarget)||isWebGL2;if(textureNeedsGenerateMipmaps(texture,supportsMips)){var target=renderTarget.isWebGLCubeRenderTarget?34067:3553;var webglTexture=properties.get(texture).__webglTexture;state.bindTexture(target,webglTexture);generateMipmap(target,texture,renderTarget.width,renderTarget.height);state.bindTexture(target,null);}}function updateMultisampleRenderTarget(renderTarget){if(renderTarget.isWebGLMultisampleRenderTarget){if(isWebGL2){var renderTargetProperties=properties.get(renderTarget);_gl.bindFramebuffer(36008,renderTargetProperties.__webglMultisampledFramebuffer);_gl.bindFramebuffer(36009,renderTargetProperties.__webglFramebuffer);var width=renderTarget.width;var height=renderTarget.height;var mask=16384;if(renderTarget.depthBuffer)mask|=256;if(renderTarget.stencilBuffer)mask|=1024;_gl.blitFramebuffer(0,0,width,height,0,0,width,height,mask,9728);_gl.bindFramebuffer(36160,renderTargetProperties.__webglMultisampledFramebuffer);// see #18905
|
1468 | }else {console.warn('THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.');}}}function getRenderTargetSamples(renderTarget){return isWebGL2&&renderTarget.isWebGLMultisampleRenderTarget?Math.min(maxSamples,renderTarget.samples):0;}function updateVideoTexture(texture){var frame=info.render.frame;// Check the last frame we updated the VideoTexture
|
1469 | if(_videoTextures.get(texture)!==frame){_videoTextures.set(texture,frame);texture.update();}}// backwards compatibility
|
1470 | var warnedTexture2D=false;var warnedTextureCube=false;function safeSetTexture2D(texture,slot){if(texture&&texture.isWebGLRenderTarget){if(warnedTexture2D===false){console.warn("THREE.WebGLTextures.safeSetTexture2D: don't use render targets as textures. Use their .texture property instead.");warnedTexture2D=true;}texture=texture.texture;}setTexture2D(texture,slot);}function safeSetTextureCube(texture,slot){if(texture&&texture.isWebGLCubeRenderTarget){if(warnedTextureCube===false){console.warn("THREE.WebGLTextures.safeSetTextureCube: don't use cube render targets as textures. Use their .texture property instead.");warnedTextureCube=true;}texture=texture.texture;}// currently relying on the fact that WebGLCubeRenderTarget.texture is a Texture and NOT a CubeTexture
|
1471 | // TODO: unify these code paths
|
1472 | if(texture&&texture.isCubeTexture||Array.isArray(texture.image)&&texture.image.length===6){// CompressedTexture can have Array in image :/
|
1473 | // this function alone should take care of cube textures
|
1474 | setTextureCube(texture,slot);}else {// assumed: texture property of THREE.WebGLCubeRenderTarget
|
1475 | setTextureCubeDynamic(texture,slot);}}//
|
1476 | this.allocateTextureUnit=allocateTextureUnit;this.resetTextureUnits=resetTextureUnits;this.setTexture2D=setTexture2D;this.setTexture2DArray=setTexture2DArray;this.setTexture3D=setTexture3D;this.setTextureCube=setTextureCube;this.setTextureCubeDynamic=setTextureCubeDynamic;this.setupRenderTarget=setupRenderTarget;this.updateRenderTargetMipmap=updateRenderTargetMipmap;this.updateMultisampleRenderTarget=updateMultisampleRenderTarget;this.safeSetTexture2D=safeSetTexture2D;this.safeSetTextureCube=safeSetTextureCube;}/**
|
1477 | * @author thespite / http://www.twitter.com/thespite
|
1478 | */function WebGLUtils(gl,extensions,capabilities){var isWebGL2=capabilities.isWebGL2;function convert(p){var extension;if(p===UnsignedByteType)return 5121;if(p===UnsignedShort4444Type)return 32819;if(p===UnsignedShort5551Type)return 32820;if(p===UnsignedShort565Type)return 33635;if(p===ByteType)return 5120;if(p===ShortType)return 5122;if(p===UnsignedShortType)return 5123;if(p===IntType)return 5124;if(p===UnsignedIntType)return 5125;if(p===FloatType)return 5126;if(p===HalfFloatType){if(isWebGL2)return 5131;extension=extensions.get('OES_texture_half_float');if(extension!==null){return extension.HALF_FLOAT_OES;}else {return null;}}if(p===AlphaFormat)return 6406;if(p===RGBFormat)return 6407;if(p===RGBAFormat)return 6408;if(p===LuminanceFormat)return 6409;if(p===LuminanceAlphaFormat)return 6410;if(p===DepthFormat)return 6402;if(p===DepthStencilFormat)return 34041;if(p===RedFormat)return 6403;// WebGL2 formats.
|
1479 | if(p===RedIntegerFormat)return 36244;if(p===RGFormat)return 33319;if(p===RGIntegerFormat)return 33320;if(p===RGBIntegerFormat)return 36248;if(p===RGBAIntegerFormat)return 36249;if(p===RGB_S3TC_DXT1_Format||p===RGBA_S3TC_DXT1_Format||p===RGBA_S3TC_DXT3_Format||p===RGBA_S3TC_DXT5_Format){extension=extensions.get('WEBGL_compressed_texture_s3tc');if(extension!==null){if(p===RGB_S3TC_DXT1_Format)return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;if(p===RGBA_S3TC_DXT1_Format)return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(p===RGBA_S3TC_DXT3_Format)return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(p===RGBA_S3TC_DXT5_Format)return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;}else {return null;}}if(p===RGB_PVRTC_4BPPV1_Format||p===RGB_PVRTC_2BPPV1_Format||p===RGBA_PVRTC_4BPPV1_Format||p===RGBA_PVRTC_2BPPV1_Format){extension=extensions.get('WEBGL_compressed_texture_pvrtc');if(extension!==null){if(p===RGB_PVRTC_4BPPV1_Format)return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(p===RGB_PVRTC_2BPPV1_Format)return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(p===RGBA_PVRTC_4BPPV1_Format)return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(p===RGBA_PVRTC_2BPPV1_Format)return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;}else {return null;}}if(p===RGB_ETC1_Format){extension=extensions.get('WEBGL_compressed_texture_etc1');if(extension!==null){return extension.COMPRESSED_RGB_ETC1_WEBGL;}else {return null;}}if(p===RGB_ETC2_Format||p===RGBA_ETC2_EAC_Format){extension=extensions.get('WEBGL_compressed_texture_etc');if(extension!==null){if(p===RGB_ETC2_Format)return extension.COMPRESSED_RGB8_ETC2;if(p===RGBA_ETC2_EAC_Format)return extension.COMPRESSED_RGBA8_ETC2_EAC;}}if(p===RGBA_ASTC_4x4_Format||p===RGBA_ASTC_5x4_Format||p===RGBA_ASTC_5x5_Format||p===RGBA_ASTC_6x5_Format||p===RGBA_ASTC_6x6_Format||p===RGBA_ASTC_8x5_Format||p===RGBA_ASTC_8x6_Format||p===RGBA_ASTC_8x8_Format||p===RGBA_ASTC_10x5_Format||p===RGBA_ASTC_10x6_Format||p===RGBA_ASTC_10x8_Format||p===RGBA_ASTC_10x10_Format||p===RGBA_ASTC_12x10_Format||p===RGBA_ASTC_12x12_Format||p===SRGB8_ALPHA8_ASTC_4x4_Format||p===SRGB8_ALPHA8_ASTC_5x4_Format||p===SRGB8_ALPHA8_ASTC_5x5_Format||p===SRGB8_ALPHA8_ASTC_6x5_Format||p===SRGB8_ALPHA8_ASTC_6x6_Format||p===SRGB8_ALPHA8_ASTC_8x5_Format||p===SRGB8_ALPHA8_ASTC_8x6_Format||p===SRGB8_ALPHA8_ASTC_8x8_Format||p===SRGB8_ALPHA8_ASTC_10x5_Format||p===SRGB8_ALPHA8_ASTC_10x6_Format||p===SRGB8_ALPHA8_ASTC_10x8_Format||p===SRGB8_ALPHA8_ASTC_10x10_Format||p===SRGB8_ALPHA8_ASTC_12x10_Format||p===SRGB8_ALPHA8_ASTC_12x12_Format){extension=extensions.get('WEBGL_compressed_texture_astc');if(extension!==null){// TODO Complete?
|
1480 | return p;}else {return null;}}if(p===RGBA_BPTC_Format){extension=extensions.get('EXT_texture_compression_bptc');if(extension!==null){// TODO Complete?
|
1481 | return p;}else {return null;}}if(p===UnsignedInt248Type){if(isWebGL2)return 34042;extension=extensions.get('WEBGL_depth_texture');if(extension!==null){return extension.UNSIGNED_INT_24_8_WEBGL;}else {return null;}}}return {convert:convert};}/**
|
1482 | * @author mrdoob / http://mrdoob.com/
|
1483 | */function ArrayCamera(array){PerspectiveCamera.call(this);this.cameras=array||[];}ArrayCamera.prototype=_extends(Object.create(PerspectiveCamera.prototype),{constructor:ArrayCamera,isArrayCamera:true});/**
|
1484 | * @author mrdoob / http://mrdoob.com/
|
1485 | */function Group(){Object3D.call(this);this.type='Group';}Group.prototype=_extends(Object.create(Object3D.prototype),{constructor:Group,isGroup:true});/**
|
1486 | * @author Mugen87 / https://github.com/Mugen87
|
1487 | */function WebXRController(){this._targetRay=null;this._grip=null;}_extends(WebXRController.prototype,{constructor:WebXRController,getTargetRaySpace:function getTargetRaySpace(){if(this._targetRay===null){this._targetRay=new Group();this._targetRay.matrixAutoUpdate=false;this._targetRay.visible=false;}return this._targetRay;},getGripSpace:function getGripSpace(){if(this._grip===null){this._grip=new Group();this._grip.matrixAutoUpdate=false;this._grip.visible=false;}return this._grip;},dispatchEvent:function dispatchEvent(event){if(this._targetRay!==null){this._targetRay.dispatchEvent(event);}if(this._grip!==null){this._grip.dispatchEvent(event);}return this;},disconnect:function disconnect(inputSource){this.dispatchEvent({type:'disconnected',data:inputSource});if(this._targetRay!==null){this._targetRay.visible=false;}if(this._grip!==null){this._grip.visible=false;}return this;},update:function update(inputSource,frame,referenceSpace){var inputPose=null;var gripPose=null;var targetRay=this._targetRay;var grip=this._grip;if(inputSource){if(targetRay!==null){inputPose=frame.getPose(inputSource.targetRaySpace,referenceSpace);if(inputPose!==null){targetRay.matrix.fromArray(inputPose.transform.matrix);targetRay.matrix.decompose(targetRay.position,targetRay.rotation,targetRay.scale);}}if(grip!==null&&inputSource.gripSpace){gripPose=frame.getPose(inputSource.gripSpace,referenceSpace);if(gripPose!==null){grip.matrix.fromArray(gripPose.transform.matrix);grip.matrix.decompose(grip.position,grip.rotation,grip.scale);}}}if(targetRay!==null){targetRay.visible=inputPose!==null;}if(grip!==null){grip.visible=gripPose!==null;}return this;}});/**
|
1488 | * @author mrdoob / http://mrdoob.com/
|
1489 | */function WebXRManager(renderer,gl){var scope=this;var session=null;var framebufferScaleFactor=1.0;var referenceSpace=null;var referenceSpaceType='local-floor';var pose=null;var controllers=[];var inputSourcesMap=new Map();//
|
1490 | var cameraL=new PerspectiveCamera();cameraL.layers.enable(1);cameraL.viewport=new Vector4();var cameraR=new PerspectiveCamera();cameraR.layers.enable(2);cameraR.viewport=new Vector4();var cameras=[cameraL,cameraR];var cameraVR=new ArrayCamera();cameraVR.layers.enable(1);cameraVR.layers.enable(2);var _currentDepthNear=null;var _currentDepthFar=null;//
|
1491 | this.enabled=false;this.isPresenting=false;this.getController=function(index){var controller=controllers[index];if(controller===undefined){controller=new WebXRController();controllers[index]=controller;}return controller.getTargetRaySpace();};this.getControllerGrip=function(index){var controller=controllers[index];if(controller===undefined){controller=new WebXRController();controllers[index]=controller;}return controller.getGripSpace();};//
|
1492 | function onSessionEvent(event){var controller=inputSourcesMap.get(event.inputSource);if(controller){controller.dispatchEvent({type:event.type});}}function onSessionEnd(){inputSourcesMap.forEach(function(controller,inputSource){controller.disconnect(inputSource);});inputSourcesMap.clear();//
|
1493 | renderer.setFramebuffer(null);renderer.setRenderTarget(renderer.getRenderTarget());// Hack #15830
|
1494 | animation.stop();scope.isPresenting=false;scope.dispatchEvent({type:'sessionend'});}function onRequestReferenceSpace(value){referenceSpace=value;animation.setContext(session);animation.start();scope.isPresenting=true;scope.dispatchEvent({type:'sessionstart'});}this.setFramebufferScaleFactor=function(value){framebufferScaleFactor=value;if(scope.isPresenting===true){console.warn('THREE.WebXRManager: Cannot change framebuffer scale while presenting.');}};this.setReferenceSpaceType=function(value){referenceSpaceType=value;if(scope.isPresenting===true){console.warn('THREE.WebXRManager: Cannot change reference space type while presenting.');}};this.getReferenceSpace=function(){return referenceSpace;};this.getSession=function(){return session;};this.setSession=function(value){session=value;if(session!==null){session.addEventListener('select',onSessionEvent);session.addEventListener('selectstart',onSessionEvent);session.addEventListener('selectend',onSessionEvent);session.addEventListener('squeeze',onSessionEvent);session.addEventListener('squeezestart',onSessionEvent);session.addEventListener('squeezeend',onSessionEvent);session.addEventListener('end',onSessionEnd);var attributes=gl.getContextAttributes();var layerInit={antialias:attributes.antialias,alpha:attributes.alpha,depth:attributes.depth,stencil:attributes.stencil,framebufferScaleFactor:framebufferScaleFactor};// eslint-disable-next-line no-undef
|
1495 | var baseLayer=new XRWebGLLayer(session,gl,layerInit);session.updateRenderState({baseLayer:baseLayer});session.requestReferenceSpace(referenceSpaceType).then(onRequestReferenceSpace);//
|
1496 | session.addEventListener('inputsourceschange',updateInputSources);}};function updateInputSources(event){var inputSources=session.inputSources;// Assign inputSources to available controllers
|
1497 | for(var i=0;i<controllers.length;i++){inputSourcesMap.set(inputSources[i],controllers[i]);}// Notify disconnected
|
1498 | for(var i=0;i<event.removed.length;i++){var inputSource=event.removed[i];var controller=inputSourcesMap.get(inputSource);if(controller){controller.dispatchEvent({type:'disconnected',data:inputSource});inputSourcesMap["delete"](inputSource);}}// Notify connected
|
1499 | for(var i=0;i<event.added.length;i++){var inputSource=event.added[i];var controller=inputSourcesMap.get(inputSource);if(controller){controller.dispatchEvent({type:'connected',data:inputSource});}}}//
|
1500 | var cameraLPos=new Vector3();var cameraRPos=new Vector3();/**
|
1501 | * @author jsantell / https://www.jsantell.com/
|
1502 | *
|
1503 | * Assumes 2 cameras that are parallel and share an X-axis, and that
|
1504 | * the cameras' projection and world matrices have already been set.
|
1505 | * And that near and far planes are identical for both cameras.
|
1506 | * Visualization of this technique: https://computergraphics.stackexchange.com/a/4765
|
1507 | */function setProjectionFromUnion(camera,cameraL,cameraR){cameraLPos.setFromMatrixPosition(cameraL.matrixWorld);cameraRPos.setFromMatrixPosition(cameraR.matrixWorld);var ipd=cameraLPos.distanceTo(cameraRPos);var projL=cameraL.projectionMatrix.elements;var projR=cameraR.projectionMatrix.elements;// VR systems will have identical far and near planes, and
|
1508 | // most likely identical top and bottom frustum extents.
|
1509 | // Use the left camera for these values.
|
1510 | var near=projL[14]/(projL[10]-1);var far=projL[14]/(projL[10]+1);var topFov=(projL[9]+1)/projL[5];var bottomFov=(projL[9]-1)/projL[5];var leftFov=(projL[8]-1)/projL[0];var rightFov=(projR[8]+1)/projR[0];var left=near*leftFov;var right=near*rightFov;// Calculate the new camera's position offset from the
|
1511 | // left camera. xOffset should be roughly half `ipd`.
|
1512 | var zOffset=ipd/(-leftFov+rightFov);var xOffset=zOffset*-leftFov;// TODO: Better way to apply this offset?
|
1513 | cameraL.matrixWorld.decompose(camera.position,camera.quaternion,camera.scale);camera.translateX(xOffset);camera.translateZ(zOffset);camera.matrixWorld.compose(camera.position,camera.quaternion,camera.scale);camera.matrixWorldInverse.getInverse(camera.matrixWorld);// Find the union of the frustum values of the cameras and scale
|
1514 | // the values so that the near plane's position does not change in world space,
|
1515 | // although must now be relative to the new union camera.
|
1516 | var near2=near+zOffset;var far2=far+zOffset;var left2=left-xOffset;var right2=right+(ipd-xOffset);var top2=topFov*far/far2*near2;var bottom2=bottomFov*far/far2*near2;camera.projectionMatrix.makePerspective(left2,right2,top2,bottom2,near2,far2);}function updateCamera(camera,parent){if(parent===null){camera.matrixWorld.copy(camera.matrix);}else {camera.matrixWorld.multiplyMatrices(parent.matrixWorld,camera.matrix);}camera.matrixWorldInverse.getInverse(camera.matrixWorld);}this.getCamera=function(camera){cameraVR.near=cameraR.near=cameraL.near=camera.near;cameraVR.far=cameraR.far=cameraL.far=camera.far;if(_currentDepthNear!==cameraVR.near||_currentDepthFar!==cameraVR.far){// Note that the new renderState won't apply until the next frame. See #18320
|
1517 | session.updateRenderState({depthNear:cameraVR.near,depthFar:cameraVR.far});_currentDepthNear=cameraVR.near;_currentDepthFar=cameraVR.far;}var parent=camera.parent;var cameras=cameraVR.cameras;updateCamera(cameraVR,parent);for(var i=0;i<cameras.length;i++){updateCamera(cameras[i],parent);}// update camera and its children
|
1518 | camera.matrixWorld.copy(cameraVR.matrixWorld);var children=camera.children;for(var i=0,l=children.length;i<l;i++){children[i].updateMatrixWorld(true);}// update projection matrix for proper view frustum culling
|
1519 | if(cameras.length===2){setProjectionFromUnion(cameraVR,cameraL,cameraR);}else {// assume single camera setup (AR)
|
1520 | cameraVR.projectionMatrix.copy(cameraL.projectionMatrix);}return cameraVR;};// Animation Loop
|
1521 | var onAnimationFrameCallback=null;function onAnimationFrame(time,frame){pose=frame.getViewerPose(referenceSpace);if(pose!==null){var views=pose.views;var baseLayer=session.renderState.baseLayer;renderer.setFramebuffer(baseLayer.framebuffer);var cameraVRNeedsUpdate=false;// check if it's necessary to rebuild cameraVR's camera list
|
1522 | if(views.length!==cameraVR.cameras.length){cameraVR.cameras.length=0;cameraVRNeedsUpdate=true;}for(var i=0;i<views.length;i++){var view=views[i];var viewport=baseLayer.getViewport(view);var camera=cameras[i];camera.matrix.fromArray(view.transform.matrix);camera.projectionMatrix.fromArray(view.projectionMatrix);camera.viewport.set(viewport.x,viewport.y,viewport.width,viewport.height);if(i===0){cameraVR.matrix.copy(camera.matrix);}if(cameraVRNeedsUpdate===true){cameraVR.cameras.push(camera);}}}//
|
1523 | var inputSources=session.inputSources;for(var i=0;i<controllers.length;i++){var controller=controllers[i];var inputSource=inputSources[i];controller.update(inputSource,frame,referenceSpace);}if(onAnimationFrameCallback)onAnimationFrameCallback(time,frame);}var animation=new WebGLAnimation();animation.setAnimationLoop(onAnimationFrame);this.setAnimationLoop=function(callback){onAnimationFrameCallback=callback;};this.dispose=function(){};}_extends(WebXRManager.prototype,EventDispatcher.prototype);/**
|
1524 | * @author supereggbert / http://www.paulbrunt.co.uk/
|
1525 | * @author mrdoob / http://mrdoob.com/
|
1526 | * @author alteredq / http://alteredqualia.com/
|
1527 | * @author szimek / https://github.com/szimek/
|
1528 | * @author tschw
|
1529 | */function WebGLRenderer(parameters){parameters=parameters||{};var _canvas=parameters.canvas!==undefined?parameters.canvas:document.createElementNS('http://www.w3.org/1999/xhtml','canvas'),_context=parameters.context!==undefined?parameters.context:null,_alpha=parameters.alpha!==undefined?parameters.alpha:false,_depth=parameters.depth!==undefined?parameters.depth:true,_stencil=parameters.stencil!==undefined?parameters.stencil:true,_antialias=parameters.antialias!==undefined?parameters.antialias:false,_premultipliedAlpha=parameters.premultipliedAlpha!==undefined?parameters.premultipliedAlpha:true,_preserveDrawingBuffer=parameters.preserveDrawingBuffer!==undefined?parameters.preserveDrawingBuffer:false,_powerPreference=parameters.powerPreference!==undefined?parameters.powerPreference:'default',_failIfMajorPerformanceCaveat=parameters.failIfMajorPerformanceCaveat!==undefined?parameters.failIfMajorPerformanceCaveat:false;var currentRenderList=null;var currentRenderState=null;// public properties
|
1530 | this.domElement=_canvas;// Debug configuration container
|
1531 | this.debug={/**
|
1532 | * Enables error checking and reporting when shader programs are being compiled
|
1533 | * @type {boolean}
|
1534 | */checkShaderErrors:true};// clearing
|
1535 | this.autoClear=true;this.autoClearColor=true;this.autoClearDepth=true;this.autoClearStencil=true;// scene graph
|
1536 | this.sortObjects=true;// user-defined clipping
|
1537 | this.clippingPlanes=[];this.localClippingEnabled=false;// physically based shading
|
1538 | this.gammaFactor=2.0;// for backwards compatibility
|
1539 | this.outputEncoding=LinearEncoding;// physical lights
|
1540 | this.physicallyCorrectLights=false;// tone mapping
|
1541 | this.toneMapping=NoToneMapping;this.toneMappingExposure=1.0;this.toneMappingWhitePoint=1.0;// morphs
|
1542 | this.maxMorphTargets=8;this.maxMorphNormals=4;// internal properties
|
1543 | var _this=this,_isContextLost=false,// internal state cache
|
1544 | _framebuffer=null,_currentActiveCubeFace=0,_currentActiveMipmapLevel=0,_currentRenderTarget=null,_currentFramebuffer=null,_currentMaterialId=-1,// geometry and program caching
|
1545 | _currentGeometryProgram={geometry:null,program:null,wireframe:false},_currentCamera=null,_currentArrayCamera=null,_currentViewport=new Vector4(),_currentScissor=new Vector4(),_currentScissorTest=null,//
|
1546 | _width=_canvas.width,_height=_canvas.height,_pixelRatio=1,_opaqueSort=null,_transparentSort=null,_viewport=new Vector4(0,0,_width,_height),_scissor=new Vector4(0,0,_width,_height),_scissorTest=false,// frustum
|
1547 | _frustum=new Frustum(),// clipping
|
1548 | _clipping=new WebGLClipping(),_clippingEnabled=false,_localClippingEnabled=false,// camera matrices cache
|
1549 | _projScreenMatrix=new Matrix4(),_vector3=new Vector3();function getTargetPixelRatio(){return _currentRenderTarget===null?_pixelRatio:1;}// initialize
|
1550 | var _gl;try{var contextAttributes={alpha:_alpha,depth:_depth,stencil:_stencil,antialias:_antialias,premultipliedAlpha:_premultipliedAlpha,preserveDrawingBuffer:_preserveDrawingBuffer,powerPreference:_powerPreference,failIfMajorPerformanceCaveat:_failIfMajorPerformanceCaveat,xrCompatible:true};// event listeners must be registered before WebGL context is created, see #12753
|
1551 | _canvas.addEventListener('webglcontextlost',onContextLost,false);_canvas.addEventListener('webglcontextrestored',onContextRestore,false);_gl=_context||_canvas.getContext('webgl',contextAttributes)||_canvas.getContext('experimental-webgl',contextAttributes);if(_gl===null){if(_canvas.getContext('webgl')!==null){throw new Error('Error creating WebGL context with your selected attributes.');}else {throw new Error('Error creating WebGL context.');}}// Some experimental-webgl implementations do not have getShaderPrecisionFormat
|
1552 | if(_gl.getShaderPrecisionFormat===undefined){_gl.getShaderPrecisionFormat=function(){return {'rangeMin':1,'rangeMax':1,'precision':1};};}}catch(error){console.error('THREE.WebGLRenderer: '+error.message);throw error;}var extensions,capabilities,state,info;var properties,textures,attributes,geometries,objects;var programCache,renderLists,renderStates;var background,morphtargets,bufferRenderer,indexedBufferRenderer;var utils;function initGLContext(){extensions=new WebGLExtensions(_gl);capabilities=new WebGLCapabilities(_gl,extensions,parameters);if(capabilities.isWebGL2===false){extensions.get('WEBGL_depth_texture');extensions.get('OES_texture_float');extensions.get('OES_texture_half_float');extensions.get('OES_texture_half_float_linear');extensions.get('OES_standard_derivatives');extensions.get('OES_element_index_uint');extensions.get('ANGLE_instanced_arrays');}extensions.get('OES_texture_float_linear');utils=new WebGLUtils(_gl,extensions,capabilities);state=new WebGLState(_gl,extensions,capabilities);state.scissor(_currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor());state.viewport(_currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor());info=new WebGLInfo(_gl);properties=new WebGLProperties();textures=new WebGLTextures(_gl,extensions,state,properties,capabilities,utils,info);attributes=new WebGLAttributes(_gl,capabilities);geometries=new WebGLGeometries(_gl,attributes,info);objects=new WebGLObjects(_gl,geometries,attributes,info);morphtargets=new WebGLMorphtargets(_gl);programCache=new WebGLPrograms(_this,extensions,capabilities);renderLists=new WebGLRenderLists();renderStates=new WebGLRenderStates();background=new WebGLBackground(_this,state,objects,_premultipliedAlpha);bufferRenderer=new WebGLBufferRenderer(_gl,extensions,info,capabilities);indexedBufferRenderer=new WebGLIndexedBufferRenderer(_gl,extensions,info,capabilities);info.programs=programCache.programs;_this.capabilities=capabilities;_this.extensions=extensions;_this.properties=properties;_this.renderLists=renderLists;_this.state=state;_this.info=info;}initGLContext();// xr
|
1553 | var xr=new WebXRManager(_this,_gl);this.xr=xr;// shadow map
|
1554 | var shadowMap=new WebGLShadowMap(_this,objects,capabilities.maxTextureSize);this.shadowMap=shadowMap;// API
|
1555 | this.getContext=function(){return _gl;};this.getContextAttributes=function(){return _gl.getContextAttributes();};this.forceContextLoss=function(){var extension=extensions.get('WEBGL_lose_context');if(extension)extension.loseContext();};this.forceContextRestore=function(){var extension=extensions.get('WEBGL_lose_context');if(extension)extension.restoreContext();};this.getPixelRatio=function(){return _pixelRatio;};this.setPixelRatio=function(value){if(value===undefined)return;_pixelRatio=value;this.setSize(_width,_height,false);};this.getSize=function(target){if(target===undefined){console.warn('WebGLRenderer: .getsize() now requires a Vector2 as an argument');target=new Vector2();}return target.set(_width,_height);};this.setSize=function(width,height,updateStyle){if(xr.isPresenting){console.warn('THREE.WebGLRenderer: Can\'t change size while VR device is presenting.');return;}_width=width;_height=height;_canvas.width=Math.floor(width*_pixelRatio);_canvas.height=Math.floor(height*_pixelRatio);if(updateStyle!==false){_canvas.style.width=width+'px';_canvas.style.height=height+'px';}this.setViewport(0,0,width,height);};this.getDrawingBufferSize=function(target){if(target===undefined){console.warn('WebGLRenderer: .getdrawingBufferSize() now requires a Vector2 as an argument');target=new Vector2();}return target.set(_width*_pixelRatio,_height*_pixelRatio).floor();};this.setDrawingBufferSize=function(width,height,pixelRatio){_width=width;_height=height;_pixelRatio=pixelRatio;_canvas.width=Math.floor(width*pixelRatio);_canvas.height=Math.floor(height*pixelRatio);this.setViewport(0,0,width,height);};this.getCurrentViewport=function(target){if(target===undefined){console.warn('WebGLRenderer: .getCurrentViewport() now requires a Vector4 as an argument');target=new Vector4();}return target.copy(_currentViewport);};this.getViewport=function(target){return target.copy(_viewport);};this.setViewport=function(x,y,width,height){if(x.isVector4){_viewport.set(x.x,x.y,x.z,x.w);}else {_viewport.set(x,y,width,height);}state.viewport(_currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor());};this.getScissor=function(target){return target.copy(_scissor);};this.setScissor=function(x,y,width,height){if(x.isVector4){_scissor.set(x.x,x.y,x.z,x.w);}else {_scissor.set(x,y,width,height);}state.scissor(_currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor());};this.getScissorTest=function(){return _scissorTest;};this.setScissorTest=function(_boolean){state.setScissorTest(_scissorTest=_boolean);};this.setOpaqueSort=function(method){_opaqueSort=method;};this.setTransparentSort=function(method){_transparentSort=method;};// Clearing
|
1556 | this.getClearColor=function(){return background.getClearColor();};this.setClearColor=function(){background.setClearColor.apply(background,arguments);};this.getClearAlpha=function(){return background.getClearAlpha();};this.setClearAlpha=function(){background.setClearAlpha.apply(background,arguments);};this.clear=function(color,depth,stencil){var bits=0;if(color===undefined||color)bits|=16384;if(depth===undefined||depth)bits|=256;if(stencil===undefined||stencil)bits|=1024;_gl.clear(bits);};this.clearColor=function(){this.clear(true,false,false);};this.clearDepth=function(){this.clear(false,true,false);};this.clearStencil=function(){this.clear(false,false,true);};//
|
1557 | this.dispose=function(){_canvas.removeEventListener('webglcontextlost',onContextLost,false);_canvas.removeEventListener('webglcontextrestored',onContextRestore,false);renderLists.dispose();renderStates.dispose();properties.dispose();objects.dispose();xr.dispose();animation.stop();};// Events
|
1558 | function onContextLost(event){event.preventDefault();console.log('THREE.WebGLRenderer: Context Lost.');_isContextLost=true;}function onContextRestore()/* event */{console.log('THREE.WebGLRenderer: Context Restored.');_isContextLost=false;initGLContext();}function onMaterialDispose(event){var material=event.target;material.removeEventListener('dispose',onMaterialDispose);deallocateMaterial(material);}// Buffer deallocation
|
1559 | function deallocateMaterial(material){releaseMaterialProgramReference(material);properties.remove(material);}function releaseMaterialProgramReference(material){var programInfo=properties.get(material).program;material.program=undefined;if(programInfo!==undefined){programCache.releaseProgram(programInfo);}}// Buffer rendering
|
1560 | function renderObjectImmediate(object,program){object.render(function(object){_this.renderBufferImmediate(object,program);});}this.renderBufferImmediate=function(object,program){state.initAttributes();var buffers=properties.get(object);if(object.hasPositions&&!buffers.position)buffers.position=_gl.createBuffer();if(object.hasNormals&&!buffers.normal)buffers.normal=_gl.createBuffer();if(object.hasUvs&&!buffers.uv)buffers.uv=_gl.createBuffer();if(object.hasColors&&!buffers.color)buffers.color=_gl.createBuffer();var programAttributes=program.getAttributes();if(object.hasPositions){_gl.bindBuffer(34962,buffers.position);_gl.bufferData(34962,object.positionArray,35048);state.enableAttribute(programAttributes.position);_gl.vertexAttribPointer(programAttributes.position,3,5126,false,0,0);}if(object.hasNormals){_gl.bindBuffer(34962,buffers.normal);_gl.bufferData(34962,object.normalArray,35048);state.enableAttribute(programAttributes.normal);_gl.vertexAttribPointer(programAttributes.normal,3,5126,false,0,0);}if(object.hasUvs){_gl.bindBuffer(34962,buffers.uv);_gl.bufferData(34962,object.uvArray,35048);state.enableAttribute(programAttributes.uv);_gl.vertexAttribPointer(programAttributes.uv,2,5126,false,0,0);}if(object.hasColors){_gl.bindBuffer(34962,buffers.color);_gl.bufferData(34962,object.colorArray,35048);state.enableAttribute(programAttributes.color);_gl.vertexAttribPointer(programAttributes.color,3,5126,false,0,0);}state.disableUnusedAttributes();_gl.drawArrays(4,0,object.count);object.count=0;};var tempScene=new Scene();this.renderBufferDirect=function(camera,scene,geometry,material,object,group){if(scene===null)scene=tempScene;// renderBufferDirect second parameter used to be fog (could be null)
|
1561 | var frontFaceCW=object.isMesh&&object.matrixWorld.determinant()<0;var program=setProgram(camera,scene,material,object);state.setMaterial(material,frontFaceCW);var updateBuffers=false;if(_currentGeometryProgram.geometry!==geometry.id||_currentGeometryProgram.program!==program.id||_currentGeometryProgram.wireframe!==(material.wireframe===true)){_currentGeometryProgram.geometry=geometry.id;_currentGeometryProgram.program=program.id;_currentGeometryProgram.wireframe=material.wireframe===true;updateBuffers=true;}if(material.morphTargets||material.morphNormals){morphtargets.update(object,geometry,material,program);updateBuffers=true;}if(object.isInstancedMesh===true){updateBuffers=true;}//
|
1562 | var index=geometry.index;var position=geometry.attributes.position;//
|
1563 | if(index===null){if(position===undefined||position.count===0)return;}else if(index.count===0){return;}//
|
1564 | var rangeFactor=1;if(material.wireframe===true){index=geometries.getWireframeAttribute(geometry);rangeFactor=2;}var attribute;var renderer=bufferRenderer;if(index!==null){attribute=attributes.get(index);renderer=indexedBufferRenderer;renderer.setIndex(attribute);}if(updateBuffers){setupVertexAttributes(object,geometry,material,program);if(index!==null){_gl.bindBuffer(34963,attribute.buffer);}}//
|
1565 | var dataCount=index!==null?index.count:position.count;var rangeStart=geometry.drawRange.start*rangeFactor;var rangeCount=geometry.drawRange.count*rangeFactor;var groupStart=group!==null?group.start*rangeFactor:0;var groupCount=group!==null?group.count*rangeFactor:Infinity;var drawStart=Math.max(rangeStart,groupStart);var drawEnd=Math.min(dataCount,rangeStart+rangeCount,groupStart+groupCount)-1;var drawCount=Math.max(0,drawEnd-drawStart+1);if(drawCount===0)return;//
|
1566 | if(object.isMesh){if(material.wireframe===true){state.setLineWidth(material.wireframeLinewidth*getTargetPixelRatio());renderer.setMode(1);}else {renderer.setMode(4);}}else if(object.isLine){var lineWidth=material.linewidth;if(lineWidth===undefined)lineWidth=1;// Not using Line*Material
|
1567 | state.setLineWidth(lineWidth*getTargetPixelRatio());if(object.isLineSegments){renderer.setMode(1);}else if(object.isLineLoop){renderer.setMode(2);}else {renderer.setMode(3);}}else if(object.isPoints){renderer.setMode(0);}else if(object.isSprite){renderer.setMode(4);}if(object.isInstancedMesh){renderer.renderInstances(geometry,drawStart,drawCount,object.count);}else if(geometry.isInstancedBufferGeometry){renderer.renderInstances(geometry,drawStart,drawCount,geometry.maxInstancedCount);}else {renderer.render(drawStart,drawCount);}};function setupVertexAttributes(object,geometry,material,program){if(capabilities.isWebGL2===false&&(object.isInstancedMesh||geometry.isInstancedBufferGeometry)){if(extensions.get('ANGLE_instanced_arrays')===null)return;}state.initAttributes();var geometryAttributes=geometry.attributes;var programAttributes=program.getAttributes();var materialDefaultAttributeValues=material.defaultAttributeValues;for(var name in programAttributes){var programAttribute=programAttributes[name];if(programAttribute>=0){var geometryAttribute=geometryAttributes[name];if(geometryAttribute!==undefined){var normalized=geometryAttribute.normalized;var size=geometryAttribute.itemSize;var attribute=attributes.get(geometryAttribute);// TODO Attribute may not be available on context restore
|
1568 | if(attribute===undefined)continue;var buffer=attribute.buffer;var type=attribute.type;var bytesPerElement=attribute.bytesPerElement;if(geometryAttribute.isInterleavedBufferAttribute){var data=geometryAttribute.data;var stride=data.stride;var offset=geometryAttribute.offset;if(data&&data.isInstancedInterleavedBuffer){state.enableAttributeAndDivisor(programAttribute,data.meshPerAttribute);if(geometry.maxInstancedCount===undefined){geometry.maxInstancedCount=data.meshPerAttribute*data.count;}}else {state.enableAttribute(programAttribute);}_gl.bindBuffer(34962,buffer);state.vertexAttribPointer(programAttribute,size,type,normalized,stride*bytesPerElement,offset*bytesPerElement);}else {if(geometryAttribute.isInstancedBufferAttribute){state.enableAttributeAndDivisor(programAttribute,geometryAttribute.meshPerAttribute);if(geometry.maxInstancedCount===undefined){geometry.maxInstancedCount=geometryAttribute.meshPerAttribute*geometryAttribute.count;}}else {state.enableAttribute(programAttribute);}_gl.bindBuffer(34962,buffer);state.vertexAttribPointer(programAttribute,size,type,normalized,0,0);}}else if(name==='instanceMatrix'){var attribute=attributes.get(object.instanceMatrix);// TODO Attribute may not be available on context restore
|
1569 | if(attribute===undefined)continue;var buffer=attribute.buffer;var type=attribute.type;state.enableAttributeAndDivisor(programAttribute+0,1);state.enableAttributeAndDivisor(programAttribute+1,1);state.enableAttributeAndDivisor(programAttribute+2,1);state.enableAttributeAndDivisor(programAttribute+3,1);_gl.bindBuffer(34962,buffer);_gl.vertexAttribPointer(programAttribute+0,4,type,false,64,0);_gl.vertexAttribPointer(programAttribute+1,4,type,false,64,16);_gl.vertexAttribPointer(programAttribute+2,4,type,false,64,32);_gl.vertexAttribPointer(programAttribute+3,4,type,false,64,48);}else if(materialDefaultAttributeValues!==undefined){var value=materialDefaultAttributeValues[name];if(value!==undefined){switch(value.length){case 2:_gl.vertexAttrib2fv(programAttribute,value);break;case 3:_gl.vertexAttrib3fv(programAttribute,value);break;case 4:_gl.vertexAttrib4fv(programAttribute,value);break;default:_gl.vertexAttrib1fv(programAttribute,value);}}}}}state.disableUnusedAttributes();}// Compile
|
1570 | this.compile=function(scene,camera){currentRenderState=renderStates.get(scene,camera);currentRenderState.init();scene.traverse(function(object){if(object.isLight){currentRenderState.pushLight(object);if(object.castShadow){currentRenderState.pushShadow(object);}}});currentRenderState.setupLights(camera);var compiled={};scene.traverse(function(object){if(object.material){if(Array.isArray(object.material)){for(var i=0;i<object.material.length;i++){if(object.material[i].uuid in compiled===false){initMaterial(object.material[i],scene,object);compiled[object.material[i].uuid]=true;}}}else if(object.material.uuid in compiled===false){initMaterial(object.material,scene,object);compiled[object.material.uuid]=true;}}});};// Animation Loop
|
1571 | var onAnimationFrameCallback=null;function onAnimationFrame(time){if(xr.isPresenting)return;if(onAnimationFrameCallback)onAnimationFrameCallback(time);}var animation=new WebGLAnimation();animation.setAnimationLoop(onAnimationFrame);if(typeof window!=='undefined')animation.setContext(window);this.setAnimationLoop=function(callback){onAnimationFrameCallback=callback;xr.setAnimationLoop(callback);animation.start();};// Rendering
|
1572 | this.render=function(scene,camera){var renderTarget,forceClear;if(arguments[2]!==undefined){console.warn('THREE.WebGLRenderer.render(): the renderTarget argument has been removed. Use .setRenderTarget() instead.');renderTarget=arguments[2];}if(arguments[3]!==undefined){console.warn('THREE.WebGLRenderer.render(): the forceClear argument has been removed. Use .clear() instead.');forceClear=arguments[3];}if(!(camera&&camera.isCamera)){console.error('THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.');return;}if(_isContextLost)return;// reset caching for this frame
|
1573 | _currentGeometryProgram.geometry=null;_currentGeometryProgram.program=null;_currentGeometryProgram.wireframe=false;_currentMaterialId=-1;_currentCamera=null;// update scene graph
|
1574 | if(scene.autoUpdate===true)scene.updateMatrixWorld();// update camera matrices and frustum
|
1575 | if(camera.parent===null)camera.updateMatrixWorld();if(xr.enabled&&xr.isPresenting){camera=xr.getCamera(camera);}//
|
1576 | scene.onBeforeRender(_this,scene,camera,renderTarget||_currentRenderTarget);currentRenderState=renderStates.get(scene,camera);currentRenderState.init();_projScreenMatrix.multiplyMatrices(camera.projectionMatrix,camera.matrixWorldInverse);_frustum.setFromProjectionMatrix(_projScreenMatrix);_localClippingEnabled=this.localClippingEnabled;_clippingEnabled=_clipping.init(this.clippingPlanes,_localClippingEnabled,camera);currentRenderList=renderLists.get(scene,camera);currentRenderList.init();projectObject(scene,camera,0,_this.sortObjects);currentRenderList.finish();if(_this.sortObjects===true){currentRenderList.sort(_opaqueSort,_transparentSort);}//
|
1577 | if(_clippingEnabled)_clipping.beginShadows();var shadowsArray=currentRenderState.state.shadowsArray;shadowMap.render(shadowsArray,scene,camera);currentRenderState.setupLights(camera);if(_clippingEnabled)_clipping.endShadows();//
|
1578 | if(this.info.autoReset)this.info.reset();if(renderTarget!==undefined){this.setRenderTarget(renderTarget);}//
|
1579 | background.render(currentRenderList,scene,camera,forceClear);// render scene
|
1580 | var opaqueObjects=currentRenderList.opaque;var transparentObjects=currentRenderList.transparent;if(scene.overrideMaterial){var overrideMaterial=scene.overrideMaterial;if(opaqueObjects.length)renderObjects(opaqueObjects,scene,camera,overrideMaterial);if(transparentObjects.length)renderObjects(transparentObjects,scene,camera,overrideMaterial);}else {// opaque pass (front-to-back order)
|
1581 | if(opaqueObjects.length)renderObjects(opaqueObjects,scene,camera);// transparent pass (back-to-front order)
|
1582 | if(transparentObjects.length)renderObjects(transparentObjects,scene,camera);}//
|
1583 | scene.onAfterRender(_this,scene,camera);//
|
1584 | if(_currentRenderTarget!==null){// Generate mipmap if we're using any kind of mipmap filtering
|
1585 | textures.updateRenderTargetMipmap(_currentRenderTarget);// resolve multisample renderbuffers to a single-sample texture if necessary
|
1586 | textures.updateMultisampleRenderTarget(_currentRenderTarget);}// Ensure depth buffer writing is enabled so it can be cleared on next render
|
1587 | state.buffers.depth.setTest(true);state.buffers.depth.setMask(true);state.buffers.color.setMask(true);state.setPolygonOffset(false);// _gl.finish();
|
1588 | currentRenderList=null;currentRenderState=null;};function projectObject(object,camera,groupOrder,sortObjects){if(object.visible===false)return;var visible=object.layers.test(camera.layers);if(visible){if(object.isGroup){groupOrder=object.renderOrder;}else if(object.isLOD){if(object.autoUpdate===true)object.update(camera);}else if(object.isLight){currentRenderState.pushLight(object);if(object.castShadow){currentRenderState.pushShadow(object);}}else if(object.isSprite){if(!object.frustumCulled||_frustum.intersectsSprite(object)){if(sortObjects){_vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);}var geometry=objects.update(object);var material=object.material;if(material.visible){currentRenderList.push(object,geometry,material,groupOrder,_vector3.z,null);}}}else if(object.isImmediateRenderObject){if(sortObjects){_vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);}currentRenderList.push(object,null,object.material,groupOrder,_vector3.z,null);}else if(object.isMesh||object.isLine||object.isPoints){if(object.isSkinnedMesh){// update skeleton only once in a frame
|
1589 | if(object.skeleton.frame!==info.render.frame){object.skeleton.update();object.skeleton.frame=info.render.frame;}}if(!object.frustumCulled||_frustum.intersectsObject(object)){if(sortObjects){_vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix);}var geometry=objects.update(object);var material=object.material;if(Array.isArray(material)){var groups=geometry.groups;for(var i=0,l=groups.length;i<l;i++){var group=groups[i];var groupMaterial=material[group.materialIndex];if(groupMaterial&&groupMaterial.visible){currentRenderList.push(object,geometry,groupMaterial,groupOrder,_vector3.z,group);}}}else if(material.visible){currentRenderList.push(object,geometry,material,groupOrder,_vector3.z,null);}}}}var children=object.children;for(var i=0,l=children.length;i<l;i++){projectObject(children[i],camera,groupOrder,sortObjects);}}function renderObjects(renderList,scene,camera,overrideMaterial){for(var i=0,l=renderList.length;i<l;i++){var renderItem=renderList[i];var object=renderItem.object;var geometry=renderItem.geometry;var material=overrideMaterial===undefined?renderItem.material:overrideMaterial;var group=renderItem.group;if(camera.isArrayCamera){_currentArrayCamera=camera;var cameras=camera.cameras;for(var j=0,jl=cameras.length;j<jl;j++){var camera2=cameras[j];if(object.layers.test(camera2.layers)){state.viewport(_currentViewport.copy(camera2.viewport));currentRenderState.setupLights(camera2);renderObject(object,scene,camera2,geometry,material,group);}}}else {_currentArrayCamera=null;renderObject(object,scene,camera,geometry,material,group);}}}function renderObject(object,scene,camera,geometry,material,group){object.onBeforeRender(_this,scene,camera,geometry,material,group);currentRenderState=renderStates.get(scene,_currentArrayCamera||camera);object.modelViewMatrix.multiplyMatrices(camera.matrixWorldInverse,object.matrixWorld);object.normalMatrix.getNormalMatrix(object.modelViewMatrix);if(object.isImmediateRenderObject){var program=setProgram(camera,scene,material,object);state.setMaterial(material);_currentGeometryProgram.geometry=null;_currentGeometryProgram.program=null;_currentGeometryProgram.wireframe=false;renderObjectImmediate(object,program);}else {_this.renderBufferDirect(camera,scene,geometry,material,object,group);}object.onAfterRender(_this,scene,camera,geometry,material,group);currentRenderState=renderStates.get(scene,_currentArrayCamera||camera);}function initMaterial(material,scene,object){var materialProperties=properties.get(material);var lights=currentRenderState.state.lights;var shadowsArray=currentRenderState.state.shadowsArray;var lightsStateVersion=lights.state.version;var parameters=programCache.getParameters(material,lights.state,shadowsArray,scene,_clipping.numPlanes,_clipping.numIntersection,object);var programCacheKey=programCache.getProgramCacheKey(parameters);var program=materialProperties.program;var programChange=true;if(program===undefined){// new material
|
1590 | material.addEventListener('dispose',onMaterialDispose);}else if(program.cacheKey!==programCacheKey){// changed glsl or parameters
|
1591 | releaseMaterialProgramReference(material);}else if(materialProperties.lightsStateVersion!==lightsStateVersion){materialProperties.lightsStateVersion=lightsStateVersion;programChange=false;}else if(parameters.shaderID!==undefined){// same glsl and uniform list
|
1592 | return;}else {// only rebuild uniform list
|
1593 | programChange=false;}if(programChange){program=programCache.acquireProgram(parameters,programCacheKey);materialProperties.program=program;materialProperties.uniforms=parameters.uniforms;materialProperties.outputEncoding=parameters.outputEncoding;material.program=program;}var programAttributes=program.getAttributes();if(material.morphTargets){material.numSupportedMorphTargets=0;for(var i=0;i<_this.maxMorphTargets;i++){if(programAttributes['morphTarget'+i]>=0){material.numSupportedMorphTargets++;}}}if(material.morphNormals){material.numSupportedMorphNormals=0;for(var i=0;i<_this.maxMorphNormals;i++){if(programAttributes['morphNormal'+i]>=0){material.numSupportedMorphNormals++;}}}var uniforms=materialProperties.uniforms;if(!material.isShaderMaterial&&!material.isRawShaderMaterial||material.clipping===true){materialProperties.numClippingPlanes=_clipping.numPlanes;materialProperties.numIntersection=_clipping.numIntersection;uniforms.clippingPlanes=_clipping.uniform;}materialProperties.environment=material.isMeshStandardMaterial?scene.environment:null;materialProperties.fog=scene.fog;// store the light setup it was created for
|
1594 | materialProperties.needsLights=materialNeedsLights(material);materialProperties.lightsStateVersion=lightsStateVersion;if(materialProperties.needsLights){// wire up the material to this renderer's lighting state
|
1595 | uniforms.ambientLightColor.value=lights.state.ambient;uniforms.lightProbe.value=lights.state.probe;uniforms.directionalLights.value=lights.state.directional;uniforms.directionalLightShadows.value=lights.state.directionalShadow;uniforms.spotLights.value=lights.state.spot;uniforms.spotLightShadows.value=lights.state.spotShadow;uniforms.rectAreaLights.value=lights.state.rectArea;uniforms.pointLights.value=lights.state.point;uniforms.pointLightShadows.value=lights.state.pointShadow;uniforms.hemisphereLights.value=lights.state.hemi;uniforms.directionalShadowMap.value=lights.state.directionalShadowMap;uniforms.directionalShadowMatrix.value=lights.state.directionalShadowMatrix;uniforms.spotShadowMap.value=lights.state.spotShadowMap;uniforms.spotShadowMatrix.value=lights.state.spotShadowMatrix;uniforms.pointShadowMap.value=lights.state.pointShadowMap;uniforms.pointShadowMatrix.value=lights.state.pointShadowMatrix;// TODO (abelnation): add area lights shadow info to uniforms
|
1596 | }var progUniforms=materialProperties.program.getUniforms(),uniformsList=WebGLUniforms.seqWithValue(progUniforms.seq,uniforms);materialProperties.uniformsList=uniformsList;}function setProgram(camera,scene,material,object){textures.resetTextureUnits();var fog=scene.fog;var environment=material.isMeshStandardMaterial?scene.environment:null;var encoding=_currentRenderTarget===null?_this.outputEncoding:_currentRenderTarget.texture.encoding;var materialProperties=properties.get(material);var lights=currentRenderState.state.lights;if(_clippingEnabled){if(_localClippingEnabled||camera!==_currentCamera){var useCache=camera===_currentCamera&&material.id===_currentMaterialId;// we might want to call this function with some ClippingGroup
|
1597 | // object instead of the material, once it becomes feasible
|
1598 | // (#8465, #8379)
|
1599 | _clipping.setState(material.clippingPlanes,material.clipIntersection,material.clipShadows,camera,materialProperties,useCache);}}if(material.version===materialProperties.__version){if(materialProperties.program===undefined){initMaterial(material,scene,object);}else if(material.fog&&materialProperties.fog!==fog){initMaterial(material,scene,object);}else if(materialProperties.environment!==environment){initMaterial(material,scene,object);}else if(materialProperties.needsLights&&materialProperties.lightsStateVersion!==lights.state.version){initMaterial(material,scene,object);}else if(materialProperties.numClippingPlanes!==undefined&&(materialProperties.numClippingPlanes!==_clipping.numPlanes||materialProperties.numIntersection!==_clipping.numIntersection)){initMaterial(material,scene,object);}else if(materialProperties.outputEncoding!==encoding){initMaterial(material,scene,object);}}else {initMaterial(material,scene,object);materialProperties.__version=material.version;}var refreshProgram=false;var refreshMaterial=false;var refreshLights=false;var program=materialProperties.program,p_uniforms=program.getUniforms(),m_uniforms=materialProperties.uniforms;if(state.useProgram(program.program)){refreshProgram=true;refreshMaterial=true;refreshLights=true;}if(material.id!==_currentMaterialId){_currentMaterialId=material.id;refreshMaterial=true;}if(refreshProgram||_currentCamera!==camera){p_uniforms.setValue(_gl,'projectionMatrix',camera.projectionMatrix);if(capabilities.logarithmicDepthBuffer){p_uniforms.setValue(_gl,'logDepthBufFC',2.0/(Math.log(camera.far+1.0)/Math.LN2));}if(_currentCamera!==camera){_currentCamera=camera;// lighting uniforms depend on the camera so enforce an update
|
1600 | // now, in case this material supports lights - or later, when
|
1601 | // the next material that does gets activated:
|
1602 | refreshMaterial=true;// set to true on material change
|
1603 | refreshLights=true;// remains set until update done
|
1604 | }// load material specific uniforms
|
1605 | // (shader material also gets them for the sake of genericity)
|
1606 | if(material.isShaderMaterial||material.isMeshPhongMaterial||material.isMeshToonMaterial||material.isMeshStandardMaterial||material.envMap){var uCamPos=p_uniforms.map.cameraPosition;if(uCamPos!==undefined){uCamPos.setValue(_gl,_vector3.setFromMatrixPosition(camera.matrixWorld));}}if(material.isMeshPhongMaterial||material.isMeshToonMaterial||material.isMeshLambertMaterial||material.isMeshBasicMaterial||material.isMeshStandardMaterial||material.isShaderMaterial){p_uniforms.setValue(_gl,'isOrthographic',camera.isOrthographicCamera===true);}if(material.isMeshPhongMaterial||material.isMeshToonMaterial||material.isMeshLambertMaterial||material.isMeshBasicMaterial||material.isMeshStandardMaterial||material.isShaderMaterial||material.skinning){p_uniforms.setValue(_gl,'viewMatrix',camera.matrixWorldInverse);}}// skinning uniforms must be set even if material didn't change
|
1607 | // auto-setting of texture unit for bone texture must go before other textures
|
1608 | // otherwise textures used for skinning can take over texture units reserved for other material textures
|
1609 | if(material.skinning){p_uniforms.setOptional(_gl,object,'bindMatrix');p_uniforms.setOptional(_gl,object,'bindMatrixInverse');var skeleton=object.skeleton;if(skeleton){var bones=skeleton.bones;if(capabilities.floatVertexTextures){if(skeleton.boneTexture===undefined){// layout (1 matrix = 4 pixels)
|
1610 | // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
|
1611 | // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
|
1612 | // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
|
1613 | // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
|
1614 | // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
|
1615 | var size=Math.sqrt(bones.length*4);// 4 pixels needed for 1 matrix
|
1616 | size=MathUtils.ceilPowerOfTwo(size);size=Math.max(size,4);var boneMatrices=new Float32Array(size*size*4);// 4 floats per RGBA pixel
|
1617 | boneMatrices.set(skeleton.boneMatrices);// copy current values
|
1618 | var boneTexture=new DataTexture(boneMatrices,size,size,RGBAFormat,FloatType);skeleton.boneMatrices=boneMatrices;skeleton.boneTexture=boneTexture;skeleton.boneTextureSize=size;}p_uniforms.setValue(_gl,'boneTexture',skeleton.boneTexture,textures);p_uniforms.setValue(_gl,'boneTextureSize',skeleton.boneTextureSize);}else {p_uniforms.setOptional(_gl,skeleton,'boneMatrices');}}}if(refreshMaterial||materialProperties.receiveShadow!==object.receiveShadow){materialProperties.receiveShadow=object.receiveShadow;p_uniforms.setValue(_gl,'receiveShadow',object.receiveShadow);}if(refreshMaterial){p_uniforms.setValue(_gl,'toneMappingExposure',_this.toneMappingExposure);p_uniforms.setValue(_gl,'toneMappingWhitePoint',_this.toneMappingWhitePoint);if(materialProperties.needsLights){// the current material requires lighting info
|
1619 | // note: all lighting uniforms are always set correctly
|
1620 | // they simply reference the renderer's state for their
|
1621 | // values
|
1622 | //
|
1623 | // use the current material's .needsUpdate flags to set
|
1624 | // the GL state when required
|
1625 | markUniformsLightsNeedsUpdate(m_uniforms,refreshLights);}// refresh uniforms common to several materials
|
1626 | if(fog&&material.fog){refreshUniformsFog(m_uniforms,fog);}if(material.isMeshBasicMaterial){refreshUniformsCommon(m_uniforms,material);}else if(material.isMeshLambertMaterial){refreshUniformsCommon(m_uniforms,material);refreshUniformsLambert(m_uniforms,material);}else if(material.isMeshToonMaterial){refreshUniformsCommon(m_uniforms,material);refreshUniformsToon(m_uniforms,material);}else if(material.isMeshPhongMaterial){refreshUniformsCommon(m_uniforms,material);refreshUniformsPhong(m_uniforms,material);}else if(material.isMeshStandardMaterial){refreshUniformsCommon(m_uniforms,material,environment);if(material.isMeshPhysicalMaterial){refreshUniformsPhysical(m_uniforms,material,environment);}else {refreshUniformsStandard(m_uniforms,material,environment);}}else if(material.isMeshMatcapMaterial){refreshUniformsCommon(m_uniforms,material);refreshUniformsMatcap(m_uniforms,material);}else if(material.isMeshDepthMaterial){refreshUniformsCommon(m_uniforms,material);refreshUniformsDepth(m_uniforms,material);}else if(material.isMeshDistanceMaterial){refreshUniformsCommon(m_uniforms,material);refreshUniformsDistance(m_uniforms,material);}else if(material.isMeshNormalMaterial){refreshUniformsCommon(m_uniforms,material);refreshUniformsNormal(m_uniforms,material);}else if(material.isLineBasicMaterial){refreshUniformsLine(m_uniforms,material);if(material.isLineDashedMaterial){refreshUniformsDash(m_uniforms,material);}}else if(material.isPointsMaterial){refreshUniformsPoints(m_uniforms,material);}else if(material.isSpriteMaterial){refreshUniformsSprites(m_uniforms,material);}else if(material.isShadowMaterial){m_uniforms.color.value.copy(material.color);m_uniforms.opacity.value=material.opacity;}// RectAreaLight Texture
|
1627 | // TODO (mrdoob): Find a nicer implementation
|
1628 | if(m_uniforms.ltc_1!==undefined)m_uniforms.ltc_1.value=UniformsLib.LTC_1;if(m_uniforms.ltc_2!==undefined)m_uniforms.ltc_2.value=UniformsLib.LTC_2;WebGLUniforms.upload(_gl,materialProperties.uniformsList,m_uniforms,textures);if(material.isShaderMaterial){material.uniformsNeedUpdate=false;// #15581
|
1629 | }}if(material.isShaderMaterial&&material.uniformsNeedUpdate===true){WebGLUniforms.upload(_gl,materialProperties.uniformsList,m_uniforms,textures);material.uniformsNeedUpdate=false;}if(material.isSpriteMaterial){p_uniforms.setValue(_gl,'center',object.center);}// common matrices
|
1630 | p_uniforms.setValue(_gl,'modelViewMatrix',object.modelViewMatrix);p_uniforms.setValue(_gl,'normalMatrix',object.normalMatrix);p_uniforms.setValue(_gl,'modelMatrix',object.matrixWorld);return program;}// Uniforms (refresh uniforms objects)
|
1631 | function refreshUniformsCommon(uniforms,material,environment){uniforms.opacity.value=material.opacity;if(material.color){uniforms.diffuse.value.copy(material.color);}if(material.emissive){uniforms.emissive.value.copy(material.emissive).multiplyScalar(material.emissiveIntensity);}if(material.map){uniforms.map.value=material.map;}if(material.alphaMap){uniforms.alphaMap.value=material.alphaMap;}if(material.specularMap){uniforms.specularMap.value=material.specularMap;}var envMap=material.envMap||environment;if(envMap){uniforms.envMap.value=envMap;uniforms.flipEnvMap.value=envMap.isCubeTexture?-1:1;uniforms.reflectivity.value=material.reflectivity;uniforms.refractionRatio.value=material.refractionRatio;uniforms.maxMipLevel.value=properties.get(envMap).__maxMipLevel;}if(material.lightMap){uniforms.lightMap.value=material.lightMap;uniforms.lightMapIntensity.value=material.lightMapIntensity;}if(material.aoMap){uniforms.aoMap.value=material.aoMap;uniforms.aoMapIntensity.value=material.aoMapIntensity;}// uv repeat and offset setting priorities
|
1632 | // 1. color map
|
1633 | // 2. specular map
|
1634 | // 3. normal map
|
1635 | // 4. bump map
|
1636 | // 5. alpha map
|
1637 | // 6. emissive map
|
1638 | var uvScaleMap;if(material.map){uvScaleMap=material.map;}else if(material.specularMap){uvScaleMap=material.specularMap;}else if(material.displacementMap){uvScaleMap=material.displacementMap;}else if(material.normalMap){uvScaleMap=material.normalMap;}else if(material.bumpMap){uvScaleMap=material.bumpMap;}else if(material.roughnessMap){uvScaleMap=material.roughnessMap;}else if(material.metalnessMap){uvScaleMap=material.metalnessMap;}else if(material.alphaMap){uvScaleMap=material.alphaMap;}else if(material.emissiveMap){uvScaleMap=material.emissiveMap;}if(uvScaleMap!==undefined){// backwards compatibility
|
1639 | if(uvScaleMap.isWebGLRenderTarget){uvScaleMap=uvScaleMap.texture;}if(uvScaleMap.matrixAutoUpdate===true){uvScaleMap.updateMatrix();}uniforms.uvTransform.value.copy(uvScaleMap.matrix);}// uv repeat and offset setting priorities for uv2
|
1640 | // 1. ao map
|
1641 | // 2. light map
|
1642 | var uv2ScaleMap;if(material.aoMap){uv2ScaleMap=material.aoMap;}else if(material.lightMap){uv2ScaleMap=material.lightMap;}if(uv2ScaleMap!==undefined){// backwards compatibility
|
1643 | if(uv2ScaleMap.isWebGLRenderTarget){uv2ScaleMap=uv2ScaleMap.texture;}if(uv2ScaleMap.matrixAutoUpdate===true){uv2ScaleMap.updateMatrix();}uniforms.uv2Transform.value.copy(uv2ScaleMap.matrix);}}function refreshUniformsLine(uniforms,material){uniforms.diffuse.value.copy(material.color);uniforms.opacity.value=material.opacity;}function refreshUniformsDash(uniforms,material){uniforms.dashSize.value=material.dashSize;uniforms.totalSize.value=material.dashSize+material.gapSize;uniforms.scale.value=material.scale;}function refreshUniformsPoints(uniforms,material){uniforms.diffuse.value.copy(material.color);uniforms.opacity.value=material.opacity;uniforms.size.value=material.size*_pixelRatio;uniforms.scale.value=_height*0.5;if(material.map){uniforms.map.value=material.map;}if(material.alphaMap){uniforms.alphaMap.value=material.alphaMap;}// uv repeat and offset setting priorities
|
1644 | // 1. color map
|
1645 | // 2. alpha map
|
1646 | var uvScaleMap;if(material.map){uvScaleMap=material.map;}else if(material.alphaMap){uvScaleMap=material.alphaMap;}if(uvScaleMap!==undefined){if(uvScaleMap.matrixAutoUpdate===true){uvScaleMap.updateMatrix();}uniforms.uvTransform.value.copy(uvScaleMap.matrix);}}function refreshUniformsSprites(uniforms,material){uniforms.diffuse.value.copy(material.color);uniforms.opacity.value=material.opacity;uniforms.rotation.value=material.rotation;if(material.map){uniforms.map.value=material.map;}if(material.alphaMap){uniforms.alphaMap.value=material.alphaMap;}// uv repeat and offset setting priorities
|
1647 | // 1. color map
|
1648 | // 2. alpha map
|
1649 | var uvScaleMap;if(material.map){uvScaleMap=material.map;}else if(material.alphaMap){uvScaleMap=material.alphaMap;}if(uvScaleMap!==undefined){if(uvScaleMap.matrixAutoUpdate===true){uvScaleMap.updateMatrix();}uniforms.uvTransform.value.copy(uvScaleMap.matrix);}}function refreshUniformsFog(uniforms,fog){uniforms.fogColor.value.copy(fog.color);if(fog.isFog){uniforms.fogNear.value=fog.near;uniforms.fogFar.value=fog.far;}else if(fog.isFogExp2){uniforms.fogDensity.value=fog.density;}}function refreshUniformsLambert(uniforms,material){if(material.emissiveMap){uniforms.emissiveMap.value=material.emissiveMap;}}function refreshUniformsPhong(uniforms,material){uniforms.specular.value.copy(material.specular);uniforms.shininess.value=Math.max(material.shininess,1e-4);// to prevent pow( 0.0, 0.0 )
|
1650 | if(material.emissiveMap){uniforms.emissiveMap.value=material.emissiveMap;}if(material.bumpMap){uniforms.bumpMap.value=material.bumpMap;uniforms.bumpScale.value=material.bumpScale;if(material.side===BackSide)uniforms.bumpScale.value*=-1;}if(material.normalMap){uniforms.normalMap.value=material.normalMap;uniforms.normalScale.value.copy(material.normalScale);if(material.side===BackSide)uniforms.normalScale.value.negate();}if(material.displacementMap){uniforms.displacementMap.value=material.displacementMap;uniforms.displacementScale.value=material.displacementScale;uniforms.displacementBias.value=material.displacementBias;}}function refreshUniformsToon(uniforms,material){uniforms.specular.value.copy(material.specular);uniforms.shininess.value=Math.max(material.shininess,1e-4);// to prevent pow( 0.0, 0.0 )
|
1651 | if(material.gradientMap){uniforms.gradientMap.value=material.gradientMap;}if(material.emissiveMap){uniforms.emissiveMap.value=material.emissiveMap;}if(material.bumpMap){uniforms.bumpMap.value=material.bumpMap;uniforms.bumpScale.value=material.bumpScale;if(material.side===BackSide)uniforms.bumpScale.value*=-1;}if(material.normalMap){uniforms.normalMap.value=material.normalMap;uniforms.normalScale.value.copy(material.normalScale);if(material.side===BackSide)uniforms.normalScale.value.negate();}if(material.displacementMap){uniforms.displacementMap.value=material.displacementMap;uniforms.displacementScale.value=material.displacementScale;uniforms.displacementBias.value=material.displacementBias;}}function refreshUniformsStandard(uniforms,material,environment){uniforms.roughness.value=material.roughness;uniforms.metalness.value=material.metalness;if(material.roughnessMap){uniforms.roughnessMap.value=material.roughnessMap;}if(material.metalnessMap){uniforms.metalnessMap.value=material.metalnessMap;}if(material.emissiveMap){uniforms.emissiveMap.value=material.emissiveMap;}if(material.bumpMap){uniforms.bumpMap.value=material.bumpMap;uniforms.bumpScale.value=material.bumpScale;if(material.side===BackSide)uniforms.bumpScale.value*=-1;}if(material.normalMap){uniforms.normalMap.value=material.normalMap;uniforms.normalScale.value.copy(material.normalScale);if(material.side===BackSide)uniforms.normalScale.value.negate();}if(material.displacementMap){uniforms.displacementMap.value=material.displacementMap;uniforms.displacementScale.value=material.displacementScale;uniforms.displacementBias.value=material.displacementBias;}if(material.envMap||environment){//uniforms.envMap.value = material.envMap; // part of uniforms common
|
1652 | uniforms.envMapIntensity.value=material.envMapIntensity;}}function refreshUniformsPhysical(uniforms,material,environment){refreshUniformsStandard(uniforms,material,environment);uniforms.reflectivity.value=material.reflectivity;// also part of uniforms common
|
1653 | uniforms.clearcoat.value=material.clearcoat;uniforms.clearcoatRoughness.value=material.clearcoatRoughness;if(material.sheen)uniforms.sheen.value.copy(material.sheen);if(material.clearcoatMap){uniforms.clearcoatMap.value=material.clearcoatMap;}if(material.clearcoatRoughnessMap){uniforms.clearcoatRoughnessMap.value=material.clearcoatRoughnessMap;}if(material.clearcoatNormalMap){uniforms.clearcoatNormalScale.value.copy(material.clearcoatNormalScale);uniforms.clearcoatNormalMap.value=material.clearcoatNormalMap;if(material.side===BackSide){uniforms.clearcoatNormalScale.value.negate();}}uniforms.transparency.value=material.transparency;}function refreshUniformsMatcap(uniforms,material){if(material.matcap){uniforms.matcap.value=material.matcap;}if(material.bumpMap){uniforms.bumpMap.value=material.bumpMap;uniforms.bumpScale.value=material.bumpScale;if(material.side===BackSide)uniforms.bumpScale.value*=-1;}if(material.normalMap){uniforms.normalMap.value=material.normalMap;uniforms.normalScale.value.copy(material.normalScale);if(material.side===BackSide)uniforms.normalScale.value.negate();}if(material.displacementMap){uniforms.displacementMap.value=material.displacementMap;uniforms.displacementScale.value=material.displacementScale;uniforms.displacementBias.value=material.displacementBias;}}function refreshUniformsDepth(uniforms,material){if(material.displacementMap){uniforms.displacementMap.value=material.displacementMap;uniforms.displacementScale.value=material.displacementScale;uniforms.displacementBias.value=material.displacementBias;}}function refreshUniformsDistance(uniforms,material){if(material.displacementMap){uniforms.displacementMap.value=material.displacementMap;uniforms.displacementScale.value=material.displacementScale;uniforms.displacementBias.value=material.displacementBias;}uniforms.referencePosition.value.copy(material.referencePosition);uniforms.nearDistance.value=material.nearDistance;uniforms.farDistance.value=material.farDistance;}function refreshUniformsNormal(uniforms,material){if(material.bumpMap){uniforms.bumpMap.value=material.bumpMap;uniforms.bumpScale.value=material.bumpScale;if(material.side===BackSide)uniforms.bumpScale.value*=-1;}if(material.normalMap){uniforms.normalMap.value=material.normalMap;uniforms.normalScale.value.copy(material.normalScale);if(material.side===BackSide)uniforms.normalScale.value.negate();}if(material.displacementMap){uniforms.displacementMap.value=material.displacementMap;uniforms.displacementScale.value=material.displacementScale;uniforms.displacementBias.value=material.displacementBias;}}// If uniforms are marked as clean, they don't need to be loaded to the GPU.
|
1654 | function markUniformsLightsNeedsUpdate(uniforms,value){uniforms.ambientLightColor.needsUpdate=value;uniforms.lightProbe.needsUpdate=value;uniforms.directionalLights.needsUpdate=value;uniforms.directionalLightShadows.needsUpdate=value;uniforms.pointLights.needsUpdate=value;uniforms.pointLightShadows.needsUpdate=value;uniforms.spotLights.needsUpdate=value;uniforms.spotLightShadows.needsUpdate=value;uniforms.rectAreaLights.needsUpdate=value;uniforms.hemisphereLights.needsUpdate=value;}function materialNeedsLights(material){return material.isMeshLambertMaterial||material.isMeshToonMaterial||material.isMeshPhongMaterial||material.isMeshStandardMaterial||material.isShadowMaterial||material.isShaderMaterial&&material.lights===true;}//
|
1655 | this.setFramebuffer=function(value){if(_framebuffer!==value&&_currentRenderTarget===null)_gl.bindFramebuffer(36160,value);_framebuffer=value;};this.getActiveCubeFace=function(){return _currentActiveCubeFace;};this.getActiveMipmapLevel=function(){return _currentActiveMipmapLevel;};this.getRenderTarget=function(){return _currentRenderTarget;};this.setRenderTarget=function(renderTarget,activeCubeFace,activeMipmapLevel){_currentRenderTarget=renderTarget;_currentActiveCubeFace=activeCubeFace;_currentActiveMipmapLevel=activeMipmapLevel;if(renderTarget&&properties.get(renderTarget).__webglFramebuffer===undefined){textures.setupRenderTarget(renderTarget);}var framebuffer=_framebuffer;var isCube=false;if(renderTarget){var __webglFramebuffer=properties.get(renderTarget).__webglFramebuffer;if(renderTarget.isWebGLCubeRenderTarget){framebuffer=__webglFramebuffer[activeCubeFace||0];isCube=true;}else if(renderTarget.isWebGLMultisampleRenderTarget){framebuffer=properties.get(renderTarget).__webglMultisampledFramebuffer;}else {framebuffer=__webglFramebuffer;}_currentViewport.copy(renderTarget.viewport);_currentScissor.copy(renderTarget.scissor);_currentScissorTest=renderTarget.scissorTest;}else {_currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor();_currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor();_currentScissorTest=_scissorTest;}if(_currentFramebuffer!==framebuffer){_gl.bindFramebuffer(36160,framebuffer);_currentFramebuffer=framebuffer;}state.viewport(_currentViewport);state.scissor(_currentScissor);state.setScissorTest(_currentScissorTest);if(isCube){var textureProperties=properties.get(renderTarget.texture);_gl.framebufferTexture2D(36160,36064,34069+(activeCubeFace||0),textureProperties.__webglTexture,activeMipmapLevel||0);}};this.readRenderTargetPixels=function(renderTarget,x,y,width,height,buffer,activeCubeFaceIndex){if(!(renderTarget&&renderTarget.isWebGLRenderTarget)){console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.');return;}var framebuffer=properties.get(renderTarget).__webglFramebuffer;if(renderTarget.isWebGLCubeRenderTarget&&activeCubeFaceIndex!==undefined){framebuffer=framebuffer[activeCubeFaceIndex];}if(framebuffer){var restore=false;if(framebuffer!==_currentFramebuffer){_gl.bindFramebuffer(36160,framebuffer);restore=true;}try{var texture=renderTarget.texture;var textureFormat=texture.format;var textureType=texture.type;if(textureFormat!==RGBAFormat&&utils.convert(textureFormat)!==_gl.getParameter(35739)){console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.');return;}if(textureType!==UnsignedByteType&&utils.convert(textureType)!==_gl.getParameter(35738)&&// IE11, Edge and Chrome Mac < 52 (#9513)
|
1656 | !(textureType===FloatType&&(capabilities.isWebGL2||extensions.get('OES_texture_float')||extensions.get('WEBGL_color_buffer_float')))&&// Chrome Mac >= 52 and Firefox
|
1657 | !(textureType===HalfFloatType&&(capabilities.isWebGL2?extensions.get('EXT_color_buffer_float'):extensions.get('EXT_color_buffer_half_float')))){console.error('THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.');return;}if(_gl.checkFramebufferStatus(36160)===36053){// the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
|
1658 | if(x>=0&&x<=renderTarget.width-width&&y>=0&&y<=renderTarget.height-height){_gl.readPixels(x,y,width,height,utils.convert(textureFormat),utils.convert(textureType),buffer);}}else {console.error('THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.');}}finally{if(restore){_gl.bindFramebuffer(36160,_currentFramebuffer);}}}};this.copyFramebufferToTexture=function(position,texture,level){if(level===undefined)level=0;var levelScale=Math.pow(2,-level);var width=Math.floor(texture.image.width*levelScale);var height=Math.floor(texture.image.height*levelScale);var glFormat=utils.convert(texture.format);textures.setTexture2D(texture,0);_gl.copyTexImage2D(3553,level,glFormat,position.x,position.y,width,height,0);state.unbindTexture();};this.copyTextureToTexture=function(position,srcTexture,dstTexture,level){if(level===undefined)level=0;var width=srcTexture.image.width;var height=srcTexture.image.height;var glFormat=utils.convert(dstTexture.format);var glType=utils.convert(dstTexture.type);textures.setTexture2D(dstTexture,0);if(srcTexture.isDataTexture){_gl.texSubImage2D(3553,level,position.x,position.y,width,height,glFormat,glType,srcTexture.image.data);}else {if(srcTexture.isCompressedTexture){_gl.compressedTexSubImage2D(3553,level,position.x,position.y,srcTexture.mipmaps[0].width,srcTexture.mipmaps[0].height,glFormat,srcTexture.mipmaps[0].data);}else {_gl.texSubImage2D(3553,level,position.x,position.y,glFormat,glType,srcTexture.image);}}// Generate mipmaps only when copying level 0
|
1659 | if(level===0&&dstTexture.generateMipmaps)_gl.generateMipmap(3553);state.unbindTexture();};this.initTexture=function(texture){textures.setTexture2D(texture,0);state.unbindTexture();};if(typeof __THREE_DEVTOOLS__!=='undefined'){__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('observe',{detail:this}));// eslint-disable-line no-undef
|
1660 | }}/**
|
1661 | * @author mrdoob / http://mrdoob.com/
|
1662 | * @author alteredq / http://alteredqualia.com/
|
1663 | */function FogExp2(color,density){this.name='';this.color=new Color(color);this.density=density!==undefined?density:0.00025;}_extends(FogExp2.prototype,{isFogExp2:true,clone:function clone(){return new FogExp2(this.color,this.density);},toJSON:function toJSON()/* meta */{return {type:'FogExp2',color:this.color.getHex(),density:this.density};}});/**
|
1664 | * @author mrdoob / http://mrdoob.com/
|
1665 | * @author alteredq / http://alteredqualia.com/
|
1666 | */function Fog(color,near,far){this.name='';this.color=new Color(color);this.near=near!==undefined?near:1;this.far=far!==undefined?far:1000;}_extends(Fog.prototype,{isFog:true,clone:function clone(){return new Fog(this.color,this.near,this.far);},toJSON:function toJSON()/* meta */{return {type:'Fog',color:this.color.getHex(),near:this.near,far:this.far};}});/**
|
1667 | * @author benaadams / https://twitter.com/ben_a_adams
|
1668 | */function InterleavedBuffer(array,stride){this.array=array;this.stride=stride;this.count=array!==undefined?array.length/stride:0;this.usage=StaticDrawUsage;this.updateRange={offset:0,count:-1};this.version=0;}Object.defineProperty(InterleavedBuffer.prototype,'needsUpdate',{set:function set(value){if(value===true)this.version++;}});_extends(InterleavedBuffer.prototype,{isInterleavedBuffer:true,onUploadCallback:function onUploadCallback(){},setUsage:function setUsage(value){this.usage=value;return this;},copy:function copy(source){this.array=new source.array.constructor(source.array);this.count=source.count;this.stride=source.stride;this.usage=source.usage;return this;},copyAt:function copyAt(index1,attribute,index2){index1*=this.stride;index2*=attribute.stride;for(var i=0,l=this.stride;i<l;i++){this.array[index1+i]=attribute.array[index2+i];}return this;},set:function set(value,offset){if(offset===undefined)offset=0;this.array.set(value,offset);return this;},clone:function clone(){return new this.constructor().copy(this);},onUpload:function onUpload(callback){this.onUploadCallback=callback;return this;}});/**
|
1669 | * @author benaadams / https://twitter.com/ben_a_adams
|
1670 | */var _vector$6=new Vector3();function InterleavedBufferAttribute(interleavedBuffer,itemSize,offset,normalized){this.data=interleavedBuffer;this.itemSize=itemSize;this.offset=offset;this.normalized=normalized===true;}Object.defineProperties(InterleavedBufferAttribute.prototype,{count:{get:function get(){return this.data.count;}},array:{get:function get(){return this.data.array;}}});_extends(InterleavedBufferAttribute.prototype,{isInterleavedBufferAttribute:true,applyMatrix4:function applyMatrix4(m){for(var i=0,l=this.data.count;i<l;i++){_vector$6.x=this.getX(i);_vector$6.y=this.getY(i);_vector$6.z=this.getZ(i);_vector$6.applyMatrix4(m);this.setXYZ(i,_vector$6.x,_vector$6.y,_vector$6.z);}return this;},setX:function setX(index,x){this.data.array[index*this.data.stride+this.offset]=x;return this;},setY:function setY(index,y){this.data.array[index*this.data.stride+this.offset+1]=y;return this;},setZ:function setZ(index,z){this.data.array[index*this.data.stride+this.offset+2]=z;return this;},setW:function setW(index,w){this.data.array[index*this.data.stride+this.offset+3]=w;return this;},getX:function getX(index){return this.data.array[index*this.data.stride+this.offset];},getY:function getY(index){return this.data.array[index*this.data.stride+this.offset+1];},getZ:function getZ(index){return this.data.array[index*this.data.stride+this.offset+2];},getW:function getW(index){return this.data.array[index*this.data.stride+this.offset+3];},setXY:function setXY(index,x,y){index=index*this.data.stride+this.offset;this.data.array[index+0]=x;this.data.array[index+1]=y;return this;},setXYZ:function setXYZ(index,x,y,z){index=index*this.data.stride+this.offset;this.data.array[index+0]=x;this.data.array[index+1]=y;this.data.array[index+2]=z;return this;},setXYZW:function setXYZW(index,x,y,z,w){index=index*this.data.stride+this.offset;this.data.array[index+0]=x;this.data.array[index+1]=y;this.data.array[index+2]=z;this.data.array[index+3]=w;return this;}});/**
|
1671 | * @author alteredq / http://alteredqualia.com/
|
1672 | *
|
1673 | * parameters = {
|
1674 | * color: <hex>,
|
1675 | * map: new THREE.Texture( <Image> ),
|
1676 | * alphaMap: new THREE.Texture( <Image> ),
|
1677 | * rotation: <float>,
|
1678 | * sizeAttenuation: <bool>
|
1679 | * }
|
1680 | */function SpriteMaterial(parameters){Material.call(this);this.type='SpriteMaterial';this.color=new Color(0xffffff);this.map=null;this.alphaMap=null;this.rotation=0;this.sizeAttenuation=true;this.transparent=true;this.setValues(parameters);}SpriteMaterial.prototype=Object.create(Material.prototype);SpriteMaterial.prototype.constructor=SpriteMaterial;SpriteMaterial.prototype.isSpriteMaterial=true;SpriteMaterial.prototype.copy=function(source){Material.prototype.copy.call(this,source);this.color.copy(source.color);this.map=source.map;this.alphaMap=source.alphaMap;this.rotation=source.rotation;this.sizeAttenuation=source.sizeAttenuation;return this;};/**
|
1681 | * @author mikael emtinger / http://gomo.se/
|
1682 | * @author alteredq / http://alteredqualia.com/
|
1683 | */var _geometry;var _intersectPoint=new Vector3();var _worldScale=new Vector3();var _mvPosition=new Vector3();var _alignedPosition=new Vector2();var _rotatedPosition=new Vector2();var _viewWorldMatrix=new Matrix4();var _vA$1=new Vector3();var _vB$1=new Vector3();var _vC$1=new Vector3();var _uvA$1=new Vector2();var _uvB$1=new Vector2();var _uvC$1=new Vector2();function Sprite(material){Object3D.call(this);this.type='Sprite';if(_geometry===undefined){_geometry=new BufferGeometry();var float32Array=new Float32Array([-0.5,-0.5,0,0,0,0.5,-0.5,0,1,0,0.5,0.5,0,1,1,-0.5,0.5,0,0,1]);var interleavedBuffer=new InterleavedBuffer(float32Array,5);_geometry.setIndex([0,1,2,0,2,3]);_geometry.setAttribute('position',new InterleavedBufferAttribute(interleavedBuffer,3,0,false));_geometry.setAttribute('uv',new InterleavedBufferAttribute(interleavedBuffer,2,3,false));}this.geometry=_geometry;this.material=material!==undefined?material:new SpriteMaterial();this.center=new Vector2(0.5,0.5);}Sprite.prototype=_extends(Object.create(Object3D.prototype),{constructor:Sprite,isSprite:true,raycast:function raycast(raycaster,intersects){if(raycaster.camera===null){console.error('THREE.Sprite: "Raycaster.camera" needs to be set in order to raycast against sprites.');}_worldScale.setFromMatrixScale(this.matrixWorld);_viewWorldMatrix.copy(raycaster.camera.matrixWorld);this.modelViewMatrix.multiplyMatrices(raycaster.camera.matrixWorldInverse,this.matrixWorld);_mvPosition.setFromMatrixPosition(this.modelViewMatrix);if(raycaster.camera.isPerspectiveCamera&&this.material.sizeAttenuation===false){_worldScale.multiplyScalar(-_mvPosition.z);}var rotation=this.material.rotation;var sin,cos;if(rotation!==0){cos=Math.cos(rotation);sin=Math.sin(rotation);}var center=this.center;transformVertex(_vA$1.set(-0.5,-0.5,0),_mvPosition,center,_worldScale,sin,cos);transformVertex(_vB$1.set(0.5,-0.5,0),_mvPosition,center,_worldScale,sin,cos);transformVertex(_vC$1.set(0.5,0.5,0),_mvPosition,center,_worldScale,sin,cos);_uvA$1.set(0,0);_uvB$1.set(1,0);_uvC$1.set(1,1);// check first triangle
|
1684 | var intersect=raycaster.ray.intersectTriangle(_vA$1,_vB$1,_vC$1,false,_intersectPoint);if(intersect===null){// check second triangle
|
1685 | transformVertex(_vB$1.set(-0.5,0.5,0),_mvPosition,center,_worldScale,sin,cos);_uvB$1.set(0,1);intersect=raycaster.ray.intersectTriangle(_vA$1,_vC$1,_vB$1,false,_intersectPoint);if(intersect===null){return;}}var distance=raycaster.ray.origin.distanceTo(_intersectPoint);if(distance<raycaster.near||distance>raycaster.far)return;intersects.push({distance:distance,point:_intersectPoint.clone(),uv:Triangle.getUV(_intersectPoint,_vA$1,_vB$1,_vC$1,_uvA$1,_uvB$1,_uvC$1,new Vector2()),face:null,object:this});},clone:function clone(){return new this.constructor(this.material).copy(this);},copy:function copy(source){Object3D.prototype.copy.call(this,source);if(source.center!==undefined)this.center.copy(source.center);return this;}});function transformVertex(vertexPosition,mvPosition,center,scale,sin,cos){// compute position in camera space
|
1686 | _alignedPosition.subVectors(vertexPosition,center).addScalar(0.5).multiply(scale);// to check if rotation is not zero
|
1687 | if(sin!==undefined){_rotatedPosition.x=cos*_alignedPosition.x-sin*_alignedPosition.y;_rotatedPosition.y=sin*_alignedPosition.x+cos*_alignedPosition.y;}else {_rotatedPosition.copy(_alignedPosition);}vertexPosition.copy(mvPosition);vertexPosition.x+=_rotatedPosition.x;vertexPosition.y+=_rotatedPosition.y;// transform to world space
|
1688 | vertexPosition.applyMatrix4(_viewWorldMatrix);}/**
|
1689 | * @author mikael emtinger / http://gomo.se/
|
1690 | * @author alteredq / http://alteredqualia.com/
|
1691 | * @author mrdoob / http://mrdoob.com/
|
1692 | */var _v1$4=new Vector3();var _v2$2=new Vector3();function LOD(){Object3D.call(this);this._currentLevel=0;this.type='LOD';Object.defineProperties(this,{levels:{enumerable:true,value:[]}});this.autoUpdate=true;}LOD.prototype=_extends(Object.create(Object3D.prototype),{constructor:LOD,isLOD:true,copy:function copy(source){Object3D.prototype.copy.call(this,source,false);var levels=source.levels;for(var i=0,l=levels.length;i<l;i++){var level=levels[i];this.addLevel(level.object.clone(),level.distance);}this.autoUpdate=source.autoUpdate;return this;},addLevel:function addLevel(object,distance){if(distance===undefined)distance=0;distance=Math.abs(distance);var levels=this.levels;for(var l=0;l<levels.length;l++){if(distance<levels[l].distance){break;}}levels.splice(l,0,{distance:distance,object:object});this.add(object);return this;},getCurrentLevel:function getCurrentLevel(){return this._currentLevel;},getObjectForDistance:function getObjectForDistance(distance){var levels=this.levels;if(levels.length>0){for(var i=1,l=levels.length;i<l;i++){if(distance<levels[i].distance){break;}}return levels[i-1].object;}return null;},raycast:function raycast(raycaster,intersects){var levels=this.levels;if(levels.length>0){_v1$4.setFromMatrixPosition(this.matrixWorld);var distance=raycaster.ray.origin.distanceTo(_v1$4);this.getObjectForDistance(distance).raycast(raycaster,intersects);}},update:function update(camera){var levels=this.levels;if(levels.length>1){_v1$4.setFromMatrixPosition(camera.matrixWorld);_v2$2.setFromMatrixPosition(this.matrixWorld);var distance=_v1$4.distanceTo(_v2$2)/camera.zoom;levels[0].object.visible=true;for(var i=1,l=levels.length;i<l;i++){if(distance>=levels[i].distance){levels[i-1].object.visible=false;levels[i].object.visible=true;}else {break;}}this._currentLevel=i-1;for(;i<l;i++){levels[i].object.visible=false;}}},toJSON:function toJSON(meta){var data=Object3D.prototype.toJSON.call(this,meta);if(this.autoUpdate===false)data.object.autoUpdate=false;data.object.levels=[];var levels=this.levels;for(var i=0,l=levels.length;i<l;i++){var level=levels[i];data.object.levels.push({object:level.object.uuid,distance:level.distance});}return data;}});/**
|
1693 | * @author mikael emtinger / http://gomo.se/
|
1694 | * @author alteredq / http://alteredqualia.com/
|
1695 | * @author ikerr / http://verold.com
|
1696 | */function SkinnedMesh(geometry,material){if(geometry&&geometry.isGeometry){console.error('THREE.SkinnedMesh no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.');}Mesh.call(this,geometry,material);this.type='SkinnedMesh';this.bindMode='attached';this.bindMatrix=new Matrix4();this.bindMatrixInverse=new Matrix4();}SkinnedMesh.prototype=_extends(Object.create(Mesh.prototype),{constructor:SkinnedMesh,isSkinnedMesh:true,bind:function bind(skeleton,bindMatrix){this.skeleton=skeleton;if(bindMatrix===undefined){this.updateMatrixWorld(true);this.skeleton.calculateInverses();bindMatrix=this.matrixWorld;}this.bindMatrix.copy(bindMatrix);this.bindMatrixInverse.getInverse(bindMatrix);},pose:function pose(){this.skeleton.pose();},normalizeSkinWeights:function normalizeSkinWeights(){var vector=new Vector4();var skinWeight=this.geometry.attributes.skinWeight;for(var i=0,l=skinWeight.count;i<l;i++){vector.x=skinWeight.getX(i);vector.y=skinWeight.getY(i);vector.z=skinWeight.getZ(i);vector.w=skinWeight.getW(i);var scale=1.0/vector.manhattanLength();if(scale!==Infinity){vector.multiplyScalar(scale);}else {vector.set(1,0,0,0);// do something reasonable
|
1697 | }skinWeight.setXYZW(i,vector.x,vector.y,vector.z,vector.w);}},updateMatrixWorld:function updateMatrixWorld(force){Mesh.prototype.updateMatrixWorld.call(this,force);if(this.bindMode==='attached'){this.bindMatrixInverse.getInverse(this.matrixWorld);}else if(this.bindMode==='detached'){this.bindMatrixInverse.getInverse(this.bindMatrix);}else {console.warn('THREE.SkinnedMesh: Unrecognized bindMode: '+this.bindMode);}},clone:function clone(){return new this.constructor(this.geometry,this.material).copy(this);},boneTransform:function(){var basePosition=new Vector3();var skinIndex=new Vector4();var skinWeight=new Vector4();var vector=new Vector3();var matrix=new Matrix4();return function(index,target){var skeleton=this.skeleton;var geometry=this.geometry;skinIndex.fromBufferAttribute(geometry.attributes.skinIndex,index);skinWeight.fromBufferAttribute(geometry.attributes.skinWeight,index);basePosition.fromBufferAttribute(geometry.attributes.position,index).applyMatrix4(this.bindMatrix);target.set(0,0,0);for(var i=0;i<4;i++){var weight=skinWeight.getComponent(i);if(weight!==0){var boneIndex=skinIndex.getComponent(i);matrix.multiplyMatrices(skeleton.bones[boneIndex].matrixWorld,skeleton.boneInverses[boneIndex]);target.addScaledVector(vector.copy(basePosition).applyMatrix4(matrix),weight);}}return target.applyMatrix4(this.bindMatrixInverse);};}()});/**
|
1698 | * @author mikael emtinger / http://gomo.se/
|
1699 | * @author alteredq / http://alteredqualia.com/
|
1700 | * @author michael guerrero / http://realitymeltdown.com
|
1701 | * @author ikerr / http://verold.com
|
1702 | */var _offsetMatrix=new Matrix4();var _identityMatrix=new Matrix4();function Skeleton(bones,boneInverses){// copy the bone array
|
1703 | bones=bones||[];this.bones=bones.slice(0);this.boneMatrices=new Float32Array(this.bones.length*16);this.frame=-1;// use the supplied bone inverses or calculate the inverses
|
1704 | if(boneInverses===undefined){this.calculateInverses();}else {if(this.bones.length===boneInverses.length){this.boneInverses=boneInverses.slice(0);}else {console.warn('THREE.Skeleton boneInverses is the wrong length.');this.boneInverses=[];for(var i=0,il=this.bones.length;i<il;i++){this.boneInverses.push(new Matrix4());}}}}_extends(Skeleton.prototype,{calculateInverses:function calculateInverses(){this.boneInverses=[];for(var i=0,il=this.bones.length;i<il;i++){var inverse=new Matrix4();if(this.bones[i]){inverse.getInverse(this.bones[i].matrixWorld);}this.boneInverses.push(inverse);}},pose:function pose(){var bone,i,il;// recover the bind-time world matrices
|
1705 | for(i=0,il=this.bones.length;i<il;i++){bone=this.bones[i];if(bone){bone.matrixWorld.getInverse(this.boneInverses[i]);}}// compute the local matrices, positions, rotations and scales
|
1706 | for(i=0,il=this.bones.length;i<il;i++){bone=this.bones[i];if(bone){if(bone.parent&&bone.parent.isBone){bone.matrix.getInverse(bone.parent.matrixWorld);bone.matrix.multiply(bone.matrixWorld);}else {bone.matrix.copy(bone.matrixWorld);}bone.matrix.decompose(bone.position,bone.quaternion,bone.scale);}}},update:function update(){var bones=this.bones;var boneInverses=this.boneInverses;var boneMatrices=this.boneMatrices;var boneTexture=this.boneTexture;// flatten bone matrices to array
|
1707 | for(var i=0,il=bones.length;i<il;i++){// compute the offset between the current and the original transform
|
1708 | var matrix=bones[i]?bones[i].matrixWorld:_identityMatrix;_offsetMatrix.multiplyMatrices(matrix,boneInverses[i]);_offsetMatrix.toArray(boneMatrices,i*16);}if(boneTexture!==undefined){boneTexture.needsUpdate=true;}},clone:function clone(){return new Skeleton(this.bones,this.boneInverses);},getBoneByName:function getBoneByName(name){for(var i=0,il=this.bones.length;i<il;i++){var bone=this.bones[i];if(bone.name===name){return bone;}}return undefined;},dispose:function dispose(){if(this.boneTexture){this.boneTexture.dispose();this.boneTexture=undefined;}}});/**
|
1709 | * @author mikael emtinger / http://gomo.se/
|
1710 | * @author alteredq / http://alteredqualia.com/
|
1711 | * @author ikerr / http://verold.com
|
1712 | */function Bone(){Object3D.call(this);this.type='Bone';}Bone.prototype=_extends(Object.create(Object3D.prototype),{constructor:Bone,isBone:true});/**
|
1713 | * @author mrdoob / http://mrdoob.com/
|
1714 | */var _instanceLocalMatrix=new Matrix4();var _instanceWorldMatrix=new Matrix4();var _instanceIntersects=[];var _mesh=new Mesh();function InstancedMesh(geometry,material,count){Mesh.call(this,geometry,material);this.instanceMatrix=new BufferAttribute(new Float32Array(count*16),16);this.count=count;this.frustumCulled=false;}InstancedMesh.prototype=_extends(Object.create(Mesh.prototype),{constructor:InstancedMesh,isInstancedMesh:true,getMatrixAt:function getMatrixAt(index,matrix){matrix.fromArray(this.instanceMatrix.array,index*16);},raycast:function raycast(raycaster,intersects){var matrixWorld=this.matrixWorld;var raycastTimes=this.count;_mesh.geometry=this.geometry;_mesh.material=this.material;if(_mesh.material===undefined)return;for(var instanceId=0;instanceId<raycastTimes;instanceId++){// calculate the world matrix for each instance
|
1715 | this.getMatrixAt(instanceId,_instanceLocalMatrix);_instanceWorldMatrix.multiplyMatrices(matrixWorld,_instanceLocalMatrix);// the mesh represents this single instance
|
1716 | _mesh.matrixWorld=_instanceWorldMatrix;_mesh.raycast(raycaster,_instanceIntersects);// process the result of raycast
|
1717 | for(var i=0,l=_instanceIntersects.length;i<l;i++){var intersect=_instanceIntersects[i];intersect.instanceId=instanceId;intersect.object=this;intersects.push(intersect);}_instanceIntersects.length=0;}},setMatrixAt:function setMatrixAt(index,matrix){matrix.toArray(this.instanceMatrix.array,index*16);},updateMorphTargets:function updateMorphTargets(){}});/**
|
1718 | * @author mrdoob / http://mrdoob.com/
|
1719 | * @author alteredq / http://alteredqualia.com/
|
1720 | *
|
1721 | * parameters = {
|
1722 | * color: <hex>,
|
1723 | * opacity: <float>,
|
1724 | *
|
1725 | * linewidth: <float>,
|
1726 | * linecap: "round",
|
1727 | * linejoin: "round"
|
1728 | * }
|
1729 | */function LineBasicMaterial(parameters){Material.call(this);this.type='LineBasicMaterial';this.color=new Color(0xffffff);this.linewidth=1;this.linecap='round';this.linejoin='round';this.setValues(parameters);}LineBasicMaterial.prototype=Object.create(Material.prototype);LineBasicMaterial.prototype.constructor=LineBasicMaterial;LineBasicMaterial.prototype.isLineBasicMaterial=true;LineBasicMaterial.prototype.copy=function(source){Material.prototype.copy.call(this,source);this.color.copy(source.color);this.linewidth=source.linewidth;this.linecap=source.linecap;this.linejoin=source.linejoin;return this;};/**
|
1730 | * @author mrdoob / http://mrdoob.com/
|
1731 | */var _start=new Vector3();var _end=new Vector3();var _inverseMatrix$1=new Matrix4();var _ray$1=new Ray();var _sphere$2=new Sphere();function Line(geometry,material,mode){if(mode===1){console.error('THREE.Line: parameter THREE.LinePieces no longer supported. Use THREE.LineSegments instead.');}Object3D.call(this);this.type='Line';this.geometry=geometry!==undefined?geometry:new BufferGeometry();this.material=material!==undefined?material:new LineBasicMaterial();}Line.prototype=_extends(Object.create(Object3D.prototype),{constructor:Line,isLine:true,computeLineDistances:function computeLineDistances(){var geometry=this.geometry;if(geometry.isBufferGeometry){// we assume non-indexed geometry
|
1732 | if(geometry.index===null){var positionAttribute=geometry.attributes.position;var lineDistances=[0];for(var i=1,l=positionAttribute.count;i<l;i++){_start.fromBufferAttribute(positionAttribute,i-1);_end.fromBufferAttribute(positionAttribute,i);lineDistances[i]=lineDistances[i-1];lineDistances[i]+=_start.distanceTo(_end);}geometry.setAttribute('lineDistance',new Float32BufferAttribute(lineDistances,1));}else {console.warn('THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.');}}else if(geometry.isGeometry){var vertices=geometry.vertices;var lineDistances=geometry.lineDistances;lineDistances[0]=0;for(var i=1,l=vertices.length;i<l;i++){lineDistances[i]=lineDistances[i-1];lineDistances[i]+=vertices[i-1].distanceTo(vertices[i]);}}return this;},raycast:function raycast(raycaster,intersects){var geometry=this.geometry;var matrixWorld=this.matrixWorld;var threshold=raycaster.params.Line.threshold;// Checking boundingSphere distance to ray
|
1733 | if(geometry.boundingSphere===null)geometry.computeBoundingSphere();_sphere$2.copy(geometry.boundingSphere);_sphere$2.applyMatrix4(matrixWorld);_sphere$2.radius+=threshold;if(raycaster.ray.intersectsSphere(_sphere$2)===false)return;//
|
1734 | _inverseMatrix$1.getInverse(matrixWorld);_ray$1.copy(raycaster.ray).applyMatrix4(_inverseMatrix$1);var localThreshold=threshold/((this.scale.x+this.scale.y+this.scale.z)/3);var localThresholdSq=localThreshold*localThreshold;var vStart=new Vector3();var vEnd=new Vector3();var interSegment=new Vector3();var interRay=new Vector3();var step=this&&this.isLineSegments?2:1;if(geometry.isBufferGeometry){var index=geometry.index;var attributes=geometry.attributes;var positions=attributes.position.array;if(index!==null){var indices=index.array;for(var i=0,l=indices.length-1;i<l;i+=step){var a=indices[i];var b=indices[i+1];vStart.fromArray(positions,a*3);vEnd.fromArray(positions,b*3);var distSq=_ray$1.distanceSqToSegment(vStart,vEnd,interRay,interSegment);if(distSq>localThresholdSq)continue;interRay.applyMatrix4(this.matrixWorld);//Move back to world space for distance calculation
|
1735 | var distance=raycaster.ray.origin.distanceTo(interRay);if(distance<raycaster.near||distance>raycaster.far)continue;intersects.push({distance:distance,// What do we want? intersection point on the ray or on the segment??
|
1736 | // point: raycaster.ray.at( distance ),
|
1737 | point:interSegment.clone().applyMatrix4(this.matrixWorld),index:i,face:null,faceIndex:null,object:this});}}else {for(var i=0,l=positions.length/3-1;i<l;i+=step){vStart.fromArray(positions,3*i);vEnd.fromArray(positions,3*i+3);var distSq=_ray$1.distanceSqToSegment(vStart,vEnd,interRay,interSegment);if(distSq>localThresholdSq)continue;interRay.applyMatrix4(this.matrixWorld);//Move back to world space for distance calculation
|
1738 | var distance=raycaster.ray.origin.distanceTo(interRay);if(distance<raycaster.near||distance>raycaster.far)continue;intersects.push({distance:distance,// What do we want? intersection point on the ray or on the segment??
|
1739 | // point: raycaster.ray.at( distance ),
|
1740 | point:interSegment.clone().applyMatrix4(this.matrixWorld),index:i,face:null,faceIndex:null,object:this});}}}else if(geometry.isGeometry){var vertices=geometry.vertices;var nbVertices=vertices.length;for(var i=0;i<nbVertices-1;i+=step){var distSq=_ray$1.distanceSqToSegment(vertices[i],vertices[i+1],interRay,interSegment);if(distSq>localThresholdSq)continue;interRay.applyMatrix4(this.matrixWorld);//Move back to world space for distance calculation
|
1741 | var distance=raycaster.ray.origin.distanceTo(interRay);if(distance<raycaster.near||distance>raycaster.far)continue;intersects.push({distance:distance,// What do we want? intersection point on the ray or on the segment??
|
1742 | // point: raycaster.ray.at( distance ),
|
1743 | point:interSegment.clone().applyMatrix4(this.matrixWorld),index:i,face:null,faceIndex:null,object:this});}}},clone:function clone(){return new this.constructor(this.geometry,this.material).copy(this);}});/**
|
1744 | * @author mrdoob / http://mrdoob.com/
|
1745 | */var _start$1=new Vector3();var _end$1=new Vector3();function LineSegments(geometry,material){Line.call(this,geometry,material);this.type='LineSegments';}LineSegments.prototype=_extends(Object.create(Line.prototype),{constructor:LineSegments,isLineSegments:true,computeLineDistances:function computeLineDistances(){var geometry=this.geometry;if(geometry.isBufferGeometry){// we assume non-indexed geometry
|
1746 | if(geometry.index===null){var positionAttribute=geometry.attributes.position;var lineDistances=[];for(var i=0,l=positionAttribute.count;i<l;i+=2){_start$1.fromBufferAttribute(positionAttribute,i);_end$1.fromBufferAttribute(positionAttribute,i+1);lineDistances[i]=i===0?0:lineDistances[i-1];lineDistances[i+1]=lineDistances[i]+_start$1.distanceTo(_end$1);}geometry.setAttribute('lineDistance',new Float32BufferAttribute(lineDistances,1));}else {console.warn('THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.');}}else if(geometry.isGeometry){var vertices=geometry.vertices;var lineDistances=geometry.lineDistances;for(var i=0,l=vertices.length;i<l;i+=2){_start$1.copy(vertices[i]);_end$1.copy(vertices[i+1]);lineDistances[i]=i===0?0:lineDistances[i-1];lineDistances[i+1]=lineDistances[i]+_start$1.distanceTo(_end$1);}}return this;}});/**
|
1747 | * @author mgreter / http://github.com/mgreter
|
1748 | */function LineLoop(geometry,material){Line.call(this,geometry,material);this.type='LineLoop';}LineLoop.prototype=_extends(Object.create(Line.prototype),{constructor:LineLoop,isLineLoop:true});/**
|
1749 | * @author mrdoob / http://mrdoob.com/
|
1750 | * @author alteredq / http://alteredqualia.com/
|
1751 | *
|
1752 | * parameters = {
|
1753 | * color: <hex>,
|
1754 | * opacity: <float>,
|
1755 | * map: new THREE.Texture( <Image> ),
|
1756 | * alphaMap: new THREE.Texture( <Image> ),
|
1757 | *
|
1758 | * size: <float>,
|
1759 | * sizeAttenuation: <bool>
|
1760 | *
|
1761 | * morphTargets: <bool>
|
1762 | * }
|
1763 | */function PointsMaterial(parameters){Material.call(this);this.type='PointsMaterial';this.color=new Color(0xffffff);this.map=null;this.alphaMap=null;this.size=1;this.sizeAttenuation=true;this.morphTargets=false;this.setValues(parameters);}PointsMaterial.prototype=Object.create(Material.prototype);PointsMaterial.prototype.constructor=PointsMaterial;PointsMaterial.prototype.isPointsMaterial=true;PointsMaterial.prototype.copy=function(source){Material.prototype.copy.call(this,source);this.color.copy(source.color);this.map=source.map;this.alphaMap=source.alphaMap;this.size=source.size;this.sizeAttenuation=source.sizeAttenuation;this.morphTargets=source.morphTargets;return this;};/**
|
1764 | * @author alteredq / http://alteredqualia.com/
|
1765 | */var _inverseMatrix$2=new Matrix4();var _ray$2=new Ray();var _sphere$3=new Sphere();var _position$1=new Vector3();function Points(geometry,material){Object3D.call(this);this.type='Points';this.geometry=geometry!==undefined?geometry:new BufferGeometry();this.material=material!==undefined?material:new PointsMaterial();this.updateMorphTargets();}Points.prototype=_extends(Object.create(Object3D.prototype),{constructor:Points,isPoints:true,raycast:function raycast(raycaster,intersects){var geometry=this.geometry;var matrixWorld=this.matrixWorld;var threshold=raycaster.params.Points.threshold;// Checking boundingSphere distance to ray
|
1766 | if(geometry.boundingSphere===null)geometry.computeBoundingSphere();_sphere$3.copy(geometry.boundingSphere);_sphere$3.applyMatrix4(matrixWorld);_sphere$3.radius+=threshold;if(raycaster.ray.intersectsSphere(_sphere$3)===false)return;//
|
1767 | _inverseMatrix$2.getInverse(matrixWorld);_ray$2.copy(raycaster.ray).applyMatrix4(_inverseMatrix$2);var localThreshold=threshold/((this.scale.x+this.scale.y+this.scale.z)/3);var localThresholdSq=localThreshold*localThreshold;if(geometry.isBufferGeometry){var index=geometry.index;var attributes=geometry.attributes;var positions=attributes.position.array;if(index!==null){var indices=index.array;for(var i=0,il=indices.length;i<il;i++){var a=indices[i];_position$1.fromArray(positions,a*3);testPoint(_position$1,a,localThresholdSq,matrixWorld,raycaster,intersects,this);}}else {for(var i=0,l=positions.length/3;i<l;i++){_position$1.fromArray(positions,i*3);testPoint(_position$1,i,localThresholdSq,matrixWorld,raycaster,intersects,this);}}}else {var vertices=geometry.vertices;for(var i=0,l=vertices.length;i<l;i++){testPoint(vertices[i],i,localThresholdSq,matrixWorld,raycaster,intersects,this);}}},updateMorphTargets:function updateMorphTargets(){var geometry=this.geometry;var m,ml,name;if(geometry.isBufferGeometry){var morphAttributes=geometry.morphAttributes;var keys=Object.keys(morphAttributes);if(keys.length>0){var morphAttribute=morphAttributes[keys[0]];if(morphAttribute!==undefined){this.morphTargetInfluences=[];this.morphTargetDictionary={};for(m=0,ml=morphAttribute.length;m<ml;m++){name=morphAttribute[m].name||String(m);this.morphTargetInfluences.push(0);this.morphTargetDictionary[name]=m;}}}}else {var morphTargets=geometry.morphTargets;if(morphTargets!==undefined&&morphTargets.length>0){console.error('THREE.Points.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.');}}},clone:function clone(){return new this.constructor(this.geometry,this.material).copy(this);}});function testPoint(point,index,localThresholdSq,matrixWorld,raycaster,intersects,object){var rayPointDistanceSq=_ray$2.distanceSqToPoint(point);if(rayPointDistanceSq<localThresholdSq){var intersectPoint=new Vector3();_ray$2.closestPointToPoint(point,intersectPoint);intersectPoint.applyMatrix4(matrixWorld);var distance=raycaster.ray.origin.distanceTo(intersectPoint);if(distance<raycaster.near||distance>raycaster.far)return;intersects.push({distance:distance,distanceToRay:Math.sqrt(rayPointDistanceSq),point:intersectPoint,index:index,face:null,object:object});}}/**
|
1768 | * @author mrdoob / http://mrdoob.com/
|
1769 | */function VideoTexture(video,mapping,wrapS,wrapT,magFilter,minFilter,format,type,anisotropy){Texture.call(this,video,mapping,wrapS,wrapT,magFilter,minFilter,format,type,anisotropy);this.format=format!==undefined?format:RGBFormat;this.minFilter=minFilter!==undefined?minFilter:LinearFilter;this.magFilter=magFilter!==undefined?magFilter:LinearFilter;this.generateMipmaps=false;}VideoTexture.prototype=_extends(Object.create(Texture.prototype),{constructor:VideoTexture,isVideoTexture:true,update:function update(){var video=this.image;if(video.readyState>=video.HAVE_CURRENT_DATA){this.needsUpdate=true;}}});/**
|
1770 | * @author alteredq / http://alteredqualia.com/
|
1771 | */function CompressedTexture(mipmaps,width,height,format,type,mapping,wrapS,wrapT,magFilter,minFilter,anisotropy,encoding){Texture.call(this,null,mapping,wrapS,wrapT,magFilter,minFilter,format,type,anisotropy,encoding);this.image={width:width,height:height};this.mipmaps=mipmaps;// no flipping for cube textures
|
1772 | // (also flipping doesn't work for compressed textures )
|
1773 | this.flipY=false;// can't generate mipmaps for compressed textures
|
1774 | // mips must be embedded in DDS files
|
1775 | this.generateMipmaps=false;}CompressedTexture.prototype=Object.create(Texture.prototype);CompressedTexture.prototype.constructor=CompressedTexture;CompressedTexture.prototype.isCompressedTexture=true;/**
|
1776 | * @author mrdoob / http://mrdoob.com/
|
1777 | */function CanvasTexture(canvas,mapping,wrapS,wrapT,magFilter,minFilter,format,type,anisotropy){Texture.call(this,canvas,mapping,wrapS,wrapT,magFilter,minFilter,format,type,anisotropy);this.needsUpdate=true;}CanvasTexture.prototype=Object.create(Texture.prototype);CanvasTexture.prototype.constructor=CanvasTexture;CanvasTexture.prototype.isCanvasTexture=true;/**
|
1778 | * @author Matt DesLauriers / @mattdesl
|
1779 | * @author atix / arthursilber.de
|
1780 | */function DepthTexture(width,height,type,mapping,wrapS,wrapT,magFilter,minFilter,anisotropy,format){format=format!==undefined?format:DepthFormat;if(format!==DepthFormat&&format!==DepthStencilFormat){throw new Error('DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat');}if(type===undefined&&format===DepthFormat)type=UnsignedShortType;if(type===undefined&&format===DepthStencilFormat)type=UnsignedInt248Type;Texture.call(this,null,mapping,wrapS,wrapT,magFilter,minFilter,format,type,anisotropy);this.image={width:width,height:height};this.magFilter=magFilter!==undefined?magFilter:NearestFilter;this.minFilter=minFilter!==undefined?minFilter:NearestFilter;this.flipY=false;this.generateMipmaps=false;}DepthTexture.prototype=Object.create(Texture.prototype);DepthTexture.prototype.constructor=DepthTexture;DepthTexture.prototype.isDepthTexture=true;/**
|
1781 | * @author mrdoob / http://mrdoob.com/
|
1782 | * @author Mugen87 / https://github.com/Mugen87
|
1783 | */function WireframeGeometry(geometry){BufferGeometry.call(this);this.type='WireframeGeometry';// buffer
|
1784 | var vertices=[];// helper variables
|
1785 | var i,j,l,o,ol;var edge=[0,0],edges={},e,edge1,edge2;var key,keys=['a','b','c'];var vertex;// different logic for Geometry and BufferGeometry
|
1786 | if(geometry&&geometry.isGeometry){// create a data structure that contains all edges without duplicates
|
1787 | var faces=geometry.faces;for(i=0,l=faces.length;i<l;i++){var face=faces[i];for(j=0;j<3;j++){edge1=face[keys[j]];edge2=face[keys[(j+1)%3]];edge[0]=Math.min(edge1,edge2);// sorting prevents duplicates
|
1788 | edge[1]=Math.max(edge1,edge2);key=edge[0]+','+edge[1];if(edges[key]===undefined){edges[key]={index1:edge[0],index2:edge[1]};}}}// generate vertices
|
1789 | for(key in edges){e=edges[key];vertex=geometry.vertices[e.index1];vertices.push(vertex.x,vertex.y,vertex.z);vertex=geometry.vertices[e.index2];vertices.push(vertex.x,vertex.y,vertex.z);}}else if(geometry&&geometry.isBufferGeometry){var position,indices,groups;var group,start,count;var index1,index2;vertex=new Vector3();if(geometry.index!==null){// indexed BufferGeometry
|
1790 | position=geometry.attributes.position;indices=geometry.index;groups=geometry.groups;if(groups.length===0){groups=[{start:0,count:indices.count,materialIndex:0}];}// create a data structure that contains all eges without duplicates
|
1791 | for(o=0,ol=groups.length;o<ol;++o){group=groups[o];start=group.start;count=group.count;for(i=start,l=start+count;i<l;i+=3){for(j=0;j<3;j++){edge1=indices.getX(i+j);edge2=indices.getX(i+(j+1)%3);edge[0]=Math.min(edge1,edge2);// sorting prevents duplicates
|
1792 | edge[1]=Math.max(edge1,edge2);key=edge[0]+','+edge[1];if(edges[key]===undefined){edges[key]={index1:edge[0],index2:edge[1]};}}}}// generate vertices
|
1793 | for(key in edges){e=edges[key];vertex.fromBufferAttribute(position,e.index1);vertices.push(vertex.x,vertex.y,vertex.z);vertex.fromBufferAttribute(position,e.index2);vertices.push(vertex.x,vertex.y,vertex.z);}}else {// non-indexed BufferGeometry
|
1794 | position=geometry.attributes.position;for(i=0,l=position.count/3;i<l;i++){for(j=0;j<3;j++){// three edges per triangle, an edge is represented as (index1, index2)
|
1795 | // e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
|
1796 | index1=3*i+j;vertex.fromBufferAttribute(position,index1);vertices.push(vertex.x,vertex.y,vertex.z);index2=3*i+(j+1)%3;vertex.fromBufferAttribute(position,index2);vertices.push(vertex.x,vertex.y,vertex.z);}}}}// build geometry
|
1797 | this.setAttribute('position',new Float32BufferAttribute(vertices,3));}WireframeGeometry.prototype=Object.create(BufferGeometry.prototype);WireframeGeometry.prototype.constructor=WireframeGeometry;/**
|
1798 | * @author zz85 / https://github.com/zz85
|
1799 | * @author Mugen87 / https://github.com/Mugen87
|
1800 | *
|
1801 | * Parametric Surfaces Geometry
|
1802 | * based on the brilliant article by @prideout https://prideout.net/blog/old/blog/index.html@p=44.html
|
1803 | */ // ParametricGeometry
|
1804 | function ParametricGeometry(func,slices,stacks){Geometry.call(this);this.type='ParametricGeometry';this.parameters={func:func,slices:slices,stacks:stacks};this.fromBufferGeometry(new ParametricBufferGeometry(func,slices,stacks));this.mergeVertices();}ParametricGeometry.prototype=Object.create(Geometry.prototype);ParametricGeometry.prototype.constructor=ParametricGeometry;// ParametricBufferGeometry
|
1805 | function ParametricBufferGeometry(func,slices,stacks){BufferGeometry.call(this);this.type='ParametricBufferGeometry';this.parameters={func:func,slices:slices,stacks:stacks};// buffers
|
1806 | var indices=[];var vertices=[];var normals=[];var uvs=[];var EPS=0.00001;var normal=new Vector3();var p0=new Vector3(),p1=new Vector3();var pu=new Vector3(),pv=new Vector3();var i,j;if(func.length<3){console.error('THREE.ParametricGeometry: Function must now modify a Vector3 as third parameter.');}// generate vertices, normals and uvs
|
1807 | var sliceCount=slices+1;for(i=0;i<=stacks;i++){var v=i/stacks;for(j=0;j<=slices;j++){var u=j/slices;// vertex
|
1808 | func(u,v,p0);vertices.push(p0.x,p0.y,p0.z);// normal
|
1809 | // approximate tangent vectors via finite differences
|
1810 | if(u-EPS>=0){func(u-EPS,v,p1);pu.subVectors(p0,p1);}else {func(u+EPS,v,p1);pu.subVectors(p1,p0);}if(v-EPS>=0){func(u,v-EPS,p1);pv.subVectors(p0,p1);}else {func(u,v+EPS,p1);pv.subVectors(p1,p0);}// cross product of tangent vectors returns surface normal
|
1811 | normal.crossVectors(pu,pv).normalize();normals.push(normal.x,normal.y,normal.z);// uv
|
1812 | uvs.push(u,v);}}// generate indices
|
1813 | for(i=0;i<stacks;i++){for(j=0;j<slices;j++){var a=i*sliceCount+j;var b=i*sliceCount+j+1;var c=(i+1)*sliceCount+j+1;var d=(i+1)*sliceCount+j;// faces one and two
|
1814 | indices.push(a,b,d);indices.push(b,c,d);}}// build geometry
|
1815 | this.setIndex(indices);this.setAttribute('position',new Float32BufferAttribute(vertices,3));this.setAttribute('normal',new Float32BufferAttribute(normals,3));this.setAttribute('uv',new Float32BufferAttribute(uvs,2));}ParametricBufferGeometry.prototype=Object.create(BufferGeometry.prototype);ParametricBufferGeometry.prototype.constructor=ParametricBufferGeometry;/**
|
1816 | * @author clockworkgeek / https://github.com/clockworkgeek
|
1817 | * @author timothypratley / https://github.com/timothypratley
|
1818 | * @author WestLangley / http://github.com/WestLangley
|
1819 | * @author Mugen87 / https://github.com/Mugen87
|
1820 | */ // PolyhedronGeometry
|
1821 | function PolyhedronGeometry(vertices,indices,radius,detail){Geometry.call(this);this.type='PolyhedronGeometry';this.parameters={vertices:vertices,indices:indices,radius:radius,detail:detail};this.fromBufferGeometry(new PolyhedronBufferGeometry(vertices,indices,radius,detail));this.mergeVertices();}PolyhedronGeometry.prototype=Object.create(Geometry.prototype);PolyhedronGeometry.prototype.constructor=PolyhedronGeometry;// PolyhedronBufferGeometry
|
1822 | function PolyhedronBufferGeometry(vertices,indices,radius,detail){BufferGeometry.call(this);this.type='PolyhedronBufferGeometry';this.parameters={vertices:vertices,indices:indices,radius:radius,detail:detail};radius=radius||1;detail=detail||0;// default buffer data
|
1823 | var vertexBuffer=[];var uvBuffer=[];// the subdivision creates the vertex buffer data
|
1824 | subdivide(detail);// all vertices should lie on a conceptual sphere with a given radius
|
1825 | applyRadius(radius);// finally, create the uv data
|
1826 | generateUVs();// build non-indexed geometry
|
1827 | this.setAttribute('position',new Float32BufferAttribute(vertexBuffer,3));this.setAttribute('normal',new Float32BufferAttribute(vertexBuffer.slice(),3));this.setAttribute('uv',new Float32BufferAttribute(uvBuffer,2));if(detail===0){this.computeVertexNormals();// flat normals
|
1828 | }else {this.normalizeNormals();// smooth normals
|
1829 | }// helper functions
|
1830 | function subdivide(detail){var a=new Vector3();var b=new Vector3();var c=new Vector3();// iterate over all faces and apply a subdivison with the given detail value
|
1831 | for(var i=0;i<indices.length;i+=3){// get the vertices of the face
|
1832 | getVertexByIndex(indices[i+0],a);getVertexByIndex(indices[i+1],b);getVertexByIndex(indices[i+2],c);// perform subdivision
|
1833 | subdivideFace(a,b,c,detail);}}function subdivideFace(a,b,c,detail){var cols=Math.pow(2,detail);// we use this multidimensional array as a data structure for creating the subdivision
|
1834 | var v=[];var i,j;// construct all of the vertices for this subdivision
|
1835 | for(i=0;i<=cols;i++){v[i]=[];var aj=a.clone().lerp(c,i/cols);var bj=b.clone().lerp(c,i/cols);var rows=cols-i;for(j=0;j<=rows;j++){if(j===0&&i===cols){v[i][j]=aj;}else {v[i][j]=aj.clone().lerp(bj,j/rows);}}}// construct all of the faces
|
1836 | for(i=0;i<cols;i++){for(j=0;j<2*(cols-i)-1;j++){var k=Math.floor(j/2);if(j%2===0){pushVertex(v[i][k+1]);pushVertex(v[i+1][k]);pushVertex(v[i][k]);}else {pushVertex(v[i][k+1]);pushVertex(v[i+1][k+1]);pushVertex(v[i+1][k]);}}}}function applyRadius(radius){var vertex=new Vector3();// iterate over the entire buffer and apply the radius to each vertex
|
1837 | for(var i=0;i<vertexBuffer.length;i+=3){vertex.x=vertexBuffer[i+0];vertex.y=vertexBuffer[i+1];vertex.z=vertexBuffer[i+2];vertex.normalize().multiplyScalar(radius);vertexBuffer[i+0]=vertex.x;vertexBuffer[i+1]=vertex.y;vertexBuffer[i+2]=vertex.z;}}function generateUVs(){var vertex=new Vector3();for(var i=0;i<vertexBuffer.length;i+=3){vertex.x=vertexBuffer[i+0];vertex.y=vertexBuffer[i+1];vertex.z=vertexBuffer[i+2];var u=azimuth(vertex)/2/Math.PI+0.5;var v=inclination(vertex)/Math.PI+0.5;uvBuffer.push(u,1-v);}correctUVs();correctSeam();}function correctSeam(){// handle case when face straddles the seam, see #3269
|
1838 | for(var i=0;i<uvBuffer.length;i+=6){// uv data of a single face
|
1839 | var x0=uvBuffer[i+0];var x1=uvBuffer[i+2];var x2=uvBuffer[i+4];var max=Math.max(x0,x1,x2);var min=Math.min(x0,x1,x2);// 0.9 is somewhat arbitrary
|
1840 | if(max>0.9&&min<0.1){if(x0<0.2)uvBuffer[i+0]+=1;if(x1<0.2)uvBuffer[i+2]+=1;if(x2<0.2)uvBuffer[i+4]+=1;}}}function pushVertex(vertex){vertexBuffer.push(vertex.x,vertex.y,vertex.z);}function getVertexByIndex(index,vertex){var stride=index*3;vertex.x=vertices[stride+0];vertex.y=vertices[stride+1];vertex.z=vertices[stride+2];}function correctUVs(){var a=new Vector3();var b=new Vector3();var c=new Vector3();var centroid=new Vector3();var uvA=new Vector2();var uvB=new Vector2();var uvC=new Vector2();for(var i=0,j=0;i<vertexBuffer.length;i+=9,j+=6){a.set(vertexBuffer[i+0],vertexBuffer[i+1],vertexBuffer[i+2]);b.set(vertexBuffer[i+3],vertexBuffer[i+4],vertexBuffer[i+5]);c.set(vertexBuffer[i+6],vertexBuffer[i+7],vertexBuffer[i+8]);uvA.set(uvBuffer[j+0],uvBuffer[j+1]);uvB.set(uvBuffer[j+2],uvBuffer[j+3]);uvC.set(uvBuffer[j+4],uvBuffer[j+5]);centroid.copy(a).add(b).add(c).divideScalar(3);var azi=azimuth(centroid);correctUV(uvA,j+0,a,azi);correctUV(uvB,j+2,b,azi);correctUV(uvC,j+4,c,azi);}}function correctUV(uv,stride,vector,azimuth){if(azimuth<0&&uv.x===1){uvBuffer[stride]=uv.x-1;}if(vector.x===0&&vector.z===0){uvBuffer[stride]=azimuth/2/Math.PI+0.5;}}// Angle around the Y axis, counter-clockwise when looking from above.
|
1841 | function azimuth(vector){return Math.atan2(vector.z,-vector.x);}// Angle above the XZ plane.
|
1842 | function inclination(vector){return Math.atan2(-vector.y,Math.sqrt(vector.x*vector.x+vector.z*vector.z));}}PolyhedronBufferGeometry.prototype=Object.create(BufferGeometry.prototype);PolyhedronBufferGeometry.prototype.constructor=PolyhedronBufferGeometry;/**
|
1843 | * @author timothypratley / https://github.com/timothypratley
|
1844 | * @author Mugen87 / https://github.com/Mugen87
|
1845 | */ // TetrahedronGeometry
|
1846 | function TetrahedronGeometry(radius,detail){Geometry.call(this);this.type='TetrahedronGeometry';this.parameters={radius:radius,detail:detail};this.fromBufferGeometry(new TetrahedronBufferGeometry(radius,detail));this.mergeVertices();}TetrahedronGeometry.prototype=Object.create(Geometry.prototype);TetrahedronGeometry.prototype.constructor=TetrahedronGeometry;// TetrahedronBufferGeometry
|
1847 | function TetrahedronBufferGeometry(radius,detail){var vertices=[1,1,1,-1,-1,1,-1,1,-1,1,-1,-1];var indices=[2,1,0,0,3,2,1,3,0,2,3,1];PolyhedronBufferGeometry.call(this,vertices,indices,radius,detail);this.type='TetrahedronBufferGeometry';this.parameters={radius:radius,detail:detail};}TetrahedronBufferGeometry.prototype=Object.create(PolyhedronBufferGeometry.prototype);TetrahedronBufferGeometry.prototype.constructor=TetrahedronBufferGeometry;/**
|
1848 | * @author timothypratley / https://github.com/timothypratley
|
1849 | * @author Mugen87 / https://github.com/Mugen87
|
1850 | */ // OctahedronGeometry
|
1851 | function OctahedronGeometry(radius,detail){Geometry.call(this);this.type='OctahedronGeometry';this.parameters={radius:radius,detail:detail};this.fromBufferGeometry(new OctahedronBufferGeometry(radius,detail));this.mergeVertices();}OctahedronGeometry.prototype=Object.create(Geometry.prototype);OctahedronGeometry.prototype.constructor=OctahedronGeometry;// OctahedronBufferGeometry
|
1852 | function OctahedronBufferGeometry(radius,detail){var vertices=[1,0,0,-1,0,0,0,1,0,0,-1,0,0,0,1,0,0,-1];var indices=[0,2,4,0,4,3,0,3,5,0,5,2,1,2,5,1,5,3,1,3,4,1,4,2];PolyhedronBufferGeometry.call(this,vertices,indices,radius,detail);this.type='OctahedronBufferGeometry';this.parameters={radius:radius,detail:detail};}OctahedronBufferGeometry.prototype=Object.create(PolyhedronBufferGeometry.prototype);OctahedronBufferGeometry.prototype.constructor=OctahedronBufferGeometry;/**
|
1853 | * @author timothypratley / https://github.com/timothypratley
|
1854 | * @author Mugen87 / https://github.com/Mugen87
|
1855 | */ // IcosahedronGeometry
|
1856 | function IcosahedronGeometry(radius,detail){Geometry.call(this);this.type='IcosahedronGeometry';this.parameters={radius:radius,detail:detail};this.fromBufferGeometry(new IcosahedronBufferGeometry(radius,detail));this.mergeVertices();}IcosahedronGeometry.prototype=Object.create(Geometry.prototype);IcosahedronGeometry.prototype.constructor=IcosahedronGeometry;// IcosahedronBufferGeometry
|
1857 | function IcosahedronBufferGeometry(radius,detail){var t=(1+Math.sqrt(5))/2;var vertices=[-1,t,0,1,t,0,-1,-t,0,1,-t,0,0,-1,t,0,1,t,0,-1,-t,0,1,-t,t,0,-1,t,0,1,-t,0,-1,-t,0,1];var indices=[0,11,5,0,5,1,0,1,7,0,7,10,0,10,11,1,5,9,5,11,4,11,10,2,10,7,6,7,1,8,3,9,4,3,4,2,3,2,6,3,6,8,3,8,9,4,9,5,2,4,11,6,2,10,8,6,7,9,8,1];PolyhedronBufferGeometry.call(this,vertices,indices,radius,detail);this.type='IcosahedronBufferGeometry';this.parameters={radius:radius,detail:detail};}IcosahedronBufferGeometry.prototype=Object.create(PolyhedronBufferGeometry.prototype);IcosahedronBufferGeometry.prototype.constructor=IcosahedronBufferGeometry;/**
|
1858 | * @author Abe Pazos / https://hamoid.com
|
1859 | * @author Mugen87 / https://github.com/Mugen87
|
1860 | */ // DodecahedronGeometry
|
1861 | function DodecahedronGeometry(radius,detail){Geometry.call(this);this.type='DodecahedronGeometry';this.parameters={radius:radius,detail:detail};this.fromBufferGeometry(new DodecahedronBufferGeometry(radius,detail));this.mergeVertices();}DodecahedronGeometry.prototype=Object.create(Geometry.prototype);DodecahedronGeometry.prototype.constructor=DodecahedronGeometry;// DodecahedronBufferGeometry
|
1862 | function DodecahedronBufferGeometry(radius,detail){var t=(1+Math.sqrt(5))/2;var r=1/t;var vertices=[// (±1, ±1, ±1)
|
1863 | -1,-1,-1,-1,-1,1,-1,1,-1,-1,1,1,1,-1,-1,1,-1,1,1,1,-1,1,1,1,// (0, ±1/φ, ±φ)
|
1864 | 0,-r,-t,0,-r,t,0,r,-t,0,r,t,// (±1/φ, ±φ, 0)
|
1865 | -r,-t,0,-r,t,0,r,-t,0,r,t,0,// (±φ, 0, ±1/φ)
|
1866 | -t,0,-r,t,0,-r,-t,0,r,t,0,r];var indices=[3,11,7,3,7,15,3,15,13,7,19,17,7,17,6,7,6,15,17,4,8,17,8,10,17,10,6,8,0,16,8,16,2,8,2,10,0,12,1,0,1,18,0,18,16,6,10,2,6,2,13,6,13,15,2,16,18,2,18,3,2,3,13,18,1,9,18,9,11,18,11,3,4,14,12,4,12,0,4,0,8,11,9,5,11,5,19,11,19,7,19,5,14,19,14,4,19,4,17,1,12,14,1,14,5,1,5,9];PolyhedronBufferGeometry.call(this,vertices,indices,radius,detail);this.type='DodecahedronBufferGeometry';this.parameters={radius:radius,detail:detail};}DodecahedronBufferGeometry.prototype=Object.create(PolyhedronBufferGeometry.prototype);DodecahedronBufferGeometry.prototype.constructor=DodecahedronBufferGeometry;/**
|
1867 | * @author oosmoxiecode / https://github.com/oosmoxiecode
|
1868 | * @author WestLangley / https://github.com/WestLangley
|
1869 | * @author zz85 / https://github.com/zz85
|
1870 | * @author miningold / https://github.com/miningold
|
1871 | * @author jonobr1 / https://github.com/jonobr1
|
1872 | * @author Mugen87 / https://github.com/Mugen87
|
1873 | *
|
1874 | */ // TubeGeometry
|
1875 | function TubeGeometry(path,tubularSegments,radius,radialSegments,closed,taper){Geometry.call(this);this.type='TubeGeometry';this.parameters={path:path,tubularSegments:tubularSegments,radius:radius,radialSegments:radialSegments,closed:closed};if(taper!==undefined)console.warn('THREE.TubeGeometry: taper has been removed.');var bufferGeometry=new TubeBufferGeometry(path,tubularSegments,radius,radialSegments,closed);// expose internals
|
1876 | this.tangents=bufferGeometry.tangents;this.normals=bufferGeometry.normals;this.binormals=bufferGeometry.binormals;// create geometry
|
1877 | this.fromBufferGeometry(bufferGeometry);this.mergeVertices();}TubeGeometry.prototype=Object.create(Geometry.prototype);TubeGeometry.prototype.constructor=TubeGeometry;// TubeBufferGeometry
|
1878 | function TubeBufferGeometry(path,tubularSegments,radius,radialSegments,closed){BufferGeometry.call(this);this.type='TubeBufferGeometry';this.parameters={path:path,tubularSegments:tubularSegments,radius:radius,radialSegments:radialSegments,closed:closed};tubularSegments=tubularSegments||64;radius=radius||1;radialSegments=radialSegments||8;closed=closed||false;var frames=path.computeFrenetFrames(tubularSegments,closed);// expose internals
|
1879 | this.tangents=frames.tangents;this.normals=frames.normals;this.binormals=frames.binormals;// helper variables
|
1880 | var vertex=new Vector3();var normal=new Vector3();var uv=new Vector2();var P=new Vector3();var i,j;// buffer
|
1881 | var vertices=[];var normals=[];var uvs=[];var indices=[];// create buffer data
|
1882 | generateBufferData();// build geometry
|
1883 | this.setIndex(indices);this.setAttribute('position',new Float32BufferAttribute(vertices,3));this.setAttribute('normal',new Float32BufferAttribute(normals,3));this.setAttribute('uv',new Float32BufferAttribute(uvs,2));// functions
|
1884 | function generateBufferData(){for(i=0;i<tubularSegments;i++){generateSegment(i);}// if the geometry is not closed, generate the last row of vertices and normals
|
1885 | // at the regular position on the given path
|
1886 | //
|
1887 | // if the geometry is closed, duplicate the first row of vertices and normals (uvs will differ)
|
1888 | generateSegment(closed===false?tubularSegments:0);// uvs are generated in a separate function.
|
1889 | // this makes it easy compute correct values for closed geometries
|
1890 | generateUVs();// finally create faces
|
1891 | generateIndices();}function generateSegment(i){// we use getPointAt to sample evenly distributed points from the given path
|
1892 | P=path.getPointAt(i/tubularSegments,P);// retrieve corresponding normal and binormal
|
1893 | var N=frames.normals[i];var B=frames.binormals[i];// generate normals and vertices for the current segment
|
1894 | for(j=0;j<=radialSegments;j++){var v=j/radialSegments*Math.PI*2;var sin=Math.sin(v);var cos=-Math.cos(v);// normal
|
1895 | normal.x=cos*N.x+sin*B.x;normal.y=cos*N.y+sin*B.y;normal.z=cos*N.z+sin*B.z;normal.normalize();normals.push(normal.x,normal.y,normal.z);// vertex
|
1896 | vertex.x=P.x+radius*normal.x;vertex.y=P.y+radius*normal.y;vertex.z=P.z+radius*normal.z;vertices.push(vertex.x,vertex.y,vertex.z);}}function generateIndices(){for(j=1;j<=tubularSegments;j++){for(i=1;i<=radialSegments;i++){var a=(radialSegments+1)*(j-1)+(i-1);var b=(radialSegments+1)*j+(i-1);var c=(radialSegments+1)*j+i;var d=(radialSegments+1)*(j-1)+i;// faces
|
1897 | indices.push(a,b,d);indices.push(b,c,d);}}}function generateUVs(){for(i=0;i<=tubularSegments;i++){for(j=0;j<=radialSegments;j++){uv.x=i/tubularSegments;uv.y=j/radialSegments;uvs.push(uv.x,uv.y);}}}}TubeBufferGeometry.prototype=Object.create(BufferGeometry.prototype);TubeBufferGeometry.prototype.constructor=TubeBufferGeometry;TubeBufferGeometry.prototype.toJSON=function(){var data=BufferGeometry.prototype.toJSON.call(this);data.path=this.parameters.path.toJSON();return data;};/**
|
1898 | * @author oosmoxiecode
|
1899 | * @author Mugen87 / https://github.com/Mugen87
|
1900 | *
|
1901 | * based on http://www.blackpawn.com/texts/pqtorus/
|
1902 | */ // TorusKnotGeometry
|
1903 | function TorusKnotGeometry(radius,tube,tubularSegments,radialSegments,p,q,heightScale){Geometry.call(this);this.type='TorusKnotGeometry';this.parameters={radius:radius,tube:tube,tubularSegments:tubularSegments,radialSegments:radialSegments,p:p,q:q};if(heightScale!==undefined)console.warn('THREE.TorusKnotGeometry: heightScale has been deprecated. Use .scale( x, y, z ) instead.');this.fromBufferGeometry(new TorusKnotBufferGeometry(radius,tube,tubularSegments,radialSegments,p,q));this.mergeVertices();}TorusKnotGeometry.prototype=Object.create(Geometry.prototype);TorusKnotGeometry.prototype.constructor=TorusKnotGeometry;// TorusKnotBufferGeometry
|
1904 | function TorusKnotBufferGeometry(radius,tube,tubularSegments,radialSegments,p,q){BufferGeometry.call(this);this.type='TorusKnotBufferGeometry';this.parameters={radius:radius,tube:tube,tubularSegments:tubularSegments,radialSegments:radialSegments,p:p,q:q};radius=radius||1;tube=tube||0.4;tubularSegments=Math.floor(tubularSegments)||64;radialSegments=Math.floor(radialSegments)||8;p=p||2;q=q||3;// buffers
|
1905 | var indices=[];var vertices=[];var normals=[];var uvs=[];// helper variables
|
1906 | var i,j;var vertex=new Vector3();var normal=new Vector3();var P1=new Vector3();var P2=new Vector3();var B=new Vector3();var T=new Vector3();var N=new Vector3();// generate vertices, normals and uvs
|
1907 | for(i=0;i<=tubularSegments;++i){// the radian "u" is used to calculate the position on the torus curve of the current tubular segement
|
1908 | var u=i/tubularSegments*p*Math.PI*2;// now we calculate two points. P1 is our current position on the curve, P2 is a little farther ahead.
|
1909 | // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
|
1910 | calculatePositionOnCurve(u,p,q,radius,P1);calculatePositionOnCurve(u+0.01,p,q,radius,P2);// calculate orthonormal basis
|
1911 | T.subVectors(P2,P1);N.addVectors(P2,P1);B.crossVectors(T,N);N.crossVectors(B,T);// normalize B, N. T can be ignored, we don't use it
|
1912 | B.normalize();N.normalize();for(j=0;j<=radialSegments;++j){// now calculate the vertices. they are nothing more than an extrusion of the torus curve.
|
1913 | // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
|
1914 | var v=j/radialSegments*Math.PI*2;var cx=-tube*Math.cos(v);var cy=tube*Math.sin(v);// now calculate the final vertex position.
|
1915 | // first we orient the extrusion with our basis vectos, then we add it to the current position on the curve
|
1916 | vertex.x=P1.x+(cx*N.x+cy*B.x);vertex.y=P1.y+(cx*N.y+cy*B.y);vertex.z=P1.z+(cx*N.z+cy*B.z);vertices.push(vertex.x,vertex.y,vertex.z);// normal (P1 is always the center/origin of the extrusion, thus we can use it to calculate the normal)
|
1917 | normal.subVectors(vertex,P1).normalize();normals.push(normal.x,normal.y,normal.z);// uv
|
1918 | uvs.push(i/tubularSegments);uvs.push(j/radialSegments);}}// generate indices
|
1919 | for(j=1;j<=tubularSegments;j++){for(i=1;i<=radialSegments;i++){// indices
|
1920 | var a=(radialSegments+1)*(j-1)+(i-1);var b=(radialSegments+1)*j+(i-1);var c=(radialSegments+1)*j+i;var d=(radialSegments+1)*(j-1)+i;// faces
|
1921 | indices.push(a,b,d);indices.push(b,c,d);}}// build geometry
|
1922 | this.setIndex(indices);this.setAttribute('position',new Float32BufferAttribute(vertices,3));this.setAttribute('normal',new Float32BufferAttribute(normals,3));this.setAttribute('uv',new Float32BufferAttribute(uvs,2));// this function calculates the current position on the torus curve
|
1923 | function calculatePositionOnCurve(u,p,q,radius,position){var cu=Math.cos(u);var su=Math.sin(u);var quOverP=q/p*u;var cs=Math.cos(quOverP);position.x=radius*(2+cs)*0.5*cu;position.y=radius*(2+cs)*su*0.5;position.z=radius*Math.sin(quOverP)*0.5;}}TorusKnotBufferGeometry.prototype=Object.create(BufferGeometry.prototype);TorusKnotBufferGeometry.prototype.constructor=TorusKnotBufferGeometry;/**
|
1924 | * @author oosmoxiecode
|
1925 | * @author mrdoob / http://mrdoob.com/
|
1926 | * @author Mugen87 / https://github.com/Mugen87
|
1927 | */ // TorusGeometry
|
1928 | function TorusGeometry(radius,tube,radialSegments,tubularSegments,arc){Geometry.call(this);this.type='TorusGeometry';this.parameters={radius:radius,tube:tube,radialSegments:radialSegments,tubularSegments:tubularSegments,arc:arc};this.fromBufferGeometry(new TorusBufferGeometry(radius,tube,radialSegments,tubularSegments,arc));this.mergeVertices();}TorusGeometry.prototype=Object.create(Geometry.prototype);TorusGeometry.prototype.constructor=TorusGeometry;// TorusBufferGeometry
|
1929 | function TorusBufferGeometry(radius,tube,radialSegments,tubularSegments,arc){BufferGeometry.call(this);this.type='TorusBufferGeometry';this.parameters={radius:radius,tube:tube,radialSegments:radialSegments,tubularSegments:tubularSegments,arc:arc};radius=radius||1;tube=tube||0.4;radialSegments=Math.floor(radialSegments)||8;tubularSegments=Math.floor(tubularSegments)||6;arc=arc||Math.PI*2;// buffers
|
1930 | var indices=[];var vertices=[];var normals=[];var uvs=[];// helper variables
|
1931 | var center=new Vector3();var vertex=new Vector3();var normal=new Vector3();var j,i;// generate vertices, normals and uvs
|
1932 | for(j=0;j<=radialSegments;j++){for(i=0;i<=tubularSegments;i++){var u=i/tubularSegments*arc;var v=j/radialSegments*Math.PI*2;// vertex
|
1933 | vertex.x=(radius+tube*Math.cos(v))*Math.cos(u);vertex.y=(radius+tube*Math.cos(v))*Math.sin(u);vertex.z=tube*Math.sin(v);vertices.push(vertex.x,vertex.y,vertex.z);// normal
|
1934 | center.x=radius*Math.cos(u);center.y=radius*Math.sin(u);normal.subVectors(vertex,center).normalize();normals.push(normal.x,normal.y,normal.z);// uv
|
1935 | uvs.push(i/tubularSegments);uvs.push(j/radialSegments);}}// generate indices
|
1936 | for(j=1;j<=radialSegments;j++){for(i=1;i<=tubularSegments;i++){// indices
|
1937 | var a=(tubularSegments+1)*j+i-1;var b=(tubularSegments+1)*(j-1)+i-1;var c=(tubularSegments+1)*(j-1)+i;var d=(tubularSegments+1)*j+i;// faces
|
1938 | indices.push(a,b,d);indices.push(b,c,d);}}// build geometry
|
1939 | this.setIndex(indices);this.setAttribute('position',new Float32BufferAttribute(vertices,3));this.setAttribute('normal',new Float32BufferAttribute(normals,3));this.setAttribute('uv',new Float32BufferAttribute(uvs,2));}TorusBufferGeometry.prototype=Object.create(BufferGeometry.prototype);TorusBufferGeometry.prototype.constructor=TorusBufferGeometry;/**
|
1940 | * @author Mugen87 / https://github.com/Mugen87
|
1941 | * Port from https://github.com/mapbox/earcut (v2.2.2)
|
1942 | */var Earcut={triangulate:function triangulate(data,holeIndices,dim){dim=dim||2;var hasHoles=holeIndices&&holeIndices.length,outerLen=hasHoles?holeIndices[0]*dim:data.length,outerNode=linkedList(data,0,outerLen,dim,true),triangles=[];if(!outerNode||outerNode.next===outerNode.prev)return triangles;var minX,minY,maxX,maxY,x,y,invSize;if(hasHoles)outerNode=eliminateHoles(data,holeIndices,outerNode,dim);// if the shape is not too simple, we'll use z-order curve hash later; calculate polygon bbox
|
1943 | if(data.length>80*dim){minX=maxX=data[0];minY=maxY=data[1];for(var i=dim;i<outerLen;i+=dim){x=data[i];y=data[i+1];if(x<minX)minX=x;if(y<minY)minY=y;if(x>maxX)maxX=x;if(y>maxY)maxY=y;}// minX, minY and invSize are later used to transform coords into integers for z-order calculation
|
1944 | invSize=Math.max(maxX-minX,maxY-minY);invSize=invSize!==0?1/invSize:0;}earcutLinked(outerNode,triangles,dim,minX,minY,invSize);return triangles;}};// create a circular doubly linked list from polygon points in the specified winding order
|
1945 | function linkedList(data,start,end,dim,clockwise){var i,last;if(clockwise===signedArea(data,start,end,dim)>0){for(i=start;i<end;i+=dim){last=insertNode(i,data[i],data[i+1],last);}}else {for(i=end-dim;i>=start;i-=dim){last=insertNode(i,data[i],data[i+1],last);}}if(last&&equals(last,last.next)){removeNode(last);last=last.next;}return last;}// eliminate colinear or duplicate points
|
1946 | function filterPoints(start,end){if(!start)return start;if(!end)end=start;var p=start,again;do{again=false;if(!p.steiner&&(equals(p,p.next)||area(p.prev,p,p.next)===0)){removeNode(p);p=end=p.prev;if(p===p.next)break;again=true;}else {p=p.next;}}while(again||p!==end);return end;}// main ear slicing loop which triangulates a polygon (given as a linked list)
|
1947 | function earcutLinked(ear,triangles,dim,minX,minY,invSize,pass){if(!ear)return;// interlink polygon nodes in z-order
|
1948 | if(!pass&&invSize)indexCurve(ear,minX,minY,invSize);var stop=ear,prev,next;// iterate through ears, slicing them one by one
|
1949 | while(ear.prev!==ear.next){prev=ear.prev;next=ear.next;if(invSize?isEarHashed(ear,minX,minY,invSize):isEar(ear)){// cut off the triangle
|
1950 | triangles.push(prev.i/dim);triangles.push(ear.i/dim);triangles.push(next.i/dim);removeNode(ear);// skipping the next vertex leads to less sliver triangles
|
1951 | ear=next.next;stop=next.next;continue;}ear=next;// if we looped through the whole remaining polygon and can't find any more ears
|
1952 | if(ear===stop){// try filtering points and slicing again
|
1953 | if(!pass){earcutLinked(filterPoints(ear),triangles,dim,minX,minY,invSize,1);// if this didn't work, try curing all small self-intersections locally
|
1954 | }else if(pass===1){ear=cureLocalIntersections(filterPoints(ear),triangles,dim);earcutLinked(ear,triangles,dim,minX,minY,invSize,2);// as a last resort, try splitting the remaining polygon into two
|
1955 | }else if(pass===2){splitEarcut(ear,triangles,dim,minX,minY,invSize);}break;}}}// check whether a polygon node forms a valid ear with adjacent nodes
|
1956 | function isEar(ear){var a=ear.prev,b=ear,c=ear.next;if(area(a,b,c)>=0)return false;// reflex, can't be an ear
|
1957 | // now make sure we don't have other points inside the potential ear
|
1958 | var p=ear.next.next;while(p!==ear.prev){if(pointInTriangle(a.x,a.y,b.x,b.y,c.x,c.y,p.x,p.y)&&area(p.prev,p,p.next)>=0)return false;p=p.next;}return true;}function isEarHashed(ear,minX,minY,invSize){var a=ear.prev,b=ear,c=ear.next;if(area(a,b,c)>=0)return false;// reflex, can't be an ear
|
1959 | // triangle bbox; min & max are calculated like this for speed
|
1960 | var minTX=a.x<b.x?a.x<c.x?a.x:c.x:b.x<c.x?b.x:c.x,minTY=a.y<b.y?a.y<c.y?a.y:c.y:b.y<c.y?b.y:c.y,maxTX=a.x>b.x?a.x>c.x?a.x:c.x:b.x>c.x?b.x:c.x,maxTY=a.y>b.y?a.y>c.y?a.y:c.y:b.y>c.y?b.y:c.y;// z-order range for the current triangle bbox;
|
1961 | var minZ=zOrder(minTX,minTY,minX,minY,invSize),maxZ=zOrder(maxTX,maxTY,minX,minY,invSize);var p=ear.prevZ,n=ear.nextZ;// look for points inside the triangle in both directions
|
1962 | while(p&&p.z>=minZ&&n&&n.z<=maxZ){if(p!==ear.prev&&p!==ear.next&&pointInTriangle(a.x,a.y,b.x,b.y,c.x,c.y,p.x,p.y)&&area(p.prev,p,p.next)>=0)return false;p=p.prevZ;if(n!==ear.prev&&n!==ear.next&&pointInTriangle(a.x,a.y,b.x,b.y,c.x,c.y,n.x,n.y)&&area(n.prev,n,n.next)>=0)return false;n=n.nextZ;}// look for remaining points in decreasing z-order
|
1963 | while(p&&p.z>=minZ){if(p!==ear.prev&&p!==ear.next&&pointInTriangle(a.x,a.y,b.x,b.y,c.x,c.y,p.x,p.y)&&area(p.prev,p,p.next)>=0)return false;p=p.prevZ;}// look for remaining points in increasing z-order
|
1964 | while(n&&n.z<=maxZ){if(n!==ear.prev&&n!==ear.next&&pointInTriangle(a.x,a.y,b.x,b.y,c.x,c.y,n.x,n.y)&&area(n.prev,n,n.next)>=0)return false;n=n.nextZ;}return true;}// go through all polygon nodes and cure small local self-intersections
|
1965 | function cureLocalIntersections(start,triangles,dim){var p=start;do{var a=p.prev,b=p.next.next;if(!equals(a,b)&&intersects(a,p,p.next,b)&&locallyInside(a,b)&&locallyInside(b,a)){triangles.push(a.i/dim);triangles.push(p.i/dim);triangles.push(b.i/dim);// remove two nodes involved
|
1966 | removeNode(p);removeNode(p.next);p=start=b;}p=p.next;}while(p!==start);return filterPoints(p);}// try splitting polygon into two and triangulate them independently
|
1967 | function splitEarcut(start,triangles,dim,minX,minY,invSize){// look for a valid diagonal that divides the polygon into two
|
1968 | var a=start;do{var b=a.next.next;while(b!==a.prev){if(a.i!==b.i&&isValidDiagonal(a,b)){// split the polygon in two by the diagonal
|
1969 | var c=splitPolygon(a,b);// filter colinear points around the cuts
|
1970 | a=filterPoints(a,a.next);c=filterPoints(c,c.next);// run earcut on each half
|
1971 | earcutLinked(a,triangles,dim,minX,minY,invSize);earcutLinked(c,triangles,dim,minX,minY,invSize);return;}b=b.next;}a=a.next;}while(a!==start);}// link every hole into the outer loop, producing a single-ring polygon without holes
|
1972 | function eliminateHoles(data,holeIndices,outerNode,dim){var queue=[],i,len,start,end,list;for(i=0,len=holeIndices.length;i<len;i++){start=holeIndices[i]*dim;end=i<len-1?holeIndices[i+1]*dim:data.length;list=linkedList(data,start,end,dim,false);if(list===list.next)list.steiner=true;queue.push(getLeftmost(list));}queue.sort(compareX);// process holes from left to right
|
1973 | for(i=0;i<queue.length;i++){eliminateHole(queue[i],outerNode);outerNode=filterPoints(outerNode,outerNode.next);}return outerNode;}function compareX(a,b){return a.x-b.x;}// find a bridge between vertices that connects hole with an outer ring and and link it
|
1974 | function eliminateHole(hole,outerNode){outerNode=findHoleBridge(hole,outerNode);if(outerNode){var b=splitPolygon(outerNode,hole);// filter collinear points around the cuts
|
1975 | filterPoints(outerNode,outerNode.next);filterPoints(b,b.next);}}// David Eberly's algorithm for finding a bridge between hole and outer polygon
|
1976 | function findHoleBridge(hole,outerNode){var p=outerNode,hx=hole.x,hy=hole.y,qx=-Infinity,m;// find a segment intersected by a ray from the hole's leftmost point to the left;
|
1977 | // segment's endpoint with lesser x will be potential connection point
|
1978 | do{if(hy<=p.y&&hy>=p.next.y&&p.next.y!==p.y){var x=p.x+(hy-p.y)*(p.next.x-p.x)/(p.next.y-p.y);if(x<=hx&&x>qx){qx=x;if(x===hx){if(hy===p.y)return p;if(hy===p.next.y)return p.next;}m=p.x<p.next.x?p:p.next;}}p=p.next;}while(p!==outerNode);if(!m)return null;if(hx===qx)return m;// hole touches outer segment; pick leftmost endpoint
|
1979 | // look for points inside the triangle of hole point, segment intersection and endpoint;
|
1980 | // if there are no points found, we have a valid connection;
|
1981 | // otherwise choose the point of the minimum angle with the ray as connection point
|
1982 | var stop=m,mx=m.x,my=m.y,tanMin=Infinity,tan;p=m;do{if(hx>=p.x&&p.x>=mx&&hx!==p.x&&pointInTriangle(hy<my?hx:qx,hy,mx,my,hy<my?qx:hx,hy,p.x,p.y)){tan=Math.abs(hy-p.y)/(hx-p.x);// tangential
|
1983 | if(locallyInside(p,hole)&&(tan<tanMin||tan===tanMin&&(p.x>m.x||p.x===m.x&§orContainsSector(m,p)))){m=p;tanMin=tan;}}p=p.next;}while(p!==stop);return m;}// whether sector in vertex m contains sector in vertex p in the same coordinates
|
1984 | function sectorContainsSector(m,p){return area(m.prev,m,p.prev)<0&&area(p.next,m,m.next)<0;}// interlink polygon nodes in z-order
|
1985 | function indexCurve(start,minX,minY,invSize){var p=start;do{if(p.z===null)p.z=zOrder(p.x,p.y,minX,minY,invSize);p.prevZ=p.prev;p.nextZ=p.next;p=p.next;}while(p!==start);p.prevZ.nextZ=null;p.prevZ=null;sortLinked(p);}// Simon Tatham's linked list merge sort algorithm
|
1986 | // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
|
1987 | function sortLinked(list){var i,p,q,e,tail,numMerges,pSize,qSize,inSize=1;do{p=list;list=null;tail=null;numMerges=0;while(p){numMerges++;q=p;pSize=0;for(i=0;i<inSize;i++){pSize++;q=q.nextZ;if(!q)break;}qSize=inSize;while(pSize>0||qSize>0&&q){if(pSize!==0&&(qSize===0||!q||p.z<=q.z)){e=p;p=p.nextZ;pSize--;}else {e=q;q=q.nextZ;qSize--;}if(tail)tail.nextZ=e;else list=e;e.prevZ=tail;tail=e;}p=q;}tail.nextZ=null;inSize*=2;}while(numMerges>1);return list;}// z-order of a point given coords and inverse of the longer side of data bbox
|
1988 | function zOrder(x,y,minX,minY,invSize){// coords are transformed into non-negative 15-bit integer range
|
1989 | x=32767*(x-minX)*invSize;y=32767*(y-minY)*invSize;x=(x|x<<8)&0x00FF00FF;x=(x|x<<4)&0x0F0F0F0F;x=(x|x<<2)&0x33333333;x=(x|x<<1)&0x55555555;y=(y|y<<8)&0x00FF00FF;y=(y|y<<4)&0x0F0F0F0F;y=(y|y<<2)&0x33333333;y=(y|y<<1)&0x55555555;return x|y<<1;}// find the leftmost node of a polygon ring
|
1990 | function getLeftmost(start){var p=start,leftmost=start;do{if(p.x<leftmost.x||p.x===leftmost.x&&p.y<leftmost.y)leftmost=p;p=p.next;}while(p!==start);return leftmost;}// check if a point lies within a convex triangle
|
1991 | function pointInTriangle(ax,ay,bx,by,cx,cy,px,py){return (cx-px)*(ay-py)-(ax-px)*(cy-py)>=0&&(ax-px)*(by-py)-(bx-px)*(ay-py)>=0&&(bx-px)*(cy-py)-(cx-px)*(by-py)>=0;}// check if a diagonal between two polygon nodes is valid (lies in polygon interior)
|
1992 | function isValidDiagonal(a,b){return a.next.i!==b.i&&a.prev.i!==b.i&&!intersectsPolygon(a,b)&&(// dones't intersect other edges
|
1993 | locallyInside(a,b)&&locallyInside(b,a)&&middleInside(a,b)&&(// locally visible
|
1994 | area(a.prev,a,b.prev)||area(a,b.prev,b))||// does not create opposite-facing sectors
|
1995 | equals(a,b)&&area(a.prev,a,a.next)>0&&area(b.prev,b,b.next)>0);// special zero-length case
|
1996 | }// signed area of a triangle
|
1997 | function area(p,q,r){return (q.y-p.y)*(r.x-q.x)-(q.x-p.x)*(r.y-q.y);}// check if two points are equal
|
1998 | function equals(p1,p2){return p1.x===p2.x&&p1.y===p2.y;}// check if two segments intersect
|
1999 | function intersects(p1,q1,p2,q2){var o1=sign(area(p1,q1,p2));var o2=sign(area(p1,q1,q2));var o3=sign(area(p2,q2,p1));var o4=sign(area(p2,q2,q1));if(o1!==o2&&o3!==o4)return true;// general case
|
2000 | if(o1===0&&onSegment(p1,p2,q1))return true;// p1, q1 and p2 are collinear and p2 lies on p1q1
|
2001 | if(o2===0&&onSegment(p1,q2,q1))return true;// p1, q1 and q2 are collinear and q2 lies on p1q1
|
2002 | if(o3===0&&onSegment(p2,p1,q2))return true;// p2, q2 and p1 are collinear and p1 lies on p2q2
|
2003 | if(o4===0&&onSegment(p2,q1,q2))return true;// p2, q2 and q1 are collinear and q1 lies on p2q2
|
2004 | return false;}// for collinear points p, q, r, check if point q lies on segment pr
|
2005 | function onSegment(p,q,r){return q.x<=Math.max(p.x,r.x)&&q.x>=Math.min(p.x,r.x)&&q.y<=Math.max(p.y,r.y)&&q.y>=Math.min(p.y,r.y);}function sign(num){return num>0?1:num<0?-1:0;}// check if a polygon diagonal intersects any polygon segments
|
2006 | function intersectsPolygon(a,b){var p=a;do{if(p.i!==a.i&&p.next.i!==a.i&&p.i!==b.i&&p.next.i!==b.i&&intersects(p,p.next,a,b))return true;p=p.next;}while(p!==a);return false;}// check if a polygon diagonal is locally inside the polygon
|
2007 | function locallyInside(a,b){return area(a.prev,a,a.next)<0?area(a,b,a.next)>=0&&area(a,a.prev,b)>=0:area(a,b,a.prev)<0||area(a,a.next,b)<0;}// check if the middle point of a polygon diagonal is inside the polygon
|
2008 | function middleInside(a,b){var p=a,inside=false,px=(a.x+b.x)/2,py=(a.y+b.y)/2;do{if(p.y>py!==p.next.y>py&&p.next.y!==p.y&&px<(p.next.x-p.x)*(py-p.y)/(p.next.y-p.y)+p.x)inside=!inside;p=p.next;}while(p!==a);return inside;}// link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
|
2009 | // if one belongs to the outer ring and another to a hole, it merges it into a single ring
|
2010 | function splitPolygon(a,b){var a2=new Node$1(a.i,a.x,a.y),b2=new Node$1(b.i,b.x,b.y),an=a.next,bp=b.prev;a.next=b;b.prev=a;a2.next=an;an.prev=a2;b2.next=a2;a2.prev=b2;bp.next=b2;b2.prev=bp;return b2;}// create a node and optionally link it with previous one (in a circular doubly linked list)
|
2011 | function insertNode(i,x,y,last){var p=new Node$1(i,x,y);if(!last){p.prev=p;p.next=p;}else {p.next=last.next;p.prev=last;last.next.prev=p;last.next=p;}return p;}function removeNode(p){p.next.prev=p.prev;p.prev.next=p.next;if(p.prevZ)p.prevZ.nextZ=p.nextZ;if(p.nextZ)p.nextZ.prevZ=p.prevZ;}function Node$1(i,x,y){// vertex index in coordinates array
|
2012 | this.i=i;// vertex coordinates
|
2013 | this.x=x;this.y=y;// previous and next vertex nodes in a polygon ring
|
2014 | this.prev=null;this.next=null;// z-order curve value
|
2015 | this.z=null;// previous and next nodes in z-order
|
2016 | this.prevZ=null;this.nextZ=null;// indicates whether this is a steiner point
|
2017 | this.steiner=false;}function signedArea(data,start,end,dim){var sum=0;for(var i=start,j=end-dim;i<end;i+=dim){sum+=(data[j]-data[i])*(data[i+1]+data[j+1]);j=i;}return sum;}/**
|
2018 | * @author zz85 / http://www.lab4games.net/zz85/blog
|
2019 | */var ShapeUtils={// calculate area of the contour polygon
|
2020 | area:function area(contour){var n=contour.length;var a=0.0;for(var p=n-1,q=0;q<n;p=q++){a+=contour[p].x*contour[q].y-contour[q].x*contour[p].y;}return a*0.5;},isClockWise:function isClockWise(pts){return ShapeUtils.area(pts)<0;},triangulateShape:function triangulateShape(contour,holes){var vertices=[];// flat array of vertices like [ x0,y0, x1,y1, x2,y2, ... ]
|
2021 | var holeIndices=[];// array of hole indices
|
2022 | var faces=[];// final array of vertex indices like [ [ a,b,d ], [ b,c,d ] ]
|
2023 | removeDupEndPts(contour);addContour(vertices,contour);//
|
2024 | var holeIndex=contour.length;holes.forEach(removeDupEndPts);for(var i=0;i<holes.length;i++){holeIndices.push(holeIndex);holeIndex+=holes[i].length;addContour(vertices,holes[i]);}//
|
2025 | var triangles=Earcut.triangulate(vertices,holeIndices);//
|
2026 | for(var i=0;i<triangles.length;i+=3){faces.push(triangles.slice(i,i+3));}return faces;}};function removeDupEndPts(points){var l=points.length;if(l>2&&points[l-1].equals(points[0])){points.pop();}}function addContour(vertices,contour){for(var i=0;i<contour.length;i++){vertices.push(contour[i].x);vertices.push(contour[i].y);}}/**
|
2027 | * @author zz85 / http://www.lab4games.net/zz85/blog
|
2028 | *
|
2029 | * Creates extruded geometry from a path shape.
|
2030 | *
|
2031 | * parameters = {
|
2032 | *
|
2033 | * curveSegments: <int>, // number of points on the curves
|
2034 | * steps: <int>, // number of points for z-side extrusions / used for subdividing segments of extrude spline too
|
2035 | * depth: <float>, // Depth to extrude the shape
|
2036 | *
|
2037 | * bevelEnabled: <bool>, // turn on bevel
|
2038 | * bevelThickness: <float>, // how deep into the original shape bevel goes
|
2039 | * bevelSize: <float>, // how far from shape outline (including bevelOffset) is bevel
|
2040 | * bevelOffset: <float>, // how far from shape outline does bevel start
|
2041 | * bevelSegments: <int>, // number of bevel layers
|
2042 | *
|
2043 | * extrudePath: <THREE.Curve> // curve to extrude shape along
|
2044 | *
|
2045 | * UVGenerator: <Object> // object that provides UV generator functions
|
2046 | *
|
2047 | * }
|
2048 | */ // ExtrudeGeometry
|
2049 | function ExtrudeGeometry(shapes,options){Geometry.call(this);this.type='ExtrudeGeometry';this.parameters={shapes:shapes,options:options};this.fromBufferGeometry(new ExtrudeBufferGeometry(shapes,options));this.mergeVertices();}ExtrudeGeometry.prototype=Object.create(Geometry.prototype);ExtrudeGeometry.prototype.constructor=ExtrudeGeometry;ExtrudeGeometry.prototype.toJSON=function(){var data=Geometry.prototype.toJSON.call(this);var shapes=this.parameters.shapes;var options=this.parameters.options;return toJSON(shapes,options,data);};// ExtrudeBufferGeometry
|
2050 | function ExtrudeBufferGeometry(shapes,options){BufferGeometry.call(this);this.type='ExtrudeBufferGeometry';this.parameters={shapes:shapes,options:options};shapes=Array.isArray(shapes)?shapes:[shapes];var scope=this;var verticesArray=[];var uvArray=[];for(var i=0,l=shapes.length;i<l;i++){var shape=shapes[i];addShape(shape);}// build geometry
|
2051 | this.setAttribute('position',new Float32BufferAttribute(verticesArray,3));this.setAttribute('uv',new Float32BufferAttribute(uvArray,2));this.computeVertexNormals();// functions
|
2052 | function addShape(shape){var placeholder=[];// options
|
2053 | var curveSegments=options.curveSegments!==undefined?options.curveSegments:12;var steps=options.steps!==undefined?options.steps:1;var depth=options.depth!==undefined?options.depth:100;var bevelEnabled=options.bevelEnabled!==undefined?options.bevelEnabled:true;var bevelThickness=options.bevelThickness!==undefined?options.bevelThickness:6;var bevelSize=options.bevelSize!==undefined?options.bevelSize:bevelThickness-2;var bevelOffset=options.bevelOffset!==undefined?options.bevelOffset:0;var bevelSegments=options.bevelSegments!==undefined?options.bevelSegments:3;var extrudePath=options.extrudePath;var uvgen=options.UVGenerator!==undefined?options.UVGenerator:WorldUVGenerator;// deprecated options
|
2054 | if(options.amount!==undefined){console.warn('THREE.ExtrudeBufferGeometry: amount has been renamed to depth.');depth=options.amount;}//
|
2055 | var extrudePts,extrudeByPath=false;var splineTube,binormal,normal,position2;if(extrudePath){extrudePts=extrudePath.getSpacedPoints(steps);extrudeByPath=true;bevelEnabled=false;// bevels not supported for path extrusion
|
2056 | // SETUP TNB variables
|
2057 | // TODO1 - have a .isClosed in spline?
|
2058 | splineTube=extrudePath.computeFrenetFrames(steps,false);// console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
|
2059 | binormal=new Vector3();normal=new Vector3();position2=new Vector3();}// Safeguards if bevels are not enabled
|
2060 | if(!bevelEnabled){bevelSegments=0;bevelThickness=0;bevelSize=0;bevelOffset=0;}// Variables initialization
|
2061 | var ahole,h,hl;// looping of holes
|
2062 | var shapePoints=shape.extractPoints(curveSegments);var vertices=shapePoints.shape;var holes=shapePoints.holes;var reverse=!ShapeUtils.isClockWise(vertices);if(reverse){vertices=vertices.reverse();// Maybe we should also check if holes are in the opposite direction, just to be safe ...
|
2063 | for(h=0,hl=holes.length;h<hl;h++){ahole=holes[h];if(ShapeUtils.isClockWise(ahole)){holes[h]=ahole.reverse();}}}var faces=ShapeUtils.triangulateShape(vertices,holes);/* Vertices */var contour=vertices;// vertices has all points but contour has only points of circumference
|
2064 | for(h=0,hl=holes.length;h<hl;h++){ahole=holes[h];vertices=vertices.concat(ahole);}function scalePt2(pt,vec,size){if(!vec)console.error("THREE.ExtrudeGeometry: vec does not exist");return vec.clone().multiplyScalar(size).add(pt);}var b,bs,t,z,vert,vlen=vertices.length,face,flen=faces.length;// Find directions for point movement
|
2065 | function getBevelVec(inPt,inPrev,inNext){// computes for inPt the corresponding point inPt' on a new contour
|
2066 | // shifted by 1 unit (length of normalized vector) to the left
|
2067 | // if we walk along contour clockwise, this new contour is outside the old one
|
2068 | //
|
2069 | // inPt' is the intersection of the two lines parallel to the two
|
2070 | // adjacent edges of inPt at a distance of 1 unit on the left side.
|
2071 | var v_trans_x,v_trans_y,shrink_by;// resulting translation vector for inPt
|
2072 | // good reading for geometry algorithms (here: line-line intersection)
|
2073 | // http://geomalgorithms.com/a05-_intersect-1.html
|
2074 | var v_prev_x=inPt.x-inPrev.x,v_prev_y=inPt.y-inPrev.y;var v_next_x=inNext.x-inPt.x,v_next_y=inNext.y-inPt.y;var v_prev_lensq=v_prev_x*v_prev_x+v_prev_y*v_prev_y;// check for collinear edges
|
2075 | var collinear0=v_prev_x*v_next_y-v_prev_y*v_next_x;if(Math.abs(collinear0)>Number.EPSILON){// not collinear
|
2076 | // length of vectors for normalizing
|
2077 | var v_prev_len=Math.sqrt(v_prev_lensq);var v_next_len=Math.sqrt(v_next_x*v_next_x+v_next_y*v_next_y);// shift adjacent points by unit vectors to the left
|
2078 | var ptPrevShift_x=inPrev.x-v_prev_y/v_prev_len;var ptPrevShift_y=inPrev.y+v_prev_x/v_prev_len;var ptNextShift_x=inNext.x-v_next_y/v_next_len;var ptNextShift_y=inNext.y+v_next_x/v_next_len;// scaling factor for v_prev to intersection point
|
2079 | var sf=((ptNextShift_x-ptPrevShift_x)*v_next_y-(ptNextShift_y-ptPrevShift_y)*v_next_x)/(v_prev_x*v_next_y-v_prev_y*v_next_x);// vector from inPt to intersection point
|
2080 | v_trans_x=ptPrevShift_x+v_prev_x*sf-inPt.x;v_trans_y=ptPrevShift_y+v_prev_y*sf-inPt.y;// Don't normalize!, otherwise sharp corners become ugly
|
2081 | // but prevent crazy spikes
|
2082 | var v_trans_lensq=v_trans_x*v_trans_x+v_trans_y*v_trans_y;if(v_trans_lensq<=2){return new Vector2(v_trans_x,v_trans_y);}else {shrink_by=Math.sqrt(v_trans_lensq/2);}}else {// handle special case of collinear edges
|
2083 | var direction_eq=false;// assumes: opposite
|
2084 | if(v_prev_x>Number.EPSILON){if(v_next_x>Number.EPSILON){direction_eq=true;}}else {if(v_prev_x<-Number.EPSILON){if(v_next_x<-Number.EPSILON){direction_eq=true;}}else {if(Math.sign(v_prev_y)===Math.sign(v_next_y)){direction_eq=true;}}}if(direction_eq){// console.log("Warning: lines are a straight sequence");
|
2085 | v_trans_x=-v_prev_y;v_trans_y=v_prev_x;shrink_by=Math.sqrt(v_prev_lensq);}else {// console.log("Warning: lines are a straight spike");
|
2086 | v_trans_x=v_prev_x;v_trans_y=v_prev_y;shrink_by=Math.sqrt(v_prev_lensq/2);}}return new Vector2(v_trans_x/shrink_by,v_trans_y/shrink_by);}var contourMovements=[];for(var i=0,il=contour.length,j=il-1,k=i+1;i<il;i++,j++,k++){if(j===il)j=0;if(k===il)k=0;// (j)---(i)---(k)
|
2087 | // console.log('i,j,k', i, j , k)
|
2088 | contourMovements[i]=getBevelVec(contour[i],contour[j],contour[k]);}var holesMovements=[],oneHoleMovements,verticesMovements=contourMovements.concat();for(h=0,hl=holes.length;h<hl;h++){ahole=holes[h];oneHoleMovements=[];for(i=0,il=ahole.length,j=il-1,k=i+1;i<il;i++,j++,k++){if(j===il)j=0;if(k===il)k=0;// (j)---(i)---(k)
|
2089 | oneHoleMovements[i]=getBevelVec(ahole[i],ahole[j],ahole[k]);}holesMovements.push(oneHoleMovements);verticesMovements=verticesMovements.concat(oneHoleMovements);}// Loop bevelSegments, 1 for the front, 1 for the back
|
2090 | for(b=0;b<bevelSegments;b++){//for ( b = bevelSegments; b > 0; b -- ) {
|
2091 | t=b/bevelSegments;z=bevelThickness*Math.cos(t*Math.PI/2);bs=bevelSize*Math.sin(t*Math.PI/2)+bevelOffset;// contract shape
|
2092 | for(i=0,il=contour.length;i<il;i++){vert=scalePt2(contour[i],contourMovements[i],bs);v(vert.x,vert.y,-z);}// expand holes
|
2093 | for(h=0,hl=holes.length;h<hl;h++){ahole=holes[h];oneHoleMovements=holesMovements[h];for(i=0,il=ahole.length;i<il;i++){vert=scalePt2(ahole[i],oneHoleMovements[i],bs);v(vert.x,vert.y,-z);}}}bs=bevelSize+bevelOffset;// Back facing vertices
|
2094 | for(i=0;i<vlen;i++){vert=bevelEnabled?scalePt2(vertices[i],verticesMovements[i],bs):vertices[i];if(!extrudeByPath){v(vert.x,vert.y,0);}else {// v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
|
2095 | normal.copy(splineTube.normals[0]).multiplyScalar(vert.x);binormal.copy(splineTube.binormals[0]).multiplyScalar(vert.y);position2.copy(extrudePts[0]).add(normal).add(binormal);v(position2.x,position2.y,position2.z);}}// Add stepped vertices...
|
2096 | // Including front facing vertices
|
2097 | var s;for(s=1;s<=steps;s++){for(i=0;i<vlen;i++){vert=bevelEnabled?scalePt2(vertices[i],verticesMovements[i],bs):vertices[i];if(!extrudeByPath){v(vert.x,vert.y,depth/steps*s);}else {// v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
|
2098 | normal.copy(splineTube.normals[s]).multiplyScalar(vert.x);binormal.copy(splineTube.binormals[s]).multiplyScalar(vert.y);position2.copy(extrudePts[s]).add(normal).add(binormal);v(position2.x,position2.y,position2.z);}}}// Add bevel segments planes
|
2099 | //for ( b = 1; b <= bevelSegments; b ++ ) {
|
2100 | for(b=bevelSegments-1;b>=0;b--){t=b/bevelSegments;z=bevelThickness*Math.cos(t*Math.PI/2);bs=bevelSize*Math.sin(t*Math.PI/2)+bevelOffset;// contract shape
|
2101 | for(i=0,il=contour.length;i<il;i++){vert=scalePt2(contour[i],contourMovements[i],bs);v(vert.x,vert.y,depth+z);}// expand holes
|
2102 | for(h=0,hl=holes.length;h<hl;h++){ahole=holes[h];oneHoleMovements=holesMovements[h];for(i=0,il=ahole.length;i<il;i++){vert=scalePt2(ahole[i],oneHoleMovements[i],bs);if(!extrudeByPath){v(vert.x,vert.y,depth+z);}else {v(vert.x,vert.y+extrudePts[steps-1].y,extrudePts[steps-1].x+z);}}}}/* Faces */ // Top and bottom faces
|
2103 | buildLidFaces();// Sides faces
|
2104 | buildSideFaces();///// Internal functions
|
2105 | function buildLidFaces(){var start=verticesArray.length/3;if(bevelEnabled){var layer=0;// steps + 1
|
2106 | var offset=vlen*layer;// Bottom faces
|
2107 | for(i=0;i<flen;i++){face=faces[i];f3(face[2]+offset,face[1]+offset,face[0]+offset);}layer=steps+bevelSegments*2;offset=vlen*layer;// Top faces
|
2108 | for(i=0;i<flen;i++){face=faces[i];f3(face[0]+offset,face[1]+offset,face[2]+offset);}}else {// Bottom faces
|
2109 | for(i=0;i<flen;i++){face=faces[i];f3(face[2],face[1],face[0]);}// Top faces
|
2110 | for(i=0;i<flen;i++){face=faces[i];f3(face[0]+vlen*steps,face[1]+vlen*steps,face[2]+vlen*steps);}}scope.addGroup(start,verticesArray.length/3-start,0);}// Create faces for the z-sides of the shape
|
2111 | function buildSideFaces(){var start=verticesArray.length/3;var layeroffset=0;sidewalls(contour,layeroffset);layeroffset+=contour.length;for(h=0,hl=holes.length;h<hl;h++){ahole=holes[h];sidewalls(ahole,layeroffset);//, true
|
2112 | layeroffset+=ahole.length;}scope.addGroup(start,verticesArray.length/3-start,1);}function sidewalls(contour,layeroffset){var j,k;i=contour.length;while(--i>=0){j=i;k=i-1;if(k<0)k=contour.length-1;//console.log('b', i,j, i-1, k,vertices.length);
|
2113 | var s=0,sl=steps+bevelSegments*2;for(s=0;s<sl;s++){var slen1=vlen*s;var slen2=vlen*(s+1);var a=layeroffset+j+slen1,b=layeroffset+k+slen1,c=layeroffset+k+slen2,d=layeroffset+j+slen2;f4(a,b,c,d);}}}function v(x,y,z){placeholder.push(x);placeholder.push(y);placeholder.push(z);}function f3(a,b,c){addVertex(a);addVertex(b);addVertex(c);var nextIndex=verticesArray.length/3;var uvs=uvgen.generateTopUV(scope,verticesArray,nextIndex-3,nextIndex-2,nextIndex-1);addUV(uvs[0]);addUV(uvs[1]);addUV(uvs[2]);}function f4(a,b,c,d){addVertex(a);addVertex(b);addVertex(d);addVertex(b);addVertex(c);addVertex(d);var nextIndex=verticesArray.length/3;var uvs=uvgen.generateSideWallUV(scope,verticesArray,nextIndex-6,nextIndex-3,nextIndex-2,nextIndex-1);addUV(uvs[0]);addUV(uvs[1]);addUV(uvs[3]);addUV(uvs[1]);addUV(uvs[2]);addUV(uvs[3]);}function addVertex(index){verticesArray.push(placeholder[index*3+0]);verticesArray.push(placeholder[index*3+1]);verticesArray.push(placeholder[index*3+2]);}function addUV(vector2){uvArray.push(vector2.x);uvArray.push(vector2.y);}}}ExtrudeBufferGeometry.prototype=Object.create(BufferGeometry.prototype);ExtrudeBufferGeometry.prototype.constructor=ExtrudeBufferGeometry;ExtrudeBufferGeometry.prototype.toJSON=function(){var data=BufferGeometry.prototype.toJSON.call(this);var shapes=this.parameters.shapes;var options=this.parameters.options;return toJSON(shapes,options,data);};//
|
2114 | var WorldUVGenerator={generateTopUV:function generateTopUV(geometry,vertices,indexA,indexB,indexC){var a_x=vertices[indexA*3];var a_y=vertices[indexA*3+1];var b_x=vertices[indexB*3];var b_y=vertices[indexB*3+1];var c_x=vertices[indexC*3];var c_y=vertices[indexC*3+1];return [new Vector2(a_x,a_y),new Vector2(b_x,b_y),new Vector2(c_x,c_y)];},generateSideWallUV:function generateSideWallUV(geometry,vertices,indexA,indexB,indexC,indexD){var a_x=vertices[indexA*3];var a_y=vertices[indexA*3+1];var a_z=vertices[indexA*3+2];var b_x=vertices[indexB*3];var b_y=vertices[indexB*3+1];var b_z=vertices[indexB*3+2];var c_x=vertices[indexC*3];var c_y=vertices[indexC*3+1];var c_z=vertices[indexC*3+2];var d_x=vertices[indexD*3];var d_y=vertices[indexD*3+1];var d_z=vertices[indexD*3+2];if(Math.abs(a_y-b_y)<0.01){return [new Vector2(a_x,1-a_z),new Vector2(b_x,1-b_z),new Vector2(c_x,1-c_z),new Vector2(d_x,1-d_z)];}else {return [new Vector2(a_y,1-a_z),new Vector2(b_y,1-b_z),new Vector2(c_y,1-c_z),new Vector2(d_y,1-d_z)];}}};function toJSON(shapes,options,data){//
|
2115 | data.shapes=[];if(Array.isArray(shapes)){for(var i=0,l=shapes.length;i<l;i++){var shape=shapes[i];data.shapes.push(shape.uuid);}}else {data.shapes.push(shapes.uuid);}//
|
2116 | if(options.extrudePath!==undefined)data.options.extrudePath=options.extrudePath.toJSON();return data;}/**
|
2117 | * @author zz85 / http://www.lab4games.net/zz85/blog
|
2118 | * @author alteredq / http://alteredqualia.com/
|
2119 | *
|
2120 | * Text = 3D Text
|
2121 | *
|
2122 | * parameters = {
|
2123 | * font: <THREE.Font>, // font
|
2124 | *
|
2125 | * size: <float>, // size of the text
|
2126 | * height: <float>, // thickness to extrude text
|
2127 | * curveSegments: <int>, // number of points on the curves
|
2128 | *
|
2129 | * bevelEnabled: <bool>, // turn on bevel
|
2130 | * bevelThickness: <float>, // how deep into text bevel goes
|
2131 | * bevelSize: <float>, // how far from text outline (including bevelOffset) is bevel
|
2132 | * bevelOffset: <float> // how far from text outline does bevel start
|
2133 | * }
|
2134 | */ // TextGeometry
|
2135 | function TextGeometry(text,parameters){Geometry.call(this);this.type='TextGeometry';this.parameters={text:text,parameters:parameters};this.fromBufferGeometry(new TextBufferGeometry(text,parameters));this.mergeVertices();}TextGeometry.prototype=Object.create(Geometry.prototype);TextGeometry.prototype.constructor=TextGeometry;// TextBufferGeometry
|
2136 | function TextBufferGeometry(text,parameters){parameters=parameters||{};var font=parameters.font;if(!(font&&font.isFont)){console.error('THREE.TextGeometry: font parameter is not an instance of THREE.Font.');return new Geometry();}var shapes=font.generateShapes(text,parameters.size);// translate parameters to ExtrudeGeometry API
|
2137 | parameters.depth=parameters.height!==undefined?parameters.height:50;// defaults
|
2138 | if(parameters.bevelThickness===undefined)parameters.bevelThickness=10;if(parameters.bevelSize===undefined)parameters.bevelSize=8;if(parameters.bevelEnabled===undefined)parameters.bevelEnabled=false;ExtrudeBufferGeometry.call(this,shapes,parameters);this.type='TextBufferGeometry';}TextBufferGeometry.prototype=Object.create(ExtrudeBufferGeometry.prototype);TextBufferGeometry.prototype.constructor=TextBufferGeometry;/**
|
2139 | * @author mrdoob / http://mrdoob.com/
|
2140 | * @author benaadams / https://twitter.com/ben_a_adams
|
2141 | * @author Mugen87 / https://github.com/Mugen87
|
2142 | */ // SphereGeometry
|
2143 | function SphereGeometry(radius,widthSegments,heightSegments,phiStart,phiLength,thetaStart,thetaLength){Geometry.call(this);this.type='SphereGeometry';this.parameters={radius:radius,widthSegments:widthSegments,heightSegments:heightSegments,phiStart:phiStart,phiLength:phiLength,thetaStart:thetaStart,thetaLength:thetaLength};this.fromBufferGeometry(new SphereBufferGeometry(radius,widthSegments,heightSegments,phiStart,phiLength,thetaStart,thetaLength));this.mergeVertices();}SphereGeometry.prototype=Object.create(Geometry.prototype);SphereGeometry.prototype.constructor=SphereGeometry;// SphereBufferGeometry
|
2144 | function SphereBufferGeometry(radius,widthSegments,heightSegments,phiStart,phiLength,thetaStart,thetaLength){BufferGeometry.call(this);this.type='SphereBufferGeometry';this.parameters={radius:radius,widthSegments:widthSegments,heightSegments:heightSegments,phiStart:phiStart,phiLength:phiLength,thetaStart:thetaStart,thetaLength:thetaLength};radius=radius||1;widthSegments=Math.max(3,Math.floor(widthSegments)||8);heightSegments=Math.max(2,Math.floor(heightSegments)||6);phiStart=phiStart!==undefined?phiStart:0;phiLength=phiLength!==undefined?phiLength:Math.PI*2;thetaStart=thetaStart!==undefined?thetaStart:0;thetaLength=thetaLength!==undefined?thetaLength:Math.PI;var thetaEnd=Math.min(thetaStart+thetaLength,Math.PI);var ix,iy;var index=0;var grid=[];var vertex=new Vector3();var normal=new Vector3();// buffers
|
2145 | var indices=[];var vertices=[];var normals=[];var uvs=[];// generate vertices, normals and uvs
|
2146 | for(iy=0;iy<=heightSegments;iy++){var verticesRow=[];var v=iy/heightSegments;// special case for the poles
|
2147 | var uOffset=0;if(iy==0&&thetaStart==0){uOffset=0.5/widthSegments;}else if(iy==heightSegments&&thetaEnd==Math.PI){uOffset=-0.5/widthSegments;}for(ix=0;ix<=widthSegments;ix++){var u=ix/widthSegments;// vertex
|
2148 | vertex.x=-radius*Math.cos(phiStart+u*phiLength)*Math.sin(thetaStart+v*thetaLength);vertex.y=radius*Math.cos(thetaStart+v*thetaLength);vertex.z=radius*Math.sin(phiStart+u*phiLength)*Math.sin(thetaStart+v*thetaLength);vertices.push(vertex.x,vertex.y,vertex.z);// normal
|
2149 | normal.copy(vertex).normalize();normals.push(normal.x,normal.y,normal.z);// uv
|
2150 | uvs.push(u+uOffset,1-v);verticesRow.push(index++);}grid.push(verticesRow);}// indices
|
2151 | for(iy=0;iy<heightSegments;iy++){for(ix=0;ix<widthSegments;ix++){var a=grid[iy][ix+1];var b=grid[iy][ix];var c=grid[iy+1][ix];var d=grid[iy+1][ix+1];if(iy!==0||thetaStart>0)indices.push(a,b,d);if(iy!==heightSegments-1||thetaEnd<Math.PI)indices.push(b,c,d);}}// build geometry
|
2152 | this.setIndex(indices);this.setAttribute('position',new Float32BufferAttribute(vertices,3));this.setAttribute('normal',new Float32BufferAttribute(normals,3));this.setAttribute('uv',new Float32BufferAttribute(uvs,2));}SphereBufferGeometry.prototype=Object.create(BufferGeometry.prototype);SphereBufferGeometry.prototype.constructor=SphereBufferGeometry;/**
|
2153 | * @author Kaleb Murphy
|
2154 | * @author Mugen87 / https://github.com/Mugen87
|
2155 | */ // RingGeometry
|
2156 | function RingGeometry(innerRadius,outerRadius,thetaSegments,phiSegments,thetaStart,thetaLength){Geometry.call(this);this.type='RingGeometry';this.parameters={innerRadius:innerRadius,outerRadius:outerRadius,thetaSegments:thetaSegments,phiSegments:phiSegments,thetaStart:thetaStart,thetaLength:thetaLength};this.fromBufferGeometry(new RingBufferGeometry(innerRadius,outerRadius,thetaSegments,phiSegments,thetaStart,thetaLength));this.mergeVertices();}RingGeometry.prototype=Object.create(Geometry.prototype);RingGeometry.prototype.constructor=RingGeometry;// RingBufferGeometry
|
2157 | function RingBufferGeometry(innerRadius,outerRadius,thetaSegments,phiSegments,thetaStart,thetaLength){BufferGeometry.call(this);this.type='RingBufferGeometry';this.parameters={innerRadius:innerRadius,outerRadius:outerRadius,thetaSegments:thetaSegments,phiSegments:phiSegments,thetaStart:thetaStart,thetaLength:thetaLength};innerRadius=innerRadius||0.5;outerRadius=outerRadius||1;thetaStart=thetaStart!==undefined?thetaStart:0;thetaLength=thetaLength!==undefined?thetaLength:Math.PI*2;thetaSegments=thetaSegments!==undefined?Math.max(3,thetaSegments):8;phiSegments=phiSegments!==undefined?Math.max(1,phiSegments):1;// buffers
|
2158 | var indices=[];var vertices=[];var normals=[];var uvs=[];// some helper variables
|
2159 | var segment;var radius=innerRadius;var radiusStep=(outerRadius-innerRadius)/phiSegments;var vertex=new Vector3();var uv=new Vector2();var j,i;// generate vertices, normals and uvs
|
2160 | for(j=0;j<=phiSegments;j++){for(i=0;i<=thetaSegments;i++){// values are generate from the inside of the ring to the outside
|
2161 | segment=thetaStart+i/thetaSegments*thetaLength;// vertex
|
2162 | vertex.x=radius*Math.cos(segment);vertex.y=radius*Math.sin(segment);vertices.push(vertex.x,vertex.y,vertex.z);// normal
|
2163 | normals.push(0,0,1);// uv
|
2164 | uv.x=(vertex.x/outerRadius+1)/2;uv.y=(vertex.y/outerRadius+1)/2;uvs.push(uv.x,uv.y);}// increase the radius for next row of vertices
|
2165 | radius+=radiusStep;}// indices
|
2166 | for(j=0;j<phiSegments;j++){var thetaSegmentLevel=j*(thetaSegments+1);for(i=0;i<thetaSegments;i++){segment=i+thetaSegmentLevel;var a=segment;var b=segment+thetaSegments+1;var c=segment+thetaSegments+2;var d=segment+1;// faces
|
2167 | indices.push(a,b,d);indices.push(b,c,d);}}// build geometry
|
2168 | this.setIndex(indices);this.setAttribute('position',new Float32BufferAttribute(vertices,3));this.setAttribute('normal',new Float32BufferAttribute(normals,3));this.setAttribute('uv',new Float32BufferAttribute(uvs,2));}RingBufferGeometry.prototype=Object.create(BufferGeometry.prototype);RingBufferGeometry.prototype.constructor=RingBufferGeometry;/**
|
2169 | * @author zz85 / https://github.com/zz85
|
2170 | * @author bhouston / http://clara.io
|
2171 | * @author Mugen87 / https://github.com/Mugen87
|
2172 | */ // LatheGeometry
|
2173 | function LatheGeometry(points,segments,phiStart,phiLength){Geometry.call(this);this.type='LatheGeometry';this.parameters={points:points,segments:segments,phiStart:phiStart,phiLength:phiLength};this.fromBufferGeometry(new LatheBufferGeometry(points,segments,phiStart,phiLength));this.mergeVertices();}LatheGeometry.prototype=Object.create(Geometry.prototype);LatheGeometry.prototype.constructor=LatheGeometry;// LatheBufferGeometry
|
2174 | function LatheBufferGeometry(points,segments,phiStart,phiLength){BufferGeometry.call(this);this.type='LatheBufferGeometry';this.parameters={points:points,segments:segments,phiStart:phiStart,phiLength:phiLength};segments=Math.floor(segments)||12;phiStart=phiStart||0;phiLength=phiLength||Math.PI*2;// clamp phiLength so it's in range of [ 0, 2PI ]
|
2175 | phiLength=MathUtils.clamp(phiLength,0,Math.PI*2);// buffers
|
2176 | var indices=[];var vertices=[];var uvs=[];// helper variables
|
2177 | var base;var inverseSegments=1.0/segments;var vertex=new Vector3();var uv=new Vector2();var i,j;// generate vertices and uvs
|
2178 | for(i=0;i<=segments;i++){var phi=phiStart+i*inverseSegments*phiLength;var sin=Math.sin(phi);var cos=Math.cos(phi);for(j=0;j<=points.length-1;j++){// vertex
|
2179 | vertex.x=points[j].x*sin;vertex.y=points[j].y;vertex.z=points[j].x*cos;vertices.push(vertex.x,vertex.y,vertex.z);// uv
|
2180 | uv.x=i/segments;uv.y=j/(points.length-1);uvs.push(uv.x,uv.y);}}// indices
|
2181 | for(i=0;i<segments;i++){for(j=0;j<points.length-1;j++){base=j+i*points.length;var a=base;var b=base+points.length;var c=base+points.length+1;var d=base+1;// faces
|
2182 | indices.push(a,b,d);indices.push(b,c,d);}}// build geometry
|
2183 | this.setIndex(indices);this.setAttribute('position',new Float32BufferAttribute(vertices,3));this.setAttribute('uv',new Float32BufferAttribute(uvs,2));// generate normals
|
2184 | this.computeVertexNormals();// if the geometry is closed, we need to average the normals along the seam.
|
2185 | // because the corresponding vertices are identical (but still have different UVs).
|
2186 | if(phiLength===Math.PI*2){var normals=this.attributes.normal.array;var n1=new Vector3();var n2=new Vector3();var n=new Vector3();// this is the buffer offset for the last line of vertices
|
2187 | base=segments*points.length*3;for(i=0,j=0;i<points.length;i++,j+=3){// select the normal of the vertex in the first line
|
2188 | n1.x=normals[j+0];n1.y=normals[j+1];n1.z=normals[j+2];// select the normal of the vertex in the last line
|
2189 | n2.x=normals[base+j+0];n2.y=normals[base+j+1];n2.z=normals[base+j+2];// average normals
|
2190 | n.addVectors(n1,n2).normalize();// assign the new values to both normals
|
2191 | normals[j+0]=normals[base+j+0]=n.x;normals[j+1]=normals[base+j+1]=n.y;normals[j+2]=normals[base+j+2]=n.z;}}}LatheBufferGeometry.prototype=Object.create(BufferGeometry.prototype);LatheBufferGeometry.prototype.constructor=LatheBufferGeometry;/**
|
2192 | * @author jonobr1 / http://jonobr1.com
|
2193 | * @author Mugen87 / https://github.com/Mugen87
|
2194 | */ // ShapeGeometry
|
2195 | function ShapeGeometry(shapes,curveSegments){Geometry.call(this);this.type='ShapeGeometry';if(typeof curveSegments==='object'){console.warn('THREE.ShapeGeometry: Options parameter has been removed.');curveSegments=curveSegments.curveSegments;}this.parameters={shapes:shapes,curveSegments:curveSegments};this.fromBufferGeometry(new ShapeBufferGeometry(shapes,curveSegments));this.mergeVertices();}ShapeGeometry.prototype=Object.create(Geometry.prototype);ShapeGeometry.prototype.constructor=ShapeGeometry;ShapeGeometry.prototype.toJSON=function(){var data=Geometry.prototype.toJSON.call(this);var shapes=this.parameters.shapes;return toJSON$1(shapes,data);};// ShapeBufferGeometry
|
2196 | function ShapeBufferGeometry(shapes,curveSegments){BufferGeometry.call(this);this.type='ShapeBufferGeometry';this.parameters={shapes:shapes,curveSegments:curveSegments};curveSegments=curveSegments||12;// buffers
|
2197 | var indices=[];var vertices=[];var normals=[];var uvs=[];// helper variables
|
2198 | var groupStart=0;var groupCount=0;// allow single and array values for "shapes" parameter
|
2199 | if(Array.isArray(shapes)===false){addShape(shapes);}else {for(var i=0;i<shapes.length;i++){addShape(shapes[i]);this.addGroup(groupStart,groupCount,i);// enables MultiMaterial support
|
2200 | groupStart+=groupCount;groupCount=0;}}// build geometry
|
2201 | this.setIndex(indices);this.setAttribute('position',new Float32BufferAttribute(vertices,3));this.setAttribute('normal',new Float32BufferAttribute(normals,3));this.setAttribute('uv',new Float32BufferAttribute(uvs,2));// helper functions
|
2202 | function addShape(shape){var i,l,shapeHole;var indexOffset=vertices.length/3;var points=shape.extractPoints(curveSegments);var shapeVertices=points.shape;var shapeHoles=points.holes;// check direction of vertices
|
2203 | if(ShapeUtils.isClockWise(shapeVertices)===false){shapeVertices=shapeVertices.reverse();}for(i=0,l=shapeHoles.length;i<l;i++){shapeHole=shapeHoles[i];if(ShapeUtils.isClockWise(shapeHole)===true){shapeHoles[i]=shapeHole.reverse();}}var faces=ShapeUtils.triangulateShape(shapeVertices,shapeHoles);// join vertices of inner and outer paths to a single array
|
2204 | for(i=0,l=shapeHoles.length;i<l;i++){shapeHole=shapeHoles[i];shapeVertices=shapeVertices.concat(shapeHole);}// vertices, normals, uvs
|
2205 | for(i=0,l=shapeVertices.length;i<l;i++){var vertex=shapeVertices[i];vertices.push(vertex.x,vertex.y,0);normals.push(0,0,1);uvs.push(vertex.x,vertex.y);// world uvs
|
2206 | }// incides
|
2207 | for(i=0,l=faces.length;i<l;i++){var face=faces[i];var a=face[0]+indexOffset;var b=face[1]+indexOffset;var c=face[2]+indexOffset;indices.push(a,b,c);groupCount+=3;}}}ShapeBufferGeometry.prototype=Object.create(BufferGeometry.prototype);ShapeBufferGeometry.prototype.constructor=ShapeBufferGeometry;ShapeBufferGeometry.prototype.toJSON=function(){var data=BufferGeometry.prototype.toJSON.call(this);var shapes=this.parameters.shapes;return toJSON$1(shapes,data);};//
|
2208 | function toJSON$1(shapes,data){data.shapes=[];if(Array.isArray(shapes)){for(var i=0,l=shapes.length;i<l;i++){var shape=shapes[i];data.shapes.push(shape.uuid);}}else {data.shapes.push(shapes.uuid);}return data;}/**
|
2209 | * @author WestLangley / http://github.com/WestLangley
|
2210 | * @author Mugen87 / https://github.com/Mugen87
|
2211 | */function EdgesGeometry(geometry,thresholdAngle){BufferGeometry.call(this);this.type='EdgesGeometry';this.parameters={thresholdAngle:thresholdAngle};thresholdAngle=thresholdAngle!==undefined?thresholdAngle:1;// buffer
|
2212 | var vertices=[];// helper variables
|
2213 | var thresholdDot=Math.cos(MathUtils.DEG2RAD*thresholdAngle);var edge=[0,0],edges={},edge1,edge2;var key,keys=['a','b','c'];// prepare source geometry
|
2214 | var geometry2;if(geometry.isBufferGeometry){geometry2=new Geometry();geometry2.fromBufferGeometry(geometry);}else {geometry2=geometry.clone();}geometry2.mergeVertices();geometry2.computeFaceNormals();var sourceVertices=geometry2.vertices;var faces=geometry2.faces;// now create a data structure where each entry represents an edge with its adjoining faces
|
2215 | for(var i=0,l=faces.length;i<l;i++){var face=faces[i];for(var j=0;j<3;j++){edge1=face[keys[j]];edge2=face[keys[(j+1)%3]];edge[0]=Math.min(edge1,edge2);edge[1]=Math.max(edge1,edge2);key=edge[0]+','+edge[1];if(edges[key]===undefined){edges[key]={index1:edge[0],index2:edge[1],face1:i,face2:undefined};}else {edges[key].face2=i;}}}// generate vertices
|
2216 | for(key in edges){var e=edges[key];// an edge is only rendered if the angle (in degrees) between the face normals of the adjoining faces exceeds this value. default = 1 degree.
|
2217 | if(e.face2===undefined||faces[e.face1].normal.dot(faces[e.face2].normal)<=thresholdDot){var vertex=sourceVertices[e.index1];vertices.push(vertex.x,vertex.y,vertex.z);vertex=sourceVertices[e.index2];vertices.push(vertex.x,vertex.y,vertex.z);}}// build geometry
|
2218 | this.setAttribute('position',new Float32BufferAttribute(vertices,3));}EdgesGeometry.prototype=Object.create(BufferGeometry.prototype);EdgesGeometry.prototype.constructor=EdgesGeometry;/**
|
2219 | * @author mrdoob / http://mrdoob.com/
|
2220 | * @author Mugen87 / https://github.com/Mugen87
|
2221 | */ // CylinderGeometry
|
2222 | function CylinderGeometry(radiusTop,radiusBottom,height,radialSegments,heightSegments,openEnded,thetaStart,thetaLength){Geometry.call(this);this.type='CylinderGeometry';this.parameters={radiusTop:radiusTop,radiusBottom:radiusBottom,height:height,radialSegments:radialSegments,heightSegments:heightSegments,openEnded:openEnded,thetaStart:thetaStart,thetaLength:thetaLength};this.fromBufferGeometry(new CylinderBufferGeometry(radiusTop,radiusBottom,height,radialSegments,heightSegments,openEnded,thetaStart,thetaLength));this.mergeVertices();}CylinderGeometry.prototype=Object.create(Geometry.prototype);CylinderGeometry.prototype.constructor=CylinderGeometry;// CylinderBufferGeometry
|
2223 | function CylinderBufferGeometry(radiusTop,radiusBottom,height,radialSegments,heightSegments,openEnded,thetaStart,thetaLength){BufferGeometry.call(this);this.type='CylinderBufferGeometry';this.parameters={radiusTop:radiusTop,radiusBottom:radiusBottom,height:height,radialSegments:radialSegments,heightSegments:heightSegments,openEnded:openEnded,thetaStart:thetaStart,thetaLength:thetaLength};var scope=this;radiusTop=radiusTop!==undefined?radiusTop:1;radiusBottom=radiusBottom!==undefined?radiusBottom:1;height=height||1;radialSegments=Math.floor(radialSegments)||8;heightSegments=Math.floor(heightSegments)||1;openEnded=openEnded!==undefined?openEnded:false;thetaStart=thetaStart!==undefined?thetaStart:0.0;thetaLength=thetaLength!==undefined?thetaLength:Math.PI*2;// buffers
|
2224 | var indices=[];var vertices=[];var normals=[];var uvs=[];// helper variables
|
2225 | var index=0;var indexArray=[];var halfHeight=height/2;var groupStart=0;// generate geometry
|
2226 | generateTorso();if(openEnded===false){if(radiusTop>0)generateCap(true);if(radiusBottom>0)generateCap(false);}// build geometry
|
2227 | this.setIndex(indices);this.setAttribute('position',new Float32BufferAttribute(vertices,3));this.setAttribute('normal',new Float32BufferAttribute(normals,3));this.setAttribute('uv',new Float32BufferAttribute(uvs,2));function generateTorso(){var x,y;var normal=new Vector3();var vertex=new Vector3();var groupCount=0;// this will be used to calculate the normal
|
2228 | var slope=(radiusBottom-radiusTop)/height;// generate vertices, normals and uvs
|
2229 | for(y=0;y<=heightSegments;y++){var indexRow=[];var v=y/heightSegments;// calculate the radius of the current row
|
2230 | var radius=v*(radiusBottom-radiusTop)+radiusTop;for(x=0;x<=radialSegments;x++){var u=x/radialSegments;var theta=u*thetaLength+thetaStart;var sinTheta=Math.sin(theta);var cosTheta=Math.cos(theta);// vertex
|
2231 | vertex.x=radius*sinTheta;vertex.y=-v*height+halfHeight;vertex.z=radius*cosTheta;vertices.push(vertex.x,vertex.y,vertex.z);// normal
|
2232 | normal.set(sinTheta,slope,cosTheta).normalize();normals.push(normal.x,normal.y,normal.z);// uv
|
2233 | uvs.push(u,1-v);// save index of vertex in respective row
|
2234 | indexRow.push(index++);}// now save vertices of the row in our index array
|
2235 | indexArray.push(indexRow);}// generate indices
|
2236 | for(x=0;x<radialSegments;x++){for(y=0;y<heightSegments;y++){// we use the index array to access the correct indices
|
2237 | var a=indexArray[y][x];var b=indexArray[y+1][x];var c=indexArray[y+1][x+1];var d=indexArray[y][x+1];// faces
|
2238 | indices.push(a,b,d);indices.push(b,c,d);// update group counter
|
2239 | groupCount+=6;}}// add a group to the geometry. this will ensure multi material support
|
2240 | scope.addGroup(groupStart,groupCount,0);// calculate new start value for groups
|
2241 | groupStart+=groupCount;}function generateCap(top){var x,centerIndexStart,centerIndexEnd;var uv=new Vector2();var vertex=new Vector3();var groupCount=0;var radius=top===true?radiusTop:radiusBottom;var sign=top===true?1:-1;// save the index of the first center vertex
|
2242 | centerIndexStart=index;// first we generate the center vertex data of the cap.
|
2243 | // because the geometry needs one set of uvs per face,
|
2244 | // we must generate a center vertex per face/segment
|
2245 | for(x=1;x<=radialSegments;x++){// vertex
|
2246 | vertices.push(0,halfHeight*sign,0);// normal
|
2247 | normals.push(0,sign,0);// uv
|
2248 | uvs.push(0.5,0.5);// increase index
|
2249 | index++;}// save the index of the last center vertex
|
2250 | centerIndexEnd=index;// now we generate the surrounding vertices, normals and uvs
|
2251 | for(x=0;x<=radialSegments;x++){var u=x/radialSegments;var theta=u*thetaLength+thetaStart;var cosTheta=Math.cos(theta);var sinTheta=Math.sin(theta);// vertex
|
2252 | vertex.x=radius*sinTheta;vertex.y=halfHeight*sign;vertex.z=radius*cosTheta;vertices.push(vertex.x,vertex.y,vertex.z);// normal
|
2253 | normals.push(0,sign,0);// uv
|
2254 | uv.x=cosTheta*0.5+0.5;uv.y=sinTheta*0.5*sign+0.5;uvs.push(uv.x,uv.y);// increase index
|
2255 | index++;}// generate indices
|
2256 | for(x=0;x<radialSegments;x++){var c=centerIndexStart+x;var i=centerIndexEnd+x;if(top===true){// face top
|
2257 | indices.push(i,i+1,c);}else {// face bottom
|
2258 | indices.push(i+1,i,c);}groupCount+=3;}// add a group to the geometry. this will ensure multi material support
|
2259 | scope.addGroup(groupStart,groupCount,top===true?1:2);// calculate new start value for groups
|
2260 | groupStart+=groupCount;}}CylinderBufferGeometry.prototype=Object.create(BufferGeometry.prototype);CylinderBufferGeometry.prototype.constructor=CylinderBufferGeometry;/**
|
2261 | * @author abelnation / http://github.com/abelnation
|
2262 | */ // ConeGeometry
|
2263 | function ConeGeometry(radius,height,radialSegments,heightSegments,openEnded,thetaStart,thetaLength){CylinderGeometry.call(this,0,radius,height,radialSegments,heightSegments,openEnded,thetaStart,thetaLength);this.type='ConeGeometry';this.parameters={radius:radius,height:height,radialSegments:radialSegments,heightSegments:heightSegments,openEnded:openEnded,thetaStart:thetaStart,thetaLength:thetaLength};}ConeGeometry.prototype=Object.create(CylinderGeometry.prototype);ConeGeometry.prototype.constructor=ConeGeometry;// ConeBufferGeometry
|
2264 | function ConeBufferGeometry(radius,height,radialSegments,heightSegments,openEnded,thetaStart,thetaLength){CylinderBufferGeometry.call(this,0,radius,height,radialSegments,heightSegments,openEnded,thetaStart,thetaLength);this.type='ConeBufferGeometry';this.parameters={radius:radius,height:height,radialSegments:radialSegments,heightSegments:heightSegments,openEnded:openEnded,thetaStart:thetaStart,thetaLength:thetaLength};}ConeBufferGeometry.prototype=Object.create(CylinderBufferGeometry.prototype);ConeBufferGeometry.prototype.constructor=ConeBufferGeometry;/**
|
2265 | * @author benaadams / https://twitter.com/ben_a_adams
|
2266 | * @author Mugen87 / https://github.com/Mugen87
|
2267 | * @author hughes
|
2268 | */ // CircleGeometry
|
2269 | function CircleGeometry(radius,segments,thetaStart,thetaLength){Geometry.call(this);this.type='CircleGeometry';this.parameters={radius:radius,segments:segments,thetaStart:thetaStart,thetaLength:thetaLength};this.fromBufferGeometry(new CircleBufferGeometry(radius,segments,thetaStart,thetaLength));this.mergeVertices();}CircleGeometry.prototype=Object.create(Geometry.prototype);CircleGeometry.prototype.constructor=CircleGeometry;// CircleBufferGeometry
|
2270 | function CircleBufferGeometry(radius,segments,thetaStart,thetaLength){BufferGeometry.call(this);this.type='CircleBufferGeometry';this.parameters={radius:radius,segments:segments,thetaStart:thetaStart,thetaLength:thetaLength};radius=radius||1;segments=segments!==undefined?Math.max(3,segments):8;thetaStart=thetaStart!==undefined?thetaStart:0;thetaLength=thetaLength!==undefined?thetaLength:Math.PI*2;// buffers
|
2271 | var indices=[];var vertices=[];var normals=[];var uvs=[];// helper variables
|
2272 | var i,s;var vertex=new Vector3();var uv=new Vector2();// center point
|
2273 | vertices.push(0,0,0);normals.push(0,0,1);uvs.push(0.5,0.5);for(s=0,i=3;s<=segments;s++,i+=3){var segment=thetaStart+s/segments*thetaLength;// vertex
|
2274 | vertex.x=radius*Math.cos(segment);vertex.y=radius*Math.sin(segment);vertices.push(vertex.x,vertex.y,vertex.z);// normal
|
2275 | normals.push(0,0,1);// uvs
|
2276 | uv.x=(vertices[i]/radius+1)/2;uv.y=(vertices[i+1]/radius+1)/2;uvs.push(uv.x,uv.y);}// indices
|
2277 | for(i=1;i<=segments;i++){indices.push(i,i+1,0);}// build geometry
|
2278 | this.setIndex(indices);this.setAttribute('position',new Float32BufferAttribute(vertices,3));this.setAttribute('normal',new Float32BufferAttribute(normals,3));this.setAttribute('uv',new Float32BufferAttribute(uvs,2));}CircleBufferGeometry.prototype=Object.create(BufferGeometry.prototype);CircleBufferGeometry.prototype.constructor=CircleBufferGeometry;var Geometries=/*#__PURE__*/Object.freeze({__proto__:null,WireframeGeometry:WireframeGeometry,ParametricGeometry:ParametricGeometry,ParametricBufferGeometry:ParametricBufferGeometry,TetrahedronGeometry:TetrahedronGeometry,TetrahedronBufferGeometry:TetrahedronBufferGeometry,OctahedronGeometry:OctahedronGeometry,OctahedronBufferGeometry:OctahedronBufferGeometry,IcosahedronGeometry:IcosahedronGeometry,IcosahedronBufferGeometry:IcosahedronBufferGeometry,DodecahedronGeometry:DodecahedronGeometry,DodecahedronBufferGeometry:DodecahedronBufferGeometry,PolyhedronGeometry:PolyhedronGeometry,PolyhedronBufferGeometry:PolyhedronBufferGeometry,TubeGeometry:TubeGeometry,TubeBufferGeometry:TubeBufferGeometry,TorusKnotGeometry:TorusKnotGeometry,TorusKnotBufferGeometry:TorusKnotBufferGeometry,TorusGeometry:TorusGeometry,TorusBufferGeometry:TorusBufferGeometry,TextGeometry:TextGeometry,TextBufferGeometry:TextBufferGeometry,SphereGeometry:SphereGeometry,SphereBufferGeometry:SphereBufferGeometry,RingGeometry:RingGeometry,RingBufferGeometry:RingBufferGeometry,PlaneGeometry:PlaneGeometry,PlaneBufferGeometry:PlaneBufferGeometry,LatheGeometry:LatheGeometry,LatheBufferGeometry:LatheBufferGeometry,ShapeGeometry:ShapeGeometry,ShapeBufferGeometry:ShapeBufferGeometry,ExtrudeGeometry:ExtrudeGeometry,ExtrudeBufferGeometry:ExtrudeBufferGeometry,EdgesGeometry:EdgesGeometry,ConeGeometry:ConeGeometry,ConeBufferGeometry:ConeBufferGeometry,CylinderGeometry:CylinderGeometry,CylinderBufferGeometry:CylinderBufferGeometry,CircleGeometry:CircleGeometry,CircleBufferGeometry:CircleBufferGeometry,BoxGeometry:BoxGeometry,BoxBufferGeometry:BoxBufferGeometry});/**
|
2279 | * @author mrdoob / http://mrdoob.com/
|
2280 | *
|
2281 | * parameters = {
|
2282 | * color: <THREE.Color>
|
2283 | * }
|
2284 | */function ShadowMaterial(parameters){Material.call(this);this.type='ShadowMaterial';this.color=new Color(0x000000);this.transparent=true;this.setValues(parameters);}ShadowMaterial.prototype=Object.create(Material.prototype);ShadowMaterial.prototype.constructor=ShadowMaterial;ShadowMaterial.prototype.isShadowMaterial=true;ShadowMaterial.prototype.copy=function(source){Material.prototype.copy.call(this,source);this.color.copy(source.color);return this;};/**
|
2285 | * @author mrdoob / http://mrdoob.com/
|
2286 | */function RawShaderMaterial(parameters){ShaderMaterial.call(this,parameters);this.type='RawShaderMaterial';}RawShaderMaterial.prototype=Object.create(ShaderMaterial.prototype);RawShaderMaterial.prototype.constructor=RawShaderMaterial;RawShaderMaterial.prototype.isRawShaderMaterial=true;/**
|
2287 | * @author WestLangley / http://github.com/WestLangley
|
2288 | *
|
2289 | * parameters = {
|
2290 | * color: <hex>,
|
2291 | * roughness: <float>,
|
2292 | * metalness: <float>,
|
2293 | * opacity: <float>,
|
2294 | *
|
2295 | * map: new THREE.Texture( <Image> ),
|
2296 | *
|
2297 | * lightMap: new THREE.Texture( <Image> ),
|
2298 | * lightMapIntensity: <float>
|
2299 | *
|
2300 | * aoMap: new THREE.Texture( <Image> ),
|
2301 | * aoMapIntensity: <float>
|
2302 | *
|
2303 | * emissive: <hex>,
|
2304 | * emissiveIntensity: <float>
|
2305 | * emissiveMap: new THREE.Texture( <Image> ),
|
2306 | *
|
2307 | * bumpMap: new THREE.Texture( <Image> ),
|
2308 | * bumpScale: <float>,
|
2309 | *
|
2310 | * normalMap: new THREE.Texture( <Image> ),
|
2311 | * normalMapType: THREE.TangentSpaceNormalMap,
|
2312 | * normalScale: <Vector2>,
|
2313 | *
|
2314 | * displacementMap: new THREE.Texture( <Image> ),
|
2315 | * displacementScale: <float>,
|
2316 | * displacementBias: <float>,
|
2317 | *
|
2318 | * roughnessMap: new THREE.Texture( <Image> ),
|
2319 | *
|
2320 | * metalnessMap: new THREE.Texture( <Image> ),
|
2321 | *
|
2322 | * alphaMap: new THREE.Texture( <Image> ),
|
2323 | *
|
2324 | * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
|
2325 | * envMapIntensity: <float>
|
2326 | *
|
2327 | * refractionRatio: <float>,
|
2328 | *
|
2329 | * wireframe: <boolean>,
|
2330 | * wireframeLinewidth: <float>,
|
2331 | *
|
2332 | * skinning: <bool>,
|
2333 | * morphTargets: <bool>,
|
2334 | * morphNormals: <bool>
|
2335 | * }
|
2336 | */function MeshStandardMaterial(parameters){Material.call(this);this.defines={'STANDARD':''};this.type='MeshStandardMaterial';this.color=new Color(0xffffff);// diffuse
|
2337 | this.roughness=1.0;this.metalness=0.0;this.map=null;this.lightMap=null;this.lightMapIntensity=1.0;this.aoMap=null;this.aoMapIntensity=1.0;this.emissive=new Color(0x000000);this.emissiveIntensity=1.0;this.emissiveMap=null;this.bumpMap=null;this.bumpScale=1;this.normalMap=null;this.normalMapType=TangentSpaceNormalMap;this.normalScale=new Vector2(1,1);this.displacementMap=null;this.displacementScale=1;this.displacementBias=0;this.roughnessMap=null;this.metalnessMap=null;this.alphaMap=null;this.envMap=null;this.envMapIntensity=1.0;this.refractionRatio=0.98;this.wireframe=false;this.wireframeLinewidth=1;this.wireframeLinecap='round';this.wireframeLinejoin='round';this.skinning=false;this.morphTargets=false;this.morphNormals=false;this.vertexTangents=false;this.setValues(parameters);}MeshStandardMaterial.prototype=Object.create(Material.prototype);MeshStandardMaterial.prototype.constructor=MeshStandardMaterial;MeshStandardMaterial.prototype.isMeshStandardMaterial=true;MeshStandardMaterial.prototype.copy=function(source){Material.prototype.copy.call(this,source);this.defines={'STANDARD':''};this.color.copy(source.color);this.roughness=source.roughness;this.metalness=source.metalness;this.map=source.map;this.lightMap=source.lightMap;this.lightMapIntensity=source.lightMapIntensity;this.aoMap=source.aoMap;this.aoMapIntensity=source.aoMapIntensity;this.emissive.copy(source.emissive);this.emissiveMap=source.emissiveMap;this.emissiveIntensity=source.emissiveIntensity;this.bumpMap=source.bumpMap;this.bumpScale=source.bumpScale;this.normalMap=source.normalMap;this.normalMapType=source.normalMapType;this.normalScale.copy(source.normalScale);this.displacementMap=source.displacementMap;this.displacementScale=source.displacementScale;this.displacementBias=source.displacementBias;this.roughnessMap=source.roughnessMap;this.metalnessMap=source.metalnessMap;this.alphaMap=source.alphaMap;this.envMap=source.envMap;this.envMapIntensity=source.envMapIntensity;this.refractionRatio=source.refractionRatio;this.wireframe=source.wireframe;this.wireframeLinewidth=source.wireframeLinewidth;this.wireframeLinecap=source.wireframeLinecap;this.wireframeLinejoin=source.wireframeLinejoin;this.skinning=source.skinning;this.morphTargets=source.morphTargets;this.morphNormals=source.morphNormals;this.vertexTangents=source.vertexTangents;return this;};/**
|
2338 | * @author WestLangley / http://github.com/WestLangley
|
2339 | *
|
2340 | * parameters = {
|
2341 | * clearcoat: <float>,
|
2342 | * clearcoatMap: new THREE.Texture( <Image> ),
|
2343 | * clearcoatRoughness: <float>,
|
2344 | * clearcoatRoughnessMap: new THREE.Texture( <Image> ),
|
2345 | * clearcoatNormalScale: <Vector2>,
|
2346 | * clearcoatNormalMap: new THREE.Texture( <Image> ),
|
2347 | *
|
2348 | * reflectivity: <float>,
|
2349 | *
|
2350 | * sheen: <Color>,
|
2351 | *
|
2352 | * transparency: <float>
|
2353 | * }
|
2354 | */function MeshPhysicalMaterial(parameters){MeshStandardMaterial.call(this);this.defines={'STANDARD':'','PHYSICAL':''};this.type='MeshPhysicalMaterial';this.clearcoat=0.0;this.clearcoatMap=null;this.clearcoatRoughness=0.0;this.clearcoatRoughnessMap=null;this.clearcoatNormalScale=new Vector2(1,1);this.clearcoatNormalMap=null;this.reflectivity=0.5;// maps to F0 = 0.04
|
2355 | this.sheen=null;// null will disable sheen bsdf
|
2356 | this.transparency=0.0;this.setValues(parameters);}MeshPhysicalMaterial.prototype=Object.create(MeshStandardMaterial.prototype);MeshPhysicalMaterial.prototype.constructor=MeshPhysicalMaterial;MeshPhysicalMaterial.prototype.isMeshPhysicalMaterial=true;MeshPhysicalMaterial.prototype.copy=function(source){MeshStandardMaterial.prototype.copy.call(this,source);this.defines={'STANDARD':'','PHYSICAL':''};this.clearcoat=source.clearcoat;this.clearcoatMap=source.clearcoatMap;this.clearcoatRoughness=source.clearcoatRoughness;this.clearcoatRoughnessMap=source.clearcoatRoughnessMap;this.clearcoatNormalMap=source.clearcoatNormalMap;this.clearcoatNormalScale.copy(source.clearcoatNormalScale);this.reflectivity=source.reflectivity;if(source.sheen){this.sheen=(this.sheen||new Color()).copy(source.sheen);}else {this.sheen=null;}this.transparency=source.transparency;return this;};/**
|
2357 | * @author mrdoob / http://mrdoob.com/
|
2358 | * @author alteredq / http://alteredqualia.com/
|
2359 | *
|
2360 | * parameters = {
|
2361 | * color: <hex>,
|
2362 | * specular: <hex>,
|
2363 | * shininess: <float>,
|
2364 | * opacity: <float>,
|
2365 | *
|
2366 | * map: new THREE.Texture( <Image> ),
|
2367 | *
|
2368 | * lightMap: new THREE.Texture( <Image> ),
|
2369 | * lightMapIntensity: <float>
|
2370 | *
|
2371 | * aoMap: new THREE.Texture( <Image> ),
|
2372 | * aoMapIntensity: <float>
|
2373 | *
|
2374 | * emissive: <hex>,
|
2375 | * emissiveIntensity: <float>
|
2376 | * emissiveMap: new THREE.Texture( <Image> ),
|
2377 | *
|
2378 | * bumpMap: new THREE.Texture( <Image> ),
|
2379 | * bumpScale: <float>,
|
2380 | *
|
2381 | * normalMap: new THREE.Texture( <Image> ),
|
2382 | * normalMapType: THREE.TangentSpaceNormalMap,
|
2383 | * normalScale: <Vector2>,
|
2384 | *
|
2385 | * displacementMap: new THREE.Texture( <Image> ),
|
2386 | * displacementScale: <float>,
|
2387 | * displacementBias: <float>,
|
2388 | *
|
2389 | * specularMap: new THREE.Texture( <Image> ),
|
2390 | *
|
2391 | * alphaMap: new THREE.Texture( <Image> ),
|
2392 | *
|
2393 | * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
|
2394 | * combine: THREE.MultiplyOperation,
|
2395 | * reflectivity: <float>,
|
2396 | * refractionRatio: <float>,
|
2397 | *
|
2398 | * wireframe: <boolean>,
|
2399 | * wireframeLinewidth: <float>,
|
2400 | *
|
2401 | * skinning: <bool>,
|
2402 | * morphTargets: <bool>,
|
2403 | * morphNormals: <bool>
|
2404 | * }
|
2405 | */function MeshPhongMaterial(parameters){Material.call(this);this.type='MeshPhongMaterial';this.color=new Color(0xffffff);// diffuse
|
2406 | this.specular=new Color(0x111111);this.shininess=30;this.map=null;this.lightMap=null;this.lightMapIntensity=1.0;this.aoMap=null;this.aoMapIntensity=1.0;this.emissive=new Color(0x000000);this.emissiveIntensity=1.0;this.emissiveMap=null;this.bumpMap=null;this.bumpScale=1;this.normalMap=null;this.normalMapType=TangentSpaceNormalMap;this.normalScale=new Vector2(1,1);this.displacementMap=null;this.displacementScale=1;this.displacementBias=0;this.specularMap=null;this.alphaMap=null;this.envMap=null;this.combine=MultiplyOperation;this.reflectivity=1;this.refractionRatio=0.98;this.wireframe=false;this.wireframeLinewidth=1;this.wireframeLinecap='round';this.wireframeLinejoin='round';this.skinning=false;this.morphTargets=false;this.morphNormals=false;this.setValues(parameters);}MeshPhongMaterial.prototype=Object.create(Material.prototype);MeshPhongMaterial.prototype.constructor=MeshPhongMaterial;MeshPhongMaterial.prototype.isMeshPhongMaterial=true;MeshPhongMaterial.prototype.copy=function(source){Material.prototype.copy.call(this,source);this.color.copy(source.color);this.specular.copy(source.specular);this.shininess=source.shininess;this.map=source.map;this.lightMap=source.lightMap;this.lightMapIntensity=source.lightMapIntensity;this.aoMap=source.aoMap;this.aoMapIntensity=source.aoMapIntensity;this.emissive.copy(source.emissive);this.emissiveMap=source.emissiveMap;this.emissiveIntensity=source.emissiveIntensity;this.bumpMap=source.bumpMap;this.bumpScale=source.bumpScale;this.normalMap=source.normalMap;this.normalMapType=source.normalMapType;this.normalScale.copy(source.normalScale);this.displacementMap=source.displacementMap;this.displacementScale=source.displacementScale;this.displacementBias=source.displacementBias;this.specularMap=source.specularMap;this.alphaMap=source.alphaMap;this.envMap=source.envMap;this.combine=source.combine;this.reflectivity=source.reflectivity;this.refractionRatio=source.refractionRatio;this.wireframe=source.wireframe;this.wireframeLinewidth=source.wireframeLinewidth;this.wireframeLinecap=source.wireframeLinecap;this.wireframeLinejoin=source.wireframeLinejoin;this.skinning=source.skinning;this.morphTargets=source.morphTargets;this.morphNormals=source.morphNormals;return this;};/**
|
2407 | * @author takahirox / http://github.com/takahirox
|
2408 | *
|
2409 | * parameters = {
|
2410 | * color: <hex>,
|
2411 | * specular: <hex>,
|
2412 | * shininess: <float>,
|
2413 | *
|
2414 | * map: new THREE.Texture( <Image> ),
|
2415 | * gradientMap: new THREE.Texture( <Image> ),
|
2416 | *
|
2417 | * lightMap: new THREE.Texture( <Image> ),
|
2418 | * lightMapIntensity: <float>
|
2419 | *
|
2420 | * aoMap: new THREE.Texture( <Image> ),
|
2421 | * aoMapIntensity: <float>
|
2422 | *
|
2423 | * emissive: <hex>,
|
2424 | * emissiveIntensity: <float>
|
2425 | * emissiveMap: new THREE.Texture( <Image> ),
|
2426 | *
|
2427 | * bumpMap: new THREE.Texture( <Image> ),
|
2428 | * bumpScale: <float>,
|
2429 | *
|
2430 | * normalMap: new THREE.Texture( <Image> ),
|
2431 | * normalMapType: THREE.TangentSpaceNormalMap,
|
2432 | * normalScale: <Vector2>,
|
2433 | *
|
2434 | * displacementMap: new THREE.Texture( <Image> ),
|
2435 | * displacementScale: <float>,
|
2436 | * displacementBias: <float>,
|
2437 | *
|
2438 | * specularMap: new THREE.Texture( <Image> ),
|
2439 | *
|
2440 | * alphaMap: new THREE.Texture( <Image> ),
|
2441 | *
|
2442 | * wireframe: <boolean>,
|
2443 | * wireframeLinewidth: <float>,
|
2444 | *
|
2445 | * skinning: <bool>,
|
2446 | * morphTargets: <bool>,
|
2447 | * morphNormals: <bool>
|
2448 | * }
|
2449 | */function MeshToonMaterial(parameters){Material.call(this);this.defines={'TOON':''};this.type='MeshToonMaterial';this.color=new Color(0xffffff);this.specular=new Color(0x111111);this.shininess=30;this.map=null;this.gradientMap=null;this.lightMap=null;this.lightMapIntensity=1.0;this.aoMap=null;this.aoMapIntensity=1.0;this.emissive=new Color(0x000000);this.emissiveIntensity=1.0;this.emissiveMap=null;this.bumpMap=null;this.bumpScale=1;this.normalMap=null;this.normalMapType=TangentSpaceNormalMap;this.normalScale=new Vector2(1,1);this.displacementMap=null;this.displacementScale=1;this.displacementBias=0;this.specularMap=null;this.alphaMap=null;this.wireframe=false;this.wireframeLinewidth=1;this.wireframeLinecap='round';this.wireframeLinejoin='round';this.skinning=false;this.morphTargets=false;this.morphNormals=false;this.setValues(parameters);}MeshToonMaterial.prototype=Object.create(Material.prototype);MeshToonMaterial.prototype.constructor=MeshToonMaterial;MeshToonMaterial.prototype.isMeshToonMaterial=true;MeshToonMaterial.prototype.copy=function(source){Material.prototype.copy.call(this,source);this.color.copy(source.color);this.specular.copy(source.specular);this.shininess=source.shininess;this.map=source.map;this.gradientMap=source.gradientMap;this.lightMap=source.lightMap;this.lightMapIntensity=source.lightMapIntensity;this.aoMap=source.aoMap;this.aoMapIntensity=source.aoMapIntensity;this.emissive.copy(source.emissive);this.emissiveMap=source.emissiveMap;this.emissiveIntensity=source.emissiveIntensity;this.bumpMap=source.bumpMap;this.bumpScale=source.bumpScale;this.normalMap=source.normalMap;this.normalMapType=source.normalMapType;this.normalScale.copy(source.normalScale);this.displacementMap=source.displacementMap;this.displacementScale=source.displacementScale;this.displacementBias=source.displacementBias;this.specularMap=source.specularMap;this.alphaMap=source.alphaMap;this.wireframe=source.wireframe;this.wireframeLinewidth=source.wireframeLinewidth;this.wireframeLinecap=source.wireframeLinecap;this.wireframeLinejoin=source.wireframeLinejoin;this.skinning=source.skinning;this.morphTargets=source.morphTargets;this.morphNormals=source.morphNormals;return this;};/**
|
2450 | * @author mrdoob / http://mrdoob.com/
|
2451 | * @author WestLangley / http://github.com/WestLangley
|
2452 | *
|
2453 | * parameters = {
|
2454 | * opacity: <float>,
|
2455 | *
|
2456 | * bumpMap: new THREE.Texture( <Image> ),
|
2457 | * bumpScale: <float>,
|
2458 | *
|
2459 | * normalMap: new THREE.Texture( <Image> ),
|
2460 | * normalMapType: THREE.TangentSpaceNormalMap,
|
2461 | * normalScale: <Vector2>,
|
2462 | *
|
2463 | * displacementMap: new THREE.Texture( <Image> ),
|
2464 | * displacementScale: <float>,
|
2465 | * displacementBias: <float>,
|
2466 | *
|
2467 | * wireframe: <boolean>,
|
2468 | * wireframeLinewidth: <float>
|
2469 | *
|
2470 | * skinning: <bool>,
|
2471 | * morphTargets: <bool>,
|
2472 | * morphNormals: <bool>
|
2473 | * }
|
2474 | */function MeshNormalMaterial(parameters){Material.call(this);this.type='MeshNormalMaterial';this.bumpMap=null;this.bumpScale=1;this.normalMap=null;this.normalMapType=TangentSpaceNormalMap;this.normalScale=new Vector2(1,1);this.displacementMap=null;this.displacementScale=1;this.displacementBias=0;this.wireframe=false;this.wireframeLinewidth=1;this.fog=false;this.skinning=false;this.morphTargets=false;this.morphNormals=false;this.setValues(parameters);}MeshNormalMaterial.prototype=Object.create(Material.prototype);MeshNormalMaterial.prototype.constructor=MeshNormalMaterial;MeshNormalMaterial.prototype.isMeshNormalMaterial=true;MeshNormalMaterial.prototype.copy=function(source){Material.prototype.copy.call(this,source);this.bumpMap=source.bumpMap;this.bumpScale=source.bumpScale;this.normalMap=source.normalMap;this.normalMapType=source.normalMapType;this.normalScale.copy(source.normalScale);this.displacementMap=source.displacementMap;this.displacementScale=source.displacementScale;this.displacementBias=source.displacementBias;this.wireframe=source.wireframe;this.wireframeLinewidth=source.wireframeLinewidth;this.skinning=source.skinning;this.morphTargets=source.morphTargets;this.morphNormals=source.morphNormals;return this;};/**
|
2475 | * @author mrdoob / http://mrdoob.com/
|
2476 | * @author alteredq / http://alteredqualia.com/
|
2477 | *
|
2478 | * parameters = {
|
2479 | * color: <hex>,
|
2480 | * opacity: <float>,
|
2481 | *
|
2482 | * map: new THREE.Texture( <Image> ),
|
2483 | *
|
2484 | * lightMap: new THREE.Texture( <Image> ),
|
2485 | * lightMapIntensity: <float>
|
2486 | *
|
2487 | * aoMap: new THREE.Texture( <Image> ),
|
2488 | * aoMapIntensity: <float>
|
2489 | *
|
2490 | * emissive: <hex>,
|
2491 | * emissiveIntensity: <float>
|
2492 | * emissiveMap: new THREE.Texture( <Image> ),
|
2493 | *
|
2494 | * specularMap: new THREE.Texture( <Image> ),
|
2495 | *
|
2496 | * alphaMap: new THREE.Texture( <Image> ),
|
2497 | *
|
2498 | * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
|
2499 | * combine: THREE.Multiply,
|
2500 | * reflectivity: <float>,
|
2501 | * refractionRatio: <float>,
|
2502 | *
|
2503 | * wireframe: <boolean>,
|
2504 | * wireframeLinewidth: <float>,
|
2505 | *
|
2506 | * skinning: <bool>,
|
2507 | * morphTargets: <bool>,
|
2508 | * morphNormals: <bool>
|
2509 | * }
|
2510 | */function MeshLambertMaterial(parameters){Material.call(this);this.type='MeshLambertMaterial';this.color=new Color(0xffffff);// diffuse
|
2511 | this.map=null;this.lightMap=null;this.lightMapIntensity=1.0;this.aoMap=null;this.aoMapIntensity=1.0;this.emissive=new Color(0x000000);this.emissiveIntensity=1.0;this.emissiveMap=null;this.specularMap=null;this.alphaMap=null;this.envMap=null;this.combine=MultiplyOperation;this.reflectivity=1;this.refractionRatio=0.98;this.wireframe=false;this.wireframeLinewidth=1;this.wireframeLinecap='round';this.wireframeLinejoin='round';this.skinning=false;this.morphTargets=false;this.morphNormals=false;this.setValues(parameters);}MeshLambertMaterial.prototype=Object.create(Material.prototype);MeshLambertMaterial.prototype.constructor=MeshLambertMaterial;MeshLambertMaterial.prototype.isMeshLambertMaterial=true;MeshLambertMaterial.prototype.copy=function(source){Material.prototype.copy.call(this,source);this.color.copy(source.color);this.map=source.map;this.lightMap=source.lightMap;this.lightMapIntensity=source.lightMapIntensity;this.aoMap=source.aoMap;this.aoMapIntensity=source.aoMapIntensity;this.emissive.copy(source.emissive);this.emissiveMap=source.emissiveMap;this.emissiveIntensity=source.emissiveIntensity;this.specularMap=source.specularMap;this.alphaMap=source.alphaMap;this.envMap=source.envMap;this.combine=source.combine;this.reflectivity=source.reflectivity;this.refractionRatio=source.refractionRatio;this.wireframe=source.wireframe;this.wireframeLinewidth=source.wireframeLinewidth;this.wireframeLinecap=source.wireframeLinecap;this.wireframeLinejoin=source.wireframeLinejoin;this.skinning=source.skinning;this.morphTargets=source.morphTargets;this.morphNormals=source.morphNormals;return this;};/**
|
2512 | * @author WestLangley / http://github.com/WestLangley
|
2513 | *
|
2514 | * parameters = {
|
2515 | * color: <hex>,
|
2516 | * opacity: <float>,
|
2517 | *
|
2518 | * matcap: new THREE.Texture( <Image> ),
|
2519 | *
|
2520 | * map: new THREE.Texture( <Image> ),
|
2521 | *
|
2522 | * bumpMap: new THREE.Texture( <Image> ),
|
2523 | * bumpScale: <float>,
|
2524 | *
|
2525 | * normalMap: new THREE.Texture( <Image> ),
|
2526 | * normalMapType: THREE.TangentSpaceNormalMap,
|
2527 | * normalScale: <Vector2>,
|
2528 | *
|
2529 | * displacementMap: new THREE.Texture( <Image> ),
|
2530 | * displacementScale: <float>,
|
2531 | * displacementBias: <float>,
|
2532 | *
|
2533 | * alphaMap: new THREE.Texture( <Image> ),
|
2534 | *
|
2535 | * skinning: <bool>,
|
2536 | * morphTargets: <bool>,
|
2537 | * morphNormals: <bool>
|
2538 | * }
|
2539 | */function MeshMatcapMaterial(parameters){Material.call(this);this.defines={'MATCAP':''};this.type='MeshMatcapMaterial';this.color=new Color(0xffffff);// diffuse
|
2540 | this.matcap=null;this.map=null;this.bumpMap=null;this.bumpScale=1;this.normalMap=null;this.normalMapType=TangentSpaceNormalMap;this.normalScale=new Vector2(1,1);this.displacementMap=null;this.displacementScale=1;this.displacementBias=0;this.alphaMap=null;this.skinning=false;this.morphTargets=false;this.morphNormals=false;this.setValues(parameters);}MeshMatcapMaterial.prototype=Object.create(Material.prototype);MeshMatcapMaterial.prototype.constructor=MeshMatcapMaterial;MeshMatcapMaterial.prototype.isMeshMatcapMaterial=true;MeshMatcapMaterial.prototype.copy=function(source){Material.prototype.copy.call(this,source);this.defines={'MATCAP':''};this.color.copy(source.color);this.matcap=source.matcap;this.map=source.map;this.bumpMap=source.bumpMap;this.bumpScale=source.bumpScale;this.normalMap=source.normalMap;this.normalMapType=source.normalMapType;this.normalScale.copy(source.normalScale);this.displacementMap=source.displacementMap;this.displacementScale=source.displacementScale;this.displacementBias=source.displacementBias;this.alphaMap=source.alphaMap;this.skinning=source.skinning;this.morphTargets=source.morphTargets;this.morphNormals=source.morphNormals;return this;};/**
|
2541 | * @author alteredq / http://alteredqualia.com/
|
2542 | *
|
2543 | * parameters = {
|
2544 | * color: <hex>,
|
2545 | * opacity: <float>,
|
2546 | *
|
2547 | * linewidth: <float>,
|
2548 | *
|
2549 | * scale: <float>,
|
2550 | * dashSize: <float>,
|
2551 | * gapSize: <float>
|
2552 | * }
|
2553 | */function LineDashedMaterial(parameters){LineBasicMaterial.call(this);this.type='LineDashedMaterial';this.scale=1;this.dashSize=3;this.gapSize=1;this.setValues(parameters);}LineDashedMaterial.prototype=Object.create(LineBasicMaterial.prototype);LineDashedMaterial.prototype.constructor=LineDashedMaterial;LineDashedMaterial.prototype.isLineDashedMaterial=true;LineDashedMaterial.prototype.copy=function(source){LineBasicMaterial.prototype.copy.call(this,source);this.scale=source.scale;this.dashSize=source.dashSize;this.gapSize=source.gapSize;return this;};var Materials=/*#__PURE__*/Object.freeze({__proto__:null,ShadowMaterial:ShadowMaterial,SpriteMaterial:SpriteMaterial,RawShaderMaterial:RawShaderMaterial,ShaderMaterial:ShaderMaterial,PointsMaterial:PointsMaterial,MeshPhysicalMaterial:MeshPhysicalMaterial,MeshStandardMaterial:MeshStandardMaterial,MeshPhongMaterial:MeshPhongMaterial,MeshToonMaterial:MeshToonMaterial,MeshNormalMaterial:MeshNormalMaterial,MeshLambertMaterial:MeshLambertMaterial,MeshDepthMaterial:MeshDepthMaterial,MeshDistanceMaterial:MeshDistanceMaterial,MeshBasicMaterial:MeshBasicMaterial,MeshMatcapMaterial:MeshMatcapMaterial,LineDashedMaterial:LineDashedMaterial,LineBasicMaterial:LineBasicMaterial,Material:Material});/**
|
2554 | * @author tschw
|
2555 | * @author Ben Houston / http://clara.io/
|
2556 | * @author David Sarno / http://lighthaus.us/
|
2557 | */var AnimationUtils={// same as Array.prototype.slice, but also works on typed arrays
|
2558 | arraySlice:function arraySlice(array,from,to){if(AnimationUtils.isTypedArray(array)){// in ios9 array.subarray(from, undefined) will return empty array
|
2559 | // but array.subarray(from) or array.subarray(from, len) is correct
|
2560 | return new array.constructor(array.subarray(from,to!==undefined?to:array.length));}return array.slice(from,to);},// converts an array to a specific type
|
2561 | convertArray:function convertArray(array,type,forceClone){if(!array||// let 'undefined' and 'null' pass
|
2562 | !forceClone&&array.constructor===type)return array;if(typeof type.BYTES_PER_ELEMENT==='number'){return new type(array);// create typed array
|
2563 | }return Array.prototype.slice.call(array);// create Array
|
2564 | },isTypedArray:function isTypedArray(object){return ArrayBuffer.isView(object)&&!(object instanceof DataView);},// returns an array by which times and values can be sorted
|
2565 | getKeyframeOrder:function getKeyframeOrder(times){function compareTime(i,j){return times[i]-times[j];}var n=times.length;var result=new Array(n);for(var i=0;i!==n;++i){result[i]=i;}result.sort(compareTime);return result;},// uses the array previously returned by 'getKeyframeOrder' to sort data
|
2566 | sortedArray:function sortedArray(values,stride,order){var nValues=values.length;var result=new values.constructor(nValues);for(var i=0,dstOffset=0;dstOffset!==nValues;++i){var srcOffset=order[i]*stride;for(var j=0;j!==stride;++j){result[dstOffset++]=values[srcOffset+j];}}return result;},// function for parsing AOS keyframe formats
|
2567 | flattenJSON:function flattenJSON(jsonKeys,times,values,valuePropertyName){var i=1,key=jsonKeys[0];while(key!==undefined&&key[valuePropertyName]===undefined){key=jsonKeys[i++];}if(key===undefined)return;// no data
|
2568 | var value=key[valuePropertyName];if(value===undefined)return;// no data
|
2569 | if(Array.isArray(value)){do{value=key[valuePropertyName];if(value!==undefined){times.push(key.time);values.push.apply(values,value);// push all elements
|
2570 | }key=jsonKeys[i++];}while(key!==undefined);}else if(value.toArray!==undefined){// ...assume THREE.Math-ish
|
2571 | do{value=key[valuePropertyName];if(value!==undefined){times.push(key.time);value.toArray(values,values.length);}key=jsonKeys[i++];}while(key!==undefined);}else {// otherwise push as-is
|
2572 | do{value=key[valuePropertyName];if(value!==undefined){times.push(key.time);values.push(value);}key=jsonKeys[i++];}while(key!==undefined);}},subclip:function subclip(sourceClip,name,startFrame,endFrame,fps){fps=fps||30;var clip=sourceClip.clone();clip.name=name;var tracks=[];for(var i=0;i<clip.tracks.length;++i){var track=clip.tracks[i];var valueSize=track.getValueSize();var times=[];var values=[];for(var j=0;j<track.times.length;++j){var frame=track.times[j]*fps;if(frame<startFrame||frame>=endFrame)continue;times.push(track.times[j]);for(var k=0;k<valueSize;++k){values.push(track.values[j*valueSize+k]);}}if(times.length===0)continue;track.times=AnimationUtils.convertArray(times,track.times.constructor);track.values=AnimationUtils.convertArray(values,track.values.constructor);tracks.push(track);}clip.tracks=tracks;// find minimum .times value across all tracks in the trimmed clip
|
2573 | var minStartTime=Infinity;for(var i=0;i<clip.tracks.length;++i){if(minStartTime>clip.tracks[i].times[0]){minStartTime=clip.tracks[i].times[0];}}// shift all tracks such that clip begins at t=0
|
2574 | for(var i=0;i<clip.tracks.length;++i){clip.tracks[i].shift(-1*minStartTime);}clip.resetDuration();return clip;},makeClipAdditive:function makeClipAdditive(targetClip,referenceFrame,referenceClip,fps){if(referenceFrame===undefined)referenceFrame=0;if(referenceClip===undefined)referenceClip=targetClip;if(fps===undefined||fps<=0)fps=30;var numTracks=targetClip.tracks.length;var referenceTime=referenceFrame/fps;// Make each track's values relative to the values at the reference frame
|
2575 | for(var i=0;i<numTracks;++i){var referenceTrack=referenceClip.tracks[i];var referenceTrackType=referenceTrack.ValueTypeName;// Skip this track if it's non-numeric
|
2576 | if(referenceTrackType==='bool'||referenceTrackType==='string')continue;// Find the track in the target clip whose name and type matches the reference track
|
2577 | var targetTrack=targetClip.tracks.find(function(track){return track.name===referenceTrack.name&&track.ValueTypeName===referenceTrackType;});if(targetTrack===undefined)continue;var valueSize=referenceTrack.getValueSize();var lastIndex=referenceTrack.times.length-1;var referenceValue;// Find the value to subtract out of the track
|
2578 | if(referenceTime<=referenceTrack.times[0]){// Reference frame is earlier than the first keyframe, so just use the first keyframe
|
2579 | referenceValue=AnimationUtils.arraySlice(referenceTrack.values,0,referenceTrack.valueSize);}else if(referenceTime>=referenceTrack.times[lastIndex]){// Reference frame is after the last keyframe, so just use the last keyframe
|
2580 | var startIndex=lastIndex*valueSize;referenceValue=AnimationUtils.arraySlice(referenceTrack.values,startIndex);}else {// Interpolate to the reference value
|
2581 | var interpolant=referenceTrack.createInterpolant();interpolant.evaluate(referenceTime);referenceValue=interpolant.resultBuffer;}// Conjugate the quaternion
|
2582 | if(referenceTrackType==='quaternion'){var referenceQuat=new Quaternion(referenceValue[0],referenceValue[1],referenceValue[2],referenceValue[3]).normalize().conjugate();referenceQuat.toArray(referenceValue);}// Subtract the reference value from all of the track values
|
2583 | var numTimes=targetTrack.times.length;for(var j=0;j<numTimes;++j){var valueStart=j*valueSize;if(referenceTrackType==='quaternion'){// Multiply the conjugate for quaternion track types
|
2584 | Quaternion.multiplyQuaternionsFlat(targetTrack.values,valueStart,referenceValue,0,targetTrack.values,valueStart);}else {// Subtract each value for all other numeric track types
|
2585 | for(var k=0;k<valueSize;++k){targetTrack.values[valueStart+k]-=referenceValue[k];}}}}targetClip.blendMode=AdditiveAnimationBlendMode;return targetClip;}};/**
|
2586 | * Abstract base class of interpolants over parametric samples.
|
2587 | *
|
2588 | * The parameter domain is one dimensional, typically the time or a path
|
2589 | * along a curve defined by the data.
|
2590 | *
|
2591 | * The sample values can have any dimensionality and derived classes may
|
2592 | * apply special interpretations to the data.
|
2593 | *
|
2594 | * This class provides the interval seek in a Template Method, deferring
|
2595 | * the actual interpolation to derived classes.
|
2596 | *
|
2597 | * Time complexity is O(1) for linear access crossing at most two points
|
2598 | * and O(log N) for random access, where N is the number of positions.
|
2599 | *
|
2600 | * References:
|
2601 | *
|
2602 | * http://www.oodesign.com/template-method-pattern.html
|
2603 | *
|
2604 | * @author tschw
|
2605 | */function Interpolant(parameterPositions,sampleValues,sampleSize,resultBuffer){this.parameterPositions=parameterPositions;this._cachedIndex=0;this.resultBuffer=resultBuffer!==undefined?resultBuffer:new sampleValues.constructor(sampleSize);this.sampleValues=sampleValues;this.valueSize=sampleSize;}_extends(Interpolant.prototype,{evaluate:function evaluate(t){var pp=this.parameterPositions,i1=this._cachedIndex,t1=pp[i1],t0=pp[i1-1];validate_interval:{seek:{var right;linear_scan:{//- See http://jsperf.com/comparison-to-undefined/3
|
2606 | //- slower code:
|
2607 | //-
|
2608 | //- if ( t >= t1 || t1 === undefined ) {
|
2609 | forward_scan:if(!(t<t1)){for(var giveUpAt=i1+2;;){if(t1===undefined){if(t<t0)break forward_scan;// after end
|
2610 | i1=pp.length;this._cachedIndex=i1;return this.afterEnd_(i1-1,t,t0);}if(i1===giveUpAt)break;// this loop
|
2611 | t0=t1;t1=pp[++i1];if(t<t1){// we have arrived at the sought interval
|
2612 | break seek;}}// prepare binary search on the right side of the index
|
2613 | right=pp.length;break linear_scan;}//- slower code:
|
2614 | //- if ( t < t0 || t0 === undefined ) {
|
2615 | if(!(t>=t0)){// looping?
|
2616 | var t1global=pp[1];if(t<t1global){i1=2;// + 1, using the scan for the details
|
2617 | t0=t1global;}// linear reverse scan
|
2618 | for(var giveUpAt=i1-2;;){if(t0===undefined){// before start
|
2619 | this._cachedIndex=0;return this.beforeStart_(0,t,t1);}if(i1===giveUpAt)break;// this loop
|
2620 | t1=t0;t0=pp[--i1-1];if(t>=t0){// we have arrived at the sought interval
|
2621 | break seek;}}// prepare binary search on the left side of the index
|
2622 | right=i1;i1=0;break linear_scan;}// the interval is valid
|
2623 | break validate_interval;}// linear scan
|
2624 | // binary search
|
2625 | while(i1<right){var mid=i1+right>>>1;if(t<pp[mid]){right=mid;}else {i1=mid+1;}}t1=pp[i1];t0=pp[i1-1];// check boundary cases, again
|
2626 | if(t0===undefined){this._cachedIndex=0;return this.beforeStart_(0,t,t1);}if(t1===undefined){i1=pp.length;this._cachedIndex=i1;return this.afterEnd_(i1-1,t0,t);}}// seek
|
2627 | this._cachedIndex=i1;this.intervalChanged_(i1,t0,t1);}// validate_interval
|
2628 | return this.interpolate_(i1,t0,t,t1);},settings:null,// optional, subclass-specific settings structure
|
2629 | // Note: The indirection allows central control of many interpolants.
|
2630 | // --- Protected interface
|
2631 | DefaultSettings_:{},getSettings_:function getSettings_(){return this.settings||this.DefaultSettings_;},copySampleValue_:function copySampleValue_(index){// copies a sample value to the result buffer
|
2632 | var result=this.resultBuffer,values=this.sampleValues,stride=this.valueSize,offset=index*stride;for(var i=0;i!==stride;++i){result[i]=values[offset+i];}return result;},// Template methods for derived classes:
|
2633 | interpolate_:function interpolate_()/* i1, t0, t, t1 */{throw new Error('call to abstract method');// implementations shall return this.resultBuffer
|
2634 | },intervalChanged_:function intervalChanged_()/* i1, t0, t1 */{// empty
|
2635 | }});// DECLARE ALIAS AFTER assign prototype
|
2636 | _extends(Interpolant.prototype,{//( 0, t, t0 ), returns this.resultBuffer
|
2637 | beforeStart_:Interpolant.prototype.copySampleValue_,//( N-1, tN-1, t ), returns this.resultBuffer
|
2638 | afterEnd_:Interpolant.prototype.copySampleValue_});/**
|
2639 | * Fast and simple cubic spline interpolant.
|
2640 | *
|
2641 | * It was derived from a Hermitian construction setting the first derivative
|
2642 | * at each sample position to the linear slope between neighboring positions
|
2643 | * over their parameter interval.
|
2644 | *
|
2645 | * @author tschw
|
2646 | */function CubicInterpolant(parameterPositions,sampleValues,sampleSize,resultBuffer){Interpolant.call(this,parameterPositions,sampleValues,sampleSize,resultBuffer);this._weightPrev=-0;this._offsetPrev=-0;this._weightNext=-0;this._offsetNext=-0;}CubicInterpolant.prototype=_extends(Object.create(Interpolant.prototype),{constructor:CubicInterpolant,DefaultSettings_:{endingStart:ZeroCurvatureEnding,endingEnd:ZeroCurvatureEnding},intervalChanged_:function intervalChanged_(i1,t0,t1){var pp=this.parameterPositions,iPrev=i1-2,iNext=i1+1,tPrev=pp[iPrev],tNext=pp[iNext];if(tPrev===undefined){switch(this.getSettings_().endingStart){case ZeroSlopeEnding:// f'(t0) = 0
|
2647 | iPrev=i1;tPrev=2*t0-t1;break;case WrapAroundEnding:// use the other end of the curve
|
2648 | iPrev=pp.length-2;tPrev=t0+pp[iPrev]-pp[iPrev+1];break;default:// ZeroCurvatureEnding
|
2649 | // f''(t0) = 0 a.k.a. Natural Spline
|
2650 | iPrev=i1;tPrev=t1;}}if(tNext===undefined){switch(this.getSettings_().endingEnd){case ZeroSlopeEnding:// f'(tN) = 0
|
2651 | iNext=i1;tNext=2*t1-t0;break;case WrapAroundEnding:// use the other end of the curve
|
2652 | iNext=1;tNext=t1+pp[1]-pp[0];break;default:// ZeroCurvatureEnding
|
2653 | // f''(tN) = 0, a.k.a. Natural Spline
|
2654 | iNext=i1-1;tNext=t0;}}var halfDt=(t1-t0)*0.5,stride=this.valueSize;this._weightPrev=halfDt/(t0-tPrev);this._weightNext=halfDt/(tNext-t1);this._offsetPrev=iPrev*stride;this._offsetNext=iNext*stride;},interpolate_:function interpolate_(i1,t0,t,t1){var result=this.resultBuffer,values=this.sampleValues,stride=this.valueSize,o1=i1*stride,o0=o1-stride,oP=this._offsetPrev,oN=this._offsetNext,wP=this._weightPrev,wN=this._weightNext,p=(t-t0)/(t1-t0),pp=p*p,ppp=pp*p;// evaluate polynomials
|
2655 | var sP=-wP*ppp+2*wP*pp-wP*p;var s0=(1+wP)*ppp+(-1.5-2*wP)*pp+(-0.5+wP)*p+1;var s1=(-1-wN)*ppp+(1.5+wN)*pp+0.5*p;var sN=wN*ppp-wN*pp;// combine data linearly
|
2656 | for(var i=0;i!==stride;++i){result[i]=sP*values[oP+i]+s0*values[o0+i]+s1*values[o1+i]+sN*values[oN+i];}return result;}});/**
|
2657 | * @author tschw
|
2658 | */function LinearInterpolant(parameterPositions,sampleValues,sampleSize,resultBuffer){Interpolant.call(this,parameterPositions,sampleValues,sampleSize,resultBuffer);}LinearInterpolant.prototype=_extends(Object.create(Interpolant.prototype),{constructor:LinearInterpolant,interpolate_:function interpolate_(i1,t0,t,t1){var result=this.resultBuffer,values=this.sampleValues,stride=this.valueSize,offset1=i1*stride,offset0=offset1-stride,weight1=(t-t0)/(t1-t0),weight0=1-weight1;for(var i=0;i!==stride;++i){result[i]=values[offset0+i]*weight0+values[offset1+i]*weight1;}return result;}});/**
|
2659 | *
|
2660 | * Interpolant that evaluates to the sample value at the position preceeding
|
2661 | * the parameter.
|
2662 | *
|
2663 | * @author tschw
|
2664 | */function DiscreteInterpolant(parameterPositions,sampleValues,sampleSize,resultBuffer){Interpolant.call(this,parameterPositions,sampleValues,sampleSize,resultBuffer);}DiscreteInterpolant.prototype=_extends(Object.create(Interpolant.prototype),{constructor:DiscreteInterpolant,interpolate_:function interpolate_(i1/*, t0, t, t1 */){return this.copySampleValue_(i1-1);}});/**
|
2665 | *
|
2666 | * A timed sequence of keyframes for a specific property.
|
2667 | *
|
2668 | *
|
2669 | * @author Ben Houston / http://clara.io/
|
2670 | * @author David Sarno / http://lighthaus.us/
|
2671 | * @author tschw
|
2672 | */function KeyframeTrack(name,times,values,interpolation){if(name===undefined)throw new Error('THREE.KeyframeTrack: track name is undefined');if(times===undefined||times.length===0)throw new Error('THREE.KeyframeTrack: no keyframes in track named '+name);this.name=name;this.times=AnimationUtils.convertArray(times,this.TimeBufferType);this.values=AnimationUtils.convertArray(values,this.ValueBufferType);this.setInterpolation(interpolation||this.DefaultInterpolation);}// Static methods
|
2673 | _extends(KeyframeTrack,{// Serialization (in static context, because of constructor invocation
|
2674 | // and automatic invocation of .toJSON):
|
2675 | toJSON:function toJSON(track){var trackType=track.constructor;var json;// derived classes can define a static toJSON method
|
2676 | if(trackType.toJSON!==undefined){json=trackType.toJSON(track);}else {// by default, we assume the data can be serialized as-is
|
2677 | json={'name':track.name,'times':AnimationUtils.convertArray(track.times,Array),'values':AnimationUtils.convertArray(track.values,Array)};var interpolation=track.getInterpolation();if(interpolation!==track.DefaultInterpolation){json.interpolation=interpolation;}}json.type=track.ValueTypeName;// mandatory
|
2678 | return json;}});_extends(KeyframeTrack.prototype,{constructor:KeyframeTrack,TimeBufferType:Float32Array,ValueBufferType:Float32Array,DefaultInterpolation:InterpolateLinear,InterpolantFactoryMethodDiscrete:function InterpolantFactoryMethodDiscrete(result){return new DiscreteInterpolant(this.times,this.values,this.getValueSize(),result);},InterpolantFactoryMethodLinear:function InterpolantFactoryMethodLinear(result){return new LinearInterpolant(this.times,this.values,this.getValueSize(),result);},InterpolantFactoryMethodSmooth:function InterpolantFactoryMethodSmooth(result){return new CubicInterpolant(this.times,this.values,this.getValueSize(),result);},setInterpolation:function setInterpolation(interpolation){var factoryMethod;switch(interpolation){case InterpolateDiscrete:factoryMethod=this.InterpolantFactoryMethodDiscrete;break;case InterpolateLinear:factoryMethod=this.InterpolantFactoryMethodLinear;break;case InterpolateSmooth:factoryMethod=this.InterpolantFactoryMethodSmooth;break;}if(factoryMethod===undefined){var message="unsupported interpolation for "+this.ValueTypeName+" keyframe track named "+this.name;if(this.createInterpolant===undefined){// fall back to default, unless the default itself is messed up
|
2679 | if(interpolation!==this.DefaultInterpolation){this.setInterpolation(this.DefaultInterpolation);}else {throw new Error(message);// fatal, in this case
|
2680 | }}console.warn('THREE.KeyframeTrack:',message);return this;}this.createInterpolant=factoryMethod;return this;},getInterpolation:function getInterpolation(){switch(this.createInterpolant){case this.InterpolantFactoryMethodDiscrete:return InterpolateDiscrete;case this.InterpolantFactoryMethodLinear:return InterpolateLinear;case this.InterpolantFactoryMethodSmooth:return InterpolateSmooth;}},getValueSize:function getValueSize(){return this.values.length/this.times.length;},// move all keyframes either forwards or backwards in time
|
2681 | shift:function shift(timeOffset){if(timeOffset!==0.0){var times=this.times;for(var i=0,n=times.length;i!==n;++i){times[i]+=timeOffset;}}return this;},// scale all keyframe times by a factor (useful for frame <-> seconds conversions)
|
2682 | scale:function scale(timeScale){if(timeScale!==1.0){var times=this.times;for(var i=0,n=times.length;i!==n;++i){times[i]*=timeScale;}}return this;},// removes keyframes before and after animation without changing any values within the range [startTime, endTime].
|
2683 | // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
|
2684 | trim:function trim(startTime,endTime){var times=this.times,nKeys=times.length,from=0,to=nKeys-1;while(from!==nKeys&×[from]<startTime){++from;}while(to!==-1&×[to]>endTime){--to;}++to;// inclusive -> exclusive bound
|
2685 | if(from!==0||to!==nKeys){// empty tracks are forbidden, so keep at least one keyframe
|
2686 | if(from>=to){to=Math.max(to,1);from=to-1;}var stride=this.getValueSize();this.times=AnimationUtils.arraySlice(times,from,to);this.values=AnimationUtils.arraySlice(this.values,from*stride,to*stride);}return this;},// ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
|
2687 | validate:function validate(){var valid=true;var valueSize=this.getValueSize();if(valueSize-Math.floor(valueSize)!==0){console.error('THREE.KeyframeTrack: Invalid value size in track.',this);valid=false;}var times=this.times,values=this.values,nKeys=times.length;if(nKeys===0){console.error('THREE.KeyframeTrack: Track is empty.',this);valid=false;}var prevTime=null;for(var i=0;i!==nKeys;i++){var currTime=times[i];if(typeof currTime==='number'&&isNaN(currTime)){console.error('THREE.KeyframeTrack: Time is not a valid number.',this,i,currTime);valid=false;break;}if(prevTime!==null&&prevTime>currTime){console.error('THREE.KeyframeTrack: Out of order keys.',this,i,currTime,prevTime);valid=false;break;}prevTime=currTime;}if(values!==undefined){if(AnimationUtils.isTypedArray(values)){for(var i=0,n=values.length;i!==n;++i){var value=values[i];if(isNaN(value)){console.error('THREE.KeyframeTrack: Value is not a valid number.',this,i,value);valid=false;break;}}}}return valid;},// removes equivalent sequential keys as common in morph target sequences
|
2688 | // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
|
2689 | optimize:function optimize(){// times or values may be shared with other tracks, so overwriting is unsafe
|
2690 | var times=AnimationUtils.arraySlice(this.times),values=AnimationUtils.arraySlice(this.values),stride=this.getValueSize(),smoothInterpolation=this.getInterpolation()===InterpolateSmooth,writeIndex=1,lastIndex=times.length-1;for(var i=1;i<lastIndex;++i){var keep=false;var time=times[i];var timeNext=times[i+1];// remove adjacent keyframes scheduled at the same time
|
2691 | if(time!==timeNext&&(i!==1||time!==time[0])){if(!smoothInterpolation){// remove unnecessary keyframes same as their neighbors
|
2692 | var offset=i*stride,offsetP=offset-stride,offsetN=offset+stride;for(var j=0;j!==stride;++j){var value=values[offset+j];if(value!==values[offsetP+j]||value!==values[offsetN+j]){keep=true;break;}}}else {keep=true;}}// in-place compaction
|
2693 | if(keep){if(i!==writeIndex){times[writeIndex]=times[i];var readOffset=i*stride,writeOffset=writeIndex*stride;for(var j=0;j!==stride;++j){values[writeOffset+j]=values[readOffset+j];}}++writeIndex;}}// flush last keyframe (compaction looks ahead)
|
2694 | if(lastIndex>0){times[writeIndex]=times[lastIndex];for(var readOffset=lastIndex*stride,writeOffset=writeIndex*stride,j=0;j!==stride;++j){values[writeOffset+j]=values[readOffset+j];}++writeIndex;}if(writeIndex!==times.length){this.times=AnimationUtils.arraySlice(times,0,writeIndex);this.values=AnimationUtils.arraySlice(values,0,writeIndex*stride);}else {this.times=times;this.values=values;}return this;},clone:function clone(){var times=AnimationUtils.arraySlice(this.times,0);var values=AnimationUtils.arraySlice(this.values,0);var TypedKeyframeTrack=this.constructor;var track=new TypedKeyframeTrack(this.name,times,values);// Interpolant argument to constructor is not saved, so copy the factory method directly.
|
2695 | track.createInterpolant=this.createInterpolant;return track;}});/**
|
2696 | *
|
2697 | * A Track of Boolean keyframe values.
|
2698 | *
|
2699 | *
|
2700 | * @author Ben Houston / http://clara.io/
|
2701 | * @author David Sarno / http://lighthaus.us/
|
2702 | * @author tschw
|
2703 | */function BooleanKeyframeTrack(name,times,values){KeyframeTrack.call(this,name,times,values);}BooleanKeyframeTrack.prototype=_extends(Object.create(KeyframeTrack.prototype),{constructor:BooleanKeyframeTrack,ValueTypeName:'bool',ValueBufferType:Array,DefaultInterpolation:InterpolateDiscrete,InterpolantFactoryMethodLinear:undefined,InterpolantFactoryMethodSmooth:undefined// Note: Actually this track could have a optimized / compressed
|
2704 | // representation of a single value and a custom interpolant that
|
2705 | // computes "firstValue ^ isOdd( index )".
|
2706 | });/**
|
2707 | *
|
2708 | * A Track of keyframe values that represent color.
|
2709 | *
|
2710 | *
|
2711 | * @author Ben Houston / http://clara.io/
|
2712 | * @author David Sarno / http://lighthaus.us/
|
2713 | * @author tschw
|
2714 | */function ColorKeyframeTrack(name,times,values,interpolation){KeyframeTrack.call(this,name,times,values,interpolation);}ColorKeyframeTrack.prototype=_extends(Object.create(KeyframeTrack.prototype),{constructor:ColorKeyframeTrack,ValueTypeName:'color'// ValueBufferType is inherited
|
2715 | // DefaultInterpolation is inherited
|
2716 | // Note: Very basic implementation and nothing special yet.
|
2717 | // However, this is the place for color space parameterization.
|
2718 | });/**
|
2719 | *
|
2720 | * A Track of numeric keyframe values.
|
2721 | *
|
2722 | * @author Ben Houston / http://clara.io/
|
2723 | * @author David Sarno / http://lighthaus.us/
|
2724 | * @author tschw
|
2725 | */function NumberKeyframeTrack(name,times,values,interpolation){KeyframeTrack.call(this,name,times,values,interpolation);}NumberKeyframeTrack.prototype=_extends(Object.create(KeyframeTrack.prototype),{constructor:NumberKeyframeTrack,ValueTypeName:'number'// ValueBufferType is inherited
|
2726 | // DefaultInterpolation is inherited
|
2727 | });/**
|
2728 | * Spherical linear unit quaternion interpolant.
|
2729 | *
|
2730 | * @author tschw
|
2731 | */function QuaternionLinearInterpolant(parameterPositions,sampleValues,sampleSize,resultBuffer){Interpolant.call(this,parameterPositions,sampleValues,sampleSize,resultBuffer);}QuaternionLinearInterpolant.prototype=_extends(Object.create(Interpolant.prototype),{constructor:QuaternionLinearInterpolant,interpolate_:function interpolate_(i1,t0,t,t1){var result=this.resultBuffer,values=this.sampleValues,stride=this.valueSize,offset=i1*stride,alpha=(t-t0)/(t1-t0);for(var end=offset+stride;offset!==end;offset+=4){Quaternion.slerpFlat(result,0,values,offset-stride,values,offset,alpha);}return result;}});/**
|
2732 | *
|
2733 | * A Track of quaternion keyframe values.
|
2734 | *
|
2735 | * @author Ben Houston / http://clara.io/
|
2736 | * @author David Sarno / http://lighthaus.us/
|
2737 | * @author tschw
|
2738 | */function QuaternionKeyframeTrack(name,times,values,interpolation){KeyframeTrack.call(this,name,times,values,interpolation);}QuaternionKeyframeTrack.prototype=_extends(Object.create(KeyframeTrack.prototype),{constructor:QuaternionKeyframeTrack,ValueTypeName:'quaternion',// ValueBufferType is inherited
|
2739 | DefaultInterpolation:InterpolateLinear,InterpolantFactoryMethodLinear:function InterpolantFactoryMethodLinear(result){return new QuaternionLinearInterpolant(this.times,this.values,this.getValueSize(),result);},InterpolantFactoryMethodSmooth:undefined// not yet implemented
|
2740 | });/**
|
2741 | *
|
2742 | * A Track that interpolates Strings
|
2743 | *
|
2744 | *
|
2745 | * @author Ben Houston / http://clara.io/
|
2746 | * @author David Sarno / http://lighthaus.us/
|
2747 | * @author tschw
|
2748 | */function StringKeyframeTrack(name,times,values,interpolation){KeyframeTrack.call(this,name,times,values,interpolation);}StringKeyframeTrack.prototype=_extends(Object.create(KeyframeTrack.prototype),{constructor:StringKeyframeTrack,ValueTypeName:'string',ValueBufferType:Array,DefaultInterpolation:InterpolateDiscrete,InterpolantFactoryMethodLinear:undefined,InterpolantFactoryMethodSmooth:undefined});/**
|
2749 | *
|
2750 | * A Track of vectored keyframe values.
|
2751 | *
|
2752 | *
|
2753 | * @author Ben Houston / http://clara.io/
|
2754 | * @author David Sarno / http://lighthaus.us/
|
2755 | * @author tschw
|
2756 | */function VectorKeyframeTrack(name,times,values,interpolation){KeyframeTrack.call(this,name,times,values,interpolation);}VectorKeyframeTrack.prototype=_extends(Object.create(KeyframeTrack.prototype),{constructor:VectorKeyframeTrack,ValueTypeName:'vector'// ValueBufferType is inherited
|
2757 | // DefaultInterpolation is inherited
|
2758 | });/**
|
2759 | *
|
2760 | * Reusable set of Tracks that represent an animation.
|
2761 | *
|
2762 | * @author Ben Houston / http://clara.io/
|
2763 | * @author David Sarno / http://lighthaus.us/
|
2764 | */function AnimationClip(name,duration,tracks,blendMode){this.name=name;this.tracks=tracks;this.duration=duration!==undefined?duration:-1;this.blendMode=blendMode!==undefined?blendMode:NormalAnimationBlendMode;this.uuid=MathUtils.generateUUID();// this means it should figure out its duration by scanning the tracks
|
2765 | if(this.duration<0){this.resetDuration();}}function getTrackTypeForValueTypeName(typeName){switch(typeName.toLowerCase()){case'scalar':case'double':case'float':case'number':case'integer':return NumberKeyframeTrack;case'vector':case'vector2':case'vector3':case'vector4':return VectorKeyframeTrack;case'color':return ColorKeyframeTrack;case'quaternion':return QuaternionKeyframeTrack;case'bool':case'boolean':return BooleanKeyframeTrack;case'string':return StringKeyframeTrack;}throw new Error('THREE.KeyframeTrack: Unsupported typeName: '+typeName);}function parseKeyframeTrack(json){if(json.type===undefined){throw new Error('THREE.KeyframeTrack: track type undefined, can not parse');}var trackType=getTrackTypeForValueTypeName(json.type);if(json.times===undefined){var times=[],values=[];AnimationUtils.flattenJSON(json.keys,times,values,'value');json.times=times;json.values=values;}// derived classes can define a static parse method
|
2766 | if(trackType.parse!==undefined){return trackType.parse(json);}else {// by default, we assume a constructor compatible with the base
|
2767 | return new trackType(json.name,json.times,json.values,json.interpolation);}}_extends(AnimationClip,{parse:function parse(json){var tracks=[],jsonTracks=json.tracks,frameTime=1.0/(json.fps||1.0);for(var i=0,n=jsonTracks.length;i!==n;++i){tracks.push(parseKeyframeTrack(jsonTracks[i]).scale(frameTime));}return new AnimationClip(json.name,json.duration,tracks,json.blendMode);},toJSON:function toJSON(clip){var tracks=[],clipTracks=clip.tracks;var json={'name':clip.name,'duration':clip.duration,'tracks':tracks,'uuid':clip.uuid,'blendMode':clip.blendMode};for(var i=0,n=clipTracks.length;i!==n;++i){tracks.push(KeyframeTrack.toJSON(clipTracks[i]));}return json;},CreateFromMorphTargetSequence:function CreateFromMorphTargetSequence(name,morphTargetSequence,fps,noLoop){var numMorphTargets=morphTargetSequence.length;var tracks=[];for(var i=0;i<numMorphTargets;i++){var times=[];var values=[];times.push((i+numMorphTargets-1)%numMorphTargets,i,(i+1)%numMorphTargets);values.push(0,1,0);var order=AnimationUtils.getKeyframeOrder(times);times=AnimationUtils.sortedArray(times,1,order);values=AnimationUtils.sortedArray(values,1,order);// if there is a key at the first frame, duplicate it as the
|
2768 | // last frame as well for perfect loop.
|
2769 | if(!noLoop&×[0]===0){times.push(numMorphTargets);values.push(values[0]);}tracks.push(new NumberKeyframeTrack('.morphTargetInfluences['+morphTargetSequence[i].name+']',times,values).scale(1.0/fps));}return new AnimationClip(name,-1,tracks);},findByName:function findByName(objectOrClipArray,name){var clipArray=objectOrClipArray;if(!Array.isArray(objectOrClipArray)){var o=objectOrClipArray;clipArray=o.geometry&&o.geometry.animations||o.animations;}for(var i=0;i<clipArray.length;i++){if(clipArray[i].name===name){return clipArray[i];}}return null;},CreateClipsFromMorphTargetSequences:function CreateClipsFromMorphTargetSequences(morphTargets,fps,noLoop){var animationToMorphTargets={};// tested with https://regex101.com/ on trick sequences
|
2770 | // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
|
2771 | var pattern=/^([\w-]*?)([\d]+)$/;// sort morph target names into animation groups based
|
2772 | // patterns like Walk_001, Walk_002, Run_001, Run_002
|
2773 | for(var i=0,il=morphTargets.length;i<il;i++){var morphTarget=morphTargets[i];var parts=morphTarget.name.match(pattern);if(parts&&parts.length>1){var name=parts[1];var animationMorphTargets=animationToMorphTargets[name];if(!animationMorphTargets){animationToMorphTargets[name]=animationMorphTargets=[];}animationMorphTargets.push(morphTarget);}}var clips=[];for(var name in animationToMorphTargets){clips.push(AnimationClip.CreateFromMorphTargetSequence(name,animationToMorphTargets[name],fps,noLoop));}return clips;},// parse the animation.hierarchy format
|
2774 | parseAnimation:function parseAnimation(animation,bones){if(!animation){console.error('THREE.AnimationClip: No animation in JSONLoader data.');return null;}var addNonemptyTrack=function addNonemptyTrack(trackType,trackName,animationKeys,propertyName,destTracks){// only return track if there are actually keys.
|
2775 | if(animationKeys.length!==0){var times=[];var values=[];AnimationUtils.flattenJSON(animationKeys,times,values,propertyName);// empty keys are filtered out, so check again
|
2776 | if(times.length!==0){destTracks.push(new trackType(trackName,times,values));}}};var tracks=[];var clipName=animation.name||'default';// automatic length determination in AnimationClip.
|
2777 | var duration=animation.length||-1;var fps=animation.fps||30;var blendMode=animation.blendMode;var hierarchyTracks=animation.hierarchy||[];for(var h=0;h<hierarchyTracks.length;h++){var animationKeys=hierarchyTracks[h].keys;// skip empty tracks
|
2778 | if(!animationKeys||animationKeys.length===0)continue;// process morph targets
|
2779 | if(animationKeys[0].morphTargets){// figure out all morph targets used in this track
|
2780 | var morphTargetNames={};for(var k=0;k<animationKeys.length;k++){if(animationKeys[k].morphTargets){for(var m=0;m<animationKeys[k].morphTargets.length;m++){morphTargetNames[animationKeys[k].morphTargets[m]]=-1;}}}// create a track for each morph target with all zero
|
2781 | // morphTargetInfluences except for the keys in which
|
2782 | // the morphTarget is named.
|
2783 | for(var morphTargetName in morphTargetNames){var times=[];var values=[];for(var m=0;m!==animationKeys[k].morphTargets.length;++m){var animationKey=animationKeys[k];times.push(animationKey.time);values.push(animationKey.morphTarget===morphTargetName?1:0);}tracks.push(new NumberKeyframeTrack('.morphTargetInfluence['+morphTargetName+']',times,values));}duration=morphTargetNames.length*(fps||1.0);}else {// ...assume skeletal animation
|
2784 | var boneName='.bones['+bones[h].name+']';addNonemptyTrack(VectorKeyframeTrack,boneName+'.position',animationKeys,'pos',tracks);addNonemptyTrack(QuaternionKeyframeTrack,boneName+'.quaternion',animationKeys,'rot',tracks);addNonemptyTrack(VectorKeyframeTrack,boneName+'.scale',animationKeys,'scl',tracks);}}if(tracks.length===0){return null;}var clip=new AnimationClip(clipName,duration,tracks,blendMode);return clip;}});_extends(AnimationClip.prototype,{resetDuration:function resetDuration(){var tracks=this.tracks,duration=0;for(var i=0,n=tracks.length;i!==n;++i){var track=this.tracks[i];duration=Math.max(duration,track.times[track.times.length-1]);}this.duration=duration;return this;},trim:function trim(){for(var i=0;i<this.tracks.length;i++){this.tracks[i].trim(0,this.duration);}return this;},validate:function validate(){var valid=true;for(var i=0;i<this.tracks.length;i++){valid=valid&&this.tracks[i].validate();}return valid;},optimize:function optimize(){for(var i=0;i<this.tracks.length;i++){this.tracks[i].optimize();}return this;},clone:function clone(){var tracks=[];for(var i=0;i<this.tracks.length;i++){tracks.push(this.tracks[i].clone());}return new AnimationClip(this.name,this.duration,tracks,this.blendMode);}});/**
|
2785 | * @author mrdoob / http://mrdoob.com/
|
2786 | */var Cache={enabled:false,files:{},add:function add(key,file){if(this.enabled===false)return;// console.log( 'THREE.Cache', 'Adding key:', key );
|
2787 | this.files[key]=file;},get:function get(key){if(this.enabled===false)return;// console.log( 'THREE.Cache', 'Checking key:', key );
|
2788 | return this.files[key];},remove:function remove(key){delete this.files[key];},clear:function clear(){this.files={};}};/**
|
2789 | * @author mrdoob / http://mrdoob.com/
|
2790 | */function LoadingManager(onLoad,onProgress,onError){var scope=this;var isLoading=false;var itemsLoaded=0;var itemsTotal=0;var urlModifier=undefined;var handlers=[];// Refer to #5689 for the reason why we don't set .onStart
|
2791 | // in the constructor
|
2792 | this.onStart=undefined;this.onLoad=onLoad;this.onProgress=onProgress;this.onError=onError;this.itemStart=function(url){itemsTotal++;if(isLoading===false){if(scope.onStart!==undefined){scope.onStart(url,itemsLoaded,itemsTotal);}}isLoading=true;};this.itemEnd=function(url){itemsLoaded++;if(scope.onProgress!==undefined){scope.onProgress(url,itemsLoaded,itemsTotal);}if(itemsLoaded===itemsTotal){isLoading=false;if(scope.onLoad!==undefined){scope.onLoad();}}};this.itemError=function(url){if(scope.onError!==undefined){scope.onError(url);}};this.resolveURL=function(url){if(urlModifier){return urlModifier(url);}return url;};this.setURLModifier=function(transform){urlModifier=transform;return this;};this.addHandler=function(regex,loader){handlers.push(regex,loader);return this;};this.removeHandler=function(regex){var index=handlers.indexOf(regex);if(index!==-1){handlers.splice(index,2);}return this;};this.getHandler=function(file){for(var i=0,l=handlers.length;i<l;i+=2){var regex=handlers[i];var loader=handlers[i+1];if(regex.global)regex.lastIndex=0;// see #17920
|
2793 | if(regex.test(file)){return loader;}}return null;};}var DefaultLoadingManager=new LoadingManager();/**
|
2794 | * @author alteredq / http://alteredqualia.com/
|
2795 | */function Loader(manager){this.manager=manager!==undefined?manager:DefaultLoadingManager;this.crossOrigin='anonymous';this.path='';this.resourcePath='';}_extends(Loader.prototype,{load:function load()/* url, onLoad, onProgress, onError */{},loadAsync:function loadAsync(url,onProgress){var scope=this;return new Promise(function(resolve,reject){scope.load(url,resolve,onProgress,reject);});},parse:function parse()/* data */{},setCrossOrigin:function setCrossOrigin(crossOrigin){this.crossOrigin=crossOrigin;return this;},setPath:function setPath(path){this.path=path;return this;},setResourcePath:function setResourcePath(resourcePath){this.resourcePath=resourcePath;return this;}});/**
|
2796 | * @author mrdoob / http://mrdoob.com/
|
2797 | */var loading={};function FileLoader(manager){Loader.call(this,manager);}FileLoader.prototype=_extends(Object.create(Loader.prototype),{constructor:FileLoader,load:function load(url,onLoad,onProgress,onError){if(url===undefined)url='';if(this.path!==undefined)url=this.path+url;url=this.manager.resolveURL(url);var scope=this;var cached=Cache.get(url);if(cached!==undefined){scope.manager.itemStart(url);setTimeout(function(){if(onLoad)onLoad(cached);scope.manager.itemEnd(url);},0);return cached;}// Check if request is duplicate
|
2798 | if(loading[url]!==undefined){loading[url].push({onLoad:onLoad,onProgress:onProgress,onError:onError});return;}// Check for data: URI
|
2799 | var dataUriRegex=/^data:(.*?)(;base64)?,(.*)$/;var dataUriRegexResult=url.match(dataUriRegex);// Safari can not handle Data URIs through XMLHttpRequest so process manually
|
2800 | if(dataUriRegexResult){var mimeType=dataUriRegexResult[1];var isBase64=!!dataUriRegexResult[2];var data=dataUriRegexResult[3];data=decodeURIComponent(data);if(isBase64)data=atob(data);try{var response;var responseType=(this.responseType||'').toLowerCase();switch(responseType){case'arraybuffer':case'blob':var view=new Uint8Array(data.length);for(var i=0;i<data.length;i++){view[i]=data.charCodeAt(i);}if(responseType==='blob'){response=new Blob([view.buffer],{type:mimeType});}else {response=view.buffer;}break;case'document':var parser=new DOMParser();response=parser.parseFromString(data,mimeType);break;case'json':response=JSON.parse(data);break;default:// 'text' or other
|
2801 | response=data;break;}// Wait for next browser tick like standard XMLHttpRequest event dispatching does
|
2802 | setTimeout(function(){if(onLoad)onLoad(response);scope.manager.itemEnd(url);},0);}catch(error){// Wait for next browser tick like standard XMLHttpRequest event dispatching does
|
2803 | setTimeout(function(){if(onError)onError(error);scope.manager.itemError(url);scope.manager.itemEnd(url);},0);}}else {// Initialise array for duplicate requests
|
2804 | loading[url]=[];loading[url].push({onLoad:onLoad,onProgress:onProgress,onError:onError});var request=new XMLHttpRequest();request.open('GET',url,true);request.addEventListener('load',function(event){var response=this.response;var callbacks=loading[url];delete loading[url];if(this.status===200||this.status===0){// Some browsers return HTTP Status 0 when using non-http protocol
|
2805 | // e.g. 'file://' or 'data://'. Handle as success.
|
2806 | if(this.status===0)console.warn('THREE.FileLoader: HTTP Status 0 received.');// Add to cache only on HTTP success, so that we do not cache
|
2807 | // error response bodies as proper responses to requests.
|
2808 | Cache.add(url,response);for(var i=0,il=callbacks.length;i<il;i++){var callback=callbacks[i];if(callback.onLoad)callback.onLoad(response);}scope.manager.itemEnd(url);}else {for(var i=0,il=callbacks.length;i<il;i++){var callback=callbacks[i];if(callback.onError)callback.onError(event);}scope.manager.itemError(url);scope.manager.itemEnd(url);}},false);request.addEventListener('progress',function(event){var callbacks=loading[url];for(var i=0,il=callbacks.length;i<il;i++){var callback=callbacks[i];if(callback.onProgress)callback.onProgress(event);}},false);request.addEventListener('error',function(event){var callbacks=loading[url];delete loading[url];for(var i=0,il=callbacks.length;i<il;i++){var callback=callbacks[i];if(callback.onError)callback.onError(event);}scope.manager.itemError(url);scope.manager.itemEnd(url);},false);request.addEventListener('abort',function(event){var callbacks=loading[url];delete loading[url];for(var i=0,il=callbacks.length;i<il;i++){var callback=callbacks[i];if(callback.onError)callback.onError(event);}scope.manager.itemError(url);scope.manager.itemEnd(url);},false);if(this.responseType!==undefined)request.responseType=this.responseType;if(this.withCredentials!==undefined)request.withCredentials=this.withCredentials;if(request.overrideMimeType)request.overrideMimeType(this.mimeType!==undefined?this.mimeType:'text/plain');for(var header in this.requestHeader){request.setRequestHeader(header,this.requestHeader[header]);}request.send(null);}scope.manager.itemStart(url);return request;},setResponseType:function setResponseType(value){this.responseType=value;return this;},setWithCredentials:function setWithCredentials(value){this.withCredentials=value;return this;},setMimeType:function setMimeType(value){this.mimeType=value;return this;},setRequestHeader:function setRequestHeader(value){this.requestHeader=value;return this;}});/**
|
2809 | * @author bhouston / http://clara.io/
|
2810 | */function AnimationLoader(manager){Loader.call(this,manager);}AnimationLoader.prototype=_extends(Object.create(Loader.prototype),{constructor:AnimationLoader,load:function load(url,onLoad,onProgress,onError){var scope=this;var loader=new FileLoader(scope.manager);loader.setPath(scope.path);loader.load(url,function(text){onLoad(scope.parse(JSON.parse(text)));},onProgress,onError);},parse:function parse(json){var animations=[];for(var i=0;i<json.length;i++){var clip=AnimationClip.parse(json[i]);animations.push(clip);}return animations;}});/**
|
2811 | * @author mrdoob / http://mrdoob.com/
|
2812 | *
|
2813 | * Abstract Base class to block based textures loader (dds, pvr, ...)
|
2814 | *
|
2815 | * Sub classes have to implement the parse() method which will be used in load().
|
2816 | */function CompressedTextureLoader(manager){Loader.call(this,manager);}CompressedTextureLoader.prototype=_extends(Object.create(Loader.prototype),{constructor:CompressedTextureLoader,load:function load(url,onLoad,onProgress,onError){var scope=this;var images=[];var texture=new CompressedTexture();texture.image=images;var loader=new FileLoader(this.manager);loader.setPath(this.path);loader.setResponseType('arraybuffer');function loadTexture(i){loader.load(url[i],function(buffer){var texDatas=scope.parse(buffer,true);images[i]={width:texDatas.width,height:texDatas.height,format:texDatas.format,mipmaps:texDatas.mipmaps};loaded+=1;if(loaded===6){if(texDatas.mipmapCount===1)texture.minFilter=LinearFilter;texture.format=texDatas.format;texture.needsUpdate=true;if(onLoad)onLoad(texture);}},onProgress,onError);}if(Array.isArray(url)){var loaded=0;for(var i=0,il=url.length;i<il;++i){loadTexture(i);}}else {// compressed cubemap texture stored in a single DDS file
|
2817 | loader.load(url,function(buffer){var texDatas=scope.parse(buffer,true);if(texDatas.isCubemap){var faces=texDatas.mipmaps.length/texDatas.mipmapCount;for(var f=0;f<faces;f++){images[f]={mipmaps:[]};for(var i=0;i<texDatas.mipmapCount;i++){images[f].mipmaps.push(texDatas.mipmaps[f*texDatas.mipmapCount+i]);images[f].format=texDatas.format;images[f].width=texDatas.width;images[f].height=texDatas.height;}}}else {texture.image.width=texDatas.width;texture.image.height=texDatas.height;texture.mipmaps=texDatas.mipmaps;}if(texDatas.mipmapCount===1){texture.minFilter=LinearFilter;}texture.format=texDatas.format;texture.needsUpdate=true;if(onLoad)onLoad(texture);},onProgress,onError);}return texture;}});/**
|
2818 | * @author Nikos M. / https://github.com/foo123/
|
2819 | *
|
2820 | * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
|
2821 | *
|
2822 | * Sub classes have to implement the parse() method which will be used in load().
|
2823 | */function DataTextureLoader(manager){Loader.call(this,manager);}DataTextureLoader.prototype=_extends(Object.create(Loader.prototype),{constructor:DataTextureLoader,load:function load(url,onLoad,onProgress,onError){var scope=this;var texture=new DataTexture();var loader=new FileLoader(this.manager);loader.setResponseType('arraybuffer');loader.setPath(this.path);loader.load(url,function(buffer){var texData=scope.parse(buffer);if(!texData)return;if(texData.image!==undefined){texture.image=texData.image;}else if(texData.data!==undefined){texture.image.width=texData.width;texture.image.height=texData.height;texture.image.data=texData.data;}texture.wrapS=texData.wrapS!==undefined?texData.wrapS:ClampToEdgeWrapping;texture.wrapT=texData.wrapT!==undefined?texData.wrapT:ClampToEdgeWrapping;texture.magFilter=texData.magFilter!==undefined?texData.magFilter:LinearFilter;texture.minFilter=texData.minFilter!==undefined?texData.minFilter:LinearFilter;texture.anisotropy=texData.anisotropy!==undefined?texData.anisotropy:1;if(texData.format!==undefined){texture.format=texData.format;}if(texData.type!==undefined){texture.type=texData.type;}if(texData.mipmaps!==undefined){texture.mipmaps=texData.mipmaps;texture.minFilter=LinearMipmapLinearFilter;// presumably...
|
2824 | }if(texData.mipmapCount===1){texture.minFilter=LinearFilter;}texture.needsUpdate=true;if(onLoad)onLoad(texture,texData);},onProgress,onError);return texture;}});/**
|
2825 | * @author mrdoob / http://mrdoob.com/
|
2826 | */function ImageLoader(manager){Loader.call(this,manager);}ImageLoader.prototype=_extends(Object.create(Loader.prototype),{constructor:ImageLoader,load:function load(url,onLoad,onProgress,onError){if(this.path!==undefined)url=this.path+url;url=this.manager.resolveURL(url);var scope=this;var cached=Cache.get(url);if(cached!==undefined){scope.manager.itemStart(url);setTimeout(function(){if(onLoad)onLoad(cached);scope.manager.itemEnd(url);},0);return cached;}var image=document.createElementNS('http://www.w3.org/1999/xhtml','img');function onImageLoad(){image.removeEventListener('load',onImageLoad,false);image.removeEventListener('error',onImageError,false);Cache.add(url,this);if(onLoad)onLoad(this);scope.manager.itemEnd(url);}function onImageError(event){image.removeEventListener('load',onImageLoad,false);image.removeEventListener('error',onImageError,false);if(onError)onError(event);scope.manager.itemError(url);scope.manager.itemEnd(url);}image.addEventListener('load',onImageLoad,false);image.addEventListener('error',onImageError,false);if(url.substr(0,5)!=='data:'){if(this.crossOrigin!==undefined)image.crossOrigin=this.crossOrigin;}scope.manager.itemStart(url);image.src=url;return image;}});/**
|
2827 | * @author mrdoob / http://mrdoob.com/
|
2828 | */function CubeTextureLoader(manager){Loader.call(this,manager);}CubeTextureLoader.prototype=_extends(Object.create(Loader.prototype),{constructor:CubeTextureLoader,load:function load(urls,onLoad,onProgress,onError){var texture=new CubeTexture();var loader=new ImageLoader(this.manager);loader.setCrossOrigin(this.crossOrigin);loader.setPath(this.path);var loaded=0;function loadTexture(i){loader.load(urls[i],function(image){texture.images[i]=image;loaded++;if(loaded===6){texture.needsUpdate=true;if(onLoad)onLoad(texture);}},undefined,onError);}for(var i=0;i<urls.length;++i){loadTexture(i);}return texture;}});/**
|
2829 | * @author mrdoob / http://mrdoob.com/
|
2830 | */function TextureLoader(manager){Loader.call(this,manager);}TextureLoader.prototype=_extends(Object.create(Loader.prototype),{constructor:TextureLoader,load:function load(url,onLoad,onProgress,onError){var texture=new Texture();var loader=new ImageLoader(this.manager);loader.setCrossOrigin(this.crossOrigin);loader.setPath(this.path);loader.load(url,function(image){texture.image=image;// JPEGs can't have an alpha channel, so memory can be saved by storing them as RGB.
|
2831 | var isJPEG=url.search(/\.jpe?g($|\?)/i)>0||url.search(/^data\:image\/jpeg/)===0;texture.format=isJPEG?RGBFormat:RGBAFormat;texture.needsUpdate=true;if(onLoad!==undefined){onLoad(texture);}},onProgress,onError);return texture;}});/**
|
2832 | * @author zz85 / http://www.lab4games.net/zz85/blog
|
2833 | * Extensible curve object
|
2834 | *
|
2835 | * Some common of curve methods:
|
2836 | * .getPoint( t, optionalTarget ), .getTangent( t, optionalTarget )
|
2837 | * .getPointAt( u, optionalTarget ), .getTangentAt( u, optionalTarget )
|
2838 | * .getPoints(), .getSpacedPoints()
|
2839 | * .getLength()
|
2840 | * .updateArcLengths()
|
2841 | *
|
2842 | * This following curves inherit from THREE.Curve:
|
2843 | *
|
2844 | * -- 2D curves --
|
2845 | * THREE.ArcCurve
|
2846 | * THREE.CubicBezierCurve
|
2847 | * THREE.EllipseCurve
|
2848 | * THREE.LineCurve
|
2849 | * THREE.QuadraticBezierCurve
|
2850 | * THREE.SplineCurve
|
2851 | *
|
2852 | * -- 3D curves --
|
2853 | * THREE.CatmullRomCurve3
|
2854 | * THREE.CubicBezierCurve3
|
2855 | * THREE.LineCurve3
|
2856 | * THREE.QuadraticBezierCurve3
|
2857 | *
|
2858 | * A series of curves can be represented as a THREE.CurvePath.
|
2859 | *
|
2860 | **/ /**************************************************************
|
2861 | * Abstract Curve base class
|
2862 | **************************************************************/function Curve(){this.type='Curve';this.arcLengthDivisions=200;}_extends(Curve.prototype,{// Virtual base class method to overwrite and implement in subclasses
|
2863 | // - t [0 .. 1]
|
2864 | getPoint:function getPoint()/* t, optionalTarget */{console.warn('THREE.Curve: .getPoint() not implemented.');return null;},// Get point at relative position in curve according to arc length
|
2865 | // - u [0 .. 1]
|
2866 | getPointAt:function getPointAt(u,optionalTarget){var t=this.getUtoTmapping(u);return this.getPoint(t,optionalTarget);},// Get sequence of points using getPoint( t )
|
2867 | getPoints:function getPoints(divisions){if(divisions===undefined)divisions=5;var points=[];for(var d=0;d<=divisions;d++){points.push(this.getPoint(d/divisions));}return points;},// Get sequence of points using getPointAt( u )
|
2868 | getSpacedPoints:function getSpacedPoints(divisions){if(divisions===undefined)divisions=5;var points=[];for(var d=0;d<=divisions;d++){points.push(this.getPointAt(d/divisions));}return points;},// Get total curve arc length
|
2869 | getLength:function getLength(){var lengths=this.getLengths();return lengths[lengths.length-1];},// Get list of cumulative segment lengths
|
2870 | getLengths:function getLengths(divisions){if(divisions===undefined)divisions=this.arcLengthDivisions;if(this.cacheArcLengths&&this.cacheArcLengths.length===divisions+1&&!this.needsUpdate){return this.cacheArcLengths;}this.needsUpdate=false;var cache=[];var current,last=this.getPoint(0);var p,sum=0;cache.push(0);for(p=1;p<=divisions;p++){current=this.getPoint(p/divisions);sum+=current.distanceTo(last);cache.push(sum);last=current;}this.cacheArcLengths=cache;return cache;// { sums: cache, sum: sum }; Sum is in the last element.
|
2871 | },updateArcLengths:function updateArcLengths(){this.needsUpdate=true;this.getLengths();},// Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
|
2872 | getUtoTmapping:function getUtoTmapping(u,distance){var arcLengths=this.getLengths();var i=0,il=arcLengths.length;var targetArcLength;// The targeted u distance value to get
|
2873 | if(distance){targetArcLength=distance;}else {targetArcLength=u*arcLengths[il-1];}// binary search for the index with largest value smaller than target u distance
|
2874 | var low=0,high=il-1,comparison;while(low<=high){i=Math.floor(low+(high-low)/2);// less likely to overflow, though probably not issue here, JS doesn't really have integers, all numbers are floats
|
2875 | comparison=arcLengths[i]-targetArcLength;if(comparison<0){low=i+1;}else if(comparison>0){high=i-1;}else {high=i;break;// DONE
|
2876 | }}i=high;if(arcLengths[i]===targetArcLength){return i/(il-1);}// we could get finer grain at lengths, or use simple interpolation between two points
|
2877 | var lengthBefore=arcLengths[i];var lengthAfter=arcLengths[i+1];var segmentLength=lengthAfter-lengthBefore;// determine where we are between the 'before' and 'after' points
|
2878 | var segmentFraction=(targetArcLength-lengthBefore)/segmentLength;// add that fractional amount to t
|
2879 | var t=(i+segmentFraction)/(il-1);return t;},// Returns a unit vector tangent at t
|
2880 | // In case any sub curve does not implement its tangent derivation,
|
2881 | // 2 points a small delta apart will be used to find its gradient
|
2882 | // which seems to give a reasonable approximation
|
2883 | getTangent:function getTangent(t,optionalTarget){var delta=0.0001;var t1=t-delta;var t2=t+delta;// Capping in case of danger
|
2884 | if(t1<0)t1=0;if(t2>1)t2=1;var pt1=this.getPoint(t1);var pt2=this.getPoint(t2);var tangent=optionalTarget||(pt1.isVector2?new Vector2():new Vector3());tangent.copy(pt2).sub(pt1).normalize();return tangent;},getTangentAt:function getTangentAt(u,optionalTarget){var t=this.getUtoTmapping(u);return this.getTangent(t,optionalTarget);},computeFrenetFrames:function computeFrenetFrames(segments,closed){// see http://www.cs.indiana.edu/pub/techreports/TR425.pdf
|
2885 | var normal=new Vector3();var tangents=[];var normals=[];var binormals=[];var vec=new Vector3();var mat=new Matrix4();var i,u,theta;// compute the tangent vectors for each segment on the curve
|
2886 | for(i=0;i<=segments;i++){u=i/segments;tangents[i]=this.getTangentAt(u,new Vector3());tangents[i].normalize();}// select an initial normal vector perpendicular to the first tangent vector,
|
2887 | // and in the direction of the minimum tangent xyz component
|
2888 | normals[0]=new Vector3();binormals[0]=new Vector3();var min=Number.MAX_VALUE;var tx=Math.abs(tangents[0].x);var ty=Math.abs(tangents[0].y);var tz=Math.abs(tangents[0].z);if(tx<=min){min=tx;normal.set(1,0,0);}if(ty<=min){min=ty;normal.set(0,1,0);}if(tz<=min){normal.set(0,0,1);}vec.crossVectors(tangents[0],normal).normalize();normals[0].crossVectors(tangents[0],vec);binormals[0].crossVectors(tangents[0],normals[0]);// compute the slowly-varying normal and binormal vectors for each segment on the curve
|
2889 | for(i=1;i<=segments;i++){normals[i]=normals[i-1].clone();binormals[i]=binormals[i-1].clone();vec.crossVectors(tangents[i-1],tangents[i]);if(vec.length()>Number.EPSILON){vec.normalize();theta=Math.acos(MathUtils.clamp(tangents[i-1].dot(tangents[i]),-1,1));// clamp for floating pt errors
|
2890 | normals[i].applyMatrix4(mat.makeRotationAxis(vec,theta));}binormals[i].crossVectors(tangents[i],normals[i]);}// if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
|
2891 | if(closed===true){theta=Math.acos(MathUtils.clamp(normals[0].dot(normals[segments]),-1,1));theta/=segments;if(tangents[0].dot(vec.crossVectors(normals[0],normals[segments]))>0){theta=-theta;}for(i=1;i<=segments;i++){// twist a little...
|
2892 | normals[i].applyMatrix4(mat.makeRotationAxis(tangents[i],theta*i));binormals[i].crossVectors(tangents[i],normals[i]);}}return {tangents:tangents,normals:normals,binormals:binormals};},clone:function clone(){return new this.constructor().copy(this);},copy:function copy(source){this.arcLengthDivisions=source.arcLengthDivisions;return this;},toJSON:function toJSON(){var data={metadata:{version:4.5,type:'Curve',generator:'Curve.toJSON'}};data.arcLengthDivisions=this.arcLengthDivisions;data.type=this.type;return data;},fromJSON:function fromJSON(json){this.arcLengthDivisions=json.arcLengthDivisions;return this;}});function EllipseCurve(aX,aY,xRadius,yRadius,aStartAngle,aEndAngle,aClockwise,aRotation){Curve.call(this);this.type='EllipseCurve';this.aX=aX||0;this.aY=aY||0;this.xRadius=xRadius||1;this.yRadius=yRadius||1;this.aStartAngle=aStartAngle||0;this.aEndAngle=aEndAngle||2*Math.PI;this.aClockwise=aClockwise||false;this.aRotation=aRotation||0;}EllipseCurve.prototype=Object.create(Curve.prototype);EllipseCurve.prototype.constructor=EllipseCurve;EllipseCurve.prototype.isEllipseCurve=true;EllipseCurve.prototype.getPoint=function(t,optionalTarget){var point=optionalTarget||new Vector2();var twoPi=Math.PI*2;var deltaAngle=this.aEndAngle-this.aStartAngle;var samePoints=Math.abs(deltaAngle)<Number.EPSILON;// ensures that deltaAngle is 0 .. 2 PI
|
2893 | while(deltaAngle<0){deltaAngle+=twoPi;}while(deltaAngle>twoPi){deltaAngle-=twoPi;}if(deltaAngle<Number.EPSILON){if(samePoints){deltaAngle=0;}else {deltaAngle=twoPi;}}if(this.aClockwise===true&&!samePoints){if(deltaAngle===twoPi){deltaAngle=-twoPi;}else {deltaAngle=deltaAngle-twoPi;}}var angle=this.aStartAngle+t*deltaAngle;var x=this.aX+this.xRadius*Math.cos(angle);var y=this.aY+this.yRadius*Math.sin(angle);if(this.aRotation!==0){var cos=Math.cos(this.aRotation);var sin=Math.sin(this.aRotation);var tx=x-this.aX;var ty=y-this.aY;// Rotate the point about the center of the ellipse.
|
2894 | x=tx*cos-ty*sin+this.aX;y=tx*sin+ty*cos+this.aY;}return point.set(x,y);};EllipseCurve.prototype.copy=function(source){Curve.prototype.copy.call(this,source);this.aX=source.aX;this.aY=source.aY;this.xRadius=source.xRadius;this.yRadius=source.yRadius;this.aStartAngle=source.aStartAngle;this.aEndAngle=source.aEndAngle;this.aClockwise=source.aClockwise;this.aRotation=source.aRotation;return this;};EllipseCurve.prototype.toJSON=function(){var data=Curve.prototype.toJSON.call(this);data.aX=this.aX;data.aY=this.aY;data.xRadius=this.xRadius;data.yRadius=this.yRadius;data.aStartAngle=this.aStartAngle;data.aEndAngle=this.aEndAngle;data.aClockwise=this.aClockwise;data.aRotation=this.aRotation;return data;};EllipseCurve.prototype.fromJSON=function(json){Curve.prototype.fromJSON.call(this,json);this.aX=json.aX;this.aY=json.aY;this.xRadius=json.xRadius;this.yRadius=json.yRadius;this.aStartAngle=json.aStartAngle;this.aEndAngle=json.aEndAngle;this.aClockwise=json.aClockwise;this.aRotation=json.aRotation;return this;};function ArcCurve(aX,aY,aRadius,aStartAngle,aEndAngle,aClockwise){EllipseCurve.call(this,aX,aY,aRadius,aRadius,aStartAngle,aEndAngle,aClockwise);this.type='ArcCurve';}ArcCurve.prototype=Object.create(EllipseCurve.prototype);ArcCurve.prototype.constructor=ArcCurve;ArcCurve.prototype.isArcCurve=true;/**
|
2895 | * @author zz85 https://github.com/zz85
|
2896 | *
|
2897 | * Centripetal CatmullRom Curve - which is useful for avoiding
|
2898 | * cusps and self-intersections in non-uniform catmull rom curves.
|
2899 | * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
|
2900 | *
|
2901 | * curve.type accepts centripetal(default), chordal and catmullrom
|
2902 | * curve.tension is used for catmullrom which defaults to 0.5
|
2903 | */ /*
|
2904 | Based on an optimized c++ solution in
|
2905 | - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
|
2906 | - http://ideone.com/NoEbVM
|
2907 |
|
2908 | This CubicPoly class could be used for reusing some variables and calculations,
|
2909 | but for three.js curve use, it could be possible inlined and flatten into a single function call
|
2910 | which can be placed in CurveUtils.
|
2911 | */function CubicPoly(){var c0=0,c1=0,c2=0,c3=0;/*
|
2912 | * Compute coefficients for a cubic polynomial
|
2913 | * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
|
2914 | * such that
|
2915 | * p(0) = x0, p(1) = x1
|
2916 | * and
|
2917 | * p'(0) = t0, p'(1) = t1.
|
2918 | */function init(x0,x1,t0,t1){c0=x0;c1=t0;c2=-3*x0+3*x1-2*t0-t1;c3=2*x0-2*x1+t0+t1;}return {initCatmullRom:function initCatmullRom(x0,x1,x2,x3,tension){init(x1,x2,tension*(x2-x0),tension*(x3-x1));},initNonuniformCatmullRom:function initNonuniformCatmullRom(x0,x1,x2,x3,dt0,dt1,dt2){// compute tangents when parameterized in [t1,t2]
|
2919 | var t1=(x1-x0)/dt0-(x2-x0)/(dt0+dt1)+(x2-x1)/dt1;var t2=(x2-x1)/dt1-(x3-x1)/(dt1+dt2)+(x3-x2)/dt2;// rescale tangents for parametrization in [0,1]
|
2920 | t1*=dt1;t2*=dt1;init(x1,x2,t1,t2);},calc:function calc(t){var t2=t*t;var t3=t2*t;return c0+c1*t+c2*t2+c3*t3;}};}//
|
2921 | var tmp=new Vector3();var px=new CubicPoly(),py=new CubicPoly(),pz=new CubicPoly();function CatmullRomCurve3(points,closed,curveType,tension){Curve.call(this);this.type='CatmullRomCurve3';this.points=points||[];this.closed=closed||false;this.curveType=curveType||'centripetal';this.tension=tension||0.5;}CatmullRomCurve3.prototype=Object.create(Curve.prototype);CatmullRomCurve3.prototype.constructor=CatmullRomCurve3;CatmullRomCurve3.prototype.isCatmullRomCurve3=true;CatmullRomCurve3.prototype.getPoint=function(t,optionalTarget){var point=optionalTarget||new Vector3();var points=this.points;var l=points.length;var p=(l-(this.closed?0:1))*t;var intPoint=Math.floor(p);var weight=p-intPoint;if(this.closed){intPoint+=intPoint>0?0:(Math.floor(Math.abs(intPoint)/l)+1)*l;}else if(weight===0&&intPoint===l-1){intPoint=l-2;weight=1;}var p0,p1,p2,p3;// 4 points
|
2922 | if(this.closed||intPoint>0){p0=points[(intPoint-1)%l];}else {// extrapolate first point
|
2923 | tmp.subVectors(points[0],points[1]).add(points[0]);p0=tmp;}p1=points[intPoint%l];p2=points[(intPoint+1)%l];if(this.closed||intPoint+2<l){p3=points[(intPoint+2)%l];}else {// extrapolate last point
|
2924 | tmp.subVectors(points[l-1],points[l-2]).add(points[l-1]);p3=tmp;}if(this.curveType==='centripetal'||this.curveType==='chordal'){// init Centripetal / Chordal Catmull-Rom
|
2925 | var pow=this.curveType==='chordal'?0.5:0.25;var dt0=Math.pow(p0.distanceToSquared(p1),pow);var dt1=Math.pow(p1.distanceToSquared(p2),pow);var dt2=Math.pow(p2.distanceToSquared(p3),pow);// safety check for repeated points
|
2926 | if(dt1<1e-4)dt1=1.0;if(dt0<1e-4)dt0=dt1;if(dt2<1e-4)dt2=dt1;px.initNonuniformCatmullRom(p0.x,p1.x,p2.x,p3.x,dt0,dt1,dt2);py.initNonuniformCatmullRom(p0.y,p1.y,p2.y,p3.y,dt0,dt1,dt2);pz.initNonuniformCatmullRom(p0.z,p1.z,p2.z,p3.z,dt0,dt1,dt2);}else if(this.curveType==='catmullrom'){px.initCatmullRom(p0.x,p1.x,p2.x,p3.x,this.tension);py.initCatmullRom(p0.y,p1.y,p2.y,p3.y,this.tension);pz.initCatmullRom(p0.z,p1.z,p2.z,p3.z,this.tension);}point.set(px.calc(weight),py.calc(weight),pz.calc(weight));return point;};CatmullRomCurve3.prototype.copy=function(source){Curve.prototype.copy.call(this,source);this.points=[];for(var i=0,l=source.points.length;i<l;i++){var point=source.points[i];this.points.push(point.clone());}this.closed=source.closed;this.curveType=source.curveType;this.tension=source.tension;return this;};CatmullRomCurve3.prototype.toJSON=function(){var data=Curve.prototype.toJSON.call(this);data.points=[];for(var i=0,l=this.points.length;i<l;i++){var point=this.points[i];data.points.push(point.toArray());}data.closed=this.closed;data.curveType=this.curveType;data.tension=this.tension;return data;};CatmullRomCurve3.prototype.fromJSON=function(json){Curve.prototype.fromJSON.call(this,json);this.points=[];for(var i=0,l=json.points.length;i<l;i++){var point=json.points[i];this.points.push(new Vector3().fromArray(point));}this.closed=json.closed;this.curveType=json.curveType;this.tension=json.tension;return this;};/**
|
2927 | * @author zz85 / http://www.lab4games.net/zz85/blog
|
2928 | *
|
2929 | * Bezier Curves formulas obtained from
|
2930 | * http://en.wikipedia.org/wiki/Bézier_curve
|
2931 | */function CatmullRom(t,p0,p1,p2,p3){var v0=(p2-p0)*0.5;var v1=(p3-p1)*0.5;var t2=t*t;var t3=t*t2;return (2*p1-2*p2+v0+v1)*t3+(-3*p1+3*p2-2*v0-v1)*t2+v0*t+p1;}//
|
2932 | function QuadraticBezierP0(t,p){var k=1-t;return k*k*p;}function QuadraticBezierP1(t,p){return 2*(1-t)*t*p;}function QuadraticBezierP2(t,p){return t*t*p;}function QuadraticBezier(t,p0,p1,p2){return QuadraticBezierP0(t,p0)+QuadraticBezierP1(t,p1)+QuadraticBezierP2(t,p2);}//
|
2933 | function CubicBezierP0(t,p){var k=1-t;return k*k*k*p;}function CubicBezierP1(t,p){var k=1-t;return 3*k*k*t*p;}function CubicBezierP2(t,p){return 3*(1-t)*t*t*p;}function CubicBezierP3(t,p){return t*t*t*p;}function CubicBezier(t,p0,p1,p2,p3){return CubicBezierP0(t,p0)+CubicBezierP1(t,p1)+CubicBezierP2(t,p2)+CubicBezierP3(t,p3);}function CubicBezierCurve(v0,v1,v2,v3){Curve.call(this);this.type='CubicBezierCurve';this.v0=v0||new Vector2();this.v1=v1||new Vector2();this.v2=v2||new Vector2();this.v3=v3||new Vector2();}CubicBezierCurve.prototype=Object.create(Curve.prototype);CubicBezierCurve.prototype.constructor=CubicBezierCurve;CubicBezierCurve.prototype.isCubicBezierCurve=true;CubicBezierCurve.prototype.getPoint=function(t,optionalTarget){var point=optionalTarget||new Vector2();var v0=this.v0,v1=this.v1,v2=this.v2,v3=this.v3;point.set(CubicBezier(t,v0.x,v1.x,v2.x,v3.x),CubicBezier(t,v0.y,v1.y,v2.y,v3.y));return point;};CubicBezierCurve.prototype.copy=function(source){Curve.prototype.copy.call(this,source);this.v0.copy(source.v0);this.v1.copy(source.v1);this.v2.copy(source.v2);this.v3.copy(source.v3);return this;};CubicBezierCurve.prototype.toJSON=function(){var data=Curve.prototype.toJSON.call(this);data.v0=this.v0.toArray();data.v1=this.v1.toArray();data.v2=this.v2.toArray();data.v3=this.v3.toArray();return data;};CubicBezierCurve.prototype.fromJSON=function(json){Curve.prototype.fromJSON.call(this,json);this.v0.fromArray(json.v0);this.v1.fromArray(json.v1);this.v2.fromArray(json.v2);this.v3.fromArray(json.v3);return this;};function CubicBezierCurve3(v0,v1,v2,v3){Curve.call(this);this.type='CubicBezierCurve3';this.v0=v0||new Vector3();this.v1=v1||new Vector3();this.v2=v2||new Vector3();this.v3=v3||new Vector3();}CubicBezierCurve3.prototype=Object.create(Curve.prototype);CubicBezierCurve3.prototype.constructor=CubicBezierCurve3;CubicBezierCurve3.prototype.isCubicBezierCurve3=true;CubicBezierCurve3.prototype.getPoint=function(t,optionalTarget){var point=optionalTarget||new Vector3();var v0=this.v0,v1=this.v1,v2=this.v2,v3=this.v3;point.set(CubicBezier(t,v0.x,v1.x,v2.x,v3.x),CubicBezier(t,v0.y,v1.y,v2.y,v3.y),CubicBezier(t,v0.z,v1.z,v2.z,v3.z));return point;};CubicBezierCurve3.prototype.copy=function(source){Curve.prototype.copy.call(this,source);this.v0.copy(source.v0);this.v1.copy(source.v1);this.v2.copy(source.v2);this.v3.copy(source.v3);return this;};CubicBezierCurve3.prototype.toJSON=function(){var data=Curve.prototype.toJSON.call(this);data.v0=this.v0.toArray();data.v1=this.v1.toArray();data.v2=this.v2.toArray();data.v3=this.v3.toArray();return data;};CubicBezierCurve3.prototype.fromJSON=function(json){Curve.prototype.fromJSON.call(this,json);this.v0.fromArray(json.v0);this.v1.fromArray(json.v1);this.v2.fromArray(json.v2);this.v3.fromArray(json.v3);return this;};function LineCurve(v1,v2){Curve.call(this);this.type='LineCurve';this.v1=v1||new Vector2();this.v2=v2||new Vector2();}LineCurve.prototype=Object.create(Curve.prototype);LineCurve.prototype.constructor=LineCurve;LineCurve.prototype.isLineCurve=true;LineCurve.prototype.getPoint=function(t,optionalTarget){var point=optionalTarget||new Vector2();if(t===1){point.copy(this.v2);}else {point.copy(this.v2).sub(this.v1);point.multiplyScalar(t).add(this.v1);}return point;};// Line curve is linear, so we can overwrite default getPointAt
|
2934 | LineCurve.prototype.getPointAt=function(u,optionalTarget){return this.getPoint(u,optionalTarget);};LineCurve.prototype.getTangent=function(t,optionalTarget){var tangent=optionalTarget||new Vector2();var tangent=tangent.copy(this.v2).sub(this.v1).normalize();return tangent;};LineCurve.prototype.copy=function(source){Curve.prototype.copy.call(this,source);this.v1.copy(source.v1);this.v2.copy(source.v2);return this;};LineCurve.prototype.toJSON=function(){var data=Curve.prototype.toJSON.call(this);data.v1=this.v1.toArray();data.v2=this.v2.toArray();return data;};LineCurve.prototype.fromJSON=function(json){Curve.prototype.fromJSON.call(this,json);this.v1.fromArray(json.v1);this.v2.fromArray(json.v2);return this;};function LineCurve3(v1,v2){Curve.call(this);this.type='LineCurve3';this.v1=v1||new Vector3();this.v2=v2||new Vector3();}LineCurve3.prototype=Object.create(Curve.prototype);LineCurve3.prototype.constructor=LineCurve3;LineCurve3.prototype.isLineCurve3=true;LineCurve3.prototype.getPoint=function(t,optionalTarget){var point=optionalTarget||new Vector3();if(t===1){point.copy(this.v2);}else {point.copy(this.v2).sub(this.v1);point.multiplyScalar(t).add(this.v1);}return point;};// Line curve is linear, so we can overwrite default getPointAt
|
2935 | LineCurve3.prototype.getPointAt=function(u,optionalTarget){return this.getPoint(u,optionalTarget);};LineCurve3.prototype.copy=function(source){Curve.prototype.copy.call(this,source);this.v1.copy(source.v1);this.v2.copy(source.v2);return this;};LineCurve3.prototype.toJSON=function(){var data=Curve.prototype.toJSON.call(this);data.v1=this.v1.toArray();data.v2=this.v2.toArray();return data;};LineCurve3.prototype.fromJSON=function(json){Curve.prototype.fromJSON.call(this,json);this.v1.fromArray(json.v1);this.v2.fromArray(json.v2);return this;};function QuadraticBezierCurve(v0,v1,v2){Curve.call(this);this.type='QuadraticBezierCurve';this.v0=v0||new Vector2();this.v1=v1||new Vector2();this.v2=v2||new Vector2();}QuadraticBezierCurve.prototype=Object.create(Curve.prototype);QuadraticBezierCurve.prototype.constructor=QuadraticBezierCurve;QuadraticBezierCurve.prototype.isQuadraticBezierCurve=true;QuadraticBezierCurve.prototype.getPoint=function(t,optionalTarget){var point=optionalTarget||new Vector2();var v0=this.v0,v1=this.v1,v2=this.v2;point.set(QuadraticBezier(t,v0.x,v1.x,v2.x),QuadraticBezier(t,v0.y,v1.y,v2.y));return point;};QuadraticBezierCurve.prototype.copy=function(source){Curve.prototype.copy.call(this,source);this.v0.copy(source.v0);this.v1.copy(source.v1);this.v2.copy(source.v2);return this;};QuadraticBezierCurve.prototype.toJSON=function(){var data=Curve.prototype.toJSON.call(this);data.v0=this.v0.toArray();data.v1=this.v1.toArray();data.v2=this.v2.toArray();return data;};QuadraticBezierCurve.prototype.fromJSON=function(json){Curve.prototype.fromJSON.call(this,json);this.v0.fromArray(json.v0);this.v1.fromArray(json.v1);this.v2.fromArray(json.v2);return this;};function QuadraticBezierCurve3(v0,v1,v2){Curve.call(this);this.type='QuadraticBezierCurve3';this.v0=v0||new Vector3();this.v1=v1||new Vector3();this.v2=v2||new Vector3();}QuadraticBezierCurve3.prototype=Object.create(Curve.prototype);QuadraticBezierCurve3.prototype.constructor=QuadraticBezierCurve3;QuadraticBezierCurve3.prototype.isQuadraticBezierCurve3=true;QuadraticBezierCurve3.prototype.getPoint=function(t,optionalTarget){var point=optionalTarget||new Vector3();var v0=this.v0,v1=this.v1,v2=this.v2;point.set(QuadraticBezier(t,v0.x,v1.x,v2.x),QuadraticBezier(t,v0.y,v1.y,v2.y),QuadraticBezier(t,v0.z,v1.z,v2.z));return point;};QuadraticBezierCurve3.prototype.copy=function(source){Curve.prototype.copy.call(this,source);this.v0.copy(source.v0);this.v1.copy(source.v1);this.v2.copy(source.v2);return this;};QuadraticBezierCurve3.prototype.toJSON=function(){var data=Curve.prototype.toJSON.call(this);data.v0=this.v0.toArray();data.v1=this.v1.toArray();data.v2=this.v2.toArray();return data;};QuadraticBezierCurve3.prototype.fromJSON=function(json){Curve.prototype.fromJSON.call(this,json);this.v0.fromArray(json.v0);this.v1.fromArray(json.v1);this.v2.fromArray(json.v2);return this;};function SplineCurve(points/* array of Vector2 */){Curve.call(this);this.type='SplineCurve';this.points=points||[];}SplineCurve.prototype=Object.create(Curve.prototype);SplineCurve.prototype.constructor=SplineCurve;SplineCurve.prototype.isSplineCurve=true;SplineCurve.prototype.getPoint=function(t,optionalTarget){var point=optionalTarget||new Vector2();var points=this.points;var p=(points.length-1)*t;var intPoint=Math.floor(p);var weight=p-intPoint;var p0=points[intPoint===0?intPoint:intPoint-1];var p1=points[intPoint];var p2=points[intPoint>points.length-2?points.length-1:intPoint+1];var p3=points[intPoint>points.length-3?points.length-1:intPoint+2];point.set(CatmullRom(weight,p0.x,p1.x,p2.x,p3.x),CatmullRom(weight,p0.y,p1.y,p2.y,p3.y));return point;};SplineCurve.prototype.copy=function(source){Curve.prototype.copy.call(this,source);this.points=[];for(var i=0,l=source.points.length;i<l;i++){var point=source.points[i];this.points.push(point.clone());}return this;};SplineCurve.prototype.toJSON=function(){var data=Curve.prototype.toJSON.call(this);data.points=[];for(var i=0,l=this.points.length;i<l;i++){var point=this.points[i];data.points.push(point.toArray());}return data;};SplineCurve.prototype.fromJSON=function(json){Curve.prototype.fromJSON.call(this,json);this.points=[];for(var i=0,l=json.points.length;i<l;i++){var point=json.points[i];this.points.push(new Vector2().fromArray(point));}return this;};var Curves=/*#__PURE__*/Object.freeze({__proto__:null,ArcCurve:ArcCurve,CatmullRomCurve3:CatmullRomCurve3,CubicBezierCurve:CubicBezierCurve,CubicBezierCurve3:CubicBezierCurve3,EllipseCurve:EllipseCurve,LineCurve:LineCurve,LineCurve3:LineCurve3,QuadraticBezierCurve:QuadraticBezierCurve,QuadraticBezierCurve3:QuadraticBezierCurve3,SplineCurve:SplineCurve});/**
|
2936 | * @author zz85 / http://www.lab4games.net/zz85/blog
|
2937 | *
|
2938 | **/ /**************************************************************
|
2939 | * Curved Path - a curve path is simply a array of connected
|
2940 | * curves, but retains the api of a curve
|
2941 | **************************************************************/function CurvePath(){Curve.call(this);this.type='CurvePath';this.curves=[];this.autoClose=false;// Automatically closes the path
|
2942 | }CurvePath.prototype=_extends(Object.create(Curve.prototype),{constructor:CurvePath,add:function add(curve){this.curves.push(curve);},closePath:function closePath(){// Add a line curve if start and end of lines are not connected
|
2943 | var startPoint=this.curves[0].getPoint(0);var endPoint=this.curves[this.curves.length-1].getPoint(1);if(!startPoint.equals(endPoint)){this.curves.push(new LineCurve(endPoint,startPoint));}},// To get accurate point with reference to
|
2944 | // entire path distance at time t,
|
2945 | // following has to be done:
|
2946 | // 1. Length of each sub path have to be known
|
2947 | // 2. Locate and identify type of curve
|
2948 | // 3. Get t for the curve
|
2949 | // 4. Return curve.getPointAt(t')
|
2950 | getPoint:function getPoint(t){var d=t*this.getLength();var curveLengths=this.getCurveLengths();var i=0;// To think about boundaries points.
|
2951 | while(i<curveLengths.length){if(curveLengths[i]>=d){var diff=curveLengths[i]-d;var curve=this.curves[i];var segmentLength=curve.getLength();var u=segmentLength===0?0:1-diff/segmentLength;return curve.getPointAt(u);}i++;}return null;// loop where sum != 0, sum > d , sum+1 <d
|
2952 | },// We cannot use the default THREE.Curve getPoint() with getLength() because in
|
2953 | // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
|
2954 | // getPoint() depends on getLength
|
2955 | getLength:function getLength(){var lens=this.getCurveLengths();return lens[lens.length-1];},// cacheLengths must be recalculated.
|
2956 | updateArcLengths:function updateArcLengths(){this.needsUpdate=true;this.cacheLengths=null;this.getCurveLengths();},// Compute lengths and cache them
|
2957 | // We cannot overwrite getLengths() because UtoT mapping uses it.
|
2958 | getCurveLengths:function getCurveLengths(){// We use cache values if curves and cache array are same length
|
2959 | if(this.cacheLengths&&this.cacheLengths.length===this.curves.length){return this.cacheLengths;}// Get length of sub-curve
|
2960 | // Push sums into cached array
|
2961 | var lengths=[],sums=0;for(var i=0,l=this.curves.length;i<l;i++){sums+=this.curves[i].getLength();lengths.push(sums);}this.cacheLengths=lengths;return lengths;},getSpacedPoints:function getSpacedPoints(divisions){if(divisions===undefined)divisions=40;var points=[];for(var i=0;i<=divisions;i++){points.push(this.getPoint(i/divisions));}if(this.autoClose){points.push(points[0]);}return points;},getPoints:function getPoints(divisions){divisions=divisions||12;var points=[],last;for(var i=0,curves=this.curves;i<curves.length;i++){var curve=curves[i];var resolution=curve&&curve.isEllipseCurve?divisions*2:curve&&(curve.isLineCurve||curve.isLineCurve3)?1:curve&&curve.isSplineCurve?divisions*curve.points.length:divisions;var pts=curve.getPoints(resolution);for(var j=0;j<pts.length;j++){var point=pts[j];if(last&&last.equals(point))continue;// ensures no consecutive points are duplicates
|
2962 | points.push(point);last=point;}}if(this.autoClose&&points.length>1&&!points[points.length-1].equals(points[0])){points.push(points[0]);}return points;},copy:function copy(source){Curve.prototype.copy.call(this,source);this.curves=[];for(var i=0,l=source.curves.length;i<l;i++){var curve=source.curves[i];this.curves.push(curve.clone());}this.autoClose=source.autoClose;return this;},toJSON:function toJSON(){var data=Curve.prototype.toJSON.call(this);data.autoClose=this.autoClose;data.curves=[];for(var i=0,l=this.curves.length;i<l;i++){var curve=this.curves[i];data.curves.push(curve.toJSON());}return data;},fromJSON:function fromJSON(json){Curve.prototype.fromJSON.call(this,json);this.autoClose=json.autoClose;this.curves=[];for(var i=0,l=json.curves.length;i<l;i++){var curve=json.curves[i];this.curves.push(new Curves[curve.type]().fromJSON(curve));}return this;}});/**
|
2963 | * @author zz85 / http://www.lab4games.net/zz85/blog
|
2964 | * Creates free form 2d path using series of points, lines or curves.
|
2965 | **/function Path(points){CurvePath.call(this);this.type='Path';this.currentPoint=new Vector2();if(points){this.setFromPoints(points);}}Path.prototype=_extends(Object.create(CurvePath.prototype),{constructor:Path,setFromPoints:function setFromPoints(points){this.moveTo(points[0].x,points[0].y);for(var i=1,l=points.length;i<l;i++){this.lineTo(points[i].x,points[i].y);}return this;},moveTo:function moveTo(x,y){this.currentPoint.set(x,y);// TODO consider referencing vectors instead of copying?
|
2966 | return this;},lineTo:function lineTo(x,y){var curve=new LineCurve(this.currentPoint.clone(),new Vector2(x,y));this.curves.push(curve);this.currentPoint.set(x,y);return this;},quadraticCurveTo:function quadraticCurveTo(aCPx,aCPy,aX,aY){var curve=new QuadraticBezierCurve(this.currentPoint.clone(),new Vector2(aCPx,aCPy),new Vector2(aX,aY));this.curves.push(curve);this.currentPoint.set(aX,aY);return this;},bezierCurveTo:function bezierCurveTo(aCP1x,aCP1y,aCP2x,aCP2y,aX,aY){var curve=new CubicBezierCurve(this.currentPoint.clone(),new Vector2(aCP1x,aCP1y),new Vector2(aCP2x,aCP2y),new Vector2(aX,aY));this.curves.push(curve);this.currentPoint.set(aX,aY);return this;},splineThru:function splineThru(pts/*Array of Vector*/){var npts=[this.currentPoint.clone()].concat(pts);var curve=new SplineCurve(npts);this.curves.push(curve);this.currentPoint.copy(pts[pts.length-1]);return this;},arc:function arc(aX,aY,aRadius,aStartAngle,aEndAngle,aClockwise){var x0=this.currentPoint.x;var y0=this.currentPoint.y;this.absarc(aX+x0,aY+y0,aRadius,aStartAngle,aEndAngle,aClockwise);return this;},absarc:function absarc(aX,aY,aRadius,aStartAngle,aEndAngle,aClockwise){this.absellipse(aX,aY,aRadius,aRadius,aStartAngle,aEndAngle,aClockwise);return this;},ellipse:function ellipse(aX,aY,xRadius,yRadius,aStartAngle,aEndAngle,aClockwise,aRotation){var x0=this.currentPoint.x;var y0=this.currentPoint.y;this.absellipse(aX+x0,aY+y0,xRadius,yRadius,aStartAngle,aEndAngle,aClockwise,aRotation);return this;},absellipse:function absellipse(aX,aY,xRadius,yRadius,aStartAngle,aEndAngle,aClockwise,aRotation){var curve=new EllipseCurve(aX,aY,xRadius,yRadius,aStartAngle,aEndAngle,aClockwise,aRotation);if(this.curves.length>0){// if a previous curve is present, attempt to join
|
2967 | var firstPoint=curve.getPoint(0);if(!firstPoint.equals(this.currentPoint)){this.lineTo(firstPoint.x,firstPoint.y);}}this.curves.push(curve);var lastPoint=curve.getPoint(1);this.currentPoint.copy(lastPoint);return this;},copy:function copy(source){CurvePath.prototype.copy.call(this,source);this.currentPoint.copy(source.currentPoint);return this;},toJSON:function toJSON(){var data=CurvePath.prototype.toJSON.call(this);data.currentPoint=this.currentPoint.toArray();return data;},fromJSON:function fromJSON(json){CurvePath.prototype.fromJSON.call(this,json);this.currentPoint.fromArray(json.currentPoint);return this;}});/**
|
2968 | * @author zz85 / http://www.lab4games.net/zz85/blog
|
2969 | * Defines a 2d shape plane using paths.
|
2970 | **/ // STEP 1 Create a path.
|
2971 | // STEP 2 Turn path into shape.
|
2972 | // STEP 3 ExtrudeGeometry takes in Shape/Shapes
|
2973 | // STEP 3a - Extract points from each shape, turn to vertices
|
2974 | // STEP 3b - Triangulate each shape, add faces.
|
2975 | function Shape(points){Path.call(this,points);this.uuid=MathUtils.generateUUID();this.type='Shape';this.holes=[];}Shape.prototype=_extends(Object.create(Path.prototype),{constructor:Shape,getPointsHoles:function getPointsHoles(divisions){var holesPts=[];for(var i=0,l=this.holes.length;i<l;i++){holesPts[i]=this.holes[i].getPoints(divisions);}return holesPts;},// get points of shape and holes (keypoints based on segments parameter)
|
2976 | extractPoints:function extractPoints(divisions){return {shape:this.getPoints(divisions),holes:this.getPointsHoles(divisions)};},copy:function copy(source){Path.prototype.copy.call(this,source);this.holes=[];for(var i=0,l=source.holes.length;i<l;i++){var hole=source.holes[i];this.holes.push(hole.clone());}return this;},toJSON:function toJSON(){var data=Path.prototype.toJSON.call(this);data.uuid=this.uuid;data.holes=[];for(var i=0,l=this.holes.length;i<l;i++){var hole=this.holes[i];data.holes.push(hole.toJSON());}return data;},fromJSON:function fromJSON(json){Path.prototype.fromJSON.call(this,json);this.uuid=json.uuid;this.holes=[];for(var i=0,l=json.holes.length;i<l;i++){var hole=json.holes[i];this.holes.push(new Path().fromJSON(hole));}return this;}});/**
|
2977 | * @author mrdoob / http://mrdoob.com/
|
2978 | * @author alteredq / http://alteredqualia.com/
|
2979 | */function Light(color,intensity){Object3D.call(this);this.type='Light';this.color=new Color(color);this.intensity=intensity!==undefined?intensity:1;this.receiveShadow=undefined;}Light.prototype=_extends(Object.create(Object3D.prototype),{constructor:Light,isLight:true,copy:function copy(source){Object3D.prototype.copy.call(this,source);this.color.copy(source.color);this.intensity=source.intensity;return this;},toJSON:function toJSON(meta){var data=Object3D.prototype.toJSON.call(this,meta);data.object.color=this.color.getHex();data.object.intensity=this.intensity;if(this.groundColor!==undefined)data.object.groundColor=this.groundColor.getHex();if(this.distance!==undefined)data.object.distance=this.distance;if(this.angle!==undefined)data.object.angle=this.angle;if(this.decay!==undefined)data.object.decay=this.decay;if(this.penumbra!==undefined)data.object.penumbra=this.penumbra;if(this.shadow!==undefined)data.object.shadow=this.shadow.toJSON();return data;}});/**
|
2980 | * @author alteredq / http://alteredqualia.com/
|
2981 | */function HemisphereLight(skyColor,groundColor,intensity){Light.call(this,skyColor,intensity);this.type='HemisphereLight';this.castShadow=undefined;this.position.copy(Object3D.DefaultUp);this.updateMatrix();this.groundColor=new Color(groundColor);}HemisphereLight.prototype=_extends(Object.create(Light.prototype),{constructor:HemisphereLight,isHemisphereLight:true,copy:function copy(source){Light.prototype.copy.call(this,source);this.groundColor.copy(source.groundColor);return this;}});/**
|
2982 | * @author mrdoob / http://mrdoob.com/
|
2983 | */function LightShadow(camera){this.camera=camera;this.bias=0;this.radius=1;this.mapSize=new Vector2(512,512);this.map=null;this.mapPass=null;this.matrix=new Matrix4();this._frustum=new Frustum();this._frameExtents=new Vector2(1,1);this._viewportCount=1;this._viewports=[new Vector4(0,0,1,1)];}_extends(LightShadow.prototype,{_projScreenMatrix:new Matrix4(),_lightPositionWorld:new Vector3(),_lookTarget:new Vector3(),getViewportCount:function getViewportCount(){return this._viewportCount;},getFrustum:function getFrustum(){return this._frustum;},updateMatrices:function updateMatrices(light){var shadowCamera=this.camera,shadowMatrix=this.matrix,projScreenMatrix=this._projScreenMatrix,lookTarget=this._lookTarget,lightPositionWorld=this._lightPositionWorld;lightPositionWorld.setFromMatrixPosition(light.matrixWorld);shadowCamera.position.copy(lightPositionWorld);lookTarget.setFromMatrixPosition(light.target.matrixWorld);shadowCamera.lookAt(lookTarget);shadowCamera.updateMatrixWorld();projScreenMatrix.multiplyMatrices(shadowCamera.projectionMatrix,shadowCamera.matrixWorldInverse);this._frustum.setFromProjectionMatrix(projScreenMatrix);shadowMatrix.set(0.5,0.0,0.0,0.5,0.0,0.5,0.0,0.5,0.0,0.0,0.5,0.5,0.0,0.0,0.0,1.0);shadowMatrix.multiply(shadowCamera.projectionMatrix);shadowMatrix.multiply(shadowCamera.matrixWorldInverse);},getViewport:function getViewport(viewportIndex){return this._viewports[viewportIndex];},getFrameExtents:function getFrameExtents(){return this._frameExtents;},copy:function copy(source){this.camera=source.camera.clone();this.bias=source.bias;this.radius=source.radius;this.mapSize.copy(source.mapSize);return this;},clone:function clone(){return new this.constructor().copy(this);},toJSON:function toJSON(){var object={};if(this.bias!==0)object.bias=this.bias;if(this.radius!==1)object.radius=this.radius;if(this.mapSize.x!==512||this.mapSize.y!==512)object.mapSize=this.mapSize.toArray();object.camera=this.camera.toJSON(false).object;delete object.camera.matrix;return object;}});/**
|
2984 | * @author mrdoob / http://mrdoob.com/
|
2985 | */function SpotLightShadow(){LightShadow.call(this,new PerspectiveCamera(50,1,0.5,500));}SpotLightShadow.prototype=_extends(Object.create(LightShadow.prototype),{constructor:SpotLightShadow,isSpotLightShadow:true,updateMatrices:function updateMatrices(light){var camera=this.camera;var fov=MathUtils.RAD2DEG*2*light.angle;var aspect=this.mapSize.width/this.mapSize.height;var far=light.distance||camera.far;if(fov!==camera.fov||aspect!==camera.aspect||far!==camera.far){camera.fov=fov;camera.aspect=aspect;camera.far=far;camera.updateProjectionMatrix();}LightShadow.prototype.updateMatrices.call(this,light);}});/**
|
2986 | * @author alteredq / http://alteredqualia.com/
|
2987 | */function SpotLight(color,intensity,distance,angle,penumbra,decay){Light.call(this,color,intensity);this.type='SpotLight';this.position.copy(Object3D.DefaultUp);this.updateMatrix();this.target=new Object3D();Object.defineProperty(this,'power',{get:function get(){// intensity = power per solid angle.
|
2988 | // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
|
2989 | return this.intensity*Math.PI;},set:function set(power){// intensity = power per solid angle.
|
2990 | // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
|
2991 | this.intensity=power/Math.PI;}});this.distance=distance!==undefined?distance:0;this.angle=angle!==undefined?angle:Math.PI/3;this.penumbra=penumbra!==undefined?penumbra:0;this.decay=decay!==undefined?decay:1;// for physically correct lights, should be 2.
|
2992 | this.shadow=new SpotLightShadow();}SpotLight.prototype=_extends(Object.create(Light.prototype),{constructor:SpotLight,isSpotLight:true,copy:function copy(source){Light.prototype.copy.call(this,source);this.distance=source.distance;this.angle=source.angle;this.penumbra=source.penumbra;this.decay=source.decay;this.target=source.target.clone();this.shadow=source.shadow.clone();return this;}});function PointLightShadow(){LightShadow.call(this,new PerspectiveCamera(90,1,0.5,500));this._frameExtents=new Vector2(4,2);this._viewportCount=6;this._viewports=[// These viewports map a cube-map onto a 2D texture with the
|
2993 | // following orientation:
|
2994 | //
|
2995 | // xzXZ
|
2996 | // y Y
|
2997 | //
|
2998 | // X - Positive x direction
|
2999 | // x - Negative x direction
|
3000 | // Y - Positive y direction
|
3001 | // y - Negative y direction
|
3002 | // Z - Positive z direction
|
3003 | // z - Negative z direction
|
3004 | // positive X
|
3005 | new Vector4(2,1,1,1),// negative X
|
3006 | new Vector4(0,1,1,1),// positive Z
|
3007 | new Vector4(3,1,1,1),// negative Z
|
3008 | new Vector4(1,1,1,1),// positive Y
|
3009 | new Vector4(3,0,1,1),// negative Y
|
3010 | new Vector4(1,0,1,1)];this._cubeDirections=[new Vector3(1,0,0),new Vector3(-1,0,0),new Vector3(0,0,1),new Vector3(0,0,-1),new Vector3(0,1,0),new Vector3(0,-1,0)];this._cubeUps=[new Vector3(0,1,0),new Vector3(0,1,0),new Vector3(0,1,0),new Vector3(0,1,0),new Vector3(0,0,1),new Vector3(0,0,-1)];}PointLightShadow.prototype=_extends(Object.create(LightShadow.prototype),{constructor:PointLightShadow,isPointLightShadow:true,updateMatrices:function updateMatrices(light,viewportIndex){if(viewportIndex===undefined)viewportIndex=0;var camera=this.camera,shadowMatrix=this.matrix,lightPositionWorld=this._lightPositionWorld,lookTarget=this._lookTarget,projScreenMatrix=this._projScreenMatrix;lightPositionWorld.setFromMatrixPosition(light.matrixWorld);camera.position.copy(lightPositionWorld);lookTarget.copy(camera.position);lookTarget.add(this._cubeDirections[viewportIndex]);camera.up.copy(this._cubeUps[viewportIndex]);camera.lookAt(lookTarget);camera.updateMatrixWorld();shadowMatrix.makeTranslation(-lightPositionWorld.x,-lightPositionWorld.y,-lightPositionWorld.z);projScreenMatrix.multiplyMatrices(camera.projectionMatrix,camera.matrixWorldInverse);this._frustum.setFromProjectionMatrix(projScreenMatrix);}});/**
|
3011 | * @author mrdoob / http://mrdoob.com/
|
3012 | */function PointLight(color,intensity,distance,decay){Light.call(this,color,intensity);this.type='PointLight';Object.defineProperty(this,'power',{get:function get(){// intensity = power per solid angle.
|
3013 | // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
|
3014 | return this.intensity*4*Math.PI;},set:function set(power){// intensity = power per solid angle.
|
3015 | // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
|
3016 | this.intensity=power/(4*Math.PI);}});this.distance=distance!==undefined?distance:0;this.decay=decay!==undefined?decay:1;// for physically correct lights, should be 2.
|
3017 | this.shadow=new PointLightShadow();}PointLight.prototype=_extends(Object.create(Light.prototype),{constructor:PointLight,isPointLight:true,copy:function copy(source){Light.prototype.copy.call(this,source);this.distance=source.distance;this.decay=source.decay;this.shadow=source.shadow.clone();return this;}});/**
|
3018 | * @author alteredq / http://alteredqualia.com/
|
3019 | * @author arose / http://github.com/arose
|
3020 | */function OrthographicCamera(left,right,top,bottom,near,far){Camera.call(this);this.type='OrthographicCamera';this.zoom=1;this.view=null;this.left=left!==undefined?left:-1;this.right=right!==undefined?right:1;this.top=top!==undefined?top:1;this.bottom=bottom!==undefined?bottom:-1;this.near=near!==undefined?near:0.1;this.far=far!==undefined?far:2000;this.updateProjectionMatrix();}OrthographicCamera.prototype=_extends(Object.create(Camera.prototype),{constructor:OrthographicCamera,isOrthographicCamera:true,copy:function copy(source,recursive){Camera.prototype.copy.call(this,source,recursive);this.left=source.left;this.right=source.right;this.top=source.top;this.bottom=source.bottom;this.near=source.near;this.far=source.far;this.zoom=source.zoom;this.view=source.view===null?null:_extends({},source.view);return this;},setViewOffset:function setViewOffset(fullWidth,fullHeight,x,y,width,height){if(this.view===null){this.view={enabled:true,fullWidth:1,fullHeight:1,offsetX:0,offsetY:0,width:1,height:1};}this.view.enabled=true;this.view.fullWidth=fullWidth;this.view.fullHeight=fullHeight;this.view.offsetX=x;this.view.offsetY=y;this.view.width=width;this.view.height=height;this.updateProjectionMatrix();},clearViewOffset:function clearViewOffset(){if(this.view!==null){this.view.enabled=false;}this.updateProjectionMatrix();},updateProjectionMatrix:function updateProjectionMatrix(){var dx=(this.right-this.left)/(2*this.zoom);var dy=(this.top-this.bottom)/(2*this.zoom);var cx=(this.right+this.left)/2;var cy=(this.top+this.bottom)/2;var left=cx-dx;var right=cx+dx;var top=cy+dy;var bottom=cy-dy;if(this.view!==null&&this.view.enabled){var scaleW=(this.right-this.left)/this.view.fullWidth/this.zoom;var scaleH=(this.top-this.bottom)/this.view.fullHeight/this.zoom;left+=scaleW*this.view.offsetX;right=left+scaleW*this.view.width;top-=scaleH*this.view.offsetY;bottom=top-scaleH*this.view.height;}this.projectionMatrix.makeOrthographic(left,right,top,bottom,this.near,this.far);this.projectionMatrixInverse.getInverse(this.projectionMatrix);},toJSON:function toJSON(meta){var data=Object3D.prototype.toJSON.call(this,meta);data.object.zoom=this.zoom;data.object.left=this.left;data.object.right=this.right;data.object.top=this.top;data.object.bottom=this.bottom;data.object.near=this.near;data.object.far=this.far;if(this.view!==null)data.object.view=_extends({},this.view);return data;}});/**
|
3021 | * @author mrdoob / http://mrdoob.com/
|
3022 | */function DirectionalLightShadow(){LightShadow.call(this,new OrthographicCamera(-5,5,5,-5,0.5,500));}DirectionalLightShadow.prototype=_extends(Object.create(LightShadow.prototype),{constructor:DirectionalLightShadow,isDirectionalLightShadow:true,updateMatrices:function updateMatrices(light){LightShadow.prototype.updateMatrices.call(this,light);}});/**
|
3023 | * @author mrdoob / http://mrdoob.com/
|
3024 | * @author alteredq / http://alteredqualia.com/
|
3025 | */function DirectionalLight(color,intensity){Light.call(this,color,intensity);this.type='DirectionalLight';this.position.copy(Object3D.DefaultUp);this.updateMatrix();this.target=new Object3D();this.shadow=new DirectionalLightShadow();}DirectionalLight.prototype=_extends(Object.create(Light.prototype),{constructor:DirectionalLight,isDirectionalLight:true,copy:function copy(source){Light.prototype.copy.call(this,source);this.target=source.target.clone();this.shadow=source.shadow.clone();return this;}});/**
|
3026 | * @author mrdoob / http://mrdoob.com/
|
3027 | */function AmbientLight(color,intensity){Light.call(this,color,intensity);this.type='AmbientLight';this.castShadow=undefined;}AmbientLight.prototype=_extends(Object.create(Light.prototype),{constructor:AmbientLight,isAmbientLight:true});/**
|
3028 | * @author abelnation / http://github.com/abelnation
|
3029 | */function RectAreaLight(color,intensity,width,height){Light.call(this,color,intensity);this.type='RectAreaLight';this.width=width!==undefined?width:10;this.height=height!==undefined?height:10;}RectAreaLight.prototype=_extends(Object.create(Light.prototype),{constructor:RectAreaLight,isRectAreaLight:true,copy:function copy(source){Light.prototype.copy.call(this,source);this.width=source.width;this.height=source.height;return this;},toJSON:function toJSON(meta){var data=Light.prototype.toJSON.call(this,meta);data.object.width=this.width;data.object.height=this.height;return data;}});/**
|
3030 | * @author bhouston / http://clara.io
|
3031 | * @author WestLangley / http://github.com/WestLangley
|
3032 | *
|
3033 | * Primary reference:
|
3034 | * https://graphics.stanford.edu/papers/envmap/envmap.pdf
|
3035 | *
|
3036 | * Secondary reference:
|
3037 | * https://www.ppsloan.org/publications/StupidSH36.pdf
|
3038 | */ // 3-band SH defined by 9 coefficients
|
3039 | function SphericalHarmonics3(){this.coefficients=[];for(var i=0;i<9;i++){this.coefficients.push(new Vector3());}}_extends(SphericalHarmonics3.prototype,{isSphericalHarmonics3:true,set:function set(coefficients){for(var i=0;i<9;i++){this.coefficients[i].copy(coefficients[i]);}return this;},zero:function zero(){for(var i=0;i<9;i++){this.coefficients[i].set(0,0,0);}return this;},// get the radiance in the direction of the normal
|
3040 | // target is a Vector3
|
3041 | getAt:function getAt(normal,target){// normal is assumed to be unit length
|
3042 | var x=normal.x,y=normal.y,z=normal.z;var coeff=this.coefficients;// band 0
|
3043 | target.copy(coeff[0]).multiplyScalar(0.282095);// band 1
|
3044 | target.addScaledVector(coeff[1],0.488603*y);target.addScaledVector(coeff[2],0.488603*z);target.addScaledVector(coeff[3],0.488603*x);// band 2
|
3045 | target.addScaledVector(coeff[4],1.092548*(x*y));target.addScaledVector(coeff[5],1.092548*(y*z));target.addScaledVector(coeff[6],0.315392*(3.0*z*z-1.0));target.addScaledVector(coeff[7],1.092548*(x*z));target.addScaledVector(coeff[8],0.546274*(x*x-y*y));return target;},// get the irradiance (radiance convolved with cosine lobe) in the direction of the normal
|
3046 | // target is a Vector3
|
3047 | // https://graphics.stanford.edu/papers/envmap/envmap.pdf
|
3048 | getIrradianceAt:function getIrradianceAt(normal,target){// normal is assumed to be unit length
|
3049 | var x=normal.x,y=normal.y,z=normal.z;var coeff=this.coefficients;// band 0
|
3050 | target.copy(coeff[0]).multiplyScalar(0.886227);// π * 0.282095
|
3051 | // band 1
|
3052 | target.addScaledVector(coeff[1],2.0*0.511664*y);// ( 2 * π / 3 ) * 0.488603
|
3053 | target.addScaledVector(coeff[2],2.0*0.511664*z);target.addScaledVector(coeff[3],2.0*0.511664*x);// band 2
|
3054 | target.addScaledVector(coeff[4],2.0*0.429043*x*y);// ( π / 4 ) * 1.092548
|
3055 | target.addScaledVector(coeff[5],2.0*0.429043*y*z);target.addScaledVector(coeff[6],0.743125*z*z-0.247708);// ( π / 4 ) * 0.315392 * 3
|
3056 | target.addScaledVector(coeff[7],2.0*0.429043*x*z);target.addScaledVector(coeff[8],0.429043*(x*x-y*y));// ( π / 4 ) * 0.546274
|
3057 | return target;},add:function add(sh){for(var i=0;i<9;i++){this.coefficients[i].add(sh.coefficients[i]);}return this;},addScaledSH:function addScaledSH(sh,s){for(var i=0;i<9;i++){this.coefficients[i].addScaledVector(sh.coefficients[i],s);}return this;},scale:function scale(s){for(var i=0;i<9;i++){this.coefficients[i].multiplyScalar(s);}return this;},lerp:function lerp(sh,alpha){for(var i=0;i<9;i++){this.coefficients[i].lerp(sh.coefficients[i],alpha);}return this;},equals:function equals(sh){for(var i=0;i<9;i++){if(!this.coefficients[i].equals(sh.coefficients[i])){return false;}}return true;},copy:function copy(sh){return this.set(sh.coefficients);},clone:function clone(){return new this.constructor().copy(this);},fromArray:function fromArray(array,offset){if(offset===undefined)offset=0;var coefficients=this.coefficients;for(var i=0;i<9;i++){coefficients[i].fromArray(array,offset+i*3);}return this;},toArray:function toArray(array,offset){if(array===undefined)array=[];if(offset===undefined)offset=0;var coefficients=this.coefficients;for(var i=0;i<9;i++){coefficients[i].toArray(array,offset+i*3);}return array;}});_extends(SphericalHarmonics3,{// evaluate the basis functions
|
3058 | // shBasis is an Array[ 9 ]
|
3059 | getBasisAt:function getBasisAt(normal,shBasis){// normal is assumed to be unit length
|
3060 | var x=normal.x,y=normal.y,z=normal.z;// band 0
|
3061 | shBasis[0]=0.282095;// band 1
|
3062 | shBasis[1]=0.488603*y;shBasis[2]=0.488603*z;shBasis[3]=0.488603*x;// band 2
|
3063 | shBasis[4]=1.092548*x*y;shBasis[5]=1.092548*y*z;shBasis[6]=0.315392*(3*z*z-1);shBasis[7]=1.092548*x*z;shBasis[8]=0.546274*(x*x-y*y);}});/**
|
3064 | * @author WestLangley / http://github.com/WestLangley
|
3065 | *
|
3066 | * A LightProbe is a source of indirect-diffuse light
|
3067 | */function LightProbe(sh,intensity){Light.call(this,undefined,intensity);this.type='LightProbe';this.sh=sh!==undefined?sh:new SphericalHarmonics3();}LightProbe.prototype=_extends(Object.create(Light.prototype),{constructor:LightProbe,isLightProbe:true,copy:function copy(source){Light.prototype.copy.call(this,source);this.sh.copy(source.sh);return this;},fromJSON:function fromJSON(json){this.intensity=json.intensity;// TODO: Move this bit to Light.fromJSON();
|
3068 | this.sh.fromArray(json.sh);return this;},toJSON:function toJSON(meta){var data=Light.prototype.toJSON.call(this,meta);data.object.sh=this.sh.toArray();return data;}});/**
|
3069 | * @author mrdoob / http://mrdoob.com/
|
3070 | */function MaterialLoader(manager){Loader.call(this,manager);this.textures={};}MaterialLoader.prototype=_extends(Object.create(Loader.prototype),{constructor:MaterialLoader,load:function load(url,onLoad,onProgress,onError){var scope=this;var loader=new FileLoader(scope.manager);loader.setPath(scope.path);loader.load(url,function(text){onLoad(scope.parse(JSON.parse(text)));},onProgress,onError);},parse:function parse(json){var textures=this.textures;function getTexture(name){if(textures[name]===undefined){console.warn('THREE.MaterialLoader: Undefined texture',name);}return textures[name];}var material=new Materials[json.type]();if(json.uuid!==undefined)material.uuid=json.uuid;if(json.name!==undefined)material.name=json.name;if(json.color!==undefined)material.color.setHex(json.color);if(json.roughness!==undefined)material.roughness=json.roughness;if(json.metalness!==undefined)material.metalness=json.metalness;if(json.sheen!==undefined)material.sheen=new Color().setHex(json.sheen);if(json.emissive!==undefined)material.emissive.setHex(json.emissive);if(json.specular!==undefined)material.specular.setHex(json.specular);if(json.shininess!==undefined)material.shininess=json.shininess;if(json.clearcoat!==undefined)material.clearcoat=json.clearcoat;if(json.clearcoatRoughness!==undefined)material.clearcoatRoughness=json.clearcoatRoughness;if(json.fog!==undefined)material.fog=json.fog;if(json.flatShading!==undefined)material.flatShading=json.flatShading;if(json.blending!==undefined)material.blending=json.blending;if(json.combine!==undefined)material.combine=json.combine;if(json.side!==undefined)material.side=json.side;if(json.opacity!==undefined)material.opacity=json.opacity;if(json.transparent!==undefined)material.transparent=json.transparent;if(json.alphaTest!==undefined)material.alphaTest=json.alphaTest;if(json.depthTest!==undefined)material.depthTest=json.depthTest;if(json.depthWrite!==undefined)material.depthWrite=json.depthWrite;if(json.colorWrite!==undefined)material.colorWrite=json.colorWrite;if(json.stencilWrite!==undefined)material.stencilWrite=json.stencilWrite;if(json.stencilWriteMask!==undefined)material.stencilWriteMask=json.stencilWriteMask;if(json.stencilFunc!==undefined)material.stencilFunc=json.stencilFunc;if(json.stencilRef!==undefined)material.stencilRef=json.stencilRef;if(json.stencilFuncMask!==undefined)material.stencilFuncMask=json.stencilFuncMask;if(json.stencilFail!==undefined)material.stencilFail=json.stencilFail;if(json.stencilZFail!==undefined)material.stencilZFail=json.stencilZFail;if(json.stencilZPass!==undefined)material.stencilZPass=json.stencilZPass;if(json.wireframe!==undefined)material.wireframe=json.wireframe;if(json.wireframeLinewidth!==undefined)material.wireframeLinewidth=json.wireframeLinewidth;if(json.wireframeLinecap!==undefined)material.wireframeLinecap=json.wireframeLinecap;if(json.wireframeLinejoin!==undefined)material.wireframeLinejoin=json.wireframeLinejoin;if(json.rotation!==undefined)material.rotation=json.rotation;if(json.linewidth!==1)material.linewidth=json.linewidth;if(json.dashSize!==undefined)material.dashSize=json.dashSize;if(json.gapSize!==undefined)material.gapSize=json.gapSize;if(json.scale!==undefined)material.scale=json.scale;if(json.polygonOffset!==undefined)material.polygonOffset=json.polygonOffset;if(json.polygonOffsetFactor!==undefined)material.polygonOffsetFactor=json.polygonOffsetFactor;if(json.polygonOffsetUnits!==undefined)material.polygonOffsetUnits=json.polygonOffsetUnits;if(json.skinning!==undefined)material.skinning=json.skinning;if(json.morphTargets!==undefined)material.morphTargets=json.morphTargets;if(json.morphNormals!==undefined)material.morphNormals=json.morphNormals;if(json.dithering!==undefined)material.dithering=json.dithering;if(json.vertexTangents!==undefined)material.vertexTangents=json.vertexTangents;if(json.visible!==undefined)material.visible=json.visible;if(json.toneMapped!==undefined)material.toneMapped=json.toneMapped;if(json.userData!==undefined)material.userData=json.userData;if(json.vertexColors!==undefined){if(typeof json.vertexColors==='number'){material.vertexColors=json.vertexColors>0?true:false;}else {material.vertexColors=json.vertexColors;}}// Shader Material
|
3071 | if(json.uniforms!==undefined){for(var name in json.uniforms){var uniform=json.uniforms[name];material.uniforms[name]={};switch(uniform.type){case't':material.uniforms[name].value=getTexture(uniform.value);break;case'c':material.uniforms[name].value=new Color().setHex(uniform.value);break;case'v2':material.uniforms[name].value=new Vector2().fromArray(uniform.value);break;case'v3':material.uniforms[name].value=new Vector3().fromArray(uniform.value);break;case'v4':material.uniforms[name].value=new Vector4().fromArray(uniform.value);break;case'm3':material.uniforms[name].value=new Matrix3().fromArray(uniform.value);case'm4':material.uniforms[name].value=new Matrix4().fromArray(uniform.value);break;default:material.uniforms[name].value=uniform.value;}}}if(json.defines!==undefined)material.defines=json.defines;if(json.vertexShader!==undefined)material.vertexShader=json.vertexShader;if(json.fragmentShader!==undefined)material.fragmentShader=json.fragmentShader;if(json.extensions!==undefined){for(var key in json.extensions){material.extensions[key]=json.extensions[key];}}// Deprecated
|
3072 | if(json.shading!==undefined)material.flatShading=json.shading===1;// THREE.FlatShading
|
3073 | // for PointsMaterial
|
3074 | if(json.size!==undefined)material.size=json.size;if(json.sizeAttenuation!==undefined)material.sizeAttenuation=json.sizeAttenuation;// maps
|
3075 | if(json.map!==undefined)material.map=getTexture(json.map);if(json.matcap!==undefined)material.matcap=getTexture(json.matcap);if(json.alphaMap!==undefined)material.alphaMap=getTexture(json.alphaMap);if(json.bumpMap!==undefined)material.bumpMap=getTexture(json.bumpMap);if(json.bumpScale!==undefined)material.bumpScale=json.bumpScale;if(json.normalMap!==undefined)material.normalMap=getTexture(json.normalMap);if(json.normalMapType!==undefined)material.normalMapType=json.normalMapType;if(json.normalScale!==undefined){var normalScale=json.normalScale;if(Array.isArray(normalScale)===false){// Blender exporter used to export a scalar. See #7459
|
3076 | normalScale=[normalScale,normalScale];}material.normalScale=new Vector2().fromArray(normalScale);}if(json.displacementMap!==undefined)material.displacementMap=getTexture(json.displacementMap);if(json.displacementScale!==undefined)material.displacementScale=json.displacementScale;if(json.displacementBias!==undefined)material.displacementBias=json.displacementBias;if(json.roughnessMap!==undefined)material.roughnessMap=getTexture(json.roughnessMap);if(json.metalnessMap!==undefined)material.metalnessMap=getTexture(json.metalnessMap);if(json.emissiveMap!==undefined)material.emissiveMap=getTexture(json.emissiveMap);if(json.emissiveIntensity!==undefined)material.emissiveIntensity=json.emissiveIntensity;if(json.specularMap!==undefined)material.specularMap=getTexture(json.specularMap);if(json.envMap!==undefined)material.envMap=getTexture(json.envMap);if(json.envMapIntensity!==undefined)material.envMapIntensity=json.envMapIntensity;if(json.reflectivity!==undefined)material.reflectivity=json.reflectivity;if(json.refractionRatio!==undefined)material.refractionRatio=json.refractionRatio;if(json.lightMap!==undefined)material.lightMap=getTexture(json.lightMap);if(json.lightMapIntensity!==undefined)material.lightMapIntensity=json.lightMapIntensity;if(json.aoMap!==undefined)material.aoMap=getTexture(json.aoMap);if(json.aoMapIntensity!==undefined)material.aoMapIntensity=json.aoMapIntensity;if(json.gradientMap!==undefined)material.gradientMap=getTexture(json.gradientMap);if(json.clearcoatMap!==undefined)material.clearcoatMap=getTexture(json.clearcoatMap);if(json.clearcoatRoughnessMap!==undefined)material.clearcoatRoughnessMap=getTexture(json.clearcoatRoughnessMap);if(json.clearcoatNormalMap!==undefined)material.clearcoatNormalMap=getTexture(json.clearcoatNormalMap);if(json.clearcoatNormalScale!==undefined)material.clearcoatNormalScale=new Vector2().fromArray(json.clearcoatNormalScale);return material;},setTextures:function setTextures(value){this.textures=value;return this;}});/**
|
3077 | * @author Don McCurdy / https://www.donmccurdy.com
|
3078 | */var LoaderUtils={decodeText:function decodeText(array){if(typeof TextDecoder!=='undefined'){return new TextDecoder().decode(array);}// Avoid the String.fromCharCode.apply(null, array) shortcut, which
|
3079 | // throws a "maximum call stack size exceeded" error for large arrays.
|
3080 | var s='';for(var i=0,il=array.length;i<il;i++){// Implicitly assumes little-endian.
|
3081 | s+=String.fromCharCode(array[i]);}try{// merges multi-byte utf-8 characters.
|
3082 | return decodeURIComponent(escape(s));}catch(e){// see #16358
|
3083 | return s;}},extractUrlBase:function extractUrlBase(url){var index=url.lastIndexOf('/');if(index===-1)return './';return url.substr(0,index+1);}};/**
|
3084 | * @author benaadams / https://twitter.com/ben_a_adams
|
3085 | */function InstancedBufferGeometry(){BufferGeometry.call(this);this.type='InstancedBufferGeometry';this.maxInstancedCount=undefined;}InstancedBufferGeometry.prototype=_extends(Object.create(BufferGeometry.prototype),{constructor:InstancedBufferGeometry,isInstancedBufferGeometry:true,copy:function copy(source){BufferGeometry.prototype.copy.call(this,source);this.maxInstancedCount=source.maxInstancedCount;return this;},clone:function clone(){return new this.constructor().copy(this);},toJSON:function toJSON(){var data=BufferGeometry.prototype.toJSON.call(this);data.maxInstancedCount=this.maxInstancedCount;data.isInstancedBufferGeometry=true;return data;}});/**
|
3086 | * @author benaadams / https://twitter.com/ben_a_adams
|
3087 | */function InstancedBufferAttribute(array,itemSize,normalized,meshPerAttribute){if(typeof normalized==='number'){meshPerAttribute=normalized;normalized=false;console.error('THREE.InstancedBufferAttribute: The constructor now expects normalized as the third argument.');}BufferAttribute.call(this,array,itemSize,normalized);this.meshPerAttribute=meshPerAttribute||1;}InstancedBufferAttribute.prototype=_extends(Object.create(BufferAttribute.prototype),{constructor:InstancedBufferAttribute,isInstancedBufferAttribute:true,copy:function copy(source){BufferAttribute.prototype.copy.call(this,source);this.meshPerAttribute=source.meshPerAttribute;return this;},toJSON:function toJSON(){var data=BufferAttribute.prototype.toJSON.call(this);data.meshPerAttribute=this.meshPerAttribute;data.isInstancedBufferAttribute=true;return data;}});/**
|
3088 | * @author mrdoob / http://mrdoob.com/
|
3089 | */function BufferGeometryLoader(manager){Loader.call(this,manager);}BufferGeometryLoader.prototype=_extends(Object.create(Loader.prototype),{constructor:BufferGeometryLoader,load:function load(url,onLoad,onProgress,onError){var scope=this;var loader=new FileLoader(scope.manager);loader.setPath(scope.path);loader.load(url,function(text){onLoad(scope.parse(JSON.parse(text)));},onProgress,onError);},parse:function parse(json){var geometry=json.isInstancedBufferGeometry?new InstancedBufferGeometry():new BufferGeometry();var index=json.data.index;if(index!==undefined){var typedArray=new TYPED_ARRAYS[index.type](index.array);geometry.setIndex(new BufferAttribute(typedArray,1));}var attributes=json.data.attributes;for(var key in attributes){var attribute=attributes[key];var typedArray=new TYPED_ARRAYS[attribute.type](attribute.array);var bufferAttributeConstr=attribute.isInstancedBufferAttribute?InstancedBufferAttribute:BufferAttribute;var bufferAttribute=new bufferAttributeConstr(typedArray,attribute.itemSize,attribute.normalized);if(attribute.name!==undefined)bufferAttribute.name=attribute.name;geometry.setAttribute(key,bufferAttribute);}var morphAttributes=json.data.morphAttributes;if(morphAttributes){for(var key in morphAttributes){var attributeArray=morphAttributes[key];var array=[];for(var i=0,il=attributeArray.length;i<il;i++){var attribute=attributeArray[i];var typedArray=new TYPED_ARRAYS[attribute.type](attribute.array);var bufferAttribute=new BufferAttribute(typedArray,attribute.itemSize,attribute.normalized);if(attribute.name!==undefined)bufferAttribute.name=attribute.name;array.push(bufferAttribute);}geometry.morphAttributes[key]=array;}}var morphTargetsRelative=json.data.morphTargetsRelative;if(morphTargetsRelative){geometry.morphTargetsRelative=true;}var groups=json.data.groups||json.data.drawcalls||json.data.offsets;if(groups!==undefined){for(var i=0,n=groups.length;i!==n;++i){var group=groups[i];geometry.addGroup(group.start,group.count,group.materialIndex);}}var boundingSphere=json.data.boundingSphere;if(boundingSphere!==undefined){var center=new Vector3();if(boundingSphere.center!==undefined){center.fromArray(boundingSphere.center);}geometry.boundingSphere=new Sphere(center,boundingSphere.radius);}if(json.name)geometry.name=json.name;if(json.userData)geometry.userData=json.userData;return geometry;}});var TYPED_ARRAYS={Int8Array:Int8Array,Uint8Array:Uint8Array,// Workaround for IE11 pre KB2929437. See #11440
|
3090 | Uint8ClampedArray:typeof Uint8ClampedArray!=='undefined'?Uint8ClampedArray:Uint8Array,Int16Array:Int16Array,Uint16Array:Uint16Array,Int32Array:Int32Array,Uint32Array:Uint32Array,Float32Array:Float32Array,Float64Array:Float64Array};/**
|
3091 | * @author mrdoob / http://mrdoob.com/
|
3092 | */function ObjectLoader(manager){Loader.call(this,manager);}ObjectLoader.prototype=_extends(Object.create(Loader.prototype),{constructor:ObjectLoader,load:function load(url,onLoad,onProgress,onError){var scope=this;var path=this.path===''?LoaderUtils.extractUrlBase(url):this.path;this.resourcePath=this.resourcePath||path;var loader=new FileLoader(scope.manager);loader.setPath(this.path);loader.load(url,function(text){var json=null;try{json=JSON.parse(text);}catch(error){if(onError!==undefined)onError(error);console.error('THREE:ObjectLoader: Can\'t parse '+url+'.',error.message);return;}var metadata=json.metadata;if(metadata===undefined||metadata.type===undefined||metadata.type.toLowerCase()==='geometry'){console.error('THREE.ObjectLoader: Can\'t load '+url);return;}scope.parse(json,onLoad);},onProgress,onError);},parse:function parse(json,onLoad){var shapes=this.parseShape(json.shapes);var geometries=this.parseGeometries(json.geometries,shapes);var images=this.parseImages(json.images,function(){if(onLoad!==undefined)onLoad(object);});var textures=this.parseTextures(json.textures,images);var materials=this.parseMaterials(json.materials,textures);var object=this.parseObject(json.object,geometries,materials);if(json.animations){object.animations=this.parseAnimations(json.animations);}if(json.images===undefined||json.images.length===0){if(onLoad!==undefined)onLoad(object);}return object;},parseShape:function parseShape(json){var shapes={};if(json!==undefined){for(var i=0,l=json.length;i<l;i++){var shape=new Shape().fromJSON(json[i]);shapes[shape.uuid]=shape;}}return shapes;},parseGeometries:function parseGeometries(json,shapes){var geometries={};if(json!==undefined){var bufferGeometryLoader=new BufferGeometryLoader();for(var i=0,l=json.length;i<l;i++){var geometry;var data=json[i];switch(data.type){case'PlaneGeometry':case'PlaneBufferGeometry':geometry=new Geometries[data.type](data.width,data.height,data.widthSegments,data.heightSegments);break;case'BoxGeometry':case'BoxBufferGeometry':case'CubeGeometry':// backwards compatible
|
3093 | geometry=new Geometries[data.type](data.width,data.height,data.depth,data.widthSegments,data.heightSegments,data.depthSegments);break;case'CircleGeometry':case'CircleBufferGeometry':geometry=new Geometries[data.type](data.radius,data.segments,data.thetaStart,data.thetaLength);break;case'CylinderGeometry':case'CylinderBufferGeometry':geometry=new Geometries[data.type](data.radiusTop,data.radiusBottom,data.height,data.radialSegments,data.heightSegments,data.openEnded,data.thetaStart,data.thetaLength);break;case'ConeGeometry':case'ConeBufferGeometry':geometry=new Geometries[data.type](data.radius,data.height,data.radialSegments,data.heightSegments,data.openEnded,data.thetaStart,data.thetaLength);break;case'SphereGeometry':case'SphereBufferGeometry':geometry=new Geometries[data.type](data.radius,data.widthSegments,data.heightSegments,data.phiStart,data.phiLength,data.thetaStart,data.thetaLength);break;case'DodecahedronGeometry':case'DodecahedronBufferGeometry':case'IcosahedronGeometry':case'IcosahedronBufferGeometry':case'OctahedronGeometry':case'OctahedronBufferGeometry':case'TetrahedronGeometry':case'TetrahedronBufferGeometry':geometry=new Geometries[data.type](data.radius,data.detail);break;case'RingGeometry':case'RingBufferGeometry':geometry=new Geometries[data.type](data.innerRadius,data.outerRadius,data.thetaSegments,data.phiSegments,data.thetaStart,data.thetaLength);break;case'TorusGeometry':case'TorusBufferGeometry':geometry=new Geometries[data.type](data.radius,data.tube,data.radialSegments,data.tubularSegments,data.arc);break;case'TorusKnotGeometry':case'TorusKnotBufferGeometry':geometry=new Geometries[data.type](data.radius,data.tube,data.tubularSegments,data.radialSegments,data.p,data.q);break;case'TubeGeometry':case'TubeBufferGeometry':// This only works for built-in curves (e.g. CatmullRomCurve3).
|
3094 | // User defined curves or instances of CurvePath will not be deserialized.
|
3095 | geometry=new Geometries[data.type](new Curves[data.path.type]().fromJSON(data.path),data.tubularSegments,data.radius,data.radialSegments,data.closed);break;case'LatheGeometry':case'LatheBufferGeometry':geometry=new Geometries[data.type](data.points,data.segments,data.phiStart,data.phiLength);break;case'PolyhedronGeometry':case'PolyhedronBufferGeometry':geometry=new Geometries[data.type](data.vertices,data.indices,data.radius,data.details);break;case'ShapeGeometry':case'ShapeBufferGeometry':var geometryShapes=[];for(var j=0,jl=data.shapes.length;j<jl;j++){var shape=shapes[data.shapes[j]];geometryShapes.push(shape);}geometry=new Geometries[data.type](geometryShapes,data.curveSegments);break;case'ExtrudeGeometry':case'ExtrudeBufferGeometry':var geometryShapes=[];for(var j=0,jl=data.shapes.length;j<jl;j++){var shape=shapes[data.shapes[j]];geometryShapes.push(shape);}var extrudePath=data.options.extrudePath;if(extrudePath!==undefined){data.options.extrudePath=new Curves[extrudePath.type]().fromJSON(extrudePath);}geometry=new Geometries[data.type](geometryShapes,data.options);break;case'BufferGeometry':case'InstancedBufferGeometry':geometry=bufferGeometryLoader.parse(data);break;case'Geometry':console.error('THREE.ObjectLoader: Loading "Geometry" is not supported anymore.');break;default:console.warn('THREE.ObjectLoader: Unsupported geometry type "'+data.type+'"');continue;}geometry.uuid=data.uuid;if(data.name!==undefined)geometry.name=data.name;if(geometry.isBufferGeometry===true&&data.userData!==undefined)geometry.userData=data.userData;geometries[data.uuid]=geometry;}}return geometries;},parseMaterials:function parseMaterials(json,textures){var cache={};// MultiMaterial
|
3096 | var materials={};if(json!==undefined){var loader=new MaterialLoader();loader.setTextures(textures);for(var i=0,l=json.length;i<l;i++){var data=json[i];if(data.type==='MultiMaterial'){// Deprecated
|
3097 | var array=[];for(var j=0;j<data.materials.length;j++){var material=data.materials[j];if(cache[material.uuid]===undefined){cache[material.uuid]=loader.parse(material);}array.push(cache[material.uuid]);}materials[data.uuid]=array;}else {if(cache[data.uuid]===undefined){cache[data.uuid]=loader.parse(data);}materials[data.uuid]=cache[data.uuid];}}}return materials;},parseAnimations:function parseAnimations(json){var animations=[];for(var i=0;i<json.length;i++){var data=json[i];var clip=AnimationClip.parse(data);if(data.uuid!==undefined)clip.uuid=data.uuid;animations.push(clip);}return animations;},parseImages:function parseImages(json,onLoad){var scope=this;var images={};function loadImage(url){scope.manager.itemStart(url);return loader.load(url,function(){scope.manager.itemEnd(url);},undefined,function(){scope.manager.itemError(url);scope.manager.itemEnd(url);});}if(json!==undefined&&json.length>0){var manager=new LoadingManager(onLoad);var loader=new ImageLoader(manager);loader.setCrossOrigin(this.crossOrigin);for(var i=0,il=json.length;i<il;i++){var image=json[i];var url=image.url;if(Array.isArray(url)){// load array of images e.g CubeTexture
|
3098 | images[image.uuid]=[];for(var j=0,jl=url.length;j<jl;j++){var currentUrl=url[j];var path=/^(\/\/)|([a-z]+:(\/\/)?)/i.test(currentUrl)?currentUrl:scope.resourcePath+currentUrl;images[image.uuid].push(loadImage(path));}}else {// load single image
|
3099 | var path=/^(\/\/)|([a-z]+:(\/\/)?)/i.test(image.url)?image.url:scope.resourcePath+image.url;images[image.uuid]=loadImage(path);}}}return images;},parseTextures:function parseTextures(json,images){function parseConstant(value,type){if(typeof value==='number')return value;console.warn('THREE.ObjectLoader.parseTexture: Constant should be in numeric form.',value);return type[value];}var textures={};if(json!==undefined){for(var i=0,l=json.length;i<l;i++){var data=json[i];if(data.image===undefined){console.warn('THREE.ObjectLoader: No "image" specified for',data.uuid);}if(images[data.image]===undefined){console.warn('THREE.ObjectLoader: Undefined image',data.image);}var texture;if(Array.isArray(images[data.image])){texture=new CubeTexture(images[data.image]);}else {texture=new Texture(images[data.image]);}texture.needsUpdate=true;texture.uuid=data.uuid;if(data.name!==undefined)texture.name=data.name;if(data.mapping!==undefined)texture.mapping=parseConstant(data.mapping,TEXTURE_MAPPING);if(data.offset!==undefined)texture.offset.fromArray(data.offset);if(data.repeat!==undefined)texture.repeat.fromArray(data.repeat);if(data.center!==undefined)texture.center.fromArray(data.center);if(data.rotation!==undefined)texture.rotation=data.rotation;if(data.wrap!==undefined){texture.wrapS=parseConstant(data.wrap[0],TEXTURE_WRAPPING);texture.wrapT=parseConstant(data.wrap[1],TEXTURE_WRAPPING);}if(data.format!==undefined)texture.format=data.format;if(data.type!==undefined)texture.type=data.type;if(data.encoding!==undefined)texture.encoding=data.encoding;if(data.minFilter!==undefined)texture.minFilter=parseConstant(data.minFilter,TEXTURE_FILTER);if(data.magFilter!==undefined)texture.magFilter=parseConstant(data.magFilter,TEXTURE_FILTER);if(data.anisotropy!==undefined)texture.anisotropy=data.anisotropy;if(data.flipY!==undefined)texture.flipY=data.flipY;if(data.premultiplyAlpha!==undefined)texture.premultiplyAlpha=data.premultiplyAlpha;if(data.unpackAlignment!==undefined)texture.unpackAlignment=data.unpackAlignment;textures[data.uuid]=texture;}}return textures;},parseObject:function parseObject(data,geometries,materials){var object;function getGeometry(name){if(geometries[name]===undefined){console.warn('THREE.ObjectLoader: Undefined geometry',name);}return geometries[name];}function getMaterial(name){if(name===undefined)return undefined;if(Array.isArray(name)){var array=[];for(var i=0,l=name.length;i<l;i++){var uuid=name[i];if(materials[uuid]===undefined){console.warn('THREE.ObjectLoader: Undefined material',uuid);}array.push(materials[uuid]);}return array;}if(materials[name]===undefined){console.warn('THREE.ObjectLoader: Undefined material',name);}return materials[name];}switch(data.type){case'Scene':object=new Scene();if(data.background!==undefined){if(Number.isInteger(data.background)){object.background=new Color(data.background);}}if(data.fog!==undefined){if(data.fog.type==='Fog'){object.fog=new Fog(data.fog.color,data.fog.near,data.fog.far);}else if(data.fog.type==='FogExp2'){object.fog=new FogExp2(data.fog.color,data.fog.density);}}break;case'PerspectiveCamera':object=new PerspectiveCamera(data.fov,data.aspect,data.near,data.far);if(data.focus!==undefined)object.focus=data.focus;if(data.zoom!==undefined)object.zoom=data.zoom;if(data.filmGauge!==undefined)object.filmGauge=data.filmGauge;if(data.filmOffset!==undefined)object.filmOffset=data.filmOffset;if(data.view!==undefined)object.view=_extends({},data.view);break;case'OrthographicCamera':object=new OrthographicCamera(data.left,data.right,data.top,data.bottom,data.near,data.far);if(data.zoom!==undefined)object.zoom=data.zoom;if(data.view!==undefined)object.view=_extends({},data.view);break;case'AmbientLight':object=new AmbientLight(data.color,data.intensity);break;case'DirectionalLight':object=new DirectionalLight(data.color,data.intensity);break;case'PointLight':object=new PointLight(data.color,data.intensity,data.distance,data.decay);break;case'RectAreaLight':object=new RectAreaLight(data.color,data.intensity,data.width,data.height);break;case'SpotLight':object=new SpotLight(data.color,data.intensity,data.distance,data.angle,data.penumbra,data.decay);break;case'HemisphereLight':object=new HemisphereLight(data.color,data.groundColor,data.intensity);break;case'LightProbe':object=new LightProbe().fromJSON(data);break;case'SkinnedMesh':console.warn('THREE.ObjectLoader.parseObject() does not support SkinnedMesh yet.');case'Mesh':var geometry=getGeometry(data.geometry);var material=getMaterial(data.material);object=new Mesh(geometry,material);break;case'InstancedMesh':var geometry=getGeometry(data.geometry);var material=getMaterial(data.material);var count=data.count;var instanceMatrix=data.instanceMatrix;object=new InstancedMesh(geometry,material,count);object.instanceMatrix=new BufferAttribute(new Float32Array(instanceMatrix.array),16);break;case'LOD':object=new LOD();break;case'Line':object=new Line(getGeometry(data.geometry),getMaterial(data.material),data.mode);break;case'LineLoop':object=new LineLoop(getGeometry(data.geometry),getMaterial(data.material));break;case'LineSegments':object=new LineSegments(getGeometry(data.geometry),getMaterial(data.material));break;case'PointCloud':case'Points':object=new Points(getGeometry(data.geometry),getMaterial(data.material));break;case'Sprite':object=new Sprite(getMaterial(data.material));break;case'Group':object=new Group();break;default:object=new Object3D();}object.uuid=data.uuid;if(data.name!==undefined)object.name=data.name;if(data.matrix!==undefined){object.matrix.fromArray(data.matrix);if(data.matrixAutoUpdate!==undefined)object.matrixAutoUpdate=data.matrixAutoUpdate;if(object.matrixAutoUpdate)object.matrix.decompose(object.position,object.quaternion,object.scale);}else {if(data.position!==undefined)object.position.fromArray(data.position);if(data.rotation!==undefined)object.rotation.fromArray(data.rotation);if(data.quaternion!==undefined)object.quaternion.fromArray(data.quaternion);if(data.scale!==undefined)object.scale.fromArray(data.scale);}if(data.castShadow!==undefined)object.castShadow=data.castShadow;if(data.receiveShadow!==undefined)object.receiveShadow=data.receiveShadow;if(data.shadow){if(data.shadow.bias!==undefined)object.shadow.bias=data.shadow.bias;if(data.shadow.radius!==undefined)object.shadow.radius=data.shadow.radius;if(data.shadow.mapSize!==undefined)object.shadow.mapSize.fromArray(data.shadow.mapSize);if(data.shadow.camera!==undefined)object.shadow.camera=this.parseObject(data.shadow.camera);}if(data.visible!==undefined)object.visible=data.visible;if(data.frustumCulled!==undefined)object.frustumCulled=data.frustumCulled;if(data.renderOrder!==undefined)object.renderOrder=data.renderOrder;if(data.userData!==undefined)object.userData=data.userData;if(data.layers!==undefined)object.layers.mask=data.layers;if(data.children!==undefined){var children=data.children;for(var i=0;i<children.length;i++){object.add(this.parseObject(children[i],geometries,materials));}}if(data.type==='LOD'){if(data.autoUpdate!==undefined)object.autoUpdate=data.autoUpdate;var levels=data.levels;for(var l=0;l<levels.length;l++){var level=levels[l];var child=object.getObjectByProperty('uuid',level.object);if(child!==undefined){object.addLevel(child,level.distance);}}}return object;}});var TEXTURE_MAPPING={UVMapping:UVMapping,CubeReflectionMapping:CubeReflectionMapping,CubeRefractionMapping:CubeRefractionMapping,EquirectangularReflectionMapping:EquirectangularReflectionMapping,EquirectangularRefractionMapping:EquirectangularRefractionMapping,SphericalReflectionMapping:SphericalReflectionMapping,CubeUVReflectionMapping:CubeUVReflectionMapping,CubeUVRefractionMapping:CubeUVRefractionMapping};var TEXTURE_WRAPPING={RepeatWrapping:RepeatWrapping,ClampToEdgeWrapping:ClampToEdgeWrapping,MirroredRepeatWrapping:MirroredRepeatWrapping};var TEXTURE_FILTER={NearestFilter:NearestFilter,NearestMipmapNearestFilter:NearestMipmapNearestFilter,NearestMipmapLinearFilter:NearestMipmapLinearFilter,LinearFilter:LinearFilter,LinearMipmapNearestFilter:LinearMipmapNearestFilter,LinearMipmapLinearFilter:LinearMipmapLinearFilter};/**
|
3100 | * @author thespite / http://clicktorelease.com/
|
3101 | */function ImageBitmapLoader(manager){if(typeof createImageBitmap==='undefined'){console.warn('THREE.ImageBitmapLoader: createImageBitmap() not supported.');}if(typeof fetch==='undefined'){console.warn('THREE.ImageBitmapLoader: fetch() not supported.');}Loader.call(this,manager);this.options=undefined;}ImageBitmapLoader.prototype=_extends(Object.create(Loader.prototype),{constructor:ImageBitmapLoader,setOptions:function setOptions(options){this.options=options;return this;},load:function load(url,onLoad,onProgress,onError){if(url===undefined)url='';if(this.path!==undefined)url=this.path+url;url=this.manager.resolveURL(url);var scope=this;var cached=Cache.get(url);if(cached!==undefined){scope.manager.itemStart(url);setTimeout(function(){if(onLoad)onLoad(cached);scope.manager.itemEnd(url);},0);return cached;}fetch(url).then(function(res){return res.blob();}).then(function(blob){if(scope.options===undefined){// Workaround for FireFox. It causes an error if you pass options.
|
3102 | return createImageBitmap(blob);}else {return createImageBitmap(blob,scope.options);}}).then(function(imageBitmap){Cache.add(url,imageBitmap);if(onLoad)onLoad(imageBitmap);scope.manager.itemEnd(url);})["catch"](function(e){if(onError)onError(e);scope.manager.itemError(url);scope.manager.itemEnd(url);});scope.manager.itemStart(url);}});/**
|
3103 | * @author zz85 / http://www.lab4games.net/zz85/blog
|
3104 | * minimal class for proxing functions to Path. Replaces old "extractSubpaths()"
|
3105 | **/function ShapePath(){this.type='ShapePath';this.color=new Color();this.subPaths=[];this.currentPath=null;}_extends(ShapePath.prototype,{moveTo:function moveTo(x,y){this.currentPath=new Path();this.subPaths.push(this.currentPath);this.currentPath.moveTo(x,y);return this;},lineTo:function lineTo(x,y){this.currentPath.lineTo(x,y);return this;},quadraticCurveTo:function quadraticCurveTo(aCPx,aCPy,aX,aY){this.currentPath.quadraticCurveTo(aCPx,aCPy,aX,aY);return this;},bezierCurveTo:function bezierCurveTo(aCP1x,aCP1y,aCP2x,aCP2y,aX,aY){this.currentPath.bezierCurveTo(aCP1x,aCP1y,aCP2x,aCP2y,aX,aY);return this;},splineThru:function splineThru(pts){this.currentPath.splineThru(pts);return this;},toShapes:function toShapes(isCCW,noHoles){function toShapesNoHoles(inSubpaths){var shapes=[];for(var i=0,l=inSubpaths.length;i<l;i++){var tmpPath=inSubpaths[i];var tmpShape=new Shape();tmpShape.curves=tmpPath.curves;shapes.push(tmpShape);}return shapes;}function isPointInsidePolygon(inPt,inPolygon){var polyLen=inPolygon.length;// inPt on polygon contour => immediate success or
|
3106 | // toggling of inside/outside at every single! intersection point of an edge
|
3107 | // with the horizontal line through inPt, left of inPt
|
3108 | // not counting lowerY endpoints of edges and whole edges on that line
|
3109 | var inside=false;for(var p=polyLen-1,q=0;q<polyLen;p=q++){var edgeLowPt=inPolygon[p];var edgeHighPt=inPolygon[q];var edgeDx=edgeHighPt.x-edgeLowPt.x;var edgeDy=edgeHighPt.y-edgeLowPt.y;if(Math.abs(edgeDy)>Number.EPSILON){// not parallel
|
3110 | if(edgeDy<0){edgeLowPt=inPolygon[q];edgeDx=-edgeDx;edgeHighPt=inPolygon[p];edgeDy=-edgeDy;}if(inPt.y<edgeLowPt.y||inPt.y>edgeHighPt.y)continue;if(inPt.y===edgeLowPt.y){if(inPt.x===edgeLowPt.x)return true;// inPt is on contour ?
|
3111 | // continue; // no intersection or edgeLowPt => doesn't count !!!
|
3112 | }else {var perpEdge=edgeDy*(inPt.x-edgeLowPt.x)-edgeDx*(inPt.y-edgeLowPt.y);if(perpEdge===0)return true;// inPt is on contour ?
|
3113 | if(perpEdge<0)continue;inside=!inside;// true intersection left of inPt
|
3114 | }}else {// parallel or collinear
|
3115 | if(inPt.y!==edgeLowPt.y)continue;// parallel
|
3116 | // edge lies on the same horizontal line as inPt
|
3117 | if(edgeHighPt.x<=inPt.x&&inPt.x<=edgeLowPt.x||edgeLowPt.x<=inPt.x&&inPt.x<=edgeHighPt.x)return true;// inPt: Point on contour !
|
3118 | // continue;
|
3119 | }}return inside;}var isClockWise=ShapeUtils.isClockWise;var subPaths=this.subPaths;if(subPaths.length===0)return [];if(noHoles===true)return toShapesNoHoles(subPaths);var solid,tmpPath,tmpShape,shapes=[];if(subPaths.length===1){tmpPath=subPaths[0];tmpShape=new Shape();tmpShape.curves=tmpPath.curves;shapes.push(tmpShape);return shapes;}var holesFirst=!isClockWise(subPaths[0].getPoints());holesFirst=isCCW?!holesFirst:holesFirst;// console.log("Holes first", holesFirst);
|
3120 | var betterShapeHoles=[];var newShapes=[];var newShapeHoles=[];var mainIdx=0;var tmpPoints;newShapes[mainIdx]=undefined;newShapeHoles[mainIdx]=[];for(var i=0,l=subPaths.length;i<l;i++){tmpPath=subPaths[i];tmpPoints=tmpPath.getPoints();solid=isClockWise(tmpPoints);solid=isCCW?!solid:solid;if(solid){if(!holesFirst&&newShapes[mainIdx])mainIdx++;newShapes[mainIdx]={s:new Shape(),p:tmpPoints};newShapes[mainIdx].s.curves=tmpPath.curves;if(holesFirst)mainIdx++;newShapeHoles[mainIdx]=[];//console.log('cw', i);
|
3121 | }else {newShapeHoles[mainIdx].push({h:tmpPath,p:tmpPoints[0]});//console.log('ccw', i);
|
3122 | }}// only Holes? -> probably all Shapes with wrong orientation
|
3123 | if(!newShapes[0])return toShapesNoHoles(subPaths);if(newShapes.length>1){var ambiguous=false;var toChange=[];for(var sIdx=0,sLen=newShapes.length;sIdx<sLen;sIdx++){betterShapeHoles[sIdx]=[];}for(var sIdx=0,sLen=newShapes.length;sIdx<sLen;sIdx++){var sho=newShapeHoles[sIdx];for(var hIdx=0;hIdx<sho.length;hIdx++){var ho=sho[hIdx];var hole_unassigned=true;for(var s2Idx=0;s2Idx<newShapes.length;s2Idx++){if(isPointInsidePolygon(ho.p,newShapes[s2Idx].p)){if(sIdx!==s2Idx)toChange.push({froms:sIdx,tos:s2Idx,hole:hIdx});if(hole_unassigned){hole_unassigned=false;betterShapeHoles[s2Idx].push(ho);}else {ambiguous=true;}}}if(hole_unassigned){betterShapeHoles[sIdx].push(ho);}}}// console.log("ambiguous: ", ambiguous);
|
3124 | if(toChange.length>0){// console.log("to change: ", toChange);
|
3125 | if(!ambiguous)newShapeHoles=betterShapeHoles;}}var tmpHoles;for(var i=0,il=newShapes.length;i<il;i++){tmpShape=newShapes[i].s;shapes.push(tmpShape);tmpHoles=newShapeHoles[i];for(var j=0,jl=tmpHoles.length;j<jl;j++){tmpShape.holes.push(tmpHoles[j].h);}}//console.log("shape", shapes);
|
3126 | return shapes;}});/**
|
3127 | * @author zz85 / http://www.lab4games.net/zz85/blog
|
3128 | * @author mrdoob / http://mrdoob.com/
|
3129 | */function Font(data){this.type='Font';this.data=data;}_extends(Font.prototype,{isFont:true,generateShapes:function generateShapes(text,size){if(size===undefined)size=100;var shapes=[];var paths=createPaths(text,size,this.data);for(var p=0,pl=paths.length;p<pl;p++){Array.prototype.push.apply(shapes,paths[p].toShapes());}return shapes;}});function createPaths(text,size,data){var chars=Array.from?Array.from(text):String(text).split('');// workaround for IE11, see #13988
|
3130 | var scale=size/data.resolution;var line_height=(data.boundingBox.yMax-data.boundingBox.yMin+data.underlineThickness)*scale;var paths=[];var offsetX=0,offsetY=0;for(var i=0;i<chars.length;i++){var _char=chars[i];if(_char==='\n'){offsetX=0;offsetY-=line_height;}else {var ret=createPath(_char,scale,offsetX,offsetY,data);offsetX+=ret.offsetX;paths.push(ret.path);}}return paths;}function createPath(_char2,scale,offsetX,offsetY,data){var glyph=data.glyphs[_char2]||data.glyphs['?'];if(!glyph){console.error('THREE.Font: character "'+_char2+'" does not exists in font family '+data.familyName+'.');return;}var path=new ShapePath();var x,y,cpx,cpy,cpx1,cpy1,cpx2,cpy2;if(glyph.o){var outline=glyph._cachedOutline||(glyph._cachedOutline=glyph.o.split(' '));for(var i=0,l=outline.length;i<l;){var action=outline[i++];switch(action){case'm':// moveTo
|
3131 | x=outline[i++]*scale+offsetX;y=outline[i++]*scale+offsetY;path.moveTo(x,y);break;case'l':// lineTo
|
3132 | x=outline[i++]*scale+offsetX;y=outline[i++]*scale+offsetY;path.lineTo(x,y);break;case'q':// quadraticCurveTo
|
3133 | cpx=outline[i++]*scale+offsetX;cpy=outline[i++]*scale+offsetY;cpx1=outline[i++]*scale+offsetX;cpy1=outline[i++]*scale+offsetY;path.quadraticCurveTo(cpx1,cpy1,cpx,cpy);break;case'b':// bezierCurveTo
|
3134 | cpx=outline[i++]*scale+offsetX;cpy=outline[i++]*scale+offsetY;cpx1=outline[i++]*scale+offsetX;cpy1=outline[i++]*scale+offsetY;cpx2=outline[i++]*scale+offsetX;cpy2=outline[i++]*scale+offsetY;path.bezierCurveTo(cpx1,cpy1,cpx2,cpy2,cpx,cpy);break;}}}return {offsetX:glyph.ha*scale,path:path};}/**
|
3135 | * @author mrdoob / http://mrdoob.com/
|
3136 | */function FontLoader(manager){Loader.call(this,manager);}FontLoader.prototype=_extends(Object.create(Loader.prototype),{constructor:FontLoader,load:function load(url,onLoad,onProgress,onError){var scope=this;var loader=new FileLoader(this.manager);loader.setPath(this.path);loader.load(url,function(text){var json;try{json=JSON.parse(text);}catch(e){console.warn('THREE.FontLoader: typeface.js support is being deprecated. Use typeface.json instead.');json=JSON.parse(text.substring(65,text.length-2));}var font=scope.parse(json);if(onLoad)onLoad(font);},onProgress,onError);},parse:function parse(json){return new Font(json);}});/**
|
3137 | * @author mrdoob / http://mrdoob.com/
|
3138 | */var _context;var AudioContext={getContext:function getContext(){if(_context===undefined){_context=new(window.AudioContext||window.webkitAudioContext)();}return _context;},setContext:function setContext(value){_context=value;}};/**
|
3139 | * @author Reece Aaron Lecrivain / http://reecenotes.com/
|
3140 | */function AudioLoader(manager){Loader.call(this,manager);}AudioLoader.prototype=_extends(Object.create(Loader.prototype),{constructor:AudioLoader,load:function load(url,onLoad,onProgress,onError){var loader=new FileLoader(this.manager);loader.setResponseType('arraybuffer');loader.setPath(this.path);loader.load(url,function(buffer){// Create a copy of the buffer. The `decodeAudioData` method
|
3141 | // detaches the buffer when complete, preventing reuse.
|
3142 | var bufferCopy=buffer.slice(0);var context=AudioContext.getContext();context.decodeAudioData(bufferCopy,function(audioBuffer){onLoad(audioBuffer);});},onProgress,onError);}});/**
|
3143 | * @author WestLangley / http://github.com/WestLangley
|
3144 | */function HemisphereLightProbe(skyColor,groundColor,intensity){LightProbe.call(this,undefined,intensity);var color1=new Color().set(skyColor);var color2=new Color().set(groundColor);var sky=new Vector3(color1.r,color1.g,color1.b);var ground=new Vector3(color2.r,color2.g,color2.b);// without extra factor of PI in the shader, should = 1 / Math.sqrt( Math.PI );
|
3145 | var c0=Math.sqrt(Math.PI);var c1=c0*Math.sqrt(0.75);this.sh.coefficients[0].copy(sky).add(ground).multiplyScalar(c0);this.sh.coefficients[1].copy(sky).sub(ground).multiplyScalar(c1);}HemisphereLightProbe.prototype=_extends(Object.create(LightProbe.prototype),{constructor:HemisphereLightProbe,isHemisphereLightProbe:true,copy:function copy(source){// modifying colors not currently supported
|
3146 | LightProbe.prototype.copy.call(this,source);return this;},toJSON:function toJSON(meta){var data=LightProbe.prototype.toJSON.call(this,meta);// data.sh = this.sh.toArray(); // todo
|
3147 | return data;}});/**
|
3148 | * @author WestLangley / http://github.com/WestLangley
|
3149 | */function AmbientLightProbe(color,intensity){LightProbe.call(this,undefined,intensity);var color1=new Color().set(color);// without extra factor of PI in the shader, would be 2 / Math.sqrt( Math.PI );
|
3150 | this.sh.coefficients[0].set(color1.r,color1.g,color1.b).multiplyScalar(2*Math.sqrt(Math.PI));}AmbientLightProbe.prototype=_extends(Object.create(LightProbe.prototype),{constructor:AmbientLightProbe,isAmbientLightProbe:true,copy:function copy(source){// modifying color not currently supported
|
3151 | LightProbe.prototype.copy.call(this,source);return this;},toJSON:function toJSON(meta){var data=LightProbe.prototype.toJSON.call(this,meta);// data.sh = this.sh.toArray(); // todo
|
3152 | return data;}});var _eyeRight=new Matrix4();var _eyeLeft=new Matrix4();/**
|
3153 | * @author mrdoob / http://mrdoob.com/
|
3154 | */function StereoCamera(){this.type='StereoCamera';this.aspect=1;this.eyeSep=0.064;this.cameraL=new PerspectiveCamera();this.cameraL.layers.enable(1);this.cameraL.matrixAutoUpdate=false;this.cameraR=new PerspectiveCamera();this.cameraR.layers.enable(2);this.cameraR.matrixAutoUpdate=false;this._cache={focus:null,fov:null,aspect:null,near:null,far:null,zoom:null,eyeSep:null};}_extends(StereoCamera.prototype,{update:function update(camera){var cache=this._cache;var needsUpdate=cache.focus!==camera.focus||cache.fov!==camera.fov||cache.aspect!==camera.aspect*this.aspect||cache.near!==camera.near||cache.far!==camera.far||cache.zoom!==camera.zoom||cache.eyeSep!==this.eyeSep;if(needsUpdate){cache.focus=camera.focus;cache.fov=camera.fov;cache.aspect=camera.aspect*this.aspect;cache.near=camera.near;cache.far=camera.far;cache.zoom=camera.zoom;cache.eyeSep=this.eyeSep;// Off-axis stereoscopic effect based on
|
3155 | // http://paulbourke.net/stereographics/stereorender/
|
3156 | var projectionMatrix=camera.projectionMatrix.clone();var eyeSepHalf=cache.eyeSep/2;var eyeSepOnProjection=eyeSepHalf*cache.near/cache.focus;var ymax=cache.near*Math.tan(MathUtils.DEG2RAD*cache.fov*0.5)/cache.zoom;var xmin,xmax;// translate xOffset
|
3157 | _eyeLeft.elements[12]=-eyeSepHalf;_eyeRight.elements[12]=eyeSepHalf;// for left eye
|
3158 | xmin=-ymax*cache.aspect+eyeSepOnProjection;xmax=ymax*cache.aspect+eyeSepOnProjection;projectionMatrix.elements[0]=2*cache.near/(xmax-xmin);projectionMatrix.elements[8]=(xmax+xmin)/(xmax-xmin);this.cameraL.projectionMatrix.copy(projectionMatrix);// for right eye
|
3159 | xmin=-ymax*cache.aspect-eyeSepOnProjection;xmax=ymax*cache.aspect-eyeSepOnProjection;projectionMatrix.elements[0]=2*cache.near/(xmax-xmin);projectionMatrix.elements[8]=(xmax+xmin)/(xmax-xmin);this.cameraR.projectionMatrix.copy(projectionMatrix);}this.cameraL.matrixWorld.copy(camera.matrixWorld).multiply(_eyeLeft);this.cameraR.matrixWorld.copy(camera.matrixWorld).multiply(_eyeRight);}});/**
|
3160 | * @author alteredq / http://alteredqualia.com/
|
3161 | */function Clock(autoStart){this.autoStart=autoStart!==undefined?autoStart:true;this.startTime=0;this.oldTime=0;this.elapsedTime=0;this.running=false;}_extends(Clock.prototype,{start:function start(){this.startTime=(typeof performance==='undefined'?Date:performance).now();// see #10732
|
3162 | this.oldTime=this.startTime;this.elapsedTime=0;this.running=true;},stop:function stop(){this.getElapsedTime();this.running=false;this.autoStart=false;},getElapsedTime:function getElapsedTime(){this.getDelta();return this.elapsedTime;},getDelta:function getDelta(){var diff=0;if(this.autoStart&&!this.running){this.start();return 0;}if(this.running){var newTime=(typeof performance==='undefined'?Date:performance).now();diff=(newTime-this.oldTime)/1000;this.oldTime=newTime;this.elapsedTime+=diff;}return diff;}});/**
|
3163 | * @author mrdoob / http://mrdoob.com/
|
3164 | */var _position$2=new Vector3();var _quaternion$3=new Quaternion();var _scale$1=new Vector3();var _orientation=new Vector3();function AudioListener(){Object3D.call(this);this.type='AudioListener';this.context=AudioContext.getContext();this.gain=this.context.createGain();this.gain.connect(this.context.destination);this.filter=null;this.timeDelta=0;// private
|
3165 | this._clock=new Clock();}AudioListener.prototype=_extends(Object.create(Object3D.prototype),{constructor:AudioListener,getInput:function getInput(){return this.gain;},removeFilter:function removeFilter(){if(this.filter!==null){this.gain.disconnect(this.filter);this.filter.disconnect(this.context.destination);this.gain.connect(this.context.destination);this.filter=null;}return this;},getFilter:function getFilter(){return this.filter;},setFilter:function setFilter(value){if(this.filter!==null){this.gain.disconnect(this.filter);this.filter.disconnect(this.context.destination);}else {this.gain.disconnect(this.context.destination);}this.filter=value;this.gain.connect(this.filter);this.filter.connect(this.context.destination);return this;},getMasterVolume:function getMasterVolume(){return this.gain.gain.value;},setMasterVolume:function setMasterVolume(value){this.gain.gain.setTargetAtTime(value,this.context.currentTime,0.01);return this;},updateMatrixWorld:function updateMatrixWorld(force){Object3D.prototype.updateMatrixWorld.call(this,force);var listener=this.context.listener;var up=this.up;this.timeDelta=this._clock.getDelta();this.matrixWorld.decompose(_position$2,_quaternion$3,_scale$1);_orientation.set(0,0,-1).applyQuaternion(_quaternion$3);if(listener.positionX){// code path for Chrome (see #14393)
|
3166 | var endTime=this.context.currentTime+this.timeDelta;listener.positionX.linearRampToValueAtTime(_position$2.x,endTime);listener.positionY.linearRampToValueAtTime(_position$2.y,endTime);listener.positionZ.linearRampToValueAtTime(_position$2.z,endTime);listener.forwardX.linearRampToValueAtTime(_orientation.x,endTime);listener.forwardY.linearRampToValueAtTime(_orientation.y,endTime);listener.forwardZ.linearRampToValueAtTime(_orientation.z,endTime);listener.upX.linearRampToValueAtTime(up.x,endTime);listener.upY.linearRampToValueAtTime(up.y,endTime);listener.upZ.linearRampToValueAtTime(up.z,endTime);}else {listener.setPosition(_position$2.x,_position$2.y,_position$2.z);listener.setOrientation(_orientation.x,_orientation.y,_orientation.z,up.x,up.y,up.z);}}});/**
|
3167 | * @author mrdoob / http://mrdoob.com/
|
3168 | * @author Reece Aaron Lecrivain / http://reecenotes.com/
|
3169 | */function Audio(listener){Object3D.call(this);this.type='Audio';this.listener=listener;this.context=listener.context;this.gain=this.context.createGain();this.gain.connect(listener.getInput());this.autoplay=false;this.buffer=null;this.detune=0;this.loop=false;this.loopStart=0;this.loopEnd=0;this.offset=0;this.duration=undefined;this.playbackRate=1;this.isPlaying=false;this.hasPlaybackControl=true;this.sourceType='empty';this._startedAt=0;this._progress=0;this.filters=[];}Audio.prototype=_extends(Object.create(Object3D.prototype),{constructor:Audio,getOutput:function getOutput(){return this.gain;},setNodeSource:function setNodeSource(audioNode){this.hasPlaybackControl=false;this.sourceType='audioNode';this.source=audioNode;this.connect();return this;},setMediaElementSource:function setMediaElementSource(mediaElement){this.hasPlaybackControl=false;this.sourceType='mediaNode';this.source=this.context.createMediaElementSource(mediaElement);this.connect();return this;},setMediaStreamSource:function setMediaStreamSource(mediaStream){this.hasPlaybackControl=false;this.sourceType='mediaStreamNode';this.source=this.context.createMediaStreamSource(mediaStream);this.connect();return this;},setBuffer:function setBuffer(audioBuffer){this.buffer=audioBuffer;this.sourceType='buffer';if(this.autoplay)this.play();return this;},play:function play(delay){if(delay===undefined)delay=0;if(this.isPlaying===true){console.warn('THREE.Audio: Audio is already playing.');return;}if(this.hasPlaybackControl===false){console.warn('THREE.Audio: this Audio has no playback control.');return;}this._startedAt=this.context.currentTime+delay;var source=this.context.createBufferSource();source.buffer=this.buffer;source.loop=this.loop;source.loopStart=this.loopStart;source.loopEnd=this.loopEnd;source.onended=this.onEnded.bind(this);source.start(this._startedAt,this._progress+this.offset,this.duration);this.isPlaying=true;this.source=source;this.setDetune(this.detune);this.setPlaybackRate(this.playbackRate);return this.connect();},pause:function pause(){if(this.hasPlaybackControl===false){console.warn('THREE.Audio: this Audio has no playback control.');return;}if(this.isPlaying===true){// update current progress
|
3170 | this._progress+=Math.max(this.context.currentTime-this._startedAt,0)*this.playbackRate;if(this.loop===true){// ensure _progress does not exceed duration with looped audios
|
3171 | this._progress=this._progress%(this.duration||this.buffer.duration);}this.source.stop();this.source.onended=null;this.isPlaying=false;}return this;},stop:function stop(){if(this.hasPlaybackControl===false){console.warn('THREE.Audio: this Audio has no playback control.');return;}this._progress=0;this.source.stop();this.source.onended=null;this.isPlaying=false;return this;},connect:function connect(){if(this.filters.length>0){this.source.connect(this.filters[0]);for(var i=1,l=this.filters.length;i<l;i++){this.filters[i-1].connect(this.filters[i]);}this.filters[this.filters.length-1].connect(this.getOutput());}else {this.source.connect(this.getOutput());}return this;},disconnect:function disconnect(){if(this.filters.length>0){this.source.disconnect(this.filters[0]);for(var i=1,l=this.filters.length;i<l;i++){this.filters[i-1].disconnect(this.filters[i]);}this.filters[this.filters.length-1].disconnect(this.getOutput());}else {this.source.disconnect(this.getOutput());}return this;},getFilters:function getFilters(){return this.filters;},setFilters:function setFilters(value){if(!value)value=[];if(this.isPlaying===true){this.disconnect();this.filters=value;this.connect();}else {this.filters=value;}return this;},setDetune:function setDetune(value){this.detune=value;if(this.source.detune===undefined)return;// only set detune when available
|
3172 | if(this.isPlaying===true){this.source.detune.setTargetAtTime(this.detune,this.context.currentTime,0.01);}return this;},getDetune:function getDetune(){return this.detune;},getFilter:function getFilter(){return this.getFilters()[0];},setFilter:function setFilter(filter){return this.setFilters(filter?[filter]:[]);},setPlaybackRate:function setPlaybackRate(value){if(this.hasPlaybackControl===false){console.warn('THREE.Audio: this Audio has no playback control.');return;}this.playbackRate=value;if(this.isPlaying===true){this.source.playbackRate.setTargetAtTime(this.playbackRate,this.context.currentTime,0.01);}return this;},getPlaybackRate:function getPlaybackRate(){return this.playbackRate;},onEnded:function onEnded(){this.isPlaying=false;},getLoop:function getLoop(){if(this.hasPlaybackControl===false){console.warn('THREE.Audio: this Audio has no playback control.');return false;}return this.loop;},setLoop:function setLoop(value){if(this.hasPlaybackControl===false){console.warn('THREE.Audio: this Audio has no playback control.');return;}this.loop=value;if(this.isPlaying===true){this.source.loop=this.loop;}return this;},setLoopStart:function setLoopStart(value){this.loopStart=value;return this;},setLoopEnd:function setLoopEnd(value){this.loopEnd=value;return this;},getVolume:function getVolume(){return this.gain.gain.value;},setVolume:function setVolume(value){this.gain.gain.setTargetAtTime(value,this.context.currentTime,0.01);return this;}});/**
|
3173 | * @author mrdoob / http://mrdoob.com/
|
3174 | */var _position$3=new Vector3();var _quaternion$4=new Quaternion();var _scale$2=new Vector3();var _orientation$1=new Vector3();function PositionalAudio(listener){Audio.call(this,listener);this.panner=this.context.createPanner();this.panner.panningModel='HRTF';this.panner.connect(this.gain);}PositionalAudio.prototype=_extends(Object.create(Audio.prototype),{constructor:PositionalAudio,getOutput:function getOutput(){return this.panner;},getRefDistance:function getRefDistance(){return this.panner.refDistance;},setRefDistance:function setRefDistance(value){this.panner.refDistance=value;return this;},getRolloffFactor:function getRolloffFactor(){return this.panner.rolloffFactor;},setRolloffFactor:function setRolloffFactor(value){this.panner.rolloffFactor=value;return this;},getDistanceModel:function getDistanceModel(){return this.panner.distanceModel;},setDistanceModel:function setDistanceModel(value){this.panner.distanceModel=value;return this;},getMaxDistance:function getMaxDistance(){return this.panner.maxDistance;},setMaxDistance:function setMaxDistance(value){this.panner.maxDistance=value;return this;},setDirectionalCone:function setDirectionalCone(coneInnerAngle,coneOuterAngle,coneOuterGain){this.panner.coneInnerAngle=coneInnerAngle;this.panner.coneOuterAngle=coneOuterAngle;this.panner.coneOuterGain=coneOuterGain;return this;},updateMatrixWorld:function updateMatrixWorld(force){Object3D.prototype.updateMatrixWorld.call(this,force);if(this.hasPlaybackControl===true&&this.isPlaying===false)return;this.matrixWorld.decompose(_position$3,_quaternion$4,_scale$2);_orientation$1.set(0,0,1).applyQuaternion(_quaternion$4);var panner=this.panner;if(panner.positionX){// code path for Chrome and Firefox (see #14393)
|
3175 | var endTime=this.context.currentTime+this.listener.timeDelta;panner.positionX.linearRampToValueAtTime(_position$3.x,endTime);panner.positionY.linearRampToValueAtTime(_position$3.y,endTime);panner.positionZ.linearRampToValueAtTime(_position$3.z,endTime);panner.orientationX.linearRampToValueAtTime(_orientation$1.x,endTime);panner.orientationY.linearRampToValueAtTime(_orientation$1.y,endTime);panner.orientationZ.linearRampToValueAtTime(_orientation$1.z,endTime);}else {panner.setPosition(_position$3.x,_position$3.y,_position$3.z);panner.setOrientation(_orientation$1.x,_orientation$1.y,_orientation$1.z);}}});/**
|
3176 | * @author mrdoob / http://mrdoob.com/
|
3177 | */function AudioAnalyser(audio,fftSize){this.analyser=audio.context.createAnalyser();this.analyser.fftSize=fftSize!==undefined?fftSize:2048;this.data=new Uint8Array(this.analyser.frequencyBinCount);audio.getOutput().connect(this.analyser);}_extends(AudioAnalyser.prototype,{getFrequencyData:function getFrequencyData(){this.analyser.getByteFrequencyData(this.data);return this.data;},getAverageFrequency:function getAverageFrequency(){var value=0,data=this.getFrequencyData();for(var i=0;i<data.length;i++){value+=data[i];}return value/data.length;}});/**
|
3178 | *
|
3179 | * Buffered scene graph property that allows weighted accumulation.
|
3180 | *
|
3181 | *
|
3182 | * @author Ben Houston / http://clara.io/
|
3183 | * @author David Sarno / http://lighthaus.us/
|
3184 | * @author tschw
|
3185 | */function PropertyMixer(binding,typeName,valueSize){this.binding=binding;this.valueSize=valueSize;var mixFunction,mixFunctionAdditive,setIdentity;// buffer layout: [ incoming | accu0 | accu1 | orig | addAccu | (optional work) ]
|
3186 | //
|
3187 | // interpolators can use .buffer as their .result
|
3188 | // the data then goes to 'incoming'
|
3189 | //
|
3190 | // 'accu0' and 'accu1' are used frame-interleaved for
|
3191 | // the cumulative result and are compared to detect
|
3192 | // changes
|
3193 | //
|
3194 | // 'orig' stores the original state of the property
|
3195 | //
|
3196 | // 'add' is used for additive cumulative results
|
3197 | //
|
3198 | // 'work' is optional and is only present for quaternion types. It is used
|
3199 | // to store intermediate quaternion multiplication results
|
3200 | switch(typeName){case'quaternion':mixFunction=this._slerp;mixFunctionAdditive=this._slerpAdditive;setIdentity=this._setAdditiveIdentityQuaternion;this.buffer=new Float64Array(valueSize*6);this._workIndex=5;break;case'string':case'bool':mixFunction=this._select;// Use the regular mix function and for additive on these types,
|
3201 | // additive is not relevant for non-numeric types
|
3202 | mixFunctionAdditive=this._select;setIdentity=this._setAdditiveIdentityOther;this.buffer=new Array(valueSize*5);break;default:mixFunction=this._lerp;mixFunctionAdditive=this._lerpAdditive;setIdentity=this._setAdditiveIdentityNumeric;this.buffer=new Float64Array(valueSize*5);}this._mixBufferRegion=mixFunction;this._mixBufferRegionAdditive=mixFunctionAdditive;this._setIdentity=setIdentity;this._origIndex=3;this._addIndex=4;this.cumulativeWeight=0;this.cumulativeWeightAdditive=0;this.useCount=0;this.referenceCount=0;}_extends(PropertyMixer.prototype,{// accumulate data in the 'incoming' region into 'accu<i>'
|
3203 | accumulate:function accumulate(accuIndex,weight){// note: happily accumulating nothing when weight = 0, the caller knows
|
3204 | // the weight and shouldn't have made the call in the first place
|
3205 | var buffer=this.buffer,stride=this.valueSize,offset=accuIndex*stride+stride,currentWeight=this.cumulativeWeight;if(currentWeight===0){// accuN := incoming * weight
|
3206 | for(var i=0;i!==stride;++i){buffer[offset+i]=buffer[i];}currentWeight=weight;}else {// accuN := accuN + incoming * weight
|
3207 | currentWeight+=weight;var mix=weight/currentWeight;this._mixBufferRegion(buffer,offset,0,mix,stride);}this.cumulativeWeight=currentWeight;},// accumulate data in the 'incoming' region into 'add'
|
3208 | accumulateAdditive:function accumulateAdditive(weight){var buffer=this.buffer,stride=this.valueSize,offset=stride*this._addIndex;if(this.cumulativeWeightAdditive===0){// add = identity
|
3209 | this._setIdentity();}// add := add + incoming * weight
|
3210 | this._mixBufferRegionAdditive(buffer,offset,0,weight,stride);this.cumulativeWeightAdditive+=weight;},// apply the state of 'accu<i>' to the binding when accus differ
|
3211 | apply:function apply(accuIndex){var stride=this.valueSize,buffer=this.buffer,offset=accuIndex*stride+stride,weight=this.cumulativeWeight,weightAdditive=this.cumulativeWeightAdditive,binding=this.binding;this.cumulativeWeight=0;this.cumulativeWeightAdditive=0;if(weight<1){// accuN := accuN + original * ( 1 - cumulativeWeight )
|
3212 | var originalValueOffset=stride*this._origIndex;this._mixBufferRegion(buffer,offset,originalValueOffset,1-weight,stride);}if(weightAdditive>0){// accuN := accuN + additive accuN
|
3213 | this._mixBufferRegionAdditive(buffer,offset,this._addIndex*stride,1,stride);}for(var i=stride,e=stride+stride;i!==e;++i){if(buffer[i]!==buffer[i+stride]){// value has changed -> update scene graph
|
3214 | binding.setValue(buffer,offset);break;}}},// remember the state of the bound property and copy it to both accus
|
3215 | saveOriginalState:function saveOriginalState(){var binding=this.binding;var buffer=this.buffer,stride=this.valueSize,originalValueOffset=stride*this._origIndex;binding.getValue(buffer,originalValueOffset);// accu[0..1] := orig -- initially detect changes against the original
|
3216 | for(var i=stride,e=originalValueOffset;i!==e;++i){buffer[i]=buffer[originalValueOffset+i%stride];}// Add to identity for additive
|
3217 | this._setIdentity();this.cumulativeWeight=0;this.cumulativeWeightAdditive=0;},// apply the state previously taken via 'saveOriginalState' to the binding
|
3218 | restoreOriginalState:function restoreOriginalState(){var originalValueOffset=this.valueSize*3;this.binding.setValue(this.buffer,originalValueOffset);},_setAdditiveIdentityNumeric:function _setAdditiveIdentityNumeric(){var startIndex=this._addIndex*this.valueSize;this.buffer.fill(0,startIndex,startIndex+this.valueSize);},_setAdditiveIdentityQuaternion:function _setAdditiveIdentityQuaternion(){this._setAdditiveIdentityNumeric();this.buffer[this._addIndex*4+3]=1;},_setAdditiveIdentityOther:function _setAdditiveIdentityOther(){var startIndex=this._origIndex*this.valueSize;var targetIndex=this._addIndex*this.valueSize;this.buffer.copyWithin(targetIndex,startIndex,this.valueSize);},// mix functions
|
3219 | _select:function _select(buffer,dstOffset,srcOffset,t,stride){if(t>=0.5){for(var i=0;i!==stride;++i){buffer[dstOffset+i]=buffer[srcOffset+i];}}},_slerp:function _slerp(buffer,dstOffset,srcOffset,t){Quaternion.slerpFlat(buffer,dstOffset,buffer,dstOffset,buffer,srcOffset,t);},_slerpAdditive:function _slerpAdditive(buffer,dstOffset,srcOffset,t,stride){var workOffset=this._workIndex*stride;// Store result in intermediate buffer offset
|
3220 | Quaternion.multiplyQuaternionsFlat(buffer,workOffset,buffer,dstOffset,buffer,srcOffset);// Slerp to the intermediate result
|
3221 | Quaternion.slerpFlat(buffer,dstOffset,buffer,dstOffset,buffer,workOffset,t);},_lerp:function _lerp(buffer,dstOffset,srcOffset,t,stride){var s=1-t;for(var i=0;i!==stride;++i){var j=dstOffset+i;buffer[j]=buffer[j]*s+buffer[srcOffset+i]*t;}},_lerpAdditive:function _lerpAdditive(buffer,dstOffset,srcOffset,t,stride){for(var i=0;i!==stride;++i){var j=dstOffset+i;buffer[j]=buffer[j]+buffer[srcOffset+i]*t;}}});/**
|
3222 | *
|
3223 | * A reference to a real property in the scene graph.
|
3224 | *
|
3225 | *
|
3226 | * @author Ben Houston / http://clara.io/
|
3227 | * @author David Sarno / http://lighthaus.us/
|
3228 | * @author tschw
|
3229 | */ // Characters [].:/ are reserved for track binding syntax.
|
3230 | var _RESERVED_CHARS_RE='\\[\\]\\.:\\/';var _reservedRe=new RegExp('['+_RESERVED_CHARS_RE+']','g');// Attempts to allow node names from any language. ES5's `\w` regexp matches
|
3231 | // only latin characters, and the unicode \p{L} is not yet supported. So
|
3232 | // instead, we exclude reserved characters and match everything else.
|
3233 | var _wordChar='[^'+_RESERVED_CHARS_RE+']';var _wordCharOrDot='[^'+_RESERVED_CHARS_RE.replace('\\.','')+']';// Parent directories, delimited by '/' or ':'. Currently unused, but must
|
3234 | // be matched to parse the rest of the track name.
|
3235 | var _directoryRe=/((?:WC+[\/:])*)/.source.replace('WC',_wordChar);// Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
|
3236 | var _nodeRe=/(WCOD+)?/.source.replace('WCOD',_wordCharOrDot);// Object on target node, and accessor. May not contain reserved
|
3237 | // characters. Accessor may contain any character except closing bracket.
|
3238 | var _objectRe=/(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace('WC',_wordChar);// Property and accessor. May not contain reserved characters. Accessor may
|
3239 | // contain any non-bracket characters.
|
3240 | var _propertyRe=/\.(WC+)(?:\[(.+)\])?/.source.replace('WC',_wordChar);var _trackRe=new RegExp(''+'^'+_directoryRe+_nodeRe+_objectRe+_propertyRe+'$');var _supportedObjectNames=['material','materials','bones'];function Composite(targetGroup,path,optionalParsedPath){var parsedPath=optionalParsedPath||PropertyBinding.parseTrackName(path);this._targetGroup=targetGroup;this._bindings=targetGroup.subscribe_(path,parsedPath);}_extends(Composite.prototype,{getValue:function getValue(array,offset){this.bind();// bind all binding
|
3241 | var firstValidIndex=this._targetGroup.nCachedObjects_,binding=this._bindings[firstValidIndex];// and only call .getValue on the first
|
3242 | if(binding!==undefined)binding.getValue(array,offset);},setValue:function setValue(array,offset){var bindings=this._bindings;for(var i=this._targetGroup.nCachedObjects_,n=bindings.length;i!==n;++i){bindings[i].setValue(array,offset);}},bind:function bind(){var bindings=this._bindings;for(var i=this._targetGroup.nCachedObjects_,n=bindings.length;i!==n;++i){bindings[i].bind();}},unbind:function unbind(){var bindings=this._bindings;for(var i=this._targetGroup.nCachedObjects_,n=bindings.length;i!==n;++i){bindings[i].unbind();}}});function PropertyBinding(rootNode,path,parsedPath){this.path=path;this.parsedPath=parsedPath||PropertyBinding.parseTrackName(path);this.node=PropertyBinding.findNode(rootNode,this.parsedPath.nodeName)||rootNode;this.rootNode=rootNode;}_extends(PropertyBinding,{Composite:Composite,create:function create(root,path,parsedPath){if(!(root&&root.isAnimationObjectGroup)){return new PropertyBinding(root,path,parsedPath);}else {return new PropertyBinding.Composite(root,path,parsedPath);}},/**
|
3243 | * Replaces spaces with underscores and removes unsupported characters from
|
3244 | * node names, to ensure compatibility with parseTrackName().
|
3245 | *
|
3246 | * @param {string} name Node name to be sanitized.
|
3247 | * @return {string}
|
3248 | */sanitizeNodeName:function sanitizeNodeName(name){return name.replace(/\s/g,'_').replace(_reservedRe,'');},parseTrackName:function parseTrackName(trackName){var matches=_trackRe.exec(trackName);if(!matches){throw new Error('PropertyBinding: Cannot parse trackName: '+trackName);}var results={// directoryName: matches[ 1 ], // (tschw) currently unused
|
3249 | nodeName:matches[2],objectName:matches[3],objectIndex:matches[4],propertyName:matches[5],// required
|
3250 | propertyIndex:matches[6]};var lastDot=results.nodeName&&results.nodeName.lastIndexOf('.');if(lastDot!==undefined&&lastDot!==-1){var objectName=results.nodeName.substring(lastDot+1);// Object names must be checked against a whitelist. Otherwise, there
|
3251 | // is no way to parse 'foo.bar.baz': 'baz' must be a property, but
|
3252 | // 'bar' could be the objectName, or part of a nodeName (which can
|
3253 | // include '.' characters).
|
3254 | if(_supportedObjectNames.indexOf(objectName)!==-1){results.nodeName=results.nodeName.substring(0,lastDot);results.objectName=objectName;}}if(results.propertyName===null||results.propertyName.length===0){throw new Error('PropertyBinding: can not parse propertyName from trackName: '+trackName);}return results;},findNode:function findNode(root,nodeName){if(!nodeName||nodeName===""||nodeName==="."||nodeName===-1||nodeName===root.name||nodeName===root.uuid){return root;}// search into skeleton bones.
|
3255 | if(root.skeleton){var bone=root.skeleton.getBoneByName(nodeName);if(bone!==undefined){return bone;}}// search into node subtree.
|
3256 | if(root.children){var searchNodeSubtree=function searchNodeSubtree(children){for(var i=0;i<children.length;i++){var childNode=children[i];if(childNode.name===nodeName||childNode.uuid===nodeName){return childNode;}var result=searchNodeSubtree(childNode.children);if(result)return result;}return null;};var subTreeNode=searchNodeSubtree(root.children);if(subTreeNode){return subTreeNode;}}return null;}});_extends(PropertyBinding.prototype,{// prototype, continued
|
3257 | // these are used to "bind" a nonexistent property
|
3258 | _getValue_unavailable:function _getValue_unavailable(){},_setValue_unavailable:function _setValue_unavailable(){},BindingType:{Direct:0,EntireArray:1,ArrayElement:2,HasFromToArray:3},Versioning:{None:0,NeedsUpdate:1,MatrixWorldNeedsUpdate:2},GetterByBindingType:[function getValue_direct(buffer,offset){buffer[offset]=this.node[this.propertyName];},function getValue_array(buffer,offset){var source=this.resolvedProperty;for(var i=0,n=source.length;i!==n;++i){buffer[offset++]=source[i];}},function getValue_arrayElement(buffer,offset){buffer[offset]=this.resolvedProperty[this.propertyIndex];},function getValue_toArray(buffer,offset){this.resolvedProperty.toArray(buffer,offset);}],SetterByBindingTypeAndVersioning:[[// Direct
|
3259 | function setValue_direct(buffer,offset){this.targetObject[this.propertyName]=buffer[offset];},function setValue_direct_setNeedsUpdate(buffer,offset){this.targetObject[this.propertyName]=buffer[offset];this.targetObject.needsUpdate=true;},function setValue_direct_setMatrixWorldNeedsUpdate(buffer,offset){this.targetObject[this.propertyName]=buffer[offset];this.targetObject.matrixWorldNeedsUpdate=true;}],[// EntireArray
|
3260 | function setValue_array(buffer,offset){var dest=this.resolvedProperty;for(var i=0,n=dest.length;i!==n;++i){dest[i]=buffer[offset++];}},function setValue_array_setNeedsUpdate(buffer,offset){var dest=this.resolvedProperty;for(var i=0,n=dest.length;i!==n;++i){dest[i]=buffer[offset++];}this.targetObject.needsUpdate=true;},function setValue_array_setMatrixWorldNeedsUpdate(buffer,offset){var dest=this.resolvedProperty;for(var i=0,n=dest.length;i!==n;++i){dest[i]=buffer[offset++];}this.targetObject.matrixWorldNeedsUpdate=true;}],[// ArrayElement
|
3261 | function setValue_arrayElement(buffer,offset){this.resolvedProperty[this.propertyIndex]=buffer[offset];},function setValue_arrayElement_setNeedsUpdate(buffer,offset){this.resolvedProperty[this.propertyIndex]=buffer[offset];this.targetObject.needsUpdate=true;},function setValue_arrayElement_setMatrixWorldNeedsUpdate(buffer,offset){this.resolvedProperty[this.propertyIndex]=buffer[offset];this.targetObject.matrixWorldNeedsUpdate=true;}],[// HasToFromArray
|
3262 | function setValue_fromArray(buffer,offset){this.resolvedProperty.fromArray(buffer,offset);},function setValue_fromArray_setNeedsUpdate(buffer,offset){this.resolvedProperty.fromArray(buffer,offset);this.targetObject.needsUpdate=true;},function setValue_fromArray_setMatrixWorldNeedsUpdate(buffer,offset){this.resolvedProperty.fromArray(buffer,offset);this.targetObject.matrixWorldNeedsUpdate=true;}]],getValue:function getValue_unbound(targetArray,offset){this.bind();this.getValue(targetArray,offset);// Note: This class uses a State pattern on a per-method basis:
|
3263 | // 'bind' sets 'this.getValue' / 'setValue' and shadows the
|
3264 | // prototype version of these methods with one that represents
|
3265 | // the bound state. When the property is not found, the methods
|
3266 | // become no-ops.
|
3267 | },setValue:function getValue_unbound(sourceArray,offset){this.bind();this.setValue(sourceArray,offset);},// create getter / setter pair for a property in the scene graph
|
3268 | bind:function bind(){var targetObject=this.node,parsedPath=this.parsedPath,objectName=parsedPath.objectName,propertyName=parsedPath.propertyName,propertyIndex=parsedPath.propertyIndex;if(!targetObject){targetObject=PropertyBinding.findNode(this.rootNode,parsedPath.nodeName)||this.rootNode;this.node=targetObject;}// set fail state so we can just 'return' on error
|
3269 | this.getValue=this._getValue_unavailable;this.setValue=this._setValue_unavailable;// ensure there is a value node
|
3270 | if(!targetObject){console.error('THREE.PropertyBinding: Trying to update node for track: '+this.path+' but it wasn\'t found.');return;}if(objectName){var objectIndex=parsedPath.objectIndex;// special cases were we need to reach deeper into the hierarchy to get the face materials....
|
3271 | switch(objectName){case'materials':if(!targetObject.material){console.error('THREE.PropertyBinding: Can not bind to material as node does not have a material.',this);return;}if(!targetObject.material.materials){console.error('THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.',this);return;}targetObject=targetObject.material.materials;break;case'bones':if(!targetObject.skeleton){console.error('THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.',this);return;}// potential future optimization: skip this if propertyIndex is already an integer
|
3272 | // and convert the integer string to a true integer.
|
3273 | targetObject=targetObject.skeleton.bones;// support resolving morphTarget names into indices.
|
3274 | for(var i=0;i<targetObject.length;i++){if(targetObject[i].name===objectIndex){objectIndex=i;break;}}break;default:if(targetObject[objectName]===undefined){console.error('THREE.PropertyBinding: Can not bind to objectName of node undefined.',this);return;}targetObject=targetObject[objectName];}if(objectIndex!==undefined){if(targetObject[objectIndex]===undefined){console.error('THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.',this,targetObject);return;}targetObject=targetObject[objectIndex];}}// resolve property
|
3275 | var nodeProperty=targetObject[propertyName];if(nodeProperty===undefined){var nodeName=parsedPath.nodeName;console.error('THREE.PropertyBinding: Trying to update property for track: '+nodeName+'.'+propertyName+' but it wasn\'t found.',targetObject);return;}// determine versioning scheme
|
3276 | var versioning=this.Versioning.None;this.targetObject=targetObject;if(targetObject.needsUpdate!==undefined){// material
|
3277 | versioning=this.Versioning.NeedsUpdate;}else if(targetObject.matrixWorldNeedsUpdate!==undefined){// node transform
|
3278 | versioning=this.Versioning.MatrixWorldNeedsUpdate;}// determine how the property gets bound
|
3279 | var bindingType=this.BindingType.Direct;if(propertyIndex!==undefined){// access a sub element of the property array (only primitives are supported right now)
|
3280 | if(propertyName==="morphTargetInfluences"){// potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
|
3281 | // support resolving morphTarget names into indices.
|
3282 | if(!targetObject.geometry){console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.',this);return;}if(targetObject.geometry.isBufferGeometry){if(!targetObject.geometry.morphAttributes){console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.',this);return;}for(var i=0;i<this.node.geometry.morphAttributes.position.length;i++){if(targetObject.geometry.morphAttributes.position[i].name===propertyIndex){propertyIndex=i;break;}}}else {if(!targetObject.geometry.morphTargets){console.error('THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphTargets.',this);return;}for(var i=0;i<this.node.geometry.morphTargets.length;i++){if(targetObject.geometry.morphTargets[i].name===propertyIndex){propertyIndex=i;break;}}}}bindingType=this.BindingType.ArrayElement;this.resolvedProperty=nodeProperty;this.propertyIndex=propertyIndex;}else if(nodeProperty.fromArray!==undefined&&nodeProperty.toArray!==undefined){// must use copy for Object3D.Euler/Quaternion
|
3283 | bindingType=this.BindingType.HasFromToArray;this.resolvedProperty=nodeProperty;}else if(Array.isArray(nodeProperty)){bindingType=this.BindingType.EntireArray;this.resolvedProperty=nodeProperty;}else {this.propertyName=propertyName;}// select getter / setter
|
3284 | this.getValue=this.GetterByBindingType[bindingType];this.setValue=this.SetterByBindingTypeAndVersioning[bindingType][versioning];},unbind:function unbind(){this.node=null;// back to the prototype version of getValue / setValue
|
3285 | // note: avoiding to mutate the shape of 'this' via 'delete'
|
3286 | this.getValue=this._getValue_unbound;this.setValue=this._setValue_unbound;}});// DECLARE ALIAS AFTER assign prototype
|
3287 | _extends(PropertyBinding.prototype,{// initial state of these methods that calls 'bind'
|
3288 | _getValue_unbound:PropertyBinding.prototype.getValue,_setValue_unbound:PropertyBinding.prototype.setValue});/**
|
3289 | *
|
3290 | * A group of objects that receives a shared animation state.
|
3291 | *
|
3292 | * Usage:
|
3293 | *
|
3294 | * - Add objects you would otherwise pass as 'root' to the
|
3295 | * constructor or the .clipAction method of AnimationMixer.
|
3296 | *
|
3297 | * - Instead pass this object as 'root'.
|
3298 | *
|
3299 | * - You can also add and remove objects later when the mixer
|
3300 | * is running.
|
3301 | *
|
3302 | * Note:
|
3303 | *
|
3304 | * Objects of this class appear as one object to the mixer,
|
3305 | * so cache control of the individual objects must be done
|
3306 | * on the group.
|
3307 | *
|
3308 | * Limitation:
|
3309 | *
|
3310 | * - The animated properties must be compatible among the
|
3311 | * all objects in the group.
|
3312 | *
|
3313 | * - A single property can either be controlled through a
|
3314 | * target group or directly, but not both.
|
3315 | *
|
3316 | * @author tschw
|
3317 | */function AnimationObjectGroup(){this.uuid=MathUtils.generateUUID();// cached objects followed by the active ones
|
3318 | this._objects=Array.prototype.slice.call(arguments);this.nCachedObjects_=0;// threshold
|
3319 | // note: read by PropertyBinding.Composite
|
3320 | var indices={};this._indicesByUUID=indices;// for bookkeeping
|
3321 | for(var i=0,n=arguments.length;i!==n;++i){indices[arguments[i].uuid]=i;}this._paths=[];// inside: string
|
3322 | this._parsedPaths=[];// inside: { we don't care, here }
|
3323 | this._bindings=[];// inside: Array< PropertyBinding >
|
3324 | this._bindingsIndicesByPath={};// inside: indices in these arrays
|
3325 | var scope=this;this.stats={objects:{get total(){return scope._objects.length;},get inUse(){return this.total-scope.nCachedObjects_;}},get bindingsPerObject(){return scope._bindings.length;}};}_extends(AnimationObjectGroup.prototype,{isAnimationObjectGroup:true,add:function add(){var objects=this._objects,nObjects=objects.length,nCachedObjects=this.nCachedObjects_,indicesByUUID=this._indicesByUUID,paths=this._paths,parsedPaths=this._parsedPaths,bindings=this._bindings,nBindings=bindings.length,knownObject=undefined;for(var i=0,n=arguments.length;i!==n;++i){var object=arguments[i],uuid=object.uuid,index=indicesByUUID[uuid];if(index===undefined){// unknown object -> add it to the ACTIVE region
|
3326 | index=nObjects++;indicesByUUID[uuid]=index;objects.push(object);// accounting is done, now do the same for all bindings
|
3327 | for(var j=0,m=nBindings;j!==m;++j){bindings[j].push(new PropertyBinding(object,paths[j],parsedPaths[j]));}}else if(index<nCachedObjects){knownObject=objects[index];// move existing object to the ACTIVE region
|
3328 | var firstActiveIndex=--nCachedObjects,lastCachedObject=objects[firstActiveIndex];indicesByUUID[lastCachedObject.uuid]=index;objects[index]=lastCachedObject;indicesByUUID[uuid]=firstActiveIndex;objects[firstActiveIndex]=object;// accounting is done, now do the same for all bindings
|
3329 | for(var j=0,m=nBindings;j!==m;++j){var bindingsForPath=bindings[j],lastCached=bindingsForPath[firstActiveIndex],binding=bindingsForPath[index];bindingsForPath[index]=lastCached;if(binding===undefined){// since we do not bother to create new bindings
|
3330 | // for objects that are cached, the binding may
|
3331 | // or may not exist
|
3332 | binding=new PropertyBinding(object,paths[j],parsedPaths[j]);}bindingsForPath[firstActiveIndex]=binding;}}else if(objects[index]!==knownObject){console.error('THREE.AnimationObjectGroup: Different objects with the same UUID '+'detected. Clean the caches or recreate your infrastructure when reloading scenes.');}// else the object is already where we want it to be
|
3333 | }// for arguments
|
3334 | this.nCachedObjects_=nCachedObjects;},remove:function remove(){var objects=this._objects,nCachedObjects=this.nCachedObjects_,indicesByUUID=this._indicesByUUID,bindings=this._bindings,nBindings=bindings.length;for(var i=0,n=arguments.length;i!==n;++i){var object=arguments[i],uuid=object.uuid,index=indicesByUUID[uuid];if(index!==undefined&&index>=nCachedObjects){// move existing object into the CACHED region
|
3335 | var lastCachedIndex=nCachedObjects++,firstActiveObject=objects[lastCachedIndex];indicesByUUID[firstActiveObject.uuid]=index;objects[index]=firstActiveObject;indicesByUUID[uuid]=lastCachedIndex;objects[lastCachedIndex]=object;// accounting is done, now do the same for all bindings
|
3336 | for(var j=0,m=nBindings;j!==m;++j){var bindingsForPath=bindings[j],firstActive=bindingsForPath[lastCachedIndex],binding=bindingsForPath[index];bindingsForPath[index]=firstActive;bindingsForPath[lastCachedIndex]=binding;}}}// for arguments
|
3337 | this.nCachedObjects_=nCachedObjects;},// remove & forget
|
3338 | uncache:function uncache(){var objects=this._objects,nObjects=objects.length,nCachedObjects=this.nCachedObjects_,indicesByUUID=this._indicesByUUID,bindings=this._bindings,nBindings=bindings.length;for(var i=0,n=arguments.length;i!==n;++i){var object=arguments[i],uuid=object.uuid,index=indicesByUUID[uuid];if(index!==undefined){delete indicesByUUID[uuid];if(index<nCachedObjects){// object is cached, shrink the CACHED region
|
3339 | var firstActiveIndex=--nCachedObjects,lastCachedObject=objects[firstActiveIndex],lastIndex=--nObjects,lastObject=objects[lastIndex];// last cached object takes this object's place
|
3340 | indicesByUUID[lastCachedObject.uuid]=index;objects[index]=lastCachedObject;// last object goes to the activated slot and pop
|
3341 | indicesByUUID[lastObject.uuid]=firstActiveIndex;objects[firstActiveIndex]=lastObject;objects.pop();// accounting is done, now do the same for all bindings
|
3342 | for(var j=0,m=nBindings;j!==m;++j){var bindingsForPath=bindings[j],lastCached=bindingsForPath[firstActiveIndex],last=bindingsForPath[lastIndex];bindingsForPath[index]=lastCached;bindingsForPath[firstActiveIndex]=last;bindingsForPath.pop();}}else {// object is active, just swap with the last and pop
|
3343 | var lastIndex=--nObjects,lastObject=objects[lastIndex];indicesByUUID[lastObject.uuid]=index;objects[index]=lastObject;objects.pop();// accounting is done, now do the same for all bindings
|
3344 | for(var j=0,m=nBindings;j!==m;++j){var bindingsForPath=bindings[j];bindingsForPath[index]=bindingsForPath[lastIndex];bindingsForPath.pop();}}// cached or active
|
3345 | }// if object is known
|
3346 | }// for arguments
|
3347 | this.nCachedObjects_=nCachedObjects;},// Internal interface used by befriended PropertyBinding.Composite:
|
3348 | subscribe_:function subscribe_(path,parsedPath){// returns an array of bindings for the given path that is changed
|
3349 | // according to the contained objects in the group
|
3350 | var indicesByPath=this._bindingsIndicesByPath,index=indicesByPath[path],bindings=this._bindings;if(index!==undefined)return bindings[index];var paths=this._paths,parsedPaths=this._parsedPaths,objects=this._objects,nObjects=objects.length,nCachedObjects=this.nCachedObjects_,bindingsForPath=new Array(nObjects);index=bindings.length;indicesByPath[path]=index;paths.push(path);parsedPaths.push(parsedPath);bindings.push(bindingsForPath);for(var i=nCachedObjects,n=objects.length;i!==n;++i){var object=objects[i];bindingsForPath[i]=new PropertyBinding(object,path,parsedPath);}return bindingsForPath;},unsubscribe_:function unsubscribe_(path){// tells the group to forget about a property path and no longer
|
3351 | // update the array previously obtained with 'subscribe_'
|
3352 | var indicesByPath=this._bindingsIndicesByPath,index=indicesByPath[path];if(index!==undefined){var paths=this._paths,parsedPaths=this._parsedPaths,bindings=this._bindings,lastBindingsIndex=bindings.length-1,lastBindings=bindings[lastBindingsIndex],lastBindingsPath=path[lastBindingsIndex];indicesByPath[lastBindingsPath]=index;bindings[index]=lastBindings;bindings.pop();parsedPaths[index]=parsedPaths[lastBindingsIndex];parsedPaths.pop();paths[index]=paths[lastBindingsIndex];paths.pop();}}});/**
|
3353 | *
|
3354 | * Action provided by AnimationMixer for scheduling clip playback on specific
|
3355 | * objects.
|
3356 | *
|
3357 | * @author Ben Houston / http://clara.io/
|
3358 | * @author David Sarno / http://lighthaus.us/
|
3359 | * @author tschw
|
3360 | *
|
3361 | */function AnimationAction(mixer,clip,localRoot,blendMode){this._mixer=mixer;this._clip=clip;this._localRoot=localRoot||null;this.blendMode=blendMode||clip.blendMode;var tracks=clip.tracks,nTracks=tracks.length,interpolants=new Array(nTracks);var interpolantSettings={endingStart:ZeroCurvatureEnding,endingEnd:ZeroCurvatureEnding};for(var i=0;i!==nTracks;++i){var interpolant=tracks[i].createInterpolant(null);interpolants[i]=interpolant;interpolant.settings=interpolantSettings;}this._interpolantSettings=interpolantSettings;this._interpolants=interpolants;// bound by the mixer
|
3362 | // inside: PropertyMixer (managed by the mixer)
|
3363 | this._propertyBindings=new Array(nTracks);this._cacheIndex=null;// for the memory manager
|
3364 | this._byClipCacheIndex=null;// for the memory manager
|
3365 | this._timeScaleInterpolant=null;this._weightInterpolant=null;this.loop=LoopRepeat;this._loopCount=-1;// global mixer time when the action is to be started
|
3366 | // it's set back to 'null' upon start of the action
|
3367 | this._startTime=null;// scaled local time of the action
|
3368 | // gets clamped or wrapped to 0..clip.duration according to loop
|
3369 | this.time=0;this.timeScale=1;this._effectiveTimeScale=1;this.weight=1;this._effectiveWeight=1;this.repetitions=Infinity;// no. of repetitions when looping
|
3370 | this.paused=false;// true -> zero effective time scale
|
3371 | this.enabled=true;// false -> zero effective weight
|
3372 | this.clampWhenFinished=false;// keep feeding the last frame?
|
3373 | this.zeroSlopeAtStart=true;// for smooth interpolation w/o separate
|
3374 | this.zeroSlopeAtEnd=true;// clips for start, loop and end
|
3375 | }_extends(AnimationAction.prototype,{// State & Scheduling
|
3376 | play:function play(){this._mixer._activateAction(this);return this;},stop:function stop(){this._mixer._deactivateAction(this);return this.reset();},reset:function reset(){this.paused=false;this.enabled=true;this.time=0;// restart clip
|
3377 | this._loopCount=-1;// forget previous loops
|
3378 | this._startTime=null;// forget scheduling
|
3379 | return this.stopFading().stopWarping();},isRunning:function isRunning(){return this.enabled&&!this.paused&&this.timeScale!==0&&this._startTime===null&&this._mixer._isActiveAction(this);},// return true when play has been called
|
3380 | isScheduled:function isScheduled(){return this._mixer._isActiveAction(this);},startAt:function startAt(time){this._startTime=time;return this;},setLoop:function setLoop(mode,repetitions){this.loop=mode;this.repetitions=repetitions;return this;},// Weight
|
3381 | // set the weight stopping any scheduled fading
|
3382 | // although .enabled = false yields an effective weight of zero, this
|
3383 | // method does *not* change .enabled, because it would be confusing
|
3384 | setEffectiveWeight:function setEffectiveWeight(weight){this.weight=weight;// note: same logic as when updated at runtime
|
3385 | this._effectiveWeight=this.enabled?weight:0;return this.stopFading();},// return the weight considering fading and .enabled
|
3386 | getEffectiveWeight:function getEffectiveWeight(){return this._effectiveWeight;},fadeIn:function fadeIn(duration){return this._scheduleFading(duration,0,1);},fadeOut:function fadeOut(duration){return this._scheduleFading(duration,1,0);},crossFadeFrom:function crossFadeFrom(fadeOutAction,duration,warp){fadeOutAction.fadeOut(duration);this.fadeIn(duration);if(warp){var fadeInDuration=this._clip.duration,fadeOutDuration=fadeOutAction._clip.duration,startEndRatio=fadeOutDuration/fadeInDuration,endStartRatio=fadeInDuration/fadeOutDuration;fadeOutAction.warp(1.0,startEndRatio,duration);this.warp(endStartRatio,1.0,duration);}return this;},crossFadeTo:function crossFadeTo(fadeInAction,duration,warp){return fadeInAction.crossFadeFrom(this,duration,warp);},stopFading:function stopFading(){var weightInterpolant=this._weightInterpolant;if(weightInterpolant!==null){this._weightInterpolant=null;this._mixer._takeBackControlInterpolant(weightInterpolant);}return this;},// Time Scale Control
|
3387 | // set the time scale stopping any scheduled warping
|
3388 | // although .paused = true yields an effective time scale of zero, this
|
3389 | // method does *not* change .paused, because it would be confusing
|
3390 | setEffectiveTimeScale:function setEffectiveTimeScale(timeScale){this.timeScale=timeScale;this._effectiveTimeScale=this.paused?0:timeScale;return this.stopWarping();},// return the time scale considering warping and .paused
|
3391 | getEffectiveTimeScale:function getEffectiveTimeScale(){return this._effectiveTimeScale;},setDuration:function setDuration(duration){this.timeScale=this._clip.duration/duration;return this.stopWarping();},syncWith:function syncWith(action){this.time=action.time;this.timeScale=action.timeScale;return this.stopWarping();},halt:function halt(duration){return this.warp(this._effectiveTimeScale,0,duration);},warp:function warp(startTimeScale,endTimeScale,duration){var mixer=this._mixer,now=mixer.time,interpolant=this._timeScaleInterpolant,timeScale=this.timeScale;if(interpolant===null){interpolant=mixer._lendControlInterpolant();this._timeScaleInterpolant=interpolant;}var times=interpolant.parameterPositions,values=interpolant.sampleValues;times[0]=now;times[1]=now+duration;values[0]=startTimeScale/timeScale;values[1]=endTimeScale/timeScale;return this;},stopWarping:function stopWarping(){var timeScaleInterpolant=this._timeScaleInterpolant;if(timeScaleInterpolant!==null){this._timeScaleInterpolant=null;this._mixer._takeBackControlInterpolant(timeScaleInterpolant);}return this;},// Object Accessors
|
3392 | getMixer:function getMixer(){return this._mixer;},getClip:function getClip(){return this._clip;},getRoot:function getRoot(){return this._localRoot||this._mixer._root;},// Interna
|
3393 | _update:function _update(time,deltaTime,timeDirection,accuIndex){// called by the mixer
|
3394 | if(!this.enabled){// call ._updateWeight() to update ._effectiveWeight
|
3395 | this._updateWeight(time);return;}var startTime=this._startTime;if(startTime!==null){// check for scheduled start of action
|
3396 | var timeRunning=(time-startTime)*timeDirection;if(timeRunning<0||timeDirection===0){return;// yet to come / don't decide when delta = 0
|
3397 | }// start
|
3398 | this._startTime=null;// unschedule
|
3399 | deltaTime=timeDirection*timeRunning;}// apply time scale and advance time
|
3400 | deltaTime*=this._updateTimeScale(time);var clipTime=this._updateTime(deltaTime);// note: _updateTime may disable the action resulting in
|
3401 | // an effective weight of 0
|
3402 | var weight=this._updateWeight(time);if(weight>0){var interpolants=this._interpolants;var propertyMixers=this._propertyBindings;switch(this.blendMode){case AdditiveAnimationBlendMode:for(var j=0,m=interpolants.length;j!==m;++j){interpolants[j].evaluate(clipTime);propertyMixers[j].accumulateAdditive(weight);}break;case NormalAnimationBlendMode:default:for(var j=0,m=interpolants.length;j!==m;++j){interpolants[j].evaluate(clipTime);propertyMixers[j].accumulate(accuIndex,weight);}}}},_updateWeight:function _updateWeight(time){var weight=0;if(this.enabled){weight=this.weight;var interpolant=this._weightInterpolant;if(interpolant!==null){var interpolantValue=interpolant.evaluate(time)[0];weight*=interpolantValue;if(time>interpolant.parameterPositions[1]){this.stopFading();if(interpolantValue===0){// faded out, disable
|
3403 | this.enabled=false;}}}}this._effectiveWeight=weight;return weight;},_updateTimeScale:function _updateTimeScale(time){var timeScale=0;if(!this.paused){timeScale=this.timeScale;var interpolant=this._timeScaleInterpolant;if(interpolant!==null){var interpolantValue=interpolant.evaluate(time)[0];timeScale*=interpolantValue;if(time>interpolant.parameterPositions[1]){this.stopWarping();if(timeScale===0){// motion has halted, pause
|
3404 | this.paused=true;}else {// warp done - apply final time scale
|
3405 | this.timeScale=timeScale;}}}}this._effectiveTimeScale=timeScale;return timeScale;},_updateTime:function _updateTime(deltaTime){var time=this.time+deltaTime;var duration=this._clip.duration;var loop=this.loop;var loopCount=this._loopCount;var pingPong=loop===LoopPingPong;if(deltaTime===0){if(loopCount===-1)return time;return pingPong&&(loopCount&1)===1?duration-time:time;}if(loop===LoopOnce){if(loopCount===-1){// just started
|
3406 | this._loopCount=0;this._setEndings(true,true,false);}handle_stop:{if(time>=duration){time=duration;}else if(time<0){time=0;}else {this.time=time;break handle_stop;}if(this.clampWhenFinished)this.paused=true;else this.enabled=false;this.time=time;this._mixer.dispatchEvent({type:'finished',action:this,direction:deltaTime<0?-1:1});}}else {// repetitive Repeat or PingPong
|
3407 | if(loopCount===-1){// just started
|
3408 | if(deltaTime>=0){loopCount=0;this._setEndings(true,this.repetitions===0,pingPong);}else {// when looping in reverse direction, the initial
|
3409 | // transition through zero counts as a repetition,
|
3410 | // so leave loopCount at -1
|
3411 | this._setEndings(this.repetitions===0,true,pingPong);}}if(time>=duration||time<0){// wrap around
|
3412 | var loopDelta=Math.floor(time/duration);// signed
|
3413 | time-=duration*loopDelta;loopCount+=Math.abs(loopDelta);var pending=this.repetitions-loopCount;if(pending<=0){// have to stop (switch state, clamp time, fire event)
|
3414 | if(this.clampWhenFinished)this.paused=true;else this.enabled=false;time=deltaTime>0?duration:0;this.time=time;this._mixer.dispatchEvent({type:'finished',action:this,direction:deltaTime>0?1:-1});}else {// keep running
|
3415 | if(pending===1){// entering the last round
|
3416 | var atStart=deltaTime<0;this._setEndings(atStart,!atStart,pingPong);}else {this._setEndings(false,false,pingPong);}this._loopCount=loopCount;this.time=time;this._mixer.dispatchEvent({type:'loop',action:this,loopDelta:loopDelta});}}else {this.time=time;}if(pingPong&&(loopCount&1)===1){// invert time for the "pong round"
|
3417 | return duration-time;}}return time;},_setEndings:function _setEndings(atStart,atEnd,pingPong){var settings=this._interpolantSettings;if(pingPong){settings.endingStart=ZeroSlopeEnding;settings.endingEnd=ZeroSlopeEnding;}else {// assuming for LoopOnce atStart == atEnd == true
|
3418 | if(atStart){settings.endingStart=this.zeroSlopeAtStart?ZeroSlopeEnding:ZeroCurvatureEnding;}else {settings.endingStart=WrapAroundEnding;}if(atEnd){settings.endingEnd=this.zeroSlopeAtEnd?ZeroSlopeEnding:ZeroCurvatureEnding;}else {settings.endingEnd=WrapAroundEnding;}}},_scheduleFading:function _scheduleFading(duration,weightNow,weightThen){var mixer=this._mixer,now=mixer.time,interpolant=this._weightInterpolant;if(interpolant===null){interpolant=mixer._lendControlInterpolant();this._weightInterpolant=interpolant;}var times=interpolant.parameterPositions,values=interpolant.sampleValues;times[0]=now;values[0]=weightNow;times[1]=now+duration;values[1]=weightThen;return this;}});/**
|
3419 | *
|
3420 | * Player for AnimationClips.
|
3421 | *
|
3422 | *
|
3423 | * @author Ben Houston / http://clara.io/
|
3424 | * @author David Sarno / http://lighthaus.us/
|
3425 | * @author tschw
|
3426 | */function AnimationMixer(root){this._root=root;this._initMemoryManager();this._accuIndex=0;this.time=0;this.timeScale=1.0;}AnimationMixer.prototype=_extends(Object.create(EventDispatcher.prototype),{constructor:AnimationMixer,_bindAction:function _bindAction(action,prototypeAction){var root=action._localRoot||this._root,tracks=action._clip.tracks,nTracks=tracks.length,bindings=action._propertyBindings,interpolants=action._interpolants,rootUuid=root.uuid,bindingsByRoot=this._bindingsByRootAndName,bindingsByName=bindingsByRoot[rootUuid];if(bindingsByName===undefined){bindingsByName={};bindingsByRoot[rootUuid]=bindingsByName;}for(var i=0;i!==nTracks;++i){var track=tracks[i],trackName=track.name,binding=bindingsByName[trackName];if(binding!==undefined){bindings[i]=binding;}else {binding=bindings[i];if(binding!==undefined){// existing binding, make sure the cache knows
|
3427 | if(binding._cacheIndex===null){++binding.referenceCount;this._addInactiveBinding(binding,rootUuid,trackName);}continue;}var path=prototypeAction&&prototypeAction._propertyBindings[i].binding.parsedPath;binding=new PropertyMixer(PropertyBinding.create(root,trackName,path),track.ValueTypeName,track.getValueSize());++binding.referenceCount;this._addInactiveBinding(binding,rootUuid,trackName);bindings[i]=binding;}interpolants[i].resultBuffer=binding.buffer;}},_activateAction:function _activateAction(action){if(!this._isActiveAction(action)){if(action._cacheIndex===null){// this action has been forgotten by the cache, but the user
|
3428 | // appears to be still using it -> rebind
|
3429 | var rootUuid=(action._localRoot||this._root).uuid,clipUuid=action._clip.uuid,actionsForClip=this._actionsByClip[clipUuid];this._bindAction(action,actionsForClip&&actionsForClip.knownActions[0]);this._addInactiveAction(action,clipUuid,rootUuid);}var bindings=action._propertyBindings;// increment reference counts / sort out state
|
3430 | for(var i=0,n=bindings.length;i!==n;++i){var binding=bindings[i];if(binding.useCount++===0){this._lendBinding(binding);binding.saveOriginalState();}}this._lendAction(action);}},_deactivateAction:function _deactivateAction(action){if(this._isActiveAction(action)){var bindings=action._propertyBindings;// decrement reference counts / sort out state
|
3431 | for(var i=0,n=bindings.length;i!==n;++i){var binding=bindings[i];if(--binding.useCount===0){binding.restoreOriginalState();this._takeBackBinding(binding);}}this._takeBackAction(action);}},// Memory manager
|
3432 | _initMemoryManager:function _initMemoryManager(){this._actions=[];// 'nActiveActions' followed by inactive ones
|
3433 | this._nActiveActions=0;this._actionsByClip={};// inside:
|
3434 | // {
|
3435 | // knownActions: Array< AnimationAction > - used as prototypes
|
3436 | // actionByRoot: AnimationAction - lookup
|
3437 | // }
|
3438 | this._bindings=[];// 'nActiveBindings' followed by inactive ones
|
3439 | this._nActiveBindings=0;this._bindingsByRootAndName={};// inside: Map< name, PropertyMixer >
|
3440 | this._controlInterpolants=[];// same game as above
|
3441 | this._nActiveControlInterpolants=0;var scope=this;this.stats={actions:{get total(){return scope._actions.length;},get inUse(){return scope._nActiveActions;}},bindings:{get total(){return scope._bindings.length;},get inUse(){return scope._nActiveBindings;}},controlInterpolants:{get total(){return scope._controlInterpolants.length;},get inUse(){return scope._nActiveControlInterpolants;}}};},// Memory management for AnimationAction objects
|
3442 | _isActiveAction:function _isActiveAction(action){var index=action._cacheIndex;return index!==null&&index<this._nActiveActions;},_addInactiveAction:function _addInactiveAction(action,clipUuid,rootUuid){var actions=this._actions,actionsByClip=this._actionsByClip,actionsForClip=actionsByClip[clipUuid];if(actionsForClip===undefined){actionsForClip={knownActions:[action],actionByRoot:{}};action._byClipCacheIndex=0;actionsByClip[clipUuid]=actionsForClip;}else {var knownActions=actionsForClip.knownActions;action._byClipCacheIndex=knownActions.length;knownActions.push(action);}action._cacheIndex=actions.length;actions.push(action);actionsForClip.actionByRoot[rootUuid]=action;},_removeInactiveAction:function _removeInactiveAction(action){var actions=this._actions,lastInactiveAction=actions[actions.length-1],cacheIndex=action._cacheIndex;lastInactiveAction._cacheIndex=cacheIndex;actions[cacheIndex]=lastInactiveAction;actions.pop();action._cacheIndex=null;var clipUuid=action._clip.uuid,actionsByClip=this._actionsByClip,actionsForClip=actionsByClip[clipUuid],knownActionsForClip=actionsForClip.knownActions,lastKnownAction=knownActionsForClip[knownActionsForClip.length-1],byClipCacheIndex=action._byClipCacheIndex;lastKnownAction._byClipCacheIndex=byClipCacheIndex;knownActionsForClip[byClipCacheIndex]=lastKnownAction;knownActionsForClip.pop();action._byClipCacheIndex=null;var actionByRoot=actionsForClip.actionByRoot,rootUuid=(action._localRoot||this._root).uuid;delete actionByRoot[rootUuid];if(knownActionsForClip.length===0){delete actionsByClip[clipUuid];}this._removeInactiveBindingsForAction(action);},_removeInactiveBindingsForAction:function _removeInactiveBindingsForAction(action){var bindings=action._propertyBindings;for(var i=0,n=bindings.length;i!==n;++i){var binding=bindings[i];if(--binding.referenceCount===0){this._removeInactiveBinding(binding);}}},_lendAction:function _lendAction(action){// [ active actions | inactive actions ]
|
3443 | // [ active actions >| inactive actions ]
|
3444 | // s a
|
3445 | // <-swap->
|
3446 | // a s
|
3447 | var actions=this._actions,prevIndex=action._cacheIndex,lastActiveIndex=this._nActiveActions++,firstInactiveAction=actions[lastActiveIndex];action._cacheIndex=lastActiveIndex;actions[lastActiveIndex]=action;firstInactiveAction._cacheIndex=prevIndex;actions[prevIndex]=firstInactiveAction;},_takeBackAction:function _takeBackAction(action){// [ active actions | inactive actions ]
|
3448 | // [ active actions |< inactive actions ]
|
3449 | // a s
|
3450 | // <-swap->
|
3451 | // s a
|
3452 | var actions=this._actions,prevIndex=action._cacheIndex,firstInactiveIndex=--this._nActiveActions,lastActiveAction=actions[firstInactiveIndex];action._cacheIndex=firstInactiveIndex;actions[firstInactiveIndex]=action;lastActiveAction._cacheIndex=prevIndex;actions[prevIndex]=lastActiveAction;},// Memory management for PropertyMixer objects
|
3453 | _addInactiveBinding:function _addInactiveBinding(binding,rootUuid,trackName){var bindingsByRoot=this._bindingsByRootAndName,bindingByName=bindingsByRoot[rootUuid],bindings=this._bindings;if(bindingByName===undefined){bindingByName={};bindingsByRoot[rootUuid]=bindingByName;}bindingByName[trackName]=binding;binding._cacheIndex=bindings.length;bindings.push(binding);},_removeInactiveBinding:function _removeInactiveBinding(binding){var bindings=this._bindings,propBinding=binding.binding,rootUuid=propBinding.rootNode.uuid,trackName=propBinding.path,bindingsByRoot=this._bindingsByRootAndName,bindingByName=bindingsByRoot[rootUuid],lastInactiveBinding=bindings[bindings.length-1],cacheIndex=binding._cacheIndex;lastInactiveBinding._cacheIndex=cacheIndex;bindings[cacheIndex]=lastInactiveBinding;bindings.pop();delete bindingByName[trackName];if(Object.keys(bindingByName).length===0){delete bindingsByRoot[rootUuid];}},_lendBinding:function _lendBinding(binding){var bindings=this._bindings,prevIndex=binding._cacheIndex,lastActiveIndex=this._nActiveBindings++,firstInactiveBinding=bindings[lastActiveIndex];binding._cacheIndex=lastActiveIndex;bindings[lastActiveIndex]=binding;firstInactiveBinding._cacheIndex=prevIndex;bindings[prevIndex]=firstInactiveBinding;},_takeBackBinding:function _takeBackBinding(binding){var bindings=this._bindings,prevIndex=binding._cacheIndex,firstInactiveIndex=--this._nActiveBindings,lastActiveBinding=bindings[firstInactiveIndex];binding._cacheIndex=firstInactiveIndex;bindings[firstInactiveIndex]=binding;lastActiveBinding._cacheIndex=prevIndex;bindings[prevIndex]=lastActiveBinding;},// Memory management of Interpolants for weight and time scale
|
3454 | _lendControlInterpolant:function _lendControlInterpolant(){var interpolants=this._controlInterpolants,lastActiveIndex=this._nActiveControlInterpolants++,interpolant=interpolants[lastActiveIndex];if(interpolant===undefined){interpolant=new LinearInterpolant(new Float32Array(2),new Float32Array(2),1,this._controlInterpolantsResultBuffer);interpolant.__cacheIndex=lastActiveIndex;interpolants[lastActiveIndex]=interpolant;}return interpolant;},_takeBackControlInterpolant:function _takeBackControlInterpolant(interpolant){var interpolants=this._controlInterpolants,prevIndex=interpolant.__cacheIndex,firstInactiveIndex=--this._nActiveControlInterpolants,lastActiveInterpolant=interpolants[firstInactiveIndex];interpolant.__cacheIndex=firstInactiveIndex;interpolants[firstInactiveIndex]=interpolant;lastActiveInterpolant.__cacheIndex=prevIndex;interpolants[prevIndex]=lastActiveInterpolant;},_controlInterpolantsResultBuffer:new Float32Array(1),// return an action for a clip optionally using a custom root target
|
3455 | // object (this method allocates a lot of dynamic memory in case a
|
3456 | // previously unknown clip/root combination is specified)
|
3457 | clipAction:function clipAction(clip,optionalRoot,blendMode){var root=optionalRoot||this._root,rootUuid=root.uuid,clipObject=typeof clip==='string'?AnimationClip.findByName(root,clip):clip,clipUuid=clipObject!==null?clipObject.uuid:clip,actionsForClip=this._actionsByClip[clipUuid],prototypeAction=null;if(blendMode===undefined){if(clipObject!==null){blendMode=clipObject.blendMode;}else {blendMode=NormalAnimationBlendMode;}}if(actionsForClip!==undefined){var existingAction=actionsForClip.actionByRoot[rootUuid];if(existingAction!==undefined&&existingAction.blendMode===blendMode){return existingAction;}// we know the clip, so we don't have to parse all
|
3458 | // the bindings again but can just copy
|
3459 | prototypeAction=actionsForClip.knownActions[0];// also, take the clip from the prototype action
|
3460 | if(clipObject===null)clipObject=prototypeAction._clip;}// clip must be known when specified via string
|
3461 | if(clipObject===null)return null;// allocate all resources required to run it
|
3462 | var newAction=new AnimationAction(this,clipObject,optionalRoot,blendMode);this._bindAction(newAction,prototypeAction);// and make the action known to the memory manager
|
3463 | this._addInactiveAction(newAction,clipUuid,rootUuid);return newAction;},// get an existing action
|
3464 | existingAction:function existingAction(clip,optionalRoot){var root=optionalRoot||this._root,rootUuid=root.uuid,clipObject=typeof clip==='string'?AnimationClip.findByName(root,clip):clip,clipUuid=clipObject?clipObject.uuid:clip,actionsForClip=this._actionsByClip[clipUuid];if(actionsForClip!==undefined){return actionsForClip.actionByRoot[rootUuid]||null;}return null;},// deactivates all previously scheduled actions
|
3465 | stopAllAction:function stopAllAction(){var actions=this._actions,nActions=this._nActiveActions,bindings=this._bindings,nBindings=this._nActiveBindings;this._nActiveActions=0;this._nActiveBindings=0;for(var i=0;i!==nActions;++i){actions[i].reset();}for(var i=0;i!==nBindings;++i){bindings[i].useCount=0;}return this;},// advance the time and update apply the animation
|
3466 | update:function update(deltaTime){deltaTime*=this.timeScale;var actions=this._actions,nActions=this._nActiveActions,time=this.time+=deltaTime,timeDirection=Math.sign(deltaTime),accuIndex=this._accuIndex^=1;// run active actions
|
3467 | for(var i=0;i!==nActions;++i){var action=actions[i];action._update(time,deltaTime,timeDirection,accuIndex);}// update scene graph
|
3468 | var bindings=this._bindings,nBindings=this._nActiveBindings;for(var i=0;i!==nBindings;++i){bindings[i].apply(accuIndex);}return this;},// Allows you to seek to a specific time in an animation.
|
3469 | setTime:function setTime(timeInSeconds){this.time=0;// Zero out time attribute for AnimationMixer object;
|
3470 | for(var i=0;i<this._actions.length;i++){this._actions[i].time=0;// Zero out time attribute for all associated AnimationAction objects.
|
3471 | }return this.update(timeInSeconds);// Update used to set exact time. Returns "this" AnimationMixer object.
|
3472 | },// return this mixer's root target object
|
3473 | getRoot:function getRoot(){return this._root;},// free all resources specific to a particular clip
|
3474 | uncacheClip:function uncacheClip(clip){var actions=this._actions,clipUuid=clip.uuid,actionsByClip=this._actionsByClip,actionsForClip=actionsByClip[clipUuid];if(actionsForClip!==undefined){// note: just calling _removeInactiveAction would mess up the
|
3475 | // iteration state and also require updating the state we can
|
3476 | // just throw away
|
3477 | var actionsToRemove=actionsForClip.knownActions;for(var i=0,n=actionsToRemove.length;i!==n;++i){var action=actionsToRemove[i];this._deactivateAction(action);var cacheIndex=action._cacheIndex,lastInactiveAction=actions[actions.length-1];action._cacheIndex=null;action._byClipCacheIndex=null;lastInactiveAction._cacheIndex=cacheIndex;actions[cacheIndex]=lastInactiveAction;actions.pop();this._removeInactiveBindingsForAction(action);}delete actionsByClip[clipUuid];}},// free all resources specific to a particular root target object
|
3478 | uncacheRoot:function uncacheRoot(root){var rootUuid=root.uuid,actionsByClip=this._actionsByClip;for(var clipUuid in actionsByClip){var actionByRoot=actionsByClip[clipUuid].actionByRoot,action=actionByRoot[rootUuid];if(action!==undefined){this._deactivateAction(action);this._removeInactiveAction(action);}}var bindingsByRoot=this._bindingsByRootAndName,bindingByName=bindingsByRoot[rootUuid];if(bindingByName!==undefined){for(var trackName in bindingByName){var binding=bindingByName[trackName];binding.restoreOriginalState();this._removeInactiveBinding(binding);}}},// remove a targeted clip from the cache
|
3479 | uncacheAction:function uncacheAction(clip,optionalRoot){var action=this.existingAction(clip,optionalRoot);if(action!==null){this._deactivateAction(action);this._removeInactiveAction(action);}}});/**
|
3480 | * @author mrdoob / http://mrdoob.com/
|
3481 | */function Uniform(value){if(typeof value==='string'){console.warn('THREE.Uniform: Type parameter is no longer needed.');value=arguments[1];}this.value=value;}Uniform.prototype.clone=function(){return new Uniform(this.value.clone===undefined?this.value:this.value.clone());};/**
|
3482 | * @author benaadams / https://twitter.com/ben_a_adams
|
3483 | */function InstancedInterleavedBuffer(array,stride,meshPerAttribute){InterleavedBuffer.call(this,array,stride);this.meshPerAttribute=meshPerAttribute||1;}InstancedInterleavedBuffer.prototype=_extends(Object.create(InterleavedBuffer.prototype),{constructor:InstancedInterleavedBuffer,isInstancedInterleavedBuffer:true,copy:function copy(source){InterleavedBuffer.prototype.copy.call(this,source);this.meshPerAttribute=source.meshPerAttribute;return this;}});/**
|
3484 | * @author mrdoob / http://mrdoob.com/
|
3485 | * @author bhouston / http://clara.io/
|
3486 | * @author stephomi / http://stephaneginier.com/
|
3487 | */function Raycaster(origin,direction,near,far){this.ray=new Ray(origin,direction);// direction is assumed to be normalized (for accurate distance calculations)
|
3488 | this.near=near||0;this.far=far||Infinity;this.camera=null;this.layers=new Layers();this.params={Mesh:{},Line:{threshold:1},LOD:{},Points:{threshold:1},Sprite:{}};Object.defineProperties(this.params,{PointCloud:{get:function get(){console.warn('THREE.Raycaster: params.PointCloud has been renamed to params.Points.');return this.Points;}}});}function ascSort(a,b){return a.distance-b.distance;}function _intersectObject(object,raycaster,intersects,recursive){if(object.layers.test(raycaster.layers)){object.raycast(raycaster,intersects);}if(recursive===true){var children=object.children;for(var i=0,l=children.length;i<l;i++){_intersectObject(children[i],raycaster,intersects,true);}}}_extends(Raycaster.prototype,{set:function set(origin,direction){// direction is assumed to be normalized (for accurate distance calculations)
|
3489 | this.ray.set(origin,direction);},setFromCamera:function setFromCamera(coords,camera){if(camera&&camera.isPerspectiveCamera){this.ray.origin.setFromMatrixPosition(camera.matrixWorld);this.ray.direction.set(coords.x,coords.y,0.5).unproject(camera).sub(this.ray.origin).normalize();this.camera=camera;}else if(camera&&camera.isOrthographicCamera){this.ray.origin.set(coords.x,coords.y,(camera.near+camera.far)/(camera.near-camera.far)).unproject(camera);// set origin in plane of camera
|
3490 | this.ray.direction.set(0,0,-1).transformDirection(camera.matrixWorld);this.camera=camera;}else {console.error('THREE.Raycaster: Unsupported camera type.');}},intersectObject:function intersectObject(object,recursive,optionalTarget){var intersects=optionalTarget||[];_intersectObject(object,this,intersects,recursive);intersects.sort(ascSort);return intersects;},intersectObjects:function intersectObjects(objects,recursive,optionalTarget){var intersects=optionalTarget||[];if(Array.isArray(objects)===false){console.warn('THREE.Raycaster.intersectObjects: objects is not an Array.');return intersects;}for(var i=0,l=objects.length;i<l;i++){_intersectObject(objects[i],this,intersects,recursive);}intersects.sort(ascSort);return intersects;}});/**
|
3491 | * @author bhouston / http://clara.io
|
3492 | * @author WestLangley / http://github.com/WestLangley
|
3493 | *
|
3494 | * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
|
3495 | *
|
3496 | * The polar angle (phi) is measured from the positive y-axis. The positive y-axis is up.
|
3497 | * The azimuthal angle (theta) is measured from the positive z-axis.
|
3498 | */function Spherical(radius,phi,theta){this.radius=radius!==undefined?radius:1.0;this.phi=phi!==undefined?phi:0;// polar angle
|
3499 | this.theta=theta!==undefined?theta:0;// azimuthal angle
|
3500 | return this;}_extends(Spherical.prototype,{set:function set(radius,phi,theta){this.radius=radius;this.phi=phi;this.theta=theta;return this;},clone:function clone(){return new this.constructor().copy(this);},copy:function copy(other){this.radius=other.radius;this.phi=other.phi;this.theta=other.theta;return this;},// restrict phi to be betwee EPS and PI-EPS
|
3501 | makeSafe:function makeSafe(){var EPS=0.000001;this.phi=Math.max(EPS,Math.min(Math.PI-EPS,this.phi));return this;},setFromVector3:function setFromVector3(v){return this.setFromCartesianCoords(v.x,v.y,v.z);},setFromCartesianCoords:function setFromCartesianCoords(x,y,z){this.radius=Math.sqrt(x*x+y*y+z*z);if(this.radius===0){this.theta=0;this.phi=0;}else {this.theta=Math.atan2(x,z);this.phi=Math.acos(MathUtils.clamp(y/this.radius,-1,1));}return this;}});/**
|
3502 | * @author Mugen87 / https://github.com/Mugen87
|
3503 | *
|
3504 | * Ref: https://en.wikipedia.org/wiki/Cylindrical_coordinate_system
|
3505 | *
|
3506 | */function Cylindrical(radius,theta,y){this.radius=radius!==undefined?radius:1.0;// distance from the origin to a point in the x-z plane
|
3507 | this.theta=theta!==undefined?theta:0;// counterclockwise angle in the x-z plane measured in radians from the positive z-axis
|
3508 | this.y=y!==undefined?y:0;// height above the x-z plane
|
3509 | return this;}_extends(Cylindrical.prototype,{set:function set(radius,theta,y){this.radius=radius;this.theta=theta;this.y=y;return this;},clone:function clone(){return new this.constructor().copy(this);},copy:function copy(other){this.radius=other.radius;this.theta=other.theta;this.y=other.y;return this;},setFromVector3:function setFromVector3(v){return this.setFromCartesianCoords(v.x,v.y,v.z);},setFromCartesianCoords:function setFromCartesianCoords(x,y,z){this.radius=Math.sqrt(x*x+z*z);this.theta=Math.atan2(x,z);this.y=y;return this;}});/**
|
3510 | * @author bhouston / http://clara.io
|
3511 | */var _vector$7=new Vector2();function Box2(min,max){this.min=min!==undefined?min:new Vector2(+Infinity,+Infinity);this.max=max!==undefined?max:new Vector2(-Infinity,-Infinity);}_extends(Box2.prototype,{set:function set(min,max){this.min.copy(min);this.max.copy(max);return this;},setFromPoints:function setFromPoints(points){this.makeEmpty();for(var i=0,il=points.length;i<il;i++){this.expandByPoint(points[i]);}return this;},setFromCenterAndSize:function setFromCenterAndSize(center,size){var halfSize=_vector$7.copy(size).multiplyScalar(0.5);this.min.copy(center).sub(halfSize);this.max.copy(center).add(halfSize);return this;},clone:function clone(){return new this.constructor().copy(this);},copy:function copy(box){this.min.copy(box.min);this.max.copy(box.max);return this;},makeEmpty:function makeEmpty(){this.min.x=this.min.y=+Infinity;this.max.x=this.max.y=-Infinity;return this;},isEmpty:function isEmpty(){// this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
|
3512 | return this.max.x<this.min.x||this.max.y<this.min.y;},getCenter:function getCenter(target){if(target===undefined){console.warn('THREE.Box2: .getCenter() target is now required');target=new Vector2();}return this.isEmpty()?target.set(0,0):target.addVectors(this.min,this.max).multiplyScalar(0.5);},getSize:function getSize(target){if(target===undefined){console.warn('THREE.Box2: .getSize() target is now required');target=new Vector2();}return this.isEmpty()?target.set(0,0):target.subVectors(this.max,this.min);},expandByPoint:function expandByPoint(point){this.min.min(point);this.max.max(point);return this;},expandByVector:function expandByVector(vector){this.min.sub(vector);this.max.add(vector);return this;},expandByScalar:function expandByScalar(scalar){this.min.addScalar(-scalar);this.max.addScalar(scalar);return this;},containsPoint:function containsPoint(point){return point.x<this.min.x||point.x>this.max.x||point.y<this.min.y||point.y>this.max.y?false:true;},containsBox:function containsBox(box){return this.min.x<=box.min.x&&box.max.x<=this.max.x&&this.min.y<=box.min.y&&box.max.y<=this.max.y;},getParameter:function getParameter(point,target){// This can potentially have a divide by zero if the box
|
3513 | // has a size dimension of 0.
|
3514 | if(target===undefined){console.warn('THREE.Box2: .getParameter() target is now required');target=new Vector2();}return target.set((point.x-this.min.x)/(this.max.x-this.min.x),(point.y-this.min.y)/(this.max.y-this.min.y));},intersectsBox:function intersectsBox(box){// using 4 splitting planes to rule out intersections
|
3515 | return box.max.x<this.min.x||box.min.x>this.max.x||box.max.y<this.min.y||box.min.y>this.max.y?false:true;},clampPoint:function clampPoint(point,target){if(target===undefined){console.warn('THREE.Box2: .clampPoint() target is now required');target=new Vector2();}return target.copy(point).clamp(this.min,this.max);},distanceToPoint:function distanceToPoint(point){var clampedPoint=_vector$7.copy(point).clamp(this.min,this.max);return clampedPoint.sub(point).length();},intersect:function intersect(box){this.min.max(box.min);this.max.min(box.max);return this;},union:function union(box){this.min.min(box.min);this.max.max(box.max);return this;},translate:function translate(offset){this.min.add(offset);this.max.add(offset);return this;},equals:function equals(box){return box.min.equals(this.min)&&box.max.equals(this.max);}});/**
|
3516 | * @author bhouston / http://clara.io
|
3517 | */var _startP=new Vector3();var _startEnd=new Vector3();function Line3(start,end){this.start=start!==undefined?start:new Vector3();this.end=end!==undefined?end:new Vector3();}_extends(Line3.prototype,{set:function set(start,end){this.start.copy(start);this.end.copy(end);return this;},clone:function clone(){return new this.constructor().copy(this);},copy:function copy(line){this.start.copy(line.start);this.end.copy(line.end);return this;},getCenter:function getCenter(target){if(target===undefined){console.warn('THREE.Line3: .getCenter() target is now required');target=new Vector3();}return target.addVectors(this.start,this.end).multiplyScalar(0.5);},delta:function delta(target){if(target===undefined){console.warn('THREE.Line3: .delta() target is now required');target=new Vector3();}return target.subVectors(this.end,this.start);},distanceSq:function distanceSq(){return this.start.distanceToSquared(this.end);},distance:function distance(){return this.start.distanceTo(this.end);},at:function at(t,target){if(target===undefined){console.warn('THREE.Line3: .at() target is now required');target=new Vector3();}return this.delta(target).multiplyScalar(t).add(this.start);},closestPointToPointParameter:function closestPointToPointParameter(point,clampToLine){_startP.subVectors(point,this.start);_startEnd.subVectors(this.end,this.start);var startEnd2=_startEnd.dot(_startEnd);var startEnd_startP=_startEnd.dot(_startP);var t=startEnd_startP/startEnd2;if(clampToLine){t=MathUtils.clamp(t,0,1);}return t;},closestPointToPoint:function closestPointToPoint(point,clampToLine,target){var t=this.closestPointToPointParameter(point,clampToLine);if(target===undefined){console.warn('THREE.Line3: .closestPointToPoint() target is now required');target=new Vector3();}return this.delta(target).multiplyScalar(t).add(this.start);},applyMatrix4:function applyMatrix4(matrix){this.start.applyMatrix4(matrix);this.end.applyMatrix4(matrix);return this;},equals:function equals(line){return line.start.equals(this.start)&&line.end.equals(this.end);}});/**
|
3518 | * @author alteredq / http://alteredqualia.com/
|
3519 | */function ImmediateRenderObject(material){Object3D.call(this);this.material=material;this.render=function()/* renderCallback */{};}ImmediateRenderObject.prototype=Object.create(Object3D.prototype);ImmediateRenderObject.prototype.constructor=ImmediateRenderObject;ImmediateRenderObject.prototype.isImmediateRenderObject=true;/**
|
3520 | * @author alteredq / http://alteredqualia.com/
|
3521 | * @author mrdoob / http://mrdoob.com/
|
3522 | * @author WestLangley / http://github.com/WestLangley
|
3523 | */var _vector$8=new Vector3();function SpotLightHelper(light,color){Object3D.call(this);this.light=light;this.light.updateMatrixWorld();this.matrix=light.matrixWorld;this.matrixAutoUpdate=false;this.color=color;var geometry=new BufferGeometry();var positions=[0,0,0,0,0,1,0,0,0,1,0,1,0,0,0,-1,0,1,0,0,0,0,1,1,0,0,0,0,-1,1];for(var i=0,j=1,l=32;i<l;i++,j++){var p1=i/l*Math.PI*2;var p2=j/l*Math.PI*2;positions.push(Math.cos(p1),Math.sin(p1),1,Math.cos(p2),Math.sin(p2),1);}geometry.setAttribute('position',new Float32BufferAttribute(positions,3));var material=new LineBasicMaterial({fog:false,toneMapped:false});this.cone=new LineSegments(geometry,material);this.add(this.cone);this.update();}SpotLightHelper.prototype=Object.create(Object3D.prototype);SpotLightHelper.prototype.constructor=SpotLightHelper;SpotLightHelper.prototype.dispose=function(){this.cone.geometry.dispose();this.cone.material.dispose();};SpotLightHelper.prototype.update=function(){this.light.updateMatrixWorld();var coneLength=this.light.distance?this.light.distance:1000;var coneWidth=coneLength*Math.tan(this.light.angle);this.cone.scale.set(coneWidth,coneWidth,coneLength);_vector$8.setFromMatrixPosition(this.light.target.matrixWorld);this.cone.lookAt(_vector$8);if(this.color!==undefined){this.cone.material.color.set(this.color);}else {this.cone.material.color.copy(this.light.color);}};/**
|
3524 | * @author Sean Griffin / http://twitter.com/sgrif
|
3525 | * @author Michael Guerrero / http://realitymeltdown.com
|
3526 | * @author mrdoob / http://mrdoob.com/
|
3527 | * @author ikerr / http://verold.com
|
3528 | * @author Mugen87 / https://github.com/Mugen87
|
3529 | */var _vector$9=new Vector3();var _boneMatrix=new Matrix4();var _matrixWorldInv=new Matrix4();function getBoneList(object){var boneList=[];if(object&&object.isBone){boneList.push(object);}for(var i=0;i<object.children.length;i++){boneList.push.apply(boneList,getBoneList(object.children[i]));}return boneList;}function SkeletonHelper(object){var bones=getBoneList(object);var geometry=new BufferGeometry();var vertices=[];var colors=[];var color1=new Color(0,0,1);var color2=new Color(0,1,0);for(var i=0;i<bones.length;i++){var bone=bones[i];if(bone.parent&&bone.parent.isBone){vertices.push(0,0,0);vertices.push(0,0,0);colors.push(color1.r,color1.g,color1.b);colors.push(color2.r,color2.g,color2.b);}}geometry.setAttribute('position',new Float32BufferAttribute(vertices,3));geometry.setAttribute('color',new Float32BufferAttribute(colors,3));var material=new LineBasicMaterial({vertexColors:true,depthTest:false,depthWrite:false,toneMapped:false,transparent:true});LineSegments.call(this,geometry,material);this.type='SkeletonHelper';this.root=object;this.bones=bones;this.matrix=object.matrixWorld;this.matrixAutoUpdate=false;}SkeletonHelper.prototype=Object.create(LineSegments.prototype);SkeletonHelper.prototype.constructor=SkeletonHelper;SkeletonHelper.prototype.isSkeletonHelper=true;SkeletonHelper.prototype.updateMatrixWorld=function(force){var bones=this.bones;var geometry=this.geometry;var position=geometry.getAttribute('position');_matrixWorldInv.getInverse(this.root.matrixWorld);for(var i=0,j=0;i<bones.length;i++){var bone=bones[i];if(bone.parent&&bone.parent.isBone){_boneMatrix.multiplyMatrices(_matrixWorldInv,bone.matrixWorld);_vector$9.setFromMatrixPosition(_boneMatrix);position.setXYZ(j,_vector$9.x,_vector$9.y,_vector$9.z);_boneMatrix.multiplyMatrices(_matrixWorldInv,bone.parent.matrixWorld);_vector$9.setFromMatrixPosition(_boneMatrix);position.setXYZ(j+1,_vector$9.x,_vector$9.y,_vector$9.z);j+=2;}}geometry.getAttribute('position').needsUpdate=true;Object3D.prototype.updateMatrixWorld.call(this,force);};/**
|
3530 | * @author alteredq / http://alteredqualia.com/
|
3531 | * @author mrdoob / http://mrdoob.com/
|
3532 | */function PointLightHelper(light,sphereSize,color){this.light=light;this.light.updateMatrixWorld();this.color=color;var geometry=new SphereBufferGeometry(sphereSize,4,2);var material=new MeshBasicMaterial({wireframe:true,fog:false,toneMapped:false});Mesh.call(this,geometry,material);this.type='PointLightHelper';this.matrix=this.light.matrixWorld;this.matrixAutoUpdate=false;this.update();/*
|
3533 | var distanceGeometry = new THREE.IcosahedronBufferGeometry( 1, 2 );
|
3534 | var distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
|
3535 |
|
3536 | this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
|
3537 | this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
|
3538 |
|
3539 | var d = light.distance;
|
3540 |
|
3541 | if ( d === 0.0 ) {
|
3542 |
|
3543 | this.lightDistance.visible = false;
|
3544 |
|
3545 | } else {
|
3546 |
|
3547 | this.lightDistance.scale.set( d, d, d );
|
3548 |
|
3549 | }
|
3550 |
|
3551 | this.add( this.lightDistance );
|
3552 | */}PointLightHelper.prototype=Object.create(Mesh.prototype);PointLightHelper.prototype.constructor=PointLightHelper;PointLightHelper.prototype.dispose=function(){this.geometry.dispose();this.material.dispose();};PointLightHelper.prototype.update=function(){if(this.color!==undefined){this.material.color.set(this.color);}else {this.material.color.copy(this.light.color);}/*
|
3553 | var d = this.light.distance;
|
3554 |
|
3555 | if ( d === 0.0 ) {
|
3556 |
|
3557 | this.lightDistance.visible = false;
|
3558 |
|
3559 | } else {
|
3560 |
|
3561 | this.lightDistance.visible = true;
|
3562 | this.lightDistance.scale.set( d, d, d );
|
3563 |
|
3564 | }
|
3565 | */};/**
|
3566 | * @author alteredq / http://alteredqualia.com/
|
3567 | * @author mrdoob / http://mrdoob.com/
|
3568 | * @author Mugen87 / https://github.com/Mugen87
|
3569 | */var _vector$a=new Vector3();var _color1=new Color();var _color2=new Color();function HemisphereLightHelper(light,size,color){Object3D.call(this);this.light=light;this.light.updateMatrixWorld();this.matrix=light.matrixWorld;this.matrixAutoUpdate=false;this.color=color;var geometry=new OctahedronBufferGeometry(size);geometry.rotateY(Math.PI*0.5);this.material=new MeshBasicMaterial({wireframe:true,fog:false,toneMapped:false});if(this.color===undefined)this.material.vertexColors=true;var position=geometry.getAttribute('position');var colors=new Float32Array(position.count*3);geometry.setAttribute('color',new BufferAttribute(colors,3));this.add(new Mesh(geometry,this.material));this.update();}HemisphereLightHelper.prototype=Object.create(Object3D.prototype);HemisphereLightHelper.prototype.constructor=HemisphereLightHelper;HemisphereLightHelper.prototype.dispose=function(){this.children[0].geometry.dispose();this.children[0].material.dispose();};HemisphereLightHelper.prototype.update=function(){var mesh=this.children[0];if(this.color!==undefined){this.material.color.set(this.color);}else {var colors=mesh.geometry.getAttribute('color');_color1.copy(this.light.color);_color2.copy(this.light.groundColor);for(var i=0,l=colors.count;i<l;i++){var color=i<l/2?_color1:_color2;colors.setXYZ(i,color.r,color.g,color.b);}colors.needsUpdate=true;}mesh.lookAt(_vector$a.setFromMatrixPosition(this.light.matrixWorld).negate());};/**
|
3570 | * @author mrdoob / http://mrdoob.com/
|
3571 | */function GridHelper(size,divisions,color1,color2){size=size||10;divisions=divisions||10;color1=new Color(color1!==undefined?color1:0x444444);color2=new Color(color2!==undefined?color2:0x888888);var center=divisions/2;var step=size/divisions;var halfSize=size/2;var vertices=[],colors=[];for(var i=0,j=0,k=-halfSize;i<=divisions;i++,k+=step){vertices.push(-halfSize,0,k,halfSize,0,k);vertices.push(k,0,-halfSize,k,0,halfSize);var color=i===center?color1:color2;color.toArray(colors,j);j+=3;color.toArray(colors,j);j+=3;color.toArray(colors,j);j+=3;color.toArray(colors,j);j+=3;}var geometry=new BufferGeometry();geometry.setAttribute('position',new Float32BufferAttribute(vertices,3));geometry.setAttribute('color',new Float32BufferAttribute(colors,3));var material=new LineBasicMaterial({vertexColors:true,toneMapped:false});LineSegments.call(this,geometry,material);this.type='GridHelper';}GridHelper.prototype=_extends(Object.create(LineSegments.prototype),{constructor:GridHelper,copy:function copy(source){LineSegments.prototype.copy.call(this,source);this.geometry.copy(source.geometry);this.material.copy(source.material);return this;},clone:function clone(){return new this.constructor().copy(this);}});/**
|
3572 | * @author mrdoob / http://mrdoob.com/
|
3573 | * @author Mugen87 / http://github.com/Mugen87
|
3574 | * @author Hectate / http://www.github.com/Hectate
|
3575 | */function PolarGridHelper(radius,radials,circles,divisions,color1,color2){radius=radius||10;radials=radials||16;circles=circles||8;divisions=divisions||64;color1=new Color(color1!==undefined?color1:0x444444);color2=new Color(color2!==undefined?color2:0x888888);var vertices=[];var colors=[];var x,z;var v,i,j,r,color;// create the radials
|
3576 | for(i=0;i<=radials;i++){v=i/radials*(Math.PI*2);x=Math.sin(v)*radius;z=Math.cos(v)*radius;vertices.push(0,0,0);vertices.push(x,0,z);color=i&1?color1:color2;colors.push(color.r,color.g,color.b);colors.push(color.r,color.g,color.b);}// create the circles
|
3577 | for(i=0;i<=circles;i++){color=i&1?color1:color2;r=radius-radius/circles*i;for(j=0;j<divisions;j++){// first vertex
|
3578 | v=j/divisions*(Math.PI*2);x=Math.sin(v)*r;z=Math.cos(v)*r;vertices.push(x,0,z);colors.push(color.r,color.g,color.b);// second vertex
|
3579 | v=(j+1)/divisions*(Math.PI*2);x=Math.sin(v)*r;z=Math.cos(v)*r;vertices.push(x,0,z);colors.push(color.r,color.g,color.b);}}var geometry=new BufferGeometry();geometry.setAttribute('position',new Float32BufferAttribute(vertices,3));geometry.setAttribute('color',new Float32BufferAttribute(colors,3));var material=new LineBasicMaterial({vertexColors:true,toneMapped:false});LineSegments.call(this,geometry,material);this.type='PolarGridHelper';}PolarGridHelper.prototype=Object.create(LineSegments.prototype);PolarGridHelper.prototype.constructor=PolarGridHelper;/**
|
3580 | * @author alteredq / http://alteredqualia.com/
|
3581 | * @author mrdoob / http://mrdoob.com/
|
3582 | * @author WestLangley / http://github.com/WestLangley
|
3583 | */var _v1$5=new Vector3();var _v2$3=new Vector3();var _v3$1=new Vector3();function DirectionalLightHelper(light,size,color){Object3D.call(this);this.light=light;this.light.updateMatrixWorld();this.matrix=light.matrixWorld;this.matrixAutoUpdate=false;this.color=color;if(size===undefined)size=1;var geometry=new BufferGeometry();geometry.setAttribute('position',new Float32BufferAttribute([-size,size,0,size,size,0,size,-size,0,-size,-size,0,-size,size,0],3));var material=new LineBasicMaterial({fog:false,toneMapped:false});this.lightPlane=new Line(geometry,material);this.add(this.lightPlane);geometry=new BufferGeometry();geometry.setAttribute('position',new Float32BufferAttribute([0,0,0,0,0,1],3));this.targetLine=new Line(geometry,material);this.add(this.targetLine);this.update();}DirectionalLightHelper.prototype=Object.create(Object3D.prototype);DirectionalLightHelper.prototype.constructor=DirectionalLightHelper;DirectionalLightHelper.prototype.dispose=function(){this.lightPlane.geometry.dispose();this.lightPlane.material.dispose();this.targetLine.geometry.dispose();this.targetLine.material.dispose();};DirectionalLightHelper.prototype.update=function(){_v1$5.setFromMatrixPosition(this.light.matrixWorld);_v2$3.setFromMatrixPosition(this.light.target.matrixWorld);_v3$1.subVectors(_v2$3,_v1$5);this.lightPlane.lookAt(_v2$3);if(this.color!==undefined){this.lightPlane.material.color.set(this.color);this.targetLine.material.color.set(this.color);}else {this.lightPlane.material.color.copy(this.light.color);this.targetLine.material.color.copy(this.light.color);}this.targetLine.lookAt(_v2$3);this.targetLine.scale.z=_v3$1.length();};/**
|
3584 | * @author alteredq / http://alteredqualia.com/
|
3585 | * @author Mugen87 / https://github.com/Mugen87
|
3586 | *
|
3587 | * - shows frustum, line of sight and up of the camera
|
3588 | * - suitable for fast updates
|
3589 | * - based on frustum visualization in lightgl.js shadowmap example
|
3590 | * http://evanw.github.com/lightgl.js/tests/shadowmap.html
|
3591 | */var _vector$b=new Vector3();var _camera=new Camera();function CameraHelper(camera){var geometry=new BufferGeometry();var material=new LineBasicMaterial({color:0xffffff,vertexColors:true,toneMapped:false});var vertices=[];var colors=[];var pointMap={};// colors
|
3592 | var colorFrustum=new Color(0xffaa00);var colorCone=new Color(0xff0000);var colorUp=new Color(0x00aaff);var colorTarget=new Color(0xffffff);var colorCross=new Color(0x333333);// near
|
3593 | addLine('n1','n2',colorFrustum);addLine('n2','n4',colorFrustum);addLine('n4','n3',colorFrustum);addLine('n3','n1',colorFrustum);// far
|
3594 | addLine('f1','f2',colorFrustum);addLine('f2','f4',colorFrustum);addLine('f4','f3',colorFrustum);addLine('f3','f1',colorFrustum);// sides
|
3595 | addLine('n1','f1',colorFrustum);addLine('n2','f2',colorFrustum);addLine('n3','f3',colorFrustum);addLine('n4','f4',colorFrustum);// cone
|
3596 | addLine('p','n1',colorCone);addLine('p','n2',colorCone);addLine('p','n3',colorCone);addLine('p','n4',colorCone);// up
|
3597 | addLine('u1','u2',colorUp);addLine('u2','u3',colorUp);addLine('u3','u1',colorUp);// target
|
3598 | addLine('c','t',colorTarget);addLine('p','c',colorCross);// cross
|
3599 | addLine('cn1','cn2',colorCross);addLine('cn3','cn4',colorCross);addLine('cf1','cf2',colorCross);addLine('cf3','cf4',colorCross);function addLine(a,b,color){addPoint(a,color);addPoint(b,color);}function addPoint(id,color){vertices.push(0,0,0);colors.push(color.r,color.g,color.b);if(pointMap[id]===undefined){pointMap[id]=[];}pointMap[id].push(vertices.length/3-1);}geometry.setAttribute('position',new Float32BufferAttribute(vertices,3));geometry.setAttribute('color',new Float32BufferAttribute(colors,3));LineSegments.call(this,geometry,material);this.type='CameraHelper';this.camera=camera;if(this.camera.updateProjectionMatrix)this.camera.updateProjectionMatrix();this.matrix=camera.matrixWorld;this.matrixAutoUpdate=false;this.pointMap=pointMap;this.update();}CameraHelper.prototype=Object.create(LineSegments.prototype);CameraHelper.prototype.constructor=CameraHelper;CameraHelper.prototype.update=function(){var geometry=this.geometry;var pointMap=this.pointMap;var w=1,h=1;// we need just camera projection matrix inverse
|
3600 | // world matrix must be identity
|
3601 | _camera.projectionMatrixInverse.copy(this.camera.projectionMatrixInverse);// center / target
|
3602 | setPoint('c',pointMap,geometry,_camera,0,0,-1);setPoint('t',pointMap,geometry,_camera,0,0,1);// near
|
3603 | setPoint('n1',pointMap,geometry,_camera,-w,-h,-1);setPoint('n2',pointMap,geometry,_camera,w,-h,-1);setPoint('n3',pointMap,geometry,_camera,-w,h,-1);setPoint('n4',pointMap,geometry,_camera,w,h,-1);// far
|
3604 | setPoint('f1',pointMap,geometry,_camera,-w,-h,1);setPoint('f2',pointMap,geometry,_camera,w,-h,1);setPoint('f3',pointMap,geometry,_camera,-w,h,1);setPoint('f4',pointMap,geometry,_camera,w,h,1);// up
|
3605 | setPoint('u1',pointMap,geometry,_camera,w*0.7,h*1.1,-1);setPoint('u2',pointMap,geometry,_camera,-w*0.7,h*1.1,-1);setPoint('u3',pointMap,geometry,_camera,0,h*2,-1);// cross
|
3606 | setPoint('cf1',pointMap,geometry,_camera,-w,0,1);setPoint('cf2',pointMap,geometry,_camera,w,0,1);setPoint('cf3',pointMap,geometry,_camera,0,-h,1);setPoint('cf4',pointMap,geometry,_camera,0,h,1);setPoint('cn1',pointMap,geometry,_camera,-w,0,-1);setPoint('cn2',pointMap,geometry,_camera,w,0,-1);setPoint('cn3',pointMap,geometry,_camera,0,-h,-1);setPoint('cn4',pointMap,geometry,_camera,0,h,-1);geometry.getAttribute('position').needsUpdate=true;};function setPoint(point,pointMap,geometry,camera,x,y,z){_vector$b.set(x,y,z).unproject(camera);var points=pointMap[point];if(points!==undefined){var position=geometry.getAttribute('position');for(var i=0,l=points.length;i<l;i++){position.setXYZ(points[i],_vector$b.x,_vector$b.y,_vector$b.z);}}}/**
|
3607 | * @author mrdoob / http://mrdoob.com/
|
3608 | * @author Mugen87 / http://github.com/Mugen87
|
3609 | */var _box$3=new Box3();function BoxHelper(object,color){this.object=object;if(color===undefined)color=0xffff00;var indices=new Uint16Array([0,1,1,2,2,3,3,0,4,5,5,6,6,7,7,4,0,4,1,5,2,6,3,7]);var positions=new Float32Array(8*3);var geometry=new BufferGeometry();geometry.setIndex(new BufferAttribute(indices,1));geometry.setAttribute('position',new BufferAttribute(positions,3));LineSegments.call(this,geometry,new LineBasicMaterial({color:color,toneMapped:false}));this.type='BoxHelper';this.matrixAutoUpdate=false;this.update();}BoxHelper.prototype=Object.create(LineSegments.prototype);BoxHelper.prototype.constructor=BoxHelper;BoxHelper.prototype.update=function(object){if(object!==undefined){console.warn('THREE.BoxHelper: .update() has no longer arguments.');}if(this.object!==undefined){_box$3.setFromObject(this.object);}if(_box$3.isEmpty())return;var min=_box$3.min;var max=_box$3.max;/*
|
3610 | 5____4
|
3611 | 1/___0/|
|
3612 | | 6__|_7
|
3613 | 2/___3/
|
3614 |
|
3615 | 0: max.x, max.y, max.z
|
3616 | 1: min.x, max.y, max.z
|
3617 | 2: min.x, min.y, max.z
|
3618 | 3: max.x, min.y, max.z
|
3619 | 4: max.x, max.y, min.z
|
3620 | 5: min.x, max.y, min.z
|
3621 | 6: min.x, min.y, min.z
|
3622 | 7: max.x, min.y, min.z
|
3623 | */var position=this.geometry.attributes.position;var array=position.array;array[0]=max.x;array[1]=max.y;array[2]=max.z;array[3]=min.x;array[4]=max.y;array[5]=max.z;array[6]=min.x;array[7]=min.y;array[8]=max.z;array[9]=max.x;array[10]=min.y;array[11]=max.z;array[12]=max.x;array[13]=max.y;array[14]=min.z;array[15]=min.x;array[16]=max.y;array[17]=min.z;array[18]=min.x;array[19]=min.y;array[20]=min.z;array[21]=max.x;array[22]=min.y;array[23]=min.z;position.needsUpdate=true;this.geometry.computeBoundingSphere();};BoxHelper.prototype.setFromObject=function(object){this.object=object;this.update();return this;};BoxHelper.prototype.copy=function(source){LineSegments.prototype.copy.call(this,source);this.object=source.object;return this;};BoxHelper.prototype.clone=function(){return new this.constructor().copy(this);};/**
|
3624 | * @author WestLangley / http://github.com/WestLangley
|
3625 | */function Box3Helper(box,color){this.type='Box3Helper';this.box=box;color=color||0xffff00;var indices=new Uint16Array([0,1,1,2,2,3,3,0,4,5,5,6,6,7,7,4,0,4,1,5,2,6,3,7]);var positions=[1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,-1,-1,1,-1,-1,-1,-1,1,-1,-1];var geometry=new BufferGeometry();geometry.setIndex(new BufferAttribute(indices,1));geometry.setAttribute('position',new Float32BufferAttribute(positions,3));LineSegments.call(this,geometry,new LineBasicMaterial({color:color,toneMapped:false}));this.type='Box3Helper';this.geometry.computeBoundingSphere();}Box3Helper.prototype=Object.create(LineSegments.prototype);Box3Helper.prototype.constructor=Box3Helper;Box3Helper.prototype.updateMatrixWorld=function(force){var box=this.box;if(box.isEmpty())return;box.getCenter(this.position);box.getSize(this.scale);this.scale.multiplyScalar(0.5);Object3D.prototype.updateMatrixWorld.call(this,force);};/**
|
3626 | * @author WestLangley / http://github.com/WestLangley
|
3627 | */function PlaneHelper(plane,size,hex){this.plane=plane;this.size=size===undefined?1:size;var color=hex!==undefined?hex:0xffff00;var positions=[1,-1,1,-1,1,1,-1,-1,1,1,1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,0,0,1,0,0,0];var geometry=new BufferGeometry();geometry.setAttribute('position',new Float32BufferAttribute(positions,3));geometry.computeBoundingSphere();Line.call(this,geometry,new LineBasicMaterial({color:color,toneMapped:false}));this.type='PlaneHelper';//
|
3628 | var positions2=[1,1,1,-1,1,1,-1,-1,1,1,1,1,-1,-1,1,1,-1,1];var geometry2=new BufferGeometry();geometry2.setAttribute('position',new Float32BufferAttribute(positions2,3));geometry2.computeBoundingSphere();this.add(new Mesh(geometry2,new MeshBasicMaterial({color:color,opacity:0.2,transparent:true,depthWrite:false,toneMapped:false})));}PlaneHelper.prototype=Object.create(Line.prototype);PlaneHelper.prototype.constructor=PlaneHelper;PlaneHelper.prototype.updateMatrixWorld=function(force){var scale=-this.plane.constant;if(Math.abs(scale)<1e-8)scale=1e-8;// sign does not matter
|
3629 | this.scale.set(0.5*this.size,0.5*this.size,scale);this.children[0].material.side=scale<0?BackSide:FrontSide;// renderer flips side when determinant < 0; flipping not wanted here
|
3630 | this.lookAt(this.plane.normal);Object3D.prototype.updateMatrixWorld.call(this,force);};/**
|
3631 | * @author WestLangley / http://github.com/WestLangley
|
3632 | * @author zz85 / http://github.com/zz85
|
3633 | * @author bhouston / http://clara.io
|
3634 | *
|
3635 | * Creates an arrow for visualizing directions
|
3636 | *
|
3637 | * Parameters:
|
3638 | * dir - Vector3
|
3639 | * origin - Vector3
|
3640 | * length - Number
|
3641 | * color - color in hex value
|
3642 | * headLength - Number
|
3643 | * headWidth - Number
|
3644 | */var _axis=new Vector3();var _lineGeometry,_coneGeometry;function ArrowHelper(dir,origin,length,color,headLength,headWidth){// dir is assumed to be normalized
|
3645 | Object3D.call(this);this.type='ArrowHelper';if(dir===undefined)dir=new Vector3(0,0,1);if(origin===undefined)origin=new Vector3(0,0,0);if(length===undefined)length=1;if(color===undefined)color=0xffff00;if(headLength===undefined)headLength=0.2*length;if(headWidth===undefined)headWidth=0.2*headLength;if(_lineGeometry===undefined){_lineGeometry=new BufferGeometry();_lineGeometry.setAttribute('position',new Float32BufferAttribute([0,0,0,0,1,0],3));_coneGeometry=new CylinderBufferGeometry(0,0.5,1,5,1);_coneGeometry.translate(0,-0.5,0);}this.position.copy(origin);this.line=new Line(_lineGeometry,new LineBasicMaterial({color:color,toneMapped:false}));this.line.matrixAutoUpdate=false;this.add(this.line);this.cone=new Mesh(_coneGeometry,new MeshBasicMaterial({color:color,toneMapped:false}));this.cone.matrixAutoUpdate=false;this.add(this.cone);this.setDirection(dir);this.setLength(length,headLength,headWidth);}ArrowHelper.prototype=Object.create(Object3D.prototype);ArrowHelper.prototype.constructor=ArrowHelper;ArrowHelper.prototype.setDirection=function(dir){// dir is assumed to be normalized
|
3646 | if(dir.y>0.99999){this.quaternion.set(0,0,0,1);}else if(dir.y<-0.99999){this.quaternion.set(1,0,0,0);}else {_axis.set(dir.z,0,-dir.x).normalize();var radians=Math.acos(dir.y);this.quaternion.setFromAxisAngle(_axis,radians);}};ArrowHelper.prototype.setLength=function(length,headLength,headWidth){if(headLength===undefined)headLength=0.2*length;if(headWidth===undefined)headWidth=0.2*headLength;this.line.scale.set(1,Math.max(0.0001,length-headLength),1);// see #17458
|
3647 | this.line.updateMatrix();this.cone.scale.set(headWidth,headLength,headWidth);this.cone.position.y=length;this.cone.updateMatrix();};ArrowHelper.prototype.setColor=function(color){this.line.material.color.set(color);this.cone.material.color.set(color);};ArrowHelper.prototype.copy=function(source){Object3D.prototype.copy.call(this,source,false);this.line.copy(source.line);this.cone.copy(source.cone);return this;};ArrowHelper.prototype.clone=function(){return new this.constructor().copy(this);};/**
|
3648 | * @author sroucheray / http://sroucheray.org/
|
3649 | * @author mrdoob / http://mrdoob.com/
|
3650 | */function AxesHelper(size){size=size||1;var vertices=[0,0,0,size,0,0,0,0,0,0,size,0,0,0,0,0,0,size];var colors=[1,0,0,1,0.6,0,0,1,0,0.6,1,0,0,0,1,0,0.6,1];var geometry=new BufferGeometry();geometry.setAttribute('position',new Float32BufferAttribute(vertices,3));geometry.setAttribute('color',new Float32BufferAttribute(colors,3));var material=new LineBasicMaterial({vertexColors:true,toneMapped:false});LineSegments.call(this,geometry,material);this.type='AxesHelper';}AxesHelper.prototype=Object.create(LineSegments.prototype);AxesHelper.prototype.constructor=AxesHelper;/**
|
3651 | * @author Emmett Lalish / elalish
|
3652 | *
|
3653 | * This class generates a Prefiltered, Mipmapped Radiance Environment Map
|
3654 | * (PMREM) from a cubeMap environment texture. This allows different levels of
|
3655 | * blur to be quickly accessed based on material roughness. It is packed into a
|
3656 | * special CubeUV format that allows us to perform custom interpolation so that
|
3657 | * we can support nonlinear formats such as RGBE. Unlike a traditional mipmap
|
3658 | * chain, it only goes down to the LOD_MIN level (above), and then creates extra
|
3659 | * even more filtered 'mips' at the same LOD_MIN resolution, associated with
|
3660 | * higher roughness levels. In this way we maintain resolution to smoothly
|
3661 | * interpolate diffuse lighting while limiting sampling computation.
|
3662 | */var LOD_MIN=4;var LOD_MAX=8;var SIZE_MAX=Math.pow(2,LOD_MAX);// The standard deviations (radians) associated with the extra mips. These are
|
3663 | // chosen to approximate a Trowbridge-Reitz distribution function times the
|
3664 | // geometric shadowing function. These sigma values squared must match the
|
3665 | // variance #defines in cube_uv_reflection_fragment.glsl.js.
|
3666 | var EXTRA_LOD_SIGMA=[0.125,0.215,0.35,0.446,0.526,0.582];var TOTAL_LODS=LOD_MAX-LOD_MIN+1+EXTRA_LOD_SIGMA.length;// The maximum length of the blur for loop. Smaller sigmas will use fewer
|
3667 | // samples and exit early, but not recompile the shader.
|
3668 | var MAX_SAMPLES=20;var ENCODINGS=(_ENCODINGS={},_ENCODINGS[LinearEncoding]=0,_ENCODINGS[sRGBEncoding]=1,_ENCODINGS[RGBEEncoding]=2,_ENCODINGS[RGBM7Encoding]=3,_ENCODINGS[RGBM16Encoding]=4,_ENCODINGS[RGBDEncoding]=5,_ENCODINGS[GammaEncoding]=6,_ENCODINGS);var _flatCamera=new OrthographicCamera();var _createPlanes2=_createPlanes(),_lodPlanes=_createPlanes2._lodPlanes,_sizeLods=_createPlanes2._sizeLods,_sigmas=_createPlanes2._sigmas;var _oldTarget=null;// Golden Ratio
|
3669 | var PHI=(1+Math.sqrt(5))/2;var INV_PHI=1/PHI;// Vertices of a dodecahedron (except the opposites, which represent the
|
3670 | // same axis), used as axis directions evenly spread on a sphere.
|
3671 | var _axisDirections=[new Vector3(1,1,1),new Vector3(-1,1,1),new Vector3(1,1,-1),new Vector3(-1,1,-1),new Vector3(0,PHI,INV_PHI),new Vector3(0,PHI,-INV_PHI),new Vector3(INV_PHI,0,PHI),new Vector3(-INV_PHI,0,PHI),new Vector3(PHI,INV_PHI,0),new Vector3(-PHI,INV_PHI,0)];function PMREMGenerator(renderer){this._renderer=renderer;this._pingPongRenderTarget=null;this._blurMaterial=_getBlurShader(MAX_SAMPLES);this._equirectShader=null;this._cubemapShader=null;this._compileMaterial(this._blurMaterial);}PMREMGenerator.prototype={constructor:PMREMGenerator,/**
|
3672 | * Generates a PMREM from a supplied Scene, which can be faster than using an
|
3673 | * image if networking bandwidth is low. Optional sigma specifies a blur radius
|
3674 | * in radians to be applied to the scene before PMREM generation. Optional near
|
3675 | * and far planes ensure the scene is rendered in its entirety (the cubeCamera
|
3676 | * is placed at the origin).
|
3677 | */fromScene:function fromScene(scene,sigma,near,far){if(sigma===void 0){sigma=0;}if(near===void 0){near=0.1;}if(far===void 0){far=100;}_oldTarget=this._renderer.getRenderTarget();var cubeUVRenderTarget=this._allocateTargets();this._sceneToCubeUV(scene,near,far,cubeUVRenderTarget);if(sigma>0){this._blur(cubeUVRenderTarget,0,0,sigma);}this._applyPMREM(cubeUVRenderTarget);this._cleanup(cubeUVRenderTarget);return cubeUVRenderTarget;},/**
|
3678 | * Generates a PMREM from an equirectangular texture, which can be either LDR
|
3679 | * (RGBFormat) or HDR (RGBEFormat). The ideal input image size is 1k (1024 x 512),
|
3680 | * as this matches best with the 256 x 256 cubemap output.
|
3681 | */fromEquirectangular:function fromEquirectangular(equirectangular){equirectangular.magFilter=NearestFilter;equirectangular.minFilter=NearestFilter;equirectangular.generateMipmaps=false;return this.fromCubemap(equirectangular);},/**
|
3682 | * Generates a PMREM from an cubemap texture, which can be either LDR
|
3683 | * (RGBFormat) or HDR (RGBEFormat). The ideal input cube size is 256 x 256,
|
3684 | * as this matches best with the 256 x 256 cubemap output.
|
3685 | */fromCubemap:function fromCubemap(cubemap){_oldTarget=this._renderer.getRenderTarget();var cubeUVRenderTarget=this._allocateTargets(cubemap);this._textureToCubeUV(cubemap,cubeUVRenderTarget);this._applyPMREM(cubeUVRenderTarget);this._cleanup(cubeUVRenderTarget);return cubeUVRenderTarget;},/**
|
3686 | * Pre-compiles the cubemap shader. You can get faster start-up by invoking this method during
|
3687 | * your texture's network fetch for increased concurrency.
|
3688 | */compileCubemapShader:function compileCubemapShader(){if(this._cubemapShader===null){this._cubemapShader=_getCubemapShader();this._compileMaterial(this._cubemapShader);}},/**
|
3689 | * Pre-compiles the equirectangular shader. You can get faster start-up by invoking this method during
|
3690 | * your texture's network fetch for increased concurrency.
|
3691 | */compileEquirectangularShader:function compileEquirectangularShader(){if(this._equirectShader===null){this._equirectShader=_getEquirectShader();this._compileMaterial(this._equirectShader);}},/**
|
3692 | * Disposes of the PMREMGenerator's internal memory. Note that PMREMGenerator is a static class,
|
3693 | * so you should not need more than one PMREMGenerator object. If you do, calling dispose() on
|
3694 | * one of them will cause any others to also become unusable.
|
3695 | */dispose:function dispose(){this._blurMaterial.dispose();if(this._cubemapShader!==null)this._cubemapShader.dispose();if(this._equirectShader!==null)this._equirectShader.dispose();for(var i=0;i<_lodPlanes.length;i++){_lodPlanes[i].dispose();}},// private interface
|
3696 | _cleanup:function _cleanup(outputTarget){this._pingPongRenderTarget.dispose();this._renderer.setRenderTarget(_oldTarget);outputTarget.scissorTest=false;// reset viewport and scissor
|
3697 | outputTarget.setSize(outputTarget.width,outputTarget.height);},_allocateTargets:function _allocateTargets(equirectangular){var params={magFilter:NearestFilter,minFilter:NearestFilter,generateMipmaps:false,type:UnsignedByteType,format:RGBEFormat,encoding:_isLDR(equirectangular)?equirectangular.encoding:RGBEEncoding,depthBuffer:false,stencilBuffer:false};var cubeUVRenderTarget=_createRenderTarget(params);cubeUVRenderTarget.depthBuffer=equirectangular?false:true;this._pingPongRenderTarget=_createRenderTarget(params);return cubeUVRenderTarget;},_compileMaterial:function _compileMaterial(material){var tmpScene=new Scene();tmpScene.add(new Mesh(_lodPlanes[0],material));this._renderer.compile(tmpScene,_flatCamera);},_sceneToCubeUV:function _sceneToCubeUV(scene,near,far,cubeUVRenderTarget){var fov=90;var aspect=1;var cubeCamera=new PerspectiveCamera(fov,aspect,near,far);var upSign=[1,1,1,1,-1,1];var forwardSign=[1,1,-1,-1,-1,1];var renderer=this._renderer;var outputEncoding=renderer.outputEncoding;var toneMapping=renderer.toneMapping;var toneMappingExposure=renderer.toneMappingExposure;var clearColor=renderer.getClearColor();var clearAlpha=renderer.getClearAlpha();renderer.toneMapping=LinearToneMapping;renderer.toneMappingExposure=1.0;renderer.outputEncoding=LinearEncoding;scene.scale.z*=-1;var background=scene.background;if(background&&background.isColor){background.convertSRGBToLinear();// Convert linear to RGBE
|
3698 | var maxComponent=Math.max(background.r,background.g,background.b);var fExp=Math.min(Math.max(Math.ceil(Math.log2(maxComponent)),-128.0),127.0);background=background.multiplyScalar(Math.pow(2.0,-fExp));var alpha=(fExp+128.0)/255.0;renderer.setClearColor(background,alpha);scene.background=null;}for(var i=0;i<6;i++){var col=i%3;if(col==0){cubeCamera.up.set(0,upSign[i],0);cubeCamera.lookAt(forwardSign[i],0,0);}else if(col==1){cubeCamera.up.set(0,0,upSign[i]);cubeCamera.lookAt(0,forwardSign[i],0);}else {cubeCamera.up.set(0,upSign[i],0);cubeCamera.lookAt(0,0,forwardSign[i]);}_setViewport(cubeUVRenderTarget,col*SIZE_MAX,i>2?SIZE_MAX:0,SIZE_MAX,SIZE_MAX);renderer.setRenderTarget(cubeUVRenderTarget);renderer.render(scene,cubeCamera);}renderer.toneMapping=toneMapping;renderer.toneMappingExposure=toneMappingExposure;renderer.outputEncoding=outputEncoding;renderer.setClearColor(clearColor,clearAlpha);scene.scale.z*=-1;},_textureToCubeUV:function _textureToCubeUV(texture,cubeUVRenderTarget){var scene=new Scene();var renderer=this._renderer;if(texture.isCubeTexture){if(this._cubemapShader==null){this._cubemapShader=_getCubemapShader();}}else {if(this._equirectShader==null){this._equirectShader=_getEquirectShader();}}var material=texture.isCubeTexture?this._cubemapShader:this._equirectShader;scene.add(new Mesh(_lodPlanes[0],material));var uniforms=material.uniforms;uniforms['envMap'].value=texture;if(!texture.isCubeTexture){uniforms['texelSize'].value.set(1.0/texture.image.width,1.0/texture.image.height);}uniforms['inputEncoding'].value=ENCODINGS[texture.encoding];uniforms['outputEncoding'].value=ENCODINGS[cubeUVRenderTarget.texture.encoding];_setViewport(cubeUVRenderTarget,0,0,3*SIZE_MAX,2*SIZE_MAX);renderer.setRenderTarget(cubeUVRenderTarget);renderer.render(scene,_flatCamera);},_applyPMREM:function _applyPMREM(cubeUVRenderTarget){var renderer=this._renderer;var autoClear=renderer.autoClear;renderer.autoClear=false;for(var i=1;i<TOTAL_LODS;i++){var sigma=Math.sqrt(_sigmas[i]*_sigmas[i]-_sigmas[i-1]*_sigmas[i-1]);var poleAxis=_axisDirections[(i-1)%_axisDirections.length];this._blur(cubeUVRenderTarget,i-1,i,sigma,poleAxis);}renderer.autoClear=autoClear;},/**
|
3699 | * This is a two-pass Gaussian blur for a cubemap. Normally this is done
|
3700 | * vertically and horizontally, but this breaks down on a cube. Here we apply
|
3701 | * the blur latitudinally (around the poles), and then longitudinally (towards
|
3702 | * the poles) to approximate the orthogonally-separable blur. It is least
|
3703 | * accurate at the poles, but still does a decent job.
|
3704 | */_blur:function _blur(cubeUVRenderTarget,lodIn,lodOut,sigma,poleAxis){var pingPongRenderTarget=this._pingPongRenderTarget;this._halfBlur(cubeUVRenderTarget,pingPongRenderTarget,lodIn,lodOut,sigma,'latitudinal',poleAxis);this._halfBlur(pingPongRenderTarget,cubeUVRenderTarget,lodOut,lodOut,sigma,'longitudinal',poleAxis);},_halfBlur:function _halfBlur(targetIn,targetOut,lodIn,lodOut,sigmaRadians,direction,poleAxis){var renderer=this._renderer;var blurMaterial=this._blurMaterial;if(direction!=='latitudinal'&&direction!=='longitudinal'){console.error('blur direction must be either latitudinal or longitudinal!');}// Number of standard deviations at which to cut off the discrete approximation.
|
3705 | var STANDARD_DEVIATIONS=3;var blurScene=new Scene();blurScene.add(new Mesh(_lodPlanes[lodOut],blurMaterial));var blurUniforms=blurMaterial.uniforms;var pixels=_sizeLods[lodIn]-1;var radiansPerPixel=isFinite(sigmaRadians)?Math.PI/(2*pixels):2*Math.PI/(2*MAX_SAMPLES-1);var sigmaPixels=sigmaRadians/radiansPerPixel;var samples=isFinite(sigmaRadians)?1+Math.floor(STANDARD_DEVIATIONS*sigmaPixels):MAX_SAMPLES;if(samples>MAX_SAMPLES){console.warn("sigmaRadians, "+sigmaRadians+", is too large and will clip, as it requested "+samples+" samples when the maximum is set to "+MAX_SAMPLES);}var weights=[];var sum=0;for(var i=0;i<MAX_SAMPLES;++i){var x=i/sigmaPixels;var weight=Math.exp(-x*x/2);weights.push(weight);if(i==0){sum+=weight;}else if(i<samples){sum+=2*weight;}}for(var i=0;i<weights.length;i++){weights[i]=weights[i]/sum;}blurUniforms['envMap'].value=targetIn.texture;blurUniforms['samples'].value=samples;blurUniforms['weights'].value=weights;blurUniforms['latitudinal'].value=direction==='latitudinal';if(poleAxis){blurUniforms['poleAxis'].value=poleAxis;}blurUniforms['dTheta'].value=radiansPerPixel;blurUniforms['mipInt'].value=LOD_MAX-lodIn;blurUniforms['inputEncoding'].value=ENCODINGS[targetIn.texture.encoding];blurUniforms['outputEncoding'].value=ENCODINGS[targetIn.texture.encoding];var outputSize=_sizeLods[lodOut];var x=3*Math.max(0,SIZE_MAX-2*outputSize);var y=(lodOut===0?0:2*SIZE_MAX)+2*outputSize*(lodOut>LOD_MAX-LOD_MIN?lodOut-LOD_MAX+LOD_MIN:0);_setViewport(targetOut,x,y,3*outputSize,2*outputSize);renderer.setRenderTarget(targetOut);renderer.render(blurScene,_flatCamera);}};function _isLDR(texture){if(texture===undefined||texture.type!==UnsignedByteType)return false;return texture.encoding===LinearEncoding||texture.encoding===sRGBEncoding||texture.encoding===GammaEncoding;}function _createPlanes(){var _lodPlanes=[];var _sizeLods=[];var _sigmas=[];var lod=LOD_MAX;for(var i=0;i<TOTAL_LODS;i++){var sizeLod=Math.pow(2,lod);_sizeLods.push(sizeLod);var sigma=1.0/sizeLod;if(i>LOD_MAX-LOD_MIN){sigma=EXTRA_LOD_SIGMA[i-LOD_MAX+LOD_MIN-1];}else if(i==0){sigma=0;}_sigmas.push(sigma);var texelSize=1.0/(sizeLod-1);var min=-texelSize/2;var max=1+texelSize/2;var uv1=[min,min,max,min,max,max,min,min,max,max,min,max];var cubeFaces=6;var vertices=6;var positionSize=3;var uvSize=2;var faceIndexSize=1;var position=new Float32Array(positionSize*vertices*cubeFaces);var uv=new Float32Array(uvSize*vertices*cubeFaces);var faceIndex=new Float32Array(faceIndexSize*vertices*cubeFaces);for(var face=0;face<cubeFaces;face++){var x=face%3*2/3-1;var y=face>2?0:-1;var coordinates=[x,y,0,x+2/3,y,0,x+2/3,y+1,0,x,y,0,x+2/3,y+1,0,x,y+1,0];position.set(coordinates,positionSize*vertices*face);uv.set(uv1,uvSize*vertices*face);var fill=[face,face,face,face,face,face];faceIndex.set(fill,faceIndexSize*vertices*face);}var planes=new BufferGeometry();planes.setAttribute('position',new BufferAttribute(position,positionSize));planes.setAttribute('uv',new BufferAttribute(uv,uvSize));planes.setAttribute('faceIndex',new BufferAttribute(faceIndex,faceIndexSize));_lodPlanes.push(planes);if(lod>LOD_MIN){lod--;}}return {_lodPlanes:_lodPlanes,_sizeLods:_sizeLods,_sigmas:_sigmas};}function _createRenderTarget(params){var cubeUVRenderTarget=new WebGLRenderTarget(3*SIZE_MAX,3*SIZE_MAX,params);cubeUVRenderTarget.texture.mapping=CubeUVReflectionMapping;cubeUVRenderTarget.texture.name='PMREM.cubeUv';cubeUVRenderTarget.scissorTest=true;return cubeUVRenderTarget;}function _setViewport(target,x,y,width,height){target.viewport.set(x,y,width,height);target.scissor.set(x,y,width,height);}function _getBlurShader(maxSamples){var weights=new Float32Array(maxSamples);var poleAxis=new Vector3(0,1,0);var shaderMaterial=new RawShaderMaterial({defines:{'n':maxSamples},uniforms:{'envMap':{value:null},'samples':{value:1},'weights':{value:weights},'latitudinal':{value:false},'dTheta':{value:0},'mipInt':{value:0},'poleAxis':{value:poleAxis},'inputEncoding':{value:ENCODINGS[LinearEncoding]},'outputEncoding':{value:ENCODINGS[LinearEncoding]}},vertexShader:_getCommonVertexShader(),fragmentShader:"\nprecision mediump float;\nprecision mediump int;\nvarying vec3 vOutputDirection;\nuniform sampler2D envMap;\nuniform int samples;\nuniform float weights[n];\nuniform bool latitudinal;\nuniform float dTheta;\nuniform float mipInt;\nuniform vec3 poleAxis;\n\n"+_getEncodings()+"\n\n#define ENVMAP_TYPE_CUBE_UV\n#include <cube_uv_reflection_fragment>\n\nvec3 getSample(float theta, vec3 axis) {\n\tfloat cosTheta = cos(theta);\n\t// Rodrigues' axis-angle rotation\n\tvec3 sampleDirection = vOutputDirection * cosTheta\n\t\t+ cross(axis, vOutputDirection) * sin(theta)\n\t\t+ axis * dot(axis, vOutputDirection) * (1.0 - cosTheta);\n\treturn bilinearCubeUV(envMap, sampleDirection, mipInt);\n}\n\nvoid main() {\n\tvec3 axis = latitudinal ? poleAxis : cross(poleAxis, vOutputDirection);\n\tif (all(equal(axis, vec3(0.0))))\n\t\taxis = vec3(vOutputDirection.z, 0.0, - vOutputDirection.x);\n\taxis = normalize(axis);\n\tgl_FragColor = vec4(0.0);\n\tgl_FragColor.rgb += weights[0] * getSample(0.0, axis);\n\tfor (int i = 1; i < n; i++) {\n\t\tif (i >= samples)\n\t\t\tbreak;\n\t\tfloat theta = dTheta * float(i);\n\t\tgl_FragColor.rgb += weights[i] * getSample(-1.0 * theta, axis);\n\t\tgl_FragColor.rgb += weights[i] * getSample(theta, axis);\n\t}\n\tgl_FragColor = linearToOutputTexel(gl_FragColor);\n}\n\t\t",blending:NoBlending,depthTest:false,depthWrite:false});shaderMaterial.type='SphericalGaussianBlur';return shaderMaterial;}function _getEquirectShader(){var texelSize=new Vector2(1,1);var shaderMaterial=new RawShaderMaterial({uniforms:{'envMap':{value:null},'texelSize':{value:texelSize},'inputEncoding':{value:ENCODINGS[LinearEncoding]},'outputEncoding':{value:ENCODINGS[LinearEncoding]}},vertexShader:_getCommonVertexShader(),fragmentShader:"\nprecision mediump float;\nprecision mediump int;\nvarying vec3 vOutputDirection;\nuniform sampler2D envMap;\nuniform vec2 texelSize;\n\n"+_getEncodings()+"\n\n#define RECIPROCAL_PI 0.31830988618\n#define RECIPROCAL_PI2 0.15915494\n\nvoid main() {\n\tgl_FragColor = vec4(0.0);\n\tvec3 outputDirection = normalize(vOutputDirection);\n\tvec2 uv;\n\tuv.y = asin(clamp(outputDirection.y, -1.0, 1.0)) * RECIPROCAL_PI + 0.5;\n\tuv.x = atan(outputDirection.z, outputDirection.x) * RECIPROCAL_PI2 + 0.5;\n\tvec2 f = fract(uv / texelSize - 0.5);\n\tuv -= f * texelSize;\n\tvec3 tl = envMapTexelToLinear(texture2D(envMap, uv)).rgb;\n\tuv.x += texelSize.x;\n\tvec3 tr = envMapTexelToLinear(texture2D(envMap, uv)).rgb;\n\tuv.y += texelSize.y;\n\tvec3 br = envMapTexelToLinear(texture2D(envMap, uv)).rgb;\n\tuv.x -= texelSize.x;\n\tvec3 bl = envMapTexelToLinear(texture2D(envMap, uv)).rgb;\n\tvec3 tm = mix(tl, tr, f.x);\n\tvec3 bm = mix(bl, br, f.x);\n\tgl_FragColor.rgb = mix(tm, bm, f.y);\n\tgl_FragColor = linearToOutputTexel(gl_FragColor);\n}\n\t\t",blending:NoBlending,depthTest:false,depthWrite:false});shaderMaterial.type='EquirectangularToCubeUV';return shaderMaterial;}function _getCubemapShader(){var shaderMaterial=new RawShaderMaterial({uniforms:{'envMap':{value:null},'inputEncoding':{value:ENCODINGS[LinearEncoding]},'outputEncoding':{value:ENCODINGS[LinearEncoding]}},vertexShader:_getCommonVertexShader(),fragmentShader:"\nprecision mediump float;\nprecision mediump int;\nvarying vec3 vOutputDirection;\nuniform samplerCube envMap;\n\n"+_getEncodings()+"\n\nvoid main() {\n\tgl_FragColor = vec4(0.0);\n\tgl_FragColor.rgb = envMapTexelToLinear(textureCube(envMap, vec3( - vOutputDirection.x, vOutputDirection.yz ))).rgb;\n\tgl_FragColor = linearToOutputTexel(gl_FragColor);\n}\n\t\t",blending:NoBlending,depthTest:false,depthWrite:false});shaderMaterial.type='CubemapToCubeUV';return shaderMaterial;}function _getCommonVertexShader(){return "\nprecision mediump float;\nprecision mediump int;\nattribute vec3 position;\nattribute vec2 uv;\nattribute float faceIndex;\nvarying vec3 vOutputDirection;\nvec3 getDirection(vec2 uv, float face) {\n\tuv = 2.0 * uv - 1.0;\n\tvec3 direction = vec3(uv, 1.0);\n\tif (face == 0.0) {\n\t\tdirection = direction.zyx;\n\t\tdirection.z *= -1.0;\n\t} else if (face == 1.0) {\n\t\tdirection = direction.xzy;\n\t\tdirection.z *= -1.0;\n\t} else if (face == 3.0) {\n\t\tdirection = direction.zyx;\n\t\tdirection.x *= -1.0;\n\t} else if (face == 4.0) {\n\t\tdirection = direction.xzy;\n\t\tdirection.y *= -1.0;\n\t} else if (face == 5.0) {\n\t\tdirection.xz *= -1.0;\n\t}\n\treturn direction;\n}\nvoid main() {\n\tvOutputDirection = getDirection(uv, faceIndex);\n\tgl_Position = vec4( position, 1.0 );\n}\n\t";}function _getEncodings(){return "\nuniform int inputEncoding;\nuniform int outputEncoding;\n\n#include <encodings_pars_fragment>\n\nvec4 inputTexelToLinear(vec4 value){\n\tif(inputEncoding == 0){\n\t\treturn value;\n\t}else if(inputEncoding == 1){\n\t\treturn sRGBToLinear(value);\n\t}else if(inputEncoding == 2){\n\t\treturn RGBEToLinear(value);\n\t}else if(inputEncoding == 3){\n\t\treturn RGBMToLinear(value, 7.0);\n\t}else if(inputEncoding == 4){\n\t\treturn RGBMToLinear(value, 16.0);\n\t}else if(inputEncoding == 5){\n\t\treturn RGBDToLinear(value, 256.0);\n\t}else{\n\t\treturn GammaToLinear(value, 2.2);\n\t}\n}\n\nvec4 linearToOutputTexel(vec4 value){\n\tif(outputEncoding == 0){\n\t\treturn value;\n\t}else if(outputEncoding == 1){\n\t\treturn LinearTosRGB(value);\n\t}else if(outputEncoding == 2){\n\t\treturn LinearToRGBE(value);\n\t}else if(outputEncoding == 3){\n\t\treturn LinearToRGBM(value, 7.0);\n\t}else if(outputEncoding == 4){\n\t\treturn LinearToRGBM(value, 16.0);\n\t}else if(outputEncoding == 5){\n\t\treturn LinearToRGBD(value, 256.0);\n\t}else{\n\t\treturn LinearToGamma(value, 2.2);\n\t}\n}\n\nvec4 envMapTexelToLinear(vec4 color) {\n\treturn inputTexelToLinear(color);\n}\n\t";}/**
|
3706 | * @author mrdoob / http://mrdoob.com/
|
3707 | */function Face4(a,b,c,d,normal,color,materialIndex){console.warn('THREE.Face4 has been removed. A THREE.Face3 will be created instead.');return new Face3(a,b,c,normal,color,materialIndex);}var LineStrip=0;var LinePieces=1;var NoColors=0;var FaceColors=1;var VertexColors=2;function MeshFaceMaterial(materials){console.warn('THREE.MeshFaceMaterial has been removed. Use an Array instead.');return materials;}function MultiMaterial(materials){if(materials===undefined)materials=[];console.warn('THREE.MultiMaterial has been removed. Use an Array instead.');materials.isMultiMaterial=true;materials.materials=materials;materials.clone=function(){return materials.slice();};return materials;}function PointCloud(geometry,material){console.warn('THREE.PointCloud has been renamed to THREE.Points.');return new Points(geometry,material);}function Particle(material){console.warn('THREE.Particle has been renamed to THREE.Sprite.');return new Sprite(material);}function ParticleSystem(geometry,material){console.warn('THREE.ParticleSystem has been renamed to THREE.Points.');return new Points(geometry,material);}function PointCloudMaterial(parameters){console.warn('THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.');return new PointsMaterial(parameters);}function ParticleBasicMaterial(parameters){console.warn('THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.');return new PointsMaterial(parameters);}function ParticleSystemMaterial(parameters){console.warn('THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.');return new PointsMaterial(parameters);}function Vertex(x,y,z){console.warn('THREE.Vertex has been removed. Use THREE.Vector3 instead.');return new Vector3(x,y,z);}//
|
3708 | function DynamicBufferAttribute(array,itemSize){console.warn('THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setUsage( THREE.DynamicDrawUsage ) instead.');return new BufferAttribute(array,itemSize).setUsage(DynamicDrawUsage);}function Int8Attribute(array,itemSize){console.warn('THREE.Int8Attribute has been removed. Use new THREE.Int8BufferAttribute() instead.');return new Int8BufferAttribute(array,itemSize);}function Uint8Attribute(array,itemSize){console.warn('THREE.Uint8Attribute has been removed. Use new THREE.Uint8BufferAttribute() instead.');return new Uint8BufferAttribute(array,itemSize);}function Uint8ClampedAttribute(array,itemSize){console.warn('THREE.Uint8ClampedAttribute has been removed. Use new THREE.Uint8ClampedBufferAttribute() instead.');return new Uint8ClampedBufferAttribute(array,itemSize);}function Int16Attribute(array,itemSize){console.warn('THREE.Int16Attribute has been removed. Use new THREE.Int16BufferAttribute() instead.');return new Int16BufferAttribute(array,itemSize);}function Uint16Attribute(array,itemSize){console.warn('THREE.Uint16Attribute has been removed. Use new THREE.Uint16BufferAttribute() instead.');return new Uint16BufferAttribute(array,itemSize);}function Int32Attribute(array,itemSize){console.warn('THREE.Int32Attribute has been removed. Use new THREE.Int32BufferAttribute() instead.');return new Int32BufferAttribute(array,itemSize);}function Uint32Attribute(array,itemSize){console.warn('THREE.Uint32Attribute has been removed. Use new THREE.Uint32BufferAttribute() instead.');return new Uint32BufferAttribute(array,itemSize);}function Float32Attribute(array,itemSize){console.warn('THREE.Float32Attribute has been removed. Use new THREE.Float32BufferAttribute() instead.');return new Float32BufferAttribute(array,itemSize);}function Float64Attribute(array,itemSize){console.warn('THREE.Float64Attribute has been removed. Use new THREE.Float64BufferAttribute() instead.');return new Float64BufferAttribute(array,itemSize);}//
|
3709 | Curve.create=function(construct,getPoint){console.log('THREE.Curve.create() has been deprecated');construct.prototype=Object.create(Curve.prototype);construct.prototype.constructor=construct;construct.prototype.getPoint=getPoint;return construct;};//
|
3710 | _extends(CurvePath.prototype,{createPointsGeometry:function createPointsGeometry(divisions){console.warn('THREE.CurvePath: .createPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.');// generate geometry from path points (for Line or Points objects)
|
3711 | var pts=this.getPoints(divisions);return this.createGeometry(pts);},createSpacedPointsGeometry:function createSpacedPointsGeometry(divisions){console.warn('THREE.CurvePath: .createSpacedPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.');// generate geometry from equidistant sampling along the path
|
3712 | var pts=this.getSpacedPoints(divisions);return this.createGeometry(pts);},createGeometry:function createGeometry(points){console.warn('THREE.CurvePath: .createGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.');var geometry=new Geometry();for(var i=0,l=points.length;i<l;i++){var point=points[i];geometry.vertices.push(new Vector3(point.x,point.y,point.z||0));}return geometry;}});//
|
3713 | _extends(Path.prototype,{fromPoints:function fromPoints(points){console.warn('THREE.Path: .fromPoints() has been renamed to .setFromPoints().');return this.setFromPoints(points);}});//
|
3714 | function ClosedSplineCurve3(points){console.warn('THREE.ClosedSplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.');CatmullRomCurve3.call(this,points);this.type='catmullrom';this.closed=true;}ClosedSplineCurve3.prototype=Object.create(CatmullRomCurve3.prototype);//
|
3715 | function SplineCurve3(points){console.warn('THREE.SplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.');CatmullRomCurve3.call(this,points);this.type='catmullrom';}SplineCurve3.prototype=Object.create(CatmullRomCurve3.prototype);//
|
3716 | function Spline(points){console.warn('THREE.Spline has been removed. Use THREE.CatmullRomCurve3 instead.');CatmullRomCurve3.call(this,points);this.type='catmullrom';}Spline.prototype=Object.create(CatmullRomCurve3.prototype);_extends(Spline.prototype,{initFromArray:function initFromArray()/* a */{console.error('THREE.Spline: .initFromArray() has been removed.');},getControlPointsArray:function getControlPointsArray()/* optionalTarget */{console.error('THREE.Spline: .getControlPointsArray() has been removed.');},reparametrizeByArcLength:function reparametrizeByArcLength()/* samplingCoef */{console.error('THREE.Spline: .reparametrizeByArcLength() has been removed.');}});//
|
3717 | function AxisHelper(size){console.warn('THREE.AxisHelper has been renamed to THREE.AxesHelper.');return new AxesHelper(size);}function BoundingBoxHelper(object,color){console.warn('THREE.BoundingBoxHelper has been deprecated. Creating a THREE.BoxHelper instead.');return new BoxHelper(object,color);}function EdgesHelper(object,hex){console.warn('THREE.EdgesHelper has been removed. Use THREE.EdgesGeometry instead.');return new LineSegments(new EdgesGeometry(object.geometry),new LineBasicMaterial({color:hex!==undefined?hex:0xffffff}));}GridHelper.prototype.setColors=function(){console.error('THREE.GridHelper: setColors() has been deprecated, pass them in the constructor instead.');};SkeletonHelper.prototype.update=function(){console.error('THREE.SkeletonHelper: update() no longer needs to be called.');};function WireframeHelper(object,hex){console.warn('THREE.WireframeHelper has been removed. Use THREE.WireframeGeometry instead.');return new LineSegments(new WireframeGeometry(object.geometry),new LineBasicMaterial({color:hex!==undefined?hex:0xffffff}));}//
|
3718 | _extends(Loader.prototype,{extractUrlBase:function extractUrlBase(url){console.warn('THREE.Loader: .extractUrlBase() has been deprecated. Use THREE.LoaderUtils.extractUrlBase() instead.');return LoaderUtils.extractUrlBase(url);}});Loader.Handlers={add:function add()/* regex, loader */{console.error('THREE.Loader: Handlers.add() has been removed. Use LoadingManager.addHandler() instead.');},get:function get()/* file */{console.error('THREE.Loader: Handlers.get() has been removed. Use LoadingManager.getHandler() instead.');}};function XHRLoader(manager){console.warn('THREE.XHRLoader has been renamed to THREE.FileLoader.');return new FileLoader(manager);}function BinaryTextureLoader(manager){console.warn('THREE.BinaryTextureLoader has been renamed to THREE.DataTextureLoader.');return new DataTextureLoader(manager);}_extends(ObjectLoader.prototype,{setTexturePath:function setTexturePath(value){console.warn('THREE.ObjectLoader: .setTexturePath() has been renamed to .setResourcePath().');return this.setResourcePath(value);}});//
|
3719 | _extends(Box2.prototype,{center:function center(optionalTarget){console.warn('THREE.Box2: .center() has been renamed to .getCenter().');return this.getCenter(optionalTarget);},empty:function empty(){console.warn('THREE.Box2: .empty() has been renamed to .isEmpty().');return this.isEmpty();},isIntersectionBox:function isIntersectionBox(box){console.warn('THREE.Box2: .isIntersectionBox() has been renamed to .intersectsBox().');return this.intersectsBox(box);},size:function size(optionalTarget){console.warn('THREE.Box2: .size() has been renamed to .getSize().');return this.getSize(optionalTarget);}});_extends(Box3.prototype,{center:function center(optionalTarget){console.warn('THREE.Box3: .center() has been renamed to .getCenter().');return this.getCenter(optionalTarget);},empty:function empty(){console.warn('THREE.Box3: .empty() has been renamed to .isEmpty().');return this.isEmpty();},isIntersectionBox:function isIntersectionBox(box){console.warn('THREE.Box3: .isIntersectionBox() has been renamed to .intersectsBox().');return this.intersectsBox(box);},isIntersectionSphere:function isIntersectionSphere(sphere){console.warn('THREE.Box3: .isIntersectionSphere() has been renamed to .intersectsSphere().');return this.intersectsSphere(sphere);},size:function size(optionalTarget){console.warn('THREE.Box3: .size() has been renamed to .getSize().');return this.getSize(optionalTarget);}});_extends(Sphere.prototype,{empty:function empty(){console.warn('THREE.Sphere: .empty() has been renamed to .isEmpty().');return this.isEmpty();}});Frustum.prototype.setFromMatrix=function(m){console.warn('THREE.Frustum: .setFromMatrix() has been renamed to .setFromProjectionMatrix().');return this.setFromProjectionMatrix(m);};Line3.prototype.center=function(optionalTarget){console.warn('THREE.Line3: .center() has been renamed to .getCenter().');return this.getCenter(optionalTarget);};_extends(MathUtils,{random16:function random16(){console.warn('THREE.Math: .random16() has been deprecated. Use Math.random() instead.');return Math.random();},nearestPowerOfTwo:function nearestPowerOfTwo(value){console.warn('THREE.Math: .nearestPowerOfTwo() has been renamed to .floorPowerOfTwo().');return MathUtils.floorPowerOfTwo(value);},nextPowerOfTwo:function nextPowerOfTwo(value){console.warn('THREE.Math: .nextPowerOfTwo() has been renamed to .ceilPowerOfTwo().');return MathUtils.ceilPowerOfTwo(value);}});_extends(Matrix3.prototype,{flattenToArrayOffset:function flattenToArrayOffset(array,offset){console.warn("THREE.Matrix3: .flattenToArrayOffset() has been deprecated. Use .toArray() instead.");return this.toArray(array,offset);},multiplyVector3:function multiplyVector3(vector){console.warn('THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.');return vector.applyMatrix3(this);},multiplyVector3Array:function multiplyVector3Array()/* a */{console.error('THREE.Matrix3: .multiplyVector3Array() has been removed.');},applyToBufferAttribute:function applyToBufferAttribute(attribute){console.warn('THREE.Matrix3: .applyToBufferAttribute() has been removed. Use attribute.applyMatrix3( matrix ) instead.');return attribute.applyMatrix3(this);},applyToVector3Array:function applyToVector3Array()/* array, offset, length */{console.error('THREE.Matrix3: .applyToVector3Array() has been removed.');}});_extends(Matrix4.prototype,{extractPosition:function extractPosition(m){console.warn('THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().');return this.copyPosition(m);},flattenToArrayOffset:function flattenToArrayOffset(array,offset){console.warn("THREE.Matrix4: .flattenToArrayOffset() has been deprecated. Use .toArray() instead.");return this.toArray(array,offset);},getPosition:function getPosition(){console.warn('THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.');return new Vector3().setFromMatrixColumn(this,3);},setRotationFromQuaternion:function setRotationFromQuaternion(q){console.warn('THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().');return this.makeRotationFromQuaternion(q);},multiplyToArray:function multiplyToArray(){console.warn('THREE.Matrix4: .multiplyToArray() has been removed.');},multiplyVector3:function multiplyVector3(vector){console.warn('THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) instead.');return vector.applyMatrix4(this);},multiplyVector4:function multiplyVector4(vector){console.warn('THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.');return vector.applyMatrix4(this);},multiplyVector3Array:function multiplyVector3Array()/* a */{console.error('THREE.Matrix4: .multiplyVector3Array() has been removed.');},rotateAxis:function rotateAxis(v){console.warn('THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.');v.transformDirection(this);},crossVector:function crossVector(vector){console.warn('THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.');return vector.applyMatrix4(this);},translate:function translate(){console.error('THREE.Matrix4: .translate() has been removed.');},rotateX:function rotateX(){console.error('THREE.Matrix4: .rotateX() has been removed.');},rotateY:function rotateY(){console.error('THREE.Matrix4: .rotateY() has been removed.');},rotateZ:function rotateZ(){console.error('THREE.Matrix4: .rotateZ() has been removed.');},rotateByAxis:function rotateByAxis(){console.error('THREE.Matrix4: .rotateByAxis() has been removed.');},applyToBufferAttribute:function applyToBufferAttribute(attribute){console.warn('THREE.Matrix4: .applyToBufferAttribute() has been removed. Use attribute.applyMatrix4( matrix ) instead.');return attribute.applyMatrix4(this);},applyToVector3Array:function applyToVector3Array()/* array, offset, length */{console.error('THREE.Matrix4: .applyToVector3Array() has been removed.');},makeFrustum:function makeFrustum(left,right,bottom,top,near,far){console.warn('THREE.Matrix4: .makeFrustum() has been removed. Use .makePerspective( left, right, top, bottom, near, far ) instead.');return this.makePerspective(left,right,top,bottom,near,far);}});Plane.prototype.isIntersectionLine=function(line){console.warn('THREE.Plane: .isIntersectionLine() has been renamed to .intersectsLine().');return this.intersectsLine(line);};Quaternion.prototype.multiplyVector3=function(vector){console.warn('THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.');return vector.applyQuaternion(this);};_extends(Ray.prototype,{isIntersectionBox:function isIntersectionBox(box){console.warn('THREE.Ray: .isIntersectionBox() has been renamed to .intersectsBox().');return this.intersectsBox(box);},isIntersectionPlane:function isIntersectionPlane(plane){console.warn('THREE.Ray: .isIntersectionPlane() has been renamed to .intersectsPlane().');return this.intersectsPlane(plane);},isIntersectionSphere:function isIntersectionSphere(sphere){console.warn('THREE.Ray: .isIntersectionSphere() has been renamed to .intersectsSphere().');return this.intersectsSphere(sphere);}});_extends(Triangle.prototype,{area:function area(){console.warn('THREE.Triangle: .area() has been renamed to .getArea().');return this.getArea();},barycoordFromPoint:function barycoordFromPoint(point,target){console.warn('THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().');return this.getBarycoord(point,target);},midpoint:function midpoint(target){console.warn('THREE.Triangle: .midpoint() has been renamed to .getMidpoint().');return this.getMidpoint(target);},normal:function normal(target){console.warn('THREE.Triangle: .normal() has been renamed to .getNormal().');return this.getNormal(target);},plane:function plane(target){console.warn('THREE.Triangle: .plane() has been renamed to .getPlane().');return this.getPlane(target);}});_extends(Triangle,{barycoordFromPoint:function barycoordFromPoint(point,a,b,c,target){console.warn('THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().');return Triangle.getBarycoord(point,a,b,c,target);},normal:function normal(a,b,c,target){console.warn('THREE.Triangle: .normal() has been renamed to .getNormal().');return Triangle.getNormal(a,b,c,target);}});_extends(Shape.prototype,{extractAllPoints:function extractAllPoints(divisions){console.warn('THREE.Shape: .extractAllPoints() has been removed. Use .extractPoints() instead.');return this.extractPoints(divisions);},extrude:function extrude(options){console.warn('THREE.Shape: .extrude() has been removed. Use ExtrudeGeometry() instead.');return new ExtrudeGeometry(this,options);},makeGeometry:function makeGeometry(options){console.warn('THREE.Shape: .makeGeometry() has been removed. Use ShapeGeometry() instead.');return new ShapeGeometry(this,options);}});_extends(Vector2.prototype,{fromAttribute:function fromAttribute(attribute,index,offset){console.warn('THREE.Vector2: .fromAttribute() has been renamed to .fromBufferAttribute().');return this.fromBufferAttribute(attribute,index,offset);},distanceToManhattan:function distanceToManhattan(v){console.warn('THREE.Vector2: .distanceToManhattan() has been renamed to .manhattanDistanceTo().');return this.manhattanDistanceTo(v);},lengthManhattan:function lengthManhattan(){console.warn('THREE.Vector2: .lengthManhattan() has been renamed to .manhattanLength().');return this.manhattanLength();}});_extends(Vector3.prototype,{setEulerFromRotationMatrix:function setEulerFromRotationMatrix(){console.error('THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.');},setEulerFromQuaternion:function setEulerFromQuaternion(){console.error('THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.');},getPositionFromMatrix:function getPositionFromMatrix(m){console.warn('THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().');return this.setFromMatrixPosition(m);},getScaleFromMatrix:function getScaleFromMatrix(m){console.warn('THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().');return this.setFromMatrixScale(m);},getColumnFromMatrix:function getColumnFromMatrix(index,matrix){console.warn('THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().');return this.setFromMatrixColumn(matrix,index);},applyProjection:function applyProjection(m){console.warn('THREE.Vector3: .applyProjection() has been removed. Use .applyMatrix4( m ) instead.');return this.applyMatrix4(m);},fromAttribute:function fromAttribute(attribute,index,offset){console.warn('THREE.Vector3: .fromAttribute() has been renamed to .fromBufferAttribute().');return this.fromBufferAttribute(attribute,index,offset);},distanceToManhattan:function distanceToManhattan(v){console.warn('THREE.Vector3: .distanceToManhattan() has been renamed to .manhattanDistanceTo().');return this.manhattanDistanceTo(v);},lengthManhattan:function lengthManhattan(){console.warn('THREE.Vector3: .lengthManhattan() has been renamed to .manhattanLength().');return this.manhattanLength();}});_extends(Vector4.prototype,{fromAttribute:function fromAttribute(attribute,index,offset){console.warn('THREE.Vector4: .fromAttribute() has been renamed to .fromBufferAttribute().');return this.fromBufferAttribute(attribute,index,offset);},lengthManhattan:function lengthManhattan(){console.warn('THREE.Vector4: .lengthManhattan() has been renamed to .manhattanLength().');return this.manhattanLength();}});//
|
3720 | _extends(Geometry.prototype,{computeTangents:function computeTangents(){console.error('THREE.Geometry: .computeTangents() has been removed.');},computeLineDistances:function computeLineDistances(){console.error('THREE.Geometry: .computeLineDistances() has been removed. Use THREE.Line.computeLineDistances() instead.');},applyMatrix:function applyMatrix(matrix){console.warn('THREE.Geometry: .applyMatrix() has been renamed to .applyMatrix4().');return this.applyMatrix4(matrix);}});_extends(Object3D.prototype,{getChildByName:function getChildByName(name){console.warn('THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().');return this.getObjectByName(name);},renderDepth:function renderDepth(){console.warn('THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.');},translate:function translate(distance,axis){console.warn('THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.');return this.translateOnAxis(axis,distance);},getWorldRotation:function getWorldRotation(){console.error('THREE.Object3D: .getWorldRotation() has been removed. Use THREE.Object3D.getWorldQuaternion( target ) instead.');},applyMatrix:function applyMatrix(matrix){console.warn('THREE.Object3D: .applyMatrix() has been renamed to .applyMatrix4().');return this.applyMatrix4(matrix);}});Object.defineProperties(Object3D.prototype,{eulerOrder:{get:function get(){console.warn('THREE.Object3D: .eulerOrder is now .rotation.order.');return this.rotation.order;},set:function set(value){console.warn('THREE.Object3D: .eulerOrder is now .rotation.order.');this.rotation.order=value;}},useQuaternion:{get:function get(){console.warn('THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.');},set:function set(){console.warn('THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.');}}});_extends(Mesh.prototype,{setDrawMode:function setDrawMode(){console.error('THREE.Mesh: .setDrawMode() has been removed. The renderer now always assumes THREE.TrianglesDrawMode. Transform your geometry via BufferGeometryUtils.toTrianglesDrawMode() if necessary.');}});Object.defineProperties(Mesh.prototype,{drawMode:{get:function get(){console.error('THREE.Mesh: .drawMode has been removed. The renderer now always assumes THREE.TrianglesDrawMode.');return TrianglesDrawMode;},set:function set(){console.error('THREE.Mesh: .drawMode has been removed. The renderer now always assumes THREE.TrianglesDrawMode. Transform your geometry via BufferGeometryUtils.toTrianglesDrawMode() if necessary.');}}});Object.defineProperties(LOD.prototype,{objects:{get:function get(){console.warn('THREE.LOD: .objects has been renamed to .levels.');return this.levels;}}});Object.defineProperty(Skeleton.prototype,'useVertexTexture',{get:function get(){console.warn('THREE.Skeleton: useVertexTexture has been removed.');},set:function set(){console.warn('THREE.Skeleton: useVertexTexture has been removed.');}});SkinnedMesh.prototype.initBones=function(){console.error('THREE.SkinnedMesh: initBones() has been removed.');};Object.defineProperty(Curve.prototype,'__arcLengthDivisions',{get:function get(){console.warn('THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.');return this.arcLengthDivisions;},set:function set(value){console.warn('THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.');this.arcLengthDivisions=value;}});//
|
3721 | PerspectiveCamera.prototype.setLens=function(focalLength,filmGauge){console.warn("THREE.PerspectiveCamera.setLens is deprecated. "+"Use .setFocalLength and .filmGauge for a photographic setup.");if(filmGauge!==undefined)this.filmGauge=filmGauge;this.setFocalLength(focalLength);};//
|
3722 | Object.defineProperties(Light.prototype,{onlyShadow:{set:function set(){console.warn('THREE.Light: .onlyShadow has been removed.');}},shadowCameraFov:{set:function set(value){console.warn('THREE.Light: .shadowCameraFov is now .shadow.camera.fov.');this.shadow.camera.fov=value;}},shadowCameraLeft:{set:function set(value){console.warn('THREE.Light: .shadowCameraLeft is now .shadow.camera.left.');this.shadow.camera.left=value;}},shadowCameraRight:{set:function set(value){console.warn('THREE.Light: .shadowCameraRight is now .shadow.camera.right.');this.shadow.camera.right=value;}},shadowCameraTop:{set:function set(value){console.warn('THREE.Light: .shadowCameraTop is now .shadow.camera.top.');this.shadow.camera.top=value;}},shadowCameraBottom:{set:function set(value){console.warn('THREE.Light: .shadowCameraBottom is now .shadow.camera.bottom.');this.shadow.camera.bottom=value;}},shadowCameraNear:{set:function set(value){console.warn('THREE.Light: .shadowCameraNear is now .shadow.camera.near.');this.shadow.camera.near=value;}},shadowCameraFar:{set:function set(value){console.warn('THREE.Light: .shadowCameraFar is now .shadow.camera.far.');this.shadow.camera.far=value;}},shadowCameraVisible:{set:function set(){console.warn('THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow.camera ) instead.');}},shadowBias:{set:function set(value){console.warn('THREE.Light: .shadowBias is now .shadow.bias.');this.shadow.bias=value;}},shadowDarkness:{set:function set(){console.warn('THREE.Light: .shadowDarkness has been removed.');}},shadowMapWidth:{set:function set(value){console.warn('THREE.Light: .shadowMapWidth is now .shadow.mapSize.width.');this.shadow.mapSize.width=value;}},shadowMapHeight:{set:function set(value){console.warn('THREE.Light: .shadowMapHeight is now .shadow.mapSize.height.');this.shadow.mapSize.height=value;}}});//
|
3723 | Object.defineProperties(BufferAttribute.prototype,{length:{get:function get(){console.warn('THREE.BufferAttribute: .length has been deprecated. Use .count instead.');return this.array.length;}},dynamic:{get:function get(){console.warn('THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.');return this.usage===DynamicDrawUsage;},set:function set()/* value */{console.warn('THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.');this.setUsage(DynamicDrawUsage);}}});_extends(BufferAttribute.prototype,{setDynamic:function setDynamic(value){console.warn('THREE.BufferAttribute: .setDynamic() has been deprecated. Use .setUsage() instead.');this.setUsage(value===true?DynamicDrawUsage:StaticDrawUsage);return this;},copyIndicesArray:function copyIndicesArray()/* indices */{console.error('THREE.BufferAttribute: .copyIndicesArray() has been removed.');},setArray:function setArray()/* array */{console.error('THREE.BufferAttribute: .setArray has been removed. Use BufferGeometry .setAttribute to replace/resize attribute buffers');}});_extends(BufferGeometry.prototype,{addIndex:function addIndex(index){console.warn('THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().');this.setIndex(index);},addAttribute:function addAttribute(name,attribute){console.warn('THREE.BufferGeometry: .addAttribute() has been renamed to .setAttribute().');if(!(attribute&&attribute.isBufferAttribute)&&!(attribute&&attribute.isInterleavedBufferAttribute)){console.warn('THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).');return this.setAttribute(name,new BufferAttribute(arguments[1],arguments[2]));}if(name==='index'){console.warn('THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.');this.setIndex(attribute);return this;}return this.setAttribute(name,attribute);},addDrawCall:function addDrawCall(start,count,indexOffset){if(indexOffset!==undefined){console.warn('THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.');}console.warn('THREE.BufferGeometry: .addDrawCall() is now .addGroup().');this.addGroup(start,count);},clearDrawCalls:function clearDrawCalls(){console.warn('THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().');this.clearGroups();},computeTangents:function computeTangents(){console.warn('THREE.BufferGeometry: .computeTangents() has been removed.');},computeOffsets:function computeOffsets(){console.warn('THREE.BufferGeometry: .computeOffsets() has been removed.');},removeAttribute:function removeAttribute(name){console.warn('THREE.BufferGeometry: .removeAttribute() has been renamed to .deleteAttribute().');return this.deleteAttribute(name);},applyMatrix:function applyMatrix(matrix){console.warn('THREE.BufferGeometry: .applyMatrix() has been renamed to .applyMatrix4().');return this.applyMatrix4(matrix);}});Object.defineProperties(BufferGeometry.prototype,{drawcalls:{get:function get(){console.error('THREE.BufferGeometry: .drawcalls has been renamed to .groups.');return this.groups;}},offsets:{get:function get(){console.warn('THREE.BufferGeometry: .offsets has been renamed to .groups.');return this.groups;}}});Object.defineProperties(Raycaster.prototype,{linePrecision:{get:function get(){console.warn('THREE.Raycaster: .linePrecision has been deprecated. Use .params.Line.threshold instead.');return this.params.Line.threshold;},set:function set(value){console.warn('THREE.Raycaster: .linePrecision has been deprecated. Use .params.Line.threshold instead.');this.params.Line.threshold=value;}}});Object.defineProperties(InterleavedBuffer.prototype,{dynamic:{get:function get(){console.warn('THREE.InterleavedBuffer: .length has been deprecated. Use .usage instead.');return this.usage===DynamicDrawUsage;},set:function set(value){console.warn('THREE.InterleavedBuffer: .length has been deprecated. Use .usage instead.');this.setUsage(value);}}});_extends(InterleavedBuffer.prototype,{setDynamic:function setDynamic(value){console.warn('THREE.InterleavedBuffer: .setDynamic() has been deprecated. Use .setUsage() instead.');this.setUsage(value===true?DynamicDrawUsage:StaticDrawUsage);return this;},setArray:function setArray()/* array */{console.error('THREE.InterleavedBuffer: .setArray has been removed. Use BufferGeometry .setAttribute to replace/resize attribute buffers');}});//
|
3724 | _extends(ExtrudeBufferGeometry.prototype,{getArrays:function getArrays(){console.error('THREE.ExtrudeBufferGeometry: .getArrays() has been removed.');},addShapeList:function addShapeList(){console.error('THREE.ExtrudeBufferGeometry: .addShapeList() has been removed.');},addShape:function addShape(){console.error('THREE.ExtrudeBufferGeometry: .addShape() has been removed.');}});//
|
3725 | Object.defineProperties(Uniform.prototype,{dynamic:{set:function set(){console.warn('THREE.Uniform: .dynamic has been removed. Use object.onBeforeRender() instead.');}},onUpdate:{value:function value(){console.warn('THREE.Uniform: .onUpdate() has been removed. Use object.onBeforeRender() instead.');return this;}}});//
|
3726 | Object.defineProperties(Material.prototype,{wrapAround:{get:function get(){console.warn('THREE.Material: .wrapAround has been removed.');},set:function set(){console.warn('THREE.Material: .wrapAround has been removed.');}},overdraw:{get:function get(){console.warn('THREE.Material: .overdraw has been removed.');},set:function set(){console.warn('THREE.Material: .overdraw has been removed.');}},wrapRGB:{get:function get(){console.warn('THREE.Material: .wrapRGB has been removed.');return new Color();}},shading:{get:function get(){console.error('THREE.'+this.type+': .shading has been removed. Use the boolean .flatShading instead.');},set:function set(value){console.warn('THREE.'+this.type+': .shading has been removed. Use the boolean .flatShading instead.');this.flatShading=value===FlatShading;}},stencilMask:{get:function get(){console.warn('THREE.'+this.type+': .stencilMask has been removed. Use .stencilFuncMask instead.');return this.stencilFuncMask;},set:function set(value){console.warn('THREE.'+this.type+': .stencilMask has been removed. Use .stencilFuncMask instead.');this.stencilFuncMask=value;}}});Object.defineProperties(MeshPhongMaterial.prototype,{metal:{get:function get(){console.warn('THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead.');return false;},set:function set(){console.warn('THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead');}}});Object.defineProperties(ShaderMaterial.prototype,{derivatives:{get:function get(){console.warn('THREE.ShaderMaterial: .derivatives has been moved to .extensions.derivatives.');return this.extensions.derivatives;},set:function set(value){console.warn('THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.');this.extensions.derivatives=value;}}});//
|
3727 | _extends(WebGLRenderer.prototype,{clearTarget:function clearTarget(renderTarget,color,depth,stencil){console.warn('THREE.WebGLRenderer: .clearTarget() has been deprecated. Use .setRenderTarget() and .clear() instead.');this.setRenderTarget(renderTarget);this.clear(color,depth,stencil);},animate:function animate(callback){console.warn('THREE.WebGLRenderer: .animate() is now .setAnimationLoop().');this.setAnimationLoop(callback);},getCurrentRenderTarget:function getCurrentRenderTarget(){console.warn('THREE.WebGLRenderer: .getCurrentRenderTarget() is now .getRenderTarget().');return this.getRenderTarget();},getMaxAnisotropy:function getMaxAnisotropy(){console.warn('THREE.WebGLRenderer: .getMaxAnisotropy() is now .capabilities.getMaxAnisotropy().');return this.capabilities.getMaxAnisotropy();},getPrecision:function getPrecision(){console.warn('THREE.WebGLRenderer: .getPrecision() is now .capabilities.precision.');return this.capabilities.precision;},resetGLState:function resetGLState(){console.warn('THREE.WebGLRenderer: .resetGLState() is now .state.reset().');return this.state.reset();},supportsFloatTextures:function supportsFloatTextures(){console.warn('THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).');return this.extensions.get('OES_texture_float');},supportsHalfFloatTextures:function supportsHalfFloatTextures(){console.warn('THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).');return this.extensions.get('OES_texture_half_float');},supportsStandardDerivatives:function supportsStandardDerivatives(){console.warn('THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).');return this.extensions.get('OES_standard_derivatives');},supportsCompressedTextureS3TC:function supportsCompressedTextureS3TC(){console.warn('THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).');return this.extensions.get('WEBGL_compressed_texture_s3tc');},supportsCompressedTexturePVRTC:function supportsCompressedTexturePVRTC(){console.warn('THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).');return this.extensions.get('WEBGL_compressed_texture_pvrtc');},supportsBlendMinMax:function supportsBlendMinMax(){console.warn('THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).');return this.extensions.get('EXT_blend_minmax');},supportsVertexTextures:function supportsVertexTextures(){console.warn('THREE.WebGLRenderer: .supportsVertexTextures() is now .capabilities.vertexTextures.');return this.capabilities.vertexTextures;},supportsInstancedArrays:function supportsInstancedArrays(){console.warn('THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).');return this.extensions.get('ANGLE_instanced_arrays');},enableScissorTest:function enableScissorTest(_boolean2){console.warn('THREE.WebGLRenderer: .enableScissorTest() is now .setScissorTest().');this.setScissorTest(_boolean2);},initMaterial:function initMaterial(){console.warn('THREE.WebGLRenderer: .initMaterial() has been removed.');},addPrePlugin:function addPrePlugin(){console.warn('THREE.WebGLRenderer: .addPrePlugin() has been removed.');},addPostPlugin:function addPostPlugin(){console.warn('THREE.WebGLRenderer: .addPostPlugin() has been removed.');},updateShadowMap:function updateShadowMap(){console.warn('THREE.WebGLRenderer: .updateShadowMap() has been removed.');},setFaceCulling:function setFaceCulling(){console.warn('THREE.WebGLRenderer: .setFaceCulling() has been removed.');},allocTextureUnit:function allocTextureUnit(){console.warn('THREE.WebGLRenderer: .allocTextureUnit() has been removed.');},setTexture:function setTexture(){console.warn('THREE.WebGLRenderer: .setTexture() has been removed.');},setTexture2D:function setTexture2D(){console.warn('THREE.WebGLRenderer: .setTexture2D() has been removed.');},setTextureCube:function setTextureCube(){console.warn('THREE.WebGLRenderer: .setTextureCube() has been removed.');},getActiveMipMapLevel:function getActiveMipMapLevel(){console.warn('THREE.WebGLRenderer: .getActiveMipMapLevel() is now .getActiveMipmapLevel().');return this.getActiveMipmapLevel();}});Object.defineProperties(WebGLRenderer.prototype,{shadowMapEnabled:{get:function get(){return this.shadowMap.enabled;},set:function set(value){console.warn('THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.');this.shadowMap.enabled=value;}},shadowMapType:{get:function get(){return this.shadowMap.type;},set:function set(value){console.warn('THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.');this.shadowMap.type=value;}},shadowMapCullFace:{get:function get(){console.warn('THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.');return undefined;},set:function set()/* value */{console.warn('THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.');}},context:{get:function get(){console.warn('THREE.WebGLRenderer: .context has been removed. Use .getContext() instead.');return this.getContext();}},vr:{get:function get(){console.warn('THREE.WebGLRenderer: .vr has been renamed to .xr');return this.xr;}},gammaInput:{get:function get(){console.warn('THREE.WebGLRenderer: .gammaInput has been removed. Set the encoding for textures via Texture.encoding instead.');return false;},set:function set(){console.warn('THREE.WebGLRenderer: .gammaInput has been removed. Set the encoding for textures via Texture.encoding instead.');}},gammaOutput:{get:function get(){console.warn('THREE.WebGLRenderer: .gammaOutput has been removed. Set WebGLRenderer.outputEncoding instead.');return false;},set:function set(value){console.warn('THREE.WebGLRenderer: .gammaOutput has been removed. Set WebGLRenderer.outputEncoding instead.');this.outputEncoding=value===true?sRGBEncoding:LinearEncoding;}}});Object.defineProperties(WebGLShadowMap.prototype,{cullFace:{get:function get(){console.warn('THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.');return undefined;},set:function set()/* cullFace */{console.warn('THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.');}},renderReverseSided:{get:function get(){console.warn('THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.');return undefined;},set:function set(){console.warn('THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.');}},renderSingleSided:{get:function get(){console.warn('THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.');return undefined;},set:function set(){console.warn('THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.');}}});function WebGLRenderTargetCube(width,height,options){console.warn('THREE.WebGLRenderTargetCube( width, height, options ) is now WebGLCubeRenderTarget( size, options ).');return new WebGLCubeRenderTarget(width,options);}//
|
3728 | Object.defineProperties(WebGLRenderTarget.prototype,{wrapS:{get:function get(){console.warn('THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.');return this.texture.wrapS;},set:function set(value){console.warn('THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.');this.texture.wrapS=value;}},wrapT:{get:function get(){console.warn('THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.');return this.texture.wrapT;},set:function set(value){console.warn('THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.');this.texture.wrapT=value;}},magFilter:{get:function get(){console.warn('THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.');return this.texture.magFilter;},set:function set(value){console.warn('THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.');this.texture.magFilter=value;}},minFilter:{get:function get(){console.warn('THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.');return this.texture.minFilter;},set:function set(value){console.warn('THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.');this.texture.minFilter=value;}},anisotropy:{get:function get(){console.warn('THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.');return this.texture.anisotropy;},set:function set(value){console.warn('THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.');this.texture.anisotropy=value;}},offset:{get:function get(){console.warn('THREE.WebGLRenderTarget: .offset is now .texture.offset.');return this.texture.offset;},set:function set(value){console.warn('THREE.WebGLRenderTarget: .offset is now .texture.offset.');this.texture.offset=value;}},repeat:{get:function get(){console.warn('THREE.WebGLRenderTarget: .repeat is now .texture.repeat.');return this.texture.repeat;},set:function set(value){console.warn('THREE.WebGLRenderTarget: .repeat is now .texture.repeat.');this.texture.repeat=value;}},format:{get:function get(){console.warn('THREE.WebGLRenderTarget: .format is now .texture.format.');return this.texture.format;},set:function set(value){console.warn('THREE.WebGLRenderTarget: .format is now .texture.format.');this.texture.format=value;}},type:{get:function get(){console.warn('THREE.WebGLRenderTarget: .type is now .texture.type.');return this.texture.type;},set:function set(value){console.warn('THREE.WebGLRenderTarget: .type is now .texture.type.');this.texture.type=value;}},generateMipmaps:{get:function get(){console.warn('THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.');return this.texture.generateMipmaps;},set:function set(value){console.warn('THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.');this.texture.generateMipmaps=value;}}});//
|
3729 | Object.defineProperties(Audio.prototype,{load:{value:function value(file){console.warn('THREE.Audio: .load has been deprecated. Use THREE.AudioLoader instead.');var scope=this;var audioLoader=new AudioLoader();audioLoader.load(file,function(buffer){scope.setBuffer(buffer);});return this;}},startTime:{set:function set(){console.warn('THREE.Audio: .startTime is now .play( delay ).');}}});AudioAnalyser.prototype.getData=function(){console.warn('THREE.AudioAnalyser: .getData() is now .getFrequencyData().');return this.getFrequencyData();};//
|
3730 | CubeCamera.prototype.updateCubeMap=function(renderer,scene){console.warn('THREE.CubeCamera: .updateCubeMap() is now .update().');return this.update(renderer,scene);};//
|
3731 | var GeometryUtils={merge:function merge(geometry1,geometry2,materialIndexOffset){console.warn('THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.');var matrix;if(geometry2.isMesh){geometry2.matrixAutoUpdate&&geometry2.updateMatrix();matrix=geometry2.matrix;geometry2=geometry2.geometry;}geometry1.merge(geometry2,matrix,materialIndexOffset);},center:function center(geometry){console.warn('THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.');return geometry.center();}};ImageUtils.crossOrigin=undefined;ImageUtils.loadTexture=function(url,mapping,onLoad,onError){console.warn('THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.');var loader=new TextureLoader();loader.setCrossOrigin(this.crossOrigin);var texture=loader.load(url,onLoad,undefined,onError);if(mapping)texture.mapping=mapping;return texture;};ImageUtils.loadTextureCube=function(urls,mapping,onLoad,onError){console.warn('THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.');var loader=new CubeTextureLoader();loader.setCrossOrigin(this.crossOrigin);var texture=loader.load(urls,onLoad,undefined,onError);if(mapping)texture.mapping=mapping;return texture;};ImageUtils.loadCompressedTexture=function(){console.error('THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.');};ImageUtils.loadCompressedTextureCube=function(){console.error('THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.');};//
|
3732 | function CanvasRenderer(){console.error('THREE.CanvasRenderer has been removed');}//
|
3733 | function JSONLoader(){console.error('THREE.JSONLoader has been removed.');}//
|
3734 | var SceneUtils={createMultiMaterialObject:function createMultiMaterialObject()/* geometry, materials */{console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');},detach:function detach()/* child, parent, scene */{console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');},attach:function attach()/* child, scene, parent */{console.error('THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js');}};//
|
3735 | function LensFlare(){console.error('THREE.LensFlare has been moved to /examples/jsm/objects/Lensflare.js');}if(typeof __THREE_DEVTOOLS__!=='undefined'){/* eslint-disable no-undef */__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent('register',{detail:{revision:REVISION}}));/* eslint-enable no-undef */}
|
3736 |
|
3737 | var three_module = {
|
3738 | __proto__: null,
|
3739 | ACESFilmicToneMapping: ACESFilmicToneMapping,
|
3740 | AddEquation: AddEquation,
|
3741 | AddOperation: AddOperation,
|
3742 | AdditiveAnimationBlendMode: AdditiveAnimationBlendMode,
|
3743 | AdditiveBlending: AdditiveBlending,
|
3744 | AlphaFormat: AlphaFormat,
|
3745 | AlwaysDepth: AlwaysDepth,
|
3746 | AlwaysStencilFunc: AlwaysStencilFunc,
|
3747 | AmbientLight: AmbientLight,
|
3748 | AmbientLightProbe: AmbientLightProbe,
|
3749 | AnimationClip: AnimationClip,
|
3750 | AnimationLoader: AnimationLoader,
|
3751 | AnimationMixer: AnimationMixer,
|
3752 | AnimationObjectGroup: AnimationObjectGroup,
|
3753 | AnimationUtils: AnimationUtils,
|
3754 | ArcCurve: ArcCurve,
|
3755 | ArrayCamera: ArrayCamera,
|
3756 | ArrowHelper: ArrowHelper,
|
3757 | Audio: Audio,
|
3758 | AudioAnalyser: AudioAnalyser,
|
3759 | AudioContext: AudioContext,
|
3760 | AudioListener: AudioListener,
|
3761 | AudioLoader: AudioLoader,
|
3762 | AxesHelper: AxesHelper,
|
3763 | AxisHelper: AxisHelper,
|
3764 | BackSide: BackSide,
|
3765 | BasicDepthPacking: BasicDepthPacking,
|
3766 | BasicShadowMap: BasicShadowMap,
|
3767 | BinaryTextureLoader: BinaryTextureLoader,
|
3768 | Bone: Bone,
|
3769 | BooleanKeyframeTrack: BooleanKeyframeTrack,
|
3770 | BoundingBoxHelper: BoundingBoxHelper,
|
3771 | Box2: Box2,
|
3772 | Box3: Box3,
|
3773 | Box3Helper: Box3Helper,
|
3774 | BoxBufferGeometry: BoxBufferGeometry,
|
3775 | BoxGeometry: BoxGeometry,
|
3776 | BoxHelper: BoxHelper,
|
3777 | BufferAttribute: BufferAttribute,
|
3778 | BufferGeometry: BufferGeometry,
|
3779 | BufferGeometryLoader: BufferGeometryLoader,
|
3780 | ByteType: ByteType,
|
3781 | Cache: Cache,
|
3782 | Camera: Camera,
|
3783 | CameraHelper: CameraHelper,
|
3784 | CanvasRenderer: CanvasRenderer,
|
3785 | CanvasTexture: CanvasTexture,
|
3786 | CatmullRomCurve3: CatmullRomCurve3,
|
3787 | CineonToneMapping: CineonToneMapping,
|
3788 | CircleBufferGeometry: CircleBufferGeometry,
|
3789 | CircleGeometry: CircleGeometry,
|
3790 | ClampToEdgeWrapping: ClampToEdgeWrapping,
|
3791 | Clock: Clock,
|
3792 | ClosedSplineCurve3: ClosedSplineCurve3,
|
3793 | Color: Color,
|
3794 | ColorKeyframeTrack: ColorKeyframeTrack,
|
3795 | CompressedTexture: CompressedTexture,
|
3796 | CompressedTextureLoader: CompressedTextureLoader,
|
3797 | ConeBufferGeometry: ConeBufferGeometry,
|
3798 | ConeGeometry: ConeGeometry,
|
3799 | CubeCamera: CubeCamera,
|
3800 | CubeGeometry: BoxGeometry,
|
3801 | CubeReflectionMapping: CubeReflectionMapping,
|
3802 | CubeRefractionMapping: CubeRefractionMapping,
|
3803 | CubeTexture: CubeTexture,
|
3804 | CubeTextureLoader: CubeTextureLoader,
|
3805 | CubeUVReflectionMapping: CubeUVReflectionMapping,
|
3806 | CubeUVRefractionMapping: CubeUVRefractionMapping,
|
3807 | CubicBezierCurve: CubicBezierCurve,
|
3808 | CubicBezierCurve3: CubicBezierCurve3,
|
3809 | CubicInterpolant: CubicInterpolant,
|
3810 | CullFaceBack: CullFaceBack,
|
3811 | CullFaceFront: CullFaceFront,
|
3812 | CullFaceFrontBack: CullFaceFrontBack,
|
3813 | CullFaceNone: CullFaceNone,
|
3814 | Curve: Curve,
|
3815 | CurvePath: CurvePath,
|
3816 | CustomBlending: CustomBlending,
|
3817 | CylinderBufferGeometry: CylinderBufferGeometry,
|
3818 | CylinderGeometry: CylinderGeometry,
|
3819 | Cylindrical: Cylindrical,
|
3820 | DataTexture: DataTexture,
|
3821 | DataTexture2DArray: DataTexture2DArray,
|
3822 | DataTexture3D: DataTexture3D,
|
3823 | DataTextureLoader: DataTextureLoader,
|
3824 | DecrementStencilOp: DecrementStencilOp,
|
3825 | DecrementWrapStencilOp: DecrementWrapStencilOp,
|
3826 | DefaultLoadingManager: DefaultLoadingManager,
|
3827 | DepthFormat: DepthFormat,
|
3828 | DepthStencilFormat: DepthStencilFormat,
|
3829 | DepthTexture: DepthTexture,
|
3830 | DirectionalLight: DirectionalLight,
|
3831 | DirectionalLightHelper: DirectionalLightHelper,
|
3832 | DirectionalLightShadow: DirectionalLightShadow,
|
3833 | DiscreteInterpolant: DiscreteInterpolant,
|
3834 | DodecahedronBufferGeometry: DodecahedronBufferGeometry,
|
3835 | DodecahedronGeometry: DodecahedronGeometry,
|
3836 | DoubleSide: DoubleSide,
|
3837 | DstAlphaFactor: DstAlphaFactor,
|
3838 | DstColorFactor: DstColorFactor,
|
3839 | DynamicBufferAttribute: DynamicBufferAttribute,
|
3840 | DynamicCopyUsage: DynamicCopyUsage,
|
3841 | DynamicDrawUsage: DynamicDrawUsage,
|
3842 | DynamicReadUsage: DynamicReadUsage,
|
3843 | EdgesGeometry: EdgesGeometry,
|
3844 | EdgesHelper: EdgesHelper,
|
3845 | EllipseCurve: EllipseCurve,
|
3846 | EqualDepth: EqualDepth,
|
3847 | EqualStencilFunc: EqualStencilFunc,
|
3848 | EquirectangularReflectionMapping: EquirectangularReflectionMapping,
|
3849 | EquirectangularRefractionMapping: EquirectangularRefractionMapping,
|
3850 | Euler: Euler,
|
3851 | EventDispatcher: EventDispatcher,
|
3852 | ExtrudeBufferGeometry: ExtrudeBufferGeometry,
|
3853 | ExtrudeGeometry: ExtrudeGeometry,
|
3854 | Face3: Face3,
|
3855 | Face4: Face4,
|
3856 | FaceColors: FaceColors,
|
3857 | FileLoader: FileLoader,
|
3858 | FlatShading: FlatShading,
|
3859 | Float32Attribute: Float32Attribute,
|
3860 | Float32BufferAttribute: Float32BufferAttribute,
|
3861 | Float64Attribute: Float64Attribute,
|
3862 | Float64BufferAttribute: Float64BufferAttribute,
|
3863 | FloatType: FloatType,
|
3864 | Fog: Fog,
|
3865 | FogExp2: FogExp2,
|
3866 | Font: Font,
|
3867 | FontLoader: FontLoader,
|
3868 | FrontFaceDirectionCCW: FrontFaceDirectionCCW,
|
3869 | FrontFaceDirectionCW: FrontFaceDirectionCW,
|
3870 | FrontSide: FrontSide,
|
3871 | Frustum: Frustum,
|
3872 | GammaEncoding: GammaEncoding,
|
3873 | Geometry: Geometry,
|
3874 | GeometryUtils: GeometryUtils,
|
3875 | GreaterDepth: GreaterDepth,
|
3876 | GreaterEqualDepth: GreaterEqualDepth,
|
3877 | GreaterEqualStencilFunc: GreaterEqualStencilFunc,
|
3878 | GreaterStencilFunc: GreaterStencilFunc,
|
3879 | GridHelper: GridHelper,
|
3880 | Group: Group,
|
3881 | HalfFloatType: HalfFloatType,
|
3882 | HemisphereLight: HemisphereLight,
|
3883 | HemisphereLightHelper: HemisphereLightHelper,
|
3884 | HemisphereLightProbe: HemisphereLightProbe,
|
3885 | IcosahedronBufferGeometry: IcosahedronBufferGeometry,
|
3886 | IcosahedronGeometry: IcosahedronGeometry,
|
3887 | ImageBitmapLoader: ImageBitmapLoader,
|
3888 | ImageLoader: ImageLoader,
|
3889 | ImageUtils: ImageUtils,
|
3890 | ImmediateRenderObject: ImmediateRenderObject,
|
3891 | IncrementStencilOp: IncrementStencilOp,
|
3892 | IncrementWrapStencilOp: IncrementWrapStencilOp,
|
3893 | InstancedBufferAttribute: InstancedBufferAttribute,
|
3894 | InstancedBufferGeometry: InstancedBufferGeometry,
|
3895 | InstancedInterleavedBuffer: InstancedInterleavedBuffer,
|
3896 | InstancedMesh: InstancedMesh,
|
3897 | Int16Attribute: Int16Attribute,
|
3898 | Int16BufferAttribute: Int16BufferAttribute,
|
3899 | Int32Attribute: Int32Attribute,
|
3900 | Int32BufferAttribute: Int32BufferAttribute,
|
3901 | Int8Attribute: Int8Attribute,
|
3902 | Int8BufferAttribute: Int8BufferAttribute,
|
3903 | IntType: IntType,
|
3904 | InterleavedBuffer: InterleavedBuffer,
|
3905 | InterleavedBufferAttribute: InterleavedBufferAttribute,
|
3906 | Interpolant: Interpolant,
|
3907 | InterpolateDiscrete: InterpolateDiscrete,
|
3908 | InterpolateLinear: InterpolateLinear,
|
3909 | InterpolateSmooth: InterpolateSmooth,
|
3910 | InvertStencilOp: InvertStencilOp,
|
3911 | JSONLoader: JSONLoader,
|
3912 | KeepStencilOp: KeepStencilOp,
|
3913 | KeyframeTrack: KeyframeTrack,
|
3914 | LOD: LOD,
|
3915 | LatheBufferGeometry: LatheBufferGeometry,
|
3916 | LatheGeometry: LatheGeometry,
|
3917 | Layers: Layers,
|
3918 | LensFlare: LensFlare,
|
3919 | LessDepth: LessDepth,
|
3920 | LessEqualDepth: LessEqualDepth,
|
3921 | LessEqualStencilFunc: LessEqualStencilFunc,
|
3922 | LessStencilFunc: LessStencilFunc,
|
3923 | Light: Light,
|
3924 | LightProbe: LightProbe,
|
3925 | LightShadow: LightShadow,
|
3926 | Line: Line,
|
3927 | Line3: Line3,
|
3928 | LineBasicMaterial: LineBasicMaterial,
|
3929 | LineCurve: LineCurve,
|
3930 | LineCurve3: LineCurve3,
|
3931 | LineDashedMaterial: LineDashedMaterial,
|
3932 | LineLoop: LineLoop,
|
3933 | LinePieces: LinePieces,
|
3934 | LineSegments: LineSegments,
|
3935 | LineStrip: LineStrip,
|
3936 | LinearEncoding: LinearEncoding,
|
3937 | LinearFilter: LinearFilter,
|
3938 | LinearInterpolant: LinearInterpolant,
|
3939 | LinearMipMapLinearFilter: LinearMipMapLinearFilter,
|
3940 | LinearMipMapNearestFilter: LinearMipMapNearestFilter,
|
3941 | LinearMipmapLinearFilter: LinearMipmapLinearFilter,
|
3942 | LinearMipmapNearestFilter: LinearMipmapNearestFilter,
|
3943 | LinearToneMapping: LinearToneMapping,
|
3944 | Loader: Loader,
|
3945 | LoaderUtils: LoaderUtils,
|
3946 | LoadingManager: LoadingManager,
|
3947 | LogLuvEncoding: LogLuvEncoding,
|
3948 | LoopOnce: LoopOnce,
|
3949 | LoopPingPong: LoopPingPong,
|
3950 | LoopRepeat: LoopRepeat,
|
3951 | LuminanceAlphaFormat: LuminanceAlphaFormat,
|
3952 | LuminanceFormat: LuminanceFormat,
|
3953 | MOUSE: MOUSE,
|
3954 | Material: Material,
|
3955 | MaterialLoader: MaterialLoader,
|
3956 | Math: MathUtils,
|
3957 | MathUtils: MathUtils,
|
3958 | Matrix3: Matrix3,
|
3959 | Matrix4: Matrix4,
|
3960 | MaxEquation: MaxEquation,
|
3961 | Mesh: Mesh,
|
3962 | MeshBasicMaterial: MeshBasicMaterial,
|
3963 | MeshDepthMaterial: MeshDepthMaterial,
|
3964 | MeshDistanceMaterial: MeshDistanceMaterial,
|
3965 | MeshFaceMaterial: MeshFaceMaterial,
|
3966 | MeshLambertMaterial: MeshLambertMaterial,
|
3967 | MeshMatcapMaterial: MeshMatcapMaterial,
|
3968 | MeshNormalMaterial: MeshNormalMaterial,
|
3969 | MeshPhongMaterial: MeshPhongMaterial,
|
3970 | MeshPhysicalMaterial: MeshPhysicalMaterial,
|
3971 | MeshStandardMaterial: MeshStandardMaterial,
|
3972 | MeshToonMaterial: MeshToonMaterial,
|
3973 | MinEquation: MinEquation,
|
3974 | MirroredRepeatWrapping: MirroredRepeatWrapping,
|
3975 | MixOperation: MixOperation,
|
3976 | MultiMaterial: MultiMaterial,
|
3977 | MultiplyBlending: MultiplyBlending,
|
3978 | MultiplyOperation: MultiplyOperation,
|
3979 | NearestFilter: NearestFilter,
|
3980 | NearestMipMapLinearFilter: NearestMipMapLinearFilter,
|
3981 | NearestMipMapNearestFilter: NearestMipMapNearestFilter,
|
3982 | NearestMipmapLinearFilter: NearestMipmapLinearFilter,
|
3983 | NearestMipmapNearestFilter: NearestMipmapNearestFilter,
|
3984 | NeverDepth: NeverDepth,
|
3985 | NeverStencilFunc: NeverStencilFunc,
|
3986 | NoBlending: NoBlending,
|
3987 | NoColors: NoColors,
|
3988 | NoToneMapping: NoToneMapping,
|
3989 | NormalAnimationBlendMode: NormalAnimationBlendMode,
|
3990 | NormalBlending: NormalBlending,
|
3991 | NotEqualDepth: NotEqualDepth,
|
3992 | NotEqualStencilFunc: NotEqualStencilFunc,
|
3993 | NumberKeyframeTrack: NumberKeyframeTrack,
|
3994 | Object3D: Object3D,
|
3995 | ObjectLoader: ObjectLoader,
|
3996 | ObjectSpaceNormalMap: ObjectSpaceNormalMap,
|
3997 | OctahedronBufferGeometry: OctahedronBufferGeometry,
|
3998 | OctahedronGeometry: OctahedronGeometry,
|
3999 | OneFactor: OneFactor,
|
4000 | OneMinusDstAlphaFactor: OneMinusDstAlphaFactor,
|
4001 | OneMinusDstColorFactor: OneMinusDstColorFactor,
|
4002 | OneMinusSrcAlphaFactor: OneMinusSrcAlphaFactor,
|
4003 | OneMinusSrcColorFactor: OneMinusSrcColorFactor,
|
4004 | OrthographicCamera: OrthographicCamera,
|
4005 | PCFShadowMap: PCFShadowMap,
|
4006 | PCFSoftShadowMap: PCFSoftShadowMap,
|
4007 | PMREMGenerator: PMREMGenerator,
|
4008 | ParametricBufferGeometry: ParametricBufferGeometry,
|
4009 | ParametricGeometry: ParametricGeometry,
|
4010 | Particle: Particle,
|
4011 | ParticleBasicMaterial: ParticleBasicMaterial,
|
4012 | ParticleSystem: ParticleSystem,
|
4013 | ParticleSystemMaterial: ParticleSystemMaterial,
|
4014 | Path: Path,
|
4015 | PerspectiveCamera: PerspectiveCamera,
|
4016 | Plane: Plane,
|
4017 | PlaneBufferGeometry: PlaneBufferGeometry,
|
4018 | PlaneGeometry: PlaneGeometry,
|
4019 | PlaneHelper: PlaneHelper,
|
4020 | PointCloud: PointCloud,
|
4021 | PointCloudMaterial: PointCloudMaterial,
|
4022 | PointLight: PointLight,
|
4023 | PointLightHelper: PointLightHelper,
|
4024 | Points: Points,
|
4025 | PointsMaterial: PointsMaterial,
|
4026 | PolarGridHelper: PolarGridHelper,
|
4027 | PolyhedronBufferGeometry: PolyhedronBufferGeometry,
|
4028 | PolyhedronGeometry: PolyhedronGeometry,
|
4029 | PositionalAudio: PositionalAudio,
|
4030 | PropertyBinding: PropertyBinding,
|
4031 | PropertyMixer: PropertyMixer,
|
4032 | QuadraticBezierCurve: QuadraticBezierCurve,
|
4033 | QuadraticBezierCurve3: QuadraticBezierCurve3,
|
4034 | Quaternion: Quaternion,
|
4035 | QuaternionKeyframeTrack: QuaternionKeyframeTrack,
|
4036 | QuaternionLinearInterpolant: QuaternionLinearInterpolant,
|
4037 | REVISION: REVISION,
|
4038 | RGBADepthPacking: RGBADepthPacking,
|
4039 | RGBAFormat: RGBAFormat,
|
4040 | RGBAIntegerFormat: RGBAIntegerFormat,
|
4041 | RGBA_ASTC_10x10_Format: RGBA_ASTC_10x10_Format,
|
4042 | RGBA_ASTC_10x5_Format: RGBA_ASTC_10x5_Format,
|
4043 | RGBA_ASTC_10x6_Format: RGBA_ASTC_10x6_Format,
|
4044 | RGBA_ASTC_10x8_Format: RGBA_ASTC_10x8_Format,
|
4045 | RGBA_ASTC_12x10_Format: RGBA_ASTC_12x10_Format,
|
4046 | RGBA_ASTC_12x12_Format: RGBA_ASTC_12x12_Format,
|
4047 | RGBA_ASTC_4x4_Format: RGBA_ASTC_4x4_Format,
|
4048 | RGBA_ASTC_5x4_Format: RGBA_ASTC_5x4_Format,
|
4049 | RGBA_ASTC_5x5_Format: RGBA_ASTC_5x5_Format,
|
4050 | RGBA_ASTC_6x5_Format: RGBA_ASTC_6x5_Format,
|
4051 | RGBA_ASTC_6x6_Format: RGBA_ASTC_6x6_Format,
|
4052 | RGBA_ASTC_8x5_Format: RGBA_ASTC_8x5_Format,
|
4053 | RGBA_ASTC_8x6_Format: RGBA_ASTC_8x6_Format,
|
4054 | RGBA_ASTC_8x8_Format: RGBA_ASTC_8x8_Format,
|
4055 | RGBA_BPTC_Format: RGBA_BPTC_Format,
|
4056 | RGBA_ETC2_EAC_Format: RGBA_ETC2_EAC_Format,
|
4057 | RGBA_PVRTC_2BPPV1_Format: RGBA_PVRTC_2BPPV1_Format,
|
4058 | RGBA_PVRTC_4BPPV1_Format: RGBA_PVRTC_4BPPV1_Format,
|
4059 | RGBA_S3TC_DXT1_Format: RGBA_S3TC_DXT1_Format,
|
4060 | RGBA_S3TC_DXT3_Format: RGBA_S3TC_DXT3_Format,
|
4061 | RGBA_S3TC_DXT5_Format: RGBA_S3TC_DXT5_Format,
|
4062 | RGBDEncoding: RGBDEncoding,
|
4063 | RGBEEncoding: RGBEEncoding,
|
4064 | RGBEFormat: RGBEFormat,
|
4065 | RGBFormat: RGBFormat,
|
4066 | RGBIntegerFormat: RGBIntegerFormat,
|
4067 | RGBM16Encoding: RGBM16Encoding,
|
4068 | RGBM7Encoding: RGBM7Encoding,
|
4069 | RGB_ETC1_Format: RGB_ETC1_Format,
|
4070 | RGB_ETC2_Format: RGB_ETC2_Format,
|
4071 | RGB_PVRTC_2BPPV1_Format: RGB_PVRTC_2BPPV1_Format,
|
4072 | RGB_PVRTC_4BPPV1_Format: RGB_PVRTC_4BPPV1_Format,
|
4073 | RGB_S3TC_DXT1_Format: RGB_S3TC_DXT1_Format,
|
4074 | RGFormat: RGFormat,
|
4075 | RGIntegerFormat: RGIntegerFormat,
|
4076 | RawShaderMaterial: RawShaderMaterial,
|
4077 | Ray: Ray,
|
4078 | Raycaster: Raycaster,
|
4079 | RectAreaLight: RectAreaLight,
|
4080 | RedFormat: RedFormat,
|
4081 | RedIntegerFormat: RedIntegerFormat,
|
4082 | ReinhardToneMapping: ReinhardToneMapping,
|
4083 | RepeatWrapping: RepeatWrapping,
|
4084 | ReplaceStencilOp: ReplaceStencilOp,
|
4085 | ReverseSubtractEquation: ReverseSubtractEquation,
|
4086 | RingBufferGeometry: RingBufferGeometry,
|
4087 | RingGeometry: RingGeometry,
|
4088 | SRGB8_ALPHA8_ASTC_10x10_Format: SRGB8_ALPHA8_ASTC_10x10_Format,
|
4089 | SRGB8_ALPHA8_ASTC_10x5_Format: SRGB8_ALPHA8_ASTC_10x5_Format,
|
4090 | SRGB8_ALPHA8_ASTC_10x6_Format: SRGB8_ALPHA8_ASTC_10x6_Format,
|
4091 | SRGB8_ALPHA8_ASTC_10x8_Format: SRGB8_ALPHA8_ASTC_10x8_Format,
|
4092 | SRGB8_ALPHA8_ASTC_12x10_Format: SRGB8_ALPHA8_ASTC_12x10_Format,
|
4093 | SRGB8_ALPHA8_ASTC_12x12_Format: SRGB8_ALPHA8_ASTC_12x12_Format,
|
4094 | SRGB8_ALPHA8_ASTC_4x4_Format: SRGB8_ALPHA8_ASTC_4x4_Format,
|
4095 | SRGB8_ALPHA8_ASTC_5x4_Format: SRGB8_ALPHA8_ASTC_5x4_Format,
|
4096 | SRGB8_ALPHA8_ASTC_5x5_Format: SRGB8_ALPHA8_ASTC_5x5_Format,
|
4097 | SRGB8_ALPHA8_ASTC_6x5_Format: SRGB8_ALPHA8_ASTC_6x5_Format,
|
4098 | SRGB8_ALPHA8_ASTC_6x6_Format: SRGB8_ALPHA8_ASTC_6x6_Format,
|
4099 | SRGB8_ALPHA8_ASTC_8x5_Format: SRGB8_ALPHA8_ASTC_8x5_Format,
|
4100 | SRGB8_ALPHA8_ASTC_8x6_Format: SRGB8_ALPHA8_ASTC_8x6_Format,
|
4101 | SRGB8_ALPHA8_ASTC_8x8_Format: SRGB8_ALPHA8_ASTC_8x8_Format,
|
4102 | Scene: Scene,
|
4103 | SceneUtils: SceneUtils,
|
4104 | ShaderChunk: ShaderChunk,
|
4105 | ShaderLib: ShaderLib,
|
4106 | ShaderMaterial: ShaderMaterial,
|
4107 | ShadowMaterial: ShadowMaterial,
|
4108 | Shape: Shape,
|
4109 | ShapeBufferGeometry: ShapeBufferGeometry,
|
4110 | ShapeGeometry: ShapeGeometry,
|
4111 | ShapePath: ShapePath,
|
4112 | ShapeUtils: ShapeUtils,
|
4113 | ShortType: ShortType,
|
4114 | Skeleton: Skeleton,
|
4115 | SkeletonHelper: SkeletonHelper,
|
4116 | SkinnedMesh: SkinnedMesh,
|
4117 | SmoothShading: SmoothShading,
|
4118 | Sphere: Sphere,
|
4119 | SphereBufferGeometry: SphereBufferGeometry,
|
4120 | SphereGeometry: SphereGeometry,
|
4121 | Spherical: Spherical,
|
4122 | SphericalHarmonics3: SphericalHarmonics3,
|
4123 | SphericalReflectionMapping: SphericalReflectionMapping,
|
4124 | Spline: Spline,
|
4125 | SplineCurve: SplineCurve,
|
4126 | SplineCurve3: SplineCurve3,
|
4127 | SpotLight: SpotLight,
|
4128 | SpotLightHelper: SpotLightHelper,
|
4129 | SpotLightShadow: SpotLightShadow,
|
4130 | Sprite: Sprite,
|
4131 | SpriteMaterial: SpriteMaterial,
|
4132 | SrcAlphaFactor: SrcAlphaFactor,
|
4133 | SrcAlphaSaturateFactor: SrcAlphaSaturateFactor,
|
4134 | SrcColorFactor: SrcColorFactor,
|
4135 | StaticCopyUsage: StaticCopyUsage,
|
4136 | StaticDrawUsage: StaticDrawUsage,
|
4137 | StaticReadUsage: StaticReadUsage,
|
4138 | StereoCamera: StereoCamera,
|
4139 | StreamCopyUsage: StreamCopyUsage,
|
4140 | StreamDrawUsage: StreamDrawUsage,
|
4141 | StreamReadUsage: StreamReadUsage,
|
4142 | StringKeyframeTrack: StringKeyframeTrack,
|
4143 | SubtractEquation: SubtractEquation,
|
4144 | SubtractiveBlending: SubtractiveBlending,
|
4145 | TOUCH: TOUCH,
|
4146 | TangentSpaceNormalMap: TangentSpaceNormalMap,
|
4147 | TetrahedronBufferGeometry: TetrahedronBufferGeometry,
|
4148 | TetrahedronGeometry: TetrahedronGeometry,
|
4149 | TextBufferGeometry: TextBufferGeometry,
|
4150 | TextGeometry: TextGeometry,
|
4151 | Texture: Texture,
|
4152 | TextureLoader: TextureLoader,
|
4153 | TorusBufferGeometry: TorusBufferGeometry,
|
4154 | TorusGeometry: TorusGeometry,
|
4155 | TorusKnotBufferGeometry: TorusKnotBufferGeometry,
|
4156 | TorusKnotGeometry: TorusKnotGeometry,
|
4157 | Triangle: Triangle,
|
4158 | TriangleFanDrawMode: TriangleFanDrawMode,
|
4159 | TriangleStripDrawMode: TriangleStripDrawMode,
|
4160 | TrianglesDrawMode: TrianglesDrawMode,
|
4161 | TubeBufferGeometry: TubeBufferGeometry,
|
4162 | TubeGeometry: TubeGeometry,
|
4163 | UVMapping: UVMapping,
|
4164 | Uint16Attribute: Uint16Attribute,
|
4165 | Uint16BufferAttribute: Uint16BufferAttribute,
|
4166 | Uint32Attribute: Uint32Attribute,
|
4167 | Uint32BufferAttribute: Uint32BufferAttribute,
|
4168 | Uint8Attribute: Uint8Attribute,
|
4169 | Uint8BufferAttribute: Uint8BufferAttribute,
|
4170 | Uint8ClampedAttribute: Uint8ClampedAttribute,
|
4171 | Uint8ClampedBufferAttribute: Uint8ClampedBufferAttribute,
|
4172 | Uncharted2ToneMapping: Uncharted2ToneMapping,
|
4173 | Uniform: Uniform,
|
4174 | UniformsLib: UniformsLib,
|
4175 | UniformsUtils: UniformsUtils,
|
4176 | UnsignedByteType: UnsignedByteType,
|
4177 | UnsignedInt248Type: UnsignedInt248Type,
|
4178 | UnsignedIntType: UnsignedIntType,
|
4179 | UnsignedShort4444Type: UnsignedShort4444Type,
|
4180 | UnsignedShort5551Type: UnsignedShort5551Type,
|
4181 | UnsignedShort565Type: UnsignedShort565Type,
|
4182 | UnsignedShortType: UnsignedShortType,
|
4183 | VSMShadowMap: VSMShadowMap,
|
4184 | Vector2: Vector2,
|
4185 | Vector3: Vector3,
|
4186 | Vector4: Vector4,
|
4187 | VectorKeyframeTrack: VectorKeyframeTrack,
|
4188 | Vertex: Vertex,
|
4189 | VertexColors: VertexColors,
|
4190 | VideoTexture: VideoTexture,
|
4191 | WebGLCubeRenderTarget: WebGLCubeRenderTarget,
|
4192 | WebGLMultisampleRenderTarget: WebGLMultisampleRenderTarget,
|
4193 | WebGLRenderTarget: WebGLRenderTarget,
|
4194 | WebGLRenderTargetCube: WebGLRenderTargetCube,
|
4195 | WebGLRenderer: WebGLRenderer,
|
4196 | WebGLUtils: WebGLUtils,
|
4197 | WireframeGeometry: WireframeGeometry,
|
4198 | WireframeHelper: WireframeHelper,
|
4199 | WrapAroundEnding: WrapAroundEnding,
|
4200 | XHRLoader: XHRLoader,
|
4201 | ZeroCurvatureEnding: ZeroCurvatureEnding,
|
4202 | ZeroFactor: ZeroFactor,
|
4203 | ZeroSlopeEnding: ZeroSlopeEnding,
|
4204 | ZeroStencilOp: ZeroStencilOp,
|
4205 | sRGBEncoding: sRGBEncoding
|
4206 | };
|
4207 |
|
4208 | /*
|
4209 | * Copyright (c) 2020 NAVER Corp.
|
4210 | * egjs projects are licensed under the MIT license
|
4211 | */
|
4212 | /**
|
4213 | * Renderer that renders View3D's Scene
|
4214 | * @category Core
|
4215 | */
|
4216 |
|
4217 | var Renderer =
|
4218 | /*#__PURE__*/
|
4219 | function () {
|
4220 | /**
|
4221 | * Create new Renderer instance
|
4222 | * @param canvas \<canvas\> element to render 3d model
|
4223 | */
|
4224 | function Renderer(canvas) {
|
4225 | this._canvas = canvas;
|
4226 | this._renderer = new WebGLRenderer({
|
4227 | canvas: this._canvas,
|
4228 | alpha: true,
|
4229 | antialias: true,
|
4230 | preserveDrawingBuffer: true
|
4231 | });
|
4232 | this._renderer.xr.enabled = true;
|
4233 | this._renderer.outputEncoding = sRGBEncoding;
|
4234 | this._clock = new Clock(false);
|
4235 | this.enableShadow();
|
4236 | }
|
4237 |
|
4238 | var __proto = Renderer.prototype;
|
4239 | Object.defineProperty(__proto, "canvas", {
|
4240 | /**
|
4241 | * {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement HTMLCanvasElement} given when creating View3D instance
|
4242 | * @type HTMLCanvasElement
|
4243 | * @readonly
|
4244 | */
|
4245 | get: function () {
|
4246 | return this._canvas;
|
4247 | },
|
4248 | enumerable: false,
|
4249 | configurable: true
|
4250 | });
|
4251 | Object.defineProperty(__proto, "context", {
|
4252 | /**
|
4253 | * Current {@link https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext WebGLRenderingContext}
|
4254 | * @type WebGLRenderingContext
|
4255 | * @readonly
|
4256 | */
|
4257 | get: function () {
|
4258 | return this._renderer.context;
|
4259 | },
|
4260 | enumerable: false,
|
4261 | configurable: true
|
4262 | });
|
4263 | Object.defineProperty(__proto, "size", {
|
4264 | /**
|
4265 | * The width and height of the renderer's output canvas
|
4266 | * @see https://threejs.org/docs/#api/en/math/Vector2
|
4267 | * @type THREE.Vector2
|
4268 | */
|
4269 | get: function () {
|
4270 | return this._renderer.getSize(new Vector2());
|
4271 | },
|
4272 | set: function (val) {
|
4273 | this._renderer.setSize(val.x, val.y, false);
|
4274 | },
|
4275 | enumerable: false,
|
4276 | configurable: true
|
4277 | });
|
4278 | Object.defineProperty(__proto, "threeRenderer", {
|
4279 | /**
|
4280 | * Three.js {@link https://threejs.org/docs/#api/en/renderers/WebGLRenderer WebGLRenderer} instance
|
4281 | * @type THREE.WebGLRenderer
|
4282 | * @readonly
|
4283 | */
|
4284 | get: function () {
|
4285 | return this._renderer;
|
4286 | },
|
4287 | enumerable: false,
|
4288 | configurable: true
|
4289 | });
|
4290 | /**
|
4291 | * Resize the renderer based on current canvas width / height
|
4292 | * @returns {void} Nothing
|
4293 | */
|
4294 |
|
4295 | __proto.resize = function () {
|
4296 | var renderer = this._renderer;
|
4297 | var canvas = this._canvas;
|
4298 | if (renderer.xr.isPresenting) return;
|
4299 | renderer.setPixelRatio(window.devicePixelRatio);
|
4300 | renderer.setSize(canvas.offsetWidth, canvas.offsetHeight, false);
|
4301 | };
|
4302 | /**
|
4303 | * Render a scene using a camera.
|
4304 | * @see https://threejs.org/docs/#api/en/renderers/WebGLRenderer.render
|
4305 | * @param scene {@link Scene} to render
|
4306 | * @param camera {@link Camera} to render
|
4307 | */
|
4308 |
|
4309 |
|
4310 | __proto.render = function (scene, camera) {
|
4311 | this._renderer.render(scene.root, camera.threeCamera);
|
4312 | };
|
4313 |
|
4314 | __proto.setAnimationLoop = function (callback) {
|
4315 | var _this = this;
|
4316 |
|
4317 | this._clock.start();
|
4318 |
|
4319 | this._renderer.setAnimationLoop(function (timestamp, frame) {
|
4320 | var delta = _this._clock.getDelta();
|
4321 |
|
4322 | callback(delta, frame);
|
4323 | });
|
4324 | };
|
4325 |
|
4326 | __proto.stopAnimationLoop = function () {
|
4327 | this._clock.stop(); // See https://threejs.org/docs/#api/en/renderers/WebGLRenderer.setAnimationLoop
|
4328 |
|
4329 |
|
4330 | this._renderer.setAnimationLoop(null);
|
4331 | };
|
4332 | /**
|
4333 | * Enable shadow map
|
4334 | */
|
4335 |
|
4336 |
|
4337 | __proto.enableShadow = function () {
|
4338 | var threeRenderer = this._renderer;
|
4339 | threeRenderer.shadowMap.enabled = true;
|
4340 | threeRenderer.shadowMap.type = PCFSoftShadowMap;
|
4341 | };
|
4342 | /**
|
4343 | * Disable shadow map
|
4344 | */
|
4345 |
|
4346 |
|
4347 | __proto.disableShadow = function () {
|
4348 | var threeRenderer = this._renderer;
|
4349 | threeRenderer.shadowMap.enabled = false;
|
4350 | };
|
4351 |
|
4352 | return Renderer;
|
4353 | }();
|
4354 |
|
4355 | /*
|
4356 | * Copyright (c) 2020 NAVER Corp.
|
4357 | * egjs projects are licensed under the MIT license
|
4358 | */
|
4359 | // Constants that used internally
|
4360 | // Texture map names that used in THREE#MeshStandardMaterial
|
4361 | var STANDARD_MAPS = ["alphaMap", "aoMap", "bumpMap", "displacementMap", "emissiveMap", "envMap", "lightMap", "map", "metalnessMap", "normalMap", "roughnessMap"];
|
4362 |
|
4363 | /*
|
4364 | * Copyright (c) 2020 NAVER Corp.
|
4365 | * egjs projects are licensed under the MIT license
|
4366 | */
|
4367 |
|
4368 | var View3DError =
|
4369 | /*#__PURE__*/
|
4370 | function (_super) {
|
4371 | __extends(View3DError, _super);
|
4372 |
|
4373 | function View3DError(message, code) {
|
4374 | var _this = _super.call(this, message) || this;
|
4375 |
|
4376 | _this.message = message;
|
4377 | _this.code = code;
|
4378 | Object.setPrototypeOf(_this, View3DError.prototype);
|
4379 | _this.name = "View3DError";
|
4380 | return _this;
|
4381 | }
|
4382 |
|
4383 | return View3DError;
|
4384 | }(Error);
|
4385 |
|
4386 | /*
|
4387 | * Copyright (c) 2020 NAVER Corp.
|
4388 | * egjs projects are licensed under the MIT license
|
4389 | */
|
4390 |
|
4391 | /**
|
4392 | * Error codes of {@link View3DError}
|
4393 | * @name ERROR_CODES
|
4394 | * @memberof Constants
|
4395 | * @type object
|
4396 | * @property {number} WRONG_TYPE 0
|
4397 | * @property {number} ELEMENT_NOT_FOUND 1
|
4398 | * @property {number} CANVAS_NOT_FOUND 2
|
4399 | * @property {number} WEBGL_NOT_SUPPORTED 3
|
4400 | * @property {number} ADD_CONTROL_FIRST 4
|
4401 | * @property {number} PROVIDE_WIDTH_OR_HEIGHT 5
|
4402 | */
|
4403 | var CODES = {
|
4404 | WRONG_TYPE: 0,
|
4405 | ELEMENT_NOT_FOUND: 1,
|
4406 | ELEMENT_NOT_CANVAS: 2,
|
4407 | WEBGL_NOT_SUPPORTED: 3,
|
4408 | ADD_CONTROL_FIRST: 4,
|
4409 | PROVIDE_WIDTH_OR_HEIGHT: 5
|
4410 | };
|
4411 | var MESSAGES = {
|
4412 | WRONG_TYPE: function (val, types) {
|
4413 | return typeof val + " is not a " + types.map(function (type) {
|
4414 | return "\"" + type + "\"";
|
4415 | }).join(" or ") + ".";
|
4416 | },
|
4417 | ELEMENT_NOT_FOUND: function (query) {
|
4418 | return "Element with selector \"" + query + "\" not found.";
|
4419 | },
|
4420 | ELEMENT_NOT_CANVAS: function (el) {
|
4421 | return "Given element <" + el.tagName + "> is not a canvas.";
|
4422 | },
|
4423 | WEBGL_NOT_SUPPORTED: "WebGL is not supported on this browser.",
|
4424 | ADD_CONTROL_FIRST: "Control is enabled before setting a target element.",
|
4425 | PROVIDE_WIDTH_OR_HEIGHT: "Either width or height should be given."
|
4426 | };
|
4427 |
|
4428 | /*
|
4429 | * Copyright (c) 2020 NAVER Corp.
|
4430 | * egjs projects are licensed under the MIT license
|
4431 | */
|
4432 | function getElement(el, parent) {
|
4433 | var targetEl = null;
|
4434 |
|
4435 | if (typeof el === "string") {
|
4436 | var parentEl = parent ? parent : document;
|
4437 | var queryResult = parentEl.querySelector(el);
|
4438 |
|
4439 | if (!queryResult) {
|
4440 | throw new View3DError(MESSAGES.ELEMENT_NOT_FOUND(el), CODES.ELEMENT_NOT_FOUND);
|
4441 | }
|
4442 |
|
4443 | targetEl = queryResult;
|
4444 | } else if (el && el.nodeType === Node.ELEMENT_NODE) {
|
4445 | targetEl = el;
|
4446 | }
|
4447 |
|
4448 | return targetEl;
|
4449 | }
|
4450 | function getCanvas(el) {
|
4451 | var targetEl = getElement(el);
|
4452 |
|
4453 | if (!targetEl) {
|
4454 | throw new View3DError(MESSAGES.WRONG_TYPE(el, ["HTMLElement", "string"]), CODES.WRONG_TYPE);
|
4455 | }
|
4456 |
|
4457 | if (!/^canvas$/i.test(targetEl.tagName)) {
|
4458 | throw new View3DError(MESSAGES.ELEMENT_NOT_CANVAS(targetEl), CODES.ELEMENT_NOT_CANVAS);
|
4459 | }
|
4460 |
|
4461 | return targetEl;
|
4462 | }
|
4463 | function range(end) {
|
4464 | if (!end || end <= 0) {
|
4465 | return [];
|
4466 | }
|
4467 |
|
4468 | return Array.apply(0, Array(end)).map(function (undef, idx) {
|
4469 | return idx;
|
4470 | });
|
4471 | }
|
4472 | function toRadian(x) {
|
4473 | return x * Math.PI / 180;
|
4474 | }
|
4475 | function clamp(x, min, max) {
|
4476 | return Math.max(Math.min(x, max), min);
|
4477 | }
|
4478 | function findIndex(target, list) {
|
4479 | var e_1, _a;
|
4480 |
|
4481 | var index = -1;
|
4482 |
|
4483 | try {
|
4484 | for (var _b = __values(range(list.length)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
4485 | var itemIndex = _c.value;
|
4486 |
|
4487 | if (list[itemIndex] === target) {
|
4488 | index = itemIndex;
|
4489 | break;
|
4490 | }
|
4491 | }
|
4492 | } catch (e_1_1) {
|
4493 | e_1 = {
|
4494 | error: e_1_1
|
4495 | };
|
4496 | } finally {
|
4497 | try {
|
4498 | if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
4499 | } finally {
|
4500 | if (e_1) throw e_1.error;
|
4501 | }
|
4502 | }
|
4503 |
|
4504 | return index;
|
4505 | } // Linear interpolation between a and b
|
4506 |
|
4507 | function mix(a, b, t) {
|
4508 | return a * (1 - t) + b * t;
|
4509 | }
|
4510 | function circulate(val, min, max) {
|
4511 | var size = Math.abs(max - min);
|
4512 |
|
4513 | if (val < min) {
|
4514 | var offset = (min - val) % size;
|
4515 | val = max - offset;
|
4516 | } else if (val > max) {
|
4517 | var offset = (val - max) % size;
|
4518 | val = min + offset;
|
4519 | }
|
4520 |
|
4521 | return val;
|
4522 | }
|
4523 | function merge(target) {
|
4524 | var srcs = [];
|
4525 |
|
4526 | for (var _i = 1; _i < arguments.length; _i++) {
|
4527 | srcs[_i - 1] = arguments[_i];
|
4528 | }
|
4529 |
|
4530 | srcs.forEach(function (source) {
|
4531 | Object.keys(source).forEach(function (key) {
|
4532 | var value = source[key];
|
4533 |
|
4534 | if (Array.isArray(target[key]) && Array.isArray(value)) {
|
4535 | target[key] = __spread(target[key], value);
|
4536 | } else {
|
4537 | target[key] = value;
|
4538 | }
|
4539 | });
|
4540 | });
|
4541 | return target;
|
4542 | }
|
4543 | function getBoxPoints(box) {
|
4544 | return [box.min.clone(), new Vector3(box.min.x, box.min.y, box.max.z), new Vector3(box.min.x, box.max.y, box.min.z), new Vector3(box.min.x, box.max.y, box.max.z), new Vector3(box.max.x, box.min.y, box.min.z), new Vector3(box.max.x, box.min.y, box.max.z), new Vector3(box.max.x, box.max.y, box.min.z), box.max.clone()];
|
4545 | }
|
4546 | function toPowerOfTwo(val) {
|
4547 | var result = 1;
|
4548 |
|
4549 | while (result < val) {
|
4550 | result *= 2;
|
4551 | }
|
4552 |
|
4553 | return result;
|
4554 | }
|
4555 | function getPrimaryAxisIndex(basis, viewDir) {
|
4556 | var primaryIdx = 0;
|
4557 | var maxDot = 0;
|
4558 | basis.forEach(function (axes, axesIdx) {
|
4559 | var dotProduct = Math.abs(viewDir.dot(axes));
|
4560 |
|
4561 | if (dotProduct > maxDot) {
|
4562 | primaryIdx = axesIdx;
|
4563 | maxDot = dotProduct;
|
4564 | }
|
4565 | });
|
4566 | return primaryIdx;
|
4567 | } // In radian
|
4568 |
|
4569 | function getRotationAngle(center, v1, v2) {
|
4570 | var centerToV1 = new Vector2().subVectors(v1, center).normalize();
|
4571 | var centerToV2 = new Vector2().subVectors(v2, center).normalize(); // Get the rotation angle with the model's NDC coordinates as the center.
|
4572 |
|
4573 | var deg = centerToV2.angle() - centerToV1.angle();
|
4574 | var compDeg = -Math.sign(deg) * (2 * Math.PI - Math.abs(deg)); // Take the smaller deg
|
4575 |
|
4576 | var rotationAngle = Math.abs(deg) < Math.abs(compDeg) ? deg : compDeg;
|
4577 | return rotationAngle;
|
4578 | }
|
4579 |
|
4580 | /*
|
4581 | * Copyright (c) 2020 NAVER Corp.
|
4582 | * egjs projects are licensed under the MIT license
|
4583 | */
|
4584 | /**
|
4585 | * Scene that View3D will render.
|
4586 | * All model datas including Mesh, Lights, etc. will be included on this
|
4587 | * @category Core
|
4588 | */
|
4589 |
|
4590 | var Scene$1 =
|
4591 | /*#__PURE__*/
|
4592 | function () {
|
4593 | /**
|
4594 | * Create new Scene instance
|
4595 | */
|
4596 | function Scene$1() {
|
4597 | this._root = new Scene();
|
4598 | this._userObjects = new Group();
|
4599 | this._envObjects = new Group();
|
4600 | this._envs = [];
|
4601 | var root = this._root;
|
4602 | var userObjects = this._userObjects;
|
4603 | var envObjects = this._envObjects;
|
4604 | userObjects.name = "userObjects";
|
4605 | envObjects.name = "envObjects";
|
4606 | root.add(userObjects);
|
4607 | root.add(envObjects);
|
4608 | }
|
4609 |
|
4610 | var __proto = Scene$1.prototype;
|
4611 | Object.defineProperty(__proto, "root", {
|
4612 | /**
|
4613 | * Root {@link https://threejs.org/docs/#api/en/scenes/Scene THREE.Scene} object
|
4614 | */
|
4615 | get: function () {
|
4616 | return this._root;
|
4617 | },
|
4618 | enumerable: false,
|
4619 | configurable: true
|
4620 | });
|
4621 | Object.defineProperty(__proto, "environments", {
|
4622 | /**
|
4623 | * {@link Environment}s inside scene
|
4624 | */
|
4625 | get: function () {
|
4626 | return this._envs;
|
4627 | },
|
4628 | enumerable: false,
|
4629 | configurable: true
|
4630 | });
|
4631 | Object.defineProperty(__proto, "visible", {
|
4632 | /**
|
4633 | * Return the visibility of the root scene
|
4634 | */
|
4635 | get: function () {
|
4636 | return this._root.visible;
|
4637 | },
|
4638 | enumerable: false,
|
4639 | configurable: true
|
4640 | });
|
4641 | /**
|
4642 | * Update scene to fit the given model
|
4643 | * @param model model to fit
|
4644 | * @param override options for specific environments
|
4645 | */
|
4646 |
|
4647 | __proto.update = function (model, override) {
|
4648 | this._envs.forEach(function (env) {
|
4649 | return env.fit(model, override);
|
4650 | });
|
4651 | };
|
4652 | /**
|
4653 | * Reset scene to initial state
|
4654 | * @returns {void} Nothing
|
4655 | */
|
4656 |
|
4657 |
|
4658 | __proto.reset = function () {
|
4659 | this.resetModel();
|
4660 | this.resetEnv();
|
4661 | };
|
4662 | /**
|
4663 | * Fully remove all objects that added by calling {@link Scene#add add()}
|
4664 | * @returns {void} Nothing
|
4665 | */
|
4666 |
|
4667 |
|
4668 | __proto.resetModel = function () {
|
4669 | this._removeChildsOf(this._userObjects);
|
4670 | };
|
4671 | /**
|
4672 | * Remove all objects that added by calling {@link Scene#addEnv addEnv()}
|
4673 | * This will also reset scene background & envmap
|
4674 | * @returns {void} Nothing
|
4675 | */
|
4676 |
|
4677 |
|
4678 | __proto.resetEnv = function () {
|
4679 | this._removeChildsOf(this._envObjects);
|
4680 |
|
4681 | this._envs = [];
|
4682 | this._root.background = null;
|
4683 | this._root.environment = null;
|
4684 | };
|
4685 | /**
|
4686 | * Add new Three.js {@link https://threejs.org/docs/#api/en/core/Object3D Object3D} into the scene
|
4687 | * @param object {@link https://threejs.org/docs/#api/en/core/Object3D THREE.Object3D}s to add
|
4688 | * @returns {void} Nothing
|
4689 | */
|
4690 |
|
4691 |
|
4692 | __proto.add = function () {
|
4693 | var _a;
|
4694 |
|
4695 | var object = [];
|
4696 |
|
4697 | for (var _i = 0; _i < arguments.length; _i++) {
|
4698 | object[_i] = arguments[_i];
|
4699 | }
|
4700 |
|
4701 | (_a = this._userObjects).add.apply(_a, __spread(object));
|
4702 | };
|
4703 | /**
|
4704 | * Add new {@link Environment} or Three.js {@link https://threejs.org/docs/#api/en/core/Object3D Object3D}s to the scene, which won't be removed after displaying another 3D model
|
4705 | * @param envs {@link Environment} | {@link https://threejs.org/docs/#api/en/core/Object3D THREE.Object3D}s to add
|
4706 | * @returns {void} Nothing
|
4707 | */
|
4708 |
|
4709 |
|
4710 | __proto.addEnv = function () {
|
4711 | var _this = this;
|
4712 |
|
4713 | var envs = [];
|
4714 |
|
4715 | for (var _i = 0; _i < arguments.length; _i++) {
|
4716 | envs[_i] = arguments[_i];
|
4717 | }
|
4718 |
|
4719 | envs.forEach(function (env) {
|
4720 | var _a;
|
4721 |
|
4722 | if (env.isObject3D) {
|
4723 | _this._envObjects.add(env);
|
4724 | } else {
|
4725 | _this._envs.push(env);
|
4726 |
|
4727 | (_a = _this._envObjects).add.apply(_a, __spread(env.objects));
|
4728 | }
|
4729 | });
|
4730 | };
|
4731 | /**
|
4732 | * Remove Three.js {@link https://threejs.org/docs/#api/en/core/Object3D Object3D} into the scene
|
4733 | * @param object {@link https://threejs.org/docs/#api/en/core/Object3D THREE.Object3D}s to add
|
4734 | * @returns {void} Nothing
|
4735 | */
|
4736 |
|
4737 |
|
4738 | __proto.remove = function () {
|
4739 | var _a;
|
4740 |
|
4741 | var object = [];
|
4742 |
|
4743 | for (var _i = 0; _i < arguments.length; _i++) {
|
4744 | object[_i] = arguments[_i];
|
4745 | }
|
4746 |
|
4747 | (_a = this._userObjects).remove.apply(_a, __spread(object));
|
4748 | };
|
4749 | /**
|
4750 | * Remove {@link Environment} or Three.js {@link https://threejs.org/docs/#api/en/core/Object3D Object3D}s to the scene, which won't be removed after displaying another 3D model
|
4751 | * @param envs {@link Environment} | {@link https://threejs.org/docs/#api/en/core/Object3D THREE.Object3D}s to add
|
4752 | * @returns {void} Nothing
|
4753 | */
|
4754 |
|
4755 |
|
4756 | __proto.removeEnv = function () {
|
4757 | var _this = this;
|
4758 |
|
4759 | var envs = [];
|
4760 |
|
4761 | for (var _i = 0; _i < arguments.length; _i++) {
|
4762 | envs[_i] = arguments[_i];
|
4763 | }
|
4764 |
|
4765 | envs.forEach(function (env) {
|
4766 | var _a;
|
4767 |
|
4768 | if (env.isObject3D) {
|
4769 | _this._envObjects.remove(env);
|
4770 | } else {
|
4771 | var envIndex = findIndex(env, _this._envs);
|
4772 |
|
4773 | if (envIndex > -1) {
|
4774 | _this._envs.splice(envIndex, 1);
|
4775 | }
|
4776 |
|
4777 | (_a = _this._envObjects).remove.apply(_a, __spread(env.objects));
|
4778 | }
|
4779 | });
|
4780 | };
|
4781 | /**
|
4782 | * Set background of the scene.
|
4783 | * @see {@link https://threejs.org/docs/#api/en/scenes/Scene.background THREE.Scene.background}
|
4784 | * @param background A texture to set as background
|
4785 | * @returns {void} Nothing
|
4786 | */
|
4787 |
|
4788 |
|
4789 | __proto.setBackground = function (background) {
|
4790 | // Three.js's type definition does not include WebGLCubeRenderTarget, but it works and defined on their document
|
4791 | // See https://threejs.org/docs/#api/en/scenes/Scene.background
|
4792 | this._root.background = background;
|
4793 | };
|
4794 | /**
|
4795 | * Set scene's environment map that affects all physical materials in the scene
|
4796 | * @see {@link https://threejs.org/docs/#api/en/scenes/Scene.environment THREE.Scene.environment}
|
4797 | * @param envmap A texture to set as environment map
|
4798 | * @returns {void} Nothing
|
4799 | */
|
4800 |
|
4801 |
|
4802 | __proto.setEnvMap = function (envmap) {
|
4803 | // Next line written to silence Three.js's warning
|
4804 | var environment = envmap.texture ? envmap.texture : envmap;
|
4805 | this._root.environment = environment;
|
4806 | };
|
4807 | /**
|
4808 | * Make this scene visible
|
4809 | * @returns {void} Nothing
|
4810 | */
|
4811 |
|
4812 |
|
4813 | __proto.show = function () {
|
4814 | this._root.visible = true;
|
4815 | };
|
4816 | /**
|
4817 | * Make this scene invisible
|
4818 | * @returns {void} Nothing
|
4819 | */
|
4820 |
|
4821 |
|
4822 | __proto.hide = function () {
|
4823 | this._root.visible = false;
|
4824 | };
|
4825 |
|
4826 | __proto._removeChildsOf = function (obj) {
|
4827 | obj.traverse(function (child) {
|
4828 | if (child.isMesh) {
|
4829 | var mesh = child; // Release geometry & material memory
|
4830 |
|
4831 | mesh.geometry.dispose();
|
4832 | var materials = Array.isArray(mesh.material) ? mesh.material : [mesh.material];
|
4833 | materials.forEach(function (mat) {
|
4834 | STANDARD_MAPS.forEach(function (map) {
|
4835 | if (mat[map]) {
|
4836 | mat[map].dispose();
|
4837 | }
|
4838 | });
|
4839 | });
|
4840 | }
|
4841 | });
|
4842 |
|
4843 | while (obj.children.length > 0) {
|
4844 | obj.remove(obj.children[0]);
|
4845 | }
|
4846 | };
|
4847 |
|
4848 | return Scene$1;
|
4849 | }();
|
4850 |
|
4851 | /*
|
4852 | * Copyright (c) 2020 NAVER Corp.
|
4853 | * egjs projects are licensed under the MIT license
|
4854 | */
|
4855 | /**
|
4856 | * Controller that controls camera of the View3D
|
4857 | * @category Core
|
4858 | */
|
4859 |
|
4860 | var Controller =
|
4861 | /*#__PURE__*/
|
4862 | function () {
|
4863 | /**
|
4864 | * Create new Controller instance
|
4865 | */
|
4866 | function Controller(canvas, camera) {
|
4867 | this._controls = [];
|
4868 | this._canvas = canvas;
|
4869 | this._camera = camera;
|
4870 | }
|
4871 |
|
4872 | var __proto = Controller.prototype;
|
4873 | Object.defineProperty(__proto, "controls", {
|
4874 | /**
|
4875 | * {@link CameraControl CameraControl} instances that is added on this controller.
|
4876 | */
|
4877 | get: function () {
|
4878 | return this._controls;
|
4879 | },
|
4880 | enumerable: false,
|
4881 | configurable: true
|
4882 | });
|
4883 | /**
|
4884 | * Remove all attached controls, and removes all event listeners attached by that controls.
|
4885 | * @returns {void} Nothing
|
4886 | */
|
4887 |
|
4888 | __proto.clear = function () {
|
4889 | this._controls.forEach(function (control) {
|
4890 | return control.destroy();
|
4891 | });
|
4892 |
|
4893 | this._controls = [];
|
4894 | };
|
4895 | /**
|
4896 | * Add a new control
|
4897 | * @param control {@link CameraControl CameraControl} instance to add
|
4898 | * @see Adding Controls
|
4899 | * @returns {void} Nothing
|
4900 | */
|
4901 |
|
4902 |
|
4903 | __proto.add = function (control) {
|
4904 | var canvas = this._canvas;
|
4905 |
|
4906 | if (!control.element) {
|
4907 | // Set canvas as default element
|
4908 | control.setElement(canvas);
|
4909 | }
|
4910 |
|
4911 | control.sync(this._camera);
|
4912 | control.enable();
|
4913 |
|
4914 | this._controls.push(control);
|
4915 | };
|
4916 | /**
|
4917 | * Remove control and disable it
|
4918 | * @param control {@link CameraControl CameraControl} instance to remove
|
4919 | * @returns removed control or null if it doesn't exists
|
4920 | */
|
4921 |
|
4922 |
|
4923 | __proto.remove = function (control) {
|
4924 | var controls = this._controls;
|
4925 | var controlIndex = findIndex(control, controls);
|
4926 | if (controlIndex < 0) return null;
|
4927 | var removedControl = controls.splice(controlIndex, 1)[0];
|
4928 | removedControl.disable();
|
4929 | return removedControl;
|
4930 | };
|
4931 | /**
|
4932 | * Enable all controls attached
|
4933 | * @returns {void} Nothing
|
4934 | */
|
4935 |
|
4936 |
|
4937 | __proto.enableAll = function () {
|
4938 | this._controls.forEach(function (control) {
|
4939 | return control.enable();
|
4940 | });
|
4941 |
|
4942 | this.syncToCamera();
|
4943 | };
|
4944 | /**
|
4945 | * Disable all controls attached
|
4946 | * @returns {void} Nothing
|
4947 | */
|
4948 |
|
4949 |
|
4950 | __proto.disableAll = function () {
|
4951 | this._controls.forEach(function (control) {
|
4952 | return control.disable();
|
4953 | });
|
4954 | };
|
4955 | /**
|
4956 | * Update all controls attached to given screen size.
|
4957 | * @param size Size of the screen. Noramlly size of the canvas is used.
|
4958 | * @returns {void} Nothing
|
4959 | */
|
4960 |
|
4961 |
|
4962 | __proto.resize = function (size) {
|
4963 | this._controls.forEach(function (control) {
|
4964 | return control.resize(size);
|
4965 | });
|
4966 | };
|
4967 | /**
|
4968 | * Synchronize all controls attached to current camera position.
|
4969 | * @returns {void} Nothing
|
4970 | */
|
4971 |
|
4972 |
|
4973 | __proto.syncToCamera = function () {
|
4974 | var _this = this;
|
4975 |
|
4976 | this._controls.forEach(function (control) {
|
4977 | return control.sync(_this._camera);
|
4978 | });
|
4979 | };
|
4980 | /**
|
4981 | * Update all controls attached to this controller & update camera position based on it.
|
4982 | * @param delta number of seconds to update controls
|
4983 | * @returns {void} Nothing
|
4984 | */
|
4985 |
|
4986 |
|
4987 | __proto.update = function (delta) {
|
4988 | var deltaMiliSec = delta * 1000;
|
4989 | var camera = this._camera;
|
4990 |
|
4991 | this._controls.forEach(function (control) {
|
4992 | control.update(camera, deltaMiliSec);
|
4993 | });
|
4994 |
|
4995 | camera.updatePosition();
|
4996 | };
|
4997 |
|
4998 | return Controller;
|
4999 | }();
|
5000 |
|
5001 | /*
|
5002 | * Copyright (c) 2020 NAVER Corp.
|
5003 | * egjs projects are licensed under the MIT license
|
5004 | */
|
5005 | /**
|
5006 | * Data class of camera's pose
|
5007 | */
|
5008 |
|
5009 | var Pose =
|
5010 | /*#__PURE__*/
|
5011 | function () {
|
5012 | /**
|
5013 | * Create new instance of pose
|
5014 | * @param yaw yaw
|
5015 | * @param pitch pitch
|
5016 | * @param distance distance
|
5017 | * @param pivot pivot
|
5018 | * @see https://threejs.org/docs/#api/en/math/Vector3
|
5019 | * @example
|
5020 | * import { THREE, Pose } from "@egjs/view3d";
|
5021 | *
|
5022 | * const pose = new Pose(180, 45, 150, new THREE.Vector3(5, -1, 3));
|
5023 | */
|
5024 | function Pose(yaw, pitch, distance, pivot) {
|
5025 | if (pivot === void 0) {
|
5026 | pivot = new Vector3(0, 0, 0);
|
5027 | }
|
5028 |
|
5029 | this.yaw = yaw;
|
5030 | this.pitch = pitch;
|
5031 | this.distance = distance;
|
5032 | this.pivot = pivot;
|
5033 | }
|
5034 | /**
|
5035 | * Clone this pose
|
5036 | * @returns Cloned pose
|
5037 | */
|
5038 |
|
5039 |
|
5040 | var __proto = Pose.prototype;
|
5041 |
|
5042 | __proto.clone = function () {
|
5043 | return new Pose(this.yaw, this.pitch, this.distance, this.pivot.clone());
|
5044 | };
|
5045 |
|
5046 | return Pose;
|
5047 | }();
|
5048 |
|
5049 | /*
|
5050 | * Copyright (c) 2020 NAVER Corp.
|
5051 | * egjs projects are licensed under the MIT license
|
5052 | */
|
5053 |
|
5054 | /**
|
5055 | * Collection of easing functions
|
5056 | * @namespace EASING
|
5057 | * @example
|
5058 | * import View3D, { RotateControl, EASING } from "@egjs/view3d";
|
5059 | *
|
5060 | * new RotateControl({
|
5061 | * easing: EASING.EASE_OUT_CUBIC,
|
5062 | * });
|
5063 | */
|
5064 |
|
5065 | /**
|
5066 | * @memberof EASING
|
5067 | * @name SINE_WAVE
|
5068 | */
|
5069 | var SINE_WAVE = function (x) {
|
5070 | return Math.sin(x * Math.PI * 2);
|
5071 | };
|
5072 | /**
|
5073 | * @memberof EASING
|
5074 | * @name EASE_OUT_CUBIC
|
5075 | */
|
5076 |
|
5077 | var EASE_OUT_CUBIC = function (x) {
|
5078 | return 1 - Math.pow(1 - x, 3);
|
5079 | };
|
5080 | /**
|
5081 | * @memberof EASING
|
5082 | * @name EASE_OUT_BOUNCE
|
5083 | */
|
5084 |
|
5085 | var EASE_OUT_BOUNCE = function (x) {
|
5086 | var n1 = 7.5625;
|
5087 | var d1 = 2.75;
|
5088 |
|
5089 | if (x < 1 / d1) {
|
5090 | return n1 * x * x;
|
5091 | } else if (x < 2 / d1) {
|
5092 | return n1 * (x -= 1.5 / d1) * x + 0.75;
|
5093 | } else if (x < 2.5 / d1) {
|
5094 | return n1 * (x -= 2.25 / d1) * x + 0.9375;
|
5095 | } else {
|
5096 | return n1 * (x -= 2.625 / d1) * x + 0.984375;
|
5097 | }
|
5098 | };
|
5099 |
|
5100 | var EASING = {
|
5101 | __proto__: null,
|
5102 | SINE_WAVE: SINE_WAVE,
|
5103 | EASE_OUT_CUBIC: EASE_OUT_CUBIC,
|
5104 | EASE_OUT_BOUNCE: EASE_OUT_BOUNCE
|
5105 | };
|
5106 |
|
5107 | /*
|
5108 | * Copyright (c) 2020 NAVER Corp.
|
5109 | * egjs projects are licensed under the MIT license
|
5110 | */
|
5111 | var MODEL_SIZE = 80; // Animation related
|
5112 |
|
5113 | var EASING$1 = EASE_OUT_CUBIC;
|
5114 | var ANIMATION_DURATION = 500;
|
5115 | var ANIMATION_LOOP = false;
|
5116 | var ANIMATION_RANGE = {
|
5117 | min: 0,
|
5118 | max: 1
|
5119 | }; // Camera related
|
5120 |
|
5121 | var CAMERA_POSE = new Pose(0, 0, 100, new Vector3(0, 0, 0));
|
5122 | var INFINITE_RANGE = {
|
5123 | min: -Infinity,
|
5124 | max: Infinity
|
5125 | };
|
5126 | var PITCH_RANGE = {
|
5127 | min: -89.9,
|
5128 | max: 89.9
|
5129 | };
|
5130 | var DISTANCE_RANGE = {
|
5131 | min: 0,
|
5132 | max: 500
|
5133 | };
|
5134 | var MINIMUM_DISTANCE = 1;
|
5135 | var MAXIMUM_DISTANCE = 500;
|
5136 | var NULL_ELEMENT = null;
|
5137 | var DRACO_DECODER_URL = "https://www.gstatic.com/draco/v1/decoders/";
|
5138 |
|
5139 | /*
|
5140 | * Copyright (c) 2020 NAVER Corp.
|
5141 | * egjs projects are licensed under the MIT license
|
5142 | */
|
5143 |
|
5144 | var Motion =
|
5145 | /*#__PURE__*/
|
5146 | function () {
|
5147 | function Motion(_a) {
|
5148 | var _b = _a === void 0 ? {} : _a,
|
5149 | _c = _b.duration,
|
5150 | duration = _c === void 0 ? ANIMATION_DURATION : _c,
|
5151 | _d = _b.loop,
|
5152 | loop = _d === void 0 ? ANIMATION_LOOP : _d,
|
5153 | _e = _b.range,
|
5154 | range = _e === void 0 ? ANIMATION_RANGE : _e,
|
5155 | _f = _b.easing,
|
5156 | easing = _f === void 0 ? EASING$1 : _f;
|
5157 |
|
5158 | this._duration = duration;
|
5159 | this._loop = loop;
|
5160 | this._range = range;
|
5161 | this._easing = easing;
|
5162 | this._activated = false;
|
5163 | this.reset(0);
|
5164 | }
|
5165 |
|
5166 | var __proto = Motion.prototype;
|
5167 | Object.defineProperty(__proto, "val", {
|
5168 | get: function () {
|
5169 | return this._val;
|
5170 | },
|
5171 | enumerable: false,
|
5172 | configurable: true
|
5173 | });
|
5174 | Object.defineProperty(__proto, "start", {
|
5175 | get: function () {
|
5176 | return this._start;
|
5177 | },
|
5178 | enumerable: false,
|
5179 | configurable: true
|
5180 | });
|
5181 | Object.defineProperty(__proto, "end", {
|
5182 | get: function () {
|
5183 | return this._end;
|
5184 | },
|
5185 | enumerable: false,
|
5186 | configurable: true
|
5187 | });
|
5188 | Object.defineProperty(__proto, "progress", {
|
5189 | get: function () {
|
5190 | return this._progress;
|
5191 | },
|
5192 | enumerable: false,
|
5193 | configurable: true
|
5194 | });
|
5195 | Object.defineProperty(__proto, "duration", {
|
5196 | get: function () {
|
5197 | return this._duration;
|
5198 | },
|
5199 | set: function (val) {
|
5200 | this._duration = val;
|
5201 | },
|
5202 | enumerable: false,
|
5203 | configurable: true
|
5204 | });
|
5205 | Object.defineProperty(__proto, "loop", {
|
5206 | get: function () {
|
5207 | return this._loop;
|
5208 | },
|
5209 | set: function (val) {
|
5210 | this._loop = val;
|
5211 | },
|
5212 | enumerable: false,
|
5213 | configurable: true
|
5214 | });
|
5215 | Object.defineProperty(__proto, "range", {
|
5216 | get: function () {
|
5217 | return this._range;
|
5218 | },
|
5219 | set: function (val) {
|
5220 | this._range = val;
|
5221 | },
|
5222 | enumerable: false,
|
5223 | configurable: true
|
5224 | });
|
5225 | Object.defineProperty(__proto, "easing", {
|
5226 | get: function () {
|
5227 | return this._easing;
|
5228 | },
|
5229 | set: function (val) {
|
5230 | this._easing = val;
|
5231 | },
|
5232 | enumerable: false,
|
5233 | configurable: true
|
5234 | });
|
5235 | /**
|
5236 | * Update motion and progress it by given deltaTime
|
5237 | * @param deltaTime number of milisec to update motion
|
5238 | * @returns Difference(delta) of the value from the last update.
|
5239 | */
|
5240 |
|
5241 | __proto.update = function (deltaTime) {
|
5242 | if (!this._activated) return 0;
|
5243 | var start = this._start;
|
5244 | var end = this._end;
|
5245 | var duration = this._duration;
|
5246 | var prev = this._val;
|
5247 | var loop = this._loop;
|
5248 | var nextProgress = this._progress + deltaTime / duration;
|
5249 | this._progress = loop ? circulate(nextProgress, 0, 1) : clamp(nextProgress, 0, 1);
|
5250 |
|
5251 | var easedProgress = this._easing(this._progress);
|
5252 |
|
5253 | this._val = mix(start, end, easedProgress);
|
5254 |
|
5255 | if (!loop && this._progress >= 1) {
|
5256 | this._activated = false;
|
5257 | }
|
5258 |
|
5259 | return this._val - prev;
|
5260 | };
|
5261 |
|
5262 | __proto.reset = function (defaultVal) {
|
5263 | var range = this._range;
|
5264 | var val = clamp(defaultVal, range.min, range.max);
|
5265 | this._start = val;
|
5266 | this._end = val;
|
5267 | this._val = val;
|
5268 | this._progress = 0;
|
5269 | this._activated = false;
|
5270 | };
|
5271 |
|
5272 | __proto.setEndDelta = function (delta) {
|
5273 | var range = this._range;
|
5274 | this._start = this._val;
|
5275 | this._end = clamp(this._end + delta, range.min, range.max);
|
5276 | this._progress = 0;
|
5277 | this._activated = true;
|
5278 | };
|
5279 |
|
5280 | return Motion;
|
5281 | }();
|
5282 |
|
5283 | /*
|
5284 | * Copyright (c) 2020 NAVER Corp.
|
5285 | * egjs projects are licensed under the MIT license
|
5286 | */
|
5287 | /**
|
5288 | * Control that animates model without user input
|
5289 | * @category Controls
|
5290 | */
|
5291 |
|
5292 | var AnimationControl =
|
5293 | /*#__PURE__*/
|
5294 | function () {
|
5295 | /**
|
5296 | * Create new instance of AnimationControl
|
5297 | * @param from Start pose
|
5298 | * @param to End pose
|
5299 | * @param {object} options Options
|
5300 | * @param {number} [options.duration=500] Animation duration
|
5301 | * @param {function} [options.easing=(x: number) => 1 - Math.pow(1 - x, 3)] Animation easing function
|
5302 | */
|
5303 | function AnimationControl(from, to, _a) {
|
5304 | var _b = _a === void 0 ? {} : _a,
|
5305 | _c = _b.duration,
|
5306 | duration = _c === void 0 ? ANIMATION_DURATION : _c,
|
5307 | _d = _b.easing,
|
5308 | easing = _d === void 0 ? EASING$1 : _d;
|
5309 |
|
5310 | this._enabled = false;
|
5311 | this._finishCallbacks = [];
|
5312 | from = from.clone();
|
5313 | to = to.clone();
|
5314 | from.yaw = circulate(from.yaw, 0, 360);
|
5315 | to.yaw = circulate(to.yaw, 0, 360); // Take the smaller degree
|
5316 |
|
5317 | if (Math.abs(to.yaw - from.yaw) > 180) {
|
5318 | to.yaw = to.yaw < from.yaw ? to.yaw + 360 : to.yaw - 360;
|
5319 | }
|
5320 |
|
5321 | this._motion = new Motion({
|
5322 | duration: duration,
|
5323 | range: ANIMATION_RANGE,
|
5324 | easing: easing
|
5325 | });
|
5326 | this._from = from;
|
5327 | this._to = to;
|
5328 | }
|
5329 |
|
5330 | var __proto = AnimationControl.prototype;
|
5331 | Object.defineProperty(__proto, "element", {
|
5332 | get: function () {
|
5333 | return null;
|
5334 | },
|
5335 | enumerable: false,
|
5336 | configurable: true
|
5337 | });
|
5338 | Object.defineProperty(__proto, "enabled", {
|
5339 | /**
|
5340 | * Whether this control is enabled or not
|
5341 | * @readonly
|
5342 | */
|
5343 | get: function () {
|
5344 | return this._enabled;
|
5345 | },
|
5346 | enumerable: false,
|
5347 | configurable: true
|
5348 | });
|
5349 | Object.defineProperty(__proto, "duration", {
|
5350 | /**
|
5351 | * Duration of the animation
|
5352 | */
|
5353 | get: function () {
|
5354 | return this._motion.duration;
|
5355 | },
|
5356 | set: function (val) {
|
5357 | this._motion.duration = val;
|
5358 | },
|
5359 | enumerable: false,
|
5360 | configurable: true
|
5361 | });
|
5362 | Object.defineProperty(__proto, "easing", {
|
5363 | /**
|
5364 | * Easing function of the animation
|
5365 | */
|
5366 | get: function () {
|
5367 | return this._motion.easing;
|
5368 | },
|
5369 | set: function (val) {
|
5370 | this._motion.easing = val;
|
5371 | },
|
5372 | enumerable: false,
|
5373 | configurable: true
|
5374 | });
|
5375 | /**
|
5376 | * Destroy the instance and remove all event listeners attached
|
5377 | * This also will reset CSS cursor to intial
|
5378 | * @returns {void} Nothing
|
5379 | */
|
5380 |
|
5381 | __proto.destroy = function () {
|
5382 | this.disable();
|
5383 | };
|
5384 | /**
|
5385 | * Update control by given deltaTime
|
5386 | * @param camera Camera to update position
|
5387 | * @param deltaTime Number of milisec to update
|
5388 | * @returns {void} Nothing
|
5389 | */
|
5390 |
|
5391 |
|
5392 | __proto.update = function (camera, deltaTime) {
|
5393 | if (!this._enabled) return;
|
5394 | var from = this._from;
|
5395 | var to = this._to;
|
5396 | var motion = this._motion;
|
5397 | motion.update(deltaTime); // Progress that easing is applied
|
5398 |
|
5399 | var progress = motion.val;
|
5400 | camera.yaw = mix(from.yaw, to.yaw, progress);
|
5401 | camera.pitch = mix(from.pitch, to.pitch, progress);
|
5402 | camera.distance = mix(from.distance, to.distance, progress);
|
5403 | camera.pivot = from.pivot.clone().lerp(to.pivot, progress);
|
5404 |
|
5405 | if (motion.progress >= 1) {
|
5406 | this.disable();
|
5407 |
|
5408 | this._finishCallbacks.forEach(function (callback) {
|
5409 | return callback();
|
5410 | });
|
5411 | }
|
5412 | };
|
5413 | /**
|
5414 | * Enable this input and add event listeners
|
5415 | * @returns {void} Nothing
|
5416 | */
|
5417 |
|
5418 |
|
5419 | __proto.enable = function () {
|
5420 | if (this._enabled) return;
|
5421 | this._enabled = true;
|
5422 |
|
5423 | this._motion.reset(0);
|
5424 |
|
5425 | this._motion.setEndDelta(1);
|
5426 | };
|
5427 | /**
|
5428 | * Disable this input and remove all event handlers
|
5429 | * @returns {void} Nothing
|
5430 | */
|
5431 |
|
5432 |
|
5433 | __proto.disable = function () {
|
5434 | if (!this._enabled) return;
|
5435 | this._enabled = false;
|
5436 | };
|
5437 | /**
|
5438 | * Add callback which is called when animation is finished
|
5439 | * @param callback Callback that will be called when animation finishes
|
5440 | * @returns {void} Nothing
|
5441 | */
|
5442 |
|
5443 |
|
5444 | __proto.onFinished = function (callback) {
|
5445 | this._finishCallbacks.push(callback);
|
5446 | };
|
5447 | /**
|
5448 | * Remove all onFinished callbacks
|
5449 | * @returns {void} Nothing
|
5450 | */
|
5451 |
|
5452 |
|
5453 | __proto.clearFinished = function () {
|
5454 | this._finishCallbacks = [];
|
5455 | };
|
5456 |
|
5457 | __proto.resize = function (size) {// DO NOTHING
|
5458 | };
|
5459 |
|
5460 | __proto.setElement = function (element) {// DO NOTHING
|
5461 | };
|
5462 |
|
5463 | __proto.sync = function (camera) {// Do nothing
|
5464 | };
|
5465 |
|
5466 | return AnimationControl;
|
5467 | }();
|
5468 |
|
5469 | /*
|
5470 | * Copyright (c) 2020 NAVER Corp.
|
5471 | * egjs projects are licensed under the MIT license
|
5472 | */
|
5473 | /**
|
5474 | * Camera that renders the scene of View3D
|
5475 | * @category Core
|
5476 | */
|
5477 |
|
5478 | var Camera$1 =
|
5479 | /*#__PURE__*/
|
5480 | function () {
|
5481 | /**
|
5482 | * Create new Camera instance
|
5483 | * @param canvas \<canvas\> element to render 3d model
|
5484 | */
|
5485 | function Camera(canvas) {
|
5486 | this._minDistance = MINIMUM_DISTANCE;
|
5487 | this._maxDistance = MAXIMUM_DISTANCE;
|
5488 | this._defaultPose = CAMERA_POSE;
|
5489 | this._currentPose = this._defaultPose.clone();
|
5490 | this._threeCamera = new PerspectiveCamera();
|
5491 | this._controller = new Controller(canvas, this);
|
5492 | }
|
5493 |
|
5494 | var __proto = Camera.prototype;
|
5495 | Object.defineProperty(__proto, "threeCamera", {
|
5496 | /**
|
5497 | * Three.js {@link https://threejs.org/docs/#api/en/cameras/PerspectiveCamera PerspectiveCamera} instance
|
5498 | * @readonly
|
5499 | * @type THREE.PerspectiveCamera
|
5500 | */
|
5501 | get: function () {
|
5502 | return this._threeCamera;
|
5503 | },
|
5504 | enumerable: false,
|
5505 | configurable: true
|
5506 | });
|
5507 | Object.defineProperty(__proto, "controller", {
|
5508 | /**
|
5509 | * Controller of the camera
|
5510 | * @readonly
|
5511 | * @type Controller
|
5512 | */
|
5513 | get: function () {
|
5514 | return this._controller;
|
5515 | },
|
5516 | enumerable: false,
|
5517 | configurable: true
|
5518 | });
|
5519 | Object.defineProperty(__proto, "defaultPose", {
|
5520 | /**
|
5521 | * Camera's default pose(yaw, pitch, distance, pivot)
|
5522 | * This will be new currentPose when {@link Camera#reset reset()} is called
|
5523 | * @readonly
|
5524 | * @type Pose
|
5525 | */
|
5526 | get: function () {
|
5527 | return this._defaultPose;
|
5528 | },
|
5529 | enumerable: false,
|
5530 | configurable: true
|
5531 | });
|
5532 | Object.defineProperty(__proto, "currentPose", {
|
5533 | /**
|
5534 | * Camera's current pose value
|
5535 | * @readonly
|
5536 | * @type Pose
|
5537 | */
|
5538 | get: function () {
|
5539 | return this._currentPose.clone();
|
5540 | },
|
5541 | enumerable: false,
|
5542 | configurable: true
|
5543 | });
|
5544 | Object.defineProperty(__proto, "yaw", {
|
5545 | /**
|
5546 | * Camera's current yaw
|
5547 | * {@link Camera#updatePosition} should be called after changing this value, and normally it is called every frame.
|
5548 | * @type number
|
5549 | */
|
5550 | get: function () {
|
5551 | return this._currentPose.yaw;
|
5552 | },
|
5553 | set: function (val) {
|
5554 | this._currentPose.yaw = val;
|
5555 | },
|
5556 | enumerable: false,
|
5557 | configurable: true
|
5558 | });
|
5559 | Object.defineProperty(__proto, "pitch", {
|
5560 | /**
|
5561 | * Camera's current pitch
|
5562 | * {@link Camera#updatePosition} should be called after changing this value, and normally it is called every frame.
|
5563 | * @type number
|
5564 | */
|
5565 | get: function () {
|
5566 | return this._currentPose.pitch;
|
5567 | },
|
5568 | set: function (val) {
|
5569 | this._currentPose.pitch = val;
|
5570 | },
|
5571 | enumerable: false,
|
5572 | configurable: true
|
5573 | });
|
5574 | Object.defineProperty(__proto, "distance", {
|
5575 | /**
|
5576 | * Camera's current distance
|
5577 | * {@link Camera#updatePosition} should be called after changing this value, and normally it is called every frame.
|
5578 | * @type number
|
5579 | */
|
5580 | get: function () {
|
5581 | return this._currentPose.distance;
|
5582 | },
|
5583 | set: function (val) {
|
5584 | this._currentPose.distance = val;
|
5585 | },
|
5586 | enumerable: false,
|
5587 | configurable: true
|
5588 | });
|
5589 | Object.defineProperty(__proto, "pivot", {
|
5590 | /**
|
5591 | * Current pivot point of camera rotation
|
5592 | * @readonly
|
5593 | * @type THREE.Vector3
|
5594 | * @see {@link https://threejs.org/docs/#api/en/math/Vector3 THREE#Vector3}
|
5595 | */
|
5596 | get: function () {
|
5597 | return this._currentPose.pivot;
|
5598 | },
|
5599 | set: function (val) {
|
5600 | this._currentPose.pivot = val;
|
5601 | },
|
5602 | enumerable: false,
|
5603 | configurable: true
|
5604 | });
|
5605 | Object.defineProperty(__proto, "minDistance", {
|
5606 | /**
|
5607 | * Minimum distance from lookAtPosition
|
5608 | * @type number
|
5609 | * @example
|
5610 | * import View3D from "@egjs/view3d";
|
5611 | *
|
5612 | * const view3d = new View3D("#view3d-canvas");
|
5613 | * view3d.camera.minDistance = 100;
|
5614 | */
|
5615 | get: function () {
|
5616 | return this._minDistance;
|
5617 | },
|
5618 | set: function (val) {
|
5619 | this._minDistance = val;
|
5620 | },
|
5621 | enumerable: false,
|
5622 | configurable: true
|
5623 | });
|
5624 | Object.defineProperty(__proto, "maxDistance", {
|
5625 | /**
|
5626 | * Maximum distance from lookAtPosition
|
5627 | * @type number
|
5628 | * @example
|
5629 | * import View3D from "@egjs/view3d";
|
5630 | *
|
5631 | * const view3d = new View3D("#view3d-canvas");
|
5632 | * view3d.camera.maxDistance = 400;
|
5633 | */
|
5634 | get: function () {
|
5635 | return this._maxDistance;
|
5636 | },
|
5637 | set: function (val) {
|
5638 | this._maxDistance = val;
|
5639 | },
|
5640 | enumerable: false,
|
5641 | configurable: true
|
5642 | });
|
5643 | Object.defineProperty(__proto, "fov", {
|
5644 | /**
|
5645 | * Camera's focus of view value
|
5646 | * @type number
|
5647 | * @see {@link https://threejs.org/docs/#api/en/cameras/PerspectiveCamera.fov THREE#PerspectiveCamera}
|
5648 | */
|
5649 | get: function () {
|
5650 | return this._threeCamera.fov;
|
5651 | },
|
5652 | set: function (val) {
|
5653 | this._threeCamera.fov = val;
|
5654 |
|
5655 | this._threeCamera.updateProjectionMatrix();
|
5656 | },
|
5657 | enumerable: false,
|
5658 | configurable: true
|
5659 | });
|
5660 | Object.defineProperty(__proto, "renderWidth", {
|
5661 | /**
|
5662 | * Camera's frustum width on current distance value
|
5663 | * @type number
|
5664 | */
|
5665 | get: function () {
|
5666 | return this.renderHeight * this._threeCamera.aspect;
|
5667 | },
|
5668 | enumerable: false,
|
5669 | configurable: true
|
5670 | });
|
5671 | Object.defineProperty(__proto, "renderHeight", {
|
5672 | /**
|
5673 | * Camera's frustum height on current distance value
|
5674 | * @type number
|
5675 | */
|
5676 | get: function () {
|
5677 | return 2 * this.distance * Math.tan(toRadian(this.fov / 2));
|
5678 | },
|
5679 | enumerable: false,
|
5680 | configurable: true
|
5681 | });
|
5682 | Object.defineProperty(__proto, "pose", {
|
5683 | set: function (val) {
|
5684 | this._currentPose = val;
|
5685 |
|
5686 | this._controller.syncToCamera();
|
5687 | },
|
5688 | enumerable: false,
|
5689 | configurable: true
|
5690 | });
|
5691 | /**
|
5692 | * Reset camera to default pose
|
5693 | * @param duration Duration of the reset animation
|
5694 | * @param easing Easing function for the reset animation
|
5695 | * @returns Promise that resolves when the animation finishes
|
5696 | */
|
5697 |
|
5698 | __proto.reset = function (duration, easing) {
|
5699 | if (duration === void 0) {
|
5700 | duration = 0;
|
5701 | }
|
5702 |
|
5703 | if (easing === void 0) {
|
5704 | easing = EASING$1;
|
5705 | }
|
5706 |
|
5707 | var controller = this._controller;
|
5708 | var currentPose = this._currentPose;
|
5709 | var defaultPose = this._defaultPose;
|
5710 |
|
5711 | if (duration <= 0) {
|
5712 | // Reset camera immediately
|
5713 | this._currentPose = defaultPose.clone();
|
5714 | controller.syncToCamera();
|
5715 | return Promise.resolve();
|
5716 | } else {
|
5717 | // Add reset animation control to controller
|
5718 | var resetControl_1 = new AnimationControl(currentPose, defaultPose);
|
5719 | resetControl_1.duration = duration;
|
5720 | resetControl_1.easing = easing;
|
5721 | return new Promise(function (resolve) {
|
5722 | resetControl_1.onFinished(function () {
|
5723 | controller.remove(resetControl_1);
|
5724 | controller.syncToCamera();
|
5725 | resolve();
|
5726 | });
|
5727 | controller.add(resetControl_1);
|
5728 | });
|
5729 | }
|
5730 | };
|
5731 | /**
|
5732 | * Update camera's aspect to given size
|
5733 | * @param size {@link THREE.Vector2} instance that has width(x), height(y)
|
5734 | * @returns {void} Nothing
|
5735 | */
|
5736 |
|
5737 |
|
5738 | __proto.resize = function (size) {
|
5739 | var cam = this._threeCamera;
|
5740 | var aspect = size.x / size.y;
|
5741 | cam.aspect = aspect;
|
5742 | cam.updateProjectionMatrix();
|
5743 |
|
5744 | this._controller.resize(size);
|
5745 | };
|
5746 | /**
|
5747 | * Set default position of camera relative to the 3d model
|
5748 | * New default pose will be used when {@link Camera#reset reset()} is called
|
5749 | * @param newDefaultPose new default pose to apply
|
5750 | * @returns {void} Nothing
|
5751 | */
|
5752 |
|
5753 |
|
5754 | __proto.setDefaultPose = function (newDefaultPose) {
|
5755 | var defaultPose = this._defaultPose;
|
5756 | var yaw = newDefaultPose.yaw,
|
5757 | pitch = newDefaultPose.pitch,
|
5758 | distance = newDefaultPose.distance,
|
5759 | pivot = newDefaultPose.pivot;
|
5760 |
|
5761 | if (yaw != null) {
|
5762 | defaultPose.yaw = yaw;
|
5763 | }
|
5764 |
|
5765 | if (pitch != null) {
|
5766 | defaultPose.pitch = pitch;
|
5767 | }
|
5768 |
|
5769 | if (distance != null) {
|
5770 | defaultPose.distance = distance;
|
5771 | }
|
5772 |
|
5773 | if (pivot != null) {
|
5774 | defaultPose.pivot = pivot;
|
5775 | }
|
5776 | };
|
5777 | /**
|
5778 | * Update camera position base on the {@link Camera#currentPose currentPose} value
|
5779 | * @returns {void} Nothing
|
5780 | */
|
5781 |
|
5782 |
|
5783 | __proto.updatePosition = function () {
|
5784 | this._clampCurrentPose();
|
5785 |
|
5786 | var threeCamera = this._threeCamera;
|
5787 | var pose = this._currentPose;
|
5788 | var yaw = toRadian(pose.yaw);
|
5789 | var pitch = toRadian(pose.pitch); // Should use minimum distance to prevent distance becomes 0, which makes whole x,y,z to 0 regardless of pose
|
5790 |
|
5791 | var distance = Math.max(pose.distance + this._minDistance, MINIMUM_DISTANCE);
|
5792 | var newCamPos = new Vector3(0, 0, 0);
|
5793 | newCamPos.y = distance * Math.sin(pitch);
|
5794 | newCamPos.z = distance * Math.cos(pitch);
|
5795 | newCamPos.x = newCamPos.z * Math.sin(-yaw);
|
5796 | newCamPos.z = newCamPos.z * Math.cos(-yaw);
|
5797 | newCamPos.add(pose.pivot);
|
5798 | threeCamera.position.copy(newCamPos);
|
5799 | threeCamera.lookAt(pose.pivot);
|
5800 | threeCamera.updateProjectionMatrix();
|
5801 | };
|
5802 |
|
5803 | __proto._clampCurrentPose = function () {
|
5804 | var currentPose = this._currentPose;
|
5805 | currentPose.yaw = circulate(currentPose.yaw, 0, 360);
|
5806 | currentPose.pitch = clamp(currentPose.pitch, PITCH_RANGE.min, PITCH_RANGE.max);
|
5807 | currentPose.distance = clamp(currentPose.distance, this._minDistance, this._maxDistance);
|
5808 | };
|
5809 |
|
5810 | return Camera;
|
5811 | }();
|
5812 |
|
5813 | /*
|
5814 | * Copyright (c) 2020 NAVER Corp.
|
5815 | * egjs projects are licensed under the MIT license
|
5816 | */
|
5817 | /**
|
5818 | * Component that manages animations of the 3D Model
|
5819 | * @category Core
|
5820 | */
|
5821 |
|
5822 | var ModelAnimator =
|
5823 | /*#__PURE__*/
|
5824 | function () {
|
5825 | /**
|
5826 | * Create new ModelAnimator instance
|
5827 | * @param scene {@link https://threejs.org/docs/index.html#api/en/scenes/Scene THREE.Scene} instance that is root of all 3d objects
|
5828 | */
|
5829 | function ModelAnimator(scene) {
|
5830 | this._mixer = new AnimationMixer(scene);
|
5831 | this._clips = [];
|
5832 | this._actions = [];
|
5833 | }
|
5834 |
|
5835 | var __proto = ModelAnimator.prototype;
|
5836 | Object.defineProperty(__proto, "clips", {
|
5837 | /**
|
5838 | * Three.js {@link https://threejs.org/docs/#api/en/animation/AnimationClip AnimationClip}s that stored
|
5839 | * @type THREE.AnimationClip
|
5840 | * @readonly
|
5841 | */
|
5842 | get: function () {
|
5843 | return this._clips;
|
5844 | },
|
5845 | enumerable: false,
|
5846 | configurable: true
|
5847 | });
|
5848 | Object.defineProperty(__proto, "mixer", {
|
5849 | /**
|
5850 | * {@link https://threejs.org/docs/index.html#api/en/animation/AnimationMixer THREE.AnimationMixer} instance
|
5851 | * @type THREE.AnimationMixer
|
5852 | * @readonly
|
5853 | */
|
5854 | get: function () {
|
5855 | return this._mixer;
|
5856 | },
|
5857 | enumerable: false,
|
5858 | configurable: true
|
5859 | });
|
5860 | /**
|
5861 | * Store the given clips
|
5862 | * @param clips Three.js {@link https://threejs.org/docs/#api/en/animation/AnimationClip AnimationClip}s of the model
|
5863 | * @returns {void} Nothing
|
5864 | * @example
|
5865 | * // After loading model
|
5866 | * view3d.animator.setClips(model.animations);
|
5867 | */
|
5868 |
|
5869 | __proto.setClips = function (clips) {
|
5870 | var mixer = this._mixer;
|
5871 | this._clips = clips;
|
5872 | this._actions = clips.map(function (clip) {
|
5873 | return mixer.clipAction(clip);
|
5874 | });
|
5875 | };
|
5876 | /**
|
5877 | * Play one of the model's animation
|
5878 | * @param index Index of the animation to play
|
5879 | * @returns {void} Nothing
|
5880 | */
|
5881 |
|
5882 |
|
5883 | __proto.play = function (index) {
|
5884 | var action = this._actions[index];
|
5885 |
|
5886 | if (action) {
|
5887 | action.play();
|
5888 | }
|
5889 | };
|
5890 | /**
|
5891 | * Pause one of the model's animation
|
5892 | * If you want to stop animation completely, you should call {@link ModelAnimator#stop stop} instead
|
5893 | * You should call {@link ModelAnimator#resume resume} to resume animation
|
5894 | * @param index Index of the animation to pause
|
5895 | * @returns {void} Nothing
|
5896 | */
|
5897 |
|
5898 |
|
5899 | __proto.pause = function (index) {
|
5900 | var action = this._actions[index];
|
5901 |
|
5902 | if (action) {
|
5903 | action.timeScale = 0;
|
5904 | }
|
5905 | };
|
5906 | /**
|
5907 | * Resume one of the model's animation
|
5908 | * This will play animation from the point when the animation is paused
|
5909 | * @param index Index of the animation to resume
|
5910 | * @returns {void} Nothing
|
5911 | */
|
5912 |
|
5913 |
|
5914 | __proto.resume = function (index) {
|
5915 | var action = this._actions[index];
|
5916 |
|
5917 | if (action) {
|
5918 | action.timeScale = 1;
|
5919 | }
|
5920 | };
|
5921 | /**
|
5922 | * Fully stops one of the model's animation
|
5923 | * @param index Index of the animation to stop
|
5924 | * @returns {void} Nothing
|
5925 | */
|
5926 |
|
5927 |
|
5928 | __proto.stop = function (index) {
|
5929 | var action = this._actions[index];
|
5930 |
|
5931 | if (action) {
|
5932 | action.stop();
|
5933 | }
|
5934 | };
|
5935 | /**
|
5936 | * Update animations
|
5937 | * @param delta number of seconds to play animations attached
|
5938 | * @returns {void} Nothing
|
5939 | */
|
5940 |
|
5941 |
|
5942 | __proto.update = function (delta) {
|
5943 | this._mixer.update(delta);
|
5944 | };
|
5945 | /**
|
5946 | * Reset the instance and remove all cached animation clips attached to it
|
5947 | * @returns {void} Nothing
|
5948 | */
|
5949 |
|
5950 |
|
5951 | __proto.reset = function () {
|
5952 | var mixer = this._mixer;
|
5953 | mixer.uncacheRoot(mixer.getRoot());
|
5954 | this._clips = [];
|
5955 | this._actions = [];
|
5956 | };
|
5957 |
|
5958 | return ModelAnimator;
|
5959 | }();
|
5960 |
|
5961 | /*
|
5962 | * Copyright (c) 2020 NAVER Corp.
|
5963 | * egjs projects are licensed under the MIT license
|
5964 | */
|
5965 | /**
|
5966 | * XRManager that manages XRSessions
|
5967 | * @category Core
|
5968 | */
|
5969 |
|
5970 | var XRManager =
|
5971 | /*#__PURE__*/
|
5972 | function () {
|
5973 | /**
|
5974 | * Create a new instance of the XRManager
|
5975 | * @param view3d Instance of the View3D
|
5976 | */
|
5977 | function XRManager(view3d) {
|
5978 | this._view3d = view3d;
|
5979 | this._sessions = [];
|
5980 | this._currentSession = null;
|
5981 | }
|
5982 |
|
5983 | var __proto = XRManager.prototype;
|
5984 | Object.defineProperty(__proto, "sessions", {
|
5985 | /**
|
5986 | * Array of {@link XRSession}s added
|
5987 | */
|
5988 | get: function () {
|
5989 | return this._sessions;
|
5990 | },
|
5991 | enumerable: false,
|
5992 | configurable: true
|
5993 | });
|
5994 | Object.defineProperty(__proto, "currentSession", {
|
5995 | /**
|
5996 | * Current entry session. Note that only WebXR type session can be returned.
|
5997 | */
|
5998 | get: function () {
|
5999 | return this._currentSession;
|
6000 | },
|
6001 | enumerable: false,
|
6002 | configurable: true
|
6003 | });
|
6004 | /**
|
6005 | * Return a Promise containing whether any of the added session is available
|
6006 | */
|
6007 |
|
6008 | __proto.isAvailable = function () {
|
6009 | return __awaiter(this, void 0, void 0, function () {
|
6010 | var results;
|
6011 | return __generator(this, function (_a) {
|
6012 | switch (_a.label) {
|
6013 | case 0:
|
6014 | return [4
|
6015 | /*yield*/
|
6016 | , Promise.all(this._sessions.map(function (session) {
|
6017 | return session.isAvailable();
|
6018 | }))];
|
6019 |
|
6020 | case 1:
|
6021 | results = _a.sent();
|
6022 | return [2
|
6023 | /*return*/
|
6024 | , results.some(function (result) {
|
6025 | return result === true;
|
6026 | })];
|
6027 | }
|
6028 | });
|
6029 | });
|
6030 | };
|
6031 | /**
|
6032 | * Add new {@link XRSession}.
|
6033 | * The XRSession's order added is the same as the order of entry.
|
6034 | * @param xrSession XRSession to add
|
6035 | */
|
6036 |
|
6037 |
|
6038 | __proto.addSession = function () {
|
6039 | var _a;
|
6040 |
|
6041 | var xrSession = [];
|
6042 |
|
6043 | for (var _i = 0; _i < arguments.length; _i++) {
|
6044 | xrSession[_i] = arguments[_i];
|
6045 | }
|
6046 |
|
6047 | (_a = this._sessions).push.apply(_a, __spread(xrSession));
|
6048 | };
|
6049 | /**
|
6050 | * Enter XR Session.
|
6051 | */
|
6052 |
|
6053 |
|
6054 | __proto.enter = function () {
|
6055 | return __awaiter(this, void 0, void 0, function () {
|
6056 | return __generator(this, function (_a) {
|
6057 | return [2
|
6058 | /*return*/
|
6059 | , this._enterSession(0, [])];
|
6060 | });
|
6061 | });
|
6062 | };
|
6063 | /**
|
6064 | * Exit current XR Session.
|
6065 | */
|
6066 |
|
6067 |
|
6068 | __proto.exit = function () {
|
6069 | if (this._currentSession) {
|
6070 | this._currentSession.exit(this._view3d);
|
6071 |
|
6072 | this._currentSession = null;
|
6073 | }
|
6074 | };
|
6075 |
|
6076 | __proto._enterSession = function (sessionIdx, errors) {
|
6077 | return __awaiter(this, void 0, void 0, function () {
|
6078 | var view3d, sessions, xrSession, isSessionAvailable;
|
6079 |
|
6080 | var _this = this;
|
6081 |
|
6082 | return __generator(this, function (_a) {
|
6083 | switch (_a.label) {
|
6084 | case 0:
|
6085 | view3d = this._view3d;
|
6086 | sessions = this._sessions;
|
6087 |
|
6088 | if (sessionIdx >= sessions.length) {
|
6089 | if (errors.length < 1) {
|
6090 | errors.push(new Error("No sessions available"));
|
6091 | }
|
6092 |
|
6093 | return [2
|
6094 | /*return*/
|
6095 | , Promise.reject(errors)];
|
6096 | }
|
6097 |
|
6098 | xrSession = sessions[sessionIdx];
|
6099 | return [4
|
6100 | /*yield*/
|
6101 | , xrSession.isAvailable()];
|
6102 |
|
6103 | case 1:
|
6104 | isSessionAvailable = _a.sent();
|
6105 |
|
6106 | if (!isSessionAvailable) {
|
6107 | return [2
|
6108 | /*return*/
|
6109 | , this._enterSession(sessionIdx + 1, errors)];
|
6110 | }
|
6111 |
|
6112 | return [4
|
6113 | /*yield*/
|
6114 | , xrSession.enter(view3d).then(function () {
|
6115 | if (xrSession.isWebXRSession) {
|
6116 | // Non-webxr sessions are ignored
|
6117 | _this._currentSession = xrSession;
|
6118 | xrSession.session.addEventListener("end", function () {
|
6119 | _this._currentSession = null;
|
6120 | });
|
6121 | }
|
6122 |
|
6123 | return errors;
|
6124 | }).catch(function (e) {
|
6125 | errors.push(e);
|
6126 | return _this._enterSession(sessionIdx + 1, errors);
|
6127 | })];
|
6128 |
|
6129 | case 2:
|
6130 | return [2
|
6131 | /*return*/
|
6132 | , _a.sent()];
|
6133 | }
|
6134 | });
|
6135 | });
|
6136 | };
|
6137 |
|
6138 | return XRManager;
|
6139 | }();
|
6140 |
|
6141 | /*
|
6142 | * Copyright (c) 2020 NAVER Corp.
|
6143 | * egjs projects are licensed under the MIT license
|
6144 | */
|
6145 | var EVENTS = {
|
6146 | MOUSE_DOWN: "mousedown",
|
6147 | MOUSE_MOVE: "mousemove",
|
6148 | MOUSE_UP: "mouseup",
|
6149 | TOUCH_START: "touchstart",
|
6150 | TOUCH_MOVE: "touchmove",
|
6151 | TOUCH_END: "touchend",
|
6152 | WHEEL: "wheel",
|
6153 | RESIZE: "resize",
|
6154 | CONTEXT_MENU: "contextmenu",
|
6155 | MOUSE_ENTER: "mouseenter",
|
6156 | MOUSE_LEAVE: "mouseleave"
|
6157 | }; // https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent.button
|
6158 |
|
6159 | var MOUSE_BUTTON;
|
6160 |
|
6161 | (function (MOUSE_BUTTON) {
|
6162 | MOUSE_BUTTON[MOUSE_BUTTON["LEFT"] = 0] = "LEFT";
|
6163 | MOUSE_BUTTON[MOUSE_BUTTON["MIDDLE"] = 1] = "MIDDLE";
|
6164 | MOUSE_BUTTON[MOUSE_BUTTON["RIGHT"] = 2] = "RIGHT";
|
6165 | })(MOUSE_BUTTON || (MOUSE_BUTTON = {}));
|
6166 |
|
6167 | /*
|
6168 | * Copyright (c) 2020 NAVER Corp.
|
6169 | * egjs projects are licensed under the MIT license
|
6170 | */
|
6171 | /**
|
6172 | * Yet another 3d model viewer
|
6173 | * @category Core
|
6174 | * @mermaid
|
6175 | * classDiagram
|
6176 | * class View3D
|
6177 | * View3D *-- Camera
|
6178 | * View3D *-- Renderer
|
6179 | * View3D *-- Scene
|
6180 | * View3D *-- ModelAnimator
|
6181 | * Camera *-- Controller
|
6182 | * @event resize
|
6183 | * @event beforeRender
|
6184 | * @event afterRender
|
6185 | */
|
6186 |
|
6187 | var View3D =
|
6188 | /*#__PURE__*/
|
6189 | function (_super) {
|
6190 | __extends(View3D, _super);
|
6191 | /**
|
6192 | * Creates new View3D instance
|
6193 | * @example
|
6194 | * import View3D, { ERROR_CODES } from "@egjs/view3d";
|
6195 | *
|
6196 | * try {
|
6197 | * const view3d = new View3D("#wrapper")
|
6198 | * } catch (e) {
|
6199 | * if (e.code === ERROR_CODES.ELEMENT_NOT_FOUND) {
|
6200 | * console.error("Element not found")
|
6201 | * }
|
6202 | * }
|
6203 | * @throws {View3DError} `CODES.WRONG_TYPE`<br/>When the parameter is not either string or the canvas element.
|
6204 | * @throws {View3DError} `CODES.ELEMENT_NOT_FOUND`<br/>When the element with given query does not exist.
|
6205 | * @throws {View3DError} `CODES.ELEMENT_NOT_CANVAS`<br/>When the element given is not a \<canvas\> element.
|
6206 | * @throws {View3DError} `CODES.WEBGL_NOT_SUPPORTED`<br/>When browser does not support WebGL.
|
6207 | * @see Model
|
6208 | * @see Camera
|
6209 | * @see Renderer
|
6210 | * @see Scene
|
6211 | * @see Controller
|
6212 | * @see XRManager
|
6213 | */
|
6214 |
|
6215 |
|
6216 | function View3D(el) {
|
6217 | var _this = _super.call(this) || this;
|
6218 | /**
|
6219 | * Resize View3D instance to fit current canvas size
|
6220 | * @method
|
6221 | * @returns {void} Nothing
|
6222 | */
|
6223 |
|
6224 |
|
6225 | _this.resize = function () {
|
6226 | _this._renderer.resize();
|
6227 |
|
6228 | var newSize = _this._renderer.size;
|
6229 |
|
6230 | _this._camera.resize(newSize);
|
6231 |
|
6232 | _this.emit("resize", __assign(__assign({}, newSize), {
|
6233 | target: _this
|
6234 | }));
|
6235 | };
|
6236 | /**
|
6237 | * View3D's basic render loop function
|
6238 | * @param delta Number of seconds passed since last frame
|
6239 | */
|
6240 |
|
6241 |
|
6242 | _this.renderLoop = function (delta) {
|
6243 | var renderer = _this._renderer;
|
6244 | var scene = _this._scene;
|
6245 | var camera = _this._camera;
|
6246 | var controller = _this.controller;
|
6247 | var animator = _this._animator;
|
6248 | animator.update(delta);
|
6249 | controller.update(delta);
|
6250 |
|
6251 | _this.emit("beforeRender", _this);
|
6252 |
|
6253 | renderer.render(scene, camera);
|
6254 |
|
6255 | _this.emit("afterRender", _this);
|
6256 | };
|
6257 |
|
6258 | var canvas = getCanvas(el);
|
6259 | _this._renderer = new Renderer(canvas);
|
6260 | _this._camera = new Camera$1(canvas);
|
6261 | _this._scene = new Scene$1();
|
6262 | _this._animator = new ModelAnimator(_this._scene.root);
|
6263 | _this._xr = new XRManager(_this);
|
6264 | _this._model = null;
|
6265 |
|
6266 | _this.resize();
|
6267 |
|
6268 | window.addEventListener(EVENTS.RESIZE, _this.resize);
|
6269 | return _this;
|
6270 | }
|
6271 |
|
6272 | var __proto = View3D.prototype;
|
6273 | Object.defineProperty(__proto, "renderer", {
|
6274 | /**
|
6275 | * {@link Renderer} instance of the View3D
|
6276 | * @type {Renderer}
|
6277 | */
|
6278 | get: function () {
|
6279 | return this._renderer;
|
6280 | },
|
6281 | enumerable: false,
|
6282 | configurable: true
|
6283 | });
|
6284 | Object.defineProperty(__proto, "scene", {
|
6285 | /**
|
6286 | * {@link Scene} instance of the View3D
|
6287 | * @type {Scene}
|
6288 | */
|
6289 | get: function () {
|
6290 | return this._scene;
|
6291 | },
|
6292 | enumerable: false,
|
6293 | configurable: true
|
6294 | });
|
6295 | Object.defineProperty(__proto, "camera", {
|
6296 | /**
|
6297 | * {@link Camera} instance of the View3D
|
6298 | * @type {Camera}
|
6299 | */
|
6300 | get: function () {
|
6301 | return this._camera;
|
6302 | },
|
6303 | enumerable: false,
|
6304 | configurable: true
|
6305 | });
|
6306 | Object.defineProperty(__proto, "controller", {
|
6307 | /**
|
6308 | * {@link Controller} instance of the Camera
|
6309 | * @type {Controller}
|
6310 | */
|
6311 | get: function () {
|
6312 | return this._camera.controller;
|
6313 | },
|
6314 | enumerable: false,
|
6315 | configurable: true
|
6316 | });
|
6317 | Object.defineProperty(__proto, "animator", {
|
6318 | /**
|
6319 | * {@link ModelAnimator} instance of the View3D
|
6320 | * @type {ModelAnimator}
|
6321 | */
|
6322 | get: function () {
|
6323 | return this._animator;
|
6324 | },
|
6325 | enumerable: false,
|
6326 | configurable: true
|
6327 | });
|
6328 | Object.defineProperty(__proto, "xr", {
|
6329 | /**
|
6330 | * {@link XRManager} instance of the View3D
|
6331 | * @type {XRManager}
|
6332 | */
|
6333 | get: function () {
|
6334 | return this._xr;
|
6335 | },
|
6336 | enumerable: false,
|
6337 | configurable: true
|
6338 | });
|
6339 | Object.defineProperty(__proto, "model", {
|
6340 | /**
|
6341 | * {@link Model} that View3D is currently showing
|
6342 | * @type {Model|null}
|
6343 | */
|
6344 | get: function () {
|
6345 | return this._model;
|
6346 | },
|
6347 | enumerable: false,
|
6348 | configurable: true
|
6349 | });
|
6350 | /**
|
6351 | * Destroy View3D instance and remove all events attached to it
|
6352 | * @returns {void} Nothing
|
6353 | */
|
6354 |
|
6355 | __proto.destroy = function () {
|
6356 | this._scene.reset();
|
6357 |
|
6358 | this.controller.clear();
|
6359 | this._model = null;
|
6360 | window.removeEventListener(EVENTS.RESIZE, this.resize);
|
6361 | };
|
6362 | /**
|
6363 | * Display the given model.
|
6364 | * This method will remove the current displaying model, and reset the camera & control to default position.
|
6365 | * View3D can only show one model at a time
|
6366 | * @param model {@link Model} instance to show
|
6367 | * @param {object} [options={}] Display options
|
6368 | * @param {number} [options.applySize=true] Whether to change model size to given "size" option.
|
6369 | * @param {number} [options.size=80] Size of the model to show as.
|
6370 | * @param {boolean} [options.resetView=true] Whether to reset the view to the camera's default pose.
|
6371 | * @returns {void} Nothing
|
6372 | */
|
6373 |
|
6374 |
|
6375 | __proto.display = function (model, _a) {
|
6376 | var _b = _a === void 0 ? {} : _a,
|
6377 | _c = _b.applySize,
|
6378 | applySize = _c === void 0 ? true : _c,
|
6379 | _d = _b.size,
|
6380 | size = _d === void 0 ? MODEL_SIZE : _d,
|
6381 | _e = _b.resetView,
|
6382 | resetView = _e === void 0 ? true : _e;
|
6383 |
|
6384 | var renderer = this._renderer;
|
6385 | var scene = this._scene;
|
6386 | var camera = this._camera;
|
6387 | var animator = this._animator;
|
6388 |
|
6389 | if (applySize) {
|
6390 | model.size = size;
|
6391 | } // model.moveToOrigin();
|
6392 |
|
6393 |
|
6394 | scene.resetModel();
|
6395 |
|
6396 | if (resetView) {
|
6397 | camera.reset();
|
6398 | }
|
6399 |
|
6400 | animator.reset();
|
6401 | this._model = model;
|
6402 | scene.add(model.scene);
|
6403 | animator.setClips(model.animations);
|
6404 | scene.update(model);
|
6405 | renderer.stopAnimationLoop();
|
6406 | renderer.setAnimationLoop(this.renderLoop);
|
6407 | };
|
6408 | /**
|
6409 | * Current version of the View3D
|
6410 | */
|
6411 |
|
6412 |
|
6413 | View3D.VERSION = "1.1.0";
|
6414 | return View3D;
|
6415 | }(EventEmitter);
|
6416 |
|
6417 | /*
|
6418 | * Copyright (c) 2020 NAVER Corp.
|
6419 | * egjs projects are licensed under the MIT license
|
6420 | */
|
6421 | /**
|
6422 | * Data class for loaded 3d model
|
6423 | * @category Core
|
6424 | */
|
6425 |
|
6426 | var Model =
|
6427 | /*#__PURE__*/
|
6428 | function () {
|
6429 | /**
|
6430 | * Create new Model instance
|
6431 | */
|
6432 | function Model(_a) {
|
6433 | var scenes = _a.scenes,
|
6434 | _b = _a.animations,
|
6435 | animations = _b === void 0 ? [] : _b,
|
6436 | _c = _a.fixSkinnedBbox,
|
6437 | fixSkinnedBbox = _c === void 0 ? false : _c,
|
6438 | _d = _a.castShadow,
|
6439 | castShadow = _d === void 0 ? true : _d,
|
6440 | _e = _a.receiveShadow,
|
6441 | receiveShadow = _e === void 0 ? false : _e; // This guarantees model's root has identity matrix at creation
|
6442 |
|
6443 | this._scene = new Group();
|
6444 | var pivot = new Object3D();
|
6445 | pivot.name = "Pivot";
|
6446 | pivot.add.apply(pivot, __spread(scenes));
|
6447 |
|
6448 | this._scene.add(pivot);
|
6449 |
|
6450 | this._animations = animations;
|
6451 | this._fixSkinnedBbox = fixSkinnedBbox;
|
6452 | this._cachedLights = null;
|
6453 | this._cachedMeshes = null;
|
6454 |
|
6455 | this._setInitialBbox();
|
6456 |
|
6457 | var bboxCenter = this._initialBbox.getCenter(new Vector3());
|
6458 |
|
6459 | pivot.position.copy(bboxCenter.negate());
|
6460 |
|
6461 | this._moveInitialBboxToCenter();
|
6462 |
|
6463 | this._originalSize = this.size;
|
6464 | this.castShadow = castShadow;
|
6465 | this.receiveShadow = receiveShadow;
|
6466 | }
|
6467 |
|
6468 | var __proto = Model.prototype;
|
6469 | Object.defineProperty(__proto, "scene", {
|
6470 | /**
|
6471 | * Scene of the model, see {@link https://threejs.org/docs/#api/en/objects/Group THREE.Group}
|
6472 | * @readonly
|
6473 | */
|
6474 | get: function () {
|
6475 | return this._scene;
|
6476 | },
|
6477 | enumerable: false,
|
6478 | configurable: true
|
6479 | });
|
6480 | Object.defineProperty(__proto, "animations", {
|
6481 | /**
|
6482 | * {@link https://threejs.org/docs/#api/en/animation/AnimationClip THREE.AnimationClip}s inside model
|
6483 | */
|
6484 | get: function () {
|
6485 | return this._animations;
|
6486 | },
|
6487 | enumerable: false,
|
6488 | configurable: true
|
6489 | });
|
6490 | Object.defineProperty(__proto, "lights", {
|
6491 | /***
|
6492 | * {@link https://threejs.org/docs/#api/en/lights/Light THREE.Light}s inside model if there's any.
|
6493 | * @readonly
|
6494 | */
|
6495 | get: function () {
|
6496 | return this._cachedLights ? this._cachedLights : this._getAllLights();
|
6497 | },
|
6498 | enumerable: false,
|
6499 | configurable: true
|
6500 | });
|
6501 | Object.defineProperty(__proto, "meshes", {
|
6502 | /**
|
6503 | * {@link https://threejs.org/docs/#api/en/objects/Mesh THREE.Mesh}es inside model if there's any.
|
6504 | * @readonly
|
6505 | */
|
6506 | get: function () {
|
6507 | return this._cachedMeshes ? this._cachedMeshes : this._getAllMeshes();
|
6508 | },
|
6509 | enumerable: false,
|
6510 | configurable: true
|
6511 | });
|
6512 | Object.defineProperty(__proto, "bbox", {
|
6513 | /**
|
6514 | * Get a copy of model's current bounding box
|
6515 | * @type THREE#Box3
|
6516 | * @see https://threejs.org/docs/#api/en/math/Box3
|
6517 | */
|
6518 | get: function () {
|
6519 | return this._getTransformedBbox();
|
6520 | },
|
6521 | enumerable: false,
|
6522 | configurable: true
|
6523 | });
|
6524 | Object.defineProperty(__proto, "initialBbox", {
|
6525 | /**
|
6526 | * Get a copy of model's initial bounding box without transform
|
6527 | */
|
6528 | get: function () {
|
6529 | return this._initialBbox.clone();
|
6530 | },
|
6531 | enumerable: false,
|
6532 | configurable: true
|
6533 | });
|
6534 | Object.defineProperty(__proto, "size", {
|
6535 | /**
|
6536 | * Model's bounding box size
|
6537 | * Changing this will scale the model.
|
6538 | * @type number
|
6539 | * @example
|
6540 | * import { GLTFLoader } from "@egjs/view3d";
|
6541 | * new GLTFLoader().load(URL_TO_GLTF)
|
6542 | * .then(model => {
|
6543 | * model.size = 100;
|
6544 | * })
|
6545 | */
|
6546 | get: function () {
|
6547 | return this._getTransformedBbox().getSize(new Vector3()).length();
|
6548 | },
|
6549 | set: function (val) {
|
6550 | var scene = this._scene;
|
6551 | var initialBbox = this._initialBbox; // Modify scale
|
6552 |
|
6553 | var bboxSize = initialBbox.getSize(new Vector3());
|
6554 | var scale = val / bboxSize.length();
|
6555 | scene.scale.setScalar(scale);
|
6556 | scene.updateMatrix();
|
6557 | },
|
6558 | enumerable: false,
|
6559 | configurable: true
|
6560 | });
|
6561 | Object.defineProperty(__proto, "fixSkinnedBbox", {
|
6562 | /**
|
6563 | * Whether to apply inference from skeleton when calculating bounding box
|
6564 | * This can fix some models with skinned mesh when it has wrong bounding box
|
6565 | * @type boolean
|
6566 | */
|
6567 | get: function () {
|
6568 | return this._fixSkinnedBbox;
|
6569 | },
|
6570 | set: function (val) {
|
6571 | this._fixSkinnedBbox = val;
|
6572 | },
|
6573 | enumerable: false,
|
6574 | configurable: true
|
6575 | });
|
6576 | Object.defineProperty(__proto, "originalSize", {
|
6577 | /**
|
6578 | * Return the model's original bbox size before applying any transform
|
6579 | * @type number
|
6580 | */
|
6581 | get: function () {
|
6582 | return this._originalSize;
|
6583 | },
|
6584 | enumerable: false,
|
6585 | configurable: true
|
6586 | });
|
6587 | Object.defineProperty(__proto, "castShadow", {
|
6588 | /**
|
6589 | * Whether the model's meshes gets rendered into shadow map
|
6590 | * @type boolean
|
6591 | * @example
|
6592 | * model.castShadow = true;
|
6593 | */
|
6594 | set: function (val) {
|
6595 | var meshes = this.meshes;
|
6596 | meshes.forEach(function (mesh) {
|
6597 | return mesh.castShadow = val;
|
6598 | });
|
6599 | },
|
6600 | enumerable: false,
|
6601 | configurable: true
|
6602 | });
|
6603 | Object.defineProperty(__proto, "receiveShadow", {
|
6604 | /**
|
6605 | * Whether the model's mesh materials receive shadows
|
6606 | * @type boolean
|
6607 | * @example
|
6608 | * model.receiveShadow = true;
|
6609 | */
|
6610 | set: function (val) {
|
6611 | var meshes = this.meshes;
|
6612 | meshes.forEach(function (mesh) {
|
6613 | return mesh.receiveShadow = val;
|
6614 | });
|
6615 | },
|
6616 | enumerable: false,
|
6617 | configurable: true
|
6618 | });
|
6619 | /**
|
6620 | * Translate the model to center the model's bounding box to world origin (0, 0, 0).
|
6621 | */
|
6622 |
|
6623 | __proto.moveToOrigin = function () {
|
6624 | // Translate scene position to origin
|
6625 | var scene = this._scene;
|
6626 |
|
6627 | var initialBbox = this._initialBbox.clone();
|
6628 |
|
6629 | initialBbox.min.multiply(scene.scale);
|
6630 | initialBbox.max.multiply(scene.scale);
|
6631 | var bboxCenter = initialBbox.getCenter(new Vector3());
|
6632 | scene.position.copy(bboxCenter.negate());
|
6633 | scene.updateMatrix();
|
6634 | };
|
6635 |
|
6636 | __proto._setInitialBbox = function () {
|
6637 | this._scene.updateMatrixWorld();
|
6638 |
|
6639 | if (this._fixSkinnedBbox && this._hasSkinnedMesh()) {
|
6640 | this._initialBbox = this._getSkeletonBbox();
|
6641 | } else {
|
6642 | this._initialBbox = new Box3().setFromObject(this._scene);
|
6643 | }
|
6644 | };
|
6645 |
|
6646 | __proto._getSkeletonBbox = function () {
|
6647 | var bbox = new Box3();
|
6648 | this.meshes.forEach(function (mesh) {
|
6649 | if (!mesh.isSkinnedMesh) {
|
6650 | bbox.expandByObject(mesh);
|
6651 | return;
|
6652 | }
|
6653 |
|
6654 | var geometry = mesh.geometry;
|
6655 | var positions = geometry.attributes.position;
|
6656 | var skinIndicies = geometry.attributes.skinIndex;
|
6657 | var skinWeights = geometry.attributes.skinWeight;
|
6658 | var skeleton = mesh.skeleton;
|
6659 | skeleton.update();
|
6660 | var boneMatricies = skeleton.boneMatrices;
|
6661 | var finalMatrix = new Matrix4();
|
6662 |
|
6663 | var _loop_1 = function (posIdx) {
|
6664 | finalMatrix.identity();
|
6665 | var skinned = new Vector4();
|
6666 | skinned.set(0, 0, 0, 0);
|
6667 | var skinVertex = new Vector4();
|
6668 | skinVertex.set(positions.getX(posIdx), positions.getY(posIdx), positions.getZ(posIdx), 1).applyMatrix4(mesh.bindMatrix);
|
6669 | var weights = [skinWeights.getX(posIdx), skinWeights.getY(posIdx), skinWeights.getZ(posIdx), skinWeights.getW(posIdx)];
|
6670 | var indicies = [skinIndicies.getX(posIdx), skinIndicies.getY(posIdx), skinIndicies.getZ(posIdx), skinIndicies.getW(posIdx)];
|
6671 | weights.forEach(function (weight, index) {
|
6672 | var boneMatrix = new Matrix4().fromArray(boneMatricies, indicies[index] * 16);
|
6673 | skinned.add(skinVertex.clone().applyMatrix4(boneMatrix).multiplyScalar(weight));
|
6674 | });
|
6675 | var transformed = new Vector3().fromArray(skinned.applyMatrix4(mesh.bindMatrixInverse).toArray());
|
6676 | transformed.applyMatrix4(mesh.matrixWorld);
|
6677 | bbox.expandByPoint(transformed);
|
6678 | };
|
6679 |
|
6680 | for (var posIdx = 0; posIdx < positions.count; posIdx++) {
|
6681 | _loop_1(posIdx);
|
6682 | }
|
6683 | });
|
6684 | return bbox;
|
6685 | };
|
6686 |
|
6687 | __proto._moveInitialBboxToCenter = function () {
|
6688 | var bboxCenter = this._initialBbox.getCenter(new Vector3());
|
6689 |
|
6690 | this._initialBbox.translate(bboxCenter.negate());
|
6691 | };
|
6692 |
|
6693 | __proto._getAllLights = function () {
|
6694 | var lights = [];
|
6695 |
|
6696 | this._scene.traverse(function (obj) {
|
6697 | if (obj.isLight) {
|
6698 | lights.push(obj);
|
6699 | }
|
6700 | });
|
6701 |
|
6702 | this._cachedLights = lights;
|
6703 | return lights;
|
6704 | };
|
6705 | /**
|
6706 | * Get all {@link https://threejs.org/docs/#api/en/objects/Mesh THREE.Mesh}es inside model if there's any.
|
6707 | * @private
|
6708 | * @returns Meshes found at model's scene
|
6709 | */
|
6710 |
|
6711 |
|
6712 | __proto._getAllMeshes = function () {
|
6713 | var meshes = [];
|
6714 |
|
6715 | this._scene.traverse(function (obj) {
|
6716 | if (obj.isMesh) {
|
6717 | meshes.push(obj);
|
6718 | }
|
6719 | });
|
6720 |
|
6721 | this._cachedMeshes = meshes;
|
6722 | return meshes;
|
6723 | };
|
6724 |
|
6725 | __proto._hasSkinnedMesh = function () {
|
6726 | return this.meshes.some(function (mesh) {
|
6727 | return mesh.isSkinnedMesh;
|
6728 | });
|
6729 | };
|
6730 |
|
6731 | __proto._getTransformedBbox = function () {
|
6732 | return this._initialBbox.clone().applyMatrix4(this._scene.matrix);
|
6733 | };
|
6734 |
|
6735 | return Model;
|
6736 | }();
|
6737 |
|
6738 | /*
|
6739 | * Copyright (c) 2020 NAVER Corp.
|
6740 | * egjs projects are licensed under the MIT license
|
6741 | */
|
6742 |
|
6743 | var Core = {
|
6744 | __proto__: null,
|
6745 | ModelAnimator: ModelAnimator,
|
6746 | Model: Model,
|
6747 | Renderer: Renderer,
|
6748 | Scene: Scene$1,
|
6749 | XRManager: XRManager,
|
6750 | Camera: Camera$1,
|
6751 | Controller: Controller,
|
6752 | Pose: Pose
|
6753 | };
|
6754 |
|
6755 | /*
|
6756 | * Copyright (c) 2020 NAVER Corp.
|
6757 | * egjs projects are licensed under the MIT license
|
6758 | */
|
6759 | /**
|
6760 | * Control that animates model without user input
|
6761 | * @category Controls
|
6762 | */
|
6763 |
|
6764 | var AutoControl =
|
6765 | /*#__PURE__*/
|
6766 | function () {
|
6767 | /**
|
6768 | * Create new RotateControl instance
|
6769 | * @param {object} options Options
|
6770 | * @param {HTMLElement | string | null} [options.element=null] Attaching element / selector of the element
|
6771 | * @param {number} [options.delay=2000] Reactivation delay after mouse input in milisecond
|
6772 | * @param {number} [options.delayOnMouseLeave=0] Reactivation delay after mouse leave
|
6773 | * @param {number} [options.speed=1] Y-axis(yaw) rotation speed
|
6774 | * @param {boolean} [options.pauseOnHover=false] Whether to pause rotation on mouse hover
|
6775 | * @param {boolean} [options.canInterrupt=true] Whether user can interrupt the rotation with click/wheel input
|
6776 | * @param {boolean} [options.disableOnInterrupt=false] Whether to disable control on user interrupt
|
6777 | * @tutorial Adding Controls
|
6778 | */
|
6779 | function AutoControl(_a) {
|
6780 | var _this = this;
|
6781 |
|
6782 | var _b = _a === void 0 ? {} : _a,
|
6783 | _c = _b.element,
|
6784 | element = _c === void 0 ? NULL_ELEMENT : _c,
|
6785 | _d = _b.delay,
|
6786 | delay = _d === void 0 ? 2000 : _d,
|
6787 | _e = _b.delayOnMouseLeave,
|
6788 | delayOnMouseLeave = _e === void 0 ? 0 : _e,
|
6789 | _f = _b.speed,
|
6790 | speed = _f === void 0 ? 1 : _f,
|
6791 | _g = _b.pauseOnHover,
|
6792 | pauseOnHover = _g === void 0 ? false : _g,
|
6793 | _h = _b.canInterrupt,
|
6794 | canInterrupt = _h === void 0 ? true : _h,
|
6795 | _j = _b.disableOnInterrupt,
|
6796 | disableOnInterrupt = _j === void 0 ? false : _j; // Internal values
|
6797 |
|
6798 |
|
6799 | this._targetEl = null;
|
6800 | this._enabled = false;
|
6801 | this._interrupted = false;
|
6802 | this._interruptionTimer = -1;
|
6803 | this._hovering = false;
|
6804 |
|
6805 | this._onMouseDown = function (evt) {
|
6806 | if (!_this._canInterrupt) return;
|
6807 | if (evt.button !== MOUSE_BUTTON.LEFT && evt.button !== MOUSE_BUTTON.RIGHT) return;
|
6808 | _this._interrupted = true;
|
6809 |
|
6810 | _this._clearTimeout();
|
6811 |
|
6812 | window.addEventListener(EVENTS.MOUSE_UP, _this._onMouseUp, false);
|
6813 | };
|
6814 |
|
6815 | this._onMouseUp = function () {
|
6816 | window.removeEventListener(EVENTS.MOUSE_UP, _this._onMouseUp, false);
|
6817 |
|
6818 | _this._setUninterruptedAfterDelay(_this._delay);
|
6819 | };
|
6820 |
|
6821 | this._onTouchStart = function () {
|
6822 | if (!_this._canInterrupt) return;
|
6823 | _this._interrupted = true;
|
6824 |
|
6825 | _this._clearTimeout();
|
6826 | };
|
6827 |
|
6828 | this._onTouchEnd = function () {
|
6829 | _this._setUninterruptedAfterDelay(_this._delay);
|
6830 | };
|
6831 |
|
6832 | this._onMouseEnter = function () {
|
6833 | if (!_this._pauseOnHover) return;
|
6834 | _this._interrupted = true;
|
6835 | _this._hovering = true;
|
6836 | };
|
6837 |
|
6838 | this._onMouseLeave = function () {
|
6839 | if (!_this._pauseOnHover) return;
|
6840 | _this._hovering = false;
|
6841 |
|
6842 | _this._setUninterruptedAfterDelay(_this._delayOnMouseLeave);
|
6843 | };
|
6844 |
|
6845 | this._onWheel = function () {
|
6846 | if (!_this._canInterrupt) return;
|
6847 | _this._interrupted = true;
|
6848 |
|
6849 | _this._setUninterruptedAfterDelay(_this._delay);
|
6850 | };
|
6851 |
|
6852 | var targetEl = getElement(element);
|
6853 |
|
6854 | if (targetEl) {
|
6855 | this.setElement(targetEl);
|
6856 | }
|
6857 |
|
6858 | this._delay = delay;
|
6859 | this._delayOnMouseLeave = delayOnMouseLeave;
|
6860 | this._speed = speed;
|
6861 | this._pauseOnHover = pauseOnHover;
|
6862 | this._canInterrupt = canInterrupt;
|
6863 | this._disableOnInterrupt = disableOnInterrupt;
|
6864 | }
|
6865 |
|
6866 | var __proto = AutoControl.prototype;
|
6867 | Object.defineProperty(__proto, "element", {
|
6868 | /**
|
6869 | * Control's current target element to attach event listeners
|
6870 | * @readonly
|
6871 | */
|
6872 | get: function () {
|
6873 | return this._targetEl;
|
6874 | },
|
6875 | enumerable: false,
|
6876 | configurable: true
|
6877 | });
|
6878 | Object.defineProperty(__proto, "enabled", {
|
6879 | /**
|
6880 | * Whether this control is enabled or not
|
6881 | * @readonly
|
6882 | */
|
6883 | get: function () {
|
6884 | return this._enabled;
|
6885 | },
|
6886 | enumerable: false,
|
6887 | configurable: true
|
6888 | });
|
6889 | Object.defineProperty(__proto, "delay", {
|
6890 | /**
|
6891 | * Reactivation delay after mouse input in milisecond
|
6892 | */
|
6893 | get: function () {
|
6894 | return this._delay;
|
6895 | },
|
6896 | set: function (val) {
|
6897 | this._delay = val;
|
6898 | },
|
6899 | enumerable: false,
|
6900 | configurable: true
|
6901 | });
|
6902 | Object.defineProperty(__proto, "delayOnMouseLeave", {
|
6903 | /**
|
6904 | * Reactivation delay after mouse leave
|
6905 | * This option only works when {@link AutoControl#pauseOnHover pauseOnHover} is activated
|
6906 | */
|
6907 | get: function () {
|
6908 | return this._delayOnMouseLeave;
|
6909 | },
|
6910 | set: function (val) {
|
6911 | this._delayOnMouseLeave = val;
|
6912 | },
|
6913 | enumerable: false,
|
6914 | configurable: true
|
6915 | });
|
6916 | Object.defineProperty(__proto, "speed", {
|
6917 | /**
|
6918 | * Y-axis(yaw) rotation speed
|
6919 | * @default 1
|
6920 | */
|
6921 | get: function () {
|
6922 | return this._speed;
|
6923 | },
|
6924 | set: function (val) {
|
6925 | this._speed = val;
|
6926 | },
|
6927 | enumerable: false,
|
6928 | configurable: true
|
6929 | });
|
6930 | Object.defineProperty(__proto, "pauseOnHover", {
|
6931 | /**
|
6932 | * Whether to pause rotation on mouse hover
|
6933 | * @default false
|
6934 | */
|
6935 | get: function () {
|
6936 | return this._pauseOnHover;
|
6937 | },
|
6938 | set: function (val) {
|
6939 | this._pauseOnHover = val;
|
6940 | },
|
6941 | enumerable: false,
|
6942 | configurable: true
|
6943 | });
|
6944 | Object.defineProperty(__proto, "canInterrupt", {
|
6945 | /**
|
6946 | * Whether user can interrupt the rotation with click/wheel input
|
6947 | * @default true
|
6948 | */
|
6949 | get: function () {
|
6950 | return this._canInterrupt;
|
6951 | },
|
6952 | set: function (val) {
|
6953 | this._canInterrupt = val;
|
6954 | },
|
6955 | enumerable: false,
|
6956 | configurable: true
|
6957 | });
|
6958 | Object.defineProperty(__proto, "disableOnInterrupt", {
|
6959 | /**
|
6960 | * Whether to disable control on user interrupt
|
6961 | * @default false
|
6962 | */
|
6963 | get: function () {
|
6964 | return this._disableOnInterrupt;
|
6965 | },
|
6966 | set: function (val) {
|
6967 | this._disableOnInterrupt = val;
|
6968 | },
|
6969 | enumerable: false,
|
6970 | configurable: true
|
6971 | });
|
6972 | /**
|
6973 | * Destroy the instance and remove all event listeners attached
|
6974 | * This also will reset CSS cursor to intial
|
6975 | * @returns {void} Nothing
|
6976 | */
|
6977 |
|
6978 | __proto.destroy = function () {
|
6979 | this.disable();
|
6980 | };
|
6981 | /**
|
6982 | * Update control by given deltaTime
|
6983 | * @param camera Camera to update position
|
6984 | * @param deltaTime Number of milisec to update
|
6985 | * @returns {void} Nothing
|
6986 | */
|
6987 |
|
6988 |
|
6989 | __proto.update = function (camera, deltaTime) {
|
6990 | if (!this._enabled) return;
|
6991 |
|
6992 | if (this._interrupted) {
|
6993 | if (this._disableOnInterrupt) {
|
6994 | this.disable();
|
6995 | }
|
6996 |
|
6997 | return;
|
6998 | }
|
6999 |
|
7000 | camera.yaw += this._speed * deltaTime / 100;
|
7001 | }; // This is not documetned on purpose as it doesn't do nothing
|
7002 |
|
7003 |
|
7004 | __proto.resize = function (size) {// DO NOTHING
|
7005 | };
|
7006 | /**
|
7007 | * Enable this input and add event listeners
|
7008 | * @returns {void} Nothing
|
7009 | */
|
7010 |
|
7011 |
|
7012 | __proto.enable = function () {
|
7013 | if (this._enabled) return;
|
7014 |
|
7015 | if (!this._targetEl) {
|
7016 | throw new View3DError(MESSAGES.ADD_CONTROL_FIRST, CODES.ADD_CONTROL_FIRST);
|
7017 | }
|
7018 |
|
7019 | var targetEl = this._targetEl;
|
7020 | targetEl.addEventListener(EVENTS.MOUSE_DOWN, this._onMouseDown, false);
|
7021 | targetEl.addEventListener(EVENTS.TOUCH_START, this._onTouchStart, false);
|
7022 | targetEl.addEventListener(EVENTS.TOUCH_END, this._onTouchEnd, false);
|
7023 | targetEl.addEventListener(EVENTS.MOUSE_ENTER, this._onMouseEnter, false);
|
7024 | targetEl.addEventListener(EVENTS.MOUSE_LEAVE, this._onMouseLeave, false);
|
7025 | targetEl.addEventListener(EVENTS.WHEEL, this._onWheel, false);
|
7026 | this._enabled = true;
|
7027 | };
|
7028 | /**
|
7029 | * Disable this input and remove all event handlers
|
7030 | * @returns {void} Nothing
|
7031 | */
|
7032 |
|
7033 |
|
7034 | __proto.disable = function () {
|
7035 | if (!this._enabled || !this._targetEl) return;
|
7036 | var targetEl = this._targetEl;
|
7037 | targetEl.removeEventListener(EVENTS.MOUSE_DOWN, this._onMouseDown, false);
|
7038 | window.removeEventListener(EVENTS.MOUSE_UP, this._onMouseUp, false);
|
7039 | targetEl.removeEventListener(EVENTS.TOUCH_START, this._onTouchStart, false);
|
7040 | targetEl.removeEventListener(EVENTS.TOUCH_END, this._onTouchEnd, false);
|
7041 | targetEl.removeEventListener(EVENTS.MOUSE_ENTER, this._onMouseEnter, false);
|
7042 | targetEl.removeEventListener(EVENTS.MOUSE_LEAVE, this._onMouseLeave, false);
|
7043 | targetEl.removeEventListener(EVENTS.WHEEL, this._onWheel, false);
|
7044 | this._enabled = false;
|
7045 | this._interrupted = false;
|
7046 | this._hovering = false;
|
7047 |
|
7048 | this._clearTimeout();
|
7049 | }; // This does nothing
|
7050 |
|
7051 |
|
7052 | __proto.sync = function (camera) {// Do nothing
|
7053 | };
|
7054 | /**
|
7055 | * Set target element to attach event listener
|
7056 | * @param element target element
|
7057 | * @returns {void} Nothing
|
7058 | */
|
7059 |
|
7060 |
|
7061 | __proto.setElement = function (element) {
|
7062 | this._targetEl = element;
|
7063 | };
|
7064 |
|
7065 | __proto._setUninterruptedAfterDelay = function (delay) {
|
7066 | var _this = this;
|
7067 |
|
7068 | if (this._hovering) return;
|
7069 |
|
7070 | this._clearTimeout();
|
7071 |
|
7072 | if (delay > 0) {
|
7073 | this._interruptionTimer = window.setTimeout(function () {
|
7074 | _this._interrupted = false;
|
7075 | _this._interruptionTimer = -1;
|
7076 | }, delay);
|
7077 | } else {
|
7078 | this._interrupted = false;
|
7079 | this._interruptionTimer = -1;
|
7080 | }
|
7081 | };
|
7082 |
|
7083 | __proto._clearTimeout = function () {
|
7084 | if (this._interruptionTimer >= 0) {
|
7085 | window.clearTimeout(this._interruptionTimer);
|
7086 | this._interruptionTimer = -1;
|
7087 | }
|
7088 | };
|
7089 |
|
7090 | return AutoControl;
|
7091 | }();
|
7092 |
|
7093 | /*
|
7094 | * Copyright (c) 2020 NAVER Corp.
|
7095 | * egjs projects are licensed under the MIT license
|
7096 | */
|
7097 | var CURSOR = {
|
7098 | GRAB: "grab",
|
7099 | GRABBING: "grabbing"
|
7100 | };
|
7101 |
|
7102 | /*
|
7103 | * Copyright (c) 2020 NAVER Corp.
|
7104 | * egjs projects are licensed under the MIT license
|
7105 | */
|
7106 | /**
|
7107 | * Model's rotation control that supports both mouse & touch
|
7108 | * @category Controls
|
7109 | */
|
7110 |
|
7111 | var RotateControl =
|
7112 | /*#__PURE__*/
|
7113 | function () {
|
7114 | /**
|
7115 | * Create new RotateControl instance
|
7116 | * @param {object} options Options
|
7117 | * @param {HTMLElement | null} [options.element] Target element.
|
7118 | * @param {number} [options.duration=500] Motion's duration.
|
7119 | * @param {function} [options.easing=(x: number) => 1 - Math.pow(1 - x, 3)] Motion's easing function.
|
7120 | * @param {THREE.Vector2} [options.scale=new THREE.Vector2(1, 1)] Scale factor for panning, x is for horizontal and y is for vertical panning.
|
7121 | * @param {boolean} [options.useGrabCursor=true] Whether to apply CSS style `cursor: grab` on the target element or not.
|
7122 | * @param {boolean} [options.scaleToElement=true] Whether to scale control to fit element size.
|
7123 | * @tutorial Adding Controls
|
7124 | */
|
7125 | function RotateControl(_a) {
|
7126 | var _this = this;
|
7127 |
|
7128 | var _b = _a === void 0 ? {} : _a,
|
7129 | _c = _b.element,
|
7130 | element = _c === void 0 ? NULL_ELEMENT : _c,
|
7131 | _d = _b.duration,
|
7132 | duration = _d === void 0 ? ANIMATION_DURATION : _d,
|
7133 | _e = _b.easing,
|
7134 | easing = _e === void 0 ? EASING$1 : _e,
|
7135 | _f = _b.scale,
|
7136 | scale = _f === void 0 ? new Vector2(1, 1) : _f,
|
7137 | _g = _b.useGrabCursor,
|
7138 | useGrabCursor = _g === void 0 ? true : _g,
|
7139 | _h = _b.scaleToElement,
|
7140 | scaleToElement = _h === void 0 ? true : _h; // Internal values
|
7141 |
|
7142 |
|
7143 | this._targetEl = null;
|
7144 | this._screenScale = new Vector2(0, 0);
|
7145 | this._prevPos = new Vector2(0, 0);
|
7146 | this._enabled = false;
|
7147 |
|
7148 | this._onMouseDown = function (evt) {
|
7149 | if (evt.button !== MOUSE_BUTTON.LEFT) return;
|
7150 | var targetEl = _this._targetEl;
|
7151 | evt.preventDefault();
|
7152 | targetEl.focus ? targetEl.focus() : window.focus();
|
7153 |
|
7154 | _this._prevPos.set(evt.clientX, evt.clientY);
|
7155 |
|
7156 | window.addEventListener(EVENTS.MOUSE_MOVE, _this._onMouseMove, false);
|
7157 | window.addEventListener(EVENTS.MOUSE_UP, _this._onMouseUp, false);
|
7158 |
|
7159 | _this._setCursor(CURSOR.GRABBING);
|
7160 | };
|
7161 |
|
7162 | this._onMouseMove = function (evt) {
|
7163 | evt.preventDefault();
|
7164 | var prevPos = _this._prevPos;
|
7165 | var rotateDelta = new Vector2(evt.clientX, evt.clientY).sub(prevPos).multiply(_this._userScale);
|
7166 |
|
7167 | if (_this._scaleToElement) {
|
7168 | rotateDelta.multiply(_this._screenScale);
|
7169 | }
|
7170 |
|
7171 | _this._xMotion.setEndDelta(rotateDelta.x);
|
7172 |
|
7173 | _this._yMotion.setEndDelta(rotateDelta.y);
|
7174 |
|
7175 | prevPos.set(evt.clientX, evt.clientY);
|
7176 | };
|
7177 |
|
7178 | this._onMouseUp = function () {
|
7179 | _this._prevPos.set(0, 0);
|
7180 |
|
7181 | window.removeEventListener(EVENTS.MOUSE_MOVE, _this._onMouseMove, false);
|
7182 | window.removeEventListener(EVENTS.MOUSE_UP, _this._onMouseUp, false);
|
7183 |
|
7184 | _this._setCursor(CURSOR.GRAB);
|
7185 | };
|
7186 |
|
7187 | this._onTouchStart = function (evt) {
|
7188 | evt.preventDefault();
|
7189 | var touch = evt.touches[0];
|
7190 |
|
7191 | _this._prevPos.set(touch.clientX, touch.clientY);
|
7192 | };
|
7193 |
|
7194 | this._onTouchMove = function (evt) {
|
7195 | // Only the one finger motion should be considered
|
7196 | if (evt.touches.length > 1) return;
|
7197 |
|
7198 | if (evt.cancelable !== false) {
|
7199 | evt.preventDefault();
|
7200 | }
|
7201 |
|
7202 | evt.stopPropagation();
|
7203 | var touch = evt.touches[0];
|
7204 | var prevPos = _this._prevPos;
|
7205 | var rotateDelta = new Vector2(touch.clientX, touch.clientY).sub(prevPos).multiply(_this._userScale);
|
7206 |
|
7207 | if (_this._scaleToElement) {
|
7208 | rotateDelta.multiply(_this._screenScale);
|
7209 | }
|
7210 |
|
7211 | _this._xMotion.setEndDelta(rotateDelta.x);
|
7212 |
|
7213 | _this._yMotion.setEndDelta(rotateDelta.y);
|
7214 |
|
7215 | prevPos.set(touch.clientX, touch.clientY);
|
7216 | };
|
7217 |
|
7218 | this._onTouchEnd = function (evt) {
|
7219 | var touch = evt.touches[0];
|
7220 |
|
7221 | if (touch) {
|
7222 | _this._prevPos.set(touch.clientX, touch.clientY);
|
7223 | } else {
|
7224 | _this._prevPos.set(0, 0);
|
7225 | }
|
7226 | };
|
7227 |
|
7228 | var targetEl = getElement(element);
|
7229 |
|
7230 | if (targetEl) {
|
7231 | this.setElement(targetEl);
|
7232 | }
|
7233 |
|
7234 | this._userScale = scale;
|
7235 | this._useGrabCursor = useGrabCursor;
|
7236 | this._scaleToElement = scaleToElement;
|
7237 | this._xMotion = new Motion({
|
7238 | duration: duration,
|
7239 | range: INFINITE_RANGE,
|
7240 | easing: easing
|
7241 | });
|
7242 | this._yMotion = new Motion({
|
7243 | duration: duration,
|
7244 | range: PITCH_RANGE,
|
7245 | easing: easing
|
7246 | });
|
7247 | }
|
7248 |
|
7249 | var __proto = RotateControl.prototype;
|
7250 | Object.defineProperty(__proto, "element", {
|
7251 | /**
|
7252 | * Control's current target element to attach event listeners
|
7253 | * @readonly
|
7254 | */
|
7255 | get: function () {
|
7256 | return this._targetEl;
|
7257 | },
|
7258 | enumerable: false,
|
7259 | configurable: true
|
7260 | });
|
7261 | Object.defineProperty(__proto, "scale", {
|
7262 | /**
|
7263 | * Scale factor for panning, x is for horizontal and y is for vertical panning.
|
7264 | * @type THREE.Vector2
|
7265 | * @see https://threejs.org/docs/#api/en/math/Vector2
|
7266 | * @example
|
7267 | * const rotateControl = new View3D.RotateControl();
|
7268 | * rotateControl.scale.setX(2);
|
7269 | */
|
7270 | get: function () {
|
7271 | return this._userScale;
|
7272 | },
|
7273 | set: function (val) {
|
7274 | this._userScale.copy(val);
|
7275 | },
|
7276 | enumerable: false,
|
7277 | configurable: true
|
7278 | });
|
7279 | Object.defineProperty(__proto, "useGrabCursor", {
|
7280 | /**
|
7281 | * Whether to apply CSS style `cursor: grab` on the target element or not
|
7282 | * @default true
|
7283 | * @example
|
7284 | * const rotateControl = new View3D.RotateControl();
|
7285 | * rotateControl.useGrabCursor = true;
|
7286 | */
|
7287 | get: function () {
|
7288 | return this._useGrabCursor;
|
7289 | },
|
7290 | set: function (val) {
|
7291 | if (!val) {
|
7292 | this._setCursor("");
|
7293 |
|
7294 | this._useGrabCursor = false;
|
7295 | } else {
|
7296 | this._useGrabCursor = true;
|
7297 |
|
7298 | this._setCursor(CURSOR.GRAB);
|
7299 | }
|
7300 | },
|
7301 | enumerable: false,
|
7302 | configurable: true
|
7303 | });
|
7304 | Object.defineProperty(__proto, "scaleToElement", {
|
7305 | /**
|
7306 | * Whether to scale control to fit element size.
|
7307 | * When this is true and {@link RotateControl#scale scale.x} is 1, panning through element's width will make 3d model's yaw rotate 360°.
|
7308 | * When this is true and {@link RotateControl#scale scale.y} is 1, panning through element's height will make 3d model's pitch rotate 180°.
|
7309 | * @default true
|
7310 | * @example
|
7311 | * import View3D, { RotateControl } from "@egjs/view3d";
|
7312 | * const view3d = new View3D("#view3d-canvas");
|
7313 | * const rotateControl = new RotateControl();
|
7314 | * rotateControl.scaleToElement = true;
|
7315 | * view3d.controller.add(rotateControl);
|
7316 | * view3d.resize();
|
7317 | */
|
7318 | get: function () {
|
7319 | return this._scaleToElement;
|
7320 | },
|
7321 | set: function (val) {
|
7322 | this._scaleToElement = val;
|
7323 | },
|
7324 | enumerable: false,
|
7325 | configurable: true
|
7326 | });
|
7327 | Object.defineProperty(__proto, "enabled", {
|
7328 | /**
|
7329 | * Whether this control is enabled or not
|
7330 | * @readonly
|
7331 | */
|
7332 | get: function () {
|
7333 | return this._enabled;
|
7334 | },
|
7335 | enumerable: false,
|
7336 | configurable: true
|
7337 | });
|
7338 | /**
|
7339 | * Destroy the instance and remove all event listeners attached
|
7340 | * This also will reset CSS cursor to intial
|
7341 | * @returns {void} Nothing
|
7342 | */
|
7343 |
|
7344 | __proto.destroy = function () {
|
7345 | this.disable();
|
7346 | };
|
7347 | /**
|
7348 | * Update control by given deltaTime
|
7349 | * @param camera Camera to update position
|
7350 | * @param deltaTime Number of milisec to update
|
7351 | * @returns {void} Nothing
|
7352 | */
|
7353 |
|
7354 |
|
7355 | __proto.update = function (camera, deltaTime) {
|
7356 | var xMotion = this._xMotion;
|
7357 | var yMotion = this._yMotion;
|
7358 | var delta = new Vector2(xMotion.update(deltaTime), yMotion.update(deltaTime));
|
7359 | camera.yaw += delta.x;
|
7360 | camera.pitch += delta.y;
|
7361 | };
|
7362 | /**
|
7363 | * Resize control to match target size
|
7364 | * This method is only meaningful when {@link RotateControl#scaleToElement scaleToElement} is enabled
|
7365 | * @param size {@link https://threejs.org/docs/#api/en/math/Vector2 THREE.Vector2} instance of width(x), height(y)
|
7366 | */
|
7367 |
|
7368 |
|
7369 | __proto.resize = function (size) {
|
7370 | this._screenScale.set(360 / size.x, 180 / size.y);
|
7371 | };
|
7372 | /**
|
7373 | * Enable this input and add event listeners
|
7374 | * @returns {void} Nothing
|
7375 | */
|
7376 |
|
7377 |
|
7378 | __proto.enable = function () {
|
7379 | if (this._enabled) return;
|
7380 |
|
7381 | if (!this._targetEl) {
|
7382 | throw new View3DError(MESSAGES.ADD_CONTROL_FIRST, CODES.ADD_CONTROL_FIRST);
|
7383 | }
|
7384 |
|
7385 | var targetEl = this._targetEl;
|
7386 | targetEl.addEventListener(EVENTS.MOUSE_DOWN, this._onMouseDown, false);
|
7387 | targetEl.addEventListener(EVENTS.TOUCH_START, this._onTouchStart, false);
|
7388 | targetEl.addEventListener(EVENTS.TOUCH_MOVE, this._onTouchMove, false);
|
7389 | targetEl.addEventListener(EVENTS.TOUCH_END, this._onTouchEnd, false);
|
7390 | this._enabled = true;
|
7391 |
|
7392 | this._setCursor(CURSOR.GRAB);
|
7393 | };
|
7394 | /**
|
7395 | * Disable this input and remove all event handlers
|
7396 | * @returns {void} Nothing
|
7397 | */
|
7398 |
|
7399 |
|
7400 | __proto.disable = function () {
|
7401 | if (!this._enabled || !this._targetEl) return;
|
7402 | var targetEl = this._targetEl;
|
7403 | targetEl.removeEventListener(EVENTS.MOUSE_DOWN, this._onMouseDown, false);
|
7404 | window.removeEventListener(EVENTS.MOUSE_MOVE, this._onMouseMove, false);
|
7405 | window.removeEventListener(EVENTS.MOUSE_UP, this._onMouseUp, false);
|
7406 | targetEl.removeEventListener(EVENTS.TOUCH_START, this._onTouchStart, false);
|
7407 | targetEl.removeEventListener(EVENTS.TOUCH_MOVE, this._onTouchMove, false);
|
7408 | targetEl.removeEventListener(EVENTS.TOUCH_END, this._onTouchEnd, false);
|
7409 |
|
7410 | this._setCursor("");
|
7411 |
|
7412 | this._enabled = false;
|
7413 | };
|
7414 | /**
|
7415 | * Synchronize this control's state to given camera position
|
7416 | * @param camera Camera to match state
|
7417 | * @returns {void} Nothing
|
7418 | */
|
7419 |
|
7420 |
|
7421 | __proto.sync = function (camera) {
|
7422 | this._xMotion.reset(camera.yaw);
|
7423 |
|
7424 | this._yMotion.reset(camera.pitch);
|
7425 | };
|
7426 | /**
|
7427 | * Set target element to attach event listener
|
7428 | * @param element target element
|
7429 | * @returns {void} Nothing
|
7430 | */
|
7431 |
|
7432 |
|
7433 | __proto.setElement = function (element) {
|
7434 | this._targetEl = element;
|
7435 | this.resize(new Vector2(element.offsetWidth, element.offsetHeight));
|
7436 | };
|
7437 |
|
7438 | __proto._setCursor = function (val) {
|
7439 | var targetEl = this._targetEl;
|
7440 | if (!this._useGrabCursor || !targetEl || !this._enabled) return;
|
7441 | targetEl.style.cursor = val;
|
7442 | };
|
7443 |
|
7444 | return RotateControl;
|
7445 | }();
|
7446 |
|
7447 | /*
|
7448 | * Copyright (c) 2020 NAVER Corp.
|
7449 | * egjs projects are licensed under the MIT license
|
7450 | */
|
7451 | /**
|
7452 | * Model's translation control that supports both mouse & touch
|
7453 | * @category Controls
|
7454 | */
|
7455 |
|
7456 | var TranslateControl =
|
7457 | /*#__PURE__*/
|
7458 | function () {
|
7459 | /**
|
7460 | * Create new TranslateControl instance
|
7461 | * @param {object} options Options
|
7462 | * @param {HTMLElement | null} [options.element] Target element.
|
7463 | * @param {function} [options.easing=(x: number) => 1 - Math.pow(1 - x, 3)] Motion's easing function.
|
7464 | * @param {THREE.Vector2} [options.scale=new THREE.Vector2(1, 1)] Scale factor for translation.
|
7465 | * @param {boolean} [options.useGrabCursor=true] Whether to apply CSS style `cursor: grab` on the target element or not.
|
7466 | * @param {boolean} [options.scaleToElement=true] Whether to scale control to fit element size.
|
7467 | * @tutorial Adding Controls
|
7468 | */
|
7469 | function TranslateControl(_a) {
|
7470 | var _this = this;
|
7471 |
|
7472 | var _b = _a === void 0 ? {} : _a,
|
7473 | _c = _b.element,
|
7474 | element = _c === void 0 ? NULL_ELEMENT : _c,
|
7475 | _d = _b.easing,
|
7476 | easing = _d === void 0 ? EASING$1 : _d,
|
7477 | _e = _b.scale,
|
7478 | scale = _e === void 0 ? new Vector2(1, 1) : _e,
|
7479 | _f = _b.useGrabCursor,
|
7480 | useGrabCursor = _f === void 0 ? true : _f,
|
7481 | _g = _b.scaleToElement,
|
7482 | scaleToElement = _g === void 0 ? true : _g; // Internal values
|
7483 |
|
7484 |
|
7485 | this._targetEl = null;
|
7486 | this._enabled = false; // Sometimes, touchstart for second finger doesn't triggered.
|
7487 | // This flag checks whether that happened
|
7488 |
|
7489 | this._touchInitialized = false;
|
7490 | this._prevPos = new Vector2(0, 0);
|
7491 | this._screenSize = new Vector2(0, 0);
|
7492 |
|
7493 | this._onMouseDown = function (evt) {
|
7494 | if (evt.button !== MOUSE_BUTTON.RIGHT) return;
|
7495 | var targetEl = _this._targetEl;
|
7496 | evt.preventDefault();
|
7497 | targetEl.focus ? targetEl.focus() : window.focus();
|
7498 |
|
7499 | _this._prevPos.set(evt.clientX, evt.clientY);
|
7500 |
|
7501 | window.addEventListener(EVENTS.MOUSE_MOVE, _this._onMouseMove, false);
|
7502 | window.addEventListener(EVENTS.MOUSE_UP, _this._onMouseUp, false);
|
7503 |
|
7504 | _this._setCursor(CURSOR.GRABBING);
|
7505 | };
|
7506 |
|
7507 | this._onMouseMove = function (evt) {
|
7508 | evt.preventDefault();
|
7509 | var prevPos = _this._prevPos;
|
7510 | var delta = new Vector2(evt.clientX, evt.clientY).sub(prevPos).multiply(_this._userScale); // X value is negated to match cursor direction
|
7511 |
|
7512 | _this._xMotion.setEndDelta(-delta.x);
|
7513 |
|
7514 | _this._yMotion.setEndDelta(delta.y);
|
7515 |
|
7516 | prevPos.set(evt.clientX, evt.clientY);
|
7517 | };
|
7518 |
|
7519 | this._onMouseUp = function () {
|
7520 | _this._prevPos.set(0, 0);
|
7521 |
|
7522 | window.removeEventListener(EVENTS.MOUSE_MOVE, _this._onMouseMove, false);
|
7523 | window.removeEventListener(EVENTS.MOUSE_UP, _this._onMouseUp, false);
|
7524 |
|
7525 | _this._setCursor(CURSOR.GRAB);
|
7526 | };
|
7527 |
|
7528 | this._onTouchStart = function (evt) {
|
7529 | // Only the two finger motion should be considered
|
7530 | if (evt.touches.length !== 2) return;
|
7531 | evt.preventDefault();
|
7532 |
|
7533 | _this._prevPos.copy(_this._getTouchesMiddle(evt.touches));
|
7534 |
|
7535 | _this._touchInitialized = true;
|
7536 | };
|
7537 |
|
7538 | this._onTouchMove = function (evt) {
|
7539 | // Only the two finger motion should be considered
|
7540 | if (evt.touches.length !== 2) return;
|
7541 |
|
7542 | if (evt.cancelable !== false) {
|
7543 | evt.preventDefault();
|
7544 | }
|
7545 |
|
7546 | evt.stopPropagation();
|
7547 | var prevPos = _this._prevPos;
|
7548 |
|
7549 | var middlePoint = _this._getTouchesMiddle(evt.touches);
|
7550 |
|
7551 | if (!_this._touchInitialized) {
|
7552 | prevPos.copy(middlePoint);
|
7553 | _this._touchInitialized = true;
|
7554 | return;
|
7555 | }
|
7556 |
|
7557 | var delta = new Vector2().subVectors(middlePoint, prevPos).multiply(_this._userScale); // X value is negated to match cursor direction
|
7558 |
|
7559 | _this._xMotion.setEndDelta(-delta.x);
|
7560 |
|
7561 | _this._yMotion.setEndDelta(delta.y);
|
7562 |
|
7563 | prevPos.copy(middlePoint);
|
7564 | };
|
7565 |
|
7566 | this._onTouchEnd = function (evt) {
|
7567 | // Only the two finger motion should be considered
|
7568 | if (evt.touches.length !== 2) {
|
7569 | _this._touchInitialized = false;
|
7570 | return;
|
7571 | } // Three fingers to two fingers
|
7572 |
|
7573 |
|
7574 | _this._prevPos.copy(_this._getTouchesMiddle(evt.touches));
|
7575 |
|
7576 | _this._touchInitialized = true;
|
7577 | };
|
7578 |
|
7579 | this._onContextMenu = function (evt) {
|
7580 | evt.preventDefault();
|
7581 | };
|
7582 |
|
7583 | var targetEl = getElement(element);
|
7584 |
|
7585 | if (targetEl) {
|
7586 | this.setElement(targetEl);
|
7587 | }
|
7588 |
|
7589 | this._xMotion = new Motion({
|
7590 | duration: 0,
|
7591 | range: INFINITE_RANGE,
|
7592 | easing: easing
|
7593 | });
|
7594 | this._yMotion = new Motion({
|
7595 | duration: 0,
|
7596 | range: INFINITE_RANGE,
|
7597 | easing: easing
|
7598 | });
|
7599 | this._userScale = scale;
|
7600 | this._useGrabCursor = useGrabCursor;
|
7601 | this._scaleToElement = scaleToElement;
|
7602 | }
|
7603 |
|
7604 | var __proto = TranslateControl.prototype;
|
7605 | Object.defineProperty(__proto, "element", {
|
7606 | /**
|
7607 | * Control's current target element to attach event listeners
|
7608 | * @readonly
|
7609 | */
|
7610 | get: function () {
|
7611 | return this._targetEl;
|
7612 | },
|
7613 | enumerable: false,
|
7614 | configurable: true
|
7615 | });
|
7616 | Object.defineProperty(__proto, "scale", {
|
7617 | /**
|
7618 | * Scale factor for translation
|
7619 | * @type THREE.Vector2
|
7620 | * @see https://threejs.org/docs/#api/en/math/Vector2
|
7621 | * @example
|
7622 | * import { TranslateControl } from "@egjs/view3d";
|
7623 | * const translateControl = new TranslateControl();
|
7624 | * translateControl.scale.set(2, 2);
|
7625 | */
|
7626 | get: function () {
|
7627 | return this._userScale;
|
7628 | },
|
7629 | set: function (val) {
|
7630 | this._userScale.copy(val);
|
7631 | },
|
7632 | enumerable: false,
|
7633 | configurable: true
|
7634 | });
|
7635 | Object.defineProperty(__proto, "useGrabCursor", {
|
7636 | /**
|
7637 | * Whether to apply CSS style `cursor: grab` on the target element or not
|
7638 | * @default true
|
7639 | * @example
|
7640 | * import { TranslateControl } from "@egjs/view3d";
|
7641 | * const translateControl = new TranslateControl();
|
7642 | * translateControl.useGrabCursor = true;
|
7643 | */
|
7644 | get: function () {
|
7645 | return this._useGrabCursor;
|
7646 | },
|
7647 | set: function (val) {
|
7648 | if (!val) {
|
7649 | this._setCursor("");
|
7650 |
|
7651 | this._useGrabCursor = false;
|
7652 | } else {
|
7653 | this._useGrabCursor = true;
|
7654 |
|
7655 | this._setCursor(CURSOR.GRAB);
|
7656 | }
|
7657 | },
|
7658 | enumerable: false,
|
7659 | configurable: true
|
7660 | });
|
7661 | Object.defineProperty(__proto, "scaleToElement", {
|
7662 | /**
|
7663 | * Scale control to fit element size.
|
7664 | * When this is true, camera's pivot change will correspond same amount you've dragged.
|
7665 | * @default true
|
7666 | * @example
|
7667 | * import View3D, { TranslateControl } from "@egjs/view3d";
|
7668 | * const view3d = new View3D("#view3d-canvas");
|
7669 | * const translateControl = new TranslateControl();
|
7670 | * translateControl.scaleToElement = true;
|
7671 | * view3d.controller.add(translateControl);
|
7672 | * view3d.resize();
|
7673 | */
|
7674 | get: function () {
|
7675 | return this._scaleToElement;
|
7676 | },
|
7677 | set: function (val) {
|
7678 | this._scaleToElement = val;
|
7679 | },
|
7680 | enumerable: false,
|
7681 | configurable: true
|
7682 | });
|
7683 | Object.defineProperty(__proto, "enabled", {
|
7684 | /**
|
7685 | * Whether this control is enabled or not
|
7686 | * @readonly
|
7687 | */
|
7688 | get: function () {
|
7689 | return this._enabled;
|
7690 | },
|
7691 | enumerable: false,
|
7692 | configurable: true
|
7693 | });
|
7694 | /**
|
7695 | * Destroy the instance and remove all event listeners attached
|
7696 | * This also will reset CSS cursor to intial
|
7697 | * @returns {void} Nothing
|
7698 | */
|
7699 |
|
7700 | __proto.destroy = function () {
|
7701 | this.disable();
|
7702 | };
|
7703 | /**
|
7704 | * Update control by given deltaTime
|
7705 | * @param deltaTime Number of milisec to update
|
7706 | * @returns {void} Nothing
|
7707 | */
|
7708 |
|
7709 |
|
7710 | __proto.update = function (camera, deltaTime) {
|
7711 | var screenSize = this._screenSize;
|
7712 | var delta = new Vector2(this._xMotion.update(deltaTime), this._yMotion.update(deltaTime));
|
7713 | var viewXDir = new Vector3(1, 0, 0).applyQuaternion(camera.threeCamera.quaternion);
|
7714 | var viewYDir = new Vector3(0, 1, 0).applyQuaternion(camera.threeCamera.quaternion);
|
7715 |
|
7716 | if (this._scaleToElement) {
|
7717 | var screenScale = new Vector2(camera.renderWidth, camera.renderHeight).divide(screenSize);
|
7718 | delta.multiply(screenScale);
|
7719 | }
|
7720 |
|
7721 | camera.pivot.add(viewXDir.multiplyScalar(delta.x));
|
7722 | camera.pivot.add(viewYDir.multiplyScalar(delta.y));
|
7723 | };
|
7724 | /**
|
7725 | * Resize control to match target size
|
7726 | * This method is only meaningful when {@link RotateControl#scaleToElementSize scaleToElementSize} is enabled
|
7727 | * @param size {@link https://threejs.org/docs/#api/en/math/Vector2 THREE.Vector2} instance of width(x), height(y)
|
7728 | */
|
7729 |
|
7730 |
|
7731 | __proto.resize = function (size) {
|
7732 | var screenSize = this._screenSize;
|
7733 | screenSize.copy(size);
|
7734 | };
|
7735 | /**
|
7736 | * Enable this input and add event listeners
|
7737 | * @returns {void} Nothing
|
7738 | */
|
7739 |
|
7740 |
|
7741 | __proto.enable = function () {
|
7742 | if (this._enabled) return;
|
7743 |
|
7744 | if (!this._targetEl) {
|
7745 | throw new View3DError(MESSAGES.ADD_CONTROL_FIRST, CODES.ADD_CONTROL_FIRST);
|
7746 | }
|
7747 |
|
7748 | var targetEl = this._targetEl;
|
7749 | targetEl.addEventListener(EVENTS.MOUSE_DOWN, this._onMouseDown, false);
|
7750 | targetEl.addEventListener(EVENTS.TOUCH_START, this._onTouchStart, false);
|
7751 | targetEl.addEventListener(EVENTS.TOUCH_MOVE, this._onTouchMove, false);
|
7752 | targetEl.addEventListener(EVENTS.TOUCH_END, this._onTouchEnd, false);
|
7753 | targetEl.addEventListener(EVENTS.CONTEXT_MENU, this._onContextMenu, false);
|
7754 | this._enabled = true;
|
7755 |
|
7756 | this._setCursor(CURSOR.GRAB);
|
7757 | };
|
7758 | /**
|
7759 | * Disable this input and remove all event handlers
|
7760 | * @returns {void} Nothing
|
7761 | */
|
7762 |
|
7763 |
|
7764 | __proto.disable = function () {
|
7765 | if (!this._enabled || !this._targetEl) return;
|
7766 | var targetEl = this._targetEl;
|
7767 | targetEl.removeEventListener(EVENTS.MOUSE_DOWN, this._onMouseDown, false);
|
7768 | window.removeEventListener(EVENTS.MOUSE_MOVE, this._onMouseMove, false);
|
7769 | window.removeEventListener(EVENTS.MOUSE_UP, this._onMouseUp, false);
|
7770 | targetEl.removeEventListener(EVENTS.TOUCH_START, this._onTouchStart, false);
|
7771 | targetEl.removeEventListener(EVENTS.TOUCH_MOVE, this._onTouchMove, false);
|
7772 | targetEl.removeEventListener(EVENTS.TOUCH_END, this._onTouchEnd, false);
|
7773 | targetEl.removeEventListener(EVENTS.CONTEXT_MENU, this._onContextMenu, false);
|
7774 |
|
7775 | this._setCursor("");
|
7776 |
|
7777 | this._enabled = false;
|
7778 | };
|
7779 | /**
|
7780 | * Synchronize this control's state to given camera position
|
7781 | * @param camera Camera to match state
|
7782 | * @returns {void} Nothing
|
7783 | */
|
7784 |
|
7785 |
|
7786 | __proto.sync = function (camera) {
|
7787 | this._xMotion.reset(0);
|
7788 |
|
7789 | this._yMotion.reset(0);
|
7790 | };
|
7791 | /**
|
7792 | * Set target element to attach event listener
|
7793 | * @param element target element
|
7794 | * @returns {void} Nothing
|
7795 | */
|
7796 |
|
7797 |
|
7798 | __proto.setElement = function (element) {
|
7799 | this._targetEl = element;
|
7800 | this.resize(new Vector2(element.offsetWidth, element.offsetHeight));
|
7801 | };
|
7802 |
|
7803 | __proto._setCursor = function (val) {
|
7804 | var targetEl = this._targetEl;
|
7805 | if (!this._useGrabCursor || !targetEl || !this._enabled) return;
|
7806 | targetEl.style.cursor = val;
|
7807 | };
|
7808 |
|
7809 | __proto._getTouchesMiddle = function (touches) {
|
7810 | return new Vector2(touches[0].clientX + touches[1].clientX, touches[0].clientY + touches[1].clientY).multiplyScalar(0.5);
|
7811 | };
|
7812 |
|
7813 | return TranslateControl;
|
7814 | }();
|
7815 |
|
7816 | /*
|
7817 | * Copyright (c) 2020 NAVER Corp.
|
7818 | * egjs projects are licensed under the MIT license
|
7819 | */
|
7820 | /**
|
7821 | * Distance controller handling both mouse wheel and pinch zoom
|
7822 | * @category Controls
|
7823 | */
|
7824 |
|
7825 | var DistanceControl =
|
7826 | /*#__PURE__*/
|
7827 | function () {
|
7828 | /**
|
7829 | * Create new DistanceControl instance
|
7830 | * @tutorial Adding Controls
|
7831 | * @param {object} options Options
|
7832 | * @param {HTMLElement | string | null} [options.element=null] Attaching element / selector of the element.
|
7833 | * @param {number} [options.duration=500] Motion's duration.
|
7834 | * @param {object} [options.range={min: 0, max: 500}] Motion's range.
|
7835 | * @param {function} [options.easing=(x: number) => 1 - Math.pow(1 - x, 3)] Motion's easing function.
|
7836 | */
|
7837 | function DistanceControl(_a) {
|
7838 | var _this = this;
|
7839 |
|
7840 | var _b = _a === void 0 ? {} : _a,
|
7841 | _c = _b.element,
|
7842 | element = _c === void 0 ? NULL_ELEMENT : _c,
|
7843 | _d = _b.duration,
|
7844 | duration = _d === void 0 ? ANIMATION_DURATION : _d,
|
7845 | _e = _b.range,
|
7846 | range = _e === void 0 ? DISTANCE_RANGE : _e,
|
7847 | _f = _b.easing,
|
7848 | easing = _f === void 0 ? EASING$1 : _f; // Options
|
7849 |
|
7850 |
|
7851 | this._scale = 1; // Internal values
|
7852 |
|
7853 | this._targetEl = null;
|
7854 | this._scaleModifier = 0.25;
|
7855 | this._prevTouchDistance = -1;
|
7856 | this._enabled = false;
|
7857 |
|
7858 | this._onWheel = function (evt) {
|
7859 | if (evt.deltaY === 0) return;
|
7860 | evt.preventDefault();
|
7861 | evt.stopPropagation();
|
7862 | var animation = _this._motion;
|
7863 | var delta = _this._scale * _this._scaleModifier * evt.deltaY;
|
7864 | animation.setEndDelta(delta);
|
7865 | };
|
7866 |
|
7867 | this._onTouchMove = function (evt) {
|
7868 | var touches = evt.touches;
|
7869 | if (touches.length !== 2) return;
|
7870 |
|
7871 | if (evt.cancelable !== false) {
|
7872 | evt.preventDefault();
|
7873 | }
|
7874 |
|
7875 | evt.stopPropagation();
|
7876 | var animation = _this._motion;
|
7877 | var prevTouchDistance = _this._prevTouchDistance;
|
7878 | var touchPoint1 = new Vector2(touches[0].pageX, touches[0].pageY);
|
7879 | var touchPoint2 = new Vector2(touches[1].pageX, touches[1].pageY);
|
7880 | var touchDiff = touchPoint1.sub(touchPoint2);
|
7881 |
|
7882 | var touchDistance = touchDiff.length() * _this._scale * _this._scaleModifier;
|
7883 |
|
7884 | var delta = -(touchDistance - prevTouchDistance);
|
7885 | _this._prevTouchDistance = touchDistance;
|
7886 | if (prevTouchDistance < 0) return;
|
7887 | animation.setEndDelta(delta);
|
7888 | };
|
7889 |
|
7890 | this._onTouchEnd = function () {
|
7891 | _this._prevTouchDistance = -1;
|
7892 | };
|
7893 |
|
7894 | var targetEl = getElement(element);
|
7895 |
|
7896 | if (targetEl) {
|
7897 | this.setElement(targetEl);
|
7898 | }
|
7899 |
|
7900 | this._motion = new Motion({
|
7901 | duration: duration,
|
7902 | range: range,
|
7903 | easing: easing
|
7904 | });
|
7905 | }
|
7906 |
|
7907 | var __proto = DistanceControl.prototype;
|
7908 | Object.defineProperty(__proto, "element", {
|
7909 | /**
|
7910 | * Control's current target element to attach event listeners
|
7911 | * @readonly
|
7912 | */
|
7913 | get: function () {
|
7914 | return this._targetEl;
|
7915 | },
|
7916 | enumerable: false,
|
7917 | configurable: true
|
7918 | });
|
7919 | Object.defineProperty(__proto, "scale", {
|
7920 | /**
|
7921 | * Scale factor of the distance
|
7922 | * @type number
|
7923 | * @example
|
7924 | * import { DistanceControl } from "@egjs/view3d";
|
7925 | * const distanceControl = new DistanceControl();
|
7926 | * distanceControl.scale = 2;
|
7927 | */
|
7928 | get: function () {
|
7929 | return this._scale;
|
7930 | },
|
7931 | set: function (val) {
|
7932 | this._scale = val;
|
7933 | },
|
7934 | enumerable: false,
|
7935 | configurable: true
|
7936 | });
|
7937 | Object.defineProperty(__proto, "enabled", {
|
7938 | /**
|
7939 | * Whether this control is enabled or not
|
7940 | * @readonly
|
7941 | */
|
7942 | get: function () {
|
7943 | return this._enabled;
|
7944 | },
|
7945 | enumerable: false,
|
7946 | configurable: true
|
7947 | });
|
7948 | /**
|
7949 | * Destroy the instance and remove all event listeners attached
|
7950 | * @returns {void} Nothing
|
7951 | */
|
7952 |
|
7953 | __proto.destroy = function () {
|
7954 | this.disable();
|
7955 | };
|
7956 | /**
|
7957 | * Update control by given deltaTime
|
7958 | * @param camera Camera to update position
|
7959 | * @param deltaTime Number of milisec to update
|
7960 | * @returns {void} Nothing
|
7961 | */
|
7962 |
|
7963 |
|
7964 | __proto.update = function (camera, deltaTime) {
|
7965 | var motion = this._motion;
|
7966 | camera.distance += motion.update(deltaTime);
|
7967 | }; // This is not documetned on purpose as it doesn't do nothing
|
7968 |
|
7969 |
|
7970 | __proto.resize = function (size) {// DO NOTHING
|
7971 | };
|
7972 | /**
|
7973 | * Enable this input and add event listeners
|
7974 | * @returns {void} Nothing
|
7975 | */
|
7976 |
|
7977 |
|
7978 | __proto.enable = function () {
|
7979 | if (this._enabled) return;
|
7980 |
|
7981 | if (!this._targetEl) {
|
7982 | throw new View3DError(MESSAGES.ADD_CONTROL_FIRST, CODES.ADD_CONTROL_FIRST);
|
7983 | }
|
7984 |
|
7985 | var targetEl = this._targetEl;
|
7986 | targetEl.addEventListener(EVENTS.WHEEL, this._onWheel, false);
|
7987 | targetEl.addEventListener(EVENTS.TOUCH_MOVE, this._onTouchMove, false);
|
7988 | targetEl.addEventListener(EVENTS.TOUCH_END, this._onTouchEnd, false);
|
7989 | this._enabled = true;
|
7990 | };
|
7991 | /**
|
7992 | * Disable this input and remove all event handlers
|
7993 | * @returns {void} Nothing
|
7994 | */
|
7995 |
|
7996 |
|
7997 | __proto.disable = function () {
|
7998 | if (!this._enabled || !this._targetEl) return;
|
7999 | var targetEl = this._targetEl;
|
8000 | targetEl.removeEventListener(EVENTS.WHEEL, this._onWheel, false);
|
8001 | targetEl.removeEventListener(EVENTS.TOUCH_MOVE, this._onTouchMove, false);
|
8002 | targetEl.removeEventListener(EVENTS.TOUCH_END, this._onTouchEnd, false);
|
8003 | this._enabled = false;
|
8004 | };
|
8005 | /**
|
8006 | * Synchronize this control's state to given camera position
|
8007 | * @param camera Camera to match state
|
8008 | * @returns {void} Nothing
|
8009 | */
|
8010 |
|
8011 |
|
8012 | __proto.sync = function (camera) {
|
8013 | this._motion.range.min = camera.minDistance;
|
8014 | this._motion.range.max = camera.maxDistance;
|
8015 |
|
8016 | this._motion.reset(camera.distance);
|
8017 | };
|
8018 | /**
|
8019 | * Set target element to attach event listener
|
8020 | * @param element target element
|
8021 | * @returns {void} Nothing
|
8022 | */
|
8023 |
|
8024 |
|
8025 | __proto.setElement = function (element) {
|
8026 | this._targetEl = element;
|
8027 | };
|
8028 |
|
8029 | return DistanceControl;
|
8030 | }();
|
8031 |
|
8032 | /*
|
8033 | * Copyright (c) 2020 NAVER Corp.
|
8034 | * egjs projects are licensed under the MIT license
|
8035 | */
|
8036 | /**
|
8037 | * Aggregation of {@link RotateControl}, {@link TranslateControl}, and {@link DistanceControl}.
|
8038 | * @category Controls
|
8039 | */
|
8040 |
|
8041 | var OrbitControl =
|
8042 | /*#__PURE__*/
|
8043 | function () {
|
8044 | /**
|
8045 | * Create new OrbitControl instance
|
8046 | * @param {object} options Options
|
8047 | * @param {HTMLElement | string | null} [options.element=null] Attaching element / selector of the element
|
8048 | * @param {object} [options.rotate={}] Constructor options of {@link RotateControl}
|
8049 | * @param {object} [options.translate={}] Constructor options of {@link TranslateControl}
|
8050 | * @param {object} [options.distance={}] Constructor options of {@link DistanceControl}
|
8051 | * @tutorial Adding Controls
|
8052 | */
|
8053 | function OrbitControl(_a) {
|
8054 | var _b = _a === void 0 ? {} : _a,
|
8055 | _c = _b.element,
|
8056 | element = _c === void 0 ? NULL_ELEMENT : _c,
|
8057 | _d = _b.rotate,
|
8058 | rotate = _d === void 0 ? {} : _d,
|
8059 | _e = _b.translate,
|
8060 | translate = _e === void 0 ? {} : _e,
|
8061 | _f = _b.distance,
|
8062 | distance = _f === void 0 ? {} : _f;
|
8063 |
|
8064 | this._enabled = false;
|
8065 | this._targetEl = getElement(element);
|
8066 | this._rotateControl = new RotateControl(__assign(__assign({}, rotate), {
|
8067 | element: rotate.element || this._targetEl
|
8068 | }));
|
8069 | this._translateControl = new TranslateControl(__assign(__assign({}, translate), {
|
8070 | element: translate.element || this._targetEl
|
8071 | }));
|
8072 | this._distanceControl = new DistanceControl(__assign(__assign({}, distance), {
|
8073 | element: distance.element || this._targetEl
|
8074 | }));
|
8075 | }
|
8076 |
|
8077 | var __proto = OrbitControl.prototype;
|
8078 | Object.defineProperty(__proto, "element", {
|
8079 | /**
|
8080 | * Control's current target element to attach event listeners
|
8081 | * @readonly
|
8082 | */
|
8083 | get: function () {
|
8084 | return this._targetEl;
|
8085 | },
|
8086 | enumerable: false,
|
8087 | configurable: true
|
8088 | });
|
8089 | Object.defineProperty(__proto, "enabled", {
|
8090 | /**
|
8091 | * Whether this control is enabled or not
|
8092 | * @readonly
|
8093 | */
|
8094 | get: function () {
|
8095 | return this._enabled;
|
8096 | },
|
8097 | enumerable: false,
|
8098 | configurable: true
|
8099 | });
|
8100 | Object.defineProperty(__proto, "rotate", {
|
8101 | /**
|
8102 | * {@link RotateControl} of this control
|
8103 | */
|
8104 | get: function () {
|
8105 | return this._rotateControl;
|
8106 | },
|
8107 | enumerable: false,
|
8108 | configurable: true
|
8109 | });
|
8110 | Object.defineProperty(__proto, "translate", {
|
8111 | /**
|
8112 | * {@link TranslateControl} of this control
|
8113 | */
|
8114 | get: function () {
|
8115 | return this._translateControl;
|
8116 | },
|
8117 | enumerable: false,
|
8118 | configurable: true
|
8119 | });
|
8120 | Object.defineProperty(__proto, "distance", {
|
8121 | /**
|
8122 | * {@link DistanceControl} of this control
|
8123 | */
|
8124 | get: function () {
|
8125 | return this._distanceControl;
|
8126 | },
|
8127 | enumerable: false,
|
8128 | configurable: true
|
8129 | });
|
8130 | /**
|
8131 | * Destroy the instance and remove all event listeners attached
|
8132 | * This also will reset CSS cursor to intial
|
8133 | * @returns {void} Nothing
|
8134 | */
|
8135 |
|
8136 | __proto.destroy = function () {
|
8137 | this._rotateControl.destroy();
|
8138 |
|
8139 | this._translateControl.destroy();
|
8140 |
|
8141 | this._distanceControl.destroy();
|
8142 | };
|
8143 | /**
|
8144 | * Update control by given deltaTime
|
8145 | * @param camera Camera to update position
|
8146 | * @param deltaTime Number of milisec to update
|
8147 | * @returns {void} Nothing
|
8148 | */
|
8149 |
|
8150 |
|
8151 | __proto.update = function (camera, deltaTime) {
|
8152 | this._rotateControl.update(camera, deltaTime);
|
8153 |
|
8154 | this._translateControl.update(camera, deltaTime);
|
8155 |
|
8156 | this._distanceControl.update(camera, deltaTime);
|
8157 | };
|
8158 | /**
|
8159 | * Resize control to match target size
|
8160 | * @param size {@link https://threejs.org/docs/#api/en/math/Vector2 THREE.Vector2} instance of width(x), height(y)
|
8161 | */
|
8162 |
|
8163 |
|
8164 | __proto.resize = function (size) {
|
8165 | this._rotateControl.resize(size);
|
8166 |
|
8167 | this._translateControl.resize(size);
|
8168 |
|
8169 | this._distanceControl.resize(size);
|
8170 | };
|
8171 | /**
|
8172 | * Enable this control and add event listeners
|
8173 | * @returns {void} Nothingß
|
8174 | */
|
8175 |
|
8176 |
|
8177 | __proto.enable = function () {
|
8178 | if (this._enabled) return;
|
8179 |
|
8180 | if (!this._targetEl) {
|
8181 | throw new View3DError(MESSAGES.ADD_CONTROL_FIRST, CODES.ADD_CONTROL_FIRST);
|
8182 | }
|
8183 |
|
8184 | this._rotateControl.enable();
|
8185 |
|
8186 | this._translateControl.enable();
|
8187 |
|
8188 | this._distanceControl.enable();
|
8189 |
|
8190 | this._enabled = true;
|
8191 | };
|
8192 | /**
|
8193 | * Disable this control and remove all event handlers
|
8194 | * @returns {void} Nothing
|
8195 | */
|
8196 |
|
8197 |
|
8198 | __proto.disable = function () {
|
8199 | if (!this._enabled || !this._targetEl) return;
|
8200 |
|
8201 | this._rotateControl.disable();
|
8202 |
|
8203 | this._translateControl.disable();
|
8204 |
|
8205 | this._distanceControl.disable();
|
8206 |
|
8207 | this._enabled = false;
|
8208 | };
|
8209 | /**
|
8210 | * Synchronize this control's state to given camera position
|
8211 | * @param camera Camera to match state
|
8212 | * @returns {void} Nothing
|
8213 | */
|
8214 |
|
8215 |
|
8216 | __proto.sync = function (camera) {
|
8217 | this._rotateControl.sync(camera);
|
8218 |
|
8219 | this._translateControl.sync(camera);
|
8220 |
|
8221 | this._distanceControl.sync(camera);
|
8222 | };
|
8223 | /**
|
8224 | * Set target element to attach event listener
|
8225 | * @param element target element
|
8226 | * @returns {void} Nothing
|
8227 | */
|
8228 |
|
8229 |
|
8230 | __proto.setElement = function (element) {
|
8231 | this._targetEl = element;
|
8232 |
|
8233 | this._rotateControl.setElement(element);
|
8234 |
|
8235 | this._translateControl.setElement(element);
|
8236 |
|
8237 | this._distanceControl.setElement(element);
|
8238 | };
|
8239 |
|
8240 | return OrbitControl;
|
8241 | }();
|
8242 |
|
8243 | /*
|
8244 | * Copyright (c) 2020 NAVER Corp.
|
8245 | * egjs projects are licensed under the MIT license
|
8246 | */
|
8247 |
|
8248 | var Controls = {
|
8249 | __proto__: null,
|
8250 | AnimationControl: AnimationControl,
|
8251 | AutoControl: AutoControl,
|
8252 | Motion: Motion,
|
8253 | OrbitControl: OrbitControl,
|
8254 | RotateControl: RotateControl,
|
8255 | TranslateControl: TranslateControl,
|
8256 | DistanceControl: DistanceControl
|
8257 | };
|
8258 |
|
8259 | var DRACOLoader = function DRACOLoader(manager) {
|
8260 | Loader.call(this, manager);
|
8261 | this.decoderPath = '';
|
8262 | this.decoderConfig = {};
|
8263 | this.decoderBinary = null;
|
8264 | this.decoderPending = null;
|
8265 | this.workerLimit = 4;
|
8266 | this.workerPool = [];
|
8267 | this.workerNextTaskID = 1;
|
8268 | this.workerSourceURL = '';
|
8269 | this.defaultAttributeIDs = {
|
8270 | position: 'POSITION',
|
8271 | normal: 'NORMAL',
|
8272 | color: 'COLOR',
|
8273 | uv: 'TEX_COORD'
|
8274 | };
|
8275 | this.defaultAttributeTypes = {
|
8276 | position: 'Float32Array',
|
8277 | normal: 'Float32Array',
|
8278 | color: 'Float32Array',
|
8279 | uv: 'Float32Array'
|
8280 | };
|
8281 | };
|
8282 |
|
8283 | DRACOLoader.prototype = _extends(Object.create(Loader.prototype), {
|
8284 | constructor: DRACOLoader,
|
8285 | setDecoderPath: function setDecoderPath(path) {
|
8286 | this.decoderPath = path;
|
8287 | return this;
|
8288 | },
|
8289 | setDecoderConfig: function setDecoderConfig(config) {
|
8290 | this.decoderConfig = config;
|
8291 | return this;
|
8292 | },
|
8293 | setWorkerLimit: function setWorkerLimit(workerLimit) {
|
8294 | this.workerLimit = workerLimit;
|
8295 | return this;
|
8296 | },
|
8297 |
|
8298 | /** @deprecated */
|
8299 | setVerbosity: function setVerbosity() {
|
8300 | console.warn('THREE.DRACOLoader: The .setVerbosity() method has been removed.');
|
8301 | },
|
8302 |
|
8303 | /** @deprecated */
|
8304 | setDrawMode: function setDrawMode() {
|
8305 | console.warn('THREE.DRACOLoader: The .setDrawMode() method has been removed.');
|
8306 | },
|
8307 |
|
8308 | /** @deprecated */
|
8309 | setSkipDequantization: function setSkipDequantization() {
|
8310 | console.warn('THREE.DRACOLoader: The .setSkipDequantization() method has been removed.');
|
8311 | },
|
8312 | load: function load(url, onLoad, onProgress, onError) {
|
8313 | var _this = this;
|
8314 |
|
8315 | var loader = new FileLoader(this.manager);
|
8316 | loader.setPath(this.path);
|
8317 | loader.setResponseType('arraybuffer');
|
8318 |
|
8319 | if (this.crossOrigin === 'use-credentials') {
|
8320 | loader.setWithCredentials(true);
|
8321 | }
|
8322 |
|
8323 | loader.load(url, function (buffer) {
|
8324 | var taskConfig = {
|
8325 | attributeIDs: _this.defaultAttributeIDs,
|
8326 | attributeTypes: _this.defaultAttributeTypes,
|
8327 | useUniqueIDs: false
|
8328 | };
|
8329 |
|
8330 | _this.decodeGeometry(buffer, taskConfig).then(onLoad)["catch"](onError);
|
8331 | }, onProgress, onError);
|
8332 | },
|
8333 |
|
8334 | /** @deprecated Kept for backward-compatibility with previous DRACOLoader versions. */
|
8335 | decodeDracoFile: function decodeDracoFile(buffer, callback, attributeIDs, attributeTypes) {
|
8336 | var taskConfig = {
|
8337 | attributeIDs: attributeIDs || this.defaultAttributeIDs,
|
8338 | attributeTypes: attributeTypes || this.defaultAttributeTypes,
|
8339 | useUniqueIDs: !!attributeIDs
|
8340 | };
|
8341 | this.decodeGeometry(buffer, taskConfig).then(callback);
|
8342 | },
|
8343 | decodeGeometry: function decodeGeometry(buffer, taskConfig) {
|
8344 | var _this2 = this;
|
8345 |
|
8346 | // TODO: For backward-compatibility, support 'attributeTypes' objects containing
|
8347 | // references (rather than names) to typed array constructors. These must be
|
8348 | // serialized before sending them to the worker.
|
8349 | for (var attribute in taskConfig.attributeTypes) {
|
8350 | var type = taskConfig.attributeTypes[attribute];
|
8351 |
|
8352 | if (type.BYTES_PER_ELEMENT !== undefined) {
|
8353 | taskConfig.attributeTypes[attribute] = type.name;
|
8354 | }
|
8355 | } //
|
8356 |
|
8357 |
|
8358 | var taskKey = JSON.stringify(taskConfig); // Check for an existing task using this buffer. A transferred buffer cannot be transferred
|
8359 | // again from this thread.
|
8360 |
|
8361 | if (DRACOLoader.taskCache.has(buffer)) {
|
8362 | var cachedTask = DRACOLoader.taskCache.get(buffer);
|
8363 |
|
8364 | if (cachedTask.key === taskKey) {
|
8365 | return cachedTask.promise;
|
8366 | } else if (buffer.byteLength === 0) {
|
8367 | // Technically, it would be possible to wait for the previous task to complete,
|
8368 | // transfer the buffer back, and decode again with the second configuration. That
|
8369 | // is complex, and I don't know of any reason to decode a Draco buffer twice in
|
8370 | // different ways, so this is left unimplemented.
|
8371 | throw new Error('THREE.DRACOLoader: Unable to re-decode a buffer with different ' + 'settings. Buffer has already been transferred.');
|
8372 | }
|
8373 | } //
|
8374 |
|
8375 |
|
8376 | var worker;
|
8377 | var taskID = this.workerNextTaskID++;
|
8378 | var taskCost = buffer.byteLength; // Obtain a worker and assign a task, and construct a geometry instance
|
8379 | // when the task completes.
|
8380 |
|
8381 | var geometryPending = this._getWorker(taskID, taskCost).then(function (_worker) {
|
8382 | worker = _worker;
|
8383 | return new Promise(function (resolve, reject) {
|
8384 | worker._callbacks[taskID] = {
|
8385 | resolve: resolve,
|
8386 | reject: reject
|
8387 | };
|
8388 | worker.postMessage({
|
8389 | type: 'decode',
|
8390 | id: taskID,
|
8391 | taskConfig: taskConfig,
|
8392 | buffer: buffer
|
8393 | }, [buffer]); // this.debug();
|
8394 | });
|
8395 | }).then(function (message) {
|
8396 | return _this2._createGeometry(message.geometry);
|
8397 | }); // Remove task from the task list.
|
8398 |
|
8399 |
|
8400 | geometryPending["finally"](function () {
|
8401 | if (worker && taskID) {
|
8402 | _this2._releaseTask(worker, taskID); // this.debug();
|
8403 |
|
8404 | }
|
8405 | }); // Cache the task result.
|
8406 |
|
8407 | DRACOLoader.taskCache.set(buffer, {
|
8408 | key: taskKey,
|
8409 | promise: geometryPending
|
8410 | });
|
8411 | return geometryPending;
|
8412 | },
|
8413 | _createGeometry: function _createGeometry(geometryData) {
|
8414 | var geometry = new BufferGeometry();
|
8415 |
|
8416 | if (geometryData.index) {
|
8417 | geometry.setIndex(new BufferAttribute(geometryData.index.array, 1));
|
8418 | }
|
8419 |
|
8420 | for (var i = 0; i < geometryData.attributes.length; i++) {
|
8421 | var attribute = geometryData.attributes[i];
|
8422 | var name = attribute.name;
|
8423 | var array = attribute.array;
|
8424 | var itemSize = attribute.itemSize;
|
8425 | geometry.setAttribute(name, new BufferAttribute(array, itemSize));
|
8426 | }
|
8427 |
|
8428 | return geometry;
|
8429 | },
|
8430 | _loadLibrary: function _loadLibrary(url, responseType) {
|
8431 | var loader = new FileLoader(this.manager);
|
8432 | loader.setPath(this.decoderPath);
|
8433 | loader.setResponseType(responseType);
|
8434 | return new Promise(function (resolve, reject) {
|
8435 | loader.load(url, resolve, undefined, reject);
|
8436 | });
|
8437 | },
|
8438 | preload: function preload() {
|
8439 | this._initDecoder();
|
8440 |
|
8441 | return this;
|
8442 | },
|
8443 | _initDecoder: function _initDecoder() {
|
8444 | var _this3 = this;
|
8445 |
|
8446 | if (this.decoderPending) return this.decoderPending;
|
8447 | var useJS = typeof WebAssembly !== 'object' || this.decoderConfig.type === 'js';
|
8448 | var librariesPending = [];
|
8449 |
|
8450 | if (useJS) {
|
8451 | librariesPending.push(this._loadLibrary('draco_decoder.js', 'text'));
|
8452 | } else {
|
8453 | librariesPending.push(this._loadLibrary('draco_wasm_wrapper.js', 'text'));
|
8454 | librariesPending.push(this._loadLibrary('draco_decoder.wasm', 'arraybuffer'));
|
8455 | }
|
8456 |
|
8457 | this.decoderPending = Promise.all(librariesPending).then(function (libraries) {
|
8458 | var jsContent = libraries[0];
|
8459 |
|
8460 | if (!useJS) {
|
8461 | _this3.decoderConfig.wasmBinary = libraries[1];
|
8462 | }
|
8463 |
|
8464 | var fn = DRACOLoader.DRACOWorker.toString();
|
8465 | var body = ['/* draco decoder */', jsContent, '', '/* worker */', fn.substring(fn.indexOf('{') + 1, fn.lastIndexOf('}'))].join('\n');
|
8466 | _this3.workerSourceURL = URL.createObjectURL(new Blob([body]));
|
8467 | });
|
8468 | return this.decoderPending;
|
8469 | },
|
8470 | _getWorker: function _getWorker(taskID, taskCost) {
|
8471 | var _this4 = this;
|
8472 |
|
8473 | return this._initDecoder().then(function () {
|
8474 | if (_this4.workerPool.length < _this4.workerLimit) {
|
8475 | var worker = new Worker(_this4.workerSourceURL);
|
8476 | worker._callbacks = {};
|
8477 | worker._taskCosts = {};
|
8478 | worker._taskLoad = 0;
|
8479 | worker.postMessage({
|
8480 | type: 'init',
|
8481 | decoderConfig: _this4.decoderConfig
|
8482 | });
|
8483 |
|
8484 | worker.onmessage = function (e) {
|
8485 | var message = e.data;
|
8486 |
|
8487 | switch (message.type) {
|
8488 | case 'decode':
|
8489 | worker._callbacks[message.id].resolve(message);
|
8490 |
|
8491 | break;
|
8492 |
|
8493 | case 'error':
|
8494 | worker._callbacks[message.id].reject(message);
|
8495 |
|
8496 | break;
|
8497 |
|
8498 | default:
|
8499 | console.error('THREE.DRACOLoader: Unexpected message, "' + message.type + '"');
|
8500 | }
|
8501 | };
|
8502 |
|
8503 | _this4.workerPool.push(worker);
|
8504 | } else {
|
8505 | _this4.workerPool.sort(function (a, b) {
|
8506 | return a._taskLoad > b._taskLoad ? -1 : 1;
|
8507 | });
|
8508 | }
|
8509 |
|
8510 | var worker = _this4.workerPool[_this4.workerPool.length - 1];
|
8511 | worker._taskCosts[taskID] = taskCost;
|
8512 | worker._taskLoad += taskCost;
|
8513 | return worker;
|
8514 | });
|
8515 | },
|
8516 | _releaseTask: function _releaseTask(worker, taskID) {
|
8517 | worker._taskLoad -= worker._taskCosts[taskID];
|
8518 | delete worker._callbacks[taskID];
|
8519 | delete worker._taskCosts[taskID];
|
8520 | },
|
8521 | debug: function debug() {
|
8522 | console.log('Task load: ', this.workerPool.map(function (worker) {
|
8523 | return worker._taskLoad;
|
8524 | }));
|
8525 | },
|
8526 | dispose: function dispose() {
|
8527 | for (var i = 0; i < this.workerPool.length; ++i) {
|
8528 | this.workerPool[i].terminate();
|
8529 | }
|
8530 |
|
8531 | this.workerPool.length = 0;
|
8532 | return this;
|
8533 | }
|
8534 | });
|
8535 | /* WEB WORKER */
|
8536 |
|
8537 | DRACOLoader.DRACOWorker = function () {
|
8538 | var decoderConfig;
|
8539 | var decoderPending;
|
8540 |
|
8541 | onmessage = function onmessage(e) {
|
8542 | var message = e.data;
|
8543 |
|
8544 | switch (message.type) {
|
8545 | case 'init':
|
8546 | decoderConfig = message.decoderConfig;
|
8547 | decoderPending = new Promise(function (resolve
|
8548 | /*, reject*/
|
8549 | ) {
|
8550 | decoderConfig.onModuleLoaded = function (draco) {
|
8551 | // Module is Promise-like. Wrap before resolving to avoid loop.
|
8552 | resolve({
|
8553 | draco: draco
|
8554 | });
|
8555 | };
|
8556 |
|
8557 | DracoDecoderModule(decoderConfig);
|
8558 | });
|
8559 | break;
|
8560 |
|
8561 | case 'decode':
|
8562 | var buffer = message.buffer;
|
8563 | var taskConfig = message.taskConfig;
|
8564 | decoderPending.then(function (module) {
|
8565 | var draco = module.draco;
|
8566 | var decoder = new draco.Decoder();
|
8567 | var decoderBuffer = new draco.DecoderBuffer();
|
8568 | decoderBuffer.Init(new Int8Array(buffer), buffer.byteLength);
|
8569 |
|
8570 | try {
|
8571 | var geometry = decodeGeometry(draco, decoder, decoderBuffer, taskConfig);
|
8572 | var buffers = geometry.attributes.map(function (attr) {
|
8573 | return attr.array.buffer;
|
8574 | });
|
8575 | if (geometry.index) buffers.push(geometry.index.array.buffer);
|
8576 | self.postMessage({
|
8577 | type: 'decode',
|
8578 | id: message.id,
|
8579 | geometry: geometry
|
8580 | }, buffers);
|
8581 | } catch (error) {
|
8582 | console.error(error);
|
8583 | self.postMessage({
|
8584 | type: 'error',
|
8585 | id: message.id,
|
8586 | error: error.message
|
8587 | });
|
8588 | } finally {
|
8589 | draco.destroy(decoderBuffer);
|
8590 | draco.destroy(decoder);
|
8591 | }
|
8592 | });
|
8593 | break;
|
8594 | }
|
8595 | };
|
8596 |
|
8597 | function decodeGeometry(draco, decoder, decoderBuffer, taskConfig) {
|
8598 | var attributeIDs = taskConfig.attributeIDs;
|
8599 | var attributeTypes = taskConfig.attributeTypes;
|
8600 | var dracoGeometry;
|
8601 | var decodingStatus;
|
8602 | var geometryType = decoder.GetEncodedGeometryType(decoderBuffer);
|
8603 |
|
8604 | if (geometryType === draco.TRIANGULAR_MESH) {
|
8605 | dracoGeometry = new draco.Mesh();
|
8606 | decodingStatus = decoder.DecodeBufferToMesh(decoderBuffer, dracoGeometry);
|
8607 | } else if (geometryType === draco.POINT_CLOUD) {
|
8608 | dracoGeometry = new draco.PointCloud();
|
8609 | decodingStatus = decoder.DecodeBufferToPointCloud(decoderBuffer, dracoGeometry);
|
8610 | } else {
|
8611 | throw new Error('THREE.DRACOLoader: Unexpected geometry type.');
|
8612 | }
|
8613 |
|
8614 | if (!decodingStatus.ok() || dracoGeometry.ptr === 0) {
|
8615 | throw new Error('THREE.DRACOLoader: Decoding failed: ' + decodingStatus.error_msg());
|
8616 | }
|
8617 |
|
8618 | var geometry = {
|
8619 | index: null,
|
8620 | attributes: []
|
8621 | }; // Gather all vertex attributes.
|
8622 |
|
8623 | for (var attributeName in attributeIDs) {
|
8624 | var attributeType = self[attributeTypes[attributeName]];
|
8625 | var attribute;
|
8626 | var attributeID; // A Draco file may be created with default vertex attributes, whose attribute IDs
|
8627 | // are mapped 1:1 from their semantic name (POSITION, NORMAL, ...). Alternatively,
|
8628 | // a Draco file may contain a custom set of attributes, identified by known unique
|
8629 | // IDs. glTF files always do the latter, and `.drc` files typically do the former.
|
8630 |
|
8631 | if (taskConfig.useUniqueIDs) {
|
8632 | attributeID = attributeIDs[attributeName];
|
8633 | attribute = decoder.GetAttributeByUniqueId(dracoGeometry, attributeID);
|
8634 | } else {
|
8635 | attributeID = decoder.GetAttributeId(dracoGeometry, draco[attributeIDs[attributeName]]);
|
8636 | if (attributeID === -1) continue;
|
8637 | attribute = decoder.GetAttribute(dracoGeometry, attributeID);
|
8638 | }
|
8639 |
|
8640 | geometry.attributes.push(decodeAttribute(draco, decoder, dracoGeometry, attributeName, attributeType, attribute));
|
8641 | } // Add index.
|
8642 |
|
8643 |
|
8644 | if (geometryType === draco.TRIANGULAR_MESH) {
|
8645 | // Generate mesh faces.
|
8646 | var numFaces = dracoGeometry.num_faces();
|
8647 | var numIndices = numFaces * 3;
|
8648 | var index = new Uint32Array(numIndices);
|
8649 | var indexArray = new draco.DracoInt32Array();
|
8650 |
|
8651 | for (var i = 0; i < numFaces; ++i) {
|
8652 | decoder.GetFaceFromMesh(dracoGeometry, i, indexArray);
|
8653 |
|
8654 | for (var j = 0; j < 3; ++j) {
|
8655 | index[i * 3 + j] = indexArray.GetValue(j);
|
8656 | }
|
8657 | }
|
8658 |
|
8659 | geometry.index = {
|
8660 | array: index,
|
8661 | itemSize: 1
|
8662 | };
|
8663 | draco.destroy(indexArray);
|
8664 | }
|
8665 |
|
8666 | draco.destroy(dracoGeometry);
|
8667 | return geometry;
|
8668 | }
|
8669 |
|
8670 | function decodeAttribute(draco, decoder, dracoGeometry, attributeName, attributeType, attribute) {
|
8671 | var numComponents = attribute.num_components();
|
8672 | var numPoints = dracoGeometry.num_points();
|
8673 | var numValues = numPoints * numComponents;
|
8674 | var dracoArray;
|
8675 | var array;
|
8676 |
|
8677 | switch (attributeType) {
|
8678 | case Float32Array:
|
8679 | dracoArray = new draco.DracoFloat32Array();
|
8680 | decoder.GetAttributeFloatForAllPoints(dracoGeometry, attribute, dracoArray);
|
8681 | array = new Float32Array(numValues);
|
8682 | break;
|
8683 |
|
8684 | case Int8Array:
|
8685 | dracoArray = new draco.DracoInt8Array();
|
8686 | decoder.GetAttributeInt8ForAllPoints(dracoGeometry, attribute, dracoArray);
|
8687 | array = new Int8Array(numValues);
|
8688 | break;
|
8689 |
|
8690 | case Int16Array:
|
8691 | dracoArray = new draco.DracoInt16Array();
|
8692 | decoder.GetAttributeInt16ForAllPoints(dracoGeometry, attribute, dracoArray);
|
8693 | array = new Int16Array(numValues);
|
8694 | break;
|
8695 |
|
8696 | case Int32Array:
|
8697 | dracoArray = new draco.DracoInt32Array();
|
8698 | decoder.GetAttributeInt32ForAllPoints(dracoGeometry, attribute, dracoArray);
|
8699 | array = new Int32Array(numValues);
|
8700 | break;
|
8701 |
|
8702 | case Uint8Array:
|
8703 | dracoArray = new draco.DracoUInt8Array();
|
8704 | decoder.GetAttributeUInt8ForAllPoints(dracoGeometry, attribute, dracoArray);
|
8705 | array = new Uint8Array(numValues);
|
8706 | break;
|
8707 |
|
8708 | case Uint16Array:
|
8709 | dracoArray = new draco.DracoUInt16Array();
|
8710 | decoder.GetAttributeUInt16ForAllPoints(dracoGeometry, attribute, dracoArray);
|
8711 | array = new Uint16Array(numValues);
|
8712 | break;
|
8713 |
|
8714 | case Uint32Array:
|
8715 | dracoArray = new draco.DracoUInt32Array();
|
8716 | decoder.GetAttributeUInt32ForAllPoints(dracoGeometry, attribute, dracoArray);
|
8717 | array = new Uint32Array(numValues);
|
8718 | break;
|
8719 |
|
8720 | default:
|
8721 | throw new Error('THREE.DRACOLoader: Unexpected attribute type.');
|
8722 | }
|
8723 |
|
8724 | for (var i = 0; i < numValues; i++) {
|
8725 | array[i] = dracoArray.GetValue(i);
|
8726 | }
|
8727 |
|
8728 | draco.destroy(dracoArray);
|
8729 | return {
|
8730 | name: attributeName,
|
8731 | array: array,
|
8732 | itemSize: numComponents
|
8733 | };
|
8734 | }
|
8735 | };
|
8736 |
|
8737 | DRACOLoader.taskCache = new WeakMap();
|
8738 | /** Deprecated static methods */
|
8739 |
|
8740 | /** @deprecated */
|
8741 |
|
8742 | DRACOLoader.setDecoderPath = function () {
|
8743 | console.warn('THREE.DRACOLoader: The .setDecoderPath() method has been removed. Use instance methods.');
|
8744 | };
|
8745 | /** @deprecated */
|
8746 |
|
8747 |
|
8748 | DRACOLoader.setDecoderConfig = function () {
|
8749 | console.warn('THREE.DRACOLoader: The .setDecoderConfig() method has been removed. Use instance methods.');
|
8750 | };
|
8751 | /** @deprecated */
|
8752 |
|
8753 |
|
8754 | DRACOLoader.releaseDecoderModule = function () {
|
8755 | console.warn('THREE.DRACOLoader: The .releaseDecoderModule() method has been removed. Use instance methods.');
|
8756 | };
|
8757 | /** @deprecated */
|
8758 |
|
8759 |
|
8760 | DRACOLoader.getDecoderModule = function () {
|
8761 | console.warn('THREE.DRACOLoader: The .getDecoderModule() method has been removed. Use instance methods.');
|
8762 | };
|
8763 |
|
8764 | /**
|
8765 | * DracoLoader
|
8766 | * @category Loaders
|
8767 | */
|
8768 |
|
8769 | var DracoLoader =
|
8770 | /*#__PURE__*/
|
8771 | function () {
|
8772 | function DracoLoader() {}
|
8773 | /**
|
8774 | * Load new DRC model from the given url
|
8775 | * @param url URL to fetch .drc file
|
8776 | * @param options Options for a loaded model
|
8777 | * @returns Promise that resolves {@link Model}
|
8778 | */
|
8779 |
|
8780 |
|
8781 | var __proto = DracoLoader.prototype;
|
8782 |
|
8783 | __proto.load = function (url, options) {
|
8784 | var _this = this;
|
8785 |
|
8786 | if (options === void 0) {
|
8787 | options = {};
|
8788 | }
|
8789 |
|
8790 | var loader = new DRACOLoader();
|
8791 | loader.setCrossOrigin("anonymous");
|
8792 | loader.setDecoderPath(DRACO_DECODER_URL);
|
8793 | loader.manager = new LoadingManager();
|
8794 | return new Promise(function (resolve, reject) {
|
8795 | loader.load(url, function (geometry) {
|
8796 | var model = _this._parseToModel(geometry, options);
|
8797 |
|
8798 | loader.dispose();
|
8799 | resolve(model);
|
8800 | }, undefined, function (err) {
|
8801 | loader.dispose();
|
8802 | reject(err);
|
8803 | });
|
8804 | });
|
8805 | };
|
8806 |
|
8807 | __proto._parseToModel = function (geometry, _a) {
|
8808 | var _b = _a === void 0 ? {} : _a,
|
8809 | _c = _b.fixSkinnedBbox,
|
8810 | fixSkinnedBbox = _c === void 0 ? false : _c,
|
8811 | _d = _b.color,
|
8812 | color = _d === void 0 ? 0xffffff : _d,
|
8813 | _e = _b.point,
|
8814 | point = _e === void 0 ? false : _e,
|
8815 | _f = _b.pointOptions,
|
8816 | pointOptions = _f === void 0 ? {} : _f;
|
8817 |
|
8818 | geometry.computeVertexNormals();
|
8819 | var material = point ? new PointsMaterial(__assign({
|
8820 | color: color
|
8821 | }, pointOptions)) : new MeshStandardMaterial({
|
8822 | color: color
|
8823 | });
|
8824 | var mesh = point ? new Points(geometry, material) : new Mesh(geometry, material);
|
8825 | var model = new Model({
|
8826 | scenes: [mesh],
|
8827 | fixSkinnedBbox: fixSkinnedBbox
|
8828 | });
|
8829 | return model;
|
8830 | };
|
8831 |
|
8832 | return DracoLoader;
|
8833 | }();
|
8834 |
|
8835 | var GLTFLoader = function () {
|
8836 | function GLTFLoader(manager) {
|
8837 | Loader.call(this, manager);
|
8838 | this.dracoLoader = null;
|
8839 | this.ddsLoader = null;
|
8840 | }
|
8841 |
|
8842 | GLTFLoader.prototype = _extends(Object.create(Loader.prototype), {
|
8843 | constructor: GLTFLoader,
|
8844 | load: function load(url, onLoad, onProgress, onError) {
|
8845 | var scope = this;
|
8846 | var resourcePath;
|
8847 |
|
8848 | if (this.resourcePath !== '') {
|
8849 | resourcePath = this.resourcePath;
|
8850 | } else if (this.path !== '') {
|
8851 | resourcePath = this.path;
|
8852 | } else {
|
8853 | resourcePath = LoaderUtils.extractUrlBase(url);
|
8854 | } // Tells the LoadingManager to track an extra item, which resolves after
|
8855 | // the model is fully loaded. This means the count of items loaded will
|
8856 | // be incorrect, but ensures manager.onLoad() does not fire early.
|
8857 |
|
8858 |
|
8859 | scope.manager.itemStart(url);
|
8860 |
|
8861 | var _onError = function _onError(e) {
|
8862 | if (onError) {
|
8863 | onError(e);
|
8864 | } else {
|
8865 | console.error(e);
|
8866 | }
|
8867 |
|
8868 | scope.manager.itemError(url);
|
8869 | scope.manager.itemEnd(url);
|
8870 | };
|
8871 |
|
8872 | var loader = new FileLoader(scope.manager);
|
8873 | loader.setPath(this.path);
|
8874 | loader.setResponseType('arraybuffer');
|
8875 |
|
8876 | if (scope.crossOrigin === 'use-credentials') {
|
8877 | loader.setWithCredentials(true);
|
8878 | }
|
8879 |
|
8880 | loader.load(url, function (data) {
|
8881 | try {
|
8882 | scope.parse(data, resourcePath, function (gltf) {
|
8883 | onLoad(gltf);
|
8884 | scope.manager.itemEnd(url);
|
8885 | }, _onError);
|
8886 | } catch (e) {
|
8887 | _onError(e);
|
8888 | }
|
8889 | }, onProgress, _onError);
|
8890 | },
|
8891 | setDRACOLoader: function setDRACOLoader(dracoLoader) {
|
8892 | this.dracoLoader = dracoLoader;
|
8893 | return this;
|
8894 | },
|
8895 | setDDSLoader: function setDDSLoader(ddsLoader) {
|
8896 | this.ddsLoader = ddsLoader;
|
8897 | return this;
|
8898 | },
|
8899 | parse: function parse(data, path, onLoad, onError) {
|
8900 | var content;
|
8901 | var extensions = {};
|
8902 |
|
8903 | if (typeof data === 'string') {
|
8904 | content = data;
|
8905 | } else {
|
8906 | var magic = LoaderUtils.decodeText(new Uint8Array(data, 0, 4));
|
8907 |
|
8908 | if (magic === BINARY_EXTENSION_HEADER_MAGIC) {
|
8909 | try {
|
8910 | extensions[EXTENSIONS.KHR_BINARY_GLTF] = new GLTFBinaryExtension(data);
|
8911 | } catch (error) {
|
8912 | if (onError) onError(error);
|
8913 | return;
|
8914 | }
|
8915 |
|
8916 | content = extensions[EXTENSIONS.KHR_BINARY_GLTF].content;
|
8917 | } else {
|
8918 | content = LoaderUtils.decodeText(new Uint8Array(data));
|
8919 | }
|
8920 | }
|
8921 |
|
8922 | var json = JSON.parse(content);
|
8923 |
|
8924 | if (json.asset === undefined || json.asset.version[0] < 2) {
|
8925 | if (onError) onError(new Error('THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported.'));
|
8926 | return;
|
8927 | }
|
8928 |
|
8929 | if (json.extensionsUsed) {
|
8930 | for (var i = 0; i < json.extensionsUsed.length; ++i) {
|
8931 | var extensionName = json.extensionsUsed[i];
|
8932 | var extensionsRequired = json.extensionsRequired || [];
|
8933 |
|
8934 | switch (extensionName) {
|
8935 | case EXTENSIONS.KHR_LIGHTS_PUNCTUAL:
|
8936 | extensions[extensionName] = new GLTFLightsExtension(json);
|
8937 | break;
|
8938 |
|
8939 | case EXTENSIONS.KHR_MATERIALS_CLEARCOAT:
|
8940 | extensions[extensionName] = new GLTFMaterialsClearcoatExtension();
|
8941 | break;
|
8942 |
|
8943 | case EXTENSIONS.KHR_MATERIALS_UNLIT:
|
8944 | extensions[extensionName] = new GLTFMaterialsUnlitExtension();
|
8945 | break;
|
8946 |
|
8947 | case EXTENSIONS.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS:
|
8948 | extensions[extensionName] = new GLTFMaterialsPbrSpecularGlossinessExtension();
|
8949 | break;
|
8950 |
|
8951 | case EXTENSIONS.KHR_DRACO_MESH_COMPRESSION:
|
8952 | extensions[extensionName] = new GLTFDracoMeshCompressionExtension(json, this.dracoLoader);
|
8953 | break;
|
8954 |
|
8955 | case EXTENSIONS.MSFT_TEXTURE_DDS:
|
8956 | extensions[extensionName] = new GLTFTextureDDSExtension(this.ddsLoader);
|
8957 | break;
|
8958 |
|
8959 | case EXTENSIONS.KHR_TEXTURE_TRANSFORM:
|
8960 | extensions[extensionName] = new GLTFTextureTransformExtension();
|
8961 | break;
|
8962 |
|
8963 | case EXTENSIONS.KHR_MESH_QUANTIZATION:
|
8964 | extensions[extensionName] = new GLTFMeshQuantizationExtension();
|
8965 | break;
|
8966 |
|
8967 | default:
|
8968 | if (extensionsRequired.indexOf(extensionName) >= 0) {
|
8969 | console.warn('THREE.GLTFLoader: Unknown extension "' + extensionName + '".');
|
8970 | }
|
8971 |
|
8972 | }
|
8973 | }
|
8974 | }
|
8975 |
|
8976 | var parser = new GLTFParser(json, extensions, {
|
8977 | path: path || this.resourcePath || '',
|
8978 | crossOrigin: this.crossOrigin,
|
8979 | manager: this.manager
|
8980 | });
|
8981 | parser.parse(onLoad, onError);
|
8982 | }
|
8983 | });
|
8984 | /* GLTFREGISTRY */
|
8985 |
|
8986 | function GLTFRegistry() {
|
8987 | var objects = {};
|
8988 | return {
|
8989 | get: function get(key) {
|
8990 | return objects[key];
|
8991 | },
|
8992 | add: function add(key, object) {
|
8993 | objects[key] = object;
|
8994 | },
|
8995 | remove: function remove(key) {
|
8996 | delete objects[key];
|
8997 | },
|
8998 | removeAll: function removeAll() {
|
8999 | objects = {};
|
9000 | }
|
9001 | };
|
9002 | }
|
9003 | /*********************************/
|
9004 |
|
9005 | /********** EXTENSIONS ***********/
|
9006 |
|
9007 | /*********************************/
|
9008 |
|
9009 |
|
9010 | var EXTENSIONS = {
|
9011 | KHR_BINARY_GLTF: 'KHR_binary_glTF',
|
9012 | KHR_DRACO_MESH_COMPRESSION: 'KHR_draco_mesh_compression',
|
9013 | KHR_LIGHTS_PUNCTUAL: 'KHR_lights_punctual',
|
9014 | KHR_MATERIALS_CLEARCOAT: 'KHR_materials_clearcoat',
|
9015 | KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS: 'KHR_materials_pbrSpecularGlossiness',
|
9016 | KHR_MATERIALS_UNLIT: 'KHR_materials_unlit',
|
9017 | KHR_TEXTURE_TRANSFORM: 'KHR_texture_transform',
|
9018 | KHR_MESH_QUANTIZATION: 'KHR_mesh_quantization',
|
9019 | MSFT_TEXTURE_DDS: 'MSFT_texture_dds'
|
9020 | };
|
9021 | /**
|
9022 | * DDS Texture Extension
|
9023 | *
|
9024 | * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/MSFT_texture_dds
|
9025 | *
|
9026 | */
|
9027 |
|
9028 | function GLTFTextureDDSExtension(ddsLoader) {
|
9029 | if (!ddsLoader) {
|
9030 | throw new Error('THREE.GLTFLoader: Attempting to load .dds texture without importing DDSLoader');
|
9031 | }
|
9032 |
|
9033 | this.name = EXTENSIONS.MSFT_TEXTURE_DDS;
|
9034 | this.ddsLoader = ddsLoader;
|
9035 | }
|
9036 | /**
|
9037 | * Punctual Lights Extension
|
9038 | *
|
9039 | * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_lights_punctual
|
9040 | */
|
9041 |
|
9042 |
|
9043 | function GLTFLightsExtension(json) {
|
9044 | this.name = EXTENSIONS.KHR_LIGHTS_PUNCTUAL;
|
9045 | var extension = json.extensions && json.extensions[EXTENSIONS.KHR_LIGHTS_PUNCTUAL] || {};
|
9046 | this.lightDefs = extension.lights || [];
|
9047 | }
|
9048 |
|
9049 | GLTFLightsExtension.prototype.loadLight = function (lightIndex) {
|
9050 | var lightDef = this.lightDefs[lightIndex];
|
9051 | var lightNode;
|
9052 | var color = new Color(0xffffff);
|
9053 | if (lightDef.color !== undefined) color.fromArray(lightDef.color);
|
9054 | var range = lightDef.range !== undefined ? lightDef.range : 0;
|
9055 |
|
9056 | switch (lightDef.type) {
|
9057 | case 'directional':
|
9058 | lightNode = new DirectionalLight(color);
|
9059 | lightNode.target.position.set(0, 0, -1);
|
9060 | lightNode.add(lightNode.target);
|
9061 | break;
|
9062 |
|
9063 | case 'point':
|
9064 | lightNode = new PointLight(color);
|
9065 | lightNode.distance = range;
|
9066 | break;
|
9067 |
|
9068 | case 'spot':
|
9069 | lightNode = new SpotLight(color);
|
9070 | lightNode.distance = range; // Handle spotlight properties.
|
9071 |
|
9072 | lightDef.spot = lightDef.spot || {};
|
9073 | lightDef.spot.innerConeAngle = lightDef.spot.innerConeAngle !== undefined ? lightDef.spot.innerConeAngle : 0;
|
9074 | lightDef.spot.outerConeAngle = lightDef.spot.outerConeAngle !== undefined ? lightDef.spot.outerConeAngle : Math.PI / 4.0;
|
9075 | lightNode.angle = lightDef.spot.outerConeAngle;
|
9076 | lightNode.penumbra = 1.0 - lightDef.spot.innerConeAngle / lightDef.spot.outerConeAngle;
|
9077 | lightNode.target.position.set(0, 0, -1);
|
9078 | lightNode.add(lightNode.target);
|
9079 | break;
|
9080 |
|
9081 | default:
|
9082 | throw new Error('THREE.GLTFLoader: Unexpected light type, "' + lightDef.type + '".');
|
9083 | } // Some lights (e.g. spot) default to a position other than the origin. Reset the position
|
9084 | // here, because node-level parsing will only override position if explicitly specified.
|
9085 |
|
9086 |
|
9087 | lightNode.position.set(0, 0, 0);
|
9088 | lightNode.decay = 2;
|
9089 | if (lightDef.intensity !== undefined) lightNode.intensity = lightDef.intensity;
|
9090 | lightNode.name = lightDef.name || 'light_' + lightIndex;
|
9091 | return Promise.resolve(lightNode);
|
9092 | };
|
9093 | /**
|
9094 | * Unlit Materials Extension
|
9095 | *
|
9096 | * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit
|
9097 | */
|
9098 |
|
9099 |
|
9100 | function GLTFMaterialsUnlitExtension() {
|
9101 | this.name = EXTENSIONS.KHR_MATERIALS_UNLIT;
|
9102 | }
|
9103 |
|
9104 | GLTFMaterialsUnlitExtension.prototype.getMaterialType = function () {
|
9105 | return MeshBasicMaterial;
|
9106 | };
|
9107 |
|
9108 | GLTFMaterialsUnlitExtension.prototype.extendParams = function (materialParams, materialDef, parser) {
|
9109 | var pending = [];
|
9110 | materialParams.color = new Color(1.0, 1.0, 1.0);
|
9111 | materialParams.opacity = 1.0;
|
9112 | var metallicRoughness = materialDef.pbrMetallicRoughness;
|
9113 |
|
9114 | if (metallicRoughness) {
|
9115 | if (Array.isArray(metallicRoughness.baseColorFactor)) {
|
9116 | var array = metallicRoughness.baseColorFactor;
|
9117 | materialParams.color.fromArray(array);
|
9118 | materialParams.opacity = array[3];
|
9119 | }
|
9120 |
|
9121 | if (metallicRoughness.baseColorTexture !== undefined) {
|
9122 | pending.push(parser.assignTexture(materialParams, 'map', metallicRoughness.baseColorTexture));
|
9123 | }
|
9124 | }
|
9125 |
|
9126 | return Promise.all(pending);
|
9127 | };
|
9128 | /**
|
9129 | * Clearcoat Materials Extension
|
9130 | *
|
9131 | * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_clearcoat
|
9132 | */
|
9133 |
|
9134 |
|
9135 | function GLTFMaterialsClearcoatExtension() {
|
9136 | this.name = EXTENSIONS.KHR_MATERIALS_CLEARCOAT;
|
9137 | }
|
9138 |
|
9139 | GLTFMaterialsClearcoatExtension.prototype.getMaterialType = function () {
|
9140 | return MeshPhysicalMaterial;
|
9141 | };
|
9142 |
|
9143 | GLTFMaterialsClearcoatExtension.prototype.extendParams = function (materialParams, materialDef, parser) {
|
9144 | var pending = [];
|
9145 | var extension = materialDef.extensions[this.name];
|
9146 |
|
9147 | if (extension.clearcoatFactor !== undefined) {
|
9148 | materialParams.clearcoat = extension.clearcoatFactor;
|
9149 | }
|
9150 |
|
9151 | if (extension.clearcoatTexture !== undefined) {
|
9152 | pending.push(parser.assignTexture(materialParams, 'clearcoatMap', extension.clearcoatTexture));
|
9153 | }
|
9154 |
|
9155 | if (extension.clearcoatRoughnessFactor !== undefined) {
|
9156 | materialParams.clearcoatRoughness = extension.clearcoatRoughnessFactor;
|
9157 | }
|
9158 |
|
9159 | if (extension.clearcoatRoughnessTexture !== undefined) {
|
9160 | pending.push(parser.assignTexture(materialParams, 'clearcoatRoughnessMap', extension.clearcoatRoughnessTexture));
|
9161 | }
|
9162 |
|
9163 | if (extension.clearcoatNormalTexture !== undefined) {
|
9164 | pending.push(parser.assignTexture(materialParams, 'clearcoatNormalMap', extension.clearcoatNormalTexture));
|
9165 |
|
9166 | if (extension.clearcoatNormalTexture.scale !== undefined) {
|
9167 | var scale = extension.clearcoatNormalTexture.scale;
|
9168 | materialParams.clearcoatNormalScale = new Vector2(scale, scale);
|
9169 | }
|
9170 | }
|
9171 |
|
9172 | return Promise.all(pending);
|
9173 | };
|
9174 | /* BINARY EXTENSION */
|
9175 |
|
9176 |
|
9177 | var BINARY_EXTENSION_HEADER_MAGIC = 'glTF';
|
9178 | var BINARY_EXTENSION_HEADER_LENGTH = 12;
|
9179 | var BINARY_EXTENSION_CHUNK_TYPES = {
|
9180 | JSON: 0x4E4F534A,
|
9181 | BIN: 0x004E4942
|
9182 | };
|
9183 |
|
9184 | function GLTFBinaryExtension(data) {
|
9185 | this.name = EXTENSIONS.KHR_BINARY_GLTF;
|
9186 | this.content = null;
|
9187 | this.body = null;
|
9188 | var headerView = new DataView(data, 0, BINARY_EXTENSION_HEADER_LENGTH);
|
9189 | this.header = {
|
9190 | magic: LoaderUtils.decodeText(new Uint8Array(data.slice(0, 4))),
|
9191 | version: headerView.getUint32(4, true),
|
9192 | length: headerView.getUint32(8, true)
|
9193 | };
|
9194 |
|
9195 | if (this.header.magic !== BINARY_EXTENSION_HEADER_MAGIC) {
|
9196 | throw new Error('THREE.GLTFLoader: Unsupported glTF-Binary header.');
|
9197 | } else if (this.header.version < 2.0) {
|
9198 | throw new Error('THREE.GLTFLoader: Legacy binary file detected.');
|
9199 | }
|
9200 |
|
9201 | var chunkView = new DataView(data, BINARY_EXTENSION_HEADER_LENGTH);
|
9202 | var chunkIndex = 0;
|
9203 |
|
9204 | while (chunkIndex < chunkView.byteLength) {
|
9205 | var chunkLength = chunkView.getUint32(chunkIndex, true);
|
9206 | chunkIndex += 4;
|
9207 | var chunkType = chunkView.getUint32(chunkIndex, true);
|
9208 | chunkIndex += 4;
|
9209 |
|
9210 | if (chunkType === BINARY_EXTENSION_CHUNK_TYPES.JSON) {
|
9211 | var contentArray = new Uint8Array(data, BINARY_EXTENSION_HEADER_LENGTH + chunkIndex, chunkLength);
|
9212 | this.content = LoaderUtils.decodeText(contentArray);
|
9213 | } else if (chunkType === BINARY_EXTENSION_CHUNK_TYPES.BIN) {
|
9214 | var byteOffset = BINARY_EXTENSION_HEADER_LENGTH + chunkIndex;
|
9215 | this.body = data.slice(byteOffset, byteOffset + chunkLength);
|
9216 | } // Clients must ignore chunks with unknown types.
|
9217 |
|
9218 |
|
9219 | chunkIndex += chunkLength;
|
9220 | }
|
9221 |
|
9222 | if (this.content === null) {
|
9223 | throw new Error('THREE.GLTFLoader: JSON content not found.');
|
9224 | }
|
9225 | }
|
9226 | /**
|
9227 | * DRACO Mesh Compression Extension
|
9228 | *
|
9229 | * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression
|
9230 | */
|
9231 |
|
9232 |
|
9233 | function GLTFDracoMeshCompressionExtension(json, dracoLoader) {
|
9234 | if (!dracoLoader) {
|
9235 | throw new Error('THREE.GLTFLoader: No DRACOLoader instance provided.');
|
9236 | }
|
9237 |
|
9238 | this.name = EXTENSIONS.KHR_DRACO_MESH_COMPRESSION;
|
9239 | this.json = json;
|
9240 | this.dracoLoader = dracoLoader;
|
9241 | this.dracoLoader.preload();
|
9242 | }
|
9243 |
|
9244 | GLTFDracoMeshCompressionExtension.prototype.decodePrimitive = function (primitive, parser) {
|
9245 | var json = this.json;
|
9246 | var dracoLoader = this.dracoLoader;
|
9247 | var bufferViewIndex = primitive.extensions[this.name].bufferView;
|
9248 | var gltfAttributeMap = primitive.extensions[this.name].attributes;
|
9249 | var threeAttributeMap = {};
|
9250 | var attributeNormalizedMap = {};
|
9251 | var attributeTypeMap = {};
|
9252 |
|
9253 | for (var attributeName in gltfAttributeMap) {
|
9254 | var threeAttributeName = ATTRIBUTES[attributeName] || attributeName.toLowerCase();
|
9255 | threeAttributeMap[threeAttributeName] = gltfAttributeMap[attributeName];
|
9256 | }
|
9257 |
|
9258 | for (attributeName in primitive.attributes) {
|
9259 | var threeAttributeName = ATTRIBUTES[attributeName] || attributeName.toLowerCase();
|
9260 |
|
9261 | if (gltfAttributeMap[attributeName] !== undefined) {
|
9262 | var accessorDef = json.accessors[primitive.attributes[attributeName]];
|
9263 | var componentType = WEBGL_COMPONENT_TYPES[accessorDef.componentType];
|
9264 | attributeTypeMap[threeAttributeName] = componentType;
|
9265 | attributeNormalizedMap[threeAttributeName] = accessorDef.normalized === true;
|
9266 | }
|
9267 | }
|
9268 |
|
9269 | return parser.getDependency('bufferView', bufferViewIndex).then(function (bufferView) {
|
9270 | return new Promise(function (resolve) {
|
9271 | dracoLoader.decodeDracoFile(bufferView, function (geometry) {
|
9272 | for (var attributeName in geometry.attributes) {
|
9273 | var attribute = geometry.attributes[attributeName];
|
9274 | var normalized = attributeNormalizedMap[attributeName];
|
9275 | if (normalized !== undefined) attribute.normalized = normalized;
|
9276 | }
|
9277 |
|
9278 | resolve(geometry);
|
9279 | }, threeAttributeMap, attributeTypeMap);
|
9280 | });
|
9281 | });
|
9282 | };
|
9283 | /**
|
9284 | * Texture Transform Extension
|
9285 | *
|
9286 | * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_texture_transform
|
9287 | */
|
9288 |
|
9289 |
|
9290 | function GLTFTextureTransformExtension() {
|
9291 | this.name = EXTENSIONS.KHR_TEXTURE_TRANSFORM;
|
9292 | }
|
9293 |
|
9294 | GLTFTextureTransformExtension.prototype.extendTexture = function (texture, transform) {
|
9295 | texture = texture.clone();
|
9296 |
|
9297 | if (transform.offset !== undefined) {
|
9298 | texture.offset.fromArray(transform.offset);
|
9299 | }
|
9300 |
|
9301 | if (transform.rotation !== undefined) {
|
9302 | texture.rotation = transform.rotation;
|
9303 | }
|
9304 |
|
9305 | if (transform.scale !== undefined) {
|
9306 | texture.repeat.fromArray(transform.scale);
|
9307 | }
|
9308 |
|
9309 | if (transform.texCoord !== undefined) {
|
9310 | console.warn('THREE.GLTFLoader: Custom UV sets in "' + this.name + '" extension not yet supported.');
|
9311 | }
|
9312 |
|
9313 | texture.needsUpdate = true;
|
9314 | return texture;
|
9315 | };
|
9316 | /**
|
9317 | * Specular-Glossiness Extension
|
9318 | *
|
9319 | * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_pbrSpecularGlossiness
|
9320 | */
|
9321 |
|
9322 | /**
|
9323 | * A sub class of StandardMaterial with some of the functionality
|
9324 | * changed via the `onBeforeCompile` callback
|
9325 | * @pailhead
|
9326 | */
|
9327 |
|
9328 |
|
9329 | function GLTFMeshStandardSGMaterial(params) {
|
9330 | MeshStandardMaterial.call(this);
|
9331 | this.isGLTFSpecularGlossinessMaterial = true; //various chunks that need replacing
|
9332 |
|
9333 | var specularMapParsFragmentChunk = ['#ifdef USE_SPECULARMAP', ' uniform sampler2D specularMap;', '#endif'].join('\n');
|
9334 | var glossinessMapParsFragmentChunk = ['#ifdef USE_GLOSSINESSMAP', ' uniform sampler2D glossinessMap;', '#endif'].join('\n');
|
9335 | var specularMapFragmentChunk = ['vec3 specularFactor = specular;', '#ifdef USE_SPECULARMAP', ' vec4 texelSpecular = texture2D( specularMap, vUv );', ' texelSpecular = sRGBToLinear( texelSpecular );', ' // reads channel RGB, compatible with a glTF Specular-Glossiness (RGBA) texture', ' specularFactor *= texelSpecular.rgb;', '#endif'].join('\n');
|
9336 | var glossinessMapFragmentChunk = ['float glossinessFactor = glossiness;', '#ifdef USE_GLOSSINESSMAP', ' vec4 texelGlossiness = texture2D( glossinessMap, vUv );', ' // reads channel A, compatible with a glTF Specular-Glossiness (RGBA) texture', ' glossinessFactor *= texelGlossiness.a;', '#endif'].join('\n');
|
9337 | var lightPhysicalFragmentChunk = ['PhysicalMaterial material;', 'material.diffuseColor = diffuseColor.rgb;', 'vec3 dxy = max( abs( dFdx( geometryNormal ) ), abs( dFdy( geometryNormal ) ) );', 'float geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );', 'material.specularRoughness = max( 1.0 - glossinessFactor, 0.0525 );// 0.0525 corresponds to the base mip of a 256 cubemap.', 'material.specularRoughness += geometryRoughness;', 'material.specularRoughness = min( material.specularRoughness, 1.0 );', 'material.specularColor = specularFactor.rgb;'].join('\n');
|
9338 | var uniforms = {
|
9339 | specular: {
|
9340 | value: new Color().setHex(0xffffff)
|
9341 | },
|
9342 | glossiness: {
|
9343 | value: 1
|
9344 | },
|
9345 | specularMap: {
|
9346 | value: null
|
9347 | },
|
9348 | glossinessMap: {
|
9349 | value: null
|
9350 | }
|
9351 | };
|
9352 | this._extraUniforms = uniforms; // please see #14031 or #13198 for an alternate approach
|
9353 |
|
9354 | this.onBeforeCompile = function (shader) {
|
9355 | for (var uniformName in uniforms) {
|
9356 | shader.uniforms[uniformName] = uniforms[uniformName];
|
9357 | }
|
9358 |
|
9359 | shader.fragmentShader = shader.fragmentShader.replace('uniform float roughness;', 'uniform vec3 specular;');
|
9360 | shader.fragmentShader = shader.fragmentShader.replace('uniform float metalness;', 'uniform float glossiness;');
|
9361 | shader.fragmentShader = shader.fragmentShader.replace('#include <roughnessmap_pars_fragment>', specularMapParsFragmentChunk);
|
9362 | shader.fragmentShader = shader.fragmentShader.replace('#include <metalnessmap_pars_fragment>', glossinessMapParsFragmentChunk);
|
9363 | shader.fragmentShader = shader.fragmentShader.replace('#include <roughnessmap_fragment>', specularMapFragmentChunk);
|
9364 | shader.fragmentShader = shader.fragmentShader.replace('#include <metalnessmap_fragment>', glossinessMapFragmentChunk);
|
9365 | shader.fragmentShader = shader.fragmentShader.replace('#include <lights_physical_fragment>', lightPhysicalFragmentChunk);
|
9366 | };
|
9367 | /*eslint-disable*/
|
9368 |
|
9369 |
|
9370 | Object.defineProperties(this, {
|
9371 | specular: {
|
9372 | get: function get() {
|
9373 | return uniforms.specular.value;
|
9374 | },
|
9375 | set: function set(v) {
|
9376 | uniforms.specular.value = v;
|
9377 | }
|
9378 | },
|
9379 | specularMap: {
|
9380 | get: function get() {
|
9381 | return uniforms.specularMap.value;
|
9382 | },
|
9383 | set: function set(v) {
|
9384 | uniforms.specularMap.value = v;
|
9385 | }
|
9386 | },
|
9387 | glossiness: {
|
9388 | get: function get() {
|
9389 | return uniforms.glossiness.value;
|
9390 | },
|
9391 | set: function set(v) {
|
9392 | uniforms.glossiness.value = v;
|
9393 | }
|
9394 | },
|
9395 | glossinessMap: {
|
9396 | get: function get() {
|
9397 | return uniforms.glossinessMap.value;
|
9398 | },
|
9399 | set: function set(v) {
|
9400 | uniforms.glossinessMap.value = v; //how about something like this - @pailhead
|
9401 |
|
9402 | if (v) {
|
9403 | this.defines.USE_GLOSSINESSMAP = ''; // set USE_ROUGHNESSMAP to enable vUv
|
9404 |
|
9405 | this.defines.USE_ROUGHNESSMAP = '';
|
9406 | } else {
|
9407 | delete this.defines.USE_ROUGHNESSMAP;
|
9408 | delete this.defines.USE_GLOSSINESSMAP;
|
9409 | }
|
9410 | }
|
9411 | }
|
9412 | });
|
9413 | /*eslint-enable*/
|
9414 |
|
9415 | delete this.metalness;
|
9416 | delete this.roughness;
|
9417 | delete this.metalnessMap;
|
9418 | delete this.roughnessMap;
|
9419 | this.setValues(params);
|
9420 | }
|
9421 |
|
9422 | GLTFMeshStandardSGMaterial.prototype = Object.create(MeshStandardMaterial.prototype);
|
9423 | GLTFMeshStandardSGMaterial.prototype.constructor = GLTFMeshStandardSGMaterial;
|
9424 |
|
9425 | GLTFMeshStandardSGMaterial.prototype.copy = function (source) {
|
9426 | MeshStandardMaterial.prototype.copy.call(this, source);
|
9427 | this.specularMap = source.specularMap;
|
9428 | this.specular.copy(source.specular);
|
9429 | this.glossinessMap = source.glossinessMap;
|
9430 | this.glossiness = source.glossiness;
|
9431 | delete this.metalness;
|
9432 | delete this.roughness;
|
9433 | delete this.metalnessMap;
|
9434 | delete this.roughnessMap;
|
9435 | return this;
|
9436 | };
|
9437 |
|
9438 | function GLTFMaterialsPbrSpecularGlossinessExtension() {
|
9439 | return {
|
9440 | name: EXTENSIONS.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS,
|
9441 | specularGlossinessParams: ['color', 'map', 'lightMap', 'lightMapIntensity', 'aoMap', 'aoMapIntensity', 'emissive', 'emissiveIntensity', 'emissiveMap', 'bumpMap', 'bumpScale', 'normalMap', 'normalMapType', 'displacementMap', 'displacementScale', 'displacementBias', 'specularMap', 'specular', 'glossinessMap', 'glossiness', 'alphaMap', 'envMap', 'envMapIntensity', 'refractionRatio'],
|
9442 | getMaterialType: function getMaterialType() {
|
9443 | return GLTFMeshStandardSGMaterial;
|
9444 | },
|
9445 | extendParams: function extendParams(materialParams, materialDef, parser) {
|
9446 | var pbrSpecularGlossiness = materialDef.extensions[this.name];
|
9447 | materialParams.color = new Color(1.0, 1.0, 1.0);
|
9448 | materialParams.opacity = 1.0;
|
9449 | var pending = [];
|
9450 |
|
9451 | if (Array.isArray(pbrSpecularGlossiness.diffuseFactor)) {
|
9452 | var array = pbrSpecularGlossiness.diffuseFactor;
|
9453 | materialParams.color.fromArray(array);
|
9454 | materialParams.opacity = array[3];
|
9455 | }
|
9456 |
|
9457 | if (pbrSpecularGlossiness.diffuseTexture !== undefined) {
|
9458 | pending.push(parser.assignTexture(materialParams, 'map', pbrSpecularGlossiness.diffuseTexture));
|
9459 | }
|
9460 |
|
9461 | materialParams.emissive = new Color(0.0, 0.0, 0.0);
|
9462 | materialParams.glossiness = pbrSpecularGlossiness.glossinessFactor !== undefined ? pbrSpecularGlossiness.glossinessFactor : 1.0;
|
9463 | materialParams.specular = new Color(1.0, 1.0, 1.0);
|
9464 |
|
9465 | if (Array.isArray(pbrSpecularGlossiness.specularFactor)) {
|
9466 | materialParams.specular.fromArray(pbrSpecularGlossiness.specularFactor);
|
9467 | }
|
9468 |
|
9469 | if (pbrSpecularGlossiness.specularGlossinessTexture !== undefined) {
|
9470 | var specGlossMapDef = pbrSpecularGlossiness.specularGlossinessTexture;
|
9471 | pending.push(parser.assignTexture(materialParams, 'glossinessMap', specGlossMapDef));
|
9472 | pending.push(parser.assignTexture(materialParams, 'specularMap', specGlossMapDef));
|
9473 | }
|
9474 |
|
9475 | return Promise.all(pending);
|
9476 | },
|
9477 | createMaterial: function createMaterial(materialParams) {
|
9478 | var material = new GLTFMeshStandardSGMaterial(materialParams);
|
9479 | material.fog = true;
|
9480 | material.color = materialParams.color;
|
9481 | material.map = materialParams.map === undefined ? null : materialParams.map;
|
9482 | material.lightMap = null;
|
9483 | material.lightMapIntensity = 1.0;
|
9484 | material.aoMap = materialParams.aoMap === undefined ? null : materialParams.aoMap;
|
9485 | material.aoMapIntensity = 1.0;
|
9486 | material.emissive = materialParams.emissive;
|
9487 | material.emissiveIntensity = 1.0;
|
9488 | material.emissiveMap = materialParams.emissiveMap === undefined ? null : materialParams.emissiveMap;
|
9489 | material.bumpMap = materialParams.bumpMap === undefined ? null : materialParams.bumpMap;
|
9490 | material.bumpScale = 1;
|
9491 | material.normalMap = materialParams.normalMap === undefined ? null : materialParams.normalMap;
|
9492 | material.normalMapType = TangentSpaceNormalMap;
|
9493 | if (materialParams.normalScale) material.normalScale = materialParams.normalScale;
|
9494 | material.displacementMap = null;
|
9495 | material.displacementScale = 1;
|
9496 | material.displacementBias = 0;
|
9497 | material.specularMap = materialParams.specularMap === undefined ? null : materialParams.specularMap;
|
9498 | material.specular = materialParams.specular;
|
9499 | material.glossinessMap = materialParams.glossinessMap === undefined ? null : materialParams.glossinessMap;
|
9500 | material.glossiness = materialParams.glossiness;
|
9501 | material.alphaMap = null;
|
9502 | material.envMap = materialParams.envMap === undefined ? null : materialParams.envMap;
|
9503 | material.envMapIntensity = 1.0;
|
9504 | material.refractionRatio = 0.98;
|
9505 | return material;
|
9506 | }
|
9507 | };
|
9508 | }
|
9509 | /**
|
9510 | * Mesh Quantization Extension
|
9511 | *
|
9512 | * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_mesh_quantization
|
9513 | */
|
9514 |
|
9515 |
|
9516 | function GLTFMeshQuantizationExtension() {
|
9517 | this.name = EXTENSIONS.KHR_MESH_QUANTIZATION;
|
9518 | }
|
9519 | /*********************************/
|
9520 |
|
9521 | /********** INTERPOLATION ********/
|
9522 |
|
9523 | /*********************************/
|
9524 | // Spline Interpolation
|
9525 | // Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#appendix-c-spline-interpolation
|
9526 |
|
9527 |
|
9528 | function GLTFCubicSplineInterpolant(parameterPositions, sampleValues, sampleSize, resultBuffer) {
|
9529 | Interpolant.call(this, parameterPositions, sampleValues, sampleSize, resultBuffer);
|
9530 | }
|
9531 |
|
9532 | GLTFCubicSplineInterpolant.prototype = Object.create(Interpolant.prototype);
|
9533 | GLTFCubicSplineInterpolant.prototype.constructor = GLTFCubicSplineInterpolant;
|
9534 |
|
9535 | GLTFCubicSplineInterpolant.prototype.copySampleValue_ = function (index) {
|
9536 | // Copies a sample value to the result buffer. See description of glTF
|
9537 | // CUBICSPLINE values layout in interpolate_() function below.
|
9538 | var result = this.resultBuffer,
|
9539 | values = this.sampleValues,
|
9540 | valueSize = this.valueSize,
|
9541 | offset = index * valueSize * 3 + valueSize;
|
9542 |
|
9543 | for (var i = 0; i !== valueSize; i++) {
|
9544 | result[i] = values[offset + i];
|
9545 | }
|
9546 |
|
9547 | return result;
|
9548 | };
|
9549 |
|
9550 | GLTFCubicSplineInterpolant.prototype.beforeStart_ = GLTFCubicSplineInterpolant.prototype.copySampleValue_;
|
9551 | GLTFCubicSplineInterpolant.prototype.afterEnd_ = GLTFCubicSplineInterpolant.prototype.copySampleValue_;
|
9552 |
|
9553 | GLTFCubicSplineInterpolant.prototype.interpolate_ = function (i1, t0, t, t1) {
|
9554 | var result = this.resultBuffer;
|
9555 | var values = this.sampleValues;
|
9556 | var stride = this.valueSize;
|
9557 | var stride2 = stride * 2;
|
9558 | var stride3 = stride * 3;
|
9559 | var td = t1 - t0;
|
9560 | var p = (t - t0) / td;
|
9561 | var pp = p * p;
|
9562 | var ppp = pp * p;
|
9563 | var offset1 = i1 * stride3;
|
9564 | var offset0 = offset1 - stride3;
|
9565 | var s2 = -2 * ppp + 3 * pp;
|
9566 | var s3 = ppp - pp;
|
9567 | var s0 = 1 - s2;
|
9568 | var s1 = s3 - pp + p; // Layout of keyframe output values for CUBICSPLINE animations:
|
9569 | // [ inTangent_1, splineVertex_1, outTangent_1, inTangent_2, splineVertex_2, ... ]
|
9570 |
|
9571 | for (var i = 0; i !== stride; i++) {
|
9572 | var p0 = values[offset0 + i + stride]; // splineVertex_k
|
9573 |
|
9574 | var m0 = values[offset0 + i + stride2] * td; // outTangent_k * (t_k+1 - t_k)
|
9575 |
|
9576 | var p1 = values[offset1 + i + stride]; // splineVertex_k+1
|
9577 |
|
9578 | var m1 = values[offset1 + i] * td; // inTangent_k+1 * (t_k+1 - t_k)
|
9579 |
|
9580 | result[i] = s0 * p0 + s1 * m0 + s2 * p1 + s3 * m1;
|
9581 | }
|
9582 |
|
9583 | return result;
|
9584 | };
|
9585 | /*********************************/
|
9586 |
|
9587 | /********** INTERNALS ************/
|
9588 |
|
9589 | /*********************************/
|
9590 |
|
9591 | /* CONSTANTS */
|
9592 |
|
9593 |
|
9594 | var WEBGL_CONSTANTS = {
|
9595 | FLOAT: 5126,
|
9596 | //FLOAT_MAT2: 35674,
|
9597 | FLOAT_MAT3: 35675,
|
9598 | FLOAT_MAT4: 35676,
|
9599 | FLOAT_VEC2: 35664,
|
9600 | FLOAT_VEC3: 35665,
|
9601 | FLOAT_VEC4: 35666,
|
9602 | LINEAR: 9729,
|
9603 | REPEAT: 10497,
|
9604 | SAMPLER_2D: 35678,
|
9605 | POINTS: 0,
|
9606 | LINES: 1,
|
9607 | LINE_LOOP: 2,
|
9608 | LINE_STRIP: 3,
|
9609 | TRIANGLES: 4,
|
9610 | TRIANGLE_STRIP: 5,
|
9611 | TRIANGLE_FAN: 6,
|
9612 | UNSIGNED_BYTE: 5121,
|
9613 | UNSIGNED_SHORT: 5123
|
9614 | };
|
9615 | var WEBGL_COMPONENT_TYPES = {
|
9616 | 5120: Int8Array,
|
9617 | 5121: Uint8Array,
|
9618 | 5122: Int16Array,
|
9619 | 5123: Uint16Array,
|
9620 | 5125: Uint32Array,
|
9621 | 5126: Float32Array
|
9622 | };
|
9623 | var WEBGL_FILTERS = {
|
9624 | 9728: NearestFilter,
|
9625 | 9729: LinearFilter,
|
9626 | 9984: NearestMipmapNearestFilter,
|
9627 | 9985: LinearMipmapNearestFilter,
|
9628 | 9986: NearestMipmapLinearFilter,
|
9629 | 9987: LinearMipmapLinearFilter
|
9630 | };
|
9631 | var WEBGL_WRAPPINGS = {
|
9632 | 33071: ClampToEdgeWrapping,
|
9633 | 33648: MirroredRepeatWrapping,
|
9634 | 10497: RepeatWrapping
|
9635 | };
|
9636 | var WEBGL_TYPE_SIZES = {
|
9637 | 'SCALAR': 1,
|
9638 | 'VEC2': 2,
|
9639 | 'VEC3': 3,
|
9640 | 'VEC4': 4,
|
9641 | 'MAT2': 4,
|
9642 | 'MAT3': 9,
|
9643 | 'MAT4': 16
|
9644 | };
|
9645 | var ATTRIBUTES = {
|
9646 | POSITION: 'position',
|
9647 | NORMAL: 'normal',
|
9648 | TANGENT: 'tangent',
|
9649 | TEXCOORD_0: 'uv',
|
9650 | TEXCOORD_1: 'uv2',
|
9651 | COLOR_0: 'color',
|
9652 | WEIGHTS_0: 'skinWeight',
|
9653 | JOINTS_0: 'skinIndex'
|
9654 | };
|
9655 | var PATH_PROPERTIES = {
|
9656 | scale: 'scale',
|
9657 | translation: 'position',
|
9658 | rotation: 'quaternion',
|
9659 | weights: 'morphTargetInfluences'
|
9660 | };
|
9661 | var INTERPOLATION = {
|
9662 | CUBICSPLINE: undefined,
|
9663 | // We use a custom interpolant (GLTFCubicSplineInterpolation) for CUBICSPLINE tracks. Each
|
9664 | // keyframe track will be initialized with a default interpolation type, then modified.
|
9665 | LINEAR: InterpolateLinear,
|
9666 | STEP: InterpolateDiscrete
|
9667 | };
|
9668 | var ALPHA_MODES = {
|
9669 | OPAQUE: 'OPAQUE',
|
9670 | MASK: 'MASK',
|
9671 | BLEND: 'BLEND'
|
9672 | };
|
9673 | var MIME_TYPE_FORMATS = {
|
9674 | 'image/png': RGBAFormat,
|
9675 | 'image/jpeg': RGBFormat
|
9676 | };
|
9677 | /* UTILITY FUNCTIONS */
|
9678 |
|
9679 | function resolveURL(url, path) {
|
9680 | // Invalid URL
|
9681 | if (typeof url !== 'string' || url === '') return ''; // Host Relative URL
|
9682 |
|
9683 | if (/^https?:\/\//i.test(path) && /^\//.test(url)) {
|
9684 | path = path.replace(/(^https?:\/\/[^\/]+).*/i, '$1');
|
9685 | } // Absolute URL http://,https://,//
|
9686 |
|
9687 |
|
9688 | if (/^(https?:)?\/\//i.test(url)) return url; // Data URI
|
9689 |
|
9690 | if (/^data:.*,.*$/i.test(url)) return url; // Blob URL
|
9691 |
|
9692 | if (/^blob:.*$/i.test(url)) return url; // Relative URL
|
9693 |
|
9694 | return path + url;
|
9695 | }
|
9696 | /**
|
9697 | * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#default-material
|
9698 | */
|
9699 |
|
9700 |
|
9701 | function createDefaultMaterial(cache) {
|
9702 | if (cache['DefaultMaterial'] === undefined) {
|
9703 | cache['DefaultMaterial'] = new MeshStandardMaterial({
|
9704 | color: 0xFFFFFF,
|
9705 | emissive: 0x000000,
|
9706 | metalness: 1,
|
9707 | roughness: 1,
|
9708 | transparent: false,
|
9709 | depthTest: true,
|
9710 | side: FrontSide
|
9711 | });
|
9712 | }
|
9713 |
|
9714 | return cache['DefaultMaterial'];
|
9715 | }
|
9716 |
|
9717 | function addUnknownExtensionsToUserData(knownExtensions, object, objectDef) {
|
9718 | // Add unknown glTF extensions to an object's userData.
|
9719 | for (var name in objectDef.extensions) {
|
9720 | if (knownExtensions[name] === undefined) {
|
9721 | object.userData.gltfExtensions = object.userData.gltfExtensions || {};
|
9722 | object.userData.gltfExtensions[name] = objectDef.extensions[name];
|
9723 | }
|
9724 | }
|
9725 | }
|
9726 | /**
|
9727 | * @param {Object3D|Material|BufferGeometry} object
|
9728 | * @param {GLTF.definition} gltfDef
|
9729 | */
|
9730 |
|
9731 |
|
9732 | function assignExtrasToUserData(object, gltfDef) {
|
9733 | if (gltfDef.extras !== undefined) {
|
9734 | if (typeof gltfDef.extras === 'object') {
|
9735 | _extends(object.userData, gltfDef.extras);
|
9736 | } else {
|
9737 | console.warn('THREE.GLTFLoader: Ignoring primitive type .extras, ' + gltfDef.extras);
|
9738 | }
|
9739 | }
|
9740 | }
|
9741 | /**
|
9742 | * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#morph-targets
|
9743 | *
|
9744 | * @param {BufferGeometry} geometry
|
9745 | * @param {Array<GLTF.Target>} targets
|
9746 | * @param {GLTFParser} parser
|
9747 | * @return {Promise<BufferGeometry>}
|
9748 | */
|
9749 |
|
9750 |
|
9751 | function addMorphTargets(geometry, targets, parser) {
|
9752 | var hasMorphPosition = false;
|
9753 | var hasMorphNormal = false;
|
9754 |
|
9755 | for (var i = 0, il = targets.length; i < il; i++) {
|
9756 | var target = targets[i];
|
9757 | if (target.POSITION !== undefined) hasMorphPosition = true;
|
9758 | if (target.NORMAL !== undefined) hasMorphNormal = true;
|
9759 | if (hasMorphPosition && hasMorphNormal) break;
|
9760 | }
|
9761 |
|
9762 | if (!hasMorphPosition && !hasMorphNormal) return Promise.resolve(geometry);
|
9763 | var pendingPositionAccessors = [];
|
9764 | var pendingNormalAccessors = [];
|
9765 |
|
9766 | for (var i = 0, il = targets.length; i < il; i++) {
|
9767 | var target = targets[i];
|
9768 |
|
9769 | if (hasMorphPosition) {
|
9770 | var pendingAccessor = target.POSITION !== undefined ? parser.getDependency('accessor', target.POSITION) : geometry.attributes.position;
|
9771 | pendingPositionAccessors.push(pendingAccessor);
|
9772 | }
|
9773 |
|
9774 | if (hasMorphNormal) {
|
9775 | var pendingAccessor = target.NORMAL !== undefined ? parser.getDependency('accessor', target.NORMAL) : geometry.attributes.normal;
|
9776 | pendingNormalAccessors.push(pendingAccessor);
|
9777 | }
|
9778 | }
|
9779 |
|
9780 | return Promise.all([Promise.all(pendingPositionAccessors), Promise.all(pendingNormalAccessors)]).then(function (accessors) {
|
9781 | var morphPositions = accessors[0];
|
9782 | var morphNormals = accessors[1];
|
9783 | if (hasMorphPosition) geometry.morphAttributes.position = morphPositions;
|
9784 | if (hasMorphNormal) geometry.morphAttributes.normal = morphNormals;
|
9785 | geometry.morphTargetsRelative = true;
|
9786 | return geometry;
|
9787 | });
|
9788 | }
|
9789 | /**
|
9790 | * @param {Mesh} mesh
|
9791 | * @param {GLTF.Mesh} meshDef
|
9792 | */
|
9793 |
|
9794 |
|
9795 | function updateMorphTargets(mesh, meshDef) {
|
9796 | mesh.updateMorphTargets();
|
9797 |
|
9798 | if (meshDef.weights !== undefined) {
|
9799 | for (var i = 0, il = meshDef.weights.length; i < il; i++) {
|
9800 | mesh.morphTargetInfluences[i] = meshDef.weights[i];
|
9801 | }
|
9802 | } // .extras has user-defined data, so check that .extras.targetNames is an array.
|
9803 |
|
9804 |
|
9805 | if (meshDef.extras && Array.isArray(meshDef.extras.targetNames)) {
|
9806 | var targetNames = meshDef.extras.targetNames;
|
9807 |
|
9808 | if (mesh.morphTargetInfluences.length === targetNames.length) {
|
9809 | mesh.morphTargetDictionary = {};
|
9810 |
|
9811 | for (var i = 0, il = targetNames.length; i < il; i++) {
|
9812 | mesh.morphTargetDictionary[targetNames[i]] = i;
|
9813 | }
|
9814 | } else {
|
9815 | console.warn('THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.');
|
9816 | }
|
9817 | }
|
9818 | }
|
9819 |
|
9820 | function createPrimitiveKey(primitiveDef) {
|
9821 | var dracoExtension = primitiveDef.extensions && primitiveDef.extensions[EXTENSIONS.KHR_DRACO_MESH_COMPRESSION];
|
9822 | var geometryKey;
|
9823 |
|
9824 | if (dracoExtension) {
|
9825 | geometryKey = 'draco:' + dracoExtension.bufferView + ':' + dracoExtension.indices + ':' + createAttributesKey(dracoExtension.attributes);
|
9826 | } else {
|
9827 | geometryKey = primitiveDef.indices + ':' + createAttributesKey(primitiveDef.attributes) + ':' + primitiveDef.mode;
|
9828 | }
|
9829 |
|
9830 | return geometryKey;
|
9831 | }
|
9832 |
|
9833 | function createAttributesKey(attributes) {
|
9834 | var attributesKey = '';
|
9835 | var keys = Object.keys(attributes).sort();
|
9836 |
|
9837 | for (var i = 0, il = keys.length; i < il; i++) {
|
9838 | attributesKey += keys[i] + ':' + attributes[keys[i]] + ';';
|
9839 | }
|
9840 |
|
9841 | return attributesKey;
|
9842 | }
|
9843 | /* GLTF PARSER */
|
9844 |
|
9845 |
|
9846 | function GLTFParser(json, extensions, options) {
|
9847 | this.json = json || {};
|
9848 | this.extensions = extensions || {};
|
9849 | this.options = options || {}; // loader object cache
|
9850 |
|
9851 | this.cache = new GLTFRegistry(); // BufferGeometry caching
|
9852 |
|
9853 | this.primitiveCache = {};
|
9854 | this.textureLoader = new TextureLoader(this.options.manager);
|
9855 | this.textureLoader.setCrossOrigin(this.options.crossOrigin);
|
9856 | this.fileLoader = new FileLoader(this.options.manager);
|
9857 | this.fileLoader.setResponseType('arraybuffer');
|
9858 |
|
9859 | if (this.options.crossOrigin === 'use-credentials') {
|
9860 | this.fileLoader.setWithCredentials(true);
|
9861 | }
|
9862 | }
|
9863 |
|
9864 | GLTFParser.prototype.parse = function (onLoad, onError) {
|
9865 | var parser = this;
|
9866 | var json = this.json;
|
9867 | var extensions = this.extensions; // Clear the loader cache
|
9868 |
|
9869 | this.cache.removeAll(); // Mark the special nodes/meshes in json for efficient parse
|
9870 |
|
9871 | this.markDefs();
|
9872 | Promise.all([this.getDependencies('scene'), this.getDependencies('animation'), this.getDependencies('camera')]).then(function (dependencies) {
|
9873 | var result = {
|
9874 | scene: dependencies[0][json.scene || 0],
|
9875 | scenes: dependencies[0],
|
9876 | animations: dependencies[1],
|
9877 | cameras: dependencies[2],
|
9878 | asset: json.asset,
|
9879 | parser: parser,
|
9880 | userData: {}
|
9881 | };
|
9882 | addUnknownExtensionsToUserData(extensions, result, json);
|
9883 | assignExtrasToUserData(result, json);
|
9884 | onLoad(result);
|
9885 | })["catch"](onError);
|
9886 | };
|
9887 | /**
|
9888 | * Marks the special nodes/meshes in json for efficient parse.
|
9889 | */
|
9890 |
|
9891 |
|
9892 | GLTFParser.prototype.markDefs = function () {
|
9893 | var nodeDefs = this.json.nodes || [];
|
9894 | var skinDefs = this.json.skins || [];
|
9895 | var meshDefs = this.json.meshes || [];
|
9896 | var meshReferences = {};
|
9897 | var meshUses = {}; // Nothing in the node definition indicates whether it is a Bone or an
|
9898 | // Object3D. Use the skins' joint references to mark bones.
|
9899 |
|
9900 | for (var skinIndex = 0, skinLength = skinDefs.length; skinIndex < skinLength; skinIndex++) {
|
9901 | var joints = skinDefs[skinIndex].joints;
|
9902 |
|
9903 | for (var i = 0, il = joints.length; i < il; i++) {
|
9904 | nodeDefs[joints[i]].isBone = true;
|
9905 | }
|
9906 | } // Meshes can (and should) be reused by multiple nodes in a glTF asset. To
|
9907 | // avoid having more than one Mesh with the same name, count
|
9908 | // references and rename instances below.
|
9909 | //
|
9910 | // Example: CesiumMilkTruck sample model reuses "Wheel" meshes.
|
9911 |
|
9912 |
|
9913 | for (var nodeIndex = 0, nodeLength = nodeDefs.length; nodeIndex < nodeLength; nodeIndex++) {
|
9914 | var nodeDef = nodeDefs[nodeIndex];
|
9915 |
|
9916 | if (nodeDef.mesh !== undefined) {
|
9917 | if (meshReferences[nodeDef.mesh] === undefined) {
|
9918 | meshReferences[nodeDef.mesh] = meshUses[nodeDef.mesh] = 0;
|
9919 | }
|
9920 |
|
9921 | meshReferences[nodeDef.mesh]++; // Nothing in the mesh definition indicates whether it is
|
9922 | // a SkinnedMesh or Mesh. Use the node's mesh reference
|
9923 | // to mark SkinnedMesh if node has skin.
|
9924 |
|
9925 | if (nodeDef.skin !== undefined) {
|
9926 | meshDefs[nodeDef.mesh].isSkinnedMesh = true;
|
9927 | }
|
9928 | }
|
9929 | }
|
9930 |
|
9931 | this.json.meshReferences = meshReferences;
|
9932 | this.json.meshUses = meshUses;
|
9933 | };
|
9934 | /**
|
9935 | * Requests the specified dependency asynchronously, with caching.
|
9936 | * @param {string} type
|
9937 | * @param {number} index
|
9938 | * @return {Promise<Object3D|Material|THREE.Texture|AnimationClip|ArrayBuffer|Object>}
|
9939 | */
|
9940 |
|
9941 |
|
9942 | GLTFParser.prototype.getDependency = function (type, index) {
|
9943 | var cacheKey = type + ':' + index;
|
9944 | var dependency = this.cache.get(cacheKey);
|
9945 |
|
9946 | if (!dependency) {
|
9947 | switch (type) {
|
9948 | case 'scene':
|
9949 | dependency = this.loadScene(index);
|
9950 | break;
|
9951 |
|
9952 | case 'node':
|
9953 | dependency = this.loadNode(index);
|
9954 | break;
|
9955 |
|
9956 | case 'mesh':
|
9957 | dependency = this.loadMesh(index);
|
9958 | break;
|
9959 |
|
9960 | case 'accessor':
|
9961 | dependency = this.loadAccessor(index);
|
9962 | break;
|
9963 |
|
9964 | case 'bufferView':
|
9965 | dependency = this.loadBufferView(index);
|
9966 | break;
|
9967 |
|
9968 | case 'buffer':
|
9969 | dependency = this.loadBuffer(index);
|
9970 | break;
|
9971 |
|
9972 | case 'material':
|
9973 | dependency = this.loadMaterial(index);
|
9974 | break;
|
9975 |
|
9976 | case 'texture':
|
9977 | dependency = this.loadTexture(index);
|
9978 | break;
|
9979 |
|
9980 | case 'skin':
|
9981 | dependency = this.loadSkin(index);
|
9982 | break;
|
9983 |
|
9984 | case 'animation':
|
9985 | dependency = this.loadAnimation(index);
|
9986 | break;
|
9987 |
|
9988 | case 'camera':
|
9989 | dependency = this.loadCamera(index);
|
9990 | break;
|
9991 |
|
9992 | case 'light':
|
9993 | dependency = this.extensions[EXTENSIONS.KHR_LIGHTS_PUNCTUAL].loadLight(index);
|
9994 | break;
|
9995 |
|
9996 | default:
|
9997 | throw new Error('Unknown type: ' + type);
|
9998 | }
|
9999 |
|
10000 | this.cache.add(cacheKey, dependency);
|
10001 | }
|
10002 |
|
10003 | return dependency;
|
10004 | };
|
10005 | /**
|
10006 | * Requests all dependencies of the specified type asynchronously, with caching.
|
10007 | * @param {string} type
|
10008 | * @return {Promise<Array<Object>>}
|
10009 | */
|
10010 |
|
10011 |
|
10012 | GLTFParser.prototype.getDependencies = function (type) {
|
10013 | var dependencies = this.cache.get(type);
|
10014 |
|
10015 | if (!dependencies) {
|
10016 | var parser = this;
|
10017 | var defs = this.json[type + (type === 'mesh' ? 'es' : 's')] || [];
|
10018 | dependencies = Promise.all(defs.map(function (def, index) {
|
10019 | return parser.getDependency(type, index);
|
10020 | }));
|
10021 | this.cache.add(type, dependencies);
|
10022 | }
|
10023 |
|
10024 | return dependencies;
|
10025 | };
|
10026 | /**
|
10027 | * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#buffers-and-buffer-views
|
10028 | * @param {number} bufferIndex
|
10029 | * @return {Promise<ArrayBuffer>}
|
10030 | */
|
10031 |
|
10032 |
|
10033 | GLTFParser.prototype.loadBuffer = function (bufferIndex) {
|
10034 | var bufferDef = this.json.buffers[bufferIndex];
|
10035 | var loader = this.fileLoader;
|
10036 |
|
10037 | if (bufferDef.type && bufferDef.type !== 'arraybuffer') {
|
10038 | throw new Error('THREE.GLTFLoader: ' + bufferDef.type + ' buffer type is not supported.');
|
10039 | } // If present, GLB container is required to be the first buffer.
|
10040 |
|
10041 |
|
10042 | if (bufferDef.uri === undefined && bufferIndex === 0) {
|
10043 | return Promise.resolve(this.extensions[EXTENSIONS.KHR_BINARY_GLTF].body);
|
10044 | }
|
10045 |
|
10046 | var options = this.options;
|
10047 | return new Promise(function (resolve, reject) {
|
10048 | loader.load(resolveURL(bufferDef.uri, options.path), resolve, undefined, function () {
|
10049 | reject(new Error('THREE.GLTFLoader: Failed to load buffer "' + bufferDef.uri + '".'));
|
10050 | });
|
10051 | });
|
10052 | };
|
10053 | /**
|
10054 | * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#buffers-and-buffer-views
|
10055 | * @param {number} bufferViewIndex
|
10056 | * @return {Promise<ArrayBuffer>}
|
10057 | */
|
10058 |
|
10059 |
|
10060 | GLTFParser.prototype.loadBufferView = function (bufferViewIndex) {
|
10061 | var bufferViewDef = this.json.bufferViews[bufferViewIndex];
|
10062 | return this.getDependency('buffer', bufferViewDef.buffer).then(function (buffer) {
|
10063 | var byteLength = bufferViewDef.byteLength || 0;
|
10064 | var byteOffset = bufferViewDef.byteOffset || 0;
|
10065 | return buffer.slice(byteOffset, byteOffset + byteLength);
|
10066 | });
|
10067 | };
|
10068 | /**
|
10069 | * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#accessors
|
10070 | * @param {number} accessorIndex
|
10071 | * @return {Promise<BufferAttribute|InterleavedBufferAttribute>}
|
10072 | */
|
10073 |
|
10074 |
|
10075 | GLTFParser.prototype.loadAccessor = function (accessorIndex) {
|
10076 | var parser = this;
|
10077 | var json = this.json;
|
10078 | var accessorDef = this.json.accessors[accessorIndex];
|
10079 |
|
10080 | if (accessorDef.bufferView === undefined && accessorDef.sparse === undefined) {
|
10081 | // Ignore empty accessors, which may be used to declare runtime
|
10082 | // information about attributes coming from another source (e.g. Draco
|
10083 | // compression extension).
|
10084 | return Promise.resolve(null);
|
10085 | }
|
10086 |
|
10087 | var pendingBufferViews = [];
|
10088 |
|
10089 | if (accessorDef.bufferView !== undefined) {
|
10090 | pendingBufferViews.push(this.getDependency('bufferView', accessorDef.bufferView));
|
10091 | } else {
|
10092 | pendingBufferViews.push(null);
|
10093 | }
|
10094 |
|
10095 | if (accessorDef.sparse !== undefined) {
|
10096 | pendingBufferViews.push(this.getDependency('bufferView', accessorDef.sparse.indices.bufferView));
|
10097 | pendingBufferViews.push(this.getDependency('bufferView', accessorDef.sparse.values.bufferView));
|
10098 | }
|
10099 |
|
10100 | return Promise.all(pendingBufferViews).then(function (bufferViews) {
|
10101 | var bufferView = bufferViews[0];
|
10102 | var itemSize = WEBGL_TYPE_SIZES[accessorDef.type];
|
10103 | var TypedArray = WEBGL_COMPONENT_TYPES[accessorDef.componentType]; // For VEC3: itemSize is 3, elementBytes is 4, itemBytes is 12.
|
10104 |
|
10105 | var elementBytes = TypedArray.BYTES_PER_ELEMENT;
|
10106 | var itemBytes = elementBytes * itemSize;
|
10107 | var byteOffset = accessorDef.byteOffset || 0;
|
10108 | var byteStride = accessorDef.bufferView !== undefined ? json.bufferViews[accessorDef.bufferView].byteStride : undefined;
|
10109 | var normalized = accessorDef.normalized === true;
|
10110 | var array, bufferAttribute; // The buffer is not interleaved if the stride is the item size in bytes.
|
10111 |
|
10112 | if (byteStride && byteStride !== itemBytes) {
|
10113 | // Each "slice" of the buffer, as defined by 'count' elements of 'byteStride' bytes, gets its own InterleavedBuffer
|
10114 | // This makes sure that IBA.count reflects accessor.count properly
|
10115 | var ibSlice = Math.floor(byteOffset / byteStride);
|
10116 | var ibCacheKey = 'InterleavedBuffer:' + accessorDef.bufferView + ':' + accessorDef.componentType + ':' + ibSlice + ':' + accessorDef.count;
|
10117 | var ib = parser.cache.get(ibCacheKey);
|
10118 |
|
10119 | if (!ib) {
|
10120 | array = new TypedArray(bufferView, ibSlice * byteStride, accessorDef.count * byteStride / elementBytes); // Integer parameters to IB/IBA are in array elements, not bytes.
|
10121 |
|
10122 | ib = new InterleavedBuffer(array, byteStride / elementBytes);
|
10123 | parser.cache.add(ibCacheKey, ib);
|
10124 | }
|
10125 |
|
10126 | bufferAttribute = new InterleavedBufferAttribute(ib, itemSize, byteOffset % byteStride / elementBytes, normalized);
|
10127 | } else {
|
10128 | if (bufferView === null) {
|
10129 | array = new TypedArray(accessorDef.count * itemSize);
|
10130 | } else {
|
10131 | array = new TypedArray(bufferView, byteOffset, accessorDef.count * itemSize);
|
10132 | }
|
10133 |
|
10134 | bufferAttribute = new BufferAttribute(array, itemSize, normalized);
|
10135 | } // https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#sparse-accessors
|
10136 |
|
10137 |
|
10138 | if (accessorDef.sparse !== undefined) {
|
10139 | var itemSizeIndices = WEBGL_TYPE_SIZES.SCALAR;
|
10140 | var TypedArrayIndices = WEBGL_COMPONENT_TYPES[accessorDef.sparse.indices.componentType];
|
10141 | var byteOffsetIndices = accessorDef.sparse.indices.byteOffset || 0;
|
10142 | var byteOffsetValues = accessorDef.sparse.values.byteOffset || 0;
|
10143 | var sparseIndices = new TypedArrayIndices(bufferViews[1], byteOffsetIndices, accessorDef.sparse.count * itemSizeIndices);
|
10144 | var sparseValues = new TypedArray(bufferViews[2], byteOffsetValues, accessorDef.sparse.count * itemSize);
|
10145 |
|
10146 | if (bufferView !== null) {
|
10147 | // Avoid modifying the original ArrayBuffer, if the bufferView wasn't initialized with zeroes.
|
10148 | bufferAttribute = new BufferAttribute(bufferAttribute.array.slice(), bufferAttribute.itemSize, bufferAttribute.normalized);
|
10149 | }
|
10150 |
|
10151 | for (var i = 0, il = sparseIndices.length; i < il; i++) {
|
10152 | var index = sparseIndices[i];
|
10153 | bufferAttribute.setX(index, sparseValues[i * itemSize]);
|
10154 | if (itemSize >= 2) bufferAttribute.setY(index, sparseValues[i * itemSize + 1]);
|
10155 | if (itemSize >= 3) bufferAttribute.setZ(index, sparseValues[i * itemSize + 2]);
|
10156 | if (itemSize >= 4) bufferAttribute.setW(index, sparseValues[i * itemSize + 3]);
|
10157 | if (itemSize >= 5) throw new Error('THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.');
|
10158 | }
|
10159 | }
|
10160 |
|
10161 | return bufferAttribute;
|
10162 | });
|
10163 | };
|
10164 | /**
|
10165 | * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#textures
|
10166 | * @param {number} textureIndex
|
10167 | * @return {Promise<THREE.Texture>}
|
10168 | */
|
10169 |
|
10170 |
|
10171 | GLTFParser.prototype.loadTexture = function (textureIndex) {
|
10172 | var parser = this;
|
10173 | var json = this.json;
|
10174 | var options = this.options;
|
10175 | var textureLoader = this.textureLoader;
|
10176 | var URL = self.URL || self.webkitURL;
|
10177 | var textureDef = json.textures[textureIndex];
|
10178 | var textureExtensions = textureDef.extensions || {};
|
10179 | var source;
|
10180 |
|
10181 | if (textureExtensions[EXTENSIONS.MSFT_TEXTURE_DDS]) {
|
10182 | source = json.images[textureExtensions[EXTENSIONS.MSFT_TEXTURE_DDS].source];
|
10183 | } else {
|
10184 | source = json.images[textureDef.source];
|
10185 | }
|
10186 |
|
10187 | var sourceURI = source.uri;
|
10188 | var isObjectURL = false;
|
10189 |
|
10190 | if (source.bufferView !== undefined) {
|
10191 | // Load binary image data from bufferView, if provided.
|
10192 | sourceURI = parser.getDependency('bufferView', source.bufferView).then(function (bufferView) {
|
10193 | isObjectURL = true;
|
10194 | var blob = new Blob([bufferView], {
|
10195 | type: source.mimeType
|
10196 | });
|
10197 | sourceURI = URL.createObjectURL(blob);
|
10198 | return sourceURI;
|
10199 | });
|
10200 | }
|
10201 |
|
10202 | return Promise.resolve(sourceURI).then(function (sourceURI) {
|
10203 | // Load Texture resource.
|
10204 | var loader = options.manager.getHandler(sourceURI);
|
10205 |
|
10206 | if (!loader) {
|
10207 | loader = textureExtensions[EXTENSIONS.MSFT_TEXTURE_DDS] ? parser.extensions[EXTENSIONS.MSFT_TEXTURE_DDS].ddsLoader : textureLoader;
|
10208 | }
|
10209 |
|
10210 | return new Promise(function (resolve, reject) {
|
10211 | loader.load(resolveURL(sourceURI, options.path), resolve, undefined, reject);
|
10212 | });
|
10213 | }).then(function (texture) {
|
10214 | // Clean up resources and configure Texture.
|
10215 | if (isObjectURL === true) {
|
10216 | URL.revokeObjectURL(sourceURI);
|
10217 | }
|
10218 |
|
10219 | texture.flipY = false;
|
10220 | if (textureDef.name) texture.name = textureDef.name; // Ignore unknown mime types, like DDS files.
|
10221 |
|
10222 | if (source.mimeType in MIME_TYPE_FORMATS) {
|
10223 | texture.format = MIME_TYPE_FORMATS[source.mimeType];
|
10224 | }
|
10225 |
|
10226 | var samplers = json.samplers || {};
|
10227 | var sampler = samplers[textureDef.sampler] || {};
|
10228 | texture.magFilter = WEBGL_FILTERS[sampler.magFilter] || LinearFilter;
|
10229 | texture.minFilter = WEBGL_FILTERS[sampler.minFilter] || LinearMipmapLinearFilter;
|
10230 | texture.wrapS = WEBGL_WRAPPINGS[sampler.wrapS] || RepeatWrapping;
|
10231 | texture.wrapT = WEBGL_WRAPPINGS[sampler.wrapT] || RepeatWrapping;
|
10232 | return texture;
|
10233 | });
|
10234 | };
|
10235 | /**
|
10236 | * Asynchronously assigns a texture to the given material parameters.
|
10237 | * @param {Object} materialParams
|
10238 | * @param {string} mapName
|
10239 | * @param {Object} mapDef
|
10240 | * @return {Promise}
|
10241 | */
|
10242 |
|
10243 |
|
10244 | GLTFParser.prototype.assignTexture = function (materialParams, mapName, mapDef) {
|
10245 | var parser = this;
|
10246 | return this.getDependency('texture', mapDef.index).then(function (texture) {
|
10247 | if (!texture.isCompressedTexture) {
|
10248 | switch (mapName) {
|
10249 | case 'aoMap':
|
10250 | case 'emissiveMap':
|
10251 | case 'metalnessMap':
|
10252 | case 'normalMap':
|
10253 | case 'roughnessMap':
|
10254 | texture.format = RGBFormat;
|
10255 | break;
|
10256 | }
|
10257 | } // Materials sample aoMap from UV set 1 and other maps from UV set 0 - this can't be configured
|
10258 | // However, we will copy UV set 0 to UV set 1 on demand for aoMap
|
10259 |
|
10260 |
|
10261 | if (mapDef.texCoord !== undefined && mapDef.texCoord != 0 && !(mapName === 'aoMap' && mapDef.texCoord == 1)) {
|
10262 | console.warn('THREE.GLTFLoader: Custom UV set ' + mapDef.texCoord + ' for texture ' + mapName + ' not yet supported.');
|
10263 | }
|
10264 |
|
10265 | if (parser.extensions[EXTENSIONS.KHR_TEXTURE_TRANSFORM]) {
|
10266 | var transform = mapDef.extensions !== undefined ? mapDef.extensions[EXTENSIONS.KHR_TEXTURE_TRANSFORM] : undefined;
|
10267 |
|
10268 | if (transform) {
|
10269 | texture = parser.extensions[EXTENSIONS.KHR_TEXTURE_TRANSFORM].extendTexture(texture, transform);
|
10270 | }
|
10271 | }
|
10272 |
|
10273 | materialParams[mapName] = texture;
|
10274 | });
|
10275 | };
|
10276 | /**
|
10277 | * Assigns final material to a Mesh, Line, or Points instance. The instance
|
10278 | * already has a material (generated from the glTF material options alone)
|
10279 | * but reuse of the same glTF material may require multiple threejs materials
|
10280 | * to accomodate different primitive types, defines, etc. New materials will
|
10281 | * be created if necessary, and reused from a cache.
|
10282 | * @param {Object3D} mesh Mesh, Line, or Points instance.
|
10283 | */
|
10284 |
|
10285 |
|
10286 | GLTFParser.prototype.assignFinalMaterial = function (mesh) {
|
10287 | var geometry = mesh.geometry;
|
10288 | var material = mesh.material;
|
10289 | var useVertexTangents = geometry.attributes.tangent !== undefined;
|
10290 | var useVertexColors = geometry.attributes.color !== undefined;
|
10291 | var useFlatShading = geometry.attributes.normal === undefined;
|
10292 | var useSkinning = mesh.isSkinnedMesh === true;
|
10293 | var useMorphTargets = Object.keys(geometry.morphAttributes).length > 0;
|
10294 | var useMorphNormals = useMorphTargets && geometry.morphAttributes.normal !== undefined;
|
10295 |
|
10296 | if (mesh.isPoints) {
|
10297 | var cacheKey = 'PointsMaterial:' + material.uuid;
|
10298 | var pointsMaterial = this.cache.get(cacheKey);
|
10299 |
|
10300 | if (!pointsMaterial) {
|
10301 | pointsMaterial = new PointsMaterial();
|
10302 | Material.prototype.copy.call(pointsMaterial, material);
|
10303 | pointsMaterial.color.copy(material.color);
|
10304 | pointsMaterial.map = material.map;
|
10305 | pointsMaterial.sizeAttenuation = false; // glTF spec says points should be 1px
|
10306 |
|
10307 | this.cache.add(cacheKey, pointsMaterial);
|
10308 | }
|
10309 |
|
10310 | material = pointsMaterial;
|
10311 | } else if (mesh.isLine) {
|
10312 | var cacheKey = 'LineBasicMaterial:' + material.uuid;
|
10313 | var lineMaterial = this.cache.get(cacheKey);
|
10314 |
|
10315 | if (!lineMaterial) {
|
10316 | lineMaterial = new LineBasicMaterial();
|
10317 | Material.prototype.copy.call(lineMaterial, material);
|
10318 | lineMaterial.color.copy(material.color);
|
10319 | this.cache.add(cacheKey, lineMaterial);
|
10320 | }
|
10321 |
|
10322 | material = lineMaterial;
|
10323 | } // Clone the material if it will be modified
|
10324 |
|
10325 |
|
10326 | if (useVertexTangents || useVertexColors || useFlatShading || useSkinning || useMorphTargets) {
|
10327 | var cacheKey = 'ClonedMaterial:' + material.uuid + ':';
|
10328 | if (material.isGLTFSpecularGlossinessMaterial) cacheKey += 'specular-glossiness:';
|
10329 | if (useSkinning) cacheKey += 'skinning:';
|
10330 | if (useVertexTangents) cacheKey += 'vertex-tangents:';
|
10331 | if (useVertexColors) cacheKey += 'vertex-colors:';
|
10332 | if (useFlatShading) cacheKey += 'flat-shading:';
|
10333 | if (useMorphTargets) cacheKey += 'morph-targets:';
|
10334 | if (useMorphNormals) cacheKey += 'morph-normals:';
|
10335 | var cachedMaterial = this.cache.get(cacheKey);
|
10336 |
|
10337 | if (!cachedMaterial) {
|
10338 | cachedMaterial = material.clone();
|
10339 | if (useSkinning) cachedMaterial.skinning = true;
|
10340 | if (useVertexTangents) cachedMaterial.vertexTangents = true;
|
10341 | if (useVertexColors) cachedMaterial.vertexColors = true;
|
10342 | if (useFlatShading) cachedMaterial.flatShading = true;
|
10343 | if (useMorphTargets) cachedMaterial.morphTargets = true;
|
10344 | if (useMorphNormals) cachedMaterial.morphNormals = true;
|
10345 | this.cache.add(cacheKey, cachedMaterial);
|
10346 | }
|
10347 |
|
10348 | material = cachedMaterial;
|
10349 | } // workarounds for mesh and geometry
|
10350 |
|
10351 |
|
10352 | if (material.aoMap && geometry.attributes.uv2 === undefined && geometry.attributes.uv !== undefined) {
|
10353 | geometry.setAttribute('uv2', geometry.attributes.uv);
|
10354 | } // https://github.com/mrdoob/three.js/issues/11438#issuecomment-507003995
|
10355 |
|
10356 |
|
10357 | if (material.normalScale && !useVertexTangents) {
|
10358 | material.normalScale.y = -material.normalScale.y;
|
10359 | }
|
10360 |
|
10361 | if (material.clearcoatNormalScale && !useVertexTangents) {
|
10362 | material.clearcoatNormalScale.y = -material.clearcoatNormalScale.y;
|
10363 | }
|
10364 |
|
10365 | mesh.material = material;
|
10366 | };
|
10367 | /**
|
10368 | * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#materials
|
10369 | * @param {number} materialIndex
|
10370 | * @return {Promise<Material>}
|
10371 | */
|
10372 |
|
10373 |
|
10374 | GLTFParser.prototype.loadMaterial = function (materialIndex) {
|
10375 | var parser = this;
|
10376 | var json = this.json;
|
10377 | var extensions = this.extensions;
|
10378 | var materialDef = json.materials[materialIndex];
|
10379 | var materialType;
|
10380 | var materialParams = {};
|
10381 | var materialExtensions = materialDef.extensions || {};
|
10382 | var pending = [];
|
10383 |
|
10384 | if (materialExtensions[EXTENSIONS.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS]) {
|
10385 | var sgExtension = extensions[EXTENSIONS.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS];
|
10386 | materialType = sgExtension.getMaterialType();
|
10387 | pending.push(sgExtension.extendParams(materialParams, materialDef, parser));
|
10388 | } else if (materialExtensions[EXTENSIONS.KHR_MATERIALS_UNLIT]) {
|
10389 | var kmuExtension = extensions[EXTENSIONS.KHR_MATERIALS_UNLIT];
|
10390 | materialType = kmuExtension.getMaterialType();
|
10391 | pending.push(kmuExtension.extendParams(materialParams, materialDef, parser));
|
10392 | } else {
|
10393 | // Specification:
|
10394 | // https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#metallic-roughness-material
|
10395 | materialType = MeshStandardMaterial;
|
10396 | var metallicRoughness = materialDef.pbrMetallicRoughness || {};
|
10397 | materialParams.color = new Color(1.0, 1.0, 1.0);
|
10398 | materialParams.opacity = 1.0;
|
10399 |
|
10400 | if (Array.isArray(metallicRoughness.baseColorFactor)) {
|
10401 | var array = metallicRoughness.baseColorFactor;
|
10402 | materialParams.color.fromArray(array);
|
10403 | materialParams.opacity = array[3];
|
10404 | }
|
10405 |
|
10406 | if (metallicRoughness.baseColorTexture !== undefined) {
|
10407 | pending.push(parser.assignTexture(materialParams, 'map', metallicRoughness.baseColorTexture));
|
10408 | }
|
10409 |
|
10410 | materialParams.metalness = metallicRoughness.metallicFactor !== undefined ? metallicRoughness.metallicFactor : 1.0;
|
10411 | materialParams.roughness = metallicRoughness.roughnessFactor !== undefined ? metallicRoughness.roughnessFactor : 1.0;
|
10412 |
|
10413 | if (metallicRoughness.metallicRoughnessTexture !== undefined) {
|
10414 | pending.push(parser.assignTexture(materialParams, 'metalnessMap', metallicRoughness.metallicRoughnessTexture));
|
10415 | pending.push(parser.assignTexture(materialParams, 'roughnessMap', metallicRoughness.metallicRoughnessTexture));
|
10416 | }
|
10417 | }
|
10418 |
|
10419 | if (materialDef.doubleSided === true) {
|
10420 | materialParams.side = DoubleSide;
|
10421 | }
|
10422 |
|
10423 | var alphaMode = materialDef.alphaMode || ALPHA_MODES.OPAQUE;
|
10424 |
|
10425 | if (alphaMode === ALPHA_MODES.BLEND) {
|
10426 | materialParams.transparent = true; // See: https://github.com/mrdoob/three.js/issues/17706
|
10427 |
|
10428 | materialParams.depthWrite = false;
|
10429 | } else {
|
10430 | materialParams.transparent = false;
|
10431 |
|
10432 | if (alphaMode === ALPHA_MODES.MASK) {
|
10433 | materialParams.alphaTest = materialDef.alphaCutoff !== undefined ? materialDef.alphaCutoff : 0.5;
|
10434 | }
|
10435 | }
|
10436 |
|
10437 | if (materialDef.normalTexture !== undefined && materialType !== MeshBasicMaterial) {
|
10438 | pending.push(parser.assignTexture(materialParams, 'normalMap', materialDef.normalTexture));
|
10439 | materialParams.normalScale = new Vector2(1, 1);
|
10440 |
|
10441 | if (materialDef.normalTexture.scale !== undefined) {
|
10442 | materialParams.normalScale.set(materialDef.normalTexture.scale, materialDef.normalTexture.scale);
|
10443 | }
|
10444 | }
|
10445 |
|
10446 | if (materialDef.occlusionTexture !== undefined && materialType !== MeshBasicMaterial) {
|
10447 | pending.push(parser.assignTexture(materialParams, 'aoMap', materialDef.occlusionTexture));
|
10448 |
|
10449 | if (materialDef.occlusionTexture.strength !== undefined) {
|
10450 | materialParams.aoMapIntensity = materialDef.occlusionTexture.strength;
|
10451 | }
|
10452 | }
|
10453 |
|
10454 | if (materialDef.emissiveFactor !== undefined && materialType !== MeshBasicMaterial) {
|
10455 | materialParams.emissive = new Color().fromArray(materialDef.emissiveFactor);
|
10456 | }
|
10457 |
|
10458 | if (materialDef.emissiveTexture !== undefined && materialType !== MeshBasicMaterial) {
|
10459 | pending.push(parser.assignTexture(materialParams, 'emissiveMap', materialDef.emissiveTexture));
|
10460 | }
|
10461 |
|
10462 | if (materialExtensions[EXTENSIONS.KHR_MATERIALS_CLEARCOAT]) {
|
10463 | var clearcoatExtension = extensions[EXTENSIONS.KHR_MATERIALS_CLEARCOAT];
|
10464 | materialType = clearcoatExtension.getMaterialType();
|
10465 | pending.push(clearcoatExtension.extendParams(materialParams, {
|
10466 | extensions: materialExtensions
|
10467 | }, parser));
|
10468 | }
|
10469 |
|
10470 | return Promise.all(pending).then(function () {
|
10471 | var material;
|
10472 |
|
10473 | if (materialType === GLTFMeshStandardSGMaterial) {
|
10474 | material = extensions[EXTENSIONS.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS].createMaterial(materialParams);
|
10475 | } else {
|
10476 | material = new materialType(materialParams);
|
10477 | }
|
10478 |
|
10479 | if (materialDef.name) material.name = materialDef.name; // baseColorTexture, emissiveTexture, and specularGlossinessTexture use sRGB encoding.
|
10480 |
|
10481 | if (material.map) material.map.encoding = sRGBEncoding;
|
10482 | if (material.emissiveMap) material.emissiveMap.encoding = sRGBEncoding;
|
10483 | assignExtrasToUserData(material, materialDef);
|
10484 | if (materialDef.extensions) addUnknownExtensionsToUserData(extensions, material, materialDef);
|
10485 | return material;
|
10486 | });
|
10487 | };
|
10488 | /**
|
10489 | * @param {BufferGeometry} geometry
|
10490 | * @param {GLTF.Primitive} primitiveDef
|
10491 | * @param {GLTFParser} parser
|
10492 | */
|
10493 |
|
10494 |
|
10495 | function computeBounds(geometry, primitiveDef, parser) {
|
10496 | var attributes = primitiveDef.attributes;
|
10497 | var box = new Box3();
|
10498 |
|
10499 | if (attributes.POSITION !== undefined) {
|
10500 | var accessor = parser.json.accessors[attributes.POSITION];
|
10501 | var min = accessor.min;
|
10502 | var max = accessor.max; // glTF requires 'min' and 'max', but VRM (which extends glTF) currently ignores that requirement.
|
10503 |
|
10504 | if (min !== undefined && max !== undefined) {
|
10505 | box.set(new Vector3(min[0], min[1], min[2]), new Vector3(max[0], max[1], max[2]));
|
10506 | } else {
|
10507 | console.warn('THREE.GLTFLoader: Missing min/max properties for accessor POSITION.');
|
10508 | return;
|
10509 | }
|
10510 | } else {
|
10511 | return;
|
10512 | }
|
10513 |
|
10514 | var targets = primitiveDef.targets;
|
10515 |
|
10516 | if (targets !== undefined) {
|
10517 | var maxDisplacement = new Vector3();
|
10518 | var vector = new Vector3();
|
10519 |
|
10520 | for (var i = 0, il = targets.length; i < il; i++) {
|
10521 | var target = targets[i];
|
10522 |
|
10523 | if (target.POSITION !== undefined) {
|
10524 | var accessor = parser.json.accessors[target.POSITION];
|
10525 | var min = accessor.min;
|
10526 | var max = accessor.max; // glTF requires 'min' and 'max', but VRM (which extends glTF) currently ignores that requirement.
|
10527 |
|
10528 | if (min !== undefined && max !== undefined) {
|
10529 | // we need to get max of absolute components because target weight is [-1,1]
|
10530 | vector.setX(Math.max(Math.abs(min[0]), Math.abs(max[0])));
|
10531 | vector.setY(Math.max(Math.abs(min[1]), Math.abs(max[1])));
|
10532 | vector.setZ(Math.max(Math.abs(min[2]), Math.abs(max[2]))); // Note: this assumes that the sum of all weights is at most 1. This isn't quite correct - it's more conservative
|
10533 | // to assume that each target can have a max weight of 1. However, for some use cases - notably, when morph targets
|
10534 | // are used to implement key-frame animations and as such only two are active at a time - this results in very large
|
10535 | // boxes. So for now we make a box that's sometimes a touch too small but is hopefully mostly of reasonable size.
|
10536 |
|
10537 | maxDisplacement.max(vector);
|
10538 | } else {
|
10539 | console.warn('THREE.GLTFLoader: Missing min/max properties for accessor POSITION.');
|
10540 | }
|
10541 | }
|
10542 | } // As per comment above this box isn't conservative, but has a reasonable size for a very large number of morph targets.
|
10543 |
|
10544 |
|
10545 | box.expandByVector(maxDisplacement);
|
10546 | }
|
10547 |
|
10548 | geometry.boundingBox = box;
|
10549 | var sphere = new Sphere();
|
10550 | box.getCenter(sphere.center);
|
10551 | sphere.radius = box.min.distanceTo(box.max) / 2;
|
10552 | geometry.boundingSphere = sphere;
|
10553 | }
|
10554 | /**
|
10555 | * @param {BufferGeometry} geometry
|
10556 | * @param {GLTF.Primitive} primitiveDef
|
10557 | * @param {GLTFParser} parser
|
10558 | * @return {Promise<BufferGeometry>}
|
10559 | */
|
10560 |
|
10561 |
|
10562 | function addPrimitiveAttributes(geometry, primitiveDef, parser) {
|
10563 | var attributes = primitiveDef.attributes;
|
10564 | var pending = [];
|
10565 |
|
10566 | function assignAttributeAccessor(accessorIndex, attributeName) {
|
10567 | return parser.getDependency('accessor', accessorIndex).then(function (accessor) {
|
10568 | geometry.setAttribute(attributeName, accessor);
|
10569 | });
|
10570 | }
|
10571 |
|
10572 | for (var gltfAttributeName in attributes) {
|
10573 | var threeAttributeName = ATTRIBUTES[gltfAttributeName] || gltfAttributeName.toLowerCase(); // Skip attributes already provided by e.g. Draco extension.
|
10574 |
|
10575 | if (threeAttributeName in geometry.attributes) continue;
|
10576 | pending.push(assignAttributeAccessor(attributes[gltfAttributeName], threeAttributeName));
|
10577 | }
|
10578 |
|
10579 | if (primitiveDef.indices !== undefined && !geometry.index) {
|
10580 | var accessor = parser.getDependency('accessor', primitiveDef.indices).then(function (accessor) {
|
10581 | geometry.setIndex(accessor);
|
10582 | });
|
10583 | pending.push(accessor);
|
10584 | }
|
10585 |
|
10586 | assignExtrasToUserData(geometry, primitiveDef);
|
10587 | computeBounds(geometry, primitiveDef, parser);
|
10588 | return Promise.all(pending).then(function () {
|
10589 | return primitiveDef.targets !== undefined ? addMorphTargets(geometry, primitiveDef.targets, parser) : geometry;
|
10590 | });
|
10591 | }
|
10592 | /**
|
10593 | * @param {BufferGeometry} geometry
|
10594 | * @param {Number} drawMode
|
10595 | * @return {BufferGeometry}
|
10596 | */
|
10597 |
|
10598 |
|
10599 | function toTrianglesDrawMode(geometry, drawMode) {
|
10600 | var index = geometry.getIndex(); // generate index if not present
|
10601 |
|
10602 | if (index === null) {
|
10603 | var indices = [];
|
10604 | var position = geometry.getAttribute('position');
|
10605 |
|
10606 | if (position !== undefined) {
|
10607 | for (var i = 0; i < position.count; i++) {
|
10608 | indices.push(i);
|
10609 | }
|
10610 |
|
10611 | geometry.setIndex(indices);
|
10612 | index = geometry.getIndex();
|
10613 | } else {
|
10614 | console.error('THREE.GLTFLoader.toTrianglesDrawMode(): Undefined position attribute. Processing not possible.');
|
10615 | return geometry;
|
10616 | }
|
10617 | } //
|
10618 |
|
10619 |
|
10620 | var numberOfTriangles = index.count - 2;
|
10621 | var newIndices = [];
|
10622 |
|
10623 | if (drawMode === TriangleFanDrawMode) {
|
10624 | // gl.TRIANGLE_FAN
|
10625 | for (var i = 1; i <= numberOfTriangles; i++) {
|
10626 | newIndices.push(index.getX(0));
|
10627 | newIndices.push(index.getX(i));
|
10628 | newIndices.push(index.getX(i + 1));
|
10629 | }
|
10630 | } else {
|
10631 | // gl.TRIANGLE_STRIP
|
10632 | for (var i = 0; i < numberOfTriangles; i++) {
|
10633 | if (i % 2 === 0) {
|
10634 | newIndices.push(index.getX(i));
|
10635 | newIndices.push(index.getX(i + 1));
|
10636 | newIndices.push(index.getX(i + 2));
|
10637 | } else {
|
10638 | newIndices.push(index.getX(i + 2));
|
10639 | newIndices.push(index.getX(i + 1));
|
10640 | newIndices.push(index.getX(i));
|
10641 | }
|
10642 | }
|
10643 | }
|
10644 |
|
10645 | if (newIndices.length / 3 !== numberOfTriangles) {
|
10646 | console.error('THREE.GLTFLoader.toTrianglesDrawMode(): Unable to generate correct amount of triangles.');
|
10647 | } // build final geometry
|
10648 |
|
10649 |
|
10650 | var newGeometry = geometry.clone();
|
10651 | newGeometry.setIndex(newIndices);
|
10652 | return newGeometry;
|
10653 | }
|
10654 | /**
|
10655 | * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#geometry
|
10656 | *
|
10657 | * Creates BufferGeometries from primitives.
|
10658 | *
|
10659 | * @param {Array<GLTF.Primitive>} primitives
|
10660 | * @return {Promise<Array<BufferGeometry>>}
|
10661 | */
|
10662 |
|
10663 |
|
10664 | GLTFParser.prototype.loadGeometries = function (primitives) {
|
10665 | var parser = this;
|
10666 | var extensions = this.extensions;
|
10667 | var cache = this.primitiveCache;
|
10668 |
|
10669 | function createDracoPrimitive(primitive) {
|
10670 | return extensions[EXTENSIONS.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(primitive, parser).then(function (geometry) {
|
10671 | return addPrimitiveAttributes(geometry, primitive, parser);
|
10672 | });
|
10673 | }
|
10674 |
|
10675 | var pending = [];
|
10676 |
|
10677 | for (var i = 0, il = primitives.length; i < il; i++) {
|
10678 | var primitive = primitives[i];
|
10679 | var cacheKey = createPrimitiveKey(primitive); // See if we've already created this geometry
|
10680 |
|
10681 | var cached = cache[cacheKey];
|
10682 |
|
10683 | if (cached) {
|
10684 | // Use the cached geometry if it exists
|
10685 | pending.push(cached.promise);
|
10686 | } else {
|
10687 | var geometryPromise;
|
10688 |
|
10689 | if (primitive.extensions && primitive.extensions[EXTENSIONS.KHR_DRACO_MESH_COMPRESSION]) {
|
10690 | // Use DRACO geometry if available
|
10691 | geometryPromise = createDracoPrimitive(primitive);
|
10692 | } else {
|
10693 | // Otherwise create a new geometry
|
10694 | geometryPromise = addPrimitiveAttributes(new BufferGeometry(), primitive, parser);
|
10695 | } // Cache this geometry
|
10696 |
|
10697 |
|
10698 | cache[cacheKey] = {
|
10699 | primitive: primitive,
|
10700 | promise: geometryPromise
|
10701 | };
|
10702 | pending.push(geometryPromise);
|
10703 | }
|
10704 | }
|
10705 |
|
10706 | return Promise.all(pending);
|
10707 | };
|
10708 | /**
|
10709 | * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#meshes
|
10710 | * @param {number} meshIndex
|
10711 | * @return {Promise<Group|Mesh|SkinnedMesh>}
|
10712 | */
|
10713 |
|
10714 |
|
10715 | GLTFParser.prototype.loadMesh = function (meshIndex) {
|
10716 | var parser = this;
|
10717 | var json = this.json;
|
10718 | var meshDef = json.meshes[meshIndex];
|
10719 | var primitives = meshDef.primitives;
|
10720 | var pending = [];
|
10721 |
|
10722 | for (var i = 0, il = primitives.length; i < il; i++) {
|
10723 | var material = primitives[i].material === undefined ? createDefaultMaterial(this.cache) : this.getDependency('material', primitives[i].material);
|
10724 | pending.push(material);
|
10725 | }
|
10726 |
|
10727 | pending.push(parser.loadGeometries(primitives));
|
10728 | return Promise.all(pending).then(function (results) {
|
10729 | var materials = results.slice(0, results.length - 1);
|
10730 | var geometries = results[results.length - 1];
|
10731 | var meshes = [];
|
10732 |
|
10733 | for (var i = 0, il = geometries.length; i < il; i++) {
|
10734 | var geometry = geometries[i];
|
10735 | var primitive = primitives[i]; // 1. create Mesh
|
10736 |
|
10737 | var mesh;
|
10738 | var material = materials[i];
|
10739 |
|
10740 | if (primitive.mode === WEBGL_CONSTANTS.TRIANGLES || primitive.mode === WEBGL_CONSTANTS.TRIANGLE_STRIP || primitive.mode === WEBGL_CONSTANTS.TRIANGLE_FAN || primitive.mode === undefined) {
|
10741 | // .isSkinnedMesh isn't in glTF spec. See .markDefs()
|
10742 | mesh = meshDef.isSkinnedMesh === true ? new SkinnedMesh(geometry, material) : new Mesh(geometry, material);
|
10743 |
|
10744 | if (mesh.isSkinnedMesh === true && !mesh.geometry.attributes.skinWeight.normalized) {
|
10745 | // we normalize floating point skin weight array to fix malformed assets (see #15319)
|
10746 | // it's important to skip this for non-float32 data since normalizeSkinWeights assumes non-normalized inputs
|
10747 | mesh.normalizeSkinWeights();
|
10748 | }
|
10749 |
|
10750 | if (primitive.mode === WEBGL_CONSTANTS.TRIANGLE_STRIP) {
|
10751 | mesh.geometry = toTrianglesDrawMode(mesh.geometry, TriangleStripDrawMode);
|
10752 | } else if (primitive.mode === WEBGL_CONSTANTS.TRIANGLE_FAN) {
|
10753 | mesh.geometry = toTrianglesDrawMode(mesh.geometry, TriangleFanDrawMode);
|
10754 | }
|
10755 | } else if (primitive.mode === WEBGL_CONSTANTS.LINES) {
|
10756 | mesh = new LineSegments(geometry, material);
|
10757 | } else if (primitive.mode === WEBGL_CONSTANTS.LINE_STRIP) {
|
10758 | mesh = new Line(geometry, material);
|
10759 | } else if (primitive.mode === WEBGL_CONSTANTS.LINE_LOOP) {
|
10760 | mesh = new LineLoop(geometry, material);
|
10761 | } else if (primitive.mode === WEBGL_CONSTANTS.POINTS) {
|
10762 | mesh = new Points(geometry, material);
|
10763 | } else {
|
10764 | throw new Error('THREE.GLTFLoader: Primitive mode unsupported: ' + primitive.mode);
|
10765 | }
|
10766 |
|
10767 | if (Object.keys(mesh.geometry.morphAttributes).length > 0) {
|
10768 | updateMorphTargets(mesh, meshDef);
|
10769 | }
|
10770 |
|
10771 | mesh.name = meshDef.name || 'mesh_' + meshIndex;
|
10772 | if (geometries.length > 1) mesh.name += '_' + i;
|
10773 | assignExtrasToUserData(mesh, meshDef);
|
10774 | parser.assignFinalMaterial(mesh);
|
10775 | meshes.push(mesh);
|
10776 | }
|
10777 |
|
10778 | if (meshes.length === 1) {
|
10779 | return meshes[0];
|
10780 | }
|
10781 |
|
10782 | var group = new Group();
|
10783 |
|
10784 | for (var i = 0, il = meshes.length; i < il; i++) {
|
10785 | group.add(meshes[i]);
|
10786 | }
|
10787 |
|
10788 | return group;
|
10789 | });
|
10790 | };
|
10791 | /**
|
10792 | * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#cameras
|
10793 | * @param {number} cameraIndex
|
10794 | * @return {Promise<THREE.Camera>}
|
10795 | */
|
10796 |
|
10797 |
|
10798 | GLTFParser.prototype.loadCamera = function (cameraIndex) {
|
10799 | var camera;
|
10800 | var cameraDef = this.json.cameras[cameraIndex];
|
10801 | var params = cameraDef[cameraDef.type];
|
10802 |
|
10803 | if (!params) {
|
10804 | console.warn('THREE.GLTFLoader: Missing camera parameters.');
|
10805 | return;
|
10806 | }
|
10807 |
|
10808 | if (cameraDef.type === 'perspective') {
|
10809 | camera = new PerspectiveCamera(MathUtils.radToDeg(params.yfov), params.aspectRatio || 1, params.znear || 1, params.zfar || 2e6);
|
10810 | } else if (cameraDef.type === 'orthographic') {
|
10811 | camera = new OrthographicCamera(-params.xmag, params.xmag, params.ymag, -params.ymag, params.znear, params.zfar);
|
10812 | }
|
10813 |
|
10814 | if (cameraDef.name) camera.name = cameraDef.name;
|
10815 | assignExtrasToUserData(camera, cameraDef);
|
10816 | return Promise.resolve(camera);
|
10817 | };
|
10818 | /**
|
10819 | * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins
|
10820 | * @param {number} skinIndex
|
10821 | * @return {Promise<Object>}
|
10822 | */
|
10823 |
|
10824 |
|
10825 | GLTFParser.prototype.loadSkin = function (skinIndex) {
|
10826 | var skinDef = this.json.skins[skinIndex];
|
10827 | var skinEntry = {
|
10828 | joints: skinDef.joints
|
10829 | };
|
10830 |
|
10831 | if (skinDef.inverseBindMatrices === undefined) {
|
10832 | return Promise.resolve(skinEntry);
|
10833 | }
|
10834 |
|
10835 | return this.getDependency('accessor', skinDef.inverseBindMatrices).then(function (accessor) {
|
10836 | skinEntry.inverseBindMatrices = accessor;
|
10837 | return skinEntry;
|
10838 | });
|
10839 | };
|
10840 | /**
|
10841 | * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#animations
|
10842 | * @param {number} animationIndex
|
10843 | * @return {Promise<AnimationClip>}
|
10844 | */
|
10845 |
|
10846 |
|
10847 | GLTFParser.prototype.loadAnimation = function (animationIndex) {
|
10848 | var json = this.json;
|
10849 | var animationDef = json.animations[animationIndex];
|
10850 | var pendingNodes = [];
|
10851 | var pendingInputAccessors = [];
|
10852 | var pendingOutputAccessors = [];
|
10853 | var pendingSamplers = [];
|
10854 | var pendingTargets = [];
|
10855 |
|
10856 | for (var i = 0, il = animationDef.channels.length; i < il; i++) {
|
10857 | var channel = animationDef.channels[i];
|
10858 | var sampler = animationDef.samplers[channel.sampler];
|
10859 | var target = channel.target;
|
10860 | var name = target.node !== undefined ? target.node : target.id; // NOTE: target.id is deprecated.
|
10861 |
|
10862 | var input = animationDef.parameters !== undefined ? animationDef.parameters[sampler.input] : sampler.input;
|
10863 | var output = animationDef.parameters !== undefined ? animationDef.parameters[sampler.output] : sampler.output;
|
10864 | pendingNodes.push(this.getDependency('node', name));
|
10865 | pendingInputAccessors.push(this.getDependency('accessor', input));
|
10866 | pendingOutputAccessors.push(this.getDependency('accessor', output));
|
10867 | pendingSamplers.push(sampler);
|
10868 | pendingTargets.push(target);
|
10869 | }
|
10870 |
|
10871 | return Promise.all([Promise.all(pendingNodes), Promise.all(pendingInputAccessors), Promise.all(pendingOutputAccessors), Promise.all(pendingSamplers), Promise.all(pendingTargets)]).then(function (dependencies) {
|
10872 | var nodes = dependencies[0];
|
10873 | var inputAccessors = dependencies[1];
|
10874 | var outputAccessors = dependencies[2];
|
10875 | var samplers = dependencies[3];
|
10876 | var targets = dependencies[4];
|
10877 | var tracks = [];
|
10878 |
|
10879 | for (var i = 0, il = nodes.length; i < il; i++) {
|
10880 | var node = nodes[i];
|
10881 | var inputAccessor = inputAccessors[i];
|
10882 | var outputAccessor = outputAccessors[i];
|
10883 | var sampler = samplers[i];
|
10884 | var target = targets[i];
|
10885 | if (node === undefined) continue;
|
10886 | node.updateMatrix();
|
10887 | node.matrixAutoUpdate = true;
|
10888 | var TypedKeyframeTrack;
|
10889 |
|
10890 | switch (PATH_PROPERTIES[target.path]) {
|
10891 | case PATH_PROPERTIES.weights:
|
10892 | TypedKeyframeTrack = NumberKeyframeTrack;
|
10893 | break;
|
10894 |
|
10895 | case PATH_PROPERTIES.rotation:
|
10896 | TypedKeyframeTrack = QuaternionKeyframeTrack;
|
10897 | break;
|
10898 |
|
10899 | case PATH_PROPERTIES.position:
|
10900 | case PATH_PROPERTIES.scale:
|
10901 | default:
|
10902 | TypedKeyframeTrack = VectorKeyframeTrack;
|
10903 | break;
|
10904 | }
|
10905 |
|
10906 | var targetName = node.name ? node.name : node.uuid;
|
10907 | var interpolation = sampler.interpolation !== undefined ? INTERPOLATION[sampler.interpolation] : InterpolateLinear;
|
10908 | var targetNames = [];
|
10909 |
|
10910 | if (PATH_PROPERTIES[target.path] === PATH_PROPERTIES.weights) {
|
10911 | // Node may be a Group (glTF mesh with several primitives) or a Mesh.
|
10912 | node.traverse(function (object) {
|
10913 | if (object.isMesh === true && object.morphTargetInfluences) {
|
10914 | targetNames.push(object.name ? object.name : object.uuid);
|
10915 | }
|
10916 | });
|
10917 | } else {
|
10918 | targetNames.push(targetName);
|
10919 | }
|
10920 |
|
10921 | var outputArray = outputAccessor.array;
|
10922 |
|
10923 | if (outputAccessor.normalized) {
|
10924 | var scale;
|
10925 |
|
10926 | if (outputArray.constructor === Int8Array) {
|
10927 | scale = 1 / 127;
|
10928 | } else if (outputArray.constructor === Uint8Array) {
|
10929 | scale = 1 / 255;
|
10930 | } else if (outputArray.constructor == Int16Array) {
|
10931 | scale = 1 / 32767;
|
10932 | } else if (outputArray.constructor === Uint16Array) {
|
10933 | scale = 1 / 65535;
|
10934 | } else {
|
10935 | throw new Error('THREE.GLTFLoader: Unsupported output accessor component type.');
|
10936 | }
|
10937 |
|
10938 | var scaled = new Float32Array(outputArray.length);
|
10939 |
|
10940 | for (var j = 0, jl = outputArray.length; j < jl; j++) {
|
10941 | scaled[j] = outputArray[j] * scale;
|
10942 | }
|
10943 |
|
10944 | outputArray = scaled;
|
10945 | }
|
10946 |
|
10947 | for (var j = 0, jl = targetNames.length; j < jl; j++) {
|
10948 | var track = new TypedKeyframeTrack(targetNames[j] + '.' + PATH_PROPERTIES[target.path], inputAccessor.array, outputArray, interpolation); // Override interpolation with custom factory method.
|
10949 |
|
10950 | if (sampler.interpolation === 'CUBICSPLINE') {
|
10951 | track.createInterpolant = function InterpolantFactoryMethodGLTFCubicSpline(result) {
|
10952 | // A CUBICSPLINE keyframe in glTF has three output values for each input value,
|
10953 | // representing inTangent, splineVertex, and outTangent. As a result, track.getValueSize()
|
10954 | // must be divided by three to get the interpolant's sampleSize argument.
|
10955 | return new GLTFCubicSplineInterpolant(this.times, this.values, this.getValueSize() / 3, result);
|
10956 | }; // Mark as CUBICSPLINE. `track.getInterpolation()` doesn't support custom interpolants.
|
10957 |
|
10958 |
|
10959 | track.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline = true;
|
10960 | }
|
10961 |
|
10962 | tracks.push(track);
|
10963 | }
|
10964 | }
|
10965 |
|
10966 | var name = animationDef.name ? animationDef.name : 'animation_' + animationIndex;
|
10967 | return new AnimationClip(name, undefined, tracks);
|
10968 | });
|
10969 | };
|
10970 | /**
|
10971 | * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#nodes-and-hierarchy
|
10972 | * @param {number} nodeIndex
|
10973 | * @return {Promise<Object3D>}
|
10974 | */
|
10975 |
|
10976 |
|
10977 | GLTFParser.prototype.loadNode = function (nodeIndex) {
|
10978 | var json = this.json;
|
10979 | var extensions = this.extensions;
|
10980 | var parser = this;
|
10981 | var meshReferences = json.meshReferences;
|
10982 | var meshUses = json.meshUses;
|
10983 | var nodeDef = json.nodes[nodeIndex];
|
10984 | return function () {
|
10985 | var pending = [];
|
10986 |
|
10987 | if (nodeDef.mesh !== undefined) {
|
10988 | pending.push(parser.getDependency('mesh', nodeDef.mesh).then(function (mesh) {
|
10989 | var node;
|
10990 |
|
10991 | if (meshReferences[nodeDef.mesh] > 1) {
|
10992 | var instanceNum = meshUses[nodeDef.mesh]++;
|
10993 | node = mesh.clone();
|
10994 | node.name += '_instance_' + instanceNum;
|
10995 | } else {
|
10996 | node = mesh;
|
10997 | } // if weights are provided on the node, override weights on the mesh.
|
10998 |
|
10999 |
|
11000 | if (nodeDef.weights !== undefined) {
|
11001 | node.traverse(function (o) {
|
11002 | if (!o.isMesh) return;
|
11003 |
|
11004 | for (var i = 0, il = nodeDef.weights.length; i < il; i++) {
|
11005 | o.morphTargetInfluences[i] = nodeDef.weights[i];
|
11006 | }
|
11007 | });
|
11008 | }
|
11009 |
|
11010 | return node;
|
11011 | }));
|
11012 | }
|
11013 |
|
11014 | if (nodeDef.camera !== undefined) {
|
11015 | pending.push(parser.getDependency('camera', nodeDef.camera));
|
11016 | }
|
11017 |
|
11018 | if (nodeDef.extensions && nodeDef.extensions[EXTENSIONS.KHR_LIGHTS_PUNCTUAL] && nodeDef.extensions[EXTENSIONS.KHR_LIGHTS_PUNCTUAL].light !== undefined) {
|
11019 | pending.push(parser.getDependency('light', nodeDef.extensions[EXTENSIONS.KHR_LIGHTS_PUNCTUAL].light));
|
11020 | }
|
11021 |
|
11022 | return Promise.all(pending);
|
11023 | }().then(function (objects) {
|
11024 | var node; // .isBone isn't in glTF spec. See .markDefs
|
11025 |
|
11026 | if (nodeDef.isBone === true) {
|
11027 | node = new Bone();
|
11028 | } else if (objects.length > 1) {
|
11029 | node = new Group();
|
11030 | } else if (objects.length === 1) {
|
11031 | node = objects[0];
|
11032 | } else {
|
11033 | node = new Object3D();
|
11034 | }
|
11035 |
|
11036 | if (node !== objects[0]) {
|
11037 | for (var i = 0, il = objects.length; i < il; i++) {
|
11038 | node.add(objects[i]);
|
11039 | }
|
11040 | }
|
11041 |
|
11042 | if (nodeDef.name) {
|
11043 | node.userData.name = nodeDef.name;
|
11044 | node.name = PropertyBinding.sanitizeNodeName(nodeDef.name);
|
11045 | }
|
11046 |
|
11047 | assignExtrasToUserData(node, nodeDef);
|
11048 | if (nodeDef.extensions) addUnknownExtensionsToUserData(extensions, node, nodeDef);
|
11049 |
|
11050 | if (nodeDef.matrix !== undefined) {
|
11051 | var matrix = new Matrix4();
|
11052 | matrix.fromArray(nodeDef.matrix);
|
11053 | node.applyMatrix4(matrix);
|
11054 | } else {
|
11055 | if (nodeDef.translation !== undefined) {
|
11056 | node.position.fromArray(nodeDef.translation);
|
11057 | }
|
11058 |
|
11059 | if (nodeDef.rotation !== undefined) {
|
11060 | node.quaternion.fromArray(nodeDef.rotation);
|
11061 | }
|
11062 |
|
11063 | if (nodeDef.scale !== undefined) {
|
11064 | node.scale.fromArray(nodeDef.scale);
|
11065 | }
|
11066 | }
|
11067 |
|
11068 | return node;
|
11069 | });
|
11070 | };
|
11071 | /**
|
11072 | * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#scenes
|
11073 | * @param {number} sceneIndex
|
11074 | * @return {Promise<Group>}
|
11075 | */
|
11076 |
|
11077 |
|
11078 | GLTFParser.prototype.loadScene = function () {
|
11079 | // scene node hierachy builder
|
11080 | function buildNodeHierachy(nodeId, parentObject, json, parser) {
|
11081 | var nodeDef = json.nodes[nodeId];
|
11082 | return parser.getDependency('node', nodeId).then(function (node) {
|
11083 | if (nodeDef.skin === undefined) return node; // build skeleton here as well
|
11084 |
|
11085 | var skinEntry;
|
11086 | return parser.getDependency('skin', nodeDef.skin).then(function (skin) {
|
11087 | skinEntry = skin;
|
11088 | var pendingJoints = [];
|
11089 |
|
11090 | for (var i = 0, il = skinEntry.joints.length; i < il; i++) {
|
11091 | pendingJoints.push(parser.getDependency('node', skinEntry.joints[i]));
|
11092 | }
|
11093 |
|
11094 | return Promise.all(pendingJoints);
|
11095 | }).then(function (jointNodes) {
|
11096 | node.traverse(function (mesh) {
|
11097 | if (!mesh.isMesh) return;
|
11098 | var bones = [];
|
11099 | var boneInverses = [];
|
11100 |
|
11101 | for (var j = 0, jl = jointNodes.length; j < jl; j++) {
|
11102 | var jointNode = jointNodes[j];
|
11103 |
|
11104 | if (jointNode) {
|
11105 | bones.push(jointNode);
|
11106 | var mat = new Matrix4();
|
11107 |
|
11108 | if (skinEntry.inverseBindMatrices !== undefined) {
|
11109 | mat.fromArray(skinEntry.inverseBindMatrices.array, j * 16);
|
11110 | }
|
11111 |
|
11112 | boneInverses.push(mat);
|
11113 | } else {
|
11114 | console.warn('THREE.GLTFLoader: Joint "%s" could not be found.', skinEntry.joints[j]);
|
11115 | }
|
11116 | }
|
11117 |
|
11118 | mesh.bind(new Skeleton(bones, boneInverses), mesh.matrixWorld);
|
11119 | });
|
11120 | return node;
|
11121 | });
|
11122 | }).then(function (node) {
|
11123 | // build node hierachy
|
11124 | parentObject.add(node);
|
11125 | var pending = [];
|
11126 |
|
11127 | if (nodeDef.children) {
|
11128 | var children = nodeDef.children;
|
11129 |
|
11130 | for (var i = 0, il = children.length; i < il; i++) {
|
11131 | var child = children[i];
|
11132 | pending.push(buildNodeHierachy(child, node, json, parser));
|
11133 | }
|
11134 | }
|
11135 |
|
11136 | return Promise.all(pending);
|
11137 | });
|
11138 | }
|
11139 |
|
11140 | return function loadScene(sceneIndex) {
|
11141 | var json = this.json;
|
11142 | var extensions = this.extensions;
|
11143 | var sceneDef = this.json.scenes[sceneIndex];
|
11144 | var parser = this; // Loader returns Group, not Scene.
|
11145 | // See: https://github.com/mrdoob/three.js/issues/18342#issuecomment-578981172
|
11146 |
|
11147 | var scene = new Group();
|
11148 | if (sceneDef.name) scene.name = sceneDef.name;
|
11149 | assignExtrasToUserData(scene, sceneDef);
|
11150 | if (sceneDef.extensions) addUnknownExtensionsToUserData(extensions, scene, sceneDef);
|
11151 | var nodeIds = sceneDef.nodes || [];
|
11152 | var pending = [];
|
11153 |
|
11154 | for (var i = 0, il = nodeIds.length; i < il; i++) {
|
11155 | pending.push(buildNodeHierachy(nodeIds[i], scene, json, parser));
|
11156 | }
|
11157 |
|
11158 | return Promise.all(pending).then(function () {
|
11159 | return scene;
|
11160 | });
|
11161 | };
|
11162 | }();
|
11163 |
|
11164 | return GLTFLoader;
|
11165 | }();
|
11166 |
|
11167 | /*
|
11168 | * Copyright (c) 2020 NAVER Corp.
|
11169 | * egjs projects are licensed under the MIT license
|
11170 | */
|
11171 | /**
|
11172 | * THREE.DirectionalLight wrapper that will automatically update its shadow size to model
|
11173 | * Shadow is enabled by default, use {@link AutoDirectionalLight#disableShadow disableShadow} to disable it
|
11174 | * @category Environment
|
11175 | */
|
11176 |
|
11177 | var AutoDirectionalLight =
|
11178 | /*#__PURE__*/
|
11179 | function () {
|
11180 | /**
|
11181 | * Create new instance of AutoDirectionalLight
|
11182 | * @param [color="#ffffff"] Color of the light
|
11183 | * @param [intensity=1] Intensity of the light
|
11184 | * @param {object} [options={}] Additional options
|
11185 | * @param {THREE.Vector3} [options.direction=new THREE.Vector3(-1, -1, -1)] Direction of the light
|
11186 | */
|
11187 | function AutoDirectionalLight(color, intensity, _a) {
|
11188 | if (color === void 0) {
|
11189 | color = "#ffffff";
|
11190 | }
|
11191 |
|
11192 | if (intensity === void 0) {
|
11193 | intensity = 1;
|
11194 | }
|
11195 |
|
11196 | var _b = (_a === void 0 ? {} : _a).direction,
|
11197 | direction = _b === void 0 ? new Vector3(-1, -1, -1) : _b;
|
11198 | this._light = new DirectionalLight(color, intensity); // Set the default position ratio of the directional light
|
11199 |
|
11200 | var light = this._light;
|
11201 | light.castShadow = true; // Is enabled by default
|
11202 |
|
11203 | light.shadow.mapSize.width = 2048;
|
11204 | light.shadow.mapSize.height = 2048;
|
11205 | light.matrixAutoUpdate = false;
|
11206 | this._direction = direction.clone().normalize();
|
11207 | }
|
11208 |
|
11209 | var __proto = AutoDirectionalLight.prototype;
|
11210 | Object.defineProperty(__proto, "objects", {
|
11211 | /**
|
11212 | * Array of lights that used in this preset
|
11213 | * @see https://threejs.org/docs/#api/en/lights/Light
|
11214 | */
|
11215 | get: function () {
|
11216 | return [this._light, this._light.target];
|
11217 | },
|
11218 | enumerable: false,
|
11219 | configurable: true
|
11220 | });
|
11221 | Object.defineProperty(__proto, "light", {
|
11222 | /**
|
11223 | * The actual THREE.DirectionalLight
|
11224 | * @type THREE#DirectionalLight
|
11225 | * @see https://threejs.org/docs/#api/en/lights/DirectionalLight
|
11226 | */
|
11227 | get: function () {
|
11228 | return this._light;
|
11229 | },
|
11230 | enumerable: false,
|
11231 | configurable: true
|
11232 | });
|
11233 | Object.defineProperty(__proto, "position", {
|
11234 | /**
|
11235 | * Position of the light
|
11236 | * @type THREE#Vector3
|
11237 | * @see https://threejs.org/docs/#api/en/math/Vector3
|
11238 | */
|
11239 | get: function () {
|
11240 | return this._light.position;
|
11241 | },
|
11242 | enumerable: false,
|
11243 | configurable: true
|
11244 | });
|
11245 | Object.defineProperty(__proto, "direction", {
|
11246 | get: function () {
|
11247 | return this._direction;
|
11248 | },
|
11249 | enumerable: false,
|
11250 | configurable: true
|
11251 | });
|
11252 | /**
|
11253 | * Make light cast a shadow
|
11254 | */
|
11255 |
|
11256 | __proto.enableShadow = function () {
|
11257 | this._light.castShadow = true;
|
11258 | };
|
11259 | /**
|
11260 | * Make light don't cast a shadow
|
11261 | */
|
11262 |
|
11263 |
|
11264 | __proto.disableShadow = function () {
|
11265 | this._light.castShadow = false;
|
11266 | };
|
11267 | /**
|
11268 | * Modify light's position & shadow camera size from model's bounding box
|
11269 | * @param model Model to fit size
|
11270 | * @param scale Scale factor for shadow camera size
|
11271 | */
|
11272 |
|
11273 |
|
11274 | __proto.fit = function (model, _a) {
|
11275 | var _b = (_a === void 0 ? {} : _a).scale,
|
11276 | scale = _b === void 0 ? 1.5 : _b;
|
11277 | var bbox = model.bbox;
|
11278 | var light = this._light;
|
11279 | var direction = this._direction;
|
11280 | var boxSize = bbox.getSize(new Vector3()).length();
|
11281 | var boxCenter = bbox.getCenter(new Vector3()); // Position fitting
|
11282 |
|
11283 | var newPos = new Vector3().addVectors(boxCenter, direction.clone().negate().multiplyScalar(boxSize * 0.5));
|
11284 | light.position.copy(newPos);
|
11285 | light.target.position.copy(boxCenter);
|
11286 | light.updateMatrix(); // Shadowcam fitting
|
11287 |
|
11288 | var shadowCam = light.shadow.camera;
|
11289 | shadowCam.near = 0;
|
11290 | shadowCam.far = 2 * boxSize;
|
11291 | shadowCam.position.copy(newPos);
|
11292 | shadowCam.lookAt(boxCenter);
|
11293 | shadowCam.left = -1;
|
11294 | shadowCam.right = 1;
|
11295 | shadowCam.top = 1;
|
11296 | shadowCam.bottom = -1;
|
11297 | shadowCam.updateMatrixWorld();
|
11298 | shadowCam.updateProjectionMatrix();
|
11299 | var bboxPoints = getBoxPoints(bbox);
|
11300 | var projectedPoints = bboxPoints.map(function (position) {
|
11301 | return position.project(shadowCam);
|
11302 | });
|
11303 | var screenBbox = new Box3().setFromPoints(projectedPoints);
|
11304 | shadowCam.left *= -scale * screenBbox.min.x;
|
11305 | shadowCam.right *= scale * screenBbox.max.x;
|
11306 | shadowCam.top *= scale * screenBbox.max.y;
|
11307 | shadowCam.bottom *= -scale * screenBbox.min.y;
|
11308 | shadowCam.updateProjectionMatrix();
|
11309 | };
|
11310 |
|
11311 | return AutoDirectionalLight;
|
11312 | }();
|
11313 |
|
11314 | /*
|
11315 | * Copyright (c) 2020 NAVER Corp.
|
11316 | * egjs projects are licensed under the MIT license
|
11317 | */
|
11318 | /**
|
11319 | * Helper class to easily add shadow plane under your 3D model
|
11320 | * @category Environment
|
11321 | * @example
|
11322 | * import View3D, { ShadowPlane } from "@egjs/view3d";
|
11323 | *
|
11324 | * const view3d = new View3D("#view3d-canvas");
|
11325 | * const shadowPlane = new ShadowPlane();
|
11326 | * view3d.scene.addEnv(shadowPlane);
|
11327 | */
|
11328 |
|
11329 | var ShadowPlane =
|
11330 | /*#__PURE__*/
|
11331 | function () {
|
11332 | /**
|
11333 | * Create new shadow plane
|
11334 | * @param {object} options Options
|
11335 | * @param {number} [options.size=10000] Size of the shadow plane
|
11336 | * @param {number} [options.opacity=0.3] Opacity of the shadow
|
11337 | */
|
11338 | function ShadowPlane(_a) {
|
11339 | var _b = _a === void 0 ? {} : _a,
|
11340 | _c = _b.size,
|
11341 | size = _c === void 0 ? 10000 : _c,
|
11342 | _d = _b.opacity,
|
11343 | opacity = _d === void 0 ? 0.3 : _d;
|
11344 |
|
11345 | this.geometry = new PlaneGeometry(size, size, 100, 100);
|
11346 | this.material = new ShadowMaterial({
|
11347 | opacity: opacity
|
11348 | });
|
11349 | this.mesh = new Mesh(this.geometry, this.material);
|
11350 | var mesh = this.mesh;
|
11351 | mesh.rotateX(-Math.PI / 2);
|
11352 | mesh.receiveShadow = true;
|
11353 | }
|
11354 |
|
11355 | var __proto = ShadowPlane.prototype;
|
11356 | Object.defineProperty(__proto, "objects", {
|
11357 | get: function () {
|
11358 | return [this.mesh];
|
11359 | },
|
11360 | enumerable: false,
|
11361 | configurable: true
|
11362 | });
|
11363 | Object.defineProperty(__proto, "opacity", {
|
11364 | /**
|
11365 | * Shadow opacity, value can be between 0(invisible) and 1(solid)
|
11366 | * @type number
|
11367 | */
|
11368 | get: function () {
|
11369 | return this.material.opacity;
|
11370 | },
|
11371 | set: function (val) {
|
11372 | this.material.opacity = val;
|
11373 | },
|
11374 | enumerable: false,
|
11375 | configurable: true
|
11376 | });
|
11377 | /**
|
11378 | * Fit shadow plane's size & position to given model
|
11379 | * @param model Model to fit
|
11380 | */
|
11381 |
|
11382 | __proto.fit = function (model, _a) {
|
11383 | var _b = _a === void 0 ? {} : _a,
|
11384 | floorPosition = _b.floorPosition,
|
11385 | _c = _b.floorRotation,
|
11386 | floorRotation = _c === void 0 ? new Quaternion(0, 0, 0, 1) : _c;
|
11387 |
|
11388 | var modelPosition = model.scene.position;
|
11389 | var localYAxis = new Vector3(0, 1, 0).applyQuaternion(floorRotation); // Apply position
|
11390 |
|
11391 | if (floorPosition) {
|
11392 | // Apply a tiny offset to prevent z-fighting with original model
|
11393 | this.mesh.position.copy(floorPosition.clone().add(localYAxis.clone().multiplyScalar(0.001)));
|
11394 | } else {
|
11395 | var modelBbox = model.bbox;
|
11396 | var modelBboxYOffset = modelBbox.getCenter(new Vector3()).y - modelBbox.min.y;
|
11397 | var modelFloor = new Vector3().addVectors(modelPosition, // Apply a tiny offset to prevent z-fighting with original model
|
11398 | localYAxis.multiplyScalar(-modelBboxYOffset + 0.0001));
|
11399 | this.mesh.position.copy(modelFloor);
|
11400 | } // Apply rotation
|
11401 |
|
11402 |
|
11403 | var rotX90 = new Quaternion().setFromEuler(new Euler(-Math.PI / 2, 0, 0));
|
11404 | var shadowRotation = new Quaternion().multiplyQuaternions(floorRotation, rotX90);
|
11405 | this.mesh.quaternion.copy(shadowRotation);
|
11406 | this.mesh.updateMatrix();
|
11407 | };
|
11408 |
|
11409 | return ShadowPlane;
|
11410 | }();
|
11411 |
|
11412 | /*
|
11413 | * Copyright (c) 2020 NAVER Corp.
|
11414 | * egjs projects are licensed under the MIT license
|
11415 | */
|
11416 |
|
11417 | var Environments = {
|
11418 | __proto__: null,
|
11419 | AutoDirectionalLight: AutoDirectionalLight,
|
11420 | ShadowPlane: ShadowPlane
|
11421 | };
|
11422 |
|
11423 | /*
|
11424 | * Copyright (c) 2020 NAVER Corp.
|
11425 | * egjs projects are licensed under the MIT license
|
11426 | */
|
11427 | /**
|
11428 | * GLTFLoader
|
11429 | * @category Loaders
|
11430 | */
|
11431 |
|
11432 | var GLTFLoader$1 =
|
11433 | /*#__PURE__*/
|
11434 | function () {
|
11435 | /**
|
11436 | * Create a new instance of GLTFLoader
|
11437 | */
|
11438 | function GLTFLoader$1() {
|
11439 | this._loader = new GLTFLoader();
|
11440 | this._dracoLoader = new DRACOLoader();
|
11441 | var loader = this._loader;
|
11442 | loader.setCrossOrigin("anonymous");
|
11443 | var dracoLoader = this._dracoLoader;
|
11444 | dracoLoader.setDecoderPath(DRACO_DECODER_URL);
|
11445 | loader.setDRACOLoader(dracoLoader);
|
11446 | }
|
11447 |
|
11448 | var __proto = GLTFLoader$1.prototype;
|
11449 | Object.defineProperty(__proto, "loader", {
|
11450 | get: function () {
|
11451 | return this._loader;
|
11452 | },
|
11453 | enumerable: false,
|
11454 | configurable: true
|
11455 | });
|
11456 | Object.defineProperty(__proto, "dracoLoader", {
|
11457 | get: function () {
|
11458 | return this._dracoLoader;
|
11459 | },
|
11460 | enumerable: false,
|
11461 | configurable: true
|
11462 | });
|
11463 | /**
|
11464 | * Load new GLTF model from the given url
|
11465 | * @param url URL to fetch glTF/glb file
|
11466 | * @param options Options for a loaded model
|
11467 | * @returns Promise that resolves {@link Model}
|
11468 | */
|
11469 |
|
11470 | __proto.load = function (url, options) {
|
11471 | var _this = this;
|
11472 |
|
11473 | if (options === void 0) {
|
11474 | options = {};
|
11475 | }
|
11476 |
|
11477 | var loader = this._loader;
|
11478 | loader.manager = new LoadingManager();
|
11479 | return new Promise(function (resolve, reject) {
|
11480 | loader.load(url, function (gltf) {
|
11481 | var model = _this._parseToModel(gltf, options);
|
11482 |
|
11483 | resolve(model);
|
11484 | }, undefined, function (err) {
|
11485 | reject(err);
|
11486 | });
|
11487 | });
|
11488 | };
|
11489 | /**
|
11490 | * Load preset generated from View3D editor.
|
11491 | * @param viewer Instance of the {@link View3D}.
|
11492 | * @param url Preset url
|
11493 | * @param {object} options Options
|
11494 | * @param {string} [options.path] Base path for additional files.
|
11495 | * @param {function} [options.onLoad] Callback which called after each model LOD is loaded.
|
11496 | * @returns {Model} Model instance with highest LOD
|
11497 | */
|
11498 |
|
11499 |
|
11500 | __proto.loadPreset = function (viewer, url, options) {
|
11501 | var _this = this;
|
11502 |
|
11503 | if (options === void 0) {
|
11504 | options = {};
|
11505 | }
|
11506 |
|
11507 | var loader = this._loader;
|
11508 | var fileLoader = new FileLoader();
|
11509 | return fileLoader.loadAsync(url).then(function (jsonRaw) {
|
11510 | return new Promise(function (resolve, reject) {
|
11511 | var json = JSON.parse(jsonRaw);
|
11512 | var baseURL = LoaderUtils.extractUrlBase(url); // Reset
|
11513 |
|
11514 | viewer.scene.reset();
|
11515 | viewer.camera.reset();
|
11516 | viewer.animator.reset();
|
11517 | var modelOptions = json.model;
|
11518 | var cameraOptions = json.camera;
|
11519 | var environmentOptions = json.env;
|
11520 | viewer.camera.setDefaultPose({
|
11521 | yaw: cameraOptions.yaw,
|
11522 | pitch: cameraOptions.pitch
|
11523 | });
|
11524 | viewer.camera.minDistance = cameraOptions.distanceRange[0];
|
11525 | viewer.camera.maxDistance = cameraOptions.distanceRange[1];
|
11526 |
|
11527 | if (environmentOptions.background) {
|
11528 | viewer.scene.setBackground(new Color(environmentOptions.background));
|
11529 | }
|
11530 |
|
11531 | var shadowPlane = new ShadowPlane();
|
11532 | shadowPlane.opacity = environmentOptions.shadow.opacity;
|
11533 | viewer.scene.addEnv(shadowPlane);
|
11534 | var ambientOptions = environmentOptions.ambient;
|
11535 | var ambient = new AmbientLight(new Color(ambientOptions.color), ambientOptions.intensity);
|
11536 | viewer.scene.addEnv(ambient);
|
11537 | var lightOptions = [environmentOptions.light1, environmentOptions.light2, environmentOptions.light3];
|
11538 | lightOptions.forEach(function (lightOption) {
|
11539 | var lightDirection = new Vector3(lightOption.x, lightOption.y, lightOption.z).negate();
|
11540 | var directional = new AutoDirectionalLight(new Color(lightOption.color), lightOption.intensity, {
|
11541 | direction: lightDirection
|
11542 | });
|
11543 | directional.light.castShadow = lightOption.castShadow;
|
11544 | directional.light.updateMatrixWorld();
|
11545 | viewer.scene.addEnv(directional);
|
11546 | });
|
11547 | var isFirstLoad = true;
|
11548 | var loadFlags = json.LOD.map(function () {
|
11549 | return false;
|
11550 | });
|
11551 | json.LOD.forEach(function (fileName, lodIndex) {
|
11552 | var glbURL = _this._resolveURL("" + baseURL + fileName, options.path || "");
|
11553 |
|
11554 | loader.load(glbURL, function (gltf) {
|
11555 | loadFlags[lodIndex] = true;
|
11556 | var higherLODLoaded = loadFlags.slice(lodIndex + 1).some(function (loaded) {
|
11557 | return loaded;
|
11558 | });
|
11559 | if (higherLODLoaded) return;
|
11560 |
|
11561 | var model = _this._parseToModel(gltf);
|
11562 |
|
11563 | viewer.display(model, {
|
11564 | size: modelOptions.size,
|
11565 | resetView: isFirstLoad
|
11566 | });
|
11567 | isFirstLoad = false;
|
11568 | model.castShadow = modelOptions.castShadow;
|
11569 | model.receiveShadow = modelOptions.receiveShadow;
|
11570 |
|
11571 | if (options.onLoad) {
|
11572 | options.onLoad(model, lodIndex);
|
11573 | }
|
11574 |
|
11575 | if (lodIndex === json.LOD.length - 1) {
|
11576 | resolve(model);
|
11577 | }
|
11578 | }, undefined, function (err) {
|
11579 | reject(err);
|
11580 | });
|
11581 | });
|
11582 | });
|
11583 | });
|
11584 | };
|
11585 | /**
|
11586 | * Load new GLTF model from the given files
|
11587 | * @param files Files that has glTF/glb and all its associated resources like textures and .bin data files
|
11588 | * @param options Options for a loaded model
|
11589 | * @returns Promise that resolves {@link Model}
|
11590 | */
|
11591 |
|
11592 |
|
11593 | __proto.loadFromFiles = function (files, options) {
|
11594 | var _this = this;
|
11595 |
|
11596 | if (options === void 0) {
|
11597 | options = {};
|
11598 | }
|
11599 |
|
11600 | var objectURLs = [];
|
11601 |
|
11602 | var revokeURLs = function () {
|
11603 | objectURLs.forEach(function (url) {
|
11604 | URL.revokeObjectURL(url);
|
11605 | });
|
11606 | };
|
11607 |
|
11608 | return new Promise(function (resolve, reject) {
|
11609 | if (files.length <= 0) {
|
11610 | reject(new Error("No files found"));
|
11611 | return;
|
11612 | }
|
11613 |
|
11614 | var gltfFile = files.find(function (file) {
|
11615 | return /\.(gltf|glb)$/i.test(file.name);
|
11616 | });
|
11617 |
|
11618 | if (!gltfFile) {
|
11619 | reject(new Error("No glTF file found"));
|
11620 | return;
|
11621 | }
|
11622 |
|
11623 | var filesMap = new Map();
|
11624 | files.forEach(function (file) {
|
11625 | filesMap.set(file.name, file);
|
11626 | });
|
11627 | var gltfURL = URL.createObjectURL(gltfFile);
|
11628 | objectURLs.push(gltfURL);
|
11629 | var manager = new LoadingManager();
|
11630 | manager.setURLModifier(function (fileURL) {
|
11631 | var fileNameResult = /[^\/|\\]+$/.exec(fileURL);
|
11632 | var fileName = fileNameResult && fileNameResult[0] || "";
|
11633 |
|
11634 | if (filesMap.has(fileName)) {
|
11635 | var blob = filesMap.get(fileName);
|
11636 | var blobURL = URL.createObjectURL(blob);
|
11637 | objectURLs.push(blobURL);
|
11638 | return blobURL;
|
11639 | }
|
11640 |
|
11641 | return fileURL;
|
11642 | });
|
11643 | var loader = _this._loader;
|
11644 | loader.manager = manager;
|
11645 | loader.load(gltfURL, function (gltf) {
|
11646 | var model = _this._parseToModel(gltf, options);
|
11647 |
|
11648 | resolve(model);
|
11649 | revokeURLs();
|
11650 | }, undefined, function (err) {
|
11651 | reject(err);
|
11652 | revokeURLs();
|
11653 | });
|
11654 | });
|
11655 | };
|
11656 | /**
|
11657 | * Parse from array buffer
|
11658 | * @param data glTF asset to parse, as an ArrayBuffer or JSON string.
|
11659 | * @param path The base path from which to find subsequent glTF resources such as textures and .bin data files.
|
11660 | * @param options Options for a loaded model
|
11661 | * @returns Promise that resolves {@link Model}
|
11662 | */
|
11663 |
|
11664 |
|
11665 | __proto.parse = function (data, path, options) {
|
11666 | var _this = this;
|
11667 |
|
11668 | if (options === void 0) {
|
11669 | options = {};
|
11670 | }
|
11671 |
|
11672 | var loader = this._loader;
|
11673 | loader.manager = new LoadingManager();
|
11674 | return new Promise(function (resolve, reject) {
|
11675 | loader.parse(data, path, function (gltf) {
|
11676 | var model = _this._parseToModel(gltf, options);
|
11677 |
|
11678 | resolve(model);
|
11679 | }, function (err) {
|
11680 | reject(err);
|
11681 | });
|
11682 | });
|
11683 | };
|
11684 |
|
11685 | __proto._parseToModel = function (gltf, _a) {
|
11686 | var _b = (_a === void 0 ? {} : _a).fixSkinnedBbox,
|
11687 | fixSkinnedBbox = _b === void 0 ? false : _b;
|
11688 | var model = new Model({
|
11689 | scenes: gltf.scenes,
|
11690 | animations: gltf.animations,
|
11691 | fixSkinnedBbox: fixSkinnedBbox
|
11692 | });
|
11693 | model.meshes.forEach(function (mesh) {
|
11694 | var materials = Array.isArray(mesh.material) ? mesh.material : [mesh.material];
|
11695 | materials.forEach(function (mat) {
|
11696 | if (mat.map) {
|
11697 | mat.map.encoding = sRGBEncoding;
|
11698 | }
|
11699 | });
|
11700 | });
|
11701 | return model;
|
11702 | }; // Grabbed from three.js/GLTFLoader
|
11703 | // Original code: https://github.com/mrdoob/three.js/blob/master/examples/jsm/loaders/GLTFLoader.js#L1221
|
11704 | // License: MIT
|
11705 |
|
11706 |
|
11707 | __proto._resolveURL = function (url, path) {
|
11708 | // Invalid URL
|
11709 | if (typeof url !== "string" || url === "") return ""; // Host Relative URL
|
11710 |
|
11711 | if (/^https?:\/\//i.test(path) && /^\//.test(url)) {
|
11712 | path = path.replace(/(^https?:\/\/[^\/]+).*/i, "$1");
|
11713 | } // Absolute URL http://,https://,//
|
11714 |
|
11715 |
|
11716 | if (/^(https?:)?\/\//i.test(url)) return url; // Data URI
|
11717 |
|
11718 | if (/^data:.*,.*$/i.test(url)) return url; // Blob URL
|
11719 |
|
11720 | if (/^blob:.*$/i.test(url)) return url; // Relative URL
|
11721 |
|
11722 | return path + url;
|
11723 | };
|
11724 |
|
11725 | return GLTFLoader$1;
|
11726 | }();
|
11727 |
|
11728 | // http://en.wikipedia.org/wiki/RGBE_image_format
|
11729 |
|
11730 | var RGBELoader = function RGBELoader(manager) {
|
11731 | DataTextureLoader.call(this, manager);
|
11732 | this.type = UnsignedByteType;
|
11733 | };
|
11734 |
|
11735 | RGBELoader.prototype = _extends(Object.create(DataTextureLoader.prototype), {
|
11736 | constructor: RGBELoader,
|
11737 | // adapted from http://www.graphics.cornell.edu/~bjw/rgbe.html
|
11738 | parse: function parse(buffer) {
|
11739 | var
|
11740 | /* return codes for rgbe routines */
|
11741 | //RGBE_RETURN_SUCCESS = 0,
|
11742 | RGBE_RETURN_FAILURE = -1,
|
11743 |
|
11744 | /* default error routine. change this to change error handling */
|
11745 | rgbe_read_error = 1,
|
11746 | rgbe_write_error = 2,
|
11747 | rgbe_format_error = 3,
|
11748 | rgbe_memory_error = 4,
|
11749 | rgbe_error = function rgbe_error(rgbe_error_code, msg) {
|
11750 | switch (rgbe_error_code) {
|
11751 | case rgbe_read_error:
|
11752 | console.error("RGBELoader Read Error: " + (msg || ''));
|
11753 | break;
|
11754 |
|
11755 | case rgbe_write_error:
|
11756 | console.error("RGBELoader Write Error: " + (msg || ''));
|
11757 | break;
|
11758 |
|
11759 | case rgbe_format_error:
|
11760 | console.error("RGBELoader Bad File Format: " + (msg || ''));
|
11761 | break;
|
11762 |
|
11763 | default:
|
11764 | case rgbe_memory_error:
|
11765 | console.error("RGBELoader: Error: " + (msg || ''));
|
11766 | }
|
11767 |
|
11768 | return RGBE_RETURN_FAILURE;
|
11769 | },
|
11770 |
|
11771 | /* offsets to red, green, and blue components in a data (float) pixel */
|
11772 | //RGBE_DATA_RED = 0,
|
11773 | //RGBE_DATA_GREEN = 1,
|
11774 | //RGBE_DATA_BLUE = 2,
|
11775 |
|
11776 | /* number of floats per pixel, use 4 since stored in rgba image format */
|
11777 | //RGBE_DATA_SIZE = 4,
|
11778 |
|
11779 | /* flags indicating which fields in an rgbe_header_info are valid */
|
11780 | RGBE_VALID_PROGRAMTYPE = 1,
|
11781 | RGBE_VALID_FORMAT = 2,
|
11782 | RGBE_VALID_DIMENSIONS = 4,
|
11783 | NEWLINE = "\n",
|
11784 | fgets = function fgets(buffer, lineLimit, consume) {
|
11785 | lineLimit = !lineLimit ? 1024 : lineLimit;
|
11786 | var p = buffer.pos,
|
11787 | i = -1,
|
11788 | len = 0,
|
11789 | s = '',
|
11790 | chunkSize = 128,
|
11791 | chunk = String.fromCharCode.apply(null, new Uint16Array(buffer.subarray(p, p + chunkSize)));
|
11792 |
|
11793 | while (0 > (i = chunk.indexOf(NEWLINE)) && len < lineLimit && p < buffer.byteLength) {
|
11794 | s += chunk;
|
11795 | len += chunk.length;
|
11796 | p += chunkSize;
|
11797 | chunk += String.fromCharCode.apply(null, new Uint16Array(buffer.subarray(p, p + chunkSize)));
|
11798 | }
|
11799 |
|
11800 | if (-1 < i) {
|
11801 | /*for (i=l-1; i>=0; i--) {
|
11802 | byteCode = m.charCodeAt(i);
|
11803 | if (byteCode > 0x7f && byteCode <= 0x7ff) byteLen++;
|
11804 | else if (byteCode > 0x7ff && byteCode <= 0xffff) byteLen += 2;
|
11805 | if (byteCode >= 0xDC00 && byteCode <= 0xDFFF) i--; //trail surrogate
|
11806 | }*/
|
11807 | if (false !== consume) buffer.pos += len + i + 1;
|
11808 | return s + chunk.slice(0, i);
|
11809 | }
|
11810 |
|
11811 | return false;
|
11812 | },
|
11813 |
|
11814 | /* minimal header reading. modify if you want to parse more information */
|
11815 | RGBE_ReadHeader = function RGBE_ReadHeader(buffer) {
|
11816 | var line,
|
11817 | match,
|
11818 | // regexes to parse header info fields
|
11819 | magic_token_re = /^#\?(\S+)$/,
|
11820 | gamma_re = /^\s*GAMMA\s*=\s*(\d+(\.\d+)?)\s*$/,
|
11821 | exposure_re = /^\s*EXPOSURE\s*=\s*(\d+(\.\d+)?)\s*$/,
|
11822 | format_re = /^\s*FORMAT=(\S+)\s*$/,
|
11823 | dimensions_re = /^\s*\-Y\s+(\d+)\s+\+X\s+(\d+)\s*$/,
|
11824 | // RGBE format header struct
|
11825 | header = {
|
11826 | valid: 0,
|
11827 |
|
11828 | /* indicate which fields are valid */
|
11829 | string: '',
|
11830 |
|
11831 | /* the actual header string */
|
11832 | comments: '',
|
11833 |
|
11834 | /* comments found in header */
|
11835 | programtype: 'RGBE',
|
11836 |
|
11837 | /* listed at beginning of file to identify it after "#?". defaults to "RGBE" */
|
11838 | format: '',
|
11839 |
|
11840 | /* RGBE format, default 32-bit_rle_rgbe */
|
11841 | gamma: 1.0,
|
11842 |
|
11843 | /* image has already been gamma corrected with given gamma. defaults to 1.0 (no correction) */
|
11844 | exposure: 1.0,
|
11845 |
|
11846 | /* a value of 1.0 in an image corresponds to <exposure> watts/steradian/m^2. defaults to 1.0 */
|
11847 | width: 0,
|
11848 | height: 0
|
11849 | /* image dimensions, width/height */
|
11850 |
|
11851 | };
|
11852 |
|
11853 | if (buffer.pos >= buffer.byteLength || !(line = fgets(buffer))) {
|
11854 | return rgbe_error(rgbe_read_error, "no header found");
|
11855 | }
|
11856 | /* if you want to require the magic token then uncomment the next line */
|
11857 |
|
11858 |
|
11859 | if (!(match = line.match(magic_token_re))) {
|
11860 | return rgbe_error(rgbe_format_error, "bad initial token");
|
11861 | }
|
11862 |
|
11863 | header.valid |= RGBE_VALID_PROGRAMTYPE;
|
11864 | header.programtype = match[1];
|
11865 | header.string += line + "\n";
|
11866 |
|
11867 | while (true) {
|
11868 | line = fgets(buffer);
|
11869 | if (false === line) break;
|
11870 | header.string += line + "\n";
|
11871 |
|
11872 | if ('#' === line.charAt(0)) {
|
11873 | header.comments += line + "\n";
|
11874 | continue; // comment line
|
11875 | }
|
11876 |
|
11877 | if (match = line.match(gamma_re)) {
|
11878 | header.gamma = parseFloat(match[1], 10);
|
11879 | }
|
11880 |
|
11881 | if (match = line.match(exposure_re)) {
|
11882 | header.exposure = parseFloat(match[1], 10);
|
11883 | }
|
11884 |
|
11885 | if (match = line.match(format_re)) {
|
11886 | header.valid |= RGBE_VALID_FORMAT;
|
11887 | header.format = match[1]; //'32-bit_rle_rgbe';
|
11888 | }
|
11889 |
|
11890 | if (match = line.match(dimensions_re)) {
|
11891 | header.valid |= RGBE_VALID_DIMENSIONS;
|
11892 | header.height = parseInt(match[1], 10);
|
11893 | header.width = parseInt(match[2], 10);
|
11894 | }
|
11895 |
|
11896 | if (header.valid & RGBE_VALID_FORMAT && header.valid & RGBE_VALID_DIMENSIONS) break;
|
11897 | }
|
11898 |
|
11899 | if (!(header.valid & RGBE_VALID_FORMAT)) {
|
11900 | return rgbe_error(rgbe_format_error, "missing format specifier");
|
11901 | }
|
11902 |
|
11903 | if (!(header.valid & RGBE_VALID_DIMENSIONS)) {
|
11904 | return rgbe_error(rgbe_format_error, "missing image size specifier");
|
11905 | }
|
11906 |
|
11907 | return header;
|
11908 | },
|
11909 | RGBE_ReadPixels_RLE = function RGBE_ReadPixels_RLE(buffer, w, h) {
|
11910 | var data_rgba,
|
11911 | offset,
|
11912 | pos,
|
11913 | count,
|
11914 | byteValue,
|
11915 | scanline_buffer,
|
11916 | ptr,
|
11917 | ptr_end,
|
11918 | i,
|
11919 | l,
|
11920 | off,
|
11921 | isEncodedRun,
|
11922 | scanline_width = w,
|
11923 | num_scanlines = h,
|
11924 | rgbeStart;
|
11925 |
|
11926 | if ( // run length encoding is not allowed so read flat
|
11927 | scanline_width < 8 || scanline_width > 0x7fff || // this file is not run length encoded
|
11928 | 2 !== buffer[0] || 2 !== buffer[1] || buffer[2] & 0x80) {
|
11929 | // return the flat buffer
|
11930 | return new Uint8Array(buffer);
|
11931 | }
|
11932 |
|
11933 | if (scanline_width !== (buffer[2] << 8 | buffer[3])) {
|
11934 | return rgbe_error(rgbe_format_error, "wrong scanline width");
|
11935 | }
|
11936 |
|
11937 | data_rgba = new Uint8Array(4 * w * h);
|
11938 |
|
11939 | if (!data_rgba.length) {
|
11940 | return rgbe_error(rgbe_memory_error, "unable to allocate buffer space");
|
11941 | }
|
11942 |
|
11943 | offset = 0;
|
11944 | pos = 0;
|
11945 | ptr_end = 4 * scanline_width;
|
11946 | rgbeStart = new Uint8Array(4);
|
11947 | scanline_buffer = new Uint8Array(ptr_end); // read in each successive scanline
|
11948 |
|
11949 | while (num_scanlines > 0 && pos < buffer.byteLength) {
|
11950 | if (pos + 4 > buffer.byteLength) {
|
11951 | return rgbe_error(rgbe_read_error);
|
11952 | }
|
11953 |
|
11954 | rgbeStart[0] = buffer[pos++];
|
11955 | rgbeStart[1] = buffer[pos++];
|
11956 | rgbeStart[2] = buffer[pos++];
|
11957 | rgbeStart[3] = buffer[pos++];
|
11958 |
|
11959 | if (2 != rgbeStart[0] || 2 != rgbeStart[1] || (rgbeStart[2] << 8 | rgbeStart[3]) != scanline_width) {
|
11960 | return rgbe_error(rgbe_format_error, "bad rgbe scanline format");
|
11961 | } // read each of the four channels for the scanline into the buffer
|
11962 | // first red, then green, then blue, then exponent
|
11963 |
|
11964 |
|
11965 | ptr = 0;
|
11966 |
|
11967 | while (ptr < ptr_end && pos < buffer.byteLength) {
|
11968 | count = buffer[pos++];
|
11969 | isEncodedRun = count > 128;
|
11970 | if (isEncodedRun) count -= 128;
|
11971 |
|
11972 | if (0 === count || ptr + count > ptr_end) {
|
11973 | return rgbe_error(rgbe_format_error, "bad scanline data");
|
11974 | }
|
11975 |
|
11976 | if (isEncodedRun) {
|
11977 | // a (encoded) run of the same value
|
11978 | byteValue = buffer[pos++];
|
11979 |
|
11980 | for (i = 0; i < count; i++) {
|
11981 | scanline_buffer[ptr++] = byteValue;
|
11982 | } //ptr += count;
|
11983 |
|
11984 | } else {
|
11985 | // a literal-run
|
11986 | scanline_buffer.set(buffer.subarray(pos, pos + count), ptr);
|
11987 | ptr += count;
|
11988 | pos += count;
|
11989 | }
|
11990 | } // now convert data from buffer into rgba
|
11991 | // first red, then green, then blue, then exponent (alpha)
|
11992 |
|
11993 |
|
11994 | l = scanline_width; //scanline_buffer.byteLength;
|
11995 |
|
11996 | for (i = 0; i < l; i++) {
|
11997 | off = 0;
|
11998 | data_rgba[offset] = scanline_buffer[i + off];
|
11999 | off += scanline_width; //1;
|
12000 |
|
12001 | data_rgba[offset + 1] = scanline_buffer[i + off];
|
12002 | off += scanline_width; //1;
|
12003 |
|
12004 | data_rgba[offset + 2] = scanline_buffer[i + off];
|
12005 | off += scanline_width; //1;
|
12006 |
|
12007 | data_rgba[offset + 3] = scanline_buffer[i + off];
|
12008 | offset += 4;
|
12009 | }
|
12010 |
|
12011 | num_scanlines--;
|
12012 | }
|
12013 |
|
12014 | return data_rgba;
|
12015 | };
|
12016 |
|
12017 | var RGBEByteToRGBFloat = function RGBEByteToRGBFloat(sourceArray, sourceOffset, destArray, destOffset) {
|
12018 | var e = sourceArray[sourceOffset + 3];
|
12019 | var scale = Math.pow(2.0, e - 128.0) / 255.0;
|
12020 | destArray[destOffset + 0] = sourceArray[sourceOffset + 0] * scale;
|
12021 | destArray[destOffset + 1] = sourceArray[sourceOffset + 1] * scale;
|
12022 | destArray[destOffset + 2] = sourceArray[sourceOffset + 2] * scale;
|
12023 | };
|
12024 |
|
12025 | var RGBEByteToRGBHalf = function () {
|
12026 | // Source: http://gamedev.stackexchange.com/questions/17326/conversion-of-a-number-from-single-precision-floating-point-representation-to-a/17410#17410
|
12027 | var floatView = new Float32Array(1);
|
12028 | var int32View = new Int32Array(floatView.buffer);
|
12029 | /* This method is faster than the OpenEXR implementation (very often
|
12030 | * used, eg. in Ogre), with the additional benefit of rounding, inspired
|
12031 | * by James Tursa?s half-precision code. */
|
12032 |
|
12033 | function toHalf(val) {
|
12034 | floatView[0] = val;
|
12035 | var x = int32View[0];
|
12036 | var bits = x >> 16 & 0x8000;
|
12037 | /* Get the sign */
|
12038 |
|
12039 | var m = x >> 12 & 0x07ff;
|
12040 | /* Keep one extra bit for rounding */
|
12041 |
|
12042 | var e = x >> 23 & 0xff;
|
12043 | /* Using int is faster here */
|
12044 |
|
12045 | /* If zero, or denormal, or exponent underflows too much for a denormal
|
12046 | * half, return signed zero. */
|
12047 |
|
12048 | if (e < 103) return bits;
|
12049 | /* If NaN, return NaN. If Inf or exponent overflow, return Inf. */
|
12050 |
|
12051 | if (e > 142) {
|
12052 | bits |= 0x7c00;
|
12053 | /* If exponent was 0xff and one mantissa bit was set, it means NaN,
|
12054 | * not Inf, so make sure we set one mantissa bit too. */
|
12055 |
|
12056 | bits |= (e == 255 ? 0 : 1) && x & 0x007fffff;
|
12057 | return bits;
|
12058 | }
|
12059 | /* If exponent underflows but not too much, return a denormal */
|
12060 |
|
12061 |
|
12062 | if (e < 113) {
|
12063 | m |= 0x0800;
|
12064 | /* Extra rounding may overflow and set mantissa to 0 and exponent
|
12065 | * to 1, which is OK. */
|
12066 |
|
12067 | bits |= (m >> 114 - e) + (m >> 113 - e & 1);
|
12068 | return bits;
|
12069 | }
|
12070 |
|
12071 | bits |= e - 112 << 10 | m >> 1;
|
12072 | /* Extra rounding. An overflow will set mantissa to 0 and increment
|
12073 | * the exponent, which is OK. */
|
12074 |
|
12075 | bits += m & 1;
|
12076 | return bits;
|
12077 | }
|
12078 |
|
12079 | return function (sourceArray, sourceOffset, destArray, destOffset) {
|
12080 | var e = sourceArray[sourceOffset + 3];
|
12081 | var scale = Math.pow(2.0, e - 128.0) / 255.0;
|
12082 | destArray[destOffset + 0] = toHalf(sourceArray[sourceOffset + 0] * scale);
|
12083 | destArray[destOffset + 1] = toHalf(sourceArray[sourceOffset + 1] * scale);
|
12084 | destArray[destOffset + 2] = toHalf(sourceArray[sourceOffset + 2] * scale);
|
12085 | };
|
12086 | }();
|
12087 |
|
12088 | var byteArray = new Uint8Array(buffer);
|
12089 | byteArray.pos = 0;
|
12090 | var rgbe_header_info = RGBE_ReadHeader(byteArray);
|
12091 |
|
12092 | if (RGBE_RETURN_FAILURE !== rgbe_header_info) {
|
12093 | var w = rgbe_header_info.width,
|
12094 | h = rgbe_header_info.height,
|
12095 | image_rgba_data = RGBE_ReadPixels_RLE(byteArray.subarray(byteArray.pos), w, h);
|
12096 |
|
12097 | if (RGBE_RETURN_FAILURE !== image_rgba_data) {
|
12098 | switch (this.type) {
|
12099 | case UnsignedByteType:
|
12100 | var data = image_rgba_data;
|
12101 | var format = RGBEFormat; // handled as THREE.RGBAFormat in shaders
|
12102 |
|
12103 | var type = UnsignedByteType;
|
12104 | break;
|
12105 |
|
12106 | case FloatType:
|
12107 | var numElements = image_rgba_data.length / 4 * 3;
|
12108 | var floatArray = new Float32Array(numElements);
|
12109 |
|
12110 | for (var j = 0; j < numElements; j++) {
|
12111 | RGBEByteToRGBFloat(image_rgba_data, j * 4, floatArray, j * 3);
|
12112 | }
|
12113 |
|
12114 | var data = floatArray;
|
12115 | var format = RGBFormat;
|
12116 | var type = FloatType;
|
12117 | break;
|
12118 |
|
12119 | case HalfFloatType:
|
12120 | var numElements = image_rgba_data.length / 4 * 3;
|
12121 | var halfArray = new Uint16Array(numElements);
|
12122 |
|
12123 | for (var j = 0; j < numElements; j++) {
|
12124 | RGBEByteToRGBHalf(image_rgba_data, j * 4, halfArray, j * 3);
|
12125 | }
|
12126 |
|
12127 | var data = halfArray;
|
12128 | var format = RGBFormat;
|
12129 | var type = HalfFloatType;
|
12130 | break;
|
12131 |
|
12132 | default:
|
12133 | console.error('THREE.RGBELoader: unsupported type: ', this.type);
|
12134 | break;
|
12135 | }
|
12136 |
|
12137 | return {
|
12138 | width: w,
|
12139 | height: h,
|
12140 | data: data,
|
12141 | header: rgbe_header_info.string,
|
12142 | gamma: rgbe_header_info.gamma,
|
12143 | exposure: rgbe_header_info.exposure,
|
12144 | format: format,
|
12145 | type: type
|
12146 | };
|
12147 | }
|
12148 | }
|
12149 |
|
12150 | return null;
|
12151 | },
|
12152 | setDataType: function setDataType(value) {
|
12153 | this.type = value;
|
12154 | return this;
|
12155 | },
|
12156 | load: function load(url, onLoad, onProgress, onError) {
|
12157 | function onLoadCallback(texture, texData) {
|
12158 | switch (texture.type) {
|
12159 | case UnsignedByteType:
|
12160 | texture.encoding = RGBEEncoding;
|
12161 | texture.minFilter = NearestFilter;
|
12162 | texture.magFilter = NearestFilter;
|
12163 | texture.generateMipmaps = false;
|
12164 | texture.flipY = true;
|
12165 | break;
|
12166 |
|
12167 | case FloatType:
|
12168 | texture.encoding = LinearEncoding;
|
12169 | texture.minFilter = LinearFilter;
|
12170 | texture.magFilter = LinearFilter;
|
12171 | texture.generateMipmaps = false;
|
12172 | texture.flipY = true;
|
12173 | break;
|
12174 |
|
12175 | case HalfFloatType:
|
12176 | texture.encoding = LinearEncoding;
|
12177 | texture.minFilter = LinearFilter;
|
12178 | texture.magFilter = LinearFilter;
|
12179 | texture.generateMipmaps = false;
|
12180 | texture.flipY = true;
|
12181 | break;
|
12182 | }
|
12183 |
|
12184 | if (onLoad) onLoad(texture, texData);
|
12185 | }
|
12186 |
|
12187 | return DataTextureLoader.prototype.load.call(this, url, onLoadCallback, onProgress, onError);
|
12188 | }
|
12189 | });
|
12190 |
|
12191 | /*
|
12192 | * Copyright (c) 2020 NAVER Corp.
|
12193 | * egjs projects are licensed under the MIT license
|
12194 | */
|
12195 | /**
|
12196 | * Texture loader
|
12197 | * @category Loaders
|
12198 | */
|
12199 |
|
12200 | var TextureLoader$1 =
|
12201 | /*#__PURE__*/
|
12202 | function () {
|
12203 | /**
|
12204 | * Create new TextureLoader instance
|
12205 | * @param renderer {@link Renderer} instance of View3D
|
12206 | */
|
12207 | function TextureLoader$1(renderer) {
|
12208 | this._renderer = renderer;
|
12209 | }
|
12210 | /**
|
12211 | * Create new {@link https://threejs.org/docs/index.html#api/en/textures/Texture Texture} with given url
|
12212 | * Texture's {@link https://threejs.org/docs/index.html#api/en/textures/Texture.flipY flipY} property is `true` by Three.js's policy, so be careful when using it as a map texture.
|
12213 | * @param url url to fetch image
|
12214 | */
|
12215 |
|
12216 |
|
12217 | var __proto = TextureLoader$1.prototype;
|
12218 |
|
12219 | __proto.load = function (url) {
|
12220 | return new Promise(function (resolve, reject) {
|
12221 | var loader = new TextureLoader();
|
12222 | loader.load(url, resolve, undefined, reject);
|
12223 | });
|
12224 | };
|
12225 | /**
|
12226 | * Create new {@link https://threejs.org/docs/#api/en/renderers/WebGLCubeRenderTarget WebGLCubeRenderTarget} with given equirectangular image url
|
12227 | * Be sure that equirectangular image has height of power of 2, as it will be resized if it isn't
|
12228 | * @param url url to fetch equirectangular image
|
12229 | * @returns WebGLCubeRenderTarget created
|
12230 | */
|
12231 |
|
12232 |
|
12233 | __proto.loadEquirectagularTexture = function (url) {
|
12234 | var _this = this;
|
12235 |
|
12236 | return new Promise(function (resolve, reject) {
|
12237 | var loader = new TextureLoader();
|
12238 | loader.load(url, function (skyboxTexture) {
|
12239 | resolve(_this._equirectToCubemap(skyboxTexture));
|
12240 | }, undefined, reject);
|
12241 | });
|
12242 | };
|
12243 | /**
|
12244 | * Create new {@link https://threejs.org/docs/#api/en/textures/CubeTexture CubeTexture} with given cubemap image urls
|
12245 | * Image order should be: px, nx, py, ny, pz, nz
|
12246 | * @param urls cubemap image urls
|
12247 | * @returns CubeTexture created
|
12248 | */
|
12249 |
|
12250 |
|
12251 | __proto.loadCubeTexture = function (urls) {
|
12252 | return new Promise(function (resolve, reject) {
|
12253 | var loader = new CubeTextureLoader();
|
12254 | loader.load(urls, resolve, undefined, reject);
|
12255 | });
|
12256 | };
|
12257 | /**
|
12258 | * Create new texture with given HDR(RGBE) image url
|
12259 | * @param url image url
|
12260 | * @param isEquirectangular Whether to read this image as a equirectangular texture
|
12261 | */
|
12262 |
|
12263 |
|
12264 | __proto.loadHDRTexture = function (url, isEquirectangular) {
|
12265 | var _this = this;
|
12266 |
|
12267 | if (isEquirectangular === void 0) {
|
12268 | isEquirectangular = true;
|
12269 | }
|
12270 |
|
12271 | return new Promise(function (resolve, reject) {
|
12272 | var loader = new RGBELoader();
|
12273 | loader.load(url, function (texture) {
|
12274 | if (isEquirectangular) {
|
12275 | resolve(_this._equirectToCubemap(texture));
|
12276 | } else {
|
12277 | resolve(texture);
|
12278 | }
|
12279 | }, undefined, reject);
|
12280 | });
|
12281 | };
|
12282 |
|
12283 | __proto._equirectToCubemap = function (texture) {
|
12284 | return new WebGLCubeRenderTarget(texture.image.height).fromEquirectangularTexture(this._renderer.threeRenderer, texture);
|
12285 | };
|
12286 |
|
12287 | return TextureLoader$1;
|
12288 | }();
|
12289 |
|
12290 | /*
|
12291 | * Copyright (c) 2020 NAVER Corp.
|
12292 | * egjs projects are licensed under the MIT license
|
12293 | */
|
12294 |
|
12295 | var Loaders = {
|
12296 | __proto__: null,
|
12297 | GLTFLoader: GLTFLoader$1,
|
12298 | DracoLoader: DracoLoader,
|
12299 | TextureLoader: TextureLoader$1
|
12300 | };
|
12301 |
|
12302 | /*
|
12303 | * Copyright (c) 2020 NAVER Corp.
|
12304 | * egjs projects are licensed under the MIT license
|
12305 | */
|
12306 | var QUICKLOOK_SUPPORTED = function () {
|
12307 | var anchorEl = document.createElement("a");
|
12308 | return anchorEl.relList && anchorEl.relList.supports && anchorEl.relList.supports("ar");
|
12309 | }();
|
12310 | var WEBXR_SUPPORTED = navigator.xr && navigator.xr.isSessionSupported;
|
12311 | var HIT_TEST_SUPPORTED = window.XRSession && window.XRSession.prototype.requestHitTestSource;
|
12312 | var DOM_OVERLAY_SUPPORTED = window.XRDOMOverlayState != null;
|
12313 | var SESSION = {
|
12314 | AR: "immersive-ar",
|
12315 | VR: "immersive-ar"
|
12316 | };
|
12317 | var REFERENCE_SPACE = {
|
12318 | LOCAL: "local",
|
12319 | LOCAL_FLOOR: "local-floor",
|
12320 | VIEWER: "viewer"
|
12321 | };
|
12322 | var EVENTS$1 = {
|
12323 | SELECT_START: "selectstart",
|
12324 | SELECT: "select",
|
12325 | SELECT_END: "selectend"
|
12326 | };
|
12327 | var INPUT_PROFILE = {
|
12328 | TOUCH: "generic-touchscreen"
|
12329 | };
|
12330 | var FEATURES = {
|
12331 | HIT_TEST: {
|
12332 | requiredFeatures: ["hit-test"]
|
12333 | },
|
12334 | DOM_OVERLAY: function (root) {
|
12335 | return {
|
12336 | optionalFeatures: ["dom-overlay"],
|
12337 | domOverlay: {
|
12338 | root: root
|
12339 | }
|
12340 | };
|
12341 | }
|
12342 | }; // For type definition
|
12343 |
|
12344 | var EMPTY_FEATURES = {};
|
12345 | var SCENE_VIEWER = {
|
12346 | INTENT_AR_CORE: function (params, fallback) {
|
12347 | return "intent://arvr.google.com/scene-viewer/1.1?" + params + "#Intent;scheme=https;package=com.google.ar.core;action=android.intent.action.VIEW;" + (fallback ? "S.browser_fallback_url=" + fallback + ";" : "") + "end;";
|
12348 | },
|
12349 | INTENT_SEARCHBOX: function (params, fallback) {
|
12350 | return "intent://arvr.google.com/scene-viewer/1.1?" + params + "#Intent;scheme=https;package=com.google.android.googlequicksearchbox;action=android.intent.action.VIEW;" + (fallback ? "S.browser_fallback_url=" + fallback + ";" : "") + "end;";
|
12351 | },
|
12352 | FALLBACK_DEFAULT: function (params) {
|
12353 | return "https://arvr.google.com/scene-viewer?" + params;
|
12354 | }
|
12355 | };
|
12356 |
|
12357 | /*
|
12358 | * Copyright (c) 2020 NAVER Corp.
|
12359 | * egjs projects are licensed under the MIT license
|
12360 | */
|
12361 | /**
|
12362 | * Manager for WebXR dom-overlay feature
|
12363 | * @category XR
|
12364 | */
|
12365 |
|
12366 | var DOMOverlay =
|
12367 | /*#__PURE__*/
|
12368 | function () {
|
12369 | /**
|
12370 | * Create new DOMOverlay instance
|
12371 | * @param {object} [options] Options
|
12372 | * @param {HTMLElement} [options.root] Overlay root element
|
12373 | * @param {HTMLElement | null} [options.loadingEl] Model loading indicator element which will be invisible after placing model on the floor.
|
12374 | */
|
12375 | function DOMOverlay(options) {
|
12376 | this._root = options.root;
|
12377 | this._loadingEl = options.loadingEl;
|
12378 | }
|
12379 |
|
12380 | var __proto = DOMOverlay.prototype;
|
12381 | Object.defineProperty(__proto, "root", {
|
12382 | /**
|
12383 | * Overlay root element
|
12384 | */
|
12385 | get: function () {
|
12386 | return this._root;
|
12387 | },
|
12388 | enumerable: false,
|
12389 | configurable: true
|
12390 | });
|
12391 | Object.defineProperty(__proto, "loadingElement", {
|
12392 | /**
|
12393 | * Loading indicator element, if there's any
|
12394 | */
|
12395 | get: function () {
|
12396 | return this._loadingEl;
|
12397 | },
|
12398 | enumerable: false,
|
12399 | configurable: true
|
12400 | });
|
12401 | Object.defineProperty(__proto, "features", {
|
12402 | /**
|
12403 | * {@link https://developer.mozilla.org/en-US/docs/Web/API/XRSessionInit XRSessionInit} object for dom-overlay feature
|
12404 | */
|
12405 | get: function () {
|
12406 | return FEATURES.DOM_OVERLAY(this._root);
|
12407 | },
|
12408 | enumerable: false,
|
12409 | configurable: true
|
12410 | });
|
12411 | /**
|
12412 | * Return whether dom-overlay feature is available
|
12413 | */
|
12414 |
|
12415 | __proto.isAvailable = function () {
|
12416 | return DOM_OVERLAY_SUPPORTED;
|
12417 | };
|
12418 | /**
|
12419 | * Show loading indicator, if there's any
|
12420 | */
|
12421 |
|
12422 |
|
12423 | __proto.showLoading = function () {
|
12424 | if (!this._loadingEl) return;
|
12425 | this._loadingEl.style.visibility = "visible";
|
12426 | };
|
12427 | /**
|
12428 | * Hide loading indicator, if there's any
|
12429 | */
|
12430 |
|
12431 |
|
12432 | __proto.hideLoading = function () {
|
12433 | if (!this._loadingEl) return;
|
12434 | this._loadingEl.style.visibility = "hidden";
|
12435 | };
|
12436 |
|
12437 | return DOMOverlay;
|
12438 | }();
|
12439 |
|
12440 | /*
|
12441 | * Copyright (c) 2020 NAVER Corp.
|
12442 | * egjs projects are licensed under the MIT license
|
12443 | */
|
12444 | /**
|
12445 | * WebXR based abstract AR session class
|
12446 | * @category XR
|
12447 | * @fires WebARSession#start
|
12448 | * @fires WebARSession#end
|
12449 | * @fires WebARSession#canPlace
|
12450 | * @fires WebARSession#modelPlaced
|
12451 | */
|
12452 |
|
12453 | var WebARSession =
|
12454 | /*#__PURE__*/
|
12455 | function (_super) {
|
12456 | __extends(WebARSession, _super);
|
12457 | /**
|
12458 | * Emitted when session is started.
|
12459 | * @event start
|
12460 | * @category XR
|
12461 | * @memberof WebARSession
|
12462 | * @type void
|
12463 | */
|
12464 |
|
12465 | /**
|
12466 | * Emitted when session is ended.
|
12467 | * @event end
|
12468 | * @category XR
|
12469 | * @memberof WebARSession
|
12470 | * @type void
|
12471 | */
|
12472 |
|
12473 | /**
|
12474 | * Emitted when model can be placed on the space.
|
12475 | * @event canPlace
|
12476 | * @category XR
|
12477 | * @memberof WebARSession
|
12478 | * @type void
|
12479 | */
|
12480 |
|
12481 | /**
|
12482 | * Emitted when model is placed.
|
12483 | * @event modelPlaced
|
12484 | * @category XR
|
12485 | * @memberof WebARSession
|
12486 | * @type void
|
12487 | */
|
12488 |
|
12489 | /**
|
12490 | * Create new instance of WebARSession
|
12491 | * @param {object} [options={}] Options
|
12492 | * @param {object} [options.features={}] You can set additional features(see {@link https://developer.mozilla.org/en-US/docs/Web/API/XRSessionInit XRSessionInit}) with this option.
|
12493 | * @param {number} [options.maxModelSize=Infinity] If model's size is too big to show on AR, you can restrict it's size with this option. Model with size bigger than this value will clamped to this value.
|
12494 | * @param {HTMLElement|string|null} [options.overlayRoot=null] If this value is set, dom-overlay feature will be automatically added for this session. And this value will be used as dom-overlay's root element. You can set either HTMLElement or query selector for that element.
|
12495 | * @param {HTMLElement|string|null} [options.loadingEl=null] This will be used for loading indicator element, which will automatically invisible after placing 3D model by setting `visibility: hidden`. This element must be placed under `overlayRoot`. You can set either HTMLElement or query selector for that element.
|
12496 | * @param {boolean} [options.forceOverlay=false] Whether to apply `dom-overlay` feature as required. If set to false, `dom-overlay` will be optional feature.
|
12497 | */
|
12498 |
|
12499 |
|
12500 | function WebARSession(_a) {
|
12501 | var _b = _a === void 0 ? {} : _a,
|
12502 | _c = _b.features,
|
12503 | userFeatures = _c === void 0 ? EMPTY_FEATURES : _c,
|
12504 | // https://developer.mozilla.org/en-US/docs/Web/API/XRSessionInit
|
12505 | _d = _b.maxModelSize,
|
12506 | // https://developer.mozilla.org/en-US/docs/Web/API/XRSessionInit
|
12507 | maxModelSize = _d === void 0 ? Infinity : _d,
|
12508 | _e = _b.overlayRoot,
|
12509 | overlayRoot = _e === void 0 ? NULL_ELEMENT : _e,
|
12510 | _f = _b.loadingEl,
|
12511 | loadingEl = _f === void 0 ? NULL_ELEMENT : _f,
|
12512 | _g = _b.forceOverlay,
|
12513 | forceOverlay = _g === void 0 ? false : _g;
|
12514 |
|
12515 | var _this = _super.call(this) || this;
|
12516 | /**
|
12517 | * Whether it's webxr-based session or not
|
12518 | * @type true
|
12519 | */
|
12520 |
|
12521 |
|
12522 | _this.isWebXRSession = true;
|
12523 | _this._session = null;
|
12524 | _this._domOverlay = null;
|
12525 | var overlayEl = getElement(overlayRoot);
|
12526 | var features = [];
|
12527 |
|
12528 | if (overlayEl) {
|
12529 | _this._domOverlay = new DOMOverlay({
|
12530 | root: overlayEl,
|
12531 | loadingEl: getElement(loadingEl, overlayEl)
|
12532 | });
|
12533 | features.push(_this._domOverlay.features);
|
12534 | }
|
12535 |
|
12536 | _this._features = merge.apply(void 0, __spread([{}], features, [userFeatures]));
|
12537 | _this._maxModelSize = maxModelSize;
|
12538 | _this._forceOverlay = forceOverlay;
|
12539 | return _this;
|
12540 | }
|
12541 |
|
12542 | var __proto = WebARSession.prototype;
|
12543 | Object.defineProperty(__proto, "session", {
|
12544 | /**
|
12545 | * {@link https://developer.mozilla.org/en-US/docs/Web/API/XRSession XRSession} of this session
|
12546 | * This value is only available after calling enter
|
12547 | */
|
12548 | get: function () {
|
12549 | return this._session;
|
12550 | },
|
12551 | enumerable: false,
|
12552 | configurable: true
|
12553 | });
|
12554 | Object.defineProperty(__proto, "features", {
|
12555 | /**
|
12556 | * {@link https://developer.mozilla.org/en-US/docs/Web/API/XRSessionInit XRSessionInit} object for this session.
|
12557 | */
|
12558 | get: function () {
|
12559 | return this._features;
|
12560 | },
|
12561 | enumerable: false,
|
12562 | configurable: true
|
12563 | });
|
12564 | /**
|
12565 | * Return availability of this session
|
12566 | * @returns {Promise} A Promise that resolves availability of this session(boolean).
|
12567 | */
|
12568 |
|
12569 | __proto.isAvailable = function () {
|
12570 | var domOverlay = this._domOverlay;
|
12571 | if (!WEBXR_SUPPORTED || !HIT_TEST_SUPPORTED) return Promise.resolve(false);
|
12572 |
|
12573 | if (this._forceOverlay) {
|
12574 | if (domOverlay && !domOverlay.isAvailable()) return Promise.resolve(false);
|
12575 | }
|
12576 |
|
12577 | return navigator.xr.isSessionSupported(SESSION.AR);
|
12578 | };
|
12579 | /**
|
12580 | * Enter session
|
12581 | * @param view3d Instance of the View3D
|
12582 | * @returns {Promise}
|
12583 | */
|
12584 |
|
12585 |
|
12586 | __proto.enter = function (view3d) {
|
12587 | var _this = this; // Model not loaded yet
|
12588 |
|
12589 |
|
12590 | if (!view3d.model) return Promise.reject("3D Model is not loaded");
|
12591 | var model = view3d.model;
|
12592 | return navigator.xr.requestSession(SESSION.AR, this._features).then(function (session) {
|
12593 | var renderer = view3d.renderer;
|
12594 | var threeRenderer = renderer.threeRenderer;
|
12595 | var xrContext = {
|
12596 | view3d: view3d,
|
12597 | model: model,
|
12598 | session: session
|
12599 | }; // Cache original values
|
12600 |
|
12601 | var originalMatrix = model.scene.matrix.clone();
|
12602 | var originalModelSize = model.size;
|
12603 | var originalBackground = view3d.scene.root.background;
|
12604 | var arModelSize = Math.min(model.originalSize, _this._maxModelSize);
|
12605 | model.size = arModelSize;
|
12606 | model.moveToOrigin();
|
12607 | view3d.scene.setBackground(null); // Cache original model rotation
|
12608 |
|
12609 | threeRenderer.xr.setReferenceSpaceType(REFERENCE_SPACE.LOCAL);
|
12610 | threeRenderer.xr.setSession(session);
|
12611 | threeRenderer.setPixelRatio(1);
|
12612 |
|
12613 | _this.onStart(xrContext);
|
12614 |
|
12615 | session.addEventListener("end", function () {
|
12616 | _this.onEnd(xrContext); // Restore original values
|
12617 |
|
12618 |
|
12619 | model.scene.matrix.copy(originalMatrix);
|
12620 | model.scene.matrix.decompose(model.scene.position, model.scene.quaternion, model.scene.scale);
|
12621 | model.size = originalModelSize;
|
12622 | model.moveToOrigin();
|
12623 | view3d.scene.update(model);
|
12624 | view3d.scene.setBackground(originalBackground); // Restore renderer values
|
12625 |
|
12626 | threeRenderer.xr.setSession(null);
|
12627 | threeRenderer.setPixelRatio(window.devicePixelRatio); // Restore render loop
|
12628 |
|
12629 | renderer.stopAnimationLoop();
|
12630 | renderer.setAnimationLoop(view3d.renderLoop);
|
12631 | }, {
|
12632 | once: true
|
12633 | }); // Set XR session render loop
|
12634 |
|
12635 | renderer.stopAnimationLoop();
|
12636 | renderer.setAnimationLoop(function (delta, frame) {
|
12637 | var xrCam = threeRenderer.xr.getCamera(new PerspectiveCamera());
|
12638 | var referenceSpace = threeRenderer.xr.getReferenceSpace();
|
12639 | var glLayer = session.renderState.baseLayer;
|
12640 | var size = {
|
12641 | width: glLayer.framebufferWidth,
|
12642 | height: glLayer.framebufferHeight
|
12643 | };
|
12644 |
|
12645 | var renderContext = __assign(__assign({}, xrContext), {
|
12646 | delta: delta,
|
12647 | frame: frame,
|
12648 | referenceSpace: referenceSpace,
|
12649 | xrCam: xrCam,
|
12650 | size: size
|
12651 | });
|
12652 |
|
12653 | _this._beforeRender(renderContext);
|
12654 |
|
12655 | view3d.renderLoop(delta);
|
12656 | });
|
12657 | });
|
12658 | };
|
12659 | /**
|
12660 | * Exit this session
|
12661 | * @param view3d Instance of the View3D
|
12662 | */
|
12663 |
|
12664 |
|
12665 | __proto.exit = function (view3d) {
|
12666 | var session = view3d.renderer.threeRenderer.xr.getSession();
|
12667 | session.end();
|
12668 | };
|
12669 |
|
12670 | __proto.onStart = function (ctx) {
|
12671 | var _a;
|
12672 |
|
12673 | this._session = ctx.session;
|
12674 | (_a = this._domOverlay) === null || _a === void 0 ? void 0 : _a.showLoading();
|
12675 | this.emit("start");
|
12676 | };
|
12677 |
|
12678 | __proto.onEnd = function (ctx) {
|
12679 | var _a;
|
12680 |
|
12681 | this._session = null;
|
12682 | (_a = this._domOverlay) === null || _a === void 0 ? void 0 : _a.hideLoading();
|
12683 | this.emit("end");
|
12684 | };
|
12685 |
|
12686 | return WebARSession;
|
12687 | }(EventEmitter);
|
12688 |
|
12689 | /*
|
12690 | * Copyright (c) 2020 NAVER Corp.
|
12691 | * egjs projects are licensed under the MIT license
|
12692 | */
|
12693 | /**
|
12694 | * Manager for WebXR hit-test feature
|
12695 | * @category XR
|
12696 | */
|
12697 |
|
12698 | var HitTest =
|
12699 | /*#__PURE__*/
|
12700 | function () {
|
12701 | function HitTest() {
|
12702 | this._source = null;
|
12703 | }
|
12704 |
|
12705 | var __proto = HitTest.prototype;
|
12706 | Object.defineProperty(__proto, "ready", {
|
12707 | /**
|
12708 | * Return whether hit-test is ready
|
12709 | */
|
12710 | get: function () {
|
12711 | return this._source != null;
|
12712 | },
|
12713 | enumerable: false,
|
12714 | configurable: true
|
12715 | });
|
12716 | Object.defineProperty(__proto, "features", {
|
12717 | /**
|
12718 | * {@link https://developer.mozilla.org/en-US/docs/Web/API/XRSessionInit XRSessionInit} object for hit-test feature
|
12719 | */
|
12720 | get: function () {
|
12721 | return FEATURES.HIT_TEST;
|
12722 | },
|
12723 | enumerable: false,
|
12724 | configurable: true
|
12725 | });
|
12726 | /**
|
12727 | * Destroy instance
|
12728 | */
|
12729 |
|
12730 | __proto.destroy = function () {
|
12731 | if (this._source) {
|
12732 | this._source.cancel();
|
12733 |
|
12734 | this._source = null;
|
12735 | }
|
12736 | };
|
12737 | /**
|
12738 | * Initialize hit-test feature
|
12739 | * @param {XRSession} session XRSession instance
|
12740 | */
|
12741 |
|
12742 |
|
12743 | __proto.init = function (session) {
|
12744 | var _this = this;
|
12745 |
|
12746 | session.requestReferenceSpace(REFERENCE_SPACE.VIEWER).then(function (referenceSpace) {
|
12747 | session.requestHitTestSource({
|
12748 | space: referenceSpace
|
12749 | }).then(function (source) {
|
12750 | _this._source = source;
|
12751 | });
|
12752 | });
|
12753 | };
|
12754 | /**
|
12755 | * Return whether hit-test feature is available
|
12756 | */
|
12757 |
|
12758 |
|
12759 | __proto.isAvailable = function () {
|
12760 | return HIT_TEST_SUPPORTED;
|
12761 | };
|
12762 | /**
|
12763 | * Get hit-test results
|
12764 | * @param {XRFrame} frame XRFrame instance
|
12765 | */
|
12766 |
|
12767 |
|
12768 | __proto.getResults = function (frame) {
|
12769 | return frame.getHitTestResults(this._source);
|
12770 | };
|
12771 |
|
12772 | return HitTest;
|
12773 | }();
|
12774 |
|
12775 | /*
|
12776 | * Copyright (c) 2020 NAVER Corp.
|
12777 | * egjs projects are licensed under the MIT license
|
12778 | */
|
12779 | /**
|
12780 | * Fires for every animation frame when animation is active.
|
12781 | * @type object
|
12782 | * @property {object} event Event object.
|
12783 | * @property {number} [event.progress] Current animation progress value.
|
12784 | * Value is ranged from 0(start) to 1(end).
|
12785 | * @property {number} [event.easedProgress] Eased progress value.
|
12786 | * @event Animation#progress
|
12787 | */
|
12788 |
|
12789 | /**
|
12790 | * Fires for every animation loop except for the last loop
|
12791 | * This will be triggered only when repeat > 0
|
12792 | * @type object
|
12793 | * @property {object} event Event object.
|
12794 | * @property {number} [event.progress] Current animation progress value.
|
12795 | * Value is ranged from 0(start) to 1(end).
|
12796 | * @property {number} [event.easedProgress] Eased progress value.
|
12797 | * @property {number} [event.loopIndex] Index of the current loop.
|
12798 | * @event Animation#loop
|
12799 | */
|
12800 |
|
12801 | /**
|
12802 | * Fires when animation ends.
|
12803 | * @type void
|
12804 | * @event Animation#finish
|
12805 | */
|
12806 |
|
12807 | /**
|
12808 | * Self-running animation
|
12809 | * @category Core
|
12810 | */
|
12811 |
|
12812 | var Animation =
|
12813 | /*#__PURE__*/
|
12814 | function (_super) {
|
12815 | __extends(Animation, _super);
|
12816 | /**
|
12817 | * Create new instance of the Animation
|
12818 | * @param {object} [options={}] Options
|
12819 | */
|
12820 |
|
12821 |
|
12822 | function Animation(_a) {
|
12823 | var _b = _a === void 0 ? {} : _a,
|
12824 | _c = _b.context,
|
12825 | context = _c === void 0 ? window : _c,
|
12826 | _d = _b.repeat,
|
12827 | repeat = _d === void 0 ? 0 : _d,
|
12828 | _e = _b.duration,
|
12829 | duration = _e === void 0 ? ANIMATION_DURATION : _e,
|
12830 | _f = _b.easing,
|
12831 | easing = _f === void 0 ? EASE_OUT_CUBIC : _f;
|
12832 |
|
12833 | var _this = _super.call(this) || this;
|
12834 |
|
12835 | _this._loop = function () {
|
12836 | var delta = _this._getDeltaTime();
|
12837 |
|
12838 | var duration = _this._duration;
|
12839 | _this._time += delta;
|
12840 | var loopIncrease = Math.floor(_this._time / duration);
|
12841 | _this._time = circulate(_this._time, 0, duration);
|
12842 | var progress = _this._time / duration;
|
12843 | var progressEvent = {
|
12844 | progress: progress,
|
12845 | easedProgress: _this._easing(progress)
|
12846 | };
|
12847 |
|
12848 | _this.emit("progress", progressEvent);
|
12849 |
|
12850 | for (var loopIdx = 0; loopIdx < loopIncrease; loopIdx++) {
|
12851 | _this._loopCount++;
|
12852 |
|
12853 | if (_this._loopCount > _this._repeat) {
|
12854 | _this.emit("finish");
|
12855 |
|
12856 | _this.stop();
|
12857 |
|
12858 | return;
|
12859 | } else {
|
12860 | _this.emit("loop", __assign(__assign({}, progressEvent), {
|
12861 | loopIndex: _this._loopCount
|
12862 | }));
|
12863 | }
|
12864 | }
|
12865 |
|
12866 | _this._rafId = _this._ctx.requestAnimationFrame(_this._loop);
|
12867 | }; // Options
|
12868 |
|
12869 |
|
12870 | _this._repeat = repeat;
|
12871 | _this._duration = duration;
|
12872 | _this._easing = easing; // Internal States
|
12873 |
|
12874 | _this._ctx = context;
|
12875 | _this._rafId = -1;
|
12876 | _this._time = 0;
|
12877 | _this._clock = 0;
|
12878 | _this._loopCount = 0;
|
12879 | return _this;
|
12880 | }
|
12881 |
|
12882 | var __proto = Animation.prototype;
|
12883 |
|
12884 | __proto.start = function () {
|
12885 | if (this._rafId >= 0) return; // This guarantees "progress" event with progress = 0 on first start
|
12886 |
|
12887 | this._updateClock();
|
12888 |
|
12889 | this._loop();
|
12890 | };
|
12891 |
|
12892 | __proto.stop = function () {
|
12893 | if (this._rafId < 0) return;
|
12894 | this._time = 0;
|
12895 | this._loopCount = 0;
|
12896 |
|
12897 | this._stopLoop();
|
12898 | };
|
12899 |
|
12900 | __proto.pause = function () {
|
12901 | if (this._rafId < 0) return;
|
12902 |
|
12903 | this._stopLoop();
|
12904 | };
|
12905 |
|
12906 | __proto._stopLoop = function () {
|
12907 | this._ctx.cancelAnimationFrame(this._rafId);
|
12908 |
|
12909 | this._rafId = -1;
|
12910 | };
|
12911 |
|
12912 | __proto._getDeltaTime = function () {
|
12913 | var lastTime = this._clock;
|
12914 |
|
12915 | this._updateClock();
|
12916 |
|
12917 | return this._clock - lastTime;
|
12918 | };
|
12919 |
|
12920 | __proto._updateClock = function () {
|
12921 | this._clock = Date.now();
|
12922 | };
|
12923 |
|
12924 | return Animation;
|
12925 | }(EventEmitter);
|
12926 |
|
12927 | /*
|
12928 | * Copyright (c) 2020 NAVER Corp.
|
12929 | * egjs projects are licensed under the MIT license
|
12930 | */
|
12931 | /**
|
12932 | * Rotation indicator for ARHoverSession
|
12933 | * @category Controls-AR
|
12934 | */
|
12935 |
|
12936 | var RotationIndicator =
|
12937 | /*#__PURE__*/
|
12938 | function () {
|
12939 | /**
|
12940 | * Create new RotationIndicator
|
12941 | * @param {RotationIndicatorOption} [options={}] Options
|
12942 | */
|
12943 | function RotationIndicator(_a) {
|
12944 | var _b = _a === void 0 ? {} : _a,
|
12945 | _c = _b.ringColor,
|
12946 | ringColor = _c === void 0 ? 0xffffff : _c,
|
12947 | _d = _b.axisColor,
|
12948 | axisColor = _d === void 0 ? 0xffffff : _d;
|
12949 |
|
12950 | var ringGeometry = new RingGeometry(0.99, 1, 150, 1, 0, Math.PI * 2);
|
12951 | var ringMaterial = new MeshBasicMaterial({
|
12952 | color: ringColor,
|
12953 | side: DoubleSide
|
12954 | });
|
12955 | this._ring = new Mesh(ringGeometry, ringMaterial);
|
12956 | var axisVertices = [new Vector3(0, 0, -1000), new Vector3(0, 0, +1000)];
|
12957 | var axisGeometry = new BufferGeometry().setFromPoints(axisVertices);
|
12958 | var axisMaterial = new LineBasicMaterial({
|
12959 | color: axisColor
|
12960 | });
|
12961 | this._axis = new Line(axisGeometry, axisMaterial);
|
12962 | this._obj = new Group();
|
12963 |
|
12964 | this._obj.add(this._ring);
|
12965 |
|
12966 | this._obj.add(this._axis);
|
12967 |
|
12968 | this.hide();
|
12969 | }
|
12970 |
|
12971 | var __proto = RotationIndicator.prototype;
|
12972 | Object.defineProperty(__proto, "object", {
|
12973 | /**
|
12974 | * {@link https://threejs.org/docs/index.html#api/en/objects/Group THREE.Group} object that contains ring & axis.
|
12975 | */
|
12976 | get: function () {
|
12977 | return this._obj;
|
12978 | },
|
12979 | enumerable: false,
|
12980 | configurable: true
|
12981 | });
|
12982 | /**
|
12983 | * Show indicator
|
12984 | */
|
12985 |
|
12986 | __proto.show = function () {
|
12987 | this._obj.visible = true;
|
12988 | };
|
12989 | /**
|
12990 | * Hide indicator
|
12991 | */
|
12992 |
|
12993 |
|
12994 | __proto.hide = function () {
|
12995 | this._obj.visible = false;
|
12996 | };
|
12997 | /**
|
12998 | * Change the position of the indicator
|
12999 | * @param position New position
|
13000 | */
|
13001 |
|
13002 |
|
13003 | __proto.updatePosition = function (position) {
|
13004 | this._obj.position.copy(position);
|
13005 | };
|
13006 | /**
|
13007 | * Update scale of the ring
|
13008 | * @param scale New scale
|
13009 | */
|
13010 |
|
13011 |
|
13012 | __proto.updateScale = function (scale) {
|
13013 | this._ring.scale.setScalar(scale);
|
13014 | };
|
13015 | /**
|
13016 | * Update indicator's rotation
|
13017 | * @param rotation Quaternion value set as new rotation.
|
13018 | */
|
13019 |
|
13020 |
|
13021 | __proto.updateRotation = function (rotation) {
|
13022 | this._obj.quaternion.copy(rotation);
|
13023 | };
|
13024 |
|
13025 | return RotationIndicator;
|
13026 | }();
|
13027 |
|
13028 | /*
|
13029 | * Copyright (c) 2020 NAVER Corp.
|
13030 | * egjs projects are licensed under the MIT license
|
13031 | */
|
13032 | /**
|
13033 | * One finger swirl control on single axis
|
13034 | * @category Controls-AR
|
13035 | */
|
13036 |
|
13037 | var ARSwirlControl =
|
13038 | /*#__PURE__*/
|
13039 | function () {
|
13040 | /**
|
13041 | * Create new ARSwirlControl
|
13042 | * @param {ARSwirlControlOption} [options={}] Options
|
13043 | */
|
13044 | function ARSwirlControl(_a) {
|
13045 | var _b = _a === void 0 ? {} : _a,
|
13046 | _c = _b.scale,
|
13047 | scale = _c === void 0 ? 1 : _c,
|
13048 | _d = _b.showIndicator,
|
13049 | showIndicator = _d === void 0 ? true : _d;
|
13050 | /**
|
13051 | * Current rotation value
|
13052 | */
|
13053 |
|
13054 |
|
13055 | this.rotation = new Quaternion(); // Internal States
|
13056 |
|
13057 | this._axis = new Vector3(0, 1, 0);
|
13058 | this._enabled = true;
|
13059 | this._active = false;
|
13060 | this._prevPos = new Vector2();
|
13061 | this._fromQuat = new Quaternion();
|
13062 | this._toQuat = new Quaternion();
|
13063 | this._motion = new Motion({
|
13064 | range: INFINITE_RANGE
|
13065 | });
|
13066 | this._userScale = scale;
|
13067 |
|
13068 | if (showIndicator) {
|
13069 | this._rotationIndicator = new RotationIndicator();
|
13070 | }
|
13071 | }
|
13072 |
|
13073 | var __proto = ARSwirlControl.prototype;
|
13074 | Object.defineProperty(__proto, "enabled", {
|
13075 | /**
|
13076 | * Whether this control is enabled or not.
|
13077 | * @readonly
|
13078 | */
|
13079 | get: function () {
|
13080 | return this._enabled;
|
13081 | },
|
13082 | enumerable: false,
|
13083 | configurable: true
|
13084 | });
|
13085 | Object.defineProperty(__proto, "scale", {
|
13086 | /**
|
13087 | * Scale(speed) factor of this control.
|
13088 | */
|
13089 | get: function () {
|
13090 | return this._userScale;
|
13091 | },
|
13092 | set: function (val) {
|
13093 | this._userScale = val;
|
13094 | },
|
13095 | enumerable: false,
|
13096 | configurable: true
|
13097 | });
|
13098 |
|
13099 | __proto.init = function (_a) {
|
13100 | var view3d = _a.view3d;
|
13101 | var initialRotation = view3d.model.scene.quaternion;
|
13102 | this.updateRotation(initialRotation);
|
13103 |
|
13104 | if (this._rotationIndicator) {
|
13105 | view3d.scene.add(this._rotationIndicator.object);
|
13106 | }
|
13107 | };
|
13108 |
|
13109 | __proto.destroy = function (_a) {
|
13110 | var view3d = _a.view3d;
|
13111 |
|
13112 | if (this._rotationIndicator) {
|
13113 | view3d.scene.remove(this._rotationIndicator.object);
|
13114 | }
|
13115 | };
|
13116 |
|
13117 | __proto.updateRotation = function (rotation) {
|
13118 | this.rotation.copy(rotation);
|
13119 |
|
13120 | this._fromQuat.copy(rotation);
|
13121 |
|
13122 | this._toQuat.copy(rotation);
|
13123 | };
|
13124 | /**
|
13125 | * Enable this control
|
13126 | */
|
13127 |
|
13128 |
|
13129 | __proto.enable = function () {
|
13130 | this._enabled = true;
|
13131 | };
|
13132 | /**
|
13133 | * Disable this control
|
13134 | */
|
13135 |
|
13136 |
|
13137 | __proto.disable = function () {
|
13138 | this._enabled = false;
|
13139 | };
|
13140 |
|
13141 | __proto.activate = function (_a, gesture) {
|
13142 | var view3d = _a.view3d;
|
13143 | if (!this._enabled) return;
|
13144 | this._active = true;
|
13145 | var model = view3d.model;
|
13146 | var rotationIndicator = this._rotationIndicator;
|
13147 |
|
13148 | if (rotationIndicator) {
|
13149 | rotationIndicator.show();
|
13150 | rotationIndicator.updatePosition(model.bbox.getCenter(new Vector3()));
|
13151 | rotationIndicator.updateScale(model.size / 2);
|
13152 | rotationIndicator.updateRotation(model.scene.quaternion);
|
13153 | }
|
13154 | };
|
13155 |
|
13156 | __proto.deactivate = function () {
|
13157 | this._active = false;
|
13158 |
|
13159 | if (this._rotationIndicator) {
|
13160 | this._rotationIndicator.hide();
|
13161 | }
|
13162 | };
|
13163 |
|
13164 | __proto.updateAxis = function (axis) {
|
13165 | this._axis.copy(axis);
|
13166 | };
|
13167 |
|
13168 | __proto.setInitialPos = function (coords) {
|
13169 | this._prevPos.copy(coords[0]);
|
13170 | };
|
13171 |
|
13172 | __proto.process = function (_a, _b) {
|
13173 | var view3d = _a.view3d,
|
13174 | xrCam = _a.xrCam;
|
13175 | var coords = _b.coords;
|
13176 | if (!this._active || coords.length !== 1) return;
|
13177 | var prevPos = this._prevPos;
|
13178 | var motion = this._motion;
|
13179 | var model = view3d.model;
|
13180 | var coord = coords[0];
|
13181 | var modelPos = model.scene.position.clone();
|
13182 | var ndcModelPos = new Vector2().fromArray(modelPos.project(xrCam).toArray()); // Get the rotation angle with the model's NDC coordinates as the center.
|
13183 |
|
13184 | var rotationAngle = getRotationAngle(ndcModelPos, prevPos, coord) * this._userScale;
|
13185 |
|
13186 | var rotation = new Quaternion().setFromAxisAngle(this._axis, rotationAngle);
|
13187 |
|
13188 | var interpolated = this._getInterpolatedQuaternion();
|
13189 |
|
13190 | this._fromQuat.copy(interpolated);
|
13191 |
|
13192 | this._toQuat.premultiply(rotation);
|
13193 |
|
13194 | motion.reset(0);
|
13195 | motion.setEndDelta(1);
|
13196 | prevPos.copy(coord);
|
13197 | };
|
13198 |
|
13199 | __proto.update = function (_a, deltaTime) {
|
13200 | var model = _a.model;
|
13201 | if (!this._active) return;
|
13202 | var motion = this._motion;
|
13203 | motion.update(deltaTime);
|
13204 |
|
13205 | var interpolated = this._getInterpolatedQuaternion();
|
13206 |
|
13207 | this.rotation.copy(interpolated);
|
13208 | model.scene.quaternion.copy(interpolated);
|
13209 | };
|
13210 |
|
13211 | __proto._getInterpolatedQuaternion = function () {
|
13212 | var motion = this._motion;
|
13213 | var toEuler = this._toQuat;
|
13214 | var fromEuler = this._fromQuat;
|
13215 | var progress = motion.val;
|
13216 | return new Quaternion().copy(fromEuler).slerp(toEuler, progress);
|
13217 | };
|
13218 |
|
13219 | return ARSwirlControl;
|
13220 | }();
|
13221 |
|
13222 | /*
|
13223 | * Copyright (c) 2020 NAVER Corp.
|
13224 | * egjs projects are licensed under the MIT license
|
13225 | */
|
13226 | var STATE;
|
13227 |
|
13228 | (function (STATE) {
|
13229 | STATE[STATE["WAITING"] = 0] = "WAITING";
|
13230 | STATE[STATE["TRANSLATING"] = 1] = "TRANSLATING";
|
13231 | STATE[STATE["BOUNCING"] = 2] = "BOUNCING";
|
13232 | })(STATE || (STATE = {}));
|
13233 | /**
|
13234 | * Model's translation(position) control for {@link ARFloorControl}
|
13235 | * @category Controls-AR
|
13236 | */
|
13237 |
|
13238 |
|
13239 | var ARFloorTranslateControl =
|
13240 | /*#__PURE__*/
|
13241 | function () {
|
13242 | /**
|
13243 | * Create new instance of ARTranslateControl
|
13244 | * @param {ARFloorTranslateControlOption} [options={}] Options
|
13245 | */
|
13246 | function ARFloorTranslateControl(_a) {
|
13247 | var _b = _a === void 0 ? {} : _a,
|
13248 | _c = _b.hoverAmplitude,
|
13249 | hoverAmplitude = _c === void 0 ? 0.01 : _c,
|
13250 | _d = _b.hoverHeight,
|
13251 | hoverHeight = _d === void 0 ? 0.1 : _d,
|
13252 | _e = _b.hoverPeriod,
|
13253 | hoverPeriod = _e === void 0 ? 1000 : _e,
|
13254 | _f = _b.hoverEasing,
|
13255 | hoverEasing = _f === void 0 ? SINE_WAVE : _f,
|
13256 | _g = _b.bounceDuration,
|
13257 | bounceDuration = _g === void 0 ? 1000 : _g,
|
13258 | _h = _b.bounceEasing,
|
13259 | bounceEasing = _h === void 0 ? EASE_OUT_BOUNCE : _h; // Internal states
|
13260 |
|
13261 |
|
13262 | this._modelPosition = new Vector3();
|
13263 | this._hoverPosition = new Vector3();
|
13264 | this._floorPosition = new Vector3();
|
13265 | this._dragPlane = new Plane();
|
13266 | this._enabled = true;
|
13267 | this._state = STATE.WAITING;
|
13268 | this._initialPos = new Vector2();
|
13269 | this._hoverAmplitude = hoverAmplitude;
|
13270 | this._hoverHeight = hoverHeight;
|
13271 | this._hoverMotion = new Motion({
|
13272 | loop: true,
|
13273 | duration: hoverPeriod,
|
13274 | easing: hoverEasing
|
13275 | });
|
13276 | this._bounceMotion = new Motion({
|
13277 | duration: bounceDuration,
|
13278 | easing: bounceEasing,
|
13279 | range: INFINITE_RANGE
|
13280 | });
|
13281 | }
|
13282 |
|
13283 | var __proto = ARFloorTranslateControl.prototype;
|
13284 | Object.defineProperty(__proto, "enabled", {
|
13285 | /**
|
13286 | * Whether this control is enabled or not
|
13287 | * @readonly
|
13288 | */
|
13289 | get: function () {
|
13290 | return this._enabled;
|
13291 | },
|
13292 | enumerable: false,
|
13293 | configurable: true
|
13294 | });
|
13295 | Object.defineProperty(__proto, "modelPosition", {
|
13296 | /**
|
13297 | * Position including hover/bounce animation offset from the floor.
|
13298 | * @readonly
|
13299 | */
|
13300 | get: function () {
|
13301 | return this._modelPosition.clone();
|
13302 | },
|
13303 | enumerable: false,
|
13304 | configurable: true
|
13305 | });
|
13306 | Object.defineProperty(__proto, "floorPosition", {
|
13307 | /**
|
13308 | * Last detected floor position
|
13309 | * @readonly
|
13310 | */
|
13311 | get: function () {
|
13312 | return this._floorPosition.clone();
|
13313 | },
|
13314 | enumerable: false,
|
13315 | configurable: true
|
13316 | });
|
13317 | Object.defineProperty(__proto, "hoverAmplitude", {
|
13318 | /**
|
13319 | * How much model will hover up and down, in meter.
|
13320 | */
|
13321 | get: function () {
|
13322 | return this._hoverAmplitude;
|
13323 | },
|
13324 | set: function (val) {
|
13325 | this._hoverAmplitude = val;
|
13326 | },
|
13327 | enumerable: false,
|
13328 | configurable: true
|
13329 | });
|
13330 | Object.defineProperty(__proto, "hoverHeight", {
|
13331 | /**
|
13332 | * How much model will float from the floor, in meter.
|
13333 | */
|
13334 | get: function () {
|
13335 | return this._hoverHeight;
|
13336 | },
|
13337 | set: function (val) {
|
13338 | this._hoverHeight = val;
|
13339 | },
|
13340 | enumerable: false,
|
13341 | configurable: true
|
13342 | });
|
13343 |
|
13344 | __proto.initFloorPosition = function (position) {
|
13345 | this._modelPosition.copy(position);
|
13346 |
|
13347 | this._floorPosition.copy(position);
|
13348 |
|
13349 | this._hoverPosition.copy(position);
|
13350 |
|
13351 | this._hoverPosition.setY(position.y + this._hoverHeight);
|
13352 | }; // tslint:disable-next-line no-empty
|
13353 |
|
13354 |
|
13355 | __proto.init = function (ctx) {}; // tslint:disable-next-line no-empty
|
13356 |
|
13357 |
|
13358 | __proto.destroy = function (ctx) {};
|
13359 | /**
|
13360 | * Enable this control
|
13361 | */
|
13362 |
|
13363 |
|
13364 | __proto.enable = function () {
|
13365 | this._enabled = true;
|
13366 | };
|
13367 | /**
|
13368 | * Disable this control
|
13369 | */
|
13370 |
|
13371 |
|
13372 | __proto.disable = function () {
|
13373 | this._enabled = false;
|
13374 | this.deactivate();
|
13375 | };
|
13376 |
|
13377 | __proto.activate = function (_a, gesture) {
|
13378 | var model = _a.model;
|
13379 | if (!this._enabled) return;
|
13380 | var modelBbox = model.bbox;
|
13381 | var modelBboxYOffset = modelBbox.getCenter(new Vector3()).y - modelBbox.min.y;
|
13382 |
|
13383 | this._dragPlane.set(new Vector3(0, 1, 0), -(this._floorPosition.y + this._hoverHeight + modelBboxYOffset));
|
13384 |
|
13385 | this._hoverMotion.reset(0);
|
13386 |
|
13387 | this._hoverMotion.setEndDelta(1);
|
13388 |
|
13389 | this._state = STATE.TRANSLATING;
|
13390 | };
|
13391 |
|
13392 | __proto.deactivate = function () {
|
13393 | if (!this._enabled || this._state === STATE.WAITING) {
|
13394 | this._state = STATE.WAITING;
|
13395 | return;
|
13396 | }
|
13397 |
|
13398 | this._state = STATE.BOUNCING;
|
13399 | var floorPosition = this._floorPosition;
|
13400 | var modelPosition = this._modelPosition;
|
13401 | var hoverPosition = this._hoverPosition;
|
13402 | var bounceMotion = this._bounceMotion;
|
13403 | var hoveringAmount = modelPosition.y - floorPosition.y;
|
13404 | bounceMotion.reset(modelPosition.y);
|
13405 | bounceMotion.setEndDelta(-hoveringAmount); // Restore hover pos
|
13406 |
|
13407 | hoverPosition.copy(floorPosition);
|
13408 | hoverPosition.setY(floorPosition.y + this._hoverHeight);
|
13409 | };
|
13410 |
|
13411 | __proto.setInitialPos = function (coords) {
|
13412 | this._initialPos.copy(coords[0]);
|
13413 | };
|
13414 |
|
13415 | __proto.process = function (_a, _b) {
|
13416 | var view3d = _a.view3d,
|
13417 | model = _a.model,
|
13418 | frame = _a.frame,
|
13419 | referenceSpace = _a.referenceSpace,
|
13420 | xrCam = _a.xrCam;
|
13421 | var hitResults = _b.hitResults;
|
13422 | var state = this._state;
|
13423 | var notActive = state === STATE.WAITING || state === STATE.BOUNCING;
|
13424 | if (!hitResults || hitResults.length !== 1 || notActive) return;
|
13425 | var hitResult = hitResults[0];
|
13426 |
|
13427 | var prevFloorPosition = this._floorPosition.clone();
|
13428 |
|
13429 | var floorPosition = this._floorPosition;
|
13430 | var hoverPosition = this._hoverPosition;
|
13431 | var hoverHeight = this._hoverHeight;
|
13432 | var dragPlane = this._dragPlane;
|
13433 | var modelBbox = model.bbox;
|
13434 | var modelBboxYOffset = modelBbox.getCenter(new Vector3()).y - modelBbox.min.y;
|
13435 | var hitPose = hitResult.results[0] && hitResult.results[0].getPose(referenceSpace);
|
13436 | var isFloorHit = hitPose && hitPose.transform.matrix[5] >= 0.75;
|
13437 | var camPos = new Vector3().setFromMatrixPosition(xrCam.matrixWorld);
|
13438 |
|
13439 | if (!hitPose || !isFloorHit) {
|
13440 | // Use previous drag plane if no hit plane is found
|
13441 | var targetRayPose = frame.getPose(hitResult.inputSource.targetRaySpace, view3d.renderer.threeRenderer.xr.getReferenceSpace());
|
13442 | var fingerDir = new Vector3().copy(targetRayPose.transform.position).sub(camPos).normalize();
|
13443 | var fingerRay = new Ray(camPos, fingerDir);
|
13444 | var intersection = fingerRay.intersectPlane(dragPlane, new Vector3());
|
13445 |
|
13446 | if (intersection) {
|
13447 | floorPosition.copy(intersection);
|
13448 | floorPosition.setY(prevFloorPosition.y);
|
13449 | hoverPosition.copy(intersection);
|
13450 | hoverPosition.setY(intersection.y - modelBboxYOffset);
|
13451 | }
|
13452 |
|
13453 | return;
|
13454 | }
|
13455 |
|
13456 | var hitMatrix = new Matrix4().fromArray(hitPose.transform.matrix);
|
13457 | var hitPosition = new Vector3().setFromMatrixPosition(hitMatrix); // Set new floor level when it's increased at least 10cm
|
13458 |
|
13459 | var currentDragPlaneHeight = -dragPlane.constant;
|
13460 | var hitDragPlaneHeight = hitPosition.y + hoverHeight + modelBboxYOffset;
|
13461 |
|
13462 | if (hitDragPlaneHeight - currentDragPlaneHeight > 0.1) {
|
13463 | dragPlane.constant = -hitDragPlaneHeight;
|
13464 | }
|
13465 |
|
13466 | var camToHitDir = new Vector3().subVectors(hitPosition, camPos).normalize();
|
13467 | var camToHitRay = new Ray(camPos, camToHitDir);
|
13468 | var hitOnDragPlane = camToHitRay.intersectPlane(dragPlane, new Vector3());
|
13469 | if (!hitOnDragPlane) return;
|
13470 | floorPosition.copy(hitOnDragPlane);
|
13471 | floorPosition.setY(hitPosition.y);
|
13472 | hoverPosition.copy(hitOnDragPlane);
|
13473 | hoverPosition.setY(hitOnDragPlane.y - modelBboxYOffset);
|
13474 | };
|
13475 |
|
13476 | __proto.update = function (_a, delta) {
|
13477 | var model = _a.model;
|
13478 | var state = this._state;
|
13479 | var modelPosition = this._modelPosition;
|
13480 | var hoverPosition = this._hoverPosition;
|
13481 | if (state === STATE.WAITING) return;
|
13482 |
|
13483 | if (state !== STATE.BOUNCING) {
|
13484 | // Hover
|
13485 | var hoverMotion = this._hoverMotion;
|
13486 | hoverMotion.update(delta); // Change only x, y component of position
|
13487 |
|
13488 | var hoverOffset = hoverMotion.val * this._hoverAmplitude;
|
13489 | modelPosition.copy(hoverPosition);
|
13490 | modelPosition.setY(hoverPosition.y + hoverOffset);
|
13491 | } else {
|
13492 | // Bounce
|
13493 | var bounceMotion = this._bounceMotion;
|
13494 | bounceMotion.update(delta);
|
13495 | modelPosition.setY(bounceMotion.val);
|
13496 |
|
13497 | if (bounceMotion.progress >= 1) {
|
13498 | this._state = STATE.WAITING;
|
13499 | }
|
13500 | }
|
13501 |
|
13502 | var modelBbox = model.bbox;
|
13503 | var modelYOffset = modelBbox.getCenter(new Vector3()).y - modelBbox.min.y; // modelPosition = where model.bbox.min.y should be
|
13504 |
|
13505 | model.scene.position.copy(modelPosition.clone().setY(modelPosition.y + modelYOffset));
|
13506 | };
|
13507 |
|
13508 | return ARFloorTranslateControl;
|
13509 | }();
|
13510 |
|
13511 | /*
|
13512 | * Copyright (c) 2020 NAVER Corp.
|
13513 | * egjs projects are licensed under the MIT license
|
13514 | */
|
13515 | /**
|
13516 | * UI element displaying model's scale percentage info when user chaning model's scale.
|
13517 | * @category Controls-AR
|
13518 | */
|
13519 |
|
13520 | var ScaleUI =
|
13521 | /*#__PURE__*/
|
13522 | function () {
|
13523 | /**
|
13524 | * Create new instance of ScaleUI
|
13525 | * @param {ScaleUIOption} [options={}] Options
|
13526 | */
|
13527 | function ScaleUI(_a) {
|
13528 | var _b = _a === void 0 ? {} : _a,
|
13529 | _c = _b.width,
|
13530 | width = _c === void 0 ? 0.1 : _c,
|
13531 | _d = _b.padding,
|
13532 | padding = _d === void 0 ? 20 : _d,
|
13533 | _e = _b.offset,
|
13534 | offset = _e === void 0 ? 0.05 : _e,
|
13535 | _f = _b.font,
|
13536 | font = _f === void 0 ? "64px sans-serif" : _f,
|
13537 | _g = _b.color,
|
13538 | color = _g === void 0 ? "white" : _g;
|
13539 |
|
13540 | var canvas = document.createElement("canvas");
|
13541 | var ctx = canvas.getContext("2d");
|
13542 | ctx.font = font; // Maximum canvas width should be equal to this
|
13543 |
|
13544 | var maxText = ctx.measureText("100%"); // Following APIs won't work on IE, but it's WebXR so I think it's okay
|
13545 |
|
13546 | var maxWidth = maxText.actualBoundingBoxLeft + maxText.actualBoundingBoxRight;
|
13547 | var maxHeight = maxText.actualBoundingBoxAscent + maxText.actualBoundingBoxDescent;
|
13548 | var widthPowerOfTwo = toPowerOfTwo(maxWidth);
|
13549 | canvas.width = widthPowerOfTwo;
|
13550 | canvas.height = widthPowerOfTwo; // This considers increased amount by making width to power of two
|
13551 |
|
13552 | var planeWidth = width * (widthPowerOfTwo / maxWidth);
|
13553 | this._ctx = ctx;
|
13554 | this._canvas = canvas;
|
13555 | this._height = planeWidth * maxHeight / maxWidth; // Text height inside plane
|
13556 |
|
13557 | this._texture = new CanvasTexture(canvas); // Plane is square
|
13558 |
|
13559 | var uiGeometry = new PlaneGeometry(planeWidth, planeWidth);
|
13560 | var mesh = new Mesh(uiGeometry, new MeshBasicMaterial({
|
13561 | map: this._texture,
|
13562 | transparent: true
|
13563 | }));
|
13564 | mesh.matrixAutoUpdate = false;
|
13565 | this._mesh = mesh;
|
13566 | this._font = font;
|
13567 | this._color = color;
|
13568 | this._padding = padding;
|
13569 | this._offset = offset;
|
13570 | }
|
13571 |
|
13572 | var __proto = ScaleUI.prototype;
|
13573 | Object.defineProperty(__proto, "mesh", {
|
13574 | /**
|
13575 | * Scale UI's plane mesh
|
13576 | * @readonly
|
13577 | */
|
13578 | get: function () {
|
13579 | return this._mesh;
|
13580 | },
|
13581 | enumerable: false,
|
13582 | configurable: true
|
13583 | });
|
13584 | Object.defineProperty(__proto, "height", {
|
13585 | /**
|
13586 | * Scale UI's height value
|
13587 | * @readonly
|
13588 | */
|
13589 | get: function () {
|
13590 | return this._height;
|
13591 | },
|
13592 | enumerable: false,
|
13593 | configurable: true
|
13594 | });
|
13595 | Object.defineProperty(__proto, "visible", {
|
13596 | /**
|
13597 | * Whether UI is visible or not.
|
13598 | * @readonly
|
13599 | */
|
13600 | get: function () {
|
13601 | return this._mesh.visible;
|
13602 | },
|
13603 | enumerable: false,
|
13604 | configurable: true
|
13605 | });
|
13606 |
|
13607 | __proto.updatePosition = function (position, focus) {
|
13608 | // Update mesh
|
13609 | var mesh = this._mesh;
|
13610 | mesh.lookAt(focus);
|
13611 | mesh.position.copy(position);
|
13612 | mesh.position.setY(position.y + this._height / 2 + this._offset);
|
13613 | mesh.updateMatrix();
|
13614 | };
|
13615 |
|
13616 | __proto.updateScale = function (scale) {
|
13617 | var ctx = this._ctx;
|
13618 | var canvas = this._canvas;
|
13619 | var padding = this._padding;
|
13620 | var scalePercentage = (scale * 100).toFixed(0);
|
13621 | ctx.clearRect(0, 0, canvas.width, canvas.height);
|
13622 | var centerX = canvas.width / 2;
|
13623 | var centerY = canvas.height / 2; // Draw round rect
|
13624 |
|
13625 | var textSize = ctx.measureText(scalePercentage + "%");
|
13626 | var halfWidth = (textSize.actualBoundingBoxLeft + textSize.actualBoundingBoxRight) / 2;
|
13627 | var halfHeight = (textSize.actualBoundingBoxAscent + textSize.actualBoundingBoxDescent) / 2;
|
13628 | ctx.beginPath();
|
13629 | ctx.moveTo(centerX - halfWidth, centerY - halfHeight - padding);
|
13630 | ctx.lineTo(centerX + halfWidth, centerY - halfHeight - padding);
|
13631 | ctx.quadraticCurveTo(centerX + halfWidth + padding, centerY - halfHeight - padding, centerX + halfWidth + padding, centerY - halfHeight);
|
13632 | ctx.lineTo(centerX + halfWidth + padding, centerY + halfHeight);
|
13633 | ctx.quadraticCurveTo(centerX + halfWidth + padding, centerY + halfHeight + padding, centerX + halfWidth, centerY + halfHeight + padding);
|
13634 | ctx.lineTo(centerX - halfWidth, centerY + halfHeight + padding);
|
13635 | ctx.quadraticCurveTo(centerX - halfWidth - padding, centerY + halfHeight + padding, centerX - halfWidth - padding, centerY + halfHeight);
|
13636 | ctx.lineTo(centerX - halfWidth - padding, centerY - halfHeight);
|
13637 | ctx.quadraticCurveTo(centerX - halfWidth - padding, centerY - halfHeight - padding, centerX - halfWidth, centerY - halfHeight - padding);
|
13638 | ctx.closePath();
|
13639 | ctx.lineWidth = 5;
|
13640 | ctx.fillStyle = "rgba(0, 0, 0, 0.3)";
|
13641 | ctx.fill();
|
13642 | ctx.stroke(); // Draw text
|
13643 |
|
13644 | ctx.font = this._font;
|
13645 | ctx.textAlign = "center";
|
13646 | ctx.textBaseline = "middle";
|
13647 | ctx.strokeStyle = this._color;
|
13648 | ctx.fillStyle = this._color;
|
13649 | ctx.fillText(scalePercentage + "%", centerX, centerY);
|
13650 | this._texture.needsUpdate = true;
|
13651 | };
|
13652 | /**
|
13653 | * Show UI
|
13654 | */
|
13655 |
|
13656 |
|
13657 | __proto.show = function () {
|
13658 | this._mesh.visible = true;
|
13659 | };
|
13660 | /**
|
13661 | * Hide UI
|
13662 | */
|
13663 |
|
13664 |
|
13665 | __proto.hide = function () {
|
13666 | this._mesh.visible = false;
|
13667 | };
|
13668 |
|
13669 | return ScaleUI;
|
13670 | }();
|
13671 |
|
13672 | /*
|
13673 | * Copyright (c) 2020 NAVER Corp.
|
13674 | * egjs projects are licensed under the MIT license
|
13675 | */
|
13676 | /**
|
13677 | * Model's scale controller which works on AR(WebXR) mode.
|
13678 | * @category Controls-AR
|
13679 | */
|
13680 |
|
13681 | var ARScaleControl =
|
13682 | /*#__PURE__*/
|
13683 | function () {
|
13684 | /**
|
13685 | * Create new instance of ARScaleControl
|
13686 | * @param {ARScaleControlOption} [options={}] Options
|
13687 | */
|
13688 | function ARScaleControl(_a) {
|
13689 | var _b = _a === void 0 ? {} : _a,
|
13690 | _c = _b.min,
|
13691 | min = _c === void 0 ? 0.05 : _c,
|
13692 | _d = _b.max,
|
13693 | max = _d === void 0 ? 2 : _d;
|
13694 |
|
13695 | this._enabled = true;
|
13696 | this._active = false;
|
13697 | this._prevCoordDistance = -1;
|
13698 | this._scaleMultiplier = 1;
|
13699 | this._initialScale = new Vector3();
|
13700 | this._ui = new ScaleUI();
|
13701 | this._motion = new Motion({
|
13702 | duration: 0,
|
13703 | range: {
|
13704 | min: min,
|
13705 | max: max
|
13706 | }
|
13707 | });
|
13708 |
|
13709 | this._motion.reset(1); // default scale is 1(100%)
|
13710 |
|
13711 |
|
13712 | this._ui = new ScaleUI();
|
13713 | }
|
13714 |
|
13715 | var __proto = ARScaleControl.prototype;
|
13716 | Object.defineProperty(__proto, "enabled", {
|
13717 | /**
|
13718 | * Whether this control is enabled or not
|
13719 | * @readonly
|
13720 | */
|
13721 | get: function () {
|
13722 | return this._enabled;
|
13723 | },
|
13724 | enumerable: false,
|
13725 | configurable: true
|
13726 | });
|
13727 | Object.defineProperty(__proto, "scale", {
|
13728 | get: function () {
|
13729 | return this._initialScale.clone().multiplyScalar(this._scaleMultiplier);
|
13730 | },
|
13731 | enumerable: false,
|
13732 | configurable: true
|
13733 | });
|
13734 | Object.defineProperty(__proto, "scaleMultiplier", {
|
13735 | get: function () {
|
13736 | return this._scaleMultiplier;
|
13737 | },
|
13738 | enumerable: false,
|
13739 | configurable: true
|
13740 | });
|
13741 | Object.defineProperty(__proto, "range", {
|
13742 | /**
|
13743 | * Range of the scale
|
13744 | * @readonly
|
13745 | */
|
13746 | get: function () {
|
13747 | return this._motion.range;
|
13748 | },
|
13749 | enumerable: false,
|
13750 | configurable: true
|
13751 | });
|
13752 |
|
13753 | __proto.init = function (_a) {
|
13754 | var view3d = _a.view3d;
|
13755 |
|
13756 | this._initialScale.copy(view3d.model.scene.scale);
|
13757 |
|
13758 | view3d.scene.add(this._ui.mesh);
|
13759 | };
|
13760 |
|
13761 | __proto.destroy = function (_a) {
|
13762 | var view3d = _a.view3d;
|
13763 | view3d.scene.remove(this._ui.mesh);
|
13764 | };
|
13765 |
|
13766 | __proto.setInitialPos = function (coords) {
|
13767 | this._prevCoordDistance = new Vector2().subVectors(coords[0], coords[1]).length();
|
13768 | };
|
13769 | /**
|
13770 | * Enable this control
|
13771 | */
|
13772 |
|
13773 |
|
13774 | __proto.enable = function () {
|
13775 | this._enabled = true;
|
13776 | };
|
13777 | /**
|
13778 | * Disable this control
|
13779 | */
|
13780 |
|
13781 |
|
13782 | __proto.disable = function () {
|
13783 | this._enabled = false;
|
13784 | this.deactivate();
|
13785 | };
|
13786 |
|
13787 | __proto.activate = function (ctx, gesture) {
|
13788 | this._active = true;
|
13789 |
|
13790 | this._ui.show();
|
13791 |
|
13792 | this._updateUIPosition(ctx);
|
13793 | };
|
13794 |
|
13795 | __proto.deactivate = function () {
|
13796 | this._active = false;
|
13797 |
|
13798 | this._ui.hide();
|
13799 |
|
13800 | this._prevCoordDistance = -1;
|
13801 | };
|
13802 | /**
|
13803 | * Update scale range
|
13804 | * @param min Minimum scale
|
13805 | * @param max Maximum scale
|
13806 | */
|
13807 |
|
13808 |
|
13809 | __proto.setRange = function (min, max) {
|
13810 | this._motion.range = {
|
13811 | min: min,
|
13812 | max: max
|
13813 | };
|
13814 | };
|
13815 |
|
13816 | __proto.process = function (ctx, _a) {
|
13817 | var coords = _a.coords;
|
13818 | if (coords.length !== 2 || !this._enabled || !this._active) return;
|
13819 | var motion = this._motion;
|
13820 | var distance = new Vector2().subVectors(coords[0], coords[1]).length();
|
13821 | var delta = distance - this._prevCoordDistance;
|
13822 | motion.setEndDelta(delta);
|
13823 | this._prevCoordDistance = distance;
|
13824 |
|
13825 | this._updateUIPosition(ctx);
|
13826 | };
|
13827 |
|
13828 | __proto.update = function (_a, deltaTime) {
|
13829 | var model = _a.model;
|
13830 | if (!this._enabled || !this._active) return;
|
13831 | var motion = this._motion;
|
13832 | motion.update(deltaTime);
|
13833 | this._scaleMultiplier = motion.val;
|
13834 |
|
13835 | this._ui.updateScale(this._scaleMultiplier);
|
13836 |
|
13837 | model.scene.scale.copy(this.scale);
|
13838 | };
|
13839 |
|
13840 | __proto._updateUIPosition = function (_a) {
|
13841 | var view3d = _a.view3d,
|
13842 | xrCam = _a.xrCam; // Update UI
|
13843 |
|
13844 | var model = view3d.model;
|
13845 | var camPos = new Vector3().setFromMatrixPosition(xrCam.matrixWorld);
|
13846 | var uiPos = model.scene.position.clone().setY(model.bbox.max.y);
|
13847 |
|
13848 | this._ui.updatePosition(uiPos, camPos);
|
13849 | };
|
13850 |
|
13851 | return ARScaleControl;
|
13852 | }();
|
13853 |
|
13854 | /*
|
13855 | * Copyright (c) 2020 NAVER Corp.
|
13856 | * egjs projects are licensed under the MIT license
|
13857 | */
|
13858 | /**
|
13859 | * Ring type indicator for showing where the model's at.
|
13860 | * @category Controls-AR
|
13861 | */
|
13862 |
|
13863 | var FloorIndicator =
|
13864 | /*#__PURE__*/
|
13865 | function () {
|
13866 | /**
|
13867 | * Create new instance of FloorIndicator
|
13868 | * @param {FloorIndicatorOption} [options={}] Options
|
13869 | */
|
13870 | function FloorIndicator(_a) {
|
13871 | var _b = _a === void 0 ? {} : _a,
|
13872 | _c = _b.ringOpacity,
|
13873 | ringOpacity = _c === void 0 ? 0.3 : _c,
|
13874 | _d = _b.dirIndicatorOpacity,
|
13875 | dirIndicatorOpacity = _d === void 0 ? 1 : _d,
|
13876 | _e = _b.fadeoutDuration,
|
13877 | fadeoutDuration = _e === void 0 ? 1000 : _e;
|
13878 |
|
13879 | var deg10 = Math.PI / 18;
|
13880 | var dimmedRingGeomtry = new RingGeometry(0.975, 1, 150, 1, -6 * deg10, 30 * deg10);
|
13881 | var reticle = new CircleGeometry(0.1, 30, 0, Math.PI * 2);
|
13882 | dimmedRingGeomtry.merge(reticle);
|
13883 | var highlightedRingGeometry = new RingGeometry(0.96, 1.015, 30, 1, 25 * deg10, 4 * deg10); // Create little triangle in ring
|
13884 |
|
13885 | var ringVertices = highlightedRingGeometry.vertices;
|
13886 | var trianglePart = ringVertices.slice(Math.floor(11 * ringVertices.length / 16), Math.floor(13 * ringVertices.length / 16));
|
13887 | var firstY = trianglePart[0].y;
|
13888 | var midIndex = Math.floor(trianglePart.length / 2);
|
13889 | trianglePart.forEach(function (vec, vecIdx) {
|
13890 | var offsetAmount = 0.025 * (midIndex - Math.abs(vecIdx - midIndex));
|
13891 | vec.setY(firstY - offsetAmount);
|
13892 | });
|
13893 | var indicatorMat = new Matrix4().makeRotationX(-Math.PI / 2);
|
13894 | var mergedGeometry = new Geometry();
|
13895 | mergedGeometry.merge(dimmedRingGeomtry, indicatorMat, 0);
|
13896 | mergedGeometry.merge(highlightedRingGeometry, indicatorMat, 1);
|
13897 | var dimmedMaterial = new MeshBasicMaterial({
|
13898 | transparent: true,
|
13899 | opacity: ringOpacity,
|
13900 | color: 0xffffff
|
13901 | });
|
13902 | var highlightMaterial = new MeshBasicMaterial({
|
13903 | transparent: true,
|
13904 | opacity: dirIndicatorOpacity,
|
13905 | color: 0xffffff
|
13906 | });
|
13907 | var materials = [dimmedMaterial, highlightMaterial];
|
13908 | this._mesh = new Mesh(mergedGeometry, materials);
|
13909 | this._mesh.matrixAutoUpdate = false;
|
13910 | this._animator = new Motion({
|
13911 | duration: fadeoutDuration
|
13912 | });
|
13913 | this._opacityRange = {
|
13914 | min: ringOpacity,
|
13915 | max: dirIndicatorOpacity
|
13916 | };
|
13917 | }
|
13918 |
|
13919 | var __proto = FloorIndicator.prototype;
|
13920 | Object.defineProperty(__proto, "mesh", {
|
13921 | /**
|
13922 | * Ring mesh
|
13923 | */
|
13924 | get: function () {
|
13925 | return this._mesh;
|
13926 | },
|
13927 | enumerable: false,
|
13928 | configurable: true
|
13929 | });
|
13930 |
|
13931 | __proto.update = function (_a) {
|
13932 | var delta = _a.delta,
|
13933 | scale = _a.scale,
|
13934 | position = _a.position,
|
13935 | rotation = _a.rotation;
|
13936 | var mesh = this._mesh;
|
13937 | var animator = this._animator;
|
13938 | if (!this._mesh.visible) return;
|
13939 | animator.update(delta);
|
13940 | var materials = this._mesh.material;
|
13941 | var minOpacityMat = materials[0];
|
13942 | var maxOpacityMat = materials[1];
|
13943 | var opacityRange = this._opacityRange;
|
13944 | minOpacityMat.opacity = animator.val * opacityRange.min;
|
13945 | maxOpacityMat.opacity = animator.val * opacityRange.max;
|
13946 |
|
13947 | if (animator.val <= 0) {
|
13948 | mesh.visible = false;
|
13949 | } // Update mesh
|
13950 |
|
13951 |
|
13952 | mesh.scale.setScalar(scale);
|
13953 | mesh.position.copy(position);
|
13954 | mesh.quaternion.copy(rotation);
|
13955 | mesh.updateMatrix();
|
13956 | };
|
13957 |
|
13958 | __proto.show = function () {
|
13959 | this._mesh.visible = true;
|
13960 |
|
13961 | this._animator.reset(1);
|
13962 | };
|
13963 |
|
13964 | __proto.fadeout = function () {
|
13965 | this._animator.setEndDelta(-1);
|
13966 | };
|
13967 |
|
13968 | return FloorIndicator;
|
13969 | }();
|
13970 |
|
13971 | /*
|
13972 | * Copyright (c) 2020 NAVER Corp.
|
13973 | * egjs projects are licensed under the MIT license
|
13974 | */
|
13975 | var GESTURE;
|
13976 |
|
13977 | (function (GESTURE) {
|
13978 | GESTURE[GESTURE["NONE"] = 0] = "NONE";
|
13979 | GESTURE[GESTURE["ONE_FINGER_HORIZONTAL"] = 1] = "ONE_FINGER_HORIZONTAL";
|
13980 | GESTURE[GESTURE["ONE_FINGER_VERTICAL"] = 2] = "ONE_FINGER_VERTICAL";
|
13981 | GESTURE[GESTURE["ONE_FINGER"] = 3] = "ONE_FINGER";
|
13982 | GESTURE[GESTURE["TWO_FINGER_HORIZONTAL"] = 4] = "TWO_FINGER_HORIZONTAL";
|
13983 | GESTURE[GESTURE["TWO_FINGER_VERTICAL"] = 8] = "TWO_FINGER_VERTICAL";
|
13984 | GESTURE[GESTURE["TWO_FINGER"] = 12] = "TWO_FINGER";
|
13985 | GESTURE[GESTURE["PINCH"] = 16] = "PINCH";
|
13986 | })(GESTURE || (GESTURE = {}));
|
13987 |
|
13988 | /*
|
13989 | * Copyright (c) 2020 NAVER Corp.
|
13990 | * egjs projects are licensed under the MIT license
|
13991 | */
|
13992 | var STATE$1;
|
13993 |
|
13994 | (function (STATE) {
|
13995 | STATE[STATE["WAITING"] = 0] = "WAITING";
|
13996 | STATE[STATE["IN_DEADZONE"] = 1] = "IN_DEADZONE";
|
13997 | STATE[STATE["OUT_OF_DEADZONE"] = 2] = "OUT_OF_DEADZONE";
|
13998 | })(STATE$1 || (STATE$1 = {}));
|
13999 | /**
|
14000 | * Deadzone checker for deadzone-based controls
|
14001 | * @category Controls-AR
|
14002 | */
|
14003 |
|
14004 |
|
14005 | var DeadzoneChecker =
|
14006 | /*#__PURE__*/
|
14007 | function () {
|
14008 | /**
|
14009 | * Create new DeadzoneChecker
|
14010 | * @param {DeadzoneCheckerOption} [options={}] Options
|
14011 | */
|
14012 | function DeadzoneChecker(_a) {
|
14013 | var _b = (_a === void 0 ? {} : _a).size,
|
14014 | size = _b === void 0 ? 0.1 : _b; // Internal States
|
14015 |
|
14016 | this._state = STATE$1.WAITING;
|
14017 | this._detectedGesture = GESTURE.NONE;
|
14018 | this._testingGestures = GESTURE.NONE;
|
14019 | this._lastFingerCount = 0;
|
14020 | this._aspect = 1; // Store two prev positions, as it should be maintained separately
|
14021 |
|
14022 | this._prevOneFingerPos = new Vector2();
|
14023 | this._prevTwoFingerPos = new Vector2();
|
14024 | this._initialTwoFingerDistance = 0;
|
14025 | this._prevOneFingerPosInitialized = false;
|
14026 | this._prevTwoFingerPosInitialized = false;
|
14027 | this._size = size;
|
14028 | }
|
14029 |
|
14030 | var __proto = DeadzoneChecker.prototype;
|
14031 | Object.defineProperty(__proto, "size", {
|
14032 | /**
|
14033 | * Size of the deadzone.
|
14034 | * @type number
|
14035 | */
|
14036 | get: function () {
|
14037 | return this._size;
|
14038 | },
|
14039 | set: function (val) {
|
14040 | this._size = val;
|
14041 | },
|
14042 | enumerable: false,
|
14043 | configurable: true
|
14044 | });
|
14045 | Object.defineProperty(__proto, "inDeadzone", {
|
14046 | get: function () {
|
14047 | return this._state === STATE$1.IN_DEADZONE;
|
14048 | },
|
14049 | enumerable: false,
|
14050 | configurable: true
|
14051 | });
|
14052 | /**
|
14053 | * Set screen aspect(height / width)
|
14054 | * @param aspect Screen aspect value
|
14055 | */
|
14056 |
|
14057 | __proto.setAspect = function (aspect) {
|
14058 | this._aspect = aspect;
|
14059 | };
|
14060 |
|
14061 | __proto.setFirstInput = function (inputs) {
|
14062 | var fingerCount = inputs.length;
|
14063 |
|
14064 | if (fingerCount === 1 && !this._prevOneFingerPosInitialized) {
|
14065 | this._prevOneFingerPos.copy(inputs[0]);
|
14066 |
|
14067 | this._prevOneFingerPosInitialized = true;
|
14068 | } else if (fingerCount === 2 && !this._prevTwoFingerPosInitialized) {
|
14069 | this._prevTwoFingerPos.copy(new Vector2().addVectors(inputs[0], inputs[1]).multiplyScalar(0.5));
|
14070 |
|
14071 | this._initialTwoFingerDistance = new Vector2().subVectors(inputs[0], inputs[1]).length();
|
14072 | this._prevTwoFingerPosInitialized = true;
|
14073 | }
|
14074 |
|
14075 | this._lastFingerCount = fingerCount;
|
14076 | this._state = STATE$1.IN_DEADZONE;
|
14077 | };
|
14078 |
|
14079 | __proto.addTestingGestures = function () {
|
14080 | var gestures = [];
|
14081 |
|
14082 | for (var _i = 0; _i < arguments.length; _i++) {
|
14083 | gestures[_i] = arguments[_i];
|
14084 | }
|
14085 |
|
14086 | this._testingGestures = this._testingGestures | gestures.reduce(function (gesture, accumulated) {
|
14087 | return gesture | accumulated;
|
14088 | }, GESTURE.NONE);
|
14089 | };
|
14090 |
|
14091 | __proto.cleanup = function () {
|
14092 | this._testingGestures = GESTURE.NONE;
|
14093 | this._lastFingerCount = 0;
|
14094 | this._prevOneFingerPosInitialized = false;
|
14095 | this._prevTwoFingerPosInitialized = false;
|
14096 | this._initialTwoFingerDistance = 0;
|
14097 | this._detectedGesture = GESTURE.NONE;
|
14098 | this._state = STATE$1.WAITING;
|
14099 | };
|
14100 |
|
14101 | __proto.applyScreenAspect = function (inputs) {
|
14102 | var aspect = this._aspect;
|
14103 | inputs.forEach(function (input) {
|
14104 | if (aspect > 1) {
|
14105 | input.setY(input.y * aspect);
|
14106 | } else {
|
14107 | input.setX(input.x / aspect);
|
14108 | }
|
14109 | });
|
14110 | };
|
14111 |
|
14112 | __proto.check = function (inputs) {
|
14113 | var state = this._state;
|
14114 | var deadzone = this._size;
|
14115 | var testingGestures = this._testingGestures;
|
14116 | var lastFingerCount = this._lastFingerCount;
|
14117 | var fingerCount = inputs.length;
|
14118 |
|
14119 | if (state === STATE$1.OUT_OF_DEADZONE) {
|
14120 | return this._detectedGesture;
|
14121 | }
|
14122 |
|
14123 | this._lastFingerCount = fingerCount;
|
14124 | this.applyScreenAspect(inputs);
|
14125 |
|
14126 | if (fingerCount !== lastFingerCount) {
|
14127 | this.setFirstInput(inputs);
|
14128 | return GESTURE.NONE;
|
14129 | }
|
14130 |
|
14131 | if (fingerCount === 1) {
|
14132 | var input = inputs[0];
|
14133 |
|
14134 | var prevPos = this._prevOneFingerPos.clone();
|
14135 |
|
14136 | var diff = new Vector2().subVectors(input, prevPos);
|
14137 |
|
14138 | if (diff.length() > deadzone) {
|
14139 | if (Math.abs(diff.x) > Math.abs(diff.y)) {
|
14140 | if (GESTURE.ONE_FINGER_HORIZONTAL & testingGestures) {
|
14141 | this._detectedGesture = GESTURE.ONE_FINGER_HORIZONTAL;
|
14142 | }
|
14143 | } else {
|
14144 | if (GESTURE.ONE_FINGER_VERTICAL & testingGestures) {
|
14145 | this._detectedGesture = GESTURE.ONE_FINGER_VERTICAL;
|
14146 | }
|
14147 | }
|
14148 | }
|
14149 | } else if (fingerCount === 2) {
|
14150 | var middle = new Vector2().addVectors(inputs[1], inputs[0]).multiplyScalar(0.5);
|
14151 |
|
14152 | var prevPos = this._prevTwoFingerPos.clone();
|
14153 |
|
14154 | var diff = new Vector2().subVectors(middle, prevPos);
|
14155 |
|
14156 | if (diff.length() > deadzone) {
|
14157 | if (Math.abs(diff.x) > Math.abs(diff.y)) {
|
14158 | if (GESTURE.TWO_FINGER_HORIZONTAL & testingGestures) {
|
14159 | this._detectedGesture = GESTURE.TWO_FINGER_HORIZONTAL;
|
14160 | }
|
14161 | } else {
|
14162 | if (GESTURE.TWO_FINGER_VERTICAL & testingGestures) {
|
14163 | this._detectedGesture = GESTURE.TWO_FINGER_VERTICAL;
|
14164 | }
|
14165 | }
|
14166 | }
|
14167 |
|
14168 | var distance = new Vector2().subVectors(inputs[1], inputs[0]).length();
|
14169 |
|
14170 | if (Math.abs(distance - this._initialTwoFingerDistance) > deadzone) {
|
14171 | if (GESTURE.PINCH & testingGestures) {
|
14172 | this._detectedGesture = GESTURE.PINCH;
|
14173 | }
|
14174 | }
|
14175 | }
|
14176 |
|
14177 | if (this._detectedGesture !== GESTURE.NONE) {
|
14178 | this._state = STATE$1.OUT_OF_DEADZONE;
|
14179 | }
|
14180 |
|
14181 | return this._detectedGesture;
|
14182 | };
|
14183 |
|
14184 | return DeadzoneChecker;
|
14185 | }();
|
14186 |
|
14187 | /*
|
14188 | * Copyright (c) 2020 NAVER Corp.
|
14189 | * egjs projects are licensed under the MIT license
|
14190 | */
|
14191 | /**
|
14192 | * AR control for {@link FloorARSession}
|
14193 | * @category Controls-AR
|
14194 | */
|
14195 |
|
14196 | var ARFloorControl =
|
14197 | /*#__PURE__*/
|
14198 | function () {
|
14199 | /**
|
14200 | * Create new instance of ARFloorControl
|
14201 | * @param {ARFloorControlOption} options Options
|
14202 | */
|
14203 | function ARFloorControl(options) {
|
14204 | var _this = this;
|
14205 |
|
14206 | if (options === void 0) {
|
14207 | options = {};
|
14208 | }
|
14209 |
|
14210 | this._enabled = true;
|
14211 | this._initialized = false;
|
14212 | this._modelHit = false;
|
14213 | this._hitTestSource = null;
|
14214 |
|
14215 | this.onSelectStart = function (ctx) {
|
14216 | var view3d = ctx.view3d,
|
14217 | frame = ctx.frame,
|
14218 | xrCam = ctx.xrCam,
|
14219 | referenceSpace = ctx.referenceSpace;
|
14220 | var hitTestSource = _this._hitTestSource;
|
14221 | if (!hitTestSource || !_this._enabled) return;
|
14222 | var deadzoneChecker = _this._deadzoneChecker;
|
14223 | var rotateControl = _this._rotateControl;
|
14224 | var translateControl = _this._translateControl;
|
14225 | var scaleControl = _this._scaleControl; // Update deadzone testing gestures
|
14226 |
|
14227 | if (rotateControl.enabled) {
|
14228 | deadzoneChecker.addTestingGestures(GESTURE.ONE_FINGER);
|
14229 | }
|
14230 |
|
14231 | if (translateControl.enabled) {
|
14232 | deadzoneChecker.addTestingGestures(GESTURE.ONE_FINGER);
|
14233 | }
|
14234 |
|
14235 | if (scaleControl.enabled) {
|
14236 | deadzoneChecker.addTestingGestures(GESTURE.PINCH);
|
14237 | }
|
14238 |
|
14239 | var hitResults = frame.getHitTestResultsForTransientInput(hitTestSource);
|
14240 |
|
14241 | var coords = _this._hitResultToVector(hitResults);
|
14242 |
|
14243 | deadzoneChecker.applyScreenAspect(coords);
|
14244 | deadzoneChecker.setFirstInput(coords);
|
14245 |
|
14246 | if (coords.length === 1) {
|
14247 | // Check finger is on the model
|
14248 | var modelBbox = view3d.model.bbox;
|
14249 | var targetRayPose = frame.getPose(hitResults[0].inputSource.targetRaySpace, referenceSpace);
|
14250 | var camPos = new Vector3().setFromMatrixPosition(xrCam.matrixWorld);
|
14251 | var fingerDir = new Vector3().copy(targetRayPose.transform.position).sub(camPos).normalize();
|
14252 | var fingerRay = new Ray(camPos, fingerDir);
|
14253 | var intersection = fingerRay.intersectBox(modelBbox, new Vector3());
|
14254 |
|
14255 | if (intersection) {
|
14256 | // Touch point intersected with model
|
14257 | _this._modelHit = true;
|
14258 | }
|
14259 | }
|
14260 |
|
14261 | _this._floorIndicator.show();
|
14262 | };
|
14263 |
|
14264 | this.onSelectEnd = function () {
|
14265 | _this.deactivate();
|
14266 |
|
14267 | _this._floorIndicator.fadeout();
|
14268 | };
|
14269 |
|
14270 | this._rotateControl = new ARSwirlControl(__assign({
|
14271 | showIndicator: false
|
14272 | }, options.rotate));
|
14273 | this._translateControl = new ARFloorTranslateControl(options.translate);
|
14274 | this._scaleControl = new ARScaleControl(options.scale);
|
14275 | this._floorIndicator = new FloorIndicator(options.floorIndicator);
|
14276 | this._deadzoneChecker = new DeadzoneChecker(options.deadzone);
|
14277 | }
|
14278 |
|
14279 | var __proto = ARFloorControl.prototype;
|
14280 | Object.defineProperty(__proto, "enabled", {
|
14281 | /**
|
14282 | * Return whether this control is enabled or not
|
14283 | */
|
14284 | get: function () {
|
14285 | return this._enabled;
|
14286 | },
|
14287 | enumerable: false,
|
14288 | configurable: true
|
14289 | });
|
14290 | Object.defineProperty(__proto, "rotate", {
|
14291 | /**
|
14292 | * {@link ARSwirlControl} in this control
|
14293 | */
|
14294 | get: function () {
|
14295 | return this._rotateControl;
|
14296 | },
|
14297 | enumerable: false,
|
14298 | configurable: true
|
14299 | });
|
14300 | Object.defineProperty(__proto, "translate", {
|
14301 | /**
|
14302 | * {@link ARFloorTranslateControl} in this control
|
14303 | */
|
14304 | get: function () {
|
14305 | return this._translateControl;
|
14306 | },
|
14307 | enumerable: false,
|
14308 | configurable: true
|
14309 | });
|
14310 | Object.defineProperty(__proto, "scale", {
|
14311 | /**
|
14312 | * {@link ARScaleControl} in this control
|
14313 | */
|
14314 | get: function () {
|
14315 | return this._scaleControl;
|
14316 | },
|
14317 | enumerable: false,
|
14318 | configurable: true
|
14319 | });
|
14320 | Object.defineProperty(__proto, "controls", {
|
14321 | get: function () {
|
14322 | return [this._rotateControl, this._translateControl, this._scaleControl];
|
14323 | },
|
14324 | enumerable: false,
|
14325 | configurable: true
|
14326 | });
|
14327 |
|
14328 | __proto.init = function (ctx, initialFloorPos) {
|
14329 | var _this = this;
|
14330 |
|
14331 | var session = ctx.session,
|
14332 | view3d = ctx.view3d,
|
14333 | size = ctx.size;
|
14334 | this.controls.forEach(function (control) {
|
14335 | return control.init(ctx);
|
14336 | });
|
14337 |
|
14338 | this._translateControl.initFloorPosition(initialFloorPos);
|
14339 |
|
14340 | this._deadzoneChecker.setAspect(size.height / size.width);
|
14341 |
|
14342 | view3d.scene.add(this._floorIndicator.mesh);
|
14343 | this._initialized = true;
|
14344 | session.requestHitTestSourceForTransientInput({
|
14345 | profile: INPUT_PROFILE.TOUCH
|
14346 | }).then(function (transientHitTestSource) {
|
14347 | _this._hitTestSource = transientHitTestSource;
|
14348 | });
|
14349 | };
|
14350 | /**
|
14351 | * Destroy this control and deactivate it
|
14352 | * @param view3d Instance of the {@link View3D}
|
14353 | */
|
14354 |
|
14355 |
|
14356 | __proto.destroy = function (ctx) {
|
14357 | if (!this._initialized) return;
|
14358 |
|
14359 | if (this._hitTestSource) {
|
14360 | this._hitTestSource.cancel();
|
14361 |
|
14362 | this._hitTestSource = null;
|
14363 | }
|
14364 |
|
14365 | ctx.view3d.scene.remove(this._floorIndicator.mesh);
|
14366 | this.deactivate();
|
14367 | this.controls.forEach(function (control) {
|
14368 | return control.destroy(ctx);
|
14369 | });
|
14370 | this._initialized = false;
|
14371 | };
|
14372 |
|
14373 | __proto.deactivate = function () {
|
14374 | this._modelHit = false;
|
14375 |
|
14376 | this._deadzoneChecker.cleanup();
|
14377 |
|
14378 | this.controls.forEach(function (control) {
|
14379 | return control.deactivate();
|
14380 | });
|
14381 | };
|
14382 | /**
|
14383 | * Enable this control
|
14384 | */
|
14385 |
|
14386 |
|
14387 | __proto.enable = function () {
|
14388 | this._enabled = true;
|
14389 | };
|
14390 | /**
|
14391 | * Disable this control
|
14392 | */
|
14393 |
|
14394 |
|
14395 | __proto.disable = function () {
|
14396 | this._enabled = false;
|
14397 | this.deactivate();
|
14398 | };
|
14399 |
|
14400 | __proto.update = function (ctx) {
|
14401 | var view3d = ctx.view3d,
|
14402 | session = ctx.session,
|
14403 | frame = ctx.frame;
|
14404 | var hitTestSource = this._hitTestSource;
|
14405 | if (!hitTestSource || !view3d.model) return;
|
14406 | var deadzoneChecker = this._deadzoneChecker;
|
14407 | var inputSources = session.inputSources;
|
14408 | var hitResults = frame.getHitTestResultsForTransientInput(hitTestSource);
|
14409 |
|
14410 | var coords = this._hitResultToVector(hitResults);
|
14411 |
|
14412 | var xrInputs = {
|
14413 | coords: coords,
|
14414 | inputSources: inputSources,
|
14415 | hitResults: hitResults
|
14416 | };
|
14417 |
|
14418 | if (deadzoneChecker.inDeadzone) {
|
14419 | this._checkDeadzone(ctx, xrInputs);
|
14420 | } else {
|
14421 | this._processInput(ctx, xrInputs);
|
14422 | }
|
14423 |
|
14424 | this._updateControls(ctx);
|
14425 | };
|
14426 |
|
14427 | __proto._checkDeadzone = function (ctx, _a) {
|
14428 | var coords = _a.coords;
|
14429 |
|
14430 | var gesture = this._deadzoneChecker.check(coords.map(function (coord) {
|
14431 | return coord.clone();
|
14432 | }));
|
14433 |
|
14434 | var rotateControl = this._rotateControl;
|
14435 | var translateControl = this._translateControl;
|
14436 | var scaleControl = this._scaleControl;
|
14437 | if (gesture === GESTURE.NONE) return;
|
14438 |
|
14439 | switch (gesture) {
|
14440 | case GESTURE.ONE_FINGER_HORIZONTAL:
|
14441 | case GESTURE.ONE_FINGER_VERTICAL:
|
14442 | if (this._modelHit) {
|
14443 | translateControl.activate(ctx, gesture);
|
14444 | translateControl.setInitialPos(coords);
|
14445 | } else {
|
14446 | rotateControl.activate(ctx, gesture);
|
14447 | rotateControl.setInitialPos(coords);
|
14448 | }
|
14449 |
|
14450 | break;
|
14451 |
|
14452 | case GESTURE.PINCH:
|
14453 | scaleControl.activate(ctx, gesture);
|
14454 | scaleControl.setInitialPos(coords);
|
14455 | break;
|
14456 | }
|
14457 | };
|
14458 |
|
14459 | __proto._processInput = function (ctx, inputs) {
|
14460 | this.controls.forEach(function (control) {
|
14461 | return control.process(ctx, inputs);
|
14462 | });
|
14463 | };
|
14464 |
|
14465 | __proto._updateControls = function (ctx) {
|
14466 | var view3d = ctx.view3d,
|
14467 | model = ctx.model,
|
14468 | delta = ctx.delta;
|
14469 | var deltaMilisec = delta * 1000;
|
14470 | this.controls.forEach(function (control) {
|
14471 | return control.update(ctx, deltaMilisec);
|
14472 | });
|
14473 | model.scene.updateMatrix();
|
14474 | var modelRotation = this._rotateControl.rotation;
|
14475 | var floorPosition = this._translateControl.floorPosition;
|
14476 | view3d.scene.update(model, {
|
14477 | floorPosition: floorPosition
|
14478 | }); // Get a scaled bbox, which only has scale applied on it.
|
14479 |
|
14480 | var scaleControl = this._scaleControl;
|
14481 | var scaledBbox = model.initialBbox;
|
14482 | scaledBbox.min.multiply(scaleControl.scale);
|
14483 | scaledBbox.max.multiply(scaleControl.scale);
|
14484 | var floorIndicator = this._floorIndicator;
|
14485 | var boundingSphere = scaledBbox.getBoundingSphere(new Sphere());
|
14486 | floorIndicator.update({
|
14487 | delta: deltaMilisec,
|
14488 | scale: boundingSphere.radius,
|
14489 | position: floorPosition,
|
14490 | rotation: modelRotation
|
14491 | });
|
14492 | };
|
14493 |
|
14494 | __proto._hitResultToVector = function (hitResults) {
|
14495 | return hitResults.map(function (input) {
|
14496 | return new Vector2().set(input.inputSource.gamepad.axes[0], -input.inputSource.gamepad.axes[1]);
|
14497 | });
|
14498 | };
|
14499 |
|
14500 | return ARFloorControl;
|
14501 | }();
|
14502 |
|
14503 | /*
|
14504 | * Copyright (c) 2020 NAVER Corp.
|
14505 | * egjs projects are licensed under the MIT license
|
14506 | */
|
14507 | /**
|
14508 | * WebXR based AR session which puts model on the detected floor.
|
14509 | * @category XR
|
14510 | * @fires WebARSession#start
|
14511 | * @fires WebARSession#end
|
14512 | * @fires WebARSession#canPlace
|
14513 | * @fires WebARSession#modelPlaced
|
14514 | */
|
14515 |
|
14516 | var FloorARSession =
|
14517 | /*#__PURE__*/
|
14518 | function (_super) {
|
14519 | __extends(FloorARSession, _super);
|
14520 | /**
|
14521 | * Create new instance of FloorARSession
|
14522 | * @param {FloorARSessionOption} options Options
|
14523 | */
|
14524 |
|
14525 |
|
14526 | function FloorARSession(options) {
|
14527 | if (options === void 0) {
|
14528 | options = {};
|
14529 | }
|
14530 |
|
14531 | var _this = _super.call(this, options) || this;
|
14532 |
|
14533 | _this.onStart = function (ctx) {
|
14534 | var view3d = ctx.view3d,
|
14535 | session = ctx.session;
|
14536 |
|
14537 | _super.prototype.onStart.call(_this, ctx);
|
14538 |
|
14539 | _this._control = new ARFloorControl(_this._options);
|
14540 | view3d.scene.hide();
|
14541 |
|
14542 | _this._hitTest.init(session);
|
14543 | };
|
14544 |
|
14545 | _this.onEnd = function (ctx) {
|
14546 | var view3d = ctx.view3d,
|
14547 | session = ctx.session;
|
14548 |
|
14549 | _super.prototype.onEnd.call(_this, ctx);
|
14550 |
|
14551 | _this._renderContext = null;
|
14552 | _this._modelPlaced = false;
|
14553 | session.removeEventListener(EVENTS$1.SELECT_START, _this._onSelectStart);
|
14554 | session.removeEventListener(EVENTS$1.SELECT_END, _this._onSelectEnd);
|
14555 |
|
14556 | _this._hitTest.destroy();
|
14557 |
|
14558 | _this._control.destroy(ctx);
|
14559 |
|
14560 | _this._control = null;
|
14561 | view3d.scene.show();
|
14562 | };
|
14563 |
|
14564 | _this._beforeRender = function (ctx) {
|
14565 | _this._renderContext = ctx;
|
14566 |
|
14567 | if (!_this._modelPlaced) {
|
14568 | _this._initModelPosition(ctx);
|
14569 | } else {
|
14570 | _this._control.update(ctx);
|
14571 | }
|
14572 | };
|
14573 |
|
14574 | _this._onSelectStart = function (e) {
|
14575 | _this._control.onSelectStart(__assign(__assign({}, _this._renderContext), {
|
14576 | frame: e.frame
|
14577 | }));
|
14578 | };
|
14579 |
|
14580 | _this._onSelectEnd = function () {
|
14581 | _this._control.onSelectEnd();
|
14582 | };
|
14583 |
|
14584 | _this._control = null;
|
14585 | _this._renderContext = null;
|
14586 | _this._modelPlaced = false;
|
14587 | _this._hitTest = new HitTest();
|
14588 | _this._features = merge(_this._features, _this._hitTest.features);
|
14589 | _this._options = options;
|
14590 | return _this;
|
14591 | }
|
14592 |
|
14593 | var __proto = FloorARSession.prototype;
|
14594 | Object.defineProperty(__proto, "control", {
|
14595 | /**
|
14596 | * {@link ARControl} instance of this session
|
14597 | * @type ARFloorControl | null
|
14598 | */
|
14599 | get: function () {
|
14600 | return this._control;
|
14601 | },
|
14602 | enumerable: false,
|
14603 | configurable: true
|
14604 | });
|
14605 |
|
14606 | __proto._initModelPosition = function (ctx) {
|
14607 | var _a;
|
14608 |
|
14609 | var view3d = ctx.view3d,
|
14610 | frame = ctx.frame,
|
14611 | session = ctx.session;
|
14612 | var model = view3d.model;
|
14613 | var hitTest = this._hitTest; // Make sure the model is loaded
|
14614 |
|
14615 | if (!hitTest.ready || !model) return;
|
14616 | var control = this._control;
|
14617 | var referenceSpace = view3d.renderer.threeRenderer.xr.getReferenceSpace();
|
14618 | var hitTestResults = hitTest.getResults(frame);
|
14619 | if (hitTestResults.length <= 0) return;
|
14620 | var hit = hitTestResults[0];
|
14621 | var hitMatrix = new Matrix4().fromArray(hit.getPose(referenceSpace).transform.matrix); // If transformed coords space's y axis is not facing up, don't use it.
|
14622 |
|
14623 | if (hitMatrix.elements[5] < 0.75) return;
|
14624 | var modelRoot = model.scene;
|
14625 | var hitPosition = new Vector3().setFromMatrixPosition(hitMatrix); // Reset rotation & update position
|
14626 |
|
14627 | modelRoot.quaternion.set(0, 0, 0, 1);
|
14628 | modelRoot.position.copy(hitPosition);
|
14629 | modelRoot.position.setY(modelRoot.position.y - model.bbox.min.y);
|
14630 | modelRoot.updateMatrix();
|
14631 | view3d.scene.update(model);
|
14632 | view3d.scene.show();
|
14633 | this.emit("canPlace"); // Don't need it
|
14634 |
|
14635 | hitTest.destroy();
|
14636 | session.addEventListener(EVENTS$1.SELECT_START, this._onSelectStart);
|
14637 | session.addEventListener(EVENTS$1.SELECT_END, this._onSelectEnd);
|
14638 | (_a = this._domOverlay) === null || _a === void 0 ? void 0 : _a.hideLoading();
|
14639 | this._modelPlaced = true;
|
14640 | this.emit("modelPlaced"); // Show scale up animation
|
14641 |
|
14642 | var originalModelScale = modelRoot.scale.clone();
|
14643 | var scaleUpAnimation = new Animation({
|
14644 | context: session
|
14645 | });
|
14646 | scaleUpAnimation.on("progress", function (evt) {
|
14647 | var newScale = originalModelScale.clone().multiplyScalar(evt.easedProgress);
|
14648 | modelRoot.scale.copy(newScale);
|
14649 | });
|
14650 | scaleUpAnimation.on("finish", function () {
|
14651 | modelRoot.scale.copy(originalModelScale);
|
14652 | control.init(ctx, hitPosition);
|
14653 | });
|
14654 | scaleUpAnimation.start();
|
14655 | };
|
14656 |
|
14657 | return FloorARSession;
|
14658 | }(WebARSession);
|
14659 |
|
14660 | /*
|
14661 | * Copyright (c) 2020 NAVER Corp.
|
14662 | * egjs projects are licensed under the MIT license
|
14663 | */
|
14664 | /**
|
14665 | * Arrow indicator for AR model translatioon.
|
14666 | * @category Controls-AR
|
14667 | */
|
14668 |
|
14669 | var ArrowIndicator =
|
14670 | /*#__PURE__*/
|
14671 | function () {
|
14672 | /**
|
14673 | * Create new ArrowIndicator
|
14674 | * @param {ArrowIndicatorOption} [options={}] Options
|
14675 | */
|
14676 | function ArrowIndicator(_a) {
|
14677 | var _this = this;
|
14678 |
|
14679 | var _b = (_a === void 0 ? {} : _a).color,
|
14680 | color = _b === void 0 ? 0xffffff : _b;
|
14681 | var bodyGeometry = new CylinderBufferGeometry(0.1, 0.1, 1);
|
14682 | var coneGeometry = new CylinderBufferGeometry(0, 0.5, 1, 30, 1);
|
14683 | bodyGeometry.translate(0, 0.5, 0);
|
14684 | coneGeometry.translate(0, 1.5, 0);
|
14685 | var body = new Mesh(bodyGeometry, new MeshBasicMaterial({
|
14686 | color: color
|
14687 | }));
|
14688 | var cone = new Mesh(coneGeometry, new MeshBasicMaterial({
|
14689 | color: color
|
14690 | }));
|
14691 | var arrow = new Group();
|
14692 | arrow.add(body);
|
14693 | arrow.add(cone);
|
14694 | this._arrows = [arrow];
|
14695 | this._obj = new Group();
|
14696 |
|
14697 | this._obj.add(arrow);
|
14698 |
|
14699 | range(3).forEach(function (idx) {
|
14700 | var copied = arrow.clone(true);
|
14701 | copied.rotateZ(Math.PI / 2 * (idx + 1));
|
14702 |
|
14703 | _this._obj.add(copied);
|
14704 |
|
14705 | _this._arrows.push(copied);
|
14706 | });
|
14707 | this.hide();
|
14708 | }
|
14709 |
|
14710 | var __proto = ArrowIndicator.prototype;
|
14711 | Object.defineProperty(__proto, "object", {
|
14712 | /**
|
14713 | * {@link https://threejs.org/docs/index.html#api/en/objects/Group THREE.Group} object that contains arrows.
|
14714 | */
|
14715 | get: function () {
|
14716 | return this._obj;
|
14717 | },
|
14718 | enumerable: false,
|
14719 | configurable: true
|
14720 | });
|
14721 | /**
|
14722 | * Show indicator
|
14723 | */
|
14724 |
|
14725 | __proto.show = function () {
|
14726 | this._obj.visible = true;
|
14727 | };
|
14728 | /**
|
14729 | * Hide indicator
|
14730 | */
|
14731 |
|
14732 |
|
14733 | __proto.hide = function () {
|
14734 | this._obj.visible = false;
|
14735 | };
|
14736 | /**
|
14737 | * Change the center of the arrows to a given position
|
14738 | * @param position Position to set as center of the arrows
|
14739 | */
|
14740 |
|
14741 |
|
14742 | __proto.updatePosition = function (position) {
|
14743 | this._obj.position.copy(position);
|
14744 | };
|
14745 | /**
|
14746 | * Update the arrow's offset from the center
|
14747 | * @param offset Offset vector.
|
14748 | */
|
14749 |
|
14750 |
|
14751 | __proto.updateOffset = function (offset) {
|
14752 | this._arrows.forEach(function (arrow, idx) {
|
14753 | var facingDirection = new Vector3(0, 1, 0).applyQuaternion(arrow.quaternion);
|
14754 | var facingOffset = facingDirection.multiply(offset);
|
14755 | arrow.position.copy(facingOffset);
|
14756 | });
|
14757 | };
|
14758 | /**
|
14759 | * Update arrow's scale
|
14760 | * @param scale Scale vector
|
14761 | */
|
14762 |
|
14763 |
|
14764 | __proto.updateScale = function (scale) {
|
14765 | this._arrows.forEach(function (arrow) {
|
14766 | return arrow.scale.setScalar(scale);
|
14767 | });
|
14768 | };
|
14769 | /**
|
14770 | * Update arrow's rotation.
|
14771 | * @param rotation Quaternion value to rotate arrows.
|
14772 | */
|
14773 |
|
14774 |
|
14775 | __proto.updateRotation = function (rotation) {
|
14776 | this._obj.quaternion.copy(rotation);
|
14777 | };
|
14778 |
|
14779 | return ArrowIndicator;
|
14780 | }();
|
14781 |
|
14782 | /*
|
14783 | * Copyright (c) 2020 NAVER Corp.
|
14784 | * egjs projects are licensed under the MIT license
|
14785 | */
|
14786 | /**
|
14787 | * Model's translation(position) control for {@link ARWallControl}
|
14788 | * @category Controls-AR
|
14789 | */
|
14790 |
|
14791 | var ARWallTranslateControl =
|
14792 | /*#__PURE__*/
|
14793 | function () {
|
14794 | /**
|
14795 | * Create new instance of ARTranslateControl
|
14796 | * @param {ARWallTranslateControlOption} [options={}] Options
|
14797 | */
|
14798 | function ARWallTranslateControl(options) {
|
14799 | if (options === void 0) {
|
14800 | options = {};
|
14801 | }
|
14802 |
|
14803 | this.position = new Vector3();
|
14804 | this.wallPosition = new Vector3();
|
14805 | this.hitRotation = new Quaternion(); // Global Y guaranteed rotation matrix
|
14806 |
|
14807 | this.wallRotation = new Quaternion(); // Options
|
14808 | // Internal states
|
14809 |
|
14810 | this._dragPlane = new Plane();
|
14811 | this._enabled = true;
|
14812 | this._active = false;
|
14813 | this._initialPos = new Vector2();
|
14814 | this._arrowIndicator = new ArrowIndicator(options.arrow);
|
14815 | }
|
14816 |
|
14817 | var __proto = ARWallTranslateControl.prototype;
|
14818 | Object.defineProperty(__proto, "enabled", {
|
14819 | /**
|
14820 | * Whether this control is enabled or not
|
14821 | * @readonly
|
14822 | */
|
14823 | get: function () {
|
14824 | return this._enabled;
|
14825 | },
|
14826 | enumerable: false,
|
14827 | configurable: true
|
14828 | });
|
14829 |
|
14830 | __proto.initWallTransform = function (_a) {
|
14831 | var hitPosition = _a.hitPosition,
|
14832 | hitRotation = _a.hitRotation,
|
14833 | modelPosition = _a.modelPosition,
|
14834 | wallRotation = _a.wallRotation;
|
14835 | this.position.copy(modelPosition);
|
14836 | this.hitRotation.copy(hitRotation);
|
14837 | this.wallPosition.copy(hitPosition);
|
14838 | this.wallRotation.copy(wallRotation);
|
14839 | var wallNormal = new Vector3(0, 1, 0).applyQuaternion(wallRotation);
|
14840 |
|
14841 | this._dragPlane.set(wallNormal, -wallNormal.dot(modelPosition));
|
14842 | };
|
14843 |
|
14844 | __proto.init = function (_a) {
|
14845 | var view3d = _a.view3d;
|
14846 | view3d.scene.add(this._arrowIndicator.object);
|
14847 | };
|
14848 |
|
14849 | __proto.destroy = function (_a) {
|
14850 | var view3d = _a.view3d;
|
14851 | view3d.scene.remove(this._arrowIndicator.object);
|
14852 | };
|
14853 | /**
|
14854 | * Enable this control
|
14855 | */
|
14856 |
|
14857 |
|
14858 | __proto.enable = function () {
|
14859 | this._enabled = true;
|
14860 | };
|
14861 | /**
|
14862 | * Disable this control
|
14863 | */
|
14864 |
|
14865 |
|
14866 | __proto.disable = function () {
|
14867 | this._enabled = false;
|
14868 | this.deactivate();
|
14869 | };
|
14870 |
|
14871 | __proto.activate = function (_a, gesture) {
|
14872 | var model = _a.model;
|
14873 | if (!this._enabled) return;
|
14874 | this._active = true; // Update arrows
|
14875 |
|
14876 | var arrowIndicator = this._arrowIndicator;
|
14877 | var modelBbox = model.initialBbox;
|
14878 | modelBbox.min.multiply(model.scene.scale);
|
14879 | modelBbox.max.multiply(model.scene.scale);
|
14880 | modelBbox.translate(model.scene.position);
|
14881 | arrowIndicator.show();
|
14882 | arrowIndicator.updatePosition(modelBbox.getCenter(new Vector3()));
|
14883 | arrowIndicator.updateScale(model.size / 16);
|
14884 | var arrowPlaneRotation = model.scene.quaternion.clone();
|
14885 | arrowIndicator.updateRotation(arrowPlaneRotation);
|
14886 | arrowIndicator.updateOffset(new Vector3().subVectors(modelBbox.max, modelBbox.min).multiplyScalar(0.5));
|
14887 | };
|
14888 |
|
14889 | __proto.deactivate = function () {
|
14890 | this._active = false;
|
14891 |
|
14892 | this._arrowIndicator.hide();
|
14893 | };
|
14894 |
|
14895 | __proto.setInitialPos = function (coords) {
|
14896 | this._initialPos.copy(coords[0]);
|
14897 | };
|
14898 |
|
14899 | __proto.process = function (_a, _b) {
|
14900 | var view3d = _a.view3d,
|
14901 | model = _a.model,
|
14902 | frame = _a.frame,
|
14903 | referenceSpace = _a.referenceSpace,
|
14904 | xrCam = _a.xrCam;
|
14905 | var hitResults = _b.hitResults;
|
14906 | if (!hitResults || hitResults.length !== 1 || !this._active) return;
|
14907 | var dragPlane = this._dragPlane;
|
14908 | var modelRoot = model.scene;
|
14909 | var modelZOffset = -model.initialBbox.min.z * modelRoot.scale.z;
|
14910 | var camPos = new Vector3().setFromMatrixPosition(xrCam.matrixWorld);
|
14911 | var hitResult = hitResults[0];
|
14912 | var hitPose = hitResult.results[0] && hitResult.results[0].getPose(referenceSpace);
|
14913 | var isWallHit = hitPose && hitPose.transform.matrix[5] < 0.25;
|
14914 |
|
14915 | if (!hitPose || !isWallHit) {
|
14916 | // Use previous drag plane if no hit plane is found
|
14917 | var targetRayPose = frame.getPose(hitResult.inputSource.targetRaySpace, view3d.renderer.threeRenderer.xr.getReferenceSpace());
|
14918 | var fingerDir = new Vector3().copy(targetRayPose.transform.position).sub(camPos).normalize();
|
14919 | var fingerRay = new Ray(camPos, fingerDir);
|
14920 | var intersection = fingerRay.intersectPlane(dragPlane, new Vector3());
|
14921 |
|
14922 | if (intersection) {
|
14923 | this.wallPosition.copy(intersection.clone().sub(dragPlane.normal.clone().multiplyScalar(modelZOffset)));
|
14924 | this.position.copy(intersection);
|
14925 | }
|
14926 |
|
14927 | return;
|
14928 | }
|
14929 |
|
14930 | var hitMatrix = new Matrix4().fromArray(hitPose.transform.matrix);
|
14931 | var hitOrientation = new Quaternion().copy(hitPose.transform.orientation);
|
14932 | var hitPosition = new Vector3().setFromMatrixPosition(hitMatrix);
|
14933 | var worldYAxis = new Vector3(0, 1, 0);
|
14934 | /*
|
14935 | * ^ wallU
|
14936 | * |
|
14937 | * ⨀---> wallV
|
14938 | * wallNormal
|
14939 | */
|
14940 |
|
14941 | var wallNormal = new Vector3(0, 1, 0).applyQuaternion(hitOrientation).normalize();
|
14942 | var wallU = new Vector3().crossVectors(worldYAxis, wallNormal);
|
14943 | var wallV = wallNormal.clone().applyAxisAngle(wallU, -Math.PI / 2); // Reconstruct wall matrix with prev Y(normal) direction as Z axis
|
14944 |
|
14945 | var wallMatrix = new Matrix4().makeBasis(wallU, wallV, wallNormal);
|
14946 | var modelPosition = hitPosition.clone().add(wallNormal.clone().multiplyScalar(modelZOffset)); // Update position
|
14947 |
|
14948 | this.position.copy(modelPosition);
|
14949 | this.wallPosition.copy(hitPosition); // Update rotation if it differs more than 10deg
|
14950 |
|
14951 | var prevWallNormal = new Vector3(0, 1, 0).applyQuaternion(this.hitRotation).normalize();
|
14952 |
|
14953 | if (Math.acos(Math.abs(prevWallNormal.dot(wallNormal))) >= Math.PI / 18) {
|
14954 | var prevWallRotation = this.wallRotation.clone();
|
14955 | var wallRotation = new Quaternion().setFromRotationMatrix(wallMatrix);
|
14956 | var rotationDiff = prevWallRotation.inverse().premultiply(wallRotation);
|
14957 | modelRoot.quaternion.premultiply(rotationDiff);
|
14958 | this.wallRotation.copy(wallRotation);
|
14959 | this.hitRotation.copy(hitOrientation);
|
14960 |
|
14961 | this._arrowIndicator.updateRotation(modelRoot.quaternion); // Update drag plane
|
14962 |
|
14963 |
|
14964 | dragPlane.set(wallNormal, -modelPosition.dot(wallNormal));
|
14965 | }
|
14966 | };
|
14967 |
|
14968 | __proto.update = function (_a, delta) {
|
14969 | var model = _a.model;
|
14970 | model.scene.position.copy(this.position);
|
14971 |
|
14972 | this._arrowIndicator.updatePosition(this.position);
|
14973 |
|
14974 | model.scene.updateMatrix();
|
14975 | };
|
14976 |
|
14977 | return ARWallTranslateControl;
|
14978 | }();
|
14979 |
|
14980 | /*
|
14981 | * Copyright (c) 2020 NAVER Corp.
|
14982 | * egjs projects are licensed under the MIT license
|
14983 | */
|
14984 | /**
|
14985 | * AR control for {@link WallARSession}.
|
14986 | * @category Controls-AR
|
14987 | */
|
14988 |
|
14989 | var ARWallControl =
|
14990 | /*#__PURE__*/
|
14991 | function () {
|
14992 | /**
|
14993 | * Create new instance of ARControl
|
14994 | * @param {ARWallControlOption} options Options
|
14995 | */
|
14996 | function ARWallControl(options) {
|
14997 | var _this = this;
|
14998 |
|
14999 | if (options === void 0) {
|
15000 | options = {};
|
15001 | }
|
15002 |
|
15003 | this._enabled = true;
|
15004 | this._initialized = false;
|
15005 | this._modelHit = false;
|
15006 | this._hitTestSource = null;
|
15007 |
|
15008 | this.onSelectStart = function (ctx) {
|
15009 | var view3d = ctx.view3d,
|
15010 | session = ctx.session,
|
15011 | frame = ctx.frame,
|
15012 | referenceSpace = ctx.referenceSpace,
|
15013 | xrCam = ctx.xrCam;
|
15014 | var hitTestSource = _this._hitTestSource;
|
15015 | if (!hitTestSource || !_this._enabled) return;
|
15016 | var deadzoneChecker = _this._deadzoneChecker;
|
15017 | var rotateControl = _this._rotateControl;
|
15018 | var translateControl = _this._translateControl;
|
15019 | var scaleControl = _this._scaleControl; // Update deadzone testing gestures
|
15020 |
|
15021 | if (rotateControl.enabled) {
|
15022 | deadzoneChecker.addTestingGestures(GESTURE.ONE_FINGER);
|
15023 | }
|
15024 |
|
15025 | if (translateControl.enabled) {
|
15026 | deadzoneChecker.addTestingGestures(GESTURE.ONE_FINGER);
|
15027 | }
|
15028 |
|
15029 | if (scaleControl.enabled) {
|
15030 | deadzoneChecker.addTestingGestures(GESTURE.PINCH);
|
15031 | }
|
15032 |
|
15033 | var hitResults = frame.getHitTestResultsForTransientInput(hitTestSource);
|
15034 |
|
15035 | var coords = _this._hitResultToVector(hitResults);
|
15036 |
|
15037 | deadzoneChecker.applyScreenAspect(coords);
|
15038 | deadzoneChecker.setFirstInput(coords);
|
15039 |
|
15040 | if (coords.length === 1) {
|
15041 | // Check finger is on the model
|
15042 | var modelBbox = view3d.model.bbox;
|
15043 | var targetRayPose = frame.getPose(session.inputSources[0].targetRaySpace, referenceSpace);
|
15044 | var camPos = new Vector3().setFromMatrixPosition(xrCam.matrixWorld);
|
15045 | var fingerDir = new Vector3().copy(targetRayPose.transform.position).sub(camPos).normalize();
|
15046 | var fingerRay = new Ray(camPos, fingerDir);
|
15047 | var intersection = fingerRay.intersectBox(modelBbox, new Vector3());
|
15048 |
|
15049 | if (intersection) {
|
15050 | // Touch point intersected with model
|
15051 | _this._modelHit = true;
|
15052 | }
|
15053 | }
|
15054 |
|
15055 | _this._floorIndicator.show();
|
15056 | };
|
15057 |
|
15058 | this.onSelectEnd = function () {
|
15059 | _this.deactivate();
|
15060 |
|
15061 | _this._floorIndicator.fadeout();
|
15062 | }; // TODO: bind options
|
15063 |
|
15064 |
|
15065 | this._rotateControl = new ARSwirlControl(__assign(__assign({}, options.rotate), {
|
15066 | showIndicator: false
|
15067 | }));
|
15068 | this._translateControl = new ARWallTranslateControl(options.translate);
|
15069 | this._scaleControl = new ARScaleControl(options.scale);
|
15070 | this._floorIndicator = new FloorIndicator(options.floorIndicator);
|
15071 | this._deadzoneChecker = new DeadzoneChecker(options.deadzone);
|
15072 | }
|
15073 |
|
15074 | var __proto = ARWallControl.prototype;
|
15075 | Object.defineProperty(__proto, "enabled", {
|
15076 | /**
|
15077 | * Return whether this control is enabled or not
|
15078 | */
|
15079 | get: function () {
|
15080 | return this._enabled;
|
15081 | },
|
15082 | enumerable: false,
|
15083 | configurable: true
|
15084 | });
|
15085 | Object.defineProperty(__proto, "rotate", {
|
15086 | /**
|
15087 | * {@link ARSwirlControlOptions} in this control
|
15088 | */
|
15089 | get: function () {
|
15090 | return this._rotateControl;
|
15091 | },
|
15092 | enumerable: false,
|
15093 | configurable: true
|
15094 | });
|
15095 | Object.defineProperty(__proto, "translate", {
|
15096 | /**
|
15097 | * {@link ARTranslateControl} in this control
|
15098 | */
|
15099 | get: function () {
|
15100 | return this._translateControl;
|
15101 | },
|
15102 | enumerable: false,
|
15103 | configurable: true
|
15104 | });
|
15105 | Object.defineProperty(__proto, "scale", {
|
15106 | /**
|
15107 | * {@link ARScaleControl} in this control
|
15108 | */
|
15109 | get: function () {
|
15110 | return this._scaleControl;
|
15111 | },
|
15112 | enumerable: false,
|
15113 | configurable: true
|
15114 | });
|
15115 | Object.defineProperty(__proto, "controls", {
|
15116 | get: function () {
|
15117 | return [this._rotateControl, this._translateControl, this._scaleControl];
|
15118 | },
|
15119 | enumerable: false,
|
15120 | configurable: true
|
15121 | });
|
15122 |
|
15123 | __proto.init = function (ctx, initialTransform) {
|
15124 | var _this = this;
|
15125 |
|
15126 | var session = ctx.session,
|
15127 | view3d = ctx.view3d,
|
15128 | size = ctx.size;
|
15129 | this.controls.forEach(function (control) {
|
15130 | return control.init(ctx);
|
15131 | });
|
15132 |
|
15133 | this._translateControl.initWallTransform(initialTransform);
|
15134 |
|
15135 | this._deadzoneChecker.setAspect(size.height / size.width);
|
15136 |
|
15137 | view3d.scene.add(this._floorIndicator.mesh);
|
15138 | this._initialized = true;
|
15139 | session.requestHitTestSourceForTransientInput({
|
15140 | profile: INPUT_PROFILE.TOUCH
|
15141 | }).then(function (transientHitTestSource) {
|
15142 | _this._hitTestSource = transientHitTestSource;
|
15143 | });
|
15144 | };
|
15145 | /**
|
15146 | * Destroy this control and deactivate it
|
15147 | * @param view3d Instance of the {@link View3D}
|
15148 | */
|
15149 |
|
15150 |
|
15151 | __proto.destroy = function (ctx) {
|
15152 | if (!this._initialized) return;
|
15153 |
|
15154 | if (this._hitTestSource) {
|
15155 | this._hitTestSource.cancel();
|
15156 |
|
15157 | this._hitTestSource = null;
|
15158 | }
|
15159 |
|
15160 | ctx.view3d.scene.remove(this._floorIndicator.mesh);
|
15161 | this.deactivate();
|
15162 | this.controls.forEach(function (control) {
|
15163 | return control.destroy(ctx);
|
15164 | });
|
15165 | this._initialized = false;
|
15166 | };
|
15167 |
|
15168 | __proto.deactivate = function () {
|
15169 | this._modelHit = false;
|
15170 |
|
15171 | this._deadzoneChecker.cleanup();
|
15172 |
|
15173 | this.controls.forEach(function (control) {
|
15174 | return control.deactivate();
|
15175 | });
|
15176 | };
|
15177 | /**
|
15178 | * Enable this control
|
15179 | */
|
15180 |
|
15181 |
|
15182 | __proto.enable = function () {
|
15183 | this._enabled = true;
|
15184 | };
|
15185 | /**
|
15186 | * Disable this control
|
15187 | */
|
15188 |
|
15189 |
|
15190 | __proto.disable = function () {
|
15191 | this._enabled = false;
|
15192 | this.deactivate();
|
15193 | };
|
15194 |
|
15195 | __proto.update = function (ctx) {
|
15196 | var view3d = ctx.view3d,
|
15197 | session = ctx.session,
|
15198 | frame = ctx.frame;
|
15199 | var hitTestSource = this._hitTestSource;
|
15200 | if (!hitTestSource || !view3d.model) return;
|
15201 | var deadzoneChecker = this._deadzoneChecker;
|
15202 | var inputSources = session.inputSources;
|
15203 | var hitResults = frame.getHitTestResultsForTransientInput(hitTestSource);
|
15204 |
|
15205 | var coords = this._hitResultToVector(hitResults);
|
15206 |
|
15207 | var xrInputs = {
|
15208 | coords: coords,
|
15209 | inputSources: inputSources,
|
15210 | hitResults: hitResults
|
15211 | };
|
15212 |
|
15213 | if (deadzoneChecker.inDeadzone) {
|
15214 | this._checkDeadzone(ctx, xrInputs);
|
15215 | } else {
|
15216 | this._processInput(ctx, xrInputs);
|
15217 | }
|
15218 |
|
15219 | this._updateControls(ctx);
|
15220 | };
|
15221 |
|
15222 | __proto._checkDeadzone = function (ctx, _a) {
|
15223 | var coords = _a.coords;
|
15224 | var model = ctx.model;
|
15225 |
|
15226 | var gesture = this._deadzoneChecker.check(coords.map(function (coord) {
|
15227 | return coord.clone();
|
15228 | }));
|
15229 |
|
15230 | var rotateControl = this._rotateControl;
|
15231 | var translateControl = this._translateControl;
|
15232 | var scaleControl = this._scaleControl;
|
15233 | if (gesture === GESTURE.NONE) return;
|
15234 |
|
15235 | switch (gesture) {
|
15236 | case GESTURE.ONE_FINGER_HORIZONTAL:
|
15237 | case GESTURE.ONE_FINGER_VERTICAL:
|
15238 | if (this._modelHit) {
|
15239 | translateControl.activate(ctx, gesture);
|
15240 | translateControl.setInitialPos(coords);
|
15241 | } else {
|
15242 | rotateControl.activate(ctx, gesture);
|
15243 | rotateControl.updateAxis(new Vector3(0, 1, 0).applyQuaternion(translateControl.hitRotation));
|
15244 | rotateControl.updateRotation(model.scene.quaternion);
|
15245 | rotateControl.setInitialPos(coords);
|
15246 | }
|
15247 |
|
15248 | break;
|
15249 |
|
15250 | case GESTURE.PINCH:
|
15251 | scaleControl.activate(ctx, gesture);
|
15252 | scaleControl.setInitialPos(coords);
|
15253 | break;
|
15254 | }
|
15255 | };
|
15256 |
|
15257 | __proto._processInput = function (ctx, inputs) {
|
15258 | this.controls.forEach(function (control) {
|
15259 | return control.process(ctx, inputs);
|
15260 | });
|
15261 | };
|
15262 |
|
15263 | __proto._updateControls = function (ctx) {
|
15264 | var view3d = ctx.view3d,
|
15265 | model = ctx.model,
|
15266 | delta = ctx.delta;
|
15267 | var deltaMilisec = delta * 1000;
|
15268 | this.controls.forEach(function (control) {
|
15269 | return control.update(ctx, deltaMilisec);
|
15270 | });
|
15271 | model.scene.updateMatrix();
|
15272 | var translateControl = this._translateControl;
|
15273 | var floorPosition = translateControl.wallPosition;
|
15274 | view3d.scene.update(model, {
|
15275 | floorPosition: floorPosition,
|
15276 | floorRotation: translateControl.hitRotation
|
15277 | }); // Get a scaled bbox, which only has scale applied on it.
|
15278 |
|
15279 | var scaleControl = this._scaleControl;
|
15280 | var scaledBbox = model.initialBbox;
|
15281 | scaledBbox.min.multiply(scaleControl.scale);
|
15282 | scaledBbox.max.multiply(scaleControl.scale);
|
15283 | var floorIndicator = this._floorIndicator;
|
15284 | var boundingSphere = scaledBbox.getBoundingSphere(new Sphere());
|
15285 | var rotX90 = new Quaternion().setFromEuler(new Euler(Math.PI / 2, 0, 0));
|
15286 | var floorRotation = model.scene.quaternion.clone().multiply(rotX90);
|
15287 | floorIndicator.update({
|
15288 | delta: deltaMilisec,
|
15289 | scale: boundingSphere.radius,
|
15290 | position: floorPosition,
|
15291 | rotation: floorRotation
|
15292 | });
|
15293 | };
|
15294 |
|
15295 | __proto._hitResultToVector = function (hitResults) {
|
15296 | return hitResults.map(function (input) {
|
15297 | return new Vector2().set(input.inputSource.gamepad.axes[0], -input.inputSource.gamepad.axes[1]);
|
15298 | });
|
15299 | };
|
15300 |
|
15301 | return ARWallControl;
|
15302 | }();
|
15303 |
|
15304 | /*
|
15305 | * Copyright (c) 2020 NAVER Corp.
|
15306 | * egjs projects are licensed under the MIT license
|
15307 | */
|
15308 | /**
|
15309 | * AR session which places model on the wall
|
15310 | * @category XR
|
15311 | * @fires WebARSession#start
|
15312 | * @fires WebARSession#end
|
15313 | * @fires WebARSession#canPlace
|
15314 | * @fires WebARSession#modelPlaced
|
15315 | */
|
15316 |
|
15317 | var WallARSession =
|
15318 | /*#__PURE__*/
|
15319 | function (_super) {
|
15320 | __extends(WallARSession, _super);
|
15321 | /**
|
15322 | * Create new instance of WallARSession
|
15323 | * @param {WallARSessionOption} [options={}] Options
|
15324 | */
|
15325 |
|
15326 |
|
15327 | function WallARSession(options) {
|
15328 | if (options === void 0) {
|
15329 | options = {};
|
15330 | }
|
15331 |
|
15332 | var _this = _super.call(this, options) || this;
|
15333 |
|
15334 | _this.onStart = function (ctx) {
|
15335 | var view3d = ctx.view3d,
|
15336 | session = ctx.session;
|
15337 |
|
15338 | _super.prototype.onStart.call(_this, ctx);
|
15339 |
|
15340 | _this._control = new ARWallControl(_this._options);
|
15341 | view3d.scene.hide();
|
15342 |
|
15343 | _this._hitTest.init(session);
|
15344 | };
|
15345 |
|
15346 | _this.onEnd = function (ctx) {
|
15347 | var view3d = ctx.view3d,
|
15348 | session = ctx.session;
|
15349 |
|
15350 | _super.prototype.onEnd.call(_this, ctx);
|
15351 |
|
15352 | _this._renderContext = null;
|
15353 | _this._modelPlaced = false;
|
15354 | session.removeEventListener(EVENTS$1.SELECT_START, _this._onSelectStart);
|
15355 | session.removeEventListener(EVENTS$1.SELECT_END, _this._onSelectEnd);
|
15356 |
|
15357 | _this._hitTest.destroy();
|
15358 |
|
15359 | _this._control.destroy(ctx);
|
15360 |
|
15361 | _this._control = null;
|
15362 | view3d.scene.show();
|
15363 | };
|
15364 |
|
15365 | _this._beforeRender = function (ctx) {
|
15366 | _this._renderContext = ctx;
|
15367 |
|
15368 | if (!_this._modelPlaced) {
|
15369 | _this._initModelPosition(ctx);
|
15370 | } else {
|
15371 | _this._control.update(ctx);
|
15372 | }
|
15373 | };
|
15374 |
|
15375 | _this._onSelectStart = function (e) {
|
15376 | _this._control.onSelectStart(__assign(__assign({}, _this._renderContext), {
|
15377 | frame: e.frame
|
15378 | }));
|
15379 | };
|
15380 |
|
15381 | _this._onSelectEnd = function () {
|
15382 | _this._control.onSelectEnd();
|
15383 | };
|
15384 |
|
15385 | _this._control = null;
|
15386 | _this._renderContext = null;
|
15387 | _this._modelPlaced = false;
|
15388 | _this._hitTest = new HitTest();
|
15389 | _this._features = merge(_this._features, _this._hitTest.features);
|
15390 | _this._options = options;
|
15391 | return _this;
|
15392 | }
|
15393 |
|
15394 | var __proto = WallARSession.prototype;
|
15395 | Object.defineProperty(__proto, "control", {
|
15396 | /**
|
15397 | * {@link ARWallControl} instance of this session
|
15398 | * @type ARWallControl | null
|
15399 | */
|
15400 | get: function () {
|
15401 | return this._control;
|
15402 | },
|
15403 | enumerable: false,
|
15404 | configurable: true
|
15405 | });
|
15406 |
|
15407 | __proto._initModelPosition = function (ctx) {
|
15408 | var _a;
|
15409 |
|
15410 | var view3d = ctx.view3d,
|
15411 | frame = ctx.frame,
|
15412 | session = ctx.session;
|
15413 | var model = view3d.model;
|
15414 | var hitTest = this._hitTest; // Make sure the model is loaded
|
15415 |
|
15416 | if (!hitTest.ready || !model) return;
|
15417 | var control = this._control;
|
15418 | var referenceSpace = view3d.renderer.threeRenderer.xr.getReferenceSpace();
|
15419 | var hitTestResults = hitTest.getResults(frame);
|
15420 | if (hitTestResults.length <= 0) return;
|
15421 | var hit = hitTestResults[0];
|
15422 | var hitPose = hit.getPose(referenceSpace);
|
15423 | var hitMatrix = new Matrix4().fromArray(hitPose.transform.matrix); // If transformed coord space's y axis is facing up or down, don't use it.
|
15424 |
|
15425 | if (hitMatrix.elements[5] >= 0.25 || hitMatrix.elements[5] <= -0.25) return;
|
15426 | var modelRoot = model.scene;
|
15427 | var hitRotation = new Quaternion().copy(hitPose.transform.orientation);
|
15428 | var hitPosition = new Vector3().setFromMatrixPosition(hitMatrix);
|
15429 | var modelZOffset = -model.initialBbox.min.z * modelRoot.scale.z;
|
15430 | var modelPosition = hitPosition.clone().setZ(hitPosition.z + modelZOffset);
|
15431 | var worldYAxis = new Vector3(0, 1, 0);
|
15432 | /*
|
15433 | * ^ wallU
|
15434 | * |
|
15435 | * ⨀---> wallV
|
15436 | * wallNormal
|
15437 | */
|
15438 |
|
15439 | var wallNormal = new Vector3(0, 1, 0).applyQuaternion(hitRotation).normalize();
|
15440 | var wallU = new Vector3().crossVectors(worldYAxis, wallNormal);
|
15441 | var wallV = wallNormal.clone().applyAxisAngle(wallU, -Math.PI / 2); // Reconstruct wall matrix with prev Y(normal) direction as Z axis
|
15442 |
|
15443 | var wallMatrix = new Matrix4().makeBasis(wallU, wallV, wallNormal);
|
15444 | var wallRotation = new Quaternion().setFromRotationMatrix(wallMatrix);
|
15445 | var modelRotation = model.scene.quaternion.clone().premultiply(wallRotation); // Update rotation & position
|
15446 |
|
15447 | modelRoot.quaternion.copy(modelRotation);
|
15448 | modelRoot.position.copy(modelPosition);
|
15449 | modelRoot.updateMatrix();
|
15450 | view3d.scene.update(model);
|
15451 | view3d.scene.show(); // Don't need it
|
15452 |
|
15453 | hitTest.destroy();
|
15454 | session.addEventListener(EVENTS$1.SELECT_START, this._onSelectStart);
|
15455 | session.addEventListener(EVENTS$1.SELECT_END, this._onSelectEnd);
|
15456 | (_a = this._domOverlay) === null || _a === void 0 ? void 0 : _a.hideLoading();
|
15457 | this._modelPlaced = true; // Show scale up animation
|
15458 |
|
15459 | var originalModelScale = model.scene.scale.clone();
|
15460 | var scaleUpAnimation = new Animation({
|
15461 | context: session
|
15462 | });
|
15463 | scaleUpAnimation.on("progress", function (evt) {
|
15464 | var newScale = originalModelScale.clone().multiplyScalar(evt.easedProgress);
|
15465 | model.scene.scale.copy(newScale);
|
15466 | });
|
15467 | scaleUpAnimation.on("finish", function () {
|
15468 | model.scene.scale.copy(originalModelScale);
|
15469 | control.init(ctx, {
|
15470 | hitPosition: hitPosition,
|
15471 | hitRotation: hitRotation,
|
15472 | wallRotation: wallRotation,
|
15473 | modelPosition: modelPosition
|
15474 | });
|
15475 | });
|
15476 | scaleUpAnimation.start();
|
15477 | };
|
15478 |
|
15479 | return WallARSession;
|
15480 | }(WebARSession);
|
15481 |
|
15482 | /*
|
15483 | * Copyright (c) 2020 NAVER Corp.
|
15484 | * egjs projects are licensed under the MIT license
|
15485 | */
|
15486 | var STATE$2;
|
15487 |
|
15488 | (function (STATE) {
|
15489 | STATE[STATE["WAITING"] = 0] = "WAITING";
|
15490 | STATE[STATE["ROTATE_HORIZONTAL"] = 1] = "ROTATE_HORIZONTAL";
|
15491 | STATE[STATE["ROTATE_VERTICAL"] = 2] = "ROTATE_VERTICAL";
|
15492 | })(STATE$2 || (STATE$2 = {}));
|
15493 | /**
|
15494 | * Two finger swipe control
|
15495 | * @category Controls-AR
|
15496 | */
|
15497 |
|
15498 |
|
15499 | var ARSwipeControl =
|
15500 | /*#__PURE__*/
|
15501 | function () {
|
15502 | /**
|
15503 | * Create new ARSwipeControl
|
15504 | * @param {ARSwipeControlOption} [options={}] Options
|
15505 | */
|
15506 | function ARSwipeControl(_a) {
|
15507 | var _b = (_a === void 0 ? {} : _a).scale,
|
15508 | scale = _b === void 0 ? 1 : _b;
|
15509 | /**
|
15510 | * Current rotation value
|
15511 | */
|
15512 |
|
15513 | this.rotation = new Quaternion(); // Internal States
|
15514 |
|
15515 | this._state = STATE$2.WAITING;
|
15516 | this._enabled = true;
|
15517 | this._active = false;
|
15518 | this._prevPos = new Vector2();
|
15519 | this._fromQuat = new Quaternion();
|
15520 | this._toQuat = new Quaternion();
|
15521 | this._horizontalAxis = new Vector3();
|
15522 | this._verticalAxis = new Vector3();
|
15523 | this._motion = new Motion({
|
15524 | range: INFINITE_RANGE
|
15525 | });
|
15526 | this._rotationIndicator = new RotationIndicator();
|
15527 | this._userScale = scale;
|
15528 | }
|
15529 |
|
15530 | var __proto = ARSwipeControl.prototype;
|
15531 | Object.defineProperty(__proto, "enabled", {
|
15532 | /**
|
15533 | * Whether this control is enabled or not.
|
15534 | * @readonly
|
15535 | */
|
15536 | get: function () {
|
15537 | return this._enabled;
|
15538 | },
|
15539 | enumerable: false,
|
15540 | configurable: true
|
15541 | });
|
15542 | Object.defineProperty(__proto, "scale", {
|
15543 | /**
|
15544 | * Scale(speed) factor of this control.
|
15545 | */
|
15546 | get: function () {
|
15547 | return this._userScale;
|
15548 | },
|
15549 | set: function (val) {
|
15550 | this._userScale = val;
|
15551 | },
|
15552 | enumerable: false,
|
15553 | configurable: true
|
15554 | });
|
15555 | Object.defineProperty(__proto, "horizontalAxis", {
|
15556 | get: function () {
|
15557 | return this._horizontalAxis;
|
15558 | },
|
15559 | enumerable: false,
|
15560 | configurable: true
|
15561 | });
|
15562 | Object.defineProperty(__proto, "verticalAxis", {
|
15563 | get: function () {
|
15564 | return this._verticalAxis;
|
15565 | },
|
15566 | enumerable: false,
|
15567 | configurable: true
|
15568 | });
|
15569 |
|
15570 | __proto.init = function (_a) {
|
15571 | var view3d = _a.view3d;
|
15572 | var initialRotation = view3d.model.scene.quaternion;
|
15573 | this.updateRotation(initialRotation);
|
15574 | view3d.scene.add(this._rotationIndicator.object);
|
15575 | };
|
15576 |
|
15577 | __proto.destroy = function (_a) {
|
15578 | var view3d = _a.view3d;
|
15579 | view3d.scene.remove(this._rotationIndicator.object);
|
15580 | };
|
15581 |
|
15582 | __proto.updateRotation = function (rotation) {
|
15583 | this.rotation.copy(rotation);
|
15584 |
|
15585 | this._fromQuat.copy(rotation);
|
15586 |
|
15587 | this._toQuat.copy(rotation);
|
15588 | };
|
15589 | /**
|
15590 | * Enable this control
|
15591 | */
|
15592 |
|
15593 |
|
15594 | __proto.enable = function () {
|
15595 | this._enabled = true;
|
15596 | };
|
15597 | /**
|
15598 | * Disable this control
|
15599 | */
|
15600 |
|
15601 |
|
15602 | __proto.disable = function () {
|
15603 | this._enabled = false;
|
15604 | };
|
15605 |
|
15606 | __proto.updateAxis = function (horizontal, vertical) {
|
15607 | this._horizontalAxis.copy(horizontal);
|
15608 |
|
15609 | this._verticalAxis.copy(vertical);
|
15610 | };
|
15611 |
|
15612 | __proto.activate = function (_a, gesture) {
|
15613 | var view3d = _a.view3d;
|
15614 | if (!this._enabled) return;
|
15615 | var model = view3d.model;
|
15616 | var rotationIndicator = this._rotationIndicator;
|
15617 | this._active = true;
|
15618 | rotationIndicator.show();
|
15619 | rotationIndicator.updatePosition(model.bbox.getCenter(new Vector3()));
|
15620 | rotationIndicator.updateScale(model.size / 2);
|
15621 |
|
15622 | if (gesture === GESTURE.TWO_FINGER_HORIZONTAL) {
|
15623 | rotationIndicator.updateRotation(model.scene.quaternion.clone().multiply(new Quaternion().setFromEuler(new Euler(-Math.PI / 2, 0, 0))));
|
15624 | this._state = STATE$2.ROTATE_HORIZONTAL;
|
15625 | } else if (gesture === GESTURE.TWO_FINGER_VERTICAL) {
|
15626 | rotationIndicator.updateRotation(model.scene.quaternion.clone().multiply(new Quaternion().setFromEuler(new Euler(0, Math.PI / 2, 0))));
|
15627 | this._state = STATE$2.ROTATE_VERTICAL;
|
15628 | }
|
15629 | };
|
15630 |
|
15631 | __proto.deactivate = function () {
|
15632 | this._active = false;
|
15633 |
|
15634 | this._rotationIndicator.hide();
|
15635 |
|
15636 | this._state = STATE$2.WAITING;
|
15637 | };
|
15638 |
|
15639 | __proto.setInitialPos = function (coords) {
|
15640 | if (coords.length < 2) return;
|
15641 |
|
15642 | this._prevPos.set((coords[0].x + coords[1].x) / 2, (coords[0].y + coords[1].y) / 2);
|
15643 | };
|
15644 |
|
15645 | __proto.process = function (ctx, _a) {
|
15646 | var coords = _a.coords;
|
15647 | if (!this._active || coords.length !== 2) return;
|
15648 | var state = this._state;
|
15649 | var prevPos = this._prevPos;
|
15650 | var motion = this._motion;
|
15651 | var scale = this._userScale;
|
15652 | var middlePos = new Vector2((coords[0].x + coords[1].x) / 2, (coords[0].y + coords[1].y) / 2);
|
15653 | var posDiff = new Vector2().subVectors(prevPos, middlePos);
|
15654 | var rotationAxis = state === STATE$2.ROTATE_HORIZONTAL ? this._horizontalAxis : this._verticalAxis;
|
15655 | var rotationAngle = state === STATE$2.ROTATE_HORIZONTAL ? posDiff.x * scale : -posDiff.y * scale;
|
15656 | var rotation = new Quaternion().setFromAxisAngle(rotationAxis, rotationAngle);
|
15657 |
|
15658 | var interpolated = this._getInterpolatedQuaternion();
|
15659 |
|
15660 | this._fromQuat.copy(interpolated);
|
15661 |
|
15662 | this._toQuat.premultiply(rotation);
|
15663 |
|
15664 | motion.reset(0);
|
15665 | motion.setEndDelta(1);
|
15666 | prevPos.copy(middlePos);
|
15667 | };
|
15668 |
|
15669 | __proto.update = function (_a, deltaTime) {
|
15670 | var model = _a.model;
|
15671 | var motion = this._motion;
|
15672 | motion.update(deltaTime);
|
15673 |
|
15674 | var interpolated = this._getInterpolatedQuaternion();
|
15675 |
|
15676 | this.rotation.copy(interpolated);
|
15677 | model.scene.quaternion.copy(this.rotation);
|
15678 | };
|
15679 |
|
15680 | __proto._getInterpolatedQuaternion = function () {
|
15681 | var motion = this._motion;
|
15682 | var toEuler = this._toQuat;
|
15683 | var fromEuler = this._fromQuat;
|
15684 | var progress = motion.val;
|
15685 | return new Quaternion().copy(fromEuler).slerp(toEuler, progress);
|
15686 | };
|
15687 |
|
15688 | return ARSwipeControl;
|
15689 | }();
|
15690 |
|
15691 | /*
|
15692 | * Copyright (c) 2020 NAVER Corp.
|
15693 | * egjs projects are licensed under the MIT license
|
15694 | */
|
15695 | /**
|
15696 | * Model's yaw(local y-axis rotation) controller which works on AR(WebXR) mode.
|
15697 | * @category Controls-AR
|
15698 | */
|
15699 |
|
15700 | var ARHoverRotateControl =
|
15701 | /*#__PURE__*/
|
15702 | function () {
|
15703 | /**
|
15704 | * Create new instance of ARRotateControl
|
15705 | * @param {ARHoverRotateControlOption} options Options
|
15706 | */
|
15707 | function ARHoverRotateControl(options) {
|
15708 | if (options === void 0) {
|
15709 | options = {};
|
15710 | }
|
15711 | /**
|
15712 | * Current rotation value
|
15713 | */
|
15714 |
|
15715 |
|
15716 | this.rotation = new Quaternion();
|
15717 | this._zRotationControl = new ARSwirlControl(options.swirl);
|
15718 | this._xyRotationControl = new ARSwipeControl(options.swipe);
|
15719 | this._activatedControl = null;
|
15720 | }
|
15721 |
|
15722 | var __proto = ARHoverRotateControl.prototype;
|
15723 | Object.defineProperty(__proto, "enabled", {
|
15724 | /**
|
15725 | * Whether this control is enabled or not.
|
15726 | * This returns true when either one finger control or two finger control is enabled.
|
15727 | * @readonly
|
15728 | */
|
15729 | get: function () {
|
15730 | return this._zRotationControl.enabled || this._xyRotationControl.enabled;
|
15731 | },
|
15732 | enumerable: false,
|
15733 | configurable: true
|
15734 | });
|
15735 | Object.defineProperty(__proto, "swirl", {
|
15736 | /**
|
15737 | * {@link ARSwirlControl} of this control.
|
15738 | */
|
15739 | get: function () {
|
15740 | return this._zRotationControl;
|
15741 | },
|
15742 | enumerable: false,
|
15743 | configurable: true
|
15744 | });
|
15745 | Object.defineProperty(__proto, "swipe", {
|
15746 | /**
|
15747 | * {@link ARSwipeControl} of this control.
|
15748 | */
|
15749 | get: function () {
|
15750 | return this._xyRotationControl;
|
15751 | },
|
15752 | enumerable: false,
|
15753 | configurable: true
|
15754 | });
|
15755 |
|
15756 | __proto.init = function (ctx) {
|
15757 | var initialRotation = ctx.view3d.model.scene.quaternion;
|
15758 | this.rotation.copy(initialRotation);
|
15759 |
|
15760 | this._zRotationControl.init(ctx);
|
15761 |
|
15762 | this._xyRotationControl.init(ctx);
|
15763 | };
|
15764 |
|
15765 | __proto.destroy = function (ctx) {
|
15766 | this._zRotationControl.destroy(ctx);
|
15767 |
|
15768 | this._xyRotationControl.destroy(ctx);
|
15769 | };
|
15770 | /**
|
15771 | * Enable this control
|
15772 | */
|
15773 |
|
15774 |
|
15775 | __proto.enable = function () {
|
15776 | this._zRotationControl.enable();
|
15777 |
|
15778 | this._xyRotationControl.enable();
|
15779 | };
|
15780 | /**
|
15781 | * Disable this control
|
15782 | */
|
15783 |
|
15784 |
|
15785 | __proto.disable = function () {
|
15786 | this._zRotationControl.disable();
|
15787 |
|
15788 | this._xyRotationControl.disable();
|
15789 | };
|
15790 |
|
15791 | __proto.activate = function (ctx, gesture) {
|
15792 | var zRotationControl = this._zRotationControl;
|
15793 | var xyRotationControl = this._xyRotationControl;
|
15794 |
|
15795 | if (gesture & GESTURE.ONE_FINGER) {
|
15796 | zRotationControl.activate(ctx, gesture);
|
15797 | zRotationControl.updateRotation(this.rotation);
|
15798 | this._activatedControl = zRotationControl;
|
15799 | } else if (gesture & GESTURE.TWO_FINGER) {
|
15800 | xyRotationControl.activate(ctx, gesture);
|
15801 | xyRotationControl.updateRotation(this.rotation);
|
15802 | this._activatedControl = xyRotationControl;
|
15803 | }
|
15804 | };
|
15805 |
|
15806 | __proto.deactivate = function () {
|
15807 | this._zRotationControl.deactivate();
|
15808 |
|
15809 | this._xyRotationControl.deactivate();
|
15810 | };
|
15811 |
|
15812 | __proto.process = function (ctx, inputs) {
|
15813 | this._zRotationControl.process(ctx, inputs);
|
15814 |
|
15815 | this._xyRotationControl.process(ctx, inputs);
|
15816 | };
|
15817 |
|
15818 | __proto.setInitialPos = function (coords) {
|
15819 | this._zRotationControl.setInitialPos(coords);
|
15820 |
|
15821 | this._xyRotationControl.setInitialPos(coords);
|
15822 | };
|
15823 |
|
15824 | __proto.update = function (ctx, deltaTime) {
|
15825 | if (this._activatedControl) {
|
15826 | this._activatedControl.update(ctx, deltaTime);
|
15827 |
|
15828 | this.rotation.copy(this._activatedControl.rotation);
|
15829 | }
|
15830 | };
|
15831 |
|
15832 | __proto.updateRotateAxis = function (_a) {
|
15833 | var view3d = _a.view3d,
|
15834 | xrCam = _a.xrCam;
|
15835 | var model = view3d.model;
|
15836 | var zRotateAxis = new Vector3();
|
15837 | var horizontalRotateAxis = new Vector3();
|
15838 | var verticalRotateAxis = new Vector3();
|
15839 | var cameraRotation = new Quaternion().setFromRotationMatrix(xrCam.matrixWorld);
|
15840 | var cameraBasis = [new Vector3(1, 0, 0), new Vector3(0, 1, 0), new Vector3(0, 0, 1)].map(function (axis) {
|
15841 | return axis.applyQuaternion(cameraRotation).normalize();
|
15842 | });
|
15843 | var modelBasis = [new Vector3(1, 0, 0), new Vector3(0, 1, 0), new Vector3(0, 0, 1)].map(function (axis) {
|
15844 | return axis.applyQuaternion(model.scene.quaternion);
|
15845 | }); // Always use z-rotation
|
15846 |
|
15847 | zRotateAxis.copy(modelBasis[2]); // Use more appropriate one between x/y axis
|
15848 |
|
15849 | horizontalRotateAxis.copy(modelBasis[1]);
|
15850 | verticalRotateAxis.copy(modelBasis[0]); // If it's facing other direction, negate it to face correct direction
|
15851 |
|
15852 | if (zRotateAxis.dot(cameraBasis[2]) < 0) {
|
15853 | zRotateAxis.negate();
|
15854 | }
|
15855 |
|
15856 | if (horizontalRotateAxis.dot(cameraBasis[1]) > 0) {
|
15857 | horizontalRotateAxis.negate();
|
15858 | }
|
15859 |
|
15860 | if (verticalRotateAxis.dot(cameraBasis[0]) > 0) {
|
15861 | verticalRotateAxis.negate();
|
15862 | }
|
15863 |
|
15864 | this._zRotationControl.updateAxis(zRotateAxis);
|
15865 |
|
15866 | this._xyRotationControl.updateAxis(horizontalRotateAxis, verticalRotateAxis);
|
15867 | };
|
15868 |
|
15869 | return ARHoverRotateControl;
|
15870 | }();
|
15871 |
|
15872 | /*
|
15873 | * Copyright (c) 2020 NAVER Corp.
|
15874 | * egjs projects are licensed under the MIT license
|
15875 | */
|
15876 | /**
|
15877 | * Model's translation(position) control for {@link ARHoverControl}
|
15878 | * @category Controls-AR
|
15879 | */
|
15880 |
|
15881 | var ARHoverTranslateControl =
|
15882 | /*#__PURE__*/
|
15883 | function () {
|
15884 | /**
|
15885 | * Create new instance of ARTranslateControl
|
15886 | * @param {ARHoverTranslateControlOption} [options={}] Options
|
15887 | */
|
15888 | function ARHoverTranslateControl(options) {
|
15889 | if (options === void 0) {
|
15890 | options = {};
|
15891 | } // Internal states
|
15892 |
|
15893 |
|
15894 | this._position = new Vector3();
|
15895 | this._dragPlane = new Plane();
|
15896 | this._enabled = true;
|
15897 | this._active = false;
|
15898 | this._initialPos = new Vector2();
|
15899 | this._arrowIndicator = new ArrowIndicator(options.arrow);
|
15900 | }
|
15901 |
|
15902 | var __proto = ARHoverTranslateControl.prototype;
|
15903 | Object.defineProperty(__proto, "enabled", {
|
15904 | get: function () {
|
15905 | return this._enabled;
|
15906 | },
|
15907 | enumerable: false,
|
15908 | configurable: true
|
15909 | });
|
15910 | Object.defineProperty(__proto, "position", {
|
15911 | get: function () {
|
15912 | return this._position.clone();
|
15913 | },
|
15914 | enumerable: false,
|
15915 | configurable: true
|
15916 | });
|
15917 |
|
15918 | __proto.init = function (_a) {
|
15919 | var view3d = _a.view3d;
|
15920 |
|
15921 | this._position.copy(view3d.model.scene.position);
|
15922 |
|
15923 | view3d.scene.add(this._arrowIndicator.object);
|
15924 | };
|
15925 |
|
15926 | __proto.destroy = function (_a) {
|
15927 | var view3d = _a.view3d;
|
15928 | view3d.scene.remove(this._arrowIndicator.object);
|
15929 | };
|
15930 | /**
|
15931 | * Enable this control
|
15932 | */
|
15933 |
|
15934 |
|
15935 | __proto.enable = function () {
|
15936 | this._enabled = true;
|
15937 | };
|
15938 | /**
|
15939 | * Disable this control
|
15940 | */
|
15941 |
|
15942 |
|
15943 | __proto.disable = function () {
|
15944 | this._enabled = false;
|
15945 | this.deactivate();
|
15946 | };
|
15947 |
|
15948 | __proto.activate = function (_a, gesture) {
|
15949 | var model = _a.model,
|
15950 | xrCam = _a.xrCam;
|
15951 | if (!this._enabled) return;
|
15952 | var modelPos = model.scene.position;
|
15953 | var camPos = new Vector3().setFromMatrixPosition(xrCam.matrixWorld);
|
15954 | var modelBasis = [new Vector3(), new Vector3(), new Vector3()];
|
15955 | model.scene.matrixWorld.extractBasis(modelBasis[0], modelBasis[1], modelBasis[2]);
|
15956 | modelBasis.forEach(function (axes) {
|
15957 | return axes.normalize();
|
15958 | });
|
15959 | var camToModelDir = new Vector3().subVectors(modelPos, camPos).clone().normalize();
|
15960 | var primaryAxisIdx = getPrimaryAxisIndex(modelBasis, camToModelDir);
|
15961 | var primaryAxis = modelBasis[primaryAxisIdx]; // If axes is facing the opposite of camera, negate it
|
15962 |
|
15963 | if (primaryAxis.dot(camToModelDir) < 0) {
|
15964 | primaryAxis.negate();
|
15965 | }
|
15966 |
|
15967 | var originToDragPlane = new Plane(primaryAxis, 0).distanceToPoint(modelPos);
|
15968 |
|
15969 | this._dragPlane.set(primaryAxis, -originToDragPlane);
|
15970 |
|
15971 | this._active = true; // Update arrows
|
15972 |
|
15973 | var arrowIndicator = this._arrowIndicator;
|
15974 | var modelBbox = model.initialBbox;
|
15975 | modelBbox.min.multiply(model.scene.scale);
|
15976 | modelBbox.max.multiply(model.scene.scale);
|
15977 | modelBbox.translate(modelPos);
|
15978 | arrowIndicator.show();
|
15979 | arrowIndicator.updatePosition(modelBbox.getCenter(new Vector3()));
|
15980 | arrowIndicator.updateScale(model.size / 16);
|
15981 | var arrowPlaneRotation = model.scene.quaternion.clone();
|
15982 |
|
15983 | if (primaryAxisIdx === 0) {
|
15984 | arrowPlaneRotation.multiply(new Quaternion().setFromEuler(new Euler(0, Math.PI / 2, 0)));
|
15985 | } else if (primaryAxisIdx === 1) {
|
15986 | arrowPlaneRotation.multiply(new Quaternion().setFromEuler(new Euler(Math.PI / 2, 0, 0)));
|
15987 | }
|
15988 |
|
15989 | arrowIndicator.updateRotation(arrowPlaneRotation);
|
15990 | arrowIndicator.updateOffset(new Vector3().subVectors(modelBbox.max, modelBbox.min).multiplyScalar(0.5));
|
15991 | };
|
15992 |
|
15993 | __proto.deactivate = function () {
|
15994 | this._active = false;
|
15995 |
|
15996 | this._arrowIndicator.hide();
|
15997 | };
|
15998 |
|
15999 | __proto.setInitialPos = function (coords) {
|
16000 | this._initialPos.copy(coords[0]);
|
16001 | };
|
16002 |
|
16003 | __proto.process = function (_a, _b) {
|
16004 | var view3d = _a.view3d,
|
16005 | frame = _a.frame,
|
16006 | referenceSpace = _a.referenceSpace,
|
16007 | xrCam = _a.xrCam;
|
16008 | var inputSources = _b.inputSources;
|
16009 | if (inputSources.length !== 1 || !this._active) return;
|
16010 | var inputSource = inputSources[0];
|
16011 | var dragPlane = this._dragPlane;
|
16012 | var targetRayPose = frame.getPose(inputSource.targetRaySpace, referenceSpace);
|
16013 | var camPos = new Vector3().setFromMatrixPosition(xrCam.matrixWorld);
|
16014 | var fingerDir = new Vector3().copy(targetRayPose.transform.position).sub(camPos).normalize();
|
16015 | var fingerRay = new Ray(camPos, fingerDir);
|
16016 | var intersection = fingerRay.intersectPlane(dragPlane, new Vector3());
|
16017 |
|
16018 | if (intersection) {
|
16019 | this._position.copy(intersection); // Update arrow position. As position is not a center of model, we should apply offset from it
|
16020 |
|
16021 |
|
16022 | var model = view3d.model;
|
16023 | var centerYOffset = model.initialBbox.getCenter(new Vector3()).multiply(model.scene.scale).y;
|
16024 | var modelLocalYDir = new Vector3().applyQuaternion(model.scene.quaternion);
|
16025 | var newCenter = intersection.add(modelLocalYDir.multiplyScalar(centerYOffset));
|
16026 |
|
16027 | this._arrowIndicator.updatePosition(newCenter);
|
16028 | }
|
16029 | };
|
16030 |
|
16031 | __proto.update = function (_a, delta) {
|
16032 | var model = _a.model;
|
16033 | model.scene.position.copy(this._position);
|
16034 | };
|
16035 |
|
16036 | return ARHoverTranslateControl;
|
16037 | }();
|
16038 |
|
16039 | /*
|
16040 | * Copyright (c) 2020 NAVER Corp.
|
16041 | * egjs projects are licensed under the MIT license
|
16042 | */
|
16043 | /**
|
16044 | * AR control for {@link HoverARSession}
|
16045 | * @category Controls-AR
|
16046 | */
|
16047 |
|
16048 | var ARHoverControl =
|
16049 | /*#__PURE__*/
|
16050 | function () {
|
16051 | /**
|
16052 | * Create new instance of ARHoverControl
|
16053 | * @param {ARHoverControlOption} options Options
|
16054 | */
|
16055 | function ARHoverControl(options) {
|
16056 | var _this = this;
|
16057 |
|
16058 | if (options === void 0) {
|
16059 | options = {};
|
16060 | }
|
16061 |
|
16062 | this._enabled = true;
|
16063 | this._initialized = false;
|
16064 | this._modelHit = false;
|
16065 |
|
16066 | this.onSelectStart = function (ctx) {
|
16067 | var view3d = ctx.view3d,
|
16068 | session = ctx.session,
|
16069 | frame = ctx.frame,
|
16070 | referenceSpace = ctx.referenceSpace,
|
16071 | xrCam = ctx.xrCam;
|
16072 | if (!_this._enabled) return;
|
16073 | var deadzoneChecker = _this._deadzoneChecker;
|
16074 | var rotateControl = _this._rotateControl;
|
16075 | var translateControl = _this._translateControl;
|
16076 | var scaleControl = _this._scaleControl; // Update rotation axis
|
16077 |
|
16078 | if (rotateControl.enabled) {
|
16079 | rotateControl.updateRotateAxis(ctx);
|
16080 | } // Update deadzone testing gestures
|
16081 |
|
16082 |
|
16083 | if (rotateControl.swirl.enabled) {
|
16084 | deadzoneChecker.addTestingGestures(GESTURE.ONE_FINGER);
|
16085 | }
|
16086 |
|
16087 | if (rotateControl.swipe.enabled) {
|
16088 | deadzoneChecker.addTestingGestures(GESTURE.TWO_FINGER);
|
16089 | }
|
16090 |
|
16091 | if (translateControl.enabled) {
|
16092 | deadzoneChecker.addTestingGestures(GESTURE.ONE_FINGER);
|
16093 | }
|
16094 |
|
16095 | if (scaleControl.enabled) {
|
16096 | deadzoneChecker.addTestingGestures(GESTURE.PINCH);
|
16097 | }
|
16098 |
|
16099 | var coords = _this._inputSourceToVector(session.inputSources);
|
16100 |
|
16101 | deadzoneChecker.applyScreenAspect(coords);
|
16102 | deadzoneChecker.setFirstInput(coords);
|
16103 |
|
16104 | if (coords.length === 1) {
|
16105 | // Check finger is on the model
|
16106 | var modelBbox = view3d.model.bbox;
|
16107 | var targetRayPose = frame.getPose(session.inputSources[0].targetRaySpace, referenceSpace);
|
16108 | var camPos = new Vector3().setFromMatrixPosition(xrCam.matrixWorld);
|
16109 | var fingerDir = new Vector3().copy(targetRayPose.transform.position).sub(camPos).normalize();
|
16110 | var fingerRay = new Ray(camPos, fingerDir);
|
16111 | var intersection = fingerRay.intersectBox(modelBbox, new Vector3());
|
16112 |
|
16113 | if (intersection) {
|
16114 | // Touch point intersected with model
|
16115 | _this._modelHit = true;
|
16116 | }
|
16117 | }
|
16118 | };
|
16119 |
|
16120 | this.onSelectEnd = function () {
|
16121 | _this.deactivate();
|
16122 | };
|
16123 |
|
16124 | this._rotateControl = new ARHoverRotateControl(options.rotate);
|
16125 | this._translateControl = new ARHoverTranslateControl(options.translate);
|
16126 | this._scaleControl = new ARScaleControl(options.scale);
|
16127 | this._deadzoneChecker = new DeadzoneChecker();
|
16128 | }
|
16129 |
|
16130 | var __proto = ARHoverControl.prototype;
|
16131 | Object.defineProperty(__proto, "enabled", {
|
16132 | /**
|
16133 | * Return whether this control is enabled or not
|
16134 | */
|
16135 | get: function () {
|
16136 | return this._enabled;
|
16137 | },
|
16138 | enumerable: false,
|
16139 | configurable: true
|
16140 | });
|
16141 | Object.defineProperty(__proto, "rotate", {
|
16142 | /**
|
16143 | * {@link ARHoverRotateControlOption} in this control
|
16144 | */
|
16145 | get: function () {
|
16146 | return this._rotateControl;
|
16147 | },
|
16148 | enumerable: false,
|
16149 | configurable: true
|
16150 | });
|
16151 | Object.defineProperty(__proto, "translate", {
|
16152 | /**
|
16153 | * {@link ARHoverTranslateControlOption} in this control
|
16154 | */
|
16155 | get: function () {
|
16156 | return this._translateControl;
|
16157 | },
|
16158 | enumerable: false,
|
16159 | configurable: true
|
16160 | });
|
16161 | Object.defineProperty(__proto, "scale", {
|
16162 | /**
|
16163 | * {@link ARScaleControl} in this control
|
16164 | */
|
16165 | get: function () {
|
16166 | return this._scaleControl;
|
16167 | },
|
16168 | enumerable: false,
|
16169 | configurable: true
|
16170 | });
|
16171 | Object.defineProperty(__proto, "controls", {
|
16172 | get: function () {
|
16173 | return [this._rotateControl, this._translateControl, this._scaleControl];
|
16174 | },
|
16175 | enumerable: false,
|
16176 | configurable: true
|
16177 | });
|
16178 |
|
16179 | __proto.init = function (ctx) {
|
16180 | var size = ctx.size;
|
16181 | this.controls.forEach(function (control) {
|
16182 | return control.init(ctx);
|
16183 | });
|
16184 |
|
16185 | this._deadzoneChecker.setAspect(size.height / size.width);
|
16186 |
|
16187 | this._initialized = true;
|
16188 | };
|
16189 | /**
|
16190 | * Destroy this control and deactivate it
|
16191 | * @param view3d Instance of the {@link View3D}
|
16192 | */
|
16193 |
|
16194 |
|
16195 | __proto.destroy = function (ctx) {
|
16196 | if (!this._initialized) return;
|
16197 | this.deactivate();
|
16198 | this.controls.forEach(function (control) {
|
16199 | return control.destroy(ctx);
|
16200 | });
|
16201 | this._initialized = false;
|
16202 | };
|
16203 |
|
16204 | __proto.deactivate = function () {
|
16205 | this._modelHit = false;
|
16206 |
|
16207 | this._deadzoneChecker.cleanup();
|
16208 |
|
16209 | this.controls.forEach(function (control) {
|
16210 | return control.deactivate();
|
16211 | });
|
16212 | };
|
16213 | /**
|
16214 | * Enable this control
|
16215 | */
|
16216 |
|
16217 |
|
16218 | __proto.enable = function () {
|
16219 | this._enabled = true;
|
16220 | };
|
16221 | /**
|
16222 | * Disable this control
|
16223 | */
|
16224 |
|
16225 |
|
16226 | __proto.disable = function () {
|
16227 | this._enabled = false;
|
16228 | this.deactivate();
|
16229 | };
|
16230 |
|
16231 | __proto.update = function (ctx) {
|
16232 | var session = ctx.session;
|
16233 | if (!this._initialized) return;
|
16234 | var deadzoneChecker = this._deadzoneChecker;
|
16235 | var inputSources = session.inputSources;
|
16236 |
|
16237 | if (deadzoneChecker.inDeadzone) {
|
16238 | this._checkDeadzone(ctx, inputSources);
|
16239 | } else {
|
16240 | this._processInput(ctx, inputSources);
|
16241 | }
|
16242 |
|
16243 | this._updateControls(ctx);
|
16244 | };
|
16245 |
|
16246 | __proto._checkDeadzone = function (ctx, inputSources) {
|
16247 | var coords = this._inputSourceToVector(inputSources);
|
16248 |
|
16249 | var gesture = this._deadzoneChecker.check(coords.map(function (coord) {
|
16250 | return coord.clone();
|
16251 | }));
|
16252 |
|
16253 | var rotateControl = this._rotateControl;
|
16254 | var translateControl = this._translateControl;
|
16255 | var scaleControl = this._scaleControl;
|
16256 | if (gesture === GESTURE.NONE) return;
|
16257 |
|
16258 | switch (gesture) {
|
16259 | case GESTURE.ONE_FINGER_HORIZONTAL:
|
16260 | case GESTURE.ONE_FINGER_VERTICAL:
|
16261 | if (this._modelHit) {
|
16262 | translateControl.activate(ctx, gesture);
|
16263 | translateControl.setInitialPos(coords);
|
16264 | } else {
|
16265 | rotateControl.activate(ctx, gesture);
|
16266 | rotateControl.setInitialPos(coords);
|
16267 | }
|
16268 |
|
16269 | break;
|
16270 |
|
16271 | case GESTURE.TWO_FINGER_HORIZONTAL:
|
16272 | case GESTURE.TWO_FINGER_VERTICAL:
|
16273 | rotateControl.activate(ctx, gesture);
|
16274 | rotateControl.setInitialPos(coords);
|
16275 | break;
|
16276 |
|
16277 | case GESTURE.PINCH:
|
16278 | scaleControl.activate(ctx, gesture);
|
16279 | scaleControl.setInitialPos(coords);
|
16280 | break;
|
16281 | }
|
16282 | };
|
16283 |
|
16284 | __proto._processInput = function (ctx, inputSources) {
|
16285 | var coords = this._inputSourceToVector(inputSources);
|
16286 |
|
16287 | this.controls.forEach(function (control) {
|
16288 | return control.process(ctx, {
|
16289 | coords: coords,
|
16290 | inputSources: inputSources
|
16291 | });
|
16292 | });
|
16293 | };
|
16294 |
|
16295 | __proto._updateControls = function (ctx) {
|
16296 | var view3d = ctx.view3d,
|
16297 | model = ctx.model,
|
16298 | delta = ctx.delta;
|
16299 | var deltaMilisec = delta * 1000;
|
16300 | this.controls.forEach(function (control) {
|
16301 | return control.update(ctx, deltaMilisec);
|
16302 | });
|
16303 | model.scene.updateMatrix();
|
16304 | view3d.scene.update(model);
|
16305 | };
|
16306 |
|
16307 | __proto._inputSourceToVector = function (inputSources) {
|
16308 | return Array.from(inputSources).map(function (inputSource) {
|
16309 | var axes = inputSource.gamepad.axes;
|
16310 | return new Vector2(axes[0], -axes[1]);
|
16311 | });
|
16312 | };
|
16313 |
|
16314 | return ARHoverControl;
|
16315 | }();
|
16316 |
|
16317 | /*
|
16318 | * Copyright (c) 2020 NAVER Corp.
|
16319 | * egjs projects are licensed under the MIT license
|
16320 | */
|
16321 | /**
|
16322 | * WebXR based AR session which puts model at the space front of camera.
|
16323 | * @category XR
|
16324 | * @fires WebARSession#start
|
16325 | * @fires WebARSession#end
|
16326 | * @fires WebARSession#canPlace
|
16327 | * @fires WebARSession#modelPlaced
|
16328 | */
|
16329 |
|
16330 | var HoverARSession =
|
16331 | /*#__PURE__*/
|
16332 | function (_super) {
|
16333 | __extends(HoverARSession, _super);
|
16334 | /**
|
16335 | * Create new instance of HoverARSession
|
16336 | * @param {HoverARSessionOption} options Options
|
16337 | */
|
16338 |
|
16339 |
|
16340 | function HoverARSession(options) {
|
16341 | if (options === void 0) {
|
16342 | options = {};
|
16343 | }
|
16344 |
|
16345 | var _this = _super.call(this, options) || this;
|
16346 |
|
16347 | _this.onStart = function (ctx) {
|
16348 | var view3d = ctx.view3d;
|
16349 |
|
16350 | _super.prototype.onStart.call(_this, ctx);
|
16351 |
|
16352 | _this._control = new ARHoverControl(_this._options);
|
16353 | view3d.scene.hide();
|
16354 | };
|
16355 |
|
16356 | _this.onEnd = function (ctx) {
|
16357 | var view3d = ctx.view3d,
|
16358 | session = ctx.session;
|
16359 |
|
16360 | _super.prototype.onEnd.call(_this, ctx);
|
16361 |
|
16362 | _this._renderContext = null;
|
16363 | _this._modelPlaced = false;
|
16364 | session.removeEventListener(EVENTS$1.SELECT_START, _this._onSelectStart);
|
16365 | session.removeEventListener(EVENTS$1.SELECT_END, _this._onSelectEnd);
|
16366 |
|
16367 | _this._control.destroy(ctx);
|
16368 |
|
16369 | _this._control = null;
|
16370 | view3d.scene.show();
|
16371 | };
|
16372 |
|
16373 | _this._beforeRender = function (ctx) {
|
16374 | _this._renderContext = ctx;
|
16375 |
|
16376 | if (!_this._modelPlaced) {
|
16377 | _this._initModelPosition(ctx);
|
16378 | } else {
|
16379 | _this._control.update(ctx);
|
16380 | }
|
16381 | };
|
16382 |
|
16383 | _this._onSelectStart = function (e) {
|
16384 | _this._control.onSelectStart(__assign(__assign({}, _this._renderContext), {
|
16385 | frame: e.frame
|
16386 | }));
|
16387 | };
|
16388 |
|
16389 | _this._onSelectEnd = function () {
|
16390 | _this._control.onSelectEnd();
|
16391 | };
|
16392 |
|
16393 | _this._control = null;
|
16394 | _this._renderContext = null;
|
16395 | _this._modelPlaced = false;
|
16396 | _this._options = options;
|
16397 | return _this;
|
16398 | }
|
16399 |
|
16400 | var __proto = HoverARSession.prototype;
|
16401 | Object.defineProperty(__proto, "control", {
|
16402 | /**
|
16403 | * {@link ARControl} instance of this session
|
16404 | * @type ARHoverControl | null
|
16405 | */
|
16406 | get: function () {
|
16407 | return this._control;
|
16408 | },
|
16409 | enumerable: false,
|
16410 | configurable: true
|
16411 | });
|
16412 | /**
|
16413 | * Place model on the current position
|
16414 | */
|
16415 |
|
16416 | __proto.placeModel = function () {
|
16417 | var ctx = this._renderContext; // Not ready to place model yet
|
16418 |
|
16419 | if (!ctx || !ctx.view3d.scene.visible || this._modelPlaced) return;
|
16420 | var session = ctx.session,
|
16421 | view3d = ctx.view3d;
|
16422 | var modelRoot = view3d.model.scene;
|
16423 | var control = this._control;
|
16424 | session.addEventListener(EVENTS$1.SELECT_START, this._onSelectStart);
|
16425 | session.addEventListener(EVENTS$1.SELECT_END, this._onSelectEnd);
|
16426 | this._modelPlaced = true;
|
16427 | this.emit("modelPlaced"); // Show scale up animation
|
16428 |
|
16429 | var originalModelScale = modelRoot.scale.clone();
|
16430 | var scaleUpAnimation = new Animation({
|
16431 | context: session
|
16432 | });
|
16433 | scaleUpAnimation.on("progress", function (evt) {
|
16434 | var newScale = originalModelScale.clone().multiplyScalar(evt.easedProgress);
|
16435 | modelRoot.scale.copy(newScale);
|
16436 | });
|
16437 | scaleUpAnimation.on("finish", function () {
|
16438 | modelRoot.scale.copy(originalModelScale);
|
16439 | control.init(ctx);
|
16440 | });
|
16441 | scaleUpAnimation.start();
|
16442 | };
|
16443 |
|
16444 | __proto._initModelPosition = function (ctx) {
|
16445 | var view3d = ctx.view3d,
|
16446 | xrCam = ctx.xrCam;
|
16447 | var model = view3d.model; // Make sure the model exist
|
16448 |
|
16449 | if (!model) return;
|
16450 | var modelRoot = model.scene;
|
16451 | var camPos = new Vector3().setFromMatrixPosition(xrCam.matrixWorld);
|
16452 | var camQuat = new Quaternion().setFromRotationMatrix(xrCam.matrixWorld);
|
16453 | var viewDir = new Vector3(0, 0, -1).applyQuaternion(camQuat);
|
16454 | var modelBbox = model.bbox;
|
16455 | var bboxDiff = new Vector3().subVectors(modelBbox.max, modelBbox.min);
|
16456 | var maxComponent = Math.max(bboxDiff.x, bboxDiff.y, bboxDiff.z); // Reset rotation & update position
|
16457 |
|
16458 | modelRoot.position.copy(camPos);
|
16459 | modelRoot.position.add(viewDir.multiplyScalar(clamp(maxComponent, 0.5, 3))); // Place at 1m from camera
|
16460 |
|
16461 | modelRoot.lookAt(camPos.setY(modelRoot.position.y));
|
16462 | modelRoot.updateMatrix();
|
16463 | view3d.scene.update(model);
|
16464 |
|
16465 | if (!view3d.scene.visible) {
|
16466 | view3d.scene.show();
|
16467 | this.emit("canPlace");
|
16468 | }
|
16469 | };
|
16470 |
|
16471 | return HoverARSession;
|
16472 | }(WebARSession);
|
16473 |
|
16474 | /*
|
16475 | * Copyright (c) 2020 NAVER Corp.
|
16476 | * egjs projects are licensed under the MIT license
|
16477 | */
|
16478 | // Browser related constants
|
16479 | var IS_IOS = /iPad|iPhone|iPod/.test(navigator.userAgent) || navigator.platform === "MacIntel" && navigator.maxTouchPoints > 1;
|
16480 | var IS_ANDROID = /android/i.test(navigator.userAgent);
|
16481 | var IS_SAFARI = /safari/i.test(navigator.userAgent);
|
16482 |
|
16483 | /*
|
16484 | * Copyright (c) 2020 NAVER Corp.
|
16485 | * egjs projects are licensed under the MIT license
|
16486 | */
|
16487 | /**
|
16488 | * AR session using Google's scene-viewer
|
16489 | * @category XR
|
16490 | * @see https://developers.google.com/ar/develop/java/scene-viewer
|
16491 | */
|
16492 |
|
16493 | var SceneViewerSession =
|
16494 | /*#__PURE__*/
|
16495 | function () {
|
16496 | /**
|
16497 | * Create new instance of SceneViewerSession
|
16498 | * @see https://developers.google.com/ar/develop/java/scene-viewer
|
16499 | * @param params Session params
|
16500 | * @param {string} [params.file] This URL specifies the glTF or glb file that should be loaded into Scene Viewer. This should be URL-escaped.
|
16501 | * @param {string} [params.browser_fallback_url] This is a Google Chrome feature supported only for web-based implementations. When the Google app com.google.android.googlequicksearchbox is not present on the device, this is the URL that Google Chrome navigates to.
|
16502 | * @param {string} [params.mode="ar_only"] See {@link https://developers.google.com/ar/develop/java/scene-viewer} for available modes.
|
16503 | * @param {string} [params.title] A name for the model. If present, it will be displayed in the UI. The name will be truncated with ellipses after 60 characters.
|
16504 | * @param {string} [params.link] A URL for an external webpage. If present, a button will be surfaced in the UI that intents to this URL when clicked.
|
16505 | * @param {string} [params.sound] A URL to a looping audio track that is synchronized with the first animation embedded in a glTF file. It should be provided alongside a glTF with an animation of matching length. If present, the sound is looped after the model is loaded. This should be URL-escaped.
|
16506 | * @param {string} [params.resizable=true] When set to false, users will not be able to scale the model in the AR experience. Scaling works normally in the 3D experience.
|
16507 | */
|
16508 | function SceneViewerSession(params) {
|
16509 | this.params = params;
|
16510 | this.isWebXRSession = false;
|
16511 |
|
16512 | if (!this.params.mode) {
|
16513 | // Default mode is "ar_only", which should use com.google.ar.core package
|
16514 | this.params.mode = "ar_only";
|
16515 | }
|
16516 | }
|
16517 | /**
|
16518 | * Return the availability of SceneViewerSession.
|
16519 | * Scene-viewer is available on all android devices with google ARCore installed.
|
16520 | * @returns {Promise} A Promise that resolves availability of this session(boolean).
|
16521 | */
|
16522 |
|
16523 |
|
16524 | var __proto = SceneViewerSession.prototype;
|
16525 |
|
16526 | __proto.isAvailable = function () {
|
16527 | return Promise.resolve(IS_ANDROID);
|
16528 | };
|
16529 | /**
|
16530 | * Enter Scene-viewer AR session
|
16531 | */
|
16532 |
|
16533 |
|
16534 | __proto.enter = function () {
|
16535 | var params = Object.assign({}, this.params);
|
16536 | var fallback = params.browser_fallback_url;
|
16537 | delete params.browser_fallback_url;
|
16538 | var resizable = params.resizable;
|
16539 | delete params.resizable;
|
16540 |
|
16541 | if (resizable === true) {
|
16542 | params.resizable = "true";
|
16543 | } else if (resizable === false) {
|
16544 | params.resizable = "false";
|
16545 | } else if (resizable) {
|
16546 | params.resizable = resizable;
|
16547 | }
|
16548 |
|
16549 | var queryString = Object.keys(params).filter(function (key) {
|
16550 | return params[key] != null;
|
16551 | }).map(function (key) {
|
16552 | return key + "=" + params[key];
|
16553 | }).join("&");
|
16554 | var intentURL = params.mode === "ar_only" ? SCENE_VIEWER.INTENT_AR_CORE(queryString, fallback) : SCENE_VIEWER.INTENT_SEARCHBOX(queryString, fallback || SCENE_VIEWER.FALLBACK_DEFAULT(queryString));
|
16555 | var anchor = document.createElement("a");
|
16556 | anchor.href = intentURL;
|
16557 | anchor.click();
|
16558 | return Promise.resolve();
|
16559 | };
|
16560 |
|
16561 | __proto.exit = function () {// DO NOTHING
|
16562 | };
|
16563 |
|
16564 | return SceneViewerSession;
|
16565 | }();
|
16566 |
|
16567 | /*
|
16568 | * Copyright (c) 2020 NAVER Corp.
|
16569 | * egjs projects are licensed under the MIT license
|
16570 | */
|
16571 | /**
|
16572 | * AR Session using Apple AR Quick Look Viewer
|
16573 | * @category XR
|
16574 | * @see https://developer.apple.com/augmented-reality/quick-look/
|
16575 | */
|
16576 |
|
16577 | var QuickLookSession =
|
16578 | /*#__PURE__*/
|
16579 | function () {
|
16580 | /**
|
16581 | * Create new instance of QuickLookSession
|
16582 | * @param {object} [options] Quick Look options
|
16583 | * @param {string} [options.file] USDZ file's location URL.
|
16584 | * @param {boolean} [options.allowsContentScaling=true] Whether to allow content scaling.
|
16585 | */
|
16586 | function QuickLookSession(_a) {
|
16587 | var file = _a.file,
|
16588 | _b = _a.allowsContentScaling,
|
16589 | allowsContentScaling = _b === void 0 ? true : _b;
|
16590 | /**
|
16591 | * Whether it's webxr-based session or not
|
16592 | * @type false
|
16593 | */
|
16594 |
|
16595 | this.isWebXRSession = false;
|
16596 | this._file = file;
|
16597 | this._allowsContentScaling = allowsContentScaling;
|
16598 | }
|
16599 | /**
|
16600 | * Return the availability of QuickLookSession.
|
16601 | * QuickLook AR is available on iOS12+ on Safari & Chrome browser
|
16602 | * Note that iOS Chrome won't show up QuickLook AR when it's local dev environment
|
16603 | * @returns {Promise} A Promise that resolves availability of this session(boolean).
|
16604 | */
|
16605 |
|
16606 |
|
16607 | var __proto = QuickLookSession.prototype;
|
16608 |
|
16609 | __proto.isAvailable = function () {
|
16610 | // This can handle all WebKit based browsers including iOS Safari & iOS Chrome
|
16611 | return Promise.resolve(QUICKLOOK_SUPPORTED && IS_IOS && IS_SAFARI);
|
16612 | };
|
16613 | /**
|
16614 | * Enter QuickLook AR Session
|
16615 | */
|
16616 |
|
16617 |
|
16618 | __proto.enter = function () {
|
16619 | var anchor = document.createElement("a");
|
16620 | anchor.setAttribute("rel", "ar");
|
16621 | anchor.appendChild(document.createElement("img"));
|
16622 | var usdzURL = new URL(this._file, window.location.toString());
|
16623 |
|
16624 | if (!this._allowsContentScaling) {
|
16625 | usdzURL.hash = "allowsContentScaling=0";
|
16626 | }
|
16627 |
|
16628 | anchor.setAttribute("href", usdzURL.toString());
|
16629 | anchor.click();
|
16630 | return Promise.resolve();
|
16631 | };
|
16632 |
|
16633 | __proto.exit = function () {// DO NOTHING
|
16634 | };
|
16635 |
|
16636 | return QuickLookSession;
|
16637 | }();
|
16638 |
|
16639 | /*
|
16640 | * Copyright (c) 2020 NAVER Corp.
|
16641 | * egjs projects are licensed under the MIT license
|
16642 | */
|
16643 |
|
16644 | var XR = {
|
16645 | __proto__: null,
|
16646 | WebARSession: WebARSession,
|
16647 | FloorARSession: FloorARSession,
|
16648 | WallARSession: WallARSession,
|
16649 | HoverARSession: HoverARSession,
|
16650 | SceneViewerSession: SceneViewerSession,
|
16651 | QuickLookSession: QuickLookSession
|
16652 | };
|
16653 |
|
16654 | /*
|
16655 | * Copyright (c) 2020 NAVER Corp.
|
16656 | * egjs projects are licensed under the MIT license
|
16657 | */
|
16658 | /**
|
16659 | * Texture(image) model
|
16660 | * @category Extra
|
16661 | */
|
16662 |
|
16663 | var TextureModel =
|
16664 | /*#__PURE__*/
|
16665 | function (_super) {
|
16666 | __extends(TextureModel, _super);
|
16667 | /**
|
16668 | * Create new TextureModel
|
16669 | * @param {object} options Options
|
16670 | * @param {number} [options.width] Width of the model.
|
16671 | * @param {number} [options.height] Height of the model.
|
16672 | * @param {boolean} [options.billboard=false] When set to true, model will keep rotate to show its front face to camera. Only Y-axis rotation is considered.
|
16673 | * @throws {View3DError} `CODES.PROVIDE_WIDTH_OR_HEIGHT` When both width and height are not given.
|
16674 | */
|
16675 |
|
16676 |
|
16677 | function TextureModel(_a) {
|
16678 | var image = _a.image,
|
16679 | width = _a.width,
|
16680 | height = _a.height,
|
16681 | _b = _a.billboard,
|
16682 | billboard = _b === void 0 ? false : _b;
|
16683 |
|
16684 | var _this = this;
|
16685 |
|
16686 | var texture = image.isTexture ? image : new Texture(image);
|
16687 | var aspect = texture.image.width / texture.image.height;
|
16688 |
|
16689 | if (width == null && height == null) {
|
16690 | throw new View3DError(MESSAGES.PROVIDE_WIDTH_OR_HEIGHT, CODES.PROVIDE_WIDTH_OR_HEIGHT);
|
16691 | }
|
16692 |
|
16693 | if (width == null) {
|
16694 | width = height * aspect;
|
16695 | } else if (height == null) {
|
16696 | height = width / aspect;
|
16697 | }
|
16698 |
|
16699 | texture.encoding = sRGBEncoding;
|
16700 | var geometry = new PlaneGeometry(width, height);
|
16701 | var material = new MeshBasicMaterial({
|
16702 | map: texture,
|
16703 | side: DoubleSide
|
16704 | });
|
16705 | var mesh = new Mesh(geometry, material);
|
16706 | _this = _super.call(this, {
|
16707 | scenes: [mesh]
|
16708 | }) || this;
|
16709 | _this._texture = texture;
|
16710 | _this._mesh = mesh;
|
16711 |
|
16712 | if (billboard) {
|
16713 | var root_1 = mesh;
|
16714 |
|
16715 | root_1.onBeforeRender = function (renderer, scene, camera) {
|
16716 | var pos = root_1.getWorldPosition(new Vector3());
|
16717 | var camPos = new Vector3().setFromMatrixPosition(camera.matrixWorld);
|
16718 | root_1.lookAt(camPos.setY(pos.y));
|
16719 | mesh.updateMatrix();
|
16720 | };
|
16721 | }
|
16722 |
|
16723 | return _this;
|
16724 | }
|
16725 |
|
16726 | var __proto = TextureModel.prototype;
|
16727 | Object.defineProperty(__proto, "texture", {
|
16728 | /**
|
16729 | * Texture that used for this model
|
16730 | * @see https://threejs.org/docs/index.html#api/en/textures/Texture
|
16731 | * @type THREE.Texture
|
16732 | */
|
16733 | get: function () {
|
16734 | return this._texture;
|
16735 | },
|
16736 | enumerable: false,
|
16737 | configurable: true
|
16738 | });
|
16739 | Object.defineProperty(__proto, "mesh", {
|
16740 | /**
|
16741 | * Model's mesh object
|
16742 | * @see https://threejs.org/docs/index.html#api/en/objects/Mesh
|
16743 | * @type THREE.Mesh
|
16744 | */
|
16745 | get: function () {
|
16746 | return this._mesh;
|
16747 | },
|
16748 | enumerable: false,
|
16749 | configurable: true
|
16750 | });
|
16751 | return TextureModel;
|
16752 | }(Model);
|
16753 |
|
16754 | /*
|
16755 | * Copyright (c) 2020 NAVER Corp.
|
16756 | * egjs projects are licensed under the MIT license
|
16757 | */
|
16758 |
|
16759 | var Extra = {
|
16760 | __proto__: null,
|
16761 | TextureModel: TextureModel
|
16762 | };
|
16763 |
|
16764 | /*
|
16765 | * Copyright (c) 2020 NAVER Corp.
|
16766 | * egjs projects are licensed under the MIT license
|
16767 | */
|
16768 |
|
16769 | var Externals = {
|
16770 | __proto__: null,
|
16771 | THREE: three_module
|
16772 | };
|
16773 |
|
16774 | /*
|
16775 | * Copyright (c) 2020 NAVER Corp.
|
16776 | * egjs projects are licensed under the MIT license
|
16777 | */
|
16778 | merge(View3D, Core);
|
16779 | merge(View3D, Environments);
|
16780 | merge(View3D, Controls);
|
16781 | merge(View3D, Loaders);
|
16782 | merge(View3D, XR);
|
16783 | merge(View3D, Extra);
|
16784 | merge(View3D, Externals);
|
16785 | View3D.View3DError = View3DError;
|
16786 | View3D.ERROR_CODES = CODES;
|
16787 | View3D.EASING = EASING;
|
16788 |
|
16789 | return View3D;
|
16790 |
|
16791 | })));
|
16792 | //# sourceMappingURL=view3d.pkgd.js.map
|