VRMLLoader.js 55 KB

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