TDSLoader.js 24 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124
  1. import {
  2. AdditiveBlending,
  3. BufferGeometry,
  4. Color,
  5. DoubleSide,
  6. FileLoader,
  7. Float32BufferAttribute,
  8. Group,
  9. Loader,
  10. LoaderUtils,
  11. Matrix4,
  12. Mesh,
  13. MeshPhongMaterial,
  14. TextureLoader
  15. } from 'three';
  16. /**
  17. * Autodesk 3DS three.js file loader, based on lib3ds.
  18. *
  19. * Loads geometry with uv and materials basic properties with texture support.
  20. *
  21. * @class TDSLoader
  22. * @constructor
  23. */
  24. class TDSLoader extends Loader {
  25. constructor( manager ) {
  26. super( manager );
  27. this.debug = false;
  28. this.group = null;
  29. this.materials = [];
  30. this.meshes = [];
  31. }
  32. /**
  33. * Load 3ds file from url.
  34. *
  35. * @method load
  36. * @param {[type]} url URL for the file.
  37. * @param {Function} onLoad onLoad callback, receives group Object3D as argument.
  38. * @param {Function} onProgress onProgress callback.
  39. * @param {Function} onError onError callback.
  40. */
  41. load( url, onLoad, onProgress, onError ) {
  42. const scope = this;
  43. const path = ( this.path === '' ) ? LoaderUtils.extractUrlBase( url ) : this.path;
  44. const loader = new FileLoader( this.manager );
  45. loader.setPath( this.path );
  46. loader.setResponseType( 'arraybuffer' );
  47. loader.setRequestHeader( this.requestHeader );
  48. loader.setWithCredentials( this.withCredentials );
  49. loader.load( url, function ( data ) {
  50. try {
  51. onLoad( scope.parse( data, path ) );
  52. } catch ( e ) {
  53. if ( onError ) {
  54. onError( e );
  55. } else {
  56. console.error( e );
  57. }
  58. scope.manager.itemError( url );
  59. }
  60. }, onProgress, onError );
  61. }
  62. /**
  63. * Parse arraybuffer data and load 3ds file.
  64. *
  65. * @method parse
  66. * @param {ArrayBuffer} arraybuffer Arraybuffer data to be loaded.
  67. * @param {String} path Path for external resources.
  68. * @return {Group} Group loaded from 3ds file.
  69. */
  70. parse( arraybuffer, path ) {
  71. this.group = new Group();
  72. this.materials = [];
  73. this.meshes = [];
  74. this.readFile( arraybuffer, path );
  75. for ( let i = 0; i < this.meshes.length; i ++ ) {
  76. this.group.add( this.meshes[ i ] );
  77. }
  78. return this.group;
  79. }
  80. /**
  81. * Decode file content to read 3ds data.
  82. *
  83. * @method readFile
  84. * @param {ArrayBuffer} arraybuffer Arraybuffer data to be loaded.
  85. * @param {String} path Path for external resources.
  86. */
  87. readFile( arraybuffer, path ) {
  88. const data = new DataView( arraybuffer );
  89. const chunk = new Chunk( data, 0, this.debugMessage );
  90. if ( chunk.id === MLIBMAGIC || chunk.id === CMAGIC || chunk.id === M3DMAGIC ) {
  91. let next = chunk.readChunk();
  92. while ( next ) {
  93. if ( next.id === M3D_VERSION ) {
  94. const version = next.readDWord();
  95. this.debugMessage( '3DS file version: ' + version );
  96. } else if ( next.id === MDATA ) {
  97. this.readMeshData( next, path );
  98. } else {
  99. this.debugMessage( 'Unknown main chunk: ' + next.hexId );
  100. }
  101. next = chunk.readChunk();
  102. }
  103. }
  104. this.debugMessage( 'Parsed ' + this.meshes.length + ' meshes' );
  105. }
  106. /**
  107. * Read mesh data chunk.
  108. *
  109. * @method readMeshData
  110. * @param {Chunk} chunk to read mesh from
  111. * @param {String} path Path for external resources.
  112. */
  113. readMeshData( chunk, path ) {
  114. let next = chunk.readChunk();
  115. while ( next ) {
  116. if ( next.id === MESH_VERSION ) {
  117. const version = + next.readDWord();
  118. this.debugMessage( 'Mesh Version: ' + version );
  119. } else if ( next.id === MASTER_SCALE ) {
  120. const scale = next.readFloat();
  121. this.debugMessage( 'Master scale: ' + scale );
  122. this.group.scale.set( scale, scale, scale );
  123. } else if ( next.id === NAMED_OBJECT ) {
  124. this.debugMessage( 'Named Object' );
  125. this.readNamedObject( next );
  126. } else if ( next.id === MAT_ENTRY ) {
  127. this.debugMessage( 'Material' );
  128. this.readMaterialEntry( next, path );
  129. } else {
  130. this.debugMessage( 'Unknown MDATA chunk: ' + next.hexId );
  131. }
  132. next = chunk.readChunk();
  133. }
  134. }
  135. /**
  136. * Read named object chunk.
  137. *
  138. * @method readNamedObject
  139. * @param {Chunk} chunk Chunk in use.
  140. */
  141. readNamedObject( chunk ) {
  142. const name = chunk.readString();
  143. let next = chunk.readChunk();
  144. while ( next ) {
  145. if ( next.id === N_TRI_OBJECT ) {
  146. const mesh = this.readMesh( next );
  147. mesh.name = name;
  148. this.meshes.push( mesh );
  149. } else {
  150. this.debugMessage( 'Unknown named object chunk: ' + next.hexId );
  151. }
  152. next = chunk.readChunk( );
  153. }
  154. }
  155. /**
  156. * Read material data chunk and add it to the material list.
  157. *
  158. * @method readMaterialEntry
  159. * @param {Chunk} chunk Chunk in use.
  160. * @param {String} path Path for external resources.
  161. */
  162. readMaterialEntry( chunk, path ) {
  163. let next = chunk.readChunk();
  164. const material = new MeshPhongMaterial();
  165. while ( next ) {
  166. if ( next.id === MAT_NAME ) {
  167. material.name = next.readString();
  168. this.debugMessage( ' Name: ' + material.name );
  169. } else if ( next.id === MAT_WIRE ) {
  170. this.debugMessage( ' Wireframe' );
  171. material.wireframe = true;
  172. } else if ( next.id === MAT_WIRE_SIZE ) {
  173. const value = next.readByte();
  174. material.wireframeLinewidth = value;
  175. this.debugMessage( ' Wireframe Thickness: ' + value );
  176. } else if ( next.id === MAT_TWO_SIDE ) {
  177. material.side = DoubleSide;
  178. this.debugMessage( ' DoubleSided' );
  179. } else if ( next.id === MAT_ADDITIVE ) {
  180. this.debugMessage( ' Additive Blending' );
  181. material.blending = AdditiveBlending;
  182. } else if ( next.id === MAT_DIFFUSE ) {
  183. this.debugMessage( ' Diffuse Color' );
  184. material.color = this.readColor( next );
  185. } else if ( next.id === MAT_SPECULAR ) {
  186. this.debugMessage( ' Specular Color' );
  187. material.specular = this.readColor( next );
  188. } else if ( next.id === MAT_AMBIENT ) {
  189. this.debugMessage( ' Ambient color' );
  190. material.color = this.readColor( next );
  191. } else if ( next.id === MAT_SHININESS ) {
  192. const shininess = this.readPercentage( next );
  193. material.shininess = shininess * 100;
  194. this.debugMessage( ' Shininess : ' + shininess );
  195. } else if ( next.id === MAT_TRANSPARENCY ) {
  196. const transparency = this.readPercentage( next );
  197. material.opacity = 1 - transparency;
  198. this.debugMessage( ' Transparency : ' + transparency );
  199. material.transparent = material.opacity < 1 ? true : false;
  200. } else if ( next.id === MAT_TEXMAP ) {
  201. this.debugMessage( ' ColorMap' );
  202. material.map = this.readMap( next, path );
  203. } else if ( next.id === MAT_BUMPMAP ) {
  204. this.debugMessage( ' BumpMap' );
  205. material.bumpMap = this.readMap( next, path );
  206. } else if ( next.id === MAT_OPACMAP ) {
  207. this.debugMessage( ' OpacityMap' );
  208. material.alphaMap = this.readMap( next, path );
  209. } else if ( next.id === MAT_SPECMAP ) {
  210. this.debugMessage( ' SpecularMap' );
  211. material.specularMap = this.readMap( next, path );
  212. } else {
  213. this.debugMessage( ' Unknown material chunk: ' + next.hexId );
  214. }
  215. next = chunk.readChunk();
  216. }
  217. this.materials[ material.name ] = material;
  218. }
  219. /**
  220. * Read mesh data chunk.
  221. *
  222. * @method readMesh
  223. * @param {Chunk} chunk Chunk in use.
  224. * @return {Mesh} The parsed mesh.
  225. */
  226. readMesh( chunk ) {
  227. let next = chunk.readChunk( );
  228. const geometry = new BufferGeometry();
  229. const material = new MeshPhongMaterial();
  230. const mesh = new Mesh( geometry, material );
  231. mesh.name = 'mesh';
  232. while ( next ) {
  233. if ( next.id === POINT_ARRAY ) {
  234. const points = next.readWord( );
  235. this.debugMessage( ' Vertex: ' + points );
  236. //BufferGeometry
  237. const vertices = [];
  238. for ( let i = 0; i < points; i ++ ) {
  239. vertices.push( next.readFloat( ) );
  240. vertices.push( next.readFloat( ) );
  241. vertices.push( next.readFloat( ) );
  242. }
  243. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  244. } else if ( next.id === FACE_ARRAY ) {
  245. this.readFaceArray( next, mesh );
  246. } else if ( next.id === TEX_VERTS ) {
  247. const texels = next.readWord( );
  248. this.debugMessage( ' UV: ' + texels );
  249. //BufferGeometry
  250. const uvs = [];
  251. for ( let i = 0; i < texels; i ++ ) {
  252. uvs.push( next.readFloat( ) );
  253. uvs.push( next.readFloat( ) );
  254. }
  255. geometry.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  256. } else if ( next.id === MESH_MATRIX ) {
  257. this.debugMessage( ' Tranformation Matrix (TODO)' );
  258. const values = [];
  259. for ( let i = 0; i < 12; i ++ ) {
  260. values[ i ] = next.readFloat( );
  261. }
  262. const matrix = new Matrix4();
  263. //X Line
  264. matrix.elements[ 0 ] = values[ 0 ];
  265. matrix.elements[ 1 ] = values[ 6 ];
  266. matrix.elements[ 2 ] = values[ 3 ];
  267. matrix.elements[ 3 ] = values[ 9 ];
  268. //Y Line
  269. matrix.elements[ 4 ] = values[ 2 ];
  270. matrix.elements[ 5 ] = values[ 8 ];
  271. matrix.elements[ 6 ] = values[ 5 ];
  272. matrix.elements[ 7 ] = values[ 11 ];
  273. //Z Line
  274. matrix.elements[ 8 ] = values[ 1 ];
  275. matrix.elements[ 9 ] = values[ 7 ];
  276. matrix.elements[ 10 ] = values[ 4 ];
  277. matrix.elements[ 11 ] = values[ 10 ];
  278. //W Line
  279. matrix.elements[ 12 ] = 0;
  280. matrix.elements[ 13 ] = 0;
  281. matrix.elements[ 14 ] = 0;
  282. matrix.elements[ 15 ] = 1;
  283. matrix.transpose();
  284. const inverse = new Matrix4();
  285. inverse.copy( matrix ).invert();
  286. geometry.applyMatrix4( inverse );
  287. matrix.decompose( mesh.position, mesh.quaternion, mesh.scale );
  288. } else {
  289. this.debugMessage( ' Unknown mesh chunk: ' + next.hexId );
  290. }
  291. next = chunk.readChunk( );
  292. }
  293. geometry.computeVertexNormals();
  294. return mesh;
  295. }
  296. /**
  297. * Read face array data chunk.
  298. *
  299. * @method readFaceArray
  300. * @param {Chunk} chunk Chunk in use.
  301. * @param {Mesh} mesh Mesh to be filled with the data read.
  302. */
  303. readFaceArray( chunk, mesh ) {
  304. const faces = chunk.readWord( );
  305. this.debugMessage( ' Faces: ' + faces );
  306. const index = [];
  307. for ( let i = 0; i < faces; ++ i ) {
  308. index.push( chunk.readWord( ), chunk.readWord( ), chunk.readWord( ) );
  309. chunk.readWord( ); // visibility
  310. }
  311. mesh.geometry.setIndex( index );
  312. //The rest of the FACE_ARRAY chunk is subchunks
  313. let materialIndex = 0;
  314. let start = 0;
  315. while ( ! chunk.endOfChunk ) {
  316. const subchunk = chunk.readChunk( );
  317. if ( subchunk.id === MSH_MAT_GROUP ) {
  318. this.debugMessage( ' Material Group' );
  319. const group = this.readMaterialGroup( subchunk );
  320. const count = group.index.length * 3; // assuming successive indices
  321. mesh.geometry.addGroup( start, count, materialIndex );
  322. start += count;
  323. materialIndex ++;
  324. const material = this.materials[ group.name ];
  325. if ( Array.isArray( mesh.material ) === false ) mesh.material = [];
  326. if ( material !== undefined ) {
  327. mesh.material.push( material );
  328. }
  329. } else {
  330. this.debugMessage( ' Unknown face array chunk: ' + subchunk.hexId );
  331. }
  332. }
  333. if ( mesh.material.length === 1 ) mesh.material = mesh.material[ 0 ]; // for backwards compatibility
  334. }
  335. /**
  336. * Read texture map data chunk.
  337. *
  338. * @method readMap
  339. * @param {Chunk} chunk Chunk in use.
  340. * @param {String} path Path for external resources.
  341. * @return {Texture} Texture read from this data chunk.
  342. */
  343. readMap( chunk, path ) {
  344. let next = chunk.readChunk( );
  345. let texture = {};
  346. const loader = new TextureLoader( this.manager );
  347. loader.setPath( this.resourcePath || path ).setCrossOrigin( this.crossOrigin );
  348. while ( next ) {
  349. if ( next.id === MAT_MAPNAME ) {
  350. const name = next.readString();
  351. texture = loader.load( name );
  352. this.debugMessage( ' File: ' + path + name );
  353. } else if ( next.id === MAT_MAP_UOFFSET ) {
  354. texture.offset.x = next.readFloat( );
  355. this.debugMessage( ' OffsetX: ' + texture.offset.x );
  356. } else if ( next.id === MAT_MAP_VOFFSET ) {
  357. texture.offset.y = next.readFloat( );
  358. this.debugMessage( ' OffsetY: ' + texture.offset.y );
  359. } else if ( next.id === MAT_MAP_USCALE ) {
  360. texture.repeat.x = next.readFloat( );
  361. this.debugMessage( ' RepeatX: ' + texture.repeat.x );
  362. } else if ( next.id === MAT_MAP_VSCALE ) {
  363. texture.repeat.y = next.readFloat( );
  364. this.debugMessage( ' RepeatY: ' + texture.repeat.y );
  365. } else {
  366. this.debugMessage( ' Unknown map chunk: ' + next.hexId );
  367. }
  368. next = chunk.readChunk( );
  369. }
  370. return texture;
  371. }
  372. /**
  373. * Read material group data chunk.
  374. *
  375. * @method readMaterialGroup
  376. * @param {Chunk} chunk Chunk in use.
  377. * @return {Object} Object with name and index of the object.
  378. */
  379. readMaterialGroup( chunk ) {
  380. const name = chunk.readString();
  381. const numFaces = chunk.readWord();
  382. this.debugMessage( ' Name: ' + name );
  383. this.debugMessage( ' Faces: ' + numFaces );
  384. const index = [];
  385. for ( let i = 0; i < numFaces; ++ i ) {
  386. index.push( chunk.readWord( ) );
  387. }
  388. return { name: name, index: index };
  389. }
  390. /**
  391. * Read a color value.
  392. *
  393. * @method readColor
  394. * @param {Chunk} chunk Chunk.
  395. * @return {Color} Color value read..
  396. */
  397. readColor( chunk ) {
  398. const subChunk = chunk.readChunk( );
  399. const color = new Color();
  400. if ( subChunk.id === COLOR_24 || subChunk.id === LIN_COLOR_24 ) {
  401. const r = subChunk.readByte( );
  402. const g = subChunk.readByte( );
  403. const b = subChunk.readByte( );
  404. color.setRGB( r / 255, g / 255, b / 255 );
  405. this.debugMessage( ' Color: ' + color.r + ', ' + color.g + ', ' + color.b );
  406. } else if ( subChunk.id === COLOR_F || subChunk.id === LIN_COLOR_F ) {
  407. const r = subChunk.readFloat( );
  408. const g = subChunk.readFloat( );
  409. const b = subChunk.readFloat( );
  410. color.setRGB( r, g, b );
  411. this.debugMessage( ' Color: ' + color.r + ', ' + color.g + ', ' + color.b );
  412. } else {
  413. this.debugMessage( ' Unknown color chunk: ' + subChunk.hexId );
  414. }
  415. return color;
  416. }
  417. /**
  418. * Read percentage value.
  419. *
  420. * @method readPercentage
  421. * @param {Chunk} chunk Chunk to read data from.
  422. * @return {Number} Data read from the dataview.
  423. */
  424. readPercentage( chunk ) {
  425. const subChunk = chunk.readChunk( );
  426. switch ( subChunk.id ) {
  427. case INT_PERCENTAGE:
  428. return ( subChunk.readShort( ) / 100 );
  429. break;
  430. case FLOAT_PERCENTAGE:
  431. return subChunk.readFloat( );
  432. break;
  433. default:
  434. this.debugMessage( ' Unknown percentage chunk: ' + subChunk.hexId );
  435. return 0;
  436. }
  437. }
  438. /**
  439. * Print debug message to the console.
  440. *
  441. * Is controlled by a flag to show or hide debug messages.
  442. *
  443. * @method debugMessage
  444. * @param {Object} message Debug message to print to the console.
  445. */
  446. debugMessage( message ) {
  447. if ( this.debug ) {
  448. console.log( message );
  449. }
  450. }
  451. }
  452. /** Read data/sub-chunks from chunk */
  453. class Chunk {
  454. /**
  455. * Create a new chunk
  456. *
  457. * @class Chunk
  458. * @param {DataView} data DataView to read from.
  459. * @param {Number} position in data.
  460. * @param {Function} debugMessage logging callback.
  461. */
  462. constructor( data, position, debugMessage ) {
  463. this.data = data;
  464. // the offset to the begin of this chunk
  465. this.offset = position;
  466. // the current reading position
  467. this.position = position;
  468. this.debugMessage = debugMessage;
  469. if ( this.debugMessage instanceof Function ) {
  470. this.debugMessage = function () {};
  471. }
  472. this.id = this.readWord();
  473. this.size = this.readDWord();
  474. this.end = this.offset + this.size;
  475. if ( this.end > data.byteLength ) {
  476. this.debugMessage( 'Bad chunk size for chunk at ' + position );
  477. }
  478. }
  479. /**
  480. * read a sub cchunk.
  481. *
  482. * @method readChunk
  483. * @return {Chunk | null} next sub chunk
  484. */
  485. readChunk() {
  486. if ( this.endOfChunk ) {
  487. return null;
  488. }
  489. try {
  490. const next = new Chunk( this.data, this.position, this.debugMessage );
  491. this.position += next.size;
  492. return next;
  493. } catch ( e ) {
  494. this.debugMessage( 'Unable to read chunk at ' + this.position );
  495. return null;
  496. }
  497. }
  498. /**
  499. * return the ID of this chunk as Hex
  500. *
  501. * @method idToString
  502. * @return {String} hex-string of id
  503. */
  504. get hexId() {
  505. return this.id.toString( 16 );
  506. }
  507. get endOfChunk() {
  508. return this.position >= this.end;
  509. }
  510. /**
  511. * Read byte value.
  512. *
  513. * @method readByte
  514. * @return {Number} Data read from the dataview.
  515. */
  516. readByte() {
  517. const v = this.data.getUint8( this.position, true );
  518. this.position += 1;
  519. return v;
  520. }
  521. /**
  522. * Read 32 bit float value.
  523. *
  524. * @method readFloat
  525. * @return {Number} Data read from the dataview.
  526. */
  527. readFloat() {
  528. try {
  529. const v = this.data.getFloat32( this.position, true );
  530. this.position += 4;
  531. return v;
  532. } catch ( e ) {
  533. this.debugMessage( e + ' ' + this.position + ' ' + this.data.byteLength );
  534. return 0;
  535. }
  536. }
  537. /**
  538. * Read 32 bit signed integer value.
  539. *
  540. * @method readInt
  541. * @return {Number} Data read from the dataview.
  542. */
  543. readInt() {
  544. const v = this.data.getInt32( this.position, true );
  545. this.position += 4;
  546. return v;
  547. }
  548. /**
  549. * Read 16 bit signed integer value.
  550. *
  551. * @method readShort
  552. * @return {Number} Data read from the dataview.
  553. */
  554. readShort() {
  555. const v = this.data.getInt16( this.position, true );
  556. this.position += 2;
  557. return v;
  558. }
  559. /**
  560. * Read 64 bit unsigned integer value.
  561. *
  562. * @method readDWord
  563. * @return {Number} Data read from the dataview.
  564. */
  565. readDWord() {
  566. const v = this.data.getUint32( this.position, true );
  567. this.position += 4;
  568. return v;
  569. }
  570. /**
  571. * Read 32 bit unsigned integer value.
  572. *
  573. * @method readWord
  574. * @return {Number} Data read from the dataview.
  575. */
  576. readWord() {
  577. const v = this.data.getUint16( this.position, true );
  578. this.position += 2;
  579. return v;
  580. }
  581. /**
  582. * Read NULL terminated ASCII string value from chunk-pos.
  583. *
  584. * @method readString
  585. * @return {String} Data read from the dataview.
  586. */
  587. readString() {
  588. let s = '';
  589. let c = this.readByte();
  590. while ( c ) {
  591. s += String.fromCharCode( c );
  592. c = this.readByte();
  593. }
  594. return s;
  595. }
  596. }
  597. // const NULL_CHUNK = 0x0000;
  598. const M3DMAGIC = 0x4D4D;
  599. // const SMAGIC = 0x2D2D;
  600. // const LMAGIC = 0x2D3D;
  601. const MLIBMAGIC = 0x3DAA;
  602. // const MATMAGIC = 0x3DFF;
  603. const CMAGIC = 0xC23D;
  604. const M3D_VERSION = 0x0002;
  605. // const M3D_KFVERSION = 0x0005;
  606. const COLOR_F = 0x0010;
  607. const COLOR_24 = 0x0011;
  608. const LIN_COLOR_24 = 0x0012;
  609. const LIN_COLOR_F = 0x0013;
  610. const INT_PERCENTAGE = 0x0030;
  611. const FLOAT_PERCENTAGE = 0x0031;
  612. const MDATA = 0x3D3D;
  613. const MESH_VERSION = 0x3D3E;
  614. const MASTER_SCALE = 0x0100;
  615. // const LO_SHADOW_BIAS = 0x1400;
  616. // const HI_SHADOW_BIAS = 0x1410;
  617. // const SHADOW_MAP_SIZE = 0x1420;
  618. // const SHADOW_SAMPLES = 0x1430;
  619. // const SHADOW_RANGE = 0x1440;
  620. // const SHADOW_FILTER = 0x1450;
  621. // const RAY_BIAS = 0x1460;
  622. // const O_CONSTS = 0x1500;
  623. // const AMBIENT_LIGHT = 0x2100;
  624. // const BIT_MAP = 0x1100;
  625. // const SOLID_BGND = 0x1200;
  626. // const V_GRADIENT = 0x1300;
  627. // const USE_BIT_MAP = 0x1101;
  628. // const USE_SOLID_BGND = 0x1201;
  629. // const USE_V_GRADIENT = 0x1301;
  630. // const FOG = 0x2200;
  631. // const FOG_BGND = 0x2210;
  632. // const LAYER_FOG = 0x2302;
  633. // const DISTANCE_CUE = 0x2300;
  634. // const DCUE_BGND = 0x2310;
  635. // const USE_FOG = 0x2201;
  636. // const USE_LAYER_FOG = 0x2303;
  637. // const USE_DISTANCE_CUE = 0x2301;
  638. const MAT_ENTRY = 0xAFFF;
  639. const MAT_NAME = 0xA000;
  640. const MAT_AMBIENT = 0xA010;
  641. const MAT_DIFFUSE = 0xA020;
  642. const MAT_SPECULAR = 0xA030;
  643. const MAT_SHININESS = 0xA040;
  644. // const MAT_SHIN2PCT = 0xA041;
  645. const MAT_TRANSPARENCY = 0xA050;
  646. // const MAT_XPFALL = 0xA052;
  647. // const MAT_USE_XPFALL = 0xA240;
  648. // const MAT_REFBLUR = 0xA053;
  649. // const MAT_SHADING = 0xA100;
  650. // const MAT_USE_REFBLUR = 0xA250;
  651. // const MAT_SELF_ILLUM = 0xA084;
  652. const MAT_TWO_SIDE = 0xA081;
  653. // const MAT_DECAL = 0xA082;
  654. const MAT_ADDITIVE = 0xA083;
  655. const MAT_WIRE = 0xA085;
  656. // const MAT_FACEMAP = 0xA088;
  657. // const MAT_TRANSFALLOFF_IN = 0xA08A;
  658. // const MAT_PHONGSOFT = 0xA08C;
  659. // const MAT_WIREABS = 0xA08E;
  660. const MAT_WIRE_SIZE = 0xA087;
  661. const MAT_TEXMAP = 0xA200;
  662. // const MAT_SXP_TEXT_DATA = 0xA320;
  663. // const MAT_TEXMASK = 0xA33E;
  664. // const MAT_SXP_TEXTMASK_DATA = 0xA32A;
  665. // const MAT_TEX2MAP = 0xA33A;
  666. // const MAT_SXP_TEXT2_DATA = 0xA321;
  667. // const MAT_TEX2MASK = 0xA340;
  668. // const MAT_SXP_TEXT2MASK_DATA = 0xA32C;
  669. const MAT_OPACMAP = 0xA210;
  670. // const MAT_SXP_OPAC_DATA = 0xA322;
  671. // const MAT_OPACMASK = 0xA342;
  672. // const MAT_SXP_OPACMASK_DATA = 0xA32E;
  673. const MAT_BUMPMAP = 0xA230;
  674. // const MAT_SXP_BUMP_DATA = 0xA324;
  675. // const MAT_BUMPMASK = 0xA344;
  676. // const MAT_SXP_BUMPMASK_DATA = 0xA330;
  677. const MAT_SPECMAP = 0xA204;
  678. // const MAT_SXP_SPEC_DATA = 0xA325;
  679. // const MAT_SPECMASK = 0xA348;
  680. // const MAT_SXP_SPECMASK_DATA = 0xA332;
  681. // const MAT_SHINMAP = 0xA33C;
  682. // const MAT_SXP_SHIN_DATA = 0xA326;
  683. // const MAT_SHINMASK = 0xA346;
  684. // const MAT_SXP_SHINMASK_DATA = 0xA334;
  685. // const MAT_SELFIMAP = 0xA33D;
  686. // const MAT_SXP_SELFI_DATA = 0xA328;
  687. // const MAT_SELFIMASK = 0xA34A;
  688. // const MAT_SXP_SELFIMASK_DATA = 0xA336;
  689. // const MAT_REFLMAP = 0xA220;
  690. // const MAT_REFLMASK = 0xA34C;
  691. // const MAT_SXP_REFLMASK_DATA = 0xA338;
  692. // const MAT_ACUBIC = 0xA310;
  693. const MAT_MAPNAME = 0xA300;
  694. // const MAT_MAP_TILING = 0xA351;
  695. // const MAT_MAP_TEXBLUR = 0xA353;
  696. const MAT_MAP_USCALE = 0xA354;
  697. const MAT_MAP_VSCALE = 0xA356;
  698. const MAT_MAP_UOFFSET = 0xA358;
  699. const MAT_MAP_VOFFSET = 0xA35A;
  700. // const MAT_MAP_ANG = 0xA35C;
  701. // const MAT_MAP_COL1 = 0xA360;
  702. // const MAT_MAP_COL2 = 0xA362;
  703. // const MAT_MAP_RCOL = 0xA364;
  704. // const MAT_MAP_GCOL = 0xA366;
  705. // const MAT_MAP_BCOL = 0xA368;
  706. const NAMED_OBJECT = 0x4000;
  707. // const N_DIRECT_LIGHT = 0x4600;
  708. // const DL_OFF = 0x4620;
  709. // const DL_OUTER_RANGE = 0x465A;
  710. // const DL_INNER_RANGE = 0x4659;
  711. // const DL_MULTIPLIER = 0x465B;
  712. // const DL_EXCLUDE = 0x4654;
  713. // const DL_ATTENUATE = 0x4625;
  714. // const DL_SPOTLIGHT = 0x4610;
  715. // const DL_SPOT_ROLL = 0x4656;
  716. // const DL_SHADOWED = 0x4630;
  717. // const DL_LOCAL_SHADOW2 = 0x4641;
  718. // const DL_SEE_CONE = 0x4650;
  719. // const DL_SPOT_RECTANGULAR = 0x4651;
  720. // const DL_SPOT_ASPECT = 0x4657;
  721. // const DL_SPOT_PROJECTOR = 0x4653;
  722. // const DL_SPOT_OVERSHOOT = 0x4652;
  723. // const DL_RAY_BIAS = 0x4658;
  724. // const DL_RAYSHAD = 0x4627;
  725. // const N_CAMERA = 0x4700;
  726. // const CAM_SEE_CONE = 0x4710;
  727. // const CAM_RANGES = 0x4720;
  728. // const OBJ_HIDDEN = 0x4010;
  729. // const OBJ_VIS_LOFTER = 0x4011;
  730. // const OBJ_DOESNT_CAST = 0x4012;
  731. // const OBJ_DONT_RECVSHADOW = 0x4017;
  732. // const OBJ_MATTE = 0x4013;
  733. // const OBJ_FAST = 0x4014;
  734. // const OBJ_PROCEDURAL = 0x4015;
  735. // const OBJ_FROZEN = 0x4016;
  736. const N_TRI_OBJECT = 0x4100;
  737. const POINT_ARRAY = 0x4110;
  738. // const POINT_FLAG_ARRAY = 0x4111;
  739. const FACE_ARRAY = 0x4120;
  740. const MSH_MAT_GROUP = 0x4130;
  741. // const SMOOTH_GROUP = 0x4150;
  742. // const MSH_BOXMAP = 0x4190;
  743. const TEX_VERTS = 0x4140;
  744. const MESH_MATRIX = 0x4160;
  745. // const MESH_COLOR = 0x4165;
  746. // const MESH_TEXTURE_INFO = 0x4170;
  747. // const KFDATA = 0xB000;
  748. // const KFHDR = 0xB00A;
  749. // const KFSEG = 0xB008;
  750. // const KFCURTIME = 0xB009;
  751. // const AMBIENT_NODE_TAG = 0xB001;
  752. // const OBJECT_NODE_TAG = 0xB002;
  753. // const CAMERA_NODE_TAG = 0xB003;
  754. // const TARGET_NODE_TAG = 0xB004;
  755. // const LIGHT_NODE_TAG = 0xB005;
  756. // const L_TARGET_NODE_TAG = 0xB006;
  757. // const SPOTLIGHT_NODE_TAG = 0xB007;
  758. // const NODE_ID = 0xB030;
  759. // const NODE_HDR = 0xB010;
  760. // const PIVOT = 0xB013;
  761. // const INSTANCE_NAME = 0xB011;
  762. // const MORPH_SMOOTH = 0xB015;
  763. // const BOUNDBOX = 0xB014;
  764. // const POS_TRACK_TAG = 0xB020;
  765. // const COL_TRACK_TAG = 0xB025;
  766. // const ROT_TRACK_TAG = 0xB021;
  767. // const SCL_TRACK_TAG = 0xB022;
  768. // const MORPH_TRACK_TAG = 0xB026;
  769. // const FOV_TRACK_TAG = 0xB023;
  770. // const ROLL_TRACK_TAG = 0xB024;
  771. // const HOT_TRACK_TAG = 0xB027;
  772. // const FALL_TRACK_TAG = 0xB028;
  773. // const HIDE_TRACK_TAG = 0xB029;
  774. // const POLY_2D = 0x5000;
  775. // const SHAPE_OK = 0x5010;
  776. // const SHAPE_NOT_OK = 0x5011;
  777. // const SHAPE_HOOK = 0x5020;
  778. // const PATH_3D = 0x6000;
  779. // const PATH_MATRIX = 0x6005;
  780. // const SHAPE_2D = 0x6010;
  781. // const M_SCALE = 0x6020;
  782. // const M_TWIST = 0x6030;
  783. // const M_TEETER = 0x6040;
  784. // const M_FIT = 0x6050;
  785. // const M_BEVEL = 0x6060;
  786. // const XZ_CURVE = 0x6070;
  787. // const YZ_CURVE = 0x6080;
  788. // const INTERPCT = 0x6090;
  789. // const DEFORM_LIMIT = 0x60A0;
  790. // const USE_CONTOUR = 0x6100;
  791. // const USE_TWEEN = 0x6110;
  792. // const USE_SCALE = 0x6120;
  793. // const USE_TWIST = 0x6130;
  794. // const USE_TEETER = 0x6140;
  795. // const USE_FIT = 0x6150;
  796. // const USE_BEVEL = 0x6160;
  797. // const DEFAULT_VIEW = 0x3000;
  798. // const VIEW_TOP = 0x3010;
  799. // const VIEW_BOTTOM = 0x3020;
  800. // const VIEW_LEFT = 0x3030;
  801. // const VIEW_RIGHT = 0x3040;
  802. // const VIEW_FRONT = 0x3050;
  803. // const VIEW_BACK = 0x3060;
  804. // const VIEW_USER = 0x3070;
  805. // const VIEW_CAMERA = 0x3080;
  806. // const VIEW_WINDOW = 0x3090;
  807. // const VIEWPORT_LAYOUT_OLD = 0x7000;
  808. // const VIEWPORT_DATA_OLD = 0x7010;
  809. // const VIEWPORT_LAYOUT = 0x7001;
  810. // const VIEWPORT_DATA = 0x7011;
  811. // const VIEWPORT_DATA_3 = 0x7012;
  812. // const VIEWPORT_SIZE = 0x7020;
  813. // const NETWORK_VIEW = 0x7030;
  814. export { TDSLoader };