LWO3Parser.js 9.1 KB

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