VRMLLoader.js 55 KB

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