LWO3Parser.js 9.5 KB

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