VRMLLoader.js 73 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454
  1. THREE.VRMLLoader = ( function () {
  2. // dependency check
  3. if ( typeof chevrotain === 'undefined' ) { // eslint-disable-line no-undef
  4. throw Error( 'THREE.VRMLLoader: External library chevrotain.min.js required.' );
  5. }
  6. // class definitions
  7. function VRMLLoader( manager ) {
  8. THREE.Loader.call( this, manager );
  9. }
  10. VRMLLoader.prototype = Object.assign( Object.create( THREE.Loader.prototype ), {
  11. constructor: VRMLLoader,
  12. load: function ( url, onLoad, onProgress, onError ) {
  13. var scope = this;
  14. var path = ( scope.path === '' ) ? THREE.LoaderUtils.extractUrlBase( url ) : scope.path;
  15. var loader = new THREE.FileLoader( scope.manager );
  16. loader.setPath( scope.path );
  17. loader.setRequestHeader( scope.requestHeader );
  18. loader.setWithCredentials( scope.withCredentials );
  19. loader.load( url, function ( text ) {
  20. try {
  21. onLoad( scope.parse( text, path ) );
  22. } catch ( e ) {
  23. if ( onError ) {
  24. onError( e );
  25. } else {
  26. console.error( e );
  27. }
  28. scope.manager.itemError( url );
  29. }
  30. }, onProgress, onError );
  31. },
  32. parse: function ( data, path ) {
  33. var nodeMap = {};
  34. function generateVRMLTree( data ) {
  35. // create lexer, parser and visitor
  36. var tokenData = createTokens();
  37. var lexer = new VRMLLexer( tokenData.tokens );
  38. var parser = new VRMLParser( tokenData.tokenVocabulary );
  39. var visitor = createVisitor( parser.getBaseCstVisitorConstructor() );
  40. // lexing
  41. var lexingResult = lexer.lex( data );
  42. parser.input = lexingResult.tokens;
  43. // parsing
  44. var cstOutput = parser.vrml();
  45. if ( parser.errors.length > 0 ) {
  46. console.error( parser.errors );
  47. throw Error( 'THREE.VRMLLoader: Parsing errors detected.' );
  48. }
  49. // actions
  50. var ast = visitor.visit( cstOutput );
  51. return ast;
  52. }
  53. function createTokens() {
  54. var createToken = chevrotain.createToken; // eslint-disable-line no-undef
  55. // from http://gun.teipir.gr/VRML-amgem/spec/part1/concepts.html#SyntaxBasics
  56. 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]*/ } );
  57. 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 } );
  58. // from http://gun.teipir.gr/VRML-amgem/spec/part1/nodesRef.html
  59. var nodeTypes = [
  60. 'Anchor', 'Billboard', 'Collision', 'Group', 'Transform', // grouping nodes
  61. 'Inline', 'LOD', 'Switch', // special groups
  62. 'AudioClip', 'DirectionalLight', 'PointLight', 'Script', 'Shape', 'Sound', 'SpotLight', 'WorldInfo', // common nodes
  63. 'CylinderSensor', 'PlaneSensor', 'ProximitySensor', 'SphereSensor', 'TimeSensor', 'TouchSensor', 'VisibilitySensor', // sensors
  64. 'Box', 'Cone', 'Cylinder', 'ElevationGrid', 'Extrusion', 'IndexedFaceSet', 'IndexedLineSet', 'PointSet', 'Sphere', // geometries
  65. 'Color', 'Coordinate', 'Normal', 'TextureCoordinate', // geometric properties
  66. 'Appearance', 'FontStyle', 'ImageTexture', 'Material', 'MovieTexture', 'PixelTexture', 'TextureTransform', // appearance
  67. 'ColorInterpolator', 'CoordinateInterpolator', 'NormalInterpolator', 'OrientationInterpolator', 'PositionInterpolator', 'ScalarInterpolator', // interpolators
  68. 'Background', 'Fog', 'NavigationInfo', 'Viewpoint', // bindable nodes
  69. 'Text' // Text must be placed at the end of the regex so there are no matches for TextureTransform and TextureCoordinate
  70. ];
  71. //
  72. var Version = createToken( {
  73. name: 'Version',
  74. pattern: /#VRML.*/,
  75. longer_alt: Identifier
  76. } );
  77. var NodeName = createToken( {
  78. name: 'NodeName',
  79. pattern: new RegExp( nodeTypes.join( '|' ) ),
  80. longer_alt: Identifier
  81. } );
  82. var DEF = createToken( {
  83. name: 'DEF',
  84. pattern: /DEF/,
  85. longer_alt: Identifier
  86. } );
  87. var USE = createToken( {
  88. name: 'USE',
  89. pattern: /USE/,
  90. longer_alt: Identifier
  91. } );
  92. var ROUTE = createToken( {
  93. name: 'ROUTE',
  94. pattern: /ROUTE/,
  95. longer_alt: Identifier
  96. } );
  97. var TO = createToken( {
  98. name: 'TO',
  99. pattern: /TO/,
  100. longer_alt: Identifier
  101. } );
  102. //
  103. var StringLiteral = createToken( { name: 'StringLiteral', pattern: /"(:?[^\\"\n\r]+|\\(:?[bfnrtv"\\/]|u[0-9a-fA-F]{4}))*"/ } );
  104. var HexLiteral = createToken( { name: 'HexLiteral', pattern: /0[xX][0-9a-fA-F]+/ } );
  105. var NumberLiteral = createToken( { name: 'NumberLiteral', pattern: /[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?/ } );
  106. var TrueLiteral = createToken( { name: 'TrueLiteral', pattern: /TRUE/ } );
  107. var FalseLiteral = createToken( { name: 'FalseLiteral', pattern: /FALSE/ } );
  108. var NullLiteral = createToken( { name: 'NullLiteral', pattern: /NULL/ } );
  109. var LSquare = createToken( { name: 'LSquare', pattern: /\[/ } );
  110. var RSquare = createToken( { name: 'RSquare', pattern: /]/ } );
  111. var LCurly = createToken( { name: 'LCurly', pattern: /{/ } );
  112. var RCurly = createToken( { name: 'RCurly', pattern: /}/ } );
  113. var Comment = createToken( {
  114. name: 'Comment',
  115. pattern: /#.*/,
  116. group: chevrotain.Lexer.SKIPPED // eslint-disable-line no-undef
  117. } );
  118. // commas, blanks, tabs, newlines and carriage returns are whitespace characters wherever they appear outside of string fields
  119. var WhiteSpace = createToken( {
  120. name: 'WhiteSpace',
  121. pattern: /[ ,\s]/,
  122. group: chevrotain.Lexer.SKIPPED // eslint-disable-line no-undef
  123. } );
  124. var tokens = [
  125. WhiteSpace,
  126. // keywords appear before the Identifier
  127. NodeName,
  128. DEF,
  129. USE,
  130. ROUTE,
  131. TO,
  132. TrueLiteral,
  133. FalseLiteral,
  134. NullLiteral,
  135. // the Identifier must appear after the keywords because all keywords are valid identifiers
  136. Version,
  137. Identifier,
  138. RouteIdentifier,
  139. StringLiteral,
  140. HexLiteral,
  141. NumberLiteral,
  142. LSquare,
  143. RSquare,
  144. LCurly,
  145. RCurly,
  146. Comment
  147. ];
  148. var tokenVocabulary = {};
  149. for ( var i = 0, l = tokens.length; i < l; i ++ ) {
  150. var token = tokens[ i ];
  151. tokenVocabulary[ token.name ] = token;
  152. }
  153. return { tokens: tokens, tokenVocabulary: tokenVocabulary };
  154. }
  155. function createVisitor( BaseVRMLVisitor ) {
  156. // the visitor is created dynmaically based on the given base class
  157. function VRMLToASTVisitor() {
  158. BaseVRMLVisitor.call( this );
  159. this.validateVisitor();
  160. }
  161. VRMLToASTVisitor.prototype = Object.assign( Object.create( BaseVRMLVisitor.prototype ), {
  162. constructor: VRMLToASTVisitor,
  163. vrml: function ( ctx ) {
  164. var data = {
  165. version: this.visit( ctx.version ),
  166. nodes: [],
  167. routes: []
  168. };
  169. for ( var i = 0, l = ctx.node.length; i < l; i ++ ) {
  170. var node = ctx.node[ i ];
  171. data.nodes.push( this.visit( node ) );
  172. }
  173. if ( ctx.route ) {
  174. for ( var i = 0, l = ctx.route.length; i < l; i ++ ) {
  175. var route = ctx.route[ i ];
  176. data.routes.push( this.visit( route ) );
  177. }
  178. }
  179. return data;
  180. },
  181. version: function ( ctx ) {
  182. return ctx.Version[ 0 ].image;
  183. },
  184. node: function ( ctx ) {
  185. var data = {
  186. name: ctx.NodeName[ 0 ].image,
  187. fields: []
  188. };
  189. if ( ctx.field ) {
  190. for ( var i = 0, l = ctx.field.length; i < l; i ++ ) {
  191. var field = ctx.field[ i ];
  192. data.fields.push( this.visit( field ) );
  193. }
  194. }
  195. // DEF
  196. if ( ctx.def ) {
  197. data.DEF = this.visit( ctx.def[ 0 ] );
  198. }
  199. return data;
  200. },
  201. field: function ( ctx ) {
  202. var data = {
  203. name: ctx.Identifier[ 0 ].image,
  204. type: null,
  205. values: null
  206. };
  207. var result;
  208. // SFValue
  209. if ( ctx.singleFieldValue ) {
  210. result = this.visit( ctx.singleFieldValue[ 0 ] );
  211. }
  212. // MFValue
  213. if ( ctx.multiFieldValue ) {
  214. result = this.visit( ctx.multiFieldValue[ 0 ] );
  215. }
  216. data.type = result.type;
  217. data.values = result.values;
  218. return data;
  219. },
  220. def: function ( ctx ) {
  221. return ( ctx.Identifier || ctx.NodeName )[ 0 ].image;
  222. },
  223. use: function ( ctx ) {
  224. return { USE: ( ctx.Identifier || ctx.NodeName )[ 0 ].image };
  225. },
  226. singleFieldValue: function ( ctx ) {
  227. return processField( this, ctx );
  228. },
  229. multiFieldValue: function ( ctx ) {
  230. return processField( this, ctx );
  231. },
  232. route: function ( ctx ) {
  233. var data = {
  234. FROM: ctx.RouteIdentifier[ 0 ].image,
  235. TO: ctx.RouteIdentifier[ 1 ].image
  236. };
  237. return data;
  238. }
  239. } );
  240. function processField( scope, ctx ) {
  241. var field = {
  242. type: null,
  243. values: []
  244. };
  245. if ( ctx.node ) {
  246. field.type = 'node';
  247. for ( var i = 0, l = ctx.node.length; i < l; i ++ ) {
  248. var node = ctx.node[ i ];
  249. field.values.push( scope.visit( node ) );
  250. }
  251. }
  252. if ( ctx.use ) {
  253. field.type = 'use';
  254. for ( var i = 0, l = ctx.use.length; i < l; i ++ ) {
  255. var use = ctx.use[ i ];
  256. field.values.push( scope.visit( use ) );
  257. }
  258. }
  259. if ( ctx.StringLiteral ) {
  260. field.type = 'string';
  261. for ( var i = 0, l = ctx.StringLiteral.length; i < l; i ++ ) {
  262. var stringLiteral = ctx.StringLiteral[ i ];
  263. field.values.push( stringLiteral.image.replace( /'|"/g, '' ) );
  264. }
  265. }
  266. if ( ctx.NumberLiteral ) {
  267. field.type = 'number';
  268. for ( var i = 0, l = ctx.NumberLiteral.length; i < l; i ++ ) {
  269. var numberLiteral = ctx.NumberLiteral[ i ];
  270. field.values.push( parseFloat( numberLiteral.image ) );
  271. }
  272. }
  273. if ( ctx.HexLiteral ) {
  274. field.type = 'hex';
  275. for ( var i = 0, l = ctx.HexLiteral.length; i < l; i ++ ) {
  276. var hexLiteral = ctx.HexLiteral[ i ];
  277. field.values.push( hexLiteral.image );
  278. }
  279. }
  280. if ( ctx.TrueLiteral ) {
  281. field.type = 'boolean';
  282. for ( var i = 0, l = ctx.TrueLiteral.length; i < l; i ++ ) {
  283. var trueLiteral = ctx.TrueLiteral[ i ];
  284. if ( trueLiteral.image === 'TRUE' ) field.values.push( true );
  285. }
  286. }
  287. if ( ctx.FalseLiteral ) {
  288. field.type = 'boolean';
  289. for ( var i = 0, l = ctx.FalseLiteral.length; i < l; i ++ ) {
  290. var falseLiteral = ctx.FalseLiteral[ i ];
  291. if ( falseLiteral.image === 'FALSE' ) field.values.push( false );
  292. }
  293. }
  294. if ( ctx.NullLiteral ) {
  295. field.type = 'null';
  296. ctx.NullLiteral.forEach( function () {
  297. field.values.push( null );
  298. } );
  299. }
  300. return field;
  301. }
  302. return new VRMLToASTVisitor();
  303. }
  304. function parseTree( tree ) {
  305. // console.log( JSON.stringify( tree, null, 2 ) );
  306. var nodes = tree.nodes;
  307. var scene = new THREE.Scene();
  308. // first iteration: build nodemap based on DEF statements
  309. for ( var i = 0, l = nodes.length; i < l; i ++ ) {
  310. var node = nodes[ i ];
  311. buildNodeMap( node );
  312. }
  313. // second iteration: build nodes
  314. for ( var i = 0, l = nodes.length; i < l; i ++ ) {
  315. var node = nodes[ i ];
  316. var object = getNode( node );
  317. if ( object instanceof THREE.Object3D ) scene.add( object );
  318. if ( node.name === 'WorldInfo' ) scene.userData.worldInfo = object;
  319. }
  320. return scene;
  321. }
  322. function buildNodeMap( node ) {
  323. if ( node.DEF ) {
  324. nodeMap[ node.DEF ] = node;
  325. }
  326. var fields = node.fields;
  327. for ( var i = 0, l = fields.length; i < l; i ++ ) {
  328. var field = fields[ i ];
  329. if ( field.type === 'node' ) {
  330. var fieldValues = field.values;
  331. for ( var j = 0, jl = fieldValues.length; j < jl; j ++ ) {
  332. buildNodeMap( fieldValues[ j ] );
  333. }
  334. }
  335. }
  336. }
  337. function getNode( node ) {
  338. // handle case where a node refers to a different one
  339. if ( node.USE ) {
  340. return resolveUSE( node.USE );
  341. }
  342. if ( node.build !== undefined ) return node.build;
  343. node.build = buildNode( node );
  344. return node.build;
  345. }
  346. // node builder
  347. function buildNode( node ) {
  348. var nodeName = node.name;
  349. var build;
  350. switch ( nodeName ) {
  351. case 'Group':
  352. case 'Transform':
  353. case 'Collision':
  354. build = buildGroupingNode( node );
  355. break;
  356. case 'Background':
  357. build = buildBackgroundNode( node );
  358. break;
  359. case 'Shape':
  360. build = buildShapeNode( node );
  361. break;
  362. case 'Appearance':
  363. build = buildAppearanceNode( node );
  364. break;
  365. case 'Material':
  366. build = buildMaterialNode( node );
  367. break;
  368. case 'ImageTexture':
  369. build = buildImageTextureNode( node );
  370. break;
  371. case 'PixelTexture':
  372. build = buildPixelTextureNode( node );
  373. break;
  374. case 'TextureTransform':
  375. build = buildTextureTransformNode( node );
  376. break;
  377. case 'IndexedFaceSet':
  378. build = buildIndexedFaceSetNode( node );
  379. break;
  380. case 'IndexedLineSet':
  381. build = buildIndexedLineSetNode( node );
  382. break;
  383. case 'PointSet':
  384. build = buildPointSetNode( node );
  385. break;
  386. case 'Box':
  387. build = buildBoxNode( node );
  388. break;
  389. case 'Cone':
  390. build = buildConeNode( node );
  391. break;
  392. case 'Cylinder':
  393. build = buildCylinderNode( node );
  394. break;
  395. case 'Sphere':
  396. build = buildSphereNode( node );
  397. break;
  398. case 'ElevationGrid':
  399. build = buildElevationGridNode( node );
  400. break;
  401. case 'Extrusion':
  402. build = buildExtrusionNode( node );
  403. break;
  404. case 'Color':
  405. case 'Coordinate':
  406. case 'Normal':
  407. case 'TextureCoordinate':
  408. build = buildGeometricNode( node );
  409. break;
  410. case 'WorldInfo':
  411. build = buildWorldInfoNode( node );
  412. break;
  413. case 'Anchor':
  414. case 'Billboard':
  415. case 'Inline':
  416. case 'LOD':
  417. case 'Switch':
  418. case 'AudioClip':
  419. case 'DirectionalLight':
  420. case 'PointLight':
  421. case 'Script':
  422. case 'Sound':
  423. case 'SpotLight':
  424. case 'CylinderSensor':
  425. case 'PlaneSensor':
  426. case 'ProximitySensor':
  427. case 'SphereSensor':
  428. case 'TimeSensor':
  429. case 'TouchSensor':
  430. case 'VisibilitySensor':
  431. case 'Text':
  432. case 'FontStyle':
  433. case 'MovieTexture':
  434. case 'ColorInterpolator':
  435. case 'CoordinateInterpolator':
  436. case 'NormalInterpolator':
  437. case 'OrientationInterpolator':
  438. case 'PositionInterpolator':
  439. case 'ScalarInterpolator':
  440. case 'Fog':
  441. case 'NavigationInfo':
  442. case 'Viewpoint':
  443. // node not supported yet
  444. break;
  445. default:
  446. console.warn( 'THREE.VRMLLoader: Unknown node:', nodeName );
  447. break;
  448. }
  449. return build;
  450. }
  451. function buildGroupingNode( node ) {
  452. var object = new THREE.Group();
  453. //
  454. var fields = node.fields;
  455. for ( var i = 0, l = fields.length; i < l; i ++ ) {
  456. var field = fields[ i ];
  457. var fieldName = field.name;
  458. var fieldValues = field.values;
  459. switch ( fieldName ) {
  460. case 'bboxCenter':
  461. // field not supported
  462. break;
  463. case 'bboxSize':
  464. // field not supported
  465. break;
  466. case 'center':
  467. // field not supported
  468. break;
  469. case 'children':
  470. parseFieldChildren( fieldValues, object );
  471. break;
  472. case 'collide':
  473. // field not supported
  474. break;
  475. case 'rotation':
  476. var axis = new THREE.Vector3( fieldValues[ 0 ], fieldValues[ 1 ], fieldValues[ 2 ] );
  477. var angle = fieldValues[ 3 ];
  478. object.quaternion.setFromAxisAngle( axis, angle );
  479. break;
  480. case 'scale':
  481. object.scale.set( fieldValues[ 0 ], fieldValues[ 1 ], fieldValues[ 2 ] );
  482. break;
  483. case 'scaleOrientation':
  484. // field not supported
  485. break;
  486. case 'translation':
  487. object.position.set( fieldValues[ 0 ], fieldValues[ 1 ], fieldValues[ 2 ] );
  488. break;
  489. case 'proxy':
  490. // field not supported
  491. break;
  492. default:
  493. console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
  494. break;
  495. }
  496. }
  497. return object;
  498. }
  499. function buildBackgroundNode( node ) {
  500. var group = new THREE.Group();
  501. var groundAngle, groundColor;
  502. var skyAngle, skyColor;
  503. var fields = node.fields;
  504. for ( var i = 0, l = fields.length; i < l; i ++ ) {
  505. var field = fields[ i ];
  506. var fieldName = field.name;
  507. var fieldValues = field.values;
  508. switch ( fieldName ) {
  509. case 'groundAngle':
  510. groundAngle = fieldValues;
  511. break;
  512. case 'groundColor':
  513. groundColor = fieldValues;
  514. break;
  515. case 'backUrl':
  516. // field not supported
  517. break;
  518. case 'bottomUrl':
  519. // field not supported
  520. break;
  521. case 'frontUrl':
  522. // field not supported
  523. break;
  524. case 'leftUrl':
  525. // field not supported
  526. break;
  527. case 'rightUrl':
  528. // field not supported
  529. break;
  530. case 'topUrl':
  531. // field not supported
  532. break;
  533. case 'skyAngle':
  534. skyAngle = fieldValues;
  535. break;
  536. case 'skyColor':
  537. skyColor = fieldValues;
  538. break;
  539. default:
  540. console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
  541. break;
  542. }
  543. }
  544. var radius = 10000;
  545. // sky
  546. if ( skyColor ) {
  547. var skyGeometry = new THREE.SphereGeometry( radius, 32, 16 );
  548. var skyMaterial = new THREE.MeshBasicMaterial( { fog: false, side: THREE.BackSide, depthWrite: false, depthTest: false } );
  549. if ( skyColor.length > 3 ) {
  550. paintFaces( skyGeometry, radius, skyAngle, toColorArray( skyColor ), true );
  551. skyMaterial.vertexColors = true;
  552. } else {
  553. skyMaterial.color.setRGB( skyColor[ 0 ], skyColor[ 1 ], skyColor[ 2 ] );
  554. }
  555. var sky = new THREE.Mesh( skyGeometry, skyMaterial );
  556. group.add( sky );
  557. }
  558. // ground
  559. if ( groundColor ) {
  560. if ( groundColor.length > 0 ) {
  561. var groundGeometry = new THREE.SphereGeometry( radius, 32, 16, 0, 2 * Math.PI, 0.5 * Math.PI, 1.5 * Math.PI );
  562. var groundMaterial = new THREE.MeshBasicMaterial( { fog: false, side: THREE.BackSide, vertexColors: true, depthWrite: false, depthTest: false } );
  563. paintFaces( groundGeometry, radius, groundAngle, toColorArray( groundColor ), false );
  564. var ground = new THREE.Mesh( groundGeometry, groundMaterial );
  565. group.add( ground );
  566. }
  567. }
  568. // render background group first
  569. group.renderOrder = - Infinity;
  570. return group;
  571. }
  572. function buildShapeNode( node ) {
  573. var fields = node.fields;
  574. // if the appearance field is NULL or unspecified, lighting is off and the unlit object color is (0, 0, 0)
  575. var material = new THREE.MeshBasicMaterial( { color: 0x000000 } );
  576. var geometry;
  577. for ( var i = 0, l = fields.length; i < l; i ++ ) {
  578. var field = fields[ i ];
  579. var fieldName = field.name;
  580. var fieldValues = field.values;
  581. switch ( fieldName ) {
  582. case 'appearance':
  583. if ( fieldValues[ 0 ] !== null ) {
  584. material = getNode( fieldValues[ 0 ] );
  585. }
  586. break;
  587. case 'geometry':
  588. if ( fieldValues[ 0 ] !== null ) {
  589. geometry = getNode( fieldValues[ 0 ] );
  590. }
  591. break;
  592. default:
  593. console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
  594. break;
  595. }
  596. }
  597. // build 3D object
  598. var object;
  599. if ( geometry && geometry.attributes.position ) {
  600. var type = geometry._type;
  601. if ( type === 'points' ) { // points
  602. var pointsMaterial = new THREE.PointsMaterial( { color: 0xffffff } );
  603. if ( geometry.attributes.color !== undefined ) {
  604. pointsMaterial.vertexColors = true;
  605. } else {
  606. // 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
  607. if ( material.isMeshPhongMaterial ) {
  608. pointsMaterial.color.copy( material.emissive );
  609. }
  610. }
  611. object = new THREE.Points( geometry, pointsMaterial );
  612. } else if ( type === 'line' ) { // lines
  613. var lineMaterial = new THREE.LineBasicMaterial( { color: 0xffffff } );
  614. if ( geometry.attributes.color !== undefined ) {
  615. lineMaterial.vertexColors = true;
  616. } else {
  617. // 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
  618. if ( material.isMeshPhongMaterial ) {
  619. lineMaterial.color.copy( material.emissive );
  620. }
  621. }
  622. object = new THREE.LineSegments( geometry, lineMaterial );
  623. } else { // consider meshes
  624. // check "solid" hint (it's placed in the geometry but affects the material)
  625. if ( geometry._solid !== undefined ) {
  626. material.side = ( geometry._solid ) ? THREE.FrontSide : THREE.DoubleSide;
  627. }
  628. // check for vertex colors
  629. if ( geometry.attributes.color !== undefined ) {
  630. material.vertexColors = true;
  631. }
  632. object = new THREE.Mesh( geometry, material );
  633. }
  634. } else {
  635. object = new THREE.Object3D();
  636. // if the geometry field is NULL or no vertices are defined the object is not drawn
  637. object.visible = false;
  638. }
  639. return object;
  640. }
  641. function buildAppearanceNode( node ) {
  642. var material = new THREE.MeshPhongMaterial();
  643. var transformData;
  644. var fields = node.fields;
  645. for ( var i = 0, l = fields.length; i < l; i ++ ) {
  646. var field = fields[ i ];
  647. var fieldName = field.name;
  648. var fieldValues = field.values;
  649. switch ( fieldName ) {
  650. case 'material':
  651. if ( fieldValues[ 0 ] !== null ) {
  652. var materialData = getNode( fieldValues[ 0 ] );
  653. if ( materialData.diffuseColor ) material.color.copy( materialData.diffuseColor );
  654. if ( materialData.emissiveColor ) material.emissive.copy( materialData.emissiveColor );
  655. if ( materialData.shininess ) material.shininess = materialData.shininess;
  656. if ( materialData.specularColor ) material.specular.copy( materialData.specularColor );
  657. if ( materialData.transparency ) material.opacity = 1 - materialData.transparency;
  658. if ( materialData.transparency > 0 ) material.transparent = true;
  659. } else {
  660. // if the material field is NULL or unspecified, lighting is off and the unlit object color is (0, 0, 0)
  661. material = new THREE.MeshBasicMaterial( { color: 0x000000 } );
  662. }
  663. break;
  664. case 'texture':
  665. var textureNode = fieldValues[ 0 ];
  666. if ( textureNode !== null ) {
  667. if ( textureNode.name === 'ImageTexture' || textureNode.name === 'PixelTexture' ) {
  668. material.map = getNode( textureNode );
  669. } else {
  670. // MovieTexture not supported yet
  671. }
  672. }
  673. break;
  674. case 'textureTransform':
  675. if ( fieldValues[ 0 ] !== null ) {
  676. transformData = getNode( fieldValues[ 0 ] );
  677. }
  678. break;
  679. default:
  680. console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
  681. break;
  682. }
  683. }
  684. // only apply texture transform data if a texture was defined
  685. if ( material.map ) {
  686. // respect VRML lighting model
  687. if ( material.map.__type ) {
  688. switch ( material.map.__type ) {
  689. case TEXTURE_TYPE.INTENSITY_ALPHA:
  690. material.opacity = 1; // ignore transparency
  691. break;
  692. case TEXTURE_TYPE.RGB:
  693. material.color.set( 0xffffff ); // ignore material color
  694. break;
  695. case TEXTURE_TYPE.RGBA:
  696. material.color.set( 0xffffff ); // ignore material color
  697. material.opacity = 1; // ignore transparency
  698. break;
  699. default:
  700. }
  701. delete material.map.__type;
  702. }
  703. // apply texture transform
  704. if ( transformData ) {
  705. material.map.center.copy( transformData.center );
  706. material.map.rotation = transformData.rotation;
  707. material.map.repeat.copy( transformData.scale );
  708. material.map.offset.copy( transformData.translation );
  709. }
  710. }
  711. return material;
  712. }
  713. function buildMaterialNode( node ) {
  714. var materialData = {};
  715. var fields = node.fields;
  716. for ( var i = 0, l = fields.length; i < l; i ++ ) {
  717. var field = fields[ i ];
  718. var fieldName = field.name;
  719. var fieldValues = field.values;
  720. switch ( fieldName ) {
  721. case 'ambientIntensity':
  722. // field not supported
  723. break;
  724. case 'diffuseColor':
  725. materialData.diffuseColor = new THREE.Color( fieldValues[ 0 ], fieldValues[ 1 ], fieldValues[ 2 ] );
  726. break;
  727. case 'emissiveColor':
  728. materialData.emissiveColor = new THREE.Color( fieldValues[ 0 ], fieldValues[ 1 ], fieldValues[ 2 ] );
  729. break;
  730. case 'shininess':
  731. materialData.shininess = fieldValues[ 0 ];
  732. break;
  733. case 'specularColor':
  734. materialData.emissiveColor = new THREE.Color( fieldValues[ 0 ], fieldValues[ 1 ], fieldValues[ 2 ] );
  735. break;
  736. case 'transparency':
  737. materialData.transparency = fieldValues[ 0 ];
  738. break;
  739. default:
  740. console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
  741. break;
  742. }
  743. }
  744. return materialData;
  745. }
  746. function parseHexColor( hex, textureType, color ) {
  747. switch ( textureType ) {
  748. case TEXTURE_TYPE.INTENSITY:
  749. // Intensity texture: A one-component image specifies one-byte hexadecimal or integer values representing the intensity of the image
  750. var value = parseInt( hex );
  751. color.r = value;
  752. color.g = value;
  753. color.b = value;
  754. break;
  755. case TEXTURE_TYPE.INTENSITY_ALPHA:
  756. // Intensity+Alpha texture: A two-component image specifies the intensity in the first (high) byte and the alpha opacity in the second (low) byte.
  757. var value = parseInt( '0x' + hex.substring( 2, 4 ) );
  758. color.r = value;
  759. color.g = value;
  760. color.b = value;
  761. color.a = parseInt( '0x' + hex.substring( 4, 6 ) );
  762. break;
  763. case TEXTURE_TYPE.RGB:
  764. // RGB texture: Pixels in a three-component image specify the red component in the first (high) byte, followed by the green and blue components
  765. color.r = parseInt( '0x' + hex.substring( 2, 4 ) );
  766. color.g = parseInt( '0x' + hex.substring( 4, 6 ) );
  767. color.b = parseInt( '0x' + hex.substring( 6, 8 ) );
  768. break;
  769. case TEXTURE_TYPE.RGBA:
  770. // RGBA texture: Four-component images specify the alpha opacity byte after red/green/blue
  771. color.r = parseInt( '0x' + hex.substring( 2, 4 ) );
  772. color.g = parseInt( '0x' + hex.substring( 4, 6 ) );
  773. color.b = parseInt( '0x' + hex.substring( 6, 8 ) );
  774. color.a = parseInt( '0x' + hex.substring( 8, 10 ) );
  775. break;
  776. default:
  777. }
  778. }
  779. function getTextureType( num_components ) {
  780. var type;
  781. switch ( num_components ) {
  782. case 1:
  783. type = TEXTURE_TYPE.INTENSITY;
  784. break;
  785. case 2:
  786. type = TEXTURE_TYPE.INTENSITY_ALPHA;
  787. break;
  788. case 3:
  789. type = TEXTURE_TYPE.RGB;
  790. break;
  791. case 4:
  792. type = TEXTURE_TYPE.RGBA;
  793. break;
  794. default:
  795. }
  796. return type;
  797. }
  798. function buildPixelTextureNode( node ) {
  799. var texture;
  800. var wrapS = THREE.RepeatWrapping;
  801. var wrapT = THREE.RepeatWrapping;
  802. var fields = node.fields;
  803. for ( var i = 0, l = fields.length; i < l; i ++ ) {
  804. var field = fields[ i ];
  805. var fieldName = field.name;
  806. var fieldValues = field.values;
  807. switch ( fieldName ) {
  808. case 'image':
  809. var width = fieldValues[ 0 ];
  810. var height = fieldValues[ 1 ];
  811. var num_components = fieldValues[ 2 ];
  812. var useAlpha = ( num_components === 2 || num_components === 4 );
  813. var textureType = getTextureType( num_components );
  814. var size = ( ( useAlpha === true ) ? 4 : 3 ) * ( width * height );
  815. var data = new Uint8Array( size );
  816. var color = { r: 0, g: 0, b: 0, a: 0 };
  817. for ( var j = 3, k = 0, jl = fieldValues.length; j < jl; j ++, k ++ ) {
  818. parseHexColor( fieldValues[ j ], textureType, color );
  819. if ( useAlpha === true ) {
  820. var stride = k * 4;
  821. data[ stride + 0 ] = color.r;
  822. data[ stride + 1 ] = color.g;
  823. data[ stride + 2 ] = color.b;
  824. data[ stride + 3 ] = color.a;
  825. } else {
  826. var stride = k * 3;
  827. data[ stride + 0 ] = color.r;
  828. data[ stride + 1 ] = color.g;
  829. data[ stride + 2 ] = color.b;
  830. }
  831. }
  832. texture = new THREE.DataTexture( data, width, height, ( useAlpha === true ) ? THREE.RGBAFormat : THREE.RGBFormat );
  833. texture.__type = textureType; // needed for material modifications
  834. break;
  835. case 'repeatS':
  836. if ( fieldValues[ 0 ] === false ) wrapS = THREE.ClampToEdgeWrapping;
  837. break;
  838. case 'repeatT':
  839. if ( fieldValues[ 0 ] === false ) wrapT = THREE.ClampToEdgeWrapping;
  840. break;
  841. default:
  842. console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
  843. break;
  844. }
  845. }
  846. if ( texture ) {
  847. texture.wrapS = wrapS;
  848. texture.wrapT = wrapT;
  849. }
  850. return texture;
  851. }
  852. function buildImageTextureNode( node ) {
  853. var texture;
  854. var wrapS = THREE.RepeatWrapping;
  855. var wrapT = THREE.RepeatWrapping;
  856. var fields = node.fields;
  857. for ( var i = 0, l = fields.length; i < l; i ++ ) {
  858. var field = fields[ i ];
  859. var fieldName = field.name;
  860. var fieldValues = field.values;
  861. switch ( fieldName ) {
  862. case 'url':
  863. var url = fieldValues[ 0 ];
  864. if ( url ) texture = textureLoader.load( url );
  865. break;
  866. case 'repeatS':
  867. if ( fieldValues[ 0 ] === false ) wrapS = THREE.ClampToEdgeWrapping;
  868. break;
  869. case 'repeatT':
  870. if ( fieldValues[ 0 ] === false ) wrapT = THREE.ClampToEdgeWrapping;
  871. break;
  872. default:
  873. console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
  874. break;
  875. }
  876. }
  877. if ( texture ) {
  878. texture.wrapS = wrapS;
  879. texture.wrapT = wrapT;
  880. }
  881. return texture;
  882. }
  883. function buildTextureTransformNode( node ) {
  884. var transformData = {
  885. center: new THREE.Vector2(),
  886. rotation: new THREE.Vector2(),
  887. scale: new THREE.Vector2(),
  888. translation: new THREE.Vector2()
  889. };
  890. var fields = node.fields;
  891. for ( var i = 0, l = fields.length; i < l; i ++ ) {
  892. var field = fields[ i ];
  893. var fieldName = field.name;
  894. var fieldValues = field.values;
  895. switch ( fieldName ) {
  896. case 'center':
  897. transformData.center.set( fieldValues[ 0 ], fieldValues[ 1 ] );
  898. break;
  899. case 'rotation':
  900. transformData.rotation = fieldValues[ 0 ];
  901. break;
  902. case 'scale':
  903. transformData.scale.set( fieldValues[ 0 ], fieldValues[ 1 ] );
  904. break;
  905. case 'translation':
  906. transformData.translation.set( fieldValues[ 0 ], fieldValues[ 1 ] );
  907. break;
  908. default:
  909. console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
  910. break;
  911. }
  912. }
  913. return transformData;
  914. }
  915. function buildGeometricNode( node ) {
  916. return node.fields[ 0 ].values;
  917. }
  918. function buildWorldInfoNode( node ) {
  919. var worldInfo = {};
  920. var fields = node.fields;
  921. for ( var i = 0, l = fields.length; i < l; i ++ ) {
  922. var field = fields[ i ];
  923. var fieldName = field.name;
  924. var fieldValues = field.values;
  925. switch ( fieldName ) {
  926. case 'title':
  927. worldInfo.title = fieldValues[ 0 ];
  928. break;
  929. case 'info':
  930. worldInfo.info = fieldValues;
  931. break;
  932. default:
  933. console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
  934. break;
  935. }
  936. }
  937. return worldInfo;
  938. }
  939. function buildIndexedFaceSetNode( node ) {
  940. var color, coord, normal, texCoord;
  941. var ccw = true, solid = true, creaseAngle = 0;
  942. var colorIndex, coordIndex, normalIndex, texCoordIndex;
  943. var colorPerVertex = true, normalPerVertex = true;
  944. var fields = node.fields;
  945. for ( var i = 0, l = fields.length; i < l; i ++ ) {
  946. var field = fields[ i ];
  947. var fieldName = field.name;
  948. var fieldValues = field.values;
  949. switch ( fieldName ) {
  950. case 'color':
  951. var colorNode = fieldValues[ 0 ];
  952. if ( colorNode !== null ) {
  953. color = getNode( colorNode );
  954. }
  955. break;
  956. case 'coord':
  957. var coordNode = fieldValues[ 0 ];
  958. if ( coordNode !== null ) {
  959. coord = getNode( coordNode );
  960. }
  961. break;
  962. case 'normal':
  963. var normalNode = fieldValues[ 0 ];
  964. if ( normalNode !== null ) {
  965. normal = getNode( normalNode );
  966. }
  967. break;
  968. case 'texCoord':
  969. var texCoordNode = fieldValues[ 0 ];
  970. if ( texCoordNode !== null ) {
  971. texCoord = getNode( texCoordNode );
  972. }
  973. break;
  974. case 'ccw':
  975. ccw = fieldValues[ 0 ];
  976. break;
  977. case 'colorIndex':
  978. colorIndex = fieldValues;
  979. break;
  980. case 'colorPerVertex':
  981. colorPerVertex = fieldValues[ 0 ];
  982. break;
  983. case 'convex':
  984. // field not supported
  985. break;
  986. case 'coordIndex':
  987. coordIndex = fieldValues;
  988. break;
  989. case 'creaseAngle':
  990. creaseAngle = fieldValues[ 0 ];
  991. break;
  992. case 'normalIndex':
  993. normalIndex = fieldValues;
  994. break;
  995. case 'normalPerVertex':
  996. normalPerVertex = fieldValues[ 0 ];
  997. break;
  998. case 'solid':
  999. solid = fieldValues[ 0 ];
  1000. break;
  1001. case 'texCoordIndex':
  1002. texCoordIndex = fieldValues;
  1003. break;
  1004. default:
  1005. console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
  1006. break;
  1007. }
  1008. }
  1009. if ( coordIndex === undefined ) {
  1010. console.warn( 'THREE.VRMLLoader: Missing coordIndex.' );
  1011. return new THREE.BufferGeometry(); // handle VRML files with incomplete geometry definition
  1012. }
  1013. var triangulatedCoordIndex = triangulateFaceIndex( coordIndex, ccw );
  1014. var positionAttribute;
  1015. var colorAttribute;
  1016. var normalAttribute;
  1017. var uvAttribute;
  1018. if ( color ) {
  1019. if ( colorPerVertex === true ) {
  1020. if ( colorIndex && colorIndex.length > 0 ) {
  1021. // if the colorIndex field is not empty, then it is used to choose colors for each vertex of the IndexedFaceSet.
  1022. var triangulatedColorIndex = triangulateFaceIndex( colorIndex, ccw );
  1023. colorAttribute = computeAttributeFromIndexedData( triangulatedCoordIndex, triangulatedColorIndex, color, 3 );
  1024. } else {
  1025. // if the colorIndex field is empty, then the coordIndex field is used to choose colors from the Color node
  1026. colorAttribute = toNonIndexedAttribute( triangulatedCoordIndex, new THREE.Float32BufferAttribute( color, 3 ) );
  1027. }
  1028. } else {
  1029. if ( colorIndex && colorIndex.length > 0 ) {
  1030. // if the colorIndex field is not empty, then they are used to choose one color for each face of the IndexedFaceSet
  1031. var flattenFaceColors = flattenData( color, colorIndex );
  1032. var triangulatedFaceColors = triangulateFaceData( flattenFaceColors, coordIndex );
  1033. colorAttribute = computeAttributeFromFaceData( triangulatedCoordIndex, triangulatedFaceColors );
  1034. } else {
  1035. // if the colorIndex field is empty, then the color are applied to each face of the IndexedFaceSet in order
  1036. var triangulatedFaceColors = triangulateFaceData( color, coordIndex );
  1037. colorAttribute = computeAttributeFromFaceData( triangulatedCoordIndex, triangulatedFaceColors );
  1038. }
  1039. }
  1040. }
  1041. if ( normal ) {
  1042. if ( normalPerVertex === true ) {
  1043. // consider vertex normals
  1044. if ( normalIndex && normalIndex.length > 0 ) {
  1045. // if the normalIndex field is not empty, then it is used to choose normals for each vertex of the IndexedFaceSet.
  1046. var triangulatedNormalIndex = triangulateFaceIndex( normalIndex, ccw );
  1047. normalAttribute = computeAttributeFromIndexedData( triangulatedCoordIndex, triangulatedNormalIndex, normal, 3 );
  1048. } else {
  1049. // if the normalIndex field is empty, then the coordIndex field is used to choose normals from the Normal node
  1050. normalAttribute = toNonIndexedAttribute( triangulatedCoordIndex, new THREE.Float32BufferAttribute( normal, 3 ) );
  1051. }
  1052. } else {
  1053. // consider face normals
  1054. if ( normalIndex && normalIndex.length > 0 ) {
  1055. // if the normalIndex field is not empty, then they are used to choose one normal for each face of the IndexedFaceSet
  1056. var flattenFaceNormals = flattenData( normal, normalIndex );
  1057. var triangulatedFaceNormals = triangulateFaceData( flattenFaceNormals, coordIndex );
  1058. normalAttribute = computeAttributeFromFaceData( triangulatedCoordIndex, triangulatedFaceNormals );
  1059. } else {
  1060. // if the normalIndex field is empty, then the normals are applied to each face of the IndexedFaceSet in order
  1061. var triangulatedFaceNormals = triangulateFaceData( normal, coordIndex );
  1062. normalAttribute = computeAttributeFromFaceData( triangulatedCoordIndex, triangulatedFaceNormals );
  1063. }
  1064. }
  1065. } else {
  1066. // 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
  1067. normalAttribute = computeNormalAttribute( triangulatedCoordIndex, coord, creaseAngle );
  1068. }
  1069. if ( texCoord ) {
  1070. // texture coordinates are always defined on vertex level
  1071. if ( texCoordIndex && texCoordIndex.length > 0 ) {
  1072. // if the texCoordIndex field is not empty, then it is used to choose texture coordinates for each vertex of the IndexedFaceSet.
  1073. var triangulatedTexCoordIndex = triangulateFaceIndex( texCoordIndex, ccw );
  1074. uvAttribute = computeAttributeFromIndexedData( triangulatedCoordIndex, triangulatedTexCoordIndex, texCoord, 2 );
  1075. } else {
  1076. // if the texCoordIndex field is empty, then the coordIndex array is used to choose texture coordinates from the TextureCoordinate node
  1077. uvAttribute = toNonIndexedAttribute( triangulatedCoordIndex, new THREE.Float32BufferAttribute( texCoord, 2 ) );
  1078. }
  1079. }
  1080. var geometry = new THREE.BufferGeometry();
  1081. positionAttribute = toNonIndexedAttribute( triangulatedCoordIndex, new THREE.Float32BufferAttribute( coord, 3 ) );
  1082. geometry.setAttribute( 'position', positionAttribute );
  1083. geometry.setAttribute( 'normal', normalAttribute );
  1084. // optional attributes
  1085. if ( colorAttribute ) geometry.setAttribute( 'color', colorAttribute );
  1086. if ( uvAttribute ) geometry.setAttribute( 'uv', uvAttribute );
  1087. // "solid" influences the material so let's store it for later use
  1088. geometry._solid = solid;
  1089. geometry._type = 'mesh';
  1090. return geometry;
  1091. }
  1092. function buildIndexedLineSetNode( node ) {
  1093. var color, coord;
  1094. var colorIndex, coordIndex;
  1095. var colorPerVertex = true;
  1096. var fields = node.fields;
  1097. for ( var i = 0, l = fields.length; i < l; i ++ ) {
  1098. var field = fields[ i ];
  1099. var fieldName = field.name;
  1100. var fieldValues = field.values;
  1101. switch ( fieldName ) {
  1102. case 'color':
  1103. var colorNode = fieldValues[ 0 ];
  1104. if ( colorNode !== null ) {
  1105. color = getNode( colorNode );
  1106. }
  1107. break;
  1108. case 'coord':
  1109. var coordNode = fieldValues[ 0 ];
  1110. if ( coordNode !== null ) {
  1111. coord = getNode( coordNode );
  1112. }
  1113. break;
  1114. case 'colorIndex':
  1115. colorIndex = fieldValues;
  1116. break;
  1117. case 'colorPerVertex':
  1118. colorPerVertex = fieldValues[ 0 ];
  1119. break;
  1120. case 'coordIndex':
  1121. coordIndex = fieldValues;
  1122. break;
  1123. default:
  1124. console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
  1125. break;
  1126. }
  1127. }
  1128. // build lines
  1129. var colorAttribute;
  1130. var expandedLineIndex = expandLineIndex( coordIndex ); // create an index for three.js's linesegment primitive
  1131. if ( color ) {
  1132. if ( colorPerVertex === true ) {
  1133. if ( colorIndex.length > 0 ) {
  1134. // if the colorIndex field is not empty, then one color is used for each polyline of the IndexedLineSet.
  1135. var expandedColorIndex = expandLineIndex( colorIndex ); // compute colors for each line segment (rendering primitve)
  1136. colorAttribute = computeAttributeFromIndexedData( expandedLineIndex, expandedColorIndex, color, 3 ); // compute data on vertex level
  1137. } else {
  1138. // if the colorIndex field is empty, then the colors are applied to each polyline of the IndexedLineSet in order.
  1139. colorAttribute = toNonIndexedAttribute( expandedLineIndex, new THREE.Float32BufferAttribute( color, 3 ) );
  1140. }
  1141. } else {
  1142. if ( colorIndex.length > 0 ) {
  1143. // if the colorIndex field is not empty, then colors are applied to each vertex of the IndexedLineSet
  1144. var flattenLineColors = flattenData( color, colorIndex ); // compute colors for each VRML primitve
  1145. var expandedLineColors = expandLineData( flattenLineColors, coordIndex ); // compute colors for each line segment (rendering primitve)
  1146. colorAttribute = computeAttributeFromLineData( expandedLineIndex, expandedLineColors ); // compute data on vertex level
  1147. } else {
  1148. // if the colorIndex field is empty, then the coordIndex field is used to choose colors from the Color node
  1149. var expandedLineColors = expandLineData( color, coordIndex ); // compute colors for each line segment (rendering primitve)
  1150. colorAttribute = computeAttributeFromLineData( expandedLineIndex, expandedLineColors ); // compute data on vertex level
  1151. }
  1152. }
  1153. }
  1154. //
  1155. var geometry = new THREE.BufferGeometry();
  1156. var positionAttribute = toNonIndexedAttribute( expandedLineIndex, new THREE.Float32BufferAttribute( coord, 3 ) );
  1157. geometry.setAttribute( 'position', positionAttribute );
  1158. if ( colorAttribute ) geometry.setAttribute( 'color', colorAttribute );
  1159. geometry._type = 'line';
  1160. return geometry;
  1161. }
  1162. function buildPointSetNode( node ) {
  1163. var geometry;
  1164. var color, coord;
  1165. var fields = node.fields;
  1166. for ( var i = 0, l = fields.length; i < l; i ++ ) {
  1167. var field = fields[ i ];
  1168. var fieldName = field.name;
  1169. var fieldValues = field.values;
  1170. switch ( fieldName ) {
  1171. case 'color':
  1172. var colorNode = fieldValues[ 0 ];
  1173. if ( colorNode !== null ) {
  1174. color = getNode( colorNode );
  1175. }
  1176. break;
  1177. case 'coord':
  1178. var coordNode = fieldValues[ 0 ];
  1179. if ( coordNode !== null ) {
  1180. coord = getNode( coordNode );
  1181. }
  1182. break;
  1183. default:
  1184. console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
  1185. break;
  1186. }
  1187. }
  1188. var geometry = new THREE.BufferGeometry();
  1189. geometry.setAttribute( 'position', new THREE.Float32BufferAttribute( coord, 3 ) );
  1190. if ( color ) geometry.setAttribute( 'color', new THREE.Float32BufferAttribute( color, 3 ) );
  1191. geometry._type = 'points';
  1192. return geometry;
  1193. }
  1194. function buildBoxNode( node ) {
  1195. var size = new THREE.Vector3( 2, 2, 2 );
  1196. var fields = node.fields;
  1197. for ( var i = 0, l = fields.length; i < l; i ++ ) {
  1198. var field = fields[ i ];
  1199. var fieldName = field.name;
  1200. var fieldValues = field.values;
  1201. switch ( fieldName ) {
  1202. case 'size':
  1203. size.x = fieldValues[ 0 ];
  1204. size.y = fieldValues[ 1 ];
  1205. size.z = fieldValues[ 2 ];
  1206. break;
  1207. default:
  1208. console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
  1209. break;
  1210. }
  1211. }
  1212. var geometry = new THREE.BoxGeometry( size.x, size.y, size.z );
  1213. return geometry;
  1214. }
  1215. function buildConeNode( node ) {
  1216. var radius = 1, height = 2, openEnded = false;
  1217. var fields = node.fields;
  1218. for ( var i = 0, l = fields.length; i < l; i ++ ) {
  1219. var field = fields[ i ];
  1220. var fieldName = field.name;
  1221. var fieldValues = field.values;
  1222. switch ( fieldName ) {
  1223. case 'bottom':
  1224. openEnded = ! fieldValues[ 0 ];
  1225. break;
  1226. case 'bottomRadius':
  1227. radius = fieldValues[ 0 ];
  1228. break;
  1229. case 'height':
  1230. height = fieldValues[ 0 ];
  1231. break;
  1232. case 'side':
  1233. // field not supported
  1234. break;
  1235. default:
  1236. console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
  1237. break;
  1238. }
  1239. }
  1240. var geometry = new THREE.ConeGeometry( radius, height, 16, 1, openEnded );
  1241. return geometry;
  1242. }
  1243. function buildCylinderNode( node ) {
  1244. var radius = 1, height = 2;
  1245. var fields = node.fields;
  1246. for ( var i = 0, l = fields.length; i < l; i ++ ) {
  1247. var field = fields[ i ];
  1248. var fieldName = field.name;
  1249. var fieldValues = field.values;
  1250. switch ( fieldName ) {
  1251. case 'bottom':
  1252. // field not supported
  1253. break;
  1254. case 'radius':
  1255. radius = fieldValues[ 0 ];
  1256. break;
  1257. case 'height':
  1258. height = fieldValues[ 0 ];
  1259. break;
  1260. case 'side':
  1261. // field not supported
  1262. break;
  1263. case 'top':
  1264. // field not supported
  1265. break;
  1266. default:
  1267. console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
  1268. break;
  1269. }
  1270. }
  1271. var geometry = new THREE.CylinderGeometry( radius, radius, height, 16, 1 );
  1272. return geometry;
  1273. }
  1274. function buildSphereNode( node ) {
  1275. var radius = 1;
  1276. var fields = node.fields;
  1277. for ( var i = 0, l = fields.length; i < l; i ++ ) {
  1278. var field = fields[ i ];
  1279. var fieldName = field.name;
  1280. var fieldValues = field.values;
  1281. switch ( fieldName ) {
  1282. case 'radius':
  1283. radius = fieldValues[ 0 ];
  1284. break;
  1285. default:
  1286. console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
  1287. break;
  1288. }
  1289. }
  1290. var geometry = new THREE.SphereGeometry( radius, 16, 16 );
  1291. return geometry;
  1292. }
  1293. function buildElevationGridNode( node ) {
  1294. var color;
  1295. var normal;
  1296. var texCoord;
  1297. var height;
  1298. var colorPerVertex = true;
  1299. var normalPerVertex = true;
  1300. var solid = true;
  1301. var ccw = true;
  1302. var creaseAngle = 0;
  1303. var xDimension = 2;
  1304. var zDimension = 2;
  1305. var xSpacing = 1;
  1306. var zSpacing = 1;
  1307. var fields = node.fields;
  1308. for ( var i = 0, l = fields.length; i < l; i ++ ) {
  1309. var field = fields[ i ];
  1310. var fieldName = field.name;
  1311. var fieldValues = field.values;
  1312. switch ( fieldName ) {
  1313. case 'color':
  1314. var colorNode = fieldValues[ 0 ];
  1315. if ( colorNode !== null ) {
  1316. color = getNode( colorNode );
  1317. }
  1318. break;
  1319. case 'normal':
  1320. var normalNode = fieldValues[ 0 ];
  1321. if ( normalNode !== null ) {
  1322. normal = getNode( normalNode );
  1323. }
  1324. break;
  1325. case 'texCoord':
  1326. var texCoordNode = fieldValues[ 0 ];
  1327. if ( texCoordNode !== null ) {
  1328. texCoord = getNode( texCoordNode );
  1329. }
  1330. break;
  1331. case 'height':
  1332. height = fieldValues;
  1333. break;
  1334. case 'ccw':
  1335. ccw = fieldValues[ 0 ];
  1336. break;
  1337. case 'colorPerVertex':
  1338. colorPerVertex = fieldValues[ 0 ];
  1339. break;
  1340. case 'creaseAngle':
  1341. creaseAngle = fieldValues[ 0 ];
  1342. break;
  1343. case 'normalPerVertex':
  1344. normalPerVertex = fieldValues[ 0 ];
  1345. break;
  1346. case 'solid':
  1347. solid = fieldValues[ 0 ];
  1348. break;
  1349. case 'xDimension':
  1350. xDimension = fieldValues[ 0 ];
  1351. break;
  1352. case 'xSpacing':
  1353. xSpacing = fieldValues[ 0 ];
  1354. break;
  1355. case 'zDimension':
  1356. zDimension = fieldValues[ 0 ];
  1357. break;
  1358. case 'zSpacing':
  1359. zSpacing = fieldValues[ 0 ];
  1360. break;
  1361. default:
  1362. console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
  1363. break;
  1364. }
  1365. }
  1366. // vertex data
  1367. var vertices = [];
  1368. var normals = [];
  1369. var colors = [];
  1370. var uvs = [];
  1371. for ( var i = 0; i < zDimension; i ++ ) {
  1372. for ( var j = 0; j < xDimension; j ++ ) {
  1373. // compute a row major index
  1374. var index = ( i * xDimension ) + j;
  1375. // vertices
  1376. var x = xSpacing * i;
  1377. var y = height[ index ];
  1378. var z = zSpacing * j;
  1379. vertices.push( x, y, z );
  1380. // colors
  1381. if ( color && colorPerVertex === true ) {
  1382. var r = color[ index * 3 + 0 ];
  1383. var g = color[ index * 3 + 1 ];
  1384. var b = color[ index * 3 + 2 ];
  1385. colors.push( r, g, b );
  1386. }
  1387. // normals
  1388. if ( normal && normalPerVertex === true ) {
  1389. var xn = normal[ index * 3 + 0 ];
  1390. var yn = normal[ index * 3 + 1 ];
  1391. var zn = normal[ index * 3 + 2 ];
  1392. normals.push( xn, yn, zn );
  1393. }
  1394. // uvs
  1395. if ( texCoord ) {
  1396. var s = texCoord[ index * 2 + 0 ];
  1397. var t = texCoord[ index * 2 + 1 ];
  1398. uvs.push( s, t );
  1399. } else {
  1400. uvs.push( i / ( xDimension - 1 ), j / ( zDimension - 1 ) );
  1401. }
  1402. }
  1403. }
  1404. // indices
  1405. var indices = [];
  1406. for ( var i = 0; i < xDimension - 1; i ++ ) {
  1407. for ( var j = 0; j < zDimension - 1; j ++ ) {
  1408. // from https://tecfa.unige.ch/guides/vrml/vrml97/spec/part1/nodesRef.html#ElevationGrid
  1409. var a = i + j * xDimension;
  1410. var b = i + ( j + 1 ) * xDimension;
  1411. var c = ( i + 1 ) + ( j + 1 ) * xDimension;
  1412. var d = ( i + 1 ) + j * xDimension;
  1413. // faces
  1414. if ( ccw === true ) {
  1415. indices.push( a, c, b );
  1416. indices.push( c, a, d );
  1417. } else {
  1418. indices.push( a, b, c );
  1419. indices.push( c, d, a );
  1420. }
  1421. }
  1422. }
  1423. //
  1424. var positionAttribute = toNonIndexedAttribute( indices, new THREE.Float32BufferAttribute( vertices, 3 ) );
  1425. var uvAttribute = toNonIndexedAttribute( indices, new THREE.Float32BufferAttribute( uvs, 2 ) );
  1426. var colorAttribute;
  1427. var normalAttribute;
  1428. // color attribute
  1429. if ( color ) {
  1430. if ( colorPerVertex === false ) {
  1431. for ( var i = 0; i < xDimension - 1; i ++ ) {
  1432. for ( var j = 0; j < zDimension - 1; j ++ ) {
  1433. var index = i + j * ( xDimension - 1 );
  1434. var r = color[ index * 3 + 0 ];
  1435. var g = color[ index * 3 + 1 ];
  1436. var b = color[ index * 3 + 2 ];
  1437. // one color per quad
  1438. colors.push( r, g, b ); colors.push( r, g, b ); colors.push( r, g, b );
  1439. colors.push( r, g, b ); colors.push( r, g, b ); colors.push( r, g, b );
  1440. }
  1441. }
  1442. colorAttribute = new THREE.Float32BufferAttribute( colors, 3 );
  1443. } else {
  1444. colorAttribute = toNonIndexedAttribute( indices, new THREE.Float32BufferAttribute( colors, 3 ) );
  1445. }
  1446. }
  1447. // normal attribute
  1448. if ( normal ) {
  1449. if ( normalPerVertex === false ) {
  1450. for ( var i = 0; i < xDimension - 1; i ++ ) {
  1451. for ( var j = 0; j < zDimension - 1; j ++ ) {
  1452. var index = i + j * ( xDimension - 1 );
  1453. var xn = normal[ index * 3 + 0 ];
  1454. var yn = normal[ index * 3 + 1 ];
  1455. var zn = normal[ index * 3 + 2 ];
  1456. // one normal per quad
  1457. normals.push( xn, yn, zn ); normals.push( xn, yn, zn ); normals.push( xn, yn, zn );
  1458. normals.push( xn, yn, zn ); normals.push( xn, yn, zn ); normals.push( xn, yn, zn );
  1459. }
  1460. }
  1461. normalAttribute = new THREE.Float32BufferAttribute( normals, 3 );
  1462. } else {
  1463. normalAttribute = toNonIndexedAttribute( indices, new THREE.Float32BufferAttribute( normals, 3 ) );
  1464. }
  1465. } else {
  1466. normalAttribute = computeNormalAttribute( indices, vertices, creaseAngle );
  1467. }
  1468. // build geometry
  1469. var geometry = new THREE.BufferGeometry();
  1470. geometry.setAttribute( 'position', positionAttribute );
  1471. geometry.setAttribute( 'normal', normalAttribute );
  1472. geometry.setAttribute( 'uv', uvAttribute );
  1473. if ( colorAttribute ) geometry.setAttribute( 'color', colorAttribute );
  1474. // "solid" influences the material so let's store it for later use
  1475. geometry._solid = solid;
  1476. geometry._type = 'mesh';
  1477. return geometry;
  1478. }
  1479. function buildExtrusionNode( node ) {
  1480. var crossSection = [ 1, 1, 1, - 1, - 1, - 1, - 1, 1, 1, 1 ];
  1481. var spine = [ 0, 0, 0, 0, 1, 0 ];
  1482. var scale;
  1483. var orientation;
  1484. var beginCap = true;
  1485. var ccw = true;
  1486. var creaseAngle = 0;
  1487. var endCap = true;
  1488. var solid = true;
  1489. var fields = node.fields;
  1490. for ( var i = 0, l = fields.length; i < l; i ++ ) {
  1491. var field = fields[ i ];
  1492. var fieldName = field.name;
  1493. var fieldValues = field.values;
  1494. switch ( fieldName ) {
  1495. case 'beginCap':
  1496. beginCap = fieldValues[ 0 ];
  1497. break;
  1498. case 'ccw':
  1499. ccw = fieldValues[ 0 ];
  1500. break;
  1501. case 'convex':
  1502. // field not supported
  1503. break;
  1504. case 'creaseAngle':
  1505. creaseAngle = fieldValues[ 0 ];
  1506. break;
  1507. case 'crossSection':
  1508. crossSection = fieldValues;
  1509. break;
  1510. case 'endCap':
  1511. endCap = fieldValues[ 0 ];
  1512. break;
  1513. case 'orientation':
  1514. orientation = fieldValues;
  1515. break;
  1516. case 'scale':
  1517. scale = fieldValues;
  1518. break;
  1519. case 'solid':
  1520. solid = fieldValues[ 0 ];
  1521. break;
  1522. case 'spine':
  1523. spine = fieldValues; // only extrusion along the Y-axis are supported so far
  1524. break;
  1525. default:
  1526. console.warn( 'THREE.VRMLLoader: Unknown field:', fieldName );
  1527. break;
  1528. }
  1529. }
  1530. var crossSectionClosed = ( crossSection[ 0 ] === crossSection[ crossSection.length - 2 ] && crossSection[ 1 ] === crossSection[ crossSection.length - 1 ] );
  1531. // vertices
  1532. var vertices = [];
  1533. var spineVector = new THREE.Vector3();
  1534. var scaling = new THREE.Vector3();
  1535. var axis = new THREE.Vector3();
  1536. var vertex = new THREE.Vector3();
  1537. var quaternion = new THREE.Quaternion();
  1538. for ( var i = 0, j = 0, o = 0, il = spine.length; i < il; i += 3, j += 2, o += 4 ) {
  1539. spineVector.fromArray( spine, i );
  1540. scaling.x = scale ? scale[ j + 0 ] : 1;
  1541. scaling.y = 1;
  1542. scaling.z = scale ? scale[ j + 1 ] : 1;
  1543. axis.x = orientation ? orientation[ o + 0 ] : 0;
  1544. axis.y = orientation ? orientation[ o + 1 ] : 0;
  1545. axis.z = orientation ? orientation[ o + 2 ] : 1;
  1546. var angle = orientation ? orientation[ o + 3 ] : 0;
  1547. for ( var k = 0, kl = crossSection.length; k < kl; k += 2 ) {
  1548. vertex.x = crossSection[ k + 0 ];
  1549. vertex.y = 0;
  1550. vertex.z = crossSection[ k + 1 ];
  1551. // scale
  1552. vertex.multiply( scaling );
  1553. // rotate
  1554. quaternion.setFromAxisAngle( axis, angle );
  1555. vertex.applyQuaternion( quaternion );
  1556. // translate
  1557. vertex.add( spineVector );
  1558. vertices.push( vertex.x, vertex.y, vertex.z );
  1559. }
  1560. }
  1561. // indices
  1562. var indices = [];
  1563. var spineCount = spine.length / 3;
  1564. var crossSectionCount = crossSection.length / 2;
  1565. for ( var i = 0; i < spineCount - 1; i ++ ) {
  1566. for ( var j = 0; j < crossSectionCount - 1; j ++ ) {
  1567. var a = j + i * crossSectionCount;
  1568. var b = ( j + 1 ) + i * crossSectionCount;
  1569. var c = j + ( i + 1 ) * crossSectionCount;
  1570. var d = ( j + 1 ) + ( i + 1 ) * crossSectionCount;
  1571. if ( ( j === crossSectionCount - 2 ) && ( crossSectionClosed === true ) ) {
  1572. b = i * crossSectionCount;
  1573. d = ( i + 1 ) * crossSectionCount;
  1574. }
  1575. if ( ccw === true ) {
  1576. indices.push( a, b, c );
  1577. indices.push( c, b, d );
  1578. } else {
  1579. indices.push( a, c, b );
  1580. indices.push( c, d, b );
  1581. }
  1582. }
  1583. }
  1584. // triangulate cap
  1585. if ( beginCap === true || endCap === true ) {
  1586. var contour = [];
  1587. for ( var i = 0, l = crossSection.length; i < l; i += 2 ) {
  1588. contour.push( new THREE.Vector2( crossSection[ i ], crossSection[ i + 1 ] ) );
  1589. }
  1590. var faces = THREE.ShapeUtils.triangulateShape( contour, [] );
  1591. var capIndices = [];
  1592. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  1593. var face = faces[ i ];
  1594. capIndices.push( face[ 0 ], face[ 1 ], face[ 2 ] );
  1595. }
  1596. // begin cap
  1597. if ( beginCap === true ) {
  1598. for ( var i = 0, l = capIndices.length; i < l; i += 3 ) {
  1599. if ( ccw === true ) {
  1600. indices.push( capIndices[ i + 0 ], capIndices[ i + 1 ], capIndices[ i + 2 ] );
  1601. } else {
  1602. indices.push( capIndices[ i + 0 ], capIndices[ i + 2 ], capIndices[ i + 1 ] );
  1603. }
  1604. }
  1605. }
  1606. // end cap
  1607. if ( endCap === true ) {
  1608. var indexOffset = crossSectionCount * ( spineCount - 1 ); // references to the first vertex of the last cross section
  1609. for ( var i = 0, l = capIndices.length; i < l; i += 3 ) {
  1610. if ( ccw === true ) {
  1611. indices.push( indexOffset + capIndices[ i + 0 ], indexOffset + capIndices[ i + 2 ], indexOffset + capIndices[ i + 1 ] );
  1612. } else {
  1613. indices.push( indexOffset + capIndices[ i + 0 ], indexOffset + capIndices[ i + 1 ], indexOffset + capIndices[ i + 2 ] );
  1614. }
  1615. }
  1616. }
  1617. }
  1618. var positionAttribute = toNonIndexedAttribute( indices, new THREE.Float32BufferAttribute( vertices, 3 ) );
  1619. var normalAttribute = computeNormalAttribute( indices, vertices, creaseAngle );
  1620. var geometry = new THREE.BufferGeometry();
  1621. geometry.setAttribute( 'position', positionAttribute );
  1622. geometry.setAttribute( 'normal', normalAttribute );
  1623. // no uvs yet
  1624. // "solid" influences the material so let's store it for later use
  1625. geometry._solid = solid;
  1626. geometry._type = 'mesh';
  1627. return geometry;
  1628. }
  1629. // helper functions
  1630. function resolveUSE( identifier ) {
  1631. var node = nodeMap[ identifier ];
  1632. var build = getNode( node );
  1633. // because the same 3D objects can have different transformations, it's necessary to clone them.
  1634. // materials can be influenced by the geometry (e.g. vertex normals). cloning is necessary to avoid
  1635. // any side effects
  1636. return ( build.isObject3D || build.isMaterial ) ? build.clone() : build;
  1637. }
  1638. function parseFieldChildren( children, owner ) {
  1639. for ( var i = 0, l = children.length; i < l; i ++ ) {
  1640. var object = getNode( children[ i ] );
  1641. if ( object instanceof THREE.Object3D ) owner.add( object );
  1642. }
  1643. }
  1644. function triangulateFaceIndex( index, ccw ) {
  1645. var indices = [];
  1646. // since face defintions can have more than three vertices, it's necessary to
  1647. // perform a simple triangulation
  1648. var start = 0;
  1649. for ( var i = 0, l = index.length; i < l; i ++ ) {
  1650. var i1 = index[ start ];
  1651. var i2 = index[ i + ( ccw ? 1 : 2 ) ];
  1652. var i3 = index[ i + ( ccw ? 2 : 1 ) ];
  1653. indices.push( i1, i2, i3 );
  1654. // an index of -1 indicates that the current face has ended and the next one begins
  1655. if ( index[ i + 3 ] === - 1 || i + 3 >= l ) {
  1656. i += 3;
  1657. start = i + 1;
  1658. }
  1659. }
  1660. return indices;
  1661. }
  1662. function triangulateFaceData( data, index ) {
  1663. var triangulatedData = [];
  1664. var start = 0;
  1665. for ( var i = 0, l = index.length; i < l; i ++ ) {
  1666. var stride = start * 3;
  1667. var x = data[ stride ];
  1668. var y = data[ stride + 1 ];
  1669. var z = data[ stride + 2 ];
  1670. triangulatedData.push( x, y, z );
  1671. // an index of -1 indicates that the current face has ended and the next one begins
  1672. if ( index[ i + 3 ] === - 1 || i + 3 >= l ) {
  1673. i += 3;
  1674. start ++;
  1675. }
  1676. }
  1677. return triangulatedData;
  1678. }
  1679. function flattenData( data, index ) {
  1680. var flattenData = [];
  1681. for ( var i = 0, l = index.length; i < l; i ++ ) {
  1682. var i1 = index[ i ];
  1683. var stride = i1 * 3;
  1684. var x = data[ stride ];
  1685. var y = data[ stride + 1 ];
  1686. var z = data[ stride + 2 ];
  1687. flattenData.push( x, y, z );
  1688. }
  1689. return flattenData;
  1690. }
  1691. function expandLineIndex( index ) {
  1692. var indices = [];
  1693. for ( var i = 0, l = index.length; i < l; i ++ ) {
  1694. var i1 = index[ i ];
  1695. var i2 = index[ i + 1 ];
  1696. indices.push( i1, i2 );
  1697. // an index of -1 indicates that the current line has ended and the next one begins
  1698. if ( index[ i + 2 ] === - 1 || i + 2 >= l ) {
  1699. i += 2;
  1700. }
  1701. }
  1702. return indices;
  1703. }
  1704. function expandLineData( data, index ) {
  1705. var triangulatedData = [];
  1706. var start = 0;
  1707. for ( var i = 0, l = index.length; i < l; i ++ ) {
  1708. var stride = start * 3;
  1709. var x = data[ stride ];
  1710. var y = data[ stride + 1 ];
  1711. var z = data[ stride + 2 ];
  1712. triangulatedData.push( x, y, z );
  1713. // an index of -1 indicates that the current line has ended and the next one begins
  1714. if ( index[ i + 2 ] === - 1 || i + 2 >= l ) {
  1715. i += 2;
  1716. start ++;
  1717. }
  1718. }
  1719. return triangulatedData;
  1720. }
  1721. var vA = new THREE.Vector3();
  1722. var vB = new THREE.Vector3();
  1723. var vC = new THREE.Vector3();
  1724. var uvA = new THREE.Vector2();
  1725. var uvB = new THREE.Vector2();
  1726. var uvC = new THREE.Vector2();
  1727. function computeAttributeFromIndexedData( coordIndex, index, data, itemSize ) {
  1728. var array = [];
  1729. // we use the coordIndex.length as delimiter since normalIndex must contain at least as many indices
  1730. for ( var i = 0, l = coordIndex.length; i < l; i += 3 ) {
  1731. var a = index[ i ];
  1732. var b = index[ i + 1 ];
  1733. var c = index[ i + 2 ];
  1734. if ( itemSize === 2 ) {
  1735. uvA.fromArray( data, a * itemSize );
  1736. uvB.fromArray( data, b * itemSize );
  1737. uvC.fromArray( data, c * itemSize );
  1738. array.push( uvA.x, uvA.y );
  1739. array.push( uvB.x, uvB.y );
  1740. array.push( uvC.x, uvC.y );
  1741. } else {
  1742. vA.fromArray( data, a * itemSize );
  1743. vB.fromArray( data, b * itemSize );
  1744. vC.fromArray( data, c * itemSize );
  1745. array.push( vA.x, vA.y, vA.z );
  1746. array.push( vB.x, vB.y, vB.z );
  1747. array.push( vC.x, vC.y, vC.z );
  1748. }
  1749. }
  1750. return new THREE.Float32BufferAttribute( array, itemSize );
  1751. }
  1752. function computeAttributeFromFaceData( index, faceData ) {
  1753. var array = [];
  1754. for ( var i = 0, j = 0, l = index.length; i < l; i += 3, j ++ ) {
  1755. vA.fromArray( faceData, j * 3 );
  1756. array.push( vA.x, vA.y, vA.z );
  1757. array.push( vA.x, vA.y, vA.z );
  1758. array.push( vA.x, vA.y, vA.z );
  1759. }
  1760. return new THREE.Float32BufferAttribute( array, 3 );
  1761. }
  1762. function computeAttributeFromLineData( index, lineData ) {
  1763. var array = [];
  1764. for ( var i = 0, j = 0, l = index.length; i < l; i += 2, j ++ ) {
  1765. vA.fromArray( lineData, j * 3 );
  1766. array.push( vA.x, vA.y, vA.z );
  1767. array.push( vA.x, vA.y, vA.z );
  1768. }
  1769. return new THREE.Float32BufferAttribute( array, 3 );
  1770. }
  1771. function toNonIndexedAttribute( indices, attribute ) {
  1772. var array = attribute.array;
  1773. var itemSize = attribute.itemSize;
  1774. var array2 = new array.constructor( indices.length * itemSize );
  1775. var index = 0, index2 = 0;
  1776. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  1777. index = indices[ i ] * itemSize;
  1778. for ( var j = 0; j < itemSize; j ++ ) {
  1779. array2[ index2 ++ ] = array[ index ++ ];
  1780. }
  1781. }
  1782. return new THREE.Float32BufferAttribute( array2, itemSize );
  1783. }
  1784. var ab = new THREE.Vector3();
  1785. var cb = new THREE.Vector3();
  1786. function computeNormalAttribute( index, coord, creaseAngle ) {
  1787. var faces = [];
  1788. var vertexNormals = {};
  1789. // prepare face and raw vertex normals
  1790. for ( var i = 0, l = index.length; i < l; i += 3 ) {
  1791. var a = index[ i ];
  1792. var b = index[ i + 1 ];
  1793. var c = index[ i + 2 ];
  1794. var face = new Face( a, b, c );
  1795. vA.fromArray( coord, a * 3 );
  1796. vB.fromArray( coord, b * 3 );
  1797. vC.fromArray( coord, c * 3 );
  1798. cb.subVectors( vC, vB );
  1799. ab.subVectors( vA, vB );
  1800. cb.cross( ab );
  1801. cb.normalize();
  1802. face.normal.copy( cb );
  1803. if ( vertexNormals[ a ] === undefined ) vertexNormals[ a ] = [];
  1804. if ( vertexNormals[ b ] === undefined ) vertexNormals[ b ] = [];
  1805. if ( vertexNormals[ c ] === undefined ) vertexNormals[ c ] = [];
  1806. vertexNormals[ a ].push( face.normal );
  1807. vertexNormals[ b ].push( face.normal );
  1808. vertexNormals[ c ].push( face.normal );
  1809. faces.push( face );
  1810. }
  1811. // compute vertex normals and build final geometry
  1812. var normals = [];
  1813. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  1814. var face = faces[ i ];
  1815. var nA = weightedNormal( vertexNormals[ face.a ], face.normal, creaseAngle );
  1816. var nB = weightedNormal( vertexNormals[ face.b ], face.normal, creaseAngle );
  1817. var nC = weightedNormal( vertexNormals[ face.c ], face.normal, creaseAngle );
  1818. vA.fromArray( coord, face.a * 3 );
  1819. vB.fromArray( coord, face.b * 3 );
  1820. vC.fromArray( coord, face.c * 3 );
  1821. normals.push( nA.x, nA.y, nA.z );
  1822. normals.push( nB.x, nB.y, nB.z );
  1823. normals.push( nC.x, nC.y, nC.z );
  1824. }
  1825. return new THREE.Float32BufferAttribute( normals, 3 );
  1826. }
  1827. function weightedNormal( normals, vector, creaseAngle ) {
  1828. var normal = new THREE.Vector3();
  1829. if ( creaseAngle === 0 ) {
  1830. normal.copy( vector );
  1831. } else {
  1832. for ( var i = 0, l = normals.length; i < l; i ++ ) {
  1833. if ( normals[ i ].angleTo( vector ) < creaseAngle ) {
  1834. normal.add( normals[ i ] );
  1835. }
  1836. }
  1837. }
  1838. return normal.normalize();
  1839. }
  1840. function toColorArray( colors ) {
  1841. var array = [];
  1842. for ( var i = 0, l = colors.length; i < l; i += 3 ) {
  1843. array.push( new THREE.Color( colors[ i ], colors[ i + 1 ], colors[ i + 2 ] ) );
  1844. }
  1845. return array;
  1846. }
  1847. /**
  1848. * Vertically paints the faces interpolating between the
  1849. * specified colors at the specified angels. This is used for the Background
  1850. * node, but could be applied to other nodes with multiple faces as well.
  1851. *
  1852. * When used with the Background node, default is directionIsDown is true if
  1853. * interpolating the skyColor down from the Zenith. When interpolationg up from
  1854. * the Nadir i.e. interpolating the groundColor, the directionIsDown is false.
  1855. *
  1856. * The first angle is never specified, it is the Zenith (0 rad). Angles are specified
  1857. * in radians. The geometry is thought a sphere, but could be anything. The color interpolation
  1858. * is linear along the Y axis in any case.
  1859. *
  1860. * You must specify one more color than you have angles at the beginning of the colors array.
  1861. * This is the color of the Zenith (the top of the shape).
  1862. *
  1863. * @param {BufferGeometry} geometry
  1864. * @param {number} radius
  1865. * @param {array} angles
  1866. * @param {array} colors
  1867. * @param {boolean} topDown - Whether to work top down or bottom up.
  1868. */
  1869. function paintFaces( geometry, radius, angles, colors, topDown ) {
  1870. // compute threshold values
  1871. var thresholds = [];
  1872. var startAngle = ( topDown === true ) ? 0 : Math.PI;
  1873. for ( var i = 0, l = colors.length; i < l; i ++ ) {
  1874. var angle = ( i === 0 ) ? 0 : angles[ i - 1 ];
  1875. angle = ( topDown === true ) ? angle : ( startAngle - angle );
  1876. var point = new THREE.Vector3();
  1877. point.setFromSphericalCoords( radius, angle, 0 );
  1878. thresholds.push( point );
  1879. }
  1880. // generate vertex colors
  1881. var indices = geometry.index;
  1882. var positionAttribute = geometry.attributes.position;
  1883. var colorAttribute = new THREE.BufferAttribute( new Float32Array( geometry.attributes.position.count * 3 ), 3 );
  1884. var position = new THREE.Vector3();
  1885. var color = new THREE.Color();
  1886. for ( var i = 0; i < indices.count; i ++ ) {
  1887. var index = indices.getX( i );
  1888. position.fromBufferAttribute( positionAttribute, index );
  1889. var thresholdIndexA, thresholdIndexB;
  1890. var t = 1;
  1891. for ( var j = 1; j < thresholds.length; j ++ ) {
  1892. thresholdIndexA = j - 1;
  1893. thresholdIndexB = j;
  1894. var thresholdA = thresholds[ thresholdIndexA ];
  1895. var thresholdB = thresholds[ thresholdIndexB ];
  1896. if ( topDown === true ) {
  1897. // interpolation for sky color
  1898. if ( position.y <= thresholdA.y && position.y > thresholdB.y ) {
  1899. t = Math.abs( thresholdA.y - position.y ) / Math.abs( thresholdA.y - thresholdB.y );
  1900. break;
  1901. }
  1902. } else {
  1903. // interpolation for ground color
  1904. if ( position.y >= thresholdA.y && position.y < thresholdB.y ) {
  1905. t = Math.abs( thresholdA.y - position.y ) / Math.abs( thresholdA.y - thresholdB.y );
  1906. break;
  1907. }
  1908. }
  1909. }
  1910. var colorA = colors[ thresholdIndexA ];
  1911. var colorB = colors[ thresholdIndexB ];
  1912. color.copy( colorA ).lerp( colorB, t );
  1913. colorAttribute.setXYZ( index, color.r, color.g, color.b );
  1914. }
  1915. geometry.setAttribute( 'color', colorAttribute );
  1916. }
  1917. //
  1918. var textureLoader = new THREE.TextureLoader( this.manager );
  1919. textureLoader.setPath( this.resourcePath || path ).setCrossOrigin( this.crossOrigin );
  1920. // check version (only 2.0 is supported)
  1921. if ( data.indexOf( '#VRML V2.0' ) === - 1 ) {
  1922. throw Error( 'THREE.VRMLLexer: Version of VRML asset not supported.' );
  1923. }
  1924. // create JSON representing the tree structure of the VRML asset
  1925. var tree = generateVRMLTree( data );
  1926. // parse the tree structure to a three.js scene
  1927. var scene = parseTree( tree );
  1928. return scene;
  1929. }
  1930. } );
  1931. function VRMLLexer( tokens ) {
  1932. this.lexer = new chevrotain.Lexer( tokens ); // eslint-disable-line no-undef
  1933. }
  1934. VRMLLexer.prototype = {
  1935. constructor: VRMLLexer,
  1936. lex: function ( inputText ) {
  1937. var lexingResult = this.lexer.tokenize( inputText );
  1938. if ( lexingResult.errors.length > 0 ) {
  1939. console.error( lexingResult.errors );
  1940. throw Error( 'THREE.VRMLLexer: Lexing errors detected.' );
  1941. }
  1942. return lexingResult;
  1943. }
  1944. };
  1945. function VRMLParser( tokenVocabulary ) {
  1946. chevrotain.Parser.call( this, tokenVocabulary ); // eslint-disable-line no-undef
  1947. var $ = this;
  1948. var Version = tokenVocabulary[ 'Version' ];
  1949. var LCurly = tokenVocabulary[ 'LCurly' ];
  1950. var RCurly = tokenVocabulary[ 'RCurly' ];
  1951. var LSquare = tokenVocabulary[ 'LSquare' ];
  1952. var RSquare = tokenVocabulary[ 'RSquare' ];
  1953. var Identifier = tokenVocabulary[ 'Identifier' ];
  1954. var RouteIdentifier = tokenVocabulary[ 'RouteIdentifier' ];
  1955. var StringLiteral = tokenVocabulary[ 'StringLiteral' ];
  1956. var HexLiteral = tokenVocabulary[ 'HexLiteral' ];
  1957. var NumberLiteral = tokenVocabulary[ 'NumberLiteral' ];
  1958. var TrueLiteral = tokenVocabulary[ 'TrueLiteral' ];
  1959. var FalseLiteral = tokenVocabulary[ 'FalseLiteral' ];
  1960. var NullLiteral = tokenVocabulary[ 'NullLiteral' ];
  1961. var DEF = tokenVocabulary[ 'DEF' ];
  1962. var USE = tokenVocabulary[ 'USE' ];
  1963. var ROUTE = tokenVocabulary[ 'ROUTE' ];
  1964. var TO = tokenVocabulary[ 'TO' ];
  1965. var NodeName = tokenVocabulary[ 'NodeName' ];
  1966. $.RULE( 'vrml', function () {
  1967. $.SUBRULE( $.version );
  1968. $.AT_LEAST_ONE( function () {
  1969. $.SUBRULE( $.node );
  1970. } );
  1971. $.MANY( function () {
  1972. $.SUBRULE( $.route );
  1973. } );
  1974. } );
  1975. $.RULE( 'version', function () {
  1976. $.CONSUME( Version );
  1977. } );
  1978. $.RULE( 'node', function () {
  1979. $.OPTION( function () {
  1980. $.SUBRULE( $.def );
  1981. } );
  1982. $.CONSUME( NodeName );
  1983. $.CONSUME( LCurly );
  1984. $.MANY( function () {
  1985. $.SUBRULE( $.field );
  1986. } );
  1987. $.CONSUME( RCurly );
  1988. } );
  1989. $.RULE( 'field', function () {
  1990. $.CONSUME( Identifier );
  1991. $.OR2( [
  1992. { ALT: function () {
  1993. $.SUBRULE( $.singleFieldValue );
  1994. } },
  1995. { ALT: function () {
  1996. $.SUBRULE( $.multiFieldValue );
  1997. } }
  1998. ] );
  1999. } );
  2000. $.RULE( 'def', function () {
  2001. $.CONSUME( DEF );
  2002. $.OR( [
  2003. { ALT: function () {
  2004. $.CONSUME( Identifier );
  2005. } },
  2006. { ALT: function () {
  2007. $.CONSUME( NodeName );
  2008. } }
  2009. ] );
  2010. } );
  2011. $.RULE( 'use', function () {
  2012. $.CONSUME( USE );
  2013. $.OR( [
  2014. { ALT: function () {
  2015. $.CONSUME( Identifier );
  2016. } },
  2017. { ALT: function () {
  2018. $.CONSUME( NodeName );
  2019. } }
  2020. ] );
  2021. } );
  2022. $.RULE( 'singleFieldValue', function () {
  2023. $.AT_LEAST_ONE( function () {
  2024. $.OR( [
  2025. { ALT: function () {
  2026. $.SUBRULE( $.node );
  2027. } },
  2028. { ALT: function () {
  2029. $.SUBRULE( $.use );
  2030. } },
  2031. { ALT: function () {
  2032. $.CONSUME( StringLiteral );
  2033. } },
  2034. { ALT: function () {
  2035. $.CONSUME( HexLiteral );
  2036. } },
  2037. { ALT: function () {
  2038. $.CONSUME( NumberLiteral );
  2039. } },
  2040. { ALT: function () {
  2041. $.CONSUME( TrueLiteral );
  2042. } },
  2043. { ALT: function () {
  2044. $.CONSUME( FalseLiteral );
  2045. } },
  2046. { ALT: function () {
  2047. $.CONSUME( NullLiteral );
  2048. } }
  2049. ] );
  2050. } );
  2051. } );
  2052. $.RULE( 'multiFieldValue', function () {
  2053. $.CONSUME( LSquare );
  2054. $.MANY( function () {
  2055. $.OR( [
  2056. { ALT: function () {
  2057. $.SUBRULE( $.node );
  2058. } },
  2059. { ALT: function () {
  2060. $.SUBRULE( $.use );
  2061. } },
  2062. { ALT: function () {
  2063. $.CONSUME( StringLiteral );
  2064. } },
  2065. { ALT: function () {
  2066. $.CONSUME( HexLiteral );
  2067. } },
  2068. { ALT: function () {
  2069. $.CONSUME( NumberLiteral );
  2070. } },
  2071. { ALT: function () {
  2072. $.CONSUME( NullLiteral );
  2073. } }
  2074. ] );
  2075. } );
  2076. $.CONSUME( RSquare );
  2077. } );
  2078. $.RULE( 'route', function () {
  2079. $.CONSUME( ROUTE );
  2080. $.CONSUME( RouteIdentifier );
  2081. $.CONSUME( TO );
  2082. $.CONSUME2( RouteIdentifier );
  2083. } );
  2084. this.performSelfAnalysis();
  2085. }
  2086. VRMLParser.prototype = Object.create( chevrotain.Parser.prototype ); // eslint-disable-line no-undef
  2087. VRMLParser.prototype.constructor = VRMLParser;
  2088. function Face( a, b, c ) {
  2089. this.a = a;
  2090. this.b = b;
  2091. this.c = c;
  2092. this.normal = new THREE.Vector3();
  2093. }
  2094. var TEXTURE_TYPE = {
  2095. INTENSITY: 1,
  2096. INTENSITY_ALPHA: 2,
  2097. RGB: 3,
  2098. RGBA: 4
  2099. };
  2100. return VRMLLoader;
  2101. } )();