SEA3DLoader.js 65 KB

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