LWO3Parser.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. ( function () {
  2. class LWO3Parser {
  3. constructor( IFFParser ) {
  4. this.IFF = IFFParser;
  5. }
  6. parseBlock() {
  7. this.IFF.debugger.offset = this.IFF.reader.offset;
  8. this.IFF.debugger.closeForms();
  9. const blockID = this.IFF.reader.getIDTag();
  10. const length = this.IFF.reader.getUint32(); // size of data in bytes
  11. this.IFF.debugger.dataOffset = this.IFF.reader.offset;
  12. this.IFF.debugger.length = length;
  13. // Data types may be found in either LWO2 OR LWO3 spec
  14. switch ( blockID ) {
  15. case 'FORM':
  16. // form blocks may consist of sub -chunks or sub-forms
  17. this.IFF.parseForm( length );
  18. break;
  19. // SKIPPED CHUNKS
  20. // MISC skipped
  21. case 'ICON': // Thumbnail Icon Image
  22. case 'VMPA': // Vertex Map Parameter
  23. case 'BBOX': // bounding box
  24. // case 'VMMD':
  25. // case 'VTYP':
  26. // normal maps can be specified, normally on models imported from other applications. Currently ignored
  27. case 'NORM':
  28. // ENVL FORM skipped
  29. case 'PRE ': // Pre-loop behavior for the keyframe
  30. case 'POST': // Post-loop behavior for the keyframe
  31. case 'KEY ':
  32. case 'SPAN':
  33. // CLIP FORM skipped
  34. case 'TIME':
  35. case 'CLRS':
  36. case 'CLRA':
  37. case 'FILT':
  38. case 'DITH':
  39. case 'CONT':
  40. case 'BRIT':
  41. case 'SATR':
  42. case 'HUE ':
  43. case 'GAMM':
  44. case 'NEGA':
  45. case 'IFLT':
  46. case 'PFLT':
  47. // Image Map Layer skipped
  48. case 'PROJ':
  49. case 'AXIS':
  50. case 'AAST':
  51. case 'PIXB':
  52. case 'STCK':
  53. // Procedural Textures skipped
  54. case 'VALU':
  55. // Gradient Textures skipped
  56. case 'PNAM':
  57. case 'INAM':
  58. case 'GRST':
  59. case 'GREN':
  60. case 'GRPT':
  61. case 'FKEY':
  62. case 'IKEY':
  63. // Texture Mapping Form skipped
  64. case 'CSYS':
  65. // Surface CHUNKs skipped
  66. case 'OPAQ': // top level 'opacity' checkbox
  67. case 'CMAP': // clip map
  68. // Surface node CHUNKS skipped
  69. // These mainly specify the node editor setup in LW
  70. case 'NLOC':
  71. case 'NZOM':
  72. case 'NVER':
  73. case 'NSRV':
  74. case 'NCRD':
  75. case 'NMOD':
  76. case 'NSEL':
  77. case 'NPRW':
  78. case 'NPLA':
  79. case 'VERS':
  80. case 'ENUM':
  81. case 'TAG ':
  82. // Car Material CHUNKS
  83. case 'CGMD':
  84. case 'CGTY':
  85. case 'CGST':
  86. case 'CGEN':
  87. case 'CGTS':
  88. case 'CGTE':
  89. case 'OSMP':
  90. case 'OMDE':
  91. case 'OUTR':
  92. case 'FLAG':
  93. case 'TRNL':
  94. case 'SHRP':
  95. case 'RFOP':
  96. case 'RSAN':
  97. case 'TROP':
  98. case 'RBLR':
  99. case 'TBLR':
  100. case 'CLRH':
  101. case 'CLRF':
  102. case 'ADTR':
  103. case 'GLOW':
  104. case 'LINE':
  105. case 'ALPH':
  106. case 'VCOL':
  107. case 'ENAB':
  108. this.IFF.debugger.skipped = true;
  109. this.IFF.reader.skip( length );
  110. break;
  111. // Texture node chunks (not in spec)
  112. case 'IPIX': // usePixelBlending
  113. case 'IMIP': // useMipMaps
  114. case 'IMOD': // imageBlendingMode
  115. case 'AMOD': // unknown
  116. case 'IINV': // imageInvertAlpha
  117. case 'INCR': // imageInvertColor
  118. case 'IAXS': // imageAxis ( for non-UV maps)
  119. case 'IFOT': // imageFallofType
  120. case 'ITIM': // timing for animated textures
  121. case 'IWRL':
  122. case 'IUTI':
  123. case 'IINX':
  124. case 'IINY':
  125. case 'IINZ':
  126. case 'IREF':
  127. // possibly a VX for reused texture nodes
  128. if ( length === 4 ) this.IFF.currentNode[ blockID ] = this.IFF.reader.getInt32(); else this.IFF.reader.skip( length );
  129. break;
  130. case 'OTAG':
  131. this.IFF.parseObjectTag();
  132. break;
  133. case 'LAYR':
  134. this.IFF.parseLayer( length );
  135. break;
  136. case 'PNTS':
  137. this.IFF.parsePoints( length );
  138. break;
  139. case 'VMAP':
  140. this.IFF.parseVertexMapping( length );
  141. break;
  142. case 'POLS':
  143. this.IFF.parsePolygonList( length );
  144. break;
  145. case 'TAGS':
  146. this.IFF.parseTagStrings( length );
  147. break;
  148. case 'PTAG':
  149. this.IFF.parsePolygonTagMapping( length );
  150. break;
  151. case 'VMAD':
  152. this.IFF.parseVertexMapping( length, true );
  153. break;
  154. // Misc CHUNKS
  155. case 'DESC':
  156. // Description Line
  157. this.IFF.currentForm.description = this.IFF.reader.getString();
  158. break;
  159. case 'TEXT':
  160. case 'CMNT':
  161. case 'NCOM':
  162. this.IFF.currentForm.comment = this.IFF.reader.getString();
  163. break;
  164. // Envelope Form
  165. case 'NAME':
  166. this.IFF.currentForm.channelName = this.IFF.reader.getString();
  167. break;
  168. // Image Map Layer
  169. case 'WRAP':
  170. this.IFF.currentForm.wrap = {
  171. w: this.IFF.reader.getUint16(),
  172. h: this.IFF.reader.getUint16()
  173. };
  174. break;
  175. case 'IMAG':
  176. const index = this.IFF.reader.getVariableLengthIndex();
  177. this.IFF.currentForm.imageIndex = index;
  178. break;
  179. // Texture Mapping Form
  180. case 'OREF':
  181. this.IFF.currentForm.referenceObject = this.IFF.reader.getString();
  182. break;
  183. case 'ROID':
  184. this.IFF.currentForm.referenceObjectID = this.IFF.reader.getUint32();
  185. break;
  186. // Surface Blocks
  187. case 'SSHN':
  188. this.IFF.currentSurface.surfaceShaderName = this.IFF.reader.getString();
  189. break;
  190. case 'AOVN':
  191. this.IFF.currentSurface.surfaceCustomAOVName = this.IFF.reader.getString();
  192. break;
  193. // Nodal Blocks
  194. case 'NSTA':
  195. this.IFF.currentForm.disabled = this.IFF.reader.getUint16();
  196. break;
  197. case 'NRNM':
  198. this.IFF.currentForm.realName = this.IFF.reader.getString();
  199. break;
  200. case 'NNME':
  201. this.IFF.currentForm.refName = this.IFF.reader.getString();
  202. this.IFF.currentSurface.nodes[ this.IFF.currentForm.refName ] = this.IFF.currentForm;
  203. break;
  204. // Nodal Blocks : connections
  205. case 'INME':
  206. if ( ! this.IFF.currentForm.nodeName ) this.IFF.currentForm.nodeName = [];
  207. this.IFF.currentForm.nodeName.push( this.IFF.reader.getString() );
  208. break;
  209. case 'IINN':
  210. if ( ! this.IFF.currentForm.inputNodeName ) this.IFF.currentForm.inputNodeName = [];
  211. this.IFF.currentForm.inputNodeName.push( this.IFF.reader.getString() );
  212. break;
  213. case 'IINM':
  214. if ( ! this.IFF.currentForm.inputName ) this.IFF.currentForm.inputName = [];
  215. this.IFF.currentForm.inputName.push( this.IFF.reader.getString() );
  216. break;
  217. case 'IONM':
  218. if ( ! this.IFF.currentForm.inputOutputName ) this.IFF.currentForm.inputOutputName = [];
  219. this.IFF.currentForm.inputOutputName.push( this.IFF.reader.getString() );
  220. break;
  221. case 'FNAM':
  222. this.IFF.currentForm.fileName = this.IFF.reader.getString();
  223. break;
  224. case 'CHAN':
  225. // NOTE: ENVL Forms may also have CHAN chunk, however ENVL is currently ignored
  226. if ( length === 4 ) this.IFF.currentForm.textureChannel = this.IFF.reader.getIDTag(); else this.IFF.reader.skip( length );
  227. break;
  228. // LWO2 Spec chunks: these are needed since the SURF FORMs are often in LWO2 format
  229. case 'SMAN':
  230. const maxSmoothingAngle = this.IFF.reader.getFloat32();
  231. this.IFF.currentSurface.attributes.smooth = maxSmoothingAngle < 0 ? false : true;
  232. break;
  233. // LWO2: Basic Surface Parameters
  234. case 'COLR':
  235. this.IFF.currentSurface.attributes.Color = {
  236. value: this.IFF.reader.getFloat32Array( 3 )
  237. };
  238. this.IFF.reader.skip( 2 ); // VX: envelope
  239. break;
  240. case 'LUMI':
  241. this.IFF.currentSurface.attributes.Luminosity = {
  242. value: this.IFF.reader.getFloat32()
  243. };
  244. this.IFF.reader.skip( 2 );
  245. break;
  246. case 'SPEC':
  247. this.IFF.currentSurface.attributes.Specular = {
  248. value: this.IFF.reader.getFloat32()
  249. };
  250. this.IFF.reader.skip( 2 );
  251. break;
  252. case 'DIFF':
  253. this.IFF.currentSurface.attributes.Diffuse = {
  254. value: this.IFF.reader.getFloat32()
  255. };
  256. this.IFF.reader.skip( 2 );
  257. break;
  258. case 'REFL':
  259. this.IFF.currentSurface.attributes.Reflection = {
  260. value: this.IFF.reader.getFloat32()
  261. };
  262. this.IFF.reader.skip( 2 );
  263. break;
  264. case 'GLOS':
  265. this.IFF.currentSurface.attributes.Glossiness = {
  266. value: this.IFF.reader.getFloat32()
  267. };
  268. this.IFF.reader.skip( 2 );
  269. break;
  270. case 'TRAN':
  271. this.IFF.currentSurface.attributes.opacity = this.IFF.reader.getFloat32();
  272. this.IFF.reader.skip( 2 );
  273. break;
  274. case 'BUMP':
  275. this.IFF.currentSurface.attributes.bumpStrength = this.IFF.reader.getFloat32();
  276. this.IFF.reader.skip( 2 );
  277. break;
  278. case 'SIDE':
  279. this.IFF.currentSurface.attributes.side = this.IFF.reader.getUint16();
  280. break;
  281. case 'RIMG':
  282. this.IFF.currentSurface.attributes.reflectionMap = this.IFF.reader.getVariableLengthIndex();
  283. break;
  284. case 'RIND':
  285. this.IFF.currentSurface.attributes.refractiveIndex = this.IFF.reader.getFloat32();
  286. this.IFF.reader.skip( 2 );
  287. break;
  288. case 'TIMG':
  289. this.IFF.currentSurface.attributes.refractionMap = this.IFF.reader.getVariableLengthIndex();
  290. break;
  291. case 'IMAP':
  292. this.IFF.currentSurface.attributes.imageMapIndex = this.IFF.reader.getUint32();
  293. break;
  294. case 'IUVI':
  295. // uv channel name
  296. this.IFF.currentNode.UVChannel = this.IFF.reader.getString( length );
  297. break;
  298. case 'IUTL':
  299. // widthWrappingMode: 0 = Reset, 1 = Repeat, 2 = Mirror, 3 = Edge
  300. this.IFF.currentNode.widthWrappingMode = this.IFF.reader.getUint32();
  301. break;
  302. case 'IVTL':
  303. // heightWrappingMode
  304. this.IFF.currentNode.heightWrappingMode = this.IFF.reader.getUint32();
  305. break;
  306. default:
  307. this.IFF.parseUnknownCHUNK( blockID, length );
  308. }
  309. if ( blockID != 'FORM' ) {
  310. this.IFF.debugger.node = 1;
  311. this.IFF.debugger.nodeID = blockID;
  312. this.IFF.debugger.log();
  313. }
  314. if ( this.IFF.reader.offset >= this.IFF.currentFormEnd ) {
  315. this.IFF.currentForm = this.IFF.parentForm;
  316. }
  317. }
  318. }
  319. THREE.LWO3Parser = LWO3Parser;
  320. } )();