VRMLLoader.js 73 KB

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