VRMLLoader.js 72 KB

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