VRMLLoader.js 71 KB

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