LDrawLoader.js 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694
  1. /**
  2. * @author mrdoob / http://mrdoob.com/
  3. * @author yomboprime / https://github.com/yomboprime/
  4. *
  5. *
  6. */
  7. THREE.LDrawLoader = ( function () {
  8. var tempVec0 = new THREE.Vector3();
  9. var tempVec1 = new THREE.Vector3();
  10. function smoothNormals( triangles, lineSegments ) {
  11. function hashVertex( v ) {
  12. var x = ~ ~ ( v.x * 1e6 );
  13. var y = ~ ~ ( v.y * 1e6 );
  14. var z = ~ ~ ( v.z * 1e6 );
  15. return `${ x },${ y },${ z }`;
  16. }
  17. function hashEdge( v0, v1 ) {
  18. return `${ hashVertex( v0 ) }_${ hashVertex( v1 ) }`;
  19. }
  20. var hardEdges = new Set();
  21. var halfEdgeList = {};
  22. var fullHalfEdgeList = {};
  23. var normals = [];
  24. // Save the list of hard edges by hash
  25. for ( var i = 0, l = lineSegments.length; i < l; i ++ ) {
  26. var ls = lineSegments[ i ];
  27. var v0 = ls.v0;
  28. var v1 = ls.v1;
  29. hardEdges.add( hashEdge( v0, v1 ) );
  30. hardEdges.add( hashEdge( v1, v0 ) );
  31. }
  32. // track the half edges associated with each triangle
  33. for ( var i = 0, l = triangles.length; i < l; i ++ ) {
  34. var tri = triangles[ i ];
  35. for ( var i2 = 0, l2 = 3; i2 < l2; i2 ++ ) {
  36. var index = i2;
  37. var next = ( i2 + 1 ) % 3;
  38. var v0 = tri[ `v${ index }` ];
  39. var v1 = tri[ `v${ next }` ];
  40. var hash = hashEdge( v0, v1 );
  41. // don't add the triangle if the edge is supposed to be hard
  42. if ( hardEdges.has( hash ) ) continue;
  43. halfEdgeList[ hash ] = tri;
  44. fullHalfEdgeList[ hash ] = tri;
  45. }
  46. }
  47. // Iterate until we've tried to connect all triangles to share normals
  48. while ( true ) {
  49. // Stop if there are no more triangles left
  50. var halfEdges = Object.keys( halfEdgeList );
  51. if ( halfEdges.length === 0 ) break;
  52. // Exhaustively find all connected triangles
  53. var i = 0;
  54. var queue = [ fullHalfEdgeList[ halfEdges[ 0 ] ] ];
  55. while ( i < queue.length ) {
  56. // initialize all vertex normals in this triangle
  57. var tri = queue[ i ];
  58. i ++;
  59. var faceNormal = tri.faceNormal;
  60. if ( tri.n0 === null ) {
  61. tri.n0 = faceNormal.clone();
  62. normals.push( tri.n0 );
  63. }
  64. if ( tri.n1 === null ) {
  65. tri.n1 = faceNormal.clone();
  66. normals.push( tri.n1 );
  67. }
  68. if ( tri.n2 === null ) {
  69. tri.n2 = faceNormal.clone();
  70. normals.push( tri.n2 );
  71. }
  72. // Check if any edge is connected to another triangle edge
  73. for ( var i2 = 0, l2 = 3; i2 < l2; i2 ++ ) {
  74. var index = i2;
  75. var next = ( i2 + 1 ) % 3;
  76. var v0 = tri[ `v${ index }` ];
  77. var v1 = tri[ `v${ next }` ];
  78. // delete this triangle from the list so it won't be found again
  79. var hash = hashEdge( v0, v1 );
  80. delete halfEdgeList[ hash ];
  81. var reverseHash = hashEdge( v1, v0 );
  82. var otherTri = fullHalfEdgeList[ reverseHash ];
  83. if ( otherTri ) {
  84. // if this triangle has already been traversed then it won't be in
  85. // the halfEdgeList. If it has not then add it to the queue and delete
  86. // it so it won't be found again.
  87. if ( reverseHash in halfEdgeList ) {
  88. queue.push( otherTri );
  89. delete halfEdgeList[ reverseHash ];
  90. }
  91. // Find the matching edge in this triangle and copy the normal vector over
  92. for ( var i3 = 0, l3 = 3; i3 < l3; i3 ++ ) {
  93. var otherIndex = i3;
  94. var otherNext = ( i3 + 1 ) % 3;
  95. var otherV0 = otherTri[ `v${ otherIndex }` ];
  96. var otherV1 = otherTri[ `v${ otherNext }` ];
  97. var otherHash = hashEdge( otherV0, otherV1 );
  98. if ( otherHash === reverseHash ) {
  99. otherTri[ `n${ otherIndex }` ] = tri[ `n${ next }` ];
  100. otherTri[ `n${ otherNext }` ] = tri[ `n${ index }` ];
  101. tri[ `n${ next }` ].add( otherTri.faceNormal );
  102. tri[ `n${ index }` ].add( otherTri.faceNormal );
  103. break;
  104. }
  105. }
  106. }
  107. }
  108. }
  109. }
  110. // The normals of each face have been added up so now we average them by normalizing the vector.
  111. for ( var i = 0, l = normals.length; i < l; i ++ ) {
  112. normals[ i ].normalize();
  113. }
  114. }
  115. function isPrimitiveType( type ) {
  116. return /primitive/i.test( type ) || type === 'Subpart';
  117. }
  118. function LineParser( line, lineNumber ) {
  119. this.line = line;
  120. this.lineLength = line.length;
  121. this.currentCharIndex = 0;
  122. this.currentChar = ' ';
  123. this.lineNumber = lineNumber;
  124. }
  125. LineParser.prototype = {
  126. constructor: LineParser,
  127. seekNonSpace: function () {
  128. while ( this.currentCharIndex < this.lineLength ) {
  129. this.currentChar = this.line.charAt( this.currentCharIndex );
  130. if ( this.currentChar !== ' ' && this.currentChar !== '\t' ) {
  131. return;
  132. }
  133. this.currentCharIndex ++;
  134. }
  135. },
  136. getToken: function () {
  137. var pos0 = this.currentCharIndex ++;
  138. // Seek space
  139. while ( this.currentCharIndex < this.lineLength ) {
  140. this.currentChar = this.line.charAt( this.currentCharIndex );
  141. if ( this.currentChar === ' ' || this.currentChar === '\t' ) {
  142. break;
  143. }
  144. this.currentCharIndex ++;
  145. }
  146. var pos1 = this.currentCharIndex;
  147. this.seekNonSpace();
  148. return this.line.substring( pos0, pos1 );
  149. },
  150. getRemainingString: function () {
  151. return this.line.substring( this.currentCharIndex, this.lineLength );
  152. },
  153. isAtTheEnd: function () {
  154. return this.currentCharIndex >= this.lineLength;
  155. },
  156. setToEnd: function () {
  157. this.currentCharIndex = this.lineLength;
  158. },
  159. getLineNumberString: function () {
  160. return this.lineNumber >= 0 ? " at line " + this.lineNumber : "";
  161. }
  162. };
  163. function sortByMaterial( a, b ) {
  164. if ( a.colourCode === b.colourCode ) {
  165. return 0;
  166. }
  167. if ( a.colourCode < b.colourCode ) {
  168. return - 1;
  169. }
  170. return 1;
  171. }
  172. function createObject( elements, elementSize ) {
  173. // Creates a THREE.LineSegments (elementSize = 2) or a THREE.Mesh (elementSize = 3 )
  174. // With per face / segment material, implemented with mesh groups and materials array
  175. // Sort the triangles or line segments by colour code to make later the mesh groups
  176. elements.sort( sortByMaterial );
  177. var positions = [];
  178. var normals = [];
  179. var materials = [];
  180. var bufferGeometry = new THREE.BufferGeometry();
  181. var prevMaterial = null;
  182. var index0 = 0;
  183. var numGroupVerts = 0;
  184. for ( var iElem = 0, nElem = elements.length; iElem < nElem; iElem ++ ) {
  185. var elem = elements[ iElem ];
  186. var v0 = elem.v0;
  187. var v1 = elem.v1;
  188. // Note that LDraw coordinate system is rotated 180 deg. in the X axis w.r.t. Three.js's one
  189. positions.push( v0.x, v0.y, v0.z, v1.x, v1.y, v1.z );
  190. if ( elementSize === 3 ) {
  191. positions.push( elem.v2.x, elem.v2.y, elem.v2.z );
  192. var n0 = elem.n0 || elem.faceNormal;
  193. var n1 = elem.n1 || elem.faceNormal;
  194. var n2 = elem.n2 || elem.faceNormal;
  195. normals.push( n0.x, n0.y, n0.z );
  196. normals.push( n1.x, n1.y, n1.z );
  197. normals.push( n2.x, n2.y, n2.z );
  198. }
  199. if ( prevMaterial !== elem.material ) {
  200. if ( prevMaterial !== null ) {
  201. bufferGeometry.addGroup( index0, numGroupVerts, materials.length - 1 );
  202. }
  203. materials.push( elem.material );
  204. prevMaterial = elem.material;
  205. index0 = iElem * elementSize;
  206. numGroupVerts = elementSize;
  207. } else {
  208. numGroupVerts += elementSize;
  209. }
  210. }
  211. if ( numGroupVerts > 0 ) {
  212. bufferGeometry.addGroup( index0, Infinity, materials.length - 1 );
  213. }
  214. bufferGeometry.addAttribute( 'position', new THREE.Float32BufferAttribute( positions, 3 ) );
  215. if ( elementSize === 3 ) {
  216. bufferGeometry.addAttribute( 'normal', new THREE.Float32BufferAttribute( normals, 3 ) );
  217. }
  218. var object3d = null;
  219. if ( elementSize === 2 ) {
  220. object3d = new THREE.LineSegments( bufferGeometry, materials );
  221. } else if ( elementSize === 3 ) {
  222. object3d = new THREE.Mesh( bufferGeometry, materials );
  223. }
  224. return object3d;
  225. }
  226. //
  227. function LDrawLoader( manager ) {
  228. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  229. // This is a stack of 'parse scopes' with one level per subobject loaded file.
  230. // Each level contains a material lib and also other runtime variables passed between parent and child subobjects
  231. // When searching for a material code, the stack is read from top of the stack to bottom
  232. // Each material library is an object map keyed by colour codes.
  233. this.parseScopesStack = null;
  234. this.path = '';
  235. // Array of THREE.Material
  236. this.materials = [];
  237. // Not using THREE.Cache here because it returns the previous HTML error response instead of calling onError()
  238. // This also allows to handle the embedded text files ("0 FILE" lines)
  239. this.subobjectCache = {};
  240. // This object is a map from file names to paths. It agilizes the paths search. If it is not set then files will be searched by trial and error.
  241. this.fileMap = null;
  242. // Add default main triangle and line edge materials (used in piecess that can be coloured with a main color)
  243. this.setMaterials( [
  244. this.parseColourMetaDirective( new LineParser( "Main_Colour CODE 16 VALUE #FF8080 EDGE #333333" ) ),
  245. this.parseColourMetaDirective( new LineParser( "Edge_Colour CODE 24 VALUE #A0A0A0 EDGE #333333" ) )
  246. ] );
  247. // If this flag is set to true, each subobject will be a THREE.Object.
  248. // If not (the default), only one object which contains all the merged primitives will be created.
  249. this.separateObjects = false;
  250. }
  251. // Special surface finish tag types.
  252. // Note: "MATERIAL" tag (e.g. GLITTER, SPECKLE) is not implemented
  253. LDrawLoader.FINISH_TYPE_DEFAULT = 0;
  254. LDrawLoader.FINISH_TYPE_CHROME = 1;
  255. LDrawLoader.FINISH_TYPE_PEARLESCENT = 2;
  256. LDrawLoader.FINISH_TYPE_RUBBER = 3;
  257. LDrawLoader.FINISH_TYPE_MATTE_METALLIC = 4;
  258. LDrawLoader.FINISH_TYPE_METAL = 5;
  259. // State machine to search a subobject path.
  260. // The LDraw standard establishes these various possible subfolders.
  261. LDrawLoader.FILE_LOCATION_AS_IS = 0;
  262. LDrawLoader.FILE_LOCATION_TRY_PARTS = 1;
  263. LDrawLoader.FILE_LOCATION_TRY_P = 2;
  264. LDrawLoader.FILE_LOCATION_TRY_MODELS = 3;
  265. LDrawLoader.FILE_LOCATION_TRY_RELATIVE = 4;
  266. LDrawLoader.FILE_LOCATION_TRY_ABSOLUTE = 5;
  267. LDrawLoader.FILE_LOCATION_NOT_FOUND = 6;
  268. LDrawLoader.prototype = {
  269. constructor: LDrawLoader,
  270. load: function ( url, onLoad, onProgress, onError ) {
  271. if ( ! this.fileMap ) {
  272. this.fileMap = {};
  273. }
  274. var scope = this;
  275. var fileLoader = new THREE.FileLoader( this.manager );
  276. fileLoader.setPath( this.path );
  277. fileLoader.load( url, function ( text ) {
  278. processObject( text, onLoad );
  279. }, onProgress, onError );
  280. function processObject( text, onProcessed, subobject ) {
  281. var parseScope = scope.newParseScopeLevel();
  282. parseScope.url = url;
  283. var parentParseScope = scope.getParentParseScope();
  284. // Set current matrix
  285. if ( subobject ) {
  286. parseScope.currentMatrix.multiplyMatrices( parentParseScope.currentMatrix, subobject.matrix );
  287. parseScope.matrix.copy( subobject.matrix );
  288. parseScope.inverted = subobject.inverted;
  289. }
  290. // Add to cache
  291. var currentFileName = parentParseScope.currentFileName;
  292. if ( currentFileName !== null ) {
  293. currentFileName = parentParseScope.currentFileName.toLowerCase();
  294. }
  295. if ( scope.subobjectCache[ currentFileName ] === undefined ) {
  296. scope.subobjectCache[ currentFileName ] = text;
  297. }
  298. // Parse the object (returns a THREE.Group)
  299. scope.parse( text );
  300. var finishedCount = 0;
  301. onSubobjectFinish();
  302. function onSubobjectFinish() {
  303. finishedCount ++;
  304. if ( finishedCount === parseScope.subobjects.length + 1 ) {
  305. finalizeObject();
  306. } else {
  307. // Once the previous subobject has finished we can start processing the next one in the list.
  308. // The subobject processing shares scope in processing so it's important that they be loaded serially
  309. // to avoid race conditions.
  310. // Promise.resolve is used as an approach to asynchronously schedule a task _before_ this frame ends to
  311. // avoid stack overflow exceptions when loading many subobjects from the cache. RequestAnimationFrame
  312. // will work but causes the load to happen after the next frame which causes the load to take significantly longer.
  313. var subobject = parseScope.subobjects[ parseScope.subobjectIndex ];
  314. Promise.resolve().then( function () {
  315. loadSubobject( subobject );
  316. } );
  317. parseScope.subobjectIndex ++;
  318. }
  319. }
  320. function finalizeObject() {
  321. if ( parseScope.type === 'Part' ) {
  322. smoothNormals( parseScope.triangles, parseScope.lineSegments );
  323. }
  324. var isRoot = ! parentParseScope.isFromParse;
  325. if ( scope.separateObjects && ! isPrimitiveType( parseScope.type ) || isRoot ) {
  326. const objGroup = parseScope.groupObject;
  327. if ( parseScope.triangles.length > 0 ) {
  328. objGroup.add( createObject( parseScope.triangles, 3 ) );
  329. }
  330. if ( parseScope.lineSegments.length > 0 ) {
  331. objGroup.add( createObject( parseScope.lineSegments, 2 ) );
  332. }
  333. if ( parseScope.optionalSegments.length > 0 ) {
  334. objGroup.add( createObject( parseScope.optionalSegments, 2 ) );
  335. }
  336. if ( parentParseScope.groupObject ) {
  337. objGroup.name = parseScope.fileName;
  338. objGroup.matrix.copy( parseScope.matrix );
  339. objGroup.matrix.decompose( objGroup.position, objGroup.quaternion, objGroup.scale );
  340. objGroup.matrixAutoUpdate = false;
  341. parentParseScope.groupObject.add( objGroup );
  342. }
  343. } else {
  344. var separateObjects = scope.separateObjects;
  345. var parentLineSegments = parentParseScope.lineSegments;
  346. var parentOptionalSegments = parentParseScope.optionalSegments;
  347. var parentTriangles = parentParseScope.triangles;
  348. var lineSegments = parseScope.lineSegments;
  349. var optionalSegments = parseScope.optionalSegments;
  350. var triangles = parseScope.triangles;
  351. for ( var i = 0, l = lineSegments.length; i < l; i ++ ) {
  352. var ls = lineSegments[ i ];
  353. if ( separateObjects ) {
  354. ls.v0.applyMatrix4( parseScope.matrix );
  355. ls.v1.applyMatrix4( parseScope.matrix );
  356. }
  357. parentLineSegments.push( ls );
  358. }
  359. for ( var i = 0, l = optionalSegments.length; i < l; i ++ ) {
  360. var os = optionalSegments[ i ];
  361. if ( separateObjects ) {
  362. os.v0.applyMatrix4( parseScope.matrix );
  363. os.v1.applyMatrix4( parseScope.matrix );
  364. }
  365. parentOptionalSegments.push( os );
  366. }
  367. for ( var i = 0, l = triangles.length; i < l; i ++ ) {
  368. var tri = triangles[ i ];
  369. if ( separateObjects ) {
  370. tri.v0 = tri.v0.clone().applyMatrix4( parseScope.matrix );
  371. tri.v1 = tri.v1.clone().applyMatrix4( parseScope.matrix );
  372. tri.v2 = tri.v2.clone().applyMatrix4( parseScope.matrix );
  373. tempVec0.subVectors( tri.v1, tri.v0 );
  374. tempVec1.subVectors( tri.v2, tri.v1 );
  375. tri.faceNormal.crossVectors( tempVec0, tempVec1 ).normalize();
  376. }
  377. parentTriangles.push( tri );
  378. }
  379. }
  380. scope.removeScopeLevel();
  381. if ( onProcessed ) {
  382. onProcessed( parseScope.groupObject );
  383. }
  384. }
  385. function loadSubobject( subobject ) {
  386. parseScope.mainColourCode = subobject.material.userData.code;
  387. parseScope.mainEdgeColourCode = subobject.material.userData.edgeMaterial.userData.code;
  388. parseScope.currentFileName = subobject.originalFileName;
  389. // If subobject was cached previously, use the cached one
  390. var cached = scope.subobjectCache[ subobject.originalFileName.toLowerCase() ];
  391. if ( cached ) {
  392. processObject( cached, function ( subobjectGroup ) {
  393. onSubobjectLoaded( subobjectGroup, subobject );
  394. onSubobjectFinish();
  395. }, subobject );
  396. return;
  397. }
  398. // Adjust file name to locate the subobject file path in standard locations (always under directory scope.path)
  399. // Update also subobject.locationState for the next try if this load fails.
  400. var subobjectURL = subobject.fileName;
  401. var newLocationState = LDrawLoader.FILE_LOCATION_NOT_FOUND;
  402. switch ( subobject.locationState ) {
  403. case LDrawLoader.FILE_LOCATION_AS_IS:
  404. newLocationState = subobject.locationState + 1;
  405. break;
  406. case LDrawLoader.FILE_LOCATION_TRY_PARTS:
  407. subobjectURL = 'parts/' + subobjectURL;
  408. newLocationState = subobject.locationState + 1;
  409. break;
  410. case LDrawLoader.FILE_LOCATION_TRY_P:
  411. subobjectURL = 'p/' + subobjectURL;
  412. newLocationState = subobject.locationState + 1;
  413. break;
  414. case LDrawLoader.FILE_LOCATION_TRY_MODELS:
  415. subobjectURL = 'models/' + subobjectURL;
  416. newLocationState = subobject.locationState + 1;
  417. break;
  418. case LDrawLoader.FILE_LOCATION_TRY_RELATIVE:
  419. subobjectURL = url.substring( 0, url.lastIndexOf( "/" ) + 1 ) + subobjectURL;
  420. newLocationState = subobject.locationState + 1;
  421. break;
  422. case LDrawLoader.FILE_LOCATION_TRY_ABSOLUTE:
  423. if ( subobject.triedLowerCase ) {
  424. // Try absolute path
  425. newLocationState = LDrawLoader.FILE_LOCATION_NOT_FOUND;
  426. } else {
  427. // Next attempt is lower case
  428. subobject.fileName = subobject.fileName.toLowerCase();
  429. subobjectURL = subobject.fileName;
  430. subobject.triedLowerCase = true;
  431. newLocationState = LDrawLoader.FILE_LOCATION_AS_IS;
  432. }
  433. break;
  434. case LDrawLoader.FILE_LOCATION_NOT_FOUND:
  435. // All location possibilities have been tried, give up loading this object
  436. console.warn( 'LDrawLoader: Subobject "' + subobject.originalFileName + '" could not be found.' );
  437. return;
  438. }
  439. subobject.locationState = newLocationState;
  440. subobject.url = subobjectURL;
  441. // Load the subobject
  442. // Use another file loader here so we can keep track of the subobject information
  443. // and use it when processing the next model.
  444. var fileLoader = new THREE.FileLoader( scope.manager );
  445. fileLoader.setPath( scope.path );
  446. fileLoader.load( subobjectURL, function ( text ) {
  447. processObject( text, function ( subobjectGroup ) {
  448. onSubobjectLoaded( subobjectGroup, subobject );
  449. onSubobjectFinish();
  450. }, subobject );
  451. }, undefined, function ( err ) {
  452. onSubobjectError( err, subobject );
  453. }, subobject );
  454. }
  455. function onSubobjectLoaded( subobjectGroup, subobject ) {
  456. if ( subobjectGroup === null ) {
  457. // Try to reload
  458. loadSubobject( subobject );
  459. return;
  460. }
  461. scope.fileMap[ subobject.originalFileName ] = subobject.url;
  462. }
  463. function onSubobjectError( err, subobject ) {
  464. // Retry download from a different default possible location
  465. loadSubobject( subobject );
  466. }
  467. }
  468. },
  469. setPath: function ( value ) {
  470. this.path = value;
  471. return this;
  472. },
  473. setMaterials: function ( materials ) {
  474. // Clears parse scopes stack, adds new scope with material library
  475. this.parseScopesStack = [];
  476. this.newParseScopeLevel( materials );
  477. this.getCurrentParseScope().isFromParse = false;
  478. this.materials = materials;
  479. return this;
  480. },
  481. setFileMap: function ( fileMap ) {
  482. this.fileMap = fileMap;
  483. return this;
  484. },
  485. newParseScopeLevel: function ( materials ) {
  486. // Adds a new scope level, assign materials to it and returns it
  487. var matLib = {};
  488. if ( materials ) {
  489. for ( var i = 0, n = materials.length; i < n; i ++ ) {
  490. var material = materials[ i ];
  491. matLib[ material.userData.code ] = material;
  492. }
  493. }
  494. var topParseScope = this.getCurrentParseScope();
  495. var newParseScope = {
  496. lib: matLib,
  497. url: null,
  498. // Subobjects
  499. subobjects: null,
  500. numSubobjects: 0,
  501. subobjectIndex: 0,
  502. inverted: false,
  503. // Current subobject
  504. currentFileName: null,
  505. mainColourCode: topParseScope ? topParseScope.mainColourCode : '16',
  506. mainEdgeColourCode: topParseScope ? topParseScope.mainEdgeColourCode : '24',
  507. currentMatrix: new THREE.Matrix4(),
  508. matrix: new THREE.Matrix4(),
  509. // If false, it is a root material scope previous to parse
  510. isFromParse: true,
  511. triangles: null,
  512. lineSegments: null,
  513. optionalSegments: null,
  514. };
  515. this.parseScopesStack.push( newParseScope );
  516. return newParseScope;
  517. },
  518. removeScopeLevel: function () {
  519. this.parseScopesStack.pop();
  520. return this;
  521. },
  522. addMaterial: function ( material ) {
  523. // Adds a material to the material library which is on top of the parse scopes stack. And also to the materials array
  524. var matLib = this.getCurrentParseScope().lib;
  525. if ( ! matLib[ material.userData.code ] ) {
  526. this.materials.push( material );
  527. }
  528. matLib[ material.userData.code ] = material;
  529. return this;
  530. },
  531. getMaterial: function ( colourCode ) {
  532. // Given a colour code search its material in the parse scopes stack
  533. if ( colourCode.startsWith( "0x2" ) ) {
  534. // Special 'direct' material value (RGB colour)
  535. var colour = colourCode.substring( 3 );
  536. return this.parseColourMetaDirective( new LineParser( "Direct_Color_" + colour + " CODE -1 VALUE #" + colour + " EDGE #" + colour + "" ) );
  537. }
  538. for ( var i = this.parseScopesStack.length - 1; i >= 0; i -- ) {
  539. var material = this.parseScopesStack[ i ].lib[ colourCode ];
  540. if ( material ) {
  541. return material;
  542. }
  543. }
  544. // Material was not found
  545. return null;
  546. },
  547. getParentParseScope: function () {
  548. if ( this.parseScopesStack.length > 1 ) {
  549. return this.parseScopesStack[ this.parseScopesStack.length - 2 ];
  550. }
  551. return null;
  552. },
  553. getCurrentParseScope: function () {
  554. if ( this.parseScopesStack.length > 0 ) {
  555. return this.parseScopesStack[ this.parseScopesStack.length - 1 ];
  556. }
  557. return null;
  558. },
  559. parseColourMetaDirective: function ( lineParser ) {
  560. // Parses a colour definition and returns a THREE.Material or null if error
  561. var code = null;
  562. // Triangle and line colours
  563. var colour = 0xFF00FF;
  564. var edgeColour = 0xFF00FF;
  565. // Transparency
  566. var alpha = 1;
  567. var isTransparent = false;
  568. // Self-illumination:
  569. var luminance = 0;
  570. var finishType = LDrawLoader.FINISH_TYPE_DEFAULT;
  571. var canHaveEnvMap = true;
  572. var edgeMaterial = null;
  573. var name = lineParser.getToken();
  574. if ( ! name ) {
  575. throw 'LDrawLoader: Material name was expected after "!COLOUR tag' + lineParser.getLineNumberString() + ".";
  576. }
  577. // Parse tag tokens and their parameters
  578. var token = null;
  579. while ( true ) {
  580. token = lineParser.getToken();
  581. if ( ! token ) {
  582. break;
  583. }
  584. switch ( token.toUpperCase() ) {
  585. case "CODE":
  586. code = lineParser.getToken();
  587. break;
  588. case "VALUE":
  589. colour = lineParser.getToken();
  590. if ( colour.startsWith( '0x' ) ) {
  591. colour = '#' + colour.substring( 2 );
  592. } else if ( ! colour.startsWith( '#' ) ) {
  593. throw 'LDrawLoader: Invalid colour while parsing material' + lineParser.getLineNumberString() + ".";
  594. }
  595. break;
  596. case "EDGE":
  597. edgeColour = lineParser.getToken();
  598. if ( edgeColour.startsWith( '0x' ) ) {
  599. edgeColour = '#' + edgeColour.substring( 2 );
  600. } else if ( ! edgeColour.startsWith( '#' ) ) {
  601. // Try to see if edge colour is a colour code
  602. edgeMaterial = this.getMaterial( edgeColour );
  603. if ( ! edgeMaterial ) {
  604. throw 'LDrawLoader: Invalid edge colour while parsing material' + lineParser.getLineNumberString() + ".";
  605. }
  606. // Get the edge material for this triangle material
  607. edgeMaterial = edgeMaterial.userData.edgeMaterial;
  608. }
  609. break;
  610. case 'ALPHA':
  611. alpha = parseInt( lineParser.getToken() );
  612. if ( isNaN( alpha ) ) {
  613. throw 'LDrawLoader: Invalid alpha value in material definition' + lineParser.getLineNumberString() + ".";
  614. }
  615. alpha = Math.max( 0, Math.min( 1, alpha / 255 ) );
  616. if ( alpha < 1 ) {
  617. isTransparent = true;
  618. }
  619. break;
  620. case 'LUMINANCE':
  621. luminance = parseInt( lineParser.getToken() );
  622. if ( isNaN( luminance ) ) {
  623. throw 'LDrawLoader: Invalid luminance value in material definition' + LineParser.getLineNumberString() + ".";
  624. }
  625. luminance = Math.max( 0, Math.min( 1, luminance / 255 ) );
  626. break;
  627. case 'CHROME':
  628. finishType = LDrawLoader.FINISH_TYPE_CHROME;
  629. break;
  630. case 'PEARLESCENT':
  631. finishType = LDrawLoader.FINISH_TYPE_PEARLESCENT;
  632. break;
  633. case 'RUBBER':
  634. finishType = LDrawLoader.FINISH_TYPE_RUBBER;
  635. break;
  636. case 'MATTE_METALLIC':
  637. finishType = LDrawLoader.FINISH_TYPE_MATTE_METALLIC;
  638. break;
  639. case 'METAL':
  640. finishType = LDrawLoader.FINISH_TYPE_METAL;
  641. break;
  642. case 'MATERIAL':
  643. // Not implemented
  644. lineParser.setToEnd();
  645. break;
  646. default:
  647. throw 'LDrawLoader: Unknown token "' + token + '" while parsing material' + lineParser.getLineNumberString() + ".";
  648. break;
  649. }
  650. }
  651. var material = null;
  652. switch ( finishType ) {
  653. case LDrawLoader.FINISH_TYPE_DEFAULT:
  654. material = new THREE.MeshStandardMaterial( { color: colour, roughness: 0.3, envMapIntensity: 0.3, metalness: 0 } );
  655. break;
  656. case LDrawLoader.FINISH_TYPE_PEARLESCENT:
  657. // Try to imitate pearlescency by setting the specular to the complementary of the color, and low shininess
  658. var specular = new THREE.Color( colour );
  659. var hsl = specular.getHSL( { h: 0, s: 0, l: 0 } );
  660. hsl.h = ( hsl.h + 0.5 ) % 1;
  661. hsl.l = Math.min( 1, hsl.l + ( 1 - hsl.l ) * 0.7 );
  662. specular.setHSL( hsl.h, hsl.s, hsl.l );
  663. material = new THREE.MeshPhongMaterial( { color: colour, specular: specular, shininess: 10, reflectivity: 0.3 } );
  664. break;
  665. case LDrawLoader.FINISH_TYPE_CHROME:
  666. // Mirror finish surface
  667. material = new THREE.MeshStandardMaterial( { color: colour, roughness: 0, metalness: 1 } );
  668. break;
  669. case LDrawLoader.FINISH_TYPE_RUBBER:
  670. // Rubber is best simulated with Lambert
  671. material = new THREE.MeshStandardMaterial( { color: colour, roughness: 0.9, metalness: 0 } );
  672. canHaveEnvMap = false;
  673. break;
  674. case LDrawLoader.FINISH_TYPE_MATTE_METALLIC:
  675. // Brushed metal finish
  676. material = new THREE.MeshStandardMaterial( { color: colour, roughness: 0.8, metalness: 0.4 } );
  677. break;
  678. case LDrawLoader.FINISH_TYPE_METAL:
  679. // Average metal finish
  680. material = new THREE.MeshStandardMaterial( { color: colour, roughness: 0.2, metalness: 0.85 } );
  681. break;
  682. default:
  683. // Should not happen
  684. break;
  685. }
  686. material.transparent = isTransparent;
  687. material.opacity = alpha;
  688. material.userData.canHaveEnvMap = canHaveEnvMap;
  689. if ( luminance !== 0 ) {
  690. material.emissive.set( material.color ).multiplyScalar( luminance );
  691. }
  692. if ( ! edgeMaterial ) {
  693. // This is the material used for edges
  694. edgeMaterial = new THREE.LineBasicMaterial( { color: edgeColour } );
  695. edgeMaterial.userData.code = code;
  696. edgeMaterial.name = name + " - Edge";
  697. edgeMaterial.userData.canHaveEnvMap = false;
  698. }
  699. material.userData.code = code;
  700. material.name = name;
  701. material.userData.edgeMaterial = edgeMaterial;
  702. return material;
  703. },
  704. //
  705. parse: function ( text ) {
  706. //console.time( 'LDrawLoader' );
  707. // Retrieve data from the parent parse scope
  708. var parentParseScope = this.getParentParseScope();
  709. // Main colour codes passed to this subobject (or default codes 16 and 24 if it is the root object)
  710. var mainColourCode = parentParseScope.mainColourCode;
  711. var mainEdgeColourCode = parentParseScope.mainEdgeColourCode;
  712. var url = parentParseScope.url;
  713. var currentParseScope = this.getCurrentParseScope();
  714. // Parse result variables
  715. var triangles;
  716. var lineSegments;
  717. var optionalSegments;
  718. var subobjects = [];
  719. var category = null;
  720. var keywords = null;
  721. if ( text.indexOf( '\r\n' ) !== - 1 ) {
  722. // This is faster than String.split with regex that splits on both
  723. text = text.replace( /\r\n/g, '\n' );
  724. }
  725. var lines = text.split( '\n' );
  726. var numLines = lines.length;
  727. var lineIndex = 0;
  728. var parsingEmbeddedFiles = false;
  729. var currentEmbeddedFileName = null;
  730. var currentEmbeddedText = null;
  731. var bfcCertified = false;
  732. var bfcCCW = true;
  733. var bfcInverted = false;
  734. var bfcCull = true;
  735. var type = '';
  736. var scope = this;
  737. function parseColourCode( lineParser, forEdge ) {
  738. // Parses next colour code and returns a THREE.Material
  739. var colourCode = lineParser.getToken();
  740. if ( ! forEdge && colourCode === '16' ) {
  741. colourCode = mainColourCode;
  742. }
  743. if ( forEdge && colourCode === '24' ) {
  744. colourCode = mainEdgeColourCode;
  745. }
  746. var material = scope.getMaterial( colourCode );
  747. if ( ! material ) {
  748. throw 'LDrawLoader: Unknown colour code "' + colourCode + '" is used' + lineParser.getLineNumberString() + ' but it was not defined previously.';
  749. }
  750. return material;
  751. }
  752. function parseVector( lp ) {
  753. var v = new THREE.Vector3( parseFloat( lp.getToken() ), parseFloat( lp.getToken() ), parseFloat( lp.getToken() ) );
  754. if ( ! scope.separateObjects ) {
  755. v.applyMatrix4( currentParseScope.currentMatrix );
  756. }
  757. return v;
  758. }
  759. // Parse all line commands
  760. for ( lineIndex = 0; lineIndex < numLines; lineIndex ++ ) {
  761. var line = lines[ lineIndex ];
  762. if ( line.length === 0 ) continue;
  763. if ( parsingEmbeddedFiles ) {
  764. if ( line.startsWith( '0 FILE ' ) ) {
  765. // Save previous embedded file in the cache
  766. this.subobjectCache[ currentEmbeddedFileName.toLowerCase() ] = currentEmbeddedText;
  767. // New embedded text file
  768. currentEmbeddedFileName = line.substring( 7 );
  769. currentEmbeddedText = '';
  770. } else {
  771. currentEmbeddedText += line + '\n';
  772. }
  773. continue;
  774. }
  775. var lp = new LineParser( line, lineIndex + 1 );
  776. lp.seekNonSpace();
  777. if ( lp.isAtTheEnd() ) {
  778. // Empty line
  779. continue;
  780. }
  781. // Parse the line type
  782. var lineType = lp.getToken();
  783. switch ( lineType ) {
  784. // Line type 0: Comment or META
  785. case '0':
  786. // Parse meta directive
  787. var meta = lp.getToken();
  788. if ( meta ) {
  789. switch ( meta ) {
  790. case '!LDRAW_ORG':
  791. type = lp.getToken();
  792. if ( ! parsingEmbeddedFiles ) {
  793. currentParseScope.triangles = [];
  794. currentParseScope.lineSegments = [];
  795. currentParseScope.optionalSegments = [];
  796. currentParseScope.type = type;
  797. var isRoot = ! parentParseScope.isFromParse;
  798. if ( isRoot || scope.separateObjects && ! isPrimitiveType( type ) ) {
  799. currentParseScope.groupObject = new THREE.Group();
  800. }
  801. // If the scale of the object is negated then the triangle winding order
  802. // needs to be flipped.
  803. var matrix = currentParseScope.matrix;
  804. if (
  805. matrix.determinant() < 0 && (
  806. scope.separateObjects && isPrimitiveType( type ) ||
  807. ! scope.separateObjects
  808. ) ) {
  809. currentParseScope.inverted = ! currentParseScope.inverted;
  810. }
  811. triangles = currentParseScope.triangles;
  812. lineSegments = currentParseScope.lineSegments;
  813. optionalSegments = currentParseScope.optionalSegments;
  814. }
  815. break;
  816. case '!COLOUR':
  817. var material = this.parseColourMetaDirective( lp );
  818. if ( material ) {
  819. this.addMaterial( material );
  820. } else {
  821. console.warn( 'LDrawLoader: Error parsing material' + lp.getLineNumberString() );
  822. }
  823. break;
  824. case '!CATEGORY':
  825. category = lp.getToken();
  826. break;
  827. case '!KEYWORDS':
  828. var newKeywords = lp.getRemainingString().split( ',' );
  829. if ( newKeywords.length > 0 ) {
  830. if ( ! keywords ) {
  831. keywords = [];
  832. }
  833. newKeywords.forEach( function ( keyword ) {
  834. keywords.push( keyword.trim() );
  835. } );
  836. }
  837. break;
  838. case 'FILE':
  839. if ( lineIndex > 0 ) {
  840. // Start embedded text files parsing
  841. parsingEmbeddedFiles = true;
  842. currentEmbeddedFileName = lp.getRemainingString();
  843. currentEmbeddedText = '';
  844. bfcCertified = false;
  845. bfcCCW = true;
  846. }
  847. break;
  848. case 'BFC':
  849. // Changes to the backface culling state
  850. while ( ! lp.isAtTheEnd() ) {
  851. var token = lp.getToken();
  852. switch ( token ) {
  853. case 'CERTIFY':
  854. case 'NOCERTIFY':
  855. bfcCertified = token === 'CERTIFY';
  856. bfcCCW = true;
  857. break;
  858. case 'CW':
  859. case 'CCW':
  860. bfcCCW = token === 'CCW';
  861. break;
  862. case 'INVERTNEXT':
  863. bfcInverted = true;
  864. break;
  865. case 'CLIP':
  866. case 'NOCLIP':
  867. bfcCull = token === 'CLIP';
  868. break;
  869. default:
  870. console.warn( 'THREE.LDrawLoader: BFC directive "' + token + '" is unknown.' );
  871. break;
  872. }
  873. }
  874. break;
  875. default:
  876. // Other meta directives are not implemented
  877. break;
  878. }
  879. }
  880. break;
  881. // Line type 1: Sub-object file
  882. case '1':
  883. var material = parseColourCode( lp );
  884. var posX = parseFloat( lp.getToken() );
  885. var posY = parseFloat( lp.getToken() );
  886. var posZ = parseFloat( lp.getToken() );
  887. var m0 = parseFloat( lp.getToken() );
  888. var m1 = parseFloat( lp.getToken() );
  889. var m2 = parseFloat( lp.getToken() );
  890. var m3 = parseFloat( lp.getToken() );
  891. var m4 = parseFloat( lp.getToken() );
  892. var m5 = parseFloat( lp.getToken() );
  893. var m6 = parseFloat( lp.getToken() );
  894. var m7 = parseFloat( lp.getToken() );
  895. var m8 = parseFloat( lp.getToken() );
  896. var matrix = new THREE.Matrix4().set(
  897. m0, m1, m2, posX,
  898. m3, m4, m5, posY,
  899. m6, m7, m8, posZ,
  900. 0, 0, 0, 1
  901. );
  902. var fileName = lp.getRemainingString().trim().replace( "\\", "/" );
  903. if ( scope.fileMap[ fileName ] ) {
  904. // Found the subobject path in the preloaded file path map
  905. fileName = scope.fileMap[ fileName ];
  906. } else {
  907. // Standardized subfolders
  908. if ( fileName.startsWith( 's/' ) ) {
  909. fileName = 'parts/' + fileName;
  910. } else if ( fileName.startsWith( '48/' ) ) {
  911. fileName = 'p/' + fileName;
  912. }
  913. }
  914. subobjects.push( {
  915. material: material,
  916. matrix: matrix,
  917. fileName: fileName,
  918. originalFileName: fileName,
  919. locationState: LDrawLoader.FILE_LOCATION_AS_IS,
  920. url: null,
  921. triedLowerCase: false,
  922. inverted: bfcInverted !== currentParseScope.inverted
  923. } );
  924. bfcInverted = false;
  925. break;
  926. // Line type 2: Line segment
  927. // Line type 5: Optional Line segment
  928. case '2':
  929. case '5':
  930. var material = parseColourCode( lp, true );
  931. var arr = lineType === '2' ? lineSegments : optionalSegments;
  932. arr.push( {
  933. material: material.userData.edgeMaterial,
  934. colourCode: material.userData.code,
  935. v0: parseVector( lp ),
  936. v1: parseVector( lp )
  937. } );
  938. break;
  939. // Line type 3: Triangle
  940. case '3':
  941. var material = parseColourCode( lp );
  942. var inverted = currentParseScope.inverted;
  943. var ccw = bfcCCW !== inverted;
  944. var doubleSided = ! bfcCertified || ! bfcCull;
  945. var v0, v1, v2, faceNormal;
  946. if ( ccw === true ) {
  947. v0 = parseVector( lp );
  948. v1 = parseVector( lp );
  949. v2 = parseVector( lp );
  950. } else {
  951. v2 = parseVector( lp );
  952. v1 = parseVector( lp );
  953. v0 = parseVector( lp );
  954. }
  955. tempVec0.subVectors( v1, v0 );
  956. tempVec1.subVectors( v2, v1 );
  957. faceNormal = new THREE.Vector3()
  958. .crossVectors( tempVec0, tempVec1 )
  959. .normalize();
  960. triangles.push( {
  961. material: material,
  962. colourCode: material.userData.code,
  963. v0: v0,
  964. v1: v1,
  965. v2: v2,
  966. faceNormal: faceNormal,
  967. n0: null,
  968. n1: null,
  969. n2: null
  970. } );
  971. if ( doubleSided === true ) {
  972. triangles.push( {
  973. material: material,
  974. colourCode: material.userData.code,
  975. v0: v0,
  976. v1: v2,
  977. v2: v1,
  978. faceNormal: faceNormal,
  979. n0: null,
  980. n1: null,
  981. n2: null
  982. } );
  983. }
  984. break;
  985. // Line type 4: Quadrilateral
  986. case '4':
  987. var material = parseColourCode( lp );
  988. var inverted = currentParseScope.inverted;
  989. var ccw = bfcCCW !== inverted;
  990. var doubleSided = ! bfcCertified || ! bfcCull;
  991. var v0, v1, v2, v3, faceNormal;
  992. if ( ccw === true ) {
  993. v0 = parseVector( lp );
  994. v1 = parseVector( lp );
  995. v2 = parseVector( lp );
  996. v3 = parseVector( lp );
  997. } else {
  998. v3 = parseVector( lp );
  999. v2 = parseVector( lp );
  1000. v1 = parseVector( lp );
  1001. v0 = parseVector( lp );
  1002. }
  1003. tempVec0.subVectors( v1, v0 );
  1004. tempVec1.subVectors( v2, v1 );
  1005. faceNormal = new THREE.Vector3()
  1006. .crossVectors( tempVec0, tempVec1 )
  1007. .normalize();
  1008. triangles.push( {
  1009. material: material,
  1010. colourCode: material.userData.code,
  1011. v0: v0,
  1012. v1: v1,
  1013. v2: v2,
  1014. faceNormal: faceNormal,
  1015. n0: null,
  1016. n1: null,
  1017. n2: null
  1018. } );
  1019. triangles.push( {
  1020. material: material,
  1021. colourCode: material.userData.code,
  1022. v0: v0,
  1023. v1: v2,
  1024. v2: v3,
  1025. faceNormal: faceNormal,
  1026. n0: null,
  1027. n1: null,
  1028. n2: null
  1029. } );
  1030. if ( doubleSided === true ) {
  1031. triangles.push( {
  1032. material: material,
  1033. colourCode: material.userData.code,
  1034. v0: v0,
  1035. v1: v2,
  1036. v2: v1,
  1037. faceNormal: faceNormal,
  1038. n0: null,
  1039. n1: null,
  1040. n2: null
  1041. } );
  1042. triangles.push( {
  1043. material: material,
  1044. colourCode: material.userData.code,
  1045. v0: v0,
  1046. v1: v3,
  1047. v2: v2,
  1048. faceNormal: faceNormal,
  1049. n0: null,
  1050. n1: null,
  1051. n2: null
  1052. } );
  1053. }
  1054. break;
  1055. default:
  1056. throw 'LDrawLoader: Unknown line type "' + lineType + '"' + lp.getLineNumberString() + '.';
  1057. break;
  1058. }
  1059. }
  1060. if ( parsingEmbeddedFiles ) {
  1061. this.subobjectCache[ currentEmbeddedFileName.toLowerCase() ] = currentEmbeddedText;
  1062. }
  1063. currentParseScope.category = category;
  1064. currentParseScope.keywords = keywords;
  1065. currentParseScope.subobjects = subobjects;
  1066. currentParseScope.numSubobjects = subobjects.length;
  1067. currentParseScope.subobjectIndex = 0;
  1068. }
  1069. };
  1070. return LDrawLoader;
  1071. } )();