VRMLLoader.js 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632
  1. /**
  2. * @author Mugen87 / https://github.com/Mugen87
  3. */
  4. import {
  5. BackSide,
  6. BoxBufferGeometry,
  7. BufferAttribute,
  8. BufferGeometry,
  9. ClampToEdgeWrapping,
  10. Color,
  11. ConeBufferGeometry,
  12. CylinderBufferGeometry,
  13. DefaultLoadingManager,
  14. DoubleSide,
  15. FileLoader,
  16. Float32BufferAttribute,
  17. FrontSide,
  18. Group,
  19. LineBasicMaterial,
  20. LineSegments,
  21. LoaderUtils,
  22. Mesh,
  23. MeshBasicMaterial,
  24. MeshPhongMaterial,
  25. Object3D,
  26. Points,
  27. PointsMaterial,
  28. RepeatWrapping,
  29. Scene,
  30. SphereBufferGeometry,
  31. TextureLoader,
  32. Vector2,
  33. Vector3,
  34. VertexColors
  35. } from "../../../build/three.module.js";
  36. import { chevrotain } from "../libs/chevrotain.module.min.js";
  37. /* global chevrotain */
  38. var VRMLLoader = ( function () {
  39. // dependency check
  40. if ( typeof chevrotain === 'undefined' ) {
  41. throw Error( 'THREE.VRMLLoader: External library chevrotain.min.js required.' );
  42. }
  43. // class definitions
  44. function VRMLLoader( manager ) {
  45. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  46. }
  47. VRMLLoader.prototype = {
  48. constructor: VRMLLoader,
  49. crossOrigin: 'anonymous',
  50. load: function ( url, onLoad, onProgress, onError ) {
  51. var scope = this;
  52. var path = ( scope.path === undefined ) ? LoaderUtils.extractUrlBase( url ) : scope.path;
  53. var loader = new FileLoader( this.manager );
  54. loader.setPath( scope.path );
  55. loader.load( url, function ( text ) {
  56. onLoad( scope.parse( text, path ) );
  57. }, onProgress, onError );
  58. },
  59. setPath: function ( value ) {
  60. this.path = value;
  61. return this;
  62. },
  63. setResourcePath: function ( value ) {
  64. this.resourcePath = value;
  65. return this;
  66. },
  67. setCrossOrigin: function ( value ) {
  68. this.crossOrigin = value;
  69. return this;
  70. },
  71. parse: function ( data, path ) {
  72. var nodeMap = {};
  73. function generateVRMLTree( data ) {
  74. // create lexer, parser and visitor
  75. var tokenData = createTokens();
  76. var lexer = new VRMLLexer( tokenData.tokens );
  77. var parser = new VRMLParser( tokenData.tokenVocabulary );
  78. var visitor = createVisitor( parser.getBaseCstVisitorConstructor() );
  79. // lexing
  80. var lexingResult = lexer.lex( data );
  81. parser.input = lexingResult.tokens;
  82. // parsing
  83. var cstOutput = parser.vrml();
  84. if ( parser.errors.length > 0 ) {
  85. console.error( parser.errors );
  86. throw Error( 'THREE.VRMLLoader: Parsing errors detected.' );
  87. }
  88. // actions
  89. var ast = visitor.visit( cstOutput );
  90. return ast;
  91. }
  92. function createTokens() {
  93. var createToken = chevrotain.createToken;
  94. // from http://gun.teipir.gr/VRML-amgem/spec/part1/concepts.html#SyntaxBasics
  95. var RouteIdentifier = createToken( { name: 'RouteIdentifier', pattern: /[^\x30-\x39\0-\x20\x22\x27\x23\x2b\x2c\x2d\x2e\x5b\x5d\x5c\x7b\x7d][^\0-\x20\x22\x27\x23\x2b\x2c\x2d\x2e\x5b\x5d\x5c\x7b\x7d]*[\.][^\x30-\x39\0-\x20\x22\x27\x23\x2b\x2c\x2d\x2e\x5b\x5d\x5c\x7b\x7d][^\0-\x20\x22\x27\x23\x2b\x2c\x2d\x2e\x5b\x5d\x5c\x7b\x7d]*/ } );
  96. var Identifier = createToken( { name: 'Identifier', pattern: /[^\x30-\x39\0-\x20\x22\x27\x23\x2b\x2c\x2d\x2e\x5b\x5d\x5c\x7b\x7d][^\0-\x20\x22\x27\x23\x2b\x2c\x2d\x2e\x5b\x5d\x5c\x7b\x7d]*/, longer_alt: RouteIdentifier } );
  97. // from http://gun.teipir.gr/VRML-amgem/spec/part1/nodesRef.html
  98. var nodeTypes = [
  99. 'Anchor', 'Billboard', 'Collision', 'Group', 'Transform', // grouping nodes
  100. 'Inline', 'LOD', 'Switch', // special groups
  101. 'AudioClip', 'DirectionalLight', 'PointLight', 'Script', 'Shape', 'Sound', 'SpotLight', 'WorldInfo', // common nodes
  102. 'CylinderSensor', 'PlaneSensor', 'ProximitySensor', 'SphereSensor', 'TimeSensor', 'TouchSensor', 'VisibilitySensor', // sensors
  103. 'Box', 'Cone', 'Cylinder', 'ElevationGrid', 'Extrusion', 'IndexedFaceSet', 'IndexedLineSet', 'PointSet', 'Sphere', // geometries
  104. 'Color', 'Coordinate', 'Normal', 'TextureCoordinate', // geometric properties
  105. 'Appearance', 'FontStyle', 'ImageTexture', 'Material', 'MovieTexture', 'PixelTexture', 'TextureTransform', // appearance
  106. 'ColorInterpolator', 'CoordinateInterpolator', 'NormalInterpolator', 'OrientationInterpolator', 'PositionInterpolator', 'ScalarInterpolator', // interpolators
  107. 'Background', 'Fog', 'NavigationInfo', 'Viewpoint', // bindable nodes
  108. 'Text' // Text must be placed at the end of the regex so there are no matches for TextureTransform and TextureCoordinate
  109. ];
  110. //
  111. var Version = createToken( {
  112. name: 'Version',
  113. pattern: /#VRML.*/,
  114. longer_alt: Identifier
  115. } );
  116. var NodeName = createToken( {
  117. name: 'NodeName',
  118. pattern: new RegExp( nodeTypes.join( '|' ) ),
  119. longer_alt: Identifier
  120. } );
  121. var DEF = createToken( {
  122. name: 'DEF',
  123. pattern: /DEF/,
  124. longer_alt: Identifier
  125. } );
  126. var USE = createToken( {
  127. name: 'USE',
  128. pattern: /USE/,
  129. longer_alt: Identifier
  130. } );
  131. var ROUTE = createToken( {
  132. name: 'ROUTE',
  133. pattern: /ROUTE/,
  134. longer_alt: Identifier
  135. } );
  136. var TO = createToken( {
  137. name: 'TO',
  138. pattern: /TO/,
  139. longer_alt: Identifier
  140. } );
  141. //
  142. var StringLiteral = createToken( { name: "StringLiteral", pattern: /"(:?[^\\"\n\r]+|\\(:?[bfnrtv"\\/]|u[0-9a-fA-F]{4}))*"/ } );
  143. var NumberLiteral = createToken( { name: 'NumberLiteral', pattern: /[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?/ } );
  144. var TrueLiteral = createToken( { name: 'TrueLiteral', pattern: /TRUE/ } );
  145. var FalseLiteral = createToken( { name: 'FalseLiteral', pattern: /FALSE/ } );
  146. var NullLiteral = createToken( { name: 'NullLiteral', pattern: /NULL/ } );
  147. var LSquare = createToken( { name: 'LSquare', pattern: /\[/ } );
  148. var RSquare = createToken( { name: 'RSquare', pattern: /]/ } );
  149. var LCurly = createToken( { name: 'LCurly', pattern: /{/ } );
  150. var RCurly = createToken( { name: 'RCurly', pattern: /}/ } );
  151. var Comment = createToken( {
  152. name: 'Comment',
  153. pattern: /#.*/,
  154. group: chevrotain.Lexer.SKIPPED
  155. } );
  156. // commas, blanks, tabs, newlines and carriage returns are whitespace characters wherever they appear outside of string fields
  157. var WhiteSpace = createToken( {
  158. name: 'WhiteSpace',
  159. pattern: /[ ,\s]/,
  160. group: chevrotain.Lexer.SKIPPED
  161. } );
  162. var tokens = [
  163. WhiteSpace,
  164. // keywords appear before the Identifier
  165. NodeName,
  166. DEF,
  167. USE,
  168. ROUTE,
  169. TO,
  170. TrueLiteral,
  171. FalseLiteral,
  172. NullLiteral,
  173. // the Identifier must appear after the keywords because all keywords are valid identifiers
  174. Version,
  175. Identifier,
  176. RouteIdentifier,
  177. StringLiteral,
  178. NumberLiteral,
  179. LSquare,
  180. RSquare,
  181. LCurly,
  182. RCurly,
  183. Comment
  184. ];
  185. var tokenVocabulary = {};
  186. for ( var i = 0, l = tokens.length; i < l; i ++ ) {
  187. var token = tokens[ i ];
  188. tokenVocabulary[ token.name ] = token;
  189. }
  190. return { tokens: tokens, tokenVocabulary: tokenVocabulary };
  191. }
  192. function createVisitor( BaseVRMLVisitor ) {
  193. // the visitor is created dynmaically based on the given base class
  194. function VRMLToASTVisitor() {
  195. BaseVRMLVisitor.call( this );
  196. this.validateVisitor();
  197. }
  198. VRMLToASTVisitor.prototype = Object.assign( Object.create( BaseVRMLVisitor.prototype ), {
  199. constructor: VRMLToASTVisitor,
  200. vrml: function ( ctx ) {
  201. var data = {
  202. version: this.visit( ctx.version ),
  203. nodes: [],
  204. routes: []
  205. };
  206. for ( var i = 0, l = ctx.node.length; i < l; i ++ ) {
  207. var node = ctx.node[ i ];
  208. data.nodes.push( this.visit( node ) );
  209. }
  210. if ( ctx.route ) {
  211. for ( var i = 0, l = ctx.route.length; i < l; i ++ ) {
  212. var route = ctx.route[ i ];
  213. data.routes.push( this.visit( route ) );
  214. }
  215. }
  216. return data;
  217. },
  218. version: function ( ctx ) {
  219. return ctx.Version[ 0 ].image;
  220. },
  221. node: function ( ctx ) {
  222. var data = {
  223. name: ctx.NodeName[ 0 ].image,
  224. fields: []
  225. };
  226. if ( ctx.field ) {
  227. for ( var i = 0, l = ctx.field.length; i < l; i ++ ) {
  228. var field = ctx.field[ i ];
  229. data.fields.push( this.visit( field ) );
  230. }
  231. }
  232. // DEF
  233. if ( ctx.def ) {
  234. data.DEF = this.visit( ctx.def[ 0 ] );
  235. }
  236. return data;
  237. },
  238. field: function ( ctx ) {
  239. var data = {
  240. name: ctx.Identifier[ 0 ].image,
  241. type: null,
  242. values: null
  243. };
  244. var result;
  245. // SFValue
  246. if ( ctx.singleFieldValue ) {
  247. result = this.visit( ctx.singleFieldValue[ 0 ] );
  248. }
  249. // MFValue
  250. if ( ctx.multiFieldValue ) {
  251. result = this.visit( ctx.multiFieldValue[ 0 ] );
  252. }
  253. data.type = result.type;
  254. data.values = result.values;
  255. return data;
  256. },
  257. def: function ( ctx ) {
  258. return ctx.Identifier[ 0 ].image;
  259. },
  260. use: function ( ctx ) {
  261. return { USE: ctx.Identifier[ 0 ].image };
  262. },
  263. singleFieldValue: function ( ctx ) {
  264. return processField( this, ctx );
  265. },
  266. multiFieldValue: function ( ctx ) {
  267. return processField( this, ctx );
  268. },
  269. route: function ( ctx ) {
  270. var data = {
  271. FROM: ctx.RouteIdentifier[ 0 ].image,
  272. TO: ctx.RouteIdentifier[ 1 ].image
  273. };
  274. return data;
  275. }
  276. } );
  277. function processField( scope, ctx ) {
  278. var field = {
  279. type: null,
  280. values: []
  281. };
  282. if ( ctx.node ) {
  283. field.type = 'node';
  284. for ( var i = 0, l = ctx.node.length; i < l; i ++ ) {
  285. var node = ctx.node[ i ];
  286. field.values.push( scope.visit( node ) );
  287. }
  288. }
  289. if ( ctx.use ) {
  290. field.type = 'use';
  291. for ( var i = 0, l = ctx.use.length; i < l; i ++ ) {
  292. var use = ctx.use[ i ];
  293. field.values.push( scope.visit( use ) );
  294. }
  295. }
  296. if ( ctx.StringLiteral ) {
  297. field.type = 'string';
  298. for ( var i = 0, l = ctx.StringLiteral.length; i < l; i ++ ) {
  299. var stringLiteral = ctx.StringLiteral[ i ];
  300. field.values.push( stringLiteral.image.replace( /'|"/g, '' ) );
  301. }
  302. }
  303. if ( ctx.NumberLiteral ) {
  304. field.type = 'number';
  305. for ( var i = 0, l = ctx.NumberLiteral.length; i < l; i ++ ) {
  306. var numberLiteral = ctx.NumberLiteral[ i ];
  307. field.values.push( parseFloat( numberLiteral.image ) );
  308. }
  309. }
  310. if ( ctx.TrueLiteral ) {
  311. field.type = 'boolean';
  312. for ( var i = 0, l = ctx.TrueLiteral.length; i < l; i ++ ) {
  313. var trueLiteral = ctx.TrueLiteral[ i ];
  314. if ( trueLiteral.image === 'TRUE' ) field.values.push( true );
  315. }
  316. }
  317. if ( ctx.FalseLiteral ) {
  318. field.type = 'boolean';
  319. for ( var i = 0, l = ctx.FalseLiteral.length; i < l; i ++ ) {
  320. var falseLiteral = ctx.FalseLiteral[ i ];
  321. if ( falseLiteral.image === 'FALSE' ) field.values.push( false );
  322. }
  323. }
  324. if ( ctx.NullLiteral ) {
  325. field.type = 'null';
  326. ctx.NullLiteral.forEach( function () {
  327. field.values.push( null );
  328. } );
  329. }
  330. return field;
  331. }
  332. return new VRMLToASTVisitor();
  333. }
  334. function parseTree( tree ) {
  335. // console.log( JSON.stringify( tree, null, 2 ) );
  336. var nodes = tree.nodes;
  337. var scene = new Scene();
  338. // first iteration: build nodemap based on DEF statements
  339. for ( var i = 0, l = nodes.length; i < l; i ++ ) {
  340. var node = nodes[ i ];
  341. buildNodeMap( node );
  342. }
  343. // second iteration: build nodes
  344. for ( var i = 0, l = nodes.length; i < l; i ++ ) {
  345. var node = nodes[ i ];
  346. var object = getNode( node );
  347. if ( object instanceof Object3D ) scene.add( object );
  348. }
  349. return scene;
  350. }
  351. function buildNodeMap( node ) {
  352. if ( node.DEF ) {
  353. nodeMap[ node.DEF ] = node;
  354. }
  355. var fields = node.fields;
  356. for ( var i = 0, l = fields.length; i < l; i ++ ) {
  357. var field = fields[ i ];
  358. if ( field.type === 'node' ) {
  359. var fieldValues = field.values;
  360. for ( var j = 0, jl = fieldValues.length; j < jl; j ++ ) {
  361. buildNodeMap( fieldValues[ j ] );
  362. }
  363. }
  364. }
  365. }
  366. function getNode( node ) {
  367. // handle case where a node refers to a different one
  368. if ( node.USE ) {
  369. return resolveUSE( node.USE );
  370. }
  371. if ( node.build !== undefined ) return node.build;
  372. node.build = buildNode( node );
  373. return node.build;
  374. }
  375. // node builder
  376. function buildNode( node ) {
  377. var nodeName = node.name;
  378. var build;
  379. switch ( nodeName ) {
  380. case 'Group':
  381. case 'Transform':
  382. build = buildGroupingNode( node );
  383. break;
  384. case 'Background':
  385. build = buildBackgroundNode( node );
  386. break;
  387. case 'Shape':
  388. build = buildShapeNode( node );
  389. break;
  390. case 'Appearance':
  391. build = buildApperanceNode( node );
  392. break;
  393. case 'Material':
  394. build = buildMaterialNode( node );
  395. break;
  396. case 'ImageTexture':
  397. build = buildImageTextureNode( node );
  398. break;
  399. case 'TextureTransform':
  400. build = buildTextureTransformNode( node );
  401. break;
  402. case 'IndexedFaceSet':
  403. build = buildIndexedFaceSetNode( node );
  404. break;
  405. case 'IndexedLineSet':
  406. build = buildIndexedLineSetNode( node );
  407. break;
  408. case 'PointSet':
  409. build = buildPointSetNode( node );
  410. break;
  411. case 'Box':
  412. build = buildBoxNode( node );
  413. break;
  414. case 'Cone':
  415. build = buildConeNode( node );
  416. break;
  417. case 'Cylinder':
  418. build = buildCylinderNode( node );
  419. break;
  420. case 'Sphere':
  421. build = buildSphereNode( node );
  422. break;
  423. case 'Color':
  424. case 'Coordinate':
  425. case 'Normal':
  426. case 'TextureCoordinate':
  427. build = buildGeometricNode( node );
  428. break;
  429. case 'Anchor':
  430. case 'Billboard':
  431. case 'Collision':
  432. case 'Inline':
  433. case 'LOD':
  434. case 'Switch':
  435. case 'AudioClip':
  436. case 'DirectionalLight':
  437. case 'PointLight':
  438. case 'Script':
  439. case 'Sound':
  440. case 'SpotLight':
  441. case 'WorldInfo':
  442. case 'CylinderSensor':
  443. case 'PlaneSensor':
  444. case 'ProximitySensor':
  445. case 'SphereSensor':
  446. case 'TimeSensor':
  447. case 'TouchSensor':
  448. case 'VisibilitySensor':
  449. case 'ElevationGrid':
  450. case 'Extrusion':
  451. case 'Text':
  452. case 'FontStyle':
  453. case 'MovieTexture':
  454. case 'PixelTexture':
  455. case 'ColorInterpolator':
  456. case 'CoordinateInterpolator':
  457. case 'NormalInterpolator':
  458. case 'OrientationInterpolator':
  459. case 'PositionInterpolator':
  460. case 'ScalarInterpolator':
  461. case 'Fog':
  462. case 'NavigationInfo':
  463. case 'Viewpoint':
  464. // node not supported yet
  465. break;
  466. default:
  467. console.warn( 'THREE.VRMLLoader: Unknown node:', nodeName );
  468. break;
  469. }
  470. return build;
  471. }
  472. function buildGroupingNode( node ) {
  473. var object = new Group();
  474. //
  475. var fields = node.fields;
  476. for ( var i = 0, l = fields.length; i < l; i ++ ) {
  477. var field = fields[ i ];
  478. var fieldName = field.name;
  479. var fieldValues = field.values;
  480. switch ( fieldName ) {
  481. case 'center':
  482. // field not supported
  483. break;
  484. case 'children':
  485. parseFieldChildren( fieldValues, object );
  486. break;
  487. case 'rotation':
  488. var axis = new Vector3( fieldValues[ 0 ], fieldValues[ 1 ], fieldValues[ 2 ] );
  489. var angle = fieldValues[ 3 ];
  490. object.quaternion.setFromAxisAngle( axis, angle );
  491. break;
  492. case 'scale':
  493. object.scale.set( fieldValues[ 0 ], fieldValues[ 1 ], fieldValues[ 2 ] );
  494. break;
  495. case 'scaleOrientation':
  496. // field not supported
  497. break;
  498. case 'translation':
  499. object.position.set( fieldValues[ 0 ], fieldValues[ 1 ], fieldValues[ 2 ] );
  500. break;
  501. case 'bboxCenter':
  502. // field not supported
  503. break;
  504. case 'bboxSize':
  505. // field not supported
  506. break;
  507. default:
  508. console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
  509. break;
  510. }
  511. }
  512. return object;
  513. }
  514. function buildBackgroundNode( node ) {
  515. var group = new Group();
  516. var groundAngle, groundColor;
  517. var skyAngle, skyColor;
  518. var fields = node.fields;
  519. for ( var i = 0, l = fields.length; i < l; i ++ ) {
  520. var field = fields[ i ];
  521. var fieldName = field.name;
  522. var fieldValues = field.values;
  523. switch ( fieldName ) {
  524. case 'groundAngle':
  525. groundAngle = fieldValues;
  526. break;
  527. case 'groundColor':
  528. groundColor = fieldValues;
  529. break;
  530. case 'backUrl':
  531. // field not supported
  532. break;
  533. case 'bottomUrl':
  534. // field not supported
  535. break;
  536. case 'frontUrl':
  537. // field not supported
  538. break;
  539. case 'leftUrl':
  540. // field not supported
  541. break;
  542. case 'rightUrl':
  543. // field not supported
  544. break;
  545. case 'topUrl':
  546. // field not supported
  547. break;
  548. case 'skyAngle':
  549. skyAngle = fieldValues;
  550. break;
  551. case 'skyColor':
  552. skyColor = fieldValues;
  553. break;
  554. default:
  555. console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
  556. break;
  557. }
  558. }
  559. // sky
  560. if ( skyColor ) {
  561. var radius = 10000;
  562. var skyGeometry = new SphereBufferGeometry( radius, 32, 16 );
  563. var skyMaterial = new MeshBasicMaterial( { fog: false, side: BackSide, depthWrite: false, depthTest: false } );
  564. if ( skyColor.length > 3 ) {
  565. paintFaces( skyGeometry, radius, skyAngle, toColorArray( skyColor ), true );
  566. skyMaterial.vertexColors = VertexColors;
  567. } else {
  568. skyMaterial.color.setRGB( skyColor[ 0 ], skyColor[ 1 ], skyColor[ 2 ] );
  569. }
  570. var sky = new Mesh( skyGeometry, skyMaterial );
  571. group.add( sky );
  572. }
  573. // ground
  574. if ( groundColor ) {
  575. if ( groundColor.length > 0 ) {
  576. var groundGeometry = new SphereBufferGeometry( radius, 32, 16, 0, 2 * Math.PI, 0.5 * Math.PI, 1.5 * Math.PI );
  577. var groundMaterial = new MeshBasicMaterial( { fog: false, side: BackSide, vertexColors: VertexColors, depthWrite: false, depthTest: false } );
  578. paintFaces( groundGeometry, radius, groundAngle, toColorArray( groundColor ), false );
  579. var ground = new Mesh( groundGeometry, groundMaterial );
  580. group.add( ground );
  581. }
  582. }
  583. // render background group first
  584. group.renderOrder = - Infinity;
  585. return group;
  586. }
  587. function buildShapeNode( node ) {
  588. var fields = node.fields;
  589. // if the appearance field is NULL or unspecified, lighting is off and the unlit object color is (0, 0, 0)
  590. var material = new MeshBasicMaterial( { color: 0x000000 } );
  591. var geometry;
  592. for ( var i = 0, l = fields.length; i < l; i ++ ) {
  593. var field = fields[ i ];
  594. var fieldName = field.name;
  595. var fieldValues = field.values;
  596. switch ( fieldName ) {
  597. case 'appearance':
  598. if ( fieldValues[ 0 ] !== null ) {
  599. material = getNode( fieldValues[ 0 ] );
  600. }
  601. break;
  602. case 'geometry':
  603. if ( fieldValues[ 0 ] !== null ) {
  604. geometry = getNode( fieldValues[ 0 ] );
  605. }
  606. break;
  607. default:
  608. console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
  609. break;
  610. }
  611. }
  612. // build 3D object
  613. var object;
  614. if ( geometry && geometry.attributes.position ) {
  615. var type = geometry._type;
  616. if ( type === 'points' ) { // points
  617. var pointsMaterial = new PointsMaterial( { color: 0xffffff } );
  618. if ( geometry.attributes.color !== undefined ) {
  619. pointsMaterial.vertexColors = VertexColors;
  620. } else {
  621. // if the color field is NULL and there is a material defined for the appearance affecting this PointSet, then use the emissiveColor of the material to draw the points
  622. if ( material.isMeshPhongMaterial ) {
  623. pointsMaterial.color.copy( material.emissive );
  624. }
  625. }
  626. object = new Points( geometry, pointsMaterial );
  627. } else if ( type === 'line' ) { // lines
  628. var lineMaterial = new LineBasicMaterial( { color: 0xffffff } );
  629. if ( geometry.attributes.color !== undefined ) {
  630. lineMaterial.vertexColors = VertexColors;
  631. } else {
  632. // if the color field is NULL and there is a material defined for the appearance affecting this IndexedLineSet, then use the emissiveColor of the material to draw the lines
  633. if ( material.isMeshPhongMaterial ) {
  634. lineMaterial.color.copy( material.emissive );
  635. }
  636. }
  637. object = new LineSegments( geometry, lineMaterial );
  638. } else { // consider meshes
  639. // check "solid" hint (it's placed in the geometry but affects the material)
  640. if ( geometry._solid !== undefined ) {
  641. material.side = ( geometry._solid ) ? FrontSide : DoubleSide;
  642. }
  643. // check for vertex colors
  644. if ( geometry.attributes.color !== undefined ) {
  645. material.vertexColors = VertexColors;
  646. }
  647. object = new Mesh( geometry, material );
  648. }
  649. } else {
  650. object = new Object3D();
  651. // if the geometry field is NULL or no vertices are defined the object is not drawn
  652. object.visible = false;
  653. }
  654. return object;
  655. }
  656. function buildApperanceNode( node ) {
  657. var material = new MeshPhongMaterial();
  658. var transformData;
  659. var fields = node.fields;
  660. for ( var i = 0, l = fields.length; i < l; i ++ ) {
  661. var field = fields[ i ];
  662. var fieldName = field.name;
  663. var fieldValues = field.values;
  664. switch ( fieldName ) {
  665. case 'material':
  666. if ( fieldValues[ 0 ] !== null ) {
  667. var materialData = getNode( fieldValues[ 0 ] );
  668. if ( materialData.diffuseColor ) material.color.copy( materialData.diffuseColor );
  669. if ( materialData.emissiveColor ) material.emissive.copy( materialData.emissiveColor );
  670. if ( materialData.shininess ) material.shininess = materialData.shininess;
  671. if ( materialData.specularColor ) material.specular.copy( materialData.specularColor );
  672. if ( materialData.transparency ) material.opacity = 1 - materialData.transparency;
  673. if ( materialData.transparency > 0 ) material.transparent = true;
  674. } else {
  675. // if the material field is NULL or unspecified, lighting is off and the unlit object color is (0, 0, 0)
  676. material = new MeshBasicMaterial( { color: 0x000000 } );
  677. }
  678. break;
  679. case 'texture':
  680. var textureNode = fieldValues[ 0 ];
  681. if ( textureNode !== null ) {
  682. if ( textureNode.name === 'ImageTexture' ) {
  683. material.map = getNode( textureNode );
  684. } else {
  685. // MovieTexture and PixelTexture not supported yet
  686. }
  687. }
  688. break;
  689. case 'textureTransform':
  690. if ( fieldValues[ 0 ] !== null ) {
  691. transformData = getNode( fieldValues[ 0 ] );
  692. }
  693. break;
  694. default:
  695. console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
  696. break;
  697. }
  698. }
  699. // only apply texture transform data if a texture was defined
  700. if ( material.map && transformData ) {
  701. material.map.center.copy( transformData.center );
  702. material.map.rotation = transformData.rotation;
  703. material.map.repeat.copy( transformData.scale );
  704. material.map.offset.copy( transformData.translation );
  705. }
  706. return material;
  707. }
  708. function buildMaterialNode( node ) {
  709. var materialData = {};
  710. var fields = node.fields;
  711. for ( var i = 0, l = fields.length; i < l; i ++ ) {
  712. var field = fields[ i ];
  713. var fieldName = field.name;
  714. var fieldValues = field.values;
  715. switch ( fieldName ) {
  716. case 'ambientIntensity':
  717. // field not supported
  718. break;
  719. case 'diffuseColor':
  720. materialData.diffuseColor = new Color( fieldValues[ 0 ], fieldValues[ 1 ], fieldValues[ 2 ] );
  721. break;
  722. case 'emissiveColor':
  723. materialData.emissiveColor = new Color( fieldValues[ 0 ], fieldValues[ 1 ], fieldValues[ 2 ] );
  724. break;
  725. case 'shininess':
  726. materialData.shininess = fieldValues[ 0 ];
  727. break;
  728. case 'specularColor':
  729. materialData.emissiveColor = new Color( fieldValues[ 0 ], fieldValues[ 1 ], fieldValues[ 2 ] );
  730. break;
  731. case 'transparency':
  732. materialData.transparency = fieldValues[ 0 ];
  733. break;
  734. default:
  735. console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
  736. break;
  737. }
  738. }
  739. return materialData;
  740. }
  741. function buildImageTextureNode( node ) {
  742. var texture;
  743. var wrapS = RepeatWrapping;
  744. var wrapT = RepeatWrapping;
  745. var fields = node.fields;
  746. for ( var i = 0, l = fields.length; i < l; i ++ ) {
  747. var field = fields[ i ];
  748. var fieldName = field.name;
  749. var fieldValues = field.values;
  750. switch ( fieldName ) {
  751. case 'url':
  752. var url = fieldValues[ 0 ];
  753. if ( url ) texture = textureLoader.load( url );
  754. break;
  755. case 'repeatS':
  756. if ( fieldValues[ 0 ] === false ) wrapS = ClampToEdgeWrapping;
  757. break;
  758. case 'repeatT':
  759. if ( fieldValues[ 0 ] === false ) wrapT = ClampToEdgeWrapping;
  760. break;
  761. default:
  762. console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
  763. break;
  764. }
  765. }
  766. if ( texture ) {
  767. texture.wrapS = wrapS;
  768. texture.wrapT = wrapT;
  769. }
  770. return texture;
  771. }
  772. function buildTextureTransformNode( node ) {
  773. var transformData = {
  774. center: new Vector2(),
  775. rotation: new Vector2(),
  776. scale: new Vector2(),
  777. translation: new Vector2()
  778. };
  779. var fields = node.fields;
  780. for ( var i = 0, l = fields.length; i < l; i ++ ) {
  781. var field = fields[ i ];
  782. var fieldName = field.name;
  783. var fieldValues = field.values;
  784. switch ( fieldName ) {
  785. case 'center':
  786. transformData.center.set( fieldValues[ 0 ], fieldValues[ 1 ] );
  787. break;
  788. case 'rotation':
  789. transformData.rotation = fieldValues[ 0 ];
  790. break;
  791. case 'scale':
  792. transformData.scale.set( fieldValues[ 0 ], fieldValues[ 1 ] );
  793. break;
  794. case 'translation':
  795. transformData.translation.set( fieldValues[ 0 ], fieldValues[ 1 ] );
  796. break;
  797. default:
  798. console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
  799. break;
  800. }
  801. }
  802. return transformData;
  803. }
  804. function buildGeometricNode( node ) {
  805. return node.fields[ 0 ].values;
  806. }
  807. function buildIndexedFaceSetNode( node ) {
  808. var color, coord, normal, texCoord;
  809. var ccw = true, solid = true, creaseAngle;
  810. var colorIndex, coordIndex, normalIndex, texCoordIndex;
  811. var colorPerVertex = true, normalPerVertex = true;
  812. var fields = node.fields;
  813. for ( var i = 0, l = fields.length; i < l; i ++ ) {
  814. var field = fields[ i ];
  815. var fieldName = field.name;
  816. var fieldValues = field.values;
  817. switch ( fieldName ) {
  818. case 'color':
  819. var colorNode = fieldValues[ 0 ];
  820. if ( colorNode !== null ) {
  821. color = getNode( colorNode );
  822. }
  823. break;
  824. case 'coord':
  825. var coordNode = fieldValues[ 0 ];
  826. if ( coordNode !== null ) {
  827. coord = getNode( coordNode );
  828. }
  829. break;
  830. case 'normal':
  831. var normalNode = fieldValues[ 0 ];
  832. if ( normalNode !== null ) {
  833. normal = getNode( normalNode );
  834. }
  835. break;
  836. case 'texCoord':
  837. var texCoordNode = fieldValues[ 0 ];
  838. if ( texCoordNode !== null ) {
  839. texCoord = getNode( texCoordNode );
  840. }
  841. break;
  842. case 'ccw':
  843. ccw = fieldValues[ 0 ];
  844. break;
  845. case 'colorIndex':
  846. colorIndex = fieldValues;
  847. break;
  848. case 'colorPerVertex':
  849. colorPerVertex = fieldValues[ 0 ];
  850. break;
  851. case 'convex':
  852. // field not supported
  853. break;
  854. case 'coordIndex':
  855. coordIndex = fieldValues;
  856. break;
  857. case 'creaseAngle':
  858. creaseAngle = fieldValues[ 0 ];
  859. break;
  860. case 'normalIndex':
  861. normalIndex = fieldValues;
  862. break;
  863. case 'normalPerVertex':
  864. normalPerVertex = fieldValues[ 0 ];
  865. break;
  866. case 'solid':
  867. solid = fieldValues[ 0 ];
  868. break;
  869. case 'texCoordIndex':
  870. texCoordIndex = fieldValues;
  871. break;
  872. default:
  873. console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
  874. break;
  875. }
  876. }
  877. if ( coordIndex === undefined ) {
  878. console.warn( 'THREE.VRMLLoader: Missing coordIndex.' );
  879. return new BufferGeometry(); // handle VRML files with incomplete geometry definition
  880. }
  881. var triangulatedCoordIndex = triangulateFaceIndex( coordIndex, ccw );
  882. var positionAttribute;
  883. var colorAttribute;
  884. var normalAttribute;
  885. var uvAttribute;
  886. if ( color ) {
  887. if ( colorPerVertex === true ) {
  888. if ( colorIndex && colorIndex.length > 0 ) {
  889. // if the colorIndex field is not empty, then it is used to choose colors for each vertex of the IndexedFaceSet.
  890. var triangulatedColorIndex = triangulateFaceIndex( colorIndex, ccw );
  891. colorAttribute = computeAttributeFromIndexedData( triangulatedCoordIndex, triangulatedColorIndex, color, 3 );
  892. } else {
  893. // if the colorIndex field is empty, then the coordIndex field is used to choose colors from the Color node
  894. colorAttribute = toNonIndexedAttribute( triangulatedCoordIndex, new Float32BufferAttribute( color, 3 ) );
  895. }
  896. } else {
  897. if ( colorIndex && colorIndex.length > 0 ) {
  898. // if the colorIndex field is not empty, then they are used to choose one color for each face of the IndexedFaceSet
  899. var flattenFaceColors = flattenData( color, colorIndex );
  900. var triangulatedFaceColors = triangulateFaceData( flattenFaceColors, coordIndex );
  901. colorAttribute = computeAttributeFromFaceData( triangulatedCoordIndex, triangulatedFaceColors );
  902. } else {
  903. // if the colorIndex field is empty, then the color are applied to each face of the IndexedFaceSet in order
  904. var triangulatedFaceColors = triangulateFaceData( color, coordIndex );
  905. colorAttribute = computeAttributeFromFaceData( triangulatedCoordIndex, triangulatedFaceColors );
  906. }
  907. }
  908. }
  909. if ( normal ) {
  910. if ( normalPerVertex === true ) {
  911. // consider vertex normals
  912. if ( normalIndex && normalIndex.length > 0 ) {
  913. // if the normalIndex field is not empty, then it is used to choose normals for each vertex of the IndexedFaceSet.
  914. var triangulatedNormalIndex = triangulateFaceIndex( normalIndex, ccw );
  915. normalAttribute = computeAttributeFromIndexedData( triangulatedCoordIndex, triangulatedNormalIndex, normal, 3 );
  916. } else {
  917. // if the normalIndex field is empty, then the coordIndex field is used to choose normals from the Normal node
  918. normalAttribute = toNonIndexedAttribute( triangulatedCoordIndex, new Float32BufferAttribute( normal, 3 ) );
  919. }
  920. } else {
  921. // consider face normals
  922. if ( normalIndex && normalIndex.length > 0 ) {
  923. // if the normalIndex field is not empty, then they are used to choose one normal for each face of the IndexedFaceSet
  924. var flattenFaceNormals = flattenData( normal, normalIndex );
  925. var triangulatedFaceNormals = triangulateFaceData( flattenFaceNormals, coordIndex );
  926. normalAttribute = computeAttributeFromFaceData( triangulatedCoordIndex, triangulatedFaceNormals );
  927. } else {
  928. // if the normalIndex field is empty, then the normals are applied to each face of the IndexedFaceSet in order
  929. var triangulatedFaceNormals = triangulateFaceData( normal, coordIndex );
  930. normalAttribute = computeAttributeFromFaceData( triangulatedCoordIndex, triangulatedFaceNormals );
  931. }
  932. }
  933. } else {
  934. // if the normal field is NULL, then the loader should automatically generate normals, using creaseAngle to determine if and how normals are smoothed across shared vertices
  935. normalAttribute = computeNormalAttribute( triangulatedCoordIndex, coord, creaseAngle );
  936. }
  937. if ( texCoord ) {
  938. // texture coordinates are always defined on vertex level
  939. if ( texCoordIndex && texCoordIndex.length > 0 ) {
  940. // if the texCoordIndex field is not empty, then it is used to choose texture coordinates for each vertex of the IndexedFaceSet.
  941. var triangulatedTexCoordIndex = triangulateFaceIndex( texCoordIndex, ccw );
  942. uvAttribute = computeAttributeFromIndexedData( triangulatedCoordIndex, triangulatedTexCoordIndex, texCoord, 2 );
  943. } else {
  944. // if the texCoordIndex field is empty, then the coordIndex array is used to choose texture coordinates from the TextureCoordinate node
  945. uvAttribute = toNonIndexedAttribute( triangulatedCoordIndex, new Float32BufferAttribute( texCoord, 2 ) );
  946. }
  947. }
  948. var geometry = new BufferGeometry();
  949. positionAttribute = toNonIndexedAttribute( triangulatedCoordIndex, new Float32BufferAttribute( coord, 3 ) );
  950. geometry.addAttribute( 'position', positionAttribute );
  951. geometry.addAttribute( 'normal', normalAttribute );
  952. // optional attributes
  953. if ( colorAttribute ) geometry.addAttribute( 'color', colorAttribute );
  954. if ( uvAttribute ) geometry.addAttribute( 'uv', uvAttribute );
  955. // "solid" influences the material so let's store it for later use
  956. geometry._solid = solid;
  957. geometry._type = 'mesh';
  958. return geometry;
  959. }
  960. function buildIndexedLineSetNode( node ) {
  961. var color, coord;
  962. var colorIndex, coordIndex;
  963. var colorPerVertex = true;
  964. var fields = node.fields;
  965. for ( var i = 0, l = fields.length; i < l; i ++ ) {
  966. var field = fields[ i ];
  967. var fieldName = field.name;
  968. var fieldValues = field.values;
  969. switch ( fieldName ) {
  970. case 'color':
  971. var colorNode = fieldValues[ 0 ];
  972. if ( colorNode !== null ) {
  973. color = getNode( colorNode );
  974. }
  975. break;
  976. case 'coord':
  977. var coordNode = fieldValues[ 0 ];
  978. if ( coordNode !== null ) {
  979. coord = getNode( coordNode );
  980. }
  981. break;
  982. case 'colorIndex':
  983. colorIndex = fieldValues;
  984. break;
  985. case 'colorPerVertex':
  986. colorPerVertex = fieldValues[ 0 ];
  987. break;
  988. case 'coordIndex':
  989. coordIndex = fieldValues;
  990. break;
  991. default:
  992. console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
  993. break;
  994. }
  995. }
  996. // build lines
  997. var colorAttribute;
  998. var expandedLineIndex = expandLineIndex( coordIndex ); // create an index for three.js's linesegment primitive
  999. if ( color ) {
  1000. if ( colorPerVertex === true ) {
  1001. if ( colorIndex.length > 0 ) {
  1002. // if the colorIndex field is not empty, then one color is used for each polyline of the IndexedLineSet.
  1003. var expandedColorIndex = expandLineIndex( colorIndex ); // compute colors for each line segment (rendering primitve)
  1004. colorAttribute = computeAttributeFromIndexedData( expandedLineIndex, expandedColorIndex, color, 3 ); // compute data on vertex level
  1005. } else {
  1006. // if the colorIndex field is empty, then the colors are applied to each polyline of the IndexedLineSet in order.
  1007. colorAttribute = toNonIndexedAttribute( expandedLineIndex, new Float32BufferAttribute( color, 3 ) );
  1008. }
  1009. } else {
  1010. if ( colorIndex.length > 0 ) {
  1011. // if the colorIndex field is not empty, then colors are applied to each vertex of the IndexedLineSet
  1012. var flattenLineColors = flattenData( color, colorIndex ); // compute colors for each VRML primitve
  1013. var expandedLineColors = expandLineData( flattenLineColors, coordIndex ); // compute colors for each line segment (rendering primitve)
  1014. colorAttribute = computeAttributeFromLineData( expandedLineIndex, expandedLineColors ); // compute data on vertex level
  1015. } else {
  1016. // if the colorIndex field is empty, then the coordIndex field is used to choose colors from the Color node
  1017. var expandedLineColors = expandLineData( color, coordIndex ); // compute colors for each line segment (rendering primitve)
  1018. colorAttribute = computeAttributeFromLineData( expandedLineIndex, expandedLineColors ); // compute data on vertex level
  1019. }
  1020. }
  1021. }
  1022. //
  1023. var geometry = new BufferGeometry();
  1024. var positionAttribute = toNonIndexedAttribute( expandedLineIndex, new Float32BufferAttribute( coord, 3 ) );
  1025. geometry.addAttribute( 'position', positionAttribute );
  1026. if ( colorAttribute ) geometry.addAttribute( 'color', colorAttribute );
  1027. geometry._type = 'line';
  1028. return geometry;
  1029. }
  1030. function buildPointSetNode( node ) {
  1031. var geometry;
  1032. var color, coord;
  1033. var fields = node.fields;
  1034. for ( var i = 0, l = fields.length; i < l; i ++ ) {
  1035. var field = fields[ i ];
  1036. var fieldName = field.name;
  1037. var fieldValues = field.values;
  1038. switch ( fieldName ) {
  1039. case 'color':
  1040. var colorNode = fieldValues[ 0 ];
  1041. if ( colorNode !== null ) {
  1042. color = getNode( colorNode );
  1043. }
  1044. break;
  1045. case 'coord':
  1046. var coordNode = fieldValues[ 0 ];
  1047. if ( coordNode !== null ) {
  1048. coord = getNode( coordNode );
  1049. }
  1050. break;
  1051. default:
  1052. console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
  1053. break;
  1054. }
  1055. }
  1056. var geometry = new BufferGeometry();
  1057. geometry.addAttribute( 'position', new Float32BufferAttribute( coord, 3 ) );
  1058. if ( color ) geometry.addAttribute( 'color', new Float32BufferAttribute( color, 3 ) );
  1059. geometry._type = 'points';
  1060. return geometry;
  1061. }
  1062. function buildBoxNode( node ) {
  1063. var size = new Vector3( 2, 2, 2 );
  1064. var fields = node.fields;
  1065. for ( var i = 0, l = fields.length; i < l; i ++ ) {
  1066. var field = fields[ i ];
  1067. var fieldName = field.name;
  1068. var fieldValues = field.values;
  1069. switch ( fieldName ) {
  1070. case 'size':
  1071. size.x = fieldValues[ 0 ];
  1072. size.y = fieldValues[ 1 ];
  1073. size.z = fieldValues[ 2 ];
  1074. break;
  1075. default:
  1076. console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
  1077. break;
  1078. }
  1079. }
  1080. var geometry = new BoxBufferGeometry( size.x, size.y, size.z );
  1081. return geometry;
  1082. }
  1083. function buildConeNode( node ) {
  1084. var radius = 1, height = 2, openEnded = false;
  1085. var fields = node.fields;
  1086. for ( var i = 0, l = fields.length; i < l; i ++ ) {
  1087. var field = fields[ i ];
  1088. var fieldName = field.name;
  1089. var fieldValues = field.values;
  1090. switch ( fieldName ) {
  1091. case 'bottom':
  1092. openEnded = ! fieldValues[ 0 ];
  1093. break;
  1094. case 'bottomRadius':
  1095. radius = fieldValues[ 0 ];
  1096. break;
  1097. case 'height':
  1098. height = fieldValues[ 0 ];
  1099. break;
  1100. case 'side':
  1101. // field not supported
  1102. break;
  1103. default:
  1104. console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
  1105. break;
  1106. }
  1107. }
  1108. var geometry = new ConeBufferGeometry( radius, height, 16, 1, openEnded );
  1109. return geometry;
  1110. }
  1111. function buildCylinderNode( node ) {
  1112. var radius = 1, height = 2;
  1113. var fields = node.fields;
  1114. for ( var i = 0, l = fields.length; i < l; i ++ ) {
  1115. var field = fields[ i ];
  1116. var fieldName = field.name;
  1117. var fieldValues = field.values;
  1118. switch ( fieldName ) {
  1119. case 'bottom':
  1120. // field not supported
  1121. break;
  1122. case 'radius':
  1123. radius = fieldValues[ 0 ];
  1124. break;
  1125. case 'height':
  1126. height = fieldValues[ 0 ];
  1127. break;
  1128. case 'side':
  1129. // field not supported
  1130. break;
  1131. case 'top':
  1132. // field not supported
  1133. break;
  1134. default:
  1135. console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
  1136. break;
  1137. }
  1138. }
  1139. var geometry = new CylinderBufferGeometry( radius, radius, height, 16, 1 );
  1140. return geometry;
  1141. }
  1142. function buildSphereNode( node ) {
  1143. var radius = 1;
  1144. var fields = node.fields;
  1145. for ( var i = 0, l = fields.length; i < l; i ++ ) {
  1146. var field = fields[ i ];
  1147. var fieldName = field.name;
  1148. var fieldValues = field.values;
  1149. switch ( fieldName ) {
  1150. case 'radius':
  1151. radius = fieldValues[ 0 ];
  1152. break;
  1153. default:
  1154. console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
  1155. break;
  1156. }
  1157. }
  1158. var geometry = new SphereBufferGeometry( radius, 16, 16 );
  1159. return geometry;
  1160. }
  1161. // helper functions
  1162. function resolveUSE( identifier ) {
  1163. var node = nodeMap[ identifier ];
  1164. var build = getNode( node );
  1165. // because the same 3D objects can have different transformations, it's necessary to clone them.
  1166. // materials can be influenced by the geometry (e.g. vertex normals). cloning is necessary to avoid
  1167. // any side effects
  1168. return ( build.isObject3D || build.isMaterial ) ? build.clone() : build;
  1169. }
  1170. function parseFieldChildren( children, owner ) {
  1171. for ( var i = 0, l = children.length; i < l; i ++ ) {
  1172. var object = getNode( children[ i ] );
  1173. if ( object instanceof Object3D ) owner.add( object );
  1174. }
  1175. }
  1176. function triangulateFaceIndex( index, ccw ) {
  1177. var indices = [];
  1178. // since face defintions can have more than three vertices, it's necessary to
  1179. // perform a simple triangulation
  1180. var start = 0;
  1181. for ( var i = 0, l = index.length; i < l; i ++ ) {
  1182. var i1 = index[ start ];
  1183. var i2 = index[ i + ( ccw ? 1 : 2 ) ];
  1184. var i3 = index[ i + ( ccw ? 2 : 1 ) ];
  1185. indices.push( i1, i2, i3 );
  1186. // an index of -1 indicates that the current face has ended and the next one begins
  1187. if ( index[ i + 3 ] === - 1 || i + 3 >= l ) {
  1188. i += 3;
  1189. start = i + 1;
  1190. }
  1191. }
  1192. return indices;
  1193. }
  1194. function triangulateFaceData( data, index ) {
  1195. var triangulatedData = [];
  1196. var start = 0;
  1197. for ( var i = 0, l = index.length; i < l; i ++ ) {
  1198. var stride = start * 3;
  1199. var x = data[ stride ];
  1200. var y = data[ stride + 1 ];
  1201. var z = data[ stride + 2 ];
  1202. triangulatedData.push( x, y, z );
  1203. // an index of -1 indicates that the current face has ended and the next one begins
  1204. if ( index[ i + 3 ] === - 1 || i + 3 >= l ) {
  1205. i += 3;
  1206. start ++;
  1207. }
  1208. }
  1209. return triangulatedData;
  1210. }
  1211. function flattenData( data, index ) {
  1212. var flattenData = [];
  1213. for ( var i = 0, l = index.length; i < l; i ++ ) {
  1214. var i1 = index[ i ];
  1215. var stride = i1 * 3;
  1216. var x = data[ stride ];
  1217. var y = data[ stride + 1 ];
  1218. var z = data[ stride + 2 ];
  1219. flattenData.push( x, y, z );
  1220. }
  1221. return flattenData;
  1222. }
  1223. function expandLineIndex( index ) {
  1224. var indices = [];
  1225. for ( var i = 0, l = index.length; i < l; i ++ ) {
  1226. var i1 = index[ i ];
  1227. var i2 = index[ i + 1 ];
  1228. indices.push( i1, i2 );
  1229. // an index of -1 indicates that the current line has ended and the next one begins
  1230. if ( index[ i + 2 ] === - 1 || i + 2 >= l ) {
  1231. i += 2;
  1232. }
  1233. }
  1234. return indices;
  1235. }
  1236. function expandLineData( data, index ) {
  1237. var triangulatedData = [];
  1238. var start = 0;
  1239. for ( var i = 0, l = index.length; i < l; i ++ ) {
  1240. var stride = start * 3;
  1241. var x = data[ stride ];
  1242. var y = data[ stride + 1 ];
  1243. var z = data[ stride + 2 ];
  1244. triangulatedData.push( x, y, z );
  1245. // an index of -1 indicates that the current line has ended and the next one begins
  1246. if ( index[ i + 2 ] === - 1 || i + 2 >= l ) {
  1247. i += 2;
  1248. start ++;
  1249. }
  1250. }
  1251. return triangulatedData;
  1252. }
  1253. var vA = new Vector3();
  1254. var vB = new Vector3();
  1255. var vC = new Vector3();
  1256. var uvA = new Vector2();
  1257. var uvB = new Vector2();
  1258. var uvC = new Vector2();
  1259. function computeAttributeFromIndexedData( coordIndex, index, data, itemSize ) {
  1260. var array = [];
  1261. // we use the coordIndex.length as delimiter since normalIndex must contain at least as many indices
  1262. for ( var i = 0, l = coordIndex.length; i < l; i += 3 ) {
  1263. var a = index[ i ];
  1264. var b = index[ i + 1 ];
  1265. var c = index[ i + 2 ];
  1266. if ( itemSize === 2 ) {
  1267. uvA.fromArray( data, a * itemSize );
  1268. uvB.fromArray( data, b * itemSize );
  1269. uvC.fromArray( data, c * itemSize );
  1270. array.push( uvA.x, uvA.y );
  1271. array.push( uvB.x, uvB.y );
  1272. array.push( uvC.x, uvC.y );
  1273. } else {
  1274. vA.fromArray( data, a * itemSize );
  1275. vB.fromArray( data, b * itemSize );
  1276. vC.fromArray( data, c * itemSize );
  1277. array.push( vA.x, vA.y, vA.z );
  1278. array.push( vB.x, vB.y, vB.z );
  1279. array.push( vC.x, vC.y, vC.z );
  1280. }
  1281. }
  1282. return new Float32BufferAttribute( array, itemSize );
  1283. }
  1284. function computeAttributeFromFaceData( index, faceData ) {
  1285. var array = [];
  1286. for ( var i = 0, j = 0, l = index.length; i < l; i += 3, j ++ ) {
  1287. vA.fromArray( faceData, j * 3 );
  1288. array.push( vA.x, vA.y, vA.z );
  1289. array.push( vA.x, vA.y, vA.z );
  1290. array.push( vA.x, vA.y, vA.z );
  1291. }
  1292. return new Float32BufferAttribute( array, 3 );
  1293. }
  1294. function computeAttributeFromLineData( index, lineData ) {
  1295. var array = [];
  1296. for ( var i = 0, j = 0, l = index.length; i < l; i += 2, j ++ ) {
  1297. vA.fromArray( lineData, j * 3 );
  1298. array.push( vA.x, vA.y, vA.z );
  1299. array.push( vA.x, vA.y, vA.z );
  1300. }
  1301. return new Float32BufferAttribute( array, 3 );
  1302. }
  1303. function toNonIndexedAttribute( indices, attribute ) {
  1304. var array = attribute.array;
  1305. var itemSize = attribute.itemSize;
  1306. var array2 = new array.constructor( indices.length * itemSize );
  1307. var index = 0, index2 = 0;
  1308. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  1309. index = indices[ i ] * itemSize;
  1310. for ( var j = 0; j < itemSize; j ++ ) {
  1311. array2[ index2 ++ ] = array[ index ++ ];
  1312. }
  1313. }
  1314. return new Float32BufferAttribute( array2, itemSize );
  1315. }
  1316. var ab = new Vector3();
  1317. var cb = new Vector3();
  1318. function computeNormalAttribute( index, coord, creaseAngle ) {
  1319. var faces = [];
  1320. var vertexNormals = {};
  1321. // prepare face and raw vertex normals
  1322. for ( var i = 0, l = index.length; i < l; i += 3 ) {
  1323. var a = index[ i ];
  1324. var b = index[ i + 1 ];
  1325. var c = index[ i + 2 ];
  1326. var face = new Face( a, b, c );
  1327. vA.fromArray( coord, a * 3 );
  1328. vB.fromArray( coord, b * 3 );
  1329. vC.fromArray( coord, c * 3 );
  1330. cb.subVectors( vC, vB );
  1331. ab.subVectors( vA, vB );
  1332. cb.cross( ab );
  1333. cb.normalize();
  1334. face.normal.copy( cb );
  1335. if ( vertexNormals[ a ] === undefined ) vertexNormals[ a ] = [];
  1336. if ( vertexNormals[ b ] === undefined ) vertexNormals[ b ] = [];
  1337. if ( vertexNormals[ c ] === undefined ) vertexNormals[ c ] = [];
  1338. vertexNormals[ a ].push( face.normal );
  1339. vertexNormals[ b ].push( face.normal );
  1340. vertexNormals[ c ].push( face.normal );
  1341. faces.push( face );
  1342. }
  1343. // compute vertex normals and build final geometry
  1344. var normals = [];
  1345. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  1346. var face = faces[ i ];
  1347. var nA = weightedNormal( vertexNormals[ face.a ], face.normal, creaseAngle );
  1348. var nB = weightedNormal( vertexNormals[ face.b ], face.normal, creaseAngle );
  1349. var nC = weightedNormal( vertexNormals[ face.c ], face.normal, creaseAngle );
  1350. vA.fromArray( coord, face.a * 3 );
  1351. vB.fromArray( coord, face.b * 3 );
  1352. vC.fromArray( coord, face.c * 3 );
  1353. normals.push( nA.x, nA.y, nA.z );
  1354. normals.push( nB.x, nB.y, nB.z );
  1355. normals.push( nC.x, nC.y, nC.z );
  1356. }
  1357. return new Float32BufferAttribute( normals, 3 );
  1358. }
  1359. function weightedNormal( normals, vector, creaseAngle ) {
  1360. var normal = vector.clone();
  1361. for ( var i = 0, l = normals.length; i < l; i ++ ) {
  1362. if ( normals[ i ].angleTo( vector ) < creaseAngle ) {
  1363. normal.add( normals[ i ] );
  1364. }
  1365. }
  1366. return normal.normalize();
  1367. }
  1368. function toColorArray( colors ) {
  1369. var array = [];
  1370. for ( var i = 0, l = colors.length; i < l; i += 3 ) {
  1371. array.push( new Color( colors[ i ], colors[ i + 1 ], colors[ i + 2 ] ) );
  1372. }
  1373. return array;
  1374. }
  1375. /**
  1376. * Vertically paints the faces interpolating between the
  1377. * specified colors at the specified angels. This is used for the Background
  1378. * node, but could be applied to other nodes with multiple faces as well.
  1379. *
  1380. * When used with the Background node, default is directionIsDown is true if
  1381. * interpolating the skyColor down from the Zenith. When interpolationg up from
  1382. * the Nadir i.e. interpolating the groundColor, the directionIsDown is false.
  1383. *
  1384. * The first angle is never specified, it is the Zenith (0 rad). Angles are specified
  1385. * in radians. The geometry is thought a sphere, but could be anything. The color interpolation
  1386. * is linear along the Y axis in any case.
  1387. *
  1388. * You must specify one more color than you have angles at the beginning of the colors array.
  1389. * This is the color of the Zenith (the top of the shape).
  1390. *
  1391. * @param {BufferGeometry} geometry
  1392. * @param {number} radius
  1393. * @param {array} angles
  1394. * @param {array} colors
  1395. * @param {boolean} topDown - Whether to work top down or bottom up.
  1396. */
  1397. function paintFaces( geometry, radius, angles, colors, topDown ) {
  1398. var direction = ( topDown === true ) ? 1 : - 1;
  1399. var coord = [], A = {}, B = {}, applyColor = false;
  1400. for ( var k = 0; k < angles.length; k ++ ) {
  1401. // push the vector at which the color changes
  1402. var vec = {
  1403. x: direction * ( Math.cos( angles[ k ] ) * radius ),
  1404. y: direction * ( Math.sin( angles[ k ] ) * radius )
  1405. };
  1406. coord.push( vec );
  1407. }
  1408. var index = geometry.index;
  1409. var positionAttribute = geometry.attributes.position;
  1410. var colorAttribute = new BufferAttribute( new Float32Array( geometry.attributes.position.count * 3 ), 3 );
  1411. var position = new Vector3();
  1412. var color = new Color();
  1413. for ( var i = 0; i < index.count; i ++ ) {
  1414. var vertexIndex = index.getX( i );
  1415. position.fromBufferAttribute( positionAttribute, vertexIndex );
  1416. for ( var j = 0; j < colors.length; j ++ ) {
  1417. // linear interpolation between aColor and bColor, calculate proportion
  1418. // A is previous point (angle)
  1419. if ( j === 0 ) {
  1420. A.x = 0;
  1421. A.y = ( topDown === true ) ? radius : - 1 * radius;
  1422. } else {
  1423. A.x = coord[ j - 1 ].x;
  1424. A.y = coord[ j - 1 ].y;
  1425. }
  1426. // B is current point (angle)
  1427. B = coord[ j ];
  1428. if ( B !== undefined ) {
  1429. // p has to be between the points A and B which we interpolate
  1430. applyColor = ( topDown === true ) ? ( position.y <= A.y && position.y > B.y ) : ( position.y >= A.y && position.y < B.y );
  1431. if ( applyColor === true ) {
  1432. var aColor = colors[ j ];
  1433. var bColor = colors[ j + 1 ];
  1434. // below is simple linear interpolation
  1435. var t = Math.abs( position.y - A.y ) / ( A.y - B.y );
  1436. // to make it faster, you can only calculate this if the y coord changes, the color is the same for points with the same y
  1437. color.copy( aColor ).lerp( bColor, t );
  1438. colorAttribute.setXYZ( vertexIndex, color.r, color.g, color.b );
  1439. } else {
  1440. var colorIndex = ( topDown === true ) ? colors.length - 1 : 0;
  1441. var c = colors[ colorIndex ];
  1442. colorAttribute.setXYZ( vertexIndex, c.r, c.g, c.b );
  1443. }
  1444. }
  1445. }
  1446. }
  1447. geometry.addAttribute( 'color', colorAttribute );
  1448. }
  1449. //
  1450. var textureLoader = new TextureLoader( this.manager );
  1451. textureLoader.setPath( this.resourcePath || path ).setCrossOrigin( this.crossOrigin );
  1452. // create JSON representing the tree structure of the VRML asset
  1453. var tree = generateVRMLTree( data );
  1454. // check version (only 2.0 is supported)
  1455. if ( tree.version.indexOf( 'V2.0' ) === - 1 ) {
  1456. throw Error( 'THREE.VRMLLexer: Version of VRML asset not supported.' );
  1457. }
  1458. // parse the tree structure to a three.js scene
  1459. var scene = parseTree( tree );
  1460. return scene;
  1461. }
  1462. };
  1463. function VRMLLexer( tokens ) {
  1464. this.lexer = new chevrotain.Lexer( tokens );
  1465. }
  1466. VRMLLexer.prototype = {
  1467. constructor: VRMLLexer,
  1468. lex: function ( inputText ) {
  1469. var lexingResult = this.lexer.tokenize( inputText );
  1470. if ( lexingResult.errors.length > 0 ) {
  1471. console.error( lexingResult.errors );
  1472. throw Error( 'THREE.VRMLLexer: Lexing errors detected.' );
  1473. }
  1474. return lexingResult;
  1475. }
  1476. };
  1477. function VRMLParser( tokenVocabulary ) {
  1478. chevrotain.Parser.call( this, tokenVocabulary );
  1479. var $ = this;
  1480. var Version = tokenVocabulary[ 'Version' ];
  1481. var LCurly = tokenVocabulary[ 'LCurly' ];
  1482. var RCurly = tokenVocabulary[ 'RCurly' ];
  1483. var LSquare = tokenVocabulary[ 'LSquare' ];
  1484. var RSquare = tokenVocabulary[ 'RSquare' ];
  1485. var Identifier = tokenVocabulary[ 'Identifier' ];
  1486. var RouteIdentifier = tokenVocabulary[ 'RouteIdentifier' ];
  1487. var StringLiteral = tokenVocabulary[ 'StringLiteral' ];
  1488. var NumberLiteral = tokenVocabulary[ 'NumberLiteral' ];
  1489. var TrueLiteral = tokenVocabulary[ 'TrueLiteral' ];
  1490. var FalseLiteral = tokenVocabulary[ 'FalseLiteral' ];
  1491. var NullLiteral = tokenVocabulary[ 'NullLiteral' ];
  1492. var DEF = tokenVocabulary[ 'DEF' ];
  1493. var USE = tokenVocabulary[ 'USE' ];
  1494. var ROUTE = tokenVocabulary[ 'ROUTE' ];
  1495. var TO = tokenVocabulary[ 'TO' ];
  1496. var NodeName = tokenVocabulary[ 'NodeName' ];
  1497. $.RULE( 'vrml', function () {
  1498. $.SUBRULE( $.version );
  1499. $.AT_LEAST_ONE( function () {
  1500. $.SUBRULE( $.node );
  1501. } );
  1502. $.MANY( function () {
  1503. $.SUBRULE( $.route );
  1504. } );
  1505. } );
  1506. $.RULE( 'version', function () {
  1507. $.CONSUME( Version );
  1508. } );
  1509. $.RULE( 'node', function () {
  1510. $.OPTION( function () {
  1511. $.SUBRULE( $.def );
  1512. } );
  1513. $.CONSUME( NodeName );
  1514. $.CONSUME( LCurly );
  1515. $.MANY( function () {
  1516. $.SUBRULE( $.field );
  1517. } );
  1518. $.CONSUME( RCurly );
  1519. } );
  1520. $.RULE( 'field', function () {
  1521. $.CONSUME( Identifier );
  1522. $.OR2( [
  1523. { ALT: function () {
  1524. $.SUBRULE( $.singleFieldValue );
  1525. } },
  1526. { ALT: function () {
  1527. $.SUBRULE( $.multiFieldValue );
  1528. } }
  1529. ] );
  1530. } );
  1531. $.RULE( 'def', function () {
  1532. $.CONSUME( DEF );
  1533. $.CONSUME( Identifier );
  1534. } );
  1535. $.RULE( 'use', function () {
  1536. $.CONSUME( USE );
  1537. $.CONSUME( Identifier );
  1538. } );
  1539. $.RULE( 'singleFieldValue', function () {
  1540. $.AT_LEAST_ONE( function () {
  1541. $.OR( [
  1542. { ALT: function () {
  1543. $.SUBRULE( $.node );
  1544. } },
  1545. { ALT: function () {
  1546. $.SUBRULE( $.use );
  1547. } },
  1548. { ALT: function () {
  1549. $.CONSUME( StringLiteral );
  1550. } },
  1551. { ALT: function () {
  1552. $.CONSUME( NumberLiteral );
  1553. } },
  1554. { ALT: function () {
  1555. $.CONSUME( TrueLiteral );
  1556. } },
  1557. { ALT: function () {
  1558. $.CONSUME( FalseLiteral );
  1559. } },
  1560. { ALT: function () {
  1561. $.CONSUME( NullLiteral );
  1562. } }
  1563. ] );
  1564. } );
  1565. } );
  1566. $.RULE( 'multiFieldValue', function () {
  1567. $.CONSUME( LSquare );
  1568. $.MANY( function () {
  1569. $.OR( [
  1570. { ALT: function () {
  1571. $.SUBRULE( $.node );
  1572. } },
  1573. { ALT: function () {
  1574. $.SUBRULE( $.use );
  1575. } },
  1576. { ALT: function () {
  1577. $.CONSUME( StringLiteral );
  1578. } },
  1579. { ALT: function () {
  1580. $.CONSUME( NumberLiteral );
  1581. } },
  1582. { ALT: function () {
  1583. $.CONSUME( NullLiteral );
  1584. } }
  1585. ] );
  1586. } );
  1587. $.CONSUME( RSquare );
  1588. } );
  1589. $.RULE( 'route', function () {
  1590. $.CONSUME( ROUTE );
  1591. $.CONSUME( RouteIdentifier );
  1592. $.CONSUME( TO );
  1593. $.CONSUME2( RouteIdentifier );
  1594. } );
  1595. this.performSelfAnalysis();
  1596. }
  1597. VRMLParser.prototype = Object.create( chevrotain.Parser.prototype );
  1598. VRMLParser.prototype.constructor = VRMLParser;
  1599. function Face( a, b, c ) {
  1600. this.a = a;
  1601. this.b = b;
  1602. this.c = c;
  1603. this.normal = new Vector3();
  1604. }
  1605. return VRMLLoader;
  1606. } )();
  1607. export { VRMLLoader };