SEA3DLoader.js 65 KB

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