SEA3DLoader.js 65 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305
  1. /**
  2. * SEA3D for Three.JS
  3. * @author Sunag / http://www.sunag.com.br/
  4. */
  5. 'use strict';
  6. //
  7. // Polyfills
  8. //
  9. if (THREE.Float32BufferAttribute === undefined) {
  10. THREE.Float32BufferAttribute = THREE.Float32Attribute;
  11. }
  12. //
  13. //
  14. // SEA3D
  15. //
  16. THREE.SEA3D = function ( config ) {
  17. this.config = {
  18. id: "",
  19. scripts: true,
  20. runScripts: true,
  21. autoPlay: false,
  22. dummys: true,
  23. multiplier: 1,
  24. bounding: true,
  25. audioRolloffFactor: 10,
  26. lights: true,
  27. useEnvironment: true,
  28. useVertexTexture: true,
  29. forceStatic: false,
  30. forcePremultipliedAlpha: false,
  31. streaming: true,
  32. async: true,
  33. paths: {},
  34. timeLimit: 10
  35. };
  36. if ( config ) this.loadConfig( config );
  37. };
  38. //
  39. // Config
  40. //
  41. THREE.SEA3D.MTXBUF = new THREE.Matrix4();
  42. THREE.SEA3D.VECBUF = new THREE.Vector3();
  43. THREE.SEA3D.QUABUF = new THREE.Quaternion();
  44. THREE.SEA3D.BACKGROUND_COLOR = 0x333333;
  45. THREE.SEA3D.HELPER_COLOR = 0x9AB9E5;
  46. THREE.SEA3D.RTT_SIZE = 512;
  47. THREE.SEA3D.prototype = {
  48. constructor: THREE.SEA3D,
  49. set container( val ) {
  50. this.config.container = val;
  51. },
  52. get container() {
  53. return this.config.container;
  54. },
  55. setShadowMap: function ( light ) {
  56. light.shadow.mapSize.width = 2048;
  57. light.shadow.mapSize.height = 1024;
  58. light.castShadow = true;
  59. light.shadow.camera.left = - 200;
  60. light.shadow.camera.right = 200;
  61. light.shadow.camera.top = 200;
  62. light.shadow.camera.bottom = - 200;
  63. light.shadow.camera.near = 1;
  64. light.shadow.camera.far = 3000;
  65. light.shadow.camera.fov = 45;
  66. light.shadow.bias = - 0.001;
  67. }
  68. };
  69. Object.assign( THREE.SEA3D.prototype, THREE.EventDispatcher.prototype );
  70. //
  71. // Domain
  72. //
  73. THREE.SEA3D.Domain = function ( id, objects, container ) {
  74. this.id = id;
  75. this.objects = objects;
  76. this.container = container;
  77. this.sources = [];
  78. this.global = {};
  79. this.scriptTargets = [];
  80. this.events = new THREE.EventDispatcher();
  81. };
  82. Object.assign( THREE.SEA3D.Domain.prototype, {
  83. add: function ( src ) {
  84. this.sources.push( src );
  85. },
  86. remove: function ( src ) {
  87. this.sources.splice( this.sources.indexOf( src ), 1 );
  88. },
  89. contains: function ( src ) {
  90. return this.sources.indexOf( src ) != - 1;
  91. },
  92. addEventListener: function ( type, listener ) {
  93. this.events.addEventListener( type, listener );
  94. },
  95. hasEventListener: function ( type, listener ) {
  96. return this.events.hasEventListener( type, listener );
  97. },
  98. removeEventListener: function ( type, listener ) {
  99. this.events.removeEventListener( type, listener );
  100. },
  101. print: function () {
  102. console.log.apply( console, arguments );
  103. },
  104. watch: function () {
  105. console.log.apply( console, 'watch:', arguments );
  106. },
  107. runScripts: function () {
  108. for ( var i = 0; i < this.scriptTargets.length; i ++ ) {
  109. this.runJSMList( this.scriptTargets[ i ] );
  110. }
  111. },
  112. runJSMList: function ( target ) {
  113. var scripts = target.scripts;
  114. for ( var i = 0; i < scripts.length; i ++ ) {
  115. this.runJSM( target, scripts[ i ] );
  116. }
  117. return scripts;
  118. },
  119. runJSM: function ( target, script ) {
  120. if ( target.local == undefined ) target.local = {};
  121. var include = {
  122. print: this.print,
  123. watch: this.watch,
  124. sea3d: this,
  125. scene: this.container,
  126. source: new THREE.SEA3D.ScriptDomain( this, target instanceof THREE.SEA3D.Domain )
  127. };
  128. Object.freeze( include.source );
  129. THREE.SEA3D.ScriptHandler.add( include.source );
  130. try {
  131. this.methods[ script.method ](
  132. include,
  133. this.getReference,
  134. this.global,
  135. target.local,
  136. target,
  137. script.params
  138. );
  139. } catch ( e ) {
  140. console.error( 'SEA3D JavaScript: Error running method "' + script.method + '".' );
  141. console.error( e );
  142. }
  143. },
  144. getReference: function ( ns ) {
  145. return eval( ns );
  146. },
  147. disposeList: function ( list ) {
  148. if ( ! list || ! list.length ) return;
  149. list = list.concat();
  150. var i = list.length;
  151. while ( i -- ) {
  152. list[ i ].dispose();
  153. }
  154. },
  155. dispatchEvent: function ( event ) {
  156. event.domain = this;
  157. var sources = this.sources.concat(),
  158. i = sources.length;
  159. while ( i -- ) {
  160. sources[ i ].dispatchEvent( event );
  161. }
  162. this.events.dispatchEvent( event );
  163. },
  164. dispose: function () {
  165. this.disposeList( this.sources );
  166. while ( this.container.children.length ) {
  167. this.container.remove( this.container.children[ 0 ] );
  168. }
  169. var i = THREE.SEA3D.EXTENSIONS_DOMAIN.length;
  170. while ( i -- ) {
  171. var domain = THREE.SEA3D.EXTENSIONS_DOMAIN[ i ];
  172. if ( domain.dispose ) domain.dispose.call( this );
  173. }
  174. this.disposeList( this.materials );
  175. this.disposeList( this.dummys );
  176. this.dispatchEvent( { type: "dispose" } );
  177. }
  178. } );
  179. //
  180. // Domain Manager
  181. //
  182. THREE.SEA3D.DomainManager = function ( autoDisposeRootDomain ) {
  183. this.domains = [];
  184. this.autoDisposeRootDomain = autoDisposeRootDomain == undefined ? true : false;
  185. };
  186. Object.assign( THREE.SEA3D.DomainManager.prototype, {
  187. onDisposeDomain: function ( e ) {
  188. this.remove( e.domain );
  189. if ( this.autoDisposeRootDomain && this.domains.length == 1 ) {
  190. this.dispose();
  191. }
  192. },
  193. add: function ( domain ) {
  194. this._onDisposeDomain = this._onDisposeDomain || this.onDisposeDomain.bind( this );
  195. domain.on( "dispose", this._onDisposeDomain );
  196. this.domains.push( domain );
  197. this.textures = this.textures || domain.textures;
  198. this.cubemaps = this.cubemaps || domain.cubemaps;
  199. this.geometries = this.geometries || domain.geometries;
  200. },
  201. remove: function ( domain ) {
  202. domain.removeEvent( "dispose", this._onDisposeDomain );
  203. this.domains.splice( this.domains.indexOf( domain ), 1 );
  204. },
  205. contains: function ( domain ) {
  206. return this.domains.indexOf( domain ) != - 1;
  207. },
  208. disposeList: function ( list ) {
  209. if ( ! list || ! list.length ) return;
  210. list = list.concat();
  211. var i = list.length;
  212. while ( i -- ) {
  213. list[ i ].dispose();
  214. }
  215. },
  216. dispose: function () {
  217. this.disposeList( this.domains );
  218. this.disposeList( this.textures );
  219. this.disposeList( this.cubemaps );
  220. this.disposeList( this.geometries );
  221. }
  222. } );
  223. //
  224. // Script ( closure for private functions )
  225. //
  226. THREE.SEA3D.ScriptDomain = function ( domain, root ) {
  227. domain = domain || new THREE.SEA3D.Domain();
  228. domain.add( this );
  229. var events = new THREE.EventDispatcher();
  230. this.getId = function () {
  231. return domain.id;
  232. };
  233. this.isRoot = function () {
  234. return root;
  235. };
  236. this.addEventListener = function ( type, listener ) {
  237. events.addEventListener( type, listener );
  238. };
  239. this.hasEventListener = function ( type, listener ) {
  240. return events.hasEventListener( type, listener );
  241. };
  242. this.removeEventListener = function ( type, listener ) {
  243. events.removeEventListener( type, listener );
  244. };
  245. this.dispatchEvent = function ( event ) {
  246. event.script = this;
  247. events.dispatchEvent( event );
  248. };
  249. this.dispose = function () {
  250. domain.remove( this );
  251. if ( root ) domain.dispose();
  252. this.dispatchEvent( { type: "dispose" } );
  253. };
  254. };
  255. //
  256. // Script Manager ( closure for private functions )
  257. //
  258. THREE.SEA3D.ScriptManager = function () {
  259. this.scripts = [];
  260. var onDisposeScript = ( function ( e ) {
  261. this.remove( e.script );
  262. } ).bind( this );
  263. this.add = function ( src ) {
  264. src.addEventListener( "dispose", onDisposeScript );
  265. this.scripts.push( src );
  266. };
  267. this.remove = function ( src ) {
  268. src.removeEventListener( "dispose", onDisposeScript );
  269. this.scripts.splice( this.scripts.indexOf( src ), 1 );
  270. };
  271. this.contains = function ( src ) {
  272. return this.scripts.indexOf( src ) > - 1;
  273. };
  274. this.dispatchEvent = function ( event ) {
  275. var scripts = this.scripts.concat(),
  276. i = scripts.length;
  277. while ( i -- ) {
  278. scripts[ i ].dispatchEvent( event );
  279. }
  280. };
  281. };
  282. //
  283. // Script Handler
  284. //
  285. THREE.SEA3D.ScriptHandler = new THREE.SEA3D.ScriptManager();
  286. THREE.SEA3D.ScriptHandler.dispatchUpdate = function ( delta ) {
  287. this.dispatchEvent( {
  288. type: "update",
  289. delta: delta
  290. } );
  291. };
  292. //
  293. // Animator
  294. //
  295. THREE.SEA3D.Animator = function ( clips, mixer ) {
  296. this.clips = clips;
  297. this.updateAnimations( mixer );
  298. };
  299. Object.assign( THREE.SEA3D.Animator.prototype, {
  300. update: function ( dt ) {
  301. this.mixer.update( dt || 0 );
  302. if ( this.currentAnimationAction && this.currentAnimationAction.paused ) {
  303. this.pause();
  304. if ( this.currentAnimationData && this.currentAnimationData.onComplete ) this.currentAnimationData.onComplete( this );
  305. }
  306. return this;
  307. },
  308. updateAnimations: function ( mixer ) {
  309. if ( this.playing ) this.stop();
  310. if ( this.mixer ) THREE.SEA3D.AnimationHandler.removeAnimator( this );
  311. //THREE.SEA3D.AnimationHandler.addAnimator( this ); //////////§§§§!!!
  312. this.mixer = mixer;
  313. this.relative = false;
  314. this.playing = false;
  315. this.paused = false;
  316. this.timeScale = 1;
  317. this.animations = {};
  318. this.animationsIndex = [];
  319. this.animationsData = {};
  320. // if no geometry animation
  321. if ( this.geometry && this.geometry.animations === undefined ) return;
  322. this.clips = this instanceof THREE.SEA3D.Animator ? this.clips : this.geometry.animations;
  323. for ( var i = 0; i < this.clips.length; i ++ ) {
  324. this.addAnimation( this.clips[ i ] );
  325. }
  326. return this;
  327. },
  328. addAnimation: function ( clip ) {
  329. var name = clip.name;
  330. this.animations[ name ] = clip;
  331. this.animationsData[ name ] = {};
  332. this.animationsIndex.push( clip );
  333. this.mixer.clipAction( clip );
  334. return this;
  335. },
  336. removeAnimation: function ( clip ) {
  337. var name = clip.name;
  338. delete this.animations[ name ];
  339. delete this.animationsData[ name ];
  340. this.animationsIndex.splice( this.animationsIndex.indexOf( clip ), 1 );
  341. this.mixer.uncacheClip( clip );
  342. return this;
  343. },
  344. pause: function () {
  345. if ( this.playing && this.currentAnimation ) {
  346. THREE.SEA3D.AnimationHandler.removeAnimator( this );
  347. this.playing = false;
  348. }
  349. return this;
  350. },
  351. resume: function () {
  352. if ( ! this.playing && this.currentAnimation ) {
  353. THREE.SEA3D.AnimationHandler.addAnimator( this );
  354. this.playing = true;
  355. }
  356. return this;
  357. },
  358. setTimeScale: function ( val ) {
  359. this.timeScale = val;
  360. if ( this.currentAnimationAction ) this.updateTimeScale();
  361. return this;
  362. },
  363. getTimeScale: function () {
  364. return this.timeScale;
  365. },
  366. updateTimeScale: function () {
  367. this.currentAnimationAction.setEffectiveTimeScale( this.timeScale * ( this.currentAnimation ? this.currentAnimation.timeScale : 1 ) );
  368. return this;
  369. },
  370. play: function ( name, crossfade, offset, weight ) {
  371. var animation = this.animations[ name ] || this.animationsIndex[ name ];
  372. name = animation.name;
  373. if ( animation == this.currentAnimation ) {
  374. if ( offset !== undefined || ! animation.loop ) this.currentAnimationAction.time = offset !== undefined ? offset :
  375. ( this.currentAnimationAction.timeScale >= 0 ? 0 : this.currentAnimation.duration );
  376. this.currentAnimationAction.setEffectiveWeight( weight !== undefined ? weight : 1 );
  377. this.currentAnimationAction.paused = false;
  378. return this.resume();
  379. } else {
  380. if ( ! animation ) throw new Error( 'Animation "' + name + '" not found.' );
  381. this.previousAnimation = this.currentAnimation;
  382. this.currentAnimation = animation;
  383. this.previousAnimationAction = this.currentAnimationAction;
  384. this.currentAnimationAction = this.mixer.clipAction( animation ).setLoop( animation.loop ? THREE.LoopRepeat : THREE.LoopOnce, Infinity ).reset();
  385. this.currentAnimationAction.clampWhenFinished = ! animation.loop;
  386. this.currentAnimationAction.paused = false;
  387. this.previousAnimationData = this.currentAnimationData;
  388. this.currentAnimationData = this.animationsData[ name ];
  389. this.updateTimeScale();
  390. if ( offset !== undefined || ! animation.loop ) this.currentAnimationAction.time = offset !== undefined ? offset :
  391. ( this.currentAnimationAction.timeScale >= 0 ? 0 : this.currentAnimation.duration );
  392. this.currentAnimationAction.setEffectiveWeight( weight !== undefined ? weight : 1 );
  393. this.currentAnimationAction.play();
  394. if ( ! this.playing ) this.mixer.update( 0 );
  395. this.playing = true;
  396. if ( this.previousAnimation ) this.previousAnimationAction.crossFadeTo( this.currentAnimationAction, crossfade || 0, true );
  397. THREE.SEA3D.AnimationHandler.addAnimator( this );
  398. }
  399. return this;
  400. },
  401. stop: function () {
  402. if ( this.playing ) THREE.SEA3D.AnimationHandler.removeAnimator( this );
  403. if ( this.currentAnimation ) {
  404. this.currentAnimationAction.stop();
  405. //THREE.SEA3D.AnimationHandler.removeAnimator( this );
  406. this.previousAnimation = this.currentAnimation;
  407. this.previousAnimationData = this.currentAnimationData;
  408. this.previousAnimationAction = this.currentAnimationAction;
  409. delete this.currentAnimationAction;
  410. delete this.currentAnimationData;
  411. delete this.currentAnimation;
  412. this.playing = false;
  413. }
  414. return this;
  415. },
  416. playw: function ( name, weight ) {
  417. if ( ! this.playing && ! this.paused ) THREE.SEA3D.AnimationHandler.addAnimator( this );
  418. var anim = this.animations[ name ] || this.animationsIndex[ name ];
  419. this.playing = true;
  420. var clip = this.mixer.clipAction( anim );
  421. clip.setLoop( anim.loop ? THREE.LoopRepeat : THREE.LoopOnce, Infinity ).reset();
  422. clip.clampWhenFinished = ! anim.loop;
  423. clip.paused = false;
  424. clip.setEffectiveWeight( weight ).play();
  425. return clip;
  426. },
  427. crossFade: function ( fromAnimName, toAnimName, duration, wrap ) {
  428. this.mixer.stopAllAction();
  429. var fromAction = this.playw( fromAnimName, 1 );
  430. var toAction = this.playw( toAnimName, 1 );
  431. fromAction.crossFadeTo( toAction, duration, wrap !== undefined ? wrap : false );
  432. return this;
  433. },
  434. setClipTimeScale: function ( name, value ) {
  435. var anim = this.animations[ name ];
  436. var clip = this.mixer.clipAction( anim );
  437. clip.setEffectiveTimeScale( value );
  438. return this;
  439. },
  440. stopAll: function () {
  441. this.stop().mixer.stopAllAction();
  442. this.playing = false;
  443. return this;
  444. },
  445. unPauseAll: function () {
  446. this.mixer.timeScale = 1;
  447. this.playing = true;
  448. this.paused = false;
  449. return this;
  450. },
  451. pauseAll: function () {
  452. this.mixer.timeScale = 0;
  453. this.playing = false;
  454. this.paused = true;
  455. return this;
  456. },
  457. setRelative: function ( val ) {
  458. if ( this.relative == val ) return;
  459. this.stop();
  460. this.relative = val;
  461. return this;
  462. },
  463. getRelative: function () {
  464. return this.relative;
  465. }
  466. } );
  467. //
  468. // Object3D Animator
  469. //
  470. THREE.SEA3D.Object3DAnimator = function ( clips, object3d ) {
  471. this.object3d = object3d;
  472. THREE.SEA3D.Animator.call( this, clips, new THREE.AnimationMixer( object3d ) );
  473. };
  474. THREE.SEA3D.Object3DAnimator.prototype = Object.assign( Object.create( THREE.SEA3D.Animator.prototype ), {
  475. constructor: THREE.SEA3D.Object3DAnimator,
  476. stop: function () {
  477. if ( this.currentAnimation ) {
  478. var animate = this.object3d.animate;
  479. if ( animate && this instanceof THREE.SEA3D.Object3DAnimator ) {
  480. animate.position.set( 0, 0, 0 );
  481. animate.quaternion.set( 0, 0, 0, 1 );
  482. animate.scale.set( 1, 1, 1 );
  483. }
  484. }
  485. THREE.SEA3D.Animator.prototype.stop.call( this );
  486. },
  487. setRelative: function ( val ) {
  488. THREE.SEA3D.Animator.prototype.setRelative.call( this, val );
  489. this.object3d.setAnimator( this.relative );
  490. this.updateAnimations( new THREE.AnimationMixer( this.relative ? this.object3d.animate : this.object3d ) );
  491. }
  492. } );
  493. //
  494. // Camera Animator
  495. //
  496. THREE.SEA3D.CameraAnimator = function ( clips, object3d ) {
  497. THREE.SEA3D.Object3DAnimator.call( this, clips, object3d );
  498. };
  499. THREE.SEA3D.CameraAnimator.prototype = Object.assign( Object.create( THREE.SEA3D.Object3DAnimator.prototype ), {
  500. constructor: THREE.SEA3D.CameraAnimator
  501. } );
  502. //
  503. // Sound Animator
  504. //
  505. THREE.SEA3D.SoundAnimator = function ( clips, object3d ) {
  506. THREE.SEA3D.Object3DAnimator.call( this, clips, object3d );
  507. };
  508. THREE.SEA3D.SoundAnimator.prototype = Object.assign( Object.create( THREE.SEA3D.Object3DAnimator.prototype ), {
  509. constructor: THREE.SEA3D.SoundAnimator
  510. } );
  511. //
  512. // Light Animator
  513. //
  514. THREE.SEA3D.LightAnimator = function ( clips, object3d ) {
  515. THREE.SEA3D.Object3DAnimator.call( this, clips, object3d );
  516. };
  517. THREE.SEA3D.LightAnimator.prototype = Object.assign( Object.create( THREE.SEA3D.Object3DAnimator.prototype ), {
  518. constructor: THREE.SEA3D.LightAnimator
  519. } );
  520. //
  521. // Container
  522. //
  523. THREE.SEA3D.Object3D = function ( ) {
  524. THREE.Object3D.call( this );
  525. };
  526. THREE.SEA3D.Object3D.prototype = Object.assign( Object.create( THREE.Object3D.prototype ), {
  527. constructor: THREE.SEA3D.Object3D,
  528. // Relative Animation Extension ( Only used if relative animation is enabled )
  529. // TODO: It can be done with shader
  530. updateAnimateMatrix: function ( force ) {
  531. if ( this.matrixAutoUpdate === true ) this.updateMatrix();
  532. if ( this.matrixWorldNeedsUpdate === true || force === true ) {
  533. if ( this.parent === null ) {
  534. this.matrixWorld.copy( this.matrix );
  535. } else {
  536. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  537. }
  538. this.animate.updateMatrix();
  539. this.matrixWorld.multiplyMatrices( this.matrixWorld, this.animate.matrix );
  540. this.matrixWorldNeedsUpdate = false;
  541. force = true;
  542. }
  543. // update children
  544. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  545. this.children[ i ].updateMatrixWorld( force );
  546. }
  547. },
  548. setAnimator: function ( val ) {
  549. if ( this.getAnimator() == val )
  550. return;
  551. if ( val ) {
  552. this.animate = new THREE.Object3D();
  553. this.updateMatrixWorld = THREE.SEA3D.Object3D.prototype.updateAnimateMatrix;
  554. } else {
  555. delete this.animate;
  556. this.updateMatrixWorld = THREE.Object3D.prototype.updateMatrixWorld;
  557. }
  558. this.matrixWorldNeedsUpdate = true;
  559. },
  560. getAnimator: function () {
  561. return this.animate != undefined;
  562. }
  563. } );
  564. //
  565. // Dummy
  566. //
  567. THREE.SEA3D.Dummy = function ( width, height, depth ) {
  568. this.width = width != undefined ? width : 100;
  569. this.height = height != undefined ? height : 100;
  570. this.depth = depth != undefined ? depth : 100;
  571. var geo = new THREE.BoxGeometry( this.width, this.height, this.depth, 1, 1, 1 );
  572. geo.computeBoundingBox();
  573. geo.computeBoundingSphere();
  574. THREE.Mesh.call( this, geo, THREE.SEA3D.Dummy.MATERIAL );
  575. };
  576. THREE.SEA3D.Dummy.MATERIAL = new THREE.MeshBasicMaterial( { wireframe: true, color: THREE.SEA3D.HELPER_COLOR } );
  577. THREE.SEA3D.Dummy.prototype = Object.assign( Object.create( THREE.Mesh.prototype ), THREE.SEA3D.Object3D.prototype, {
  578. constructor: THREE.SEA3D.Dummy,
  579. copy: function ( source ) {
  580. THREE.Mesh.prototype.copy.call( this, source );
  581. this.attribs = source.attribs;
  582. this.scripts = source.scripts;
  583. if ( this.animator ) this.animator = source.animator.clone( this );
  584. return this;
  585. },
  586. dispose: function () {
  587. this.geometry.dispose();
  588. }
  589. } );
  590. //
  591. // Mesh
  592. //
  593. THREE.SEA3D.Mesh = function ( geometry, material ) {
  594. THREE.Mesh.call( this, geometry, material );
  595. };
  596. THREE.SEA3D.Mesh.prototype = Object.assign( Object.create( THREE.Mesh.prototype ), THREE.SEA3D.Mesh.prototype, THREE.SEA3D.Object3D.prototype, {
  597. constructor: THREE.SEA3D.Mesh,
  598. setWeight: function ( name, val ) {
  599. if ( this.animations && ( this.animations[ name ] || this.animationsIndex[ name ] ) ) this.mixer.clipAction( name ).setEffectiveWeight( val );
  600. if ( this.morphTargetInfluences && this.morphTargetDictionary[ name ] !== undefined ) this.morphTargetInfluences[ this.morphTargetDictionary[ name ] ] = val;
  601. },
  602. getWeight: function ( name ) {
  603. if ( this.animations && ( this.animations[ name ] || this.animationsIndex[ name ] ) ) return this.mixer.clipAction( name ).getEffectiveWeight();
  604. if ( this.morphTargetDictionary && this.morphTargetDictionary[ name ] !== undefined ) return this.morphTargetInfluences[ this.morphTargetDictionary[ name ] ];
  605. },
  606. copy: function ( source ) {
  607. THREE.Mesh.prototype.copy.call( this, source );
  608. this.attribs = source.attribs;
  609. this.scripts = source.scripts;
  610. if ( this.animator ) this.animator = source.animator.clone( this );
  611. return this;
  612. }
  613. } );
  614. //
  615. // Skinning
  616. //
  617. THREE.SEA3D.SkinnedMesh = function ( geometry, material, useVertexTexture ) {
  618. THREE.SkinnedMesh.call( this, geometry, material, useVertexTexture );
  619. this.updateAnimations( new THREE.AnimationMixer( this ) );
  620. };
  621. THREE.SEA3D.SkinnedMesh.prototype = Object.assign( Object.create( THREE.SkinnedMesh.prototype ), THREE.SEA3D.Mesh.prototype, THREE.SEA3D.Animator.prototype, {
  622. constructor: THREE.SEA3D.SkinnedMesh,
  623. boneByName: function ( name ) {
  624. var bones = this.skeleton.bones;
  625. for ( var i = 0, bl = bones.length; i < bl; i ++ ) {
  626. if ( name == bones[ i ].name )
  627. return bones[ i ];
  628. }
  629. },
  630. copy: function ( source ) {
  631. THREE.SkinnedMesh.prototype.copy.call( this, source );
  632. this.attribs = source.attribs;
  633. this.scripts = source.scripts;
  634. if ( this.animator ) this.animator = source.animator.clone( this );
  635. return this;
  636. }
  637. } );
  638. //
  639. // Vertex Animation
  640. //
  641. THREE.SEA3D.VertexAnimationMesh = function ( geometry, material ) {
  642. THREE.Mesh.call( this, geometry, material );
  643. this.type = 'MorphAnimMesh';
  644. this.updateAnimations( new THREE.AnimationMixer( this ) );
  645. };
  646. THREE.SEA3D.VertexAnimationMesh.prototype = Object.assign( Object.create( THREE.Mesh.prototype ), THREE.SEA3D.Mesh.prototype, THREE.SEA3D.Animator.prototype, {
  647. constructor: THREE.SEA3D.VertexAnimationMesh,
  648. copy: function ( source ) {
  649. THREE.Mesh.prototype.copy.call( this, source );
  650. this.attribs = source.attribs;
  651. this.scripts = source.scripts;
  652. if ( this.animator ) this.animator = source.animator.clone( this );
  653. return this;
  654. }
  655. } );
  656. //
  657. // Camera
  658. //
  659. THREE.SEA3D.Camera = function ( fov, aspect, near, far ) {
  660. THREE.PerspectiveCamera.call( this, fov, aspect, near, far );
  661. };
  662. THREE.SEA3D.Camera.prototype = Object.assign( Object.create( THREE.PerspectiveCamera.prototype ), THREE.SEA3D.Object3D.prototype, {
  663. constructor: THREE.SEA3D.Camera,
  664. copy: function ( source ) {
  665. THREE.PerspectiveCamera.prototype.copy.call( this, source );
  666. this.attribs = source.attribs;
  667. this.scripts = source.scripts;
  668. if ( this.animator ) this.animator = source.animator.clone( this );
  669. return this;
  670. }
  671. } );
  672. //
  673. // Orthographic Camera
  674. //
  675. THREE.SEA3D.OrthographicCamera = function ( left, right, top, bottom, near, far ) {
  676. THREE.OrthographicCamera.call( this, left, right, top, bottom, near, far );
  677. };
  678. THREE.SEA3D.OrthographicCamera.prototype = Object.assign( Object.create( THREE.OrthographicCamera.prototype ), THREE.SEA3D.Object3D.prototype, {
  679. constructor: THREE.SEA3D.OrthographicCamera,
  680. copy: function ( source ) {
  681. THREE.OrthographicCamera.prototype.copy.call( this, source );
  682. this.attribs = source.attribs;
  683. this.scripts = source.scripts;
  684. if ( this.animator ) this.animator = source.animator.clone( this );
  685. return this;
  686. }
  687. } );
  688. //
  689. // PointLight
  690. //
  691. THREE.SEA3D.PointLight = function ( hex, intensity, distance, decay ) {
  692. THREE.PointLight.call( this, hex, intensity, distance, decay );
  693. };
  694. THREE.SEA3D.PointLight.prototype = Object.assign( Object.create( THREE.PointLight.prototype ), THREE.SEA3D.Object3D.prototype, {
  695. constructor: THREE.SEA3D.PointLight,
  696. copy: function ( source ) {
  697. THREE.PointLight.prototype.copy.call( this, source );
  698. this.attribs = source.attribs;
  699. this.scripts = source.scripts;
  700. if ( this.animator ) this.animator = source.animator.clone( this );
  701. return this;
  702. }
  703. } );
  704. //
  705. // Point Sound
  706. //
  707. THREE.SEA3D.PointSound = function ( listener ) {
  708. THREE.PositionalAudio.call( this, listener );
  709. };
  710. THREE.SEA3D.PointSound.prototype = Object.assign( Object.create( THREE.PositionalAudio.prototype ), THREE.SEA3D.Object3D.prototype, {
  711. constructor: THREE.SEA3D.PointSound,
  712. copy: function ( source ) {
  713. THREE.PositionalAudio.prototype.copy.call( this, source );
  714. this.attribs = source.attribs;
  715. this.scripts = source.scripts;
  716. if ( this.animator ) this.animator = source.animator.clone( this );
  717. return this;
  718. }
  719. } );
  720. //
  721. // Animation Handler
  722. //
  723. THREE.SEA3D.AnimationHandler = {
  724. animators: [],
  725. update: function ( dt ) {
  726. var i = 0;
  727. while ( i < this.animators.length ) {
  728. this.animators[ i ++ ].update( dt );
  729. }
  730. },
  731. addAnimator: function ( animator ) {
  732. var index = this.animators.indexOf( animator );
  733. if ( index === - 1 ) this.animators.push( animator );
  734. },
  735. removeAnimator: function ( animator ) {
  736. var index = this.animators.indexOf( animator );
  737. if ( index !== - 1 ) this.animators.splice( index, 1 );
  738. }
  739. };
  740. //
  741. // Output
  742. //
  743. THREE.SEA3D.Domain.prototype.getMesh = THREE.SEA3D.prototype.getMesh = function ( name ) {
  744. return this.objects[ "m3d/" + name ];
  745. };
  746. THREE.SEA3D.Domain.prototype.getDummy = THREE.SEA3D.prototype.getDummy = function ( name ) {
  747. return this.objects[ "dmy/" + name ];
  748. };
  749. THREE.SEA3D.Domain.prototype.getLine = THREE.SEA3D.prototype.getLine = function ( name ) {
  750. return this.objects[ "line/" + name ];
  751. };
  752. THREE.SEA3D.Domain.prototype.getSound3D = THREE.SEA3D.prototype.getSound3D = function ( name ) {
  753. return this.objects[ "sn3d/" + name ];
  754. };
  755. THREE.SEA3D.Domain.prototype.getMaterial = THREE.SEA3D.prototype.getMaterial = function ( name ) {
  756. return this.objects[ "mat/" + name ];
  757. };
  758. THREE.SEA3D.Domain.prototype.getLight = THREE.SEA3D.prototype.getLight = function ( name ) {
  759. return this.objects[ "lht/" + name ];
  760. };
  761. THREE.SEA3D.Domain.prototype.getGLSL = THREE.SEA3D.prototype.getGLSL = function ( name ) {
  762. return this.objects[ "glsl/" + name ];
  763. };
  764. THREE.SEA3D.Domain.prototype.getCamera = THREE.SEA3D.prototype.getCamera = function ( name ) {
  765. return this.objects[ "cam/" + name ];
  766. };
  767. THREE.SEA3D.Domain.prototype.getTexture = THREE.SEA3D.prototype.getTexture = function ( name ) {
  768. return this.objects[ "tex/" + name ];
  769. };
  770. THREE.SEA3D.Domain.prototype.getCubeMap = THREE.SEA3D.prototype.getCubeMap = function ( name ) {
  771. return this.objects[ "cmap/" + name ];
  772. };
  773. THREE.SEA3D.Domain.prototype.getJointObject = THREE.SEA3D.prototype.getJointObject = function ( name ) {
  774. return this.objects[ "jnt/" + name ];
  775. };
  776. THREE.SEA3D.Domain.prototype.getContainer3D = THREE.SEA3D.prototype.getContainer3D = function ( name ) {
  777. return this.objects[ "c3d/" + name ];
  778. };
  779. THREE.SEA3D.Domain.prototype.getSprite = THREE.SEA3D.prototype.getSprite = function ( name ) {
  780. return this.objects[ "m2d/" + name ];
  781. };
  782. THREE.SEA3D.Domain.prototype.getProperties = THREE.SEA3D.prototype.getProperties = function ( name ) {
  783. return this.objects[ "prop/" + name ];
  784. };
  785. //
  786. // Utils
  787. //
  788. THREE.SEA3D.prototype.isPowerOfTwo = function ( num ) {
  789. return num ? ( ( num & - num ) == num ) : false;
  790. };
  791. THREE.SEA3D.prototype.nearestPowerOfTwo = function ( num ) {
  792. return Math.pow( 2, Math.round( Math.log( num ) / Math.LN2 ) );
  793. };
  794. THREE.SEA3D.prototype.updateTransform = function ( obj3d, sea ) {
  795. var mtx = THREE.SEA3D.MTXBUF, vec = THREE.SEA3D.VECBUF;
  796. if ( sea.transform ) mtx.elements.set( sea.transform );
  797. else mtx.makeTranslation( sea.position.x, sea.position.y, sea.position.z );
  798. // matrix
  799. obj3d.position.setFromMatrixPosition( mtx );
  800. obj3d.scale.setFromMatrixScale( mtx );
  801. // ignore rotation scale
  802. mtx.scale( vec.set( 1 / obj3d.scale.x, 1 / obj3d.scale.y, 1 / obj3d.scale.z ) );
  803. obj3d.rotation.setFromRotationMatrix( mtx );
  804. // optimize if is static
  805. if ( this.config.forceStatic || sea.isStatic ) {
  806. obj3d.updateMatrix();
  807. obj3d.matrixAutoUpdate = false;
  808. }
  809. };
  810. THREE.SEA3D.prototype.toVector3 = function ( data ) {
  811. return new THREE.Vector3( data.x, data.y, data.z );
  812. };
  813. THREE.SEA3D.prototype.toFaces = function ( faces ) {
  814. // xyz(- / +) to xyz(+ / -) sequence
  815. var f = [];
  816. f[ 0 ] = faces[ 1 ];
  817. f[ 1 ] = faces[ 0 ];
  818. f[ 2 ] = faces[ 3 ];
  819. f[ 3 ] = faces[ 2 ];
  820. f[ 4 ] = faces[ 5 ];
  821. f[ 5 ] = faces[ 4 ];
  822. return f;
  823. };
  824. THREE.SEA3D.prototype.updateScene = function () {
  825. if ( this.materials != undefined ) {
  826. for ( var i = 0, l = this.materials.length; i < l; ++ i ) {
  827. this.materials[ i ].needsUpdate = true;
  828. }
  829. }
  830. };
  831. THREE.SEA3D.prototype.addSceneObject = function ( sea, obj3d ) {
  832. obj3d = obj3d || sea.tag;
  833. obj3d.visible = sea.visible;
  834. if ( sea.parent ) sea.parent.tag.add( obj3d );
  835. else if ( this.config.container ) this.config.container.add( obj3d );
  836. if ( sea.attributes ) obj3d.attribs = sea.attributes.tag;
  837. if ( sea.scripts ) {
  838. obj3d.scripts = this.getJSMList( obj3d, sea.scripts );
  839. if ( this.config.runScripts ) this.domain.runJSMList( obj3d );
  840. }
  841. };
  842. THREE.SEA3D.prototype.createObjectURL = function ( raw, mime ) {
  843. return ( window.URL || window.webkitURL ).createObjectURL( new Blob( [ raw ], { type: mime } ) );
  844. };
  845. THREE.SEA3D.prototype.bufferToTexture = function ( raw ) {
  846. return this.createObjectURL( raw, "image" );
  847. };
  848. THREE.SEA3D.prototype.bufferToSound = function ( raw ) {
  849. return this.createObjectURL( raw, "audio" );
  850. };
  851. THREE.SEA3D.prototype.parsePath = function ( url ) {
  852. var paths = this.config.paths;
  853. for ( var name in paths ) {
  854. url = url.replace( new RegExp( "%" + name + "%", "g" ), paths[ name ] );
  855. }
  856. return url;
  857. };
  858. THREE.SEA3D.prototype.applyDefaultAnimation = function ( sea, animatorClass ) {
  859. var obj = sea.tag;
  860. for ( var i = 0, count = sea.animations ? sea.animations.length : 0; i < count; i ++ ) {
  861. var anm = sea.animations[ i ];
  862. switch ( anm.tag.type ) {
  863. case SEA3D.Animation.prototype.type:
  864. obj.animator = new animatorClass( anm.tag.tag, obj );
  865. obj.animator.setRelative( anm.relative );
  866. if ( this.config.autoPlay ) {
  867. obj.animator.play( 0 );
  868. }
  869. return obj.animator;
  870. break;
  871. }
  872. }
  873. };
  874. //
  875. // Animation
  876. //
  877. THREE.SEA3D.prototype.readAnimation = function ( sea ) {
  878. var clips = [], delta = ( 1000 / sea.frameRate ) / 1000;
  879. for ( var i = 0; i < sea.sequence.length; i ++ ) {
  880. var seq = sea.sequence[ i ];
  881. var tracks = [];
  882. for ( var j = 0; j < sea.dataList.length; j ++ ) {
  883. var anm = sea.dataList[ j ],
  884. t, k, times, values,
  885. data = anm.data,
  886. start = seq.start * anm.blockSize,
  887. end = start + ( seq.count * anm.blockSize ),
  888. intrpl = seq.intrpl ? THREE.InterpolateLinear : false,
  889. name = null;
  890. switch ( anm.kind ) {
  891. case SEA3D.Animation.POSITION:
  892. name = '.position';
  893. break;
  894. case SEA3D.Animation.ROTATION:
  895. name = '.quaternion';
  896. break;
  897. case SEA3D.Animation.SCALE:
  898. name = '.scale';
  899. break;
  900. case SEA3D.Animation.COLOR:
  901. name = '.color';
  902. break;
  903. case SEA3D.Animation.MULTIPLIER:
  904. name = '.intensity';
  905. break;
  906. case SEA3D.Animation.FOV:
  907. name = '.fov';
  908. break;
  909. }
  910. if ( ! name ) continue;
  911. switch ( anm.type ) {
  912. case SEA3D.Stream.BYTE:
  913. case SEA3D.Stream.UBYTE:
  914. case SEA3D.Stream.INT:
  915. case SEA3D.Stream.UINT:
  916. case SEA3D.Stream.FLOAT:
  917. case SEA3D.Stream.DOUBLE:
  918. case SEA3D.Stream.DECIMAL:
  919. values = data.subarray( start, end );
  920. times = new Float32Array( values.length );
  921. t = 0;
  922. for ( k = 0; k < times.length; k ++ ) {
  923. times[ k ] = t;
  924. t += delta;
  925. }
  926. tracks.push( new THREE.VectorKeyframeTrack( name, times, values, intrpl ) );
  927. break;
  928. case SEA3D.Stream.VECTOR3D:
  929. values = data.subarray( start, end );
  930. times = new Float32Array( values.length / anm.blockSize );
  931. t = 0;
  932. for ( k = 0; k < times.length; k ++ ) {
  933. times[ k ] = t;
  934. t += delta;
  935. }
  936. tracks.push( new THREE.VectorKeyframeTrack( name, times, values, intrpl ) );
  937. break;
  938. case SEA3D.Stream.VECTOR4D:
  939. values = data.subarray( start, end );
  940. times = new Float32Array( values.length / anm.blockSize );
  941. t = 0;
  942. for ( k = 0; k < times.length; k ++ ) {
  943. times[ k ] = t;
  944. t += delta;
  945. }
  946. tracks.push( new THREE.QuaternionKeyframeTrack( name, times, values, intrpl ) );
  947. break;
  948. case SEA3D.Stream.INT24:
  949. case SEA3D.Stream.UINT24:
  950. values = new Float32Array( ( end - start ) * 3 );
  951. times = new Float32Array( values.length / 3 );
  952. t = 0;
  953. for ( k = 0; k < times.length; k ++ ) {
  954. values[ ( k * 3 ) ] = ( ( data[ k ] >> 16 ) & 0xFF ) / 255;
  955. values[ ( k * 3 ) + 1 ] = ( ( data[ k ] >> 8 ) & 0xFF ) / 255;
  956. values[ ( k * 3 ) + 2 ] = ( data[ k ] & 0xFF ) / 255;
  957. times[ k ] = t;
  958. t += delta;
  959. }
  960. tracks.push( new THREE.VectorKeyframeTrack( name, times, values, intrpl ) );//ColorKeyframeTrack
  961. break;
  962. }
  963. }
  964. var clip = new THREE.AnimationClip( seq.name, - 1, tracks );
  965. clip.loop = seq.repeat;
  966. clip.timeScale = 1;
  967. clips.push( clip );
  968. }
  969. this.domain.animationClips = this.animationClips = this.animationClips || [];
  970. this.animationClips.push( this.objects[ sea.name + '.#anm' ] = sea.tag = clips );
  971. };
  972. //
  973. // Geometry
  974. //
  975. THREE.SEA3D.prototype.readGeometryBuffer = function ( sea ) {
  976. var geo = new THREE.BufferGeometry();
  977. for ( var i = 0; i < sea.groups.length; i ++ ) {
  978. var g = sea.groups[ i ];
  979. geo.addGroup( g.start, g.count, i );
  980. }
  981. geo.setIndex( new THREE.BufferAttribute( sea.indexes, 1 ) );
  982. geo.addAttribute( 'position', new THREE.BufferAttribute( sea.vertex, 3 ) );
  983. if ( sea.uv ) {
  984. geo.addAttribute( 'uv', new THREE.BufferAttribute( sea.uv[ 0 ], 2 ) );
  985. if ( sea.uv.length > 1 ) geo.addAttribute( 'uv2', new THREE.BufferAttribute( sea.uv[ 1 ], 2 ) );
  986. }
  987. if ( sea.normal ) geo.addAttribute( 'normal', new THREE.BufferAttribute( sea.normal, 3 ) );
  988. else geo.computeVertexNormals();
  989. if ( sea.tangent4 ) geo.addAttribute( 'tangent', new THREE.BufferAttribute( sea.tangent4, 4 ) );
  990. if ( sea.color ) geo.addAttribute( 'color', new THREE.BufferAttribute( sea.color[ 0 ], sea.numColor ) );
  991. if ( sea.joint ) {
  992. geo.addAttribute( 'skinIndex', new THREE.Float32BufferAttribute( sea.joint, sea.jointPerVertex ) );
  993. geo.addAttribute( 'skinWeight', new THREE.Float32BufferAttribute( sea.weight, sea.jointPerVertex ) );
  994. }
  995. if ( this.config.bounding ) {
  996. geo.computeBoundingBox();
  997. geo.computeBoundingSphere();
  998. }
  999. geo.name = sea.name;
  1000. this.domain.geometries = this.geometries = this.geometries || [];
  1001. this.geometries.push( this.objects[ "geo/" + sea.name ] = sea.tag = geo );
  1002. };
  1003. //
  1004. // Dummy
  1005. //
  1006. THREE.SEA3D.prototype.readDummy = function ( sea ) {
  1007. var dummy = new THREE.SEA3D.Dummy( sea.width, sea.height, sea.depth );
  1008. dummy.name = sea.name;
  1009. this.domain.dummys = this.dummys = this.dummys || [];
  1010. this.dummys.push( this.objects[ "dmy/" + sea.name ] = sea.tag = dummy );
  1011. this.addSceneObject( sea );
  1012. this.updateTransform( dummy, sea );
  1013. this.applyDefaultAnimation( sea, THREE.SEA3D.Object3DAnimator );
  1014. };
  1015. //
  1016. // Line
  1017. //
  1018. THREE.SEA3D.prototype.readLine = function ( sea ) {
  1019. var geo = new THREE.BufferGeometry();
  1020. if ( sea.closed )
  1021. sea.vertex.push( sea.vertex[ 0 ], sea.vertex[ 1 ], sea.vertex[ 2 ] );
  1022. geo.addAttribute( 'position', new THREE.Float32BufferAttribute( sea.vertex, 3 ) );
  1023. var line = new THREE.Line( geo, new THREE.LineBasicMaterial( { color: THREE.SEA3D.HELPER_COLOR, linewidth: 3 } ) );
  1024. line.name = sea.name;
  1025. this.lines = this.lines || [];
  1026. this.lines.push( this.objects[ "line/" + sea.name ] = sea.tag = line );
  1027. this.addSceneObject( sea );
  1028. this.updateTransform( line, sea );
  1029. this.applyDefaultAnimation( sea, THREE.SEA3D.Object3DAnimator );
  1030. };
  1031. //
  1032. // Container3D
  1033. //
  1034. THREE.SEA3D.prototype.readContainer3D = function ( sea ) {
  1035. var container = new THREE.SEA3D.Object3D();
  1036. this.domain.containers = this.containers = this.containers || [];
  1037. this.containers.push( this.objects[ "c3d/" + sea.name ] = sea.tag = container );
  1038. this.addSceneObject( sea );
  1039. this.updateTransform( container, sea );
  1040. this.applyDefaultAnimation( sea, THREE.SEA3D.Object3DAnimator );
  1041. };
  1042. //
  1043. // Sprite
  1044. //
  1045. THREE.SEA3D.prototype.readSprite = function ( sea ) {
  1046. var mat;
  1047. if ( sea.material ) {
  1048. if ( ! sea.material.tag.sprite ) {
  1049. mat = sea.material.tag.sprite = new THREE.SpriteMaterial();
  1050. this.setBlending( mat, sea.blendMode );
  1051. mat.map = sea.material.tag.map;
  1052. mat.map.flipY = true;
  1053. mat.color.set( sea.material.tag.color );
  1054. mat.opacity = sea.material.tag.opacity;
  1055. mat.fog = sea.material.receiveFog;
  1056. } else mat = sea.material.tag.sprite;
  1057. }
  1058. var sprite = new THREE.Sprite( mat );
  1059. sprite.name = sea.name;
  1060. this.domain.sprites = this.sprites = this.sprites || [];
  1061. this.sprites.push( this.objects[ "m2d/" + sea.name ] = sea.tag = sprite );
  1062. this.addSceneObject( sea );
  1063. this.updateTransform( sprite, sea );
  1064. sprite.scale.set( sea.width, sea.height, 1 );
  1065. };
  1066. //
  1067. // Mesh
  1068. //
  1069. THREE.SEA3D.prototype.readMesh = function ( sea ) {
  1070. var i, count, geo = sea.geometry.tag, mesh, mat, skeleton, skeletonAnimation, vertexAnimation, morpher;
  1071. for ( i = 0, count = sea.modifiers ? sea.modifiers.length : 0; i < count; i ++ ) {
  1072. var mod = sea.modifiers[ i ];
  1073. switch ( mod.type ) {
  1074. case SEA3D.Skeleton.prototype.type:
  1075. case SEA3D.SkeletonLocal.prototype.type:
  1076. skeleton = mod;
  1077. geo.bones = skeleton.tag;
  1078. break;
  1079. case SEA3D.Morph.prototype.type:
  1080. morpher = mod;
  1081. geo.morphAttributes = morpher.tag.attribs;
  1082. geo.morphTargets = morpher.tag.targets;
  1083. break;
  1084. }
  1085. }
  1086. for ( i = 0, count = sea.animations ? sea.animations.length : 0; i < count; i ++ ) {
  1087. var anm = sea.animations[ i ];
  1088. switch ( anm.tag.type ) {
  1089. case SEA3D.SkeletonAnimation.prototype.type:
  1090. skeletonAnimation = anm.tag;
  1091. geo.animations = this.getSkeletonAnimation( skeletonAnimation, skeleton );
  1092. break;
  1093. case SEA3D.VertexAnimation.prototype.type:
  1094. vertexAnimation = anm.tag;
  1095. geo.morphAttributes = vertexAnimation.tag.attribs;
  1096. geo.morphTargets = vertexAnimation.tag.targets;
  1097. geo.animations = vertexAnimation.tag.animations;
  1098. break;
  1099. }
  1100. }
  1101. var uMorph = morpher != undefined || vertexAnimation != undefined,
  1102. uMorphNormal =
  1103. ( morpher && morpher.tag.attribs.normal != undefined ) ||
  1104. ( vertexAnimation && vertexAnimation.tag.attribs.normal != undefined );
  1105. if ( sea.material ) {
  1106. if ( sea.material.length > 1 ) {
  1107. var mats = [];
  1108. for ( i = 0; i < sea.material.length; i ++ ) {
  1109. mats[ i ] = sea.material[ i ].tag;
  1110. mats[ i ].skinning = skeleton != undefined;
  1111. mats[ i ].morphTargets = uMorph;
  1112. mats[ i ].morphNormals = uMorphNormal;
  1113. mats[ i ].vertexColors = sea.geometry.color ? THREE.VertexColors : THREE.NoColors;
  1114. }
  1115. mat = new THREE.MultiMaterial( mats );
  1116. } else {
  1117. mat = sea.material[ 0 ].tag;
  1118. mat.skinning = skeleton != undefined;
  1119. mat.morphTargets = uMorph;
  1120. mat.morphNormals = uMorphNormal;
  1121. mat.vertexColors = sea.geometry.color ? THREE.VertexColors : THREE.NoColors;
  1122. }
  1123. }
  1124. if ( skeleton ) {
  1125. mesh = new THREE.SEA3D.SkinnedMesh( geo, mat, this.config.useVertexTexture );
  1126. if ( this.config.autoPlay && skeletonAnimation ) {
  1127. mesh.play( 0 );
  1128. }
  1129. } else if ( vertexAnimation ) {
  1130. mesh = new THREE.SEA3D.VertexAnimationMesh( geo, mat, vertexAnimation.frameRate );
  1131. if ( this.config.autoPlay ) {
  1132. mesh.play( 0 );
  1133. }
  1134. } else {
  1135. mesh = new THREE.SEA3D.Mesh( geo, mat );
  1136. }
  1137. mesh.name = sea.name;
  1138. mesh.castShadow = sea.castShadows;
  1139. mesh.receiveShadow = sea.material ? sea.material[ 0 ].receiveShadows : true;
  1140. this.domain.meshes = this.meshes = this.meshes || [];
  1141. this.meshes.push( this.objects[ "m3d/" + sea.name ] = sea.tag = mesh );
  1142. this.addSceneObject( sea );
  1143. this.updateTransform( mesh, sea );
  1144. this.applyDefaultAnimation( sea, THREE.SEA3D.Object3DAnimator );
  1145. };
  1146. //
  1147. // Sound Point
  1148. //
  1149. THREE.SEA3D.prototype.readSoundPoint = function ( sea ) {
  1150. if ( ! this.audioListener ) {
  1151. this.audioListener = new THREE.AudioListener();
  1152. if ( this.config.container ) {
  1153. this.config.container.add( this.audioListener );
  1154. }
  1155. }
  1156. var sound3d = new THREE.SEA3D.PointSound( this.audioListener );
  1157. new THREE.AudioLoader().load( sea.sound.tag, function ( buffer ) {
  1158. sound3d.setBuffer( buffer );
  1159. } );
  1160. sound3d.autoplay = sea.autoPlay;
  1161. sound3d.setLoop( sea.autoPlay );
  1162. sound3d.setVolume( sea.volume );
  1163. sound3d.setRefDistance( sea.distance );
  1164. sound3d.setRolloffFactor( this.config.audioRolloffFactor );
  1165. sound3d.name = sea.name;
  1166. this.domain.sounds3d = this.sounds3d = this.sounds3d || [];
  1167. this.sounds3d.push( this.objects[ "sn3d/" + sea.name ] = sea.tag = sound3d );
  1168. this.addSceneObject( sea );
  1169. this.updateTransform( sound3d, sea );
  1170. this.applyDefaultAnimation( sea, THREE.SEA3D.SoundAnimator );
  1171. };
  1172. //
  1173. // Cube Render
  1174. //
  1175. THREE.SEA3D.prototype.readCubeRender = function ( sea ) {
  1176. var cube = new THREE.CubeCamera( 0.1, 5000, THREE.SEA3D.RTT_SIZE );
  1177. cube.renderTarget.cubeCamera = cube;
  1178. sea.tag = cube.renderTarget;
  1179. this.domain.cubeRenderers = this.cubeRenderers = this.cubeRenderers || [];
  1180. this.cubeRenderers.push( this.objects[ "rttc/" + sea.name ] = cube );
  1181. this.addSceneObject( sea, cube );
  1182. this.updateTransform( cube, sea );
  1183. };
  1184. //
  1185. // Images (WDP, JPEG, PNG and GIF)
  1186. //
  1187. THREE.SEA3D.prototype.readTexture = function ( sea ) {
  1188. var image = new Image(),
  1189. texture = new THREE.Texture();
  1190. texture.name = sea.name;
  1191. texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
  1192. texture.flipY = false;
  1193. texture.image = image;
  1194. if ( this.config.anisotropy !== undefined ) texture.anisotropy = this.config.anisotropy;
  1195. image.onload = function () {
  1196. texture.needsUpdate = true;
  1197. };
  1198. image.src = this.bufferToTexture( sea.data.buffer );
  1199. this.domain.textures = this.textures = this.textures || [];
  1200. this.textures.push( this.objects[ "tex/" + sea.name ] = sea.tag = texture );
  1201. };
  1202. //
  1203. // Cube Map
  1204. //
  1205. THREE.SEA3D.prototype.readCubeMap = function ( sea ) {
  1206. var faces = this.toFaces( sea.faces ), texture = new THREE.CubeTexture( [] );
  1207. var loaded = 0;
  1208. texture.name = sea.name;
  1209. texture.flipY = false;
  1210. texture.format = THREE.RGBFormat;
  1211. var onLoaded = function () {
  1212. if ( ++ loaded == 6 ) {
  1213. texture.needsUpdate = true;
  1214. if ( ! this.config.async ) this.file.resume = true;
  1215. }
  1216. }.bind( this );
  1217. for ( var i = 0; i < faces.length; ++ i ) {
  1218. var cubeImage = new Image();
  1219. cubeImage.onload = onLoaded;
  1220. cubeImage.src = this.bufferToTexture( faces[ i ].buffer );
  1221. texture.images[ i ] = cubeImage;
  1222. }
  1223. if ( ! this.config.async ) this.file.resume = false;
  1224. this.domain.cubemaps = this.cubemaps = this.cubemaps || [];
  1225. this.cubemaps.push( this.objects[ "cmap/" + sea.name ] = sea.tag = texture );
  1226. };
  1227. //
  1228. // Sound (MP3, OGG)
  1229. //
  1230. THREE.SEA3D.prototype.readSound = function ( sea ) {
  1231. var sound = this.bufferToSound( sea.data.buffer );
  1232. this.domain.sounds = this.sounds = this.sounds || [];
  1233. this.sounds.push( this.objects[ "snd/" + sea.name ] = sea.tag = sound );
  1234. };
  1235. //
  1236. // Script URL
  1237. //
  1238. THREE.SEA3D.prototype.readScriptURL = function ( sea ) {
  1239. this.file.resume = false;
  1240. var loader = new THREE.FileLoader();
  1241. loader.setResponseType( "text" ).load( sea.url, function ( src ) {
  1242. this.file.resume = true;
  1243. this.domain.scripts = this.scripts = this.scripts || [];
  1244. this.scripts.push( this.objects[ "src/" + sea.name ] = sea.tag = src );
  1245. }.bind( this ) );
  1246. };
  1247. //
  1248. // Texture URL
  1249. //
  1250. THREE.SEA3D.prototype.readTextureURL = function ( sea ) {
  1251. var texture = new THREE.TextureLoader().load( this.parsePath( sea.url ) );
  1252. texture.name = sea.name;
  1253. texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
  1254. texture.flipY = false;
  1255. if ( this.config.anisotropy !== undefined ) texture.anisotropy = this.config.anisotropy;
  1256. this.domain.textures = this.textures = this.textures || [];
  1257. this.textures.push( this.objects[ "tex/" + sea.name ] = sea.tag = texture );
  1258. };
  1259. //
  1260. // CubeMap URL
  1261. //
  1262. THREE.SEA3D.prototype.readCubeMapURL = function ( sea ) {
  1263. var faces = this.toFaces( sea.faces );
  1264. for ( var i = 0; i < faces.length; i ++ ) {
  1265. faces[ i ] = this.parsePath( faces[ i ] );
  1266. }
  1267. var texture, format = faces[ 0 ].substr( - 3 );
  1268. if ( format == "hdr" ) {
  1269. var usePMREM = THREE.PMREMGenerator != null;
  1270. this.file.resume = ! usePMREM;
  1271. texture = new THREE.HDRCubeTextureLoader().load( THREE.UnsignedByteType, faces, function ( texture ) {
  1272. if ( usePMREM ) {
  1273. var pmremGenerator = new THREE.PMREMGenerator( texture );
  1274. pmremGenerator.update( this.config.renderer );
  1275. var pmremCubeUVPacker = new THREE.PMREMCubeUVPacker( pmremGenerator.cubeLods );
  1276. pmremCubeUVPacker.update( this.config.renderer );
  1277. texture.dispose();
  1278. this.objects[ "cmap/" + sea.name ] = sea.tag = pmremCubeUVPacker.CubeUVRenderTarget.texture;
  1279. this.file.resume = true;
  1280. }
  1281. }.bind( this ) );
  1282. } else {
  1283. texture = new THREE.CubeTextureLoader().load( faces );
  1284. }
  1285. texture.name = sea.name;
  1286. texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
  1287. texture.flipY = false;
  1288. if ( this.config.anisotropy !== undefined ) texture.anisotropy = this.config.anisotropy;
  1289. this.domain.cubemaps = this.cubemaps = this.cubemaps || [];
  1290. this.cubemaps.push( this.objects[ "cmap/" + sea.name ] = sea.tag = texture );
  1291. };
  1292. //
  1293. // Runtime
  1294. //
  1295. THREE.SEA3D.prototype.getJSMList = function ( target, scripts ) {
  1296. var scriptTarget = [];
  1297. for ( var i = 0; i < scripts.length; i ++ ) {
  1298. var script = scripts[ i ];
  1299. if ( script.tag.type == SEA3D.JavaScriptMethod.prototype.type ) {
  1300. scriptTarget.push( script );
  1301. }
  1302. }
  1303. this.domain.scriptTargets = this.scriptTargets = this.scriptTargets || [];
  1304. this.scriptTargets.push( target );
  1305. return scriptTarget;
  1306. };
  1307. THREE.SEA3D.prototype.readJavaScriptMethod = function ( sea ) {
  1308. try {
  1309. var src =
  1310. '(function() {\n' +
  1311. 'var $METHOD = {}\n';
  1312. var declare =
  1313. 'function($INC, $REF, global, local, $his, $PARAM) {\n' +
  1314. 'var watch = $INC["watch"],\n' +
  1315. 'scene = $INC["scene"],\n' +
  1316. 'sea3d = $INC["sea3d"],\n' +
  1317. 'print = $INC["print"];\n';
  1318. declare +=
  1319. 'var $SRC = $INC["source"],\n' +
  1320. 'addEventListener = $SRC.addEventListener.bind( $SRC ),\n' +
  1321. 'hasEventListener = $SRC.hasEventListener.bind( $SRC ),\n' +
  1322. 'removeEventListener = $SRC.removeEventListener.bind( $SRC ),\n' +
  1323. 'dispatchEvent = $SRC.dispatchEvent.bind( $SRC ),\n' +
  1324. 'dispose = $SRC.dispose.bind( $SRC );\n';
  1325. for ( var name in sea.methods ) {
  1326. src += '$METHOD["' + name + '"] = ' + declare + sea.methods[ name ].src + '}\n';
  1327. }
  1328. src += 'return $METHOD; })';
  1329. this.domain.methods = eval( src )();
  1330. } catch ( e ) {
  1331. console.error( 'SEA3D JavaScriptMethod: Error running "' + sea.name + '".' );
  1332. console.error( e );
  1333. }
  1334. };
  1335. //
  1336. // GLSL
  1337. //
  1338. THREE.SEA3D.prototype.readGLSL = function ( sea ) {
  1339. this.domain.glsl = this.glsl = this.glsl || [];
  1340. this.glsl.push( this.objects[ "glsl/" + sea.name ] = sea.tag = sea.src );
  1341. };
  1342. //
  1343. // Material
  1344. //
  1345. THREE.SEA3D.prototype.materialTechnique =
  1346. ( function () {
  1347. var techniques = {};
  1348. // FINAL
  1349. techniques.onComplete = function ( mat, sea ) {
  1350. if ( sea.alpha < 1 || mat.blending > THREE.NormalBlending ) {
  1351. mat.opacity = sea.alpha;
  1352. mat.transparent = true;
  1353. }
  1354. };
  1355. // PHYSICAL
  1356. techniques[ SEA3D.Material.PHYSICAL ] =
  1357. function ( mat, tech ) {
  1358. mat.color.setHex( tech.color );
  1359. mat.roughness = tech.roughness;
  1360. mat.metalness = tech.metalness;
  1361. };
  1362. // REFLECTIVITY
  1363. techniques[ SEA3D.Material.REFLECTIVITY ] =
  1364. function ( mat, tech ) {
  1365. mat.reflectivity = tech.strength;
  1366. };
  1367. // CLEAR_COAT
  1368. techniques[ SEA3D.Material.CLEAR_COAT ] =
  1369. function ( mat, tech ) {
  1370. mat.clearCoat = tech.strength;
  1371. mat.clearCoatRoughness = tech.roughness;
  1372. };
  1373. // PHONG
  1374. techniques[ SEA3D.Material.PHONG ] =
  1375. function ( mat, tech ) {
  1376. mat.color.setHex( tech.diffuseColor );
  1377. mat.specular.setHex( tech.specularColor ).multiplyScalar( tech.specular );
  1378. mat.shininess = tech.gloss;
  1379. };
  1380. // DIFFUSE_MAP
  1381. techniques[ SEA3D.Material.DIFFUSE_MAP ] =
  1382. function ( mat, tech, sea ) {
  1383. mat.map = tech.texture.tag;
  1384. mat.color.setHex( 0xFFFFFF );
  1385. mat.map.wrapS = mat.map.wrapT = sea.repeat ? THREE.RepeatWrapping : THREE.ClampToEdgeWrapping;
  1386. if ( tech.texture.transparent ) {
  1387. mat.transparent = true;
  1388. }
  1389. };
  1390. // ROUGHNESS_MAP
  1391. techniques[ SEA3D.Material.ROUGHNESS_MAP ] =
  1392. function ( mat, tech ) {
  1393. mat.roughnessMap = tech.texture.tag;
  1394. };
  1395. // METALNESS_MAP
  1396. techniques[ SEA3D.Material.METALNESS_MAP ] =
  1397. function ( mat, tech ) {
  1398. mat.metalnessMap = tech.texture.tag;
  1399. };
  1400. // SPECULAR_MAP
  1401. techniques[ SEA3D.Material.SPECULAR_MAP ] =
  1402. function ( mat, tech ) {
  1403. if ( mat.specular ) {
  1404. mat.specularMap = tech.texture.tag;
  1405. mat.specular.setHex( 0xFFFFFF );
  1406. }
  1407. };
  1408. // NORMAL_MAP
  1409. techniques[ SEA3D.Material.NORMAL_MAP ] =
  1410. function ( mat, tech ) {
  1411. mat.normalMap = tech.texture.tag;
  1412. };
  1413. // REFLECTION
  1414. techniques[ SEA3D.Material.REFLECTION ] =
  1415. techniques[ SEA3D.Material.FRESNEL_REFLECTION ] =
  1416. function ( mat, tech ) {
  1417. mat.envMap = tech.texture.tag;
  1418. mat.envMap.mapping = THREE.CubeReflectionMapping;
  1419. mat.combine = THREE.MixOperation;
  1420. mat.reflectivity = tech.alpha;
  1421. };
  1422. // REFLECTION_SPHERICAL
  1423. techniques[ SEA3D.Material.REFLECTION_SPHERICAL ] =
  1424. function ( mat, tech ) {
  1425. mat.envMap = tech.texture.tag;
  1426. mat.envMap.mapping = THREE.SphericalReflectionMapping;
  1427. mat.combine = THREE.MixOperation;
  1428. mat.reflectivity = tech.alpha;
  1429. };
  1430. // REFRACTION
  1431. techniques[ SEA3D.Material.REFRACTION_MAP ] =
  1432. function ( mat, tech ) {
  1433. mat.envMap = tech.texture.tag;
  1434. mat.envMap.mapping = THREE.CubeRefractionMapping;
  1435. mat.refractionRatio = tech.ior;
  1436. mat.reflectivity = tech.alpha;
  1437. };
  1438. // LIGHT_MAP
  1439. techniques[ SEA3D.Material.LIGHT_MAP ] =
  1440. function ( mat, tech ) {
  1441. if ( tech.blendMode == "multiply" ) mat.aoMap = tech.texture.tag;
  1442. else mat.lightMap = tech.texture.tag;
  1443. };
  1444. // ALPHA_MAP
  1445. techniques[ SEA3D.Material.ALPHA_MAP ] =
  1446. function ( mat, tech, sea ) {
  1447. mat.alphaMap = tech.texture.tag;
  1448. mat.transparent = true;
  1449. mat.alphaMap.wrapS = mat.alphaMap.wrapT = sea.repeat ? THREE.RepeatWrapping : THREE.ClampToEdgeWrapping;
  1450. };
  1451. return techniques;
  1452. } )();
  1453. THREE.SEA3D.prototype.createMaterial = function ( sea ) {
  1454. if ( sea.tecniquesDict[ SEA3D.Material.REFLECTIVITY ] || sea.tecniquesDict[ SEA3D.Material.CLEAR_COAT ] ) {
  1455. return new THREE.MeshPhysicalMaterial();
  1456. } else if ( sea.tecniquesDict[ SEA3D.Material.PHYSICAL ] ) {
  1457. return new THREE.MeshStandardMaterial();
  1458. }
  1459. return new THREE.MeshPhongMaterial();
  1460. };
  1461. THREE.SEA3D.prototype.setBlending = function ( mat, blendMode ) {
  1462. if ( blendMode === "normal" ) return;
  1463. switch ( blendMode ) {
  1464. case "add":
  1465. mat.blending = THREE.AdditiveBlending;
  1466. break;
  1467. case "subtract":
  1468. mat.blending = THREE.SubtractiveBlending;
  1469. break;
  1470. case "multiply":
  1471. mat.blending = THREE.MultiplyBlending;
  1472. break;
  1473. case "screen":
  1474. mat.blending = THREE.CustomBlending;
  1475. mat.blendSrc = THREE.OneFactor;
  1476. mat.blendDst = THREE.OneMinusSrcColorFactor;
  1477. mat.blendEquation = THREE.AddEquation;
  1478. break;
  1479. }
  1480. mat.transparent = true;
  1481. };
  1482. THREE.SEA3D.prototype.readMaterial = function ( sea ) {
  1483. var mat = this.createMaterial( sea );
  1484. mat.name = sea.name;
  1485. mat.premultipliedAlpha = this.config.forcePremultipliedAlpha;
  1486. mat.side = sea.bothSides ? THREE.DoubleSide : THREE.FrontSide;
  1487. this.setBlending( mat, sea.blendMode );
  1488. for ( var i = 0; i < sea.technique.length; i ++ ) {
  1489. var tech = sea.technique[ i ];
  1490. if ( this.materialTechnique[ tech.kind ] ) {
  1491. this.materialTechnique[ tech.kind ].call( this, mat, tech, sea );
  1492. }
  1493. }
  1494. if ( this.materialTechnique.onComplete ) {
  1495. this.materialTechnique.onComplete.call( this, mat, sea );
  1496. }
  1497. this.domain.materials = this.materials = this.materials || [];
  1498. this.materials.push( this.objects[ "mat/" + sea.name ] = sea.tag = mat );
  1499. };
  1500. //
  1501. // Point Light
  1502. //
  1503. THREE.SEA3D.prototype.readPointLight = function ( sea ) {
  1504. var light = new THREE.SEA3D.PointLight( sea.color, sea.multiplier * this.config.multiplier );
  1505. light.name = sea.name;
  1506. if ( sea.attenuation ) {
  1507. light.distance = sea.attenuation.end;
  1508. }
  1509. if ( sea.shadow ) this.setShadowMap( light );
  1510. this.domain.lights = this.lights = this.lights || [];
  1511. this.lights.push( this.objects[ "lht/" + sea.name ] = sea.tag = light );
  1512. this.addSceneObject( sea );
  1513. this.updateTransform( light, sea );
  1514. this.applyDefaultAnimation( sea, THREE.SEA3D.LightAnimator );
  1515. this.updateScene();
  1516. };
  1517. //
  1518. // Hemisphere Light
  1519. //
  1520. THREE.SEA3D.prototype.readHemisphereLight = function ( sea ) {
  1521. var light = new THREE.HemisphereLight( sea.color, sea.secondColor, sea.multiplier * this.config.multiplier );
  1522. light.position.set( 0, 500, 0 );
  1523. light.name = sea.name;
  1524. this.domain.lights = this.lights = this.lights || [];
  1525. this.lights.push( this.objects[ "lht/" + sea.name ] = sea.tag = light );
  1526. this.addSceneObject( sea );
  1527. this.applyDefaultAnimation( sea, THREE.SEA3D.LightAnimator );
  1528. this.updateScene();
  1529. };
  1530. //
  1531. // Ambient Light
  1532. //
  1533. THREE.SEA3D.prototype.readAmbientLight = function ( sea ) {
  1534. var light = new THREE.AmbientLight( sea.color, sea.multiplier * this.config.multiplier );
  1535. light.name = sea.name;
  1536. this.domain.lights = this.lights = this.lights || [];
  1537. this.lights.push( this.objects[ "lht/" + sea.name ] = sea.tag = light );
  1538. this.addSceneObject( sea );
  1539. this.applyDefaultAnimation( sea, THREE.SEA3D.LightAnimator );
  1540. this.updateScene();
  1541. };
  1542. //
  1543. // Directional Light
  1544. //
  1545. THREE.SEA3D.prototype.readDirectionalLight = function ( sea ) {
  1546. var light = new THREE.DirectionalLight( sea.color, sea.multiplier * this.config.multiplier );
  1547. light.name = sea.name;
  1548. if ( sea.shadow ) {
  1549. this.setShadowMap( light );
  1550. }
  1551. this.domain.lights = this.lights = this.lights || [];
  1552. this.lights.push( this.objects[ "lht/" + sea.name ] = sea.tag = light );
  1553. this.addSceneObject( sea );
  1554. this.updateTransform( light, sea );
  1555. this.applyDefaultAnimation( sea, THREE.SEA3D.LightAnimator );
  1556. this.updateScene();
  1557. };
  1558. //
  1559. // Camera
  1560. //
  1561. THREE.SEA3D.prototype.readCamera = function ( sea ) {
  1562. var camera = new THREE.SEA3D.Camera( sea.fov );
  1563. camera.name = sea.name;
  1564. this.domain.cameras = this.cameras = this.cameras || [];
  1565. this.cameras.push( this.objects[ "cam/" + sea.name ] = sea.tag = camera );
  1566. this.addSceneObject( sea );
  1567. this.updateTransform( camera, sea );
  1568. this.applyDefaultAnimation( sea, THREE.SEA3D.CameraAnimator );
  1569. };
  1570. //
  1571. // Orthographic Camera
  1572. //
  1573. THREE.SEA3D.prototype.readOrthographicCamera = function ( sea ) {
  1574. var aspect, width, height;
  1575. var stageWidth = this.config.stageWidth !== undefined ? this.config.stageWidth : ( window ? window.innerWidth : 1024 );
  1576. var stageHeight = this.config.stageHeight !== undefined ? this.config.stageHeight : ( window ? window.innerHeight : 1024 );
  1577. if ( stageWidth > stageHeight ) {
  1578. aspect = stageWidth / stageHeight;
  1579. width = sea.height * aspect;
  1580. height = sea.height;
  1581. } else {
  1582. aspect = stageHeight / stageWidth;
  1583. width = sea.height;
  1584. height = sea.height * aspect;
  1585. }
  1586. var camera = new THREE.SEA3D.OrthographicCamera( - width, width, height, - height );
  1587. camera.name = sea.name;
  1588. this.domain.cameras = this.cameras = this.cameras || [];
  1589. this.cameras.push( this.objects[ "cam/" + sea.name ] = sea.tag = camera );
  1590. this.addSceneObject( sea );
  1591. this.updateTransform( camera, sea );
  1592. this.applyDefaultAnimation( sea, THREE.SEA3D.CameraAnimator );
  1593. };
  1594. //
  1595. // Skeleton
  1596. //
  1597. THREE.SEA3D.prototype.readSkeletonLocal = function ( sea ) {
  1598. var bones = [];
  1599. for ( var i = 0; i < sea.joint.length; i ++ ) {
  1600. var bone = sea.joint[ i ];
  1601. bones[ i ] = {
  1602. name: bone.name,
  1603. pos: [ bone.x, bone.y, bone.z ],
  1604. rotq: [ bone.qx, bone.qy, bone.qz, bone.qw ],
  1605. parent: bone.parentIndex
  1606. };
  1607. }
  1608. sea.tag = bones;
  1609. };
  1610. //
  1611. // Joint Object
  1612. //
  1613. THREE.SEA3D.prototype.readJointObject = function ( sea ) {
  1614. var mesh = sea.target.tag,
  1615. bone = mesh.skeleton.bones[ sea.joint ];
  1616. this.domain.joints = this.joints = this.joints || [];
  1617. this.joints.push( this.objects[ "jnt/" + sea.name ] = sea.tag = bone );
  1618. };
  1619. //
  1620. // Morpher
  1621. //
  1622. THREE.SEA3D.prototype.readMorpher = function ( sea ) {
  1623. var attribs = { position: [] }, targets = [];
  1624. for ( var i = 0; i < sea.node.length; i ++ ) {
  1625. var node = sea.node[ i ];
  1626. attribs.position[ i ] = new THREE.Float32BufferAttribute( node.vertex, 3 );
  1627. if ( node.normal ) {
  1628. attribs.normal = attribs.normal || [];
  1629. attribs.normal[ i ] = new THREE.Float32BufferAttribute( node.normal, 3 );
  1630. }
  1631. targets[ i ] = { name: node.name };
  1632. }
  1633. sea.tag = {
  1634. attribs: attribs,
  1635. targets: targets
  1636. };
  1637. };
  1638. //
  1639. // Skeleton Animation
  1640. //
  1641. THREE.SEA3D.prototype.getSkeletonAnimation = function ( sea, skl ) {
  1642. if ( sea.tag ) return sea.tag;
  1643. var animations = [], delta = ( 1000 / sea.frameRate ) / 1000;
  1644. for ( var i = 0; i < sea.sequence.length; i ++ ) {
  1645. var seq = sea.sequence[ i ];
  1646. var start = seq.start;
  1647. var end = start + seq.count;
  1648. var animation = {
  1649. name: seq.name,
  1650. fps: sea.frameRate,
  1651. length: delta * seq.count,
  1652. hierarchy: []
  1653. };
  1654. var numJoints = sea.numJoints,
  1655. raw = sea.raw;
  1656. for ( var j = 0; j < numJoints; j ++ ) {
  1657. var bone = skl.joint[ j ],
  1658. node = { parent: bone.parentIndex, keys: [] },
  1659. keys = node.keys,
  1660. time = 0;
  1661. for ( var frame = start; frame < end; frame ++ ) {
  1662. var idx = ( frame * numJoints * 7 ) + ( j * 7 );
  1663. keys.push( {
  1664. time: time,
  1665. pos: [ raw[ idx ], raw[ idx + 1 ], raw[ idx + 2 ] ],
  1666. rot: [ raw[ idx + 3 ], raw[ idx + 4 ], raw[ idx + 5 ], raw[ idx + 6 ] ],
  1667. scl: [ 1, 1, 1 ]
  1668. } );
  1669. time += delta;
  1670. }
  1671. animation.hierarchy[ j ] = node;
  1672. }
  1673. var anm = THREE.AnimationClip.parseAnimation( animation, skl.tag );
  1674. anm.loop = seq.repeat;
  1675. anm.timeScale = 1;
  1676. animations.push( anm );
  1677. }
  1678. return sea.tag = animations;
  1679. };
  1680. //
  1681. // Vertex Animation
  1682. //
  1683. THREE.SEA3D.prototype.readVertexAnimation = function ( sea ) {
  1684. var attribs = { position: [] }, targets = [], animations = [], i, j, l;
  1685. for ( i = 0, l = sea.frame.length; i < l; i ++ ) {
  1686. var frame = sea.frame[ i ];
  1687. attribs.position[ i ] = new THREE.Float32BufferAttribute( frame.vertex, 3 );
  1688. if ( frame.normal ) {
  1689. attribs.normal = attribs.normal || [];
  1690. attribs.normal[ i ] = new THREE.Float32BufferAttribute( frame.normal, 3 );
  1691. }
  1692. targets[ i ] = { name: i };
  1693. }
  1694. for ( i = 0; i < sea.sequence.length; i ++ ) {
  1695. var seq = sea.sequence[ i ];
  1696. var seqTargets = [];
  1697. for ( j = 0; j < seq.count; j ++ ) {
  1698. seqTargets[ j ] = targets[ seq.start + j ];
  1699. }
  1700. var anm = THREE.AnimationClip.CreateFromMorphTargetSequence( seq.name, seqTargets, sea.frameRate );
  1701. anm.loop = seq.repeat;
  1702. anm.timeScale = 1;
  1703. animations.push( anm );
  1704. }
  1705. sea.tag = {
  1706. attribs: attribs,
  1707. targets: targets,
  1708. animations: animations
  1709. };
  1710. };
  1711. //
  1712. // Actions
  1713. //
  1714. THREE.SEA3D.prototype.applyEnvironment = function ( envMap ) {
  1715. for ( var j = 0, l = this.materials.length; j < l; ++ j ) {
  1716. var mat = this.materials[ j ];
  1717. if ( mat instanceof THREE.MeshStandardMaterial ) {
  1718. if ( mat.envMap ) continue;
  1719. mat.envMap = envMap;
  1720. mat.envMap.mapping = THREE.CubeReflectionMapping;
  1721. mat.needsUpdate = true;
  1722. }
  1723. }
  1724. };
  1725. THREE.SEA3D.prototype.readActions = function ( sea ) {
  1726. for ( var i = 0; i < sea.actions.length; i ++ ) {
  1727. var act = sea.actions[ i ];
  1728. switch ( act.kind ) {
  1729. case SEA3D.Actions.ATTRIBUTES:
  1730. this.attribs = this.domain.attribs = act.attributes.tag;
  1731. break;
  1732. case SEA3D.Actions.SCRIPTS:
  1733. this.domain.scripts = this.getJSMList( this.domain, act.scripts );
  1734. if ( this.config.runScripts ) this.domain.runJSMList( this.domain );
  1735. break;
  1736. case SEA3D.Actions.ENVIRONMENT_COLOR:
  1737. this.domain.background = this.background = this.background || {};
  1738. this.background.color = new THREE.Color( act.color );
  1739. break;
  1740. case SEA3D.Actions.ENVIRONMENT:
  1741. this.domain.background = this.background = this.background || {};
  1742. this.background.texture = act.texture.tag;
  1743. if ( this.config.useEnvironment && this.materials != undefined ) {
  1744. this.applyEnvironment( act.texture.tag );
  1745. }
  1746. break;
  1747. }
  1748. }
  1749. };
  1750. //
  1751. // Events
  1752. //
  1753. THREE.SEA3D.Event = {
  1754. PROGRESS: "sea3d_progress",
  1755. LOAD_PROGRESS: "sea3d_load",
  1756. DOWNLOAD_PROGRESS: "sea3d_download",
  1757. COMPLETE: "sea3d_complete",
  1758. OBJECT_COMPLETE: "sea3d_object",
  1759. PARSE_PROGRESS: "parse_progress",
  1760. PARSE_COMPLETE: "parse_complete",
  1761. ERROR: "sea3d_error"
  1762. };
  1763. THREE.SEA3D.prototype.onProgress = function ( e ) {
  1764. e.status = e.type;
  1765. e.progress = e.loaded / e.total;
  1766. e.type = THREE.SEA3D.Event.PROGRESS;
  1767. this.dispatchEvent( e );
  1768. };
  1769. THREE.SEA3D.prototype.onLoadProgress = function ( e ) {
  1770. e.type = THREE.SEA3D.Event.LOAD_PROGRESS;
  1771. this.dispatchEvent( e );
  1772. this.onProgress( e );
  1773. };
  1774. THREE.SEA3D.prototype.onDownloadProgress = function ( e ) {
  1775. e.type = THREE.SEA3D.Event.DOWNLOAD_PROGRESS;
  1776. this.dispatchEvent( e );
  1777. this.onProgress( e );
  1778. };
  1779. THREE.SEA3D.prototype.onComplete = function ( e ) {
  1780. e.type = THREE.SEA3D.Event.COMPLETE;
  1781. this.dispatchEvent( e );
  1782. };
  1783. THREE.SEA3D.prototype.onCompleteObject = function ( e ) {
  1784. e.type = THREE.SEA3D.Event.OBJECT_COMPLETE;
  1785. this.dispatchEvent( e );
  1786. };
  1787. THREE.SEA3D.prototype.onParseProgress = function ( e ) {
  1788. e.type = THREE.SEA3D.Event.PARSE_PROGRESS;
  1789. this.dispatchEvent( e );
  1790. };
  1791. THREE.SEA3D.prototype.onParseComplete = function ( e ) {
  1792. e.type = THREE.SEA3D.Event.PARSE_COMPLETE;
  1793. this.dispatchEvent( e );
  1794. };
  1795. THREE.SEA3D.prototype.onError = function ( e ) {
  1796. e.type = THREE.SEA3D.Event.ERROR;
  1797. this.dispatchEvent( e );
  1798. };
  1799. //
  1800. // Loader
  1801. //
  1802. THREE.SEA3D.prototype.createDomain = function () {
  1803. return this.domain = new THREE.SEA3D.Domain(
  1804. this.config.id,
  1805. this.objects = {},
  1806. this.config.container
  1807. );
  1808. };
  1809. THREE.SEA3D.prototype.clone = function ( config, onParseComplete, onParseProgress ) {
  1810. if ( ! this.file.isDone() ) throw new Error( "Previous parse is not completed." );
  1811. this.config.container = config && config.container !== undefined ? config.container : new THREE.Object3D();
  1812. if ( config ) this.loadConfig( config );
  1813. var timeLimit = this.config.timeLimit;
  1814. this.config.timeLimit = config && config.timeLimit !== undefined ? config.timeLimit : Infinity;
  1815. this.parse( onParseComplete, onParseProgress );
  1816. this.config.timeLimit = timeLimit;
  1817. return this.domain;
  1818. };
  1819. THREE.SEA3D.prototype.loadConfig = function ( config ) {
  1820. for ( var name in config ) {
  1821. this.config[ name ] = config[ name ];
  1822. }
  1823. };
  1824. THREE.SEA3D.prototype.parse = function ( onParseComplete, onParseProgress ) {
  1825. delete this.cameras;
  1826. delete this.containers;
  1827. delete this.lights;
  1828. delete this.joints;
  1829. delete this.meshes;
  1830. delete this.materials;
  1831. delete this.animationSets;
  1832. delete this.sprites;
  1833. delete this.sounds3d;
  1834. delete this.cubeRenderers;
  1835. delete this.sounds;
  1836. delete this.glsl;
  1837. delete this.dummy;
  1838. delete this.background;
  1839. delete this.domain;
  1840. this.createDomain();
  1841. this.setTypeRead();
  1842. this.file.onParseComplete = ( function ( e ) {
  1843. if ( this.config.manager ) this.config.manager.add( this.domain );
  1844. ( onParseComplete || this.onParseComplete ).call( this, e );
  1845. } ).bind( this );
  1846. this.file.onParseProgress = onParseProgress || this.onParseProgress;
  1847. // EXTENSIONS
  1848. var i = THREE.SEA3D.EXTENSIONS_LOADER.length;
  1849. while ( i -- ) {
  1850. var loader = THREE.SEA3D.EXTENSIONS_LOADER[ i ];
  1851. if ( loader.parse ) loader.parse.call( this );
  1852. }
  1853. this.file.parse();
  1854. return this.domain;
  1855. };
  1856. THREE.SEA3D.prototype.onHead = function ( args ) {
  1857. if ( args.sign != 'TJS' ) {
  1858. throw new Error( "Sign '" + args.sign + "' not supported! Use SEA3D Studio to publish or SEA3DLegacy.js" );
  1859. }
  1860. };
  1861. THREE.SEA3D.EXTENSIONS_LOADER = [];
  1862. THREE.SEA3D.EXTENSIONS_DOMAIN = [];
  1863. THREE.SEA3D.prototype.setTypeRead = function () {
  1864. this.file.typeRead = {};
  1865. this.file.typeRead[ SEA3D.Geometry.prototype.type ] = this.readGeometryBuffer;
  1866. this.file.typeRead[ SEA3D.Mesh.prototype.type ] = this.readMesh;
  1867. this.file.typeRead[ SEA3D.Sprite.prototype.type ] = this.readSprite;
  1868. this.file.typeRead[ SEA3D.Container3D.prototype.type ] = this.readContainer3D;
  1869. this.file.typeRead[ SEA3D.Line.prototype.type ] = this.readLine;
  1870. this.file.typeRead[ SEA3D.Material.prototype.type ] = this.readMaterial;
  1871. this.file.typeRead[ SEA3D.Camera.prototype.type ] = this.readCamera;
  1872. this.file.typeRead[ SEA3D.OrthographicCamera.prototype.type ] = this.readOrthographicCamera;
  1873. this.file.typeRead[ SEA3D.SkeletonLocal.prototype.type ] = this.readSkeletonLocal;
  1874. this.file.typeRead[ SEA3D.JointObject.prototype.type ] = this.readJointObject;
  1875. this.file.typeRead[ SEA3D.CubeMap.prototype.type ] = this.readCubeMap;
  1876. this.file.typeRead[ SEA3D.CubeRender.prototype.type ] = this.readCubeRender;
  1877. this.file.typeRead[ SEA3D.Animation.prototype.type ] = this.readAnimation;
  1878. this.file.typeRead[ SEA3D.SoundPoint.prototype.type ] = this.readSoundPoint;
  1879. this.file.typeRead[ SEA3D.TextureURL.prototype.type ] = this.readTextureURL;
  1880. this.file.typeRead[ SEA3D.CubeMapURL.prototype.type ] = this.readCubeMapURL;
  1881. this.file.typeRead[ SEA3D.Morph.prototype.type ] = this.readMorpher;
  1882. this.file.typeRead[ SEA3D.VertexAnimation.prototype.type ] = this.readVertexAnimation;
  1883. this.file.typeRead[ SEA3D.Actions.prototype.type ] = this.readActions;
  1884. if ( this.config.dummys ) {
  1885. this.file.typeRead[ SEA3D.Dummy.prototype.type ] = this.readDummy;
  1886. }
  1887. if ( this.config.scripts ) {
  1888. this.file.typeRead[ SEA3D.ScriptURL.prototype.type ] = this.readScriptURL;
  1889. this.file.typeRead[ SEA3D.JavaScriptMethod.prototype.type ] = this.readJavaScriptMethod;
  1890. }
  1891. if ( this.config.lights ) {
  1892. this.file.typeRead[ SEA3D.PointLight.prototype.type ] = this.readPointLight;
  1893. this.file.typeRead[ SEA3D.DirectionalLight.prototype.type ] = this.readDirectionalLight;
  1894. this.file.typeRead[ SEA3D.HemisphereLight.prototype.type ] = this.readHemisphereLight;
  1895. this.file.typeRead[ SEA3D.AmbientLight.prototype.type ] = this.readAmbientLight;
  1896. }
  1897. // UNIVERSAL
  1898. this.file.typeRead[ SEA3D.JPEG.prototype.type ] =
  1899. this.file.typeRead[ SEA3D.JPEG_XR.prototype.type ] =
  1900. this.file.typeRead[ SEA3D.PNG.prototype.type ] =
  1901. this.file.typeRead[ SEA3D.GIF.prototype.type ] = this.readTexture;
  1902. this.file.typeRead[ SEA3D.MP3.prototype.type ] = this.readSound;
  1903. this.file.typeRead[ SEA3D.GLSL.prototype.type ] = this.readGLSL;
  1904. // EXTENSIONS
  1905. var i = THREE.SEA3D.EXTENSIONS_LOADER.length;
  1906. while ( i -- ) {
  1907. var loader = THREE.SEA3D.EXTENSIONS_LOADER[ i ];
  1908. if ( loader.setTypeRead ) loader.setTypeRead.call( this );
  1909. }
  1910. };
  1911. THREE.SEA3D.prototype.load = function ( data ) {
  1912. this.file = new SEA3D.File();
  1913. this.file.scope = this;
  1914. this.file.config = this.config;
  1915. this.file.onProgress = this.onLoadProgress.bind( this );
  1916. this.file.onCompleteObject = this.onCompleteObject.bind( this );
  1917. this.file.onDownloadProgress = this.onDownloadProgress.bind( this );
  1918. this.file.onParseProgress = this.onParseProgress.bind( this );
  1919. this.file.onParseComplete = this.onParseComplete.bind( this );
  1920. this.file.onError = this.onError.bind( this );
  1921. this.file.onHead = this.onHead.bind( this );
  1922. this.file.onComplete = ( function ( e ) {
  1923. if ( this.config.manager ) this.config.manager.add( this.domain );
  1924. this.onComplete.call( this, e );
  1925. } ).bind( this );
  1926. // SEA3D
  1927. this.createDomain();
  1928. this.setTypeRead();
  1929. if ( data === undefined ) return;
  1930. if ( typeof data == "string" ) this.file.load( data );
  1931. else this.file.read( data );
  1932. };