WP Photo Album Plus - Version 6.9.12.007

Version Description

= 6.9.12 =

  • This version addresses various minor bug fixes and performance improvements.

= 6.9.11 =

  • This version addresses various minor bug fixes and performance improvements.

= 6.9.10 =

  • This version addresses various minor bug fixes and performance improvements.

= 6.9.09 =

  • Panorama support phase III.

= 6.9.08 =

  • This version addresses various minor bug fixes and feature requests.
  • Panorama support phase II.

= 6.9.07 =

  • This version addresses various minor bug fixes and feature requests.
  • Panorama support phase I.

= 6.9.06 =

  • This version addresses various minor bug fixes and feature requests.

= 6.9.05 =

  • This version addresses various minor bug fixes and feature requests.

= 6.9.04 =

  • This version addresses various minor bug fixes and feature requests.
  • Local CDN functionality has been added.

= 6.9.03 =

  • This version addresses various minor bug fixes and feature requests.

= 6.9.02 =

  • This version addresses various minor bug fixes and feature requests.

= 6.9.01 =

  • This version addresses various minor bug fixes and feature requests.

= 6.9.00 =

  • This version includes the code for the privacy policy requirements.

= 6.8.09

  • This version addresses various bug fixes and code edits.

= 6.8.08 =

  • This version addresses various minor bug fixes and feature requests.
  • This version offers substantial performance improvements when the box in Table IV-A13: Defer Javascript is ticked. This setting is now recommended and set ticked as the default.
  • For more info on performance improvements and compatibility with optimizers: see the changelog.txt

= 6.8.07 =

  • This version addresses various minor bug fixes and enhancements, and a new widget: Statistics.

= 6.8.06 =

  • This version addresses various minor bug fixes and improved cache handling.

= 6.8.05 =

  • This version addresses various minor bug fixes and feture requests.

= 6.8.04 =

  • This version addresses various display issues and a few fixes of bugs that seldom affected the plugins behaviour.
Download this release

Release Info

Developer opajaap
Plugin Icon wp plugin WP Photo Album Plus
Version 6.9.12.007
Comparing to
See all releases

Code changes from version 6.9.11 to 6.9.12.007

changelog.txt CHANGED
@@ -1,5 +1,19 @@
1
  WP Photo Album Plus Changelog
2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  = 6.9.11 =
4
 
5
  = Bug Fixes =
1
  WP Photo Album Plus Changelog
2
 
3
+ = 6.9.12 =
4
+
5
+ = Bug Fixes =
6
+
7
+ * Fixed a layout issue on the settings page.
8
+ * Fixed a loayout issue on lightbox spheric panoramas that occurs when there are also normal photos in the set.
9
+ * Fixed uninitialized vars in widget activation screens.
10
+
11
+ = Other Changes =
12
+
13
+ * One can select 'none' in Table IV-H1: Panorama control bar.
14
+ * A smaller subset of THREE.js is now loaded, and it is only loaded when needed, provided that you have set defer javascript in Table IV-A13 (is the default).
15
+ * Panorama code is now also available at the backend edit screen if applicable.
16
+
17
  = 6.9.11 =
18
 
19
  = Bug Fixes =
js/wppa-lightbox.js CHANGED
@@ -3,7 +3,7 @@
3
  // Conatins lightbox modules
4
  // Dependancies: wppa.js and default wp jQuery library
5
  //
6
- var wppaLightboxVersion = '6.9.11';
7
 
8
  // Global inits
9
  var wppaNormsBtnOpac = 0.75;
@@ -28,7 +28,7 @@ var wppaSavedImageWidth;
28
  var wppaSavedImageHeight;
29
 
30
  // Panorama related vars
31
- var renderer, scene, camera, sphere, sphereMaterial, sphereMesh;
32
 
33
  // Initial initialization
34
  jQuery( document ).ready( function( e ) {
@@ -1020,10 +1020,10 @@ wppaConsoleLog( 'wppaOvlFormatFull '+wppaOvlMode );
1020
 
1021
  // Panoramas do their own resize
1022
  if ( wppaOvlActivePanorama > 0 ) {
1023
- setTimeout(function(){
1024
- wppaConsoleLog('kicking panorama from wppaOvlFormatFull');
1025
- jQuery(window).trigger("kickpanorama");
1026
- },125);
1027
  return;
1028
  }
1029
 
@@ -1312,7 +1312,7 @@ wppaConsoleLog( 'wppaOvlHide' );
1312
  // Remove spinner
1313
  jQuery( '#wppa-ovl-spin' ).hide();
1314
 
1315
- // Stop any panorama from running the renderer
1316
  wppaOvlActivePanorama = 0;
1317
 
1318
  // Record we are out
@@ -1433,10 +1433,10 @@ wppaConsoleLog( 'wppaOvlResize' );
1433
 
1434
  // Panoramas do their own resize
1435
  if ( wppaOvlActivePanorama > 0 ) {
1436
- setTimeout(function(){
1437
- wppaConsoleLog('kicking panorama from wppaOvlResize');
1438
- jQuery(window).trigger("kickpanorama");
1439
- },125);
1440
  return;
1441
  }
1442
 
3
  // Conatins lightbox modules
4
  // Dependancies: wppa.js and default wp jQuery library
5
  //
6
+ var wppaLightboxVersion = '6.9.12';
7
 
8
  // Global inits
9
  var wppaNormsBtnOpac = 0.75;
28
  var wppaSavedImageHeight;
29
 
30
  // Panorama related vars
31
+ var wppaRenderer, wppaScene, wppaCamera, wppaSphere, wppaSphereMaterial, wppaSphereMesh;
32
 
33
  // Initial initialization
34
  jQuery( document ).ready( function( e ) {
1020
 
1021
  // Panoramas do their own resize
1022
  if ( wppaOvlActivePanorama > 0 ) {
1023
+ // setTimeout(function(){
1024
+ // wppaConsoleLog('kicking panorama from wppaOvlFormatFull');
1025
+ // jQuery(window).trigger("kickpanorama");
1026
+ // },125);
1027
  return;
1028
  }
1029
 
1312
  // Remove spinner
1313
  jQuery( '#wppa-ovl-spin' ).hide();
1314
 
1315
+ // Stop any panorama from running the wppaRenderer
1316
  wppaOvlActivePanorama = 0;
1317
 
1318
  // Record we are out
1433
 
1434
  // Panoramas do their own resize
1435
  if ( wppaOvlActivePanorama > 0 ) {
1436
+ // setTimeout(function(){
1437
+ // wppaConsoleLog('kicking panorama from wppaOvlResize');
1438
+ // jQuery(window).trigger("kickpanorama");
1439
+ // },125);
1440
  return;
1441
  }
1442
 
js/wppa-lightbox.min.js CHANGED
@@ -1 +1 @@
1
- var wppaSavedContainerHeight,wppaSavedMarginLeft,wppaSavedMarginTop,wppaSavedImageWidth,wppaSavedImageHeight,renderer,scene,camera,sphere,sphereMaterial,sphereMesh,wppaLightboxVersion="6.9.11",wppaNormsBtnOpac=.75,wppaIsVideo=!1,wppaHasAudio=!1,wppaOvlImgs=[],wppaKbHandlerInstalled=!1,wppaOvlMode="",wppaOvlCurIdx=0,wppaOvlSvgInverse=!1,wppaOvlFsExitBtnSize="48",wppaOvlActivePanorama=0,wppaOvlHasPanoramas=!1,wppaGlobalOvlPanoramaId=0,wppaSavedContainerWidth=0;function wppaDoOnOrientationChange(p){"normal"!=wppaOvlMode&&document.getElementById("wppa-overlay-img")&&setTimeout("wppaOvlShow( "+wppaOvlIdx+" )",10)}function wppaOvlKeyboardHandler(p){var a,e;a=null==p?event.keyCode:p.keyCode,e=27;var t=String.fromCharCode(a).toLowerCase();switch(a){case e:wppaStopVideo(mocc),"normal"!=wppaOvlMode&&wppaOvlNorm(!0),wppaOvlHide();break;case 37:wppaOvlShowPrev();break;case 39:wppaOvlShowNext()}switch(t){case"p":wppaOvlShowPrev();break;case"n":wppaOvlShowNext();break;case"s":wppaOvlStartStop();break;case"d":jQuery("#wppa-ovl-legenda-1").css("visibility","hidden"),jQuery("#wppa-ovl-legenda-2").css("visibility","hidden"),wppaShowLegenda="hidden";break;case"f":wppaOvlFull();break;case"l":wppaOvlNorm();break;case"q":case"x":wppaStopVideo(mocc),"normal"!=wppaOvlMode&&wppaOvlNorm(!0),wppaOvlHide()}return!1}function wppaOvlFull(p){wppaConsoleLog("wppaOvlFull"),wppaNormsBtnOpac=.75;var a=wppaOvlMode;p||wppaOvlStepMode();var e=document.getElementById("wppa-overlay-ic");e&&((p||"normal"==a)&&(e.requestFullscreen?e.requestFullscreen():e.mozRequestFullScreen?e.mozRequestFullScreen():e.webkitRequestFullscreen&&e.webkitRequestFullscreen()),"normal"==wppaOvlMode&&(document.cancelFullScreen?document.cancelFullScreen():document.mozCancelFullScreen?document.mozCancelFullScreen():document.webkitCancelFullScreen&&document.webkitCancelFullScreen()),setTimeout(function(){wppaShowFsButtons(.75)},30),jQuery("#wppa-ovl-legenda-1").html(""))}function wppaOvlNorm(p){wppaConsoleLog("wppaOvlNorm"),wppaOvlMode="normal",wppaNormsBtnOpac=.75,document.cancelFullScreen?document.cancelFullScreen():document.mozCancelFullScreen?document.mozCancelFullScreen():document.webkitCancelFullScreen&&document.webkitCancelFullScreen(),p?wppaOvlMode=wppaOvlModeInitial:(setTimeout(function(){wppaShowFsButtons(.75)},30),setTimeout(function(){wppaOvlShow(wppaOvlIdx)},50))}function wppaOvlShow(p){var a,e;if(wppaConsoleLog("wppaOvlShow arg="+p),0<wppaOvlActivePanorama?jQuery("#wppa-overlay-ic").css({top:0,left:0}):jQuery("#wppa-overlay-ic").css({top:"50%",left:"50%"}),wppaOvlFirst&&(jQuery("#weaver-final").removeClass("wvr-hide-bang"),jQuery("#wppa-overlay-bg").stop().fadeTo(3,wppaOvlOpacity),wppaKbHandlerInstalled||(jQuery(document).on("keydown",wppaOvlKeyboardHandler),wppaKbHandlerInstalled=!0),jQuery("#wppa-overlay-bg").css({width:window.innerWidth,height:window.innerHeight}),"normal"!=wppaOvlModeInitial&&wppaOvlFull(!0)),"object"==typeof p){wppaOvlUrls=[],wppaOvlTitles=[],wppaOvlAlts=[],wppaOvlVideoHtmls=[],wppaOvlAudioHtmls=[],wppaOvlVideoNaturalWidths=[],wppaOvlVideoNaturalHeights=[],wppaOvlImgs=[],wppaOvlIdx=0,wppaOvlPanoramaHtml=[],wppaOvlPanoramaIds=[],wppaOvlHasPanoramas=!1;var t=(p.rel?p.rel:!!jQuery(p).attr("data-rel")&&jQuery(p).attr("data-rel")).split("[");if(t[1]){var o,l,i=t[1],n=jQuery("a"),r=0;for(l=0;l<n.length;l++)o=n[l],1<(t=!!jQuery(o).attr("data-rel")&&jQuery(o).attr("data-rel").split("[")).length&&"wppa"==t[0]&&t[1]==i&&(wppaOvlUrls[r]=o.href,jQuery(o).attr("data-lbtitle")?wppaOvlTitles[r]=wppaRepairScriptTags(jQuery(o).attr("data-lbtitle")):wppaOvlTitles[r]=wppaRepairScriptTags(o.title),wppaOvlAlts[r]=jQuery(o).attr("data-alt")?jQuery(o).attr("data-alt"):"",wppaOvlVideoHtmls[r]=jQuery(o).attr("data-videohtml")?decodeURI(jQuery(o).attr("data-videohtml")):"",wppaOvlAudioHtmls[r]=jQuery(o).attr("data-audiohtml")?decodeURI(jQuery(o).attr("data-audiohtml")):"",wppaOvlVideoNaturalWidths[r]=jQuery(o).attr("data-videonatwidth")?jQuery(o).attr("data-videonatwidth"):"",wppaOvlVideoNaturalHeights[r]=jQuery(o).attr("data-videonatheight")?jQuery(o).attr("data-videonatheight"):"",0<(a=jQuery(o).attr("data-panorama")?jQuery(o).attr("data-panorama"):"").length?(wppaOvlHasPanoramas=!0,e=a.indexOf("."),wppaOvlPanoramaHtml[r]=a.substr(e+1),wppaOvlPanoramaIds[r]=a.substr(0,e)):(wppaOvlPanoramaHtml[r]="",wppaOvlPanoramaIds[r]=0),o.href==p.href&&(wppaOvlIdx=r),r++)}else wppaOvlUrls[0]=p.href,jQuery(p).attr("data-lbtitle")?wppaOvlTitles[0]=wppaRepairScriptTags(jQuery(p).attr("data-lbtitle")):wppaOvlTitles[0]=wppaRepairScriptTags(p.title),wppaOvlAlts[0]=jQuery(p).attr("data-alt")?jQuery(p).attr("data-alt"):"",wppaOvlVideoHtmls[0]=jQuery(p).attr("data-videohtml")?decodeURI(jQuery(p).attr("data-videohtml")):"",wppaOvlAudioHtmls[0]=jQuery(p).attr("data-audiohtml")?decodeURI(jQuery(p).attr("data-audiohtml")):"",wppaOvlVideoNaturalWidths[0]=jQuery(p).attr("data-videonatwidth")?jQuery(p).attr("data-videonatwidth"):"",wppaOvlVideoNaturalHeights[0]=jQuery(p).attr("data-videonatheight")?jQuery(p).attr("data-videonatheight"):"",0<(a=jQuery(p).attr("data-panorama")?jQuery(p).attr("data-panorama"):"").length?(wppaOvlHasPanoramas=!0,e=a.indexOf("."),wppaOvlPanoramaHtml[0]=a.substr(e+1),wppaOvlPanoramaIds[0]=a.substr(0,e)):(wppaOvlPanoramaHtml[0]="",wppaOvlPanoramaIds[0]=0),wppaOvlIdx=0}else wppaOvlIdx=p;wppaOvlOpen=!0,setTimeout(function(){_wppaOvlShow(wppaOvlIdx)},1)}function _wppaOvlShow(p){if(wppaConsoleLog("_wppaOvlShow, idx="+p),wppaOvlCurIdx=p,wppaOvlFirst&&jQuery("#wppa-ovl-spin").show(),wppaIsVideo=""!=wppaOvlVideoHtmls[p],wppaHasAudio=""!=wppaOvlAudioHtmls[p],0<wppaOvlUrls[p].length&&!wppaIsVideo&&(wppaOvlImgs[p]=new Image,wppaOvlImgs[p].src=wppaOvlUrls[p],wppaConsoleLog("Preloading "+(p+1)+"/"+wppaOvlUrls.length+" (current)"),!wppaIsIe&&!wppaOvlImgs[p].complete&&wppaOvlOpen))return wppaConsoleLog("Retrying preload current image"),void setTimeout("_wppaOvlShow("+p+")",500);var a,e;if(a=wppaOvlIdx==wppaOvlUrls.length-1?0:wppaOvlIdx+1,""==wppaOvlVideoHtmls[a]&&wppaOvlOpen&&(wppaOvlImgs[a]=new Image,wppaOvlImgs[a].src=wppaOvlUrls[a],wppaConsoleLog("Preloading > "+(a+1))),!wppaOvlRunning&&wppaOvlOpen&&(e=0==wppaOvlIdx?wppaOvlUrls.length-1:wppaOvlIdx-1,""==wppaOvlVideoHtmls[e]&&(wppaOvlImgs[e]=new Image,wppaOvlImgs[e].src=wppaOvlUrls[e],wppaConsoleLog("Preloading < "+(e+1)))),wppaPhotoId=wppaUrlToId(wppaOvlUrls[p]),_bumpViewCount(wppaPhotoId),wppaOvlIsSingle=1==wppaOvlUrls.length,0<wppaOvlPanoramaIds[p]?(wppaOvlActivePanorama=wppaOvlPanoramaIds[p],jQuery("#wppa-overlay-ic").css({top:0,left:0})):(wppaOvlActivePanorama=0,jQuery("#wppa-overlay-ic").css({top:"50%",left:"50%",display:"block"})),"normal"!=wppaOvlMode||wppaOvlActivePanorama){wppaOvlActivePanorama?(l=wppaOvlPanoramaHtml[p]+"<div style=\"height: 20px; width: 100%; position:absolute; top:0; left:0;\" onmouseover=\"jQuery('#wppa-ovl-legenda-2').css('visibility','visible');\" onmouseout=\"jQuery('#wppa-ovl-legenda-2').css('visibility','hidden');wppaShowLegenda='hidden';\" >",wppaOvlShowLegenda&&"normal"!=wppaOvlMode&&(l+='<div id="wppa-ovl-legenda-2" style="position:fixed; left:0; top:0; background-color:'+("black"==wppaOvlTheme?"#272727":"#a7a7a7")+"; color:"+("black"==wppaOvlTheme?"#a7a7a7":"#272727")+"; visibility:"+wppaShowLegenda+';" >Mode=fullscreen. '+(wppaOvlIsSingle?wppaOvlFullLegendaSinglePanorama:wppaOvlFullLegendaPanorama)+"</div>")):(wppaIsVideo?l='<div id="wppa-ovl-full-bg" style="position:fixed; width:'+screen.width+"px; height:"+screen.height+'px; left:0px; top:0px; text-align:center;" ><video id="wppa-overlay-img" controls preload="metadata"'+(wppaOvlVideoStart?" autoplay":"")+' ontouchstart="wppaTouchStart( event, \'wppa-overlay-img\', -1 );" ontouchend="wppaTouchEnd( event );" ontouchmove="wppaTouchMove( event );" ontouchcancel="wppaTouchCancel( event );" onpause="wppaOvlVideoPlaying = false;" onplay="wppaOvlVideoPlaying = true;" style="border:none; width:'+screen.width+'px; box-shadow:none; position:absolute;" alt="'+wppaOvlAlts[p]+'" >'+wppaOvlVideoHtmls[p]+"</video><div style=\"height: 20px; width: 100%; position:absolute; top:0; left:0;\" onmouseover=\"jQuery('#wppa-ovl-legenda-2').css('visibility','visible');\" onmouseout=\"jQuery('#wppa-ovl-legenda-2').css('visibility','hidden');wppaShowLegenda='hidden';\" >":(l='<div id="wppa-ovl-full-bg" style="position:fixed; width:'+screen.width+"px; height:"+screen.height+'px; left:0px; top:0px; text-align:center;" ><img id="wppa-overlay-img" ontouchstart="wppaTouchStart( event, \'wppa-overlay-img\', -1 );" ontouchend="wppaTouchEnd( event );" ontouchmove="wppaTouchMove( event );" ontouchcancel="wppaTouchCancel( event );" src="'+wppaOvlUrls[p]+'" style="border:none; width:'+screen.width+'px; visibility:hidden; box-shadow:none; position:absolute;" alt="'+wppaOvlAlts[p]+'" />',wppaHasAudio&&(l+='<audio id="wppa-overlay-audio" class="wppa-overlay-audio" data-from="wppa" preload="metadata"'+(wppaOvlAudioStart?" autoplay":"")+' onpause="wppaOvlAudioPlaying = false;" onplay="wppaOvlAudioPlaying = true;" style="width:100%;position:absolute;left:0px;bottom:0px;padding:0;" controls >'+wppaOvlAudioHtmls[p]+"</audio>"),l+="<div style=\"height: 20px; width: 100%; position:absolute; top:0; left:0;\" onmouseover=\"jQuery('#wppa-ovl-legenda-2').css('visibility','visible');\" onmouseout=\"jQuery('#wppa-ovl-legenda-2').css('visibility','hidden');wppaShowLegenda='hidden';\" >"),wppaOvlShowLegenda&&(l+='<div id="wppa-ovl-legenda-2" style="position:fixed; left:0; top:0; background-color:'+("black"==wppaOvlTheme?"#272727":"#a7a7a7")+"; color:"+("black"==wppaOvlTheme?"#a7a7a7":"#272727")+"; visibility:"+wppaShowLegenda+';" >Mode='+wppaOvlMode+". "+(wppaOvlIsSingle?wppaOvlFullLegendaSingle:wppaOvlFullLegenda)+"</div>")),l+="</div>";var t=(wppaIsMobile,"0.1");return l+='<div id="wppa-exit-btn" style="height:'+wppaOvlFsExitBtnSize+"px;z-index:100098;position:fixed;top:0;right:0;opacity:"+wppaNormsBtnOpac+';" onclick="wppaOvlHide()" onmouseover="jQuery(this).stop().fadeTo(300,1);" ontouchstart="jQuery(this).stop().fadeTo(300,1);" onmouseout="jQuery(this).stop().fadeTo(300,'+t+");wppaNormsBtnOpac="+t+';" ontouchend="jQuery(this).stop().fadeTo(300,'+t+");wppaNormsBtnOpac="+t+';" >'+wppaSvgHtml("Exit",wppaOvlFsExitBtnSize+"px",!0,!0,"0","0","0","0")+"</div>","normal"!=wppaOvlMode&&(l+='<div id="wppa-norms-btn" style="height:48px;z-index:100098;position:fixed;top:0;right:'+wppaOvlFsExitBtnSize+"px;opacity:"+wppaNormsBtnOpac+';" onclick="wppaOvlNorm()" onmouseover="jQuery(this).stop().fadeTo(300,1);" ontouchstart="jQuery(this).stop().fadeTo(300,1);" onmouseout="jQuery(this).stop().fadeTo(300,'+t+");wppaNormsBtnOpac="+t+';" ontouchend="jQuery(this).stop().fadeTo(300,'+t+");wppaNormsBtnOpac="+t+';" >'+wppaSvgHtml("Exit-Full-Screen",wppaOvlFsExitBtnSize+"px",!0,!0,"0","0","0","0")+"</div>"),(wppaIsVideo||wppaHasAudio)&&wppaOvlFsPhotoId==wppaPhotoId&&0!=wppaPhotoId||(wppaStopVideo(0),wppaStopAudio(),jQuery("#wppa-overlay-ic").html(l)),0<wppaOvlPanoramaIds[p]&&wppaOvlIsSingle&&jQuery(".wppa-pan-prevnext").hide(),wppaProtect(),wppaOvlIsVideo=wppaIsVideo,setTimeout("wppaOvlFormatFull()",10),wppaIsVideo||wppaHasAudio?setTimeout("wppaOvlUpdateFsId()",20):wppaOvlFsPhotoId=0,wppaOvlFirst=!1,wppaShowFsButtons(),!1}wppaOvlFsPhotoId=0,wppaPhotoId=0,wppaStopVideo(0);var o="black"==wppaOvlTheme?"#a7a7a7":"#272727";wppaOvlFontColor&&(o=wppaOvlFontColor);wppaOvlUrls.length;jQuery("#wppa-overlay-ic").css({width:wppaSavedContainerWidth,marginLeft:wppaSavedMarginLeft,marginTop:wppaSavedMarginTop});var l="";l+='<div id="img-sb-img-cont" style="position:relative;line-height:0;" >',wppaIsVideo?(l+='<video id="wppa-overlay-img" onmouseover="jQuery(\'.wppa-ovl-nav-btn\').stop().fadeTo(200,0.8);" onmouseout="jQuery(\'.wppa-ovl-nav-btn\').stop().fadeTo(200,0);" preload="metadata"'+(wppaOvlVideoStart?" autoplay":"")+' onpause="wppaOvlVideoPlaying = false;" onplay="wppaOvlVideoPlaying = true;" ontouchstart="wppaTouchStart( event, \'wppa-overlay-img\', -1 );" ontouchend="wppaTouchEnd( event );" ontouchmove="wppaTouchMove( event );" ontouchcancel="wppaTouchCancel( event );" controls style="border-width:'+wppaOvlBorderWidth+"px "+wppaOvlBorderWidth+"px 0;border-style:solid;border-color:"+wppaOvlTheme+";width:"+wppaSavedImageWidth+"px;height:"+wppaSavedImageHeight+"px;box-shadow:none;box-sizing:content-box;position:relative;border-top-left-radius:"+wppaOvlRadius+"px;border-top-right-radius:"+wppaOvlRadius+'px;margin:0;padding:0;" alt="'+wppaOvlAlts[p]+'" >'+wppaOvlVideoHtmls[p]+"</video>",wppaOvlIsVideo=!0):(l+='<img id="wppa-overlay-img" onmouseover="jQuery(\'.wppa-ovl-nav-btn\').stop().fadeTo(200,0.8);" onmouseout="jQuery(\'.wppa-ovl-nav-btn\').stop().fadeTo(200,0);" ontouchstart="wppaTouchStart( event, \'wppa-overlay-img\', -1 );" ontouchend="wppaTouchEnd( event );" ontouchmove="wppaTouchMove( event );" ontouchcancel="wppaTouchCancel( event );" src="'+wppaOvlUrls[p]+'" style="border-width:'+wppaOvlBorderWidth+"px "+wppaOvlBorderWidth+"px 0;border-style:solid;border-color:"+wppaOvlTheme+";width:"+wppaSavedImageWidth+"px;height:"+wppaSavedImageHeight+"px;box-shadow:none;box-sizing:content-box;position:relative;border-top-left-radius:"+wppaOvlRadius+"px;border-top-right-radius:"+wppaOvlRadius+'px;margin:0;padding:0;" alt="'+wppaOvlAlts[p]+'" />',wppaHasAudio&&(l+='<audio id="wppa-overlay-audio" class="wppa-overlay-audio" data-from="wppa" preload="metadata" onpause="wppaOvlAudioPlaying = false;" onplay="wppaOvlAudioPlaying = true;" style="width:100%;position:absolute;box-shadow:none;left:0;bottom:0;padding:0 '+wppaOvlBorderWidth+'px;margin:0;background-color:transparent;box-sizing:border-box;" controls >'+wppaOvlAudioHtmls[p]+"</audio>"),wppaOvlIsVideo=!1),!wppaOvlShowStartStop||wppaOvlIsSingle||wppaIsVideo||(l+='<div id="wppa-ovl-start-stop-btn" class="wppa-ovl-nav-btn" style="z-index:100101;position:absolute;top:50%;margin-top:-24px;left:50%;margin-left:-24px;'+(-1==wppaOvlIdx?"visibility:hidden;":"")+"box-shadow:none;"+(wppaOvlFirst?"opacity:1;":"opacity:0;")+'" onclick="wppaOvlStartStop()" onmouseover="jQuery(this).stop().fadeTo(200,1);" onmouseout="jQuery(this).stop().fadeTo(200,0);" ontouchstart="jQuery(this).stop().fadeTo(200,1);" onload="jQuery(this).stop().fadeTo(5000,0);" >'+wppaSvgHtml(wppaOvlRunning?"Pause-Button":"Play-Button","48px",!0,!0,"0","20","50","50")+"</div>"),wppaOvlIsSingle||(l+='<div id="wppa-ovl-prev-btn" class="wppa-ovl-nav-btn" style="position:absolute;z-index:100101;width:48px;top:50%;margin-top:-24px;left:1px;box-shadow:none;'+(wppaOvlFirst?"opacity:1;":"opacity:0;")+'" onclick="wppaOvlShowPrev()" onmouseover="jQuery(this).stop().fadeTo(200,1);" onmouseout="jQuery(this).stop().fadeTo(200,0);" ontouchstart="jQuery(this).stop().fadeTo(200,1);" onload="jQuery(this).stop().fadeTo(5000,0);" >'+wppaSvgHtml("Prev-Button","48px",!0,!0)+"</div>",l+='<div id="wppa-ovl-next-btn" class="wppa-ovl-nav-btn" style="position:absolute;z-index:100101;width:48px;top:50%;margin-top:-24px;right:1px;box-shadow:none;'+(wppaOvlFirst?"opacity:1;":"opacity:0;")+'" onclick="wppaOvlShowNext()" onmouseover="jQuery(this).stop().fadeTo(200,1);" onmouseout="jQuery(this).stop().fadeTo(200,0);" ontouchstart="jQuery(this).stop().fadeTo(200,1);" onload="jQuery(this).stop().fadeTo(5000,0);" >'+wppaSvgHtml("Next-Button","48px",!0,!0)+"</div>"),l+="</div>";var i=!wppaOvlIsSingle&&wppaOvlShowCounter;return l+='<div id="wppa-overlay-txt-container" style="position:relative;padding:10px;background-color:'+wppaOvlTheme+";color:"+o+";text-align:center;font-family:"+wppaOvlFontFamily+";font-size:"+wppaOvlFontSize+"px;font-weight:"+wppaOvlFontWeight+";line-height:"+wppaOvlLineHeight+"px;box-shadow:none;border-bottom-left-radius:"+wppaOvlRadius+"px;border-bottom-right-radius:"+wppaOvlRadius+'px;" ><div id="wppa-overlay-txt" style="text-align:center;min-height:36px;width:100%;'+("auto"==wppaOvlTxtHeight?"max-height:200px;":"max-height:"+wppaOvlTxtHeight+"px;")+'overflow:auto;box-shadow:none;" >'+(i?wppaOvlIdx+1+"/"+wppaOvlUrls.length+"<br />":"")+wppaOvlTitles[p]+"</div>",jQuery("#wppa-overlay-ic").html(l),wppaShowFsButtons(),jQuery("#wppa-overlay-img").bind("contextmenu",function(p){return!1}),0==wppaOvlPanoramaIds[p]&&wppaOvlResize(),wppaOvlFirst&&wppaShowFsButtons(),!1}function wppaOvlSize(p){if(wppaConsoleLog("wppaOvlSize"),!wppaOvlActivePanorama){var a=document.getElementById("wppa-overlay-img"),e=document.getElementById("wppa-overlay-txt");if(a&&e&&"none"!=jQuery("#wppa-overlay-bg").css("display")){if("normal"==wppaOvlMode){var t,o,l,i,n,r,w,d=jQuery(window).width(),v=jQuery(window).height();wppaOvlIsVideo?(t=a.clientWidth,o=wppaOvlVideoNaturalWidths[wppaOvlCurIdx],l=wppaOvlVideoNaturalHeights[wppaOvlCurIdx]):(t=a.clientWidth,o=a.naturalWidth,l=a.naturalHeight),void 0===o&&(o=a.clientWidth,l=a.clientHeight),(r=(i=(d-3*wppaOvlBorderWidth)/o)<(n=v/l)?i:n)<1&&(o=parseInt(o*r),l=parseInt(l*r));var s=jQuery("#wppa-overlay-txt").height();"auto"==wppaOvlTxtHeight?(0==s&&(s=20+2*wppaOvlBorderWidth),w=v-s-20-2*wppaOvlBorderWidth):w=v-wppaOvlTxtHeight-20-2*wppaOvlBorderWidth;var u=parseInt(w*o/l),h=(wppaOvlPadTop,parseInt((d-u)/2),u);l<w&&(wppaOvlPadTop+(w-l)/2,parseInt((d-o)/2),h=o);var O=wppaSavedImageWidth-h<3&&h-wppaSavedImageWidth<3;return h<=10&&(l=180,O=!(o=h=240)),h=parseInt(h),wppaSavedImageWidth=parseInt(h),wppaSavedImageHeight=parseInt(h*l/o),wppaSavedMarginLeft=-parseInt(h/2+wppaOvlBorderWidth),wppaSavedContainerWidth=parseInt(h+2*wppaOvlBorderWidth),wppaSavedContainerHeight=parseInt(wppaSavedImageHeight+wppaOvlBorderWidth+jQuery("#wppa-overlay-txt-container").height()+20),wppaSavedMarginTop=-parseInt(wppaSavedContainerHeight/2),jQuery("#wppa-overlay-img").stop().animate({width:wppaSavedImageWidth,height:wppaSavedImageHeight},p),jQuery("#wppa-overlay-ic").stop().animate({width:wppaSavedContainerWidth,marginLeft:wppaSavedMarginLeft,marginTop:wppaSavedMarginTop},p),O?(jQuery("#wppa-ovl-spin").hide(),wppaConsoleLog("Done "+wppaOvlIdx),wppaOvlFirst=!1):(setTimeout(function(){wppaOvlSize(wppaOvlAnimSpeed)},p+10),wppaConsoleLog("Not done "+wppaOvlIdx+" saved="+wppaSavedImageWidth+", wid="+h+", cw="+t+", nw="+o+", img complete="+document.getElementById("wppa-overlay-img").complete)),!0}wppaOvlFormatFull()}else wppaConsoleLog("Lb quitted")}}function wppaOvlFormatFull(){if(wppaConsoleLog("wppaOvlFormatFull "+wppaOvlMode),wppaOvlOpen){if(!(0<wppaOvlActivePanorama)){var p,a,e;if(wppaOvlIsVideo)p=document.getElementById("wppa-overlay-img"),a=wppaOvlVideoNaturalWidths[wppaOvlIdx],e=wppaOvlVideoNaturalHeights[wppaOvlIdx];else{if(p=document.getElementById("wppa-overlay-img"),!(wppaIsIe||p&&p.complete))return void setTimeout("wppaOvlFormatFull()",10);a=p.naturalWidth,e=p.naturalHeight}var t=screen.width/screen.height,o=a/e,l=0,i=0,n=0,r=0,w=0,d=0,v="hidden";switch(wppaOvlMode){case"padded":o<t?(l=(screen.width-screen.height*o)/2,i=0,n=screen.height,r=screen.height*o):(l=0,i=(screen.height-screen.width/o)/2,n=screen.width/o,r=screen.width);break;case"stretched":i=l=0,n=screen.height,r=screen.width;break;case"clipped":o<t?(l=0,i=(screen.height-screen.width/o)/2,n=screen.width/o,r=screen.width):(l=(screen.width-screen.height*o)/2,i=0,n=screen.height,r=screen.height*o);break;case"realsize":(l=(screen.width-a)/2)<0&&(d=parseInt(-l),l=0),(i=(screen.height-e)/2)<0&&(w=parseInt(-i),i=0),n=e,r=a,v="auto"}return l=parseInt(l),i=parseInt(i),n=parseInt(n),r=parseInt(r),jQuery(p).css({height:n,width:r,marginLeft:l,marginTop:i,left:0,top:0,maxWidth:1e4}),jQuery(p).css({visibility:"visible"}),jQuery("#wppa-ovl-full-bg").css({overflow:v}),jQuery("#wppa-ovl-full-bg").scrollTop(w),jQuery("#wppa-ovl-full-bg").scrollLeft(d),jQuery("#wppa-ovl-spin").hide(),!0}setTimeout(function(){wppaConsoleLog("kicking panorama from wppaOvlFormatFull"),jQuery(window).trigger("kickpanorama")},125)}}function wppaOvlUpdateFsId(){wppaConsoleLog("wppaOvlUpdateFsId"),wppaOvlFsPhotoId=wppaPhotoId}function wppaOvlStartAudio(){wppaConsoleLog("wppaOvlStartAudio");var p=document.getElementById("wppa-overlay-audio");p&&"function"==typeof p.play&&(p.play(),wppaConsoleLog("Audio play wppa-overlay-audio"))}function wppaOvlStepMode(){wppaConsoleLog("wppaOvlStepMode from "+wppaOvlMode);for(var p=new Array("normal","padded","stretched","clipped","realsize","padded"),a=0;a<p.length;){if(wppaOvlMode==p[a])return wppaOvlMode=p[a+1],void wppaOvlShow(wppaOvlIdx);a++}}function wppaOvlStartStop(){wppaConsoleLog("wppaOvlStartStop called. Running="+wppaOvlRunning),wppaOvlRunning?(wppaOvlRunning=!1,jQuery("#wppa-ovl-start-stop-btn").html(wppaSvgHtml(wppaOvlRunning?"Pause-Button":"Play-Button","48px",!0,!0,"0","20","50","50")),-1!=wppaOvlIdx&&(0!=wppaOvlIdx&&jQuery("#wppa-ovl-prev-btn").css("visibility","visible"),wppaOvlIdx!=wppaOvlUrls.length-1&&jQuery("#wppa-ovl-next-btn").css("visibility","visible"))):(jQuery("#wppa-ovl-start-stop-btn").html(wppaSvgHtml((wppaOvlRunning,"Pause-Button"),"48px",!0,!0,"0","20","50","50")),wppaOvlRunning=!0,wppaOvlRun())}function wppaOvlRun(){if(wppaConsoleLog("wppaOvlRun, running="+wppaOvlRunning),wppaOvlRunning)if(wppaOvlVideoPlaying||wppaOvlAudioPlaying)setTimeout("wppaOvlRun()",50);else{if(!wppaIsVideo){var p=document.getElementById("wppa-overlay-img");if(p&&!wppaIsIe&&!p.complete)return wppaConsoleLog("Wait during run"),void setTimeout("wppaOvlRun()",50)}var a;a=wppaOvlIdx>=wppaOvlUrls.length-1?0:wppaOvlIdx+1,wppaOvlFsPhotoId=0,wppaPhotoId=0,wppaOvlShow(a),setTimeout("wppaOvlRun()",wppaOvlSlideSpeed)}}function wppaOvlShowPrev(){return wppaConsoleLog("wppaOvlShowPrev"),wppaOvlFsPhotoId=0,wppaPhotoId=0,wppaOvlIsSingle||(wppaOvlIdx<1&&(wppaOvlIdx=wppaOvlUrls.length),wppaOvlShow(wppaOvlIdx-1)),!1}function wppaOvlShowNext(){return wppaConsoleLog("wppaOvlShowNext"),jQuery("#wppa-ovl-spin").show(),wppaOvlFsPhotoId=0,wppaPhotoId=0,wppaOvlIsSingle||(wppaOvlIdx>=wppaOvlUrls.length-1&&(wppaOvlIdx=-1),wppaOvlShow(wppaOvlIdx+1)),!1}function wppaOvlHide(){wppaConsoleLog("wppaOvlHide"),wppaStopAudio(),"normal"!=wppaOvlMode&&wppaOvlNorm(!0),jQuery("#wppa-overlay-ic").html(""),jQuery("#wppa-overlay-bg").fadeOut(300),jQuery(document).off("keydown",wppaOvlKeyboardHandler),wppaKbHandlerInstalled=!1,wppaOvlFirst=!0,wppaOvlRunning=!1,wppaOvlMode=wppaOvlModeInitial,wppaNormsBtnOpac=.75,jQuery("#wppa-ovl-spin").hide(),jQuery("#wppa-fulls-btn").stop().fadeOut(300),jQuery("#wppa-exit-btn").stop().fadeOut(300),jQuery("#wppa-ovl-spin").hide(),wppaOvlActivePanorama=0,wppaOvlOpen=!1}function wppaOvlOnclick(p){switch(wppaConsoleLog("wppaOvlOnClick"),wppaOvlOnclickType){case"none":break;case"close":"normal"==wppaOvlMode&&wppaOvlHide();break;case"browse":var a=p.screenX-window.screenX;48<p.clientY&&(a<screen.width/2?wppaOvlShowPrev():wppaOvlShowNext());break;default:alert("Unimplemented action: "+wppaOvlOnclickType)}return!0}function wppaInitOverlay(){wppaConsoleLog("wppaInitOverlay"),jQuery(".wp-caption").each(function(){var p=jQuery(this),a=p.find("IMG[alt]").attr("alt")||"",e=p.find(".wp-caption-text").html()||"",t=p.find("a"),o=a+"<br>"+e;t.attr("data-lbtitle")||t.attr("data-lbtitle",o)}),""==wppaOvlMode&&(wppaOvlMode=wppaOvlModeInitial);var p,a,e=jQuery("a"),t=[];for(wppaOvlFsPhotoId=0,wppaPhotoId=0,(wppaOvlActivePanorama=wppaOvlCurIdx=0)==wppaSavedContainerWidth&&(wppaSavedContainerWidth=240+2*wppaOvlBorderWidth,wppaSavedContainerHeight=180+3*wppaOvlBorderWidth+20+("auto"==wppaOvlTxtHeight?50:wppaOvlTxtHeight),wppaSavedMarginLeft=-(120+wppaOvlBorderWidth),wppaSavedMarginTop=-(90+wppaOvlBorderWidth+10+("auto"==wppaOvlTxtHeight?25:wppaOvlTxtHeight/2)),wppaSavedImageWidth=240,wppaSavedImageHeight=180+wppaOvlBorderWidth),a=0;a<e.length;a++)p=e[a],jQuery(p).attr("data-rel")?t=jQuery(p).attr("data-rel").split("["):p.rel?t=p.rel.split("["):t[0]="","wppa"==t[0]&&(wppaWppaOverlayActivated=!0,jQuery(p).on("click",function(p){wppaOvlShow(this),p.preventDefault()}),jQuery(p).css("cursor","url( "+wppaImageDirectory+wppaMagnifierCursor+" ),auto"));wppaIsMobile&&window.addEventListener("orientationchange",wppaDoOnOrientationChange)}function wppaOvlResize(){wppaConsoleLog("wppaOvlResize"),0<wppaOvlActivePanorama?setTimeout(function(){wppaConsoleLog("kicking panorama from wppaOvlResize"),jQuery(window).trigger("kickpanorama")},125):(setTimeout("wppaOvlSize( "+wppaOvlAnimSpeed+" )",10),wppaOvlAudioStart&&!wppaOvlAudioPlaying&&setTimeout("wppaOvlStartAudio()",100))}function wppaShowFsButtons(p){void 0!==p&&(wppaNormsBtnOpac=p),jQuery("#wppa-exit-btn").stop().fadeTo(3,wppaNormsBtnOpac),"normal"==wppaOvlMode?jQuery("#wppa-fulls-btn").stop().fadeTo(3,wppaNormsBtnOpac):jQuery("#wppa-norms-btn").stop().fadeTo(3,wppaNormsBtnOpac)}jQuery(document).ready(function(p){wppaInitOverlay()}),jQuery(window).resize(function(){jQuery("#wppa-overlay-bg").css({height:window.innerHeight,width:window.innerWidth}),wppaOvlResize()}),wppaConsoleLog("wppa-lightbox.js version "+wppaLightboxVersion+" loaded.","force");
1
+ var wppaSavedContainerHeight,wppaSavedMarginLeft,wppaSavedMarginTop,wppaSavedImageWidth,wppaSavedImageHeight,wppaRenderer,wppaScene,wppaCamera,wppaSphere,wppaSphereMaterial,wppaSphereMesh,wppaLightboxVersion="6.9.12",wppaNormsBtnOpac=.75,wppaIsVideo=!1,wppaHasAudio=!1,wppaOvlImgs=[],wppaKbHandlerInstalled=!1,wppaOvlMode="",wppaOvlCurIdx=0,wppaOvlSvgInverse=!1,wppaOvlFsExitBtnSize="48",wppaOvlActivePanorama=0,wppaOvlHasPanoramas=!1,wppaGlobalOvlPanoramaId=0,wppaSavedContainerWidth=0;function wppaDoOnOrientationChange(p){"normal"!=wppaOvlMode&&document.getElementById("wppa-overlay-img")&&setTimeout("wppaOvlShow( "+wppaOvlIdx+" )",10)}function wppaOvlKeyboardHandler(p){var a,e;a=null==p?event.keyCode:p.keyCode,e=27;var t=String.fromCharCode(a).toLowerCase();switch(a){case e:wppaStopVideo(mocc),"normal"!=wppaOvlMode&&wppaOvlNorm(!0),wppaOvlHide();break;case 37:wppaOvlShowPrev();break;case 39:wppaOvlShowNext()}switch(t){case"p":wppaOvlShowPrev();break;case"n":wppaOvlShowNext();break;case"s":wppaOvlStartStop();break;case"d":jQuery("#wppa-ovl-legenda-1").css("visibility","hidden"),jQuery("#wppa-ovl-legenda-2").css("visibility","hidden"),wppaShowLegenda="hidden";break;case"f":wppaOvlFull();break;case"l":wppaOvlNorm();break;case"q":case"x":wppaStopVideo(mocc),"normal"!=wppaOvlMode&&wppaOvlNorm(!0),wppaOvlHide()}return!1}function wppaOvlFull(p){wppaConsoleLog("wppaOvlFull"),wppaNormsBtnOpac=.75;var a=wppaOvlMode;p||wppaOvlStepMode();var e=document.getElementById("wppa-overlay-ic");e&&((p||"normal"==a)&&(e.requestFullscreen?e.requestFullscreen():e.mozRequestFullScreen?e.mozRequestFullScreen():e.webkitRequestFullscreen&&e.webkitRequestFullscreen()),"normal"==wppaOvlMode&&(document.cancelFullScreen?document.cancelFullScreen():document.mozCancelFullScreen?document.mozCancelFullScreen():document.webkitCancelFullScreen&&document.webkitCancelFullScreen()),setTimeout(function(){wppaShowFsButtons(.75)},30),jQuery("#wppa-ovl-legenda-1").html(""))}function wppaOvlNorm(p){wppaConsoleLog("wppaOvlNorm"),wppaOvlMode="normal",wppaNormsBtnOpac=.75,document.cancelFullScreen?document.cancelFullScreen():document.mozCancelFullScreen?document.mozCancelFullScreen():document.webkitCancelFullScreen&&document.webkitCancelFullScreen(),p?wppaOvlMode=wppaOvlModeInitial:(setTimeout(function(){wppaShowFsButtons(.75)},30),setTimeout(function(){wppaOvlShow(wppaOvlIdx)},50))}function wppaOvlShow(p){var a,e;if(wppaConsoleLog("wppaOvlShow arg="+p),0<wppaOvlActivePanorama?jQuery("#wppa-overlay-ic").css({top:0,left:0}):jQuery("#wppa-overlay-ic").css({top:"50%",left:"50%"}),wppaOvlFirst&&(jQuery("#weaver-final").removeClass("wvr-hide-bang"),jQuery("#wppa-overlay-bg").stop().fadeTo(3,wppaOvlOpacity),wppaKbHandlerInstalled||(jQuery(document).on("keydown",wppaOvlKeyboardHandler),wppaKbHandlerInstalled=!0),jQuery("#wppa-overlay-bg").css({width:window.innerWidth,height:window.innerHeight}),"normal"!=wppaOvlModeInitial&&wppaOvlFull(!0)),"object"==typeof p){wppaOvlUrls=[],wppaOvlTitles=[],wppaOvlAlts=[],wppaOvlVideoHtmls=[],wppaOvlAudioHtmls=[],wppaOvlVideoNaturalWidths=[],wppaOvlVideoNaturalHeights=[],wppaOvlImgs=[],wppaOvlIdx=0,wppaOvlPanoramaHtml=[],wppaOvlPanoramaIds=[],wppaOvlHasPanoramas=!1;var t=(p.rel?p.rel:!!jQuery(p).attr("data-rel")&&jQuery(p).attr("data-rel")).split("[");if(t[1]){var o,l,i=t[1],n=jQuery("a"),r=0;for(l=0;l<n.length;l++)o=n[l],1<(t=!!jQuery(o).attr("data-rel")&&jQuery(o).attr("data-rel").split("[")).length&&"wppa"==t[0]&&t[1]==i&&(wppaOvlUrls[r]=o.href,jQuery(o).attr("data-lbtitle")?wppaOvlTitles[r]=wppaRepairScriptTags(jQuery(o).attr("data-lbtitle")):wppaOvlTitles[r]=wppaRepairScriptTags(o.title),wppaOvlAlts[r]=jQuery(o).attr("data-alt")?jQuery(o).attr("data-alt"):"",wppaOvlVideoHtmls[r]=jQuery(o).attr("data-videohtml")?decodeURI(jQuery(o).attr("data-videohtml")):"",wppaOvlAudioHtmls[r]=jQuery(o).attr("data-audiohtml")?decodeURI(jQuery(o).attr("data-audiohtml")):"",wppaOvlVideoNaturalWidths[r]=jQuery(o).attr("data-videonatwidth")?jQuery(o).attr("data-videonatwidth"):"",wppaOvlVideoNaturalHeights[r]=jQuery(o).attr("data-videonatheight")?jQuery(o).attr("data-videonatheight"):"",0<(a=jQuery(o).attr("data-panorama")?jQuery(o).attr("data-panorama"):"").length?(wppaOvlHasPanoramas=!0,e=a.indexOf("."),wppaOvlPanoramaHtml[r]=a.substr(e+1),wppaOvlPanoramaIds[r]=a.substr(0,e)):(wppaOvlPanoramaHtml[r]="",wppaOvlPanoramaIds[r]=0),o.href==p.href&&(wppaOvlIdx=r),r++)}else wppaOvlUrls[0]=p.href,jQuery(p).attr("data-lbtitle")?wppaOvlTitles[0]=wppaRepairScriptTags(jQuery(p).attr("data-lbtitle")):wppaOvlTitles[0]=wppaRepairScriptTags(p.title),wppaOvlAlts[0]=jQuery(p).attr("data-alt")?jQuery(p).attr("data-alt"):"",wppaOvlVideoHtmls[0]=jQuery(p).attr("data-videohtml")?decodeURI(jQuery(p).attr("data-videohtml")):"",wppaOvlAudioHtmls[0]=jQuery(p).attr("data-audiohtml")?decodeURI(jQuery(p).attr("data-audiohtml")):"",wppaOvlVideoNaturalWidths[0]=jQuery(p).attr("data-videonatwidth")?jQuery(p).attr("data-videonatwidth"):"",wppaOvlVideoNaturalHeights[0]=jQuery(p).attr("data-videonatheight")?jQuery(p).attr("data-videonatheight"):"",0<(a=jQuery(p).attr("data-panorama")?jQuery(p).attr("data-panorama"):"").length?(wppaOvlHasPanoramas=!0,e=a.indexOf("."),wppaOvlPanoramaHtml[0]=a.substr(e+1),wppaOvlPanoramaIds[0]=a.substr(0,e)):(wppaOvlPanoramaHtml[0]="",wppaOvlPanoramaIds[0]=0),wppaOvlIdx=0}else wppaOvlIdx=p;wppaOvlOpen=!0,setTimeout(function(){_wppaOvlShow(wppaOvlIdx)},1)}function _wppaOvlShow(p){if(wppaConsoleLog("_wppaOvlShow, idx="+p),wppaOvlCurIdx=p,wppaOvlFirst&&jQuery("#wppa-ovl-spin").show(),wppaIsVideo=""!=wppaOvlVideoHtmls[p],wppaHasAudio=""!=wppaOvlAudioHtmls[p],0<wppaOvlUrls[p].length&&!wppaIsVideo&&(wppaOvlImgs[p]=new Image,wppaOvlImgs[p].src=wppaOvlUrls[p],wppaConsoleLog("Preloading "+(p+1)+"/"+wppaOvlUrls.length+" (current)"),!wppaIsIe&&!wppaOvlImgs[p].complete&&wppaOvlOpen))return wppaConsoleLog("Retrying preload current image"),void setTimeout("_wppaOvlShow("+p+")",500);var a,e;if(a=wppaOvlIdx==wppaOvlUrls.length-1?0:wppaOvlIdx+1,""==wppaOvlVideoHtmls[a]&&wppaOvlOpen&&(wppaOvlImgs[a]=new Image,wppaOvlImgs[a].src=wppaOvlUrls[a],wppaConsoleLog("Preloading > "+(a+1))),!wppaOvlRunning&&wppaOvlOpen&&(e=0==wppaOvlIdx?wppaOvlUrls.length-1:wppaOvlIdx-1,""==wppaOvlVideoHtmls[e]&&(wppaOvlImgs[e]=new Image,wppaOvlImgs[e].src=wppaOvlUrls[e],wppaConsoleLog("Preloading < "+(e+1)))),wppaPhotoId=wppaUrlToId(wppaOvlUrls[p]),_bumpViewCount(wppaPhotoId),wppaOvlIsSingle=1==wppaOvlUrls.length,0<wppaOvlPanoramaIds[p]?(wppaOvlActivePanorama=wppaOvlPanoramaIds[p],jQuery("#wppa-overlay-ic").css({top:0,left:0})):(wppaOvlActivePanorama=0,jQuery("#wppa-overlay-ic").css({top:"50%",left:"50%",display:"block"})),"normal"!=wppaOvlMode||wppaOvlActivePanorama){wppaOvlActivePanorama?(l=wppaOvlPanoramaHtml[p]+"<div style=\"height: 20px; width: 100%; position:absolute; top:0; left:0;\" onmouseover=\"jQuery('#wppa-ovl-legenda-2').css('visibility','visible');\" onmouseout=\"jQuery('#wppa-ovl-legenda-2').css('visibility','hidden');wppaShowLegenda='hidden';\" >",wppaOvlShowLegenda&&"normal"!=wppaOvlMode&&(l+='<div id="wppa-ovl-legenda-2" style="position:fixed; left:0; top:0; background-color:'+("black"==wppaOvlTheme?"#272727":"#a7a7a7")+"; color:"+("black"==wppaOvlTheme?"#a7a7a7":"#272727")+"; visibility:"+wppaShowLegenda+';" >Mode=fullscreen. '+(wppaOvlIsSingle?wppaOvlFullLegendaSinglePanorama:wppaOvlFullLegendaPanorama)+"</div>")):(wppaIsVideo?l='<div id="wppa-ovl-full-bg" style="position:fixed; width:'+screen.width+"px; height:"+screen.height+'px; left:0px; top:0px; text-align:center;" ><video id="wppa-overlay-img" controls preload="metadata"'+(wppaOvlVideoStart?" autoplay":"")+' ontouchstart="wppaTouchStart( event, \'wppa-overlay-img\', -1 );" ontouchend="wppaTouchEnd( event );" ontouchmove="wppaTouchMove( event );" ontouchcancel="wppaTouchCancel( event );" onpause="wppaOvlVideoPlaying = false;" onplay="wppaOvlVideoPlaying = true;" style="border:none; width:'+screen.width+'px; box-shadow:none; position:absolute;" alt="'+wppaOvlAlts[p]+'" >'+wppaOvlVideoHtmls[p]+"</video><div style=\"height: 20px; width: 100%; position:absolute; top:0; left:0;\" onmouseover=\"jQuery('#wppa-ovl-legenda-2').css('visibility','visible');\" onmouseout=\"jQuery('#wppa-ovl-legenda-2').css('visibility','hidden');wppaShowLegenda='hidden';\" >":(l='<div id="wppa-ovl-full-bg" style="position:fixed; width:'+screen.width+"px; height:"+screen.height+'px; left:0px; top:0px; text-align:center;" ><img id="wppa-overlay-img" ontouchstart="wppaTouchStart( event, \'wppa-overlay-img\', -1 );" ontouchend="wppaTouchEnd( event );" ontouchmove="wppaTouchMove( event );" ontouchcancel="wppaTouchCancel( event );" src="'+wppaOvlUrls[p]+'" style="border:none; width:'+screen.width+'px; visibility:hidden; box-shadow:none; position:absolute;" alt="'+wppaOvlAlts[p]+'" />',wppaHasAudio&&(l+='<audio id="wppa-overlay-audio" class="wppa-overlay-audio" data-from="wppa" preload="metadata"'+(wppaOvlAudioStart?" autoplay":"")+' onpause="wppaOvlAudioPlaying = false;" onplay="wppaOvlAudioPlaying = true;" style="width:100%;position:absolute;left:0px;bottom:0px;padding:0;" controls >'+wppaOvlAudioHtmls[p]+"</audio>"),l+="<div style=\"height: 20px; width: 100%; position:absolute; top:0; left:0;\" onmouseover=\"jQuery('#wppa-ovl-legenda-2').css('visibility','visible');\" onmouseout=\"jQuery('#wppa-ovl-legenda-2').css('visibility','hidden');wppaShowLegenda='hidden';\" >"),wppaOvlShowLegenda&&(l+='<div id="wppa-ovl-legenda-2" style="position:fixed; left:0; top:0; background-color:'+("black"==wppaOvlTheme?"#272727":"#a7a7a7")+"; color:"+("black"==wppaOvlTheme?"#a7a7a7":"#272727")+"; visibility:"+wppaShowLegenda+';" >Mode='+wppaOvlMode+". "+(wppaOvlIsSingle?wppaOvlFullLegendaSingle:wppaOvlFullLegenda)+"</div>")),l+="</div>";var t=(wppaIsMobile,"0.1");return l+='<div id="wppa-exit-btn" style="height:'+wppaOvlFsExitBtnSize+"px;z-index:100098;position:fixed;top:0;right:0;opacity:"+wppaNormsBtnOpac+';" onclick="wppaOvlHide()" onmouseover="jQuery(this).stop().fadeTo(300,1);" ontouchstart="jQuery(this).stop().fadeTo(300,1);" onmouseout="jQuery(this).stop().fadeTo(300,'+t+");wppaNormsBtnOpac="+t+';" ontouchend="jQuery(this).stop().fadeTo(300,'+t+");wppaNormsBtnOpac="+t+';" >'+wppaSvgHtml("Exit",wppaOvlFsExitBtnSize+"px",!0,!0,"0","0","0","0")+"</div>","normal"!=wppaOvlMode&&(l+='<div id="wppa-norms-btn" style="height:48px;z-index:100098;position:fixed;top:0;right:'+wppaOvlFsExitBtnSize+"px;opacity:"+wppaNormsBtnOpac+';" onclick="wppaOvlNorm()" onmouseover="jQuery(this).stop().fadeTo(300,1);" ontouchstart="jQuery(this).stop().fadeTo(300,1);" onmouseout="jQuery(this).stop().fadeTo(300,'+t+");wppaNormsBtnOpac="+t+';" ontouchend="jQuery(this).stop().fadeTo(300,'+t+");wppaNormsBtnOpac="+t+';" >'+wppaSvgHtml("Exit-Full-Screen",wppaOvlFsExitBtnSize+"px",!0,!0,"0","0","0","0")+"</div>"),(wppaIsVideo||wppaHasAudio)&&wppaOvlFsPhotoId==wppaPhotoId&&0!=wppaPhotoId||(wppaStopVideo(0),wppaStopAudio(),jQuery("#wppa-overlay-ic").html(l)),0<wppaOvlPanoramaIds[p]&&wppaOvlIsSingle&&jQuery(".wppa-pan-prevnext").hide(),wppaProtect(),wppaOvlIsVideo=wppaIsVideo,setTimeout("wppaOvlFormatFull()",10),wppaIsVideo||wppaHasAudio?setTimeout("wppaOvlUpdateFsId()",20):wppaOvlFsPhotoId=0,wppaOvlFirst=!1,wppaShowFsButtons(),!1}wppaOvlFsPhotoId=0,wppaPhotoId=0,wppaStopVideo(0);var o="black"==wppaOvlTheme?"#a7a7a7":"#272727";wppaOvlFontColor&&(o=wppaOvlFontColor);wppaOvlUrls.length;jQuery("#wppa-overlay-ic").css({width:wppaSavedContainerWidth,marginLeft:wppaSavedMarginLeft,marginTop:wppaSavedMarginTop});var l="";l+='<div id="img-sb-img-cont" style="position:relative;line-height:0;" >',wppaIsVideo?(l+='<video id="wppa-overlay-img" onmouseover="jQuery(\'.wppa-ovl-nav-btn\').stop().fadeTo(200,0.8);" onmouseout="jQuery(\'.wppa-ovl-nav-btn\').stop().fadeTo(200,0);" preload="metadata"'+(wppaOvlVideoStart?" autoplay":"")+' onpause="wppaOvlVideoPlaying = false;" onplay="wppaOvlVideoPlaying = true;" ontouchstart="wppaTouchStart( event, \'wppa-overlay-img\', -1 );" ontouchend="wppaTouchEnd( event );" ontouchmove="wppaTouchMove( event );" ontouchcancel="wppaTouchCancel( event );" controls style="border-width:'+wppaOvlBorderWidth+"px "+wppaOvlBorderWidth+"px 0;border-style:solid;border-color:"+wppaOvlTheme+";width:"+wppaSavedImageWidth+"px;height:"+wppaSavedImageHeight+"px;box-shadow:none;box-sizing:content-box;position:relative;border-top-left-radius:"+wppaOvlRadius+"px;border-top-right-radius:"+wppaOvlRadius+'px;margin:0;padding:0;" alt="'+wppaOvlAlts[p]+'" >'+wppaOvlVideoHtmls[p]+"</video>",wppaOvlIsVideo=!0):(l+='<img id="wppa-overlay-img" onmouseover="jQuery(\'.wppa-ovl-nav-btn\').stop().fadeTo(200,0.8);" onmouseout="jQuery(\'.wppa-ovl-nav-btn\').stop().fadeTo(200,0);" ontouchstart="wppaTouchStart( event, \'wppa-overlay-img\', -1 );" ontouchend="wppaTouchEnd( event );" ontouchmove="wppaTouchMove( event );" ontouchcancel="wppaTouchCancel( event );" src="'+wppaOvlUrls[p]+'" style="border-width:'+wppaOvlBorderWidth+"px "+wppaOvlBorderWidth+"px 0;border-style:solid;border-color:"+wppaOvlTheme+";width:"+wppaSavedImageWidth+"px;height:"+wppaSavedImageHeight+"px;box-shadow:none;box-sizing:content-box;position:relative;border-top-left-radius:"+wppaOvlRadius+"px;border-top-right-radius:"+wppaOvlRadius+'px;margin:0;padding:0;" alt="'+wppaOvlAlts[p]+'" />',wppaHasAudio&&(l+='<audio id="wppa-overlay-audio" class="wppa-overlay-audio" data-from="wppa" preload="metadata" onpause="wppaOvlAudioPlaying = false;" onplay="wppaOvlAudioPlaying = true;" style="width:100%;position:absolute;box-shadow:none;left:0;bottom:0;padding:0 '+wppaOvlBorderWidth+'px;margin:0;background-color:transparent;box-sizing:border-box;" controls >'+wppaOvlAudioHtmls[p]+"</audio>"),wppaOvlIsVideo=!1),!wppaOvlShowStartStop||wppaOvlIsSingle||wppaIsVideo||(l+='<div id="wppa-ovl-start-stop-btn" class="wppa-ovl-nav-btn" style="z-index:100101;position:absolute;top:50%;margin-top:-24px;left:50%;margin-left:-24px;'+(-1==wppaOvlIdx?"visibility:hidden;":"")+"box-shadow:none;"+(wppaOvlFirst?"opacity:1;":"opacity:0;")+'" onclick="wppaOvlStartStop()" onmouseover="jQuery(this).stop().fadeTo(200,1);" onmouseout="jQuery(this).stop().fadeTo(200,0);" ontouchstart="jQuery(this).stop().fadeTo(200,1);" onload="jQuery(this).stop().fadeTo(5000,0);" >'+wppaSvgHtml(wppaOvlRunning?"Pause-Button":"Play-Button","48px",!0,!0,"0","20","50","50")+"</div>"),wppaOvlIsSingle||(l+='<div id="wppa-ovl-prev-btn" class="wppa-ovl-nav-btn" style="position:absolute;z-index:100101;width:48px;top:50%;margin-top:-24px;left:1px;box-shadow:none;'+(wppaOvlFirst?"opacity:1;":"opacity:0;")+'" onclick="wppaOvlShowPrev()" onmouseover="jQuery(this).stop().fadeTo(200,1);" onmouseout="jQuery(this).stop().fadeTo(200,0);" ontouchstart="jQuery(this).stop().fadeTo(200,1);" onload="jQuery(this).stop().fadeTo(5000,0);" >'+wppaSvgHtml("Prev-Button","48px",!0,!0)+"</div>",l+='<div id="wppa-ovl-next-btn" class="wppa-ovl-nav-btn" style="position:absolute;z-index:100101;width:48px;top:50%;margin-top:-24px;right:1px;box-shadow:none;'+(wppaOvlFirst?"opacity:1;":"opacity:0;")+'" onclick="wppaOvlShowNext()" onmouseover="jQuery(this).stop().fadeTo(200,1);" onmouseout="jQuery(this).stop().fadeTo(200,0);" ontouchstart="jQuery(this).stop().fadeTo(200,1);" onload="jQuery(this).stop().fadeTo(5000,0);" >'+wppaSvgHtml("Next-Button","48px",!0,!0)+"</div>"),l+="</div>";var i=!wppaOvlIsSingle&&wppaOvlShowCounter;return l+='<div id="wppa-overlay-txt-container" style="position:relative;padding:10px;background-color:'+wppaOvlTheme+";color:"+o+";text-align:center;font-family:"+wppaOvlFontFamily+";font-size:"+wppaOvlFontSize+"px;font-weight:"+wppaOvlFontWeight+";line-height:"+wppaOvlLineHeight+"px;box-shadow:none;border-bottom-left-radius:"+wppaOvlRadius+"px;border-bottom-right-radius:"+wppaOvlRadius+'px;" ><div id="wppa-overlay-txt" style="text-align:center;min-height:36px;width:100%;'+("auto"==wppaOvlTxtHeight?"max-height:200px;":"max-height:"+wppaOvlTxtHeight+"px;")+'overflow:auto;box-shadow:none;" >'+(i?wppaOvlIdx+1+"/"+wppaOvlUrls.length+"<br />":"")+wppaOvlTitles[p]+"</div>",jQuery("#wppa-overlay-ic").html(l),wppaShowFsButtons(),jQuery("#wppa-overlay-img").bind("contextmenu",function(p){return!1}),0==wppaOvlPanoramaIds[p]&&wppaOvlResize(),wppaOvlFirst&&wppaShowFsButtons(),!1}function wppaOvlSize(p){if(wppaConsoleLog("wppaOvlSize"),!wppaOvlActivePanorama){var a=document.getElementById("wppa-overlay-img"),e=document.getElementById("wppa-overlay-txt");if(a&&e&&"none"!=jQuery("#wppa-overlay-bg").css("display")){if("normal"==wppaOvlMode){var t,o,l,i,n,r,w,d=jQuery(window).width(),v=jQuery(window).height();wppaOvlIsVideo?(t=a.clientWidth,o=wppaOvlVideoNaturalWidths[wppaOvlCurIdx],l=wppaOvlVideoNaturalHeights[wppaOvlCurIdx]):(t=a.clientWidth,o=a.naturalWidth,l=a.naturalHeight),void 0===o&&(o=a.clientWidth,l=a.clientHeight),(r=(i=(d-3*wppaOvlBorderWidth)/o)<(n=v/l)?i:n)<1&&(o=parseInt(o*r),l=parseInt(l*r));var s=jQuery("#wppa-overlay-txt").height();"auto"==wppaOvlTxtHeight?(0==s&&(s=20+2*wppaOvlBorderWidth),w=v-s-20-2*wppaOvlBorderWidth):w=v-wppaOvlTxtHeight-20-2*wppaOvlBorderWidth;var u=parseInt(w*o/l),h=(wppaOvlPadTop,parseInt((d-u)/2),u);l<w&&(wppaOvlPadTop+(w-l)/2,parseInt((d-o)/2),h=o);var O=wppaSavedImageWidth-h<3&&h-wppaSavedImageWidth<3;return h<=10&&(l=180,O=!(o=h=240)),h=parseInt(h),wppaSavedImageWidth=parseInt(h),wppaSavedImageHeight=parseInt(h*l/o),wppaSavedMarginLeft=-parseInt(h/2+wppaOvlBorderWidth),wppaSavedContainerWidth=parseInt(h+2*wppaOvlBorderWidth),wppaSavedContainerHeight=parseInt(wppaSavedImageHeight+wppaOvlBorderWidth+jQuery("#wppa-overlay-txt-container").height()+20),wppaSavedMarginTop=-parseInt(wppaSavedContainerHeight/2),jQuery("#wppa-overlay-img").stop().animate({width:wppaSavedImageWidth,height:wppaSavedImageHeight},p),jQuery("#wppa-overlay-ic").stop().animate({width:wppaSavedContainerWidth,marginLeft:wppaSavedMarginLeft,marginTop:wppaSavedMarginTop},p),O?(jQuery("#wppa-ovl-spin").hide(),wppaConsoleLog("Done "+wppaOvlIdx),wppaOvlFirst=!1):(setTimeout(function(){wppaOvlSize(wppaOvlAnimSpeed)},p+10),wppaConsoleLog("Not done "+wppaOvlIdx+" saved="+wppaSavedImageWidth+", wid="+h+", cw="+t+", nw="+o+", img complete="+document.getElementById("wppa-overlay-img").complete)),!0}wppaOvlFormatFull()}else wppaConsoleLog("Lb quitted")}}function wppaOvlFormatFull(){if(wppaConsoleLog("wppaOvlFormatFull "+wppaOvlMode),wppaOvlOpen&&!(0<wppaOvlActivePanorama)){var p,a,e;if(wppaOvlIsVideo)p=document.getElementById("wppa-overlay-img"),a=wppaOvlVideoNaturalWidths[wppaOvlIdx],e=wppaOvlVideoNaturalHeights[wppaOvlIdx];else{if(p=document.getElementById("wppa-overlay-img"),!(wppaIsIe||p&&p.complete))return void setTimeout("wppaOvlFormatFull()",10);a=p.naturalWidth,e=p.naturalHeight}var t=screen.width/screen.height,o=a/e,l=0,i=0,n=0,r=0,w=0,d=0,v="hidden";switch(wppaOvlMode){case"padded":o<t?(l=(screen.width-screen.height*o)/2,i=0,n=screen.height,r=screen.height*o):(l=0,i=(screen.height-screen.width/o)/2,n=screen.width/o,r=screen.width);break;case"stretched":i=l=0,n=screen.height,r=screen.width;break;case"clipped":o<t?(l=0,i=(screen.height-screen.width/o)/2,n=screen.width/o,r=screen.width):(l=(screen.width-screen.height*o)/2,i=0,n=screen.height,r=screen.height*o);break;case"realsize":(l=(screen.width-a)/2)<0&&(d=parseInt(-l),l=0),(i=(screen.height-e)/2)<0&&(w=parseInt(-i),i=0),n=e,r=a,v="auto"}return l=parseInt(l),i=parseInt(i),n=parseInt(n),r=parseInt(r),jQuery(p).css({height:n,width:r,marginLeft:l,marginTop:i,left:0,top:0,maxWidth:1e4}),jQuery(p).css({visibility:"visible"}),jQuery("#wppa-ovl-full-bg").css({overflow:v}),jQuery("#wppa-ovl-full-bg").scrollTop(w),jQuery("#wppa-ovl-full-bg").scrollLeft(d),jQuery("#wppa-ovl-spin").hide(),!0}}function wppaOvlUpdateFsId(){wppaConsoleLog("wppaOvlUpdateFsId"),wppaOvlFsPhotoId=wppaPhotoId}function wppaOvlStartAudio(){wppaConsoleLog("wppaOvlStartAudio");var p=document.getElementById("wppa-overlay-audio");p&&"function"==typeof p.play&&(p.play(),wppaConsoleLog("Audio play wppa-overlay-audio"))}function wppaOvlStepMode(){wppaConsoleLog("wppaOvlStepMode from "+wppaOvlMode);for(var p=new Array("normal","padded","stretched","clipped","realsize","padded"),a=0;a<p.length;){if(wppaOvlMode==p[a])return wppaOvlMode=p[a+1],void wppaOvlShow(wppaOvlIdx);a++}}function wppaOvlStartStop(){wppaConsoleLog("wppaOvlStartStop called. Running="+wppaOvlRunning),wppaOvlRunning?(wppaOvlRunning=!1,jQuery("#wppa-ovl-start-stop-btn").html(wppaSvgHtml(wppaOvlRunning?"Pause-Button":"Play-Button","48px",!0,!0,"0","20","50","50")),-1!=wppaOvlIdx&&(0!=wppaOvlIdx&&jQuery("#wppa-ovl-prev-btn").css("visibility","visible"),wppaOvlIdx!=wppaOvlUrls.length-1&&jQuery("#wppa-ovl-next-btn").css("visibility","visible"))):(jQuery("#wppa-ovl-start-stop-btn").html(wppaSvgHtml((wppaOvlRunning,"Pause-Button"),"48px",!0,!0,"0","20","50","50")),wppaOvlRunning=!0,wppaOvlRun())}function wppaOvlRun(){if(wppaConsoleLog("wppaOvlRun, running="+wppaOvlRunning),wppaOvlRunning)if(wppaOvlVideoPlaying||wppaOvlAudioPlaying)setTimeout("wppaOvlRun()",50);else{if(!wppaIsVideo){var p=document.getElementById("wppa-overlay-img");if(p&&!wppaIsIe&&!p.complete)return wppaConsoleLog("Wait during run"),void setTimeout("wppaOvlRun()",50)}var a;a=wppaOvlIdx>=wppaOvlUrls.length-1?0:wppaOvlIdx+1,wppaOvlFsPhotoId=0,wppaPhotoId=0,wppaOvlShow(a),setTimeout("wppaOvlRun()",wppaOvlSlideSpeed)}}function wppaOvlShowPrev(){return wppaConsoleLog("wppaOvlShowPrev"),wppaOvlFsPhotoId=0,wppaPhotoId=0,wppaOvlIsSingle||(wppaOvlIdx<1&&(wppaOvlIdx=wppaOvlUrls.length),wppaOvlShow(wppaOvlIdx-1)),!1}function wppaOvlShowNext(){return wppaConsoleLog("wppaOvlShowNext"),jQuery("#wppa-ovl-spin").show(),wppaOvlFsPhotoId=0,wppaPhotoId=0,wppaOvlIsSingle||(wppaOvlIdx>=wppaOvlUrls.length-1&&(wppaOvlIdx=-1),wppaOvlShow(wppaOvlIdx+1)),!1}function wppaOvlHide(){wppaConsoleLog("wppaOvlHide"),wppaStopAudio(),"normal"!=wppaOvlMode&&wppaOvlNorm(!0),jQuery("#wppa-overlay-ic").html(""),jQuery("#wppa-overlay-bg").fadeOut(300),jQuery(document).off("keydown",wppaOvlKeyboardHandler),wppaKbHandlerInstalled=!1,wppaOvlFirst=!0,wppaOvlRunning=!1,wppaOvlMode=wppaOvlModeInitial,wppaNormsBtnOpac=.75,jQuery("#wppa-ovl-spin").hide(),jQuery("#wppa-fulls-btn").stop().fadeOut(300),jQuery("#wppa-exit-btn").stop().fadeOut(300),jQuery("#wppa-ovl-spin").hide(),wppaOvlActivePanorama=0,wppaOvlOpen=!1}function wppaOvlOnclick(p){switch(wppaConsoleLog("wppaOvlOnClick"),wppaOvlOnclickType){case"none":break;case"close":"normal"==wppaOvlMode&&wppaOvlHide();break;case"browse":var a=p.screenX-window.screenX;48<p.clientY&&(a<screen.width/2?wppaOvlShowPrev():wppaOvlShowNext());break;default:alert("Unimplemented action: "+wppaOvlOnclickType)}return!0}function wppaInitOverlay(){wppaConsoleLog("wppaInitOverlay"),jQuery(".wp-caption").each(function(){var p=jQuery(this),a=p.find("IMG[alt]").attr("alt")||"",e=p.find(".wp-caption-text").html()||"",t=p.find("a"),o=a+"<br>"+e;t.attr("data-lbtitle")||t.attr("data-lbtitle",o)}),""==wppaOvlMode&&(wppaOvlMode=wppaOvlModeInitial);var p,a,e=jQuery("a"),t=[];for(wppaOvlFsPhotoId=0,wppaPhotoId=0,(wppaOvlActivePanorama=wppaOvlCurIdx=0)==wppaSavedContainerWidth&&(wppaSavedContainerWidth=240+2*wppaOvlBorderWidth,wppaSavedContainerHeight=180+3*wppaOvlBorderWidth+20+("auto"==wppaOvlTxtHeight?50:wppaOvlTxtHeight),wppaSavedMarginLeft=-(120+wppaOvlBorderWidth),wppaSavedMarginTop=-(90+wppaOvlBorderWidth+10+("auto"==wppaOvlTxtHeight?25:wppaOvlTxtHeight/2)),wppaSavedImageWidth=240,wppaSavedImageHeight=180+wppaOvlBorderWidth),a=0;a<e.length;a++)p=e[a],jQuery(p).attr("data-rel")?t=jQuery(p).attr("data-rel").split("["):p.rel?t=p.rel.split("["):t[0]="","wppa"==t[0]&&(wppaWppaOverlayActivated=!0,jQuery(p).on("click",function(p){wppaOvlShow(this),p.preventDefault()}),jQuery(p).css("cursor","url( "+wppaImageDirectory+wppaMagnifierCursor+" ),auto"));wppaIsMobile&&window.addEventListener("orientationchange",wppaDoOnOrientationChange)}function wppaOvlResize(){wppaConsoleLog("wppaOvlResize"),0<wppaOvlActivePanorama||(setTimeout("wppaOvlSize( "+wppaOvlAnimSpeed+" )",10),wppaOvlAudioStart&&!wppaOvlAudioPlaying&&setTimeout("wppaOvlStartAudio()",100))}function wppaShowFsButtons(p){void 0!==p&&(wppaNormsBtnOpac=p),jQuery("#wppa-exit-btn").stop().fadeTo(3,wppaNormsBtnOpac),"normal"==wppaOvlMode?jQuery("#wppa-fulls-btn").stop().fadeTo(3,wppaNormsBtnOpac):jQuery("#wppa-norms-btn").stop().fadeTo(3,wppaNormsBtnOpac)}jQuery(document).ready(function(p){wppaInitOverlay()}),jQuery(window).resize(function(){jQuery("#wppa-overlay-bg").css({height:window.innerHeight,width:window.innerWidth}),wppaOvlResize()}),wppaConsoleLog("wppa-lightbox.js version "+wppaLightboxVersion+" loaded.","force");
js/wppa-panorama.js ADDED
@@ -0,0 +1,25607 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* wppa-panorama.js
2
+ /*
3
+ /* This is a stripped version of Three.js
4
+ /*
5
+ /* wppa version 6.9.12
6
+ /**/
7
+
8
+
9
+ // File:src/Three.js
10
+
11
+ /**
12
+ * @author mrdoob / http://mrdoob.com/
13
+ */
14
+
15
+ var THREE = { REVISION: '69' };
16
+
17
+ // browserify support
18
+
19
+ if ( typeof module === 'object' ) {
20
+
21
+ module.exports = THREE;
22
+
23
+ }
24
+
25
+ // polyfills
26
+
27
+ if ( Math.sign === undefined ) {
28
+
29
+ Math.sign = function ( x ) {
30
+
31
+ return ( x < 0 ) ? - 1 : ( x > 0 ) ? 1 : 0;
32
+
33
+ };
34
+
35
+ }
36
+
37
+ // https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent.button
38
+
39
+ THREE.MOUSE = { LEFT: 0, MIDDLE: 1, RIGHT: 2 };
40
+
41
+ // GL STATE CONSTANTS
42
+
43
+ THREE.CullFaceNone = 0;
44
+ THREE.CullFaceBack = 1;
45
+ THREE.CullFaceFront = 2;
46
+ THREE.CullFaceFrontBack = 3;
47
+
48
+ THREE.FrontFaceDirectionCW = 0;
49
+ THREE.FrontFaceDirectionCCW = 1;
50
+
51
+ // SHADOWING TYPES
52
+
53
+ THREE.BasicShadowMap = 0;
54
+ THREE.PCFShadowMap = 1;
55
+ THREE.PCFSoftShadowMap = 2;
56
+
57
+ // MATERIAL CONSTANTS
58
+
59
+ // side
60
+
61
+ THREE.FrontSide = 0;
62
+ THREE.BackSide = 1;
63
+ THREE.DoubleSide = 2;
64
+
65
+ // shading
66
+
67
+ THREE.NoShading = 0;
68
+ THREE.FlatShading = 1;
69
+ THREE.SmoothShading = 2;
70
+
71
+ // colors
72
+
73
+ THREE.NoColors = 0;
74
+ THREE.FaceColors = 1;
75
+ THREE.VertexColors = 2;
76
+
77
+ // blending modes
78
+
79
+ THREE.NoBlending = 0;
80
+ THREE.NormalBlending = 1;
81
+ THREE.AdditiveBlending = 2;
82
+ THREE.SubtractiveBlending = 3;
83
+ THREE.MultiplyBlending = 4;
84
+ THREE.CustomBlending = 5;
85
+
86
+ // custom blending equations
87
+ // (numbers start from 100 not to clash with other
88
+ // mappings to OpenGL constants defined in Texture.js)
89
+
90
+ THREE.AddEquation = 100;
91
+ THREE.SubtractEquation = 101;
92
+ THREE.ReverseSubtractEquation = 102;
93
+ THREE.MinEquation = 103;
94
+ THREE.MaxEquation = 104;
95
+
96
+ // custom blending destination factors
97
+
98
+ THREE.ZeroFactor = 200;
99
+ THREE.OneFactor = 201;
100
+ THREE.SrcColorFactor = 202;
101
+ THREE.OneMinusSrcColorFactor = 203;
102
+ THREE.SrcAlphaFactor = 204;
103
+ THREE.OneMinusSrcAlphaFactor = 205;
104
+ THREE.DstAlphaFactor = 206;
105
+ THREE.OneMinusDstAlphaFactor = 207;
106
+
107
+ // custom blending source factors
108
+
109
+ //THREE.ZeroFactor = 200;
110
+ //THREE.OneFactor = 201;
111
+ //THREE.SrcAlphaFactor = 204;
112
+ //THREE.OneMinusSrcAlphaFactor = 205;
113
+ //THREE.DstAlphaFactor = 206;
114
+ //THREE.OneMinusDstAlphaFactor = 207;
115
+ THREE.DstColorFactor = 208;
116
+ THREE.OneMinusDstColorFactor = 209;
117
+ THREE.SrcAlphaSaturateFactor = 210;
118
+
119
+
120
+ // TEXTURE CONSTANTS
121
+
122
+ THREE.MultiplyOperation = 0;
123
+ THREE.MixOperation = 1;
124
+ THREE.AddOperation = 2;
125
+
126
+ // Mapping modes
127
+
128
+ THREE.UVMapping = function () {};
129
+
130
+ THREE.CubeReflectionMapping = function () {};
131
+ THREE.CubeRefractionMapping = function () {};
132
+
133
+ THREE.SphericalReflectionMapping = function () {};
134
+ THREE.SphericalRefractionMapping = function () {};
135
+
136
+ // Wrapping modes
137
+
138
+ THREE.RepeatWrapping = 1000;
139
+ THREE.ClampToEdgeWrapping = 1001;
140
+ THREE.MirroredRepeatWrapping = 1002;
141
+
142
+ // Filters
143
+
144
+ THREE.NearestFilter = 1003;
145
+ THREE.NearestMipMapNearestFilter = 1004;
146
+ THREE.NearestMipMapLinearFilter = 1005;
147
+ THREE.LinearFilter = 1006;
148
+ THREE.LinearMipMapNearestFilter = 1007;
149
+ THREE.LinearMipMapLinearFilter = 1008;
150
+
151
+ // Data types
152
+
153
+ THREE.UnsignedByteType = 1009;
154
+ THREE.ByteType = 1010;
155
+ THREE.ShortType = 1011;
156
+ THREE.UnsignedShortType = 1012;
157
+ THREE.IntType = 1013;
158
+ THREE.UnsignedIntType = 1014;
159
+ THREE.FloatType = 1015;
160
+
161
+ // Pixel types
162
+
163
+ //THREE.UnsignedByteType = 1009;
164
+ THREE.UnsignedShort4444Type = 1016;
165
+ THREE.UnsignedShort5551Type = 1017;
166
+ THREE.UnsignedShort565Type = 1018;
167
+
168
+ // Pixel formats
169
+
170
+ THREE.AlphaFormat = 1019;
171
+ THREE.RGBFormat = 1020;
172
+ THREE.RGBAFormat = 1021;
173
+ THREE.LuminanceFormat = 1022;
174
+ THREE.LuminanceAlphaFormat = 1023;
175
+
176
+ // DDS / ST3C Compressed texture formats
177
+
178
+ THREE.RGB_S3TC_DXT1_Format = 2001;
179
+ THREE.RGBA_S3TC_DXT1_Format = 2002;
180
+ THREE.RGBA_S3TC_DXT3_Format = 2003;
181
+ THREE.RGBA_S3TC_DXT5_Format = 2004;
182
+
183
+
184
+ // PVRTC compressed texture formats
185
+
186
+ THREE.RGB_PVRTC_4BPPV1_Format = 2100;
187
+ THREE.RGB_PVRTC_2BPPV1_Format = 2101;
188
+ THREE.RGBA_PVRTC_4BPPV1_Format = 2102;
189
+ THREE.RGBA_PVRTC_2BPPV1_Format = 2103;
190
+
191
+
192
+ // File:src/math/Color.js
193
+
194
+ /**
195
+ * @author mrdoob / http://mrdoob.com/
196
+ */
197
+
198
+ THREE.Color = function ( color ) {
199
+
200
+ if ( arguments.length === 3 ) {
201
+
202
+ return this.setRGB( arguments[ 0 ], arguments[ 1 ], arguments[ 2 ] );
203
+
204
+ }
205
+
206
+ return this.set( color )
207
+
208
+ };
209
+
210
+ THREE.Color.prototype = {
211
+
212
+ constructor: THREE.Color,
213
+
214
+ r: 1, g: 1, b: 1,
215
+
216
+ set: function ( value ) {
217
+
218
+ if ( value instanceof THREE.Color ) {
219
+
220
+ this.copy( value );
221
+
222
+ } else if ( typeof value === 'number' ) {
223
+
224
+ this.setHex( value );
225
+
226
+ } else if ( typeof value === 'string' ) {
227
+
228
+ this.setStyle( value );
229
+
230
+ }
231
+
232
+ return this;
233
+
234
+ },
235
+
236
+ setHex: function ( hex ) {
237
+
238
+ hex = Math.floor( hex );
239
+
240
+ this.r = ( hex >> 16 & 255 ) / 255;
241
+ this.g = ( hex >> 8 & 255 ) / 255;
242
+ this.b = ( hex & 255 ) / 255;
243
+
244
+ return this;
245
+
246
+ },
247
+
248
+ setRGB: function ( r, g, b ) {
249
+
250
+ this.r = r;
251
+ this.g = g;
252
+ this.b = b;
253
+
254
+ return this;
255
+
256
+ },
257
+
258
+ setHSL: function ( h, s, l ) {
259
+
260
+ // h,s,l ranges are in 0.0 - 1.0
261
+
262
+ if ( s === 0 ) {
263
+
264
+ this.r = this.g = this.b = l;
265
+
266
+ } else {
267
+
268
+ var hue2rgb = function ( p, q, t ) {
269
+
270
+ if ( t < 0 ) t += 1;
271
+ if ( t > 1 ) t -= 1;
272
+ if ( t < 1 / 6 ) return p + ( q - p ) * 6 * t;
273
+ if ( t < 1 / 2 ) return q;
274
+ if ( t < 2 / 3 ) return p + ( q - p ) * 6 * ( 2 / 3 - t );
275
+ return p;
276
+
277
+ };
278
+
279
+ var p = l <= 0.5 ? l * ( 1 + s ) : l + s - ( l * s );
280
+ var q = ( 2 * l ) - p;
281
+
282
+ this.r = hue2rgb( q, p, h + 1 / 3 );
283
+ this.g = hue2rgb( q, p, h );
284
+ this.b = hue2rgb( q, p, h - 1 / 3 );
285
+
286
+ }
287
+
288
+ return this;
289
+
290
+ },
291
+
292
+ setStyle: function ( style ) {
293
+
294
+ // rgb(255,0,0)
295
+
296
+ if ( /^rgb\((\d+), ?(\d+), ?(\d+)\)$/i.test( style ) ) {
297
+
298
+ var color = /^rgb\((\d+), ?(\d+), ?(\d+)\)$/i.exec( style );
299
+
300
+ this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
301
+ this.g = Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255;
302
+ this.b = Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255;
303
+
304
+ return this;
305
+
306
+ }
307
+
308
+ // rgb(100%,0%,0%)
309
+
310
+ if ( /^rgb\((\d+)\%, ?(\d+)\%, ?(\d+)\%\)$/i.test( style ) ) {
311
+
312
+ var color = /^rgb\((\d+)\%, ?(\d+)\%, ?(\d+)\%\)$/i.exec( style );
313
+
314
+ this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100;
315
+ this.g = Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100;
316
+ this.b = Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100;
317
+
318
+ return this;
319
+
320
+ }
321
+
322
+ // #ff0000
323
+
324
+ if ( /^\#([0-9a-f]{6})$/i.test( style ) ) {
325
+
326
+ var color = /^\#([0-9a-f]{6})$/i.exec( style );
327
+
328
+ this.setHex( parseInt( color[ 1 ], 16 ) );
329
+
330
+ return this;
331
+
332
+ }
333
+
334
+ // #f00
335
+
336
+ if ( /^\#([0-9a-f])([0-9a-f])([0-9a-f])$/i.test( style ) ) {
337
+
338
+ var color = /^\#([0-9a-f])([0-9a-f])([0-9a-f])$/i.exec( style );
339
+
340
+ this.setHex( parseInt( color[ 1 ] + color[ 1 ] + color[ 2 ] + color[ 2 ] + color[ 3 ] + color[ 3 ], 16 ) );
341
+
342
+ return this;
343
+
344
+ }
345
+
346
+ // red
347
+
348
+ if ( /^(\w+)$/i.test( style ) ) {
349
+
350
+ this.setHex( THREE.ColorKeywords[ style ] );
351
+
352
+ return this;
353
+
354
+ }
355
+
356
+
357
+ },
358
+
359
+ copy: function ( color ) {
360
+
361
+ this.r = color.r;
362
+ this.g = color.g;
363
+ this.b = color.b;
364
+
365
+ return this;
366
+
367
+ },
368
+
369
+ copyGammaToLinear: function ( color ) {
370
+
371
+ this.r = color.r * color.r;
372
+ this.g = color.g * color.g;
373
+ this.b = color.b * color.b;
374
+
375
+ return this;
376
+
377
+ },
378
+
379
+ copyLinearToGamma: function ( color ) {
380
+
381
+ this.r = Math.sqrt( color.r );
382
+ this.g = Math.sqrt( color.g );
383
+ this.b = Math.sqrt( color.b );
384
+
385
+ return this;
386
+
387
+ },
388
+
389
+ convertGammaToLinear: function () {
390
+
391
+ var r = this.r, g = this.g, b = this.b;
392
+
393
+ this.r = r * r;
394
+ this.g = g * g;
395
+ this.b = b * b;
396
+
397
+ return this;
398
+
399
+ },
400
+
401
+ convertLinearToGamma: function () {
402
+
403
+ this.r = Math.sqrt( this.r );
404
+ this.g = Math.sqrt( this.g );
405
+ this.b = Math.sqrt( this.b );
406
+
407
+ return this;
408
+
409
+ },
410
+
411
+ getHex: function () {
412
+
413
+ return ( this.r * 255 ) << 16 ^ ( this.g * 255 ) << 8 ^ ( this.b * 255 ) << 0;
414
+
415
+ },
416
+
417
+ getHexString: function () {
418
+
419
+ return ( '000000' + this.getHex().toString( 16 ) ).slice( - 6 );
420
+
421
+ },
422
+
423
+ getHSL: function ( optionalTarget ) {
424
+
425
+ // h,s,l ranges are in 0.0 - 1.0
426
+
427
+ var hsl = optionalTarget || { h: 0, s: 0, l: 0 };
428
+
429
+ var r = this.r, g = this.g, b = this.b;
430
+
431
+ var max = Math.max( r, g, b );
432
+ var min = Math.min( r, g, b );
433
+
434
+ var hue, saturation;
435
+ var lightness = ( min + max ) / 2.0;
436
+
437
+ if ( min === max ) {
438
+
439
+ hue = 0;
440
+ saturation = 0;
441
+
442
+ } else {
443
+
444
+ var delta = max - min;
445
+
446
+ saturation = lightness <= 0.5 ? delta / ( max + min ) : delta / ( 2 - max - min );
447
+
448
+ switch ( max ) {
449
+
450
+ case r: hue = ( g - b ) / delta + ( g < b ? 6 : 0 ); break;
451
+ case g: hue = ( b - r ) / delta + 2; break;
452
+ case b: hue = ( r - g ) / delta + 4; break;
453
+
454
+ }
455
+
456
+ hue /= 6;
457
+
458
+ }
459
+
460
+ hsl.h = hue;
461
+ hsl.s = saturation;
462
+ hsl.l = lightness;
463
+
464
+ return hsl;
465
+
466
+ },
467
+
468
+ getStyle: function () {
469
+
470
+ return 'rgb(' + ( ( this.r * 255 ) | 0 ) + ',' + ( ( this.g * 255 ) | 0 ) + ',' + ( ( this.b * 255 ) | 0 ) + ')';
471
+
472
+ },
473
+
474
+ offsetHSL: function ( h, s, l ) {
475
+
476
+ var hsl = this.getHSL();
477
+
478
+ hsl.h += h; hsl.s += s; hsl.l += l;
479
+
480
+ this.setHSL( hsl.h, hsl.s, hsl.l );
481
+
482
+ return this;
483
+
484
+ },
485
+
486
+ add: function ( color ) {
487
+
488
+ this.r += color.r;
489
+ this.g += color.g;
490
+ this.b += color.b;
491
+
492
+ return this;
493
+
494
+ },
495
+
496
+ addColors: function ( color1, color2 ) {
497
+
498
+ this.r = color1.r + color2.r;
499
+ this.g = color1.g + color2.g;
500
+ this.b = color1.b + color2.b;
501
+
502
+ return this;
503
+
504
+ },
505
+
506
+ addScalar: function ( s ) {
507
+
508
+ this.r += s;
509
+ this.g += s;
510
+ this.b += s;
511
+
512
+ return this;
513
+
514
+ },
515
+
516
+ multiply: function ( color ) {
517
+
518
+ this.r *= color.r;
519
+ this.g *= color.g;
520
+ this.b *= color.b;
521
+
522
+ return this;
523
+
524
+ },
525
+
526
+ multiplyScalar: function ( s ) {
527
+
528
+ this.r *= s;
529
+ this.g *= s;
530
+ this.b *= s;
531
+
532
+ return this;
533
+
534
+ },
535
+
536
+ lerp: function ( color, alpha ) {
537
+
538
+ this.r += ( color.r - this.r ) * alpha;
539
+ this.g += ( color.g - this.g ) * alpha;
540
+ this.b += ( color.b - this.b ) * alpha;
541
+
542
+ return this;
543
+
544
+ },
545
+
546
+ equals: function ( c ) {
547
+
548
+ return ( c.r === this.r ) && ( c.g === this.g ) && ( c.b === this.b );
549
+
550
+ },
551
+
552
+ fromArray: function ( array ) {
553
+
554
+ this.r = array[ 0 ];
555
+ this.g = array[ 1 ];
556
+ this.b = array[ 2 ];
557
+
558
+ return this;
559
+
560
+ },
561
+
562
+ toArray: function () {
563
+
564
+ return [ this.r, this.g, this.b ];
565
+
566
+ },
567
+
568
+ clone: function () {
569
+
570
+ return new THREE.Color().setRGB( this.r, this.g, this.b );
571
+
572
+ }
573
+
574
+ };
575
+
576
+ THREE.ColorKeywords = { 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF,
577
+ 'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2,
578
+ 'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50,
579
+ 'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B,
580
+ 'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B,
581
+ 'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F,
582
+ 'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3,
583
+ 'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222,
584
+ 'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700,
585
+ 'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4,
586
+ 'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00,
587
+ 'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3,
588
+ 'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA,
589
+ 'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32,
590
+ 'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3,
591
+ 'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC,
592
+ 'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD,
593
+ 'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6,
594
+ 'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9,
595
+ 'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F,
596
+ 'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE,
597
+ 'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA,
598
+ 'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0,
599
+ 'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32 };
600
+
601
+ // File:src/math/Quaternion.js
602
+
603
+ /**
604
+ * @author mikael emtinger / http://gomo.se/
605
+ * @author alteredq / http://alteredqualia.com/
606
+ * @author WestLangley / http://github.com/WestLangley
607
+ * @author bhouston / http://exocortex.com
608
+ */
609
+
610
+ THREE.Quaternion = function ( x, y, z, w ) {
611
+
612
+ this._x = x || 0;
613
+ this._y = y || 0;
614
+ this._z = z || 0;
615
+ this._w = ( w !== undefined ) ? w : 1;
616
+
617
+ };
618
+
619
+ THREE.Quaternion.prototype = {
620
+
621
+ constructor: THREE.Quaternion,
622
+
623
+ _x: 0,_y: 0, _z: 0, _w: 0,
624
+
625
+ get x () {
626
+
627
+ return this._x;
628
+
629
+ },
630
+
631
+ set x ( value ) {
632
+
633
+ this._x = value;
634
+ this.onChangeCallback();
635
+
636
+ },
637
+
638
+ get y () {
639
+
640
+ return this._y;
641
+
642
+ },
643
+
644
+ set y ( value ) {
645
+
646
+ this._y = value;
647
+ this.onChangeCallback();
648
+
649
+ },
650
+
651
+ get z () {
652
+
653
+ return this._z;
654
+
655
+ },
656
+
657
+ set z ( value ) {
658
+
659
+ this._z = value;
660
+ this.onChangeCallback();
661
+
662
+ },
663
+
664
+ get w () {
665
+
666
+ return this._w;
667
+
668
+ },
669
+
670
+ set w ( value ) {
671
+
672
+ this._w = value;
673
+ this.onChangeCallback();
674
+
675
+ },
676
+
677
+ set: function ( x, y, z, w ) {
678
+
679
+ this._x = x;
680
+ this._y = y;
681
+ this._z = z;
682
+ this._w = w;
683
+
684
+ this.onChangeCallback();
685
+
686
+ return this;
687
+
688
+ },
689
+
690
+ copy: function ( quaternion ) {
691
+
692
+ this._x = quaternion.x;
693
+ this._y = quaternion.y;
694
+ this._z = quaternion.z;
695
+ this._w = quaternion.w;
696
+
697
+ this.onChangeCallback();
698
+
699
+ return this;
700
+
701
+ },
702
+
703
+ setFromEuler: function ( euler, update ) {
704
+
705
+ if ( euler instanceof THREE.Euler === false ) {
706
+
707
+ throw new Error( 'THREE.Quaternion: .setFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
708
+ }
709
+
710
+ // http://www.mathworks.com/matlabcentral/fileexchange/
711
+ // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
712
+ // content/SpinCalc.m
713
+
714
+ var c1 = Math.cos( euler._x / 2 );
715
+ var c2 = Math.cos( euler._y / 2 );
716
+ var c3 = Math.cos( euler._z / 2 );
717
+ var s1 = Math.sin( euler._x / 2 );
718
+ var s2 = Math.sin( euler._y / 2 );
719
+ var s3 = Math.sin( euler._z / 2 );
720
+
721
+ if ( euler.order === 'XYZ' ) {
722
+
723
+ this._x = s1 * c2 * c3 + c1 * s2 * s3;
724
+ this._y = c1 * s2 * c3 - s1 * c2 * s3;
725
+ this._z = c1 * c2 * s3 + s1 * s2 * c3;
726
+ this._w = c1 * c2 * c3 - s1 * s2 * s3;
727
+
728
+ } else if ( euler.order === 'YXZ' ) {
729
+
730
+ this._x = s1 * c2 * c3 + c1 * s2 * s3;
731
+ this._y = c1 * s2 * c3 - s1 * c2 * s3;
732
+ this._z = c1 * c2 * s3 - s1 * s2 * c3;
733
+ this._w = c1 * c2 * c3 + s1 * s2 * s3;
734
+
735
+ } else if ( euler.order === 'ZXY' ) {
736
+
737
+ this._x = s1 * c2 * c3 - c1 * s2 * s3;
738
+ this._y = c1 * s2 * c3 + s1 * c2 * s3;
739
+ this._z = c1 * c2 * s3 + s1 * s2 * c3;
740
+ this._w = c1 * c2 * c3 - s1 * s2 * s3;
741
+
742
+ } else if ( euler.order === 'ZYX' ) {
743
+
744
+ this._x = s1 * c2 * c3 - c1 * s2 * s3;
745
+ this._y = c1 * s2 * c3 + s1 * c2 * s3;
746
+ this._z = c1 * c2 * s3 - s1 * s2 * c3;
747
+ this._w = c1 * c2 * c3 + s1 * s2 * s3;
748
+
749
+ } else if ( euler.order === 'YZX' ) {
750
+
751
+ this._x = s1 * c2 * c3 + c1 * s2 * s3;
752
+ this._y = c1 * s2 * c3 + s1 * c2 * s3;
753
+ this._z = c1 * c2 * s3 - s1 * s2 * c3;
754
+ this._w = c1 * c2 * c3 - s1 * s2 * s3;
755
+
756
+ } else if ( euler.order === 'XZY' ) {
757
+
758
+ this._x = s1 * c2 * c3 - c1 * s2 * s3;
759
+ this._y = c1 * s2 * c3 - s1 * c2 * s3;
760
+ this._z = c1 * c2 * s3 + s1 * s2 * c3;
761
+ this._w = c1 * c2 * c3 + s1 * s2 * s3;
762
+
763
+ }
764
+
765
+ if ( update !== false ) this.onChangeCallback();
766
+
767
+ return this;
768
+
769
+ },
770
+
771
+ setFromAxisAngle: function ( axis, angle ) {
772
+
773
+ // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
774
+
775
+ // assumes axis is normalized
776
+
777
+ var halfAngle = angle / 2, s = Math.sin( halfAngle );
778
+
779
+ this._x = axis.x * s;
780
+ this._y = axis.y * s;
781
+ this._z = axis.z * s;
782
+ this._w = Math.cos( halfAngle );
783
+
784
+ this.onChangeCallback();
785
+
786
+ return this;
787
+
788
+ },
789
+
790
+ setFromRotationMatrix: function ( m ) {
791
+
792
+ // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
793
+
794
+ // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
795
+
796
+ var te = m.elements,
797
+
798
+ m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
799
+ m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
800
+ m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ],
801
+
802
+ trace = m11 + m22 + m33,
803
+ s;
804
+
805
+ if ( trace > 0 ) {
806
+
807
+ s = 0.5 / Math.sqrt( trace + 1.0 );
808
+
809
+ this._w = 0.25 / s;
810
+ this._x = ( m32 - m23 ) * s;
811
+ this._y = ( m13 - m31 ) * s;
812
+ this._z = ( m21 - m12 ) * s;
813
+
814
+ } else if ( m11 > m22 && m11 > m33 ) {
815
+
816
+ s = 2.0 * Math.sqrt( 1.0 + m11 - m22 - m33 );
817
+
818
+ this._w = ( m32 - m23 ) / s;
819
+ this._x = 0.25 * s;
820
+ this._y = ( m12 + m21 ) / s;
821
+ this._z = ( m13 + m31 ) / s;
822
+
823
+ } else if ( m22 > m33 ) {
824
+
825
+ s = 2.0 * Math.sqrt( 1.0 + m22 - m11 - m33 );
826
+
827
+ this._w = ( m13 - m31 ) / s;
828
+ this._x = ( m12 + m21 ) / s;
829
+ this._y = 0.25 * s;
830
+ this._z = ( m23 + m32 ) / s;
831
+
832
+ } else {
833
+
834
+ s = 2.0 * Math.sqrt( 1.0 + m33 - m11 - m22 );
835
+
836
+ this._w = ( m21 - m12 ) / s;
837
+ this._x = ( m13 + m31 ) / s;
838
+ this._y = ( m23 + m32 ) / s;
839
+ this._z = 0.25 * s;
840
+
841
+ }
842
+
843
+ this.onChangeCallback();
844
+
845
+ return this;
846
+
847
+ },
848
+
849
+ setFromUnitVectors: function () {
850
+
851
+ // http://lolengine.net/blog/2014/02/24/quaternion-from-two-vectors-final
852
+
853
+ // assumes direction vectors vFrom and vTo are normalized
854
+
855
+ var v1, r;
856
+
857
+ var EPS = 0.000001;
858
+
859
+ return function ( vFrom, vTo ) {
860
+
861
+ if ( v1 === undefined ) v1 = new THREE.Vector3();
862
+
863
+ r = vFrom.dot( vTo ) + 1;
864
+
865
+ if ( r < EPS ) {
866
+
867
+ r = 0;
868
+
869
+ if ( Math.abs( vFrom.x ) > Math.abs( vFrom.z ) ) {
870
+
871
+ v1.set( - vFrom.y, vFrom.x, 0 );
872
+
873
+ } else {
874
+
875
+ v1.set( 0, - vFrom.z, vFrom.y );
876
+
877
+ }
878
+
879
+ } else {
880
+
881
+ v1.crossVectors( vFrom, vTo );
882
+
883
+ }
884
+
885
+ this._x = v1.x;
886
+ this._y = v1.y;
887
+ this._z = v1.z;
888
+ this._w = r;
889
+
890
+ this.normalize();
891
+
892
+ return this;
893
+
894
+ }
895
+
896
+ }(),
897
+
898
+ inverse: function () {
899
+
900
+ this.conjugate().normalize();
901
+
902
+ return this;
903
+
904
+ },
905
+
906
+ conjugate: function () {
907
+
908
+ this._x *= - 1;
909
+ this._y *= - 1;
910
+ this._z *= - 1;
911
+
912
+ this.onChangeCallback();
913
+
914
+ return this;
915
+
916
+ },
917
+
918
+ dot: function ( v ) {
919
+
920
+ return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
921
+
922
+ },
923
+
924
+ lengthSq: function () {
925
+
926
+ return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
927
+
928
+ },
929
+
930
+ length: function () {
931
+
932
+ return Math.sqrt( this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w );
933
+
934
+ },
935
+
936
+ normalize: function () {
937
+
938
+ var l = this.length();
939
+
940
+ if ( l === 0 ) {
941
+
942
+ this._x = 0;
943
+ this._y = 0;
944
+ this._z = 0;
945
+ this._w = 1;
946
+
947
+ } else {
948
+
949
+ l = 1 / l;
950
+
951
+ this._x = this._x * l;
952
+ this._y = this._y * l;
953
+ this._z = this._z * l;
954
+ this._w = this._w * l;
955
+
956
+ }
957
+
958
+ this.onChangeCallback();
959
+
960
+ return this;
961
+
962
+ },
963
+
964
+ multiply: function ( q, p ) {
965
+
966
+ if ( p !== undefined ) {
967
+
968
+ console.warn( 'THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.' );
969
+ return this.multiplyQuaternions( q, p );
970
+
971
+ }
972
+
973
+ return this.multiplyQuaternions( this, q );
974
+
975
+ },
976
+
977
+ multiplyQuaternions: function ( a, b ) {
978
+
979
+ // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
980
+
981
+ var qax = a._x, qay = a._y, qaz = a._z, qaw = a._w;
982
+ var qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w;
983
+
984
+ this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
985
+ this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
986
+ this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
987
+ this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
988
+
989
+ this.onChangeCallback();
990
+
991
+ return this;
992
+
993
+ },
994
+
995
+ multiplyVector3: function ( vector ) {
996
+
997
+ console.warn( 'THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.' );
998
+ return vector.applyQuaternion( this );
999
+
1000
+ },
1001
+
1002
+ slerp: function ( qb, t ) {
1003
+
1004
+ if ( t === 0 ) return this;
1005
+ if ( t === 1 ) return this.copy( qb );
1006
+
1007
+ var x = this._x, y = this._y, z = this._z, w = this._w;
1008
+
1009
+ // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
1010
+
1011
+ var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
1012
+
1013
+ if ( cosHalfTheta < 0 ) {
1014
+
1015
+ this._w = - qb._w;
1016
+ this._x = - qb._x;
1017
+ this._y = - qb._y;
1018
+ this._z = - qb._z;
1019
+
1020
+ cosHalfTheta = - cosHalfTheta;
1021
+
1022
+ } else {
1023
+
1024
+ this.copy( qb );
1025
+
1026
+ }
1027
+
1028
+ if ( cosHalfTheta >= 1.0 ) {
1029
+
1030
+ this._w = w;
1031
+ this._x = x;
1032
+ this._y = y;
1033
+ this._z = z;
1034
+
1035
+ return this;
1036
+
1037
+ }
1038
+
1039
+ var halfTheta = Math.acos( cosHalfTheta );
1040
+ var sinHalfTheta = Math.sqrt( 1.0 - cosHalfTheta * cosHalfTheta );
1041
+
1042
+ if ( Math.abs( sinHalfTheta ) < 0.001 ) {
1043
+
1044
+ this._w = 0.5 * ( w + this._w );
1045
+ this._x = 0.5 * ( x + this._x );
1046
+ this._y = 0.5 * ( y + this._y );
1047
+ this._z = 0.5 * ( z + this._z );
1048
+
1049
+ return this;
1050
+
1051
+ }
1052
+
1053
+ var ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta,
1054
+ ratioB = Math.sin( t * halfTheta ) / sinHalfTheta;
1055
+
1056
+ this._w = ( w * ratioA + this._w * ratioB );
1057
+ this._x = ( x * ratioA + this._x * ratioB );
1058
+ this._y = ( y * ratioA + this._y * ratioB );
1059
+ this._z = ( z * ratioA + this._z * ratioB );
1060
+
1061
+ this.onChangeCallback();
1062
+
1063
+ return this;
1064
+
1065
+ },
1066
+
1067
+ equals: function ( quaternion ) {
1068
+
1069
+ return ( quaternion._x === this._x ) && ( quaternion._y === this._y ) && ( quaternion._z === this._z ) && ( quaternion._w === this._w );
1070
+
1071
+ },
1072
+
1073
+ fromArray: function ( array, offset ) {
1074
+
1075
+ if ( offset === undefined ) offset = 0;
1076
+
1077
+ this._x = array[ offset ];
1078
+ this._y = array[ offset + 1 ];
1079
+ this._z = array[ offset + 2 ];
1080
+ this._w = array[ offset + 3 ];
1081
+
1082
+ this.onChangeCallback();
1083
+
1084
+ return this;
1085
+
1086
+ },
1087
+
1088
+ toArray: function ( array, offset ) {
1089
+
1090
+ if ( array === undefined ) array = [];
1091
+ if ( offset === undefined ) offset = 0;
1092
+
1093
+ array[ offset ] = this._x;
1094
+ array[ offset + 1 ] = this._y;
1095
+ array[ offset + 2 ] = this._z;
1096
+ array[ offset + 3 ] = this._w;
1097
+
1098
+ return array;
1099
+
1100
+ },
1101
+
1102
+ onChange: function ( callback ) {
1103
+
1104
+ this.onChangeCallback = callback;
1105
+
1106
+ return this;
1107
+
1108
+ },
1109
+
1110
+ onChangeCallback: function () {},
1111
+
1112
+ clone: function () {
1113
+
1114
+ return new THREE.Quaternion( this._x, this._y, this._z, this._w );
1115
+
1116
+ }
1117
+
1118
+ };
1119
+
1120
+ THREE.Quaternion.slerp = function ( qa, qb, qm, t ) {
1121
+
1122
+ return qm.copy( qa ).slerp( qb, t );
1123
+
1124
+ }
1125
+
1126
+ // File:src/math/Vector2.js
1127
+
1128
+ /**
1129
+ * @author mrdoob / http://mrdoob.com/
1130
+ * @author philogb / http://blog.thejit.org/
1131
+ * @author egraether / http://egraether.com/
1132
+ * @author zz85 / http://www.lab4games.net/zz85/blog
1133
+ */
1134
+
1135
+ THREE.Vector2 = function ( x, y ) {
1136
+
1137
+ this.x = x || 0;
1138
+ this.y = y || 0;
1139
+
1140
+ };
1141
+
1142
+ THREE.Vector2.prototype = {
1143
+
1144
+ constructor: THREE.Vector2,
1145
+
1146
+ set: function ( x, y ) {
1147
+
1148
+ this.x = x;
1149
+ this.y = y;
1150
+
1151
+ return this;
1152
+
1153
+ },
1154
+
1155
+ setX: function ( x ) {
1156
+
1157
+ this.x = x;
1158
+
1159
+ return this;
1160
+
1161
+ },
1162
+
1163
+ setY: function ( y ) {
1164
+
1165
+ this.y = y;
1166
+
1167
+ return this;
1168
+
1169
+ },
1170
+
1171
+ setComponent: function ( index, value ) {
1172
+
1173
+ switch ( index ) {
1174
+
1175
+ case 0: this.x = value; break;
1176
+ case 1: this.y = value; break;
1177
+ default: throw new Error( 'index is out of range: ' + index );
1178
+
1179
+ }
1180
+
1181
+ },
1182
+
1183
+ getComponent: function ( index ) {
1184
+
1185
+ switch ( index ) {
1186
+
1187
+ case 0: return this.x;
1188
+ case 1: return this.y;
1189
+ default: throw new Error( 'index is out of range: ' + index );
1190
+
1191
+ }
1192
+
1193
+ },
1194
+
1195
+ copy: function ( v ) {
1196
+
1197
+ this.x = v.x;
1198
+ this.y = v.y;
1199
+
1200
+ return this;
1201
+
1202
+ },
1203
+
1204
+ add: function ( v, w ) {
1205
+
1206
+ if ( w !== undefined ) {
1207
+
1208
+ console.warn( 'THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
1209
+ return this.addVectors( v, w );
1210
+
1211
+ }
1212
+
1213
+ this.x += v.x;
1214
+ this.y += v.y;
1215
+
1216
+ return this;
1217
+
1218
+ },
1219
+
1220
+ addVectors: function ( a, b ) {
1221
+
1222
+ this.x = a.x + b.x;
1223
+ this.y = a.y + b.y;
1224
+
1225
+ return this;
1226
+
1227
+ },
1228
+
1229
+ addScalar: function ( s ) {
1230
+
1231
+ this.x += s;
1232
+ this.y += s;
1233
+
1234
+ return this;
1235
+
1236
+ },
1237
+
1238
+ sub: function ( v, w ) {
1239
+
1240
+ if ( w !== undefined ) {
1241
+
1242
+ console.warn( 'THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
1243
+ return this.subVectors( v, w );
1244
+
1245
+ }
1246
+
1247
+ this.x -= v.x;
1248
+ this.y -= v.y;
1249
+
1250
+ return this;
1251
+
1252
+ },
1253
+
1254
+ subVectors: function ( a, b ) {
1255
+
1256
+ this.x = a.x - b.x;
1257
+ this.y = a.y - b.y;
1258
+
1259
+ return this;
1260
+
1261
+ },
1262
+
1263
+ multiply: function ( v ) {
1264
+
1265
+ this.x *= v.x;
1266
+ this.y *= v.y;
1267
+
1268
+ return this;
1269
+
1270
+ },
1271
+
1272
+ multiplyScalar: function ( s ) {
1273
+
1274
+ this.x *= s;
1275
+ this.y *= s;
1276
+
1277
+ return this;
1278
+
1279
+ },
1280
+
1281
+ divide: function ( v ) {
1282
+
1283
+ this.x /= v.x;
1284
+ this.y /= v.y;
1285
+
1286
+ return this;
1287
+
1288
+ },
1289
+
1290
+ divideScalar: function ( scalar ) {
1291
+
1292
+ if ( scalar !== 0 ) {
1293
+
1294
+ var invScalar = 1 / scalar;
1295
+
1296
+ this.x *= invScalar;
1297
+ this.y *= invScalar;
1298
+
1299
+ } else {
1300
+
1301
+ this.x = 0;
1302
+ this.y = 0;
1303
+
1304
+ }
1305
+
1306
+ return this;
1307
+
1308
+ },
1309
+
1310
+ min: function ( v ) {
1311
+
1312
+ if ( this.x > v.x ) {
1313
+
1314
+ this.x = v.x;
1315
+
1316
+ }
1317
+
1318
+ if ( this.y > v.y ) {
1319
+
1320
+ this.y = v.y;
1321
+
1322
+ }
1323
+
1324
+ return this;
1325
+
1326
+ },
1327
+
1328
+ max: function ( v ) {
1329
+
1330
+ if ( this.x < v.x ) {
1331
+
1332
+ this.x = v.x;
1333
+
1334
+ }
1335
+
1336
+ if ( this.y < v.y ) {
1337
+
1338
+ this.y = v.y;
1339
+
1340
+ }
1341
+
1342
+ return this;
1343
+
1344
+ },
1345
+
1346
+ clamp: function ( min, max ) {
1347
+
1348
+ // This function assumes min < max, if this assumption isn't true it will not operate correctly
1349
+
1350
+ if ( this.x < min.x ) {
1351
+
1352
+ this.x = min.x;
1353
+
1354
+ } else if ( this.x > max.x ) {
1355
+
1356
+ this.x = max.x;
1357
+
1358
+ }
1359
+
1360
+ if ( this.y < min.y ) {
1361
+
1362
+ this.y = min.y;
1363
+
1364
+ } else if ( this.y > max.y ) {
1365
+
1366
+ this.y = max.y;
1367
+
1368
+ }
1369
+
1370
+ return this;
1371
+ },
1372
+
1373
+ clampScalar: ( function () {
1374
+
1375
+ var min, max;
1376
+
1377
+ return function ( minVal, maxVal ) {
1378
+
1379
+ if ( min === undefined ) {
1380
+
1381
+ min = new THREE.Vector2();
1382
+ max = new THREE.Vector2();
1383
+
1384
+ }
1385
+
1386
+ min.set( minVal, minVal );
1387
+ max.set( maxVal, maxVal );
1388
+
1389
+ return this.clamp( min, max );
1390
+
1391
+ };
1392
+
1393
+ } )(),
1394
+
1395
+ floor: function () {
1396
+
1397
+ this.x = Math.floor( this.x );
1398
+ this.y = Math.floor( this.y );
1399
+
1400
+ return this;
1401
+
1402
+ },
1403
+
1404
+ ceil: function () {
1405
+
1406
+ this.x = Math.ceil( this.x );
1407
+ this.y = Math.ceil( this.y );
1408
+
1409
+ return this;
1410
+
1411
+ },
1412
+
1413
+ round: function () {
1414
+
1415
+ this.x = Math.round( this.x );
1416
+ this.y = Math.round( this.y );
1417
+
1418
+ return this;
1419
+
1420
+ },
1421
+
1422
+ roundToZero: function () {
1423
+
1424
+ this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
1425
+ this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
1426
+
1427
+ return this;
1428
+
1429
+ },
1430
+
1431
+ negate: function () {
1432
+
1433
+ this.x = - this.x;
1434
+ this.y = - this.y;
1435
+
1436
+ return this;
1437
+
1438
+ },
1439
+
1440
+ dot: function ( v ) {
1441
+
1442
+ return this.x * v.x + this.y * v.y;
1443
+
1444
+ },
1445
+
1446
+ lengthSq: function () {
1447
+
1448
+ return this.x * this.x + this.y * this.y;
1449
+
1450
+ },
1451
+
1452
+ length: function () {
1453
+
1454
+ return Math.sqrt( this.x * this.x + this.y * this.y );
1455
+
1456
+ },
1457
+
1458
+ normalize: function () {
1459
+
1460
+ return this.divideScalar( this.length() );
1461
+
1462
+ },
1463
+
1464
+ distanceTo: function ( v ) {
1465
+
1466
+ return Math.sqrt( this.distanceToSquared( v ) );
1467
+
1468
+ },
1469
+
1470
+ distanceToSquared: function ( v ) {
1471
+
1472
+ var dx = this.x - v.x, dy = this.y - v.y;
1473
+ return dx * dx + dy * dy;
1474
+
1475
+ },
1476
+
1477
+ setLength: function ( l ) {
1478
+
1479
+ var oldLength = this.length();
1480
+
1481
+ if ( oldLength !== 0 && l !== oldLength ) {
1482
+
1483
+ this.multiplyScalar( l / oldLength );
1484
+ }
1485
+
1486
+ return this;
1487
+
1488
+ },
1489
+
1490
+ lerp: function ( v, alpha ) {
1491
+
1492
+ this.x += ( v.x - this.x ) * alpha;
1493
+ this.y += ( v.y - this.y ) * alpha;
1494
+
1495
+ return this;
1496
+
1497
+ },
1498
+
1499
+ equals: function ( v ) {
1500
+
1501
+ return ( ( v.x === this.x ) && ( v.y === this.y ) );
1502
+
1503
+ },
1504
+
1505
+ fromArray: function ( array, offset ) {
1506
+
1507
+ if ( offset === undefined ) offset = 0;
1508
+
1509
+ this.x = array[ offset ];
1510
+ this.y = array[ offset + 1 ];
1511
+
1512
+ return this;
1513
+
1514
+ },
1515
+
1516
+ toArray: function ( array, offset ) {
1517
+
1518
+ if ( array === undefined ) array = [];
1519
+ if ( offset === undefined ) offset = 0;
1520
+
1521
+ array[ offset ] = this.x;
1522
+ array[ offset + 1 ] = this.y;
1523
+
1524
+ return array;
1525
+
1526
+ },
1527
+
1528
+ clone: function () {
1529
+
1530
+ return new THREE.Vector2( this.x, this.y );
1531
+
1532
+ }
1533
+
1534
+ };
1535
+
1536
+ // File:src/math/Vector3.js
1537
+
1538
+ /**
1539
+ * @author mrdoob / http://mrdoob.com/
1540
+ * @author *kile / http://kile.stravaganza.org/
1541
+ * @author philogb / http://blog.thejit.org/
1542
+ * @author mikael emtinger / http://gomo.se/
1543
+ * @author egraether / http://egraether.com/
1544
+ * @author WestLangley / http://github.com/WestLangley
1545
+ */
1546
+
1547
+ THREE.Vector3 = function ( x, y, z ) {
1548
+
1549
+ this.x = x || 0;
1550
+ this.y = y || 0;
1551
+ this.z = z || 0;
1552
+
1553
+ };
1554
+
1555
+ THREE.Vector3.prototype = {
1556
+
1557
+ constructor: THREE.Vector3,
1558
+
1559
+ set: function ( x, y, z ) {
1560
+
1561
+ this.x = x;
1562
+ this.y = y;
1563
+ this.z = z;
1564
+
1565
+ return this;
1566
+
1567
+ },
1568
+
1569
+ setX: function ( x ) {
1570
+
1571
+ this.x = x;
1572
+
1573
+ return this;
1574
+
1575
+ },
1576
+
1577
+ setY: function ( y ) {
1578
+
1579
+ this.y = y;
1580
+
1581
+ return this;
1582
+
1583
+ },
1584
+
1585
+ setZ: function ( z ) {
1586
+
1587
+ this.z = z;
1588
+
1589
+ return this;
1590
+
1591
+ },
1592
+
1593
+ setComponent: function ( index, value ) {
1594
+
1595
+ switch ( index ) {
1596
+
1597
+ case 0: this.x = value; break;
1598
+ case 1: this.y = value; break;
1599
+ case 2: this.z = value; break;
1600
+ default: throw new Error( 'index is out of range: ' + index );
1601
+
1602
+ }
1603
+
1604
+ },
1605
+
1606
+ getComponent: function ( index ) {
1607
+
1608
+ switch ( index ) {
1609
+
1610
+ case 0: return this.x;
1611
+ case 1: return this.y;
1612
+ case 2: return this.z;
1613
+ default: throw new Error( 'index is out of range: ' + index );
1614
+
1615
+ }
1616
+
1617
+ },
1618
+
1619
+ copy: function ( v ) {
1620
+
1621
+ this.x = v.x;
1622
+ this.y = v.y;
1623
+ this.z = v.z;
1624
+
1625
+ return this;
1626
+
1627
+ },
1628
+
1629
+ add: function ( v, w ) {
1630
+
1631
+ if ( w !== undefined ) {
1632
+
1633
+ console.warn( 'THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
1634
+ return this.addVectors( v, w );
1635
+
1636
+ }
1637
+
1638
+ this.x += v.x;
1639
+ this.y += v.y;
1640
+ this.z += v.z;
1641
+
1642
+ return this;
1643
+
1644
+ },
1645
+
1646
+ addScalar: function ( s ) {
1647
+
1648
+ this.x += s;
1649
+ this.y += s;
1650
+ this.z += s;
1651
+
1652
+ return this;
1653
+
1654
+ },
1655
+
1656
+ addVectors: function ( a, b ) {
1657
+
1658
+ this.x = a.x + b.x;
1659
+ this.y = a.y + b.y;
1660
+ this.z = a.z + b.z;
1661
+
1662
+ return this;
1663
+
1664
+ },
1665
+
1666
+ sub: function ( v, w ) {
1667
+
1668
+ if ( w !== undefined ) {
1669
+
1670
+ console.warn( 'THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
1671
+ return this.subVectors( v, w );
1672
+
1673
+ }
1674
+
1675
+ this.x -= v.x;
1676
+ this.y -= v.y;
1677
+ this.z -= v.z;
1678
+
1679
+ return this;
1680
+
1681
+ },
1682
+
1683
+ subVectors: function ( a, b ) {
1684
+
1685
+ this.x = a.x - b.x;
1686
+ this.y = a.y - b.y;
1687
+ this.z = a.z - b.z;
1688
+
1689
+ return this;
1690
+
1691
+ },
1692
+
1693
+ multiply: function ( v, w ) {
1694
+
1695
+ if ( w !== undefined ) {
1696
+
1697
+ console.warn( 'THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.' );
1698
+ return this.multiplyVectors( v, w );
1699
+
1700
+ }
1701
+
1702
+ this.x *= v.x;
1703
+ this.y *= v.y;
1704
+ this.z *= v.z;
1705
+
1706
+ return this;
1707
+
1708
+ },
1709
+
1710
+ multiplyScalar: function ( scalar ) {
1711
+
1712
+ this.x *= scalar;
1713
+ this.y *= scalar;
1714
+ this.z *= scalar;
1715
+
1716
+ return this;
1717
+
1718
+ },
1719
+
1720
+ multiplyVectors: function ( a, b ) {
1721
+
1722
+ this.x = a.x * b.x;
1723
+ this.y = a.y * b.y;
1724
+ this.z = a.z * b.z;
1725
+
1726
+ return this;
1727
+
1728
+ },
1729
+
1730
+ applyEuler: function () {
1731
+
1732
+ var quaternion;
1733
+
1734
+ return function ( euler ) {
1735
+
1736
+ if ( euler instanceof THREE.Euler === false ) {
1737
+
1738
+ console.error( 'THREE.Vector3: .applyEuler() now expects a Euler rotation rather than a Vector3 and order.' );
1739
+
1740
+ }
1741
+
1742
+ if ( quaternion === undefined ) quaternion = new THREE.Quaternion();
1743
+
1744
+ this.applyQuaternion( quaternion.setFromEuler( euler ) );
1745
+
1746
+ return this;
1747
+
1748
+ };
1749
+
1750
+ }(),
1751
+
1752
+ applyAxisAngle: function () {
1753
+
1754
+ var quaternion;
1755
+
1756
+ return function ( axis, angle ) {
1757
+
1758
+ if ( quaternion === undefined ) quaternion = new THREE.Quaternion();
1759
+
1760
+ this.applyQuaternion( quaternion.setFromAxisAngle( axis, angle ) );
1761
+
1762
+ return this;
1763
+
1764
+ };
1765
+
1766
+ }(),
1767
+
1768
+ applyMatrix3: function ( m ) {
1769
+
1770
+ var x = this.x;
1771
+ var y = this.y;
1772
+ var z = this.z;
1773
+
1774
+ var e = m.elements;
1775
+
1776
+ this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ] * z;
1777
+ this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ] * z;
1778
+ this.z = e[ 2 ] * x + e[ 5 ] * y + e[ 8 ] * z;
1779
+
1780
+ return this;
1781
+
1782
+ },
1783
+
1784
+ applyMatrix4: function ( m ) {
1785
+
1786
+ // input: THREE.Matrix4 affine matrix
1787
+
1788
+ var x = this.x, y = this.y, z = this.z;
1789
+
1790
+ var e = m.elements;
1791
+
1792
+ this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ];
1793
+ this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ];
1794
+ this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ];
1795
+
1796
+ return this;
1797
+
1798
+ },
1799
+
1800
+ applyProjection: function ( m ) {
1801
+
1802
+ // input: THREE.Matrix4 projection matrix
1803
+
1804
+ var x = this.x, y = this.y, z = this.z;
1805
+
1806
+ var e = m.elements;
1807
+ var d = 1 / ( e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] ); // perspective divide
1808
+
1809
+ this.x = ( e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] ) * d;
1810
+ this.y = ( e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] ) * d;
1811
+ this.z = ( e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] ) * d;
1812
+
1813
+ return this;
1814
+
1815
+ },
1816
+
1817
+ applyQuaternion: function ( q ) {
1818
+
1819
+ var x = this.x;
1820
+ var y = this.y;
1821
+ var z = this.z;
1822
+
1823
+ var qx = q.x;
1824
+ var qy = q.y;
1825
+ var qz = q.z;
1826
+ var qw = q.w;
1827
+
1828
+ // calculate quat * vector
1829
+
1830
+ var ix = qw * x + qy * z - qz * y;
1831
+ var iy = qw * y + qz * x - qx * z;
1832
+ var iz = qw * z + qx * y - qy * x;
1833
+ var iw = - qx * x - qy * y - qz * z;
1834
+
1835
+ // calculate result * inverse quat
1836
+
1837
+ this.x = ix * qw + iw * - qx + iy * - qz - iz * - qy;
1838
+ this.y = iy * qw + iw * - qy + iz * - qx - ix * - qz;
1839
+ this.z = iz * qw + iw * - qz + ix * - qy - iy * - qx;
1840
+
1841
+ return this;
1842
+
1843
+ },
1844
+
1845
+ project: function () {
1846
+
1847
+ var matrix;
1848
+
1849
+ return function ( camera ) {
1850
+
1851
+ if ( matrix === undefined ) matrix = new THREE.Matrix4();
1852
+
1853
+ matrix.multiplyMatrices( camera.projectionMatrix, matrix.getInverse( camera.matrixWorld ) );
1854
+ return this.applyProjection( matrix );
1855
+
1856
+ };
1857
+
1858
+ }(),
1859
+
1860
+ unproject: function () {
1861
+
1862
+ var matrix;
1863
+
1864
+ return function ( camera ) {
1865
+
1866
+ if ( matrix === undefined ) matrix = new THREE.Matrix4();
1867
+
1868
+ matrix.multiplyMatrices( camera.matrixWorld, matrix.getInverse( camera.projectionMatrix ) );
1869
+ return this.applyProjection( matrix );
1870
+
1871
+ };
1872
+
1873
+ }(),
1874
+
1875
+ transformDirection: function ( m ) {
1876
+
1877
+ // input: THREE.Matrix4 affine matrix
1878
+ // vector interpreted as a direction
1879
+
1880
+ var x = this.x, y = this.y, z = this.z;
1881
+
1882
+ var e = m.elements;
1883
+
1884
+ this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z;
1885
+ this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z;
1886
+ this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z;
1887
+
1888
+ this.normalize();
1889
+
1890
+ return this;
1891
+
1892
+ },
1893
+
1894
+ divide: function ( v ) {
1895
+
1896
+ this.x /= v.x;
1897
+ this.y /= v.y;
1898
+ this.z /= v.z;
1899
+
1900
+ return this;
1901
+
1902
+ },
1903
+
1904
+ divideScalar: function ( scalar ) {
1905
+
1906
+ if ( scalar !== 0 ) {
1907
+
1908
+ var invScalar = 1 / scalar;
1909
+
1910
+ this.x *= invScalar;
1911
+ this.y *= invScalar;
1912
+ this.z *= invScalar;
1913
+
1914
+ } else {
1915
+
1916
+ this.x = 0;
1917
+ this.y = 0;
1918
+ this.z = 0;
1919
+
1920
+ }
1921
+
1922
+ return this;
1923
+
1924
+ },
1925
+
1926
+ min: function ( v ) {
1927
+
1928
+ if ( this.x > v.x ) {
1929
+
1930
+ this.x = v.x;
1931
+
1932
+ }
1933
+
1934
+ if ( this.y > v.y ) {
1935
+
1936
+ this.y = v.y;
1937
+
1938
+ }
1939
+
1940
+ if ( this.z > v.z ) {
1941
+
1942
+ this.z = v.z;
1943
+
1944
+ }
1945
+
1946
+ return this;
1947
+
1948
+ },
1949
+
1950
+ max: function ( v ) {
1951
+
1952
+ if ( this.x < v.x ) {
1953
+
1954
+ this.x = v.x;
1955
+
1956
+ }
1957
+
1958
+ if ( this.y < v.y ) {
1959
+
1960
+ this.y = v.y;
1961
+
1962
+ }
1963
+
1964
+ if ( this.z < v.z ) {
1965
+
1966
+ this.z = v.z;
1967
+
1968
+ }
1969
+
1970
+ return this;
1971
+
1972
+ },
1973
+
1974
+ clamp: function ( min, max ) {
1975
+
1976
+ // This function assumes min < max, if this assumption isn't true it will not operate correctly
1977
+
1978
+ if ( this.x < min.x ) {
1979
+
1980
+ this.x = min.x;
1981
+
1982
+ } else if ( this.x > max.x ) {
1983
+
1984
+ this.x = max.x;
1985
+
1986
+ }
1987
+
1988
+ if ( this.y < min.y ) {
1989
+
1990
+ this.y = min.y;
1991
+
1992
+ } else if ( this.y > max.y ) {
1993
+
1994
+ this.y = max.y;
1995
+
1996
+ }
1997
+
1998
+ if ( this.z < min.z ) {
1999
+
2000
+ this.z = min.z;
2001
+
2002
+ } else if ( this.z > max.z ) {
2003
+
2004
+ this.z = max.z;
2005
+
2006
+ }
2007
+
2008
+ return this;
2009
+
2010
+ },
2011
+
2012
+ clampScalar: ( function () {
2013
+
2014
+ var min, max;
2015
+
2016
+ return function ( minVal, maxVal ) {
2017
+
2018
+ if ( min === undefined ) {
2019
+
2020
+ min = new THREE.Vector3();
2021
+ max = new THREE.Vector3();
2022
+
2023
+ }
2024
+
2025
+ min.set( minVal, minVal, minVal );
2026
+ max.set( maxVal, maxVal, maxVal );
2027
+
2028
+ return this.clamp( min, max );
2029
+
2030
+ };
2031
+
2032
+ } )(),
2033
+
2034
+ floor: function () {
2035
+
2036
+ this.x = Math.floor( this.x );
2037
+ this.y = Math.floor( this.y );
2038
+ this.z = Math.floor( this.z );
2039
+
2040
+ return this;
2041
+
2042
+ },
2043
+
2044
+ ceil: function () {
2045
+
2046
+ this.x = Math.ceil( this.x );
2047
+ this.y = Math.ceil( this.y );
2048
+ this.z = Math.ceil( this.z );
2049
+
2050
+ return this;
2051
+
2052
+ },
2053
+
2054
+ round: function () {
2055
+
2056
+ this.x = Math.round( this.x );
2057
+ this.y = Math.round( this.y );
2058
+ this.z = Math.round( this.z );
2059
+
2060
+ return this;
2061
+
2062
+ },
2063
+
2064
+ roundToZero: function () {
2065
+
2066
+ this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
2067
+ this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
2068
+ this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
2069
+
2070
+ return this;
2071
+
2072
+ },
2073
+
2074
+ negate: function () {
2075
+
2076
+ this.x = - this.x;
2077
+ this.y = - this.y;
2078
+ this.z = - this.z;
2079
+
2080
+ return this;
2081
+
2082
+ },
2083
+
2084
+ dot: function ( v ) {
2085
+
2086
+ return this.x * v.x + this.y * v.y + this.z * v.z;
2087
+
2088
+ },
2089
+
2090
+ lengthSq: function () {
2091
+
2092
+ return this.x * this.x + this.y * this.y + this.z * this.z;
2093
+
2094
+ },
2095
+
2096
+ length: function () {
2097
+
2098
+ return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
2099
+
2100
+ },
2101
+
2102
+ lengthManhattan: function () {
2103
+
2104
+ return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z );
2105
+
2106
+ },
2107
+
2108
+ normalize: function () {
2109
+
2110
+ return this.divideScalar( this.length() );
2111
+
2112
+ },
2113
+
2114
+ setLength: function ( l ) {
2115
+
2116
+ var oldLength = this.length();
2117
+
2118
+ if ( oldLength !== 0 && l !== oldLength ) {
2119
+
2120
+ this.multiplyScalar( l / oldLength );
2121
+ }
2122
+
2123
+ return this;
2124
+
2125
+ },
2126
+
2127
+ lerp: function ( v, alpha ) {
2128
+
2129
+ this.x += ( v.x - this.x ) * alpha;
2130
+ this.y += ( v.y - this.y ) * alpha;
2131
+ this.z += ( v.z - this.z ) * alpha;
2132
+
2133
+ return this;
2134
+
2135
+ },
2136
+
2137
+ cross: function ( v, w ) {
2138
+
2139
+ if ( w !== undefined ) {
2140
+
2141
+ console.warn( 'THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.' );
2142
+ return this.crossVectors( v, w );
2143
+
2144
+ }
2145
+
2146
+ var x = this.x, y = this.y, z = this.z;
2147
+
2148
+ this.x = y * v.z - z * v.y;
2149
+ this.y = z * v.x - x * v.z;
2150
+ this.z = x * v.y - y * v.x;
2151
+
2152
+ return this;
2153
+
2154
+ },
2155
+
2156
+ crossVectors: function ( a, b ) {
2157
+
2158
+ var ax = a.x, ay = a.y, az = a.z;
2159
+ var bx = b.x, by = b.y, bz = b.z;
2160
+
2161
+ this.x = ay * bz - az * by;
2162
+ this.y = az * bx - ax * bz;
2163
+ this.z = ax * by - ay * bx;
2164
+
2165
+ return this;
2166
+
2167
+ },
2168
+
2169
+ projectOnVector: function () {
2170
+
2171
+ var v1, dot;
2172
+
2173
+ return function ( vector ) {
2174
+
2175
+ if ( v1 === undefined ) v1 = new THREE.Vector3();
2176
+
2177
+ v1.copy( vector ).normalize();
2178
+
2179
+ dot = this.dot( v1 );
2180
+
2181
+ return this.copy( v1 ).multiplyScalar( dot );
2182
+
2183
+ };
2184
+
2185
+ }(),
2186
+
2187
+ projectOnPlane: function () {
2188
+
2189
+ var v1;
2190
+
2191
+ return function ( planeNormal ) {
2192
+
2193
+ if ( v1 === undefined ) v1 = new THREE.Vector3();
2194
+
2195
+ v1.copy( this ).projectOnVector( planeNormal );
2196
+
2197
+ return this.sub( v1 );
2198
+
2199
+ }
2200
+
2201
+ }(),
2202
+
2203
+ reflect: function () {
2204
+
2205
+ // reflect incident vector off plane orthogonal to normal
2206
+ // normal is assumed to have unit length
2207
+
2208
+ var v1;
2209
+
2210
+ return function ( normal ) {
2211
+
2212
+ if ( v1 === undefined ) v1 = new THREE.Vector3();
2213
+
2214
+ return this.sub( v1.copy( normal ).multiplyScalar( 2 * this.dot( normal ) ) );
2215
+
2216
+ }
2217
+
2218
+ }(),
2219
+
2220
+ angleTo: function ( v ) {
2221
+
2222
+ var theta = this.dot( v ) / ( this.length() * v.length() );
2223
+
2224
+ // clamp, to handle numerical problems
2225
+
2226
+ return Math.acos( THREE.Math.clamp( theta, - 1, 1 ) );
2227
+
2228
+ },
2229
+
2230
+ distanceTo: function ( v ) {
2231
+
2232
+ return Math.sqrt( this.distanceToSquared( v ) );
2233
+
2234
+ },
2235
+
2236
+ distanceToSquared: function ( v ) {
2237
+
2238
+ var dx = this.x - v.x;
2239
+ var dy = this.y - v.y;
2240
+ var dz = this.z - v.z;
2241
+
2242
+ return dx * dx + dy * dy + dz * dz;
2243
+
2244
+ },
2245
+
2246
+ setEulerFromRotationMatrix: function ( m, order ) {
2247
+
2248
+ console.error( 'THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.' );
2249
+
2250
+ },
2251
+
2252
+ setEulerFromQuaternion: function ( q, order ) {
2253
+
2254
+ console.error( 'THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.' );
2255
+
2256
+ },
2257
+
2258
+ getPositionFromMatrix: function ( m ) {
2259
+
2260
+ console.warn( 'THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().' );
2261
+
2262
+ return this.setFromMatrixPosition( m );
2263
+
2264
+ },
2265
+
2266
+ getScaleFromMatrix: function ( m ) {
2267
+
2268
+ console.warn( 'THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().' );
2269
+
2270
+ return this.setFromMatrixScale( m );
2271
+ },
2272
+
2273
+ getColumnFromMatrix: function ( index, matrix ) {
2274
+
2275
+ console.warn( 'THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().' );
2276
+
2277
+ return this.setFromMatrixColumn( index, matrix );
2278
+
2279
+ },
2280
+
2281
+ setFromMatrixPosition: function ( m ) {
2282
+
2283
+ this.x = m.elements[ 12 ];
2284
+ this.y = m.elements[ 13 ];
2285
+ this.z = m.elements[ 14 ];
2286
+
2287
+ return this;
2288
+
2289
+ },
2290
+
2291
+ setFromMatrixScale: function ( m ) {
2292
+
2293
+ var sx = this.set( m.elements[ 0 ], m.elements[ 1 ], m.elements[ 2 ] ).length();
2294
+ var sy = this.set( m.elements[ 4 ], m.elements[ 5 ], m.elements[ 6 ] ).length();
2295
+ var sz = this.set( m.elements[ 8 ], m.elements[ 9 ], m.elements[ 10 ] ).length();
2296
+
2297
+ this.x = sx;
2298
+ this.y = sy;
2299
+ this.z = sz;
2300
+
2301
+ return this;
2302
+ },
2303
+
2304
+ setFromMatrixColumn: function ( index, matrix ) {
2305
+
2306
+ var offset = index * 4;
2307
+
2308
+ var me = matrix.elements;
2309
+
2310
+ this.x = me[ offset ];
2311
+ this.y = me[ offset + 1 ];
2312
+ this.z = me[ offset + 2 ];
2313
+
2314
+ return this;
2315
+
2316
+ },
2317
+
2318
+ equals: function ( v ) {
2319
+
2320
+ return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) );
2321
+
2322
+ },
2323
+
2324
+ fromArray: function ( array, offset ) {
2325
+
2326
+ if ( offset === undefined ) offset = 0;
2327
+
2328
+ this.x = array[ offset ];
2329
+ this.y = array[ offset + 1 ];
2330
+ this.z = array[ offset + 2 ];
2331
+
2332
+ return this;
2333
+
2334
+ },
2335
+
2336
+ toArray: function ( array, offset ) {
2337
+
2338
+ if ( array === undefined ) array = [];
2339
+ if ( offset === undefined ) offset = 0;
2340
+
2341
+ array[ offset ] = this.x;
2342
+ array[ offset + 1 ] = this.y;
2343
+ array[ offset + 2 ] = this.z;
2344
+
2345
+ return array;
2346
+
2347
+ },
2348
+
2349
+ clone: function () {
2350
+
2351
+ return new THREE.Vector3( this.x, this.y, this.z );
2352
+
2353
+ }
2354
+
2355
+ };
2356
+
2357
+ // File:src/math/Vector4.js
2358
+
2359
+ /**
2360
+ * @author supereggbert / http://www.paulbrunt.co.uk/
2361
+ * @author philogb / http://blog.thejit.org/
2362
+ * @author mikael emtinger / http://gomo.se/
2363
+ * @author egraether / http://egraether.com/
2364
+ * @author WestLangley / http://github.com/WestLangley
2365
+ */
2366
+
2367
+ THREE.Vector4 = function ( x, y, z, w ) {
2368
+
2369
+ this.x = x || 0;
2370
+ this.y = y || 0;
2371
+ this.z = z || 0;
2372
+ this.w = ( w !== undefined ) ? w : 1;
2373
+
2374
+ };
2375
+
2376
+ THREE.Vector4.prototype = {
2377
+
2378
+ constructor: THREE.Vector4,
2379
+
2380
+ set: function ( x, y, z, w ) {
2381
+
2382
+ this.x = x;
2383
+ this.y = y;
2384
+ this.z = z;
2385
+ this.w = w;
2386
+
2387
+ return this;
2388
+
2389
+ },
2390
+
2391
+ setX: function ( x ) {
2392
+
2393
+ this.x = x;
2394
+
2395
+ return this;
2396
+
2397
+ },
2398
+
2399
+ setY: function ( y ) {
2400
+
2401
+ this.y = y;
2402
+
2403
+ return this;
2404
+
2405
+ },
2406
+
2407
+ setZ: function ( z ) {
2408
+
2409
+ this.z = z;
2410
+
2411
+ return this;
2412
+
2413
+ },
2414
+
2415
+ setW: function ( w ) {
2416
+
2417
+ this.w = w;
2418
+
2419
+ return this;
2420
+
2421
+ },
2422
+
2423
+ setComponent: function ( index, value ) {
2424
+
2425
+ switch ( index ) {
2426
+
2427
+ case 0: this.x = value; break;
2428
+ case 1: this.y = value; break;
2429
+ case 2: this.z = value; break;
2430
+ case 3: this.w = value; break;
2431
+ default: throw new Error( 'index is out of range: ' + index );
2432
+
2433
+ }
2434
+
2435
+ },
2436
+
2437
+ getComponent: function ( index ) {
2438
+
2439
+ switch ( index ) {
2440
+
2441
+ case 0: return this.x;
2442
+ case 1: return this.y;
2443
+ case 2: return this.z;
2444
+ case 3: return this.w;
2445
+ default: throw new Error( 'index is out of range: ' + index );
2446
+
2447
+ }
2448
+
2449
+ },
2450
+
2451
+ copy: function ( v ) {
2452
+
2453
+ this.x = v.x;
2454
+ this.y = v.y;
2455
+ this.z = v.z;
2456
+ this.w = ( v.w !== undefined ) ? v.w : 1;
2457
+
2458
+ return this;
2459
+
2460
+ },
2461
+
2462
+ add: function ( v, w ) {
2463
+
2464
+ if ( w !== undefined ) {
2465
+
2466
+ console.warn( 'THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
2467
+ return this.addVectors( v, w );
2468
+
2469
+ }
2470
+
2471
+ this.x += v.x;
2472
+ this.y += v.y;
2473
+ this.z += v.z;
2474
+ this.w += v.w;
2475
+
2476
+ return this;
2477
+
2478
+ },
2479
+
2480
+ addScalar: function ( s ) {
2481
+
2482
+ this.x += s;
2483
+ this.y += s;
2484
+ this.z += s;
2485
+ this.w += s;
2486
+
2487
+ return this;
2488
+
2489
+ },
2490
+
2491
+ addVectors: function ( a, b ) {
2492
+
2493
+ this.x = a.x + b.x;
2494
+ this.y = a.y + b.y;
2495
+ this.z = a.z + b.z;
2496
+ this.w = a.w + b.w;
2497
+
2498
+ return this;
2499
+
2500
+ },
2501
+
2502
+ sub: function ( v, w ) {
2503
+
2504
+ if ( w !== undefined ) {
2505
+
2506
+ console.warn( 'THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
2507
+ return this.subVectors( v, w );
2508
+
2509
+ }
2510
+
2511
+ this.x -= v.x;
2512
+ this.y -= v.y;
2513
+ this.z -= v.z;
2514
+ this.w -= v.w;
2515
+
2516
+ return this;
2517
+
2518
+ },
2519
+
2520
+ subVectors: function ( a, b ) {
2521
+
2522
+ this.x = a.x - b.x;
2523
+ this.y = a.y - b.y;
2524
+ this.z = a.z - b.z;
2525
+ this.w = a.w - b.w;
2526
+
2527
+ return this;
2528
+
2529
+ },
2530
+
2531
+ multiplyScalar: function ( scalar ) {
2532
+
2533
+ this.x *= scalar;
2534
+ this.y *= scalar;
2535
+ this.z *= scalar;
2536
+ this.w *= scalar;
2537
+
2538
+ return this;
2539
+
2540
+ },
2541
+
2542
+ applyMatrix4: function ( m ) {
2543
+
2544
+ var x = this.x;
2545
+ var y = this.y;
2546
+ var z = this.z;
2547
+ var w = this.w;
2548
+
2549
+ var e = m.elements;
2550
+
2551
+ this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] * w;
2552
+ this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] * w;
2553
+ this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] * w;
2554
+ this.w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] * w;
2555
+
2556
+ return this;
2557
+
2558
+ },
2559
+
2560
+ divideScalar: function ( scalar ) {
2561
+
2562
+ if ( scalar !== 0 ) {
2563
+
2564
+ var invScalar = 1 / scalar;
2565
+
2566
+ this.x *= invScalar;
2567
+ this.y *= invScalar;
2568
+ this.z *= invScalar;
2569
+ this.w *= invScalar;
2570
+
2571
+ } else {
2572
+
2573
+ this.x = 0;
2574
+ this.y = 0;
2575
+ this.z = 0;
2576
+ this.w = 1;
2577
+
2578
+ }
2579
+
2580
+ return this;
2581
+
2582
+ },
2583
+
2584
+ setAxisAngleFromQuaternion: function ( q ) {
2585
+
2586
+ // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
2587
+
2588
+ // q is assumed to be normalized
2589
+
2590
+ this.w = 2 * Math.acos( q.w );
2591
+
2592
+ var s = Math.sqrt( 1 - q.w * q.w );
2593
+
2594
+ if ( s < 0.0001 ) {
2595
+
2596
+ this.x = 1;
2597
+ this.y = 0;
2598
+ this.z = 0;
2599
+
2600
+ } else {
2601
+
2602
+ this.x = q.x / s;
2603
+ this.y = q.y / s;
2604
+ this.z = q.z / s;
2605
+
2606
+ }
2607
+
2608
+ return this;
2609
+
2610
+ },
2611
+
2612
+ setAxisAngleFromRotationMatrix: function ( m ) {
2613
+
2614
+ // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
2615
+
2616
+ // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
2617
+
2618
+ var angle, x, y, z, // variables for result
2619
+ epsilon = 0.01, // margin to allow for rounding errors
2620
+ epsilon2 = 0.1, // margin to distinguish between 0 and 180 degrees
2621
+
2622
+ te = m.elements,
2623
+
2624
+ m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
2625
+ m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
2626
+ m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
2627
+
2628
+ if ( ( Math.abs( m12 - m21 ) < epsilon )
2629
+ && ( Math.abs( m13 - m31 ) < epsilon )
2630
+ && ( Math.abs( m23 - m32 ) < epsilon ) ) {
2631
+
2632
+ // singularity found
2633
+ // first check for identity matrix which must have +1 for all terms
2634
+ // in leading diagonal and zero in other terms
2635
+
2636
+ if ( ( Math.abs( m12 + m21 ) < epsilon2 )
2637
+ && ( Math.abs( m13 + m31 ) < epsilon2 )
2638
+ && ( Math.abs( m23 + m32 ) < epsilon2 )
2639
+ && ( Math.abs( m11 + m22 + m33 - 3 ) < epsilon2 ) ) {
2640
+
2641
+ // this singularity is identity matrix so angle = 0
2642
+
2643
+ this.set( 1, 0, 0, 0 );
2644
+
2645
+ return this; // zero angle, arbitrary axis
2646
+
2647
+ }
2648
+
2649
+ // otherwise this singularity is angle = 180
2650
+
2651
+ angle = Math.PI;
2652
+
2653
+ var xx = ( m11 + 1 ) / 2;
2654
+ var yy = ( m22 + 1 ) / 2;
2655
+ var zz = ( m33 + 1 ) / 2;
2656
+ var xy = ( m12 + m21 ) / 4;
2657
+ var xz = ( m13 + m31 ) / 4;
2658
+ var yz = ( m23 + m32 ) / 4;
2659
+
2660
+ if ( ( xx > yy ) && ( xx > zz ) ) { // m11 is the largest diagonal term
2661
+
2662
+ if ( xx < epsilon ) {
2663
+
2664
+ x = 0;
2665
+ y = 0.707106781;
2666
+ z = 0.707106781;
2667
+
2668
+ } else {
2669
+
2670
+ x = Math.sqrt( xx );
2671
+ y = xy / x;
2672
+ z = xz / x;
2673
+
2674
+ }
2675
+
2676
+ } else if ( yy > zz ) { // m22 is the largest diagonal term
2677
+
2678
+ if ( yy < epsilon ) {
2679
+
2680
+ x = 0.707106781;
2681
+ y = 0;
2682
+ z = 0.707106781;
2683
+
2684
+ } else {
2685
+
2686
+ y = Math.sqrt( yy );
2687
+ x = xy / y;
2688
+ z = yz / y;
2689
+
2690
+ }
2691
+
2692
+ } else { // m33 is the largest diagonal term so base result on this
2693
+
2694
+ if ( zz < epsilon ) {
2695
+
2696
+ x = 0.707106781;
2697
+ y = 0.707106781;
2698
+ z = 0;
2699
+
2700
+ } else {
2701
+
2702
+ z = Math.sqrt( zz );
2703
+ x = xz / z;
2704
+ y = yz / z;
2705
+
2706
+ }
2707
+
2708
+ }
2709
+
2710
+ this.set( x, y, z, angle );
2711
+
2712
+ return this; // return 180 deg rotation
2713
+
2714
+ }
2715
+
2716
+ // as we have reached here there are no singularities so we can handle normally
2717
+
2718
+ var s = Math.sqrt( ( m32 - m23 ) * ( m32 - m23 )
2719
+ + ( m13 - m31 ) * ( m13 - m31 )
2720
+ + ( m21 - m12 ) * ( m21 - m12 ) ); // used to normalize
2721
+
2722
+ if ( Math.abs( s ) < 0.001 ) s = 1;
2723
+
2724
+ // prevent divide by zero, should not happen if matrix is orthogonal and should be
2725
+ // caught by singularity test above, but I've left it in just in case
2726
+
2727
+ this.x = ( m32 - m23 ) / s;
2728
+ this.y = ( m13 - m31 ) / s;
2729
+ this.z = ( m21 - m12 ) / s;
2730
+ this.w = Math.acos( ( m11 + m22 + m33 - 1 ) / 2 );
2731
+
2732
+ return this;
2733
+
2734
+ },
2735
+
2736
+ min: function ( v ) {
2737
+
2738
+ if ( this.x > v.x ) {
2739
+
2740
+ this.x = v.x;
2741
+
2742
+ }
2743
+
2744
+ if ( this.y > v.y ) {
2745
+
2746
+ this.y = v.y;
2747
+
2748
+ }
2749
+
2750
+ if ( this.z > v.z ) {
2751
+
2752
+ this.z = v.z;
2753
+
2754
+ }
2755
+
2756
+ if ( this.w > v.w ) {
2757
+
2758
+ this.w = v.w;
2759
+
2760
+ }
2761
+
2762
+ return this;
2763
+
2764
+ },
2765
+
2766
+ max: function ( v ) {
2767
+
2768
+ if ( this.x < v.x ) {
2769
+
2770
+ this.x = v.x;
2771
+
2772
+ }
2773
+
2774
+ if ( this.y < v.y ) {
2775
+
2776
+ this.y = v.y;
2777
+
2778
+ }
2779
+
2780
+ if ( this.z < v.z ) {
2781
+
2782
+ this.z = v.z;
2783
+
2784
+ }
2785
+
2786
+ if ( this.w < v.w ) {
2787
+
2788
+ this.w = v.w;
2789
+
2790
+ }
2791
+
2792
+ return this;
2793
+
2794
+ },
2795
+
2796
+ clamp: function ( min, max ) {
2797
+
2798
+ // This function assumes min < max, if this assumption isn't true it will not operate correctly
2799
+
2800
+ if ( this.x < min.x ) {
2801
+
2802
+ this.x = min.x;
2803
+
2804
+ } else if ( this.x > max.x ) {
2805
+
2806
+ this.x = max.x;
2807
+
2808
+ }
2809
+
2810
+ if ( this.y < min.y ) {
2811
+
2812
+ this.y = min.y;
2813
+
2814
+ } else if ( this.y > max.y ) {
2815
+
2816
+ this.y = max.y;
2817
+
2818
+ }
2819
+
2820
+ if ( this.z < min.z ) {
2821
+
2822
+ this.z = min.z;
2823
+
2824
+ } else if ( this.z > max.z ) {
2825
+
2826
+ this.z = max.z;
2827
+
2828
+ }
2829
+
2830
+ if ( this.w < min.w ) {
2831
+
2832
+ this.w = min.w;
2833
+
2834
+ } else if ( this.w > max.w ) {
2835
+
2836
+ this.w = max.w;
2837
+
2838
+ }
2839
+
2840
+ return this;
2841
+
2842
+ },
2843
+
2844
+ clampScalar: ( function () {
2845
+
2846
+ var min, max;
2847
+
2848
+ return function ( minVal, maxVal ) {
2849
+
2850
+ if ( min === undefined ) {
2851
+
2852
+ min = new THREE.Vector4();
2853
+ max = new THREE.Vector4();
2854
+
2855
+ }
2856
+
2857
+ min.set( minVal, minVal, minVal, minVal );
2858
+ max.set( maxVal, maxVal, maxVal, maxVal );
2859
+
2860
+ return this.clamp( min, max );
2861
+
2862
+ };
2863
+
2864
+ } )(),
2865
+
2866
+ floor: function () {
2867
+
2868
+ this.x = Math.floor( this.x );
2869
+ this.y = Math.floor( this.y );
2870
+ this.z = Math.floor( this.z );
2871
+ this.w = Math.floor( this.w );
2872
+
2873
+ return this;
2874
+
2875
+ },
2876
+
2877
+ ceil: function () {
2878
+
2879
+ this.x = Math.ceil( this.x );
2880
+ this.y = Math.ceil( this.y );
2881
+ this.z = Math.ceil( this.z );
2882
+ this.w = Math.ceil( this.w );
2883
+
2884
+ return this;
2885
+
2886
+ },
2887
+
2888
+ round: function () {
2889
+
2890
+ this.x = Math.round( this.x );
2891
+ this.y = Math.round( this.y );
2892
+ this.z = Math.round( this.z );
2893
+ this.w = Math.round( this.w );
2894
+
2895
+ return this;
2896
+
2897
+ },
2898
+
2899
+ roundToZero: function () {
2900
+
2901
+ this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
2902
+ this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
2903
+ this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
2904
+ this.w = ( this.w < 0 ) ? Math.ceil( this.w ) : Math.floor( this.w );
2905
+
2906
+ return this;
2907
+
2908
+ },
2909
+
2910
+ negate: function () {
2911
+
2912
+ this.x = - this.x;
2913
+ this.y = - this.y;
2914
+ this.z = - this.z;
2915
+ this.w = - this.w;
2916
+
2917
+ return this;
2918
+
2919
+ },
2920
+
2921
+ dot: function ( v ) {
2922
+
2923
+ return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
2924
+
2925
+ },
2926
+
2927
+ lengthSq: function () {
2928
+
2929
+ return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
2930
+
2931
+ },
2932
+
2933
+ length: function () {
2934
+
2935
+ return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
2936
+
2937
+ },
2938
+
2939
+ lengthManhattan: function () {
2940
+
2941
+ return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w );
2942
+
2943
+ },
2944
+
2945
+ normalize: function () {
2946
+
2947
+ return this.divideScalar( this.length() );
2948
+
2949
+ },
2950
+
2951
+ setLength: function ( l ) {
2952
+
2953
+ var oldLength = this.length();
2954
+
2955
+ if ( oldLength !== 0 && l !== oldLength ) {
2956
+
2957
+ this.multiplyScalar( l / oldLength );
2958
+
2959
+ }
2960
+
2961
+ return this;
2962
+
2963
+ },
2964
+
2965
+ lerp: function ( v, alpha ) {
2966
+
2967
+ this.x += ( v.x - this.x ) * alpha;
2968
+ this.y += ( v.y - this.y ) * alpha;
2969
+ this.z += ( v.z - this.z ) * alpha;
2970
+ this.w += ( v.w - this.w ) * alpha;
2971
+
2972
+ return this;
2973
+
2974
+ },
2975
+
2976
+ equals: function ( v ) {
2977
+
2978
+ return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) && ( v.w === this.w ) );
2979
+
2980
+ },
2981
+
2982
+ fromArray: function ( array, offset ) {
2983
+
2984
+ if ( offset === undefined ) offset = 0;
2985
+
2986
+ this.x = array[ offset ];
2987
+ this.y = array[ offset + 1 ];
2988
+ this.z = array[ offset + 2 ];
2989
+ this.w = array[ offset + 3 ];
2990
+
2991
+ return this;
2992
+
2993
+ },
2994
+
2995
+ toArray: function ( array, offset ) {
2996
+
2997
+ if ( array === undefined ) array = [];
2998
+ if ( offset === undefined ) offset = 0;
2999
+
3000
+ array[ offset ] = this.x;
3001
+ array[ offset + 1 ] = this.y;
3002
+ array[ offset + 2 ] = this.z;
3003
+ array[ offset + 3 ] = this.w;
3004
+
3005
+ return array;
3006
+
3007
+ },
3008
+
3009
+ clone: function () {
3010
+
3011
+ return new THREE.Vector4( this.x, this.y, this.z, this.w );
3012
+
3013
+ }
3014
+
3015
+ };
3016
+
3017
+ // File:src/math/Euler.js
3018
+
3019
+ /**
3020
+ * @author mrdoob / http://mrdoob.com/
3021
+ * @author WestLangley / http://github.com/WestLangley
3022
+ * @author bhouston / http://exocortex.com
3023
+ */
3024
+
3025
+ THREE.Euler = function ( x, y, z, order ) {
3026
+
3027
+ this._x = x || 0;
3028
+ this._y = y || 0;
3029
+ this._z = z || 0;
3030
+ this._order = order || THREE.Euler.DefaultOrder;
3031
+
3032
+ };
3033
+
3034
+ THREE.Euler.RotationOrders = [ 'XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX' ];
3035
+
3036
+ THREE.Euler.DefaultOrder = 'XYZ';
3037
+
3038
+ THREE.Euler.prototype = {
3039
+
3040
+ constructor: THREE.Euler,
3041
+
3042
+ _x: 0, _y: 0, _z: 0, _order: THREE.Euler.DefaultOrder,
3043
+
3044
+ get x () {
3045
+
3046
+ return this._x;
3047
+
3048
+ },
3049
+
3050
+ set x ( value ) {
3051
+
3052
+ this._x = value;
3053
+ this.onChangeCallback();
3054
+
3055
+ },
3056
+
3057
+ get y () {
3058
+
3059
+ return this._y;
3060
+
3061
+ },
3062
+
3063
+ set y ( value ) {
3064
+
3065
+ this._y = value;
3066
+ this.onChangeCallback();
3067
+
3068
+ },
3069
+
3070
+ get z () {
3071
+
3072
+ return this._z;
3073
+
3074
+ },
3075
+
3076
+ set z ( value ) {
3077
+
3078
+ this._z = value;
3079
+ this.onChangeCallback();
3080
+
3081
+ },
3082
+
3083
+ get order () {
3084
+
3085
+ return this._order;
3086
+
3087
+ },
3088
+
3089
+ set order ( value ) {
3090
+
3091
+ this._order = value;
3092
+ this.onChangeCallback();
3093
+
3094
+ },
3095
+
3096
+ set: function ( x, y, z, order ) {
3097
+
3098
+ this._x = x;
3099
+ this._y = y;
3100
+ this._z = z;
3101
+ this._order = order || this._order;
3102
+
3103
+ this.onChangeCallback();
3104
+
3105
+ return this;
3106
+
3107
+ },
3108
+
3109
+ copy: function ( euler ) {
3110
+
3111
+ this._x = euler._x;
3112
+ this._y = euler._y;
3113
+ this._z = euler._z;
3114
+ this._order = euler._order;
3115
+
3116
+ this.onChangeCallback();
3117
+
3118
+ return this;
3119
+
3120
+ },
3121
+
3122
+ setFromRotationMatrix: function ( m, order ) {
3123
+
3124
+ var clamp = THREE.Math.clamp;
3125
+
3126
+ // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
3127
+
3128
+ var te = m.elements;
3129
+ var m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ];
3130
+ var m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ];
3131
+ var m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
3132
+
3133
+ order = order || this._order;
3134
+
3135
+ if ( order === 'XYZ' ) {
3136
+
3137
+ this._y = Math.asin( clamp( m13, - 1, 1 ) );
3138
+
3139
+ if ( Math.abs( m13 ) < 0.99999 ) {
3140
+
3141
+ this._x = Math.atan2( - m23, m33 );
3142
+ this._z = Math.atan2( - m12, m11 );
3143
+
3144
+ } else {
3145
+
3146
+ this._x = Math.atan2( m32, m22 );
3147
+ this._z = 0;
3148
+
3149
+ }
3150
+
3151
+ } else if ( order === 'YXZ' ) {
3152
+
3153
+ this._x = Math.asin( - clamp( m23, - 1, 1 ) );
3154
+
3155
+ if ( Math.abs( m23 ) < 0.99999 ) {
3156
+
3157
+ this._y = Math.atan2( m13, m33 );
3158
+ this._z = Math.atan2( m21, m22 );
3159
+
3160
+ } else {
3161
+
3162
+ this._y = Math.atan2( - m31, m11 );
3163
+ this._z = 0;
3164
+
3165
+ }
3166
+
3167
+ } else if ( order === 'ZXY' ) {
3168
+
3169
+ this._x = Math.asin( clamp( m32, - 1, 1 ) );
3170
+
3171
+ if ( Math.abs( m32 ) < 0.99999 ) {
3172
+
3173
+ this._y = Math.atan2( - m31, m33 );
3174
+ this._z = Math.atan2( - m12, m22 );
3175
+
3176
+ } else {
3177
+
3178
+ this._y = 0;
3179
+ this._z = Math.atan2( m21, m11 );
3180
+
3181
+ }
3182
+
3183
+ } else if ( order === 'ZYX' ) {
3184
+
3185
+ this._y = Math.asin( - clamp( m31, - 1, 1 ) );
3186
+
3187
+ if ( Math.abs( m31 ) < 0.99999 ) {
3188
+
3189
+ this._x = Math.atan2( m32, m33 );
3190
+ this._z = Math.atan2( m21, m11 );
3191
+
3192
+ } else {
3193
+
3194
+ this._x = 0;
3195
+ this._z = Math.atan2( - m12, m22 );
3196
+
3197
+ }
3198
+
3199
+ } else if ( order === 'YZX' ) {
3200
+
3201
+ this._z = Math.asin( clamp( m21, - 1, 1 ) );
3202
+
3203
+ if ( Math.abs( m21 ) < 0.99999 ) {
3204
+
3205
+ this._x = Math.atan2( - m23, m22 );
3206
+ this._y = Math.atan2( - m31, m11 );
3207
+
3208
+ } else {
3209
+
3210
+ this._x = 0;
3211
+ this._y = Math.atan2( m13, m33 );
3212
+
3213
+ }
3214
+
3215
+ } else if ( order === 'XZY' ) {
3216
+
3217
+ this._z = Math.asin( - clamp( m12, - 1, 1 ) );
3218
+
3219
+ if ( Math.abs( m12 ) < 0.99999 ) {
3220
+
3221
+ this._x = Math.atan2( m32, m22 );
3222
+ this._y = Math.atan2( m13, m11 );
3223
+
3224
+ } else {
3225
+
3226
+ this._x = Math.atan2( - m23, m33 );
3227
+ this._y = 0;
3228
+
3229
+ }
3230
+
3231
+ } else {
3232
+
3233
+ console.warn( 'THREE.Euler: .setFromRotationMatrix() given unsupported order: ' + order )
3234
+
3235
+ }
3236
+
3237
+ this._order = order;
3238
+
3239
+ this.onChangeCallback();
3240
+
3241
+ return this;
3242
+
3243
+ },
3244
+
3245
+ setFromQuaternion: function ( q, order, update ) {
3246
+
3247
+ var clamp = THREE.Math.clamp;
3248
+
3249
+ // q is assumed to be normalized
3250
+
3251
+ // http://www.mathworks.com/matlabcentral/fileexchange/20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/content/SpinCalc.m
3252
+
3253
+ var sqx = q.x * q.x;
3254
+ var sqy = q.y * q.y;
3255
+ var sqz = q.z * q.z;
3256
+ var sqw = q.w * q.w;
3257
+
3258
+ order = order || this._order;
3259
+
3260
+ if ( order === 'XYZ' ) {
3261
+
3262
+ this._x = Math.atan2( 2 * ( q.x * q.w - q.y * q.z ), ( sqw - sqx - sqy + sqz ) );
3263
+ this._y = Math.asin( clamp( 2 * ( q.x * q.z + q.y * q.w ), - 1, 1 ) );
3264
+ this._z = Math.atan2( 2 * ( q.z * q.w - q.x * q.y ), ( sqw + sqx - sqy - sqz ) );
3265
+
3266
+ } else if ( order === 'YXZ' ) {
3267
+
3268
+ this._x = Math.asin( clamp( 2 * ( q.x * q.w - q.y * q.z ), - 1, 1 ) );
3269
+ this._y = Math.atan2( 2 * ( q.x * q.z + q.y * q.w ), ( sqw - sqx - sqy + sqz ) );
3270
+ this._z = Math.atan2( 2 * ( q.x * q.y + q.z * q.w ), ( sqw - sqx + sqy - sqz ) );
3271
+
3272
+ } else if ( order === 'ZXY' ) {
3273
+
3274
+ this._x = Math.asin( clamp( 2 * ( q.x * q.w + q.y * q.z ), - 1, 1 ) );
3275
+ this._y = Math.atan2( 2 * ( q.y * q.w - q.z * q.x ), ( sqw - sqx - sqy + sqz ) );
3276
+ this._z = Math.atan2( 2 * ( q.z * q.w - q.x * q.y ), ( sqw - sqx + sqy - sqz ) );
3277
+
3278
+ } else if ( order === 'ZYX' ) {
3279
+
3280
+ this._x = Math.atan2( 2 * ( q.x * q.w + q.z * q.y ), ( sqw - sqx - sqy + sqz ) );
3281
+ this._y = Math.asin( clamp( 2 * ( q.y * q.w - q.x * q.z ), - 1, 1 ) );
3282
+ this._z = Math.atan2( 2 * ( q.x * q.y + q.z * q.w ), ( sqw + sqx - sqy - sqz ) );
3283
+
3284
+ } else if ( order === 'YZX' ) {
3285
+
3286
+ this._x = Math.atan2( 2 * ( q.x * q.w - q.z * q.y ), ( sqw - sqx + sqy - sqz ) );
3287
+ this._y = Math.atan2( 2 * ( q.y * q.w - q.x * q.z ), ( sqw + sqx - sqy - sqz ) );
3288
+ this._z = Math.asin( clamp( 2 * ( q.x * q.y + q.z * q.w ), - 1, 1 ) );
3289
+
3290
+ } else if ( order === 'XZY' ) {
3291
+
3292
+ this._x = Math.atan2( 2 * ( q.x * q.w + q.y * q.z ), ( sqw - sqx + sqy - sqz ) );
3293
+ this._y = Math.atan2( 2 * ( q.x * q.z + q.y * q.w ), ( sqw + sqx - sqy - sqz ) );
3294
+ this._z = Math.asin( clamp( 2 * ( q.z * q.w - q.x * q.y ), - 1, 1 ) );
3295
+
3296
+ } else {
3297
+
3298
+ console.warn( 'THREE.Euler: .setFromQuaternion() given unsupported order: ' + order )
3299
+
3300
+ }
3301
+
3302
+ this._order = order;
3303
+
3304
+ if ( update !== false ) this.onChangeCallback();
3305
+
3306
+ return this;
3307
+
3308
+ },
3309
+
3310
+ reorder: function () {
3311
+
3312
+ // WARNING: this discards revolution information -bhouston
3313
+
3314
+ var q = new THREE.Quaternion();
3315
+
3316
+ return function ( newOrder ) {
3317
+
3318
+ q.setFromEuler( this );
3319
+ this.setFromQuaternion( q, newOrder );
3320
+
3321
+ };
3322
+
3323
+
3324
+ }(),
3325
+
3326
+ equals: function ( euler ) {
3327
+
3328
+ return ( euler._x === this._x ) && ( euler._y === this._y ) && ( euler._z === this._z ) && ( euler._order === this._order );
3329
+
3330
+ },
3331
+
3332
+ fromArray: function ( array ) {
3333
+
3334
+ this._x = array[ 0 ];
3335
+ this._y = array[ 1 ];
3336
+ this._z = array[ 2 ];
3337
+ if ( array[ 3 ] !== undefined ) this._order = array[ 3 ];
3338
+
3339
+ this.onChangeCallback();
3340
+
3341
+ return this;
3342
+
3343
+ },
3344
+
3345
+ toArray: function () {
3346
+
3347
+ return [ this._x, this._y, this._z, this._order ];
3348
+
3349
+ },
3350
+
3351
+ onChange: function ( callback ) {
3352
+
3353
+ this.onChangeCallback = callback;
3354
+
3355
+ return this;
3356
+
3357
+ },
3358
+
3359
+ onChangeCallback: function () {},
3360
+
3361
+ clone: function () {
3362
+
3363
+ return new THREE.Euler( this._x, this._y, this._z, this._order );
3364
+
3365
+ }
3366
+
3367
+ };
3368
+
3369
+ // File:src/math/Box3.js
3370
+
3371
+ /**
3372
+ * @author bhouston / http://exocortex.com
3373
+ * @author WestLangley / http://github.com/WestLangley
3374
+ */
3375
+
3376
+ THREE.Box3 = function ( min, max ) {
3377
+
3378
+ this.min = ( min !== undefined ) ? min : new THREE.Vector3( Infinity, Infinity, Infinity );
3379
+ this.max = ( max !== undefined ) ? max : new THREE.Vector3( - Infinity, - Infinity, - Infinity );
3380
+
3381
+ };
3382
+
3383
+ THREE.Box3.prototype = {
3384
+
3385
+ constructor: THREE.Box3,
3386
+
3387
+ set: function ( min, max ) {
3388
+
3389
+ this.min.copy( min );
3390
+ this.max.copy( max );
3391
+
3392
+ return this;
3393
+
3394
+ },
3395
+
3396
+ setFromPoints: function ( points ) {
3397
+
3398
+ this.makeEmpty();
3399
+
3400
+ for ( var i = 0, il = points.length; i < il; i ++ ) {
3401
+
3402
+ this.expandByPoint( points[ i ] )
3403
+
3404
+ }
3405
+
3406
+ return this;
3407
+
3408
+ },
3409
+
3410
+ setFromCenterAndSize: function () {
3411
+
3412
+ var v1 = new THREE.Vector3();
3413
+
3414
+ return function ( center, size ) {
3415
+
3416
+ var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
3417
+
3418
+ this.min.copy( center ).sub( halfSize );
3419
+ this.max.copy( center ).add( halfSize );
3420
+
3421
+ return this;
3422
+
3423
+ };
3424
+
3425
+ }(),
3426
+
3427
+ setFromObject: function () {
3428
+
3429
+ // Computes the world-axis-aligned bounding box of an object (including its children),
3430
+ // accounting for both the object's, and childrens', world transforms
3431
+
3432
+ var v1 = new THREE.Vector3();
3433
+
3434
+ return function ( object ) {
3435
+
3436
+ var scope = this;
3437
+
3438
+ object.updateMatrixWorld( true );
3439
+
3440
+ this.makeEmpty();
3441
+
3442
+ object.traverse( function ( node ) {
3443
+
3444
+ var geometry = node.geometry;
3445
+
3446
+ if ( geometry !== undefined ) {
3447
+
3448
+ if ( geometry instanceof THREE.Geometry ) {
3449
+
3450
+ var vertices = geometry.vertices;
3451
+
3452
+ for ( var i = 0, il = vertices.length; i < il; i ++ ) {
3453
+
3454
+ v1.copy( vertices[ i ] );
3455
+
3456
+ v1.applyMatrix4( node.matrixWorld );
3457
+
3458
+ scope.expandByPoint( v1 );
3459
+
3460
+ }
3461
+
3462
+ } else if ( geometry instanceof THREE.BufferGeometry && geometry.attributes[ 'position' ] !== undefined ) {
3463
+
3464
+ var positions = geometry.attributes[ 'position' ].array;
3465
+
3466
+ for ( var i = 0, il = positions.length; i < il; i += 3 ) {
3467
+
3468
+ v1.set( positions[ i ], positions[ i + 1 ], positions[ i + 2 ] );
3469
+
3470
+ v1.applyMatrix4( node.matrixWorld );
3471
+
3472
+ scope.expandByPoint( v1 );
3473
+
3474
+ }
3475
+
3476
+ }
3477
+
3478
+ }
3479
+
3480
+ } );
3481
+
3482
+ return this;
3483
+
3484
+ };
3485
+
3486
+ }(),
3487
+
3488
+ copy: function ( box ) {
3489
+
3490
+ this.min.copy( box.min );
3491
+ this.max.copy( box.max );
3492
+
3493
+ return this;
3494
+
3495
+ },
3496
+
3497
+ makeEmpty: function () {
3498
+
3499
+ this.min.x = this.min.y = this.min.z = Infinity;
3500
+ this.max.x = this.max.y = this.max.z = - Infinity;
3501
+
3502
+ return this;
3503
+
3504
+ },
3505
+
3506
+ empty: function () {
3507
+
3508
+ // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
3509
+
3510
+ return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ) || ( this.max.z < this.min.z );
3511
+
3512
+ },
3513
+
3514
+ center: function ( optionalTarget ) {
3515
+
3516
+ var result = optionalTarget || new THREE.Vector3();
3517
+ return result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
3518
+
3519
+ },
3520
+
3521
+ size: function ( optionalTarget ) {
3522
+
3523
+ var result = optionalTarget || new THREE.Vector3();
3524
+ return result.subVectors( this.max, this.min );
3525
+
3526
+ },
3527
+
3528
+ expandByPoint: function ( point ) {
3529
+
3530
+ this.min.min( point );
3531
+ this.max.max( point );
3532
+
3533
+ return this;
3534
+
3535
+ },
3536
+
3537
+ expandByVector: function ( vector ) {
3538
+
3539
+ this.min.sub( vector );
3540
+ this.max.add( vector );
3541
+
3542
+ return this;
3543
+
3544
+ },
3545
+
3546
+ expandByScalar: function ( scalar ) {
3547
+
3548
+ this.min.addScalar( - scalar );
3549
+ this.max.addScalar( scalar );
3550
+
3551
+ return this;
3552
+
3553
+ },
3554
+
3555
+ containsPoint: function ( point ) {
3556
+
3557
+ if ( point.x < this.min.x || point.x > this.max.x ||
3558
+ point.y < this.min.y || point.y > this.max.y ||
3559
+ point.z < this.min.z || point.z > this.max.z ) {
3560
+
3561
+ return false;
3562
+
3563
+ }
3564
+
3565
+ return true;
3566
+
3567
+ },
3568
+
3569
+ containsBox: function ( box ) {
3570
+
3571
+ if ( ( this.min.x <= box.min.x ) && ( box.max.x <= this.max.x ) &&
3572
+ ( this.min.y <= box.min.y ) && ( box.max.y <= this.max.y ) &&
3573
+ ( this.min.z <= box.min.z ) && ( box.max.z <= this.max.z ) ) {
3574
+
3575
+ return true;
3576
+
3577
+ }
3578
+
3579
+ return false;
3580
+
3581
+ },
3582
+
3583
+ getParameter: function ( point, optionalTarget ) {
3584
+
3585
+ // This can potentially have a divide by zero if the box
3586
+ // has a size dimension of 0.
3587
+
3588
+ var result = optionalTarget || new THREE.Vector3();
3589
+
3590
+ return result.set(
3591
+ ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
3592
+ ( point.y - this.min.y ) / ( this.max.y - this.min.y ),
3593
+ ( point.z - this.min.z ) / ( this.max.z - this.min.z )
3594
+ );
3595
+
3596
+ },
3597
+
3598
+ isIntersectionBox: function ( box ) {
3599
+
3600
+ // using 6 splitting planes to rule out intersections.
3601
+
3602
+ if ( box.max.x < this.min.x || box.min.x > this.max.x ||
3603
+ box.max.y < this.min.y || box.min.y > this.max.y ||
3604
+ box.max.z < this.min.z || box.min.z > this.max.z ) {
3605
+
3606
+ return false;
3607
+
3608
+ }
3609
+
3610
+ return true;
3611
+
3612
+ },
3613
+
3614
+ clampPoint: function ( point, optionalTarget ) {
3615
+
3616
+ var result = optionalTarget || new THREE.Vector3();
3617
+ return result.copy( point ).clamp( this.min, this.max );
3618
+
3619
+ },
3620
+
3621
+ distanceToPoint: function () {
3622
+
3623
+ var v1 = new THREE.Vector3();
3624
+
3625
+ return function ( point ) {
3626
+
3627
+ var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
3628
+ return clampedPoint.sub( point ).length();
3629
+
3630
+ };
3631
+
3632
+ }(),
3633
+
3634
+ getBoundingSphere: function () {
3635
+
3636
+ var v1 = new THREE.Vector3();
3637
+
3638
+ return function ( optionalTarget ) {
3639
+
3640
+ var result = optionalTarget || new THREE.Sphere();
3641
+
3642
+ result.center = this.center();
3643
+ result.radius = this.size( v1 ).length() * 0.5;
3644
+
3645
+ return result;
3646
+
3647
+ };
3648
+
3649
+ }(),
3650
+
3651
+ intersect: function ( box ) {
3652
+
3653
+ this.min.max( box.min );
3654
+ this.max.min( box.max );
3655
+
3656
+ return this;
3657
+
3658
+ },
3659
+
3660
+ union: function ( box ) {
3661
+
3662
+ this.min.min( box.min );
3663
+ this.max.max( box.max );
3664
+
3665
+ return this;
3666
+
3667
+ },
3668
+
3669
+ applyMatrix4: function () {
3670
+
3671
+ var points = [
3672
+ new THREE.Vector3(),
3673
+ new THREE.Vector3(),
3674
+ new THREE.Vector3(),
3675
+ new THREE.Vector3(),
3676
+ new THREE.Vector3(),
3677
+ new THREE.Vector3(),
3678
+ new THREE.Vector3(),
3679
+ new THREE.Vector3()
3680
+ ];
3681
+
3682
+ return function ( matrix ) {
3683
+
3684
+ // NOTE: I am using a binary pattern to specify all 2^3 combinations below
3685
+ points[ 0 ].set( this.min.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 000
3686
+ points[ 1 ].set( this.min.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 001
3687
+ points[ 2 ].set( this.min.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 010
3688
+ points[ 3 ].set( this.min.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 011
3689
+ points[ 4 ].set( this.max.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 100
3690
+ points[ 5 ].set( this.max.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 101
3691
+ points[ 6 ].set( this.max.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 110
3692
+ points[ 7 ].set( this.max.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 111
3693
+
3694
+ this.makeEmpty();
3695
+ this.setFromPoints( points );
3696
+
3697
+ return this;
3698
+
3699
+ };
3700
+
3701
+ }(),
3702
+
3703
+ translate: function ( offset ) {
3704
+
3705
+ this.min.add( offset );
3706
+ this.max.add( offset );
3707
+
3708
+ return this;
3709
+
3710
+ },
3711
+
3712
+ equals: function ( box ) {
3713
+
3714
+ return box.min.equals( this.min ) && box.max.equals( this.max );
3715
+
3716
+ },
3717
+
3718
+ clone: function () {
3719
+
3720
+ return new THREE.Box3().copy( this );
3721
+
3722
+ }
3723
+
3724
+ };
3725
+
3726
+ // File:src/math/Matrix3.js
3727
+
3728
+ /**
3729
+ * @author alteredq / http://alteredqualia.com/
3730
+ * @author WestLangley / http://github.com/WestLangley
3731
+ * @author bhouston / http://exocortex.com
3732
+ */
3733
+
3734
+ THREE.Matrix3 = function () {
3735
+
3736
+ this.elements = new Float32Array( [
3737
+
3738
+ 1, 0, 0,
3739
+ 0, 1, 0,
3740
+ 0, 0, 1
3741
+
3742
+ ] );
3743
+
3744
+ if ( arguments.length > 0 ) {
3745
+
3746
+ console.error( 'THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.' );
3747
+
3748
+ }
3749
+
3750
+ };
3751
+
3752
+ THREE.Matrix3.prototype = {
3753
+
3754
+ constructor: THREE.Matrix3,
3755
+
3756
+ set: function ( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
3757
+
3758
+ var te = this.elements;
3759
+
3760
+ te[ 0 ] = n11; te[ 3 ] = n12; te[ 6 ] = n13;
3761
+ te[ 1 ] = n21; te[ 4 ] = n22; te[ 7 ] = n23;
3762
+ te[ 2 ] = n31; te[ 5 ] = n32; te[ 8 ] = n33;
3763
+
3764
+ return this;
3765
+
3766
+ },
3767
+
3768
+ identity: function () {
3769
+
3770
+ this.set(
3771
+
3772
+ 1, 0, 0,
3773
+ 0, 1, 0,
3774
+ 0, 0, 1
3775
+
3776
+ );
3777
+
3778
+ return this;
3779
+
3780
+ },
3781
+
3782
+ copy: function ( m ) {
3783
+
3784
+ var me = m.elements;
3785
+
3786
+ this.set(
3787
+
3788
+ me[ 0 ], me[ 3 ], me[ 6 ],
3789
+ me[ 1 ], me[ 4 ], me[ 7 ],
3790
+ me[ 2 ], me[ 5 ], me[ 8 ]
3791
+
3792
+ );
3793
+
3794
+ return this;
3795
+
3796
+ },
3797
+
3798
+ multiplyVector3: function ( vector ) {
3799
+
3800
+ console.warn( 'THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.' );
3801
+ return vector.applyMatrix3( this );
3802
+
3803
+ },
3804
+
3805
+ multiplyVector3Array: function ( a ) {
3806
+
3807
+ console.warn( 'THREE.Matrix3: .multiplyVector3Array() has been renamed. Use matrix.applyToVector3Array( array ) instead.' );
3808
+ return this.applyToVector3Array( a );
3809
+
3810
+ },
3811
+
3812
+ applyToVector3Array: function () {
3813
+
3814
+ var v1 = new THREE.Vector3();
3815
+
3816
+ return function ( array, offset, length ) {
3817
+
3818
+ if ( offset === undefined ) offset = 0;
3819
+ if ( length === undefined ) length = array.length;
3820
+
3821
+ for ( var i = 0, j = offset, il; i < length; i += 3, j += 3 ) {
3822
+
3823
+ v1.x = array[ j ];
3824
+ v1.y = array[ j + 1 ];
3825
+ v1.z = array[ j + 2 ];
3826
+
3827
+ v1.applyMatrix3( this );
3828
+
3829
+ array[ j ] = v1.x;
3830
+ array[ j + 1 ] = v1.y;
3831
+ array[ j + 2 ] = v1.z;
3832
+
3833
+ }
3834
+
3835
+ return array;
3836
+
3837
+ };
3838
+
3839
+ }(),
3840
+
3841
+ multiplyScalar: function ( s ) {
3842
+
3843
+ var te = this.elements;
3844
+
3845
+ te[ 0 ] *= s; te[ 3 ] *= s; te[ 6 ] *= s;
3846
+ te[ 1 ] *= s; te[ 4 ] *= s; te[ 7 ] *= s;
3847
+ te[ 2 ] *= s; te[ 5 ] *= s; te[ 8 ] *= s;
3848
+
3849
+ return this;
3850
+
3851
+ },
3852
+
3853
+ determinant: function () {
3854
+
3855
+ var te = this.elements;
3856
+
3857
+ var a = te[ 0 ], b = te[ 1 ], c = te[ 2 ],
3858
+ d = te[ 3 ], e = te[ 4 ], f = te[ 5 ],
3859
+ g = te[ 6 ], h = te[ 7 ], i = te[ 8 ];
3860
+
3861
+ return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
3862
+
3863
+ },
3864
+
3865
+ getInverse: function ( matrix, throwOnInvertible ) {
3866
+
3867
+ // input: THREE.Matrix4
3868
+ // ( based on http://code.google.com/p/webgl-mjs/ )
3869
+
3870
+ var me = matrix.elements;
3871
+ var te = this.elements;
3872
+
3873
+ te[ 0 ] = me[ 10 ] * me[ 5 ] - me[ 6 ] * me[ 9 ];
3874
+ te[ 1 ] = - me[ 10 ] * me[ 1 ] + me[ 2 ] * me[ 9 ];
3875
+ te[ 2 ] = me[ 6 ] * me[ 1 ] - me[ 2 ] * me[ 5 ];
3876
+ te[ 3 ] = - me[ 10 ] * me[ 4 ] + me[ 6 ] * me[ 8 ];
3877
+ te[ 4 ] = me[ 10 ] * me[ 0 ] - me[ 2 ] * me[ 8 ];
3878
+ te[ 5 ] = - me[ 6 ] * me[ 0 ] + me[ 2 ] * me[ 4 ];
3879
+ te[ 6 ] = me[ 9 ] * me[ 4 ] - me[ 5 ] * me[ 8 ];
3880
+ te[ 7 ] = - me[ 9 ] * me[ 0 ] + me[ 1 ] * me[ 8 ];
3881
+ te[ 8 ] = me[ 5 ] * me[ 0 ] - me[ 1 ] * me[ 4 ];
3882
+
3883
+ var det = me[ 0 ] * te[ 0 ] + me[ 1 ] * te[ 3 ] + me[ 2 ] * te[ 6 ];
3884
+
3885
+ // no inverse
3886
+
3887
+ if ( det === 0 ) {
3888
+
3889
+ var msg = "Matrix3.getInverse(): can't invert matrix, determinant is 0";
3890
+
3891
+ if ( throwOnInvertible || false ) {
3892
+
3893
+ throw new Error( msg );
3894
+
3895
+ } else {
3896
+
3897
+ console.warn( msg );
3898
+
3899
+ }
3900
+
3901
+ this.identity();
3902
+
3903
+ return this;
3904
+
3905
+ }
3906
+
3907
+ this.multiplyScalar( 1.0 / det );
3908
+
3909
+ return this;
3910
+
3911
+ },
3912
+
3913
+ transpose: function () {
3914
+
3915
+ var tmp, m = this.elements;
3916
+
3917
+ tmp = m[ 1 ]; m[ 1 ] = m[ 3 ]; m[ 3 ] = tmp;
3918
+ tmp = m[ 2 ]; m[ 2 ] = m[ 6 ]; m[ 6 ] = tmp;
3919
+ tmp = m[ 5 ]; m[ 5 ] = m[ 7 ]; m[ 7 ] = tmp;
3920
+
3921
+ return this;
3922
+
3923
+ },
3924
+
3925
+ flattenToArrayOffset: function ( array, offset ) {
3926
+
3927
+ var te = this.elements;
3928
+
3929
+ array[ offset ] = te[ 0 ];
3930
+ array[ offset + 1 ] = te[ 1 ];
3931
+ array[ offset + 2 ] = te[ 2 ];
3932
+
3933
+ array[ offset + 3 ] = te[ 3 ];
3934
+ array[ offset + 4 ] = te[ 4 ];
3935
+ array[ offset + 5 ] = te[ 5 ];
3936
+
3937
+ array[ offset + 6 ] = te[ 6 ];
3938
+ array[ offset + 7 ] = te[ 7 ];
3939
+ array[ offset + 8 ] = te[ 8 ];
3940
+
3941
+ return array;
3942
+
3943
+ },
3944
+
3945
+ getNormalMatrix: function ( m ) {
3946
+
3947
+ // input: THREE.Matrix4
3948
+
3949
+ this.getInverse( m ).transpose();
3950
+
3951
+ return this;
3952
+
3953
+ },
3954
+
3955
+ transposeIntoArray: function ( r ) {
3956
+
3957
+ var m = this.elements;
3958
+
3959
+ r[ 0 ] = m[ 0 ];
3960
+ r[ 1 ] = m[ 3 ];
3961
+ r[ 2 ] = m[ 6 ];
3962
+ r[ 3 ] = m[ 1 ];
3963
+ r[ 4 ] = m[ 4 ];
3964
+ r[ 5 ] = m[ 7 ];
3965
+ r[ 6 ] = m[ 2 ];
3966
+ r[ 7 ] = m[ 5 ];
3967
+ r[ 8 ] = m[ 8 ];
3968
+
3969
+ return this;
3970
+
3971
+ },
3972
+
3973
+ fromArray: function ( array ) {
3974
+
3975
+ this.elements.set( array );
3976
+
3977
+ return this;
3978
+
3979
+ },
3980
+
3981
+ toArray: function () {
3982
+
3983
+ var te = this.elements;
3984
+
3985
+ return [
3986
+ te[ 0 ], te[ 1 ], te[ 2 ],
3987
+ te[ 3 ], te[ 4 ], te[ 5 ],
3988
+ te[ 6 ], te[ 7 ], te[ 8 ]
3989
+ ];
3990
+
3991
+ },
3992
+
3993
+ clone: function () {
3994
+
3995
+ return new THREE.Matrix3().fromArray( this.elements );
3996
+
3997
+ }
3998
+
3999
+ };
4000
+
4001
+ // File:src/math/Matrix4.js
4002
+
4003
+ /**
4004
+ * @author mrdoob / http://mrdoob.com/
4005
+ * @author supereggbert / http://www.paulbrunt.co.uk/
4006
+ * @author philogb / http://blog.thejit.org/
4007
+ * @author jordi_ros / http://plattsoft.com
4008
+ * @author D1plo1d / http://github.com/D1plo1d
4009
+ * @author alteredq / http://alteredqualia.com/
4010
+ * @author mikael emtinger / http://gomo.se/
4011
+ * @author timknip / http://www.floorplanner.com/
4012
+ * @author bhouston / http://exocortex.com
4013
+ * @author WestLangley / http://github.com/WestLangley
4014
+ */
4015
+
4016
+ THREE.Matrix4 = function () {
4017
+
4018
+ this.elements = new Float32Array( [
4019
+
4020
+ 1, 0, 0, 0,
4021
+ 0, 1, 0, 0,
4022
+ 0, 0, 1, 0,
4023
+ 0, 0, 0, 1
4024
+
4025
+ ] );
4026
+
4027
+ if ( arguments.length > 0 ) {
4028
+
4029
+ console.error( 'THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.' );
4030
+
4031
+ }
4032
+
4033
+ };
4034
+
4035
+ THREE.Matrix4.prototype = {
4036
+
4037
+ constructor: THREE.Matrix4,
4038
+
4039
+ set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
4040
+
4041
+ var te = this.elements;
4042
+
4043
+ te[ 0 ] = n11; te[ 4 ] = n12; te[ 8 ] = n13; te[ 12 ] = n14;
4044
+ te[ 1 ] = n21; te[ 5 ] = n22; te[ 9 ] = n23; te[ 13 ] = n24;
4045
+ te[ 2 ] = n31; te[ 6 ] = n32; te[ 10 ] = n33; te[ 14 ] = n34;
4046
+ te[ 3 ] = n41; te[ 7 ] = n42; te[ 11 ] = n43; te[ 15 ] = n44;
4047
+
4048
+ return this;
4049
+
4050
+ },
4051
+
4052
+ identity: function () {
4053
+
4054
+ this.set(
4055
+
4056
+ 1, 0, 0, 0,
4057
+ 0, 1, 0, 0,
4058
+ 0, 0, 1, 0,
4059
+ 0, 0, 0, 1
4060
+
4061
+ );
4062
+
4063
+ return this;
4064
+
4065
+ },
4066
+
4067
+ copy: function ( m ) {
4068
+
4069
+ this.elements.set( m.elements );
4070
+
4071
+ return this;
4072
+
4073
+ },
4074
+
4075
+ extractPosition: function ( m ) {
4076
+
4077
+ console.warn( 'THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().' );
4078
+ return this.copyPosition( m );
4079
+
4080
+ },
4081
+
4082
+ copyPosition: function ( m ) {
4083
+
4084
+ var te = this.elements;
4085
+ var me = m.elements;
4086
+
4087
+ te[ 12 ] = me[ 12 ];
4088
+ te[ 13 ] = me[ 13 ];
4089
+ te[ 14 ] = me[ 14 ];
4090
+
4091
+ return this;
4092
+
4093
+ },
4094
+
4095
+ extractRotation: function () {
4096
+
4097
+ var v1 = new THREE.Vector3();
4098
+
4099
+ return function ( m ) {
4100
+
4101
+ var te = this.elements;
4102
+ var me = m.elements;
4103
+
4104
+ var scaleX = 1 / v1.set( me[ 0 ], me[ 1 ], me[ 2 ] ).length();
4105
+ var scaleY = 1 / v1.set( me[ 4 ], me[ 5 ], me[ 6 ] ).length();
4106
+ var scaleZ = 1 / v1.set( me[ 8 ], me[ 9 ], me[ 10 ] ).length();
4107
+
4108
+ te[ 0 ] = me[ 0 ] * scaleX;
4109
+ te[ 1 ] = me[ 1 ] * scaleX;
4110
+ te[ 2 ] = me[ 2 ] * scaleX;
4111
+
4112
+ te[ 4 ] = me[ 4 ] * scaleY;
4113
+ te[ 5 ] = me[ 5 ] * scaleY;
4114
+ te[ 6 ] = me[ 6 ] * scaleY;
4115
+
4116
+ te[ 8 ] = me[ 8 ] * scaleZ;
4117
+ te[ 9 ] = me[ 9 ] * scaleZ;
4118
+ te[ 10 ] = me[ 10 ] * scaleZ;
4119
+
4120
+ return this;
4121
+
4122
+ };
4123
+
4124
+ }(),
4125
+
4126
+ makeRotationFromEuler: function ( euler ) {
4127
+
4128
+ if ( euler instanceof THREE.Euler === false ) {
4129
+
4130
+ console.error( 'THREE.Matrix: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
4131
+
4132
+ }
4133
+
4134
+ var te = this.elements;
4135
+
4136
+ var x = euler.x, y = euler.y, z = euler.z;
4137
+ var a = Math.cos( x ), b = Math.sin( x );
4138
+ var c = Math.cos( y ), d = Math.sin( y );
4139
+ var e = Math.cos( z ), f = Math.sin( z );
4140
+
4141
+ if ( euler.order === 'XYZ' ) {
4142
+
4143
+ var ae = a * e, af = a * f, be = b * e, bf = b * f;
4144
+
4145
+ te[ 0 ] = c * e;
4146
+ te[ 4 ] = - c * f;
4147
+ te[ 8 ] = d;
4148
+
4149
+ te[ 1 ] = af + be * d;
4150
+ te[ 5 ] = ae - bf * d;
4151
+ te[ 9 ] = - b * c;
4152
+
4153
+ te[ 2 ] = bf - ae * d;
4154
+ te[ 6 ] = be + af * d;
4155
+ te[ 10 ] = a * c;
4156
+
4157
+ } else if ( euler.order === 'YXZ' ) {
4158
+
4159
+ var ce = c * e, cf = c * f, de = d * e, df = d * f;
4160
+
4161
+ te[ 0 ] = ce + df * b;
4162
+ te[ 4 ] = de * b - cf;
4163
+ te[ 8 ] = a * d;
4164
+
4165
+ te[ 1 ] = a * f;
4166
+ te[ 5 ] = a * e;
4167
+ te[ 9 ] = - b;
4168
+
4169
+ te[ 2 ] = cf * b - de;
4170
+ te[ 6 ] = df + ce * b;
4171
+ te[ 10 ] = a * c;
4172
+
4173
+ } else if ( euler.order === 'ZXY' ) {
4174
+
4175
+ var ce = c * e, cf = c * f, de = d * e, df = d * f;
4176
+
4177
+ te[ 0 ] = ce - df * b;
4178
+ te[ 4 ] = - a * f;
4179
+ te[ 8 ] = de + cf * b;
4180
+
4181
+ te[ 1 ] = cf + de * b;
4182
+ te[ 5 ] = a * e;
4183
+ te[ 9 ] = df - ce * b;
4184
+
4185
+ te[ 2 ] = - a * d;
4186
+ te[ 6 ] = b;
4187
+ te[ 10 ] = a * c;
4188
+
4189
+ } else if ( euler.order === 'ZYX' ) {
4190
+
4191
+ var ae = a * e, af = a * f, be = b * e, bf = b * f;
4192
+
4193
+ te[ 0 ] = c * e;
4194
+ te[ 4 ] = be * d - af;
4195
+ te[ 8 ] = ae * d + bf;
4196
+
4197
+ te[ 1 ] = c * f;
4198
+ te[ 5 ] = bf * d + ae;
4199
+ te[ 9 ] = af * d - be;
4200
+
4201
+ te[ 2 ] = - d;
4202
+ te[ 6 ] = b * c;
4203
+ te[ 10 ] = a * c;
4204
+
4205
+ } else if ( euler.order === 'YZX' ) {
4206
+
4207
+ var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
4208
+
4209
+ te[ 0 ] = c * e;
4210
+ te[ 4 ] = bd - ac * f;
4211
+ te[ 8 ] = bc * f + ad;
4212
+
4213
+ te[ 1 ] = f;
4214
+ te[ 5 ] = a * e;
4215
+ te[ 9 ] = - b * e;
4216
+
4217
+ te[ 2 ] = - d * e;
4218
+ te[ 6 ] = ad * f + bc;
4219
+ te[ 10 ] = ac - bd * f;
4220
+
4221
+ } else if ( euler.order === 'XZY' ) {
4222
+
4223
+ var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
4224
+
4225
+ te[ 0 ] = c * e;
4226
+ te[ 4 ] = - f;
4227
+ te[ 8 ] = d * e;
4228
+
4229
+ te[ 1 ] = ac * f + bd;
4230
+ te[ 5 ] = a * e;
4231
+ te[ 9 ] = ad * f - bc;
4232
+
4233
+ te[ 2 ] = bc * f - ad;
4234
+ te[ 6 ] = b * e;
4235
+ te[ 10 ] = bd * f + ac;
4236
+
4237
+ }
4238
+
4239
+ // last column
4240
+ te[ 3 ] = 0;
4241
+ te[ 7 ] = 0;
4242
+ te[ 11 ] = 0;
4243
+
4244
+ // bottom row
4245
+ te[ 12 ] = 0;
4246
+ te[ 13 ] = 0;
4247
+ te[ 14 ] = 0;
4248
+ te[ 15 ] = 1;
4249
+
4250
+ return this;
4251
+
4252
+ },
4253
+
4254
+ setRotationFromQuaternion: function ( q ) {
4255
+
4256
+ console.warn( 'THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().' );
4257
+
4258
+ return this.makeRotationFromQuaternion( q );
4259
+
4260
+ },
4261
+
4262
+ makeRotationFromQuaternion: function ( q ) {
4263
+
4264
+ var te = this.elements;
4265
+
4266
+ var x = q.x, y = q.y, z = q.z, w = q.w;
4267
+ var x2 = x + x, y2 = y + y, z2 = z + z;
4268
+ var xx = x * x2, xy = x * y2, xz = x * z2;
4269
+ var yy = y * y2, yz = y * z2, zz = z * z2;
4270
+ var wx = w * x2, wy = w * y2, wz = w * z2;
4271
+
4272
+ te[ 0 ] = 1 - ( yy + zz );
4273
+ te[ 4 ] = xy - wz;
4274
+ te[ 8 ] = xz + wy;
4275
+
4276
+ te[ 1 ] = xy + wz;
4277
+ te[ 5 ] = 1 - ( xx + zz );
4278
+ te[ 9 ] = yz - wx;
4279
+
4280
+ te[ 2 ] = xz - wy;
4281
+ te[ 6 ] = yz + wx;
4282
+ te[ 10 ] = 1 - ( xx + yy );
4283
+
4284
+ // last column
4285
+ te[ 3 ] = 0;
4286
+ te[ 7 ] = 0;
4287
+ te[ 11 ] = 0;
4288
+
4289
+ // bottom row
4290
+ te[ 12 ] = 0;
4291
+ te[ 13 ] = 0;
4292
+ te[ 14 ] = 0;
4293
+ te[ 15 ] = 1;
4294
+
4295
+ return this;
4296
+
4297
+ },
4298
+
4299
+ lookAt: function () {
4300
+
4301
+ var x = new THREE.Vector3();
4302
+ var y = new THREE.Vector3();
4303
+ var z = new THREE.Vector3();
4304
+
4305
+ return function ( eye, target, up ) {
4306
+
4307
+ var te = this.elements;
4308
+
4309
+ z.subVectors( eye, target ).normalize();
4310
+
4311
+ if ( z.length() === 0 ) {
4312
+
4313
+ z.z = 1;
4314
+
4315
+ }
4316
+
4317
+ x.crossVectors( up, z ).normalize();
4318
+
4319
+ if ( x.length() === 0 ) {
4320
+
4321
+ z.x += 0.0001;
4322
+ x.crossVectors( up, z ).normalize();
4323
+
4324
+ }
4325
+
4326
+ y.crossVectors( z, x );
4327
+
4328
+
4329
+ te[ 0 ] = x.x; te[ 4 ] = y.x; te[ 8 ] = z.x;
4330
+ te[ 1 ] = x.y; te[ 5 ] = y.y; te[ 9 ] = z.y;
4331
+ te[ 2 ] = x.z; te[ 6 ] = y.z; te[ 10 ] = z.z;
4332
+
4333
+ return this;
4334
+
4335
+ };
4336
+
4337
+ }(),
4338
+
4339
+ multiply: function ( m, n ) {
4340
+
4341
+ if ( n !== undefined ) {
4342
+
4343
+ console.warn( 'THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.' );
4344
+ return this.multiplyMatrices( m, n );
4345
+
4346
+ }
4347
+
4348
+ return this.multiplyMatrices( this, m );
4349
+
4350
+ },
4351
+
4352
+ multiplyMatrices: function ( a, b ) {
4353
+
4354
+ var ae = a.elements;
4355
+ var be = b.elements;
4356
+ var te = this.elements;
4357
+
4358
+ var a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ];
4359
+ var a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ];
4360
+ var a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ];
4361
+ var a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ];
4362
+
4363
+ var b11 = be[ 0 ], b12 = be[ 4 ], b13 = be[ 8 ], b14 = be[ 12 ];
4364
+ var b21 = be[ 1 ], b22 = be[ 5 ], b23 = be[ 9 ], b24 = be[ 13 ];
4365
+ var b31 = be[ 2 ], b32 = be[ 6 ], b33 = be[ 10 ], b34 = be[ 14 ];
4366
+ var b41 = be[ 3 ], b42 = be[ 7 ], b43 = be[ 11 ], b44 = be[ 15 ];
4367
+
4368
+ te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
4369
+ te[ 4 ] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
4370
+ te[ 8 ] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
4371
+ te[ 12 ] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
4372
+
4373
+ te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
4374
+ te[ 5 ] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
4375
+ te[ 9 ] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
4376
+ te[ 13 ] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
4377
+
4378
+ te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
4379
+ te[ 6 ] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
4380
+ te[ 10 ] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
4381
+ te[ 14 ] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
4382
+
4383
+ te[ 3 ] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
4384
+ te[ 7 ] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
4385
+ te[ 11 ] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
4386
+ te[ 15 ] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
4387
+
4388
+ return this;
4389
+
4390
+ },
4391
+
4392
+ multiplyToArray: function ( a, b, r ) {
4393
+
4394
+ var te = this.elements;
4395
+
4396
+ this.multiplyMatrices( a, b );
4397
+
4398
+ r[ 0 ] = te[ 0 ]; r[ 1 ] = te[ 1 ]; r[ 2 ] = te[ 2 ]; r[ 3 ] = te[ 3 ];
4399
+ r[ 4 ] = te[ 4 ]; r[ 5 ] = te[ 5 ]; r[ 6 ] = te[ 6 ]; r[ 7 ] = te[ 7 ];
4400
+ r[ 8 ] = te[ 8 ]; r[ 9 ] = te[ 9 ]; r[ 10 ] = te[ 10 ]; r[ 11 ] = te[ 11 ];
4401
+ r[ 12 ] = te[ 12 ]; r[ 13 ] = te[ 13 ]; r[ 14 ] = te[ 14 ]; r[ 15 ] = te[ 15 ];
4402
+
4403
+ return this;
4404
+
4405
+ },
4406
+
4407
+ multiplyScalar: function ( s ) {
4408
+
4409
+ var te = this.elements;
4410
+
4411
+ te[ 0 ] *= s; te[ 4 ] *= s; te[ 8 ] *= s; te[ 12 ] *= s;
4412
+ te[ 1 ] *= s; te[ 5 ] *= s; te[ 9 ] *= s; te[ 13 ] *= s;
4413
+ te[ 2 ] *= s; te[ 6 ] *= s; te[ 10 ] *= s; te[ 14 ] *= s;
4414
+ te[ 3 ] *= s; te[ 7 ] *= s; te[ 11 ] *= s; te[ 15 ] *= s;
4415
+
4416
+ return this;
4417
+
4418
+ },
4419
+
4420
+ multiplyVector3: function ( vector ) {
4421
+
4422
+ console.warn( 'THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) or vector.applyProjection( matrix ) instead.' );
4423
+ return vector.applyProjection( this );
4424
+
4425
+ },
4426
+
4427
+ multiplyVector4: function ( vector ) {
4428
+
4429
+ console.warn( 'THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
4430
+ return vector.applyMatrix4( this );
4431
+
4432
+ },
4433
+
4434
+ multiplyVector3Array: function ( a ) {
4435
+
4436
+ console.warn( 'THREE.Matrix4: .multiplyVector3Array() has been renamed. Use matrix.applyToVector3Array( array ) instead.' );
4437
+ return this.applyToVector3Array( a );
4438
+
4439
+ },
4440
+
4441
+ applyToVector3Array: function () {
4442
+
4443
+ var v1 = new THREE.Vector3();
4444
+
4445
+ return function ( array, offset, length ) {
4446
+
4447
+ if ( offset === undefined ) offset = 0;
4448
+ if ( length === undefined ) length = array.length;
4449
+
4450
+ for ( var i = 0, j = offset, il; i < length; i += 3, j += 3 ) {
4451
+
4452
+ v1.x = array[ j ];
4453
+ v1.y = array[ j + 1 ];
4454
+ v1.z = array[ j + 2 ];
4455
+
4456
+ v1.applyMatrix4( this );
4457
+
4458
+ array[ j ] = v1.x;
4459
+ array[ j + 1 ] = v1.y;
4460
+ array[ j + 2 ] = v1.z;
4461
+
4462
+ }
4463
+
4464
+ return array;
4465
+
4466
+ };
4467
+
4468
+ }(),
4469
+
4470
+ rotateAxis: function ( v ) {
4471
+
4472
+ console.warn( 'THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.' );
4473
+
4474
+ v.transformDirection( this );
4475
+
4476
+ },
4477
+
4478
+ crossVector: function ( vector ) {
4479
+
4480
+ console.warn( 'THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
4481
+ return vector.applyMatrix4( this );
4482
+
4483
+ },
4484
+
4485
+ determinant: function () {
4486
+
4487
+ var te = this.elements;
4488
+
4489
+ var n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ], n14 = te[ 12 ];
4490
+ var n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ], n24 = te[ 13 ];
4491
+ var n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ];
4492
+ var n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ];
4493
+
4494
+ //TODO: make this more efficient
4495
+ //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
4496
+
4497
+ return (
4498
+ n41 * (
4499
+ + n14 * n23 * n32
4500
+ - n13 * n24 * n32
4501
+ - n14 * n22 * n33
4502
+ + n12 * n24 * n33
4503
+ + n13 * n22 * n34
4504
+ - n12 * n23 * n34
4505
+ ) +
4506
+ n42 * (
4507
+ + n11 * n23 * n34
4508
+ - n11 * n24 * n33
4509
+ + n14 * n21 * n33
4510
+ - n13 * n21 * n34
4511
+ + n13 * n24 * n31
4512
+ - n14 * n23 * n31
4513
+ ) +
4514
+ n43 * (
4515
+ + n11 * n24 * n32
4516
+ - n11 * n22 * n34
4517
+ - n14 * n21 * n32
4518
+ + n12 * n21 * n34
4519
+ + n14 * n22 * n31
4520
+ - n12 * n24 * n31
4521
+ ) +
4522
+ n44 * (
4523
+ - n13 * n22 * n31
4524
+ - n11 * n23 * n32
4525
+ + n11 * n22 * n33
4526
+ + n13 * n21 * n32
4527
+ - n12 * n21 * n33
4528
+ + n12 * n23 * n31
4529
+ )
4530
+
4531
+ );
4532
+
4533
+ },
4534
+
4535
+ transpose: function () {
4536
+
4537
+ var te = this.elements;
4538
+ var tmp;
4539
+
4540
+ tmp = te[ 1 ]; te[ 1 ] = te[ 4 ]; te[ 4 ] = tmp;
4541
+ tmp = te[ 2 ]; te[ 2 ] = te[ 8 ]; te[ 8 ] = tmp;
4542
+ tmp = te[ 6 ]; te[ 6 ] = te[ 9 ]; te[ 9 ] = tmp;
4543
+
4544
+ tmp = te[ 3 ]; te[ 3 ] = te[ 12 ]; te[ 12 ] = tmp;
4545
+ tmp = te[ 7 ]; te[ 7 ] = te[ 13 ]; te[ 13 ] = tmp;
4546
+ tmp = te[ 11 ]; te[ 11 ] = te[ 14 ]; te[ 14 ] = tmp;
4547
+
4548
+ return this;
4549
+
4550
+ },
4551
+
4552
+ flattenToArrayOffset: function ( array, offset ) {
4553
+
4554
+ var te = this.elements;
4555
+
4556
+ array[ offset ] = te[ 0 ];
4557
+ array[ offset + 1 ] = te[ 1 ];
4558
+ array[ offset + 2 ] = te[ 2 ];
4559
+ array[ offset + 3 ] = te[ 3 ];
4560
+
4561
+ array[ offset + 4 ] = te[ 4 ];
4562
+ array[ offset + 5 ] = te[ 5 ];
4563
+ array[ offset + 6 ] = te[ 6 ];
4564
+ array[ offset + 7 ] = te[ 7 ];
4565
+
4566
+ array[ offset + 8 ] = te[ 8 ];
4567
+ array[ offset + 9 ] = te[ 9 ];
4568
+ array[ offset + 10 ] = te[ 10 ];
4569
+ array[ offset + 11 ] = te[ 11 ];
4570
+
4571
+ array[ offset + 12 ] = te[ 12 ];
4572
+ array[ offset + 13 ] = te[ 13 ];
4573
+ array[ offset + 14 ] = te[ 14 ];
4574
+ array[ offset + 15 ] = te[ 15 ];
4575
+
4576
+ return array;
4577
+
4578
+ },
4579
+
4580
+ getPosition: function () {
4581
+
4582
+ var v1 = new THREE.Vector3();
4583
+
4584
+ return function () {
4585
+
4586
+ console.warn( 'THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.' );
4587
+
4588
+ var te = this.elements;
4589
+ return v1.set( te[ 12 ], te[ 13 ], te[ 14 ] );
4590
+
4591
+ };
4592
+
4593
+ }(),
4594
+
4595
+ setPosition: function ( v ) {
4596
+
4597
+ var te = this.elements;
4598
+
4599
+ te[ 12 ] = v.x;
4600
+ te[ 13 ] = v.y;
4601
+ te[ 14 ] = v.z;
4602
+
4603
+ return this;
4604
+
4605
+ },
4606
+
4607
+ getInverse: function ( m, throwOnInvertible ) {
4608
+
4609
+ // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
4610
+ var te = this.elements;
4611
+ var me = m.elements;
4612
+
4613
+ var n11 = me[ 0 ], n12 = me[ 4 ], n13 = me[ 8 ], n14 = me[ 12 ];
4614
+ var n21 = me[ 1 ], n22 = me[ 5 ], n23 = me[ 9 ], n24 = me[ 13 ];
4615
+ var n31 = me[ 2 ], n32 = me[ 6 ], n33 = me[ 10 ], n34 = me[ 14 ];
4616
+ var n41 = me[ 3 ], n42 = me[ 7 ], n43 = me[ 11 ], n44 = me[ 15 ];
4617
+
4618
+ te[ 0 ] = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44;
4619
+ te[ 4 ] = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44;
4620
+ te[ 8 ] = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44;
4621
+ te[ 12 ] = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
4622
+ te[ 1 ] = n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44;
4623
+ te[ 5 ] = n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44;
4624
+ te[ 9 ] = n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44;
4625
+ te[ 13 ] = n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34;
4626
+ te[ 2 ] = n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44;
4627
+ te[ 6 ] = n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44;
4628
+ te[ 10 ] = n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44;
4629
+ te[ 14 ] = n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34;
4630
+ te[ 3 ] = n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43;
4631
+ te[ 7 ] = n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43;
4632
+ te[ 11 ] = n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43;
4633
+ te[ 15 ] = n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33;
4634
+
4635
+ var det = n11 * te[ 0 ] + n21 * te[ 4 ] + n31 * te[ 8 ] + n41 * te[ 12 ];
4636
+
4637
+ if ( det == 0 ) {
4638
+
4639
+ var msg = "Matrix4.getInverse(): can't invert matrix, determinant is 0";
4640
+
4641
+ if ( throwOnInvertible || false ) {
4642
+
4643
+ throw new Error( msg );
4644
+
4645
+ } else {
4646
+
4647
+ console.warn( msg );
4648
+
4649
+ }
4650
+
4651
+ this.identity();
4652
+
4653
+ return this;
4654
+ }
4655
+
4656
+ this.multiplyScalar( 1 / det );
4657
+
4658
+ return this;
4659
+
4660
+ },
4661
+
4662
+ translate: function ( v ) {
4663
+
4664
+ console.warn( 'THREE.Matrix4: .translate() has been removed.' );
4665
+
4666
+ },
4667
+
4668
+ rotateX: function ( angle ) {
4669
+
4670
+ console.warn( 'THREE.Matrix4: .rotateX() has been removed.' );
4671
+
4672
+ },
4673
+
4674
+ rotateY: function ( angle ) {
4675
+
4676
+ console.warn( 'THREE.Matrix4: .rotateY() has been removed.' );
4677
+
4678
+ },
4679
+
4680
+ rotateZ: function ( angle ) {
4681
+
4682
+ console.warn( 'THREE.Matrix4: .rotateZ() has been removed.' );
4683
+
4684
+ },
4685
+
4686
+ rotateByAxis: function ( axis, angle ) {
4687
+
4688
+ console.warn( 'THREE.Matrix4: .rotateByAxis() has been removed.' );
4689
+
4690
+ },
4691
+
4692
+ scale: function ( v ) {
4693
+
4694
+ var te = this.elements;
4695
+ var x = v.x, y = v.y, z = v.z;
4696
+
4697
+ te[ 0 ] *= x; te[ 4 ] *= y; te[ 8 ] *= z;
4698
+ te[ 1 ] *= x; te[ 5 ] *= y; te[ 9 ] *= z;
4699
+ te[ 2 ] *= x; te[ 6 ] *= y; te[ 10 ] *= z;
4700
+ te[ 3 ] *= x; te[ 7 ] *= y; te[ 11 ] *= z;
4701
+
4702
+ return this;
4703
+
4704
+ },
4705
+
4706
+ getMaxScaleOnAxis: function () {
4707
+
4708
+ var te = this.elements;
4709
+
4710
+ var scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ];
4711
+ var scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ];
4712
+ var scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ];
4713
+
4714
+ return Math.sqrt( Math.max( scaleXSq, Math.max( scaleYSq, scaleZSq ) ) );
4715
+
4716
+ },
4717
+
4718
+ makeTranslation: function ( x, y, z ) {
4719
+
4720
+ this.set(
4721
+
4722
+ 1, 0, 0, x,
4723
+ 0, 1, 0, y,
4724
+ 0, 0, 1, z,
4725
+ 0, 0, 0, 1
4726
+
4727
+ );
4728
+
4729
+ return this;
4730
+
4731
+ },
4732
+
4733
+ makeRotationX: function ( theta ) {
4734
+
4735
+ var c = Math.cos( theta ), s = Math.sin( theta );
4736
+
4737
+ this.set(
4738
+
4739
+ 1, 0, 0, 0,
4740
+ 0, c, - s, 0,
4741
+ 0, s, c, 0,
4742
+ 0, 0, 0, 1
4743
+
4744
+ );
4745
+
4746
+ return this;
4747
+
4748
+ },
4749
+
4750
+ makeRotationY: function ( theta ) {
4751
+
4752
+ var c = Math.cos( theta ), s = Math.sin( theta );
4753
+
4754
+ this.set(
4755
+
4756
+ c, 0, s, 0,
4757
+ 0, 1, 0, 0,
4758
+ - s, 0, c, 0,
4759
+ 0, 0, 0, 1
4760
+
4761
+ );
4762
+
4763
+ return this;
4764
+
4765
+ },
4766
+
4767
+ makeRotationZ: function ( theta ) {
4768
+
4769
+ var c = Math.cos( theta ), s = Math.sin( theta );
4770
+
4771
+ this.set(
4772
+
4773
+ c, - s, 0, 0,
4774
+ s, c, 0, 0,
4775
+ 0, 0, 1, 0,
4776
+ 0, 0, 0, 1
4777
+
4778
+ );
4779
+
4780
+ return this;
4781
+
4782
+ },
4783
+
4784
+ makeRotationAxis: function ( axis, angle ) {
4785
+
4786
+ // Based on http://www.gamedev.net/reference/articles/article1199.asp
4787
+
4788
+ var c = Math.cos( angle );
4789
+ var s = Math.sin( angle );
4790
+ var t = 1 - c;
4791
+ var x = axis.x, y = axis.y, z = axis.z;
4792
+ var tx = t * x, ty = t * y;
4793
+
4794
+ this.set(
4795
+
4796
+ tx * x + c, tx * y - s * z, tx * z + s * y, 0,
4797
+ tx * y + s * z, ty * y + c, ty * z - s * x, 0,
4798
+ tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
4799
+ 0, 0, 0, 1
4800
+
4801
+ );
4802
+
4803
+ return this;
4804
+
4805
+ },
4806
+
4807
+ makeScale: function ( x, y, z ) {
4808
+
4809
+ this.set(
4810
+
4811
+ x, 0, 0, 0,
4812
+ 0, y, 0, 0,
4813
+ 0, 0, z, 0,
4814
+ 0, 0, 0, 1
4815
+
4816
+ );
4817
+
4818
+ return this;
4819
+
4820
+ },
4821
+
4822
+ compose: function ( position, quaternion, scale ) {
4823
+
4824
+ this.makeRotationFromQuaternion( quaternion );
4825
+ this.scale( scale );
4826
+ this.setPosition( position );
4827
+
4828
+ return this;
4829
+
4830
+ },
4831
+
4832
+ decompose: function () {
4833
+
4834
+ var vector = new THREE.Vector3();
4835
+ var matrix = new THREE.Matrix4();
4836
+
4837
+ return function ( position, quaternion, scale ) {
4838
+
4839
+ var te = this.elements;
4840
+
4841
+ var sx = vector.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
4842
+ var sy = vector.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
4843
+ var sz = vector.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
4844
+
4845
+ // if determine is negative, we need to invert one scale
4846
+ var det = this.determinant();
4847
+ if ( det < 0 ) {
4848
+ sx = - sx;
4849
+ }
4850
+
4851
+ position.x = te[ 12 ];
4852
+ position.y = te[ 13 ];
4853
+ position.z = te[ 14 ];
4854
+
4855
+ // scale the rotation part
4856
+
4857
+ matrix.elements.set( this.elements ); // at this point matrix is incomplete so we can't use .copy()
4858
+
4859
+ var invSX = 1 / sx;
4860
+ var invSY = 1 / sy;
4861
+ var invSZ = 1 / sz;
4862
+
4863
+ matrix.elements[ 0 ] *= invSX;
4864
+ matrix.elements[ 1 ] *= invSX;
4865
+ matrix.elements[ 2 ] *= invSX;
4866
+
4867
+ matrix.elements[ 4 ] *= invSY;
4868
+ matrix.elements[ 5 ] *= invSY;
4869
+ matrix.elements[ 6 ] *= invSY;
4870
+
4871
+ matrix.elements[ 8 ] *= invSZ;
4872
+ matrix.elements[ 9 ] *= invSZ;
4873
+ matrix.elements[ 10 ] *= invSZ;
4874
+
4875
+ quaternion.setFromRotationMatrix( matrix );
4876
+
4877
+ scale.x = sx;
4878
+ scale.y = sy;
4879
+ scale.z = sz;
4880
+
4881
+ return this;
4882
+
4883
+ };
4884
+
4885
+ }(),
4886
+
4887
+ makeFrustum: function ( left, right, bottom, top, near, far ) {
4888
+
4889
+ var te = this.elements;
4890
+ var x = 2 * near / ( right - left );
4891
+ var y = 2 * near / ( top - bottom );
4892
+
4893
+ var a = ( right + left ) / ( right - left );
4894
+ var b = ( top + bottom ) / ( top - bottom );
4895
+ var c = - ( far + near ) / ( far - near );
4896
+ var d = - 2 * far * near / ( far - near );
4897
+
4898
+ te[ 0 ] = x; te[ 4 ] = 0; te[ 8 ] = a; te[ 12 ] = 0;
4899
+ te[ 1 ] = 0; te[ 5 ] = y; te[ 9 ] = b; te[ 13 ] = 0;
4900
+ te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = c; te[ 14 ] = d;
4901
+ te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = - 1; te[ 15 ] = 0;
4902
+
4903
+ return this;
4904
+
4905
+ },
4906
+
4907
+ makePerspective: function ( fov, aspect, near, far ) {
4908
+
4909
+ var ymax = near * Math.tan( THREE.Math.degToRad( fov * 0.5 ) );
4910
+ var ymin = - ymax;
4911
+ var xmin = ymin * aspect;
4912
+ var xmax = ymax * aspect;
4913
+
4914
+ return this.makeFrustum( xmin, xmax, ymin, ymax, near, far );
4915
+
4916
+ },
4917
+
4918
+ makeOrthographic: function ( left, right, top, bottom, near, far ) {
4919
+
4920
+ var te = this.elements;
4921
+ var w = right - left;
4922
+ var h = top - bottom;
4923
+ var p = far - near;
4924
+
4925
+ var x = ( right + left ) / w;
4926
+ var y = ( top + bottom ) / h;
4927
+ var z = ( far + near ) / p;
4928
+
4929
+ te[ 0 ] = 2 / w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x;
4930
+ te[ 1 ] = 0; te[ 5 ] = 2 / h; te[ 9 ] = 0; te[ 13 ] = - y;
4931
+ te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = - 2 / p; te[ 14 ] = - z;
4932
+ te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1;
4933
+
4934
+ return this;
4935
+
4936
+ },
4937
+
4938
+ fromArray: function ( array ) {
4939
+
4940
+ this.elements.set( array );
4941
+
4942
+ return this;
4943
+
4944
+ },
4945
+
4946
+ toArray: function () {
4947
+
4948
+ var te = this.elements;
4949
+
4950
+ return [
4951
+ te[ 0 ], te[ 1 ], te[ 2 ], te[ 3 ],
4952
+ te[ 4 ], te[ 5 ], te[ 6 ], te[ 7 ],
4953
+ te[ 8 ], te[ 9 ], te[ 10 ], te[ 11 ],
4954
+ te[ 12 ], te[ 13 ], te[ 14 ], te[ 15 ]
4955
+ ];
4956
+
4957
+ },
4958
+
4959
+ clone: function () {
4960
+
4961
+ return new THREE.Matrix4().fromArray( this.elements );
4962
+
4963
+ }
4964
+
4965
+ };
4966
+
4967
+ // File:src/math/Ray.js
4968
+
4969
+ /**
4970
+ * @author bhouston / http://exocortex.com
4971
+ */
4972
+
4973
+ THREE.Ray = function ( origin, direction ) {
4974
+
4975
+ this.origin = ( origin !== undefined ) ? origin : new THREE.Vector3();
4976
+ this.direction = ( direction !== undefined ) ? direction : new THREE.Vector3();
4977
+
4978
+ };
4979
+
4980
+ THREE.Ray.prototype = {
4981
+
4982
+ constructor: THREE.Ray,
4983
+
4984
+ set: function ( origin, direction ) {
4985
+
4986
+ this.origin.copy( origin );
4987
+ this.direction.copy( direction );
4988
+
4989
+ return this;
4990
+
4991
+ },
4992
+
4993
+ copy: function ( ray ) {
4994
+
4995
+ this.origin.copy( ray.origin );
4996
+ this.direction.copy( ray.direction );
4997
+
4998
+ return this;
4999
+
5000
+ },
5001
+
5002
+ at: function ( t, optionalTarget ) {
5003
+
5004
+ var result = optionalTarget || new THREE.Vector3();
5005
+
5006
+ return result.copy( this.direction ).multiplyScalar( t ).add( this.origin );
5007
+
5008
+ },
5009
+
5010
+ recast: function () {
5011
+
5012
+ var v1 = new THREE.Vector3();
5013
+
5014
+ return function ( t ) {
5015
+
5016
+ this.origin.copy( this.at( t, v1 ) );
5017
+
5018
+ return this;
5019
+
5020
+ };
5021
+
5022
+ }(),
5023
+
5024
+ closestPointToPoint: function ( point, optionalTarget ) {
5025
+
5026
+ var result = optionalTarget || new THREE.Vector3();
5027
+ result.subVectors( point, this.origin );
5028
+ var directionDistance = result.dot( this.direction );
5029
+
5030
+ if ( directionDistance < 0 ) {
5031
+
5032
+ return result.copy( this.origin );
5033
+
5034
+ }
5035
+
5036
+ return result.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
5037
+
5038
+ },
5039
+
5040
+ distanceToPoint: function () {
5041
+
5042
+ var v1 = new THREE.Vector3();
5043
+
5044
+ return function ( point ) {
5045
+
5046
+ var directionDistance = v1.subVectors( point, this.origin ).dot( this.direction );
5047
+
5048
+ // point behind the ray
5049
+
5050
+ if ( directionDistance < 0 ) {
5051
+
5052
+ return this.origin.distanceTo( point );
5053
+
5054
+ }
5055
+
5056
+ v1.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
5057
+
5058
+ return v1.distanceTo( point );
5059
+
5060
+ };
5061
+
5062
+ }(),
5063
+
5064
+ distanceSqToSegment: function ( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {
5065
+
5066
+ // from http://www.geometrictools.com/LibMathematics/Distance/Wm5DistRay3Segment3.cpp
5067
+ // It returns the min distance between the ray and the segment
5068
+ // defined by v0 and v1
5069
+ // It can also set two optional targets :
5070
+ // - The closest point on the ray
5071
+ // - The closest point on the segment
5072
+
5073
+ var segCenter = v0.clone().add( v1 ).multiplyScalar( 0.5 );
5074
+ var segDir = v1.clone().sub( v0 ).normalize();
5075
+ var segExtent = v0.distanceTo( v1 ) * 0.5;
5076
+ var diff = this.origin.clone().sub( segCenter );
5077
+ var a01 = - this.direction.dot( segDir );
5078
+ var b0 = diff.dot( this.direction );
5079
+ var b1 = - diff.dot( segDir );
5080
+ var c = diff.lengthSq();
5081
+ var det = Math.abs( 1 - a01 * a01 );
5082
+ var s0, s1, sqrDist, extDet;
5083
+
5084
+ if ( det >= 0 ) {
5085
+
5086
+ // The ray and segment are not parallel.
5087
+
5088
+ s0 = a01 * b1 - b0;
5089
+ s1 = a01 * b0 - b1;
5090
+ extDet = segExtent * det;
5091
+
5092
+ if ( s0 >= 0 ) {
5093
+
5094
+ if ( s1 >= - extDet ) {
5095
+
5096
+ if ( s1 <= extDet ) {
5097
+
5098
+ // region 0
5099
+ // Minimum at interior points of ray and segment.
5100
+
5101
+ var invDet = 1 / det;
5102
+ s0 *= invDet;
5103
+ s1 *= invDet;
5104
+ sqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c;
5105
+
5106
+ } else {
5107
+
5108
+ // region 1
5109
+
5110
+ s1 = segExtent;
5111
+ s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
5112
+ sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
5113
+
5114
+ }
5115
+
5116
+ } else {
5117
+
5118
+ // region 5
5119
+
5120
+ s1 = - segExtent;
5121
+ s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
5122
+ sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
5123
+
5124
+ }
5125
+
5126
+ } else {
5127
+
5128
+ if ( s1 <= - extDet ) {
5129
+
5130
+ // region 4
5131
+
5132
+ s0 = Math.max( 0, - ( - a01 * segExtent + b0 ) );
5133
+ s1 = ( s0 > 0 ) ? - segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
5134
+ sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
5135
+
5136
+ } else if ( s1 <= extDet ) {
5137
+
5138
+ // region 3
5139
+
5140
+ s0 = 0;
5141
+ s1 = Math.min( Math.max( - segExtent, - b1 ), segExtent );
5142
+ sqrDist = s1 * ( s1 + 2 * b1 ) + c;
5143
+
5144
+ } else {
5145
+
5146
+ // region 2
5147
+
5148
+ s0 = Math.max( 0, - ( a01 * segExtent + b0 ) );
5149
+ s1 = ( s0 > 0 ) ? segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
5150
+ sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
5151
+
5152
+ }
5153
+
5154
+ }
5155
+
5156
+ } else {
5157
+
5158
+ // Ray and segment are parallel.
5159
+
5160
+ s1 = ( a01 > 0 ) ? - segExtent : segExtent;
5161
+ s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
5162
+ sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
5163
+
5164
+ }
5165
+
5166
+ if ( optionalPointOnRay ) {
5167
+
5168
+ optionalPointOnRay.copy( this.direction.clone().multiplyScalar( s0 ).add( this.origin ) );
5169
+
5170
+ }
5171
+
5172
+ if ( optionalPointOnSegment ) {
5173
+
5174
+ optionalPointOnSegment.copy( segDir.clone().multiplyScalar( s1 ).add( segCenter ) );
5175
+
5176
+ }
5177
+
5178
+ return sqrDist;
5179
+
5180
+ },
5181
+
5182
+ isIntersectionSphere: function ( sphere ) {
5183
+
5184
+ return this.distanceToPoint( sphere.center ) <= sphere.radius;
5185
+
5186
+ },
5187
+
5188
+ intersectSphere: function () {
5189
+
5190
+ // from http://www.scratchapixel.com/lessons/3d-basic-lessons/lesson-7-intersecting-simple-shapes/ray-sphere-intersection/
5191
+
5192
+ var v1 = new THREE.Vector3();
5193
+
5194
+ return function ( sphere, optionalTarget ) {
5195
+
5196
+ v1.subVectors( sphere.center, this.origin );
5197
+
5198
+ var tca = v1.dot( this.direction );
5199
+
5200
+ var d2 = v1.dot( v1 ) - tca * tca;
5201
+
5202
+ var radius2 = sphere.radius * sphere.radius;
5203
+
5204
+ if ( d2 > radius2 ) return null;
5205
+
5206
+ var thc = Math.sqrt( radius2 - d2 );
5207
+
5208
+ // t0 = first intersect point - entrance on front of sphere
5209
+ var t0 = tca - thc;
5210
+
5211
+ // t1 = second intersect point - exit point on back of sphere
5212
+ var t1 = tca + thc;
5213
+
5214
+ // test to see if both t0 and t1 are behind the ray - if so, return null
5215
+ if ( t0 < 0 && t1 < 0 ) return null;
5216
+
5217
+ // test to see if t0 is behind the ray:
5218
+ // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
5219
+ // in order to always return an intersect point that is in front of the ray.
5220
+ if ( t0 < 0 ) return this.at( t1, optionalTarget );
5221
+
5222
+ // else t0 is in front of the ray, so return the first collision point scaled by t0
5223
+ return this.at( t0, optionalTarget );
5224
+
5225
+ }
5226
+
5227
+ }(),
5228
+
5229
+ isIntersectionPlane: function ( plane ) {
5230
+
5231
+ // check if the ray lies on the plane first
5232
+
5233
+ var distToPoint = plane.distanceToPoint( this.origin );
5234
+
5235
+ if ( distToPoint === 0 ) {
5236
+
5237
+ return true;
5238
+
5239
+ }
5240
+
5241
+ var denominator = plane.normal.dot( this.direction );
5242
+
5243
+ if ( denominator * distToPoint < 0 ) {
5244
+
5245
+ return true;
5246
+
5247
+ }
5248
+
5249
+ // ray origin is behind the plane (and is pointing behind it)
5250
+
5251
+ return false;
5252
+
5253
+ },
5254
+
5255
+ distanceToPlane: function ( plane ) {
5256
+
5257
+ var denominator = plane.normal.dot( this.direction );
5258
+ if ( denominator == 0 ) {
5259
+
5260
+ // line is coplanar, return origin
5261
+ if ( plane.distanceToPoint( this.origin ) == 0 ) {
5262
+
5263
+ return 0;
5264
+
5265
+ }
5266
+
5267
+ // Null is preferable to undefined since undefined means.... it is undefined
5268
+
5269
+ return null;
5270
+
5271
+ }
5272
+
5273
+ var t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator;
5274
+
5275
+ // Return if the ray never intersects the plane
5276
+
5277
+ return t >= 0 ? t : null;
5278
+
5279
+ },
5280
+
5281
+ intersectPlane: function ( plane, optionalTarget ) {
5282
+
5283
+ var t = this.distanceToPlane( plane );
5284
+
5285
+ if ( t === null ) {
5286
+
5287
+ return null;
5288
+ }
5289
+
5290
+ return this.at( t, optionalTarget );
5291
+
5292
+ },
5293
+
5294
+ isIntersectionBox: function () {
5295
+
5296
+ var v = new THREE.Vector3();
5297
+
5298
+ return function ( box ) {
5299
+
5300
+ return this.intersectBox( box, v ) !== null;
5301
+
5302
+ };
5303
+
5304
+ }(),
5305
+
5306
+ intersectBox: function ( box , optionalTarget ) {
5307
+
5308
+ // http://www.scratchapixel.com/lessons/3d-basic-lessons/lesson-7-intersecting-simple-shapes/ray-box-intersection/
5309
+
5310
+ var tmin,tmax,tymin,tymax,tzmin,tzmax;
5311
+
5312
+ var invdirx = 1 / this.direction.x,
5313
+ invdiry = 1 / this.direction.y,
5314
+ invdirz = 1 / this.direction.z;
5315
+
5316
+ var origin = this.origin;
5317
+
5318
+ if ( invdirx >= 0 ) {
5319
+
5320
+ tmin = ( box.min.x - origin.x ) * invdirx;
5321
+ tmax = ( box.max.x - origin.x ) * invdirx;
5322
+
5323
+ } else {
5324
+
5325
+ tmin = ( box.max.x - origin.x ) * invdirx;
5326
+ tmax = ( box.min.x - origin.x ) * invdirx;
5327
+ }
5328
+
5329
+ if ( invdiry >= 0 ) {
5330
+
5331
+ tymin = ( box.min.y - origin.y ) * invdiry;
5332
+ tymax = ( box.max.y - origin.y ) * invdiry;
5333
+
5334
+ } else {
5335
+
5336
+ tymin = ( box.max.y - origin.y ) * invdiry;
5337
+ tymax = ( box.min.y - origin.y ) * invdiry;
5338
+ }
5339
+
5340
+ if ( ( tmin > tymax ) || ( tymin > tmax ) ) return null;
5341
+
5342
+ // These lines also handle the case where tmin or tmax is NaN
5343
+ // (result of 0 * Infinity). x !== x returns true if x is NaN
5344
+
5345
+ if ( tymin > tmin || tmin !== tmin ) tmin = tymin;
5346
+
5347
+ if ( tymax < tmax || tmax !== tmax ) tmax = tymax;
5348
+
5349
+ if ( invdirz >= 0 ) {
5350
+
5351
+ tzmin = ( box.min.z - origin.z ) * invdirz;
5352
+ tzmax = ( box.max.z - origin.z ) * invdirz;
5353
+
5354
+ } else {
5355
+
5356
+ tzmin = ( box.max.z - origin.z ) * invdirz;
5357
+ tzmax = ( box.min.z - origin.z ) * invdirz;
5358
+ }
5359
+
5360
+ if ( ( tmin > tzmax ) || ( tzmin > tmax ) ) return null;
5361
+
5362
+ if ( tzmin > tmin || tmin !== tmin ) tmin = tzmin;
5363
+
5364
+ if ( tzmax < tmax || tmax !== tmax ) tmax = tzmax;
5365
+
5366
+ //return point closest to the ray (positive side)
5367
+
5368
+ if ( tmax < 0 ) return null;
5369
+
5370
+ return this.at( tmin >= 0 ? tmin : tmax, optionalTarget );
5371
+
5372
+ },
5373
+
5374
+ intersectTriangle: function () {
5375
+
5376
+ // Compute the offset origin, edges, and normal.
5377
+ var diff = new THREE.Vector3();
5378
+ var edge1 = new THREE.Vector3();
5379
+ var edge2 = new THREE.Vector3();
5380
+ var normal = new THREE.Vector3();
5381
+
5382
+ return function ( a, b, c, backfaceCulling, optionalTarget ) {
5383
+
5384
+ // from http://www.geometrictools.com/LibMathematics/Intersection/Wm5IntrRay3Triangle3.cpp
5385
+
5386
+ edge1.subVectors( b, a );
5387
+ edge2.subVectors( c, a );
5388
+ normal.crossVectors( edge1, edge2 );
5389
+
5390
+ // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
5391
+ // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
5392
+ // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
5393
+ // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
5394
+ // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
5395
+ var DdN = this.direction.dot( normal );
5396
+ var sign;
5397
+
5398
+ if ( DdN > 0 ) {
5399
+
5400
+ if ( backfaceCulling ) return null;
5401
+ sign = 1;
5402
+
5403
+ } else if ( DdN < 0 ) {
5404
+
5405
+ sign = - 1;
5406
+ DdN = - DdN;
5407
+
5408
+ } else {
5409
+
5410
+ return null;
5411
+
5412
+ }
5413
+
5414
+ diff.subVectors( this.origin, a );
5415
+ var DdQxE2 = sign * this.direction.dot( edge2.crossVectors( diff, edge2 ) );
5416
+
5417
+ // b1 < 0, no intersection
5418
+ if ( DdQxE2 < 0 ) {
5419
+
5420
+ return null;
5421
+
5422
+ }
5423
+
5424
+ var DdE1xQ = sign * this.direction.dot( edge1.cross( diff ) );
5425
+
5426
+ // b2 < 0, no intersection
5427
+ if ( DdE1xQ < 0 ) {
5428
+
5429
+ return null;
5430
+
5431
+ }
5432
+
5433
+ // b1+b2 > 1, no intersection
5434
+ if ( DdQxE2 + DdE1xQ > DdN ) {
5435
+
5436
+ return null;
5437
+
5438
+ }
5439
+
5440
+ // Line intersects triangle, check if ray does.
5441
+ var QdN = - sign * diff.dot( normal );
5442
+
5443
+ // t < 0, no intersection
5444
+ if ( QdN < 0 ) {
5445
+
5446
+ return null;
5447
+
5448
+ }
5449
+
5450
+ // Ray intersects triangle.
5451
+ return this.at( QdN / DdN, optionalTarget );
5452
+
5453
+ };
5454
+
5455
+ }(),
5456
+
5457
+ applyMatrix4: function ( matrix4 ) {
5458
+
5459
+ this.direction.add( this.origin ).applyMatrix4( matrix4 );
5460
+ this.origin.applyMatrix4( matrix4 );
5461
+ this.direction.sub( this.origin );
5462
+ this.direction.normalize();
5463
+
5464
+ return this;
5465
+ },
5466
+
5467
+ equals: function ( ray ) {
5468
+
5469
+ return ray.origin.equals( this.origin ) && ray.direction.equals( this.direction );
5470
+
5471
+ },
5472
+
5473
+ clone: function () {
5474
+
5475
+ return new THREE.Ray().copy( this );
5476
+
5477
+ }
5478
+
5479
+ };
5480
+
5481
+ // File:src/math/Sphere.js
5482
+
5483
+ /**
5484
+ * @author bhouston / http://exocortex.com
5485
+ * @author mrdoob / http://mrdoob.com/
5486
+ */
5487
+
5488
+ THREE.Sphere = function ( center, radius ) {
5489
+
5490
+ this.center = ( center !== undefined ) ? center : new THREE.Vector3();
5491
+ this.radius = ( radius !== undefined ) ? radius : 0;
5492
+
5493
+ };
5494
+
5495
+ THREE.Sphere.prototype = {
5496
+
5497
+ constructor: THREE.Sphere,
5498
+
5499
+ set: function ( center, radius ) {
5500
+
5501
+ this.center.copy( center );
5502
+ this.radius = radius;
5503
+
5504
+ return this;
5505
+ },
5506
+
5507
+ setFromPoints: function () {
5508
+
5509
+ var box = new THREE.Box3();
5510
+
5511
+ return function ( points, optionalCenter ) {
5512
+
5513
+ var center = this.center;
5514
+
5515
+ if ( optionalCenter !== undefined ) {
5516
+
5517
+ center.copy( optionalCenter );
5518
+
5519
+ } else {
5520
+
5521
+ box.setFromPoints( points ).center( center );
5522
+
5523
+ }
5524
+
5525
+ var maxRadiusSq = 0;
5526
+
5527
+ for ( var i = 0, il = points.length; i < il; i ++ ) {
5528
+
5529
+ maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) );
5530
+
5531
+ }
5532
+
5533
+ this.radius = Math.sqrt( maxRadiusSq );
5534
+
5535
+ return this;
5536
+
5537
+ };
5538
+
5539
+ }(),
5540
+
5541
+ copy: function ( sphere ) {
5542
+
5543
+ this.center.copy( sphere.center );
5544
+ this.radius = sphere.radius;
5545
+
5546
+ return this;
5547
+
5548
+ },
5549
+
5550
+ empty: function () {
5551
+
5552
+ return ( this.radius <= 0 );
5553
+
5554
+ },
5555
+
5556
+ containsPoint: function ( point ) {
5557
+
5558
+ return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );
5559
+
5560
+ },
5561
+
5562
+ distanceToPoint: function ( point ) {
5563
+
5564
+ return ( point.distanceTo( this.center ) - this.radius );
5565
+
5566
+ },
5567
+
5568
+ intersectsSphere: function ( sphere ) {
5569
+
5570
+ var radiusSum = this.radius + sphere.radius;
5571
+
5572
+ return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum );
5573
+
5574
+ },
5575
+
5576
+ clampPoint: function ( point, optionalTarget ) {
5577
+
5578
+ var deltaLengthSq = this.center.distanceToSquared( point );
5579
+
5580
+ var result = optionalTarget || new THREE.Vector3();
5581
+ result.copy( point );
5582
+
5583
+ if ( deltaLengthSq > ( this.radius * this.radius ) ) {
5584
+
5585
+ result.sub( this.center ).normalize();
5586
+ result.multiplyScalar( this.radius ).add( this.center );
5587
+
5588
+ }
5589
+
5590
+ return result;
5591
+
5592
+ },
5593
+
5594
+ getBoundingBox: function ( optionalTarget ) {
5595
+
5596
+ var box = optionalTarget || new THREE.Box3();
5597
+
5598
+ box.set( this.center, this.center );
5599
+ box.expandByScalar( this.radius );
5600
+
5601
+ return box;
5602
+
5603
+ },
5604
+
5605
+ applyMatrix4: function ( matrix ) {
5606
+
5607
+ this.center.applyMatrix4( matrix );
5608
+ this.radius = this.radius * matrix.getMaxScaleOnAxis();
5609
+
5610
+ return this;
5611
+
5612
+ },
5613
+
5614
+ translate: function ( offset ) {
5615
+
5616
+ this.center.add( offset );
5617
+
5618
+ return this;
5619
+
5620
+ },
5621
+
5622
+ equals: function ( sphere ) {
5623
+
5624
+ return sphere.center.equals( this.center ) && ( sphere.radius === this.radius );
5625
+
5626
+ },
5627
+
5628
+ clone: function () {
5629
+
5630
+ return new THREE.Sphere().copy( this );
5631
+
5632
+ }
5633
+
5634
+ };
5635
+
5636
+ // File:src/math/Frustum.js
5637
+
5638
+ /**
5639
+ * @author mrdoob / http://mrdoob.com/
5640
+ * @author alteredq / http://alteredqualia.com/
5641
+ * @author bhouston / http://exocortex.com
5642
+ */
5643
+
5644
+ THREE.Frustum = function ( p0, p1, p2, p3, p4, p5 ) {
5645
+
5646
+ this.planes = [
5647
+
5648
+ ( p0 !== undefined ) ? p0 : new THREE.Plane(),
5649
+ ( p1 !== undefined ) ? p1 : new THREE.Plane(),
5650
+ ( p2 !== undefined ) ? p2 : new THREE.Plane(),
5651
+ ( p3 !== undefined ) ? p3 : new THREE.Plane(),
5652
+ ( p4 !== undefined ) ? p4 : new THREE.Plane(),
5653
+ ( p5 !== undefined ) ? p5 : new THREE.Plane()
5654
+
5655
+ ];
5656
+
5657
+ };
5658
+
5659
+ THREE.Frustum.prototype = {
5660
+
5661
+ constructor: THREE.Frustum,
5662
+
5663
+ set: function ( p0, p1, p2, p3, p4, p5 ) {
5664
+
5665
+ var planes = this.planes;
5666
+
5667
+ planes[ 0 ].copy( p0 );
5668
+ planes[ 1 ].copy( p1 );
5669
+ planes[ 2 ].copy( p2 );
5670
+ planes[ 3 ].copy( p3 );
5671
+ planes[ 4 ].copy( p4 );
5672
+ planes[ 5 ].copy( p5 );
5673
+
5674
+ return this;
5675
+
5676
+ },
5677
+
5678
+ copy: function ( frustum ) {
5679
+
5680
+ var planes = this.planes;
5681
+
5682
+ for ( var i = 0; i < 6; i ++ ) {
5683
+
5684
+ planes[ i ].copy( frustum.planes[ i ] );
5685
+
5686
+ }
5687
+
5688
+ return this;
5689
+
5690
+ },
5691
+
5692
+ setFromMatrix: function ( m ) {
5693
+
5694
+ var planes = this.planes;
5695
+ var me = m.elements;
5696
+ var me0 = me[ 0 ], me1 = me[ 1 ], me2 = me[ 2 ], me3 = me[ 3 ];
5697
+ var me4 = me[ 4 ], me5 = me[ 5 ], me6 = me[ 6 ], me7 = me[ 7 ];
5698
+ var me8 = me[ 8 ], me9 = me[ 9 ], me10 = me[ 10 ], me11 = me[ 11 ];
5699
+ var me12 = me[ 12 ], me13 = me[ 13 ], me14 = me[ 14 ], me15 = me[ 15 ];
5700
+
5701
+ planes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ).normalize();
5702
+ planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize();
5703
+ planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize();
5704
+ planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize();
5705
+ planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize();
5706
+ planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize();
5707
+
5708
+ return this;
5709
+
5710
+ },
5711
+
5712
+ intersectsObject: function () {
5713
+
5714
+ var sphere = new THREE.Sphere();
5715
+
5716
+ return function ( object ) {
5717
+
5718
+ var geometry = object.geometry;
5719
+
5720
+ if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
5721
+
5722
+ sphere.copy( geometry.boundingSphere );
5723
+ sphere.applyMatrix4( object.matrixWorld );
5724
+
5725
+ return this.intersectsSphere( sphere );
5726
+
5727
+ };
5728
+
5729
+ }(),
5730
+
5731
+ intersectsSphere: function ( sphere ) {
5732
+
5733
+ var planes = this.planes;
5734
+ var center = sphere.center;
5735
+ var negRadius = - sphere.radius;
5736
+
5737
+ for ( var i = 0; i < 6; i ++ ) {
5738
+
5739
+ var distance = planes[ i ].distanceToPoint( center );
5740
+
5741
+ if ( distance < negRadius ) {
5742
+
5743
+ return false;
5744
+
5745
+ }
5746
+
5747
+ }
5748
+
5749
+ return true;
5750
+
5751
+ },
5752
+
5753
+ intersectsBox: function () {
5754
+
5755
+ var p1 = new THREE.Vector3(),
5756
+ p2 = new THREE.Vector3();
5757
+
5758
+ return function ( box ) {
5759
+
5760
+ var planes = this.planes;
5761
+
5762
+ for ( var i = 0; i < 6 ; i ++ ) {
5763
+
5764
+ var plane = planes[ i ];
5765
+
5766
+ p1.x = plane.normal.x > 0 ? box.min.x : box.max.x;
5767
+ p2.x = plane.normal.x > 0 ? box.max.x : box.min.x;
5768
+ p1.y = plane.normal.y > 0 ? box.min.y : box.max.y;
5769
+ p2.y = plane.normal.y > 0 ? box.max.y : box.min.y;
5770
+ p1.z = plane.normal.z > 0 ? box.min.z : box.max.z;
5771
+ p2.z = plane.normal.z > 0 ? box.max.z : box.min.z;
5772
+
5773
+ var d1 = plane.distanceToPoint( p1 );
5774
+ var d2 = plane.distanceToPoint( p2 );
5775
+
5776
+ // if both outside plane, no intersection
5777
+
5778
+ if ( d1 < 0 && d2 < 0 ) {
5779
+
5780
+ return false;
5781
+
5782
+ }
5783
+ }
5784
+
5785
+ return true;
5786
+ };
5787
+
5788
+ }(),
5789
+
5790
+
5791
+ containsPoint: function ( point ) {
5792
+
5793
+ var planes = this.planes;
5794
+
5795
+ for ( var i = 0; i < 6; i ++ ) {
5796
+
5797
+ if ( planes[ i ].distanceToPoint( point ) < 0 ) {
5798
+
5799
+ return false;
5800
+
5801
+ }
5802
+
5803
+ }
5804
+
5805
+ return true;
5806
+
5807
+ },
5808
+
5809
+ clone: function () {
5810
+
5811
+ return new THREE.Frustum().copy( this );
5812
+
5813
+ }
5814
+
5815
+ };
5816
+
5817
+ // File:src/math/Plane.js
5818
+
5819
+ /**
5820
+ * @author bhouston / http://exocortex.com
5821
+ */
5822
+
5823
+ THREE.Plane = function ( normal, constant ) {
5824
+
5825
+ this.normal = ( normal !== undefined ) ? normal : new THREE.Vector3( 1, 0, 0 );
5826
+ this.constant = ( constant !== undefined ) ? constant : 0;
5827
+
5828
+ };
5829
+
5830
+ THREE.Plane.prototype = {
5831
+
5832
+ constructor: THREE.Plane,
5833
+
5834
+ set: function ( normal, constant ) {
5835
+
5836
+ this.normal.copy( normal );
5837
+ this.constant = constant;
5838
+
5839
+ return this;
5840
+
5841
+ },
5842
+
5843
+ setComponents: function ( x, y, z, w ) {
5844
+
5845
+ this.normal.set( x, y, z );
5846
+ this.constant = w;
5847
+
5848
+ return this;
5849
+
5850
+ },
5851
+
5852
+ setFromNormalAndCoplanarPoint: function ( normal, point ) {
5853
+
5854
+ this.normal.copy( normal );
5855
+ this.constant = - point.dot( this.normal ); // must be this.normal, not normal, as this.normal is normalized
5856
+
5857
+ return this;
5858
+
5859
+ },
5860
+
5861
+ setFromCoplanarPoints: function () {
5862
+
5863
+ var v1 = new THREE.Vector3();
5864
+ var v2 = new THREE.Vector3();
5865
+
5866
+ return function ( a, b, c ) {
5867
+
5868
+ var normal = v1.subVectors( c, b ).cross( v2.subVectors( a, b ) ).normalize();
5869
+
5870
+ // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
5871
+
5872
+ this.setFromNormalAndCoplanarPoint( normal, a );
5873
+
5874
+ return this;
5875
+
5876
+ };
5877
+
5878
+ }(),
5879
+
5880
+
5881
+ copy: function ( plane ) {
5882
+
5883
+ this.normal.copy( plane.normal );
5884
+ this.constant = plane.constant;
5885
+
5886
+ return this;
5887
+
5888
+ },
5889
+
5890
+ normalize: function () {
5891
+
5892
+ // Note: will lead to a divide by zero if the plane is invalid.
5893
+
5894
+ var inverseNormalLength = 1.0 / this.normal.length();
5895
+ this.normal.multiplyScalar( inverseNormalLength );
5896
+ this.constant *= inverseNormalLength;
5897
+
5898
+ return this;
5899
+
5900
+ },
5901
+
5902
+ negate: function () {
5903
+
5904
+ this.constant *= - 1;
5905
+ this.normal.negate();
5906
+
5907
+ return this;
5908
+
5909
+ },
5910
+
5911
+ distanceToPoint: function ( point ) {
5912
+
5913
+ return this.normal.dot( point ) + this.constant;
5914
+
5915
+ },
5916
+
5917
+ distanceToSphere: function ( sphere ) {
5918
+
5919
+ return this.distanceToPoint( sphere.center ) - sphere.radius;
5920
+
5921
+ },
5922
+
5923
+ projectPoint: function ( point, optionalTarget ) {
5924
+
5925
+ return this.orthoPoint( point, optionalTarget ).sub( point ).negate();
5926
+
5927
+ },
5928
+
5929
+ orthoPoint: function ( point, optionalTarget ) {
5930
+
5931
+ var perpendicularMagnitude = this.distanceToPoint( point );
5932
+
5933
+ var result = optionalTarget || new THREE.Vector3();
5934
+ return result.copy( this.normal ).multiplyScalar( perpendicularMagnitude );
5935
+
5936
+ },
5937
+
5938
+ isIntersectionLine: function ( line ) {
5939
+
5940
+ // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
5941
+
5942
+ var startSign = this.distanceToPoint( line.start );
5943
+ var endSign = this.distanceToPoint( line.end );
5944
+
5945
+ return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
5946
+
5947
+ },
5948
+
5949
+ intersectLine: function () {
5950
+
5951
+ var v1 = new THREE.Vector3();
5952
+
5953
+ return function ( line, optionalTarget ) {
5954
+
5955
+ var result = optionalTarget || new THREE.Vector3();
5956
+
5957
+ var direction = line.delta( v1 );
5958
+
5959
+ var denominator = this.normal.dot( direction );
5960
+
5961
+ if ( denominator == 0 ) {
5962
+
5963
+ // line is coplanar, return origin
5964
+ if ( this.distanceToPoint( line.start ) == 0 ) {
5965
+
5966
+ return result.copy( line.start );
5967
+
5968
+ }
5969
+
5970
+ // Unsure if this is the correct method to handle this case.
5971
+ return undefined;
5972
+
5973
+ }
5974
+
5975
+ var t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;
5976
+
5977
+ if ( t < 0 || t > 1 ) {
5978
+
5979
+ return undefined;
5980
+
5981
+ }
5982
+
5983
+ return result.copy( direction ).multiplyScalar( t ).add( line.start );
5984
+
5985
+ };
5986
+
5987
+ }(),
5988
+
5989
+
5990
+ coplanarPoint: function ( optionalTarget ) {
5991
+
5992
+ var result = optionalTarget || new THREE.Vector3();
5993
+ return result.copy( this.normal ).multiplyScalar( - this.constant );
5994
+
5995
+ },
5996
+
5997
+ applyMatrix4: function () {
5998
+
5999
+ var v1 = new THREE.Vector3();
6000
+ var v2 = new THREE.Vector3();
6001
+ var m1 = new THREE.Matrix3();
6002
+
6003
+ return function ( matrix, optionalNormalMatrix ) {
6004
+
6005
+ // compute new normal based on theory here:
6006
+ // http://www.songho.ca/opengl/gl_normaltransform.html
6007
+ var normalMatrix = optionalNormalMatrix || m1.getNormalMatrix( matrix );
6008
+ var newNormal = v1.copy( this.normal ).applyMatrix3( normalMatrix );
6009
+
6010
+ var newCoplanarPoint = this.coplanarPoint( v2 );
6011
+ newCoplanarPoint.applyMatrix4( matrix );
6012
+
6013
+ this.setFromNormalAndCoplanarPoint( newNormal, newCoplanarPoint );
6014
+
6015
+ return this;
6016
+
6017
+ };
6018
+
6019
+ }(),
6020
+
6021
+ translate: function ( offset ) {
6022
+
6023
+ this.constant = this.constant - offset.dot( this.normal );
6024
+
6025
+ return this;
6026
+
6027
+ },
6028
+
6029
+ equals: function ( plane ) {
6030
+
6031
+ return plane.normal.equals( this.normal ) && ( plane.constant == this.constant );
6032
+
6033
+ },
6034
+
6035
+ clone: function () {
6036
+
6037
+ return new THREE.Plane().copy( this );
6038
+
6039
+ }
6040
+
6041
+ };
6042
+
6043
+ // File:src/math/Math.js
6044
+
6045
+ /**
6046
+ * @author alteredq / http://alteredqualia.com/
6047
+ * @author mrdoob / http://mrdoob.com/
6048
+ */
6049
+
6050
+ THREE.Math = {
6051
+
6052
+ generateUUID: function () {
6053
+
6054
+ // http://www.broofa.com/Tools/Math.uuid.htm
6055
+
6056
+ var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split( '' );
6057
+ var uuid = new Array( 36 );
6058
+ var rnd = 0, r;
6059
+
6060
+ return function () {
6061
+
6062
+ for ( var i = 0; i < 36; i ++ ) {
6063
+
6064
+ if ( i == 8 || i == 13 || i == 18 || i == 23 ) {
6065
+
6066
+ uuid[ i ] = '-';
6067
+
6068
+ } else if ( i == 14 ) {
6069
+
6070
+ uuid[ i ] = '4';
6071
+
6072
+ } else {
6073
+
6074
+ if ( rnd <= 0x02 ) rnd = 0x2000000 + ( Math.random() * 0x1000000 ) | 0;
6075
+ r = rnd & 0xf;
6076
+ rnd = rnd >> 4;
6077
+ uuid[ i ] = chars[ ( i == 19 ) ? ( r & 0x3 ) | 0x8 : r ];
6078
+
6079
+ }
6080
+ }
6081
+
6082
+ return uuid.join( '' );
6083
+
6084
+ };
6085
+
6086
+ }(),
6087
+
6088
+ // Clamp value to range <a, b>
6089
+
6090
+ clamp: function ( x, a, b ) {
6091
+
6092
+ return ( x < a ) ? a : ( ( x > b ) ? b : x );
6093
+
6094
+ },
6095
+
6096
+ // Clamp value to range <a, inf)
6097
+
6098
+ clampBottom: function ( x, a ) {
6099
+
6100
+ return x < a ? a : x;
6101
+
6102
+ },
6103
+
6104
+ // Linear mapping from range <a1, a2> to range <b1, b2>
6105
+
6106
+ mapLinear: function ( x, a1, a2, b1, b2 ) {
6107
+
6108
+ return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 );
6109
+
6110
+ },
6111
+
6112
+ // http://en.wikipedia.org/wiki/Smoothstep
6113
+
6114
+ smoothstep: function ( x, min, max ) {
6115
+
6116
+ if ( x <= min ) return 0;
6117
+ if ( x >= max ) return 1;
6118
+
6119
+ x = ( x - min ) / ( max - min );
6120
+
6121
+ return x * x * ( 3 - 2 * x );
6122
+
6123
+ },
6124
+
6125
+ smootherstep: function ( x, min, max ) {
6126
+
6127
+ if ( x <= min ) return 0;
6128
+ if ( x >= max ) return 1;
6129
+
6130
+ x = ( x - min ) / ( max - min );
6131
+
6132
+ return x * x * x * ( x * ( x * 6 - 15 ) + 10 );
6133
+
6134
+ },
6135
+
6136
+ // Random float from <0, 1> with 16 bits of randomness
6137
+ // (standard Math.random() creates repetitive patterns when applied over larger space)
6138
+
6139
+ random16: function () {
6140
+
6141
+ return ( 65280 * Math.random() + 255 * Math.random() ) / 65535;
6142
+
6143
+ },
6144
+
6145
+ // Random integer from <low, high> interval
6146
+
6147
+ randInt: function ( low, high ) {
6148
+
6149
+ return low + Math.floor( Math.random() * ( high - low + 1 ) );
6150
+
6151
+ },
6152
+
6153
+ // Random float from <low, high> interval
6154
+
6155
+ randFloat: function ( low, high ) {
6156
+
6157
+ return low + Math.random() * ( high - low );
6158
+
6159
+ },
6160
+
6161
+ // Random float from <-range/2, range/2> interval
6162
+
6163
+ randFloatSpread: function ( range ) {
6164
+
6165
+ return range * ( 0.5 - Math.random() );
6166
+
6167
+ },
6168
+
6169
+ degToRad: function () {
6170
+
6171
+ var degreeToRadiansFactor = Math.PI / 180;
6172
+
6173
+ return function ( degrees ) {
6174
+
6175
+ return degrees * degreeToRadiansFactor;
6176
+
6177
+ };
6178
+
6179
+ }(),
6180
+
6181
+ radToDeg: function () {
6182
+
6183
+ var radianToDegreesFactor = 180 / Math.PI;
6184
+
6185
+ return function ( radians ) {
6186
+
6187
+ return radians * radianToDegreesFactor;
6188
+
6189
+ };
6190
+
6191
+ }(),
6192
+
6193
+ isPowerOfTwo: function ( value ) {
6194
+
6195
+ return ( value & ( value - 1 ) ) === 0 && value !== 0;
6196
+
6197
+ }
6198
+
6199
+ };
6200
+
6201
+ // File:src/math/Spline.js
6202
+
6203
+ /**
6204
+ * Spline from Tween.js, slightly optimized (and trashed)
6205
+ * http://sole.github.com/tween.js/examples/05_spline.html
6206
+ *
6207
+ * @author mrdoob / http://mrdoob.com/
6208
+ * @author alteredq / http://alteredqualia.com/
6209
+ */
6210
+
6211
+ THREE.Spline = function ( points ) {
6212
+
6213
+ this.points = points;
6214
+
6215
+ var c = [], v3 = { x: 0, y: 0, z: 0 },
6216
+ point, intPoint, weight, w2, w3,
6217
+ pa, pb, pc, pd;
6218
+
6219
+ this.initFromArray = function ( a ) {
6220
+
6221
+ this.points = [];
6222
+
6223
+ for ( var i = 0; i < a.length; i ++ ) {
6224
+
6225
+ this.points[ i ] = { x: a[ i ][ 0 ], y: a[ i ][ 1 ], z: a[ i ][ 2 ] };
6226
+
6227
+ }
6228
+
6229
+ };
6230
+
6231
+ this.getPoint = function ( k ) {
6232
+
6233
+ point = ( this.points.length - 1 ) * k;
6234
+ intPoint = Math.floor( point );
6235
+ weight = point - intPoint;
6236
+
6237
+ c[ 0 ] = intPoint === 0 ? intPoint : intPoint - 1;
6238
+ c[ 1 ] = intPoint;
6239
+ c[ 2 ] = intPoint > this.points.length - 2 ? this.points.length - 1 : intPoint + 1;
6240
+ c[ 3 ] = intPoint > this.points.length - 3 ? this.points.length - 1 : intPoint + 2;
6241
+
6242
+ pa = this.points[ c[ 0 ] ];
6243
+ pb = this.points[ c[ 1 ] ];
6244
+ pc = this.points[ c[ 2 ] ];
6245
+ pd = this.points[ c[ 3 ] ];
6246
+
6247
+ w2 = weight * weight;
6248
+ w3 = weight * w2;
6249
+
6250
+ v3.x = interpolate( pa.x, pb.x, pc.x, pd.x, weight, w2, w3 );
6251
+ v3.y = interpolate( pa.y, pb.y, pc.y, pd.y, weight, w2, w3 );
6252
+ v3.z = interpolate( pa.z, pb.z, pc.z, pd.z, weight, w2, w3 );
6253
+
6254
+ return v3;
6255
+
6256
+ };
6257
+
6258
+ this.getControlPointsArray = function () {
6259
+
6260
+ var i, p, l = this.points.length,
6261
+ coords = [];
6262
+
6263
+ for ( i = 0; i < l; i ++ ) {
6264
+
6265
+ p = this.points[ i ];
6266
+ coords[ i ] = [ p.x, p.y, p.z ];
6267
+
6268
+ }
6269
+
6270
+ return coords;
6271
+
6272
+ };
6273
+
6274
+ // approximate length by summing linear segments
6275
+
6276
+ this.getLength = function ( nSubDivisions ) {
6277
+
6278
+ var i, index, nSamples, position,
6279
+ point = 0, intPoint = 0, oldIntPoint = 0,
6280
+ oldPosition = new THREE.Vector3(),
6281
+ tmpVec = new THREE.Vector3(),
6282
+ chunkLengths = [],
6283
+ totalLength = 0;
6284
+
6285
+ // first point has 0 length
6286
+
6287
+ chunkLengths[ 0 ] = 0;
6288
+
6289
+ if ( ! nSubDivisions ) nSubDivisions = 100;
6290
+
6291
+ nSamples = this.points.length * nSubDivisions;
6292
+
6293
+ oldPosition.copy( this.points[ 0 ] );
6294
+
6295
+ for ( i = 1; i < nSamples; i ++ ) {
6296
+
6297
+ index = i / nSamples;
6298
+
6299
+ position = this.getPoint( index );
6300
+ tmpVec.copy( position );
6301
+
6302
+ totalLength += tmpVec.distanceTo( oldPosition );
6303
+
6304
+ oldPosition.copy( position );
6305
+
6306
+ point = ( this.points.length - 1 ) * index;
6307
+ intPoint = Math.floor( point );
6308
+
6309
+ if ( intPoint != oldIntPoint ) {
6310
+
6311
+ chunkLengths[ intPoint ] = totalLength;
6312
+ oldIntPoint = intPoint;
6313
+
6314
+ }
6315
+
6316
+ }
6317
+
6318
+ // last point ends with total length
6319
+
6320
+ chunkLengths[ chunkLengths.length ] = totalLength;
6321
+
6322
+ return { chunks: chunkLengths, total: totalLength };
6323
+
6324
+ };
6325
+
6326
+ this.reparametrizeByArcLength = function ( samplingCoef ) {
6327
+
6328
+ var i, j,
6329
+ index, indexCurrent, indexNext,
6330
+ linearDistance, realDistance,
6331
+ sampling, position,
6332
+ newpoints = [],
6333
+ tmpVec = new THREE.Vector3(),
6334
+ sl = this.getLength();
6335
+
6336
+ newpoints.push( tmpVec.copy( this.points[ 0 ] ).clone() );
6337
+
6338
+ for ( i = 1; i < this.points.length; i ++ ) {
6339
+
6340
+ //tmpVec.copy( this.points[ i - 1 ] );
6341
+ //linearDistance = tmpVec.distanceTo( this.points[ i ] );
6342
+
6343
+ realDistance = sl.chunks[ i ] - sl.chunks[ i - 1 ];
6344
+
6345
+ sampling = Math.ceil( samplingCoef * realDistance / sl.total );
6346
+
6347
+ indexCurrent = ( i - 1 ) / ( this.points.length - 1 );
6348
+ indexNext = i / ( this.points.length - 1 );
6349
+
6350
+ for ( j = 1; j < sampling - 1; j ++ ) {
6351
+
6352
+ index = indexCurrent + j * ( 1 / sampling ) * ( indexNext - indexCurrent );
6353
+
6354
+ position = this.getPoint( index );
6355
+ newpoints.push( tmpVec.copy( position ).clone() );
6356
+
6357
+ }
6358
+
6359
+ newpoints.push( tmpVec.copy( this.points[ i ] ).clone() );
6360
+
6361
+ }
6362
+
6363
+ this.points = newpoints;
6364
+
6365
+ };
6366
+
6367
+ // Catmull-Rom
6368
+
6369
+ function interpolate( p0, p1, p2, p3, t, t2, t3 ) {
6370
+
6371
+ var v0 = ( p2 - p0 ) * 0.5,
6372
+ v1 = ( p3 - p1 ) * 0.5;
6373
+
6374
+ return ( 2 * ( p1 - p2 ) + v0 + v1 ) * t3 + ( - 3 * ( p1 - p2 ) - 2 * v0 - v1 ) * t2 + v0 * t + p1;
6375
+
6376
+ };
6377
+
6378
+ };
6379
+
6380
+ THREE.Clock = function ( autoStart ) {
6381
+
6382
+ this.autoStart = ( autoStart !== undefined ) ? autoStart : true;
6383
+
6384
+ this.startTime = 0;
6385
+ this.oldTime = 0;
6386
+ this.elapsedTime = 0;
6387
+
6388
+ this.running = false;
6389
+
6390
+ };
6391
+
6392
+ THREE.Clock.prototype = {
6393
+
6394
+ constructor: THREE.Clock,
6395
+
6396
+ start: function () {
6397
+
6398
+ this.startTime = self.performance !== undefined && self.performance.now !== undefined
6399
+ ? self.performance.now()
6400
+ : Date.now();
6401
+
6402
+ this.oldTime = this.startTime;
6403
+ this.running = true;
6404
+ },
6405
+
6406
+ stop: function () {
6407
+
6408
+ this.getElapsedTime();
6409
+ this.running = false;
6410
+
6411
+ },
6412
+
6413
+ getElapsedTime: function () {
6414
+
6415
+ this.getDelta();
6416
+ return this.elapsedTime;
6417
+
6418
+ },
6419
+
6420
+ getDelta: function () {
6421
+
6422
+ var diff = 0;
6423
+
6424
+ if ( this.autoStart && ! this.running ) {
6425
+
6426
+ this.start();
6427
+
6428
+ }
6429
+
6430
+ if ( this.running ) {
6431
+
6432
+ var newTime = self.performance !== undefined && self.performance.now !== undefined
6433
+ ? self.performance.now()
6434
+ : Date.now();
6435
+
6436
+ diff = 0.001 * ( newTime - this.oldTime );
6437
+ this.oldTime = newTime;
6438
+
6439
+ this.elapsedTime += diff;
6440
+
6441
+ }
6442
+
6443
+ return diff;
6444
+
6445
+ }
6446
+
6447
+ };
6448
+
6449
+ // File:src/core/EventDispatcher.js
6450
+
6451
+ /**
6452
+ * https://github.com/mrdoob/eventdispatcher.js/
6453
+ */
6454
+
6455
+ THREE.EventDispatcher = function () {}
6456
+
6457
+ THREE.EventDispatcher.prototype = {
6458
+
6459
+ constructor: THREE.EventDispatcher,
6460
+
6461
+ apply: function ( object ) {
6462
+
6463
+ object.addEventListener = THREE.EventDispatcher.prototype.addEventListener;
6464
+ object.hasEventListener = THREE.EventDispatcher.prototype.hasEventListener;
6465
+ object.removeEventListener = THREE.EventDispatcher.prototype.removeEventListener;
6466
+ object.dispatchEvent = THREE.EventDispatcher.prototype.dispatchEvent;
6467
+
6468
+ },
6469
+
6470
+ addEventListener: function ( type, listener ) {
6471
+
6472
+ if ( this._listeners === undefined ) this._listeners = {};
6473
+
6474
+ var listeners = this._listeners;
6475
+
6476
+ if ( listeners[ type ] === undefined ) {
6477
+
6478
+ listeners[ type ] = [];
6479
+
6480
+ }
6481
+
6482
+ if ( listeners[ type ].indexOf( listener ) === - 1 ) {
6483
+
6484
+ listeners[ type ].push( listener );
6485
+
6486
+ }
6487
+
6488
+ },
6489
+
6490
+ hasEventListener: function ( type, listener ) {
6491
+
6492
+ if ( this._listeners === undefined ) return false;
6493
+
6494
+ var listeners = this._listeners;
6495
+
6496
+ if ( listeners[ type ] !== undefined && listeners[ type ].indexOf( listener ) !== - 1 ) {
6497
+
6498
+ return true;
6499
+
6500
+ }
6501
+
6502
+ return false;
6503
+
6504
+ },
6505
+
6506
+ removeEventListener: function ( type, listener ) {
6507
+
6508
+ if ( this._listeners === undefined ) return;
6509
+
6510
+ var listeners = this._listeners;
6511
+ var listenerArray = listeners[ type ];
6512
+
6513
+ if ( listenerArray !== undefined ) {
6514
+
6515
+ var index = listenerArray.indexOf( listener );
6516
+
6517
+ if ( index !== - 1 ) {
6518
+
6519
+ listenerArray.splice( index, 1 );
6520
+
6521
+ }
6522
+
6523
+ }
6524
+
6525
+ },
6526
+
6527
+ dispatchEvent: function ( event ) {
6528
+
6529
+ if ( this._listeners === undefined ) return;
6530
+
6531
+ var listeners = this._listeners;
6532
+ var listenerArray = listeners[ event.type ];
6533
+
6534
+ if ( listenerArray !== undefined ) {
6535
+
6536
+ event.target = this;
6537
+
6538
+ var array = [];
6539
+ var length = listenerArray.length;
6540
+
6541
+ for ( var i = 0; i < length; i ++ ) {
6542
+
6543
+ array[ i ] = listenerArray[ i ];
6544
+
6545
+ }
6546
+
6547
+ for ( var i = 0; i < length; i ++ ) {
6548
+
6549
+ array[ i ].call( this, event );
6550
+
6551
+ }
6552
+
6553
+ }
6554
+
6555
+ }
6556
+
6557
+ };
6558
+
6559
+ // File:src/core/Object3D.js
6560
+
6561
+ /**
6562
+ * @author mrdoob / http://mrdoob.com/
6563
+ * @author mikael emtinger / http://gomo.se/
6564
+ * @author alteredq / http://alteredqualia.com/
6565
+ * @author WestLangley / http://github.com/WestLangley
6566
+ */
6567
+
6568
+ THREE.Object3D = function () {
6569
+
6570
+ Object.defineProperty( this, 'id', { value: THREE.Object3DIdCount ++ } );
6571
+
6572
+ this.uuid = THREE.Math.generateUUID();
6573
+
6574
+ this.name = '';
6575
+ this.type = 'Object3D';
6576
+
6577
+ this.parent = undefined;
6578
+ this.children = [];
6579
+
6580
+ this.up = THREE.Object3D.DefaultUp.clone();
6581
+
6582
+ var scope = this;
6583
+
6584
+ var position = new THREE.Vector3();
6585
+ var rotation = new THREE.Euler();
6586
+ var quaternion = new THREE.Quaternion();
6587
+ var scale = new THREE.Vector3( 1, 1, 1 );
6588
+
6589
+ var onRotationChange = function () {
6590
+ quaternion.setFromEuler( rotation, false );
6591
+ };
6592
+
6593
+ var onQuaternionChange = function () {
6594
+ rotation.setFromQuaternion( quaternion, undefined, false );
6595
+ };
6596
+
6597
+ rotation.onChange( onRotationChange );
6598
+ quaternion.onChange( onQuaternionChange );
6599
+
6600
+ Object.defineProperties( this, {
6601
+ position: {
6602
+ enumerable: true,
6603
+ value: position
6604
+ },
6605
+ rotation: {
6606
+ enumerable: true,
6607
+ value: rotation
6608
+ },
6609
+ quaternion: {
6610
+ enumerable: true,
6611
+ value: quaternion
6612
+ },
6613
+ scale: {
6614
+ enumerable: true,
6615
+ value: scale
6616
+ },
6617
+ } );
6618
+
6619
+ this.renderDepth = null;
6620
+
6621
+ this.rotationAutoUpdate = true;
6622
+
6623
+ this.matrix = new THREE.Matrix4();
6624
+ this.matrixWorld = new THREE.Matrix4();
6625
+
6626
+ this.matrixAutoUpdate = true;
6627
+ this.matrixWorldNeedsUpdate = false;
6628
+
6629
+ this.visible = true;
6630
+
6631
+ this.castShadow = false;
6632
+ this.receiveShadow = false;
6633
+
6634
+ this.frustumCulled = true;
6635
+
6636
+ this.userData = {};
6637
+
6638
+ };
6639
+
6640
+ THREE.Object3D.DefaultUp = new THREE.Vector3( 0, 1, 0 );
6641
+
6642
+ THREE.Object3D.prototype = {
6643
+
6644
+ constructor: THREE.Object3D,
6645
+
6646
+ get eulerOrder () {
6647
+
6648
+ console.warn( 'THREE.Object3D: .eulerOrder has been moved to .rotation.order.' );
6649
+
6650
+ return this.rotation.order;
6651
+
6652
+ },
6653
+
6654
+ set eulerOrder ( value ) {
6655
+
6656
+ console.warn( 'THREE.Object3D: .eulerOrder has been moved to .rotation.order.' );
6657
+
6658
+ this.rotation.order = value;
6659
+
6660
+ },
6661
+
6662
+ get useQuaternion () {
6663
+
6664
+ console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
6665
+
6666
+ },
6667
+
6668
+ set useQuaternion ( value ) {
6669
+
6670
+ console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
6671
+
6672
+ },
6673
+
6674
+ applyMatrix: function ( matrix ) {
6675
+
6676
+ this.matrix.multiplyMatrices( matrix, this.matrix );
6677
+
6678
+ this.matrix.decompose( this.position, this.quaternion, this.scale );
6679
+
6680
+ },
6681
+
6682
+ setRotationFromAxisAngle: function ( axis, angle ) {
6683
+
6684
+ // assumes axis is normalized
6685
+
6686
+ this.quaternion.setFromAxisAngle( axis, angle );
6687
+
6688
+ },
6689
+
6690
+ setRotationFromEuler: function ( euler ) {
6691
+
6692
+ this.quaternion.setFromEuler( euler, true );
6693
+
6694
+ },
6695
+
6696
+ setRotationFromMatrix: function ( m ) {
6697
+
6698
+ // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
6699
+
6700
+ this.quaternion.setFromRotationMatrix( m );
6701
+
6702
+ },
6703
+
6704
+ setRotationFromQuaternion: function ( q ) {
6705
+
6706
+ // assumes q is normalized
6707
+
6708
+ this.quaternion.copy( q );
6709
+
6710
+ },
6711
+
6712
+ rotateOnAxis: function () {
6713
+
6714
+ // rotate object on axis in object space
6715
+ // axis is assumed to be normalized
6716
+
6717
+ var q1 = new THREE.Quaternion();
6718
+
6719
+ return function ( axis, angle ) {
6720
+
6721
+ q1.setFromAxisAngle( axis, angle );
6722
+
6723
+ this.quaternion.multiply( q1 );
6724
+
6725
+ return this;
6726
+
6727
+ }
6728
+
6729
+ }(),
6730
+
6731
+ rotateX: function () {
6732
+
6733
+ var v1 = new THREE.Vector3( 1, 0, 0 );
6734
+
6735
+ return function ( angle ) {
6736
+
6737
+ return this.rotateOnAxis( v1, angle );
6738
+
6739
+ };
6740
+
6741
+ }(),
6742
+
6743
+ rotateY: function () {
6744
+
6745
+ var v1 = new THREE.Vector3( 0, 1, 0 );
6746
+
6747
+ return function ( angle ) {
6748
+
6749
+ return this.rotateOnAxis( v1, angle );
6750
+
6751
+ };
6752
+
6753
+ }(),
6754
+
6755
+ rotateZ: function () {
6756
+
6757
+ var v1 = new THREE.Vector3( 0, 0, 1 );
6758
+
6759
+ return function ( angle ) {
6760
+
6761
+ return this.rotateOnAxis( v1, angle );
6762
+
6763
+ };
6764
+
6765
+ }(),
6766
+
6767
+ translateOnAxis: function () {
6768
+
6769
+ // translate object by distance along axis in object space
6770
+ // axis is assumed to be normalized
6771
+
6772
+ var v1 = new THREE.Vector3();
6773
+
6774
+ return function ( axis, distance ) {
6775
+
6776
+ v1.copy( axis ).applyQuaternion( this.quaternion );
6777
+
6778
+ this.position.add( v1.multiplyScalar( distance ) );
6779
+
6780
+ return this;
6781
+
6782
+ }
6783
+
6784
+ }(),
6785
+
6786
+ translate: function ( distance, axis ) {
6787
+
6788
+ console.warn( 'THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.' );
6789
+ return this.translateOnAxis( axis, distance );
6790
+
6791
+ },
6792
+
6793
+ translateX: function () {
6794
+
6795
+ var v1 = new THREE.Vector3( 1, 0, 0 );
6796
+
6797
+ return function ( distance ) {
6798
+
6799
+ return this.translateOnAxis( v1, distance );
6800
+
6801
+ };
6802
+
6803
+ }(),
6804
+
6805
+ translateY: function () {
6806
+
6807
+ var v1 = new THREE.Vector3( 0, 1, 0 );
6808
+
6809
+ return function ( distance ) {
6810
+
6811
+ return this.translateOnAxis( v1, distance );
6812
+
6813
+ };
6814
+
6815
+ }(),
6816
+
6817
+ translateZ: function () {
6818
+
6819
+ var v1 = new THREE.Vector3( 0, 0, 1 );
6820
+
6821
+ return function ( distance ) {
6822
+
6823
+ return this.translateOnAxis( v1, distance );
6824
+
6825
+ };
6826
+
6827
+ }(),
6828
+
6829
+ localToWorld: function ( vector ) {
6830
+
6831
+ return vector.applyMatrix4( this.matrixWorld );
6832
+
6833
+ },
6834
+
6835
+ worldToLocal: function () {
6836
+
6837
+ var m1 = new THREE.Matrix4();
6838
+
6839
+ return function ( vector ) {
6840
+
6841
+ return vector.applyMatrix4( m1.getInverse( this.matrixWorld ) );
6842
+
6843
+ };
6844
+
6845
+ }(),
6846
+
6847
+ lookAt: function () {
6848
+
6849
+ // This routine does not support objects with rotated and/or translated parent(s)
6850
+
6851
+ var m1 = new THREE.Matrix4();
6852
+
6853
+ return function ( vector ) {
6854
+
6855
+ m1.lookAt( vector, this.position, this.up );
6856
+
6857
+ this.quaternion.setFromRotationMatrix( m1 );
6858
+
6859
+ };
6860
+
6861
+ }(),
6862
+
6863
+ add: function ( object ) {
6864
+
6865
+ if ( arguments.length > 1 ) {
6866
+
6867
+ for ( var i = 0; i < arguments.length; i++ ) {
6868
+
6869
+ this.add( arguments[ i ] );
6870
+
6871
+ }
6872
+
6873
+ return this;
6874
+
6875
+ };
6876
+
6877
+ if ( object === this ) {
6878
+
6879
+ console.error( "THREE.Object3D.add:", object, "can't be added as a child of itself." );
6880
+ return this;
6881
+
6882
+ }
6883
+
6884
+ if ( object instanceof THREE.Object3D ) {
6885
+
6886
+ if ( object.parent !== undefined ) {
6887
+
6888
+ object.parent.remove( object );
6889
+
6890
+ }
6891
+
6892
+ object.parent = this;
6893
+ object.dispatchEvent( { type: 'added' } );
6894
+
6895
+ this.children.push( object );
6896
+
6897
+ } else {
6898
+
6899
+ console.error( "THREE.Object3D.add:", object, "is not an instance of THREE.Object3D." );
6900
+
6901
+ }
6902
+
6903
+ return this;
6904
+
6905
+ },
6906
+
6907
+ remove: function ( object ) {
6908
+
6909
+ if ( arguments.length > 1 ) {
6910
+
6911
+ for ( var i = 0; i < arguments.length; i++ ) {
6912
+
6913
+ this.remove( arguments[ i ] );
6914
+
6915
+ }
6916
+
6917
+ };
6918
+
6919
+ var index = this.children.indexOf( object );
6920
+
6921
+ if ( index !== - 1 ) {
6922
+
6923
+ object.parent = undefined;
6924
+
6925
+ object.dispatchEvent( { type: 'removed' } );
6926
+
6927
+ this.children.splice( index, 1 );
6928
+
6929
+ }
6930
+
6931
+ },
6932
+
6933
+ getChildByName: function ( name, recursive ) {
6934
+
6935
+ console.warn( 'THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().' );
6936
+ return this.getObjectByName( name, recursive );
6937
+
6938
+ },
6939
+
6940
+ getObjectById: function ( id, recursive ) {
6941
+
6942
+ if ( this.id === id ) return this;
6943
+
6944
+ for ( var i = 0, l = this.children.length; i < l; i ++ ) {
6945
+
6946
+ var child = this.children[ i ];
6947
+ var object = child.getObjectById( id, recursive );
6948
+
6949
+ if ( object !== undefined ) {
6950
+
6951
+ return object;
6952
+
6953
+ }
6954
+
6955
+ }
6956
+
6957
+ return undefined;
6958
+
6959
+ },
6960
+
6961
+ getObjectByName: function ( name, recursive ) {
6962
+
6963
+ if ( this.name === name ) return this;
6964
+
6965
+ for ( var i = 0, l = this.children.length; i < l; i ++ ) {
6966
+
6967
+ var child = this.children[ i ];
6968
+ var object = child.getObjectByName( name, recursive );
6969
+
6970
+ if ( object !== undefined ) {
6971
+
6972
+ return object;
6973
+
6974
+ }
6975
+
6976
+ }
6977
+
6978
+ return undefined;
6979
+
6980
+ },
6981
+
6982
+ getWorldPosition: function ( optionalTarget ) {
6983
+
6984
+ var result = optionalTarget || new THREE.Vector3();
6985
+
6986
+ this.updateMatrixWorld( true );
6987
+
6988
+ return result.setFromMatrixPosition( this.matrixWorld );
6989
+
6990
+ },
6991
+
6992
+ getWorldQuaternion: function () {
6993
+
6994
+ var position = new THREE.Vector3();
6995
+ var scale = new THREE.Vector3();
6996
+
6997
+ return function ( optionalTarget ) {
6998
+
6999
+ var result = optionalTarget || new THREE.Quaternion();
7000
+
7001
+ this.updateMatrixWorld( true );
7002
+
7003
+ this.matrixWorld.decompose( position, result, scale );
7004
+
7005
+ return result;
7006
+
7007
+ }
7008
+
7009
+ }(),
7010
+
7011
+ getWorldRotation: function () {
7012
+
7013
+ var quaternion = new THREE.Quaternion();
7014
+
7015
+ return function ( optionalTarget ) {
7016
+
7017
+ var result = optionalTarget || new THREE.Euler();
7018
+
7019
+ this.getWorldQuaternion( quaternion );
7020
+
7021
+ return result.setFromQuaternion( quaternion, this.rotation.order, false );
7022
+
7023
+ }
7024
+
7025
+ }(),
7026
+
7027
+ getWorldScale: function () {
7028
+
7029
+ var position = new THREE.Vector3();
7030
+ var quaternion = new THREE.Quaternion();
7031
+
7032
+ return function ( optionalTarget ) {
7033
+
7034
+ var result = optionalTarget || new THREE.Vector3();
7035
+
7036
+ this.updateMatrixWorld( true );
7037
+
7038
+ this.matrixWorld.decompose( position, quaternion, result );
7039
+
7040
+ return result;
7041
+
7042
+ }
7043
+
7044
+ }(),
7045
+
7046
+ getWorldDirection: function () {
7047
+
7048
+ var quaternion = new THREE.Quaternion();
7049
+
7050
+ return function ( optionalTarget ) {
7051
+
7052
+ var result = optionalTarget || new THREE.Vector3();
7053
+
7054
+ this.getWorldQuaternion( quaternion );
7055
+
7056
+ return result.set( 0, 0, 1 ).applyQuaternion( quaternion );
7057
+
7058
+ }
7059
+
7060
+ }(),
7061
+
7062
+ raycast: function () {},
7063
+
7064
+ traverse: function ( callback ) {
7065
+
7066
+ callback( this );
7067
+
7068
+ for ( var i = 0, l = this.children.length; i < l; i ++ ) {
7069
+
7070
+ this.children[ i ].traverse( callback );
7071
+
7072
+ }
7073
+
7074
+ },
7075
+
7076
+ traverseVisible: function ( callback ) {
7077
+
7078
+ if ( this.visible === false ) return;
7079
+
7080
+ callback( this );
7081
+
7082
+ for ( var i = 0, l = this.children.length; i < l; i ++ ) {
7083
+
7084
+ this.children[ i ].traverseVisible( callback );
7085
+
7086
+ }
7087
+
7088
+ },
7089
+
7090
+ updateMatrix: function () {
7091
+
7092
+ this.matrix.compose( this.position, this.quaternion, this.scale );
7093
+
7094
+ this.matrixWorldNeedsUpdate = true;
7095
+
7096
+ },
7097
+
7098
+ updateMatrixWorld: function ( force ) {
7099
+
7100
+ if ( this.matrixAutoUpdate === true ) this.updateMatrix();
7101
+
7102
+ if ( this.matrixWorldNeedsUpdate === true || force === true ) {
7103
+
7104
+ if ( this.parent === undefined ) {
7105
+
7106
+ this.matrixWorld.copy( this.matrix );
7107
+
7108
+ } else {
7109
+
7110
+ this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
7111
+
7112
+ }
7113
+
7114
+ this.matrixWorldNeedsUpdate = false;
7115
+
7116
+ force = true;
7117
+
7118
+ }
7119
+
7120
+ // update children
7121
+
7122
+ for ( var i = 0, l = this.children.length; i < l; i ++ ) {
7123
+
7124
+ this.children[ i ].updateMatrixWorld( force );
7125
+
7126
+ }
7127
+
7128
+ },
7129
+
7130
+ toJSON: function () {
7131
+
7132
+ var output = {
7133
+ metadata: {
7134
+ version: 4.3,
7135
+ type: 'Object',
7136
+ generator: 'ObjectExporter'
7137
+ }
7138
+ };
7139
+
7140
+ //
7141
+
7142
+ var geometries = {};
7143
+
7144
+ var parseGeometry = function ( geometry ) {
7145
+
7146
+ if ( output.geometries === undefined ) {
7147
+
7148
+ output.geometries = [];
7149
+
7150
+ }
7151
+
7152
+ if ( geometries[ geometry.uuid ] === undefined ) {
7153
+
7154
+ var json = geometry.toJSON();
7155
+
7156
+ delete json.metadata;
7157
+
7158
+ geometries[ geometry.uuid ] = json;
7159
+
7160
+ output.geometries.push( json );
7161
+
7162
+ }
7163
+
7164
+ return geometry.uuid;
7165
+
7166
+ };
7167
+
7168
+ //
7169
+
7170
+ var materials = {};
7171
+
7172
+ var parseMaterial = function ( material ) {
7173
+
7174
+ if ( output.materials === undefined ) {
7175
+
7176
+ output.materials = [];
7177
+
7178
+ }
7179
+
7180
+ if ( materials[ material.uuid ] === undefined ) {
7181
+
7182
+ var json = material.toJSON();
7183
+
7184
+ delete json.metadata;
7185
+
7186
+ materials[ material.uuid ] = json;
7187
+
7188
+ output.materials.push( json );
7189
+
7190
+ }
7191
+
7192
+ return material.uuid;
7193
+
7194
+ };
7195
+
7196
+ //
7197
+
7198
+ var parseObject = function ( object ) {
7199
+
7200
+ var data = {};
7201
+
7202
+ data.uuid = object.uuid;
7203
+ data.type = object.type;
7204
+
7205
+ if ( object.name !== '' ) data.name = object.name;
7206
+ if ( JSON.stringify( object.userData ) !== '{}' ) data.userData = object.userData;
7207
+ if ( object.visible !== true ) data.visible = object.visible;
7208
+
7209
+ if ( object instanceof THREE.PerspectiveCamera ) {
7210
+
7211
+ data.fov = object.fov;
7212
+ data.aspect = object.aspect;
7213
+ data.near = object.near;
7214
+ data.far = object.far;
7215
+
7216
+ } else if ( object instanceof THREE.OrthographicCamera ) {
7217
+
7218
+ data.left = object.left;
7219
+ data.right = object.right;
7220
+ data.top = object.top;
7221
+ data.bottom = object.bottom;
7222
+ data.near = object.near;
7223
+ data.far = object.far;
7224
+
7225
+ } else if ( object instanceof THREE.AmbientLight ) {
7226
+
7227
+ data.color = object.color.getHex();
7228
+
7229
+ } else if ( object instanceof THREE.DirectionalLight ) {
7230
+
7231
+ data.color = object.color.getHex();
7232
+ data.intensity = object.intensity;
7233
+
7234
+ } else if ( object instanceof THREE.PointLight ) {
7235
+
7236
+ data.color = object.color.getHex();
7237
+ data.intensity = object.intensity;
7238
+ data.distance = object.distance;
7239
+
7240
+ } else if ( object instanceof THREE.SpotLight ) {
7241
+
7242
+ data.color = object.color.getHex();
7243
+ data.intensity = object.intensity;
7244
+ data.distance = object.distance;
7245
+ data.angle = object.angle;
7246
+ data.exponent = object.exponent;
7247
+
7248
+ } else if ( object instanceof THREE.HemisphereLight ) {
7249
+
7250
+ data.color = object.color.getHex();
7251
+ data.groundColor = object.groundColor.getHex();
7252
+
7253
+ } else if ( object instanceof THREE.Mesh ) {
7254
+
7255
+ data.geometry = parseGeometry( object.geometry );
7256
+ data.material = parseMaterial( object.material );
7257
+
7258
+ } else if ( object instanceof THREE.Line ) {
7259
+
7260
+ data.geometry = parseGeometry( object.geometry );
7261
+ data.material = parseMaterial( object.material );
7262
+
7263
+ } else if ( object instanceof THREE.Sprite ) {
7264
+
7265
+ data.material = parseMaterial( object.material );
7266
+
7267
+ }
7268
+
7269
+ data.matrix = object.matrix.toArray();
7270
+
7271
+ if ( object.children.length > 0 ) {
7272
+
7273
+ data.children = [];
7274
+
7275
+ for ( var i = 0; i < object.children.length; i ++ ) {
7276
+
7277
+ data.children.push( parseObject( object.children[ i ] ) );
7278
+
7279
+ }
7280
+
7281
+ }
7282
+
7283
+ return data;
7284
+
7285
+ }
7286
+
7287
+ output.object = parseObject( this );
7288
+
7289
+ return output;
7290
+
7291
+ },
7292
+
7293
+ clone: function ( object, recursive ) {
7294
+
7295
+ if ( object === undefined ) object = new THREE.Object3D();
7296
+ if ( recursive === undefined ) recursive = true;
7297
+
7298
+ object.name = this.name;
7299
+
7300
+ object.up.copy( this.up );
7301
+
7302
+ object.position.copy( this.position );
7303
+ object.quaternion.copy( this.quaternion );
7304
+ object.scale.copy( this.scale );
7305
+
7306
+ object.renderDepth = this.renderDepth;
7307
+
7308
+ object.rotationAutoUpdate = this.rotationAutoUpdate;
7309
+
7310
+ object.matrix.copy( this.matrix );
7311
+ object.matrixWorld.copy( this.matrixWorld );
7312
+
7313
+ object.matrixAutoUpdate = this.matrixAutoUpdate;
7314
+ object.matrixWorldNeedsUpdate = this.matrixWorldNeedsUpdate;
7315
+
7316
+ object.visible = this.visible;
7317
+
7318
+ object.castShadow = this.castShadow;
7319
+ object.receiveShadow = this.receiveShadow;
7320
+
7321
+ object.frustumCulled = this.frustumCulled;
7322
+
7323
+ object.userData = JSON.parse( JSON.stringify( this.userData ) );
7324
+
7325
+ if ( recursive === true ) {
7326
+
7327
+ for ( var i = 0; i < this.children.length; i ++ ) {
7328
+
7329
+ var child = this.children[ i ];
7330
+ object.add( child.clone() );
7331
+
7332
+ }
7333
+
7334
+ }
7335
+
7336
+ return object;
7337
+
7338
+ }
7339
+
7340
+ };
7341
+
7342
+ THREE.EventDispatcher.prototype.apply( THREE.Object3D.prototype );
7343
+
7344
+ THREE.Object3DIdCount = 0;
7345
+
7346
+ // File:src/core/Projector.js
7347
+
7348
+ /**
7349
+ * @author mrdoob / http://mrdoob.com/
7350
+ */
7351
+ /*
7352
+ THREE.Projector = function () {
7353
+
7354
+ console.warn( 'THREE.Projector has been moved to /examples/renderers/Projector.js.' );
7355
+
7356
+ this.projectVector = function ( vector, camera ) {
7357
+
7358
+ console.warn( 'THREE.Projector: .projectVector() is now vector.project().' );
7359
+ vector.project( camera );
7360
+
7361
+ };
7362
+
7363
+ this.unprojectVector = function ( vector, camera ) {
7364
+
7365
+ console.warn( 'THREE.Projector: .unprojectVector() is now vector.unproject().' );
7366
+ vector.unproject( camera );
7367
+
7368
+ };
7369
+
7370
+ this.pickingRay = function ( vector, camera ) {
7371
+
7372
+ console.error( 'THREE.Projector: .pickingRay() has been removed.' );
7373
+
7374
+ };
7375
+
7376
+ };
7377
+
7378
+ // File:src/core/Face3.js
7379
+
7380
+ /**
7381
+ * @author mrdoob / http://mrdoob.com/
7382
+ * @author alteredq / http://alteredqualia.com/
7383
+ */
7384
+
7385
+ THREE.Face3 = function ( a, b, c, normal, color, materialIndex ) {
7386
+
7387
+ this.a = a;
7388
+ this.b = b;
7389
+ this.c = c;
7390
+
7391
+ this.normal = normal instanceof THREE.Vector3 ? normal : new THREE.Vector3();
7392
+ this.vertexNormals = normal instanceof Array ? normal : [];
7393
+
7394
+ this.color = color instanceof THREE.Color ? color : new THREE.Color();
7395
+ this.vertexColors = color instanceof Array ? color : [];
7396
+
7397
+ this.vertexTangents = [];
7398
+
7399
+ this.materialIndex = materialIndex !== undefined ? materialIndex : 0;
7400
+
7401
+ };
7402
+
7403
+ THREE.Face3.prototype = {
7404
+
7405
+ constructor: THREE.Face3,
7406
+
7407
+ clone: function () {
7408
+
7409
+ var face = new THREE.Face3( this.a, this.b, this.c );
7410
+
7411
+ face.normal.copy( this.normal );
7412
+ face.color.copy( this.color );
7413
+
7414
+ face.materialIndex = this.materialIndex;
7415
+
7416
+ for ( var i = 0, il = this.vertexNormals.length; i < il; i ++ ) {
7417
+
7418
+ face.vertexNormals[ i ] = this.vertexNormals[ i ].clone();
7419
+
7420
+ }
7421
+
7422
+ for ( var i = 0, il = this.vertexColors.length; i < il; i ++ ) {
7423
+
7424
+ face.vertexColors[ i ] = this.vertexColors[ i ].clone();
7425
+
7426
+ }
7427
+
7428
+ for ( var i = 0, il = this.vertexTangents.length; i < il; i ++ ) {
7429
+
7430
+ face.vertexTangents[ i ] = this.vertexTangents[ i ].clone();
7431
+
7432
+ }
7433
+
7434
+ return face;
7435
+
7436
+ }
7437
+
7438
+ };
7439
+
7440
+ // File:src/core/Face4.js
7441
+
7442
+ /**
7443
+ * @author mrdoob / http://mrdoob.com/
7444
+ */
7445
+ /*
7446
+ THREE.Face4 = function ( a, b, c, d, normal, color, materialIndex ) {
7447
+
7448
+ console.warn( 'THREE.Face4 has been removed. A THREE.Face3 will be created instead.' )
7449
+ return new THREE.Face3( a, b, c, normal, color, materialIndex );
7450
+
7451
+ };
7452
+
7453
+ // File:src/core/BufferAttribute.js
7454
+
7455
+ /**
7456
+ * @author mrdoob / http://mrdoob.com/
7457
+ */
7458
+
7459
+ THREE.BufferAttribute = function ( array, itemSize ) {
7460
+
7461
+ this.array = array;
7462
+ this.itemSize = itemSize;
7463
+
7464
+ this.needsUpdate = false;
7465
+
7466
+ };
7467
+
7468
+ THREE.BufferAttribute.prototype = {
7469
+
7470
+ constructor: THREE.BufferAttribute,
7471
+
7472
+ get length () {
7473
+
7474
+ return this.array.length;
7475
+
7476
+ },
7477
+
7478
+ copyAt: function ( index1, attribute, index2 ) {
7479
+
7480
+ index1 *= this.itemSize;
7481
+ index2 *= attribute.itemSize;
7482
+
7483
+ for ( var i = 0, l = this.itemSize; i < l; i ++ ) {
7484
+
7485
+ this.array[ index1 + i ] = attribute.array[ index2 + i ];
7486
+
7487
+ }
7488
+
7489
+ },
7490
+
7491
+ set: function ( value ) {
7492
+
7493
+ this.array.set( value );
7494
+
7495
+ return this;
7496
+
7497
+ },
7498
+
7499
+ setX: function ( index, x ) {
7500
+
7501
+ this.array[ index * this.itemSize ] = x;
7502
+
7503
+ return this;
7504
+
7505
+ },
7506
+
7507
+ setY: function ( index, y ) {
7508
+
7509
+ this.array[ index * this.itemSize + 1 ] = y;
7510
+
7511
+ return this;
7512
+
7513
+ },
7514
+
7515
+ setZ: function ( index, z ) {
7516
+
7517
+ this.array[ index * this.itemSize + 2 ] = z;
7518
+
7519
+ return this;
7520
+
7521
+ },
7522
+
7523
+ setXY: function ( index, x, y ) {
7524
+
7525
+ index *= this.itemSize;
7526
+
7527
+ this.array[ index ] = x;
7528
+ this.array[ index + 1 ] = y;
7529
+
7530
+ return this;
7531
+
7532
+ },
7533
+
7534
+ setXYZ: function ( index, x, y, z ) {
7535
+
7536
+ index *= this.itemSize;
7537
+
7538
+ this.array[ index ] = x;
7539
+ this.array[ index + 1 ] = y;
7540
+ this.array[ index + 2 ] = z;
7541
+
7542
+ return this;
7543
+
7544
+ },
7545
+
7546
+ setXYZW: function ( index, x, y, z, w ) {
7547
+
7548
+ index *= this.itemSize;
7549
+
7550
+ this.array[ index ] = x;
7551
+ this.array[ index + 1 ] = y;
7552
+ this.array[ index + 2 ] = z;
7553
+ this.array[ index + 3 ] = w;
7554
+
7555
+ return this;
7556
+
7557
+ },
7558
+
7559
+ clone: function () {
7560
+
7561
+ return new THREE.BufferAttribute( new this.array.constructor( this.array ), this.itemSize );
7562
+
7563
+ }
7564
+
7565
+ };
7566
+
7567
+ //
7568
+ /*
7569
+ THREE.Int8Attribute = function ( data, itemSize ) {
7570
+
7571
+ console.warn( 'THREE.Int8Attribute has been removed. Use THREE.BufferAttribute( array, itemSize ) instead.' );
7572
+ return new THREE.BufferAttribute( data, itemSize );
7573
+
7574
+ };
7575
+
7576
+ THREE.Uint8Attribute = function ( data, itemSize ) {
7577
+
7578
+ console.warn( 'THREE.Uint8Attribute has been removed. Use THREE.BufferAttribute( array, itemSize ) instead.' );
7579
+ return new THREE.BufferAttribute( data, itemSize );
7580
+
7581
+ };
7582
+
7583
+ THREE.Uint8ClampedAttribute = function ( data, itemSize ) {
7584
+
7585
+ console.warn( 'THREE.Uint8ClampedAttribute has been removed. Use THREE.BufferAttribute( array, itemSize ) instead.' );
7586
+ return new THREE.BufferAttribute( data, itemSize );
7587
+
7588
+
7589
+ };
7590
+
7591
+ THREE.Int16Attribute = function ( data, itemSize ) {
7592
+
7593
+ console.warn( 'THREE.Int16Attribute has been removed. Use THREE.BufferAttribute( array, itemSize ) instead.' );
7594
+ return new THREE.BufferAttribute( data, itemSize );
7595
+
7596
+ };
7597
+
7598
+ THREE.Uint16Attribute = function ( data, itemSize ) {
7599
+
7600
+ console.warn( 'THREE.Uint16Attribute has been removed. Use THREE.BufferAttribute( array, itemSize ) instead.' );
7601
+ return new THREE.BufferAttribute( data, itemSize );
7602
+
7603
+ };
7604
+
7605
+ THREE.Int32Attribute = function ( data, itemSize ) {
7606
+
7607
+ console.warn( 'THREE.Int32Attribute has been removed. Use THREE.BufferAttribute( array, itemSize ) instead.' );
7608
+ return new THREE.BufferAttribute( data, itemSize );
7609
+
7610
+ };
7611
+
7612
+ THREE.Uint32Attribute = function ( data, itemSize ) {
7613
+
7614
+ console.warn( 'THREE.Uint32Attribute has been removed. Use THREE.BufferAttribute( array, itemSize ) instead.' );
7615
+ return new THREE.BufferAttribute( data, itemSize );
7616
+
7617
+ };
7618
+
7619
+ THREE.Float32Attribute = function ( data, itemSize ) {
7620
+
7621
+ console.warn( 'THREE.Float32Attribute has been removed. Use THREE.BufferAttribute( array, itemSize ) instead.' );
7622
+ return new THREE.BufferAttribute( data, itemSize );
7623
+
7624
+ };
7625
+
7626
+ THREE.Float64Attribute = function ( data, itemSize ) {
7627
+
7628
+ console.warn( 'THREE.Float64Attribute has been removed. Use THREE.BufferAttribute( array, itemSize ) instead.' );
7629
+ return new THREE.BufferAttribute( data, itemSize );
7630
+
7631
+ };
7632
+
7633
+ // File:src/core/BufferGeometry.js
7634
+
7635
+ /**
7636
+ * @author alteredq / http://alteredqualia.com/
7637
+ * @author mrdoob / http://mrdoob.com/
7638
+ */
7639
+
7640
+ THREE.BufferGeometry = function () {
7641
+
7642
+ Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
7643
+
7644
+ this.uuid = THREE.Math.generateUUID();
7645
+
7646
+ this.name = '';
7647
+ this.type = 'BufferGeometry';
7648
+
7649
+ this.attributes = {};
7650
+ this.attributesKeys = [];
7651
+
7652
+ this.drawcalls = [];
7653
+ this.offsets = this.drawcalls; // backwards compatibility
7654
+
7655
+ this.boundingBox = null;
7656
+ this.boundingSphere = null;
7657
+
7658
+ };
7659
+
7660
+ THREE.BufferGeometry.prototype = {
7661
+
7662
+ constructor: THREE.BufferGeometry,
7663
+
7664
+ addAttribute: function ( name, attribute ) {
7665
+
7666
+ if ( attribute instanceof THREE.BufferAttribute === false ) {
7667
+
7668
+ console.warn( 'THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).' );
7669
+
7670
+ this.attributes[ name ] = { array: arguments[ 1 ], itemSize: arguments[ 2 ] };
7671
+
7672
+ return;
7673
+
7674
+ }
7675
+
7676
+ this.attributes[ name ] = attribute;
7677
+ this.attributesKeys = Object.keys( this.attributes );
7678
+
7679
+ },
7680
+
7681
+ getAttribute: function ( name ) {
7682
+
7683
+ return this.attributes[ name ];
7684
+
7685
+ },
7686
+
7687
+ addDrawCall: function ( start, count, indexOffset ) {
7688
+
7689
+ this.drawcalls.push( {
7690
+
7691
+ start: start,
7692
+ count: count,
7693
+ index: indexOffset !== undefined ? indexOffset : 0
7694
+
7695
+ } );
7696
+
7697
+ },
7698
+
7699
+ applyMatrix: function ( matrix ) {
7700
+
7701
+ var position = this.attributes.position;
7702
+
7703
+ if ( position !== undefined ) {
7704
+
7705
+ matrix.applyToVector3Array( position.array );
7706
+ position.needsUpdate = true;
7707
+
7708
+ }
7709
+
7710
+ var normal = this.attributes.normal;
7711
+
7712
+ if ( normal !== undefined ) {
7713
+
7714
+ var normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
7715
+
7716
+ normalMatrix.applyToVector3Array( normal.array );
7717
+ normal.needsUpdate = true;
7718
+
7719
+ }
7720
+
7721
+ },
7722
+
7723
+ center: function () {
7724
+
7725
+ // TODO
7726
+
7727
+ },
7728
+
7729
+ fromGeometry: function ( geometry, settings ) {
7730
+
7731
+ settings = settings || { 'vertexColors': THREE.NoColors };
7732
+
7733
+ var vertices = geometry.vertices;
7734
+ var faces = geometry.faces;
7735
+ var faceVertexUvs = geometry.faceVertexUvs;
7736
+ var vertexColors = settings.vertexColors;
7737
+ var hasFaceVertexUv = faceVertexUvs[ 0 ].length > 0;
7738
+ var hasFaceVertexNormals = faces[ 0 ].vertexNormals.length == 3;
7739
+
7740
+ var positions = new Float32Array( faces.length * 3 * 3 );
7741
+ this.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
7742
+
7743
+ var normals = new Float32Array( faces.length * 3 * 3 );
7744
+ this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
7745
+
7746
+ if ( vertexColors !== THREE.NoColors ) {
7747
+
7748
+ var colors = new Float32Array( faces.length * 3 * 3 );
7749
+ this.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ) );
7750
+
7751
+ }
7752
+
7753
+ if ( hasFaceVertexUv === true ) {
7754
+
7755
+ var uvs = new Float32Array( faces.length * 3 * 2 );
7756
+ this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
7757
+
7758
+ }
7759
+
7760
+ for ( var i = 0, i2 = 0, i3 = 0; i < faces.length; i ++, i2 += 6, i3 += 9 ) {
7761
+
7762
+ var face = faces[ i ];
7763
+
7764
+ var a = vertices[ face.a ];
7765
+ var b = vertices[ face.b ];
7766
+ var c = vertices[ face.c ];
7767
+
7768
+ positions[ i3 ] = a.x;
7769
+ positions[ i3 + 1 ] = a.y;
7770
+ positions[ i3 + 2 ] = a.z;
7771
+
7772
+ positions[ i3 + 3 ] = b.x;
7773
+ positions[ i3 + 4 ] = b.y;
7774
+ positions[ i3 + 5 ] = b.z;
7775
+
7776
+ positions[ i3 + 6 ] = c.x;
7777
+ positions[ i3 + 7 ] = c.y;
7778
+ positions[ i3 + 8 ] = c.z;
7779
+
7780
+ if ( hasFaceVertexNormals === true ) {
7781
+
7782
+ var na = face.vertexNormals[ 0 ];
7783
+ var nb = face.vertexNormals[ 1 ];
7784
+ var nc = face.vertexNormals[ 2 ];
7785
+
7786
+ normals[ i3 ] = na.x;
7787
+ normals[ i3 + 1 ] = na.y;
7788
+ normals[ i3 + 2 ] = na.z;
7789
+
7790
+ normals[ i3 + 3 ] = nb.x;
7791
+ normals[ i3 + 4 ] = nb.y;
7792
+ normals[ i3 + 5 ] = nb.z;
7793
+
7794
+ normals[ i3 + 6 ] = nc.x;
7795
+ normals[ i3 + 7 ] = nc.y;
7796
+ normals[ i3 + 8 ] = nc.z;
7797
+
7798
+ } else {
7799
+
7800
+ var n = face.normal;
7801
+
7802
+ normals[ i3 ] = n.x;
7803
+ normals[ i3 + 1 ] = n.y;
7804
+ normals[ i3 + 2 ] = n.z;
7805
+
7806
+ normals[ i3 + 3 ] = n.x;
7807
+ normals[ i3 + 4 ] = n.y;
7808
+ normals[ i3 + 5 ] = n.z;
7809
+
7810
+ normals[ i3 + 6 ] = n.x;
7811
+ normals[ i3 + 7 ] = n.y;
7812
+ normals[ i3 + 8 ] = n.z;
7813
+
7814
+ }
7815
+
7816
+ if ( vertexColors === THREE.FaceColors ) {
7817
+
7818
+ var fc = face.color;
7819
+
7820
+ colors[ i3 ] = fc.r;
7821
+ colors[ i3 + 1 ] = fc.g;
7822
+ colors[ i3 + 2 ] = fc.b;
7823
+
7824
+ colors[ i3 + 3 ] = fc.r;
7825
+ colors[ i3 + 4 ] = fc.g;
7826
+ colors[ i3 + 5 ] = fc.b;
7827
+
7828
+ colors[ i3 + 6 ] = fc.r;
7829
+ colors[ i3 + 7 ] = fc.g;
7830
+ colors[ i3 + 8 ] = fc.b;
7831
+
7832
+ } else if ( vertexColors === THREE.VertexColors ) {
7833
+
7834
+ var vca = face.vertexColors[ 0 ];
7835
+ var vcb = face.vertexColors[ 1 ];
7836
+ var vcc = face.vertexColors[ 2 ];
7837
+
7838
+ colors[ i3 ] = vca.r;
7839
+ colors[ i3 + 1 ] = vca.g;
7840
+ colors[ i3 + 2 ] = vca.b;
7841
+
7842
+ colors[ i3 + 3 ] = vcb.r;
7843
+ colors[ i3 + 4 ] = vcb.g;
7844
+ colors[ i3 + 5 ] = vcb.b;
7845
+
7846
+ colors[ i3 + 6 ] = vcc.r;
7847
+ colors[ i3 + 7 ] = vcc.g;
7848
+ colors[ i3 + 8 ] = vcc.b;
7849
+
7850
+ }
7851
+
7852
+ if ( hasFaceVertexUv === true ) {
7853
+
7854
+ var uva = faceVertexUvs[ 0 ][ i ][ 0 ];
7855
+ var uvb = faceVertexUvs[ 0 ][ i ][ 1 ];
7856
+ var uvc = faceVertexUvs[ 0 ][ i ][ 2 ];
7857
+
7858
+ uvs[ i2 ] = uva.x;
7859
+ uvs[ i2 + 1 ] = uva.y;
7860
+
7861
+ uvs[ i2 + 2 ] = uvb.x;
7862
+ uvs[ i2 + 3 ] = uvb.y;
7863
+
7864
+ uvs[ i2 + 4 ] = uvc.x;
7865
+ uvs[ i2 + 5 ] = uvc.y;
7866
+
7867
+ }
7868
+
7869
+ }
7870
+
7871
+ this.computeBoundingSphere()
7872
+
7873
+ return this;
7874
+
7875
+ },
7876
+
7877
+ computeBoundingBox: function () {
7878
+
7879
+ var vector = new THREE.Vector3();
7880
+
7881
+ return function () {
7882
+
7883
+ if ( this.boundingBox === null ) {
7884
+
7885
+ this.boundingBox = new THREE.Box3();
7886
+
7887
+ }
7888
+
7889
+ var positions = this.attributes.position.array;
7890
+
7891
+ if ( positions ) {
7892
+
7893
+ var bb = this.boundingBox;
7894
+ bb.makeEmpty();
7895
+
7896
+ for ( var i = 0, il = positions.length; i < il; i += 3 ) {
7897
+
7898
+ vector.set( positions[ i ], positions[ i + 1 ], positions[ i + 2 ] );
7899
+ bb.expandByPoint( vector );
7900
+
7901
+ }
7902
+
7903
+ }
7904
+
7905
+ if ( positions === undefined || positions.length === 0 ) {
7906
+
7907
+ this.boundingBox.min.set( 0, 0, 0 );
7908
+ this.boundingBox.max.set( 0, 0, 0 );
7909
+
7910
+ }
7911
+
7912
+ if ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) {
7913
+
7914
+ console.error( 'THREE.BufferGeometry.computeBoundingBox: Computed min/max have NaN values. The "position" attribute is likely to have NaN values.' );
7915
+
7916
+ }
7917
+
7918
+ }
7919
+
7920
+ }(),
7921
+
7922
+ computeBoundingSphere: function () {
7923
+
7924
+ var box = new THREE.Box3();
7925
+ var vector = new THREE.Vector3();
7926
+
7927
+ return function () {
7928
+
7929
+ if ( this.boundingSphere === null ) {
7930
+
7931
+ this.boundingSphere = new THREE.Sphere();
7932
+
7933
+ }
7934
+
7935
+ var positions = this.attributes.position.array;
7936
+
7937
+ if ( positions ) {
7938
+
7939
+ box.makeEmpty();
7940
+
7941
+ var center = this.boundingSphere.center;
7942
+
7943
+ for ( var i = 0, il = positions.length; i < il; i += 3 ) {
7944
+
7945
+ vector.set( positions[ i ], positions[ i + 1 ], positions[ i + 2 ] );
7946
+ box.expandByPoint( vector );
7947
+
7948
+ }
7949
+
7950
+ box.center( center );
7951
+
7952
+ // hoping to find a boundingSphere with a radius smaller than the
7953
+ // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
7954
+
7955
+ var maxRadiusSq = 0;
7956
+
7957
+ for ( var i = 0, il = positions.length; i < il; i += 3 ) {
7958
+
7959
+ vector.set( positions[ i ], positions[ i + 1 ], positions[ i + 2 ] );
7960
+ maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( vector ) );
7961
+
7962
+ }
7963
+
7964
+ this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
7965
+
7966
+ if ( isNaN( this.boundingSphere.radius ) ) {
7967
+
7968
+ console.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.' );
7969
+
7970
+ }
7971
+
7972
+ }
7973
+
7974
+ }
7975
+
7976
+ }(),
7977
+
7978
+ computeFaceNormals: function () {
7979
+
7980
+ // backwards compatibility
7981
+
7982
+ },
7983
+
7984
+ computeVertexNormals: function () {
7985
+
7986
+ var attributes = this.attributes;
7987
+
7988
+ if ( attributes.position ) {
7989
+
7990
+ var positions = attributes.position.array;
7991
+
7992
+ if ( attributes.normal === undefined ) {
7993
+
7994
+ this.addAttribute( 'normal', new THREE.BufferAttribute( new Float32Array( positions.length ), 3 ) );
7995
+
7996
+ } else {
7997
+
7998
+ // reset existing normals to zero
7999
+
8000
+ var normals = attributes.normal.array;
8001
+
8002
+ for ( var i = 0, il = normals.length; i < il; i ++ ) {
8003
+
8004
+ normals[ i ] = 0;
8005
+
8006
+ }
8007
+
8008
+ }
8009
+
8010
+ var normals = attributes.normal.array;
8011
+
8012
+ var vA, vB, vC,
8013
+
8014
+ pA = new THREE.Vector3(),
8015
+ pB = new THREE.Vector3(),
8016
+ pC = new THREE.Vector3(),
8017
+
8018
+ cb = new THREE.Vector3(),
8019
+ ab = new THREE.Vector3();
8020
+
8021
+ // indexed elements
8022
+
8023
+ if ( attributes.index ) {
8024
+
8025
+ var indices = attributes.index.array;
8026
+
8027
+ var offsets = ( this.offsets.length > 0 ? this.offsets : [ { start: 0, count: indices.length, index: 0 } ] );
8028
+
8029
+ for ( var j = 0, jl = offsets.length; j < jl; ++ j ) {
8030
+
8031
+ var start = offsets[ j ].start;
8032
+ var count = offsets[ j ].count;
8033
+ var index = offsets[ j ].index;
8034
+
8035
+ for ( var i = start, il = start + count; i < il; i += 3 ) {
8036
+
8037
+ vA = ( index + indices[ i ] ) * 3;
8038
+ vB = ( index + indices[ i + 1 ] ) * 3;
8039
+ vC = ( index + indices[ i + 2 ] ) * 3;
8040
+
8041
+ pA.fromArray( positions, vA );
8042
+ pB.fromArray( positions, vB );
8043
+ pC.fromArray( positions, vC );
8044
+
8045
+ cb.subVectors( pC, pB );
8046
+ ab.subVectors( pA, pB );
8047
+ cb.cross( ab );
8048
+
8049
+ normals[ vA ] += cb.x;
8050
+ normals[ vA + 1 ] += cb.y;
8051
+ normals[ vA + 2 ] += cb.z;
8052
+
8053
+ normals[ vB ] += cb.x;
8054
+ normals[ vB + 1 ] += cb.y;
8055
+ normals[ vB + 2 ] += cb.z;
8056
+
8057
+ normals[ vC ] += cb.x;
8058
+ normals[ vC + 1 ] += cb.y;
8059
+ normals[ vC + 2 ] += cb.z;
8060
+
8061
+ }
8062
+
8063
+ }
8064
+
8065
+ } else {
8066
+
8067
+ // non-indexed elements (unconnected triangle soup)
8068
+
8069
+ for ( var i = 0, il = positions.length; i < il; i += 9 ) {
8070
+
8071
+ pA.fromArray( positions, i );
8072
+ pB.fromArray( positions, i + 3 );
8073
+ pC.fromArray( positions, i + 6 );
8074
+
8075
+ cb.subVectors( pC, pB );
8076
+ ab.subVectors( pA, pB );
8077
+ cb.cross( ab );
8078
+
8079
+ normals[ i ] = cb.x;
8080
+ normals[ i + 1 ] = cb.y;
8081
+ normals[ i + 2 ] = cb.z;
8082
+
8083
+ normals[ i + 3 ] = cb.x;
8084
+ normals[ i + 4 ] = cb.y;
8085
+ normals[ i + 5 ] = cb.z;
8086
+
8087
+ normals[ i + 6 ] = cb.x;
8088
+ normals[ i + 7 ] = cb.y;
8089
+ normals[ i + 8 ] = cb.z;
8090
+
8091
+ }
8092
+
8093
+ }
8094
+
8095
+ this.normalizeNormals();
8096
+
8097
+ attributes.normal.needsUpdate = true;
8098
+
8099
+ }
8100
+
8101
+ },
8102
+
8103
+ computeTangents: function () {
8104
+
8105
+ // based on http://www.terathon.com/code/tangent.html
8106
+ // (per vertex tangents)
8107
+
8108
+ if ( this.attributes.index === undefined ||
8109
+ this.attributes.position === undefined ||
8110
+ this.attributes.normal === undefined ||
8111
+ this.attributes.uv === undefined ) {
8112
+
8113
+ console.warn( 'Missing required attributes (index, position, normal or uv) in BufferGeometry.computeTangents()' );
8114
+ return;
8115
+
8116
+ }
8117
+
8118
+ var indices = this.attributes.index.array;
8119
+ var positions = this.attributes.position.array;
8120
+ var normals = this.attributes.normal.array;
8121
+ var uvs = this.attributes.uv.array;
8122
+
8123
+ var nVertices = positions.length / 3;
8124
+
8125
+ if ( this.attributes.tangent === undefined ) {
8126
+
8127
+ this.addAttribute( 'tangent', new THREE.BufferAttribute( new Float32Array( 4 * nVertices ), 4 ) );
8128
+
8129
+ }
8130
+
8131
+ var tangents = this.attributes.tangent.array;
8132
+
8133
+ var tan1 = [], tan2 = [];
8134
+
8135
+ for ( var k = 0; k < nVertices; k ++ ) {
8136
+
8137
+ tan1[ k ] = new THREE.Vector3();
8138
+ tan2[ k ] = new THREE.Vector3();
8139
+
8140
+ }
8141
+
8142
+ var vA = new THREE.Vector3(),
8143
+ vB = new THREE.Vector3(),
8144
+ vC = new THREE.Vector3(),
8145
+
8146
+ uvA = new THREE.Vector2(),
8147
+ uvB = new THREE.Vector2(),
8148
+ uvC = new THREE.Vector2(),
8149
+
8150
+ x1, x2, y1, y2, z1, z2,
8151
+ s1, s2, t1, t2, r;
8152
+
8153
+ var sdir = new THREE.Vector3(), tdir = new THREE.Vector3();
8154
+
8155
+ function handleTriangle( a, b, c ) {
8156
+
8157
+ vA.fromArray( positions, a * 3 );
8158
+ vB.fromArray( positions, b * 3 );
8159
+ vC.fromArray( positions, c * 3 );
8160
+
8161
+ uvA.fromArray( uvs, a * 2 );
8162
+ uvB.fromArray( uvs, b * 2 );
8163
+ uvC.fromArray( uvs, c * 2 );
8164
+
8165
+ x1 = vB.x - vA.x;
8166
+ x2 = vC.x - vA.x;
8167
+
8168
+ y1 = vB.y - vA.y;
8169
+ y2 = vC.y - vA.y;
8170
+
8171
+ z1 = vB.z - vA.z;
8172
+ z2 = vC.z - vA.z;
8173
+
8174
+ s1 = uvB.x - uvA.x;
8175
+ s2 = uvC.x - uvA.x;
8176
+
8177
+ t1 = uvB.y - uvA.y;
8178
+ t2 = uvC.y - uvA.y;
8179
+
8180
+ r = 1.0 / ( s1 * t2 - s2 * t1 );
8181
+
8182
+ sdir.set(
8183
+ ( t2 * x1 - t1 * x2 ) * r,
8184
+ ( t2 * y1 - t1 * y2 ) * r,
8185
+ ( t2 * z1 - t1 * z2 ) * r
8186
+ );
8187
+
8188
+ tdir.set(
8189
+ ( s1 * x2 - s2 * x1 ) * r,
8190
+ ( s1 * y2 - s2 * y1 ) * r,
8191
+ ( s1 * z2 - s2 * z1 ) * r
8192
+ );
8193
+
8194
+ tan1[ a ].add( sdir );
8195
+ tan1[ b ].add( sdir );
8196
+ tan1[ c ].add( sdir );
8197
+
8198
+ tan2[ a ].add( tdir );
8199
+ tan2[ b ].add( tdir );
8200
+ tan2[ c ].add( tdir );
8201
+
8202
+ }
8203
+
8204
+ var i, il;
8205
+ var j, jl;
8206
+ var iA, iB, iC;
8207
+
8208
+ if ( this.drawcalls.length === 0 ) {
8209
+
8210
+ this.addDrawCall( 0, indices.length, 0 );
8211
+
8212
+ }
8213
+
8214
+ var drawcalls = this.drawcalls;
8215
+
8216
+ for ( j = 0, jl = drawcalls.length; j < jl; ++ j ) {
8217
+
8218
+ var start = drawcalls[ j ].start;
8219
+ var count = drawcalls[ j ].count;
8220
+ var index = drawcalls[ j ].index;
8221
+
8222
+ for ( i = start, il = start + count; i < il; i += 3 ) {
8223
+
8224
+ iA = index + indices[ i ];
8225
+ iB = index + indices[ i + 1 ];
8226
+ iC = index + indices[ i + 2 ];
8227
+
8228
+ handleTriangle( iA, iB, iC );
8229
+
8230
+ }
8231
+
8232
+ }
8233
+
8234
+ var tmp = new THREE.Vector3(), tmp2 = new THREE.Vector3();
8235
+ var n = new THREE.Vector3(), n2 = new THREE.Vector3();
8236
+ var w, t, test;
8237
+
8238
+ function handleVertex( v ) {
8239
+
8240
+ n.fromArray( normals, v * 3 );
8241
+ n2.copy( n );
8242
+
8243
+ t = tan1[ v ];
8244
+
8245
+ // Gram-Schmidt orthogonalize
8246
+
8247
+ tmp.copy( t );
8248
+ tmp.sub( n.multiplyScalar( n.dot( t ) ) ).normalize();
8249
+
8250
+ // Calculate handedness
8251
+
8252
+ tmp2.crossVectors( n2, t );
8253
+ test = tmp2.dot( tan2[ v ] );
8254
+ w = ( test < 0.0 ) ? - 1.0 : 1.0;
8255
+
8256
+ tangents[ v * 4 ] = tmp.x;
8257
+ tangents[ v * 4 + 1 ] = tmp.y;
8258
+ tangents[ v * 4 + 2 ] = tmp.z;
8259
+ tangents[ v * 4 + 3 ] = w;
8260
+
8261
+ }
8262
+
8263
+ for ( j = 0, jl = drawcalls.length; j < jl; ++ j ) {
8264
+
8265
+ var start = drawcalls[ j ].start;
8266
+ var count = drawcalls[ j ].count;
8267
+ var index = drawcalls[ j ].index;
8268
+
8269
+ for ( i = start, il = start + count; i < il; i += 3 ) {
8270
+
8271
+ iA = index + indices[ i ];
8272
+ iB = index + indices[ i + 1 ];
8273
+ iC = index + indices[ i + 2 ];
8274
+
8275
+ handleVertex( iA );
8276
+ handleVertex( iB );
8277
+ handleVertex( iC );
8278
+
8279
+ }
8280
+
8281
+ }
8282
+
8283
+ },
8284
+
8285
+ /*
8286
+ computeOffsets
8287
+ Compute the draw offset for large models by chunking the index buffer into chunks of 65k addressable vertices.
8288
+ This method will effectively rewrite the index buffer and remap all attributes to match the new indices.
8289
+ WARNING: This method will also expand the vertex count to prevent sprawled triangles across draw offsets.
8290
+ indexBufferSize - Defaults to 65535, but allows for larger or smaller chunks.
8291
+ */
8292
+
8293
+ computeOffsets: function ( indexBufferSize ) {
8294
+
8295
+ var size = indexBufferSize;
8296
+ if ( indexBufferSize === undefined )
8297
+ size = 65535; //WebGL limits type of index buffer values to 16-bit.
8298
+
8299
+ var s = Date.now();
8300
+
8301
+ var indices = this.attributes.index.array;
8302
+ var vertices = this.attributes.position.array;
8303
+
8304
+ var verticesCount = ( vertices.length / 3 );
8305
+ var facesCount = ( indices.length / 3 );
8306
+
8307
+ /*
8308
+ console.log("Computing buffers in offsets of "+size+" -> indices:"+indices.length+" vertices:"+vertices.length);
8309
+ console.log("Faces to process: "+(indices.length/3));
8310
+ console.log("Reordering "+verticesCount+" vertices.");
8311
+ */
8312
+
8313
+ var sortedIndices = new Uint16Array( indices.length ); //16-bit buffers
8314
+ var indexPtr = 0;
8315
+ var vertexPtr = 0;
8316
+
8317
+ var offsets = [ { start:0, count:0, index:0 } ];
8318
+ var offset = offsets[ 0 ];
8319
+
8320
+ var duplicatedVertices = 0;
8321
+ var newVerticeMaps = 0;
8322
+ var faceVertices = new Int32Array( 6 );
8323
+ var vertexMap = new Int32Array( vertices.length );
8324
+ var revVertexMap = new Int32Array( vertices.length );
8325
+ for ( var j = 0; j < vertices.length; j ++ ) { vertexMap[ j ] = - 1; revVertexMap[ j ] = - 1; }
8326
+
8327
+ /*
8328
+ Traverse every face and reorder vertices in the proper offsets of 65k.
8329
+ We can have more than 65k entries in the index buffer per offset, but only reference 65k values.
8330
+ */
8331
+ for ( var findex = 0; findex < facesCount; findex ++ ) {
8332
+ newVerticeMaps = 0;
8333
+
8334
+ for ( var vo = 0; vo < 3; vo ++ ) {
8335
+ var vid = indices[ findex * 3 + vo ];
8336
+ if ( vertexMap[ vid ] == - 1 ) {
8337
+ //Unmapped vertice
8338
+ faceVertices[ vo * 2 ] = vid;
8339
+ faceVertices[ vo * 2 + 1 ] = - 1;
8340
+ newVerticeMaps ++;
8341
+ } else if ( vertexMap[ vid ] < offset.index ) {
8342
+ //Reused vertices from previous block (duplicate)
8343
+ faceVertices[ vo * 2 ] = vid;
8344
+ faceVertices[ vo * 2 + 1 ] = - 1;
8345
+ duplicatedVertices ++;
8346
+ } else {
8347
+ //Reused vertice in the current block
8348
+ faceVertices[ vo * 2 ] = vid;
8349
+ faceVertices[ vo * 2 + 1 ] = vertexMap[ vid ];
8350
+ }
8351
+ }
8352
+
8353
+ var faceMax = vertexPtr + newVerticeMaps;
8354
+ if ( faceMax > ( offset.index + size ) ) {
8355
+ var new_offset = { start:indexPtr, count:0, index:vertexPtr };
8356
+ offsets.push( new_offset );
8357
+ offset = new_offset;
8358
+
8359
+ //Re-evaluate reused vertices in light of new offset.
8360
+ for ( var v = 0; v < 6; v += 2 ) {
8361
+ var new_vid = faceVertices[ v + 1 ];
8362
+ if ( new_vid > - 1 && new_vid < offset.index )
8363
+ faceVertices[ v + 1 ] = - 1;
8364
+ }
8365
+ }
8366
+
8367
+ //Reindex the face.
8368
+ for ( var v = 0; v < 6; v += 2 ) {
8369
+ var vid = faceVertices[ v ];
8370
+ var new_vid = faceVertices[ v + 1 ];
8371
+
8372
+ if ( new_vid === - 1 )
8373
+ new_vid = vertexPtr ++;
8374
+
8375
+ vertexMap[ vid ] = new_vid;
8376
+ revVertexMap[ new_vid ] = vid;
8377
+ sortedIndices[ indexPtr ++ ] = new_vid - offset.index; //XXX overflows at 16bit
8378
+ offset.count ++;
8379
+ }
8380
+ }
8381
+
8382
+ /* Move all attribute values to map to the new computed indices , also expand the vertice stack to match our new vertexPtr. */
8383
+ this.reorderBuffers( sortedIndices, revVertexMap, vertexPtr );
8384
+ this.offsets = offsets;
8385
+
8386
+ /*
8387
+ var orderTime = Date.now();
8388
+ console.log("Reorder time: "+(orderTime-s)+"ms");
8389
+ console.log("Duplicated "+duplicatedVertices+" vertices.");
8390
+ console.log("Compute Buffers time: "+(Date.now()-s)+"ms");
8391
+ console.log("Draw offsets: "+offsets.length);
8392
+ */
8393
+
8394
+ return offsets;
8395
+ },
8396
+
8397
+ merge: function () {
8398
+
8399
+ console.log( 'BufferGeometry.merge(): TODO' );
8400
+
8401
+ },
8402
+
8403
+ normalizeNormals: function () {
8404
+
8405
+ var normals = this.attributes.normal.array;
8406
+
8407
+ var x, y, z, n;
8408
+
8409
+ for ( var i = 0, il = normals.length; i < il; i += 3 ) {
8410
+
8411
+ x = normals[ i ];
8412
+ y = normals[ i + 1 ];
8413
+ z = normals[ i + 2 ];
8414
+
8415
+ n = 1.0 / Math.sqrt( x * x + y * y + z * z );
8416
+
8417
+ normals[ i ] *= n;
8418
+ normals[ i + 1 ] *= n;
8419
+ normals[ i + 2 ] *= n;
8420
+
8421
+ }
8422
+
8423
+ },
8424
+
8425
+ /*
8426
+ reoderBuffers:
8427
+ Reorder attributes based on a new indexBuffer and indexMap.
8428
+ indexBuffer - Uint16Array of the new ordered indices.
8429
+ indexMap - Int32Array where the position is the new vertex ID and the value the old vertex ID for each vertex.
8430
+ vertexCount - Amount of total vertices considered in this reordering (in case you want to grow the vertice stack).
8431
+ */
8432
+ reorderBuffers: function ( indexBuffer, indexMap, vertexCount ) {
8433
+
8434
+ /* Create a copy of all attributes for reordering. */
8435
+ var sortedAttributes = {};
8436
+ for ( var attr in this.attributes ) {
8437
+ if ( attr == 'index' )
8438
+ continue;
8439
+ var sourceArray = this.attributes[ attr ].array;
8440
+ sortedAttributes[ attr ] = new sourceArray.constructor( this.attributes[ attr ].itemSize * vertexCount );
8441
+ }
8442
+
8443
+ /* Move attribute positions based on the new index map */
8444
+ for ( var new_vid = 0; new_vid < vertexCount; new_vid ++ ) {
8445
+ var vid = indexMap[ new_vid ];
8446
+ for ( var attr in this.attributes ) {
8447
+ if ( attr == 'index' )
8448
+ continue;
8449
+ var attrArray = this.attributes[ attr ].array;
8450
+ var attrSize = this.attributes[ attr ].itemSize;
8451
+ var sortedAttr = sortedAttributes[ attr ];
8452
+ for ( var k = 0; k < attrSize; k ++ )
8453
+ sortedAttr[ new_vid * attrSize + k ] = attrArray[ vid * attrSize + k ];
8454
+ }
8455
+ }
8456
+
8457
+ /* Carry the new sorted buffers locally */
8458
+ this.attributes[ 'index' ].array = indexBuffer;
8459
+ for ( var attr in this.attributes ) {
8460
+ if ( attr == 'index' )
8461
+ continue;
8462
+ this.attributes[ attr ].array = sortedAttributes[ attr ];
8463
+ this.attributes[ attr ].numItems = this.attributes[ attr ].itemSize * vertexCount;
8464
+ }
8465
+ },
8466
+
8467
+ toJSON: function () {
8468
+
8469
+ var output = {
8470
+ metadata: {
8471
+ version: 4.0,
8472
+ type: 'BufferGeometry',
8473
+ generator: 'BufferGeometryExporter'
8474
+ },
8475
+ uuid: this.uuid,
8476
+ type: this.type,
8477
+ data: {
8478
+ attributes: {}
8479
+ }
8480
+ };
8481
+
8482
+ var attributes = this.attributes;
8483
+ var offsets = this.offsets;
8484
+ var boundingSphere = this.boundingSphere;
8485
+
8486
+ for ( var key in attributes ) {
8487
+
8488
+ var attribute = attributes[ key ];
8489
+
8490
+ var array = [], typeArray = attribute.array;
8491
+
8492
+ for ( var i = 0, l = typeArray.length; i < l; i ++ ) {
8493
+
8494
+ array[ i ] = typeArray[ i ];
8495
+
8496
+ }
8497
+
8498
+ output.data.attributes[ key ] = {
8499
+ itemSize: attribute.itemSize,
8500
+ type: attribute.array.constructor.name,
8501
+ array: array
8502
+ }
8503
+
8504
+ }
8505
+
8506
+ if ( offsets.length > 0 ) {
8507
+
8508
+ output.data.offsets = JSON.parse( JSON.stringify( offsets ) );
8509
+
8510
+ }
8511
+
8512
+ if ( boundingSphere !== null ) {
8513
+
8514
+ output.data.boundingSphere = {
8515
+ center: boundingSphere.center.toArray(),
8516
+ radius: boundingSphere.radius
8517
+ }
8518
+
8519
+ }
8520
+
8521
+ return output;
8522
+
8523
+ },
8524
+
8525
+ clone: function () {
8526
+
8527
+ var geometry = new THREE.BufferGeometry();
8528
+
8529
+ for ( var attr in this.attributes ) {
8530
+
8531
+ var sourceAttr = this.attributes[ attr ];
8532
+ geometry.addAttribute( attr, sourceAttr.clone() );
8533
+
8534
+ }
8535
+
8536
+ for ( var i = 0, il = this.offsets.length; i < il; i ++ ) {
8537
+
8538
+ var offset = this.offsets[ i ];
8539
+
8540
+ geometry.offsets.push( {
8541
+
8542
+ start: offset.start,
8543
+ index: offset.index,
8544
+ count: offset.count
8545
+
8546
+ } );
8547
+
8548
+ }
8549
+
8550
+ return geometry;
8551
+
8552
+ },
8553
+
8554
+ dispose: function () {
8555
+
8556
+ this.dispatchEvent( { type: 'dispose' } );
8557
+
8558
+ }
8559
+
8560
+ };
8561
+
8562
+ THREE.EventDispatcher.prototype.apply( THREE.BufferGeometry.prototype );
8563
+
8564
+ // File:src/core/Geometry.js
8565
+
8566
+ /**
8567
+ * @author mrdoob / http://mrdoob.com/
8568
+ * @author kile / http://kile.stravaganza.org/
8569
+ * @author alteredq / http://alteredqualia.com/
8570
+ * @author mikael emtinger / http://gomo.se/
8571
+ * @author zz85 / http://www.lab4games.net/zz85/blog
8572
+ * @author bhouston / http://exocortex.com
8573
+ */
8574
+
8575
+ THREE.Geometry = function () {
8576
+
8577
+ Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
8578
+
8579
+ this.uuid = THREE.Math.generateUUID();
8580
+
8581
+ this.name = '';
8582
+ this.type = 'Geometry';
8583
+
8584
+ this.vertices = [];
8585
+ this.colors = []; // one-to-one vertex colors, used in Points and Line
8586
+
8587
+ this.faces = [];
8588
+
8589
+ this.faceVertexUvs = [ [] ];
8590
+
8591
+ this.morphTargets = [];
8592
+ this.morphColors = [];
8593
+ this.morphNormals = [];
8594
+
8595
+ this.skinWeights = [];
8596
+ this.skinIndices = [];
8597
+
8598
+ this.lineDistances = [];
8599
+
8600
+ this.boundingBox = null;
8601
+ this.boundingSphere = null;
8602
+
8603
+ this.hasTangents = false;
8604
+
8605
+ this.dynamic = true; // the intermediate typed arrays will be deleted when set to false
8606
+
8607
+ // update flags
8608
+
8609
+ this.verticesNeedUpdate = false;
8610
+ this.elementsNeedUpdate = false;
8611
+ this.uvsNeedUpdate = false;
8612
+ this.normalsNeedUpdate = false;
8613
+ this.tangentsNeedUpdate = false;
8614
+ this.colorsNeedUpdate = false;
8615
+ this.lineDistancesNeedUpdate = false;
8616
+
8617
+ this.groupsNeedUpdate = false;
8618
+
8619
+ };
8620
+
8621
+ THREE.Geometry.prototype = {
8622
+
8623
+ constructor: THREE.Geometry,
8624
+
8625
+ applyMatrix: function ( matrix ) {
8626
+
8627
+ var normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
8628
+
8629
+ for ( var i = 0, il = this.vertices.length; i < il; i ++ ) {
8630
+
8631
+ var vertex = this.vertices[ i ];
8632
+ vertex.applyMatrix4( matrix );
8633
+
8634
+ }
8635
+
8636
+ for ( var i = 0, il = this.faces.length; i < il; i ++ ) {
8637
+
8638
+ var face = this.faces[ i ];
8639
+ face.normal.applyMatrix3( normalMatrix ).normalize();
8640
+
8641
+ for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
8642
+
8643
+ face.vertexNormals[ j ].applyMatrix3( normalMatrix ).normalize();
8644
+
8645
+ }
8646
+
8647
+ }
8648
+
8649
+ if ( this.boundingBox instanceof THREE.Box3 ) {
8650
+
8651
+ this.computeBoundingBox();
8652
+
8653
+ }
8654
+
8655
+ if ( this.boundingSphere instanceof THREE.Sphere ) {
8656
+
8657
+ this.computeBoundingSphere();
8658
+
8659
+ }
8660
+
8661
+ },
8662
+
8663
+ fromBufferGeometry: function ( geometry ) {
8664
+
8665
+ var scope = this;
8666
+
8667
+ var attributes = geometry.attributes;
8668
+
8669
+ var vertices = attributes.position.array;
8670
+ var indices = attributes.index !== undefined ? attributes.index.array : undefined;
8671
+ var normals = attributes.normal !== undefined ? attributes.normal.array : undefined;
8672
+ var colors = attributes.color !== undefined ? attributes.color.array : undefined;
8673
+ var uvs = attributes.uv !== undefined ? attributes.uv.array : undefined;
8674
+
8675
+ var tempNormals = [];
8676
+ var tempUVs = [];
8677
+
8678
+ for ( var i = 0, j = 0; i < vertices.length; i += 3, j += 2 ) {
8679
+
8680
+ scope.vertices.push( new THREE.Vector3( vertices[ i ], vertices[ i + 1 ], vertices[ i + 2 ] ) );
8681
+
8682
+ if ( normals !== undefined ) {
8683
+
8684
+ tempNormals.push( new THREE.Vector3( normals[ i ], normals[ i + 1 ], normals[ i + 2 ] ) );
8685
+
8686
+ }
8687
+
8688
+ if ( colors !== undefined ) {
8689
+
8690
+ scope.colors.push( new THREE.Color( colors[ i ], colors[ i + 1 ], colors[ i + 2 ] ) );
8691
+
8692
+ }
8693
+
8694
+ if ( uvs !== undefined ) {
8695
+
8696
+ tempUVs.push( new THREE.Vector2( uvs[ j ], uvs[ j + 1 ] ) );
8697
+
8698
+ }
8699
+
8700
+ }
8701
+
8702
+ var addFace = function ( a, b, c ) {
8703
+
8704
+ var vertexNormals = normals !== undefined ? [ tempNormals[ a ].clone(), tempNormals[ b ].clone(), tempNormals[ c ].clone() ] : [];
8705
+ var vertexColors = colors !== undefined ? [ scope.colors[ a ].clone(), scope.colors[ b ].clone(), scope.colors[ c ].clone() ] : [];
8706
+
8707
+ scope.faces.push( new THREE.Face3( a, b, c, vertexNormals, vertexColors ) );
8708
+ scope.faceVertexUvs[ 0 ].push( [ tempUVs[ a ], tempUVs[ b ], tempUVs[ c ] ] );
8709
+
8710
+ };
8711
+
8712
+ if ( indices !== undefined ) {
8713
+
8714
+ for ( var i = 0; i < indices.length; i += 3 ) {
8715
+
8716
+ addFace( indices[ i ], indices[ i + 1 ], indices[ i + 2 ] );
8717
+
8718
+ }
8719
+
8720
+ } else {
8721
+
8722
+ for ( var i = 0; i < vertices.length / 3; i += 3 ) {
8723
+
8724
+ addFace( i, i + 1, i + 2 );
8725
+
8726
+ }
8727
+
8728
+ }
8729
+
8730
+ this.computeFaceNormals();
8731
+
8732
+ if ( geometry.boundingBox !== null ) {
8733
+
8734
+ this.boundingBox = geometry.boundingBox.clone();
8735
+
8736
+ }
8737
+
8738
+ if ( geometry.boundingSphere !== null ) {
8739
+
8740
+ this.boundingSphere = geometry.boundingSphere.clone();
8741
+
8742
+ }
8743
+
8744
+ return this;
8745
+
8746
+ },
8747
+
8748
+ center: function () {
8749
+
8750
+ this.computeBoundingBox();
8751
+
8752
+ var offset = new THREE.Vector3();
8753
+
8754
+ offset.addVectors( this.boundingBox.min, this.boundingBox.max );
8755
+ offset.multiplyScalar( - 0.5 );
8756
+
8757
+ this.applyMatrix( new THREE.Matrix4().makeTranslation( offset.x, offset.y, offset.z ) );
8758
+ this.computeBoundingBox();
8759
+
8760
+ return offset;
8761
+
8762
+ },
8763
+
8764
+ computeFaceNormals: function () {
8765
+
8766
+ var cb = new THREE.Vector3(), ab = new THREE.Vector3();
8767
+
8768
+ for ( var f = 0, fl = this.faces.length; f < fl; f ++ ) {
8769
+
8770
+ var face = this.faces[ f ];
8771
+
8772
+ var vA = this.vertices[ face.a ];
8773
+ var vB = this.vertices[ face.b ];
8774
+ var vC = this.vertices[ face.c ];
8775
+
8776
+ cb.subVectors( vC, vB );
8777
+ ab.subVectors( vA, vB );
8778
+ cb.cross( ab );
8779
+
8780
+ cb.normalize();
8781
+
8782
+ face.normal.copy( cb );
8783
+
8784
+ }
8785
+
8786
+ },
8787
+
8788
+ computeVertexNormals: function ( areaWeighted ) {
8789
+
8790
+ var v, vl, f, fl, face, vertices;
8791
+
8792
+ vertices = new Array( this.vertices.length );
8793
+
8794
+ for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
8795
+
8796
+ vertices[ v ] = new THREE.Vector3();
8797
+
8798
+ }
8799
+
8800
+ if ( areaWeighted ) {
8801
+
8802
+ // vertex normals weighted by triangle areas
8803
+ // http://www.iquilezles.org/www/articles/normals/normals.htm
8804
+
8805
+ var vA, vB, vC, vD;
8806
+ var cb = new THREE.Vector3(), ab = new THREE.Vector3(),
8807
+ db = new THREE.Vector3(), dc = new THREE.Vector3(), bc = new THREE.Vector3();
8808
+
8809
+ for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
8810
+
8811
+ face = this.faces[ f ];
8812
+
8813
+ vA = this.vertices[ face.a ];
8814
+ vB = this.vertices[ face.b ];
8815
+ vC = this.vertices[ face.c ];
8816
+
8817
+ cb.subVectors( vC, vB );
8818
+ ab.subVectors( vA, vB );
8819
+ cb.cross( ab );
8820
+
8821
+ vertices[ face.a ].add( cb );
8822
+ vertices[ face.b ].add( cb );
8823
+ vertices[ face.c ].add( cb );
8824
+
8825
+ }
8826
+
8827
+ } else {
8828
+
8829
+ for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
8830
+
8831
+ face = this.faces[ f ];
8832
+
8833
+ vertices[ face.a ].add( face.normal );
8834
+ vertices[ face.b ].add( face.normal );
8835
+ vertices[ face.c ].add( face.normal );
8836
+
8837
+ }
8838
+
8839
+ }
8840
+
8841
+ for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
8842
+
8843
+ vertices[ v ].normalize();
8844
+
8845
+ }
8846
+
8847
+ for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
8848
+
8849
+ face = this.faces[ f ];
8850
+
8851
+ face.vertexNormals[ 0 ] = vertices[ face.a ].clone();
8852
+ face.vertexNormals[ 1 ] = vertices[ face.b ].clone();
8853
+ face.vertexNormals[ 2 ] = vertices[ face.c ].clone();
8854
+
8855
+ }
8856
+
8857
+ },
8858
+
8859
+ computeMorphNormals: function () {
8860
+
8861
+ var i, il, f, fl, face;
8862
+
8863
+ // save original normals
8864
+ // - create temp variables on first access
8865
+ // otherwise just copy (for faster repeated calls)
8866
+
8867
+ for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
8868
+
8869
+ face = this.faces[ f ];
8870
+
8871
+ if ( ! face.__originalFaceNormal ) {
8872
+
8873
+ face.__originalFaceNormal = face.normal.clone();
8874
+
8875
+ } else {
8876
+
8877
+ face.__originalFaceNormal.copy( face.normal );
8878
+
8879
+ }
8880
+
8881
+ if ( ! face.__originalVertexNormals ) face.__originalVertexNormals = [];
8882
+
8883
+ for ( i = 0, il = face.vertexNormals.length; i < il; i ++ ) {
8884
+
8885
+ if ( ! face.__originalVertexNormals[ i ] ) {
8886
+
8887
+ face.__originalVertexNormals[ i ] = face.vertexNormals[ i ].clone();
8888
+
8889
+ } else {
8890
+
8891
+ face.__originalVertexNormals[ i ].copy( face.vertexNormals[ i ] );
8892
+
8893
+ }
8894
+
8895
+ }
8896
+
8897
+ }
8898
+
8899
+ // use temp geometry to compute face and vertex normals for each morph
8900
+
8901
+ var tmpGeo = new THREE.Geometry();
8902
+ tmpGeo.faces = this.faces;
8903
+
8904
+ for ( i = 0, il = this.morphTargets.length; i < il; i ++ ) {
8905
+
8906
+ // create on first access
8907
+
8908
+ if ( ! this.morphNormals[ i ] ) {
8909
+
8910
+ this.morphNormals[ i ] = {};
8911
+ this.morphNormals[ i ].faceNormals = [];
8912
+ this.morphNormals[ i ].vertexNormals = [];
8913
+
8914
+ var dstNormalsFace = this.morphNormals[ i ].faceNormals;
8915
+ var dstNormalsVertex = this.morphNormals[ i ].vertexNormals;
8916
+
8917
+ var faceNormal, vertexNormals;
8918
+
8919
+ for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
8920
+
8921
+ faceNormal = new THREE.Vector3();
8922
+ vertexNormals = { a: new THREE.Vector3(), b: new THREE.Vector3(), c: new THREE.Vector3() };
8923
+
8924
+ dstNormalsFace.push( faceNormal );
8925
+ dstNormalsVertex.push( vertexNormals );
8926
+
8927
+ }
8928
+
8929
+ }
8930
+
8931
+ var morphNormals = this.morphNormals[ i ];
8932
+
8933
+ // set vertices to morph target
8934
+
8935
+ tmpGeo.vertices = this.morphTargets[ i ].vertices;
8936
+
8937
+ // compute morph normals
8938
+
8939
+ tmpGeo.computeFaceNormals();
8940
+ tmpGeo.computeVertexNormals();
8941
+
8942
+ // store morph normals
8943
+
8944
+ var faceNormal, vertexNormals;
8945
+
8946
+ for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
8947
+
8948
+ face = this.faces[ f ];
8949
+
8950
+ faceNormal = morphNormals.faceNormals[ f ];
8951
+ vertexNormals = morphNormals.vertexNormals[ f ];
8952
+
8953
+ faceNormal.copy( face.normal );
8954
+
8955
+ vertexNormals.a.copy( face.vertexNormals[ 0 ] );
8956
+ vertexNormals.b.copy( face.vertexNormals[ 1 ] );
8957
+ vertexNormals.c.copy( face.vertexNormals[ 2 ] );
8958
+
8959
+ }
8960
+
8961
+ }
8962
+
8963
+ // restore original normals
8964
+
8965
+ for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
8966
+
8967
+ face = this.faces[ f ];
8968
+
8969
+ face.normal = face.__originalFaceNormal;
8970
+ face.vertexNormals = face.__originalVertexNormals;
8971
+
8972
+ }
8973
+
8974
+ },
8975
+
8976
+ computeTangents: function () {
8977
+
8978
+ // based on http://www.terathon.com/code/tangent.html
8979
+ // tangents go to vertices
8980
+
8981
+ var f, fl, v, vl, i, il, vertexIndex,
8982
+ face, uv, vA, vB, vC, uvA, uvB, uvC,
8983
+ x1, x2, y1, y2, z1, z2,
8984
+ s1, s2, t1, t2, r, t, test,
8985
+ tan1 = [], tan2 = [],
8986
+ sdir = new THREE.Vector3(), tdir = new THREE.Vector3(),
8987
+ tmp = new THREE.Vector3(), tmp2 = new THREE.Vector3(),
8988
+ n = new THREE.Vector3(), w;
8989
+
8990
+ for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
8991
+
8992
+ tan1[ v ] = new THREE.Vector3();
8993
+ tan2[ v ] = new THREE.Vector3();
8994
+
8995
+ }
8996
+
8997
+ function handleTriangle( context, a, b, c, ua, ub, uc ) {
8998
+
8999
+ vA = context.vertices[ a ];
9000
+ vB = context.vertices[ b ];
9001
+ vC = context.vertices[ c ];
9002
+
9003
+ uvA = uv[ ua ];
9004
+ uvB = uv[ ub ];
9005
+ uvC = uv[ uc ];
9006
+
9007
+ x1 = vB.x - vA.x;
9008
+ x2 = vC.x - vA.x;
9009
+ y1 = vB.y - vA.y;
9010
+ y2 = vC.y - vA.y;
9011
+ z1 = vB.z - vA.z;
9012
+ z2 = vC.z - vA.z;
9013
+
9014
+ s1 = uvB.x - uvA.x;
9015
+ s2 = uvC.x - uvA.x;
9016
+ t1 = uvB.y - uvA.y;
9017
+ t2 = uvC.y - uvA.y;
9018
+
9019
+ r = 1.0 / ( s1 * t2 - s2 * t1 );
9020
+ sdir.set( ( t2 * x1 - t1 * x2 ) * r,
9021
+ ( t2 * y1 - t1 * y2 ) * r,
9022
+ ( t2 * z1 - t1 * z2 ) * r );
9023
+ tdir.set( ( s1 * x2 - s2 * x1 ) * r,
9024
+ ( s1 * y2 - s2 * y1 ) * r,
9025
+ ( s1 * z2 - s2 * z1 ) * r );
9026
+
9027
+ tan1[ a ].add( sdir );
9028
+ tan1[ b ].add( sdir );
9029
+ tan1[ c ].add( sdir );
9030
+
9031
+ tan2[ a ].add( tdir );
9032
+ tan2[ b ].add( tdir );
9033
+ tan2[ c ].add( tdir );
9034
+
9035
+ }
9036
+
9037
+ for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
9038
+
9039
+ face = this.faces[ f ];
9040
+ uv = this.faceVertexUvs[ 0 ][ f ]; // use UV layer 0 for tangents
9041
+
9042
+ handleTriangle( this, face.a, face.b, face.c, 0, 1, 2 );
9043
+
9044
+ }
9045
+
9046
+ var faceIndex = [ 'a', 'b', 'c', 'd' ];
9047
+
9048
+ for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
9049
+
9050
+ face = this.faces[ f ];
9051
+
9052
+ for ( i = 0; i < Math.min( face.vertexNormals.length, 3 ); i ++ ) {
9053
+
9054
+ n.copy( face.vertexNormals[ i ] );
9055
+
9056
+ vertexIndex = face[ faceIndex[ i ] ];
9057
+
9058
+ t = tan1[ vertexIndex ];
9059
+
9060
+ // Gram-Schmidt orthogonalize
9061
+
9062
+ tmp.copy( t );
9063
+ tmp.sub( n.multiplyScalar( n.dot( t ) ) ).normalize();
9064
+
9065
+ // Calculate handedness
9066
+
9067
+ tmp2.crossVectors( face.vertexNormals[ i ], t );
9068
+ test = tmp2.dot( tan2[ vertexIndex ] );
9069
+ w = ( test < 0.0 ) ? - 1.0 : 1.0;
9070
+
9071
+ face.vertexTangents[ i ] = new THREE.Vector4( tmp.x, tmp.y, tmp.z, w );
9072
+
9073
+ }
9074
+
9075
+ }
9076
+
9077
+ this.hasTangents = true;
9078
+
9079
+ },
9080
+
9081
+ computeLineDistances: function () {
9082
+
9083
+ var d = 0;
9084
+ var vertices = this.vertices;
9085
+
9086
+ for ( var i = 0, il = vertices.length; i < il; i ++ ) {
9087
+
9088
+ if ( i > 0 ) {
9089
+
9090
+ d += vertices[ i ].distanceTo( vertices[ i - 1 ] );
9091
+
9092
+ }
9093
+
9094
+ this.lineDistances[ i ] = d;
9095
+
9096
+ }
9097
+
9098
+ },
9099
+
9100
+ computeBoundingBox: function () {
9101
+
9102
+ if ( this.boundingBox === null ) {
9103
+
9104
+ this.boundingBox = new THREE.Box3();
9105
+
9106
+ }
9107
+
9108
+ this.boundingBox.setFromPoints( this.vertices );
9109
+
9110
+ },
9111
+
9112
+ computeBoundingSphere: function () {
9113
+
9114
+ if ( this.boundingSphere === null ) {
9115
+
9116
+ this.boundingSphere = new THREE.Sphere();
9117
+
9118
+ }
9119
+
9120
+ this.boundingSphere.setFromPoints( this.vertices );
9121
+
9122
+ },
9123
+
9124
+ merge: function ( geometry, matrix, materialIndexOffset ) {
9125
+
9126
+ if ( geometry instanceof THREE.Geometry === false ) {
9127
+
9128
+ console.error( 'THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry );
9129
+ return;
9130
+
9131
+ }
9132
+
9133
+ var normalMatrix,
9134
+ vertexOffset = this.vertices.length,
9135
+ vertices1 = this.vertices,
9136
+ vertices2 = geometry.vertices,
9137
+ faces1 = this.faces,
9138
+ faces2 = geometry.faces,
9139
+ uvs1 = this.faceVertexUvs[ 0 ],
9140
+ uvs2 = geometry.faceVertexUvs[ 0 ];
9141
+
9142
+ if ( materialIndexOffset === undefined ) materialIndexOffset = 0;
9143
+
9144
+ if ( matrix !== undefined ) {
9145
+
9146
+ normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
9147
+
9148
+ }
9149
+
9150
+ // vertices
9151
+
9152
+ for ( var i = 0, il = vertices2.length; i < il; i ++ ) {
9153
+
9154
+ var vertex = vertices2[ i ];
9155
+
9156
+ var vertexCopy = vertex.clone();
9157
+
9158
+ if ( matrix !== undefined ) vertexCopy.applyMatrix4( matrix );
9159
+
9160
+ vertices1.push( vertexCopy );
9161
+
9162
+ }
9163
+
9164
+ // faces
9165
+
9166
+ for ( i = 0, il = faces2.length; i < il; i ++ ) {
9167
+
9168
+ var face = faces2[ i ], faceCopy, normal, color,
9169
+ faceVertexNormals = face.vertexNormals,
9170
+ faceVertexColors = face.vertexColors;
9171
+
9172
+ faceCopy = new THREE.Face3( face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset );
9173
+ faceCopy.normal.copy( face.normal );
9174
+
9175
+ if ( normalMatrix !== undefined ) {
9176
+
9177
+ faceCopy.normal.applyMatrix3( normalMatrix ).normalize();
9178
+
9179
+ }
9180
+
9181
+ for ( var j = 0, jl = faceVertexNormals.length; j < jl; j ++ ) {
9182
+
9183
+ normal = faceVertexNormals[ j ].clone();
9184
+
9185
+ if ( normalMatrix !== undefined ) {
9186
+
9187
+ normal.applyMatrix3( normalMatrix ).normalize();
9188
+
9189
+ }
9190
+
9191
+ faceCopy.vertexNormals.push( normal );
9192
+
9193
+ }
9194
+
9195
+ faceCopy.color.copy( face.color );
9196
+
9197
+ for ( var j = 0, jl = faceVertexColors.length; j < jl; j ++ ) {
9198
+
9199
+ color = faceVertexColors[ j ];
9200
+ faceCopy.vertexColors.push( color.clone() );
9201
+
9202
+ }
9203
+
9204
+ faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
9205
+
9206
+ faces1.push( faceCopy );
9207
+
9208
+ }
9209
+
9210
+ // uvs
9211
+
9212
+ for ( i = 0, il = uvs2.length; i < il; i ++ ) {
9213
+
9214
+ var uv = uvs2[ i ], uvCopy = [];
9215
+
9216
+ if ( uv === undefined ) {
9217
+
9218
+ continue;
9219
+
9220
+ }
9221
+
9222
+ for ( var j = 0, jl = uv.length; j < jl; j ++ ) {
9223
+
9224
+ uvCopy.push( new THREE.Vector2( uv[ j ].x, uv[ j ].y ) );
9225
+
9226
+ }
9227
+
9228
+ uvs1.push( uvCopy );
9229
+
9230
+ }
9231
+
9232
+ },
9233
+
9234
+ /*
9235
+ * Checks for duplicate vertices with hashmap.
9236
+ * Duplicated vertices are removed
9237
+ * and faces' vertices are updated.
9238
+ */
9239
+
9240
+ mergeVertices: function () {
9241
+
9242
+ var verticesMap = {}; // Hashmap for looking up vertice by position coordinates (and making sure they are unique)
9243
+ var unique = [], changes = [];
9244
+
9245
+ var v, key;
9246
+ var precisionPoints = 4; // number of decimal points, eg. 4 for epsilon of 0.0001
9247
+ var precision = Math.pow( 10, precisionPoints );
9248
+ var i,il, face;
9249
+ var indices, k, j, jl, u;
9250
+
9251
+ for ( i = 0, il = this.vertices.length; i < il; i ++ ) {
9252
+
9253
+ v = this.vertices[ i ];
9254
+ key = Math.round( v.x * precision ) + '_' + Math.round( v.y * precision ) + '_' + Math.round( v.z * precision );
9255
+
9256
+ if ( verticesMap[ key ] === undefined ) {
9257
+
9258
+ verticesMap[ key ] = i;
9259
+ unique.push( this.vertices[ i ] );
9260
+ changes[ i ] = unique.length - 1;
9261
+
9262
+ } else {
9263
+
9264
+ //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
9265
+ changes[ i ] = changes[ verticesMap[ key ] ];
9266
+
9267
+ }
9268
+
9269
+ };
9270
+
9271
+
9272
+ // if faces are completely degenerate after merging vertices, we
9273
+ // have to remove them from the geometry.
9274
+ var faceIndicesToRemove = [];
9275
+
9276
+ for ( i = 0, il = this.faces.length; i < il; i ++ ) {
9277
+
9278
+ face = this.faces[ i ];
9279
+
9280
+ face.a = changes[ face.a ];
9281
+ face.b = changes[ face.b ];
9282
+ face.c = changes[ face.c ];
9283
+
9284
+ indices = [ face.a, face.b, face.c ];
9285
+
9286
+ var dupIndex = - 1;
9287
+
9288
+ // if any duplicate vertices are found in a Face3
9289
+ // we have to remove the face as nothing can be saved
9290
+ for ( var n = 0; n < 3; n ++ ) {
9291
+ if ( indices[ n ] == indices[ ( n + 1 ) % 3 ] ) {
9292
+
9293
+ dupIndex = n;
9294
+ faceIndicesToRemove.push( i );
9295
+ break;
9296
+
9297
+ }
9298
+ }
9299
+
9300
+ }
9301
+
9302
+ for ( i = faceIndicesToRemove.length - 1; i >= 0; i -- ) {
9303
+ var idx = faceIndicesToRemove[ i ];
9304
+
9305
+ this.faces.splice( idx, 1 );
9306
+
9307
+ for ( j = 0, jl = this.faceVertexUvs.length; j < jl; j ++ ) {
9308
+
9309
+ this.faceVertexUvs[ j ].splice( idx, 1 );
9310
+
9311
+ }
9312
+
9313
+ }
9314
+
9315
+ // Use unique set of vertices
9316
+
9317
+ var diff = this.vertices.length - unique.length;
9318
+ this.vertices = unique;
9319
+ return diff;
9320
+
9321
+ },
9322
+
9323
+ toJSON: function () {
9324
+
9325
+ var output = {
9326
+ metadata: {
9327
+ version: 4.0,
9328
+ type: 'BufferGeometry',
9329
+ generator: 'BufferGeometryExporter'
9330
+ },
9331
+ uuid: this.uuid,
9332
+ type: this.type
9333
+ };
9334
+
9335
+ if ( this.name !== "" ) output.name = this.name;
9336
+
9337
+ if ( this.parameters !== undefined ) {
9338
+
9339
+ var parameters = this.parameters;
9340
+
9341
+ for ( var key in parameters ) {
9342
+
9343
+ if ( parameters[ key ] !== undefined ) output[ key ] = parameters[ key ];
9344
+
9345
+ }
9346
+
9347
+ return output;
9348
+
9349
+ }
9350
+
9351
+ var vertices = [];
9352
+
9353
+ for ( var i = 0; i < this.vertices.length; i ++ ) {
9354
+
9355
+ var vertex = this.vertices[ i ];
9356
+ vertices.push( vertex.x, vertex.y, vertex.z );
9357
+
9358
+ }
9359
+
9360
+ var faces = [];
9361
+ var normals = [];
9362
+ var normalsHash = {};
9363
+ var colors = [];
9364
+ var colorsHash = {};
9365
+ var uvs = [];
9366
+ var uvsHash = {};
9367
+
9368
+ for ( var i = 0; i < this.faces.length; i ++ ) {
9369
+
9370
+ var face = this.faces[ i ];
9371
+
9372
+ var hasMaterial = false; // face.materialIndex !== undefined;
9373
+ var hasFaceUv = false; // deprecated
9374
+ var hasFaceVertexUv = this.faceVertexUvs[ 0 ][ i ] !== undefined;
9375
+ var hasFaceNormal = face.normal.length() > 0;
9376
+ var hasFaceVertexNormal = face.vertexNormals.length > 0;
9377
+ var hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
9378
+ var hasFaceVertexColor = face.vertexColors.length > 0;
9379
+
9380
+ var faceType = 0;
9381
+
9382
+ faceType = setBit( faceType, 0, 0 );
9383
+ faceType = setBit( faceType, 1, hasMaterial );
9384
+ faceType = setBit( faceType, 2, hasFaceUv );
9385
+ faceType = setBit( faceType, 3, hasFaceVertexUv );
9386
+ faceType = setBit( faceType, 4, hasFaceNormal );
9387
+ faceType = setBit( faceType, 5, hasFaceVertexNormal );
9388
+ faceType = setBit( faceType, 6, hasFaceColor );
9389
+ faceType = setBit( faceType, 7, hasFaceVertexColor );
9390
+
9391
+ faces.push( faceType );
9392
+ faces.push( face.a, face.b, face.c );
9393
+
9394
+
9395
+ /*
9396
+ if ( hasMaterial ) {
9397
+
9398
+ faces.push( face.materialIndex );
9399
+
9400
+ }
9401
+ */
9402
+
9403
+ if ( hasFaceVertexUv ) {
9404
+
9405
+ var faceVertexUvs = this.faceVertexUvs[ 0 ][ i ];
9406
+
9407
+ faces.push(
9408
+ getUvIndex( faceVertexUvs[ 0 ] ),
9409
+ getUvIndex( faceVertexUvs[ 1 ] ),
9410
+ getUvIndex( faceVertexUvs[ 2 ] )
9411
+ );
9412
+
9413
+ }
9414
+
9415
+ if ( hasFaceNormal ) {
9416
+
9417
+ faces.push( getNormalIndex( face.normal ) );
9418
+
9419
+ }
9420
+
9421
+ if ( hasFaceVertexNormal ) {
9422
+
9423
+ var vertexNormals = face.vertexNormals;
9424
+
9425
+ faces.push(
9426
+ getNormalIndex( vertexNormals[ 0 ] ),
9427
+ getNormalIndex( vertexNormals[ 1 ] ),
9428
+ getNormalIndex( vertexNormals[ 2 ] )
9429
+ );
9430
+
9431
+ }
9432
+
9433
+ if ( hasFaceColor ) {
9434
+
9435
+ faces.push( getColorIndex( face.color ) );
9436
+
9437
+ }
9438
+
9439
+ if ( hasFaceVertexColor ) {
9440
+
9441
+ var vertexColors = face.vertexColors;
9442
+
9443
+ faces.push(
9444
+ getColorIndex( vertexColors[ 0 ] ),
9445
+ getColorIndex( vertexColors[ 1 ] ),
9446
+ getColorIndex( vertexColors[ 2 ] )
9447
+ );
9448
+
9449
+ }
9450
+
9451
+ }
9452
+
9453
+ function setBit( value, position, enabled ) {
9454
+
9455
+ return enabled ? value | ( 1 << position ) : value & ( ~ ( 1 << position) );
9456
+
9457
+ }
9458
+
9459
+ function getNormalIndex( normal ) {
9460
+
9461
+ var hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
9462
+
9463
+ if ( normalsHash[ hash ] !== undefined ) {
9464
+
9465
+ return normalsHash[ hash ];
9466
+
9467
+ }
9468
+
9469
+ normalsHash[ hash ] = normals.length / 3;
9470
+ normals.push( normal.x, normal.y, normal.z );
9471
+
9472
+ return normalsHash[ hash ];
9473
+
9474
+ }
9475
+
9476
+ function getColorIndex( color ) {
9477
+
9478
+ var hash = color.r.toString() + color.g.toString() + color.b.toString();
9479
+
9480
+ if ( colorsHash[ hash ] !== undefined ) {
9481
+
9482
+ return colorsHash[ hash ];
9483
+
9484
+ }
9485
+
9486
+ colorsHash[ hash ] = colors.length;
9487
+ colors.push( color.getHex() );
9488
+
9489
+ return colorsHash[ hash ];
9490
+
9491
+ }
9492
+
9493
+ function getUvIndex( uv ) {
9494
+
9495
+ var hash = uv.x.toString() + uv.y.toString();
9496
+
9497
+ if ( uvsHash[ hash ] !== undefined ) {
9498
+
9499
+ return uvsHash[ hash ];
9500
+
9501
+ }
9502
+
9503
+ uvsHash[ hash ] = uvs.length / 2;
9504
+ uvs.push( uv.x, uv.y );
9505
+
9506
+ return uvsHash[ hash ];
9507
+
9508
+ }
9509
+
9510
+ output.data = {};
9511
+
9512
+ output.data.vertices = vertices;
9513
+ output.data.normals = normals;
9514
+ if ( colors.length > 0 ) output.data.colors = colors;
9515
+ if ( uvs.length > 0 ) output.data.uvs = [ uvs ]; // temporal backward compatibility
9516
+ output.data.faces = faces;
9517
+
9518
+ //
9519
+
9520
+ return output;
9521
+
9522
+ },
9523
+
9524
+ clone: function () {
9525
+
9526
+ var geometry = new THREE.Geometry();
9527
+
9528
+ var vertices = this.vertices;
9529
+
9530
+ for ( var i = 0, il = vertices.length; i < il; i ++ ) {
9531
+
9532
+ geometry.vertices.push( vertices[ i ].clone() );
9533
+
9534
+ }
9535
+
9536
+ var faces = this.faces;
9537
+
9538
+ for ( var i = 0, il = faces.length; i < il; i ++ ) {
9539
+
9540
+ geometry.faces.push( faces[ i ].clone() );
9541
+
9542
+ }
9543
+
9544
+ var uvs = this.faceVertexUvs[ 0 ];
9545
+
9546
+ for ( var i = 0, il = uvs.length; i < il; i ++ ) {
9547
+
9548
+ var uv = uvs[ i ], uvCopy = [];
9549
+
9550
+ for ( var j = 0, jl = uv.length; j < jl; j ++ ) {
9551
+
9552
+ uvCopy.push( new THREE.Vector2( uv[ j ].x, uv[ j ].y ) );
9553
+
9554
+ }
9555
+
9556
+ geometry.faceVertexUvs[ 0 ].push( uvCopy );
9557
+
9558
+ }
9559
+
9560
+ return geometry;
9561
+
9562
+ },
9563
+
9564
+ dispose: function () {
9565
+
9566
+ this.dispatchEvent( { type: 'dispose' } );
9567
+
9568
+ }
9569
+
9570
+ };
9571
+
9572
+ THREE.EventDispatcher.prototype.apply( THREE.Geometry.prototype );
9573
+
9574
+ THREE.GeometryIdCount = 0;
9575
+
9576
+ // File:src/cameras/Camera.js
9577
+
9578
+ /**
9579
+ * @author mrdoob / http://mrdoob.com/
9580
+ * @author mikael emtinger / http://gomo.se/
9581
+ * @author WestLangley / http://github.com/WestLangley
9582
+ */
9583
+
9584
+ THREE.Camera = function () {
9585
+
9586
+ THREE.Object3D.call( this );
9587
+
9588
+ this.type = 'Camera';
9589
+
9590
+ this.matrixWorldInverse = new THREE.Matrix4();
9591
+ this.projectionMatrix = new THREE.Matrix4();
9592
+
9593
+ };
9594
+
9595
+ THREE.Camera.prototype = Object.create( THREE.Object3D.prototype );
9596
+
9597
+ THREE.Camera.prototype.getWorldDirection = function () {
9598
+
9599
+ var quaternion = new THREE.Quaternion();
9600
+
9601
+ return function ( optionalTarget ) {
9602
+
9603
+ var result = optionalTarget || new THREE.Vector3();
9604
+
9605
+ this.getWorldQuaternion( quaternion );
9606
+
9607
+ return result.set( 0, 0, - 1 ).applyQuaternion( quaternion );
9608
+
9609
+ }
9610
+
9611
+ }();
9612
+
9613
+ THREE.Camera.prototype.lookAt = function () {
9614
+
9615
+ // This routine does not support cameras with rotated and/or translated parent(s)
9616
+
9617
+ var m1 = new THREE.Matrix4();
9618
+
9619
+ return function ( vector ) {
9620
+
9621
+ m1.lookAt( this.position, vector, this.up );
9622
+
9623
+ this.quaternion.setFromRotationMatrix( m1 );
9624
+
9625
+ };
9626
+
9627
+ }();
9628
+
9629
+ THREE.Camera.prototype.clone = function ( camera ) {
9630
+
9631
+ if ( camera === undefined ) camera = new THREE.Camera();
9632
+
9633
+ THREE.Object3D.prototype.clone.call( this, camera );
9634
+
9635
+ camera.matrixWorldInverse.copy( this.matrixWorldInverse );
9636
+ camera.projectionMatrix.copy( this.projectionMatrix );
9637
+
9638
+ return camera;
9639
+ };
9640
+
9641
+ THREE.PerspectiveCamera = function ( fov, aspect, near, far ) {
9642
+
9643
+ THREE.Camera.call( this );
9644
+
9645
+ this.type = 'PerspectiveCamera';
9646
+
9647
+ this.zoom = 1;
9648
+
9649
+ this.fov = fov !== undefined ? fov : 50;
9650
+ this.aspect = aspect !== undefined ? aspect : 1;
9651
+ this.near = near !== undefined ? near : 0.1;
9652
+ this.far = far !== undefined ? far : 2000;
9653
+
9654
+ this.updateProjectionMatrix();
9655
+
9656
+ };
9657
+
9658
+ THREE.PerspectiveCamera.prototype = Object.create( THREE.Camera.prototype );
9659
+
9660
+
9661
+ /**
9662
+ * Uses Focal Length (in mm) to estimate and set FOV
9663
+ * 35mm (fullframe) camera is used if frame size is not specified;
9664
+ * Formula based on http://www.bobatkins.com/photography/technical/field_of_view.html
9665
+ */
9666
+
9667
+ THREE.PerspectiveCamera.prototype.setLens = function ( focalLength, frameHeight ) {
9668
+
9669
+ if ( frameHeight === undefined ) frameHeight = 24;
9670
+
9671
+ this.fov = 2 * THREE.Math.radToDeg( Math.atan( frameHeight / ( focalLength * 2 ) ) );
9672
+ this.updateProjectionMatrix();
9673
+
9674
+ }
9675
+
9676
+
9677
+ /**
9678
+ * Sets an offset in a larger frustum. This is useful for multi-window or
9679
+ * multi-monitor/multi-machine setups.
9680
+ *
9681
+ * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
9682
+ * the monitors are in grid like this
9683
+ *
9684
+ * +---+---+---+
9685
+ * | A | B | C |
9686
+ * +---+---+---+
9687
+ * | D | E | F |
9688
+ * +---+---+---+
9689
+ *
9690
+ * then for each monitor you would call it like this
9691
+ *
9692
+ * var w = 1920;
9693
+ * var h = 1080;
9694
+ * var fullWidth = w * 3;
9695
+ * var fullHeight = h * 2;
9696
+ *
9697
+ * --A--
9698
+ * camera.setOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
9699
+ * --B--
9700
+ * camera.setOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
9701
+ * --C--
9702
+ * camera.setOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
9703
+ * --D--
9704
+ * camera.setOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
9705
+ * --E--
9706
+ * camera.setOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
9707
+ * --F--
9708
+ * camera.setOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
9709
+ *
9710
+ * Note there is no reason monitors have to be the same size or in a grid.
9711
+ */
9712
+
9713
+ THREE.PerspectiveCamera.prototype.setViewOffset = function ( fullWidth, fullHeight, x, y, width, height ) {
9714
+
9715
+ this.fullWidth = fullWidth;
9716
+ this.fullHeight = fullHeight;
9717
+ this.x = x;
9718
+ this.y = y;
9719
+ this.width = width;
9720
+ this.height = height;
9721
+
9722
+ this.updateProjectionMatrix();
9723
+
9724
+ };
9725
+
9726
+
9727
+ THREE.PerspectiveCamera.prototype.updateProjectionMatrix = function () {
9728
+
9729
+ var fov = THREE.Math.radToDeg( 2 * Math.atan( Math.tan( THREE.Math.degToRad( this.fov ) * 0.5 ) / this.zoom ) );
9730
+
9731
+ if ( this.fullWidth ) {
9732
+
9733
+ var aspect = this.fullWidth / this.fullHeight;
9734
+ var top = Math.tan( THREE.Math.degToRad( fov * 0.5 ) ) * this.near;
9735
+ var bottom = - top;
9736
+ var left = aspect * bottom;
9737
+ var right = aspect * top;
9738
+ var width = Math.abs( right - left );
9739
+ var height = Math.abs( top - bottom );
9740
+
9741
+ this.projectionMatrix.makeFrustum(
9742
+ left + this.x * width / this.fullWidth,
9743
+ left + ( this.x + this.width ) * width / this.fullWidth,
9744
+ top - ( this.y + this.height ) * height / this.fullHeight,
9745
+ top - this.y * height / this.fullHeight,
9746
+ this.near,
9747
+ this.far
9748
+ );
9749
+
9750
+ } else {
9751
+
9752
+ this.projectionMatrix.makePerspective( fov, this.aspect, this.near, this.far );
9753
+
9754
+ }
9755
+
9756
+ };
9757
+
9758
+ THREE.PerspectiveCamera.prototype.clone = function () {
9759
+
9760
+ var camera = new THREE.PerspectiveCamera();
9761
+
9762
+ THREE.Camera.prototype.clone.call( this, camera );
9763
+
9764
+ camera.zoom = this.zoom;
9765
+
9766
+ camera.fov = this.fov;
9767
+ camera.aspect = this.aspect;
9768
+ camera.near = this.near;
9769
+ camera.far = this.far;
9770
+
9771
+ camera.projectionMatrix.copy( this.projectionMatrix );
9772
+
9773
+ return camera;
9774
+
9775
+ };
9776
+
9777
+ // File:src/lights/Light.js
9778
+
9779
+ /**
9780
+ * @author mrdoob / http://mrdoob.com/
9781
+ * @author alteredq / http://alteredqualia.com/
9782
+ */
9783
+
9784
+ THREE.Light = function ( color ) {
9785
+
9786
+ THREE.Object3D.call( this );
9787
+
9788
+ this.type = 'Light';
9789
+
9790
+ this.color = new THREE.Color( color );
9791
+
9792
+ };
9793
+
9794
+ THREE.Light.prototype = Object.create( THREE.Object3D.prototype );
9795
+
9796
+ THREE.Light.prototype.clone = function ( light ) {
9797
+
9798
+ if ( light === undefined ) light = new THREE.Light();
9799
+
9800
+ THREE.Object3D.prototype.clone.call( this, light );
9801
+
9802
+ light.color.copy( this.color );
9803
+
9804
+ return light;
9805
+
9806
+ };
9807
+
9808
+ // File:src/lights/AmbientLight.js
9809
+
9810
+ /**
9811
+ * @author mrdoob / http://mrdoob.com/
9812
+ */
9813
+ /*
9814
+ THREE.AmbientLight = function ( color ) {
9815
+
9816
+ THREE.Light.call( this, color );
9817
+
9818
+ this.type = 'AmbientLight';
9819
+
9820
+ };
9821
+
9822
+ THREE.AmbientLight.prototype = Object.create( THREE.Light.prototype );
9823
+
9824
+ THREE.AmbientLight.prototype.clone = function () {
9825
+
9826
+ var light = new THREE.AmbientLight();
9827
+
9828
+ THREE.Light.prototype.clone.call( this, light );
9829
+
9830
+ return light;
9831
+
9832
+ };
9833
+
9834
+ // File:src/lights/AreaLight.js
9835
+
9836
+ /**
9837
+ * @author MPanknin / http://www.redplant.de/
9838
+ * @author alteredq / http://alteredqualia.com/
9839
+ */
9840
+ /*
9841
+ THREE.AreaLight = function ( color, intensity ) {
9842
+
9843
+ THREE.Light.call( this, color );
9844
+
9845
+ this.type = 'AreaLight';
9846
+
9847
+ this.normal = new THREE.Vector3( 0, - 1, 0 );
9848
+ this.right = new THREE.Vector3( 1, 0, 0 );
9849
+
9850
+ this.intensity = ( intensity !== undefined ) ? intensity : 1;
9851
+
9852
+ this.width = 1.0;
9853
+ this.height = 1.0;
9854
+
9855
+ this.constantAttenuation = 1.5;
9856
+ this.linearAttenuation = 0.5;
9857
+ this.quadraticAttenuation = 0.1;
9858
+
9859
+ };
9860
+
9861
+ THREE.AreaLight.prototype = Object.create( THREE.Light.prototype );
9862
+
9863
+
9864
+ // File:src/lights/DirectionalLight.js
9865
+
9866
+ /**
9867
+ * @author mrdoob / http://mrdoob.com/
9868
+ * @author alteredq / http://alteredqualia.com/
9869
+ */
9870
+ /*
9871
+ THREE.DirectionalLight = function ( color, intensity ) {
9872
+
9873
+ THREE.Light.call( this, color );
9874
+
9875
+ this.type = 'DirectionalLight';
9876
+
9877
+ this.position.set( 0, 1, 0 );
9878
+ this.target = new THREE.Object3D();
9879
+
9880
+ this.intensity = ( intensity !== undefined ) ? intensity : 1;
9881
+
9882
+ this.castShadow = false;
9883
+ this.onlyShadow = false;
9884
+
9885
+ //
9886
+
9887
+ this.shadowCameraNear = 50;
9888
+ this.shadowCameraFar = 5000;
9889
+
9890
+ this.shadowCameraLeft = - 500;
9891
+ this.shadowCameraRight = 500;
9892
+ this.shadowCameraTop = 500;
9893
+ this.shadowCameraBottom = - 500;
9894
+
9895
+ this.shadowCameraVisible = false;
9896
+
9897
+ this.shadowBias = 0;
9898
+ this.shadowDarkness = 0.5;
9899
+
9900
+ this.shadowMapWidth = 512;
9901
+ this.shadowMapHeight = 512;
9902
+
9903
+ //
9904
+
9905
+ this.shadowCascade = false;
9906
+
9907
+ this.shadowCascadeOffset = new THREE.Vector3( 0, 0, - 1000 );
9908
+ this.shadowCascadeCount = 2;
9909
+
9910
+ this.shadowCascadeBias = [ 0, 0, 0 ];
9911
+ this.shadowCascadeWidth = [ 512, 512, 512 ];
9912
+ this.shadowCascadeHeight = [ 512, 512, 512 ];
9913
+
9914
+ this.shadowCascadeNearZ = [ - 1.000, 0.990, 0.998 ];
9915
+ this.shadowCascadeFarZ = [ 0.990, 0.998, 1.000 ];
9916
+
9917
+ this.shadowCascadeArray = [];
9918
+
9919
+ //
9920
+
9921
+ this.shadowMap = null;
9922
+ this.shadowMapSize = null;
9923
+ this.shadowCamera = null;
9924
+ this.shadowMatrix = null;
9925
+
9926
+ };
9927
+
9928
+ THREE.DirectionalLight.prototype = Object.create( THREE.Light.prototype );
9929
+
9930
+ THREE.DirectionalLight.prototype.clone = function () {
9931
+
9932
+ var light = new THREE.DirectionalLight();
9933
+
9934
+ THREE.Light.prototype.clone.call( this, light );
9935
+
9936
+ light.target = this.target.clone();
9937
+
9938
+ light.intensity = this.intensity;
9939
+
9940
+ light.castShadow = this.castShadow;
9941
+ light.onlyShadow = this.onlyShadow;
9942
+
9943
+ //
9944
+
9945
+ light.shadowCameraNear = this.shadowCameraNear;
9946
+ light.shadowCameraFar = this.shadowCameraFar;
9947
+
9948
+ light.shadowCameraLeft = this.shadowCameraLeft;
9949
+ light.shadowCameraRight = this.shadowCameraRight;
9950
+ light.shadowCameraTop = this.shadowCameraTop;
9951
+ light.shadowCameraBottom = this.shadowCameraBottom;
9952
+
9953
+ light.shadowCameraVisible = this.shadowCameraVisible;
9954
+
9955
+ light.shadowBias = this.shadowBias;
9956
+ light.shadowDarkness = this.shadowDarkness;
9957
+
9958
+ light.shadowMapWidth = this.shadowMapWidth;
9959
+ light.shadowMapHeight = this.shadowMapHeight;
9960
+
9961
+ //
9962
+
9963
+ light.shadowCascade = this.shadowCascade;
9964
+
9965
+ light.shadowCascadeOffset.copy( this.shadowCascadeOffset );
9966
+ light.shadowCascadeCount = this.shadowCascadeCount;
9967
+
9968
+ light.shadowCascadeBias = this.shadowCascadeBias.slice( 0 );
9969
+ light.shadowCascadeWidth = this.shadowCascadeWidth.slice( 0 );
9970
+ light.shadowCascadeHeight = this.shadowCascadeHeight.slice( 0 );
9971
+
9972
+ light.shadowCascadeNearZ = this.shadowCascadeNearZ.slice( 0 );
9973
+ light.shadowCascadeFarZ = this.shadowCascadeFarZ.slice( 0 );
9974
+
9975
+ return light;
9976
+
9977
+ };
9978
+
9979
+ // File:src/lights/HemisphereLight.js
9980
+
9981
+ /**
9982
+ * @author alteredq / http://alteredqualia.com/
9983
+ */
9984
+ /*
9985
+ THREE.HemisphereLight = function ( skyColor, groundColor, intensity ) {
9986
+
9987
+ THREE.Light.call( this, skyColor );
9988
+
9989
+ this.type = 'HemisphereLight';
9990
+
9991
+ this.position.set( 0, 100, 0 );
9992
+
9993
+ this.groundColor = new THREE.Color( groundColor );
9994
+ this.intensity = ( intensity !== undefined ) ? intensity : 1;
9995
+
9996
+ };
9997
+
9998
+ THREE.HemisphereLight.prototype = Object.create( THREE.Light.prototype );
9999
+
10000
+ THREE.HemisphereLight.prototype.clone = function () {
10001
+
10002
+ var light = new THREE.HemisphereLight();
10003
+
10004
+ THREE.Light.prototype.clone.call( this, light );
10005
+
10006
+ light.groundColor.copy( this.groundColor );
10007
+ light.intensity = this.intensity;
10008
+
10009
+ return light;
10010
+
10011
+ };
10012
+
10013
+ // File:src/lights/PointLight.js
10014
+
10015
+ /**
10016
+ * @author mrdoob / http://mrdoob.com/
10017
+ */
10018
+ /*
10019
+ THREE.PointLight = function ( color, intensity, distance ) {
10020
+
10021
+ THREE.Light.call( this, color );
10022
+
10023
+ this.type = 'PointLight';
10024
+
10025
+ this.intensity = ( intensity !== undefined ) ? intensity : 1;
10026
+ this.distance = ( distance !== undefined ) ? distance : 0;
10027
+
10028
+ };
10029
+
10030
+ THREE.PointLight.prototype = Object.create( THREE.Light.prototype );
10031
+
10032
+ THREE.PointLight.prototype.clone = function () {
10033
+
10034
+ var light = new THREE.PointLight();
10035
+
10036
+ THREE.Light.prototype.clone.call( this, light );
10037
+
10038
+ light.intensity = this.intensity;
10039
+ light.distance = this.distance;
10040
+
10041
+ return light;
10042
+
10043
+ };
10044
+
10045
+ // File:src/lights/SpotLight.js
10046
+
10047
+ /**
10048
+ * @author alteredq / http://alteredqualia.com/
10049
+ */
10050
+ /*
10051
+ THREE.SpotLight = function ( color, intensity, distance, angle, exponent ) {
10052
+
10053
+ THREE.Light.call( this, color );
10054
+
10055
+ this.type = 'SpotLight';
10056
+
10057
+ this.position.set( 0, 1, 0 );
10058
+ this.target = new THREE.Object3D();
10059
+
10060
+ this.intensity = ( intensity !== undefined ) ? intensity : 1;
10061
+ this.distance = ( distance !== undefined ) ? distance : 0;
10062
+ this.angle = ( angle !== undefined ) ? angle : Math.PI / 3;
10063
+ this.exponent = ( exponent !== undefined ) ? exponent : 10;
10064
+
10065
+ this.castShadow = false;
10066
+ this.onlyShadow = false;
10067
+
10068
+ //
10069
+
10070
+ this.shadowCameraNear = 50;
10071
+ this.shadowCameraFar = 5000;
10072
+ this.shadowCameraFov = 50;
10073
+
10074
+ this.shadowCameraVisible = false;
10075
+
10076
+ this.shadowBias = 0;
10077
+ this.shadowDarkness = 0.5;
10078
+
10079
+ this.shadowMapWidth = 512;
10080
+ this.shadowMapHeight = 512;
10081
+
10082
+ //
10083
+
10084
+ this.shadowMap = null;
10085
+ this.shadowMapSize = null;
10086
+ this.shadowCamera = null;
10087
+ this.shadowMatrix = null;
10088
+
10089
+ };
10090
+
10091
+ THREE.SpotLight.prototype = Object.create( THREE.Light.prototype );
10092
+
10093
+ THREE.SpotLight.prototype.clone = function () {
10094
+
10095
+ var light = new THREE.SpotLight();
10096
+
10097
+ THREE.Light.prototype.clone.call( this, light );
10098
+
10099
+ light.target = this.target.clone();
10100
+
10101
+ light.intensity = this.intensity;
10102
+ light.distance = this.distance;
10103
+ light.angle = this.angle;
10104
+ light.exponent = this.exponent;
10105
+
10106
+ light.castShadow = this.castShadow;
10107
+ light.onlyShadow = this.onlyShadow;
10108
+
10109
+ //
10110
+
10111
+ light.shadowCameraNear = this.shadowCameraNear;
10112
+ light.shadowCameraFar = this.shadowCameraFar;
10113
+ light.shadowCameraFov = this.shadowCameraFov;
10114
+
10115
+ light.shadowCameraVisible = this.shadowCameraVisible;
10116
+
10117
+ light.shadowBias = this.shadowBias;
10118
+ light.shadowDarkness = this.shadowDarkness;
10119
+
10120
+ light.shadowMapWidth = this.shadowMapWidth;
10121
+ light.shadowMapHeight = this.shadowMapHeight;
10122
+
10123
+ return light;
10124
+
10125
+ };
10126
+
10127
+ // File:src/loaders/Cache.js
10128
+
10129
+ /**
10130
+ * @author mrdoob / http://mrdoob.com/
10131
+ */
10132
+
10133
+ THREE.Cache = function () {
10134
+
10135
+ this.files = {};
10136
+
10137
+ };
10138
+
10139
+ THREE.Cache.prototype = {
10140
+
10141
+ constructor: THREE.Cache,
10142
+
10143
+ add: function ( key, file ) {
10144
+
10145
+ // console.log( 'THREE.Cache', 'Adding key:', key );
10146
+
10147
+ this.files[ key ] = file;
10148
+
10149
+ },
10150
+
10151
+ get: function ( key ) {
10152
+
10153
+ // console.log( 'THREE.Cache', 'Checking key:', key );
10154
+
10155
+ return this.files[ key ];
10156
+
10157
+ },
10158
+
10159
+ remove: function ( key ) {
10160
+
10161
+ delete this.files[ key ];
10162
+
10163
+ },
10164
+
10165
+ clear: function () {
10166
+
10167
+ this.files = {}
10168
+
10169
+ }
10170
+
10171
+ };
10172
+
10173
+ // File:src/loaders/Loader.js
10174
+
10175
+ /**
10176
+ * @author alteredq / http://alteredqualia.com/
10177
+ */
10178
+
10179
+ THREE.Loader = function ( showStatus ) {
10180
+
10181
+ this.showStatus = showStatus;
10182
+ this.statusDomElement = showStatus ? THREE.Loader.prototype.addStatusElement() : null;
10183
+
10184
+ this.imageLoader = new THREE.ImageLoader();
10185
+
10186
+ this.onLoadStart = function () {};
10187
+ this.onLoadProgress = function () {};
10188
+ this.onLoadComplete = function () {};
10189
+
10190
+ };
10191
+
10192
+ THREE.Loader.prototype = {
10193
+
10194
+ constructor: THREE.Loader,
10195
+
10196
+ crossOrigin: undefined,
10197
+
10198
+ addStatusElement: function () {
10199
+
10200
+ var e = document.createElement( 'div' );
10201
+
10202
+ e.style.position = 'absolute';
10203
+ e.style.right = '0px';
10204
+ e.style.top = '0px';
10205
+ e.style.fontSize = '0.8em';
10206
+ e.style.textAlign = 'left';
10207
+ e.style.background = 'rgba(0,0,0,0.25)';
10208
+ e.style.color = '#fff';
10209
+ e.style.width = '120px';
10210
+ e.style.padding = '0.5em 0.5em 0.5em 0.5em';
10211
+ e.style.zIndex = 1000;
10212
+
10213
+ e.innerHTML = 'Loading ...';
10214
+
10215
+ return e;
10216
+
10217
+ },
10218
+
10219
+ updateProgress: function ( progress ) {
10220
+
10221
+ var message = 'Loaded ';
10222
+
10223
+ if ( progress.total ) {
10224
+
10225
+ message += ( 100 * progress.loaded / progress.total ).toFixed( 0 ) + '%';
10226
+
10227
+
10228
+ } else {
10229
+
10230
+ message += ( progress.loaded / 1024 ).toFixed( 2 ) + ' KB';
10231
+
10232
+ }
10233
+
10234
+ this.statusDomElement.innerHTML = message;
10235
+
10236
+ },
10237
+
10238
+ extractUrlBase: function ( url ) {
10239
+
10240
+ var parts = url.split( '/' );
10241
+
10242
+ if ( parts.length === 1 ) return './';
10243
+
10244
+ parts.pop();
10245
+
10246
+ return parts.join( '/' ) + '/';
10247
+
10248
+ },
10249
+
10250
+ initMaterials: function ( materials, texturePath ) {
10251
+
10252
+ var array = [];
10253
+
10254
+ for ( var i = 0; i < materials.length; ++ i ) {
10255
+
10256
+ array[ i ] = this.createMaterial( materials[ i ], texturePath );
10257
+
10258
+ }
10259
+
10260
+ return array;
10261
+
10262
+ },
10263
+
10264
+ needsTangents: function ( materials ) {
10265
+
10266
+ for ( var i = 0, il = materials.length; i < il; i ++ ) {
10267
+
10268
+ var m = materials[ i ];
10269
+
10270
+ if ( m instanceof THREE.ShaderMaterial ) return true;
10271
+
10272
+ }
10273
+
10274
+ return false;
10275
+
10276
+ },
10277
+
10278
+ createMaterial: function ( m, texturePath ) {
10279
+
10280
+ var scope = this;
10281
+
10282
+ function nearest_pow2( n ) {
10283
+
10284
+ var l = Math.log( n ) / Math.LN2;
10285
+ return Math.pow( 2, Math.round( l ) );
10286
+
10287
+ }
10288
+
10289
+ function create_texture( where, name, sourceFile, repeat, offset, wrap, anisotropy ) {
10290
+
10291
+ var fullPath = texturePath + sourceFile;
10292
+
10293
+ var texture;
10294
+
10295
+ var loader = THREE.Loader.Handlers.get( fullPath );
10296
+
10297
+ if ( loader !== null ) {
10298
+
10299
+ texture = loader.load( fullPath );
10300
+
10301
+ } else {
10302
+
10303
+ texture = new THREE.Texture();
10304
+
10305
+ loader = scope.imageLoader;
10306
+ loader.crossOrigin = scope.crossOrigin;
10307
+ loader.load( fullPath, function ( image ) {
10308
+
10309
+ if ( THREE.Math.isPowerOfTwo( image.width ) === false ||
10310
+ THREE.Math.isPowerOfTwo( image.height ) === false ) {
10311
+
10312
+ var width = nearest_pow2( image.width );
10313
+ var height = nearest_pow2( image.height );
10314
+
10315
+ var canvas = document.createElement( 'canvas' );
10316
+ canvas.width = width;
10317
+ canvas.height = height;
10318
+
10319
+ var context = canvas.getContext( '2d' );
10320
+ context.drawImage( image, 0, 0, width, height );
10321
+
10322
+ texture.image = canvas;
10323
+
10324
+ } else {
10325
+
10326
+ texture.image = image;
10327
+
10328
+ }
10329
+
10330
+ texture.needsUpdate = true;
10331
+
10332
+ } );
10333
+
10334
+ }
10335
+
10336
+ texture.sourceFile = sourceFile;
10337
+
10338
+ if ( repeat ) {
10339
+
10340
+ texture.repeat.set( repeat[ 0 ], repeat[ 1 ] );
10341
+
10342
+ if ( repeat[ 0 ] !== 1 ) texture.wrapS = THREE.RepeatWrapping;
10343
+ if ( repeat[ 1 ] !== 1 ) texture.wrapT = THREE.RepeatWrapping;
10344
+
10345
+ }
10346
+
10347
+ if ( offset ) {
10348
+
10349
+ texture.offset.set( offset[ 0 ], offset[ 1 ] );
10350
+
10351
+ }
10352
+
10353
+ if ( wrap ) {
10354
+
10355
+ var wrapMap = {
10356
+ 'repeat': THREE.RepeatWrapping,
10357
+ 'mirror': THREE.MirroredRepeatWrapping
10358
+ }
10359
+
10360
+ if ( wrapMap[ wrap[ 0 ] ] !== undefined ) texture.wrapS = wrapMap[ wrap[ 0 ] ];
10361
+ if ( wrapMap[ wrap[ 1 ] ] !== undefined ) texture.wrapT = wrapMap[ wrap[ 1 ] ];
10362
+
10363
+ }
10364
+
10365
+ if ( anisotropy ) {
10366
+
10367
+ texture.anisotropy = anisotropy;
10368
+
10369
+ }
10370
+
10371
+ where[ name ] = texture;
10372
+
10373
+ }
10374
+
10375
+ function rgb2hex( rgb ) {
10376
+
10377
+ return ( rgb[ 0 ] * 255 << 16 ) + ( rgb[ 1 ] * 255 << 8 ) + rgb[ 2 ] * 255;
10378
+
10379
+ }
10380
+
10381
+ // defaults
10382
+
10383
+ var mtype = 'MeshLambertMaterial';
10384
+ var mpars = { color: 0xeeeeee, opacity: 1.0, map: null, lightMap: null, normalMap: null, bumpMap: null, wireframe: false };
10385
+
10386
+ // parameters from model file
10387
+
10388
+ if ( m.shading ) {
10389
+
10390
+ var shading = m.shading.toLowerCase();
10391
+
10392
+ if ( shading === 'phong' ) mtype = 'MeshPhongMaterial';
10393
+ else if ( shading === 'basic' ) mtype = 'MeshBasicMaterial';
10394
+
10395
+ }
10396
+
10397
+ if ( m.blending !== undefined && THREE[ m.blending ] !== undefined ) {
10398
+
10399
+ mpars.blending = THREE[ m.blending ];
10400
+
10401
+ }
10402
+
10403
+ if ( m.transparent !== undefined || m.opacity < 1.0 ) {
10404
+
10405
+ mpars.transparent = m.transparent;
10406
+
10407
+ }
10408
+
10409
+ if ( m.depthTest !== undefined ) {
10410
+
10411
+ mpars.depthTest = m.depthTest;
10412
+
10413
+ }
10414
+
10415
+ if ( m.depthWrite !== undefined ) {
10416
+
10417
+ mpars.depthWrite = m.depthWrite;
10418
+
10419
+ }
10420
+
10421
+ if ( m.visible !== undefined ) {
10422
+
10423
+ mpars.visible = m.visible;
10424
+
10425
+ }
10426
+
10427
+ if ( m.flipSided !== undefined ) {
10428
+
10429
+ mpars.side = THREE.BackSide;
10430
+
10431
+ }
10432
+
10433
+ if ( m.doubleSided !== undefined ) {
10434
+
10435
+ mpars.side = THREE.DoubleSide;
10436
+
10437
+ }
10438
+
10439
+ if ( m.wireframe !== undefined ) {
10440
+
10441
+ mpars.wireframe = m.wireframe;
10442
+
10443
+ }
10444
+
10445
+ if ( m.vertexColors !== undefined ) {
10446
+
10447
+ if ( m.vertexColors === 'face' ) {
10448
+
10449
+ mpars.vertexColors = THREE.FaceColors;
10450
+
10451
+ } else if ( m.vertexColors ) {
10452
+
10453
+ mpars.vertexColors = THREE.VertexColors;
10454
+
10455
+ }
10456
+
10457
+ }
10458
+
10459
+ // colors
10460
+
10461
+ if ( m.colorDiffuse ) {
10462
+
10463
+ mpars.color = rgb2hex( m.colorDiffuse );
10464
+
10465
+ } else if ( m.DbgColor ) {
10466
+
10467
+ mpars.color = m.DbgColor;
10468
+
10469
+ }
10470
+
10471
+ if ( m.colorSpecular ) {
10472
+
10473
+ mpars.specular = rgb2hex( m.colorSpecular );
10474
+
10475
+ }
10476
+
10477
+ if ( m.colorAmbient ) {
10478
+
10479
+ mpars.ambient = rgb2hex( m.colorAmbient );
10480
+
10481
+ }
10482
+
10483
+ if ( m.colorEmissive ) {
10484
+
10485
+ mpars.emissive = rgb2hex( m.colorEmissive );
10486
+
10487
+ }
10488
+
10489
+ // modifiers
10490
+
10491
+ if ( m.transparency ) {
10492
+
10493
+ mpars.opacity = m.transparency;
10494
+
10495
+ }
10496
+
10497
+ if ( m.specularCoef ) {
10498
+
10499
+ mpars.shininess = m.specularCoef;
10500
+
10501
+ }
10502
+
10503
+ // textures
10504
+
10505
+ if ( m.mapDiffuse && texturePath ) {
10506
+
10507
+ create_texture( mpars, 'map', m.mapDiffuse, m.mapDiffuseRepeat, m.mapDiffuseOffset, m.mapDiffuseWrap, m.mapDiffuseAnisotropy );
10508
+
10509
+ }
10510
+
10511
+ if ( m.mapLight && texturePath ) {
10512
+
10513
+ create_texture( mpars, 'lightMap', m.mapLight, m.mapLightRepeat, m.mapLightOffset, m.mapLightWrap, m.mapLightAnisotropy );
10514
+
10515
+ }
10516
+
10517
+ if ( m.mapBump && texturePath ) {
10518
+
10519
+ create_texture( mpars, 'bumpMap', m.mapBump, m.mapBumpRepeat, m.mapBumpOffset, m.mapBumpWrap, m.mapBumpAnisotropy );
10520
+
10521
+ }
10522
+
10523
+ if ( m.mapNormal && texturePath ) {
10524
+
10525
+ create_texture( mpars, 'normalMap', m.mapNormal, m.mapNormalRepeat, m.mapNormalOffset, m.mapNormalWrap, m.mapNormalAnisotropy );
10526
+
10527
+ }
10528
+
10529
+ if ( m.mapSpecular && texturePath ) {
10530
+
10531
+ create_texture( mpars, 'specularMap', m.mapSpecular, m.mapSpecularRepeat, m.mapSpecularOffset, m.mapSpecularWrap, m.mapSpecularAnisotropy );
10532
+
10533
+ }
10534
+
10535
+ if ( m.mapAlpha && texturePath ) {
10536
+
10537
+ create_texture( mpars, 'alphaMap', m.mapAlpha, m.mapAlphaRepeat, m.mapAlphaOffset, m.mapAlphaWrap, m.mapAlphaAnisotropy );
10538
+
10539
+ }
10540
+
10541
+ //
10542
+
10543
+ if ( m.mapBumpScale ) {
10544
+
10545
+ mpars.bumpScale = m.mapBumpScale;
10546
+
10547
+ }
10548
+
10549
+ // special case for normal mapped material
10550
+
10551
+ if ( m.mapNormal ) {
10552
+
10553
+ var shader = THREE.ShaderLib[ 'normalmap' ];
10554
+ var uniforms = THREE.UniformsUtils.clone( shader.uniforms );
10555
+
10556
+ uniforms[ 'tNormal' ].value = mpars.normalMap;
10557
+
10558
+ if ( m.mapNormalFactor ) {
10559
+
10560
+ uniforms[ 'uNormalScale' ].value.set( m.mapNormalFactor, m.mapNormalFactor );
10561
+
10562
+ }
10563
+
10564
+ if ( mpars.map ) {
10565
+
10566
+ uniforms[ 'tDiffuse' ].value = mpars.map;
10567
+ uniforms[ 'enableDiffuse' ].value = true;
10568
+
10569
+ }
10570
+
10571
+ if ( mpars.specularMap ) {
10572
+
10573
+ uniforms[ 'tSpecular' ].value = mpars.specularMap;
10574
+ uniforms[ 'enableSpecular' ].value = true;
10575
+
10576
+ }
10577
+
10578
+ if ( mpars.lightMap ) {
10579
+
10580
+ uniforms[ 'tAO' ].value = mpars.lightMap;
10581
+ uniforms[ 'enableAO' ].value = true;
10582
+
10583
+ }
10584
+
10585
+ // for the moment don't handle displacement texture
10586
+
10587
+ uniforms[ 'diffuse' ].value.setHex( mpars.color );
10588
+ uniforms[ 'specular' ].value.setHex( mpars.specular );
10589
+ uniforms[ 'ambient' ].value.setHex( mpars.ambient );
10590
+
10591
+ uniforms[ 'shininess' ].value = mpars.shininess;
10592
+
10593
+ if ( mpars.opacity !== undefined ) {
10594
+
10595
+ uniforms[ 'opacity' ].value = mpars.opacity;
10596
+
10597
+ }
10598
+
10599
+ var parameters = { fragmentShader: shader.fragmentShader, vertexShader: shader.vertexShader, uniforms: uniforms, lights: true, fog: true };
10600
+ var material = new THREE.ShaderMaterial( parameters );
10601
+
10602
+ if ( mpars.transparent ) {
10603
+
10604
+ material.transparent = true;
10605
+
10606
+ }
10607
+
10608
+ } else {
10609
+
10610
+ var material = new THREE[ mtype ]( mpars );
10611
+
10612
+ }
10613
+
10614
+ if ( m.DbgName !== undefined ) material.name = m.DbgName;
10615
+
10616
+ return material;
10617
+
10618
+ }
10619
+
10620
+ };
10621
+
10622
+ THREE.Loader.Handlers = {
10623
+
10624
+ handlers: [],
10625
+
10626
+ add: function ( regex, loader ) {
10627
+
10628
+ this.handlers.push( regex, loader );
10629
+
10630
+ },
10631
+
10632
+ get: function ( file ) {
10633
+
10634
+ for ( var i = 0, l = this.handlers.length; i < l; i += 2 ) {
10635
+
10636
+ var regex = this.handlers[ i ];
10637
+ var loader = this.handlers[ i + 1 ];
10638
+
10639
+ if ( regex.test( file ) ) {
10640
+
10641
+ return loader;
10642
+
10643
+ }
10644
+
10645
+ }
10646
+
10647
+ return null;
10648
+
10649
+ }
10650
+
10651
+ };
10652
+
10653
+ // File:src/loaders/XHRLoader.js
10654
+
10655
+ /**
10656
+ * @author mrdoob / http://mrdoob.com/
10657
+ */
10658
+
10659
+ THREE.XHRLoader = function ( manager ) {
10660
+
10661
+ this.cache = new THREE.Cache();
10662
+ this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
10663
+
10664
+ };
10665
+
10666
+ THREE.XHRLoader.prototype = {
10667
+
10668
+ constructor: THREE.XHRLoader,
10669
+
10670
+ load: function ( url, onLoad, onProgress, onError ) {
10671
+
10672
+ var scope = this;
10673
+
10674
+ var cached = scope.cache.get( url );
10675
+
10676
+ if ( cached !== undefined ) {
10677
+
10678
+ if ( onLoad ) onLoad( cached );
10679
+ return;
10680
+
10681
+ }
10682
+
10683
+ var request = new XMLHttpRequest();
10684
+ request.open( 'GET', url, true );
10685
+
10686
+ request.addEventListener( 'load', function ( event ) {
10687
+
10688
+ scope.cache.add( url, this.response );
10689
+
10690
+ if ( onLoad ) onLoad( this.response );
10691
+
10692
+ scope.manager.itemEnd( url );
10693
+
10694
+ }, false );
10695
+
10696
+ if ( onProgress !== undefined ) {
10697
+
10698
+ request.addEventListener( 'progress', function ( event ) {
10699
+
10700
+ onProgress( event );
10701
+
10702
+ }, false );
10703
+
10704
+ }
10705
+
10706
+ if ( onError !== undefined ) {
10707
+
10708
+ request.addEventListener( 'error', function ( event ) {
10709
+
10710
+ onError( event );
10711
+
10712
+ }, false );
10713
+
10714
+ }
10715
+
10716
+ if ( this.crossOrigin !== undefined ) request.crossOrigin = this.crossOrigin;
10717
+ if ( this.responseType !== undefined ) request.responseType = this.responseType;
10718
+
10719
+ request.send( null );
10720
+
10721
+ scope.manager.itemStart( url );
10722
+
10723
+ },
10724
+
10725
+ setResponseType: function ( value ) {
10726
+
10727
+ this.responseType = value;
10728
+
10729
+ },
10730
+
10731
+ setCrossOrigin: function ( value ) {
10732
+
10733
+ this.crossOrigin = value;
10734
+
10735
+ }
10736
+
10737
+ };
10738
+
10739
+ // File:src/loaders/ImageLoader.js
10740
+
10741
+ /**
10742
+ * @author mrdoob / http://mrdoob.com/
10743
+ */
10744
+
10745
+ THREE.ImageLoader = function ( manager ) {
10746
+
10747
+ this.cache = new THREE.Cache();
10748
+ this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
10749
+
10750
+ };
10751
+
10752
+ THREE.ImageLoader.prototype = {
10753
+
10754
+ constructor: THREE.ImageLoader,
10755
+
10756
+ load: function ( url, onLoad, onProgress, onError ) {
10757
+
10758
+ var scope = this;
10759
+
10760
+ var cached = scope.cache.get( url );
10761
+
10762
+ if ( cached !== undefined ) {
10763
+
10764
+ onLoad( cached );
10765
+ return;
10766
+
10767
+ }
10768
+
10769
+ var image = document.createElement( 'img' );
10770
+
10771
+ if ( onLoad !== undefined ) {
10772
+
10773
+ image.addEventListener( 'load', function ( event ) {
10774
+
10775
+ scope.cache.add( url, this );
10776
+
10777
+ onLoad( this );
10778
+ scope.manager.itemEnd( url );
10779
+
10780
+ }, false );
10781
+
10782
+ }
10783
+
10784
+ if ( onProgress !== undefined ) {
10785
+
10786
+ image.addEventListener( 'progress', function ( event ) {
10787
+
10788
+ onProgress( event );
10789
+
10790
+ }, false );
10791
+
10792
+ }
10793
+
10794
+ if ( onError !== undefined ) {
10795
+
10796
+ image.addEventListener( 'error', function ( event ) {
10797
+
10798
+ onError( event );
10799
+
10800
+ }, false );
10801
+
10802
+ }
10803
+
10804
+ if ( this.crossOrigin !== undefined ) image.crossOrigin = this.crossOrigin;
10805
+
10806
+ image.src = url;
10807
+
10808
+ scope.manager.itemStart( url );
10809
+
10810
+ return image;
10811
+
10812
+ },
10813
+
10814
+ setCrossOrigin: function ( value ) {
10815
+
10816
+ this.crossOrigin = value;
10817
+
10818
+ }
10819
+
10820
+ }
10821
+
10822
+ // File:src/loaders/JSONLoader.js
10823
+
10824
+ /**
10825
+ * @author mrdoob / http://mrdoob.com/
10826
+ * @author alteredq / http://alteredqualia.com/
10827
+ */
10828
+ /*
10829
+ THREE.JSONLoader = function ( showStatus ) {
10830
+
10831
+ THREE.Loader.call( this, showStatus );
10832
+
10833
+ this.withCredentials = false;
10834
+
10835
+ };
10836
+
10837
+ THREE.JSONLoader.prototype = Object.create( THREE.Loader.prototype );
10838
+
10839
+ THREE.JSONLoader.prototype.load = function ( url, callback, texturePath ) {
10840
+
10841
+ var scope = this;
10842
+
10843
+ // todo: unify load API to for easier SceneLoader use
10844
+
10845
+ texturePath = texturePath && ( typeof texturePath === 'string' ) ? texturePath : this.extractUrlBase( url );
10846
+
10847
+ this.onLoadStart();
10848
+ this.loadAjaxJSON( this, url, callback, texturePath );
10849
+
10850
+ };
10851
+
10852
+ THREE.JSONLoader.prototype.loadAjaxJSON = function ( context, url, callback, texturePath, callbackProgress ) {
10853
+
10854
+ var xhr = new XMLHttpRequest();
10855
+
10856
+ var length = 0;
10857
+
10858
+ xhr.onreadystatechange = function () {
10859
+
10860
+ if ( xhr.readyState === xhr.DONE ) {
10861
+
10862
+ if ( xhr.status === 200 || xhr.status === 0 ) {
10863
+
10864
+ if ( xhr.responseText ) {
10865
+
10866
+ var json = JSON.parse( xhr.responseText );
10867
+
10868
+ if ( json.metadata !== undefined && json.metadata.type === 'scene' ) {
10869
+
10870
+ console.error( 'THREE.JSONLoader: "' + url + '" seems to be a Scene. Use THREE.SceneLoader instead.' );
10871
+ return;
10872
+
10873
+ }
10874
+
10875
+ var result = context.parse( json, texturePath );
10876
+ callback( result.geometry, result.materials );
10877
+
10878
+ } else {
10879
+
10880
+ console.error( 'THREE.JSONLoader: "' + url + '" seems to be unreachable or the file is empty.' );
10881
+
10882
+ }
10883
+
10884
+ // in context of more complex asset initialization
10885
+ // do not block on single failed file
10886
+ // maybe should go even one more level up
10887
+
10888
+ context.onLoadComplete();
10889
+
10890
+ } else {
10891
+
10892
+ console.error( 'THREE.JSONLoader: Couldn\'t load "' + url + '" (' + xhr.status + ')' );
10893
+
10894
+ }
10895
+
10896
+ } else if ( xhr.readyState === xhr.LOADING ) {
10897
+
10898
+ if ( callbackProgress ) {
10899
+
10900
+ if ( length === 0 ) {
10901
+
10902
+ length = xhr.getResponseHeader( 'Content-Length' );
10903
+
10904
+ }
10905
+
10906
+ callbackProgress( { total: length, loaded: xhr.responseText.length } );
10907
+
10908
+ }
10909
+
10910
+ } else if ( xhr.readyState === xhr.HEADERS_RECEIVED ) {
10911
+
10912
+ if ( callbackProgress !== undefined ) {
10913
+
10914
+ length = xhr.getResponseHeader( 'Content-Length' );
10915
+
10916
+ }
10917
+
10918
+ }
10919
+
10920
+ };
10921
+
10922
+ xhr.open( 'GET', url, true );
10923
+ xhr.withCredentials = this.withCredentials;
10924
+ xhr.send( null );
10925
+
10926
+ };
10927
+
10928
+ THREE.JSONLoader.prototype.parse = function ( json, texturePath ) {
10929
+
10930
+ var scope = this,
10931
+ geometry = new THREE.Geometry(),
10932
+ scale = ( json.scale !== undefined ) ? 1.0 / json.scale : 1.0;
10933
+
10934
+ parseModel( scale );
10935
+
10936
+ parseSkin();
10937
+ parseMorphing( scale );
10938
+
10939
+ geometry.computeFaceNormals();
10940
+ geometry.computeBoundingSphere();
10941
+
10942
+ function parseModel( scale ) {
10943
+
10944
+ function isBitSet( value, position ) {
10945
+
10946
+ return value & ( 1 << position );
10947
+
10948
+ }
10949
+
10950
+ var i, j, fi,
10951
+
10952
+ offset, zLength,
10953
+
10954
+ colorIndex, normalIndex, uvIndex, materialIndex,
10955
+
10956
+ type,
10957
+ isQuad,
10958
+ hasMaterial,
10959
+ hasFaceVertexUv,
10960
+ hasFaceNormal, hasFaceVertexNormal,
10961
+ hasFaceColor, hasFaceVertexColor,
10962
+
10963
+ vertex, face, faceA, faceB, color, hex, normal,
10964
+
10965
+ uvLayer, uv, u, v,
10966
+
10967
+ faces = json.faces,
10968
+ vertices = json.vertices,
10969
+ normals = json.normals,
10970
+ colors = json.colors,
10971
+
10972
+ nUvLayers = 0;
10973
+
10974
+ if ( json.uvs !== undefined ) {
10975
+
10976
+ // disregard empty arrays
10977
+
10978
+ for ( i = 0; i < json.uvs.length; i ++ ) {
10979
+
10980
+ if ( json.uvs[ i ].length ) nUvLayers ++;
10981
+
10982
+ }
10983
+
10984
+ for ( i = 0; i < nUvLayers; i ++ ) {
10985
+
10986
+ geometry.faceVertexUvs[ i ] = [];
10987
+
10988
+ }
10989
+
10990
+ }
10991
+
10992
+ offset = 0;
10993
+ zLength = vertices.length;
10994
+
10995
+ while ( offset < zLength ) {
10996
+
10997
+ vertex = new THREE.Vector3();
10998
+
10999
+ vertex.x = vertices[ offset ++ ] * scale;
11000
+ vertex.y = vertices[ offset ++ ] * scale;
11001
+ vertex.z = vertices[ offset ++ ] * scale;
11002
+
11003
+ geometry.vertices.push( vertex );
11004
+
11005
+ }
11006
+
11007
+ offset = 0;
11008
+ zLength = faces.length;
11009
+
11010
+ while ( offset < zLength ) {
11011
+
11012
+ type = faces[ offset ++ ];
11013
+
11014
+
11015
+ isQuad = isBitSet( type, 0 );
11016
+ hasMaterial = isBitSet( type, 1 );
11017
+ hasFaceVertexUv = isBitSet( type, 3 );
11018
+ hasFaceNormal = isBitSet( type, 4 );
11019
+ hasFaceVertexNormal = isBitSet( type, 5 );
11020
+ hasFaceColor = isBitSet( type, 6 );
11021
+ hasFaceVertexColor = isBitSet( type, 7 );
11022
+
11023
+ // console.log("type", type, "bits", isQuad, hasMaterial, hasFaceVertexUv, hasFaceNormal, hasFaceVertexNormal, hasFaceColor, hasFaceVertexColor);
11024
+
11025
+ if ( isQuad ) {
11026
+
11027
+ faceA = new THREE.Face3();
11028
+ faceA.a = faces[ offset ];
11029
+ faceA.b = faces[ offset + 1 ];
11030
+ faceA.c = faces[ offset + 3 ];
11031
+
11032
+ faceB = new THREE.Face3();
11033
+ faceB.a = faces[ offset + 1 ];
11034
+ faceB.b = faces[ offset + 2 ];
11035
+ faceB.c = faces[ offset + 3 ];
11036
+
11037
+ offset += 4;
11038
+
11039
+ if ( hasMaterial ) {
11040
+
11041
+ materialIndex = faces[ offset ++ ];
11042
+ faceA.materialIndex = materialIndex;
11043
+ faceB.materialIndex = materialIndex;
11044
+
11045
+ }
11046
+
11047
+ // to get face <=> uv index correspondence
11048
+
11049
+ fi = geometry.faces.length;
11050
+
11051
+ if ( hasFaceVertexUv ) {
11052
+
11053
+ for ( i = 0; i < nUvLayers; i ++ ) {
11054
+
11055
+ uvLayer = json.uvs[ i ];
11056
+
11057
+ geometry.faceVertexUvs[ i ][ fi ] = [];
11058
+ geometry.faceVertexUvs[ i ][ fi + 1 ] = []
11059
+
11060
+ for ( j = 0; j < 4; j ++ ) {
11061
+
11062
+ uvIndex = faces[ offset ++ ];
11063
+
11064
+ u = uvLayer[ uvIndex * 2 ];
11065
+ v = uvLayer[ uvIndex * 2 + 1 ];
11066
+
11067
+ uv = new THREE.Vector2( u, v );
11068
+
11069
+ if ( j !== 2 ) geometry.faceVertexUvs[ i ][ fi ].push( uv );
11070
+ if ( j !== 0 ) geometry.faceVertexUvs[ i ][ fi + 1 ].push( uv );
11071
+
11072
+ }
11073
+
11074
+ }
11075
+
11076
+ }
11077
+
11078
+ if ( hasFaceNormal ) {
11079
+
11080
+ normalIndex = faces[ offset ++ ] * 3;
11081
+
11082
+ faceA.normal.set(
11083
+ normals[ normalIndex ++ ],
11084
+ normals[ normalIndex ++ ],
11085
+ normals[ normalIndex ]
11086
+ );
11087
+
11088
+ faceB.normal.copy( faceA.normal );
11089
+
11090
+ }
11091
+
11092
+ if ( hasFaceVertexNormal ) {
11093
+
11094
+ for ( i = 0; i < 4; i ++ ) {
11095
+
11096
+ normalIndex = faces[ offset ++ ] * 3;
11097
+
11098
+ normal = new THREE.Vector3(
11099
+ normals[ normalIndex ++ ],
11100
+ normals[ normalIndex ++ ],
11101
+ normals[ normalIndex ]
11102
+ );
11103
+
11104
+
11105
+ if ( i !== 2 ) faceA.vertexNormals.push( normal );
11106
+ if ( i !== 0 ) faceB.vertexNormals.push( normal );
11107
+
11108
+ }
11109
+
11110
+ }
11111
+
11112
+
11113
+ if ( hasFaceColor ) {
11114
+
11115
+ colorIndex = faces[ offset ++ ];
11116
+ hex = colors[ colorIndex ];
11117
+
11118
+ faceA.color.setHex( hex );
11119
+ faceB.color.setHex( hex );
11120
+
11121
+ }
11122
+
11123
+
11124
+ if ( hasFaceVertexColor ) {
11125
+
11126
+ for ( i = 0; i < 4; i ++ ) {
11127
+
11128
+ colorIndex = faces[ offset ++ ];
11129
+ hex = colors[ colorIndex ];
11130
+
11131
+ if ( i !== 2 ) faceA.vertexColors.push( new THREE.Color( hex ) );
11132
+ if ( i !== 0 ) faceB.vertexColors.push( new THREE.Color( hex ) );
11133
+
11134
+ }
11135
+
11136
+ }
11137
+
11138
+ geometry.faces.push( faceA );
11139
+ geometry.faces.push( faceB );
11140
+
11141
+ } else {
11142
+
11143
+ face = new THREE.Face3();
11144
+ face.a = faces[ offset ++ ];
11145
+ face.b = faces[ offset ++ ];
11146
+ face.c = faces[ offset ++ ];
11147
+
11148
+ if ( hasMaterial ) {
11149
+
11150
+ materialIndex = faces[ offset ++ ];
11151
+ face.materialIndex = materialIndex;
11152
+
11153
+ }
11154
+
11155
+ // to get face <=> uv index correspondence
11156
+
11157
+ fi = geometry.faces.length;
11158
+
11159
+ if ( hasFaceVertexUv ) {
11160
+
11161
+ for ( i = 0; i < nUvLayers; i ++ ) {
11162
+
11163
+ uvLayer = json.uvs[ i ];
11164
+
11165
+ geometry.faceVertexUvs[ i ][ fi ] = [];
11166
+
11167
+ for ( j = 0; j < 3; j ++ ) {
11168
+
11169
+ uvIndex = faces[ offset ++ ];
11170
+
11171
+ u = uvLayer[ uvIndex * 2 ];
11172
+ v = uvLayer[ uvIndex * 2 + 1 ];
11173
+
11174
+ uv = new THREE.Vector2( u, v );
11175
+
11176
+ geometry.faceVertexUvs[ i ][ fi ].push( uv );
11177
+
11178
+ }
11179
+
11180
+ }
11181
+
11182
+ }
11183
+
11184
+ if ( hasFaceNormal ) {
11185
+
11186
+ normalIndex = faces[ offset ++ ] * 3;
11187
+
11188
+ face.normal.set(
11189
+ normals[ normalIndex ++ ],
11190
+ normals[ normalIndex ++ ],
11191
+ normals[ normalIndex ]
11192
+ );
11193
+
11194
+ }
11195
+
11196
+ if ( hasFaceVertexNormal ) {
11197
+
11198
+ for ( i = 0; i < 3; i ++ ) {
11199
+
11200
+ normalIndex = faces[ offset ++ ] * 3;
11201
+
11202
+ normal = new THREE.Vector3(
11203
+ normals[ normalIndex ++ ],
11204
+ normals[ normalIndex ++ ],
11205
+ normals[ normalIndex ]
11206
+ );
11207
+
11208
+ face.vertexNormals.push( normal );
11209
+
11210
+ }
11211
+
11212
+ }
11213
+
11214
+
11215
+ if ( hasFaceColor ) {
11216
+
11217
+ colorIndex = faces[ offset ++ ];
11218
+ face.color.setHex( colors[ colorIndex ] );
11219
+
11220
+ }
11221
+
11222
+
11223
+ if ( hasFaceVertexColor ) {
11224
+
11225
+ for ( i = 0; i < 3; i ++ ) {
11226
+
11227
+ colorIndex = faces[ offset ++ ];
11228
+ face.vertexColors.push( new THREE.Color( colors[ colorIndex ] ) );
11229
+
11230
+ }
11231
+
11232
+ }
11233
+
11234
+ geometry.faces.push( face );
11235
+
11236
+ }
11237
+
11238
+ }
11239
+
11240
+ };
11241
+
11242
+ function parseSkin() {
11243
+ var influencesPerVertex = ( json.influencesPerVertex !== undefined ) ? json.influencesPerVertex : 2;
11244
+
11245
+ if ( json.skinWeights ) {
11246
+
11247
+ for ( var i = 0, l = json.skinWeights.length; i < l; i += influencesPerVertex ) {
11248
+
11249
+ var x = json.skinWeights[ i ];
11250
+ var y = ( influencesPerVertex > 1 ) ? json.skinWeights[ i + 1 ] : 0;
11251
+ var z = ( influencesPerVertex > 2 ) ? json.skinWeights[ i + 2 ] : 0;
11252
+ var w = ( influencesPerVertex > 3 ) ? json.skinWeights[ i + 3 ] : 0;
11253
+
11254
+ geometry.skinWeights.push( new THREE.Vector4( x, y, z, w ) );
11255
+
11256
+ }
11257
+
11258
+ }
11259
+
11260
+ if ( json.skinIndices ) {
11261
+
11262
+ for ( var i = 0, l = json.skinIndices.length; i < l; i += influencesPerVertex ) {
11263
+
11264
+ var a = json.skinIndices[ i ];
11265
+ var b = ( influencesPerVertex > 1 ) ? json.skinIndices[ i + 1 ] : 0;
11266
+ var c = ( influencesPerVertex > 2 ) ? json.skinIndices[ i + 2 ] : 0;
11267
+ var d = ( influencesPerVertex > 3 ) ? json.skinIndices[ i + 3 ] : 0;
11268
+
11269
+ geometry.skinIndices.push( new THREE.Vector4( a, b, c, d ) );
11270
+
11271
+ }
11272
+
11273
+ }
11274
+
11275
+ geometry.bones = json.bones;
11276
+
11277
+ if ( geometry.bones && geometry.bones.length > 0 && ( geometry.skinWeights.length !== geometry.skinIndices.length || geometry.skinIndices.length !== geometry.vertices.length ) ) {
11278
+
11279
+ console.warn( 'When skinning, number of vertices (' + geometry.vertices.length + '), skinIndices (' +
11280
+ geometry.skinIndices.length + '), and skinWeights (' + geometry.skinWeights.length + ') should match.' );
11281
+
11282
+ }
11283
+
11284
+
11285
+ // could change this to json.animations[0] or remove completely
11286
+
11287
+ geometry.animation = json.animation;
11288
+ geometry.animations = json.animations;
11289
+
11290
+ };
11291
+
11292
+ function parseMorphing( scale ) {
11293
+
11294
+ if ( json.morphTargets !== undefined ) {
11295
+
11296
+ var i, l, v, vl, dstVertices, srcVertices;
11297
+
11298
+ for ( i = 0, l = json.morphTargets.length; i < l; i ++ ) {
11299
+
11300
+ geometry.morphTargets[ i ] = {};
11301
+ geometry.morphTargets[ i ].name = json.morphTargets[ i ].name;
11302
+ geometry.morphTargets[ i ].vertices = [];
11303
+
11304
+ dstVertices = geometry.morphTargets[ i ].vertices;
11305
+ srcVertices = json.morphTargets [ i ].vertices;
11306
+
11307
+ for ( v = 0, vl = srcVertices.length; v < vl; v += 3 ) {
11308
+
11309
+ var vertex = new THREE.Vector3();
11310
+ vertex.x = srcVertices[ v ] * scale;
11311
+ vertex.y = srcVertices[ v + 1 ] * scale;
11312
+ vertex.z = srcVertices[ v + 2 ] * scale;
11313
+
11314
+ dstVertices.push( vertex );
11315
+
11316
+ }
11317
+
11318
+ }
11319
+
11320
+ }
11321
+
11322
+ if ( json.morphColors !== undefined ) {
11323
+
11324
+ var i, l, c, cl, dstColors, srcColors, color;
11325
+
11326
+ for ( i = 0, l = json.morphColors.length; i < l; i ++ ) {
11327
+
11328
+ geometry.morphColors[ i ] = {};
11329
+ geometry.morphColors[ i ].name = json.morphColors[ i ].name;
11330
+ geometry.morphColors[ i ].colors = [];
11331
+
11332
+ dstColors = geometry.morphColors[ i ].colors;
11333
+ srcColors = json.morphColors [ i ].colors;
11334
+
11335
+ for ( c = 0, cl = srcColors.length; c < cl; c += 3 ) {
11336
+
11337
+ color = new THREE.Color( 0xffaa00 );
11338
+ color.setRGB( srcColors[ c ], srcColors[ c + 1 ], srcColors[ c + 2 ] );
11339
+ dstColors.push( color );
11340
+
11341
+ }
11342
+
11343
+ }
11344
+
11345
+ }
11346
+
11347
+ };
11348
+
11349
+ if ( json.materials === undefined || json.materials.length === 0 ) {
11350
+
11351
+ return { geometry: geometry };
11352
+
11353
+ } else {
11354
+
11355
+ var materials = this.initMaterials( json.materials, texturePath );
11356
+
11357
+ if ( this.needsTangents( materials ) ) {
11358
+
11359
+ geometry.computeTangents();
11360
+
11361
+ }
11362
+
11363
+ return { geometry: geometry, materials: materials };
11364
+
11365
+ }
11366
+
11367
+ };
11368
+
11369
+ // File:src/loaders/LoadingManager.js
11370
+
11371
+ /**
11372
+ * @author mrdoob / http://mrdoob.com/
11373
+ */
11374
+
11375
+ THREE.LoadingManager = function ( onLoad, onProgress, onError ) {
11376
+
11377
+ var scope = this;
11378
+
11379
+ var loaded = 0, total = 0;
11380
+
11381
+ this.onLoad = onLoad;
11382
+ this.onProgress = onProgress;
11383
+ this.onError = onError;
11384
+
11385
+ this.itemStart = function ( url ) {
11386
+
11387
+ total ++;
11388
+
11389
+ };
11390
+
11391
+ this.itemEnd = function ( url ) {
11392
+
11393
+ loaded ++;
11394
+
11395
+ if ( scope.onProgress !== undefined ) {
11396
+
11397
+ scope.onProgress( url, loaded, total );
11398
+
11399
+ }
11400
+
11401
+ if ( loaded === total && scope.onLoad !== undefined ) {
11402
+
11403
+ scope.onLoad();
11404
+
11405
+ }
11406
+
11407
+ };
11408
+
11409
+ };
11410
+
11411
+ THREE.DefaultLoadingManager = new THREE.LoadingManager();
11412
+
11413
+ // File:src/loaders/BufferGeometryLoader.js
11414
+
11415
+ /**
11416
+ * @author mrdoob / http://mrdoob.com/
11417
+ */
11418
+ /*
11419
+ THREE.BufferGeometryLoader = function ( manager ) {
11420
+
11421
+ this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
11422
+
11423
+ };
11424
+
11425
+ THREE.BufferGeometryLoader.prototype = {
11426
+
11427
+ constructor: THREE.BufferGeometryLoader,
11428
+
11429
+ load: function ( url, onLoad, onProgress, onError ) {
11430
+
11431
+ var scope = this;
11432
+
11433
+ var loader = new THREE.XHRLoader();
11434
+ loader.setCrossOrigin( this.crossOrigin );
11435
+ loader.load( url, function ( text ) {
11436
+
11437
+ onLoad( scope.parse( JSON.parse( text ) ) );
11438
+
11439
+ }, onProgress, onError );
11440
+
11441
+ },
11442
+
11443
+ setCrossOrigin: function ( value ) {
11444
+
11445
+ this.crossOrigin = value;
11446
+
11447
+ },
11448
+
11449
+ parse: function ( json ) {
11450
+
11451
+ var geometry = new THREE.BufferGeometry();
11452
+
11453
+ var attributes = json.attributes;
11454
+
11455
+ for ( var key in attributes ) {
11456
+
11457
+ var attribute = attributes[ key ];
11458
+ var typedArray = new self[ attribute.type ]( attribute.array );
11459
+
11460
+ geometry.addAttribute( key, new THREE.BufferAttribute( typedArray, attribute.itemSize ) );
11461
+
11462
+ }
11463
+
11464
+ var offsets = json.offsets;
11465
+
11466
+ if ( offsets !== undefined ) {
11467
+
11468
+ geometry.offsets = JSON.parse( JSON.stringify( offsets ) );
11469
+
11470
+ }
11471
+
11472
+ var boundingSphere = json.boundingSphere;
11473
+
11474
+ if ( boundingSphere !== undefined ) {
11475
+
11476
+ var center = new THREE.Vector3();
11477
+
11478
+ if ( boundingSphere.center !== undefined ) {
11479
+
11480
+ center.fromArray( boundingSphere.center );
11481
+
11482
+ }
11483
+
11484
+ geometry.boundingSphere = new THREE.Sphere( center, boundingSphere.radius );
11485
+
11486
+ }
11487
+
11488
+ return geometry;
11489
+
11490
+ }
11491
+
11492
+ };
11493
+
11494
+ // File:src/loaders/MaterialLoader.js
11495
+
11496
+ /**
11497
+ * @author mrdoob / http://mrdoob.com/
11498
+ */
11499
+ /*
11500
+ THREE.MaterialLoader = function ( manager ) {
11501
+
11502
+ this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
11503
+
11504
+ };
11505
+
11506
+ THREE.MaterialLoader.prototype = {
11507
+
11508
+ constructor: THREE.MaterialLoader,
11509
+
11510
+ load: function ( url, onLoad, onProgress, onError ) {
11511
+
11512
+ var scope = this;
11513
+
11514
+ var loader = new THREE.XHRLoader();
11515
+ loader.setCrossOrigin( this.crossOrigin );
11516
+ loader.load( url, function ( text ) {
11517
+
11518
+ onLoad( scope.parse( JSON.parse( text ) ) );
11519
+
11520
+ }, onProgress, onError );
11521
+
11522
+ },
11523
+
11524
+ setCrossOrigin: function ( value ) {
11525
+
11526
+ this.crossOrigin = value;
11527
+
11528
+ },
11529
+
11530
+ parse: function ( json ) {
11531
+
11532
+ var material = new THREE[ json.type ];
11533
+
11534
+ if ( json.color !== undefined ) material.color.setHex( json.color );
11535
+ if ( json.ambient !== undefined ) material.ambient.setHex( json.ambient );
11536
+ if ( json.emissive !== undefined ) material.emissive.setHex( json.emissive );
11537
+ if ( json.specular !== undefined ) material.specular.setHex( json.specular );
11538
+ if ( json.shininess !== undefined ) material.shininess = json.shininess;
11539
+ if ( json.uniforms !== undefined ) material.uniforms = json.uniforms;
11540
+ if ( json.vertexShader !== undefined ) material.vertexShader = json.vertexShader;
11541
+ if ( json.fragmentShader !== undefined ) material.fragmentShader = json.fragmentShader;
11542
+ if ( json.vertexColors !== undefined ) material.vertexColors = json.vertexColors;
11543
+ if ( json.shading !== undefined ) material.shading = json.shading;
11544
+ if ( json.blending !== undefined ) material.blending = json.blending;
11545
+ if ( json.side !== undefined ) material.side = json.side;
11546
+ if ( json.opacity !== undefined ) material.opacity = json.opacity;
11547
+ if ( json.transparent !== undefined ) material.transparent = json.transparent;
11548
+ if ( json.wireframe !== undefined ) material.wireframe = json.wireframe;
11549
+
11550
+ if ( json.materials !== undefined ) {
11551
+
11552
+ for ( var i = 0, l = json.materials.length; i < l; i ++ ) {
11553
+
11554
+ material.materials.push( this.parse( json.materials[ i ] ) );
11555
+
11556
+ }
11557
+
11558
+ }
11559
+
11560
+ return material;
11561
+
11562
+ }
11563
+
11564
+ };
11565
+
11566
+ // File:src/loaders/ObjectLoader.js
11567
+
11568
+ /**
11569
+ * @author mrdoob / http://mrdoob.com/
11570
+ */
11571
+ /*
11572
+ THREE.ObjectLoader = function ( manager ) {
11573
+
11574
+ this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
11575
+
11576
+ };
11577
+
11578
+ THREE.ObjectLoader.prototype = {
11579
+
11580
+ constructor: THREE.ObjectLoader,
11581
+
11582
+ load: function ( url, onLoad, onProgress, onError ) {
11583
+
11584
+ var scope = this;
11585
+
11586
+ var loader = new THREE.XHRLoader( scope.manager );
11587
+ loader.setCrossOrigin( this.crossOrigin );
11588
+ loader.load( url, function ( text ) {
11589
+
11590
+ onLoad( scope.parse( JSON.parse( text ) ) );
11591
+
11592
+ }, onProgress, onError );
11593
+
11594
+ },
11595
+
11596
+ setCrossOrigin: function ( value ) {
11597
+
11598
+ this.crossOrigin = value;
11599
+
11600
+ },
11601
+
11602
+ parse: function ( json ) {
11603
+
11604
+ var geometries = this.parseGeometries( json.geometries );
11605
+ var materials = this.parseMaterials( json.materials );
11606
+ var object = this.parseObject( json.object, geometries, materials );
11607
+
11608
+ return object;
11609
+
11610
+ },
11611
+
11612
+ parseGeometries: function ( json ) {
11613
+
11614
+ var geometries = {};
11615
+
11616
+ if ( json !== undefined ) {
11617
+
11618
+ var geometryLoader = new THREE.JSONLoader();
11619
+ var bufferGeometryLoader = new THREE.BufferGeometryLoader();
11620
+
11621
+ for ( var i = 0, l = json.length; i < l; i ++ ) {
11622
+
11623
+ var geometry;
11624
+ var data = json[ i ];
11625
+
11626
+ switch ( data.type ) {
11627
+
11628
+ case 'PlaneGeometry':
11629
+
11630
+ geometry = new THREE.PlaneGeometry(
11631
+ data.width,
11632
+ data.height,
11633
+ data.widthSegments,
11634
+ data.heightSegments
11635
+ );
11636
+
11637
+ break;
11638
+
11639
+ case 'BoxGeometry':
11640
+ case 'CubeGeometry': // backwards compatible
11641
+
11642
+ geometry = new THREE.BoxGeometry(
11643
+ data.width,
11644
+ data.height,
11645
+ data.depth,
11646
+ data.widthSegments,
11647
+ data.heightSegments,
11648
+ data.depthSegments
11649
+ );
11650
+
11651
+ break;
11652
+
11653
+ case 'CircleGeometry':
11654
+
11655
+ geometry = new THREE.CircleGeometry(
11656
+ data.radius,
11657
+ data.segments
11658
+ );
11659
+
11660
+ break;
11661
+
11662
+ case 'CylinderGeometry':
11663
+
11664
+ geometry = new THREE.CylinderGeometry(
11665
+ data.radiusTop,
11666
+ data.radiusBottom,
11667
+ data.height,
11668
+ data.radialSegments,
11669
+ data.heightSegments,
11670
+ data.openEnded
11671
+ );
11672
+
11673
+ break;
11674
+
11675
+ case 'SphereGeometry':
11676
+
11677
+ geometry = new THREE.SphereGeometry(
11678
+ data.radius,
11679
+ data.widthSegments,
11680
+ data.heightSegments,
11681
+ data.phiStart,
11682
+ data.phiLength,
11683
+ data.thetaStart,
11684
+ data.thetaLength
11685
+ );
11686
+
11687
+ break;
11688
+
11689
+ case 'IcosahedronGeometry':
11690
+
11691
+ geometry = new THREE.IcosahedronGeometry(
11692
+ data.radius,
11693
+ data.detail
11694
+ );
11695
+
11696
+ break;
11697
+
11698
+ case 'TorusGeometry':
11699
+
11700
+ geometry = new THREE.TorusGeometry(
11701
+ data.radius,
11702
+ data.tube,
11703
+ data.radialSegments,
11704
+ data.tubularSegments,
11705
+ data.arc
11706
+ );
11707
+
11708
+ break;
11709
+
11710
+ case 'TorusKnotGeometry':
11711
+
11712
+ geometry = new THREE.TorusKnotGeometry(
11713
+ data.radius,
11714
+ data.tube,
11715
+ data.radialSegments,
11716
+ data.tubularSegments,
11717
+ data.p,
11718
+ data.q,
11719
+ data.heightScale
11720
+ );
11721
+
11722
+ break;
11723
+
11724
+ case 'BufferGeometry':
11725
+
11726
+ geometry = bufferGeometryLoader.parse( data.data );
11727
+
11728
+ break;
11729
+
11730
+ case 'Geometry':
11731
+
11732
+ geometry = geometryLoader.parse( data.data ).geometry;
11733
+
11734
+ break;
11735
+
11736
+ }
11737
+
11738
+ geometry.uuid = data.uuid;
11739
+
11740
+ if ( data.name !== undefined ) geometry.name = data.name;
11741
+
11742
+ geometries[ data.uuid ] = geometry;
11743
+
11744
+ }
11745
+
11746
+ }
11747
+
11748
+ return geometries;
11749
+
11750
+ },
11751
+
11752
+ parseMaterials: function ( json ) {
11753
+
11754
+ var materials = {};
11755
+
11756
+ if ( json !== undefined ) {
11757
+
11758
+ var loader = new THREE.MaterialLoader();
11759
+
11760
+ for ( var i = 0, l = json.length; i < l; i ++ ) {
11761
+
11762
+ var data = json[ i ];
11763
+ var material = loader.parse( data );
11764
+
11765
+ material.uuid = data.uuid;
11766
+
11767
+ if ( data.name !== undefined ) material.name = data.name;
11768
+
11769
+ materials[ data.uuid ] = material;
11770
+
11771
+ }
11772
+
11773
+ }
11774
+
11775
+ return materials;
11776
+
11777
+ },
11778
+
11779
+ parseObject: function () {
11780
+
11781
+ var matrix = new THREE.Matrix4();
11782
+
11783
+ return function ( data, geometries, materials ) {
11784
+
11785
+ var object;
11786
+
11787
+ switch ( data.type ) {
11788
+
11789
+ case 'Scene':
11790
+
11791
+ object = new THREE.Scene();
11792
+
11793
+ break;
11794
+
11795
+ case 'PerspectiveCamera':
11796
+
11797
+ object = new THREE.PerspectiveCamera( data.fov, data.aspect, data.near, data.far );
11798
+
11799
+ break;
11800
+
11801
+ case 'OrthographicCamera':
11802
+
11803
+ object = new THREE.OrthographicCamera( data.left, data.right, data.top, data.bottom, data.near, data.far );
11804
+
11805
+ break;
11806
+
11807
+ case 'AmbientLight':
11808
+
11809
+ object = new THREE.AmbientLight( data.color );
11810
+
11811
+ break;
11812
+
11813
+ case 'DirectionalLight':
11814
+
11815
+ object = new THREE.DirectionalLight( data.color, data.intensity );
11816
+
11817
+ break;
11818
+
11819
+ case 'PointLight':
11820
+
11821
+ object = new THREE.PointLight( data.color, data.intensity, data.distance );
11822
+
11823
+ break;
11824
+
11825
+ case 'SpotLight':
11826
+
11827
+ object = new THREE.SpotLight( data.color, data.intensity, data.distance, data.angle, data.exponent );
11828
+
11829
+ break;
11830
+
11831
+ case 'HemisphereLight':
11832
+
11833
+ object = new THREE.HemisphereLight( data.color, data.groundColor, data.intensity );
11834
+
11835
+ break;
11836
+
11837
+ case 'Mesh':
11838
+
11839
+ var geometry = geometries[ data.geometry ];
11840
+ var material = materials[ data.material ];
11841
+
11842
+ if ( geometry === undefined ) {
11843
+
11844
+ console.warn( 'THREE.ObjectLoader: Undefined geometry', data.geometry );
11845
+
11846
+ }
11847
+
11848
+ if ( material === undefined ) {
11849
+
11850
+ console.warn( 'THREE.ObjectLoader: Undefined material', data.material );
11851
+
11852
+ }
11853
+
11854
+ object = new THREE.Mesh( geometry, material );
11855
+
11856
+ break;
11857
+
11858
+ case 'Line':
11859
+
11860
+ var geometry = geometries[ data.geometry ];
11861
+ var material = materials[ data.material ];
11862
+
11863
+ if ( geometry === undefined ) {
11864
+
11865
+ console.warn( 'THREE.ObjectLoader: Undefined geometry', data.geometry );
11866
+
11867
+ }
11868
+
11869
+ if ( material === undefined ) {
11870
+
11871
+ console.warn( 'THREE.ObjectLoader: Undefined material', data.material );
11872
+
11873
+ }
11874
+
11875
+ object = new THREE.Line( geometry, material );
11876
+
11877
+ break;
11878
+
11879
+ case 'Sprite':
11880
+
11881
+ var material = materials[ data.material ];
11882
+
11883
+ if ( material === undefined ) {
11884
+
11885
+ console.warn( 'THREE.ObjectLoader: Undefined material', data.material );
11886
+
11887
+ }
11888
+
11889
+ object = new THREE.Sprite( material );
11890
+
11891
+ break;
11892
+
11893
+ case 'Group':
11894
+
11895
+ object = new THREE.Group();
11896
+
11897
+ break;
11898
+
11899
+ default:
11900
+
11901
+ object = new THREE.Object3D();
11902
+
11903
+ }
11904
+
11905
+ object.uuid = data.uuid;
11906
+
11907
+ if ( data.name !== undefined ) object.name = data.name;
11908
+ if ( data.matrix !== undefined ) {
11909
+
11910
+ matrix.fromArray( data.matrix );
11911
+ matrix.decompose( object.position, object.quaternion, object.scale );
11912
+
11913
+ } else {
11914
+
11915
+ if ( data.position !== undefined ) object.position.fromArray( data.position );
11916
+ if ( data.rotation !== undefined ) object.rotation.fromArray( data.rotation );
11917
+ if ( data.scale !== undefined ) object.scale.fromArray( data.scale );
11918
+
11919
+ }
11920
+
11921
+ if ( data.visible !== undefined ) object.visible = data.visible;
11922
+ if ( data.userData !== undefined ) object.userData = data.userData;
11923
+
11924
+ if ( data.children !== undefined ) {
11925
+
11926
+ for ( var child in data.children ) {
11927
+
11928
+ object.add( this.parseObject( data.children[ child ], geometries, materials ) );
11929
+
11930
+ }
11931
+
11932
+ }
11933
+
11934
+ return object;
11935
+
11936
+ }
11937
+
11938
+ }()
11939
+
11940
+ };
11941
+
11942
+ // File:src/loaders/TextureLoader.js
11943
+
11944
+ /**
11945
+ * @author mrdoob / http://mrdoob.com/
11946
+ */
11947
+
11948
+ THREE.TextureLoader = function ( manager ) {
11949
+
11950
+ this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
11951
+
11952
+ };
11953
+
11954
+ THREE.TextureLoader.prototype = {
11955
+
11956
+ constructor: THREE.TextureLoader,
11957
+
11958
+ load: function ( url, onLoad, onProgress, onError ) {
11959
+
11960
+ var scope = this;
11961
+
11962
+ var loader = new THREE.ImageLoader( scope.manager );
11963
+ loader.setCrossOrigin( this.crossOrigin );
11964
+ loader.load( url, function ( image ) {
11965
+
11966
+ var texture = new THREE.Texture( image );
11967
+ texture.needsUpdate = true;
11968
+
11969
+ if ( onLoad !== undefined ) {
11970
+
11971
+ onLoad( texture );
11972
+
11973
+ }
11974
+
11975
+ }, onProgress, onError );
11976
+
11977
+ },
11978
+
11979
+ setCrossOrigin: function ( value ) {
11980
+
11981
+ this.crossOrigin = value;
11982
+
11983
+ }
11984
+
11985
+ };
11986
+
11987
+ // File:src/loaders/CompressedTextureLoader.js
11988
+
11989
+ /**
11990
+ * @author mrdoob / http://mrdoob.com/
11991
+ *
11992
+ * Abstract Base class to block based textures loader (dds, pvr, ...)
11993
+ */
11994
+
11995
+ THREE.CompressedTextureLoader = function () {
11996
+
11997
+ // override in sub classes
11998
+ this._parser = null;
11999
+
12000
+ };
12001
+
12002
+
12003
+ THREE.CompressedTextureLoader.prototype = {
12004
+
12005
+ constructor: THREE.CompressedTextureLoader,
12006
+
12007
+ load: function ( url, onLoad, onError ) {
12008
+
12009
+ var scope = this;
12010
+
12011
+ var images = [];
12012
+
12013
+ var texture = new THREE.CompressedTexture();
12014
+ texture.image = images;
12015
+
12016
+ var loader = new THREE.XHRLoader();
12017
+ loader.setResponseType( 'arraybuffer' );
12018
+
12019
+ if ( url instanceof Array ) {
12020
+
12021
+ var loaded = 0;
12022
+
12023
+ var loadTexture = function ( i ) {
12024
+
12025
+ loader.load( url[ i ], function ( buffer ) {
12026
+
12027
+ var texDatas = scope._parser( buffer, true );
12028
+
12029
+ images[ i ] = {
12030
+ width: texDatas.width,
12031
+ height: texDatas.height,
12032
+ format: texDatas.format,
12033
+ mipmaps: texDatas.mipmaps
12034
+ };
12035
+
12036
+ loaded += 1;
12037
+
12038
+ if ( loaded === 6 ) {
12039
+
12040
+ if (texDatas.mipmapCount == 1)
12041
+ texture.minFilter = THREE.LinearFilter;
12042
+
12043
+ texture.format = texDatas.format;
12044
+ texture.needsUpdate = true;
12045
+
12046
+ if ( onLoad ) onLoad( texture );
12047
+
12048
+ }
12049
+
12050
+ } );
12051
+
12052
+ };
12053
+
12054
+ for ( var i = 0, il = url.length; i < il; ++ i ) {
12055
+
12056
+ loadTexture( i );
12057
+
12058
+ }
12059
+
12060
+ } else {
12061
+
12062
+ // compressed cubemap texture stored in a single DDS file
12063
+
12064
+ loader.load( url, function ( buffer ) {
12065
+
12066
+ var texDatas = scope._parser( buffer, true );
12067
+
12068
+ if ( texDatas.isCubemap ) {
12069
+
12070
+ var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
12071
+
12072
+ for ( var f = 0; f < faces; f ++ ) {
12073
+
12074
+ images[ f ] = { mipmaps : [] };
12075
+
12076
+ for ( var i = 0; i < texDatas.mipmapCount; i ++ ) {
12077
+
12078
+ images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] );
12079
+ images[ f ].format = texDatas.format;
12080
+ images[ f ].width = texDatas.width;
12081
+ images[ f ].height = texDatas.height;
12082
+
12083
+ }
12084
+
12085
+ }
12086
+
12087
+ } else {
12088
+
12089
+ texture.image.width = texDatas.width;
12090
+ texture.image.height = texDatas.height;
12091
+ texture.mipmaps = texDatas.mipmaps;
12092
+
12093
+ }
12094
+
12095
+ if ( texDatas.mipmapCount === 1 ) {
12096
+
12097
+ texture.minFilter = THREE.LinearFilter;
12098
+
12099
+ }
12100
+
12101
+ texture.format = texDatas.format;
12102
+ texture.needsUpdate = true;
12103
+
12104
+ if ( onLoad ) onLoad( texture );
12105
+
12106
+ } );
12107
+
12108
+ }
12109
+
12110
+ return texture;
12111
+
12112
+ }
12113
+
12114
+ };
12115
+
12116
+ // File:src/materials/Material.js
12117
+
12118
+ /**
12119
+ * @author mrdoob / http://mrdoob.com/
12120
+ * @author alteredq / http://alteredqualia.com/
12121
+ */
12122
+
12123
+ THREE.Material = function () {
12124
+
12125
+ Object.defineProperty( this, 'id', { value: THREE.MaterialIdCount ++ } );
12126
+
12127
+ this.uuid = THREE.Math.generateUUID();
12128
+
12129
+ this.name = '';
12130
+ this.type = 'Material';
12131
+
12132
+ this.side = THREE.FrontSide;
12133
+
12134
+ this.opacity = 1;
12135
+ this.transparent = false;
12136
+
12137
+ this.blending = THREE.NormalBlending;
12138
+
12139
+ this.blendSrc = THREE.SrcAlphaFactor;
12140
+ this.blendDst = THREE.OneMinusSrcAlphaFactor;
12141
+ this.blendEquation = THREE.AddEquation;
12142
+
12143
+ this.depthTest = true;
12144
+ this.depthWrite = true;
12145
+
12146
+ this.polygonOffset = false;
12147
+ this.polygonOffsetFactor = 0;
12148
+ this.polygonOffsetUnits = 0;
12149
+
12150
+ this.alphaTest = 0;
12151
+
12152
+ this.overdraw = 0; // Overdrawn pixels (typically between 0 and 1) for fixing antialiasing gaps in CanvasRenderer
12153
+
12154
+ this.visible = true;
12155
+
12156
+ this.needsUpdate = true;
12157
+
12158
+ };
12159
+
12160
+ THREE.Material.prototype = {
12161
+
12162
+ constructor: THREE.Material,
12163
+
12164
+ setValues: function ( values ) {
12165
+
12166
+ if ( values === undefined ) return;
12167
+
12168
+ for ( var key in values ) {
12169
+
12170
+ var newValue = values[ key ];
12171
+
12172
+ if ( newValue === undefined ) {
12173
+
12174
+ console.warn( "THREE.Material: '" + key + "' parameter is undefined." );
12175
+ continue;
12176
+
12177
+ }
12178
+
12179
+ if ( key in this ) {
12180
+
12181
+ var currentValue = this[ key ];
12182
+
12183
+ if ( currentValue instanceof THREE.Color ) {
12184
+
12185
+ currentValue.set( newValue );
12186
+
12187
+ } else if ( currentValue instanceof THREE.Vector3 && newValue instanceof THREE.Vector3 ) {
12188
+
12189
+ currentValue.copy( newValue );
12190
+
12191
+ } else if ( key == 'overdraw' ) {
12192
+
12193
+ // ensure overdraw is backwards-compatable with legacy boolean type
12194
+ this[ key ] = Number( newValue );
12195
+
12196
+ } else {
12197
+
12198
+ this[ key ] = newValue;
12199
+
12200
+ }
12201
+
12202
+ }
12203
+
12204
+ }
12205
+
12206
+ },
12207
+
12208
+ toJSON: function () {
12209
+
12210
+ var output = {
12211
+ metadata: {
12212
+ version: 4.2,
12213
+ type: 'material',
12214
+ generator: 'MaterialExporter'
12215
+ },
12216
+ uuid: this.uuid,
12217
+ type: this.type
12218
+ };
12219
+
12220
+ if ( this.name !== "" ) output.name = this.name;
12221
+
12222
+ if ( this instanceof THREE.MeshBasicMaterial ) {
12223
+
12224
+ output.color = this.color.getHex();
12225
+ if ( this.vertexColors !== THREE.NoColors ) output.vertexColors = this.vertexColors;
12226
+ if ( this.blending !== THREE.NormalBlending ) output.blending = this.blending;
12227
+ if ( this.side !== THREE.FrontSide ) output.side = this.side;
12228
+
12229
+ } else if ( this instanceof THREE.MeshLambertMaterial ) {
12230
+
12231
+ output.color = this.color.getHex();
12232
+ output.ambient = this.ambient.getHex();
12233
+ output.emissive = this.emissive.getHex();
12234
+ if ( this.vertexColors !== THREE.NoColors ) output.vertexColors = this.vertexColors;
12235
+ if ( this.blending !== THREE.NormalBlending ) output.blending = this.blending;
12236
+ if ( this.side !== THREE.FrontSide ) output.side = this.side;
12237
+
12238
+ } else if ( this instanceof THREE.MeshPhongMaterial ) {
12239
+
12240
+ output.color = this.color.getHex();
12241
+ output.ambient = this.ambient.getHex();
12242
+ output.emissive = this.emissive.getHex();
12243
+ output.specular = this.specular.getHex();
12244
+ output.shininess = this.shininess;
12245
+ if ( this.vertexColors !== THREE.NoColors ) output.vertexColors = this.vertexColors;
12246
+ if ( this.blending !== THREE.NormalBlending ) output.blending = this.blending;
12247
+ if ( this.side !== THREE.FrontSide ) output.side = this.side;
12248
+
12249
+ } else if ( this instanceof THREE.MeshNormalMaterial ) {
12250
+
12251
+ if ( this.shading !== THREE.FlatShading ) output.shading = this.shading;
12252
+ if ( this.blending !== THREE.NormalBlending ) output.blending = this.blending;
12253
+ if ( this.side !== THREE.FrontSide ) output.side = this.side;
12254
+
12255
+ } else if ( this instanceof THREE.MeshDepthMaterial ) {
12256
+
12257
+ if ( this.blending !== THREE.NormalBlending ) output.blending = this.blending;
12258
+ if ( this.side !== THREE.FrontSide ) output.side = this.side;
12259
+
12260
+ } else if ( this instanceof THREE.ShaderMaterial ) {
12261
+
12262
+ output.uniforms = this.uniforms;
12263
+ output.vertexShader = this.vertexShader;
12264
+ output.fragmentShader = this.fragmentShader;
12265
+
12266
+ } else if ( this instanceof THREE.SpriteMaterial ) {
12267
+
12268
+ output.color = this.color.getHex();
12269
+
12270
+ }
12271
+
12272
+ if ( this.opacity < 1 ) output.opacity = this.opacity;
12273
+ if ( this.transparent !== false ) output.transparent = this.transparent;
12274
+ if ( this.wireframe !== false ) output.wireframe = this.wireframe;
12275
+
12276
+ return output;
12277
+
12278
+ },
12279
+
12280
+ clone: function ( material ) {
12281
+
12282
+ if ( material === undefined ) material = new THREE.Material();
12283
+
12284
+ material.name = this.name;
12285
+
12286
+ material.side = this.side;
12287
+
12288
+ material.opacity = this.opacity;
12289
+ material.transparent = this.transparent;
12290
+
12291
+ material.blending = this.blending;
12292
+
12293
+ material.blendSrc = this.blendSrc;
12294
+ material.blendDst = this.blendDst;
12295
+ material.blendEquation = this.blendEquation;
12296
+
12297
+ material.depthTest = this.depthTest;
12298
+ material.depthWrite = this.depthWrite;
12299
+
12300
+ material.polygonOffset = this.polygonOffset;
12301
+ material.polygonOffsetFactor = this.polygonOffsetFactor;
12302
+ material.polygonOffsetUnits = this.polygonOffsetUnits;
12303
+
12304
+ material.alphaTest = this.alphaTest;
12305
+
12306
+ material.overdraw = this.overdraw;
12307
+
12308
+ material.visible = this.visible;
12309
+
12310
+ return material;
12311
+
12312
+ },
12313
+
12314
+ dispose: function () {
12315
+
12316
+ this.dispatchEvent( { type: 'dispose' } );
12317
+
12318
+ }
12319
+
12320
+ };
12321
+
12322
+ THREE.EventDispatcher.prototype.apply( THREE.Material.prototype );
12323
+
12324
+ THREE.MaterialIdCount = 0;
12325
+
12326
+ // File:src/materials/LineBasicMaterial.js
12327
+
12328
+ /**
12329
+ * @author mrdoob / http://mrdoob.com/
12330
+ * @author alteredq / http://alteredqualia.com/
12331
+ *
12332
+ * parameters = {
12333
+ * color: <hex>,
12334
+ * opacity: <float>,
12335
+ *
12336
+ * blending: THREE.NormalBlending,
12337
+ * depthTest: <bool>,
12338
+ * depthWrite: <bool>,
12339
+ *
12340
+ * linewidth: <float>,
12341
+ * linecap: "round",
12342
+ * linejoin: "round",
12343
+ *
12344
+ * vertexColors: <bool>
12345
+ *
12346
+ * fog: <bool>
12347
+ * }
12348
+ */
12349
+
12350
+ THREE.LineBasicMaterial = function ( parameters ) {
12351
+
12352
+ THREE.Material.call( this );
12353
+
12354
+ this.type = 'LineBasicMaterial';
12355
+
12356
+ this.color = new THREE.Color( 0xffffff );
12357
+
12358
+ this.linewidth = 1;
12359
+ this.linecap = 'round';
12360
+ this.linejoin = 'round';
12361
+
12362
+ this.vertexColors = THREE.NoColors;
12363
+
12364
+ this.fog = true;
12365
+
12366
+ this.setValues( parameters );
12367
+
12368
+ };
12369
+
12370
+ THREE.LineBasicMaterial.prototype = Object.create( THREE.Material.prototype );
12371
+
12372
+ THREE.LineBasicMaterial.prototype.clone = function () {
12373
+
12374
+ var material = new THREE.LineBasicMaterial();
12375
+
12376
+ THREE.Material.prototype.clone.call( this, material );
12377
+
12378
+ material.color.copy( this.color );
12379
+
12380
+ material.linewidth = this.linewidth;
12381
+ material.linecap = this.linecap;
12382
+ material.linejoin = this.linejoin;
12383
+
12384
+ material.vertexColors = this.vertexColors;
12385
+
12386
+ material.fog = this.fog;
12387
+
12388
+ return material;
12389
+
12390
+ };
12391
+
12392
+ // File:src/materials/LineDashedMaterial.js
12393
+
12394
+ /**
12395
+ * @author alteredq / http://alteredqualia.com/
12396
+ *
12397
+ * parameters = {
12398
+ * color: <hex>,
12399
+ * opacity: <float>,
12400
+ *
12401
+ * blending: THREE.NormalBlending,
12402
+ * depthTest: <bool>,
12403
+ * depthWrite: <bool>,
12404
+ *
12405
+ * linewidth: <float>,
12406
+ *
12407
+ * scale: <float>,
12408
+ * dashSize: <float>,
12409
+ * gapSize: <float>,
12410
+ *
12411
+ * vertexColors: <bool>
12412
+ *
12413
+ * fog: <bool>
12414
+ * }
12415
+ */
12416
+
12417
+ THREE.LineDashedMaterial = function ( parameters ) {
12418
+
12419
+ THREE.Material.call( this );
12420
+
12421
+ this.type = 'LineDashedMaterial';
12422
+
12423
+ this.color = new THREE.Color( 0xffffff );
12424
+
12425
+ this.linewidth = 1;
12426
+
12427
+ this.scale = 1;
12428
+ this.dashSize = 3;
12429
+ this.gapSize = 1;
12430
+
12431
+ this.vertexColors = false;
12432
+
12433
+ this.fog = true;
12434
+
12435
+ this.setValues( parameters );
12436
+
12437
+ };
12438
+
12439
+ THREE.LineDashedMaterial.prototype = Object.create( THREE.Material.prototype );
12440
+
12441
+ THREE.LineDashedMaterial.prototype.clone = function () {
12442
+
12443
+ var material = new THREE.LineDashedMaterial();
12444
+
12445
+ THREE.Material.prototype.clone.call( this, material );
12446
+
12447
+ material.color.copy( this.color );
12448
+
12449
+ material.linewidth = this.linewidth;
12450
+
12451
+ material.scale = this.scale;
12452
+ material.dashSize = this.dashSize;
12453
+ material.gapSize = this.gapSize;
12454
+
12455
+ material.vertexColors = this.vertexColors;
12456
+
12457
+ material.fog = this.fog;
12458
+
12459
+ return material;
12460
+
12461
+ };
12462
+
12463
+ // File:src/materials/MeshBasicMaterial.js
12464
+
12465
+ /**
12466
+ * @author mrdoob / http://mrdoob.com/
12467
+ * @author alteredq / http://alteredqualia.com/
12468
+ *
12469
+ * parameters = {
12470
+ * color: <hex>,
12471
+ * opacity: <float>,
12472
+ * map: new THREE.Texture( <Image> ),
12473
+ *
12474
+ * lightMap: new THREE.Texture( <Image> ),
12475
+ *
12476
+ * specularMap: new THREE.Texture( <Image> ),
12477
+ *
12478
+ * alphaMap: new THREE.Texture( <Image> ),
12479
+ *
12480
+ * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
12481
+ * combine: THREE.Multiply,
12482
+ * reflectivity: <float>,
12483
+ * refractionRatio: <float>,
12484
+ *
12485
+ * shading: THREE.SmoothShading,
12486
+ * blending: THREE.NormalBlending,
12487
+ * depthTest: <bool>,
12488
+ * depthWrite: <bool>,
12489
+ *
12490
+ * wireframe: <boolean>,
12491
+ * wireframeLinewidth: <float>,
12492
+ *
12493
+ * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
12494
+ *
12495
+ * skinning: <bool>,
12496
+ * morphTargets: <bool>,
12497
+ *
12498
+ * fog: <bool>
12499
+ * }
12500
+ */
12501
+
12502
+ THREE.MeshBasicMaterial = function ( parameters ) {
12503
+
12504
+ THREE.Material.call( this );
12505
+
12506
+ this.type = 'MeshBasicMaterial';
12507
+
12508
+ this.color = new THREE.Color( 0xffffff ); // emissive
12509
+
12510
+ this.map = null;
12511
+
12512
+ this.lightMap = null;
12513
+
12514
+ this.specularMap = null;
12515
+
12516
+ this.alphaMap = null;
12517
+
12518
+ this.envMap = null;
12519
+ this.combine = THREE.MultiplyOperation;
12520
+ this.reflectivity = 1;
12521
+ this.refractionRatio = 0.98;
12522
+
12523
+ this.fog = true;
12524
+
12525
+ this.shading = THREE.SmoothShading;
12526
+
12527
+ this.wireframe = false;
12528
+ this.wireframeLinewidth = 1;
12529
+ this.wireframeLinecap = 'round';
12530
+ this.wireframeLinejoin = 'round';
12531
+
12532
+ this.vertexColors = THREE.NoColors;
12533
+
12534
+ this.skinning = false;
12535
+ this.morphTargets = false;
12536
+
12537
+ this.setValues( parameters );
12538
+
12539
+ };
12540
+
12541
+ THREE.MeshBasicMaterial.prototype = Object.create( THREE.Material.prototype );
12542
+
12543
+ THREE.MeshBasicMaterial.prototype.clone = function () {
12544
+
12545
+ var material = new THREE.MeshBasicMaterial();
12546
+
12547
+ THREE.Material.prototype.clone.call( this, material );
12548
+
12549
+ material.color.copy( this.color );
12550
+
12551
+ material.map = this.map;
12552
+
12553
+ material.lightMap = this.lightMap;
12554
+
12555
+ material.specularMap = this.specularMap;
12556
+
12557
+ material.alphaMap = this.alphaMap;
12558
+
12559
+ material.envMap = this.envMap;
12560
+ material.combine = this.combine;
12561
+ material.reflectivity = this.reflectivity;
12562
+ material.refractionRatio = this.refractionRatio;
12563
+
12564
+ material.fog = this.fog;
12565
+
12566
+ material.shading = this.shading;
12567
+
12568
+ material.wireframe = this.wireframe;
12569
+ material.wireframeLinewidth = this.wireframeLinewidth;
12570
+ material.wireframeLinecap = this.wireframeLinecap;
12571
+ material.wireframeLinejoin = this.wireframeLinejoin;
12572
+
12573
+ material.vertexColors = this.vertexColors;
12574
+
12575
+ material.skinning = this.skinning;
12576
+ material.morphTargets = this.morphTargets;
12577
+
12578
+ return material;
12579
+
12580
+ };
12581
+
12582
+ // File:src/materials/MeshLambertMaterial.js
12583
+
12584
+ /**
12585
+ * @author mrdoob / http://mrdoob.com/
12586
+ * @author alteredq / http://alteredqualia.com/
12587
+ *
12588
+ * parameters = {
12589
+ * color: <hex>,
12590
+ * ambient: <hex>,
12591
+ * emissive: <hex>,
12592
+ * opacity: <float>,
12593
+ *
12594
+ * map: new THREE.Texture( <Image> ),
12595
+ *
12596
+ * lightMap: new THREE.Texture( <Image> ),
12597
+ *
12598
+ * specularMap: new THREE.Texture( <Image> ),
12599
+ *
12600
+ * alphaMap: new THREE.Texture( <Image> ),
12601
+ *
12602
+ * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
12603
+ * combine: THREE.Multiply,
12604
+ * reflectivity: <float>,
12605
+ * refractionRatio: <float>,
12606
+ *
12607
+ * shading: THREE.SmoothShading,
12608
+ * blending: THREE.NormalBlending,
12609
+ * depthTest: <bool>,
12610
+ * depthWrite: <bool>,
12611
+ *
12612
+ * wireframe: <boolean>,
12613
+ * wireframeLinewidth: <float>,
12614
+ *
12615
+ * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
12616
+ *
12617
+ * skinning: <bool>,
12618
+ * morphTargets: <bool>,
12619
+ * morphNormals: <bool>,
12620
+ *
12621
+ * fog: <bool>
12622
+ * }
12623
+ */
12624
+
12625
+ THREE.MeshLambertMaterial = function ( parameters ) {
12626
+
12627
+ THREE.Material.call( this );
12628
+
12629
+ this.type = 'MeshLambertMaterial';
12630
+
12631
+ this.color = new THREE.Color( 0xffffff ); // diffuse
12632
+ this.ambient = new THREE.Color( 0xffffff );
12633
+ this.emissive = new THREE.Color( 0x000000 );
12634
+
12635
+ this.wrapAround = false;
12636
+ this.wrapRGB = new THREE.Vector3( 1, 1, 1 );
12637
+
12638
+ this.map = null;
12639
+
12640
+ this.lightMap = null;
12641
+
12642
+ this.specularMap = null;
12643
+
12644
+ this.alphaMap = null;
12645
+
12646
+ this.envMap = null;
12647
+ this.combine = THREE.MultiplyOperation;
12648
+ this.reflectivity = 1;
12649
+ this.refractionRatio = 0.98;
12650
+
12651
+ this.fog = true;
12652
+
12653
+ this.shading = THREE.SmoothShading;
12654
+
12655
+ this.wireframe = false;
12656
+ this.wireframeLinewidth = 1;
12657
+ this.wireframeLinecap = 'round';
12658
+ this.wireframeLinejoin = 'round';
12659
+
12660
+ this.vertexColors = THREE.NoColors;
12661
+
12662
+ this.skinning = false;
12663
+ this.morphTargets = false;
12664
+ this.morphNormals = false;
12665
+
12666
+ this.setValues( parameters );
12667
+
12668
+ };
12669
+
12670
+ THREE.MeshLambertMaterial.prototype = Object.create( THREE.Material.prototype );
12671
+
12672
+ THREE.MeshLambertMaterial.prototype.clone = function () {
12673
+
12674
+ var material = new THREE.MeshLambertMaterial();
12675
+
12676
+ THREE.Material.prototype.clone.call( this, material );
12677
+
12678
+ material.color.copy( this.color );
12679
+ material.ambient.copy( this.ambient );
12680
+ material.emissive.copy( this.emissive );
12681
+
12682
+ material.wrapAround = this.wrapAround;
12683
+ material.wrapRGB.copy( this.wrapRGB );
12684
+
12685
+ material.map = this.map;
12686
+
12687
+ material.lightMap = this.lightMap;
12688
+
12689
+ material.specularMap = this.specularMap;
12690
+
12691
+ material.alphaMap = this.alphaMap;
12692
+
12693
+ material.envMap = this.envMap;
12694
+ material.combine = this.combine;
12695
+ material.reflectivity = this.reflectivity;
12696
+ material.refractionRatio = this.refractionRatio;
12697
+
12698
+ material.fog = this.fog;
12699
+
12700
+ material.shading = this.shading;
12701
+
12702
+ material.wireframe = this.wireframe;
12703
+ material.wireframeLinewidth = this.wireframeLinewidth;
12704
+ material.wireframeLinecap = this.wireframeLinecap;
12705
+ material.wireframeLinejoin = this.wireframeLinejoin;
12706
+
12707
+ material.vertexColors = this.vertexColors;
12708
+
12709
+ material.skinning = this.skinning;
12710
+ material.morphTargets = this.morphTargets;
12711
+ material.morphNormals = this.morphNormals;
12712
+
12713
+ return material;
12714
+
12715
+ };
12716
+
12717
+ // File:src/materials/MeshPhongMaterial.js
12718
+
12719
+ /**
12720
+ * @author mrdoob / http://mrdoob.com/
12721
+ * @author alteredq / http://alteredqualia.com/
12722
+ *
12723
+ * parameters = {
12724
+ * color: <hex>,
12725
+ * ambient: <hex>,
12726
+ * emissive: <hex>,
12727
+ * specular: <hex>,
12728
+ * shininess: <float>,
12729
+ * opacity: <float>,
12730
+ *
12731
+ * map: new THREE.Texture( <Image> ),
12732
+ *
12733
+ * lightMap: new THREE.Texture( <Image> ),
12734
+ *
12735
+ * bumpMap: new THREE.Texture( <Image> ),
12736
+ * bumpScale: <float>,
12737
+ *
12738
+ * normalMap: new THREE.Texture( <Image> ),
12739
+ * normalScale: <Vector2>,
12740
+ *
12741
+ * specularMap: new THREE.Texture( <Image> ),
12742
+ *
12743
+ * alphaMap: new THREE.Texture( <Image> ),
12744
+ *
12745
+ * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
12746
+ * combine: THREE.Multiply,
12747
+ * reflectivity: <float>,
12748
+ * refractionRatio: <float>,
12749
+ *
12750
+ * shading: THREE.SmoothShading,
12751
+ * blending: THREE.NormalBlending,
12752
+ * depthTest: <bool>,
12753
+ * depthWrite: <bool>,
12754
+ *
12755
+ * wireframe: <boolean>,
12756
+ * wireframeLinewidth: <float>,
12757
+ *
12758
+ * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
12759
+ *
12760
+ * skinning: <bool>,
12761
+ * morphTargets: <bool>,
12762
+ * morphNormals: <bool>,
12763
+ *
12764
+ * fog: <bool>
12765
+ * }
12766
+ */
12767
+
12768
+ THREE.MeshPhongMaterial = function ( parameters ) {
12769
+
12770
+ THREE.Material.call( this );
12771
+
12772
+ this.type = 'MeshPhongMaterial';
12773
+
12774
+ this.color = new THREE.Color( 0xffffff ); // diffuse
12775
+ this.ambient = new THREE.Color( 0xffffff );
12776
+ this.emissive = new THREE.Color( 0x000000 );
12777
+ this.specular = new THREE.Color( 0x111111 );
12778
+ this.shininess = 30;
12779
+
12780
+ this.metal = false;
12781
+
12782
+ this.wrapAround = false;
12783
+ this.wrapRGB = new THREE.Vector3( 1, 1, 1 );
12784
+
12785
+ this.map = null;
12786
+
12787
+ this.lightMap = null;
12788
+
12789
+ this.bumpMap = null;
12790
+ this.bumpScale = 1;
12791
+
12792
+ this.normalMap = null;
12793
+ this.normalScale = new THREE.Vector2( 1, 1 );
12794
+
12795
+ this.specularMap = null;
12796
+
12797
+ this.alphaMap = null;
12798
+
12799
+ this.envMap = null;
12800
+ this.combine = THREE.MultiplyOperation;
12801
+ this.reflectivity = 1;
12802
+ this.refractionRatio = 0.98;
12803
+
12804
+ this.fog = true;
12805
+
12806
+ this.shading = THREE.SmoothShading;
12807
+
12808
+ this.wireframe = false;
12809
+ this.wireframeLinewidth = 1;
12810
+ this.wireframeLinecap = 'round';
12811
+ this.wireframeLinejoin = 'round';
12812
+
12813
+ this.vertexColors = THREE.NoColors;
12814
+
12815
+ this.skinning = false;
12816
+ this.morphTargets = false;
12817
+ this.morphNormals = false;
12818
+
12819
+ this.setValues( parameters );
12820
+
12821
+ };
12822
+
12823
+ THREE.MeshPhongMaterial.prototype = Object.create( THREE.Material.prototype );
12824
+
12825
+ THREE.MeshPhongMaterial.prototype.clone = function () {
12826
+
12827
+ var material = new THREE.MeshPhongMaterial();
12828
+
12829
+ THREE.Material.prototype.clone.call( this, material );
12830
+
12831
+ material.color.copy( this.color );
12832
+ material.ambient.copy( this.ambient );
12833
+ material.emissive.copy( this.emissive );
12834
+ material.specular.copy( this.specular );
12835
+ material.shininess = this.shininess;
12836
+
12837
+ material.metal = this.metal;
12838
+
12839
+ material.wrapAround = this.wrapAround;
12840
+ material.wrapRGB.copy( this.wrapRGB );
12841
+
12842
+ material.map = this.map;
12843
+
12844
+ material.lightMap = this.lightMap;
12845
+
12846
+ material.bumpMap = this.bumpMap;
12847
+ material.bumpScale = this.bumpScale;
12848
+
12849
+ material.normalMap = this.normalMap;
12850
+ material.normalScale.copy( this.normalScale );
12851
+
12852
+ material.specularMap = this.specularMap;
12853
+
12854
+ material.alphaMap = this.alphaMap;
12855
+
12856
+ material.envMap = this.envMap;
12857
+ material.combine = this.combine;
12858
+ material.reflectivity = this.reflectivity;
12859
+ material.refractionRatio = this.refractionRatio;
12860
+
12861
+ material.fog = this.fog;
12862
+
12863
+ material.shading = this.shading;
12864
+
12865
+ material.wireframe = this.wireframe;
12866
+ material.wireframeLinewidth = this.wireframeLinewidth;
12867
+ material.wireframeLinecap = this.wireframeLinecap;
12868
+ material.wireframeLinejoin = this.wireframeLinejoin;
12869
+
12870
+ material.vertexColors = this.vertexColors;
12871
+
12872
+ material.skinning = this.skinning;
12873
+ material.morphTargets = this.morphTargets;
12874
+ material.morphNormals = this.morphNormals;
12875
+
12876
+ return material;
12877
+
12878
+ };
12879
+
12880
+ // File:src/materials/MeshDepthMaterial.js
12881
+
12882
+ /**
12883
+ * @author mrdoob / http://mrdoob.com/
12884
+ * @author alteredq / http://alteredqualia.com/
12885
+ *
12886
+ * parameters = {
12887
+ * opacity: <float>,
12888
+ *
12889
+ * blending: THREE.NormalBlending,
12890
+ * depthTest: <bool>,
12891
+ * depthWrite: <bool>,
12892
+ *
12893
+ * wireframe: <boolean>,
12894
+ * wireframeLinewidth: <float>
12895
+ * }
12896
+ */
12897
+
12898
+ THREE.MeshDepthMaterial = function ( parameters ) {
12899
+
12900
+ THREE.Material.call( this );
12901
+
12902
+ this.type = 'MeshDepthMaterial';
12903
+
12904
+ this.morphTargets = false;
12905
+ this.wireframe = false;
12906
+ this.wireframeLinewidth = 1;
12907
+
12908
+ this.setValues( parameters );
12909
+
12910
+ };
12911
+
12912
+ THREE.MeshDepthMaterial.prototype = Object.create( THREE.Material.prototype );
12913
+
12914
+ THREE.MeshDepthMaterial.prototype.clone = function () {
12915
+
12916
+ var material = new THREE.MeshDepthMaterial();
12917
+
12918
+ THREE.Material.prototype.clone.call( this, material );
12919
+
12920
+ material.wireframe = this.wireframe;
12921
+ material.wireframeLinewidth = this.wireframeLinewidth;
12922
+
12923
+ return material;
12924
+
12925
+ };
12926
+
12927
+ // File:src/materials/MeshNormalMaterial.js
12928
+
12929
+ /**
12930
+ * @author mrdoob / http://mrdoob.com/
12931
+ *
12932
+ * parameters = {
12933
+ * opacity: <float>,
12934
+ *
12935
+ * shading: THREE.FlatShading,
12936
+ * blending: THREE.NormalBlending,
12937
+ * depthTest: <bool>,
12938
+ * depthWrite: <bool>,
12939
+ *
12940
+ * wireframe: <boolean>,
12941
+ * wireframeLinewidth: <float>
12942
+ * }
12943
+ */
12944
+
12945
+ THREE.MeshNormalMaterial = function ( parameters ) {
12946
+
12947
+ THREE.Material.call( this, parameters );
12948
+
12949
+ this.type = 'MeshNormalMaterial';
12950
+
12951
+ this.shading = THREE.FlatShading;
12952
+
12953
+ this.wireframe = false;
12954
+ this.wireframeLinewidth = 1;
12955
+
12956
+ this.morphTargets = false;
12957
+
12958
+ this.setValues( parameters );
12959
+
12960
+ };
12961
+
12962
+ THREE.MeshNormalMaterial.prototype = Object.create( THREE.Material.prototype );
12963
+
12964
+ THREE.MeshNormalMaterial.prototype.clone = function () {
12965
+
12966
+ var material = new THREE.MeshNormalMaterial();
12967
+
12968
+ THREE.Material.prototype.clone.call( this, material );
12969
+
12970
+ material.shading = this.shading;
12971
+
12972
+ material.wireframe = this.wireframe;
12973
+ material.wireframeLinewidth = this.wireframeLinewidth;
12974
+
12975
+ return material;
12976
+
12977
+ };
12978
+
12979
+ // File:src/materials/MeshFaceMaterial.js
12980
+
12981
+ /**
12982
+ * @author mrdoob / http://mrdoob.com/
12983
+ */
12984
+
12985
+ THREE.MeshFaceMaterial = function ( materials ) {
12986
+
12987
+ this.uuid = THREE.Math.generateUUID();
12988
+
12989
+ this.type = 'MeshFaceMaterial';
12990
+
12991
+ this.materials = materials instanceof Array ? materials : [];
12992
+
12993
+ };
12994
+
12995
+ THREE.MeshFaceMaterial.prototype = {
12996
+
12997
+ constructor: THREE.MeshFaceMaterial,
12998
+
12999
+ toJSON: function () {
13000
+
13001
+ var output = {
13002
+ metadata: {
13003
+ version: 4.2,
13004
+ type: 'material',
13005
+ generator: 'MaterialExporter'
13006
+ },
13007
+ uuid: this.uuid,
13008
+ type: this.type,
13009
+ materials: []
13010
+ };
13011
+
13012
+ for ( var i = 0, l = this.materials.length; i < l; i ++ ) {
13013
+
13014
+ output.materials.push( this.materials[ i ].toJSON() );
13015
+
13016
+ }
13017
+
13018
+ return output;
13019
+
13020
+ },
13021
+
13022
+ clone: function () {
13023
+
13024
+ var material = new THREE.MeshFaceMaterial();
13025
+
13026
+ for ( var i = 0; i < this.materials.length; i ++ ) {
13027
+
13028
+ material.materials.push( this.materials[ i ].clone() );
13029
+
13030
+ }
13031
+
13032
+ return material;
13033
+
13034
+ }
13035
+
13036
+ };
13037
+
13038
+ // File:src/materials/PointCloudMaterial.js
13039
+
13040
+ /**
13041
+ * @author mrdoob / http://mrdoob.com/
13042
+ * @author alteredq / http://alteredqualia.com/
13043
+ *
13044
+ * parameters = {
13045
+ * color: <hex>,
13046
+ * opacity: <float>,
13047
+ * map: new THREE.Texture( <Image> ),
13048
+ *
13049
+ * size: <float>,
13050
+ *
13051
+ * blending: THREE.NormalBlending,
13052
+ * depthTest: <bool>,
13053
+ * depthWrite: <bool>,
13054
+ *
13055
+ * vertexColors: <bool>,
13056
+ *
13057
+ * fog: <bool>
13058
+ * }
13059
+ */
13060
+
13061
+ THREE.PointCloudMaterial = function ( parameters ) {
13062
+
13063
+ THREE.Material.call( this );
13064
+
13065
+ this.type = 'PointCloudMaterial';
13066
+
13067
+ this.color = new THREE.Color( 0xffffff );
13068
+
13069
+ this.map = null;
13070
+
13071
+ this.size = 1;
13072
+ this.sizeAttenuation = true;
13073
+
13074
+ this.vertexColors = THREE.NoColors;
13075
+
13076
+ this.fog = true;
13077
+
13078
+ this.setValues( parameters );
13079
+
13080
+ };
13081
+
13082
+ THREE.PointCloudMaterial.prototype = Object.create( THREE.Material.prototype );
13083
+
13084
+ THREE.PointCloudMaterial.prototype.clone = function () {
13085
+
13086
+ var material = new THREE.PointCloudMaterial();
13087
+
13088
+ THREE.Material.prototype.clone.call( this, material );
13089
+
13090
+ material.color.copy( this.color );
13091
+
13092
+ material.map = this.map;
13093
+
13094
+ material.size = this.size;
13095
+ material.sizeAttenuation = this.sizeAttenuation;
13096
+
13097
+ material.vertexColors = this.vertexColors;
13098
+
13099
+ material.fog = this.fog;
13100
+
13101
+ return material;
13102
+
13103
+ };
13104
+
13105
+ // backwards compatibility
13106
+
13107
+ THREE.ParticleBasicMaterial = function ( parameters ) {
13108
+
13109
+ console.warn( 'THREE.ParticleBasicMaterial has been renamed to THREE.PointCloudMaterial.' );
13110
+ return new THREE.PointCloudMaterial( parameters );
13111
+
13112
+ };
13113
+
13114
+ THREE.ParticleSystemMaterial = function ( parameters ) {
13115
+
13116
+ console.warn( 'THREE.ParticleSystemMaterial has been renamed to THREE.PointCloudMaterial.' );
13117
+ return new THREE.PointCloudMaterial( parameters );
13118
+
13119
+ };
13120
+
13121
+ // File:src/materials/ShaderMaterial.js
13122
+
13123
+ /**
13124
+ * @author alteredq / http://alteredqualia.com/
13125
+ *
13126
+ * parameters = {
13127
+ * defines: { "label" : "value" },
13128
+ * uniforms: { "parameter1": { type: "f", value: 1.0 }, "parameter2": { type: "i" value2: 2 } },
13129
+ *
13130
+ * fragmentShader: <string>,
13131
+ * vertexShader: <string>,
13132
+ *
13133
+ * shading: THREE.SmoothShading,
13134
+ * blending: THREE.NormalBlending,
13135
+ * depthTest: <bool>,
13136
+ * depthWrite: <bool>,
13137
+ *
13138
+ * wireframe: <boolean>,
13139
+ * wireframeLinewidth: <float>,
13140
+ *
13141
+ * lights: <bool>,
13142
+ *
13143
+ * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
13144
+ *
13145
+ * skinning: <bool>,
13146
+ * morphTargets: <bool>,
13147
+ * morphNormals: <bool>,
13148
+ *
13149
+ * fog: <bool>
13150
+ * }
13151
+ */
13152
+
13153
+ THREE.ShaderMaterial = function ( parameters ) {
13154
+
13155
+ THREE.Material.call( this );
13156
+
13157
+ this.type = 'ShaderMaterial';
13158
+
13159
+ this.defines = {};
13160
+ this.uniforms = {};
13161
+ this.attributes = null;
13162
+
13163
+ this.vertexShader = 'void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}';
13164
+ this.fragmentShader = 'void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}';
13165
+
13166
+ this.shading = THREE.SmoothShading;
13167
+
13168
+ this.linewidth = 1;
13169
+
13170
+ this.wireframe = false;
13171
+ this.wireframeLinewidth = 1;
13172
+
13173
+ this.fog = false; // set to use scene fog
13174
+
13175
+ this.lights = false; // set to use scene lights
13176
+
13177
+ this.vertexColors = THREE.NoColors; // set to use "color" attribute stream
13178
+
13179
+ this.skinning = false; // set to use skinning attribute streams
13180
+
13181
+ this.morphTargets = false; // set to use morph targets
13182
+ this.morphNormals = false; // set to use morph normals
13183
+
13184
+ // When rendered geometry doesn't include these attributes but the material does,
13185
+ // use these default values in WebGL. This avoids errors when buffer data is missing.
13186
+ this.defaultAttributeValues = {
13187
+ 'color': [ 1, 1, 1 ],
13188
+ 'uv': [ 0, 0 ],
13189
+ 'uv2': [ 0, 0 ]
13190
+ };
13191
+
13192
+ this.index0AttributeName = undefined;
13193
+
13194
+ this.setValues( parameters );
13195
+
13196
+ };
13197
+
13198
+ THREE.ShaderMaterial.prototype = Object.create( THREE.Material.prototype );
13199
+
13200
+ THREE.ShaderMaterial.prototype.clone = function () {
13201
+
13202
+ var material = new THREE.ShaderMaterial();
13203
+
13204
+ THREE.Material.prototype.clone.call( this, material );
13205
+
13206
+ material.fragmentShader = this.fragmentShader;
13207
+ material.vertexShader = this.vertexShader;
13208
+
13209
+ material.uniforms = THREE.UniformsUtils.clone( this.uniforms );
13210
+
13211
+ material.attributes = this.attributes;
13212
+ material.defines = this.defines;
13213
+
13214
+ material.shading = this.shading;
13215
+
13216
+ material.wireframe = this.wireframe;
13217
+ material.wireframeLinewidth = this.wireframeLinewidth;
13218
+
13219
+ material.fog = this.fog;
13220
+
13221
+ material.lights = this.lights;
13222
+
13223
+ material.vertexColors = this.vertexColors;
13224
+
13225
+ material.skinning = this.skinning;
13226
+
13227
+ material.morphTargets = this.morphTargets;
13228
+ material.morphNormals = this.morphNormals;
13229
+
13230
+ return material;
13231
+
13232
+ };
13233
+
13234
+ // File:src/materials/RawShaderMaterial.js
13235
+
13236
+ /**
13237
+ * @author mrdoob / http://mrdoob.com/
13238
+ */
13239
+
13240
+ THREE.RawShaderMaterial = function ( parameters ) {
13241
+
13242
+ THREE.ShaderMaterial.call( this, parameters );
13243
+
13244
+ this.type = 'RawShaderMaterial';
13245
+
13246
+ };
13247
+
13248
+ THREE.RawShaderMaterial.prototype = Object.create( THREE.ShaderMaterial.prototype );
13249
+
13250
+ THREE.RawShaderMaterial.prototype.clone = function () {
13251
+
13252
+ var material = new THREE.RawShaderMaterial();
13253
+
13254
+ THREE.ShaderMaterial.prototype.clone.call( this, material );
13255
+
13256
+ return material;
13257
+
13258
+ };
13259
+
13260
+ // File:src/materials/SpriteMaterial.js
13261
+
13262
+ /**
13263
+ * @author alteredq / http://alteredqualia.com/
13264
+ *
13265
+ * parameters = {
13266
+ * color: <hex>,
13267
+ * opacity: <float>,
13268
+ * map: new THREE.Texture( <Image> ),
13269
+ *
13270
+ * blending: THREE.NormalBlending,
13271
+ * depthTest: <bool>,
13272
+ * depthWrite: <bool>,
13273
+ *
13274
+ * uvOffset: new THREE.Vector2(),
13275
+ * uvScale: new THREE.Vector2(),
13276
+ *
13277
+ * fog: <bool>
13278
+ * }
13279
+ */
13280
+
13281
+ THREE.SpriteMaterial = function ( parameters ) {
13282
+
13283
+ THREE.Material.call( this );
13284
+
13285
+ this.type = 'SpriteMaterial';
13286
+
13287
+ this.color = new THREE.Color( 0xffffff );
13288
+ this.map = null;
13289
+
13290
+ this.rotation = 0;
13291
+
13292
+ this.fog = false;
13293
+
13294
+ // set parameters
13295
+
13296
+ this.setValues( parameters );
13297
+
13298
+ };
13299
+
13300
+ THREE.SpriteMaterial.prototype = Object.create( THREE.Material.prototype );
13301
+
13302
+ THREE.SpriteMaterial.prototype.clone = function () {
13303
+
13304
+ var material = new THREE.SpriteMaterial();
13305
+
13306
+ THREE.Material.prototype.clone.call( this, material );
13307
+
13308
+ material.color.copy( this.color );
13309
+ material.map = this.map;
13310
+
13311
+ material.rotation = this.rotation;
13312
+
13313
+ material.fog = this.fog;
13314
+
13315
+ return material;
13316
+
13317
+ };
13318
+
13319
+ // File:src/textures/Texture.js
13320
+
13321
+ /**
13322
+ * @author mrdoob / http://mrdoob.com/
13323
+ * @author alteredq / http://alteredqualia.com/
13324
+ * @author szimek / https://github.com/szimek/
13325
+ */
13326
+
13327
+ THREE.Texture = function ( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
13328
+
13329
+ Object.defineProperty( this, 'id', { value: THREE.TextureIdCount ++ } );
13330
+
13331
+ this.uuid = THREE.Math.generateUUID();
13332
+
13333
+ this.name = '';
13334
+
13335
+ this.image = image !== undefined ? image : THREE.Texture.DEFAULT_IMAGE;
13336
+ this.mipmaps = [];
13337
+
13338
+ this.mapping = mapping !== undefined ? mapping : THREE.Texture.DEFAULT_MAPPING;
13339
+
13340
+ this.wrapS = wrapS !== undefined ? wrapS : THREE.ClampToEdgeWrapping;
13341
+ this.wrapT = wrapT !== undefined ? wrapT : THREE.ClampToEdgeWrapping;
13342
+
13343
+ this.magFilter = magFilter !== undefined ? magFilter : THREE.LinearFilter;
13344
+ this.minFilter = minFilter !== undefined ? minFilter : THREE.LinearMipMapLinearFilter;
13345
+
13346
+ this.anisotropy = anisotropy !== undefined ? anisotropy : 1;
13347
+
13348
+ this.format = format !== undefined ? format : THREE.RGBAFormat;
13349
+ this.type = type !== undefined ? type : THREE.UnsignedByteType;
13350
+
13351
+ this.offset = new THREE.Vector2( 0, 0 );
13352
+ this.repeat = new THREE.Vector2( 1, 1 );
13353
+
13354
+ this.generateMipmaps = true;
13355
+ this.premultiplyAlpha = false;
13356
+ this.flipY = true;
13357
+ this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
13358
+
13359
+ this._needsUpdate = false;
13360
+ this.onUpdate = null;
13361
+
13362
+ };
13363
+
13364
+ THREE.Texture.DEFAULT_IMAGE = undefined;
13365
+ THREE.Texture.DEFAULT_MAPPING = new THREE.UVMapping();
13366
+
13367
+ THREE.Texture.prototype = {
13368
+
13369
+ constructor: THREE.Texture,
13370
+
13371
+ get needsUpdate () {
13372
+
13373
+ return this._needsUpdate;
13374
+
13375
+ },
13376
+
13377
+ set needsUpdate ( value ) {
13378
+
13379
+ if ( value === true ) this.update();
13380
+
13381
+ this._needsUpdate = value;
13382
+
13383
+ },
13384
+
13385
+ clone: function ( texture ) {
13386
+
13387
+ if ( texture === undefined ) texture = new THREE.Texture();
13388
+
13389
+ texture.image = this.image;
13390
+ texture.mipmaps = this.mipmaps.slice( 0 );
13391
+
13392
+ texture.mapping = this.mapping;
13393
+
13394
+ texture.wrapS = this.wrapS;
13395
+ texture.wrapT = this.wrapT;
13396
+
13397
+ texture.magFilter = this.magFilter;
13398
+ texture.minFilter = this.minFilter;
13399
+
13400
+ texture.anisotropy = this.anisotropy;
13401
+
13402
+ texture.format = this.format;
13403
+ texture.type = this.type;
13404
+
13405
+ texture.offset.copy( this.offset );
13406
+ texture.repeat.copy( this.repeat );
13407
+
13408
+ texture.generateMipmaps = this.generateMipmaps;
13409
+ texture.premultiplyAlpha = this.premultiplyAlpha;
13410
+ texture.flipY = this.flipY;
13411
+ texture.unpackAlignment = this.unpackAlignment;
13412
+
13413
+ return texture;
13414
+
13415
+ },
13416
+
13417
+ update: function () {
13418
+
13419
+ this.dispatchEvent( { type: 'update' } );
13420
+
13421
+ },
13422
+
13423
+ dispose: function () {
13424
+
13425
+ this.dispatchEvent( { type: 'dispose' } );
13426
+
13427
+ }
13428
+
13429
+ };
13430
+
13431
+ THREE.EventDispatcher.prototype.apply( THREE.Texture.prototype );
13432
+
13433
+ THREE.TextureIdCount = 0;
13434
+
13435
+ // File:src/textures/CubeTexture.js
13436
+
13437
+ /**
13438
+ * @author mrdoob / http://mrdoob.com/
13439
+ */
13440
+
13441
+ THREE.CubeTexture = function ( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
13442
+
13443
+ THREE.Texture.call( this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
13444
+
13445
+ this.images = images;
13446
+
13447
+ };
13448
+
13449
+ THREE.CubeTexture.prototype = Object.create( THREE.Texture.prototype );
13450
+
13451
+ THREE.CubeTexture.clone = function ( texture ) {
13452
+
13453
+ if ( texture === undefined ) texture = new THREE.CubeTexture();
13454
+
13455
+ THREE.Texture.prototype.clone.call( this, texture );
13456
+
13457
+ texture.images = this.images;
13458
+
13459
+ return texture;
13460
+
13461
+ };
13462
+
13463
+ // File:src/textures/CompressedTexture.js
13464
+
13465
+ /**
13466
+ * @author alteredq / http://alteredqualia.com/
13467
+ */
13468
+
13469
+ THREE.CompressedTexture = function ( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy ) {
13470
+
13471
+ THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
13472
+
13473
+ this.image = { width: width, height: height };
13474
+ this.mipmaps = mipmaps;
13475
+
13476
+ // no flipping for cube textures
13477
+ // (also flipping doesn't work for compressed textures )
13478
+
13479
+ this.flipY = false;
13480
+
13481
+ // can't generate mipmaps for compressed textures
13482
+ // mips must be embedded in DDS files
13483
+
13484
+ this.generateMipmaps = false;
13485
+
13486
+ };
13487
+
13488
+ THREE.CompressedTexture.prototype = Object.create( THREE.Texture.prototype );
13489
+
13490
+ THREE.CompressedTexture.prototype.clone = function () {
13491
+
13492
+ var texture = new THREE.CompressedTexture();
13493
+
13494
+ THREE.Texture.prototype.clone.call( this, texture );
13495
+
13496
+ return texture;
13497
+
13498
+ };
13499
+
13500
+ // File:src/textures/DataTexture.js
13501
+
13502
+ /**
13503
+ * @author alteredq / http://alteredqualia.com/
13504
+ */
13505
+
13506
+ THREE.DataTexture = function ( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy ) {
13507
+
13508
+ THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
13509
+
13510
+ this.image = { data: data, width: width, height: height };
13511
+
13512
+ };
13513
+
13514
+ THREE.DataTexture.prototype = Object.create( THREE.Texture.prototype );
13515
+
13516
+ THREE.DataTexture.prototype.clone = function () {
13517
+
13518
+ var texture = new THREE.DataTexture();
13519
+
13520
+ THREE.Texture.prototype.clone.call( this, texture );
13521
+
13522
+ return texture;
13523
+
13524
+ };
13525
+
13526
+ // File:src/textures/VideoTexture.js
13527
+
13528
+ /**
13529
+ * @author mrdoob / http://mrdoob.com/
13530
+ */
13531
+
13532
+ THREE.VideoTexture = function ( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
13533
+
13534
+ THREE.Texture.call( this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
13535
+
13536
+ this.generateMipmaps = false;
13537
+
13538
+ var scope = this;
13539
+
13540
+ var update = function () {
13541
+
13542
+ requestAnimationFrame( update );
13543
+
13544
+ if ( video.readyState === video.HAVE_ENOUGH_DATA ) {
13545
+
13546
+ scope.needsUpdate = true;
13547
+
13548
+ }
13549
+
13550
+ };
13551
+
13552
+ update();
13553
+
13554
+ };
13555
+
13556
+ THREE.VideoTexture.prototype = Object.create( THREE.Texture.prototype );
13557
+
13558
+ // File:src/objects/Group.js
13559
+
13560
+ /**
13561
+ * @author mrdoob / http://mrdoob.com/
13562
+ */
13563
+
13564
+ THREE.Group = function () {
13565
+
13566
+ THREE.Object3D.call( this );
13567
+
13568
+ this.type = 'Group';
13569
+
13570
+ };
13571
+
13572
+ THREE.Group.prototype = Object.create( THREE.Object3D.prototype );
13573
+
13574
+ // File:src/objects/PointCloud.js
13575
+
13576
+ /**
13577
+ * @author alteredq / http://alteredqualia.com/
13578
+ */
13579
+
13580
+ THREE.PointCloud = function ( geometry, material ) {
13581
+
13582
+ THREE.Object3D.call( this );
13583
+
13584
+ this.type = 'PointCloud';
13585
+
13586
+ this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
13587
+ this.material = material !== undefined ? material : new THREE.PointCloudMaterial( { color: Math.random() * 0xffffff } );
13588
+
13589
+ this.sortParticles = false;
13590
+
13591
+ };
13592
+
13593
+ THREE.PointCloud.prototype = Object.create( THREE.Object3D.prototype );
13594
+
13595
+ THREE.PointCloud.prototype.raycast = ( function () {
13596
+
13597
+ var inverseMatrix = new THREE.Matrix4();
13598
+ var ray = new THREE.Ray();
13599
+
13600
+ return function ( raycaster, intersects ) {
13601
+
13602
+ var object = this;
13603
+ var geometry = object.geometry;
13604
+ var threshold = raycaster.params.PointCloud.threshold;
13605
+
13606
+ inverseMatrix.getInverse( this.matrixWorld );
13607
+ ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
13608
+
13609
+ if ( geometry.boundingBox !== null ) {
13610
+
13611
+ if ( ray.isIntersectionBox( geometry.boundingBox ) === false ) {
13612
+
13613
+ return;
13614
+
13615
+ }
13616
+
13617
+ }
13618
+
13619
+ var localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
13620
+ var position = new THREE.Vector3();
13621
+
13622
+ var testPoint = function ( point, index ) {
13623
+
13624
+ var rayPointDistance = ray.distanceToPoint( point );
13625
+
13626
+ if ( rayPointDistance < localThreshold ) {
13627
+
13628
+ var intersectPoint = ray.closestPointToPoint( point );
13629
+ intersectPoint.applyMatrix4( object.matrixWorld );
13630
+
13631
+ var distance = raycaster.ray.origin.distanceTo( intersectPoint );
13632
+
13633
+ intersects.push( {
13634
+
13635
+ distance: distance,
13636
+ distanceToRay: rayPointDistance,
13637
+ point: intersectPoint.clone(),
13638
+ index: index,
13639
+ face: null,
13640
+ object: object
13641
+
13642
+ } );
13643
+
13644
+ }
13645
+
13646
+ };
13647
+
13648
+ if ( geometry instanceof THREE.BufferGeometry ) {
13649
+
13650
+ var attributes = geometry.attributes;
13651
+ var positions = attributes.position.array;
13652
+
13653
+ if ( attributes.index !== undefined ) {
13654
+
13655
+ var indices = attributes.index.array;
13656
+ var offsets = geometry.offsets;
13657
+
13658
+ if ( offsets.length === 0 ) {
13659
+
13660
+ var offset = {
13661
+ start: 0,
13662
+ count: indices.length,
13663
+ index: 0
13664
+ };
13665
+
13666
+ offsets = [ offset ];
13667
+
13668
+ }
13669
+
13670
+ for ( var oi = 0, ol = offsets.length; oi < ol; ++oi ) {
13671
+
13672
+ var start = offsets[ oi ].start;
13673
+ var count = offsets[ oi ].count;
13674
+ var index = offsets[ oi ].index;
13675
+
13676
+ for ( var i = start, il = start + count; i < il; i ++ ) {
13677
+
13678
+ var a = index + indices[ i ];
13679
+
13680
+ position.fromArray( positions, a * 3 );
13681
+
13682
+ testPoint( position, a );
13683
+
13684
+ }
13685
+
13686
+ }
13687
+
13688
+ } else {
13689
+
13690
+ var pointCount = positions.length / 3;
13691
+
13692
+ for ( var i = 0; i < pointCount; i ++ ) {
13693
+
13694
+ position.set(
13695
+ positions[ 3 * i ],
13696
+ positions[ 3 * i + 1 ],
13697
+ positions[ 3 * i + 2 ]
13698
+ );
13699
+
13700
+ testPoint( position, i );
13701
+
13702
+ }
13703
+
13704
+ }
13705
+
13706
+ } else {
13707
+
13708
+ var vertices = this.geometry.vertices;
13709
+
13710
+ for ( var i = 0; i < vertices.length; i ++ ) {
13711
+
13712
+ testPoint( vertices[ i ], i );
13713
+
13714
+ }
13715
+
13716
+ }
13717
+
13718
+ };
13719
+
13720
+ }() );
13721
+
13722
+ THREE.PointCloud.prototype.clone = function ( object ) {
13723
+
13724
+ if ( object === undefined ) object = new THREE.PointCloud( this.geometry, this.material );
13725
+
13726
+ object.sortParticles = this.sortParticles;
13727
+
13728
+ THREE.Object3D.prototype.clone.call( this, object );
13729
+
13730
+ return object;
13731
+
13732
+ };
13733
+
13734
+ // Backwards compatibility
13735
+
13736
+ THREE.ParticleSystem = function ( geometry, material ) {
13737
+
13738
+ console.warn( 'THREE.ParticleSystem has been renamed to THREE.PointCloud.' );
13739
+ return new THREE.PointCloud( geometry, material );
13740
+
13741
+ };
13742
+
13743
+ // File:src/objects/Line.js
13744
+
13745
+ /**
13746
+ * @author mrdoob / http://mrdoob.com/
13747
+ */
13748
+
13749
+ THREE.Line = function ( geometry, material, mode ) {
13750
+
13751
+ THREE.Object3D.call( this );
13752
+
13753
+ this.type = 'Line';
13754
+
13755
+ this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
13756
+ this.material = material !== undefined ? material : new THREE.LineBasicMaterial( { color: Math.random() * 0xffffff } );
13757
+
13758
+ this.mode = ( mode !== undefined ) ? mode : THREE.LineStrip;
13759
+
13760
+ };
13761
+
13762
+ THREE.LineStrip = 0;
13763
+ THREE.LinePieces = 1;
13764
+
13765
+ THREE.Line.prototype = Object.create( THREE.Object3D.prototype );
13766
+
13767
+ THREE.Line.prototype.raycast = ( function () {
13768
+
13769
+ var inverseMatrix = new THREE.Matrix4();
13770
+ var ray = new THREE.Ray();
13771
+ var sphere = new THREE.Sphere();
13772
+
13773
+ return function ( raycaster, intersects ) {
13774
+
13775
+ var precision = raycaster.linePrecision;
13776
+ var precisionSq = precision * precision;
13777
+
13778
+ var geometry = this.geometry;
13779
+
13780
+ if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
13781
+
13782
+ // Checking boundingSphere distance to ray
13783
+
13784
+ sphere.copy( geometry.boundingSphere );
13785
+ sphere.applyMatrix4( this.matrixWorld );
13786
+
13787
+ if ( raycaster.ray.isIntersectionSphere( sphere ) === false ) {
13788
+
13789
+ return;
13790
+
13791
+ }
13792
+
13793
+ inverseMatrix.getInverse( this.matrixWorld );
13794
+ ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
13795
+
13796
+ /* if ( geometry instanceof THREE.BufferGeometry ) {
13797
+
13798
+ } else */ if ( geometry instanceof THREE.Geometry ) {
13799
+
13800
+ var vertices = geometry.vertices;
13801
+ var nbVertices = vertices.length;
13802
+ var interSegment = new THREE.Vector3();
13803
+ var interRay = new THREE.Vector3();
13804
+ var step = this.mode === THREE.LineStrip ? 1 : 2;
13805
+
13806
+ for ( var i = 0; i < nbVertices - 1; i = i + step ) {
13807
+
13808
+ var distSq = ray.distanceSqToSegment( vertices[ i ], vertices[ i + 1 ], interRay, interSegment );
13809
+
13810
+ if ( distSq > precisionSq ) continue;
13811
+
13812
+ var distance = ray.origin.distanceTo( interRay );
13813
+
13814
+ if ( distance < raycaster.near || distance > raycaster.far ) continue;
13815
+
13816
+ intersects.push( {
13817
+
13818
+ distance: distance,
13819
+ // What do we want? intersection point on the ray or on the segment??
13820
+ // point: raycaster.ray.at( distance ),
13821
+ point: interSegment.clone().applyMatrix4( this.matrixWorld ),
13822
+ face: null,
13823
+ faceIndex: null,
13824
+ object: this
13825
+
13826
+ } );
13827
+
13828
+ }
13829
+
13830
+ }
13831
+
13832
+ };
13833
+
13834
+ }() );
13835
+
13836
+ THREE.Line.prototype.clone = function ( object ) {
13837
+
13838
+ if ( object === undefined ) object = new THREE.Line( this.geometry, this.material, this.mode );
13839
+
13840
+ THREE.Object3D.prototype.clone.call( this, object );
13841
+
13842
+ return object;
13843
+
13844
+ };
13845
+
13846
+ // File:src/objects/Mesh.js
13847
+
13848
+ /**
13849
+ * @author mrdoob / http://mrdoob.com/
13850
+ * @author alteredq / http://alteredqualia.com/
13851
+ * @author mikael emtinger / http://gomo.se/
13852
+ * @author jonobr1 / http://jonobr1.com/
13853
+ */
13854
+
13855
+ THREE.Mesh = function ( geometry, material ) {
13856
+
13857
+ THREE.Object3D.call( this );
13858
+
13859
+ this.type = 'Mesh';
13860
+
13861
+ this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
13862
+ this.material = material !== undefined ? material : new THREE.MeshBasicMaterial( { color: Math.random() * 0xffffff } );
13863
+
13864
+ this.updateMorphTargets();
13865
+
13866
+ };
13867
+
13868
+ THREE.Mesh.prototype = Object.create( THREE.Object3D.prototype );
13869
+
13870
+ THREE.Mesh.prototype.updateMorphTargets = function () {
13871
+
13872
+ if ( this.geometry.morphTargets !== undefined && this.geometry.morphTargets.length > 0 ) {
13873
+
13874
+ this.morphTargetBase = - 1;
13875
+ this.morphTargetForcedOrder = [];
13876
+ this.morphTargetInfluences = [];
13877
+ this.morphTargetDictionary = {};
13878
+
13879
+ for ( var m = 0, ml = this.geometry.morphTargets.length; m < ml; m ++ ) {
13880
+
13881
+ this.morphTargetInfluences.push( 0 );
13882
+ this.morphTargetDictionary[ this.geometry.morphTargets[ m ].name ] = m;
13883
+
13884
+ }
13885
+
13886
+ }
13887
+
13888
+ };
13889
+
13890
+ THREE.Mesh.prototype.getMorphTargetIndexByName = function ( name ) {
13891
+
13892
+ if ( this.morphTargetDictionary[ name ] !== undefined ) {
13893
+
13894
+ return this.morphTargetDictionary[ name ];
13895
+
13896
+ }
13897
+
13898
+ console.log( 'THREE.Mesh.getMorphTargetIndexByName: morph target ' + name + ' does not exist. Returning 0.' );
13899
+
13900
+ return 0;
13901
+
13902
+ };
13903
+
13904
+
13905
+ THREE.Mesh.prototype.raycast = ( function () {
13906
+
13907
+ var inverseMatrix = new THREE.Matrix4();
13908
+ var ray = new THREE.Ray();
13909
+ var sphere = new THREE.Sphere();
13910
+
13911
+ var vA = new THREE.Vector3();
13912
+ var vB = new THREE.Vector3();
13913
+ var vC = new THREE.Vector3();
13914
+
13915
+ return function ( raycaster, intersects ) {
13916
+
13917
+ var geometry = this.geometry;
13918
+
13919
+ // Checking boundingSphere distance to ray
13920
+
13921
+ if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
13922
+
13923
+ sphere.copy( geometry.boundingSphere );
13924
+ sphere.applyMatrix4( this.matrixWorld );
13925
+
13926
+ if ( raycaster.ray.isIntersectionSphere( sphere ) === false ) {
13927
+
13928
+ return;
13929
+
13930
+ }
13931
+
13932
+ // Check boundingBox before continuing
13933
+
13934
+ inverseMatrix.getInverse( this.matrixWorld );
13935
+ ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
13936
+
13937
+ if ( geometry.boundingBox !== null ) {
13938
+
13939
+ if ( ray.isIntersectionBox( geometry.boundingBox ) === false ) {
13940
+
13941
+ return;
13942
+
13943
+ }
13944
+
13945
+ }
13946
+
13947
+ if ( geometry instanceof THREE.BufferGeometry ) {
13948
+
13949
+ var material = this.material;
13950
+
13951
+ if ( material === undefined ) return;
13952
+
13953
+ var attributes = geometry.attributes;
13954
+
13955
+ var a, b, c;
13956
+ var precision = raycaster.precision;
13957
+
13958
+ if ( attributes.index !== undefined ) {
13959
+
13960
+ var indices = attributes.index.array;
13961
+ var positions = attributes.position.array;
13962
+ var offsets = geometry.offsets;
13963
+
13964
+ if ( offsets.length === 0 ) {
13965
+
13966
+ offsets = [ { start: 0, count: indices.length, index: 0 } ];
13967
+
13968
+ }
13969
+
13970
+ for ( var oi = 0, ol = offsets.length; oi < ol; ++oi ) {
13971
+
13972
+ var start = offsets[ oi ].start;
13973
+ var count = offsets[ oi ].count;
13974
+ var index = offsets[ oi ].index;
13975
+
13976
+ for ( var i = start, il = start + count; i < il; i += 3 ) {
13977
+
13978
+ a = index + indices[ i ];
13979
+ b = index + indices[ i + 1 ];
13980
+ c = index + indices[ i + 2 ];
13981
+
13982
+ vA.fromArray( positions, a * 3 );
13983
+ vB.fromArray( positions, b * 3 );
13984
+ vC.fromArray( positions, c * 3 );
13985
+
13986
+ if ( material.side === THREE.BackSide ) {
13987
+
13988
+ var intersectionPoint = ray.intersectTriangle( vC, vB, vA, true );
13989
+
13990
+ } else {
13991
+
13992
+ var intersectionPoint = ray.intersectTriangle( vA, vB, vC, material.side !== THREE.DoubleSide );
13993
+
13994
+ }
13995
+
13996
+ if ( intersectionPoint === null ) continue;
13997
+
13998
+ intersectionPoint.applyMatrix4( this.matrixWorld );
13999
+
14000
+ var distance = raycaster.ray.origin.distanceTo( intersectionPoint );
14001
+
14002
+ if ( distance < precision || distance < raycaster.near || distance > raycaster.far ) continue;
14003
+
14004
+ intersects.push( {
14005
+
14006
+ distance: distance,
14007
+ point: intersectionPoint,
14008
+ face: new THREE.Face3( a, b, c, THREE.Triangle.normal( vA, vB, vC ) ),
14009
+ faceIndex: null,
14010
+ object: this
14011
+
14012
+ } );
14013
+
14014
+ }
14015
+
14016
+ }
14017
+
14018
+ } else {
14019
+
14020
+ var positions = attributes.position.array;
14021
+
14022
+ for ( var i = 0, j = 0, il = positions.length; i < il; i += 3, j += 9 ) {
14023
+
14024
+ a = i;
14025
+ b = i + 1;
14026
+ c = i + 2;
14027
+
14028
+ vA.fromArray( positions, j );
14029
+ vB.fromArray( positions, j + 3 );
14030
+ vC.fromArray( positions, j + 6 );
14031
+
14032
+ if ( material.side === THREE.BackSide ) {
14033
+
14034
+ var intersectionPoint = ray.intersectTriangle( vC, vB, vA, true );
14035
+
14036
+ } else {
14037
+
14038
+ var intersectionPoint = ray.intersectTriangle( vA, vB, vC, material.side !== THREE.DoubleSide );
14039
+
14040
+ }
14041
+
14042
+ if ( intersectionPoint === null ) continue;
14043
+
14044
+ intersectionPoint.applyMatrix4( this.matrixWorld );
14045
+
14046
+ var distance = raycaster.ray.origin.distanceTo( intersectionPoint );
14047
+
14048
+ if ( distance < precision || distance < raycaster.near || distance > raycaster.far ) continue;
14049
+
14050
+ intersects.push( {
14051
+
14052
+ distance: distance,
14053
+ point: intersectionPoint,
14054
+ face: new THREE.Face3( a, b, c, THREE.Triangle.normal( vA, vB, vC ) ),
14055
+ faceIndex: null,
14056
+ object: this
14057
+
14058
+ } );
14059
+
14060
+ }
14061
+
14062
+ }
14063
+
14064
+ } else if ( geometry instanceof THREE.Geometry ) {
14065
+
14066
+ var isFaceMaterial = this.material instanceof THREE.MeshFaceMaterial;
14067
+ var objectMaterials = isFaceMaterial === true ? this.material.materials : null;
14068
+
14069
+ var a, b, c, d;
14070
+ var precision = raycaster.precision;
14071
+
14072
+ var vertices = geometry.vertices;
14073
+
14074
+ for ( var f = 0, fl = geometry.faces.length; f < fl; f ++ ) {
14075
+
14076
+ var face = geometry.faces[ f ];
14077
+
14078
+ var material = isFaceMaterial === true ? objectMaterials[ face.materialIndex ] : this.material;
14079
+
14080
+ if ( material === undefined ) continue;
14081
+
14082
+ a = vertices[ face.a ];
14083
+ b = vertices[ face.b ];
14084
+ c = vertices[ face.c ];
14085
+
14086
+ if ( material.morphTargets === true ) {
14087
+
14088
+ var morphTargets = geometry.morphTargets;
14089
+ var morphInfluences = this.morphTargetInfluences;
14090
+
14091
+ vA.set( 0, 0, 0 );
14092
+ vB.set( 0, 0, 0 );
14093
+ vC.set( 0, 0, 0 );
14094
+
14095
+ for ( var t = 0, tl = morphTargets.length; t < tl; t ++ ) {
14096
+
14097
+ var influence = morphInfluences[ t ];
14098
+
14099
+ if ( influence === 0 ) continue;
14100
+
14101
+ var targets = morphTargets[ t ].vertices;
14102
+
14103
+ vA.x += ( targets[ face.a ].x - a.x ) * influence;
14104
+ vA.y += ( targets[ face.a ].y - a.y ) * influence;
14105
+ vA.z += ( targets[ face.a ].z - a.z ) * influence;
14106
+
14107
+ vB.x += ( targets[ face.b ].x - b.x ) * influence;
14108
+ vB.y += ( targets[ face.b ].y - b.y ) * influence;
14109
+ vB.z += ( targets[ face.b ].z - b.z ) * influence;
14110
+
14111
+ vC.x += ( targets[ face.c ].x - c.x ) * influence;
14112
+ vC.y += ( targets[ face.c ].y - c.y ) * influence;
14113
+ vC.z += ( targets[ face.c ].z - c.z ) * influence;
14114
+
14115
+ }
14116
+
14117
+ vA.add( a );
14118
+ vB.add( b );
14119
+ vC.add( c );
14120
+
14121
+ a = vA;
14122
+ b = vB;
14123
+ c = vC;
14124
+
14125
+ }
14126
+
14127
+ if ( material.side === THREE.BackSide ) {
14128
+
14129
+ var intersectionPoint = ray.intersectTriangle( c, b, a, true );
14130
+
14131
+ } else {
14132
+
14133
+ var intersectionPoint = ray.intersectTriangle( a, b, c, material.side !== THREE.DoubleSide );
14134
+
14135
+ }
14136
+
14137
+ if ( intersectionPoint === null ) continue;
14138
+
14139
+ intersectionPoint.applyMatrix4( this.matrixWorld );
14140
+
14141
+ var distance = raycaster.ray.origin.distanceTo( intersectionPoint );
14142
+
14143
+ if ( distance < precision || distance < raycaster.near || distance > raycaster.far ) continue;
14144
+
14145
+ intersects.push( {
14146
+
14147
+ distance: distance,
14148
+ point: intersectionPoint,
14149
+ face: face,
14150
+ faceIndex: f,
14151
+ object: this
14152
+
14153
+ } );
14154
+
14155
+ }
14156
+
14157
+ }
14158
+
14159
+ };
14160
+
14161
+ }() );
14162
+
14163
+ THREE.Mesh.prototype.clone = function ( object, recursive ) {
14164
+
14165
+ if ( object === undefined ) object = new THREE.Mesh( this.geometry, this.material );
14166
+
14167
+ THREE.Object3D.prototype.clone.call( this, object, recursive );
14168
+
14169
+ return object;
14170
+
14171
+ };
14172
+
14173
+ // File:src/objects/Bone.js
14174
+
14175
+ /**
14176
+ * @author mikael emtinger / http://gomo.se/
14177
+ * @author alteredq / http://alteredqualia.com/
14178
+ * @author ikerr / http://verold.com
14179
+ */
14180
+
14181
+ THREE.Bone = function ( belongsToSkin ) {
14182
+
14183
+ THREE.Object3D.call( this );
14184
+
14185
+ this.skin = belongsToSkin;
14186
+
14187
+ };
14188
+
14189
+ THREE.Bone.prototype = Object.create( THREE.Object3D.prototype );
14190
+
14191
+
14192
+ // File:src/objects/Skeleton.js
14193
+
14194
+ /**
14195
+ * @author mikael emtinger / http://gomo.se/
14196
+ * @author alteredq / http://alteredqualia.com/
14197
+ * @author michael guerrero / http://realitymeltdown.com
14198
+ * @author ikerr / http://verold.com
14199
+ */
14200
+
14201
+ THREE.Skeleton = function ( bones, boneInverses, useVertexTexture ) {
14202
+
14203
+ this.useVertexTexture = useVertexTexture !== undefined ? useVertexTexture : true;
14204
+
14205
+ this.identityMatrix = new THREE.Matrix4();
14206
+
14207
+ // copy the bone array
14208
+
14209
+ bones = bones || [];
14210
+
14211
+ this.bones = bones.slice( 0 );
14212
+
14213
+ // create a bone texture or an array of floats
14214
+
14215
+ if ( this.useVertexTexture ) {
14216
+
14217
+ // layout (1 matrix = 4 pixels)
14218
+ // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
14219
+ // with 8x8 pixel texture max 16 bones (8 * 8 / 4)
14220
+ // 16x16 pixel texture max 64 bones (16 * 16 / 4)
14221
+ // 32x32 pixel texture max 256 bones (32 * 32 / 4)
14222
+ // 64x64 pixel texture max 1024 bones (64 * 64 / 4)
14223
+
14224
+ var size;
14225
+
14226
+ if ( this.bones.length > 256 )
14227
+ size = 64;
14228
+ else if ( this.bones.length > 64 )
14229
+ size = 32;
14230
+ else if ( this.bones.length > 16 )
14231
+ size = 16;
14232
+ else
14233
+ size = 8;
14234
+
14235
+ this.boneTextureWidth = size;
14236
+ this.boneTextureHeight = size;
14237
+
14238
+ this.boneMatrices = new Float32Array( this.boneTextureWidth * this.boneTextureHeight * 4 ); // 4 floats per RGBA pixel
14239
+ this.boneTexture = new THREE.DataTexture( this.boneMatrices, this.boneTextureWidth, this.boneTextureHeight, THREE.RGBAFormat, THREE.FloatType );
14240
+ this.boneTexture.minFilter = THREE.NearestFilter;
14241
+ this.boneTexture.magFilter = THREE.NearestFilter;
14242
+ this.boneTexture.generateMipmaps = false;
14243
+ this.boneTexture.flipY = false;
14244
+
14245
+ } else {
14246
+
14247
+ this.boneMatrices = new Float32Array( 16 * this.bones.length );
14248
+
14249
+ }
14250
+
14251
+ // use the supplied bone inverses or calculate the inverses
14252
+
14253
+ if ( boneInverses === undefined ) {
14254
+
14255
+ this.calculateInverses();
14256
+
14257
+ } else {
14258
+
14259
+ if ( this.bones.length === boneInverses.length ) {
14260
+
14261
+ this.boneInverses = boneInverses.slice( 0 );
14262
+
14263
+ } else {
14264
+
14265
+ console.warn( 'THREE.Skeleton bonInverses is the wrong length.' );
14266
+
14267
+ this.boneInverses = [];
14268
+
14269
+ for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
14270
+
14271
+ this.boneInverses.push( new THREE.Matrix4() );
14272
+
14273
+ }
14274
+
14275
+ }
14276
+
14277
+ }
14278
+
14279
+ };
14280
+
14281
+ THREE.Skeleton.prototype.calculateInverses = function () {
14282
+
14283
+ this.boneInverses = [];
14284
+
14285
+ for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
14286
+
14287
+ var inverse = new THREE.Matrix4();
14288
+
14289
+ if ( this.bones[ b ] ) {
14290
+
14291
+ inverse.getInverse( this.bones[ b ].matrixWorld );
14292
+
14293
+ }
14294
+
14295
+ this.boneInverses.push( inverse );
14296
+
14297
+ }
14298
+
14299
+ };
14300
+
14301
+ THREE.Skeleton.prototype.pose = function () {
14302
+
14303
+ var bone;
14304
+
14305
+ // recover the bind-time world matrices
14306
+
14307
+ for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
14308
+
14309
+ bone = this.bones[ b ];
14310
+
14311
+ if ( bone ) {
14312
+
14313
+ bone.matrixWorld.getInverse( this.boneInverses[ b ] );
14314
+
14315
+ }
14316
+
14317
+ }
14318
+
14319
+ // compute the local matrices, positions, rotations and scales
14320
+
14321
+ for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
14322
+
14323
+ bone = this.bones[ b ];
14324
+
14325
+ if ( bone ) {
14326
+
14327
+ if ( bone.parent ) {
14328
+
14329
+ bone.matrix.getInverse( bone.parent.matrixWorld );
14330
+ bone.matrix.multiply( bone.matrixWorld );
14331
+
14332
+ } else {
14333
+
14334
+ bone.matrix.copy( bone.matrixWorld );
14335
+
14336
+ }
14337
+
14338
+ bone.matrix.decompose( bone.position, bone.quaternion, bone.scale );
14339
+
14340
+ }
14341
+
14342
+ }
14343
+
14344
+ };
14345
+
14346
+ THREE.Skeleton.prototype.update = ( function () {
14347
+
14348
+ var offsetMatrix = new THREE.Matrix4();
14349
+
14350
+ return function () {
14351
+
14352
+ // flatten bone matrices to array
14353
+
14354
+ for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
14355
+
14356
+ // compute the offset between the current and the original transform
14357
+
14358
+ var matrix = this.bones[ b ] ? this.bones[ b ].matrixWorld : this.identityMatrix;
14359
+
14360
+ offsetMatrix.multiplyMatrices( matrix, this.boneInverses[ b ] );
14361
+ offsetMatrix.flattenToArrayOffset( this.boneMatrices, b * 16 );
14362
+
14363
+ }
14364
+
14365
+ if ( this.useVertexTexture ) {
14366
+
14367
+ this.boneTexture.needsUpdate = true;
14368
+
14369
+ }
14370
+
14371
+ };
14372
+
14373
+ } )();
14374
+
14375
+
14376
+ // File:src/objects/SkinnedMesh.js
14377
+
14378
+ /**
14379
+ * @author mikael emtinger / http://gomo.se/
14380
+ * @author alteredq / http://alteredqualia.com/
14381
+ * @author ikerr / http://verold.com
14382
+ */
14383
+
14384
+ THREE.SkinnedMesh = function ( geometry, material, useVertexTexture ) {
14385
+
14386
+ THREE.Mesh.call( this, geometry, material );
14387
+
14388
+ this.type = 'SkinnedMesh';
14389
+
14390
+ this.bindMode = "attached";
14391
+ this.bindMatrix = new THREE.Matrix4();
14392
+ this.bindMatrixInverse = new THREE.Matrix4();
14393
+
14394
+ // init bones
14395
+
14396
+ // TODO: remove bone creation as there is no reason (other than
14397
+ // convenience) for THREE.SkinnedMesh to do this.
14398
+
14399
+ var bones = [];
14400
+
14401
+ if ( this.geometry && this.geometry.bones !== undefined ) {
14402
+
14403
+ var bone, gbone, p, q, s;
14404
+
14405
+ for ( var b = 0, bl = this.geometry.bones.length; b < bl; ++b ) {
14406
+
14407
+ gbone = this.geometry.bones[ b ];
14408
+
14409
+ p = gbone.pos;
14410
+ q = gbone.rotq;
14411
+ s = gbone.scl;
14412
+
14413
+ bone = new THREE.Bone( this );
14414
+ bones.push( bone );
14415
+
14416
+ bone.name = gbone.name;
14417
+ bone.position.set( p[ 0 ], p[ 1 ], p[ 2 ] );
14418
+ bone.quaternion.set( q[ 0 ], q[ 1 ], q[ 2 ], q[ 3 ] );
14419
+
14420
+ if ( s !== undefined ) {
14421
+
14422
+ bone.scale.set( s[ 0 ], s[ 1 ], s[ 2 ] );
14423
+
14424
+ } else {
14425
+
14426
+ bone.scale.set( 1, 1, 1 );
14427
+
14428
+ }
14429
+
14430
+ }
14431
+
14432
+ for ( var b = 0, bl = this.geometry.bones.length; b < bl; ++b ) {
14433
+
14434
+ gbone = this.geometry.bones[ b ];
14435
+
14436
+ if ( gbone.parent !== - 1 ) {
14437
+
14438
+ bones[ gbone.parent ].add( bones[ b ] );
14439
+
14440
+ } else {
14441
+
14442
+ this.add( bones[ b ] );
14443
+
14444
+ }
14445
+
14446
+ }
14447
+
14448
+ }
14449
+
14450
+ this.normalizeSkinWeights();
14451
+
14452
+ this.updateMatrixWorld( true );
14453
+ this.bind( new THREE.Skeleton( bones, undefined, useVertexTexture ) );
14454
+
14455
+ };
14456
+
14457
+
14458
+ THREE.SkinnedMesh.prototype = Object.create( THREE.Mesh.prototype );
14459
+
14460
+ THREE.SkinnedMesh.prototype.bind = function( skeleton, bindMatrix ) {
14461
+
14462
+ this.skeleton = skeleton;
14463
+
14464
+ if ( bindMatrix === undefined ) {
14465
+
14466
+ this.updateMatrixWorld( true );
14467
+
14468
+ bindMatrix = this.matrixWorld;
14469
+
14470
+ }
14471
+
14472
+ this.bindMatrix.copy( bindMatrix );
14473
+ this.bindMatrixInverse.getInverse( bindMatrix );
14474
+
14475
+ };
14476
+
14477
+ THREE.SkinnedMesh.prototype.pose = function () {
14478
+
14479
+ this.skeleton.pose();
14480
+
14481
+ };
14482
+
14483
+ THREE.SkinnedMesh.prototype.normalizeSkinWeights = function () {
14484
+
14485
+ if ( this.geometry instanceof THREE.Geometry ) {
14486
+
14487
+ for ( var i = 0; i < this.geometry.skinIndices.length; i ++ ) {
14488
+
14489
+ var sw = this.geometry.skinWeights[ i ];
14490
+
14491
+ var scale = 1.0 / sw.lengthManhattan();
14492
+
14493
+ if ( scale !== Infinity ) {
14494
+
14495
+ sw.multiplyScalar( scale );
14496
+
14497
+ } else {
14498
+
14499
+ sw.set( 1 ); // this will be normalized by the shader anyway
14500
+
14501
+ }
14502
+
14503
+ }
14504
+
14505
+ } else {
14506
+
14507
+ // skinning weights assumed to be normalized for THREE.BufferGeometry
14508
+
14509
+ }
14510
+
14511
+ };
14512
+
14513
+ THREE.SkinnedMesh.prototype.updateMatrixWorld = function( force ) {
14514
+
14515
+ THREE.Mesh.prototype.updateMatrixWorld.call( this, true );
14516
+
14517
+ if ( this.bindMode === "attached" ) {
14518
+
14519
+ this.bindMatrixInverse.getInverse( this.matrixWorld );
14520
+
14521
+ } else if ( this.bindMode === "detached" ) {
14522
+
14523
+ this.bindMatrixInverse.getInverse( this.bindMatrix );
14524
+
14525
+ } else {
14526
+
14527
+ console.warn( 'THREE.SkinnedMesh unreckognized bindMode: ' + this.bindMode );
14528
+
14529
+ }
14530
+
14531
+ };
14532
+
14533
+ THREE.SkinnedMesh.prototype.clone = function( object ) {
14534
+
14535
+ if ( object === undefined ) {
14536
+
14537
+ object = new THREE.SkinnedMesh( this.geometry, this.material, this.useVertexTexture );
14538
+
14539
+ }
14540
+
14541
+ THREE.Mesh.prototype.clone.call( this, object );
14542
+
14543
+ return object;
14544
+
14545
+ };
14546
+
14547
+
14548
+ // File:src/objects/MorphAnimMesh.js
14549
+
14550
+ /**
14551
+ * @author alteredq / http://alteredqualia.com/
14552
+ */
14553
+
14554
+ THREE.MorphAnimMesh = function ( geometry, material ) {
14555
+
14556
+ THREE.Mesh.call( this, geometry, material );
14557
+
14558
+ this.type = 'MorphAnimMesh';
14559
+
14560
+ // API
14561
+
14562
+ this.duration = 1000; // milliseconds
14563
+ this.mirroredLoop = false;
14564
+ this.time = 0;
14565
+
14566
+ // internals
14567
+
14568
+ this.lastKeyframe = 0;
14569
+ this.currentKeyframe = 0;
14570
+
14571
+ this.direction = 1;
14572
+ this.directionBackwards = false;
14573
+
14574
+ this.setFrameRange( 0, this.geometry.morphTargets.length - 1 );
14575
+
14576
+ };
14577
+
14578
+ THREE.MorphAnimMesh.prototype = Object.create( THREE.Mesh.prototype );
14579
+
14580
+ THREE.MorphAnimMesh.prototype.setFrameRange = function ( start, end ) {
14581
+
14582
+ this.startKeyframe = start;
14583
+ this.endKeyframe = end;
14584
+
14585
+ this.length = this.endKeyframe - this.startKeyframe + 1;
14586
+
14587
+ };
14588
+
14589
+ THREE.MorphAnimMesh.prototype.setDirectionForward = function () {
14590
+
14591
+ this.direction = 1;
14592
+ this.directionBackwards = false;
14593
+
14594
+ };
14595
+
14596
+ THREE.MorphAnimMesh.prototype.setDirectionBackward = function () {
14597
+
14598
+ this.direction = - 1;
14599
+ this.directionBackwards = true;
14600
+
14601
+ };
14602
+
14603
+ THREE.MorphAnimMesh.prototype.parseAnimations = function () {
14604
+
14605
+ var geometry = this.geometry;
14606
+
14607
+ if ( ! geometry.animations ) geometry.animations = {};
14608
+
14609
+ var firstAnimation, animations = geometry.animations;
14610
+
14611
+ var pattern = /([a-z]+)_?(\d+)/;
14612
+
14613
+ for ( var i = 0, il = geometry.morphTargets.length; i < il; i ++ ) {
14614
+
14615
+ var morph = geometry.morphTargets[ i ];
14616
+ var parts = morph.name.match( pattern );
14617
+
14618
+ if ( parts && parts.length > 1 ) {
14619
+
14620
+ var label = parts[ 1 ];
14621
+ var num = parts[ 2 ];
14622
+
14623
+ if ( ! animations[ label ] ) animations[ label ] = { start: Infinity, end: - Infinity };
14624
+
14625
+ var animation = animations[ label ];
14626
+
14627
+ if ( i < animation.start ) animation.start = i;
14628
+ if ( i > animation.end ) animation.end = i;
14629
+
14630
+ if ( ! firstAnimation ) firstAnimation = label;
14631
+
14632
+ }
14633
+
14634
+ }
14635
+
14636
+ geometry.firstAnimation = firstAnimation;
14637
+
14638
+ };
14639
+
14640
+ THREE.MorphAnimMesh.prototype.setAnimationLabel = function ( label, start, end ) {
14641
+
14642
+ if ( ! this.geometry.animations ) this.geometry.animations = {};
14643
+
14644
+ this.geometry.animations[ label ] = { start: start, end: end };
14645
+
14646
+ };
14647
+
14648
+ THREE.MorphAnimMesh.prototype.playAnimation = function ( label, fps ) {
14649
+
14650
+ var animation = this.geometry.animations[ label ];
14651
+
14652
+ if ( animation ) {
14653
+
14654
+ this.setFrameRange( animation.start, animation.end );
14655
+ this.duration = 1000 * ( ( animation.end - animation.start ) / fps );
14656
+ this.time = 0;
14657
+
14658
+ } else {
14659
+
14660
+ console.warn( 'animation[' + label + '] undefined' );
14661
+
14662
+ }
14663
+
14664
+ };
14665
+
14666
+ THREE.MorphAnimMesh.prototype.updateAnimation = function ( delta ) {
14667
+
14668
+ var frameTime = this.duration / this.length;
14669
+
14670
+ this.time += this.direction * delta;
14671
+
14672
+ if ( this.mirroredLoop ) {
14673
+
14674
+ if ( this.time > this.duration || this.time < 0 ) {
14675
+
14676
+ this.direction *= - 1;
14677
+
14678
+ if ( this.time > this.duration ) {
14679
+
14680
+ this.time = this.duration;
14681
+ this.directionBackwards = true;
14682
+
14683
+ }
14684
+
14685
+ if ( this.time < 0 ) {
14686
+
14687
+ this.time = 0;
14688
+ this.directionBackwards = false;
14689
+
14690
+ }
14691
+
14692
+ }
14693
+
14694
+ } else {
14695
+
14696
+ this.time = this.time % this.duration;
14697
+
14698
+ if ( this.time < 0 ) this.time += this.duration;
14699
+
14700
+ }
14701
+
14702
+ var keyframe = this.startKeyframe + THREE.Math.clamp( Math.floor( this.time / frameTime ), 0, this.length - 1 );
14703
+
14704
+ if ( keyframe !== this.currentKeyframe ) {
14705
+
14706
+ this.morphTargetInfluences[ this.lastKeyframe ] = 0;
14707
+ this.morphTargetInfluences[ this.currentKeyframe ] = 1;
14708
+
14709
+ this.morphTargetInfluences[ keyframe ] = 0;
14710
+
14711
+ this.lastKeyframe = this.currentKeyframe;
14712
+ this.currentKeyframe = keyframe;
14713
+
14714
+ }
14715
+
14716
+ var mix = ( this.time % frameTime ) / frameTime;
14717
+
14718
+ if ( this.directionBackwards ) {
14719
+
14720
+ mix = 1 - mix;
14721
+
14722
+ }
14723
+
14724
+ this.morphTargetInfluences[ this.currentKeyframe ] = mix;
14725
+ this.morphTargetInfluences[ this.lastKeyframe ] = 1 - mix;
14726
+
14727
+ };
14728
+
14729
+ THREE.MorphAnimMesh.prototype.interpolateTargets = function ( a, b, t ) {
14730
+
14731
+ var influences = this.morphTargetInfluences;
14732
+
14733
+ for ( var i = 0, l = influences.length; i < l; i ++ ) {
14734
+
14735
+ influences[ i ] = 0;
14736
+
14737
+ }
14738
+
14739
+ if ( a > -1 ) influences[ a ] = 1 - t;
14740
+ if ( b > -1 ) influences[ b ] = t;
14741
+
14742
+ };
14743
+
14744
+ THREE.MorphAnimMesh.prototype.clone = function ( object ) {
14745
+
14746
+ if ( object === undefined ) object = new THREE.MorphAnimMesh( this.geometry, this.material );
14747
+
14748
+ object.duration = this.duration;
14749
+ object.mirroredLoop = this.mirroredLoop;
14750
+ object.time = this.time;
14751
+
14752
+ object.lastKeyframe = this.lastKeyframe;
14753
+ object.currentKeyframe = this.currentKeyframe;
14754
+
14755
+ object.direction = this.direction;
14756
+ object.directionBackwards = this.directionBackwards;
14757
+
14758
+ THREE.Mesh.prototype.clone.call( this, object );
14759
+
14760
+ return object;
14761
+
14762
+ };
14763
+
14764
+ // File:src/objects/LOD.js
14765
+
14766
+ /**
14767
+ * @author mikael emtinger / http://gomo.se/
14768
+ * @author alteredq / http://alteredqualia.com/
14769
+ * @author mrdoob / http://mrdoob.com/
14770
+ */
14771
+
14772
+ THREE.LOD = function () {
14773
+
14774
+ THREE.Object3D.call( this );
14775
+
14776
+ this.objects = [];
14777
+
14778
+ };
14779
+
14780
+
14781
+ THREE.LOD.prototype = Object.create( THREE.Object3D.prototype );
14782
+
14783
+ THREE.LOD.prototype.addLevel = function ( object, distance ) {
14784
+
14785
+ if ( distance === undefined ) distance = 0;
14786
+
14787
+ distance = Math.abs( distance );
14788
+
14789
+ for ( var l = 0; l < this.objects.length; l ++ ) {
14790
+
14791
+ if ( distance < this.objects[ l ].distance ) {
14792
+
14793
+ break;
14794
+
14795
+ }
14796
+
14797
+ }
14798
+
14799
+ this.objects.splice( l, 0, { distance: distance, object: object } );
14800
+ this.add( object );
14801
+
14802
+ };
14803
+
14804
+ THREE.LOD.prototype.getObjectForDistance = function ( distance ) {
14805
+
14806
+ for ( var i = 1, l = this.objects.length; i < l; i ++ ) {
14807
+
14808
+ if ( distance < this.objects[ i ].distance ) {
14809
+
14810
+ break;
14811
+
14812
+ }
14813
+
14814
+ }
14815
+
14816
+ return this.objects[ i - 1 ].object;
14817
+
14818
+ };
14819
+
14820
+ THREE.LOD.prototype.raycast = ( function () {
14821
+
14822
+ var matrixPosition = new THREE.Vector3();
14823
+
14824
+ return function ( raycaster, intersects ) {
14825
+
14826
+ matrixPosition.setFromMatrixPosition( this.matrixWorld );
14827
+
14828
+ var distance = raycaster.ray.origin.distanceTo( matrixPosition );
14829
+
14830
+ this.getObjectForDistance( distance ).raycast( raycaster, intersects );
14831
+
14832
+ };
14833
+
14834
+ }() );
14835
+
14836
+ THREE.LOD.prototype.update = function () {
14837
+
14838
+ var v1 = new THREE.Vector3();
14839
+ var v2 = new THREE.Vector3();
14840
+
14841
+ return function ( camera ) {
14842
+
14843
+ if ( this.objects.length > 1 ) {
14844
+
14845
+ v1.setFromMatrixPosition( camera.matrixWorld );
14846
+ v2.setFromMatrixPosition( this.matrixWorld );
14847
+
14848
+ var distance = v1.distanceTo( v2 );
14849
+
14850
+ this.objects[ 0 ].object.visible = true;
14851
+
14852
+ for ( var i = 1, l = this.objects.length; i < l; i ++ ) {
14853
+
14854
+ if ( distance >= this.objects[ i ].distance ) {
14855
+
14856
+ this.objects[ i - 1 ].object.visible = false;
14857
+ this.objects[ i ].object.visible = true;
14858
+
14859
+ } else {
14860
+
14861
+ break;
14862
+
14863
+ }
14864
+
14865
+ }
14866
+
14867
+ for ( ; i < l; i ++ ) {
14868
+
14869
+ this.objects[ i ].object.visible = false;
14870
+
14871
+ }
14872
+
14873
+ }
14874
+
14875
+ };
14876
+
14877
+ }();
14878
+
14879
+ THREE.LOD.prototype.clone = function ( object ) {
14880
+
14881
+ if ( object === undefined ) object = new THREE.LOD();
14882
+
14883
+ THREE.Object3D.prototype.clone.call( this, object );
14884
+
14885
+ for ( var i = 0, l = this.objects.length; i < l; i ++ ) {
14886
+ var x = this.objects[ i ].object.clone();
14887
+ x.visible = i === 0;
14888
+ object.addLevel( x, this.objects[ i ].distance );
14889
+ }
14890
+
14891
+ return object;
14892
+
14893
+ };
14894
+
14895
+ // File:src/objects/Sprite.js
14896
+
14897
+ /**
14898
+ * @author mikael emtinger / http://gomo.se/
14899
+ * @author alteredq / http://alteredqualia.com/
14900
+ */
14901
+
14902
+ THREE.Sprite = ( function () {
14903
+
14904
+ var indices = new Uint16Array( [ 0, 1, 2, 0, 2, 3 ] );
14905
+ var vertices = new Float32Array( [ - 0.5, - 0.5, 0, 0.5, - 0.5, 0, 0.5, 0.5, 0, - 0.5, 0.5, 0 ] );
14906
+ var uvs = new Float32Array( [ 0, 0, 1, 0, 1, 1, 0, 1 ] );
14907
+
14908
+ var geometry = new THREE.BufferGeometry();
14909
+ geometry.addAttribute( 'index', new THREE.BufferAttribute( indices, 1 ) );
14910
+ geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
14911
+ geometry.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
14912
+
14913
+ return function ( material ) {
14914
+
14915
+ THREE.Object3D.call( this );
14916
+
14917
+ this.type = 'Sprite';
14918
+
14919
+ this.geometry = geometry;
14920
+ this.material = ( material !== undefined ) ? material : new THREE.SpriteMaterial();
14921
+
14922
+ };
14923
+
14924
+ } )();
14925
+
14926
+ THREE.Sprite.prototype = Object.create( THREE.Object3D.prototype );
14927
+
14928
+ THREE.Sprite.prototype.raycast = ( function () {
14929
+
14930
+ var matrixPosition = new THREE.Vector3();
14931
+
14932
+ return function ( raycaster, intersects ) {
14933
+
14934
+ matrixPosition.setFromMatrixPosition( this.matrixWorld );
14935
+
14936
+ var distance = raycaster.ray.distanceToPoint( matrixPosition );
14937
+
14938
+ if ( distance > this.scale.x ) {
14939
+
14940
+ return;
14941
+
14942
+ }
14943
+
14944
+ intersects.push( {
14945
+
14946
+ distance: distance,
14947
+ point: this.position,
14948
+ face: null,
14949
+ object: this
14950
+
14951
+ } );
14952
+
14953
+ };
14954
+
14955
+ }() );
14956
+
14957
+ THREE.Sprite.prototype.clone = function ( object ) {
14958
+
14959
+ if ( object === undefined ) object = new THREE.Sprite( this.material );
14960
+
14961
+ THREE.Object3D.prototype.clone.call( this, object );
14962
+
14963
+ return object;
14964
+
14965
+ };
14966
+
14967
+ // Backwards compatibility
14968
+
14969
+ THREE.Particle = THREE.Sprite;
14970
+
14971
+ // File:src/objects/LensFlare.js
14972
+
14973
+ /**
14974
+ * @author mikael emtinger / http://gomo.se/
14975
+ * @author alteredq / http://alteredqualia.com/
14976
+ */
14977
+
14978
+ THREE.LensFlare = function ( texture, size, distance, blending, color ) {
14979
+
14980
+ THREE.Object3D.call( this );
14981
+
14982
+ this.lensFlares = [];
14983
+
14984
+ this.positionScreen = new THREE.Vector3();
14985
+ this.customUpdateCallback = undefined;
14986
+
14987
+ if( texture !== undefined ) {
14988
+
14989
+ this.add( texture, size, distance, blending, color );
14990
+
14991
+ }
14992
+
14993
+ };
14994
+
14995
+ THREE.LensFlare.prototype = Object.create( THREE.Object3D.prototype );
14996
+
14997
+
14998
+ /*
14999
+ * Add: adds another flare
15000
+ */
15001
+
15002
+ THREE.LensFlare.prototype.add = function ( texture, size, distance, blending, color, opacity ) {
15003
+
15004
+ if ( size === undefined ) size = - 1;
15005
+ if ( distance === undefined ) distance = 0;
15006
+ if ( opacity === undefined ) opacity = 1;
15007
+ if ( color === undefined ) color = new THREE.Color( 0xffffff );
15008
+ if ( blending === undefined ) blending = THREE.NormalBlending;
15009
+
15010
+ distance = Math.min( distance, Math.max( 0, distance ) );
15011
+
15012
+ this.lensFlares.push( {
15013
+ texture: texture, // THREE.Texture
15014
+ size: size, // size in pixels (-1 = use texture.width)
15015
+ distance: distance, // distance (0-1) from light source (0=at light source)
15016
+ x: 0, y: 0, z: 0, // screen position (-1 => 1) z = 0 is ontop z = 1 is back
15017
+ scale: 1, // scale
15018
+ rotation: 1, // rotation
15019
+ opacity: opacity, // opacity
15020
+ color: color, // color
15021
+ blending: blending // blending
15022
+ } );
15023
+
15024
+ };
15025
+
15026
+ /*
15027
+ * Update lens flares update positions on all flares based on the screen position
15028
+ * Set myLensFlare.customUpdateCallback to alter the flares in your project specific way.
15029
+ */
15030
+
15031
+ THREE.LensFlare.prototype.updateLensFlares = function () {
15032
+
15033
+ var f, fl = this.lensFlares.length;
15034
+ var flare;
15035
+ var vecX = - this.positionScreen.x * 2;
15036
+ var vecY = - this.positionScreen.y * 2;
15037
+
15038
+ for( f = 0; f < fl; f ++ ) {
15039
+
15040
+ flare = this.lensFlares[ f ];
15041
+
15042
+ flare.x = this.positionScreen.x + vecX * flare.distance;
15043
+ flare.y = this.positionScreen.y + vecY * flare.distance;
15044
+
15045
+ flare.wantedRotation = flare.x * Math.PI * 0.25;
15046
+ flare.rotation += ( flare.wantedRotation - flare.rotation ) * 0.25;
15047
+
15048
+ }
15049
+
15050
+ };
15051
+
15052
+
15053
+ // File:src/scenes/Scene.js
15054
+
15055
+ /**
15056
+ * @author mrdoob / http://mrdoob.com/
15057
+ */
15058
+
15059
+ THREE.Scene = function () {
15060
+
15061
+ THREE.Object3D.call( this );
15062
+
15063
+ this.type = 'Scene';
15064
+
15065
+ this.fog = null;
15066
+ this.overrideMaterial = null;
15067
+
15068
+ this.autoUpdate = true; // checked by the renderer
15069
+
15070
+ };
15071
+
15072
+ THREE.Scene.prototype = Object.create( THREE.Object3D.prototype );
15073
+
15074
+ THREE.Scene.prototype.clone = function ( object ) {
15075
+
15076
+ if ( object === undefined ) object = new THREE.Scene();
15077
+
15078
+ THREE.Object3D.prototype.clone.call( this, object );
15079
+
15080
+ if ( this.fog !== null ) object.fog = this.fog.clone();
15081
+ if ( this.overrideMaterial !== null ) object.overrideMaterial = this.overrideMaterial.clone();
15082
+
15083
+ object.autoUpdate = this.autoUpdate;
15084
+ object.matrixAutoUpdate = this.matrixAutoUpdate;
15085
+
15086
+ return object;
15087
+
15088
+ };
15089
+
15090
+ // File:src/scenes/Fog.js
15091
+
15092
+ /**
15093
+ * @author mrdoob / http://mrdoob.com/
15094
+ * @author alteredq / http://alteredqualia.com/
15095
+ */
15096
+
15097
+ THREE.Fog = function ( color, near, far ) {
15098
+
15099
+ this.name = '';
15100
+
15101
+ this.color = new THREE.Color( color );
15102
+
15103
+ this.near = ( near !== undefined ) ? near : 1;
15104
+ this.far = ( far !== undefined ) ? far : 1000;
15105
+
15106
+ };
15107
+
15108
+ THREE.Fog.prototype.clone = function () {
15109
+
15110
+ return new THREE.Fog( this.color.getHex(), this.near, this.far );
15111
+
15112
+ };
15113
+
15114
+ // File:src/scenes/FogExp2.js
15115
+
15116
+ /**
15117
+ * @author mrdoob / http://mrdoob.com/
15118
+ * @author alteredq / http://alteredqualia.com/
15119
+ */
15120
+
15121
+ THREE.FogExp2 = function ( color, density ) {
15122
+
15123
+ this.name = '';
15124
+
15125
+ this.color = new THREE.Color( color );
15126
+ this.density = ( density !== undefined ) ? density : 0.00025;
15127
+
15128
+ };
15129
+
15130
+ THREE.FogExp2.prototype.clone = function () {
15131
+
15132
+ return new THREE.FogExp2( this.color.getHex(), this.density );
15133
+
15134
+ };
15135
+
15136
+ // File:src/renderers/shaders/ShaderChunk.js
15137
+
15138
+ THREE.ShaderChunk = {};
15139
+
15140
+ // File:src/renderers/shaders/ShaderChunk/alphatest_fragment.glsl
15141
+
15142
+ THREE.ShaderChunk[ 'alphatest_fragment'] = "#ifdef ALPHATEST\n\n if ( gl_FragColor.a < ALPHATEST ) discard;\n\n#endif\n";
15143
+
15144
+ // File:src/renderers/shaders/ShaderChunk/lights_lambert_vertex.glsl
15145
+
15146
+ THREE.ShaderChunk[ 'lights_lambert_vertex'] = "vLightFront = vec3( 0.0 );\n\n#ifdef DOUBLE_SIDED\n\n vLightBack = vec3( 0.0 );\n\n#endif\n\ntransformedNormal = normalize( transformedNormal );\n\n#if MAX_DIR_LIGHTS > 0\n\nfor( int i = 0; i < MAX_DIR_LIGHTS; i ++ ) {\n\n vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );\n vec3 dirVector = normalize( lDirection.xyz );\n\n float dotProduct = dot( transformedNormal, dirVector );\n vec3 directionalLightWeighting = vec3( max( dotProduct, 0.0 ) );\n\n #ifdef DOUBLE_SIDED\n\n vec3 directionalLightWeightingBack = vec3( max( -dotProduct, 0.0 ) );\n\n #ifdef WRAP_AROUND\n\n vec3 directionalLightWeightingHalfBack = vec3( max( -0.5 * dotProduct + 0.5, 0.0 ) );\n\n #endif\n\n #endif\n\n #ifdef WRAP_AROUND\n\n vec3 directionalLightWeightingHalf = vec3( max( 0.5 * dotProduct + 0.5, 0.0 ) );\n directionalLightWeighting = mix( directionalLightWeighting, directionalLightWeightingHalf, wrapRGB );\n\n #ifdef DOUBLE_SIDED\n\n directionalLightWeightingBack = mix( directionalLightWeightingBack, directionalLightWeightingHalfBack, wrapRGB );\n\n #endif\n\n #endif\n\n vLightFront += directionalLightColor[ i ] * directionalLightWeighting;\n\n #ifdef DOUBLE_SIDED\n\n vLightBack += directionalLightColor[ i ] * directionalLightWeightingBack;\n\n #endif\n\n}\n\n#endif\n\n#if MAX_POINT_LIGHTS > 0\n\n for( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {\n\n vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );\n vec3 lVector = lPosition.xyz - mvPosition.xyz;\n\n float lDistance = 1.0;\n if ( pointLightDistance[ i ] > 0.0 )\n lDistance = 1.0 - min( ( length( lVector ) / pointLightDistance[ i ] ), 1.0 );\n\n lVector = normalize( lVector );\n float dotProduct = dot( transformedNormal, lVector );\n\n vec3 pointLightWeighting = vec3( max( dotProduct, 0.0 ) );\n\n #ifdef DOUBLE_SIDED\n\n vec3 pointLightWeightingBack = vec3( max( -dotProduct, 0.0 ) );\n\n #ifdef WRAP_AROUND\n\n vec3 pointLightWeightingHalfBack = vec3( max( -0.5 * dotProduct + 0.5, 0.0 ) );\n\n #endif\n\n #endif\n\n #ifdef WRAP_AROUND\n\n vec3 pointLightWeightingHalf = vec3( max( 0.5 * dotProduct + 0.5, 0.0 ) );\n pointLightWeighting = mix( pointLightWeighting, pointLightWeightingHalf, wrapRGB );\n\n #ifdef DOUBLE_SIDED\n\n pointLightWeightingBack = mix( pointLightWeightingBack, pointLightWeightingHalfBack, wrapRGB );\n\n #endif\n\n #endif\n\n vLightFront += pointLightColor[ i ] * pointLightWeighting * lDistance;\n\n #ifdef DOUBLE_SIDED\n\n vLightBack += pointLightColor[ i ] * pointLightWeightingBack * lDistance;\n\n #endif\n\n }\n\n#endif\n\n#if MAX_SPOT_LIGHTS > 0\n\n for( int i = 0; i < MAX_SPOT_LIGHTS; i ++ ) {\n\n vec4 lPosition = viewMatrix * vec4( spotLightPosition[ i ], 1.0 );\n vec3 lVector = lPosition.xyz - mvPosition.xyz;\n\n float spotEffect = dot( spotLightDirection[ i ], normalize( spotLightPosition[ i ] - worldPosition.xyz ) );\n\n if ( spotEffect > spotLightAngleCos[ i ] ) {\n\n spotEffect = max( pow( max( spotEffect, 0.0 ), spotLightExponent[ i ] ), 0.0 );\n\n float lDistance = 1.0;\n if ( spotLightDistance[ i ] > 0.0 )\n lDistance = 1.0 - min( ( length( lVector ) / spotLightDistance[ i ] ), 1.0 );\n\n lVector = normalize( lVector );\n\n float dotProduct = dot( transformedNormal, lVector );\n vec3 spotLightWeighting = vec3( max( dotProduct, 0.0 ) );\n\n #ifdef DOUBLE_SIDED\n\n vec3 spotLightWeightingBack = vec3( max( -dotProduct, 0.0 ) );\n\n #ifdef WRAP_AROUND\n\n vec3 spotLightWeightingHalfBack = vec3( max( -0.5 * dotProduct + 0.5, 0.0 ) );\n\n #endif\n\n #endif\n\n #ifdef WRAP_AROUND\n\n vec3 spotLightWeightingHalf = vec3( max( 0.5 * dotProduct + 0.5, 0.0 ) );\n spotLightWeighting = mix( spotLightWeighting, spotLightWeightingHalf, wrapRGB );\n\n #ifdef DOUBLE_SIDED\n\n spotLightWeightingBack = mix( spotLightWeightingBack, spotLightWeightingHalfBack, wrapRGB );\n\n #endif\n\n #endif\n\n vLightFront += spotLightColor[ i ] * spotLightWeighting * lDistance * spotEffect;\n\n #ifdef DOUBLE_SIDED\n\n vLightBack += spotLightColor[ i ] * spotLightWeightingBack * lDistance * spotEffect;\n\n #endif\n\n }\n\n }\n\n#endif\n\n#if MAX_HEMI_LIGHTS > 0\n\n for( int i = 0; i < MAX_HEMI_LIGHTS; i ++ ) {\n\n vec4 lDirection = viewMatrix * vec4( hemisphereLightDirection[ i ], 0.0 );\n vec3 lVector = normalize( lDirection.xyz );\n\n float dotProduct = dot( transformedNormal, lVector );\n\n float hemiDiffuseWeight = 0.5 * dotProduct + 0.5;\n float hemiDiffuseWeightBack = -0.5 * dotProduct + 0.5;\n\n vLightFront += mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeight );\n\n #ifdef DOUBLE_SIDED\n\n vLightBack += mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeightBack );\n\n #endif\n\n }\n\n#endif\n\nvLightFront = vLightFront * diffuse + ambient * ambientLightColor + emissive;\n\n#ifdef DOUBLE_SIDED\n\n vLightBack = vLightBack * diffuse + ambient * ambientLightColor + emissive;\n\n#endif";
15147
+
15148
+ // File:src/renderers/shaders/ShaderChunk/map_particle_pars_fragment.glsl
15149
+
15150
+ THREE.ShaderChunk[ 'map_particle_pars_fragment'] = "#ifdef USE_MAP\n\n uniform sampler2D map;\n\n#endif";
15151
+
15152
+ // File:src/renderers/shaders/ShaderChunk/default_vertex.glsl
15153
+
15154
+ THREE.ShaderChunk[ 'default_vertex'] = "vec4 mvPosition;\n\n#ifdef USE_SKINNING\n\n mvPosition = modelViewMatrix * skinned;\n\n#endif\n\n#if !defined( USE_SKINNING ) && defined( USE_MORPHTARGETS )\n\n mvPosition = modelViewMatrix * vec4( morphed, 1.0 );\n\n#endif\n\n#if !defined( USE_SKINNING ) && ! defined( USE_MORPHTARGETS )\n\n mvPosition = modelViewMatrix * vec4( position, 1.0 );\n\n#endif\n\ngl_Position = projectionMatrix * mvPosition;";
15155
+
15156
+ // File:src/renderers/shaders/ShaderChunk/map_pars_fragment.glsl
15157
+
15158
+ THREE.ShaderChunk[ 'map_pars_fragment'] = "#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP )\n\n varying vec2 vUv;\n\n#endif\n\n#ifdef USE_MAP\n\n uniform sampler2D map;\n\n#endif";
15159
+
15160
+ // File:src/renderers/shaders/ShaderChunk/skinnormal_vertex.glsl
15161
+
15162
+ THREE.ShaderChunk[ 'skinnormal_vertex'] = "#ifdef USE_SKINNING\n\n mat4 skinMatrix = mat4( 0.0 );\n skinMatrix += skinWeight.x * boneMatX;\n skinMatrix += skinWeight.y * boneMatY;\n skinMatrix += skinWeight.z * boneMatZ;\n skinMatrix += skinWeight.w * boneMatW;\n skinMatrix = bindMatrixInverse * skinMatrix * bindMatrix;\n\n #ifdef USE_MORPHNORMALS\n\n vec4 skinnedNormal = skinMatrix * vec4( morphedNormal, 0.0 );\n\n #else\n\n vec4 skinnedNormal = skinMatrix * vec4( normal, 0.0 );\n\n #endif\n\n#endif\n";
15163
+
15164
+ // File:src/renderers/shaders/ShaderChunk/logdepthbuf_pars_vertex.glsl
15165
+
15166
+ THREE.ShaderChunk[ 'logdepthbuf_pars_vertex'] = "#ifdef USE_LOGDEPTHBUF\n\n #ifdef USE_LOGDEPTHBUF_EXT\n\n varying float vFragDepth;\n\n #endif\n\n uniform float logDepthBufFC;\n\n#endif";
15167
+
15168
+ // File:src/renderers/shaders/ShaderChunk/lightmap_pars_vertex.glsl
15169
+
15170
+ THREE.ShaderChunk[ 'lightmap_pars_vertex'] = "#ifdef USE_LIGHTMAP\n\n varying vec2 vUv2;\n\n#endif";
15171
+
15172
+ // File:src/renderers/shaders/ShaderChunk/lights_phong_fragment.glsl
15173
+
15174
+ THREE.ShaderChunk[ 'lights_phong_fragment'] = "vec3 normal = normalize( vNormal );\nvec3 viewPosition = normalize( vViewPosition );\n\n#ifdef DOUBLE_SIDED\n\n normal = normal * ( -1.0 + 2.0 * float( gl_FrontFacing ) );\n\n#endif\n\n#ifdef USE_NORMALMAP\n\n normal = perturbNormal2Arb( -vViewPosition, normal );\n\n#elif defined( USE_BUMPMAP )\n\n normal = perturbNormalArb( -vViewPosition, normal, dHdxy_fwd() );\n\n#endif\n\n#if MAX_POINT_LIGHTS > 0\n\n vec3 pointDiffuse = vec3( 0.0 );\n vec3 pointSpecular = vec3( 0.0 );\n\n for ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {\n\n vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );\n vec3 lVector = lPosition.xyz + vViewPosition.xyz;\n\n float lDistance = 1.0;\n if ( pointLightDistance[ i ] > 0.0 )\n lDistance = 1.0 - min( ( length( lVector ) / pointLightDistance[ i ] ), 1.0 );\n\n lVector = normalize( lVector );\n\n // diffuse\n\n float dotProduct = dot( normal, lVector );\n\n #ifdef WRAP_AROUND\n\n float pointDiffuseWeightFull = max( dotProduct, 0.0 );\n float pointDiffuseWeightHalf = max( 0.5 * dotProduct + 0.5, 0.0 );\n\n vec3 pointDiffuseWeight = mix( vec3( pointDiffuseWeightFull ), vec3( pointDiffuseWeightHalf ), wrapRGB );\n\n #else\n\n float pointDiffuseWeight = max( dotProduct, 0.0 );\n\n #endif\n\n pointDiffuse += diffuse * pointLightColor[ i ] * pointDiffuseWeight * lDistance;\n\n // specular\n\n vec3 pointHalfVector = normalize( lVector + viewPosition );\n float pointDotNormalHalf = max( dot( normal, pointHalfVector ), 0.0 );\n float pointSpecularWeight = specularStrength * max( pow( pointDotNormalHalf, shininess ), 0.0 );\n\n float specularNormalization = ( shininess + 2.0 ) / 8.0;\n\n vec3 schlick = specular + vec3( 1.0 - specular ) * pow( max( 1.0 - dot( lVector, pointHalfVector ), 0.0 ), 5.0 );\n pointSpecular += schlick * pointLightColor[ i ] * pointSpecularWeight * pointDiffuseWeight * lDistance * specularNormalization;\n\n }\n\n#endif\n\n#if MAX_SPOT_LIGHTS > 0\n\n vec3 spotDiffuse = vec3( 0.0 );\n vec3 spotSpecular = vec3( 0.0 );\n\n for ( int i = 0; i < MAX_SPOT_LIGHTS; i ++ ) {\n\n vec4 lPosition = viewMatrix * vec4( spotLightPosition[ i ], 1.0 );\n vec3 lVector = lPosition.xyz + vViewPosition.xyz;\n\n float lDistance = 1.0;\n if ( spotLightDistance[ i ] > 0.0 )\n lDistance = 1.0 - min( ( length( lVector ) / spotLightDistance[ i ] ), 1.0 );\n\n lVector = normalize( lVector );\n\n float spotEffect = dot( spotLightDirection[ i ], normalize( spotLightPosition[ i ] - vWorldPosition ) );\n\n if ( spotEffect > spotLightAngleCos[ i ] ) {\n\n spotEffect = max( pow( max( spotEffect, 0.0 ), spotLightExponent[ i ] ), 0.0 );\n\n // diffuse\n\n float dotProduct = dot( normal, lVector );\n\n #ifdef WRAP_AROUND\n\n float spotDiffuseWeightFull = max( dotProduct, 0.0 );\n float spotDiffuseWeightHalf = max( 0.5 * dotProduct + 0.5, 0.0 );\n\n vec3 spotDiffuseWeight = mix( vec3( spotDiffuseWeightFull ), vec3( spotDiffuseWeightHalf ), wrapRGB );\n\n #else\n\n float spotDiffuseWeight = max( dotProduct, 0.0 );\n\n #endif\n\n spotDiffuse += diffuse * spotLightColor[ i ] * spotDiffuseWeight * lDistance * spotEffect;\n\n // specular\n\n vec3 spotHalfVector = normalize( lVector + viewPosition );\n float spotDotNormalHalf = max( dot( normal, spotHalfVector ), 0.0 );\n float spotSpecularWeight = specularStrength * max( pow( spotDotNormalHalf, shininess ), 0.0 );\n\n float specularNormalization = ( shininess + 2.0 ) / 8.0;\n\n vec3 schlick = specular + vec3( 1.0 - specular ) * pow( max( 1.0 - dot( lVector, spotHalfVector ), 0.0 ), 5.0 );\n spotSpecular += schlick * spotLightColor[ i ] * spotSpecularWeight * spotDiffuseWeight * lDistance * specularNormalization * spotEffect;\n\n }\n\n }\n\n#endif\n\n#if MAX_DIR_LIGHTS > 0\n\n vec3 dirDiffuse = vec3( 0.0 );\n vec3 dirSpecular = vec3( 0.0 );\n\n for( int i = 0; i < MAX_DIR_LIGHTS; i ++ ) {\n\n vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );\n vec3 dirVector = normalize( lDirection.xyz );\n\n // diffuse\n\n float dotProduct = dot( normal, dirVector );\n\n #ifdef WRAP_AROUND\n\n float dirDiffuseWeightFull = max( dotProduct, 0.0 );\n float dirDiffuseWeightHalf = max( 0.5 * dotProduct + 0.5, 0.0 );\n\n vec3 dirDiffuseWeight = mix( vec3( dirDiffuseWeightFull ), vec3( dirDiffuseWeightHalf ), wrapRGB );\n\n #else\n\n float dirDiffuseWeight = max( dotProduct, 0.0 );\n\n #endif\n\n dirDiffuse += diffuse * directionalLightColor[ i ] * dirDiffuseWeight;\n\n // specular\n\n vec3 dirHalfVector = normalize( dirVector + viewPosition );\n float dirDotNormalHalf = max( dot( normal, dirHalfVector ), 0.0 );\n float dirSpecularWeight = specularStrength * max( pow( dirDotNormalHalf, shininess ), 0.0 );\n\n /*\n // fresnel term from skin shader\n const float F0 = 0.128;\n\n float base = 1.0 - dot( viewPosition, dirHalfVector );\n float exponential = pow( base, 5.0 );\n\n float fresnel = exponential + F0 * ( 1.0 - exponential );\n */\n\n /*\n // fresnel term from fresnel shader\n const float mFresnelBias = 0.08;\n const float mFresnelScale = 0.3;\n const float mFresnelPower = 5.0;\n\n float fresnel = mFresnelBias + mFresnelScale * pow( 1.0 + dot( normalize( -viewPosition ), normal ), mFresnelPower );\n */\n\n float specularNormalization = ( shininess + 2.0 ) / 8.0;\n\n // dirSpecular += specular * directionalLightColor[ i ] * dirSpecularWeight * dirDiffuseWeight * specularNormalization * fresnel;\n\n vec3 schlick = specular + vec3( 1.0 - specular ) * pow( max( 1.0 - dot( dirVector, dirHalfVector ), 0.0 ), 5.0 );\n dirSpecular += schlick * directionalLightColor[ i ] * dirSpecularWeight * dirDiffuseWeight * specularNormalization;\n\n\n }\n\n#endif\n\n#if MAX_HEMI_LIGHTS > 0\n\n vec3 hemiDiffuse = vec3( 0.0 );\n vec3 hemiSpecular = vec3( 0.0 );\n\n for( int i = 0; i < MAX_HEMI_LIGHTS; i ++ ) {\n\n vec4 lDirection = viewMatrix * vec4( hemisphereLightDirection[ i ], 0.0 );\n vec3 lVector = normalize( lDirection.xyz );\n\n // diffuse\n\n float dotProduct = dot( normal, lVector );\n float hemiDiffuseWeight = 0.5 * dotProduct + 0.5;\n\n vec3 hemiColor = mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeight );\n\n hemiDiffuse += diffuse * hemiColor;\n\n // specular (sky light)\n\n vec3 hemiHalfVectorSky = normalize( lVector + viewPosition );\n float hemiDotNormalHalfSky = 0.5 * dot( normal, hemiHalfVectorSky ) + 0.5;\n float hemiSpecularWeightSky = specularStrength * max( pow( max( hemiDotNormalHalfSky, 0.0 ), shininess ), 0.0 );\n\n // specular (ground light)\n\n vec3 lVectorGround = -lVector;\n\n vec3 hemiHalfVectorGround = normalize( lVectorGround + viewPosition );\n float hemiDotNormalHalfGround = 0.5 * dot( normal, hemiHalfVectorGround ) + 0.5;\n float hemiSpecularWeightGround = specularStrength * max( pow( max( hemiDotNormalHalfGround, 0.0 ), shininess ), 0.0 );\n\n float dotProductGround = dot( normal, lVectorGround );\n\n float specularNormalization = ( shininess + 2.0 ) / 8.0;\n\n vec3 schlickSky = specular + vec3( 1.0 - specular ) * pow( max( 1.0 - dot( lVector, hemiHalfVectorSky ), 0.0 ), 5.0 );\n vec3 schlickGround = specular + vec3( 1.0 - specular ) * pow( max( 1.0 - dot( lVectorGround, hemiHalfVectorGround ), 0.0 ), 5.0 );\n hemiSpecular += hemiColor * specularNormalization * ( schlickSky * hemiSpecularWeightSky * max( dotProduct, 0.0 ) + schlickGround * hemiSpecularWeightGround * max( dotProductGround, 0.0 ) );\n\n }\n\n#endif\n\nvec3 totalDiffuse = vec3( 0.0 );\nvec3 totalSpecular = vec3( 0.0 );\n\n#if MAX_DIR_LIGHTS > 0\n\n totalDiffuse += dirDiffuse;\n totalSpecular += dirSpecular;\n\n#endif\n\n#if MAX_HEMI_LIGHTS > 0\n\n totalDiffuse += hemiDiffuse;\n totalSpecular += hemiSpecular;\n\n#endif\n\n#if MAX_POINT_LIGHTS > 0\n\n totalDiffuse += pointDiffuse;\n totalSpecular += pointSpecular;\n\n#endif\n\n#if MAX_SPOT_LIGHTS > 0\n\n totalDiffuse += spotDiffuse;\n totalSpecular += spotSpecular;\n\n#endif\n\n#ifdef METAL\n\n gl_FragColor.xyz = gl_FragColor.xyz * ( emissive + totalDiffuse + ambientLightColor * ambient + totalSpecular );\n\n#else\n\n gl_FragColor.xyz = gl_FragColor.xyz * ( emissive + totalDiffuse + ambientLightColor * ambient ) + totalSpecular;\n\n#endif";
15175
+
15176
+ // File:src/renderers/shaders/ShaderChunk/fog_pars_fragment.glsl
15177
+
15178
+ THREE.ShaderChunk[ 'fog_pars_fragment'] = "#ifdef USE_FOG\n\n uniform vec3 fogColor;\n\n #ifdef FOG_EXP2\n\n uniform float fogDensity;\n\n #else\n\n uniform float fogNear;\n uniform float fogFar;\n #endif\n\n#endif";
15179
+
15180
+ // File:src/renderers/shaders/ShaderChunk/morphnormal_vertex.glsl
15181
+
15182
+ THREE.ShaderChunk[ 'morphnormal_vertex'] = "#ifdef USE_MORPHNORMALS\n\n vec3 morphedNormal = vec3( 0.0 );\n\n morphedNormal += ( morphNormal0 - normal ) * morphTargetInfluences[ 0 ];\n morphedNormal += ( morphNormal1 - normal ) * morphTargetInfluences[ 1 ];\n morphedNormal += ( morphNormal2 - normal ) * morphTargetInfluences[ 2 ];\n morphedNormal += ( morphNormal3 - normal ) * morphTargetInfluences[ 3 ];\n\n morphedNormal += normal;\n\n#endif";
15183
+
15184
+ // File:src/renderers/shaders/ShaderChunk/envmap_pars_fragment.glsl
15185
+
15186
+ THREE.ShaderChunk[ 'envmap_pars_fragment'] = "#ifdef USE_ENVMAP\n\n uniform float reflectivity;\n uniform samplerCube envMap;\n uniform float flipEnvMap;\n uniform int combine;\n\n #if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG )\n\n uniform bool useRefract;\n uniform float refractionRatio;\n\n #else\n\n varying vec3 vReflect;\n\n #endif\n\n#endif";
15187
+
15188
+ // File:src/renderers/shaders/ShaderChunk/logdepthbuf_fragment.glsl
15189
+
15190
+ THREE.ShaderChunk[ 'logdepthbuf_fragment'] = "#if defined(USE_LOGDEPTHBUF) && defined(USE_LOGDEPTHBUF_EXT)\n\n gl_FragDepthEXT = log2(vFragDepth) * logDepthBufFC * 0.5;\n\n#endif";
15191
+
15192
+ // File:src/renderers/shaders/ShaderChunk/normalmap_pars_fragment.glsl
15193
+
15194
+ THREE.ShaderChunk[ 'normalmap_pars_fragment'] = "#ifdef USE_NORMALMAP\n\n uniform sampler2D normalMap;\n uniform vec2 normalScale;\n\n // Per-Pixel Tangent Space Normal Mapping\n // http://hacksoflife.blogspot.ch/2009/11/per-pixel-tangent-space-normal-mapping.html\n\n vec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm ) {\n\n vec3 q0 = dFdx( eye_pos.xyz );\n vec3 q1 = dFdy( eye_pos.xyz );\n vec2 st0 = dFdx( vUv.st );\n vec2 st1 = dFdy( vUv.st );\n\n vec3 S = normalize( q0 * st1.t - q1 * st0.t );\n vec3 T = normalize( -q0 * st1.s + q1 * st0.s );\n vec3 N = normalize( surf_norm );\n\n vec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\n mapN.xy = normalScale * mapN.xy;\n mat3 tsn = mat3( S, T, N );\n return normalize( tsn * mapN );\n\n }\n\n#endif\n";
15195
+
15196
+ // File:src/renderers/shaders/ShaderChunk/lights_phong_pars_vertex.glsl
15197
+
15198
+ THREE.ShaderChunk[ 'lights_phong_pars_vertex'] = "#if MAX_SPOT_LIGHTS > 0 || defined( USE_BUMPMAP ) || defined( USE_ENVMAP )\n\n varying vec3 vWorldPosition;\n\n#endif\n";
15199
+
15200
+ // File:src/renderers/shaders/ShaderChunk/lightmap_pars_fragment.glsl
15201
+
15202
+ THREE.ShaderChunk[ 'lightmap_pars_fragment'] = "#ifdef USE_LIGHTMAP\n\n varying vec2 vUv2;\n uniform sampler2D lightMap;\n\n#endif";
15203
+
15204
+ // File:src/renderers/shaders/ShaderChunk/shadowmap_vertex.glsl
15205
+
15206
+ THREE.ShaderChunk[ 'shadowmap_vertex'] = "#ifdef USE_SHADOWMAP\n\n for( int i = 0; i < MAX_SHADOWS; i ++ ) {\n\n vShadowCoord[ i ] = shadowMatrix[ i ] * worldPosition;\n\n }\n\n#endif";
15207
+
15208
+ // File:src/renderers/shaders/ShaderChunk/lights_phong_vertex.glsl
15209
+
15210
+ THREE.ShaderChunk[ 'lights_phong_vertex'] = "#if MAX_SPOT_LIGHTS > 0 || defined( USE_BUMPMAP ) || defined( USE_ENVMAP )\n\n vWorldPosition = worldPosition.xyz;\n\n#endif";
15211
+
15212
+ // File:src/renderers/shaders/ShaderChunk/map_fragment.glsl
15213
+
15214
+ THREE.ShaderChunk[ 'map_fragment'] = "#ifdef USE_MAP\n\n vec4 texelColor = texture2D( map, vUv );\n\n #ifdef GAMMA_INPUT\n\n texelColor.xyz *= texelColor.xyz;\n\n #endif\n\n gl_FragColor = gl_FragColor * texelColor;\n\n#endif";
15215
+
15216
+ // File:src/renderers/shaders/ShaderChunk/lightmap_vertex.glsl
15217
+
15218
+ THREE.ShaderChunk[ 'lightmap_vertex'] = "#ifdef USE_LIGHTMAP\n\n vUv2 = uv2;\n\n#endif";
15219
+
15220
+ // File:src/renderers/shaders/ShaderChunk/map_particle_fragment.glsl
15221
+
15222
+ THREE.ShaderChunk[ 'map_particle_fragment'] = "#ifdef USE_MAP\n\n gl_FragColor = gl_FragColor * texture2D( map, vec2( gl_PointCoord.x, 1.0 - gl_PointCoord.y ) );\n\n#endif";
15223
+
15224
+ // File:src/renderers/shaders/ShaderChunk/color_pars_fragment.glsl
15225
+
15226
+ THREE.ShaderChunk[ 'color_pars_fragment'] = "#ifdef USE_COLOR\n\n varying vec3 vColor;\n\n#endif\n";
15227
+
15228
+ // File:src/renderers/shaders/ShaderChunk/color_vertex.glsl
15229
+
15230
+ THREE.ShaderChunk[ 'color_vertex'] = "#ifdef USE_COLOR\n\n #ifdef GAMMA_INPUT\n\n vColor = color * color;\n\n #else\n\n vColor = color;\n\n #endif\n\n#endif";
15231
+
15232
+ // File:src/renderers/shaders/ShaderChunk/skinning_vertex.glsl
15233
+
15234
+ THREE.ShaderChunk[ 'skinning_vertex'] = "#ifdef USE_SKINNING\n\n #ifdef USE_MORPHTARGETS\n\n vec4 skinVertex = bindMatrix * vec4( morphed, 1.0 );\n\n #else\n\n vec4 skinVertex = bindMatrix * vec4( position, 1.0 );\n\n #endif\n\n vec4 skinned = vec4( 0.0 );\n skinned += boneMatX * skinVertex * skinWeight.x;\n skinned += boneMatY * skinVertex * skinWeight.y;\n skinned += boneMatZ * skinVertex * skinWeight.z;\n skinned += boneMatW * skinVertex * skinWeight.w;\n skinned = bindMatrixInverse * skinned;\n\n#endif\n";
15235
+
15236
+ // File:src/renderers/shaders/ShaderChunk/envmap_pars_vertex.glsl
15237
+
15238
+ THREE.ShaderChunk[ 'envmap_pars_vertex'] = "#if defined( USE_ENVMAP ) && ! defined( USE_BUMPMAP ) && ! defined( USE_NORMALMAP ) && ! defined( PHONG )\n\n varying vec3 vReflect;\n\n uniform float refractionRatio;\n uniform bool useRefract;\n\n#endif\n";
15239
+
15240
+ // File:src/renderers/shaders/ShaderChunk/linear_to_gamma_fragment.glsl
15241
+
15242
+ THREE.ShaderChunk[ 'linear_to_gamma_fragment'] = "#ifdef GAMMA_OUTPUT\n\n gl_FragColor.xyz = sqrt( gl_FragColor.xyz );\n\n#endif";
15243
+
15244
+ // File:src/renderers/shaders/ShaderChunk/color_pars_vertex.glsl
15245
+
15246
+ THREE.ShaderChunk[ 'color_pars_vertex'] = "#ifdef USE_COLOR\n\n varying vec3 vColor;\n\n#endif";
15247
+
15248
+ // File:src/renderers/shaders/ShaderChunk/lights_lambert_pars_vertex.glsl
15249
+
15250
+ THREE.ShaderChunk[ 'lights_lambert_pars_vertex'] = "uniform vec3 ambient;\nuniform vec3 diffuse;\nuniform vec3 emissive;\n\nuniform vec3 ambientLightColor;\n\n#if MAX_DIR_LIGHTS > 0\n\n uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];\n uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];\n\n#endif\n\n#if MAX_HEMI_LIGHTS > 0\n\n uniform vec3 hemisphereLightSkyColor[ MAX_HEMI_LIGHTS ];\n uniform vec3 hemisphereLightGroundColor[ MAX_HEMI_LIGHTS ];\n uniform vec3 hemisphereLightDirection[ MAX_HEMI_LIGHTS ];\n\n#endif\n\n#if MAX_POINT_LIGHTS > 0\n\n uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];\n uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];\n uniform float pointLightDistance[ MAX_POINT_LIGHTS ];\n\n#endif\n\n#if MAX_SPOT_LIGHTS > 0\n\n uniform vec3 spotLightColor[ MAX_SPOT_LIGHTS ];\n uniform vec3 spotLightPosition[ MAX_SPOT_LIGHTS ];\n uniform vec3 spotLightDirection[ MAX_SPOT_LIGHTS ];\n uniform float spotLightDistance[ MAX_SPOT_LIGHTS ];\n uniform float spotLightAngleCos[ MAX_SPOT_LIGHTS ];\n uniform float spotLightExponent[ MAX_SPOT_LIGHTS ];\n\n#endif\n\n#ifdef WRAP_AROUND\n\n uniform vec3 wrapRGB;\n\n#endif\n";
15251
+
15252
+ // File:src/renderers/shaders/ShaderChunk/map_pars_vertex.glsl
15253
+
15254
+ THREE.ShaderChunk[ 'map_pars_vertex'] = "#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP )\n\n varying vec2 vUv;\n uniform vec4 offsetRepeat;\n\n#endif\n";
15255
+
15256
+ // File:src/renderers/shaders/ShaderChunk/envmap_fragment.glsl
15257
+
15258
+ THREE.ShaderChunk[ 'envmap_fragment'] = "#ifdef USE_ENVMAP\n\n vec3 reflectVec;\n\n #if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG )\n\n vec3 cameraToVertex = normalize( vWorldPosition - cameraPosition );\n\n // http://en.wikibooks.org/wiki/GLSL_Programming/Applying_Matrix_Transformations\n // Transforming Normal Vectors with the Inverse Transformation\n\n vec3 worldNormal = normalize( vec3( vec4( normal, 0.0 ) * viewMatrix ) );\n\n if ( useRefract ) {\n\n reflectVec = refract( cameraToVertex, worldNormal, refractionRatio );\n\n } else { \n\n reflectVec = reflect( cameraToVertex, worldNormal );\n\n }\n\n #else\n\n reflectVec = vReflect;\n\n #endif\n\n #ifdef DOUBLE_SIDED\n\n float flipNormal = ( -1.0 + 2.0 * float( gl_FrontFacing ) );\n vec4 cubeColor = textureCube( envMap, flipNormal * vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );\n\n #else\n\n vec4 cubeColor = textureCube( envMap, vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );\n\n #endif\n\n #ifdef GAMMA_INPUT\n\n cubeColor.xyz *= cubeColor.xyz;\n\n #endif\n\n if ( combine == 1 ) {\n\n gl_FragColor.xyz = mix( gl_FragColor.xyz, cubeColor.xyz, specularStrength * reflectivity );\n\n } else if ( combine == 2 ) {\n\n gl_FragColor.xyz += cubeColor.xyz * specularStrength * reflectivity;\n\n } else {\n\n gl_FragColor.xyz = mix( gl_FragColor.xyz, gl_FragColor.xyz * cubeColor.xyz, specularStrength * reflectivity );\n\n }\n\n#endif";
15259
+
15260
+ // File:src/renderers/shaders/ShaderChunk/specularmap_pars_fragment.glsl
15261
+
15262
+ THREE.ShaderChunk[ 'specularmap_pars_fragment'] = "#ifdef USE_SPECULARMAP\n\n uniform sampler2D specularMap;\n\n#endif";
15263
+
15264
+ // File:src/renderers/shaders/ShaderChunk/logdepthbuf_vertex.glsl
15265
+
15266
+ THREE.ShaderChunk[ 'logdepthbuf_vertex'] = "#ifdef USE_LOGDEPTHBUF\n\n gl_Position.z = log2(max(1e-6, gl_Position.w + 1.0)) * logDepthBufFC;\n\n #ifdef USE_LOGDEPTHBUF_EXT\n\n vFragDepth = 1.0 + gl_Position.w;\n\n#else\n\n gl_Position.z = (gl_Position.z - 1.0) * gl_Position.w;\n\n #endif\n\n#endif";
15267
+
15268
+ // File:src/renderers/shaders/ShaderChunk/morphtarget_pars_vertex.glsl
15269
+
15270
+ THREE.ShaderChunk[ 'morphtarget_pars_vertex'] = "#ifdef USE_MORPHTARGETS\n\n #ifndef USE_MORPHNORMALS\n\n uniform float morphTargetInfluences[ 8 ];\n\n #else\n\n uniform float morphTargetInfluences[ 4 ];\n\n #endif\n\n#endif";
15271
+
15272
+ // File:src/renderers/shaders/ShaderChunk/specularmap_fragment.glsl
15273
+
15274
+ THREE.ShaderChunk[ 'specularmap_fragment'] = "float specularStrength;\n\n#ifdef USE_SPECULARMAP\n\n vec4 texelSpecular = texture2D( specularMap, vUv );\n specularStrength = texelSpecular.r;\n\n#else\n\n specularStrength = 1.0;\n\n#endif";
15275
+
15276
+ // File:src/renderers/shaders/ShaderChunk/fog_fragment.glsl
15277
+
15278
+ THREE.ShaderChunk[ 'fog_fragment'] = "#ifdef USE_FOG\n\n #ifdef USE_LOGDEPTHBUF_EXT\n\n float depth = gl_FragDepthEXT / gl_FragCoord.w;\n\n #else\n\n float depth = gl_FragCoord.z / gl_FragCoord.w;\n\n #endif\n\n #ifdef FOG_EXP2\n\n const float LOG2 = 1.442695;\n float fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );\n fogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );\n\n #else\n\n float fogFactor = smoothstep( fogNear, fogFar, depth );\n\n #endif\n \n gl_FragColor = mix( gl_FragColor, vec4( fogColor, gl_FragColor.w ), fogFactor );\n\n#endif";
15279
+
15280
+ // File:src/renderers/shaders/ShaderChunk/bumpmap_pars_fragment.glsl
15281
+
15282
+ THREE.ShaderChunk[ 'bumpmap_pars_fragment'] = "#ifdef USE_BUMPMAP\n\n uniform sampler2D bumpMap;\n uniform float bumpScale;\n\n // Derivative maps - bump mapping unparametrized surfaces by Morten Mikkelsen\n // http://mmikkelsen3d.blogspot.sk/2011/07/derivative-maps.html\n\n // Evaluate the derivative of the height w.r.t. screen-space using forward differencing (listing 2)\n\n vec2 dHdxy_fwd() {\n\n vec2 dSTdx = dFdx( vUv );\n vec2 dSTdy = dFdy( vUv );\n\n float Hll = bumpScale * texture2D( bumpMap, vUv ).x;\n float dBx = bumpScale * texture2D( bumpMap, vUv + dSTdx ).x - Hll;\n float dBy = bumpScale * texture2D( bumpMap, vUv + dSTdy ).x - Hll;\n\n return vec2( dBx, dBy );\n\n }\n\n vec3 perturbNormalArb( vec3 surf_pos, vec3 surf_norm, vec2 dHdxy ) {\n\n vec3 vSigmaX = dFdx( surf_pos );\n vec3 vSigmaY = dFdy( surf_pos );\n vec3 vN = surf_norm; // normalized\n\n vec3 R1 = cross( vSigmaY, vN );\n vec3 R2 = cross( vN, vSigmaX );\n\n float fDet = dot( vSigmaX, R1 );\n\n vec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 );\n return normalize( abs( fDet ) * surf_norm - vGrad );\n\n }\n\n#endif";
15283
+
15284
+ // File:src/renderers/shaders/ShaderChunk/defaultnormal_vertex.glsl
15285
+
15286
+ THREE.ShaderChunk[ 'defaultnormal_vertex'] = "vec3 objectNormal;\n\n#ifdef USE_SKINNING\n\n objectNormal = skinnedNormal.xyz;\n\n#endif\n\n#if !defined( USE_SKINNING ) && defined( USE_MORPHNORMALS )\n\n objectNormal = morphedNormal;\n\n#endif\n\n#if !defined( USE_SKINNING ) && ! defined( USE_MORPHNORMALS )\n\n objectNormal = normal;\n\n#endif\n\n#ifdef FLIP_SIDED\n\n objectNormal = -objectNormal;\n\n#endif\n\nvec3 transformedNormal = normalMatrix * objectNormal;";
15287
+
15288
+ // File:src/renderers/shaders/ShaderChunk/lights_phong_pars_fragment.glsl
15289
+
15290
+ THREE.ShaderChunk[ 'lights_phong_pars_fragment'] = "uniform vec3 ambientLightColor;\n\n#if MAX_DIR_LIGHTS > 0\n\n uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];\n uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];\n\n#endif\n\n#if MAX_HEMI_LIGHTS > 0\n\n uniform vec3 hemisphereLightSkyColor[ MAX_HEMI_LIGHTS ];\n uniform vec3 hemisphereLightGroundColor[ MAX_HEMI_LIGHTS ];\n uniform vec3 hemisphereLightDirection[ MAX_HEMI_LIGHTS ];\n\n#endif\n\n#if MAX_POINT_LIGHTS > 0\n\n uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];\n\n uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];\n uniform float pointLightDistance[ MAX_POINT_LIGHTS ];\n\n#endif\n\n#if MAX_SPOT_LIGHTS > 0\n\n uniform vec3 spotLightColor[ MAX_SPOT_LIGHTS ];\n uniform vec3 spotLightPosition[ MAX_SPOT_LIGHTS ];\n uniform vec3 spotLightDirection[ MAX_SPOT_LIGHTS ];\n uniform float spotLightAngleCos[ MAX_SPOT_LIGHTS ];\n uniform float spotLightExponent[ MAX_SPOT_LIGHTS ];\n\n uniform float spotLightDistance[ MAX_SPOT_LIGHTS ];\n\n#endif\n\n#if MAX_SPOT_LIGHTS > 0 || defined( USE_BUMPMAP ) || defined( USE_ENVMAP )\n\n varying vec3 vWorldPosition;\n\n#endif\n\n#ifdef WRAP_AROUND\n\n uniform vec3 wrapRGB;\n\n#endif\n\nvarying vec3 vViewPosition;\nvarying vec3 vNormal;";
15291
+
15292
+ // File:src/renderers/shaders/ShaderChunk/skinbase_vertex.glsl
15293
+
15294
+ THREE.ShaderChunk[ 'skinbase_vertex'] = "#ifdef USE_SKINNING\n\n mat4 boneMatX = getBoneMatrix( skinIndex.x );\n mat4 boneMatY = getBoneMatrix( skinIndex.y );\n mat4 boneMatZ = getBoneMatrix( skinIndex.z );\n mat4 boneMatW = getBoneMatrix( skinIndex.w );\n\n#endif";
15295
+
15296
+ // File:src/renderers/shaders/ShaderChunk/map_vertex.glsl
15297
+
15298
+ THREE.ShaderChunk[ 'map_vertex'] = "#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP )\n\n vUv = uv * offsetRepeat.zw + offsetRepeat.xy;\n\n#endif";
15299
+
15300
+ // File:src/renderers/shaders/ShaderChunk/lightmap_fragment.glsl
15301
+
15302
+ THREE.ShaderChunk[ 'lightmap_fragment'] = "#ifdef USE_LIGHTMAP\n\n gl_FragColor = gl_FragColor * texture2D( lightMap, vUv2 );\n\n#endif";
15303
+
15304
+ // File:src/renderers/shaders/ShaderChunk/shadowmap_pars_vertex.glsl
15305
+
15306
+ THREE.ShaderChunk[ 'shadowmap_pars_vertex'] = "#ifdef USE_SHADOWMAP\n\n varying vec4 vShadowCoord[ MAX_SHADOWS ];\n uniform mat4 shadowMatrix[ MAX_SHADOWS ];\n\n#endif";
15307
+
15308
+ // File:src/renderers/shaders/ShaderChunk/color_fragment.glsl
15309
+
15310
+ THREE.ShaderChunk[ 'color_fragment'] = "#ifdef USE_COLOR\n\n gl_FragColor = gl_FragColor * vec4( vColor, 1.0 );\n\n#endif";
15311
+
15312
+ // File:src/renderers/shaders/ShaderChunk/morphtarget_vertex.glsl
15313
+
15314
+ THREE.ShaderChunk[ 'morphtarget_vertex'] = "#ifdef USE_MORPHTARGETS\n\n vec3 morphed = vec3( 0.0 );\n morphed += ( morphTarget0 - position ) * morphTargetInfluences[ 0 ];\n morphed += ( morphTarget1 - position ) * morphTargetInfluences[ 1 ];\n morphed += ( morphTarget2 - position ) * morphTargetInfluences[ 2 ];\n morphed += ( morphTarget3 - position ) * morphTargetInfluences[ 3 ];\n\n #ifndef USE_MORPHNORMALS\n\n morphed += ( morphTarget4 - position ) * morphTargetInfluences[ 4 ];\n morphed += ( morphTarget5 - position ) * morphTargetInfluences[ 5 ];\n morphed += ( morphTarget6 - position ) * morphTargetInfluences[ 6 ];\n morphed += ( morphTarget7 - position ) * morphTargetInfluences[ 7 ];\n\n #endif\n\n morphed += position;\n\n#endif";
15315
+
15316
+ // File:src/renderers/shaders/ShaderChunk/envmap_vertex.glsl
15317
+
15318
+ THREE.ShaderChunk[ 'envmap_vertex'] = "#if defined( USE_ENVMAP ) && ! defined( USE_BUMPMAP ) && ! defined( USE_NORMALMAP ) && ! defined( PHONG )\n\n vec3 worldNormal = mat3( modelMatrix[ 0 ].xyz, modelMatrix[ 1 ].xyz, modelMatrix[ 2 ].xyz ) * objectNormal;\n worldNormal = normalize( worldNormal );\n\n vec3 cameraToVertex = normalize( worldPosition.xyz - cameraPosition );\n\n if ( useRefract ) {\n\n vReflect = refract( cameraToVertex, worldNormal, refractionRatio );\n\n } else {\n\n vReflect = reflect( cameraToVertex, worldNormal );\n\n }\n\n#endif";
15319
+
15320
+ // File:src/renderers/shaders/ShaderChunk/shadowmap_fragment.glsl
15321
+
15322
+ THREE.ShaderChunk[ 'shadowmap_fragment'] = "#ifdef USE_SHADOWMAP\n\n #ifdef SHADOWMAP_DEBUG\n\n vec3 frustumColors[3];\n frustumColors[0] = vec3( 1.0, 0.5, 0.0 );\n frustumColors[1] = vec3( 0.0, 1.0, 0.8 );\n frustumColors[2] = vec3( 0.0, 0.5, 1.0 );\n\n #endif\n\n #ifdef SHADOWMAP_CASCADE\n\n int inFrustumCount = 0;\n\n #endif\n\n float fDepth;\n vec3 shadowColor = vec3( 1.0 );\n\n for( int i = 0; i < MAX_SHADOWS; i ++ ) {\n\n vec3 shadowCoord = vShadowCoord[ i ].xyz / vShadowCoord[ i ].w;\n\n // if ( something && something ) breaks ATI OpenGL shader compiler\n // if ( all( something, something ) ) using this instead\n\n bvec4 inFrustumVec = bvec4 ( shadowCoord.x >= 0.0, shadowCoord.x <= 1.0, shadowCoord.y >= 0.0, shadowCoord.y <= 1.0 );\n bool inFrustum = all( inFrustumVec );\n\n // don't shadow pixels outside of light frustum\n // use just first frustum (for cascades)\n // don't shadow pixels behind far plane of light frustum\n\n #ifdef SHADOWMAP_CASCADE\n\n inFrustumCount += int( inFrustum );\n bvec3 frustumTestVec = bvec3( inFrustum, inFrustumCount == 1, shadowCoord.z <= 1.0 );\n\n #else\n\n bvec2 frustumTestVec = bvec2( inFrustum, shadowCoord.z <= 1.0 );\n\n #endif\n\n bool frustumTest = all( frustumTestVec );\n\n if ( frustumTest ) {\n\n shadowCoord.z += shadowBias[ i ];\n\n #if defined( SHADOWMAP_TYPE_PCF )\n\n // Percentage-close filtering\n // (9 pixel kernel)\n // http://fabiensanglard.net/shadowmappingPCF/\n\n float shadow = 0.0;\n\n /*\n // nested loops breaks shader compiler / validator on some ATI cards when using OpenGL\n // must enroll loop manually\n\n for ( float y = -1.25; y <= 1.25; y += 1.25 )\n for ( float x = -1.25; x <= 1.25; x += 1.25 ) {\n\n vec4 rgbaDepth = texture2D( shadowMap[ i ], vec2( x * xPixelOffset, y * yPixelOffset ) + shadowCoord.xy );\n\n // doesn't seem to produce any noticeable visual difference compared to simple texture2D lookup\n //vec4 rgbaDepth = texture2DProj( shadowMap[ i ], vec4( vShadowCoord[ i ].w * ( vec2( x * xPixelOffset, y * yPixelOffset ) + shadowCoord.xy ), 0.05, vShadowCoord[ i ].w ) );\n\n float fDepth = unpackDepth( rgbaDepth );\n\n if ( fDepth < shadowCoord.z )\n shadow += 1.0;\n\n }\n\n shadow /= 9.0;\n\n */\n\n const float shadowDelta = 1.0 / 9.0;\n\n float xPixelOffset = 1.0 / shadowMapSize[ i ].x;\n float yPixelOffset = 1.0 / shadowMapSize[ i ].y;\n\n float dx0 = -1.25 * xPixelOffset;\n float dy0 = -1.25 * yPixelOffset;\n float dx1 = 1.25 * xPixelOffset;\n float dy1 = 1.25 * yPixelOffset;\n\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy0 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += shadowDelta;\n\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy0 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += shadowDelta;\n\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy0 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += shadowDelta;\n\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, 0.0 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += shadowDelta;\n\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy ) );\n if ( fDepth < shadowCoord.z ) shadow += shadowDelta;\n\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, 0.0 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += shadowDelta;\n\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy1 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += shadowDelta;\n\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy1 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += shadowDelta;\n\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy1 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += shadowDelta;\n\n shadowColor = shadowColor * vec3( ( 1.0 - shadowDarkness[ i ] * shadow ) );\n\n #elif defined( SHADOWMAP_TYPE_PCF_SOFT )\n\n // Percentage-close filtering\n // (9 pixel kernel)\n // http://fabiensanglard.net/shadowmappingPCF/\n\n float shadow = 0.0;\n\n float xPixelOffset = 1.0 / shadowMapSize[ i ].x;\n float yPixelOffset = 1.0 / shadowMapSize[ i ].y;\n\n float dx0 = -1.0 * xPixelOffset;\n float dy0 = -1.0 * yPixelOffset;\n float dx1 = 1.0 * xPixelOffset;\n float dy1 = 1.0 * yPixelOffset;\n\n mat3 shadowKernel;\n mat3 depthKernel;\n\n depthKernel[0][0] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy0 ) ) );\n depthKernel[0][1] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, 0.0 ) ) );\n depthKernel[0][2] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy1 ) ) );\n depthKernel[1][0] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy0 ) ) );\n depthKernel[1][1] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy ) );\n depthKernel[1][2] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy1 ) ) );\n depthKernel[2][0] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy0 ) ) );\n depthKernel[2][1] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, 0.0 ) ) );\n depthKernel[2][2] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy1 ) ) );\n\n vec3 shadowZ = vec3( shadowCoord.z );\n shadowKernel[0] = vec3(lessThan(depthKernel[0], shadowZ ));\n shadowKernel[0] *= vec3(0.25);\n\n shadowKernel[1] = vec3(lessThan(depthKernel[1], shadowZ ));\n shadowKernel[1] *= vec3(0.25);\n\n shadowKernel[2] = vec3(lessThan(depthKernel[2], shadowZ ));\n shadowKernel[2] *= vec3(0.25);\n\n vec2 fractionalCoord = 1.0 - fract( shadowCoord.xy * shadowMapSize[i].xy );\n\n shadowKernel[0] = mix( shadowKernel[1], shadowKernel[0], fractionalCoord.x );\n shadowKernel[1] = mix( shadowKernel[2], shadowKernel[1], fractionalCoord.x );\n\n vec4 shadowValues;\n shadowValues.x = mix( shadowKernel[0][1], shadowKernel[0][0], fractionalCoord.y );\n shadowValues.y = mix( shadowKernel[0][2], shadowKernel[0][1], fractionalCoord.y );\n shadowValues.z = mix( shadowKernel[1][1], shadowKernel[1][0], fractionalCoord.y );\n shadowValues.w = mix( shadowKernel[1][2], shadowKernel[1][1], fractionalCoord.y );\n\n shadow = dot( shadowValues, vec4( 1.0 ) );\n\n shadowColor = shadowColor * vec3( ( 1.0 - shadowDarkness[ i ] * shadow ) );\n\n #else\n\n vec4 rgbaDepth = texture2D( shadowMap[ i ], shadowCoord.xy );\n float fDepth = unpackDepth( rgbaDepth );\n\n if ( fDepth < shadowCoord.z )\n\n // spot with multiple shadows is darker\n\n shadowColor = shadowColor * vec3( 1.0 - shadowDarkness[ i ] );\n\n // spot with multiple shadows has the same color as single shadow spot\n\n // shadowColor = min( shadowColor, vec3( shadowDarkness[ i ] ) );\n\n #endif\n\n }\n\n\n #ifdef SHADOWMAP_DEBUG\n\n #ifdef SHADOWMAP_CASCADE\n\n if ( inFrustum && inFrustumCount == 1 ) gl_FragColor.xyz *= frustumColors[ i ];\n\n #else\n\n if ( inFrustum ) gl_FragColor.xyz *= frustumColors[ i ];\n\n #endif\n\n #endif\n\n }\n\n #ifdef GAMMA_OUTPUT\n\n shadowColor *= shadowColor;\n\n #endif\n\n gl_FragColor.xyz = gl_FragColor.xyz * shadowColor;\n\n#endif\n";
15323
+
15324
+ // File:src/renderers/shaders/ShaderChunk/worldpos_vertex.glsl
15325
+
15326
+ THREE.ShaderChunk[ 'worldpos_vertex'] = "#if defined( USE_ENVMAP ) || defined( PHONG ) || defined( LAMBERT ) || defined ( USE_SHADOWMAP )\n\n #ifdef USE_SKINNING\n\n vec4 worldPosition = modelMatrix * skinned;\n\n #endif\n\n #if defined( USE_MORPHTARGETS ) && ! defined( USE_SKINNING )\n\n vec4 worldPosition = modelMatrix * vec4( morphed, 1.0 );\n\n #endif\n\n #if ! defined( USE_MORPHTARGETS ) && ! defined( USE_SKINNING )\n\n vec4 worldPosition = modelMatrix * vec4( position, 1.0 );\n\n #endif\n\n#endif";
15327
+
15328
+ // File:src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl
15329
+
15330
+ THREE.ShaderChunk[ 'shadowmap_pars_fragment'] = "#ifdef USE_SHADOWMAP\n\n uniform sampler2D shadowMap[ MAX_SHADOWS ];\n uniform vec2 shadowMapSize[ MAX_SHADOWS ];\n\n uniform float shadowDarkness[ MAX_SHADOWS ];\n uniform float shadowBias[ MAX_SHADOWS ];\n\n varying vec4 vShadowCoord[ MAX_SHADOWS ];\n\n float unpackDepth( const in vec4 rgba_depth ) {\n\n const vec4 bit_shift = vec4( 1.0 / ( 256.0 * 256.0 * 256.0 ), 1.0 / ( 256.0 * 256.0 ), 1.0 / 256.0, 1.0 );\n float depth = dot( rgba_depth, bit_shift );\n return depth;\n\n }\n\n#endif";
15331
+
15332
+ // File:src/renderers/shaders/ShaderChunk/skinning_pars_vertex.glsl
15333
+
15334
+ THREE.ShaderChunk[ 'skinning_pars_vertex'] = "#ifdef USE_SKINNING\n\n uniform mat4 bindMatrix;\n uniform mat4 bindMatrixInverse;\n\n #ifdef BONE_TEXTURE\n\n uniform sampler2D boneTexture;\n uniform int boneTextureWidth;\n uniform int boneTextureHeight;\n\n mat4 getBoneMatrix( const in float i ) {\n\n float j = i * 4.0;\n float x = mod( j, float( boneTextureWidth ) );\n float y = floor( j / float( boneTextureWidth ) );\n\n float dx = 1.0 / float( boneTextureWidth );\n float dy = 1.0 / float( boneTextureHeight );\n\n y = dy * ( y + 0.5 );\n\n vec4 v1 = texture2D( boneTexture, vec2( dx * ( x + 0.5 ), y ) );\n vec4 v2 = texture2D( boneTexture, vec2( dx * ( x + 1.5 ), y ) );\n vec4 v3 = texture2D( boneTexture, vec2( dx * ( x + 2.5 ), y ) );\n vec4 v4 = texture2D( boneTexture, vec2( dx * ( x + 3.5 ), y ) );\n\n mat4 bone = mat4( v1, v2, v3, v4 );\n\n return bone;\n\n }\n\n #else\n\n uniform mat4 boneGlobalMatrices[ MAX_BONES ];\n\n mat4 getBoneMatrix( const in float i ) {\n\n mat4 bone = boneGlobalMatrices[ int(i) ];\n return bone;\n\n }\n\n #endif\n\n#endif\n";
15335
+
15336
+ // File:src/renderers/shaders/ShaderChunk/logdepthbuf_pars_fragment.glsl
15337
+
15338
+ THREE.ShaderChunk[ 'logdepthbuf_pars_fragment'] = "#ifdef USE_LOGDEPTHBUF\n\n uniform float logDepthBufFC;\n\n #ifdef USE_LOGDEPTHBUF_EXT\n\n #extension GL_EXT_frag_depth : enable\n varying float vFragDepth;\n\n #endif\n\n#endif";
15339
+
15340
+ // File:src/renderers/shaders/ShaderChunk/alphamap_fragment.glsl
15341
+
15342
+ THREE.ShaderChunk[ 'alphamap_fragment'] = "#ifdef USE_ALPHAMAP\n\n gl_FragColor.a *= texture2D( alphaMap, vUv ).g;\n\n#endif\n";
15343
+
15344
+ // File:src/renderers/shaders/ShaderChunk/alphamap_pars_fragment.glsl
15345
+
15346
+ THREE.ShaderChunk[ 'alphamap_pars_fragment'] = "#ifdef USE_ALPHAMAP\n\n uniform sampler2D alphaMap;\n\n#endif\n";
15347
+
15348
+ // File:src/renderers/shaders/UniformsUtils.js
15349
+
15350
+ /**
15351
+ * Uniform Utilities
15352
+ */
15353
+
15354
+ THREE.UniformsUtils = {
15355
+
15356
+ merge: function ( uniforms ) {
15357
+
15358
+ var merged = {};
15359
+
15360
+ for ( var u = 0; u < uniforms.length; u ++ ) {
15361
+
15362
+ var tmp = this.clone( uniforms[ u ] );
15363
+
15364
+ for ( var p in tmp ) {
15365
+
15366
+ merged[ p ] = tmp[ p ];
15367
+
15368
+ }
15369
+
15370
+ }
15371
+
15372
+ return merged;
15373
+
15374
+ },
15375
+
15376
+ clone: function ( uniforms_src ) {
15377
+
15378
+ var uniforms_dst = {};
15379
+
15380
+ for ( var u in uniforms_src ) {
15381
+
15382
+ uniforms_dst[ u ] = {};
15383
+
15384
+ for ( var p in uniforms_src[ u ] ) {
15385
+
15386
+ var parameter_src = uniforms_src[ u ][ p ];
15387
+
15388
+ if ( parameter_src instanceof THREE.Color ||
15389
+ parameter_src instanceof THREE.Vector2 ||
15390
+ parameter_src instanceof THREE.Vector3 ||
15391
+ parameter_src instanceof THREE.Vector4 ||
15392
+ parameter_src instanceof THREE.Matrix4 ||
15393
+ parameter_src instanceof THREE.Texture ) {
15394
+
15395
+ uniforms_dst[ u ][ p ] = parameter_src.clone();
15396
+
15397
+ } else if ( parameter_src instanceof Array ) {
15398
+
15399
+ uniforms_dst[ u ][ p ] = parameter_src.slice();
15400
+
15401
+ } else {
15402
+
15403
+ uniforms_dst[ u ][ p ] = parameter_src;
15404
+
15405
+ }
15406
+
15407
+ }
15408
+
15409
+ }
15410
+
15411
+ return uniforms_dst;
15412
+
15413
+ }
15414
+
15415
+ };
15416
+
15417
+ // File:src/renderers/shaders/UniformsLib.js
15418
+
15419
+ /**
15420
+ * Uniforms library for shared webgl shaders
15421
+ */
15422
+
15423
+ THREE.UniformsLib = {
15424
+
15425
+ common: {
15426
+
15427
+ "diffuse" : { type: "c", value: new THREE.Color( 0xeeeeee ) },
15428
+ "opacity" : { type: "f", value: 1.0 },
15429
+
15430
+ "map" : { type: "t", value: null },
15431
+ "offsetRepeat" : { type: "v4", value: new THREE.Vector4( 0, 0, 1, 1 ) },
15432
+
15433
+ "lightMap" : { type: "t", value: null },
15434
+ "specularMap" : { type: "t", value: null },
15435
+ "alphaMap" : { type: "t", value: null },
15436
+
15437
+ "envMap" : { type: "t", value: null },
15438
+ "flipEnvMap" : { type: "f", value: - 1 },
15439
+ "useRefract" : { type: "i", value: 0 },
15440
+ "reflectivity" : { type: "f", value: 1.0 },
15441
+ "refractionRatio" : { type: "f", value: 0.98 },
15442
+ "combine" : { type: "i", value: 0 },
15443
+
15444
+ "morphTargetInfluences" : { type: "f", value: 0 }
15445
+
15446
+ },
15447
+
15448
+ bump: {
15449
+
15450
+ "bumpMap" : { type: "t", value: null },
15451
+ "bumpScale" : { type: "f", value: 1 }
15452
+
15453
+ },
15454
+
15455
+ normalmap: {
15456
+
15457
+ "normalMap" : { type: "t", value: null },
15458
+ "normalScale" : { type: "v2", value: new THREE.Vector2( 1, 1 ) }
15459
+ },
15460
+
15461
+ fog : {
15462
+
15463
+ "fogDensity" : { type: "f", value: 0.00025 },
15464
+ "fogNear" : { type: "f", value: 1 },
15465
+ "fogFar" : { type: "f", value: 2000 },
15466
+ "fogColor" : { type: "c", value: new THREE.Color( 0xffffff ) }
15467
+
15468
+ },
15469
+
15470
+ lights: {
15471
+
15472
+ "ambientLightColor" : { type: "fv", value: [] },
15473
+
15474
+ "directionalLightDirection" : { type: "fv", value: [] },
15475
+ "directionalLightColor" : { type: "fv", value: [] },
15476
+
15477
+ "hemisphereLightDirection" : { type: "fv", value: [] },
15478
+ "hemisphereLightSkyColor" : { type: "fv", value: [] },
15479
+ "hemisphereLightGroundColor" : { type: "fv", value: [] },
15480
+
15481
+ "pointLightColor" : { type: "fv", value: [] },
15482
+ "pointLightPosition" : { type: "fv", value: [] },
15483
+ "pointLightDistance" : { type: "fv1", value: [] },
15484
+
15485
+ "spotLightColor" : { type: "fv", value: [] },
15486
+ "spotLightPosition" : { type: "fv", value: [] },
15487
+ "spotLightDirection" : { type: "fv", value: [] },
15488
+ "spotLightDistance" : { type: "fv1", value: [] },
15489
+ "spotLightAngleCos" : { type: "fv1", value: [] },
15490
+ "spotLightExponent" : { type: "fv1", value: [] }
15491
+
15492
+ },
15493
+
15494
+ particle: {
15495
+
15496
+ "psColor" : { type: "c", value: new THREE.Color( 0xeeeeee ) },
15497
+ "opacity" : { type: "f", value: 1.0 },
15498
+ "size" : { type: "f", value: 1.0 },
15499
+ "scale" : { type: "f", value: 1.0 },
15500
+ "map" : { type: "t", value: null },
15501
+
15502
+ "fogDensity" : { type: "f", value: 0.00025 },
15503
+ "fogNear" : { type: "f", value: 1 },
15504
+ "fogFar" : { type: "f", value: 2000 },
15505
+ "fogColor" : { type: "c", value: new THREE.Color( 0xffffff ) }
15506
+
15507
+ },
15508
+
15509
+ shadowmap: {
15510
+
15511
+ "shadowMap": { type: "tv", value: [] },
15512
+ "shadowMapSize": { type: "v2v", value: [] },
15513
+
15514
+ "shadowBias" : { type: "fv1", value: [] },
15515
+ "shadowDarkness": { type: "fv1", value: [] },
15516
+
15517
+ "shadowMatrix" : { type: "m4v", value: [] }
15518
+
15519
+ }
15520
+
15521
+ };
15522
+
15523
+ // File:src/renderers/shaders/ShaderLib.js
15524
+
15525
+ /**
15526
+ * Webgl Shader Library for three.js
15527
+ *
15528
+ * @author alteredq / http://alteredqualia.com/
15529
+ * @author mrdoob / http://mrdoob.com/
15530
+ * @author mikael emtinger / http://gomo.se/
15531
+ */
15532
+
15533
+
15534
+ THREE.ShaderLib = {
15535
+
15536
+ 'basic': {
15537
+
15538
+ uniforms: THREE.UniformsUtils.merge( [
15539
+
15540
+ THREE.UniformsLib[ "common" ],
15541
+ THREE.UniformsLib[ "fog" ],
15542
+ THREE.UniformsLib[ "shadowmap" ]
15543
+
15544
+ ] ),
15545
+
15546
+ vertexShader: [
15547
+
15548
+ THREE.ShaderChunk[ "map_pars_vertex" ],
15549
+ THREE.ShaderChunk[ "lightmap_pars_vertex" ],
15550
+ THREE.ShaderChunk[ "envmap_pars_vertex" ],
15551
+ THREE.ShaderChunk[ "color_pars_vertex" ],
15552
+ THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
15553
+ THREE.ShaderChunk[ "skinning_pars_vertex" ],
15554
+ THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
15555
+ THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
15556
+
15557
+ "void main() {",
15558
+
15559
+ THREE.ShaderChunk[ "map_vertex" ],
15560
+ THREE.ShaderChunk[ "lightmap_vertex" ],
15561
+ THREE.ShaderChunk[ "color_vertex" ],
15562
+ THREE.ShaderChunk[ "skinbase_vertex" ],
15563
+
15564
+ " #ifdef USE_ENVMAP",
15565
+
15566
+ THREE.ShaderChunk[ "morphnormal_vertex" ],
15567
+ THREE.ShaderChunk[ "skinnormal_vertex" ],
15568
+ THREE.ShaderChunk[ "defaultnormal_vertex" ],
15569
+
15570
+ " #endif",
15571
+
15572
+ THREE.ShaderChunk[ "morphtarget_vertex" ],
15573
+ THREE.ShaderChunk[ "skinning_vertex" ],
15574
+ THREE.ShaderChunk[ "default_vertex" ],
15575
+ THREE.ShaderChunk[ "logdepthbuf_vertex" ],
15576
+
15577
+ THREE.ShaderChunk[ "worldpos_vertex" ],
15578
+ THREE.ShaderChunk[ "envmap_vertex" ],
15579
+ THREE.ShaderChunk[ "shadowmap_vertex" ],
15580
+
15581
+ "}"
15582
+
15583
+ ].join("\n"),
15584
+
15585
+ fragmentShader: [
15586
+
15587
+ "uniform vec3 diffuse;",
15588
+ "uniform float opacity;",
15589
+
15590
+ THREE.ShaderChunk[ "color_pars_fragment" ],
15591
+ THREE.ShaderChunk[ "map_pars_fragment" ],
15592
+ THREE.ShaderChunk[ "alphamap_pars_fragment" ],
15593
+ THREE.ShaderChunk[ "lightmap_pars_fragment" ],
15594
+ THREE.ShaderChunk[ "envmap_pars_fragment" ],
15595
+ THREE.ShaderChunk[ "fog_pars_fragment" ],
15596
+ THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
15597
+ THREE.ShaderChunk[ "specularmap_pars_fragment" ],
15598
+ THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
15599
+
15600
+ "void main() {",
15601
+
15602
+ " gl_FragColor = vec4( diffuse, opacity );",
15603
+
15604
+ THREE.ShaderChunk[ "logdepthbuf_fragment" ],
15605
+ THREE.ShaderChunk[ "map_fragment" ],
15606
+ THREE.ShaderChunk[ "alphamap_fragment" ],
15607
+ THREE.ShaderChunk[ "alphatest_fragment" ],
15608
+ THREE.ShaderChunk[ "specularmap_fragment" ],
15609
+ THREE.ShaderChunk[ "lightmap_fragment" ],
15610
+ THREE.ShaderChunk[ "color_fragment" ],
15611
+ THREE.ShaderChunk[ "envmap_fragment" ],
15612
+ THREE.ShaderChunk[ "shadowmap_fragment" ],
15613
+
15614
+ THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
15615
+
15616
+ THREE.ShaderChunk[ "fog_fragment" ],
15617
+
15618
+ "}"
15619
+
15620
+ ].join("\n")
15621
+
15622
+ },
15623
+
15624
+ 'lambert': {
15625
+
15626
+ uniforms: THREE.UniformsUtils.merge( [
15627
+
15628
+ THREE.UniformsLib[ "common" ],
15629
+ THREE.UniformsLib[ "fog" ],
15630
+ THREE.UniformsLib[ "lights" ],
15631
+ THREE.UniformsLib[ "shadowmap" ],
15632
+
15633
+ {
15634
+ "ambient" : { type: "c", value: new THREE.Color( 0xffffff ) },
15635
+ "emissive" : { type: "c", value: new THREE.Color( 0x000000 ) },
15636
+ "wrapRGB" : { type: "v3", value: new THREE.Vector3( 1, 1, 1 ) }
15637
+ }
15638
+
15639
+ ] ),
15640
+
15641
+ vertexShader: [
15642
+
15643
+ "#define LAMBERT",
15644
+
15645
+ "varying vec3 vLightFront;",
15646
+
15647
+ "#ifdef DOUBLE_SIDED",
15648
+
15649
+ " varying vec3 vLightBack;",
15650
+
15651
+ "#endif",
15652
+
15653
+ THREE.ShaderChunk[ "map_pars_vertex" ],
15654
+ THREE.ShaderChunk[ "lightmap_pars_vertex" ],
15655
+ THREE.ShaderChunk[ "envmap_pars_vertex" ],
15656
+ THREE.ShaderChunk[ "lights_lambert_pars_vertex" ],
15657
+ THREE.ShaderChunk[ "color_pars_vertex" ],
15658
+ THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
15659
+ THREE.ShaderChunk[ "skinning_pars_vertex" ],
15660
+ THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
15661
+ THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
15662
+
15663
+ "void main() {",
15664
+
15665
+ THREE.ShaderChunk[ "map_vertex" ],
15666
+ THREE.ShaderChunk[ "lightmap_vertex" ],
15667
+ THREE.ShaderChunk[ "color_vertex" ],
15668
+
15669
+ THREE.ShaderChunk[ "morphnormal_vertex" ],
15670
+ THREE.ShaderChunk[ "skinbase_vertex" ],
15671
+ THREE.ShaderChunk[ "skinnormal_vertex" ],
15672
+ THREE.ShaderChunk[ "defaultnormal_vertex" ],
15673
+
15674
+ THREE.ShaderChunk[ "morphtarget_vertex" ],
15675
+ THREE.ShaderChunk[ "skinning_vertex" ],
15676
+ THREE.ShaderChunk[ "default_vertex" ],
15677
+ THREE.ShaderChunk[ "logdepthbuf_vertex" ],
15678
+
15679
+ THREE.ShaderChunk[ "worldpos_vertex" ],
15680
+ THREE.ShaderChunk[ "envmap_vertex" ],
15681
+ THREE.ShaderChunk[ "lights_lambert_vertex" ],
15682
+ THREE.ShaderChunk[ "shadowmap_vertex" ],
15683
+
15684
+ "}"
15685
+
15686
+ ].join("\n"),
15687
+
15688
+ fragmentShader: [
15689
+
15690
+ "uniform float opacity;",
15691
+
15692
+ "varying vec3 vLightFront;",
15693
+
15694
+ "#ifdef DOUBLE_SIDED",
15695
+
15696
+ " varying vec3 vLightBack;",
15697
+
15698
+ "#endif",
15699
+
15700
+ THREE.ShaderChunk[ "color_pars_fragment" ],
15701
+ THREE.ShaderChunk[ "map_pars_fragment" ],
15702
+ THREE.ShaderChunk[ "alphamap_pars_fragment" ],
15703
+ THREE.ShaderChunk[ "lightmap_pars_fragment" ],
15704
+ THREE.ShaderChunk[ "envmap_pars_fragment" ],
15705
+ THREE.ShaderChunk[ "fog_pars_fragment" ],
15706
+ THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
15707
+ THREE.ShaderChunk[ "specularmap_pars_fragment" ],
15708
+ THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
15709
+
15710
+ "void main() {",
15711
+
15712
+ " gl_FragColor = vec4( vec3( 1.0 ), opacity );",
15713
+
15714
+ THREE.ShaderChunk[ "logdepthbuf_fragment" ],
15715
+ THREE.ShaderChunk[ "map_fragment" ],
15716
+ THREE.ShaderChunk[ "alphamap_fragment" ],
15717
+ THREE.ShaderChunk[ "alphatest_fragment" ],
15718
+ THREE.ShaderChunk[ "specularmap_fragment" ],
15719
+
15720
+ " #ifdef DOUBLE_SIDED",
15721
+
15722
+ //"float isFront = float( gl_FrontFacing );",
15723
+ //"gl_FragColor.xyz *= isFront * vLightFront + ( 1.0 - isFront ) * vLightBack;",
15724
+
15725
+ " if ( gl_FrontFacing )",
15726
+ " gl_FragColor.xyz *= vLightFront;",
15727
+ " else",
15728
+ " gl_FragColor.xyz *= vLightBack;",
15729
+
15730
+ " #else",
15731
+
15732
+ " gl_FragColor.xyz *= vLightFront;",
15733
+
15734
+ " #endif",
15735
+
15736
+ THREE.ShaderChunk[ "lightmap_fragment" ],
15737
+ THREE.ShaderChunk[ "color_fragment" ],
15738
+ THREE.ShaderChunk[ "envmap_fragment" ],
15739
+ THREE.ShaderChunk[ "shadowmap_fragment" ],
15740
+
15741
+ THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
15742
+
15743
+ THREE.ShaderChunk[ "fog_fragment" ],
15744
+
15745
+ "}"
15746
+
15747
+ ].join("\n")
15748
+
15749
+ },
15750
+
15751
+ 'phong': {
15752
+
15753
+ uniforms: THREE.UniformsUtils.merge( [
15754
+
15755
+ THREE.UniformsLib[ "common" ],
15756
+ THREE.UniformsLib[ "bump" ],
15757
+ THREE.UniformsLib[ "normalmap" ],
15758
+ THREE.UniformsLib[ "fog" ],
15759
+ THREE.UniformsLib[ "lights" ],
15760
+ THREE.UniformsLib[ "shadowmap" ],
15761
+
15762
+ {
15763
+ "ambient" : { type: "c", value: new THREE.Color( 0xffffff ) },
15764
+ "emissive" : { type: "c", value: new THREE.Color( 0x000000 ) },
15765
+ "specular" : { type: "c", value: new THREE.Color( 0x111111 ) },
15766
+ "shininess": { type: "f", value: 30 },
15767
+ "wrapRGB" : { type: "v3", value: new THREE.Vector3( 1, 1, 1 ) }
15768
+ }
15769
+
15770
+ ] ),
15771
+
15772
+ vertexShader: [
15773
+
15774
+ "#define PHONG",
15775
+
15776
+ "varying vec3 vViewPosition;",
15777
+ "varying vec3 vNormal;",
15778
+
15779
+ THREE.ShaderChunk[ "map_pars_vertex" ],
15780
+ THREE.ShaderChunk[ "lightmap_pars_vertex" ],
15781
+ THREE.ShaderChunk[ "envmap_pars_vertex" ],
15782
+ THREE.ShaderChunk[ "lights_phong_pars_vertex" ],
15783
+ THREE.ShaderChunk[ "color_pars_vertex" ],
15784
+ THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
15785
+ THREE.ShaderChunk[ "skinning_pars_vertex" ],
15786
+ THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
15787
+ THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
15788
+
15789
+ "void main() {",
15790
+
15791
+ THREE.ShaderChunk[ "map_vertex" ],
15792
+ THREE.ShaderChunk[ "lightmap_vertex" ],
15793
+ THREE.ShaderChunk[ "color_vertex" ],
15794
+
15795
+ THREE.ShaderChunk[ "morphnormal_vertex" ],
15796
+ THREE.ShaderChunk[ "skinbase_vertex" ],
15797
+ THREE.ShaderChunk[ "skinnormal_vertex" ],
15798
+ THREE.ShaderChunk[ "defaultnormal_vertex" ],
15799
+
15800
+ " vNormal = normalize( transformedNormal );",
15801
+
15802
+ THREE.ShaderChunk[ "morphtarget_vertex" ],
15803
+ THREE.ShaderChunk[ "skinning_vertex" ],
15804
+ THREE.ShaderChunk[ "default_vertex" ],
15805
+ THREE.ShaderChunk[ "logdepthbuf_vertex" ],
15806
+
15807
+ " vViewPosition = -mvPosition.xyz;",
15808
+
15809
+ THREE.ShaderChunk[ "worldpos_vertex" ],
15810
+ THREE.ShaderChunk[ "envmap_vertex" ],
15811
+ THREE.ShaderChunk[ "lights_phong_vertex" ],
15812
+ THREE.ShaderChunk[ "shadowmap_vertex" ],
15813
+
15814
+ "}"
15815
+
15816
+ ].join("\n"),
15817
+
15818
+ fragmentShader: [
15819
+
15820
+ "#define PHONG",
15821
+
15822
+ "uniform vec3 diffuse;",
15823
+ "uniform float opacity;",
15824
+
15825
+ "uniform vec3 ambient;",
15826
+ "uniform vec3 emissive;",
15827
+ "uniform vec3 specular;",
15828
+ "uniform float shininess;",
15829
+
15830
+ THREE.ShaderChunk[ "color_pars_fragment" ],
15831
+ THREE.ShaderChunk[ "map_pars_fragment" ],
15832
+ THREE.ShaderChunk[ "alphamap_pars_fragment" ],
15833
+ THREE.ShaderChunk[ "lightmap_pars_fragment" ],
15834
+ THREE.ShaderChunk[ "envmap_pars_fragment" ],
15835
+ THREE.ShaderChunk[ "fog_pars_fragment" ],
15836
+ THREE.ShaderChunk[ "lights_phong_pars_fragment" ],
15837
+ THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
15838
+ THREE.ShaderChunk[ "bumpmap_pars_fragment" ],
15839
+ THREE.ShaderChunk[ "normalmap_pars_fragment" ],
15840
+ THREE.ShaderChunk[ "specularmap_pars_fragment" ],
15841
+ THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
15842
+
15843
+ "void main() {",
15844
+
15845
+ " gl_FragColor = vec4( vec3( 1.0 ), opacity );",
15846
+
15847
+ THREE.ShaderChunk[ "logdepthbuf_fragment" ],
15848
+ THREE.ShaderChunk[ "map_fragment" ],
15849
+ THREE.ShaderChunk[ "alphamap_fragment" ],
15850
+ THREE.ShaderChunk[ "alphatest_fragment" ],
15851
+ THREE.ShaderChunk[ "specularmap_fragment" ],
15852
+
15853
+ THREE.ShaderChunk[ "lights_phong_fragment" ],
15854
+
15855
+ THREE.ShaderChunk[ "lightmap_fragment" ],
15856
+ THREE.ShaderChunk[ "color_fragment" ],
15857
+ THREE.ShaderChunk[ "envmap_fragment" ],
15858
+ THREE.ShaderChunk[ "shadowmap_fragment" ],
15859
+
15860
+ THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
15861
+
15862
+ THREE.ShaderChunk[ "fog_fragment" ],
15863
+
15864
+ "}"
15865
+
15866
+ ].join("\n")
15867
+
15868
+ },
15869
+
15870
+ 'particle_basic': {
15871
+
15872
+ uniforms: THREE.UniformsUtils.merge( [
15873
+
15874
+ THREE.UniformsLib[ "particle" ],
15875
+ THREE.UniformsLib[ "shadowmap" ]
15876
+
15877
+ ] ),
15878
+
15879
+ vertexShader: [
15880
+
15881
+ "uniform float size;",
15882
+ "uniform float scale;",
15883
+
15884
+ THREE.ShaderChunk[ "color_pars_vertex" ],
15885
+ THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
15886
+ THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
15887
+
15888
+ "void main() {",
15889
+
15890
+ THREE.ShaderChunk[ "color_vertex" ],
15891
+
15892
+ " vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
15893
+
15894
+ " #ifdef USE_SIZEATTENUATION",
15895
+ " gl_PointSize = size * ( scale / length( mvPosition.xyz ) );",
15896
+ " #else",
15897
+ " gl_PointSize = size;",
15898
+ " #endif",
15899
+
15900
+ " gl_Position = projectionMatrix * mvPosition;",
15901
+
15902
+ THREE.ShaderChunk[ "logdepthbuf_vertex" ],
15903
+ THREE.ShaderChunk[ "worldpos_vertex" ],
15904
+ THREE.ShaderChunk[ "shadowmap_vertex" ],
15905
+
15906
+ "}"
15907
+
15908
+ ].join("\n"),
15909
+
15910
+ fragmentShader: [
15911
+
15912
+ "uniform vec3 psColor;",
15913
+ "uniform float opacity;",
15914
+
15915
+ THREE.ShaderChunk[ "color_pars_fragment" ],
15916
+ THREE.ShaderChunk[ "map_particle_pars_fragment" ],
15917
+ THREE.ShaderChunk[ "fog_pars_fragment" ],
15918
+ THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
15919
+ THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
15920
+
15921
+ "void main() {",
15922
+
15923
+ " gl_FragColor = vec4( psColor, opacity );",
15924
+
15925
+ THREE.ShaderChunk[ "logdepthbuf_fragment" ],
15926
+ THREE.ShaderChunk[ "map_particle_fragment" ],
15927
+ THREE.ShaderChunk[ "alphatest_fragment" ],
15928
+ THREE.ShaderChunk[ "color_fragment" ],
15929
+ THREE.ShaderChunk[ "shadowmap_fragment" ],
15930
+ THREE.ShaderChunk[ "fog_fragment" ],
15931
+
15932
+ "}"
15933
+
15934
+ ].join("\n")
15935
+
15936
+ },
15937
+
15938
+ 'dashed': {
15939
+
15940
+ uniforms: THREE.UniformsUtils.merge( [
15941
+
15942
+ THREE.UniformsLib[ "common" ],
15943
+ THREE.UniformsLib[ "fog" ],
15944
+
15945
+ {
15946
+ "scale" : { type: "f", value: 1 },
15947
+ "dashSize" : { type: "f", value: 1 },
15948
+ "totalSize": { type: "f", value: 2 }
15949
+ }
15950
+
15951
+ ] ),
15952
+
15953
+ vertexShader: [
15954
+
15955
+ "uniform float scale;",
15956
+ "attribute float lineDistance;",
15957
+
15958
+ "varying float vLineDistance;",
15959
+
15960
+ THREE.ShaderChunk[ "color_pars_vertex" ],
15961
+ THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
15962
+
15963
+ "void main() {",
15964
+
15965
+ THREE.ShaderChunk[ "color_vertex" ],
15966
+
15967
+ " vLineDistance = scale * lineDistance;",
15968
+
15969
+ " vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
15970
+ " gl_Position = projectionMatrix * mvPosition;",
15971
+
15972
+ THREE.ShaderChunk[ "logdepthbuf_vertex" ],
15973
+
15974
+ "}"
15975
+
15976
+ ].join("\n"),
15977
+
15978
+ fragmentShader: [
15979
+
15980
+ "uniform vec3 diffuse;",
15981
+ "uniform float opacity;",
15982
+
15983
+ "uniform float dashSize;",
15984
+ "uniform float totalSize;",
15985
+
15986
+ "varying float vLineDistance;",
15987
+
15988
+ THREE.ShaderChunk[ "color_pars_fragment" ],
15989
+ THREE.ShaderChunk[ "fog_pars_fragment" ],
15990
+ THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
15991
+
15992
+ "void main() {",
15993
+
15994
+ " if ( mod( vLineDistance, totalSize ) > dashSize ) {",
15995
+
15996
+ " discard;",
15997
+
15998
+ " }",
15999
+
16000
+ " gl_FragColor = vec4( diffuse, opacity );",
16001
+
16002
+ THREE.ShaderChunk[ "logdepthbuf_fragment" ],
16003
+ THREE.ShaderChunk[ "color_fragment" ],
16004
+ THREE.ShaderChunk[ "fog_fragment" ],
16005
+
16006
+ "}"
16007
+
16008
+ ].join("\n")
16009
+
16010
+ },
16011
+
16012
+ 'depth': {
16013
+
16014
+ uniforms: {
16015
+
16016
+ "mNear": { type: "f", value: 1.0 },
16017
+ "mFar" : { type: "f", value: 2000.0 },
16018
+ "opacity" : { type: "f", value: 1.0 }
16019
+
16020
+ },
16021
+
16022
+ vertexShader: [
16023
+
16024
+ THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
16025
+ THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
16026
+
16027
+ "void main() {",
16028
+
16029
+ THREE.ShaderChunk[ "morphtarget_vertex" ],
16030
+ THREE.ShaderChunk[ "default_vertex" ],
16031
+ THREE.ShaderChunk[ "logdepthbuf_vertex" ],
16032
+
16033
+ "}"
16034
+
16035
+ ].join("\n"),
16036
+
16037
+ fragmentShader: [
16038
+
16039
+ "uniform float mNear;",
16040
+ "uniform float mFar;",
16041
+ "uniform float opacity;",
16042
+
16043
+ THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
16044
+
16045
+ "void main() {",
16046
+
16047
+ THREE.ShaderChunk[ "logdepthbuf_fragment" ],
16048
+
16049
+ " #ifdef USE_LOGDEPTHBUF_EXT",
16050
+
16051
+ " float depth = gl_FragDepthEXT / gl_FragCoord.w;",
16052
+
16053
+ " #else",
16054
+
16055
+ " float depth = gl_FragCoord.z / gl_FragCoord.w;",
16056
+
16057
+ " #endif",
16058
+
16059
+ " float color = 1.0 - smoothstep( mNear, mFar, depth );",
16060
+ " gl_FragColor = vec4( vec3( color ), opacity );",
16061
+
16062
+ "}"
16063
+
16064
+ ].join("\n")
16065
+
16066
+ },
16067
+
16068
+ 'normal': {
16069
+
16070
+ uniforms: {
16071
+
16072
+ "opacity" : { type: "f", value: 1.0 }
16073
+
16074
+ },
16075
+
16076
+ vertexShader: [
16077
+
16078
+ "varying vec3 vNormal;",
16079
+
16080
+ THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
16081
+ THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
16082
+
16083
+ "void main() {",
16084
+
16085
+ " vNormal = normalize( normalMatrix * normal );",
16086
+
16087
+ THREE.ShaderChunk[ "morphtarget_vertex" ],
16088
+ THREE.ShaderChunk[ "default_vertex" ],
16089
+ THREE.ShaderChunk[ "logdepthbuf_vertex" ],
16090
+
16091
+ "}"
16092
+
16093
+ ].join("\n"),
16094
+
16095
+ fragmentShader: [
16096
+
16097
+ "uniform float opacity;",
16098
+ "varying vec3 vNormal;",
16099
+
16100
+ THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
16101
+
16102
+ "void main() {",
16103
+
16104
+ " gl_FragColor = vec4( 0.5 * normalize( vNormal ) + 0.5, opacity );",
16105
+
16106
+ THREE.ShaderChunk[ "logdepthbuf_fragment" ],
16107
+
16108
+ "}"
16109
+
16110
+ ].join("\n")
16111
+
16112
+ },
16113
+
16114
+ /* -------------------------------------------------------------------------
16115
+ // Normal map shader
16116
+ // - Blinn-Phong
16117
+ // - normal + diffuse + specular + AO + displacement + reflection + shadow maps
16118
+ // - point and directional lights (use with "lights: true" material option)
16119
+ ------------------------------------------------------------------------- */
16120
+
16121
+ 'normalmap' : {
16122
+
16123
+ uniforms: THREE.UniformsUtils.merge( [
16124
+
16125
+ THREE.UniformsLib[ "fog" ],
16126
+ THREE.UniformsLib[ "lights" ],
16127
+ THREE.UniformsLib[ "shadowmap" ],
16128
+
16129
+ {
16130
+
16131
+ "enableAO" : { type: "i", value: 0 },
16132
+ "enableDiffuse" : { type: "i", value: 0 },
16133
+ "enableSpecular" : { type: "i", value: 0 },
16134
+ "enableReflection" : { type: "i", value: 0 },
16135
+ "enableDisplacement": { type: "i", value: 0 },
16136
+
16137
+ "tDisplacement": { type: "t", value: null }, // must go first as this is vertex texture
16138
+ "tDiffuse" : { type: "t", value: null },
16139
+ "tCube" : { type: "t", value: null },
16140
+ "tNormal" : { type: "t", value: null },
16141
+ "tSpecular" : { type: "t", value: null },
16142
+ "tAO" : { type: "t", value: null },
16143
+
16144
+ "uNormalScale": { type: "v2", value: new THREE.Vector2( 1, 1 ) },
16145
+
16146
+ "uDisplacementBias": { type: "f", value: 0.0 },
16147
+ "uDisplacementScale": { type: "f", value: 1.0 },
16148
+
16149
+ "diffuse": { type: "c", value: new THREE.Color( 0xffffff ) },
16150
+ "specular": { type: "c", value: new THREE.Color( 0x111111 ) },
16151
+ "ambient": { type: "c", value: new THREE.Color( 0xffffff ) },
16152
+ "shininess": { type: "f", value: 30 },
16153
+ "opacity": { type: "f", value: 1 },
16154
+
16155
+ "useRefract": { type: "i", value: 0 },
16156
+ "refractionRatio": { type: "f", value: 0.98 },
16157
+ "reflectivity": { type: "f", value: 0.5 },
16158
+
16159
+ "uOffset" : { type: "v2", value: new THREE.Vector2( 0, 0 ) },
16160
+ "uRepeat" : { type: "v2", value: new THREE.Vector2( 1, 1 ) },
16161
+
16162
+ "wrapRGB" : { type: "v3", value: new THREE.Vector3( 1, 1, 1 ) }
16163
+
16164
+ }
16165
+
16166
+ ] ),
16167
+
16168
+ fragmentShader: [
16169
+
16170
+ "uniform vec3 ambient;",
16171
+ "uniform vec3 diffuse;",
16172
+ "uniform vec3 specular;",
16173
+ "uniform float shininess;",
16174
+ "uniform float opacity;",
16175
+
16176
+ "uniform bool enableDiffuse;",
16177
+ "uniform bool enableSpecular;",
16178
+ "uniform bool enableAO;",
16179
+ "uniform bool enableReflection;",
16180
+
16181
+ "uniform sampler2D tDiffuse;",
16182
+ "uniform sampler2D tNormal;",
16183
+ "uniform sampler2D tSpecular;",
16184
+ "uniform sampler2D tAO;",
16185
+
16186
+ "uniform samplerCube tCube;",
16187
+
16188
+ "uniform vec2 uNormalScale;",
16189
+
16190
+ "uniform bool useRefract;",
16191
+ "uniform float refractionRatio;",
16192
+ "uniform float reflectivity;",
16193
+
16194
+ "varying vec3 vTangent;",
16195
+ "varying vec3 vBinormal;",
16196
+ "varying vec3 vNormal;",
16197
+ "varying vec2 vUv;",
16198
+
16199
+ "uniform vec3 ambientLightColor;",
16200
+
16201
+ "#if MAX_DIR_LIGHTS > 0",
16202
+
16203
+ " uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];",
16204
+ " uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];",
16205
+
16206
+ "#endif",
16207
+
16208
+ "#if MAX_HEMI_LIGHTS > 0",
16209
+
16210
+ " uniform vec3 hemisphereLightSkyColor[ MAX_HEMI_LIGHTS ];",
16211
+ " uniform vec3 hemisphereLightGroundColor[ MAX_HEMI_LIGHTS ];",
16212
+ " uniform vec3 hemisphereLightDirection[ MAX_HEMI_LIGHTS ];",
16213
+
16214
+ "#endif",
16215
+
16216
+ "#if MAX_POINT_LIGHTS > 0",
16217
+
16218
+ " uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];",
16219
+ " uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];",
16220
+ " uniform float pointLightDistance[ MAX_POINT_LIGHTS ];",
16221
+
16222
+ "#endif",
16223
+
16224
+ "#if MAX_SPOT_LIGHTS > 0",
16225
+
16226
+ " uniform vec3 spotLightColor[ MAX_SPOT_LIGHTS ];",
16227
+ " uniform vec3 spotLightPosition[ MAX_SPOT_LIGHTS ];",
16228
+ " uniform vec3 spotLightDirection[ MAX_SPOT_LIGHTS ];",
16229
+ " uniform float spotLightAngleCos[ MAX_SPOT_LIGHTS ];",
16230
+ " uniform float spotLightExponent[ MAX_SPOT_LIGHTS ];",
16231
+ " uniform float spotLightDistance[ MAX_SPOT_LIGHTS ];",
16232
+
16233
+ "#endif",
16234
+
16235
+ "#ifdef WRAP_AROUND",
16236
+
16237
+ " uniform vec3 wrapRGB;",
16238
+
16239
+ "#endif",
16240
+
16241
+ "varying vec3 vWorldPosition;",
16242
+ "varying vec3 vViewPosition;",
16243
+
16244
+ THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
16245
+ THREE.ShaderChunk[ "fog_pars_fragment" ],
16246
+ THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
16247
+
16248
+ "void main() {",
16249
+ THREE.ShaderChunk[ "logdepthbuf_fragment" ],
16250
+
16251
+ " gl_FragColor = vec4( vec3( 1.0 ), opacity );",
16252
+
16253
+ " vec3 specularTex = vec3( 1.0 );",
16254
+
16255
+ " vec3 normalTex = texture2D( tNormal, vUv ).xyz * 2.0 - 1.0;",
16256
+ " normalTex.xy *= uNormalScale;",
16257
+ " normalTex = normalize( normalTex );",
16258
+
16259
+ " if( enableDiffuse ) {",
16260
+
16261
+ " #ifdef GAMMA_INPUT",
16262
+
16263
+ " vec4 texelColor = texture2D( tDiffuse, vUv );",
16264
+ " texelColor.xyz *= texelColor.xyz;",
16265
+
16266
+ " gl_FragColor = gl_FragColor * texelColor;",
16267
+
16268
+ " #else",
16269
+
16270
+ " gl_FragColor = gl_FragColor * texture2D( tDiffuse, vUv );",
16271
+
16272
+ " #endif",
16273
+
16274
+ " }",
16275
+
16276
+ " if( enableAO ) {",
16277
+
16278
+ " #ifdef GAMMA_INPUT",
16279
+
16280
+ " vec4 aoColor = texture2D( tAO, vUv );",
16281
+ " aoColor.xyz *= aoColor.xyz;",
16282
+
16283
+ " gl_FragColor.xyz = gl_FragColor.xyz * aoColor.xyz;",
16284
+
16285
+ " #else",
16286
+
16287
+ " gl_FragColor.xyz = gl_FragColor.xyz * texture2D( tAO, vUv ).xyz;",
16288
+
16289
+ " #endif",
16290
+
16291
+ " }",
16292
+
16293
+ THREE.ShaderChunk[ "alphatest_fragment" ],
16294
+
16295
+ " if( enableSpecular )",
16296
+ " specularTex = texture2D( tSpecular, vUv ).xyz;",
16297
+
16298
+ " mat3 tsb = mat3( normalize( vTangent ), normalize( vBinormal ), normalize( vNormal ) );",
16299
+ " vec3 finalNormal = tsb * normalTex;",
16300
+
16301
+ " #ifdef FLIP_SIDED",
16302
+
16303
+ " finalNormal = -finalNormal;",
16304
+
16305
+ " #endif",
16306
+
16307
+ " vec3 normal = normalize( finalNormal );",
16308
+ " vec3 viewPosition = normalize( vViewPosition );",
16309
+
16310
+ // point lights
16311
+
16312
+ " #if MAX_POINT_LIGHTS > 0",
16313
+
16314
+ " vec3 pointDiffuse = vec3( 0.0 );",
16315
+ " vec3 pointSpecular = vec3( 0.0 );",
16316
+
16317
+ " for ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {",
16318
+
16319
+ " vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );",
16320
+ " vec3 pointVector = lPosition.xyz + vViewPosition.xyz;",
16321
+
16322
+ " float pointDistance = 1.0;",
16323
+ " if ( pointLightDistance[ i ] > 0.0 )",
16324
+ " pointDistance = 1.0 - min( ( length( pointVector ) / pointLightDistance[ i ] ), 1.0 );",
16325
+
16326
+ " pointVector = normalize( pointVector );",
16327
+
16328
+ // diffuse
16329
+
16330
+ " #ifdef WRAP_AROUND",
16331
+
16332
+ " float pointDiffuseWeightFull = max( dot( normal, pointVector ), 0.0 );",
16333
+ " float pointDiffuseWeightHalf = max( 0.5 * dot( normal, pointVector ) + 0.5, 0.0 );",
16334
+
16335
+ " vec3 pointDiffuseWeight = mix( vec3( pointDiffuseWeightFull ), vec3( pointDiffuseWeightHalf ), wrapRGB );",
16336
+
16337
+ " #else",
16338
+
16339
+ " float pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );",
16340
+
16341
+ " #endif",
16342
+
16343
+ " pointDiffuse += pointDistance * pointLightColor[ i ] * diffuse * pointDiffuseWeight;",
16344
+
16345
+ // specular
16346
+
16347
+ " vec3 pointHalfVector = normalize( pointVector + viewPosition );",
16348
+ " float pointDotNormalHalf = max( dot( normal, pointHalfVector ), 0.0 );",
16349
+ " float pointSpecularWeight = specularTex.r * max( pow( pointDotNormalHalf, shininess ), 0.0 );",
16350
+
16351
+ " float specularNormalization = ( shininess + 2.0 ) / 8.0;",
16352
+
16353
+ " vec3 schlick = specular + vec3( 1.0 - specular ) * pow( max( 1.0 - dot( pointVector, pointHalfVector ), 0.0 ), 5.0 );",
16354
+ " pointSpecular += schlick * pointLightColor[ i ] * pointSpecularWeight * pointDiffuseWeight * pointDistance * specularNormalization;",
16355
+
16356
+ " }",
16357
+
16358
+ " #endif",
16359
+
16360
+ // spot lights
16361
+
16362
+ " #if MAX_SPOT_LIGHTS > 0",
16363
+
16364
+ " vec3 spotDiffuse = vec3( 0.0 );",
16365
+ " vec3 spotSpecular = vec3( 0.0 );",
16366
+
16367
+ " for ( int i = 0; i < MAX_SPOT_LIGHTS; i ++ ) {",
16368
+
16369
+ " vec4 lPosition = viewMatrix * vec4( spotLightPosition[ i ], 1.0 );",
16370
+ " vec3 spotVector = lPosition.xyz + vViewPosition.xyz;",
16371
+
16372
+ " float spotDistance = 1.0;",
16373
+ " if ( spotLightDistance[ i ] > 0.0 )",
16374
+ " spotDistance = 1.0 - min( ( length( spotVector ) / spotLightDistance[ i ] ), 1.0 );",
16375
+
16376
+ " spotVector = normalize( spotVector );",
16377
+
16378
+ " float spotEffect = dot( spotLightDirection[ i ], normalize( spotLightPosition[ i ] - vWorldPosition ) );",
16379
+
16380
+ " if ( spotEffect > spotLightAngleCos[ i ] ) {",
16381
+
16382
+ " spotEffect = max( pow( max( spotEffect, 0.0 ), spotLightExponent[ i ] ), 0.0 );",
16383
+
16384
+ // diffuse
16385
+
16386
+ " #ifdef WRAP_AROUND",
16387
+
16388
+ " float spotDiffuseWeightFull = max( dot( normal, spotVector ), 0.0 );",
16389
+ " float spotDiffuseWeightHalf = max( 0.5 * dot( normal, spotVector ) + 0.5, 0.0 );",
16390
+
16391
+ " vec3 spotDiffuseWeight = mix( vec3( spotDiffuseWeightFull ), vec3( spotDiffuseWeightHalf ), wrapRGB );",
16392
+
16393
+ " #else",
16394
+
16395
+ " float spotDiffuseWeight = max( dot( normal, spotVector ), 0.0 );",
16396
+
16397
+ " #endif",
16398
+
16399
+ " spotDiffuse += spotDistance * spotLightColor[ i ] * diffuse * spotDiffuseWeight * spotEffect;",
16400
+
16401
+ // specular
16402
+
16403
+ " vec3 spotHalfVector = normalize( spotVector + viewPosition );",
16404
+ " float spotDotNormalHalf = max( dot( normal, spotHalfVector ), 0.0 );",
16405
+ " float spotSpecularWeight = specularTex.r * max( pow( spotDotNormalHalf, shininess ), 0.0 );",
16406
+
16407
+ " float specularNormalization = ( shininess + 2.0 ) / 8.0;",
16408
+
16409
+ " vec3 schlick = specular + vec3( 1.0 - specular ) * pow( max( 1.0 - dot( spotVector, spotHalfVector ), 0.0 ), 5.0 );",
16410
+ " spotSpecular += schlick * spotLightColor[ i ] * spotSpecularWeight * spotDiffuseWeight * spotDistance * specularNormalization * spotEffect;",
16411
+
16412
+ " }",
16413
+
16414
+ " }",
16415
+
16416
+ " #endif",
16417
+
16418
+ // directional lights
16419
+
16420
+ " #if MAX_DIR_LIGHTS > 0",
16421
+
16422
+ " vec3 dirDiffuse = vec3( 0.0 );",
16423
+ " vec3 dirSpecular = vec3( 0.0 );",
16424
+
16425
+ " for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {",
16426
+
16427
+ " vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );",
16428
+ " vec3 dirVector = normalize( lDirection.xyz );",
16429
+
16430
+ // diffuse
16431
+
16432
+ " #ifdef WRAP_AROUND",
16433
+
16434
+ " float directionalLightWeightingFull = max( dot( normal, dirVector ), 0.0 );",
16435
+ " float directionalLightWeightingHalf = max( 0.5 * dot( normal, dirVector ) + 0.5, 0.0 );",
16436
+
16437
+ " vec3 dirDiffuseWeight = mix( vec3( directionalLightWeightingFull ), vec3( directionalLightWeightingHalf ), wrapRGB );",
16438
+
16439
+ " #else",
16440
+
16441
+ " float dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );",
16442
+
16443
+ " #endif",
16444
+
16445
+ " dirDiffuse += directionalLightColor[ i ] * diffuse * dirDiffuseWeight;",
16446
+
16447
+ // specular
16448
+
16449
+ " vec3 dirHalfVector = normalize( dirVector + viewPosition );",
16450
+ " float dirDotNormalHalf = max( dot( normal, dirHalfVector ), 0.0 );",
16451
+ " float dirSpecularWeight = specularTex.r * max( pow( dirDotNormalHalf, shininess ), 0.0 );",
16452
+
16453
+ " float specularNormalization = ( shininess + 2.0 ) / 8.0;",
16454
+
16455
+ " vec3 schlick = specular + vec3( 1.0 - specular ) * pow( max( 1.0 - dot( dirVector, dirHalfVector ), 0.0 ), 5.0 );",
16456
+ " dirSpecular += schlick * directionalLightColor[ i ] * dirSpecularWeight * dirDiffuseWeight * specularNormalization;",
16457
+
16458
+ " }",
16459
+
16460
+ " #endif",
16461
+
16462
+ // hemisphere lights
16463
+
16464
+ " #if MAX_HEMI_LIGHTS > 0",
16465
+
16466
+ " vec3 hemiDiffuse = vec3( 0.0 );",
16467
+ " vec3 hemiSpecular = vec3( 0.0 );" ,
16468
+
16469
+ " for( int i = 0; i < MAX_HEMI_LIGHTS; i ++ ) {",
16470
+
16471
+ " vec4 lDirection = viewMatrix * vec4( hemisphereLightDirection[ i ], 0.0 );",
16472
+ " vec3 lVector = normalize( lDirection.xyz );",
16473
+
16474
+ // diffuse
16475
+
16476
+ " float dotProduct = dot( normal, lVector );",
16477
+ " float hemiDiffuseWeight = 0.5 * dotProduct + 0.5;",
16478
+
16479
+ " vec3 hemiColor = mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeight );",
16480
+
16481
+ " hemiDiffuse += diffuse * hemiColor;",
16482
+
16483
+ // specular (sky light)
16484
+
16485
+
16486
+ " vec3 hemiHalfVectorSky = normalize( lVector + viewPosition );",
16487
+ " float hemiDotNormalHalfSky = 0.5 * dot( normal, hemiHalfVectorSky ) + 0.5;",
16488
+ " float hemiSpecularWeightSky = specularTex.r * max( pow( max( hemiDotNormalHalfSky, 0.0 ), shininess ), 0.0 );",
16489
+
16490
+ // specular (ground light)
16491
+
16492
+ " vec3 lVectorGround = -lVector;",
16493
+
16494
+ " vec3 hemiHalfVectorGround = normalize( lVectorGround + viewPosition );",
16495
+ " float hemiDotNormalHalfGround = 0.5 * dot( normal, hemiHalfVectorGround ) + 0.5;",
16496
+ " float hemiSpecularWeightGround = specularTex.r * max( pow( max( hemiDotNormalHalfGround, 0.0 ), shininess ), 0.0 );",
16497
+
16498
+ " float dotProductGround = dot( normal, lVectorGround );",
16499
+
16500
+ " float specularNormalization = ( shininess + 2.0 ) / 8.0;",
16501
+
16502
+ " vec3 schlickSky = specular + vec3( 1.0 - specular ) * pow( max( 1.0 - dot( lVector, hemiHalfVectorSky ), 0.0 ), 5.0 );",
16503
+ " vec3 schlickGround = specular + vec3( 1.0 - specular ) * pow( max( 1.0 - dot( lVectorGround, hemiHalfVectorGround ), 0.0 ), 5.0 );",
16504
+ " hemiSpecular += hemiColor * specularNormalization * ( schlickSky * hemiSpecularWeightSky * max( dotProduct, 0.0 ) + schlickGround * hemiSpecularWeightGround * max( dotProductGround, 0.0 ) );",
16505
+
16506
+ " }",
16507
+
16508
+ " #endif",
16509
+
16510
+ // all lights contribution summation
16511
+
16512
+ " vec3 totalDiffuse = vec3( 0.0 );",
16513
+ " vec3 totalSpecular = vec3( 0.0 );",
16514
+
16515
+ " #if MAX_DIR_LIGHTS > 0",
16516
+
16517
+ " totalDiffuse += dirDiffuse;",
16518
+ " totalSpecular += dirSpecular;",
16519
+
16520
+ " #endif",
16521
+
16522
+ " #if MAX_HEMI_LIGHTS > 0",
16523
+
16524
+ " totalDiffuse += hemiDiffuse;",
16525
+ " totalSpecular += hemiSpecular;",
16526
+
16527
+ " #endif",
16528
+
16529
+ " #if MAX_POINT_LIGHTS > 0",
16530
+
16531
+ " totalDiffuse += pointDiffuse;",
16532
+ " totalSpecular += pointSpecular;",
16533
+
16534
+ " #endif",
16535
+
16536
+ " #if MAX_SPOT_LIGHTS > 0",
16537
+
16538
+ " totalDiffuse += spotDiffuse;",
16539
+ " totalSpecular += spotSpecular;",
16540
+
16541
+ " #endif",
16542
+
16543
+ " #ifdef METAL",
16544
+
16545
+ " gl_FragColor.xyz = gl_FragColor.xyz * ( totalDiffuse + ambientLightColor * ambient + totalSpecular );",
16546
+
16547
+ " #else",
16548
+
16549
+ " gl_FragColor.xyz = gl_FragColor.xyz * ( totalDiffuse + ambientLightColor * ambient ) + totalSpecular;",
16550
+
16551
+ " #endif",
16552
+
16553
+ " if ( enableReflection ) {",
16554
+
16555
+ " vec3 vReflect;",
16556
+ " vec3 cameraToVertex = normalize( vWorldPosition - cameraPosition );",
16557
+
16558
+ " if ( useRefract ) {",
16559
+
16560
+ " vReflect = refract( cameraToVertex, normal, refractionRatio );",
16561
+
16562
+ " } else {",
16563
+
16564
+ " vReflect = reflect( cameraToVertex, normal );",
16565
+
16566
+ " }",
16567
+
16568
+ " vec4 cubeColor = textureCube( tCube, vec3( -vReflect.x, vReflect.yz ) );",
16569
+
16570
+ " #ifdef GAMMA_INPUT",
16571
+
16572
+ " cubeColor.xyz *= cubeColor.xyz;",
16573
+
16574
+ " #endif",
16575
+
16576
+ " gl_FragColor.xyz = mix( gl_FragColor.xyz, cubeColor.xyz, specularTex.r * reflectivity );",
16577
+
16578
+ " }",
16579
+
16580
+ THREE.ShaderChunk[ "shadowmap_fragment" ],
16581
+ THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
16582
+ THREE.ShaderChunk[ "fog_fragment" ],
16583
+
16584
+ "}"
16585
+
16586
+ ].join("\n"),
16587
+
16588
+ vertexShader: [
16589
+
16590
+ "attribute vec4 tangent;",
16591
+
16592
+ "uniform vec2 uOffset;",
16593
+ "uniform vec2 uRepeat;",
16594
+
16595
+ "uniform bool enableDisplacement;",
16596
+
16597
+ "#ifdef VERTEX_TEXTURES",
16598
+
16599
+ " uniform sampler2D tDisplacement;",
16600
+ " uniform float uDisplacementScale;",
16601
+ " uniform float uDisplacementBias;",
16602
+
16603
+ "#endif",
16604
+
16605
+ "varying vec3 vTangent;",
16606
+ "varying vec3 vBinormal;",
16607
+ "varying vec3 vNormal;",
16608
+ "varying vec2 vUv;",
16609
+
16610
+ "varying vec3 vWorldPosition;",
16611
+ "varying vec3 vViewPosition;",
16612
+
16613
+ THREE.ShaderChunk[ "skinning_pars_vertex" ],
16614
+ THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
16615
+ THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
16616
+
16617
+ "void main() {",
16618
+
16619
+ THREE.ShaderChunk[ "skinbase_vertex" ],
16620
+ THREE.ShaderChunk[ "skinnormal_vertex" ],
16621
+
16622
+ // normal, tangent and binormal vectors
16623
+
16624
+ " #ifdef USE_SKINNING",
16625
+
16626
+ " vNormal = normalize( normalMatrix * skinnedNormal.xyz );",
16627
+
16628
+ " vec4 skinnedTangent = skinMatrix * vec4( tangent.xyz, 0.0 );",
16629
+ " vTangent = normalize( normalMatrix * skinnedTangent.xyz );",
16630
+
16631
+ " #else",
16632
+
16633
+ " vNormal = normalize( normalMatrix * normal );",
16634
+ " vTangent = normalize( normalMatrix * tangent.xyz );",
16635
+
16636
+ " #endif",
16637
+
16638
+ " vBinormal = normalize( cross( vNormal, vTangent ) * tangent.w );",
16639
+
16640
+ " vUv = uv * uRepeat + uOffset;",
16641
+
16642
+ // displacement mapping
16643
+
16644
+ " vec3 displacedPosition;",
16645
+
16646
+ " #ifdef VERTEX_TEXTURES",
16647
+
16648
+ " if ( enableDisplacement ) {",
16649
+
16650
+ " vec3 dv = texture2D( tDisplacement, uv ).xyz;",
16651
+ " float df = uDisplacementScale * dv.x + uDisplacementBias;",
16652
+ " displacedPosition = position + normalize( normal ) * df;",
16653
+
16654
+ " } else {",
16655
+
16656
+ " #ifdef USE_SKINNING",
16657
+
16658
+ " vec4 skinVertex = bindMatrix * vec4( position, 1.0 );",
16659
+
16660
+ " vec4 skinned = vec4( 0.0 );",
16661
+ " skinned += boneMatX * skinVertex * skinWeight.x;",
16662
+ " skinned += boneMatY * skinVertex * skinWeight.y;",
16663
+ " skinned += boneMatZ * skinVertex * skinWeight.z;",
16664
+ " skinned += boneMatW * skinVertex * skinWeight.w;",
16665
+ " skinned = bindMatrixInverse * skinned;",
16666
+
16667
+ " displacedPosition = skinned.xyz;",
16668
+
16669
+ " #else",
16670
+
16671
+ " displacedPosition = position;",
16672
+
16673
+ " #endif",
16674
+
16675
+ " }",
16676
+
16677
+ " #else",
16678
+
16679
+ " #ifdef USE_SKINNING",
16680
+
16681
+ " vec4 skinVertex = bindMatrix * vec4( position, 1.0 );",
16682
+
16683
+ " vec4 skinned = vec4( 0.0 );",
16684
+ " skinned += boneMatX * skinVertex * skinWeight.x;",
16685
+ " skinned += boneMatY * skinVertex * skinWeight.y;",
16686
+ " skinned += boneMatZ * skinVertex * skinWeight.z;",
16687
+ " skinned += boneMatW * skinVertex * skinWeight.w;",
16688
+ " skinned = bindMatrixInverse * skinned;",
16689
+
16690
+ " displacedPosition = skinned.xyz;",
16691
+
16692
+ " #else",
16693
+
16694
+ " displacedPosition = position;",
16695
+
16696
+ " #endif",
16697
+
16698
+ " #endif",
16699
+
16700
+ //
16701
+
16702
+ " vec4 mvPosition = modelViewMatrix * vec4( displacedPosition, 1.0 );",
16703
+ " vec4 worldPosition = modelMatrix * vec4( displacedPosition, 1.0 );",
16704
+
16705
+ " gl_Position = projectionMatrix * mvPosition;",
16706
+
16707
+ THREE.ShaderChunk[ "logdepthbuf_vertex" ],
16708
+
16709
+ //
16710
+
16711
+ " vWorldPosition = worldPosition.xyz;",
16712
+ " vViewPosition = -mvPosition.xyz;",
16713
+
16714
+ // shadows
16715
+
16716
+ " #ifdef USE_SHADOWMAP",
16717
+
16718
+ " for( int i = 0; i < MAX_SHADOWS; i ++ ) {",
16719
+
16720
+ " vShadowCoord[ i ] = shadowMatrix[ i ] * worldPosition;",
16721
+
16722
+ " }",
16723
+
16724
+ " #endif",
16725
+
16726
+ "}"
16727
+
16728
+ ].join("\n")
16729
+
16730
+ },
16731
+
16732
+ /* -------------------------------------------------------------------------
16733
+ // Cube map shader
16734
+ ------------------------------------------------------------------------- */
16735
+
16736
+ 'cube': {
16737
+
16738
+ uniforms: { "tCube": { type: "t", value: null },
16739
+ "tFlip": { type: "f", value: - 1 } },
16740
+
16741
+ vertexShader: [
16742
+
16743
+ "varying vec3 vWorldPosition;",
16744
+
16745
+ THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
16746
+
16747
+ "void main() {",
16748
+
16749
+ " vec4 worldPosition = modelMatrix * vec4( position, 1.0 );",
16750
+ " vWorldPosition = worldPosition.xyz;",
16751
+
16752
+ " gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
16753
+
16754
+ THREE.ShaderChunk[ "logdepthbuf_vertex" ],
16755
+
16756
+ "}"
16757
+
16758
+ ].join("\n"),
16759
+
16760
+ fragmentShader: [
16761
+
16762
+ "uniform samplerCube tCube;",
16763
+ "uniform float tFlip;",
16764
+
16765
+ "varying vec3 vWorldPosition;",
16766
+
16767
+ THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
16768
+
16769
+ "void main() {",
16770
+
16771
+ " gl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );",
16772
+
16773
+ THREE.ShaderChunk[ "logdepthbuf_fragment" ],
16774
+
16775
+ "}"
16776
+
16777
+ ].join("\n")
16778
+
16779
+ },
16780
+
16781
+ /* Depth encoding into RGBA texture
16782
+ *
16783
+ * based on SpiderGL shadow map example
16784
+ * http://spidergl.org/example.php?id=6
16785
+ *
16786
+ * originally from
16787
+ * http://www.gamedev.net/topic/442138-packing-a-float-into-a-a8r8g8b8-texture-shader/page__whichpage__1%25EF%25BF%25BD
16788
+ *
16789
+ * see also
16790
+ * http://aras-p.info/blog/2009/07/30/encoding-floats-to-rgba-the-final/
16791
+ */
16792
+
16793
+ 'depthRGBA': {
16794
+
16795
+ uniforms: {},
16796
+
16797
+ vertexShader: [
16798
+
16799
+ THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
16800
+ THREE.ShaderChunk[ "skinning_pars_vertex" ],
16801
+ THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
16802
+
16803
+ "void main() {",
16804
+
16805
+ THREE.ShaderChunk[ "skinbase_vertex" ],
16806
+ THREE.ShaderChunk[ "morphtarget_vertex" ],
16807
+ THREE.ShaderChunk[ "skinning_vertex" ],
16808
+ THREE.ShaderChunk[ "default_vertex" ],
16809
+ THREE.ShaderChunk[ "logdepthbuf_vertex" ],
16810
+
16811
+ "}"
16812
+
16813
+ ].join("\n"),
16814
+
16815
+ fragmentShader: [
16816
+
16817
+ THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
16818
+
16819
+ "vec4 pack_depth( const in float depth ) {",
16820
+
16821
+ " const vec4 bit_shift = vec4( 256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0 );",
16822
+ " const vec4 bit_mask = vec4( 0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0 );",
16823
+ " vec4 res = mod( depth * bit_shift * vec4( 255 ), vec4( 256 ) ) / vec4( 255 );", // " vec4 res = fract( depth * bit_shift );",
16824
+ " res -= res.xxyz * bit_mask;",
16825
+ " return res;",
16826
+
16827
+ "}",
16828
+
16829
+ "void main() {",
16830
+
16831
+ THREE.ShaderChunk[ "logdepthbuf_fragment" ],
16832
+
16833
+ " #ifdef USE_LOGDEPTHBUF_EXT",
16834
+
16835
+ " gl_FragData[ 0 ] = pack_depth( gl_FragDepthEXT );",
16836
+
16837
+ " #else",
16838
+
16839
+ " gl_FragData[ 0 ] = pack_depth( gl_FragCoord.z );",
16840
+
16841
+ " #endif",
16842
+
16843
+ //"gl_FragData[ 0 ] = pack_depth( gl_FragCoord.z / gl_FragCoord.w );",
16844
+ //"float z = ( ( gl_FragCoord.z / gl_FragCoord.w ) - 3.0 ) / ( 4000.0 - 3.0 );",
16845
+ //"gl_FragData[ 0 ] = pack_depth( z );",
16846
+ //"gl_FragData[ 0 ] = vec4( z, z, z, 1.0 );",
16847
+
16848
+ "}"
16849
+
16850
+ ].join("\n")
16851
+
16852
+ }
16853
+
16854
+ };
16855
+
16856
+ // File:src/renderers/WebGLRenderer.js
16857
+
16858
+ /**
16859
+ * @author supereggbert / http://www.paulbrunt.co.uk/
16860
+ * @author mrdoob / http://mrdoob.com/
16861
+ * @author alteredq / http://alteredqualia.com/
16862
+ * @author szimek / https://github.com/szimek/
16863
+ */
16864
+
16865
+ THREE.WebGLRenderer = function ( parameters ) {
16866
+
16867
+ console.log( 'THREE.WebGLRenderer', THREE.REVISION );
16868
+
16869
+ parameters = parameters || {};
16870
+
16871
+ var _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElement( 'canvas' ),
16872
+ _context = parameters.context !== undefined ? parameters.context : null,
16873
+
16874
+ _precision = parameters.precision !== undefined ? parameters.precision : 'highp',
16875
+
16876
+ _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
16877
+ _depth = parameters.depth !== undefined ? parameters.depth : true,
16878
+ _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
16879
+ _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
16880
+ _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
16881
+ _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false,
16882
+ _logarithmicDepthBuffer = parameters.logarithmicDepthBuffer !== undefined ? parameters.logarithmicDepthBuffer : false,
16883
+
16884
+ _clearColor = new THREE.Color( 0x000000 ),
16885
+ _clearAlpha = 0;
16886
+
16887
+ var lights = [];
16888
+
16889
+ var _webglObjects = {};
16890
+ var _webglObjectsImmediate = [];
16891
+
16892
+ var opaqueObjects = [];
16893
+ var transparentObjects = [];
16894
+
16895
+ var sprites = [];
16896
+ var lensFlares = [];
16897
+
16898
+ // public properties
16899
+
16900
+ this.domElement = _canvas;
16901
+ this.context = null;
16902
+ this.devicePixelRatio = parameters.devicePixelRatio !== undefined
16903
+ ? parameters.devicePixelRatio
16904
+ : self.devicePixelRatio !== undefined
16905
+ ? self.devicePixelRatio
16906
+ : 1;
16907
+
16908
+ // clearing
16909
+
16910
+ this.autoClear = true;
16911
+ this.autoClearColor = true;
16912
+ this.autoClearDepth = true;
16913
+ this.autoClearStencil = true;
16914
+
16915
+ // scene graph
16916
+
16917
+ this.sortObjects = true;
16918
+
16919
+ // physically based shading
16920
+
16921
+ this.gammaInput = false;
16922
+ this.gammaOutput = false;
16923
+
16924
+ // shadow map
16925
+
16926
+ this.shadowMapEnabled = false;
16927
+ this.shadowMapType = THREE.PCFShadowMap;
16928
+ this.shadowMapCullFace = THREE.CullFaceFront;
16929
+ this.shadowMapDebug = false;
16930
+ this.shadowMapCascade = false;
16931
+
16932
+ // morphs
16933
+
16934
+ this.maxMorphTargets = 8;
16935
+ this.maxMorphNormals = 4;
16936
+
16937
+ // flags
16938
+
16939
+ this.autoScaleCubemaps = true;
16940
+
16941
+ // info
16942
+
16943
+ this.info = {
16944
+
16945
+ memory: {
16946
+
16947
+ programs: 0,
16948
+ geometries: 0,
16949
+ textures: 0
16950
+
16951
+ },
16952
+
16953
+ render: {
16954
+
16955
+ calls: 0,
16956
+ vertices: 0,
16957
+ faces: 0,
16958
+ points: 0
16959
+
16960
+ }
16961
+
16962
+ };
16963
+
16964
+ // internal properties
16965
+
16966
+ var _this = this,
16967
+
16968
+ _programs = [],
16969
+
16970
+ // internal state cache
16971
+
16972
+ _currentProgram = null,
16973
+ _currentFramebuffer = null,
16974
+ _currentMaterialId = - 1,
16975
+ _currentGeometryGroupHash = - 1,
16976
+ _currentCamera = null,
16977
+
16978
+ _usedTextureUnits = 0,
16979
+
16980
+ // GL state cache
16981
+
16982
+ _oldDoubleSided = - 1,
16983
+ _oldFlipSided = - 1,
16984
+
16985
+ _oldBlending = - 1,
16986
+
16987
+ _oldBlendEquation = - 1,
16988
+ _oldBlendSrc = - 1,
16989
+ _oldBlendDst = - 1,
16990
+
16991
+ _oldDepthTest = - 1,
16992
+ _oldDepthWrite = - 1,
16993
+
16994
+ _oldPolygonOffset = null,
16995
+ _oldPolygonOffsetFactor = null,
16996
+ _oldPolygonOffsetUnits = null,
16997
+
16998
+ _oldLineWidth = null,
16999
+
17000
+ _viewportX = 0,
17001
+ _viewportY = 0,
17002
+ _viewportWidth = _canvas.width,
17003
+ _viewportHeight = _canvas.height,
17004
+ _currentWidth = 0,
17005
+ _currentHeight = 0,
17006
+
17007
+ _newAttributes = new Uint8Array( 16 ),
17008
+ _enabledAttributes = new Uint8Array( 16 ),
17009
+
17010
+ // frustum
17011
+
17012
+ _frustum = new THREE.Frustum(),
17013
+
17014
+ // camera matrices cache
17015
+
17016
+ _projScreenMatrix = new THREE.Matrix4(),
17017
+ _projScreenMatrixPS = new THREE.Matrix4(),
17018
+
17019
+ _vector3 = new THREE.Vector3(),
17020
+
17021
+ // light arrays cache
17022
+
17023
+ _direction = new THREE.Vector3(),
17024
+
17025
+ _lightsNeedUpdate = true,
17026
+
17027
+ _lights = {
17028
+
17029
+ ambient: [ 0, 0, 0 ],
17030
+ directional: { length: 0, colors:[], positions: [] },
17031
+ point: { length: 0, colors: [], positions: [], distances: [] },
17032
+ spot: { length: 0, colors: [], positions: [], distances: [], directions: [], anglesCos: [], exponents: [] },
17033
+ hemi: { length: 0, skyColors: [], groundColors: [], positions: [] }
17034
+
17035
+ };
17036
+
17037
+ // initialize
17038
+
17039
+ var _gl;
17040
+
17041
+ try {
17042
+
17043
+ var attributes = {
17044
+ alpha: _alpha,
17045
+ depth: _depth,
17046
+ stencil: _stencil,
17047
+ antialias: _antialias,
17048
+ premultipliedAlpha: _premultipliedAlpha,
17049
+ preserveDrawingBuffer: _preserveDrawingBuffer
17050
+ };
17051
+
17052
+ _gl = _context || _canvas.getContext( 'webgl', attributes ) || _canvas.getContext( 'experimental-webgl', attributes );
17053
+
17054
+ if ( _gl === null ) {
17055
+
17056
+ if ( _canvas.getContext( 'webgl') !== null ) {
17057
+
17058
+ throw 'Error creating WebGL context with your selected attributes.';
17059
+
17060
+ } else {
17061
+
17062
+ throw 'Error creating WebGL context.';
17063
+
17064
+ }
17065
+
17066
+ }
17067
+
17068
+ } catch ( error ) {
17069
+
17070
+ console.error( error );
17071
+
17072
+ }
17073
+
17074
+ if ( _gl.getShaderPrecisionFormat === undefined ) {
17075
+
17076
+ _gl.getShaderPrecisionFormat = function () {
17077
+
17078
+ return {
17079
+ 'rangeMin': 1,
17080
+ 'rangeMax': 1,
17081
+ 'precision': 1
17082
+ };
17083
+
17084
+ }
17085
+
17086
+ }
17087
+
17088
+ var extensions = new THREE.WebGLExtensions( _gl );
17089
+
17090
+ extensions.get( 'OES_texture_float' );
17091
+ extensions.get( 'OES_texture_float_linear' );
17092
+ extensions.get( 'OES_standard_derivatives' );
17093
+
17094
+ if ( _logarithmicDepthBuffer ) {
17095
+
17096
+ extensions.get( 'EXT_frag_depth' );
17097
+
17098
+ }
17099
+
17100
+ //
17101
+
17102
+ function setDefaultGLState() {
17103
+
17104
+ _gl.clearColor( 0, 0, 0, 1 );
17105
+ _gl.clearDepth( 1 );
17106
+ _gl.clearStencil( 0 );
17107
+
17108
+ _gl.enable( _gl.DEPTH_TEST );
17109
+ _gl.depthFunc( _gl.LEQUAL );
17110
+
17111
+ _gl.frontFace( _gl.CCW );
17112
+ _gl.cullFace( _gl.BACK );
17113
+ _gl.enable( _gl.CULL_FACE );
17114
+
17115
+ _gl.enable( _gl.BLEND );
17116
+ _gl.blendEquation( _gl.FUNC_ADD );
17117
+ _gl.blendFunc( _gl.SRC_ALPHA, _gl.ONE_MINUS_SRC_ALPHA );
17118
+
17119
+ _gl.viewport( _viewportX, _viewportY, _viewportWidth, _viewportHeight );
17120
+
17121
+ _gl.clearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
17122
+
17123
+ }
17124
+
17125
+ setDefaultGLState();
17126
+
17127
+ this.context = _gl;
17128
+
17129
+ // GPU capabilities
17130
+
17131
+ var _maxTextures = _gl.getParameter( _gl.MAX_TEXTURE_IMAGE_UNITS );
17132
+ var _maxVertexTextures = _gl.getParameter( _gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS );
17133
+ var _maxTextureSize = _gl.getParameter( _gl.MAX_TEXTURE_SIZE );
17134
+ var _maxCubemapSize = _gl.getParameter( _gl.MAX_CUBE_MAP_TEXTURE_SIZE );
17135
+
17136
+ var _supportsVertexTextures = _maxVertexTextures > 0;
17137
+ var _supportsBoneTextures = _supportsVertexTextures && extensions.get( 'OES_texture_float' );
17138
+
17139
+ //
17140
+
17141
+ var _vertexShaderPrecisionHighpFloat = _gl.getShaderPrecisionFormat( _gl.VERTEX_SHADER, _gl.HIGH_FLOAT );
17142
+ var _vertexShaderPrecisionMediumpFloat = _gl.getShaderPrecisionFormat( _gl.VERTEX_SHADER, _gl.MEDIUM_FLOAT );
17143
+ var _vertexShaderPrecisionLowpFloat = _gl.getShaderPrecisionFormat( _gl.VERTEX_SHADER, _gl.LOW_FLOAT );
17144
+
17145
+ var _fragmentShaderPrecisionHighpFloat = _gl.getShaderPrecisionFormat( _gl.FRAGMENT_SHADER, _gl.HIGH_FLOAT );
17146
+ var _fragmentShaderPrecisionMediumpFloat = _gl.getShaderPrecisionFormat( _gl.FRAGMENT_SHADER, _gl.MEDIUM_FLOAT );
17147
+ var _fragmentShaderPrecisionLowpFloat = _gl.getShaderPrecisionFormat( _gl.FRAGMENT_SHADER, _gl.LOW_FLOAT );
17148
+
17149
+ var getCompressedTextureFormats = ( function () {
17150
+
17151
+ var array;
17152
+
17153
+ return function () {
17154
+
17155
+ if ( array !== undefined ) {
17156
+
17157
+ return array;
17158
+
17159
+ }
17160
+
17161
+ array = [];
17162
+
17163
+ if ( extensions.get( 'WEBGL_compressed_texture_pvrtc' ) || extensions.get( 'WEBGL_compressed_texture_s3tc' ) ) {
17164
+
17165
+ var formats = _gl.getParameter( _gl.COMPRESSED_TEXTURE_FORMATS );
17166
+
17167
+ for ( var i = 0; i < formats.length; i ++ ){
17168
+
17169
+ array.push( formats[ i ] );
17170
+
17171
+ }
17172
+
17173
+ }
17174
+
17175
+ return array;
17176
+
17177
+ };
17178
+
17179
+ } )();
17180
+
17181
+ // clamp precision to maximum available
17182
+
17183
+ var highpAvailable = _vertexShaderPrecisionHighpFloat.precision > 0 && _fragmentShaderPrecisionHighpFloat.precision > 0;
17184
+ var mediumpAvailable = _vertexShaderPrecisionMediumpFloat.precision > 0 && _fragmentShaderPrecisionMediumpFloat.precision > 0;
17185
+
17186
+ if ( _precision === 'highp' && ! highpAvailable ) {
17187
+
17188
+ if ( mediumpAvailable ) {
17189
+
17190
+ _precision = 'mediump';
17191
+ console.warn( 'THREE.WebGLRenderer: highp not supported, using mediump.' );
17192
+
17193
+ } else {
17194
+
17195
+ _precision = 'lowp';
17196
+ console.warn( 'THREE.WebGLRenderer: highp and mediump not supported, using lowp.' );
17197
+
17198
+ }
17199
+
17200
+ }
17201
+
17202
+ if ( _precision === 'mediump' && ! mediumpAvailable ) {
17203
+
17204
+ _precision = 'lowp';
17205
+ console.warn( 'THREE.WebGLRenderer: mediump not supported, using lowp.' );
17206
+
17207
+ }
17208
+
17209
+ // Plugins
17210
+
17211
+ var shadowMapPlugin = new THREE.ShadowMapPlugin( this, lights, _webglObjects, _webglObjectsImmediate );
17212
+
17213
+ var spritePlugin = new THREE.SpritePlugin( this, sprites );
17214
+ var lensFlarePlugin = new THREE.LensFlarePlugin( this, lensFlares );
17215
+
17216
+ // API
17217
+
17218
+ this.getContext = function () {
17219
+
17220
+ return _gl;
17221
+
17222
+ };
17223
+
17224
+ this.supportsVertexTextures = function () {
17225
+
17226
+ return _supportsVertexTextures;
17227
+
17228
+ };
17229
+
17230
+ this.supportsFloatTextures = function () {
17231
+
17232
+ return extensions.get( 'OES_texture_float' );
17233
+
17234
+ };
17235
+
17236
+ this.supportsStandardDerivatives = function () {
17237
+
17238
+ return extensions.get( 'OES_standard_derivatives' );
17239
+
17240
+ };
17241
+
17242
+ this.supportsCompressedTextureS3TC = function () {
17243
+
17244
+ return extensions.get( 'WEBGL_compressed_texture_s3tc' );
17245
+
17246
+ };
17247
+
17248
+ this.supportsCompressedTexturePVRTC = function () {
17249
+
17250
+ return extensions.get( 'WEBGL_compressed_texture_pvrtc' );
17251
+
17252
+ };
17253
+
17254
+ this.supportsBlendMinMax = function () {
17255
+
17256
+ return extensions.get( 'EXT_blend_minmax' );
17257
+
17258
+ };
17259
+
17260
+ this.getMaxAnisotropy = ( function () {
17261
+
17262
+ var value;
17263
+
17264
+ return function () {
17265
+
17266
+ if ( value !== undefined ) {
17267
+
17268
+ return value;
17269
+
17270
+ }
17271
+
17272
+ var extension = extensions.get( 'EXT_texture_filter_anisotropic' );
17273
+
17274
+ value = extension !== null ? _gl.getParameter( extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT ) : 0;
17275
+
17276
+ return value;
17277
+
17278
+ }
17279
+
17280
+ } )();
17281
+
17282
+ this.getPrecision = function () {
17283
+
17284
+ return _precision;
17285
+
17286
+ };
17287
+
17288
+ this.setSize = function ( width, height, updateStyle ) {
17289
+
17290
+ _canvas.width = width * this.devicePixelRatio;
17291
+ _canvas.height = height * this.devicePixelRatio;
17292
+
17293
+ if ( updateStyle !== false ) {
17294
+
17295
+ _canvas.style.width = width + 'px';
17296
+ _canvas.style.height = height + 'px';
17297
+
17298
+ }
17299
+
17300
+ this.setViewport( 0, 0, width, height );
17301
+
17302
+ };
17303
+
17304
+ this.setViewport = function ( x, y, width, height ) {
17305
+
17306
+ _viewportX = x * this.devicePixelRatio;
17307
+ _viewportY = y * this.devicePixelRatio;
17308
+
17309
+ _viewportWidth = width * this.devicePixelRatio;
17310
+ _viewportHeight = height * this.devicePixelRatio;
17311
+
17312
+ _gl.viewport( _viewportX, _viewportY, _viewportWidth, _viewportHeight );
17313
+
17314
+ };
17315
+
17316
+ this.setScissor = function ( x, y, width, height ) {
17317
+
17318
+ _gl.scissor(
17319
+ x * this.devicePixelRatio,
17320
+ y * this.devicePixelRatio,
17321
+ width * this.devicePixelRatio,
17322
+ height * this.devicePixelRatio
17323
+ );
17324
+
17325
+ };
17326
+
17327
+ this.enableScissorTest = function ( enable ) {
17328
+
17329
+ enable ? _gl.enable( _gl.SCISSOR_TEST ) : _gl.disable( _gl.SCISSOR_TEST );
17330
+
17331
+ };
17332
+
17333
+ // Clearing
17334
+
17335
+ this.setClearColor = function ( color, alpha ) {
17336
+
17337
+ _clearColor.set( color );
17338
+ _clearAlpha = alpha !== undefined ? alpha : 1;
17339
+
17340
+ _gl.clearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
17341
+
17342
+ };
17343
+
17344
+ this.setClearColorHex = function ( hex, alpha ) {
17345
+
17346
+ console.warn( 'THREE.WebGLRenderer: .setClearColorHex() is being removed. Use .setClearColor() instead.' );
17347
+ this.setClearColor( hex, alpha );
17348
+
17349
+ };
17350
+
17351
+ this.getClearColor = function () {
17352
+
17353
+ return _clearColor;
17354
+
17355
+ };
17356
+
17357
+ this.getClearAlpha = function () {
17358
+
17359
+ return _clearAlpha;
17360
+
17361
+ };
17362
+
17363
+ this.clear = function ( color, depth, stencil ) {
17364
+
17365
+ var bits = 0;
17366
+
17367
+ if ( color === undefined || color ) bits |= _gl.COLOR_BUFFER_BIT;
17368
+ if ( depth === undefined || depth ) bits |= _gl.DEPTH_BUFFER_BIT;
17369
+ if ( stencil === undefined || stencil ) bits |= _gl.STENCIL_BUFFER_BIT;
17370
+
17371
+ _gl.clear( bits );
17372
+
17373
+ };
17374
+
17375
+ this.clearColor = function () {
17376
+
17377
+ _gl.clear( _gl.COLOR_BUFFER_BIT );
17378
+
17379
+ };
17380
+
17381
+ this.clearDepth = function () {
17382
+
17383
+ _gl.clear( _gl.DEPTH_BUFFER_BIT );
17384
+
17385
+ };
17386
+
17387
+ this.clearStencil = function () {
17388
+
17389
+ _gl.clear( _gl.STENCIL_BUFFER_BIT );
17390
+
17391
+ };
17392
+
17393
+ this.clearTarget = function ( renderTarget, color, depth, stencil ) {
17394
+
17395
+ this.setRenderTarget( renderTarget );
17396
+ this.clear( color, depth, stencil );
17397
+
17398
+ };
17399
+
17400
+ // Reset
17401
+
17402
+ this.resetGLState = function () {
17403
+
17404
+ _currentProgram = null;
17405
+ _currentCamera = null;
17406
+
17407
+ _oldBlending = - 1;
17408
+ _oldDepthTest = - 1;
17409
+ _oldDepthWrite = - 1;
17410
+ _oldDoubleSided = - 1;
17411
+ _oldFlipSided = - 1;
17412
+ _currentGeometryGroupHash = - 1;
17413
+ _currentMaterialId = - 1;
17414
+
17415
+ _lightsNeedUpdate = true;
17416
+
17417
+ };
17418
+
17419
+ // Buffer allocation
17420
+
17421
+ function createParticleBuffers ( geometry ) {
17422
+
17423
+ geometry.__webglVertexBuffer = _gl.createBuffer();
17424
+ geometry.__webglColorBuffer = _gl.createBuffer();
17425
+
17426
+ _this.info.memory.geometries ++;
17427
+
17428
+ };
17429
+
17430
+ function createLineBuffers ( geometry ) {
17431
+
17432
+ geometry.__webglVertexBuffer = _gl.createBuffer();
17433
+ geometry.__webglColorBuffer = _gl.createBuffer();
17434
+ geometry.__webglLineDistanceBuffer = _gl.createBuffer();
17435
+
17436
+ _this.info.memory.geometries ++;
17437
+
17438
+ };
17439
+
17440
+ function createMeshBuffers ( geometryGroup ) {
17441
+
17442
+ geometryGroup.__webglVertexBuffer = _gl.createBuffer();
17443
+ geometryGroup.__webglNormalBuffer = _gl.createBuffer();
17444
+ geometryGroup.__webglTangentBuffer = _gl.createBuffer();
17445
+ geometryGroup.__webglColorBuffer = _gl.createBuffer();
17446
+ geometryGroup.__webglUVBuffer = _gl.createBuffer();
17447
+ geometryGroup.__webglUV2Buffer = _gl.createBuffer();
17448
+
17449
+ geometryGroup.__webglSkinIndicesBuffer = _gl.createBuffer();
17450
+ geometryGroup.__webglSkinWeightsBuffer = _gl.createBuffer();
17451
+
17452
+ geometryGroup.__webglFaceBuffer = _gl.createBuffer();
17453
+ geometryGroup.__webglLineBuffer = _gl.createBuffer();
17454
+
17455
+ var m, ml;
17456
+
17457
+ if ( geometryGroup.numMorphTargets ) {
17458
+
17459
+ geometryGroup.__webglMorphTargetsBuffers = [];
17460
+
17461
+ for ( m = 0, ml = geometryGroup.numMorphTargets; m < ml; m ++ ) {
17462
+
17463
+ geometryGroup.__webglMorphTargetsBuffers.push( _gl.createBuffer() );
17464
+
17465
+ }
17466
+
17467
+ }
17468
+
17469
+ if ( geometryGroup.numMorphNormals ) {
17470
+
17471
+ geometryGroup.__webglMorphNormalsBuffers = [];
17472
+
17473
+ for ( m = 0, ml = geometryGroup.numMorphNormals; m < ml; m ++ ) {
17474
+
17475
+ geometryGroup.__webglMorphNormalsBuffers.push( _gl.createBuffer() );
17476
+
17477
+ }
17478
+
17479
+ }
17480
+
17481
+ _this.info.memory.geometries ++;
17482
+
17483
+ };
17484
+
17485
+ // Events
17486
+
17487
+ var onObjectRemoved = function ( event ) {
17488
+
17489
+ var object = event.target;
17490
+
17491
+ object.traverse( function ( child ) {
17492
+
17493
+ child.removeEventListener( 'remove', onObjectRemoved );
17494
+
17495
+ removeObject( child );
17496
+
17497
+ } );
17498
+
17499
+ };
17500
+
17501
+ var onGeometryDispose = function ( event ) {
17502
+
17503
+ var geometry = event.target;
17504
+
17505
+ geometry.removeEventListener( 'dispose', onGeometryDispose );
17506
+
17507
+ deallocateGeometry( geometry );
17508
+
17509
+ };
17510
+
17511
+ var onTextureDispose = function ( event ) {
17512
+
17513
+ var texture = event.target;
17514
+
17515
+ texture.removeEventListener( 'dispose', onTextureDispose );
17516
+
17517
+ deallocateTexture( texture );
17518
+
17519
+ _this.info.memory.textures --;
17520
+
17521
+
17522
+ };
17523
+
17524
+ var onRenderTargetDispose = function ( event ) {
17525
+
17526
+ var renderTarget = event.target;
17527
+
17528
+ renderTarget.removeEventListener( 'dispose', onRenderTargetDispose );
17529
+
17530
+ deallocateRenderTarget( renderTarget );
17531
+
17532
+ _this.info.memory.textures --;
17533
+
17534
+ };
17535
+
17536
+ var onMaterialDispose = function ( event ) {
17537
+
17538
+ var material = event.target;
17539
+
17540
+ material.removeEventListener( 'dispose', onMaterialDispose );
17541
+
17542
+ deallocateMaterial( material );
17543
+
17544
+ };
17545
+
17546
+ // Buffer deallocation
17547
+
17548
+ var deleteBuffers = function ( geometry ) {
17549
+
17550
+ var buffers = [
17551
+ '__webglVertexBuffer',
17552
+ '__webglNormalBuffer',
17553
+ '__webglTangentBuffer',
17554
+ '__webglColorBuffer',
17555
+ '__webglUVBuffer',
17556
+ '__webglUV2Buffer',
17557
+
17558
+ '__webglSkinIndicesBuffer',
17559
+ '__webglSkinWeightsBuffer',
17560
+
17561
+ '__webglFaceBuffer',
17562
+ '__webglLineBuffer',
17563
+
17564
+ '__webglLineDistanceBuffer'
17565
+ ];
17566
+
17567
+ for ( var i = 0, l = buffers.length; i < l; i ++ ) {
17568
+
17569
+ var name = buffers[ i ];
17570
+
17571
+ if ( geometry[ name ] !== undefined ) {
17572
+
17573
+ _gl.deleteBuffer( geometry[ name ] );
17574
+
17575
+ delete geometry[ name ];
17576
+
17577
+ }
17578
+
17579
+ }
17580
+
17581
+ // custom attributes
17582
+
17583
+ if ( geometry.__webglCustomAttributesList !== undefined ) {
17584
+
17585
+ for ( var name in geometry.__webglCustomAttributesList ) {
17586
+
17587
+ _gl.deleteBuffer( geometry.__webglCustomAttributesList[ name ].buffer );
17588
+
17589
+ }
17590
+
17591
+ delete geometry.__webglCustomAttributesList;
17592
+
17593
+ }
17594
+
17595
+ _this.info.memory.geometries --;
17596
+
17597
+ };
17598
+
17599
+ var deallocateGeometry = function ( geometry ) {
17600
+
17601
+ delete geometry.__webglInit;
17602
+
17603
+ if ( geometry instanceof THREE.BufferGeometry ) {
17604
+
17605
+ for ( var name in geometry.attributes ) {
17606
+
17607
+ var attribute = geometry.attributes[ name ];
17608
+
17609
+ if ( attribute.buffer !== undefined ) {
17610
+
17611
+ _gl.deleteBuffer( attribute.buffer );
17612
+
17613
+ delete attribute.buffer;
17614
+
17615
+ }
17616
+
17617
+ }
17618
+
17619
+ _this.info.memory.geometries --;
17620
+
17621
+ } else {
17622
+
17623
+ var geometryGroupsList = geometryGroups[ geometry.id ];
17624
+
17625
+ if ( geometryGroupsList !== undefined ) {
17626
+
17627
+ for ( var i = 0,l = geometryGroupsList.length; i < l; i ++ ) {
17628
+
17629
+ var geometryGroup = geometryGroupsList[ i ];
17630
+
17631
+ if ( geometryGroup.numMorphTargets !== undefined ) {
17632
+
17633
+ for ( var m = 0, ml = geometryGroup.numMorphTargets; m < ml; m ++ ) {
17634
+
17635
+ _gl.deleteBuffer( geometryGroup.__webglMorphTargetsBuffers[ m ] );
17636
+
17637
+ }
17638
+
17639
+ delete geometryGroup.__webglMorphTargetsBuffers;
17640
+
17641
+ }
17642
+
17643
+ if ( geometryGroup.numMorphNormals !== undefined ) {
17644
+
17645
+ for ( var m = 0, ml = geometryGroup.numMorphNormals; m < ml; m ++ ) {
17646
+
17647
+ _gl.deleteBuffer( geometryGroup.__webglMorphNormalsBuffers[ m ] );
17648
+
17649
+ }
17650
+
17651
+ delete geometryGroup.__webglMorphNormalsBuffers;
17652
+
17653
+ }
17654
+
17655
+ deleteBuffers( geometryGroup );
17656
+
17657
+ }
17658
+
17659
+ delete geometryGroups[ geometry.id ];
17660
+
17661
+ } else {
17662
+
17663
+ deleteBuffers( geometry );
17664
+
17665
+ }
17666
+
17667
+ }
17668
+
17669
+ // TOFIX: Workaround for deleted geometry being currently bound
17670
+
17671
+ _currentGeometryGroupHash = - 1;
17672
+
17673
+ };
17674
+
17675
+ var deallocateTexture = function ( texture ) {
17676
+
17677
+ if ( texture.image && texture.image.__webglTextureCube ) {
17678
+
17679
+ // cube texture
17680
+
17681
+ _gl.deleteTexture( texture.image.__webglTextureCube );
17682
+
17683
+ delete texture.image.__webglTextureCube;
17684
+
17685
+ } else {
17686
+
17687
+ // 2D texture
17688
+
17689
+ if ( texture.__webglInit === undefined ) return;
17690
+
17691
+ _gl.deleteTexture( texture.__webglTexture );
17692
+
17693
+ delete texture.__webglTexture;
17694
+ delete texture.__webglInit;
17695
+
17696
+ }
17697
+
17698
+ };
17699
+
17700
+ var deallocateRenderTarget = function ( renderTarget ) {
17701
+
17702
+ if ( ! renderTarget || renderTarget.__webglTexture === undefined ) return;
17703
+
17704
+ _gl.deleteTexture( renderTarget.__webglTexture );
17705
+
17706
+ delete renderTarget.__webglTexture;
17707
+
17708
+ if ( renderTarget instanceof THREE.WebGLRenderTargetCube ) {
17709
+
17710
+ for ( var i = 0; i < 6; i ++ ) {
17711
+
17712
+ _gl.deleteFramebuffer( renderTarget.__webglFramebuffer[ i ] );
17713
+ _gl.deleteRenderbuffer( renderTarget.__webglRenderbuffer[ i ] );
17714
+
17715
+ }
17716
+
17717
+ } else {
17718
+
17719
+ _gl.deleteFramebuffer( renderTarget.__webglFramebuffer );
17720
+ _gl.deleteRenderbuffer( renderTarget.__webglRenderbuffer );
17721
+
17722
+ }
17723
+
17724
+ delete renderTarget.__webglFramebuffer;
17725
+ delete renderTarget.__webglRenderbuffer;
17726
+
17727
+ };
17728
+
17729
+ var deallocateMaterial = function ( material ) {
17730
+
17731
+ var program = material.program.program;
17732
+
17733
+ if ( program === undefined ) return;
17734
+
17735
+ material.program = undefined;
17736
+
17737
+ // only deallocate GL program if this was the last use of shared program
17738
+ // assumed there is only single copy of any program in the _programs list
17739
+ // (that's how it's constructed)
17740
+
17741
+ var i, il, programInfo;
17742
+ var deleteProgram = false;
17743
+
17744
+ for ( i = 0, il = _programs.length; i < il; i ++ ) {
17745
+
17746
+ programInfo = _programs[ i ];
17747
+
17748
+ if ( programInfo.program === program ) {
17749
+
17750
+ programInfo.usedTimes --;
17751
+
17752
+ if ( programInfo.usedTimes === 0 ) {
17753
+
17754
+ deleteProgram = true;
17755
+
17756
+ }
17757
+
17758
+ break;
17759
+
17760
+ }
17761
+
17762
+ }
17763
+
17764
+ if ( deleteProgram === true ) {
17765
+
17766
+ // avoid using array.splice, this is costlier than creating new array from scratch
17767
+
17768
+ var newPrograms = [];
17769
+
17770
+ for ( i = 0, il = _programs.length; i < il; i ++ ) {
17771
+
17772
+ programInfo = _programs[ i ];
17773
+
17774
+ if ( programInfo.program !== program ) {
17775
+
17776
+ newPrograms.push( programInfo );
17777
+
17778
+ }
17779
+
17780
+ }
17781
+
17782
+ _programs = newPrograms;
17783
+
17784
+ _gl.deleteProgram( program );
17785
+
17786
+ _this.info.memory.programs --;
17787
+
17788
+ }
17789
+
17790
+ };
17791
+
17792
+ // Buffer initialization
17793
+
17794
+ function initCustomAttributes ( object ) {
17795
+
17796
+ var geometry = object.geometry;
17797
+ var material = object.material;
17798
+
17799
+ var nvertices = geometry.vertices.length;
17800
+
17801
+ if ( material.attributes ) {
17802
+
17803
+ if ( geometry.__webglCustomAttributesList === undefined ) {
17804
+
17805
+ geometry.__webglCustomAttributesList = [];
17806
+
17807
+ }
17808
+
17809
+ for ( var name in material.attributes ) {
17810
+
17811
+ var attribute = material.attributes[ name ];
17812
+
17813
+ if ( ! attribute.__webglInitialized || attribute.createUniqueBuffers ) {
17814
+
17815
+ attribute.__webglInitialized = true;
17816
+
17817
+ var size = 1; // "f" and "i"
17818
+
17819
+ if ( attribute.type === 'v2' ) size = 2;
17820
+ else if ( attribute.type === 'v3' ) size = 3;
17821
+ else if ( attribute.type === 'v4' ) size = 4;
17822
+ else if ( attribute.type === 'c' ) size = 3;
17823
+
17824
+ attribute.size = size;
17825
+
17826
+ attribute.array = new Float32Array( nvertices * size );
17827
+
17828
+ attribute.buffer = _gl.createBuffer();
17829
+ attribute.buffer.belongsToAttribute = name;
17830
+
17831
+ attribute.needsUpdate = true;
17832
+
17833
+ }
17834
+
17835
+ geometry.__webglCustomAttributesList.push( attribute );
17836
+
17837
+ }
17838
+
17839
+ }
17840
+
17841
+ };
17842
+
17843
+ function initParticleBuffers ( geometry, object ) {
17844
+
17845
+ var nvertices = geometry.vertices.length;
17846
+
17847
+ geometry.__vertexArray = new Float32Array( nvertices * 3 );
17848
+ geometry.__colorArray = new Float32Array( nvertices * 3 );
17849
+
17850
+ geometry.__sortArray = [];
17851
+
17852
+ geometry.__webglParticleCount = nvertices;
17853
+
17854
+ initCustomAttributes( object );
17855
+
17856
+ };
17857
+
17858
+ function initLineBuffers ( geometry, object ) {
17859
+
17860
+ var nvertices = geometry.vertices.length;
17861
+
17862
+ geometry.__vertexArray = new Float32Array( nvertices * 3 );
17863
+ geometry.__colorArray = new Float32Array( nvertices * 3 );
17864
+ geometry.__lineDistanceArray = new Float32Array( nvertices * 1 );
17865
+
17866
+ geometry.__webglLineCount = nvertices;
17867
+
17868
+ initCustomAttributes( object );
17869
+
17870
+ };
17871
+
17872
+ function initMeshBuffers ( geometryGroup, object ) {
17873
+
17874
+ var geometry = object.geometry,
17875
+ faces3 = geometryGroup.faces3,
17876
+
17877
+ nvertices = faces3.length * 3,
17878
+ ntris = faces3.length * 1,
17879
+ nlines = faces3.length * 3,
17880
+
17881
+ material = getBufferMaterial( object, geometryGroup );
17882
+
17883
+ geometryGroup.__vertexArray = new Float32Array( nvertices * 3 );
17884
+ geometryGroup.__normalArray = new Float32Array( nvertices * 3 );
17885
+ geometryGroup.__colorArray = new Float32Array( nvertices * 3 );
17886
+ geometryGroup.__uvArray = new Float32Array( nvertices * 2 );
17887
+
17888
+ if ( geometry.faceVertexUvs.length > 1 ) {
17889
+
17890
+ geometryGroup.__uv2Array = new Float32Array( nvertices * 2 );
17891
+
17892
+ }
17893
+
17894
+ if ( geometry.hasTangents ) {
17895
+
17896
+ geometryGroup.__tangentArray = new Float32Array( nvertices * 4 );
17897
+
17898
+ }
17899
+
17900
+ if ( object.geometry.skinWeights.length && object.geometry.skinIndices.length ) {
17901
+
17902
+ geometryGroup.__skinIndexArray = new Float32Array( nvertices * 4 );
17903
+ geometryGroup.__skinWeightArray = new Float32Array( nvertices * 4 );
17904
+
17905
+ }
17906
+
17907
+ var UintArray = extensions.get( 'OES_element_index_uint' ) !== null && ntris > 21845 ? Uint32Array : Uint16Array; // 65535 / 3
17908
+
17909
+ geometryGroup.__typeArray = UintArray;
17910
+ geometryGroup.__faceArray = new UintArray( ntris * 3 );
17911
+ geometryGroup.__lineArray = new UintArray( nlines * 2 );
17912
+
17913
+ var m, ml;
17914
+
17915
+ if ( geometryGroup.numMorphTargets ) {
17916
+
17917
+ geometryGroup.__morphTargetsArrays = [];
17918
+
17919
+ for ( m = 0, ml = geometryGroup.numMorphTargets; m < ml; m ++ ) {
17920
+
17921
+ geometryGroup.__morphTargetsArrays.push( new Float32Array( nvertices * 3 ) );
17922
+
17923
+ }
17924
+
17925
+ }
17926
+
17927
+ if ( geometryGroup.numMorphNormals ) {
17928
+
17929
+ geometryGroup.__morphNormalsArrays = [];
17930
+
17931
+ for ( m = 0, ml = geometryGroup.numMorphNormals; m < ml; m ++ ) {
17932
+
17933
+ geometryGroup.__morphNormalsArrays.push( new Float32Array( nvertices * 3 ) );
17934
+
17935
+ }
17936
+
17937
+ }
17938
+
17939
+ geometryGroup.__webglFaceCount = ntris * 3;
17940
+ geometryGroup.__webglLineCount = nlines * 2;
17941
+
17942
+
17943
+ // custom attributes
17944
+
17945
+ if ( material.attributes ) {
17946
+
17947
+ if ( geometryGroup.__webglCustomAttributesList === undefined ) {
17948
+
17949
+ geometryGroup.__webglCustomAttributesList = [];
17950
+
17951
+ }
17952
+
17953
+ for ( var name in material.attributes ) {
17954
+
17955
+ // Do a shallow copy of the attribute object so different geometryGroup chunks use different
17956
+ // attribute buffers which are correctly indexed in the setMeshBuffers function
17957
+
17958
+ var originalAttribute = material.attributes[ name ];
17959
+
17960
+ var attribute = {};
17961
+
17962
+ for ( var property in originalAttribute ) {
17963
+
17964
+ attribute[ property ] = originalAttribute[ property ];
17965
+
17966
+ }
17967
+
17968
+ if ( ! attribute.__webglInitialized || attribute.createUniqueBuffers ) {
17969
+
17970
+ attribute.__webglInitialized = true;
17971
+
17972
+ var size = 1; // "f" and "i"
17973
+
17974
+ if ( attribute.type === 'v2' ) size = 2;
17975
+ else if ( attribute.type === 'v3' ) size = 3;
17976
+ else if ( attribute.type === 'v4' ) size = 4;
17977
+ else if ( attribute.type === 'c' ) size = 3;
17978
+
17979
+ attribute.size = size;
17980
+
17981
+ attribute.array = new Float32Array( nvertices * size );
17982
+
17983
+ attribute.buffer = _gl.createBuffer();
17984
+ attribute.buffer.belongsToAttribute = name;
17985
+
17986
+ originalAttribute.needsUpdate = true;
17987
+ attribute.__original = originalAttribute;
17988
+
17989
+ }
17990
+
17991
+ geometryGroup.__webglCustomAttributesList.push( attribute );
17992
+
17993
+ }
17994
+
17995
+ }
17996
+
17997
+ geometryGroup.__inittedArrays = true;
17998
+
17999
+ };
18000
+
18001
+ function getBufferMaterial( object, geometryGroup ) {
18002
+
18003
+ return object.material instanceof THREE.MeshFaceMaterial
18004
+ ? object.material.materials[ geometryGroup.materialIndex ]
18005
+ : object.material;
18006
+
18007
+ };
18008
+
18009
+ function materialNeedsSmoothNormals ( material ) {
18010
+
18011
+ return material && material.shading !== undefined && material.shading === THREE.SmoothShading;
18012
+
18013
+ };
18014
+
18015
+ // Buffer setting
18016
+
18017
+ function setParticleBuffers ( geometry, hint, object ) {
18018
+
18019
+ var v, c, vertex, offset, index, color,
18020
+
18021
+ vertices = geometry.vertices,
18022
+ vl = vertices.length,
18023
+
18024
+ colors = geometry.colors,
18025
+ cl = colors.length,
18026
+
18027
+ vertexArray = geometry.__vertexArray,
18028
+ colorArray = geometry.__colorArray,
18029
+
18030
+ sortArray = geometry.__sortArray,
18031
+
18032
+ dirtyVertices = geometry.verticesNeedUpdate,
18033
+ dirtyElements = geometry.elementsNeedUpdate,
18034
+ dirtyColors = geometry.colorsNeedUpdate,
18035
+
18036
+ customAttributes = geometry.__webglCustomAttributesList,
18037
+ i, il,
18038
+ a, ca, cal, value,
18039
+ customAttribute;
18040
+
18041
+ if ( object.sortParticles ) {
18042
+
18043
+ _projScreenMatrixPS.copy( _projScreenMatrix );
18044
+ _projScreenMatrixPS.multiply( object.matrixWorld );
18045
+
18046
+ for ( v = 0; v < vl; v ++ ) {
18047
+
18048
+ vertex = vertices[ v ];
18049
+
18050
+ _vector3.copy( vertex );
18051
+ _vector3.applyProjection( _projScreenMatrixPS );
18052
+
18053
+ sortArray[ v ] = [ _vector3.z, v ];
18054
+
18055
+ }
18056
+
18057
+ sortArray.sort( numericalSort );
18058
+
18059
+ for ( v = 0; v < vl; v ++ ) {
18060
+
18061
+ vertex = vertices[ sortArray[ v ][ 1 ] ];
18062
+
18063
+ offset = v * 3;
18064
+
18065
+ vertexArray[ offset ] = vertex.x;
18066
+ vertexArray[ offset + 1 ] = vertex.y;
18067
+ vertexArray[ offset + 2 ] = vertex.z;
18068
+
18069
+ }
18070
+
18071
+ for ( c = 0; c < cl; c ++ ) {
18072
+
18073
+ offset = c * 3;
18074
+
18075
+ color = colors[ sortArray[ c ][ 1 ] ];
18076
+
18077
+ colorArray[ offset ] = color.r;
18078
+ colorArray[ offset + 1 ] = color.g;
18079
+ colorArray[ offset + 2 ] = color.b;
18080
+
18081
+ }
18082
+
18083
+ if ( customAttributes ) {
18084
+
18085
+ for ( i = 0, il = customAttributes.length; i < il; i ++ ) {
18086
+
18087
+ customAttribute = customAttributes[ i ];
18088
+
18089
+ if ( ! ( customAttribute.boundTo === undefined || customAttribute.boundTo === 'vertices' ) ) continue;
18090
+
18091
+ offset = 0;
18092
+
18093
+ cal = customAttribute.value.length;
18094
+
18095
+ if ( customAttribute.size === 1 ) {
18096
+
18097
+ for ( ca = 0; ca < cal; ca ++ ) {
18098
+
18099
+ index = sortArray[ ca ][ 1 ];
18100
+
18101
+ customAttribute.array[ ca ] = customAttribute.value[ index ];
18102
+
18103
+ }
18104
+
18105
+ } else if ( customAttribute.size === 2 ) {
18106
+
18107
+ for ( ca = 0; ca < cal; ca ++ ) {
18108
+
18109
+ index = sortArray[ ca ][ 1 ];
18110
+
18111
+ value = customAttribute.value[ index ];
18112
+
18113
+ customAttribute.array[ offset ] = value.x;
18114
+ customAttribute.array[ offset + 1 ] = value.y;
18115
+
18116
+ offset += 2;
18117
+
18118
+ }
18119
+
18120
+ } else if ( customAttribute.size === 3 ) {
18121
+
18122
+ if ( customAttribute.type === 'c' ) {
18123
+
18124
+ for ( ca = 0; ca < cal; ca ++ ) {
18125
+
18126
+ index = sortArray[ ca ][ 1 ];
18127
+
18128
+ value = customAttribute.value[ index ];
18129
+
18130
+ customAttribute.array[ offset ] = value.r;
18131
+ customAttribute.array[ offset + 1 ] = value.g;
18132
+ customAttribute.array[ offset + 2 ] = value.b;
18133
+
18134
+ offset += 3;
18135
+
18136
+ }
18137
+
18138
+ } else {
18139
+
18140
+ for ( ca = 0; ca < cal; ca ++ ) {
18141
+
18142
+ index = sortArray[ ca ][ 1 ];
18143
+
18144
+ value = customAttribute.value[ index ];
18145
+
18146
+ customAttribute.array[ offset ] = value.x;
18147
+ customAttribute.array[ offset + 1 ] = value.y;
18148
+ customAttribute.array[ offset + 2 ] = value.z;
18149
+
18150
+ offset += 3;
18151
+
18152
+ }
18153
+
18154
+ }
18155
+
18156
+ } else if ( customAttribute.size === 4 ) {
18157
+
18158
+ for ( ca = 0; ca < cal; ca ++ ) {
18159
+
18160
+ index = sortArray[ ca ][ 1 ];
18161
+
18162
+ value = customAttribute.value[ index ];
18163
+
18164
+ customAttribute.array[ offset ] = value.x;
18165
+ customAttribute.array[ offset + 1 ] = value.y;
18166
+ customAttribute.array[ offset + 2 ] = value.z;
18167
+ customAttribute.array[ offset + 3 ] = value.w;
18168
+
18169
+ offset += 4;
18170
+
18171
+ }
18172
+
18173
+ }
18174
+
18175
+ }
18176
+
18177
+ }
18178
+
18179
+ } else {
18180
+
18181
+ if ( dirtyVertices ) {
18182
+
18183
+ for ( v = 0; v < vl; v ++ ) {
18184
+
18185
+ vertex = vertices[ v ];
18186
+
18187
+ offset = v * 3;
18188
+
18189
+ vertexArray[ offset ] = vertex.x;
18190
+ vertexArray[ offset + 1 ] = vertex.y;
18191
+ vertexArray[ offset + 2 ] = vertex.z;
18192
+
18193
+ }
18194
+
18195
+ }
18196
+
18197
+ if ( dirtyColors ) {
18198
+
18199
+ for ( c = 0; c < cl; c ++ ) {
18200
+
18201
+ color = colors[ c ];
18202
+
18203
+ offset = c * 3;
18204
+
18205
+ colorArray[ offset ] = color.r;
18206
+ colorArray[ offset + 1 ] = color.g;
18207
+ colorArray[ offset + 2 ] = color.b;
18208
+
18209
+ }
18210
+
18211
+ }
18212
+
18213
+ if ( customAttributes ) {
18214
+
18215
+ for ( i = 0, il = customAttributes.length; i < il; i ++ ) {
18216
+
18217
+ customAttribute = customAttributes[ i ];
18218
+
18219
+ if ( customAttribute.needsUpdate &&
18220
+ ( customAttribute.boundTo === undefined ||
18221
+ customAttribute.boundTo === 'vertices' ) ) {
18222
+
18223
+ cal = customAttribute.value.length;
18224
+
18225
+ offset = 0;
18226
+
18227
+ if ( customAttribute.size === 1 ) {
18228
+
18229
+ for ( ca = 0; ca < cal; ca ++ ) {
18230
+
18231
+ customAttribute.array[ ca ] = customAttribute.value[ ca ];
18232
+
18233
+ }
18234
+
18235
+ } else if ( customAttribute.size === 2 ) {
18236
+
18237
+ for ( ca = 0; ca < cal; ca ++ ) {
18238
+
18239
+ value = customAttribute.value[ ca ];
18240
+
18241
+ customAttribute.array[ offset ] = value.x;
18242
+ customAttribute.array[ offset + 1 ] = value.y;
18243
+
18244
+ offset += 2;
18245
+
18246
+ }
18247
+
18248
+ } else if ( customAttribute.size === 3 ) {
18249
+
18250
+ if ( customAttribute.type === 'c' ) {
18251
+
18252
+ for ( ca = 0; ca < cal; ca ++ ) {
18253
+
18254
+ value = customAttribute.value[ ca ];
18255
+
18256
+ customAttribute.array[ offset ] = value.r;
18257
+ customAttribute.array[ offset + 1 ] = value.g;
18258
+ customAttribute.array[ offset + 2 ] = value.b;
18259
+
18260
+ offset += 3;
18261
+
18262
+ }
18263
+
18264
+ } else {
18265
+
18266
+ for ( ca = 0; ca < cal; ca ++ ) {
18267
+
18268
+ value = customAttribute.value[ ca ];
18269
+
18270
+ customAttribute.array[ offset ] = value.x;
18271
+ customAttribute.array[ offset + 1 ] = value.y;
18272
+ customAttribute.array[ offset + 2 ] = value.z;
18273
+
18274
+ offset += 3;
18275
+
18276
+ }
18277
+
18278
+ }
18279
+
18280
+ } else if ( customAttribute.size === 4 ) {
18281
+
18282
+ for ( ca = 0; ca < cal; ca ++ ) {
18283
+
18284
+ value = customAttribute.value[ ca ];
18285
+
18286
+ customAttribute.array[ offset ] = value.x;
18287
+ customAttribute.array[ offset + 1 ] = value.y;
18288
+ customAttribute.array[ offset + 2 ] = value.z;
18289
+ customAttribute.array[ offset + 3 ] = value.w;
18290
+
18291
+ offset += 4;
18292
+
18293
+ }
18294
+
18295
+ }
18296
+
18297
+ }
18298
+
18299
+ }
18300
+
18301
+ }
18302
+
18303
+ }
18304
+
18305
+ if ( dirtyVertices || object.sortParticles ) {
18306
+
18307
+ _gl.bindBuffer( _gl.ARRAY_BUFFER, geometry.__webglVertexBuffer );
18308
+ _gl.bufferData( _gl.ARRAY_BUFFER, vertexArray, hint );
18309
+
18310
+ }
18311
+
18312
+ if ( dirtyColors || object.sortParticles ) {
18313
+
18314
+ _gl.bindBuffer( _gl.ARRAY_BUFFER, geometry.__webglColorBuffer );
18315
+ _gl.bufferData( _gl.ARRAY_BUFFER, colorArray, hint );
18316
+
18317
+ }
18318
+
18319
+ if ( customAttributes ) {
18320
+
18321
+ for ( i = 0, il = customAttributes.length; i < il; i ++ ) {
18322
+
18323
+ customAttribute = customAttributes[ i ];
18324
+
18325
+ if ( customAttribute.needsUpdate || object.sortParticles ) {
18326
+
18327
+ _gl.bindBuffer( _gl.ARRAY_BUFFER, customAttribute.buffer );
18328
+ _gl.bufferData( _gl.ARRAY_BUFFER, customAttribute.array, hint );
18329
+
18330
+ }
18331
+
18332
+ }
18333
+
18334
+ }
18335
+
18336
+ }
18337
+
18338
+ function setLineBuffers ( geometry, hint ) {
18339
+
18340
+ var v, c, d, vertex, offset, color,
18341
+
18342
+ vertices = geometry.vertices,
18343
+ colors = geometry.colors,
18344
+ lineDistances = geometry.lineDistances,
18345
+
18346
+ vl = vertices.length,
18347
+ cl = colors.length,
18348
+ dl = lineDistances.length,
18349
+
18350
+ vertexArray = geometry.__vertexArray,
18351
+ colorArray = geometry.__colorArray,
18352
+ lineDistanceArray = geometry.__lineDistanceArray,
18353
+
18354
+ dirtyVertices = geometry.verticesNeedUpdate,
18355
+ dirtyColors = geometry.colorsNeedUpdate,
18356
+ dirtyLineDistances = geometry.lineDistancesNeedUpdate,
18357
+
18358
+ customAttributes = geometry.__webglCustomAttributesList,
18359
+
18360
+ i, il,
18361
+ a, ca, cal, value,
18362
+ customAttribute;
18363
+
18364
+ if ( dirtyVertices ) {
18365
+
18366
+ for ( v = 0; v < vl; v ++ ) {
18367
+
18368
+ vertex = vertices[ v ];
18369
+
18370
+ offset = v * 3;
18371
+
18372
+ vertexArray[ offset ] = vertex.x;
18373
+ vertexArray[ offset + 1 ] = vertex.y;
18374
+ vertexArray[ offset + 2 ] = vertex.z;
18375
+
18376
+ }
18377
+
18378
+ _gl.bindBuffer( _gl.ARRAY_BUFFER, geometry.__webglVertexBuffer );
18379
+ _gl.bufferData( _gl.ARRAY_BUFFER, vertexArray, hint );
18380
+
18381
+ }
18382
+
18383
+ if ( dirtyColors ) {
18384
+
18385
+ for ( c = 0; c < cl; c ++ ) {
18386
+
18387
+ color = colors[ c ];
18388
+
18389
+ offset = c * 3;
18390
+
18391
+ colorArray[ offset ] = color.r;
18392
+ colorArray[ offset + 1 ] = color.g;
18393
+ colorArray[ offset + 2 ] = color.b;
18394
+
18395
+ }
18396
+
18397
+ _gl.bindBuffer( _gl.ARRAY_BUFFER, geometry.__webglColorBuffer );
18398
+ _gl.bufferData( _gl.ARRAY_BUFFER, colorArray, hint );
18399
+
18400
+ }
18401
+
18402
+ if ( dirtyLineDistances ) {
18403
+
18404
+ for ( d = 0; d < dl; d ++ ) {
18405
+
18406
+ lineDistanceArray[ d ] = lineDistances[ d ];
18407
+
18408
+ }
18409
+
18410
+ _gl.bindBuffer( _gl.ARRAY_BUFFER, geometry.__webglLineDistanceBuffer );
18411
+ _gl.bufferData( _gl.ARRAY_BUFFER, lineDistanceArray, hint );
18412
+
18413
+ }
18414
+
18415
+ if ( customAttributes ) {
18416
+
18417
+ for ( i = 0, il = customAttributes.length; i < il; i ++ ) {
18418
+
18419
+ customAttribute = customAttributes[ i ];
18420
+
18421
+ if ( customAttribute.needsUpdate &&
18422
+ ( customAttribute.boundTo === undefined ||
18423
+ customAttribute.boundTo === 'vertices' ) ) {
18424
+
18425
+ offset = 0;
18426
+
18427
+ cal = customAttribute.value.length;
18428
+
18429
+ if ( customAttribute.size === 1 ) {
18430
+
18431
+ for ( ca = 0; ca < cal; ca ++ ) {
18432
+
18433
+ customAttribute.array[ ca ] = customAttribute.value[ ca ];
18434
+
18435
+ }
18436
+
18437
+ } else if ( customAttribute.size === 2 ) {
18438
+
18439
+ for ( ca = 0; ca < cal; ca ++ ) {
18440
+
18441
+ value = customAttribute.value[ ca ];
18442
+
18443
+ customAttribute.array[ offset ] = value.x;
18444
+ customAttribute.array[ offset + 1 ] = value.y;
18445
+
18446
+ offset += 2;
18447
+
18448
+ }
18449
+
18450
+ } else if ( customAttribute.size === 3 ) {
18451
+
18452
+ if ( customAttribute.type === 'c' ) {
18453
+
18454
+ for ( ca = 0; ca < cal; ca ++ ) {
18455
+
18456
+ value = customAttribute.value[ ca ];
18457
+
18458
+ customAttribute.array[ offset ] = value.r;
18459
+ customAttribute.array[ offset + 1 ] = value.g;
18460
+ customAttribute.array[ offset + 2 ] = value.b;
18461
+
18462
+ offset += 3;
18463
+
18464
+ }
18465
+
18466
+ } else {
18467
+
18468
+ for ( ca = 0; ca < cal; ca ++ ) {
18469
+
18470
+ value = customAttribute.value[ ca ];
18471
+
18472
+ customAttribute.array[ offset ] = value.x;
18473
+ customAttribute.array[ offset + 1 ] = value.y;
18474
+ customAttribute.array[ offset + 2 ] = value.z;
18475
+
18476
+ offset += 3;
18477
+
18478
+ }
18479
+
18480
+ }
18481
+
18482
+ } else if ( customAttribute.size === 4 ) {
18483
+
18484
+ for ( ca = 0; ca < cal; ca ++ ) {
18485
+
18486
+ value = customAttribute.value[ ca ];
18487
+
18488
+ customAttribute.array[ offset ] = value.x;
18489
+ customAttribute.array[ offset + 1 ] = value.y;
18490
+ customAttribute.array[ offset + 2 ] = value.z;
18491
+ customAttribute.array[ offset + 3 ] = value.w;
18492
+
18493
+ offset += 4;
18494
+
18495
+ }
18496
+
18497
+ }
18498
+
18499
+ _gl.bindBuffer( _gl.ARRAY_BUFFER, customAttribute.buffer );
18500
+ _gl.bufferData( _gl.ARRAY_BUFFER, customAttribute.array, hint );
18501
+
18502
+ }
18503
+
18504
+ }
18505
+
18506
+ }
18507
+
18508
+ }
18509
+
18510
+ function setMeshBuffers( geometryGroup, object, hint, dispose, material ) {
18511
+
18512
+ if ( ! geometryGroup.__inittedArrays ) {
18513
+
18514
+ return;
18515
+
18516
+ }
18517
+
18518
+ var needsSmoothNormals = materialNeedsSmoothNormals( material );
18519
+
18520
+ var f, fl, fi, face,
18521
+ vertexNormals, faceNormal, normal,
18522
+ vertexColors, faceColor,
18523
+ vertexTangents,
18524
+ uv, uv2, v1, v2, v3, v4, t1, t2, t3, t4, n1, n2, n3, n4,
18525
+ c1, c2, c3,
18526
+ sw1, sw2, sw3, sw4,
18527
+ si1, si2, si3, si4,
18528
+ sa1, sa2, sa3, sa4,
18529
+ sb1, sb2, sb3, sb4,
18530
+ m, ml, i, il,
18531
+ vn, uvi, uv2i,
18532
+ vk, vkl, vka,
18533
+ nka, chf, faceVertexNormals,
18534
+ a,
18535
+
18536
+ vertexIndex = 0,
18537
+
18538
+ offset = 0,
18539
+ offset_uv = 0,
18540
+ offset_uv2 = 0,
18541
+ offset_face = 0,
18542
+ offset_normal = 0,
18543
+ offset_tangent = 0,
18544
+ offset_line = 0,
18545
+ offset_color = 0,
18546
+ offset_skin = 0,
18547
+ offset_morphTarget = 0,
18548
+ offset_custom = 0,
18549
+ offset_customSrc = 0,
18550
+
18551
+ value,
18552
+
18553
+ vertexArray = geometryGroup.__vertexArray,
18554
+ uvArray = geometryGroup.__uvArray,
18555
+ uv2Array = geometryGroup.__uv2Array,
18556
+ normalArray = geometryGroup.__normalArray,
18557
+ tangentArray = geometryGroup.__tangentArray,
18558
+ colorArray = geometryGroup.__colorArray,
18559
+
18560
+ skinIndexArray = geometryGroup.__skinIndexArray,
18561
+ skinWeightArray = geometryGroup.__skinWeightArray,
18562
+
18563
+ morphTargetsArrays = geometryGroup.__morphTargetsArrays,
18564
+ morphNormalsArrays = geometryGroup.__morphNormalsArrays,
18565
+
18566
+ customAttributes = geometryGroup.__webglCustomAttributesList,
18567
+ customAttribute,
18568
+
18569
+ faceArray = geometryGroup.__faceArray,
18570
+ lineArray = geometryGroup.__lineArray,
18571
+
18572
+ geometry = object.geometry, // this is shared for all chunks
18573
+
18574
+ dirtyVertices = geometry.verticesNeedUpdate,
18575
+ dirtyElements = geometry.elementsNeedUpdate,
18576
+ dirtyUvs = geometry.uvsNeedUpdate,
18577
+ dirtyNormals = geometry.normalsNeedUpdate,
18578
+ dirtyTangents = geometry.tangentsNeedUpdate,
18579
+ dirtyColors = geometry.colorsNeedUpdate,
18580
+ dirtyMorphTargets = geometry.morphTargetsNeedUpdate,
18581
+
18582
+ vertices = geometry.vertices,
18583
+ chunk_faces3 = geometryGroup.faces3,
18584
+ obj_faces = geometry.faces,
18585
+
18586
+ obj_uvs = geometry.faceVertexUvs[ 0 ],
18587
+ obj_uvs2 = geometry.faceVertexUvs[ 1 ],
18588
+
18589
+ obj_colors = geometry.colors,
18590
+
18591
+ obj_skinIndices = geometry.skinIndices,
18592
+ obj_skinWeights = geometry.skinWeights,
18593
+
18594
+ morphTargets = geometry.morphTargets,
18595
+ morphNormals = geometry.morphNormals;
18596
+
18597
+ if ( dirtyVertices ) {
18598
+
18599
+ for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
18600
+
18601
+ face = obj_faces[ chunk_faces3[ f ] ];
18602
+
18603
+ v1 = vertices[ face.a ];
18604
+ v2 = vertices[ face.b ];
18605
+ v3 = vertices[ face.c ];
18606
+
18607
+ vertexArray[ offset ] = v1.x;
18608
+ vertexArray[ offset + 1 ] = v1.y;
18609
+ vertexArray[ offset + 2 ] = v1.z;
18610
+
18611
+ vertexArray[ offset + 3 ] = v2.x;
18612
+ vertexArray[ offset + 4 ] = v2.y;
18613
+ vertexArray[ offset + 5 ] = v2.z;
18614
+
18615
+ vertexArray[ offset + 6 ] = v3.x;
18616
+ vertexArray[ offset + 7 ] = v3.y;
18617
+ vertexArray[ offset + 8 ] = v3.z;
18618
+
18619
+ offset += 9;
18620
+
18621
+ }
18622
+
18623
+ _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglVertexBuffer );
18624
+ _gl.bufferData( _gl.ARRAY_BUFFER, vertexArray, hint );
18625
+
18626
+ }
18627
+
18628
+ if ( dirtyMorphTargets ) {
18629
+
18630
+ for ( vk = 0, vkl = morphTargets.length; vk < vkl; vk ++ ) {
18631
+
18632
+ offset_morphTarget = 0;
18633
+
18634
+ for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
18635
+
18636
+ chf = chunk_faces3[ f ];
18637
+ face = obj_faces[ chf ];
18638
+
18639
+ // morph positions
18640
+
18641
+ v1 = morphTargets[ vk ].vertices[ face.a ];
18642
+ v2 = morphTargets[ vk ].vertices[ face.b ];
18643
+ v3 = morphTargets[ vk ].vertices[ face.c ];
18644
+
18645
+ vka = morphTargetsArrays[ vk ];
18646
+
18647
+ vka[ offset_morphTarget ] = v1.x;
18648
+ vka[ offset_morphTarget + 1 ] = v1.y;
18649
+ vka[ offset_morphTarget + 2 ] = v1.z;
18650
+
18651
+ vka[ offset_morphTarget + 3 ] = v2.x;
18652
+ vka[ offset_morphTarget + 4 ] = v2.y;
18653
+ vka[ offset_morphTarget + 5 ] = v2.z;
18654
+
18655
+ vka[ offset_morphTarget + 6 ] = v3.x;
18656
+ vka[ offset_morphTarget + 7 ] = v3.y;
18657
+ vka[ offset_morphTarget + 8 ] = v3.z;
18658
+
18659
+ // morph normals
18660
+
18661
+ if ( material.morphNormals ) {
18662
+
18663
+ if ( needsSmoothNormals ) {
18664
+
18665
+ faceVertexNormals = morphNormals[ vk ].vertexNormals[ chf ];
18666
+
18667
+ n1 = faceVertexNormals.a;
18668
+ n2 = faceVertexNormals.b;
18669
+ n3 = faceVertexNormals.c;
18670
+
18671
+ } else {
18672
+
18673
+ n1 = morphNormals[ vk ].faceNormals[ chf ];
18674
+ n2 = n1;
18675
+ n3 = n1;
18676
+
18677
+ }
18678
+
18679
+ nka = morphNormalsArrays[ vk ];
18680
+
18681
+ nka[ offset_morphTarget ] = n1.x;
18682
+ nka[ offset_morphTarget + 1 ] = n1.y;
18683
+ nka[ offset_morphTarget + 2 ] = n1.z;
18684
+
18685
+ nka[ offset_morphTarget + 3 ] = n2.x;
18686
+ nka[ offset_morphTarget + 4 ] = n2.y;
18687
+ nka[ offset_morphTarget + 5 ] = n2.z;
18688
+
18689
+ nka[ offset_morphTarget + 6 ] = n3.x;
18690
+ nka[ offset_morphTarget + 7 ] = n3.y;
18691
+ nka[ offset_morphTarget + 8 ] = n3.z;
18692
+
18693
+ }
18694
+
18695
+ //
18696
+
18697
+ offset_morphTarget += 9;
18698
+
18699
+ }
18700
+
18701
+ _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglMorphTargetsBuffers[ vk ] );
18702
+ _gl.bufferData( _gl.ARRAY_BUFFER, morphTargetsArrays[ vk ], hint );
18703
+
18704
+ if ( material.morphNormals ) {
18705
+
18706
+ _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglMorphNormalsBuffers[ vk ] );
18707
+ _gl.bufferData( _gl.ARRAY_BUFFER, morphNormalsArrays[ vk ], hint );
18708
+
18709
+ }
18710
+
18711
+ }
18712
+
18713
+ }
18714
+
18715
+ if ( obj_skinWeights.length ) {
18716
+
18717
+ for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
18718
+
18719
+ face = obj_faces[ chunk_faces3[ f ] ];
18720
+
18721
+ // weights
18722
+
18723
+ sw1 = obj_skinWeights[ face.a ];
18724
+ sw2 = obj_skinWeights[ face.b ];
18725
+ sw3 = obj_skinWeights[ face.c ];
18726
+
18727
+ skinWeightArray[ offset_skin ] = sw1.x;
18728
+ skinWeightArray[ offset_skin + 1 ] = sw1.y;
18729
+ skinWeightArray[ offset_skin + 2 ] = sw1.z;
18730
+ skinWeightArray[ offset_skin + 3 ] = sw1.w;
18731
+
18732
+ skinWeightArray[ offset_skin + 4 ] = sw2.x;
18733
+ skinWeightArray[ offset_skin + 5 ] = sw2.y;
18734
+ skinWeightArray[ offset_skin + 6 ] = sw2.z;
18735
+ skinWeightArray[ offset_skin + 7 ] = sw2.w;
18736
+
18737
+ skinWeightArray[ offset_skin + 8 ] = sw3.x;
18738
+ skinWeightArray[ offset_skin + 9 ] = sw3.y;
18739
+ skinWeightArray[ offset_skin + 10 ] = sw3.z;
18740
+ skinWeightArray[ offset_skin + 11 ] = sw3.w;
18741
+
18742
+ // indices
18743
+
18744
+ si1 = obj_skinIndices[ face.a ];
18745
+ si2 = obj_skinIndices[ face.b ];
18746
+ si3 = obj_skinIndices[ face.c ];
18747
+
18748
+ skinIndexArray[ offset_skin ] = si1.x;
18749
+ skinIndexArray[ offset_skin + 1 ] = si1.y;
18750
+ skinIndexArray[ offset_skin + 2 ] = si1.z;
18751
+ skinIndexArray[ offset_skin + 3 ] = si1.w;
18752
+
18753
+ skinIndexArray[ offset_skin + 4 ] = si2.x;
18754
+ skinIndexArray[ offset_skin + 5 ] = si2.y;
18755
+ skinIndexArray[ offset_skin + 6 ] = si2.z;
18756
+ skinIndexArray[ offset_skin + 7 ] = si2.w;
18757
+
18758
+ skinIndexArray[ offset_skin + 8 ] = si3.x;
18759
+ skinIndexArray[ offset_skin + 9 ] = si3.y;
18760
+ skinIndexArray[ offset_skin + 10 ] = si3.z;
18761
+ skinIndexArray[ offset_skin + 11 ] = si3.w;
18762
+
18763
+ offset_skin += 12;
18764
+
18765
+ }
18766
+
18767
+ if ( offset_skin > 0 ) {
18768
+
18769
+ _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglSkinIndicesBuffer );
18770
+ _gl.bufferData( _gl.ARRAY_BUFFER, skinIndexArray, hint );
18771
+
18772
+ _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglSkinWeightsBuffer );
18773
+ _gl.bufferData( _gl.ARRAY_BUFFER, skinWeightArray, hint );
18774
+
18775
+ }
18776
+
18777
+ }
18778
+
18779
+ if ( dirtyColors ) {
18780
+
18781
+ for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
18782
+
18783
+ face = obj_faces[ chunk_faces3[ f ] ];
18784
+
18785
+ vertexColors = face.vertexColors;
18786
+ faceColor = face.color;
18787
+
18788
+ if ( vertexColors.length === 3 && material.vertexColors === THREE.VertexColors ) {
18789
+
18790
+ c1 = vertexColors[ 0 ];
18791
+ c2 = vertexColors[ 1 ];
18792
+ c3 = vertexColors[ 2 ];
18793
+
18794
+ } else {
18795
+
18796
+ c1 = faceColor;
18797
+ c2 = faceColor;
18798
+ c3 = faceColor;
18799
+
18800
+ }
18801
+
18802
+ colorArray[ offset_color ] = c1.r;
18803
+ colorArray[ offset_color + 1 ] = c1.g;
18804
+ colorArray[ offset_color + 2 ] = c1.b;
18805
+
18806
+ colorArray[ offset_color + 3 ] = c2.r;
18807
+ colorArray[ offset_color + 4 ] = c2.g;
18808
+ colorArray[ offset_color + 5 ] = c2.b;
18809
+
18810
+ colorArray[ offset_color + 6 ] = c3.r;
18811
+ colorArray[ offset_color + 7 ] = c3.g;
18812
+ colorArray[ offset_color + 8 ] = c3.b;
18813
+
18814
+ offset_color += 9;
18815
+
18816
+ }
18817
+
18818
+ if ( offset_color > 0 ) {
18819
+
18820
+ _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglColorBuffer );
18821
+ _gl.bufferData( _gl.ARRAY_BUFFER, colorArray, hint );
18822
+
18823
+ }
18824
+
18825
+ }
18826
+
18827
+ if ( dirtyTangents && geometry.hasTangents ) {
18828
+
18829
+ for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
18830
+
18831
+ face = obj_faces[ chunk_faces3[ f ] ];
18832
+
18833
+ vertexTangents = face.vertexTangents;
18834
+
18835
+ t1 = vertexTangents[ 0 ];
18836
+ t2 = vertexTangents[ 1 ];
18837
+ t3 = vertexTangents[ 2 ];
18838
+
18839
+ tangentArray[ offset_tangent ] = t1.x;
18840
+ tangentArray[ offset_tangent + 1 ] = t1.y;
18841
+ tangentArray[ offset_tangent + 2 ] = t1.z;
18842
+ tangentArray[ offset_tangent + 3 ] = t1.w;
18843
+
18844
+ tangentArray[ offset_tangent + 4 ] = t2.x;
18845
+ tangentArray[ offset_tangent + 5 ] = t2.y;
18846
+ tangentArray[ offset_tangent + 6 ] = t2.z;
18847
+ tangentArray[ offset_tangent + 7 ] = t2.w;
18848
+
18849
+ tangentArray[ offset_tangent + 8 ] = t3.x;
18850
+ tangentArray[ offset_tangent + 9 ] = t3.y;
18851
+ tangentArray[ offset_tangent + 10 ] = t3.z;
18852
+ tangentArray[ offset_tangent + 11 ] = t3.w;
18853
+
18854
+ offset_tangent += 12;
18855
+
18856
+ }
18857
+
18858
+ _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglTangentBuffer );
18859
+ _gl.bufferData( _gl.ARRAY_BUFFER, tangentArray, hint );
18860
+
18861
+ }
18862
+
18863
+ if ( dirtyNormals ) {
18864
+
18865
+ for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
18866
+
18867
+ face = obj_faces[ chunk_faces3[ f ] ];
18868
+
18869
+ vertexNormals = face.vertexNormals;
18870
+ faceNormal = face.normal;
18871
+
18872
+ if ( vertexNormals.length === 3 && needsSmoothNormals ) {
18873
+
18874
+ for ( i = 0; i < 3; i ++ ) {
18875
+
18876
+ vn = vertexNormals[ i ];
18877
+
18878
+ normalArray[ offset_normal ] = vn.x;
18879
+ normalArray[ offset_normal + 1 ] = vn.y;
18880
+ normalArray[ offset_normal + 2 ] = vn.z;
18881
+
18882
+ offset_normal += 3;
18883
+
18884
+ }
18885
+
18886
+ } else {
18887
+
18888
+ for ( i = 0; i < 3; i ++ ) {
18889
+
18890
+ normalArray[ offset_normal ] = faceNormal.x;
18891
+ normalArray[ offset_normal + 1 ] = faceNormal.y;
18892
+ normalArray[ offset_normal + 2 ] = faceNormal.z;
18893
+
18894
+ offset_normal += 3;
18895
+
18896
+ }
18897
+
18898
+ }
18899
+
18900
+ }
18901
+
18902
+ _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglNormalBuffer );
18903
+ _gl.bufferData( _gl.ARRAY_BUFFER, normalArray, hint );
18904
+
18905
+ }
18906
+
18907
+ if ( dirtyUvs && obj_uvs ) {
18908
+
18909
+ for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
18910
+
18911
+ fi = chunk_faces3[ f ];
18912
+
18913
+ uv = obj_uvs[ fi ];
18914
+
18915
+ if ( uv === undefined ) continue;
18916
+
18917
+ for ( i = 0; i < 3; i ++ ) {
18918
+
18919
+ uvi = uv[ i ];
18920
+
18921
+ uvArray[ offset_uv ] = uvi.x;
18922
+ uvArray[ offset_uv + 1 ] = uvi.y;
18923
+
18924
+ offset_uv += 2;
18925
+
18926
+ }
18927
+
18928
+ }
18929
+
18930
+ if ( offset_uv > 0 ) {
18931
+
18932
+ _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglUVBuffer );
18933
+ _gl.bufferData( _gl.ARRAY_BUFFER, uvArray, hint );
18934
+
18935
+ }
18936
+
18937
+ }
18938
+
18939
+ if ( dirtyUvs && obj_uvs2 ) {
18940
+
18941
+ for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
18942
+
18943
+ fi = chunk_faces3[ f ];
18944
+
18945
+ uv2 = obj_uvs2[ fi ];
18946
+
18947
+ if ( uv2 === undefined ) continue;
18948
+
18949
+ for ( i = 0; i < 3; i ++ ) {
18950
+
18951
+ uv2i = uv2[ i ];
18952
+
18953
+ uv2Array[ offset_uv2 ] = uv2i.x;
18954
+ uv2Array[ offset_uv2 + 1 ] = uv2i.y;
18955
+
18956
+ offset_uv2 += 2;
18957
+
18958
+ }
18959
+
18960
+ }
18961
+
18962
+ if ( offset_uv2 > 0 ) {
18963
+
18964
+ _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglUV2Buffer );
18965
+ _gl.bufferData( _gl.ARRAY_BUFFER, uv2Array, hint );
18966
+
18967
+ }
18968
+
18969
+ }
18970
+
18971
+ if ( dirtyElements ) {
18972
+
18973
+ for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
18974
+
18975
+ faceArray[ offset_face ] = vertexIndex;
18976
+ faceArray[ offset_face + 1 ] = vertexIndex + 1;
18977
+ faceArray[ offset_face + 2 ] = vertexIndex + 2;
18978
+
18979
+ offset_face += 3;
18980
+
18981
+ lineArray[ offset_line ] = vertexIndex;
18982
+ lineArray[ offset_line + 1 ] = vertexIndex + 1;
18983
+
18984
+ lineArray[ offset_line + 2 ] = vertexIndex;
18985
+ lineArray[ offset_line + 3 ] = vertexIndex + 2;
18986
+
18987
+ lineArray[ offset_line + 4 ] = vertexIndex + 1;
18988
+ lineArray[ offset_line + 5 ] = vertexIndex + 2;
18989
+
18990
+ offset_line += 6;
18991
+
18992
+ vertexIndex += 3;
18993
+
18994
+ }
18995
+
18996
+ _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, geometryGroup.__webglFaceBuffer );
18997
+ _gl.bufferData( _gl.ELEMENT_ARRAY_BUFFER, faceArray, hint );
18998
+
18999
+ _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, geometryGroup.__webglLineBuffer );
19000
+ _gl.bufferData( _gl.ELEMENT_ARRAY_BUFFER, lineArray, hint );
19001
+
19002
+ }
19003
+
19004
+ if ( customAttributes ) {
19005
+
19006
+ for ( i = 0, il = customAttributes.length; i < il; i ++ ) {
19007
+
19008
+ customAttribute = customAttributes[ i ];
19009
+
19010
+ if ( ! customAttribute.__original.needsUpdate ) continue;
19011
+
19012
+ offset_custom = 0;
19013
+ offset_customSrc = 0;
19014
+
19015
+ if ( customAttribute.size === 1 ) {
19016
+
19017
+ if ( customAttribute.boundTo === undefined || customAttribute.boundTo === 'vertices' ) {
19018
+
19019
+ for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
19020
+
19021
+ face = obj_faces[ chunk_faces3[ f ] ];
19022
+
19023
+ customAttribute.array[ offset_custom ] = customAttribute.value[ face.a ];
19024
+ customAttribute.array[ offset_custom + 1 ] = customAttribute.value[ face.b ];
19025
+ customAttribute.array[ offset_custom + 2 ] = customAttribute.value[ face.c ];
19026
+
19027
+ offset_custom += 3;
19028
+
19029
+ }
19030
+
19031
+ } else if ( customAttribute.boundTo === 'faces' ) {
19032
+
19033
+ for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
19034
+
19035
+ value = customAttribute.value[ chunk_faces3[ f ] ];
19036
+
19037
+ customAttribute.array[ offset_custom ] = value;
19038
+ customAttribute.array[ offset_custom + 1 ] = value;
19039
+ customAttribute.array[ offset_custom + 2 ] = value;
19040
+
19041
+ offset_custom += 3;
19042
+
19043
+ }
19044
+
19045
+ }
19046
+
19047
+ } else if ( customAttribute.size === 2 ) {
19048
+
19049
+ if ( customAttribute.boundTo === undefined || customAttribute.boundTo === 'vertices' ) {
19050
+
19051
+ for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
19052
+
19053
+ face = obj_faces[ chunk_faces3[ f ] ];
19054
+
19055
+ v1 = customAttribute.value[ face.a ];
19056
+ v2 = customAttribute.value[ face.b ];
19057
+ v3 = customAttribute.value[ face.c ];
19058
+
19059
+ customAttribute.array[ offset_custom ] = v1.x;
19060
+ customAttribute.array[ offset_custom + 1 ] = v1.y;
19061
+
19062
+ customAttribute.array[ offset_custom + 2 ] = v2.x;
19063
+ customAttribute.array[ offset_custom + 3 ] = v2.y;
19064
+
19065
+ customAttribute.array[ offset_custom + 4 ] = v3.x;
19066
+ customAttribute.array[ offset_custom + 5 ] = v3.y;
19067
+
19068
+ offset_custom += 6;
19069
+
19070
+ }
19071
+
19072
+ } else if ( customAttribute.boundTo === 'faces' ) {
19073
+
19074
+ for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
19075
+
19076
+ value = customAttribute.value[ chunk_faces3[ f ] ];
19077
+
19078
+ v1 = value;
19079
+ v2 = value;
19080
+ v3 = value;
19081
+
19082
+ customAttribute.array[ offset_custom ] = v1.x;
19083
+ customAttribute.array[ offset_custom + 1 ] = v1.y;
19084
+
19085
+ customAttribute.array[ offset_custom + 2 ] = v2.x;
19086
+ customAttribute.array[ offset_custom + 3 ] = v2.y;
19087
+
19088
+ customAttribute.array[ offset_custom + 4 ] = v3.x;
19089
+ customAttribute.array[ offset_custom + 5 ] = v3.y;
19090
+
19091
+ offset_custom += 6;
19092
+
19093
+ }
19094
+
19095
+ }
19096
+
19097
+ } else if ( customAttribute.size === 3 ) {
19098
+
19099
+ var pp;
19100
+
19101
+ if ( customAttribute.type === 'c' ) {
19102
+
19103
+ pp = [ 'r', 'g', 'b' ];
19104
+
19105
+ } else {
19106
+
19107
+ pp = [ 'x', 'y', 'z' ];
19108
+
19109
+ }
19110
+
19111
+ if ( customAttribute.boundTo === undefined || customAttribute.boundTo === 'vertices' ) {
19112
+
19113
+ for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
19114
+
19115
+ face = obj_faces[ chunk_faces3[ f ] ];
19116
+
19117
+ v1 = customAttribute.value[ face.a ];
19118
+ v2 = customAttribute.value[ face.b ];
19119
+ v3 = customAttribute.value[ face.c ];
19120
+
19121
+ customAttribute.array[ offset_custom ] = v1[ pp[ 0 ] ];
19122
+ customAttribute.array[ offset_custom + 1 ] = v1[ pp[ 1 ] ];
19123
+ customAttribute.array[ offset_custom + 2 ] = v1[ pp[ 2 ] ];
19124
+
19125
+ customAttribute.array[ offset_custom + 3 ] = v2[ pp[ 0 ] ];
19126
+ customAttribute.array[ offset_custom + 4 ] = v2[ pp[ 1 ] ];
19127
+ customAttribute.array[ offset_custom + 5 ] = v2[ pp[ 2 ] ];
19128
+
19129
+ customAttribute.array[ offset_custom + 6 ] = v3[ pp[ 0 ] ];
19130
+ customAttribute.array[ offset_custom + 7 ] = v3[ pp[ 1 ] ];
19131
+ customAttribute.array[ offset_custom + 8 ] = v3[ pp[ 2 ] ];
19132
+
19133
+ offset_custom += 9;
19134
+
19135
+ }
19136
+
19137
+ } else if ( customAttribute.boundTo === 'faces' ) {
19138
+
19139
+ for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
19140
+
19141
+ value = customAttribute.value[ chunk_faces3[ f ] ];
19142
+
19143
+ v1 = value;
19144
+ v2 = value;
19145
+ v3 = value;
19146
+
19147
+ customAttribute.array[ offset_custom ] = v1[ pp[ 0 ] ];
19148
+ customAttribute.array[ offset_custom + 1 ] = v1[ pp[ 1 ] ];
19149
+ customAttribute.array[ offset_custom + 2 ] = v1[ pp[ 2 ] ];
19150
+
19151
+ customAttribute.array[ offset_custom + 3 ] = v2[ pp[ 0 ] ];
19152
+ customAttribute.array[ offset_custom + 4 ] = v2[ pp[ 1 ] ];
19153
+ customAttribute.array[ offset_custom + 5 ] = v2[ pp[ 2 ] ];
19154
+
19155
+ customAttribute.array[ offset_custom + 6 ] = v3[ pp[ 0 ] ];
19156
+ customAttribute.array[ offset_custom + 7 ] = v3[ pp[ 1 ] ];
19157
+ customAttribute.array[ offset_custom + 8 ] = v3[ pp[ 2 ] ];
19158
+
19159
+ offset_custom += 9;
19160
+
19161
+ }
19162
+
19163
+ } else if ( customAttribute.boundTo === 'faceVertices' ) {
19164
+
19165
+ for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
19166
+
19167
+ value = customAttribute.value[ chunk_faces3[ f ] ];
19168
+
19169
+ v1 = value[ 0 ];
19170
+ v2 = value[ 1 ];
19171
+ v3 = value[ 2 ];
19172
+
19173
+ customAttribute.array[ offset_custom ] = v1[ pp[ 0 ] ];
19174
+ customAttribute.array[ offset_custom + 1 ] = v1[ pp[ 1 ] ];
19175
+ customAttribute.array[ offset_custom + 2 ] = v1[ pp[ 2 ] ];
19176
+
19177
+ customAttribute.array[ offset_custom + 3 ] = v2[ pp[ 0 ] ];
19178
+ customAttribute.array[ offset_custom + 4 ] = v2[ pp[ 1 ] ];
19179
+ customAttribute.array[ offset_custom + 5 ] = v2[ pp[ 2 ] ];
19180
+
19181
+ customAttribute.array[ offset_custom + 6 ] = v3[ pp[ 0 ] ];
19182
+ customAttribute.array[ offset_custom + 7 ] = v3[ pp[ 1 ] ];
19183
+ customAttribute.array[ offset_custom + 8 ] = v3[ pp[ 2 ] ];
19184
+
19185
+ offset_custom += 9;
19186
+
19187
+ }
19188
+
19189
+ }
19190
+
19191
+ } else if ( customAttribute.size === 4 ) {
19192
+
19193
+ if ( customAttribute.boundTo === undefined || customAttribute.boundTo === 'vertices' ) {
19194
+
19195
+ for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
19196
+
19197
+ face = obj_faces[ chunk_faces3[ f ] ];
19198
+
19199
+ v1 = customAttribute.value[ face.a ];
19200
+ v2 = customAttribute.value[ face.b ];
19201
+ v3 = customAttribute.value[ face.c ];
19202
+
19203
+ customAttribute.array[ offset_custom ] = v1.x;
19204
+ customAttribute.array[ offset_custom + 1 ] = v1.y;
19205
+ customAttribute.array[ offset_custom + 2 ] = v1.z;
19206
+ customAttribute.array[ offset_custom + 3 ] = v1.w;
19207
+
19208
+ customAttribute.array[ offset_custom + 4 ] = v2.x;
19209
+ customAttribute.array[ offset_custom + 5 ] = v2.y;
19210
+ customAttribute.array[ offset_custom + 6 ] = v2.z;
19211
+ customAttribute.array[ offset_custom + 7 ] = v2.w;
19212
+
19213
+ customAttribute.array[ offset_custom + 8 ] = v3.x;
19214
+ customAttribute.array[ offset_custom + 9 ] = v3.y;
19215
+ customAttribute.array[ offset_custom + 10 ] = v3.z;
19216
+ customAttribute.array[ offset_custom + 11 ] = v3.w;
19217
+
19218
+ offset_custom += 12;
19219
+
19220
+ }
19221
+
19222
+ } else if ( customAttribute.boundTo === 'faces' ) {
19223
+
19224
+ for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
19225
+
19226
+ value = customAttribute.value[ chunk_faces3[ f ] ];
19227
+
19228
+ v1 = value;
19229
+ v2 = value;
19230
+ v3 = value;
19231
+
19232
+ customAttribute.array[ offset_custom ] = v1.x;
19233
+ customAttribute.array[ offset_custom + 1 ] = v1.y;
19234
+ customAttribute.array[ offset_custom + 2 ] = v1.z;
19235
+ customAttribute.array[ offset_custom + 3 ] = v1.w;
19236
+
19237
+ customAttribute.array[ offset_custom + 4 ] = v2.x;
19238
+ customAttribute.array[ offset_custom + 5 ] = v2.y;
19239
+ customAttribute.array[ offset_custom + 6 ] = v2.z;
19240
+ customAttribute.array[ offset_custom + 7 ] = v2.w;
19241
+
19242
+ customAttribute.array[ offset_custom + 8 ] = v3.x;
19243
+ customAttribute.array[ offset_custom + 9 ] = v3.y;
19244
+ customAttribute.array[ offset_custom + 10 ] = v3.z;
19245
+ customAttribute.array[ offset_custom + 11 ] = v3.w;
19246
+
19247
+ offset_custom += 12;
19248
+
19249
+ }
19250
+
19251
+ } else if ( customAttribute.boundTo === 'faceVertices' ) {
19252
+
19253
+ for ( f = 0, fl = chunk_faces3.length; f < fl; f ++ ) {
19254
+
19255
+ value = customAttribute.value[ chunk_faces3[ f ] ];
19256
+
19257
+ v1 = value[ 0 ];
19258
+ v2 = value[ 1 ];
19259
+ v3 = value[ 2 ];
19260
+
19261
+ customAttribute.array[ offset_custom ] = v1.x;
19262
+ customAttribute.array[ offset_custom + 1 ] = v1.y;
19263
+ customAttribute.array[ offset_custom + 2 ] = v1.z;
19264
+ customAttribute.array[ offset_custom + 3 ] = v1.w;
19265
+
19266
+ customAttribute.array[ offset_custom + 4 ] = v2.x;
19267
+ customAttribute.array[ offset_custom + 5 ] = v2.y;
19268
+ customAttribute.array[ offset_custom + 6 ] = v2.z;
19269
+ customAttribute.array[ offset_custom + 7 ] = v2.w;
19270
+
19271
+ customAttribute.array[ offset_custom + 8 ] = v3.x;
19272
+ customAttribute.array[ offset_custom + 9 ] = v3.y;
19273
+ customAttribute.array[ offset_custom + 10 ] = v3.z;
19274
+ customAttribute.array[ offset_custom + 11 ] = v3.w;
19275
+
19276
+ offset_custom += 12;
19277
+
19278
+ }
19279
+
19280
+ }
19281
+
19282
+ }
19283
+
19284
+ _gl.bindBuffer( _gl.ARRAY_BUFFER, customAttribute.buffer );
19285
+ _gl.bufferData( _gl.ARRAY_BUFFER, customAttribute.array, hint );
19286
+
19287
+ }
19288
+
19289
+ }
19290
+
19291
+ if ( dispose ) {
19292
+
19293
+ delete geometryGroup.__inittedArrays;
19294
+ delete geometryGroup.__colorArray;
19295
+ delete geometryGroup.__normalArray;
19296
+ delete geometryGroup.__tangentArray;
19297
+ delete geometryGroup.__uvArray;
19298
+ delete geometryGroup.__uv2Array;
19299
+ delete geometryGroup.__faceArray;
19300
+ delete geometryGroup.__vertexArray;
19301
+ delete geometryGroup.__lineArray;
19302
+ delete geometryGroup.__skinIndexArray;
19303
+ delete geometryGroup.__skinWeightArray;
19304
+
19305
+ }
19306
+
19307
+ };
19308
+
19309
+ function setDirectBuffers( geometry ) {
19310
+
19311
+ var attributes = geometry.attributes;
19312
+ var attributesKeys = geometry.attributesKeys;
19313
+
19314
+ for ( var i = 0, l = attributesKeys.length; i < l; i ++ ) {
19315
+
19316
+ var key = attributesKeys[ i ];
19317
+ var attribute = attributes[ key ];
19318
+
19319
+ if ( attribute.buffer === undefined ) {
19320
+
19321
+ attribute.buffer = _gl.createBuffer();
19322
+ attribute.needsUpdate = true;
19323
+
19324
+ }
19325
+
19326
+ if ( attribute.needsUpdate === true ) {
19327
+
19328
+ var bufferType = ( key === 'index' ) ? _gl.ELEMENT_ARRAY_BUFFER : _gl.ARRAY_BUFFER;
19329
+
19330
+ _gl.bindBuffer( bufferType, attribute.buffer );
19331
+ _gl.bufferData( bufferType, attribute.array, _gl.STATIC_DRAW );
19332
+
19333
+ attribute.needsUpdate = false;
19334
+
19335
+ }
19336
+
19337
+ }
19338
+
19339
+ }
19340
+
19341
+ // Buffer rendering
19342
+
19343
+ this.renderBufferImmediate = function ( object, program, material ) {
19344
+
19345
+ initAttributes();
19346
+
19347
+ if ( object.hasPositions && ! object.__webglVertexBuffer ) object.__webglVertexBuffer = _gl.createBuffer();
19348
+ if ( object.hasNormals && ! object.__webglNormalBuffer ) object.__webglNormalBuffer = _gl.createBuffer();
19349
+ if ( object.hasUvs && ! object.__webglUvBuffer ) object.__webglUvBuffer = _gl.createBuffer();
19350
+ if ( object.hasColors && ! object.__webglColorBuffer ) object.__webglColorBuffer = _gl.createBuffer();
19351
+
19352
+ if ( object.hasPositions ) {
19353
+
19354
+ _gl.bindBuffer( _gl.ARRAY_BUFFER, object.__webglVertexBuffer );
19355
+ _gl.bufferData( _gl.ARRAY_BUFFER, object.positionArray, _gl.DYNAMIC_DRAW );
19356
+ enableAttribute( program.attributes.position );
19357
+ _gl.vertexAttribPointer( program.attributes.position, 3, _gl.FLOAT, false, 0, 0 );
19358
+
19359
+ }
19360
+
19361
+ if ( object.hasNormals ) {
19362
+
19363
+ _gl.bindBuffer( _gl.ARRAY_BUFFER, object.__webglNormalBuffer );
19364
+
19365
+ if ( material.shading === THREE.FlatShading ) {
19366
+
19367
+ var nx, ny, nz,
19368
+ nax, nbx, ncx, nay, nby, ncy, naz, nbz, ncz,
19369
+ normalArray,
19370
+ i, il = object.count * 3;
19371
+
19372
+ for ( i = 0; i < il; i += 9 ) {
19373
+
19374
+ normalArray = object.normalArray;
19375
+
19376
+ nax = normalArray[ i ];
19377
+ nay = normalArray[ i + 1 ];
19378
+ naz = normalArray[ i + 2 ];
19379
+
19380
+ nbx = normalArray[ i + 3 ];
19381
+ nby = normalArray[ i + 4 ];
19382
+ nbz = normalArray[ i + 5 ];
19383
+
19384
+ ncx = normalArray[ i + 6 ];
19385
+ ncy = normalArray[ i + 7 ];
19386
+ ncz = normalArray[ i + 8 ];
19387
+
19388
+ nx = ( nax + nbx + ncx ) / 3;
19389
+ ny = ( nay + nby + ncy ) / 3;
19390
+ nz = ( naz + nbz + ncz ) / 3;
19391
+
19392
+ normalArray[ i ] = nx;
19393
+ normalArray[ i + 1 ] = ny;
19394
+ normalArray[ i + 2 ] = nz;
19395
+
19396
+ normalArray[ i + 3 ] = nx;
19397
+ normalArray[ i + 4 ] = ny;
19398
+ normalArray[ i + 5 ] = nz;
19399
+
19400
+ normalArray[ i + 6 ] = nx;
19401
+ normalArray[ i + 7 ] = ny;
19402
+ normalArray[ i + 8 ] = nz;
19403
+
19404
+ }
19405
+
19406
+ }
19407
+
19408
+ _gl.bufferData( _gl.ARRAY_BUFFER, object.normalArray, _gl.DYNAMIC_DRAW );
19409
+ enableAttribute( program.attributes.normal );
19410
+ _gl.vertexAttribPointer( program.attributes.normal, 3, _gl.FLOAT, false, 0, 0 );
19411
+
19412
+ }
19413
+
19414
+ if ( object.hasUvs && material.map ) {
19415
+
19416
+ _gl.bindBuffer( _gl.ARRAY_BUFFER, object.__webglUvBuffer );
19417
+ _gl.bufferData( _gl.ARRAY_BUFFER, object.uvArray, _gl.DYNAMIC_DRAW );
19418
+ enableAttribute( program.attributes.uv );
19419
+ _gl.vertexAttribPointer( program.attributes.uv, 2, _gl.FLOAT, false, 0, 0 );
19420
+
19421
+ }
19422
+
19423
+ if ( object.hasColors && material.vertexColors !== THREE.NoColors ) {
19424
+
19425
+ _gl.bindBuffer( _gl.ARRAY_BUFFER, object.__webglColorBuffer );
19426
+ _gl.bufferData( _gl.ARRAY_BUFFER, object.colorArray, _gl.DYNAMIC_DRAW );
19427
+ enableAttribute( program.attributes.color );
19428
+ _gl.vertexAttribPointer( program.attributes.color, 3, _gl.FLOAT, false, 0, 0 );
19429
+
19430
+ }
19431
+
19432
+ disableUnusedAttributes();
19433
+
19434
+ _gl.drawArrays( _gl.TRIANGLES, 0, object.count );
19435
+
19436
+ object.count = 0;
19437
+
19438
+ };
19439
+
19440
+ function setupVertexAttributes( material, program, geometry, startIndex ) {
19441
+
19442
+ var geometryAttributes = geometry.attributes;
19443
+
19444
+ var programAttributes = program.attributes;
19445
+ var programAttributesKeys = program.attributesKeys;
19446
+
19447
+ for ( var i = 0, l = programAttributesKeys.length; i < l; i ++ ) {
19448
+
19449
+ var key = programAttributesKeys[ i ];
19450
+ var programAttribute = programAttributes[ key ];
19451
+
19452
+ if ( programAttribute >= 0 ) {
19453
+
19454
+ var geometryAttribute = geometryAttributes[ key ];
19455
+
19456
+ if ( geometryAttribute !== undefined ) {
19457
+
19458
+ var size = geometryAttribute.itemSize;
19459
+
19460
+ _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryAttribute.buffer );
19461
+
19462
+ enableAttribute( programAttribute );
19463
+
19464
+ _gl.vertexAttribPointer( programAttribute, size, _gl.FLOAT, false, 0, startIndex * size * 4 ); // 4 bytes per Float32
19465
+
19466
+ } else if ( material.defaultAttributeValues !== undefined ) {
19467
+
19468
+ if ( material.defaultAttributeValues[ key ].length === 2 ) {
19469
+
19470
+ _gl.vertexAttrib2fv( programAttribute, material.defaultAttributeValues[ key ] );
19471
+
19472
+ } else if ( material.defaultAttributeValues[ key ].length === 3 ) {
19473
+
19474
+ _gl.vertexAttrib3fv( programAttribute, material.defaultAttributeValues[ key ] );
19475
+
19476
+ }
19477
+
19478
+ }
19479
+
19480
+ }
19481
+
19482
+ }
19483
+
19484
+ disableUnusedAttributes();
19485
+
19486
+ }
19487
+
19488
+ this.renderBufferDirect = function ( camera, lights, fog, material, geometry, object ) {
19489
+
19490
+ if ( material.visible === false ) return;
19491
+
19492
+ var program = setProgram( camera, lights, fog, material, object );
19493
+
19494
+ var updateBuffers = false,
19495
+ wireframeBit = material.wireframe ? 1 : 0,
19496
+ geometryHash = ( geometry.id * 0xffffff ) + ( program.id * 2 ) + wireframeBit;
19497
+
19498
+ if ( geometryHash !== _currentGeometryGroupHash ) {
19499
+
19500
+ _currentGeometryGroupHash = geometryHash;
19501
+ updateBuffers = true;
19502
+
19503
+ }
19504
+
19505
+ if ( updateBuffers ) {
19506
+
19507
+ initAttributes();
19508
+
19509
+ }
19510
+
19511
+ // render mesh
19512
+
19513
+ if ( object instanceof THREE.Mesh ) {
19514
+
19515
+ var mode = material.wireframe === true ? _gl.LINES : _gl.TRIANGLES;
19516
+
19517
+ var index = geometry.attributes.index;
19518
+
19519
+ if ( index ) {
19520
+
19521
+ // indexed triangles
19522
+
19523
+ var type, size;
19524
+
19525
+ if ( index.array instanceof Uint32Array && extensions.get( 'OES_element_index_uint' ) ) {
19526
+
19527
+ type = _gl.UNSIGNED_INT;
19528
+ size = 4;
19529
+
19530
+ } else {
19531
+
19532
+ type = _gl.UNSIGNED_SHORT;
19533
+ size = 2;
19534
+
19535
+ }
19536
+
19537
+ var offsets = geometry.offsets;
19538
+
19539
+ if ( offsets.length === 0 ) {
19540
+
19541
+ if ( updateBuffers ) {
19542
+
19543
+ setupVertexAttributes( material, program, geometry, 0 );
19544
+ _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, index.buffer );
19545
+
19546
+ }
19547
+
19548
+ _gl.drawElements( mode, index.array.length, type, 0 );
19549
+
19550
+ _this.info.render.calls ++;
19551
+ _this.info.render.vertices += index.array.length; // not really true, here vertices can be shared
19552
+ _this.info.render.faces += index.array.length / 3;
19553
+
19554
+ } else {
19555
+
19556
+ // if there is more than 1 chunk
19557
+ // must set attribute pointers to use new offsets for each chunk
19558
+ // even if geometry and materials didn't change
19559
+
19560
+ updateBuffers = true;
19561
+
19562
+ for ( var i = 0, il = offsets.length; i < il; i ++ ) {
19563
+
19564
+ var startIndex = offsets[ i ].index;
19565
+
19566
+ if ( updateBuffers ) {
19567
+
19568
+ setupVertexAttributes( material, program, geometry, startIndex );
19569
+ _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, index.buffer );
19570
+
19571
+ }
19572
+
19573
+ // render indexed triangles
19574
+
19575
+ _gl.drawElements( mode, offsets[ i ].count, type, offsets[ i ].start * size );
19576
+
19577
+ _this.info.render.calls ++;
19578
+ _this.info.render.vertices += offsets[ i ].count; // not really true, here vertices can be shared
19579
+ _this.info.render.faces += offsets[ i ].count / 3;
19580
+
19581
+ }
19582
+
19583
+ }
19584
+
19585
+ } else {
19586
+
19587
+ // non-indexed triangles
19588
+
19589
+ if ( updateBuffers ) {
19590
+
19591
+ setupVertexAttributes( material, program, geometry, 0 );
19592
+
19593
+ }
19594
+
19595
+ var position = geometry.attributes[ 'position' ];
19596
+
19597
+ // render non-indexed triangles
19598
+
19599
+ _gl.drawArrays( mode, 0, position.array.length / 3 );
19600
+
19601
+ _this.info.render.calls ++;
19602
+ _this.info.render.vertices += position.array.length / 3;
19603
+ _this.info.render.faces += position.array.length / 9;
19604
+
19605
+ }
19606
+
19607
+ } else if ( object instanceof THREE.PointCloud ) {
19608
+
19609
+ // render particles
19610
+
19611
+ if ( updateBuffers ) {
19612
+
19613
+ setupVertexAttributes( material, program, geometry, 0 );
19614
+
19615
+ }
19616
+
19617
+ var position = geometry.attributes.position;
19618
+
19619
+ // render particles
19620
+
19621
+ _gl.drawArrays( _gl.POINTS, 0, position.array.length / 3 );
19622
+
19623
+ _this.info.render.calls ++;
19624
+ _this.info.render.points += position.array.length / 3;
19625
+
19626
+ } else if ( object instanceof THREE.Line ) {
19627
+
19628
+ var mode = ( object.mode === THREE.LineStrip ) ? _gl.LINE_STRIP : _gl.LINES;
19629
+
19630
+ setLineWidth( material.linewidth );
19631
+
19632
+ var index = geometry.attributes.index;
19633
+
19634
+ if ( index ) {
19635
+
19636
+ // indexed lines
19637
+
19638
+ var type, size;
19639
+
19640
+ if ( index.array instanceof Uint32Array ) {
19641
+
19642
+ type = _gl.UNSIGNED_INT;
19643
+ size = 4;
19644
+
19645
+ } else {
19646
+
19647
+ type = _gl.UNSIGNED_SHORT;
19648
+ size = 2;
19649
+
19650
+ }
19651
+
19652
+ var offsets = geometry.offsets;
19653
+
19654
+ if ( offsets.length === 0 ) {
19655
+
19656
+ if ( updateBuffers ) {
19657
+
19658
+ setupVertexAttributes( material, program, geometry, 0 );
19659
+ _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, index.buffer );
19660
+
19661
+ }
19662
+
19663
+ _gl.drawElements( mode, index.array.length, type, 0 ); // 2 bytes per Uint16Array
19664
+
19665
+ _this.info.render.calls ++;
19666
+ _this.info.render.vertices += index.array.length; // not really true, here vertices can be shared
19667
+
19668
+ } else {
19669
+
19670
+ // if there is more than 1 chunk
19671
+ // must set attribute pointers to use new offsets for each chunk
19672
+ // even if geometry and materials didn't change
19673
+
19674
+ if ( offsets.length > 1 ) updateBuffers = true;
19675
+
19676
+ for ( var i = 0, il = offsets.length; i < il; i ++ ) {
19677
+
19678
+ var startIndex = offsets[ i ].index;
19679
+
19680
+ if ( updateBuffers ) {
19681
+
19682
+ setupVertexAttributes( material, program, geometry, startIndex );
19683
+ _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, index.buffer );
19684
+
19685
+ }
19686
+
19687
+ // render indexed lines
19688
+
19689
+ _gl.drawElements( mode, offsets[ i ].count, type, offsets[ i ].start * size ); // 2 bytes per Uint16Array
19690
+
19691
+ _this.info.render.calls ++;
19692
+ _this.info.render.vertices += offsets[ i ].count; // not really true, here vertices can be shared
19693
+
19694
+ }
19695
+
19696
+ }
19697
+
19698
+ } else {
19699
+
19700
+ // non-indexed lines
19701
+
19702
+ if ( updateBuffers ) {
19703
+
19704
+ setupVertexAttributes( material, program, geometry, 0 );
19705
+
19706
+ }
19707
+
19708
+ var position = geometry.attributes.position;
19709
+
19710
+ _gl.drawArrays( mode, 0, position.array.length / 3 );
19711
+
19712
+ _this.info.render.calls ++;
19713
+ _this.info.render.points += position.array.length / 3;
19714
+
19715
+ }
19716
+
19717
+ }
19718
+
19719
+ };
19720
+
19721
+ this.renderBuffer = function ( camera, lights, fog, material, geometryGroup, object ) {
19722
+
19723
+ if ( material.visible === false ) return;
19724
+
19725
+ var program = setProgram( camera, lights, fog, material, object );
19726
+
19727
+ var attributes = program.attributes;
19728
+
19729
+ var updateBuffers = false,
19730
+ wireframeBit = material.wireframe ? 1 : 0,
19731
+ geometryGroupHash = ( geometryGroup.id * 0xffffff ) + ( program.id * 2 ) + wireframeBit;
19732
+
19733
+ if ( geometryGroupHash !== _currentGeometryGroupHash ) {
19734
+
19735
+ _currentGeometryGroupHash = geometryGroupHash;
19736
+ updateBuffers = true;
19737
+
19738
+ }
19739
+
19740
+ if ( updateBuffers ) {
19741
+
19742
+ initAttributes();
19743
+
19744
+ }
19745
+
19746
+ // vertices
19747
+
19748
+ if ( ! material.morphTargets && attributes.position >= 0 ) {
19749
+
19750
+ if ( updateBuffers ) {
19751
+
19752
+ _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglVertexBuffer );
19753
+ enableAttribute( attributes.position );
19754
+ _gl.vertexAttribPointer( attributes.position, 3, _gl.FLOAT, false, 0, 0 );
19755
+
19756
+ }
19757
+
19758
+ } else {
19759
+
19760
+ if ( object.morphTargetBase ) {
19761
+
19762
+ setupMorphTargets( material, geometryGroup, object );
19763
+
19764
+ }
19765
+
19766
+ }
19767
+
19768
+
19769
+ if ( updateBuffers ) {
19770
+
19771
+ // custom attributes
19772
+
19773
+ // Use the per-geometryGroup custom attribute arrays which are setup in initMeshBuffers
19774
+
19775
+ if ( geometryGroup.__webglCustomAttributesList ) {
19776
+
19777
+ for ( var i = 0, il = geometryGroup.__webglCustomAttributesList.length; i < il; i ++ ) {
19778
+
19779
+ var attribute = geometryGroup.__webglCustomAttributesList[ i ];
19780
+
19781
+ if ( attributes[ attribute.buffer.belongsToAttribute ] >= 0 ) {
19782
+
19783
+ _gl.bindBuffer( _gl.ARRAY_BUFFER, attribute.buffer );
19784
+ enableAttribute( attributes[ attribute.buffer.belongsToAttribute ] );
19785
+ _gl.vertexAttribPointer( attributes[ attribute.buffer.belongsToAttribute ], attribute.size, _gl.FLOAT, false, 0, 0 );
19786
+
19787
+ }
19788
+
19789
+ }
19790
+
19791
+ }
19792
+
19793
+
19794
+ // colors
19795
+
19796
+ if ( attributes.color >= 0 ) {
19797
+
19798
+ if ( object.geometry.colors.length > 0 || object.geometry.faces.length > 0 ) {
19799
+
19800
+ _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglColorBuffer );
19801
+ enableAttribute( attributes.color );
19802
+ _gl.vertexAttribPointer( attributes.color, 3, _gl.FLOAT, false, 0, 0 );
19803
+
19804
+ } else if ( material.defaultAttributeValues !== undefined ) {
19805
+
19806
+
19807
+ _gl.vertexAttrib3fv( attributes.color, material.defaultAttributeValues.color );
19808
+
19809
+ }
19810
+
19811
+ }
19812
+
19813
+ // normals
19814
+
19815
+ if ( attributes.normal >= 0 ) {
19816
+
19817
+ _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglNormalBuffer );
19818
+ enableAttribute( attributes.normal );
19819
+ _gl.vertexAttribPointer( attributes.normal, 3, _gl.FLOAT, false, 0, 0 );
19820
+
19821
+ }
19822
+
19823
+ // tangents
19824
+
19825
+ if ( attributes.tangent >= 0 ) {
19826
+
19827
+ _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglTangentBuffer );
19828
+ enableAttribute( attributes.tangent );
19829
+ _gl.vertexAttribPointer( attributes.tangent, 4, _gl.FLOAT, false, 0, 0 );
19830
+
19831
+ }
19832
+
19833
+ // uvs
19834
+
19835
+ if ( attributes.uv >= 0 ) {
19836
+
19837
+ if ( object.geometry.faceVertexUvs[ 0 ] ) {
19838
+
19839
+ _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglUVBuffer );
19840
+ enableAttribute( attributes.uv );
19841
+ _gl.vertexAttribPointer( attributes.uv, 2, _gl.FLOAT, false, 0, 0 );
19842
+
19843
+ } else if ( material.defaultAttributeValues !== undefined ) {
19844
+
19845
+
19846
+ _gl.vertexAttrib2fv( attributes.uv, material.defaultAttributeValues.uv );
19847
+
19848
+ }
19849
+
19850
+ }
19851
+
19852
+ if ( attributes.uv2 >= 0 ) {
19853
+
19854
+ if ( object.geometry.faceVertexUvs[ 1 ] ) {
19855
+
19856
+ _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglUV2Buffer );
19857
+ enableAttribute( attributes.uv2 );
19858
+ _gl.vertexAttribPointer( attributes.uv2, 2, _gl.FLOAT, false, 0, 0 );
19859
+
19860
+ } else if ( material.defaultAttributeValues !== undefined ) {
19861
+
19862
+
19863
+ _gl.vertexAttrib2fv( attributes.uv2, material.defaultAttributeValues.uv2 );
19864
+
19865
+ }
19866
+
19867
+ }
19868
+
19869
+ if ( material.skinning &&
19870
+ attributes.skinIndex >= 0 && attributes.skinWeight >= 0 ) {
19871
+
19872
+ _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglSkinIndicesBuffer );
19873
+ enableAttribute( attributes.skinIndex );
19874
+ _gl.vertexAttribPointer( attributes.skinIndex, 4, _gl.FLOAT, false, 0, 0 );
19875
+
19876
+ _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglSkinWeightsBuffer );
19877
+ enableAttribute( attributes.skinWeight );
19878
+ _gl.vertexAttribPointer( attributes.skinWeight, 4, _gl.FLOAT, false, 0, 0 );
19879
+
19880
+ }
19881
+
19882
+ // line distances
19883
+
19884
+ if ( attributes.lineDistance >= 0 ) {
19885
+
19886
+ _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglLineDistanceBuffer );
19887
+ enableAttribute( attributes.lineDistance );
19888
+ _gl.vertexAttribPointer( attributes.lineDistance, 1, _gl.FLOAT, false, 0, 0 );
19889
+
19890
+ }
19891
+
19892
+ }
19893
+
19894
+ disableUnusedAttributes();
19895
+
19896
+ // render mesh
19897
+
19898
+ if ( object instanceof THREE.Mesh ) {
19899
+
19900
+ var type = geometryGroup.__typeArray === Uint32Array ? _gl.UNSIGNED_INT : _gl.UNSIGNED_SHORT;
19901
+
19902
+ // wireframe
19903
+
19904
+ if ( material.wireframe ) {
19905
+
19906
+ setLineWidth( material.wireframeLinewidth );
19907
+ if ( updateBuffers ) _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, geometryGroup.__webglLineBuffer );
19908
+ _gl.drawElements( _gl.LINES, geometryGroup.__webglLineCount, type, 0 );
19909
+
19910
+ // triangles
19911
+
19912
+ } else {
19913
+
19914
+ if ( updateBuffers ) _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, geometryGroup.__webglFaceBuffer );
19915
+ _gl.drawElements( _gl.TRIANGLES, geometryGroup.__webglFaceCount, type, 0 );
19916
+
19917
+ }
19918
+
19919
+ _this.info.render.calls ++;
19920
+ _this.info.render.vertices += geometryGroup.__webglFaceCount;
19921
+ _this.info.render.faces += geometryGroup.__webglFaceCount / 3;
19922
+
19923
+ // render lines
19924
+
19925
+ } else if ( object instanceof THREE.Line ) {
19926
+
19927
+ var mode = ( object.mode === THREE.LineStrip ) ? _gl.LINE_STRIP : _gl.LINES;
19928
+
19929
+ setLineWidth( material.linewidth );
19930
+
19931
+ _gl.drawArrays( mode, 0, geometryGroup.__webglLineCount );
19932
+
19933
+ _this.info.render.calls ++;
19934
+
19935
+ // render particles
19936
+
19937
+ } else if ( object instanceof THREE.PointCloud ) {
19938
+
19939
+ _gl.drawArrays( _gl.POINTS, 0, geometryGroup.__webglParticleCount );
19940
+
19941
+ _this.info.render.calls ++;
19942
+ _this.info.render.points += geometryGroup.__webglParticleCount;
19943
+
19944
+ }
19945
+
19946
+ };
19947
+
19948
+ function initAttributes() {
19949
+
19950
+ for ( var i = 0, l = _newAttributes.length; i < l; i ++ ) {
19951
+
19952
+ _newAttributes[ i ] = 0;
19953
+
19954
+ }
19955
+
19956
+ }
19957
+
19958
+ function enableAttribute( attribute ) {
19959
+
19960
+ _newAttributes[ attribute ] = 1;
19961
+
19962
+ if ( _enabledAttributes[ attribute ] === 0 ) {
19963
+
19964
+ _gl.enableVertexAttribArray( attribute );
19965
+ _enabledAttributes[ attribute ] = 1;
19966
+
19967
+ }
19968
+
19969
+ }
19970
+
19971
+ function disableUnusedAttributes() {
19972
+
19973
+ for ( var i = 0, l = _enabledAttributes.length; i < l; i ++ ) {
19974
+
19975
+ if ( _enabledAttributes[ i ] !== _newAttributes[ i ] ) {
19976
+
19977
+ _gl.disableVertexAttribArray( i );
19978
+ _enabledAttributes[ i ] = 0;
19979
+
19980
+ }
19981
+
19982
+ }
19983
+
19984
+ }
19985
+
19986
+ function setupMorphTargets ( material, geometryGroup, object ) {
19987
+
19988
+ // set base
19989
+
19990
+ var attributes = material.program.attributes;
19991
+
19992
+ if ( object.morphTargetBase !== - 1 && attributes.position >= 0 ) {
19993
+
19994
+ _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglMorphTargetsBuffers[ object.morphTargetBase ] );
19995
+ enableAttribute( attributes.position );
19996
+ _gl.vertexAttribPointer( attributes.position, 3, _gl.FLOAT, false, 0, 0 );
19997
+
19998
+ } else if ( attributes.position >= 0 ) {
19999
+
20000
+ _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglVertexBuffer );
20001
+ enableAttribute( attributes.position );
20002
+ _gl.vertexAttribPointer( attributes.position, 3, _gl.FLOAT, false, 0, 0 );
20003
+
20004
+ }
20005
+
20006
+ if ( object.morphTargetForcedOrder.length ) {
20007
+
20008
+ // set forced order
20009
+
20010
+ var m = 0;
20011
+ var order = object.morphTargetForcedOrder;
20012
+ var influences = object.morphTargetInfluences;
20013
+
20014
+ while ( m < material.numSupportedMorphTargets && m < order.length ) {
20015
+
20016
+ if ( attributes[ 'morphTarget' + m ] >= 0 ) {
20017
+
20018
+ _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglMorphTargetsBuffers[ order[ m ] ] );
20019
+ enableAttribute( attributes[ 'morphTarget' + m ] );
20020
+ _gl.vertexAttribPointer( attributes[ 'morphTarget' + m ], 3, _gl.FLOAT, false, 0, 0 );
20021
+
20022
+ }
20023
+
20024
+ if ( attributes[ 'morphNormal' + m ] >= 0 && material.morphNormals ) {
20025
+
20026
+ _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglMorphNormalsBuffers[ order[ m ] ] );
20027
+ enableAttribute( attributes[ 'morphNormal' + m ] );
20028
+ _gl.vertexAttribPointer( attributes[ 'morphNormal' + m ], 3, _gl.FLOAT, false, 0, 0 );
20029
+
20030
+ }
20031
+
20032
+ object.__webglMorphTargetInfluences[ m ] = influences[ order[ m ] ];
20033
+
20034
+ m ++;
20035
+ }
20036
+
20037
+ } else {
20038
+
20039
+ // find the most influencing
20040
+
20041
+ var influence, activeInfluenceIndices = [];
20042
+ var influences = object.morphTargetInfluences;
20043
+ var i, il = influences.length;
20044
+
20045
+ for ( i = 0; i < il; i ++ ) {
20046
+
20047
+ influence = influences[ i ];
20048
+
20049
+ if ( influence > 0 ) {
20050
+
20051
+ activeInfluenceIndices.push( [ influence, i ] );
20052
+
20053
+ }
20054
+
20055
+ }
20056
+
20057
+ if ( activeInfluenceIndices.length > material.numSupportedMorphTargets ) {
20058
+
20059
+ activeInfluenceIndices.sort( numericalSort );
20060
+ activeInfluenceIndices.length = material.numSupportedMorphTargets;
20061
+
20062
+ } else if ( activeInfluenceIndices.length > material.numSupportedMorphNormals ) {
20063
+
20064
+ activeInfluenceIndices.sort( numericalSort );
20065
+
20066
+ } else if ( activeInfluenceIndices.length === 0 ) {
20067
+
20068
+ activeInfluenceIndices.push( [ 0, 0 ] );
20069
+
20070
+ };
20071
+
20072
+ var influenceIndex, m = 0;
20073
+
20074
+ while ( m < material.numSupportedMorphTargets ) {
20075
+
20076
+ if ( activeInfluenceIndices[ m ] ) {
20077
+
20078
+ influenceIndex = activeInfluenceIndices[ m ][ 1 ];
20079
+
20080
+ if ( attributes[ 'morphTarget' + m ] >= 0 ) {
20081
+
20082
+ _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglMorphTargetsBuffers[ influenceIndex ] );
20083
+ enableAttribute( attributes[ 'morphTarget' + m ] );
20084
+ _gl.vertexAttribPointer( attributes[ 'morphTarget' + m ], 3, _gl.FLOAT, false, 0, 0 );
20085
+
20086
+ }
20087
+
20088
+ if ( attributes[ 'morphNormal' + m ] >= 0 && material.morphNormals ) {
20089
+
20090
+ _gl.bindBuffer( _gl.ARRAY_BUFFER, geometryGroup.__webglMorphNormalsBuffers[ influenceIndex ] );
20091
+ enableAttribute( attributes[ 'morphNormal' + m ] );
20092
+ _gl.vertexAttribPointer( attributes[ 'morphNormal' + m ], 3, _gl.FLOAT, false, 0, 0 );
20093
+
20094
+
20095
+ }
20096
+
20097
+ object.__webglMorphTargetInfluences[ m ] = influences[ influenceIndex ];
20098
+
20099
+ } else {
20100
+
20101
+ /*
20102
+ _gl.vertexAttribPointer( attributes[ "morphTarget" + m ], 3, _gl.FLOAT, false, 0, 0 );
20103
+
20104
+ if ( material.morphNormals ) {
20105
+
20106
+ _gl.vertexAttribPointer( attributes[ "morphNormal" + m ], 3, _gl.FLOAT, false, 0, 0 );
20107
+
20108
+ }
20109
+ */
20110
+
20111
+ object.__webglMorphTargetInfluences[ m ] = 0;
20112
+
20113
+ }
20114
+
20115
+ m ++;
20116
+
20117
+ }
20118
+
20119
+ }
20120
+
20121
+ // load updated influences uniform
20122
+
20123
+ if ( material.program.uniforms.morphTargetInfluences !== null ) {
20124
+
20125
+ _gl.uniform1fv( material.program.uniforms.morphTargetInfluences, object.__webglMorphTargetInfluences );
20126
+
20127
+ }
20128
+
20129
+ }
20130
+
20131
+ // Sorting
20132
+
20133
+ function painterSortStable ( a, b ) {
20134
+
20135
+ if ( a.material.id !== b.material.id ) {
20136
+
20137
+ return b.material.id - a.material.id;
20138
+
20139
+ } else if ( a.z !== b.z ) {
20140
+
20141
+ return b.z - a.z;
20142
+
20143
+ } else {
20144
+
20145
+ return a.id - b.id;
20146
+
20147
+ }
20148
+
20149
+ }
20150
+
20151
+ function reversePainterSortStable ( a, b ) {
20152
+
20153
+ if ( a.z !== b.z ) {
20154
+
20155
+ return a.z - b.z;
20156
+
20157
+ } else {
20158
+
20159
+ return a.id - b.id;
20160
+
20161
+ }
20162
+
20163
+ }
20164
+
20165
+ function numericalSort ( a, b ) {
20166
+
20167
+ return b[ 0 ] - a[ 0 ];
20168
+
20169
+ }
20170
+
20171
+ // Rendering
20172
+
20173
+ this.render = function ( scene, camera, renderTarget, forceClear ) {
20174
+
20175
+ if ( camera instanceof THREE.Camera === false ) {
20176
+
20177
+ console.error( 'THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.' );
20178
+ return;
20179
+
20180
+ }
20181
+
20182
+ var fog = scene.fog;
20183
+
20184
+ // reset caching for this frame
20185
+
20186
+ _currentGeometryGroupHash = - 1;
20187
+ _currentMaterialId = - 1;
20188
+ _currentCamera = null;
20189
+ _lightsNeedUpdate = true;
20190
+
20191
+ // update scene graph
20192
+
20193
+ if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
20194
+
20195
+ // update camera matrices and frustum
20196
+
20197
+ if ( camera.parent === undefined ) camera.updateMatrixWorld();
20198
+
20199
+ // update Skeleton objects
20200
+
20201
+ scene.traverse( function ( object ) {
20202
+
20203
+ if ( object instanceof THREE.SkinnedMesh ) {
20204
+
20205
+ object.skeleton.update();
20206
+
20207
+ }
20208
+
20209
+ } );
20210
+
20211
+ camera.matrixWorldInverse.getInverse( camera.matrixWorld );
20212
+
20213
+ _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
20214
+ _frustum.setFromMatrix( _projScreenMatrix );
20215
+
20216
+ lights.length = 0;
20217
+ opaqueObjects.length = 0;
20218
+ transparentObjects.length = 0;
20219
+
20220
+ sprites.length = 0;
20221
+ lensFlares.length = 0;
20222
+
20223
+ projectObject( scene, scene );
20224
+
20225
+ if ( _this.sortObjects === true ) {
20226
+
20227
+ opaqueObjects.sort( painterSortStable );
20228
+ transparentObjects.sort( reversePainterSortStable );
20229
+
20230
+ }
20231
+
20232
+ // custom render plugins (pre pass)
20233
+
20234
+ shadowMapPlugin.render( scene, camera );
20235
+
20236
+ //
20237
+
20238
+ _this.info.render.calls = 0;
20239
+ _this.info.render.vertices = 0;
20240
+ _this.info.render.faces = 0;
20241
+ _this.info.render.points = 0;
20242
+
20243
+ this.setRenderTarget( renderTarget );
20244
+
20245
+ if ( this.autoClear || forceClear ) {
20246
+
20247
+ this.clear( this.autoClearColor, this.autoClearDepth, this.autoClearStencil );
20248
+
20249
+ }
20250
+
20251
+ // set matrices for immediate objects
20252
+
20253
+ for ( var i = 0, il = _webglObjectsImmediate.length; i < il; i ++ ) {
20254
+
20255
+ var webglObject = _webglObjectsImmediate[ i ];
20256
+ var object = webglObject.object;
20257
+
20258
+ if ( object.visible ) {
20259
+
20260
+ setupMatrices( object, camera );
20261
+
20262
+ unrollImmediateBufferMaterial( webglObject );
20263
+
20264
+ }
20265
+
20266
+ }
20267
+
20268
+ if ( scene.overrideMaterial ) {
20269
+
20270
+ var material = scene.overrideMaterial;
20271
+
20272
+ this.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst );
20273
+ this.setDepthTest( material.depthTest );
20274
+ this.setDepthWrite( material.depthWrite );
20275
+ setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
20276
+
20277
+ renderObjects( opaqueObjects, camera, lights, fog, true, material );
20278
+ renderObjects( transparentObjects, camera, lights, fog, true, material );
20279
+ renderObjectsImmediate( _webglObjectsImmediate, '', camera, lights, fog, false, material );
20280
+
20281
+ } else {
20282
+
20283
+ var material = null;
20284
+
20285
+ // opaque pass (front-to-back order)
20286
+
20287
+ this.setBlending( THREE.NoBlending );
20288
+
20289
+ renderObjects( opaqueObjects, camera, lights, fog, false, material );
20290
+ renderObjectsImmediate( _webglObjectsImmediate, 'opaque', camera, lights, fog, false, material );
20291
+
20292
+ // transparent pass (back-to-front order)
20293
+
20294
+ renderObjects( transparentObjects, camera, lights, fog, true, material );
20295
+ renderObjectsImmediate( _webglObjectsImmediate, 'transparent', camera, lights, fog, true, material );
20296
+
20297
+ }
20298
+
20299
+ // custom render plugins (post pass)
20300
+
20301
+ spritePlugin.render( scene, camera );
20302
+ lensFlarePlugin.render( scene, camera, _currentWidth, _currentHeight );
20303
+
20304
+ // Generate mipmap if we're using any kind of mipmap filtering
20305
+
20306
+ if ( renderTarget && renderTarget.generateMipmaps && renderTarget.minFilter !== THREE.NearestFilter && renderTarget.minFilter !== THREE.LinearFilter ) {
20307
+
20308
+ updateRenderTargetMipmap( renderTarget );
20309
+
20310
+ }
20311
+
20312
+ // Ensure depth buffer writing is enabled so it can be cleared on next render
20313
+
20314
+ this.setDepthTest( true );
20315
+ this.setDepthWrite( true );
20316
+
20317
+ // _gl.finish();
20318
+
20319
+ };
20320
+
20321
+ function projectObject( scene, object ) {
20322
+
20323
+ if ( object.visible === false ) return;
20324
+
20325
+ if ( object instanceof THREE.Scene || object instanceof THREE.Group ) {
20326
+
20327
+ // skip
20328
+
20329
+ } else {
20330
+
20331
+ initObject( object, scene );
20332
+
20333
+ if ( object instanceof THREE.Light ) {
20334
+
20335
+ lights.push( object );
20336
+
20337
+ } else if ( object instanceof THREE.Sprite ) {
20338
+
20339
+ sprites.push( object );
20340
+
20341
+ } else if ( object instanceof THREE.LensFlare ) {
20342
+
20343
+ lensFlares.push( object );
20344
+
20345
+ } else {
20346
+
20347
+ var webglObjects = _webglObjects[ object.id ];
20348
+
20349
+ if ( webglObjects && ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) ) {
20350
+
20351
+ updateObject( object, scene );
20352
+
20353
+ for ( var i = 0, l = webglObjects.length; i < l; i ++ ) {
20354
+
20355
+ var webglObject = webglObjects[i];
20356
+
20357
+ unrollBufferMaterial( webglObject );
20358
+
20359
+ webglObject.render = true;
20360
+
20361
+ if ( _this.sortObjects === true ) {
20362
+
20363
+ if ( object.renderDepth !== null ) {
20364
+
20365
+ webglObject.z = object.renderDepth;
20366
+
20367
+ } else {
20368
+
20369
+ _vector3.setFromMatrixPosition( object.matrixWorld );
20370
+ _vector3.applyProjection( _projScreenMatrix );
20371
+
20372
+ webglObject.z = _vector3.z;
20373
+
20374
+ }
20375
+
20376
+ }
20377
+
20378
+ }
20379
+
20380
+ }
20381
+
20382
+ }
20383
+
20384
+ }
20385
+
20386
+ for ( var i = 0, l = object.children.length; i < l; i ++ ) {
20387
+
20388
+ projectObject( scene, object.children[ i ] );
20389
+
20390
+ }
20391
+
20392
+ }
20393
+
20394
+ function renderObjects( renderList, camera, lights, fog, useBlending, overrideMaterial ) {
20395
+
20396
+ var material;
20397
+
20398
+ for ( var i = renderList.length - 1; i !== - 1; i -- ) {
20399
+
20400
+ var webglObject = renderList[ i ];
20401
+
20402
+ var object = webglObject.object;
20403
+ var buffer = webglObject.buffer;
20404
+
20405
+ setupMatrices( object, camera );
20406
+
20407
+ if ( overrideMaterial ) {
20408
+
20409
+ material = overrideMaterial;
20410
+
20411
+ } else {
20412
+
20413
+ material = webglObject.material;
20414
+
20415
+ if ( ! material ) continue;
20416
+
20417
+ if ( useBlending ) _this.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst );
20418
+
20419
+ _this.setDepthTest( material.depthTest );
20420
+ _this.setDepthWrite( material.depthWrite );
20421
+ setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
20422
+
20423
+ }
20424
+
20425
+ _this.setMaterialFaces( material );
20426
+
20427
+ if ( buffer instanceof THREE.BufferGeometry ) {
20428
+
20429
+ _this.renderBufferDirect( camera, lights, fog, material, buffer, object );
20430
+
20431
+ } else {
20432
+
20433
+ _this.renderBuffer( camera, lights, fog, material, buffer, object );
20434
+
20435
+ }
20436
+
20437
+ }
20438
+
20439
+ }
20440
+
20441
+ function renderObjectsImmediate ( renderList, materialType, camera, lights, fog, useBlending, overrideMaterial ) {
20442
+
20443
+ var material;
20444
+
20445
+ for ( var i = 0, il = renderList.length; i < il; i ++ ) {
20446
+
20447
+ var webglObject = renderList[ i ];
20448
+ var object = webglObject.object;
20449
+
20450
+ if ( object.visible ) {
20451
+
20452
+ if ( overrideMaterial ) {
20453
+
20454
+ material = overrideMaterial;
20455
+
20456
+ } else {
20457
+
20458
+ material = webglObject[ materialType ];
20459
+
20460
+ if ( ! material ) continue;
20461
+
20462
+ if ( useBlending ) _this.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst );
20463
+
20464
+ _this.setDepthTest( material.depthTest );
20465
+ _this.setDepthWrite( material.depthWrite );
20466
+ setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
20467
+
20468
+ }
20469
+
20470
+ _this.renderImmediateObject( camera, lights, fog, material, object );
20471
+
20472
+ }
20473
+
20474
+ }
20475
+
20476
+ }
20477
+
20478
+ this.renderImmediateObject = function ( camera, lights, fog, material, object ) {
20479
+
20480
+ var program = setProgram( camera, lights, fog, material, object );
20481
+
20482
+ _currentGeometryGroupHash = - 1;
20483
+
20484
+ _this.setMaterialFaces( material );
20485
+
20486
+ if ( object.immediateRenderCallback ) {
20487
+
20488
+ object.immediateRenderCallback( program, _gl, _frustum );
20489
+
20490
+ } else {
20491
+
20492
+ object.render( function ( object ) { _this.renderBufferImmediate( object, program, material ); } );
20493
+
20494
+ }
20495
+
20496
+ };
20497
+
20498
+ function unrollImmediateBufferMaterial ( globject ) {
20499
+
20500
+ var object = globject.object,
20501
+ material = object.material;
20502
+
20503
+ if ( material.transparent ) {
20504
+
20505
+ globject.transparent = material;
20506
+ globject.opaque = null;
20507
+
20508
+ } else {
20509
+
20510
+ globject.opaque = material;
20511
+ globject.transparent = null;
20512
+
20513
+ }
20514
+
20515
+ }
20516
+
20517
+ function unrollBufferMaterial ( globject ) {
20518
+
20519
+ var object = globject.object;
20520
+ var buffer = globject.buffer;
20521
+
20522
+ var geometry = object.geometry;
20523
+ var material = object.material;
20524
+
20525
+ if ( material instanceof THREE.MeshFaceMaterial ) {
20526
+
20527
+ var materialIndex = geometry instanceof THREE.BufferGeometry ? 0 : buffer.materialIndex;
20528
+
20529
+ material = material.materials[ materialIndex ];
20530
+
20531
+ globject.material = material;
20532
+
20533
+ if ( material.transparent ) {
20534
+
20535
+ transparentObjects.push( globject );
20536
+
20537
+ } else {
20538
+
20539
+ opaqueObjects.push( globject );
20540
+
20541
+ }
20542
+
20543
+ } else if ( material ) {
20544
+
20545
+ globject.material = material;
20546
+
20547
+ if ( material.transparent ) {
20548
+
20549
+ transparentObjects.push( globject );
20550
+
20551
+ } else {
20552
+
20553
+ opaqueObjects.push( globject );
20554
+
20555
+ }
20556
+
20557
+ }
20558
+
20559
+ }
20560
+
20561
+ function initObject( object, scene ) {
20562
+
20563
+ if ( object.__webglInit === undefined ) {
20564
+
20565
+ object.__webglInit = true;
20566
+ object._modelViewMatrix = new THREE.Matrix4();
20567
+ object._normalMatrix = new THREE.Matrix3();
20568
+
20569
+ object.addEventListener( 'removed', onObjectRemoved );
20570
+
20571
+ }
20572
+
20573
+ var geometry = object.geometry;
20574
+
20575
+ if ( geometry === undefined ) {
20576
+
20577
+ // ImmediateRenderObject
20578
+
20579
+ } else if ( geometry.__webglInit === undefined ) {
20580
+
20581
+ geometry.__webglInit = true;
20582
+ geometry.addEventListener( 'dispose', onGeometryDispose );
20583
+
20584
+ if ( geometry instanceof THREE.BufferGeometry ) {
20585
+
20586
+ //
20587
+
20588
+ } else if ( object instanceof THREE.Mesh ) {
20589
+
20590
+ initGeometryGroups( scene, object, geometry );
20591
+
20592
+ } else if ( object instanceof THREE.Line ) {
20593
+
20594
+ if ( geometry.__webglVertexBuffer === undefined ) {
20595
+
20596
+ createLineBuffers( geometry );
20597
+ initLineBuffers( geometry, object );
20598
+
20599
+ geometry.verticesNeedUpdate = true;
20600
+ geometry.colorsNeedUpdate = true;
20601
+ geometry.lineDistancesNeedUpdate = true;
20602
+
20603
+ }
20604
+
20605
+ } else if ( object instanceof THREE.PointCloud ) {
20606
+
20607
+ if ( geometry.__webglVertexBuffer === undefined ) {
20608
+
20609
+ createParticleBuffers( geometry );
20610
+ initParticleBuffers( geometry, object );
20611
+
20612
+ geometry.verticesNeedUpdate = true;
20613
+ geometry.colorsNeedUpdate = true;
20614
+
20615
+ }
20616
+
20617
+ }
20618
+
20619
+ }
20620
+
20621
+ if ( object.__webglActive === undefined) {
20622
+
20623
+ object.__webglActive = true;
20624
+
20625
+ if ( object instanceof THREE.Mesh ) {
20626
+
20627
+ if ( geometry instanceof THREE.BufferGeometry ) {
20628
+
20629
+ addBuffer( _webglObjects, geometry, object );
20630
+
20631
+ } else if ( geometry instanceof THREE.Geometry ) {
20632
+
20633
+ var geometryGroupsList = geometryGroups[ geometry.id ];
20634
+
20635
+ for ( var i = 0,l = geometryGroupsList.length; i < l; i ++ ) {
20636
+
20637
+ addBuffer( _webglObjects, geometryGroupsList[ i ], object );
20638
+
20639
+ }
20640
+
20641
+ }
20642
+
20643
+ } else if ( object instanceof THREE.Line || object instanceof THREE.PointCloud ) {
20644
+
20645
+ addBuffer( _webglObjects, geometry, object );
20646
+
20647
+ } else if ( object instanceof THREE.ImmediateRenderObject || object.immediateRenderCallback ) {
20648
+
20649
+ addBufferImmediate( _webglObjectsImmediate, object );
20650
+
20651
+ }
20652
+
20653
+ }
20654
+
20655
+ }
20656
+
20657
+ // Geometry splitting
20658
+
20659
+ var geometryGroups = {};
20660
+ var geometryGroupCounter = 0;
20661
+
20662
+ function makeGroups( geometry, usesFaceMaterial ) {
20663
+
20664
+ var maxVerticesInGroup = extensions.get( 'OES_element_index_uint' ) ? 4294967296 : 65535;
20665
+
20666
+ var groupHash, hash_map = {};
20667
+
20668
+ var numMorphTargets = geometry.morphTargets.length;
20669
+ var numMorphNormals = geometry.morphNormals.length;
20670
+
20671
+ var group;
20672
+ var groups = {};
20673
+ var groupsList = [];
20674
+
20675
+ for ( var f = 0, fl = geometry.faces.length; f < fl; f ++ ) {
20676
+
20677
+ var face = geometry.faces[ f ];
20678
+ var materialIndex = usesFaceMaterial ? face.materialIndex : 0;
20679
+
20680
+ if ( ! ( materialIndex in hash_map ) ) {
20681
+
20682
+ hash_map[ materialIndex ] = { hash: materialIndex, counter: 0 };
20683
+
20684
+ }
20685
+
20686
+ groupHash = hash_map[ materialIndex ].hash + '_' + hash_map[ materialIndex ].counter;
20687
+
20688
+ if ( ! ( groupHash in groups ) ) {
20689
+
20690
+ group = {
20691
+ id: geometryGroupCounter ++,
20692
+ faces3: [],
20693
+ materialIndex: materialIndex,
20694
+ vertices: 0,
20695
+ numMorphTargets: numMorphTargets,
20696
+ numMorphNormals: numMorphNormals
20697
+ };
20698
+
20699
+ groups[ groupHash ] = group;
20700
+ groupsList.push( group );
20701
+
20702
+ }
20703
+
20704
+ if ( groups[ groupHash ].vertices + 3 > maxVerticesInGroup ) {
20705
+
20706
+ hash_map[ materialIndex ].counter += 1;
20707
+ groupHash = hash_map[ materialIndex ].hash + '_' + hash_map[ materialIndex ].counter;
20708
+
20709
+ if ( ! ( groupHash in groups ) ) {
20710
+
20711
+ group = {
20712
+ id: geometryGroupCounter ++,
20713
+ faces3: [],
20714
+ materialIndex: materialIndex,
20715
+ vertices: 0,
20716
+ numMorphTargets: numMorphTargets,
20717
+ numMorphNormals: numMorphNormals
20718
+ };
20719
+
20720
+ groups[ groupHash ] = group;
20721
+ groupsList.push( group );
20722
+
20723
+ }
20724
+
20725
+ }
20726
+
20727
+ groups[ groupHash ].faces3.push( f );
20728
+ groups[ groupHash ].vertices += 3;
20729
+
20730
+ }
20731
+
20732
+ return groupsList;
20733
+
20734
+ }
20735
+
20736
+ function initGeometryGroups( scene, object, geometry ) {
20737
+
20738
+ var material = object.material, addBuffers = false;
20739
+
20740
+ if ( geometryGroups[ geometry.id ] === undefined || geometry.groupsNeedUpdate === true ) {
20741
+
20742
+ delete _webglObjects[ object.id ];
20743
+
20744
+ geometryGroups[ geometry.id ] = makeGroups( geometry, material instanceof THREE.MeshFaceMaterial );
20745
+
20746
+ geometry.groupsNeedUpdate = false;
20747
+
20748
+ }
20749
+
20750
+ var geometryGroupsList = geometryGroups[ geometry.id ];
20751
+
20752
+ // create separate VBOs per geometry chunk
20753
+
20754
+ for ( var i = 0, il = geometryGroupsList.length; i < il; i ++ ) {
20755
+
20756
+ var geometryGroup = geometryGroupsList[ i ];
20757
+
20758
+ // initialise VBO on the first access
20759
+
20760
+ if ( geometryGroup.__webglVertexBuffer === undefined ) {
20761
+
20762
+ createMeshBuffers( geometryGroup );
20763
+ initMeshBuffers( geometryGroup, object );
20764
+
20765
+ geometry.verticesNeedUpdate = true;
20766
+ geometry.morphTargetsNeedUpdate = true;
20767
+ geometry.elementsNeedUpdate = true;
20768
+ geometry.uvsNeedUpdate = true;
20769
+ geometry.normalsNeedUpdate = true;
20770
+ geometry.tangentsNeedUpdate = true;
20771
+ geometry.colorsNeedUpdate = true;
20772
+
20773
+ addBuffers = true;
20774
+
20775
+ } else {
20776
+
20777
+ addBuffers = false;
20778
+
20779
+ }
20780
+
20781
+ if ( addBuffers || object.__webglActive === undefined ) {
20782
+
20783
+ addBuffer( _webglObjects, geometryGroup, object );
20784
+
20785
+ }
20786
+
20787
+ }
20788
+
20789
+ object.__webglActive = true;
20790
+
20791
+ }
20792
+
20793
+ function addBuffer( objlist, buffer, object ) {
20794
+
20795
+ var id = object.id;
20796
+ objlist[id] = objlist[id] || [];
20797
+ objlist[id].push(
20798
+ {
20799
+ id: id,
20800
+ buffer: buffer,
20801
+ object: object,
20802
+ material: null,
20803
+ z: 0
20804
+ }
20805
+ );
20806
+
20807
+ };
20808
+
20809
+ function addBufferImmediate( objlist, object ) {
20810
+
20811
+ objlist.push(
20812
+ {
20813
+ id: null,
20814
+ object: object,
20815
+ opaque: null,
20816
+ transparent: null,
20817
+ z: 0
20818
+ }
20819
+ );
20820
+
20821
+ };
20822
+
20823
+ // Objects updates
20824
+
20825
+ function updateObject( object, scene ) {
20826
+
20827
+ var geometry = object.geometry, customAttributesDirty, material;
20828
+
20829
+ if ( geometry instanceof THREE.BufferGeometry ) {
20830
+
20831
+ setDirectBuffers( geometry );
20832
+
20833
+ } else if ( object instanceof THREE.Mesh ) {
20834
+
20835
+ // check all geometry groups
20836
+
20837
+ if ( geometry.groupsNeedUpdate === true ) {
20838
+
20839
+ initGeometryGroups( scene, object, geometry );
20840
+
20841
+ }
20842
+
20843
+ var geometryGroupsList = geometryGroups[ geometry.id ];
20844
+
20845
+ for ( var i = 0, il = geometryGroupsList.length; i < il; i ++ ) {
20846
+
20847
+ var geometryGroup = geometryGroupsList[ i ];
20848
+
20849
+ material = getBufferMaterial( object, geometryGroup );
20850
+
20851
+ if ( geometry.groupsNeedUpdate === true ) {
20852
+
20853
+ initMeshBuffers( geometryGroup, object );
20854
+
20855
+ }
20856
+
20857
+ customAttributesDirty = material.attributes && areCustomAttributesDirty( material );
20858
+
20859
+ if ( geometry.verticesNeedUpdate || geometry.morphTargetsNeedUpdate || geometry.elementsNeedUpdate ||
20860
+ geometry.uvsNeedUpdate || geometry.normalsNeedUpdate ||
20861
+ geometry.colorsNeedUpdate || geometry.tangentsNeedUpdate || customAttributesDirty ) {
20862
+
20863
+ setMeshBuffers( geometryGroup, object, _gl.DYNAMIC_DRAW, ! geometry.dynamic, material );
20864
+
20865
+ }
20866
+
20867
+ }
20868
+
20869
+ geometry.verticesNeedUpdate = false;
20870
+ geometry.morphTargetsNeedUpdate = false;
20871
+ geometry.elementsNeedUpdate = false;
20872
+ geometry.uvsNeedUpdate = false;
20873
+ geometry.normalsNeedUpdate = false;
20874
+ geometry.colorsNeedUpdate = false;
20875
+ geometry.tangentsNeedUpdate = false;
20876
+
20877
+ material.attributes && clearCustomAttributes( material );
20878
+
20879
+ } else if ( object instanceof THREE.Line ) {
20880
+
20881
+ material = getBufferMaterial( object, geometry );
20882
+
20883
+ customAttributesDirty = material.attributes && areCustomAttributesDirty( material );
20884
+
20885
+ if ( geometry.verticesNeedUpdate || geometry.colorsNeedUpdate || geometry.lineDistancesNeedUpdate || customAttributesDirty ) {
20886
+
20887
+ setLineBuffers( geometry, _gl.DYNAMIC_DRAW );
20888
+
20889
+ }
20890
+
20891
+ geometry.verticesNeedUpdate = false;
20892
+ geometry.colorsNeedUpdate = false;
20893
+ geometry.lineDistancesNeedUpdate = false;
20894
+
20895
+ material.attributes && clearCustomAttributes( material );
20896
+
20897
+
20898
+ } else if ( object instanceof THREE.PointCloud ) {
20899
+
20900
+ material = getBufferMaterial( object, geometry );
20901
+
20902
+ customAttributesDirty = material.attributes && areCustomAttributesDirty( material );
20903
+
20904
+ if ( geometry.verticesNeedUpdate || geometry.colorsNeedUpdate || object.sortParticles || customAttributesDirty ) {
20905
+
20906
+ setParticleBuffers( geometry, _gl.DYNAMIC_DRAW, object );
20907
+
20908
+ }
20909
+
20910
+ geometry.verticesNeedUpdate = false;
20911
+ geometry.colorsNeedUpdate = false;
20912
+
20913
+ material.attributes && clearCustomAttributes( material );
20914
+
20915
+ }
20916
+
20917
+ }
20918
+
20919
+ // Objects updates - custom attributes check
20920
+
20921
+ function areCustomAttributesDirty( material ) {
20922
+
20923
+ for ( var name in material.attributes ) {
20924
+
20925
+ if ( material.attributes[ name ].needsUpdate ) return true;
20926
+
20927
+ }
20928
+
20929
+ return false;
20930
+
20931
+ }
20932
+
20933
+ function clearCustomAttributes( material ) {
20934
+
20935
+ for ( var name in material.attributes ) {
20936
+
20937
+ material.attributes[ name ].needsUpdate = false;
20938
+
20939
+ }
20940
+
20941
+ }
20942
+
20943
+ // Objects removal
20944
+
20945
+ function removeObject( object ) {
20946
+
20947
+ if ( object instanceof THREE.Mesh ||
20948
+ object instanceof THREE.PointCloud ||
20949
+ object instanceof THREE.Line ) {
20950
+
20951
+ delete _webglObjects[ object.id ];
20952
+
20953
+ } else if ( object instanceof THREE.ImmediateRenderObject || object.immediateRenderCallback ) {
20954
+
20955
+ removeInstances( _webglObjectsImmediate, object );
20956
+
20957
+ }
20958
+
20959
+ delete object.__webglInit;
20960
+ delete object._modelViewMatrix;
20961
+ delete object._normalMatrix;
20962
+
20963
+ delete object.__webglActive;
20964
+
20965
+ }
20966
+
20967
+ function removeInstances( objlist, object ) {
20968
+
20969
+ for ( var o = objlist.length - 1; o >= 0; o -- ) {
20970
+
20971
+ if ( objlist[ o ].object === object ) {
20972
+
20973
+ objlist.splice( o, 1 );
20974
+
20975
+ }
20976
+
20977
+ }
20978
+
20979
+ }
20980
+
20981
+ // Materials
20982
+
20983
+ function initMaterial( material, lights, fog, object ) {
20984
+
20985
+ material.addEventListener( 'dispose', onMaterialDispose );
20986
+
20987
+ var shaderID;
20988
+
20989
+ if ( material instanceof THREE.MeshDepthMaterial ) {
20990
+
20991
+ shaderID = 'depth';
20992
+
20993
+ } else if ( material instanceof THREE.MeshNormalMaterial ) {
20994
+
20995
+ shaderID = 'normal';
20996
+
20997
+ } else if ( material instanceof THREE.MeshBasicMaterial ) {
20998
+
20999
+ shaderID = 'basic';
21000
+
21001
+ } else if ( material instanceof THREE.MeshLambertMaterial ) {
21002
+
21003
+ shaderID = 'lambert';
21004
+
21005
+ } else if ( material instanceof THREE.MeshPhongMaterial ) {
21006
+
21007
+ shaderID = 'phong';
21008
+
21009
+ } else if ( material instanceof THREE.LineBasicMaterial ) {
21010
+
21011
+ shaderID = 'basic';
21012
+
21013
+ } else if ( material instanceof THREE.LineDashedMaterial ) {
21014
+
21015
+ shaderID = 'dashed';
21016
+
21017
+ } else if ( material instanceof THREE.PointCloudMaterial ) {
21018
+
21019
+ shaderID = 'particle_basic';
21020
+
21021
+ }
21022
+
21023
+ if ( shaderID ) {
21024
+
21025
+ var shader = THREE.ShaderLib[ shaderID ];
21026
+
21027
+ material.__webglShader = {
21028
+ uniforms: THREE.UniformsUtils.clone( shader.uniforms ),
21029
+ vertexShader: shader.vertexShader,
21030
+ fragmentShader: shader.fragmentShader
21031
+ }
21032
+
21033
+ } else {
21034
+
21035
+ material.__webglShader = {
21036
+ uniforms: material.uniforms,
21037
+ vertexShader: material.vertexShader,
21038
+ fragmentShader: material.fragmentShader
21039
+ }
21040
+
21041
+ }
21042
+
21043
+ // heuristics to create shader parameters according to lights in the scene
21044
+ // (not to blow over maxLights budget)
21045
+
21046
+ var maxLightCount = allocateLights( lights );
21047
+ var maxShadows = allocateShadows( lights );
21048
+ var maxBones = allocateBones( object );
21049
+
21050
+ var parameters = {
21051
+
21052
+ precision: _precision,
21053
+ supportsVertexTextures: _supportsVertexTextures,
21054
+
21055
+ map: !! material.map,
21056
+ envMap: !! material.envMap,
21057
+ lightMap: !! material.lightMap,
21058
+ bumpMap: !! material.bumpMap,
21059
+ normalMap: !! material.normalMap,
21060
+ specularMap: !! material.specularMap,
21061
+ alphaMap: !! material.alphaMap,
21062
+
21063
+ vertexColors: material.vertexColors,
21064
+
21065
+ fog: fog,
21066
+ useFog: material.fog,
21067
+ fogExp: fog instanceof THREE.FogExp2,
21068
+
21069
+ sizeAttenuation: material.sizeAttenuation,
21070
+ logarithmicDepthBuffer: _logarithmicDepthBuffer,
21071
+
21072
+ skinning: material.skinning,
21073
+ maxBones: maxBones,
21074
+ useVertexTexture: _supportsBoneTextures && object && object.skeleton && object.skeleton.useVertexTexture,
21075
+
21076
+ morphTargets: material.morphTargets,
21077
+ morphNormals: material.morphNormals,
21078
+ maxMorphTargets: _this.maxMorphTargets,
21079
+ maxMorphNormals: _this.maxMorphNormals,
21080
+
21081
+ maxDirLights: maxLightCount.directional,
21082
+ maxPointLights: maxLightCount.point,
21083
+ maxSpotLights: maxLightCount.spot,
21084
+ maxHemiLights: maxLightCount.hemi,
21085
+
21086
+ maxShadows: maxShadows,
21087
+ shadowMapEnabled: _this.shadowMapEnabled && object.receiveShadow && maxShadows > 0,
21088
+ shadowMapType: _this.shadowMapType,
21089
+ shadowMapDebug: _this.shadowMapDebug,
21090
+ shadowMapCascade: _this.shadowMapCascade,
21091
+
21092
+ alphaTest: material.alphaTest,
21093
+ metal: material.metal,
21094
+ wrapAround: material.wrapAround,
21095
+ doubleSided: material.side === THREE.DoubleSide,
21096
+ flipSided: material.side === THREE.BackSide
21097
+
21098
+ };
21099
+
21100
+ // Generate code
21101
+
21102
+ var chunks = [];
21103
+
21104
+ if ( shaderID ) {
21105
+
21106
+ chunks.push( shaderID );
21107
+
21108
+ } else {
21109
+
21110
+ chunks.push( material.fragmentShader );
21111
+ chunks.push( material.vertexShader );
21112
+
21113
+ }
21114
+
21115
+ if ( material.defines !== undefined ) {
21116
+
21117
+ for ( var name in material.defines ) {
21118
+
21119
+ chunks.push( name );
21120
+ chunks.push( material.defines[ name ] );
21121
+
21122
+ }
21123
+
21124
+ }
21125
+
21126
+ for ( var name in parameters ) {
21127
+
21128
+ chunks.push( name );
21129
+ chunks.push( parameters[ name ] );
21130
+
21131
+ }
21132
+
21133
+ var code = chunks.join();
21134
+
21135
+ var program;
21136
+
21137
+ // Check if code has been already compiled
21138
+
21139
+ for ( var p = 0, pl = _programs.length; p < pl; p ++ ) {
21140
+
21141
+ var programInfo = _programs[ p ];
21142
+
21143
+ if ( programInfo.code === code ) {
21144
+
21145
+ program = programInfo;
21146
+ program.usedTimes ++;
21147
+
21148
+ break;
21149
+
21150
+ }
21151
+
21152
+ }
21153
+
21154
+ if ( program === undefined ) {
21155
+
21156
+ program = new THREE.WebGLProgram( _this, code, material, parameters );
21157
+ _programs.push( program );
21158
+
21159
+ _this.info.memory.programs = _programs.length;
21160
+
21161
+ }
21162
+
21163
+ material.program = program;
21164
+
21165
+ var attributes = program.attributes;
21166
+
21167
+ if ( material.morphTargets ) {
21168
+
21169
+ material.numSupportedMorphTargets = 0;
21170
+
21171
+ var id, base = 'morphTarget';
21172
+
21173
+ for ( var i = 0; i < _this.maxMorphTargets; i ++ ) {
21174
+
21175
+ id = base + i;
21176
+
21177
+ if ( attributes[ id ] >= 0 ) {
21178
+
21179
+ material.numSupportedMorphTargets ++;
21180
+
21181
+ }
21182
+
21183
+ }
21184
+
21185
+ }
21186
+
21187
+ if ( material.morphNormals ) {
21188
+
21189
+ material.numSupportedMorphNormals = 0;
21190
+
21191
+ var id, base = 'morphNormal';
21192
+
21193
+ for ( i = 0; i < _this.maxMorphNormals; i ++ ) {
21194
+
21195
+ id = base + i;
21196
+
21197
+ if ( attributes[ id ] >= 0 ) {
21198
+
21199
+ material.numSupportedMorphNormals ++;
21200
+
21201
+ }
21202
+
21203
+ }
21204
+
21205
+ }
21206
+
21207
+ material.uniformsList = [];
21208
+
21209
+ for ( var u in material.__webglShader.uniforms ) {
21210
+
21211
+ var location = material.program.uniforms[ u ];
21212
+
21213
+ if ( location ) {
21214
+ material.uniformsList.push( [ material.__webglShader.uniforms[ u ], location ] );
21215
+ }
21216
+
21217
+ }
21218
+
21219
+ }
21220
+
21221
+ function setProgram( camera, lights, fog, material, object ) {
21222
+
21223
+ _usedTextureUnits = 0;
21224
+
21225
+ if ( material.needsUpdate ) {
21226
+
21227
+ if ( material.program ) deallocateMaterial( material );
21228
+
21229
+ initMaterial( material, lights, fog, object );
21230
+ material.needsUpdate = false;
21231
+
21232
+ }
21233
+
21234
+ if ( material.morphTargets ) {
21235
+
21236
+ if ( ! object.__webglMorphTargetInfluences ) {
21237
+
21238
+ object.__webglMorphTargetInfluences = new Float32Array( _this.maxMorphTargets );
21239
+
21240
+ }
21241
+
21242
+ }
21243
+
21244
+ var refreshProgram = false;
21245
+ var refreshMaterial = false;
21246
+ var refreshLights = false;
21247
+
21248
+ var program = material.program,
21249
+ p_uniforms = program.uniforms,
21250
+ m_uniforms = material.__webglShader.uniforms;
21251
+
21252
+ if ( program.id !== _currentProgram ) {
21253
+
21254
+ _gl.useProgram( program.program );
21255
+ _currentProgram = program.id;
21256
+
21257
+ refreshProgram = true;
21258
+ refreshMaterial = true;
21259
+ refreshLights = true;
21260
+
21261
+ }
21262
+
21263
+ if ( material.id !== _currentMaterialId ) {
21264
+
21265
+ if ( _currentMaterialId === -1 ) refreshLights = true;
21266
+ _currentMaterialId = material.id;
21267
+
21268
+ refreshMaterial = true;
21269
+
21270
+ }
21271
+
21272
+ if ( refreshProgram || camera !== _currentCamera ) {
21273
+
21274
+ _gl.uniformMatrix4fv( p_uniforms.projectionMatrix, false, camera.projectionMatrix.elements );
21275
+
21276
+ if ( _logarithmicDepthBuffer ) {
21277
+
21278
+ _gl.uniform1f( p_uniforms.logDepthBufFC, 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) );
21279
+
21280
+ }
21281
+
21282
+
21283
+ if ( camera !== _currentCamera ) _currentCamera = camera;
21284
+
21285
+ // load material specific uniforms
21286
+ // (shader material also gets them for the sake of genericity)
21287
+
21288
+ if ( material instanceof THREE.ShaderMaterial ||
21289
+ material instanceof THREE.MeshPhongMaterial ||
21290
+ material.envMap ) {
21291
+
21292
+ if ( p_uniforms.cameraPosition !== null ) {
21293
+
21294
+ _vector3.setFromMatrixPosition( camera.matrixWorld );
21295
+ _gl.uniform3f( p_uniforms.cameraPosition, _vector3.x, _vector3.y, _vector3.z );
21296
+
21297
+ }
21298
+
21299
+ }
21300
+
21301
+ if ( material instanceof THREE.MeshPhongMaterial ||
21302
+ material instanceof THREE.MeshLambertMaterial ||
21303
+ material instanceof THREE.ShaderMaterial ||
21304
+ material.skinning ) {
21305
+
21306
+ if ( p_uniforms.viewMatrix !== null ) {
21307
+
21308
+ _gl.uniformMatrix4fv( p_uniforms.viewMatrix, false, camera.matrixWorldInverse.elements );
21309
+
21310
+ }
21311
+
21312
+ }
21313
+
21314
+ }
21315
+
21316
+ // skinning uniforms must be set even if material didn't change
21317
+ // auto-setting of texture unit for bone texture must go before other textures
21318
+ // not sure why, but otherwise weird things happen
21319
+
21320
+ if ( material.skinning ) {
21321
+
21322
+ if ( object.bindMatrix && p_uniforms.bindMatrix !== null ) {
21323
+
21324
+ _gl.uniformMatrix4fv( p_uniforms.bindMatrix, false, object.bindMatrix.elements );
21325
+
21326
+ }
21327
+
21328
+ if ( object.bindMatrixInverse && p_uniforms.bindMatrixInverse !== null ) {
21329
+
21330
+ _gl.uniformMatrix4fv( p_uniforms.bindMatrixInverse, false, object.bindMatrixInverse.elements );
21331
+
21332
+ }
21333
+
21334
+ if ( _supportsBoneTextures && object.skeleton && object.skeleton.useVertexTexture ) {
21335
+
21336
+ if ( p_uniforms.boneTexture !== null ) {
21337
+
21338
+ var textureUnit = getTextureUnit();
21339
+
21340
+ _gl.uniform1i( p_uniforms.boneTexture, textureUnit );
21341
+ _this.setTexture( object.skeleton.boneTexture, textureUnit );
21342
+
21343
+ }
21344
+
21345
+ if ( p_uniforms.boneTextureWidth !== null ) {
21346
+
21347
+ _gl.uniform1i( p_uniforms.boneTextureWidth, object.skeleton.boneTextureWidth );
21348
+
21349
+ }
21350
+
21351
+ if ( p_uniforms.boneTextureHeight !== null ) {
21352
+
21353
+ _gl.uniform1i( p_uniforms.boneTextureHeight, object.skeleton.boneTextureHeight );
21354
+
21355
+ }
21356
+
21357
+ } else if ( object.skeleton && object.skeleton.boneMatrices ) {
21358
+
21359
+ if ( p_uniforms.boneGlobalMatrices !== null ) {
21360
+
21361
+ _gl.uniformMatrix4fv( p_uniforms.boneGlobalMatrices, false, object.skeleton.boneMatrices );
21362
+
21363
+ }
21364
+
21365
+ }
21366
+
21367
+ }
21368
+
21369
+ if ( refreshMaterial ) {
21370
+
21371
+ // refresh uniforms common to several materials
21372
+
21373
+ if ( fog && material.fog ) {
21374
+
21375
+ refreshUniformsFog( m_uniforms, fog );
21376
+
21377
+ }
21378
+
21379
+ if ( material instanceof THREE.MeshPhongMaterial ||
21380
+ material instanceof THREE.MeshLambertMaterial ||
21381
+ material.lights ) {
21382
+
21383
+ if ( _lightsNeedUpdate ) {
21384
+
21385
+ refreshLights = true;
21386
+ setupLights( lights );
21387
+ _lightsNeedUpdate = false;
21388
+ }
21389
+
21390
+ if ( refreshLights ) {
21391
+ refreshUniformsLights( m_uniforms, _lights );
21392
+ markUniformsLightsNeedsUpdate( m_uniforms, true );
21393
+ } else {
21394
+ markUniformsLightsNeedsUpdate( m_uniforms, false );
21395
+ }
21396
+
21397
+ }
21398
+
21399
+ if ( material instanceof THREE.MeshBasicMaterial ||
21400
+ material instanceof THREE.MeshLambertMaterial ||
21401
+ material instanceof THREE.MeshPhongMaterial ) {
21402
+
21403
+ refreshUniformsCommon( m_uniforms, material );
21404
+
21405
+ }
21406
+
21407
+ // refresh single material specific uniforms
21408
+
21409
+ if ( material instanceof THREE.LineBasicMaterial ) {
21410
+
21411
+ refreshUniformsLine( m_uniforms, material );
21412
+
21413
+ } else if ( material instanceof THREE.LineDashedMaterial ) {
21414
+
21415
+ refreshUniformsLine( m_uniforms, material );
21416
+ refreshUniformsDash( m_uniforms, material );
21417
+
21418
+ } else if ( material instanceof THREE.PointCloudMaterial ) {
21419
+
21420
+ refreshUniformsParticle( m_uniforms, material );
21421
+
21422
+ } else if ( material instanceof THREE.MeshPhongMaterial ) {
21423
+
21424
+ refreshUniformsPhong( m_uniforms, material );
21425
+
21426
+ } else if ( material instanceof THREE.MeshLambertMaterial ) {
21427
+
21428
+ refreshUniformsLambert( m_uniforms, material );
21429
+
21430
+ } else if ( material instanceof THREE.MeshDepthMaterial ) {
21431
+
21432
+ m_uniforms.mNear.value = camera.near;
21433
+ m_uniforms.mFar.value = camera.far;
21434
+ m_uniforms.opacity.value = material.opacity;
21435
+
21436
+ } else if ( material instanceof THREE.MeshNormalMaterial ) {
21437
+
21438
+ m_uniforms.opacity.value = material.opacity;
21439
+
21440
+ }
21441
+
21442
+ if ( object.receiveShadow && ! material._shadowPass ) {
21443
+
21444
+ refreshUniformsShadow( m_uniforms, lights );
21445
+
21446
+ }
21447
+
21448
+ // load common uniforms
21449
+
21450
+ loadUniformsGeneric( material.uniformsList );
21451
+
21452
+ }
21453
+
21454
+ loadUniformsMatrices( p_uniforms, object );
21455
+
21456
+ if ( p_uniforms.modelMatrix !== null ) {
21457
+
21458
+ _gl.uniformMatrix4fv( p_uniforms.modelMatrix, false, object.matrixWorld.elements );
21459
+
21460
+ }
21461
+
21462
+ return program;
21463
+
21464
+ }
21465
+
21466
+ // Uniforms (refresh uniforms objects)
21467
+
21468
+ function refreshUniformsCommon ( uniforms, material ) {
21469
+
21470
+ uniforms.opacity.value = material.opacity;
21471
+
21472
+ if ( _this.gammaInput ) {
21473
+
21474
+ uniforms.diffuse.value.copyGammaToLinear( material.color );
21475
+
21476
+ } else {
21477
+
21478
+ uniforms.diffuse.value = material.color;
21479
+
21480
+ }
21481
+
21482
+ uniforms.map.value = material.map;
21483
+ uniforms.lightMap.value = material.lightMap;
21484
+ uniforms.specularMap.value = material.specularMap;
21485
+ uniforms.alphaMap.value = material.alphaMap;
21486
+
21487
+ if ( material.bumpMap ) {
21488
+
21489
+ uniforms.bumpMap.value = material.bumpMap;
21490
+ uniforms.bumpScale.value = material.bumpScale;
21491
+
21492
+ }
21493
+
21494
+ if ( material.normalMap ) {
21495
+
21496
+ uniforms.normalMap.value = material.normalMap;
21497
+ uniforms.normalScale.value.copy( material.normalScale );
21498
+
21499
+ }
21500
+
21501
+ // uv repeat and offset setting priorities
21502
+ // 1. color map
21503
+ // 2. specular map
21504
+ // 3. normal map
21505
+ // 4. bump map
21506
+ // 5. alpha map
21507
+
21508
+ var uvScaleMap;
21509
+
21510
+ if ( material.map ) {
21511
+
21512
+ uvScaleMap = material.map;
21513
+
21514
+ } else if ( material.specularMap ) {
21515
+
21516
+ uvScaleMap = material.specularMap;
21517
+
21518
+ } else if ( material.normalMap ) {
21519
+
21520
+ uvScaleMap = material.normalMap;
21521
+
21522
+ } else if ( material.bumpMap ) {
21523
+
21524
+ uvScaleMap = material.bumpMap;
21525
+
21526
+ } else if ( material.alphaMap ) {
21527
+
21528
+ uvScaleMap = material.alphaMap;
21529
+
21530
+ }
21531
+
21532
+ if ( uvScaleMap !== undefined ) {
21533
+
21534
+ var offset = uvScaleMap.offset;
21535
+ var repeat = uvScaleMap.repeat;
21536
+
21537
+ uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
21538
+
21539
+ }
21540
+
21541
+ uniforms.envMap.value = material.envMap;
21542
+ uniforms.flipEnvMap.value = ( material.envMap instanceof THREE.WebGLRenderTargetCube ) ? 1 : - 1;
21543
+
21544
+ if ( _this.gammaInput ) {
21545
+
21546
+ //uniforms.reflectivity.value = material.reflectivity * material.reflectivity;
21547
+ uniforms.reflectivity.value = material.reflectivity;
21548
+
21549
+ } else {
21550
+
21551
+ uniforms.reflectivity.value = material.reflectivity;
21552
+
21553
+ }
21554
+
21555
+ uniforms.refractionRatio.value = material.refractionRatio;
21556
+ uniforms.combine.value = material.combine;
21557
+ uniforms.useRefract.value = material.envMap && material.envMap.mapping instanceof THREE.CubeRefractionMapping;
21558
+
21559
+ }
21560
+
21561
+ function refreshUniformsLine ( uniforms, material ) {
21562
+
21563
+ uniforms.diffuse.value = material.color;
21564
+ uniforms.opacity.value = material.opacity;
21565
+
21566
+ }
21567
+
21568
+ function refreshUniformsDash ( uniforms, material ) {
21569
+
21570
+ uniforms.dashSize.value = material.dashSize;
21571
+ uniforms.totalSize.value = material.dashSize + material.gapSize;
21572
+ uniforms.scale.value = material.scale;
21573
+
21574
+ }
21575
+
21576
+ function refreshUniformsParticle ( uniforms, material ) {
21577
+
21578
+ uniforms.psColor.value = material.color;
21579
+ uniforms.opacity.value = material.opacity;
21580
+ uniforms.size.value = material.size;
21581
+ uniforms.scale.value = _canvas.height / 2.0; // TODO: Cache this.
21582
+
21583
+ uniforms.map.value = material.map;
21584
+
21585
+ }
21586
+
21587
+ function refreshUniformsFog ( uniforms, fog ) {
21588
+
21589
+ uniforms.fogColor.value = fog.color;
21590
+
21591
+ if ( fog instanceof THREE.Fog ) {
21592
+
21593
+ uniforms.fogNear.value = fog.near;
21594
+ uniforms.fogFar.value = fog.far;
21595
+
21596
+ } else if ( fog instanceof THREE.FogExp2 ) {
21597
+
21598
+ uniforms.fogDensity.value = fog.density;
21599
+
21600
+ }
21601
+
21602
+ }
21603
+
21604
+ function refreshUniformsPhong ( uniforms, material ) {
21605
+
21606
+ uniforms.shininess.value = material.shininess;
21607
+
21608
+ if ( _this.gammaInput ) {
21609
+
21610
+ uniforms.ambient.value.copyGammaToLinear( material.ambient );
21611
+ uniforms.emissive.value.copyGammaToLinear( material.emissive );
21612
+ uniforms.specular.value.copyGammaToLinear( material.specular );
21613
+
21614
+ } else {
21615
+
21616
+ uniforms.ambient.value = material.ambient;
21617
+ uniforms.emissive.value = material.emissive;
21618
+ uniforms.specular.value = material.specular;
21619
+
21620
+ }
21621
+
21622
+ if ( material.wrapAround ) {
21623
+
21624
+ uniforms.wrapRGB.value.copy( material.wrapRGB );
21625
+
21626
+ }
21627
+
21628
+ }
21629
+
21630
+ function refreshUniformsLambert ( uniforms, material ) {
21631
+
21632
+ if ( _this.gammaInput ) {
21633
+
21634
+ uniforms.ambient.value.copyGammaToLinear( material.ambient );
21635
+ uniforms.emissive.value.copyGammaToLinear( material.emissive );
21636
+
21637
+ } else {
21638
+
21639
+ uniforms.ambient.value = material.ambient;
21640
+ uniforms.emissive.value = material.emissive;
21641
+
21642
+ }
21643
+
21644
+ if ( material.wrapAround ) {
21645
+
21646
+ uniforms.wrapRGB.value.copy( material.wrapRGB );
21647
+
21648
+ }
21649
+
21650
+ }
21651
+
21652
+ function refreshUniformsLights ( uniforms, lights ) {
21653
+
21654
+ uniforms.ambientLightColor.value = lights.ambient;
21655
+
21656
+ uniforms.directionalLightColor.value = lights.directional.colors;
21657
+ uniforms.directionalLightDirection.value = lights.directional.positions;
21658
+
21659
+ uniforms.pointLightColor.value = lights.point.colors;
21660
+ uniforms.pointLightPosition.value = lights.point.positions;
21661
+ uniforms.pointLightDistance.value = lights.point.distances;
21662
+
21663
+ uniforms.spotLightColor.value = lights.spot.colors;
21664
+ uniforms.spotLightPosition.value = lights.spot.positions;
21665
+ uniforms.spotLightDistance.value = lights.spot.distances;
21666
+ uniforms.spotLightDirection.value = lights.spot.directions;
21667
+ uniforms.spotLightAngleCos.value = lights.spot.anglesCos;
21668
+ uniforms.spotLightExponent.value = lights.spot.exponents;
21669
+
21670
+ uniforms.hemisphereLightSkyColor.value = lights.hemi.skyColors;
21671
+ uniforms.hemisphereLightGroundColor.value = lights.hemi.groundColors;
21672
+ uniforms.hemisphereLightDirection.value = lights.hemi.positions;
21673
+
21674
+ }
21675
+
21676
+ // If uniforms are marked as clean, they don't need to be loaded to the GPU.
21677
+
21678
+ function markUniformsLightsNeedsUpdate ( uniforms, boolean ) {
21679
+
21680
+ uniforms.ambientLightColor.needsUpdate = boolean;
21681
+
21682
+ uniforms.directionalLightColor.needsUpdate = boolean;
21683
+ uniforms.directionalLightDirection.needsUpdate = boolean;
21684
+
21685
+ uniforms.pointLightColor.needsUpdate = boolean;
21686
+ uniforms.pointLightPosition.needsUpdate = boolean;
21687
+ uniforms.pointLightDistance.needsUpdate = boolean;
21688
+
21689
+ uniforms.spotLightColor.needsUpdate = boolean;
21690
+ uniforms.spotLightPosition.needsUpdate = boolean;
21691
+ uniforms.spotLightDistance.needsUpdate = boolean;
21692
+ uniforms.spotLightDirection.needsUpdate = boolean;
21693
+ uniforms.spotLightAngleCos.needsUpdate = boolean;
21694
+ uniforms.spotLightExponent.needsUpdate = boolean;
21695
+
21696
+ uniforms.hemisphereLightSkyColor.needsUpdate = boolean;
21697
+ uniforms.hemisphereLightGroundColor.needsUpdate = boolean;
21698
+ uniforms.hemisphereLightDirection.needsUpdate = boolean;
21699
+
21700
+ }
21701
+
21702
+ function refreshUniformsShadow ( uniforms, lights ) {
21703
+
21704
+ if ( uniforms.shadowMatrix ) {
21705
+
21706
+ var j = 0;
21707
+
21708
+ for ( var i = 0, il = lights.length; i < il; i ++ ) {
21709
+
21710
+ var light = lights[ i ];
21711
+
21712
+ if ( ! light.castShadow ) continue;
21713
+
21714
+ if ( light instanceof THREE.SpotLight || ( light instanceof THREE.DirectionalLight && ! light.shadowCascade ) ) {
21715
+
21716
+ uniforms.shadowMap.value[ j ] = light.shadowMap;
21717
+ uniforms.shadowMapSize.value[ j ] = light.shadowMapSize;
21718
+
21719
+ uniforms.shadowMatrix.value[ j ] = light.shadowMatrix;
21720
+
21721
+ uniforms.shadowDarkness.value[ j ] = light.shadowDarkness;
21722
+ uniforms.shadowBias.value[ j ] = light.shadowBias;
21723
+
21724
+ j ++;
21725
+
21726
+ }
21727
+
21728
+ }
21729
+
21730
+ }
21731
+
21732
+ }
21733
+
21734
+ // Uniforms (load to GPU)
21735
+
21736
+ function loadUniformsMatrices ( uniforms, object ) {
21737
+
21738
+ _gl.uniformMatrix4fv( uniforms.modelViewMatrix, false, object._modelViewMatrix.elements );
21739
+
21740
+ if ( uniforms.normalMatrix ) {
21741
+
21742
+ _gl.uniformMatrix3fv( uniforms.normalMatrix, false, object._normalMatrix.elements );
21743
+
21744
+ }
21745
+
21746
+ }
21747
+
21748
+ function getTextureUnit() {
21749
+
21750
+ var textureUnit = _usedTextureUnits;
21751
+
21752
+ if ( textureUnit >= _maxTextures ) {
21753
+
21754
+ console.warn( 'WebGLRenderer: trying to use ' + textureUnit + ' texture units while this GPU supports only ' + _maxTextures );
21755
+
21756
+ }
21757
+
21758
+ _usedTextureUnits += 1;
21759
+
21760
+ return textureUnit;
21761
+
21762
+ }
21763
+
21764
+ function loadUniformsGeneric ( uniforms ) {
21765
+
21766
+ var texture, textureUnit, offset;
21767
+
21768
+ for ( var j = 0, jl = uniforms.length; j < jl; j ++ ) {
21769
+
21770
+ var uniform = uniforms[ j ][ 0 ];
21771
+
21772
+ // needsUpdate property is not added to all uniforms.
21773
+ if ( uniform.needsUpdate === false ) continue;
21774
+
21775
+ var type = uniform.type;
21776
+ var value = uniform.value;
21777
+ var location = uniforms[ j ][ 1 ];
21778
+
21779
+ switch ( type ) {
21780
+
21781
+ case '1i':
21782
+ _gl.uniform1i( location, value );
21783
+ break;
21784
+
21785
+ case '1f':
21786
+ _gl.uniform1f( location, value );
21787
+ break;
21788
+
21789
+ case '2f':
21790
+ _gl.uniform2f( location, value[ 0 ], value[ 1 ] );
21791
+ break;
21792
+
21793
+ case '3f':
21794
+ _gl.uniform3f( location, value[ 0 ], value[ 1 ], value[ 2 ] );
21795
+ break;
21796
+
21797
+ case '4f':
21798
+ _gl.uniform4f( location, value[ 0 ], value[ 1 ], value[ 2 ], value[ 3 ] );
21799
+ break;
21800
+
21801
+ case '1iv':
21802
+ _gl.uniform1iv( location, value );
21803
+ break;
21804
+
21805
+ case '3iv':
21806
+ _gl.uniform3iv( location, value );
21807
+ break;
21808
+
21809
+ case '1fv':
21810
+ _gl.uniform1fv( location, value );
21811
+ break;
21812
+
21813
+ case '2fv':
21814
+ _gl.uniform2fv( location, value );
21815
+ break;
21816
+
21817
+ case '3fv':
21818
+ _gl.uniform3fv( location, value );
21819
+ break;
21820
+
21821
+ case '4fv':
21822
+ _gl.uniform4fv( location, value );
21823
+ break;
21824
+
21825
+ case 'Matrix3fv':
21826
+ _gl.uniformMatrix3fv( location, false, value );
21827
+ break;
21828
+
21829
+ case 'Matrix4fv':
21830
+ _gl.uniformMatrix4fv( location, false, value );
21831
+ break;
21832
+
21833
+ //
21834
+
21835
+ case 'i':
21836
+
21837
+ // single integer
21838
+ _gl.uniform1i( location, value );
21839
+
21840
+ break;
21841
+
21842
+ case 'f':
21843
+
21844
+ // single float
21845
+ _gl.uniform1f( location, value );
21846
+
21847
+ break;
21848
+
21849
+ case 'v2':
21850
+
21851
+ // single THREE.Vector2
21852
+ _gl.uniform2f( location, value.x, value.y );
21853
+
21854
+ break;
21855
+
21856
+ case 'v3':
21857
+
21858
+ // single THREE.Vector3
21859
+ _gl.uniform3f( location, value.x, value.y, value.z );
21860
+
21861
+ break;
21862
+
21863
+ case 'v4':
21864
+
21865
+ // single THREE.Vector4
21866
+ _gl.uniform4f( location, value.x, value.y, value.z, value.w );
21867
+
21868
+ break;
21869
+
21870
+ case 'c':
21871
+
21872
+ // single THREE.Color
21873
+ _gl.uniform3f( location, value.r, value.g, value.b );
21874
+
21875
+ break;
21876
+
21877
+ case 'iv1':
21878
+
21879
+ // flat array of integers (JS or typed array)
21880
+ _gl.uniform1iv( location, value );
21881
+
21882
+ break;
21883
+
21884
+ case 'iv':
21885
+
21886
+ // flat array of integers with 3 x N size (JS or typed array)
21887
+ _gl.uniform3iv( location, value );
21888
+
21889
+ break;
21890
+
21891
+ case 'fv1':
21892
+
21893
+ // flat array of floats (JS or typed array)
21894
+ _gl.uniform1fv( location, value );
21895
+
21896
+ break;
21897
+
21898
+ case 'fv':
21899
+
21900
+ // flat array of floats with 3 x N size (JS or typed array)
21901
+ _gl.uniform3fv( location, value );
21902
+
21903
+ break;
21904
+
21905
+ case 'v2v':
21906
+
21907
+ // array of THREE.Vector2
21908
+
21909
+ if ( uniform._array === undefined ) {
21910
+
21911
+ uniform._array = new Float32Array( 2 * value.length );
21912
+
21913
+ }
21914
+
21915
+ for ( var i = 0, il = value.length; i < il; i ++ ) {
21916
+
21917
+ offset = i * 2;
21918
+
21919
+ uniform._array[ offset ] = value[ i ].x;
21920
+ uniform._array[ offset + 1 ] = value[ i ].y;
21921
+
21922
+ }
21923
+
21924
+ _gl.uniform2fv( location, uniform._array );
21925
+
21926
+ break;
21927
+
21928
+ case 'v3v':
21929
+
21930
+ // array of THREE.Vector3
21931
+
21932
+ if ( uniform._array === undefined ) {
21933
+
21934
+ uniform._array = new Float32Array( 3 * value.length );
21935
+
21936
+ }
21937
+
21938
+ for ( var i = 0, il = value.length; i < il; i ++ ) {
21939
+
21940
+ offset = i * 3;
21941
+
21942
+ uniform._array[ offset ] = value[ i ].x;
21943
+ uniform._array[ offset + 1 ] = value[ i ].y;
21944
+ uniform._array[ offset + 2 ] = value[ i ].z;
21945
+
21946
+ }
21947
+
21948
+ _gl.uniform3fv( location, uniform._array );
21949
+
21950
+ break;
21951
+
21952
+ case 'v4v':
21953
+
21954
+ // array of THREE.Vector4
21955
+
21956
+ if ( uniform._array === undefined ) {
21957
+
21958
+ uniform._array = new Float32Array( 4 * value.length );
21959
+
21960
+ }
21961
+
21962
+ for ( var i = 0, il = value.length; i < il; i ++ ) {
21963
+
21964
+ offset = i * 4;
21965
+
21966
+ uniform._array[ offset ] = value[ i ].x;
21967
+ uniform._array[ offset + 1 ] = value[ i ].y;
21968
+ uniform._array[ offset + 2 ] = value[ i ].z;
21969
+ uniform._array[ offset + 3 ] = value[ i ].w;
21970
+
21971
+ }
21972
+
21973
+ _gl.uniform4fv( location, uniform._array );
21974
+
21975
+ break;
21976
+
21977
+ case 'm3':
21978
+
21979
+ // single THREE.Matrix3
21980
+ _gl.uniformMatrix3fv( location, false, value.elements );
21981
+
21982
+ break;
21983
+
21984
+ case 'm3v':
21985
+
21986
+ // array of THREE.Matrix3
21987
+
21988
+ if ( uniform._array === undefined ) {
21989
+
21990
+ uniform._array = new Float32Array( 9 * value.length );
21991
+
21992
+ }
21993
+
21994
+ for ( var i = 0, il = value.length; i < il; i ++ ) {
21995
+
21996
+ value[ i ].flattenToArrayOffset( uniform._array, i * 9 );
21997
+
21998
+ }
21999
+
22000
+ _gl.uniformMatrix3fv( location, false, uniform._array );
22001
+
22002
+ break;
22003
+
22004
+ case 'm4':
22005
+
22006
+ // single THREE.Matrix4
22007
+ _gl.uniformMatrix4fv( location, false, value.elements );
22008
+
22009
+ break;
22010
+
22011
+ case 'm4v':
22012
+
22013
+ // array of THREE.Matrix4
22014
+
22015
+ if ( uniform._array === undefined ) {
22016
+
22017
+ uniform._array = new Float32Array( 16 * value.length );
22018
+
22019
+ }
22020
+
22021
+ for ( var i = 0, il = value.length; i < il; i ++ ) {
22022
+
22023
+ value[ i ].flattenToArrayOffset( uniform._array, i * 16 );
22024
+
22025
+ }
22026
+
22027
+ _gl.uniformMatrix4fv( location, false, uniform._array );
22028
+
22029
+ break;
22030
+
22031
+ case 't':
22032
+
22033
+ // single THREE.Texture (2d or cube)
22034
+
22035
+ texture = value;
22036
+ textureUnit = getTextureUnit();
22037
+
22038
+ _gl.uniform1i( location, textureUnit );
22039
+
22040
+ if ( ! texture ) continue;
22041
+
22042
+ if ( texture instanceof THREE.CubeTexture ||
22043
+ ( texture.image instanceof Array && texture.image.length === 6 ) ) { // CompressedTexture can have Array in image :/
22044
+
22045
+ setCubeTexture( texture, textureUnit );
22046
+
22047
+ } else if ( texture instanceof THREE.WebGLRenderTargetCube ) {
22048
+
22049
+ setCubeTextureDynamic( texture, textureUnit );
22050
+
22051
+ } else {
22052
+
22053
+ _this.setTexture( texture, textureUnit );
22054
+
22055
+ }
22056
+
22057
+ break;
22058
+
22059
+ case 'tv':
22060
+
22061
+ // array of THREE.Texture (2d)
22062
+
22063
+ if ( uniform._array === undefined ) {
22064
+
22065
+ uniform._array = [];
22066
+
22067
+ }
22068
+
22069
+ for ( var i = 0, il = uniform.value.length; i < il; i ++ ) {
22070
+
22071
+ uniform._array[ i ] = getTextureUnit();
22072
+
22073
+ }
22074
+
22075
+ _gl.uniform1iv( location, uniform._array );
22076
+
22077
+ for ( var i = 0, il = uniform.value.length; i < il; i ++ ) {
22078
+
22079
+ texture = uniform.value[ i ];
22080
+ textureUnit = uniform._array[ i ];
22081
+
22082
+ if ( ! texture ) continue;
22083
+
22084
+ _this.setTexture( texture, textureUnit );
22085
+
22086
+ }
22087
+
22088
+ break;
22089
+
22090
+ default:
22091
+
22092
+ console.warn( 'THREE.WebGLRenderer: Unknown uniform type: ' + type );
22093
+
22094
+ }
22095
+
22096
+ }
22097
+
22098
+ }
22099
+
22100
+ function setupMatrices ( object, camera ) {
22101
+
22102
+ object._modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
22103
+ object._normalMatrix.getNormalMatrix( object._modelViewMatrix );
22104
+
22105
+ }
22106
+
22107
+ //
22108
+
22109
+ function setColorGamma( array, offset, color, intensitySq ) {
22110
+
22111
+ array[ offset ] = color.r * color.r * intensitySq;
22112
+ array[ offset + 1 ] = color.g * color.g * intensitySq;
22113
+ array[ offset + 2 ] = color.b * color.b * intensitySq;
22114
+
22115
+ }
22116
+
22117
+ function setColorLinear( array, offset, color, intensity ) {
22118
+
22119
+ array[ offset ] = color.r * intensity;
22120
+ array[ offset + 1 ] = color.g * intensity;
22121
+ array[ offset + 2 ] = color.b * intensity;
22122
+
22123
+ }
22124
+
22125
+ function setupLights ( lights ) {
22126
+
22127
+ var l, ll, light, n,
22128
+ r = 0, g = 0, b = 0,
22129
+ color, skyColor, groundColor,
22130
+ intensity, intensitySq,
22131
+ position,
22132
+ distance,
22133
+
22134
+ zlights = _lights,
22135
+
22136
+ dirColors = zlights.directional.colors,
22137
+ dirPositions = zlights.directional.positions,
22138
+
22139
+ pointColors = zlights.point.colors,
22140
+ pointPositions = zlights.point.positions,
22141
+ pointDistances = zlights.point.distances,
22142
+
22143
+ spotColors = zlights.spot.colors,
22144
+ spotPositions = zlights.spot.positions,
22145
+ spotDistances = zlights.spot.distances,
22146
+ spotDirections = zlights.spot.directions,
22147
+ spotAnglesCos = zlights.spot.anglesCos,
22148
+ spotExponents = zlights.spot.exponents,
22149
+
22150
+ hemiSkyColors = zlights.hemi.skyColors,
22151
+ hemiGroundColors = zlights.hemi.groundColors,
22152
+ hemiPositions = zlights.hemi.positions,
22153
+
22154
+ dirLength = 0,
22155
+ pointLength = 0,
22156
+ spotLength = 0,
22157
+ hemiLength = 0,
22158
+
22159
+ dirCount = 0,
22160
+ pointCount = 0,
22161
+ spotCount = 0,
22162
+ hemiCount = 0,
22163
+
22164
+ dirOffset = 0,
22165
+ pointOffset = 0,
22166
+ spotOffset = 0,
22167
+ hemiOffset = 0;
22168
+
22169
+ for ( l = 0, ll = lights.length; l < ll; l ++ ) {
22170
+
22171
+ light = lights[ l ];
22172
+
22173
+ if ( light.onlyShadow ) continue;
22174
+
22175
+ color = light.color;
22176
+ intensity = light.intensity;
22177
+ distance = light.distance;
22178
+
22179
+ if ( light instanceof THREE.AmbientLight ) {
22180
+
22181
+ if ( ! light.visible ) continue;
22182
+
22183
+ if ( _this.gammaInput ) {
22184
+
22185
+ r += color.r * color.r;
22186
+ g += color.g * color.g;
22187
+ b += color.b * color.b;
22188
+
22189
+ } else {
22190
+
22191
+ r += color.r;
22192
+ g += color.g;
22193
+ b += color.b;
22194
+
22195
+ }
22196
+
22197
+ } else if ( light instanceof THREE.DirectionalLight ) {
22198
+
22199
+ dirCount += 1;
22200
+
22201
+ if ( ! light.visible ) continue;
22202
+
22203
+ _direction.setFromMatrixPosition( light.matrixWorld );
22204
+ _vector3.setFromMatrixPosition( light.target.matrixWorld );
22205
+ _direction.sub( _vector3 );
22206
+ _direction.normalize();
22207
+
22208
+ dirOffset = dirLength * 3;
22209
+
22210
+ dirPositions[ dirOffset ] = _direction.x;
22211
+ dirPositions[ dirOffset + 1 ] = _direction.y;
22212
+ dirPositions[ dirOffset + 2 ] = _direction.z;
22213
+
22214
+ if ( _this.gammaInput ) {
22215
+
22216
+ setColorGamma( dirColors, dirOffset, color, intensity * intensity );
22217
+
22218
+ } else {
22219
+
22220
+ setColorLinear( dirColors, dirOffset, color, intensity );
22221
+
22222
+ }
22223
+
22224
+ dirLength += 1;
22225
+
22226
+ } else if ( light instanceof THREE.PointLight ) {
22227
+
22228
+ pointCount += 1;
22229
+
22230
+ if ( ! light.visible ) continue;
22231
+
22232
+ pointOffset = pointLength * 3;
22233
+
22234
+ if ( _this.gammaInput ) {
22235
+
22236
+ setColorGamma( pointColors, pointOffset, color, intensity * intensity );
22237
+
22238
+ } else {
22239
+
22240
+ setColorLinear( pointColors, pointOffset, color, intensity );
22241
+
22242
+ }
22243
+
22244
+ _vector3.setFromMatrixPosition( light.matrixWorld );
22245
+
22246
+ pointPositions[ pointOffset ] = _vector3.x;
22247
+ pointPositions[ pointOffset + 1 ] = _vector3.y;
22248
+ pointPositions[ pointOffset + 2 ] = _vector3.z;
22249
+
22250
+ pointDistances[ pointLength ] = distance;
22251
+
22252
+ pointLength += 1;
22253
+
22254
+ } else if ( light instanceof THREE.SpotLight ) {
22255
+
22256
+ spotCount += 1;
22257
+
22258
+ if ( ! light.visible ) continue;
22259
+
22260
+ spotOffset = spotLength * 3;
22261
+
22262
+ if ( _this.gammaInput ) {
22263
+
22264
+ setColorGamma( spotColors, spotOffset, color, intensity * intensity );
22265
+
22266
+ } else {
22267
+
22268
+ setColorLinear( spotColors, spotOffset, color, intensity );
22269
+
22270
+ }
22271
+
22272
+ _direction.setFromMatrixPosition( light.matrixWorld );
22273
+
22274
+ spotPositions[ spotOffset ] = _direction.x;
22275
+ spotPositions[ spotOffset + 1 ] = _direction.y;
22276
+ spotPositions[ spotOffset + 2 ] = _direction.z;
22277
+
22278
+ spotDistances[ spotLength ] = distance;
22279
+
22280
+ _vector3.setFromMatrixPosition( light.target.matrixWorld );
22281
+ _direction.sub( _vector3 );
22282
+ _direction.normalize();
22283
+
22284
+ spotDirections[ spotOffset ] = _direction.x;
22285
+ spotDirections[ spotOffset + 1 ] = _direction.y;
22286
+ spotDirections[ spotOffset + 2 ] = _direction.z;
22287
+
22288
+ spotAnglesCos[ spotLength ] = Math.cos( light.angle );
22289
+ spotExponents[ spotLength ] = light.exponent;
22290
+
22291
+ spotLength += 1;
22292
+
22293
+ } else if ( light instanceof THREE.HemisphereLight ) {
22294
+
22295
+ hemiCount += 1;
22296
+
22297
+ if ( ! light.visible ) continue;
22298
+
22299
+ _direction.setFromMatrixPosition( light.matrixWorld );
22300
+ _direction.normalize();
22301
+
22302
+ hemiOffset = hemiLength * 3;
22303
+
22304
+ hemiPositions[ hemiOffset ] = _direction.x;
22305
+ hemiPositions[ hemiOffset + 1 ] = _direction.y;
22306
+ hemiPositions[ hemiOffset + 2 ] = _direction.z;
22307
+
22308
+ skyColor = light.color;
22309
+ groundColor = light.groundColor;
22310
+
22311
+ if ( _this.gammaInput ) {
22312
+
22313
+ intensitySq = intensity * intensity;
22314
+
22315
+ setColorGamma( hemiSkyColors, hemiOffset, skyColor, intensitySq );
22316
+ setColorGamma( hemiGroundColors, hemiOffset, groundColor, intensitySq );
22317
+
22318
+ } else {
22319
+
22320
+ setColorLinear( hemiSkyColors, hemiOffset, skyColor, intensity );
22321
+ setColorLinear( hemiGroundColors, hemiOffset, groundColor, intensity );
22322
+
22323
+ }
22324
+
22325
+ hemiLength += 1;
22326
+
22327
+ }
22328
+
22329
+ }
22330
+
22331
+ // null eventual remains from removed lights
22332
+ // (this is to avoid if in shader)
22333
+
22334
+ for ( l = dirLength * 3, ll = Math.max( dirColors.length, dirCount * 3 ); l < ll; l ++ ) dirColors[ l ] = 0.0;
22335
+ for ( l = pointLength * 3, ll = Math.max( pointColors.length, pointCount * 3 ); l < ll; l ++ ) pointColors[ l ] = 0.0;
22336
+ for ( l = spotLength * 3, ll = Math.max( spotColors.length, spotCount * 3 ); l < ll; l ++ ) spotColors[ l ] = 0.0;
22337
+ for ( l = hemiLength * 3, ll = Math.max( hemiSkyColors.length, hemiCount * 3 ); l < ll; l ++ ) hemiSkyColors[ l ] = 0.0;
22338
+ for ( l = hemiLength * 3, ll = Math.max( hemiGroundColors.length, hemiCount * 3 ); l < ll; l ++ ) hemiGroundColors[ l ] = 0.0;
22339
+
22340
+ zlights.directional.length = dirLength;
22341
+ zlights.point.length = pointLength;
22342
+ zlights.spot.length = spotLength;
22343
+ zlights.hemi.length = hemiLength;
22344
+
22345
+ zlights.ambient[ 0 ] = r;
22346
+ zlights.ambient[ 1 ] = g;
22347
+ zlights.ambient[ 2 ] = b;
22348
+
22349
+ }
22350
+
22351
+ // GL state setting
22352
+
22353
+ this.setFaceCulling = function ( cullFace, frontFaceDirection ) {
22354
+
22355
+ if ( cullFace === THREE.CullFaceNone ) {
22356
+
22357
+ _gl.disable( _gl.CULL_FACE );
22358
+
22359
+ } else {
22360
+
22361
+ if ( frontFaceDirection === THREE.FrontFaceDirectionCW ) {
22362
+
22363
+ _gl.frontFace( _gl.CW );
22364
+
22365
+ } else {
22366
+
22367
+ _gl.frontFace( _gl.CCW );
22368
+
22369
+ }
22370
+
22371
+ if ( cullFace === THREE.CullFaceBack ) {
22372
+
22373
+ _gl.cullFace( _gl.BACK );
22374
+
22375
+ } else if ( cullFace === THREE.CullFaceFront ) {
22376
+
22377
+ _gl.cullFace( _gl.FRONT );
22378
+
22379
+ } else {
22380
+
22381
+ _gl.cullFace( _gl.FRONT_AND_BACK );
22382
+
22383
+ }
22384
+
22385
+ _gl.enable( _gl.CULL_FACE );
22386
+
22387
+ }
22388
+
22389
+ };
22390
+
22391
+ this.setMaterialFaces = function ( material ) {
22392
+
22393
+ var doubleSided = material.side === THREE.DoubleSide;
22394
+ var flipSided = material.side === THREE.BackSide;
22395
+
22396
+ if ( _oldDoubleSided !== doubleSided ) {
22397
+
22398
+ if ( doubleSided ) {
22399
+
22400
+ _gl.disable( _gl.CULL_FACE );
22401
+
22402
+ } else {
22403
+
22404
+ _gl.enable( _gl.CULL_FACE );
22405
+
22406
+ }
22407
+
22408
+ _oldDoubleSided = doubleSided;
22409
+
22410
+ }
22411
+
22412
+ if ( _oldFlipSided !== flipSided ) {
22413
+
22414
+ if ( flipSided ) {
22415
+
22416
+ _gl.frontFace( _gl.CW );
22417
+
22418
+ } else {
22419
+
22420
+ _gl.frontFace( _gl.CCW );
22421
+
22422
+ }
22423
+
22424
+ _oldFlipSided = flipSided;
22425
+
22426
+ }
22427
+
22428
+ };
22429
+
22430
+ this.setDepthTest = function ( depthTest ) {
22431
+
22432
+ if ( _oldDepthTest !== depthTest ) {
22433
+
22434
+ if ( depthTest ) {
22435
+
22436
+ _gl.enable( _gl.DEPTH_TEST );
22437
+
22438
+ } else {
22439
+
22440
+ _gl.disable( _gl.DEPTH_TEST );
22441
+
22442
+ }
22443
+
22444
+ _oldDepthTest = depthTest;
22445
+
22446
+ }
22447
+
22448
+ };
22449
+
22450
+ this.setDepthWrite = function ( depthWrite ) {
22451
+
22452
+ if ( _oldDepthWrite !== depthWrite ) {
22453
+
22454
+ _gl.depthMask( depthWrite );
22455
+ _oldDepthWrite = depthWrite;
22456
+
22457
+ }
22458
+
22459
+ };
22460
+
22461
+ function setLineWidth ( width ) {
22462
+
22463
+ if ( width !== _oldLineWidth ) {
22464
+
22465
+ _gl.lineWidth( width );
22466
+
22467
+ _oldLineWidth = width;
22468
+
22469
+ }
22470
+
22471
+ }
22472
+
22473
+ function setPolygonOffset ( polygonoffset, factor, units ) {
22474
+
22475
+ if ( _oldPolygonOffset !== polygonoffset ) {
22476
+
22477
+ if ( polygonoffset ) {
22478
+
22479
+ _gl.enable( _gl.POLYGON_OFFSET_FILL );
22480
+
22481
+ } else {
22482
+
22483
+ _gl.disable( _gl.POLYGON_OFFSET_FILL );
22484
+
22485
+ }
22486
+
22487
+ _oldPolygonOffset = polygonoffset;
22488
+
22489
+ }
22490
+
22491
+ if ( polygonoffset && ( _oldPolygonOffsetFactor !== factor || _oldPolygonOffsetUnits !== units ) ) {
22492
+
22493
+ _gl.polygonOffset( factor, units );
22494
+
22495
+ _oldPolygonOffsetFactor = factor;
22496
+ _oldPolygonOffsetUnits = units;
22497
+
22498
+ }
22499
+
22500
+ }
22501
+
22502
+ this.setBlending = function ( blending, blendEquation, blendSrc, blendDst ) {
22503
+
22504
+ if ( blending !== _oldBlending ) {
22505
+
22506
+ if ( blending === THREE.NoBlending ) {
22507
+
22508
+ _gl.disable( _gl.BLEND );
22509
+
22510
+ } else if ( blending === THREE.AdditiveBlending ) {
22511
+
22512
+ _gl.enable( _gl.BLEND );
22513
+ _gl.blendEquation( _gl.FUNC_ADD );
22514
+ _gl.blendFunc( _gl.SRC_ALPHA, _gl.ONE );
22515
+
22516
+ } else if ( blending === THREE.SubtractiveBlending ) {
22517
+
22518
+ // TODO: Find blendFuncSeparate() combination
22519
+ _gl.enable( _gl.BLEND );
22520
+ _gl.blendEquation( _gl.FUNC_ADD );
22521
+ _gl.blendFunc( _gl.ZERO, _gl.ONE_MINUS_SRC_COLOR );
22522
+
22523
+ } else if ( blending === THREE.MultiplyBlending ) {
22524
+
22525
+ // TODO: Find blendFuncSeparate() combination
22526
+ _gl.enable( _gl.BLEND );
22527
+ _gl.blendEquation( _gl.FUNC_ADD );
22528
+ _gl.blendFunc( _gl.ZERO, _gl.SRC_COLOR );
22529
+
22530
+ } else if ( blending === THREE.CustomBlending ) {
22531
+
22532
+ _gl.enable( _gl.BLEND );
22533
+
22534
+ } else {
22535
+
22536
+ _gl.enable( _gl.BLEND );
22537
+ _gl.blendEquationSeparate( _gl.FUNC_ADD, _gl.FUNC_ADD );
22538
+ _gl.blendFuncSeparate( _gl.SRC_ALPHA, _gl.ONE_MINUS_SRC_ALPHA, _gl.ONE, _gl.ONE_MINUS_SRC_ALPHA );
22539
+
22540
+ }
22541
+
22542
+ _oldBlending = blending;
22543
+
22544
+ }
22545
+
22546
+ if ( blending === THREE.CustomBlending ) {
22547
+
22548
+ if ( blendEquation !== _oldBlendEquation ) {
22549
+
22550
+ _gl.blendEquation( paramThreeToGL( blendEquation ) );
22551
+
22552
+ _oldBlendEquation = blendEquation;
22553
+
22554
+ }
22555
+
22556
+ if ( blendSrc !== _oldBlendSrc || blendDst !== _oldBlendDst ) {
22557
+
22558
+ _gl.blendFunc( paramThreeToGL( blendSrc ), paramThreeToGL( blendDst ) );
22559
+
22560
+ _oldBlendSrc = blendSrc;
22561
+ _oldBlendDst = blendDst;
22562
+
22563
+ }
22564
+
22565
+ } else {
22566
+
22567
+ _oldBlendEquation = null;
22568
+ _oldBlendSrc = null;
22569
+ _oldBlendDst = null;
22570
+
22571
+ }
22572
+
22573
+ };
22574
+
22575
+ // Textures
22576
+
22577
+ function setTextureParameters ( textureType, texture, isImagePowerOfTwo ) {
22578
+
22579
+ var extension;
22580
+
22581
+ if ( isImagePowerOfTwo ) {
22582
+
22583
+ _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, paramThreeToGL( texture.wrapS ) );
22584
+ _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, paramThreeToGL( texture.wrapT ) );
22585
+
22586
+ _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, paramThreeToGL( texture.magFilter ) );
22587
+ _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, paramThreeToGL( texture.minFilter ) );
22588
+
22589
+ } else {
22590
+
22591
+ _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, _gl.CLAMP_TO_EDGE );
22592
+ _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, _gl.CLAMP_TO_EDGE );
22593
+
22594
+ _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, filterFallback( texture.magFilter ) );
22595
+ _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, filterFallback( texture.minFilter ) );
22596
+
22597
+ }
22598
+
22599
+ extension = extensions.get( 'EXT_texture_filter_anisotropic' );
22600
+
22601
+ if ( extension && texture.type !== THREE.FloatType ) {
22602
+
22603
+ if ( texture.anisotropy > 1 || texture.__oldAnisotropy ) {
22604
+
22605
+ _gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, _this.getMaxAnisotropy() ) );
22606
+ texture.__oldAnisotropy = texture.anisotropy;
22607
+
22608
+ }
22609
+
22610
+ }
22611
+
22612
+ }
22613
+
22614
+ this.uploadTexture = function ( texture ) {
22615
+
22616
+ if ( texture.__webglInit === undefined ) {
22617
+
22618
+ texture.__webglInit = true;
22619
+
22620
+ texture.addEventListener( 'dispose', onTextureDispose );
22621
+
22622
+ texture.__webglTexture = _gl.createTexture();
22623
+
22624
+ _this.info.memory.textures ++;
22625
+
22626
+ }
22627
+
22628
+ _gl.bindTexture( _gl.TEXTURE_2D, texture.__webglTexture );
22629
+
22630
+ _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
22631
+ _gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha );
22632
+ _gl.pixelStorei( _gl.UNPACK_ALIGNMENT, texture.unpackAlignment );
22633
+
22634
+ texture.image = clampToMaxSize( texture.image, _maxTextureSize );
22635
+
22636
+ var image = texture.image,
22637
+ isImagePowerOfTwo = THREE.Math.isPowerOfTwo( image.width ) && THREE.Math.isPowerOfTwo( image.height ),
22638
+ glFormat = paramThreeToGL( texture.format ),
22639
+ glType = paramThreeToGL( texture.type );
22640
+
22641
+ setTextureParameters( _gl.TEXTURE_2D, texture, isImagePowerOfTwo );
22642
+
22643
+ var mipmap, mipmaps = texture.mipmaps;
22644
+
22645
+ if ( texture instanceof THREE.DataTexture ) {
22646
+
22647
+ // use manually created mipmaps if available
22648
+ // if there are no manual mipmaps
22649
+ // set 0 level mipmap and then use GL to generate other mipmap levels
22650
+
22651
+ if ( mipmaps.length > 0 && isImagePowerOfTwo ) {
22652
+
22653
+ for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
22654
+
22655
+ mipmap = mipmaps[ i ];
22656
+ _gl.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
22657
+
22658
+ }
22659
+
22660
+ texture.generateMipmaps = false;
22661
+
22662
+ } else {
22663
+
22664
+ _gl.texImage2D( _gl.TEXTURE_2D, 0, glFormat, image.width, image.height, 0, glFormat, glType, image.data );
22665
+
22666
+ }
22667
+
22668
+ } else if ( texture instanceof THREE.CompressedTexture ) {
22669
+
22670
+ for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
22671
+
22672
+ mipmap = mipmaps[ i ];
22673
+
22674
+ if ( texture.format !== THREE.RGBAFormat && texture.format !== THREE.RGBFormat ) {
22675
+
22676
+ if ( getCompressedTextureFormats().indexOf( glFormat ) > -1 ) {
22677
+
22678
+ _gl.compressedTexImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
22679
+
22680
+ } else {
22681
+
22682
+ console.warn( "Attempt to load unsupported compressed texture format" );
22683
+
22684
+ }
22685
+
22686
+ } else {
22687
+
22688
+ _gl.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
22689
+
22690
+ }
22691
+
22692
+ }
22693
+
22694
+ } else { // regular Texture (image, video, canvas)
22695
+
22696
+ // use manually created mipmaps if available
22697
+ // if there are no manual mipmaps
22698
+ // set 0 level mipmap and then use GL to generate other mipmap levels
22699
+
22700
+ if ( mipmaps.length > 0 && isImagePowerOfTwo ) {
22701
+
22702
+ for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
22703
+
22704
+ mipmap = mipmaps[ i ];
22705
+ _gl.texImage2D( _gl.TEXTURE_2D, i, glFormat, glFormat, glType, mipmap );
22706
+
22707
+ }
22708
+
22709
+ texture.generateMipmaps = false;
22710
+
22711
+ } else {
22712
+
22713
+ _gl.texImage2D( _gl.TEXTURE_2D, 0, glFormat, glFormat, glType, texture.image );
22714
+
22715
+ }
22716
+
22717
+ }
22718
+
22719
+ if ( texture.generateMipmaps && isImagePowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_2D );
22720
+
22721
+ texture.needsUpdate = false;
22722
+
22723
+ if ( texture.onUpdate ) texture.onUpdate();
22724
+
22725
+ };
22726
+
22727
+ this.setTexture = function ( texture, slot ) {
22728
+
22729
+ _gl.activeTexture( _gl.TEXTURE0 + slot );
22730
+
22731
+ if ( texture.needsUpdate ) {
22732
+
22733
+ _this.uploadTexture( texture );
22734
+
22735
+ } else {
22736
+
22737
+ _gl.bindTexture( _gl.TEXTURE_2D, texture.__webglTexture );
22738
+
22739
+ }
22740
+
22741
+ };
22742
+
22743
+ function clampToMaxSize ( image, maxSize ) {
22744
+
22745
+ if ( image.width > maxSize || image.height > maxSize ) {
22746
+
22747
+ // Warning: Scaling through the canvas will only work with images that use
22748
+ // premultiplied alpha.
22749
+
22750
+ var scale = maxSize / Math.max( image.width, image.height );
22751
+
22752
+ var canvas = document.createElement( 'canvas' );
22753
+ canvas.width = Math.floor( image.width * scale );
22754
+ canvas.height = Math.floor( image.height * scale );
22755
+
22756
+ var context = canvas.getContext( '2d' );
22757
+ context.drawImage( image, 0, 0, image.width, image.height, 0, 0, canvas.width, canvas.height );
22758
+
22759
+ console.log( 'THREE.WebGLRenderer:', image, 'is too big (' + image.width + 'x' + image.height + '). Resized to ' + canvas.width + 'x' + canvas.height + '.' );
22760
+
22761
+ return canvas;
22762
+
22763
+ }
22764
+
22765
+ return image;
22766
+
22767
+ }
22768
+
22769
+ function setCubeTexture ( texture, slot ) {
22770
+
22771
+ if ( texture.image.length === 6 ) {
22772
+
22773
+ if ( texture.needsUpdate ) {
22774
+
22775
+ if ( ! texture.image.__webglTextureCube ) {
22776
+
22777
+ texture.addEventListener( 'dispose', onTextureDispose );
22778
+
22779
+ texture.image.__webglTextureCube = _gl.createTexture();
22780
+
22781
+ _this.info.memory.textures ++;
22782
+
22783
+ }
22784
+
22785
+ _gl.activeTexture( _gl.TEXTURE0 + slot );
22786
+ _gl.bindTexture( _gl.TEXTURE_CUBE_MAP, texture.image.__webglTextureCube );
22787
+
22788
+ _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
22789
+
22790
+ var isCompressed = texture instanceof THREE.CompressedTexture;
22791
+ var isDataTexture = texture.image[ 0 ] instanceof THREE.DataTexture;
22792
+
22793
+ var cubeImage = [];
22794
+
22795
+ for ( var i = 0; i < 6; i ++ ) {
22796
+
22797
+ if ( _this.autoScaleCubemaps && ! isCompressed && ! isDataTexture ) {
22798
+
22799
+ cubeImage[ i ] = clampToMaxSize( texture.image[ i ], _maxCubemapSize );
22800
+
22801
+ } else {
22802
+
22803
+ cubeImage[ i ] = isDataTexture ? texture.image[ i ].image : texture.image[ i ];
22804
+
22805
+ }
22806
+
22807
+ }
22808
+
22809
+ var image = cubeImage[ 0 ],
22810
+ isImagePowerOfTwo = THREE.Math.isPowerOfTwo( image.width ) && THREE.Math.isPowerOfTwo( image.height ),
22811
+ glFormat = paramThreeToGL( texture.format ),
22812
+ glType = paramThreeToGL( texture.type );
22813
+
22814
+ setTextureParameters( _gl.TEXTURE_CUBE_MAP, texture, isImagePowerOfTwo );
22815
+
22816
+ for ( var i = 0; i < 6; i ++ ) {
22817
+
22818
+ if ( ! isCompressed ) {
22819
+
22820
+ if ( isDataTexture ) {
22821
+
22822
+ _gl.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, cubeImage[ i ].width, cubeImage[ i ].height, 0, glFormat, glType, cubeImage[ i ].data );
22823
+
22824
+ } else {
22825
+
22826
+ _gl.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, glFormat, glType, cubeImage[ i ] );
22827
+
22828
+ }
22829
+
22830
+ } else {
22831
+
22832
+ var mipmap, mipmaps = cubeImage[ i ].mipmaps;
22833
+
22834
+ for ( var j = 0, jl = mipmaps.length; j < jl; j ++ ) {
22835
+
22836
+ mipmap = mipmaps[ j ];
22837
+
22838
+ if ( texture.format !== THREE.RGBAFormat && texture.format !== THREE.RGBFormat ) {
22839
+
22840
+ if ( getCompressedTextureFormats().indexOf( glFormat ) > -1 ) {
22841
+
22842
+ _gl.compressedTexImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
22843
+
22844
+ } else {
22845
+
22846
+ console.warn( "Attempt to load unsupported compressed texture format" );
22847
+
22848
+ }
22849
+
22850
+ } else {
22851
+
22852
+ _gl.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
22853
+
22854
+ }
22855
+
22856
+ }
22857
+
22858
+ }
22859
+
22860
+ }
22861
+
22862
+ if ( texture.generateMipmaps && isImagePowerOfTwo ) {
22863
+
22864
+ _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
22865
+
22866
+ }
22867
+
22868
+ texture.needsUpdate = false;
22869
+
22870
+ if ( texture.onUpdate ) texture.onUpdate();
22871
+
22872
+ } else {
22873
+
22874
+ _gl.activeTexture( _gl.TEXTURE0 + slot );
22875
+ _gl.bindTexture( _gl.TEXTURE_CUBE_MAP, texture.image.__webglTextureCube );
22876
+
22877
+ }
22878
+
22879
+ }
22880
+
22881
+ }
22882
+
22883
+ function setCubeTextureDynamic ( texture, slot ) {
22884
+
22885
+ _gl.activeTexture( _gl.TEXTURE0 + slot );
22886
+ _gl.bindTexture( _gl.TEXTURE_CUBE_MAP, texture.__webglTexture );
22887
+
22888
+ }
22889
+
22890
+ // Render targets
22891
+
22892
+ function setupFrameBuffer ( framebuffer, renderTarget, textureTarget ) {
22893
+
22894
+ _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
22895
+ _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, textureTarget, renderTarget.__webglTexture, 0 );
22896
+
22897
+ }
22898
+
22899
+ function setupRenderBuffer ( renderbuffer, renderTarget ) {
22900
+
22901
+ _gl.bindRenderbuffer( _gl.RENDERBUFFER, renderbuffer );
22902
+
22903
+ if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
22904
+
22905
+ _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_COMPONENT16, renderTarget.width, renderTarget.height );
22906
+ _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
22907
+
22908
+ /* For some reason this is not working. Defaulting to RGBA4.
22909
+ } else if ( ! renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
22910
+
22911
+ _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.STENCIL_INDEX8, renderTarget.width, renderTarget.height );
22912
+ _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
22913
+ */
22914
+ } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
22915
+
22916
+ _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_STENCIL, renderTarget.width, renderTarget.height );
22917
+ _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
22918
+
22919
+ } else {
22920
+
22921
+ _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.RGBA4, renderTarget.width, renderTarget.height );
22922
+
22923
+ }
22924
+
22925
+ }
22926
+
22927
+ this.setRenderTarget = function ( renderTarget ) {
22928
+
22929
+ var isCube = ( renderTarget instanceof THREE.WebGLRenderTargetCube );
22930
+
22931
+ if ( renderTarget && renderTarget.__webglFramebuffer === undefined ) {
22932
+
22933
+ if ( renderTarget.depthBuffer === undefined ) renderTarget.depthBuffer = true;
22934
+ if ( renderTarget.stencilBuffer === undefined ) renderTarget.stencilBuffer = true;
22935
+
22936
+ renderTarget.addEventListener( 'dispose', onRenderTargetDispose );
22937
+
22938
+ renderTarget.__webglTexture = _gl.createTexture();
22939
+
22940
+ _this.info.memory.textures ++;
22941
+
22942
+ // Setup texture, create render and frame buffers
22943
+
22944
+ var isTargetPowerOfTwo = THREE.Math.isPowerOfTwo( renderTarget.width ) && THREE.Math.isPowerOfTwo( renderTarget.height ),
22945
+ glFormat = paramThreeToGL( renderTarget.format ),
22946
+ glType = paramThreeToGL( renderTarget.type );
22947
+
22948
+ if ( isCube ) {
22949
+
22950
+ renderTarget.__webglFramebuffer = [];
22951
+ renderTarget.__webglRenderbuffer = [];
22952
+
22953
+ _gl.bindTexture( _gl.TEXTURE_CUBE_MAP, renderTarget.__webglTexture );
22954
+ setTextureParameters( _gl.TEXTURE_CUBE_MAP, renderTarget, isTargetPowerOfTwo );
22955
+
22956
+ for ( var i = 0; i < 6; i ++ ) {
22957
+
22958
+ renderTarget.__webglFramebuffer[ i ] = _gl.createFramebuffer();
22959
+ renderTarget.__webglRenderbuffer[ i ] = _gl.createRenderbuffer();
22960
+
22961
+ _gl.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
22962
+
22963
+ setupFrameBuffer( renderTarget.__webglFramebuffer[ i ], renderTarget, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i );
22964
+ setupRenderBuffer( renderTarget.__webglRenderbuffer[ i ], renderTarget );
22965
+
22966
+ }
22967
+
22968
+ if ( isTargetPowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
22969
+
22970
+ } else {
22971
+
22972
+ renderTarget.__webglFramebuffer = _gl.createFramebuffer();
22973
+
22974
+ if ( renderTarget.shareDepthFrom ) {
22975
+
22976
+ renderTarget.__webglRenderbuffer = renderTarget.shareDepthFrom.__webglRenderbuffer;
22977
+
22978
+ } else {
22979
+
22980
+ renderTarget.__webglRenderbuffer = _gl.createRenderbuffer();
22981
+
22982
+ }
22983
+
22984
+ _gl.bindTexture( _gl.TEXTURE_2D, renderTarget.__webglTexture );
22985
+ setTextureParameters( _gl.TEXTURE_2D, renderTarget, isTargetPowerOfTwo );
22986
+
22987
+ _gl.texImage2D( _gl.TEXTURE_2D, 0, glFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
22988
+
22989
+ setupFrameBuffer( renderTarget.__webglFramebuffer, renderTarget, _gl.TEXTURE_2D );
22990
+
22991
+ if ( renderTarget.shareDepthFrom ) {
22992
+
22993
+ if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
22994
+
22995
+ _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.RENDERBUFFER, renderTarget.__webglRenderbuffer );
22996
+
22997
+ } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
22998
+
22999
+ _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderTarget.__webglRenderbuffer );
23000
+
23001
+ }
23002
+
23003
+ } else {
23004
+
23005
+ setupRenderBuffer( renderTarget.__webglRenderbuffer, renderTarget );
23006
+
23007
+ }
23008
+
23009
+ if ( isTargetPowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_2D );
23010
+
23011
+ }
23012
+
23013
+ // Release everything
23014
+
23015
+ if ( isCube ) {
23016
+
23017
+ _gl.bindTexture( _gl.TEXTURE_CUBE_MAP, null );
23018
+
23019
+ } else {
23020
+
23021
+ _gl.bindTexture( _gl.TEXTURE_2D, null );
23022
+
23023
+ }
23024
+
23025
+ _gl.bindRenderbuffer( _gl.RENDERBUFFER, null );
23026
+ _gl.bindFramebuffer( _gl.FRAMEBUFFER, null );
23027
+
23028
+ }
23029
+
23030
+ var framebuffer, width, height, vx, vy;
23031
+
23032
+ if ( renderTarget ) {
23033
+
23034
+ if ( isCube ) {
23035
+
23036
+ framebuffer = renderTarget.__webglFramebuffer[ renderTarget.activeCubeFace ];
23037
+
23038
+ } else {
23039
+
23040
+ framebuffer = renderTarget.__webglFramebuffer;
23041
+
23042
+ }
23043
+
23044
+ width = renderTarget.width;
23045
+ height = renderTarget.height;
23046
+
23047
+ vx = 0;
23048
+ vy = 0;
23049
+
23050
+ } else {
23051
+
23052
+ framebuffer = null;
23053
+
23054
+ width = _viewportWidth;
23055
+ height = _viewportHeight;
23056
+
23057
+ vx = _viewportX;
23058
+ vy = _viewportY;
23059
+
23060
+ }
23061
+
23062
+ if ( framebuffer !== _currentFramebuffer ) {
23063
+
23064
+ _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
23065
+ _gl.viewport( vx, vy, width, height );
23066
+
23067
+ _currentFramebuffer = framebuffer;
23068
+
23069
+ }
23070
+
23071
+ _currentWidth = width;
23072
+ _currentHeight = height;
23073
+
23074
+ };
23075
+
23076
+ function updateRenderTargetMipmap ( renderTarget ) {
23077
+
23078
+ if ( renderTarget instanceof THREE.WebGLRenderTargetCube ) {
23079
+
23080
+ _gl.bindTexture( _gl.TEXTURE_CUBE_MAP, renderTarget.__webglTexture );
23081
+ _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
23082
+ _gl.bindTexture( _gl.TEXTURE_CUBE_MAP, null );
23083
+
23084
+ } else {
23085
+
23086
+ _gl.bindTexture( _gl.TEXTURE_2D, renderTarget.__webglTexture );
23087
+ _gl.generateMipmap( _gl.TEXTURE_2D );
23088
+ _gl.bindTexture( _gl.TEXTURE_2D, null );
23089
+
23090
+ }
23091
+
23092
+ }
23093
+
23094
+ // Fallback filters for non-power-of-2 textures
23095
+
23096
+ function filterFallback ( f ) {
23097
+
23098
+ if ( f === THREE.NearestFilter || f === THREE.NearestMipMapNearestFilter || f === THREE.NearestMipMapLinearFilter ) {
23099
+
23100
+ return _gl.NEAREST;
23101
+
23102
+ }
23103
+
23104
+ return _gl.LINEAR;
23105
+
23106
+ }
23107
+
23108
+ // Map three.js constants to WebGL constants
23109
+
23110
+ function paramThreeToGL ( p ) {
23111
+
23112
+ var extension;
23113
+
23114
+ if ( p === THREE.RepeatWrapping ) return _gl.REPEAT;
23115
+ if ( p === THREE.ClampToEdgeWrapping ) return _gl.CLAMP_TO_EDGE;
23116
+ if ( p === THREE.MirroredRepeatWrapping ) return _gl.MIRRORED_REPEAT;
23117
+
23118
+ if ( p === THREE.NearestFilter ) return _gl.NEAREST;
23119
+ if ( p === THREE.NearestMipMapNearestFilter ) return _gl.NEAREST_MIPMAP_NEAREST;
23120
+ if ( p === THREE.NearestMipMapLinearFilter ) return _gl.NEAREST_MIPMAP_LINEAR;
23121
+
23122
+ if ( p === THREE.LinearFilter ) return _gl.LINEAR;
23123
+ if ( p === THREE.LinearMipMapNearestFilter ) return _gl.LINEAR_MIPMAP_NEAREST;
23124
+ if ( p === THREE.LinearMipMapLinearFilter ) return _gl.LINEAR_MIPMAP_LINEAR;
23125
+
23126
+ if ( p === THREE.UnsignedByteType ) return _gl.UNSIGNED_BYTE;
23127
+ if ( p === THREE.UnsignedShort4444Type ) return _gl.UNSIGNED_SHORT_4_4_4_4;
23128
+ if ( p === THREE.UnsignedShort5551Type ) return _gl.UNSIGNED_SHORT_5_5_5_1;
23129
+ if ( p === THREE.UnsignedShort565Type ) return _gl.UNSIGNED_SHORT_5_6_5;
23130
+
23131
+ if ( p === THREE.ByteType ) return _gl.BYTE;
23132
+ if ( p === THREE.ShortType ) return _gl.SHORT;
23133
+ if ( p === THREE.UnsignedShortType ) return _gl.UNSIGNED_SHORT;
23134
+ if ( p === THREE.IntType ) return _gl.INT;
23135
+ if ( p === THREE.UnsignedIntType ) return _gl.UNSIGNED_INT;
23136
+ if ( p === THREE.FloatType ) return _gl.FLOAT;
23137
+
23138
+ if ( p === THREE.AlphaFormat ) return _gl.ALPHA;
23139
+ if ( p === THREE.RGBFormat ) return _gl.RGB;
23140
+ if ( p === THREE.RGBAFormat ) return _gl.RGBA;
23141
+ if ( p === THREE.LuminanceFormat ) return _gl.LUMINANCE;
23142
+ if ( p === THREE.LuminanceAlphaFormat ) return _gl.LUMINANCE_ALPHA;
23143
+
23144
+ if ( p === THREE.AddEquation ) return _gl.FUNC_ADD;
23145
+ if ( p === THREE.SubtractEquation ) return _gl.FUNC_SUBTRACT;
23146
+ if ( p === THREE.ReverseSubtractEquation ) return _gl.FUNC_REVERSE_SUBTRACT;
23147
+
23148
+ if ( p === THREE.ZeroFactor ) return _gl.ZERO;
23149
+ if ( p === THREE.OneFactor ) return _gl.ONE;
23150
+ if ( p === THREE.SrcColorFactor ) return _gl.SRC_COLOR;
23151
+ if ( p === THREE.OneMinusSrcColorFactor ) return _gl.ONE_MINUS_SRC_COLOR;
23152
+ if ( p === THREE.SrcAlphaFactor ) return _gl.SRC_ALPHA;
23153
+ if ( p === THREE.OneMinusSrcAlphaFactor ) return _gl.ONE_MINUS_SRC_ALPHA;
23154
+ if ( p === THREE.DstAlphaFactor ) return _gl.DST_ALPHA;
23155
+ if ( p === THREE.OneMinusDstAlphaFactor ) return _gl.ONE_MINUS_DST_ALPHA;
23156
+
23157
+ if ( p === THREE.DstColorFactor ) return _gl.DST_COLOR;
23158
+ if ( p === THREE.OneMinusDstColorFactor ) return _gl.ONE_MINUS_DST_COLOR;
23159
+ if ( p === THREE.SrcAlphaSaturateFactor ) return _gl.SRC_ALPHA_SATURATE;
23160
+
23161
+ extension = extensions.get( 'WEBGL_compressed_texture_s3tc' );
23162
+
23163
+ if ( extension !== null ) {
23164
+
23165
+ if ( p === THREE.RGB_S3TC_DXT1_Format ) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
23166
+ if ( p === THREE.RGBA_S3TC_DXT1_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
23167
+ if ( p === THREE.RGBA_S3TC_DXT3_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
23168
+ if ( p === THREE.RGBA_S3TC_DXT5_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
23169
+
23170
+ }
23171
+
23172
+ extension = extensions.get( 'WEBGL_compressed_texture_pvrtc' );
23173
+
23174
+ if ( extension !== null ) {
23175
+
23176
+ if ( p === THREE.RGB_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
23177
+ if ( p === THREE.RGB_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
23178
+ if ( p === THREE.RGBA_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
23179
+ if ( p === THREE.RGBA_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
23180
+
23181
+ }
23182
+
23183
+ extension = extensions.get( 'EXT_blend_minmax' );
23184
+
23185
+ if ( extension !== null ) {
23186
+
23187
+ if ( p === THREE.MinEquation ) return extension.MIN_EXT;
23188
+ if ( p === THREE.MaxEquation ) return extension.MAX_EXT;
23189
+
23190
+ }
23191
+
23192
+ return 0;
23193
+
23194
+ }
23195
+
23196
+ // Allocations
23197
+
23198
+ function allocateBones ( object ) {
23199
+
23200
+ if ( _supportsBoneTextures && object && object.skeleton && object.skeleton.useVertexTexture ) {
23201
+
23202
+ return 1024;
23203
+
23204
+ } else {
23205
+
23206
+ // default for when object is not specified
23207
+ // ( for example when prebuilding shader
23208
+ // to be used with multiple objects )
23209
+ //
23210
+ // - leave some extra space for other uniforms
23211
+ // - limit here is ANGLE's 254 max uniform vectors
23212
+ // (up to 54 should be safe)
23213
+
23214
+ var nVertexUniforms = _gl.getParameter( _gl.MAX_VERTEX_UNIFORM_VECTORS );
23215
+ var nVertexMatrices = Math.floor( ( nVertexUniforms - 20 ) / 4 );
23216
+
23217
+ var maxBones = nVertexMatrices;
23218
+
23219
+ if ( object !== undefined && object instanceof THREE.SkinnedMesh ) {
23220
+
23221
+ maxBones = Math.min( object.skeleton.bones.length, maxBones );
23222
+
23223
+ if ( maxBones < object.skeleton.bones.length ) {
23224
+
23225
+ console.warn( 'WebGLRenderer: too many bones - ' + object.skeleton.bones.length + ', this GPU supports just ' + maxBones + ' (try OpenGL instead of ANGLE)' );
23226
+
23227
+ }
23228
+
23229
+ }
23230
+
23231
+ return maxBones;
23232
+
23233
+ }
23234
+
23235
+ }
23236
+
23237
+ function allocateLights( lights ) {
23238
+
23239
+ var dirLights = 0;
23240
+ var pointLights = 0;
23241
+ var spotLights = 0;
23242
+ var hemiLights = 0;
23243
+
23244
+ for ( var l = 0, ll = lights.length; l < ll; l ++ ) {
23245
+
23246
+ var light = lights[ l ];
23247
+
23248
+ if ( light.onlyShadow || light.visible === false ) continue;
23249
+
23250
+ if ( light instanceof THREE.DirectionalLight ) dirLights ++;
23251
+ if ( light instanceof THREE.PointLight ) pointLights ++;
23252
+ if ( light instanceof THREE.SpotLight ) spotLights ++;
23253
+ if ( light instanceof THREE.HemisphereLight ) hemiLights ++;
23254
+
23255
+ }
23256
+
23257
+ return { 'directional': dirLights, 'point': pointLights, 'spot': spotLights, 'hemi': hemiLights };
23258
+
23259
+ }
23260
+
23261
+ function allocateShadows( lights ) {
23262
+
23263
+ var maxShadows = 0;
23264
+
23265
+ for ( var l = 0, ll = lights.length; l < ll; l ++ ) {
23266
+
23267
+ var light = lights[ l ];
23268
+
23269
+ if ( ! light.castShadow ) continue;
23270
+
23271
+ if ( light instanceof THREE.SpotLight ) maxShadows ++;
23272
+ if ( light instanceof THREE.DirectionalLight && ! light.shadowCascade ) maxShadows ++;
23273
+
23274
+ }
23275
+
23276
+ return maxShadows;
23277
+
23278
+ }
23279
+
23280
+ // DEPRECATED
23281
+
23282
+ this.initMaterial = function () {
23283
+
23284
+ console.warn( 'THREE.WebGLRenderer: .initMaterial() has been removed.' );
23285
+
23286
+ };
23287
+
23288
+ this.addPrePlugin = function () {
23289
+
23290
+ console.warn( 'THREE.WebGLRenderer: .addPrePlugin() has been removed.' );
23291
+
23292
+ };
23293
+
23294
+ this.addPostPlugin = function () {
23295
+
23296
+ console.warn( 'THREE.WebGLRenderer: .addPostPlugin() has been removed.' );
23297
+
23298
+ };
23299
+
23300
+ this.updateShadowMap = function () {
23301
+
23302
+ console.warn( 'THREE.WebGLRenderer: .updateShadowMap() has been removed.' );
23303
+
23304
+ };
23305
+
23306
+ };
23307
+
23308
+ // File:src/renderers/WebGLRenderTarget.js
23309
+
23310
+ /**
23311
+ * @author szimek / https://github.com/szimek/
23312
+ * @author alteredq / http://alteredqualia.com/
23313
+ */
23314
+
23315
+ THREE.WebGLRenderTarget = function ( width, height, options ) {
23316
+
23317
+ this.width = width;
23318
+ this.height = height;
23319
+
23320
+ options = options || {};
23321
+
23322
+ this.wrapS = options.wrapS !== undefined ? options.wrapS : THREE.ClampToEdgeWrapping;
23323
+ this.wrapT = options.wrapT !== undefined ? options.wrapT : THREE.ClampToEdgeWrapping;
23324
+
23325
+ this.magFilter = options.magFilter !== undefined ? options.magFilter : THREE.LinearFilter;
23326
+ this.minFilter = options.minFilter !== undefined ? options.minFilter : THREE.LinearMipMapLinearFilter;
23327
+
23328
+ this.anisotropy = options.anisotropy !== undefined ? options.anisotropy : 1;
23329
+
23330
+ this.offset = new THREE.Vector2( 0, 0 );
23331
+ this.repeat = new THREE.Vector2( 1, 1 );
23332
+
23333
+ this.format = options.format !== undefined ? options.format : THREE.RGBAFormat;
23334
+ this.type = options.type !== undefined ? options.type : THREE.UnsignedByteType;
23335
+
23336
+ this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
23337
+ this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : true;
23338
+
23339
+ this.generateMipmaps = true;
23340
+
23341
+ this.shareDepthFrom = null;
23342
+
23343
+ };
23344
+
23345
+ THREE.WebGLRenderTarget.prototype = {
23346
+
23347
+ constructor: THREE.WebGLRenderTarget,
23348
+
23349
+ setSize: function ( width, height ) {
23350
+
23351
+ this.width = width;
23352
+ this.height = height;
23353
+
23354
+ },
23355
+
23356
+ clone: function () {
23357
+
23358
+ var tmp = new THREE.WebGLRenderTarget( this.width, this.height );
23359
+
23360
+ tmp.wrapS = this.wrapS;
23361
+ tmp.wrapT = this.wrapT;
23362
+
23363
+ tmp.magFilter = this.magFilter;
23364
+ tmp.minFilter = this.minFilter;
23365
+
23366
+ tmp.anisotropy = this.anisotropy;
23367
+
23368
+ tmp.offset.copy( this.offset );
23369
+ tmp.repeat.copy( this.repeat );
23370
+
23371
+ tmp.format = this.format;
23372
+ tmp.type = this.type;
23373
+
23374
+ tmp.depthBuffer = this.depthBuffer;
23375
+ tmp.stencilBuffer = this.stencilBuffer;
23376
+
23377
+ tmp.generateMipmaps = this.generateMipmaps;
23378
+
23379
+ tmp.shareDepthFrom = this.shareDepthFrom;
23380
+
23381
+ return tmp;
23382
+
23383
+ },
23384
+
23385
+ dispose: function () {
23386
+
23387
+ this.dispatchEvent( { type: 'dispose' } );
23388
+
23389
+ }
23390
+
23391
+ };
23392
+
23393
+ THREE.EventDispatcher.prototype.apply( THREE.WebGLRenderTarget.prototype );
23394
+
23395
+ // File:src/renderers/WebGLRenderTargetCube.js
23396
+
23397
+ /**
23398
+ * @author alteredq / http://alteredqualia.com
23399
+ */
23400
+
23401
+ THREE.WebGLRenderTargetCube = function ( width, height, options ) {
23402
+
23403
+ THREE.WebGLRenderTarget.call( this, width, height, options );
23404
+
23405
+ this.activeCubeFace = 0; // PX 0, NX 1, PY 2, NY 3, PZ 4, NZ 5
23406
+
23407
+ };
23408
+
23409
+ THREE.WebGLRenderTargetCube.prototype = Object.create( THREE.WebGLRenderTarget.prototype );
23410
+
23411
+ // File:src/renderers/webgl/WebGLExtensions.js
23412
+
23413
+ THREE.WebGLExtensions = function ( gl ) {
23414
+
23415
+ var extensions = {};
23416
+
23417
+ this.get = function ( name ) {
23418
+
23419
+ if ( extensions[ name ] !== undefined ) {
23420
+
23421
+ return extensions[ name ];
23422
+
23423
+ }
23424
+
23425
+ var extension;
23426
+
23427
+ switch ( name ) {
23428
+
23429
+ case 'OES_texture_float':
23430
+ extension = gl.getExtension( 'OES_texture_float' );
23431
+ break;
23432
+
23433
+ case 'OES_texture_float_linear':
23434
+ extension = gl.getExtension( 'OES_texture_float_linear' );
23435
+ break;
23436
+
23437
+ case 'OES_standard_derivatives':
23438
+ extension = gl.getExtension( 'OES_standard_derivatives' );
23439
+ break;
23440
+
23441
+ case 'EXT_texture_filter_anisotropic':
23442
+ extension = gl.getExtension( 'EXT_texture_filter_anisotropic' ) || gl.getExtension( 'MOZ_EXT_texture_filter_anisotropic' ) || gl.getExtension( 'WEBKIT_EXT_texture_filter_anisotropic' );
23443
+ break;
23444
+
23445
+ case 'WEBGL_compressed_texture_s3tc':
23446
+ extension = gl.getExtension( 'WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'MOZ_WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_s3tc' );
23447
+ break;
23448
+
23449
+ case 'WEBGL_compressed_texture_pvrtc':
23450
+ extension = gl.getExtension( 'WEBGL_compressed_texture_pvrtc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_pvrtc' );
23451
+ break;
23452
+
23453
+ case 'OES_element_index_uint':
23454
+ extension = gl.getExtension( 'OES_element_index_uint' );
23455
+ break;
23456
+
23457
+ case 'EXT_blend_minmax':
23458
+ extension = gl.getExtension( 'EXT_blend_minmax' );
23459
+ break;
23460
+
23461
+ case 'EXT_frag_depth':
23462
+ extension = gl.getExtension( 'EXT_frag_depth' );
23463
+ break;
23464
+
23465
+ }
23466
+
23467
+ if ( extension === null ) {
23468
+
23469
+ console.log( 'THREE.WebGLRenderer: ' + name + ' extension not supported.' );
23470
+
23471
+ }
23472
+
23473
+ extensions[ name ] = extension;
23474
+
23475
+ return extension;
23476
+
23477
+ };
23478
+
23479
+ };
23480
+
23481
+ // File:src/renderers/webgl/WebGLProgram.js
23482
+
23483
+ THREE.WebGLProgram = ( function () {
23484
+
23485
+ var programIdCount = 0;
23486
+
23487
+ var generateDefines = function ( defines ) {
23488
+
23489
+ var value, chunk, chunks = [];
23490
+
23491
+ for ( var d in defines ) {
23492
+
23493
+ value = defines[ d ];
23494
+ if ( value === false ) continue;
23495
+
23496
+ chunk = "#define " + d + " " + value;
23497
+ chunks.push( chunk );
23498
+
23499
+ }
23500
+
23501
+ return chunks.join( "\n" );
23502
+
23503
+ };
23504
+
23505
+ var cacheUniformLocations = function ( gl, program, identifiers ) {
23506
+
23507
+ var uniforms = {};
23508
+
23509
+ for ( var i = 0, l = identifiers.length; i < l; i ++ ) {
23510
+
23511
+ var id = identifiers[ i ];
23512
+ uniforms[ id ] = gl.getUniformLocation( program, id );
23513
+
23514
+ }
23515
+
23516
+ return uniforms;
23517
+
23518
+ };
23519
+
23520
+ var cacheAttributeLocations = function ( gl, program, identifiers ) {
23521
+
23522
+ var attributes = {};
23523
+
23524
+ for ( var i = 0, l = identifiers.length; i < l; i ++ ) {
23525
+
23526
+ var id = identifiers[ i ];
23527
+ attributes[ id ] = gl.getAttribLocation( program, id );
23528
+
23529
+ }
23530
+
23531
+ return attributes;
23532
+
23533
+ };
23534
+
23535
+ return function ( renderer, code, material, parameters ) {
23536
+
23537
+ var _this = renderer;
23538
+ var _gl = _this.context;
23539
+
23540
+ var defines = material.defines;
23541
+ var uniforms = material.__webglShader.uniforms;
23542
+ var attributes = material.attributes;
23543
+
23544
+ var vertexShader = material.__webglShader.vertexShader;
23545
+ var fragmentShader = material.__webglShader.fragmentShader;
23546
+
23547
+ var index0AttributeName = material.index0AttributeName;
23548
+
23549
+ if ( index0AttributeName === undefined && parameters.morphTargets === true ) {
23550
+
23551
+ // programs with morphTargets displace position out of attribute 0
23552
+
23553
+ index0AttributeName = 'position';
23554
+
23555
+ }
23556
+
23557
+ var shadowMapTypeDefine = "SHADOWMAP_TYPE_BASIC";
23558
+
23559
+ if ( parameters.shadowMapType === THREE.PCFShadowMap ) {
23560
+
23561
+ shadowMapTypeDefine = "SHADOWMAP_TYPE_PCF";
23562
+
23563
+ } else if ( parameters.shadowMapType === THREE.PCFSoftShadowMap ) {
23564
+
23565
+ shadowMapTypeDefine = "SHADOWMAP_TYPE_PCF_SOFT";
23566
+
23567
+ }
23568
+
23569
+ // console.log( "building new program " );
23570
+
23571
+ //
23572
+
23573
+ var customDefines = generateDefines( defines );
23574
+
23575
+ //
23576
+
23577
+ var program = _gl.createProgram();
23578
+
23579
+ var prefix_vertex, prefix_fragment;
23580
+
23581
+ if ( material instanceof THREE.RawShaderMaterial ) {
23582
+
23583
+ prefix_vertex = '';
23584
+ prefix_fragment = '';
23585
+
23586
+ } else {
23587
+
23588
+ prefix_vertex = [
23589
+
23590
+ "precision " + parameters.precision + " float;",
23591
+ "precision " + parameters.precision + " int;",
23592
+
23593
+ customDefines,
23594
+
23595
+ parameters.supportsVertexTextures ? "#define VERTEX_TEXTURES" : "",
23596
+
23597
+ _this.gammaInput ? "#define GAMMA_INPUT" : "",
23598
+ _this.gammaOutput ? "#define GAMMA_OUTPUT" : "",
23599
+
23600
+ "#define MAX_DIR_LIGHTS " + parameters.maxDirLights,
23601
+ "#define MAX_POINT_LIGHTS " + parameters.maxPointLights,
23602
+ "#define MAX_SPOT_LIGHTS " + parameters.maxSpotLights,
23603
+ "#define MAX_HEMI_LIGHTS " + parameters.maxHemiLights,
23604
+
23605
+ "#define MAX_SHADOWS " + parameters.maxShadows,
23606
+
23607
+ "#define MAX_BONES " + parameters.maxBones,
23608
+
23609
+ parameters.map ? "#define USE_MAP" : "",
23610
+ parameters.envMap ? "#define USE_ENVMAP" : "",
23611
+ parameters.lightMap ? "#define USE_LIGHTMAP" : "",
23612
+ parameters.bumpMap ? "#define USE_BUMPMAP" : "",
23613
+ parameters.normalMap ? "#define USE_NORMALMAP" : "",
23614
+ parameters.specularMap ? "#define USE_SPECULARMAP" : "",
23615
+ parameters.alphaMap ? "#define USE_ALPHAMAP" : "",
23616
+ parameters.vertexColors ? "#define USE_COLOR" : "",
23617
+
23618
+ parameters.skinning ? "#define USE_SKINNING" : "",
23619
+ parameters.useVertexTexture ? "#define BONE_TEXTURE" : "",
23620
+
23621
+ parameters.morphTargets ? "#define USE_MORPHTARGETS" : "",
23622
+ parameters.morphNormals ? "#define USE_MORPHNORMALS" : "",
23623
+ parameters.wrapAround ? "#define WRAP_AROUND" : "",
23624
+ parameters.doubleSided ? "#define DOUBLE_SIDED" : "",
23625
+ parameters.flipSided ? "#define FLIP_SIDED" : "",
23626
+
23627
+ parameters.shadowMapEnabled ? "#define USE_SHADOWMAP" : "",
23628
+ parameters.shadowMapEnabled ? "#define " + shadowMapTypeDefine : "",
23629
+ parameters.shadowMapDebug ? "#define SHADOWMAP_DEBUG" : "",
23630
+ parameters.shadowMapCascade ? "#define SHADOWMAP_CASCADE" : "",
23631
+
23632
+ parameters.sizeAttenuation ? "#define USE_SIZEATTENUATION" : "",
23633
+
23634
+ parameters.logarithmicDepthBuffer ? "#define USE_LOGDEPTHBUF" : "",
23635
+ //_this._glExtensionFragDepth ? "#define USE_LOGDEPTHBUF_EXT" : "",
23636
+
23637
+
23638
+ "uniform mat4 modelMatrix;",
23639
+ "uniform mat4 modelViewMatrix;",
23640
+ "uniform mat4 projectionMatrix;",
23641
+ "uniform mat4 viewMatrix;",
23642
+ "uniform mat3 normalMatrix;",
23643
+ "uniform vec3 cameraPosition;",
23644
+
23645
+ "attribute vec3 position;",
23646
+ "attribute vec3 normal;",
23647
+ "attribute vec2 uv;",
23648
+ "attribute vec2 uv2;",
23649
+
23650
+ "#ifdef USE_COLOR",
23651
+
23652
+ " attribute vec3 color;",
23653
+
23654
+ "#endif",
23655
+
23656
+ "#ifdef USE_MORPHTARGETS",
23657
+
23658
+ " attribute vec3 morphTarget0;",
23659
+ " attribute vec3 morphTarget1;",
23660
+ " attribute vec3 morphTarget2;",
23661
+ " attribute vec3 morphTarget3;",
23662
+
23663
+ " #ifdef USE_MORPHNORMALS",
23664
+
23665
+ " attribute vec3 morphNormal0;",
23666
+ " attribute vec3 morphNormal1;",
23667
+ " attribute vec3 morphNormal2;",
23668
+ " attribute vec3 morphNormal3;",
23669
+
23670
+ " #else",
23671
+
23672
+ " attribute vec3 morphTarget4;",
23673
+ " attribute vec3 morphTarget5;",
23674
+ " attribute vec3 morphTarget6;",
23675
+ " attribute vec3 morphTarget7;",
23676
+
23677
+ " #endif",
23678
+
23679
+ "#endif",
23680
+
23681
+ "#ifdef USE_SKINNING",
23682
+
23683
+ " attribute vec4 skinIndex;",
23684
+ " attribute vec4 skinWeight;",
23685
+
23686
+ "#endif",
23687
+
23688
+ ""
23689
+
23690
+ ].join( '\n' );
23691
+
23692
+ prefix_fragment = [
23693
+
23694
+ "precision " + parameters.precision + " float;",
23695
+ "precision " + parameters.precision + " int;",
23696
+
23697
+ ( parameters.bumpMap || parameters.normalMap ) ? "#extension GL_OES_standard_derivatives : enable" : "",
23698
+
23699
+ customDefines,
23700
+
23701
+ "#define MAX_DIR_LIGHTS " + parameters.maxDirLights,
23702
+ "#define MAX_POINT_LIGHTS " + parameters.maxPointLights,
23703
+ "#define MAX_SPOT_LIGHTS " + parameters.maxSpotLights,
23704
+ "#define MAX_HEMI_LIGHTS " + parameters.maxHemiLights,
23705
+
23706
+ "#define MAX_SHADOWS " + parameters.maxShadows,
23707
+
23708
+ parameters.alphaTest ? "#define ALPHATEST " + parameters.alphaTest: "",
23709
+
23710
+ _this.gammaInput ? "#define GAMMA_INPUT" : "",
23711
+ _this.gammaOutput ? "#define GAMMA_OUTPUT" : "",
23712
+
23713
+ ( parameters.useFog && parameters.fog ) ? "#define USE_FOG" : "",
23714
+ ( parameters.useFog && parameters.fogExp ) ? "#define FOG_EXP2" : "",
23715
+
23716
+ parameters.map ? "#define USE_MAP" : "",
23717
+ parameters.envMap ? "#define USE_ENVMAP" : "",
23718
+ parameters.lightMap ? "#define USE_LIGHTMAP" : "",
23719
+ parameters.bumpMap ? "#define USE_BUMPMAP" : "",
23720
+ parameters.normalMap ? "#define USE_NORMALMAP" : "",
23721
+ parameters.specularMap ? "#define USE_SPECULARMAP" : "",
23722
+ parameters.alphaMap ? "#define USE_ALPHAMAP" : "",
23723
+ parameters.vertexColors ? "#define USE_COLOR" : "",
23724
+
23725
+ parameters.metal ? "#define METAL" : "",
23726
+ parameters.wrapAround ? "#define WRAP_AROUND" : "",
23727
+ parameters.doubleSided ? "#define DOUBLE_SIDED" : "",
23728
+ parameters.flipSided ? "#define FLIP_SIDED" : "",
23729
+
23730
+ parameters.shadowMapEnabled ? "#define USE_SHADOWMAP" : "",
23731
+ parameters.shadowMapEnabled ? "#define " + shadowMapTypeDefine : "",
23732
+ parameters.shadowMapDebug ? "#define SHADOWMAP_DEBUG" : "",
23733
+ parameters.shadowMapCascade ? "#define SHADOWMAP_CASCADE" : "",
23734
+
23735
+ parameters.logarithmicDepthBuffer ? "#define USE_LOGDEPTHBUF" : "",
23736
+ //_this._glExtensionFragDepth ? "#define USE_LOGDEPTHBUF_EXT" : "",
23737
+
23738
+ "uniform mat4 viewMatrix;",
23739
+ "uniform vec3 cameraPosition;",
23740
+ ""
23741
+
23742
+ ].join( '\n' );
23743
+
23744
+ }
23745
+
23746
+ var glVertexShader = new THREE.WebGLShader( _gl, _gl.VERTEX_SHADER, prefix_vertex + vertexShader );
23747
+ var glFragmentShader = new THREE.WebGLShader( _gl, _gl.FRAGMENT_SHADER, prefix_fragment + fragmentShader );
23748
+
23749
+ _gl.attachShader( program, glVertexShader );
23750
+ _gl.attachShader( program, glFragmentShader );
23751
+
23752
+ if ( index0AttributeName !== undefined ) {
23753
+
23754
+ // Force a particular attribute to index 0.
23755
+ // because potentially expensive emulation is done by browser if attribute 0 is disabled.
23756
+ // And, color, for example is often automatically bound to index 0 so disabling it
23757
+
23758
+ _gl.bindAttribLocation( program, 0, index0AttributeName );
23759
+
23760
+ }
23761
+
23762
+ _gl.linkProgram( program );
23763
+
23764
+ if ( _gl.getProgramParameter( program, _gl.LINK_STATUS ) === false ) {
23765
+
23766
+ console.error( 'THREE.WebGLProgram: Could not initialise shader.' );
23767
+ console.error( 'gl.VALIDATE_STATUS', _gl.getProgramParameter( program, _gl.VALIDATE_STATUS ) );
23768
+ console.error( 'gl.getError()', _gl.getError() );
23769
+
23770
+ }
23771
+
23772
+ if ( _gl.getProgramInfoLog( program ) !== '' ) {
23773
+
23774
+ console.warn( 'THREE.WebGLProgram: gl.getProgramInfoLog()', _gl.getProgramInfoLog( program ) );
23775
+
23776
+ }
23777
+
23778
+ // clean up
23779
+
23780
+ _gl.deleteShader( glVertexShader );
23781
+ _gl.deleteShader( glFragmentShader );
23782
+
23783
+ // cache uniform locations
23784
+
23785
+ var identifiers = [
23786
+
23787
+ 'viewMatrix', 'modelViewMatrix', 'projectionMatrix', 'normalMatrix', 'modelMatrix', 'cameraPosition', 'morphTargetInfluences', 'bindMatrix', 'bindMatrixInverse'
23788
+
23789
+ ];
23790
+
23791
+ if ( parameters.useVertexTexture ) {
23792
+
23793
+ identifiers.push( 'boneTexture' );
23794
+ identifiers.push( 'boneTextureWidth' );
23795
+ identifiers.push( 'boneTextureHeight' );
23796
+
23797
+ } else {
23798
+
23799
+ identifiers.push( 'boneGlobalMatrices' );
23800
+
23801
+ }
23802
+
23803
+ if ( parameters.logarithmicDepthBuffer ) {
23804
+
23805
+ identifiers.push('logDepthBufFC');
23806
+
23807
+ }
23808
+
23809
+
23810
+ for ( var u in uniforms ) {
23811
+
23812
+ identifiers.push( u );
23813
+
23814
+ }
23815
+
23816
+ this.uniforms = cacheUniformLocations( _gl, program, identifiers );
23817
+
23818
+ // cache attributes locations
23819
+
23820
+ identifiers = [
23821
+
23822
+ "position", "normal", "uv", "uv2", "tangent", "color",
23823
+ "skinIndex", "skinWeight", "lineDistance"
23824
+
23825
+ ];
23826
+
23827
+ for ( var i = 0; i < parameters.maxMorphTargets; i ++ ) {
23828
+
23829
+ identifiers.push( "morphTarget" + i );
23830
+
23831
+ }
23832
+
23833
+ for ( var i = 0; i < parameters.maxMorphNormals; i ++ ) {
23834
+
23835
+ identifiers.push( "morphNormal" + i );
23836
+
23837
+ }
23838
+
23839
+ for ( var a in attributes ) {
23840
+
23841
+ identifiers.push( a );
23842
+
23843
+ }
23844
+
23845
+ this.attributes = cacheAttributeLocations( _gl, program, identifiers );
23846
+ this.attributesKeys = Object.keys( this.attributes );
23847
+
23848
+ //
23849
+
23850
+ this.id = programIdCount ++;
23851
+ this.code = code;
23852
+ this.usedTimes = 1;
23853
+ this.program = program;
23854
+ this.vertexShader = glVertexShader;
23855
+ this.fragmentShader = glFragmentShader;
23856
+
23857
+ return this;
23858
+
23859
+ };
23860
+
23861
+ } )();
23862
+
23863
+ // File:src/renderers/webgl/WebGLShader.js
23864
+
23865
+ THREE.WebGLShader = ( function () {
23866
+
23867
+ var addLineNumbers = function ( string ) {
23868
+
23869
+ var lines = string.split( '\n' );
23870
+
23871
+ for ( var i = 0; i < lines.length; i ++ ) {
23872
+
23873
+ lines[ i ] = ( i + 1 ) + ': ' + lines[ i ];
23874
+
23875
+ }
23876
+
23877
+ return lines.join( '\n' );
23878
+
23879
+ };
23880
+
23881
+ return function ( gl, type, string ) {
23882
+
23883
+ var shader = gl.createShader( type );
23884
+
23885
+ gl.shaderSource( shader, string );
23886
+ gl.compileShader( shader );
23887
+
23888
+ if ( gl.getShaderParameter( shader, gl.COMPILE_STATUS ) === false ) {
23889
+
23890
+ console.error( 'THREE.WebGLShader: Shader couldn\'t compile.' );
23891
+
23892
+ }
23893
+
23894
+ if ( gl.getShaderInfoLog( shader ) !== '' ) {
23895
+
23896
+ console.warn( 'THREE.WebGLShader: gl.getShaderInfoLog()', gl.getShaderInfoLog( shader ) );
23897
+ console.warn( addLineNumbers( string ) );
23898
+
23899
+ }
23900
+
23901
+ // --enable-privileged-webgl-extension
23902
+ // console.log( type, gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
23903
+
23904
+ return shader;
23905
+
23906
+ };
23907
+
23908
+ } )();
23909
+
23910
+ // File:src/renderers/webgl/plugins/LensFlarePlugin.js
23911
+
23912
+ /**
23913
+ * @author mikael emtinger / http://gomo.se/
23914
+ * @author alteredq / http://alteredqualia.com/
23915
+ */
23916
+
23917
+ THREE.LensFlarePlugin = function ( renderer, flares ) {
23918
+
23919
+ var gl = renderer.context;
23920
+
23921
+ var vertexBuffer, elementBuffer;
23922
+ var program, attributes, uniforms;
23923
+ var hasVertexTexture;
23924
+
23925
+ var tempTexture, occlusionTexture;
23926
+
23927
+ var init = function () {
23928
+
23929
+ var vertices = new Float32Array( [
23930
+ -1, -1, 0, 0,
23931
+ 1, -1, 1, 0,
23932
+ 1, 1, 1, 1,
23933
+ -1, 1, 0, 1
23934
+ ] );
23935
+
23936
+ var faces = new Uint16Array( [
23937
+ 0, 1, 2,
23938
+ 0, 2, 3
23939
+ ] );
23940
+
23941
+ // buffers
23942
+
23943
+ vertexBuffer = gl.createBuffer();
23944
+ elementBuffer = gl.createBuffer();
23945
+
23946
+ gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
23947
+ gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
23948
+
23949
+ gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
23950
+ gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
23951
+
23952
+ // textures
23953
+
23954
+ tempTexture = gl.createTexture();
23955
+ occlusionTexture = gl.createTexture();
23956
+
23957
+ gl.bindTexture( gl.TEXTURE_2D, tempTexture );
23958
+ gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGB, 16, 16, 0, gl.RGB, gl.UNSIGNED_BYTE, null );
23959
+ gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE );
23960
+ gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE );
23961
+ gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
23962
+ gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
23963
+
23964
+ gl.bindTexture( gl.TEXTURE_2D, occlusionTexture );
23965
+ gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGBA, 16, 16, 0, gl.RGBA, gl.UNSIGNED_BYTE, null );
23966
+ gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE );
23967
+ gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE );
23968
+ gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
23969
+ gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
23970
+
23971
+ hasVertexTexture = gl.getParameter( gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS ) > 0;
23972
+
23973
+ var shader;
23974
+
23975
+ if ( hasVertexTexture ) {
23976
+
23977
+ shader = {
23978
+
23979
+ vertexShader: [
23980
+
23981
+ "uniform lowp int renderType;",
23982
+
23983
+ "uniform vec3 screenPosition;",
23984
+ "uniform vec2 scale;",
23985
+ "uniform float rotation;",
23986
+
23987
+ "uniform sampler2D occlusionMap;",
23988
+
23989
+ "attribute vec2 position;",
23990
+ "attribute vec2 uv;",
23991
+
23992
+ "varying vec2 vUV;",
23993
+ "varying float vVisibility;",
23994
+
23995
+ "void main() {",
23996
+
23997
+ "vUV = uv;",
23998
+
23999
+ "vec2 pos = position;",
24000
+
24001
+ "if( renderType == 2 ) {",
24002
+
24003
+ "vec4 visibility = texture2D( occlusionMap, vec2( 0.1, 0.1 ) );",
24004
+ "visibility += texture2D( occlusionMap, vec2( 0.5, 0.1 ) );",
24005
+ "visibility += texture2D( occlusionMap, vec2( 0.9, 0.1 ) );",
24006
+ "visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) );",
24007
+ "visibility += texture2D( occlusionMap, vec2( 0.9, 0.9 ) );",
24008
+ "visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) );",
24009
+ "visibility += texture2D( occlusionMap, vec2( 0.1, 0.9 ) );",
24010
+ "visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) );",
24011
+ "visibility += texture2D( occlusionMap, vec2( 0.5, 0.5 ) );",
24012
+
24013
+ "vVisibility = visibility.r / 9.0;",
24014
+ "vVisibility *= 1.0 - visibility.g / 9.0;",
24015
+ "vVisibility *= visibility.b / 9.0;",
24016
+ "vVisibility *= 1.0 - visibility.a / 9.0;",
24017
+
24018
+ "pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
24019
+ "pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
24020
+
24021
+ "}",
24022
+
24023
+ "gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
24024
+
24025
+ "}"
24026
+
24027
+ ].join( "\n" ),
24028
+
24029
+ fragmentShader: [
24030
+
24031
+ "uniform lowp int renderType;",
24032
+
24033
+ "uniform sampler2D map;",
24034
+ "uniform float opacity;",
24035
+ "uniform vec3 color;",
24036
+
24037
+ "varying vec2 vUV;",
24038
+ "varying float vVisibility;",
24039
+
24040
+ "void main() {",
24041
+
24042
+ // pink square
24043
+
24044
+ "if( renderType == 0 ) {",
24045
+
24046
+ "gl_FragColor = vec4( 1.0, 0.0, 1.0, 0.0 );",
24047
+
24048
+ // restore
24049
+
24050
+ "} else if( renderType == 1 ) {",
24051
+
24052
+ "gl_FragColor = texture2D( map, vUV );",
24053
+
24054
+ // flare
24055
+
24056
+ "} else {",
24057
+
24058
+ "vec4 texture = texture2D( map, vUV );",
24059
+ "texture.a *= opacity * vVisibility;",
24060
+ "gl_FragColor = texture;",
24061
+ "gl_FragColor.rgb *= color;",
24062
+
24063
+ "}",
24064
+
24065
+ "}"
24066
+
24067
+ ].join( "\n" )
24068
+
24069
+ };
24070
+
24071
+ } else {
24072
+
24073
+ shader = {
24074
+
24075
+ vertexShader: [
24076
+
24077
+ "uniform lowp int renderType;",
24078
+
24079
+ "uniform vec3 screenPosition;",
24080
+ "uniform vec2 scale;",
24081
+ "uniform float rotation;",
24082
+
24083
+ "attribute vec2 position;",
24084
+ "attribute vec2 uv;",
24085
+
24086
+ "varying vec2 vUV;",
24087
+
24088
+ "void main() {",
24089
+
24090
+ "vUV = uv;",
24091
+
24092
+ "vec2 pos = position;",
24093
+
24094
+ "if( renderType == 2 ) {",
24095
+
24096
+ "pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
24097
+ "pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
24098
+
24099
+ "}",
24100
+
24101
+ "gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
24102
+
24103
+ "}"
24104
+
24105
+ ].join( "\n" ),
24106
+
24107
+ fragmentShader: [
24108
+
24109
+ "precision mediump float;",
24110
+
24111
+ "uniform lowp int renderType;",
24112
+
24113
+ "uniform sampler2D map;",
24114
+ "uniform sampler2D occlusionMap;",
24115
+ "uniform float opacity;",
24116
+ "uniform vec3 color;",
24117
+
24118
+ "varying vec2 vUV;",
24119
+
24120
+ "void main() {",
24121
+
24122
+ // pink square
24123
+
24124
+ "if( renderType == 0 ) {",
24125
+
24126
+ "gl_FragColor = vec4( texture2D( map, vUV ).rgb, 0.0 );",
24127
+
24128
+ // restore
24129
+
24130
+ "} else if( renderType == 1 ) {",
24131
+
24132
+ "gl_FragColor = texture2D( map, vUV );",
24133
+
24134
+ // flare
24135
+
24136
+ "} else {",
24137
+
24138
+ "float visibility = texture2D( occlusionMap, vec2( 0.5, 0.1 ) ).a;",
24139
+ "visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) ).a;",
24140
+ "visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) ).a;",
24141
+ "visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) ).a;",
24142
+ "visibility = ( 1.0 - visibility / 4.0 );",
24143
+
24144
+ "vec4 texture = texture2D( map, vUV );",
24145
+ "texture.a *= opacity * visibility;",
24146
+ "gl_FragColor = texture;",
24147
+ "gl_FragColor.rgb *= color;",
24148
+
24149
+ "}",
24150
+
24151
+ "}"
24152
+
24153
+ ].join( "\n" )
24154
+
24155
+ };
24156
+
24157
+ }
24158
+
24159
+ program = createProgram( shader );
24160
+
24161
+ attributes = {
24162
+ vertex: gl.getAttribLocation ( program, "position" ),
24163
+ uv: gl.getAttribLocation ( program, "uv" )
24164
+ }
24165
+
24166
+ uniforms = {
24167
+ renderType: gl.getUniformLocation( program, "renderType" ),
24168
+ map: gl.getUniformLocation( program, "map" ),
24169
+ occlusionMap: gl.getUniformLocation( program, "occlusionMap" ),
24170
+ opacity: gl.getUniformLocation( program, "opacity" ),
24171
+ color: gl.getUniformLocation( program, "color" ),
24172
+ scale: gl.getUniformLocation( program, "scale" ),
24173
+ rotation: gl.getUniformLocation( program, "rotation" ),
24174
+ screenPosition: gl.getUniformLocation( program, "screenPosition" )
24175
+ };
24176
+
24177
+ };
24178
+
24179
+ /*
24180
+ * Render lens flares
24181
+ * Method: renders 16x16 0xff00ff-colored points scattered over the light source area,
24182
+ * reads these back and calculates occlusion.
24183
+ */
24184
+
24185
+ this.render = function ( scene, camera, viewportWidth, viewportHeight ) {
24186
+
24187
+ if ( flares.length === 0 ) return;
24188
+
24189
+ var tempPosition = new THREE.Vector3();
24190
+
24191
+ var invAspect = viewportHeight / viewportWidth,
24192
+ halfViewportWidth = viewportWidth * 0.5,
24193
+ halfViewportHeight = viewportHeight * 0.5;
24194
+
24195
+ var size = 16 / viewportHeight,
24196
+ scale = new THREE.Vector2( size * invAspect, size );
24197
+
24198
+ var screenPosition = new THREE.Vector3( 1, 1, 0 ),
24199
+ screenPositionPixels = new THREE.Vector2( 1, 1 );
24200
+
24201
+ if ( program === undefined ) {
24202
+
24203
+ init();
24204
+
24205
+ }
24206
+
24207
+ gl.useProgram( program );
24208
+
24209
+ gl.enableVertexAttribArray( attributes.vertex );
24210
+ gl.enableVertexAttribArray( attributes.uv );
24211
+
24212
+ // loop through all lens flares to update their occlusion and positions
24213
+ // setup gl and common used attribs/unforms
24214
+
24215
+ gl.uniform1i( uniforms.occlusionMap, 0 );
24216
+ gl.uniform1i( uniforms.map, 1 );
24217
+
24218
+ gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
24219
+ gl.vertexAttribPointer( attributes.vertex, 2, gl.FLOAT, false, 2 * 8, 0 );
24220
+ gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
24221
+
24222
+ gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
24223
+
24224
+ gl.disable( gl.CULL_FACE );
24225
+ gl.depthMask( false );
24226
+
24227
+ for ( var i = 0, l = flares.length; i < l; i ++ ) {
24228
+
24229
+ size = 16 / viewportHeight;
24230
+ scale.set( size * invAspect, size );
24231
+
24232
+ // calc object screen position
24233
+
24234
+ var flare = flares[ i ];
24235
+
24236
+ tempPosition.set( flare.matrixWorld.elements[12], flare.matrixWorld.elements[13], flare.matrixWorld.elements[14] );
24237
+
24238
+ tempPosition.applyMatrix4( camera.matrixWorldInverse );
24239
+ tempPosition.applyProjection( camera.projectionMatrix );
24240
+
24241
+ // setup arrays for gl programs
24242
+
24243
+ screenPosition.copy( tempPosition )
24244
+
24245
+ screenPositionPixels.x = screenPosition.x * halfViewportWidth + halfViewportWidth;
24246
+ screenPositionPixels.y = screenPosition.y * halfViewportHeight + halfViewportHeight;
24247
+
24248
+ // screen cull
24249
+
24250
+ if ( hasVertexTexture || (
24251
+ screenPositionPixels.x > 0 &&
24252
+ screenPositionPixels.x < viewportWidth &&
24253
+ screenPositionPixels.y > 0 &&
24254
+ screenPositionPixels.y < viewportHeight ) ) {
24255
+
24256
+ // save current RGB to temp texture
24257
+
24258
+ gl.activeTexture( gl.TEXTURE1 );
24259
+ gl.bindTexture( gl.TEXTURE_2D, tempTexture );
24260
+ gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGB, screenPositionPixels.x - 8, screenPositionPixels.y - 8, 16, 16, 0 );
24261
+
24262
+
24263
+ // render pink quad
24264
+
24265
+ gl.uniform1i( uniforms.renderType, 0 );
24266
+ gl.uniform2f( uniforms.scale, scale.x, scale.y );
24267
+ gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
24268
+
24269
+ gl.disable( gl.BLEND );
24270
+ gl.enable( gl.DEPTH_TEST );
24271
+
24272
+ gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
24273
+
24274
+
24275
+ // copy result to occlusionMap
24276
+
24277
+ gl.activeTexture( gl.TEXTURE0 );
24278
+ gl.bindTexture( gl.TEXTURE_2D, occlusionTexture );
24279
+ gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGBA, screenPositionPixels.x - 8, screenPositionPixels.y - 8, 16, 16, 0 );
24280
+
24281
+
24282
+ // restore graphics
24283
+
24284
+ gl.uniform1i( uniforms.renderType, 1 );
24285
+ gl.disable( gl.DEPTH_TEST );
24286
+
24287
+ gl.activeTexture( gl.TEXTURE1 );
24288
+ gl.bindTexture( gl.TEXTURE_2D, tempTexture );
24289
+ gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
24290
+
24291
+
24292
+ // update object positions
24293
+
24294
+ flare.positionScreen.copy( screenPosition )
24295
+
24296
+ if ( flare.customUpdateCallback ) {
24297
+
24298
+ flare.customUpdateCallback( flare );
24299
+
24300
+ } else {
24301
+
24302
+ flare.updateLensFlares();
24303
+
24304
+ }
24305
+
24306
+ // render flares
24307
+
24308
+ gl.uniform1i( uniforms.renderType, 2 );
24309
+ gl.enable( gl.BLEND );
24310
+
24311
+ for ( var j = 0, jl = flare.lensFlares.length; j < jl; j ++ ) {
24312
+
24313
+ var sprite = flare.lensFlares[ j ];
24314
+
24315
+ if ( sprite.opacity > 0.001 && sprite.scale > 0.001 ) {
24316
+
24317
+ screenPosition.x = sprite.x;
24318
+ screenPosition.y = sprite.y;
24319
+ screenPosition.z = sprite.z;
24320
+
24321
+ size = sprite.size * sprite.scale / viewportHeight;
24322
+
24323
+ scale.x = size * invAspect;
24324
+ scale.y = size;
24325
+
24326
+ gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
24327
+ gl.uniform2f( uniforms.scale, scale.x, scale.y );
24328
+ gl.uniform1f( uniforms.rotation, sprite.rotation );
24329
+
24330
+ gl.uniform1f( uniforms.opacity, sprite.opacity );
24331
+ gl.uniform3f( uniforms.color, sprite.color.r, sprite.color.g, sprite.color.b );
24332
+
24333
+ renderer.setBlending( sprite.blending, sprite.blendEquation, sprite.blendSrc, sprite.blendDst );
24334
+ renderer.setTexture( sprite.texture, 1 );
24335
+
24336
+ gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
24337
+
24338
+ }
24339
+
24340
+ }
24341
+
24342
+ }
24343
+
24344
+ }
24345
+
24346
+ // restore gl
24347
+
24348
+ gl.enable( gl.CULL_FACE );
24349
+ gl.enable( gl.DEPTH_TEST );
24350
+ gl.depthMask( true );
24351
+
24352
+ renderer.resetGLState();
24353
+
24354
+ };
24355
+
24356
+ function createProgram ( shader ) {
24357
+
24358
+ var program = gl.createProgram();
24359
+
24360
+ var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
24361
+ var vertexShader = gl.createShader( gl.VERTEX_SHADER );
24362
+
24363
+ var prefix = "precision " + renderer.getPrecision() + " float;\n";
24364
+
24365
+ gl.shaderSource( fragmentShader, prefix + shader.fragmentShader );
24366
+ gl.shaderSource( vertexShader, prefix + shader.vertexShader );
24367
+
24368
+ gl.compileShader( fragmentShader );
24369
+ gl.compileShader( vertexShader );
24370
+
24371
+ gl.attachShader( program, fragmentShader );
24372
+ gl.attachShader( program, vertexShader );
24373
+
24374
+ gl.linkProgram( program );
24375
+
24376
+ return program;
24377
+
24378
+ }
24379
+
24380
+ };
24381
+
24382
+ // File:src/renderers/webgl/plugins/ShadowMapPlugin.js
24383
+
24384
+ /**
24385
+ * @author alteredq / http://alteredqualia.com/
24386
+ */
24387
+
24388
+ THREE.ShadowMapPlugin = function ( _renderer, _lights, _webglObjects, _webglObjectsImmediate ) {
24389
+
24390
+ var _gl = _renderer.context;
24391
+
24392
+ var _depthMaterial, _depthMaterialMorph, _depthMaterialSkin, _depthMaterialMorphSkin,
24393
+
24394
+ _frustum = new THREE.Frustum(),
24395
+ _projScreenMatrix = new THREE.Matrix4(),
24396
+
24397
+ _min = new THREE.Vector3(),
24398
+ _max = new THREE.Vector3(),
24399
+
24400
+ _matrixPosition = new THREE.Vector3(),
24401
+
24402
+ _renderList = [];
24403
+
24404
+ // init
24405
+
24406
+ var depthShader = THREE.ShaderLib[ "depthRGBA" ];
24407
+ var depthUniforms = THREE.UniformsUtils.clone( depthShader.uniforms );
24408
+
24409
+ _depthMaterial = new THREE.ShaderMaterial( {
24410
+ uniforms: depthUniforms,
24411
+ vertexShader: depthShader.vertexShader,
24412
+ fragmentShader: depthShader.fragmentShader
24413
+ } );
24414
+
24415
+ _depthMaterialMorph = new THREE.ShaderMaterial( {
24416
+ uniforms: depthUniforms,
24417
+ vertexShader: depthShader.vertexShader,
24418
+ fragmentShader: depthShader.fragmentShader,
24419
+ morphTargets: true
24420
+ } );
24421
+
24422
+ _depthMaterialSkin = new THREE.ShaderMaterial( {
24423
+ uniforms: depthUniforms,
24424
+ vertexShader: depthShader.vertexShader,
24425
+ fragmentShader: depthShader.fragmentShader,
24426
+ skinning: true
24427
+ } );
24428
+
24429
+ _depthMaterialMorphSkin = new THREE.ShaderMaterial( {
24430
+ uniforms: depthUniforms,
24431
+ vertexShader: depthShader.vertexShader,
24432
+ fragmentShader: depthShader.fragmentShader,
24433
+ morphTargets: true,
24434
+ skinning: true
24435
+ } );
24436
+
24437
+ _depthMaterial._shadowPass = true;
24438
+ _depthMaterialMorph._shadowPass = true;
24439
+ _depthMaterialSkin._shadowPass = true;
24440
+ _depthMaterialMorphSkin._shadowPass = true;
24441
+
24442
+ this.render = function ( scene, camera ) {
24443
+
24444
+ if ( _renderer.shadowMapEnabled === false ) return;
24445
+
24446
+ var i, il, j, jl, n,
24447
+
24448
+ shadowMap, shadowMatrix, shadowCamera,
24449
+ program, buffer, material,
24450
+ webglObject, object, light,
24451
+
24452
+ lights = [],
24453
+ k = 0,
24454
+
24455
+ fog = null;
24456
+
24457
+ // set GL state for depth map
24458
+
24459
+ _gl.clearColor( 1, 1, 1, 1 );
24460
+ _gl.disable( _gl.BLEND );
24461
+
24462
+ _gl.enable( _gl.CULL_FACE );
24463
+ _gl.frontFace( _gl.CCW );
24464
+
24465
+ if ( _renderer.shadowMapCullFace === THREE.CullFaceFront ) {
24466
+
24467
+ _gl.cullFace( _gl.FRONT );
24468
+
24469
+ } else {
24470
+
24471
+ _gl.cullFace( _gl.BACK );
24472
+
24473
+ }
24474
+
24475
+ _renderer.setDepthTest( true );
24476
+
24477
+ // preprocess lights
24478
+ // - skip lights that are not casting shadows
24479
+ // - create virtual lights for cascaded shadow maps
24480
+
24481
+ for ( i = 0, il = _lights.length; i < il; i ++ ) {
24482
+
24483
+ light = _lights[ i ];
24484
+
24485
+ if ( ! light.castShadow ) continue;
24486
+
24487
+ if ( ( light instanceof THREE.DirectionalLight ) && light.shadowCascade ) {
24488
+
24489
+ for ( n = 0; n < light.shadowCascadeCount; n ++ ) {
24490
+
24491
+ var virtualLight;
24492
+
24493
+ if ( ! light.shadowCascadeArray[ n ] ) {
24494
+
24495
+ virtualLight = createVirtualLight( light, n );
24496
+ virtualLight.originalCamera = camera;
24497
+
24498
+ var gyro = new THREE.Gyroscope();
24499
+ gyro.position.copy( light.shadowCascadeOffset );
24500
+
24501
+ gyro.add( virtualLight );
24502
+ gyro.add( virtualLight.target );
24503
+
24504
+ camera.add( gyro );
24505
+
24506
+ light.shadowCascadeArray[ n ] = virtualLight;
24507
+
24508
+ console.log( "Created virtualLight", virtualLight );
24509
+
24510
+ } else {
24511
+
24512
+ virtualLight = light.shadowCascadeArray[ n ];
24513
+
24514
+ }
24515
+
24516
+ updateVirtualLight( light, n );
24517
+
24518
+ lights[ k ] = virtualLight;
24519
+ k ++;
24520
+
24521
+ }
24522
+
24523
+ } else {
24524
+
24525
+ lights[ k ] = light;
24526
+ k ++;
24527
+
24528
+ }
24529
+
24530
+ }
24531
+
24532
+ // render depth map
24533
+
24534
+ for ( i = 0, il = lights.length; i < il; i ++ ) {
24535
+
24536
+ light = lights[ i ];
24537
+
24538
+ if ( ! light.shadowMap ) {
24539
+
24540
+ var shadowFilter = THREE.LinearFilter;
24541
+
24542
+ if ( _renderer.shadowMapType === THREE.PCFSoftShadowMap ) {
24543
+
24544
+ shadowFilter = THREE.NearestFilter;
24545
+
24546
+ }
24547
+
24548
+ var pars = { minFilter: shadowFilter, magFilter: shadowFilter, format: THREE.RGBAFormat };
24549
+
24550
+ light.shadowMap = new THREE.WebGLRenderTarget( light.shadowMapWidth, light.shadowMapHeight, pars );
24551
+ light.shadowMapSize = new THREE.Vector2( light.shadowMapWidth, light.shadowMapHeight );
24552
+
24553
+ light.shadowMatrix = new THREE.Matrix4();
24554
+
24555
+ }
24556
+
24557
+ if ( ! light.shadowCamera ) {
24558
+
24559
+ if ( light instanceof THREE.SpotLight ) {
24560
+
24561
+ light.shadowCamera = new THREE.PerspectiveCamera( light.shadowCameraFov, light.shadowMapWidth / light.shadowMapHeight, light.shadowCameraNear, light.shadowCameraFar );
24562
+
24563
+ } else if ( light instanceof THREE.DirectionalLight ) {
24564
+
24565
+ light.shadowCamera = new THREE.OrthographicCamera( light.shadowCameraLeft, light.shadowCameraRight, light.shadowCameraTop, light.shadowCameraBottom, light.shadowCameraNear, light.shadowCameraFar );
24566
+
24567
+ } else {
24568
+
24569
+ console.error( "Unsupported light type for shadow" );
24570
+ continue;
24571
+
24572
+ }
24573
+
24574
+ scene.add( light.shadowCamera );
24575
+
24576
+ if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
24577
+
24578
+ }
24579
+
24580
+ if ( light.shadowCameraVisible && ! light.cameraHelper ) {
24581
+
24582
+ light.cameraHelper = new THREE.CameraHelper( light.shadowCamera );
24583
+ scene.add( light.cameraHelper );
24584
+
24585
+ }
24586
+
24587
+ if ( light.isVirtual && virtualLight.originalCamera == camera ) {
24588
+
24589
+ updateShadowCamera( camera, light );
24590
+
24591
+ }
24592
+
24593
+ shadowMap = light.shadowMap;
24594
+ shadowMatrix = light.shadowMatrix;
24595
+ shadowCamera = light.shadowCamera;
24596
+
24597
+ //
24598
+
24599
+ shadowCamera.position.setFromMatrixPosition( light.matrixWorld );
24600
+ _matrixPosition.setFromMatrixPosition( light.target.matrixWorld );
24601
+ shadowCamera.lookAt( _matrixPosition );
24602
+ shadowCamera.updateMatrixWorld();
24603
+
24604
+ shadowCamera.matrixWorldInverse.getInverse( shadowCamera.matrixWorld );
24605
+
24606
+ //
24607
+
24608
+ if ( light.cameraHelper ) light.cameraHelper.visible = light.shadowCameraVisible;
24609
+ if ( light.shadowCameraVisible ) light.cameraHelper.update();
24610
+
24611
+ // compute shadow matrix
24612
+
24613
+ shadowMatrix.set(
24614
+ 0.5, 0.0, 0.0, 0.5,
24615
+ 0.0, 0.5, 0.0, 0.5,
24616
+ 0.0, 0.0, 0.5, 0.5,
24617
+ 0.0, 0.0, 0.0, 1.0
24618
+ );
24619
+
24620
+ shadowMatrix.multiply( shadowCamera.projectionMatrix );
24621
+ shadowMatrix.multiply( shadowCamera.matrixWorldInverse );
24622
+
24623
+ // update camera matrices and frustum
24624
+
24625
+ _projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
24626
+ _frustum.setFromMatrix( _projScreenMatrix );
24627
+
24628
+ // render shadow map
24629
+
24630
+ _renderer.setRenderTarget( shadowMap );
24631
+ _renderer.clear();
24632
+
24633
+ // set object matrices & frustum culling
24634
+
24635
+ _renderList.length = 0;
24636
+
24637
+ projectObject( scene, scene, shadowCamera );
24638
+
24639
+
24640
+ // render regular objects
24641
+
24642
+ var objectMaterial, useMorphing, useSkinning;
24643
+
24644
+ for ( j = 0, jl = _renderList.length; j < jl; j ++ ) {
24645
+
24646
+ webglObject = _renderList[ j ];
24647
+
24648
+ object = webglObject.object;
24649
+ buffer = webglObject.buffer;
24650
+
24651
+ // culling is overriden globally for all objects
24652
+ // while rendering depth map
24653
+
24654
+ // need to deal with MeshFaceMaterial somehow
24655
+ // in that case just use the first of material.materials for now
24656
+ // (proper solution would require to break objects by materials
24657
+ // similarly to regular rendering and then set corresponding
24658
+ // depth materials per each chunk instead of just once per object)
24659
+
24660
+ objectMaterial = getObjectMaterial( object );
24661
+
24662
+ useMorphing = object.geometry.morphTargets !== undefined && object.geometry.morphTargets.length > 0 && objectMaterial.morphTargets;
24663
+ useSkinning = object instanceof THREE.SkinnedMesh && objectMaterial.skinning;
24664
+
24665
+ if ( object.customDepthMaterial ) {
24666
+
24667
+ material = object.customDepthMaterial;
24668
+
24669
+ } else if ( useSkinning ) {
24670
+
24671
+ material = useMorphing ? _depthMaterialMorphSkin : _depthMaterialSkin;
24672
+
24673
+ } else if ( useMorphing ) {
24674
+
24675
+ material = _depthMaterialMorph;
24676
+
24677
+ } else {
24678
+
24679
+ material = _depthMaterial;
24680
+
24681
+ }
24682
+
24683
+ _renderer.setMaterialFaces( objectMaterial );
24684
+
24685
+ if ( buffer instanceof THREE.BufferGeometry ) {
24686
+
24687
+ _renderer.renderBufferDirect( shadowCamera, _lights, fog, material, buffer, object );
24688
+
24689
+ } else {
24690
+
24691
+ _renderer.renderBuffer( shadowCamera, _lights, fog, material, buffer, object );
24692
+
24693
+ }
24694
+
24695
+ }
24696
+
24697
+ // set matrices and render immediate objects
24698
+
24699
+ for ( j = 0, jl = _webglObjectsImmediate.length; j < jl; j ++ ) {
24700
+
24701
+ webglObject = _webglObjectsImmediate[ j ];
24702
+ object = webglObject.object;
24703
+
24704
+ if ( object.visible && object.castShadow ) {
24705
+
24706
+ object._modelViewMatrix.multiplyMatrices( shadowCamera.matrixWorldInverse, object.matrixWorld );
24707
+
24708
+ _renderer.renderImmediateObject( shadowCamera, _lights, fog, _depthMaterial, object );
24709
+
24710
+ }
24711
+
24712
+ }
24713
+
24714
+ }
24715
+
24716
+ // restore GL state
24717
+
24718
+ var clearColor = _renderer.getClearColor(),
24719
+ clearAlpha = _renderer.getClearAlpha();
24720
+
24721
+ _gl.clearColor( clearColor.r, clearColor.g, clearColor.b, clearAlpha );
24722
+ _gl.enable( _gl.BLEND );
24723
+
24724
+ if ( _renderer.shadowMapCullFace === THREE.CullFaceFront ) {
24725
+
24726
+ _gl.cullFace( _gl.BACK );
24727
+
24728
+ }
24729
+
24730
+ _renderer.resetGLState();
24731
+
24732
+ };
24733
+
24734
+ function projectObject( scene, object, shadowCamera ){
24735
+
24736
+ if ( object.visible ) {
24737
+
24738
+ var webglObjects = _webglObjects[ object.id ];
24739
+
24740
+ if ( webglObjects && object.castShadow && (object.frustumCulled === false || _frustum.intersectsObject( object ) === true) ) {
24741
+
24742
+ for ( var i = 0, l = webglObjects.length; i < l; i ++ ) {
24743
+
24744
+ var webglObject = webglObjects[ i ];
24745
+
24746
+ object._modelViewMatrix.multiplyMatrices( shadowCamera.matrixWorldInverse, object.matrixWorld );
24747
+ _renderList.push( webglObject );
24748
+
24749
+ }
24750
+
24751
+ }
24752
+
24753
+ for ( var i = 0, l = object.children.length; i < l; i ++ ) {
24754
+
24755
+ projectObject( scene, object.children[ i ], shadowCamera );
24756
+
24757
+ }
24758
+
24759
+ }
24760
+
24761
+ }
24762
+
24763
+ function createVirtualLight( light, cascade ) {
24764
+
24765
+ var virtualLight = new THREE.DirectionalLight();
24766
+
24767
+ virtualLight.isVirtual = true;
24768
+
24769
+ virtualLight.onlyShadow = true;
24770
+ virtualLight.castShadow = true;
24771
+
24772
+ virtualLight.shadowCameraNear = light.shadowCameraNear;
24773
+ virtualLight.shadowCameraFar = light.shadowCameraFar;
24774
+
24775
+ virtualLight.shadowCameraLeft = light.shadowCameraLeft;
24776
+ virtualLight.shadowCameraRight = light.shadowCameraRight;
24777
+ virtualLight.shadowCameraBottom = light.shadowCameraBottom;
24778
+ virtualLight.shadowCameraTop = light.shadowCameraTop;
24779
+
24780
+ virtualLight.shadowCameraVisible = light.shadowCameraVisible;
24781
+
24782
+ virtualLight.shadowDarkness = light.shadowDarkness;
24783
+
24784
+ virtualLight.shadowBias = light.shadowCascadeBias[ cascade ];
24785
+ virtualLight.shadowMapWidth = light.shadowCascadeWidth[ cascade ];
24786
+ virtualLight.shadowMapHeight = light.shadowCascadeHeight[ cascade ];
24787
+
24788
+ virtualLight.pointsWorld = [];
24789
+ virtualLight.pointsFrustum = [];
24790
+
24791
+ var pointsWorld = virtualLight.pointsWorld,
24792
+ pointsFrustum = virtualLight.pointsFrustum;
24793
+
24794
+ for ( var i = 0; i < 8; i ++ ) {
24795
+
24796
+ pointsWorld[ i ] = new THREE.Vector3();
24797
+ pointsFrustum[ i ] = new THREE.Vector3();
24798
+
24799
+ }
24800
+
24801
+ var nearZ = light.shadowCascadeNearZ[ cascade ];
24802
+ var farZ = light.shadowCascadeFarZ[ cascade ];
24803
+
24804
+ pointsFrustum[ 0 ].set( - 1, - 1, nearZ );
24805
+ pointsFrustum[ 1 ].set( 1, - 1, nearZ );
24806
+ pointsFrustum[ 2 ].set( - 1, 1, nearZ );
24807
+ pointsFrustum[ 3 ].set( 1, 1, nearZ );
24808
+
24809
+ pointsFrustum[ 4 ].set( - 1, - 1, farZ );
24810
+ pointsFrustum[ 5 ].set( 1, - 1, farZ );
24811
+ pointsFrustum[ 6 ].set( - 1, 1, farZ );
24812
+ pointsFrustum[ 7 ].set( 1, 1, farZ );
24813
+
24814
+ return virtualLight;
24815
+
24816
+ }
24817
+
24818
+ // Synchronize virtual light with the original light
24819
+
24820
+ function updateVirtualLight( light, cascade ) {
24821
+
24822
+ var virtualLight = light.shadowCascadeArray[ cascade ];
24823
+
24824
+ virtualLight.position.copy( light.position );
24825
+ virtualLight.target.position.copy( light.target.position );
24826
+ virtualLight.lookAt( virtualLight.target );
24827
+
24828
+ virtualLight.shadowCameraVisible = light.shadowCameraVisible;
24829
+ virtualLight.shadowDarkness = light.shadowDarkness;
24830
+
24831
+ virtualLight.shadowBias = light.shadowCascadeBias[ cascade ];
24832
+
24833
+ var nearZ = light.shadowCascadeNearZ[ cascade ];
24834
+ var farZ = light.shadowCascadeFarZ[ cascade ];
24835
+
24836
+ var pointsFrustum = virtualLight.pointsFrustum;
24837
+
24838
+ pointsFrustum[ 0 ].z = nearZ;
24839
+ pointsFrustum[ 1 ].z = nearZ;
24840
+ pointsFrustum[ 2 ].z = nearZ;
24841
+ pointsFrustum[ 3 ].z = nearZ;
24842
+
24843
+ pointsFrustum[ 4 ].z = farZ;
24844
+ pointsFrustum[ 5 ].z = farZ;
24845
+ pointsFrustum[ 6 ].z = farZ;
24846
+ pointsFrustum[ 7 ].z = farZ;
24847
+
24848
+ }
24849
+
24850
+ // Fit shadow camera's ortho frustum to camera frustum
24851
+
24852
+ function updateShadowCamera( camera, light ) {
24853
+
24854
+ var shadowCamera = light.shadowCamera,
24855
+ pointsFrustum = light.pointsFrustum,
24856
+ pointsWorld = light.pointsWorld;
24857
+
24858
+ _min.set( Infinity, Infinity, Infinity );
24859
+ _max.set( - Infinity, - Infinity, - Infinity );
24860
+
24861
+ for ( var i = 0; i < 8; i ++ ) {
24862
+
24863
+ var p = pointsWorld[ i ];
24864
+
24865
+ p.copy( pointsFrustum[ i ] );
24866
+ p.unproject( camera );
24867
+
24868
+ p.applyMatrix4( shadowCamera.matrixWorldInverse );
24869
+
24870
+ if ( p.x < _min.x ) _min.x = p.x;
24871
+ if ( p.x > _max.x ) _max.x = p.x;
24872
+
24873
+ if ( p.y < _min.y ) _min.y = p.y;
24874
+ if ( p.y > _max.y ) _max.y = p.y;
24875
+
24876
+ if ( p.z < _min.z ) _min.z = p.z;
24877
+ if ( p.z > _max.z ) _max.z = p.z;
24878
+
24879
+ }
24880
+
24881
+ shadowCamera.left = _min.x;
24882
+ shadowCamera.right = _max.x;
24883
+ shadowCamera.top = _max.y;
24884
+ shadowCamera.bottom = _min.y;
24885
+
24886
+ // can't really fit near/far
24887
+ //shadowCamera.near = _min.z;
24888
+ //shadowCamera.far = _max.z;
24889
+
24890
+ shadowCamera.updateProjectionMatrix();
24891
+
24892
+ }
24893
+
24894
+ // For the moment just ignore objects that have multiple materials with different animation methods
24895
+ // Only the first material will be taken into account for deciding which depth material to use for shadow maps
24896
+
24897
+ function getObjectMaterial( object ) {
24898
+
24899
+ return object.material instanceof THREE.MeshFaceMaterial
24900
+ ? object.material.materials[ 0 ]
24901
+ : object.material;
24902
+
24903
+ };
24904
+
24905
+ };
24906
+
24907
+ // File:src/renderers/webgl/plugins/SpritePlugin.js
24908
+
24909
+ /**
24910
+ * @author mikael emtinger / http://gomo.se/
24911
+ * @author alteredq / http://alteredqualia.com/
24912
+ */
24913
+
24914
+ THREE.SpritePlugin = function ( renderer, sprites ) {
24915
+
24916
+ var gl = renderer.context;
24917
+
24918
+ var vertexBuffer, elementBuffer;
24919
+ var program, attributes, uniforms;
24920
+
24921
+ var texture;
24922
+
24923
+ var init = function () {
24924
+
24925
+ var vertices = new Float32Array( [
24926
+ - 0.5, - 0.5, 0, 0,
24927
+ 0.5, - 0.5, 1, 0,
24928
+ 0.5, 0.5, 1, 1,
24929
+ - 0.5, 0.5, 0, 1
24930
+ ] );
24931
+
24932
+ var faces = new Uint16Array( [
24933
+ 0, 1, 2,
24934
+ 0, 2, 3
24935
+ ] );
24936
+
24937
+ vertexBuffer = gl.createBuffer();
24938
+ elementBuffer = gl.createBuffer();
24939
+
24940
+ gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
24941
+ gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
24942
+
24943
+ gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
24944
+ gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
24945
+
24946
+ program = createProgram();
24947
+
24948
+ attributes = {
24949
+ position: gl.getAttribLocation ( program, 'position' ),
24950
+ uv: gl.getAttribLocation ( program, 'uv' )
24951
+ };
24952
+
24953
+ uniforms = {
24954
+ uvOffset: gl.getUniformLocation( program, 'uvOffset' ),
24955
+ uvScale: gl.getUniformLocation( program, 'uvScale' ),
24956
+
24957
+ rotation: gl.getUniformLocation( program, 'rotation' ),
24958
+ scale: gl.getUniformLocation( program, 'scale' ),
24959
+
24960
+ color: gl.getUniformLocation( program, 'color' ),
24961
+ map: gl.getUniformLocation( program, 'map' ),
24962
+ opacity: gl.getUniformLocation( program, 'opacity' ),
24963
+
24964
+ modelViewMatrix: gl.getUniformLocation( program, 'modelViewMatrix' ),
24965
+ projectionMatrix: gl.getUniformLocation( program, 'projectionMatrix' ),
24966
+
24967
+ fogType: gl.getUniformLocation( program, 'fogType' ),
24968
+ fogDensity: gl.getUniformLocation( program, 'fogDensity' ),
24969
+ fogNear: gl.getUniformLocation( program, 'fogNear' ),
24970
+ fogFar: gl.getUniformLocation( program, 'fogFar' ),
24971
+ fogColor: gl.getUniformLocation( program, 'fogColor' ),
24972
+
24973
+ alphaTest: gl.getUniformLocation( program, 'alphaTest' )
24974
+ };
24975
+
24976
+ var canvas = document.createElement( 'canvas' );
24977
+ canvas.width = 8;
24978
+ canvas.height = 8;
24979
+
24980
+ var context = canvas.getContext( '2d' );
24981
+ context.fillStyle = 'white';
24982
+ context.fillRect( 0, 0, 8, 8 );
24983
+
24984
+ texture = new THREE.Texture( canvas );
24985
+ texture.needsUpdate = true;
24986
+
24987
+ };
24988
+
24989
+ this.render = function ( scene, camera ) {
24990
+
24991
+ if ( sprites.length === 0 ) return;
24992
+
24993
+ // setup gl
24994
+
24995
+ if ( program === undefined ) {
24996
+
24997
+ init();
24998
+
24999
+ }
25000
+
25001
+ gl.useProgram( program );
25002
+
25003
+ gl.enableVertexAttribArray( attributes.position );
25004
+ gl.enableVertexAttribArray( attributes.uv );
25005
+
25006
+ gl.disable( gl.CULL_FACE );
25007
+ gl.enable( gl.BLEND );
25008
+
25009
+ gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
25010
+ gl.vertexAttribPointer( attributes.position, 2, gl.FLOAT, false, 2 * 8, 0 );
25011
+ gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
25012
+
25013
+ gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
25014
+
25015
+ gl.uniformMatrix4fv( uniforms.projectionMatrix, false, camera.projectionMatrix.elements );
25016
+
25017
+ gl.activeTexture( gl.TEXTURE0 );
25018
+ gl.uniform1i( uniforms.map, 0 );
25019
+
25020
+ var oldFogType = 0;
25021
+ var sceneFogType = 0;
25022
+ var fog = scene.fog;
25023
+
25024
+ if ( fog ) {
25025
+
25026
+ gl.uniform3f( uniforms.fogColor, fog.color.r, fog.color.g, fog.color.b );
25027
+
25028
+ if ( fog instanceof THREE.Fog ) {
25029
+
25030
+ gl.uniform1f( uniforms.fogNear, fog.near );
25031
+ gl.uniform1f( uniforms.fogFar, fog.far );
25032
+
25033
+ gl.uniform1i( uniforms.fogType, 1 );
25034
+ oldFogType = 1;
25035
+ sceneFogType = 1;
25036
+
25037
+ } else if ( fog instanceof THREE.FogExp2 ) {
25038
+
25039
+ gl.uniform1f( uniforms.fogDensity, fog.density );
25040
+
25041
+ gl.uniform1i( uniforms.fogType, 2 );
25042
+ oldFogType = 2;
25043
+ sceneFogType = 2;
25044
+
25045
+ }
25046
+
25047
+ } else {
25048
+
25049
+ gl.uniform1i( uniforms.fogType, 0 );
25050
+ oldFogType = 0;
25051
+ sceneFogType = 0;
25052
+
25053
+ }
25054
+
25055
+
25056
+ // update positions and sort
25057
+
25058
+ for ( var i = 0, l = sprites.length; i < l; i ++ ) {
25059
+
25060
+ var sprite = sprites[ i ];
25061
+
25062
+ sprite._modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, sprite.matrixWorld );
25063
+
25064
+ if ( sprite.renderDepth === null ) {
25065
+
25066
+ sprite.z = - sprite._modelViewMatrix.elements[ 14 ];
25067
+
25068
+ } else {
25069
+
25070
+ sprite.z = sprite.renderDepth;
25071
+
25072
+ }
25073
+
25074
+ }
25075
+
25076
+ sprites.sort( painterSortStable );
25077
+
25078
+ // render all sprites
25079
+
25080
+ var scale = [];
25081
+
25082
+ for ( var i = 0, l = sprites.length; i < l; i ++ ) {
25083
+
25084
+ var sprite = sprites[ i ];
25085
+ var material = sprite.material;
25086
+
25087
+ gl.uniform1f( uniforms.alphaTest, material.alphaTest );
25088
+ gl.uniformMatrix4fv( uniforms.modelViewMatrix, false, sprite._modelViewMatrix.elements );
25089
+
25090
+ scale[ 0 ] = sprite.scale.x;
25091
+ scale[ 1 ] = sprite.scale.y;
25092
+
25093
+ var fogType = 0;
25094
+
25095
+ if ( scene.fog && material.fog ) {
25096
+
25097
+ fogType = sceneFogType;
25098
+
25099
+ }
25100
+
25101
+ if ( oldFogType !== fogType ) {
25102
+
25103
+ gl.uniform1i( uniforms.fogType, fogType );
25104
+ oldFogType = fogType;
25105
+
25106
+ }
25107
+
25108
+ if ( material.map !== null ) {
25109
+
25110
+ gl.uniform2f( uniforms.uvOffset, material.map.offset.x, material.map.offset.y );
25111
+ gl.uniform2f( uniforms.uvScale, material.map.repeat.x, material.map.repeat.y );
25112
+
25113
+ } else {
25114
+
25115
+ gl.uniform2f( uniforms.uvOffset, 0, 0 );
25116
+ gl.uniform2f( uniforms.uvScale, 1, 1 );
25117
+
25118
+ }
25119
+
25120
+ gl.uniform1f( uniforms.opacity, material.opacity );
25121
+ gl.uniform3f( uniforms.color, material.color.r, material.color.g, material.color.b );
25122
+
25123
+ gl.uniform1f( uniforms.rotation, material.rotation );
25124
+ gl.uniform2fv( uniforms.scale, scale );
25125
+
25126
+ renderer.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst );
25127
+ renderer.setDepthTest( material.depthTest );
25128
+ renderer.setDepthWrite( material.depthWrite );
25129
+
25130
+ if ( material.map && material.map.image && material.map.image.width ) {
25131
+
25132
+ renderer.setTexture( material.map, 0 );
25133
+
25134
+ } else {
25135
+
25136
+ renderer.setTexture( texture, 0 );
25137
+
25138
+ }
25139
+
25140
+ gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
25141
+
25142
+ }
25143
+
25144
+ // restore gl
25145
+
25146
+ gl.enable( gl.CULL_FACE );
25147
+
25148
+ renderer.resetGLState();
25149
+
25150
+ };
25151
+
25152
+ function createProgram () {
25153
+
25154
+ var program = gl.createProgram();
25155
+
25156
+ var vertexShader = gl.createShader( gl.VERTEX_SHADER );
25157
+ var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
25158
+
25159
+ gl.shaderSource( vertexShader, [
25160
+
25161
+ 'precision ' + renderer.getPrecision() + ' float;',
25162
+
25163
+ 'uniform mat4 modelViewMatrix;',
25164
+ 'uniform mat4 projectionMatrix;',
25165
+ 'uniform float rotation;',
25166
+ 'uniform vec2 scale;',
25167
+ 'uniform vec2 uvOffset;',
25168
+ 'uniform vec2 uvScale;',
25169
+
25170
+ 'attribute vec2 position;',
25171
+ 'attribute vec2 uv;',
25172
+
25173
+ 'varying vec2 vUV;',
25174
+
25175
+ 'void main() {',
25176
+
25177
+ 'vUV = uvOffset + uv * uvScale;',
25178
+
25179
+ 'vec2 alignedPosition = position * scale;',
25180
+
25181
+ 'vec2 rotatedPosition;',
25182
+ 'rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;',
25183
+ 'rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;',
25184
+
25185
+ 'vec4 finalPosition;',
25186
+
25187
+ 'finalPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );',
25188
+ 'finalPosition.xy += rotatedPosition;',
25189
+ 'finalPosition = projectionMatrix * finalPosition;',
25190
+
25191
+ 'gl_Position = finalPosition;',
25192
+
25193
+ '}'
25194
+
25195
+ ].join( '\n' ) );
25196
+
25197
+ gl.shaderSource( fragmentShader, [
25198
+
25199
+ 'precision ' + renderer.getPrecision() + ' float;',
25200
+
25201
+ 'uniform vec3 color;',
25202
+ 'uniform sampler2D map;',
25203
+ 'uniform float opacity;',
25204
+
25205
+ 'uniform int fogType;',
25206
+ 'uniform vec3 fogColor;',
25207
+ 'uniform float fogDensity;',
25208
+ 'uniform float fogNear;',
25209
+ 'uniform float fogFar;',
25210
+ 'uniform float alphaTest;',
25211
+
25212
+ 'varying vec2 vUV;',
25213
+
25214
+ 'void main() {',
25215
+
25216
+ 'vec4 texture = texture2D( map, vUV );',
25217
+
25218
+ 'if ( texture.a < alphaTest ) discard;',
25219
+
25220
+ 'gl_FragColor = vec4( color * texture.xyz, texture.a * opacity );',
25221
+
25222
+ 'if ( fogType > 0 ) {',
25223
+
25224
+ 'float depth = gl_FragCoord.z / gl_FragCoord.w;',
25225
+ 'float fogFactor = 0.0;',
25226
+
25227
+ 'if ( fogType == 1 ) {',
25228
+
25229
+ 'fogFactor = smoothstep( fogNear, fogFar, depth );',
25230
+
25231
+ '} else {',
25232
+
25233
+ 'const float LOG2 = 1.442695;',
25234
+ 'float fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );',
25235
+ 'fogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );',
25236
+
25237
+ '}',
25238
+
25239
+ 'gl_FragColor = mix( gl_FragColor, vec4( fogColor, gl_FragColor.w ), fogFactor );',
25240
+
25241
+ '}',
25242
+
25243
+ '}'
25244
+
25245
+ ].join( '\n' ) );
25246
+
25247
+ gl.compileShader( vertexShader );
25248
+ gl.compileShader( fragmentShader );
25249
+
25250
+ gl.attachShader( program, vertexShader );
25251
+ gl.attachShader( program, fragmentShader );
25252
+
25253
+ gl.linkProgram( program );
25254
+
25255
+ return program;
25256
+
25257
+ };
25258
+
25259
+ function painterSortStable ( a, b ) {
25260
+
25261
+ if ( a.z !== b.z ) {
25262
+
25263
+ return b.z - a.z;
25264
+
25265
+ } else {
25266
+
25267
+ return b.id - a.id;
25268
+
25269
+ }
25270
+
25271
+ };
25272
+
25273
+ };
25274
+
25275
+
25276
+ THREE.ImageUtils = {
25277
+
25278
+ crossOrigin: undefined,
25279
+
25280
+ loadTexture: function ( url, mapping, onLoad, onError ) {
25281
+
25282
+ var loader = new THREE.ImageLoader();
25283
+ loader.crossOrigin = this.crossOrigin;
25284
+
25285
+ var texture = new THREE.Texture( undefined, mapping );
25286
+
25287
+ loader.load( url, function ( image ) {
25288
+
25289
+ texture.image = image;
25290
+ texture.needsUpdate = true;
25291
+
25292
+ if ( onLoad ) onLoad( texture );
25293
+
25294
+ }, undefined, function ( event ) {
25295
+
25296
+ if ( onError ) onError( event );
25297
+
25298
+ } );
25299
+
25300
+ texture.sourceFile = url;
25301
+
25302
+ return texture;
25303
+
25304
+ },
25305
+
25306
+ loadTextureCube: function ( array, mapping, onLoad, onError ) {
25307
+
25308
+ var images = [];
25309
+
25310
+ var loader = new THREE.ImageLoader();
25311
+ loader.crossOrigin = this.crossOrigin;
25312
+
25313
+ var texture = new THREE.CubeTexture( images, mapping );
25314
+
25315
+ // no flipping needed for cube textures
25316
+
25317
+ texture.flipY = false;
25318
+
25319
+ var loaded = 0;
25320
+
25321
+ var loadTexture = function ( i ) {
25322
+
25323
+ loader.load( array[ i ], function ( image ) {
25324
+
25325
+ texture.images[ i ] = image;
25326
+
25327
+ loaded += 1;
25328
+
25329
+ if ( loaded === 6 ) {
25330
+
25331
+ texture.needsUpdate = true;
25332
+
25333
+ if ( onLoad ) onLoad( texture );
25334
+
25335
+ }
25336
+
25337
+ } );
25338
+
25339
+ }
25340
+
25341
+ for ( var i = 0, il = array.length; i < il; ++ i ) {
25342
+
25343
+ loadTexture( i );
25344
+
25345
+ }
25346
+
25347
+ return texture;
25348
+
25349
+ },
25350
+
25351
+ loadCompressedTexture: function () {
25352
+
25353
+ console.error( 'THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.' )
25354
+
25355
+ },
25356
+
25357
+ loadCompressedTextureCube: function () {
25358
+
25359
+ console.error( 'THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.' )
25360
+
25361
+ },
25362
+
25363
+ getNormalMap: function ( image, depth ) {
25364
+
25365
+ // Adapted from http://www.paulbrunt.co.uk/lab/heightnormal/
25366
+
25367
+ var cross = function ( a, b ) {
25368
+
25369
+ return [ a[ 1 ] * b[ 2 ] - a[ 2 ] * b[ 1 ], a[ 2 ] * b[ 0 ] - a[ 0 ] * b[ 2 ], a[ 0 ] * b[ 1 ] - a[ 1 ] * b[ 0 ] ];
25370
+
25371
+ }
25372
+
25373
+ var subtract = function ( a, b ) {
25374
+
25375
+ return [ a[ 0 ] - b[ 0 ], a[ 1 ] - b[ 1 ], a[ 2 ] - b[ 2 ] ];
25376
+
25377
+ }
25378
+
25379
+ var normalize = function ( a ) {
25380
+
25381
+ var l = Math.sqrt( a[ 0 ] * a[ 0 ] + a[ 1 ] * a[ 1 ] + a[ 2 ] * a[ 2 ] );
25382
+ return [ a[ 0 ] / l, a[ 1 ] / l, a[ 2 ] / l ];
25383
+
25384
+ }
25385
+
25386
+ depth = depth | 1;
25387
+
25388
+ var width = image.width;
25389
+ var height = image.height;
25390
+
25391
+ var canvas = document.createElement( 'canvas' );
25392
+ canvas.width = width;
25393
+ canvas.height = height;
25394
+
25395
+ var context = canvas.getContext( '2d' );
25396
+ context.drawImage( image, 0, 0 );
25397
+
25398
+ var data = context.getImageData( 0, 0, width, height ).data;
25399
+ var imageData = context.createImageData( width, height );
25400
+ var output = imageData.data;
25401
+
25402
+ for ( var x = 0; x < width; x ++ ) {
25403
+
25404
+ for ( var y = 0; y < height; y ++ ) {
25405
+
25406
+ var ly = y - 1 < 0 ? 0 : y - 1;
25407
+ var uy = y + 1 > height - 1 ? height - 1 : y + 1;
25408
+ var lx = x - 1 < 0 ? 0 : x - 1;
25409
+ var ux = x + 1 > width - 1 ? width - 1 : x + 1;
25410
+
25411
+ var points = [];
25412
+ var origin = [ 0, 0, data[ ( y * width + x ) * 4 ] / 255 * depth ];
25413
+ points.push( [ - 1, 0, data[ ( y * width + lx ) * 4 ] / 255 * depth ] );
25414
+ points.push( [ - 1, - 1, data[ ( ly * width + lx ) * 4 ] / 255 * depth ] );
25415
+ points.push( [ 0, - 1, data[ ( ly * width + x ) * 4 ] / 255 * depth ] );
25416
+ points.push( [ 1, - 1, data[ ( ly * width + ux ) * 4 ] / 255 * depth ] );
25417
+ points.push( [ 1, 0, data[ ( y * width + ux ) * 4 ] / 255 * depth ] );
25418
+ points.push( [ 1, 1, data[ ( uy * width + ux ) * 4 ] / 255 * depth ] );
25419
+ points.push( [ 0, 1, data[ ( uy * width + x ) * 4 ] / 255 * depth ] );
25420
+ points.push( [ - 1, 1, data[ ( uy * width + lx ) * 4 ] / 255 * depth ] );
25421
+
25422
+ var normals = [];
25423
+ var num_points = points.length;
25424
+
25425
+ for ( var i = 0; i < num_points; i ++ ) {
25426
+
25427
+ var v1 = points[ i ];
25428
+ var v2 = points[ ( i + 1 ) % num_points ];
25429
+ v1 = subtract( v1, origin );
25430
+ v2 = subtract( v2, origin );
25431
+ normals.push( normalize( cross( v1, v2 ) ) );
25432
+
25433
+ }
25434
+
25435
+ var normal = [ 0, 0, 0 ];
25436
+
25437
+ for ( var i = 0; i < normals.length; i ++ ) {
25438
+
25439
+ normal[ 0 ] += normals[ i ][ 0 ];
25440
+ normal[ 1 ] += normals[ i ][ 1 ];
25441
+ normal[ 2 ] += normals[ i ][ 2 ];
25442
+
25443
+ }
25444
+
25445
+ normal[ 0 ] /= normals.length;
25446
+ normal[ 1 ] /= normals.length;
25447
+ normal[ 2 ] /= normals.length;
25448
+
25449
+ var idx = ( y * width + x ) * 4;
25450
+
25451
+ output[ idx ] = ( ( normal[ 0 ] + 1.0 ) / 2.0 * 255 ) | 0;
25452
+ output[ idx + 1 ] = ( ( normal[ 1 ] + 1.0 ) / 2.0 * 255 ) | 0;
25453
+ output[ idx + 2 ] = ( normal[ 2 ] * 255 ) | 0;
25454
+ output[ idx + 3 ] = 255;
25455
+
25456
+ }
25457
+
25458
+ }
25459
+
25460
+ context.putImageData( imageData, 0, 0 );
25461
+
25462
+ return canvas;
25463
+
25464
+ },
25465
+
25466
+ generateDataTexture: function ( width, height, color ) {
25467
+
25468
+ var size = width * height;
25469
+ var data = new Uint8Array( 3 * size );
25470
+
25471
+ var r = Math.floor( color.r * 255 );
25472
+ var g = Math.floor( color.g * 255 );
25473
+ var b = Math.floor( color.b * 255 );
25474
+
25475
+ for ( var i = 0; i < size; i ++ ) {
25476
+
25477
+ data[ i * 3 ] = r;
25478
+ data[ i * 3 + 1 ] = g;
25479
+ data[ i * 3 + 2 ] = b;
25480
+
25481
+ }
25482
+
25483
+ var texture = new THREE.DataTexture( data, width, height, THREE.RGBFormat );
25484
+ texture.needsUpdate = true;
25485
+
25486
+ return texture;
25487
+
25488
+ }
25489
+
25490
+ };
25491
+
25492
+
25493
+ // File:src/extras/geometries/SphereGeometry.js
25494
+
25495
+ /**
25496
+ * @author mrdoob / http://mrdoob.com/
25497
+ */
25498
+
25499
+ THREE.SphereGeometry = function ( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
25500
+
25501
+ THREE.Geometry.call( this );
25502
+
25503
+ this.type = 'SphereGeometry';
25504
+
25505
+ this.parameters = {
25506
+ radius: radius,
25507
+ widthSegments: widthSegments,
25508
+ heightSegments: heightSegments,
25509
+ phiStart: phiStart,
25510
+ phiLength: phiLength,
25511
+ thetaStart: thetaStart,
25512
+ thetaLength: thetaLength
25513
+ };
25514
+
25515
+ radius = radius || 50;
25516
+
25517
+ widthSegments = Math.max( 3, Math.floor( widthSegments ) || 8 );
25518
+ heightSegments = Math.max( 2, Math.floor( heightSegments ) || 6 );
25519
+
25520
+ phiStart = phiStart !== undefined ? phiStart : 0;
25521
+ phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
25522
+
25523
+ thetaStart = thetaStart !== undefined ? thetaStart : 0;
25524
+ thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
25525
+
25526
+ var x, y, vertices = [], uvs = [];
25527
+
25528
+ for ( y = 0; y <= heightSegments; y ++ ) {
25529
+
25530
+ var verticesRow = [];
25531
+ var uvsRow = [];
25532
+
25533
+ for ( x = 0; x <= widthSegments; x ++ ) {
25534
+
25535
+ var u = x / widthSegments;
25536
+ var v = y / heightSegments;
25537
+
25538
+ var vertex = new THREE.Vector3();
25539
+ vertex.x = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
25540
+ vertex.y = radius * Math.cos( thetaStart + v * thetaLength );
25541
+ vertex.z = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
25542
+
25543
+ this.vertices.push( vertex );
25544
+
25545
+ verticesRow.push( this.vertices.length - 1 );
25546
+ uvsRow.push( new THREE.Vector2( u, 1 - v ) );
25547
+
25548
+ }
25549
+
25550
+ vertices.push( verticesRow );
25551
+ uvs.push( uvsRow );
25552
+
25553
+ }
25554
+
25555
+ for ( y = 0; y < heightSegments; y ++ ) {
25556
+
25557
+ for ( x = 0; x < widthSegments; x ++ ) {
25558
+
25559
+ var v1 = vertices[ y ][ x + 1 ];
25560
+ var v2 = vertices[ y ][ x ];
25561
+ var v3 = vertices[ y + 1 ][ x ];
25562
+ var v4 = vertices[ y + 1 ][ x + 1 ];
25563
+
25564
+ var n1 = this.vertices[ v1 ].clone().normalize();
25565
+ var n2 = this.vertices[ v2 ].clone().normalize();
25566
+ var n3 = this.vertices[ v3 ].clone().normalize();
25567
+ var n4 = this.vertices[ v4 ].clone().normalize();
25568
+
25569
+ var uv1 = uvs[ y ][ x + 1 ].clone();
25570
+ var uv2 = uvs[ y ][ x ].clone();
25571
+ var uv3 = uvs[ y + 1 ][ x ].clone();
25572
+ var uv4 = uvs[ y + 1 ][ x + 1 ].clone();
25573
+
25574
+ if ( Math.abs( this.vertices[ v1 ].y ) === radius ) {
25575
+
25576
+ uv1.x = ( uv1.x + uv2.x ) / 2;
25577
+ this.faces.push( new THREE.Face3( v1, v3, v4, [ n1, n3, n4 ] ) );
25578
+ this.faceVertexUvs[ 0 ].push( [ uv1, uv3, uv4 ] );
25579
+
25580
+ } else if ( Math.abs( this.vertices[ v3 ].y ) === radius ) {
25581
+
25582
+ uv3.x = ( uv3.x + uv4.x ) / 2;
25583
+ this.faces.push( new THREE.Face3( v1, v2, v3, [ n1, n2, n3 ] ) );
25584
+ this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv3 ] );
25585
+
25586
+ } else {
25587
+
25588
+ this.faces.push( new THREE.Face3( v1, v2, v4, [ n1, n2, n4 ] ) );
25589
+ this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv4 ] );
25590
+
25591
+ this.faces.push( new THREE.Face3( v2, v3, v4, [ n2.clone(), n3, n4.clone() ] ) );
25592
+ this.faceVertexUvs[ 0 ].push( [ uv2.clone(), uv3, uv4.clone() ] );
25593
+
25594
+ }
25595
+
25596
+ }
25597
+
25598
+ }
25599
+
25600
+ this.computeFaceNormals();
25601
+
25602
+ this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
25603
+
25604
+ };
25605
+
25606
+ THREE.SphereGeometry.prototype = Object.create( THREE.Geometry.prototype );
25607
+
js/wppa-panorama.min.js ADDED
@@ -0,0 +1 @@
 
1
+ var THREE={REVISION:"69"};"object"==typeof module&&(module.exports=THREE),void 0===Math.sign&&(Math.sign=function(t){return t<0?-1:0<t?1:0}),THREE.MOUSE={LEFT:0,MIDDLE:1,RIGHT:2},THREE.CullFaceNone=0,THREE.CullFaceBack=1,THREE.CullFaceFront=2,THREE.CullFaceFrontBack=3,THREE.FrontFaceDirectionCW=0,THREE.FrontFaceDirectionCCW=1,THREE.BasicShadowMap=0,THREE.PCFShadowMap=1,THREE.PCFSoftShadowMap=2,THREE.FrontSide=0,THREE.BackSide=1,THREE.DoubleSide=2,THREE.NoShading=0,THREE.FlatShading=1,THREE.SmoothShading=2,THREE.NoColors=0,THREE.FaceColors=1,THREE.VertexColors=2,THREE.NoBlending=0,THREE.NormalBlending=1,THREE.AdditiveBlending=2,THREE.SubtractiveBlending=3,THREE.MultiplyBlending=4,THREE.CustomBlending=5,THREE.AddEquation=100,THREE.SubtractEquation=101,THREE.ReverseSubtractEquation=102,THREE.MinEquation=103,THREE.MaxEquation=104,THREE.ZeroFactor=200,THREE.OneFactor=201,THREE.SrcColorFactor=202,THREE.OneMinusSrcColorFactor=203,THREE.SrcAlphaFactor=204,THREE.OneMinusSrcAlphaFactor=205,THREE.DstAlphaFactor=206,THREE.OneMinusDstAlphaFactor=207,THREE.DstColorFactor=208,THREE.OneMinusDstColorFactor=209,THREE.SrcAlphaSaturateFactor=210,THREE.MultiplyOperation=0,THREE.MixOperation=1,THREE.AddOperation=2,THREE.UVMapping=function(){},THREE.CubeReflectionMapping=function(){},THREE.CubeRefractionMapping=function(){},THREE.SphericalReflectionMapping=function(){},THREE.SphericalRefractionMapping=function(){},THREE.RepeatWrapping=1e3,THREE.ClampToEdgeWrapping=1001,THREE.MirroredRepeatWrapping=1002,THREE.NearestFilter=1003,THREE.NearestMipMapNearestFilter=1004,THREE.NearestMipMapLinearFilter=1005,THREE.LinearFilter=1006,THREE.LinearMipMapNearestFilter=1007,THREE.LinearMipMapLinearFilter=1008,THREE.UnsignedByteType=1009,THREE.ByteType=1010,THREE.ShortType=1011,THREE.UnsignedShortType=1012,THREE.IntType=1013,THREE.UnsignedIntType=1014,THREE.FloatType=1015,THREE.UnsignedShort4444Type=1016,THREE.UnsignedShort5551Type=1017,THREE.UnsignedShort565Type=1018,THREE.AlphaFormat=1019,THREE.RGBFormat=1020,THREE.RGBAFormat=1021,THREE.LuminanceFormat=1022,THREE.LuminanceAlphaFormat=1023,THREE.RGB_S3TC_DXT1_Format=2001,THREE.RGBA_S3TC_DXT1_Format=2002,THREE.RGBA_S3TC_DXT3_Format=2003,THREE.RGBA_S3TC_DXT5_Format=2004,THREE.RGB_PVRTC_4BPPV1_Format=2100,THREE.RGB_PVRTC_2BPPV1_Format=2101,THREE.RGBA_PVRTC_4BPPV1_Format=2102,THREE.RGBA_PVRTC_2BPPV1_Format=2103,THREE.Color=function(t){return 3===arguments.length?this.setRGB(t,arguments[1],arguments[2]):this.set(t)},THREE.Color.prototype={constructor:THREE.Color,r:1,g:1,b:1,set:function(t){return t instanceof THREE.Color?this.copy(t):"number"==typeof t?this.setHex(t):"string"==typeof t&&this.setStyle(t),this},setHex:function(t){return t=Math.floor(t),this.r=(t>>16&255)/255,this.g=(t>>8&255)/255,this.b=(255&t)/255,this},setRGB:function(t,e,r){return this.r=t,this.g=e,this.b=r,this},setHSL:function(t,e,r){if(0===e)this.r=this.g=this.b=r;else{var i=function(t,e,r){return r<0&&(r+=1),1<r&&(r-=1),r<1/6?t+6*(e-t)*r:r<.5?e:r<2/3?t+6*(e-t)*(2/3-r):t},n=r<=.5?r*(1+e):r+e-r*e,a=2*r-n;this.r=i(a,n,t+1/3),this.g=i(a,n,t),this.b=i(a,n,t-1/3)}return this},setStyle:function(t){if(/^rgb\((\d+), ?(\d+), ?(\d+)\)$/i.test(t)){var e=/^rgb\((\d+), ?(\d+), ?(\d+)\)$/i.exec(t);return this.r=Math.min(255,parseInt(e[1],10))/255,this.g=Math.min(255,parseInt(e[2],10))/255,this.b=Math.min(255,parseInt(e[3],10))/255,this}if(/^rgb\((\d+)\%, ?(\d+)\%, ?(\d+)\%\)$/i.test(t)){e=/^rgb\((\d+)\%, ?(\d+)\%, ?(\d+)\%\)$/i.exec(t);return this.r=Math.min(100,parseInt(e[1],10))/100,this.g=Math.min(100,parseInt(e[2],10))/100,this.b=Math.min(100,parseInt(e[3],10))/100,this}if(/^\#([0-9a-f]{6})$/i.test(t)){e=/^\#([0-9a-f]{6})$/i.exec(t);return this.setHex(parseInt(e[1],16)),this}if(/^\#([0-9a-f])([0-9a-f])([0-9a-f])$/i.test(t)){e=/^\#([0-9a-f])([0-9a-f])([0-9a-f])$/i.exec(t);return this.setHex(parseInt(e[1]+e[1]+e[2]+e[2]+e[3]+e[3],16)),this}if(/^(\w+)$/i.test(t))return this.setHex(THREE.ColorKeywords[t]),this},copy:function(t){return this.r=t.r,this.g=t.g,this.b=t.b,this},copyGammaToLinear:function(t){return this.r=t.r*t.r,this.g=t.g*t.g,this.b=t.b*t.b,this},copyLinearToGamma:function(t){return this.r=Math.sqrt(t.r),this.g=Math.sqrt(t.g),this.b=Math.sqrt(t.b),this},convertGammaToLinear:function(){var t=this.r,e=this.g,r=this.b;return this.r=t*t,this.g=e*e,this.b=r*r,this},convertLinearToGamma:function(){return this.r=Math.sqrt(this.r),this.g=Math.sqrt(this.g),this.b=Math.sqrt(this.b),this},getHex:function(){return 255*this.r<<16^255*this.g<<8^255*this.b<<0},getHexString:function(){return("000000"+this.getHex().toString(16)).slice(-6)},getHSL:function(t){var e,r,i=t||{h:0,s:0,l:0},n=this.r,a=this.g,o=this.b,s=Math.max(n,a,o),h=Math.min(n,a,o),l=(h+s)/2;if(h===s)r=e=0;else{var u=s-h;switch(r=l<=.5?u/(s+h):u/(2-s-h),s){case n:e=(a-o)/u+(a<o?6:0);break;case a:e=(o-n)/u+2;break;case o:e=(n-a)/u+4}e/=6}return i.h=e,i.s=r,i.l=l,i},getStyle:function(){return"rgb("+(255*this.r|0)+","+(255*this.g|0)+","+(255*this.b|0)+")"},offsetHSL:function(t,e,r){var i=this.getHSL();return i.h+=t,i.s+=e,i.l+=r,this.setHSL(i.h,i.s,i.l),this},add:function(t){return this.r+=t.r,this.g+=t.g,this.b+=t.b,this},addColors:function(t,e){return this.r=t.r+e.r,this.g=t.g+e.g,this.b=t.b+e.b,this},addScalar:function(t){return this.r+=t,this.g+=t,this.b+=t,this},multiply:function(t){return this.r*=t.r,this.g*=t.g,this.b*=t.b,this},multiplyScalar:function(t){return this.r*=t,this.g*=t,this.b*=t,this},lerp:function(t,e){return this.r+=(t.r-this.r)*e,this.g+=(t.g-this.g)*e,this.b+=(t.b-this.b)*e,this},equals:function(t){return t.r===this.r&&t.g===this.g&&t.b===this.b},fromArray:function(t){return this.r=t[0],this.g=t[1],this.b=t[2],this},toArray:function(){return[this.r,this.g,this.b]},clone:function(){return(new THREE.Color).setRGB(this.r,this.g,this.b)}},THREE.ColorKeywords={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074},THREE.Quaternion=function(t,e,r,i){this._x=t||0,this._y=e||0,this._z=r||0,this._w=void 0!==i?i:1},THREE.Quaternion.prototype={constructor:THREE.Quaternion,_x:0,_y:0,_z:0,_w:0,get x(){return this._x},set x(t){this._x=t,this.onChangeCallback()},get y(){return this._y},set y(t){this._y=t,this.onChangeCallback()},get z(){return this._z},set z(t){this._z=t,this.onChangeCallback()},get w(){return this._w},set w(t){this._w=t,this.onChangeCallback()},set:function(t,e,r,i){return this._x=t,this._y=e,this._z=r,this._w=i,this.onChangeCallback(),this},copy:function(t){return this._x=t.x,this._y=t.y,this._z=t.z,this._w=t.w,this.onChangeCallback(),this},setFromEuler:function(t,e){if(t instanceof THREE.Euler==!1)throw new Error("THREE.Quaternion: .setFromEuler() now expects a Euler rotation rather than a Vector3 and order.");var r=Math.cos(t._x/2),i=Math.cos(t._y/2),n=Math.cos(t._z/2),a=Math.sin(t._x/2),o=Math.sin(t._y/2),s=Math.sin(t._z/2);return"XYZ"===t.order?(this._x=a*i*n+r*o*s,this._y=r*o*n-a*i*s,this._z=r*i*s+a*o*n,this._w=r*i*n-a*o*s):"YXZ"===t.order?(this._x=a*i*n+r*o*s,this._y=r*o*n-a*i*s,this._z=r*i*s-a*o*n,this._w=r*i*n+a*o*s):"ZXY"===t.order?(this._x=a*i*n-r*o*s,this._y=r*o*n+a*i*s,this._z=r*i*s+a*o*n,this._w=r*i*n-a*o*s):"ZYX"===t.order?(this._x=a*i*n-r*o*s,this._y=r*o*n+a*i*s,this._z=r*i*s-a*o*n,this._w=r*i*n+a*o*s):"YZX"===t.order?(this._x=a*i*n+r*o*s,this._y=r*o*n+a*i*s,this._z=r*i*s-a*o*n,this._w=r*i*n-a*o*s):"XZY"===t.order&&(this._x=a*i*n-r*o*s,this._y=r*o*n-a*i*s,this._z=r*i*s+a*o*n,this._w=r*i*n+a*o*s),!1!==e&&this.onChangeCallback(),this},setFromAxisAngle:function(t,e){var r=e/2,i=Math.sin(r);return this._x=t.x*i,this._y=t.y*i,this._z=t.z*i,this._w=Math.cos(r),this.onChangeCallback(),this},setFromRotationMatrix:function(t){var e,r=t.elements,i=r[0],n=r[4],a=r[8],o=r[1],s=r[5],h=r[9],l=r[2],u=r[6],c=r[10],f=i+s+c;return 0<f?(e=.5/Math.sqrt(f+1),this._w=.25/e,this._x=(u-h)*e,this._y=(a-l)*e,this._z=(o-n)*e):s<i&&c<i?(e=2*Math.sqrt(1+i-s-c),this._w=(u-h)/e,this._x=.25*e,this._y=(n+o)/e,this._z=(a+l)/e):c<s?(e=2*Math.sqrt(1+s-i-c),this._w=(a-l)/e,this._x=(n+o)/e,this._y=.25*e,this._z=(h+u)/e):(e=2*Math.sqrt(1+c-i-s),this._w=(o-n)/e,this._x=(a+l)/e,this._y=(h+u)/e,this._z=.25*e),this.onChangeCallback(),this},setFromUnitVectors:function(){var r,i;return function(t,e){return void 0===r&&(r=new THREE.Vector3),(i=t.dot(e)+1)<1e-6?(i=0,Math.abs(t.x)>Math.abs(t.z)?r.set(-t.y,t.x,0):r.set(0,-t.z,t.y)):r.crossVectors(t,e),this._x=r.x,this._y=r.y,this._z=r.z,this._w=i,this.normalize(),this}}(),inverse:function(){return this.conjugate().normalize(),this},conjugate:function(){return this._x*=-1,this._y*=-1,this._z*=-1,this.onChangeCallback(),this},dot:function(t){return this._x*t._x+this._y*t._y+this._z*t._z+this._w*t._w},lengthSq:function(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w},length:function(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w)},normalize:function(){var t=this.length();return 0===t?(this._x=0,this._y=0,this._z=0,this._w=1):(t=1/t,this._x=this._x*t,this._y=this._y*t,this._z=this._z*t,this._w=this._w*t),this.onChangeCallback(),this},multiply:function(t,e){return void 0!==e?(console.warn("THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead."),this.multiplyQuaternions(t,e)):this.multiplyQuaternions(this,t)},multiplyQuaternions:function(t,e){var r=t._x,i=t._y,n=t._z,a=t._w,o=e._x,s=e._y,h=e._z,l=e._w;return this._x=r*l+a*o+i*h-n*s,this._y=i*l+a*s+n*o-r*h,this._z=n*l+a*h+r*s-i*o,this._w=a*l-r*o-i*s-n*h,this.onChangeCallback(),this},multiplyVector3:function(t){return console.warn("THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead."),t.applyQuaternion(this)},slerp:function(t,e){if(0===e)return this;if(1===e)return this.copy(t);var r=this._x,i=this._y,n=this._z,a=this._w,o=a*t._w+r*t._x+i*t._y+n*t._z;if(o<0?(this._w=-t._w,this._x=-t._x,this._y=-t._y,this._z=-t._z,o=-o):this.copy(t),1<=o)return this._w=a,this._x=r,this._y=i,this._z=n,this;var s=Math.acos(o),h=Math.sqrt(1-o*o);if(Math.abs(h)<.001)return this._w=.5*(a+this._w),this._x=.5*(r+this._x),this._y=.5*(i+this._y),this._z=.5*(n+this._z),this;var l=Math.sin((1-e)*s)/h,u=Math.sin(e*s)/h;return this._w=a*l+this._w*u,this._x=r*l+this._x*u,this._y=i*l+this._y*u,this._z=n*l+this._z*u,this.onChangeCallback(),this},equals:function(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._w===this._w},fromArray:function(t,e){return void 0===e&&(e=0),this._x=t[e],this._y=t[e+1],this._z=t[e+2],this._w=t[e+3],this.onChangeCallback(),this},toArray:function(t,e){return void 0===t&&(t=[]),void 0===e&&(e=0),t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._w,t},onChange:function(t){return this.onChangeCallback=t,this},onChangeCallback:function(){},clone:function(){return new THREE.Quaternion(this._x,this._y,this._z,this._w)}},THREE.Quaternion.slerp=function(t,e,r,i){return r.copy(t).slerp(e,i)},THREE.Vector2=function(t,e){this.x=t||0,this.y=e||0},THREE.Vector2.prototype={constructor:THREE.Vector2,set:function(t,e){return this.x=t,this.y=e,this},setX:function(t){return this.x=t,this},setY:function(t){return this.y=t,this},setComponent:function(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;default:throw new Error("index is out of range: "+t)}},getComponent:function(t){switch(t){case 0:return this.x;case 1:return this.y;default:throw new Error("index is out of range: "+t)}},copy:function(t){return this.x=t.x,this.y=t.y,this},add:function(t,e){return void 0!==e?(console.warn("THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead."),this.addVectors(t,e)):(this.x+=t.x,this.y+=t.y,this)},addVectors:function(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this},addScalar:function(t){return this.x+=t,this.y+=t,this},sub:function(t,e){return void 0!==e?(console.warn("THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead."),this.subVectors(t,e)):(this.x-=t.x,this.y-=t.y,this)},subVectors:function(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this},multiply:function(t){return this.x*=t.x,this.y*=t.y,this},multiplyScalar:function(t){return this.x*=t,this.y*=t,this},divide:function(t){return this.x/=t.x,this.y/=t.y,this},divideScalar:function(t){if(0!==t){var e=1/t;this.x*=e,this.y*=e}else this.x=0,this.y=0;return this},min:function(t){return this.x>t.x&&(this.x=t.x),this.y>t.y&&(this.y=t.y),this},max:function(t){return this.x<t.x&&(this.x=t.x),this.y<t.y&&(this.y=t.y),this},clamp:function(t,e){return this.x<t.x?this.x=t.x:this.x>e.x&&(this.x=e.x),this.y<t.y?this.y=t.y:this.y>e.y&&(this.y=e.y),this},clampScalar:function(){var r,i;return function(t,e){return void 0===r&&(r=new THREE.Vector2,i=new THREE.Vector2),r.set(t,t),i.set(e,e),this.clamp(r,i)}}(),floor:function(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this},ceil:function(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this},round:function(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this},roundToZero:function(){return 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},negate:function(){return this.x=-this.x,this.y=-this.y,this},dot:function(t){return this.x*t.x+this.y*t.y},lengthSq:function(){return this.x*this.x+this.y*this.y},length:function(){return Math.sqrt(this.x*this.x+this.y*this.y)},normalize:function(){return this.divideScalar(this.length())},distanceTo:function(t){return Math.sqrt(this.distanceToSquared(t))},distanceToSquared:function(t){var e=this.x-t.x,r=this.y-t.y;return e*e+r*r},setLength:function(t){var e=this.length();return 0!==e&&t!==e&&this.multiplyScalar(t/e),this},lerp:function(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this},equals:function(t){return t.x===this.x&&t.y===this.y},fromArray:function(t,e){return void 0===e&&(e=0),this.x=t[e],this.y=t[e+1],this},toArray:function(t,e){return void 0===t&&(t=[]),void 0===e&&(e=0),t[e]=this.x,t[e+1]=this.y,t},clone:function(){return new THREE.Vector2(this.x,this.y)}},THREE.Vector3=function(t,e,r){this.x=t||0,this.y=e||0,this.z=r||0},THREE.Vector3.prototype={constructor:THREE.Vector3,set:function(t,e,r){return this.x=t,this.y=e,this.z=r,this},setX:function(t){return this.x=t,this},setY:function(t){return this.y=t,this},setZ:function(t){return this.z=t,this},setComponent:function(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;default:throw new Error("index is out of range: "+t)}},getComponent:function(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("index is out of range: "+t)}},copy:function(t){return this.x=t.x,this.y=t.y,this.z=t.z,this},add:function(t,e){return void 0!==e?(console.warn("THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead."),this.addVectors(t,e)):(this.x+=t.x,this.y+=t.y,this.z+=t.z,this)},addScalar:function(t){return this.x+=t,this.y+=t,this.z+=t,this},addVectors:function(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this},sub:function(t,e){return void 0!==e?(console.warn("THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead."),this.subVectors(t,e)):(this.x-=t.x,this.y-=t.y,this.z-=t.z,this)},subVectors:function(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this},multiply:function(t,e){return void 0!==e?(console.warn("THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead."),this.multiplyVectors(t,e)):(this.x*=t.x,this.y*=t.y,this.z*=t.z,this)},multiplyScalar:function(t){return this.x*=t,this.y*=t,this.z*=t,this},multiplyVectors:function(t,e){return this.x=t.x*e.x,this.y=t.y*e.y,this.z=t.z*e.z,this},applyEuler:function(){var e;return function(t){return t instanceof THREE.Euler==!1&&console.error("THREE.Vector3: .applyEuler() now expects a Euler rotation rather than a Vector3 and order."),void 0===e&&(e=new THREE.Quaternion),this.applyQuaternion(e.setFromEuler(t)),this}}(),applyAxisAngle:function(){var r;return function(t,e){return void 0===r&&(r=new THREE.Quaternion),this.applyQuaternion(r.setFromAxisAngle(t,e)),this}}(),applyMatrix3:function(t){var e=this.x,r=this.y,i=this.z,n=t.elements;return this.x=n[0]*e+n[3]*r+n[6]*i,this.y=n[1]*e+n[4]*r+n[7]*i,this.z=n[2]*e+n[5]*r+n[8]*i,this},applyMatrix4:function(t){var e=this.x,r=this.y,i=this.z,n=t.elements;return this.x=n[0]*e+n[4]*r+n[8]*i+n[12],this.y=n[1]*e+n[5]*r+n[9]*i+n[13],this.z=n[2]*e+n[6]*r+n[10]*i+n[14],this},applyProjection:function(t){var e=this.x,r=this.y,i=this.z,n=t.elements,a=1/(n[3]*e+n[7]*r+n[11]*i+n[15]);return this.x=(n[0]*e+n[4]*r+n[8]*i+n[12])*a,this.y=(n[1]*e+n[5]*r+n[9]*i+n[13])*a,this.z=(n[2]*e+n[6]*r+n[10]*i+n[14])*a,this},applyQuaternion:function(t){var e=this.x,r=this.y,i=this.z,n=t.x,a=t.y,o=t.z,s=t.w,h=s*e+a*i-o*r,l=s*r+o*e-n*i,u=s*i+n*r-a*e,c=-n*e-a*r-o*i;return this.x=h*s+c*-n+l*-o-u*-a,this.y=l*s+c*-a+u*-n-h*-o,this.z=u*s+c*-o+h*-a-l*-n,this},project:function(){var e;return function(t){return void 0===e&&(e=new THREE.Matrix4),e.multiplyMatrices(t.projectionMatrix,e.getInverse(t.matrixWorld)),this.applyProjection(e)}}(),unproject:function(){var e;return function(t){return void 0===e&&(e=new THREE.Matrix4),e.multiplyMatrices(t.matrixWorld,e.getInverse(t.projectionMatrix)),this.applyProjection(e)}}(),transformDirection:function(t){var e=this.x,r=this.y,i=this.z,n=t.elements;return this.x=n[0]*e+n[4]*r+n[8]*i,this.y=n[1]*e+n[5]*r+n[9]*i,this.z=n[2]*e+n[6]*r+n[10]*i,this.normalize(),this},divide:function(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this},divideScalar:function(t){if(0!==t){var e=1/t;this.x*=e,this.y*=e,this.z*=e}else this.x=0,this.y=0,this.z=0;return this},min:function(t){return this.x>t.x&&(this.x=t.x),this.y>t.y&&(this.y=t.y),this.z>t.z&&(this.z=t.z),this},max:function(t){return this.x<t.x&&(this.x=t.x),this.y<t.y&&(this.y=t.y),this.z<t.z&&(this.z=t.z),this},clamp:function(t,e){return this.x<t.x?this.x=t.x:this.x>e.x&&(this.x=e.x),this.y<t.y?this.y=t.y:this.y>e.y&&(this.y=e.y),this.z<t.z?this.z=t.z:this.z>e.z&&(this.z=e.z),this},clampScalar:function(){var r,i;return function(t,e){return void 0===r&&(r=new THREE.Vector3,i=new THREE.Vector3),r.set(t,t,t),i.set(e,e,e),this.clamp(r,i)}}(),floor:function(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this},ceil:function(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this},round:function(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this},roundToZero:function(){return 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},negate:function(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this},dot:function(t){return this.x*t.x+this.y*t.y+this.z*t.z},lengthSq:function(){return this.x*this.x+this.y*this.y+this.z*this.z},length:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)},lengthManhattan:function(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)},normalize:function(){return this.divideScalar(this.length())},setLength:function(t){var e=this.length();return 0!==e&&t!==e&&this.multiplyScalar(t/e),this},lerp:function(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this},cross:function(t,e){if(void 0!==e)return console.warn("THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead."),this.crossVectors(t,e);var r=this.x,i=this.y,n=this.z;return this.x=i*t.z-n*t.y,this.y=n*t.x-r*t.z,this.z=r*t.y-i*t.x,this},crossVectors:function(t,e){var r=t.x,i=t.y,n=t.z,a=e.x,o=e.y,s=e.z;return this.x=i*s-n*o,this.y=n*a-r*s,this.z=r*o-i*a,this},projectOnVector:function(){var e,r;return function(t){return void 0===e&&(e=new THREE.Vector3),e.copy(t).normalize(),r=this.dot(e),this.copy(e).multiplyScalar(r)}}(),projectOnPlane:function(){var e;return function(t){return void 0===e&&(e=new THREE.Vector3),e.copy(this).projectOnVector(t),this.sub(e)}}(),reflect:function(){var e;return function(t){return void 0===e&&(e=new THREE.Vector3),this.sub(e.copy(t).multiplyScalar(2*this.dot(t)))}}(),angleTo:function(t){var e=this.dot(t)/(this.length()*t.length());return Math.acos(THREE.Math.clamp(e,-1,1))},distanceTo:function(t){return Math.sqrt(this.distanceToSquared(t))},distanceToSquared:function(t){var e=this.x-t.x,r=this.y-t.y,i=this.z-t.z;return e*e+r*r+i*i},setEulerFromRotationMatrix:function(t,e){console.error("THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.")},setEulerFromQuaternion:function(t,e){console.error("THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.")},getPositionFromMatrix:function(t){return console.warn("THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition()."),this.setFromMatrixPosition(t)},getScaleFromMatrix:function(t){return console.warn("THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale()."),this.setFromMatrixScale(t)},getColumnFromMatrix:function(t,e){return console.warn("THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn()."),this.setFromMatrixColumn(t,e)},setFromMatrixPosition:function(t){return this.x=t.elements[12],this.y=t.elements[13],this.z=t.elements[14],this},setFromMatrixScale:function(t){var e=this.set(t.elements[0],t.elements[1],t.elements[2]).length(),r=this.set(t.elements[4],t.elements[5],t.elements[6]).length(),i=this.set(t.elements[8],t.elements[9],t.elements[10]).length();return this.x=e,this.y=r,this.z=i,this},setFromMatrixColumn:function(t,e){var r=4*t,i=e.elements;return this.x=i[r],this.y=i[r+1],this.z=i[r+2],this},equals:function(t){return t.x===this.x&&t.y===this.y&&t.z===this.z},fromArray:function(t,e){return void 0===e&&(e=0),this.x=t[e],this.y=t[e+1],this.z=t[e+2],this},toArray:function(t,e){return void 0===t&&(t=[]),void 0===e&&(e=0),t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t},clone:function(){return new THREE.Vector3(this.x,this.y,this.z)}},THREE.Vector4=function(t,e,r,i){this.x=t||0,this.y=e||0,this.z=r||0,this.w=void 0!==i?i:1},THREE.Vector4.prototype={constructor:THREE.Vector4,set:function(t,e,r,i){return this.x=t,this.y=e,this.z=r,this.w=i,this},setX:function(t){return this.x=t,this},setY:function(t){return this.y=t,this},setZ:function(t){return this.z=t,this},setW:function(t){return this.w=t,this},setComponent:function(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;case 3:this.w=e;break;default:throw new Error("index is out of range: "+t)}},getComponent:function(t){switch(t){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: "+t)}},copy:function(t){return this.x=t.x,this.y=t.y,this.z=t.z,this.w=void 0!==t.w?t.w:1,this},add:function(t,e){return void 0!==e?(console.warn("THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead."),this.addVectors(t,e)):(this.x+=t.x,this.y+=t.y,this.z+=t.z,this.w+=t.w,this)},addScalar:function(t){return this.x+=t,this.y+=t,this.z+=t,this.w+=t,this},addVectors:function(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this.w=t.w+e.w,this},sub:function(t,e){return void 0!==e?(console.warn("THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead."),this.subVectors(t,e)):(this.x-=t.x,this.y-=t.y,this.z-=t.z,this.w-=t.w,this)},subVectors:function(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this.w=t.w-e.w,this},multiplyScalar:function(t){return this.x*=t,this.y*=t,this.z*=t,this.w*=t,this},applyMatrix4:function(t){var e=this.x,r=this.y,i=this.z,n=this.w,a=t.elements;return this.x=a[0]*e+a[4]*r+a[8]*i+a[12]*n,this.y=a[1]*e+a[5]*r+a[9]*i+a[13]*n,this.z=a[2]*e+a[6]*r+a[10]*i+a[14]*n,this.w=a[3]*e+a[7]*r+a[11]*i+a[15]*n,this},divideScalar:function(t){if(0!==t){var e=1/t;this.x*=e,this.y*=e,this.z*=e,this.w*=e}else this.x=0,this.y=0,this.z=0,this.w=1;return this},setAxisAngleFromQuaternion:function(t){this.w=2*Math.acos(t.w);var e=Math.sqrt(1-t.w*t.w);return e<1e-4?(this.x=1,this.y=0,this.z=0):(this.x=t.x/e,this.y=t.y/e,this.z=t.z/e),this},setAxisAngleFromRotationMatrix:function(t){var e,r,i,n,a=t.elements,o=a[0],s=a[4],h=a[8],l=a[1],u=a[5],c=a[9],f=a[2],d=a[6],p=a[10];if(Math.abs(s-l)<.01&&Math.abs(h-f)<.01&&Math.abs(c-d)<.01){if(Math.abs(s+l)<.1&&Math.abs(h+f)<.1&&Math.abs(c+d)<.1&&Math.abs(o+u+p-3)<.1)return this.set(1,0,0,0),this;e=Math.PI;var E=(o+1)/2,m=(u+1)/2,g=(p+1)/2,v=(s+l)/4,T=(h+f)/4,x=(c+d)/4;return m<E&&g<E?E<.01?(r=0,n=i=.707106781):(i=v/(r=Math.sqrt(E)),n=T/r):g<m?m<.01?(i=0,n=r=.707106781):(r=v/(i=Math.sqrt(m)),n=x/i):g<.01?(i=r=.707106781,n=0):(r=T/(n=Math.sqrt(g)),i=x/n),this.set(r,i,n,e),this}var y=Math.sqrt((d-c)*(d-c)+(h-f)*(h-f)+(l-s)*(l-s));return Math.abs(y)<.001&&(y=1),this.x=(d-c)/y,this.y=(h-f)/y,this.z=(l-s)/y,this.w=Math.acos((o+u+p-1)/2),this},min:function(t){return this.x>t.x&&(this.x=t.x),this.y>t.y&&(this.y=t.y),this.z>t.z&&(this.z=t.z),this.w>t.w&&(this.w=t.w),this},max:function(t){return this.x<t.x&&(this.x=t.x),this.y<t.y&&(this.y=t.y),this.z<t.z&&(this.z=t.z),this.w<t.w&&(this.w=t.w),this},clamp:function(t,e){return this.x<t.x?this.x=t.x:this.x>e.x&&(this.x=e.x),this.y<t.y?this.y=t.y:this.y>e.y&&(this.y=e.y),this.z<t.z?this.z=t.z:this.z>e.z&&(this.z=e.z),this.w<t.w?this.w=t.w:this.w>e.w&&(this.w=e.w),this},clampScalar:function(){var r,i;return function(t,e){return void 0===r&&(r=new THREE.Vector4,i=new THREE.Vector4),r.set(t,t,t,t),i.set(e,e,e,e),this.clamp(r,i)}}(),floor:function(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this.w=Math.floor(this.w),this},ceil:function(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this.w=Math.ceil(this.w),this},round:function(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this.w=Math.round(this.w),this},roundToZero:function(){return 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),this},negate:function(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this.w=-this.w,this},dot:function(t){return this.x*t.x+this.y*t.y+this.z*t.z+this.w*t.w},lengthSq:function(){return this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w},length:function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z+this.w*this.w)},lengthManhattan:function(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)+Math.abs(this.w)},normalize:function(){return this.divideScalar(this.length())},setLength:function(t){var e=this.length();return 0!==e&&t!==e&&this.multiplyScalar(t/e),this},lerp:function(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this.w+=(t.w-this.w)*e,this},equals:function(t){return t.x===this.x&&t.y===this.y&&t.z===this.z&&t.w===this.w},fromArray:function(t,e){return void 0===e&&(e=0),this.x=t[e],this.y=t[e+1],this.z=t[e+2],this.w=t[e+3],this},toArray:function(t,e){return void 0===t&&(t=[]),void 0===e&&(e=0),t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t[e+3]=this.w,t},clone:function(){return new THREE.Vector4(this.x,this.y,this.z,this.w)}},THREE.Euler=function(t,e,r,i){this._x=t||0,this._y=e||0,this._z=r||0,this._order=i||THREE.Euler.DefaultOrder},THREE.Euler.RotationOrders=["XYZ","YZX","ZXY","XZY","YXZ","ZYX"],THREE.Euler.DefaultOrder="XYZ",THREE.Euler.prototype={constructor:THREE.Euler,_x:0,_y:0,_z:0,_order:THREE.Euler.DefaultOrder,get x(){return this._x},set x(t){this._x=t,this.onChangeCallback()},get y(){return this._y},set y(t){this._y=t,this.onChangeCallback()},get z(){return this._z},set z(t){this._z=t,this.onChangeCallback()},get order(){return this._order},set order(t){this._order=t,this.onChangeCallback()},set:function(t,e,r,i){return this._x=t,this._y=e,this._z=r,this._order=i||this._order,this.onChangeCallback(),this},copy:function(t){return this._x=t._x,this._y=t._y,this._z=t._z,this._order=t._order,this.onChangeCallback(),this},setFromRotationMatrix:function(t,e){var r=THREE.Math.clamp,i=t.elements,n=i[0],a=i[4],o=i[8],s=i[1],h=i[5],l=i[9],u=i[2],c=i[6],f=i[10];return"XYZ"===(e=e||this._order)?(this._y=Math.asin(r(o,-1,1)),Math.abs(o)<.99999?(this._x=Math.atan2(-l,f),this._z=Math.atan2(-a,n)):(this._x=Math.atan2(c,h),this._z=0)):"YXZ"===e?(this._x=Math.asin(-r(l,-1,1)),Math.abs(l)<.99999?(this._y=Math.atan2(o,f),this._z=Math.atan2(s,h)):(this._y=Math.atan2(-u,n),this._z=0)):"ZXY"===e?(this._x=Math.asin(r(c,-1,1)),Math.abs(c)<.99999?(this._y=Math.atan2(-u,f),this._z=Math.atan2(-a,h)):(this._y=0,this._z=Math.atan2(s,n))):"ZYX"===e?(this._y=Math.asin(-r(u,-1,1)),Math.abs(u)<.99999?(this._x=Math.atan2(c,f),this._z=Math.atan2(s,n)):(this._x=0,this._z=Math.atan2(-a,h))):"YZX"===e?(this._z=Math.asin(r(s,-1,1)),Math.abs(s)<.99999?(this._x=Math.atan2(-l,h),this._y=Math.atan2(-u,n)):(this._x=0,this._y=Math.atan2(o,f))):"XZY"===e?(this._z=Math.asin(-r(a,-1,1)),Math.abs(a)<.99999?(this._x=Math.atan2(c,h),this._y=Math.atan2(o,n)):(this._x=Math.atan2(-l,f),this._y=0)):console.warn("THREE.Euler: .setFromRotationMatrix() given unsupported order: "+e),this._order=e,this.onChangeCallback(),this},setFromQuaternion:function(t,e,r){var i=THREE.Math.clamp,n=t.x*t.x,a=t.y*t.y,o=t.z*t.z,s=t.w*t.w;return"XYZ"===(e=e||this._order)?(this._x=Math.atan2(2*(t.x*t.w-t.y*t.z),s-n-a+o),this._y=Math.asin(i(2*(t.x*t.z+t.y*t.w),-1,1)),this._z=Math.atan2(2*(t.z*t.w-t.x*t.y),s+n-a-o)):"YXZ"===e?(this._x=Math.asin(i(2*(t.x*t.w-t.y*t.z),-1,1)),this._y=Math.atan2(2*(t.x*t.z+t.y*t.w),s-n-a+o),this._z=Math.atan2(2*(t.x*t.y+t.z*t.w),s-n+a-o)):"ZXY"===e?(this._x=Math.asin(i(2*(t.x*t.w+t.y*t.z),-1,1)),this._y=Math.atan2(2*(t.y*t.w-t.z*t.x),s-n-a+o),this._z=Math.atan2(2*(t.z*t.w-t.x*t.y),s-n+a-o)):"ZYX"===e?(this._x=Math.atan2(2*(t.x*t.w+t.z*t.y),s-n-a+o),this._y=Math.asin(i(2*(t.y*t.w-t.x*t.z),-1,1)),this._z=Math.atan2(2*(t.x*t.y+t.z*t.w),s+n-a-o)):"YZX"===e?(this._x=Math.atan2(2*(t.x*t.w-t.z*t.y),s-n+a-o),this._y=Math.atan2(2*(t.y*t.w-t.x*t.z),s+n-a-o),this._z=Math.asin(i(2*(t.x*t.y+t.z*t.w),-1,1))):"XZY"===e?(this._x=Math.atan2(2*(t.x*t.w+t.y*t.z),s-n+a-o),this._y=Math.atan2(2*(t.x*t.z+t.y*t.w),s+n-a-o),this._z=Math.asin(i(2*(t.z*t.w-t.x*t.y),-1,1))):console.warn("THREE.Euler: .setFromQuaternion() given unsupported order: "+e),this._order=e,!1!==r&&this.onChangeCallback(),this},reorder:function(){var e=new THREE.Quaternion;return function(t){e.setFromEuler(this),this.setFromQuaternion(e,t)}}(),equals:function(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._order===this._order},fromArray:function(t){return this._x=t[0],this._y=t[1],this._z=t[2],void 0!==t[3]&&(this._order=t[3]),this.onChangeCallback(),this},toArray:function(){return[this._x,this._y,this._z,this._order]},onChange:function(t){return this.onChangeCallback=t,this},onChangeCallback:function(){},clone:function(){return new THREE.Euler(this._x,this._y,this._z,this._order)}},THREE.Box3=function(t,e){this.min=void 0!==t?t:new THREE.Vector3(1/0,1/0,1/0),this.max=void 0!==e?e:new THREE.Vector3(-1/0,-1/0,-1/0)},THREE.Box3.prototype={constructor:THREE.Box3,set:function(t,e){return this.min.copy(t),this.max.copy(e),this},setFromPoints:function(t){this.makeEmpty();for(var e=0,r=t.length;e<r;e++)this.expandByPoint(t[e]);return this},setFromCenterAndSize:function(){var i=new THREE.Vector3;return function(t,e){var r=i.copy(e).multiplyScalar(.5);return this.min.copy(t).sub(r),this.max.copy(t).add(r),this}}(),setFromObject:function(){var s=new THREE.Vector3;return function(t){var o=this;return t.updateMatrixWorld(!0),this.makeEmpty(),t.traverse(function(t){var e=t.geometry;if(void 0!==e)if(e instanceof THREE.Geometry)for(var r=e.vertices,i=0,n=r.length;i<n;i++)s.copy(r[i]),s.applyMatrix4(t.matrixWorld),o.expandByPoint(s);else if(e instanceof THREE.BufferGeometry&&void 0!==e.attributes.position){var a=e.attributes.position.array;for(i=0,n=a.length;i<n;i+=3)s.set(a[i],a[i+1],a[i+2]),s.applyMatrix4(t.matrixWorld),o.expandByPoint(s)}}),this}}(),copy:function(t){return this.min.copy(t.min),this.max.copy(t.max),this},makeEmpty:function(){return this.min.x=this.min.y=this.min.z=1/0,this.max.x=this.max.y=this.max.z=-1/0,this},empty:function(){return this.max.x<this.min.x||this.max.y<this.min.y||this.max.z<this.min.z},center:function(t){return(t||new THREE.Vector3).addVectors(this.min,this.max).multiplyScalar(.5)},size:function(t){return(t||new THREE.Vector3).subVectors(this.max,this.min)},expandByPoint:function(t){return this.min.min(t),this.max.max(t),this},expandByVector:function(t){return this.min.sub(t),this.max.add(t),this},expandByScalar:function(t){return this.min.addScalar(-t),this.max.addScalar(t),this},containsPoint:function(t){return!(t.x<this.min.x||t.x>this.max.x||t.y<this.min.y||t.y>this.max.y||t.z<this.min.z||t.z>this.max.z)},containsBox:function(t){return this.min.x<=t.min.x&&t.max.x<=this.max.x&&this.min.y<=t.min.y&&t.max.y<=this.max.y&&this.min.z<=t.min.z&&t.max.z<=this.max.z},getParameter:function(t,e){return(e||new THREE.Vector3).set((t.x-this.min.x)/(this.max.x-this.min.x),(t.y-this.min.y)/(this.max.y-this.min.y),(t.z-this.min.z)/(this.max.z-this.min.z))},isIntersectionBox:function(t){return!(t.max.x<this.min.x||t.min.x>this.max.x||t.max.y<this.min.y||t.min.y>this.max.y||t.max.z<this.min.z||t.min.z>this.max.z)},clampPoint:function(t,e){return(e||new THREE.Vector3).copy(t).clamp(this.min,this.max)},distanceToPoint:function(){var e=new THREE.Vector3;return function(t){return e.copy(t).clamp(this.min,this.max).sub(t).length()}}(),getBoundingSphere:function(){var r=new THREE.Vector3;return function(t){var e=t||new THREE.Sphere;return e.center=this.center(),e.radius=.5*this.size(r).length(),e}}(),intersect:function(t){return this.min.max(t.min),this.max.min(t.max),this},union:function(t){return this.min.min(t.min),this.max.max(t.max),this},applyMatrix4:function(){var e=[new THREE.Vector3,new THREE.Vector3,new THREE.Vector3,new THREE.Vector3,new THREE.Vector3,new THREE.Vector3,new THREE.Vector3,new THREE.Vector3];return function(t){return e[0].set(this.min.x,this.min.y,this.min.z).applyMatrix4(t),e[1].set(this.min.x,this.min.y,this.max.z).applyMatrix4(t),e[2].set(this.min.x,this.max.y,this.min.z).applyMatrix4(t),e[3].set(this.min.x,this.max.y,this.max.z).applyMatrix4(t),e[4].set(this.max.x,this.min.y,this.min.z).applyMatrix4(t),e[5].set(this.max.x,this.min.y,this.max.z).applyMatrix4(t),e[6].set(this.max.x,this.max.y,this.min.z).applyMatrix4(t),e[7].set(this.max.x,this.max.y,this.max.z).applyMatrix4(t),this.makeEmpty(),this.setFromPoints(e),this}}(),translate:function(t){return this.min.add(t),this.max.add(t),this},equals:function(t){return t.min.equals(this.min)&&t.max.equals(this.max)},clone:function(){return(new THREE.Box3).copy(this)}},THREE.Matrix3=function(){this.elements=new Float32Array([1,0,0,0,1,0,0,0,1]),0<arguments.length&&console.error("THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.")},THREE.Matrix3.prototype={constructor:THREE.Matrix3,set:function(t,e,r,i,n,a,o,s,h){var l=this.elements;return l[0]=t,l[3]=e,l[6]=r,l[1]=i,l[4]=n,l[7]=a,l[2]=o,l[5]=s,l[8]=h,this},identity:function(){return this.set(1,0,0,0,1,0,0,0,1),this},copy:function(t){var e=t.elements;return this.set(e[0],e[3],e[6],e[1],e[4],e[7],e[2],e[5],e[8]),this},multiplyVector3:function(t){return console.warn("THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead."),t.applyMatrix3(this)},multiplyVector3Array:function(t){return console.warn("THREE.Matrix3: .multiplyVector3Array() has been renamed. Use matrix.applyToVector3Array( array ) instead."),this.applyToVector3Array(t)},applyToVector3Array:function(){var a=new THREE.Vector3;return function(t,e,r){void 0===e&&(e=0),void 0===r&&(r=t.length);for(var i=0,n=e;i<r;i+=3,n+=3)a.x=t[n],a.y=t[n+1],a.z=t[n+2],a.applyMatrix3(this),t[n]=a.x,t[n+1]=a.y,t[n+2]=a.z;return t}}(),multiplyScalar:function(t){var e=this.elements;return e[0]*=t,e[3]*=t,e[6]*=t,e[1]*=t,e[4]*=t,e[7]*=t,e[2]*=t,e[5]*=t,e[8]*=t,this},determinant:function(){var t=this.elements,e=t[0],r=t[1],i=t[2],n=t[3],a=t[4],o=t[5],s=t[6],h=t[7],l=t[8];return e*a*l-e*o*h-r*n*l+r*o*s+i*n*h-i*a*s},getInverse:function(t,e){var r=t.elements,i=this.elements;i[0]=r[10]*r[5]-r[6]*r[9],i[1]=-r[10]*r[1]+r[2]*r[9],i[2]=r[6]*r[1]-r[2]*r[5],i[3]=-r[10]*r[4]+r[6]*r[8],i[4]=r[10]*r[0]-r[2]*r[8],i[5]=-r[6]*r[0]+r[2]*r[4],i[6]=r[9]*r[4]-r[5]*r[8],i[7]=-r[9]*r[0]+r[1]*r[8],i[8]=r[5]*r[0]-r[1]*r[4];var n=r[0]*i[0]+r[1]*i[3]+r[2]*i[6];if(0===n){var a="Matrix3.getInverse(): can't invert matrix, determinant is 0";if(e)throw new Error(a);return console.warn(a),this.identity(),this}return this.multiplyScalar(1/n),this},transpose:function(){var t,e=this.elements;return t=e[1],e[1]=e[3],e[3]=t,t=e[2],e[2]=e[6],e[6]=t,t=e[5],e[5]=e[7],e[7]=t,this},flattenToArrayOffset:function(t,e){var r=this.elements;return t[e]=r[0],t[e+1]=r[1],t[e+2]=r[2],t[e+3]=r[3],t[e+4]=r[4],t[e+5]=r[5],t[e+6]=r[6],t[e+7]=r[7],t[e+8]=r[8],t},getNormalMatrix:function(t){return this.getInverse(t).transpose(),this},transposeIntoArray:function(t){var e=this.elements;return t[0]=e[0],t[1]=e[3],t[2]=e[6],t[3]=e[1],t[4]=e[4],t[5]=e[7],t[6]=e[2],t[7]=e[5],t[8]=e[8],this},fromArray:function(t){return this.elements.set(t),this},toArray:function(){var t=this.elements;return[t[0],t[1],t[2],t[3],t[4],t[5],t[6],t[7],t[8]]},clone:function(){return(new THREE.Matrix3).fromArray(this.elements)}},THREE.Matrix4=function(){this.elements=new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),0<arguments.length&&console.error("THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.")},THREE.Matrix4.prototype={constructor:THREE.Matrix4,set:function(t,e,r,i,n,a,o,s,h,l,u,c,f,d,p,E){var m=this.elements;return m[0]=t,m[4]=e,m[8]=r,m[12]=i,m[1]=n,m[5]=a,m[9]=o,m[13]=s,m[2]=h,m[6]=l,m[10]=u,m[14]=c,m[3]=f,m[7]=d,m[11]=p,m[15]=E,this},identity:function(){return this.set(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),this},copy:function(t){return this.elements.set(t.elements),this},extractPosition:function(t){return console.warn("THREE.Matrix4: .extractPosition() has been renamed to .copyPosition()."),this.copyPosition(t)},copyPosition:function(t){var e=this.elements,r=t.elements;return e[12]=r[12],e[13]=r[13],e[14]=r[14],this},extractRotation:function(){var o=new THREE.Vector3;return function(t){var e=this.elements,r=t.elements,i=1/o.set(r[0],r[1],r[2]).length(),n=1/o.set(r[4],r[5],r[6]).length(),a=1/o.set(r[8],r[9],r[10]).length();return e[0]=r[0]*i,e[1]=r[1]*i,e[2]=r[2]*i,e[4]=r[4]*n,e[5]=r[5]*n,e[6]=r[6]*n,e[8]=r[8]*a,e[9]=r[9]*a,e[10]=r[10]*a,this}}(),makeRotationFromEuler:function(t){t instanceof THREE.Euler==!1&&console.error("THREE.Matrix: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.");var e=this.elements,r=t.x,i=t.y,n=t.z,a=Math.cos(r),o=Math.sin(r),s=Math.cos(i),h=Math.sin(i),l=Math.cos(n),u=Math.sin(n);if("XYZ"===t.order){var c=a*l,f=a*u,d=o*l,p=o*u;e[0]=s*l,e[4]=-s*u,e[8]=h,e[1]=f+d*h,e[5]=c-p*h,e[9]=-o*s,e[2]=p-c*h,e[6]=d+f*h,e[10]=a*s}else if("YXZ"===t.order){var E=s*l,m=s*u,g=h*l,v=h*u;e[0]=E+v*o,e[4]=g*o-m,e[8]=a*h,e[1]=a*u,e[5]=a*l,e[9]=-o,e[2]=m*o-g,e[6]=v+E*o,e[10]=a*s}else if("ZXY"===t.order){E=s*l,m=s*u,g=h*l,v=h*u;e[0]=E-v*o,e[4]=-a*u,e[8]=g+m*o,e[1]=m+g*o,e[5]=a*l,e[9]=v-E*o,e[2]=-a*h,e[6]=o,e[10]=a*s}else if("ZYX"===t.order){c=a*l,f=a*u,d=o*l,p=o*u;e[0]=s*l,e[4]=d*h-f,e[8]=c*h+p,e[1]=s*u,e[5]=p*h+c,e[9]=f*h-d,e[2]=-h,e[6]=o*s,e[10]=a*s}else if("YZX"===t.order){var T=a*s,x=a*h,y=o*s,R=o*h;e[0]=s*l,e[4]=R-T*u,e[8]=y*u+x,e[1]=u,e[5]=a*l,e[9]=-o*l,e[2]=-h*l,e[6]=x*u+y,e[10]=T-R*u}else if("XZY"===t.order){T=a*s,x=a*h,y=o*s,R=o*h;e[0]=s*l,e[4]=-u,e[8]=h*l,e[1]=T*u+R,e[5]=a*l,e[9]=x*u-y,e[2]=y*u-x,e[6]=o*l,e[10]=R*u+T}return e[3]=0,e[7]=0,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this},setRotationFromQuaternion:function(t){return console.warn("THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion()."),this.makeRotationFromQuaternion(t)},makeRotationFromQuaternion:function(t){var e=this.elements,r=t.x,i=t.y,n=t.z,a=t.w,o=r+r,s=i+i,h=n+n,l=r*o,u=r*s,c=r*h,f=i*s,d=i*h,p=n*h,E=a*o,m=a*s,g=a*h;return e[0]=1-(f+p),e[4]=u-g,e[8]=c+m,e[1]=u+g,e[5]=1-(l+p),e[9]=d-E,e[2]=c-m,e[6]=d+E,e[10]=1-(l+f),e[3]=0,e[7]=0,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,this},lookAt:function(){var n=new THREE.Vector3,a=new THREE.Vector3,o=new THREE.Vector3;return function(t,e,r){var i=this.elements;return o.subVectors(t,e).normalize(),0===o.length()&&(o.z=1),n.crossVectors(r,o).normalize(),0===n.length()&&(o.x+=1e-4,n.crossVectors(r,o).normalize()),a.crossVectors(o,n),i[0]=n.x,i[4]=a.x,i[8]=o.x,i[1]=n.y,i[5]=a.y,i[9]=o.y,i[2]=n.z,i[6]=a.z,i[10]=o.z,this}}(),multiply:function(t,e){return void 0!==e?(console.warn("THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead."),this.multiplyMatrices(t,e)):this.multiplyMatrices(this,t)},multiplyMatrices:function(t,e){var r=t.elements,i=e.elements,n=this.elements,a=r[0],o=r[4],s=r[8],h=r[12],l=r[1],u=r[5],c=r[9],f=r[13],d=r[2],p=r[6],E=r[10],m=r[14],g=r[3],v=r[7],T=r[11],x=r[15],y=i[0],R=i[4],_=i[8],H=i[12],b=i[1],M=i[5],w=i[9],S=i[13],A=i[2],C=i[6],D=i[10],L=i[14],F=i[3],P=i[7],U=i[11],B=i[15];return n[0]=a*y+o*b+s*A+h*F,n[4]=a*R+o*M+s*C+h*P,n[8]=a*_+o*w+s*D+h*U,n[12]=a*H+o*S+s*L+h*B,n[1]=l*y+u*b+c*A+f*F,n[5]=l*R+u*M+c*C+f*P,n[9]=l*_+u*w+c*D+f*U,n[13]=l*H+u*S+c*L+f*B,n[2]=d*y+p*b+E*A+m*F,n[6]=d*R+p*M+E*C+m*P,n[10]=d*_+p*w+E*D+m*U,n[14]=d*H+p*S+E*L+m*B,n[3]=g*y+v*b+T*A+x*F,n[7]=g*R+v*M+T*C+x*P,n[11]=g*_+v*w+T*D+x*U,n[15]=g*H+v*S+T*L+x*B,this},multiplyToArray:function(t,e,r){var i=this.elements;return this.multiplyMatrices(t,e),r[0]=i[0],r[1]=i[1],r[2]=i[2],r[3]=i[3],r[4]=i[4],r[5]=i[5],r[6]=i[6],r[7]=i[7],r[8]=i[8],r[9]=i[9],r[10]=i[10],r[11]=i[11],r[12]=i[12],r[13]=i[13],r[14]=i[14],r[15]=i[15],this},multiplyScalar:function(t){var e=this.elements;return e[0]*=t,e[4]*=t,e[8]*=t,e[12]*=t,e[1]*=t,e[5]*=t,e[9]*=t,e[13]*=t,e[2]*=t,e[6]*=t,e[10]*=t,e[14]*=t,e[3]*=t,e[7]*=t,e[11]*=t,e[15]*=t,this},multiplyVector3:function(t){return console.warn("THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) or vector.applyProjection( matrix ) instead."),t.applyProjection(this)},multiplyVector4:function(t){return console.warn("THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead."),t.applyMatrix4(this)},multiplyVector3Array:function(t){return console.warn("THREE.Matrix4: .multiplyVector3Array() has been renamed. Use matrix.applyToVector3Array( array ) instead."),this.applyToVector3Array(t)},applyToVector3Array:function(){var a=new THREE.Vector3;return function(t,e,r){void 0===e&&(e=0),void 0===r&&(r=t.length);for(var i=0,n=e;i<r;i+=3,n+=3)a.x=t[n],a.y=t[n+1],a.z=t[n+2],a.applyMatrix4(this),t[n]=a.x,t[n+1]=a.y,t[n+2]=a.z;return t}}(),rotateAxis:function(t){console.warn("THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead."),t.transformDirection(this)},crossVector:function(t){return console.warn("THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead."),t.applyMatrix4(this)},determinant:function(){var t=this.elements,e=t[0],r=t[4],i=t[8],n=t[12],a=t[1],o=t[5],s=t[9],h=t[13],l=t[2],u=t[6],c=t[10],f=t[14];return t[3]*(+n*s*u-i*h*u-n*o*c+r*h*c+i*o*f-r*s*f)+t[7]*(+e*s*f-e*h*c+n*a*c-i*a*f+i*h*l-n*s*l)+t[11]*(+e*h*u-e*o*f-n*a*u+r*a*f+n*o*l-r*h*l)+t[15]*(-i*o*l-e*s*u+e*o*c+i*a*u-r*a*c+r*s*l)},transpose:function(){var t,e=this.elements;return t=e[1],e[1]=e[4],e[4]=t,t=e[2],e[2]=e[8],e[8]=t,t=e[6],e[6]=e[9],e[9]=t,t=e[3],e[3]=e[12],e[12]=t,t=e[7],e[7]=e[13],e[13]=t,t=e[11],e[11]=e[14],e[14]=t,this},flattenToArrayOffset:function(t,e){var r=this.elements;return t[e]=r[0],t[e+1]=r[1],t[e+2]=r[2],t[e+3]=r[3],t[e+4]=r[4],t[e+5]=r[5],t[e+6]=r[6],t[e+7]=r[7],t[e+8]=r[8],t[e+9]=r[9],t[e+10]=r[10],t[e+11]=r[11],t[e+12]=r[12],t[e+13]=r[13],t[e+14]=r[14],t[e+15]=r[15],t},getPosition:function(){var e=new THREE.Vector3;return function(){console.warn("THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.");var t=this.elements;return e.set(t[12],t[13],t[14])}}(),setPosition:function(t){var e=this.elements;return e[12]=t.x,e[13]=t.y,e[14]=t.z,this},getInverse:function(t,e){var r=this.elements,i=t.elements,n=i[0],a=i[4],o=i[8],s=i[12],h=i[1],l=i[5],u=i[9],c=i[13],f=i[2],d=i[6],p=i[10],E=i[14],m=i[3],g=i[7],v=i[11],T=i[15];r[0]=u*E*g-c*p*g+c*d*v-l*E*v-u*d*T+l*p*T,r[4]=s*p*g-o*E*g-s*d*v+a*E*v+o*d*T-a*p*T,r[8]=o*c*g-s*u*g+s*l*v-a*c*v-o*l*T+a*u*T,r[12]=s*u*d-o*c*d-s*l*p+a*c*p+o*l*E-a*u*E,r[1]=c*p*m-u*E*m-c*f*v+h*E*v+u*f*T-h*p*T,r[5]=o*E*m-s*p*m+s*f*v-n*E*v-o*f*T+n*p*T,r[9]=s*u*m-o*c*m-s*h*v+n*c*v+o*h*T-n*u*T,r[13]=o*c*f-s*u*f+s*h*p-n*c*p-o*h*E+n*u*E,r[2]=l*E*m-c*d*m+c*f*g-h*E*g-l*f*T+h*d*T,r[6]=s*d*m-a*E*m-s*f*g+n*E*g+a*f*T-n*d*T,r[10]=a*c*m-s*l*m+s*h*g-n*c*g-a*h*T+n*l*T,r[14]=s*l*f-a*c*f-s*h*d+n*c*d+a*h*E-n*l*E,r[3]=u*d*m-l*p*m-u*f*g+h*p*g+l*f*v-h*d*v,r[7]=a*p*m-o*d*m+o*f*g-n*p*g-a*f*v+n*d*v,r[11]=o*l*m-a*u*m-o*h*g+n*u*g+a*h*v-n*l*v,r[15]=a*u*f-o*l*f+o*h*d-n*u*d-a*h*p+n*l*p;var x=n*r[0]+h*r[4]+f*r[8]+m*r[12];if(0==x){var y="Matrix4.getInverse(): can't invert matrix, determinant is 0";if(e)throw new Error(y);return console.warn(y),this.identity(),this}return this.multiplyScalar(1/x),this},translate:function(t){console.warn("THREE.Matrix4: .translate() has been removed.")},rotateX:function(t){console.warn("THREE.Matrix4: .rotateX() has been removed.")},rotateY:function(t){console.warn("THREE.Matrix4: .rotateY() has been removed.")},rotateZ:function(t){console.warn("THREE.Matrix4: .rotateZ() has been removed.")},rotateByAxis:function(t,e){console.warn("THREE.Matrix4: .rotateByAxis() has been removed.")},scale:function(t){var e=this.elements,r=t.x,i=t.y,n=t.z;return e[0]*=r,e[4]*=i,e[8]*=n,e[1]*=r,e[5]*=i,e[9]*=n,e[2]*=r,e[6]*=i,e[10]*=n,e[3]*=r,e[7]*=i,e[11]*=n,this},getMaxScaleOnAxis:function(){var t=this.elements,e=t[0]*t[0]+t[1]*t[1]+t[2]*t[2],r=t[4]*t[4]+t[5]*t[5]+t[6]*t[6],i=t[8]*t[8]+t[9]*t[9]+t[10]*t[10];return Math.sqrt(Math.max(e,Math.max(r,i)))},makeTranslation:function(t,e,r){return this.set(1,0,0,t,0,1,0,e,0,0,1,r,0,0,0,1),this},makeRotationX:function(t){var e=Math.cos(t),r=Math.sin(t);return this.set(1,0,0,0,0,e,-r,0,0,r,e,0,0,0,0,1),this},makeRotationY:function(t){var e=Math.cos(t),r=Math.sin(t);return this.set(e,0,r,0,0,1,0,0,-r,0,e,0,0,0,0,1),this},makeRotationZ:function(t){var e=Math.cos(t),r=Math.sin(t);return this.set(e,-r,0,0,r,e,0,0,0,0,1,0,0,0,0,1),this},makeRotationAxis:function(t,e){var r=Math.cos(e),i=Math.sin(e),n=1-r,a=t.x,o=t.y,s=t.z,h=n*a,l=n*o;return this.set(h*a+r,h*o-i*s,h*s+i*o,0,h*o+i*s,l*o+r,l*s-i*a,0,h*s-i*o,l*s+i*a,n*s*s+r,0,0,0,0,1),this},makeScale:function(t,e,r){return this.set(t,0,0,0,0,e,0,0,0,0,r,0,0,0,0,1),this},compose:function(t,e,r){return this.makeRotationFromQuaternion(e),this.scale(r),this.setPosition(t),this},decompose:function(){var u=new THREE.Vector3,c=new THREE.Matrix4;return function(t,e,r){var i=this.elements,n=u.set(i[0],i[1],i[2]).length(),a=u.set(i[4],i[5],i[6]).length(),o=u.set(i[8],i[9],i[10]).length();this.determinant()<0&&(n=-n),t.x=i[12],t.y=i[13],t.z=i[14],c.elements.set(this.elements);var s=1/n,h=1/a,l=1/o;return c.elements[0]*=s,c.elements[1]*=s,c.elements[2]*=s,c.elements[4]*=h,c.elements[5]*=h,c.elements[6]*=h,c.elements[8]*=l,c.elements[9]*=l,c.elements[10]*=l,e.setFromRotationMatrix(c),r.x=n,r.y=a,r.z=o,this}}(),makeFrustum:function(t,e,r,i,n,a){var o=this.elements,s=2*n/(e-t),h=2*n/(i-r),l=(e+t)/(e-t),u=(i+r)/(i-r),c=-(a+n)/(a-n),f=-2*a*n/(a-n);return o[0]=s,o[4]=0,o[8]=l,o[12]=0,o[1]=0,o[5]=h,o[9]=u,o[13]=0,o[2]=0,o[6]=0,o[10]=c,o[14]=f,o[3]=0,o[7]=0,o[11]=-1,o[15]=0,this},makePerspective:function(t,e,r,i){var n=r*Math.tan(THREE.Math.degToRad(.5*t)),a=-n,o=a*e,s=n*e;return this.makeFrustum(o,s,a,n,r,i)},makeOrthographic:function(t,e,r,i,n,a){var o=this.elements,s=e-t,h=r-i,l=a-n,u=(e+t)/s,c=(r+i)/h,f=(a+n)/l;return o[0]=2/s,o[4]=0,o[8]=0,o[12]=-u,o[1]=0,o[5]=2/h,o[9]=0,o[13]=-c,o[2]=0,o[6]=0,o[10]=-2/l,o[14]=-f,o[3]=0,o[7]=0,o[11]=0,o[15]=1,this},fromArray:function(t){return this.elements.set(t),this},toArray:function(){var t=this.elements;return[t[0],t[1],t[2],t[3],t[4],t[5],t[6],t[7],t[8],t[9],t[10],t[11],t[12],t[13],t[14],t[15]]},clone:function(){return(new THREE.Matrix4).fromArray(this.elements)}},THREE.Ray=function(t,e){this.origin=void 0!==t?t:new THREE.Vector3,this.direction=void 0!==e?e:new THREE.Vector3},THREE.Ray.prototype={constructor:THREE.Ray,set:function(t,e){return this.origin.copy(t),this.direction.copy(e),this},copy:function(t){return this.origin.copy(t.origin),this.direction.copy(t.direction),this},at:function(t,e){return(e||new THREE.Vector3).copy(this.direction).multiplyScalar(t).add(this.origin)},recast:function(){var e=new THREE.Vector3;return function(t){return this.origin.copy(this.at(t,e)),this}}(),closestPointToPoint:function(t,e){var r=e||new THREE.Vector3;r.subVectors(t,this.origin);var i=r.dot(this.direction);return i<0?r.copy(this.origin):r.copy(this.direction).multiplyScalar(i).add(this.origin)},distanceToPoint:function(){var r=new THREE.Vector3;return function(t){var e=r.subVectors(t,this.origin).dot(this.direction);return e<0?this.origin.distanceTo(t):(r.copy(this.direction).multiplyScalar(e).add(this.origin),r.distanceTo(t))}}(),distanceSqToSegment:function(t,e,r,i){var n,a,o,s,h=t.clone().add(e).multiplyScalar(.5),l=e.clone().sub(t).normalize(),u=.5*t.distanceTo(e),c=this.origin.clone().sub(h),f=-this.direction.dot(l),d=c.dot(this.direction),p=-c.dot(l),E=c.lengthSq(),m=Math.abs(1-f*f);if(0<=m)if(a=f*d-p,s=u*m,0<=(n=f*p-d))if(-s<=a)if(a<=s){var g=1/m;o=(n*=g)*(n+f*(a*=g)+2*d)+a*(f*n+a+2*p)+E}else a=u,o=-(n=Math.max(0,-(f*a+d)))*n+a*(a+2*p)+E;else a=-u,o=-(n=Math.max(0,-(f*a+d)))*n+a*(a+2*p)+E;else a<=-s?o=-(n=Math.max(0,-(-f*u+d)))*n+(a=0<n?-u:Math.min(Math.max(-u,-p),u))*(a+2*p)+E:a<=s?(n=0,o=(a=Math.min(Math.max(-u,-p),u))*(a+2*p)+E):o=-(n=Math.max(0,-(f*u+d)))*n+(a=0<n?u:Math.min(Math.max(-u,-p),u))*(a+2*p)+E;else a=0<f?-u:u,o=-(n=Math.max(0,-(f*a+d)))*n+a*(a+2*p)+E;return r&&r.copy(this.direction.clone().multiplyScalar(n).add(this.origin)),i&&i.copy(l.clone().multiplyScalar(a).add(h)),o},isIntersectionSphere:function(t){return this.distanceToPoint(t.center)<=t.radius},intersectSphere:function(){var h=new THREE.Vector3;return function(t,e){h.subVectors(t.center,this.origin);var r=h.dot(this.direction),i=h.dot(h)-r*r,n=t.radius*t.radius;if(n<i)return null;var a=Math.sqrt(n-i),o=r-a,s=r+a;return o<0&&s<0?null:o<0?this.at(s,e):this.at(o,e)}}(),isIntersectionPlane:function(t){var e=t.distanceToPoint(this.origin);return 0===e||t.normal.dot(this.direction)*e<0},distanceToPlane:function(t){var e=t.normal.dot(this.direction);if(0==e)return 0==t.distanceToPoint(this.origin)?0:null;var r=-(this.origin.dot(t.normal)+t.constant)/e;return 0<=r?r:null},intersectPlane:function(t,e){var r=this.distanceToPlane(t);return null===r?null:this.at(r,e)},isIntersectionBox:function(){var e=new THREE.Vector3;return function(t){return null!==this.intersectBox(t,e)}}(),intersectBox:function(t,e){var r,i,n,a,o,s,h=1/this.direction.x,l=1/this.direction.y,u=1/this.direction.z,c=this.origin;return 0<=h?(r=(t.min.x-c.x)*h,i=(t.max.x-c.x)*h):(r=(t.max.x-c.x)*h,i=(t.min.x-c.x)*h),0<=l?(n=(t.min.y-c.y)*l,a=(t.max.y-c.y)*l):(n=(t.max.y-c.y)*l,a=(t.min.y-c.y)*l),a<r||i<n?null:((r<n||r!=r)&&(r=n),(a<i||i!=i)&&(i=a),0<=u?(o=(t.min.z-c.z)*u,s=(t.max.z-c.z)*u):(o=(t.max.z-c.z)*u,s=(t.min.z-c.z)*u),s<r||i<o?null:((r<o||r!=r)&&(r=o),(s<i||i!=i)&&(i=s),i<0?null:this.at(0<=r?r:i,e)))},intersectTriangle:function(){var u=new THREE.Vector3,c=new THREE.Vector3,f=new THREE.Vector3,d=new THREE.Vector3;return function(t,e,r,i,n){c.subVectors(e,t),f.subVectors(r,t),d.crossVectors(c,f);var a,o=this.direction.dot(d);if(0<o){if(i)return null;a=1}else{if(!(o<0))return null;a=-1,o=-o}u.subVectors(this.origin,t);var s=a*this.direction.dot(f.crossVectors(u,f));if(s<0)return null;var h=a*this.direction.dot(c.cross(u));if(h<0)return null;if(o<s+h)return null;var l=-a*u.dot(d);return l<0?null:this.at(l/o,n)}}(),applyMatrix4:function(t){return this.direction.add(this.origin).applyMatrix4(t),this.origin.applyMatrix4(t),this.direction.sub(this.origin),this.direction.normalize(),this},equals:function(t){return t.origin.equals(this.origin)&&t.direction.equals(this.direction)},clone:function(){return(new THREE.Ray).copy(this)}},THREE.Sphere=function(t,e){this.center=void 0!==t?t:new THREE.Vector3,this.radius=void 0!==e?e:0},THREE.Sphere.prototype={constructor:THREE.Sphere,set:function(t,e){return this.center.copy(t),this.radius=e,this},setFromPoints:function(){var o=new THREE.Box3;return function(t,e){var r=this.center;void 0!==e?r.copy(e):o.setFromPoints(t).center(r);for(var i=0,n=0,a=t.length;n<a;n++)i=Math.max(i,r.distanceToSquared(t[n]));return this.radius=Math.sqrt(i),this}}(),copy:function(t){return this.center.copy(t.center),this.radius=t.radius,this},empty:function(){return this.radius<=0},containsPoint:function(t){return t.distanceToSquared(this.center)<=this.radius*this.radius},distanceToPoint:function(t){return t.distanceTo(this.center)-this.radius},intersectsSphere:function(t){var e=this.radius+t.radius;return t.center.distanceToSquared(this.center)<=e*e},clampPoint:function(t,e){var r=this.center.distanceToSquared(t),i=e||new THREE.Vector3;return i.copy(t),r>this.radius*this.radius&&(i.sub(this.center).normalize(),i.multiplyScalar(this.radius).add(this.center)),i},getBoundingBox:function(t){var e=t||new THREE.Box3;return e.set(this.center,this.center),e.expandByScalar(this.radius),e},applyMatrix4:function(t){return this.center.applyMatrix4(t),this.radius=this.radius*t.getMaxScaleOnAxis(),this},translate:function(t){return this.center.add(t),this},equals:function(t){return t.center.equals(this.center)&&t.radius===this.radius},clone:function(){return(new THREE.Sphere).copy(this)}},THREE.Frustum=function(t,e,r,i,n,a){this.planes=[void 0!==t?t:new THREE.Plane,void 0!==e?e:new THREE.Plane,void 0!==r?r:new THREE.Plane,void 0!==i?i:new THREE.Plane,void 0!==n?n:new THREE.Plane,void 0!==a?a:new THREE.Plane]},THREE.Frustum.prototype={constructor:THREE.Frustum,set:function(t,e,r,i,n,a){var o=this.planes;return o[0].copy(t),o[1].copy(e),o[2].copy(r),o[3].copy(i),o[4].copy(n),o[5].copy(a),this},copy:function(t){for(var e=this.planes,r=0;r<6;r++)e[r].copy(t.planes[r]);return this},setFromMatrix:function(t){var e=this.planes,r=t.elements,i=r[0],n=r[1],a=r[2],o=r[3],s=r[4],h=r[5],l=r[6],u=r[7],c=r[8],f=r[9],d=r[10],p=r[11],E=r[12],m=r[13],g=r[14],v=r[15];return e[0].setComponents(o-i,u-s,p-c,v-E).normalize(),e[1].setComponents(o+i,u+s,p+c,v+E).normalize(),e[2].setComponents(o+n,u+h,p+f,v+m).normalize(),e[3].setComponents(o-n,u-h,p-f,v-m).normalize(),e[4].setComponents(o-a,u-l,p-d,v-g).normalize(),e[5].setComponents(o+a,u+l,p+d,v+g).normalize(),this},intersectsObject:function(){var r=new THREE.Sphere;return function(t){var e=t.geometry;return null===e.boundingSphere&&e.computeBoundingSphere(),r.copy(e.boundingSphere),r.applyMatrix4(t.matrixWorld),this.intersectsSphere(r)}}(),intersectsSphere:function(t){for(var e=this.planes,r=t.center,i=-t.radius,n=0;n<6;n++){if(e[n].distanceToPoint(r)<i)return!1}return!0},intersectsBox:function(){var o=new THREE.Vector3,s=new THREE.Vector3;return function(t){for(var e=this.planes,r=0;r<6;r++){var i=e[r];o.x=0<i.normal.x?t.min.x:t.max.x,s.x=0<i.normal.x?t.max.x:t.min.x,o.y=0<i.normal.y?t.min.y:t.max.y,s.y=0<i.normal.y?t.max.y:t.min.y,o.z=0<i.normal.z?t.min.z:t.max.z,s.z=0<i.normal.z?t.max.z:t.min.z;var n=i.distanceToPoint(o),a=i.distanceToPoint(s);if(n<0&&a<0)return!1}return!0}}(),containsPoint:function(t){for(var e=this.planes,r=0;r<6;r++)if(e[r].distanceToPoint(t)<0)return!1;return!0},clone:function(){return(new THREE.Frustum).copy(this)}},THREE.Plane=function(t,e){this.normal=void 0!==t?t:new THREE.Vector3(1,0,0),this.constant=void 0!==e?e:0},THREE.Plane.prototype={constructor:THREE.Plane,set:function(t,e){return this.normal.copy(t),this.constant=e,this},setComponents:function(t,e,r,i){return this.normal.set(t,e,r),this.constant=i,this},setFromNormalAndCoplanarPoint:function(t,e){return this.normal.copy(t),this.constant=-e.dot(this.normal),this},setFromCoplanarPoints:function(){var n=new THREE.Vector3,a=new THREE.Vector3;return function(t,e,r){var i=n.subVectors(r,e).cross(a.subVectors(t,e)).normalize();return this.setFromNormalAndCoplanarPoint(i,t),this}}(),copy:function(t){return this.normal.copy(t.normal),this.constant=t.constant,this},normalize:function(){var t=1/this.normal.length();return this.normal.multiplyScalar(t),this.constant*=t,this},negate:function(){return this.constant*=-1,this.normal.negate(),this},distanceToPoint:function(t){return this.normal.dot(t)+this.constant},distanceToSphere:function(t){return this.distanceToPoint(t.center)-t.radius},projectPoint:function(t,e){return this.orthoPoint(t,e).sub(t).negate()},orthoPoint:function(t,e){var r=this.distanceToPoint(t);return(e||new THREE.Vector3).copy(this.normal).multiplyScalar(r)},isIntersectionLine:function(t){var e=this.distanceToPoint(t.start),r=this.distanceToPoint(t.end);return e<0&&0<r||r<0&&0<e},intersectLine:function(){var o=new THREE.Vector3;return function(t,e){var r=e||new THREE.Vector3,i=t.delta(o),n=this.normal.dot(i);if(0==n)return 0==this.distanceToPoint(t.start)?r.copy(t.start):void 0;var a=-(t.start.dot(this.normal)+this.constant)/n;return a<0||1<a?void 0:r.copy(i).multiplyScalar(a).add(t.start)}}(),coplanarPoint:function(t){return(t||new THREE.Vector3).copy(this.normal).multiplyScalar(-this.constant)},applyMatrix4:function(){var a=new THREE.Vector3,o=new THREE.Vector3,s=new THREE.Matrix3;return function(t,e){var r=e||s.getNormalMatrix(t),i=a.copy(this.normal).applyMatrix3(r),n=this.coplanarPoint(o);return n.applyMatrix4(t),this.setFromNormalAndCoplanarPoint(i,n),this}}(),translate:function(t){return this.constant=this.constant-t.dot(this.normal),this},equals:function(t){return t.normal.equals(this.normal)&&t.constant==this.constant},clone:function(){return(new THREE.Plane).copy(this)}},THREE.Math={generateUUID:function(){var e,r="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""),i=new Array(36),n=0;return function(){for(var t=0;t<36;t++)8==t||13==t||18==t||23==t?i[t]="-":14==t?i[t]="4":(n<=2&&(n=33554432+16777216*Math.random()|0),e=15&n,n>>=4,i[t]=r[19==t?3&e|8:e]);return i.join("")}}(),clamp:function(t,e,r){return t<e?e:r<t?r:t},clampBottom:function(t,e){return t<e?e:t},mapLinear:function(t,e,r,i,n){return i+(t-e)*(n-i)/(r-e)},smoothstep:function(t,e,r){return t<=e?0:r<=t?1:(t=(t-e)/(r-e))*t*(3-2*t)},smootherstep:function(t,e,r){return t<=e?0:r<=t?1:(t=(t-e)/(r-e))*t*t*(t*(6*t-15)+10)},random16:function(){return(65280*Math.random()+255*Math.random())/65535},randInt:function(t,e){return t+Math.floor(Math.random()*(e-t+1))},randFloat:function(t,e){return t+Math.random()*(e-t)},randFloatSpread:function(t){return t*(.5-Math.random())},degToRad:function(){var e=Math.PI/180;return function(t){return t*e}}(),radToDeg:function(){var e=180/Math.PI;return function(t){return t*e}}(),isPowerOfTwo:function(t){return 0==(t&t-1)&&0!==t}},THREE.Spline=function(t){this.points=t;var e,r,i,n,a,o,s,h,l,u=[],c={x:0,y:0,z:0};function f(t,e,r,i,n,a,o){var s=.5*(r-t),h=.5*(i-e);return(2*(e-r)+s+h)*o+(-3*(e-r)-2*s-h)*a+s*n+e}this.initFromArray=function(t){this.points=[];for(var e=0;e<t.length;e++)this.points[e]={x:t[e][0],y:t[e][1],z:t[e][2]}},this.getPoint=function(t){return e=(this.points.length-1)*t,r=Math.floor(e),i=e-r,u[0]=0===r?r:r-1,u[1]=r,u[2]=r>this.points.length-2?this.points.length-1:r+1,u[3]=r>this.points.length-3?this.points.length-1:r+2,o=this.points[u[0]],s=this.points[u[1]],h=this.points[u[2]],l=this.points[u[3]],a=i*(n=i*i),c.x=f(o.x,s.x,h.x,l.x,i,n,a),c.y=f(o.y,s.y,h.y,l.y,i,n,a),c.z=f(o.z,s.z,h.z,l.z,i,n,a),c},this.getControlPointsArray=function(){var t,e,r=this.points.length,i=[];for(t=0;t<r;t++)e=this.points[t],i[t]=[e.x,e.y,e.z];return i},this.getLength=function(t){var e,r,i,n,a=0,o=0,s=0,h=new THREE.Vector3,l=new THREE.Vector3,u=[],c=0;for(u[0]=0,t||(t=100),i=this.points.length*t,h.copy(this.points[0]),e=1;e<i;e++)r=e/i,n=this.getPoint(r),l.copy(n),c+=l.distanceTo(h),h.copy(n),a=(this.points.length-1)*r,(o=Math.floor(a))!=s&&(u[o]=c,s=o);return u[u.length]=c,{chunks:u,total:c}},this.reparametrizeByArcLength=function(t){var e,r,i,n,a,o,s,h,l=[],u=new THREE.Vector3,c=this.getLength();for(l.push(u.copy(this.points[0]).clone()),e=1;e<this.points.length;e++){for(o=c.chunks[e]-c.chunks[e-1],s=Math.ceil(t*o/c.total),n=(e-1)/(this.points.length-1),a=e/(this.points.length-1),r=1;r<s-1;r++)i=n+r*(1/s)*(a-n),h=this.getPoint(i),l.push(u.copy(h).clone());l.push(u.copy(this.points[e]).clone())}this.points=l}},THREE.Clock=function(t){this.autoStart=void 0===t||t,this.startTime=0,this.oldTime=0,this.elapsedTime=0,this.running=!1},THREE.Clock.prototype={constructor:THREE.Clock,start:function(){this.startTime=void 0!==self.performance&&void 0!==self.performance.now?self.performance.now():Date.now(),this.oldTime=this.startTime,this.running=!0},stop:function(){this.getElapsedTime(),this.running=!1},getElapsedTime:function(){return this.getDelta(),this.elapsedTime},getDelta:function(){var t=0;if(this.autoStart&&!this.running&&this.start(),this.running){var e=void 0!==self.performance&&void 0!==self.performance.now?self.performance.now():Date.now();t=.001*(e-this.oldTime),this.oldTime=e,this.elapsedTime+=t}return t}},THREE.EventDispatcher=function(){},THREE.EventDispatcher.prototype={constructor:THREE.EventDispatcher,apply:function(t){t.addEventListener=THREE.EventDispatcher.prototype.addEventListener,t.hasEventListener=THREE.EventDispatcher.prototype.hasEventListener,t.removeEventListener=THREE.EventDispatcher.prototype.removeEventListener,t.dispatchEvent=THREE.EventDispatcher.prototype.dispatchEvent},addEventListener:function(t,e){void 0===this._listeners&&(this._listeners={});var r=this._listeners;void 0===r[t]&&(r[t]=[]),-1===r[t].indexOf(e)&&r[t].push(e)},hasEventListener:function(t,e){if(void 0===this._listeners)return!1;var r=this._listeners;return void 0!==r[t]&&-1!==r[t].indexOf(e)},removeEventListener:function(t,e){if(void 0!==this._listeners){var r=this._listeners[t];if(void 0!==r){var i=r.indexOf(e);-1!==i&&r.splice(i,1)}}},dispatchEvent:function(t){if(void 0!==this._listeners){var e=this._listeners[t.type];if(void 0!==e){t.target=this;for(var r=[],i=e.length,n=0;n<i;n++)r[n]=e[n];for(n=0;n<i;n++)r[n].call(this,t)}}}},THREE.Object3D=function(){Object.defineProperty(this,"id",{value:THREE.Object3DIdCount++}),this.uuid=THREE.Math.generateUUID(),this.name="",this.type="Object3D",this.parent=void 0,this.children=[],this.up=THREE.Object3D.DefaultUp.clone();var t=new THREE.Vector3,e=new THREE.Euler,r=new THREE.Quaternion,i=new THREE.Vector3(1,1,1);e.onChange(function(){r.setFromEuler(e,!1)}),r.onChange(function(){e.setFromQuaternion(r,void 0,!1)}),Object.defineProperties(this,{position:{enumerable:!0,value:t},rotation:{enumerable:!0,value:e},quaternion:{enumerable:!0,value:r},scale:{enumerable:!0,value:i}}),this.renderDepth=null,this.rotationAutoUpdate=!0,this.matrix=new THREE.Matrix4,this.matrixWorld=new THREE.Matrix4,this.matrixAutoUpdate=!0,this.matrixWorldNeedsUpdate=!1,this.visible=!0,this.castShadow=!1,this.receiveShadow=!1,this.frustumCulled=!0,this.userData={}},THREE.Object3D.DefaultUp=new THREE.Vector3(0,1,0),THREE.Object3D.prototype={constructor:THREE.Object3D,get eulerOrder(){return console.warn("THREE.Object3D: .eulerOrder has been moved to .rotation.order."),this.rotation.order},set eulerOrder(t){console.warn("THREE.Object3D: .eulerOrder has been moved to .rotation.order."),this.rotation.order=t},get useQuaternion(){console.warn("THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.")},set useQuaternion(t){console.warn("THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.")},applyMatrix:function(t){this.matrix.multiplyMatrices(t,this.matrix),this.matrix.decompose(this.position,this.quaternion,this.scale)},setRotationFromAxisAngle:function(t,e){this.quaternion.setFromAxisAngle(t,e)},setRotationFromEuler:function(t){this.quaternion.setFromEuler(t,!0)},setRotationFromMatrix:function(t){this.quaternion.setFromRotationMatrix(t)},setRotationFromQuaternion:function(t){this.quaternion.copy(t)},rotateOnAxis:function(){var r=new THREE.Quaternion;return function(t,e){return r.setFromAxisAngle(t,e),this.quaternion.multiply(r),this}}(),rotateX:function(){var e=new THREE.Vector3(1,0,0);return function(t){return this.rotateOnAxis(e,t)}}(),rotateY:function(){var e=new THREE.Vector3(0,1,0);return function(t){return this.rotateOnAxis(e,t)}}(),rotateZ:function(){var e=new THREE.Vector3(0,0,1);return function(t){return this.rotateOnAxis(e,t)}}(),translateOnAxis:function(){var r=new THREE.Vector3;return function(t,e){return r.copy(t).applyQuaternion(this.quaternion),this.position.add(r.multiplyScalar(e)),this}}(),translate:function(t,e){return console.warn("THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead."),this.translateOnAxis(e,t)},translateX:function(){var e=new THREE.Vector3(1,0,0);return function(t){return this.translateOnAxis(e,t)}}(),translateY:function(){var e=new THREE.Vector3(0,1,0);return function(t){return this.translateOnAxis(e,t)}}(),translateZ:function(){var e=new THREE.Vector3(0,0,1);return function(t){return this.translateOnAxis(e,t)}}(),localToWorld:function(t){return t.applyMatrix4(this.matrixWorld)},worldToLocal:function(){var e=new THREE.Matrix4;return function(t){return t.applyMatrix4(e.getInverse(this.matrixWorld))}}(),lookAt:function(){var e=new THREE.Matrix4;return function(t){e.lookAt(t,this.position,this.up),this.quaternion.setFromRotationMatrix(e)}}(),add:function(t){if(1<arguments.length){for(var e=0;e<arguments.length;e++)this.add(arguments[e]);return this}return t===this?console.error("THREE.Object3D.add:",t,"can't be added as a child of itself."):t instanceof THREE.Object3D?(void 0!==t.parent&&t.parent.remove(t),t.parent=this,t.dispatchEvent({type:"added"}),this.children.push(t)):console.error("THREE.Object3D.add:",t,"is not an instance of THREE.Object3D."),this},remove:function(t){if(1<arguments.length)for(var e=0;e<arguments.length;e++)this.remove(arguments[e]);var r=this.children.indexOf(t);-1!==r&&(t.parent=void 0,t.dispatchEvent({type:"removed"}),this.children.splice(r,1))},getChildByName:function(t,e){return console.warn("THREE.Object3D: .getChildByName() has been renamed to .getObjectByName()."),this.getObjectByName(t,e)},getObjectById:function(t,e){if(this.id===t)return this;for(var r=0,i=this.children.length;r<i;r++){var n=this.children[r].getObjectById(t,e);if(void 0!==n)return n}},getObjectByName:function(t,e){if(this.name===t)return this;for(var r=0,i=this.children.length;r<i;r++){var n=this.children[r].getObjectByName(t,e);if(void 0!==n)return n}},getWorldPosition:function(t){var e=t||new THREE.Vector3;return this.updateMatrixWorld(!0),e.setFromMatrixPosition(this.matrixWorld)},getWorldQuaternion:function(){var r=new THREE.Vector3,i=new THREE.Vector3;return function(t){var e=t||new THREE.Quaternion;return this.updateMatrixWorld(!0),this.matrixWorld.decompose(r,e,i),e}}(),getWorldRotation:function(){var r=new THREE.Quaternion;return function(t){var e=t||new THREE.Euler;return this.getWorldQuaternion(r),e.setFromQuaternion(r,this.rotation.order,!1)}}(),getWorldScale:function(){var r=new THREE.Vector3,i=new THREE.Quaternion;return function(t){var e=t||new THREE.Vector3;return this.updateMatrixWorld(!0),this.matrixWorld.decompose(r,i,e),e}}(),getWorldDirection:function(){var r=new THREE.Quaternion;return function(t){var e=t||new THREE.Vector3;return this.getWorldQuaternion(r),e.set(0,0,1).applyQuaternion(r)}}(),raycast:function(){},traverse:function(t){t(this);for(var e=0,r=this.children.length;e<r;e++)this.children[e].traverse(t)},traverseVisible:function(t){if(!1!==this.visible){t(this);for(var e=0,r=this.children.length;e<r;e++)this.children[e].traverseVisible(t)}},updateMatrix:function(){this.matrix.compose(this.position,this.quaternion,this.scale),this.matrixWorldNeedsUpdate=!0},updateMatrixWorld:function(t){!0===this.matrixAutoUpdate&&this.updateMatrix(),!0!==this.matrixWorldNeedsUpdate&&!0!==t||(void 0===this.parent?this.matrixWorld.copy(this.matrix):this.matrixWorld.multiplyMatrices(this.parent.matrixWorld,this.matrix),t=!(this.matrixWorldNeedsUpdate=!1));for(var e=0,r=this.children.length;e<r;e++)this.children[e].updateMatrixWorld(t)},toJSON:function(){var r={metadata:{version:4.3,type:"Object",generator:"ObjectExporter"}},i={},n=function(t){if(void 0===r.geometries&&(r.geometries=[]),void 0===i[t.uuid]){var e=t.toJSON();delete e.metadata,i[t.uuid]=e,r.geometries.push(e)}return t.uuid},a={},o=function(t){if(void 0===r.materials&&(r.materials=[]),void 0===a[t.uuid]){var e=t.toJSON();delete e.metadata,a[t.uuid]=e,r.materials.push(e)}return t.uuid},s=function(t){var e={};if(e.uuid=t.uuid,e.type=t.type,""!==t.name&&(e.name=t.name),"{}"!==JSON.stringify(t.userData)&&(e.userData=t.userData),!0!==t.visible&&(e.visible=t.visible),t instanceof THREE.PerspectiveCamera?(e.fov=t.fov,e.aspect=t.aspect,e.near=t.near,e.far=t.far):t instanceof THREE.OrthographicCamera?(e.left=t.left,e.right=t.right,e.top=t.top,e.bottom=t.bottom,e.near=t.near,e.far=t.far):t instanceof THREE.AmbientLight?e.color=t.color.getHex():t instanceof THREE.DirectionalLight?(e.color=t.color.getHex(),e.intensity=t.intensity):t instanceof THREE.PointLight?(e.color=t.color.getHex(),e.intensity=t.intensity,e.distance=t.distance):t instanceof THREE.SpotLight?(e.color=t.color.getHex(),e.intensity=t.intensity,e.distance=t.distance,e.angle=t.angle,e.exponent=t.exponent):t instanceof THREE.HemisphereLight?(e.color=t.color.getHex(),e.groundColor=t.groundColor.getHex()):t instanceof THREE.Mesh?(e.geometry=n(t.geometry),e.material=o(t.material)):t instanceof THREE.Line?(e.geometry=n(t.geometry),e.material=o(t.material)):t instanceof THREE.Sprite&&(e.material=o(t.material)),e.matrix=t.matrix.toArray(),0<t.children.length){e.children=[];for(var r=0;r<t.children.length;r++)e.children.push(s(t.children[r]))}return e};return r.object=s(this),r},clone:function(t,e){if(void 0===t&&(t=new THREE.Object3D),void 0===e&&(e=!0),t.name=this.name,t.up.copy(this.up),t.position.copy(this.position),t.quaternion.copy(this.quaternion),t.scale.copy(this.scale),t.renderDepth=this.renderDepth,t.rotationAutoUpdate=this.rotationAutoUpdate,t.matrix.copy(this.matrix),t.matrixWorld.copy(this.matrixWorld),t.matrixAutoUpdate=this.matrixAutoUpdate,t.matrixWorldNeedsUpdate=this.matrixWorldNeedsUpdate,t.visible=this.visible,t.castShadow=this.castShadow,t.receiveShadow=this.receiveShadow,t.frustumCulled=this.frustumCulled,t.userData=JSON.parse(JSON.stringify(this.userData)),!0===e)for(var r=0;r<this.children.length;r++){var i=this.children[r];t.add(i.clone())}return t}},THREE.EventDispatcher.prototype.apply(THREE.Object3D.prototype),THREE.Object3DIdCount=0,THREE.Face3=function(t,e,r,i,n,a){this.a=t,this.b=e,this.c=r,this.normal=i instanceof THREE.Vector3?i:new THREE.Vector3,this.vertexNormals=i instanceof Array?i:[],this.color=n instanceof THREE.Color?n:new THREE.Color,this.vertexColors=n instanceof Array?n:[],this.vertexTangents=[],this.materialIndex=void 0!==a?a:0},THREE.Face3.prototype={constructor:THREE.Face3,clone:function(){var t=new THREE.Face3(this.a,this.b,this.c);t.normal.copy(this.normal),t.color.copy(this.color),t.materialIndex=this.materialIndex;for(var e=0,r=this.vertexNormals.length;e<r;e++)t.vertexNormals[e]=this.vertexNormals[e].clone();for(e=0,r=this.vertexColors.length;e<r;e++)t.vertexColors[e]=this.vertexColors[e].clone();for(e=0,r=this.vertexTangents.length;e<r;e++)t.vertexTangents[e]=this.vertexTangents[e].clone();return t}},THREE.BufferAttribute=function(t,e){this.array=t,this.itemSize=e,this.needsUpdate=!1},THREE.BufferAttribute.prototype={constructor:THREE.BufferAttribute,get length(){return this.array.length},copyAt:function(t,e,r){t*=this.itemSize,r*=e.itemSize;for(var i=0,n=this.itemSize;i<n;i++)this.array[t+i]=e.array[r+i]},set:function(t){return this.array.set(t),this},setX:function(t,e){return this.array[t*this.itemSize]=e,this},setY:function(t,e){return this.array[t*this.itemSize+1]=e,this},setZ:function(t,e){return this.array[t*this.itemSize+2]=e,this},setXY:function(t,e,r){return t*=this.itemSize,this.array[t]=e,this.array[t+1]=r,this},setXYZ:function(t,e,r,i){return t*=this.itemSize,this.array[t]=e,this.array[t+1]=r,this.array[t+2]=i,this},setXYZW:function(t,e,r,i,n){return t*=this.itemSize,this.array[t]=e,this.array[t+1]=r,this.array[t+2]=i,this.array[t+3]=n,this},clone:function(){return new THREE.BufferAttribute(new this.array.constructor(this.array),this.itemSize)}},THREE.BufferGeometry=function(){Object.defineProperty(this,"id",{value:THREE.GeometryIdCount++}),this.uuid=THREE.Math.generateUUID(),this.name="",this.type="BufferGeometry",this.attributes={},this.attributesKeys=[],this.drawcalls=[],this.offsets=this.drawcalls,this.boundingBox=null,this.boundingSphere=null},THREE.BufferGeometry.prototype={constructor:THREE.BufferGeometry,addAttribute:function(t,e){if(e instanceof THREE.BufferAttribute==!1)return console.warn("THREE.BufferGeometry: .addAttribute() now expects ( name, attribute )."),void(this.attributes[t]={array:e,itemSize:arguments[2]});this.attributes[t]=e,this.attributesKeys=Object.keys(this.attributes)},getAttribute:function(t){return this.attributes[t]},addDrawCall:function(t,e,r){this.drawcalls.push({start:t,count:e,index:void 0!==r?r:0})},applyMatrix:function(t){var e=this.attributes.position;void 0!==e&&(t.applyToVector3Array(e.array),e.needsUpdate=!0);var r=this.attributes.normal;void 0!==r&&((new THREE.Matrix3).getNormalMatrix(t).applyToVector3Array(r.array),r.needsUpdate=!0)},center:function(){},fromGeometry:function(t,e){e=e||{vertexColors:THREE.NoColors};var r=t.vertices,i=t.faces,n=t.faceVertexUvs,a=e.vertexColors,o=0<n[0].length,s=3==i[0].vertexNormals.length,h=new Float32Array(3*i.length*3);this.addAttribute("position",new THREE.BufferAttribute(h,3));var l=new Float32Array(3*i.length*3);if(this.addAttribute("normal",new THREE.BufferAttribute(l,3)),a!==THREE.NoColors){var u=new Float32Array(3*i.length*3);this.addAttribute("color",new THREE.BufferAttribute(u,3))}if(!0===o){var c=new Float32Array(3*i.length*2);this.addAttribute("uv",new THREE.BufferAttribute(c,2))}for(var f=0,d=0,p=0;f<i.length;f++,d+=6,p+=9){var E=i[f],m=r[E.a],g=r[E.b],v=r[E.c];if(h[p]=m.x,h[p+1]=m.y,h[p+2]=m.z,h[p+3]=g.x,h[p+4]=g.y,h[p+5]=g.z,h[p+6]=v.x,h[p+7]=v.y,h[p+8]=v.z,!0===s){var T=E.vertexNormals[0],x=E.vertexNormals[1],y=E.vertexNormals[2];l[p]=T.x,l[p+1]=T.y,l[p+2]=T.z,l[p+3]=x.x,l[p+4]=x.y,l[p+5]=x.z,l[p+6]=y.x,l[p+7]=y.y,l[p+8]=y.z}else{var R=E.normal;l[p]=R.x,l[p+1]=R.y,l[p+2]=R.z,l[p+3]=R.x,l[p+4]=R.y,l[p+5]=R.z,l[p+6]=R.x,l[p+7]=R.y,l[p+8]=R.z}if(a===THREE.FaceColors){var _=E.color;u[p]=_.r,u[p+1]=_.g,u[p+2]=_.b,u[p+3]=_.r,u[p+4]=_.g,u[p+5]=_.b,u[p+6]=_.r,u[p+7]=_.g,u[p+8]=_.b}else if(a===THREE.VertexColors){var H=E.vertexColors[0],b=E.vertexColors[1],M=E.vertexColors[2];u[p]=H.r,u[p+1]=H.g,u[p+2]=H.b,u[p+3]=b.r,u[p+4]=b.g,u[p+5]=b.b,u[p+6]=M.r,u[p+7]=M.g,u[p+8]=M.b}if(!0===o){var w=n[0][f][0],S=n[0][f][1],A=n[0][f][2];c[d]=w.x,c[d+1]=w.y,c[d+2]=S.x,c[d+3]=S.y,c[d+4]=A.x,c[d+5]=A.y}}return this.computeBoundingSphere(),this},computeBoundingBox:function(){var n=new THREE.Vector3;return function(){null===this.boundingBox&&(this.boundingBox=new THREE.Box3);var t=this.attributes.position.array;if(t){var e=this.boundingBox;e.makeEmpty();for(var r=0,i=t.length;r<i;r+=3)n.set(t[r],t[r+1],t[r+2]),e.expandByPoint(n)}void 0!==t&&0!==t.length||(this.boundingBox.min.set(0,0,0),this.boundingBox.max.set(0,0,0)),(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.')}}(),computeBoundingSphere:function(){var a=new THREE.Box3,o=new THREE.Vector3;return function(){null===this.boundingSphere&&(this.boundingSphere=new THREE.Sphere);var t=this.attributes.position.array;if(t){a.makeEmpty();for(var e=this.boundingSphere.center,r=0,i=t.length;r<i;r+=3)o.set(t[r],t[r+1],t[r+2]),a.expandByPoint(o);a.center(e);var n=0;for(r=0,i=t.length;r<i;r+=3)o.set(t[r],t[r+1],t[r+2]),n=Math.max(n,e.distanceToSquared(o));this.boundingSphere.radius=Math.sqrt(n),isNaN(this.boundingSphere.radius)&&console.error('THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.')}}}(),computeFaceNormals:function(){},computeVertexNormals:function(){var t=this.attributes;if(t.position){var e=t.position.array;if(void 0===t.normal)this.addAttribute("normal",new THREE.BufferAttribute(new Float32Array(e.length),3));else for(var r=0,i=(s=t.normal.array).length;r<i;r++)s[r]=0;var n,a,o,s=t.normal.array,h=new THREE.Vector3,l=new THREE.Vector3,u=new THREE.Vector3,c=new THREE.Vector3,f=new THREE.Vector3;if(t.index)for(var d=t.index.array,p=0<this.offsets.length?this.offsets:[{start:0,count:d.length,index:0}],E=0,m=p.length;E<m;++E){var g=p[E].start,v=p[E].count,T=p[E].index;for(r=g,i=g+v;r<i;r+=3)n=3*(T+d[r]),a=3*(T+d[r+1]),o=3*(T+d[r+2]),h.fromArray(e,n),l.fromArray(e,a),u.fromArray(e,o),c.subVectors(u,l),f.subVectors(h,l),c.cross(f),s[n]+=c.x,s[n+1]+=c.y,s[n+2]+=c.z,s[a]+=c.x,s[a+1]+=c.y,s[a+2]+=c.z,s[o]+=c.x,s[o+1]+=c.y,s[o+2]+=c.z}else for(r=0,i=e.length;r<i;r+=9)h.fromArray(e,r),l.fromArray(e,r+3),u.fromArray(e,r+6),c.subVectors(u,l),f.subVectors(h,l),c.cross(f),s[r]=c.x,s[r+1]=c.y,s[r+2]=c.z,s[r+3]=c.x,s[r+4]=c.y,s[r+5]=c.z,s[r+6]=c.x,s[r+7]=c.y,s[r+8]=c.z;this.normalizeNormals(),t.normal.needsUpdate=!0}},computeTangents:function(){if(void 0!==this.attributes.index&&void 0!==this.attributes.position&&void 0!==this.attributes.normal&&void 0!==this.attributes.uv){var t=this.attributes.index.array,e=this.attributes.position.array,r=this.attributes.normal.array,i=this.attributes.uv.array,n=e.length/3;void 0===this.attributes.tangent&&this.addAttribute("tangent",new THREE.BufferAttribute(new Float32Array(4*n),4));for(var a=this.attributes.tangent.array,o=[],s=[],h=0;h<n;h++)o[h]=new THREE.Vector3,s[h]=new THREE.Vector3;var l,u,c,f,d,p,E,m,g,v,T,x,y,R,_,H,b,M,w=new THREE.Vector3,S=new THREE.Vector3,A=new THREE.Vector3,C=new THREE.Vector2,D=new THREE.Vector2,L=new THREE.Vector2,F=new THREE.Vector3,P=new THREE.Vector3;0===this.drawcalls.length&&this.addDrawCall(0,t.length,0);var U,B,z,N=this.drawcalls;for(R=0,_=N.length;R<_;++R){var k=N[R].start,V=N[R].count,O=N[R].index;for(y=(x=k)+V;x<y;x+=3)H=O+t[x],b=O+t[x+1],M=O+t[x+2],U=H,B=b,z=M,w.fromArray(e,3*U),S.fromArray(e,3*B),A.fromArray(e,3*z),C.fromArray(i,2*U),D.fromArray(i,2*B),L.fromArray(i,2*z),l=S.x-w.x,u=A.x-w.x,c=S.y-w.y,f=A.y-w.y,d=S.z-w.z,p=A.z-w.z,E=D.x-C.x,m=L.x-C.x,g=D.y-C.y,v=L.y-C.y,T=1/(E*v-m*g),F.set((v*l-g*u)*T,(v*c-g*f)*T,(v*d-g*p)*T),P.set((E*u-m*l)*T,(E*f-m*c)*T,(E*p-m*d)*T),o[U].add(F),o[B].add(F),o[z].add(F),s[U].add(P),s[B].add(P),s[z].add(P)}var I,G,W,X=new THREE.Vector3,j=new THREE.Vector3,Y=new THREE.Vector3,q=new THREE.Vector3;for(R=0,_=N.length;R<_;++R){k=N[R].start,V=N[R].count,O=N[R].index;for(y=(x=k)+V;x<y;x+=3)H=O+t[x],b=O+t[x+1],M=O+t[x+2],K(H),K(b),K(M)}}else console.warn("Missing required attributes (index, position, normal or uv) in BufferGeometry.computeTangents()");function K(t){Y.fromArray(r,3*t),q.copy(Y),G=o[t],X.copy(G),X.sub(Y.multiplyScalar(Y.dot(G))).normalize(),j.crossVectors(q,G),W=j.dot(s[t]),I=W<0?-1:1,a[4*t]=X.x,a[4*t+1]=X.y,a[4*t+2]=X.z,a[4*t+3]=I}},computeOffsets:function(t){var e=t;void 0===t&&(e=65535);Date.now();for(var r=this.attributes.index.array,i=this.attributes.position.array,n=(i.length,r.length/3),a=new Uint16Array(r.length),o=0,s=0,h=[{start:0,count:0,index:0}],l=h[0],u=0,c=new Int32Array(6),f=new Int32Array(i.length),d=new Int32Array(i.length),p=0;p<i.length;p++)f[p]=-1,d[p]=-1;for(var E=0;E<n;E++){for(var m=u=0;m<3;m++){-1==f[x=r[3*E+m]]?(c[2*m]=x,c[2*m+1]=-1,u++):f[x]<l.index?(c[2*m]=x,c[2*m+1]=-1,0):(c[2*m]=x,c[2*m+1]=f[x])}if(s+u>l.index+e){var g={start:o,count:0,index:s};h.push(g),l=g;for(var v=0;v<6;v+=2){-1<(T=c[v+1])&&T<l.index&&(c[v+1]=-1)}}for(v=0;v<6;v+=2){var T,x=c[v];-1===(T=c[v+1])&&(T=s++),d[f[x]=T]=x,a[o++]=T-l.index,l.count++}}return this.reorderBuffers(a,d,s),this.offsets=h},merge:function(){console.log("BufferGeometry.merge(): TODO")},normalizeNormals:function(){for(var t,e,r,i,n=this.attributes.normal.array,a=0,o=n.length;a<o;a+=3)t=n[a],e=n[a+1],r=n[a+2],i=1/Math.sqrt(t*t+e*e+r*r),n[a]*=i,n[a+1]*=i,n[a+2]*=i},reorderBuffers:function(t,e,r){var i={};for(var n in this.attributes)if("index"!=n){var a=this.attributes[n].array;i[n]=new a.constructor(this.attributes[n].itemSize*r)}for(var o=0;o<r;o++){var s=e[o];for(var n in this.attributes)if("index"!=n)for(var h=this.attributes[n].array,l=this.attributes[n].itemSize,u=i[n],c=0;c<l;c++)u[o*l+c]=h[s*l+c]}for(var n in this.attributes.index.array=t,this.attributes)"index"!=n&&(this.attributes[n].array=i[n],this.attributes[n].numItems=this.attributes[n].itemSize*r)},toJSON:function(){var t={metadata:{version:4,type:"BufferGeometry",generator:"BufferGeometryExporter"},uuid:this.uuid,type:this.type,data:{attributes:{}}},e=this.attributes,r=this.offsets,i=this.boundingSphere;for(var n in e){for(var a=e[n],o=[],s=a.array,h=0,l=s.length;h<l;h++)o[h]=s[h];t.data.attributes[n]={itemSize:a.itemSize,type:a.array.constructor.name,array:o}}return 0<r.length&&(t.data.offsets=JSON.parse(JSON.stringify(r))),null!==i&&(t.data.boundingSphere={center:i.center.toArray(),radius:i.radius}),t},clone:function(){var t=new THREE.BufferGeometry;for(var e in this.attributes){var r=this.attributes[e];t.addAttribute(e,r.clone())}for(var i=0,n=this.offsets.length;i<n;i++){var a=this.offsets[i];t.offsets.push({start:a.start,index:a.index,count:a.count})}return t},dispose:function(){this.dispatchEvent({type:"dispose"})}},THREE.EventDispatcher.prototype.apply(THREE.BufferGeometry.prototype),THREE.Geometry=function(){Object.defineProperty(this,"id",{value:THREE.GeometryIdCount++}),this.uuid=THREE.Math.generateUUID(),this.name="",this.type="Geometry",this.vertices=[],this.colors=[],this.faces=[],this.faceVertexUvs=[[]],this.morphTargets=[],this.morphColors=[],this.morphNormals=[],this.skinWeights=[],this.skinIndices=[],this.lineDistances=[],this.boundingBox=null,this.boundingSphere=null,this.hasTangents=!1,this.dynamic=!0,this.verticesNeedUpdate=!1,this.elementsNeedUpdate=!1,this.uvsNeedUpdate=!1,this.normalsNeedUpdate=!1,this.tangentsNeedUpdate=!1,this.colorsNeedUpdate=!1,this.lineDistancesNeedUpdate=!1,this.groupsNeedUpdate=!1},THREE.Geometry.prototype={constructor:THREE.Geometry,applyMatrix:function(t){for(var e=(new THREE.Matrix3).getNormalMatrix(t),r=0,i=this.vertices.length;r<i;r++){this.vertices[r].applyMatrix4(t)}for(r=0,i=this.faces.length;r<i;r++){var n=this.faces[r];n.normal.applyMatrix3(e).normalize();for(var a=0,o=n.vertexNormals.length;a<o;a++)n.vertexNormals[a].applyMatrix3(e).normalize()}this.boundingBox instanceof THREE.Box3&&this.computeBoundingBox(),this.boundingSphere instanceof THREE.Sphere&&this.computeBoundingSphere()},fromBufferGeometry:function(t){for(var a=this,e=t.attributes,r=e.position.array,i=void 0!==e.index?e.index.array:void 0,o=void 0!==e.normal?e.normal.array:void 0,s=void 0!==e.color?e.color.array:void 0,n=void 0!==e.uv?e.uv.array:void 0,h=[],l=[],u=0,c=0;u<r.length;u+=3,c+=2)a.vertices.push(new THREE.Vector3(r[u],r[u+1],r[u+2])),void 0!==o&&h.push(new THREE.Vector3(o[u],o[u+1],o[u+2])),void 0!==s&&a.colors.push(new THREE.Color(s[u],s[u+1],s[u+2])),void 0!==n&&l.push(new THREE.Vector2(n[c],n[c+1]));var f=function(t,e,r){var i=void 0!==o?[h[t].clone(),h[e].clone(),h[r].clone()]:[],n=void 0!==s?[a.colors[t].clone(),a.colors[e].clone(),a.colors[r].clone()]:[];a.faces.push(new THREE.Face3(t,e,r,i,n)),a.faceVertexUvs[0].push([l[t],l[e],l[r]])};if(void 0!==i)for(u=0;u<i.length;u+=3)f(i[u],i[u+1],i[u+2]);else for(u=0;u<r.length/3;u+=3)f(u,u+1,u+2);return this.computeFaceNormals(),null!==t.boundingBox&&(this.boundingBox=t.boundingBox.clone()),null!==t.boundingSphere&&(this.boundingSphere=t.boundingSphere.clone()),this},center:function(){this.computeBoundingBox();var t=new THREE.Vector3;return t.addVectors(this.boundingBox.min,this.boundingBox.max),t.multiplyScalar(-.5),this.applyMatrix((new THREE.Matrix4).makeTranslation(t.x,t.y,t.z)),this.computeBoundingBox(),t},computeFaceNormals:function(){for(var t=new THREE.Vector3,e=new THREE.Vector3,r=0,i=this.faces.length;r<i;r++){var n=this.faces[r],a=this.vertices[n.a],o=this.vertices[n.b],s=this.vertices[n.c];t.subVectors(s,o),e.subVectors(a,o),t.cross(e),t.normalize(),n.normal.copy(t)}},computeVertexNormals:function(t){var e,r,i,n,a,o;for(o=new Array(this.vertices.length),e=0,r=this.vertices.length;e<r;e++)o[e]=new THREE.Vector3;if(t){var s,h,l,u=new THREE.Vector3,c=new THREE.Vector3;new THREE.Vector3,new THREE.Vector3,new THREE.Vector3;for(i=0,n=this.faces.length;i<n;i++)a=this.faces[i],s=this.vertices[a.a],h=this.vertices[a.b],l=this.vertices[a.c],u.subVectors(l,h),c.subVectors(s,h),u.cross(c),o[a.a].add(u),o[a.b].add(u),o[a.c].add(u)}else for(i=0,n=this.faces.length;i<n;i++)o[(a=this.faces[i]).a].add(a.normal),o[a.b].add(a.normal),o[a.c].add(a.normal);for(e=0,r=this.vertices.length;e<r;e++)o[e].normalize();for(i=0,n=this.faces.length;i<n;i++)(a=this.faces[i]).vertexNormals[0]=o[a.a].clone(),a.vertexNormals[1]=o[a.b].clone(),a.vertexNormals[2]=o[a.c].clone()},computeMorphNormals:function(){var t,e,r,i,n;for(r=0,i=this.faces.length;r<i;r++)for((n=this.faces[r]).__originalFaceNormal?n.__originalFaceNormal.copy(n.normal):n.__originalFaceNormal=n.normal.clone(),n.__originalVertexNormals||(n.__originalVertexNormals=[]),t=0,e=n.vertexNormals.length;t<e;t++)n.__originalVertexNormals[t]?n.__originalVertexNormals[t].copy(n.vertexNormals[t]):n.__originalVertexNormals[t]=n.vertexNormals[t].clone();var a=new THREE.Geometry;for(a.faces=this.faces,t=0,e=this.morphTargets.length;t<e;t++){if(!this.morphNormals[t]){this.morphNormals[t]={},this.morphNormals[t].faceNormals=[],this.morphNormals[t].vertexNormals=[];var o=this.morphNormals[t].faceNormals,s=this.morphNormals[t].vertexNormals;for(r=0,i=this.faces.length;r<i;r++)h=new THREE.Vector3,l={a:new THREE.Vector3,b:new THREE.Vector3,c:new THREE.Vector3},o.push(h),s.push(l)}var h,l,u=this.morphNormals[t];for(a.vertices=this.morphTargets[t].vertices,a.computeFaceNormals(),a.computeVertexNormals(),r=0,i=this.faces.length;r<i;r++)n=this.faces[r],h=u.faceNormals[r],l=u.vertexNormals[r],h.copy(n.normal),l.a.copy(n.vertexNormals[0]),l.b.copy(n.vertexNormals[1]),l.c.copy(n.vertexNormals[2])}for(r=0,i=this.faces.length;r<i;r++)(n=this.faces[r]).normal=n.__originalFaceNormal,n.vertexNormals=n.__originalVertexNormals},computeTangents:function(){var t,e,r,i,n,a,o,s,h,l,u,c,f,d,p,E,m,g,v,T,x,y,R,_,H,b,M,w,S,A,C,D,L,F,P=[],U=[],B=new THREE.Vector3,z=new THREE.Vector3,N=new THREE.Vector3,k=new THREE.Vector3,V=new THREE.Vector3;for(r=0,i=this.vertices.length;r<i;r++)P[r]=new THREE.Vector3,U[r]=new THREE.Vector3;for(t=0,e=this.faces.length;t<e;t++)o=this.faces[t],s=this.faceVertexUvs[0][t],w=this,S=o.a,A=o.b,C=o.c,D=0,L=1,F=2,h=w.vertices[S],l=w.vertices[A],u=w.vertices[C],c=s[D],f=s[L],d=s[F],p=l.x-h.x,E=u.x-h.x,m=l.y-h.y,g=u.y-h.y,v=l.z-h.z,T=u.z-h.z,x=f.x-c.x,y=d.x-c.x,R=f.y-c.y,_=d.y-c.y,H=1/(x*_-y*R),B.set((_*p-R*E)*H,(_*m-R*g)*H,(_*v-R*T)*H),z.set((x*E-y*p)*H,(x*g-y*m)*H,(x*T-y*v)*H),P[S].add(B),P[A].add(B),P[C].add(B),U[S].add(z),U[A].add(z),U[C].add(z);var O=["a","b","c","d"];for(t=0,e=this.faces.length;t<e;t++)for(o=this.faces[t],n=0;n<Math.min(o.vertexNormals.length,3);n++)V.copy(o.vertexNormals[n]),a=o[O[n]],b=P[a],N.copy(b),N.sub(V.multiplyScalar(V.dot(b))).normalize(),k.crossVectors(o.vertexNormals[n],b),M=k.dot(U[a])<0?-1:1,o.vertexTangents[n]=new THREE.Vector4(N.x,N.y,N.z,M);this.hasTangents=!0},computeLineDistances:function(){for(var t=0,e=this.vertices,r=0,i=e.length;r<i;r++)0<r&&(t+=e[r].distanceTo(e[r-1])),this.lineDistances[r]=t},computeBoundingBox:function(){null===this.boundingBox&&(this.boundingBox=new THREE.Box3),this.boundingBox.setFromPoints(this.vertices)},computeBoundingSphere:function(){null===this.boundingSphere&&(this.boundingSphere=new THREE.Sphere),this.boundingSphere.setFromPoints(this.vertices)},merge:function(t,e,r){if(t instanceof THREE.Geometry!=!1){var i,n=this.vertices.length,a=this.vertices,o=t.vertices,s=this.faces,h=t.faces,l=this.faceVertexUvs[0],u=t.faceVertexUvs[0];void 0===r&&(r=0),void 0!==e&&(i=(new THREE.Matrix3).getNormalMatrix(e));for(var c=0,f=o.length;c<f;c++){var d=o[c].clone();void 0!==e&&d.applyMatrix4(e),a.push(d)}for(c=0,f=h.length;c<f;c++){var p,E,m,g=h[c],v=g.vertexNormals,T=g.vertexColors;(p=new THREE.Face3(g.a+n,g.b+n,g.c+n)).normal.copy(g.normal),void 0!==i&&p.normal.applyMatrix3(i).normalize();for(var x=0,y=v.length;x<y;x++)E=v[x].clone(),void 0!==i&&E.applyMatrix3(i).normalize(),p.vertexNormals.push(E);p.color.copy(g.color);for(x=0,y=T.length;x<y;x++)m=T[x],p.vertexColors.push(m.clone());p.materialIndex=g.materialIndex+r,s.push(p)}for(c=0,f=u.length;c<f;c++){var R=u[c],_=[];if(void 0!==R){for(x=0,y=R.length;x<y;x++)_.push(new THREE.Vector2(R[x].x,R[x].y));l.push(_)}}}else console.error("THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.",t)},mergeVertices:function(){var t,e,r,i,n,a,o,s,h={},l=[],u=[],c=Math.pow(10,4);for(r=0,i=this.vertices.length;r<i;r++)t=this.vertices[r],void 0===h[e=Math.round(t.x*c)+"_"+Math.round(t.y*c)+"_"+Math.round(t.z*c)]?(h[e]=r,l.push(this.vertices[r]),u[r]=l.length-1):u[r]=u[h[e]];var f=[];for(r=0,i=this.faces.length;r<i;r++){(n=this.faces[r]).a=u[n.a],n.b=u[n.b],n.c=u[n.c],a=[n.a,n.b,n.c];for(var d=0;d<3;d++)if(a[d]==a[(d+1)%3]){d,f.push(r);break}}for(r=f.length-1;0<=r;r--){var p=f[r];for(this.faces.splice(p,1),o=0,s=this.faceVertexUvs.length;o<s;o++)this.faceVertexUvs[o].splice(p,1)}var E=this.vertices.length-l.length;return this.vertices=l,E},toJSON:function(){var t={metadata:{version:4,type:"BufferGeometry",generator:"BufferGeometryExporter"},uuid:this.uuid,type:this.type};if(""!==this.name&&(t.name=this.name),void 0!==this.parameters){var e=this.parameters;for(var r in e)void 0!==e[r]&&(t[r]=e[r]);return t}for(var i=[],n=0;n<this.vertices.length;n++){var a=this.vertices[n];i.push(a.x,a.y,a.z)}var o=[],s=[],h={},l=[],u={},c=[],f={};for(n=0;n<this.faces.length;n++){var d=this.faces[n],p=void 0!==this.faceVertexUvs[0][n],E=0<d.normal.length(),m=0<d.vertexNormals.length,g=1!==d.color.r||1!==d.color.g||1!==d.color.b,v=0<d.vertexColors.length,T=0;if(T=_(T=_(T=_(T=_(T=_(T=_(T=_(T=_(T,0,0),1,!1),2,!1),3,p),4,E),5,m),6,g),7,v),o.push(T),o.push(d.a,d.b,d.c),p){var x=this.faceVertexUvs[0][n];o.push(M(x[0]),M(x[1]),M(x[2]))}if(E&&o.push(H(d.normal)),m){var y=d.vertexNormals;o.push(H(y[0]),H(y[1]),H(y[2]))}if(g&&o.push(b(d.color)),v){var R=d.vertexColors;o.push(b(R[0]),b(R[1]),b(R[2]))}}function _(t,e,r){return r?t|1<<e:t&~(1<<e)}function H(t){var e=t.x.toString()+t.y.toString()+t.z.toString();return void 0!==h[e]||(h[e]=s.length/3,s.push(t.x,t.y,t.z)),h[e]}function b(t){var e=t.r.toString()+t.g.toString()+t.b.toString();return void 0!==u[e]||(u[e]=l.length,l.push(t.getHex())),u[e]}function M(t){var e=t.x.toString()+t.y.toString();return void 0!==f[e]||(f[e]=c.length/2,c.push(t.x,t.y)),f[e]}return t.data={},t.data.vertices=i,t.data.normals=s,0<l.length&&(t.data.colors=l),0<c.length&&(t.data.uvs=[c]),t.data.faces=o,t},clone:function(){for(var t=new THREE.Geometry,e=this.vertices,r=0,i=e.length;r<i;r++)t.vertices.push(e[r].clone());var n=this.faces;for(r=0,i=n.length;r<i;r++)t.faces.push(n[r].clone());var a=this.faceVertexUvs[0];for(r=0,i=a.length;r<i;r++){for(var o=a[r],s=[],h=0,l=o.length;h<l;h++)s.push(new THREE.Vector2(o[h].x,o[h].y));t.faceVertexUvs[0].push(s)}return t},dispose:function(){this.dispatchEvent({type:"dispose"})}},THREE.EventDispatcher.prototype.apply(THREE.Geometry.prototype),THREE.GeometryIdCount=0,THREE.Camera=function(){THREE.Object3D.call(this),this.type="Camera",this.matrixWorldInverse=new THREE.Matrix4,this.projectionMatrix=new THREE.Matrix4},THREE.Camera.prototype=Object.create(THREE.Object3D.prototype),THREE.Camera.prototype.getWorldDirection=function(){var r=new THREE.Quaternion;return function(t){var e=t||new THREE.Vector3;return this.getWorldQuaternion(r),e.set(0,0,-1).applyQuaternion(r)}}(),THREE.Camera.prototype.lookAt=function(){var e=new THREE.Matrix4;return function(t){e.lookAt(this.position,t,this.up),this.quaternion.setFromRotationMatrix(e)}}(),THREE.Camera.prototype.clone=function(t){return void 0===t&&(t=new THREE.Camera),THREE.Object3D.prototype.clone.call(this,t),t.matrixWorldInverse.copy(this.matrixWorldInverse),t.projectionMatrix.copy(this.projectionMatrix),t},THREE.PerspectiveCamera=function(t,e,r,i){THREE.Camera.call(this),this.type="PerspectiveCamera",this.zoom=1,this.fov=void 0!==t?t:50,this.aspect=void 0!==e?e:1,this.near=void 0!==r?r:.1,this.far=void 0!==i?i:2e3,this.updateProjectionMatrix()},THREE.PerspectiveCamera.prototype=Object.create(THREE.Camera.prototype),THREE.PerspectiveCamera.prototype.setLens=function(t,e){void 0===e&&(e=24),this.fov=2*THREE.Math.radToDeg(Math.atan(e/(2*t))),this.updateProjectionMatrix()},THREE.PerspectiveCamera.prototype.setViewOffset=function(t,e,r,i,n,a){this.fullWidth=t,this.fullHeight=e,this.x=r,this.y=i,this.width=n,this.height=a,this.updateProjectionMatrix()},THREE.PerspectiveCamera.prototype.updateProjectionMatrix=function(){var t=THREE.Math.radToDeg(2*Math.atan(Math.tan(.5*THREE.Math.degToRad(this.fov))/this.zoom));if(this.fullWidth){var e=this.fullWidth/this.fullHeight,r=Math.tan(THREE.Math.degToRad(.5*t))*this.near,i=-r,n=e*i,a=e*r,o=Math.abs(a-n),s=Math.abs(r-i);this.projectionMatrix.makeFrustum(n+this.x*o/this.fullWidth,n+(this.x+this.width)*o/this.fullWidth,r-(this.y+this.height)*s/this.fullHeight,r-this.y*s/this.fullHeight,this.near,this.far)}else this.projectionMatrix.makePerspective(t,this.aspect,this.near,this.far)},THREE.PerspectiveCamera.prototype.clone=function(){var t=new THREE.PerspectiveCamera;return THREE.Camera.prototype.clone.call(this,t),t.zoom=this.zoom,t.fov=this.fov,t.aspect=this.aspect,t.near=this.near,t.far=this.far,t.projectionMatrix.copy(this.projectionMatrix),t},THREE.Light=function(t){THREE.Object3D.call(this),this.type="Light",this.color=new THREE.Color(t)},THREE.Light.prototype=Object.create(THREE.Object3D.prototype),THREE.Light.prototype.clone=function(t){return void 0===t&&(t=new THREE.Light),THREE.Object3D.prototype.clone.call(this,t),t.color.copy(this.color),t},THREE.Cache=function(){this.files={}},THREE.Cache.prototype={constructor:THREE.Cache,add:function(t,e){this.files[t]=e},get:function(t){return this.files[t]},remove:function(t){delete this.files[t]},clear:function(){this.files={}}},THREE.Loader=function(t){this.showStatus=t,this.statusDomElement=t?THREE.Loader.prototype.addStatusElement():null,this.imageLoader=new THREE.ImageLoader,this.onLoadStart=function(){},this.onLoadProgress=function(){},this.onLoadComplete=function(){}},THREE.Loader.prototype={constructor:THREE.Loader,crossOrigin:void 0,addStatusElement:function(){var t=document.createElement("div");return t.style.position="absolute",t.style.right="0px",t.style.top="0px",t.style.fontSize="0.8em",t.style.textAlign="left",t.style.background="rgba(0,0,0,0.25)",t.style.color="#fff",t.style.width="120px",t.style.padding="0.5em 0.5em 0.5em 0.5em",t.style.zIndex=1e3,t.innerHTML="Loading ...",t},updateProgress:function(t){var e="Loaded ";t.total?e+=(100*t.loaded/t.total).toFixed(0)+"%":e+=(t.loaded/1024).toFixed(2)+" KB",this.statusDomElement.innerHTML=e},extractUrlBase:function(t){var e=t.split("/");return 1===e.length?"./":(e.pop(),e.join("/")+"/")},initMaterials:function(t,e){for(var r=[],i=0;i<t.length;++i)r[i]=this.createMaterial(t[i],e);return r},needsTangents:function(t){for(var e=0,r=t.length;e<r;e++){if(t[e]instanceof THREE.ShaderMaterial)return!0}return!1},createMaterial:function(t,c){var f=this;function d(t){var e=Math.log(t)/Math.LN2;return Math.pow(2,Math.round(e))}function e(t,e,r,i,n,a,o){var s,h=c+r,l=THREE.Loader.Handlers.get(h);if(null!==l?s=l.load(h):(s=new THREE.Texture,(l=f.imageLoader).crossOrigin=f.crossOrigin,l.load(h,function(t){if(!1===THREE.Math.isPowerOfTwo(t.width)||!1===THREE.Math.isPowerOfTwo(t.height)){var e=d(t.width),r=d(t.height),i=document.createElement("canvas");i.width=e,i.height=r,i.getContext("2d").drawImage(t,0,0,e,r),s.image=i}else s.image=t;s.needsUpdate=!0})),s.sourceFile=r,i&&(s.repeat.set(i[0],i[1]),1!==i[0]&&(s.wrapS=THREE.RepeatWrapping),1!==i[1]&&(s.wrapT=THREE.RepeatWrapping)),n&&s.offset.set(n[0],n[1]),a){var u={repeat:THREE.RepeatWrapping,mirror:THREE.MirroredRepeatWrapping};void 0!==u[a[0]]&&(s.wrapS=u[a[0]]),void 0!==u[a[1]]&&(s.wrapT=u[a[1]])}o&&(s.anisotropy=o),t[e]=s}function r(t){return(255*t[0]<<16)+(255*t[1]<<8)+255*t[2]}var i="MeshLambertMaterial",n={color:15658734,opacity:1,map:null,lightMap:null,normalMap:null,bumpMap:null,wireframe:!1};if(t.shading){var a=t.shading.toLowerCase();"phong"===a?i="MeshPhongMaterial":"basic"===a&&(i="MeshBasicMaterial")}if(void 0!==t.blending&&void 0!==THREE[t.blending]&&(n.blending=THREE[t.blending]),(void 0!==t.transparent||t.opacity<1)&&(n.transparent=t.transparent),void 0!==t.depthTest&&(n.depthTest=t.depthTest),void 0!==t.depthWrite&&(n.depthWrite=t.depthWrite),void 0!==t.visible&&(n.visible=t.visible),void 0!==t.flipSided&&(n.side=THREE.BackSide),void 0!==t.doubleSided&&(n.side=THREE.DoubleSide),void 0!==t.wireframe&&(n.wireframe=t.wireframe),void 0!==t.vertexColors&&("face"===t.vertexColors?n.vertexColors=THREE.FaceColors:t.vertexColors&&(n.vertexColors=THREE.VertexColors)),t.colorDiffuse?n.color=r(t.colorDiffuse):t.DbgColor&&(n.color=t.DbgColor),t.colorSpecular&&(n.specular=r(t.colorSpecular)),t.colorAmbient&&(n.ambient=r(t.colorAmbient)),t.colorEmissive&&(n.emissive=r(t.colorEmissive)),t.transparency&&(n.opacity=t.transparency),t.specularCoef&&(n.shininess=t.specularCoef),t.mapDiffuse&&c&&e(n,"map",t.mapDiffuse,t.mapDiffuseRepeat,t.mapDiffuseOffset,t.mapDiffuseWrap,t.mapDiffuseAnisotropy),t.mapLight&&c&&e(n,"lightMap",t.mapLight,t.mapLightRepeat,t.mapLightOffset,t.mapLightWrap,t.mapLightAnisotropy),t.mapBump&&c&&e(n,"bumpMap",t.mapBump,t.mapBumpRepeat,t.mapBumpOffset,t.mapBumpWrap,t.mapBumpAnisotropy),t.mapNormal&&c&&e(n,"normalMap",t.mapNormal,t.mapNormalRepeat,t.mapNormalOffset,t.mapNormalWrap,t.mapNormalAnisotropy),t.mapSpecular&&c&&e(n,"specularMap",t.mapSpecular,t.mapSpecularRepeat,t.mapSpecularOffset,t.mapSpecularWrap,t.mapSpecularAnisotropy),t.mapAlpha&&c&&e(n,"alphaMap",t.mapAlpha,t.mapAlphaRepeat,t.mapAlphaOffset,t.mapAlphaWrap,t.mapAlphaAnisotropy),t.mapBumpScale&&(n.bumpScale=t.mapBumpScale),t.mapNormal){var o=THREE.ShaderLib.normalmap,s=THREE.UniformsUtils.clone(o.uniforms);s.tNormal.value=n.normalMap,t.mapNormalFactor&&s.uNormalScale.value.set(t.mapNormalFactor,t.mapNormalFactor),n.map&&(s.tDiffuse.value=n.map,s.enableDiffuse.value=!0),n.specularMap&&(s.tSpecular.value=n.specularMap,s.enableSpecular.value=!0),n.lightMap&&(s.tAO.value=n.lightMap,s.enableAO.value=!0),s.diffuse.value.setHex(n.color),s.specular.value.setHex(n.specular),s.ambient.value.setHex(n.ambient),s.shininess.value=n.shininess,void 0!==n.opacity&&(s.opacity.value=n.opacity);var h={fragmentShader:o.fragmentShader,vertexShader:o.vertexShader,uniforms:s,lights:!0,fog:!0},l=new THREE.ShaderMaterial(h);n.transparent&&(l.transparent=!0)}else l=new THREE[i](n);return void 0!==t.DbgName&&(l.name=t.DbgName),l}},THREE.Loader.Handlers={handlers:[],add:function(t,e){this.handlers.push(t,e)},get:function(t){for(var e=0,r=this.handlers.length;e<r;e+=2){var i=this.handlers[e],n=this.handlers[e+1];if(i.test(t))return n}return null}},THREE.XHRLoader=function(t){this.cache=new THREE.Cache,this.manager=void 0!==t?t:THREE.DefaultLoadingManager},THREE.XHRLoader.prototype={constructor:THREE.XHRLoader,load:function(e,r,i,n){var a=this,t=a.cache.get(e);if(void 0===t){var o=new XMLHttpRequest;o.open("GET",e,!0),o.addEventListener("load",function(t){a.cache.add(e,this.response),r&&r(this.response),a.manager.itemEnd(e)},!1),void 0!==i&&o.addEventListener("progress",function(t){i(t)},!1),void 0!==n&&o.addEventListener("error",function(t){n(t)},!1),void 0!==this.crossOrigin&&(o.crossOrigin=this.crossOrigin),void 0!==this.responseType&&(o.responseType=this.responseType),o.send(null),a.manager.itemStart(e)}else r&&r(t)},setResponseType:function(t){this.responseType=t},setCrossOrigin:function(t){this.crossOrigin=t}},THREE.ImageLoader=function(t){this.cache=new THREE.Cache,this.manager=void 0!==t?t:THREE.DefaultLoadingManager},THREE.ImageLoader.prototype={constructor:THREE.ImageLoader,load:function(e,r,i,n){var a=this,t=a.cache.get(e);if(void 0===t){var o=document.createElement("img");return void 0!==r&&o.addEventListener("load",function(t){a.cache.add(e,this),r(this),a.manager.itemEnd(e)},!1),void 0!==i&&o.addEventListener("progress",function(t){i(t)},!1),void 0!==n&&o.addEventListener("error",function(t){n(t)},!1),void 0!==this.crossOrigin&&(o.crossOrigin=this.crossOrigin),o.src=e,a.manager.itemStart(e),o}r(t)},setCrossOrigin:function(t){this.crossOrigin=t}},THREE.LoadingManager=function(t,e,r){var i=this,n=0,a=0;this.onLoad=t,this.onProgress=e,this.onError=r,this.itemStart=function(t){a++},this.itemEnd=function(t){n++,void 0!==i.onProgress&&i.onProgress(t,n,a),n===a&&void 0!==i.onLoad&&i.onLoad()}},THREE.DefaultLoadingManager=new THREE.LoadingManager,THREE.TextureLoader=function(t){this.manager=void 0!==t?t:THREE.DefaultLoadingManager},THREE.TextureLoader.prototype={constructor:THREE.TextureLoader,load:function(t,r,e,i){var n=new THREE.ImageLoader(this.manager);n.setCrossOrigin(this.crossOrigin),n.load(t,function(t){var e=new THREE.Texture(t);e.needsUpdate=!0,void 0!==r&&r(e)},e,i)},setCrossOrigin:function(t){this.crossOrigin=t}},THREE.CompressedTextureLoader=function(){this._parser=null},THREE.CompressedTextureLoader.prototype={constructor:THREE.CompressedTextureLoader,load:function(t,a,e){var o=this,s=[],h=new THREE.CompressedTexture;h.image=s;var i=new THREE.XHRLoader;if(i.setResponseType("arraybuffer"),t instanceof Array)for(var n=0,r=function(r){i.load(t[r],function(t){var e=o._parser(t,!0);s[r]={width:e.width,height:e.height,format:e.format,mipmaps:e.mipmaps},6===(n+=1)&&(1==e.mipmapCount&&(h.minFilter=THREE.LinearFilter),h.format=e.format,h.needsUpdate=!0,a&&a(h))})},l=0,u=t.length;l<u;++l)r(l);else i.load(t,function(t){var e=o._parser(t,!0);if(e.isCubemap)for(var r=e.mipmaps.length/e.mipmapCount,i=0;i<r;i++){s[i]={mipmaps:[]};for(var n=0;n<e.mipmapCount;n++)s[i].mipmaps.push(e.mipmaps[i*e.mipmapCount+n]),s[i].format=e.format,s[i].width=e.width,s[i].height=e.height}else h.image.width=e.width,h.image.height=e.height,h.mipmaps=e.mipmaps;1===e.mipmapCount&&(h.minFilter=THREE.LinearFilter),h.format=e.format,h.needsUpdate=!0,a&&a(h)});return h}},THREE.Material=function(){Object.defineProperty(this,"id",{value:THREE.MaterialIdCount++}),this.uuid=THREE.Math.generateUUID(),this.name="",this.type="Material",this.side=THREE.FrontSide,this.opacity=1,this.transparent=!1,this.blending=THREE.NormalBlending,this.blendSrc=THREE.SrcAlphaFactor,this.blendDst=THREE.OneMinusSrcAlphaFactor,this.blendEquation=THREE.AddEquation,this.depthTest=!0,this.depthWrite=!0,this.polygonOffset=!1,this.polygonOffsetFactor=0,this.polygonOffsetUnits=0,this.alphaTest=0,this.overdraw=0,this.visible=!0,this.needsUpdate=!0},THREE.Material.prototype={constructor:THREE.Material,setValues:function(t){if(void 0!==t)for(var e in t){var r=t[e];if(void 0!==r){if(e in this){var i=this[e];i instanceof THREE.Color?i.set(r):i instanceof THREE.Vector3&&r instanceof THREE.Vector3?i.copy(r):this[e]="overdraw"==e?Number(r):r}}else console.warn("THREE.Material: '"+e+"' parameter is undefined.")}},toJSON:function(){var t={metadata:{version:4.2,type:"material",generator:"MaterialExporter"},uuid:this.uuid,type:this.type};return""!==this.name&&(t.name=this.name),this instanceof THREE.MeshBasicMaterial?(t.color=this.color.getHex(),this.vertexColors!==THREE.NoColors&&(t.vertexColors=this.vertexColors),this.blending!==THREE.NormalBlending&&(t.blending=this.blending),this.side!==THREE.FrontSide&&(t.side=this.side)):this instanceof THREE.MeshLambertMaterial?(t.color=this.color.getHex(),t.ambient=this.ambient.getHex(),t.emissive=this.emissive.getHex(),this.vertexColors!==THREE.NoColors&&(t.vertexColors=this.vertexColors),this.blending!==THREE.NormalBlending&&(t.blending=this.blending),this.side!==THREE.FrontSide&&(t.side=this.side)):this instanceof THREE.MeshPhongMaterial?(t.color=this.color.getHex(),t.ambient=this.ambient.getHex(),t.emissive=this.emissive.getHex(),t.specular=this.specular.getHex(),t.shininess=this.shininess,this.vertexColors!==THREE.NoColors&&(t.vertexColors=this.vertexColors),this.blending!==THREE.NormalBlending&&(t.blending=this.blending),this.side!==THREE.FrontSide&&(t.side=this.side)):this instanceof THREE.MeshNormalMaterial?(this.shading!==THREE.FlatShading&&(t.shading=this.shading),this.blending!==THREE.NormalBlending&&(t.blending=this.blending),this.side!==THREE.FrontSide&&(t.side=this.side)):this instanceof THREE.MeshDepthMaterial?(this.blending!==THREE.NormalBlending&&(t.blending=this.blending),this.side!==THREE.FrontSide&&(t.side=this.side)):this instanceof THREE.ShaderMaterial?(t.uniforms=this.uniforms,t.vertexShader=this.vertexShader,t.fragmentShader=this.fragmentShader):this instanceof THREE.SpriteMaterial&&(t.color=this.color.getHex()),this.opacity<1&&(t.opacity=this.opacity),!1!==this.transparent&&(t.transparent=this.transparent),!1!==this.wireframe&&(t.wireframe=this.wireframe),t},clone:function(t){return void 0===t&&(t=new THREE.Material),t.name=this.name,t.side=this.side,t.opacity=this.opacity,t.transparent=this.transparent,t.blending=this.blending,t.blendSrc=this.blendSrc,t.blendDst=this.blendDst,t.blendEquation=this.blendEquation,t.depthTest=this.depthTest,t.depthWrite=this.depthWrite,t.polygonOffset=this.polygonOffset,t.polygonOffsetFactor=this.polygonOffsetFactor,t.polygonOffsetUnits=this.polygonOffsetUnits,t.alphaTest=this.alphaTest,t.overdraw=this.overdraw,t.visible=this.visible,t},dispose:function(){this.dispatchEvent({type:"dispose"})}},THREE.EventDispatcher.prototype.apply(THREE.Material.prototype),THREE.MaterialIdCount=0,THREE.LineBasicMaterial=function(t){THREE.Material.call(this),this.type="LineBasicMaterial",this.color=new THREE.Color(16777215),this.linewidth=1,this.linecap="round",this.linejoin="round",this.vertexColors=THREE.NoColors,this.fog=!0,this.setValues(t)},THREE.LineBasicMaterial.prototype=Object.create(THREE.Material.prototype),THREE.LineBasicMaterial.prototype.clone=function(){var t=new THREE.LineBasicMaterial;return THREE.Material.prototype.clone.call(this,t),t.color.copy(this.color),t.linewidth=this.linewidth,t.linecap=this.linecap,t.linejoin=this.linejoin,t.vertexColors=this.vertexColors,t.fog=this.fog,t},THREE.LineDashedMaterial=function(t){THREE.Material.call(this),this.type="LineDashedMaterial",this.color=new THREE.Color(16777215),this.linewidth=1,this.scale=1,this.dashSize=3,this.gapSize=1,this.vertexColors=!1,this.fog=!0,this.setValues(t)},THREE.LineDashedMaterial.prototype=Object.create(THREE.Material.prototype),THREE.LineDashedMaterial.prototype.clone=function(){var t=new THREE.LineDashedMaterial;return THREE.Material.prototype.clone.call(this,t),t.color.copy(this.color),t.linewidth=this.linewidth,t.scale=this.scale,t.dashSize=this.dashSize,t.gapSize=this.gapSize,t.vertexColors=this.vertexColors,t.fog=this.fog,t},THREE.MeshBasicMaterial=function(t){THREE.Material.call(this),this.type="MeshBasicMaterial",this.color=new THREE.Color(16777215),this.map=null,this.lightMap=null,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.combine=THREE.MultiplyOperation,this.reflectivity=1,this.refractionRatio=.98,this.fog=!0,this.shading=THREE.SmoothShading,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.vertexColors=THREE.NoColors,this.skinning=!1,this.morphTargets=!1,this.setValues(t)},THREE.MeshBasicMaterial.prototype=Object.create(THREE.Material.prototype),THREE.MeshBasicMaterial.prototype.clone=function(){var t=new THREE.MeshBasicMaterial;return THREE.Material.prototype.clone.call(this,t),t.color.copy(this.color),t.map=this.map,t.lightMap=this.lightMap,t.specularMap=this.specularMap,t.alphaMap=this.alphaMap,t.envMap=this.envMap,t.combine=this.combine,t.reflectivity=this.reflectivity,t.refractionRatio=this.refractionRatio,t.fog=this.fog,t.shading=this.shading,t.wireframe=this.wireframe,t.wireframeLinewidth=this.wireframeLinewidth,t.wireframeLinecap=this.wireframeLinecap,t.wireframeLinejoin=this.wireframeLinejoin,t.vertexColors=this.vertexColors,t.skinning=this.skinning,t.morphTargets=this.morphTargets,t},THREE.MeshLambertMaterial=function(t){THREE.Material.call(this),this.type="MeshLambertMaterial",this.color=new THREE.Color(16777215),this.ambient=new THREE.Color(16777215),this.emissive=new THREE.Color(0),this.wrapAround=!1,this.wrapRGB=new THREE.Vector3(1,1,1),this.map=null,this.lightMap=null,this.specularMap=null,this.alphaMap=null,this.envMap=null,this.combine=THREE.MultiplyOperation,this.reflectivity=1,this.refractionRatio=.98,this.fog=!0,this.shading=THREE.SmoothShading,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.vertexColors=THREE.NoColors,this.skinning=!1,this.morphTargets=!1,this.morphNormals=!1,this.setValues(t)},THREE.MeshLambertMaterial.prototype=Object.create(THREE.Material.prototype),THREE.MeshLambertMaterial.prototype.clone=function(){var t=new THREE.MeshLambertMaterial;return THREE.Material.prototype.clone.call(this,t),t.color.copy(this.color),t.ambient.copy(this.ambient),t.emissive.copy(this.emissive),t.wrapAround=this.wrapAround,t.wrapRGB.copy(this.wrapRGB),t.map=this.map,t.lightMap=this.lightMap,t.specularMap=this.specularMap,t.alphaMap=this.alphaMap,t.envMap=this.envMap,t.combine=this.combine,t.reflectivity=this.reflectivity,t.refractionRatio=this.refractionRatio,t.fog=this.fog,t.shading=this.shading,t.wireframe=this.wireframe,t.wireframeLinewidth=this.wireframeLinewidth,t.wireframeLinecap=this.wireframeLinecap,t.wireframeLinejoin=this.wireframeLinejoin,t.vertexColors=this.vertexColors,t.skinning=this.skinning,t.morphTargets=this.morphTargets,t.morphNormals=this.morphNormals,t},THREE.MeshPhongMaterial=function(t){THREE.Material.call(this),this.type="MeshPhongMaterial",this.color=new THREE.Color(16777215),this.ambient=new THREE.Color(16777215),this.emissive=new THREE.Color(0),this.specular=new THREE.Color(1118481),this.shininess=30,this.metal=!1,this.wrapAround=!1,this.wrapRGB=new THREE.Vector3(1,1,1),this.map=null,this.lightMap=null,this.bumpMap=null,this.bumpScale=1,this.normalMap=null,this.normalScale=new THREE.Vector2(1,1),this.specularMap=null,this.alphaMap=null,this.envMap=null,this.combine=THREE.MultiplyOperation,this.reflectivity=1,this.refractionRatio=.98,this.fog=!0,this.shading=THREE.SmoothShading,this.wireframe=!1,this.wireframeLinewidth=1,this.wireframeLinecap="round",this.wireframeLinejoin="round",this.vertexColors=THREE.NoColors,this.skinning=!1,this.morphTargets=!1,this.morphNormals=!1,this.setValues(t)},THREE.MeshPhongMaterial.prototype=Object.create(THREE.Material.prototype),THREE.MeshPhongMaterial.prototype.clone=function(){var t=new THREE.MeshPhongMaterial;return THREE.Material.prototype.clone.call(this,t),t.color.copy(this.color),t.ambient.copy(this.ambient),t.emissive.copy(this.emissive),t.specular.copy(this.specular),t.shininess=this.shininess,t.metal=this.metal,t.wrapAround=this.wrapAround,t.wrapRGB.copy(this.wrapRGB),t.map=this.map,t.lightMap=this.lightMap,t.bumpMap=this.bumpMap,t.bumpScale=this.bumpScale,t.normalMap=this.normalMap,t.normalScale.copy(this.normalScale),t.specularMap=this.specularMap,t.alphaMap=this.alphaMap,t.envMap=this.envMap,t.combine=this.combine,t.reflectivity=this.reflectivity,t.refractionRatio=this.refractionRatio,t.fog=this.fog,t.shading=this.shading,t.wireframe=this.wireframe,t.wireframeLinewidth=this.wireframeLinewidth,t.wireframeLinecap=this.wireframeLinecap,t.wireframeLinejoin=this.wireframeLinejoin,t.vertexColors=this.vertexColors,t.skinning=this.skinning,t.morphTargets=this.morphTargets,t.morphNormals=this.morphNormals,t},THREE.MeshDepthMaterial=function(t){THREE.Material.call(this),this.type="MeshDepthMaterial",this.morphTargets=!1,this.wireframe=!1,this.wireframeLinewidth=1,this.setValues(t)},THREE.MeshDepthMaterial.prototype=Object.create(THREE.Material.prototype),THREE.MeshDepthMaterial.prototype.clone=function(){var t=new THREE.MeshDepthMaterial;return THREE.Material.prototype.clone.call(this,t),t.wireframe=this.wireframe,t.wireframeLinewidth=this.wireframeLinewidth,t},THREE.MeshNormalMaterial=function(t){THREE.Material.call(this,t),this.type="MeshNormalMaterial",this.shading=THREE.FlatShading,this.wireframe=!1,this.wireframeLinewidth=1,this.morphTargets=!1,this.setValues(t)},THREE.MeshNormalMaterial.prototype=Object.create(THREE.Material.prototype),THREE.MeshNormalMaterial.prototype.clone=function(){var t=new THREE.MeshNormalMaterial;return THREE.Material.prototype.clone.call(this,t),t.shading=this.shading,t.wireframe=this.wireframe,t.wireframeLinewidth=this.wireframeLinewidth,t},THREE.MeshFaceMaterial=function(t){this.uuid=THREE.Math.generateUUID(),this.type="MeshFaceMaterial",this.materials=t instanceof Array?t:[]},THREE.MeshFaceMaterial.prototype={constructor:THREE.MeshFaceMaterial,toJSON:function(){for(var t={metadata:{version:4.2,type:"material",generator:"MaterialExporter"},uuid:this.uuid,type:this.type,materials:[]},e=0,r=this.materials.length;e<r;e++)t.materials.push(this.materials[e].toJSON());return t},clone:function(){for(var t=new THREE.MeshFaceMaterial,e=0;e<this.materials.length;e++)t.materials.push(this.materials[e].clone());return t}},THREE.PointCloudMaterial=function(t){THREE.Material.call(this),this.type="PointCloudMaterial",this.color=new THREE.Color(16777215),this.map=null,this.size=1,this.sizeAttenuation=!0,this.vertexColors=THREE.NoColors,this.fog=!0,this.setValues(t)},THREE.PointCloudMaterial.prototype=Object.create(THREE.Material.prototype),THREE.PointCloudMaterial.prototype.clone=function(){var t=new THREE.PointCloudMaterial;return THREE.Material.prototype.clone.call(this,t),t.color.copy(this.color),t.map=this.map,t.size=this.size,t.sizeAttenuation=this.sizeAttenuation,t.vertexColors=this.vertexColors,t.fog=this.fog,t},THREE.ParticleBasicMaterial=function(t){return console.warn("THREE.ParticleBasicMaterial has been renamed to THREE.PointCloudMaterial."),new THREE.PointCloudMaterial(t)},THREE.ParticleSystemMaterial=function(t){return console.warn("THREE.ParticleSystemMaterial has been renamed to THREE.PointCloudMaterial."),new THREE.PointCloudMaterial(t)},THREE.ShaderMaterial=function(t){THREE.Material.call(this),this.type="ShaderMaterial",this.defines={},this.uniforms={},this.attributes=null,this.vertexShader="void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}",this.fragmentShader="void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}",this.shading=THREE.SmoothShading,this.linewidth=1,this.wireframe=!1,this.wireframeLinewidth=1,this.fog=!1,this.lights=!1,this.vertexColors=THREE.NoColors,this.skinning=!1,this.morphTargets=!1,this.morphNormals=!1,this.defaultAttributeValues={color:[1,1,1],uv:[0,0],uv2:[0,0]},this.index0AttributeName=void 0,this.setValues(t)},THREE.ShaderMaterial.prototype=Object.create(THREE.Material.prototype),THREE.ShaderMaterial.prototype.clone=function(){var t=new THREE.ShaderMaterial;return THREE.Material.prototype.clone.call(this,t),t.fragmentShader=this.fragmentShader,t.vertexShader=this.vertexShader,t.uniforms=THREE.UniformsUtils.clone(this.uniforms),t.attributes=this.attributes,t.defines=this.defines,t.shading=this.shading,t.wireframe=this.wireframe,t.wireframeLinewidth=this.wireframeLinewidth,t.fog=this.fog,t.lights=this.lights,t.vertexColors=this.vertexColors,t.skinning=this.skinning,t.morphTargets=this.morphTargets,t.morphNormals=this.morphNormals,t},THREE.RawShaderMaterial=function(t){THREE.ShaderMaterial.call(this,t),this.type="RawShaderMaterial"},THREE.RawShaderMaterial.prototype=Object.create(THREE.ShaderMaterial.prototype),THREE.RawShaderMaterial.prototype.clone=function(){var t=new THREE.RawShaderMaterial;return THREE.ShaderMaterial.prototype.clone.call(this,t),t},THREE.SpriteMaterial=function(t){THREE.Material.call(this),this.type="SpriteMaterial",this.color=new THREE.Color(16777215),this.map=null,this.rotation=0,this.fog=!1,this.setValues(t)},THREE.SpriteMaterial.prototype=Object.create(THREE.Material.prototype),THREE.SpriteMaterial.prototype.clone=function(){var t=new THREE.SpriteMaterial;return THREE.Material.prototype.clone.call(this,t),t.color.copy(this.color),t.map=this.map,t.rotation=this.rotation,t.fog=this.fog,t},THREE.Texture=function(t,e,r,i,n,a,o,s,h){Object.defineProperty(this,"id",{value:THREE.TextureIdCount++}),this.uuid=THREE.Math.generateUUID(),this.name="",this.image=void 0!==t?t:THREE.Texture.DEFAULT_IMAGE,this.mipmaps=[],this.mapping=void 0!==e?e:THREE.Texture.DEFAULT_MAPPING,this.wrapS=void 0!==r?r:THREE.ClampToEdgeWrapping,this.wrapT=void 0!==i?i:THREE.ClampToEdgeWrapping,this.magFilter=void 0!==n?n:THREE.LinearFilter,this.minFilter=void 0!==a?a:THREE.LinearMipMapLinearFilter,this.anisotropy=void 0!==h?h:1,this.format=void 0!==o?o:THREE.RGBAFormat,this.type=void 0!==s?s:THREE.UnsignedByteType,this.offset=new THREE.Vector2(0,0),this.repeat=new THREE.Vector2(1,1),this.generateMipmaps=!0,this.premultiplyAlpha=!1,this.flipY=!0,this.unpackAlignment=4,this._needsUpdate=!1,this.onUpdate=null},THREE.Texture.DEFAULT_IMAGE=void 0,THREE.Texture.DEFAULT_MAPPING=new THREE.UVMapping,THREE.Texture.prototype={constructor:THREE.Texture,get needsUpdate(){return this._needsUpdate},set needsUpdate(t){!0===t&&this.update(),this._needsUpdate=t},clone:function(t){return void 0===t&&(t=new THREE.Texture),t.image=this.image,t.mipmaps=this.mipmaps.slice(0),t.mapping=this.mapping,t.wrapS=this.wrapS,t.wrapT=this.wrapT,t.magFilter=this.magFilter,t.minFilter=this.minFilter,t.anisotropy=this.anisotropy,t.format=this.format,t.type=this.type,t.offset.copy(this.offset),t.repeat.copy(this.repeat),t.generateMipmaps=this.generateMipmaps,t.premultiplyAlpha=this.premultiplyAlpha,t.flipY=this.flipY,t.unpackAlignment=this.unpackAlignment,t},update:function(){this.dispatchEvent({type:"update"})},dispose:function(){this.dispatchEvent({type:"dispose"})}},THREE.EventDispatcher.prototype.apply(THREE.Texture.prototype),THREE.TextureIdCount=0,THREE.CubeTexture=function(t,e,r,i,n,a,o,s,h){THREE.Texture.call(this,t,e,r,i,n,a,o,s,h),this.images=t},THREE.CubeTexture.prototype=Object.create(THREE.Texture.prototype),THREE.CubeTexture.clone=function(t){return void 0===t&&(t=new THREE.CubeTexture),THREE.Texture.prototype.clone.call(this,t),t.images=this.images,t},THREE.CompressedTexture=function(t,e,r,i,n,a,o,s,h,l,u){THREE.Texture.call(this,null,a,o,s,h,l,i,n,u),this.image={width:e,height:r},this.mipmaps=t,this.flipY=!1,this.generateMipmaps=!1},THREE.CompressedTexture.prototype=Object.create(THREE.Texture.prototype),THREE.CompressedTexture.prototype.clone=function(){var t=new THREE.CompressedTexture;return THREE.Texture.prototype.clone.call(this,t),t},THREE.DataTexture=function(t,e,r,i,n,a,o,s,h,l,u){THREE.Texture.call(this,null,a,o,s,h,l,i,n,u),this.image={data:t,width:e,height:r}},THREE.DataTexture.prototype=Object.create(THREE.Texture.prototype),THREE.DataTexture.prototype.clone=function(){var t=new THREE.DataTexture;return THREE.Texture.prototype.clone.call(this,t),t},THREE.VideoTexture=function(t,e,r,i,n,a,o,s,h){THREE.Texture.call(this,t,e,r,i,n,a,o,s,h),this.generateMipmaps=!1;var l=this,u=function(){requestAnimationFrame(u),t.readyState===t.HAVE_ENOUGH_DATA&&(l.needsUpdate=!0)};u()},THREE.VideoTexture.prototype=Object.create(THREE.Texture.prototype),THREE.Group=function(){THREE.Object3D.call(this),this.type="Group"},THREE.Group.prototype=Object.create(THREE.Object3D.prototype),THREE.PointCloud=function(t,e){THREE.Object3D.call(this),this.type="PointCloud",this.geometry=void 0!==t?t:new THREE.Geometry,this.material=void 0!==e?e:new THREE.PointCloudMaterial({color:16777215*Math.random()}),this.sortParticles=!1},THREE.PointCloud.prototype=Object.create(THREE.Object3D.prototype),THREE.PointCloud.prototype.raycast=function(){var R=new THREE.Matrix4,_=new THREE.Ray;return function(a,o){var s=this,t=s.geometry,e=a.params.PointCloud.threshold;if(R.getInverse(this.matrixWorld),_.copy(a.ray).applyMatrix4(R),null===t.boundingBox||!1!==_.isIntersectionBox(t.boundingBox)){var h=e/((this.scale.x+this.scale.y+this.scale.z)/3),r=new THREE.Vector3,i=function(t,e){var r=_.distanceToPoint(t);if(r<h){var i=_.closestPointToPoint(t);i.applyMatrix4(s.matrixWorld);var n=a.ray.origin.distanceTo(i);o.push({distance:n,distanceToRay:r,point:i.clone(),index:e,face:null,object:s})}};if(t instanceof THREE.BufferGeometry){var n=t.attributes,l=n.position.array;if(void 0!==n.index){var u=n.index.array,c=t.offsets;if(0===c.length)c=[{start:0,count:u.length,index:0}];for(var f=0,d=c.length;f<d;++f)for(var p=c[f].start,E=c[f].count,m=c[f].index,g=p,v=p+E;g<v;g++){var T=m+u[g];r.fromArray(l,3*T),i(r,T)}}else{var x=l.length/3;for(g=0;g<x;g++)r.set(l[3*g],l[3*g+1],l[3*g+2]),i(r,g)}}else{var y=this.geometry.vertices;for(g=0;g<y.length;g++)i(y[g],g)}}}}(),THREE.PointCloud.prototype.clone=function(t){return void 0===t&&(t=new THREE.PointCloud(this.geometry,this.material)),t.sortParticles=this.sortParticles,THREE.Object3D.prototype.clone.call(this,t),t},THREE.ParticleSystem=function(t,e){return console.warn("THREE.ParticleSystem has been renamed to THREE.PointCloud."),new THREE.PointCloud(t,e)},THREE.Line=function(t,e,r){THREE.Object3D.call(this),this.type="Line",this.geometry=void 0!==t?t:new THREE.Geometry,this.material=void 0!==e?e:new THREE.LineBasicMaterial({color:16777215*Math.random()}),this.mode=void 0!==r?r:THREE.LineStrip},THREE.LineStrip=0,THREE.LinePieces=1,THREE.Line.prototype=Object.create(THREE.Object3D.prototype),THREE.Line.prototype.raycast=function(){var f=new THREE.Matrix4,d=new THREE.Ray,p=new THREE.Sphere;return function(t,e){var r=t.linePrecision,i=r*r,n=this.geometry;if(null===n.boundingSphere&&n.computeBoundingSphere(),p.copy(n.boundingSphere),p.applyMatrix4(this.matrixWorld),!1!==t.ray.isIntersectionSphere(p)&&(f.getInverse(this.matrixWorld),d.copy(t.ray).applyMatrix4(f),n instanceof THREE.Geometry))for(var a=n.vertices,o=a.length,s=new THREE.Vector3,h=new THREE.Vector3,l=this.mode===THREE.LineStrip?1:2,u=0;u<o-1;u+=l){if(!(i<d.distanceSqToSegment(a[u],a[u+1],h,s))){var c=d.origin.distanceTo(h);c<t.near||c>t.far||e.push({distance:c,point:s.clone().applyMatrix4(this.matrixWorld),face:null,faceIndex:null,object:this})}}}}(),THREE.Line.prototype.clone=function(t){return void 0===t&&(t=new THREE.Line(this.geometry,this.material,this.mode)),THREE.Object3D.prototype.clone.call(this,t),t},THREE.Mesh=function(t,e){THREE.Object3D.call(this),this.type="Mesh",this.geometry=void 0!==t?t:new THREE.Geometry,this.material=void 0!==e?e:new THREE.MeshBasicMaterial({color:16777215*Math.random()}),this.updateMorphTargets()},THREE.Mesh.prototype=Object.create(THREE.Object3D.prototype),THREE.Mesh.prototype.updateMorphTargets=function(){if(void 0!==this.geometry.morphTargets&&0<this.geometry.morphTargets.length){this.morphTargetBase=-1,this.morphTargetForcedOrder=[],this.morphTargetInfluences=[],this.morphTargetDictionary={};for(var t=0,e=this.geometry.morphTargets.length;t<e;t++)this.morphTargetInfluences.push(0),this.morphTargetDictionary[this.geometry.morphTargets[t].name]=t}},THREE.Mesh.prototype.getMorphTargetIndexByName=function(t){return void 0!==this.morphTargetDictionary[t]?this.morphTargetDictionary[t]:(console.log("THREE.Mesh.getMorphTargetIndexByName: morph target "+t+" does not exist. Returning 0."),0)},THREE.Mesh.prototype.raycast=function(){var P=new THREE.Matrix4,U=new THREE.Ray,B=new THREE.Sphere,z=new THREE.Vector3,N=new THREE.Vector3,k=new THREE.Vector3;return function(t,e){var r=this.geometry;if(null===r.boundingSphere&&r.computeBoundingSphere(),B.copy(r.boundingSphere),B.applyMatrix4(this.matrixWorld),!1!==t.ray.isIntersectionSphere(B)&&(P.getInverse(this.matrixWorld),U.copy(t.ray).applyMatrix4(P),null===r.boundingBox||!1!==U.isIntersectionBox(r.boundingBox)))if(r instanceof THREE.BufferGeometry){if(void 0===(b=this.material))return;var i=r.attributes,n=t.precision;if(void 0!==i.index){var a=i.index.array,o=i.position.array,s=r.offsets;0===s.length&&(s=[{start:0,count:a.length,index:0}]);for(var h=0,l=s.length;h<l;++h)for(var u=s[h].start,c=s[h].count,f=s[h].index,d=u,p=u+c;d<p;d+=3){if(g=f+a[d],v=f+a[d+1],T=f+a[d+2],z.fromArray(o,3*g),N.fromArray(o,3*v),k.fromArray(o,3*T),b.side===THREE.BackSide)var E=U.intersectTriangle(k,N,z,!0);else E=U.intersectTriangle(z,N,k,b.side!==THREE.DoubleSide);if(null!==E)E.applyMatrix4(this.matrixWorld),(F=t.ray.origin.distanceTo(E))<n||F<t.near||F>t.far||e.push({distance:F,point:E,face:new THREE.Face3(g,v,T,THREE.Triangle.normal(z,N,k)),faceIndex:null,object:this})}}else{d=0;var m=0;for(p=(o=i.position.array).length;d<p;d+=3,m+=9){if(v=(g=d)+1,T=d+2,z.fromArray(o,m),N.fromArray(o,m+3),k.fromArray(o,m+6),b.side===THREE.BackSide)E=U.intersectTriangle(k,N,z,!0);else E=U.intersectTriangle(z,N,k,b.side!==THREE.DoubleSide);if(null!==E)E.applyMatrix4(this.matrixWorld),(F=t.ray.origin.distanceTo(E))<n||F<t.near||F>t.far||e.push({distance:F,point:E,face:new THREE.Face3(g,v,T,THREE.Triangle.normal(z,N,k)),faceIndex:null,object:this})}}}else if(r instanceof THREE.Geometry)for(var g,v,T,x=this.material instanceof THREE.MeshFaceMaterial,y=!0===x?this.material.materials:null,R=(n=t.precision,r.vertices),_=0,H=r.faces.length;_<H;_++){var b,M=r.faces[_];if(void 0!==(b=!0===x?y[M.materialIndex]:this.material)){if(g=R[M.a],v=R[M.b],T=R[M.c],!0===b.morphTargets){var w=r.morphTargets,S=this.morphTargetInfluences;z.set(0,0,0),N.set(0,0,0),k.set(0,0,0);for(var A=0,C=w.length;A<C;A++){var D=S[A];if(0!==D){var L=w[A].vertices;z.x+=(L[M.a].x-g.x)*D,z.y+=(L[M.a].y-g.y)*D,z.z+=(L[M.a].z-g.z)*D,N.x+=(L[M.b].x-v.x)*D,N.y+=(L[M.b].y-v.y)*D,N.z+=(L[M.b].z-v.z)*D,k.x+=(L[M.c].x-T.x)*D,k.y+=(L[M.c].y-T.y)*D,k.z+=(L[M.c].z-T.z)*D}}z.add(g),N.add(v),k.add(T),g=z,v=N,T=k}if(b.side===THREE.BackSide)E=U.intersectTriangle(T,v,g,!0);else E=U.intersectTriangle(g,v,T,b.side!==THREE.DoubleSide);var F;if(null!==E)E.applyMatrix4(this.matrixWorld),(F=t.ray.origin.distanceTo(E))<n||F<t.near||F>t.far||e.push({distance:F,point:E,face:M,faceIndex:_,object:this})}}}}(),THREE.Mesh.prototype.clone=function(t,e){return void 0===t&&(t=new THREE.Mesh(this.geometry,this.material)),THREE.Object3D.prototype.clone.call(this,t,e),t},THREE.Bone=function(t){THREE.Object3D.call(this),this.skin=t},THREE.Bone.prototype=Object.create(THREE.Object3D.prototype),THREE.Skeleton=function(t,e,r){var i;(this.useVertexTexture=void 0===r||r,this.identityMatrix=new THREE.Matrix4,t=t||[],this.bones=t.slice(0),this.useVertexTexture)?(i=256<this.bones.length?64:64<this.bones.length?32:16<this.bones.length?16:8,this.boneTextureWidth=i,this.boneTextureHeight=i,this.boneMatrices=new Float32Array(this.boneTextureWidth*this.boneTextureHeight*4),this.boneTexture=new THREE.DataTexture(this.boneMatrices,this.boneTextureWidth,this.boneTextureHeight,THREE.RGBAFormat,THREE.FloatType),this.boneTexture.minFilter=THREE.NearestFilter,this.boneTexture.magFilter=THREE.NearestFilter,this.boneTexture.generateMipmaps=!1,this.boneTexture.flipY=!1):this.boneMatrices=new Float32Array(16*this.bones.length);if(void 0===e)this.calculateInverses();else if(this.bones.length===e.length)this.boneInverses=e.slice(0);else{console.warn("THREE.Skeleton bonInverses is the wrong length."),this.boneInverses=[];for(var n=0,a=this.bones.length;n<a;n++)this.boneInverses.push(new THREE.Matrix4)}},THREE.Skeleton.prototype.calculateInverses=function(){this.boneInverses=[];for(var t=0,e=this.bones.length;t<e;t++){var r=new THREE.Matrix4;this.bones[t]&&r.getInverse(this.bones[t].matrixWorld),this.boneInverses.push(r)}},THREE.Skeleton.prototype.pose=function(){for(var t,e=0,r=this.bones.length;e<r;e++)(t=this.bones[e])&&t.matrixWorld.getInverse(this.boneInverses[e]);for(e=0,r=this.bones.length;e<r;e++)(t=this.bones[e])&&(t.parent?(t.matrix.getInverse(t.parent.matrixWorld),t.matrix.multiply(t.matrixWorld)):t.matrix.copy(t.matrixWorld),t.matrix.decompose(t.position,t.quaternion,t.scale))},THREE.Skeleton.prototype.update=function(){var i=new THREE.Matrix4;return function(){for(var t=0,e=this.bones.length;t<e;t++){var r=this.bones[t]?this.bones[t].matrixWorld:this.identityMatrix;i.multiplyMatrices(r,this.boneInverses[t]),i.flattenToArrayOffset(this.boneMatrices,16*t)}this.useVertexTexture&&(this.boneTexture.needsUpdate=!0)}}(),THREE.SkinnedMesh=function(t,e,r){THREE.Mesh.call(this,t,e),this.type="SkinnedMesh",this.bindMode="attached",this.bindMatrix=new THREE.Matrix4,this.bindMatrixInverse=new THREE.Matrix4;var i=[];if(this.geometry&&void 0!==this.geometry.bones){for(var n,a,o,s,h,l=0,u=this.geometry.bones.length;l<u;++l)o=(a=this.geometry.bones[l]).pos,s=a.rotq,h=a.scl,n=new THREE.Bone(this),i.push(n),n.name=a.name,n.position.set(o[0],o[1],o[2]),n.quaternion.set(s[0],s[1],s[2],s[3]),void 0!==h?n.scale.set(h[0],h[1],h[2]):n.scale.set(1,1,1);for(l=0,u=this.geometry.bones.length;l<u;++l)-1!==(a=this.geometry.bones[l]).parent?i[a.parent].add(i[l]):this.add(i[l])}this.normalizeSkinWeights(),this.updateMatrixWorld(!0),this.bind(new THREE.Skeleton(i,void 0,r))},THREE.SkinnedMesh.prototype=Object.create(THREE.Mesh.prototype),THREE.SkinnedMesh.prototype.bind=function(t,e){this.skeleton=t,void 0===e&&(this.updateMatrixWorld(!0),e=this.matrixWorld),this.bindMatrix.copy(e),this.bindMatrixInverse.getInverse(e)},THREE.SkinnedMesh.prototype.pose=function(){this.skeleton.pose()},THREE.SkinnedMesh.prototype.normalizeSkinWeights=function(){if(this.geometry instanceof THREE.Geometry)for(var t=0;t<this.geometry.skinIndices.length;t++){var e=this.geometry.skinWeights[t],r=1/e.lengthManhattan();r!==1/0?e.multiplyScalar(r):e.set(1)}},THREE.SkinnedMesh.prototype.updateMatrixWorld=function(t){THREE.Mesh.prototype.updateMatrixWorld.call(this,!0),"attached"===this.bindMode?this.bindMatrixInverse.getInverse(this.matrixWorld):"detached"===this.bindMode?this.bindMatrixInverse.getInverse(this.bindMatrix):console.warn("THREE.SkinnedMesh unreckognized bindMode: "+this.bindMode)},THREE.SkinnedMesh.prototype.clone=function(t){return void 0===t&&(t=new THREE.SkinnedMesh(this.geometry,this.material,this.useVertexTexture)),THREE.Mesh.prototype.clone.call(this,t),t},THREE.MorphAnimMesh=function(t,e){THREE.Mesh.call(this,t,e),this.type="MorphAnimMesh",this.duration=1e3,this.mirroredLoop=!1,this.time=0,this.lastKeyframe=0,this.currentKeyframe=0,this.direction=1,this.directionBackwards=!1,this.setFrameRange(0,this.geometry.morphTargets.length-1)},THREE.MorphAnimMesh.prototype=Object.create(THREE.Mesh.prototype),THREE.MorphAnimMesh.prototype.setFrameRange=function(t,e){this.startKeyframe=t,this.endKeyframe=e,this.length=this.endKeyframe-this.startKeyframe+1},THREE.MorphAnimMesh.prototype.setDirectionForward=function(){this.direction=1,this.directionBackwards=!1},THREE.MorphAnimMesh.prototype.setDirectionBackward=function(){this.direction=-1,this.directionBackwards=!0},THREE.MorphAnimMesh.prototype.parseAnimations=function(){var t=this.geometry;t.animations||(t.animations={});for(var e,r=t.animations,i=/([a-z]+)_?(\d+)/,n=0,a=t.morphTargets.length;n<a;n++){var o=t.morphTargets[n].name.match(i);if(o&&1<o.length){var s=o[1];o[2];r[s]||(r[s]={start:1/0,end:-1/0});var h=r[s];n<h.start&&(h.start=n),n>h.end&&(h.end=n),e||(e=s)}}t.firstAnimation=e},THREE.MorphAnimMesh.prototype.setAnimationLabel=function(t,e,r){this.geometry.animations||(this.geometry.animations={}),this.geometry.animations[t]={start:e,end:r}},THREE.MorphAnimMesh.prototype.playAnimation=function(t,e){var r=this.geometry.animations[t];r?(this.setFrameRange(r.start,r.end),this.duration=(r.end-r.start)/e*1e3,this.time=0):console.warn("animation["+t+"] undefined")},THREE.MorphAnimMesh.prototype.updateAnimation=function(t){var e=this.duration/this.length;this.time+=this.direction*t,this.mirroredLoop?(this.time>this.duration||this.time<0)&&(this.direction*=-1,this.time>this.duration&&(this.time=this.duration,this.directionBackwards=!0),this.time<0&&(this.time=0,this.directionBackwards=!1)):(this.time=this.time%this.duration,this.time<0&&(this.time+=this.duration));var r=this.startKeyframe+THREE.Math.clamp(Math.floor(this.time/e),0,this.length-1);r!==this.currentKeyframe&&(this.morphTargetInfluences[this.lastKeyframe]=0,this.morphTargetInfluences[this.currentKeyframe]=1,this.morphTargetInfluences[r]=0,this.lastKeyframe=this.currentKeyframe,this.currentKeyframe=r);var i=this.time%e/e;this.directionBackwards&&(i=1-i),this.morphTargetInfluences[this.currentKeyframe]=i,this.morphTargetInfluences[this.lastKeyframe]=1-i},THREE.MorphAnimMesh.prototype.interpolateTargets=function(t,e,r){for(var i=this.morphTargetInfluences,n=0,a=i.length;n<a;n++)i[n]=0;-1<t&&(i[t]=1-r),-1<e&&(i[e]=r)},THREE.MorphAnimMesh.prototype.clone=function(t){return void 0===t&&(t=new THREE.MorphAnimMesh(this.geometry,this.material)),t.duration=this.duration,t.mirroredLoop=this.mirroredLoop,t.time=this.time,t.lastKeyframe=this.lastKeyframe,t.currentKeyframe=this.currentKeyframe,t.direction=this.direction,t.directionBackwards=this.directionBackwards,THREE.Mesh.prototype.clone.call(this,t),t},THREE.LOD=function(){THREE.Object3D.call(this),this.objects=[]},THREE.LOD.prototype=Object.create(THREE.Object3D.prototype),THREE.LOD.prototype.addLevel=function(t,e){void 0===e&&(e=0),e=Math.abs(e);for(var r=0;r<this.objects.length&&!(e<this.objects[r].distance);r++);this.objects.splice(r,0,{distance:e,object:t}),this.add(t)},THREE.LOD.prototype.getObjectForDistance=function(t){for(var e=1,r=this.objects.length;e<r&&!(t<this.objects[e].distance);e++);return this.objects[e-1].object},THREE.LOD.prototype.raycast=function(){var i=new THREE.Vector3;return function(t,e){i.setFromMatrixPosition(this.matrixWorld);var r=t.ray.origin.distanceTo(i);this.getObjectForDistance(r).raycast(t,e)}}(),THREE.LOD.prototype.update=function(){var n=new THREE.Vector3,a=new THREE.Vector3;return function(t){if(1<this.objects.length){n.setFromMatrixPosition(t.matrixWorld),a.setFromMatrixPosition(this.matrixWorld);var e=n.distanceTo(a);this.objects[0].object.visible=!0;for(var r=1,i=this.objects.length;r<i&&e>=this.objects[r].distance;r++)this.objects[r-1].object.visible=!1,this.objects[r].object.visible=!0;for(;r<i;r++)this.objects[r].object.visible=!1}}}(),THREE.LOD.prototype.clone=function(t){void 0===t&&(t=new THREE.LOD),THREE.Object3D.prototype.clone.call(this,t);for(var e=0,r=this.objects.length;e<r;e++){var i=this.objects[e].object.clone();i.visible=0===e,t.addLevel(i,this.objects[e].distance)}return t},THREE.Sprite=function(){var t=new Uint16Array([0,1,2,0,2,3]),e=new Float32Array([-.5,-.5,0,.5,-.5,0,.5,.5,0,-.5,.5,0]),r=new Float32Array([0,0,1,0,1,1,0,1]),i=new THREE.BufferGeometry;return i.addAttribute("index",new THREE.BufferAttribute(t,1)),i.addAttribute("position",new THREE.BufferAttribute(e,3)),i.addAttribute("uv",new THREE.BufferAttribute(r,2)),function(t){THREE.Object3D.call(this),this.type="Sprite",this.geometry=i,this.material=void 0!==t?t:new THREE.SpriteMaterial}}(),THREE.Sprite.prototype=Object.create(THREE.Object3D.prototype),THREE.Sprite.prototype.raycast=function(){var i=new THREE.Vector3;return function(t,e){i.setFromMatrixPosition(this.matrixWorld);var r=t.ray.distanceToPoint(i);r>this.scale.x||e.push({distance:r,point:this.position,face:null,object:this})}}(),THREE.Sprite.prototype.clone=function(t){return void 0===t&&(t=new THREE.Sprite(this.material)),THREE.Object3D.prototype.clone.call(this,t),t},THREE.Particle=THREE.Sprite,THREE.LensFlare=function(t,e,r,i,n){THREE.Object3D.call(this),this.lensFlares=[],this.positionScreen=new THREE.Vector3,(this.customUpdateCallback=void 0)!==t&&this.add(t,e,r,i,n)},THREE.LensFlare.prototype=Object.create(THREE.Object3D.prototype),THREE.LensFlare.prototype.add=function(t,e,r,i,n,a){void 0===e&&(e=-1),void 0===r&&(r=0),void 0===a&&(a=1),void 0===n&&(n=new THREE.Color(16777215)),void 0===i&&(i=THREE.NormalBlending),r=Math.min(r,Math.max(0,r)),this.lensFlares.push({texture:t,size:e,distance:r,x:0,y:0,z:0,scale:1,rotation:1,opacity:a,color:n,blending:i})},THREE.LensFlare.prototype.updateLensFlares=function(){var t,e,r=this.lensFlares.length,i=2*-this.positionScreen.x,n=2*-this.positionScreen.y;for(t=0;t<r;t++)(e=this.lensFlares[t]).x=this.positionScreen.x+i*e.distance,e.y=this.positionScreen.y+n*e.distance,e.wantedRotation=e.x*Math.PI*.25,e.rotation+=.25*(e.wantedRotation-e.rotation)},THREE.Scene=function(){THREE.Object3D.call(this),this.type="Scene",this.fog=null,this.overrideMaterial=null,this.autoUpdate=!0},THREE.Scene.prototype=Object.create(THREE.Object3D.prototype),THREE.Scene.prototype.clone=function(t){return void 0===t&&(t=new THREE.Scene),THREE.Object3D.prototype.clone.call(this,t),null!==this.fog&&(t.fog=this.fog.clone()),null!==this.overrideMaterial&&(t.overrideMaterial=this.overrideMaterial.clone()),t.autoUpdate=this.autoUpdate,t.matrixAutoUpdate=this.matrixAutoUpdate,t},THREE.Fog=function(t,e,r){this.name="",this.color=new THREE.Color(t),this.near=void 0!==e?e:1,this.far=void 0!==r?r:1e3},THREE.Fog.prototype.clone=function(){return new THREE.Fog(this.color.getHex(),this.near,this.far)},THREE.FogExp2=function(t,e){this.name="",this.color=new THREE.Color(t),this.density=void 0!==e?e:25e-5},THREE.FogExp2.prototype.clone=function(){return new THREE.FogExp2(this.color.getHex(),this.density)},THREE.ShaderChunk={},THREE.ShaderChunk.alphatest_fragment="#ifdef ALPHATEST\n\n\tif ( gl_FragColor.a < ALPHATEST ) discard;\n\n#endif\n",THREE.ShaderChunk.lights_lambert_vertex="vLightFront = vec3( 0.0 );\n\n#ifdef DOUBLE_SIDED\n\n\tvLightBack = vec3( 0.0 );\n\n#endif\n\ntransformedNormal = normalize( transformedNormal );\n\n#if MAX_DIR_LIGHTS > 0\n\nfor( int i = 0; i < MAX_DIR_LIGHTS; i ++ ) {\n\n\tvec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );\n\tvec3 dirVector = normalize( lDirection.xyz );\n\n\tfloat dotProduct = dot( transformedNormal, dirVector );\n\tvec3 directionalLightWeighting = vec3( max( dotProduct, 0.0 ) );\n\n\t#ifdef DOUBLE_SIDED\n\n\t\tvec3 directionalLightWeightingBack = vec3( max( -dotProduct, 0.0 ) );\n\n\t\t#ifdef WRAP_AROUND\n\n\t\t\tvec3 directionalLightWeightingHalfBack = vec3( max( -0.5 * dotProduct + 0.5, 0.0 ) );\n\n\t\t#endif\n\n\t#endif\n\n\t#ifdef WRAP_AROUND\n\n\t\tvec3 directionalLightWeightingHalf = vec3( max( 0.5 * dotProduct + 0.5, 0.0 ) );\n\t\tdirectionalLightWeighting = mix( directionalLightWeighting, directionalLightWeightingHalf, wrapRGB );\n\n\t\t#ifdef DOUBLE_SIDED\n\n\t\t\tdirectionalLightWeightingBack = mix( directionalLightWeightingBack, directionalLightWeightingHalfBack, wrapRGB );\n\n\t\t#endif\n\n\t#endif\n\n\tvLightFront += directionalLightColor[ i ] * directionalLightWeighting;\n\n\t#ifdef DOUBLE_SIDED\n\n\t\tvLightBack += directionalLightColor[ i ] * directionalLightWeightingBack;\n\n\t#endif\n\n}\n\n#endif\n\n#if MAX_POINT_LIGHTS > 0\n\n\tfor( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {\n\n\t\tvec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );\n\t\tvec3 lVector = lPosition.xyz - mvPosition.xyz;\n\n\t\tfloat lDistance = 1.0;\n\t\tif ( pointLightDistance[ i ] > 0.0 )\n\t\t\tlDistance = 1.0 - min( ( length( lVector ) / pointLightDistance[ i ] ), 1.0 );\n\n\t\tlVector = normalize( lVector );\n\t\tfloat dotProduct = dot( transformedNormal, lVector );\n\n\t\tvec3 pointLightWeighting = vec3( max( dotProduct, 0.0 ) );\n\n\t\t#ifdef DOUBLE_SIDED\n\n\t\t\tvec3 pointLightWeightingBack = vec3( max( -dotProduct, 0.0 ) );\n\n\t\t\t#ifdef WRAP_AROUND\n\n\t\t\t\tvec3 pointLightWeightingHalfBack = vec3( max( -0.5 * dotProduct + 0.5, 0.0 ) );\n\n\t\t\t#endif\n\n\t\t#endif\n\n\t\t#ifdef WRAP_AROUND\n\n\t\t\tvec3 pointLightWeightingHalf = vec3( max( 0.5 * dotProduct + 0.5, 0.0 ) );\n\t\t\tpointLightWeighting = mix( pointLightWeighting, pointLightWeightingHalf, wrapRGB );\n\n\t\t\t#ifdef DOUBLE_SIDED\n\n\t\t\t\tpointLightWeightingBack = mix( pointLightWeightingBack, pointLightWeightingHalfBack, wrapRGB );\n\n\t\t\t#endif\n\n\t\t#endif\n\n\t\tvLightFront += pointLightColor[ i ] * pointLightWeighting * lDistance;\n\n\t\t#ifdef DOUBLE_SIDED\n\n\t\t\tvLightBack += pointLightColor[ i ] * pointLightWeightingBack * lDistance;\n\n\t\t#endif\n\n\t}\n\n#endif\n\n#if MAX_SPOT_LIGHTS > 0\n\n\tfor( int i = 0; i < MAX_SPOT_LIGHTS; i ++ ) {\n\n\t\tvec4 lPosition = viewMatrix * vec4( spotLightPosition[ i ], 1.0 );\n\t\tvec3 lVector = lPosition.xyz - mvPosition.xyz;\n\n\t\tfloat spotEffect = dot( spotLightDirection[ i ], normalize( spotLightPosition[ i ] - worldPosition.xyz ) );\n\n\t\tif ( spotEffect > spotLightAngleCos[ i ] ) {\n\n\t\t\tspotEffect = max( pow( max( spotEffect, 0.0 ), spotLightExponent[ i ] ), 0.0 );\n\n\t\t\tfloat lDistance = 1.0;\n\t\t\tif ( spotLightDistance[ i ] > 0.0 )\n\t\t\t\tlDistance = 1.0 - min( ( length( lVector ) / spotLightDistance[ i ] ), 1.0 );\n\n\t\t\tlVector = normalize( lVector );\n\n\t\t\tfloat dotProduct = dot( transformedNormal, lVector );\n\t\t\tvec3 spotLightWeighting = vec3( max( dotProduct, 0.0 ) );\n\n\t\t\t#ifdef DOUBLE_SIDED\n\n\t\t\t\tvec3 spotLightWeightingBack = vec3( max( -dotProduct, 0.0 ) );\n\n\t\t\t\t#ifdef WRAP_AROUND\n\n\t\t\t\t\tvec3 spotLightWeightingHalfBack = vec3( max( -0.5 * dotProduct + 0.5, 0.0 ) );\n\n\t\t\t\t#endif\n\n\t\t\t#endif\n\n\t\t\t#ifdef WRAP_AROUND\n\n\t\t\t\tvec3 spotLightWeightingHalf = vec3( max( 0.5 * dotProduct + 0.5, 0.0 ) );\n\t\t\t\tspotLightWeighting = mix( spotLightWeighting, spotLightWeightingHalf, wrapRGB );\n\n\t\t\t\t#ifdef DOUBLE_SIDED\n\n\t\t\t\t\tspotLightWeightingBack = mix( spotLightWeightingBack, spotLightWeightingHalfBack, wrapRGB );\n\n\t\t\t\t#endif\n\n\t\t\t#endif\n\n\t\t\tvLightFront += spotLightColor[ i ] * spotLightWeighting * lDistance * spotEffect;\n\n\t\t\t#ifdef DOUBLE_SIDED\n\n\t\t\t\tvLightBack += spotLightColor[ i ] * spotLightWeightingBack * lDistance * spotEffect;\n\n\t\t\t#endif\n\n\t\t}\n\n\t}\n\n#endif\n\n#if MAX_HEMI_LIGHTS > 0\n\n\tfor( int i = 0; i < MAX_HEMI_LIGHTS; i ++ ) {\n\n\t\tvec4 lDirection = viewMatrix * vec4( hemisphereLightDirection[ i ], 0.0 );\n\t\tvec3 lVector = normalize( lDirection.xyz );\n\n\t\tfloat dotProduct = dot( transformedNormal, lVector );\n\n\t\tfloat hemiDiffuseWeight = 0.5 * dotProduct + 0.5;\n\t\tfloat hemiDiffuseWeightBack = -0.5 * dotProduct + 0.5;\n\n\t\tvLightFront += mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeight );\n\n\t\t#ifdef DOUBLE_SIDED\n\n\t\t\tvLightBack += mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeightBack );\n\n\t\t#endif\n\n\t}\n\n#endif\n\nvLightFront = vLightFront * diffuse + ambient * ambientLightColor + emissive;\n\n#ifdef DOUBLE_SIDED\n\n\tvLightBack = vLightBack * diffuse + ambient * ambientLightColor + emissive;\n\n#endif",THREE.ShaderChunk.map_particle_pars_fragment="#ifdef USE_MAP\n\n\tuniform sampler2D map;\n\n#endif",THREE.ShaderChunk.default_vertex="vec4 mvPosition;\n\n#ifdef USE_SKINNING\n\n\tmvPosition = modelViewMatrix * skinned;\n\n#endif\n\n#if !defined( USE_SKINNING ) && defined( USE_MORPHTARGETS )\n\n\tmvPosition = modelViewMatrix * vec4( morphed, 1.0 );\n\n#endif\n\n#if !defined( USE_SKINNING ) && ! defined( USE_MORPHTARGETS )\n\n\tmvPosition = modelViewMatrix * vec4( position, 1.0 );\n\n#endif\n\ngl_Position = projectionMatrix * mvPosition;",THREE.ShaderChunk.map_pars_fragment="#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP )\n\n\tvarying vec2 vUv;\n\n#endif\n\n#ifdef USE_MAP\n\n\tuniform sampler2D map;\n\n#endif",THREE.ShaderChunk.skinnormal_vertex="#ifdef USE_SKINNING\n\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\n\t#ifdef USE_MORPHNORMALS\n\n\tvec4 skinnedNormal = skinMatrix * vec4( morphedNormal, 0.0 );\n\n\t#else\n\n\tvec4 skinnedNormal = skinMatrix * vec4( normal, 0.0 );\n\n\t#endif\n\n#endif\n",THREE.ShaderChunk.logdepthbuf_pars_vertex="#ifdef USE_LOGDEPTHBUF\n\n\t#ifdef USE_LOGDEPTHBUF_EXT\n\n\t\tvarying float vFragDepth;\n\n\t#endif\n\n\tuniform float logDepthBufFC;\n\n#endif",THREE.ShaderChunk.lightmap_pars_vertex="#ifdef USE_LIGHTMAP\n\n\tvarying vec2 vUv2;\n\n#endif",THREE.ShaderChunk.lights_phong_fragment="vec3 normal = normalize( vNormal );\nvec3 viewPosition = normalize( vViewPosition );\n\n#ifdef DOUBLE_SIDED\n\n\tnormal = normal * ( -1.0 + 2.0 * float( gl_FrontFacing ) );\n\n#endif\n\n#ifdef USE_NORMALMAP\n\n\tnormal = perturbNormal2Arb( -vViewPosition, normal );\n\n#elif defined( USE_BUMPMAP )\n\n\tnormal = perturbNormalArb( -vViewPosition, normal, dHdxy_fwd() );\n\n#endif\n\n#if MAX_POINT_LIGHTS > 0\n\n\tvec3 pointDiffuse = vec3( 0.0 );\n\tvec3 pointSpecular = vec3( 0.0 );\n\n\tfor ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {\n\n\t\tvec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );\n\t\tvec3 lVector = lPosition.xyz + vViewPosition.xyz;\n\n\t\tfloat lDistance = 1.0;\n\t\tif ( pointLightDistance[ i ] > 0.0 )\n\t\t\tlDistance = 1.0 - min( ( length( lVector ) / pointLightDistance[ i ] ), 1.0 );\n\n\t\tlVector = normalize( lVector );\n\n\t\t\t\t// diffuse\n\n\t\tfloat dotProduct = dot( normal, lVector );\n\n\t\t#ifdef WRAP_AROUND\n\n\t\t\tfloat pointDiffuseWeightFull = max( dotProduct, 0.0 );\n\t\t\tfloat pointDiffuseWeightHalf = max( 0.5 * dotProduct + 0.5, 0.0 );\n\n\t\t\tvec3 pointDiffuseWeight = mix( vec3( pointDiffuseWeightFull ), vec3( pointDiffuseWeightHalf ), wrapRGB );\n\n\t\t#else\n\n\t\t\tfloat pointDiffuseWeight = max( dotProduct, 0.0 );\n\n\t\t#endif\n\n\t\tpointDiffuse += diffuse * pointLightColor[ i ] * pointDiffuseWeight * lDistance;\n\n\t\t\t\t// specular\n\n\t\tvec3 pointHalfVector = normalize( lVector + viewPosition );\n\t\tfloat pointDotNormalHalf = max( dot( normal, pointHalfVector ), 0.0 );\n\t\tfloat pointSpecularWeight = specularStrength * max( pow( pointDotNormalHalf, shininess ), 0.0 );\n\n\t\tfloat specularNormalization = ( shininess + 2.0 ) / 8.0;\n\n\t\tvec3 schlick = specular + vec3( 1.0 - specular ) * pow( max( 1.0 - dot( lVector, pointHalfVector ), 0.0 ), 5.0 );\n\t\tpointSpecular += schlick * pointLightColor[ i ] * pointSpecularWeight * pointDiffuseWeight * lDistance * specularNormalization;\n\n\t}\n\n#endif\n\n#if MAX_SPOT_LIGHTS > 0\n\n\tvec3 spotDiffuse = vec3( 0.0 );\n\tvec3 spotSpecular = vec3( 0.0 );\n\n\tfor ( int i = 0; i < MAX_SPOT_LIGHTS; i ++ ) {\n\n\t\tvec4 lPosition = viewMatrix * vec4( spotLightPosition[ i ], 1.0 );\n\t\tvec3 lVector = lPosition.xyz + vViewPosition.xyz;\n\n\t\tfloat lDistance = 1.0;\n\t\tif ( spotLightDistance[ i ] > 0.0 )\n\t\t\tlDistance = 1.0 - min( ( length( lVector ) / spotLightDistance[ i ] ), 1.0 );\n\n\t\tlVector = normalize( lVector );\n\n\t\tfloat spotEffect = dot( spotLightDirection[ i ], normalize( spotLightPosition[ i ] - vWorldPosition ) );\n\n\t\tif ( spotEffect > spotLightAngleCos[ i ] ) {\n\n\t\t\tspotEffect = max( pow( max( spotEffect, 0.0 ), spotLightExponent[ i ] ), 0.0 );\n\n\t\t\t\t\t// diffuse\n\n\t\t\tfloat dotProduct = dot( normal, lVector );\n\n\t\t\t#ifdef WRAP_AROUND\n\n\t\t\t\tfloat spotDiffuseWeightFull = max( dotProduct, 0.0 );\n\t\t\t\tfloat spotDiffuseWeightHalf = max( 0.5 * dotProduct + 0.5, 0.0 );\n\n\t\t\t\tvec3 spotDiffuseWeight = mix( vec3( spotDiffuseWeightFull ), vec3( spotDiffuseWeightHalf ), wrapRGB );\n\n\t\t\t#else\n\n\t\t\t\tfloat spotDiffuseWeight = max( dotProduct, 0.0 );\n\n\t\t\t#endif\n\n\t\t\tspotDiffuse += diffuse * spotLightColor[ i ] * spotDiffuseWeight * lDistance * spotEffect;\n\n\t\t\t\t\t// specular\n\n\t\t\tvec3 spotHalfVector = normalize( lVector + viewPosition );\n\t\t\tfloat spotDotNormalHalf = max( dot( normal, spotHalfVector ), 0.0 );\n\t\t\tfloat spotSpecularWeight = specularStrength * max( pow( spotDotNormalHalf, shininess ), 0.0 );\n\n\t\t\tfloat specularNormalization = ( shininess + 2.0 ) / 8.0;\n\n\t\t\tvec3 schlick = specular + vec3( 1.0 - specular ) * pow( max( 1.0 - dot( lVector, spotHalfVector ), 0.0 ), 5.0 );\n\t\t\tspotSpecular += schlick * spotLightColor[ i ] * spotSpecularWeight * spotDiffuseWeight * lDistance * specularNormalization * spotEffect;\n\n\t\t}\n\n\t}\n\n#endif\n\n#if MAX_DIR_LIGHTS > 0\n\n\tvec3 dirDiffuse = vec3( 0.0 );\n\tvec3 dirSpecular = vec3( 0.0 );\n\n\tfor( int i = 0; i < MAX_DIR_LIGHTS; i ++ ) {\n\n\t\tvec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );\n\t\tvec3 dirVector = normalize( lDirection.xyz );\n\n\t\t\t\t// diffuse\n\n\t\tfloat dotProduct = dot( normal, dirVector );\n\n\t\t#ifdef WRAP_AROUND\n\n\t\t\tfloat dirDiffuseWeightFull = max( dotProduct, 0.0 );\n\t\t\tfloat dirDiffuseWeightHalf = max( 0.5 * dotProduct + 0.5, 0.0 );\n\n\t\t\tvec3 dirDiffuseWeight = mix( vec3( dirDiffuseWeightFull ), vec3( dirDiffuseWeightHalf ), wrapRGB );\n\n\t\t#else\n\n\t\t\tfloat dirDiffuseWeight = max( dotProduct, 0.0 );\n\n\t\t#endif\n\n\t\tdirDiffuse += diffuse * directionalLightColor[ i ] * dirDiffuseWeight;\n\n\t\t// specular\n\n\t\tvec3 dirHalfVector = normalize( dirVector + viewPosition );\n\t\tfloat dirDotNormalHalf = max( dot( normal, dirHalfVector ), 0.0 );\n\t\tfloat dirSpecularWeight = specularStrength * max( pow( dirDotNormalHalf, shininess ), 0.0 );\n\n\t\t/*\n\t\t// fresnel term from skin shader\n\t\tconst float F0 = 0.128;\n\n\t\tfloat base = 1.0 - dot( viewPosition, dirHalfVector );\n\t\tfloat exponential = pow( base, 5.0 );\n\n\t\tfloat fresnel = exponential + F0 * ( 1.0 - exponential );\n\t\t*/\n\n\t\t/*\n\t\t// fresnel term from fresnel shader\n\t\tconst float mFresnelBias = 0.08;\n\t\tconst float mFresnelScale = 0.3;\n\t\tconst float mFresnelPower = 5.0;\n\n\t\tfloat fresnel = mFresnelBias + mFresnelScale * pow( 1.0 + dot( normalize( -viewPosition ), normal ), mFresnelPower );\n\t\t*/\n\n\t\tfloat specularNormalization = ( shininess + 2.0 ) / 8.0;\n\n\t\t// \t\tdirSpecular += specular * directionalLightColor[ i ] * dirSpecularWeight * dirDiffuseWeight * specularNormalization * fresnel;\n\n\t\tvec3 schlick = specular + vec3( 1.0 - specular ) * pow( max( 1.0 - dot( dirVector, dirHalfVector ), 0.0 ), 5.0 );\n\t\tdirSpecular += schlick * directionalLightColor[ i ] * dirSpecularWeight * dirDiffuseWeight * specularNormalization;\n\n\n\t}\n\n#endif\n\n#if MAX_HEMI_LIGHTS > 0\n\n\tvec3 hemiDiffuse = vec3( 0.0 );\n\tvec3 hemiSpecular = vec3( 0.0 );\n\n\tfor( int i = 0; i < MAX_HEMI_LIGHTS; i ++ ) {\n\n\t\tvec4 lDirection = viewMatrix * vec4( hemisphereLightDirection[ i ], 0.0 );\n\t\tvec3 lVector = normalize( lDirection.xyz );\n\n\t\t// diffuse\n\n\t\tfloat dotProduct = dot( normal, lVector );\n\t\tfloat hemiDiffuseWeight = 0.5 * dotProduct + 0.5;\n\n\t\tvec3 hemiColor = mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeight );\n\n\t\themiDiffuse += diffuse * hemiColor;\n\n\t\t// specular (sky light)\n\n\t\tvec3 hemiHalfVectorSky = normalize( lVector + viewPosition );\n\t\tfloat hemiDotNormalHalfSky = 0.5 * dot( normal, hemiHalfVectorSky ) + 0.5;\n\t\tfloat hemiSpecularWeightSky = specularStrength * max( pow( max( hemiDotNormalHalfSky, 0.0 ), shininess ), 0.0 );\n\n\t\t// specular (ground light)\n\n\t\tvec3 lVectorGround = -lVector;\n\n\t\tvec3 hemiHalfVectorGround = normalize( lVectorGround + viewPosition );\n\t\tfloat hemiDotNormalHalfGround = 0.5 * dot( normal, hemiHalfVectorGround ) + 0.5;\n\t\tfloat hemiSpecularWeightGround = specularStrength * max( pow( max( hemiDotNormalHalfGround, 0.0 ), shininess ), 0.0 );\n\n\t\tfloat dotProductGround = dot( normal, lVectorGround );\n\n\t\tfloat specularNormalization = ( shininess + 2.0 ) / 8.0;\n\n\t\tvec3 schlickSky = specular + vec3( 1.0 - specular ) * pow( max( 1.0 - dot( lVector, hemiHalfVectorSky ), 0.0 ), 5.0 );\n\t\tvec3 schlickGround = specular + vec3( 1.0 - specular ) * pow( max( 1.0 - dot( lVectorGround, hemiHalfVectorGround ), 0.0 ), 5.0 );\n\t\themiSpecular += hemiColor * specularNormalization * ( schlickSky * hemiSpecularWeightSky * max( dotProduct, 0.0 ) + schlickGround * hemiSpecularWeightGround * max( dotProductGround, 0.0 ) );\n\n\t}\n\n#endif\n\nvec3 totalDiffuse = vec3( 0.0 );\nvec3 totalSpecular = vec3( 0.0 );\n\n#if MAX_DIR_LIGHTS > 0\n\n\ttotalDiffuse += dirDiffuse;\n\ttotalSpecular += dirSpecular;\n\n#endif\n\n#if MAX_HEMI_LIGHTS > 0\n\n\ttotalDiffuse += hemiDiffuse;\n\ttotalSpecular += hemiSpecular;\n\n#endif\n\n#if MAX_POINT_LIGHTS > 0\n\n\ttotalDiffuse += pointDiffuse;\n\ttotalSpecular += pointSpecular;\n\n#endif\n\n#if MAX_SPOT_LIGHTS > 0\n\n\ttotalDiffuse += spotDiffuse;\n\ttotalSpecular += spotSpecular;\n\n#endif\n\n#ifdef METAL\n\n\tgl_FragColor.xyz = gl_FragColor.xyz * ( emissive + totalDiffuse + ambientLightColor * ambient + totalSpecular );\n\n#else\n\n\tgl_FragColor.xyz = gl_FragColor.xyz * ( emissive + totalDiffuse + ambientLightColor * ambient ) + totalSpecular;\n\n#endif",THREE.ShaderChunk.fog_pars_fragment="#ifdef USE_FOG\n\n\tuniform vec3 fogColor;\n\n\t#ifdef FOG_EXP2\n\n\t\tuniform float fogDensity;\n\n\t#else\n\n\t\tuniform float fogNear;\n\t\tuniform float fogFar;\n\t#endif\n\n#endif",THREE.ShaderChunk.morphnormal_vertex="#ifdef USE_MORPHNORMALS\n\n\tvec3 morphedNormal = vec3( 0.0 );\n\n\tmorphedNormal += ( morphNormal0 - normal ) * morphTargetInfluences[ 0 ];\n\tmorphedNormal += ( morphNormal1 - normal ) * morphTargetInfluences[ 1 ];\n\tmorphedNormal += ( morphNormal2 - normal ) * morphTargetInfluences[ 2 ];\n\tmorphedNormal += ( morphNormal3 - normal ) * morphTargetInfluences[ 3 ];\n\n\tmorphedNormal += normal;\n\n#endif",THREE.ShaderChunk.envmap_pars_fragment="#ifdef USE_ENVMAP\n\n\tuniform float reflectivity;\n\tuniform samplerCube envMap;\n\tuniform float flipEnvMap;\n\tuniform int combine;\n\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG )\n\n\t\tuniform bool useRefract;\n\t\tuniform float refractionRatio;\n\n\t#else\n\n\t\tvarying vec3 vReflect;\n\n\t#endif\n\n#endif",THREE.ShaderChunk.logdepthbuf_fragment="#if defined(USE_LOGDEPTHBUF) && defined(USE_LOGDEPTHBUF_EXT)\n\n\tgl_FragDepthEXT = log2(vFragDepth) * logDepthBufFC * 0.5;\n\n#endif",THREE.ShaderChunk.normalmap_pars_fragment="#ifdef USE_NORMALMAP\n\n\tuniform sampler2D normalMap;\n\tuniform vec2 normalScale;\n\n\t\t\t// Per-Pixel Tangent Space Normal Mapping\n\t\t\t// http://hacksoflife.blogspot.ch/2009/11/per-pixel-tangent-space-normal-mapping.html\n\n\tvec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm ) {\n\n\t\tvec3 q0 = dFdx( eye_pos.xyz );\n\t\tvec3 q1 = dFdy( eye_pos.xyz );\n\t\tvec2 st0 = dFdx( vUv.st );\n\t\tvec2 st1 = dFdy( vUv.st );\n\n\t\tvec3 S = normalize( q0 * st1.t - q1 * st0.t );\n\t\tvec3 T = normalize( -q0 * st1.s + q1 * st0.s );\n\t\tvec3 N = normalize( surf_norm );\n\n\t\tvec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\n\t\tmapN.xy = normalScale * mapN.xy;\n\t\tmat3 tsn = mat3( S, T, N );\n\t\treturn normalize( tsn * mapN );\n\n\t}\n\n#endif\n",THREE.ShaderChunk.lights_phong_pars_vertex="#if MAX_SPOT_LIGHTS > 0 || defined( USE_BUMPMAP ) || defined( USE_ENVMAP )\n\n\tvarying vec3 vWorldPosition;\n\n#endif\n",THREE.ShaderChunk.lightmap_pars_fragment="#ifdef USE_LIGHTMAP\n\n\tvarying vec2 vUv2;\n\tuniform sampler2D lightMap;\n\n#endif",THREE.ShaderChunk.shadowmap_vertex="#ifdef USE_SHADOWMAP\n\n\tfor( int i = 0; i < MAX_SHADOWS; i ++ ) {\n\n\t\tvShadowCoord[ i ] = shadowMatrix[ i ] * worldPosition;\n\n\t}\n\n#endif",THREE.ShaderChunk.lights_phong_vertex="#if MAX_SPOT_LIGHTS > 0 || defined( USE_BUMPMAP ) || defined( USE_ENVMAP )\n\n\tvWorldPosition = worldPosition.xyz;\n\n#endif",THREE.ShaderChunk.map_fragment="#ifdef USE_MAP\n\n\tvec4 texelColor = texture2D( map, vUv );\n\n\t#ifdef GAMMA_INPUT\n\n\t\ttexelColor.xyz *= texelColor.xyz;\n\n\t#endif\n\n\tgl_FragColor = gl_FragColor * texelColor;\n\n#endif",THREE.ShaderChunk.lightmap_vertex="#ifdef USE_LIGHTMAP\n\n\tvUv2 = uv2;\n\n#endif",THREE.ShaderChunk.map_particle_fragment="#ifdef USE_MAP\n\n\tgl_FragColor = gl_FragColor * texture2D( map, vec2( gl_PointCoord.x, 1.0 - gl_PointCoord.y ) );\n\n#endif",THREE.ShaderChunk.color_pars_fragment="#ifdef USE_COLOR\n\n\tvarying vec3 vColor;\n\n#endif\n",THREE.ShaderChunk.color_vertex="#ifdef USE_COLOR\n\n\t#ifdef GAMMA_INPUT\n\n\t\tvColor = color * color;\n\n\t#else\n\n\t\tvColor = color;\n\n\t#endif\n\n#endif",THREE.ShaderChunk.skinning_vertex="#ifdef USE_SKINNING\n\n\t#ifdef USE_MORPHTARGETS\n\n\tvec4 skinVertex = bindMatrix * vec4( morphed, 1.0 );\n\n\t#else\n\n\tvec4 skinVertex = bindMatrix * vec4( position, 1.0 );\n\n\t#endif\n\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\tskinned = bindMatrixInverse * skinned;\n\n#endif\n",THREE.ShaderChunk.envmap_pars_vertex="#if defined( USE_ENVMAP ) && ! defined( USE_BUMPMAP ) && ! defined( USE_NORMALMAP ) && ! defined( PHONG )\n\n\tvarying vec3 vReflect;\n\n\tuniform float refractionRatio;\n\tuniform bool useRefract;\n\n#endif\n",THREE.ShaderChunk.linear_to_gamma_fragment="#ifdef GAMMA_OUTPUT\n\n\tgl_FragColor.xyz = sqrt( gl_FragColor.xyz );\n\n#endif",THREE.ShaderChunk.color_pars_vertex="#ifdef USE_COLOR\n\n\tvarying vec3 vColor;\n\n#endif",THREE.ShaderChunk.lights_lambert_pars_vertex="uniform vec3 ambient;\nuniform vec3 diffuse;\nuniform vec3 emissive;\n\nuniform vec3 ambientLightColor;\n\n#if MAX_DIR_LIGHTS > 0\n\n\tuniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];\n\tuniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];\n\n#endif\n\n#if MAX_HEMI_LIGHTS > 0\n\n\tuniform vec3 hemisphereLightSkyColor[ MAX_HEMI_LIGHTS ];\n\tuniform vec3 hemisphereLightGroundColor[ MAX_HEMI_LIGHTS ];\n\tuniform vec3 hemisphereLightDirection[ MAX_HEMI_LIGHTS ];\n\n#endif\n\n#if MAX_POINT_LIGHTS > 0\n\n\tuniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];\n\tuniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];\n\tuniform float pointLightDistance[ MAX_POINT_LIGHTS ];\n\n#endif\n\n#if MAX_SPOT_LIGHTS > 0\n\n\tuniform vec3 spotLightColor[ MAX_SPOT_LIGHTS ];\n\tuniform vec3 spotLightPosition[ MAX_SPOT_LIGHTS ];\n\tuniform vec3 spotLightDirection[ MAX_SPOT_LIGHTS ];\n\tuniform float spotLightDistance[ MAX_SPOT_LIGHTS ];\n\tuniform float spotLightAngleCos[ MAX_SPOT_LIGHTS ];\n\tuniform float spotLightExponent[ MAX_SPOT_LIGHTS ];\n\n#endif\n\n#ifdef WRAP_AROUND\n\n\tuniform vec3 wrapRGB;\n\n#endif\n",THREE.ShaderChunk.map_pars_vertex="#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP )\n\n\tvarying vec2 vUv;\n\tuniform vec4 offsetRepeat;\n\n#endif\n",THREE.ShaderChunk.envmap_fragment="#ifdef USE_ENVMAP\n\n\tvec3 reflectVec;\n\n\t#if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG )\n\n\t\tvec3 cameraToVertex = normalize( vWorldPosition - cameraPosition );\n\n\t\t// http://en.wikibooks.org/wiki/GLSL_Programming/Applying_Matrix_Transformations\n\t\t// Transforming Normal Vectors with the Inverse Transformation\n\n\t\tvec3 worldNormal = normalize( vec3( vec4( normal, 0.0 ) * viewMatrix ) );\n\n\t\tif ( useRefract ) {\n\n\t\t\treflectVec = refract( cameraToVertex, worldNormal, refractionRatio );\n\n\t\t} else { \n\n\t\t\treflectVec = reflect( cameraToVertex, worldNormal );\n\n\t\t}\n\n\t#else\n\n\t\treflectVec = vReflect;\n\n\t#endif\n\n\t#ifdef DOUBLE_SIDED\n\n\t\tfloat flipNormal = ( -1.0 + 2.0 * float( gl_FrontFacing ) );\n\t\tvec4 cubeColor = textureCube( envMap, flipNormal * vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );\n\n\t#else\n\n\t\tvec4 cubeColor = textureCube( envMap, vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );\n\n\t#endif\n\n\t#ifdef GAMMA_INPUT\n\n\t\tcubeColor.xyz *= cubeColor.xyz;\n\n\t#endif\n\n\tif ( combine == 1 ) {\n\n\t\tgl_FragColor.xyz = mix( gl_FragColor.xyz, cubeColor.xyz, specularStrength * reflectivity );\n\n\t} else if ( combine == 2 ) {\n\n\t\tgl_FragColor.xyz += cubeColor.xyz * specularStrength * reflectivity;\n\n\t} else {\n\n\t\tgl_FragColor.xyz = mix( gl_FragColor.xyz, gl_FragColor.xyz * cubeColor.xyz, specularStrength * reflectivity );\n\n\t}\n\n#endif",THREE.ShaderChunk.specularmap_pars_fragment="#ifdef USE_SPECULARMAP\n\n\tuniform sampler2D specularMap;\n\n#endif",THREE.ShaderChunk.logdepthbuf_vertex="#ifdef USE_LOGDEPTHBUF\n\n\tgl_Position.z = log2(max(1e-6, gl_Position.w + 1.0)) * logDepthBufFC;\n\n\t#ifdef USE_LOGDEPTHBUF_EXT\n\n\t\tvFragDepth = 1.0 + gl_Position.w;\n\n#else\n\n\t\tgl_Position.z = (gl_Position.z - 1.0) * gl_Position.w;\n\n\t#endif\n\n#endif",THREE.ShaderChunk.morphtarget_pars_vertex="#ifdef USE_MORPHTARGETS\n\n\t#ifndef USE_MORPHNORMALS\n\n\tuniform float morphTargetInfluences[ 8 ];\n\n\t#else\n\n\tuniform float morphTargetInfluences[ 4 ];\n\n\t#endif\n\n#endif",THREE.ShaderChunk.specularmap_fragment="float specularStrength;\n\n#ifdef USE_SPECULARMAP\n\n\tvec4 texelSpecular = texture2D( specularMap, vUv );\n\tspecularStrength = texelSpecular.r;\n\n#else\n\n\tspecularStrength = 1.0;\n\n#endif",THREE.ShaderChunk.fog_fragment="#ifdef USE_FOG\n\n\t#ifdef USE_LOGDEPTHBUF_EXT\n\n\t\tfloat depth = gl_FragDepthEXT / gl_FragCoord.w;\n\n\t#else\n\n\t\tfloat depth = gl_FragCoord.z / gl_FragCoord.w;\n\n\t#endif\n\n\t#ifdef FOG_EXP2\n\n\t\tconst float LOG2 = 1.442695;\n\t\tfloat fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );\n\t\tfogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );\n\n\t#else\n\n\t\tfloat fogFactor = smoothstep( fogNear, fogFar, depth );\n\n\t#endif\n\t\n\tgl_FragColor = mix( gl_FragColor, vec4( fogColor, gl_FragColor.w ), fogFactor );\n\n#endif",THREE.ShaderChunk.bumpmap_pars_fragment="#ifdef USE_BUMPMAP\n\n\tuniform sampler2D bumpMap;\n\tuniform float bumpScale;\n\n\t\t\t// Derivative maps - bump mapping unparametrized surfaces by Morten Mikkelsen\n\t\t\t//\thttp://mmikkelsen3d.blogspot.sk/2011/07/derivative-maps.html\n\n\t\t\t// Evaluate the derivative of the height w.r.t. screen-space using forward differencing (listing 2)\n\n\tvec2 dHdxy_fwd() {\n\n\t\tvec2 dSTdx = dFdx( vUv );\n\t\tvec2 dSTdy = dFdy( vUv );\n\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\n\t\treturn vec2( dBx, dBy );\n\n\t}\n\n\tvec3 perturbNormalArb( vec3 surf_pos, vec3 surf_norm, vec2 dHdxy ) {\n\n\t\tvec3 vSigmaX = dFdx( surf_pos );\n\t\tvec3 vSigmaY = dFdy( surf_pos );\n\t\tvec3 vN = surf_norm;\t\t// normalized\n\n\t\tvec3 R1 = cross( vSigmaY, vN );\n\t\tvec3 R2 = cross( vN, vSigmaX );\n\n\t\tfloat fDet = dot( vSigmaX, R1 );\n\n\t\tvec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 );\n\t\treturn normalize( abs( fDet ) * surf_norm - vGrad );\n\n\t}\n\n#endif",THREE.ShaderChunk.defaultnormal_vertex="vec3 objectNormal;\n\n#ifdef USE_SKINNING\n\n\tobjectNormal = skinnedNormal.xyz;\n\n#endif\n\n#if !defined( USE_SKINNING ) && defined( USE_MORPHNORMALS )\n\n\tobjectNormal = morphedNormal;\n\n#endif\n\n#if !defined( USE_SKINNING ) && ! defined( USE_MORPHNORMALS )\n\n\tobjectNormal = normal;\n\n#endif\n\n#ifdef FLIP_SIDED\n\n\tobjectNormal = -objectNormal;\n\n#endif\n\nvec3 transformedNormal = normalMatrix * objectNormal;",THREE.ShaderChunk.lights_phong_pars_fragment="uniform vec3 ambientLightColor;\n\n#if MAX_DIR_LIGHTS > 0\n\n\tuniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];\n\tuniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];\n\n#endif\n\n#if MAX_HEMI_LIGHTS > 0\n\n\tuniform vec3 hemisphereLightSkyColor[ MAX_HEMI_LIGHTS ];\n\tuniform vec3 hemisphereLightGroundColor[ MAX_HEMI_LIGHTS ];\n\tuniform vec3 hemisphereLightDirection[ MAX_HEMI_LIGHTS ];\n\n#endif\n\n#if MAX_POINT_LIGHTS > 0\n\n\tuniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];\n\n\tuniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];\n\tuniform float pointLightDistance[ MAX_POINT_LIGHTS ];\n\n#endif\n\n#if MAX_SPOT_LIGHTS > 0\n\n\tuniform vec3 spotLightColor[ MAX_SPOT_LIGHTS ];\n\tuniform vec3 spotLightPosition[ MAX_SPOT_LIGHTS ];\n\tuniform vec3 spotLightDirection[ MAX_SPOT_LIGHTS ];\n\tuniform float spotLightAngleCos[ MAX_SPOT_LIGHTS ];\n\tuniform float spotLightExponent[ MAX_SPOT_LIGHTS ];\n\n\tuniform float spotLightDistance[ MAX_SPOT_LIGHTS ];\n\n#endif\n\n#if MAX_SPOT_LIGHTS > 0 || defined( USE_BUMPMAP ) || defined( USE_ENVMAP )\n\n\tvarying vec3 vWorldPosition;\n\n#endif\n\n#ifdef WRAP_AROUND\n\n\tuniform vec3 wrapRGB;\n\n#endif\n\nvarying vec3 vViewPosition;\nvarying vec3 vNormal;",THREE.ShaderChunk.skinbase_vertex="#ifdef USE_SKINNING\n\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\n#endif",THREE.ShaderChunk.map_vertex="#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP )\n\n\tvUv = uv * offsetRepeat.zw + offsetRepeat.xy;\n\n#endif",THREE.ShaderChunk.lightmap_fragment="#ifdef USE_LIGHTMAP\n\n\tgl_FragColor = gl_FragColor * texture2D( lightMap, vUv2 );\n\n#endif",THREE.ShaderChunk.shadowmap_pars_vertex="#ifdef USE_SHADOWMAP\n\n\tvarying vec4 vShadowCoord[ MAX_SHADOWS ];\n\tuniform mat4 shadowMatrix[ MAX_SHADOWS ];\n\n#endif",THREE.ShaderChunk.color_fragment="#ifdef USE_COLOR\n\n\tgl_FragColor = gl_FragColor * vec4( vColor, 1.0 );\n\n#endif",THREE.ShaderChunk.morphtarget_vertex="#ifdef USE_MORPHTARGETS\n\n\tvec3 morphed = vec3( 0.0 );\n\tmorphed += ( morphTarget0 - position ) * morphTargetInfluences[ 0 ];\n\tmorphed += ( morphTarget1 - position ) * morphTargetInfluences[ 1 ];\n\tmorphed += ( morphTarget2 - position ) * morphTargetInfluences[ 2 ];\n\tmorphed += ( morphTarget3 - position ) * morphTargetInfluences[ 3 ];\n\n\t#ifndef USE_MORPHNORMALS\n\n\tmorphed += ( morphTarget4 - position ) * morphTargetInfluences[ 4 ];\n\tmorphed += ( morphTarget5 - position ) * morphTargetInfluences[ 5 ];\n\tmorphed += ( morphTarget6 - position ) * morphTargetInfluences[ 6 ];\n\tmorphed += ( morphTarget7 - position ) * morphTargetInfluences[ 7 ];\n\n\t#endif\n\n\tmorphed += position;\n\n#endif",THREE.ShaderChunk.envmap_vertex="#if defined( USE_ENVMAP ) && ! defined( USE_BUMPMAP ) && ! defined( USE_NORMALMAP ) && ! defined( PHONG )\n\n\tvec3 worldNormal = mat3( modelMatrix[ 0 ].xyz, modelMatrix[ 1 ].xyz, modelMatrix[ 2 ].xyz ) * objectNormal;\n\tworldNormal = normalize( worldNormal );\n\n\tvec3 cameraToVertex = normalize( worldPosition.xyz - cameraPosition );\n\n\tif ( useRefract ) {\n\n\t\tvReflect = refract( cameraToVertex, worldNormal, refractionRatio );\n\n\t} else {\n\n\t\tvReflect = reflect( cameraToVertex, worldNormal );\n\n\t}\n\n#endif",THREE.ShaderChunk.shadowmap_fragment="#ifdef USE_SHADOWMAP\n\n\t#ifdef SHADOWMAP_DEBUG\n\n\t\tvec3 frustumColors[3];\n\t\tfrustumColors[0] = vec3( 1.0, 0.5, 0.0 );\n\t\tfrustumColors[1] = vec3( 0.0, 1.0, 0.8 );\n\t\tfrustumColors[2] = vec3( 0.0, 0.5, 1.0 );\n\n\t#endif\n\n\t#ifdef SHADOWMAP_CASCADE\n\n\t\tint inFrustumCount = 0;\n\n\t#endif\n\n\tfloat fDepth;\n\tvec3 shadowColor = vec3( 1.0 );\n\n\tfor( int i = 0; i < MAX_SHADOWS; i ++ ) {\n\n\t\tvec3 shadowCoord = vShadowCoord[ i ].xyz / vShadowCoord[ i ].w;\n\n\t\t\t\t// if ( something && something ) breaks ATI OpenGL shader compiler\n\t\t\t\t// if ( all( something, something ) ) using this instead\n\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\n\t\t\t\t// don't shadow pixels outside of light frustum\n\t\t\t\t// use just first frustum (for cascades)\n\t\t\t\t// don't shadow pixels behind far plane of light frustum\n\n\t\t#ifdef SHADOWMAP_CASCADE\n\n\t\t\tinFrustumCount += int( inFrustum );\n\t\t\tbvec3 frustumTestVec = bvec3( inFrustum, inFrustumCount == 1, shadowCoord.z <= 1.0 );\n\n\t\t#else\n\n\t\t\tbvec2 frustumTestVec = bvec2( inFrustum, shadowCoord.z <= 1.0 );\n\n\t\t#endif\n\n\t\tbool frustumTest = all( frustumTestVec );\n\n\t\tif ( frustumTest ) {\n\n\t\t\tshadowCoord.z += shadowBias[ i ];\n\n\t\t\t#if defined( SHADOWMAP_TYPE_PCF )\n\n\t\t\t\t\t\t// Percentage-close filtering\n\t\t\t\t\t\t// (9 pixel kernel)\n\t\t\t\t\t\t// http://fabiensanglard.net/shadowmappingPCF/\n\n\t\t\t\tfloat shadow = 0.0;\n\n\t\t/*\n\t\t\t\t\t\t// nested loops breaks shader compiler / validator on some ATI cards when using OpenGL\n\t\t\t\t\t\t// must enroll loop manually\n\n\t\t\t\tfor ( float y = -1.25; y <= 1.25; y += 1.25 )\n\t\t\t\t\tfor ( float x = -1.25; x <= 1.25; x += 1.25 ) {\n\n\t\t\t\t\t\tvec4 rgbaDepth = texture2D( shadowMap[ i ], vec2( x * xPixelOffset, y * yPixelOffset ) + shadowCoord.xy );\n\n\t\t\t\t\t\t\t\t// doesn't seem to produce any noticeable visual difference compared to simple texture2D lookup\n\t\t\t\t\t\t\t\t//vec4 rgbaDepth = texture2DProj( shadowMap[ i ], vec4( vShadowCoord[ i ].w * ( vec2( x * xPixelOffset, y * yPixelOffset ) + shadowCoord.xy ), 0.05, vShadowCoord[ i ].w ) );\n\n\t\t\t\t\t\tfloat fDepth = unpackDepth( rgbaDepth );\n\n\t\t\t\t\t\tif ( fDepth < shadowCoord.z )\n\t\t\t\t\t\t\tshadow += 1.0;\n\n\t\t\t\t}\n\n\t\t\t\tshadow /= 9.0;\n\n\t\t*/\n\n\t\t\t\tconst float shadowDelta = 1.0 / 9.0;\n\n\t\t\t\tfloat xPixelOffset = 1.0 / shadowMapSize[ i ].x;\n\t\t\t\tfloat yPixelOffset = 1.0 / shadowMapSize[ i ].y;\n\n\t\t\t\tfloat dx0 = -1.25 * xPixelOffset;\n\t\t\t\tfloat dy0 = -1.25 * yPixelOffset;\n\t\t\t\tfloat dx1 = 1.25 * xPixelOffset;\n\t\t\t\tfloat dy1 = 1.25 * yPixelOffset;\n\n\t\t\t\tfDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy0 ) ) );\n\t\t\t\tif ( fDepth < shadowCoord.z ) shadow += shadowDelta;\n\n\t\t\t\tfDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy0 ) ) );\n\t\t\t\tif ( fDepth < shadowCoord.z ) shadow += shadowDelta;\n\n\t\t\t\tfDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy0 ) ) );\n\t\t\t\tif ( fDepth < shadowCoord.z ) shadow += shadowDelta;\n\n\t\t\t\tfDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, 0.0 ) ) );\n\t\t\t\tif ( fDepth < shadowCoord.z ) shadow += shadowDelta;\n\n\t\t\t\tfDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy ) );\n\t\t\t\tif ( fDepth < shadowCoord.z ) shadow += shadowDelta;\n\n\t\t\t\tfDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, 0.0 ) ) );\n\t\t\t\tif ( fDepth < shadowCoord.z ) shadow += shadowDelta;\n\n\t\t\t\tfDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy1 ) ) );\n\t\t\t\tif ( fDepth < shadowCoord.z ) shadow += shadowDelta;\n\n\t\t\t\tfDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy1 ) ) );\n\t\t\t\tif ( fDepth < shadowCoord.z ) shadow += shadowDelta;\n\n\t\t\t\tfDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy1 ) ) );\n\t\t\t\tif ( fDepth < shadowCoord.z ) shadow += shadowDelta;\n\n\t\t\t\tshadowColor = shadowColor * vec3( ( 1.0 - shadowDarkness[ i ] * shadow ) );\n\n\t\t\t#elif defined( SHADOWMAP_TYPE_PCF_SOFT )\n\n\t\t\t\t\t\t// Percentage-close filtering\n\t\t\t\t\t\t// (9 pixel kernel)\n\t\t\t\t\t\t// http://fabiensanglard.net/shadowmappingPCF/\n\n\t\t\t\tfloat shadow = 0.0;\n\n\t\t\t\tfloat xPixelOffset = 1.0 / shadowMapSize[ i ].x;\n\t\t\t\tfloat yPixelOffset = 1.0 / shadowMapSize[ i ].y;\n\n\t\t\t\tfloat dx0 = -1.0 * xPixelOffset;\n\t\t\t\tfloat dy0 = -1.0 * yPixelOffset;\n\t\t\t\tfloat dx1 = 1.0 * xPixelOffset;\n\t\t\t\tfloat dy1 = 1.0 * yPixelOffset;\n\n\t\t\t\tmat3 shadowKernel;\n\t\t\t\tmat3 depthKernel;\n\n\t\t\t\tdepthKernel[0][0] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy0 ) ) );\n\t\t\t\tdepthKernel[0][1] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, 0.0 ) ) );\n\t\t\t\tdepthKernel[0][2] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy1 ) ) );\n\t\t\t\tdepthKernel[1][0] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy0 ) ) );\n\t\t\t\tdepthKernel[1][1] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy ) );\n\t\t\t\tdepthKernel[1][2] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy1 ) ) );\n\t\t\t\tdepthKernel[2][0] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy0 ) ) );\n\t\t\t\tdepthKernel[2][1] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, 0.0 ) ) );\n\t\t\t\tdepthKernel[2][2] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy1 ) ) );\n\n\t\t\t\tvec3 shadowZ = vec3( shadowCoord.z );\n\t\t\t\tshadowKernel[0] = vec3(lessThan(depthKernel[0], shadowZ ));\n\t\t\t\tshadowKernel[0] *= vec3(0.25);\n\n\t\t\t\tshadowKernel[1] = vec3(lessThan(depthKernel[1], shadowZ ));\n\t\t\t\tshadowKernel[1] *= vec3(0.25);\n\n\t\t\t\tshadowKernel[2] = vec3(lessThan(depthKernel[2], shadowZ ));\n\t\t\t\tshadowKernel[2] *= vec3(0.25);\n\n\t\t\t\tvec2 fractionalCoord = 1.0 - fract( shadowCoord.xy * shadowMapSize[i].xy );\n\n\t\t\t\tshadowKernel[0] = mix( shadowKernel[1], shadowKernel[0], fractionalCoord.x );\n\t\t\t\tshadowKernel[1] = mix( shadowKernel[2], shadowKernel[1], fractionalCoord.x );\n\n\t\t\t\tvec4 shadowValues;\n\t\t\t\tshadowValues.x = mix( shadowKernel[0][1], shadowKernel[0][0], fractionalCoord.y );\n\t\t\t\tshadowValues.y = mix( shadowKernel[0][2], shadowKernel[0][1], fractionalCoord.y );\n\t\t\t\tshadowValues.z = mix( shadowKernel[1][1], shadowKernel[1][0], fractionalCoord.y );\n\t\t\t\tshadowValues.w = mix( shadowKernel[1][2], shadowKernel[1][1], fractionalCoord.y );\n\n\t\t\t\tshadow = dot( shadowValues, vec4( 1.0 ) );\n\n\t\t\t\tshadowColor = shadowColor * vec3( ( 1.0 - shadowDarkness[ i ] * shadow ) );\n\n\t\t\t#else\n\n\t\t\t\tvec4 rgbaDepth = texture2D( shadowMap[ i ], shadowCoord.xy );\n\t\t\t\tfloat fDepth = unpackDepth( rgbaDepth );\n\n\t\t\t\tif ( fDepth < shadowCoord.z )\n\n\t\t// spot with multiple shadows is darker\n\n\t\t\t\t\tshadowColor = shadowColor * vec3( 1.0 - shadowDarkness[ i ] );\n\n\t\t// spot with multiple shadows has the same color as single shadow spot\n\n\t\t// \t\t\t\t\tshadowColor = min( shadowColor, vec3( shadowDarkness[ i ] ) );\n\n\t\t\t#endif\n\n\t\t}\n\n\n\t\t#ifdef SHADOWMAP_DEBUG\n\n\t\t\t#ifdef SHADOWMAP_CASCADE\n\n\t\t\t\tif ( inFrustum && inFrustumCount == 1 ) gl_FragColor.xyz *= frustumColors[ i ];\n\n\t\t\t#else\n\n\t\t\t\tif ( inFrustum ) gl_FragColor.xyz *= frustumColors[ i ];\n\n\t\t\t#endif\n\n\t\t#endif\n\n\t}\n\n\t#ifdef GAMMA_OUTPUT\n\n\t\tshadowColor *= shadowColor;\n\n\t#endif\n\n\tgl_FragColor.xyz = gl_FragColor.xyz * shadowColor;\n\n#endif\n",THREE.ShaderChunk.worldpos_vertex="#if defined( USE_ENVMAP ) || defined( PHONG ) || defined( LAMBERT ) || defined ( USE_SHADOWMAP )\n\n\t#ifdef USE_SKINNING\n\n\t\tvec4 worldPosition = modelMatrix * skinned;\n\n\t#endif\n\n\t#if defined( USE_MORPHTARGETS ) && ! defined( USE_SKINNING )\n\n\t\tvec4 worldPosition = modelMatrix * vec4( morphed, 1.0 );\n\n\t#endif\n\n\t#if ! defined( USE_MORPHTARGETS ) && ! defined( USE_SKINNING )\n\n\t\tvec4 worldPosition = modelMatrix * vec4( position, 1.0 );\n\n\t#endif\n\n#endif",THREE.ShaderChunk.shadowmap_pars_fragment="#ifdef USE_SHADOWMAP\n\n\tuniform sampler2D shadowMap[ MAX_SHADOWS ];\n\tuniform vec2 shadowMapSize[ MAX_SHADOWS ];\n\n\tuniform float shadowDarkness[ MAX_SHADOWS ];\n\tuniform float shadowBias[ MAX_SHADOWS ];\n\n\tvarying vec4 vShadowCoord[ MAX_SHADOWS ];\n\n\tfloat unpackDepth( const in vec4 rgba_depth ) {\n\n\t\tconst vec4 bit_shift = vec4( 1.0 / ( 256.0 * 256.0 * 256.0 ), 1.0 / ( 256.0 * 256.0 ), 1.0 / 256.0, 1.0 );\n\t\tfloat depth = dot( rgba_depth, bit_shift );\n\t\treturn depth;\n\n\t}\n\n#endif",THREE.ShaderChunk.skinning_pars_vertex="#ifdef USE_SKINNING\n\n\tuniform mat4 bindMatrix;\n\tuniform mat4 bindMatrixInverse;\n\n\t#ifdef BONE_TEXTURE\n\n\t\tuniform sampler2D boneTexture;\n\t\tuniform int boneTextureWidth;\n\t\tuniform int boneTextureHeight;\n\n\t\tmat4 getBoneMatrix( const in float i ) {\n\n\t\t\tfloat j = i * 4.0;\n\t\t\tfloat x = mod( j, float( boneTextureWidth ) );\n\t\t\tfloat y = floor( j / float( boneTextureWidth ) );\n\n\t\t\tfloat dx = 1.0 / float( boneTextureWidth );\n\t\t\tfloat dy = 1.0 / float( boneTextureHeight );\n\n\t\t\ty = dy * ( y + 0.5 );\n\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\n\t\t\tmat4 bone = mat4( v1, v2, v3, v4 );\n\n\t\t\treturn bone;\n\n\t\t}\n\n\t#else\n\n\t\tuniform mat4 boneGlobalMatrices[ MAX_BONES ];\n\n\t\tmat4 getBoneMatrix( const in float i ) {\n\n\t\t\tmat4 bone = boneGlobalMatrices[ int(i) ];\n\t\t\treturn bone;\n\n\t\t}\n\n\t#endif\n\n#endif\n",THREE.ShaderChunk.logdepthbuf_pars_fragment="#ifdef USE_LOGDEPTHBUF\n\n\tuniform float logDepthBufFC;\n\n\t#ifdef USE_LOGDEPTHBUF_EXT\n\n\t\t#extension GL_EXT_frag_depth : enable\n\t\tvarying float vFragDepth;\n\n\t#endif\n\n#endif",THREE.ShaderChunk.alphamap_fragment="#ifdef USE_ALPHAMAP\n\n\tgl_FragColor.a *= texture2D( alphaMap, vUv ).g;\n\n#endif\n",THREE.ShaderChunk.alphamap_pars_fragment="#ifdef USE_ALPHAMAP\n\n\tuniform sampler2D alphaMap;\n\n#endif\n",THREE.UniformsUtils={merge:function(t){for(var e={},r=0;r<t.length;r++){var i=this.clone(t[r]);for(var n in i)e[n]=i[n]}return e},clone:function(t){var e={};for(var r in t)for(var i in e[r]={},t[r]){var n=t[r][i];n instanceof THREE.Color||n instanceof THREE.Vector2||n instanceof THREE.Vector3||n instanceof THREE.Vector4||n instanceof THREE.Matrix4||n instanceof THREE.Texture?e[r][i]=n.clone():n instanceof Array?e[r][i]=n.slice():e[r][i]=n}return e}},THREE.UniformsLib={common:{diffuse:{type:"c",value:new THREE.Color(15658734)},opacity:{type:"f",value:1},map:{type:"t",value:null},offsetRepeat:{type:"v4",value:new THREE.Vector4(0,0,1,1)},lightMap:{type:"t",value:null},specularMap:{type:"t",value:null},alphaMap:{type:"t",value:null},envMap:{type:"t",value:null},flipEnvMap:{type:"f",value:-1},useRefract:{type:"i",value:0},reflectivity:{type:"f",value:1},refractionRatio:{type:"f",value:.98},combine:{type:"i",value:0},morphTargetInfluences:{type:"f",value:0}},bump:{bumpMap:{type:"t",value:null},bumpScale:{type:"f",value:1}},normalmap:{normalMap:{type:"t",value:null},normalScale:{type:"v2",value:new THREE.Vector2(1,1)}},fog:{fogDensity:{type:"f",value:25e-5},fogNear:{type:"f",value:1},fogFar:{type:"f",value:2e3},fogColor:{type:"c",value:new THREE.Color(16777215)}},lights:{ambientLightColor:{type:"fv",value:[]},directionalLightDirection:{type:"fv",value:[]},directionalLightColor:{type:"fv",value:[]},hemisphereLightDirection:{type:"fv",value:[]},hemisphereLightSkyColor:{type:"fv",value:[]},hemisphereLightGroundColor:{type:"fv",value:[]},pointLightColor:{type:"fv",value:[]},pointLightPosition:{type:"fv",value:[]},pointLightDistance:{type:"fv1",value:[]},spotLightColor:{type:"fv",value:[]},spotLightPosition:{type:"fv",value:[]},spotLightDirection:{type:"fv",value:[]},spotLightDistance:{type:"fv1",value:[]},spotLightAngleCos:{type:"fv1",value:[]},spotLightExponent:{type:"fv1",value:[]}},particle:{psColor:{type:"c",value:new THREE.Color(15658734)},opacity:{type:"f",value:1},size:{type:"f",value:1},scale:{type:"f",value:1},map:{type:"t",value:null},fogDensity:{type:"f",value:25e-5},fogNear:{type:"f",value:1},fogFar:{type:"f",value:2e3},fogColor:{type:"c",value:new THREE.Color(16777215)}},shadowmap:{shadowMap:{type:"tv",value:[]},shadowMapSize:{type:"v2v",value:[]},shadowBias:{type:"fv1",value:[]},shadowDarkness:{type:"fv1",value:[]},shadowMatrix:{type:"m4v",value:[]}}},THREE.ShaderLib={basic:{uniforms:THREE.UniformsUtils.merge([THREE.UniformsLib.common,THREE.UniformsLib.fog,THREE.UniformsLib.shadowmap]),vertexShader:[THREE.ShaderChunk.map_pars_vertex,THREE.ShaderChunk.lightmap_pars_vertex,THREE.ShaderChunk.envmap_pars_vertex,THREE.ShaderChunk.color_pars_vertex,THREE.ShaderChunk.morphtarget_pars_vertex,THREE.ShaderChunk.skinning_pars_vertex,THREE.ShaderChunk.shadowmap_pars_vertex,THREE.ShaderChunk.logdepthbuf_pars_vertex,"void main() {",THREE.ShaderChunk.map_vertex,THREE.ShaderChunk.lightmap_vertex,THREE.ShaderChunk.color_vertex,THREE.ShaderChunk.skinbase_vertex,"\t#ifdef USE_ENVMAP",THREE.ShaderChunk.morphnormal_vertex,THREE.ShaderChunk.skinnormal_vertex,THREE.ShaderChunk.defaultnormal_vertex,"\t#endif",THREE.ShaderChunk.morphtarget_vertex,THREE.ShaderChunk.skinning_vertex,THREE.ShaderChunk.default_vertex,THREE.ShaderChunk.logdepthbuf_vertex,THREE.ShaderChunk.worldpos_vertex,THREE.ShaderChunk.envmap_vertex,THREE.ShaderChunk.shadowmap_vertex,"}"].join("\n"),fragmentShader:["uniform vec3 diffuse;","uniform float opacity;",THREE.ShaderChunk.color_pars_fragment,THREE.ShaderChunk.map_pars_fragment,THREE.ShaderChunk.alphamap_pars_fragment,THREE.ShaderChunk.lightmap_pars_fragment,THREE.ShaderChunk.envmap_pars_fragment,THREE.ShaderChunk.fog_pars_fragment,THREE.ShaderChunk.shadowmap_pars_fragment,THREE.ShaderChunk.specularmap_pars_fragment,THREE.ShaderChunk.logdepthbuf_pars_fragment,"void main() {","\tgl_FragColor = vec4( diffuse, opacity );",THREE.ShaderChunk.logdepthbuf_fragment,THREE.ShaderChunk.map_fragment,THREE.ShaderChunk.alphamap_fragment,THREE.ShaderChunk.alphatest_fragment,THREE.ShaderChunk.specularmap_fragment,THREE.ShaderChunk.lightmap_fragment,THREE.ShaderChunk.color_fragment,THREE.ShaderChunk.envmap_fragment,THREE.ShaderChunk.shadowmap_fragment,THREE.ShaderChunk.linear_to_gamma_fragment,THREE.ShaderChunk.fog_fragment,"}"].join("\n")},lambert:{uniforms:THREE.UniformsUtils.merge([THREE.UniformsLib.common,THREE.UniformsLib.fog,THREE.UniformsLib.lights,THREE.UniformsLib.shadowmap,{ambient:{type:"c",value:new THREE.Color(16777215)},emissive:{type:"c",value:new THREE.Color(0)},wrapRGB:{type:"v3",value:new THREE.Vector3(1,1,1)}}]),vertexShader:["#define LAMBERT","varying vec3 vLightFront;","#ifdef DOUBLE_SIDED","\tvarying vec3 vLightBack;","#endif",THREE.ShaderChunk.map_pars_vertex,THREE.ShaderChunk.lightmap_pars_vertex,THREE.ShaderChunk.envmap_pars_vertex,THREE.ShaderChunk.lights_lambert_pars_vertex,THREE.ShaderChunk.color_pars_vertex,THREE.ShaderChunk.morphtarget_pars_vertex,THREE.ShaderChunk.skinning_pars_vertex,THREE.ShaderChunk.shadowmap_pars_vertex,THREE.ShaderChunk.logdepthbuf_pars_vertex,"void main() {",THREE.ShaderChunk.map_vertex,THREE.ShaderChunk.lightmap_vertex,THREE.ShaderChunk.color_vertex,THREE.ShaderChunk.morphnormal_vertex,THREE.ShaderChunk.skinbase_vertex,THREE.ShaderChunk.skinnormal_vertex,THREE.ShaderChunk.defaultnormal_vertex,THREE.ShaderChunk.morphtarget_vertex,THREE.ShaderChunk.skinning_vertex,THREE.ShaderChunk.default_vertex,THREE.ShaderChunk.logdepthbuf_vertex,THREE.ShaderChunk.worldpos_vertex,THREE.ShaderChunk.envmap_vertex,THREE.ShaderChunk.lights_lambert_vertex,THREE.ShaderChunk.shadowmap_vertex,"}"].join("\n"),fragmentShader:["uniform float opacity;","varying vec3 vLightFront;","#ifdef DOUBLE_SIDED","\tvarying vec3 vLightBack;","#endif",THREE.ShaderChunk.color_pars_fragment,THREE.ShaderChunk.map_pars_fragment,THREE.ShaderChunk.alphamap_pars_fragment,THREE.ShaderChunk.lightmap_pars_fragment,THREE.ShaderChunk.envmap_pars_fragment,THREE.ShaderChunk.fog_pars_fragment,THREE.ShaderChunk.shadowmap_pars_fragment,THREE.ShaderChunk.specularmap_pars_fragment,THREE.ShaderChunk.logdepthbuf_pars_fragment,"void main() {","\tgl_FragColor = vec4( vec3( 1.0 ), opacity );",THREE.ShaderChunk.logdepthbuf_fragment,THREE.ShaderChunk.map_fragment,THREE.ShaderChunk.alphamap_fragment,THREE.ShaderChunk.alphatest_fragment,THREE.ShaderChunk.specularmap_fragment,"\t#ifdef DOUBLE_SIDED","\t\tif ( gl_FrontFacing )","\t\t\tgl_FragColor.xyz *= vLightFront;","\t\telse","\t\t\tgl_FragColor.xyz *= vLightBack;","\t#else","\t\tgl_FragColor.xyz *= vLightFront;","\t#endif",THREE.ShaderChunk.lightmap_fragment,THREE.ShaderChunk.color_fragment,THREE.ShaderChunk.envmap_fragment,THREE.ShaderChunk.shadowmap_fragment,THREE.ShaderChunk.linear_to_gamma_fragment,THREE.ShaderChunk.fog_fragment,"}"].join("\n")},phong:{uniforms:THREE.UniformsUtils.merge([THREE.UniformsLib.common,THREE.UniformsLib.bump,THREE.UniformsLib.normalmap,THREE.UniformsLib.fog,THREE.UniformsLib.lights,THREE.UniformsLib.shadowmap,{ambient:{type:"c",value:new THREE.Color(16777215)},emissive:{type:"c",value:new THREE.Color(0)},specular:{type:"c",value:new THREE.Color(1118481)},shininess:{type:"f",value:30},wrapRGB:{type:"v3",value:new THREE.Vector3(1,1,1)}}]),vertexShader:["#define PHONG","varying vec3 vViewPosition;","varying vec3 vNormal;",THREE.ShaderChunk.map_pars_vertex,THREE.ShaderChunk.lightmap_pars_vertex,THREE.ShaderChunk.envmap_pars_vertex,THREE.ShaderChunk.lights_phong_pars_vertex,THREE.ShaderChunk.color_pars_vertex,THREE.ShaderChunk.morphtarget_pars_vertex,THREE.ShaderChunk.skinning_pars_vertex,THREE.ShaderChunk.shadowmap_pars_vertex,THREE.ShaderChunk.logdepthbuf_pars_vertex,"void main() {",THREE.ShaderChunk.map_vertex,THREE.ShaderChunk.lightmap_vertex,THREE.ShaderChunk.color_vertex,THREE.ShaderChunk.morphnormal_vertex,THREE.ShaderChunk.skinbase_vertex,THREE.ShaderChunk.skinnormal_vertex,THREE.ShaderChunk.defaultnormal_vertex,"\tvNormal = normalize( transformedNormal );",THREE.ShaderChunk.morphtarget_vertex,THREE.ShaderChunk.skinning_vertex,THREE.ShaderChunk.default_vertex,THREE.ShaderChunk.logdepthbuf_vertex,"\tvViewPosition = -mvPosition.xyz;",THREE.ShaderChunk.worldpos_vertex,THREE.ShaderChunk.envmap_vertex,THREE.ShaderChunk.lights_phong_vertex,THREE.ShaderChunk.shadowmap_vertex,"}"].join("\n"),fragmentShader:["#define PHONG","uniform vec3 diffuse;","uniform float opacity;","uniform vec3 ambient;","uniform vec3 emissive;","uniform vec3 specular;","uniform float shininess;",THREE.ShaderChunk.color_pars_fragment,THREE.ShaderChunk.map_pars_fragment,THREE.ShaderChunk.alphamap_pars_fragment,THREE.ShaderChunk.lightmap_pars_fragment,THREE.ShaderChunk.envmap_pars_fragment,THREE.ShaderChunk.fog_pars_fragment,THREE.ShaderChunk.lights_phong_pars_fragment,THREE.ShaderChunk.shadowmap_pars_fragment,THREE.ShaderChunk.bumpmap_pars_fragment,THREE.ShaderChunk.normalmap_pars_fragment,THREE.ShaderChunk.specularmap_pars_fragment,THREE.ShaderChunk.logdepthbuf_pars_fragment,"void main() {","\tgl_FragColor = vec4( vec3( 1.0 ), opacity );",THREE.ShaderChunk.logdepthbuf_fragment,THREE.ShaderChunk.map_fragment,THREE.ShaderChunk.alphamap_fragment,THREE.ShaderChunk.alphatest_fragment,THREE.ShaderChunk.specularmap_fragment,THREE.ShaderChunk.lights_phong_fragment,THREE.ShaderChunk.lightmap_fragment,THREE.ShaderChunk.color_fragment,THREE.ShaderChunk.envmap_fragment,THREE.ShaderChunk.shadowmap_fragment,THREE.ShaderChunk.linear_to_gamma_fragment,THREE.ShaderChunk.fog_fragment,"}"].join("\n")},particle_basic:{uniforms:THREE.UniformsUtils.merge([THREE.UniformsLib.particle,THREE.UniformsLib.shadowmap]),vertexShader:["uniform float size;","uniform float scale;",THREE.ShaderChunk.color_pars_vertex,THREE.ShaderChunk.shadowmap_pars_vertex,THREE.ShaderChunk.logdepthbuf_pars_vertex,"void main() {",THREE.ShaderChunk.color_vertex,"\tvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );","\t#ifdef USE_SIZEATTENUATION","\t\tgl_PointSize = size * ( scale / length( mvPosition.xyz ) );","\t#else","\t\tgl_PointSize = size;","\t#endif","\tgl_Position = projectionMatrix * mvPosition;",THREE.ShaderChunk.logdepthbuf_vertex,THREE.ShaderChunk.worldpos_vertex,THREE.ShaderChunk.shadowmap_vertex,"}"].join("\n"),fragmentShader:["uniform vec3 psColor;","uniform float opacity;",THREE.ShaderChunk.color_pars_fragment,THREE.ShaderChunk.map_particle_pars_fragment,THREE.ShaderChunk.fog_pars_fragment,THREE.ShaderChunk.shadowmap_pars_fragment,THREE.ShaderChunk.logdepthbuf_pars_fragment,"void main() {","\tgl_FragColor = vec4( psColor, opacity );",THREE.ShaderChunk.logdepthbuf_fragment,THREE.ShaderChunk.map_particle_fragment,THREE.ShaderChunk.alphatest_fragment,THREE.ShaderChunk.color_fragment,THREE.ShaderChunk.shadowmap_fragment,THREE.ShaderChunk.fog_fragment,"}"].join("\n")},dashed:{uniforms:THREE.UniformsUtils.merge([THREE.UniformsLib.common,THREE.UniformsLib.fog,{scale:{type:"f",value:1},dashSize:{type:"f",value:1},totalSize:{type:"f",value:2}}]),vertexShader:["uniform float scale;","attribute float lineDistance;","varying float vLineDistance;",THREE.ShaderChunk.color_pars_vertex,THREE.ShaderChunk.logdepthbuf_pars_vertex,"void main() {",THREE.ShaderChunk.color_vertex,"\tvLineDistance = scale * lineDistance;","\tvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );","\tgl_Position = projectionMatrix * mvPosition;",THREE.ShaderChunk.logdepthbuf_vertex,"}"].join("\n"),fragmentShader:["uniform vec3 diffuse;","uniform float opacity;","uniform float dashSize;","uniform float totalSize;","varying float vLineDistance;",THREE.ShaderChunk.color_pars_fragment,THREE.ShaderChunk.fog_pars_fragment,THREE.ShaderChunk.logdepthbuf_pars_fragment,"void main() {","\tif ( mod( vLineDistance, totalSize ) > dashSize ) {","\t\tdiscard;","\t}","\tgl_FragColor = vec4( diffuse, opacity );",THREE.ShaderChunk.logdepthbuf_fragment,THREE.ShaderChunk.color_fragment,THREE.ShaderChunk.fog_fragment,"}"].join("\n")},depth:{uniforms:{mNear:{type:"f",value:1},mFar:{type:"f",value:2e3},opacity:{type:"f",value:1}},vertexShader:[THREE.ShaderChunk.morphtarget_pars_vertex,THREE.ShaderChunk.logdepthbuf_pars_vertex,"void main() {",THREE.ShaderChunk.morphtarget_vertex,THREE.ShaderChunk.default_vertex,THREE.ShaderChunk.logdepthbuf_vertex,"}"].join("\n"),fragmentShader:["uniform float mNear;","uniform float mFar;","uniform float opacity;",THREE.ShaderChunk.logdepthbuf_pars_fragment,"void main() {",THREE.ShaderChunk.logdepthbuf_fragment,"\t#ifdef USE_LOGDEPTHBUF_EXT","\t\tfloat depth = gl_FragDepthEXT / gl_FragCoord.w;","\t#else","\t\tfloat depth = gl_FragCoord.z / gl_FragCoord.w;","\t#endif","\tfloat color = 1.0 - smoothstep( mNear, mFar, depth );","\tgl_FragColor = vec4( vec3( color ), opacity );","}"].join("\n")},normal:{uniforms:{opacity:{type:"f",value:1}},vertexShader:["varying vec3 vNormal;",THREE.ShaderChunk.morphtarget_pars_vertex,THREE.ShaderChunk.logdepthbuf_pars_vertex,"void main() {","\tvNormal = normalize( normalMatrix * normal );",THREE.ShaderChunk.morphtarget_vertex,THREE.ShaderChunk.default_vertex,THREE.ShaderChunk.logdepthbuf_vertex,"}"].join("\n"),fragmentShader:["uniform float opacity;","varying vec3 vNormal;",THREE.ShaderChunk.logdepthbuf_pars_fragment,"void main() {","\tgl_FragColor = vec4( 0.5 * normalize( vNormal ) + 0.5, opacity );",THREE.ShaderChunk.logdepthbuf_fragment,"}"].join("\n")},normalmap:{uniforms:THREE.UniformsUtils.merge([THREE.UniformsLib.fog,THREE.UniformsLib.lights,THREE.UniformsLib.shadowmap,{enableAO:{type:"i",value:0},enableDiffuse:{type:"i",value:0},enableSpecular:{type:"i",value:0},enableReflection:{type:"i",value:0},enableDisplacement:{type:"i",value:0},tDisplacement:{type:"t",value:null},tDiffuse:{type:"t",value:null},tCube:{type:"t",value:null},tNormal:{type:"t",value:null},tSpecular:{type:"t",value:null},tAO:{type:"t",value:null},uNormalScale:{type:"v2",value:new THREE.Vector2(1,1)},uDisplacementBias:{type:"f",value:0},uDisplacementScale:{type:"f",value:1},diffuse:{type:"c",value:new THREE.Color(16777215)},specular:{type:"c",value:new THREE.Color(1118481)},ambient:{type:"c",value:new THREE.Color(16777215)},shininess:{type:"f",value:30},opacity:{type:"f",value:1},useRefract:{type:"i",value:0},refractionRatio:{type:"f",value:.98},reflectivity:{type:"f",value:.5},uOffset:{type:"v2",value:new THREE.Vector2(0,0)},uRepeat:{type:"v2",value:new THREE.Vector2(1,1)},wrapRGB:{type:"v3",value:new THREE.Vector3(1,1,1)}}]),fragmentShader:["uniform vec3 ambient;","uniform vec3 diffuse;","uniform vec3 specular;","uniform float shininess;","uniform float opacity;","uniform bool enableDiffuse;","uniform bool enableSpecular;","uniform bool enableAO;","uniform bool enableReflection;","uniform sampler2D tDiffuse;","uniform sampler2D tNormal;","uniform sampler2D tSpecular;","uniform sampler2D tAO;","uniform samplerCube tCube;","uniform vec2 uNormalScale;","uniform bool useRefract;","uniform float refractionRatio;","uniform float reflectivity;","varying vec3 vTangent;","varying vec3 vBinormal;","varying vec3 vNormal;","varying vec2 vUv;","uniform vec3 ambientLightColor;","#if MAX_DIR_LIGHTS > 0","\tuniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];","\tuniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];","#endif","#if MAX_HEMI_LIGHTS > 0","\tuniform vec3 hemisphereLightSkyColor[ MAX_HEMI_LIGHTS ];","\tuniform vec3 hemisphereLightGroundColor[ MAX_HEMI_LIGHTS ];","\tuniform vec3 hemisphereLightDirection[ MAX_HEMI_LIGHTS ];","#endif","#if MAX_POINT_LIGHTS > 0","\tuniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];","\tuniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];","\tuniform float pointLightDistance[ MAX_POINT_LIGHTS ];","#endif","#if MAX_SPOT_LIGHTS > 0","\tuniform vec3 spotLightColor[ MAX_SPOT_LIGHTS ];","\tuniform vec3 spotLightPosition[ MAX_SPOT_LIGHTS ];","\tuniform vec3 spotLightDirection[ MAX_SPOT_LIGHTS ];","\tuniform float spotLightAngleCos[ MAX_SPOT_LIGHTS ];","\tuniform float spotLightExponent[ MAX_SPOT_LIGHTS ];","\tuniform float spotLightDistance[ MAX_SPOT_LIGHTS ];","#endif","#ifdef WRAP_AROUND","\tuniform vec3 wrapRGB;","#endif","varying vec3 vWorldPosition;","varying vec3 vViewPosition;",THREE.ShaderChunk.shadowmap_pars_fragment,THREE.ShaderChunk.fog_pars_fragment,THREE.ShaderChunk.logdepthbuf_pars_fragment,"void main() {",THREE.ShaderChunk.logdepthbuf_fragment,"\tgl_FragColor = vec4( vec3( 1.0 ), opacity );","\tvec3 specularTex = vec3( 1.0 );","\tvec3 normalTex = texture2D( tNormal, vUv ).xyz * 2.0 - 1.0;","\tnormalTex.xy *= uNormalScale;","\tnormalTex = normalize( normalTex );","\tif( enableDiffuse ) {","\t\t#ifdef GAMMA_INPUT","\t\t\tvec4 texelColor = texture2D( tDiffuse, vUv );","\t\t\ttexelColor.xyz *= texelColor.xyz;","\t\t\tgl_FragColor = gl_FragColor * texelColor;","\t\t#else","\t\t\tgl_FragColor = gl_FragColor * texture2D( tDiffuse, vUv );","\t\t#endif","\t}","\tif( enableAO ) {","\t\t#ifdef GAMMA_INPUT","\t\t\tvec4 aoColor = texture2D( tAO, vUv );","\t\t\taoColor.xyz *= aoColor.xyz;","\t\t\tgl_FragColor.xyz = gl_FragColor.xyz * aoColor.xyz;","\t\t#else","\t\t\tgl_FragColor.xyz = gl_FragColor.xyz * texture2D( tAO, vUv ).xyz;","\t\t#endif","\t}",THREE.ShaderChunk.alphatest_fragment,"\tif( enableSpecular )","\t\tspecularTex = texture2D( tSpecular, vUv ).xyz;","\tmat3 tsb = mat3( normalize( vTangent ), normalize( vBinormal ), normalize( vNormal ) );","\tvec3 finalNormal = tsb * normalTex;","\t#ifdef FLIP_SIDED","\t\tfinalNormal = -finalNormal;","\t#endif","\tvec3 normal = normalize( finalNormal );","\tvec3 viewPosition = normalize( vViewPosition );","\t#if MAX_POINT_LIGHTS > 0","\t\tvec3 pointDiffuse = vec3( 0.0 );","\t\tvec3 pointSpecular = vec3( 0.0 );","\t\tfor ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {","\t\t\tvec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );","\t\t\tvec3 pointVector = lPosition.xyz + vViewPosition.xyz;","\t\t\tfloat pointDistance = 1.0;","\t\t\tif ( pointLightDistance[ i ] > 0.0 )","\t\t\t\tpointDistance = 1.0 - min( ( length( pointVector ) / pointLightDistance[ i ] ), 1.0 );","\t\t\tpointVector = normalize( pointVector );","\t\t\t#ifdef WRAP_AROUND","\t\t\t\tfloat pointDiffuseWeightFull = max( dot( normal, pointVector ), 0.0 );","\t\t\t\tfloat pointDiffuseWeightHalf = max( 0.5 * dot( normal, pointVector ) + 0.5, 0.0 );","\t\t\t\tvec3 pointDiffuseWeight = mix( vec3( pointDiffuseWeightFull ), vec3( pointDiffuseWeightHalf ), wrapRGB );","\t\t\t#else","\t\t\t\tfloat pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );","\t\t\t#endif","\t\t\tpointDiffuse += pointDistance * pointLightColor[ i ] * diffuse * pointDiffuseWeight;","\t\t\tvec3 pointHalfVector = normalize( pointVector + viewPosition );","\t\t\tfloat pointDotNormalHalf = max( dot( normal, pointHalfVector ), 0.0 );","\t\t\tfloat pointSpecularWeight = specularTex.r * max( pow( pointDotNormalHalf, shininess ), 0.0 );","\t\t\tfloat specularNormalization = ( shininess + 2.0 ) / 8.0;","\t\t\tvec3 schlick = specular + vec3( 1.0 - specular ) * pow( max( 1.0 - dot( pointVector, pointHalfVector ), 0.0 ), 5.0 );","\t\t\tpointSpecular += schlick * pointLightColor[ i ] * pointSpecularWeight * pointDiffuseWeight * pointDistance * specularNormalization;","\t\t}","\t#endif","\t#if MAX_SPOT_LIGHTS > 0","\t\tvec3 spotDiffuse = vec3( 0.0 );","\t\tvec3 spotSpecular = vec3( 0.0 );","\t\tfor ( int i = 0; i < MAX_SPOT_LIGHTS; i ++ ) {","\t\t\tvec4 lPosition = viewMatrix * vec4( spotLightPosition[ i ], 1.0 );","\t\t\tvec3 spotVector = lPosition.xyz + vViewPosition.xyz;","\t\t\tfloat spotDistance = 1.0;","\t\t\tif ( spotLightDistance[ i ] > 0.0 )","\t\t\t\tspotDistance = 1.0 - min( ( length( spotVector ) / spotLightDistance[ i ] ), 1.0 );","\t\t\tspotVector = normalize( spotVector );","\t\t\tfloat spotEffect = dot( spotLightDirection[ i ], normalize( spotLightPosition[ i ] - vWorldPosition ) );","\t\t\tif ( spotEffect > spotLightAngleCos[ i ] ) {","\t\t\t\tspotEffect = max( pow( max( spotEffect, 0.0 ), spotLightExponent[ i ] ), 0.0 );","\t\t\t\t#ifdef WRAP_AROUND","\t\t\t\t\tfloat spotDiffuseWeightFull = max( dot( normal, spotVector ), 0.0 );","\t\t\t\t\tfloat spotDiffuseWeightHalf = max( 0.5 * dot( normal, spotVector ) + 0.5, 0.0 );","\t\t\t\t\tvec3 spotDiffuseWeight = mix( vec3( spotDiffuseWeightFull ), vec3( spotDiffuseWeightHalf ), wrapRGB );","\t\t\t\t#else","\t\t\t\t\tfloat spotDiffuseWeight = max( dot( normal, spotVector ), 0.0 );","\t\t\t\t#endif","\t\t\t\tspotDiffuse += spotDistance * spotLightColor[ i ] * diffuse * spotDiffuseWeight * spotEffect;","\t\t\t\tvec3 spotHalfVector = normalize( spotVector + viewPosition );","\t\t\t\tfloat spotDotNormalHalf = max( dot( normal, spotHalfVector ), 0.0 );","\t\t\t\tfloat spotSpecularWeight = specularTex.r * max( pow( spotDotNormalHalf, shininess ), 0.0 );","\t\t\t\tfloat specularNormalization = ( shininess + 2.0 ) / 8.0;","\t\t\t\tvec3 schlick = specular + vec3( 1.0 - specular ) * pow( max( 1.0 - dot( spotVector, spotHalfVector ), 0.0 ), 5.0 );","\t\t\t\tspotSpecular += schlick * spotLightColor[ i ] * spotSpecularWeight * spotDiffuseWeight * spotDistance * specularNormalization * spotEffect;","\t\t\t}","\t\t}","\t#endif","\t#if MAX_DIR_LIGHTS > 0","\t\tvec3 dirDiffuse = vec3( 0.0 );","\t\tvec3 dirSpecular = vec3( 0.0 );","\t\tfor( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {","\t\t\tvec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );","\t\t\tvec3 dirVector = normalize( lDirection.xyz );","\t\t\t#ifdef WRAP_AROUND","\t\t\t\tfloat directionalLightWeightingFull = max( dot( normal, dirVector ), 0.0 );","\t\t\t\tfloat directionalLightWeightingHalf = max( 0.5 * dot( normal, dirVector ) + 0.5, 0.0 );","\t\t\t\tvec3 dirDiffuseWeight = mix( vec3( directionalLightWeightingFull ), vec3( directionalLightWeightingHalf ), wrapRGB );","\t\t\t#else","\t\t\t\tfloat dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );","\t\t\t#endif","\t\t\tdirDiffuse += directionalLightColor[ i ] * diffuse * dirDiffuseWeight;","\t\t\tvec3 dirHalfVector = normalize( dirVector + viewPosition );","\t\t\tfloat dirDotNormalHalf = max( dot( normal, dirHalfVector ), 0.0 );","\t\t\tfloat dirSpecularWeight = specularTex.r * max( pow( dirDotNormalHalf, shininess ), 0.0 );","\t\t\tfloat specularNormalization = ( shininess + 2.0 ) / 8.0;","\t\t\tvec3 schlick = specular + vec3( 1.0 - specular ) * pow( max( 1.0 - dot( dirVector, dirHalfVector ), 0.0 ), 5.0 );","\t\t\tdirSpecular += schlick * directionalLightColor[ i ] * dirSpecularWeight * dirDiffuseWeight * specularNormalization;","\t\t}","\t#endif","\t#if MAX_HEMI_LIGHTS > 0","\t\tvec3 hemiDiffuse = vec3( 0.0 );","\t\tvec3 hemiSpecular = vec3( 0.0 );","\t\tfor( int i = 0; i < MAX_HEMI_LIGHTS; i ++ ) {","\t\t\tvec4 lDirection = viewMatrix * vec4( hemisphereLightDirection[ i ], 0.0 );","\t\t\tvec3 lVector = normalize( lDirection.xyz );","\t\t\tfloat dotProduct = dot( normal, lVector );","\t\t\tfloat hemiDiffuseWeight = 0.5 * dotProduct + 0.5;","\t\t\tvec3 hemiColor = mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeight );","\t\t\themiDiffuse += diffuse * hemiColor;","\t\t\tvec3 hemiHalfVectorSky = normalize( lVector + viewPosition );","\t\t\tfloat hemiDotNormalHalfSky = 0.5 * dot( normal, hemiHalfVectorSky ) + 0.5;","\t\t\tfloat hemiSpecularWeightSky = specularTex.r * max( pow( max( hemiDotNormalHalfSky, 0.0 ), shininess ), 0.0 );","\t\t\tvec3 lVectorGround = -lVector;","\t\t\tvec3 hemiHalfVectorGround = normalize( lVectorGround + viewPosition );","\t\t\tfloat hemiDotNormalHalfGround = 0.5 * dot( normal, hemiHalfVectorGround ) + 0.5;","\t\t\tfloat hemiSpecularWeightGround = specularTex.r * max( pow( max( hemiDotNormalHalfGround, 0.0 ), shininess ), 0.0 );","\t\t\tfloat dotProductGround = dot( normal, lVectorGround );","\t\t\tfloat specularNormalization = ( shininess + 2.0 ) / 8.0;","\t\t\tvec3 schlickSky = specular + vec3( 1.0 - specular ) * pow( max( 1.0 - dot( lVector, hemiHalfVectorSky ), 0.0 ), 5.0 );","\t\t\tvec3 schlickGround = specular + vec3( 1.0 - specular ) * pow( max( 1.0 - dot( lVectorGround, hemiHalfVectorGround ), 0.0 ), 5.0 );","\t\t\themiSpecular += hemiColor * specularNormalization * ( schlickSky * hemiSpecularWeightSky * max( dotProduct, 0.0 ) + schlickGround * hemiSpecularWeightGround * max( dotProductGround, 0.0 ) );","\t\t}","\t#endif","\tvec3 totalDiffuse = vec3( 0.0 );","\tvec3 totalSpecular = vec3( 0.0 );","\t#if MAX_DIR_LIGHTS > 0","\t\ttotalDiffuse += dirDiffuse;","\t\ttotalSpecular += dirSpecular;","\t#endif","\t#if MAX_HEMI_LIGHTS > 0","\t\ttotalDiffuse += hemiDiffuse;","\t\ttotalSpecular += hemiSpecular;","\t#endif","\t#if MAX_POINT_LIGHTS > 0","\t\ttotalDiffuse += pointDiffuse;","\t\ttotalSpecular += pointSpecular;","\t#endif","\t#if MAX_SPOT_LIGHTS > 0","\t\ttotalDiffuse += spotDiffuse;","\t\ttotalSpecular += spotSpecular;","\t#endif","\t#ifdef METAL","\t\tgl_FragColor.xyz = gl_FragColor.xyz * ( totalDiffuse + ambientLightColor * ambient + totalSpecular );","\t#else","\t\tgl_FragColor.xyz = gl_FragColor.xyz * ( totalDiffuse + ambientLightColor * ambient ) + totalSpecular;","\t#endif","\tif ( enableReflection ) {","\t\tvec3 vReflect;","\t\tvec3 cameraToVertex = normalize( vWorldPosition - cameraPosition );","\t\tif ( useRefract ) {","\t\t\tvReflect = refract( cameraToVertex, normal, refractionRatio );","\t\t} else {","\t\t\tvReflect = reflect( cameraToVertex, normal );","\t\t}","\t\tvec4 cubeColor = textureCube( tCube, vec3( -vReflect.x, vReflect.yz ) );","\t\t#ifdef GAMMA_INPUT","\t\t\tcubeColor.xyz *= cubeColor.xyz;","\t\t#endif","\t\tgl_FragColor.xyz = mix( gl_FragColor.xyz, cubeColor.xyz, specularTex.r * reflectivity );","\t}",THREE.ShaderChunk.shadowmap_fragment,THREE.ShaderChunk.linear_to_gamma_fragment,THREE.ShaderChunk.fog_fragment,"}"].join("\n"),vertexShader:["attribute vec4 tangent;","uniform vec2 uOffset;","uniform vec2 uRepeat;","uniform bool enableDisplacement;","#ifdef VERTEX_TEXTURES","\tuniform sampler2D tDisplacement;","\tuniform float uDisplacementScale;","\tuniform float uDisplacementBias;","#endif","varying vec3 vTangent;","varying vec3 vBinormal;","varying vec3 vNormal;","varying vec2 vUv;","varying vec3 vWorldPosition;","varying vec3 vViewPosition;",THREE.ShaderChunk.skinning_pars_vertex,THREE.ShaderChunk.shadowmap_pars_vertex,THREE.ShaderChunk.logdepthbuf_pars_vertex,"void main() {",THREE.ShaderChunk.skinbase_vertex,THREE.ShaderChunk.skinnormal_vertex,"\t#ifdef USE_SKINNING","\t\tvNormal = normalize( normalMatrix * skinnedNormal.xyz );","\t\tvec4 skinnedTangent = skinMatrix * vec4( tangent.xyz, 0.0 );","\t\tvTangent = normalize( normalMatrix * skinnedTangent.xyz );","\t#else","\t\tvNormal = normalize( normalMatrix * normal );","\t\tvTangent = normalize( normalMatrix * tangent.xyz );","\t#endif","\tvBinormal = normalize( cross( vNormal, vTangent ) * tangent.w );","\tvUv = uv * uRepeat + uOffset;","\tvec3 displacedPosition;","\t#ifdef VERTEX_TEXTURES","\t\tif ( enableDisplacement ) {","\t\t\tvec3 dv = texture2D( tDisplacement, uv ).xyz;","\t\t\tfloat df = uDisplacementScale * dv.x + uDisplacementBias;","\t\t\tdisplacedPosition = position + normalize( normal ) * df;","\t\t} else {","\t\t\t#ifdef USE_SKINNING","\t\t\t\tvec4 skinVertex = bindMatrix * vec4( position, 1.0 );","\t\t\t\tvec4 skinned = vec4( 0.0 );","\t\t\t\tskinned += boneMatX * skinVertex * skinWeight.x;","\t\t\t\tskinned += boneMatY * skinVertex * skinWeight.y;","\t\t\t\tskinned += boneMatZ * skinVertex * skinWeight.z;","\t\t\t\tskinned += boneMatW * skinVertex * skinWeight.w;","\t\t\t\tskinned = bindMatrixInverse * skinned;","\t\t\t\tdisplacedPosition = skinned.xyz;","\t\t\t#else","\t\t\t\tdisplacedPosition = position;","\t\t\t#endif","\t\t}","\t#else","\t\t#ifdef USE_SKINNING","\t\t\tvec4 skinVertex = bindMatrix * vec4( position, 1.0 );","\t\t\tvec4 skinned = vec4( 0.0 );","\t\t\tskinned += boneMatX * skinVertex * skinWeight.x;","\t\t\tskinned += boneMatY * skinVertex * skinWeight.y;","\t\t\tskinned += boneMatZ * skinVertex * skinWeight.z;","\t\t\tskinned += boneMatW * skinVertex * skinWeight.w;","\t\t\tskinned = bindMatrixInverse * skinned;","\t\t\tdisplacedPosition = skinned.xyz;","\t\t#else","\t\t\tdisplacedPosition = position;","\t\t#endif","\t#endif","\tvec4 mvPosition = modelViewMatrix * vec4( displacedPosition, 1.0 );","\tvec4 worldPosition = modelMatrix * vec4( displacedPosition, 1.0 );","\tgl_Position = projectionMatrix * mvPosition;",THREE.ShaderChunk.logdepthbuf_vertex,"\tvWorldPosition = worldPosition.xyz;","\tvViewPosition = -mvPosition.xyz;","\t#ifdef USE_SHADOWMAP","\t\tfor( int i = 0; i < MAX_SHADOWS; i ++ ) {","\t\t\tvShadowCoord[ i ] = shadowMatrix[ i ] * worldPosition;","\t\t}","\t#endif","}"].join("\n")},cube:{uniforms:{tCube:{type:"t",value:null},tFlip:{type:"f",value:-1}},vertexShader:["varying vec3 vWorldPosition;",THREE.ShaderChunk.logdepthbuf_pars_vertex,"void main() {","\tvec4 worldPosition = modelMatrix * vec4( position, 1.0 );","\tvWorldPosition = worldPosition.xyz;","\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",THREE.ShaderChunk.logdepthbuf_vertex,"}"].join("\n"),fragmentShader:["uniform samplerCube tCube;","uniform float tFlip;","varying vec3 vWorldPosition;",THREE.ShaderChunk.logdepthbuf_pars_fragment,"void main() {","\tgl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );",THREE.ShaderChunk.logdepthbuf_fragment,"}"].join("\n")},depthRGBA:{uniforms:{},vertexShader:[THREE.ShaderChunk.morphtarget_pars_vertex,THREE.ShaderChunk.skinning_pars_vertex,THREE.ShaderChunk.logdepthbuf_pars_vertex,"void main() {",THREE.ShaderChunk.skinbase_vertex,THREE.ShaderChunk.morphtarget_vertex,THREE.ShaderChunk.skinning_vertex,THREE.ShaderChunk.default_vertex,THREE.ShaderChunk.logdepthbuf_vertex,"}"].join("\n"),fragmentShader:[THREE.ShaderChunk.logdepthbuf_pars_fragment,"vec4 pack_depth( const in float depth ) {","\tconst vec4 bit_shift = vec4( 256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0 );","\tconst vec4 bit_mask = vec4( 0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0 );","\tvec4 res = mod( depth * bit_shift * vec4( 255 ), vec4( 256 ) ) / vec4( 255 );","\tres -= res.xxyz * bit_mask;","\treturn res;","}","void main() {",THREE.ShaderChunk.logdepthbuf_fragment,"\t#ifdef USE_LOGDEPTHBUF_EXT","\t\tgl_FragData[ 0 ] = pack_depth( gl_FragDepthEXT );","\t#else","\t\tgl_FragData[ 0 ] = pack_depth( gl_FragCoord.z );","\t#endif","}"].join("\n")}},THREE.WebGLRenderer=function(t){console.log("THREE.WebGLRenderer",THREE.REVISION);var R=void 0!==(t=t||{}).canvas?t.canvas:document.createElement("canvas"),e=void 0!==t.context?t.context:null,_=void 0!==t.precision?t.precision:"highp",r=void 0!==t.alpha&&t.alpha,i=void 0===t.depth||t.depth,n=void 0===t.stencil||t.stencil,a=void 0!==t.antialias&&t.antialias,o=void 0===t.premultipliedAlpha||t.premultipliedAlpha,s=void 0!==t.preserveDrawingBuffer&&t.preserveDrawingBuffer,H=void 0!==t.logarithmicDepthBuffer&&t.logarithmicDepthBuffer,h=new THREE.Color(0),l=0,c=[],E={},m=[],f=[],d=[],p=[],g=[];this.domElement=R,this.context=null,this.devicePixelRatio=void 0!==t.devicePixelRatio?t.devicePixelRatio:void 0!==self.devicePixelRatio?self.devicePixelRatio:1,this.autoClear=!0,this.autoClearColor=!0,this.autoClearDepth=!0,this.autoClearStencil=!0,this.sortObjects=!0,this.gammaInput=!1,this.gammaOutput=!1,this.shadowMapEnabled=!1,this.shadowMapType=THREE.PCFShadowMap,this.shadowMapCullFace=THREE.CullFaceFront,this.shadowMapDebug=!1,this.shadowMapCascade=!1,this.maxMorphTargets=8,this.maxMorphNormals=4,this.autoScaleCubemaps=!0,this.info={memory:{programs:0,geometries:0,textures:0},render:{calls:0,vertices:0,faces:0,points:0}};var zt,V=this,b=[],M=null,v=null,w=-1,T=-1,S=null,A=0,u=-1,x=-1,y=-1,C=-1,D=-1,L=-1,F=-1,P=-1,U=null,B=null,z=null,N=null,k=0,O=0,I=R.width,G=R.height,W=0,X=0,j=new Uint8Array(16),Y=new Uint8Array(16),q=new THREE.Frustum,K=new THREE.Matrix4,Z=new THREE.Matrix4,Q=new THREE.Vector3,J=new THREE.Vector3,$=!0,tt={ambient:[0,0,0],directional:{length:0,colors:[],positions:[]},point:{length:0,colors:[],positions:[],distances:[]},spot:{length:0,colors:[],positions:[],distances:[],directions:[],anglesCos:[],exponents:[]},hemi:{length:0,skyColors:[],groundColors:[],positions:[]}};try{var et={alpha:r,depth:i,stencil:n,antialias:a,premultipliedAlpha:o,preserveDrawingBuffer:s};if(null===(zt=e||R.getContext("webgl",et)||R.getContext("experimental-webgl",et)))throw null!==R.getContext("webgl")?"Error creating WebGL context with your selected attributes.":"Error creating WebGL context."}catch(t){console.error(t)}void 0===zt.getShaderPrecisionFormat&&(zt.getShaderPrecisionFormat=function(){return{rangeMin:1,rangeMax:1,precision:1}});var rt=new THREE.WebGLExtensions(zt);rt.get("OES_texture_float"),rt.get("OES_texture_float_linear"),rt.get("OES_standard_derivatives"),H&&rt.get("EXT_frag_depth"),zt.clearColor(0,0,0,1),zt.clearDepth(1),zt.clearStencil(0),zt.enable(zt.DEPTH_TEST),zt.depthFunc(zt.LEQUAL),zt.frontFace(zt.CCW),zt.cullFace(zt.BACK),zt.enable(zt.CULL_FACE),zt.enable(zt.BLEND),zt.blendEquation(zt.FUNC_ADD),zt.blendFunc(zt.SRC_ALPHA,zt.ONE_MINUS_SRC_ALPHA),zt.viewport(k,O,I,G),zt.clearColor(h.r,h.g,h.b,l);var it,nt=(this.context=zt).getParameter(zt.MAX_TEXTURE_IMAGE_UNITS),at=zt.getParameter(zt.MAX_VERTEX_TEXTURE_IMAGE_UNITS),ot=zt.getParameter(zt.MAX_TEXTURE_SIZE),st=zt.getParameter(zt.MAX_CUBE_MAP_TEXTURE_SIZE),ht=0<at,lt=ht&&rt.get("OES_texture_float"),ut=zt.getShaderPrecisionFormat(zt.VERTEX_SHADER,zt.HIGH_FLOAT),ct=zt.getShaderPrecisionFormat(zt.VERTEX_SHADER,zt.MEDIUM_FLOAT),ft=(zt.getShaderPrecisionFormat(zt.VERTEX_SHADER,zt.LOW_FLOAT),zt.getShaderPrecisionFormat(zt.FRAGMENT_SHADER,zt.HIGH_FLOAT)),dt=zt.getShaderPrecisionFormat(zt.FRAGMENT_SHADER,zt.MEDIUM_FLOAT),pt=(zt.getShaderPrecisionFormat(zt.FRAGMENT_SHADER,zt.LOW_FLOAT),function(){if(void 0!==it)return it;if(it=[],rt.get("WEBGL_compressed_texture_pvrtc")||rt.get("WEBGL_compressed_texture_s3tc"))for(var t=zt.getParameter(zt.COMPRESSED_TEXTURE_FORMATS),e=0;e<t.length;e++)it.push(t[e]);return it}),Et=0<ut.precision&&0<ft.precision,mt=0<ct.precision&&0<dt.precision;"highp"!==_||Et||(mt?(_="mediump",console.warn("THREE.WebGLRenderer: highp not supported, using mediump.")):(_="lowp",console.warn("THREE.WebGLRenderer: highp and mediump not supported, using lowp."))),"mediump"!==_||mt||(_="lowp",console.warn("THREE.WebGLRenderer: mediump not supported, using lowp."));var gt,vt=new THREE.ShadowMapPlugin(this,c,E,m),Tt=new THREE.SpritePlugin(this,p),xt=new THREE.LensFlarePlugin(this,g);function yt(t){var e,r;if(t.__webglVertexBuffer=zt.createBuffer(),t.__webglNormalBuffer=zt.createBuffer(),t.__webglTangentBuffer=zt.createBuffer(),t.__webglColorBuffer=zt.createBuffer(),t.__webglUVBuffer=zt.createBuffer(),t.__webglUV2Buffer=zt.createBuffer(),t.__webglSkinIndicesBuffer=zt.createBuffer(),t.__webglSkinWeightsBuffer=zt.createBuffer(),t.__webglFaceBuffer=zt.createBuffer(),t.__webglLineBuffer=zt.createBuffer(),t.numMorphTargets)for(t.__webglMorphTargetsBuffers=[],e=0,r=t.numMorphTargets;e<r;e++)t.__webglMorphTargetsBuffers.push(zt.createBuffer());if(t.numMorphNormals)for(t.__webglMorphNormalsBuffers=[],e=0,r=t.numMorphNormals;e<r;e++)t.__webglMorphNormalsBuffers.push(zt.createBuffer());V.info.memory.geometries++}this.getContext=function(){return zt},this.supportsVertexTextures=function(){return ht},this.supportsFloatTextures=function(){return rt.get("OES_texture_float")},this.supportsStandardDerivatives=function(){return rt.get("OES_standard_derivatives")},this.supportsCompressedTextureS3TC=function(){return rt.get("WEBGL_compressed_texture_s3tc")},this.supportsCompressedTexturePVRTC=function(){return rt.get("WEBGL_compressed_texture_pvrtc")},this.supportsBlendMinMax=function(){return rt.get("EXT_blend_minmax")},this.getMaxAnisotropy=function(){if(void 0!==gt)return gt;var t=rt.get("EXT_texture_filter_anisotropic");return gt=null!==t?zt.getParameter(t.MAX_TEXTURE_MAX_ANISOTROPY_EXT):0},this.getPrecision=function(){return _},this.setSize=function(t,e,r){R.width=t*this.devicePixelRatio,R.height=e*this.devicePixelRatio,!1!==r&&(R.style.width=t+"px",R.style.height=e+"px"),this.setViewport(0,0,t,e)},this.setViewport=function(t,e,r,i){k=t*this.devicePixelRatio,O=e*this.devicePixelRatio,I=r*this.devicePixelRatio,G=i*this.devicePixelRatio,zt.viewport(k,O,I,G)},this.setScissor=function(t,e,r,i){zt.scissor(t*this.devicePixelRatio,e*this.devicePixelRatio,r*this.devicePixelRatio,i*this.devicePixelRatio)},this.enableScissorTest=function(t){t?zt.enable(zt.SCISSOR_TEST):zt.disable(zt.SCISSOR_TEST)},this.setClearColor=function(t,e){h.set(t),l=void 0!==e?e:1,zt.clearColor(h.r,h.g,h.b,l)},this.setClearColorHex=function(t,e){console.warn("THREE.WebGLRenderer: .setClearColorHex() is being removed. Use .setClearColor() instead."),this.setClearColor(t,e)},this.getClearColor=function(){return h},this.getClearAlpha=function(){return l},this.clear=function(t,e,r){var i=0;(void 0===t||t)&&(i|=zt.COLOR_BUFFER_BIT),(void 0===e||e)&&(i|=zt.DEPTH_BUFFER_BIT),(void 0===r||r)&&(i|=zt.STENCIL_BUFFER_BIT),zt.clear(i)},this.clearColor=function(){zt.clear(zt.COLOR_BUFFER_BIT)},this.clearDepth=function(){zt.clear(zt.DEPTH_BUFFER_BIT)},this.clearStencil=function(){zt.clear(zt.STENCIL_BUFFER_BIT)},this.clearTarget=function(t,e,r,i){this.setRenderTarget(t),this.clear(e,r,i)},this.resetGLState=function(){w=T=x=u=P=F=y=-1,$=!(S=M=null)};var Rt=function(t){t.target.traverse(function(t){t.removeEventListener("remove",Rt),function(t){t instanceof THREE.Mesh||t instanceof THREE.PointCloud||t instanceof THREE.Line?delete E[t.id]:(t instanceof THREE.ImmediateRenderObject||t.immediateRenderCallback)&&function(t,e){for(var r=t.length-1;0<=r;r--)t[r].object===e&&t.splice(r,1)}(m,t);delete t.__webglInit,delete t._modelViewMatrix,delete t._normalMatrix,delete t.__webglActive}(t)})},_t=function(t){var e=t.target;e.removeEventListener("dispose",_t),St(e)},Ht=function(t){var e=t.target;e.removeEventListener("dispose",Ht),At(e),V.info.memory.textures--},bt=function(t){var e=t.target;e.removeEventListener("dispose",bt),Ct(e),V.info.memory.textures--},Mt=function(t){var e=t.target;e.removeEventListener("dispose",Mt),Dt(e)},wt=function(t){for(var e=["__webglVertexBuffer","__webglNormalBuffer","__webglTangentBuffer","__webglColorBuffer","__webglUVBuffer","__webglUV2Buffer","__webglSkinIndicesBuffer","__webglSkinWeightsBuffer","__webglFaceBuffer","__webglLineBuffer","__webglLineDistanceBuffer"],r=0,i=e.length;r<i;r++){void 0!==t[n=e[r]]&&(zt.deleteBuffer(t[n]),delete t[n])}if(void 0!==t.__webglCustomAttributesList){for(var n in t.__webglCustomAttributesList)zt.deleteBuffer(t.__webglCustomAttributesList[n].buffer);delete t.__webglCustomAttributesList}V.info.memory.geometries--},St=function(t){if(delete t.__webglInit,t instanceof THREE.BufferGeometry){for(var e in t.attributes){var r=t.attributes[e];void 0!==r.buffer&&(zt.deleteBuffer(r.buffer),delete r.buffer)}V.info.memory.geometries--}else{var i=qt[t.id];if(void 0!==i){for(var n=0,a=i.length;n<a;n++){var o=i[n];if(void 0!==o.numMorphTargets){for(var s=0,h=o.numMorphTargets;s<h;s++)zt.deleteBuffer(o.__webglMorphTargetsBuffers[s]);delete o.__webglMorphTargetsBuffers}if(void 0!==o.numMorphNormals){for(s=0,h=o.numMorphNormals;s<h;s++)zt.deleteBuffer(o.__webglMorphNormalsBuffers[s]);delete o.__webglMorphNormalsBuffers}wt(o)}delete qt[t.id]}else wt(t)}T=-1},At=function(t){if(t.image&&t.image.__webglTextureCube)zt.deleteTexture(t.image.__webglTextureCube),delete t.image.__webglTextureCube;else{if(void 0===t.__webglInit)return;zt.deleteTexture(t.__webglTexture),delete t.__webglTexture,delete t.__webglInit}},Ct=function(t){if(t&&void 0!==t.__webglTexture){if(zt.deleteTexture(t.__webglTexture),delete t.__webglTexture,t instanceof THREE.WebGLRenderTargetCube)for(var e=0;e<6;e++)zt.deleteFramebuffer(t.__webglFramebuffer[e]),zt.deleteRenderbuffer(t.__webglRenderbuffer[e]);else zt.deleteFramebuffer(t.__webglFramebuffer),zt.deleteRenderbuffer(t.__webglRenderbuffer);delete t.__webglFramebuffer,delete t.__webglRenderbuffer}},Dt=function(t){var e=t.program.program;if(void 0!==e){var r,i,n;t.program=void 0;var a=!1;for(r=0,i=b.length;r<i;r++)if((n=b[r]).program===e){n.usedTimes--,0===n.usedTimes&&(a=!0);break}if(!0===a){var o=[];for(r=0,i=b.length;r<i;r++)(n=b[r]).program!==e&&o.push(n);b=o,zt.deleteProgram(e),V.info.memory.programs--}}};function Lt(t){var e=t.geometry,r=t.material,i=e.vertices.length;if(r.attributes)for(var n in void 0===e.__webglCustomAttributesList&&(e.__webglCustomAttributesList=[]),r.attributes){var a=r.attributes[n];if(!a.__webglInitialized||a.createUniqueBuffers){a.__webglInitialized=!0;var o=1;"v2"===a.type?o=2:"v3"===a.type?o=3:"v4"===a.type?o=4:"c"===a.type&&(o=3),a.size=o,a.array=new Float32Array(i*o),a.buffer=zt.createBuffer(),a.buffer.belongsToAttribute=n,a.needsUpdate=!0}e.__webglCustomAttributesList.push(a)}}function Ft(t,e){var r=e.geometry,i=t.faces3,n=3*i.length,a=1*i.length,o=3*i.length,s=Pt(e,t);t.__vertexArray=new Float32Array(3*n),t.__normalArray=new Float32Array(3*n),t.__colorArray=new Float32Array(3*n),t.__uvArray=new Float32Array(2*n),1<r.faceVertexUvs.length&&(t.__uv2Array=new Float32Array(2*n)),r.hasTangents&&(t.__tangentArray=new Float32Array(4*n)),e.geometry.skinWeights.length&&e.geometry.skinIndices.length&&(t.__skinIndexArray=new Float32Array(4*n),t.__skinWeightArray=new Float32Array(4*n));var h,l,u=null!==rt.get("OES_element_index_uint")&&21845<a?Uint32Array:Uint16Array;if(t.__typeArray=u,t.__faceArray=new u(3*a),t.__lineArray=new u(2*o),t.numMorphTargets)for(t.__morphTargetsArrays=[],h=0,l=t.numMorphTargets;h<l;h++)t.__morphTargetsArrays.push(new Float32Array(3*n));if(t.numMorphNormals)for(t.__morphNormalsArrays=[],h=0,l=t.numMorphNormals;h<l;h++)t.__morphNormalsArrays.push(new Float32Array(3*n));if(t.__webglFaceCount=3*a,t.__webglLineCount=2*o,s.attributes)for(var c in void 0===t.__webglCustomAttributesList&&(t.__webglCustomAttributesList=[]),s.attributes){var f=s.attributes[c],d={};for(var p in f)d[p]=f[p];if(!d.__webglInitialized||d.createUniqueBuffers){d.__webglInitialized=!0;var E=1;"v2"===d.type?E=2:"v3"===d.type?E=3:"v4"===d.type?E=4:"c"===d.type&&(E=3),d.size=E,d.array=new Float32Array(n*E),d.buffer=zt.createBuffer(),d.buffer.belongsToAttribute=c,f.needsUpdate=!0,d.__original=f}t.__webglCustomAttributesList.push(d)}t.__inittedArrays=!0}function Pt(t,e){return t.material instanceof THREE.MeshFaceMaterial?t.material.materials[e.materialIndex]:t.material}function Ut(t,e,r,i,n){if(t.__inittedArrays){var a,o,s,h,l,u,c,f,d,p,E,m,g,v,T,x,y,R,_,H,b,M,w,S,A,C,D,L,F,P,U,B,z,N,k,V,O,I,G,W,X,j,Y=(a=n)&&void 0!==a.shading&&a.shading===THREE.SmoothShading,q=0,K=0,Z=0,Q=0,J=0,$=0,tt=0,et=0,rt=0,it=0,nt=0,at=0,ot=t.__vertexArray,st=t.__uvArray,ht=t.__uv2Array,lt=t.__normalArray,ut=t.__tangentArray,ct=t.__colorArray,ft=t.__skinIndexArray,dt=t.__skinWeightArray,pt=t.__morphTargetsArrays,Et=t.__morphNormalsArrays,mt=t.__webglCustomAttributesList,gt=t.__faceArray,vt=t.__lineArray,Tt=e.geometry,xt=Tt.verticesNeedUpdate,yt=Tt.elementsNeedUpdate,Rt=Tt.uvsNeedUpdate,_t=Tt.normalsNeedUpdate,Ht=Tt.tangentsNeedUpdate,bt=Tt.colorsNeedUpdate,Mt=Tt.morphTargetsNeedUpdate,wt=Tt.vertices,St=t.faces3,At=Tt.faces,Ct=Tt.faceVertexUvs[0],Dt=Tt.faceVertexUvs[1],Lt=(Tt.colors,Tt.skinIndices),Ft=Tt.skinWeights,Pt=Tt.morphTargets,Ut=Tt.morphNormals;if(xt){for(o=0,s=St.length;o<s;o++)m=wt[(h=At[St[o]]).a],g=wt[h.b],v=wt[h.c],ot[K]=m.x,ot[K+1]=m.y,ot[K+2]=m.z,ot[K+3]=g.x,ot[K+4]=g.y,ot[K+5]=g.z,ot[K+6]=v.x,ot[K+7]=v.y,ot[K+8]=v.z,K+=9;zt.bindBuffer(zt.ARRAY_BUFFER,t.__webglVertexBuffer),zt.bufferData(zt.ARRAY_BUFFER,ot,r)}if(Mt)for(k=0,V=Pt.length;k<V;k++){for(o=nt=0,s=St.length;o<s;o++)h=At[G=St[o]],m=Pt[k].vertices[h.a],g=Pt[k].vertices[h.b],v=Pt[k].vertices[h.c],(O=pt[k])[nt]=m.x,O[nt+1]=m.y,O[nt+2]=m.z,O[nt+3]=g.x,O[nt+4]=g.y,O[nt+5]=g.z,O[nt+6]=v.x,O[nt+7]=v.y,O[nt+8]=v.z,n.morphNormals&&(Y?(R=(W=Ut[k].vertexNormals[G]).a,_=W.b,H=W.c):H=_=R=Ut[k].faceNormals[G],(I=Et[k])[nt]=R.x,I[nt+1]=R.y,I[nt+2]=R.z,I[nt+3]=_.x,I[nt+4]=_.y,I[nt+5]=_.z,I[nt+6]=H.x,I[nt+7]=H.y,I[nt+8]=H.z),nt+=9;zt.bindBuffer(zt.ARRAY_BUFFER,t.__webglMorphTargetsBuffers[k]),zt.bufferData(zt.ARRAY_BUFFER,pt[k],r),n.morphNormals&&(zt.bindBuffer(zt.ARRAY_BUFFER,t.__webglMorphNormalsBuffers[k]),zt.bufferData(zt.ARRAY_BUFFER,Et[k],r))}if(Ft.length){for(o=0,s=St.length;o<s;o++)S=Ft[(h=At[St[o]]).a],A=Ft[h.b],C=Ft[h.c],dt[it]=S.x,dt[it+1]=S.y,dt[it+2]=S.z,dt[it+3]=S.w,dt[it+4]=A.x,dt[it+5]=A.y,dt[it+6]=A.z,dt[it+7]=A.w,dt[it+8]=C.x,dt[it+9]=C.y,dt[it+10]=C.z,dt[it+11]=C.w,D=Lt[h.a],L=Lt[h.b],F=Lt[h.c],ft[it]=D.x,ft[it+1]=D.y,ft[it+2]=D.z,ft[it+3]=D.w,ft[it+4]=L.x,ft[it+5]=L.y,ft[it+6]=L.z,ft[it+7]=L.w,ft[it+8]=F.x,ft[it+9]=F.y,ft[it+10]=F.z,ft[it+11]=F.w,it+=12;0<it&&(zt.bindBuffer(zt.ARRAY_BUFFER,t.__webglSkinIndicesBuffer),zt.bufferData(zt.ARRAY_BUFFER,ft,r),zt.bindBuffer(zt.ARRAY_BUFFER,t.__webglSkinWeightsBuffer),zt.bufferData(zt.ARRAY_BUFFER,dt,r))}if(bt){for(o=0,s=St.length;o<s;o++)c=(h=At[St[o]]).vertexColors,f=h.color,3===c.length&&n.vertexColors===THREE.VertexColors?(b=c[0],M=c[1],w=c[2]):w=M=b=f,ct[rt]=b.r,ct[rt+1]=b.g,ct[rt+2]=b.b,ct[rt+3]=M.r,ct[rt+4]=M.g,ct[rt+5]=M.b,ct[rt+6]=w.r,ct[rt+7]=w.g,ct[rt+8]=w.b,rt+=9;0<rt&&(zt.bindBuffer(zt.ARRAY_BUFFER,t.__webglColorBuffer),zt.bufferData(zt.ARRAY_BUFFER,ct,r))}if(Ht&&Tt.hasTangents){for(o=0,s=St.length;o<s;o++)T=(d=(h=At[St[o]]).vertexTangents)[0],x=d[1],y=d[2],ut[tt]=T.x,ut[tt+1]=T.y,ut[tt+2]=T.z,ut[tt+3]=T.w,ut[tt+4]=x.x,ut[tt+5]=x.y,ut[tt+6]=x.z,ut[tt+7]=x.w,ut[tt+8]=y.x,ut[tt+9]=y.y,ut[tt+10]=y.z,ut[tt+11]=y.w,tt+=12;zt.bindBuffer(zt.ARRAY_BUFFER,t.__webglTangentBuffer),zt.bufferData(zt.ARRAY_BUFFER,ut,r)}if(_t){for(o=0,s=St.length;o<s;o++)if(l=(h=At[St[o]]).vertexNormals,u=h.normal,3===l.length&&Y)for(P=0;P<3;P++)B=l[P],lt[$]=B.x,lt[$+1]=B.y,lt[$+2]=B.z,$+=3;else for(P=0;P<3;P++)lt[$]=u.x,lt[$+1]=u.y,lt[$+2]=u.z,$+=3;zt.bindBuffer(zt.ARRAY_BUFFER,t.__webglNormalBuffer),zt.bufferData(zt.ARRAY_BUFFER,lt,r)}if(Rt&&Ct){for(o=0,s=St.length;o<s;o++)if(void 0!==(p=Ct[St[o]]))for(P=0;P<3;P++)z=p[P],st[Z]=z.x,st[Z+1]=z.y,Z+=2;0<Z&&(zt.bindBuffer(zt.ARRAY_BUFFER,t.__webglUVBuffer),zt.bufferData(zt.ARRAY_BUFFER,st,r))}if(Rt&&Dt){for(o=0,s=St.length;o<s;o++)if(void 0!==(E=Dt[St[o]]))for(P=0;P<3;P++)N=E[P],ht[Q]=N.x,ht[Q+1]=N.y,Q+=2;0<Q&&(zt.bindBuffer(zt.ARRAY_BUFFER,t.__webglUV2Buffer),zt.bufferData(zt.ARRAY_BUFFER,ht,r))}if(yt){for(o=0,s=St.length;o<s;o++)gt[J]=q,gt[J+1]=q+1,gt[J+2]=q+2,J+=3,vt[et]=q,vt[et+1]=q+1,vt[et+2]=q,vt[et+3]=q+2,vt[et+4]=q+1,vt[et+5]=q+2,et+=6,q+=3;zt.bindBuffer(zt.ELEMENT_ARRAY_BUFFER,t.__webglFaceBuffer),zt.bufferData(zt.ELEMENT_ARRAY_BUFFER,gt,r),zt.bindBuffer(zt.ELEMENT_ARRAY_BUFFER,t.__webglLineBuffer),zt.bufferData(zt.ELEMENT_ARRAY_BUFFER,vt,r)}if(mt)for(P=0,U=mt.length;P<U;P++)if((j=mt[P]).__original.needsUpdate){if(at=0,1===j.size){if(void 0===j.boundTo||"vertices"===j.boundTo)for(o=0,s=St.length;o<s;o++)h=At[St[o]],j.array[at]=j.value[h.a],j.array[at+1]=j.value[h.b],j.array[at+2]=j.value[h.c],at+=3;else if("faces"===j.boundTo)for(o=0,s=St.length;o<s;o++)X=j.value[St[o]],j.array[at]=X,j.array[at+1]=X,j.array[at+2]=X,at+=3}else if(2===j.size){if(void 0===j.boundTo||"vertices"===j.boundTo)for(o=0,s=St.length;o<s;o++)h=At[St[o]],m=j.value[h.a],g=j.value[h.b],v=j.value[h.c],j.array[at]=m.x,j.array[at+1]=m.y,j.array[at+2]=g.x,j.array[at+3]=g.y,j.array[at+4]=v.x,j.array[at+5]=v.y,at+=6;else if("faces"===j.boundTo)for(o=0,s=St.length;o<s;o++)v=g=m=X=j.value[St[o]],j.array[at]=m.x,j.array[at+1]=m.y,j.array[at+2]=g.x,j.array[at+3]=g.y,j.array[at+4]=v.x,j.array[at+5]=v.y,at+=6}else if(3===j.size){var Bt;if(Bt="c"===j.type?["r","g","b"]:["x","y","z"],void 0===j.boundTo||"vertices"===j.boundTo)for(o=0,s=St.length;o<s;o++)h=At[St[o]],m=j.value[h.a],g=j.value[h.b],v=j.value[h.c],j.array[at]=m[Bt[0]],j.array[at+1]=m[Bt[1]],j.array[at+2]=m[Bt[2]],j.array[at+3]=g[Bt[0]],j.array[at+4]=g[Bt[1]],j.array[at+5]=g[Bt[2]],j.array[at+6]=v[Bt[0]],j.array[at+7]=v[Bt[1]],j.array[at+8]=v[Bt[2]],at+=9;else if("faces"===j.boundTo)for(o=0,s=St.length;o<s;o++)v=g=m=X=j.value[St[o]],j.array[at]=m[Bt[0]],j.array[at+1]=m[Bt[1]],j.array[at+2]=m[Bt[2]],j.array[at+3]=g[Bt[0]],j.array[at+4]=g[Bt[1]],j.array[at+5]=g[Bt[2]],j.array[at+6]=v[Bt[0]],j.array[at+7]=v[Bt[1]],j.array[at+8]=v[Bt[2]],at+=9;else if("faceVertices"===j.boundTo)for(o=0,s=St.length;o<s;o++)m=(X=j.value[St[o]])[0],g=X[1],v=X[2],j.array[at]=m[Bt[0]],j.array[at+1]=m[Bt[1]],j.array[at+2]=m[Bt[2]],j.array[at+3]=g[Bt[0]],j.array[at+4]=g[Bt[1]],j.array[at+5]=g[Bt[2]],j.array[at+6]=v[Bt[0]],j.array[at+7]=v[Bt[1]],j.array[at+8]=v[Bt[2]],at+=9}else if(4===j.size)if(void 0===j.boundTo||"vertices"===j.boundTo)for(o=0,s=St.length;o<s;o++)h=At[St[o]],m=j.value[h.a],g=j.value[h.b],v=j.value[h.c],j.array[at]=m.x,j.array[at+1]=m.y,j.array[at+2]=m.z,j.array[at+3]=m.w,j.array[at+4]=g.x,j.array[at+5]=g.y,j.array[at+6]=g.z,j.array[at+7]=g.w,j.array[at+8]=v.x,j.array[at+9]=v.y,j.array[at+10]=v.z,j.array[at+11]=v.w,at+=12;else if("faces"===j.boundTo)for(o=0,s=St.length;o<s;o++)v=g=m=X=j.value[St[o]],j.array[at]=m.x,j.array[at+1]=m.y,j.array[at+2]=m.z,j.array[at+3]=m.w,j.array[at+4]=g.x,j.array[at+5]=g.y,j.array[at+6]=g.z,j.array[at+7]=g.w,j.array[at+8]=v.x,j.array[at+9]=v.y,j.array[at+10]=v.z,j.array[at+11]=v.w,at+=12;else if("faceVertices"===j.boundTo)for(o=0,s=St.length;o<s;o++)m=(X=j.value[St[o]])[0],g=X[1],v=X[2],j.array[at]=m.x,j.array[at+1]=m.y,j.array[at+2]=m.z,j.array[at+3]=m.w,j.array[at+4]=g.x,j.array[at+5]=g.y,j.array[at+6]=g.z,j.array[at+7]=g.w,j.array[at+8]=v.x,j.array[at+9]=v.y,j.array[at+10]=v.z,j.array[at+11]=v.w,at+=12;zt.bindBuffer(zt.ARRAY_BUFFER,j.buffer),zt.bufferData(zt.ARRAY_BUFFER,j.array,r)}i&&(delete t.__inittedArrays,delete t.__colorArray,delete t.__normalArray,delete t.__tangentArray,delete t.__uvArray,delete t.__uv2Array,delete t.__faceArray,delete t.__vertexArray,delete t.__lineArray,delete t.__skinIndexArray,delete t.__skinWeightArray)}}function Bt(t,e,r,i){for(var n=r.attributes,a=e.attributes,o=e.attributesKeys,s=0,h=o.length;s<h;s++){var l=o[s],u=a[l];if(0<=u){var c=n[l];if(void 0!==c){var f=c.itemSize;zt.bindBuffer(zt.ARRAY_BUFFER,c.buffer),kt(u),zt.vertexAttribPointer(u,f,zt.FLOAT,!1,0,i*f*4)}else void 0!==t.defaultAttributeValues&&(2===t.defaultAttributeValues[l].length?zt.vertexAttrib2fv(u,t.defaultAttributeValues[l]):3===t.defaultAttributeValues[l].length&&zt.vertexAttrib3fv(u,t.defaultAttributeValues[l]))}}Vt()}function Nt(){for(var t=0,e=j.length;t<e;t++)j[t]=0}function kt(t){j[t]=1,0===Y[t]&&(zt.enableVertexAttribArray(t),Y[t]=1)}function Vt(){for(var t=0,e=Y.length;t<e;t++)Y[t]!==j[t]&&(zt.disableVertexAttribArray(t),Y[t]=0)}function Ot(t,e){return t.material.id!==e.material.id?e.material.id-t.material.id:t.z!==e.z?e.z-t.z:t.id-e.id}function It(t,e){return t.z!==e.z?t.z-e.z:t.id-e.id}function Gt(t,e){return e[0]-t[0]}function Wt(t,e,r,i,n,a){for(var o,s=t.length-1;-1!==s;s--){var h=t[s],l=h.object,u=h.buffer;if(ae(l,e),a)o=a;else{if(!(o=h.material))continue;n&&V.setBlending(o.blending,o.blendEquation,o.blendSrc,o.blendDst),V.setDepthTest(o.depthTest),V.setDepthWrite(o.depthWrite),le(o.polygonOffset,o.polygonOffsetFactor,o.polygonOffsetUnits)}V.setMaterialFaces(o),u instanceof THREE.BufferGeometry?V.renderBufferDirect(e,r,i,o,u,l):V.renderBuffer(e,r,i,o,u,l)}}function Xt(t,e,r,i,n,a,o){for(var s,h=0,l=t.length;h<l;h++){var u=t[h],c=u.object;if(c.visible){if(o)s=o;else{if(!(s=u[e]))continue;a&&V.setBlending(s.blending,s.blendEquation,s.blendSrc,s.blendDst),V.setDepthTest(s.depthTest),V.setDepthWrite(s.depthWrite),le(s.polygonOffset,s.polygonOffsetFactor,s.polygonOffsetUnits)}V.renderImmediateObject(r,i,n,s,c)}}}function jt(t){var e=t.object.material;e.transparent?(t.transparent=e,t.opaque=null):(t.opaque=e,t.transparent=null)}function Yt(t){var e=t.object,r=t.buffer,i=e.geometry,n=e.material;if(n instanceof THREE.MeshFaceMaterial){var a=i instanceof THREE.BufferGeometry?0:r.materialIndex;n=n.materials[a],(t.material=n).transparent?d.push(t):f.push(t)}else n&&((t.material=n).transparent?d.push(t):f.push(t))}this.renderBufferImmediate=function(t,e,r){if(Nt(),t.hasPositions&&!t.__webglVertexBuffer&&(t.__webglVertexBuffer=zt.createBuffer()),t.hasNormals&&!t.__webglNormalBuffer&&(t.__webglNormalBuffer=zt.createBuffer()),t.hasUvs&&!t.__webglUvBuffer&&(t.__webglUvBuffer=zt.createBuffer()),t.hasColors&&!t.__webglColorBuffer&&(t.__webglColorBuffer=zt.createBuffer()),t.hasPositions&&(zt.bindBuffer(zt.ARRAY_BUFFER,t.__webglVertexBuffer),zt.bufferData(zt.ARRAY_BUFFER,t.positionArray,zt.DYNAMIC_DRAW),kt(e.attributes.position),zt.vertexAttribPointer(e.attributes.position,3,zt.FLOAT,!1,0,0)),t.hasNormals){if(zt.bindBuffer(zt.ARRAY_BUFFER,t.__webglNormalBuffer),r.shading===THREE.FlatShading){var i,n,a,o,s,h,l,u,c,f,d,p=3*t.count;for(d=0;d<p;d+=9)o=(f=t.normalArray)[d],h=f[d+1],u=f[d+2],s=f[d+3],l=f[d+4],c=f[d+5],i=(o+s+f[d+6])/3,n=(h+l+f[d+7])/3,a=(u+c+f[d+8])/3,f[d]=i,f[d+1]=n,f[d+2]=a,f[d+3]=i,f[d+4]=n,f[d+5]=a,f[d+6]=i,f[d+7]=n,f[d+8]=a}zt.bufferData(zt.ARRAY_BUFFER,t.normalArray,zt.DYNAMIC_DRAW),kt(e.attributes.normal),zt.vertexAttribPointer(e.attributes.normal,3,zt.FLOAT,!1,0,0)}t.hasUvs&&r.map&&(zt.bindBuffer(zt.ARRAY_BUFFER,t.__webglUvBuffer),zt.bufferData(zt.ARRAY_BUFFER,t.uvArray,zt.DYNAMIC_DRAW),kt(e.attributes.uv),zt.vertexAttribPointer(e.attributes.uv,2,zt.FLOAT,!1,0,0)),t.hasColors&&r.vertexColors!==THREE.NoColors&&(zt.bindBuffer(zt.ARRAY_BUFFER,t.__webglColorBuffer),zt.bufferData(zt.ARRAY_BUFFER,t.colorArray,zt.DYNAMIC_DRAW),kt(e.attributes.color),zt.vertexAttribPointer(e.attributes.color,3,zt.FLOAT,!1,0,0)),Vt(),zt.drawArrays(zt.TRIANGLES,0,t.count),t.count=0},this.renderBufferDirect=function(t,e,r,i,n,a){if(!1!==i.visible){var o=ee(t,e,r,i,a),s=!1,h=i.wireframe?1:0,l=16777215*n.id+2*o.id+h;if(l!==T&&(T=l,s=!0),s&&Nt(),a instanceof THREE.Mesh){var u=!0===i.wireframe?zt.LINES:zt.TRIANGLES;if(E=n.attributes.index){if(E.array instanceof Uint32Array&&rt.get("OES_element_index_uint")?(m=zt.UNSIGNED_INT,g=4):(m=zt.UNSIGNED_SHORT,g=2),0===(v=n.offsets).length)s&&(Bt(i,o,n,0),zt.bindBuffer(zt.ELEMENT_ARRAY_BUFFER,E.buffer)),zt.drawElements(u,E.array.length,m,0),V.info.render.calls++,V.info.render.vertices+=E.array.length,V.info.render.faces+=E.array.length/3;else{s=!0;for(var c=0,f=v.length;c<f;c++){var d=v[c].index;s&&(Bt(i,o,n,d),zt.bindBuffer(zt.ELEMENT_ARRAY_BUFFER,E.buffer)),zt.drawElements(u,v[c].count,m,v[c].start*g),V.info.render.calls++,V.info.render.vertices+=v[c].count,V.info.render.faces+=v[c].count/3}}}else{s&&Bt(i,o,n,0);var p=n.attributes.position;zt.drawArrays(u,0,p.array.length/3),V.info.render.calls++,V.info.render.vertices+=p.array.length/3,V.info.render.faces+=p.array.length/9}}else if(a instanceof THREE.PointCloud){s&&Bt(i,o,n,0);p=n.attributes.position;zt.drawArrays(zt.POINTS,0,p.array.length/3),V.info.render.calls++,V.info.render.points+=p.array.length/3}else if(a instanceof THREE.Line){var E;u=a.mode===THREE.LineStrip?zt.LINE_STRIP:zt.LINES;if(he(i.linewidth),E=n.attributes.index){var m,g,v;if(E.array instanceof Uint32Array?(m=zt.UNSIGNED_INT,g=4):(m=zt.UNSIGNED_SHORT,g=2),0===(v=n.offsets).length)s&&(Bt(i,o,n,0),zt.bindBuffer(zt.ELEMENT_ARRAY_BUFFER,E.buffer)),zt.drawElements(u,E.array.length,m,0),V.info.render.calls++,V.info.render.vertices+=E.array.length;else{1<v.length&&(s=!0);for(c=0,f=v.length;c<f;c++){d=v[c].index;s&&(Bt(i,o,n,d),zt.bindBuffer(zt.ELEMENT_ARRAY_BUFFER,E.buffer)),zt.drawElements(u,v[c].count,m,v[c].start*g),V.info.render.calls++,V.info.render.vertices+=v[c].count}}}else{s&&Bt(i,o,n,0);p=n.attributes.position;zt.drawArrays(u,0,p.array.length/3),V.info.render.calls++,V.info.render.points+=p.array.length/3}}}},this.renderBuffer=function(t,e,r,i,n,a){if(!1!==i.visible){var o=ee(t,e,r,i,a),s=o.attributes,h=!1,l=i.wireframe?1:0,u=16777215*n.id+2*o.id+l;if(u!==T&&(T=u,h=!0),h&&Nt(),!i.morphTargets&&0<=s.position?h&&(zt.bindBuffer(zt.ARRAY_BUFFER,n.__webglVertexBuffer),kt(s.position),zt.vertexAttribPointer(s.position,3,zt.FLOAT,!1,0,0)):a.morphTargetBase&&function(t,e,r){var i=t.program.attributes;-1!==r.morphTargetBase&&0<=i.position?(zt.bindBuffer(zt.ARRAY_BUFFER,e.__webglMorphTargetsBuffers[r.morphTargetBase]),kt(i.position),zt.vertexAttribPointer(i.position,3,zt.FLOAT,!1,0,0)):0<=i.position&&(zt.bindBuffer(zt.ARRAY_BUFFER,e.__webglVertexBuffer),kt(i.position),zt.vertexAttribPointer(i.position,3,zt.FLOAT,!1,0,0));if(r.morphTargetForcedOrder.length)for(var n=0,a=r.morphTargetForcedOrder,o=r.morphTargetInfluences;n<t.numSupportedMorphTargets&&n<a.length;)0<=i["morphTarget"+n]&&(zt.bindBuffer(zt.ARRAY_BUFFER,e.__webglMorphTargetsBuffers[a[n]]),kt(i["morphTarget"+n]),zt.vertexAttribPointer(i["morphTarget"+n],3,zt.FLOAT,!1,0,0)),0<=i["morphNormal"+n]&&t.morphNormals&&(zt.bindBuffer(zt.ARRAY_BUFFER,e.__webglMorphNormalsBuffers[a[n]]),kt(i["morphNormal"+n]),zt.vertexAttribPointer(i["morphNormal"+n],3,zt.FLOAT,!1,0,0)),r.__webglMorphTargetInfluences[n]=o[a[n]],n++;else{var s,h,l=[],o=r.morphTargetInfluences,u=o.length;for(h=0;h<u;h++)0<(s=o[h])&&l.push([s,h]);l.length>t.numSupportedMorphTargets?(l.sort(Gt),l.length=t.numSupportedMorphTargets):l.length>t.numSupportedMorphNormals?l.sort(Gt):0===l.length&&l.push([0,0]);for(var c,n=0;n<t.numSupportedMorphTargets;)l[n]?(c=l[n][1],0<=i["morphTarget"+n]&&(zt.bindBuffer(zt.ARRAY_BUFFER,e.__webglMorphTargetsBuffers[c]),kt(i["morphTarget"+n]),zt.vertexAttribPointer(i["morphTarget"+n],3,zt.FLOAT,!1,0,0)),0<=i["morphNormal"+n]&&t.morphNormals&&(zt.bindBuffer(zt.ARRAY_BUFFER,e.__webglMorphNormalsBuffers[c]),kt(i["morphNormal"+n]),zt.vertexAttribPointer(i["morphNormal"+n],3,zt.FLOAT,!1,0,0)),r.__webglMorphTargetInfluences[n]=o[c]):r.__webglMorphTargetInfluences[n]=0,n++}null!==t.program.uniforms.morphTargetInfluences&&zt.uniform1fv(t.program.uniforms.morphTargetInfluences,r.__webglMorphTargetInfluences)}(i,n,a),h){if(n.__webglCustomAttributesList)for(var c=0,f=n.__webglCustomAttributesList.length;c<f;c++){var d=n.__webglCustomAttributesList[c];0<=s[d.buffer.belongsToAttribute]&&(zt.bindBuffer(zt.ARRAY_BUFFER,d.buffer),kt(s[d.buffer.belongsToAttribute]),zt.vertexAttribPointer(s[d.buffer.belongsToAttribute],d.size,zt.FLOAT,!1,0,0))}0<=s.color&&(0<a.geometry.colors.length||0<a.geometry.faces.length?(zt.bindBuffer(zt.ARRAY_BUFFER,n.__webglColorBuffer),kt(s.color),zt.vertexAttribPointer(s.color,3,zt.FLOAT,!1,0,0)):void 0!==i.defaultAttributeValues&&zt.vertexAttrib3fv(s.color,i.defaultAttributeValues.color)),0<=s.normal&&(zt.bindBuffer(zt.ARRAY_BUFFER,n.__webglNormalBuffer),kt(s.normal),zt.vertexAttribPointer(s.normal,3,zt.FLOAT,!1,0,0)),0<=s.tangent&&(zt.bindBuffer(zt.ARRAY_BUFFER,n.__webglTangentBuffer),kt(s.tangent),zt.vertexAttribPointer(s.tangent,4,zt.FLOAT,!1,0,0)),0<=s.uv&&(a.geometry.faceVertexUvs[0]?(zt.bindBuffer(zt.ARRAY_BUFFER,n.__webglUVBuffer),kt(s.uv),zt.vertexAttribPointer(s.uv,2,zt.FLOAT,!1,0,0)):void 0!==i.defaultAttributeValues&&zt.vertexAttrib2fv(s.uv,i.defaultAttributeValues.uv)),0<=s.uv2&&(a.geometry.faceVertexUvs[1]?(zt.bindBuffer(zt.ARRAY_BUFFER,n.__webglUV2Buffer),kt(s.uv2),zt.vertexAttribPointer(s.uv2,2,zt.FLOAT,!1,0,0)):void 0!==i.defaultAttributeValues&&zt.vertexAttrib2fv(s.uv2,i.defaultAttributeValues.uv2)),i.skinning&&0<=s.skinIndex&&0<=s.skinWeight&&(zt.bindBuffer(zt.ARRAY_BUFFER,n.__webglSkinIndicesBuffer),kt(s.skinIndex),zt.vertexAttribPointer(s.skinIndex,4,zt.FLOAT,!1,0,0),zt.bindBuffer(zt.ARRAY_BUFFER,n.__webglSkinWeightsBuffer),kt(s.skinWeight),zt.vertexAttribPointer(s.skinWeight,4,zt.FLOAT,!1,0,0)),0<=s.lineDistance&&(zt.bindBuffer(zt.ARRAY_BUFFER,n.__webglLineDistanceBuffer),kt(s.lineDistance),zt.vertexAttribPointer(s.lineDistance,1,zt.FLOAT,!1,0,0))}if(Vt(),a instanceof THREE.Mesh){var p=n.__typeArray===Uint32Array?zt.UNSIGNED_INT:zt.UNSIGNED_SHORT;i.wireframe?(he(i.wireframeLinewidth),h&&zt.bindBuffer(zt.ELEMENT_ARRAY_BUFFER,n.__webglLineBuffer),zt.drawElements(zt.LINES,n.__webglLineCount,p,0)):(h&&zt.bindBuffer(zt.ELEMENT_ARRAY_BUFFER,n.__webglFaceBuffer),zt.drawElements(zt.TRIANGLES,n.__webglFaceCount,p,0)),V.info.render.calls++,V.info.render.vertices+=n.__webglFaceCount,V.info.render.faces+=n.__webglFaceCount/3}else if(a instanceof THREE.Line){var E=a.mode===THREE.LineStrip?zt.LINE_STRIP:zt.LINES;he(i.linewidth),zt.drawArrays(E,0,n.__webglLineCount),V.info.render.calls++}else a instanceof THREE.PointCloud&&(zt.drawArrays(zt.POINTS,0,n.__webglParticleCount),V.info.render.calls++,V.info.render.points+=n.__webglParticleCount)}},this.render=function(t,e,r,i){if(e instanceof THREE.Camera!=!1){var n,a=t.fog;w=T=-1,($=!(S=null))===t.autoUpdate&&t.updateMatrixWorld(),void 0===e.parent&&e.updateMatrixWorld(),t.traverse(function(t){t instanceof THREE.SkinnedMesh&&t.skeleton.update()}),e.matrixWorldInverse.getInverse(e.matrixWorld),K.multiplyMatrices(e.projectionMatrix,e.matrixWorldInverse),q.setFromMatrix(K),c.length=0,f.length=0,d.length=0,p.length=0,g.length=0,function t(e,r){if(!1===r.visible)return;if(r instanceof THREE.Scene||r instanceof THREE.Group);else if(function(t,e){void 0===t.__webglInit&&(t.__webglInit=!0,t._modelViewMatrix=new THREE.Matrix4,t._normalMatrix=new THREE.Matrix3,t.addEventListener("removed",Rt));var r=t.geometry;void 0===r||void 0===r.__webglInit&&(r.__webglInit=!0,r.addEventListener("dispose",_t),r instanceof THREE.BufferGeometry||(t instanceof THREE.Mesh?Zt(e,t,r):t instanceof THREE.Line?void 0===r.__webglVertexBuffer&&((u=r).__webglVertexBuffer=zt.createBuffer(),u.__webglColorBuffer=zt.createBuffer(),u.__webglLineDistanceBuffer=zt.createBuffer(),V.info.memory.geometries++,h=t,l=(s=r).vertices.length,s.__vertexArray=new Float32Array(3*l),s.__colorArray=new Float32Array(3*l),s.__lineDistanceArray=new Float32Array(1*l),s.__webglLineCount=l,Lt(h),r.verticesNeedUpdate=!0,r.colorsNeedUpdate=!0,r.lineDistancesNeedUpdate=!0):t instanceof THREE.PointCloud&&void 0===r.__webglVertexBuffer&&((o=r).__webglVertexBuffer=zt.createBuffer(),o.__webglColorBuffer=zt.createBuffer(),V.info.memory.geometries++,n=t,a=(i=r).vertices.length,i.__vertexArray=new Float32Array(3*a),i.__colorArray=new Float32Array(3*a),i.__sortArray=[],i.__webglParticleCount=a,Lt(n),r.verticesNeedUpdate=!0,r.colorsNeedUpdate=!0)));var i,n,a;var o;var s,h,l;var u;if(void 0===t.__webglActive)if(t.__webglActive=!0,t instanceof THREE.Mesh){if(r instanceof THREE.BufferGeometry)Qt(E,r,t);else if(r instanceof THREE.Geometry)for(var c=qt[r.id],f=0,d=c.length;f<d;f++)Qt(E,c[f],t)}else t instanceof THREE.Line||t instanceof THREE.PointCloud?Qt(E,r,t):(t instanceof THREE.ImmediateRenderObject||t.immediateRenderCallback)&&(p=t,m.push({id:null,object:p,opaque:null,transparent:null,z:0}));var p}(r,e),r instanceof THREE.Light)c.push(r);else if(r instanceof THREE.Sprite)p.push(r);else if(r instanceof THREE.LensFlare)g.push(r);else{var i=E[r.id];if(i&&(!1===r.frustumCulled||!0===q.intersectsObject(r))){!function(t,e){var r,i,n=t.geometry;if(n instanceof THREE.BufferGeometry)!function(t){for(var e=t.attributes,r=t.attributesKeys,i=0,n=r.length;i<n;i++){var a=r[i],o=e[a];if(void 0===o.buffer&&(o.buffer=zt.createBuffer(),o.needsUpdate=!0),!0===o.needsUpdate){var s="index"===a?zt.ELEMENT_ARRAY_BUFFER:zt.ARRAY_BUFFER;zt.bindBuffer(s,o.buffer),zt.bufferData(s,o.array,zt.STATIC_DRAW),o.needsUpdate=!1}}}(n);else if(t instanceof THREE.Mesh){!0===n.groupsNeedUpdate&&Zt(e,t,n);for(var a=qt[n.id],o=0,s=a.length;o<s;o++){var h=a[o];i=Pt(t,h),!0===n.groupsNeedUpdate&&Ft(h,t),r=i.attributes&&Jt(i),(n.verticesNeedUpdate||n.morphTargetsNeedUpdate||n.elementsNeedUpdate||n.uvsNeedUpdate||n.normalsNeedUpdate||n.colorsNeedUpdate||n.tangentsNeedUpdate||r)&&Ut(h,t,zt.DYNAMIC_DRAW,!n.dynamic,i)}n.verticesNeedUpdate=!1,n.morphTargetsNeedUpdate=!1,n.elementsNeedUpdate=!1,n.uvsNeedUpdate=!1,n.normalsNeedUpdate=!1,n.colorsNeedUpdate=!1,n.tangentsNeedUpdate=!1,i.attributes&&$t(i)}else t instanceof THREE.Line?(i=Pt(t,n),r=i.attributes&&Jt(i),(n.verticesNeedUpdate||n.colorsNeedUpdate||n.lineDistancesNeedUpdate||r)&&function(t,e){var r,i,n,a,o,s,h,l,u,c,f,d,p=t.vertices,E=t.colors,m=t.lineDistances,g=p.length,v=E.length,T=m.length,x=t.__vertexArray,y=t.__colorArray,R=t.__lineDistanceArray,_=t.verticesNeedUpdate,H=t.colorsNeedUpdate,b=t.lineDistancesNeedUpdate,M=t.__webglCustomAttributesList;if(_){for(r=0;r<g;r++)a=p[r],x[o=3*r]=a.x,x[o+1]=a.y,x[o+2]=a.z;zt.bindBuffer(zt.ARRAY_BUFFER,t.__webglVertexBuffer),zt.bufferData(zt.ARRAY_BUFFER,x,e)}if(H){for(i=0;i<v;i++)s=E[i],y[o=3*i]=s.r,y[o+1]=s.g,y[o+2]=s.b;zt.bindBuffer(zt.ARRAY_BUFFER,t.__webglColorBuffer),zt.bufferData(zt.ARRAY_BUFFER,y,e)}if(b){for(n=0;n<T;n++)R[n]=m[n];zt.bindBuffer(zt.ARRAY_BUFFER,t.__webglLineDistanceBuffer),zt.bufferData(zt.ARRAY_BUFFER,R,e)}if(M)for(h=0,l=M.length;h<l;h++)if((d=M[h]).needsUpdate&&(void 0===d.boundTo||"vertices"===d.boundTo)){if(o=0,c=d.value.length,1===d.size)for(u=0;u<c;u++)d.array[u]=d.value[u];else if(2===d.size)for(u=0;u<c;u++)f=d.value[u],d.array[o]=f.x,d.array[o+1]=f.y,o+=2;else if(3===d.size)if("c"===d.type)for(u=0;u<c;u++)f=d.value[u],d.array[o]=f.r,d.array[o+1]=f.g,d.array[o+2]=f.b,o+=3;else for(u=0;u<c;u++)f=d.value[u],d.array[o]=f.x,d.array[o+1]=f.y,d.array[o+2]=f.z,o+=3;else if(4===d.size)for(u=0;u<c;u++)f=d.value[u],d.array[o]=f.x,d.array[o+1]=f.y,d.array[o+2]=f.z,d.array[o+3]=f.w,o+=4;zt.bindBuffer(zt.ARRAY_BUFFER,d.buffer),zt.bufferData(zt.ARRAY_BUFFER,d.array,e)}}(n,zt.DYNAMIC_DRAW),n.verticesNeedUpdate=!1,n.colorsNeedUpdate=!1,n.lineDistancesNeedUpdate=!1,i.attributes&&$t(i)):t instanceof THREE.PointCloud&&(i=Pt(t,n),r=i.attributes&&Jt(i),(n.verticesNeedUpdate||n.colorsNeedUpdate||t.sortParticles||r)&&function(t,e,r){var i,n,a,o,s,h,l,u,c,f,d,p,E=t.vertices,m=E.length,g=t.colors,v=g.length,T=t.__vertexArray,x=t.__colorArray,y=t.__sortArray,R=t.verticesNeedUpdate,_=(t.elementsNeedUpdate,t.colorsNeedUpdate),H=t.__webglCustomAttributesList;if(r.sortParticles){for(Z.copy(K),Z.multiply(r.matrixWorld),i=0;i<m;i++)a=E[i],Q.copy(a),Q.applyProjection(Z),y[i]=[Q.z,i];for(y.sort(Gt),i=0;i<m;i++)a=E[y[i][1]],T[o=3*i]=a.x,T[o+1]=a.y,T[o+2]=a.z;for(n=0;n<v;n++)o=3*n,h=g[y[n][1]],x[o]=h.r,x[o+1]=h.g,x[o+2]=h.b;if(H)for(l=0,u=H.length;l<u;l++)if(void 0===(p=H[l]).boundTo||"vertices"===p.boundTo)if(o=0,f=p.value.length,1===p.size)for(c=0;c<f;c++)s=y[c][1],p.array[c]=p.value[s];else if(2===p.size)for(c=0;c<f;c++)s=y[c][1],d=p.value[s],p.array[o]=d.x,p.array[o+1]=d.y,o+=2;else if(3===p.size)if("c"===p.type)for(c=0;c<f;c++)s=y[c][1],d=p.value[s],p.array[o]=d.r,p.array[o+1]=d.g,p.array[o+2]=d.b,o+=3;else for(c=0;c<f;c++)s=y[c][1],d=p.value[s],p.array[o]=d.x,p.array[o+1]=d.y,p.array[o+2]=d.z,o+=3;else if(4===p.size)for(c=0;c<f;c++)s=y[c][1],d=p.value[s],p.array[o]=d.x,p.array[o+1]=d.y,p.array[o+2]=d.z,p.array[o+3]=d.w,o+=4}else{if(R)for(i=0;i<m;i++)a=E[i],T[o=3*i]=a.x,T[o+1]=a.y,T[o+2]=a.z;if(_)for(n=0;n<v;n++)h=g[n],x[o=3*n]=h.r,x[o+1]=h.g,x[o+2]=h.b;if(H)for(l=0,u=H.length;l<u;l++)if((p=H[l]).needsUpdate&&(void 0===p.boundTo||"vertices"===p.boundTo))if(f=p.value.length,o=0,1===p.size)for(c=0;c<f;c++)p.array[c]=p.value[c];else if(2===p.size)for(c=0;c<f;c++)d=p.value[c],p.array[o]=d.x,p.array[o+1]=d.y,o+=2;else if(3===p.size)if("c"===p.type)for(c=0;c<f;c++)d=p.value[c],p.array[o]=d.r,p.array[o+1]=d.g,p.array[o+2]=d.b,o+=3;else for(c=0;c<f;c++)d=p.value[c],p.array[o]=d.x,p.array[o+1]=d.y,p.array[o+2]=d.z,o+=3;else if(4===p.size)for(c=0;c<f;c++)d=p.value[c],p.array[o]=d.x,p.array[o+1]=d.y,p.array[o+2]=d.z,p.array[o+3]=d.w,o+=4}if((R||r.sortParticles)&&(zt.bindBuffer(zt.ARRAY_BUFFER,t.__webglVertexBuffer),zt.bufferData(zt.ARRAY_BUFFER,T,e)),(_||r.sortParticles)&&(zt.bindBuffer(zt.ARRAY_BUFFER,t.__webglColorBuffer),zt.bufferData(zt.ARRAY_BUFFER,x,e)),H)for(l=0,u=H.length;l<u;l++)((p=H[l]).needsUpdate||r.sortParticles)&&(zt.bindBuffer(zt.ARRAY_BUFFER,p.buffer),zt.bufferData(zt.ARRAY_BUFFER,p.array,e))}(n,zt.DYNAMIC_DRAW,t),n.verticesNeedUpdate=!1,n.colorsNeedUpdate=!1,i.attributes&&$t(i))}(r,e);for(var n=0,a=i.length;n<a;n++){var o=i[n];Yt(o),(o.render=!0)===V.sortObjects&&(null!==r.renderDepth?o.z=r.renderDepth:(Q.setFromMatrixPosition(r.matrixWorld),Q.applyProjection(K),o.z=Q.z))}}}for(var n=0,a=r.children.length;n<a;n++)t(e,r.children[n])}(t,t),!0===V.sortObjects&&(f.sort(Ot),d.sort(It)),vt.render(t,e),V.info.render.calls=0,V.info.render.vertices=0,V.info.render.faces=0,V.info.render.points=0,this.setRenderTarget(r),(this.autoClear||i)&&this.clear(this.autoClearColor,this.autoClearDepth,this.autoClearStencil);for(var o=0,s=m.length;o<s;o++){var h=m[o],l=h.object;l.visible&&(ae(l,e),jt(h))}if(t.overrideMaterial){var u=t.overrideMaterial;this.setBlending(u.blending,u.blendEquation,u.blendSrc,u.blendDst),this.setDepthTest(u.depthTest),this.setDepthWrite(u.depthWrite),le(u.polygonOffset,u.polygonOffsetFactor,u.polygonOffsetUnits),Wt(f,e,c,a,!0,u),Wt(d,e,c,a,!0,u),Xt(m,"",e,c,a,!1,u)}else{u=null;this.setBlending(THREE.NoBlending),Wt(f,e,c,a,!1,u),Xt(m,"opaque",e,c,a,!1,u),Wt(d,e,c,a,!0,u),Xt(m,"transparent",e,c,a,!0,u)}Tt.render(t,e),xt.render(t,e,W,X),r&&r.generateMipmaps&&r.minFilter!==THREE.NearestFilter&&r.minFilter!==THREE.LinearFilter&&((n=r)instanceof THREE.WebGLRenderTargetCube?(zt.bindTexture(zt.TEXTURE_CUBE_MAP,n.__webglTexture),zt.generateMipmap(zt.TEXTURE_CUBE_MAP),zt.bindTexture(zt.TEXTURE_CUBE_MAP,null)):(zt.bindTexture(zt.TEXTURE_2D,n.__webglTexture),zt.generateMipmap(zt.TEXTURE_2D),zt.bindTexture(zt.TEXTURE_2D,null))),this.setDepthTest(!0),this.setDepthWrite(!0)}else console.error("THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.")},this.renderImmediateObject=function(t,e,r,i,n){var a=ee(t,e,r,i,n);T=-1,V.setMaterialFaces(i),n.immediateRenderCallback?n.immediateRenderCallback(a,zt,q):n.render(function(t){V.renderBufferImmediate(t,a,i)})};var qt={},Kt=0;function Zt(t,e,r){var i=e.material,n=!1;void 0!==qt[r.id]&&!0!==r.groupsNeedUpdate||(delete E[e.id],qt[r.id]=function(t,e){for(var r,i,n=rt.get("OES_element_index_uint")?4294967296:65535,a={},o=t.morphTargets.length,s=t.morphNormals.length,h={},l=[],u=0,c=t.faces.length;u<c;u++){var f=t.faces[u],d=e?f.materialIndex:0;d in a||(a[d]={hash:d,counter:0}),(r=a[d].hash+"_"+a[d].counter)in h||(i={id:Kt++,faces3:[],materialIndex:d,vertices:0,numMorphTargets:o,numMorphNormals:s},h[r]=i,l.push(i)),h[r].vertices+3>n&&(a[d].counter+=1,(r=a[d].hash+"_"+a[d].counter)in h||(i={id:Kt++,faces3:[],materialIndex:d,vertices:0,numMorphTargets:o,numMorphNormals:s},h[r]=i,l.push(i))),h[r].faces3.push(u),h[r].vertices+=3}return l}(r,i instanceof THREE.MeshFaceMaterial),r.groupsNeedUpdate=!1);for(var a=qt[r.id],o=0,s=a.length;o<s;o++){var h=a[o];void 0===h.__webglVertexBuffer?(yt(h),Ft(h,e),r.verticesNeedUpdate=!0,r.morphTargetsNeedUpdate=!0,r.elementsNeedUpdate=!0,r.uvsNeedUpdate=!0,r.normalsNeedUpdate=!0,r.tangentsNeedUpdate=!0,n=r.colorsNeedUpdate=!0):n=!1,(n||void 0===e.__webglActive)&&Qt(E,h,e)}e.__webglActive=!0}function Qt(t,e,r){var i=r.id;t[i]=t[i]||[],t[i].push({id:i,buffer:e,object:r,material:null,z:0})}function Jt(t){for(var e in t.attributes)if(t.attributes[e].needsUpdate)return!0;return!1}function $t(t){for(var e in t.attributes)t.attributes[e].needsUpdate=!1}function te(t,e,r,i){var n;if(t.addEventListener("dispose",Mt),t instanceof THREE.MeshDepthMaterial?n="depth":t instanceof THREE.MeshNormalMaterial?n="normal":t instanceof THREE.MeshBasicMaterial?n="basic":t instanceof THREE.MeshLambertMaterial?n="lambert":t instanceof THREE.MeshPhongMaterial?n="phong":t instanceof THREE.LineBasicMaterial?n="basic":t instanceof THREE.LineDashedMaterial?n="dashed":t instanceof THREE.PointCloudMaterial&&(n="particle_basic"),n){var a=THREE.ShaderLib[n];t.__webglShader={uniforms:THREE.UniformsUtils.clone(a.uniforms),vertexShader:a.vertexShader,fragmentShader:a.fragmentShader}}else t.__webglShader={uniforms:t.uniforms,vertexShader:t.vertexShader,fragmentShader:t.fragmentShader};var o=function(t){for(var e=0,r=0,i=0,n=0,a=0,o=t.length;a<o;a++){var s=t[a];s.onlyShadow||!1===s.visible||(s instanceof THREE.DirectionalLight&&e++,s instanceof THREE.PointLight&&r++,s instanceof THREE.SpotLight&&i++,s instanceof THREE.HemisphereLight&&n++)}return{directional:e,point:r,spot:i,hemi:n}}(e),s=function(t){for(var e=0,r=0,i=t.length;r<i;r++){var n=t[r];n.castShadow&&(n instanceof THREE.SpotLight&&e++,n instanceof THREE.DirectionalLight&&!n.shadowCascade&&e++)}return e}(e),h=function(t){{if(lt&&t&&t.skeleton&&t.skeleton.useVertexTexture)return 1024;var e=zt.getParameter(zt.MAX_VERTEX_UNIFORM_VECTORS),r=Math.floor((e-20)/4),i=r;return void 0!==t&&t instanceof THREE.SkinnedMesh&&(i=Math.min(t.skeleton.bones.length,i))<t.skeleton.bones.length&&console.warn("WebGLRenderer: too many bones - "+t.skeleton.bones.length+", this GPU supports just "+i+" (try OpenGL instead of ANGLE)"),i}}(i),l={precision:_,supportsVertexTextures:ht,map:!!t.map,envMap:!!t.envMap,lightMap:!!t.lightMap,bumpMap:!!t.bumpMap,normalMap:!!t.normalMap,specularMap:!!t.specularMap,alphaMap:!!t.alphaMap,vertexColors:t.vertexColors,fog:r,useFog:t.fog,fogExp:r instanceof THREE.FogExp2,sizeAttenuation:t.sizeAttenuation,logarithmicDepthBuffer:H,skinning:t.skinning,maxBones:h,useVertexTexture:lt&&i&&i.skeleton&&i.skeleton.useVertexTexture,morphTargets:t.morphTargets,morphNormals:t.morphNormals,maxMorphTargets:V.maxMorphTargets,maxMorphNormals:V.maxMorphNormals,maxDirLights:o.directional,maxPointLights:o.point,maxSpotLights:o.spot,maxHemiLights:o.hemi,maxShadows:s,shadowMapEnabled:V.shadowMapEnabled&&i.receiveShadow&&0<s,shadowMapType:V.shadowMapType,shadowMapDebug:V.shadowMapDebug,shadowMapCascade:V.shadowMapCascade,alphaTest:t.alphaTest,metal:t.metal,wrapAround:t.wrapAround,doubleSided:t.side===THREE.DoubleSide,flipSided:t.side===THREE.BackSide},u=[];if(n?u.push(n):(u.push(t.fragmentShader),u.push(t.vertexShader)),void 0!==t.defines)for(var c in t.defines)u.push(c),u.push(t.defines[c]);for(var c in l)u.push(c),u.push(l[c]);for(var f,d=u.join(),p=0,E=b.length;p<E;p++){var m=b[p];if(m.code===d){(f=m).usedTimes++;break}}void 0===f&&(f=new THREE.WebGLProgram(V,d,t,l),b.push(f),V.info.memory.programs=b.length);var g=(t.program=f).attributes;if(t.morphTargets)for(var v="morphTarget",T=t.numSupportedMorphTargets=0;T<V.maxMorphTargets;T++)0<=g[v+T]&&t.numSupportedMorphTargets++;if(t.morphNormals){v="morphNormal";for(T=t.numSupportedMorphNormals=0;T<V.maxMorphNormals;T++)0<=g[v+T]&&t.numSupportedMorphNormals++}for(var x in t.uniformsList=[],t.__webglShader.uniforms){var y=t.program.uniforms[x];y&&t.uniformsList.push([t.__webglShader.uniforms[x],y])}}function ee(t,e,r,i,n){A=0,i.needsUpdate&&(i.program&&Dt(i),te(i,e,r,n),i.needsUpdate=!1),i.morphTargets&&(n.__webglMorphTargetInfluences||(n.__webglMorphTargetInfluences=new Float32Array(V.maxMorphTargets)));var a,o,s,h,l,u,c,f,d,p,E=!1,m=!1,g=!1,v=i.program,T=v.uniforms,x=i.__webglShader.uniforms;if(v.id!==M&&(zt.useProgram(v.program),M=v.id,g=m=E=!0),i.id!==w&&(-1===w&&(g=!0),w=i.id,m=!0),(E||t!==S)&&(zt.uniformMatrix4fv(T.projectionMatrix,!1,t.projectionMatrix.elements),H&&zt.uniform1f(T.logDepthBufFC,2/(Math.log(t.far+1)/Math.LN2)),t!==S&&(S=t),(i instanceof THREE.ShaderMaterial||i instanceof THREE.MeshPhongMaterial||i.envMap)&&null!==T.cameraPosition&&(Q.setFromMatrixPosition(t.matrixWorld),zt.uniform3f(T.cameraPosition,Q.x,Q.y,Q.z)),(i instanceof THREE.MeshPhongMaterial||i instanceof THREE.MeshLambertMaterial||i instanceof THREE.ShaderMaterial||i.skinning)&&null!==T.viewMatrix&&zt.uniformMatrix4fv(T.viewMatrix,!1,t.matrixWorldInverse.elements)),i.skinning)if(n.bindMatrix&&null!==T.bindMatrix&&zt.uniformMatrix4fv(T.bindMatrix,!1,n.bindMatrix.elements),n.bindMatrixInverse&&null!==T.bindMatrixInverse&&zt.uniformMatrix4fv(T.bindMatrixInverse,!1,n.bindMatrixInverse.elements),lt&&n.skeleton&&n.skeleton.useVertexTexture){if(null!==T.boneTexture){var y=ne();zt.uniform1i(T.boneTexture,y),V.setTexture(n.skeleton.boneTexture,y)}null!==T.boneTextureWidth&&zt.uniform1i(T.boneTextureWidth,n.skeleton.boneTextureWidth),null!==T.boneTextureHeight&&zt.uniform1i(T.boneTextureHeight,n.skeleton.boneTextureHeight)}else n.skeleton&&n.skeleton.boneMatrices&&null!==T.boneGlobalMatrices&&zt.uniformMatrix4fv(T.boneGlobalMatrices,!1,n.skeleton.boneMatrices);return m&&(r&&i.fog&&(f=r,(c=x).fogColor.value=f.color,f instanceof THREE.Fog?(c.fogNear.value=f.near,c.fogFar.value=f.far):f instanceof THREE.FogExp2&&(c.fogDensity.value=f.density)),(i instanceof THREE.MeshPhongMaterial||i instanceof THREE.MeshLambertMaterial||i.lights)&&($&&(g=!0,function(t){var e,r,i,n,a,o,s,h,l,u=0,c=0,f=0,d=tt,p=d.directional.colors,E=d.directional.positions,m=d.point.colors,g=d.point.positions,v=d.point.distances,T=d.spot.colors,x=d.spot.positions,y=d.spot.distances,R=d.spot.directions,_=d.spot.anglesCos,H=d.spot.exponents,b=d.hemi.skyColors,M=d.hemi.groundColors,w=d.hemi.positions,S=0,A=0,C=0,D=0,L=0,F=0,P=0,U=0,B=0,z=0,N=0,k=0;for(e=0,r=t.length;e<r;e++)if(!(i=t[e]).onlyShadow)if(n=i.color,s=i.intensity,l=i.distance,i instanceof THREE.AmbientLight){if(!i.visible)continue;V.gammaInput?(u+=n.r*n.r,c+=n.g*n.g,f+=n.b*n.b):(u+=n.r,c+=n.g,f+=n.b)}else if(i instanceof THREE.DirectionalLight){if(L+=1,!i.visible)continue;J.setFromMatrixPosition(i.matrixWorld),Q.setFromMatrixPosition(i.target.matrixWorld),J.sub(Q),J.normalize(),E[B=3*S]=J.x,E[B+1]=J.y,E[B+2]=J.z,V.gammaInput?oe(p,B,n,s*s):se(p,B,n,s),S+=1}else if(i instanceof THREE.PointLight){if(F+=1,!i.visible)continue;z=3*A,V.gammaInput?oe(m,z,n,s*s):se(m,z,n,s),Q.setFromMatrixPosition(i.matrixWorld),g[z]=Q.x,g[z+1]=Q.y,g[z+2]=Q.z,v[A]=l,A+=1}else if(i instanceof THREE.SpotLight){if(P+=1,!i.visible)continue;N=3*C,V.gammaInput?oe(T,N,n,s*s):se(T,N,n,s),J.setFromMatrixPosition(i.matrixWorld),x[N]=J.x,x[N+1]=J.y,x[N+2]=J.z,y[C]=l,Q.setFromMatrixPosition(i.target.matrixWorld),J.sub(Q),J.normalize(),R[N]=J.x,R[N+1]=J.y,R[N+2]=J.z,_[C]=Math.cos(i.angle),H[C]=i.exponent,C+=1}else if(i instanceof THREE.HemisphereLight){if(U+=1,!i.visible)continue;J.setFromMatrixPosition(i.matrixWorld),J.normalize(),w[k=3*D]=J.x,w[k+1]=J.y,w[k+2]=J.z,a=i.color,o=i.groundColor,V.gammaInput?(oe(b,k,a,h=s*s),oe(M,k,o,h)):(se(b,k,a,s),se(M,k,o,s)),D+=1}for(e=3*S,r=Math.max(p.length,3*L);e<r;e++)p[e]=0;for(e=3*A,r=Math.max(m.length,3*F);e<r;e++)m[e]=0;for(e=3*C,r=Math.max(T.length,3*P);e<r;e++)T[e]=0;for(e=3*D,r=Math.max(b.length,3*U);e<r;e++)b[e]=0;for(e=3*D,r=Math.max(M.length,3*U);e<r;e++)M[e]=0;d.directional.length=S,d.point.length=A,d.spot.length=C,d.hemi.length=D,d.ambient[0]=u,d.ambient[1]=c,d.ambient[2]=f}(e),$=!1),g?(u=tt,(l=x).ambientLightColor.value=u.ambient,l.directionalLightColor.value=u.directional.colors,l.directionalLightDirection.value=u.directional.positions,l.pointLightColor.value=u.point.colors,l.pointLightPosition.value=u.point.positions,l.pointLightDistance.value=u.point.distances,l.spotLightColor.value=u.spot.colors,l.spotLightPosition.value=u.spot.positions,l.spotLightDistance.value=u.spot.distances,l.spotLightDirection.value=u.spot.directions,l.spotLightAngleCos.value=u.spot.anglesCos,l.spotLightExponent.value=u.spot.exponents,l.hemisphereLightSkyColor.value=u.hemi.skyColors,l.hemisphereLightGroundColor.value=u.hemi.groundColors,l.hemisphereLightDirection.value=u.hemi.positions,ie(x,!0)):ie(x,!1)),(i instanceof THREE.MeshBasicMaterial||i instanceof THREE.MeshLambertMaterial||i instanceof THREE.MeshPhongMaterial)&&function(t,e){t.opacity.value=e.opacity,V.gammaInput?t.diffuse.value.copyGammaToLinear(e.color):t.diffuse.value=e.color;t.map.value=e.map,t.lightMap.value=e.lightMap,t.specularMap.value=e.specularMap,t.alphaMap.value=e.alphaMap,e.bumpMap&&(t.bumpMap.value=e.bumpMap,t.bumpScale.value=e.bumpScale);e.normalMap&&(t.normalMap.value=e.normalMap,t.normalScale.value.copy(e.normalScale));var r;e.map?r=e.map:e.specularMap?r=e.specularMap:e.normalMap?r=e.normalMap:e.bumpMap?r=e.bumpMap:e.alphaMap&&(r=e.alphaMap);if(void 0!==r){var i=r.offset,n=r.repeat;t.offsetRepeat.value.set(i.x,i.y,n.x,n.y)}t.envMap.value=e.envMap,t.flipEnvMap.value=e.envMap instanceof THREE.WebGLRenderTargetCube?1:-1,V.gammaInput,t.reflectivity.value=e.reflectivity;t.refractionRatio.value=e.refractionRatio,t.combine.value=e.combine,t.useRefract.value=e.envMap&&e.envMap.mapping instanceof THREE.CubeRefractionMapping}(x,i),i instanceof THREE.LineBasicMaterial?re(x,i):i instanceof THREE.LineDashedMaterial?(re(x,i),h=i,(s=x).dashSize.value=h.dashSize,s.totalSize.value=h.dashSize+h.gapSize,s.scale.value=h.scale):i instanceof THREE.PointCloudMaterial?(o=i,(a=x).psColor.value=o.color,a.opacity.value=o.opacity,a.size.value=o.size,a.scale.value=R.height/2,a.map.value=o.map):i instanceof THREE.MeshPhongMaterial?function(t,e){t.shininess.value=e.shininess,V.gammaInput?(t.ambient.value.copyGammaToLinear(e.ambient),t.emissive.value.copyGammaToLinear(e.emissive),t.specular.value.copyGammaToLinear(e.specular)):(t.ambient.value=e.ambient,t.emissive.value=e.emissive,t.specular.value=e.specular);e.wrapAround&&t.wrapRGB.value.copy(e.wrapRGB)}(x,i):i instanceof THREE.MeshLambertMaterial?function(t,e){V.gammaInput?(t.ambient.value.copyGammaToLinear(e.ambient),t.emissive.value.copyGammaToLinear(e.emissive)):(t.ambient.value=e.ambient,t.emissive.value=e.emissive);e.wrapAround&&t.wrapRGB.value.copy(e.wrapRGB)}(x,i):i instanceof THREE.MeshDepthMaterial?(x.mNear.value=t.near,x.mFar.value=t.far,x.opacity.value=i.opacity):i instanceof THREE.MeshNormalMaterial&&(x.opacity.value=i.opacity),n.receiveShadow&&!i._shadowPass&&function(t,e){if(t.shadowMatrix)for(var r=0,i=0,n=e.length;i<n;i++){var a=e[i];a.castShadow&&((a instanceof THREE.SpotLight||a instanceof THREE.DirectionalLight&&!a.shadowCascade)&&(t.shadowMap.value[r]=a.shadowMap,t.shadowMapSize.value[r]=a.shadowMapSize,t.shadowMatrix.value[r]=a.shadowMatrix,t.shadowDarkness.value[r]=a.shadowDarkness,t.shadowBias.value[r]=a.shadowBias,r++))}}(x,e),function(t){for(var e,r,i,n=0,a=t.length;n<a;n++){var o=t[n][0];if(!1!==o.needsUpdate){var s=o.type,h=o.value,l=t[n][1];switch(s){case"1i":zt.uniform1i(l,h);break;case"1f":zt.uniform1f(l,h);break;case"2f":zt.uniform2f(l,h[0],h[1]);break;case"3f":zt.uniform3f(l,h[0],h[1],h[2]);break;case"4f":zt.uniform4f(l,h[0],h[1],h[2],h[3]);break;case"1iv":zt.uniform1iv(l,h);break;case"3iv":zt.uniform3iv(l,h);break;case"1fv":zt.uniform1fv(l,h);break;case"2fv":zt.uniform2fv(l,h);break;case"3fv":zt.uniform3fv(l,h);break;case"4fv":zt.uniform4fv(l,h);break;case"Matrix3fv":zt.uniformMatrix3fv(l,!1,h);break;case"Matrix4fv":zt.uniformMatrix4fv(l,!1,h);break;case"i":zt.uniform1i(l,h);break;case"f":zt.uniform1f(l,h);break;case"v2":zt.uniform2f(l,h.x,h.y);break;case"v3":zt.uniform3f(l,h.x,h.y,h.z);break;case"v4":zt.uniform4f(l,h.x,h.y,h.z,h.w);break;case"c":zt.uniform3f(l,h.r,h.g,h.b);break;case"iv1":zt.uniform1iv(l,h);break;case"iv":zt.uniform3iv(l,h);break;case"fv1":zt.uniform1fv(l,h);break;case"fv":zt.uniform3fv(l,h);break;case"v2v":void 0===o._array&&(o._array=new Float32Array(2*h.length));for(var u=0,c=h.length;u<c;u++)i=2*u,o._array[i]=h[u].x,o._array[i+1]=h[u].y;zt.uniform2fv(l,o._array);break;case"v3v":void 0===o._array&&(o._array=new Float32Array(3*h.length));for(var u=0,c=h.length;u<c;u++)i=3*u,o._array[i]=h[u].x,o._array[i+1]=h[u].y,o._array[i+2]=h[u].z;zt.uniform3fv(l,o._array);break;case"v4v":void 0===o._array&&(o._array=new Float32Array(4*h.length));for(var u=0,c=h.length;u<c;u++)i=4*u,o._array[i]=h[u].x,o._array[i+1]=h[u].y,o._array[i+2]=h[u].z,o._array[i+3]=h[u].w;zt.uniform4fv(l,o._array);break;case"m3":zt.uniformMatrix3fv(l,!1,h.elements);break;case"m3v":void 0===o._array&&(o._array=new Float32Array(9*h.length));for(var u=0,c=h.length;u<c;u++)h[u].flattenToArrayOffset(o._array,9*u);zt.uniformMatrix3fv(l,!1,o._array);break;case"m4":zt.uniformMatrix4fv(l,!1,h.elements);break;case"m4v":void 0===o._array&&(o._array=new Float32Array(16*h.length));for(var u=0,c=h.length;u<c;u++)h[u].flattenToArrayOffset(o._array,16*u);zt.uniformMatrix4fv(l,!1,o._array);break;case"t":if(e=h,r=ne(),zt.uniform1i(l,r),!e)continue;e instanceof THREE.CubeTexture||e.image instanceof Array&&6===e.image.length?fe(e,r):e instanceof THREE.WebGLRenderTargetCube?de(e,r):V.setTexture(e,r);break;case"tv":void 0===o._array&&(o._array=[]);for(var u=0,c=o.value.length;u<c;u++)o._array[u]=ne();zt.uniform1iv(l,o._array);for(var u=0,c=o.value.length;u<c;u++)e=o.value[u],r=o._array[u],e&&V.setTexture(e,r);break;default:console.warn("THREE.WebGLRenderer: Unknown uniform type: "+s)}}}}(i.uniformsList)),d=T,p=n,zt.uniformMatrix4fv(d.modelViewMatrix,!1,p._modelViewMatrix.elements),d.normalMatrix&&zt.uniformMatrix3fv(d.normalMatrix,!1,p._normalMatrix.elements),null!==T.modelMatrix&&zt.uniformMatrix4fv(T.modelMatrix,!1,n.matrixWorld.elements),v}function re(t,e){t.diffuse.value=e.color,t.opacity.value=e.opacity}function ie(t,e){t.ambientLightColor.needsUpdate=e,t.directionalLightColor.needsUpdate=e,t.directionalLightDirection.needsUpdate=e,t.pointLightColor.needsUpdate=e,t.pointLightPosition.needsUpdate=e,t.pointLightDistance.needsUpdate=e,t.spotLightColor.needsUpdate=e,t.spotLightPosition.needsUpdate=e,t.spotLightDistance.needsUpdate=e,t.spotLightDirection.needsUpdate=e,t.spotLightAngleCos.needsUpdate=e,t.spotLightExponent.needsUpdate=e,t.hemisphereLightSkyColor.needsUpdate=e,t.hemisphereLightGroundColor.needsUpdate=e,t.hemisphereLightDirection.needsUpdate=e}function ne(){var t=A;return nt<=t&&console.warn("WebGLRenderer: trying to use "+t+" texture units while this GPU supports only "+nt),A+=1,t}function ae(t,e){t._modelViewMatrix.multiplyMatrices(e.matrixWorldInverse,t.matrixWorld),t._normalMatrix.getNormalMatrix(t._modelViewMatrix)}function oe(t,e,r,i){t[e]=r.r*r.r*i,t[e+1]=r.g*r.g*i,t[e+2]=r.b*r.b*i}function se(t,e,r,i){t[e]=r.r*i,t[e+1]=r.g*i,t[e+2]=r.b*i}function he(t){t!==N&&(zt.lineWidth(t),N=t)}function le(t,e,r){U!==t&&(t?zt.enable(zt.POLYGON_OFFSET_FILL):zt.disable(zt.POLYGON_OFFSET_FILL),U=t),!t||B===e&&z===r||(zt.polygonOffset(e,r),B=e,z=r)}function ue(t,e,r){var i;r?(zt.texParameteri(t,zt.TEXTURE_WRAP_S,ge(e.wrapS)),zt.texParameteri(t,zt.TEXTURE_WRAP_T,ge(e.wrapT)),zt.texParameteri(t,zt.TEXTURE_MAG_FILTER,ge(e.magFilter)),zt.texParameteri(t,zt.TEXTURE_MIN_FILTER,ge(e.minFilter))):(zt.texParameteri(t,zt.TEXTURE_WRAP_S,zt.CLAMP_TO_EDGE),zt.texParameteri(t,zt.TEXTURE_WRAP_T,zt.CLAMP_TO_EDGE),zt.texParameteri(t,zt.TEXTURE_MAG_FILTER,me(e.magFilter)),zt.texParameteri(t,zt.TEXTURE_MIN_FILTER,me(e.minFilter))),(i=rt.get("EXT_texture_filter_anisotropic"))&&e.type!==THREE.FloatType&&(1<e.anisotropy||e.__oldAnisotropy)&&(zt.texParameterf(t,i.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(e.anisotropy,V.getMaxAnisotropy())),e.__oldAnisotropy=e.anisotropy)}function ce(t,e){if(t.width>e||t.height>e){var r=e/Math.max(t.width,t.height),i=document.createElement("canvas");return i.width=Math.floor(t.width*r),i.height=Math.floor(t.height*r),i.getContext("2d").drawImage(t,0,0,t.width,t.height,0,0,i.width,i.height),console.log("THREE.WebGLRenderer:",t,"is too big ("+t.width+"x"+t.height+"). Resized to "+i.width+"x"+i.height+"."),i}return t}function fe(t,e){if(6===t.image.length)if(t.needsUpdate){t.image.__webglTextureCube||(t.addEventListener("dispose",Ht),t.image.__webglTextureCube=zt.createTexture(),V.info.memory.textures++),zt.activeTexture(zt.TEXTURE0+e),zt.bindTexture(zt.TEXTURE_CUBE_MAP,t.image.__webglTextureCube),zt.pixelStorei(zt.UNPACK_FLIP_Y_WEBGL,t.flipY);for(var r=t instanceof THREE.CompressedTexture,i=t.image[0]instanceof THREE.DataTexture,n=[],a=0;a<6;a++)!V.autoScaleCubemaps||r||i?n[a]=i?t.image[a].image:t.image[a]:n[a]=ce(t.image[a],st);var o=n[0],s=THREE.Math.isPowerOfTwo(o.width)&&THREE.Math.isPowerOfTwo(o.height),h=ge(t.format),l=ge(t.type);ue(zt.TEXTURE_CUBE_MAP,t,s);for(a=0;a<6;a++)if(r)for(var u,c=n[a].mipmaps,f=0,d=c.length;f<d;f++)u=c[f],t.format!==THREE.RGBAFormat&&t.format!==THREE.RGBFormat?-1<pt().indexOf(h)?zt.compressedTexImage2D(zt.TEXTURE_CUBE_MAP_POSITIVE_X+a,f,h,u.width,u.height,0,u.data):console.warn("Attempt to load unsupported compressed texture format"):zt.texImage2D(zt.TEXTURE_CUBE_MAP_POSITIVE_X+a,f,h,u.width,u.height,0,h,l,u.data);else i?zt.texImage2D(zt.TEXTURE_CUBE_MAP_POSITIVE_X+a,0,h,n[a].width,n[a].height,0,h,l,n[a].data):zt.texImage2D(zt.TEXTURE_CUBE_MAP_POSITIVE_X+a,0,h,h,l,n[a]);t.generateMipmaps&&s&&zt.generateMipmap(zt.TEXTURE_CUBE_MAP),t.needsUpdate=!1,t.onUpdate&&t.onUpdate()}else zt.activeTexture(zt.TEXTURE0+e),zt.bindTexture(zt.TEXTURE_CUBE_MAP,t.image.__webglTextureCube)}function de(t,e){zt.activeTexture(zt.TEXTURE0+e),zt.bindTexture(zt.TEXTURE_CUBE_MAP,t.__webglTexture)}function pe(t,e,r){zt.bindFramebuffer(zt.FRAMEBUFFER,t),zt.framebufferTexture2D(zt.FRAMEBUFFER,zt.COLOR_ATTACHMENT0,r,e.__webglTexture,0)}function Ee(t,e){zt.bindRenderbuffer(zt.RENDERBUFFER,t),e.depthBuffer&&!e.stencilBuffer?(zt.renderbufferStorage(zt.RENDERBUFFER,zt.DEPTH_COMPONENT16,e.width,e.height),zt.framebufferRenderbuffer(zt.FRAMEBUFFER,zt.DEPTH_ATTACHMENT,zt.RENDERBUFFER,t)):e.depthBuffer&&e.stencilBuffer?(zt.renderbufferStorage(zt.RENDERBUFFER,zt.DEPTH_STENCIL,e.width,e.height),zt.framebufferRenderbuffer(zt.FRAMEBUFFER,zt.DEPTH_STENCIL_ATTACHMENT,zt.RENDERBUFFER,t)):zt.renderbufferStorage(zt.RENDERBUFFER,zt.RGBA4,e.width,e.height)}function me(t){return t===THREE.NearestFilter||t===THREE.NearestMipMapNearestFilter||t===THREE.NearestMipMapLinearFilter?zt.NEAREST:zt.LINEAR}function ge(t){var e;if(t===THREE.RepeatWrapping)return zt.REPEAT;if(t===THREE.ClampToEdgeWrapping)return zt.CLAMP_TO_EDGE;if(t===THREE.MirroredRepeatWrapping)return zt.MIRRORED_REPEAT;if(t===THREE.NearestFilter)return zt.NEAREST;if(t===THREE.NearestMipMapNearestFilter)return zt.NEAREST_MIPMAP_NEAREST;if(t===THREE.NearestMipMapLinearFilter)return zt.NEAREST_MIPMAP_LINEAR;if(t===THREE.LinearFilter)return zt.LINEAR;if(t===THREE.LinearMipMapNearestFilter)return zt.LINEAR_MIPMAP_NEAREST;if(t===THREE.LinearMipMapLinearFilter)return zt.LINEAR_MIPMAP_LINEAR;if(t===THREE.UnsignedByteType)return zt.UNSIGNED_BYTE;if(t===THREE.UnsignedShort4444Type)return zt.UNSIGNED_SHORT_4_4_4_4;if(t===THREE.UnsignedShort5551Type)return zt.UNSIGNED_SHORT_5_5_5_1;if(t===THREE.UnsignedShort565Type)return zt.UNSIGNED_SHORT_5_6_5;if(t===THREE.ByteType)return zt.BYTE;if(t===THREE.ShortType)return zt.SHORT;if(t===THREE.UnsignedShortType)return zt.UNSIGNED_SHORT;if(t===THREE.IntType)return zt.INT;if(t===THREE.UnsignedIntType)return zt.UNSIGNED_INT;if(t===THREE.FloatType)return zt.FLOAT;if(t===THREE.AlphaFormat)return zt.ALPHA;if(t===THREE.RGBFormat)return zt.RGB;if(t===THREE.RGBAFormat)return zt.RGBA;if(t===THREE.LuminanceFormat)return zt.LUMINANCE;if(t===THREE.LuminanceAlphaFormat)return zt.LUMINANCE_ALPHA;if(t===THREE.AddEquation)return zt.FUNC_ADD;if(t===THREE.SubtractEquation)return zt.FUNC_SUBTRACT;if(t===THREE.ReverseSubtractEquation)return zt.FUNC_REVERSE_SUBTRACT;if(t===THREE.ZeroFactor)return zt.ZERO;if(t===THREE.OneFactor)return zt.ONE;if(t===THREE.SrcColorFactor)return zt.SRC_COLOR;if(t===THREE.OneMinusSrcColorFactor)return zt.ONE_MINUS_SRC_COLOR;if(t===THREE.SrcAlphaFactor)return zt.SRC_ALPHA;if(t===THREE.OneMinusSrcAlphaFactor)return zt.ONE_MINUS_SRC_ALPHA;if(t===THREE.DstAlphaFactor)return zt.DST_ALPHA;if(t===THREE.OneMinusDstAlphaFactor)return zt.ONE_MINUS_DST_ALPHA;if(t===THREE.DstColorFactor)return zt.DST_COLOR;if(t===THREE.OneMinusDstColorFactor)return zt.ONE_MINUS_DST_COLOR;if(t===THREE.SrcAlphaSaturateFactor)return zt.SRC_ALPHA_SATURATE;if(null!==(e=rt.get("WEBGL_compressed_texture_s3tc"))){if(t===THREE.RGB_S3TC_DXT1_Format)return e.COMPRESSED_RGB_S3TC_DXT1_EXT;if(t===THREE.RGBA_S3TC_DXT1_Format)return e.COMPRESSED_RGBA_S3TC_DXT1_EXT;if(t===THREE.RGBA_S3TC_DXT3_Format)return e.COMPRESSED_RGBA_S3TC_DXT3_EXT;if(t===THREE.RGBA_S3TC_DXT5_Format)return e.COMPRESSED_RGBA_S3TC_DXT5_EXT}if(null!==(e=rt.get("WEBGL_compressed_texture_pvrtc"))){if(t===THREE.RGB_PVRTC_4BPPV1_Format)return e.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;if(t===THREE.RGB_PVRTC_2BPPV1_Format)return e.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;if(t===THREE.RGBA_PVRTC_4BPPV1_Format)return e.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;if(t===THREE.RGBA_PVRTC_2BPPV1_Format)return e.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG}if(null!==(e=rt.get("EXT_blend_minmax"))){if(t===THREE.MinEquation)return e.MIN_EXT;if(t===THREE.MaxEquation)return e.MAX_EXT}return 0}this.setFaceCulling=function(t,e){t===THREE.CullFaceNone?zt.disable(zt.CULL_FACE):(e===THREE.FrontFaceDirectionCW?zt.frontFace(zt.CW):zt.frontFace(zt.CCW),t===THREE.CullFaceBack?zt.cullFace(zt.BACK):t===THREE.CullFaceFront?zt.cullFace(zt.FRONT):zt.cullFace(zt.FRONT_AND_BACK),zt.enable(zt.CULL_FACE))},this.setMaterialFaces=function(t){var e=t.side===THREE.DoubleSide,r=t.side===THREE.BackSide;u!==e&&(e?zt.disable(zt.CULL_FACE):zt.enable(zt.CULL_FACE),u=e),x!==r&&(r?zt.frontFace(zt.CW):zt.frontFace(zt.CCW),x=r)},this.setDepthTest=function(t){F!==t&&(t?zt.enable(zt.DEPTH_TEST):zt.disable(zt.DEPTH_TEST),F=t)},this.setDepthWrite=function(t){P!==t&&(zt.depthMask(t),P=t)},this.setBlending=function(t,e,r,i){t!==y&&(t===THREE.NoBlending?zt.disable(zt.BLEND):t===THREE.AdditiveBlending?(zt.enable(zt.BLEND),zt.blendEquation(zt.FUNC_ADD),zt.blendFunc(zt.SRC_ALPHA,zt.ONE)):t===THREE.SubtractiveBlending?(zt.enable(zt.BLEND),zt.blendEquation(zt.FUNC_ADD),zt.blendFunc(zt.ZERO,zt.ONE_MINUS_SRC_COLOR)):t===THREE.MultiplyBlending?(zt.enable(zt.BLEND),zt.blendEquation(zt.FUNC_ADD),zt.blendFunc(zt.ZERO,zt.SRC_COLOR)):t===THREE.CustomBlending?zt.enable(zt.BLEND):(zt.enable(zt.BLEND),zt.blendEquationSeparate(zt.FUNC_ADD,zt.FUNC_ADD),zt.blendFuncSeparate(zt.SRC_ALPHA,zt.ONE_MINUS_SRC_ALPHA,zt.ONE,zt.ONE_MINUS_SRC_ALPHA)),y=t),t===THREE.CustomBlending?(e!==C&&(zt.blendEquation(ge(e)),C=e),r===D&&i===L||(zt.blendFunc(ge(r),ge(i)),D=r,L=i)):L=D=C=null},this.uploadTexture=function(t){void 0===t.__webglInit&&(t.__webglInit=!0,t.addEventListener("dispose",Ht),t.__webglTexture=zt.createTexture(),V.info.memory.textures++),zt.bindTexture(zt.TEXTURE_2D,t.__webglTexture),zt.pixelStorei(zt.UNPACK_FLIP_Y_WEBGL,t.flipY),zt.pixelStorei(zt.UNPACK_PREMULTIPLY_ALPHA_WEBGL,t.premultiplyAlpha),zt.pixelStorei(zt.UNPACK_ALIGNMENT,t.unpackAlignment),t.image=ce(t.image,ot);var e=t.image,r=THREE.Math.isPowerOfTwo(e.width)&&THREE.Math.isPowerOfTwo(e.height),i=ge(t.format),n=ge(t.type);ue(zt.TEXTURE_2D,t,r);var a,o=t.mipmaps;if(t instanceof THREE.DataTexture)if(0<o.length&&r){for(var s=0,h=o.length;s<h;s++)a=o[s],zt.texImage2D(zt.TEXTURE_2D,s,i,a.width,a.height,0,i,n,a.data);t.generateMipmaps=!1}else zt.texImage2D(zt.TEXTURE_2D,0,i,e.width,e.height,0,i,n,e.data);else if(t instanceof THREE.CompressedTexture)for(s=0,h=o.length;s<h;s++)a=o[s],t.format!==THREE.RGBAFormat&&t.format!==THREE.RGBFormat?-1<pt().indexOf(i)?zt.compressedTexImage2D(zt.TEXTURE_2D,s,i,a.width,a.height,0,a.data):console.warn("Attempt to load unsupported compressed texture format"):zt.texImage2D(zt.TEXTURE_2D,s,i,a.width,a.height,0,i,n,a.data);else if(0<o.length&&r){for(s=0,h=o.length;s<h;s++)a=o[s],zt.texImage2D(zt.TEXTURE_2D,s,i,i,n,a);t.generateMipmaps=!1}else zt.texImage2D(zt.TEXTURE_2D,0,i,i,n,t.image);t.generateMipmaps&&r&&zt.generateMipmap(zt.TEXTURE_2D),t.needsUpdate=!1,t.onUpdate&&t.onUpdate()},this.setTexture=function(t,e){zt.activeTexture(zt.TEXTURE0+e),t.needsUpdate?V.uploadTexture(t):zt.bindTexture(zt.TEXTURE_2D,t.__webglTexture)},this.setRenderTarget=function(t){var e,r,i,n,a,o=t instanceof THREE.WebGLRenderTargetCube;if(t&&void 0===t.__webglFramebuffer){void 0===t.depthBuffer&&(t.depthBuffer=!0),void 0===t.stencilBuffer&&(t.stencilBuffer=!0),t.addEventListener("dispose",bt),t.__webglTexture=zt.createTexture(),V.info.memory.textures++;var s=THREE.Math.isPowerOfTwo(t.width)&&THREE.Math.isPowerOfTwo(t.height),h=ge(t.format),l=ge(t.type);if(o){t.__webglFramebuffer=[],t.__webglRenderbuffer=[],zt.bindTexture(zt.TEXTURE_CUBE_MAP,t.__webglTexture),ue(zt.TEXTURE_CUBE_MAP,t,s);for(var u=0;u<6;u++)t.__webglFramebuffer[u]=zt.createFramebuffer(),t.__webglRenderbuffer[u]=zt.createRenderbuffer(),zt.texImage2D(zt.TEXTURE_CUBE_MAP_POSITIVE_X+u,0,h,t.width,t.height,0,h,l,null),pe(t.__webglFramebuffer[u],t,zt.TEXTURE_CUBE_MAP_POSITIVE_X+u),Ee(t.__webglRenderbuffer[u],t);s&&zt.generateMipmap(zt.TEXTURE_CUBE_MAP)}else t.__webglFramebuffer=zt.createFramebuffer(),t.shareDepthFrom?t.__webglRenderbuffer=t.shareDepthFrom.__webglRenderbuffer:t.__webglRenderbuffer=zt.createRenderbuffer(),zt.bindTexture(zt.TEXTURE_2D,t.__webglTexture),ue(zt.TEXTURE_2D,t,s),zt.texImage2D(zt.TEXTURE_2D,0,h,t.width,t.height,0,h,l,null),pe(t.__webglFramebuffer,t,zt.TEXTURE_2D),t.shareDepthFrom?t.depthBuffer&&!t.stencilBuffer?zt.framebufferRenderbuffer(zt.FRAMEBUFFER,zt.DEPTH_ATTACHMENT,zt.RENDERBUFFER,t.__webglRenderbuffer):t.depthBuffer&&t.stencilBuffer&&zt.framebufferRenderbuffer(zt.FRAMEBUFFER,zt.DEPTH_STENCIL_ATTACHMENT,zt.RENDERBUFFER,t.__webglRenderbuffer):Ee(t.__webglRenderbuffer,t),s&&zt.generateMipmap(zt.TEXTURE_2D);o?zt.bindTexture(zt.TEXTURE_CUBE_MAP,null):zt.bindTexture(zt.TEXTURE_2D,null),zt.bindRenderbuffer(zt.RENDERBUFFER,null),zt.bindFramebuffer(zt.FRAMEBUFFER,null)}t?(e=o?t.__webglFramebuffer[t.activeCubeFace]:t.__webglFramebuffer,r=t.width,i=t.height,a=n=0):(e=null,r=I,i=G,n=k,a=O),e!==v&&(zt.bindFramebuffer(zt.FRAMEBUFFER,e),zt.viewport(n,a,r,i),v=e),W=r,X=i},this.initMaterial=function(){console.warn("THREE.WebGLRenderer: .initMaterial() has been removed.")},this.addPrePlugin=function(){console.warn("THREE.WebGLRenderer: .addPrePlugin() has been removed.")},this.addPostPlugin=function(){console.warn("THREE.WebGLRenderer: .addPostPlugin() has been removed.")},this.updateShadowMap=function(){console.warn("THREE.WebGLRenderer: .updateShadowMap() has been removed.")}},THREE.WebGLRenderTarget=function(t,e,r){this.width=t,this.height=e,r=r||{},this.wrapS=void 0!==r.wrapS?r.wrapS:THREE.ClampToEdgeWrapping,this.wrapT=void 0!==r.wrapT?r.wrapT:THREE.ClampToEdgeWrapping,this.magFilter=void 0!==r.magFilter?r.magFilter:THREE.LinearFilter,this.minFilter=void 0!==r.minFilter?r.minFilter:THREE.LinearMipMapLinearFilter,this.anisotropy=void 0!==r.anisotropy?r.anisotropy:1,this.offset=new THREE.Vector2(0,0),this.repeat=new THREE.Vector2(1,1),this.format=void 0!==r.format?r.format:THREE.RGBAFormat,this.type=void 0!==r.type?r.type:THREE.UnsignedByteType,this.depthBuffer=void 0===r.depthBuffer||r.depthBuffer,this.stencilBuffer=void 0===r.stencilBuffer||r.stencilBuffer,this.generateMipmaps=!0,this.shareDepthFrom=null},THREE.WebGLRenderTarget.prototype={constructor:THREE.WebGLRenderTarget,setSize:function(t,e){this.width=t,this.height=e},clone:function(){var t=new THREE.WebGLRenderTarget(this.width,this.height);return t.wrapS=this.wrapS,t.wrapT=this.wrapT,t.magFilter=this.magFilter,t.minFilter=this.minFilter,t.anisotropy=this.anisotropy,t.offset.copy(this.offset),t.repeat.copy(this.repeat),t.format=this.format,t.type=this.type,t.depthBuffer=this.depthBuffer,t.stencilBuffer=this.stencilBuffer,t.generateMipmaps=this.generateMipmaps,t.shareDepthFrom=this.shareDepthFrom,t},dispose:function(){this.dispatchEvent({type:"dispose"})}},THREE.EventDispatcher.prototype.apply(THREE.WebGLRenderTarget.prototype),THREE.WebGLRenderTargetCube=function(t,e,r){THREE.WebGLRenderTarget.call(this,t,e,r),this.activeCubeFace=0},THREE.WebGLRenderTargetCube.prototype=Object.create(THREE.WebGLRenderTarget.prototype),THREE.WebGLExtensions=function(r){var i={};this.get=function(t){if(void 0!==i[t])return i[t];var e;switch(t){case"OES_texture_float":e=r.getExtension("OES_texture_float");break;case"OES_texture_float_linear":e=r.getExtension("OES_texture_float_linear");break;case"OES_standard_derivatives":e=r.getExtension("OES_standard_derivatives");break;case"EXT_texture_filter_anisotropic":e=r.getExtension("EXT_texture_filter_anisotropic")||r.getExtension("MOZ_EXT_texture_filter_anisotropic")||r.getExtension("WEBKIT_EXT_texture_filter_anisotropic");break;case"WEBGL_compressed_texture_s3tc":e=r.getExtension("WEBGL_compressed_texture_s3tc")||r.getExtension("MOZ_WEBGL_compressed_texture_s3tc")||r.getExtension("WEBKIT_WEBGL_compressed_texture_s3tc");break;case"WEBGL_compressed_texture_pvrtc":e=r.getExtension("WEBGL_compressed_texture_pvrtc")||r.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc");break;case"OES_element_index_uint":e=r.getExtension("OES_element_index_uint");break;case"EXT_blend_minmax":e=r.getExtension("EXT_blend_minmax");break;case"EXT_frag_depth":e=r.getExtension("EXT_frag_depth")}return null===e&&console.log("THREE.WebGLRenderer: "+t+" extension not supported."),i[t]=e}},THREE.WebGLProgram=function(){var _=0;return function(t,e,r,i){var n=t,a=n.context,o=r.defines,s=r.__webglShader.uniforms,h=r.attributes,l=r.__webglShader.vertexShader,u=r.__webglShader.fragmentShader,c=r.index0AttributeName;void 0===c&&!0===i.morphTargets&&(c="position");var f="SHADOWMAP_TYPE_BASIC";i.shadowMapType===THREE.PCFShadowMap?f="SHADOWMAP_TYPE_PCF":i.shadowMapType===THREE.PCFSoftShadowMap&&(f="SHADOWMAP_TYPE_PCF_SOFT");var d,p,E=function(t){var e,r,i=[];for(var n in t)!1!==(e=t[n])&&(r="#define "+n+" "+e,i.push(r));return i.join("\n")}(o),m=a.createProgram();r instanceof THREE.RawShaderMaterial?p=d="":(d=["precision "+i.precision+" float;","precision "+i.precision+" int;",E,i.supportsVertexTextures?"#define VERTEX_TEXTURES":"",n.gammaInput?"#define GAMMA_INPUT":"",n.gammaOutput?"#define GAMMA_OUTPUT":"","#define MAX_DIR_LIGHTS "+i.maxDirLights,"#define MAX_POINT_LIGHTS "+i.maxPointLights,"#define MAX_SPOT_LIGHTS "+i.maxSpotLights,"#define MAX_HEMI_LIGHTS "+i.maxHemiLights,"#define MAX_SHADOWS "+i.maxShadows,"#define MAX_BONES "+i.maxBones,i.map?"#define USE_MAP":"",i.envMap?"#define USE_ENVMAP":"",i.lightMap?"#define USE_LIGHTMAP":"",i.bumpMap?"#define USE_BUMPMAP":"",i.normalMap?"#define USE_NORMALMAP":"",i.specularMap?"#define USE_SPECULARMAP":"",i.alphaMap?"#define USE_ALPHAMAP":"",i.vertexColors?"#define USE_COLOR":"",i.skinning?"#define USE_SKINNING":"",i.useVertexTexture?"#define BONE_TEXTURE":"",i.morphTargets?"#define USE_MORPHTARGETS":"",i.morphNormals?"#define USE_MORPHNORMALS":"",i.wrapAround?"#define WRAP_AROUND":"",i.doubleSided?"#define DOUBLE_SIDED":"",i.flipSided?"#define FLIP_SIDED":"",i.shadowMapEnabled?"#define USE_SHADOWMAP":"",i.shadowMapEnabled?"#define "+f:"",i.shadowMapDebug?"#define SHADOWMAP_DEBUG":"",i.shadowMapCascade?"#define SHADOWMAP_CASCADE":"",i.sizeAttenuation?"#define USE_SIZEATTENUATION":"",i.logarithmicDepthBuffer?"#define USE_LOGDEPTHBUF":"","uniform mat4 modelMatrix;","uniform mat4 modelViewMatrix;","uniform mat4 projectionMatrix;","uniform mat4 viewMatrix;","uniform mat3 normalMatrix;","uniform vec3 cameraPosition;","attribute vec3 position;","attribute vec3 normal;","attribute vec2 uv;","attribute vec2 uv2;","#ifdef USE_COLOR","\tattribute vec3 color;","#endif","#ifdef USE_MORPHTARGETS","\tattribute vec3 morphTarget0;","\tattribute vec3 morphTarget1;","\tattribute vec3 morphTarget2;","\tattribute vec3 morphTarget3;","\t#ifdef USE_MORPHNORMALS","\t\tattribute vec3 morphNormal0;","\t\tattribute vec3 morphNormal1;","\t\tattribute vec3 morphNormal2;","\t\tattribute vec3 morphNormal3;","\t#else","\t\tattribute vec3 morphTarget4;","\t\tattribute vec3 morphTarget5;","\t\tattribute vec3 morphTarget6;","\t\tattribute vec3 morphTarget7;","\t#endif","#endif","#ifdef USE_SKINNING","\tattribute vec4 skinIndex;","\tattribute vec4 skinWeight;","#endif",""].join("\n"),p=["precision "+i.precision+" float;","precision "+i.precision+" int;",i.bumpMap||i.normalMap?"#extension GL_OES_standard_derivatives : enable":"",E,"#define MAX_DIR_LIGHTS "+i.maxDirLights,"#define MAX_POINT_LIGHTS "+i.maxPointLights,"#define MAX_SPOT_LIGHTS "+i.maxSpotLights,"#define MAX_HEMI_LIGHTS "+i.maxHemiLights,"#define MAX_SHADOWS "+i.maxShadows,i.alphaTest?"#define ALPHATEST "+i.alphaTest:"",n.gammaInput?"#define GAMMA_INPUT":"",n.gammaOutput?"#define GAMMA_OUTPUT":"",i.useFog&&i.fog?"#define USE_FOG":"",i.useFog&&i.fogExp?"#define FOG_EXP2":"",i.map?"#define USE_MAP":"",i.envMap?"#define USE_ENVMAP":"",i.lightMap?"#define USE_LIGHTMAP":"",i.bumpMap?"#define USE_BUMPMAP":"",i.normalMap?"#define USE_NORMALMAP":"",i.specularMap?"#define USE_SPECULARMAP":"",i.alphaMap?"#define USE_ALPHAMAP":"",i.vertexColors?"#define USE_COLOR":"",i.metal?"#define METAL":"",i.wrapAround?"#define WRAP_AROUND":"",i.doubleSided?"#define DOUBLE_SIDED":"",i.flipSided?"#define FLIP_SIDED":"",i.shadowMapEnabled?"#define USE_SHADOWMAP":"",i.shadowMapEnabled?"#define "+f:"",i.shadowMapDebug?"#define SHADOWMAP_DEBUG":"",i.shadowMapCascade?"#define SHADOWMAP_CASCADE":"",i.logarithmicDepthBuffer?"#define USE_LOGDEPTHBUF":"","uniform mat4 viewMatrix;","uniform vec3 cameraPosition;",""].join("\n"));var g=new THREE.WebGLShader(a,a.VERTEX_SHADER,d+l),v=new THREE.WebGLShader(a,a.FRAGMENT_SHADER,p+u);a.attachShader(m,g),a.attachShader(m,v),void 0!==c&&a.bindAttribLocation(m,0,c),a.linkProgram(m),!1===a.getProgramParameter(m,a.LINK_STATUS)&&(console.error("THREE.WebGLProgram: Could not initialise shader."),console.error("gl.VALIDATE_STATUS",a.getProgramParameter(m,a.VALIDATE_STATUS)),console.error("gl.getError()",a.getError())),""!==a.getProgramInfoLog(m)&&console.warn("THREE.WebGLProgram: gl.getProgramInfoLog()",a.getProgramInfoLog(m)),a.deleteShader(g),a.deleteShader(v);var T=["viewMatrix","modelViewMatrix","projectionMatrix","normalMatrix","modelMatrix","cameraPosition","morphTargetInfluences","bindMatrix","bindMatrixInverse"];for(var x in i.useVertexTexture?(T.push("boneTexture"),T.push("boneTextureWidth"),T.push("boneTextureHeight")):T.push("boneGlobalMatrices"),i.logarithmicDepthBuffer&&T.push("logDepthBufFC"),s)T.push(x);this.uniforms=function(t,e,r){for(var i={},n=0,a=r.length;n<a;n++){var o=r[n];i[o]=t.getUniformLocation(e,o)}return i}(a,m,T),T=["position","normal","uv","uv2","tangent","color","skinIndex","skinWeight","lineDistance"];for(var y=0;y<i.maxMorphTargets;y++)T.push("morphTarget"+y);for(y=0;y<i.maxMorphNormals;y++)T.push("morphNormal"+y);for(var R in h)T.push(R);return this.attributes=function(t,e,r){for(var i={},n=0,a=r.length;n<a;n++){var o=r[n];i[o]=t.getAttribLocation(e,o)}return i}(a,m,T),this.attributesKeys=Object.keys(this.attributes),this.id=_++,this.code=e,this.usedTimes=1,this.program=m,this.vertexShader=g,this.fragmentShader=v,this}}(),THREE.WebGLShader=function(t,e,r){var i=t.createShader(e);return t.shaderSource(i,r),t.compileShader(i),!1===t.getShaderParameter(i,t.COMPILE_STATUS)&&console.error("THREE.WebGLShader: Shader couldn't compile."),""!==t.getShaderInfoLog(i)&&(console.warn("THREE.WebGLShader: gl.getShaderInfoLog()",t.getShaderInfoLog(i)),console.warn(function(t){for(var e=t.split("\n"),r=0;r<e.length;r++)e[r]=r+1+": "+e[r];return e.join("\n")}(r))),i},THREE.LensFlarePlugin=function(v,T){var x,y,R,_,H,b,M,w,S=v.context,A=function(){var t,e,r,i,n,a,o=new Float32Array([-1,-1,0,0,1,-1,1,0,1,1,1,1,-1,1,0,1]),s=new Uint16Array([0,1,2,0,2,3]);x=S.createBuffer(),y=S.createBuffer(),S.bindBuffer(S.ARRAY_BUFFER,x),S.bufferData(S.ARRAY_BUFFER,o,S.STATIC_DRAW),S.bindBuffer(S.ELEMENT_ARRAY_BUFFER,y),S.bufferData(S.ELEMENT_ARRAY_BUFFER,s,S.STATIC_DRAW),M=S.createTexture(),w=S.createTexture(),S.bindTexture(S.TEXTURE_2D,M),S.texImage2D(S.TEXTURE_2D,0,S.RGB,16,16,0,S.RGB,S.UNSIGNED_BYTE,null),S.texParameteri(S.TEXTURE_2D,S.TEXTURE_WRAP_S,S.CLAMP_TO_EDGE),S.texParameteri(S.TEXTURE_2D,S.TEXTURE_WRAP_T,S.CLAMP_TO_EDGE),S.texParameteri(S.TEXTURE_2D,S.TEXTURE_MAG_FILTER,S.NEAREST),S.texParameteri(S.TEXTURE_2D,S.TEXTURE_MIN_FILTER,S.NEAREST),S.bindTexture(S.TEXTURE_2D,w),S.texImage2D(S.TEXTURE_2D,0,S.RGBA,16,16,0,S.RGBA,S.UNSIGNED_BYTE,null),S.texParameteri(S.TEXTURE_2D,S.TEXTURE_WRAP_S,S.CLAMP_TO_EDGE),S.texParameteri(S.TEXTURE_2D,S.TEXTURE_WRAP_T,S.CLAMP_TO_EDGE),S.texParameteri(S.TEXTURE_2D,S.TEXTURE_MAG_FILTER,S.NEAREST),S.texParameteri(S.TEXTURE_2D,S.TEXTURE_MIN_FILTER,S.NEAREST),t=(b=0<S.getParameter(S.MAX_VERTEX_TEXTURE_IMAGE_UNITS))?{vertexShader:["uniform lowp int renderType;","uniform vec3 screenPosition;","uniform vec2 scale;","uniform float rotation;","uniform sampler2D occlusionMap;","attribute vec2 position;","attribute vec2 uv;","varying vec2 vUV;","varying float vVisibility;","void main() {","vUV = uv;","vec2 pos = position;","if( renderType == 2 ) {","vec4 visibility = texture2D( occlusionMap, vec2( 0.1, 0.1 ) );","visibility += texture2D( occlusionMap, vec2( 0.5, 0.1 ) );","visibility += texture2D( occlusionMap, vec2( 0.9, 0.1 ) );","visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) );","visibility += texture2D( occlusionMap, vec2( 0.9, 0.9 ) );","visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) );","visibility += texture2D( occlusionMap, vec2( 0.1, 0.9 ) );","visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) );","visibility += texture2D( occlusionMap, vec2( 0.5, 0.5 ) );","vVisibility = visibility.r / 9.0;","vVisibility *= 1.0 - visibility.g / 9.0;","vVisibility *= visibility.b / 9.0;","vVisibility *= 1.0 - visibility.a / 9.0;","pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;","pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;","}","gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );","}"].join("\n"),fragmentShader:["uniform lowp int renderType;","uniform sampler2D map;","uniform float opacity;","uniform vec3 color;","varying vec2 vUV;","varying float vVisibility;","void main() {","if( renderType == 0 ) {","gl_FragColor = vec4( 1.0, 0.0, 1.0, 0.0 );","} else if( renderType == 1 ) {","gl_FragColor = texture2D( map, vUV );","} else {","vec4 texture = texture2D( map, vUV );","texture.a *= opacity * vVisibility;","gl_FragColor = texture;","gl_FragColor.rgb *= color;","}","}"].join("\n")}:{vertexShader:["uniform lowp int renderType;","uniform vec3 screenPosition;","uniform vec2 scale;","uniform float rotation;","attribute vec2 position;","attribute vec2 uv;","varying vec2 vUV;","void main() {","vUV = uv;","vec2 pos = position;","if( renderType == 2 ) {","pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;","pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;","}","gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );","}"].join("\n"),fragmentShader:["precision mediump float;","uniform lowp int renderType;","uniform sampler2D map;","uniform sampler2D occlusionMap;","uniform float opacity;","uniform vec3 color;","varying vec2 vUV;","void main() {","if( renderType == 0 ) {","gl_FragColor = vec4( texture2D( map, vUV ).rgb, 0.0 );","} else if( renderType == 1 ) {","gl_FragColor = texture2D( map, vUV );","} else {","float visibility = texture2D( occlusionMap, vec2( 0.5, 0.1 ) ).a;","visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) ).a;","visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) ).a;","visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) ).a;","visibility = ( 1.0 - visibility / 4.0 );","vec4 texture = texture2D( map, vUV );","texture.a *= opacity * visibility;","gl_FragColor = texture;","gl_FragColor.rgb *= color;","}","}"].join("\n")},e=t,r=S.createProgram(),i=S.createShader(S.FRAGMENT_SHADER),n=S.createShader(S.VERTEX_SHADER),a="precision "+v.getPrecision()+" float;\n",S.shaderSource(i,a+e.fragmentShader),S.shaderSource(n,a+e.vertexShader),S.compileShader(i),S.compileShader(n),S.attachShader(r,i),S.attachShader(r,n),S.linkProgram(r),R=r,_={vertex:S.getAttribLocation(R,"position"),uv:S.getAttribLocation(R,"uv")},H={renderType:S.getUniformLocation(R,"renderType"),map:S.getUniformLocation(R,"map"),occlusionMap:S.getUniformLocation(R,"occlusionMap"),opacity:S.getUniformLocation(R,"opacity"),color:S.getUniformLocation(R,"color"),scale:S.getUniformLocation(R,"scale"),rotation:S.getUniformLocation(R,"rotation"),screenPosition:S.getUniformLocation(R,"screenPosition")}};this.render=function(t,e,r,i){if(0!==T.length){var n=new THREE.Vector3,a=i/r,o=.5*r,s=.5*i,h=16/i,l=new THREE.Vector2(h*a,h),u=new THREE.Vector3(1,1,0),c=new THREE.Vector2(1,1);void 0===R&&A(),S.useProgram(R),S.enableVertexAttribArray(_.vertex),S.enableVertexAttribArray(_.uv),S.uniform1i(H.occlusionMap,0),S.uniform1i(H.map,1),S.bindBuffer(S.ARRAY_BUFFER,x),S.vertexAttribPointer(_.vertex,2,S.FLOAT,!1,16,0),S.vertexAttribPointer(_.uv,2,S.FLOAT,!1,16,8),S.bindBuffer(S.ELEMENT_ARRAY_BUFFER,y),S.disable(S.CULL_FACE),S.depthMask(!1);for(var f=0,d=T.length;f<d;f++){h=16/i,l.set(h*a,h);var p=T[f];if(n.set(p.matrixWorld.elements[12],p.matrixWorld.elements[13],p.matrixWorld.elements[14]),n.applyMatrix4(e.matrixWorldInverse),n.applyProjection(e.projectionMatrix),u.copy(n),c.x=u.x*o+o,c.y=u.y*s+s,b||0<c.x&&c.x<r&&0<c.y&&c.y<i){S.activeTexture(S.TEXTURE1),S.bindTexture(S.TEXTURE_2D,M),S.copyTexImage2D(S.TEXTURE_2D,0,S.RGB,c.x-8,c.y-8,16,16,0),S.uniform1i(H.renderType,0),S.uniform2f(H.scale,l.x,l.y),S.uniform3f(H.screenPosition,u.x,u.y,u.z),S.disable(S.BLEND),S.enable(S.DEPTH_TEST),S.drawElements(S.TRIANGLES,6,S.UNSIGNED_SHORT,0),S.activeTexture(S.TEXTURE0),S.bindTexture(S.TEXTURE_2D,w),S.copyTexImage2D(S.TEXTURE_2D,0,S.RGBA,c.x-8,c.y-8,16,16,0),S.uniform1i(H.renderType,1),S.disable(S.DEPTH_TEST),S.activeTexture(S.TEXTURE1),S.bindTexture(S.TEXTURE_2D,M),S.drawElements(S.TRIANGLES,6,S.UNSIGNED_SHORT,0),p.positionScreen.copy(u),p.customUpdateCallback?p.customUpdateCallback(p):p.updateLensFlares(),S.uniform1i(H.renderType,2),S.enable(S.BLEND);for(var E=0,m=p.lensFlares.length;E<m;E++){var g=p.lensFlares[E];.001<g.opacity&&.001<g.scale&&(u.x=g.x,u.y=g.y,u.z=g.z,h=g.size*g.scale/i,l.x=h*a,l.y=h,S.uniform3f(H.screenPosition,u.x,u.y,u.z),S.uniform2f(H.scale,l.x,l.y),S.uniform1f(H.rotation,g.rotation),S.uniform1f(H.opacity,g.opacity),S.uniform3f(H.color,g.color.r,g.color.g,g.color.b),v.setBlending(g.blending,g.blendEquation,g.blendSrc,g.blendDst),v.setTexture(g.texture,1),S.drawElements(S.TRIANGLES,6,S.UNSIGNED_SHORT,0))}}}S.enable(S.CULL_FACE),S.enable(S.DEPTH_TEST),S.depthMask(!0),v.resetGLState()}}},THREE.ShadowMapPlugin=function(w,S,s,A){var C,D,L,F,P=w.context,U=new THREE.Frustum,B=new THREE.Matrix4,h=new THREE.Vector3,l=new THREE.Vector3,z=new THREE.Vector3,N=[],t=THREE.ShaderLib.depthRGBA,e=THREE.UniformsUtils.clone(t.uniforms);function k(t,e,r){if(e.visible){var i=s[e.id];if(i&&e.castShadow&&(!1===e.frustumCulled||!0===U.intersectsObject(e)))for(var n=0,a=i.length;n<a;n++){var o=i[n];e._modelViewMatrix.multiplyMatrices(r.matrixWorldInverse,e.matrixWorld),N.push(o)}for(n=0,a=e.children.length;n<a;n++)k(t,e.children[n],r)}}function V(t,e){var r=new THREE.DirectionalLight;r.isVirtual=!0,r.onlyShadow=!0,r.castShadow=!0,r.shadowCameraNear=t.shadowCameraNear,r.shadowCameraFar=t.shadowCameraFar,r.shadowCameraLeft=t.shadowCameraLeft,r.shadowCameraRight=t.shadowCameraRight,r.shadowCameraBottom=t.shadowCameraBottom,r.shadowCameraTop=t.shadowCameraTop,r.shadowCameraVisible=t.shadowCameraVisible,r.shadowDarkness=t.shadowDarkness,r.shadowBias=t.shadowCascadeBias[e],r.shadowMapWidth=t.shadowCascadeWidth[e],r.shadowMapHeight=t.shadowCascadeHeight[e],r.pointsWorld=[],r.pointsFrustum=[];for(var i=r.pointsWorld,n=r.pointsFrustum,a=0;a<8;a++)i[a]=new THREE.Vector3,n[a]=new THREE.Vector3;var o=t.shadowCascadeNearZ[e],s=t.shadowCascadeFarZ[e];return n[0].set(-1,-1,o),n[1].set(1,-1,o),n[2].set(-1,1,o),n[3].set(1,1,o),n[4].set(-1,-1,s),n[5].set(1,-1,s),n[6].set(-1,1,s),n[7].set(1,1,s),r}function O(t,e){var r=t.shadowCascadeArray[e];r.position.copy(t.position),r.target.position.copy(t.target.position),r.lookAt(r.target),r.shadowCameraVisible=t.shadowCameraVisible,r.shadowDarkness=t.shadowDarkness,r.shadowBias=t.shadowCascadeBias[e];var i=t.shadowCascadeNearZ[e],n=t.shadowCascadeFarZ[e],a=r.pointsFrustum;a[0].z=i,a[1].z=i,a[2].z=i,a[3].z=i,a[4].z=n,a[5].z=n,a[6].z=n,a[7].z=n}function I(t,e){var r=e.shadowCamera,i=e.pointsFrustum,n=e.pointsWorld;h.set(1/0,1/0,1/0),l.set(-1/0,-1/0,-1/0);for(var a=0;a<8;a++){var o=n[a];o.copy(i[a]),o.unproject(t),o.applyMatrix4(r.matrixWorldInverse),o.x<h.x&&(h.x=o.x),o.x>l.x&&(l.x=o.x),o.y<h.y&&(h.y=o.y),o.y>l.y&&(l.y=o.y),o.z<h.z&&(h.z=o.z),o.z>l.z&&(l.z=o.z)}r.left=h.x,r.right=l.x,r.top=l.y,r.bottom=h.y,r.updateProjectionMatrix()}C=new THREE.ShaderMaterial({uniforms:e,vertexShader:t.vertexShader,fragmentShader:t.fragmentShader}),D=new THREE.ShaderMaterial({uniforms:e,vertexShader:t.vertexShader,fragmentShader:t.fragmentShader,morphTargets:!0}),L=new THREE.ShaderMaterial({uniforms:e,vertexShader:t.vertexShader,fragmentShader:t.fragmentShader,skinning:!0}),F=new THREE.ShaderMaterial({uniforms:e,vertexShader:t.vertexShader,fragmentShader:t.fragmentShader,morphTargets:!0,skinning:!0}),C._shadowPass=!0,D._shadowPass=!0,L._shadowPass=!0,F._shadowPass=!0,this.render=function(t,e){if(!1!==w.shadowMapEnabled){var r,i,n,a,o,s,h,l,u,c,f,d,p,E,m=[],g=0;for(P.clearColor(1,1,1,1),P.disable(P.BLEND),P.enable(P.CULL_FACE),P.frontFace(P.CCW),w.shadowMapCullFace===THREE.CullFaceFront?P.cullFace(P.FRONT):P.cullFace(P.BACK),w.setDepthTest(!0),r=0,i=S.length;r<i;r++)if((p=S[r]).castShadow)if(p instanceof THREE.DirectionalLight&&p.shadowCascade)for(o=0;o<p.shadowCascadeCount;o++){var v;if(p.shadowCascadeArray[o])v=p.shadowCascadeArray[o];else{(v=V(p,o)).originalCamera=e;var T=new THREE.Gyroscope;T.position.copy(p.shadowCascadeOffset),T.add(v),T.add(v.target),e.add(T),p.shadowCascadeArray[o]=v,console.log("Created virtualLight",v)}O(p,o),m[g]=v,g++}else m[g]=p,g++;for(r=0,i=m.length;r<i;r++){if(!(p=m[r]).shadowMap){var x=THREE.LinearFilter;w.shadowMapType===THREE.PCFSoftShadowMap&&(x=THREE.NearestFilter);var y={minFilter:x,magFilter:x,format:THREE.RGBAFormat};p.shadowMap=new THREE.WebGLRenderTarget(p.shadowMapWidth,p.shadowMapHeight,y),p.shadowMapSize=new THREE.Vector2(p.shadowMapWidth,p.shadowMapHeight),p.shadowMatrix=new THREE.Matrix4}if(!p.shadowCamera){if(p instanceof THREE.SpotLight)p.shadowCamera=new THREE.PerspectiveCamera(p.shadowCameraFov,p.shadowMapWidth/p.shadowMapHeight,p.shadowCameraNear,p.shadowCameraFar);else{if(!(p instanceof THREE.DirectionalLight)){console.error("Unsupported light type for shadow");continue}p.shadowCamera=new THREE.OrthographicCamera(p.shadowCameraLeft,p.shadowCameraRight,p.shadowCameraTop,p.shadowCameraBottom,p.shadowCameraNear,p.shadowCameraFar)}t.add(p.shadowCamera),!0===t.autoUpdate&&t.updateMatrixWorld()}var R,_,H;for(p.shadowCameraVisible&&!p.cameraHelper&&(p.cameraHelper=new THREE.CameraHelper(p.shadowCamera),t.add(p.cameraHelper)),p.isVirtual&&v.originalCamera==e&&I(e,p),s=p.shadowMap,h=p.shadowMatrix,(l=p.shadowCamera).position.setFromMatrixPosition(p.matrixWorld),z.setFromMatrixPosition(p.target.matrixWorld),l.lookAt(z),l.updateMatrixWorld(),l.matrixWorldInverse.getInverse(l.matrixWorld),p.cameraHelper&&(p.cameraHelper.visible=p.shadowCameraVisible),p.shadowCameraVisible&&p.cameraHelper.update(),h.set(.5,0,0,.5,0,.5,0,.5,0,0,.5,.5,0,0,0,1),h.multiply(l.projectionMatrix),h.multiply(l.matrixWorldInverse),B.multiplyMatrices(l.projectionMatrix,l.matrixWorldInverse),U.setFromMatrix(B),w.setRenderTarget(s),w.clear(),N.length=0,k(t,t,l),n=0,a=N.length;n<a;n++)d=(f=N[n]).object,u=f.buffer,R=(E=d).material instanceof THREE.MeshFaceMaterial?E.material.materials[0]:E.material,_=void 0!==d.geometry.morphTargets&&0<d.geometry.morphTargets.length&&R.morphTargets,H=d instanceof THREE.SkinnedMesh&&R.skinning,c=d.customDepthMaterial?d.customDepthMaterial:H?_?F:L:_?D:C,w.setMaterialFaces(R),u instanceof THREE.BufferGeometry?w.renderBufferDirect(l,S,null,c,u,d):w.renderBuffer(l,S,null,c,u,d);for(n=0,a=A.length;n<a;n++)(d=(f=A[n]).object).visible&&d.castShadow&&(d._modelViewMatrix.multiplyMatrices(l.matrixWorldInverse,d.matrixWorld),w.renderImmediateObject(l,S,null,C,d))}var b=w.getClearColor(),M=w.getClearAlpha();P.clearColor(b.r,b.g,b.b,M),P.enable(P.BLEND),w.shadowMapCullFace===THREE.CullFaceFront&&P.cullFace(P.BACK),w.resetGLState()}}},THREE.SpritePlugin=function(c,f){var d,p,E,m,g,v,T=c.context,x=function(){var t,e,r,i=new Float32Array([-.5,-.5,0,0,.5,-.5,1,0,.5,.5,1,1,-.5,.5,0,1]),n=new Uint16Array([0,1,2,0,2,3]);d=T.createBuffer(),p=T.createBuffer(),T.bindBuffer(T.ARRAY_BUFFER,d),T.bufferData(T.ARRAY_BUFFER,i,T.STATIC_DRAW),T.bindBuffer(T.ELEMENT_ARRAY_BUFFER,p),T.bufferData(T.ELEMENT_ARRAY_BUFFER,n,T.STATIC_DRAW),t=T.createProgram(),e=T.createShader(T.VERTEX_SHADER),r=T.createShader(T.FRAGMENT_SHADER),T.shaderSource(e,["precision "+c.getPrecision()+" float;","uniform mat4 modelViewMatrix;","uniform mat4 projectionMatrix;","uniform float rotation;","uniform vec2 scale;","uniform vec2 uvOffset;","uniform vec2 uvScale;","attribute vec2 position;","attribute vec2 uv;","varying vec2 vUV;","void main() {","vUV = uvOffset + uv * uvScale;","vec2 alignedPosition = position * scale;","vec2 rotatedPosition;","rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;","rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;","vec4 finalPosition;","finalPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );","finalPosition.xy += rotatedPosition;","finalPosition = projectionMatrix * finalPosition;","gl_Position = finalPosition;","}"].join("\n")),T.shaderSource(r,["precision "+c.getPrecision()+" float;","uniform vec3 color;","uniform sampler2D map;","uniform float opacity;","uniform int fogType;","uniform vec3 fogColor;","uniform float fogDensity;","uniform float fogNear;","uniform float fogFar;","uniform float alphaTest;","varying vec2 vUV;","void main() {","vec4 texture = texture2D( map, vUV );","if ( texture.a < alphaTest ) discard;","gl_FragColor = vec4( color * texture.xyz, texture.a * opacity );","if ( fogType > 0 ) {","float depth = gl_FragCoord.z / gl_FragCoord.w;","float fogFactor = 0.0;","if ( fogType == 1 ) {","fogFactor = smoothstep( fogNear, fogFar, depth );","} else {","const float LOG2 = 1.442695;","float fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );","fogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );","}","gl_FragColor = mix( gl_FragColor, vec4( fogColor, gl_FragColor.w ), fogFactor );","}","}"].join("\n")),T.compileShader(e),T.compileShader(r),T.attachShader(t,e),T.attachShader(t,r),T.linkProgram(t),E=t,m={position:T.getAttribLocation(E,"position"),uv:T.getAttribLocation(E,"uv")},g={uvOffset:T.getUniformLocation(E,"uvOffset"),uvScale:T.getUniformLocation(E,"uvScale"),rotation:T.getUniformLocation(E,"rotation"),scale:T.getUniformLocation(E,"scale"),color:T.getUniformLocation(E,"color"),map:T.getUniformLocation(E,"map"),opacity:T.getUniformLocation(E,"opacity"),modelViewMatrix:T.getUniformLocation(E,"modelViewMatrix"),projectionMatrix:T.getUniformLocation(E,"projectionMatrix"),fogType:T.getUniformLocation(E,"fogType"),fogDensity:T.getUniformLocation(E,"fogDensity"),fogNear:T.getUniformLocation(E,"fogNear"),fogFar:T.getUniformLocation(E,"fogFar"),fogColor:T.getUniformLocation(E,"fogColor"),alphaTest:T.getUniformLocation(E,"alphaTest")};var a=document.createElement("canvas");a.width=8,a.height=8;var o=a.getContext("2d");o.fillStyle="white",o.fillRect(0,0,8,8),(v=new THREE.Texture(a)).needsUpdate=!0};function y(t,e){return t.z!==e.z?e.z-t.z:e.id-t.id}this.render=function(t,e){if(0!==f.length){void 0===E&&x(),T.useProgram(E),T.enableVertexAttribArray(m.position),T.enableVertexAttribArray(m.uv),T.disable(T.CULL_FACE),T.enable(T.BLEND),T.bindBuffer(T.ARRAY_BUFFER,d),T.vertexAttribPointer(m.position,2,T.FLOAT,!1,16,0),T.vertexAttribPointer(m.uv,2,T.FLOAT,!1,16,8),T.bindBuffer(T.ELEMENT_ARRAY_BUFFER,p),T.uniformMatrix4fv(g.projectionMatrix,!1,e.projectionMatrix.elements),T.activeTexture(T.TEXTURE0),T.uniform1i(g.map,0);var r=0,i=0,n=t.fog;n?(T.uniform3f(g.fogColor,n.color.r,n.color.g,n.color.b),n instanceof THREE.Fog?(T.uniform1f(g.fogNear,n.near),T.uniform1f(g.fogFar,n.far),T.uniform1i(g.fogType,1),i=r=1):n instanceof THREE.FogExp2&&(T.uniform1f(g.fogDensity,n.density),T.uniform1i(g.fogType,2),i=r=2)):(T.uniform1i(g.fogType,0),i=r=0);for(var a=0,o=f.length;a<o;a++){(h=f[a])._modelViewMatrix.multiplyMatrices(e.matrixWorldInverse,h.matrixWorld),null===h.renderDepth?h.z=-h._modelViewMatrix.elements[14]:h.z=h.renderDepth}f.sort(y);var s=[];for(a=0,o=f.length;a<o;a++){var h,l=(h=f[a]).material;T.uniform1f(g.alphaTest,l.alphaTest),T.uniformMatrix4fv(g.modelViewMatrix,!1,h._modelViewMatrix.elements),s[0]=h.scale.x,s[1]=h.scale.y;var u=0;t.fog&&l.fog&&(u=i),r!==u&&(T.uniform1i(g.fogType,u),r=u),null!==l.map?(T.uniform2f(g.uvOffset,l.map.offset.x,l.map.offset.y),T.uniform2f(g.uvScale,l.map.repeat.x,l.map.repeat.y)):(T.uniform2f(g.uvOffset,0,0),T.uniform2f(g.uvScale,1,1)),T.uniform1f(g.opacity,l.opacity),T.uniform3f(g.color,l.color.r,l.color.g,l.color.b),T.uniform1f(g.rotation,l.rotation),T.uniform2fv(g.scale,s),c.setBlending(l.blending,l.blendEquation,l.blendSrc,l.blendDst),c.setDepthTest(l.depthTest),c.setDepthWrite(l.depthWrite),l.map&&l.map.image&&l.map.image.width?c.setTexture(l.map,0):c.setTexture(v,0),T.drawElements(T.TRIANGLES,6,T.UNSIGNED_SHORT,0)}T.enable(T.CULL_FACE),c.resetGLState()}}},THREE.ImageUtils={crossOrigin:void 0,loadTexture:function(t,e,r,i){var n=new THREE.ImageLoader;n.crossOrigin=this.crossOrigin;var a=new THREE.Texture(void 0,e);return n.load(t,function(t){a.image=t,a.needsUpdate=!0,r&&r(a)},void 0,function(t){i&&i(t)}),a.sourceFile=t,a},loadTextureCube:function(t,e,r,i){var n=new THREE.ImageLoader;n.crossOrigin=this.crossOrigin;var a=new THREE.CubeTexture([],e);a.flipY=!1;for(var o=0,s=function(e){n.load(t[e],function(t){a.images[e]=t,6===(o+=1)&&(a.needsUpdate=!0,r&&r(a))})},h=0,l=t.length;h<l;++h)s(h);return a},loadCompressedTexture:function(){console.error("THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.")},loadCompressedTextureCube:function(){console.error("THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.")},getNormalMap:function(t,e){var r=function(t,e){return[t[0]-e[0],t[1]-e[1],t[2]-e[2]]};e|=1;var i=t.width,n=t.height,a=document.createElement("canvas");a.width=i,a.height=n;var o=a.getContext("2d");o.drawImage(t,0,0);for(var s,h,l,u,c=o.getImageData(0,0,i,n).data,f=o.createImageData(i,n),d=f.data,p=0;p<i;p++)for(var E=0;E<n;E++){var m=E-1<0?0:E-1,g=n-1<E+1?n-1:E+1,v=p-1<0?0:p-1,T=i-1<p+1?i-1:p+1,x=[],y=[0,0,c[4*(E*i+p)]/255*e];x.push([-1,0,c[4*(E*i+v)]/255*e]),x.push([-1,-1,c[4*(m*i+v)]/255*e]),x.push([0,-1,c[4*(m*i+p)]/255*e]),x.push([1,-1,c[4*(m*i+T)]/255*e]),x.push([1,0,c[4*(E*i+T)]/255*e]),x.push([1,1,c[4*(g*i+T)]/255*e]),x.push([0,1,c[4*(g*i+p)]/255*e]),x.push([-1,1,c[4*(g*i+v)]/255*e]);for(var R=[],_=x.length,H=0;H<_;H++){var b=x[H],M=x[(H+1)%_];b=r(b,y),M=r(M,y),R.push((u=M,s=[(l=b)[1]*u[2]-l[2]*u[1],l[2]*u[0]-l[0]*u[2],l[0]*u[1]-l[1]*u[0]],void 0,h=Math.sqrt(s[0]*s[0]+s[1]*s[1]+s[2]*s[2]),[s[0]/h,s[1]/h,s[2]/h]))}var w=[0,0,0];for(H=0;H<R.length;H++)w[0]+=R[H][0],w[1]+=R[H][1],w[2]+=R[H][2];w[0]/=R.length,w[1]/=R.length,w[2]/=R.length;var S=4*(E*i+p);d[S]=(w[0]+1)/2*255|0,d[S+1]=(w[1]+1)/2*255|0,d[S+2]=255*w[2]|0,d[S+3]=255}return o.putImageData(f,0,0),a},generateDataTexture:function(t,e,r){for(var i=t*e,n=new Uint8Array(3*i),a=Math.floor(255*r.r),o=Math.floor(255*r.g),s=Math.floor(255*r.b),h=0;h<i;h++)n[3*h]=a,n[3*h+1]=o,n[3*h+2]=s;var l=new THREE.DataTexture(n,t,e,THREE.RGBFormat);return l.needsUpdate=!0,l}},THREE.SphereGeometry=function(t,e,r,i,n,a,o){THREE.Geometry.call(this),this.type="SphereGeometry",this.parameters={radius:t,widthSegments:e,heightSegments:r,phiStart:i,phiLength:n,thetaStart:a,thetaLength:o},t=t||50,e=Math.max(3,Math.floor(e)||8),r=Math.max(2,Math.floor(r)||6),i=void 0!==i?i:0,n=void 0!==n?n:2*Math.PI,a=void 0!==a?a:0,o=void 0!==o?o:Math.PI;var s,h,l=[],u=[];for(h=0;h<=r;h++){var c=[],f=[];for(s=0;s<=e;s++){var d=s/e,p=h/r,E=new THREE.Vector3;E.x=-t*Math.cos(i+d*n)*Math.sin(a+p*o),E.y=t*Math.cos(a+p*o),E.z=t*Math.sin(i+d*n)*Math.sin(a+p*o),this.vertices.push(E),c.push(this.vertices.length-1),f.push(new THREE.Vector2(d,1-p))}l.push(c),u.push(f)}for(h=0;h<r;h++)for(s=0;s<e;s++){var m=l[h][s+1],g=l[h][s],v=l[h+1][s],T=l[h+1][s+1],x=this.vertices[m].clone().normalize(),y=this.vertices[g].clone().normalize(),R=this.vertices[v].clone().normalize(),_=this.vertices[T].clone().normalize(),H=u[h][s+1].clone(),b=u[h][s].clone(),M=u[h+1][s].clone(),w=u[h+1][s+1].clone();Math.abs(this.vertices[m].y)===t?(H.x=(H.x+b.x)/2,this.faces.push(new THREE.Face3(m,v,T,[x,R,_])),this.faceVertexUvs[0].push([H,M,w])):Math.abs(this.vertices[v].y)===t?(M.x=(M.x+w.x)/2,this.faces.push(new THREE.Face3(m,g,v,[x,y,R])),this.faceVertexUvs[0].push([H,b,M])):(this.faces.push(new THREE.Face3(m,g,T,[x,y,_])),this.faceVertexUvs[0].push([H,b,w]),this.faces.push(new THREE.Face3(g,v,T,[y.clone(),R,_.clone()])),this.faceVertexUvs[0].push([b.clone(),M,w.clone()]))}this.computeFaceNormals(),this.boundingSphere=new THREE.Sphere(new THREE.Vector3,t)},THREE.SphereGeometry.prototype=Object.create(THREE.Geometry.prototype);
readme.txt CHANGED
@@ -2,8 +2,8 @@
2
  Contributors: opajaap
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=OpaJaap@OpaJaap.nl&item_name=WP-Photo-Album-Plus&item_number=Support-Open-Source&currency_code=USD&lc=US
4
  Tags: photo, album, slideshow, video, audio, lightbox, iptc, exif, cloudinary, fotomoto, imagemagick, pdf
5
- Version: 6.9.11
6
- Stable tag: 6.9.10
7
  Author: J.N. Breetvelt
8
  Author URI: http://www.opajaap.nl/
9
  Requires at least: 3.9
@@ -137,9 +137,13 @@ See for the full changelog: <a href="http://www.wppa.nl/changelog/" >The documen
137
 
138
  == Upgrade Notice ==
139
 
 
 
 
 
140
  = 6.9.11 =
141
 
142
- * version addresses various minor bug fixes and performance improvements.
143
 
144
  = 6.9.10 =
145
 
2
  Contributors: opajaap
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=OpaJaap@OpaJaap.nl&item_name=WP-Photo-Album-Plus&item_number=Support-Open-Source&currency_code=USD&lc=US
4
  Tags: photo, album, slideshow, video, audio, lightbox, iptc, exif, cloudinary, fotomoto, imagemagick, pdf
5
+ Version: 6.9.12
6
+ Stable tag: 6.9.11
7
  Author: J.N. Breetvelt
8
  Author URI: http://www.opajaap.nl/
9
  Requires at least: 3.9
137
 
138
  == Upgrade Notice ==
139
 
140
+ = 6.9.12 =
141
+
142
+ * This version addresses various minor bug fixes and performance improvements.
143
+
144
  = 6.9.11 =
145
 
146
+ * This version addresses various minor bug fixes and performance improvements.
147
 
148
  = 6.9.10 =
149
 
wppa-admin.php CHANGED
@@ -3,7 +3,7 @@
3
  * Package: wp-photo-album-plus
4
  *
5
  * Contains the admin menu and startups the admin pages
6
- * Version 6.9.06
7
  *
8
  */
9
 
@@ -408,4 +408,27 @@ function wppa_show_potd_log() {
408
  __( 'There is no photo of the day history', 'wp-photo-album-plus' ) .
409
  '</p>';
410
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
411
  }
3
  * Package: wp-photo-album-plus
4
  *
5
  * Contains the admin menu and startups the admin pages
6
+ * Version 6.9.12
7
  *
8
  */
9
 
408
  __( 'There is no photo of the day history', 'wp-photo-album-plus' ) .
409
  '</p>';
410
  }
411
+ }
412
+
413
+ // Load pnoama js if needed at the backend
414
+ if ( get_option( 'wppa_enable_panorama' ) == 'yes' ) {
415
+ add_action( 'admin_footer', 'wppa_load_panorama_js' );
416
+ }
417
+ function wppa_load_panorama_js() {
418
+
419
+ if ( wppa( 'has_panorama' ) ) {
420
+ if ( is_file ( WPPA_PATH . '/js/wppa-panorama.min.js' ) ) {
421
+ $three_url = WPPA_URL . '/js/wppa-panorama.min.js';
422
+ $ver = $wppa_api_version;
423
+ }
424
+ elseif ( is_file ( WPPA_PATH . '/js/wppa-panorama.js' ) ) {
425
+ $three_url = WPPA_URL . '/js/wppa-panorama.js';
426
+ $ver = $wppa_api_version;
427
+ }
428
+ else {
429
+ $three_url = WPPA_URL . '/vendor/three/three.min.js';
430
+ $ver = '69';
431
+ }
432
+ wp_enqueue_script( 'wppa-three-min-js', $three_url, array(), $ver, true );
433
+ }
434
  }
wppa-admins-choice-widget.php CHANGED
@@ -3,7 +3,7 @@
3
  * Package: wp-photo-album-plus
4
  *
5
  * display the admins-choice widget
6
- * Version 6.8.07
7
  *
8
  */
9
 
@@ -69,6 +69,10 @@ class AdminsChoice extends WP_Widget {
69
  function update( $new_instance, $old_instance ) {
70
 
71
  $instance = $old_instance;
 
 
 
 
72
  $instance['title'] = strip_tags( $new_instance['title'] );
73
  $instance['logonly'] = $new_instance['logonly'];
74
  return $instance;
3
  * Package: wp-photo-album-plus
4
  *
5
  * display the admins-choice widget
6
+ * Version 6.9.12
7
  *
8
  */
9
 
69
  function update( $new_instance, $old_instance ) {
70
 
71
  $instance = $old_instance;
72
+
73
+ // Defaults
74
+ $instance = wp_parse_args( (array) $instance, array( 'title' => __( 'Admins Choice', 'wp-photo-album-plus' ), 'logonly' => 'no' ) );
75
+
76
  $instance['title'] = strip_tags( $new_instance['title'] );
77
  $instance['logonly'] = $new_instance['logonly'];
78
  return $instance;
wppa-album-navigator-widget.php CHANGED
@@ -3,7 +3,7 @@
3
  * Package: wp-photo-album-plus
4
  *
5
  * display album names linking to content
6
- * Version 6.8.08
7
  */
8
 
9
  class AlbumNavigatorWidget extends WP_Widget {
@@ -89,6 +89,15 @@ class AlbumNavigatorWidget extends WP_Widget {
89
  /** @see WP_Widget::update */
90
  function update( $new_instance, $old_instance ) {
91
  $instance = $old_instance;
 
 
 
 
 
 
 
 
 
92
  $instance['title'] = strip_tags( $new_instance['title'] );
93
  $instance['parent'] = $new_instance['parent'];
94
  $instance['skip'] = $new_instance['skip'];
@@ -101,7 +110,6 @@ class AlbumNavigatorWidget extends WP_Widget {
101
  global $wpdb;
102
 
103
  //Defaults
104
-
105
  $instance = wp_parse_args( (array) $instance, array(
106
  'title' => __( 'Album Navigator', 'wp-photo-album-plus' ),
107
  'parent' => '0',
3
  * Package: wp-photo-album-plus
4
  *
5
  * display album names linking to content
6
+ * Version 6.9.12
7
  */
8
 
9
  class AlbumNavigatorWidget extends WP_Widget {
89
  /** @see WP_Widget::update */
90
  function update( $new_instance, $old_instance ) {
91
  $instance = $old_instance;
92
+
93
+ //Defaults
94
+ $instance = wp_parse_args( (array) $instance, array(
95
+ 'title' => __( 'Album Navigator', 'wp-photo-album-plus' ),
96
+ 'parent' => '0',
97
+ 'skip' => 'yes',
98
+ 'logonly' => 'no',
99
+ ) );
100
+
101
  $instance['title'] = strip_tags( $new_instance['title'] );
102
  $instance['parent'] = $new_instance['parent'];
103
  $instance['skip'] = $new_instance['skip'];
110
  global $wpdb;
111
 
112
  //Defaults
 
113
  $instance = wp_parse_args( (array) $instance, array(
114
  'title' => __( 'Album Navigator', 'wp-photo-album-plus' ),
115
  'parent' => '0',
wppa-album-widget.php CHANGED
@@ -3,7 +3,7 @@
3
  * Package: wp-photo-album-plus
4
  *
5
  * display thumbnail albums
6
- * Version 6.9.09
7
  */
8
 
9
  if ( ! defined( 'ABSPATH' ) ) die( "Can't load this file directly" );
@@ -321,6 +321,16 @@ class AlbumWidget extends WP_Widget {
321
  /** @see WP_Widget::update */
322
  function update( $new_instance, $old_instance ) {
323
  $instance = $old_instance;
 
 
 
 
 
 
 
 
 
 
324
  $instance['title'] = strip_tags( $new_instance['title'] );
325
  $instance['parent'] = $new_instance['parent'];
326
  $instance['name'] = $new_instance['name'];
3
  * Package: wp-photo-album-plus
4
  *
5
  * display thumbnail albums
6
+ * Version 6.9.12
7
  */
8
 
9
  if ( ! defined( 'ABSPATH' ) ) die( "Can't load this file directly" );
321
  /** @see WP_Widget::update */
322
  function update( $new_instance, $old_instance ) {
323
  $instance = $old_instance;
324
+
325
+ //Defaults
326
+ $instance = wp_parse_args( (array) $instance, array(
327
+ 'title' => __( 'Thumbnail Albums', 'wp-photo-album-plus' ),
328
+ 'parent' => '0',
329
+ 'name' => 'no',
330
+ 'skip' => 'yes',
331
+ 'logonly' => 'no',
332
+ ) );
333
+
334
  $instance['title'] = strip_tags( $new_instance['title'] );
335
  $instance['parent'] = $new_instance['parent'];
336
  $instance['name'] = $new_instance['name'];
wppa-bestof-widget.php CHANGED
@@ -3,7 +3,7 @@
3
  * Package: wp-photo-album-plus
4
  *
5
  * display the best rated photos
6
- * Version 6.8.07
7
  *
8
  */
9
 
@@ -92,6 +92,22 @@ class BestOfWidget extends WP_Widget {
92
  function update( $new_instance, $old_instance ) {
93
 
94
  $instance = $old_instance;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
  $instance['title'] = strip_tags( $new_instance['title'] );
96
  $instance['count'] = $new_instance['count'];
97
  $instance['sortby'] = $new_instance['sortby'];
3
  * Package: wp-photo-album-plus
4
  *
5
  * display the best rated photos
6
+ * Version 6.9.12
7
  *
8
  */
9
 
92
  function update( $new_instance, $old_instance ) {
93
 
94
  $instance = $old_instance;
95
+
96
+ // Defaults
97
+ $instance = wp_parse_args( (array) $instance, array(
98
+ 'title' => __( 'Best Of Photos', 'wp-photo-album-plus' ),
99
+ 'count' => '10',
100
+ 'sortby' => 'maxratingcount',
101
+ 'display' => 'photo',
102
+ 'period' => 'thisweek',
103
+ 'maxratings'=> 'yes',
104
+ 'meanrat' => 'yes',
105
+ 'ratcount' => 'yes',
106
+ 'linktype' => 'none',
107
+ 'totvalue' => '',
108
+ 'logonly' => 'no',
109
+ ) );
110
+
111
  $instance['title'] = strip_tags( $new_instance['title'] );
112
  $instance['count'] = $new_instance['count'];
113
  $instance['sortby'] = $new_instance['sortby'];
wppa-comment-widget.php CHANGED
@@ -3,7 +3,7 @@
3
  * Package: wp-photo-album-plus
4
  *
5
  * display the recent commets on photos
6
- * Version 6.8.07
7
  */
8
 
9
  if ( ! defined( 'ABSPATH' ) ) die( "Can't load this file directly" );
@@ -115,6 +115,10 @@ class wppaCommentWidget extends WP_Widget {
115
  function update( $new_instance, $old_instance ) {
116
 
117
  $instance = $old_instance;
 
 
 
 
118
  $instance['title'] = strip_tags( $new_instance['title'] );
119
  $instance['logonly'] = $new_instance['logonly'];
120
 
3
  * Package: wp-photo-album-plus
4
  *
5
  * display the recent commets on photos
6
+ * Version 6.9.12
7
  */
8
 
9
  if ( ! defined( 'ABSPATH' ) ) die( "Can't load this file directly" );
115
  function update( $new_instance, $old_instance ) {
116
 
117
  $instance = $old_instance;
118
+
119
+ //Defaults
120
+ $instance = wp_parse_args( (array) $instance, array( 'title' => __( 'Comments on Photos', 'wp-photo-album-plus' ), 'logonly' => 'no' ) );
121
+
122
  $instance['title'] = strip_tags( $new_instance['title'] );
123
  $instance['logonly'] = $new_instance['logonly'];
124
 
wppa-common-functions.php CHANGED
@@ -2,7 +2,7 @@
2
  /* wppa-common-functions.php
3
  *
4
  * Functions used in admin and in themes
5
- * Version 6.9.01
6
  *
7
  */
8
 
@@ -79,6 +79,7 @@ global $thumbs;
79
  $wocc = isset( $wppa['widget_occur'] ) ? $wppa['widget_occur'] : '0';
80
  $rend = isset( $wppa['rendering_enabled'] ) ? $wppa['rendering_enabled'] : false;
81
  $debug = isset( $wppa['debug'] ) ? $wppa['debug'] : false;
 
82
  $ajax = defined( 'DOING_AJAX' ) ? true : false;
83
  $cron = wppa_is_cron();
84
 
@@ -219,6 +220,7 @@ global $thumbs;
219
  'max_slides_in_ss_widget' => '',
220
  'is_random' => false,
221
  'cron' => $cron,
 
222
 
223
  );
224
  }
2
  /* wppa-common-functions.php
3
  *
4
  * Functions used in admin and in themes
5
+ * Version 6.9.12
6
  *
7
  */
8
 
79
  $wocc = isset( $wppa['widget_occur'] ) ? $wppa['widget_occur'] : '0';
80
  $rend = isset( $wppa['rendering_enabled'] ) ? $wppa['rendering_enabled'] : false;
81
  $debug = isset( $wppa['debug'] ) ? $wppa['debug'] : false;
82
+ $pano = isset( $wppa['has_panorama'] ) ? $wppa['has_panorama'] : false;
83
  $ajax = defined( 'DOING_AJAX' ) ? true : false;
84
  $cron = wppa_is_cron();
85
 
220
  'max_slides_in_ss_widget' => '',
221
  'is_random' => false,
222
  'cron' => $cron,
223
+ 'has_panorama' => $pano,
224
 
225
  );
226
  }
wppa-featen-widget.php CHANGED
@@ -3,7 +3,7 @@
3
  * Package: wp-photo-album-plus
4
  *
5
  * display the featured photos
6
- * Version 6.8.07
7
  */
8
 
9
  if ( ! defined( 'ABSPATH' ) ) die( "Can't load this file directly" );
@@ -178,6 +178,10 @@ class FeaTenWidget extends WP_Widget {
178
  function update( $new_instance, $old_instance ) {
179
 
180
  $instance = $old_instance;
 
 
 
 
181
  $instance['title'] = strip_tags( $new_instance['title'] );
182
  $instance['album'] = $new_instance['album'];
183
  $instance['logonly'] = $new_instance['logonly'];
3
  * Package: wp-photo-album-plus
4
  *
5
  * display the featured photos
6
+ * Version 6.9.12
7
  */
8
 
9
  if ( ! defined( 'ABSPATH' ) ) die( "Can't load this file directly" );
178
  function update( $new_instance, $old_instance ) {
179
 
180
  $instance = $old_instance;
181
+
182
+ //Defaults
183
+ $instance = wp_parse_args( (array) $instance, array( 'title' => __( 'Featured Photos', 'wp-photo-album-plus' ), 'album' => '0', 'logonly' => 'no' ) );
184
+
185
  $instance['title'] = strip_tags( $new_instance['title'] );
186
  $instance['album'] = $new_instance['album'];
187
  $instance['logonly'] = $new_instance['logonly'];
wppa-gp-widget.php CHANGED
@@ -4,7 +4,7 @@
4
  *
5
  * A text widget that interpretes wppa shortcodes
6
  *
7
- * Version 6.8.07
8
  */
9
 
10
  class WppaGpWidget extends WP_Widget {
@@ -67,6 +67,8 @@ class WppaGpWidget extends WP_Widget {
67
  function update( $new_instance, $old_instance ) {
68
 
69
  $instance = $old_instance;
 
 
70
  $instance['title'] = strip_tags( $new_instance['title'] );
71
  if ( current_user_can('unfiltered_html') )
72
  $instance['text'] = $new_instance['text'];
4
  *
5
  * A text widget that interpretes wppa shortcodes
6
  *
7
+ * Version 6.9.12
8
  */
9
 
10
  class WppaGpWidget extends WP_Widget {
67
  function update( $new_instance, $old_instance ) {
68
 
69
  $instance = $old_instance;
70
+ $instance = wp_parse_args( (array) $instance, array( 'title' => __( 'Text', 'wp-photo-album-plus' ), 'text' => '', 'filter' => false, 'loggedinonly' => false ) );
71
+
72
  $instance['title'] = strip_tags( $new_instance['title'] );
73
  if ( current_user_can('unfiltered_html') )
74
  $instance['text'] = $new_instance['text'];
wppa-init.php CHANGED
@@ -4,7 +4,7 @@
4
  *
5
  * This file loads required php files and contains all functions used in init actions.
6
  *
7
- * Version 6.9.04
8
  */
9
 
10
  /* LOAD SIDEBAR WIDGETS */
@@ -64,6 +64,7 @@ require_once 'wppa-functions.php';
64
  require_once 'wppa-thumbnails.php';
65
  require_once 'wppa-boxes-html.php';
66
  require_once 'wppa-slideshow.php';
 
67
 
68
  /* Load cloudinary if configured and php version >= 5.3 */
69
  if ( PHP_VERSION_ID >= 50300 ) require_once 'wppa-cloudinary.php';
4
  *
5
  * This file loads required php files and contains all functions used in init actions.
6
  *
7
+ * Version 6.9.12
8
  */
9
 
10
  /* LOAD SIDEBAR WIDGETS */
64
  require_once 'wppa-thumbnails.php';
65
  require_once 'wppa-boxes-html.php';
66
  require_once 'wppa-slideshow.php';
67
+ require_once 'wppa-picture.php';
68
 
69
  /* Load cloudinary if configured and php version >= 5.3 */
70
  if ( PHP_VERSION_ID >= 50300 ) require_once 'wppa-cloudinary.php';
wppa-lasten-widget.php CHANGED
@@ -3,7 +3,7 @@
3
  * Package: wp-photo-album-plus
4
  *
5
  * display the last uploaded photos
6
- * Version 6.8.07
7
  */
8
 
9
  class LasTenWidget extends WP_Widget {
@@ -173,6 +173,18 @@ class LasTenWidget extends WP_Widget {
173
  /** @see WP_Widget::update */
174
  function update($new_instance, $old_instance) {
175
  $instance = $old_instance;
 
 
 
 
 
 
 
 
 
 
 
 
176
  $instance['title'] = strip_tags($new_instance['title']);
177
  $instance['album'] = strval( intval( $new_instance['album'] ) );
178
  $instance['albumenum'] = $new_instance['albumenum'];
3
  * Package: wp-photo-album-plus
4
  *
5
  * display the last uploaded photos
6
+ * Version 6.9.12
7
  */
8
 
9
  class LasTenWidget extends WP_Widget {
173
  /** @see WP_Widget::update */
174
  function update($new_instance, $old_instance) {
175
  $instance = $old_instance;
176
+
177
+ //Defaults
178
+ $instance = wp_parse_args( (array) $instance, array(
179
+ 'title' => __( 'Last Ten Photos', 'wp-photo-album-plus' ),
180
+ 'album' => '0',
181
+ 'albumenum' => '',
182
+ 'timesince' => 'yes',
183
+ 'display' => 'thumbs',
184
+ 'includesubs' => 'no',
185
+ 'logonly' => 'no',
186
+ ) );
187
+
188
  $instance['title'] = strip_tags($new_instance['title']);
189
  $instance['album'] = strval( intval( $new_instance['album'] ) );
190
  $instance['albumenum'] = $new_instance['albumenum'];
wppa-non-admin.php CHANGED
@@ -3,7 +3,7 @@
3
  * Package: wp-photo-album-plus
4
  *
5
  * Contains all the non admin stuff
6
- * Version 6.9.11
7
  *
8
  */
9
 
@@ -14,7 +14,6 @@ require_once 'wppa-filter.php';
14
  require_once 'wppa-breadcrumb.php';
15
  require_once 'wppa-album-covers.php';
16
  require_once 'wppa-cart.php';
17
- require_once 'wppa-picture.php';
18
  require_once 'wppa-tinymce-photo-front.php';
19
 
20
  /* LOAD STYLESHEET */
@@ -430,8 +429,24 @@ global $wppa_opt;
430
 
431
  // Panorama
432
  if ( wppa_switch( 'enable_panorama' ) ) {
433
- $three_url = WPPA_URL . '/vendor/three/three.min.js';
434
- wp_enqueue_script( 'wppa-three-min-js', $three_url );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
435
  }
436
 
437
  // wppa-init
3
  * Package: wp-photo-album-plus
4
  *
5
  * Contains all the non admin stuff
6
+ * Version 6.9.12
7
  *
8
  */
9
 
14
  require_once 'wppa-breadcrumb.php';
15
  require_once 'wppa-album-covers.php';
16
  require_once 'wppa-cart.php';
 
17
  require_once 'wppa-tinymce-photo-front.php';
18
 
19
  /* LOAD STYLESHEET */
429
 
430
  // Panorama
431
  if ( wppa_switch( 'enable_panorama' ) ) {
432
+
433
+ // Only if either in header or in footer and panorama's on the page found
434
+ if ( ! wppa_switch( 'defer_javascript' ) || ( wppa_switch( 'defer_javascript' ) && wppa( 'has_panorama' ) ) ) {
435
+
436
+ if ( is_file ( WPPA_PATH . '/js/wppa-panorama.min.js' ) ) {
437
+ $three_url = WPPA_URL . '/js/wppa-panorama.min.js';
438
+ $ver = $wppa_api_version;
439
+ }
440
+ elseif ( is_file ( WPPA_PATH . '/js/wppa-panorama.js' ) ) {
441
+ $three_url = WPPA_URL . '/js/wppa-panorama.js';
442
+ $ver = $wppa_api_version;
443
+ }
444
+ else {
445
+ $three_url = WPPA_URL . '/vendor/three/three.min.js';
446
+ $ver = '69';
447
+ }
448
+ wp_enqueue_script( 'wppa-three-min-js', $three_url, array(), $ver );
449
+ }
450
  }
451
 
452
  // wppa-init
wppa-picture.php CHANGED
@@ -3,7 +3,7 @@
3
  * Package: wp-photo-album-plus
4
  *
5
  * Make the picture html
6
- * Version 6.9.11
7
  *
8
  */
9
 
@@ -297,9 +297,10 @@ function wppa_get_lb_panorama_html( $id ) {
297
  // Get the html for a pan image
298
  function wppa_get_panorama_html( $args ) {
299
 
 
300
  if ( ! isset( $args['id'] ) ) return;
301
 
302
- $args['controls'] = wppa_opt( 'panorama_control' ) == 'all' || wppa_is_mobile();
303
  $args['manual'] = wppa_opt( 'panorama_manual' ) == 'all' ? true : false;
304
  $args['autorun'] = wppa_opt( 'panorama_autorun' ) == 'none' ? '' : wppa_opt( 'panorama_autorun' );
305
  $args['autorunspeed'] = wppa_opt( 'panorama_autorun_speed' );
@@ -309,6 +310,9 @@ function wppa_get_panorama_html( $args ) {
309
 
310
  case '1':
311
  $result = wppa_get_spheric_pan_html( $args );
 
 
 
312
  break;
313
  case '2':
314
  $result = wppa_get_flat_pan_html( $args );
@@ -354,7 +358,7 @@ function wppa_get_spheric_pan_html( $args ) {
354
  $autorunspeed = $args['autorunspeed'];
355
  $zoomsensitivity = $args['zoomsensitivity'];
356
 
357
- $url = wppa_is_mobile() ? wppa_get_photo_url( $id ) : wppa_get_hires_url( $id );
358
 
359
  $result =
360
  ( $lightbox ? $id . '.' : '' ) .
@@ -363,7 +367,7 @@ function wppa_get_spheric_pan_html( $args ) {
363
  '<div
364
  id="wppa-pan-div-' . $mocc . '"
365
  class="wppa-pan-div wppa-pan-div-' . $mocc . '"
366
- style="' . ( $controls ? 'margin-bottom:4px;' : '' ) . 'cursor:grab;line-height:0;"
367
  >
368
  </div>' .
369
  ( $controls ?
@@ -487,58 +491,69 @@ function wppa_get_spheric_pan_html( $args ) {
487
  '' ) .
488
 
489
  // Lghtbox uses the global vars used for the webGL context
490
- ( $lightbox ?
491
- 'if ( ! renderer ) {
492
- renderer = new THREE.WebGLRenderer();
493
- }
494
- renderer.setSize(' . $width . ', ' . $height . ');
495
- $(div).append(renderer.domElement);
496
- if ( ! scene ) {
497
- scene = new THREE.Scene();
498
- }
499
- if ( ! camera ) {
500
- camera = new THREE.PerspectiveCamera(fov, aspect, 1, 1000);
501
- camera.target = new THREE.Vector3(0, 0, 0);
502
- }
503
- if ( ! sphere ) {
504
- sphere = new THREE.SphereGeometry(100, 100, 40);
505
- sphere.applyMatrix(new THREE.Matrix4().makeScale(-1, 1, 1));
506
  }
507
- if ( ! sphereMaterial ) {
508
- sphereMaterial = new THREE.MeshBasicMaterial();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
509
  }
510
- sphereMaterial.map = THREE.ImageUtils.loadTexture("' . $url . '");
511
- if ( ! sphereMesh ) {
512
- sphereMesh = new THREE.Mesh(sphere, sphereMaterial);
513
- scene.add(sphereMesh);
 
 
514
  }
515
- ' :
516
-
517
- // setting up the renderer
518
- 'var renderer = new THREE.WebGLRenderer();
519
- renderer.setSize(' . $width . ', ' . $height . ');' .
520
 
521
  // Place the element
522
- '$(div).append(renderer.domElement);' .
523
 
524
- // creating a new scene
525
- 'var scene = new THREE.Scene();' .
526
 
527
- // adding a camera
528
- 'var camera = new THREE.PerspectiveCamera(fov, aspect, 1, 1000);
529
- camera.target = new THREE.Vector3(0, 0, 0);' .
530
 
531
- // creation of a big sphere geometry
532
- 'var sphere = new THREE.SphereGeometry(100, 100, 40);
533
- sphere.applyMatrix(new THREE.Matrix4().makeScale(-1, 1, 1));' .
534
 
535
- // creation of the sphere material
536
- 'var sphereMaterial = new THREE.MeshBasicMaterial();
537
- sphereMaterial.map = THREE.ImageUtils.loadTexture("' . $url . '");' .
538
 
539
  // geometry + material = mesh (actual object)
540
- 'var sphereMesh = new THREE.Mesh(sphere, sphereMaterial);
541
- scene.add(sphereMesh);'
542
  ) .
543
 
544
  // listeners
@@ -578,7 +593,6 @@ function wppa_get_spheric_pan_html( $args ) {
578
 
579
  // Common event handlers
580
  ( $lightbox ? '
581
- $("#wppa-fulls-btn").on("click", panDie);
582
  if (prev) {
583
  prev.on("click", panPrev);
584
  next.on("click", panNext);
@@ -604,7 +618,6 @@ function wppa_get_spheric_pan_html( $args ) {
604
 
605
  // If the abort flag is risen, die gracefully
606
  'if(abort){
607
- panDie();
608
  return;
609
  }' .
610
 
@@ -618,14 +631,14 @@ function wppa_get_spheric_pan_html( $args ) {
618
  // limiting latitude from -85 to 85 (cannot point to the sky or under your feet)
619
  'latitude = Math.max(-85, Math.min(85, latitude));' .
620
 
621
- // moving the camera according to current latitude (vertical movement) and longitude (horizontal movement)
622
- 'camera.target.x = 500 * Math.sin(THREE.Math.degToRad(90 - latitude)) * Math.cos(THREE.Math.degToRad(longitude));
623
- camera.target.y = 500 * Math.cos(THREE.Math.degToRad(90 - latitude));
624
- camera.target.z = 500 * Math.sin(THREE.Math.degToRad(90 - latitude)) * Math.sin(THREE.Math.degToRad(longitude));
625
- camera.lookAt(camera.target);' .
626
 
627
  // calling again render function
628
- 'renderer.render(scene, camera);
629
  }' .
630
 
631
  // Mouse wheel
@@ -639,8 +652,8 @@ function wppa_get_spheric_pan_html( $args ) {
639
  'function doZoom(once){
640
  fov += deltaFov;
641
  fov = Math.max(20, Math.min(120, fov));
642
- camera = new THREE.PerspectiveCamera(fov, aspect, 1, 1000);
643
- camera.target = new THREE.Vector3(0, 0, 0);
644
  if ( ! once && deltaFov != 0 ) {
645
  setTimeout(function(){doZoom()}, 25);
646
  }
@@ -651,7 +664,6 @@ function wppa_get_spheric_pan_html( $args ) {
651
 
652
  // Previous
653
  'function panPrev(e) {
654
- panDie();
655
  var stop;
656
  if ( ! stop ) {
657
  stop = true;
@@ -664,7 +676,6 @@ function wppa_get_spheric_pan_html( $args ) {
664
 
665
  // Next
666
  'function panNext(e) {
667
- panDie();
668
  var stop;
669
  if ( ! stop ) {
670
  stop = true;
@@ -728,26 +739,14 @@ function wppa_get_spheric_pan_html( $args ) {
728
  deltaFov=0;
729
  }' .
730
 
731
- // Stop this panorama
732
- 'function panDie() {
733
- /*
734
- wppaConsoleLog("Killing "+uniqueId);
735
- abort = true;
736
- scene = null;
737
- camera = null;
738
- sphere = null;
739
- sphereMaterial = null;
740
- sphereMesh = null;
741
- */
742
- }' .
743
-
744
- // When a (responsive) resize is required, we resize the scene
745
  'function onResize(e){' .
746
 
747
  ( $lightbox ?
748
 
749
  // Show image container
750
- '$("#wppa-overlay-ic").css("display", "");' .
 
751
 
752
  // There are 4 possiblilities: all combi of 'Width is the limit or not' and 'Mode is normal or fullscreen'
753
  'var widthIsLim,
@@ -763,7 +762,8 @@ function wppa_get_spheric_pan_html( $args ) {
763
  else {
764
  contWidth = screen.width;
765
  contHeight = screen.height;
766
- }' .
 
767
 
768
  // Initialize new display sizes
769
  'var newWidth,
@@ -846,14 +846,14 @@ function wppa_get_spheric_pan_html( $args ) {
846
  }
847
  }
848
 
849
- renderer.setSize(newWidth, newHeight);
850
  doZoom(true);
851
  ' :
852
  '
853
  var containerwidth = $(div).parent().width();
854
  var newWidth = containerwidth;
855
  var newHeight = newWidth * ' . ( $height / $width ) . ';
856
- renderer.setSize(newWidth, newHeight);
857
  doZoom(true);'
858
  ) . '
859
  }' .
@@ -909,7 +909,7 @@ function wppa_get_flat_pan_html( $args ) {
909
  $deltaX = '0';
910
  }
911
 
912
- $url = wppa_is_mobile() ? wppa_get_photo_url( $id ) : wppa_get_hires_url( $id );
913
 
914
  $result =
915
  ( $lightbox ? $id . '.' : '' ) .
@@ -1111,7 +1111,7 @@ function wppa_get_flat_pan_html( $args ) {
1111
  }' : '' ) .
1112
 
1113
  // Install Resize handler
1114
- '$(window).on("DOMContentLoaded load resize kickpanorama orientationchange",onResize' . $mocc . ');' .
1115
 
1116
  // Remove spinner
1117
  '$("#wppa-ovl-spin").hide();' .
@@ -1270,7 +1270,7 @@ function wppa_get_flat_pan_html( $args ) {
1270
  run=4;
1271
  }' .
1272
 
1273
- // When a (responsive) resize is required, we resize the scene
1274
  'function onResize' . $mocc . '(e){' .
1275
 
1276
  'if (abort) return;' .
@@ -1512,15 +1512,13 @@ function wppa_pan_min( $result ) {
1512
  $result = str_replace( array( ', ', '; ', '! ' ), array( ',', ';', '!' ), $result );
1513
 
1514
  // Trim braces
1515
- // $result = str_replace( array( ' ( ', '( ', ' (' ), '(', $result ); // Causes undefined error
1516
- $result = str_replace( ' ( ', '(', $result );
1517
- $result = str_replace( '( ', '(', $result );
1518
- // $result = str_replace( ' (', '(', $result ); // Causes undefined error
1519
  $result = str_replace( array( ' ) ', ') ', ' )' ), ')', $result );
 
1520
 
1521
  // Remove space between html tags
1522
  $result = str_replace( '> <', '><', $result );
1523
 
1524
  // wppa_log('dbg',' na len='.strlen($result));
 
1525
  return $result;
1526
  }
3
  * Package: wp-photo-album-plus
4
  *
5
  * Make the picture html
6
+ * Version 6.9.12
7
  *
8
  */
9
 
297
  // Get the html for a pan image
298
  function wppa_get_panorama_html( $args ) {
299
 
300
+ // If no id given, quit
301
  if ( ! isset( $args['id'] ) ) return;
302
 
303
+ $args['controls'] = ( wppa_opt( 'panorama_control' ) == 'all' ) || ( wppa_opt( 'panorama_control' ) == 'mobile' && wppa_is_mobile() );
304
  $args['manual'] = wppa_opt( 'panorama_manual' ) == 'all' ? true : false;
305
  $args['autorun'] = wppa_opt( 'panorama_autorun' ) == 'none' ? '' : wppa_opt( 'panorama_autorun' );
306
  $args['autorunspeed'] = wppa_opt( 'panorama_autorun_speed' );
310
 
311
  case '1':
312
  $result = wppa_get_spheric_pan_html( $args );
313
+
314
+ // Save we have a spheric panorama on board for loading THREE.js
315
+ wppa( 'has_panorama', true );
316
  break;
317
  case '2':
318
  $result = wppa_get_flat_pan_html( $args );
358
  $autorunspeed = $args['autorunspeed'];
359
  $zoomsensitivity = $args['zoomsensitivity'];
360
 
361
+ $url = esc_url( wppa_is_mobile() ? wppa_get_photo_url( $id ) : wppa_get_hires_url( $id ) );
362
 
363
  $result =
364
  ( $lightbox ? $id . '.' : '' ) .
367
  '<div
368
  id="wppa-pan-div-' . $mocc . '"
369
  class="wppa-pan-div wppa-pan-div-' . $mocc . '"
370
+ style="' . ( $controls ? 'margin-bottom:4px;' : '' ) . ( $manual ? 'cursor:grab;': '' ) . 'line-height:0;"
371
  >
372
  </div>' .
373
  ( $controls ?
491
  '' ) .
492
 
493
  // Lghtbox uses the global vars used for the webGL context
494
+ ( $lightbox ?
495
+ // setting up the renderer
496
+ 'if ( ! wppaRenderer ) {
497
+ wppaRenderer = new THREE.WebGLRenderer();
 
 
 
 
 
 
 
 
 
 
 
 
498
  }
499
+ wppaRenderer.setSize(' . $width . ', ' . $height . ');
500
+ $(div).append(wppaRenderer.domElement);' .
501
+
502
+ // Creating a new scene if not yet available
503
+ 'if ( ! wppaScene ) {
504
+ wppaScene = new THREE.Scene();
505
+ }' .
506
+
507
+ // Adding a camera
508
+ 'if ( ! wppaCamera ) {
509
+ wppaCamera = new THREE.PerspectiveCamera(fov, aspect, 1, 1000);
510
+ wppaCamera.target = new THREE.Vector3(0, 0, 0);
511
+ }' .
512
+
513
+ // Creation of a big sphere geometry
514
+ 'if ( ! wppaSphere ) {
515
+ wppaSphere = new THREE.SphereGeometry(100, 100, 40);
516
+ wppaSphere.applyMatrix(new THREE.Matrix4().makeScale(-1, 1, 1));
517
+ }' .
518
+
519
+ // Creation of the sphere material
520
+ 'if ( ! wppaSphereMaterial ) {
521
+ wppaSphereMaterial = new THREE.MeshBasicMaterial();
522
  }
523
+ wppaSphereMaterial.map = THREE.ImageUtils.loadTexture("' . $url . '");' .
524
+
525
+ // geometry + material = mesh (actual object)
526
+ 'if ( ! wppaSphereMesh ) {
527
+ wppaSphereMesh = new THREE.Mesh(wppaSphere, wppaSphereMaterial);
528
+ wppaScene.add(wppaSphereMesh);
529
  }
530
+ ' :
531
+
532
+ // setting up the wpparenderer
533
+ 'var wppaRenderer = new THREE.WebGLRenderer();
534
+ wppaRenderer.setSize(' . $width . ', ' . $height . ');' .
535
 
536
  // Place the element
537
+ '$(div).append(wppaRenderer.domElement);' .
538
 
539
+ // Creating a new scene
540
+ 'var wppaScene = new THREE.Scene();' .
541
 
542
+ // Adding a camera
543
+ 'var wppaCamera = new THREE.PerspectiveCamera(fov, aspect, 1, 1000);
544
+ wppaCamera.target = new THREE.Vector3(0, 0, 0);' .
545
 
546
+ // Creation of a big sphere geometry
547
+ 'var wppaSphere = new THREE.SphereGeometry(100, 100, 40);
548
+ wppaSphere.applyMatrix(new THREE.Matrix4().makeScale(-1, 1, 1));' .
549
 
550
+ // Creation of the sphere material
551
+ 'var wppaSphereMaterial = new THREE.MeshBasicMaterial();
552
+ wppaSphereMaterial.map = THREE.ImageUtils.loadTexture("' . $url . '");' .
553
 
554
  // geometry + material = mesh (actual object)
555
+ 'var wppaSphereMesh = new THREE.Mesh(wppaSphere, wppaSphereMaterial);
556
+ wppaScene.add(wppaSphereMesh);'
557
  ) .
558
 
559
  // listeners
593
 
594
  // Common event handlers
595
  ( $lightbox ? '
 
596
  if (prev) {
597
  prev.on("click", panPrev);
598
  next.on("click", panNext);
618
 
619
  // If the abort flag is risen, die gracefully
620
  'if(abort){
 
621
  return;
622
  }' .
623
 
631
  // limiting latitude from -85 to 85 (cannot point to the sky or under your feet)
632
  'latitude = Math.max(-85, Math.min(85, latitude));' .
633
 
634
+ // moving the wppaCamera according to current latitude (vertical movement) and longitude (horizontal movement)
635
+ 'wppaCamera.target.x = 500 * Math.sin(THREE.Math.degToRad(90 - latitude)) * Math.cos(THREE.Math.degToRad(longitude));
636
+ wppaCamera.target.y = 500 * Math.cos(THREE.Math.degToRad(90 - latitude));
637
+ wppaCamera.target.z = 500 * Math.sin(THREE.Math.degToRad(90 - latitude)) * Math.sin(THREE.Math.degToRad(longitude));
638
+ wppaCamera.lookAt(wppaCamera.target);' .
639
 
640
  // calling again render function
641
+ 'wppaRenderer.render(wppaScene, wppaCamera);
642
  }' .
643
 
644
  // Mouse wheel
652
  'function doZoom(once){
653
  fov += deltaFov;
654
  fov = Math.max(20, Math.min(120, fov));
655
+ wppaCamera = new THREE.PerspectiveCamera(fov, aspect, 1, 1000);
656
+ wppaCamera.target = new THREE.Vector3(0, 0, 0);
657
  if ( ! once && deltaFov != 0 ) {
658
  setTimeout(function(){doZoom()}, 25);
659
  }
664
 
665
  // Previous
666
  'function panPrev(e) {
 
667
  var stop;
668
  if ( ! stop ) {
669
  stop = true;
676
 
677
  // Next
678
  'function panNext(e) {
 
679
  var stop;
680
  if ( ! stop ) {
681
  stop = true;
739
  deltaFov=0;
740
  }' .
741
 
742
+ // When a (responsive) resize is required, we resize the wppaScene
 
 
 
 
 
 
 
 
 
 
 
 
 
743
  'function onResize(e){' .
744
 
745
  ( $lightbox ?
746
 
747
  // Show image container
748
+ '$("#wppa-overlay-ic").css("display", "");
749
+ $("#wppa-overlay-ic").css("width", "");' .
750
 
751
  // There are 4 possiblilities: all combi of 'Width is the limit or not' and 'Mode is normal or fullscreen'
752
  'var widthIsLim,
762
  else {
763
  contWidth = screen.width;
764
  contHeight = screen.height;
765
+ }'.
766
+ // alert("contWidth="+contWidth);' .
767
 
768
  // Initialize new display sizes
769
  'var newWidth,
846
  }
847
  }
848
 
849
+ wppaRenderer.setSize(newWidth, newHeight);
850
  doZoom(true);
851
  ' :
852
  '
853
  var containerwidth = $(div).parent().width();
854
  var newWidth = containerwidth;
855
  var newHeight = newWidth * ' . ( $height / $width ) . ';
856
+ wppaRenderer.setSize(newWidth, newHeight);
857
  doZoom(true);'
858
  ) . '
859
  }' .
909
  $deltaX = '0';
910
  }
911
 
912
+ $url = esc_url( wppa_is_mobile() ? wppa_get_photo_url( $id ) : wppa_get_hires_url( $id ) );
913
 
914
  $result =
915
  ( $lightbox ? $id . '.' : '' ) .
1111
  }' : '' ) .
1112
 
1113
  // Install Resize handler
1114
+ '$(window).on("DOMContentLoaded load resize orientationchange",onResize' . $mocc . ');' .
1115
 
1116
  // Remove spinner
1117
  '$("#wppa-ovl-spin").hide();' .
1270
  run=4;
1271
  }' .
1272
 
1273
+ // When a (responsive) resize is required, we resize the wppaScene
1274
  'function onResize' . $mocc . '(e){' .
1275
 
1276
  'if (abort) return;' .
1512
  $result = str_replace( array( ', ', '; ', '! ' ), array( ',', ';', '!' ), $result );
1513
 
1514
  // Trim braces
 
 
 
 
1515
  $result = str_replace( array( ' ) ', ') ', ' )' ), ')', $result );
1516
+ $result = str_replace( array( ' ( ', '( ', ' (' ), '(', $result );
1517
 
1518
  // Remove space between html tags
1519
  $result = str_replace( '> <', '><', $result );
1520
 
1521
  // wppa_log('dbg',' na len='.strlen($result));
1522
+ // wppa_dump($result);
1523
  return $result;
1524
  }
wppa-potd-widget.php CHANGED
@@ -3,7 +3,7 @@
3
  * Package: wp-photo-album-plus
4
  *
5
  * display the widget
6
- * Version 6.9.09
7
  */
8
 
9
  if ( ! defined( 'ABSPATH' ) ) die( "Can't load this file directly" );
@@ -208,6 +208,12 @@ class PhotoOfTheDay extends WP_Widget {
208
  /** @see WP_Widget::update */
209
  function update( $new_instance, $old_instance ) {
210
  $instance = $old_instance;
 
 
 
 
 
 
211
  $instance['title'] = strip_tags( $new_instance['title'] );
212
  $instance['logonly'] = $new_instance['logonly'];
213
 
3
  * Package: wp-photo-album-plus
4
  *
5
  * display the widget
6
+ * Version 6.9.12
7
  */
8
 
9
  if ( ! defined( 'ABSPATH' ) ) die( "Can't load this file directly" );
208
  /** @see WP_Widget::update */
209
  function update( $new_instance, $old_instance ) {
210
  $instance = $old_instance;
211
+
212
+ // Defaults
213
+ $instance = wp_parse_args( (array) $instance, array( 'title' => wppa_opt( 'potd_title' ),
214
+ 'logonly' => 'no',
215
+ ) );
216
+
217
  $instance['title'] = strip_tags( $new_instance['title'] );
218
  $instance['logonly'] = $new_instance['logonly'];
219
 
wppa-search-widget.php CHANGED
@@ -3,7 +3,7 @@
3
  * Package: wp-photo-album-plus
4
  *
5
  * display the search widget
6
- * Version 6.8.07
7
  *
8
  */
9
 
@@ -75,6 +75,21 @@ class SearchPhotos extends WP_Widget {
75
  function update( $new_instance, $old_instance ) {
76
 
77
  $instance = $old_instance;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
  $instance['title'] = strip_tags($new_instance['title']);
79
  $instance['label'] = $new_instance['label'];
80
  $instance['root'] = isset( $new_instance['root'] ) ? $new_instance['root'] : false;
3
  * Package: wp-photo-album-plus
4
  *
5
  * display the search widget
6
+ * Version 6.9.12
7
  *
8
  */
9
 
75
  function update( $new_instance, $old_instance ) {
76
 
77
  $instance = $old_instance;
78
+
79
+ // Defaults
80
+ $instance = wp_parse_args( (array) $instance,
81
+ array(
82
+ 'title' => __( 'Search Photos', 'wp-photo-album-plus' ),
83
+ 'label' => '',
84
+ 'root' => false,
85
+ 'sub' => false,
86
+ 'album' => '0',
87
+ 'landingpage' => '',
88
+ 'catbox' => false,
89
+ 'selboxes' => false,
90
+ 'logonly' => 'no',
91
+ ) );
92
+
93
  $instance['title'] = strip_tags($new_instance['title']);
94
  $instance['label'] = $new_instance['label'];
95
  $instance['root'] = isset( $new_instance['root'] ) ? $new_instance['root'] : false;
wppa-settings-autosave.php CHANGED
@@ -3,7 +3,7 @@
3
  * Package: wp-photo-album-plus
4
  *
5
  * manage all options
6
- * Version 6.9.11
7
  *
8
  */
9
 
@@ -459,6 +459,7 @@ echo '<input type="button" vaue="Click me" onclick="wppaTimedConfirm( \'My Text\
459
  for( i=1;i<15;i++ ) { jQuery('#wppa_table_'+i).css('display', 'inline');}
460
  jQuery( '.wppa-setting' ).css('display','');
461
  jQuery( '.wppa-h' ).css( 'display', 'none' );
 
462
  "
463
  />
464
 
@@ -5241,9 +5242,11 @@ echo '<input type="button" vaue="Click me" onclick="wppaTimedConfirm( \'My Text\
5241
  $slug = 'wppa_panorama_control';
5242
  $opts = array( __( 'Always', 'wp-photo-album-plus' ),
5243
  __( 'On mobile only', 'wp-photo-album-plus' ),
 
5244
  );
5245
  $vals = array( 'all',
5246
  'mobile',
 
5247
  );
5248
  $html = wppa_select($slug, $opts, $vals);
5249
  $clas = '';
3
  * Package: wp-photo-album-plus
4
  *
5
  * manage all options
6
+ * Version 6.9.12
7
  *
8
  */
9
 
459
  for( i=1;i<15;i++ ) { jQuery('#wppa_table_'+i).css('display', 'inline');}
460
  jQuery( '.wppa-setting' ).css('display','');
461
  jQuery( '.wppa-h' ).css( 'display', 'none' );
462
+ jQuery( '.wppa-video' ).css( 'display', '' );
463
  "
464
  />
465
 
5242
  $slug = 'wppa_panorama_control';
5243
  $opts = array( __( 'Always', 'wp-photo-album-plus' ),
5244
  __( 'On mobile only', 'wp-photo-album-plus' ),
5245
+ __( 'None', 'wp-photo-album-plus' ),
5246
  );
5247
  $vals = array( 'all',
5248
  'mobile',
5249
+ 'none',
5250
  );
5251
  $html = wppa_select($slug, $opts, $vals);
5252
  $clas = '';
wppa-stats-widget.php CHANGED
@@ -3,7 +3,7 @@
3
  * Package: wp-photo-album-plus
4
  *
5
  * display the stats widget
6
- * Version 6.9.00
7
  *
8
  */
9
  class WppaStatsWidget extends WP_Widget {
@@ -147,6 +147,11 @@ class WppaStatsWidget extends WP_Widget {
147
  // Update settings
148
  function update( $new_instance, $old_instance ) {
149
  $instance = $new_instance;
 
 
 
 
 
150
  $instance['title'] = strip_tags( $new_instance['title'] );
151
  return $instance;
152
  }
3
  * Package: wp-photo-album-plus
4
  *
5
  * display the stats widget
6
+ * Version 6.9.12
7
  *
8
  */
9
  class WppaStatsWidget extends WP_Widget {
147
  // Update settings
148
  function update( $new_instance, $old_instance ) {
149
  $instance = $new_instance;
150
+
151
+ // Defaults
152
+ $this->defaults['title'] = __( 'Statistics', 'wp-photo-album-plus' );
153
+ $instance = wp_parse_args( (array) $instance, $this->defaults );
154
+
155
  $instance['title'] = strip_tags( $new_instance['title'] );
156
  return $instance;
157
  }
wppa-stereo-widget.php CHANGED
@@ -3,7 +3,7 @@
3
  * Package: wp-photo-album-plus
4
  *
5
  * display the top rated photos
6
- * Version 6.8.07
7
  */
8
 
9
  class wppaStereoWidget extends WP_Widget {
@@ -51,6 +51,10 @@ class wppaStereoWidget extends WP_Widget {
51
  /** @see WP_Widget::update */
52
  function update($new_instance, $old_instance) {
53
  $instance = $old_instance;
 
 
 
 
54
  $instance['title'] = strip_tags( $new_instance['title'] );
55
  $instance['logonly'] = $new_instance['logonly'];
56
 
3
  * Package: wp-photo-album-plus
4
  *
5
  * display the top rated photos
6
+ * Version 6.9.12
7
  */
8
 
9
  class wppaStereoWidget extends WP_Widget {
51
  /** @see WP_Widget::update */
52
  function update($new_instance, $old_instance) {
53
  $instance = $old_instance;
54
+
55
+ //Defaults
56
+ $instance = wp_parse_args( (array) $instance, array( 'title' => __( 'Stereo Photo Settings', 'wp-photo-album-plus ' ), 'logonly' => 'no' ) );
57
+
58
  $instance['title'] = strip_tags( $new_instance['title'] );
59
  $instance['logonly'] = $new_instance['logonly'];
60
 
wppa-super-view-widget.php CHANGED
@@ -3,7 +3,7 @@
3
  * Package: wp-photo-album-plus
4
  *
5
  * ask the album / display you want
6
- * Version 6.8.07
7
  */
8
 
9
 
@@ -52,6 +52,14 @@ class WppaSuperView extends WP_Widget {
52
  /** @see WP_Widget::update */
53
  function update($new_instance, $old_instance) {
54
  $instance = $old_instance;
 
 
 
 
 
 
 
 
55
  $instance['title'] = strip_tags($new_instance['title']);
56
  $instance['root'] = $new_instance['root'];
57
  $instance['sort'] = $new_instance['sort'];
3
  * Package: wp-photo-album-plus
4
  *
5
  * ask the album / display you want
6
+ * Version 6.9.12
7
  */
8
 
9
 
52
  /** @see WP_Widget::update */
53
  function update($new_instance, $old_instance) {
54
  $instance = $old_instance;
55
+
56
+ //Defaults
57
+ $instance = wp_parse_args( (array) $instance, array( 'title' => __( 'Super View' , 'wp-photo-album-plus' ),
58
+ 'root' => '0',
59
+ 'sort' => true,
60
+ 'logonly' => 'no',
61
+ ) );
62
+
63
  $instance['title'] = strip_tags($new_instance['title']);
64
  $instance['root'] = $new_instance['root'];
65
  $instance['sort'] = $new_instance['sort'];
wppa-tagcloud-widget.php CHANGED
@@ -3,7 +3,7 @@
3
  * Package: wp-photo-album-plus
4
  *
5
  * display the tagcloud widget
6
- * Version 6.8.07
7
  *
8
  */
9
 
@@ -59,6 +59,14 @@ class TagcloudPhotos extends WP_Widget {
59
  /** @see WP_Widget::update */
60
  function update($new_instance, $old_instance) {
61
  $instance = $old_instance;
 
 
 
 
 
 
 
 
62
  $instance['title'] = strip_tags($new_instance['title']);
63
  $instance['tags'] = $new_instance['tags'];
64
  $instance['logonly'] = $new_instance['logonly'];
@@ -69,7 +77,7 @@ class TagcloudPhotos extends WP_Widget {
69
  /** @see WP_Widget::form */
70
  function form( $instance ) {
71
 
72
- //Defaults
73
  $instance = wp_parse_args( (array) $instance, array( 'title' => __( 'Photo Tag Cloud', 'wp-photo-album-plus' ), 'tags' => '', 'logonly' => 'no' ) );
74
  $title = $instance['title'];
75
  $stags = $instance['tags'];
3
  * Package: wp-photo-album-plus
4
  *
5
  * display the tagcloud widget
6
+ * Version 6.9.12
7
  *
8
  */
9
 
59
  /** @see WP_Widget::update */
60
  function update($new_instance, $old_instance) {
61
  $instance = $old_instance;
62
+
63
+ // Defaults
64
+ $instance = wp_parse_args( (array) $instance, array(
65
+ 'title' => __( 'Photo Tag Cloud', 'wp-photo-album-plus' ),
66
+ 'tags' => '',
67
+ 'logonly' => 'no' ,
68
+ ) );
69
+
70
  $instance['title'] = strip_tags($new_instance['title']);
71
  $instance['tags'] = $new_instance['tags'];
72
  $instance['logonly'] = $new_instance['logonly'];
77
  /** @see WP_Widget::form */
78
  function form( $instance ) {
79
 
80
+ // Defaults
81
  $instance = wp_parse_args( (array) $instance, array( 'title' => __( 'Photo Tag Cloud', 'wp-photo-album-plus' ), 'tags' => '', 'logonly' => 'no' ) );
82
  $title = $instance['title'];
83
  $stags = $instance['tags'];
wppa-thumbnail-widget.php CHANGED
@@ -3,7 +3,7 @@
3
  * Package: wp-photo-album-plus
4
  *
5
  * display thumbnail photos
6
- * Version 6.8.07
7
  */
8
 
9
  class ThumbnailWidget extends WP_Widget {
@@ -155,6 +155,20 @@ class ThumbnailWidget extends WP_Widget {
155
  /** @see WP_Widget::update */
156
  function update($new_instance, $old_instance) {
157
  $instance = $old_instance;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158
  $instance['title'] = strip_tags($new_instance['title']);
159
  $instance['link'] = strip_tags($new_instance['link']);
160
  $instance['album'] = $new_instance['album'];
3
  * Package: wp-photo-album-plus
4
  *
5
  * display thumbnail photos
6
+ * Version 6.9.12
7
  */
8
 
9
  class ThumbnailWidget extends WP_Widget {
155
  /** @see WP_Widget::update */
156
  function update($new_instance, $old_instance) {
157
  $instance = $old_instance;
158
+
159
+ // Defaults
160
+ $instance = wp_parse_args( (array) $instance, array(
161
+ 'title' => __( 'Thumbnail Photos', 'wp-photo-album-plus' ),
162
+ 'link' => '',
163
+ 'linktitle' => '',
164
+ 'album' => '0',
165
+ 'name' => 'no',
166
+ 'display' => 'thumbs',
167
+ 'sortby' => wppa_get_photo_order('0'),
168
+ 'limit' => wppa_opt( 'thumbnail_widget_count' ),
169
+ 'logonly' => 'no',
170
+ ) );
171
+
172
  $instance['title'] = strip_tags($new_instance['title']);
173
  $instance['link'] = strip_tags($new_instance['link']);
174
  $instance['album'] = $new_instance['album'];
wppa-tinymce-photo-front.php CHANGED
@@ -2,7 +2,7 @@
2
  /* wppa-tinymce-photo-front.php
3
  * Pachkage: wp-photo-album-plus
4
  *
5
- * Version 6.8.09
6
  *
7
  */
8
 
@@ -52,7 +52,7 @@ global $wppa_js_page_data_file;
52
  if ( wppa_switch( 'photo_shortcode_enabled' ) && ! $done ) {
53
 
54
  // Find an existing photo
55
- $id = $wpdb->get_var( "SELECT `id` FROM " . WPPA_PHOTOS . " WHERE `ext` <> 'xxx' ORDER BY `timestamp` DESC LIMIT 1" );
56
 
57
  // Fake we are in a widget, to prevent wppa_get_picture_html() from bumping viewcount
58
  wppa( 'in_widget', true );
2
  /* wppa-tinymce-photo-front.php
3
  * Pachkage: wp-photo-album-plus
4
  *
5
+ * Version 6.9.12
6
  *
7
  */
8
 
52
  if ( wppa_switch( 'photo_shortcode_enabled' ) && ! $done ) {
53
 
54
  // Find an existing photo
55
+ $id = $wpdb->get_var( "SELECT `id` FROM " . WPPA_PHOTOS . " WHERE `ext` <> 'xxx' AND `panorama` = 0 ORDER BY `timestamp` DESC LIMIT 1" );
56
 
57
  // Fake we are in a widget, to prevent wppa_get_picture_html() from bumping viewcount
58
  wppa( 'in_widget', true );
wppa-topten-widget.php CHANGED
@@ -3,7 +3,7 @@
3
  * Package: wp-photo-album-plus
4
  *
5
  * display the top rated photos
6
- * Version 6.8.07
7
  */
8
 
9
  class TopTenWidget extends WP_Widget {
@@ -304,6 +304,23 @@ class TopTenWidget extends WP_Widget {
304
  /** @see WP_Widget::update */
305
  function update($new_instance, $old_instance) {
306
  $instance = $old_instance;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
307
  $instance['title'] = strip_tags( $new_instance['title'] );
308
  $instance['album'] = strval( intval( $new_instance['album'] ) );
309
  $instance['sortby'] = $new_instance['sortby'];
3
  * Package: wp-photo-album-plus
4
  *
5
  * display the top rated photos
6
+ * Version 6.9.12
7
  */
8
 
9
  class TopTenWidget extends WP_Widget {
304
  /** @see WP_Widget::update */
305
  function update($new_instance, $old_instance) {
306
  $instance = $old_instance;
307
+
308
+ // Defaults
309
+ $instance = wp_parse_args( (array) $instance, array(
310
+ 'sortby' => 'mean_rating',
311
+ 'title' => __( 'Top Ten Photos', 'wp-photo-album-plus' ),
312
+ 'album' => '0',
313
+ 'display' => 'thumbs',
314
+ 'meanrat' => 'yes',
315
+ 'ratcount' => 'yes',
316
+ 'viewcount' => 'yes',
317
+ 'includesubs' => 'yes',
318
+ 'medalsonly' => 'no',
319
+ 'showowner' => 'no',
320
+ 'showalbum' => 'no',
321
+ 'logonly' => 'no',
322
+ ) );
323
+
324
  $instance['title'] = strip_tags( $new_instance['title'] );
325
  $instance['album'] = strval( intval( $new_instance['album'] ) );
326
  $instance['sortby'] = $new_instance['sortby'];
wppa-upldr-widget.php CHANGED
@@ -3,7 +3,7 @@
3
  * Package: wp-photo-album-plus
4
  *
5
  * display a list of users linking to their photos
6
- * Version 6.8.09
7
  */
8
 
9
  if ( ! defined( 'ABSPATH' ) ) die( "Can't load this file directly" );
@@ -169,6 +169,18 @@ class UpldrWidget extends WP_Widget {
169
  function update( $new_instance, $old_instance ) {
170
 
171
  $instance = $old_instance;
 
 
 
 
 
 
 
 
 
 
 
 
172
  $instance['title'] = strip_tags($new_instance['title']);
173
  $instance['sortby'] = $new_instance['sortby'];
174
  $instance['ignore'] = $new_instance['ignore'];
3
  * Package: wp-photo-album-plus
4
  *
5
  * display a list of users linking to their photos
6
+ * Version 6.9.12
7
  */
8
 
9
  if ( ! defined( 'ABSPATH' ) ) die( "Can't load this file directly" );
169
  function update( $new_instance, $old_instance ) {
170
 
171
  $instance = $old_instance;
172
+
173
+ //Defaults
174
+ $instance = wp_parse_args( (array) $instance, array(
175
+ 'title' => __( 'Uploader Photos', 'wp-photo-album-plus' ),
176
+ 'sortby' => 'name',
177
+ 'ignore' => 'admin',
178
+ 'parent' => '',
179
+ 'showownercount' => '',
180
+ 'showphotocount' => '',
181
+ 'logonly' => 'no',
182
+ ) );
183
+
184
  $instance['title'] = strip_tags($new_instance['title']);
185
  $instance['sortby'] = $new_instance['sortby'];
186
  $instance['ignore'] = $new_instance['ignore'];
wppa-upload-widget.php CHANGED
@@ -4,7 +4,7 @@
4
  *
5
  * A wppa widget to upload photos
6
  *
7
- * Version 6.8.07
8
  */
9
 
10
  class WppaUploadWidget extends WP_Widget {
@@ -84,6 +84,9 @@ class WppaUploadWidget extends WP_Widget {
84
 
85
  function update( $new_instance, $old_instance ) {
86
  $instance = $old_instance;
 
 
 
87
  $instance['title'] = strip_tags( $new_instance['title'] );
88
  $instance['album'] = strval( intval( $new_instance['album'] ) );
89
  $instance['logonly'] = $new_instance['logonly'];
4
  *
5
  * A wppa widget to upload photos
6
  *
7
+ * Version 6.9.12
8
  */
9
 
10
  class WppaUploadWidget extends WP_Widget {
84
 
85
  function update( $new_instance, $old_instance ) {
86
  $instance = $old_instance;
87
+
88
+ $instance = wp_parse_args( (array) $instance, array( 'title' => __( 'Upload Photos', 'wp-photo-album-plus' ), 'album' => '0', 'logonly' => 'no' ) );
89
+
90
  $instance['title'] = strip_tags( $new_instance['title'] );
91
  $instance['album'] = strval( intval( $new_instance['album'] ) );
92
  $instance['logonly'] = $new_instance['logonly'];
wppa.php CHANGED
@@ -2,7 +2,7 @@
2
  /*
3
  * Plugin Name: WP Photo Album Plus
4
  * Description: Easily manage and display your photo albums and slideshows within your WordPress site.
5
- * Version: 6.9.11.011
6
  * Author: J.N. Breetvelt a.k.a. OpaJaap
7
  * Author URI: http://wppa.opajaap.nl/
8
  * Plugin URI: http://wordpress.org/extend/plugins/wp-photo-album-plus/
@@ -23,7 +23,7 @@ global $wp_version;
23
 
24
  /* WPPA GLOBALS */
25
  global $wppa_revno; $wppa_revno = '6911'; // WPPA db version
26
- global $wppa_api_version; $wppa_api_version = '6-9-11-011'; // WPPA software version
27
 
28
  /* start timers */
29
  global $wppa_starttime; $wppa_starttime = microtime( true );
2
  /*
3
  * Plugin Name: WP Photo Album Plus
4
  * Description: Easily manage and display your photo albums and slideshows within your WordPress site.
5
+ * Version: 6.9.12.007
6
  * Author: J.N. Breetvelt a.k.a. OpaJaap
7
  * Author URI: http://wppa.opajaap.nl/
8
  * Plugin URI: http://wordpress.org/extend/plugins/wp-photo-album-plus/
23
 
24
  /* WPPA GLOBALS */
25
  global $wppa_revno; $wppa_revno = '6911'; // WPPA db version
26
+ global $wppa_api_version; $wppa_api_version = '6-9-12-007'; // WPPA software version
27
 
28
  /* start timers */
29
  global $wppa_starttime; $wppa_starttime = microtime( true );