VRMLLoader.js 72 KB

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