LWO3Parser.js 9.1 KB

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