2
0

VRMLLoader.js 72 KB

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