VRMLLoader.js 75 KB

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