SEA3DLoader.js 66 KB

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