LWO3Parser.js 9.5 KB

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