SEA3DSDK.js 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355
  1. /**
  2. * SEA3DSDK
  3. * @author Sunag / http://www.sunag.com.br/
  4. */
  5. 'use strict';
  6. var SEA3DSDK = { VERSION: 18110 };
  7. SEA3DSDK.getVersion = function () {
  8. // Max = 16777215 - VV.S.S.BB | V = Version | S = Subversion | B = Buildversion
  9. var v = SEA3DSDK.VERSION.toString(), l = v.length;
  10. return v.substring( 0, l - 4 ) + "." + v.substring( l - 4, l - 3 ) + "." + v.substring( l - 3, l - 2 ) + "." + parseFloat( v.substring( l - 2, l ) ).toString();
  11. };
  12. console.log( 'SEA3D ' + SEA3DSDK.getVersion() );
  13. //
  14. // STREAM : STANDARD DATA-IO ( LITTLE-ENDIAN )
  15. //
  16. SEA3DSDK.Stream = function ( buffer ) {
  17. this.position = 0;
  18. this.buffer = buffer || new ArrayBuffer();
  19. };
  20. SEA3DSDK.Stream.NONE = 0;
  21. // 1D = 0 at 31
  22. SEA3DSDK.Stream.BOOLEAN = 1;
  23. SEA3DSDK.Stream.BYTE = 2;
  24. SEA3DSDK.Stream.UBYTE = 3;
  25. SEA3DSDK.Stream.SHORT = 4;
  26. SEA3DSDK.Stream.USHORT = 5;
  27. SEA3DSDK.Stream.INT24 = 6;
  28. SEA3DSDK.Stream.UINT24 = 7;
  29. SEA3DSDK.Stream.INT = 8;
  30. SEA3DSDK.Stream.UINT = 9;
  31. SEA3DSDK.Stream.FLOAT = 10;
  32. SEA3DSDK.Stream.DOUBLE = 11;
  33. SEA3DSDK.Stream.DECIMAL = 12;
  34. // 2D = 32 at 63
  35. // 3D = 64 at 95
  36. SEA3DSDK.Stream.VECTOR3D = 74;
  37. // 4D = 96 at 127
  38. SEA3DSDK.Stream.VECTOR4D = 106;
  39. // Undefined Size = 128 at 255
  40. SEA3DSDK.Stream.STRING_TINY = 128;
  41. SEA3DSDK.Stream.STRING_SHORT = 129;
  42. SEA3DSDK.Stream.STRING_LONG = 130;
  43. SEA3DSDK.Stream.ASSET = 200;
  44. SEA3DSDK.Stream.GROUP = 255;
  45. SEA3DSDK.Stream.BLEND_MODE = [
  46. "normal", "add", "subtract", "multiply", "dividing", "mix", "alpha", "screen", "darken",
  47. "overlay", "colorburn", "linearburn", "lighten", "colordodge", "lineardodge",
  48. "softlight", "hardlight", "pinlight", "spotlight", "spotlightblend", "hardmix",
  49. "average", "difference", "exclusion", "hue", "saturation", "color", "value",
  50. "linearlight", "grainextract", "reflect", "glow", "darkercolor", "lightercolor", "phoenix", "negation"
  51. ];
  52. SEA3DSDK.Stream.INTERPOLATION_TABLE = [
  53. "normal", "linear",
  54. "sine.in", "sine.out", "sine.inout",
  55. "cubic.in", "cubic.out", "cubic.inout",
  56. "quint.in", "quint.out", "quint.inout",
  57. "circ.in", "circ.out", "circ.inout",
  58. "back.in", "back.out", "back.inout",
  59. "quad.in", "quad.out", "quad.inout",
  60. "quart.in", "quart.out", "quart.inout",
  61. "expo.in", "expo.out", "expo.inout",
  62. "elastic.in", "elastic.out", "elastic.inout",
  63. "bounce.in", "bounce.out", "bounce.inout"
  64. ];
  65. SEA3DSDK.Stream.sizeOf = function ( kind ) {
  66. if ( kind === 0 ) return 0;
  67. else if ( kind >= 1 && kind <= 31 ) return 1;
  68. else if ( kind >= 32 && kind <= 63 ) return 2;
  69. else if ( kind >= 64 && kind <= 95 ) return 3;
  70. else if ( kind >= 96 && kind <= 125 ) return 4;
  71. return - 1;
  72. };
  73. SEA3DSDK.Stream.prototype = {
  74. constructor: SEA3DSDK.Stream,
  75. set buffer( val ) {
  76. this.buf = val;
  77. this.data = new DataView( val );
  78. },
  79. get buffer() {
  80. return this.buf;
  81. },
  82. get bytesAvailable() {
  83. return this.length - this.position;
  84. },
  85. get length() {
  86. return this.buf.byteLength;
  87. }
  88. };
  89. SEA3DSDK.Stream.prototype.getByte = function ( pos ) {
  90. return this.data.getInt8( pos );
  91. };
  92. SEA3DSDK.Stream.prototype.readBytes = function ( len ) {
  93. var buf = this.buf.slice( this.position, this.position + len );
  94. this.position += len;
  95. return buf;
  96. };
  97. SEA3DSDK.Stream.prototype.readByte = function () {
  98. return this.data.getInt8( this.position ++ );
  99. };
  100. SEA3DSDK.Stream.prototype.readUByte = function () {
  101. return this.data.getUint8( this.position ++ );
  102. };
  103. SEA3DSDK.Stream.prototype.readBool = function () {
  104. return this.data.getInt8( this.position ++ ) != 0;
  105. };
  106. SEA3DSDK.Stream.prototype.readShort = function () {
  107. var v = this.data.getInt16( this.position, true );
  108. this.position += 2;
  109. return v;
  110. };
  111. SEA3DSDK.Stream.prototype.readUShort = function () {
  112. var v = this.data.getUint16( this.position, true );
  113. this.position += 2;
  114. return v;
  115. };
  116. SEA3DSDK.Stream.prototype.readUInt24 = function () {
  117. var v = this.data.getUint32( this.position, true ) & 0xFFFFFF;
  118. this.position += 3;
  119. return v;
  120. };
  121. SEA3DSDK.Stream.prototype.readUInt24F = function () {
  122. return this.readUShort() | ( this.readUByte() << 16 );
  123. };
  124. SEA3DSDK.Stream.prototype.readInt = function () {
  125. var v = this.data.getInt32( this.position, true );
  126. this.position += 4;
  127. return v;
  128. };
  129. SEA3DSDK.Stream.prototype.readUInt = function () {
  130. var v = this.data.getUint32( this.position, true );
  131. this.position += 4;
  132. return v;
  133. };
  134. SEA3DSDK.Stream.prototype.readFloat = function () {
  135. var v = this.data.getFloat32( this.position, true );
  136. this.position += 4;
  137. return v;
  138. };
  139. SEA3DSDK.Stream.prototype.readUInteger = function () {
  140. var v = this.readUByte(),
  141. r = v & 0x7F;
  142. if ( ( v & 0x80 ) != 0 ) {
  143. v = this.readUByte();
  144. r |= ( v & 0x7F ) << 7;
  145. if ( ( v & 0x80 ) != 0 ) {
  146. v = this.readUByte();
  147. r |= ( v & 0x7F ) << 13;
  148. }
  149. }
  150. return r;
  151. };
  152. SEA3DSDK.Stream.prototype.readVector2 = function () {
  153. return { x: this.readFloat(), y: this.readFloat() };
  154. };
  155. SEA3DSDK.Stream.prototype.readVector3 = function () {
  156. return { x: this.readFloat(), y: this.readFloat(), z: this.readFloat() };
  157. };
  158. SEA3DSDK.Stream.prototype.readVector4 = function () {
  159. return { x: this.readFloat(), y: this.readFloat(), z: this.readFloat(), w: this.readFloat() };
  160. };
  161. SEA3DSDK.Stream.prototype.readMatrix = function () {
  162. var mtx = new Float32Array( 16 );
  163. mtx[ 0 ] = this.readFloat();
  164. mtx[ 1 ] = this.readFloat();
  165. mtx[ 2 ] = this.readFloat();
  166. mtx[ 3 ] = 0.0;
  167. mtx[ 4 ] = this.readFloat();
  168. mtx[ 5 ] = this.readFloat();
  169. mtx[ 6 ] = this.readFloat();
  170. mtx[ 7 ] = 0.0;
  171. mtx[ 8 ] = this.readFloat();
  172. mtx[ 9 ] = this.readFloat();
  173. mtx[ 10 ] = this.readFloat();
  174. mtx[ 11 ] = 0.0;
  175. mtx[ 12 ] = this.readFloat();
  176. mtx[ 13 ] = this.readFloat();
  177. mtx[ 14 ] = this.readFloat();
  178. mtx[ 15 ] = 1.0;
  179. return mtx;
  180. };
  181. SEA3DSDK.Stream.prototype.decodeText = function ( array ) {
  182. if ( typeof TextDecoder !== 'undefined' ) {
  183. return new TextDecoder().decode( array );
  184. }
  185. // Avoid the String.fromCharCode.apply(null, array) shortcut, which
  186. // throws a "maximum call stack size exceeded" error for large arrays.
  187. var s = '';
  188. for ( var i = 0, il = array.length; i < il; i ++ ) {
  189. // Implicitly assumes little-endian.
  190. s += String.fromCharCode( array[ i ] );
  191. }
  192. // Merges multi-byte utf-8 characters.
  193. return decodeURIComponent( escape( s ) );
  194. };
  195. SEA3DSDK.Stream.prototype.readUTF8 = function ( len ) {
  196. var buffer = this.readBytes( len );
  197. return this.decodeText( new Uint8Array( buffer ) );
  198. };
  199. SEA3DSDK.Stream.prototype.readExt = function () {
  200. return this.readUTF8( 4 ).replace( /\0/g, "" );
  201. };
  202. SEA3DSDK.Stream.prototype.readUTF8Tiny = function () {
  203. return this.readUTF8( this.readUByte() );
  204. };
  205. SEA3DSDK.Stream.prototype.readUTF8Short = function () {
  206. return this.readUTF8( this.readUShort() );
  207. };
  208. SEA3DSDK.Stream.prototype.readUTF8Long = function () {
  209. return this.readUTF8( this.readUInt() );
  210. };
  211. SEA3DSDK.Stream.prototype.readUByteArray = function ( length ) {
  212. var v = new Uint8Array( length );
  213. SEA3DSDK.Stream.memcpy(
  214. v.buffer,
  215. 0,
  216. this.buffer,
  217. this.position,
  218. length
  219. );
  220. this.position += length;
  221. return v;
  222. };
  223. SEA3DSDK.Stream.prototype.readUShortArray = function ( length ) {
  224. var v = new Uint16Array( length ),
  225. len = length * 2;
  226. SEA3DSDK.Stream.memcpy(
  227. v.buffer,
  228. 0,
  229. this.buffer,
  230. this.position,
  231. len
  232. );
  233. this.position += len;
  234. return v;
  235. };
  236. SEA3DSDK.Stream.prototype.readUInt24Array = function ( length ) {
  237. var v = new Uint32Array( length );
  238. for ( var i = 0; i < length; i ++ ) {
  239. v[ i ] = this.readUInt24();
  240. }
  241. return v;
  242. };
  243. SEA3DSDK.Stream.prototype.readUIntArray = function ( length ) {
  244. var v = new Uint32Array( length ),
  245. len = length * 4;
  246. SEA3DSDK.Stream.memcpy(
  247. v.buffer,
  248. 0,
  249. this.buffer,
  250. this.position,
  251. len
  252. );
  253. this.position += len;
  254. return v;
  255. };
  256. SEA3DSDK.Stream.prototype.readFloatArray = function ( length ) {
  257. var v = new Float32Array( length ),
  258. len = length * 4;
  259. SEA3DSDK.Stream.memcpy(
  260. v.buffer,
  261. 0,
  262. this.buffer,
  263. this.position,
  264. len
  265. );
  266. this.position += len;
  267. return v;
  268. };
  269. SEA3DSDK.Stream.prototype.readBlendMode = function () {
  270. return SEA3DSDK.Stream.BLEND_MODE[ this.readUByte() ];
  271. };
  272. SEA3DSDK.Stream.prototype.readInterpolation = function () {
  273. return SEA3DSDK.Stream.INTERPOLATION_TABLE[ this.readUByte() ];
  274. };
  275. SEA3DSDK.Stream.prototype.readTags = function ( callback ) {
  276. var numTag = this.readUByte();
  277. for ( var i = 0; i < numTag; ++ i ) {
  278. var kind = this.readUShort();
  279. var size = this.readUInt();
  280. var pos = this.position;
  281. callback( kind, this, size );
  282. this.position = pos += size;
  283. }
  284. };
  285. SEA3DSDK.Stream.prototype.readProperties = function ( sea3d ) {
  286. var count = this.readUByte(),
  287. props = {}, types = {};
  288. props.__type = types;
  289. for ( var i = 0; i < count; i ++ ) {
  290. var name = this.readUTF8Tiny(),
  291. type = this.readUByte();
  292. types[ name ] = type;
  293. props[ name ] = type === SEA3DSDK.Stream.GROUP ? this.readProperties( sea3d ) : this.readToken( type, sea3d );
  294. }
  295. return props;
  296. };
  297. SEA3DSDK.Stream.prototype.readAnimationList = function ( sea3d ) {
  298. var list = [],
  299. count = this.readUByte();
  300. var i = 0;
  301. while ( i < count ) {
  302. var attrib = this.readUByte(),
  303. anm = {};
  304. anm.relative = ( attrib & 1 ) != 0;
  305. if ( attrib & 2 ) anm.timeScale = this.readFloat();
  306. anm.tag = sea3d.getObject( this.readUInt() );
  307. list[ i ++ ] = anm;
  308. }
  309. return list;
  310. };
  311. SEA3DSDK.Stream.prototype.readScriptList = function ( sea3d ) {
  312. var list = [],
  313. count = this.readUByte();
  314. var i = 0;
  315. while ( i < count ) {
  316. var attrib = this.readUByte(),
  317. script = {};
  318. script.priority = ( attrib & 1 ) | ( attrib & 2 );
  319. if ( attrib & 4 ) {
  320. var numParams = this.readUByte();
  321. script.params = {};
  322. for ( var j = 0; j < numParams; j ++ ) {
  323. var name = this.readUTF8Tiny();
  324. script.params[ name ] = this.readObject( sea3d );
  325. }
  326. }
  327. if ( attrib & 8 ) {
  328. script.method = this.readUTF8Tiny();
  329. }
  330. script.tag = sea3d.getObject( this.readUInt() );
  331. list[ i ++ ] = script;
  332. }
  333. return list;
  334. };
  335. SEA3DSDK.Stream.prototype.readObject = function ( sea3d ) {
  336. return this.readToken( this.readUByte(), sea3d );
  337. };
  338. SEA3DSDK.Stream.prototype.readToken = function ( type, sea3d ) {
  339. switch ( type ) {
  340. // 1D
  341. case SEA3DSDK.Stream.BOOLEAN:
  342. return this.readBool();
  343. break;
  344. case SEA3DSDK.Stream.UBYTE:
  345. return this.readUByte();
  346. break;
  347. case SEA3DSDK.Stream.USHORT:
  348. return this.readUShort();
  349. break;
  350. case SEA3DSDK.Stream.UINT24:
  351. return this.readUInt24();
  352. break;
  353. case SEA3DSDK.Stream.INT:
  354. return this.readInt();
  355. break;
  356. case SEA3DSDK.Stream.UINT:
  357. return this.readUInt();
  358. break;
  359. case SEA3DSDK.Stream.FLOAT:
  360. return this.readFloat();
  361. break;
  362. // 3D
  363. case SEA3DSDK.Stream.VECTOR3D:
  364. return this.readVector3();
  365. break;
  366. // 4D
  367. case SEA3DSDK.Stream.VECTOR4D:
  368. return this.readVector4();
  369. break;
  370. // Undefined Values
  371. case SEA3DSDK.Stream.STRING_TINY:
  372. return this.readUTF8Tiny();
  373. break;
  374. case SEA3DSDK.Stream.STRING_SHORT:
  375. return this.readUTF8Short();
  376. break;
  377. case SEA3DSDK.Stream.STRING_LONG:
  378. return this.readUTF8Long();
  379. break;
  380. case SEA3DSDK.Stream.ASSET:
  381. var asset = this.readUInt();
  382. return asset > 0 ? sea3d.getObject( asset - 1 ) : null;
  383. break;
  384. default:
  385. console.error( "DataType not found!" );
  386. }
  387. return null;
  388. };
  389. SEA3DSDK.Stream.prototype.readVector = function ( type, length, offset ) {
  390. var size = SEA3DSDK.Stream.sizeOf( type ),
  391. i = offset * size,
  392. count = i + ( length * size );
  393. switch ( type ) {
  394. // 1D
  395. case SEA3DSDK.Stream.BOOLEAN:
  396. return this.readUByteArray( count );
  397. case SEA3DSDK.Stream.UBYTE:
  398. return this.readUByteArray( count );
  399. case SEA3DSDK.Stream.USHORT:
  400. return this.readUShortArray( count );
  401. case SEA3DSDK.Stream.UINT24:
  402. return this.readUInt24Array( count );
  403. case SEA3DSDK.Stream.UINT:
  404. return this.readUIntArray( count );
  405. case SEA3DSDK.Stream.FLOAT:
  406. return this.readFloatArray( count );
  407. // 3D
  408. case SEA3DSDK.Stream.VECTOR3D:
  409. return this.readFloatArray( count );
  410. // 4D
  411. case SEA3DSDK.Stream.VECTOR4D:
  412. return this.readFloatArray( count );
  413. }
  414. };
  415. SEA3DSDK.Stream.prototype.append = function ( data ) {
  416. var buffer = new ArrayBuffer( this.data.byteLength + data.byteLength );
  417. SEA3DSDK.Stream.memcpy( buffer, 0, this.data.buffer, 0, this.data.byteLength );
  418. SEA3DSDK.Stream.memcpy( buffer, this.data.byteLength, data, 0, data.byteLength );
  419. this.buffer = buffer;
  420. };
  421. SEA3DSDK.Stream.prototype.concat = function ( position, length ) {
  422. return new SEA3DSDK.Stream( this.buffer.slice( position, position + length ) );
  423. };
  424. /**
  425. * @author DataStream.js
  426. */
  427. SEA3DSDK.Stream.memcpy = function ( dst, dstOffset, src, srcOffset, byteLength ) {
  428. var dstU8 = new Uint8Array( dst, dstOffset, byteLength );
  429. var srcU8 = new Uint8Array( src, srcOffset, byteLength );
  430. dstU8.set( srcU8 );
  431. };
  432. //
  433. // UByteArray
  434. //
  435. SEA3DSDK.UByteArray = function () {
  436. this.ubytes = [];
  437. this.length = 0;
  438. };
  439. SEA3DSDK.UByteArray.prototype = {
  440. constructor: SEA3DSDK.UByteArray,
  441. add: function ( ubytes ) {
  442. this.ubytes.push( ubytes );
  443. this.length += ubytes.byteLength;
  444. },
  445. toBuffer: function () {
  446. var memcpy = new Uint8Array( this.length );
  447. for ( var i = 0, offset = 0; i < this.ubytes.length; i ++ ) {
  448. memcpy.set( this.ubytes[ i ], offset );
  449. offset += this.ubytes[ i ].byteLength;
  450. }
  451. return memcpy.buffer;
  452. }
  453. };
  454. //
  455. // Math
  456. //
  457. SEA3DSDK.Math = {
  458. RAD_TO_DEG: 180 / Math.PI,
  459. DEG_TO_RAD: Math.PI / 180
  460. };
  461. SEA3DSDK.Math.angle = function ( val ) {
  462. var ang = 180,
  463. inv = val < 0;
  464. val = ( inv ? - val : val ) % 360;
  465. if ( val > ang ) {
  466. val = - ang + ( val - ang );
  467. }
  468. return ( inv ? - val : val );
  469. };
  470. SEA3DSDK.Math.angleDiff = function ( a, b ) {
  471. a *= this.DEG_TO_RAD;
  472. b *= this.DEG_TO_RAD;
  473. return Math.atan2( Math.sin( a - b ), Math.cos( a - b ) ) * this.RAD_TO_DEG;
  474. };
  475. SEA3DSDK.Math.angleArea = function ( angle, target, area ) {
  476. return Math.abs( this.angleDiff( angle, target ) ) <= area;
  477. };
  478. SEA3DSDK.Math.direction = function ( x1, y1, x2, y2 ) {
  479. return Math.atan2( y2 - y1, x2 - x1 );
  480. };
  481. SEA3DSDK.Math.physicalLerp = function ( val, to, deltaTime, duration ) {
  482. var t = deltaTime / duration;
  483. if ( t > 1 ) t = 1;
  484. return val + ( ( to - val ) * t );
  485. };
  486. SEA3DSDK.Math.physicalAngle = function ( val, to, deltaTime, duration ) {
  487. if ( Math.abs( val - to ) > 180 ) {
  488. if ( val > to ) {
  489. to += 360;
  490. } else {
  491. to -= 360;
  492. }
  493. }
  494. var t = deltaTime / duration;
  495. if ( t > 1 ) t = 1;
  496. return this.angle( val + ( ( to - val ) * t ) );
  497. };
  498. SEA3DSDK.Math.zero = function ( value, precision ) {
  499. precision = precision || 1.0E-3;
  500. var pValue = value < 0 ? - value : value;
  501. if ( pValue - precision < 0 ) value = 0;
  502. return value;
  503. };
  504. SEA3DSDK.Math.round = function ( value, precision ) {
  505. precision = Math.pow( 10, precision );
  506. return Math.round( value * precision ) / precision;
  507. };
  508. SEA3DSDK.Math.lerpAngle = function ( val, tar, t ) {
  509. if ( Math.abs( val - tar ) > 180 ) {
  510. if ( val > tar ) {
  511. tar += 360;
  512. } else {
  513. tar -= 360;
  514. }
  515. }
  516. val += ( tar - val ) * t;
  517. return SEA3DSDK.Math.angle( val );
  518. };
  519. SEA3DSDK.Math.lerpColor = function ( val, tar, t ) {
  520. var a0 = val >> 24 & 0xff,
  521. r0 = val >> 16 & 0xff,
  522. g0 = val >> 8 & 0xff,
  523. b0 = val & 0xff;
  524. var a1 = tar >> 24 & 0xff,
  525. r1 = tar >> 16 & 0xff,
  526. g1 = tar >> 8 & 0xff,
  527. b1 = tar & 0xff;
  528. a0 += ( a1 - a0 ) * t;
  529. r0 += ( r1 - r0 ) * t;
  530. g0 += ( g1 - g0 ) * t;
  531. b0 += ( b1 - b0 ) * t;
  532. return a0 << 24 | r0 << 16 | g0 << 8 | b0;
  533. };
  534. SEA3DSDK.Math.lerp = function ( val, tar, t ) {
  535. return val + ( ( tar - val ) * t );
  536. };
  537. //
  538. // Timer
  539. //
  540. SEA3DSDK.Timer = function () {
  541. this.time = this.start = Date.now();
  542. };
  543. SEA3DSDK.Timer.prototype = {
  544. constructor: SEA3DSDK.Timer,
  545. get now() {
  546. return Date.now();
  547. },
  548. get deltaTime() {
  549. return Date.now() - this.time;
  550. },
  551. get elapsedTime() {
  552. return Date.now() - this.start;
  553. },
  554. update: function () {
  555. this.time = Date.now();
  556. }
  557. };
  558. //
  559. // Object
  560. //
  561. SEA3DSDK.Object = function ( name, data, type, sea3d ) {
  562. this.name = name;
  563. this.data = data;
  564. this.type = type;
  565. this.sea3d = sea3d;
  566. };
  567. //
  568. // Geometry Base
  569. //
  570. SEA3DSDK.GeometryBase = function ( name, data, sea3d ) {
  571. this.name = name;
  572. this.data = data;
  573. this.sea3d = sea3d;
  574. this.attrib = data.readUShort();
  575. this.isBig = ( this.attrib & 1 ) != 0;
  576. // variable uint
  577. data.readVInt = this.isBig ? data.readUInt : data.readUShort;
  578. this.numVertex = data.readVInt();
  579. this.length = this.numVertex * 3;
  580. };
  581. //
  582. // Geometry
  583. //
  584. SEA3DSDK.Geometry = function ( name, data, sea3d ) {
  585. SEA3DSDK.GeometryBase.call( this, name, data, sea3d );
  586. var i, j, len;
  587. // NORMAL
  588. if ( this.attrib & 4 ) {
  589. this.normal = data.readFloatArray( this.length );
  590. }
  591. // TANGENT
  592. if ( this.attrib & 8 ) {
  593. this.tangent = data.readFloatArray( this.length );
  594. }
  595. // UV
  596. if ( this.attrib & 32 ) {
  597. var uvCount = data.readUByte();
  598. if ( uvCount ) {
  599. this.uv = [];
  600. len = this.numVertex * 2;
  601. i = 0;
  602. while ( i < uvCount ) {
  603. // UV VERTEX DATA
  604. this.uv[ i ++ ] = data.readFloatArray( len );
  605. }
  606. }
  607. }
  608. // JOINT-INDEXES / WEIGHTS
  609. if ( this.attrib & 64 ) {
  610. this.jointPerVertex = data.readUByte();
  611. var jntLen = this.numVertex * this.jointPerVertex;
  612. this.joint = data.readUShortArray( jntLen );
  613. this.weight = data.readFloatArray( jntLen );
  614. }
  615. // VERTEX_COLOR
  616. if ( this.attrib & 128 ) {
  617. var colorAttrib = data.readUByte();
  618. var colorCount = data.readUByte();
  619. if ( colorCount ) {
  620. this.numColor = ( ( ( colorAttrib & 64 ) >> 6 ) | ( ( colorAttrib & 128 ) >> 6 ) ) + 1;
  621. this.color = [];
  622. for ( i = 0 & 15; i < colorCount; i ++ ) {
  623. this.color.push( data.readFloatArray( this.numVertex * this.numColor ) );
  624. }
  625. }
  626. }
  627. // VERTEX
  628. this.vertex = data.readFloatArray( this.length );
  629. // SUB-MESHES
  630. var count = data.readUByte();
  631. this.groups = [];
  632. if ( this.attrib & 1024 ) {
  633. // INDEXES
  634. for ( i = 0, len = 0; i < count; i ++ ) {
  635. j = data.readVInt() * 3;
  636. this.groups.push( {
  637. start: len,
  638. count: j
  639. } );
  640. len += j;
  641. }
  642. if ( ! ( this.attrib & 2048 ) ) {
  643. this.indexes = this.isBig ? data.readUIntArray( len ) : data.readUShortArray( len );
  644. }
  645. } else {
  646. // INDEXES
  647. var stride = this.isBig ? 4 : 2,
  648. bytearray = new SEA3DSDK.UByteArray();
  649. for ( i = 0, j = 0; i < count; i ++ ) {
  650. len = data.readVInt() * 3;
  651. this.groups.push( {
  652. start: j,
  653. count: len
  654. } );
  655. j += len;
  656. bytearray.add( data.readUByteArray( len * stride ) );
  657. }
  658. this.indexes = this.isBig ? new Uint32Array( bytearray.toBuffer() ) : new Uint16Array( bytearray.toBuffer() );
  659. }
  660. };
  661. SEA3DSDK.Geometry.prototype = Object.create( SEA3DSDK.GeometryBase.prototype );
  662. SEA3DSDK.Geometry.prototype.constructor = SEA3DSDK.Geometry;
  663. SEA3DSDK.Geometry.prototype.type = "geo";
  664. //
  665. // Object3D
  666. //
  667. SEA3DSDK.Object3D = function ( name, data, sea3d ) {
  668. this.name = name;
  669. this.data = data;
  670. this.sea3d = sea3d;
  671. this.isStatic = false;
  672. this.visible = true;
  673. this.attrib = data.readUShort();
  674. if ( this.attrib & 1 ) this.parent = sea3d.getObject( data.readUInt() );
  675. if ( this.attrib & 2 ) this.animations = data.readAnimationList( sea3d );
  676. if ( this.attrib & 4 ) this.scripts = data.readScriptList( sea3d );
  677. if ( this.attrib & 16 ) this.attributes = sea3d.getObject( data.readUInt() );
  678. if ( this.attrib & 32 ) {
  679. var objectType = data.readUByte();
  680. this.isStatic = ( objectType & 1 ) !== 0;
  681. this.visible = ( objectType & 2 ) === 0;
  682. }
  683. };
  684. SEA3DSDK.Object3D.prototype.readTag = function ( kind, data, size ) {
  685. };
  686. //
  687. // Entity3D
  688. //
  689. SEA3DSDK.Entity3D = function ( name, data, sea3d ) {
  690. SEA3DSDK.Object3D.call( this, name, data, sea3d );
  691. this.castShadows = true;
  692. if ( this.attrib & 64 ) {
  693. var lightType = data.readUByte();
  694. this.castShadows = ( lightType & 1 ) === 0;
  695. }
  696. };
  697. SEA3DSDK.Entity3D.prototype = Object.create( SEA3DSDK.Object3D.prototype );
  698. SEA3DSDK.Entity3D.prototype.constructor = SEA3DSDK.Entity3D;
  699. //
  700. // Sound3D
  701. //
  702. SEA3DSDK.Sound3D = function ( name, data, sea3d ) {
  703. SEA3DSDK.Object3D.call( this, name, data, sea3d );
  704. this.autoPlay = ( this.attrib & 64 ) != 0;
  705. if ( this.attrib & 128 ) this.mixer = sea3d.getObject( data.readUInt() );
  706. this.sound = sea3d.getObject( data.readUInt() );
  707. this.volume = data.readFloat();
  708. };
  709. SEA3DSDK.Sound3D.prototype = Object.create( SEA3DSDK.Object3D.prototype );
  710. SEA3DSDK.Sound3D.prototype.constructor = SEA3DSDK.Sound3D;
  711. //
  712. // Sound Point
  713. //
  714. SEA3DSDK.SoundPoint = function ( name, data, sea3d ) {
  715. SEA3DSDK.Sound3D.call( this, name, data, sea3d );
  716. this.position = data.readVector3();
  717. this.distance = data.readFloat();
  718. data.readTags( this.readTag.bind( this ) );
  719. };
  720. SEA3DSDK.SoundPoint.prototype = Object.create( SEA3DSDK.Sound3D.prototype );
  721. SEA3DSDK.SoundPoint.prototype.constructor = SEA3DSDK.SoundPoint;
  722. SEA3DSDK.SoundPoint.prototype.type = "sp";
  723. //
  724. // Container3D
  725. //
  726. SEA3DSDK.Container3D = function ( name, data, sea3d ) {
  727. SEA3DSDK.Object3D.call( this, name, data, sea3d );
  728. this.transform = data.readMatrix();
  729. data.readTags( this.readTag.bind( this ) );
  730. };
  731. SEA3DSDK.Container3D.prototype = Object.create( SEA3DSDK.Object3D.prototype );
  732. SEA3DSDK.Container3D.prototype.constructor = SEA3DSDK.Container3D;
  733. SEA3DSDK.Container3D.prototype.type = "c3d";
  734. //
  735. // Script URL
  736. //
  737. SEA3DSDK.ScriptURL = function ( name, data, sea3d ) {
  738. this.name = name;
  739. this.data = data;
  740. this.sea3d = sea3d;
  741. this.url = data.readUTF8( data.length );
  742. };
  743. SEA3DSDK.ScriptURL.prototype.type = "src";
  744. //
  745. // Texture URL
  746. //
  747. SEA3DSDK.TextureURL = function ( name, data, sea3d ) {
  748. this.name = name;
  749. this.data = data;
  750. this.sea3d = sea3d;
  751. this.url = sea3d.config.path + data.readUTF8( data.length );
  752. };
  753. SEA3DSDK.TextureURL.prototype.type = "urlT";
  754. //
  755. // CubeMap URL
  756. //
  757. SEA3DSDK.CubeMapURL = function ( name, data, sea3d ) {
  758. this.name = name;
  759. this.data = data;
  760. this.sea3d = sea3d;
  761. this.faces = [];
  762. for ( var i = 0; i < 6; i ++ ) {
  763. this.faces[ i ] = data.readUTF8Tiny();
  764. }
  765. };
  766. SEA3DSDK.CubeMapURL.prototype.type = "cURL";
  767. //
  768. // Actions
  769. //
  770. SEA3DSDK.Actions = function ( name, data, sea3d ) {
  771. this.name = name;
  772. this.data = data;
  773. this.sea3d = sea3d;
  774. this.count = data.readUInt();
  775. this.actions = [];
  776. for ( var i = 0; i < this.count; i ++ ) {
  777. var flag = data.readUByte();
  778. var kind = data.readUShort();
  779. var size = data.readUShort();
  780. var position = data.position;
  781. var act = this.actions[ i ] = { kind: kind };
  782. // range of animation
  783. if ( flag & 1 ) {
  784. // start and count in frames
  785. act.range = [ data.readUInt(), data.readUInt() ];
  786. }
  787. // time
  788. if ( flag & 2 ) {
  789. act.time = data.readUInt();
  790. }
  791. // easing
  792. if ( flag & 4 ) {
  793. act.intrpl = data.readInterpolation();
  794. if ( act.intrpl.indexOf( 'back.' ) === 0 ) {
  795. act.intrplParam0 = data.readFloat();
  796. } else if ( act.intrpl.indexOf( 'elastic.' ) === 0 ) {
  797. act.intrplParam0 = data.readFloat();
  798. act.intrplParam1 = data.readFloat();
  799. }
  800. }
  801. switch ( kind ) {
  802. case SEA3DSDK.Actions.RTT_TARGET:
  803. act.source = sea3d.getObject( data.readUInt() );
  804. act.target = sea3d.getObject( data.readUInt() );
  805. break;
  806. case SEA3DSDK.Actions.LOOK_AT:
  807. act.source = sea3d.getObject( data.readUInt() );
  808. act.target = sea3d.getObject( data.readUInt() );
  809. break;
  810. case SEA3DSDK.Actions.PLAY_SOUND:
  811. act.sound = sea3d.getObject( data.readUInt() );
  812. act.offset = data.readUInt();
  813. break;
  814. case SEA3DSDK.Actions.PLAY_ANIMATION:
  815. act.object = sea3d.getObject( data.readUInt() );
  816. act.name = data.readUTF8Tiny();
  817. break;
  818. case SEA3DSDK.Actions.FOG:
  819. act.color = data.readUInt24();
  820. act.min = data.readFloat();
  821. act.max = data.readFloat();
  822. break;
  823. case SEA3DSDK.Actions.ENVIRONMENT:
  824. act.texture = sea3d.getObject( data.readUInt() );
  825. break;
  826. case SEA3DSDK.Actions.ENVIRONMENT_COLOR:
  827. act.color = data.readUInt24F();
  828. break;
  829. case SEA3DSDK.Actions.CAMERA:
  830. act.camera = sea3d.getObject( data.readUInt() );
  831. break;
  832. case SEA3DSDK.Actions.SCRIPTS:
  833. act.scripts = data.readScriptList( sea3d );
  834. break;
  835. case SEA3DSDK.Actions.CLASS_OF:
  836. act.classof = sea3d.getObject( data.readUInt() );
  837. break;
  838. case SEA3DSDK.Actions.ATTRIBUTES:
  839. act.attributes = sea3d.getObject( data.readUInt() );
  840. break;
  841. default:
  842. console.log( "Action \"" + kind + "\" not found." );
  843. break;
  844. }
  845. data.position = position + size;
  846. }
  847. };
  848. SEA3DSDK.Actions.SCENE = 0;
  849. SEA3DSDK.Actions.ENVIRONMENT_COLOR = 1;
  850. SEA3DSDK.Actions.ENVIRONMENT = 2;
  851. SEA3DSDK.Actions.FOG = 3;
  852. SEA3DSDK.Actions.PLAY_ANIMATION = 4;
  853. SEA3DSDK.Actions.PLAY_SOUND = 5;
  854. SEA3DSDK.Actions.ANIMATION_AUDIO_SYNC = 6;
  855. SEA3DSDK.Actions.LOOK_AT = 7;
  856. SEA3DSDK.Actions.RTT_TARGET = 8;
  857. SEA3DSDK.Actions.CAMERA = 9;
  858. SEA3DSDK.Actions.SCRIPTS = 10;
  859. SEA3DSDK.Actions.CLASS_OF = 11;
  860. SEA3DSDK.Actions.ATTRIBUTES = 12;
  861. SEA3DSDK.Actions.prototype.type = "act";
  862. //
  863. // Properties
  864. //
  865. SEA3DSDK.Properties = function ( name, data, sea3d ) {
  866. this.name = name;
  867. this.data = data;
  868. this.sea3d = sea3d;
  869. this.props = data.readProperties( sea3d );
  870. this.props.__name = name;
  871. };
  872. SEA3DSDK.Properties.prototype.type = "prop";
  873. //
  874. // File Info
  875. //
  876. SEA3DSDK.FileInfo = function ( name, data, sea3d ) {
  877. this.name = name;
  878. this.data = data;
  879. this.sea3d = sea3d;
  880. this.info = data.readProperties( sea3d );
  881. this.info.__name = name;
  882. sea3d.info = this.info;
  883. };
  884. SEA3DSDK.FileInfo.prototype.type = "info";
  885. //
  886. // Java Script
  887. //
  888. SEA3DSDK.JavaScript = function ( name, data, sea3d ) {
  889. this.name = name;
  890. this.data = data;
  891. this.sea3d = sea3d;
  892. this.src = data.readUTF8( data.length );
  893. };
  894. SEA3DSDK.JavaScript.prototype.type = "js";
  895. //
  896. // Java Script Method
  897. //
  898. SEA3DSDK.JavaScriptMethod = function ( name, data, sea3d ) {
  899. this.name = name;
  900. this.data = data;
  901. this.sea3d = sea3d;
  902. var count = data.readUShort();
  903. this.methods = {};
  904. for ( var i = 0; i < count; i ++ ) {
  905. var flag = data.readUByte();
  906. var method = data.readUTF8Tiny();
  907. this.methods[ method ] = {
  908. src: data.readUTF8Long()
  909. };
  910. }
  911. };
  912. SEA3DSDK.JavaScriptMethod.prototype.type = "jsm";
  913. //
  914. // GLSL
  915. //
  916. SEA3DSDK.GLSL = function ( name, data, sea3d ) {
  917. this.name = name;
  918. this.data = data;
  919. this.sea3d = sea3d;
  920. this.src = data.readUTF8( data.length );
  921. };
  922. SEA3DSDK.GLSL.prototype.type = "glsl";
  923. //
  924. // Dummy
  925. //
  926. SEA3DSDK.Dummy = function ( name, data, sea3d ) {
  927. SEA3DSDK.Object3D.call( this, name, data, sea3d );
  928. this.transform = data.readMatrix();
  929. this.width = data.readFloat();
  930. this.height = data.readFloat();
  931. this.depth = data.readFloat();
  932. data.readTags( this.readTag.bind( this ) );
  933. };
  934. SEA3DSDK.Dummy.prototype = Object.create( SEA3DSDK.Object3D.prototype );
  935. SEA3DSDK.Dummy.prototype.constructor = SEA3DSDK.Dummy;
  936. SEA3DSDK.Dummy.prototype.type = "dmy";
  937. //
  938. // Line
  939. //
  940. SEA3DSDK.Line = function ( name, data, sea3d ) {
  941. SEA3DSDK.Object3D.call( this, name, data, sea3d );
  942. this.count = ( this.attrib & 64 ? data.readUInt() : data.readUShort() ) * 3;
  943. this.closed = ( this.attrib & 128 ) != 0;
  944. this.transform = data.readMatrix();
  945. this.vertex = [];
  946. var i = 0;
  947. while ( i < this.count ) {
  948. this.vertex[ i ++ ] = data.readFloat();
  949. }
  950. data.readTags( this.readTag.bind( this ) );
  951. };
  952. SEA3DSDK.Line.prototype = Object.create( SEA3DSDK.Object3D.prototype );
  953. SEA3DSDK.Line.prototype.constructor = SEA3DSDK.Line;
  954. SEA3DSDK.Line.prototype.type = "line";
  955. //
  956. // Sprite
  957. //
  958. SEA3DSDK.Sprite = function ( name, data, sea3d ) {
  959. SEA3DSDK.Object3D.call( this, name, data, sea3d );
  960. if ( this.attrib & 256 ) {
  961. this.material = sea3d.getObject( data.readUInt() );
  962. }
  963. this.position = data.readVector3();
  964. this.width = data.readFloat();
  965. this.height = data.readFloat();
  966. data.readTags( this.readTag.bind( this ) );
  967. };
  968. SEA3DSDK.Sprite.prototype = Object.create( SEA3DSDK.Object3D.prototype );
  969. SEA3DSDK.Sprite.prototype.constructor = SEA3DSDK.Sprite;
  970. SEA3DSDK.Sprite.prototype.type = "m2d";
  971. //
  972. // Mesh
  973. //
  974. SEA3DSDK.Mesh = function ( name, data, sea3d ) {
  975. SEA3DSDK.Entity3D.call( this, name, data, sea3d );
  976. // MATERIAL
  977. if ( this.attrib & 256 ) {
  978. this.material = [];
  979. var len = data.readUByte();
  980. if ( len === 1 ) this.material[ 0 ] = sea3d.getObject( data.readUInt() );
  981. else {
  982. var i = 0;
  983. while ( i < len ) {
  984. var matIndex = data.readUInt();
  985. if ( matIndex > 0 ) this.material[ i ++ ] = sea3d.getObject( matIndex - 1 );
  986. else this.material[ i ++ ] = undefined;
  987. }
  988. }
  989. }
  990. if ( this.attrib & 512 ) {
  991. this.modifiers = [];
  992. var len = data.readUByte();
  993. for ( var i = 0; i < len; i ++ ) {
  994. this.modifiers[ i ] = sea3d.getObject( data.readUInt() );
  995. }
  996. }
  997. if ( this.attrib & 1024 ) {
  998. this.reference = {
  999. type: data.readUByte(),
  1000. ref: sea3d.getObject( data.readUInt() )
  1001. };
  1002. }
  1003. this.transform = data.readMatrix();
  1004. this.geometry = sea3d.getObject( data.readUInt() );
  1005. data.readTags( this.readTag.bind( this ) );
  1006. };
  1007. SEA3DSDK.Mesh.prototype = Object.create( SEA3DSDK.Entity3D.prototype );
  1008. SEA3DSDK.Mesh.prototype.constructor = SEA3DSDK.Mesh;
  1009. SEA3DSDK.Mesh.prototype.type = "m3d";
  1010. //
  1011. // Skeleton
  1012. //
  1013. SEA3DSDK.Skeleton = function ( name, data, sea3d ) {
  1014. this.name = name;
  1015. this.data = data;
  1016. this.sea3d = sea3d;
  1017. var length = data.readUShort();
  1018. this.joint = [];
  1019. for ( var i = 0; i < length; i ++ ) {
  1020. this.joint[ i ] = {
  1021. name: data.readUTF8Tiny(),
  1022. parentIndex: data.readUShort() - 1,
  1023. inverseBindMatrix: data.readMatrix()
  1024. };
  1025. }
  1026. };
  1027. SEA3DSDK.Skeleton.prototype.type = "skl";
  1028. //
  1029. // Skeleton Local
  1030. //
  1031. SEA3DSDK.SkeletonLocal = function ( name, data, sea3d ) {
  1032. this.name = name;
  1033. this.data = data;
  1034. this.sea3d = sea3d;
  1035. var length = data.readUShort();
  1036. this.joint = [];
  1037. for ( var i = 0; i < length; i ++ ) {
  1038. this.joint[ i ] = {
  1039. name: data.readUTF8Tiny(),
  1040. parentIndex: data.readUShort() - 1,
  1041. // POSITION XYZ
  1042. x: data.readFloat(),
  1043. y: data.readFloat(),
  1044. z: data.readFloat(),
  1045. // QUATERNION XYZW
  1046. qx: data.readFloat(),
  1047. qy: data.readFloat(),
  1048. qz: data.readFloat(),
  1049. qw: data.readFloat()
  1050. };
  1051. }
  1052. };
  1053. SEA3DSDK.SkeletonLocal.prototype.type = "sklq";
  1054. //
  1055. // Animation Base
  1056. //
  1057. SEA3DSDK.AnimationBase = function ( name, data, sea3d ) {
  1058. this.name = name;
  1059. this.data = data;
  1060. this.sea3d = sea3d;
  1061. var flag = data.readUByte();
  1062. this.sequence = [];
  1063. if ( flag & 1 ) {
  1064. var count = data.readUShort();
  1065. for ( var i = 0; i < count; i ++ ) {
  1066. var seqFlag = data.readUByte();
  1067. this.sequence[ i ] = {
  1068. name: data.readUTF8Tiny(),
  1069. start: data.readUInt(),
  1070. count: data.readUInt(),
  1071. repeat: ( seqFlag & 1 ) !== 0,
  1072. intrpl: ( seqFlag & 2 ) === 0
  1073. };
  1074. }
  1075. }
  1076. this.frameRate = data.readUByte();
  1077. this.numFrames = data.readUInt();
  1078. // no contains sequence
  1079. if ( this.sequence.length === 0 ) {
  1080. this.sequence[ 0 ] = { name: "root", start: 0, count: this.numFrames, repeat: true, intrpl: true };
  1081. }
  1082. };
  1083. //
  1084. // Animation
  1085. //
  1086. SEA3DSDK.Animation = function ( name, data, sea3d ) {
  1087. SEA3DSDK.AnimationBase.call( this, name, data, sea3d );
  1088. this.dataList = [];
  1089. for ( var i = 0, l = data.readUByte(); i < l; i ++ ) {
  1090. var kind = data.readUShort(),
  1091. type = data.readUByte();
  1092. var anmRaw = data.readVector( type, this.numFrames, 0 );
  1093. this.dataList.push( {
  1094. kind: kind,
  1095. type: type,
  1096. blockSize: SEA3DSDK.Stream.sizeOf( type ),
  1097. data: anmRaw
  1098. } );
  1099. }
  1100. };
  1101. SEA3DSDK.Animation.POSITION = 0;
  1102. SEA3DSDK.Animation.ROTATION = 1;
  1103. SEA3DSDK.Animation.SCALE = 2;
  1104. SEA3DSDK.Animation.COLOR = 3;
  1105. SEA3DSDK.Animation.MULTIPLIER = 4;
  1106. SEA3DSDK.Animation.ATTENUATION_START = 5;
  1107. SEA3DSDK.Animation.ATTENUATION_END = 6;
  1108. SEA3DSDK.Animation.FOV = 7;
  1109. SEA3DSDK.Animation.OFFSET_U = 8;
  1110. SEA3DSDK.Animation.OFFSET_V = 9;
  1111. SEA3DSDK.Animation.SCALE_U = 10;
  1112. SEA3DSDK.Animation.SCALE_V = 11;
  1113. SEA3DSDK.Animation.DEGREE = 12;
  1114. SEA3DSDK.Animation.ALPHA = 13;
  1115. SEA3DSDK.Animation.VOLUME = 14;
  1116. SEA3DSDK.Animation.RADIAN = 15;
  1117. SEA3DSDK.Animation.MORPH = 250;
  1118. SEA3DSDK.Animation.prototype = Object.create( SEA3DSDK.AnimationBase.prototype );
  1119. SEA3DSDK.Animation.prototype.constructor = SEA3DSDK.Animation;
  1120. SEA3DSDK.Animation.prototype.type = "anm";
  1121. //
  1122. // Skeleton Animation
  1123. //
  1124. SEA3DSDK.SkeletonAnimation = function ( name, data, sea3d ) {
  1125. SEA3DSDK.AnimationBase.call( this, name, data, sea3d );
  1126. this.name = name;
  1127. this.data = data;
  1128. this.sea3d = sea3d;
  1129. this.numJoints = data.readUShort();
  1130. this.raw = data.readFloatArray( this.numFrames * this.numJoints * 7 );
  1131. };
  1132. SEA3DSDK.SkeletonAnimation.prototype.type = "skla";
  1133. //
  1134. // UVW Animation
  1135. //
  1136. SEA3DSDK.UVWAnimation = function ( name, data, sea3d ) {
  1137. SEA3DSDK.Animation.call( this, name, data, sea3d );
  1138. };
  1139. SEA3DSDK.UVWAnimation.prototype.type = "auvw";
  1140. //
  1141. // Morph
  1142. //
  1143. SEA3DSDK.Morph = function ( name, data, sea3d ) {
  1144. SEA3DSDK.GeometryBase.call( this, name, data, sea3d );
  1145. var useVertex = ( this.attrib & 2 ) != 0;
  1146. var useNormal = ( this.attrib & 4 ) != 0;
  1147. var nodeCount = data.readUShort();
  1148. this.node = [];
  1149. for ( var i = 0; i < nodeCount; i ++ ) {
  1150. var nodeName = data.readUTF8Tiny(),
  1151. verts, norms;
  1152. if ( useVertex ) verts = data.readFloatArray( this.length );
  1153. if ( useNormal ) norms = data.readFloatArray( this.length );
  1154. this.node[ i ] = { vertex: verts, normal: norms, name: nodeName };
  1155. }
  1156. };
  1157. SEA3DSDK.Morph.prototype = Object.create( SEA3DSDK.GeometryBase.prototype );
  1158. SEA3DSDK.Morph.prototype.constructor = SEA3DSDK.Morph;
  1159. SEA3DSDK.Morph.prototype.type = "mph";
  1160. //
  1161. // Morph Animation
  1162. //
  1163. SEA3DSDK.MorphAnimation = function ( name, data, sea3d ) {
  1164. SEA3DSDK.AnimationBase.call( this, name, data, sea3d );
  1165. this.dataList = [];
  1166. for ( var i = 0, l = data.readUByte(); i < l; i ++ ) {
  1167. this.dataList.push( {
  1168. kind: SEA3DSDK.Animation.MORPH,
  1169. type: SEA3DSDK.Stream.FLOAT,
  1170. name: data.readUTF8Tiny(),
  1171. blockSize: 1,
  1172. data: data.readVector( SEA3DSDK.Stream.FLOAT, this.numFrames, 0 )
  1173. } );
  1174. }
  1175. };
  1176. SEA3DSDK.MorphAnimation.prototype.type = "mpha";
  1177. //
  1178. // Vertex Animation
  1179. //
  1180. SEA3DSDK.VertexAnimation = function ( name, data, sea3d ) {
  1181. SEA3DSDK.AnimationBase.call( this, name, data, sea3d );
  1182. var flags = data.readUByte();
  1183. this.isBig = ( flags & 1 ) != 0;
  1184. data.readVInt = this.isBig ? data.readUInt : data.readUShort;
  1185. this.numVertex = data.readVInt();
  1186. this.length = this.numVertex * 3;
  1187. var useVertex = ( flags & 2 ) != 0;
  1188. var useNormal = ( flags & 4 ) != 0;
  1189. this.frame = [];
  1190. var i, verts, norms;
  1191. for ( i = 0; i < this.numFrames; i ++ ) {
  1192. if ( useVertex ) verts = data.readFloatArray( this.length );
  1193. if ( useNormal ) norms = data.readFloatArray( this.length );
  1194. this.frame[ i ] = { vertex: verts, normal: norms };
  1195. }
  1196. };
  1197. SEA3DSDK.VertexAnimation.prototype = Object.create( SEA3DSDK.AnimationBase.prototype );
  1198. SEA3DSDK.VertexAnimation.prototype.constructor = SEA3DSDK.VertexAnimation;
  1199. SEA3DSDK.VertexAnimation.prototype.type = "vtxa";
  1200. //
  1201. // Camera
  1202. //
  1203. SEA3DSDK.Camera = function ( name, data, sea3d ) {
  1204. SEA3DSDK.Object3D.call( this, name, data, sea3d );
  1205. if ( this.attrib & 64 ) {
  1206. this.dof = {
  1207. distance: data.readFloat(),
  1208. range: data.readFloat()
  1209. };
  1210. }
  1211. this.transform = data.readMatrix();
  1212. this.fov = data.readFloat();
  1213. data.readTags( this.readTag.bind( this ) );
  1214. };
  1215. SEA3DSDK.Camera.prototype = Object.create( SEA3DSDK.Object3D.prototype );
  1216. SEA3DSDK.Camera.prototype.constructor = SEA3DSDK.Camera;
  1217. SEA3DSDK.Camera.prototype.type = "cam";
  1218. //
  1219. // Orthographic Camera
  1220. //
  1221. SEA3DSDK.OrthographicCamera = function ( name, data, sea3d ) {
  1222. SEA3DSDK.Object3D.call( this, name, data, sea3d );
  1223. this.transform = data.readMatrix();
  1224. this.height = data.readFloat();
  1225. data.readTags( this.readTag.bind( this ) );
  1226. };
  1227. SEA3DSDK.OrthographicCamera.prototype = Object.create( SEA3DSDK.Object3D.prototype );
  1228. SEA3DSDK.OrthographicCamera.prototype.constructor = SEA3DSDK.OrthographicCamera;
  1229. SEA3DSDK.OrthographicCamera.prototype.type = "camo";
  1230. //
  1231. // Joint Object
  1232. //
  1233. SEA3DSDK.JointObject = function ( name, data, sea3d ) {
  1234. SEA3DSDK.Object3D.call( this, name, data, sea3d );
  1235. this.target = sea3d.getObject( data.readUInt() );
  1236. this.joint = data.readUShort();
  1237. data.readTags( this.readTag.bind( this ) );
  1238. };
  1239. SEA3DSDK.JointObject.prototype = Object.create( SEA3DSDK.Object3D.prototype );
  1240. SEA3DSDK.JointObject.prototype.constructor = SEA3DSDK.JointObject;
  1241. SEA3DSDK.JointObject.prototype.type = "jnt";
  1242. //
  1243. // Light
  1244. //
  1245. SEA3DSDK.Light = function ( name, data, sea3d ) {
  1246. SEA3DSDK.Object3D.call( this, name, data, sea3d );
  1247. this.attenStart = Number.MAX_VALUE;
  1248. this.attenEnd = Number.MAX_VALUE;
  1249. if ( this.attrib & 64 ) {
  1250. var shadowHeader = data.readUByte();
  1251. this.shadow = {};
  1252. this.shadow.opacity = shadowHeader & 1 ? data.readFloat() : 1;
  1253. this.shadow.color = shadowHeader & 2 ? data.readUInt24() : 0x000000;
  1254. }
  1255. if ( this.attrib & 512 ) {
  1256. this.attenStart = data.readFloat();
  1257. this.attenEnd = data.readFloat();
  1258. }
  1259. this.color = data.readUInt24();
  1260. this.multiplier = data.readFloat();
  1261. };
  1262. SEA3DSDK.Light.prototype = Object.create( SEA3DSDK.Object3D.prototype );
  1263. SEA3DSDK.Light.prototype.constructor = SEA3DSDK.Light;
  1264. //
  1265. // Point Light
  1266. //
  1267. SEA3DSDK.PointLight = function ( name, data, sea3d ) {
  1268. SEA3DSDK.Light.call( this, name, data, sea3d );
  1269. if ( this.attrib & 128 ) {
  1270. this.attenuation = {
  1271. start: data.readFloat(),
  1272. end: data.readFloat()
  1273. };
  1274. }
  1275. this.position = data.readVector3();
  1276. data.readTags( this.readTag.bind( this ) );
  1277. };
  1278. SEA3DSDK.PointLight.prototype = Object.create( SEA3DSDK.Light.prototype );
  1279. SEA3DSDK.PointLight.prototype.constructor = SEA3DSDK.PointLight;
  1280. SEA3DSDK.PointLight.prototype.type = "plht";
  1281. //
  1282. // Hemisphere Light
  1283. //
  1284. SEA3DSDK.HemisphereLight = function ( name, data, sea3d ) {
  1285. SEA3DSDK.Light.call( this, name, data, sea3d );
  1286. if ( this.attrib & 128 ) {
  1287. this.attenuation = {
  1288. start: data.readFloat(),
  1289. end: data.readFloat()
  1290. };
  1291. }
  1292. this.secondColor = data.readUInt24();
  1293. data.readTags( this.readTag.bind( this ) );
  1294. };
  1295. SEA3DSDK.HemisphereLight.prototype = Object.create( SEA3DSDK.Light.prototype );
  1296. SEA3DSDK.HemisphereLight.prototype.constructor = SEA3DSDK.HemisphereLight;
  1297. SEA3DSDK.HemisphereLight.prototype.type = "hlht";
  1298. //
  1299. // Ambient Light
  1300. //
  1301. SEA3DSDK.AmbientLight = function ( name, data, sea3d ) {
  1302. SEA3DSDK.Light.call( this, name, data, sea3d );
  1303. data.readTags( this.readTag.bind( this ) );
  1304. };
  1305. SEA3DSDK.AmbientLight.prototype = Object.create( SEA3DSDK.Light.prototype );
  1306. SEA3DSDK.AmbientLight.prototype.constructor = SEA3DSDK.AmbientLight;
  1307. SEA3DSDK.AmbientLight.prototype.type = "alht";
  1308. //
  1309. // Directional Light
  1310. //
  1311. SEA3DSDK.DirectionalLight = function ( name, data, sea3d ) {
  1312. SEA3DSDK.Light.call( this, name, data, sea3d );
  1313. this.transform = data.readMatrix();
  1314. data.readTags( this.readTag.bind( this ) );
  1315. };
  1316. SEA3DSDK.DirectionalLight.prototype = Object.create( SEA3DSDK.Light.prototype );
  1317. SEA3DSDK.DirectionalLight.prototype.constructor = SEA3DSDK.DirectionalLight;
  1318. SEA3DSDK.DirectionalLight.prototype.type = "dlht";
  1319. //
  1320. // Material
  1321. //
  1322. SEA3DSDK.Material = function ( name, data, sea3d ) {
  1323. this.name = name;
  1324. this.data = data;
  1325. this.sea3d = sea3d;
  1326. this.technique = [];
  1327. this.tecniquesDict = {};
  1328. this.attrib = data.readUShort();
  1329. this.alpha = 1;
  1330. this.blendMode = "normal";
  1331. this.doubleSided = ( this.attrib & 1 ) != 0;
  1332. this.receiveLights = ( this.attrib & 2 ) === 0;
  1333. this.receiveShadows = ( this.attrib & 4 ) === 0;
  1334. this.receiveFog = ( this.attrib & 8 ) === 0;
  1335. this.repeat = ( this.attrib & 16 ) === 0;
  1336. if ( this.attrib & 32 )
  1337. this.alpha = data.readFloat();
  1338. if ( this.attrib & 64 )
  1339. this.blendMode = data.readBlendMode();
  1340. if ( this.attrib & 128 )
  1341. this.animations = data.readAnimationList( sea3d );
  1342. this.depthWrite = ( this.attrib & 256 ) === 0;
  1343. this.depthTest = ( this.attrib & 512 ) === 0;
  1344. this.premultipliedAlpha = ( this.attrib & 1024 ) != 0;
  1345. var count = data.readUByte();
  1346. for ( var i = 0; i < count; ++ i ) {
  1347. var kind = data.readUShort();
  1348. var size = data.readUShort();
  1349. var pos = data.position;
  1350. var tech, methodAttrib;
  1351. switch ( kind ) {
  1352. case SEA3DSDK.Material.PHONG:
  1353. tech = {
  1354. ambientColor: data.readUInt24(),
  1355. diffuseColor: data.readUInt24(),
  1356. specularColor: data.readUInt24(),
  1357. specular: data.readFloat(),
  1358. gloss: data.readFloat()
  1359. };
  1360. break;
  1361. case SEA3DSDK.Material.PHYSICAL:
  1362. tech = {
  1363. color: data.readUInt24(),
  1364. roughness: data.readFloat(),
  1365. metalness: data.readFloat()
  1366. };
  1367. break;
  1368. case SEA3DSDK.Material.ANISOTROPIC:
  1369. break;
  1370. case SEA3DSDK.Material.COMPOSITE_TEXTURE:
  1371. tech = {
  1372. composite: sea3d.getObject( data.readUInt() )
  1373. };
  1374. break;
  1375. case SEA3DSDK.Material.DIFFUSE_MAP:
  1376. case SEA3DSDK.Material.SPECULAR_MAP:
  1377. case SEA3DSDK.Material.NORMAL_MAP:
  1378. case SEA3DSDK.Material.AMBIENT_MAP:
  1379. case SEA3DSDK.Material.ALPHA_MAP:
  1380. case SEA3DSDK.Material.EMISSIVE_MAP:
  1381. case SEA3DSDK.Material.ROUGHNESS_MAP:
  1382. case SEA3DSDK.Material.METALNESS_MAP:
  1383. tech = {
  1384. texture: sea3d.getObject( data.readUInt() )
  1385. };
  1386. break;
  1387. case SEA3DSDK.Material.REFLECTION:
  1388. case SEA3DSDK.Material.FRESNEL_REFLECTION:
  1389. tech = {
  1390. texture: sea3d.getObject( data.readUInt() ),
  1391. alpha: data.readFloat()
  1392. };
  1393. if ( kind === SEA3DSDK.Material.FRESNEL_REFLECTION ) {
  1394. tech.power = data.readFloat();
  1395. tech.normal = data.readFloat();
  1396. }
  1397. break;
  1398. case SEA3DSDK.Material.REFRACTION:
  1399. tech = {
  1400. texture: sea3d.getObject( data.readUInt() ),
  1401. alpha: data.readFloat(),
  1402. ior: data.readFloat()
  1403. };
  1404. break;
  1405. case SEA3DSDK.Material.RIM:
  1406. tech = {
  1407. color: data.readUInt24(),
  1408. strength: data.readFloat(),
  1409. power: data.readFloat(),
  1410. blendMode: data.readBlendMode()
  1411. };
  1412. break;
  1413. case SEA3DSDK.Material.LIGHT_MAP:
  1414. tech = {
  1415. texture: sea3d.getObject( data.readUInt() ),
  1416. channel: data.readUByte(),
  1417. blendMode: data.readBlendMode()
  1418. };
  1419. break;
  1420. case SEA3DSDK.Material.DETAIL_MAP:
  1421. tech = {
  1422. texture: sea3d.getObject( data.readUInt() ),
  1423. scale: data.readFloat(),
  1424. blendMode: data.readBlendMode()
  1425. };
  1426. break;
  1427. case SEA3DSDK.Material.CEL:
  1428. tech = {
  1429. color: data.readUInt24(),
  1430. levels: data.readUByte(),
  1431. size: data.readFloat(),
  1432. specularCutOff: data.readFloat(),
  1433. smoothness: data.readFloat()
  1434. };
  1435. break;
  1436. case SEA3DSDK.Material.TRANSLUCENT:
  1437. tech = {
  1438. translucency: data.readFloat(),
  1439. scattering: data.readFloat()
  1440. };
  1441. break;
  1442. case SEA3DSDK.Material.BLEND_NORMAL_MAP:
  1443. methodAttrib = data.readUByte();
  1444. tech = {
  1445. texture: sea3d.getObject( data.readUInt() ),
  1446. secondaryTexture: sea3d.getObject( data.readUInt() )
  1447. };
  1448. if ( methodAttrib & 1 ) {
  1449. tech.offsetX0 = data.readFloat();
  1450. tech.offsetY0 = data.readFloat();
  1451. tech.offsetX1 = data.readFloat();
  1452. tech.offsetY1 = data.readFloat();
  1453. } else {
  1454. tech.offsetX0 = tech.offsetY0 =
  1455. tech.offsetX1 = tech.offsetY1 = 0;
  1456. }
  1457. tech.animate = methodAttrib & 2;
  1458. break;
  1459. case SEA3DSDK.Material.MIRROR_REFLECTION:
  1460. tech = {
  1461. texture: sea3d.getObject( data.readUInt() ),
  1462. alpha: data.readFloat()
  1463. };
  1464. break;
  1465. case SEA3DSDK.Material.EMISSIVE:
  1466. tech = {
  1467. color: data.readUInt24F()
  1468. };
  1469. break;
  1470. case SEA3DSDK.Material.VERTEX_COLOR:
  1471. tech = {
  1472. blendMode: data.readBlendMode()
  1473. };
  1474. break;
  1475. case SEA3DSDK.Material.WRAP_LIGHTING:
  1476. tech = {
  1477. color: data.readUInt24(),
  1478. strength: data.readFloat()
  1479. };
  1480. break;
  1481. case SEA3DSDK.Material.COLOR_REPLACE:
  1482. methodAttrib = data.readUByte();
  1483. tech = {
  1484. red: data.readUInt24(),
  1485. green: data.readUInt24(),
  1486. blue: data.readUInt24F()
  1487. };
  1488. if ( methodAttrib & 1 ) tech.mask = sea3d.getObject( data.readUInt() );
  1489. if ( methodAttrib & 2 ) tech.alpha = data.readFloat();
  1490. break;
  1491. case SEA3DSDK.Material.REFLECTION_SPHERICAL:
  1492. tech = {
  1493. texture: sea3d.getObject( data.readUInt() ),
  1494. alpha: data.readFloat()
  1495. };
  1496. break;
  1497. case SEA3DSDK.Material.REFLECTIVITY:
  1498. methodAttrib = data.readUByte();
  1499. tech = {
  1500. strength: data.readFloat()
  1501. };
  1502. if ( methodAttrib & 1 ) tech.mask = sea3d.getObject( data.readUInt() );
  1503. break;
  1504. case SEA3DSDK.Material.CLEAR_COAT:
  1505. tech = {
  1506. strength: data.readFloat(),
  1507. roughness: data.readFloat()
  1508. };
  1509. break;
  1510. case SEA3DSDK.Material.FLACCIDITY:
  1511. methodAttrib = data.readUByte();
  1512. tech = {
  1513. target: sea3d.getObject( data.readUInt() ),
  1514. scale: data.readFloat(),
  1515. spring: data.readFloat(),
  1516. damping: data.readFloat()
  1517. };
  1518. if ( methodAttrib & 1 ) tech.mask = sea3d.getObject( data.readUInt() );
  1519. break;
  1520. default:
  1521. console.warn( "SEA3D: MaterialTechnique not found:", kind.toString( 16 ) );
  1522. data.position = pos += size;
  1523. continue;
  1524. }
  1525. tech.kind = kind;
  1526. this.technique.push( tech );
  1527. this.tecniquesDict[ kind ] = tech;
  1528. data.position = pos += size;
  1529. }
  1530. };
  1531. SEA3DSDK.Material.PHONG = 0;
  1532. SEA3DSDK.Material.COMPOSITE_TEXTURE = 1;
  1533. SEA3DSDK.Material.DIFFUSE_MAP = 2;
  1534. SEA3DSDK.Material.SPECULAR_MAP = 3;
  1535. SEA3DSDK.Material.REFLECTION = 4;
  1536. SEA3DSDK.Material.REFRACTION = 5;
  1537. SEA3DSDK.Material.NORMAL_MAP = 6;
  1538. SEA3DSDK.Material.FRESNEL_REFLECTION = 7;
  1539. SEA3DSDK.Material.RIM = 8;
  1540. SEA3DSDK.Material.LIGHT_MAP = 9;
  1541. SEA3DSDK.Material.DETAIL_MAP = 10;
  1542. SEA3DSDK.Material.CEL = 11;
  1543. SEA3DSDK.Material.TRANSLUCENT = 12;
  1544. SEA3DSDK.Material.BLEND_NORMAL_MAP = 13;
  1545. SEA3DSDK.Material.MIRROR_REFLECTION = 14;
  1546. SEA3DSDK.Material.AMBIENT_MAP = 15;
  1547. SEA3DSDK.Material.ALPHA_MAP = 16;
  1548. SEA3DSDK.Material.EMISSIVE_MAP = 17;
  1549. SEA3DSDK.Material.VERTEX_COLOR = 18;
  1550. SEA3DSDK.Material.WRAP_LIGHTING = 19;
  1551. SEA3DSDK.Material.COLOR_REPLACE = 20;
  1552. SEA3DSDK.Material.REFLECTION_SPHERICAL = 21;
  1553. SEA3DSDK.Material.ANISOTROPIC = 22;
  1554. SEA3DSDK.Material.EMISSIVE = 23;
  1555. SEA3DSDK.Material.PHYSICAL = 24;
  1556. SEA3DSDK.Material.ROUGHNESS_MAP = 25;
  1557. SEA3DSDK.Material.METALNESS_MAP = 26;
  1558. SEA3DSDK.Material.REFLECTIVITY = 27;
  1559. SEA3DSDK.Material.CLEAR_COAT = 28;
  1560. SEA3DSDK.Material.FLACCIDITY = 29;
  1561. SEA3DSDK.Material.prototype.type = "mat";
  1562. //
  1563. // Composite
  1564. //
  1565. SEA3DSDK.Composite = function ( name, data, sea3d ) {
  1566. this.name = name;
  1567. this.data = data;
  1568. this.sea3d = sea3d;
  1569. var layerCount = data.readUByte();
  1570. this.layer = [];
  1571. for ( var i = 0; i < layerCount; i ++ ) {
  1572. this.layer[ i ] = new SEA3DSDK.Composite.prototype.Layer( data, sea3d );
  1573. }
  1574. };
  1575. SEA3DSDK.Composite.prototype.getLayerByName = function ( name ) {
  1576. for ( var i = 0; i < this.layer.length; i ++ ) {
  1577. if ( this.layer[ i ].name === name ) {
  1578. return this.layer[ i ];
  1579. }
  1580. }
  1581. };
  1582. SEA3DSDK.Composite.prototype.Layer = function ( data, sea3d ) {
  1583. var attrib = data.readUShort();
  1584. if ( attrib & 1 ) this.texture = new SEA3DSDK.Composite.LayerBitmap( data, sea3d );
  1585. else this.color = data.readUInt24();
  1586. if ( attrib & 2 ) {
  1587. this.mask = new SEA3DSDK.Composite.LayerBitmap( data, sea3d );
  1588. }
  1589. if ( attrib & 4 ) {
  1590. this.name = data.readUTF8Tiny();
  1591. }
  1592. this.blendMode = attrib & 8 ? data.readBlendMode() : "normal";
  1593. this.opacity = attrib & 16 ? data.readFloat() : 1;
  1594. };
  1595. SEA3DSDK.Composite.LayerBitmap = function ( data, sea3d ) {
  1596. this.map = sea3d.getObject( data.readUInt() );
  1597. var attrib = data.readUShort();
  1598. this.channel = attrib & 1 ? data.readUByte() : 0;
  1599. this.repeat = attrib & 2 === 0;
  1600. this.offsetU = attrib & 4 ? data.readFloat() : 0;
  1601. this.offsetV = attrib & 8 ? data.readFloat() : 0;
  1602. this.scaleU = attrib & 16 ? data.readFloat() : 1;
  1603. this.scaleV = attrib & 32 ? data.readFloat() : 1;
  1604. this.rotation = attrib & 64 ? data.readFloat() : 0;
  1605. if ( attrib & 128 ) this.animation = data.readAnimationList( sea3d );
  1606. };
  1607. SEA3DSDK.Composite.prototype.type = "ctex";
  1608. //
  1609. // Planar Render
  1610. //
  1611. SEA3DSDK.PlanarRender = function ( name, data, sea3d ) {
  1612. this.name = name;
  1613. this.data = data;
  1614. this.sea3d = sea3d;
  1615. this.attrib = data.readUByte();
  1616. this.quality = ( this.attrib & 1 ) | ( this.attrib & 2 );
  1617. this.transform = data.readMatrix();
  1618. };
  1619. SEA3DSDK.PlanarRender.prototype.type = "rttp";
  1620. //
  1621. // Cube Render
  1622. //
  1623. SEA3DSDK.CubeRender = function ( name, data, sea3d ) {
  1624. this.name = name;
  1625. this.data = data;
  1626. this.sea3d = sea3d;
  1627. this.attrib = data.readUByte();
  1628. this.quality = ( this.attrib & 1 ) | ( this.attrib & 2 );
  1629. this.position = data.readVector3();
  1630. };
  1631. SEA3DSDK.CubeRender.prototype.type = "rttc";
  1632. //
  1633. // Cube Maps
  1634. //
  1635. SEA3DSDK.CubeMap = function ( name, data, sea3d ) {
  1636. this.name = name;
  1637. this.data = data;
  1638. this.sea3d = sea3d;
  1639. this.transparent = false;
  1640. this.extension = data.readExt();
  1641. this.faces = [];
  1642. for ( var i = 0; i < 6; i ++ ) {
  1643. var size = data.readUInt();
  1644. this.faces[ i ] = data.concat( data.position, size );
  1645. data.position += size;
  1646. }
  1647. };
  1648. SEA3DSDK.CubeMap.prototype.type = "cmap";
  1649. //
  1650. // JPEG
  1651. //
  1652. SEA3DSDK.JPEG = function ( name, data, sea3d ) {
  1653. this.name = name;
  1654. this.data = data;
  1655. this.sea3d = sea3d;
  1656. this.transparent = false;
  1657. };
  1658. SEA3DSDK.JPEG.prototype.type = "jpg";
  1659. //
  1660. // JPEG_XR
  1661. //
  1662. SEA3DSDK.JPEG_XR = function ( name, data, sea3d ) {
  1663. this.name = name;
  1664. this.data = data;
  1665. this.sea3d = sea3d;
  1666. this.transparent = true;
  1667. };
  1668. SEA3DSDK.JPEG_XR.prototype.type = "wdp";
  1669. //
  1670. // PNG
  1671. //
  1672. SEA3DSDK.PNG = function ( name, data, sea3d ) {
  1673. this.name = name;
  1674. this.data = data;
  1675. this.sea3d = sea3d;
  1676. this.transparent = data.getByte( 25 ) === 0x06;
  1677. };
  1678. SEA3DSDK.PNG.prototype.type = "png";
  1679. //
  1680. // GIF
  1681. //
  1682. SEA3DSDK.GIF = function ( name, data, sea3d ) {
  1683. this.name = name;
  1684. this.data = data;
  1685. this.sea3d = sea3d;
  1686. this.transparent = data.getByte( 11 ) > 0;
  1687. };
  1688. SEA3DSDK.GIF.prototype.type = "gif";
  1689. //
  1690. // OGG
  1691. //
  1692. SEA3DSDK.OGG = function ( name, data, sea3d ) {
  1693. this.name = name;
  1694. this.data = data;
  1695. this.sea3d = sea3d;
  1696. };
  1697. SEA3DSDK.OGG.prototype.type = "ogg";
  1698. //
  1699. // MP3
  1700. //
  1701. SEA3DSDK.MP3 = function ( name, data, sea3d ) {
  1702. this.name = name;
  1703. this.data = data;
  1704. this.sea3d = sea3d;
  1705. };
  1706. SEA3DSDK.MP3.prototype.type = "mp3";
  1707. //
  1708. // Asset Update
  1709. //
  1710. SEA3DSDK.AssetUpdate = function ( name, data, sea3d ) {
  1711. this.name = name;
  1712. this.data = data;
  1713. this.sea3d = sea3d;
  1714. this.index = data.readUInt();
  1715. this.bytes = data.concat( data.position, data.length - data.position );
  1716. };
  1717. SEA3DSDK.AssetUpdate.prototype.type = "upDt";
  1718. //
  1719. // FILE FORMAT
  1720. //
  1721. SEA3DSDK.File = function ( config ) {
  1722. this.config = {
  1723. streaming: true,
  1724. timeLimit: 60,
  1725. progressive: false
  1726. };
  1727. if ( config ) {
  1728. if ( config.streaming !== undefined ) this.config.streaming = config.streaming;
  1729. if ( config.timeLimit !== undefined ) this.config.timeLimit = config.timeLimit;
  1730. if ( config.progressive !== undefined ) this.config.progressive = config.progressive;
  1731. if ( config.path !== undefined ) this.config.path = config.path;
  1732. }
  1733. this.version = SEA3DSDK.VERSION;
  1734. this.objects = [];
  1735. this.typeClass = {};
  1736. this.typeRead = {};
  1737. this.typeUnique = {};
  1738. this.position =
  1739. this.dataPosition = 0;
  1740. this.scope = this;
  1741. // SEA3D
  1742. this.addClass( SEA3DSDK.FileInfo, true );
  1743. this.addClass( SEA3DSDK.Geometry, true );
  1744. this.addClass( SEA3DSDK.Mesh );
  1745. this.addClass( SEA3DSDK.Sprite );
  1746. this.addClass( SEA3DSDK.Material );
  1747. this.addClass( SEA3DSDK.Composite );
  1748. this.addClass( SEA3DSDK.PointLight );
  1749. this.addClass( SEA3DSDK.DirectionalLight );
  1750. this.addClass( SEA3DSDK.HemisphereLight );
  1751. this.addClass( SEA3DSDK.AmbientLight );
  1752. this.addClass( SEA3DSDK.Animation, true );
  1753. this.addClass( SEA3DSDK.Skeleton, true );
  1754. this.addClass( SEA3DSDK.SkeletonLocal, true );
  1755. this.addClass( SEA3DSDK.SkeletonAnimation, true );
  1756. this.addClass( SEA3DSDK.UVWAnimation, true );
  1757. this.addClass( SEA3DSDK.JointObject );
  1758. this.addClass( SEA3DSDK.Camera );
  1759. this.addClass( SEA3DSDK.OrthographicCamera );
  1760. this.addClass( SEA3DSDK.Morph, true );
  1761. this.addClass( SEA3DSDK.MorphAnimation, true );
  1762. this.addClass( SEA3DSDK.VertexAnimation, true );
  1763. this.addClass( SEA3DSDK.CubeMap, true );
  1764. this.addClass( SEA3DSDK.Dummy );
  1765. this.addClass( SEA3DSDK.Line );
  1766. this.addClass( SEA3DSDK.SoundPoint );
  1767. this.addClass( SEA3DSDK.PlanarRender );
  1768. this.addClass( SEA3DSDK.CubeRender );
  1769. this.addClass( SEA3DSDK.Actions );
  1770. this.addClass( SEA3DSDK.Container3D );
  1771. this.addClass( SEA3DSDK.Properties );
  1772. // URL BASED
  1773. this.addClass( SEA3DSDK.ScriptURL, true );
  1774. this.addClass( SEA3DSDK.TextureURL, true );
  1775. this.addClass( SEA3DSDK.CubeMapURL, true );
  1776. // UNIVERSAL
  1777. this.addClass( SEA3DSDK.JPEG, true );
  1778. this.addClass( SEA3DSDK.JPEG_XR, true );
  1779. this.addClass( SEA3DSDK.PNG, true );
  1780. this.addClass( SEA3DSDK.GIF, true );
  1781. this.addClass( SEA3DSDK.OGG, true );
  1782. this.addClass( SEA3DSDK.MP3, true );
  1783. this.addClass( SEA3DSDK.JavaScript, true );
  1784. this.addClass( SEA3DSDK.JavaScriptMethod, true );
  1785. this.addClass( SEA3DSDK.GLSL, true );
  1786. // UPDATER
  1787. this.addClass( SEA3DSDK.AssetUpdate, true );
  1788. // EXTENSION
  1789. var i = SEA3DSDK.File.Extensions.length;
  1790. while ( i -- ) {
  1791. SEA3DSDK.File.Extensions[ i ].call( this );
  1792. }
  1793. };
  1794. SEA3DSDK.File.Extensions = [];
  1795. SEA3DSDK.File.CompressionLibs = {};
  1796. SEA3DSDK.File.DecompressionMethod = {};
  1797. SEA3DSDK.File.setExtension = function ( callback ) {
  1798. SEA3DSDK.File.Extensions.push( callback );
  1799. };
  1800. SEA3DSDK.File.setDecompressionEngine = function ( id, name, method ) {
  1801. SEA3DSDK.File.CompressionLibs[ id ] = name;
  1802. SEA3DSDK.File.DecompressionMethod[ id ] = method;
  1803. };
  1804. SEA3DSDK.File.prototype.addClass = function ( clazz, unique ) {
  1805. this.typeClass[ clazz.prototype.type ] = clazz;
  1806. this.typeUnique[ clazz.prototype.type ] = unique === true;
  1807. };
  1808. SEA3DSDK.File.prototype.readHead = function () {
  1809. if ( this.stream.bytesAvailable < 16 )
  1810. return false;
  1811. if ( this.stream.readUTF8( 3 ) != "SEA" )
  1812. throw new Error( "Invalid SEA3D format." );
  1813. this.sign = this.stream.readUTF8( 3 );
  1814. this.version = this.stream.readUInt24();
  1815. if ( this.stream.readUByte() != 0 ) {
  1816. throw new Error( "Protection algorithm not compatible." );
  1817. }
  1818. this.compressionID = this.stream.readUByte();
  1819. this.compressionAlgorithm = SEA3DSDK.File.CompressionLibs[ this.compressionID ];
  1820. this.decompressionMethod = SEA3DSDK.File.DecompressionMethod[ this.compressionID ];
  1821. if ( this.compressionID > 0 && ! this.decompressionMethod ) {
  1822. throw new Error( "Compression algorithm not compatible." );
  1823. }
  1824. this.length = this.stream.readUInt();
  1825. this.dataPosition = this.stream.position;
  1826. this.objects.length = 0;
  1827. this.state = this.readBody;
  1828. if ( this.onHead ) {
  1829. this.onHead( {
  1830. file: this,
  1831. sign: this.sign
  1832. } );
  1833. }
  1834. return true;
  1835. };
  1836. SEA3DSDK.File.prototype.getObject = function ( index ) {
  1837. return this.objects[ index ];
  1838. };
  1839. SEA3DSDK.File.prototype.getObjectIndex = function ( name ) {
  1840. return this.objects[ name ].index;
  1841. };
  1842. SEA3DSDK.File.prototype.getObjectByName = function ( name ) {
  1843. return this.getObject( this.getObjectIndex( name ) );
  1844. };
  1845. SEA3DSDK.File.prototype.readSEAObject = function () {
  1846. if ( this.stream.bytesAvailable < 4 )
  1847. return null;
  1848. var size = this.stream.readUInt(),
  1849. position = this.stream.position;
  1850. if ( this.stream.bytesAvailable < size )
  1851. return null;
  1852. var flag = this.stream.readUByte(),
  1853. type = this.stream.readExt(),
  1854. meta = null;
  1855. var name = flag & 1 ? this.stream.readUTF8Tiny() : "",
  1856. compressed = ( flag & 2 ) != 0,
  1857. streaming = ( flag & 4 ) != 0;
  1858. if ( flag & 8 ) {
  1859. var metalen = this.stream.readUShort();
  1860. var metabytes = this.stream.concat( this.stream.position, metalen );
  1861. this.stream.position += metalen;
  1862. if ( compressed && this.decompressionMethod ) {
  1863. metabytes.buffer = this.decompressionMethod( metabytes.buffer );
  1864. }
  1865. meta = metabytes.readProperties( this );
  1866. }
  1867. size -= this.stream.position - position;
  1868. position = this.stream.position;
  1869. var data = this.stream.concat( position, size ),
  1870. obj;
  1871. if ( this.typeClass[ type ] ) {
  1872. if ( compressed && this.decompressionMethod ) {
  1873. data.buffer = this.decompressionMethod( data.buffer );
  1874. }
  1875. obj = new this.typeClass[ type ]( name, data, this );
  1876. if ( ( this.config.streaming && streaming || this.config.forceStreaming ) && this.typeRead[ type ] ) {
  1877. this.typeRead[ type ].call( this.scope, obj );
  1878. }
  1879. } else {
  1880. obj = new SEA3DSDK.Object( name, data, type, this );
  1881. console.warn( "SEA3D: Unknown format \"" + type + "\" of file \"" + name + "\". Add a module referring for this format." );
  1882. }
  1883. obj.index = this.objects.length;
  1884. obj.streaming = streaming;
  1885. obj.metadata = meta;
  1886. this.objects.push( this.objects[ obj.name + "." + obj.type ] = obj );
  1887. this.dataPosition = position + size;
  1888. ++ this.position;
  1889. return obj;
  1890. };
  1891. SEA3DSDK.File.prototype.isDone = function () {
  1892. return this.position === this.length;
  1893. };
  1894. SEA3DSDK.File.prototype.readBody = function () {
  1895. this.timer.update();
  1896. if ( ! this.resume ) return false;
  1897. while ( this.position < this.length ) {
  1898. if ( this.timer.deltaTime < this.config.timeLimit ) {
  1899. this.stream.position = this.dataPosition;
  1900. var sea = this.readSEAObject();
  1901. if ( sea ) this.dispatchCompleteObject( sea );
  1902. else return false;
  1903. } else return false;
  1904. }
  1905. this.state = this.readComplete;
  1906. return true;
  1907. };
  1908. SEA3DSDK.File.prototype.initParse = function () {
  1909. this.timer = new SEA3DSDK.Timer();
  1910. this.position = 0;
  1911. this.resume = true;
  1912. };
  1913. SEA3DSDK.File.prototype.parse = function () {
  1914. this.initParse();
  1915. if ( isFinite( this.config.timeLimit ) ) requestAnimationFrame( this.parseObject.bind( this ) );
  1916. else this.parseObject();
  1917. };
  1918. SEA3DSDK.File.prototype.parseObject = function () {
  1919. this.timer.update();
  1920. while ( this.position < this.length && this.timer.deltaTime < this.config.timeLimit ) {
  1921. var obj = this.objects[ this.position ++ ],
  1922. type = obj.type;
  1923. if ( ! this.typeUnique[ type ] ) delete obj.tag;
  1924. if ( ( obj.streaming || this.config.forceStreaming ) && this.typeRead[ type ] ) {
  1925. if ( obj.tag === undefined ) {
  1926. this.typeRead[ type ].call( this.scope, obj );
  1927. }
  1928. }
  1929. }
  1930. if ( this.position === this.length ) {
  1931. var elapsedTime = this.timer.elapsedTime;
  1932. var message = elapsedTime + "ms, " + this.objects.length + " objects";
  1933. if ( this.onParseComplete ) {
  1934. this.onParseComplete( {
  1935. file: this,
  1936. timeTotal: elapsedTime,
  1937. message: message
  1938. } );
  1939. } else console.log( "SEA3D Parse Complete:", message );
  1940. } else {
  1941. if ( this.onParseProgress ) {
  1942. this.onParseProgress( {
  1943. file: this,
  1944. loaded: this.position,
  1945. total: this.length
  1946. } );
  1947. }
  1948. setTimeout( this.parseObject.bind( this ), 10 );
  1949. }
  1950. };
  1951. SEA3DSDK.File.prototype.readComplete = function () {
  1952. this.stream.position = this.dataPosition;
  1953. if ( this.stream.readUInt24F() != 0x5EA3D1 )
  1954. console.warn( "SEA3D file is corrupted." );
  1955. delete this.state;
  1956. return false;
  1957. };
  1958. SEA3DSDK.File.prototype.readState = function () {
  1959. while ( this.state() ) continue;
  1960. if ( this.state ) {
  1961. requestAnimationFrame( this.readState.bind( this ) );
  1962. this.dispatchProgress();
  1963. } else {
  1964. this.dispatchComplete();
  1965. }
  1966. };
  1967. SEA3DSDK.File.prototype.append = function( buffer ) {
  1968. if (this.state) {
  1969. this.stream.append( buffer );
  1970. } else {
  1971. this.read( buffer );
  1972. }
  1973. };
  1974. SEA3DSDK.File.prototype.read = function ( buffer ) {
  1975. if ( ! buffer ) throw new Error( "No data found." );
  1976. this.initParse();
  1977. this.stream = new SEA3DSDK.Stream( buffer );
  1978. this.state = this.readHead;
  1979. this.readState();
  1980. };
  1981. SEA3DSDK.File.prototype.dispatchCompleteObject = function ( obj ) {
  1982. if ( ! this.onCompleteObject ) return;
  1983. this.onCompleteObject( {
  1984. file: this,
  1985. object: obj
  1986. } );
  1987. };
  1988. SEA3DSDK.File.prototype.dispatchProgress = function () {
  1989. if ( ! this.onProgress ) return;
  1990. this.onProgress( {
  1991. file: this,
  1992. loaded: this.position,
  1993. total: this.length
  1994. } );
  1995. };
  1996. SEA3DSDK.File.prototype.dispatchDownloadProgress = function ( position, length ) {
  1997. if ( ! this.onDownloadProgress ) return;
  1998. this.onDownloadProgress( {
  1999. file: this,
  2000. loaded: position,
  2001. total: length
  2002. } );
  2003. };
  2004. SEA3DSDK.File.prototype.dispatchComplete = function () {
  2005. var elapsedTime = this.timer.elapsedTime;
  2006. var message = elapsedTime + "ms, " + this.objects.length + " objects";
  2007. if ( this.onComplete ) this.onComplete( {
  2008. file: this,
  2009. timeTotal: elapsedTime,
  2010. message: message
  2011. } );
  2012. else console.log( "SEA3D:", message );
  2013. };
  2014. SEA3DSDK.File.prototype.dispatchError = function ( id, message ) {
  2015. if ( this.onError ) this.onError( { file: this, id: id, message: message } );
  2016. else console.error( "SEA3D: #" + id, message );
  2017. };
  2018. SEA3DSDK.File.prototype.extractUrlBase = function ( url ) {
  2019. var parts = url.split( '/' );
  2020. if ( parts.length === 1 ) return './';
  2021. parts.pop();
  2022. return parts.join( '/' ) + '/';
  2023. };
  2024. SEA3DSDK.File.prototype.load = function ( url ) {
  2025. var self = this,
  2026. xhr = new XMLHttpRequest();
  2027. xhr.open( "GET", url, true );
  2028. if (!this.config.path) {
  2029. this.config.path = this.extractUrlBase( url );
  2030. }
  2031. if ( self.config.progressive ) {
  2032. var position = 0;
  2033. xhr.overrideMimeType( 'text/plain; charset=x-user-defined' );
  2034. } else {
  2035. xhr.responseType = 'arraybuffer';
  2036. }
  2037. xhr.onprogress = function ( e ) {
  2038. if ( self.config.progressive ) {
  2039. var binStr = xhr.responseText.substring( position ),
  2040. bytes = new Uint8Array( binStr.length );
  2041. for ( var i = 0; i < binStr.length; i ++ ) {
  2042. bytes[ i ] = binStr.charCodeAt( i ) & 0xFF;
  2043. }
  2044. position += binStr.length;
  2045. self.append( bytes.buffer );
  2046. }
  2047. self.dispatchDownloadProgress( e.loaded, e.total );
  2048. };
  2049. if ( ! self.config.progressive ) {
  2050. xhr.onreadystatechange = function () {
  2051. if ( xhr.readyState === 4 ) {
  2052. if ( xhr.status === 200 || xhr.status === 0 ) {
  2053. self.read( this.response );
  2054. } else {
  2055. this.dispatchError( 1001, "Couldn't load [" + url + "] [" + xhr.status + "]" );
  2056. }
  2057. }
  2058. };
  2059. }
  2060. xhr.send();
  2061. };
  2062. export { SEA3DSDK };