VRMLLoader.js 73 KB

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