VRMLLoader.js 73 KB

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