VRMLLoader.js 73 KB

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