VRMLLoader.js 73 KB

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