TDSLoader.js 24 KB

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